DexVault
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
Sets gas limit to maximum (tvm.accept
) and sets values for root, owner and token factory address.
Parameters:
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
_dexRoot
Returns the root address of the DexVault.
Return value:
address
Address of the dex root
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 vault owner
acceptOwner
acceptOwner
Accepts new owner in a way that owner becomes pending owner and emits OwnerTransferAccepted
event.
getOwner
getOwner
Returns DexVault owner address.
Return value:
address
getPendingOwner
getPendingOwner
Returns DexVault’s pending owner address.
Return value:
address
Address of the pending owner of the dex vault
Token
setTokenFactory
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:
new_token_factory
address
Address of the new token factory
installPlatformOnce
installPlatformOnce
Checks whether the platform is already installed, if not, reserves initial balance, passes code value to the platform code and transfers gas.
Parameters:
code
TvmCell
Platform code for initial version
installOrUpdateLpTokenPendingCode
installOrUpdateLpTokenPendingCode
Reserves initial balance, passes new code to lp token pending code.
Parameters:
code
TvmCell
Liquidity pool pending code
addLiquidityToken
addLiquidityToken
Creates new instance of DexVaultLpTokenPending
, pass necessary params such as token factory address, value and address for receiving gas.
Parameters:
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
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:
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
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:
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
_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:
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:
TvmCell
Data used for building initial state
Withdraw
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:
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
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:
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
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:
code
TvmCell
Code to be set for upgraded version
Reset
resetGas
resetGas
Resets balance to ROOT_INITIAL_BALANCE
.
Return value:
receiver
address
Address where to send gas spent by calling contract methods
resetTargetGas
resetTargetGas
Calculates max between ROOT_INITIAL_BALANCE
and after that resets gas to calculated value for target address calling resetGas
method.
Return value:
target
address
Address for which gas should be reset
receiver
address
Address where to send gas spent by calling contract methods
Key Events
VaultCodeUpgraded
VaultCodeUpgraded
Emitted when vault code is upgraded
RequestedOwnerTransfer
RequestedOwnerTransfer
Emitted when ownership transfer is requested.
OwnerTransferAccepted
OwnerTransferAccepted
Emitted when ownership transfer is accepted.
TokenFactoryAddressUpdated
TokenFactoryAddressUpdated
Emitted when old token factory address is replaced with new one.
WithdrawTokens
WithdrawTokens
PairTransferTokens
PairTransferTokens
Last updated