Skip to content

Commit

Permalink
⚡️ contracts: cache usdc as immutable
Browse files Browse the repository at this point in the history
  • Loading branch information
cruzdanilo committed Jan 7, 2025
1 parent 30cf54f commit b50653e
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 76 deletions.
140 changes: 70 additions & 70 deletions contracts/.gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,75 +1,75 @@
ExaAccountFactoryTest:testFuzz_createAccount_EOAOwners(uint256,address[63]) (runs: 256, μ: 3581832, ~: 3439966)
ExaAccountFactoryTest:test_deploy_deploysToSameAddress() (gas: 25698785)
ExaPluginTest:testFork_crossRepay_repays() (gas: 14965414)
ExaPluginTest:testFork_debitCollateral_collects() (gas: 15052899)
ExaPluginTest:testFork_swap_swaps() (gas: 12231146)
ExaPluginTest:test_borrowAtMaturity_reverts_withUnauthorized_whenReceiverNotCollector() (gas: 408782)
ExaPluginTest:test_borrow_reverts_withUnauthorized_whenReceiverNotCollector() (gas: 408338)
ExaPluginTest:test_collectCredit_collects() (gas: 918651)
ExaPluginTest:test_collectCredit_collects_whenHealthFactorHigherThanOne() (gas: 799280)
ExaPluginTest:test_collectCredit_collects_withEnoughSlippage() (gas: 797905)
ExaPluginTest:test_collectCredit_collects_withPrevIssuerSignature() (gas: 994489)
ExaPluginTest:test_collectCredit_passes_whenProposalLeavesEnoughLiquidity() (gas: 1007687)
ExaPluginTest:test_collectCredit_reverts_asNotKeeper() (gas: 362585)
ExaPluginTest:test_collectCredit_reverts_whenDisagreement() (gas: 555970)
ExaPluginTest:test_collectCredit_reverts_whenExpired() (gas: 358687)
ExaPluginTest:test_collectCredit_reverts_whenHealthFactorLowerThanOne() (gas: 997935)
ExaPluginTest:test_collectCredit_reverts_whenPrevSignatureNotValidAnymore() (gas: 461452)
ExaPluginTest:test_collectCredit_reverts_whenProposalCausesInsufficientLiquidity() (gas: 1007841)
ExaPluginTest:test_collectCredit_reverts_whenReplay() (gas: 840914)
ExaPluginTest:test_collectCredit_reverts_whenTimelocked() (gas: 354855)
ExaPluginTest:test_collectCredit_toleratesTimeDrift() (gas: 801294)
ExaPluginTest:test_collectDebit_collects() (gas: 651494)
ExaPluginTest:test_collectDebit_collects_whenProposalLeavesEnoughLiquidity() (gas: 854893)
ExaPluginTest:test_collectDebit_reverts_asNotKeeper() (gas: 362396)
ExaPluginTest:test_collectDebit_reverts_whenExpired() (gas: 358382)
ExaPluginTest:test_collectDebit_reverts_whenProposalCausesInsufficientLiquidity() (gas: 851781)
ExaPluginTest:test_collectDebit_reverts_whenReplay() (gas: 690912)
ExaPluginTest:test_collectDebit_reverts_whenTimelocked() (gas: 354663)
ExaPluginTest:test_collectDebit_toleratesTimeDrift() (gas: 651590)
ExaPluginTest:test_collectInstallments_collects() (gas: 1336326)
ExaPluginTest:test_collectInstallments_revertsWhenNoSlippage() (gas: 1202745)
ExaPluginTest:test_collectInstallments_reverts_asNotKeeper() (gas: 363437)
ExaPluginTest:test_collectInstallments_reverts_whenExpired() (gas: 360670)
ExaPluginTest:test_collectInstallments_reverts_whenReplay() (gas: 1068220)
ExaPluginTest:test_collectInstallments_reverts_whenTimelocked() (gas: 356959)
ExaPluginTest:test_collectInstallments_toleratesTimeDrift() (gas: 1192944)
ExaPluginTest:test_crossRepay_repays() (gas: 1465030)
ExaPluginTest:test_crossRepay_repays_whenKeeper() (gas: 1461809)
ExaPluginTest:test_crossRepay_reverts_whenDisagreement() (gas: 1574262)
ExaPluginTest:test_crossRepay_reverts_whenNotKeeper() (gas: 958548)
ExaPluginTest:test_debitCollateral_collects() (gas: 776479)
ExaPluginTest:test_exitMarket_reverts() (gas: 388956)
ExaPluginTest:test_marketWithdraw_transfersAsset_asOwner() (gas: 818702)
ExaPluginTest:test_onUninstall_uninstalls() (gas: 284160)
ExaPluginTest:test_poke() (gas: 315801)
ExaPluginTest:test_pokeETH_deposits() (gas: 378980)
ExaPluginTest:test_propose_emitsProposed() (gas: 218639)
ExaAccountFactoryTest:testFuzz_createAccount_EOAOwners(uint256,address[63]) (runs: 256, μ: 3631040, ~: 3499447)
ExaAccountFactoryTest:test_deploy_deploysToSameAddress() (gas: 25548411)
ExaPluginTest:testFork_crossRepay_repays() (gas: 14881932)
ExaPluginTest:testFork_debitCollateral_collects() (gas: 14970549)
ExaPluginTest:testFork_swap_swaps() (gas: 12152016)
ExaPluginTest:test_borrowAtMaturity_reverts_withUnauthorized_whenReceiverNotCollector() (gas: 408716)
ExaPluginTest:test_borrow_reverts_withUnauthorized_whenReceiverNotCollector() (gas: 408272)
ExaPluginTest:test_collectCredit_collects() (gas: 918497)
ExaPluginTest:test_collectCredit_collects_whenHealthFactorHigherThanOne() (gas: 799126)
ExaPluginTest:test_collectCredit_collects_withEnoughSlippage() (gas: 797751)
ExaPluginTest:test_collectCredit_collects_withPrevIssuerSignature() (gas: 994335)
ExaPluginTest:test_collectCredit_passes_whenProposalLeavesEnoughLiquidity() (gas: 1007445)
ExaPluginTest:test_collectCredit_reverts_asNotKeeper() (gas: 362431)
ExaPluginTest:test_collectCredit_reverts_whenDisagreement() (gas: 555816)
ExaPluginTest:test_collectCredit_reverts_whenExpired() (gas: 358555)
ExaPluginTest:test_collectCredit_reverts_whenHealthFactorLowerThanOne() (gas: 997693)
ExaPluginTest:test_collectCredit_reverts_whenPrevSignatureNotValidAnymore() (gas: 461298)
ExaPluginTest:test_collectCredit_reverts_whenProposalCausesInsufficientLiquidity() (gas: 1007599)
ExaPluginTest:test_collectCredit_reverts_whenReplay() (gas: 840672)
ExaPluginTest:test_collectCredit_reverts_whenTimelocked() (gas: 354701)
ExaPluginTest:test_collectCredit_toleratesTimeDrift() (gas: 801140)
ExaPluginTest:test_collectDebit_collects() (gas: 651340)
ExaPluginTest:test_collectDebit_collects_whenProposalLeavesEnoughLiquidity() (gas: 854651)
ExaPluginTest:test_collectDebit_reverts_asNotKeeper() (gas: 362242)
ExaPluginTest:test_collectDebit_reverts_whenExpired() (gas: 358250)
ExaPluginTest:test_collectDebit_reverts_whenProposalCausesInsufficientLiquidity() (gas: 851539)
ExaPluginTest:test_collectDebit_reverts_whenReplay() (gas: 690670)
ExaPluginTest:test_collectDebit_reverts_whenTimelocked() (gas: 354509)
ExaPluginTest:test_collectDebit_toleratesTimeDrift() (gas: 651436)
ExaPluginTest:test_collectInstallments_collects() (gas: 1336172)
ExaPluginTest:test_collectInstallments_revertsWhenNoSlippage() (gas: 1202591)
ExaPluginTest:test_collectInstallments_reverts_asNotKeeper() (gas: 363283)
ExaPluginTest:test_collectInstallments_reverts_whenExpired() (gas: 360538)
ExaPluginTest:test_collectInstallments_reverts_whenReplay() (gas: 1067978)
ExaPluginTest:test_collectInstallments_reverts_whenTimelocked() (gas: 356805)
ExaPluginTest:test_collectInstallments_toleratesTimeDrift() (gas: 1192790)
ExaPluginTest:test_crossRepay_repays() (gas: 1461183)
ExaPluginTest:test_crossRepay_repays_whenKeeper() (gas: 1457962)
ExaPluginTest:test_crossRepay_reverts_whenDisagreement() (gas: 1571612)
ExaPluginTest:test_crossRepay_reverts_whenNotKeeper() (gas: 958306)
ExaPluginTest:test_debitCollateral_collects() (gas: 773668)
ExaPluginTest:test_exitMarket_reverts() (gas: 388890)
ExaPluginTest:test_marketWithdraw_transfersAsset_asOwner() (gas: 818548)
ExaPluginTest:test_onUninstall_uninstalls() (gas: 284203)
ExaPluginTest:test_poke() (gas: 315735)
ExaPluginTest:test_pokeETH_deposits() (gas: 378892)
ExaPluginTest:test_propose_emitsProposed() (gas: 218551)
ExaPluginTest:test_refund_refunds() (gas: 361573)
ExaPluginTest:test_repay_partiallyRepays() (gas: 1245357)
ExaPluginTest:test_repay_partiallyRepays_whenKeeper() (gas: 1187544)
ExaPluginTest:test_repay_repays() (gas: 1163705)
ExaPluginTest:test_repay_repays_whenKeeper() (gas: 1106386)
ExaPluginTest:test_rollDebt_rolls() (gas: 1231509)
ExaPluginTest:test_rollDebt_rolls_asKeeper() (gas: 1231157)
ExaPluginTest:test_setCollector_emitsCollectorSet() (gas: 40516)
ExaPluginTest:test_setCollector_reverts_whenAddressZero() (gas: 32311)
ExaPluginTest:test_repay_partiallyRepays() (gas: 1243900)
ExaPluginTest:test_repay_partiallyRepays_whenKeeper() (gas: 1186087)
ExaPluginTest:test_repay_repays() (gas: 1162248)
ExaPluginTest:test_repay_repays_whenKeeper() (gas: 1104929)
ExaPluginTest:test_rollDebt_rolls() (gas: 1231289)
ExaPluginTest:test_rollDebt_rolls_asKeeper() (gas: 1230937)
ExaPluginTest:test_setCollector_emitsCollectorSet() (gas: 40494)
ExaPluginTest:test_setCollector_reverts_whenAddressZero() (gas: 32289)
ExaPluginTest:test_setCollector_reverts_whenNotAdmin() (gas: 33772)
ExaPluginTest:test_setCollector_sets_whenAdmin() (gas: 39906)
ExaPluginTest:test_swap_reverts_withDisagreement() (gas: 288784)
ExaPluginTest:test_swap_swaps() (gas: 268457)
ExaPluginTest:test_withdrawWETH_transfersETH() (gas: 851670)
ExaPluginTest:test_withdraw_reverts_whenNoProposal() (gas: 414850)
ExaPluginTest:test_withdraw_reverts_whenNoProposalKeeper() (gas: 357843)
ExaPluginTest:test_withdraw_reverts_whenNotKeeper() (gas: 354925)
ExaPluginTest:test_withdraw_reverts_whenReceiverIsContractAndMarketNotWETH() (gas: 621125)
ExaPluginTest:test_withdraw_reverts_whenTimelocked() (gas: 307341)
ExaPluginTest:test_withdraw_reverts_whenTimelockedKeeper() (gas: 309187)
ExaPluginTest:test_withdraw_reverts_whenWrongAmount() (gas: 308738)
ExaPluginTest:test_withdraw_reverts_whenWrongMarket() (gas: 308931)
ExaPluginTest:test_withdraw_reverts_whenWrongReceiver() (gas: 308342)
ExaPluginTest:test_withdraw_transfersAsset_asKeeper() (gas: 820093)
ExaPluginTest:test_withdraw_withdrawsProposed() (gas: 810839)
ExaPluginTest:test_setCollector_sets_whenAdmin() (gas: 39773)
ExaPluginTest:test_swap_reverts_withDisagreement() (gas: 288696)
ExaPluginTest:test_swap_swaps() (gas: 268369)
ExaPluginTest:test_withdrawWETH_transfersETH() (gas: 851406)
ExaPluginTest:test_withdraw_reverts_whenNoProposal() (gas: 414784)
ExaPluginTest:test_withdraw_reverts_whenNoProposalKeeper() (gas: 357689)
ExaPluginTest:test_withdraw_reverts_whenNotKeeper() (gas: 354771)
ExaPluginTest:test_withdraw_reverts_whenReceiverIsContractAndMarketNotWETH() (gas: 620971)
ExaPluginTest:test_withdraw_reverts_whenTimelocked() (gas: 307253)
ExaPluginTest:test_withdraw_reverts_whenTimelockedKeeper() (gas: 309011)
ExaPluginTest:test_withdraw_reverts_whenWrongAmount() (gas: 308650)
ExaPluginTest:test_withdraw_reverts_whenWrongMarket() (gas: 308843)
ExaPluginTest:test_withdraw_reverts_whenWrongReceiver() (gas: 308254)
ExaPluginTest:test_withdraw_transfersAsset_asKeeper() (gas: 819851)
ExaPluginTest:test_withdraw_withdrawsProposed() (gas: 810597)
InstallmentsPreviewerTest:test_preview_returns() (gas: 135598)
IssuerCheckerTest:test_setIssuer_emits_IssuerSet() (gas: 70861)
IssuerCheckerTest:test_setIssuer_reverts_whenNotAdmin() (gas: 37272)
Expand Down
14 changes: 8 additions & 6 deletions contracts/src/ExaPlugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ contract ExaPlugin is AccessControl, BasePlugin, IExaAccount {

bytes32 public constant KEEPER_ROLE = keccak256("KEEPER_ROLE");

IERC20 public immutable USDC;
address public immutable SWAPPER;
IAuditor public immutable AUDITOR;
IMarket public immutable EXA_USDC;
Expand Down Expand Up @@ -89,6 +90,7 @@ contract ExaPlugin is AccessControl, BasePlugin, IExaAccount {
address swapper,
address firstKeeper
) {
USDC = IERC20(exaUSDC.asset());
AUDITOR = auditor;
EXA_USDC = exaUSDC;
EXA_WETH = exaWETH;
Expand All @@ -103,7 +105,7 @@ contract ExaPlugin is AccessControl, BasePlugin, IExaAccount {
_grantRole(DEFAULT_ADMIN_ROLE, owner);
_setCollector(collector_);

IERC20(EXA_USDC.asset()).forceApprove(address(EXA_USDC), type(uint256).max);
IERC20(USDC).forceApprove(address(EXA_USDC), type(uint256).max);
}

function propose(IMarket market, uint256 amount, address receiver) external {
Expand Down Expand Up @@ -222,8 +224,8 @@ contract ExaPlugin is AccessControl, BasePlugin, IExaAccount {
_executeFromSender(
address(collateral), 0, abi.encodeCall(IERC4626.withdraw, (maxAmountIn, address(this), msg.sender))
);
(amountIn, amountOut) = _swap(IERC20(collateral.asset()), IERC20(EXA_USDC.asset()), maxAmountIn, amount, route);
IERC20(EXA_USDC.asset()).safeTransfer(collector, amount);
(amountIn, amountOut) = _swap(IERC20(collateral.asset()), IERC20(USDC), maxAmountIn, amount, route);
IERC20(USDC).safeTransfer(collector, amount);

_depositUnspent(collateral, maxAmountIn - amountIn, msg.sender);
_depositApprovedUnspent(EXA_USDC, amountOut - amount, msg.sender);
Expand Down Expand Up @@ -318,8 +320,8 @@ contract ExaPlugin is AccessControl, BasePlugin, IExaAccount {
CrossRepayCallbackData memory c = abi.decode(data[1:], (CrossRepayCallbackData));
c.marketIn.withdraw(c.maxAmountIn, address(this), borrower);
(uint256 amountIn, uint256 amountOut) =
_swap(IERC20(c.marketIn.asset()), IERC20(EXA_USDC.asset()), c.maxAmountIn, maxRepay, c.route);
IERC20(EXA_USDC.asset()).safeTransfer(address(BALANCER_VAULT), maxRepay);
_swap(IERC20(c.marketIn.asset()), IERC20(USDC), c.maxAmountIn, maxRepay, c.route);
IERC20(USDC).safeTransfer(address(BALANCER_VAULT), maxRepay);

_depositApprovedUnspent(EXA_USDC, amountOut - actualRepay, borrower);
_depositUnspent(c.marketIn, c.maxAmountIn - amountIn, borrower);
Expand Down Expand Up @@ -632,7 +634,7 @@ contract ExaPlugin is AccessControl, BasePlugin, IExaAccount {

function _flashLoan(uint256 amount, bytes memory data) internal {
IERC20[] memory tokens = new IERC20[](1);
tokens[0] = IERC20(EXA_USDC.asset());
tokens[0] = IERC20(USDC);
uint256[] memory amounts = new uint256[](1);
amounts[0] = amount;

Expand Down

0 comments on commit b50653e

Please sign in to comment.