@across-protocol/contracts 3.0.17 → 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 (95) 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.d.ts +1 -0
  10. package/dist/scripts/svm/addressToPublicKey.js +20 -0
  11. package/dist/scripts/svm/bridgeLiabilityToHubPool.d.ts +25 -0
  12. package/dist/scripts/svm/bridgeLiabilityToHubPool.js +221 -0
  13. package/dist/scripts/svm/closeRelayerPdas.js +8 -9
  14. package/dist/scripts/svm/enableRoute.js +7 -1
  15. package/dist/scripts/svm/executeRebalanceToHubPool.d.ts +29 -0
  16. package/dist/scripts/svm/executeRebalanceToHubPool.js +345 -0
  17. package/dist/scripts/svm/executeRebalanceToSpokePool.d.ts +1 -0
  18. package/dist/scripts/svm/executeRebalanceToSpokePool.js +240 -0
  19. package/dist/scripts/svm/fakeFillWithRandomDistribution.js +6 -7
  20. package/dist/scripts/svm/initialize.js +2 -2
  21. package/dist/scripts/svm/proposeRebalanceToHubPool.d.ts +27 -0
  22. package/dist/scripts/svm/proposeRebalanceToHubPool.js +117 -0
  23. package/dist/scripts/svm/proposeRebalanceToSpokePool.d.ts +1 -0
  24. package/dist/scripts/svm/proposeRebalanceToSpokePool.js +97 -0
  25. package/dist/scripts/svm/publicKeyToAddress.d.ts +1 -0
  26. package/dist/scripts/svm/publicKeyToAddress.js +20 -0
  27. package/dist/scripts/svm/queryDeposits.js +3 -2
  28. package/dist/scripts/svm/queryFills.js +12 -14
  29. package/dist/scripts/svm/queryRoute.js +7 -1
  30. package/dist/scripts/svm/queryState.js +1 -0
  31. package/dist/scripts/svm/remoteHubPoolPauseDeposits.d.ts +1 -0
  32. package/dist/scripts/svm/remoteHubPoolPauseDeposits.js +191 -0
  33. package/dist/scripts/svm/remoteHubPoolSetDepositRoute.js +16 -29
  34. package/dist/scripts/svm/remotePauseDeposits.js +21 -27
  35. package/dist/scripts/svm/simpleDeposit.js +7 -1
  36. package/dist/scripts/svm/simpleFakeRelayerRepayment.js +3 -3
  37. package/dist/scripts/svm/simpleFill.js +6 -6
  38. package/dist/scripts/svm/utils/constants.d.ts +4 -0
  39. package/dist/scripts/svm/utils/constants.js +8 -1
  40. package/dist/scripts/svm/utils/helpers.d.ts +33 -0
  41. package/dist/scripts/svm/utils/helpers.js +60 -1
  42. package/dist/scripts/svm/utils/poolRebalanceTree.d.ts +22 -0
  43. package/dist/scripts/svm/utils/poolRebalanceTree.js +20 -0
  44. package/dist/src/svm/coders.d.ts +37 -0
  45. package/dist/src/svm/coders.js +250 -0
  46. package/dist/src/svm/conversionUtils.d.ts +22 -0
  47. package/dist/src/svm/conversionUtils.js +73 -0
  48. package/dist/src/svm/index.d.ts +6 -0
  49. package/dist/src/svm/index.js +22 -0
  50. package/dist/src/svm/instructionParamsUtils.d.ts +31 -0
  51. package/dist/src/svm/instructionParamsUtils.js +128 -0
  52. package/dist/src/svm/relayHashUtils.d.ts +30 -0
  53. package/dist/src/svm/relayHashUtils.js +209 -0
  54. package/dist/src/svm/solanaProgramUtils.d.ts +38 -0
  55. package/dist/src/svm/solanaProgramUtils.js +147 -0
  56. package/dist/src/svm/transactionUtils.d.ts +8 -0
  57. package/dist/src/svm/transactionUtils.js +55 -0
  58. package/dist/src/types/svm.d.ts +118 -0
  59. package/dist/src/types/svm.js +2 -0
  60. package/dist/target/types/svm_spoke.d.ts +47 -42
  61. package/dist/tasks/enableL1TokenAcrossEcosystem.js +3 -33
  62. package/dist/tasks/types.d.ts +2 -0
  63. package/dist/tasks/types.js +2 -0
  64. package/dist/tasks/utils.d.ts +12 -0
  65. package/dist/tasks/utils.js +34 -0
  66. package/dist/test/svm/MulticallHandler.js +2 -2
  67. package/dist/test/svm/SvmSpoke.Bundle.js +59 -60
  68. package/dist/test/svm/SvmSpoke.Deposit.js +23 -31
  69. package/dist/test/svm/SvmSpoke.Fill.AcrossPlus.js +16 -18
  70. package/dist/test/svm/SvmSpoke.Fill.js +38 -40
  71. package/dist/test/svm/SvmSpoke.HandleReceiveMessage.js +2 -2
  72. package/dist/test/svm/SvmSpoke.Ownership.js +11 -17
  73. package/dist/test/svm/SvmSpoke.RefundClaims.js +12 -11
  74. package/dist/test/svm/SvmSpoke.Routes.js +11 -7
  75. package/dist/test/svm/SvmSpoke.SlowFill.AcrossPlus.js +72 -16
  76. package/dist/test/svm/SvmSpoke.SlowFill.js +33 -28
  77. package/dist/test/svm/SvmSpoke.TokenBridge.js +15 -17
  78. package/dist/test/svm/SvmSpoke.common.d.ts +1 -49
  79. package/dist/test/svm/SvmSpoke.common.js +6 -5
  80. package/dist/test/svm/cctpHelpers.js +2 -2
  81. package/dist/test/svm/utils.d.ts +5 -67
  82. package/dist/test/svm/utils.js +10 -220
  83. package/dist/typechain/contracts/Ink_SpokePool.d.ts +1251 -0
  84. package/dist/typechain/contracts/Ink_SpokePool.js +2 -0
  85. package/dist/typechain/contracts/index.d.ts +1 -0
  86. package/dist/typechain/factories/contracts/Ink_SpokePool__factory.d.ts +1833 -0
  87. package/dist/typechain/factories/contracts/Ink_SpokePool__factory.js +2347 -0
  88. package/dist/typechain/factories/contracts/index.d.ts +1 -0
  89. package/dist/typechain/factories/contracts/index.js +3 -1
  90. package/dist/typechain/hardhat.d.ts +9 -0
  91. package/dist/typechain/index.d.ts +2 -0
  92. package/dist/typechain/index.js +5 -3
  93. package/package.json +2 -2
  94. package/dist/src/SvmUtils.d.ts +0 -50
  95. package/dist/src/SvmUtils.js +0 -415
