Withdraw process with the Liquidity Handler
Example: A walkthrough of a withdrawal from IbAlluoUSD to USDC
/// @notice Withdraws accuratel
/// @dev When called, immediately check for new interest index. Then find the adjusted amount in IbAlluo tokens
/// Then burn appropriate amount of IbAlluo tokens to receive asset token
/// @param _targetToken Asset token
/// @param _amount Amount (parsed 10**18) in asset value
function withdrawTo(
address _recipient,
address _targetToken,
uint256 _amount
) public {
updateRatio();
uint256 adjustedAmount = (_amount * multiplier) / growingRatio;
_burn(_msgSender(), adjustedAmount);
ILiquidityHandler handler = ILiquidityHandler(liquidityHandler);
if (supportedTokens.contains(_targetToken) == false) {
(address liquidToken,) = ILiquidityHandler(liquidityHandler).getAdapterCoreTokensFromIbAlluo(address(this));
// This just is used to revert if there is no active route.
require(IExchange(exchangeAddress).buildRoute(liquidToken, _targetToken).length > 0, "!Supported");
handler.withdraw(
_recipient,
liquidToken,
_amount,
_targetToken
);
} else {
handler.withdraw(
_recipient,
_targetToken,
_amount
);
}
emit TransferAssetValue(_msgSender(), address(0), adjustedAmount, _amount, growingRatio);
emit BurnedForWithdraw(_msgSender(), adjustedAmount);
}Step 2: When withdraw is called for 100 USDC, carry out checks and either withdraw funds directly or add the user to queue.
Step 2.5: If the user wanted a withdrawal in a token not supported by the IbAlluo (i.e WETH for IbAlluoUSD), carry out the withdrawal and do a swap through the Alluo Exchange before sending to the user
Step 3: When withdraw is called on the adapter, it sends the tokens directly to the user.
Last updated