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 paramsconstructor(address initial_owner, address initial_vault) publicUsed 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
_dexRootfunction _dexRoot() override internal view returns(address)Returns address of the current DexRoot.
Return Value:
address
Address of the current dex root
installPlatformOnce
installPlatformOncefunction installPlatformOnce(TvmCell code) external onlyOwnerFills data for creating new platform for DexRoot, sets platform code.
Parameters:
code
TvmCell
Platform code to be set for initialization
installOrUpdateAccountCode
installOrUpdateAccountCodeUses 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
installOrUpdatePairCodeUses 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
getAccountVersionGets the current version of the account.
Return Value:
uint32
Account version
getPairVersion
getPairVersionGets the current version of the desired pair.
Return Value:
uint32
Pair version
Vault
setVaultOnce
setVaultOnceSets 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
getVaultGets the vault of the desired DexRoot.
Return Value:
address
Address of the root’s vault
Active
setActive
setActiveChecks 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
isActiveChecks 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
upgradeUpgrades 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
requestUpgradeAccountUsing 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
forceUpgradeAccountUpgrades 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
upgradePairAccording 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
resetGasResets balance to ROOT_INITIAL_BALANCE.
Parameters:
receiver
address
Address where to send gas spent by calling contract methods
spent by calling contract methods
resetTargetGas
resetTargetGasCalculates 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
getOwnerReturns owner’s address.
Return Value:
dex_owner
address
Address of the root’s owner
getPendingOwner
getPendingOwnerReturns pending owner’s address.
Return Value:
dex_pending_owner
address
Address of the root’s pending owner
transferOwner
transferOwnerPending 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
acceptOwnerAccepts new owner in a way that owner becomes pending owner and emits OwnerTransferAccepted event.
Expected address functions
getExpectedAccountAddress
getExpectedAccountAddressCalls _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
getExpectedPairAddressCalls _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
deployAccountUsed 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
deployPairCreates 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
onPairCreatedCallback 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
AccountCodeUpgradedEmitted when account code is upgraded
PairCodeUpgraded
PairCodeUpgradedEmitted when the pair code is updated
RootCodeUpgraded
RootCodeUpgradedEmitted when the root code is updated
ActiveUpdated
ActiveUpdatedEmitted when the activity of dex root is updated
RequestedPairUpgrade
RequestedPairUpgradeEmitted when the pair upgrade is requested
RequestedForceAccountUpgrade
RequestedForceAccountUpgradeEmitted when forced account upgrade is requested
RequestedOwnerTransfer
RequestedOwnerTransferEmitted when transfer of ownership is requested
OwnerTransferAccepted
OwnerTransferAcceptedEmitted when transfer of ownership is accepted
NewPairCreated
NewPairCreatedEmitted when new pair is created
Last updated
Was this helpful?