diff --git a/contracts/receivers/aave-v2-receiver/main.sol b/contracts/receivers/aave-v2-receiver/main.sol index 5578bb9..caff527 100644 --- a/contracts/receivers/aave-v2-receiver/main.sol +++ b/contracts/receivers/aave-v2-receiver/main.sol @@ -56,6 +56,7 @@ contract MigrateResolver is Helpers, Events { TokenInterface(wmaticAddr).deposit{value: address(this).balance}(); } } + IERC20 _tokenContract = IERC20(_token); uint _tokenBal = _tokenContract.balanceOf(address(this)); if (_tokenBal > 0) { @@ -108,7 +109,7 @@ contract AaveV2Migrator is MigrateResolver { isPositionSafe(); - emit LogAaveV2Migrate(dsa, supplyTokens, borrowTokens, supplyAmts, supplyAmts); + emit LogAaveV2Migrate(dsa, supplyTokens, borrowTokens, supplyAmts, borrowAmts); } function onStateReceive(uint256 stateId, bytes calldata receivedData) external { diff --git a/contracts/receivers/aave-v2-receiver/variables.sol b/contracts/receivers/aave-v2-receiver/variables.sol index 6a08122..bcd8c15 100644 --- a/contracts/receivers/aave-v2-receiver/variables.sol +++ b/contracts/receivers/aave-v2-receiver/variables.sol @@ -36,7 +36,6 @@ contract Variables { */ InstaListInterface public constant instaList = InstaListInterface(0x839c2D3aDe63DF5b0b8F3E57D5e145057Ab41556); - /** * @dev Matic StateReceiver contract */ @@ -67,4 +66,4 @@ contract Variables { * @dev last stateId from the onStateReceive */ uint256 internal lastStateId; -} \ No newline at end of file +} diff --git a/contracts/senders/aave-v2-migrator/interfaces.sol b/contracts/senders/aave-v2-migrator/interfaces.sol index d9c3792..5ed078d 100644 --- a/contracts/senders/aave-v2-migrator/interfaces.sol +++ b/contracts/senders/aave-v2-migrator/interfaces.sol @@ -106,4 +106,5 @@ interface ChainLinkInterface { interface RootChainManagerInterface { function depositFor(address user, address token, bytes calldata depositData) external; + function depositEtherFor(address user) external payable; } diff --git a/contracts/senders/aave-v2-migrator/main.sol b/contracts/senders/aave-v2-migrator/main.sol index f64fcd6..9c2ad7e 100644 --- a/contracts/senders/aave-v2-migrator/main.sol +++ b/contracts/senders/aave-v2-migrator/main.sol @@ -88,8 +88,18 @@ contract LiquidityResolver is Helpers, Events { for (uint i = 0; i < _tokens.length; i++) { address _token = _tokens[i] == ethAddr ? wethAddr : _tokens[i]; aave.withdraw(_token, _amts[i], address(this)); - IERC20(_token).safeApprove(erc20Predicate, _amts[i]); - rootChainManager.depositFor(polygonReceiver, _token, abi.encode(_amts[i])); + + if (_token == wethAddr) { + TokenInterface wethContract = TokenInterface(wethAddr); + uint wethBal = wethContract.balanceOf(address(this)); + wethContract.approve(wethAddr, wethBal); + wethContract.withdraw(wethBal); + rootChainManager.depositEtherFor{value: _amts[i]}(polygonReceiver); + } else { + IERC20(_token).safeApprove(erc20Predicate, _amts[i]); + rootChainManager.depositFor(polygonReceiver, _tokens[i], abi.encode(_amts[i])); + } + isPositionSafe(); } @@ -191,4 +201,4 @@ contract InstaAaveV2MigratorSenderImplementation is MigrateResolver { flashloanContract.initiateFlashLoan(data, ethAmt); } -} \ No newline at end of file +}