From 11bfdbf7f41c55e4a92ba0d4c30b37c59a7c1874 Mon Sep 17 00:00:00 2001 From: Thrilok Kumar Date: Wed, 21 Apr 2021 07:02:58 +0530 Subject: [PATCH 1/7] WETH fix --- contracts/senders/aave-v2-migrator/main.sol | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/contracts/senders/aave-v2-migrator/main.sol b/contracts/senders/aave-v2-migrator/main.sol index f64fcd6..2128123 100644 --- a/contracts/senders/aave-v2-migrator/main.sol +++ b/contracts/senders/aave-v2-migrator/main.sol @@ -89,7 +89,15 @@ contract LiquidityResolver is Helpers, Events { 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 (_tokens[i] == ethAddr) { + TokenInterface wethContract = TokenInterface(wethAddr); + uint wethBal = wethContract.balanceOf(address(this)); + wethContract.approve(wethAddr, wethBal); + wethContract.withdraw(wethBal); + } + + rootChainManager.depositFor(polygonReceiver, _tokens[i], abi.encode(_amts[i])); isPositionSafe(); } From 2ac09aea58475f3d9aeb6cf2b41f08dff43d6a4e Mon Sep 17 00:00:00 2001 From: Thrilok Kumar Date: Wed, 21 Apr 2021 07:04:11 +0530 Subject: [PATCH 2/7] WETH fix on receiver --- contracts/receivers/aave-v2-receiver/interfaces.sol | 7 ++++++- contracts/receivers/aave-v2-receiver/main.sol | 12 ++++++++++-- contracts/receivers/aave-v2-receiver/variables.sol | 12 +++++++++++- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/contracts/receivers/aave-v2-receiver/interfaces.sol b/contracts/receivers/aave-v2-receiver/interfaces.sol index 5ff7f9a..de752af 100644 --- a/contracts/receivers/aave-v2-receiver/interfaces.sol +++ b/contracts/receivers/aave-v2-receiver/interfaces.sol @@ -100,4 +100,9 @@ interface AaveInterface { interface InstaListInterface { function accountID(address) external view returns (uint); -} \ No newline at end of file +} + + +interface WETHTokenInterface { + function deposit(address user, bytes memory depositData) external payable; +} diff --git a/contracts/receivers/aave-v2-receiver/main.sol b/contracts/receivers/aave-v2-receiver/main.sol index 5578bb9..62db294 100644 --- a/contracts/receivers/aave-v2-receiver/main.sol +++ b/contracts/receivers/aave-v2-receiver/main.sol @@ -4,7 +4,7 @@ pragma experimental ABIEncoderV2; import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import { TokenInterface } from "../../common/interfaces.sol"; -import { AccountInterface, AaveData, AaveInterface, IndexInterface } from "./interfaces.sol"; +import { AccountInterface, AaveData, AaveInterface, IndexInterface, WETHTokenInterface } from "./interfaces.sol"; import { Events } from "./events.sol"; import { Helpers } from "./helpers.sol"; @@ -56,6 +56,14 @@ contract MigrateResolver is Helpers, Events { TokenInterface(wmaticAddr).deposit{value: address(this).balance}(); } } + + if (_token == wethAddr) { + TokenInterface wethPosContract = TokenInterface(wethPosAddr); + if (wethPosContract.balanceOf(address(this)) > 0) { + WETHTokenInterface(wethAddr).deposit(address(this), abi.encode(wethPosContract.balanceOf(address(this)))); + } + } + IERC20 _tokenContract = IERC20(_token); uint _tokenBal = _tokenContract.balanceOf(address(this)); if (_tokenBal > 0) { @@ -108,7 +116,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..e16f60d 100644 --- a/contracts/receivers/aave-v2-receiver/variables.sol +++ b/contracts/receivers/aave-v2-receiver/variables.sol @@ -36,12 +36,22 @@ contract Variables { */ InstaListInterface public constant instaList = InstaListInterface(0x839c2D3aDe63DF5b0b8F3E57D5e145057Ab41556); - /** * @dev Matic StateReceiver contract */ address public constant maticReceiver = 0x0000000000000000000000000000000000001001; + /** + * @dev WETH POS address + */ + address public constant wethPosAddr = 0xAe740d42E4ff0C5086b2b5b5d149eB2F9e1A754F; + + /** + * @dev WETH address + */ + address public constant wethAddr = 0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619; + + // Storage variables // From 87f884ce489db6120a21e07b5a1bf59d25b4f4f7 Mon Sep 17 00:00:00 2001 From: Thrilok Kumar Date: Wed, 21 Apr 2021 10:04:40 +0530 Subject: [PATCH 3/7] Added depositEtherFor func --- contracts/senders/aave-v2-migrator/interfaces.sol | 1 + contracts/senders/aave-v2-migrator/main.sol | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) 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 2128123..3b34da0 100644 --- a/contracts/senders/aave-v2-migrator/main.sol +++ b/contracts/senders/aave-v2-migrator/main.sol @@ -88,16 +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]); if (_tokens[i] == ethAddr) { 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])); } - rootChainManager.depositFor(polygonReceiver, _tokens[i], abi.encode(_amts[i])); isPositionSafe(); } From 507871cbddb03e28bf6d9ba0aea5ba5bfde1cb2b Mon Sep 17 00:00:00 2001 From: Thrilok Kumar Date: Wed, 21 Apr 2021 21:54:21 +0530 Subject: [PATCH 4/7] Revert WETH fix on receiver --- contracts/receivers/aave-v2-receiver/interfaces.sol | 7 +------ contracts/receivers/aave-v2-receiver/main.sol | 9 +-------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/contracts/receivers/aave-v2-receiver/interfaces.sol b/contracts/receivers/aave-v2-receiver/interfaces.sol index de752af..5ff7f9a 100644 --- a/contracts/receivers/aave-v2-receiver/interfaces.sol +++ b/contracts/receivers/aave-v2-receiver/interfaces.sol @@ -100,9 +100,4 @@ interface AaveInterface { interface InstaListInterface { function accountID(address) external view returns (uint); -} - - -interface WETHTokenInterface { - function deposit(address user, bytes memory depositData) external payable; -} +} \ No newline at end of file diff --git a/contracts/receivers/aave-v2-receiver/main.sol b/contracts/receivers/aave-v2-receiver/main.sol index 62db294..caff527 100644 --- a/contracts/receivers/aave-v2-receiver/main.sol +++ b/contracts/receivers/aave-v2-receiver/main.sol @@ -4,7 +4,7 @@ pragma experimental ABIEncoderV2; import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import { TokenInterface } from "../../common/interfaces.sol"; -import { AccountInterface, AaveData, AaveInterface, IndexInterface, WETHTokenInterface } from "./interfaces.sol"; +import { AccountInterface, AaveData, AaveInterface, IndexInterface } from "./interfaces.sol"; import { Events } from "./events.sol"; import { Helpers } from "./helpers.sol"; @@ -57,13 +57,6 @@ contract MigrateResolver is Helpers, Events { } } - if (_token == wethAddr) { - TokenInterface wethPosContract = TokenInterface(wethPosAddr); - if (wethPosContract.balanceOf(address(this)) > 0) { - WETHTokenInterface(wethAddr).deposit(address(this), abi.encode(wethPosContract.balanceOf(address(this)))); - } - } - IERC20 _tokenContract = IERC20(_token); uint _tokenBal = _tokenContract.balanceOf(address(this)); if (_tokenBal > 0) { From 729f5ab34276960974bd1b6f7435d42386ca3505 Mon Sep 17 00:00:00 2001 From: Thrilok kumar Date: Wed, 21 Apr 2021 21:55:17 +0530 Subject: [PATCH 5/7] Update contracts/receivers/aave-v2-receiver/variables.sol --- contracts/receivers/aave-v2-receiver/variables.sol | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/contracts/receivers/aave-v2-receiver/variables.sol b/contracts/receivers/aave-v2-receiver/variables.sol index e16f60d..bcd8c15 100644 --- a/contracts/receivers/aave-v2-receiver/variables.sol +++ b/contracts/receivers/aave-v2-receiver/variables.sol @@ -41,17 +41,6 @@ contract Variables { */ address public constant maticReceiver = 0x0000000000000000000000000000000000001001; - /** - * @dev WETH POS address - */ - address public constant wethPosAddr = 0xAe740d42E4ff0C5086b2b5b5d149eB2F9e1A754F; - - /** - * @dev WETH address - */ - address public constant wethAddr = 0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619; - - // Storage variables // @@ -77,4 +66,4 @@ contract Variables { * @dev last stateId from the onStateReceive */ uint256 internal lastStateId; -} \ No newline at end of file +} From 4f283c9876167ac090ff007bda493328b484e657 Mon Sep 17 00:00:00 2001 From: Thrilok kumar Date: Wed, 21 Apr 2021 23:43:28 +0530 Subject: [PATCH 6/7] Update contracts/senders/aave-v2-migrator/main.sol Co-authored-by: Samyak Jain <34437877+KaymasJain@users.noreply.github.com> --- contracts/senders/aave-v2-migrator/main.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/senders/aave-v2-migrator/main.sol b/contracts/senders/aave-v2-migrator/main.sol index 3b34da0..9c2ad7e 100644 --- a/contracts/senders/aave-v2-migrator/main.sol +++ b/contracts/senders/aave-v2-migrator/main.sol @@ -89,7 +89,7 @@ contract LiquidityResolver is Helpers, Events { address _token = _tokens[i] == ethAddr ? wethAddr : _tokens[i]; aave.withdraw(_token, _amts[i], address(this)); - if (_tokens[i] == ethAddr) { + if (_token == wethAddr) { TokenInterface wethContract = TokenInterface(wethAddr); uint wethBal = wethContract.balanceOf(address(this)); wethContract.approve(wethAddr, wethBal); @@ -201,4 +201,4 @@ contract InstaAaveV2MigratorSenderImplementation is MigrateResolver { flashloanContract.initiateFlashLoan(data, ethAmt); } -} \ No newline at end of file +}