From 77d40da24c6d1df7b97032912ff96249ae35ad06 Mon Sep 17 00:00:00 2001 From: Akash Date: Wed, 4 Oct 2023 17:46:26 +0530 Subject: [PATCH 1/5] feat:added checkBalance, switchboardData script --- scripts/deploy/checkRoles.ts | 1 + scripts/deploy/config.ts | 18 ++-- scripts/deploy/scripts/checkBalance.ts | 45 ++++++++++ scripts/deploy/scripts/switchboardData.ts | 100 ++++++++++++++++++++++ scripts/deploy/utils/utils.ts | 6 ++ 5 files changed, 161 insertions(+), 9 deletions(-) create mode 100644 scripts/deploy/scripts/checkBalance.ts create mode 100644 scripts/deploy/scripts/switchboardData.ts diff --git a/scripts/deploy/checkRoles.ts b/scripts/deploy/checkRoles.ts index 575c4f0a..f8d09ef2 100644 --- a/scripts/deploy/checkRoles.ts +++ b/scripts/deploy/checkRoles.ts @@ -652,6 +652,7 @@ const main = async () => { contractName: CORE_CONTRACTS.FastSwitchboard2, filterChains, + filterSiblingChains, sendTransaction, newRoleStatus, }); diff --git a/scripts/deploy/config.ts b/scripts/deploy/config.ts index 7693d91b..02e9328e 100644 --- a/scripts/deploy/config.ts +++ b/scripts/deploy/config.ts @@ -32,17 +32,17 @@ export const chains: Array = [ ChainSlug.ARBITRUM_GOERLI, ChainSlug.OPTIMISM_GOERLI, ChainSlug.POLYGON_MUMBAI, - // ChainSlug.BSC_TESTNET, + ChainSlug.BSC_TESTNET, ChainSlug.AEVO_TESTNET, ChainSlug.LYRA_TESTNET, - // ChainSlug.SEPOLIA, - // ChainSlug.AEVO, - // ChainSlug.MAINNET, - // ChainSlug.ARBITRUM, - // ChainSlug.OPTIMISM, - // ChainSlug.LYRA, - // ChainSlug.BSC, - // ChainSlug.POLYGON_MAINNET, + ChainSlug.SEPOLIA, + ChainSlug.AEVO, + ChainSlug.MAINNET, + ChainSlug.ARBITRUM, + ChainSlug.OPTIMISM, + ChainSlug.LYRA, + ChainSlug.BSC, + ChainSlug.POLYGON_MAINNET, ]; export const executionManagerVersion = CORE_CONTRACTS.ExecutionManager; diff --git a/scripts/deploy/scripts/checkBalance.ts b/scripts/deploy/scripts/checkBalance.ts new file mode 100644 index 00000000..c7693f44 --- /dev/null +++ b/scripts/deploy/scripts/checkBalance.ts @@ -0,0 +1,45 @@ +import { config as dotenvConfig } from "dotenv"; +import axios from "axios"; + +dotenvConfig(); +import { + ChainSlugToKey, +} from "../../../src"; +import { utils } from "ethers"; + +import { chains, mode } from "../config"; +import { getProviderFromChainName } from "../../constants/networks"; + +// check balance of owner address on all chains +export const checkBalance = async () => { + try { + // parallelize chains + await Promise.all( + chains.map(async (chainSlug) => { + + const provider = await getProviderFromChainName( + ChainSlugToKey[chainSlug] + ); + // let ownerAddress = process.env.SOCKET_OWNER_ADDRESS; + let ownerAddress = "0x752B38FA38F53dF7fa60e6113CFd9094b7e040Aa"; + if (!ownerAddress) throw Error("owner address not present"); + console.log(chainSlug, " ", ChainSlugToKey[chainSlug], " : ", utils.formatEther( await provider.getBalance(ownerAddress))); + + + }) + ); + } catch (error) { + console.log("Error while checking balance", error); + } +}; + +const main = async () => { + await checkBalance(); +}; + +main() + .then(() => process.exit(0)) + .catch((error: Error) => { + console.error(error); + process.exit(1); + }); diff --git a/scripts/deploy/scripts/switchboardData.ts b/scripts/deploy/scripts/switchboardData.ts new file mode 100644 index 00000000..fb46532b --- /dev/null +++ b/scripts/deploy/scripts/switchboardData.ts @@ -0,0 +1,100 @@ +import { + CapacitorType, + ChainSlug, + DeploymentAddresses, + IntegrationTypes, + getAllAddresses, +} from "../../../src"; +import { + toLowerCase, +} from "../utils"; + +import { mode } from "../config"; +import path from "path"; +import fs from "fs"; + +type Switchboard = { + switchboardId: string; + srcChainSlug: number; + dstChainSlug: number; + maxPacketLength: number; + integrationType: IntegrationTypes; + srcSwitchboard?: string; + dstSwitchboard?: string; + srcCapacitor?: string; + srcDecapacitor?: string; + capacitorType: CapacitorType; + isNativeSwitchboard: boolean; + isEnabled: boolean; +}; + +export const getSwitchboardData = async () => { + let addresses: DeploymentAddresses; + try { + addresses = getAllAddresses(mode); + } catch (error) { + console.log("couldn't fetch addresses: ", error); + process.exit(0); + } + + let switchboards: Switchboard[] = []; + + for (let chainSlug in addresses) { + + let chainAddresses = addresses[Number(chainSlug) as ChainSlug]; + if (!chainAddresses) { + console.log("chain addresses not found chainSlug: ", chainSlug); + return; + } + let integrations = chainAddresses["integrations"]; + if (!integrations) { + console.log("integrations not found chainSlug: ", chainSlug); + return; + } + + for (let siblingChainSlug in integrations) { + let siblingIntegrations = + integrations[Number(siblingChainSlug) as ChainSlug]; + if (!siblingIntegrations) { + console.log("sibling integrations not found chainSlug: ", chainSlug, siblingChainSlug); + return; + } + + let integrationTypes = Object.keys(siblingIntegrations); + for (let integrationType of integrationTypes) { + + let switchboardAddresses = + siblingIntegrations[integrationType as IntegrationTypes]; + + let switchboard: Switchboard = { + switchboardId: `${chainSlug}-${siblingChainSlug}-${toLowerCase( + switchboardAddresses?.switchboard + )}`, + srcChainSlug: Number(chainSlug) as ChainSlug, + dstChainSlug: Number(siblingChainSlug) as ChainSlug, + maxPacketLength: 1, + integrationType: integrationType as IntegrationTypes, + srcCapacitor: toLowerCase(switchboardAddresses?.capacitor), + srcDecapacitor: toLowerCase(switchboardAddresses?.decapacitor), + srcSwitchboard: toLowerCase(switchboardAddresses?.switchboard), + capacitorType: CapacitorType.singleCapacitor, + isEnabled: true, + dstSwitchboard: toLowerCase( + addresses[siblingChainSlug].integrations[chainSlug][ + integrationType as IntegrationTypes + ].switchboard + ), + isNativeSwitchboard:integrationType === IntegrationTypes.native + }; + switchboards.push(switchboard); + } + } + } + switchboards.forEach((s) => + console.log(s.switchboardId, s.dstSwitchboard, s.integrationType, s.isNativeSwitchboard) + ); + console.log("total switchboards: ", switchboards.length); + fs.writeFileSync("./switchboards.json", JSON.stringify(switchboards, null, 2)); +}; + +getSwitchboardData(); diff --git a/scripts/deploy/utils/utils.ts b/scripts/deploy/utils/utils.ts index 01ab5d98..689d5064 100644 --- a/scripts/deploy/utils/utils.ts +++ b/scripts/deploy/utils/utils.ts @@ -278,3 +278,9 @@ export const createObj = function ( } return obj; }; + + +export const toLowerCase = (str?: string) => { + if (!str) return ""; + return str.toLowerCase(); +} From 5aa6171aef00f91b23af14da200d3f1ea6c3c9d0 Mon Sep 17 00:00:00 2001 From: Akash Date: Wed, 4 Oct 2023 17:47:25 +0530 Subject: [PATCH 2/5] feat:updated attestBatch in socketBatcher --- contracts/socket/SocketBatcher.sol | 21 ++++++--------------- test/socket/SocketBatcher.t.sol | 2 +- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/contracts/socket/SocketBatcher.sol b/contracts/socket/SocketBatcher.sol index eca2ec8e..76b9a5f1 100644 --- a/contracts/socket/SocketBatcher.sol +++ b/contracts/socket/SocketBatcher.sol @@ -72,6 +72,7 @@ contract SocketBatcher is AccessControl { * @param signature The signature of the packet data. */ struct AttestRequest { + address switchboard; bytes32 packetId; uint256 proposalCount; bytes32 root; @@ -325,16 +326,12 @@ contract SocketBatcher is AccessControl { /** * @notice attests a batch of Packets - * @param switchboardAddress_ address of switchboard * @param attestRequests_ the list of requests with packets to be attested by switchboard in sequence */ - function _attestBatch( - address switchboardAddress_, - AttestRequest[] calldata attestRequests_ - ) internal { + function _attestBatch(AttestRequest[] calldata attestRequests_) internal { uint256 attestRequestLength = attestRequests_.length; for (uint256 index = 0; index < attestRequestLength; ) { - FastSwitchboard(switchboardAddress_).attest( + FastSwitchboard(attestRequests_[index].switchboard).attest( attestRequests_[index].packetId, attestRequests_[index].proposalCount, attestRequests_[index].root, @@ -348,27 +345,21 @@ contract SocketBatcher is AccessControl { /** * @notice attests a batch of Packets - * @param switchboardAddress_ address of switchboard * @param attestRequests_ the list of requests with packets to be attested by switchboard in sequence */ - function attestBatch( - address switchboardAddress_, - AttestRequest[] calldata attestRequests_ - ) external { - _attestBatch(switchboardAddress_, attestRequests_); + function attestBatch(AttestRequest[] calldata attestRequests_) external { + _attestBatch(attestRequests_); } /** * @notice send a batch of propose, attest and execute transactions * @param socketAddress_ address of socket - * @param switchboardAddress_ address of switchboard * @param proposeRequests_ the list of requests with packets to be proposed * @param attestRequests_ the list of requests with packets to be attested by switchboard * @param executeRequests_ the list of requests with messages to be executed */ function sendBatch( address socketAddress_, - address switchboardAddress_, SealRequest[] calldata sealRequests_, ProposeRequest[] calldata proposeRequests_, AttestRequest[] calldata attestRequests_, @@ -376,7 +367,7 @@ contract SocketBatcher is AccessControl { ) external payable { _sealBatch(socketAddress_, sealRequests_); _proposeBatch(socketAddress_, proposeRequests_); - _attestBatch(switchboardAddress_, attestRequests_); + _attestBatch(attestRequests_); _executeBatch(socketAddress_, executeRequests_); } diff --git a/test/socket/SocketBatcher.t.sol b/test/socket/SocketBatcher.t.sol index d5346911..edd33435 100644 --- a/test/socket/SocketBatcher.t.sol +++ b/test/socket/SocketBatcher.t.sol @@ -127,6 +127,7 @@ contract SocketBatcherTest is Setup { SocketBatcher.AttestRequest memory attestRequest = SocketBatcher .AttestRequest({ + switchboard: address(_b.configs__[0].switchboard__), packetId: packetId, proposalCount: 0, root: root, @@ -141,7 +142,6 @@ contract SocketBatcherTest is Setup { batcher__.sendBatch( address(_b.socket__), - address(_b.configs__[0].switchboard__), sealRequests, proposeRequests, attestRequests, From 7b30b2029cc0d9f5110639775e5b8313ae87f367 Mon Sep 17 00:00:00 2001 From: Akash Date: Mon, 9 Oct 2023 15:53:14 +0530 Subject: [PATCH 3/5] feat: capacitorCount script --- scripts/admin/rescueFunds.ts | 3 +- scripts/deploy/scripts/allPathTest.ts | 2 +- scripts/deploy/scripts/capacitorCount.ts | 97 +++++++++++++++++++++++ scripts/deploy/scripts/checkBalance.ts | 17 ++-- scripts/deploy/scripts/switchboardData.ts | 26 +++--- scripts/deploy/utils/utils.ts | 3 +- 6 files changed, 127 insertions(+), 21 deletions(-) create mode 100644 scripts/deploy/scripts/capacitorCount.ts diff --git a/scripts/admin/rescueFunds.ts b/scripts/admin/rescueFunds.ts index 25149e59..24d4269a 100644 --- a/scripts/admin/rescueFunds.ts +++ b/scripts/admin/rescueFunds.ts @@ -10,7 +10,8 @@ import { import { Contract, Wallet, ethers } from "ethers"; import { mode, overrides } from "../deploy/config"; import { getProviderFromChainName } from "../constants"; -import { getAllAddresses } from "@socket.tech/dl-core"; +// dl-core might have old addresses +import { getAllAddresses } from "../../src"; const ETH_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"; const rescueFundsABI = [ diff --git a/scripts/deploy/scripts/allPathTest.ts b/scripts/deploy/scripts/allPathTest.ts index 8e00a6d5..705dc949 100644 --- a/scripts/deploy/scripts/allPathTest.ts +++ b/scripts/deploy/scripts/allPathTest.ts @@ -100,7 +100,7 @@ export const sendMessagesToAllPaths = async (params: { count: number; }) => { const amount = 100; - const msgGasLimit = "1000000"; // update this when add fee logic for dst gas limit + const msgGasLimit = "100000"; // update this when add fee logic for dst gas limit let gasLimit: number | undefined = 185766; try { diff --git a/scripts/deploy/scripts/capacitorCount.ts b/scripts/deploy/scripts/capacitorCount.ts new file mode 100644 index 00000000..e5ecda01 --- /dev/null +++ b/scripts/deploy/scripts/capacitorCount.ts @@ -0,0 +1,97 @@ +import { ContractFactory } from "ethers"; +import { network, ethers, run } from "hardhat"; + +import { DeployParams, getOrDeploy, storeAddresses } from "../utils"; + +import { + CORE_CONTRACTS, + ChainSocketAddresses, + DeploymentMode, + ChainSlugToKey, + version, + DeploymentAddresses, + getAllAddresses, + ChainSlug, + IntegrationTypes, +} from "../../../src"; +import deploySwitchboards from "./deploySwitchboard"; +import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; +import { socketOwner, executionManagerVersion, mode, chains } from "../config"; +import { + getProviderFromChainSlug, + maxAllowedPacketLength, +} from "../../constants"; + +const main = async ( + srcChains: ChainSlug[], + dstChains: ChainSlug[], + integrationTypes: IntegrationTypes[] +) => { + try { + let addresses: DeploymentAddresses; + try { + addresses = getAllAddresses(mode); + } catch (error) { + addresses = {} as DeploymentAddresses; + } + let srcChainSlugs = srcChains ?? chains; + + await Promise.all( + srcChainSlugs.map(async (chainSlug) => { + let integrations = addresses[chainSlug as ChainSlug]?.integrations; + if (!integrations) return; + + let siblingChains = dstChains ?? Object.keys(integrations); + + await Promise.all( + siblingChains.map(async (siblingChain) => { + let siblingIntegrations = + integrations?.[Number(siblingChain) as ChainSlug]; + if (!siblingIntegrations) return; + let integrationTypesArray = + integrationTypes ?? Object.keys(siblingIntegrations); + + await Promise.all( + integrationTypesArray.map(async (integrationType) => { + let integration = + siblingIntegrations?.[integrationType as IntegrationTypes]; + if (!integration) return; + let capacitor = integration.capacitor; + if (!capacitor) return; + let provider = getProviderFromChainSlug(chainSlug as ChainSlug); + let Contract = await ethers.getContractFactory( + "SingleCapacitor" + ); + let instance = Contract.attach(capacitor).connect(provider); + let result = await instance.getNextPacketToBeSealed(); + console.log( + chainSlug, + " ", + Number(siblingChain), + " ", + integrationType, + " ", + result[1].toNumber(), + " ", + result[0].toString() + ); + }) + ); + }) + ); + }) + ); + } catch (error) { + console.log(error); + } +}; + +// let srcChains; +// let dstChains; +let integrationTypes; + +let srcChains = [ChainSlug.OPTIMISM_GOERLI]; +let dstChains = [ChainSlug.ARBITRUM_GOERLI]; +// let integrationTypes = [IntegrationTypes.fast2]; + +main(srcChains, dstChains, integrationTypes); diff --git a/scripts/deploy/scripts/checkBalance.ts b/scripts/deploy/scripts/checkBalance.ts index c7693f44..bb26589d 100644 --- a/scripts/deploy/scripts/checkBalance.ts +++ b/scripts/deploy/scripts/checkBalance.ts @@ -2,10 +2,8 @@ import { config as dotenvConfig } from "dotenv"; import axios from "axios"; dotenvConfig(); -import { - ChainSlugToKey, -} from "../../../src"; -import { utils } from "ethers"; +import { ChainSlugToKey } from "../../../src"; +import { utils } from "ethers"; import { chains, mode } from "../config"; import { getProviderFromChainName } from "../../constants/networks"; @@ -16,16 +14,19 @@ export const checkBalance = async () => { // parallelize chains await Promise.all( chains.map(async (chainSlug) => { - const provider = await getProviderFromChainName( ChainSlugToKey[chainSlug] ); // let ownerAddress = process.env.SOCKET_OWNER_ADDRESS; let ownerAddress = "0x752B38FA38F53dF7fa60e6113CFd9094b7e040Aa"; if (!ownerAddress) throw Error("owner address not present"); - console.log(chainSlug, " ", ChainSlugToKey[chainSlug], " : ", utils.formatEther( await provider.getBalance(ownerAddress))); - - + console.log( + chainSlug, + " ", + ChainSlugToKey[chainSlug], + " : ", + utils.formatEther(await provider.getBalance(ownerAddress)) + ); }) ); } catch (error) { diff --git a/scripts/deploy/scripts/switchboardData.ts b/scripts/deploy/scripts/switchboardData.ts index fb46532b..8e5965d2 100644 --- a/scripts/deploy/scripts/switchboardData.ts +++ b/scripts/deploy/scripts/switchboardData.ts @@ -5,9 +5,7 @@ import { IntegrationTypes, getAllAddresses, } from "../../../src"; -import { - toLowerCase, -} from "../utils"; +import { toLowerCase } from "../utils"; import { mode } from "../config"; import path from "path"; @@ -40,7 +38,6 @@ export const getSwitchboardData = async () => { let switchboards: Switchboard[] = []; for (let chainSlug in addresses) { - let chainAddresses = addresses[Number(chainSlug) as ChainSlug]; if (!chainAddresses) { console.log("chain addresses not found chainSlug: ", chainSlug); @@ -56,13 +53,16 @@ export const getSwitchboardData = async () => { let siblingIntegrations = integrations[Number(siblingChainSlug) as ChainSlug]; if (!siblingIntegrations) { - console.log("sibling integrations not found chainSlug: ", chainSlug, siblingChainSlug); + console.log( + "sibling integrations not found chainSlug: ", + chainSlug, + siblingChainSlug + ); return; } let integrationTypes = Object.keys(siblingIntegrations); for (let integrationType of integrationTypes) { - let switchboardAddresses = siblingIntegrations[integrationType as IntegrationTypes]; @@ -84,17 +84,25 @@ export const getSwitchboardData = async () => { integrationType as IntegrationTypes ].switchboard ), - isNativeSwitchboard:integrationType === IntegrationTypes.native + isNativeSwitchboard: integrationType === IntegrationTypes.native, }; switchboards.push(switchboard); } } } switchboards.forEach((s) => - console.log(s.switchboardId, s.dstSwitchboard, s.integrationType, s.isNativeSwitchboard) + console.log( + s.switchboardId, + s.dstSwitchboard, + s.integrationType, + s.isNativeSwitchboard + ) ); console.log("total switchboards: ", switchboards.length); - fs.writeFileSync("./switchboards.json", JSON.stringify(switchboards, null, 2)); + fs.writeFileSync( + "./switchboards.json", + JSON.stringify(switchboards, null, 2) + ); }; getSwitchboardData(); diff --git a/scripts/deploy/utils/utils.ts b/scripts/deploy/utils/utils.ts index 689d5064..181606b7 100644 --- a/scripts/deploy/utils/utils.ts +++ b/scripts/deploy/utils/utils.ts @@ -279,8 +279,7 @@ export const createObj = function ( return obj; }; - export const toLowerCase = (str?: string) => { if (!str) return ""; return str.toLowerCase(); -} +}; From 91aeba1eabb087857b335fd62571eca66e884197 Mon Sep 17 00:00:00 2001 From: Akash Date: Mon, 16 Oct 2023 13:56:44 +0530 Subject: [PATCH 4/5] feat: added switchboard script --- scripts/deploy/scripts/fastSwitchboards.ts | 78 ++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 scripts/deploy/scripts/fastSwitchboards.ts diff --git a/scripts/deploy/scripts/fastSwitchboards.ts b/scripts/deploy/scripts/fastSwitchboards.ts new file mode 100644 index 00000000..7bf83054 --- /dev/null +++ b/scripts/deploy/scripts/fastSwitchboards.ts @@ -0,0 +1,78 @@ +import { ContractFactory } from "ethers"; +import { network, ethers, run } from "hardhat"; + +import { DeployParams, getOrDeploy, storeAddresses } from "../utils"; + +import { + CORE_CONTRACTS, + ChainSocketAddresses, + DeploymentMode, + ChainSlugToKey, + version, + DeploymentAddresses, + getAllAddresses, + ChainSlug, + IntegrationTypes, +} from "../../../src"; +import deploySwitchboards from "./deploySwitchboard"; +import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; +import { socketOwner, executionManagerVersion, mode, chains } from "../config"; +import { + getProviderFromChainSlug, + maxAllowedPacketLength, +} from "../../constants"; + +const main = async ( + srcChains: ChainSlug[], + dstChains: ChainSlug[] +) => { + try { + let addresses: DeploymentAddresses; + try { + addresses = getAllAddresses(mode); + } catch (error) { + addresses = {} as DeploymentAddresses; + } + let srcChainSlugs = srcChains ?? chains; + let data: any[] = []; + await Promise.all( + srcChainSlugs.map(async (chainSlug) => { + let fastSwitchboardAddress = + addresses[chainSlug as ChainSlug]?.FastSwitchboard2; + if (!fastSwitchboardAddress) return; + + let siblingChains = dstChains ?? chains.filter((s) => chainSlug !== s); + + await Promise.all( + siblingChains.map(async (siblingChain) => { + let provider = getProviderFromChainSlug(chainSlug as ChainSlug); + let Contract = await ethers.getContractFactory("FastSwitchboard"); + let instance = Contract.attach(fastSwitchboardAddress).connect( + provider + ); + // console.log(instance);รท\ + let result = await instance["totalWatchers(uint32)"](siblingChain); + // console.log(result); + data.push({ + chainSlug, + siblingChain, + totalWatchers: result.toNumber(), + }); + }) + ); + }) + ); + console.table(data); + } catch (error) { + console.log(error); + } +}; + +// let srcChains; +// let dstChains; + +let srcChains = [ChainSlug.ARBITRUM_GOERLI]; +let dstChains = [ChainSlug.AEVO_TESTNET]; +// let integrationTypes = [IntegrationTypes.fast2]; + +main(srcChains, dstChains); From d27bcde845bb387d978667a80e9e48e4a8a13379 Mon Sep 17 00:00:00 2001 From: Akash Date: Mon, 16 Oct 2023 13:57:02 +0530 Subject: [PATCH 5/5] chore:lint --- scripts/deploy/scripts/fastSwitchboards.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scripts/deploy/scripts/fastSwitchboards.ts b/scripts/deploy/scripts/fastSwitchboards.ts index 7bf83054..dfd8db76 100644 --- a/scripts/deploy/scripts/fastSwitchboards.ts +++ b/scripts/deploy/scripts/fastSwitchboards.ts @@ -22,10 +22,7 @@ import { maxAllowedPacketLength, } from "../../constants"; -const main = async ( - srcChains: ChainSlug[], - dstChains: ChainSlug[] -) => { +const main = async (srcChains: ChainSlug[], dstChains: ChainSlug[]) => { try { let addresses: DeploymentAddresses; try {