@across-protocol/sdk 4.2.16-alpha.4 → 4.2.16-alpha.6

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 (118) hide show
  1. package/dist/cjs/arch/evm/SpokeUtils.d.ts +8 -3
  2. package/dist/cjs/arch/evm/SpokeUtils.js +21 -21
  3. package/dist/cjs/arch/evm/SpokeUtils.js.map +1 -1
  4. package/dist/cjs/arch/svm/SpokeUtils.d.ts +8 -6
  5. package/dist/cjs/arch/svm/SpokeUtils.js +17 -17
  6. package/dist/cjs/arch/svm/SpokeUtils.js.map +1 -1
  7. package/dist/cjs/arch/svm/eventsClient.js +4 -2
  8. package/dist/cjs/arch/svm/eventsClient.js.map +1 -1
  9. package/dist/cjs/arch/svm/utils.js +1 -1
  10. package/dist/cjs/arch/svm/utils.js.map +1 -1
  11. package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.d.ts +71 -71
  12. package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.js +4 -2
  13. package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -1
  14. package/dist/cjs/clients/HubPoolClient.js +4 -3
  15. package/dist/cjs/clients/HubPoolClient.js.map +1 -1
  16. package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js +2 -1
  17. package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
  18. package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.d.ts +1 -1
  19. package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.js +6 -4
  20. package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.js.map +1 -1
  21. package/dist/cjs/interfaces/SpokePool.d.ts +7 -8
  22. package/dist/cjs/interfaces/SpokePool.js.map +1 -1
  23. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.d.ts +13 -5
  24. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js +21 -12
  25. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  26. package/dist/cjs/relayFeeCalculator/chain-queries/factory.js +1 -1
  27. package/dist/cjs/relayFeeCalculator/chain-queries/factory.js.map +1 -1
  28. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.d.ts +12 -4
  29. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js +42 -30
  30. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
  31. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.d.ts +1 -1
  32. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js +5 -5
  33. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  34. package/dist/cjs/utils/AddressUtils.d.ts +12 -8
  35. package/dist/cjs/utils/AddressUtils.js +33 -36
  36. package/dist/cjs/utils/AddressUtils.js.map +1 -1
  37. package/dist/cjs/utils/TokenUtils.js +5 -3
  38. package/dist/cjs/utils/TokenUtils.js.map +1 -1
  39. package/dist/esm/arch/evm/SpokeUtils.d.ts +9 -4
  40. package/dist/esm/arch/evm/SpokeUtils.js +24 -24
  41. package/dist/esm/arch/evm/SpokeUtils.js.map +1 -1
  42. package/dist/esm/arch/svm/SpokeUtils.d.ts +9 -7
  43. package/dist/esm/arch/svm/SpokeUtils.js +19 -19
  44. package/dist/esm/arch/svm/SpokeUtils.js.map +1 -1
  45. package/dist/esm/arch/svm/eventsClient.js +5 -3
  46. package/dist/esm/arch/svm/eventsClient.js.map +1 -1
  47. package/dist/esm/arch/svm/utils.js +2 -2
  48. package/dist/esm/arch/svm/utils.js.map +1 -1
  49. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.d.ts +71 -71
  50. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js +11 -4
  51. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -1
  52. package/dist/esm/clients/HubPoolClient.js +4 -3
  53. package/dist/esm/clients/HubPoolClient.js.map +1 -1
  54. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js +2 -1
  55. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
  56. package/dist/esm/clients/mocks/MockSvmCpiEventsClient.d.ts +1 -1
  57. package/dist/esm/clients/mocks/MockSvmCpiEventsClient.js +7 -5
  58. package/dist/esm/clients/mocks/MockSvmCpiEventsClient.js.map +1 -1
  59. package/dist/esm/interfaces/SpokePool.d.ts +7 -8
  60. package/dist/esm/interfaces/SpokePool.js.map +1 -1
  61. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.d.ts +16 -8
  62. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js +25 -16
  63. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  64. package/dist/esm/relayFeeCalculator/chain-queries/factory.js +2 -2
  65. package/dist/esm/relayFeeCalculator/chain-queries/factory.js.map +1 -1
  66. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.d.ts +14 -6
  67. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js +47 -34
  68. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
  69. package/dist/esm/relayFeeCalculator/relayFeeCalculator.d.ts +1 -1
  70. package/dist/esm/relayFeeCalculator/relayFeeCalculator.js +3 -3
  71. package/dist/esm/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  72. package/dist/esm/utils/AddressUtils.d.ts +12 -8
  73. package/dist/esm/utils/AddressUtils.js +36 -38
  74. package/dist/esm/utils/AddressUtils.js.map +1 -1
  75. package/dist/esm/utils/TokenUtils.d.ts +16 -0
  76. package/dist/esm/utils/TokenUtils.js +6 -4
  77. package/dist/esm/utils/TokenUtils.js.map +1 -1
  78. package/dist/types/arch/evm/SpokeUtils.d.ts +9 -4
  79. package/dist/types/arch/evm/SpokeUtils.d.ts.map +1 -1
  80. package/dist/types/arch/svm/SpokeUtils.d.ts +9 -7
  81. package/dist/types/arch/svm/SpokeUtils.d.ts.map +1 -1
  82. package/dist/types/arch/svm/eventsClient.d.ts.map +1 -1
  83. package/dist/types/arch/svm/utils.d.ts.map +1 -1
  84. package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts +71 -71
  85. package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts.map +1 -1
  86. package/dist/types/clients/HubPoolClient.d.ts.map +1 -1
  87. package/dist/types/clients/SpokePoolClient/SpokePoolClient.d.ts.map +1 -1
  88. package/dist/types/clients/mocks/MockSvmCpiEventsClient.d.ts +1 -1
  89. package/dist/types/clients/mocks/MockSvmCpiEventsClient.d.ts.map +1 -1
  90. package/dist/types/interfaces/SpokePool.d.ts +7 -8
  91. package/dist/types/interfaces/SpokePool.d.ts.map +1 -1
  92. package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts +16 -8
  93. package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts.map +1 -1
  94. package/dist/types/relayFeeCalculator/chain-queries/factory.d.ts.map +1 -1
  95. package/dist/types/relayFeeCalculator/chain-queries/svmQuery.d.ts +14 -6
  96. package/dist/types/relayFeeCalculator/chain-queries/svmQuery.d.ts.map +1 -1
  97. package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts +1 -1
  98. package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts.map +1 -1
  99. package/dist/types/utils/AddressUtils.d.ts +12 -8
  100. package/dist/types/utils/AddressUtils.d.ts.map +1 -1
  101. package/dist/types/utils/TokenUtils.d.ts +16 -0
  102. package/dist/types/utils/TokenUtils.d.ts.map +1 -1
  103. package/package.json +1 -1
  104. package/src/arch/evm/SpokeUtils.ts +42 -27
  105. package/src/arch/svm/SpokeUtils.ts +25 -30
  106. package/src/arch/svm/eventsClient.ts +40 -8
  107. package/src/arch/svm/utils.ts +2 -2
  108. package/src/clients/BundleDataClient/utils/SuperstructUtils.ts +12 -4
  109. package/src/clients/HubPoolClient.ts +5 -4
  110. package/src/clients/SpokePoolClient/SpokePoolClient.ts +4 -1
  111. package/src/clients/mocks/MockSvmCpiEventsClient.ts +8 -5
  112. package/src/interfaces/SpokePool.ts +8 -8
  113. package/src/relayFeeCalculator/chain-queries/baseQuery.ts +33 -16
  114. package/src/relayFeeCalculator/chain-queries/factory.ts +2 -2
  115. package/src/relayFeeCalculator/chain-queries/svmQuery.ts +48 -37
  116. package/src/relayFeeCalculator/relayFeeCalculator.ts +3 -9
  117. package/src/utils/AddressUtils.ts +39 -51
  118. package/src/utils/TokenUtils.ts +6 -4
