@across-protocol/sdk 4.2.9-alpha.0 → 4.2.9-alpha.2

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 (120) hide show
  1. package/dist/cjs/arch/evm/SpokeUtils.d.ts +5 -2
  2. package/dist/cjs/arch/evm/SpokeUtils.js +1 -0
  3. package/dist/cjs/arch/evm/SpokeUtils.js.map +1 -1
  4. package/dist/cjs/arch/svm/SpokeUtils.d.ts +16 -1
  5. package/dist/cjs/arch/svm/SpokeUtils.js +128 -27
  6. package/dist/cjs/arch/svm/SpokeUtils.js.map +1 -1
  7. package/dist/cjs/arch/svm/utils.d.ts +4 -0
  8. package/dist/cjs/arch/svm/utils.js +13 -1
  9. package/dist/cjs/arch/svm/utils.js.map +1 -1
  10. package/dist/cjs/clients/BundleDataClient/BundleDataClient.d.ts +2 -2
  11. package/dist/cjs/clients/BundleDataClient/BundleDataClient.js +3 -3
  12. package/dist/cjs/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  13. package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js +5 -5
  14. package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
  15. package/dist/cjs/clients/BundleDataClient/utils/MerkleTreeUtils.js +5 -1
  16. package/dist/cjs/clients/BundleDataClient/utils/MerkleTreeUtils.js.map +1 -1
  17. package/dist/cjs/clients/HubPoolClient.d.ts +1 -1
  18. package/dist/cjs/clients/HubPoolClient.js +9 -6
  19. package/dist/cjs/clients/HubPoolClient.js.map +1 -1
  20. package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js +1 -1
  21. package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
  22. package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js +28 -28
  23. package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
  24. package/dist/cjs/clients/mocks/MockSpokePoolClient.js +3 -1
  25. package/dist/cjs/clients/mocks/MockSpokePoolClient.js.map +1 -1
  26. package/dist/cjs/interfaces/HubPool.d.ts +1 -1
  27. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js +4 -4
  28. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  29. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.d.ts +7 -8
  30. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js +70 -62
  31. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
  32. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.d.ts +1 -1
  33. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js +2 -2
  34. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  35. package/dist/cjs/utils/AddressUtils.d.ts +3 -3
  36. package/dist/cjs/utils/AddressUtils.js +24 -9
  37. package/dist/cjs/utils/AddressUtils.js.map +1 -1
  38. package/dist/cjs/utils/TokenUtils.js +3 -3
  39. package/dist/cjs/utils/TokenUtils.js.map +1 -1
  40. package/dist/esm/arch/evm/SpokeUtils.d.ts +5 -2
  41. package/dist/esm/arch/evm/SpokeUtils.js +1 -0
  42. package/dist/esm/arch/evm/SpokeUtils.js.map +1 -1
  43. package/dist/esm/arch/svm/SpokeUtils.d.ts +46 -6
  44. package/dist/esm/arch/svm/SpokeUtils.js +157 -36
  45. package/dist/esm/arch/svm/SpokeUtils.js.map +1 -1
  46. package/dist/esm/arch/svm/utils.d.ts +10 -0
  47. package/dist/esm/arch/svm/utils.js +18 -1
  48. package/dist/esm/arch/svm/utils.js.map +1 -1
  49. package/dist/esm/clients/BundleDataClient/BundleDataClient.d.ts +2 -2
  50. package/dist/esm/clients/BundleDataClient/BundleDataClient.js +3 -3
  51. package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  52. package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js +5 -5
  53. package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
  54. package/dist/esm/clients/BundleDataClient/utils/MerkleTreeUtils.js +5 -1
  55. package/dist/esm/clients/BundleDataClient/utils/MerkleTreeUtils.js.map +1 -1
  56. package/dist/esm/clients/HubPoolClient.d.ts +1 -1
  57. package/dist/esm/clients/HubPoolClient.js +9 -6
  58. package/dist/esm/clients/HubPoolClient.js.map +1 -1
  59. package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js +1 -1
  60. package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
  61. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js +28 -28
  62. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
  63. package/dist/esm/clients/mocks/MockSpokePoolClient.js +3 -1
  64. package/dist/esm/clients/mocks/MockSpokePoolClient.js.map +1 -1
  65. package/dist/esm/interfaces/HubPool.d.ts +1 -1
  66. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js +4 -4
  67. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  68. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.d.ts +8 -9
  69. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js +74 -64
  70. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
  71. package/dist/esm/relayFeeCalculator/relayFeeCalculator.d.ts +1 -1
  72. package/dist/esm/relayFeeCalculator/relayFeeCalculator.js +3 -3
  73. package/dist/esm/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  74. package/dist/esm/utils/AddressUtils.d.ts +4 -3
  75. package/dist/esm/utils/AddressUtils.js +30 -12
  76. package/dist/esm/utils/AddressUtils.js.map +1 -1
  77. package/dist/esm/utils/TokenUtils.d.ts +14 -0
  78. package/dist/esm/utils/TokenUtils.js +3 -3
  79. package/dist/esm/utils/TokenUtils.js.map +1 -1
  80. package/dist/types/arch/evm/SpokeUtils.d.ts +5 -2
  81. package/dist/types/arch/evm/SpokeUtils.d.ts.map +1 -1
  82. package/dist/types/arch/svm/SpokeUtils.d.ts +46 -6
  83. package/dist/types/arch/svm/SpokeUtils.d.ts.map +1 -1
  84. package/dist/types/arch/svm/utils.d.ts +10 -0
  85. package/dist/types/arch/svm/utils.d.ts.map +1 -1
  86. package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts +2 -2
  87. package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -1
  88. package/dist/types/clients/BundleDataClient/utils/MerkleTreeUtils.d.ts.map +1 -1
  89. package/dist/types/clients/HubPoolClient.d.ts +1 -1
  90. package/dist/types/clients/HubPoolClient.d.ts.map +1 -1
  91. package/dist/types/clients/SpokePoolClient/SpokePoolClient.d.ts.map +1 -1
  92. package/dist/types/clients/mocks/MockSpokePoolClient.d.ts.map +1 -1
  93. package/dist/types/interfaces/HubPool.d.ts +1 -1
  94. package/dist/types/interfaces/HubPool.d.ts.map +1 -1
  95. package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts.map +1 -1
  96. package/dist/types/relayFeeCalculator/chain-queries/svmQuery.d.ts +8 -9
  97. package/dist/types/relayFeeCalculator/chain-queries/svmQuery.d.ts.map +1 -1
  98. package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts +1 -1
  99. package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts.map +1 -1
  100. package/dist/types/utils/AddressUtils.d.ts +4 -3
  101. package/dist/types/utils/AddressUtils.d.ts.map +1 -1
  102. package/dist/types/utils/TokenUtils.d.ts +14 -0
  103. package/dist/types/utils/TokenUtils.d.ts.map +1 -1
  104. package/package.json +1 -1
  105. package/src/arch/evm/SpokeUtils.ts +9 -1
  106. package/src/arch/svm/SpokeUtils.ts +149 -42
  107. package/src/arch/svm/utils.ts +19 -0
  108. package/src/clients/BundleDataClient/BundleDataClient.ts +5 -5
  109. package/src/clients/BundleDataClient/utils/DataworkerUtils.ts +5 -5
  110. package/src/clients/BundleDataClient/utils/MerkleTreeUtils.ts +7 -1
  111. package/src/clients/HubPoolClient.ts +13 -7
  112. package/src/clients/SpokePoolClient/EVMSpokePoolClient.ts +5 -5
  113. package/src/clients/SpokePoolClient/SpokePoolClient.ts +32 -29
  114. package/src/clients/mocks/MockSpokePoolClient.ts +3 -1
  115. package/src/interfaces/HubPool.ts +1 -1
  116. package/src/relayFeeCalculator/chain-queries/baseQuery.ts +4 -4
  117. package/src/relayFeeCalculator/chain-queries/svmQuery.ts +85 -89
  118. package/src/relayFeeCalculator/relayFeeCalculator.ts +10 -4
  119. package/src/utils/AddressUtils.ts +31 -14
  120. package/src/utils/TokenUtils.ts +3 -3
