Withdrawals
Explore the withdraw function
By calling withdrawTo, the user burns IbAlluo in return for tokens of their choice.
This happens in the opposite way as depositing:
- 1.Burn the correct amount of IbAlluos
- 2.If the token the user wants to receive is in the list of supported tokens, withdraw this from the handler to the user
- 3.If the token the user wants to receive is NOT in the list of supported tokens, the handler converts the amount in asset value to the target token and sends it to the user.
Using IbAlluoUSD as an example, if you called withdrawTo("Bob's Address", "USDC address", "$100"):
- 1.Burn $100 worth of IbAlluos
- 2.As USDC is supported in IbAlluoUSD, send $100 USD to the user.
Using IbAlluoUSD as an example, if you called withdrawTo("Bob's Address", "EURS address", "$100"):
- 1.Burn $100 worth of IbAlluos
- 2.As EURS is not supported in IbAlluoUSD, the handler converts $100 into EURS tokens and sends that amount to the user
The
_amount
parameter is the amount in the native asset value of the IbAlluo you are interacting with. For example, USD for IbAlluoUSD or EUR for IbAlluoEUR. Then if the _targetToken
is not part of the supported tokens like in the second example above, you are withdrawing $100 USD worth of EUR tokens, not €100! IbAlluo.sol
1
/// @notice Withdraws accuratel
2
/// @dev When called, immediately check for new interest index. Then find the adjusted amount in IbAlluo tokens
3
/// Then burn appropriate amount of IbAlluo tokens to receive asset token
4
/// @param _targetToken Asset token
5
/// @param _amount Amount (parsed 10**18) in asset value
6
7
function withdrawTo(
8
address _recipient,
9
address _targetToken,
10
uint256 _amount
11
) public {
12
updateRatio();
13
uint256 adjustedAmount = (_amount * multiplier) / growingRatio;
14
_burn(_msgSender(), adjustedAmount);
15
ILiquidityHandler handler = ILiquidityHandler(liquidityHandler);
16
if (supportedTokens.contains(_targetToken) == false) {
17
(address liquidToken,) = ILiquidityHandler(liquidityHandler).getAdapterCoreTokensFromIbAlluo(address(this));
18
// This just is used to revert if there is no active route.
19
require(IExchange(exchangeAddress).buildRoute(liquidToken, _targetToken).length > 0, "!Supported");
20
handler.withdraw(
21
_recipient,
22
liquidToken,
23
_amount,
24
_targetToken
25
);
26
} else {
27
handler.withdraw(
28
_recipient,
29
_targetToken,
30
_amount
31
);
32
}
33
34
emit TransferAssetValue(_msgSender(), address(0), adjustedAmount, _amount, growingRatio);
35
emit BurnedForWithdraw(_msgSender(), adjustedAmount);
36
}
Last modified 11mo ago