@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
@@ -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.readEventsUntilFound = 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
32
  const anchor_1 = require("@coral-xyz/anchor");
44
33
  const web3_js_1 = require("@solana/web3.js");
45
- const ethers_1 = require("ethers");
46
34
  const crypto = __importStar(require("crypto"));
47
- const SvmUtils_1 = require("../../src/SvmUtils");
48
- Object.defineProperty(exports, "readEvents", { enumerable: true, get: function () { return SvmUtils_1.readEvents; } });
49
- Object.defineProperty(exports, "readProgramEvents", { enumerable: true, get: function () { return SvmUtils_1.readProgramEvents; } });
50
- Object.defineProperty(exports, "calculateRelayHashUint8Array", { enumerable: true, get: function () { return SvmUtils_1.calculateRelayHashUint8Array; } });
51
- Object.defineProperty(exports, "findProgramAddress", { enumerable: true, get: function () { return SvmUtils_1.findProgramAddress; } });
52
- Object.defineProperty(exports, "readEventsUntilFound", { enumerable: true, get: function () { return SvmUtils_1.readEventsUntilFound; } });
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,216 +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
- let bigIntValue;
299
- if (typeof num === "number") {
300
- if (!Number.isInteger(num) || num < 0) {
301
- throw new Error("Input must be a non-negative integer");
302
- }
303
- bigIntValue = BigInt(num);
304
- }
305
- else if (anchor_1.BN.isBN(num)) {
306
- if (num.isNeg()) {
307
- throw new Error("Input must be a non-negative BN");
308
- }
309
- bigIntValue = BigInt(num.toString());
310
- }
311
- else {
312
- throw new Error("Input must be a non-negative integer or BN");
313
- }
314
- const u8Array = new Array(32).fill(0);
315
- let i = 0;
316
- while (bigIntValue > 0 && i < 32) {
317
- u8Array[i++] = Number(bigIntValue & 0xffn); // Get least significant byte
318
- bigIntValue >>= 8n; // Shift right by 8 bits
319
- }
320
- return u8Array;
321
- }
322
- function u8Array32ToInt(u8Array) {
323
- const isValidArray = (arr) => Array.isArray(arr) && arr.every(Number.isInteger);
324
- if ((u8Array instanceof Uint8Array || isValidArray(u8Array)) && u8Array.length === 32) {
325
- return Array.from(u8Array).reduce((num, byte, i) => num | (BigInt(byte) << BigInt(i * 8)), 0n);
326
- }
327
- throw new Error("Input must be a Uint8Array or an array of 32 numbers.");
328
- }
329
113
  // Encodes empty list of multicall handler instructions to be used as a test message field for fills.
330
114
  function testAcrossPlusMessage() {
331
115
  const handlerProgram = anchor_1.workspace.MulticallHandler;
332
- const multicallHandlerCoder = new SvmUtils_1.MulticallHandlerCoder([]);
116
+ const multicallHandlerCoder = new svm_1.MulticallHandlerCoder([]);
333
117
  const handlerMessage = multicallHandlerCoder.encode();
334
- const message = new SvmUtils_1.AcrossPlusMessageCoder({
118
+ const message = new svm_1.AcrossPlusMessageCoder({
335
119
  handler: handlerProgram.programId,
336
120
  readOnlyLen: multicallHandlerCoder.readOnlyLen,
337
121
  valueAmount: new anchor_1.BN(0),