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

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 (85) hide show
  1. package/dist/cjs/arch/svm/SpokeUtils.d.ts +1 -1
  2. package/dist/cjs/arch/svm/SpokeUtils.js.map +1 -1
  3. package/dist/cjs/arch/svm/eventsClient.js +4 -2
  4. package/dist/cjs/arch/svm/eventsClient.js.map +1 -1
  5. package/dist/cjs/arch/svm/utils.js +1 -1
  6. package/dist/cjs/arch/svm/utils.js.map +1 -1
  7. package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.d.ts +63 -63
  8. package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.js +4 -2
  9. package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -1
  10. package/dist/cjs/clients/HubPoolClient.js +4 -3
  11. package/dist/cjs/clients/HubPoolClient.js.map +1 -1
  12. package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js +2 -1
  13. package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
  14. package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.d.ts +1 -1
  15. package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.js +6 -4
  16. package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.js.map +1 -1
  17. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.d.ts +6 -2
  18. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js +13 -4
  19. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  20. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.d.ts +5 -1
  21. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js +24 -12
  22. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
  23. package/dist/cjs/utils/AddressUtils.d.ts +12 -8
  24. package/dist/cjs/utils/AddressUtils.js +33 -36
  25. package/dist/cjs/utils/AddressUtils.js.map +1 -1
  26. package/dist/cjs/utils/TokenUtils.js +5 -3
  27. package/dist/cjs/utils/TokenUtils.js.map +1 -1
  28. package/dist/esm/arch/svm/SpokeUtils.d.ts +1 -1
  29. package/dist/esm/arch/svm/SpokeUtils.js.map +1 -1
  30. package/dist/esm/arch/svm/eventsClient.js +5 -3
  31. package/dist/esm/arch/svm/eventsClient.js.map +1 -1
  32. package/dist/esm/arch/svm/utils.js +2 -2
  33. package/dist/esm/arch/svm/utils.js.map +1 -1
  34. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.d.ts +63 -63
  35. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js +11 -4
  36. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -1
  37. package/dist/esm/clients/HubPoolClient.js +4 -3
  38. package/dist/esm/clients/HubPoolClient.js.map +1 -1
  39. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js +2 -1
  40. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
  41. package/dist/esm/clients/mocks/MockSvmCpiEventsClient.d.ts +1 -1
  42. package/dist/esm/clients/mocks/MockSvmCpiEventsClient.js +7 -5
  43. package/dist/esm/clients/mocks/MockSvmCpiEventsClient.js.map +1 -1
  44. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.d.ts +6 -2
  45. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js +13 -4
  46. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  47. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.d.ts +7 -2
  48. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js +28 -14
  49. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
  50. package/dist/esm/utils/AddressUtils.d.ts +12 -8
  51. package/dist/esm/utils/AddressUtils.js +36 -38
  52. package/dist/esm/utils/AddressUtils.js.map +1 -1
  53. package/dist/esm/utils/TokenUtils.d.ts +16 -0
  54. package/dist/esm/utils/TokenUtils.js +6 -4
  55. package/dist/esm/utils/TokenUtils.js.map +1 -1
  56. package/dist/types/arch/svm/SpokeUtils.d.ts +1 -1
  57. package/dist/types/arch/svm/SpokeUtils.d.ts.map +1 -1
  58. package/dist/types/arch/svm/eventsClient.d.ts.map +1 -1
  59. package/dist/types/arch/svm/utils.d.ts.map +1 -1
  60. package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts +63 -63
  61. package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts.map +1 -1
  62. package/dist/types/clients/HubPoolClient.d.ts.map +1 -1
  63. package/dist/types/clients/SpokePoolClient/SpokePoolClient.d.ts.map +1 -1
  64. package/dist/types/clients/mocks/MockSvmCpiEventsClient.d.ts +1 -1
  65. package/dist/types/clients/mocks/MockSvmCpiEventsClient.d.ts.map +1 -1
  66. package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts +6 -2
  67. package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts.map +1 -1
  68. package/dist/types/relayFeeCalculator/chain-queries/svmQuery.d.ts +7 -2
  69. package/dist/types/relayFeeCalculator/chain-queries/svmQuery.d.ts.map +1 -1
  70. package/dist/types/utils/AddressUtils.d.ts +12 -8
  71. package/dist/types/utils/AddressUtils.d.ts.map +1 -1
  72. package/dist/types/utils/TokenUtils.d.ts +16 -0
  73. package/dist/types/utils/TokenUtils.d.ts.map +1 -1
  74. package/package.json +1 -1
  75. package/src/arch/svm/SpokeUtils.ts +4 -1
  76. package/src/arch/svm/eventsClient.ts +40 -8
  77. package/src/arch/svm/utils.ts +2 -2
  78. package/src/clients/BundleDataClient/utils/SuperstructUtils.ts +12 -4
  79. package/src/clients/HubPoolClient.ts +5 -4
  80. package/src/clients/SpokePoolClient/SpokePoolClient.ts +4 -1
  81. package/src/clients/mocks/MockSvmCpiEventsClient.ts +8 -5
  82. package/src/relayFeeCalculator/chain-queries/baseQuery.ts +21 -3
  83. package/src/relayFeeCalculator/chain-queries/svmQuery.ts +27 -13
  84. package/src/utils/AddressUtils.ts +39 -51
  85. package/src/utils/TokenUtils.ts +6 -4
