From 1f645c37ce31b53014bc23d434ab16bac9ce5b03 Mon Sep 17 00:00:00 2001 From: Thrilok Kumar Date: Thu, 15 Apr 2021 21:45:04 +0530 Subject: [PATCH] Fixed atoken transfer amount bug --- .../senders/aave-v2-migrator/helpers.sol | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/contracts/senders/aave-v2-migrator/helpers.sol b/contracts/senders/aave-v2-migrator/helpers.sol index 12c4369..b6ddcce 100644 --- a/contracts/senders/aave-v2-migrator/helpers.sol +++ b/contracts/senders/aave-v2-migrator/helpers.sol @@ -82,23 +82,23 @@ abstract contract Helpers is DSMath, Stores, Variables { ,,,,, ) = aaveData.getUserReserveData(_token, sourceDsa); - console.log("debts", stableDebt, variableDebt); - console.log("token", _token); - console.log("stableBorrowAmts", _data.stableBorrowAmts[i]); + // 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]); + // console.log("stableBorrow", stableBorrow[i]); + // console.log("variableBorrow", variableBorrow[i]); totalBorrow[i] = add(stableBorrow[i], variableBorrow[i]); - console.log("totalBorrow", totalBorrow[i]); + // console.log("totalBorrow", totalBorrow[i]); if (totalBorrow[i] > 0) { IERC20(_token).safeApprove(address(aave), totalBorrow[i]); } - console.log("approved", IERC20(_token).allowance(address(this), address(aave))); + // 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))); } @@ -123,8 +123,12 @@ abstract contract Helpers is DSMath, Stores, Variables { } else { _finalAmt = supplyAmts[i]; } - - aTokenContract.transferFrom(dsa, address(this), finalAmts[i]); + console.log("balanceOf inital this", aTokenContract.balanceOf(address(this))); + console.log("balanceOf inital dsa", aTokenContract.balanceOf(dsa)); + console.log("_finalAmt", _finalAmt); + console.log("allownace", IERC20(_aToken).allowance(dsa, address(this))); + require(aTokenContract.transferFrom(dsa, address(this), _finalAmt), "_getAtokens: atokens transfer failed"); + console.log("balanceOf final", aTokenContract.balanceOf(address(this))); _finalAmt = wmul(_finalAmt, fee); finalAmts[i] = _finalAmt;