@@ -4,17 +4,21 @@ import { hashNonEmptyMessage } from "@across-protocol/contracts/dist/src/svm/web
4
4
  import {
5
5
  ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
6
6
  TOKEN_PROGRAM_ADDRESS,
7
+ fetchMint,
7
8
  getApproveCheckedInstruction,
9
+ getCreateAssociatedTokenIdempotentInstruction,
8
10
  } from "@solana-program/token";
9
11
  import {
10
12
  Address,
11
13
  address,
14
+ appendTransactionMessageInstruction,
12
15
  fetchEncodedAccount,
13
16
  fetchEncodedAccounts,
14
17
  getAddressEncoder,
15
18
  getProgramDerivedAddress,
16
19
  getU32Encoder,
17
20
  getU64Encoder,
21
+ pipe,
18
22
  some,
19
23
  type TransactionSigner,
20
24
  } from "@solana/kit";
@@ -22,19 +26,17 @@ import assert from "assert";
22
26
  import { arrayify, hexZeroPad, hexlify } from "ethers/lib/utils";
23
27
  import { Logger } from "winston";
24
28
 
25
- import { CHAIN_IDs } from "../../constants";
29
+ import { SYSTEM_PROGRAM_ADDRESS } from "@solana-program/system";
26
30
  import { Deposit, DepositWithBlock, FillStatus, FillWithBlock, RelayData } from "../../interfaces";
31
+ import { BigNumber, SvmAddress, chainIsSvm, chunk, isUnsafeDepositId, keccak256 } from "../../utils";
27
32
  import {
28
- BigNumber,
29
- SvmAddress,
30
- chainIsSvm,
31
- chunk,
32
- getTokenInfo,
33
- isDefined,
34
- isUnsafeDepositId,
35
- keccak256,
36
- } from "../../utils";
37
- import { SvmCpiEventsClient, getEventAuthority, getFillStatusPda, getStatePda, unwrapEventData } from "./";
33
+ SvmCpiEventsClient,
34
+ createDefaultTransaction,
35
+ getEventAuthority,
36
+ getFillStatusPda,
37
+ getStatePda,
38
+ unwrapEventData,
39
+ } from "./";
38
40
  import { SVMEventNames, SVMProvider } from "./types";
