Removing L2 Encoding from AaveV3 MixIn (#676)

This commit is contained in:
Savarn Dontamsetti (Sav) 2023-03-09 12:02:36 -05:00 committed by GitHub
parent d97dab83cd
commit 3e939f7780
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 5 additions and 52 deletions

View File

@ -47,7 +47,7 @@ contract ArbitrumBridgeAdapter is
MixinWOOFi,
MixinZeroExBridge
{
constructor(IEtherToken weth) public MixinCurve(weth) MixinAaveV3(true) {}
constructor(IEtherToken weth) public MixinCurve(weth) {}
function _trade(
BridgeOrder memory order,

View File

@ -45,7 +45,7 @@ contract AvalancheBridgeAdapter is
MixinWOOFi,
MixinZeroExBridge
{
constructor(IEtherToken weth) public MixinCurve(weth) MixinAaveV3(false) {}
constructor(IEtherToken weth) public MixinCurve(weth) {}
function _trade(
BridgeOrder memory order,

View File

@ -41,7 +41,7 @@ contract OptimismBridgeAdapter is
MixinWOOFi,
MixinZeroExBridge
{
constructor(IEtherToken weth) public MixinCurve(weth) MixinAaveV3(true) {}
constructor(IEtherToken weth) public MixinCurve(weth) {}
/* solhint-disable function-max-lines */
function _trade(

View File

@ -53,7 +53,7 @@ contract PolygonBridgeAdapter is
MixinWOOFi,
MixinZeroExBridge
{
constructor(IEtherToken weth) public MixinCurve(weth) MixinAaveV3(false) {}
constructor(IEtherToken weth) public MixinCurve(weth) {}
function _trade(
BridgeOrder memory order,

View File

@ -47,63 +47,16 @@ interface IPool {
function withdraw(address asset, uint256 amount, address to) external returns (uint256);
}
// Minimal Aave V3 L2Pool interface
interface IL2Pool {
/**
* @notice Calldata efficient wrapper of the supply function on behalf of the caller
* @param args Arguments for the supply function packed in one bytes32
* 96 bits 16 bits 128 bits 16 bits
* | 0-padding | referralCode | shortenedAmount | assetId |
* @dev the shortenedAmount is cast to 256 bits at decode time, if type(uint128).max the value will be expanded to
* type(uint256).max
* @dev assetId is the index of the asset in the reservesList.
*/
function supply(bytes32 args) external;
/**
* @notice Calldata efficient wrapper of the withdraw function, withdrawing to the caller
* @param args Arguments for the withdraw function packed in one bytes32
* 112 bits 128 bits 16 bits
* | 0-padding | shortenedAmount | assetId |
* @dev the shortenedAmount is cast to 256 bits at decode time, if type(uint128).max the value will be expanded to
* type(uint256).max
* @dev assetId is the index of the asset in the reservesList.
*/
function withdraw(bytes32 args) external;
}
contract MixinAaveV3 {
using LibERC20TokenV06 for IERC20Token;
bool private immutable _isL2;
constructor(bool isL2) public {
_isL2 = isL2;
}
function _tradeAaveV3(
IERC20Token sellToken,
IERC20Token buyToken,
uint256 sellAmount,
bytes memory bridgeData
) internal returns (uint256) {
if (_isL2) {
(IL2Pool pool, address aToken, bytes32 l2Params) = abi.decode(bridgeData, (IL2Pool, address, bytes32));
sellToken.approveIfBelow(address(pool), sellAmount);
if (address(buyToken) == aToken) {
pool.supply(l2Params);
// 1:1 mapping token --> aToken and have the same number of decimals as the underlying token
return sellAmount;
} else if (address(sellToken) == aToken) {
pool.withdraw(l2Params);
return sellAmount;
}
revert("MixinAaveV3/UNSUPPORTED_TOKEN_PAIR");
}
(IPool pool, address aToken, ) = abi.decode(bridgeData, (IPool, address, bytes32));
(IPool pool, address aToken) = abi.decode(bridgeData, (IPool, address));
sellToken.approveIfBelow(address(pool), sellAmount);