@across-protocol/contracts 3.0.18 → 3.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/README.md +2 -0
  2. package/artifacts/build-info/9cb910e5bb5dd730cd01af84a0fb0466.json +1 -0
  3. package/artifacts/contracts/Ink_SpokePool.sol/Ink_SpokePool.dbg.json +4 -0
  4. package/artifacts/contracts/Ink_SpokePool.sol/Ink_SpokePool.json +2316 -0
  5. package/contracts/Ink_SpokePool.sol +72 -0
  6. package/dist/deploy/consts.js +8 -2
  7. package/dist/deployments/deployments.json +7 -1
  8. package/dist/hardhat.config.js +17 -0
  9. package/dist/scripts/svm/addressToPublicKey.js +2 -2
  10. package/dist/scripts/svm/bridgeLiabilityToHubPool.d.ts +1 -4
  11. package/dist/scripts/svm/bridgeLiabilityToHubPool.js +5 -15
  12. package/dist/scripts/svm/closeRelayerPdas.js +3 -3
  13. package/dist/scripts/svm/executeRebalanceToHubPool.d.ts +1 -4
  14. package/dist/scripts/svm/executeRebalanceToHubPool.js +6 -16
  15. package/dist/scripts/svm/executeRebalanceToSpokePool.js +14 -27
  16. package/dist/scripts/svm/fakeFillWithRandomDistribution.js +6 -7
  17. package/dist/scripts/svm/initialize.js +2 -2
  18. package/dist/scripts/svm/proposeRebalanceToSpokePool.js +11 -15
  19. package/dist/scripts/svm/publicKeyToAddress.js +2 -2
  20. package/dist/scripts/svm/queryDeposits.js +2 -2
  21. package/dist/scripts/svm/queryFills.js +10 -11
  22. package/dist/scripts/svm/remoteHubPoolPauseDeposits.js +10 -24
  23. package/dist/scripts/svm/remoteHubPoolSetDepositRoute.js +16 -29
  24. package/dist/scripts/svm/remotePauseDeposits.js +21 -27
  25. package/dist/scripts/svm/simpleFakeRelayerRepayment.js +3 -3
  26. package/dist/scripts/svm/simpleFill.js +3 -4
  27. package/dist/scripts/svm/utils/helpers.d.ts +3 -1
  28. package/dist/scripts/svm/utils/helpers.js +13 -3
  29. package/dist/src/svm/coders.d.ts +37 -0
  30. package/dist/src/svm/coders.js +250 -0
  31. package/dist/src/svm/conversionUtils.d.ts +22 -0
  32. package/dist/src/svm/conversionUtils.js +73 -0
  33. package/dist/src/svm/index.d.ts +6 -0
  34. package/dist/src/svm/index.js +22 -0
  35. package/dist/src/svm/instructionParamsUtils.d.ts +31 -0
  36. package/dist/src/svm/instructionParamsUtils.js +128 -0
  37. package/dist/src/svm/relayHashUtils.d.ts +30 -0
  38. package/dist/src/svm/relayHashUtils.js +209 -0
  39. package/dist/src/svm/solanaProgramUtils.d.ts +38 -0
  40. package/dist/src/svm/solanaProgramUtils.js +147 -0
  41. package/dist/src/svm/transactionUtils.d.ts +8 -0
  42. package/dist/src/svm/transactionUtils.js +55 -0
  43. package/dist/src/types/svm.d.ts +118 -0
  44. package/dist/src/types/svm.js +2 -0
  45. package/dist/test/svm/MulticallHandler.js +2 -2
  46. package/dist/test/svm/SvmSpoke.Bundle.js +48 -48
  47. package/dist/test/svm/SvmSpoke.Deposit.js +13 -13
  48. package/dist/test/svm/SvmSpoke.Fill.AcrossPlus.js +15 -17
  49. package/dist/test/svm/SvmSpoke.Fill.js +29 -30
  50. package/dist/test/svm/SvmSpoke.HandleReceiveMessage.js +2 -2
  51. package/dist/test/svm/SvmSpoke.Ownership.js +6 -6
  52. package/dist/test/svm/SvmSpoke.RefundClaims.js +5 -5
  53. package/dist/test/svm/SvmSpoke.Routes.js +3 -3
  54. package/dist/test/svm/SvmSpoke.SlowFill.AcrossPlus.js +19 -20
  55. package/dist/test/svm/SvmSpoke.SlowFill.js +18 -18
  56. package/dist/test/svm/SvmSpoke.TokenBridge.js +13 -13
  57. package/dist/test/svm/SvmSpoke.common.d.ts +1 -49
  58. package/dist/test/svm/SvmSpoke.common.js +4 -4
  59. package/dist/test/svm/cctpHelpers.js +2 -2
  60. package/dist/test/svm/utils.d.ts +5 -66
  61. package/dist/test/svm/utils.js +10 -226
  62. package/dist/typechain/contracts/Ink_SpokePool.d.ts +1251 -0
  63. package/dist/typechain/contracts/Ink_SpokePool.js +2 -0
  64. package/dist/typechain/contracts/index.d.ts +1 -0
  65. package/dist/typechain/factories/contracts/Ink_SpokePool__factory.d.ts +1833 -0
  66. package/dist/typechain/factories/contracts/Ink_SpokePool__factory.js +2347 -0
  67. package/dist/typechain/factories/contracts/index.d.ts +1 -0
  68. package/dist/typechain/factories/contracts/index.js +3 -1
  69. package/dist/typechain/hardhat.d.ts +9 -0
  70. package/dist/typechain/index.d.ts +2 -0
  71. package/dist/typechain/index.js +5 -3
  72. package/package.json +2 -2
  73. package/dist/src/SvmUtils.d.ts +0 -72
  74. package/dist/src/SvmUtils.js +0 -496
