Skip to content

Commit

Permalink
Merge pull request #330 from Instadapp/fix-payback
Browse files Browse the repository at this point in the history
Fix payback
  • Loading branch information
shriyatyagii authored Feb 17, 2024
2 parents 73e2ba1 + ece247d commit f72bc33
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
24 changes: 19 additions & 5 deletions contracts/mainnet/connectors/aave/v3/main.sol
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,13 @@ abstract contract AaveResolver is Events, Helpers {

TokenInterface tokenContract = TokenInterface(_token);

_amt = _amt == uint256(-1) ? getPaybackBalance(_token, rateMode) : _amt;
if (_amt == uint256(-1)) {
uint256 _amtDSA = isEth
? address(this).balance
: tokenContract.balanceOf(address(this));
uint256 _amtDebt = getPaybackBalance(_token, rateMode);
_amt = _amtDSA > _amtDebt ? _amtDebt : _amtDSA;
}

if (isEth) convertEthToWeth(isEth, tokenContract, _amt);

Expand Down Expand Up @@ -351,9 +357,17 @@ abstract contract AaveResolver is Events, Helpers {

TokenInterface tokenContract = TokenInterface(_token);

_amt = _amt == uint256(-1)
? getOnBehalfOfPaybackBalance(_token, rateMode, onBehalfOf)
: _amt;
if (_amt == uint256(-1)) {
uint256 _amtDSA = isEth
? address(this).balance
: tokenContract.balanceOf(address(this));
uint256 _amtDebt = getOnBehalfOfPaybackBalance(
_token,
rateMode,
onBehalfOf
);
_amt = _amtDSA > _amtDebt ? _amtDebt : _amtDSA;
}

if (isEth) convertEthToWeth(isEth, tokenContract, _amt);

Expand Down Expand Up @@ -517,5 +531,5 @@ abstract contract AaveResolver is Events, Helpers {
}

contract ConnectV2AaveV3 is AaveResolver {
string public constant name = "AaveV3-v1.1";
string public constant name = "AaveV3-v1.2";
}
25 changes: 20 additions & 5 deletions contracts/mainnet/connectors/spark/main.sol
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,14 @@ abstract contract SparkConnector is Events, Helpers {
address _token = isEth ? wethAddr : token;

TokenInterface tokenContract = TokenInterface(_token);
_amt = _amt == uint256(-1) ? getPaybackBalance(_token, rateMode) : _amt;

if (_amt == uint256(-1)) {
uint256 _amtDSA = isEth
? address(this).balance
: tokenContract.balanceOf(address(this));
uint256 _amtDebt = getPaybackBalance(_token, rateMode);
_amt = _amtDSA > _amtDebt ? _amtDebt : _amtDSA;
}

if (isEth) convertEthToWeth(isEth, tokenContract, _amt);

Expand Down Expand Up @@ -350,9 +357,17 @@ abstract contract SparkConnector is Events, Helpers {

TokenInterface tokenContract = TokenInterface(_token);

_amt = _amt == uint256(-1)
? getOnBehalfOfPaybackBalance(_token, rateMode, onBehalfOf)
: _amt;
if (_amt == uint256(-1)) {
uint256 _amtDSA = isEth
? address(this).balance
: tokenContract.balanceOf(address(this));
uint256 _amtDebt = getOnBehalfOfPaybackBalance(
_token,
rateMode,
onBehalfOf
);
_amt = _amtDSA > _amtDebt ? _amtDebt : _amtDSA;
}

if (isEth) convertEthToWeth(isEth, tokenContract, _amt);

Expand Down Expand Up @@ -511,5 +526,5 @@ abstract contract SparkConnector is Events, Helpers {
}

contract ConnectV2Spark is SparkConnector {
string public constant name = "Spark-v1.0";
string public constant name = "Spark-v1.1";
}

0 comments on commit f72bc33

Please sign in to comment.