From dfbe23a1e2643c3960b6c29100a0309a89863ea0 Mon Sep 17 00:00:00 2001 From: Piotr Ostrowski Date: Sat, 7 Sep 2024 23:37:26 +0200 Subject: [PATCH] final deploy script --- packages/foundry/script/Deploy.s.sol | 55 +++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/packages/foundry/script/Deploy.s.sol b/packages/foundry/script/Deploy.s.sol index c532eb9..f466104 100644 --- a/packages/foundry/script/Deploy.s.sol +++ b/packages/foundry/script/Deploy.s.sol @@ -4,14 +4,59 @@ pragma solidity ^0.8.19; import "../contracts/FairDrop.sol"; import "./DeployHelpers.s.sol"; import { DeployFairDrop } from "./00_deploy_fair_drop.s.sol"; +import { DeployFairDropSatellite } from "./01_deploy_satellite.s.sol"; contract DeployScript is ScaffoldETHDeploy { function run() external { - // DeployFairDrop deployFairDrop = new DeployFairDrop(); - // deployFairDrop.run(); + if (block.chainid == 10) { + // Deploy on Optimism + DeployFairDrop deployFairDrop = new DeployFairDrop(); + deployFairDrop.run(); + console.logString("FairDrop deployed on Optimism"); + } else if (block.chainid == 42161) { + // Deploy on Arbitrum + DeployFairDropSatellite deployFairDropSatellite = + new DeployFairDropSatellite(); + deployFairDropSatellite.run(); + console.logString("FairDropSatellite deployed on Arbitrum"); - // deploy more contracts here - // DeployMyContract deployMyContract = new DeployMyContract(); - // deployMyContract.run(); + // Set cross-chain information + address fairDropAddress = getDeploymentAddress("FairDrop"); + address fairDropSatelliteAddress = + getDeploymentAddress("FairDropSatellite"); + + if ( + fairDropAddress != address(0) && fairDropSatelliteAddress != address(0) + ) { + FairDrop fairDrop = FairDrop(fairDropAddress); + FairDropSatellite fairDropSatellite = + FairDropSatellite(fairDropSatelliteAddress); + + fairDrop.setReceiver(42161, fairDropSatelliteAddress); + fairDropSatellite.setVerifier(10, fairDropAddress); + + console.logString("Cross-chain information set successfully"); + } else { + console.logString( + "Unable to set cross-chain information. Make sure both contracts are deployed." + ); + } + } else { + revert("Unsupported chain ID"); + } + } + + function getDeploymentAddress( + string memory name + ) internal view returns (address) { + for (uint256 i = 0; i < deployments.length; i++) { + if ( + keccak256(abi.encodePacked(deployments[i].name)) + == keccak256(abi.encodePacked(name)) + ) { + return deployments[i].addr; + } + } + return address(0); } }