feat: fix payback in spark and aave v3

This commit is contained in:
Shriya Tyagi 2024-02-14 23:29:59 +04:00
parent ca7879da10
commit eb053692e8
2 changed files with 37 additions and 8 deletions

View File

@ -263,7 +263,13 @@ abstract contract AaveResolver is Events, Helpers {
TokenInterface tokenContract = TokenInterface(_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 ? _amtDSA : _amtDebt;
}
if (isEth) convertEthToWeth(isEth, tokenContract, _amt); if (isEth) convertEthToWeth(isEth, tokenContract, _amt);
@ -351,9 +357,17 @@ abstract contract AaveResolver is Events, Helpers {
TokenInterface tokenContract = TokenInterface(_token); TokenInterface tokenContract = TokenInterface(_token);
_amt = _amt == uint256(-1) if (_amt == uint256(-1)) {
? getOnBehalfOfPaybackBalance(_token, rateMode, onBehalfOf) uint256 _amtDSA = isEth
: _amt; ? address(this).balance
: tokenContract.balanceOf(address(this));
uint256 _amtDebt = getOnBehalfOfPaybackBalance(
_token,
rateMode,
onBehalfOf
);
_amt = _amtDSA <= _amtDebt ? _amtDSA : _amtDebt;
}
if (isEth) convertEthToWeth(isEth, tokenContract, _amt); if (isEth) convertEthToWeth(isEth, tokenContract, _amt);

View File

@ -262,7 +262,14 @@ abstract contract SparkConnector is Events, Helpers {
address _token = isEth ? wethAddr : token; address _token = isEth ? wethAddr : token;
TokenInterface tokenContract = TokenInterface(_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 ? _amtDSA : _amtDebt;
}
if (isEth) convertEthToWeth(isEth, tokenContract, _amt); if (isEth) convertEthToWeth(isEth, tokenContract, _amt);
@ -350,9 +357,17 @@ abstract contract SparkConnector is Events, Helpers {
TokenInterface tokenContract = TokenInterface(_token); TokenInterface tokenContract = TokenInterface(_token);
_amt = _amt == uint256(-1) if (_amt == uint256(-1)) {
? getOnBehalfOfPaybackBalance(_token, rateMode, onBehalfOf) uint256 _amtDSA = isEth
: _amt; ? address(this).balance
: tokenContract.balanceOf(address(this));
uint256 _amtDebt = getOnBehalfOfPaybackBalance(
_token,
rateMode,
onBehalfOf
);
_amt = _amtDSA <= _amtDebt ? _amtDSA : _amtDebt;
}
if (isEth) convertEthToWeth(isEth, tokenContract, _amt); if (isEth) convertEthToWeth(isEth, tokenContract, _amt);