> For the complete documentation index, see [llms.txt](https://dev.init.capital/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dev.init.capital/guides/basic-interaction/deposit-and-withdraw.md).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