@@ -1 +1 @@
1
- {"version":3,"file":"AddressUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/AddressUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAS,MAAM,QAAQ,CAAC;AAE1C,OAAO,EAAE,SAAS,EAA0B,MAAM,IAAI,CAAC;AAEvD;;;;;GAKG;AACH,wBAAsB,2BAA2B,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,CAAC,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,CASjH;AAED,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAY/E;AAED,wBAAgB,sBAAsB,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAKpF;AAKD,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEjD;AAID,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAItD;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAc1D;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAOvE;AAID,qBAAa,OAAO;IAClB,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAGhC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAa;IAC3C,cAAc,EAAE,MAAM,GAAG,SAAS,CAAa;IAC/C,UAAU,EAAE,MAAM,GAAG,SAAS,CAAa;IAC3C,SAAS,EAAE,SAAS,GAAG,SAAS,CAAa;gBAEjC,WAAW,EAAE,UAAU;IAWnC,MAAM,CAA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6 +185,14 @@ export declare const resolveContractFromSymbol: (symbol: string, chainId: string
185
185
  };
186
186
  coingeckoId: string;
187
187
  };
188
+ /**
189
+ * Retrieves the ERC20 balance for a given address and token address.
190
+ * @param address The address to retrieve the balance for.
191
+ * @param tokenAddress The token address
192
+ * @param signerOrProvider A valid ethers.js Signer or Provider object.
193
+ * @param blockTag The block tag to retrieve the balance at.
194
+ * @returns The balance of the given address for the given token address.
195
+ */
188
196
  SOL: {
189
197
  name: string;
190
198
  symbol: string;
@@ -600,6 +608,14 @@ export declare function getTokenInfo(l2TokenAddress: string, chainId: number, to
600
608
  };
601
609
  coingeckoId: string;
602
610
  };
