Skip to content

Commit 7fe3a08

Browse files
authored
5 - Dust when depositing AToken in the vault (#39)
1 parent c651e35 commit 7fe3a08

File tree

6 files changed

+159
-97
lines changed

6 files changed

+159
-97
lines changed
+4-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
21
contract DummyContract {
3-
function havoc_all_dummy() external {
4-
// havoc_all_dummy_internal();
5-
}
2+
function havoc_all_dummy() external {
3+
// havoc_all_dummy_internal();
4+
}
65

7-
//function havoc_all_dummy_internal() internal {}
6+
//function havoc_all_dummy_internal() internal {}
87
}

certora/basic/harness/EModeConfigurationHarness.sol

+16-8
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,29 @@ contract EModeConfigurationHarness {
1010

1111
function setCollateral(uint256 reserveIndex, bool enabled) public {
1212
DataTypes.EModeCategory memory emode_new = eModeCategory;
13-
eModeCategory.collateralBitmap = EModeConfiguration.setReserveBitmapBit(emode_new.collateralBitmap, reserveIndex, enabled);
13+
eModeCategory.collateralBitmap = EModeConfiguration.setReserveBitmapBit(
14+
emode_new.collateralBitmap,
15+
reserveIndex,
16+
enabled
17+
);
1418
}
1519

1620
function isCollateralAsset(uint256 reserveIndex) public returns (bool) {
17-
return EModeConfiguration.isReserveEnabledOnBitmap(eModeCategory.collateralBitmap, reserveIndex);
21+
return
22+
EModeConfiguration.isReserveEnabledOnBitmap(eModeCategory.collateralBitmap, reserveIndex);
1823
}
1924

20-
21-
22-
function setBorrowable(uint256 reserveIndex,bool enabled) public {
25+
function setBorrowable(uint256 reserveIndex, bool enabled) public {
2326
DataTypes.EModeCategory memory emode_new = eModeCategory;
24-
eModeCategory.borrowableBitmap = EModeConfiguration.setReserveBitmapBit(emode_new.borrowableBitmap, reserveIndex, enabled);
27+
eModeCategory.borrowableBitmap = EModeConfiguration.setReserveBitmapBit(
28+
emode_new.borrowableBitmap,
29+
reserveIndex,
30+
enabled
31+
);
2532
}
26-
33+
2734
function isBorrowableAsset(uint256 reserveIndex) public returns (bool) {
28-
return EModeConfiguration.isReserveEnabledOnBitmap(eModeCategory.borrowableBitmap, reserveIndex);
35+
return
36+
EModeConfiguration.isReserveEnabledOnBitmap(eModeCategory.borrowableBitmap, reserveIndex);
2937
}
3038
}

certora/basic/harness/PoolInstanceHarness.sol

+10-10
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ import {DataTypes} from '../munged/contracts/protocol/libraries/types/DataTypes.
88
import {ReserveLogic} from '../munged/contracts/protocol/libraries/logic/ReserveLogic.sol';
99
import {WadRayMath} from '../munged/contracts/protocol/libraries/math/WadRayMath.sol';
1010

11-
import {DummyContract} from "./DummyContract.sol";
12-
11+
import {DummyContract} from './DummyContract.sol';
1312

1413
contract PoolInstanceHarness is PoolInstance {
1514
DummyContract DUMMY;
1615

1716
constructor(IPoolAddressesProvider provider) PoolInstance(provider) {}
1817

19-
function cumulateToLiquidityIndex(address asset,
20-
uint256 totalLiquidity,
21-
uint256 amount
22-
) external returns (uint256) {
18+
function cumulateToLiquidityIndex(
19+
address asset,
20+
uint256 totalLiquidity,
21+
uint256 amount
22+
) external returns (uint256) {
2323
return ReserveLogic.cumulateToLiquidityIndex(_reserves[asset], totalLiquidity, amount);
2424
}
2525

@@ -34,12 +34,12 @@ contract PoolInstanceHarness is PoolInstance {
3434
function havoc_all() public {
3535
DUMMY.havoc_all_dummy();
3636
}
37-
37+
3838
function rayMul(uint256 a, uint256 b) external returns (uint256) {
39-
return WadRayMath.rayMul(a,b);
39+
return WadRayMath.rayMul(a, b);
4040
}
41-
41+
4242
function rayDiv(uint256 a, uint256 b) external returns (uint256) {
43-
return WadRayMath.rayDiv(a,b);
43+
return WadRayMath.rayDiv(a, b);
4444
}
4545
}

certora/stata/harness/pool/SymbolicLendingPool.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ contract SymbolicLendingPool {
8080
res.isolationModeTotalDebt = reserveLegacy.isolationModeTotalDebt;
8181
return res;
8282
}
83-
83+
8484
function getReserveDataExtended(
8585
address asset
8686
) external view returns (DataTypes.ReserveData memory) {

src/contracts/extensions/static-a-token/ERC4626StataTokenUpgradeable.sol

+23-4
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ abstract contract ERC4626StataTokenUpgradeable is ERC4626Upgradeable, IERC4626St
7575

7676
///@inheritdoc IERC4626StataToken
7777
function depositATokens(uint256 assets, address receiver) external returns (uint256) {
78+
// because aToken is rebasable, we allow user to specify more then he has to compensate growth during the tx mining
79+
uint256 actualUserBalance = IERC20(aToken()).balanceOf(_msgSender());
80+
if (assets > actualUserBalance) {
81+
assets = actualUserBalance;
82+
}
83+
7884
uint256 shares = previewDeposit(assets);
7985
_deposit(_msgSender(), receiver, assets, shares, false);
8086

@@ -89,14 +95,27 @@ abstract contract ERC4626StataTokenUpgradeable is ERC4626Upgradeable, IERC4626St
8995
SignatureParams memory sig,
9096
bool depositToAave
9197
) external returns (uint256) {
92-
IERC20Permit assetToDeposit = IERC20Permit(
93-
depositToAave ? asset() : address(_getERC4626StataTokenStorage()._aToken)
94-
);
98+
address assetToDeposit = depositToAave ? asset() : aToken();
9599

96100
try
97-
assetToDeposit.permit(_msgSender(), address(this), assets, deadline, sig.v, sig.r, sig.s)
101+
IERC20Permit(assetToDeposit).permit(
102+
_msgSender(),
103+
address(this),
104+
assets,
105+
deadline,
106+
sig.v,
107+
sig.r,
108+
sig.s
109+
)
98110
{} catch {}
99111

112+
// because aToken is rebasable, we allow user to specify more then he has to compensate growth during the tx mining
113+
// to make it consistent, we keep the same behaviour for the normal underlying too
114+
uint256 actualUserBalance = IERC20(assetToDeposit).balanceOf(_msgSender());
115+
if (assets > actualUserBalance) {
116+
assets = actualUserBalance;
117+
}
118+
100119
uint256 shares = previewDeposit(assets);
101120
_deposit(_msgSender(), receiver, assets, shares, depositToAave);
102121
return shares;

0 commit comments

Comments
 (0)