From 496950341f09de63bb1da7d2e03330de6d876c7b Mon Sep 17 00:00:00 2001 From: Alexander Fadeev Date: Wed, 18 Dec 2024 04:08:00 +0200 Subject: [PATCH 1/4] Add transfer surcharge recipient script: `npm run transfer-surcharge-recipient:sepolia`. --- package.json | 7 +++-- script/transfer-surcharge-recipient.s.sol | 36 +++++++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 script/transfer-surcharge-recipient.s.sol diff --git a/package.json b/package.json index b6d888889..3fdc258fe 100644 --- a/package.json +++ b/package.json @@ -20,10 +20,10 @@ "deploy-fl-online-amoy": "source .env && forge script script/deploy-fl-online-control.s.sol:DeployFLOnlineControlScript --rpc-url ${AMOY_RPC_URL} --broadcast --etherscan-api-key ${POLYGONSCAN_API_KEY} --verify", "deploy-fl-online-polygon": "source .env && forge script script/deploy-fl-online-control.s.sol:DeployFLOnlineControlScript --rpc-url ${POLYGON_RPC_URL} --broadcast --etherscan-api-key ${POLYGONSCAN_API_KEY} --verify", - + "deploy-atlas-bsc": "source .env && forge script script/deploy-atlas.s.sol:DeployAtlasScript --rpc-url ${BSC_RPC_URL} --legacy --broadcast --etherscan-api-key ${BSCSCAN_API_KEY} --verify --delay 30", "deploy-atlas-bsc-testnet": "source .env && forge script script/deploy-atlas.s.sol:DeployAtlasScript --rpc-url ${BSC_TESTNET_RPC_URL} --legacy --broadcast --etherscan-api-key ${BSCSCAN_API_KEY} --verify --delay 30", - + "deploy-atlas-sepolia": "source .env && forge script script/deploy-atlas.s.sol:DeployAtlasScript --rpc-url ${SEPOLIA_RPC_URL} --legacy --gas-estimate-multiplier 150 --broadcast --etherscan-api-key ${ETHERSCAN_API_KEY} --verify --delay 30", "deploy-atlas-local": "source .env && forge script script/deploy-atlas.s.sol:DeployAtlasScript --fork-url http://localhost:8545 --broadcast", @@ -60,6 +60,8 @@ "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", + "transfer-surcharge-recipient:sepolia": ". ./.env && forge script script/transfer-surcharge-recipient.s.sol:TransferSurchargeRecipientScript --rpc-url ${SEPOLIA_RPC_URL} --sig 'run(string)' --broadcast --non-interactive", + "atlas-addr": "echo 'ATLAS:' && jq -r '.ATLAS' deployments.json", "swap-intent-addr": "echo 'SWAP INTENT DAPP CONTROL:' && jq -r '.SWAP_INTENT_DAPP_CONTROL' deployments.json", "tx-builder-addr": "echo 'TX BUILDER:' && jq -r '.TX_BUILDER' deployments.json", @@ -78,4 +80,3 @@ "solc": "solc-select install 0.8.18 && solc-select use 0.8.18" } } - \ No newline at end of file diff --git a/script/transfer-surcharge-recipient.s.sol b/script/transfer-surcharge-recipient.s.sol new file mode 100644 index 000000000..e78834f80 --- /dev/null +++ b/script/transfer-surcharge-recipient.s.sol @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity 0.8.25; + +import "forge-std/Script.sol"; + +import { DeployBaseScript } from "script/base/deploy-base.s.sol"; + +import { Atlas } from "src/contracts/atlas/Atlas.sol"; + +contract TransferSurchargeRecipientScript is DeployBaseScript { + function run(string calldata _newRecipient) external { + console.log("\n=== Transferring Atlas Surcharge Recipient ===\n"); + + // string hex to address + address newRecipient = vm.parseAddress(_newRecipient); + + // Get the deployer's private key from environment + uint256 deployerPrivateKey = vm.envUint("GOV_PRIVATE_KEY"); + address deployer = vm.addr(deployerPrivateKey); + + // Get Atlas contract address from deployments + address atlasAddress = _getAddressFromDeploymentsJson(".ATLAS"); + Atlas atlas = Atlas(payable(atlasAddress)); + + console.log("Deployer address: \t\t\t", deployer); + console.log("Atlas address: \t\t\t\t", atlasAddress); + console.log("New surcharge recipient: \t\t\t", newRecipient); + + // Transfer the surcharge recipient role to the new address + vm.startBroadcast(deployerPrivateKey); + atlas.transferSurchargeRecipient(newRecipient); + vm.stopBroadcast(); + + console.log("\nSurcharge recipient successfully transferred to:", newRecipient); + } +} \ No newline at end of file From 6f9841a8dbd1710b73ab96ffe965d8c57cc1d571 Mon Sep 17 00:00:00 2001 From: Alexander Fadeev Date: Wed, 18 Dec 2024 04:21:48 +0200 Subject: [PATCH 2/4] Fix linter + comments --- script/transfer-surcharge-recipient.s.sol | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/script/transfer-surcharge-recipient.s.sol b/script/transfer-surcharge-recipient.s.sol index e78834f80..d64782b01 100644 --- a/script/transfer-surcharge-recipient.s.sol +++ b/script/transfer-surcharge-recipient.s.sol @@ -7,18 +7,19 @@ import { DeployBaseScript } from "script/base/deploy-base.s.sol"; import { Atlas } from "src/contracts/atlas/Atlas.sol"; +/// @dev npm run transfer-surcharge-recipient:sepolia --
contract TransferSurchargeRecipientScript is DeployBaseScript { function run(string calldata _newRecipient) external { console.log("\n=== Transferring Atlas Surcharge Recipient ===\n"); - // string hex to address + // Hex string to address. address newRecipient = vm.parseAddress(_newRecipient); - // Get the deployer's private key from environment + // Get the deployer's private key from environment. uint256 deployerPrivateKey = vm.envUint("GOV_PRIVATE_KEY"); address deployer = vm.addr(deployerPrivateKey); - // Get Atlas contract address from deployments + // Get Atlas contract address from deployments. address atlasAddress = _getAddressFromDeploymentsJson(".ATLAS"); Atlas atlas = Atlas(payable(atlasAddress)); @@ -26,11 +27,11 @@ contract TransferSurchargeRecipientScript is DeployBaseScript { console.log("Atlas address: \t\t\t\t", atlasAddress); console.log("New surcharge recipient: \t\t\t", newRecipient); - // Transfer the surcharge recipient role to the new address + // Transfer the surcharge recipient role to the new address. vm.startBroadcast(deployerPrivateKey); atlas.transferSurchargeRecipient(newRecipient); vm.stopBroadcast(); console.log("\nSurcharge recipient successfully transferred to:", newRecipient); } -} \ No newline at end of file +} From b2bd7bb252af1638e5ecf08be9f694105b54aa9c Mon Sep 17 00:00:00 2001 From: Alexander Fadeev Date: Fri, 27 Dec 2024 23:52:26 +0200 Subject: [PATCH 3/4] Clarify transfer process in the `transfer-surcharge-resipient.s.sol` --- script/transfer-surcharge-recipient.s.sol | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/script/transfer-surcharge-recipient.s.sol b/script/transfer-surcharge-recipient.s.sol index d64782b01..065289f2f 100644 --- a/script/transfer-surcharge-recipient.s.sol +++ b/script/transfer-surcharge-recipient.s.sol @@ -32,6 +32,7 @@ contract TransferSurchargeRecipientScript is DeployBaseScript { atlas.transferSurchargeRecipient(newRecipient); vm.stopBroadcast(); - console.log("\nSurcharge recipient successfully transferred to:", newRecipient); + console.log("\nSurcharge recipient transfer initiated to:", newRecipient); + console.log("Recipient has to call `becomeSurchargeRecipient()` to become the new surcharge recipient."); } } From c3818b4772a506c2f144e6ab3063aff680043749 Mon Sep 17 00:00:00 2001 From: Alexander Fadeev Date: Wed, 1 Jan 2025 18:47:36 +0200 Subject: [PATCH 4/4] Support both address and private key inputs. Update npm command to include --slow flag for sepolia transfer. --- package.json | 2 +- script/transfer-surcharge-recipient.s.sol | 38 +++++++++++++++++------ 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 3fdc258fe..40773c873 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "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", - "transfer-surcharge-recipient:sepolia": ". ./.env && forge script script/transfer-surcharge-recipient.s.sol:TransferSurchargeRecipientScript --rpc-url ${SEPOLIA_RPC_URL} --sig 'run(string)' --broadcast --non-interactive", + "transfer-surcharge-recipient:sepolia": ". ./.env && forge script script/transfer-surcharge-recipient.s.sol:TransferSurchargeRecipientScript --rpc-url ${SEPOLIA_RPC_URL} --sig 'run(string)' --broadcast --non-interactive --slow", "atlas-addr": "echo 'ATLAS:' && jq -r '.ATLAS' deployments.json", "swap-intent-addr": "echo 'SWAP INTENT DAPP CONTROL:' && jq -r '.SWAP_INTENT_DAPP_CONTROL' deployments.json", diff --git a/script/transfer-surcharge-recipient.s.sol b/script/transfer-surcharge-recipient.s.sol index 065289f2f..fd9dbd287 100644 --- a/script/transfer-surcharge-recipient.s.sol +++ b/script/transfer-surcharge-recipient.s.sol @@ -7,13 +7,30 @@ import { DeployBaseScript } from "script/base/deploy-base.s.sol"; import { Atlas } from "src/contracts/atlas/Atlas.sol"; -/// @dev npm run transfer-surcharge-recipient:sepolia --
+/// @dev npm run transfer-surcharge-recipient:sepolia -- +/// @dev If input is a 20-byte address, only transfers the recipient role +/// @dev If input is a 32-byte private key, transfers and accepts the role contract TransferSurchargeRecipientScript is DeployBaseScript { - function run(string calldata _newRecipient) external { + function run(string calldata _new_recipient) external { console.log("\n=== Transferring Atlas Surcharge Recipient ===\n"); - // Hex string to address. - address newRecipient = vm.parseAddress(_newRecipient); + // Determine if input is an address or a private key ('0x' + 40 or 64 chars). + bool isAddress = bytes(_new_recipient).length == 42; + bool isPrivateKey = bytes(_new_recipient).length == 66; + + address newRecipient; + uint256 recipientPrivateKey; + + if (isAddress) { + newRecipient = vm.parseAddress(_new_recipient); + console.log("Input type: \t\t\t\t Address (will only transfer recipient role)"); + } else if (isPrivateKey) { + recipientPrivateKey = vm.parseUint(_new_recipient); + newRecipient = vm.addr(recipientPrivateKey); + console.log("Input type: \t\t\t\t Private key (will transfer and accept recipient role)"); + } else { + revert("Input must be a 20-byte address or 32-byte private key"); + } // Get the deployer's private key from environment. uint256 deployerPrivateKey = vm.envUint("GOV_PRIVATE_KEY"); @@ -24,15 +41,16 @@ contract TransferSurchargeRecipientScript is DeployBaseScript { Atlas atlas = Atlas(payable(atlasAddress)); console.log("Deployer address: \t\t\t", deployer); - console.log("Atlas address: \t\t\t\t", atlasAddress); - console.log("New surcharge recipient: \t\t\t", newRecipient); + console.log("Atlas address: \t\t\t", atlasAddress); + console.log("New surcharge recipient: \t\t", newRecipient); // Transfer the surcharge recipient role to the new address. - vm.startBroadcast(deployerPrivateKey); + vm.broadcast(deployerPrivateKey); atlas.transferSurchargeRecipient(newRecipient); - vm.stopBroadcast(); - console.log("\nSurcharge recipient transfer initiated to:", newRecipient); - console.log("Recipient has to call `becomeSurchargeRecipient()` to become the new surcharge recipient."); + if (isPrivateKey) { + vm.broadcast(recipientPrivateKey); + atlas.becomeSurchargeRecipient(); + } } }