611
+ /**
612
+ * Retrieves the ERC20 balance for a given address and token address.
613
+ * @param address The address to retrieve the balance for.
614
+ * @param tokenAddress The token address
615
+ * @param signerOrProvider A valid ethers.js Signer or Provider object.
616
+ * @param blockTag The block tag to retrieve the balance at.
617
+ * @returns The balance of the given address for the given token address.
618
+ */
603
619
  SOL: {
604
620
  name: string;
605
621
  symbol: string;
@@ -1 +1 @@
1
- {"version":3,"file":"TokenUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/TokenUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAC5D,OAAO,EAAY,SAAS,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErD,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAM7C,KAAK,gBAAgB,GAAG,SAAS,CAAC,QAAQ,GAAG,MAAM,CAAC;AAEpD,wBAAsB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,gBAAgB,GAAG,OAAO,CAAC,SAAS,CAAC,CAI5G;AAED,eAAO,MAAM,mBAAmB,mBACd,MAAM;;aAMvB,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAvClF;;;;;;;OAOG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgCmG,GAAG,SAAS,CAoBjH;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAOlF;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAUjF"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@across-protocol/sdk",
3
3
  "author": "UMA Team",
4
- "version": "4.2.16-alpha.4",
4
+ "version": "4.2.16-alpha.5",
5
5
  "license": "AGPL-3.0",
6
6
  "homepage": "https://docs.across.to/reference/sdk",
7
7
  "files": [
@@ -385,7 +385,10 @@ export async function findFillEvent(
385
385
  */
386
386
  export async function fillRelayInstruction(
387
387
  spokePool: SvmAddress,
388
- deposit: Omit<Deposit, "messageHash" | "fromLiteChain" | "toLiteChain"> & {
388
+ deposit: Omit<
389
+ Deposit,
390
+ "recipient" | "outputToken" | "exclusiveRelayer" | "messageHash" | "fromLiteChain" | "toLiteChain"
391
+ > & {
389
392
  recipient: SvmAddress;
390
393
  outputToken: SvmAddress;
391
394
  exclusiveRelayer: SvmAddress;
@@ -10,7 +10,7 @@ import {
10
10
  GetTransactionApi,
11
11
  Signature,
12
12
  } from "@solana/kit";
13
- import { bs58, chainIsSvm, getMessageHash } from "../../utils";
13
+ import { bs58, chainIsSvm, getMessageHash, toAddressType } from "../../utils";
14
14
  import { EventName, EventWithData, SVMProvider } from "./types";
15
15
  import { decodeEvent, isDevnet } from "./utils";
16
16
  import { Deposit, DepositWithTime, Fill, FillWithTime } from "../../interfaces";
@@ -252,7 +252,6 @@ export class SvmCpiEventsClient {
252
252
 
253
253
  // Filter for FundsDeposited events only
254
254
  const depositEvents = events?.filter((event) => event?.name === "FundsDeposited");
255
-
256
255
  if (!txDetails || !depositEvents?.length) {
257
256
  return;
258
257
  }
@@ -261,13 +260,29 @@ export class SvmCpiEventsClient {
261
260
  const unwrappedEventArgs = unwrapEventData(event as Record<string, unknown>, ["depositId"]) as Record<
262
261
  "data",
263
262
  Deposit
264
- >;
265
-
263
+ > &
264
+ Record<
265
+ "data",
266
+ {
267
+ depositor: string;
268
+ recipient: string;
269
+ exclusiveRelayer: string;
270
+ inputToken: string;
271
+ outputToken: string;
272
+ }
273
+ >;
274
+
275
+ const { data } = unwrappedEventArgs;
266
276
  return {
267
- ...unwrappedEventArgs.data,
277
+ ...data,
278
+ depositor: toAddressType(data.depositor, data.originChainId),
279
+ recipient: toAddressType(data.recipient, data.destinationChainId),
280
+ exclusiveRelayer: toAddressType(data.exclusiveRelayer, data.destinationChainId),
281
+ inputToken: toAddressType(data.inputToken, data.originChainId),
282
+ outputToken: toAddressType(data.outputToken, data.destinationChainId),
268
283
  depositTimestamp: Number(txDetails.blockTime),
269
284
  originChainId,
270
- messageHash: getMessageHash(unwrappedEventArgs.data.message),
285
+ messageHash: getMessageHash(data.message),
271
286
  blockNumber: Number(txDetails.slot),
272
287
  txnIndex: 0,
273
288
  txnRef: txSignature,
@@ -309,9 +324,26 @@ export class SvmCpiEventsClient {
309
324
  }
310
325
 
311
326
  return fillEvents.map((event) => {
312
- const unwrappedEventData = unwrapEventData(event as Record<string, unknown>) as Record<"data", Fill>;
327
+ const unwrappedEventData = unwrapEventData(event as Record<string, unknown>) as Record<"data", Fill> &
328
+ Record<
329
+ "data",
330
+ {
331
+ depositor: string;
332
+ recipient: string;
333
+ exclusiveRelayer: string;
334
+ inputToken: string;
335
+ outputToken: string;
336
+ }
337
+ >;
338
+
339
+ const { data } = unwrappedEventData;
313
340
  return {
314
- ...unwrappedEventData.data,
341
+ ...data,
342
+ depositor: toAddressType(data.depositor, data.originChainId),
343
+ recipient: toAddressType(data.recipient, data.destinationChainId),
344
+ exclusiveRelayer: toAddressType(data.exclusiveRelayer, data.destinationChainId),
345
+ inputToken: toAddressType(data.inputToken, data.originChainId),
346
+ outputToken: toAddressType(data.outputToken, data.destinationChainId),
315
347
  fillTimestamp: Number(txDetails.blockTime),
316
348
  blockNumber: Number(txDetails.slot),
317
349
  txnRef: txSignature,
@@ -17,7 +17,7 @@ import {
17
17
  } from "@solana/kit";
18
18
  import { SvmSpokeClient } from "@across-protocol/contracts";
19
19
  import { FillType, RelayData } from "../../interfaces";
20
- import { BigNumber, SvmAddress, getRelayDataHash, isUint8Array, Address as SdkAddress } from "../../utils";
20
+ import { BigNumber, getRelayDataHash, isUint8Array, Address as SdkAddress } from "../../utils";
21
21
  import { EventName, SVMEventNames, SVMProvider } from "./types";
22
22
 
23
23
  /**
@@ -144,7 +144,7 @@ export function unwrapEventData(
144
144
  }
145
145
  // Handle strings (potential addresses)
146
146
  if (typeof data === "string" && isAddress(data)) {
147
- return SvmAddress.from(data).toBytes32();
147
+ return ethers.utils.hexlify(bs58.decode(data));
148
148
  }
149
149
  // Handle objects
150
150
  if (typeof data === "object") {
@@ -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 = {
@@ -9,6 +9,7 @@ import { SpokePool, SpokePool__factory } from "../../typechain";
9
9
  import { populateV3Relay } from "../../arch/evm";
10
10
  import {
11
11
  BigNumberish,
12
+ EvmAddress,
12
13
  TransactionCostEstimate,
13
14
  BigNumber,
14
15
  toBNWei,
@@ -93,7 +94,12 @@ export class QueryBase implements QueryInterface {
93
94
  transport,
94
95
  } = options;
95
96
 
96
- const tx = await this.getUnsignedTxFromDeposit(deposit, relayer);
97
+ const { recipient, outputToken, exclusiveRelayer } = deposit;
98
+ assert(recipient.isEVM(), `getGasCosts: recipient not an EVM address (${recipient})`);
99
+ assert(outputToken.isEVM(), `getGasCosts: outputToken not an EVM address (${outputToken})`);
100
+ assert(exclusiveRelayer.isEVM(), `getGasCosts: exclusiveRelayer not an EVM address (${exclusiveRelayer})`);
101
+
102
+ const tx = await this.getUnsignedTxFromDeposit({ ...deposit, recipient, outputToken, exclusiveRelayer }, relayer);
97
103
  const {
98
104
  nativeGasCost,
99
105
  tokenGasCost,
@@ -123,7 +129,11 @@ export class QueryBase implements QueryInterface {
123
129
  * @returns PopulatedTransaction
124
130
  */
125
131
  getUnsignedTxFromDeposit(
126
- deposit: Omit<Deposit, "messageHash">,
132
+ deposit: Omit<Deposit, "messageHash"> & {
133
+ recipient: EvmAddress;
134
+ outputToken: EvmAddress;
135
+ exclusiveRelayer: EvmAddress;
136
+ },
127
137
  relayer = toAddressType(getDefaultSimulatedRelayerAddress(deposit.destinationChainId), deposit.destinationChainId)
128
138
  ): Promise<PopulatedTransaction> {
129
139
  return populateV3Relay(this.spokePool, deposit, relayer);
@@ -139,7 +149,15 @@ export class QueryBase implements QueryInterface {
139
149
  deposit: Omit<Deposit, "messageHash">,
140
150
  relayer = toAddressType(getDefaultSimulatedRelayerAddress(deposit.destinationChainId), deposit.destinationChainId)
141
151
  ): Promise<BigNumber> {
142
- const unsignedTx = await this.getUnsignedTxFromDeposit(deposit, relayer);
152
+ const { recipient, outputToken, exclusiveRelayer } = deposit;
153
+ assert(recipient.isEVM(), `getNativeGasCost: recipient not an EVM address (${recipient})`);
154
+ assert(outputToken.isEVM(), `getNativeGasCost: outputToken not an EVM address (${outputToken})`);
155
+ assert(exclusiveRelayer.isEVM(), `getNativeGasCost: exclusiveRelayer not an EVM address (${exclusiveRelayer})`);
156
+
157
+ const unsignedTx = await this.getUnsignedTxFromDeposit(
158
+ { ...deposit, recipient, outputToken, exclusiveRelayer },
159
+ relayer
160
+ );
143
161
  const voidSigner = new VoidSigner(relayer.toEvmAddress(), this.provider);
144
162
  return voidSigner.estimateGas(unsignedTx);
145
163
  }
@@ -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";
@@ -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 } = deposit;
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({ ...deposit, recipient, outputToken, exclusiveRelayer }, relayer);
87
93
 
88
94
  const [computeUnitsConsumed, gasPriceEstimate] = await Promise.all([
89
95
  toBN(await this.computeUnitEstimator(fillRelayTx)),
@@ -114,10 +120,15 @@ 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">,
123
+ deposit: Omit<Deposit, "messageHash">, // @todo Update interface to permit EvmAddress | SvmAddress
118
124
  _relayer = toAddressType(getDefaultSimulatedRelayerAddress(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
 
@@ -128,7 +139,11 @@ export class SvmQuery implements QueryInterface {
128
139
  * @returns FillRelay transaction
129
140
  */
130
141
  async getFillRelayTx(
131
- deposit: Omit<Deposit, "messageHash">,
142
+ deposit: Omit<Deposit, "recipent" | "outputToken" | "exclusiveRelayer" | "messageHash"> & {
143
+ recipient: SvmAddress;
144
+ outputToken: SvmAddress;
145
+ exclusiveRelayer: SvmAddress;
146
+ },
132
147
  relayer = toAddressType(getDefaultSimulatedRelayerAddress(deposit.destinationChainId), deposit.destinationChainId),
133
148
  repaymentChainId = deposit.destinationChainId,
134
149
  repaymentAddress = toAddressType(
@@ -136,14 +151,14 @@ export class SvmQuery implements QueryInterface {
136
151
  deposit.destinationChainId
137
152
  )
138
153
  ) {
139
- const {
140
- depositor,
141
- recipient: _recipient,
142
- inputToken,
143
- outputToken: _outputToken,
144
- exclusiveRelayer,
145
- destinationChainId,
146
- } = deposit;
154
+ const { depositor, recipient, inputToken, outputToken, exclusiveRelayer, destinationChainId } = deposit;
155
+
156
+ // tsc appeasement...should be unnecessary, but isn't. @todo Identify why.
157
+ assert(recipient.isSVM(), `getFillRelayTx: recipient not an SVM address (${recipient})`);
158
+ assert(
159
+ repaymentAddress.isValidOn(repaymentChainId),
160
+ `getFillRelayTx: repayment address ${repaymentAddress} not valid on chain ${repaymentChainId})`
161
+ );
147
162
 
148
163
  const program = toAddress(this.spokePool);
149
164
  const _relayDataHash = getRelayDataHash(deposit, destinationChainId);
@@ -154,7 +169,6 @@ export class SvmQuery implements QueryInterface {
154
169
  getFillRelayDelegatePda(relayDataHash, BigInt(repaymentChainId), toAddress(repaymentAddress), program),
155
170
  ]);
156
171
 
157
- const [recipient, outputToken] = [_recipient.forceSvmAddress(), _outputToken.forceSvmAddress()];
158
172
  const mint = toAddress(outputToken);
159
173
  const mintInfo = await fetchMint(this.provider, mint);
160
174
 
@@ -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
  }
@@ -1,3 +1,4 @@
1
+ import assert from "assert";
1
2
  import { BlockTag } from "@ethersproject/abstract-provider";
2
3
  import { Contract, providers, Signer } from "ethers";
3
4
  import * as constants from "../constants";
@@ -6,7 +7,7 @@ import { ERC20__factory } from "../typechain";
6
7
  import { BigNumber } from "./BigNumberUtils";
7
8
  import { getNetworkName, chainIsL1, chainIsProd } from "./NetworkUtils";
8
9
  import { isDefined } from "./TypeGuards";
9
- import { compareAddressesSimple, toAddressType } from "./AddressUtils";
10
+ import { compareAddressesSimple, EvmAddress, toAddressType } from "./AddressUtils";
10
11
  const { TOKEN_SYMBOLS_MAP, CHAIN_IDs, TOKEN_EQUIVALENCE_REMAPPING } = constants;
11
12
 
12
13
  type SignerOrProvider = providers.Provider | Signer;
@@ -14,7 +15,7 @@ type SignerOrProvider = providers.Provider | Signer;
14
15
  export async function fetchTokenInfo(address: string, signerOrProvider: SignerOrProvider): Promise<TokenInfo> {
15
16
  const token = new Contract(address, ERC20__factory.abi, signerOrProvider);
16
17
  const [symbol, decimals] = await Promise.all([token.symbol(), token.decimals()]);
17
- return { address: toAddressType(address, CHAIN_IDs.MAINNET), symbol, decimals };
18
+ return { address: EvmAddress.from(address), symbol, decimals };
18
19
  }
19
20
 
20
21
  export const getL2TokenAddresses = (
@@ -42,9 +43,10 @@ export function resolveSymbolOnChain(chainId: number, symbol: string): TokenInfo
42
43
  }
43
44
 
44
45
  const { decimals, addresses } = token;
45
- const address = addresses[chainId];
46
+ const address = toAddressType(addresses[chainId], chainId);
47
+ assert(address.isEVM() || address.isSVM());
46
48
 
47
- return { symbol, decimals, address: toAddressType(address, chainId) };
49
+ return { symbol, decimals, address };
48
50
  }
49
51
 
50
52
  /**