Skip to content

Commit 24a5f83

Browse files
committed
add deploy scripts
1 parent 4896e15 commit 24a5f83

File tree

5 files changed

+196
-18
lines changed

5 files changed

+196
-18
lines changed

.env-example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ REFUEL_ERC20_ACTION_GAS_CONSTANT=
2525
SWEEP_ACTION_GAS_CONSTANT=
2626
SWEEP_CCTP_ACTION_GAS_CONSTANT=
2727
SWEEP_DEPOSIT_ERC4626_ACTION_GAS_CONSTANT=
28+
REQUEST_DEPOSIT_ERC7540_ACTION_GAS_CONSTANT=
29+
SWEEP_REQUEST_DEPOSIT_ERC7540_ACTION_GAS_CONSTANT=
2830
SWEEP_ERC20_ACTION_GAS_CONSTANT=
2931
SWEEP_UNISWAP_V3_ACTION_GAS_CONSTANT=
3032
SWEEP_WITHDRAW_ERC4626_ACTION_GAS_CONSTANT=
@@ -48,6 +50,8 @@ EXPECTED_SWEEP_ERC20_ACTION_ADDRESS=
4850
EXPECTED_CALL_ONCE_ACTION_ADDRESS=
4951
EXPECTED_DEPOSIT_ERC4626_ACTION_ADDRESS=
5052
EXPECTED_SWEEP_DEPOSIT_ERC4626_ACTION_ADDRESS=
53+
EXPECTED_REQUEST_DEPOSIT_ERC7540_ACTION_ADDRESS=
54+
EXPECTED_SWEEP_REQUEST_DEPOSIT_ERC7540_ACTION_ADDRESS=
5155
EXPECTED_WITHDRAW_ERC4626_ACTION_ADDRESS=
5256
EXPECTED_SWEEP_WITHDRAW_ERC4626_ACTION_ADDRESS=
5357

