Skip to content

Commit

Permalink
✅ contracts: add repays assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
itofarina committed Nov 29, 2024
1 parent 39a1bb2 commit 5be53e2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
16 changes: 8 additions & 8 deletions contracts/.gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ ExaPluginTest:test_collectInstallments_reverts_whenExpired() (gas: 338273)
ExaPluginTest:test_collectInstallments_reverts_whenReplay() (gas: 1032370)
ExaPluginTest:test_collectInstallments_reverts_whenTimelocked() (gas: 334767)
ExaPluginTest:test_collectInstallments_toleratesTimeDrift() (gas: 1157080)
ExaPluginTest:test_crossRepay_repays() (gas: 18376728)
ExaPluginTest:test_crossRepay_repays_whenKeeper() (gas: 18376777)
ExaPluginTest:test_debitCollateral_collects() (gas: 18504063)
ExaPluginTest:test_lifiSwap_reverts_withDisagreement() (gas: 15793131)
ExaPluginTest:test_lifiSwap_swaps() (gas: 15481932)
ExaPluginTest:test_crossRepay_repays() (gas: 20002130)
ExaPluginTest:test_crossRepay_repays_whenKeeper() (gas: 19992259)
ExaPluginTest:test_debitCollateral_collects() (gas: 20119545)
ExaPluginTest:test_lifiSwap_reverts_withDisagreement() (gas: 17516987)
ExaPluginTest:test_lifiSwap_swaps() (gas: 17233414)
ExaPluginTest:test_onUninstall_uninstalls() (gas: 241212)
ExaPluginTest:test_poke() (gas: 293566)
ExaPluginTest:test_pokeETH_deposits() (gas: 364686)
ExaPluginTest:test_propose_emitsProposed() (gas: 208770)
ExaPluginTest:test_refund_refunds() (gas: 361535)
ExaPluginTest:test_repay_partiallyRepays() (gas: 1729554)
ExaPluginTest:test_repay_repays() (gas: 1138661)
ExaPluginTest:test_repay_repays_whenKeeper() (gas: 1098863)
ExaPluginTest:test_repay_partiallyRepays() (gas: 1721048)
ExaPluginTest:test_repay_repays() (gas: 1143585)
ExaPluginTest:test_repay_repays_whenKeeper() (gas: 1095818)
ExaPluginTest:test_rollDebt_rolls() (gas: 1184442)
ExaPluginTest:test_setCollector_emitsCollectorSet() (gas: 40443)
ExaPluginTest:test_setCollector_reverts_whenAddressZero() (gas: 32206)
Expand Down
34 changes: 27 additions & 7 deletions contracts/test/ExaPlugin.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -754,11 +754,16 @@ contract ExaPluginTest is ForkTest {
function test_repay_repays() external {
vm.startPrank(keeper);
account.poke(exaUSDC);
account.collectCredit(FixedLib.INTERVAL, 100e6, block.timestamp, _issuerOp(100e6, block.timestamp));
uint256 maturity = FixedLib.INTERVAL;
account.collectCredit(maturity, 100e6, block.timestamp, _issuerOp(100e6, block.timestamp));

FixedPosition memory position = exaUSDC.fixedBorrowPositions(maturity, address(account));
assertEq(position.principal, 100e6);
vm.startPrank(owner);
account.execute(address(account), 0, abi.encodeCall(IExaAccount.repay, (FixedLib.INTERVAL)));
account.execute(address(account), 0, abi.encodeCall(IExaAccount.repay, (maturity)));
assertEq(usdc.balanceOf(address(exaPlugin)), 0, "usdc dust");
position = exaUSDC.fixedBorrowPositions(maturity, address(account));
assertEq(position.principal, 0);
}

function test_repay_repays_whenKeeper() external {
Expand All @@ -772,20 +777,28 @@ contract ExaPluginTest is ForkTest {
account.repay(maturity);

assertEq(usdc.balanceOf(address(exaPlugin)), 0, "usdc dust");
(uint256 positionAssets, ) = _previewRepay(maturity, address(account));
assertEq(positionAssets, 0);
position = exaUSDC.fixedBorrowPositions(maturity, address(account));
assertEq(position.principal, 0);
}

function test_repay_partiallyRepays() external {
vm.startPrank(keeper);
account.poke(exaUSDC);
account.poke(exaEXA);
account.collectCredit(FixedLib.INTERVAL, 100_000e6 + 1, block.timestamp, _issuerOp(100_000e6 + 1, block.timestamp));
uint256 maturity = FixedLib.INTERVAL;
account.collectCredit(maturity, 100_000e6 + 1, block.timestamp, _issuerOp(100_000e6 + 1, block.timestamp));

FixedPosition memory position = exaUSDC.fixedBorrowPositions(maturity, address(account));
uint256 prevPrincipal = position.principal;
assertGt(prevPrincipal, 0);

assertEq(exaUSDC.maxWithdraw(address(account)), 100_000e6);
vm.startPrank(owner);
account.execute(address(account), 0, abi.encodeCall(IExaAccount.repay, (FixedLib.INTERVAL)));
account.execute(address(account), 0, abi.encodeCall(IExaAccount.repay, (maturity)));
assertEq(usdc.balanceOf(address(exaPlugin)), 0, "usdc dust");

position = exaUSDC.fixedBorrowPositions(maturity, address(account));
assertGt(prevPrincipal, position.principal, "fixed debt didn't decrease");
assertGt(position.principal, 0, "fixed debt is zero");
}

function test_crossRepay_repays() external {
Expand All @@ -802,11 +815,17 @@ contract ExaPluginTest is ForkTest {
hex"00000000000000000000000000000000000000000000000000000000018f7705000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000000034578610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002a30783030303030303030303030303030303030303030303030303030303030303030303030303030303000000000000000000000000000000000000000000000000000000000000000000000111111125421ca6dc452d289314280a0f8842a65000000000000000000000000111111125421ca6dc452d289314280a0f8842a6500000000000000000000000068f180fcce6836688e9084f035309e29bf0a20950000000000000000000000000b2c639c533813f4aa9d7837caf62653d097ff850000000000000000000000000000000000000000000000000000000000009c4000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000004e807ed2379000000000000000000000000b63aae6c353636d66df13b89ba4425cfe13d10ba00000000000000000000000068f180fcce6836688e9084f035309e29bf0a20950000000000000000000000000b2c639c533813f4aa9d7837caf62653d097ff85000000000000000000000000b63aae6c353636d66df13b89ba4425cfe13d10ba0000000000000000000000001231deb6f5749ef6ce6943a275a1d3e7486f4eae0000000000000000000000000000000000000000000000000000000000009c4000000000000000000000000000000000000000000000000000000000018f770400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000039600000000000000000000000000000000000000000000000000000000037800a007e5c0d20000000000000000000000000000000000000000000000000003540000f051204c4af8dbc524681930a27b2f1af5bcc8062e6fb768f180fcce6836688e9084f035309e29bf0a209500447dc2038200000000000000000000000068f180fcce6836688e9084f035309e29bf0a209500000000000000000000000042000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000002495763e3d93b6000000000000000000000000b63aae6c353636d66df13b89ba4425cfe13d10ba00000000000000000000000042f527f50f16a103b6ccab48bccca214500c102100a0c9e75c480000000000000013130c0000000000000000000000000000000000000000000002360001d300006302a000000000000000000000000000000000000000000000000000000000005f6305ee63c1e580c1738d90e2e26c35784a0d3e3d8a9f795074bca44200000000000000000000000000000000000006111111125421ca6dc452d289314280a0f8842a655106a062ae8a9c5e11aaa026fc2670b0d65ccc8b285842000000000000000000000000000000000000060004cac88ea9000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009708bd00000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000111111125421ca6dc452d289314280a0f8842a6500000000000000000000000000000000000000000000000000000000671fb839000000000000000000000000000000000000000000000000000000000000000100000000000000000000000042000000000000000000000000000000000000060000000000000000000000000b2c639c533813f4aa9d7837caf62653d097ff850000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f1046053aa5682b4f9a81b5481394da16be5ff5a02a0000000000000000000000000000000000000000000000000000000000097095eee63c1e580d4cb5566b5c16ef2f4a08b1438052013171212a24200000000000000000000000000000000000006111111125421ca6dc452d289314280a0f8842a65000000000000000000002a94d114000000000000000000000000000000000000000000000000"
);
uint256 prevCollateral = exaWBTC.balanceOf(address(account));
FixedPosition memory position = exaUSDC.fixedBorrowPositions(maturity, address(account));
uint256 prevPrincipal = position.principal;
assertGt(prevPrincipal, 0);

vm.startPrank(address(account));
account.crossRepay(maturity, 21e6, 25e6, exaWBTC, amount, route);
assertEq(usdc.balanceOf(address(exaPlugin)), 0, "usdc dust");
assertGt(prevCollateral, exaWBTC.balanceOf(address(account)), "collateral didn't decrease");

position = exaUSDC.fixedBorrowPositions(maturity, address(account));
assertGt(prevPrincipal, position.principal, "fixed debt didn't decrease");
}

function test_crossRepay_repays_whenKeeper() external {
Expand Down Expand Up @@ -1019,6 +1038,7 @@ contract ExaPluginTest is ForkTest {

exaPlugin.grantRole(exaPlugin.KEEPER_ROLE(), keeper);
usdc = MockERC20(protocol("USDC"));
exaUSDC = IMarket(protocol("MarketUSDC"));

vm.startPrank(address(account));
account.execute(
Expand Down

0 comments on commit 5be53e2

Please sign in to comment.