@across-protocol/sdk 4.3.12 → 4.3.13

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 (54) hide show
  1. package/dist/cjs/arch/svm/BlockUtils.d.ts +1 -0
  2. package/dist/cjs/arch/svm/BlockUtils.js +69 -52
  3. package/dist/cjs/arch/svm/BlockUtils.js.map +1 -1
  4. package/dist/cjs/arch/svm/SpokeUtils.d.ts +21 -10
  5. package/dist/cjs/arch/svm/SpokeUtils.js +303 -49
  6. package/dist/cjs/arch/svm/SpokeUtils.js.map +1 -1
  7. package/dist/cjs/arch/svm/types.d.ts +7 -0
  8. package/dist/cjs/arch/svm/utils.d.ts +8 -3
  9. package/dist/cjs/arch/svm/utils.js +81 -4
  10. package/dist/cjs/arch/svm/utils.js.map +1 -1
  11. package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.d.ts +1 -1
  12. package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js +5 -2
  13. package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
  14. package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.d.ts +8 -8
  15. package/dist/cjs/clients/HubPoolClient.d.ts +1 -0
  16. package/dist/cjs/clients/HubPoolClient.js +11 -0
  17. package/dist/cjs/clients/HubPoolClient.js.map +1 -1
  18. package/dist/esm/arch/svm/BlockUtils.d.ts +7 -0
  19. package/dist/esm/arch/svm/BlockUtils.js +76 -54
  20. package/dist/esm/arch/svm/BlockUtils.js.map +1 -1
  21. package/dist/esm/arch/svm/SpokeUtils.d.ts +51 -10
  22. package/dist/esm/arch/svm/SpokeUtils.js +294 -8
  23. package/dist/esm/arch/svm/SpokeUtils.js.map +1 -1
  24. package/dist/esm/arch/svm/types.d.ts +7 -0
  25. package/dist/esm/arch/svm/utils.d.ts +35 -3
  26. package/dist/esm/arch/svm/utils.js +103 -3
  27. package/dist/esm/arch/svm/utils.js.map +1 -1
  28. package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.d.ts +1 -1
  29. package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js +5 -2
  30. package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
  31. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.d.ts +8 -8
  32. package/dist/esm/clients/HubPoolClient.d.ts +1 -0
  33. package/dist/esm/clients/HubPoolClient.js +19 -0
  34. package/dist/esm/clients/HubPoolClient.js.map +1 -1
  35. package/dist/types/arch/svm/BlockUtils.d.ts +7 -0
  36. package/dist/types/arch/svm/BlockUtils.d.ts.map +1 -1
  37. package/dist/types/arch/svm/SpokeUtils.d.ts +51 -10
  38. package/dist/types/arch/svm/SpokeUtils.d.ts.map +1 -1
  39. package/dist/types/arch/svm/types.d.ts +7 -0
  40. package/dist/types/arch/svm/types.d.ts.map +1 -1
  41. package/dist/types/arch/svm/utils.d.ts +35 -3
  42. package/dist/types/arch/svm/utils.d.ts.map +1 -1
  43. package/dist/types/clients/BundleDataClient/utils/PoolRebalanceUtils.d.ts +1 -1
  44. package/dist/types/clients/BundleDataClient/utils/PoolRebalanceUtils.d.ts.map +1 -1
  45. package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts +8 -8
  46. package/dist/types/clients/HubPoolClient.d.ts +1 -0
  47. package/dist/types/clients/HubPoolClient.d.ts.map +1 -1
  48. package/package.json +1 -1
  49. package/src/arch/svm/BlockUtils.ts +33 -16
  50. package/src/arch/svm/SpokeUtils.ts +272 -10
  51. package/src/arch/svm/types.ts +8 -0
  52. package/src/arch/svm/utils.ts +99 -8
  53. package/src/clients/BundleDataClient/utils/PoolRebalanceUtils.ts +5 -2
  54. package/src/clients/HubPoolClient.ts +23 -0
@@ -1,20 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getFillRelayDelegatePda = exports.getDepositNowDelegatePda = exports.getDepositDelegatePda = exports.getRelayDataHash = exports.getAssociatedTokenAddress = exports.createCloseFillPdaInstruction = exports.getSlowFillRequestTx = exports.createRequestSlowFillInstruction = exports.createDepositInstruction = exports.createFillInstruction = exports.getFillRelayTx = exports.createTokenAccountsInstruction = exports.fillRelayInstruction = exports.findFillEvent = exports.fillStatusArray = exports.relayFillStatus = exports.findDeposit = exports.getDepositIdAtBlock = exports.getFillDeadline = exports.getTimestampForSlot = exports.SLOT_DURATION_MS = void 0;
3
+ exports.finalizeCCTPV1Messages = exports.getCCTPV1ReceiveMessageTx = exports.getAccountMetasForTokenlessMessage = exports.hasCCTPV1MessageBeenProcessed = exports.getFillRelayDelegatePda = exports.getDepositNowDelegatePda = exports.getDepositDelegatePda = exports.getRelayDataHash = exports.getAssociatedTokenAddress = exports.createReceiveMessageInstruction = exports.createCloseFillPdaInstruction = exports.getSlowFillRequestTx = exports.createRequestSlowFillInstruction = exports.createDepositInstruction = exports.createFillInstruction = exports.getFillRelayTx = exports.createTokenAccountsInstruction = exports.fillRelayInstruction = exports.findFillEvent = exports.fillStatusArray = exports.relayFillStatus = exports.findDeposit = exports.getDepositIdAtBlock = exports.getFillDeadline = exports.getTimestampForSlot = exports.SLOT_DURATION_MS = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var contracts_1 = require("@across-protocol/contracts");
6
6
  var SvmSpoke_1 = require("@across-protocol/contracts/dist/src/svm/clients/SvmSpoke");
