DexRoot
The DexRoot logic is used for deploying and updating pairs and accounts. Also it is used to set account/pair codes and other data related to the pairs and accounts such as vault and owner address.
Smart contract responsible for deploying and updating pairs and accounts, setting account/pair codes and other data related to the pairs and accounts such as vault and owner address. Gets version of account/pair.
Derives following classes and interfaces: DexContractBase, IDexRoot, IResetGas, IUpgradable
Contains constructor
with params
constructor
with paramsUsed for filling the data about new DexRoot.
Parameters:
initial_owner
address
Address of the first owner of the current dex root
initial_vault
address
Address of the initial vault of the current dex root
_dexRoot
_dexRoot
Returns address of the current DexRoot.
Return Value:
address
Address of the current dex root
installPlatformOnce
installPlatformOnce
Fills data for creating new platform for DexRoot, sets platform code.
Parameters:
code
TvmCell
Platform code to be set for initialization
installOrUpdateAccountCode
installOrUpdateAccountCode
Uses the code parameter as the account code and if it’s not installed yet installs it. If it is, updates it.
Parameters:
code
TvmCell
Account code to be set for this version
installOrUpdatePairCode
installOrUpdatePairCode
Uses the code parameter as the pair code and if it’s not installed yet installs it. If it is, updates it.
Parameters:
code
TvmCell
Pair code to be set for this version
version
getAccountVersion
getAccountVersion
Gets the current version of the account.
Return Value:
uint32
Account version
getPairVersion
getPairVersion
Gets the current version of the desired pair.
Return Value:
uint32
Pair version
Vault
setVaultOnce
setVaultOnce
Sets the vault of the DexRoot, passed vault’s address value must be zero in order to be set, it’s done only once per new root.
Parameters:
new_vault
address
Address of the vault to be set
getVault
getVault
Gets the vault of the desired DexRoot.
Return Value:
address
Address of the root’s vault
Active
setActive
setActive
Checks the conditions such as is the newActive parameter true, vault is already set, account and pair versions are set, if all the conditions are fulfilled DexRoot is set to active. After the active variable is set, ActiveUpdated event is emitted and contract’s balance is transferred to the owner’s account.
Parameters:
new_active
bool
Decides weather the root will be active or not, active if true, not if false
isActive
isActive
Checks whether the DexRoot account is active, returns true if yes, false if not.
Return Value:
bool
True if the root is active, false if not
Decides weather the root will be active or not, active if true, not if false
Upgrade
upgrade
upgrade
Upgrades root contract to a newer version, emits RootCodeUpgraded event, creates new TvmBuilder instance and stores required params for upgrade, sets new code and calls onCodeUpgrade
callback to finish with upgrade.
Parameters:
code
TvmCell
Code to be set for upgraded version
requestUpgradeAccount
requestUpgradeAccount
Using accountOwner and send_gas_to
addresses and current_version parameter upgrades account if it’s not already upgraded to the latest version, calling UpgradableByRequest
’s upgrade method.
Parameters:
current_version
uint32
Desired version for upgrade
send_gas_to
address
Address where to send gas spent by calling contract methods
account_owner
address
Address of the owner whose account should be upgraded
forceUpgradeAccount
forceUpgradeAccount
Upgrades account to the latest version using account owner and send_gas_to
addresses, emits RequestedForceAccountUpgrade
event.
Parameters:
account_owner
address
Account owner address
send_gas_to
address
Address where to send gas spent by calling contract methods
upgradePair
upgradePair
According to the leftRoot, rightRoot and send_gas_to
address parameters upgrades left and right pair and emits RequestedPairUpgrade
event.
Parameters:
left_root
address
Root address of the left pair
right_root
address
Root address of the right pair
send_gas_to
address
Address where to send gas spent by calling contract methods
Reset
resetGas
resetGas
Resets balance to ROOT_INITIAL_BALANCE
.
Parameters:
receiver
address
Address where to send gas spent by calling contract methods
spent by calling contract methods
resetTargetGas
resetTargetGas
Calculates value for gas to be reset at and after that resets gas to calculated value for target address calling IResetGas’s resetGas method.
Parameters:
target
address
Address for which gas should be reset
receiver
address
Address where to send gas spent by calling contract methods
Owner
getOwner
getOwner
Returns owner’s address.
Return Value:
dex_owner
address
Address of the root’s owner
getPendingOwner
getPendingOwner
Returns pending owner’s address.
Return Value:
dex_pending_owner
address
Address of the root’s pending owner
transferOwner
transferOwner
Pending owner address gets value of the new owner param which is used in acceptOwner method (where actual transfer of ownership is happening) and emits RequestedOwnerTransfer
event.
Parameters:
new_owner
address
Address of the new pending owner
acceptOwner
acceptOwner
Accepts new owner in a way that owner becomes pending owner and emits OwnerTransferAccepted
event.
Expected address functions
getExpectedAccountAddress
getExpectedAccountAddress
Calls _expectedAccountAddress
and based on account owner’s address returns expected address.
Parameters:
account_owner
address
Address of the account’s owner
Return Value:
address
Expected account’s address
getExpectedPairAddress
getExpectedPairAddress
Calls _expectedPairAddress
and based on left and right root’s addresses returns expected pair address.
Parameters:
left_root
address
Address of the left pair’s token root
right_root
address
Address of the right pair’s token root
Return Value:
address
Expected pair’s address
Deploy
deployAccount
deployAccount
Used for deploying child contracts, creates new DexPlatform for the account and passes data such as account code, version, vault address and address for receiving gas for new root that needs to be deployed.
Parameters:
account_owner
address
Address of the account’s owner
send_gas_to
address
Address where to send gas spent by calling contract methods
deployPair
deployPair
Creates new DexPlatform for the pair and passes data for a new pair that needs to be deployed.
Parameters:
left_root
address
Address of the left pair’s token root
right_root
address
Address of the right pair’s token root
send_gas_to
address
Address where to send gas spent by calling contract methods
onPairCreated
onPairCreated
Callback method, based on right_root
and left_root
params notify that the new pair is created and transfer fees.
Parameters:
left_root
address
Root address of the left pair
right_root
address
Root address of the right pair
send_gas_to
address
Address where to send gas spent by calling contract methods
Key Events
AccountCodeUpgraded
AccountCodeUpgraded
Emitted when account code is upgraded
PairCodeUpgraded
PairCodeUpgraded
Emitted when the pair code is updated
RootCodeUpgraded
RootCodeUpgraded
Emitted when the root code is updated
ActiveUpdated
ActiveUpdated
Emitted when the activity of dex root is updated
RequestedPairUpgrade
RequestedPairUpgrade
Emitted when the pair upgrade is requested
RequestedForceAccountUpgrade
RequestedForceAccountUpgrade
Emitted when forced account upgrade is requested
RequestedOwnerTransfer
RequestedOwnerTransfer
Emitted when transfer of ownership is requested
OwnerTransferAccepted
OwnerTransferAccepted
Emitted when transfer of ownership is accepted
NewPairCreated
NewPairCreated
Emitted when new pair is created
Last updated