Skip to content

Commit

Permalink
Add DEPLOY_TO var for chain selection in .env and scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
BenSparksCode committed Nov 9, 2023
1 parent dfc2758 commit 8003644
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 61 deletions.
7 changes: 7 additions & 0 deletions deployments2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"ATLAS": "0x38c76A767d45Fc390160449948aF80569E2C4217",
"SIMULATOR": "0x721d8077771Ebf9B931733986d619aceea412a1C",
"SWAP_INTENT_DAPP_CONTROL": "0xDC57724Ea354ec925BaFfCA0cCf8A1248a8E5CF1",
"TX_BUILDER": "0xa8d297D643a11cE83b432e87eEBce6bee0fd2bAb",
"SIMPLE_RFQ_SOLVER": "0xEb63D671653489B91E653c52a018B63D5095223B"
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 14 additions & 0 deletions script/base/deploy-base.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
122 changes: 62 additions & 60 deletions script/deploy-atlas.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down

0 comments on commit 8003644

Please sign in to comment.