The DexVault smart contract is used for creating vault and filling initial data.
Smart contract responsible for creating vault and filling initial data such as lp token, platform code, owner and manipulating vault’s transactions (transfer, withdraw).
Derives following classes and interfaces:
DexContractBase, IDexVault, IUpgradable, IResetGas.
constructor
constructor (address owner_, address root_, address token_factory_) public
Sets gas limit to maximum (tvm.accept) and sets values for root, owner and token factory address.
Parameters:
Name
Type
Description
owner_
address
Address of the dex vault owner
root_
address
Address of the dex vault root
token_factory_
address
Address of the token factory
_dexRoot
function _dexRoot() override internal view returns(address)
Returns the root address of the DexVault.
Return value:
Type
Description
address
Address of the dex root
Owner
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:
Name
Type
Description
new_owner
address
Address of the new vault owner
acceptOwner
Accepts new owner in a way that owner becomes pending owner and emits OwnerTransferAccepted event.
getOwner
Returns DexVault owner address.
Return value:
Type
Description
address
getPendingOwner
Returns DexVault’s pending owner address.
Return value:
Type
Description
address
Address of the pending owner of the dex vault
Token
setTokenFactory
Sets new address of token factory by passing new address from function params to token factory contract param, emits TokenFactoryAddressUpdated event with previous token factory address and a new one.
Parameters:
Name
Type
Description
new_token_factory
address
Address of the new token factory
installPlatformOnce
Checks whether the platform is already installed, if not, reserves initial balance, passes code value to the platform code and transfers gas.
Parameters:
Name
Type
Description
code
TvmCell
Platform code for initial version
installOrUpdateLpTokenPendingCode
Reserves initial balance, passes new code to lp token pending code.
Parameters:
Name
Type
Description
code
TvmCell
Liquidity pool pending code
addLiquidityToken
Creates new instance of DexVaultLpTokenPending, pass necessary params such as token factory address, value and address for receiving gas.
Parameters:
Name
Type
Description
pair
address
Pair address
left_root
address
Token root address of the left token
right_root
address
Token root address of the right token
send_gas_to
address
Address where to send gas spent by calling contract methods
onLiquidityTokenDeployed
Callback function, builds initial token pending data based on the params passed by onlyLpTokenPending, reserves initial balance calls the liquidityTokenRootDeployed method from the DexPair where the token root wallets are configured and the new pair is created.
Parameters:
Name
Type
Description
nonce
uint32
Flag used in building initial state of tvm
pair
address
Address of the liquidity pool
left_root
address
Token root address of the left token
right_root
address
Token root address of the right token
lp_root
address
Liquidity pool root address
send_gas_to
address
Address where to send gas spent by calling contract methods
onLiquidityTokenNotDeployed
Callback function, builds initial token pending data based on the params passed by onlyLpTokenPending, calls the liquidityTokenRootNotDeployed method from the DexPair where it does the transfer from send_gas_to address based on active variable.
Parameters:
Name
Type
Description
nonce
uint32
Flag used in building initial state of tvm
pair
address
Address of the liquidity pool
left_root
address
Token root address of the left token
right_root
address
Token root address of the right token
lp_root
address
Liquidity pool root address
send_gas_to
address
Address where to send gas spent by calling contract methods
_buildLpTokenPendingInitData
Builds pending liquidity pool token initial data calling tvm’s buildStateInit method where it returns TvmCell with initialized state using DexVaultLpTokenPending contract, additional data for the contract such as nonce, vault, pair, left, right address and lp_token_pending_code as required code param for buildStateInit method
Parameters:
Name
Type
Description
nonce
uint32
Flag used in building initial state of tvm
pair
address
Address of the liquidity pool
left_root
address
Token root address of the left token
right_root
address
Token root address of the right token
Return value:
Type
Description
TvmCell
Data used for building initial state
Withdraw
withdraw
Used for withdraw transaction, called from dex pair, transfers tokens from vault token wallet to recipient address through the transfer method from TokenWallet.
Emits WithdrawToken event and calls successCallback to notify success.
Parameters:
Name
Type
Description
nonce
uint32
Flag used in building initial state of tvm
pair
address
Address of the liquidity pool
left_root
address
Token root address of the left token
right_root
address
Token root address of the right token
lp_root
address
Liquidity pool root address
send_gas_to
address
Address where to send gas spent by calling contract methods
Transfer
transfer
Does the pair transfer tokens through the transfer method of the TokenWallet from vault wallet to the recipient’s address, emits PairTransferTokens event.
Parameters:
Name
Type
Description
amount
uint128
Amount to be transferred
token_root
address
Address of the token root which will be transferred
vault_wallet
address
Address of vault’s wallet
recipient_address
address
Address of the recipient of the transaction
deploy_wallet_grams
uint128
Fee for deploying wallet
notify_receiver
bool
Indicates if the receiver of the transaction should be notified
payload
TvmCell
Additional data needed for transfering to token wallet
left_root
address
Token root address of the left token
right_root
address
Token root address of the right token
pair_version
uint32
Current pair version
send_gas_to
address
Address where to send gas spent by calling contract methods
Code upgrade
upgrade
function upgrade(TvmCell code) public override onlyOwner
Reserves initial balance, makes new builder instance to store all the vault’s data necessary, set passed code for upgrade and finishes upgrade of DexVault by calling onCodeUpgrade
Return value:
Name
Type
Description
code
TvmCell
Code to be set for upgraded version
Reset
resetGas
Resets balance to ROOT_INITIAL_BALANCE.
Return value:
Name
Type
Description
receiver
address
Address where to send gas spent by calling contract methods
resetTargetGas
Calculates max between ROOT_INITIAL_BALANCE and after that resets gas to calculated value for target address calling resetGas method.
Return value:
Name
Type
Description
target
address
Address for which gas should be reset
receiver
address
Address where to send gas spent by calling contract methods
Key Events
VaultCodeUpgraded
Emitted when vault code is upgraded
RequestedOwnerTransfer
Emitted when ownership transfer is requested.
OwnerTransferAccepted
Emitted when ownership transfer is accepted.
TokenFactoryAddressUpdated
Emitted when old token factory address is replaced with new one.