Skip to content

Commit

Permalink
Merge pull request #324 from SocketDotTech/feat/scripts
Browse files Browse the repository at this point in the history
Feat/scripts
  • Loading branch information
ameeshaagrawal authored Oct 16, 2023
2 parents e7e9f13 + ae262d4 commit 40dabdf
Show file tree
Hide file tree
Showing 11 changed files with 357 additions and 35 deletions.
21 changes: 6 additions & 15 deletions contracts/socket/SocketBatcher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ contract SocketBatcher is AccessControl {
* @param signature The signature of the packet data.
*/
struct AttestRequest {
address switchboard;
bytes32 packetId;
uint256 proposalCount;
bytes32 root;
Expand Down Expand Up @@ -330,16 +331,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,
Expand All @@ -353,35 +350,29 @@ 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_,
ExecuteRequest[] calldata executeRequests_
) external payable {
_sealBatch(socketAddress_, sealRequests_);
_proposeBatch(socketAddress_, proposeRequests_);
_attestBatch(switchboardAddress_, attestRequests_);
_attestBatch(attestRequests_);
_executeBatch(socketAddress_, executeRequests_);
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@nomiclabs/hardhat-ethers": "^2.1.1",
"@nomiclabs/hardhat-etherscan": "^3.1.0",
"@nomiclabs/hardhat-waffle": "^2.0.3",
"@socket.tech/dl-core": "2.4.1",
"@socket.tech/dl-core": "2.4.5",
"@typechain/ethers-v5": "^10.0.0",
"@typechain/hardhat": "^6.0.0",
"@types/chai": "^4.3.0",
Expand Down
26 changes: 13 additions & 13 deletions scripts/deploy/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ console.log(
export const chains: Array<ChainSlug> = [
// ChainSlug.GOERLI,
ChainSlug.ARBITRUM_GOERLI,
// ChainSlug.OPTIMISM_GOERLI,
// ChainSlug.POLYGON_MUMBAI,
// ChainSlug.BSC_TESTNET,
// ChainSlug.AEVO_TESTNET,
// ChainSlug.LYRA_TESTNET,
ChainSlug.OPTIMISM_GOERLI,
ChainSlug.POLYGON_MUMBAI,
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.XAI_TESTNET,
// ChainSlug.SEPOLIA,
// ChainSlug.AEVO,
// ChainSlug.MAINNET,
// ChainSlug.ARBITRUM,
// ChainSlug.OPTIMISM,
// ChainSlug.LYRA,
// ChainSlug.BSC,
// ChainSlug.POLYGON_MAINNET,
];

export const executionManagerVersion = CORE_CONTRACTS.ExecutionManager;
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 @@ -101,7 +101,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);
46 changes: 46 additions & 0 deletions scripts/deploy/scripts/checkBalance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
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);
});
75 changes: 75 additions & 0 deletions scripts/deploy/scripts/fastSwitchboards.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
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);
Loading

0 comments on commit 40dabdf

Please sign in to comment.