Skip to content

Commit 68f7182

Browse files
committed
Merge remote-tracking branch 'origin/fix/new-relayer' into chains
2 parents c0167e7 + 34db410 commit 68f7182

10 files changed

Lines changed: 148 additions & 45 deletions

File tree

scripts/admin/send-execute.ts

Lines changed: 65 additions & 13 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";
@@ -37,9 +37,30 @@ dotenvConfig();
3737
* Eg. npx --sourcetxhash=0x123... --kmskeyid=abc-123 --sendtx ts-node scripts/admin/send-execute.ts
3838
*/
3939

40-
const sourceTxHash = process.env.npm_config_sourcetxhash;
41-
if (!sourceTxHash) {
42-
console.error("Error: sourcetxhash flag is required");
40+
// Configuration object with execution and message details
41+
const EXECUTION_CONFIG = {
42+
executionDetails: {
43+
packetId:
44+
"0x0000a4b129ebc834d24af22b9466a4150425354998c3e800000000000000cbe6", // Replace with actual packet ID
45+
proposalCount: "0", // Replace with actual proposal count
46+
executionGasLimit: "200000", // Replace with actual gas limit
47+
decapacitorProof: "0x", // Replace with actual proof
48+
},
49+
messageDetails: {
50+
msgId: "0x0000a4b126e5ce884875ea3776a57f0b225b1ea8d2e9beeb00000000000608cb", // Replace with actual message ID
51+
executionFee: "0", // Replace with actual execution fee
52+
minMsgGasLimit: "100000", // Replace with actual min gas limit
53+
executionParams:
54+
"0x0000000000000000000000000000000000000000000000000000000000000000", // Replace with actual execution params
55+
payload:
56+
"0x0000000000000000000000008cb4c89cc297e07c7a309af8b16cc2f5f62a3b1300000000000000000000000000000000000000000000000000000000062ebe4d", // Replace with actual payload
57+
},
58+
msgValue: "0", // ETH value to send with transaction (in wei)
59+
};
60+
61+
const destinationChainSlug = process.env.npm_config_destination;
62+
if (!destinationChainSlug) {
63+
console.error("Error: destination flag is required");
4364
process.exit(1);
4465
}
4566

@@ -75,11 +96,9 @@ export const main = async () => {
7596
`\nFetching MessageOutbound event from source transaction: ${sourceTxHash}\n`
7697
);
7798

78-
// First, we need to get the transaction receipt to determine the source chain
79-
// We'll try to fetch the receipt from all chains until we find it
80-
let sourceChain: ChainSlug | undefined;
81-
let sourceProvider: ethers.providers.Provider | undefined;
82-
let txReceipt: ethers.providers.TransactionReceipt | undefined;
99+
console.log(
100+
`\nProcessing execute transaction for chain: ${destinationChain}\n`
101+
);
83102

84103
console.log("Searching for transaction across chains...");
85104
for (const [chainSlug, chainAddresses] of Object.entries(addresses)) {
@@ -150,6 +169,32 @@ export const main = async () => {
150169
console.log("Destination Addresses:");
151170
console.log(` Socket: ${socketAddress}\n`);
152171

172+
console.log("Execution Configuration:");
173+
console.log(" ExecutionDetails:");
174+
console.log(` Packet ID: ${EXECUTION_CONFIG.executionDetails.packetId}`);
175+
console.log(
176+
` Proposal Count: ${EXECUTION_CONFIG.executionDetails.proposalCount}`
177+
);
178+
console.log(
179+
` Execution Gas Limit: ${EXECUTION_CONFIG.executionDetails.executionGasLimit}`
180+
);
181+
console.log(
182+
` Decapacitor Proof: ${EXECUTION_CONFIG.executionDetails.decapacitorProof}`
183+
);
184+
console.log(" MessageDetails:");
185+
console.log(` Message ID: ${EXECUTION_CONFIG.messageDetails.msgId}`);
186+
console.log(
187+
` Execution Fee: ${EXECUTION_CONFIG.messageDetails.executionFee}`
188+
);
189+
console.log(
190+
` Min Message Gas Limit: ${EXECUTION_CONFIG.messageDetails.minMsgGasLimit}`
191+
);
192+
console.log(
193+
` Execution Params: ${EXECUTION_CONFIG.messageDetails.executionParams}`
194+
);
195+
console.log(` Payload: ${EXECUTION_CONFIG.messageDetails.payload}`);
196+
console.log(` Message Value: ${EXECUTION_CONFIG.msgValue}\n`);
197+
153198
// Get provider
154199
const provider = getProviderFromChainSlug(destinationChain);
155200

@@ -174,10 +219,17 @@ export const main = async () => {
174219
provider
175220
);
176221

177-
// Use data from parsed event
178-
const srcChainSlug = sourceChain;
179-
const srcPlug = parsedEvent.args.localPlug;
180-
const dstPlug = parsedEvent.args.dstPlug;
222+
// Extract chain slug and plug from msgId
223+
// msgId format: chainSlug (32 bits) | plug (160 bits) | messageCount (64 bits)
224+
const msgIdBigInt = BigInt(EXECUTION_CONFIG.messageDetails.msgId);
225+
const srcChainSlug = Number(
226+
(msgIdBigInt >> BigInt(224)) & BigInt(0xffffffff)
227+
);
228+
const dstPlug =
229+
"0x" +
230+
((msgIdBigInt >> BigInt(64)) & ((BigInt(1) << BigInt(160)) - BigInt(1)))
231+
.toString(16)
232+
.padStart(40, "0");
181233

182234
// Get plug config to find siblingPlug (for verification)
183235
const plugConfig = await socketContract.getPlugConfig(dstPlug, srcChainSlug);

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

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ const ATTEST_GAS_LIMIT = 800000;
2121
const outboundTxHash = "";
2222

2323
const walletPrivateKey = process.env.SOCKET_SIGNER_KEY!;
24-
const l1Provider = new providers.JsonRpcProvider(getJsonRpcUrl(localChain));
24+
const l1Provider = new providers.JsonRpcProvider(
25+
getJsonRpcUrl(hardhatChainNameToSlug[localChain])
26+
);
2527
const l1Wallet = new Wallet(walletPrivateKey, l1Provider);
2628

2729
export const main = async () => {
@@ -45,7 +47,11 @@ export const main = async () => {
4547

4648
// get socket contracts for both chains
4749
// counter l1, counter l2, seal, execute
48-
const contracts = contractNames("", localChain, remoteChain);
50+
const contracts = contractNames(
51+
"",
52+
hardhatChainNameToSlug[localChain],
53+
hardhatChainNameToSlug[remoteChain]
54+
);
4955

5056
const l1Capacitor: Contract = (
5157
await getInstance(

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
import { providers, Wallet } from "ethers";
22
import { CrossChainMessenger, MessageStatus } from "@eth-optimism/sdk";
33
import { getJsonRpcUrl } from "../../constants";
4-
import { HardhatChainName, ChainId } from "../../../src";
4+
import {
5+
HardhatChainName,
6+
ChainId,
7+
hardhatChainNameToSlug,
8+
} from "../../../src";
59

610
// get providers for source and destination
711
const l1ChainId = ChainId.SEPOLIA;
812
const l2ChainId = ChainId.OPTIMISM_SEPOLIA;
913

1014
const walletPrivateKey = process.env.SOCKET_SIGNER_KEY!;
11-
const l1Provider = new providers.JsonRpcProvider(getJsonRpcUrl(l1ChainId));
15+
const l1Provider = new providers.JsonRpcProvider(
16+
getJsonRpcUrl(hardhatChainNameToSlug[l1ChainId])
17+
);
1218
const l1Wallet = new Wallet(walletPrivateKey, l1Provider);
1319

1420
const sealTxHash = "";
@@ -18,7 +24,9 @@ export const main = async () => {
1824
l1ChainId,
1925
l2ChainId,
2026
l1SignerOrProvider: l1Wallet,
21-
l2SignerOrProvider: new providers.JsonRpcProvider(getJsonRpcUrl(l2ChainId)),
27+
l2SignerOrProvider: new providers.JsonRpcProvider(
28+
getJsonRpcUrl(hardhatChainNameToSlug[l2ChainId])
29+
),
2230
});
2331

2432
const status = await crossChainMessenger.getMessageStatus(sealTxHash);

scripts/native-bridge-helpers/optimism/op-stack-native-withdrawals.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { config as dotenvConfig } from "dotenv";
33
import { constants, providers, Wallet } from "ethers";
44
import { CrossChainMessenger, MessageStatus } from "@eth-optimism/sdk";
55
import { getJsonRpcUrl } from "../../constants";
6-
import { ChainId } from "../../../src";
6+
import { ChainId, hardhatChainNameToSlug } from "../../../src";
77
import { resolve } from "path";
88
import axios from "axios";
99

@@ -20,8 +20,12 @@ const initTxHash =
2020
"0x373611163c75ca063aae79fc7a8ef4a9d8e66603cc92997cbbcd2a18cbbcde37";
2121

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

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

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,14 @@ const remoteChain = HardhatChainName.MAINNET;
8989

9090
const l2Provider = new providers.JsonRpcProvider(getJsonRpcUrl(localChain));
9191
const l1Provider = new providers.JsonRpcProvider(getJsonRpcUrl(remoteChain));
92+
9293
const l1Signer = new SocketRelaySigner(
9394
l1Provider,
94-
process.env.RELAYER_URL_DEV!
95+
`${process.env.RELAYER_URL_DEV!}/relay`
9596
);
9697
const l2Signer = new SocketRelaySigner(
9798
l2Provider,
98-
process.env.RELAYER_URL_DEV!
99+
`${process.env.RELAYER_URL_DEV!}/relay`
99100
);
100101

101102
export const main = async () => {

0 commit comments

Comments
 (0)