Skip to content

Commit f72bc33

Browse files
authored
Merge pull request #330 from Instadapp/fix-payback
Fix payback
2 parents 73e2ba1 + ece247d commit f72bc33

File tree

2 files changed

+39
-10
lines changed

2 files changed

+39
-10
lines changed

contracts/mainnet/connectors/aave/v3/main.sol

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,13 @@ abstract contract AaveResolver is Events, Helpers {
263263

264264
TokenInterface tokenContract = TokenInterface(_token);
265265

266-
_amt = _amt == uint256(-1) ? getPaybackBalance(_token, rateMode) : _amt;
266+
if (_amt == uint256(-1)) {
267+
uint256 _amtDSA = isEth
268+
? address(this).balance
269+
: tokenContract.balanceOf(address(this));
270+
uint256 _amtDebt = getPaybackBalance(_token, rateMode);
271+
_amt = _amtDSA > _amtDebt ? _amtDebt : _amtDSA;
272+
}
267273

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

@@ -351,9 +357,17 @@ abstract contract AaveResolver is Events, Helpers {
351357

352358
TokenInterface tokenContract = TokenInterface(_token);
353359

354-
_amt = _amt == uint256(-1)
355-
? getOnBehalfOfPaybackBalance(_token, rateMode, onBehalfOf)
356-
: _amt;
360+
if (_amt == uint256(-1)) {
361+
uint256 _amtDSA = isEth
362+
? address(this).balance
363+
: tokenContract.balanceOf(address(this));
364+
uint256 _amtDebt = getOnBehalfOfPaybackBalance(
365+
_token,
366+
rateMode,
367+
onBehalfOf
368+
);
369+
_amt = _amtDSA > _amtDebt ? _amtDebt : _amtDSA;
370+
}
357371

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

@@ -517,5 +531,5 @@ abstract contract AaveResolver is Events, Helpers {
517531
}
518532

519533
contract ConnectV2AaveV3 is AaveResolver {
520-
string public constant name = "AaveV3-v1.1";
534+
string public constant name = "AaveV3-v1.2";
521535
}

contracts/mainnet/connectors/spark/main.sol

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,14 @@ abstract contract SparkConnector is Events, Helpers {
262262
address _token = isEth ? wethAddr : token;
263263

264264
TokenInterface tokenContract = TokenInterface(_token);
265-
_amt = _amt == uint256(-1) ? getPaybackBalance(_token, rateMode) : _amt;
265+
266+
if (_amt == uint256(-1)) {
267+
uint256 _amtDSA = isEth
268+
? address(this).balance
269+
: tokenContract.balanceOf(address(this));
270+
uint256 _amtDebt = getPaybackBalance(_token, rateMode);
271+
_amt = _amtDSA > _amtDebt ? _amtDebt : _amtDSA;
272+
}
266273

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

@@ -350,9 +357,17 @@ abstract contract SparkConnector is Events, Helpers {
350357

351358
TokenInterface tokenContract = TokenInterface(_token);
352359

353-
_amt = _amt == uint256(-1)
354-
? getOnBehalfOfPaybackBalance(_token, rateMode, onBehalfOf)
355-
: _amt;
360+
if (_amt == uint256(-1)) {
361+
uint256 _amtDSA = isEth
362+
? address(this).balance
363+
: tokenContract.balanceOf(address(this));
364+
uint256 _amtDebt = getOnBehalfOfPaybackBalance(
365+
_token,
366+
rateMode,
367+
onBehalfOf
368+
);
369+
_amt = _amtDSA > _amtDebt ? _amtDebt : _amtDSA;
370+
}
356371

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

@@ -511,5 +526,5 @@ abstract contract SparkConnector is Events, Helpers {
511526
}
512527

513528
contract ConnectV2Spark is SparkConnector {
514-
string public constant name = "Spark-v1.0";
529+
string public constant name = "Spark-v1.1";
515530
}

0 commit comments

Comments
 (0)