Skip to content

Commit

Permalink
feat: capacitorCount script
Browse files Browse the repository at this point in the history
  • Loading branch information
tHeMaskedMan981 committed Oct 9, 2023
1 parent 5aa6171 commit 7b30b20
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 21 deletions.
3 changes: 2 additions & 1 deletion scripts/admin/rescueFunds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
2 changes: 1 addition & 1 deletion scripts/deploy/scripts/allPathTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
97 changes: 97 additions & 0 deletions scripts/deploy/scripts/capacitorCount.ts
Original file line number Diff line number Diff line change
@@ -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);
17 changes: 9 additions & 8 deletions scripts/deploy/scripts/checkBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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) {
Expand Down
26 changes: 17 additions & 9 deletions scripts/deploy/scripts/switchboardData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand All @@ -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];

Expand All @@ -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();
3 changes: 1 addition & 2 deletions scripts/deploy/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,7 @@ export const createObj = function (
return obj;
};


export const toLowerCase = (str?: string) => {
if (!str) return "";
return str.toLowerCase();
}
};

0 comments on commit 7b30b20

Please sign in to comment.