Deposit and Withdraw
Deposits to & Withdraws from the specified lending pool. When you deposit to the lending pool, the corresponding "inToken" will be minted as a receipt token that represents your shares of the pool.
Deposit
To deposit to a lending pool, users must perform 2 steps:
transfer underlying token to the pool
call
mintTo
on InitCore
The action returns shares
of the lending pool.
The above 2 steps must be performed in a single transaction (atomically) to avoid potential front-run attack.
// Example deposit function
function deposit(address lendingPool, uint256 amount, address receiver) external returns (uint256 shares) {
// .. transfer in the tokens to this address ..
// 1. transfer tokens to the lending pool
IERC20(underlyingToken).safeTransfer(lendingPool, amount);
// 2. call mintTo
shares = IInitCore(INIT_CORE).mintTo(lendingPool, receiver);
}
Withdraw
To withdraw from a lending pool, users must perform 2 steps:
transfer inToken to the pool
call
burnTo
on InitCore
The action returns amount
of underlying token to be received.
The above 2 steps must be performed in a single transaction (atomically) to avoid potential front-run attack.
// 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);
}
Last updated