Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/scripts #329

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@socket.tech/dl-core",
"license": "UNLICENSED",
"version": "2.4.9",
"version": "2.4.9-test.1",
"description": "Smart contracts for socket data layer.",
"main": "./dist/src/index.js",
"types": "./dist/src/index.d.ts",
Expand Down
18 changes: 12 additions & 6 deletions scripts/deploy/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,18 @@ export const main = async () => {
for (let index = 0; index < siblingSlugs.length; index++) {
const sibling = siblingSlugs[index];
const siblingCounter = addresses?.[sibling]?.["Counter"];
const switchboard = getSwitchboardAddress(
chain,
sibling,
siblingIntegrationtype[index],
mode
);
let switchboard;
try {
switchboard = getSwitchboardAddress(
chain,
sibling,
siblingIntegrationtype[index],
mode
);
} catch (error) {
console.log(error, " continuing");
}
if (!switchboard) continue;

const configs = await socket.getPlugConfig(counter.address, sibling);
if (
Expand Down
58 changes: 33 additions & 25 deletions scripts/deploy/scripts/capacitorCount.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
import { ContractFactory } from "ethers";
import { network, ethers, run } from "hardhat";

import { DeployParams, getOrDeploy, storeAddresses } from "../utils";
import { utils } from "ethers";
import { ethers } from "hardhat";

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";
import { mode, chains } from "../config";
import { getProviderFromChainSlug } from "../../constants";
import { encodePacketId } from "../utils/packetId";

const main = async (
srcChains: ChainSlug[],
dstChains: ChainSlug[],
integrationTypes: IntegrationTypes[]
) => {
try {
let data: any[] = [];

let addresses: DeploymentAddresses;
try {
addresses = getAllAddresses(mode);
Expand Down Expand Up @@ -63,24 +55,40 @@ const main = async (
"SingleCapacitor"
);
let instance = Contract.attach(capacitor).connect(provider);
let result = await instance.getNextPacketToBeSealed();
console.log(
let nextSealedPacket = await instance.getNextPacketToBeSealed();
let lastFilledPacket = await instance.getLastFilledPacket();

let digest = utils.keccak256(
utils.defaultAbiCoder.encode(
["bytes32", "uint32", "bytes32", "bytes32"],
[
utils.id(version[mode]),
siblingChain,
encodePacketId(
chainSlug,
capacitor,
nextSealedPacket[1].toNumber()
),
nextSealedPacket[0].toString(),
]
)
);
data.push({
chainSlug,
" ",
Number(siblingChain),
" ",
siblingChain,
integrationType,
" ",
result[1].toNumber(),
" ",
result[0].toString()
);
lastFilledPacket: lastFilledPacket.toNumber(),
nextSealedPacketCount: nextSealedPacket[1].toNumber(),
root: nextSealedPacket[0].toString(),
digest: digest,
});
})
);
})
);
})
);
console.table(data);
} catch (error) {
console.log(error);
}
Expand Down
15 changes: 15 additions & 0 deletions scripts/deploy/utils/packetId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,18 @@ export const packPacketId = (

return BigNumber.from(id).toString();
};

export function encodePacketId(
chainSlug: number,
capacitorAddress: string,
packetCount: number
) {
const encodedValue =
(BigInt(chainSlug) << BigInt(224)) |
(BigInt(capacitorAddress) << BigInt(64)) |
BigInt(packetCount);

// Ensure the result is a 32-byte hex string (bytes32 in Solidity)
const resultHex = encodedValue.toString(16).padStart(64, "0");
return "0x" + resultHex;
}
21 changes: 21 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,27 @@ export enum ChainSlug {
XAI_TESTNET = 1399904803,
}

export const ChainSlugToId = {
[ChainSlug.AVALANCHE]: ChainId.AVALANCHE,
[ChainSlug.BSC]: ChainId.BSC,
[ChainSlug.GOERLI]: ChainId.GOERLI,
[ChainSlug.SEPOLIA]: ChainId.SEPOLIA,
[ChainSlug.HARDHAT]: ChainId.HARDHAT,
[ChainSlug.MAINNET]: ChainId.MAINNET,
[ChainSlug.BSC_TESTNET]: ChainId.BSC_TESTNET,
[ChainSlug.ARBITRUM]: ChainId.ARBITRUM,
[ChainSlug.ARBITRUM_GOERLI]: ChainId.ARBITRUM_GOERLI,
[ChainSlug.OPTIMISM]: ChainId.OPTIMISM,
[ChainSlug.OPTIMISM_GOERLI]: ChainId.OPTIMISM_GOERLI,
[ChainSlug.POLYGON_MAINNET]: ChainId.POLYGON_MAINNET,
[ChainSlug.POLYGON_MUMBAI]: ChainId.POLYGON_MUMBAI,
[ChainSlug.AEVO_TESTNET]: ChainId.AEVO_TESTNET,
[ChainSlug.LYRA_TESTNET]: ChainId.LYRA_TESTNET,
[ChainSlug.LYRA]: ChainId.LYRA,
[ChainSlug.AEVO]: ChainId.AEVO,
[ChainSlug.XAI_TESTNET]: ChainId.XAI_TESTNET,
};

export const hardhatChainNameToSlug = {
[HardhatChainName.ARBITRUM]: ChainSlug.ARBITRUM,
[HardhatChainName.ARBITRUM_GOERLI]: ChainSlug.ARBITRUM_GOERLI,
Expand Down