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
installOrUpdateAccountCodefunction installOrUpdateAccountCode(TvmCell code) external onlyOwnerUses 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
installOrUpdatePairCodefunction installOrUpdatePairCode(TvmCell code) external onlyOwnerUses 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
getAccountVersionfunction getAccountVersion() override external view responsible returns (uint32)Gets the current version of the account.
Return Value:
uint32
Account version
getPairVersion
getPairVersionfunction getPairVersion() override external view responsible returns (uint32)Gets the current version of the desired pair.
Return Value:
uint32
Pair version
Vault
setVaultOnce
setVaultOncefunction setVaultOnce(address new_vault) external onlyOwnerSets 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
getVaultfunction getVault() override external view responsible returns (address)Gets the vault of the desired DexRoot.
Return Value:
address
Address of the root’s vault
Active
setActive
setActivefunction setActive(bool new_active) external onlyOwnerChecks 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
isActivefunction isActive() override external view responsible returns (bool)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
upgradefunction upgrade(TvmCell code) override external onlyOwnerUpgrades 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
requestUpgradeAccountfunction requestUpgradeAccount(uint32 current_version, address send_gas_to, address account_owner) externalUsing 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
forceUpgradeAccountfunction forceUpgradeAccount(address account_owner, address send_gas_to)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
upgradePairfunction upgradePair(address left_root, address right_root, address send_gas_to) external view onlyOwnerAccording 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
resetGasfunction resetGas(address receiver) override external view onlyOwnerResets balance to ROOT_INITIAL_BALANCE.
Parameters:
receiver
address
Address where to send gas spent by calling contract methods
spent by calling contract methods
resetTargetGas
resetTargetGasfunction resetTargetGas(address target, address receiver) external view onlyOwnerCalculates 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
getOwnerfunction getOwner() external view responsible returns (address dex_owner)Returns owner’s address.
Return Value:
dex_owner
address
Address of the root’s owner
getPendingOwner
getPendingOwnerfunction getPendingOwner() external view responsible returns (address dex_pending_owner)Returns pending owner’s address.
Return Value:
dex_pending_owner
address
Address of the root’s pending owner
transferOwner
transferOwnerfunction transferOwner(address new_owner) external onlyOwnerPending 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
acceptOwnerfunction acceptOwner() externalAccepts new owner in a way that owner becomes pending owner and emits OwnerTransferAccepted event.
Expected address functions
getExpectedAccountAddress
getExpectedAccountAddressfunction getExpectedAccountAddress(address account_owner) external view responsible returns (address)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
getExpectedPairAddressfunction getExpectedPairAddress(address left_root, address right_root) override external view responsible returns (address)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
deployAccountfunction deployAccount(address account_owner, address send_gas_to) external 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
deployPairfunction deployPair(address left_root, address right_root, address send_gas_to) externalCreates 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
onPairCreatedfunction onPairCreated(address left_root, address right_root, address send_gas_to) override external onlyPair(left_root, right_root)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
AccountCodeUpgradedAccountCodeUpgraded(uint32 version);Emitted when account code is upgraded
PairCodeUpgraded
PairCodeUpgradedPairCodeUpgraded(uint32 version);Emitted when the pair code is updated
RootCodeUpgraded
RootCodeUpgradedRootCodeUpgraded();Emitted when the root code is updated
ActiveUpdated
ActiveUpdatedActiveUpdated(bool new_active);Emitted when the activity of dex root is updated
RequestedPairUpgrade
RequestedPairUpgradeRequestedPairUpgrade(address left_root, address right_root);Emitted when the pair upgrade is requested
RequestedForceAccountUpgrade
RequestedForceAccountUpgradeRequestedForceAccountUpgrade(address account_owner);Emitted when forced account upgrade is requested
RequestedOwnerTransfer
RequestedOwnerTransferRequestedOwnerTransfer(address old_owner, address new_owner);Emitted when transfer of ownership is requested
OwnerTransferAccepted
OwnerTransferAcceptedOwnerTransferAccepted(address old_owner, address new_owner);Emitted when transfer of ownership is accepted
NewPairCreated
NewPairCreatedNewPairCreated(address left_root, address right_root);Emitted when new pair is created
Last updated
Was this helpful?