@@ -14,8 +14,8 @@ import {
14
14
  union,
15
15
  type,
16
16
  } from "superstruct";
17
- import { UNDEFINED_MESSAGE_HASH } from "../../../constants";
18
- import { BigNumber, toAddressType, Address } from "../../../utils";
17
+ import { CHAIN_IDs, UNDEFINED_MESSAGE_HASH } from "../../../constants";
18
+ import { BigNumber, EvmAddress, RawAddress, SvmAddress, toAddressType } from "../../../utils";
19
19
 
20
20
  const PositiveIntegerStringSS = pattern(string(), /\d+/);
21
21
  const Web3AddressSS = pattern(string(), /^0x[a-fA-F0-9]{40}$/);
@@ -31,8 +31,16 @@ const BigNumberType = coerce(instance(BigNumber), union([string(), number()]), (
31
31
  }
32
32
  });
33
33
 
34
- const AddressType = coerce(instance(Address), string(), (value) => {
35
- return toAddressType(value, 1); // @todo Don't merge without fixing this!
34
+ // Accept any concrete implementation of `Address` (Evm, Svm, or Raw) but avoid using the
35
+ // abstract `Address` class directly to keep TypeScript happy.
36
+ const AddressInstanceSS = union([instance(EvmAddress), instance(SvmAddress), instance(RawAddress)]);
37
+
38
+ const AddressType = coerce(AddressInstanceSS, string(), (value) => {
39
+ // Addresses are posted to arweave in their native format (base16 for EVM, base58 for SVM). The chainId for
40
+ // for the event data is not directly available, so infer it based on the shape of the address. RawAddress
41
+ // will be instantiated if the address format does not match the expected family.
42
+ const chainId = value.startsWith("0x") ? CHAIN_IDs.MAINNET : CHAIN_IDs.SOLANA;
43
+ return toAddressType(value, chainId);
36
44
  });
37
45
 
38
46
  const FillTypeSS = number();
@@ -1086,11 +1086,12 @@ export class HubPoolClient extends BaseAbstractClient {
1086
1086
  );
1087
1087
  }
1088
1088
  executedRootBundle.runningBalances = runningBalances.slice(0, nTokens);
1089
- const executedRootBundleWithL1Tokens = {
1089
+ this.executedRootBundles.push({
1090
1090
  ...executedRootBundle,
1091
- l1Tokens: l1Tokens.map((l1Token) => EvmAddress.from(String(l1Token))),
1092
- };
1093
- this.executedRootBundles.push(executedRootBundleWithL1Tokens);
1091
+ l1Tokens: l1Tokens.map((token: string) => {
1092
+ return EvmAddress.from(token, "base16");
1093
+ }),
1094
+ });
1094
1095
  }
1095
1096
  }
1096
1097
 