39
41
 
40
42
  /**
@@ -425,41 +427,146 @@ export function createTokenAccountsInstruction(
425
427
  }
426
428
 
427
429
  /**
428
- * @param mint Address of the token corresponding to the account being made.
429
- * @param amount Amount of the token to approve.
430
- * @param relayer Address of the relayer filling the deposit.
431
- * @param spokePool Address (program ID) of the SvmSpoke.
432
- * @returns A token approval instruction.
430
+ * Creates a fill instruction.
431
+ * @param signer - The signer of the transaction.
432
+ * @param solanaClient - The Solana client.
433
+ * @param fillInput - The fill input.
434
+ * @param tokenDecimals - The token decimals.
435
+ * @param createRecipientAtaIfNeeded - Whether to create a recipient token account.
436
+ * @returns The fill instruction.
433
437
  */
434
- export async function createApproveInstruction(
435
- mint: SvmAddress,
436
- amount: BigNumber,
437
- relayer: SvmAddress,
438
- spokePool: SvmAddress,
439
- mintDecimals?: number
440
- ) {
441
- const [relayerTokenAccount, statePda] = await Promise.all([
442
- getAssociatedTokenAddress(relayer, mint, TOKEN_PROGRAM_ADDRESS),
443
- getStatePda(spokePool.toV2Address()),
444
- ]);
438
+ export const createFillInstruction = async (
439
+ signer: TransactionSigner,
440
+ solanaClient: SVMProvider,
441
+ fillInput: SvmSpokeClient.FillRelayInput,
442
+ tokenDecimals: number,
443
+ createRecipientAtaIfNeeded: boolean = true
444
+ ) => {
445
+ const mintInfo = await fetchMint(solanaClient, fillInput.mint);
446
+ const approveIx = getApproveCheckedInstruction(
447
+ {
448
+ source: fillInput.relayerTokenAccount,
449
+ mint: fillInput.mint,
450
+ delegate: fillInput.delegate,
451
+ owner: fillInput.signer,
452
+ amount: (fillInput.relayData as SvmSpokeClient.RelayDataArgs).outputAmount,
453
+ decimals: tokenDecimals,
454
+ },
455
+ {
456
+ programAddress: mintInfo.programAddress,
457
+ }
458
+ );
445
459
 
446
- // If no mint decimals were supplied, then assign it to whatever value we have in TOKEN_SYMBOLS_MAP.
447
- // If this token is not in TOKEN_SYMBOLS_MAP, then throw an error.
448
- mintDecimals ??= getTokenInfo(mint.toBase58(), CHAIN_IDs.SOLANA)?.decimals;
449
- if (!isDefined(mintDecimals)) {
450
- throw new Error(`No mint decimals found for token ${mint.toBase58()}`);
451
- }
460
+ const getCreateAssociatedTokenIdempotentIx = () =>
461
+ getCreateAssociatedTokenIdempotentInstruction({
462
+ payer: signer,
463
+ owner: (fillInput.relayData as SvmSpokeClient.RelayDataArgs).recipient,
464
+ mint: fillInput.mint,
465
+ ata: fillInput.recipientTokenAccount,
466
+ systemProgram: SYSTEM_PROGRAM_ADDRESS,
467
+ tokenProgram: fillInput.tokenProgram,
468
+ });
452
469
 
453
- return getApproveCheckedInstruction({
454
- source: relayerTokenAccount,
455
- mint: mint.toV2Address(),
456
- delegate: statePda,
457
- owner: relayer.toV2Address(),
458
- amount: amount.toBigInt(),
459
- decimals: mintDecimals,
460
- });
461
- }
470
+ const createFillIx = await SvmSpokeClient.getFillRelayInstruction(fillInput);
471
+
472
+ return pipe(
473
+ await createDefaultTransaction(solanaClient, signer),
474
+ (tx) =>
475
+ createRecipientAtaIfNeeded ? appendTransactionMessageInstruction(getCreateAssociatedTokenIdempotentIx(), tx) : tx,
476
+ (tx) => appendTransactionMessageInstruction(approveIx, tx),
477
+ (tx) => appendTransactionMessageInstruction(createFillIx, tx)
478
+ );
479
+ };
462
480
 
