From d4a432d774c0045f1370414ba7c8eb5fae4eb787 Mon Sep 17 00:00:00 2001 From: Thrilok Kumar Date: Thu, 15 Apr 2021 19:27:55 +0530 Subject: [PATCH] Fixed invaild opcode issue --- .../senders/aave-v2-migrator/helpers.sol | 27 ++++++++++++++++--- hardhat.config.js | 2 +- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/contracts/senders/aave-v2-migrator/helpers.sol b/contracts/senders/aave-v2-migrator/helpers.sol index 435ded5..3ca3b01 100644 --- a/contracts/senders/aave-v2-migrator/helpers.sol +++ b/contracts/senders/aave-v2-migrator/helpers.sol @@ -56,8 +56,21 @@ abstract contract Helpers is DSMath, Stores, Variables { } } - function _PaybackCalculate(AaveInterface aave, AaveDataRaw memory _data, address sourceDsa) internal returns (uint[] memory stableBorrow, uint[] memory variableBorrow, uint[] memory totalBorrow) { - for (uint i = 0; i < _data.borrowTokens.length; i++) { + function _PaybackCalculate( + AaveInterface aave, + AaveDataRaw memory _data, + address sourceDsa + ) internal returns ( + uint[] memory stableBorrow, + uint[] memory variableBorrow, + uint[] memory totalBorrow + ) { + uint _len = _data.borrowTokens.length; + stableBorrow = new uint256[](_len); + variableBorrow = new uint256[](_len); + totalBorrow = new uint256[](_len); + + for (uint i = 0; i < _len; i++) { require(isSupportedToken[_data.borrowTokens[i]], "token-not-enabled"); address _token = _data.borrowTokens[i] == ethAddr ? wethAddr : _data.borrowTokens[i]; _data.borrowTokens[i] = _token; @@ -71,15 +84,23 @@ abstract contract Helpers is DSMath, Stores, Variables { console.log("debts", stableDebt, variableDebt); console.log("token", _token); + console.log("stableBorrowAmts", _data.stableBorrowAmts[i]); + stableBorrow[i] = _data.stableBorrowAmts[i] == uint(-1) ? stableDebt : _data.stableBorrowAmts[i]; // Failing here?? 'invalid-opcode' variableBorrow[i] = _data.variableBorrowAmts[i] == uint(-1) ? variableDebt : _data.variableBorrowAmts[i]; + console.log("stableBorrow", stableBorrow[i]); + console.log("variableBorrow", variableBorrow[i]); totalBorrow[i] = add(stableBorrow[i], variableBorrow[i]); + console.log("totalBorrow", totalBorrow[i]); + if (totalBorrow[i] > 0) { IERC20(_token).safeApprove(address(aave), totalBorrow[i]); } - aave.borrow(_token, totalBorrow[i], 2, 3288, address(this)); + console.log("approved", IERC20(_token).allowance(address(this), address(aave))); + aave.borrow(_token, totalBorrow[i], 2, 3288, address(this)); // Failing over here /// + console.log("balanceOf", IERC20(_token).balanceOf(address(this))); } } diff --git a/hardhat.config.js b/hardhat.config.js index cc71004..2231bbd 100644 --- a/hardhat.config.js +++ b/hardhat.config.js @@ -25,7 +25,7 @@ module.exports = { hardhat: { forking: { url: `https://eth-mainnet.alchemyapi.io/v2/${ALCHEMY_ID}`, - blockNumber: 12068005, + blockNumber: 12240294, }, blockGasLimit: 12000000, },