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 01/17] 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)); } } From 188be20f581be458446a3465d58f3f1167555e1b Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Thu, 9 Nov 2023 18:04:20 +0200 Subject: [PATCH 02/17] Refactor deploy scripts to new chain/contract json structure --- deployments.json | 28 +++++-- script/base/deploy-base.s.sol | 21 ++++-- script/deploy-atlas.s.sol | 134 +++++++++++++++++----------------- script/deploy-solver.s.sol | 6 +- script/log-balances.s.sol | 6 +- 5 files changed, 109 insertions(+), 86 deletions(-) diff --git a/deployments.json b/deployments.json index a4a7777c..6dc6313f 100644 --- a/deployments.json +++ b/deployments.json @@ -1,7 +1,23 @@ { - "ATLAS": "0x38c76A767d45Fc390160449948aF80569E2C4217", - "SIMULATOR": "0x721d8077771Ebf9B931733986d619aceea412a1C", - "SWAP_INTENT_DAPP_CONTROL": "0xDC57724Ea354ec925BaFfCA0cCf8A1248a8E5CF1", - "TX_BUILDER": "0xa8d297D643a11cE83b432e87eEBce6bee0fd2bAb", - "SIMPLE_RFQ_SOLVER": "0xEb63D671653489B91E653c52a018B63D5095223B" -} \ No newline at end of file + "LOCAL": { + "ATLAS": "0x38c76A767d45Fc390160449948aF80569E2C4217", + "SIMULATOR": "0x721d8077771Ebf9B931733986d619aceea412a1C", + "SWAP_INTENT_DAPP_CONTROL": "0xDC57724Ea354ec925BaFfCA0cCf8A1248a8E5CF1", + "TX_BUILDER": "0xa8d297D643a11cE83b432e87eEBce6bee0fd2bAb", + "SIMPLE_RFQ_SOLVER": "0xEb63D671653489B91E653c52a018B63D5095223B" + }, + "SEPOLIA": { + "ATLAS": "", + "SIMULATOR": "", + "SWAP_INTENT_DAPP_CONTROL": "", + "TX_BUILDER": "", + "SIMPLE_RFQ_SOLVER": "" + }, + "MAINNET": { + "ATLAS": "", + "SIMULATOR": "", + "SWAP_INTENT_DAPP_CONTROL": "", + "TX_BUILDER": "", + "SIMPLE_RFQ_SOLVER": "" + } +} diff --git a/script/base/deploy-base.s.sol b/script/base/deploy-base.s.sol index 7f77186e..93832b99 100644 --- a/script/base/deploy-base.s.sol +++ b/script/base/deploy-base.s.sol @@ -7,7 +7,7 @@ import "forge-std/StdJson.sol"; import {ERC20} from "solmate/tokens/ERC20.sol"; -// NOTE: When handling JSON with StdJson, prefix keys with '.' e.g. '.ATLAS' + contract DeployBaseScript is Script { using stdJson for string; @@ -29,23 +29,34 @@ contract DeployBaseScript is Script { } } + // NOTE: When handling JSON with StdJson, prefix keys with '.' e.g. '.ATLAS' + // These 2 functions abstract away the '.' thing though. + // Just pass in a key like 'ATLAS' and 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"); string memory json = vm.readFile(path); - // console.log("Getting", key, "from deployments.json"); + // Read target chain from DEPLOY_TO in .env and use to form full key + string memory fullKey = string.concat(".", _getDeployChain(), ".", key); + + console.log("Getting", fullKey, "from deployments.json"); - return json.readAddress(key); + // NOTE: Use fullKey method above for safety + return json.readAddress(fullKey); } function _writeAddressToDeploymentsJson(string memory key, address addr) internal { string memory root = vm.projectRoot(); string memory path = string.concat(root, "/deployments.json"); - // console.log(string.concat("Writing \t\t'", key), "': '", addr, "'\t\t to deployments.json"); + // Read target chain from DEPLOY_TO in .env and use to form full key + string memory fullKey = string.concat(".", _getDeployChain(), ".", key); + + console.log(string.concat("Writing \t\t'", fullKey), "': '", addr, "'\t\t to deployments.json"); - vm.writeJson(vm.toString(addr), path, key); + // NOTE: Use fullKey method above for safety + vm.writeJson(vm.toString(addr), path, fullKey); } function _logTokenBalances(address account, string memory accountLabel) internal view { diff --git a/script/deploy-atlas.s.sol b/script/deploy-atlas.s.sol index d0277188..bf03266c 100644 --- a/script/deploy-atlas.s.sol +++ b/script/deploy-atlas.s.sol @@ -29,66 +29,66 @@ contract DeployAtlasScript is DeployBaseScript { 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)); + 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)); } } @@ -165,9 +165,9 @@ contract DeployAtlasAndSwapIntentDAppControlScript is DeployBaseScript { vm.stopBroadcast(); - _writeAddressToDeploymentsJson(".ATLAS", address(atlas)); - _writeAddressToDeploymentsJson(".SIMULATOR", address(simulator)); - _writeAddressToDeploymentsJson(".SWAP_INTENT_DAPP_CONTROL", address(swapIntentControl)); + _writeAddressToDeploymentsJson("ATLAS", address(atlas)); + _writeAddressToDeploymentsJson("SIMULATOR", address(simulator)); + _writeAddressToDeploymentsJson("SWAP_INTENT_DAPP_CONTROL", address(swapIntentControl)); console.log("\n"); console.log("Atlas deployed at: \t\t\t\t", address(atlas)); @@ -253,10 +253,10 @@ contract DeployAtlasAndSwapIntentDAppControlAndTxBuilderScript is DeployBaseScri vm.stopBroadcast(); - _writeAddressToDeploymentsJson(".ATLAS", address(atlas)); - _writeAddressToDeploymentsJson(".SIMULATOR", address(simulator)); - _writeAddressToDeploymentsJson(".SWAP_INTENT_DAPP_CONTROL", address(swapIntentControl)); - _writeAddressToDeploymentsJson(".TX_BUILDER", address(txBuilder)); + _writeAddressToDeploymentsJson("ATLAS", address(atlas)); + _writeAddressToDeploymentsJson("SIMULATOR", address(simulator)); + _writeAddressToDeploymentsJson("SWAP_INTENT_DAPP_CONTROL", address(swapIntentControl)); + _writeAddressToDeploymentsJson("TX_BUILDER", address(txBuilder)); console.log("\n"); console.log("Atlas deployed at: \t\t\t\t", address(atlas)); diff --git a/script/deploy-solver.s.sol b/script/deploy-solver.s.sol index 3dca40f6..18d027e5 100644 --- a/script/deploy-solver.s.sol +++ b/script/deploy-solver.s.sol @@ -8,8 +8,6 @@ import "forge-std/StdJson.sol"; import {DeployBaseScript} from "script/base/deploy-base.s.sol"; import {SimpleRFQSolver} from "test/SwapIntent.t.sol"; -// NOTE: When handling JSON with StdJson, prefix keys with '.' e.g. '.ATLAS' - contract DeploySimpleRFQSolverScript is DeployBaseScript { SimpleRFQSolver public rfqSolver; @@ -19,7 +17,7 @@ contract DeploySimpleRFQSolverScript is DeployBaseScript { uint256 deployerPrivateKey = vm.envUint("SOLVER1_PRIVATE_KEY"); address deployer = vm.addr(deployerPrivateKey); - address atlasAddress = _getAddressFromDeploymentsJson(".ATLAS"); + address atlasAddress = _getAddressFromDeploymentsJson("ATLAS"); console.log("Deployer address: \t\t\t\t", deployer); console.log("Using Atlas address: \t\t\t\t", atlasAddress); @@ -30,7 +28,7 @@ contract DeploySimpleRFQSolverScript is DeployBaseScript { vm.stopBroadcast(); - _writeAddressToDeploymentsJson(".SIMPLE_RFQ_SOLVER", address(rfqSolver)); + _writeAddressToDeploymentsJson("SIMPLE_RFQ_SOLVER", address(rfqSolver)); console.log("\n"); console.log("SimpleRFQSolver deployed at: \t\t\t", address(rfqSolver)); diff --git a/script/log-balances.s.sol b/script/log-balances.s.sol index c051f762..5e4e9387 100644 --- a/script/log-balances.s.sol +++ b/script/log-balances.s.sol @@ -7,8 +7,6 @@ import "forge-std/StdJson.sol"; import {DeployBaseScript} from "script/base/deploy-base.s.sol"; -// NOTE: When handling JSON with StdJson, prefix keys with '.' e.g. '.ATLAS' - contract LogDemoBalancesScript is DeployBaseScript { function run() external { @@ -25,11 +23,11 @@ contract LogDemoBalancesScript is DeployBaseScript { _logTokenBalances(account, "Solver 1"); // Atlas contract - account = _getAddressFromDeploymentsJson(".ATLAS"); + account = _getAddressFromDeploymentsJson("ATLAS"); _logTokenBalances(account, "Atlas"); // Simple RFQ Solver contract - account = _getAddressFromDeploymentsJson(".SIMPLE_RFQ_SOLVER"); + account = _getAddressFromDeploymentsJson("SIMPLE_RFQ_SOLVER"); _logTokenBalances(account, "Simple RFQ Solver"); } } \ No newline at end of file From 424c326b98781369997da0cfdb291ea0b33eff35 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Thu, 9 Nov 2023 18:18:57 +0200 Subject: [PATCH 03/17] Include new contract addrs in basic atlas deploy script --- deployments.json | 18 +++++++++++++++--- package.json | 5 +++-- script/base/deploy-base.s.sol | 2 -- script/deploy-atlas.s.sol | 10 ++++++++++ 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/deployments.json b/deployments.json index 6dc6313f..a386fc47 100644 --- a/deployments.json +++ b/deployments.json @@ -1,13 +1,21 @@ { "LOCAL": { - "ATLAS": "0x38c76A767d45Fc390160449948aF80569E2C4217", - "SIMULATOR": "0x721d8077771Ebf9B931733986d619aceea412a1C", + "ATLAS": "0x4653251486a57f90Ee89F9f34E098b9218659b83", + "ATLAS_FACTORY": "0x89ec9355b1Bcc964e576211c8B011BD709083f8d", + "ATLAS_VERIFICATION": "0x72662E4da74278430123cE51405c1e7A1B87C294", + "GAS_ACCOUNTING_LIB": "0x52bad4A8584909895C22bdEcf8DBF33314468Fb0", + "SAFETY_LOCKS_LIB": "0xed12bE400A07910E4d4E743E4ceE26ab1FC9a961", + "SIMULATOR": "0x20Dc424c5fa468CbB1c702308F0cC9c14DA2825C", "SWAP_INTENT_DAPP_CONTROL": "0xDC57724Ea354ec925BaFfCA0cCf8A1248a8E5CF1", "TX_BUILDER": "0xa8d297D643a11cE83b432e87eEBce6bee0fd2bAb", "SIMPLE_RFQ_SOLVER": "0xEb63D671653489B91E653c52a018B63D5095223B" }, "SEPOLIA": { "ATLAS": "", + "ATLAS_FACTORY": "", + "ATLAS_VERIFICATION": "", + "GAS_ACCOUNTING_LIB": "", + "SAFETY_LOCKS_LIB": "", "SIMULATOR": "", "SWAP_INTENT_DAPP_CONTROL": "", "TX_BUILDER": "", @@ -15,9 +23,13 @@ }, "MAINNET": { "ATLAS": "", + "ATLAS_FACTORY": "", + "ATLAS_VERIFICATION": "", + "GAS_ACCOUNTING_LIB": "", + "SAFETY_LOCKS_LIB": "", "SIMULATOR": "", "SWAP_INTENT_DAPP_CONTROL": "", "TX_BUILDER": "", "SIMPLE_RFQ_SOLVER": "" } -} +} \ No newline at end of file diff --git a/package.json b/package.json index 8d030db1..169dbee9 100644 --- a/package.json +++ b/package.json @@ -15,8 +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 --rpc-url ${SEPOLIA_RPC_URL} --broadcast", - + "deploy-atlas-sepolia": "source .env && forge script script/deploy-atlas.s.sol:DeployAtlasScript --rpc-url ${SEPOLIA_RPC_URL} --broadcast", + "deploy-atlas-local": "source .env && forge script script/deploy-atlas.s.sol:DeployAtlasScript --fork-url http://localhost:8545 --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", diff --git a/script/base/deploy-base.s.sol b/script/base/deploy-base.s.sol index 93832b99..4907b47c 100644 --- a/script/base/deploy-base.s.sol +++ b/script/base/deploy-base.s.sol @@ -7,8 +7,6 @@ import "forge-std/StdJson.sol"; import {ERC20} from "solmate/tokens/ERC20.sol"; - - contract DeployBaseScript is Script { using stdJson for string; diff --git a/script/deploy-atlas.s.sol b/script/deploy-atlas.s.sol index bf03266c..9a0c264d 100644 --- a/script/deploy-atlas.s.sol +++ b/script/deploy-atlas.s.sol @@ -84,11 +84,21 @@ contract DeployAtlasScript is DeployBaseScript { vm.stopBroadcast(); _writeAddressToDeploymentsJson("ATLAS", address(atlas)); + _writeAddressToDeploymentsJson("ATLAS_FACTORY", address(atlasFactory)); + _writeAddressToDeploymentsJson("ATLAS_VERIFICATION", address(atlasVerification)); + _writeAddressToDeploymentsJson("GAS_ACCOUNTING_LIB", address(gasAccountingLib)); + _writeAddressToDeploymentsJson("SAFETY_LOCKS_LIB", address(safetyLocksLib)); _writeAddressToDeploymentsJson("SIMULATOR", address(simulator)); console.log("\n"); console.log("Atlas deployed at: \t\t\t\t", address(atlas)); + console.log("AtlasFactory deployed at: \t\t\t", address(atlasFactory)); + console.log("AtlasVerification deployed at: \t\t", address(atlasVerification)); + console.log("GasAccountingLib deployed at: \t\t", address(gasAccountingLib)); + console.log("SafetyLocksLib deployed at: \t\t\t", address(safetyLocksLib)); console.log("Simulator deployed at: \t\t\t", address(simulator)); + console.log("\n"); + console.log("You can find a list of contract addresses from the latest deployment in deployments.json"); } } From 67c231265064e31236335ffc02a3c59bef7d27f7 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Thu, 9 Nov 2023 18:37:55 +0200 Subject: [PATCH 04/17] Deploy script refactor and improvements --- deployments.json | 4 +- deployments2.json | 7 - package.json | 5 + script/base/deploy-base.s.sol | 24 +++- script/deploy-atlas.s.sol | 183 +----------------------- script/deploy-solver.s.sol | 3 - script/deploy-swap-intent-control.s.sol | 49 +++++++ 7 files changed, 79 insertions(+), 196 deletions(-) delete mode 100644 deployments2.json create mode 100644 script/deploy-swap-intent-control.s.sol diff --git a/deployments.json b/deployments.json index a386fc47..621aa108 100644 --- a/deployments.json +++ b/deployments.json @@ -6,8 +6,8 @@ "GAS_ACCOUNTING_LIB": "0x52bad4A8584909895C22bdEcf8DBF33314468Fb0", "SAFETY_LOCKS_LIB": "0xed12bE400A07910E4d4E743E4ceE26ab1FC9a961", "SIMULATOR": "0x20Dc424c5fa468CbB1c702308F0cC9c14DA2825C", - "SWAP_INTENT_DAPP_CONTROL": "0xDC57724Ea354ec925BaFfCA0cCf8A1248a8E5CF1", - "TX_BUILDER": "0xa8d297D643a11cE83b432e87eEBce6bee0fd2bAb", + "SWAP_INTENT_DAPP_CONTROL": "0x1B25157F05B25438441bF7CDe38A95A55ccf8E50", + "TX_BUILDER": "", "SIMPLE_RFQ_SOLVER": "0xEb63D671653489B91E653c52a018B63D5095223B" }, "SEPOLIA": { diff --git a/deployments2.json b/deployments2.json deleted file mode 100644 index a4a7777c..00000000 --- a/deployments2.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "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 169dbee9..49c0039e 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,11 @@ "deploy-atlas-sepolia": "source .env && forge script script/deploy-atlas.s.sol:DeployAtlasScript --rpc-url ${SEPOLIA_RPC_URL} --broadcast", "deploy-atlas-local": "source .env && forge script script/deploy-atlas.s.sol:DeployAtlasScript --fork-url http://localhost:8545 --broadcast", + "deploy-swap-intent-sepolia": "source .env && forge script script/deploy-swap-intent-control.s.sol:DeploySwapIntentControlScript --rpc-url ${SEPOLIA_RPC_URL} --broadcast", + "deploy-swap-intent-local": "source .env && forge script script/deploy-swap-intent-control.s.sol:DeploySwapIntentControlScript --fork-url http://localhost:8545 --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", diff --git a/script/base/deploy-base.s.sol b/script/base/deploy-base.s.sol index 4907b47c..da06d316 100644 --- a/script/base/deploy-base.s.sol +++ b/script/base/deploy-base.s.sol @@ -7,12 +7,32 @@ import "forge-std/StdJson.sol"; import {ERC20} from "solmate/tokens/ERC20.sol"; +import {Atlas} from "src/contracts/atlas/Atlas.sol"; +import {AtlasFactory} from "src/contracts/atlas/AtlasFactory.sol"; +import {AtlasVerification} from "src/contracts/atlas/AtlasVerification.sol"; +import {GasAccountingLib} from "src/contracts/atlas/GasAccountingLib.sol"; +import {SafetyLocksLib} from "src/contracts/atlas/SafetyLocksLib.sol"; +import {SwapIntentController} from "src/contracts/examples/intents-example/SwapIntent.sol"; +import {TxBuilder} from "src/contracts/helpers/TxBuilder.sol"; +import {Simulator} from "src/contracts/helpers/Simulator.sol"; +import {SimpleRFQSolver} from "test/SwapIntent.t.sol"; + contract DeployBaseScript is Script { using stdJson for string; ERC20 WETH = ERC20(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2); ERC20 DAI = ERC20(0x6B175474E89094C44Da98b954EedeAC495271d0F); + Atlas public atlas; + AtlasFactory public atlasFactory; + AtlasVerification public atlasVerification; + GasAccountingLib public gasAccountingLib; + SafetyLocksLib public safetyLocksLib; + Simulator public simulator; + SwapIntentController public swapIntentControl; + TxBuilder public txBuilder; + SimpleRFQSolver public rfqSolver; + function _getDeployChain() internal view returns (string memory) { // OPTIONS: LOCAL, SEPOLIA, MAINNET string memory deployChain = vm.envString("DEPLOY_TO"); @@ -38,7 +58,7 @@ contract DeployBaseScript is Script { // Read target chain from DEPLOY_TO in .env and use to form full key string memory fullKey = string.concat(".", _getDeployChain(), ".", key); - console.log("Getting", fullKey, "from deployments.json"); + // console.log("Getting", fullKey, "from deployments.json"); // NOTE: Use fullKey method above for safety return json.readAddress(fullKey); @@ -51,7 +71,7 @@ contract DeployBaseScript is Script { // Read target chain from DEPLOY_TO in .env and use to form full key string memory fullKey = string.concat(".", _getDeployChain(), ".", key); - console.log(string.concat("Writing \t\t'", fullKey), "': '", addr, "'\t\t to deployments.json"); + // console.log(string.concat("Writing \t\t'", fullKey), "': '", addr, "'\t\t to deployments.json"); // NOTE: Use fullKey method above for safety vm.writeJson(vm.toString(addr), path, fullKey); diff --git a/script/deploy-atlas.s.sol b/script/deploy-atlas.s.sol index 9a0c264d..9f40b23f 100644 --- a/script/deploy-atlas.s.sol +++ b/script/deploy-atlas.s.sol @@ -16,14 +16,6 @@ import {TxBuilder} from "src/contracts/helpers/TxBuilder.sol"; import {Simulator} from "src/contracts/helpers/Simulator.sol"; contract DeployAtlasScript is DeployBaseScript { - // TODO move commons vars like these to base deploy script - Atlas public atlas; - AtlasFactory public atlasFactory; - AtlasVerification public atlasVerification; - GasAccountingLib public gasAccountingLib; - SafetyLocksLib public safetyLocksLib; - Simulator public simulator; - function run() external { console.log("\n=== DEPLOYING Atlas ===\n"); @@ -80,6 +72,7 @@ contract DeployAtlasScript is DeployBaseScript { _simulator: address(simulator), _atlas: address(atlas) }); + simulator.setAtlas(address(atlas)); vm.stopBroadcast(); @@ -101,177 +94,3 @@ contract DeployAtlasScript is DeployBaseScript { console.log("You can find a list of contract addresses from the latest deployment in deployments.json"); } } - -contract DeployAtlasAndSwapIntentDAppControlScript is DeployBaseScript { - Atlas public atlas; - AtlasFactory public atlasFactory; - AtlasVerification public atlasVerification; - GasAccountingLib public gasAccountingLib; - SafetyLocksLib public safetyLocksLib; - Simulator public simulator; - SwapIntentController public swapIntentControl; - - function run() external { - console.log("\n=== DEPLOYING Atlas and SwapIntent DAppControl ===\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) - }); - - // Deploy the SwapIntent DAppControl contract - swapIntentControl = new SwapIntentController(address(atlas)); - - // Integrate SwapIntent with Atlas - atlasVerification.initializeGovernance(address(swapIntentControl)); - atlasVerification.integrateDApp(address(swapIntentControl)); - - vm.stopBroadcast(); - - _writeAddressToDeploymentsJson("ATLAS", address(atlas)); - _writeAddressToDeploymentsJson("SIMULATOR", address(simulator)); - _writeAddressToDeploymentsJson("SWAP_INTENT_DAPP_CONTROL", address(swapIntentControl)); - - 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("SwapIntent DAppControl deployed at: \t\t", address(swapIntentControl)); - } -} - -contract DeployAtlasAndSwapIntentDAppControlAndTxBuilderScript is DeployBaseScript { - Atlas public atlas; - AtlasFactory public atlasFactory; - AtlasVerification public atlasVerification; - GasAccountingLib public gasAccountingLib; - SafetyLocksLib public safetyLocksLib; - Simulator public simulator; - SwapIntentController public swapIntentControl; - TxBuilder public txBuilder; - - function run() external { - console.log("\n=== DEPLOYING Atlas and SwapIntent DAppControl and TxBuilder ===\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) - }); - - // Deploy the SwapIntent DAppControl contract - swapIntentControl = new SwapIntentController(address(atlas)); - - // Integrate SwapIntent with Atlas - atlasVerification.initializeGovernance(address(swapIntentControl)); - atlasVerification.integrateDApp(address(swapIntentControl)); - - // Deploy the TxBuilder - txBuilder = new TxBuilder(address(swapIntentControl), address(atlas), address(atlas)); - - vm.stopBroadcast(); - - _writeAddressToDeploymentsJson("ATLAS", address(atlas)); - _writeAddressToDeploymentsJson("SIMULATOR", address(simulator)); - _writeAddressToDeploymentsJson("SWAP_INTENT_DAPP_CONTROL", address(swapIntentControl)); - _writeAddressToDeploymentsJson("TX_BUILDER", address(txBuilder)); - - 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("SwapIntent DAppControl deployed at: \t\t", address(swapIntentControl)); - console.log("TxBuilder deployed at: \t\t\t", address(txBuilder)); - } -} diff --git a/script/deploy-solver.s.sol b/script/deploy-solver.s.sol index 18d027e5..98363c4c 100644 --- a/script/deploy-solver.s.sol +++ b/script/deploy-solver.s.sol @@ -9,9 +9,6 @@ import {DeployBaseScript} from "script/base/deploy-base.s.sol"; import {SimpleRFQSolver} from "test/SwapIntent.t.sol"; contract DeploySimpleRFQSolverScript is DeployBaseScript { - SimpleRFQSolver public rfqSolver; - - function run() external { console.log("\n=== DEPLOYING SimpleRFQSolver ===\n"); diff --git a/script/deploy-swap-intent-control.s.sol b/script/deploy-swap-intent-control.s.sol new file mode 100644 index 00000000..d0966d4b --- /dev/null +++ b/script/deploy-swap-intent-control.s.sol @@ -0,0 +1,49 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity 0.8.21; + +import "forge-std/Script.sol"; +import "forge-std/Test.sol"; + +import {DeployBaseScript} from "script/base/deploy-base.s.sol"; + +import {Atlas} from "src/contracts/atlas/Atlas.sol"; +import {AtlasFactory} from "src/contracts/atlas/AtlasFactory.sol"; +import {AtlasVerification} from "src/contracts/atlas/AtlasVerification.sol"; +import {GasAccountingLib} from "src/contracts/atlas/GasAccountingLib.sol"; +import {SafetyLocksLib} from "src/contracts/atlas/SafetyLocksLib.sol"; +import {SwapIntentController} from "src/contracts/examples/intents-example/SwapIntent.sol"; +import {TxBuilder} from "src/contracts/helpers/TxBuilder.sol"; +import {Simulator} from "src/contracts/helpers/Simulator.sol"; + +contract DeploySwapIntentControlScript is DeployBaseScript { + function run() external { + console.log("\n=== DEPLOYING SwapIntent DAppControl ===\n"); + console.log("And setting up with initializeGovernance and integrateDApp\n"); + + uint256 deployerPrivateKey = vm.envUint("GOV_PRIVATE_KEY"); + address deployer = vm.addr(deployerPrivateKey); + + atlas = Atlas(payable(_getAddressFromDeploymentsJson("ATLAS"))); + atlasVerification = AtlasVerification(payable(_getAddressFromDeploymentsJson("ATLAS_VERIFICATION"))); + + console.log("Deployer address: \t\t\t\t", deployer); + + vm.startBroadcast(deployerPrivateKey); + + // Deploy the SwapIntent DAppControl contract + swapIntentControl = new SwapIntentController(address(atlas)); + + // Integrate SwapIntent with Atlas + atlasVerification.initializeGovernance(address(swapIntentControl)); + atlasVerification.integrateDApp(address(swapIntentControl)); + + vm.stopBroadcast(); + + _writeAddressToDeploymentsJson("SWAP_INTENT_DAPP_CONTROL", address(swapIntentControl)); + + console.log("\n"); + console.log("SwapIntent DAppControl deployed at: \t\t", address(swapIntentControl)); + console.log("\n"); + console.log("You can find a list of contract addresses from the latest deployment in deployments.json"); + } +} \ No newline at end of file From 9ca6e5bffa0950983d55f153aac252bcf6ae4c0f Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Thu, 9 Nov 2023 19:41:36 +0200 Subject: [PATCH 05/17] Update with Sepolia deployment info --- .env.example | 14 +++++++++++--- deployments.json | 14 +++++++------- package.json | 6 ++---- script/deploy-solver.s.sol | 2 ++ 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/.env.example b/.env.example index de2c64cc..0e412d29 100644 --- a/.env.example +++ b/.env.example @@ -1,10 +1,11 @@ -MAINNET_RPC_URL=https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY_GOES_HERE +MAINNET_RPC_URL=https://eth-mainnet.g.alchemy.com/v2/XXXXXXXX MAINNET_FORK_BLOCK_NUMBER=18219600 CODE_SIZE_LIMIT=100000 +GAS_LIMIT=1000000000000 -# Private keys are the default ones generated by Anvil - +# Atlas Deployer GOV_PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 + USER_PRIVATE_KEY=0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d SOLVER1_PRIVATE_KEY=0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a SOLVER2_PRIVATE_KEY=0x47e179ec197488593b187f80a00eb0da91f1b9d0b13f8733639f19c30a34926a @@ -16,3 +17,10 @@ WETH_FOR_USER=10000000000000000000 DAI=0x6B175474E89094C44Da98b954EedeAC495271d0F DAI_WHALE=0x075e72a5eDf65F0A5f44699c7654C1a76941Ddc8 DAI_FOR_SOLVER=5000000000000000000000 + +SEPOLIA_RPC_URL=https://eth-sepolia.g.alchemy.com/v2/XXXXXXXX +ETHERSCAN_API_KEY=XXXXXXXX + +# NOTE: Set chain pref here AND in the --rpc-url flag in the forge command +# Options: SEPOLIA, MAINNET, LOCAL, HOSTED_ANVIL +DEPLOY_TO=LOCAL \ No newline at end of file diff --git a/deployments.json b/deployments.json index 621aa108..df295c01 100644 --- a/deployments.json +++ b/deployments.json @@ -11,13 +11,13 @@ "SIMPLE_RFQ_SOLVER": "0xEb63D671653489B91E653c52a018B63D5095223B" }, "SEPOLIA": { - "ATLAS": "", - "ATLAS_FACTORY": "", - "ATLAS_VERIFICATION": "", - "GAS_ACCOUNTING_LIB": "", - "SAFETY_LOCKS_LIB": "", - "SIMULATOR": "", - "SWAP_INTENT_DAPP_CONTROL": "", + "ATLAS": "0xF6A9eD78A9dbe919A9aAAF2aB6A6Abba8856Bc88", + "ATLAS_FACTORY": "0x48201501aeCD974cc350cF27aBB5eCD9b7076581", + "ATLAS_VERIFICATION": "0x03C5C3658caC2c518Fd09E114293afC83e56BF94", + "GAS_ACCOUNTING_LIB": "0x2d1D4AAE1710DbD8871A3A94A1bBd0b25351aD97", + "SAFETY_LOCKS_LIB": "0xc07fE37C5a834622c1D77eF24f0E7cDFb460E739", + "SIMULATOR": "0xf05a353DB6C59c1812cae83C919bb4d09e98a303", + "SWAP_INTENT_DAPP_CONTROL": "0xa16555AA3Ac77b501e5C9171dac9df28ad321aAb", "TX_BUILDER": "", "SIMPLE_RFQ_SOLVER": "" }, diff --git a/package.json b/package.json index 49c0039e..d7c3dbe1 100644 --- a/package.json +++ b/package.json @@ -15,14 +15,12 @@ "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-sepolia": "source .env && forge script script/deploy-atlas.s.sol:DeployAtlasScript --rpc-url ${SEPOLIA_RPC_URL} --broadcast", + "deploy-atlas-sepolia": "source .env && forge script script/deploy-atlas.s.sol:DeployAtlasScript --rpc-url ${SEPOLIA_RPC_URL} --broadcast --etherscan-api-key ${ETHERSCAN_API_KEY} --verify", "deploy-atlas-local": "source .env && forge script script/deploy-atlas.s.sol:DeployAtlasScript --fork-url http://localhost:8545 --broadcast", - "deploy-swap-intent-sepolia": "source .env && forge script script/deploy-swap-intent-control.s.sol:DeploySwapIntentControlScript --rpc-url ${SEPOLIA_RPC_URL} --broadcast", + "deploy-swap-intent-sepolia": "source .env && forge script script/deploy-swap-intent-control.s.sol:DeploySwapIntentControlScript --rpc-url ${SEPOLIA_RPC_URL} --broadcast --etherscan-api-key ${ETHERSCAN_API_KEY} --verify", "deploy-swap-intent-local": "source .env && forge script script/deploy-swap-intent-control.s.sol:DeploySwapIntentControlScript --fork-url http://localhost:8545 --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", diff --git a/script/deploy-solver.s.sol b/script/deploy-solver.s.sol index 98363c4c..f8178e4e 100644 --- a/script/deploy-solver.s.sol +++ b/script/deploy-solver.s.sol @@ -29,5 +29,7 @@ contract DeploySimpleRFQSolverScript is DeployBaseScript { console.log("\n"); console.log("SimpleRFQSolver deployed at: \t\t\t", address(rfqSolver)); + console.log("\n"); + console.log("You can find a list of contract addresses from the latest deployment in deployments.json"); } } \ No newline at end of file From 8d77bb8bfd4c957bceefece9223b76ced71c2cc1 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Fri, 10 Nov 2023 08:24:42 +0200 Subject: [PATCH 06/17] Add TxBuilder deploy script --- package.json | 6 ++++ script/deploy-tx-builder.s.sol | 50 ++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 script/deploy-tx-builder.s.sol diff --git a/package.json b/package.json index d7c3dbe1..da4d06a6 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,12 @@ "deploy-swap-intent-sepolia": "source .env && forge script script/deploy-swap-intent-control.s.sol:DeploySwapIntentControlScript --rpc-url ${SEPOLIA_RPC_URL} --broadcast --etherscan-api-key ${ETHERSCAN_API_KEY} --verify", "deploy-swap-intent-local": "source .env && forge script script/deploy-swap-intent-control.s.sol:DeploySwapIntentControlScript --fork-url http://localhost:8545 --broadcast", + "deploy-tx-builder-sepolia": "source .env && forge script script/deploy-tx-builder.s.sol:DeployTxBuilderScript --rpc-url ${SEPOLIA_RPC_URL} --broadcast --etherscan-api-key ${ETHERSCAN_API_KEY} --verify", + "deploy-tx-builder-local": "source .env && forge script script/deploy-tx-builder.s.sol:DeployTxBuilderScript --fork-url http://localhost:8545 --broadcast", + + "deploy-solver-sepolia": "source .env && forge script script/deploy-solver.s.sol:DeploySimpleRFQSolverScript --rpc-url ${SEPOLIA_RPC_URL} --broadcast --etherscan-api-key ${ETHERSCAN_API_KEY} --verify", + "deploy-solver-local": "source .env && forge script script/deploy-solver.s.sol:DeploySimpleRFQSolverScript --fork-url http://localhost:8545 --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", diff --git a/script/deploy-tx-builder.s.sol b/script/deploy-tx-builder.s.sol new file mode 100644 index 00000000..6fbe3c74 --- /dev/null +++ b/script/deploy-tx-builder.s.sol @@ -0,0 +1,50 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity 0.8.21; + +import "forge-std/Script.sol"; +import "forge-std/Test.sol"; + +import {DeployBaseScript} from "script/base/deploy-base.s.sol"; + +import {Atlas} from "src/contracts/atlas/Atlas.sol"; +import {AtlasFactory} from "src/contracts/atlas/AtlasFactory.sol"; +import {AtlasVerification} from "src/contracts/atlas/AtlasVerification.sol"; +import {GasAccountingLib} from "src/contracts/atlas/GasAccountingLib.sol"; +import {SafetyLocksLib} from "src/contracts/atlas/SafetyLocksLib.sol"; +import {SwapIntentController} from "src/contracts/examples/intents-example/SwapIntent.sol"; +import {TxBuilder} from "src/contracts/helpers/TxBuilder.sol"; +import {Simulator} from "src/contracts/helpers/Simulator.sol"; + +contract DeployTxBuilderScript is DeployBaseScript { + function run() external { + console.log("\n=== DEPLOYING Tx Builder ===\n"); + console.log("And configuring with the currernt SwapIntent DAppControl deployment..."); + + console.log("Deploying to chain: ", _getDeployChain()); + + uint256 deployerPrivateKey = vm.envUint("GOV_PRIVATE_KEY"); + address deployer = vm.addr(deployerPrivateKey); + console.log("Deployer address: \t\t\t\t", deployer); + + address atlasAddress = _getAddressFromDeploymentsJson("ATLAS"); + address atlasVerificationAddress = _getAddressFromDeploymentsJson("ATLAS_VERIFICATION"); + address swapIntentControlAddress = _getAddressFromDeploymentsJson("SWAP_INTENT_DAPP_CONTROL"); + + vm.startBroadcast(deployerPrivateKey); + + txBuilder = new TxBuilder({ + controller: swapIntentControlAddress, + atlasAddress: atlasAddress, + _verification: atlasVerificationAddress + }); + + vm.stopBroadcast(); + + _writeAddressToDeploymentsJson("TX_BUILDER", address(txBuilder)); + + console.log("\n"); + console.log("Tx Builder deployed at: \t\t\t", address(txBuilder)); + console.log("\n"); + console.log("You can find a list of contract addresses from the latest deployment in deployments.json"); + } +} From b6af168e9c761853ffc6bb15ef642967b11280ff Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Fri, 10 Nov 2023 09:17:52 +0200 Subject: [PATCH 07/17] Update Sepolia deployments --- deployments.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/deployments.json b/deployments.json index df295c01..329fdddc 100644 --- a/deployments.json +++ b/deployments.json @@ -17,9 +17,9 @@ "GAS_ACCOUNTING_LIB": "0x2d1D4AAE1710DbD8871A3A94A1bBd0b25351aD97", "SAFETY_LOCKS_LIB": "0xc07fE37C5a834622c1D77eF24f0E7cDFb460E739", "SIMULATOR": "0xf05a353DB6C59c1812cae83C919bb4d09e98a303", - "SWAP_INTENT_DAPP_CONTROL": "0xa16555AA3Ac77b501e5C9171dac9df28ad321aAb", - "TX_BUILDER": "", - "SIMPLE_RFQ_SOLVER": "" + "SWAP_INTENT_DAPP_CONTROL": "0x8bE1810264AeA4E1C265B3cD152F397FA07e63CC", + "TX_BUILDER": "0xDc7fECC520908A9142FA0C7309AF9b5674625C92", + "SIMPLE_RFQ_SOLVER": "0x7966948CDd93fDB930819Aa5b97C9d012Fb12D7a" }, "MAINNET": { "ATLAS": "", From 30c6cf4fecfeddcd31b15478a183355716bf21f8 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Fri, 10 Nov 2023 10:50:00 +0200 Subject: [PATCH 08/17] Fix addr bugs in Atlas deploy script --- deployments.json | 18 +++++++++--------- package.json | 2 ++ script/deploy-atlas.s.sol | 15 +++++++++++---- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/deployments.json b/deployments.json index 329fdddc..95deba5c 100644 --- a/deployments.json +++ b/deployments.json @@ -11,15 +11,15 @@ "SIMPLE_RFQ_SOLVER": "0xEb63D671653489B91E653c52a018B63D5095223B" }, "SEPOLIA": { - "ATLAS": "0xF6A9eD78A9dbe919A9aAAF2aB6A6Abba8856Bc88", - "ATLAS_FACTORY": "0x48201501aeCD974cc350cF27aBB5eCD9b7076581", - "ATLAS_VERIFICATION": "0x03C5C3658caC2c518Fd09E114293afC83e56BF94", - "GAS_ACCOUNTING_LIB": "0x2d1D4AAE1710DbD8871A3A94A1bBd0b25351aD97", - "SAFETY_LOCKS_LIB": "0xc07fE37C5a834622c1D77eF24f0E7cDFb460E739", - "SIMULATOR": "0xf05a353DB6C59c1812cae83C919bb4d09e98a303", - "SWAP_INTENT_DAPP_CONTROL": "0x8bE1810264AeA4E1C265B3cD152F397FA07e63CC", - "TX_BUILDER": "0xDc7fECC520908A9142FA0C7309AF9b5674625C92", - "SIMPLE_RFQ_SOLVER": "0x7966948CDd93fDB930819Aa5b97C9d012Fb12D7a" + "ATLAS": "0x590cBb439Bfb3C37ad6CcE12C92427B0358cB4Dd", + "ATLAS_FACTORY": "0xfa0aBaf52f853Ef651F14D281e9786914D280A1F", + "ATLAS_VERIFICATION": "0x6Fa1a569a3CbF16B703962e5420aA4c755aD01BD", + "GAS_ACCOUNTING_LIB": "0x0761F5a339B8Cf4999F134E537CD521DF718fa4b", + "SAFETY_LOCKS_LIB": "0xad674dF2C4f6D4F37FDc9eb1fD7530a6293e150e", + "SIMULATOR": "0x56eF55097199944f103fC15104268756998438C4", + "SWAP_INTENT_DAPP_CONTROL": "0x0DE2256dF50bd8Bceefb353c1a5520bc0fEcdA97", + "TX_BUILDER": "0x2677053483dfDEd72bE63543D9B1E85Bcf20E839", + "SIMPLE_RFQ_SOLVER": "0x08A7776F199932F8287Fd85B05447Cc8225D1b4C" }, "MAINNET": { "ATLAS": "", diff --git a/package.json b/package.json index da4d06a6..66a4204d 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,8 @@ "deploy-solver-sepolia": "source .env && forge script script/deploy-solver.s.sol:DeploySimpleRFQSolverScript --rpc-url ${SEPOLIA_RPC_URL} --broadcast --etherscan-api-key ${ETHERSCAN_API_KEY} --verify", "deploy-solver-local": "source .env && forge script script/deploy-solver.s.sol:DeploySimpleRFQSolverScript --fork-url http://localhost:8545 --broadcast", + "deploy-all-sepolia": "npm run deploy-atlas-sepolia && npm run deploy-swap-intent-sepolia && npm run deploy-tx-builder-sepolia && npm run deploy-solver-sepolia", + "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", diff --git a/script/deploy-atlas.s.sol b/script/deploy-atlas.s.sol index 9f40b23f..6bacfb32 100644 --- a/script/deploy-atlas.s.sol +++ b/script/deploy-atlas.s.sol @@ -39,20 +39,23 @@ contract DeployAtlasScript is DeployBaseScript { address expectedSafetyLocksLibAddr = computeCreateAddress( deployer, vm.getNonce(deployer) + 4 + ); + address expectedSimulatorAddr = computeCreateAddress( + deployer, + vm.getNonce(deployer) + 5 ); 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) + _simulator: expectedSimulatorAddr }); atlasFactory = new AtlasFactory(address(atlas)); atlasVerification = new AtlasVerification(address(atlas)); @@ -61,7 +64,7 @@ contract DeployAtlasScript is DeployBaseScript { _factory: expectedAtlasFactoryAddr, _verification: expectedAtlasVerificationAddr, _safetyLocksLib: expectedSafetyLocksLibAddr, - _simulator: address(simulator), + _simulator: expectedSimulatorAddr, _atlas: address(atlas) }); safetyLocksLib = new SafetyLocksLib({ @@ -69,13 +72,17 @@ contract DeployAtlasScript is DeployBaseScript { _factory: expectedAtlasFactoryAddr, _verification: expectedAtlasVerificationAddr, _gasAccLib: expectedGasAccountingLibAddr, - _simulator: address(simulator), + _simulator: expectedSimulatorAddr, _atlas: address(atlas) }); + + simulator = new Simulator(); simulator.setAtlas(address(atlas)); vm.stopBroadcast(); + // TODO add address checks with alert logs if wrong + _writeAddressToDeploymentsJson("ATLAS", address(atlas)); _writeAddressToDeploymentsJson("ATLAS_FACTORY", address(atlasFactory)); _writeAddressToDeploymentsJson("ATLAS_VERIFICATION", address(atlasVerification)); From 1c4239a119515a8b04cbb7d5783c1492603ac246 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Fri, 10 Nov 2023 11:29:52 +0200 Subject: [PATCH 09/17] Add safety checks to Atlas deploy script addrs --- script/deploy-atlas.s.sol | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/script/deploy-atlas.s.sol b/script/deploy-atlas.s.sol index 6bacfb32..8c21c830 100644 --- a/script/deploy-atlas.s.sol +++ b/script/deploy-atlas.s.sol @@ -81,7 +81,21 @@ contract DeployAtlasScript is DeployBaseScript { vm.stopBroadcast(); - // TODO add address checks with alert logs if wrong + if(address(atlasFactory) != expectedAtlasFactoryAddr) { + console.log("ERROR: AtlasFactory address does not match expected address"); + } + if(address(atlasVerification) != expectedAtlasVerificationAddr) { + console.log("ERROR: AtlasVerification address does not match expected address"); + } + if(address(gasAccountingLib) != expectedGasAccountingLibAddr) { + console.log("ERROR: GasAccountingLib address does not match expected address"); + } + if(address(safetyLocksLib) != expectedSafetyLocksLibAddr) { + console.log("ERROR: SafetyLocksLib address does not match expected address"); + } + if(address(simulator) != expectedSimulatorAddr) { + console.log("ERROR: Simulator address does not match expected address"); + } _writeAddressToDeploymentsJson("ATLAS", address(atlas)); _writeAddressToDeploymentsJson("ATLAS_FACTORY", address(atlasFactory)); From 5493b887c0e4444585f8e78d1e60562b6620bccb Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Fri, 10 Nov 2023 11:49:45 +0200 Subject: [PATCH 10/17] Better safety checks in Atlas deploy script --- script/deploy-atlas.s.sol | 53 +++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/script/deploy-atlas.s.sol b/script/deploy-atlas.s.sol index 8c21c830..4b6af7d8 100644 --- a/script/deploy-atlas.s.sol +++ b/script/deploy-atlas.s.sol @@ -24,26 +24,11 @@ contract DeployAtlasScript is DeployBaseScript { 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 - ); - address expectedSimulatorAddr = computeCreateAddress( - deployer, - vm.getNonce(deployer) + 5 - ); + 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); + address expectedSimulatorAddr = computeCreateAddress(deployer, vm.getNonce(deployer) + 5); console.log("Deployer address: \t\t\t\t", deployer); @@ -81,20 +66,28 @@ contract DeployAtlasScript is DeployBaseScript { vm.stopBroadcast(); - if(address(atlasFactory) != expectedAtlasFactoryAddr) { - console.log("ERROR: AtlasFactory address does not match expected address"); + if ( + address(atlas) != simulator.atlas() || address(atlas) != atlasVerification.ATLAS() + || address(atlas) != gasAccountingLib.ATLAS() || address(atlas) != safetyLocksLib.ATLAS() + ) { + console.log( + "ERROR: Atlas address not set correctly in Simulator, AtlasVerification, GasAccountingLib, or SafetyLocksLib" + ); } - if(address(atlasVerification) != expectedAtlasVerificationAddr) { - console.log("ERROR: AtlasVerification address does not match expected address"); + if (address(atlasFactory) != atlas.FACTORY()) { + console.log("ERROR: AtlasFactory address not set correctly in Atlas"); } - if(address(gasAccountingLib) != expectedGasAccountingLibAddr) { - console.log("ERROR: GasAccountingLib address does not match expected address"); + if (address(atlasVerification) != atlas.VERIFICATION()) { + console.log("ERROR: AtlasVerification address not set correctly in Atlas"); } - if(address(safetyLocksLib) != expectedSafetyLocksLibAddr) { - console.log("ERROR: SafetyLocksLib address does not match expected address"); + if (address(gasAccountingLib) != atlas.GAS_ACC_LIB()) { + console.log("ERROR: GasAccountingLib address not set correctly in Atlas"); } - if(address(simulator) != expectedSimulatorAddr) { - console.log("ERROR: Simulator address does not match expected address"); + if (address(safetyLocksLib) != atlas.SAFETY_LOCKS_LIB()) { + console.log("ERROR: SafetyLocksLib address not set correctly in Atlas"); + } + if (address(simulator) != atlas.SIMULATOR()) { + console.log("ERROR: Simulator address not set correctly in Atlas"); } _writeAddressToDeploymentsJson("ATLAS", address(atlas)); From 0d2acbff3dfd450473ba7af3f77e7de5c417e29f Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Mon, 13 Nov 2023 19:25:02 +0200 Subject: [PATCH 11/17] Start on verifying exec env --- package.json | 4 ++-- script/deploy-exec-env.s.sol | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 script/deploy-exec-env.s.sol diff --git a/package.json b/package.json index 66a4204d..85008ba9 100644 --- a/package.json +++ b/package.json @@ -29,13 +29,13 @@ "deploy-all-sepolia": "npm run deploy-atlas-sepolia && npm run deploy-swap-intent-sepolia && npm run deploy-tx-builder-sepolia && npm run deploy-solver-sepolia", + "verify-exec-env": "", + "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", - "solver-deposit": "source .env && forge script script/solver-deposit.s.sol:SolverAtlasDepositScript --fork-url http://localhost:8545 --broadcast --non-interactive", - "setup-demo": "npm run deploy-atlas-swap-intent-tx-builder && npm run deploy-solver && npm run solver-deposit", "atlas-addr": "echo 'ATLAS:' && jq -r '.ATLAS' deployments.json", diff --git a/script/deploy-exec-env.s.sol b/script/deploy-exec-env.s.sol new file mode 100644 index 00000000..7d222825 --- /dev/null +++ b/script/deploy-exec-env.s.sol @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity 0.8.21; + +import "forge-std/Script.sol"; +import "forge-std/Test.sol"; + +import {DeployBaseScript} from "script/base/deploy-base.s.sol"; + +contract DeployExecEnvScript is DeployBaseScript { + function run() external { + console.log("\n=== DEPLOYING Execution Environment ===\n"); + + console.log("Deploying to chain: ", _getDeployChain()); + + uint256 deployerPrivateKey = vm.envUint("GOV_PRIVATE_KEY"); + address deployer = vm.addr(deployerPrivateKey); + console.log("Deployer address: \t\t\t\t", deployer); + + vm.startBroadcast(deployerPrivateKey); + + // TODO + + vm.stopBroadcast(); + + // _writeAddressToDeploymentsJson("EXECUTION_ENV", address(simulator)); // TODO + + console.log("\n"); + // console.log("Execution Environment deployed at: \t\t\t\t", address(atlas)); // TODO + console.log("\n"); + console.log("You can find a list of contract addresses from the latest deployment in deployments.json"); + } +} From 335e54886b89e1a2d469e9699f4074c03a18fb12 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Mon, 13 Nov 2023 19:43:42 +0200 Subject: [PATCH 12/17] Add Exec Env deploy and verify script --- package.json | 2 +- script/deploy-exec-env.s.sol | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 85008ba9..e87a4e0c 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "deploy-all-sepolia": "npm run deploy-atlas-sepolia && npm run deploy-swap-intent-sepolia && npm run deploy-tx-builder-sepolia && npm run deploy-solver-sepolia", - "verify-exec-env": "", + "deploy-exec-env-sepolia": "source .env && forge script script/deploy-exec-env.s.sol:DeployExecEnvScript --rpc-url ${SEPOLIA_RPC_URL} --broadcast --etherscan-api-key ${ETHERSCAN_API_KEY} --verify", "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", diff --git a/script/deploy-exec-env.s.sol b/script/deploy-exec-env.s.sol index 7d222825..aedcca79 100644 --- a/script/deploy-exec-env.s.sol +++ b/script/deploy-exec-env.s.sol @@ -6,7 +6,11 @@ import "forge-std/Test.sol"; import {DeployBaseScript} from "script/base/deploy-base.s.sol"; +import {ExecutionEnvironment} from "src/contracts/atlas/ExecutionEnvironment.sol"; + contract DeployExecEnvScript is DeployBaseScript { + ExecutionEnvironment public execEnv; + function run() external { console.log("\n=== DEPLOYING Execution Environment ===\n"); @@ -18,14 +22,13 @@ contract DeployExecEnvScript is DeployBaseScript { vm.startBroadcast(deployerPrivateKey); - // TODO + address atlasAddress = _getAddressFromDeploymentsJson("ATLAS"); + execEnv = new ExecutionEnvironment(atlasAddress); vm.stopBroadcast(); - // _writeAddressToDeploymentsJson("EXECUTION_ENV", address(simulator)); // TODO - console.log("\n"); - // console.log("Execution Environment deployed at: \t\t\t\t", address(atlas)); // TODO + console.log("Execution Environment deployed at: \t\t\t\t", address(execEnv)); console.log("\n"); console.log("You can find a list of contract addresses from the latest deployment in deployments.json"); } From 8a845e1480ab3d21db984901d60b5677bdb21625 Mon Sep 17 00:00:00 2001 From: jj1980a Date: Tue, 14 Nov 2023 07:54:10 +0800 Subject: [PATCH 13/17] initial commit --- script/deploy-solver.s.sol | 2 +- src/contracts/solver/SolverBase.sol | 32 ++++++++++++------------- src/contracts/solver/src/TestSolver.sol | 2 +- test/Accounting.t.sol | 8 +++---- test/SwapIntent.t.sol | 8 +++---- test/base/BaseTest.t.sol | 4 ++-- 6 files changed, 27 insertions(+), 29 deletions(-) diff --git a/script/deploy-solver.s.sol b/script/deploy-solver.s.sol index f8178e4e..41434458 100644 --- a/script/deploy-solver.s.sol +++ b/script/deploy-solver.s.sol @@ -21,7 +21,7 @@ contract DeploySimpleRFQSolverScript is DeployBaseScript { vm.startBroadcast(deployerPrivateKey); - rfqSolver = new SimpleRFQSolver(atlasAddress); + rfqSolver = new SimpleRFQSolver(vm.envAddress("WETH"), atlasAddress); vm.stopBroadcast(); diff --git a/src/contracts/solver/SolverBase.sol b/src/contracts/solver/SolverBase.sol index abb0410c..a734e7a8 100644 --- a/src/contracts/solver/SolverBase.sol +++ b/src/contracts/solver/SolverBase.sol @@ -16,24 +16,25 @@ interface IWETH9 { } contract SolverBase is Test { - address public constant WETH_ADDRESS = address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2); + address public immutable WETH_ADDRESS; // TODO consider making these accessible (internal) for solvers which may want to use them address private immutable _owner; address private immutable _escrow; - constructor(address atlasEscrow, address owner) { + constructor(address weth9, address atlasEscrow, address owner) { + WETH_ADDRESS = weth9; _owner = owner; _escrow = atlasEscrow; } - function atlasSolverCall(address sender, address bidToken, uint256 bidAmount, bytes calldata solverOpData, bytes calldata extraReturnData) - external - payable - safetyFirst(sender) - payBids(bidToken, bidAmount) - returns (bool success, bytes memory data) - { + function atlasSolverCall( + address sender, + address bidToken, + uint256 bidAmount, + bytes calldata solverOpData, + bytes calldata extraReturnData + ) external payable safetyFirst(sender) payBids(bidToken, bidAmount) returns (bool success, bytes memory data) { (success, data) = address(this).call{value: msg.value}(solverOpData); require(success, "CALL UNSUCCESSFUL"); @@ -43,7 +44,7 @@ contract SolverBase is Test { // Safety checks require(sender == _owner, "INVALID CALLER"); // uint256 msgValueOwed = msg.value; - + _; IEscrow(_escrow).reconcile{value: msg.value}(msg.sender, sender, type(uint256).max); @@ -51,10 +52,9 @@ contract SolverBase is Test { modifier payBids(address bidToken, uint256 bidAmount) { // Track starting balances - - uint256 bidBalance = bidToken == address(0) ? - address(this).balance - msg.value : - ERC20(bidToken).balanceOf(address(this)); + + uint256 bidBalance = + bidToken == address(0) ? address(this).balance - msg.value : ERC20(bidToken).balanceOf(address(this)); _; @@ -62,17 +62,15 @@ contract SolverBase is Test { // Ether balance if (bidToken == address(0)) { - uint256 ethOwed = bidAmount + msg.value; if (ethOwed > address(this).balance) { IWETH9(WETH_ADDRESS).withdraw(ethOwed - address(this).balance); - } SafeTransferLib.safeTransferETH(msg.sender, bidAmount); - // ERC20 balance + // ERC20 balance } else { if (msg.value > address(this).balance) { IWETH9(WETH_ADDRESS).withdraw(msg.value - address(this).balance); diff --git a/src/contracts/solver/src/TestSolver.sol b/src/contracts/solver/src/TestSolver.sol index d52f8d11..e578de7b 100644 --- a/src/contracts/solver/src/TestSolver.sol +++ b/src/contracts/solver/src/TestSolver.sol @@ -7,5 +7,5 @@ import {SolverBase} from "../SolverBase.sol"; import {BlindBackrun} from "./BlindBackrun/BlindBackrun.sol"; contract Solver is SolverBase, BlindBackrun { - constructor(address atlasEscrow, address owner) SolverBase(atlasEscrow, owner) {} + constructor(address weth9, address atlasEscrow, address owner) SolverBase(weth9, atlasEscrow, owner) {} } \ No newline at end of file diff --git a/test/Accounting.t.sol b/test/Accounting.t.sol index 9649b5ba..ff2d48eb 100644 --- a/test/Accounting.t.sol +++ b/test/Accounting.t.sol @@ -69,7 +69,7 @@ contract AccountingTest is BaseTest { // Solver deploys the RFQ solver contract (defined at bottom of this file) vm.startPrank(solverOneEOA); - HonestRFQSolver honestSolver = new HonestRFQSolver(address(atlas)); + HonestRFQSolver honestSolver = new HonestRFQSolver(WETH_ADDRESS, address(atlas)); vm.stopPrank(); SolverOperation[] memory solverOps = _setupBorrowRepayTestUsingBasicSwapIntent(address(honestSolver)); @@ -100,7 +100,7 @@ contract AccountingTest is BaseTest { // Solver deploys the RFQ solver contract (defined at bottom of this file) vm.startPrank(solverOneEOA); // TODO make evil solver - HonestRFQSolver evilSolver = new HonestRFQSolver(address(atlas)); + HonestRFQSolver evilSolver = new HonestRFQSolver(WETH_ADDRESS, address(atlas)); // atlas.deposit{value: gasCostCoverAmount}(solverOneEOA); vm.stopPrank(); @@ -237,7 +237,7 @@ contract AccountingTest is BaseTest { // This might involve an offchain RFQ system contract HonestRFQSolver is SolverBase { address public immutable ATLAS; - constructor(address atlas) SolverBase(atlas, msg.sender) { + constructor(address weth9, address atlas) SolverBase(weth9, atlas, msg.sender) { ATLAS = atlas; } @@ -264,7 +264,7 @@ contract HonestRFQSolver is SolverBase { contract EvilRFQSolver is HonestRFQSolver { address deployer; - constructor(address atlas) HonestRFQSolver(atlas) { + constructor(address weth9, address atlas) HonestRFQSolver(weth9, atlas) { deployer = msg.sender; } function fulfillRFQ( diff --git a/test/SwapIntent.t.sol b/test/SwapIntent.t.sol index b29193a3..6fc7bc33 100644 --- a/test/SwapIntent.t.sol +++ b/test/SwapIntent.t.sol @@ -108,7 +108,7 @@ contract SwapIntentTest is BaseTest { // Solver deploys the RFQ solver contract (defined at bottom of this file) vm.startPrank(solverOneEOA); - SimpleRFQSolver rfqSolver = new SimpleRFQSolver(address(atlas)); + SimpleRFQSolver rfqSolver = new SimpleRFQSolver(WETH_ADDRESS, address(atlas)); atlas.deposit{value: 1e18}(); vm.stopPrank(); @@ -234,7 +234,7 @@ contract SwapIntentTest is BaseTest { // Solver deploys the RFQ solver contract (defined at bottom of this file) vm.startPrank(solverOneEOA); - UniswapIntentSolver uniswapSolver = new UniswapIntentSolver(address(atlas)); + UniswapIntentSolver uniswapSolver = new UniswapIntentSolver(WETH_ADDRESS, address(atlas)); deal(WETH_ADDRESS, address(uniswapSolver), 1e18); // 1 WETH to solver to pay bid atlas.deposit{value: 1e18}(); vm.stopPrank(); @@ -349,7 +349,7 @@ contract SwapIntentTest is BaseTest { // This solver magically has the tokens needed to fulfil the user's swap. // This might involve an offchain RFQ system contract SimpleRFQSolver is SolverBase { - constructor(address atlas) SolverBase(atlas, msg.sender) {} + constructor(address weth9, address atlas) SolverBase(weth9, atlas, msg.sender) {} function fulfillRFQ( SwapIntent calldata swapIntent, @@ -374,7 +374,7 @@ contract SimpleRFQSolver is SolverBase { contract UniswapIntentSolver is SolverBase { IUniV2Router02 router = IUniV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D); - constructor(address atlas) SolverBase(atlas, msg.sender) {} + constructor(address weth9, address atlas) SolverBase(weth9, atlas, msg.sender) {} function fulfillWithSwap( SwapIntent calldata swapIntent, diff --git a/test/base/BaseTest.t.sol b/test/base/BaseTest.t.sol index f1b3ddbc..d0f1fbf4 100644 --- a/test/base/BaseTest.t.sol +++ b/test/base/BaseTest.t.sol @@ -139,7 +139,7 @@ contract BaseTest is Test, TestConstants { vm.startPrank(solverOneEOA); - solverOne = new Solver(escrow, solverOneEOA); + solverOne = new Solver(WETH_ADDRESS, escrow, solverOneEOA); atlas.deposit{value: 1e18}(); deal(TOKEN_ZERO, address(solverOne), 10e24); @@ -149,7 +149,7 @@ contract BaseTest is Test, TestConstants { vm.startPrank(solverTwoEOA); - solverTwo = new Solver(escrow, solverTwoEOA); + solverTwo = new Solver(WETH_ADDRESS, escrow, solverTwoEOA); atlas.deposit{value: 1e18}(); vm.stopPrank(); From 60847c39f061b168fe69c51f5b2f9b59784aa363 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Tue, 14 Nov 2023 20:55:24 +0200 Subject: [PATCH 14/17] Add Sepolia ChainVars for token addresses --- test/base/TestConstants.sol | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/test/base/TestConstants.sol b/test/base/TestConstants.sol index 13e479b8..2161bf04 100644 --- a/test/base/TestConstants.sol +++ b/test/base/TestConstants.sol @@ -8,15 +8,31 @@ import {IUniswapV2Pair} from "../../src/contracts/examples/v2-example/interfaces contract TestConstants { uint256 public constant BLOCK_START = 17441786; - // MAINNET - ChainVars public mainnet = ChainVars({rpcUrlKey: "MAINNET_RPC_URL", forkBlock: BLOCK_START}); - // Structs struct ChainVars { string rpcUrlKey; uint256 forkBlock; + address weth; + address dai; } + // MAINNET + ChainVars public mainnet = ChainVars({ + rpcUrlKey: "MAINNET_RPC_URL", + forkBlock: BLOCK_START, + weth: address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2), + dai: address(0x6B175474E89094C44Da98b954EedeAC495271d0F) + }); + + // SEPOLIA + ChainVars public sepolia = ChainVars({ + rpcUrlKey: "SEPOLIA_RPC_URL", + forkBlock: BLOCK_START, + weth: address(0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14), // Uniswap's Sepolia WETH + dai: address(0x4F96Fe3b7A6Cf9725f59d353F723c1bDb64CA6Aa) //TODO find Sepolia DAI addrs + }); + + // Constants address public constant FXS_ADDRESS = address(0x3432B6A60D23Ca0dFCa7761B7ab56459D9C964D0); address public constant WETH_ADDRESS = address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2); From 3dc63e3fef51489d2b79f64bbdb72368edb09875 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Wed, 15 Nov 2023 16:13:43 +0200 Subject: [PATCH 15/17] Change to JSON collection of common addresses --- test/base/TestConstants.sol | 8 -------- useful-addresses.json | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 8 deletions(-) create mode 100644 useful-addresses.json diff --git a/test/base/TestConstants.sol b/test/base/TestConstants.sol index 2161bf04..a7862725 100644 --- a/test/base/TestConstants.sol +++ b/test/base/TestConstants.sol @@ -23,14 +23,6 @@ contract TestConstants { weth: address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2), dai: address(0x6B175474E89094C44Da98b954EedeAC495271d0F) }); - - // SEPOLIA - ChainVars public sepolia = ChainVars({ - rpcUrlKey: "SEPOLIA_RPC_URL", - forkBlock: BLOCK_START, - weth: address(0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14), // Uniswap's Sepolia WETH - dai: address(0x4F96Fe3b7A6Cf9725f59d353F723c1bDb64CA6Aa) //TODO find Sepolia DAI addrs - }); // Constants diff --git a/useful-addresses.json b/useful-addresses.json new file mode 100644 index 00000000..ada949b3 --- /dev/null +++ b/useful-addresses.json @@ -0,0 +1,16 @@ +{ + "MAINNET": { + "WETH": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", + "DAI": "0x6B175474E89094C44Da98b954EedeAC495271d0F", + "USDC": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", + "UNI": "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984", + "UNISWAP_V2_ROUTER": "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D" + }, + "SEPOLIA": { + "WETH": "0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14", + "DAI": "", + "USDC": "", + "UNI": "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984", + "UNISWAP_V2_ROUTER": "0x8f1dD60dBDb493DD940a44985AB43FB9901dcd2e" + } +} \ No newline at end of file From 416f6b1c48f9f47d014b7fc3440a51aa05673223 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Wed, 15 Nov 2023 17:30:32 +0200 Subject: [PATCH 16/17] Add getUsefulContractAddress util function --- src/contracts/helpers/Utilities.sol | 23 +++++++++++++++++++++++ test/SwapIntent.t.sol | 17 ----------------- test/base/BaseTest.t.sol | 5 +++++ 3 files changed, 28 insertions(+), 17 deletions(-) create mode 100644 src/contracts/helpers/Utilities.sol diff --git a/src/contracts/helpers/Utilities.sol b/src/contracts/helpers/Utilities.sol new file mode 100644 index 00000000..ee76fa34 --- /dev/null +++ b/src/contracts/helpers/Utilities.sol @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.21; + +import "forge-std/Script.sol"; +import "forge-std/Test.sol"; +import "forge-std/StdJson.sol"; + +contract Utilities is Script{ + using stdJson for string; + + function getUsefulContractAddress(string memory chain, string memory key) public view returns (address) { + string memory root = vm.projectRoot(); + string memory path = string.concat(root, "/useful-addresses.json"); + string memory json = vm.readFile(path); + string memory fullKey = string.concat(".", chain, ".", key); + + address res = json.readAddress(fullKey); + if (res == address(0x0000000000000000000000000000000000000020)) { + revert(string.concat(fullKey, " not found in useful-addresses.json")); + } + return res; + } +} \ No newline at end of file diff --git a/test/SwapIntent.t.sol b/test/SwapIntent.t.sol index 6fc7bc33..4809b2a4 100644 --- a/test/SwapIntent.t.sol +++ b/test/SwapIntent.t.sol @@ -15,22 +15,6 @@ import {DAppOperation, DAppConfig} from "../src/contracts/types/DAppApprovalType import {SwapIntentController, SwapIntent, Condition} from "../src/contracts/examples/intents-example/SwapIntent.sol"; import {SolverBase} from "../src/contracts/solver/SolverBase.sol"; -// QUESTIONS: - -// Refactor Ideas: -// 1. Lots of bitwise operations explicitly coded in contracts - could be a helper lib thats more readable -// 2. helper is currently a V2Helper and shared from BaseTest. Should only be in Uni V2 related tests -// 3. Need a more generic helper for BaseTest -// 4. Gonna be lots of StackTooDeep errors. Maybe need a way to elegantly deal with that in BaseTest -// 5. Change atlasSolverCall structure in SolverBase - maybe virtual fn to be overridden, which hooks for checks -// 6. Maybe emit error msg or some other better UX for error if !valid in metacall() - -// Doc Ideas: -// 1. Step by step instructions for building a metacall transaction (for internal testing, and integrating dApps) - -// To Understand Better: -// 1. The lock system (and look for any gas optimizations / ways to reduce lock actions) - interface IUniV2Router02 { function swapExactTokensForTokens( @@ -83,7 +67,6 @@ contract SwapIntentTest is BaseTest { function testAtlasSwapIntentWithBasicRFQ() public { // Swap 10 WETH for 20 DAI - UserCondition userCondition = new UserCondition(); Condition[] memory conditions = new Condition[](2); diff --git a/test/base/BaseTest.t.sol b/test/base/BaseTest.t.sol index d0f1fbf4..0f5f8352 100644 --- a/test/base/BaseTest.t.sol +++ b/test/base/BaseTest.t.sol @@ -22,6 +22,8 @@ import {TestConstants} from "./TestConstants.sol"; import {V2Helper} from "../V2Helper.sol"; +import {Utilities} from "src/contracts/helpers/Utilities.sol"; + contract BaseTest is Test, TestConstants { address public me = address(this); @@ -57,6 +59,8 @@ contract BaseTest is Test, TestConstants { V2Helper public helper; + Utilities public u; + // Fork stuff ChainVars public chain = mainnet; uint256 public forkNetwork; @@ -158,6 +162,7 @@ contract BaseTest is Test, TestConstants { deal(TOKEN_ONE, address(solverTwo), 10e24); helper = new V2Helper(address(control), address(atlas), address(atlasVerification)); + u = new Utilities(); deal(TOKEN_ZERO, address(atlas), 1); deal(TOKEN_ONE, address(atlas), 1); From eb9f930d8809866a05bc66b0404f498b8f075ebc Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Wed, 15 Nov 2023 17:37:24 +0200 Subject: [PATCH 17/17] Integrate contract address util fn with solver deploy script --- script/base/deploy-base.s.sol | 4 ++++ script/deploy-solver.s.sol | 6 +++++- src/contracts/solver/SolverBase.sol | 4 ++-- test/SwapIntent.t.sol | 4 ++-- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/script/base/deploy-base.s.sol b/script/base/deploy-base.s.sol index da06d316..23c2019a 100644 --- a/script/base/deploy-base.s.sol +++ b/script/base/deploy-base.s.sol @@ -17,6 +17,8 @@ import {TxBuilder} from "src/contracts/helpers/TxBuilder.sol"; import {Simulator} from "src/contracts/helpers/Simulator.sol"; import {SimpleRFQSolver} from "test/SwapIntent.t.sol"; +import {Utilities} from "src/contracts/helpers/Utilities.sol"; + contract DeployBaseScript is Script { using stdJson for string; @@ -33,6 +35,8 @@ contract DeployBaseScript is Script { TxBuilder public txBuilder; SimpleRFQSolver public rfqSolver; + Utilities public u; + function _getDeployChain() internal view returns (string memory) { // OPTIONS: LOCAL, SEPOLIA, MAINNET string memory deployChain = vm.envString("DEPLOY_TO"); diff --git a/script/deploy-solver.s.sol b/script/deploy-solver.s.sol index 41434458..86950dda 100644 --- a/script/deploy-solver.s.sol +++ b/script/deploy-solver.s.sol @@ -15,13 +15,17 @@ contract DeploySimpleRFQSolverScript is DeployBaseScript { uint256 deployerPrivateKey = vm.envUint("SOLVER1_PRIVATE_KEY"); address deployer = vm.addr(deployerPrivateKey); address atlasAddress = _getAddressFromDeploymentsJson("ATLAS"); + address wethAddress = u.getUsefulContractAddress(vm.envString("DEPLOY_TO"), "WETH"); console.log("Deployer address: \t\t\t\t", deployer); console.log("Using Atlas address: \t\t\t\t", atlasAddress); vm.startBroadcast(deployerPrivateKey); - rfqSolver = new SimpleRFQSolver(vm.envAddress("WETH"), atlasAddress); + rfqSolver = new SimpleRFQSolver({ + weth: wethAddress, + atlas: atlasAddress + }); vm.stopBroadcast(); diff --git a/src/contracts/solver/SolverBase.sol b/src/contracts/solver/SolverBase.sol index a734e7a8..41b92b61 100644 --- a/src/contracts/solver/SolverBase.sol +++ b/src/contracts/solver/SolverBase.sol @@ -22,8 +22,8 @@ contract SolverBase is Test { address private immutable _owner; address private immutable _escrow; - constructor(address weth9, address atlasEscrow, address owner) { - WETH_ADDRESS = weth9; + constructor(address weth, address atlasEscrow, address owner) { + WETH_ADDRESS = weth; _owner = owner; _escrow = atlasEscrow; } diff --git a/test/SwapIntent.t.sol b/test/SwapIntent.t.sol index 4809b2a4..9d7bb43b 100644 --- a/test/SwapIntent.t.sol +++ b/test/SwapIntent.t.sol @@ -332,7 +332,7 @@ contract SwapIntentTest is BaseTest { // This solver magically has the tokens needed to fulfil the user's swap. // This might involve an offchain RFQ system contract SimpleRFQSolver is SolverBase { - constructor(address weth9, address atlas) SolverBase(weth9, atlas, msg.sender) {} + constructor(address weth, address atlas) SolverBase(weth, atlas, msg.sender) {} function fulfillRFQ( SwapIntent calldata swapIntent, @@ -357,7 +357,7 @@ contract SimpleRFQSolver is SolverBase { contract UniswapIntentSolver is SolverBase { IUniV2Router02 router = IUniV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D); - constructor(address weth9, address atlas) SolverBase(weth9, atlas, msg.sender) {} + constructor(address weth, address atlas) SolverBase(weth, atlas, msg.sender) {} function fulfillWithSwap( SwapIntent calldata swapIntent,