481
+ /**
482
+ * Creates a deposit instruction.
483
+ * @param signer - The signer of the transaction.
484
+ * @param solanaClient - The Solana client.
485
+ * @param depositInput - The deposit input.
486
+ * @param tokenDecimals - The token decimals.
487
+ * @param createVaultAtaIfNeeded - Whether to create a vault token account.
488
+ * @returns The deposit instruction.
489
+ */
490
+ export const createDepositInstruction = async (
491
+ signer: TransactionSigner,
492
+ solanaClient: SVMProvider,
493
+ depositInput: SvmSpokeClient.DepositInput,
494
+ tokenDecimals: number,
495
+ createVaultAtaIfNeeded: boolean = true
496
+ ) => {
497
+ const getCreateAssociatedTokenIdempotentIx = () =>
498
+ getCreateAssociatedTokenIdempotentInstruction({
499
+ payer: signer,
500
+ owner: depositInput.state,
501
+ mint: depositInput.mint,
502
+ ata: depositInput.vault,
503
+ systemProgram: depositInput.systemProgram,
504
+ tokenProgram: depositInput.tokenProgram,
505
+ });
506
+ const mintInfo = await fetchMint(solanaClient, depositInput.mint);
507
+ const approveIx = getApproveCheckedInstruction(
508
+ {
509
+ source: depositInput.depositorTokenAccount,
510
+ mint: depositInput.mint,
511
+ delegate: depositInput.delegate,
512
+ owner: depositInput.depositor,
513
+ amount: depositInput.inputAmount,
514
+ decimals: tokenDecimals,
515
+ },
516
+ {
517
+ programAddress: mintInfo.programAddress,
518
+ }
519
+ );
520
+ const depositIx = await SvmSpokeClient.getDepositInstruction(depositInput);
521
+ return pipe(
522
+ await createDefaultTransaction(solanaClient, signer),
523
+ (tx) =>
524
+ createVaultAtaIfNeeded ? appendTransactionMessageInstruction(getCreateAssociatedTokenIdempotentIx(), tx) : tx,
525
+ (tx) => appendTransactionMessageInstruction(approveIx, tx),
526
+ (tx) => appendTransactionMessageInstruction(depositIx, tx)
527
+ );
528
+ };
529
+
530
+ /**
531
+ * Creates a request slow fill instruction.
532
+ * @param signer - The signer of the transaction.
533
+ * @param solanaClient - The Solana client.
534
+ * @param depositInput - The deposit input.
535
+ * @returns The request slow fill instruction.
536
+ */
537
+ export const createRequestSlowFillInstruction = async (
538
+ signer: TransactionSigner,
539
+ solanaClient: SVMProvider,
540
+ depositInput: SvmSpokeClient.RequestSlowFillInput
541
+ ) => {
542
+ const requestSlowFillIx = await SvmSpokeClient.getRequestSlowFillInstruction(depositInput);
543
+
544
+ return pipe(await createDefaultTransaction(solanaClient, signer), (tx) =>
545
+ appendTransactionMessageInstruction(requestSlowFillIx, tx)
546
+ );
547
+ };
548
+
549
+ /**
550
+ * Creates a close fill PDA instruction.
551
+ * @param signer - The signer of the transaction.
552
+ * @param solanaClient - The Solana client.
553
+ * @param fillStatusPda - The fill status PDA.
554
+ * @returns The close fill PDA instruction.
555
+ */
556
+ export const createCloseFillPdaInstruction = async (
557
+ signer: TransactionSigner,
558
+ solanaClient: SVMProvider,
559
+ fillStatusPda: Address
560
+ ) => {
561
+ const closeFillPdaIx = await SvmSpokeClient.getCloseFillPdaInstruction({
562
+ signer,
563
+ state: await getStatePda(SvmSpokeClient.SVM_SPOKE_PROGRAM_ADDRESS),
564
+ fillStatus: fillStatusPda,
565
+ });
566
+ return pipe(await createDefaultTransaction(solanaClient, signer), (tx) =>
567
+ appendTransactionMessageInstruction(closeFillPdaIx, tx)
568
+ );
569
+ };
463
570
  export async function getAssociatedTokenAddress(
464
571
  owner: SvmAddress,
465
572
  mint: SvmAddress,
@@ -10,6 +10,10 @@ import {
10
10
  getU32Encoder,
11
11
  isAddress,
12
12
  type TransactionSigner,
13
+ pipe,
14
+ createTransactionMessage,
15
+ setTransactionMessageFeePayerSigner,
16
+ setTransactionMessageLifetimeUsingBlockhash,
13
17
  } from "@solana/kit";
14
18
  import { SvmSpokeClient } from "@across-protocol/contracts";
15
19
  import { FillType, RelayData } from "../../interfaces";
@@ -280,3 +284,18 @@ export function getRandomSvmAddress() {
280
284
  const base58Address = bs58.encode(bytes);
281
285
  return address(base58Address);
282
286
  }
287
+
288
+ /**
289
+ * Creates a default v0 transaction skeleton.
290
+ * @param rpcClient - The Solana client.
291
+ * @param signer - The signer of the transaction.
292
+ * @returns The default transaction.
293
+ */
294
+ export const createDefaultTransaction = async (rpcClient: SVMProvider, signer: TransactionSigner) => {
295
+ const { value: latestBlockhash } = await rpcClient.getLatestBlockhash().send();
296
+ return pipe(
297
+ createTransactionMessage({ version: 0 }),
298
+ (tx) => setTransactionMessageFeePayerSigner(signer, tx),
299
+ (tx) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx)
300
+ );
301
+ };
@@ -676,15 +676,15 @@ export class BundleDataClient {
676
676
  return allRefunds;
677
677
  }