@@ -1,42 +1,13 @@
1
- import { BN, Program } from "@coral-xyz/anchor";
2
- import { AccountMeta, Keypair, PublicKey, TransactionInstruction } from "@solana/web3.js";
1
+ import { BN } from "@coral-xyz/anchor";
2
+ import { AccountMeta, PublicKey } from "@solana/web3.js";
3
3
  import { BigNumber } from "ethers";
4
- import { SvmSpoke } from "../../target/types/svm_spoke";
5
- import { readEvents, readProgramEvents, calculateRelayHashUint8Array, findProgramAddress } from "../../src/SvmUtils";
4
+ import { calculateRelayHashUint8Array, findProgramAddress, readEvents, readProgramEvents } from "../../src/svm";
6
5
  import { MerkleTree } from "@uma/common";
7
- import { RelayData } from "./SvmSpoke.common";
8
- export { readEvents, readProgramEvents, calculateRelayHashUint8Array, findProgramAddress };
6
+ import { RelayerRefundLeafType } from "../../src/types/svm";
7
+ export { calculateRelayHashUint8Array, findProgramAddress, readEvents, readProgramEvents };
9
8
  export declare function printLogs(connection: any, program: any, tx: any): Promise<void>;
10
9
  export declare function randomAddress(): string;
11
10
  export declare function randomBigInt(bytes?: number, signed?: boolean): bigint;
