Yelay V3 SDK Docs
  • Intro
  • Main entities
  • Setting up your account
  • Initialization
  • Deposit
  • Withdrawals
  • Tracking balance and TVL
  • Yield tracking and claiming
  • Supportive methods
  • Deposits with timelock
  • Yelay's yield farming sources
Powered by GitBook
On this page

Deposit

PreviousInitializationNextWithdrawals

Last updated 2 months ago

Depositing to a Yelay V3 Vault

To deposit assets into a Yelay V3 vault using the vault’s native asset currency, follow these steps:

const vaultAddress = '0x1234';
const poolId = 1234;
const amount = '1000000';

const allowance = await sdk.vaults.allowance(vault);

if (allowance.isZero()) {
	const approveTx = await sdk.vaults.approve(vaultAddress, amount);
	await approveTx.wait();
}

const depositTx = await sdk.vaults.deposit(vaultAddress, poolId, amount);
await depositTx.wait();

Where:

  • vaultAddress – One of the vaults set up by Yelay. Fetch vault addresses using sdk.vaults.getVaults(). (See the chapter.)

  • poolId – One of the pools set up by the client within the vault.

Once the deposit is complete, the corresponding amount of ERC-1155 NFT shares is minted in the user’s wallet.

For example:

  • Depositing 2 USDC results in 2,000,000 ERC-1155 tokens, and so on.

Depositing with any asset

  1. Depositing any ERC-20 Token

To deposit any ERC-20 token and swap it on the way, use the sdk.vaults.swapAndDeposit method:

const vault = '0x123';
const pool = 1234;
const amount = '1000000';
const tokenToSwap = '0x456';
// only 1inch Aggregation Router v6 is supported
const swapTarget = '1inch Aggregation Router v6 address';
const swapCallData = '0x9...1';

const allowance = await sdk.vaults.vaultWrapperAllowance(tokenToSwap);

if (allowance.isZero()) {
	const approveTx = await sdk.vaults.approveVaultWrapper(tokenToSwap, amount);
	await approveTx.wait();
}

const swapAndDepositTX = await sdk.vaults.swapAndDeposit(vault, pool, amount, {
	swapCallData,
	swapTarget,
	tokenIn: tokenToSwap,
});
await swapAndDepositTX.wait();

Where:

  • vault – Address of the vault.

  • pool – Pool set up by the client within the vault.

  • amount – Deposit amount.

  • swapCallData – Swap arguments from 1inch.

  • swapTarget – Should match the asset of the vault.

  • tokenToSwap – ERC-20 token to be swapped before depositing.

⚠ Note:

  • This method requires obtaining a 1inch API key and retrieving swapCallData from it.

  • Users will incur swap costs when using this method.

  1. Wrap ETH when depositing to WETH vault

To deposit ETH into a WETH vault (i.e., to wrap ETH instead of swapping it and avoid swap fees), use the depositEth method:

const tx = await sdk.vaults.depositEth(vault, poolId, amount);
await tx.wait();

Where:

  • vault – Address of the Yelay V3 WETH vault on the given chain.

  • poolId – ID of the pool where the user deposits.

  • amount – Amount of ETH to deposit.

This method leverages the VaultWrapper contract to handle ETH wrapping and depositing in a single transaction.

with Pool ID = 1 results in 1,000,000 ERC-1155 tokens being minted.

"Supportive Methods"
Depositing 1 USDC into the Yelay V3 test vault