Skip to content

Commit 3941f97

Browse files
authored
feat: add script to encode the withdrawAndCall payload for Sui (#250)
1 parent 02ca507 commit 3941f97

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { ethers } from "ethers";
2+
3+
async function encode() {
4+
// this script abi encodes type arguments, objects and the message to be passed to the Sui connected contract
5+
// in protocol this encoded bytes array is passed to GatewayZEVM.withdrawAndCall
6+
7+
const args = process.argv.slice(2);
8+
9+
if (args.length != 3) {
10+
throw new Error(`invalid argument number, expected 3, got ${args.length}`);
11+
}
12+
13+
const typeArguments: string[] = args[0].split(",").map((s) => s.trim());
14+
const objects: string[] = args[1].split(",").map((s) =>
15+
ethers.utils.hexZeroPad(s.trim(), 32)
16+
);
17+
const message = args[2];
18+
19+
// values are abi encoded
20+
const encoded = ethers.utils.defaultAbiCoder.encode(
21+
["tuple(string[] typeArguments, bytes32[] objects, bytes message)"],
22+
[[typeArguments, objects, message]]
23+
);
24+
25+
console.log(encoded);
26+
}
27+
28+
encode().catch((err) =>
29+
console.error(`Encode args for sui examples error: ${err}, usage: encodeCall.ts <commaSeparatedTypeArguments> <commaSeparatedObjectIDs> <message>`,)
30+
);

0 commit comments

Comments
 (0)