12
- export interface RelayerRefundLeaf {
13
- isSolana: boolean;
14
- amountToReturn: BigNumber;
15
- chainId: BigNumber;
16
- refundAmounts: BigNumber[];
17
- leafId: BigNumber;
18
- l2TokenAddress: string;
19
- refundAddresses: string[];
20
- }
21
- export interface RelayerRefundLeafSolana {
22
- isSolana: boolean;
23
- amountToReturn: BN;
24
- chainId: BN;
25
- refundAmounts: BN[];
26
- leafId: BN;
27
- mintPublicKey: PublicKey;
28
- refundAddresses: PublicKey[];
29
- }
30
- export type RelayerRefundLeafType = RelayerRefundLeaf | RelayerRefundLeafSolana;
31
- export declare function convertLeafIdToNumber(leaf: RelayerRefundLeafSolana): {
32
- leafId: number;
33
- isSolana: boolean;
34
- amountToReturn: BN;
35
- chainId: BN;
36
- refundAmounts: BN[];
37
- mintPublicKey: PublicKey;
38
- refundAddresses: PublicKey[];
39
- };
40
11
  export declare function buildRelayerRefundMerkleTree({ totalEvmDistributions, totalSolanaDistributions, mixLeaves, chainId, mint, svmRelayers, evmRelayers, evmTokenAddress, evmRefundAmounts, svmRefundAmounts, }: {
41
12
  totalEvmDistributions: number;
42
13
  totalSolanaDistributions: number;
@@ -52,40 +23,7 @@ export declare function buildRelayerRefundMerkleTree({ totalEvmDistributions, to
52
23
  relayerRefundLeaves: RelayerRefundLeafType[];
53
24
  merkleTree: MerkleTree<RelayerRefundLeafType>;
54
25
  };
55
- export declare function calculateRelayerRefundLeafHashUint8Array(relayData: RelayerRefundLeafSolana): string;
56
- export declare const relayerRefundHashFn: (input: RelayerRefundLeaf | RelayerRefundLeafSolana) => string;
57
- export interface SlowFillLeaf {
58
- relayData: {
59
- depositor: PublicKey;
60
- recipient: PublicKey;
61
- exclusiveRelayer: PublicKey;
62
- inputToken: PublicKey;
63
- outputToken: PublicKey;
64
- inputAmount: BN;
65
- outputAmount: BN;
66
- originChainId: BN;
67
- depositId: number[];
68
- fillDeadline: number;
69
- exclusivityDeadline: number;
70
- message: Buffer;
71
- };
72
- chainId: BN;
73
- updatedOutputAmount: BN;
74
- }
75
- export declare function slowFillHashFn(slowFillLeaf: SlowFillLeaf): string;
76
- export declare function loadExecuteRelayerRefundLeafParams(program: Program<SvmSpoke>, caller: PublicKey, rootBundleId: number, relayerRefundLeaf: RelayerRefundLeafSolana, proof: number[][]): Promise<PublicKey>;
77
- export declare function closeInstructionParams(program: Program<SvmSpoke>, signer: Keypair): Promise<void>;
78
- export declare function createFillV3RelayParamsInstructions(program: Program<SvmSpoke>, signer: PublicKey, relayData: RelayData, repaymentChainId: BN, repaymentAddress: PublicKey): Promise<{
79
- loadInstructions: TransactionInstruction[];
80
- closeInstruction: TransactionInstruction;
81
- }>;
82
- export declare function loadFillV3RelayParams(program: Program<SvmSpoke>, signer: Keypair, relayData: RelayData, repaymentChainId: BN, repaymentAddress: PublicKey): Promise<void>;
83
- export declare function loadRequestV3SlowFillParams(program: Program<SvmSpoke>, signer: Keypair, relayData: RelayData): Promise<TransactionInstruction[]>;
84
- export declare function loadExecuteV3SlowRelayLeafParams(program: Program<SvmSpoke>, signer: Keypair, slowFillLeaf: SlowFillLeaf, rootBundleId: number, proof: number[][]): Promise<TransactionInstruction[]>;
85
- export declare function intToU8Array32(num: number): number[];
86
- export declare function u8Array32ToInt(u8Array: Uint8Array): bigint;
87
26
  export declare function testAcrossPlusMessage(): {
88
27
  encodedMessage: Buffer;
89
28
  fillRemainingAccounts: AccountMeta[];
90
29
  };
91
- export declare function hashNonEmptyMessage(message: Buffer): Uint8Array;
@@ -23,33 +23,21 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.relayerRefundHashFn = exports.findProgramAddress = exports.calculateRelayHashUint8Array = exports.readProgramEvents = exports.readEvents = void 0;
26
+ exports.readProgramEvents = exports.readEvents = exports.findProgramAddress = exports.calculateRelayHashUint8Array = void 0;
27
27
  exports.printLogs = printLogs;
28
28
  exports.randomAddress = randomAddress;
29
29
  exports.randomBigInt = randomBigInt;
30
- exports.convertLeafIdToNumber = convertLeafIdToNumber;
31
30
  exports.buildRelayerRefundMerkleTree = buildRelayerRefundMerkleTree;
32
- exports.calculateRelayerRefundLeafHashUint8Array = calculateRelayerRefundLeafHashUint8Array;
33
- exports.slowFillHashFn = slowFillHashFn;
34
- exports.loadExecuteRelayerRefundLeafParams = loadExecuteRelayerRefundLeafParams;
35
- exports.closeInstructionParams = closeInstructionParams;
36
- exports.createFillV3RelayParamsInstructions = createFillV3RelayParamsInstructions;
37
- exports.loadFillV3RelayParams = loadFillV3RelayParams;
38
- exports.loadRequestV3SlowFillParams = loadRequestV3SlowFillParams;
39
- exports.loadExecuteV3SlowRelayLeafParams = loadExecuteV3SlowRelayLeafParams;
40
- exports.intToU8Array32 = intToU8Array32;
41
- exports.u8Array32ToInt = u8Array32ToInt;
42
31
  exports.testAcrossPlusMessage = testAcrossPlusMessage;
43
- exports.hashNonEmptyMessage = hashNonEmptyMessage;
44
32
  const anchor_1 = require("@coral-xyz/anchor");
45
33
  const web3_js_1 = require("@solana/web3.js");
46
- const ethers_1 = require("ethers");
47
34
  const crypto = __importStar(require("crypto"));
48
- const SvmUtils_1 = require("../../src/SvmUtils");
49
- Object.defineProperty(exports, "readEvents", { enumerable: true, get: function () { return SvmUtils_1.readEvents; } });
50
- Object.defineProperty(exports, "readProgramEvents", { enumerable: true, get: function () { return SvmUtils_1.readProgramEvents; } });
51
- Object.defineProperty(exports, "calculateRelayHashUint8Array", { enumerable: true, get: function () { return SvmUtils_1.calculateRelayHashUint8Array; } });
52
- Object.defineProperty(exports, "findProgramAddress", { enumerable: true, get: function () { return SvmUtils_1.findProgramAddress; } });
35
+ const ethers_1 = require("ethers");
36
+ const svm_1 = require("../../src/svm");
37
+ Object.defineProperty(exports, "calculateRelayHashUint8Array", { enumerable: true, get: function () { return svm_1.calculateRelayHashUint8Array; } });
38
+ Object.defineProperty(exports, "findProgramAddress", { enumerable: true, get: function () { return svm_1.findProgramAddress; } });
39
+ Object.defineProperty(exports, "readEvents", { enumerable: true, get: function () { return svm_1.readEvents; } });
40
+ Object.defineProperty(exports, "readProgramEvents", { enumerable: true, get: function () { return svm_1.readProgramEvents; } });
53
41
  const common_1 = require("@uma/common");
54
42
  async function printLogs(connection, program, tx) {
55
43
  const latestBlockHash = await connection.getLatestBlockhash();
@@ -76,9 +64,6 @@ function randomBigInt(bytes = 8, signed = false) {
76
64
  const byteString = "0x" + Buffer.from(crypto.randomBytes(bytes)).toString("hex");
77
65
  return BigInt(sign + byteString);
78
66
  }
79
- function convertLeafIdToNumber(leaf) {
80
- return { ...leaf, leafId: leaf.leafId.toNumber() };
81
- }
82
67
  function buildRelayerRefundMerkleTree({ totalEvmDistributions, totalSolanaDistributions, mixLeaves, chainId, mint, svmRelayers, evmRelayers, evmTokenAddress, evmRefundAmounts, svmRefundAmounts, }) {
83
68
  const relayerRefundLeaves = [];
84
69
  const createSolanaLeaf = (index) => ({
@@ -122,202 +107,15 @@ function buildRelayerRefundMerkleTree({ totalEvmDistributions, totalSolanaDistri
122
107
  relayerRefundLeaves.push(createEvmLeaf(i + totalSolanaDistributions));
123
108
  }
124
109
  }
125
- const merkleTree = new common_1.MerkleTree(relayerRefundLeaves, exports.relayerRefundHashFn);
110
+ const merkleTree = new common_1.MerkleTree(relayerRefundLeaves, svm_1.relayerRefundHashFn);
126
111
  return { relayerRefundLeaves, merkleTree };
127
112
  }
128
- function calculateRelayerRefundLeafHashUint8Array(relayData) {
129
- const refundAmountsBuffer = Buffer.concat(relayData.refundAmounts.map((amount) => {
130
- const buf = Buffer.alloc(8);
131
- amount.toArrayLike(Buffer, "le", 8).copy(buf);
132
- return buf;
133
- }));
134
- const refundAddressesBuffer = Buffer.concat(relayData.refundAddresses.map((address) => address.toBuffer()));
135
- // TODO: We better consider reusing Borch serializer in production.
136
- const contentToHash = Buffer.concat([
137
- // SVM leaves require the first 64 bytes to be 0 to ensure EVM leaves can never be played on SVM and vice versa.
138
- Buffer.alloc(64, 0),
139
- relayData.amountToReturn.toArrayLike(Buffer, "le", 8),
140
- relayData.chainId.toArrayLike(Buffer, "le", 8),
141
- new anchor_1.BN(relayData.refundAmounts.length).toArrayLike(Buffer, "le", 4),
142
- refundAmountsBuffer,
143
- relayData.leafId.toArrayLike(Buffer, "le", 4),
144
- relayData.mintPublicKey.toBuffer(),
145
- new anchor_1.BN(relayData.refundAddresses.length).toArrayLike(Buffer, "le", 4),
146
- refundAddressesBuffer,
147
- ]);
148
- const relayHash = ethers_1.ethers.utils.keccak256(contentToHash);
149
- return relayHash;
150
- }
151
- const relayerRefundHashFn = (input) => {
152
- if (!input.isSolana) {
153
- const abiCoder = new ethers_1.ethers.utils.AbiCoder();
154
- const encodedData = abiCoder.encode([
155
- "tuple( uint256 amountToReturn, uint256 chainId, uint256[] refundAmounts, uint256 leafId, address l2TokenAddress, address[] refundAddresses)",
156
- ], [
157
- {
158
- leafId: input.leafId,
159
- chainId: input.chainId,
160
- amountToReturn: input.amountToReturn,
161
- l2TokenAddress: input.l2TokenAddress, // Type assertion
162
- refundAddresses: input.refundAddresses, // Type assertion
163
- refundAmounts: input.refundAmounts, // Type assertion
164
- },
165
- ]);
166
- return ethers_1.ethers.utils.keccak256(encodedData);
167
- }
168
- else {
169
- return calculateRelayerRefundLeafHashUint8Array(input);
170
- }
171
- };
172
- exports.relayerRefundHashFn = relayerRefundHashFn;
173
- // TODO: We better consider reusing Borch serializer in production.
174
- function slowFillHashFn(slowFillLeaf) {
175
- const contentToHash = Buffer.concat([
176
- // SVM leaves require the first 64 bytes to be 0 to ensure EVM leaves can never be played on SVM and vice versa.
177
- Buffer.alloc(64, 0),
178
- slowFillLeaf.relayData.depositor.toBuffer(),
179
- slowFillLeaf.relayData.recipient.toBuffer(),
180
- slowFillLeaf.relayData.exclusiveRelayer.toBuffer(),
181
- slowFillLeaf.relayData.inputToken.toBuffer(),
182
- slowFillLeaf.relayData.outputToken.toBuffer(),
183
- slowFillLeaf.relayData.inputAmount.toArrayLike(Buffer, "le", 8),
184
- slowFillLeaf.relayData.outputAmount.toArrayLike(Buffer, "le", 8),
185
- slowFillLeaf.relayData.originChainId.toArrayLike(Buffer, "le", 8),
186
- Buffer.from(slowFillLeaf.relayData.depositId),
187
- new anchor_1.BN(slowFillLeaf.relayData.fillDeadline).toArrayLike(Buffer, "le", 4),
188
- new anchor_1.BN(slowFillLeaf.relayData.exclusivityDeadline).toArrayLike(Buffer, "le", 4),
189
- new anchor_1.BN(slowFillLeaf.relayData.message.length).toArrayLike(Buffer, "le", 4),
190
- slowFillLeaf.relayData.message,
191
- slowFillLeaf.chainId.toArrayLike(Buffer, "le", 8),
192
- slowFillLeaf.updatedOutputAmount.toArrayLike(Buffer, "le", 8),
193
- ]);
194
- const slowFillHash = ethers_1.ethers.utils.keccak256(contentToHash);
195
- return slowFillHash;
196
- }
197
- async function loadExecuteRelayerRefundLeafParams(program, caller, rootBundleId, relayerRefundLeaf, proof) {
198
- const maxInstructionParamsFragment = 900; // Should not exceed message size limit when writing to the data account.
199
- // Close the instruction params account if the caller has used it before.
200
- const [instructionParams] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("instruction_params"), caller.toBuffer()], program.programId);
201
- const accountInfo = await program.provider.connection.getAccountInfo(instructionParams);
202
- if (accountInfo !== null)
203
- await program.methods.closeInstructionParams().rpc();
204
- const accountCoder = new SvmUtils_1.LargeAccountsCoder(program.idl);
205
- const instructionParamsBytes = await accountCoder.encode("executeRelayerRefundLeafParams", {
206
- rootBundleId,
207
- relayerRefundLeaf,
208
- proof,
209
- });
210
- await program.methods.initializeInstructionParams(instructionParamsBytes.length).rpc();
211
- for (let i = 0; i < instructionParamsBytes.length; i += maxInstructionParamsFragment) {
212
- const fragment = instructionParamsBytes.slice(i, i + maxInstructionParamsFragment);
213
- await program.methods.writeInstructionParamsFragment(i, fragment).rpc();
214
- }
215
- return instructionParams;
216
- }
217
- async function closeInstructionParams(program, signer) {
218
- const [instructionParams] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("instruction_params"), signer.publicKey.toBuffer()], program.programId);
219
- const accountInfo = await program.provider.connection.getAccountInfo(instructionParams);
220
- if (accountInfo !== null) {
221
- const closeIx = await program.methods.closeInstructionParams().accounts({ signer: signer.publicKey }).instruction();
222
- await (0, web3_js_1.sendAndConfirmTransaction)(program.provider.connection, new web3_js_1.Transaction().add(closeIx), [signer]);
223
- }
224
- }
225
- async function createFillV3RelayParamsInstructions(program, signer, relayData, repaymentChainId, repaymentAddress) {
226
- const maxInstructionParamsFragment = 900; // Should not exceed message size limit when writing to the data account.
227
- const accountCoder = new SvmUtils_1.LargeAccountsCoder(program.idl);
228
- const instructionParamsBytes = await accountCoder.encode("fillV3RelayParams", {
229
- relayData,
230
- repaymentChainId,
231
- repaymentAddress,
232
- });
233
- const loadInstructions = [];
234
- loadInstructions.push(await program.methods.initializeInstructionParams(instructionParamsBytes.length).accounts({ signer }).instruction());
235
- for (let i = 0; i < instructionParamsBytes.length; i += maxInstructionParamsFragment) {
236
- const fragment = instructionParamsBytes.slice(i, i + maxInstructionParamsFragment);
237
- loadInstructions.push(await program.methods.writeInstructionParamsFragment(i, fragment).accounts({ signer }).instruction());
238
- }
239
- const closeInstruction = await program.methods.closeInstructionParams().accounts({ signer }).instruction();
240
- return { loadInstructions, closeInstruction };
241
- }
242
- async function loadFillV3RelayParams(program, signer, relayData, repaymentChainId, repaymentAddress) {
243
- // Close the instruction params account if the caller has used it before.
244
- await closeInstructionParams(program, signer);
245
- // Execute load instructions sequentially.
246
- const { loadInstructions } = await createFillV3RelayParamsInstructions(program, signer.publicKey, relayData, repaymentChainId, repaymentAddress);
247
- for (let i = 0; i < loadInstructions.length; i += 1) {
248
- await (0, web3_js_1.sendAndConfirmTransaction)(program.provider.connection, new web3_js_1.Transaction().add(loadInstructions[i]), [signer]);
249
- }
250
- }
251
- async function loadRequestV3SlowFillParams(program, signer, relayData) {
252
- // Close the instruction params account if the caller has used it before.
253
- await closeInstructionParams(program, signer);
254
- // Execute load instructions sequentially.
255
- const maxInstructionParamsFragment = 900; // Should not exceed message size limit when writing to the data account.
256
- const accountCoder = new SvmUtils_1.LargeAccountsCoder(program.idl);
257
- const instructionParamsBytes = await accountCoder.encode("requestV3SlowFillParams", { relayData });
258
- const loadInstructions = [];
259
- loadInstructions.push(await program.methods
260
- .initializeInstructionParams(instructionParamsBytes.length)
261
- .accounts({ signer: signer.publicKey })
262
- .instruction());
263
- for (let i = 0; i < instructionParamsBytes.length; i += maxInstructionParamsFragment) {
264
- const fragment = instructionParamsBytes.slice(i, i + maxInstructionParamsFragment);
265
- loadInstructions.push(await program.methods
266
- .writeInstructionParamsFragment(i, fragment)
267
- .accounts({ signer: signer.publicKey })
268
- .instruction());
269
- }
270
- return loadInstructions;
271
- }
272
- async function loadExecuteV3SlowRelayLeafParams(program, signer, slowFillLeaf, rootBundleId, proof) {
273
- // Close the instruction params account if the caller has used it before.
274
- await closeInstructionParams(program, signer);
275
- // Execute load instructions sequentially.
276
- const maxInstructionParamsFragment = 900; // Should not exceed message size limit when writing to the data account.
277
- const accountCoder = new SvmUtils_1.LargeAccountsCoder(program.idl);
278
- const instructionParamsBytes = await accountCoder.encode("executeV3SlowRelayLeafParams", {
279
- slowFillLeaf,
280
- rootBundleId,
281
- proof,
282
- });
283
- const loadInstructions = [];
284
- loadInstructions.push(await program.methods
285
- .initializeInstructionParams(instructionParamsBytes.length)
286
- .accounts({ signer: signer.publicKey })
287
- .instruction());
288
- for (let i = 0; i < instructionParamsBytes.length; i += maxInstructionParamsFragment) {
289
- const fragment = instructionParamsBytes.slice(i, i + maxInstructionParamsFragment);
290
- loadInstructions.push(await program.methods
291
- .writeInstructionParamsFragment(i, fragment)
292
- .accounts({ signer: signer.publicKey })
293
- .instruction());
294
- }
295
- return loadInstructions;
296
- }
297
- function intToU8Array32(num) {
298
- if (!Number.isInteger(num) || num < 0) {
299
- throw new Error("Input must be a non-negative integer");
300
- }
301
- const u8Array = new Array(32).fill(0);
302
- let i = 0;
303
- while (num > 0 && i < 32) {
304
- u8Array[i++] = num & 0xff; // Get least significant byte
305
- num >>= 8; // Shift right by 8 bits
306
- }
307
- return u8Array;
308
- }
309
- function u8Array32ToInt(u8Array) {
310
- if (!(u8Array instanceof Uint8Array) || u8Array.length !== 32) {
311
- throw new Error("Input must be a Uint8Array of length 32");
312
- }
313
- return u8Array.reduce((num, byte, i) => num | (BigInt(byte) << BigInt(i * 8)), 0n);
314
- }
315
113
  // Encodes empty list of multicall handler instructions to be used as a test message field for fills.
316
114
  function testAcrossPlusMessage() {
317
115
  const handlerProgram = anchor_1.workspace.MulticallHandler;
318
- const multicallHandlerCoder = new SvmUtils_1.MulticallHandlerCoder([]);
116
+ const multicallHandlerCoder = new svm_1.MulticallHandlerCoder([]);
319
117
  const handlerMessage = multicallHandlerCoder.encode();
320
- const message = new SvmUtils_1.AcrossPlusMessageCoder({
118
+ const message = new svm_1.AcrossPlusMessageCoder({
321
119
  handler: handlerProgram.programId,
322
120
  readOnlyLen: multicallHandlerCoder.readOnlyLen,
323
121
  valueAmount: new anchor_1.BN(0),
@@ -331,11 +129,3 @@ function testAcrossPlusMessage() {
331
129
  ];
332
130
  return { encodedMessage, fillRemainingAccounts };
333
131
  }
334
- function hashNonEmptyMessage(message) {
335
- if (message.length > 0) {
336
- const hash = ethers_1.ethers.utils.keccak256(message);
337
- return Uint8Array.from(Buffer.from(hash.slice(2), "hex"));
338
- }
339
- // else return zeroed bytes32
340
- return new Uint8Array(32);
341
- }