7
- var conversionUtils_1 = require("@across-protocol/contracts/dist/src/svm/web3-v1/conversionUtils");
8
7
  var web3_v1_1 = require("@across-protocol/contracts/dist/src/svm/web3-v1");
8
+ var conversionUtils_1 = require("@across-protocol/contracts/dist/src/svm/web3-v1/conversionUtils");
9
+ var system_1 = require("@solana-program/system");
9
10
  var token_1 = require("@solana-program/token");
10
11
  var kit_1 = require("@solana/kit");
11
12
  var assert_1 = tslib_1.__importDefault(require("assert"));
12
13
  var utils_1 = require("ethers/lib/utils");
13
- var system_1 = require("@solana-program/system");
14
+ var constants_1 = require("../../constants");
14
15
  var interfaces_1 = require("../../interfaces");
15
16
  var utils_2 = require("../../utils");
16
- var utils_3 = require("./utils");
17
- var constants_1 = require("../../constants");
17
+ var _1 = require("./");
18
18
  var provider_1 = require("./provider");
19
19
  var types_1 = require("./types");
20
20
  exports.SLOT_DURATION_MS = 400;
@@ -89,7 +89,7 @@ function findDeposit(eventClient, depositId, slot, secondsLookback) {
89
89
  if (!depositEvent) {
90
90
  return [2, undefined];
91
91
  }
92
- unwrappedDepositEvent = (0, utils_3.unwrapEventData)(depositEvent.data);
92
+ unwrappedDepositEvent = (0, _1.unwrapEventData)(depositEvent.data);
93
93
  destinationChainId = unwrappedDepositEvent.destinationChainId;
94
94
  return [2, tslib_1.__assign(tslib_1.__assign({ txnRef: depositEvent.signature.toString(), blockNumber: Number(depositEvent.slot), txnIndex: 0, logIndex: 0 }, unwrappedDepositEvent), { depositor: (0, utils_2.toAddressType)(unwrappedDepositEvent.depositor, constants_1.CHAIN_IDs.SOLANA), recipient: (0, utils_2.toAddressType)(unwrappedDepositEvent.recipient, destinationChainId), inputToken: (0, utils_2.toAddressType)(unwrappedDepositEvent.inputToken, constants_1.CHAIN_IDs.SOLANA), outputToken: (0, utils_2.toAddressType)(unwrappedDepositEvent.outputToken, destinationChainId), exclusiveRelayer: (0, utils_2.toAddressType)(unwrappedDepositEvent.exclusiveRelayer, destinationChainId) })];
95
95
  }
