# Deposit

**Depositing to a Yelay Vault**

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

### Deposit ERC20 into the vault

All action methods support an optional `options` parameter of type `WriteOptions` from `@gud/drift` for customizing transaction parameters (gas, nonce, etc.).

```ts
const vault = '0x1234';
const pool = 1234;
const amount = 1000000n; // Using bigint for amount

const allowance = await sdk.portfolio.getAllowance(vault);

if (allowance === 0n) {
	const approveTx = await sdk.actions.approve(vault, amount);
	// Note: Drift returns transaction hash, wait method depends on your adapter
}

const depositTx = await sdk.actions.deposit(vault, pool, amount);

// With optional WriteOptions
const depositTxWithOptions = await sdk.actions.deposit(vault, pool, amount, {
	gas: 300000n,
});
```

Wher&#x65;**:**

* **`vault`** – One of the vaults set up by Yelay. Fetch vault addresses using `sdk.vaults.getVaults()`. (See the ["Supportive Methods"](https://docs.yelay.io/yelay-sdk/supportive-methods) 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 1 USDC into the Yelay test vault ](https://basescan.org/tx/0xb8882d59518954801ef47f67ac367f0abe9fa746cc790ec62009c63b14a69c19)with `Pool ID = 1` results in 1,000,000 ERC-1155 tokens being minted.
* Depositing 2 USDC results in 2,000,000 ERC-1155 tokens, and so on.

<figure><img src="https://2182024280-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FnZejXGeA67gWdZSLRbwe%2Fuploads%2Fi4vSvdpjbpOfgslMbVfd%2F%D0%A1%D0%BD%D0%B8%D0%BC%D0%BE%D0%BA%20%D1%8D%D0%BA%D1%80%D0%B0%D0%BD%D0%B0%202025-03-11%20%D0%B2%2016.04.43.png?alt=media&#x26;token=bf8a46b5-f464-4630-987f-da142f12a979" alt=""><figcaption></figcaption></figure>

#### Deposit "on behalf" of another user (specifying shares receiver) <a href="#key-features" id="key-features"></a>

This function allows you to deposit tokens into a vault pool, but the resulting shares will be credited to a different address (receiver). This is useful for scenarios like depositing on behalf of users.

```ts
const vault = '0x1234';
const pool = 1234;
const amount = 1000000n; // Using bigint for amount
const receiver = '0x5678'; // Address that will receive the deposit shares

const allowance = await sdk.portfolio.getAllowance(vault);

if (allowance === 0n) {
	const approveTx = await sdk.actions.approve(vault, amount);
	// Note: Drift returns transaction hash, wait method depends on your adapter
}

const depositTx = await sdk.actions.depositOnBehalf(vault, pool, amount, receiver);
```

#### Depositing with any asset  <a href="#key-features" id="key-features"></a>

1. Depositing any ERC-20 Token

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

```ts
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();
```

Wher&#x65;**:**

* **`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.

### Deposit ETH into the vault

```ts
const vault = '0x1234';
const pool = 1234;
const amount = 1000000n; // Amount of ETH in wei
const tx = await sdk.actions.depositEth(vault, pool, amount);
```

Where:

* `vault` – Address of the Yelay WETH vault on the given chain.
* `pool` – 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.

Note that it is not possible to do 'depositOnBehalf' with swapAndDeposit and depositEth. Contact **@guilhermemussi** on Telegram if you want this to be enabled.&#x20;
