Skip to content

Commit

Permalink
✅ contracts: improve env var usage
Browse files Browse the repository at this point in the history
  • Loading branch information
cruzdanilo committed Dec 27, 2024
1 parent c877e3a commit 4c0f95a
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 75 deletions.
88 changes: 44 additions & 44 deletions contracts/.gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
ExaAccountFactoryTest:testFuzz_createAccount_EOAOwners(uint256,address[63]) (runs: 256, μ: 3621366, ~: 3460632)
ExaPluginTest:testFork_crossRepay_repays() (gas: 19666737)
ExaPluginTest:testFork_debitCollateral_collects() (gas: 19756315)
ExaPluginTest:testFork_swap_swaps() (gas: 16912274)
ExaPluginTest:testFork_crossRepay_repays() (gas: 19662223)
ExaPluginTest:testFork_debitCollateral_collects() (gas: 19751801)
ExaPluginTest:testFork_swap_swaps() (gas: 16907760)
ExaPluginTest:test_borrowAtMaturity_reverts_withUnauthorized_whenReceiverNotCollector() (gas: 408975)
ExaPluginTest:test_borrow_reverts_withUnauthorized_whenReceiverNotCollector() (gas: 408553)
ExaPluginTest:test_collectCredit_collects() (gas: 921083)
ExaPluginTest:test_collectCredit_collects() (gas: 921071)
ExaPluginTest:test_collectCredit_collects_whenHealthFactorHigherThanMinHealthFactor() (gas: 801758)
ExaPluginTest:test_collectCredit_collects_withEnoughSlippage() (gas: 800271)
ExaPluginTest:test_collectCredit_passes_whenProposalLeavesEnoughLiquidity() (gas: 1010088)
ExaPluginTest:test_collectCredit_collects_withEnoughSlippage() (gas: 800259)
ExaPluginTest:test_collectCredit_passes_whenProposalLeavesEnoughLiquidity() (gas: 1010124)
ExaPluginTest:test_collectCredit_reverts_asNotKeeper() (gas: 362757)
ExaPluginTest:test_collectCredit_reverts_whenDisagreement() (gas: 556074)
ExaPluginTest:test_collectCredit_reverts_whenExpired() (gas: 358845)
ExaPluginTest:test_collectCredit_reverts_whenDisagreement() (gas: 556062)
ExaPluginTest:test_collectCredit_reverts_whenExpired() (gas: 358857)
ExaPluginTest:test_collectCredit_reverts_whenHealthFactorLowerThanMinHealthFactor() (gas: 832014)
ExaPluginTest:test_collectCredit_reverts_whenPrposalCausesInsufficientLiquidity() (gas: 1010277)
ExaPluginTest:test_collectCredit_reverts_whenReplay() (gas: 843323)
ExaPluginTest:test_collectCredit_reverts_whenPrposalCausesInsufficientLiquidity() (gas: 1010301)
ExaPluginTest:test_collectCredit_reverts_whenReplay() (gas: 843299)
ExaPluginTest:test_collectCredit_reverts_whenTimelocked() (gas: 355114)
ExaPluginTest:test_collectCredit_toleratesTimeDrift() (gas: 803748)
ExaPluginTest:test_collectDebit_collects() (gas: 651749)
ExaPluginTest:test_collectDebit_collects_whenProposalLeavesEnoughLiquidity() (gas: 855108)
ExaPluginTest:test_collectDebit_collects() (gas: 651737)
ExaPluginTest:test_collectDebit_collects_whenProposalLeavesEnoughLiquidity() (gas: 855132)
ExaPluginTest:test_collectDebit_reverts_asNotKeeper() (gas: 362589)
ExaPluginTest:test_collectDebit_reverts_whenExpired() (gas: 358651)
ExaPluginTest:test_collectDebit_reverts_whenProposalCausesInsufficientLiquidity() (gas: 852099)
ExaPluginTest:test_collectDebit_reverts_whenReplay() (gas: 691191)
ExaPluginTest:test_collectDebit_reverts_whenExpired() (gas: 358663)
ExaPluginTest:test_collectDebit_reverts_whenProposalCausesInsufficientLiquidity() (gas: 852135)
ExaPluginTest:test_collectDebit_reverts_whenReplay() (gas: 691167)
ExaPluginTest:test_collectDebit_reverts_whenTimelocked() (gas: 354855)
ExaPluginTest:test_collectDebit_toleratesTimeDrift() (gas: 651826)
ExaPluginTest:test_collectInstallments_collects() (gas: 1338830)
ExaPluginTest:test_collectInstallments_revertsWhenNoSlippage() (gas: 1203025)
ExaPluginTest:test_collectInstallments_collects() (gas: 1338854)
ExaPluginTest:test_collectInstallments_revertsWhenNoSlippage() (gas: 1203049)
ExaPluginTest:test_collectInstallments_reverts_asNotKeeper() (gas: 363607)
ExaPluginTest:test_collectInstallments_reverts_whenExpired() (gas: 361030)
ExaPluginTest:test_collectInstallments_reverts_whenReplay() (gas: 1070925)
ExaPluginTest:test_collectInstallments_reverts_whenTimelocked() (gas: 357218)
ExaPluginTest:test_collectInstallments_toleratesTimeDrift() (gas: 1195516)
ExaPluginTest:test_crossRepay_repays() (gas: 1466544)
ExaPluginTest:test_crossRepay_repays_whenKeeper() (gas: 1463190)
ExaPluginTest:test_crossRepay_reverts_whenDisagreement() (gas: 1575464)
ExaPluginTest:test_crossRepay_reverts_whenNotKeeper() (gas: 961090)
ExaPluginTest:test_crossRepay_repays() (gas: 1466532)
ExaPluginTest:test_crossRepay_repays_whenKeeper() (gas: 1463178)
ExaPluginTest:test_crossRepay_reverts_whenDisagreement() (gas: 1575452)
ExaPluginTest:test_crossRepay_reverts_whenNotKeeper() (gas: 961078)
ExaPluginTest:test_debitCollateral_collects() (gas: 776959)
ExaPluginTest:test_exitMarket_reverts() (gas: 389259)
ExaPluginTest:test_onUninstall_uninstalls() (gas: 284122)
ExaPluginTest:test_poke() (gas: 315952)
ExaPluginTest:test_pokeETH_deposits() (gas: 375965)
ExaPluginTest:test_propose_emitsProposed() (gas: 218655)
ExaPluginTest:test_refund_refunds() (gas: 361505)
ExaPluginTest:test_propose_emitsProposed() (gas: 218667)
ExaPluginTest:test_refund_refunds() (gas: 361517)
ExaPluginTest:test_repay_partiallyRepays() (gas: 1250119)
ExaPluginTest:test_repay_partiallyRepays_whenKeeper() (gas: 1192284)
ExaPluginTest:test_repay_partiallyRepays_whenKeeper() (gas: 1192272)
ExaPluginTest:test_repay_repays() (gas: 1166226)
ExaPluginTest:test_repay_repays_whenKeeper() (gas: 1108950)
ExaPluginTest:test_rollDebt_rolls() (gas: 1234108)
ExaPluginTest:test_rollDebt_rolls_asKeeper() (gas: 1233734)
ExaPluginTest:test_repay_repays_whenKeeper() (gas: 1108938)
ExaPluginTest:test_rollDebt_rolls() (gas: 1234096)
ExaPluginTest:test_rollDebt_rolls_asKeeper() (gas: 1233722)
ExaPluginTest:test_setCollector_emitsCollectorSet() (gas: 40560)
ExaPluginTest:test_setCollector_reverts_whenAddressZero() (gas: 32246)
ExaPluginTest:test_setCollector_reverts_whenNotAdmin() (gas: 33758)
Expand All @@ -57,28 +57,28 @@ ExaPluginTest:test_setMinHealthFactor_reverts_whenNotAdmin() (gas: 33768)
ExaPluginTest:test_setMinHealthFactor_sets_whenAdmin() (gas: 39463)
ExaPluginTest:test_swap_reverts_withDisagreement() (gas: 289042)
ExaPluginTest:test_swap_swaps() (gas: 268686)
ExaPluginTest:test_withdrawWETH_transfersETH() (gas: 848687)
ExaPluginTest:test_withdraw_reverts_whenNoProposal() (gas: 415178)
ExaPluginTest:test_withdrawWETH_transfersETH() (gas: 848711)
ExaPluginTest:test_withdraw_reverts_whenNoProposal() (gas: 415202)
ExaPluginTest:test_withdraw_reverts_whenNoProposalKeeper() (gas: 358000)
ExaPluginTest:test_withdraw_reverts_whenNotKeeper() (gas: 355018)
ExaPluginTest:test_withdraw_reverts_whenReceiverIsContractAndMarketNotWETH() (gas: 621314)
ExaPluginTest:test_withdraw_reverts_whenTimelocked() (gas: 307315)
ExaPluginTest:test_withdraw_reverts_whenTimelockedKeeper() (gas: 309148)
ExaPluginTest:test_withdraw_reverts_whenWrongAmount() (gas: 308712)
ExaPluginTest:test_withdraw_reverts_whenWrongMarket() (gas: 309038)
ExaPluginTest:test_withdraw_reverts_whenWrongReceiver() (gas: 308405)
ExaPluginTest:test_withdraw_transfersAsset_asKeeper() (gas: 820334)
ExaPluginTest:test_withdraw_transfersAsset_asOwner() (gas: 819025)
ExaPluginTest:test_withdraw_reverts_whenReceiverIsContractAndMarketNotWETH() (gas: 621338)
ExaPluginTest:test_withdraw_reverts_whenTimelocked() (gas: 307363)
ExaPluginTest:test_withdraw_reverts_whenTimelockedKeeper() (gas: 309172)
ExaPluginTest:test_withdraw_reverts_whenWrongAmount() (gas: 308760)
ExaPluginTest:test_withdraw_reverts_whenWrongMarket() (gas: 309086)
ExaPluginTest:test_withdraw_reverts_whenWrongReceiver() (gas: 308429)
ExaPluginTest:test_withdraw_transfersAsset_asKeeper() (gas: 820346)
ExaPluginTest:test_withdraw_transfersAsset_asOwner() (gas: 819049)
InstallmentsPreviewerTest:test_preview_returns() (gas: 135598)
IssuerCheckerTest:test_setIssuer_emits_IssuerSet() (gas: 41782)
IssuerCheckerTest:test_setIssuer_reverts_whenNotAdmin() (gas: 37070)
IssuerCheckerTest:test_setIssuer_reverts_whenZeroAddress() (gas: 35449)
MockSwapperTest:test_swapExactAmountIn_swaps() (gas: 220530)
MockSwapperTest:test_swapExactAmountOut_swaps() (gas: 220657)
RefunderTest:test_refund_refunds() (gas: 242371)
RefunderTest:test_refund_reverts_whenExpired() (gas: 69551)
RefunderTest:test_refund_reverts_whenNotKeeper() (gas: 56897)
RefunderTest:test_refund_reverts_whenReplay() (gas: 279261)
RefunderTest:test_refund_reverts_whenTimelocked() (gas: 63310)
MockSwapperTest:test_swapExactAmountIn_swaps() (gas: 220542)
MockSwapperTest:test_swapExactAmountOut_swaps() (gas: 220669)
RefunderTest:test_refund_refunds() (gas: 242383)
RefunderTest:test_refund_reverts_whenExpired() (gas: 69563)
RefunderTest:test_refund_reverts_whenNotKeeper() (gas: 56909)
RefunderTest:test_refund_reverts_whenReplay() (gas: 279285)
RefunderTest:test_refund_reverts_whenTimelocked() (gas: 63298)
RefunderTest:test_refund_reverts_whenWrongSignature() (gas: 68975)
RefunderTest:test_refund_toleratesTimeDrift() (gas: 242469)
41 changes: 16 additions & 25 deletions contracts/test/ExaPlugin.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,12 @@ contract ExaPluginTest is ForkTest {
MockERC20 internal usdc;

function setUp() external {
vm.setEnv("DEPLOYER_ADDRESS", address(this).toHexString());

collector = payable(makeAddr("collector"));
(owner, ownerKey) = makeAddrAndKey("owner");
owners = new address[](1);
owners[0] = owner;
(keeper, keeperKey) = makeAddrAndKey("keeper");
(issuer, issuerKey) = makeAddrAndKey("issuer");
vm.setEnv("KEEPER_ADDRESS", keeper.toHexString());
vm.setEnv("ISSUER_ADDRESS", issuer.toHexString());

new DeployAccount().run();
DeployProtocol p = new DeployProtocol();
Expand All @@ -107,25 +103,31 @@ contract ExaPluginTest is ForkTest {
exaWETH = IMarket(address(p.exaWETH()));
exa = p.exa();
usdc = p.usdc();
vm.setEnv("PROTOCOL_AUDITOR_ADDRESS", address(auditor).toHexString());
vm.setEnv("PROTOCOL_MARKETUSDC_ADDRESS", address(exaUSDC).toHexString());
vm.setEnv("PROTOCOL_USDC_ADDRESS", address(usdc).toHexString());

DeployMocks m = new DeployMocks();
m.setUp();
m.run();
vm.setEnv("SWAPPER_ADDRESS", address(m.swapper()).toHexString());

DeployIssuerChecker ic = new DeployIssuerChecker();
vm.setEnv("ISSUER_ADDRESS", issuer.toHexString());
ic.run();
vm.setEnv("ISSUER_ADDRESS", "");
issuerChecker = ic.issuerChecker();
vm.setEnv("BROADCAST_ISSUERCHECKER_ADDRESS", address(issuerChecker).toHexString());

DeployMocks m = new DeployMocks();
vm.setEnv("PROTOCOL_AUDITOR_ADDRESS", address(auditor).toHexString());
vm.setEnv("PROTOCOL_USDC_ADDRESS", address(usdc).toHexString());
m.setUp();
m.run();
vm.setEnv("PROTOCOL_AUDITOR_ADDRESS", "");
vm.setEnv("PROTOCOL_USDC_ADDRESS", "");

DeployRefunder r = new DeployRefunder();
vm.setEnv("KEEPER_ADDRESS", keeper.toHexString());
vm.setEnv("PROTOCOL_MARKETUSDC_ADDRESS", address(exaUSDC).toHexString());
vm.setEnv("BROADCAST_ISSUERCHECKER_ADDRESS", address(issuerChecker).toHexString());
r.setUp();
r.run();
vm.setEnv("KEEPER_ADDRESS", "");
vm.setEnv("PROTOCOL_MARKETUSDC_ADDRESS", "");
vm.setEnv("BROADCAST_ISSUERCHECKER_ADDRESS", "");
refunder = r.refunder();
vm.setEnv("BROADCAST_REFUNDER_ADDRESS", address(refunder).toHexString());

exaPlugin = new ExaPlugin(
address(this),
Expand Down Expand Up @@ -1215,17 +1217,6 @@ contract ExaPluginTest is ForkTest {
function _setUpLifiFork() internal {
vm.createSelectFork("optimism", 127_050_624);
account = ExaAccount(payable(0x6120Fb2A9d47f7955298b80363F00C620dB9f6E6));

vm.setEnv("DEPLOYER_ADDRESS", "");
vm.setEnv("KEEPER_ADDRESS", "");
vm.setEnv("ISSUER_ADDRESS", "");
vm.setEnv("SWAPPER_ADDRESS", "");
vm.setEnv("PROTOCOL_AUDITOR_ADDRESS", "");
vm.setEnv("PROTOCOL_MARKETUSDC_ADDRESS", "");
vm.setEnv("PROTOCOL_USDC_ADDRESS", "");
vm.setEnv("BROADCAST_ISSUERCHECKER_ADDRESS", "");
vm.setEnv("BROADCAST_REFUNDER_ADDRESS", "");

issuerChecker = IssuerChecker(broadcast("IssuerChecker"));
vm.prank(acct("deployer"));
issuerChecker.setIssuer(issuer);
Expand Down
5 changes: 2 additions & 3 deletions contracts/test/InstallmentsPreviewer.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ contract InstallmentsPreviewerTest is ForkTest {
InstallmentsPreviewer internal previewer;

function setUp() external {
vm.setEnv("DEPLOYER_ADDRESS", address(this).toHexString());

DeployProtocol p = new DeployProtocol();
p.run();
exaUSDC = ICollectableMarket(address(p.exaUSDC()));
vm.setEnv("PROTOCOL_MARKETUSDC_ADDRESS", address(exaUSDC).toHexString());

DeployInstallmentsPreviewer ip = new DeployInstallmentsPreviewer();
vm.setEnv("PROTOCOL_MARKETUSDC_ADDRESS", address(exaUSDC).toHexString());
ip.run();
vm.setEnv("PROTOCOL_MARKETUSDC_ADDRESS", "");
previewer = ip.installmentsPreviewer();
}

Expand Down
6 changes: 4 additions & 2 deletions contracts/test/MockSwapper.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ contract MockSwapperTest is ForkTest {
p.run();
exa = p.exa();
usdc = p.usdc();
vm.setEnv("PROTOCOL_AUDITOR_ADDRESS", address(p.auditor()).toHexString());
vm.setEnv("PROTOCOL_USDC_ADDRESS", address(usdc).toHexString());

DeployMocks m = new DeployMocks();
vm.setEnv("PROTOCOL_AUDITOR_ADDRESS", address(p.auditor()).toHexString());
vm.setEnv("PROTOCOL_USDC_ADDRESS", address(usdc).toHexString());
m.setUp();
m.run();
vm.setEnv("PROTOCOL_AUDITOR_ADDRESS", "");
vm.setEnv("PROTOCOL_USDC_ADDRESS", "");
mockSwapper = m.swapper();

exa.mint(address(this), 10_000e18);
Expand Down
1 change: 0 additions & 1 deletion contracts/test/Refunder.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ contract RefunderTest is ForkTest {
address internal bob = address(0xb0b);

function setUp() external {
vm.setEnv("DEPLOYER_ADDRESS", address(this).toHexString());
DeployProtocol p = new DeployProtocol();
p.run();

Expand Down

0 comments on commit 4c0f95a

Please sign in to comment.