Skip to content

Commit 34db410

Browse files
fix: scripts
1 parent 88d6ea7 commit 34db410

15 files changed

Lines changed: 163 additions & 60 deletions

File tree

scripts/admin/get-outbound-txs.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,11 @@ export const main = async () => {
112112
const CHUNK_SIZE = 5000;
113113
const messageAddedEvents = [];
114114

115-
for (let currentBlock = fromBlock; currentBlock <= toBlock; currentBlock += CHUNK_SIZE) {
115+
for (
116+
let currentBlock = fromBlock;
117+
currentBlock <= toBlock;
118+
currentBlock += CHUNK_SIZE
119+
) {
116120
const chunkEnd = Math.min(currentBlock + CHUNK_SIZE - 1, toBlock);
117121
console.log(`Querying chunk: ${currentBlock} to ${chunkEnd}`);
118122

scripts/admin/get-seal-events.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,11 @@ export const main = async () => {
112112
const CHUNK_SIZE = 5000;
113113
const sealedEvents = [];
114114

115-
for (let currentBlock = fromBlock; currentBlock <= toBlock; currentBlock += CHUNK_SIZE) {
115+
for (
116+
let currentBlock = fromBlock;
117+
currentBlock <= toBlock;
118+
currentBlock += CHUNK_SIZE
119+
) {
116120
const chunkEnd = Math.min(currentBlock + CHUNK_SIZE - 1, toBlock);
117121
console.log(`Querying chunk: ${currentBlock} to ${chunkEnd}`);
118122

scripts/admin/send-attest.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ export const main = async () => {
9191
const sourceChain = sourceChainSlug;
9292
const destinationChain = destinationChainSlug;
9393

94-
console.log(`\nProcessing attest for path: ${sourceChain} -> ${destinationChain}\n`);
94+
console.log(
95+
`\nProcessing attest for path: ${sourceChain} -> ${destinationChain}\n`
96+
);
9597

9698
// Get addresses from prod_addresses.json
9799
const destinationAddresses = addresses[destinationChain];
@@ -139,19 +141,29 @@ export const main = async () => {
139141
const messageHash = keccak256(
140142
defaultAbiCoder.encode(
141143
["address", "uint32", "bytes32", "uint256", "bytes32"],
142-
[switchboardAddress, parseInt(destinationChain), packetId, proposalCount, root]
144+
[
145+
switchboardAddress,
146+
parseInt(destinationChain),
147+
packetId,
148+
proposalCount,
149+
root,
150+
]
143151
)
144152
);
145153

146154
console.log("Message hash:", messageHash);
147155

148156
// Sign with KMS
149157
console.log("\nSigning with AWS KMS...");
150-
const signature = await kmsSigner.signMessage(ethers.utils.arrayify(messageHash));
158+
const signature = await kmsSigner.signMessage(
159+
ethers.utils.arrayify(messageHash)
160+
);
151161
console.log("Signature:", signature);
152162

153163
// Prepare transaction data
154-
const switchboardInterface = new ethers.utils.Interface(FastSwitchboardArtifact.abi);
164+
const switchboardInterface = new ethers.utils.Interface(
165+
FastSwitchboardArtifact.abi
166+
);
155167
const calldata = switchboardInterface.encodeFunctionData("attest", [
156168
packetId,
157169
proposalCount,
@@ -193,7 +205,9 @@ export const main = async () => {
193205
console.log("Gas used:", receipt.gasUsed.toString());
194206
} else {
195207
console.log("To send the attest transaction, add --sendtx flag");
196-
console.log("You can use the transaction details above to manually send, simulate, or audit the transaction.");
208+
console.log(
209+
"You can use the transaction details above to manually send, simulate, or audit the transaction."
210+
);
197211
}
198212

199213
console.log("\nScript completed.");

scripts/admin/send-execute.ts

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
getAllAddresses,
66
getOverrides,
77
} from "../../src";
8-
import { mode, overrides } from "../deploy/config/config";
8+
import { mode } from "../deploy/config/config";
99
import SocketArtifact from "../../out/Socket.sol/Socket.json";
1010
import { getProviderFromChainSlug } from "../constants";
1111
import { ethers, Wallet } from "ethers";
@@ -31,7 +31,8 @@ dotenvConfig();
3131
// Configuration object with execution and message details
3232
const EXECUTION_CONFIG = {
3333
executionDetails: {
34-
packetId: "0x0000a4b129ebc834d24af22b9466a4150425354998c3e800000000000000cbe6", // Replace with actual packet ID
34+
packetId:
35+
"0x0000a4b129ebc834d24af22b9466a4150425354998c3e800000000000000cbe6", // Replace with actual packet ID
3536
proposalCount: "0", // Replace with actual proposal count
3637
executionGasLimit: "200000", // Replace with actual gas limit
3738
decapacitorProof: "0x", // Replace with actual proof
@@ -40,8 +41,10 @@ const EXECUTION_CONFIG = {
4041
msgId: "0x0000a4b126e5ce884875ea3776a57f0b225b1ea8d2e9beeb00000000000608cb", // Replace with actual message ID
4142
executionFee: "0", // Replace with actual execution fee
4243
minMsgGasLimit: "100000", // Replace with actual min gas limit
43-
executionParams: "0x0000000000000000000000000000000000000000000000000000000000000000", // Replace with actual execution params
44-
payload: "0x0000000000000000000000008cb4c89cc297e07c7a309af8b16cc2f5f62a3b1300000000000000000000000000000000000000000000000000000000062ebe4d", // Replace with actual payload
44+
executionParams:
45+
"0x0000000000000000000000000000000000000000000000000000000000000000", // Replace with actual execution params
46+
payload:
47+
"0x0000000000000000000000008cb4c89cc297e07c7a309af8b16cc2f5f62a3b1300000000000000000000000000000000000000000000000000000000062ebe4d", // Replace with actual payload
4548
},
4649
msgValue: "0", // ETH value to send with transaction (in wei)
4750
};
@@ -71,7 +74,9 @@ const addresses: DeploymentAddresses = getAllAddresses(mode);
7174
export const main = async () => {
7275
const destinationChain = parseInt(destinationChainSlug) as ChainSlug;
7376

74-
console.log(`\nProcessing execute transaction for chain: ${destinationChain}\n`);
77+
console.log(
78+
`\nProcessing execute transaction for chain: ${destinationChain}\n`
79+
);
7580

7681
// Get addresses from prod_addresses.json
7782
const destinationAddresses = addresses[destinationChain];
@@ -90,21 +95,31 @@ export const main = async () => {
9095
console.log("Execution Configuration:");
9196
console.log(" ExecutionDetails:");
9297
console.log(` Packet ID: ${EXECUTION_CONFIG.executionDetails.packetId}`);
93-
console.log(` Proposal Count: ${EXECUTION_CONFIG.executionDetails.proposalCount}`);
94-
console.log(` Execution Gas Limit: ${EXECUTION_CONFIG.executionDetails.executionGasLimit}`);
95-
console.log(` Decapacitor Proof: ${EXECUTION_CONFIG.executionDetails.decapacitorProof}`);
98+
console.log(
99+
` Proposal Count: ${EXECUTION_CONFIG.executionDetails.proposalCount}`
100+
);
101+
console.log(
102+
` Execution Gas Limit: ${EXECUTION_CONFIG.executionDetails.executionGasLimit}`
103+
);
104+
console.log(
105+
` Decapacitor Proof: ${EXECUTION_CONFIG.executionDetails.decapacitorProof}`
106+
);
96107
console.log(" MessageDetails:");
97108
console.log(` Message ID: ${EXECUTION_CONFIG.messageDetails.msgId}`);
98-
console.log(` Execution Fee: ${EXECUTION_CONFIG.messageDetails.executionFee}`);
99-
console.log(` Min Message Gas Limit: ${EXECUTION_CONFIG.messageDetails.minMsgGasLimit}`);
100-
console.log(` Execution Params: ${EXECUTION_CONFIG.messageDetails.executionParams}`);
109+
console.log(
110+
` Execution Fee: ${EXECUTION_CONFIG.messageDetails.executionFee}`
111+
);
112+
console.log(
113+
` Min Message Gas Limit: ${EXECUTION_CONFIG.messageDetails.minMsgGasLimit}`
114+
);
115+
console.log(
116+
` Execution Params: ${EXECUTION_CONFIG.messageDetails.executionParams}`
117+
);
101118
console.log(` Payload: ${EXECUTION_CONFIG.messageDetails.payload}`);
102119
console.log(` Message Value: ${EXECUTION_CONFIG.msgValue}\n`);
103120

104121
// Get provider
105-
const provider = getProviderFromChainSlug(
106-
destinationChain
107-
);
122+
const provider = getProviderFromChainSlug(destinationChain);
108123

109124
// Get Socket contract to access hasher
110125
const socketContract = new ethers.Contract(
@@ -119,15 +134,25 @@ export const main = async () => {
119134

120135
// Get hasher contract
121136
const hasherAbi = [
122-
"function packMessage(uint32 srcChainSlug_, address srcPlug_, uint32 dstChainSlug_, address dstPlug_, tuple(bytes32 msgId, uint256 executionFee, uint256 minMsgGasLimit, bytes32 executionParams, bytes payload) messageDetails_) external pure returns (bytes32)"
137+
"function packMessage(uint32 srcChainSlug_, address srcPlug_, uint32 dstChainSlug_, address dstPlug_, tuple(bytes32 msgId, uint256 executionFee, uint256 minMsgGasLimit, bytes32 executionParams, bytes payload) messageDetails_) external pure returns (bytes32)",
123138
];
124-
const hasherContract = new ethers.Contract(hasherAddress, hasherAbi, provider);
139+
const hasherContract = new ethers.Contract(
140+
hasherAddress,
141+
hasherAbi,
142+
provider
143+
);
125144

126145
// Extract chain slug and plug from msgId
127146
// msgId format: chainSlug (32 bits) | plug (160 bits) | messageCount (64 bits)
128147
const msgIdBigInt = BigInt(EXECUTION_CONFIG.messageDetails.msgId);
129-
const srcChainSlug = Number((msgIdBigInt >> BigInt(224)) & BigInt(0xFFFFFFFF));
130-
const dstPlug = "0x" + ((msgIdBigInt >> BigInt(64)) & ((BigInt(1) << BigInt(160)) - BigInt(1))).toString(16).padStart(40, "0");
148+
const srcChainSlug = Number(
149+
(msgIdBigInt >> BigInt(224)) & BigInt(0xffffffff)
150+
);
151+
const dstPlug =
152+
"0x" +
153+
((msgIdBigInt >> BigInt(64)) & ((BigInt(1) << BigInt(160)) - BigInt(1)))
154+
.toString(16)
155+
.padStart(40, "0");
131156

132157
console.log(`\nExtracted from msgId:`);
133158
console.log(` Source Chain Slug: ${srcChainSlug}`);
@@ -164,7 +189,9 @@ export const main = async () => {
164189

165190
// Sign with KMS
166191
console.log("\nSigning packed message with AWS KMS...");
167-
const signature = await kmsSigner.signMessage(ethers.utils.arrayify(packedMessage));
192+
const signature = await kmsSigner.signMessage(
193+
ethers.utils.arrayify(packedMessage)
194+
);
168195
console.log("Signature:", signature);
169196

170197
// Prepare transaction structs
@@ -223,7 +250,9 @@ export const main = async () => {
223250
console.log("Gas used:", receipt.gasUsed.toString());
224251
} else {
225252
console.log("To send the execute transaction, add --sendtx flag");
226-
console.log("You can use the transaction details above to manually send, simulate, or audit the transaction.");
253+
console.log(
254+
"You can use the transaction details above to manually send, simulate, or audit the transaction."
255+
);
227256
}
228257

229258
console.log("\nScript completed.");

scripts/constants/overrides.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export const getOverrides = async (
175175
const block = await provider.getBlock("latest");
176176
const baseFee = block.baseFeePerGas?.toNumber() || 0;
177177
const maxPriorityFeePerGas = Math.max(maxFeePerGas - baseFee, 0);
178-
console.log(chainSlug, gasLimit, maxFeePerGas, maxPriorityFeePerGas, type);
178+
console.log(chainSlug, gasLimit, maxFeePerGas, maxPriorityFeePerGas, type);
179179
return { gasLimit, maxFeePerGas, maxPriorityFeePerGas, type };
180180
} else {
181181
// Legacy transaction (type 0 or 1)

scripts/deploy/helpers/send-msg/utils.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ethers } from "ethers";
33
import Counter from "../../../../out/Counter.sol/Counter.json";
44
import Socket from "../../../../out/Socket.sol/Socket.json";
55
import { ChainSlug } from "../../../../src";
6-
import { getAPIBaseURL, getAddresses, relayTx } from "../../utils";
6+
import { getAPIBaseURL, getAddresses, getStatus, relayTx } from "../../utils";
77
dotenvConfig();
88

99
import { formatEther } from "ethers/lib/utils";
@@ -129,15 +129,21 @@ export const sendCounterBridgeMsg = async (
129129
let response = await relayTx({
130130
to,
131131
data,
132-
value,
133-
gasLimit,
134-
gasPrice,
132+
value: value?.toString(),
133+
gasLimit: gasLimit?.toString(),
134+
gasPrice: gasPrice?.toString(),
135135
type,
136136
chainSlug,
137137
});
138-
console.log(
139-
`Track message here: ${getAPIBaseURL(
140-
mode
141-
)}/messages-from-tx?srcChainSlug=${chainSlug}&srcTxHash=${response?.hash}`
142-
);
138+
139+
console.log(`Tx Id: ${response?.txId}`);
140+
const txHash = await getStatus(response?.txId);
141+
142+
if (txHash) {
143+
console.log(
144+
`Track message here: ${getAPIBaseURL(
145+
mode
146+
)}/messages-from-tx?srcChainSlug=${chainSlug}&srcTxHash=${txHash}`
147+
);
148+
}
143149
};

scripts/deploy/utils/relayer.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { BigNumber, BigNumberish } from "ethers";
22
import { getRelayAPIKEY, getRelayUrl } from "./utils";
3-
import { axiosPost } from "@socket.tech/dl-common";
3+
import { axiosGet, axiosPost } from "@socket.tech/dl-common";
44
import { mode } from "../config/config";
55
import { ChainSlugToId } from "../../../src";
66

@@ -17,7 +17,6 @@ interface RequestObj {
1717
export const relayTx = async (params: RequestObj) => {
1818
try {
1919
let { to, data, chainSlug, gasPrice, value, type, gasLimit } = params;
20-
let url = await getRelayUrl(mode);
2120
let config = {
2221
headers: {
2322
"x-api-key": getRelayAPIKEY(mode),
@@ -34,7 +33,26 @@ export const relayTx = async (params: RequestObj) => {
3433
sequential: false,
3534
source: "LoadTester",
3635
};
37-
let response = await axiosPost(url!, body, config);
36+
let response = await axiosPost(
37+
`${await getRelayUrl(mode)}/relay`,
38+
body,
39+
config
40+
);
41+
if (response?.success) return response?.data;
42+
else {
43+
console.log("error in relaying tx", response);
44+
return { hash: "" };
45+
}
46+
} catch (error) {
47+
console.log("uncaught error", error);
48+
}
49+
};
50+
51+
export const getStatus = async (txId: string) => {
52+
try {
53+
const response = await axiosGet(
54+
`${await getRelayUrl(mode)}/status?txId=${txId}`
55+
);
3856
if (response?.success) return response?.data;
3957
else {
4058
console.log("error in relaying tx", response);

scripts/deploy/utils/socket-signer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const getSocketSigner = async (
3434
ChainSlugToId[chainSlug],
3535
safeAddress,
3636
safeWrapperAddress,
37-
await getRelayUrl(mode),
37+
`${await getRelayUrl(mode)}/relay`,
3838
getRelayAPIKEY(mode),
3939
wallet,
4040
useSafe,

scripts/native-bridge-helpers/arbitrum/l1Tol2Relay.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,20 @@ import { L1ToL2MessageStatus, L1TransactionReceipt } from "@arbitrum/sdk";
1919
// get providers for source and destination
2020

2121
// replace following variables to initiate the txn
22-
const l1Chain = HardhatChainName.GOERLI;
23-
const l2Chain = HardhatChainName.ARBITRUM_GOERLI;
22+
const l1Chain = HardhatChainName.SEPOLIA;
23+
const l2Chain = HardhatChainName.ARBITRUM_SEPOLIA;
2424
const packetId =
2525
"0x00000005feb89935220606f3c3670ae510a74ab5750e810c0000000000000000";
2626
const root =
2727
"0xc8111d45052c1df62037b92c1fab7c23bda80a0854b81432aee514aaf5f6c440";
2828

2929
const walletPrivateKey = process.env.SOCKET_SIGNER_KEY!;
30-
const l1Provider = new providers.JsonRpcProvider(getJsonRpcUrl(l1Chain));
31-
const l2Provider = new providers.JsonRpcProvider(getJsonRpcUrl(l2Chain));
30+
const l1Provider = new providers.JsonRpcProvider(
31+
getJsonRpcUrl(hardhatChainNameToSlug[l1Chain])
32+
);
33+
const l2Provider = new providers.JsonRpcProvider(
34+
getJsonRpcUrl(hardhatChainNameToSlug[l2Chain])
35+
);
3236

3337
const l1Wallet = new Wallet(walletPrivateKey, l1Provider);
3438
const l2Wallet = new Wallet(walletPrivateKey, l2Provider);

scripts/native-bridge-helpers/arbitrum/l2tol1Relay.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,20 @@ import {
1111
} from "../../../src";
1212

1313
// https://goerli.arbiscan.io/txsExit to check message status
14-
const l1Chain = HardhatChainName.GOERLI;
15-
const l2Chain = HardhatChainName.ARBITRUM_GOERLI;
14+
const l1Chain = HardhatChainName.SEPOLIA;
15+
const l2Chain = HardhatChainName.ARBITRUM_SEPOLIA;
1616
const sealTxHash =
17-
"0x0113020a1e3b9f814a78791b9719bf583bb0f25075cde1e754af99f1dcf137a7";
17+
"0x4e8f4b180b2fbb5d06d637294776fda71025568bdb0cc31e2a430795e6481d54";
1818

1919
import { mode } from "../../deploy/config/config";
2020

2121
const walletPrivateKey = process.env.SOCKET_SIGNER_KEY!;
22-
const l1Provider = new providers.JsonRpcProvider(getJsonRpcUrl(l1Chain));
23-
const l2Provider = new providers.JsonRpcProvider(getJsonRpcUrl(l2Chain));
22+
const l1Provider = new providers.JsonRpcProvider(
23+
getJsonRpcUrl(hardhatChainNameToSlug[l1Chain])
24+
);
25+
const l2Provider = new providers.JsonRpcProvider(
26+
getJsonRpcUrl(hardhatChainNameToSlug[l2Chain])
27+
);
2428

2529
const l1Wallet = new Wallet(walletPrivateKey, l1Provider);
2630

0 commit comments

Comments
 (0)