# Deposit and Withdraw

## Deposit

To deposit to a lending pool, users must perform 2 steps:

1. transfer underlying token to the pool
2. call `mintTo` on InitCore

The action returns `shares` of the lending pool.

{% hint style="info" %}
inToken decimals may be different from the underlying token's decimals. Currently, it is set to `8 + underlyingToken.decimals()` to conform to the ERC-4626 standard.
{% endhint %}

{% hint style="warning" %}
The above 2 steps must be performed in a single transaction (atomically) to avoid potential front-run attack.
{% endhint %}

<pre class="language-solidity"><code class="lang-solidity">// Example deposit function
function deposit(address lendingPool, uint256 amount, address receiver) external returns (uint256 shares) {
<strong>    // .. transfer in the tokens to this address ..
</strong><strong>    
</strong><strong>    // 1. transfer tokens to the lending pool
</strong>    IERC20(underlyingToken).safeTransfer(lendingPool, amount);

    // 2. call mintTo
    shares = IInitCore(INIT_CORE).mintTo(lendingPool, receiver);
}
</code></pre>

## Withdraw

To withdraw from a lending pool, users must perform 2 steps:

1. transfer inToken to the pool
2. call `burnTo` on InitCore

The action returns `amount` of underlying token to be received.

{% hint style="warning" %}
The above 2 steps must be performed in a single transaction (atomically) to avoid potential front-run attack.
{% endhint %}

```solidity
// Example withdraw function
function withdraw(address lendingPool, uint256 sharesToBurn, address receiver) external returns (uint256 amount) {
    // 1. transfer inTokens to the lending pool
    IERC20(lendingPool).safeTransfer(lendingPool, sharesToBurn);

    // 2. call burnTo
    amount = IInitCore(INIT_CORE).burnTo(lendingPool, receiver);
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dev.init.capital/guides/basic-interaction/deposit-and-withdraw.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