678
678
 
679
- getRefundsFor(bundleRefunds: CombinedRefunds, relayer: string, chainId: number, token: string): BigNumber {
680
- if (!bundleRefunds[chainId] || !bundleRefunds[chainId][token]) {
679
+ getRefundsFor(bundleRefunds: CombinedRefunds, relayer: Address, chainId: number, token: Address): BigNumber {
680
+ if (!bundleRefunds[chainId] || !bundleRefunds[chainId][token.toBytes32()]) {
681
681
  return BigNumber.from(0);
682
682
  }
683
- const allRefunds = bundleRefunds[chainId][token];
684
- return allRefunds && allRefunds[relayer] ? allRefunds[relayer] : BigNumber.from(0);
683
+ const allRefunds = bundleRefunds[chainId][token.toBytes32()];
684
+ return allRefunds && allRefunds[relayer.toBytes32()] ? allRefunds[relayer.toBytes32()] : BigNumber.from(0);
685
685
  }
686
686
 
687
- getTotalRefund(refunds: CombinedRefunds[], relayer: string, chainId: number, refundToken: string): BigNumber {
687
+ getTotalRefund(refunds: CombinedRefunds[], relayer: Address, chainId: number, refundToken: Address): BigNumber {
688
688
  return refunds.reduce((totalRefund, refunds) => {
689
689
  return totalRefund.add(this.getRefundsFor(refunds, relayer, chainId, refundToken));
690
690
  }, bnZero);
@@ -155,7 +155,7 @@ export function _buildPoolRebalanceRoot(
155
155
  // there are no relevant L1 running balances.
156
156
  if (
157
157
  !clients.hubPoolClient.l2TokenHasPoolRebalanceRoute(
158
- toAddressType(l2TokenAddress),
158
+ toAddressType(l2TokenAddress, repaymentChainId),
159
159
  repaymentChainId,
160
160
  mainnetBundleEndBlock
161
161
  )
@@ -164,7 +164,7 @@ export function _buildPoolRebalanceRoot(
164
164
  return;
165
165
  }
166
166
  const l1TokenCounterpart = clients.hubPoolClient.getL1TokenForL2TokenAtBlock(
167
- toAddressType(l2TokenAddress),
167
+ toAddressType(l2TokenAddress, repaymentChainId),
168
168
  repaymentChainId,
169
169
  mainnetBundleEndBlock
170
170
  );
@@ -187,7 +187,7 @@ export function _buildPoolRebalanceRoot(
187
187
  Object.entries(depositsForChain).forEach(([outputToken, deposits]) => {
188
188
  deposits.forEach((deposit) => {
189
189
  const l1TokenCounterpart = clients.hubPoolClient.getL1TokenForL2TokenAtBlock(
190
- toAddressType(outputToken),
190
+ toAddressType(outputToken, destinationChainId),
191
191
  destinationChainId,
192
192
  mainnetBundleEndBlock
193
193
  );
@@ -216,7 +216,7 @@ export function _buildPoolRebalanceRoot(
216
216
  Object.entries(slowFilledDepositsForChain).forEach(([outputToken, slowFilledDeposits]) => {
217
217
  slowFilledDeposits.forEach((deposit) => {
218
218
  const l1TokenCounterpart = clients.hubPoolClient.getL1TokenForL2TokenAtBlock(
219
- toAddressType(outputToken),
219
+ toAddressType(outputToken, destinationChainId),
220
220
  destinationChainId,
221
221
  mainnetBundleEndBlock
222
222
  );
@@ -286,7 +286,7 @@ export function _buildPoolRebalanceRoot(
286
286
  return;
287
287
  }
288
288
  const l1TokenCounterpart = clients.hubPoolClient.getL1TokenForL2TokenAtBlock(
289
- toAddressType(inputToken),
289
+ toAddressType(inputToken, originChainId),
290
290
  originChainId,
291
291
  mainnetBundleEndBlock
292
292
  );
@@ -21,6 +21,12 @@ export function buildPoolRebalanceLeafTree(poolRebalanceLeaves: PoolRebalanceLea
21
21
  }
22
22
 
23
23
  const paramType = getParamType("MerkleLibTest", "verifyPoolRebalance", "rebalance");
24
- const hashFn = (input: PoolRebalanceLeaf) => utils.keccak256(utils.defaultAbiCoder.encode([paramType], [input]));
24
+ const hashFn = (input: PoolRebalanceLeaf) => {
25
+ const ethersLeaf = {
26
+ ...input,
27
+ l1Tokens: input.l1Tokens.map((l1Token) => l1Token.toEvmAddress()),
28
+ };
29
+ return utils.keccak256(utils.defaultAbiCoder.encode([paramType], [ethersLeaf]));
30
+ };
25
31
  return new MerkleTree<PoolRebalanceLeaf>(poolRebalanceLeaves, hashFn);
26
32
  }
@@ -533,8 +533,8 @@ export class HubPoolClient extends BaseAbstractClient {
533
533
  return this.l1Tokens.find((token) => token.address.eq(l1Token));
534
534
  }
535
535
 
536
- getLpTokenInfoForL1Token(l1Token: string): LpToken | undefined {
537
- return this.lpTokens[l1Token];
536
+ getLpTokenInfoForL1Token(l1Token: EvmAddress): LpToken | undefined {
537
+ return this.lpTokens[l1Token.toEvmAddress()];
538
538
  }
539
539
 
540
540
  areTokensEquivalent(
@@ -920,7 +920,7 @@ export class HubPoolClient extends BaseAbstractClient {
920
920
  for (const event of events["CrossChainContractsSet"]) {
921
921
  const args = spreadEventWithBlockNumber(event) as CrossChainContractsSet & { spokePool: string };
922
922
  const dataToAdd: CrossChainContractsSet = {
923
- spokePool: toAddressType(args.spokePool),
923
+ spokePool: toAddressType(args.spokePool, this.chainId),
924
924
  blockNumber: args.blockNumber,
925
925
  txnRef: args.txnRef,
926
926
  logIndex: args.logIndex,
@@ -960,7 +960,7 @@ export class HubPoolClient extends BaseAbstractClient {
960
960
  // If the destination chain is SVM, then we need to convert the destination token to the Solana address.
961
961
  // This is because the HubPool contract only holds a truncated address for the USDC token and currently
962
962
  // only supports USDC as a destination token for Solana.
963
- let destinationToken = toAddressType(args.destinationToken);
963
+ let destinationToken = toAddressType(args.destinationToken, this.chainId);
964
964
  if (chainIsSvm(args.destinationChainId)) {
965
965
  const usdcTokenSol = TOKEN_SYMBOLS_MAP.USDC.addresses[args.destinationChainId];
966
966
  const svmUsdc = SvmAddress.from(usdcTokenSol);
@@ -982,7 +982,7 @@ export class HubPoolClient extends BaseAbstractClient {
982
982
  [args.l1Token, args.destinationChainId],
983
983
  [
984
984
  {
985
- l1Token: toAddressType(args.l1Token),
985
+ l1Token: toAddressType(args.l1Token, this.chainId),
986
986
  l2Token: destinationToken,
987
987
  blockNumber: args.blockNumber,
988
988
  txnIndex: args.txnIndex,
@@ -1041,7 +1041,13 @@ export class HubPoolClient extends BaseAbstractClient {
1041
1041
  this.proposedRootBundles.push(
1042
1042
  ...events["ProposeRootBundle"]
1043
1043
  .filter((event) => !this.configOverride.ignoredHubProposedBundles.includes(event.blockNumber))
1044
- .map((event) => spreadEventWithBlockNumber(event) as ProposedRootBundle)
1044
+ .map((_event) => {
1045
+ const args = spreadEventWithBlockNumber(_event) as ProposedRootBundle & { proposer: string };
1046
+ return {
1047
+ ...args,
1048
+ proposer: toAddressType(args.proposer, this.chainId),
1049
+ };
1050
+ })
1045
1051
  );
1046
1052
  }
1047
1053
 
@@ -1078,7 +1084,7 @@ export class HubPoolClient extends BaseAbstractClient {
1078
1084
  executedRootBundle.runningBalances = runningBalances.slice(0, nTokens);
1079
1085
  const executedRootBundleWithL1Tokens = {
1080
1086
  ...executedRootBundle,
1081
- l1Tokens: executedRootBundle.l1Tokens.map(toAddressType),
1087
+ l1Tokens: executedRootBundle.l1Tokens.map(toAddressType, this.chainId),
1082
1088
  };
1083
1089
  this.executedRootBundles.push(executedRootBundleWithL1Tokens);
1084
1090
  }
@@ -195,11 +195,11 @@ export class EVMSpokePoolClient extends SpokePoolClient {
195
195
 
196
196
  deposit = {
197
197
  ...spreadEventWithBlockNumber(event),
198
- inputToken: toAddressType(event.args.inputToken),
199
- outputToken: toAddressType(event.args.outputToken),
200
- depositor: toAddressType(event.args.depositor),
201
- recipient: toAddressType(event.args.recipient),
202
- exclusiveRelayer: toAddressType(event.args.exclusiveRelayer),
198
+ inputToken: toAddressType(event.args.inputToken, this.chainId),
199
+ outputToken: toAddressType(event.args.outputToken, event.args.destinationChainId),
200
+ depositor: toAddressType(event.args.depositor, this.chainId),
201
+ recipient: toAddressType(event.args.recipient, event.args.destinationChainId),
202
+ exclusiveRelayer: toAddressType(event.args.exclusiveRelayer, event.args.destinationChainId),
203
203
  originChainId: this.chainId,
204
204
  quoteBlockNumber: await this.getBlockNumber(Number(event.args["quoteTimestamp"])),
205
205
  fromLiteChain: true, // To be updated immediately afterwards.
@@ -508,8 +508,8 @@ export abstract class SpokePoolClient extends BaseAbstractClient {
508
508
  };
509
509
  this.tokensBridged.push({
510
510
  ...event,
511
- l2TokenAddress: toAddressType(event.l2TokenAddress),
512
- } as TokensBridged);
511
+ l2TokenAddress: toAddressType(event.l2TokenAddress, this.chainId),
512
+ });
513
513
  }
514
514
  }
515
515
 
@@ -525,13 +525,13 @@ export abstract class SpokePoolClient extends BaseAbstractClient {
525
525
  };
526
526
  return {
527
527
  ...event,
528
- depositor: toAddressType(event.depositor),
529
- recipient: toAddressType(event.recipient),
530
- inputToken: toAddressType(event.inputToken),
531
- outputToken: toAddressType(event.outputToken),
532
- exclusiveRelayer: toAddressType(event.exclusiveRelayer),
528
+ depositor: toAddressType(event.depositor, this.chainId),
529
+ recipient: toAddressType(event.recipient, event.destinationChainId),
530
+ inputToken: toAddressType(event.inputToken, this.chainId),
531
+ outputToken: toAddressType(event.outputToken, event.destinationChainId),
532
+ exclusiveRelayer: toAddressType(event.exclusiveRelayer, event.destinationChainId),
533
533
  } as DepositWithBlock;
534
- }) as DepositWithBlock[];
534
+ });
535
535
  if (depositEvents.length > 0) {
536
536
  this.log(
537
537
  "debug",
@@ -592,7 +592,7 @@ export abstract class SpokePoolClient extends BaseAbstractClient {
592
592
  const event = _event as SpeedUpWithBlock & { depositor: string; updatedRecipient: string };
593
593
  return {
594
594
  ...event,
595
- depositor: toAddressType(event.depositor),
595
+ depositor: toAddressType(event.depositor, this.chainId),
596
596
  updatedRecipient: toAddressType(event.updatedRecipient),
597
597
  } as SpeedUpWithBlock;
598
598
  });
@@ -636,13 +636,13 @@ export abstract class SpokePoolClient extends BaseAbstractClient {
636
636
  };
637
637
  return {
638
638
  ...event,
639
- depositor: toAddressType(event.depositor),
640
- recipient: toAddressType(event.recipient),
641
- inputToken: toAddressType(event.inputToken),
642
- outputToken: toAddressType(event.outputToken),
643
- exclusiveRelayer: toAddressType(event.exclusiveRelayer),
639
+ depositor: toAddressType(event.depositor, event.originChainId),
640
+ recipient: toAddressType(event.recipient, this.chainId),
641
+ inputToken: toAddressType(event.inputToken, event.originChainId),
642
+ outputToken: toAddressType(event.outputToken, this.chainId),
643
+ exclusiveRelayer: toAddressType(event.exclusiveRelayer, this.chainId),
644
644
  } as SlowFillRequestWithBlock;
645
- }) as SlowFillRequestWithBlock[];
645
+ });
646
646
  for (const event of slowFillRequests) {
647
647
  const slowFillRequest = {
648
648
  ...event,
@@ -681,18 +681,18 @@ export abstract class SpokePoolClient extends BaseAbstractClient {
681
681
  };
682
682
  return {
683
683
  ...event,
684
- depositor: toAddressType(event.depositor),
685
- recipient: toAddressType(event.recipient),
686
- inputToken: toAddressType(event.inputToken),
687
- outputToken: toAddressType(event.outputToken),
688
- exclusiveRelayer: toAddressType(event.exclusiveRelayer),
689
- relayer: toAddressType(event.relayer),
684
+ depositor: toAddressType(event.depositor, event.originChainId),
685
+ recipient: toAddressType(event.recipient, this.chainId),
686
+ inputToken: toAddressType(event.inputToken, event.originChainId),
687
+ outputToken: toAddressType(event.outputToken, this.chainId),
688
+ exclusiveRelayer: toAddressType(event.exclusiveRelayer, this.chainId),
689
+ relayer: toAddressType(event.relayer, this.chainId),
690
690
  relayExecutionInfo: {
691
691
  ...event.relayExecutionInfo,
692
- updatedRecipient: toAddressType(event.relayExecutionInfo.updatedRecipient),
692
+ updatedRecipient: toAddressType(event.relayExecutionInfo.updatedRecipient, this.chainId),
693
693
  },
694
694
  } as FillWithBlock;
695
- }) as FillWithBlock[];
695
+ });
696
696
 
697
697
  if (fillEvents.length > 0) {
698
698
  this.log("debug", `Using ${fillEvents.length} newly queried ${eventName} events for chain ${this.chainId}`, {
@@ -728,8 +728,9 @@ export abstract class SpokePoolClient extends BaseAbstractClient {
728
728
  });
729
729
 
730
730
  if (eventsToQuery.includes("EnabledDepositRoute")) {
731
- const enableDepositsEvents = (queryResults[eventsToQuery.indexOf("EnabledDepositRoute")] ??
732
- []) as EnabledDepositRouteWithBlock[];
731
+ const enableDepositsEvents = queryResults[
732
+ eventsToQuery.indexOf("EnabledDepositRoute")
733
+ ] as EnabledDepositRouteWithBlock[];
733
734
 
734
735
  for (const event of enableDepositsEvents) {
735
736
  assign(this.depositRoutes, [event.originToken, event.destinationChainId], event.enabled);
@@ -737,16 +738,18 @@ export abstract class SpokePoolClient extends BaseAbstractClient {
737
738
  }
738
739
 
739
740
  if (eventsToQuery.includes("RelayedRootBundle")) {
740
- const relayedRootBundleEvents = (queryResults[eventsToQuery.indexOf("RelayedRootBundle")] ??
741
- []) as RootBundleRelayWithBlock[];
741
+ const relayedRootBundleEvents = queryResults[
742
+ eventsToQuery.indexOf("RelayedRootBundle")
743
+ ] as RootBundleRelayWithBlock[];
742
744
  for (const event of relayedRootBundleEvents) {
743
745
  this.rootBundleRelays.push(event);
744
746
  }
745
747
  }
746
748
 
747
749
  if (eventsToQuery.includes("ExecutedRelayerRefundRoot")) {
748
- const refundEvents = (queryResults[eventsToQuery.indexOf("ExecutedRelayerRefundRoot")] ??
749
- []) as RelayerRefundExecutionWithBlock[];
750
+ const refundEvents = queryResults[
751
+ eventsToQuery.indexOf("ExecutedRelayerRefundRoot")
752
+ ] as RelayerRefundExecutionWithBlock[];
750
753
  for (const event of refundEvents) {
751
754
  this.relayerRefundExecutions.push(event);
752
755
  }
@@ -67,7 +67,9 @@ export class MockSpokePoolClient extends EVMSpokePoolClient {
67
67
 
68
68
  getDestinationTokenForDeposit(deposit: DepositWithBlock): Address {
69
69
  const override = this.destinationTokenForChainOverride[deposit.originChainId];
70
- return isDefined(override) ? toAddressType(override) : super.getDestinationTokenForDeposit(deposit);
70
+ return isDefined(override)
71
+ ? toAddressType(override, deposit.destinationChainId)
72
+ : super.getDestinationTokenForDeposit(deposit);
71
73
  }
72
74
 
73
75
  setLatestBlockNumber(blockNumber: number): void {
@@ -27,7 +27,7 @@ export interface ProposedRootBundle extends SortableEvent {
27
27
  poolRebalanceRoot: string;
28
28
  relayerRefundRoot: string;
29
29
  slowRelayRoot: string;
30
- proposer: string;
30
+ proposer: EvmAddress;
31
31
  }
32
32
 
33
33
  export type RealizedLpFee = {
@@ -74,7 +74,7 @@ export class QueryBase implements QueryInterface {
74
74
  */
75
75
  async getGasCosts(
76
76
  deposit: Omit<Deposit, "messageHash">,
77
- relayer = toAddressType(getDefaultSimulatedRelayerAddress(deposit.destinationChainId)),
77
+ relayer = toAddressType(getDefaultSimulatedRelayerAddress(deposit.destinationChainId), deposit.destinationChainId),
78
78
  options: Partial<{
79
79
  gasPrice: BigNumberish;
80
80
  gasUnits: BigNumberish;
@@ -124,7 +124,7 @@ export class QueryBase implements QueryInterface {
124
124
  */
125
125
  getUnsignedTxFromDeposit(
126
126
  deposit: Omit<Deposit, "messageHash">,
127
- relayer = toAddressType(getDefaultSimulatedRelayerAddress(deposit.destinationChainId))
127
+ relayer = toAddressType(getDefaultSimulatedRelayerAddress(deposit.destinationChainId), deposit.destinationChainId)
128
128
  ): Promise<PopulatedTransaction> {
129
129
  return populateV3Relay(this.spokePool, deposit, relayer);
130
130
  }
@@ -137,7 +137,7 @@ export class QueryBase implements QueryInterface {
137
137
  */
138
138
  async getNativeGasCost(
139
139
  deposit: Omit<Deposit, "messageHash">,
140
- relayer = toAddressType(getDefaultSimulatedRelayerAddress(deposit.destinationChainId))
140
+ relayer = toAddressType(getDefaultSimulatedRelayerAddress(deposit.destinationChainId), deposit.destinationChainId)
141
141
  ): Promise<BigNumber> {
142
142
  const unsignedTx = await this.getUnsignedTxFromDeposit(deposit, relayer);
143
143
  const voidSigner = new VoidSigner(relayer.toEvmAddress(), this.provider);
@@ -154,7 +154,7 @@ export class QueryBase implements QueryInterface {
154
154
  */
155
155
  async getOpStackL1DataFee(
156
156
  unsignedTx: PopulatedTransaction,
157
- relayer = toAddressType(getDefaultSimulatedRelayerAddress(unsignedTx.chainId)),
157
+ relayer = toAddressType(getDefaultSimulatedRelayerAddress(unsignedTx.chainId), unsignedTx.chainId),
158
158
  options: Partial<{
159
159
  opStackL2GasUnits: BigNumberish;
160
160
  opStackL1DataFeeMultiplier: BigNumber;