Vault Integration
Technical documentation on how to integrate your app with Unagii V3 Vaults.
Unagii V3 Vaults implement the ERC-4626 Tokenized Vault Standard with some additional functions for safety checks not implemented in the standard ERC-4626 interface. We recommend developers use these when possible for protection against MEV attacks, e.g. by usingsafeRedeem()
instead of redeem()
if making a large withdrawal.
An example ERC-4626 interface implementation can be found on OpenZeppelin.
Users should ensure that they're interacting with the official Unagii V3 Vault contracts found at the following addresses.
Key Functions
Deposit
vault.safeDeposit(uint256 amount, address receiver, uint256 minimumShares) -> uint256 sharesMinted
amount
uint256
deposit exact amount of asset (e.g. USDC) in exchange to mint vault shares (e.g. uUSDCv3)
receiver
address
address which receives and owns shares minted
minimumShares
uint256
minimum shares to mint, can be calculated off-chain via helper methods like vault.previewDeposit(amount)
If receiver
is a smart contract, it must implement the ability to make withdrawals or funds will be stuck forever!
Do not calculate minimumShares
on-chain in the same call as this still leaves the transaction open to MEV attacks!
Example Code
Calculations
The vault itself is also an ERC20 token contract, ownership of which represents shares of the underlying asset (e.g. uUSDCv3 to USDC).
vault.balanceOf(address owner) -> uint256(shares)
Get the amount of vault shares (e.g. uUSDCv3) owned by
owner
address
vault.previewRedeem(uint256 shares) -> uint256(assets)
Calculates how many underlying
assets
(e.g. USDC) would be received when burning a corresponding amount of vaultshares
(e.g. uUSDCv3)This assumes an ideal scenario with zero slippage from e.g. swap and withdrawal fees
Withdrawal
vault.safeRedeem(uint256 shares, address receiver, address owner, uint256 minimumAssets) -> uint256 assetsReceived
shares
uint256
burn exact amount of vault shares (e.g. uUSDCv3) in exchange for underlying assets (e.g. USDC)
receiver
address
address which receives the withdrawn underlying assets
owner
address
address whose shares are being burnt. In most cases this will be the same as receiver
, but can differ to support more complex smart contract integrations
minimumAssets
uint256
minimum amount of underlying asset (e.g. USDC) to receive, accounting for factors like slippage from swap and withdrawal fees of underlying strategies
vault.safeWithdraw(uint256 assets, address receiver, address owner, uint256 maximumShares) -> uint256 sharesBurnt
assets
uint256
withdraw exact amount of underlying assets (e.g. USDC) by burning vault shares (e.g. uUSDCv3)
receiver
address
address which receives the withdrawn underlying assets
owner
address
address whose shares are being burnt. In most cases this will be the same as receiver
, but can differ to support more complex smart contract integrations
maximumShares
uint256
maximum amount of vault shares (e.g. uUSDCv3) to burn, accounting for factors like slippage from swap and withdrawal fees of underlying strategies
If owner
is not the same as the address making the withdrawal, ERC20 approval needs to be obtained first via vault.approve(address spender, uint256 shares)
Do not calculate minimumAssets
or maximumShares
on-chain in the same call as this still leaves the transaction open to MEV attacks!
Example Code
Notes
Block Delay
Our Vaults implement a BlockDelay which prevents the same address from making multiple deposit, withdrawal or share transfers within the same block. This is for defense against smart contract exploits like flash loan attacks.
Last updated