Nest Vault Implementation
How to implement Nest Vaults on your site.
Last updated
How to implement Nest Vaults on your site.
Last updated
Our balance tab supports the following features:
Balance
Position Value
Bridge
At its core, Nest Tokens are just ERC20 tokens. To determine the balance of Nest Tokens a user has, you just need to call the balanceOf
function of the Boring Vault contract to get a users balance. Of course, the result will be with respect to the value of the decimals
function.
The position value of a user's holdings is just the user’s balance multiplied by the Rate of the token. To get the rate of the token, you will need to call the getRate
function on the Accountant contract associated with the Boring Vault.
The bridge feature allows users to bridge their tokens from one chain to another. At this time, our application only supports migrating from Ethereum to Plume and not Plume to Ethereum. To bridge your Nest token, you will need to call the bridge
function on the Teller contract associated with the Boring Vault.
Our deposit tab supports the following features:
Compliance Check
Exchange Rate
Withdrawal Conditions
Approve
Slippage
Deposit
Deposit and Bridge
Before we load the deposit tab, you need to check that the connected user is compliant. You can do this by making an API call to the compliance endpoint.
TODO: Add details of the compliance endpoint
The exchange rate is the rate for which you would receive Nest Tokens given you deposit a particular asset token. You can get this by calling the getRateInQuoteSafe
function on the Accountant contract associated with the Boring Vault. Be sure to invert it if you need to.
Withdrawal conditions are different per token and per network. This is not specified on chain and instead is configured by the off-chain infrastructure. Typically, the withdrawal processor runs once a day on Ethereum mainnet and once every 15 minutes on Plume mainnet.
In the event that the price of the asset token is changing, we can provide a slippage tolerance. We are hard coding this per token for now, but you can allow the user to set it. If you set this, you should change the minimumMint
parameter to account for this.
Before you deposit, you will need to approve the Predicate Proxy contract associated to the Boring Vault to be able to transfer tokens on behalf of the user. You will do that by calling the approve
function on the asset token for the amount that is being deposited.
Before you can deposit into Nest Vaults, you will need to acquire a Predicate Message that ensures that the user that is depositing meets compliance requirements. You can do this by making an API call to the compliance endpoint.
TODO: Add details of the compliance endpoint.
In the event that the chain that the user is connected to is the same as the destination chain, you can deposit your asset token into the vault in exchange for Nest Tokens. To initiate a deposit, you call the deposit
function on the Predicate Proxy contract associated with the Boring Vault.
The deposit
function takes the following parameters:
depositTokenContractAddress
- The contract address of the asset token that is getting deposited.
depositAmount
- The amount of the asset token that is getting deposited.
minimumMint
- The amount of the vault token the user should receive at minimum. This should be the rate with slippage applied.
predicateMessage
- The predicate message returned from the API.
In the event that the chain that the user is connected to is different as the destination chain, you can deposit your asset token into the vault in exchange for Nest Tokens on the destination chain. To initiate a deposit and bridge, you call the depositAndBridge
function on the Predicate Proxy contract associated with the Boring Vault.
The depositAndBridge
function takes the following parameters:
depositTokenContractAddress
- The contract address of the asset token that is getting deposited.
depositAmount
- The amount of the asset token that is getting deposited.
minimumMint
- The amount of the vault token the user should receive at minimum. This should be the rate with slippage applied.
data
chainSelector
- The LayerZero Endpoint ID for the destination chain.
destinationChainReciever
- The address who should receive the tokens on the destination chain
bridgeFeeToken
- 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
(always)
messageGas
- 100000n
(always)
data
- 0x
(always)
predicateMessage
- The predicate message returned from the API.
Our withdrawal tab supports the following features:
Exchange Rate
Slippage
Deadline
Approve
Withdraw
The exchange rate is the rate for which you would receive a particular asset token in exchange for your Nest Tokens. You can get this by calling the getRateInQuoteSafe
function on the Accountant contract associated with the Boring Vault. No need to invert it this time.
In the event that the price of the asset token is changing, we can provide a slippage tolerance. We are hard coding this per token for now, but you can allow the user to set it. If you set this, you should change the atomicPrice
parameter to account for this.
Since the withdraw function is asynchronous, you will need to supply a deadline. We are hard coding this value per token to account for the off-chain processing rules. This directly correlates to the Withdrawal Conditions in the Deposit tab.
Before you withdraw, you will need to approve the AtomicQueue contract associated to the network to be able to transfer tokens on behalf of the user. You will do that by calling the approve
function on the Nest Token for the amount that is being withdrawn.
Withdraws for Nest Tokens happen asynchronously. So, you will submit a withdraw request to the AtomicQueue on behalf of the user. That request will be fulfilled based on the rules mentioned in the Withdrawal Conditions. In order to submit a withdrawal request, you need to call the withdraw
function on the AtomicQueue contract for the network.
The withdraw
function takes the following parameters:
offerTokenContractAddress
- The contract address of the Nest Token.
wantTokenContractAddress
- The contract address of the asset token.
atomicRequest
deadline
- The deadline that the request should be fulfilled by.
atomicPrice
- The rate with the slippage supplied.
offerAmount
- The amount of Nest Tokens you wish to withdraw.
inSolve
- false
(always)
Things not mentioned here that we can add:
Transaction history
Vault details
APY
TVL
Helpers
The Nucleus Team provides to help with these functions.