.gas-snapshot

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ CrossRatePriceFeedTest:test_latestRoundData_invalidDenominatorPrice(int256) (run
4040
CrossRatePriceFeedTest:test_latestRoundData_invalidNumeratorPrice(int256) (runs: 256, μ: 907390, ~: 907952)
4141
CrossRatePriceFeedTest:test_latestRoundData_realValuesFork() (gas: 70243)
4242
CrossRatePriceFeedTest:test_latestRoundData_realValuesFuzz18(int256,int256) (runs: 256, μ: 1301519, ~: 1301597)
43-
CrossRatePriceFeedTest:test_latestRoundData_realValuesFuzz8(int256,int256) (runs: 256, μ: 1301315, ~: 1301621)
44-
CrossRatePriceFeedTest:test_latestRoundData_revertsOnOverflow(int256) (runs: 256, μ: 935243, ~: 935235)
43+
CrossRatePriceFeedTest:test_latestRoundData_realValuesFuzz8(int256,int256) (runs: 256, μ: 1301321, ~: 1301621)
44+
CrossRatePriceFeedTest:test_latestRoundData_revertsOnOverflow(int256) (runs: 256, μ: 935241, ~: 935235)
4545
CrossRatePriceFeedTest:test_latestRoundData_roundIdOne() (gas: 60318)
46-
CrossRatePriceFeedTest:test_latestRoundData_staleDenominatorPrice(uint256) (runs: 256, μ: 906854, ~: 907132)
47-
CrossRatePriceFeedTest:test_latestRoundData_staleNumeratorPrice(uint256) (runs: 256, μ: 906768, ~: 907046)
46+
CrossRatePriceFeedTest:test_latestRoundData_staleDenominatorPrice(uint256) (runs: 256, μ: 906856, ~: 907132)
47+
CrossRatePriceFeedTest:test_latestRoundData_staleNumeratorPrice(uint256) (runs: 256, μ: 906770, ~: 907046)
4848
CrossRatePriceFeedTest:test_latestRoundData_startedAtZero() (gas: 60332)
4949
CrossRatePriceFeedTest:test_latestRoundData_usesEarlierUpdatedAt() (gas: 68898)
5050
DeactivateInstruction:test_deactivateInstruction_alreadyDeactivated() (gas: 20424)
@@ -83,23 +83,23 @@ DepositERC4626Test:test_depositERC4626_recipientZero() (gas: 36769)
8383
DepositERC4626Test:test_depositERC4626_totalSharesTooLow() (gas: 39187)
8484
DepositERC4626Test:test_depositERC4626_valueZero() (gas: 36815)
8585
DepositERC4626Test:test_depositERC4626_vaultZero() (gas: 36798)
86-
EstimateCallOnceGasConstant:testFuzz_callOnce_gasConstant(uint256,(address,bool,uint256,uint256,uint16,bytes4,bytes,(address,uint256,uint256,uint256))) (runs: 256, μ: 4182, ~: 3876)
87-
EstimateDeactivateInstructionGasConstant:testFuzz_deactivateInstruction_gasConstant(uint256,(bytes32,(address,uint256,uint256,uint256))) (runs: 256, μ: 1957, ~: 1941)
86+
EstimateCallOnceGasConstant:testFuzz_callOnce_gasConstant(uint256,(address,bool,uint256,uint256,uint16,bytes4,bytes,(address,uint256,uint256,uint256))) (runs: 256, μ: 4185, ~: 3876)
87+
EstimateDeactivateInstructionGasConstant:testFuzz_deactivateInstruction_gasConstant(uint256,(bytes32,(address,uint256,uint256,uint256))) (runs: 256, μ: 1963, ~: 1959)
8888
EstimateDepositERC4626GasConstant:testFuzz_depositERC4626_gasConstant(uint256,uint256,(address,address,uint256,uint256,uint256,(uint256,uint256,uint256,uint256),(address,uint256,uint256,uint256))) (runs: 256, μ: 4505, ~: 4452)
89-
EstimateRefuelERC20GasConstant:testFuzz_refuelERC20_gasConstant(uint256,uint256,(address,address,uint256,uint256,(address,uint256,uint256,uint256))) (runs: 256, μ: 3014, ~: 3006)
90-
EstimateRefuelGasConstant:testFuzz_refuel_gasConstant(uint256,uint256,(address,uint256,uint256,uint256,(address,uint256,uint256,uint256))) (runs: 256, μ: 2897, ~: 2835)
91-
EstimateSweepCCTPGasConstant:testFuzz_sweepCCTP_gasConstant(uint256,uint256,(address,uint32,bytes32,uint256,uint256,(address,uint256,uint256,uint256))) (runs: 256, μ: 3341, ~: 3306)
89+
EstimateRefuelERC20GasConstant:testFuzz_refuelERC20_gasConstant(uint256,uint256,(address,address,uint256,uint256,(address,uint256,uint256,uint256))) (runs: 256, μ: 3021, ~: 3024)
90+
EstimateRefuelGasConstant:testFuzz_refuel_gasConstant(uint256,uint256,(address,uint256,uint256,uint256,(address,uint256,uint256,uint256))) (runs: 256, μ: 2892, ~: 2835)
91+
EstimateSweepCCTPGasConstant:testFuzz_sweepCCTP_gasConstant(uint256,uint256,(address,uint32,bytes32,uint256,uint256,(address,uint256,uint256,uint256))) (runs: 256, μ: 3336, ~: 3306)
9292
EstimateSweepDepositERC4626GasConstant:testFuzz_sweepDepositERC4626_gasConstant(uint256,uint256,(address,address,uint256,uint256,uint256,uint256,(address,uint256,uint256,uint256))) (runs: 256, μ: 3537, ~: 3516)
93-
EstimateSweepERC20GasConstant:testFuzz_sweepERC20_gasConstant(uint256,uint256,(address,address,uint256,uint256,(address,uint256,uint256,uint256))) (runs: 256, μ: 3025, ~: 3042)
94-
EstimateSweepGasConstant:testFuzz_sweep_gasConstant(uint256,uint256,(address,uint256,uint256,uint256,(address,uint256,uint256,uint256))) (runs: 256, μ: 2853, ~: 2808)
95-
EstimateSweepUniswapV3GasConstant:testFuzz_sweepUniswapV3_gasConstant(uint256,uint256,(address,address,address,uint24,uint256,uint256,uint256,uint32,uint32,(address,uint256,uint256,uint256))) (runs: 256, μ: 4427, ~: 4425)
93+
EstimateSweepERC20GasConstant:testFuzz_sweepERC20_gasConstant(uint256,uint256,(address,address,uint256,uint256,(address,uint256,uint256,uint256))) (runs: 256, μ: 3019, ~: 3024)
94+
EstimateSweepGasConstant:testFuzz_sweep_gasConstant(uint256,uint256,(address,uint256,uint256,uint256,(address,uint256,uint256,uint256))) (runs: 256, μ: 2849, ~: 2808)
95+
EstimateSweepUniswapV3GasConstant:testFuzz_sweepUniswapV3_gasConstant(uint256,uint256,(address,address,address,uint24,uint256,uint256,uint256,uint32,uint32,(address,uint256,uint256,uint256))) (runs: 256, μ: 4421, ~: 4398)
9696
EstimateSweepWithdrawERC4626GasConstant:testFuzz_sweepWithdrawERC4626_gasConstant(uint256,uint256,(address,address,uint256,uint256,uint256,(address,uint256,uint256,uint256))) (runs: 256, μ: 3285, ~: 3288)
97-
EstimateTransferCCTPGasConstant:testFuzz_transferCCTP_gasConstant(uint256,uint256,(address,uint256,uint32,bytes32,(uint256,uint256,uint256,uint256),(address,uint256,uint256,uint256))) (runs: 256, μ: 4222, ~: 4215)
98-
EstimateTransferERC20GasConstant:testFuzz_transferERC20_gasConstant(uint256,uint256,(address,address,uint256,(uint256,uint256,uint256,uint256),(address,uint256,uint256,uint256))) (runs: 256, μ: 3999, ~: 3942)
99-
EstimateTransferGasConstant:testFuzz_transfer_gasConstant(uint256,uint256,(address,uint256,uint256,(uint256,uint256,uint256,uint256),(address,uint256,uint256,uint256))) (runs: 256, μ: 3774, ~: 3762)
100-
EstimateTransferOnceERC20GasConstant:testFuzz_transferERC20Once_gasConstant(uint256,(address,address,uint256,(address,uint256,uint256,uint256))) (runs: 256, μ: 2575, ~: 2586)
101-
EstimateTransferOnceGasConstant:testFuzz_transferOnce_gasConstant(uint256,(address,uint256,uint256,(address,uint256,uint256,uint256))) (runs: 256, μ: 2323, ~: 2298)
102-
EstimateUniswapV3ExactInputGasConstant:testFuzz_uniswapV3ExactInput_gasConstant(uint256,uint256,(address,address,address,uint24,uint256,uint256,uint32,uint32,(uint256,uint256,uint256,uint256),(address,uint256,uint256,uint256))) (runs: 256, μ: 5348, ~: 5352)
97+
EstimateTransferCCTPGasConstant:testFuzz_transferCCTP_gasConstant(uint256,uint256,(address,uint256,uint32,bytes32,(uint256,uint256,uint256,uint256),(address,uint256,uint256,uint256))) (runs: 256, μ: 4225, ~: 4206)
98+
EstimateTransferERC20GasConstant:testFuzz_transferERC20_gasConstant(uint256,uint256,(address,address,uint256,(uint256,uint256,uint256,uint256),(address,uint256,uint256,uint256))) (runs: 256, μ: 4006, ~: 3978)
99+
EstimateTransferGasConstant:testFuzz_transfer_gasConstant(uint256,uint256,(address,uint256,uint256,(uint256,uint256,uint256,uint256),(address,uint256,uint256,uint256))) (runs: 256, μ: 3764, ~: 3762)
100+
EstimateTransferOnceERC20GasConstant:testFuzz_transferERC20Once_gasConstant(uint256,(address,address,uint256,(address,uint256,uint256,uint256))) (runs: 256, μ: 2571, ~: 2586)
101+
EstimateTransferOnceGasConstant:testFuzz_transferOnce_gasConstant(uint256,(address,uint256,uint256,(address,uint256,uint256,uint256))) (runs: 256, μ: 2326, ~: 2289)
102+
EstimateUniswapV3ExactInputGasConstant:testFuzz_uniswapV3ExactInput_gasConstant(uint256,uint256,(address,address,address,uint24,uint256,uint256,uint32,uint32,(uint256,uint256,uint256,uint256),(address,uint256,uint256,uint256))) (runs: 256, μ: 5311, ~: 5316)
103103
EstimateWithdrawERC4626GasConstant:testFuzz_withdrawERC4626_gasConstant(uint256,uint256,(address,address,uint256,uint256,(uint256,uint256,uint256,uint256),(address,uint256,uint256,uint256))) (runs: 256, μ: 4226, ~: 4206)
104104
FeeTokenRegistryTest:test_addFeeToken_alreadyRegistered() (gas: 1898)
105105
FeeTokenRegistryTest:test_addFeeToken_happyPath() (gas: 37590)

.github/deployment/networks/.env-gas-constants

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ REFUEL_ERC20_ACTION_GAS_CONSTANT=104500
88
SWEEP_ACTION_GAS_CONSTANT=104000
99
SWEEP_CCTP_ACTION_GAS_CONSTANT=104500
1010
SWEEP_DEPOSIT_ERC4626_ACTION_GAS_CONSTANT=104500
11+
REQUEST_DEPOSIT_ERC7540_ACTION_GAS_CONSTANT=
12+
SWEEP_REQUEST_DEPOSIT_ERC7540_ACTION_GAS_CONSTANT=
1113
SWEEP_ERC20_ACTION_GAS_CONSTANT=104000
1214
SWEEP_UNISWAP_V3_ACTION_GAS_CONSTANT=106000
1315
SWEEP_WITHDRAW_ERC4626_ACTION_GAS_CONSTANT=104500
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
pragma solidity ^0.8.26;
3+
4+
import {Script, console2} from "forge-std/src/Script.sol";
5+
import {VmSafe} from "forge-std/src/Vm.sol";
6+
7+
import {RequestDepositERC7540Action} from "../../../src/actions/RequestDepositERC7540Action.sol";
8+
9+
contract DeployRequestDepositERC7540Action is Script {
10+
/// @dev make sure to run `cp .env_example .env` and fill in each variable
11+
/// then run `source .env` in your terminal before copying and pasting one of the commands below
12+
/// @dev this script will deploy to the same address on every chain.
13+
/// this deterministic address depend on a few things:
14+
/// - the owner address
15+
/// - the salt
16+
/// - the creation code of the contract
17+
/// - **** the number of optimizer_runs will change the creation code (see foundry.toml) ****
18+
/// - **** the version of the Solidity compiler will change the creation code ****
19+
/// - **** the EVM version (cancun, prague, etc) will change the creation code ****
20+
/// - **** dependency versions can change the creation code ****
21+
/// - **** the forge version can change the creation code ****
22+
/// - **** compiler flags (--via-ir, --overwrite, etc) can change the creation code ****
23+
/// - the address of the deployer (this won't change because we are using the cannoical Create2 factory 0x4e59b44847b379578588920ca78fbf26c0b4956c, but good to know)
24+
///
25+
///
26+
/// if any of these values change, the addresses will change, so we must be careful to keep these values constant.
27+
/// in order to help with this, a check is added here to ensure that the calculated address matches the expected address
28+
/// before deploying. if the addresses do not match, the script will revert.
29+
// command to generate the expected deployment address (without actually deploying):
30+
//
31+
// forge script DeployRequestDepositERC7540Action
32+
33+
// commands to deterministically deploy (and check the expected address before deploying):
34+
//
35+
// - with private key (on Anvil): forge script DeployRequestDepositERC7540Action --broadcast --fork-url http://localhost:8545 --private-key $ANVIL_DEPLOYER_PK
36+
// - with private key: forge script DeployRequestDepositERC7540Action --broadcast --rpc-url $RPC_URL --private-key $DEPLOYER_PK
37+
// - with Ledger: forge script DeployRequestDepositERC7540Action --broadcast --rpc-url $RPC_URL --ledger
38+
// - with AWS: forge script DeployRequestDepositERC7540Action --broadcast --rpc-url $RPC_URL --aws
39+
40+
bytes32 constant salt = keccak256("ON_TIME_INSTRUCTED_MONEY");
41+
42+
error ExpectedAddressMismatch();
43+
44+
function run() public {
45+
address feeTokenRegistryAddress = vm.envAddress("EXPECTED_FEE_TOKEN_REGISTRY_ADDRESS");
46+
address treasuryAddress = vm.envAddress("EXPECTED_TREASURY_ADDRESS");
47+
uint256 gasConstant = vm.envUint("REQUEST_DEPOSIT_ERC7540_ACTION_GAS_CONSTANT");
48+
49+
// if this isn't a dry-run (aka we're using `--broadcast`), make sure to check the expected address
50+
if (vm.isContext(VmSafe.ForgeContext.ScriptBroadcast)) {
51+
checkExpectedAddress(feeTokenRegistryAddress, treasuryAddress, gasConstant);
52+
}
53+
54+
vm.startBroadcast();
55+
56+
// deterministically deploy RequestDepositERC7540Action via canonical Create2 deployer
57+
RequestDepositERC7540Action requestDepositERC7540Action =
58+
new RequestDepositERC7540Action{salt: salt}(feeTokenRegistryAddress, treasuryAddress, gasConstant);
59+
60+
vm.stopBroadcast();
61+
62+
console2.log("RequestDepositERC7540Action deployed at:", address(requestDepositERC7540Action));
63+
}
64+
65+
function checkExpectedAddress(address feeTokenRegistry, address treasuryAddress, uint256 gasConstant) public view {
66+
/// @dev before deploying for the first time, generate this expected address by running this script in dry-run mode (see above).
67+
/// once it has been deployed for the first time, that deployed address should be used as the expected address from then on.
68+
address expectedAddress = vm.envAddress("EXPECTED_REQUEST_DEPOSIT_ERC7540_ACTION_ADDRESS");
69+
70+
// calculate the expected address using the current init code
71+
address calculatedAddress = vm.computeCreate2Address(
72+
salt,
73+
keccak256(
74+
abi.encodePacked(
75+
type(RequestDepositERC7540Action).creationCode,
76+
abi.encode(feeTokenRegistry, treasuryAddress, gasConstant)
77+
)
78+
)
79+
);
80+
81+
// revert if the expected address does not match the calculated address
82+
if (expectedAddress != calculatedAddress) {
83+
revert ExpectedAddressMismatch();
84+
}
85+
}
86+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
pragma solidity ^0.8.26;
3+
4+
import {Script, console2} from "forge-std/src/Script.sol";
5+
import {VmSafe} from "forge-std/src/Vm.sol";
6+
7+
import {SweepRequestDepositERC7540Action} from "../../../src/actions/SweepRequestDepositERC7540Action.sol";
8+
9+
contract DeploySweepRequestDepositERC7540Action is Script {
10+
/// @dev make sure to run `cp .env_example .env` and fill in each variable
11+
/// then run `source .env` in your terminal before copying and pasting one of the commands below
12+
/// @dev this script will deploy to the same address on every chain.
13+
/// this deterministic address depend on a few things:
14+
/// - the owner address
15+
/// - the salt
16+
/// - the creation code of the contract
17+
/// - **** the number of optimizer_runs will change the creation code (see foundry.toml) ****
18+
/// - **** the version of the Solidity compiler will change the creation code ****
19+
/// - **** the EVM version (cancun, prague, etc) will change the creation code ****
20+
/// - **** dependency versions can change the creation code ****
21+
/// - **** the forge version can change the creation code ****
22+
/// - **** compiler flags (--via-ir, --overwrite, etc) can change the creation code ****
23+
/// - the address of the deployer (this won't change because we are using the cannoical Create2 factory 0x4e59b44847b379578588920ca78fbf26c0b4956c, but good to know)
24+
///
25+
///
26+
/// if any of these values change, the addresses will change, so we must be careful to keep these values constant.
27+
/// in order to help with this, a check is added here to ensure that the calculated address matches the expected address
28+
/// before deploying. if the addresses do not match, the script will revert.
29+
// command to generate the expected deployment address (without actually deploying):
30+
//
31+
// forge script DeploySweepRequestDepositERC7540Action
32+
33+
// commands to deterministically deploy (and check the expected address before deploying):
34+
//
35+
// - with private key (on Anvil): forge script DeploySweepRequestDepositERC7540Action --broadcast --fork-url http://localhost:8545 --private-key $ANVIL_DEPLOYER_PK
36+
// - with private key: forge script DeploySweepRequestDepositERC7540Action --broadcast --rpc-url $RPC_URL --private-key $DEPLOYER_PK
37+
// - with Ledger: forge script DeploySweepRequestDepositERC7540Action --broadcast --rpc-url $RPC_URL --ledger
38+
// - with AWS: forge script DeploySweepRequestDepositERC7540Action --broadcast --rpc-url $RPC_URL --aws
39+
40+
bytes32 constant salt = keccak256("ON_TIME_INSTRUCTED_MONEY");
41+
42+
error ExpectedAddressMismatch();
43+
44+
function run() public {
45+
address feeTokenRegistryAddress = vm.envAddress("EXPECTED_FEE_TOKEN_REGISTRY_ADDRESS");
46+
address treasuryAddress = vm.envAddress("EXPECTED_TREASURY_ADDRESS");
47+
uint256 gasConstant = vm.envUint("SWEEP_REQUEST_DEPOSIT_ERC7540_ACTION_GAS_CONSTANT");
48+
49+
// if this isn't a dry-run (aka we're using `--broadcast`), make sure to check the expected address
50+
if (vm.isContext(VmSafe.ForgeContext.ScriptBroadcast)) {
51+
checkExpectedAddress(feeTokenRegistryAddress, treasuryAddress, gasConstant);
52+
}
53+
54+
vm.startBroadcast();
55+
56+
// deterministically deploy SweepRequestDepositERC7540Action via canonical Create2 deployer
57+
SweepRequestDepositERC7540Action sweepRequestDepositERC7540Action =
58+
new SweepRequestDepositERC7540Action{salt: salt}(feeTokenRegistryAddress, treasuryAddress, gasConstant);
59+
60+
vm.stopBroadcast();
61+
62+
console2.log("SweepRequestDepositERC7540Action deployed at:", address(sweepRequestDepositERC7540Action));
63+
}
64+
65+
function checkExpectedAddress(address feeTokenRegistry, address treasuryAddress, uint256 gasConstant) public view {
66+
/// @dev before deploying for the first time, generate this expected address by running this script in dry-run mode (see above).
67+
/// once it has been deployed for the first time, that deployed address should be used as the expected address from then on.
68+
address expectedAddress = vm.envAddress("EXPECTED_SWEEP_REQUEST_DEPOSIT_ERC7540_ACTION_ADDRESS");
69+
70+
// calculate the expected address using the current init code
71+
address calculatedAddress = vm.computeCreate2Address(
72+
salt,
73+
keccak256(
74+
abi.encodePacked(
75+
type(SweepRequestDepositERC7540Action).creationCode,
76+
abi.encode(feeTokenRegistry, treasuryAddress, gasConstant)
77+
)
78+
)
79+
);
80+
81+
// revert if the expected address does not match the calculated address
82+
if (expectedAddress != calculatedAddress) {
83+
revert ExpectedAddressMismatch();
84+
}
85+
}
86+
}

0 commit comments

Comments
 (0)