From 8003644c9a2e28cfecfd89b3a724434a1419a7c2 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Thu, 9 Nov 2023 17:51:03 +0200 Subject: [PATCH] Add DEPLOY_TO var for chain selection in .env and scripts --- deployments2.json | 7 ++ package.json | 4 +- script/base/deploy-base.s.sol | 14 ++++ script/deploy-atlas.s.sol | 122 +++++++++++++++++----------------- 4 files changed, 86 insertions(+), 61 deletions(-) create mode 100644 deployments2.json diff --git a/deployments2.json b/deployments2.json new file mode 100644 index 00000000..a4a7777c --- /dev/null +++ b/deployments2.json @@ -0,0 +1,7 @@ +{ + "ATLAS": "0x38c76A767d45Fc390160449948aF80569E2C4217", + "SIMULATOR": "0x721d8077771Ebf9B931733986d619aceea412a1C", + "SWAP_INTENT_DAPP_CONTROL": "0xDC57724Ea354ec925BaFfCA0cCf8A1248a8E5CF1", + "TX_BUILDER": "0xa8d297D643a11cE83b432e87eEBce6bee0fd2bAb", + "SIMPLE_RFQ_SOLVER": "0xEb63D671653489B91E653c52a018B63D5095223B" +} \ No newline at end of file diff --git a/package.json b/package.json index d39d61bc..8d030db1 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,9 @@ "anvil": "anvil", "anvil-mainnet-fork": "source .env && anvil --fork-url ${MAINNET_RPC_URL} --fork-block-number ${MAINNET_FORK_BLOCK_NUMBER} --code-size-limit ${CODE_SIZE_LIMIT}", - "deploy-atlas": "source .env && forge script script/deploy-atlas.s.sol:DeployAtlasScript --fork-url http://localhost:8545 --broadcast --non-interactive", + "deploy-atlas": "source .env && forge script script/deploy-atlas.s.sol:DeployAtlasScript --rpc-url ${SEPOLIA_RPC_URL} --broadcast", + + "deploy-atlas-demo": "source .env && forge script script/deploy-atlas.s.sol:DeployAtlasScript --fork-url http://localhost:8545 --broadcast --non-interactive", "deploy-atlas-swap-intent": "source .env && forge script script/deploy-atlas.s.sol:DeployAtlasAndSwapIntentDAppControlScript --fork-url http://localhost:8545 --broadcast --non-interactive", "deploy-atlas-swap-intent-tx-builder": "source .env && forge script script/deploy-atlas.s.sol:DeployAtlasAndSwapIntentDAppControlAndTxBuilderScript --fork-url http://localhost:8545 --broadcast --non-interactive", "deploy-solver": "source .env && forge script script/deploy-solver.s.sol:DeploySimpleRFQSolverScript --fork-url http://localhost:8545 --broadcast --non-interactive", diff --git a/script/base/deploy-base.s.sol b/script/base/deploy-base.s.sol index 306124a5..7f77186e 100644 --- a/script/base/deploy-base.s.sol +++ b/script/base/deploy-base.s.sol @@ -15,6 +15,20 @@ contract DeployBaseScript is Script { ERC20 WETH = ERC20(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2); ERC20 DAI = ERC20(0x6B175474E89094C44Da98b954EedeAC495271d0F); + function _getDeployChain() internal view returns (string memory) { + // OPTIONS: LOCAL, SEPOLIA, MAINNET + string memory deployChain = vm.envString("DEPLOY_TO"); + if ( + keccak256(bytes(deployChain)) == keccak256(bytes("SEPOLIA")) || + keccak256(bytes(deployChain)) == keccak256(bytes("MAINNET")) || + keccak256(bytes(deployChain)) == keccak256(bytes("LOCAL")) + ) { + return deployChain; + } else { + revert("Error: Set DEPLOY_TO in .env to LOCAL, SEPOLIA, or MAINNET"); + } + } + function _getAddressFromDeploymentsJson(string memory key) internal view returns (address) { string memory root = vm.projectRoot(); string memory path = string.concat(root, "/deployments.json"); diff --git a/script/deploy-atlas.s.sol b/script/deploy-atlas.s.sol index 7bab5a6c..d0277188 100644 --- a/script/deploy-atlas.s.sol +++ b/script/deploy-atlas.s.sol @@ -27,66 +27,68 @@ contract DeployAtlasScript is DeployBaseScript { function run() external { console.log("\n=== DEPLOYING Atlas ===\n"); - uint256 deployerPrivateKey = vm.envUint("GOV_PRIVATE_KEY"); - address deployer = vm.addr(deployerPrivateKey); - // Computes the addresses at which AtlasFactory and AtlasVerification will be deployed - address expectedAtlasFactoryAddr = computeCreateAddress( - deployer, - vm.getNonce(deployer) + 1 - ); - address expectedAtlasVerificationAddr = computeCreateAddress( - deployer, - vm.getNonce(deployer) + 2 - ); - address expectedGasAccountingLibAddr = computeCreateAddress( - deployer, - vm.getNonce(deployer) + 3 - ); - address expectedSafetyLocksLibAddr = computeCreateAddress( - deployer, - vm.getNonce(deployer) + 4 - ); - - console.log("Deployer address: \t\t\t\t", deployer); - - vm.startBroadcast(deployerPrivateKey); - - simulator = new Simulator(); - atlas = new Atlas({ - _escrowDuration: 64, - _factory: expectedAtlasFactoryAddr, - _verification: expectedAtlasVerificationAddr, - _gasAccLib: expectedGasAccountingLibAddr, - _safetyLocksLib: expectedSafetyLocksLibAddr, - _simulator: address(simulator) - }); - atlasFactory = new AtlasFactory(address(atlas)); - atlasVerification = new AtlasVerification(address(atlas)); - gasAccountingLib = new GasAccountingLib({ - _escrowDuration: 64, - _factory: expectedAtlasFactoryAddr, - _verification: expectedAtlasVerificationAddr, - _safetyLocksLib: expectedSafetyLocksLibAddr, - _simulator: address(simulator), - _atlas: address(atlas) - }); - safetyLocksLib = new SafetyLocksLib({ - _escrowDuration: 64, - _factory: expectedAtlasFactoryAddr, - _verification: expectedAtlasVerificationAddr, - _gasAccLib: expectedGasAccountingLibAddr, - _simulator: address(simulator), - _atlas: address(atlas) - }); - - vm.stopBroadcast(); - - _writeAddressToDeploymentsJson(".ATLAS", address(atlas)); - _writeAddressToDeploymentsJson(".SIMULATOR", address(simulator)); - - console.log("\n"); - console.log("Atlas deployed at: \t\t\t\t", address(atlas)); - console.log("Simulator deployed at: \t\t\t", address(simulator)); + console.log("Deploying to chain: ", _getDeployChain()); + + // uint256 deployerPrivateKey = vm.envUint("GOV_PRIVATE_KEY"); + // address deployer = vm.addr(deployerPrivateKey); + // // Computes the addresses at which AtlasFactory and AtlasVerification will be deployed + // address expectedAtlasFactoryAddr = computeCreateAddress( + // deployer, + // vm.getNonce(deployer) + 1 + // ); + // address expectedAtlasVerificationAddr = computeCreateAddress( + // deployer, + // vm.getNonce(deployer) + 2 + // ); + // address expectedGasAccountingLibAddr = computeCreateAddress( + // deployer, + // vm.getNonce(deployer) + 3 + // ); + // address expectedSafetyLocksLibAddr = computeCreateAddress( + // deployer, + // vm.getNonce(deployer) + 4 + // ); + + // console.log("Deployer address: \t\t\t\t", deployer); + + // vm.startBroadcast(deployerPrivateKey); + + // simulator = new Simulator(); + // atlas = new Atlas({ + // _escrowDuration: 64, + // _factory: expectedAtlasFactoryAddr, + // _verification: expectedAtlasVerificationAddr, + // _gasAccLib: expectedGasAccountingLibAddr, + // _safetyLocksLib: expectedSafetyLocksLibAddr, + // _simulator: address(simulator) + // }); + // atlasFactory = new AtlasFactory(address(atlas)); + // atlasVerification = new AtlasVerification(address(atlas)); + // gasAccountingLib = new GasAccountingLib({ + // _escrowDuration: 64, + // _factory: expectedAtlasFactoryAddr, + // _verification: expectedAtlasVerificationAddr, + // _safetyLocksLib: expectedSafetyLocksLibAddr, + // _simulator: address(simulator), + // _atlas: address(atlas) + // }); + // safetyLocksLib = new SafetyLocksLib({ + // _escrowDuration: 64, + // _factory: expectedAtlasFactoryAddr, + // _verification: expectedAtlasVerificationAddr, + // _gasAccLib: expectedGasAccountingLibAddr, + // _simulator: address(simulator), + // _atlas: address(atlas) + // }); + + // vm.stopBroadcast(); + + // _writeAddressToDeploymentsJson(".ATLAS", address(atlas)); + // _writeAddressToDeploymentsJson(".SIMULATOR", address(simulator)); + + // console.log("\n"); + // console.log("Atlas deployed at: \t\t\t\t", address(atlas)); + // console.log("Simulator deployed at: \t\t\t", address(simulator)); } }