@@ -0,0 +1,250 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.AcrossPlusMessageCoder = exports.MulticallHandlerCoder = exports.LargeAccountsCoder = void 0;
30
+ const anchor_1 = require("@coral-xyz/anchor");
31
+ const idl_1 = require("@coral-xyz/anchor/dist/cjs/coder/borsh/idl");
32
+ const borsh = __importStar(require("@coral-xyz/borsh"));
33
+ const web3_js_1 = require("@solana/web3.js");
34
+ const bs58_1 = __importDefault(require("bs58"));
35
+ /**
36
+ * Extended Anchor accounts coder to handle large account data.
37
+ */
38
+ class LargeAccountsCoder extends anchor_1.BorshAccountsCoder {
39
+ // Getter to access the private accountLayouts property from base class.
40
+ getAccountLayouts() {
41
+ return this.accountLayouts;
42
+ }
43
+ async encode(accountName, account) {
44
+ const buffer = Buffer.alloc(10240); // We don't currently need anything above instruction data account reallocation limit.
45
+ const layout = this.getAccountLayouts().get(accountName);
46
+ if (!layout) {
47
+ throw new Error(`Unknown account: ${accountName}`);
48
+ }
49
+ const len = layout.encode(account, buffer);
50
+ const accountData = buffer.slice(0, len);
51
+ const discriminator = this.accountDiscriminator(accountName);
52
+ return Buffer.concat([discriminator, accountData]);
53
+ }
54
+ }
55
+ exports.LargeAccountsCoder = LargeAccountsCoder;
56
+ /**
57
+ * Extended version of legacy CompiledKeys to handle compilation of unsigned transactions. Base implementation is here:
58
+ * https://github.com/solana-labs/solana-web3.js/blob/v1.95.3/src/message/compiled-keys.ts
59
+ */
60
+ class UnsignedCompiledKeys {
61
+ constructor(keyModeMap, payer) {
62
+ this.keyModeMap = keyModeMap;
63
+ this.payer = payer;
64
+ }
65
+ static compileUnsigned(instructions, payer) {
66
+ const keyModeMap = new Map();
67
+ const getOrInsertDefault = (pubkey) => {
68
+ const address = pubkey.toBase58();
69
+ let keyMode = keyModeMap.get(address);
70
+ if (keyMode === undefined) {
71
+ keyMode = {
72
+ isWritable: false,
73
+ };
74
+ keyModeMap.set(address, keyMode);
75
+ }
76
+ return keyMode;
77
+ };
78
+ if (payer !== undefined) {
79
+ const payerKeyMode = getOrInsertDefault(payer);
80
+ payerKeyMode.isWritable = true;
81
+ }
82
+ for (const ix of instructions) {
83
+ getOrInsertDefault(ix.programId);
84
+ for (const accountMeta of ix.keys) {
85
+ const keyMode = getOrInsertDefault(accountMeta.pubkey);
86
+ keyMode.isWritable ||= accountMeta.isWritable;
87
+ }
88
+ }
89
+ return new UnsignedCompiledKeys(keyModeMap, payer);
90
+ }
91
+ getMessageComponents() {
92
+ const mapEntries = [...this.keyModeMap.entries()];
93
+ if (mapEntries.length > 256)
94
+ throw new Error("Max static account keys length exceeded");
95
+ const writableNonSigners = mapEntries.filter(([, mode]) => mode.isWritable);
96
+ const readonlyNonSigners = mapEntries.filter(([, mode]) => !mode.isWritable);
97
+ const header = {
98
+ numRequiredSignatures: 0,
99
+ numReadonlySignedAccounts: 0,
100
+ numReadonlyUnsignedAccounts: readonlyNonSigners.length,
101
+ };
102
+ const staticAccountKeys = [
103
+ ...writableNonSigners.map(([address]) => new web3_js_1.PublicKey(address)),
104
+ ...readonlyNonSigners.map(([address]) => new web3_js_1.PublicKey(address)),
105
+ ];
106
+ return [header, staticAccountKeys];
107
+ }
108
+ }
109
+ /**
110
+ * Extended version of legacy Message to handle compilation of unsigned transactions. Base implementation is here:
111
+ * https://github.com/solana-labs/solana-web3.js/blob/v1.95.3/src/message/legacy.ts
112
+ */
113
+ class UnsignedMessage extends web3_js_1.Message {
114
+ static compileUnsigned(instructions, payer) {
115
+ const compiledKeys = UnsignedCompiledKeys.compileUnsigned(instructions, payer);
116
+ const [header, staticAccountKeys] = compiledKeys.getMessageComponents();
117
+ const accountKeys = new web3_js_1.MessageAccountKeys(staticAccountKeys);
118
+ const compiledInstructions = accountKeys.compileInstructions(instructions).map((ix) => ({
119
+ programIdIndex: ix.programIdIndex,
120
+ accounts: ix.accountKeyIndexes,
121
+ data: bs58_1.default.encode(ix.data),
122
+ }));
123
+ return new web3_js_1.Message({
124
+ header,
125
+ accountKeys: staticAccountKeys,
126
+ recentBlockhash: "", // Not used as we are not signing the transaction.
127
+ instructions: compiledInstructions,
128
+ });
129
+ }
130
+ }
131
+ /**
132
+ * Helper to encode MulticallHandler transactions.
133
+ */
134
+ class MulticallHandlerCoder {
135
+ constructor(instructions, payerKey) {
136
+ // Compile transaction message and keys.
137
+ this.compiledMessage = UnsignedMessage.compileUnsigned(instructions, payerKey);
138
+ // Setup the layout for the encoder.
139
+ const fieldLayouts = [idl_1.IdlCoder.fieldLayout(MulticallHandlerCoder.coderArg, MulticallHandlerCoder.coderTypes)];
140
+ this.layout = borsh.struct(fieldLayouts);
141
+ }
142
+ get readOnlyLen() {
143
+ return (this.compiledMessage.header.numReadonlySignedAccounts + this.compiledMessage.header.numReadonlyUnsignedAccounts);
144
+ }
145
+ get compiledKeyMetas() {
146
+ return this.compiledMessage.accountKeys.map((key, index) => {
147
+ return {
148
+ pubkey: key,
149
+ isSigner: this.compiledMessage.isAccountSigner(index),
150
+ isWritable: this.compiledMessage.isAccountWritable(index),
151
+ };
152
+ });
153
+ }
154
+ encode() {
155
+ const buffer = Buffer.alloc(1280);
156
+ const len = this.layout.encode({ compiledIxs: this.compiledMessage.compiledInstructions }, buffer);
157
+ return buffer.slice(0, len);
158
+ }
159
+ }
160
+ exports.MulticallHandlerCoder = MulticallHandlerCoder;
161
+ MulticallHandlerCoder.coderArg = {
162
+ name: "compiledIxs",
163
+ type: {
164
+ vec: {
165
+ defined: {
166
+ name: "compiledIx",
167
+ },
168
+ },
169
+ },
170
+ };
171
+ MulticallHandlerCoder.coderTypes = [
172
+ {
173
+ name: "compiledIx",
174
+ type: {
175
+ kind: "struct",
176
+ fields: [
177
+ {
178
+ name: "programIdIndex",
179
+ type: "u8",
180
+ },
181
+ {
182
+ name: "accountKeyIndexes",
183
+ type: {
184
+ vec: "u8",
185
+ },
186
+ },
187
+ {
188
+ name: "data",
189
+ type: "bytes",
190
+ },
191
+ ],
192
+ },
193
+ },
194
+ ];
195
+ /**
196
+ * Helper to encode Across+ messages.
197
+ */
198
+ class AcrossPlusMessageCoder {
199
+ constructor(acrossPlusMessage) {
200
+ this.acrossPlusMessage = acrossPlusMessage;
201
+ }
202
+ encode() {
203
+ const fieldLayouts = [idl_1.IdlCoder.fieldLayout(AcrossPlusMessageCoder.coderArg, AcrossPlusMessageCoder.coderTypes)];
204
+ const layout = borsh.struct(fieldLayouts);
205
+ const buffer = Buffer.alloc(12800);
206
+ const len = layout.encode({ message: this.acrossPlusMessage }, buffer);
207
+ return buffer.slice(0, len);
208
+ }
209
+ }
210
+ exports.AcrossPlusMessageCoder = AcrossPlusMessageCoder;
211
+ AcrossPlusMessageCoder.coderArg = {
212
+ name: "message",
213
+ type: {
214
+ defined: {
215
+ name: "acrossPlusMessage",
216
+ },
217
+ },
218
+ };
219
+ AcrossPlusMessageCoder.coderTypes = [
220
+ {
221
+ name: "acrossPlusMessage",
222
+ type: {
223
+ kind: "struct",
224
+ fields: [
225
+ {
226
+ name: "handler",
227
+ type: "pubkey",
228
+ },
229
+ {
230
+ name: "readOnlyLen",
231
+ type: "u8",
232
+ },
233
+ {
234
+ name: "valueAmount",
235
+ type: "u64",
236
+ },
237
+ {
238
+ name: "accounts",
239
+ type: {
240
+ vec: "pubkey",
241
+ },
242
+ },
243
+ {
244
+ name: "handlerMessage",
245
+ type: "bytes",
246
+ },
247
+ ],
248
+ },
249
+ },
250
+ ];
@@ -0,0 +1,22 @@
1
+ import { BN } from "@coral-xyz/anchor";
2
+ import { PublicKey } from "@solana/web3.js";
3
+ /**
4
+ * Converts an integer to a 32-byte Uint8Array.
5
+ */
6
+ export declare function intToU8Array32(num: number | BN): number[];
7
+ /**
8
+ * Converts a 32-byte Uint8Array to a bigint.
9
+ */
10
+ export declare function u8Array32ToInt(u8Array: Uint8Array | number[]): bigint;
11
+ /**
12
+ * Converts a string to a PublicKey.
13
+ */
14
+ export declare function strPublicKey(publicKey: PublicKey): string;
15
+ /**
16
+ * Converts an EVM address to a Solana PublicKey.
17
+ */
18
+ export declare const evmAddressToPublicKey: (address: string) => PublicKey;
19
+ /**
20
+ * Converts a Solana PublicKey to an EVM address.
21
+ */
22
+ export declare const publicKeyToEvmAddress: (publicKey: PublicKey | string) => string;
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.publicKeyToEvmAddress = exports.evmAddressToPublicKey = void 0;
4
+ exports.intToU8Array32 = intToU8Array32;
5
+ exports.u8Array32ToInt = u8Array32ToInt;
6
+ exports.strPublicKey = strPublicKey;
7
+ const anchor_1 = require("@coral-xyz/anchor");
8
+ const web3_js_1 = require("@solana/web3.js");
9
+ const ethers_1 = require("ethers");
10
+ /**
11
+ * Converts an integer to a 32-byte Uint8Array.
12
+ */
13
+ function intToU8Array32(num) {
14
+ let bigIntValue;
15
+ if (typeof num === "number") {
16
+ if (!Number.isInteger(num) || num < 0) {
17
+ throw new Error("Input must be a non-negative integer");
18
+ }
19
+ bigIntValue = BigInt(num);
20
+ }
21
+ else if (anchor_1.BN.isBN(num)) {
22
+ if (num.isNeg()) {
23
+ throw new Error("Input must be a non-negative BN");
24
+ }
25
+ bigIntValue = BigInt(num.toString());
26
+ }
27
+ else {
28
+ throw new Error("Input must be a non-negative integer or BN");
29
+ }
30
+ const u8Array = new Array(32).fill(0);
31
+ let i = 0;
32
+ while (bigIntValue > 0 && i < 32) {
33
+ u8Array[i++] = Number(bigIntValue & 0xffn); // Get least significant byte
34
+ bigIntValue >>= 8n; // Shift right by 8 bits
35
+ }
36
+ return u8Array;
37
+ }
38
+ /**
39
+ * Converts a 32-byte Uint8Array to a bigint.
40
+ */
41
+ function u8Array32ToInt(u8Array) {
42
+ const isValidArray = (arr) => Array.isArray(arr) && arr.every(Number.isInteger);
43
+ if ((u8Array instanceof Uint8Array || isValidArray(u8Array)) && u8Array.length === 32) {
44
+ return Array.from(u8Array).reduce((num, byte, i) => num | (BigInt(byte) << BigInt(i * 8)), 0n);
45
+ }
46
+ throw new Error("Input must be a Uint8Array or an array of 32 numbers.");
47
+ }
48
+ /**
49
+ * Converts a string to a PublicKey.
50
+ */
51
+ function strPublicKey(publicKey) {
52
+ return new web3_js_1.PublicKey(publicKey).toString();
53
+ }
54
+ /**
55
+ * Converts an EVM address to a Solana PublicKey.
56
+ */
57
+ const evmAddressToPublicKey = (address) => {
58
+ const bytes32Address = `0x000000000000000000000000${address.replace("0x", "")}`;
59
+ return new web3_js_1.PublicKey(ethers_1.ethers.utils.arrayify(bytes32Address));
60
+ };
61
+ exports.evmAddressToPublicKey = evmAddressToPublicKey;
62
+ /**
63
+ * Converts a Solana PublicKey to an EVM address.
64
+ */
65
+ const publicKeyToEvmAddress = (publicKey) => {
66
+ // Convert the input to a PublicKey if it's a string
67
+ const pubKeyBuffer = typeof publicKey === "string" ? new web3_js_1.PublicKey(publicKey).toBuffer() : publicKey.toBuffer();
68
+ // Extract the last 20 bytes to get the Ethereum address
69
+ const addressBuffer = pubKeyBuffer.slice(-20);
70
+ // Convert the buffer to a hex string and prepend '0x'
71
+ return `0x${addressBuffer.toString("hex")}`;
72
+ };
73
+ exports.publicKeyToEvmAddress = publicKeyToEvmAddress;
@@ -0,0 +1,6 @@
1
+ export * from "./relayHashUtils";
2
+ export * from "./instructionParamsUtils";
3
+ export * from "./conversionUtils";
4
+ export * from "./transactionUtils";
5
+ export * from "./solanaProgramUtils";
6
+ export * from "./coders";
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./relayHashUtils"), exports);
18
+ __exportStar(require("./instructionParamsUtils"), exports);
19
+ __exportStar(require("./conversionUtils"), exports);
20
+ __exportStar(require("./transactionUtils"), exports);
21
+ __exportStar(require("./solanaProgramUtils"), exports);
22
+ __exportStar(require("./coders"), exports);
@@ -0,0 +1,31 @@
1
+ import { Keypair, TransactionInstruction, PublicKey } from "@solana/web3.js";
2
+ import { Program, BN } from "@coral-xyz/anchor";
3
+ import { RelayData, SlowFillLeaf, RelayerRefundLeafSolana } from "../types/svm";
4
+ import { SvmSpoke } from "../../target/types/svm_spoke";
5
+ /**
6
+ * Loads execute relayer refund leaf parameters.
7
+ */
8
+ export declare function loadExecuteRelayerRefundLeafParams(program: Program<SvmSpoke>, caller: PublicKey, rootBundleId: number, relayerRefundLeaf: RelayerRefundLeafSolana, proof: number[][]): Promise<PublicKey>;
9
+ /**
10
+ * Closes the instruction parameters account.
11
+ */
12
+ export declare function closeInstructionParams(program: Program<SvmSpoke>, signer: Keypair): Promise<void>;
13
+ /**
14
+ * Creates instructions to load fillV3 relay parameters.
15
+ */
16
+ export declare function createFillV3RelayParamsInstructions(program: Program<SvmSpoke>, signer: PublicKey, relayData: RelayData, repaymentChainId: BN, repaymentAddress: PublicKey): Promise<{
17
+ loadInstructions: TransactionInstruction[];
18
+ closeInstruction: TransactionInstruction;
19
+ }>;
20
+ /**
21
+ * Loads fillV3 relay parameters.
22
+ */
23
+ export declare function loadFillV3RelayParams(program: Program<SvmSpoke>, signer: Keypair, relayData: RelayData, repaymentChainId: BN, repaymentAddress: PublicKey): Promise<void>;
24
+ /**
25
+ * Loads requestV3 slow fill parameters.
26
+ */
27
+ export declare function loadRequestV3SlowFillParams(program: Program<SvmSpoke>, signer: Keypair, relayData: RelayData): Promise<TransactionInstruction[]>;
28
+ /**
29
+ * Loads executeV3 slow relay leaf parameters.
30
+ */
31
+ export declare function loadExecuteV3SlowRelayLeafParams(program: Program<SvmSpoke>, signer: Keypair, slowFillLeaf: SlowFillLeaf, rootBundleId: number, proof: number[][]): Promise<TransactionInstruction[]>;
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadExecuteRelayerRefundLeafParams = loadExecuteRelayerRefundLeafParams;
4
+ exports.closeInstructionParams = closeInstructionParams;
5
+ exports.createFillV3RelayParamsInstructions = createFillV3RelayParamsInstructions;
6
+ exports.loadFillV3RelayParams = loadFillV3RelayParams;
7
+ exports.loadRequestV3SlowFillParams = loadRequestV3SlowFillParams;
8
+ exports.loadExecuteV3SlowRelayLeafParams = loadExecuteV3SlowRelayLeafParams;
9
+ const web3_js_1 = require("@solana/web3.js");
10
+ const coders_1 = require("./coders");
11
+ /**
12
+ * Loads execute relayer refund leaf parameters.
13
+ */
14
+ async function loadExecuteRelayerRefundLeafParams(program, caller, rootBundleId, relayerRefundLeaf, proof) {
15
+ const maxInstructionParamsFragment = 900; // Should not exceed message size limit when writing to the data account.
16
+ // Close the instruction params account if the caller has used it before.
17
+ const [instructionParams] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("instruction_params"), caller.toBuffer()], program.programId);
18
+ const accountInfo = await program.provider.connection.getAccountInfo(instructionParams);
19
+ if (accountInfo !== null)
20
+ await program.methods.closeInstructionParams().rpc();
21
+ const accountCoder = new coders_1.LargeAccountsCoder(program.idl);
22
+ const instructionParamsBytes = await accountCoder.encode("executeRelayerRefundLeafParams", {
23
+ rootBundleId,
24
+ relayerRefundLeaf,
25
+ proof,
26
+ });
27
+ await program.methods.initializeInstructionParams(instructionParamsBytes.length).rpc();
28
+ for (let i = 0; i < instructionParamsBytes.length; i += maxInstructionParamsFragment) {
29
+ const fragment = instructionParamsBytes.slice(i, i + maxInstructionParamsFragment);
30
+ await program.methods.writeInstructionParamsFragment(i, fragment).rpc();
31
+ }
32
+ return instructionParams;
33
+ }
34
+ /**
35
+ * Closes the instruction parameters account.
36
+ */
37
+ async function closeInstructionParams(program, signer) {
38
+ const [instructionParams] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("instruction_params"), signer.publicKey.toBuffer()], program.programId);
39
+ const accountInfo = await program.provider.connection.getAccountInfo(instructionParams);
40
+ if (accountInfo !== null) {
41
+ const closeIx = await program.methods.closeInstructionParams().accounts({ signer: signer.publicKey }).instruction();
42
+ await (0, web3_js_1.sendAndConfirmTransaction)(program.provider.connection, new web3_js_1.Transaction().add(closeIx), [signer]);
43
+ }
44
+ }
45
+ /**
46
+ * Creates instructions to load fillV3 relay parameters.
47
+ */
48
+ async function createFillV3RelayParamsInstructions(program, signer, relayData, repaymentChainId, repaymentAddress) {
49
+ const maxInstructionParamsFragment = 900; // Should not exceed message size limit when writing to the data account.
50
+ const accountCoder = new coders_1.LargeAccountsCoder(program.idl);
51
+ const instructionParamsBytes = await accountCoder.encode("fillV3RelayParams", {
52
+ relayData,
53
+ repaymentChainId,
54
+ repaymentAddress,
55
+ });
56
+ const loadInstructions = [];
57
+ loadInstructions.push(await program.methods.initializeInstructionParams(instructionParamsBytes.length).accounts({ signer }).instruction());
58
+ for (let i = 0; i < instructionParamsBytes.length; i += maxInstructionParamsFragment) {
59
+ const fragment = instructionParamsBytes.slice(i, i + maxInstructionParamsFragment);
60
+ loadInstructions.push(await program.methods.writeInstructionParamsFragment(i, fragment).accounts({ signer }).instruction());
61
+ }
62
+ const closeInstruction = await program.methods.closeInstructionParams().accounts({ signer }).instruction();
63
+ return { loadInstructions, closeInstruction };
64
+ }
65
+ /**
66
+ * Loads fillV3 relay parameters.
67
+ */
68
+ async function loadFillV3RelayParams(program, signer, relayData, repaymentChainId, repaymentAddress) {
69
+ // Close the instruction params account if the caller has used it before.
70
+ await closeInstructionParams(program, signer);
71
+ // Execute load instructions sequentially.
72
+ const { loadInstructions } = await createFillV3RelayParamsInstructions(program, signer.publicKey, relayData, repaymentChainId, repaymentAddress);
73
+ for (let i = 0; i < loadInstructions.length; i += 1) {
74
+ await (0, web3_js_1.sendAndConfirmTransaction)(program.provider.connection, new web3_js_1.Transaction().add(loadInstructions[i]), [signer]);
75
+ }
76
+ }
77
+ /**
78
+ * Loads requestV3 slow fill parameters.
79
+ */
80
+ async function loadRequestV3SlowFillParams(program, signer, relayData) {
81
+ // Close the instruction params account if the caller has used it before.
82
+ await closeInstructionParams(program, signer);
83
+ // Execute load instructions sequentially.
84
+ const maxInstructionParamsFragment = 900; // Should not exceed message size limit when writing to the data account.
85
+ const accountCoder = new coders_1.LargeAccountsCoder(program.idl);
86
+ const instructionParamsBytes = await accountCoder.encode("requestV3SlowFillParams", { relayData });
87
+ const loadInstructions = [];
88
+ loadInstructions.push(await program.methods
89
+ .initializeInstructionParams(instructionParamsBytes.length)
90
+ .accounts({ signer: signer.publicKey })
91
+ .instruction());
92
+ for (let i = 0; i < instructionParamsBytes.length; i += maxInstructionParamsFragment) {
93
+ const fragment = instructionParamsBytes.slice(i, i + maxInstructionParamsFragment);
94
+ loadInstructions.push(await program.methods
95
+ .writeInstructionParamsFragment(i, fragment)
96
+ .accounts({ signer: signer.publicKey })
97
+ .instruction());
98
+ }
99
+ return loadInstructions;
100
+ }
101
+ /**
102
+ * Loads executeV3 slow relay leaf parameters.
103
+ */
104
+ async function loadExecuteV3SlowRelayLeafParams(program, signer, slowFillLeaf, rootBundleId, proof) {
105
+ // Close the instruction params account if the caller has used it before.
106
+ await closeInstructionParams(program, signer);
107
+ // Execute load instructions sequentially.
108
+ const maxInstructionParamsFragment = 900; // Should not exceed message size limit when writing to the data account.
109
+ const accountCoder = new coders_1.LargeAccountsCoder(program.idl);
110
+ const instructionParamsBytes = await accountCoder.encode("executeV3SlowRelayLeafParams", {
111
+ slowFillLeaf,
112
+ rootBundleId,
113
+ proof,
114
+ });
115
+ const loadInstructions = [];
116
+ loadInstructions.push(await program.methods
117
+ .initializeInstructionParams(instructionParamsBytes.length)
118
+ .accounts({ signer: signer.publicKey })
119
+ .instruction());
120
+ for (let i = 0; i < instructionParamsBytes.length; i += maxInstructionParamsFragment) {
121
+ const fragment = instructionParamsBytes.slice(i, i + maxInstructionParamsFragment);
122
+ loadInstructions.push(await program.methods
123
+ .writeInstructionParamsFragment(i, fragment)
124
+ .accounts({ signer: signer.publicKey })
125
+ .instruction());
126
+ }
127
+ return loadInstructions;
128
+ }
@@ -0,0 +1,30 @@
1
+ import { BN } from "@coral-xyz/anchor";
2
+ import { RelayerRefundLeaf, RelayerRefundLeafSolana, SlowFillLeaf } from "../types/svm";
3
+ /**
4
+ * Calculates the relay hash from relay data and chain ID.
5
+ */
6
+ export declare function calculateRelayHashUint8Array(relayData: any, chainId: BN): Uint8Array;
7
+ /**
8
+ * Calculates the relay event hash from relay event data and chain ID.
9
+ */
10
+ export declare function calculateRelayEventHashUint8Array(relayEventData: any, chainId: BN): Uint8Array;
11
+ /**
12
+ * Reads a 256-bit unsigned integer from a buffer.
13
+ */
14
+ export declare const readUInt256BE: (buffer: Buffer) => BigInt;
15
+ /**
16
+ * Hashes a non-empty message using Keccak256.
17
+ */
18
+ export declare function hashNonEmptyMessage(message: Buffer): Uint8Array;
19
+ /**
20
+ * Calculates the relayer refund leaf hash for Solana.
21
+ */
22
+ export declare function calculateRelayerRefundLeafHashUint8Array(relayData: RelayerRefundLeafSolana): string;
23
+ /**
24
+ * Hash function for relayer refund leaves.
25
+ */
26
+ export declare const relayerRefundHashFn: (input: RelayerRefundLeaf | RelayerRefundLeafSolana) => string;
27
+ /**
28
+ * Hash function for slow fill leaves.
29
+ */
30
+ export declare function slowFillHashFn(slowFillLeaf: SlowFillLeaf): string;