Convert Comptroller
Processes energy free conversions for Sorrel Members while shared resources are available.
Last updated
Processes energy free conversions for Sorrel Members while shared resources are available.
Last updated
Mainnet Redeployment Coming Soon.
Nile
Github
The "ConvertComptroller" contract is a smart contract written in the Solidity programming language. It serves as a control mechanism for executing and tracking token conversion transactions. Let's break down the main components and functionalities of this contract:
Contract Dependencies: The contract imports various other contracts from the OpenZeppelin library, such as "Pausable.sol" and "ReentrancyGuard.sol." It also imports other custom contracts like "AdminAuth.sol," "gStable.sol," "Rewards.sol," and "BankDepository.sol."
Events: The contract defines several events that are emitted during the execution of transactions. These events include "ConversionInitiated," "ConversionExecuted," and "ConversionCancelled." They provide a way to track the status and details of each transaction.
Structs: The contract defines a struct named "Transaction" to store information about each transaction, including the hodler (address initiating the transaction), the IDs of the tokens being converted from and to, the amount of tokens being converted, the nonce (a unique identifier for the transaction), the timestamps for initiation and execution, and the transaction hash.
State Variables: The contract includes the following state variables:
"nonce": An integer variable to track the nonce value for generating transaction hashes.
"status": A mapping that associates each transaction hash with its status code.
"hashTxMapping": A mapping that associates each transaction hash with its corresponding transaction object.
"userTxHashMapping": A mapping that associates each user's address with an array of transaction hashes initiated by that user.
"bank": A variable of type "IBankDepository" that represents an instance of the "BankDepository" contract.
Constructor: The contract's constructor takes an address parameter representing the address of the "BankDepository" contract and initializes the "bank" variable with this address.
Modifiers: The contract defines a modifier called "onlyPositive" that checks if a value is greater than zero.
Functionality: The contract provides several functions to perform different operations:
"pause" and "unpause": These functions are used to pause and unpause the contract's functionality, respectively. Only the contract's admin can call these functions.
"setBankDepository": This function allows the contract's admin to update the address of the "BankDepository" contract.
"getUserTransactions": This function takes a hodler's address as input and returns arrays containing information about the user's transactions, such as token IDs, token amounts, timestamps, nonces, transaction hashes, and transaction statuses.
"getNonce": This internal function generates and returns a new nonce value.
"initiateTransaction": This function is used by the contract's admin to initiate a token conversion transaction. It takes the hodler's address, the IDs of the tokens being converted from and to, and the amount of tokens being converted as input. The function generates a transaction hash, checks if the transaction already exists, and updates the necessary mappings and status. It emits the "ConversionInitiated" event.
"executeTransaction": This function is used by the contract's admin to execute a token conversion transaction. It takes the hodler's address, the IDs of the tokens being converted from and to, the amount of tokens being converted, and the nonce as input. The function verifies the transaction's status and updates it based on the result of the conversion operation. It emits the "ConversionExecuted" event.
"cancelTransaction": This function allows a hodler to cancel their own token conversion transaction. It takes the hodler's address, the IDs of the tokens being converted from and to, the amount of tokens being converted, and the nonce as input. The function updates the transaction's status to indicate cancellation and emits the "ConversionCancelled" event.
"getTxHash": This function generates and returns a unique transaction hash based on the input parameters.
Overall, the "ConvertComptroller" contract provides a control mechanism for initiating, executing, and canceling token conversion transactions. It tracks the status of each transaction and allows users to retrieve information about their own transactions.
Explanation Generated by Sorrel's AIA Team - Powered by ChatGPT