@@ -588,7 +588,10 @@ export abstract class SpokePoolClient extends BaseAbstractClient {
588
588
  .map((_event) => {
589
589
  const event = _event as SpeedUpWithBlock & { depositor: string; updatedRecipient: string };
590
590
 
591
- if (!EvmAddress.validate(ethersUtils.arrayify(event.updatedRecipient))) {
591
+ const invalid = [event.depositor, event.updatedRecipient].some(
592
+ (addr) => !EvmAddress.validate(ethersUtils.arrayify(addr))
593
+ );
594
+ if (invalid) {
592
595
  return;
593
596
  }
594
597
 
@@ -1,4 +1,5 @@
1
1
  import assert from "assert";
2
+ import { utils as ethersUtils } from "ethers";
2
3
  import { createHash } from "crypto";
3
4
  import { hexlify, arrayify, hexZeroPad } from "ethers/lib/utils";
4
5
  import { random } from "lodash";
@@ -17,9 +18,11 @@ import {
17
18
  SVMProvider,
18
19
  getRandomSvmAddress,
19
20
  } from "../../arch/svm";
20
- import { bnZero, bnOne, bs58, getCurrentTime, randomAddress, EvmAddress } from "../../utils";
21
+ import { bnZero, bnOne, bs58, getCurrentTime, randomAddress, EvmAddress, SvmAddress } from "../../utils";
21
22
  import { FillType } from "../../interfaces";
22
23
 
24
+ const randomBytes = (n: number) => ethersUtils.hexlify(ethersUtils.randomBytes(n));
25
+
23
26
  export class MockSvmCpiEventsClient extends SvmCpiEventsClient {
24
27
  private events: Record<EventName, EventWithData[]> = {} as Record<EventName, EventWithData[]>;
25
28
  private slotHeight: bigint = BigInt(0);
@@ -75,9 +78,9 @@ export class MockSvmCpiEventsClient extends SvmCpiEventsClient {
75
78
 
76
79
  destinationChainId ??= BigInt(random(1, 42161, false));
77
80
  const depositor = deposit.depositor ?? getRandomSvmAddress();
78
- const recipient = deposit.recipient ?? EvmAddress.from(randomAddress()).toBase58();
81
+ const recipient = deposit.recipient ?? SvmAddress.from(randomBytes(32), "base16").toBase58();
79
82
  const inputToken = deposit.inputToken ?? getRandomSvmAddress();
80
- const outputToken = deposit.outputToken ?? EvmAddress.from(randomAddress()).toBase58();
83
+ const outputToken = deposit.outputToken ?? SvmAddress.from(randomBytes(32), "base16").toBase58();
81
84
  inputAmount ??= BigInt(random(1, 1000, false));
82
85
  outputAmount ??= (inputAmount * BigInt(95)) / BigInt(100);
83
86
  const message = deposit.message ?? new Uint8Array(32);
@@ -158,9 +161,9 @@ export class MockSvmCpiEventsClient extends SvmCpiEventsClient {
158
161
  let { depositId, originChainId } = slowFillRequest;
159
162
  depositId ??= Uint8Array.from([random(1, 100_000, false)]);
160
163
  originChainId ??= BigInt(random(1, 42161, false));
161
- const depositor = slowFillRequest.depositor ?? EvmAddress.from(randomAddress()).toBase58();
164
+ const depositor = slowFillRequest.depositor ?? SvmAddress.from(randomBytes(32)).toBase58();
162
165
  const recipient = slowFillRequest.recipient ?? getRandomSvmAddress();
163
- const inputToken = slowFillRequest.inputToken ?? EvmAddress.from(randomAddress()).toBase58();
166
+ const inputToken = slowFillRequest.inputToken ?? SvmAddress.from(randomBytes(32)).toBase58();
164
167
  const outputToken = slowFillRequest.outputToken ?? getRandomSvmAddress();
165
168
 
166
169
  const args = {
@@ -18,14 +18,17 @@ export interface RelayData {
18
18
  exclusivityDeadline: number;
19
19
  }
20
20
 
21
- export interface Deposit extends RelayData {
21
+ export interface SpeedUpCommon {
22
+ updatedRecipient: Address;
23
+ updatedOutputAmount: BigNumber;
24
+ updatedMessage: string;
25
+ }
26
+
27
+ export interface Deposit extends RelayData, Partial<SpeedUpCommon> {
22
28
  messageHash: string;
23
29
  destinationChainId: number;
24
30
  quoteTimestamp: number;
25
31
  speedUpSignature?: string;
26
- updatedRecipient?: Address;
27
- updatedOutputAmount?: BigNumber;
28
- updatedMessage?: string;
29
32
  fromLiteChain: boolean;
30
33
  toLiteChain: boolean;
31
34
  }
@@ -78,14 +81,11 @@ export interface EnabledDepositRoute {
78
81
  }
79
82
 
80
83
  export interface EnabledDepositRouteWithBlock extends EnabledDepositRoute, SortableEvent {}
81
- export interface SpeedUp {
84
+ export interface SpeedUp extends SpeedUpCommon {
82
85
  depositor: EvmAddress;
83
86
  depositorSignature: string;
84
87
  depositId: BigNumber;
85
88
  originChainId: number;
86
- updatedRecipient: Address;
87
- updatedOutputAmount: BigNumber;
88
- updatedMessage: string;
89
89
  }
90
90
 
91
91
  export interface SpeedUpWithBlock extends SpeedUp, SortableEvent {}
@@ -1,14 +1,14 @@
1
1
  import { L2Provider } from "@eth-optimism/sdk/dist/interfaces/l2-provider";
2
2
  import { isL2Provider as isOptimismL2Provider } from "@eth-optimism/sdk/dist/l2-provider";
3
-
4
3
  import { PopulatedTransaction, providers, VoidSigner } from "ethers";
5
4
  import { Coingecko } from "../../coingecko";
6
5
  import { CHAIN_IDs } from "../../constants";
7
- import { Deposit } from "../../interfaces";
6
+ import { RelayData } from "../../interfaces";
8
7
  import { SpokePool, SpokePool__factory } from "../../typechain";
9
8
  import { populateV3Relay } from "../../arch/evm";
10
9
  import {
11
10
  BigNumberish,
11
+ EvmAddress,
12
12
  TransactionCostEstimate,
13
13
  BigNumber,
14
14
  toBNWei,
@@ -19,7 +19,7 @@ import {
19
19
  Address,
20
20
  } from "../../utils";
21
21
  import assert from "assert";
22
- import { Logger, QueryInterface, getDefaultSimulatedRelayerAddress } from "../relayFeeCalculator";
22
+ import { Logger, QueryInterface, getDefaultRelayer } from "../relayFeeCalculator";
23
23
  import { Transport } from "viem";
24
24
  import { getGasPriceEstimate } from "../../gasPriceOracle";
25
25
  import { EvmProvider } from "../../arch/evm/types";
@@ -64,7 +64,7 @@ export class QueryBase implements QueryInterface {
64
64
 
65
65
  /**
66
66
  * Retrieves the current gas costs of performing a fillRelay contract at the referenced SpokePool.
67
- * @param deposit V3 deposit instance.
67
+ * @param relayData RelayData instance, supplemented with destinationChainId
68
68
  * @param relayerAddress Relayer address to simulate with.
69
69
  * @param options
70
70
  * @param options.gasPrice Optional gas price to use for the simulation.
@@ -73,8 +73,8 @@ export class QueryBase implements QueryInterface {
73
73
  * @returns The gas estimate for this function call (multiplied with the optional buffer).
74
74
  */
75
75
  async getGasCosts(
76
- deposit: Omit<Deposit, "messageHash">,
77
- relayer = toAddressType(getDefaultSimulatedRelayerAddress(deposit.destinationChainId), deposit.destinationChainId),
76
+ relayData: RelayData & { destinationChainId: number },
77
+ relayer = toAddressType(getDefaultRelayer(relayData.destinationChainId), relayData.destinationChainId),
78
78
  options: Partial<{
79
79
  gasPrice: BigNumberish;
80
80
  gasUnits: BigNumberish;
@@ -93,7 +93,12 @@ export class QueryBase implements QueryInterface {
93
93
  transport,
94
94
  } = options;
95
95
 
96
- const tx = await this.getUnsignedTxFromDeposit(deposit, relayer);
96
+ const { recipient, outputToken, exclusiveRelayer } = relayData;
97
+ assert(recipient.isEVM(), `getGasCosts: recipient not an EVM address (${recipient})`);
98
+ assert(outputToken.isEVM(), `getGasCosts: outputToken not an EVM address (${outputToken})`);
99
+ assert(exclusiveRelayer.isEVM(), `getGasCosts: exclusiveRelayer not an EVM address (${exclusiveRelayer})`);
100
+
101
+ const tx = await this.getUnsignedTxFromDeposit({ ...relayData, recipient, outputToken, exclusiveRelayer }, relayer);
97
102
  const {
98
103
  nativeGasCost,
99
104
  tokenGasCost,
@@ -118,28 +123,40 @@ export class QueryBase implements QueryInterface {
118
123
 
119
124
  /**
120
125
  * @notice Return ethers.PopulatedTransaction for a fill based on input deposit args
121
- * @param deposit
126
+ * @param relayData RelayData instance, supplemented with destinationChainId
122
127
  * @param relayer Sender of PopulatedTransaction
123
128
  * @returns PopulatedTransaction
124
129
  */
125
130
  getUnsignedTxFromDeposit(
126
- deposit: Omit<Deposit, "messageHash">,
127
- relayer = toAddressType(getDefaultSimulatedRelayerAddress(deposit.destinationChainId), deposit.destinationChainId)
131
+ relayData: Omit<RelayData, "recipient" | "outputToken"> & {
132
+ destinationChainId: number;
133
+ recipient: EvmAddress;
134
+ outputToken: EvmAddress;
135
+ },
136
+ relayer = toAddressType(getDefaultRelayer(relayData.destinationChainId), relayData.destinationChainId)
128
137
  ): Promise<PopulatedTransaction> {
129
- return populateV3Relay(this.spokePool, deposit, relayer);
138
+ return populateV3Relay(this.spokePool, relayData, relayer);
130
139
  }
131
140
 
132
141
  /**
133
142
  * @notice Return the gas cost of a simulated transaction
134
- * @param deposit
143
+ * @param relayData RelayData instance, supplemented with destinationChainId
135
144
  * @param relayer Sender of PopulatedTransaction
136
145
  * @returns Estimated gas cost based on ethers.VoidSigner's gas estimation
137
146
  */
138
147
  async getNativeGasCost(
139
- deposit: Omit<Deposit, "messageHash">,
140
- relayer = toAddressType(getDefaultSimulatedRelayerAddress(deposit.destinationChainId), deposit.destinationChainId)
148
+ relayData: RelayData & { destinationChainId: number },
149
+ relayer = toAddressType(getDefaultRelayer(relayData.destinationChainId), relayData.destinationChainId)
141
150
  ): Promise<BigNumber> {
142
- const unsignedTx = await this.getUnsignedTxFromDeposit(deposit, relayer);
151
+ const { recipient, outputToken, exclusiveRelayer } = relayData;
152
+ assert(recipient.isEVM(), `getNativeGasCost: recipient not an EVM address (${recipient})`);
153
+ assert(outputToken.isEVM(), `getNativeGasCost: outputToken not an EVM address (${outputToken})`);
154
+ assert(exclusiveRelayer.isEVM(), `getNativeGasCost: exclusiveRelayer not an EVM address (${exclusiveRelayer})`);
155
+
156
+ const unsignedTx = await this.getUnsignedTxFromDeposit(
157
+ { ...relayData, recipient, outputToken, exclusiveRelayer },
158
+ relayer
159
+ );
143
160
  const voidSigner = new VoidSigner(relayer.toEvmAddress(), this.provider);
144
161
  return voidSigner.estimateGas(unsignedTx);
145
162
  }
@@ -154,7 +171,7 @@ export class QueryBase implements QueryInterface {
154
171
  */
155
172
  async getOpStackL1DataFee(
156
173
  unsignedTx: PopulatedTransaction,
157
- relayer = toAddressType(getDefaultSimulatedRelayerAddress(unsignedTx.chainId), CHAIN_IDs.MAINNET),
174
+ relayer = toAddressType(getDefaultRelayer(unsignedTx.chainId), CHAIN_IDs.MAINNET),
158
175
  options: Partial<{
159
176
  opStackL2GasUnits: BigNumberish;
160
177
  opStackL1DataFeeMultiplier: BigNumber;
@@ -7,7 +7,7 @@ import { CUSTOM_GAS_TOKENS } from "../../constants";
7
7
  import { chainIsOPStack, isDefined, chainIsSvm, SvmAddress } from "../../utils";
8
8
  import { QueryBase } from "./baseQuery";
9
9
  import { SVMProvider as svmProvider } from "../../arch/svm";
10
- import { DEFAULT_LOGGER, getDefaultSimulatedRelayerAddress, Logger } from "../relayFeeCalculator";
10
+ import { DEFAULT_LOGGER, getDefaultRelayer, Logger } from "../relayFeeCalculator";
11
11
  import { CustomGasTokenQueries } from "./customGasToken";
12
12
  import { SvmQuery } from "./svmQuery";
13
13
 
@@ -25,7 +25,7 @@ export class QueryBase__factory {
25
25
  provider: providers.Provider | svmProvider,
26
26
  symbolMapping = TOKEN_SYMBOLS_MAP,
27
27
  spokePoolAddress = getDeployedAddress("SpokePool", chainId),
28
- simulatedRelayerAddress = getDefaultSimulatedRelayerAddress(chainId),
28
+ simulatedRelayerAddress = getDefaultRelayer(chainId),
29
29
  coingeckoProApiKey?: string,
30
30
  logger: Logger = DEFAULT_LOGGER,
31
31
  coingeckoBaseCurrency = "eth"
@@ -1,3 +1,4 @@
1
+ import assert from "assert";
1
2
  import { SvmSpokeClient } from "@across-protocol/contracts";
2
3
  import { intToU8Array32 } from "@across-protocol/contracts/dist/src/svm/web3-v1/conversionUtils";
3
4
  import { SYSTEM_PROGRAM_ADDRESS } from "@solana-program/system";
@@ -17,7 +18,7 @@ import {
17
18
  import { Coingecko } from "../../coingecko";
18
19
  import { CHAIN_IDs } from "../../constants";
19
20
  import { getGasPriceEstimate } from "../../gasPriceOracle";
20
- import { Deposit } from "../../interfaces";
21
+ import { RelayData } from "../../interfaces";
21
22
  import {
22
23
  BigNumber,
23
24
  BigNumberish,
@@ -27,7 +28,7 @@ import {
27
28
  toAddressType,
28
29
  toBN,
29
30
  } from "../../utils";
30
- import { Logger, QueryInterface, getDefaultSimulatedRelayerAddress } from "../relayFeeCalculator";
31
+ import { Logger, QueryInterface, getDefaultRelayer } from "../relayFeeCalculator";
31
32
  import { SymbolMappingType } from "./";
32
33
 
33
34
  /**
@@ -65,7 +66,7 @@ export class SvmQuery implements QueryInterface {
65
66
 
66
67
  /**
67
68
  * Retrieves the current gas costs of performing a fillRelay contract at the referenced SpokePool.
68
- * @param deposit V3 deposit instance.
69
+ * @param relayData RelayData instance, supplemented with destinationChainId
69
70
  * @param _relayer Relayer address to simulate with.
70
71
  * @param options
71
72
  * @param options.gasPrice Optional gas price to use for the simulation.
@@ -74,8 +75,8 @@ export class SvmQuery implements QueryInterface {
74
75
  * @returns The gas estimate for this function call (multiplied with the optional buffer).
75
76
  */
76
77
  async getGasCosts(
77
- deposit: Omit<Deposit, "messageHash">,
78
- relayer = toAddressType(getDefaultSimulatedRelayerAddress(deposit.destinationChainId), deposit.destinationChainId),
78
+ relayData: RelayData & { destinationChainId: number },
79
+ relayer = toAddressType(getDefaultRelayer(relayData.destinationChainId), relayData.destinationChainId),
79
80
  options: Partial<{
80
81
  gasPrice: BigNumberish;
81
82
  gasUnits: BigNumberish;
@@ -83,7 +84,12 @@ export class SvmQuery implements QueryInterface {
83
84
  priorityFeeMultiplier: BigNumber;
84
85
  }> = {}
85
86
  ): Promise<TransactionCostEstimate> {
86
- const fillRelayTx = await this.getFillRelayTx(deposit, relayer);
87
+ const { recipient, outputToken, exclusiveRelayer } = relayData;
88
+ assert(recipient.isSVM(), `getGasCosts: recipient not an SVM address (${recipient})`);
89
+ assert(outputToken.isSVM(), `getGasCosts: outputToken not an SVM address (${outputToken})`);
90
+ assert(exclusiveRelayer.isSVM(), `getGasCosts: exclusiveRelayer not an SVM address (${exclusiveRelayer})`);
91
+
92
+ const fillRelayTx = await this.getFillRelayTx({ ...relayData, recipient, outputToken, exclusiveRelayer }, relayer);
87
93
 
88
94
  const [computeUnitsConsumed, gasPriceEstimate] = await Promise.all([
89
95
  toBN(await this.computeUnitEstimator(fillRelayTx)),
@@ -114,39 +120,45 @@ export class SvmQuery implements QueryInterface {
114
120
  * @returns Estimated gas cost in compute units
115
121
  */
116
122
  async getNativeGasCost(
117
- deposit: Omit<Deposit, "messageHash">,
118
- _relayer = toAddressType(getDefaultSimulatedRelayerAddress(deposit.destinationChainId), deposit.destinationChainId)
123
+ deposit: RelayData & { destinationChainId: number },
124
+ _relayer = toAddressType(getDefaultRelayer(deposit.destinationChainId), deposit.destinationChainId)
119
125
  ): Promise<BigNumber> {
120
- const fillRelayTx = await this.getFillRelayTx(deposit, _relayer);
126
+ const { recipient, outputToken, exclusiveRelayer } = deposit;
127
+ assert(recipient.isSVM(), `getNativeGasCost: recipient not an SVM address (${recipient})`);
128
+ assert(outputToken.isSVM(), `getNativeGasCost: outputToken not an SVM address (${outputToken})`);
129
+ assert(exclusiveRelayer.isSVM(), `getNativeGasCost: exclusiveRelayer not an SVM address (${exclusiveRelayer})`);
130
+
131
+ const fillRelayTx = await this.getFillRelayTx({ ...deposit, recipient, outputToken, exclusiveRelayer }, _relayer);
121
132
  return toBN(await this.computeUnitEstimator(fillRelayTx));
122
133
  }
123
134
 
124
135
  /**
125
136
  * @notice Return the fillRelay transaction for a given deposit
126
- * @param deposit
137
+ * @param relayData RelayData instance, supplemented with destinationChainId
127
138
  * @param relayer SVM address of the relayer
128
139
  * @returns FillRelay transaction
129
140
  */
130
141
  async getFillRelayTx(
131
- deposit: Omit<Deposit, "messageHash">,
132
- relayer = toAddressType(getDefaultSimulatedRelayerAddress(deposit.destinationChainId), deposit.destinationChainId),
133
- repaymentChainId = deposit.destinationChainId,
134
- repaymentAddress = toAddressType(
135
- getDefaultSimulatedRelayerAddress(deposit.destinationChainId),
136
- deposit.destinationChainId
137
- )
142
+ relayData: Omit<RelayData, "recipent" | "outputToken"> & {
143
+ destinationChainId: number;
144
+ recipient: SvmAddress;
145
+ outputToken: SvmAddress;
146
+ },
147
+ relayer = toAddressType(getDefaultRelayer(relayData.destinationChainId), relayData.destinationChainId),
148
+ repaymentChainId = relayData.destinationChainId,
149
+ repaymentAddress = toAddressType(getDefaultRelayer(relayData.destinationChainId), relayData.destinationChainId)
138
150
  ) {
139
- const {
140
- depositor,
141
- recipient: _recipient,
142
- inputToken,
143
- outputToken: _outputToken,
144
- exclusiveRelayer,
145
- destinationChainId,
146
- } = deposit;
151
+ const { depositor, recipient, inputToken, outputToken, exclusiveRelayer, destinationChainId } = relayData;
152
+
153
+ // tsc appeasement...should be unnecessary, but isn't. @todo Identify why.
154
+ assert(recipient.isSVM(), `getFillRelayTx: recipient not an SVM address (${recipient})`);
155
+ assert(
156
+ repaymentAddress.isValidOn(repaymentChainId),
157
+ `getFillRelayTx: repayment address ${repaymentAddress} not valid on chain ${repaymentChainId})`
158
+ );
147
159
 
148
160
  const program = toAddress(this.spokePool);
149
- const _relayDataHash = getRelayDataHash(deposit, destinationChainId);
161
+ const _relayDataHash = getRelayDataHash(relayData, destinationChainId);
150
162
  const relayDataHash = new Uint8Array(Buffer.from(_relayDataHash.slice(2), "hex"));
151
163
 
152
164
  const [state, delegate] = await Promise.all([
@@ -154,30 +166,29 @@ export class SvmQuery implements QueryInterface {
154
166
  getFillRelayDelegatePda(relayDataHash, BigInt(repaymentChainId), toAddress(repaymentAddress), program),
155
167
  ]);
156
168
 
157
- const [recipient, outputToken] = [_recipient.forceSvmAddress(), _outputToken.forceSvmAddress()];
158
169
  const mint = toAddress(outputToken);
159
170
  const mintInfo = await fetchMint(this.provider, mint);
160
171
 
161
172
  const [recipientAta, relayerAta, fillStatus, eventAuthority] = await Promise.all([
162
173
  getAssociatedTokenAddress(recipient, outputToken, mintInfo.programAddress),
163
174
  getAssociatedTokenAddress(SvmAddress.from(relayer.toBase58()), outputToken, mintInfo.programAddress),
164
- getFillStatusPda(program, deposit, destinationChainId),
175
+ getFillStatusPda(program, relayData, destinationChainId),
165
176
  getEventAuthority(program),
166
177
  ]);
167
178
 
168
- const relayData: SvmSpokeClient.FillRelayInput["relayData"] = {
179
+ const svmRelayData: SvmSpokeClient.FillRelayInput["relayData"] = {
169
180
  depositor: toAddress(depositor),
170
181
  recipient: toAddress(recipient),
171
182
  exclusiveRelayer: toAddress(exclusiveRelayer),
172
183
  inputToken: toAddress(inputToken),
173
184
  outputToken: mint,
174
- inputAmount: deposit.inputAmount.toBigInt(),
175
- outputAmount: deposit.outputAmount.toBigInt(),
176
- originChainId: deposit.originChainId,
177
- depositId: new Uint8Array(intToU8Array32(deposit.depositId.toNumber())),
178
- fillDeadline: deposit.fillDeadline,
179
- exclusivityDeadline: deposit.exclusivityDeadline,
180
- message: new Uint8Array(Buffer.from(deposit.message, "hex")),
185
+ inputAmount: relayData.inputAmount.toBigInt(),
186
+ outputAmount: relayData.outputAmount.toBigInt(),
187
+ originChainId: relayData.originChainId,
188
+ depositId: new Uint8Array(intToU8Array32(relayData.depositId.toNumber())),
189
+ fillDeadline: relayData.fillDeadline,
190
+ exclusivityDeadline: relayData.exclusivityDeadline,
191
+ message: new Uint8Array(Buffer.from(relayData.message, "hex")),
181
192
  };
182
193
 
183
194
  const simulatedSigner = SolanaVoidSigner(relayer.toBase58());
@@ -195,7 +206,7 @@ export class SvmQuery implements QueryInterface {
195
206
  eventAuthority,
196
207
  program,
197
208
  relayHash: relayDataHash,
198
- relayData,
209
+ relayData: svmRelayData,
199
210
  repaymentChainId: BigInt(repaymentChainId),
200
211
  repaymentAddress: toAddress(repaymentAddress),
201
212
  };
@@ -114,7 +114,7 @@ export const DEFAULT_LOGGER: Logger = {
114
114
  error: (...args) => console.error(args),
115
115
  };
116
116
 
117
- export function getDefaultSimulatedRelayerAddress(chainId?: number) {
117
+ export function getDefaultRelayer(chainId?: number) {
118
118
  return isDefined(chainId) && chainIsSvm(chainId)
119
119
  ? DEFAULT_SIMULATED_RELAYER_ADDRESS_SVM
120
120
  : DEFAULT_SIMULATED_RELAYER_ADDRESS;
@@ -256,10 +256,7 @@ export class RelayFeeCalculator {
256
256
  deposit: Deposit,
257
257
  outputAmount: BigNumberish,
258
258
  simulateZeroFill = false,
259
- relayerAddress = toAddressType(
260
- getDefaultSimulatedRelayerAddress(deposit.destinationChainId),
261
- deposit.destinationChainId
262
- ),
259
+ relayerAddress = toAddressType(getDefaultRelayer(deposit.destinationChainId), deposit.destinationChainId),
263
260
  _tokenPrice?: number,
264
261
  tokenMapping = TOKEN_SYMBOLS_MAP,
265
262
  gasPrice?: BigNumberish,
@@ -498,10 +495,7 @@ export class RelayFeeCalculator {
498
495
  deposit: Deposit,
499
496
  outputAmount?: BigNumberish,
500
497
  simulateZeroFill = false,
501
- relayerAddress = toAddressType(
502
- getDefaultSimulatedRelayerAddress(deposit.destinationChainId),
503
- deposit.destinationChainId
504
- ),
498
+ relayerAddress = toAddressType(getDefaultRelayer(deposit.destinationChainId), deposit.destinationChainId),
505
499
  _tokenPrice?: number,
506
500
  gasPrice?: BigNumberish,
507
501
  gasUnits?: BigNumberish,
@@ -81,15 +81,15 @@ export function isValidEvmAddress(address: string): boolean {
81
81
  export function toAddressType(address: string, chainId: number): Address {
82
82
  const rawAddress = address.startsWith("0x") ? utils.arrayify(address) : bs58.decode(address);
83
83
 
84
- const isEvm = chainIsEvm(chainId);
85
- if (isEvm && EvmAddress.validate(rawAddress)) return new EvmAddress(rawAddress);
86
- if (!isEvm && SvmAddress.validate(rawAddress)) return new SvmAddress(rawAddress);
87
- return new Address(rawAddress);
84
+ if (chainIsEvm(chainId) && EvmAddress.validate(rawAddress)) return new EvmAddress(rawAddress);
85
+ else if (chainIsSvm(chainId) && SvmAddress.validate(rawAddress)) return new SvmAddress(rawAddress);
86
+
87
+ return new RawAddress(rawAddress);
88
88
  }
89
89
 
90
90
  // The Address class can contain any address type. It is up to the subclasses to determine how to format the address's internal representation,
91
91
  // which for this class, is a bytes32 hex string.
92
- export class Address {
92
+ export abstract class Address {
93
93
  readonly rawAddress: Uint8Array;
94
94
 
95
95
  // Keep all address types in cache so that we may lazily evaluate them when necessary.
@@ -109,10 +109,6 @@ export class Address {
109
109
  this.rawAddress = utils.zeroPad(_rawAddress, 32);
110
110
  }
111
111
 
112
- static __unsafeConstruct(_rawAddress: Uint8Array): Address {
113
- return new this(_rawAddress);
114
- }
115
-
116
112
  // Converts the address into a bytes32 string. Note that the output bytes will be lowercase so that it matches ethers event data. This function will never
117
113
  // throw since address length validation was done at construction time.
118
114
  toBytes32(): string {
@@ -167,11 +163,6 @@ export class Address {
167
163
  return false;
168
164
  }
169
165
 
170
- // Checks if the object is an address by looking at whether it has an Address constructor.
171
- static isAddress(obj: unknown): boolean {
172
- return obj instanceof this;
173
- }
174
-
175
166
  // Converts the input address to a 32-byte hex data string.
176
167
  toString(): string {
177
168
  return this.toNative();
@@ -193,6 +184,7 @@ export class Address {
193
184
  }
194
185
 
195
186
  // Compares Addresses by first converting them to BigNumbers.
187
+ // note: Intended for use when sorting like addresses.
196
188
  compare(otherAddress: Address): 1 | -1 | 0 {
197
189
  // Convert address strings to BigNumbers and then sort numerical value of the BigNumber, which sorts the addresses
198
190
  // effectively by their hex value.
@@ -207,20 +199,18 @@ export class Address {
207
199
  }
208
200
  }
209
201
 
210
- static isEvmAddress(address: Address): boolean {
211
- return address instanceof EvmAddress;
202
+ isEVM(): this is EvmAddress {
203
+ return false;
212
204
  }
213
205
 
214
- static isSvmAddress(address: Address): boolean {
215
- return address instanceof SvmAddress;
206
+ isSVM(): this is SvmAddress {
207
+ return false;
216
208
  }
217
209
  }
218
210
 
219
211
  // Subclass of address which strictly deals with 20-byte addresses. These addresses are guaranteed to be valid EVM addresses, so `toAddress` will always succeed.
220
212
  export class EvmAddress extends Address {
221
- // @dev This property is required for Typescript typechecker to know to distinguish between `Address`, `SvmAddress` and `EvmAddress`.
222
- // Otherwise it lets any of these to use in place where other is expected.
223
- private readonly _brandEvmAddress!: void;
213
+ private readonly _type = "evm";
224
214
 
225
215
  // On construction, validate that the address can indeed be coerced into an EVM address. Throw immediately if it cannot.
226
216
  constructor(rawAddress: Uint8Array) {
@@ -229,8 +219,7 @@ export class EvmAddress extends Address {
229
219
  }
230
220
 
231
221
  super(rawAddress);
232
- // @dev required for TS to compile with `noUnusedLocals` rule
233
- this._brandEvmAddress;
222
+ this._type; // tsc noUnusedLocals appeasement.
234
223
  }
235
224
 
236
225
  static validate(rawAddress: Uint8Array): boolean {
@@ -239,34 +228,24 @@ export class EvmAddress extends Address {
239
228
  );
240
229
  }
241
230
 
231
+ override isEVM(): this is EvmAddress {
232
+ return true;
233
+ }
234
+
242
235
  // Override `toAddress` to return the 20-byte representation address.
243
236
  override toNative(): string {
244
237
  return this.toEvmAddress();
245
238
  }
246
239
 
247
240
  // Constructs a new EvmAddress type.
248
- static from(address: string, encoding: "base16" | "base58" = "base16"): EvmAddress {
249
- if (encoding === "base16") {
250
- return new this(utils.arrayify(address));
251
- }
252
-
253
- const decodedAddress = bs58.decode(address);
254
- const padding = decodedAddress.subarray(0, 12);
255
- const evmAddress = decodedAddress.subarray(12);
256
-
257
- if (padding.length !== 12 || utils.stripZeros(padding).length !== 0 || evmAddress.length !== 20) {
258
- throw new Error(`Not a valid base58-encoded EVM address: ${address}`);
259
- }
260
-
261
- return new this(evmAddress);
241
+ static from(address: string, encoding: "base58" | "base16" = "base16"): EvmAddress {
242
+ return encoding === "base16" ? new this(utils.arrayify(address)) : new this(bs58.decode(address));
262
243
  }
263
244
  }
264
245
 
265
246
  // Subclass of address which strictly deals SVM addresses. These addresses are guaranteed to be valid SVM addresses, so `toBase58` will always produce a valid Solana address.
266
247
  export class SvmAddress extends Address {
267
- // @dev This property is required for Typescript typechecker to know to distinguish between `Address`, `SvmAddress` and `EvmAddress`.
268
- // Otherwise it lets any of these to use in place where other is expected.
269
- private readonly _brandSvmAddress!: void;
248
+ private readonly _type = "svm";
270
249
 
271
250
  // On construction, validate that the address is a point on Curve25519. Throw immediately if it is not.
272
251
  constructor(rawAddress: Uint8Array) {
@@ -275,12 +254,21 @@ export class SvmAddress extends Address {
275
254
  }
276
255
 
277
256
  super(rawAddress);
278
- // @dev required for TS to compile with `noUnusedLocals` rule
279
- this._brandSvmAddress;
257
+ this._type; // tsc noUnusedLocals appeasement.
280
258
  }
281
259
 
282
260
  static validate(rawAddress: Uint8Array): boolean {
283
- return rawAddress.length === 32;
261
+ // Deliberately invalidate SVM addresses w/ the upper 12 bytes zeroed. These addresses are technically valid
262
+ // but highly improbable and are much more likely to be a mistaken interpretation of an EVM address. Err on
263
+ // the side of caution for the time being. Exception: Permit the zero address (i.e. for exclusiverRelayer).
264
+ return (
265
+ rawAddress.length === 32 &&
266
+ (!rawAddress.slice(0, 12).every((field) => field === 0) || rawAddress.every((field) => field === 0))
267
+ );
268
+ }
269
+
270
+ override isSVM(): this is SvmAddress {
271
+ return true;
284
272
  }
285
273
 
286
274
  // Override the toAddress function for SVM addresses only since while they will never have a defined 20-byte representation. The base58 encoded addresses are also the encodings
@@ -291,15 +279,15 @@ export class SvmAddress extends Address {
291
279
 
292
280
  // Constructs a new SvmAddress type.
293
281
  static from(address: string, encoding: "base58" | "base16" = "base58"): SvmAddress {
294
- if (encoding === "base58") {
295
- return new this(bs58.decode(address));
296
- }
282
+ return encoding === "base58" ? new this(bs58.decode(address)) : new this(utils.arrayify(address));
283
+ }
284
+ }
297
285
 
298
- const decodedAddress = utils.arrayify(address);
299
- if (decodedAddress.length !== 32) {
300
- throw new Error(`Not a valid base16-encoded SVM address: ${address}`);
301
- }
286
+ export class RawAddress extends Address {
287
+ private readonly _type = "raw";
302
288
 
303
- return new this(decodedAddress);
289
+ constructor(rawAddress: Uint8Array) {
290
+ super(rawAddress);
291
+ this._type; // tsc noUnusedLocals appeasement.
304
292
  }
305
293
  }