@@ -105,7 +105,7 @@ function relayFillStatus(programId, relayData, destinationChainId, svmEventsClie
105
105
  case 0:
106
106
  (0, assert_1.default)((0, utils_2.chainIsSvm)(destinationChainId), "Destination chain must be an SVM chain");
107
107
  provider = svmEventsClient.getRpc();
108
- return [4, (0, utils_3.getFillStatusPda)(programId, relayData, destinationChainId)];
108
+ return [4, (0, _1.getFillStatusPda)(programId, relayData, destinationChainId)];
109
109
  case 1:
110
110
  fillStatusPda = _b.sent();
111
111
  return [4, provider.getSlot({ commitment: "confirmed" }).send()];
@@ -146,7 +146,7 @@ function fillStatusArray(programId, relayData, destinationChainId, svmEventsClie
146
146
  chunkSize = 100;
147
147
  chunkedRelayData = (0, utils_2.chunk)(relayData, chunkSize);
148
148
  return [4, Promise.all(chunkedRelayData.map(function (relayDataChunk) {
149
- return Promise.all(relayDataChunk.map(function (relayData) { return (0, utils_3.getFillStatusPda)(programId, relayData, destinationChainId); }));
149
+ return Promise.all(relayDataChunk.map(function (relayData) { return (0, _1.getFillStatusPda)(programId, relayData, destinationChainId); }));
150
150
  }))];
151
151
  case 1:
152
152
  fillStatusPdas = (_c.sent()).flat();
@@ -239,7 +239,7 @@ function findFillEvent(relayData, destinationChainId, svmEventsClient, fromSlot,
239
239
  case 3:
240
240
  _a;
241
241
  programId = svmEventsClient.getProgramAddress();
242
- return [4, (0, utils_3.getFillStatusPda)(programId, relayData, destinationChainId)];
242
+ return [4, (0, _1.getFillStatusPda)(programId, relayData, destinationChainId)];
243
243
  case 4:
244
244
  fillStatusPda = _c.sent();
245
245
  return [4, svmEventsClient.queryDerivedAddressEvents(types_1.SVMEventNames.FilledRelay, fillStatusPda, BigInt(fromSlot), BigInt(toSlot), { limit: 10 })];
@@ -248,7 +248,7 @@ function findFillEvent(relayData, destinationChainId, svmEventsClient, fromSlot,
248
248
  (0, assert_1.default)(fillEvents.length <= 1, "Expected at most one fill event for ".concat(fillStatusPda, ", got ").concat(fillEvents.length));
249
249
  if (fillEvents.length > 0) {
250
250
  rawFillEvent = fillEvents[0];
251
- eventData = (0, utils_3.unwrapEventData)(rawFillEvent.data);
251
+ eventData = (0, _1.unwrapEventData)(rawFillEvent.data);
252
252
  originChainId = eventData.originChainId;
253
253
  parsedFillEvent = tslib_1.__assign(tslib_1.__assign({}, eventData), { transactionHash: rawFillEvent.signature, blockNumber: Number(rawFillEvent.slot), transactionIndex: 0, logIndex: 0, destinationChainId: destinationChainId, inputToken: (0, utils_2.toAddressType)(eventData.inputToken, originChainId), outputToken: (0, utils_2.toAddressType)(eventData.outputToken, destinationChainId), relayer: (0, utils_2.toAddressType)(eventData.relayer, destinationChainId), exclusiveRelayer: (0, utils_2.toAddressType)(eventData.exclusiveRelayer, destinationChainId), depositor: (0, utils_2.toAddressType)(eventData.depositor, originChainId), recipient: (0, utils_2.toAddressType)(eventData.recipient, destinationChainId), relayExecutionInfo: tslib_1.__assign(tslib_1.__assign({}, eventData.relayExecutionInfo), { updatedRecipient: eventData.relayExecutionInfo.updatedRecipient }) });
254
254
  return [2, parsedFillEvent];
@@ -267,7 +267,7 @@ function fillRelayInstruction(spokePool, relayData, signer, recipientTokenAccoun
267
267
  return tslib_1.__generator(this, function (_c) {
268
268
  switch (_c.label) {
269
269
  case 0:
270
- program = (0, utils_3.toAddress)(spokePool);
270
+ program = (0, _1.toAddress)(spokePool);
271
271
  (0, assert_1.default)(repaymentAddress.isValidOn(repaymentChainId), "Invalid repayment address for chain ".concat(repaymentChainId, ": ").concat(repaymentAddress.toNative(), "."));
272
272
  _relayDataHash = getRelayDataHash(relayData, relayData.destinationChainId);
273
273
  relayDataHash = new Uint8Array(Buffer.from(_relayDataHash.slice(2), "hex"));
@@ -276,16 +276,16 @@ function fillRelayInstruction(spokePool, relayData, signer, recipientTokenAccoun
276
276
  case 1:
277
277
  relayerTokenAccount = _c.sent();
278
278
  return [4, Promise.all([
279
- (0, utils_3.getStatePda)(program),
280
- (0, utils_3.getFillStatusPda)(program, relayData, relayData.destinationChainId),
281
- (0, utils_3.getEventAuthority)(program),
279
+ (0, _1.getStatePda)(program),
280
+ (0, _1.getFillStatusPda)(program, relayData, relayData.destinationChainId),
281
+ (0, _1.getEventAuthority)(program),
282
282
  ])];
283
283
  case 2:
284
284
  _a = _c.sent(), statePda = _a[0], fillStatusPda = _a[1], eventAuthority = _a[2];
285
285
  depositIdBuffer = new Uint8Array(32);
286
286
  shortenedBuffer = new Uint8Array(Buffer.from(relayData.depositId.toHexString().slice(2), "hex"));
287
287
  depositIdBuffer.set(shortenedBuffer, 32 - shortenedBuffer.length);
288
- return [4, getFillRelayDelegatePda(relayDataHash, BigInt(repaymentChainId), (0, utils_3.toAddress)(relayer), program)];
288
+ return [4, getFillRelayDelegatePda(relayDataHash, BigInt(repaymentChainId), (0, _1.toAddress)(relayer), program)];
289
289
  case 3:
290
290
  delegatePda = _c.sent();
291
291
  _b = [
@@ -294,11 +294,11 @@ function fillRelayInstruction(spokePool, relayData, signer, recipientTokenAccoun
294
294
  relayData.exclusiveRelayer,
295
295
  relayData.depositor,
296
296
  relayData.inputToken,
297
- ].map(utils_3.toAddress), recipient = _b[0], outputToken = _b[1], exclusiveRelayer = _b[2], depositor = _b[3], inputToken = _b[4];
297
+ ].map(_1.toAddress), recipient = _b[0], outputToken = _b[1], exclusiveRelayer = _b[2], depositor = _b[3], inputToken = _b[4];
298
298
  return [2, contracts_1.SvmSpokeClient.getFillRelayInstruction({
299
299
  signer: signer,
300
300
  state: statePda,
301
- delegate: (0, utils_3.toAddress)(utils_2.SvmAddress.from(delegatePda.toString())),
301
+ delegate: (0, _1.toAddress)(utils_2.SvmAddress.from(delegatePda.toString())),
302
302
  mint: outputToken,
303
303
  relayerTokenAccount: relayerTokenAccount,
304
304
  recipientTokenAccount: recipientTokenAccount,
@@ -312,7 +312,7 @@ function fillRelayInstruction(spokePool, relayData, signer, recipientTokenAccoun
312
312
  exclusiveRelayer: exclusiveRelayer,
313
313
  inputToken: inputToken,
314
314
  outputToken: outputToken,
315
- inputAmount: (0, utils_3.bigToU8a32)(relayData.inputAmount.toBigInt()),
315
+ inputAmount: (0, _1.bigToU8a32)(relayData.inputAmount.toBigInt()),
316
316
  outputAmount: relayData.outputAmount.toBigInt(),
317
317
  originChainId: BigInt(relayData.originChainId),
318
318
  fillDeadline: relayData.fillDeadline,
@@ -321,7 +321,7 @@ function fillRelayInstruction(spokePool, relayData, signer, recipientTokenAccoun
321
321
  message: new Uint8Array(Buffer.from(relayData.message.slice(2), "hex")),
322
322
  }),
323
323
  repaymentChainId: (0, kit_1.some)(BigInt(repaymentChainId)),
324
- repaymentAddress: (0, utils_3.toAddress)(repaymentAddress),
324
+ repaymentAddress: (0, _1.toAddress)(repaymentAddress),
325
325
  })];
326
326
  }
327
327
  });
@@ -331,7 +331,7 @@ exports.fillRelayInstruction = fillRelayInstruction;
331
331
  function createTokenAccountsInstruction(mint, relayer) {
332
332
  return contracts_1.SvmSpokeClient.getCreateTokenAccountsInstruction({
333
333
  signer: relayer,
334
- mint: (0, utils_3.toAddress)(mint),
334
+ mint: (0, _1.toAddress)(mint),
335
335
  });
336
336
  }
337
337
  exports.createTokenAccountsInstruction = createTokenAccountsInstruction;
@@ -344,34 +344,34 @@ function getFillRelayTx(spokePoolAddr, solanaClient, relayData, signer, repaymen
344
344
  depositor = relayData.depositor, recipient = relayData.recipient, inputToken = relayData.inputToken, outputToken = relayData.outputToken, exclusiveRelayer = relayData.exclusiveRelayer, destinationChainId = relayData.destinationChainId;
345
345
  (0, assert_1.default)(recipient.isSVM(), "getFillRelayTx: recipient not an SVM address (".concat(recipient, ")"));
346
346
  (0, assert_1.default)(repaymentAddress.isValidOn(repaymentChainId), "getFillRelayTx: repayment address ".concat(repaymentAddress, " not valid on chain ").concat(repaymentChainId, ")"));
347
- program = (0, utils_3.toAddress)(spokePoolAddr);
347
+ program = (0, _1.toAddress)(spokePoolAddr);
348
348
  _relayDataHash = getRelayDataHash(relayData, destinationChainId);
349
349
  relayDataHash = new Uint8Array(Buffer.from(_relayDataHash.slice(2), "hex"));
350
350
  return [4, Promise.all([
351
- (0, utils_3.getStatePda)(program),
352
- getFillRelayDelegatePda(relayDataHash, BigInt(repaymentChainId), (0, utils_3.toAddress)(repaymentAddress), program),
351
+ (0, _1.getStatePda)(program),
352
+ getFillRelayDelegatePda(relayDataHash, BigInt(repaymentChainId), (0, _1.toAddress)(repaymentAddress), program),
353
353
  ])];
354
354
  case 1:
355
355
  _a = _c.sent(), state = _a[0], delegate = _a[1];
356
- mint = (0, utils_3.toAddress)(outputToken);
356
+ mint = (0, _1.toAddress)(outputToken);
357
357
  return [4, (0, token_1.fetchMint)(solanaClient, mint)];
358
358
  case 2:
359
359
  mintInfo = _c.sent();
360
360
  return [4, Promise.all([
361
361
  getAssociatedTokenAddress(recipient, outputToken, mintInfo.programAddress),
362
362
  getAssociatedTokenAddress(utils_2.SvmAddress.from(signer.address), outputToken, mintInfo.programAddress),
363
- (0, utils_3.getFillStatusPda)(program, relayData, destinationChainId),
364
- (0, utils_3.getEventAuthority)(program),
363
+ (0, _1.getFillStatusPda)(program, relayData, destinationChainId),
364
+ (0, _1.getEventAuthority)(program),
365
365
  ])];
366
366
  case 3:
367
367
  _b = _c.sent(), recipientAta = _b[0], relayerAta = _b[1], fillStatus = _b[2], eventAuthority = _b[3];
368
368
  svmRelayData = {
369
- depositor: (0, utils_3.toAddress)(depositor),
370
- recipient: (0, utils_3.toAddress)(recipient),
371
- exclusiveRelayer: (0, utils_3.toAddress)(exclusiveRelayer),
372
- inputToken: (0, utils_3.toAddress)(inputToken),
369
+ depositor: (0, _1.toAddress)(depositor),
370
+ recipient: (0, _1.toAddress)(recipient),
371
+ exclusiveRelayer: (0, _1.toAddress)(exclusiveRelayer),
372
+ inputToken: (0, _1.toAddress)(inputToken),
373
373
  outputToken: mint,
374
- inputAmount: (0, utils_3.bigToU8a32)(relayData.inputAmount.toBigInt()),
374
+ inputAmount: (0, _1.bigToU8a32)(relayData.inputAmount.toBigInt()),
375
375
  outputAmount: relayData.outputAmount.toBigInt(),
376
376
  originChainId: relayData.originChainId,
377
377
  depositId: new Uint8Array((0, conversionUtils_1.intToU8Array32)(relayData.depositId.toNumber())),
@@ -395,7 +395,7 @@ function getFillRelayTx(spokePoolAddr, solanaClient, relayData, signer, repaymen
395
395
  relayHash: relayDataHash,
396
396
  relayData: svmRelayData,
397
397
  repaymentChainId: BigInt(repaymentChainId),
398
- repaymentAddress: (0, utils_3.toAddress)(repaymentAddress),
398
+ repaymentAddress: (0, _1.toAddress)(repaymentAddress),
399
399
  };
400
400
  return [2, (0, exports.createFillInstruction)(signer, solanaClient, fillInput, mintInfo.data.decimals, true)];
401
401
  }
@@ -434,7 +434,7 @@ var createFillInstruction = function (signer, solanaClient, fillInput, tokenDeci
434
434
  };
435
435
  createFillIx = contracts_1.SvmSpokeClient.getFillRelayInstruction(fillInput);
436
436
  _a = kit_1.pipe;
437
- return [4, (0, utils_3.createDefaultTransaction)(solanaClient, signer)];
437
+ return [4, (0, _1.createDefaultTransaction)(solanaClient, signer)];
438
438
  case 2: return [2, _a.apply(void 0, [_b.sent(), function (tx) {
439
439
  return createRecipientAtaIfNeeded ? (0, kit_1.appendTransactionMessageInstruction)(getCreateAssociatedTokenIdempotentIx(), tx) : tx;
440
440
  },
@@ -477,7 +477,7 @@ var createDepositInstruction = function (signer, solanaClient, depositInput, tok
477
477
  });
478
478
  depositIx = contracts_1.SvmSpokeClient.getDepositInstruction(depositInput);
479
479
  _a = kit_1.pipe;
480
- return [4, (0, utils_3.createDefaultTransaction)(solanaClient, signer)];
480
+ return [4, (0, _1.createDefaultTransaction)(solanaClient, signer)];
481
481
  case 2: return [2, _a.apply(void 0, [_b.sent(), function (tx) {
482
482
  return createVaultAtaIfNeeded ? (0, kit_1.appendTransactionMessageInstruction)(getCreateAssociatedTokenIdempotentIx(), tx) : tx;
483
483
  },
@@ -495,7 +495,7 @@ var createRequestSlowFillInstruction = function (signer, solanaClient, requestSl
495
495
  case 0:
496
496
  requestSlowFillIx = contracts_1.SvmSpokeClient.getRequestSlowFillInstruction(requestSlowFillInput);
497
497
  _a = kit_1.pipe;
498
- return [4, (0, utils_3.createDefaultTransaction)(solanaClient, signer)];
498
+ return [4, (0, _1.createDefaultTransaction)(solanaClient, signer)];
499
499
  case 1: return [2, _a.apply(void 0, [_b.sent(), function (tx) {
500
500
  return (0, kit_1.appendTransactionMessageInstruction)(requestSlowFillIx, tx);
501
501
  }])];
@@ -510,12 +510,12 @@ function getSlowFillRequestTx(spokePoolAddr, solanaClient, relayData, signer) {
510
510
  switch (_b.label) {
511
511
  case 0:
512
512
  depositor = relayData.depositor, recipient = relayData.recipient, inputToken = relayData.inputToken, outputToken = relayData.outputToken, exclusiveRelayer = relayData.exclusiveRelayer, destinationChainId = relayData.destinationChainId, originChainId = relayData.originChainId, depositId = relayData.depositId, fillDeadline = relayData.fillDeadline, exclusivityDeadline = relayData.exclusivityDeadline, message = relayData.message;
513
- program = (0, utils_3.toAddress)(spokePoolAddr);
513
+ program = (0, _1.toAddress)(spokePoolAddr);
514
514
  relayDataHash = getRelayDataHash(relayData, destinationChainId);
515
515
  return [4, Promise.all([
516
- (0, utils_3.getStatePda)(program),
517
- (0, utils_3.getFillStatusPda)(program, relayData, destinationChainId),
518
- (0, utils_3.getEventAuthority)(program),
516
+ (0, _1.getStatePda)(program),
517
+ (0, _1.getFillStatusPda)(program, relayData, destinationChainId),
518
+ (0, _1.getEventAuthority)(program),
519
519
  ])];
520
520
  case 1:
521
521
  _a = _b.sent(), state = _a[0], fillStatus = _a[1], eventAuthority = _a[2];
@@ -523,12 +523,12 @@ function getSlowFillRequestTx(spokePoolAddr, solanaClient, relayData, signer) {
523
523
  shortenedBuffer = (0, utils_1.arrayify)(depositId.toHexString());
524
524
  depositIdBuffer.set(shortenedBuffer, 32 - shortenedBuffer.length);
525
525
  relayDataInput = {
526
- depositor: (0, utils_3.toAddress)(depositor),
527
- recipient: (0, utils_3.toAddress)(recipient),
528
- exclusiveRelayer: (0, utils_3.toAddress)(exclusiveRelayer),
529
- inputToken: (0, utils_3.toAddress)(inputToken),
530
- outputToken: (0, utils_3.toAddress)(outputToken),
531
- inputAmount: (0, utils_3.bigToU8a32)(relayData.inputAmount.toBigInt()),
526
+ depositor: (0, _1.toAddress)(depositor),
527
+ recipient: (0, _1.toAddress)(recipient),
528
+ exclusiveRelayer: (0, _1.toAddress)(exclusiveRelayer),
529
+ inputToken: (0, _1.toAddress)(inputToken),
530
+ outputToken: (0, _1.toAddress)(outputToken),
531
+ inputAmount: (0, _1.bigToU8a32)(relayData.inputAmount.toBigInt()),
532
532
  outputAmount: relayData.outputAmount.toBigInt(),
533
533
  originChainId: BigInt(originChainId),
534
534
  depositId: depositIdBuffer,
@@ -562,13 +562,13 @@ var createCloseFillPdaInstruction = function (signer, solanaClient, fillStatusPd
562
562
  _d = {
563
563
  signer: signer
564
564
  };
565
- return [4, (0, utils_3.getStatePda)(contracts_1.SvmSpokeClient.SVM_SPOKE_PROGRAM_ADDRESS)];
565
+ return [4, (0, _1.getStatePda)(contracts_1.SvmSpokeClient.SVM_SPOKE_PROGRAM_ADDRESS)];
566
566
  case 1:
567
567
  closeFillPdaIx = _b.apply(_a, [(_d.state = _e.sent(),
568
568
  _d.fillStatus = fillStatusPda,
569
569
  _d)]);
570
570
  _c = kit_1.pipe;
571
- return [4, (0, utils_3.createDefaultTransaction)(solanaClient, signer)];
571
+ return [4, (0, _1.createDefaultTransaction)(solanaClient, signer)];
572
572
  case 2: return [2, _c.apply(void 0, [_e.sent(), function (tx) {
573
573
  return (0, kit_1.appendTransactionMessageInstruction)(closeFillPdaIx, tx);
574
574
  }])];
@@ -576,6 +576,24 @@ var createCloseFillPdaInstruction = function (signer, solanaClient, fillStatusPd
576
576
  });
577
577
  }); };
578
578
  exports.createCloseFillPdaInstruction = createCloseFillPdaInstruction;
579
+ var createReceiveMessageInstruction = function (signer, solanaClient, input, remainingAccounts) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
580
+ var receiveMessageIx, _a;
581
+ var _b;
582
+ return tslib_1.__generator(this, function (_c) {
583
+ switch (_c.label) {
584
+ case 0: return [4, contracts_1.MessageTransmitterClient.getReceiveMessageInstruction(input)];
585
+ case 1:
586
+ receiveMessageIx = _c.sent();
587
+ (_b = receiveMessageIx.accounts).push.apply(_b, remainingAccounts);
588
+ _a = kit_1.pipe;
589
+ return [4, (0, _1.createDefaultTransaction)(solanaClient, signer)];
590
+ case 2: return [2, _a.apply(void 0, [_c.sent(), function (tx) {
591
+ return (0, kit_1.appendTransactionMessageInstruction)(receiveMessageIx, tx);
592
+ }])];
593
+ }
594
+ });
595
+ }); };
596
+ exports.createReceiveMessageInstruction = createReceiveMessageInstruction;
579
597
  function getAssociatedTokenAddress(owner, mint, tokenProgramId) {
580
598
  if (tokenProgramId === void 0) { tokenProgramId = token_1.TOKEN_PROGRAM_ADDRESS; }
581
599
  return tslib_1.__awaiter(this, void 0, void 0, function () {
@@ -586,7 +604,7 @@ function getAssociatedTokenAddress(owner, mint, tokenProgramId) {
586
604
  encoder = (0, kit_1.getAddressEncoder)();
587
605
  return [4, (0, kit_1.getProgramDerivedAddress)({
588
606
  programAddress: token_1.ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
589
- seeds: [encoder.encode((0, utils_3.toAddress)(owner)), encoder.encode(tokenProgramId), encoder.encode((0, utils_3.toAddress)(mint))],
607
+ seeds: [encoder.encode((0, _1.toAddress)(owner)), encoder.encode(tokenProgramId), encoder.encode((0, _1.toAddress)(mint))],
590
608
  })];
591
609
  case 1:
592
610
  associatedToken = (_a.sent())[0];
@@ -601,7 +619,7 @@ function getRelayDataHash(relayData, destinationChainId) {
601
619
  var uint64Encoder = (0, kit_1.getU64Encoder)();
602
620
  var uint32Encoder = (0, kit_1.getU32Encoder)();
603
621
  (0, assert_1.default)(relayData.message.startsWith("0x"), "Message must be a hex string");
604
- var encodeAddress = function (data) { return Uint8Array.from(addressEncoder.encode((0, utils_3.toAddress)(data))); };
622
+ var encodeAddress = function (data) { return Uint8Array.from(addressEncoder.encode((0, _1.toAddress)(data))); };
605
623
  var contentToHash = Buffer.concat([
606
624
  encodeAddress(relayData.depositor),
607
625
  encodeAddress(relayData.recipient),
@@ -782,4 +800,240 @@ function getFillRelayDelegatePda(relayHash, repaymentChainId, repaymentAddress,
782
800
  });
783
801
  }
784
802
  exports.getFillRelayDelegatePda = getFillRelayDelegatePda;
803
+ var hasCCTPV1MessageBeenProcessed = function (solanaClient, signer, nonce, sourceDomain) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
804
+ var noncePda, isNonceUsedIx, parserFunction;
805
+ return tslib_1.__generator(this, function (_a) {
806
+ switch (_a.label) {
807
+ case 0: return [4, (0, _1.getCCTPNoncePda)(solanaClient, signer, nonce, sourceDomain)];
808
+ case 1:
809
+ noncePda = _a.sent();
810
+ return [4, contracts_1.MessageTransmitterClient.getIsNonceUsedInstruction({
811
+ nonce: nonce,
812
+ usedNonces: noncePda,
813
+ })];
814
+ case 2:
815
+ isNonceUsedIx = _a.sent();
816
+ parserFunction = function (buf) {
817
+ if (buf.length != 1) {
818
+ throw new Error("Invalid buffer length for isNonceUsedIx");
819
+ }
820
+ return Boolean(buf[0]);
821
+ };
822
+ return [4, (0, _1.simulateAndDecode)(solanaClient, isNonceUsedIx, signer, parserFunction)];
823
+ case 3: return [2, _a.sent()];
824
+ }
825
+ });
826
+ }); };
827
+ exports.hasCCTPV1MessageBeenProcessed = hasCCTPV1MessageBeenProcessed;
828
+ function getAccountMetasForTokenlessMessage() {
829
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
830
+ var statePda, _a;
831
+ var _b, _c;
832
+ return tslib_1.__generator(this, function (_d) {
833
+ switch (_d.label) {
834
+ case 0: return [4, (0, _1.getStatePda)(contracts_1.SvmSpokeClient.SVM_SPOKE_PROGRAM_ADDRESS)];
835
+ case 1:
836
+ statePda = _d.sent();
837
+ _a = [{ address: statePda, role: kit_1.AccountRole.READONLY }];
838
+ _b = {};
839
+ return [4, (0, _1.getSelfAuthority)()];
840
+ case 2:
841
+ _a = _a.concat([
842
+ (_b.address = _d.sent(), _b.role = kit_1.AccountRole.READONLY, _b),
843
+ { address: contracts_1.SvmSpokeClient.SVM_SPOKE_PROGRAM_ADDRESS, role: kit_1.AccountRole.READONLY },
844
+ { address: statePda, role: kit_1.AccountRole.WRITABLE }
845
+ ]);
846
+ _c = {};
847
+ return [4, (0, _1.getEventAuthority)(contracts_1.SvmSpokeClient.SVM_SPOKE_PROGRAM_ADDRESS)];
848
+ case 3: return [2, _a.concat([
849
+ (_c.address = _d.sent(), _c.role = kit_1.AccountRole.READONLY, _c),
850
+ { address: contracts_1.SvmSpokeClient.SVM_SPOKE_PROGRAM_ADDRESS, role: kit_1.AccountRole.READONLY }
851
+ ])];
852
+ }
853
+ });
854
+ });
855
+ }
856
+ exports.getAccountMetasForTokenlessMessage = getAccountMetasForTokenlessMessage;
857
+ function getAccountMetasForDepositMessage(message, hubChainId, tokenMessengerMinter) {
858
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
859
+ var l1Usdc, l2Usdc, tokenMessengerPda, tokenMinterPda, localTokenPda, tokenMessengerEventAuthorityPda, custodyTokenAccountPda, state, tokenProgram, vault, tokenPairPda, remoteTokenMessengerPda;
860
+ return tslib_1.__generator(this, function (_a) {
861
+ switch (_a.label) {
862
+ case 0:
863
+ l1Usdc = utils_2.EvmAddress.from(constants_1.TOKEN_SYMBOLS_MAP.USDC.addresses[hubChainId]);
864
+ l2Usdc = utils_2.SvmAddress.from(constants_1.TOKEN_SYMBOLS_MAP.USDC.addresses[(0, utils_2.chainIsProd)(hubChainId) ? constants_1.CHAIN_IDs.SOLANA : constants_1.CHAIN_IDs.SOLANA_DEVNET]);
865
+ return [4, (0, kit_1.getProgramDerivedAddress)({
866
+ programAddress: tokenMessengerMinter,
867
+ seeds: ["token_messenger"],
868
+ })];
869
+ case 1:
870
+ tokenMessengerPda = (_a.sent())[0];
871
+ return [4, (0, kit_1.getProgramDerivedAddress)({
872
+ programAddress: tokenMessengerMinter,
873
+ seeds: ["token_minter"],
874
+ })];
875
+ case 2:
876
+ tokenMinterPda = (_a.sent())[0];
877
+ return [4, (0, kit_1.getProgramDerivedAddress)({
878
+ programAddress: tokenMessengerMinter,
879
+ seeds: ["local_token", utils_2.bs58.decode(l2Usdc.toBase58())],
880
+ })];
881
+ case 3:
882
+ localTokenPda = (_a.sent())[0];
883
+ return [4, (0, kit_1.getProgramDerivedAddress)({
884
+ programAddress: tokenMessengerMinter,
885
+ seeds: ["__event_authority"],
886
+ })];
887
+ case 4:
888
+ tokenMessengerEventAuthorityPda = (_a.sent())[0];
889
+ return [4, (0, kit_1.getProgramDerivedAddress)({
890
+ programAddress: tokenMessengerMinter,
891
+ seeds: ["custody", utils_2.bs58.decode(l2Usdc.toBase58())],
892
+ })];
893
+ case 5:
894
+ custodyTokenAccountPda = (_a.sent())[0];
895
+ return [4, (0, _1.getStatePda)(contracts_1.SvmSpokeClient.SVM_SPOKE_PROGRAM_ADDRESS)];
896
+ case 6:
897
+ state = _a.sent();
898
+ tokenProgram = token_1.TOKEN_PROGRAM_ADDRESS;
899
+ return [4, getAssociatedTokenAddress(utils_2.SvmAddress.from(state), utils_2.SvmAddress.from(l2Usdc.toBase58()), tokenProgram)];
900
+ case 7:
901
+ vault = _a.sent();
902
+ return [4, (0, kit_1.getProgramDerivedAddress)({
903
+ programAddress: tokenMessengerMinter,
904
+ seeds: [
905
+ new Uint8Array(Buffer.from("token_pair")),
906
+ new Uint8Array(Buffer.from(String(message.sourceDomain))),
907
+ new Uint8Array(Buffer.from(l1Usdc.toBytes32().slice(2), "hex")),
908
+ ],
909
+ })];
910
+ case 8:
911
+ tokenPairPda = (_a.sent())[0];
912
+ return [4, (0, kit_1.getProgramDerivedAddress)({
913
+ programAddress: tokenMessengerMinter,
914
+ seeds: ["remote_token_messenger", String(message.sourceDomain)],
915
+ })];
916
+ case 9:
917
+ remoteTokenMessengerPda = (_a.sent())[0];
918
+ return [2, [
919
+ { address: tokenMessengerPda, role: kit_1.AccountRole.READONLY },
920
+ { address: remoteTokenMessengerPda, role: kit_1.AccountRole.READONLY },
921
+ { address: tokenMinterPda, role: kit_1.AccountRole.WRITABLE },
922
+ { address: localTokenPda, role: kit_1.AccountRole.WRITABLE },
923
+ { address: tokenPairPda, role: kit_1.AccountRole.READONLY },
924
+ { address: vault, role: kit_1.AccountRole.WRITABLE },
925
+ { address: custodyTokenAccountPda, role: kit_1.AccountRole.WRITABLE },
926
+ { address: token_1.TOKEN_PROGRAM_ADDRESS, role: kit_1.AccountRole.READONLY },
927
+ { address: tokenMessengerEventAuthorityPda, role: kit_1.AccountRole.READONLY },
928
+ { address: tokenMessengerMinter, role: kit_1.AccountRole.READONLY },
929
+ ]];
930
+ }
931
+ });
932
+ });
933
+ }
934
+ function getCCTPV1ReceiveMessageTx(solanaClient, signer, message, hubChainId) {
935
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
936
+ var messageTransmitterPda, eventAuthorityPda, cctpMessageReceiver, authorityPda, usedNonces, accountMetas, _a, messageBytes, input;
937
+ return tslib_1.__generator(this, function (_b) {
938
+ switch (_b.label) {
939
+ case 0: return [4, (0, kit_1.getProgramDerivedAddress)({
940
+ programAddress: contracts_1.MessageTransmitterClient.MESSAGE_TRANSMITTER_PROGRAM_ADDRESS,
941
+ seeds: ["message_transmitter"],
942
+ })];
943
+ case 1:
944
+ messageTransmitterPda = (_b.sent())[0];
945
+ return [4, (0, kit_1.getProgramDerivedAddress)({
946
+ programAddress: contracts_1.MessageTransmitterClient.MESSAGE_TRANSMITTER_PROGRAM_ADDRESS,
947
+ seeds: ["__event_authority"],
948
+ })];
949
+ case 2:
950
+ eventAuthorityPda = (_b.sent())[0];
951
+ cctpMessageReceiver = (0, _1.isDepositForBurnEvent)(message)
952
+ ? contracts_1.TokenMessengerMinterClient.TOKEN_MESSENGER_MINTER_PROGRAM_ADDRESS
953
+ : contracts_1.SvmSpokeClient.SVM_SPOKE_PROGRAM_ADDRESS;
954
+ return [4, (0, kit_1.getProgramDerivedAddress)({
955
+ programAddress: contracts_1.MessageTransmitterClient.MESSAGE_TRANSMITTER_PROGRAM_ADDRESS,
956
+ seeds: ["message_transmitter_authority", utils_2.bs58.decode(cctpMessageReceiver)],
957
+ })];
958
+ case 3:
959
+ authorityPda = (_b.sent())[0];
960
+ return [4, (0, _1.getCCTPNoncePda)(solanaClient, signer, message.nonce, message.sourceDomain)];
961
+ case 4:
962
+ usedNonces = _b.sent();
963
+ if (!(0, _1.isDepositForBurnEvent)(message)) return [3, 6];
964
+ return [4, getAccountMetasForDepositMessage(message, hubChainId, contracts_1.TokenMessengerMinterClient.TOKEN_MESSENGER_MINTER_PROGRAM_ADDRESS)];
965
+ case 5:
966
+ _a = _b.sent();
967
+ return [3, 8];
968
+ case 6: return [4, getAccountMetasForTokenlessMessage()];
969
+ case 7:
970
+ _a = _b.sent();
971
+ _b.label = 8;
972
+ case 8:
973
+ accountMetas = _a;
974
+ messageBytes = message.messageBytes.startsWith("0x")
975
+ ? Buffer.from(message.messageBytes.slice(2), "hex")
976
+ : Buffer.from(message.messageBytes, "hex");
977
+ input = {
978
+ program: contracts_1.MessageTransmitterClient.MESSAGE_TRANSMITTER_PROGRAM_ADDRESS,
979
+ payer: signer,
980
+ caller: signer,
981
+ authorityPda: authorityPda,
982
+ messageTransmitter: messageTransmitterPda,
983
+ eventAuthority: eventAuthorityPda,
984
+ usedNonces: usedNonces,
985
+ receiver: contracts_1.SvmSpokeClient.SVM_SPOKE_PROGRAM_ADDRESS,
986
+ systemProgram: system_1.SYSTEM_PROGRAM_ADDRESS,
987
+ message: messageBytes,
988
+ attestation: Buffer.from(message.attestation.slice(2), "hex"),
989
+ };
990
+ return [2, (0, exports.createReceiveMessageInstruction)(signer, solanaClient, input, accountMetas)];
991
+ }
992
+ });
993
+ });
994
+ }
995
+ exports.getCCTPV1ReceiveMessageTx = getCCTPV1ReceiveMessageTx;
996
+ function finalizeCCTPV1Messages(solanaClient, attestedMessages, signer, simulate, hubChainId) {
997
+ var _this = this;
998
+ if (simulate === void 0) { simulate = false; }
999
+ if (hubChainId === void 0) { hubChainId = 1; }
1000
+ return (0, utils_2.mapAsync)(attestedMessages, function (message) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
1001
+ var receiveMessageIx, result, _a, _b, _c, signedTransaction, signature, encodedTransaction;
1002
+ return tslib_1.__generator(this, function (_d) {
1003
+ switch (_d.label) {
1004
+ case 0: return [4, getCCTPV1ReceiveMessageTx(solanaClient, signer, message, hubChainId)];
1005
+ case 1:
1006
+ receiveMessageIx = _d.sent();
1007
+ if (!simulate) return [3, 4];
1008
+ _b = (_a = solanaClient)
1009
+ .simulateTransaction;
1010
+ _c = kit_1.getBase64EncodedWireTransaction;
1011
+ return [4, (0, kit_1.signTransactionMessageWithSigners)(receiveMessageIx)];
1012
+ case 2: return [4, _b.apply(_a, [_c.apply(void 0, [_d.sent()]),
1013
+ {
1014
+ encoding: "base64",
1015
+ }])
1016
+ .send()];
1017
+ case 3:
1018
+ result = _d.sent();
1019
+ if (result.value.err) {
1020
+ throw new Error(result.value.err.toString());
1021
+ }
1022
+ return [2, ""];
1023
+ case 4: return [4, (0, kit_1.signTransactionMessageWithSigners)(receiveMessageIx)];
1024
+ case 5:
1025
+ signedTransaction = _d.sent();
1026
+ signature = (0, kit_1.getSignatureFromTransaction)(signedTransaction);
1027
+ encodedTransaction = (0, kit_1.getBase64EncodedWireTransaction)(signedTransaction);
1028
+ return [4, solanaClient
1029
+ .sendTransaction(encodedTransaction, { preflightCommitment: "confirmed", encoding: "base64" })
1030
+ .send()];
1031
+ case 6:
1032
+ _d.sent();
1033
+ return [2, signature];
1034
+ }
1035
+ });
1036
+ }); });
1037
+ }
1038
+ exports.finalizeCCTPV1Messages = finalizeCCTPV1Messages;
785
1039
  //# sourceMappingURL=SpokeUtils.js.map