# 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);
}
```
