Skip to content

Commit

Permalink
Merge pull request #45 from FastLane-Labs/deploy-script
Browse files Browse the repository at this point in the history
Sepolia Deploy Script
  • Loading branch information
BenSparksCode authored Nov 17, 2023
2 parents 7ee1f14 + 9a4fe95 commit 5450a51
Show file tree
Hide file tree
Showing 18 changed files with 385 additions and 277 deletions.
14 changes: 11 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
38 changes: 33 additions & 5 deletions deployments.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,35 @@
{
"ATLAS": "0x38c76A767d45Fc390160449948aF80569E2C4217",
"SIMULATOR": "0x721d8077771Ebf9B931733986d619aceea412a1C",
"SWAP_INTENT_DAPP_CONTROL": "0xDC57724Ea354ec925BaFfCA0cCf8A1248a8E5CF1",
"TX_BUILDER": "0xa8d297D643a11cE83b432e87eEBce6bee0fd2bAb",
"SIMPLE_RFQ_SOLVER": "0xEb63D671653489B91E653c52a018B63D5095223B"
"LOCAL": {
"ATLAS": "0x4653251486a57f90Ee89F9f34E098b9218659b83",
"ATLAS_FACTORY": "0x89ec9355b1Bcc964e576211c8B011BD709083f8d",
"ATLAS_VERIFICATION": "0x72662E4da74278430123cE51405c1e7A1B87C294",
"GAS_ACCOUNTING_LIB": "0x52bad4A8584909895C22bdEcf8DBF33314468Fb0",
"SAFETY_LOCKS_LIB": "0xed12bE400A07910E4d4E743E4ceE26ab1FC9a961",
"SIMULATOR": "0x20Dc424c5fa468CbB1c702308F0cC9c14DA2825C",
"SWAP_INTENT_DAPP_CONTROL": "0x1B25157F05B25438441bF7CDe38A95A55ccf8E50",
"TX_BUILDER": "",
"SIMPLE_RFQ_SOLVER": "0xEb63D671653489B91E653c52a018B63D5095223B"
},
"SEPOLIA": {
"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": "",
"ATLAS_FACTORY": "",
"ATLAS_VERIFICATION": "",
"GAS_ACCOUNTING_LIB": "",
"SAFETY_LOCKS_LIB": "",
"SIMULATOR": "",
"SWAP_INTENT_DAPP_CONTROL": "",
"TX_BUILDER": "",
"SIMPLE_RFQ_SOLVER": ""
}
}
20 changes: 17 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,27 @@
"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-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 --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-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-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",
"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",
Expand Down
57 changes: 52 additions & 5 deletions script/base/deploy-base.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,78 @@ import "forge-std/StdJson.sol";

import {ERC20} from "solmate/tokens/ERC20.sol";

// NOTE: When handling JSON with StdJson, prefix keys with '.' e.g. '.ATLAS'
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";

import {Utilities} from "src/contracts/helpers/Utilities.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;

Utilities public u;

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");
}
}

// 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 {
Expand Down
Loading

0 comments on commit 5450a51

Please sign in to comment.