@across-protocol/sdk 4.2.16-alpha.0 → 4.2.16-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 (211) hide show
  1. package/dist/cjs/arch/evm/SpokeUtils.d.ts +6 -2
  2. package/dist/cjs/arch/evm/SpokeUtils.js +21 -6
  3. package/dist/cjs/arch/evm/SpokeUtils.js.map +1 -1
  4. package/dist/cjs/arch/svm/SpokeUtils.d.ts +9 -5
  5. package/dist/cjs/arch/svm/SpokeUtils.js +70 -71
  6. package/dist/cjs/arch/svm/SpokeUtils.js.map +1 -1
  7. package/dist/cjs/arch/svm/utils.d.ts +3 -5
  8. package/dist/cjs/arch/svm/utils.js +20 -28
  9. package/dist/cjs/arch/svm/utils.js.map +1 -1
  10. package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +3 -3
  11. package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js +4 -2
  12. package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
  13. package/dist/cjs/clients/BundleDataClient/BundleDataClient.d.ts +4 -4
  14. package/dist/cjs/clients/BundleDataClient/BundleDataClient.js +60 -56
  15. package/dist/cjs/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  16. package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js +13 -13
  17. package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
  18. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.d.ts +2 -1
  19. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js +3 -2
  20. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
  21. package/dist/cjs/clients/BundleDataClient/utils/MerkleTreeUtils.js +5 -1
  22. package/dist/cjs/clients/BundleDataClient/utils/MerkleTreeUtils.js.map +1 -1
  23. package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js +3 -3
  24. package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
  25. package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.d.ts +63 -63
  26. package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.js +11 -8
  27. package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -1
  28. package/dist/cjs/clients/HubPoolClient.d.ts +21 -21
  29. package/dist/cjs/clients/HubPoolClient.js +83 -58
  30. package/dist/cjs/clients/HubPoolClient.js.map +1 -1
  31. package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js +1 -1
  32. package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
  33. package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.d.ts +2 -2
  34. package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js +64 -45
  35. package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
  36. package/dist/cjs/clients/mocks/MockHubPoolClient.d.ts +9 -9
  37. package/dist/cjs/clients/mocks/MockHubPoolClient.js +15 -9
  38. package/dist/cjs/clients/mocks/MockHubPoolClient.js.map +1 -1
  39. package/dist/cjs/clients/mocks/MockSpokePoolClient.d.ts +5 -3
  40. package/dist/cjs/clients/mocks/MockSpokePoolClient.js +40 -36
  41. package/dist/cjs/clients/mocks/MockSpokePoolClient.js.map +1 -1
  42. package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.d.ts +1 -1
  43. package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.js +3 -4
  44. package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.js.map +1 -1
  45. package/dist/cjs/clients/mocks/MockSvmSpokePoolClient.d.ts +3 -3
  46. package/dist/cjs/clients/mocks/MockSvmSpokePoolClient.js +2 -2
  47. package/dist/cjs/clients/mocks/MockSvmSpokePoolClient.js.map +1 -1
  48. package/dist/cjs/interfaces/HubPool.d.ts +19 -14
  49. package/dist/cjs/interfaces/SpokePool.d.ts +13 -13
  50. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.d.ts +6 -6
  51. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js +10 -10
  52. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  53. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.d.ts +5 -5
  54. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js +42 -49
  55. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
  56. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.d.ts +5 -5
  57. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js +7 -7
  58. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  59. package/dist/cjs/utils/AddressUtils.d.ts +12 -13
  60. package/dist/cjs/utils/AddressUtils.js +44 -46
  61. package/dist/cjs/utils/AddressUtils.js.map +1 -1
  62. package/dist/cjs/utils/EventUtils.js +1 -1
  63. package/dist/cjs/utils/EventUtils.js.map +1 -1
  64. package/dist/cjs/utils/SpokeUtils.d.ts +3 -3
  65. package/dist/cjs/utils/SpokeUtils.js +4 -22
  66. package/dist/cjs/utils/SpokeUtils.js.map +1 -1
  67. package/dist/cjs/utils/TokenUtils.d.ts +4 -4
  68. package/dist/cjs/utils/TokenUtils.js +4 -6
  69. package/dist/cjs/utils/TokenUtils.js.map +1 -1
  70. package/dist/esm/arch/evm/SpokeUtils.d.ts +6 -2
  71. package/dist/esm/arch/evm/SpokeUtils.js +22 -7
  72. package/dist/esm/arch/evm/SpokeUtils.js.map +1 -1
  73. package/dist/esm/arch/svm/SpokeUtils.d.ts +9 -5
  74. package/dist/esm/arch/svm/SpokeUtils.js +74 -75
  75. package/dist/esm/arch/svm/SpokeUtils.js.map +1 -1
  76. package/dist/esm/arch/svm/utils.d.ts +6 -8
  77. package/dist/esm/arch/svm/utils.js +21 -27
  78. package/dist/esm/arch/svm/utils.js.map +1 -1
  79. package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +3 -3
  80. package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js +4 -2
  81. package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
  82. package/dist/esm/clients/BundleDataClient/BundleDataClient.d.ts +4 -4
  83. package/dist/esm/clients/BundleDataClient/BundleDataClient.js +61 -57
  84. package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  85. package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js +14 -14
  86. package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
  87. package/dist/esm/clients/BundleDataClient/utils/FillUtils.d.ts +2 -1
  88. package/dist/esm/clients/BundleDataClient/utils/FillUtils.js +5 -3
  89. package/dist/esm/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
  90. package/dist/esm/clients/BundleDataClient/utils/MerkleTreeUtils.js +5 -1
  91. package/dist/esm/clients/BundleDataClient/utils/MerkleTreeUtils.js.map +1 -1
  92. package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js +4 -4
  93. package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
  94. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.d.ts +63 -63
  95. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js +12 -9
  96. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -1
  97. package/dist/esm/clients/HubPoolClient.d.ts +23 -22
  98. package/dist/esm/clients/HubPoolClient.js +97 -63
  99. package/dist/esm/clients/HubPoolClient.js.map +1 -1
  100. package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js +2 -2
  101. package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
  102. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.d.ts +2 -2
  103. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js +67 -47
  104. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
  105. package/dist/esm/clients/mocks/MockHubPoolClient.d.ts +9 -9
  106. package/dist/esm/clients/mocks/MockHubPoolClient.js +16 -10
  107. package/dist/esm/clients/mocks/MockHubPoolClient.js.map +1 -1
  108. package/dist/esm/clients/mocks/MockSpokePoolClient.d.ts +5 -3
  109. package/dist/esm/clients/mocks/MockSpokePoolClient.js +42 -38
  110. package/dist/esm/clients/mocks/MockSpokePoolClient.js.map +1 -1
  111. package/dist/esm/clients/mocks/MockSvmCpiEventsClient.d.ts +1 -1
  112. package/dist/esm/clients/mocks/MockSvmCpiEventsClient.js +4 -5
  113. package/dist/esm/clients/mocks/MockSvmCpiEventsClient.js.map +1 -1
  114. package/dist/esm/clients/mocks/MockSvmSpokePoolClient.d.ts +3 -3
  115. package/dist/esm/clients/mocks/MockSvmSpokePoolClient.js +3 -3
  116. package/dist/esm/clients/mocks/MockSvmSpokePoolClient.js.map +1 -1
  117. package/dist/esm/interfaces/HubPool.d.ts +19 -14
  118. package/dist/esm/interfaces/SpokePool.d.ts +13 -13
  119. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.d.ts +6 -6
  120. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js +11 -11
  121. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  122. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.d.ts +6 -6
  123. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js +44 -51
  124. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
  125. package/dist/esm/relayFeeCalculator/relayFeeCalculator.d.ts +5 -5
  126. package/dist/esm/relayFeeCalculator/relayFeeCalculator.js +8 -8
  127. package/dist/esm/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  128. package/dist/esm/utils/AddressUtils.d.ts +13 -14
  129. package/dist/esm/utils/AddressUtils.js +50 -56
  130. package/dist/esm/utils/AddressUtils.js.map +1 -1
  131. package/dist/esm/utils/EventUtils.js +2 -2
  132. package/dist/esm/utils/EventUtils.js.map +1 -1
  133. package/dist/esm/utils/SpokeUtils.d.ts +3 -8
  134. package/dist/esm/utils/SpokeUtils.js +4 -26
  135. package/dist/esm/utils/SpokeUtils.js.map +1 -1
  136. package/dist/esm/utils/TokenUtils.d.ts +4 -16
  137. package/dist/esm/utils/TokenUtils.js +5 -7
  138. package/dist/esm/utils/TokenUtils.js.map +1 -1
  139. package/dist/types/arch/evm/SpokeUtils.d.ts +6 -2
  140. package/dist/types/arch/evm/SpokeUtils.d.ts.map +1 -1
  141. package/dist/types/arch/svm/SpokeUtils.d.ts +9 -5
  142. package/dist/types/arch/svm/SpokeUtils.d.ts.map +1 -1
  143. package/dist/types/arch/svm/utils.d.ts +6 -8
  144. package/dist/types/arch/svm/utils.d.ts.map +1 -1
  145. package/dist/types/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +3 -3
  146. package/dist/types/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts.map +1 -1
  147. package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts +4 -4
  148. package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -1
  149. package/dist/types/clients/BundleDataClient/utils/DataworkerUtils.d.ts.map +1 -1
  150. package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts +2 -1
  151. package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts.map +1 -1
  152. package/dist/types/clients/BundleDataClient/utils/MerkleTreeUtils.d.ts.map +1 -1
  153. package/dist/types/clients/BundleDataClient/utils/PoolRebalanceUtils.d.ts.map +1 -1
  154. package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts +63 -63
  155. package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts.map +1 -1
  156. package/dist/types/clients/HubPoolClient.d.ts +23 -22
  157. package/dist/types/clients/HubPoolClient.d.ts.map +1 -1
  158. package/dist/types/clients/SpokePoolClient/EVMSpokePoolClient.d.ts.map +1 -1
  159. package/dist/types/clients/SpokePoolClient/SpokePoolClient.d.ts +2 -2
  160. package/dist/types/clients/SpokePoolClient/SpokePoolClient.d.ts.map +1 -1
  161. package/dist/types/clients/mocks/MockHubPoolClient.d.ts +9 -9
  162. package/dist/types/clients/mocks/MockHubPoolClient.d.ts.map +1 -1
  163. package/dist/types/clients/mocks/MockSpokePoolClient.d.ts +5 -3
  164. package/dist/types/clients/mocks/MockSpokePoolClient.d.ts.map +1 -1
  165. package/dist/types/clients/mocks/MockSvmCpiEventsClient.d.ts +1 -1
  166. package/dist/types/clients/mocks/MockSvmCpiEventsClient.d.ts.map +1 -1
  167. package/dist/types/clients/mocks/MockSvmSpokePoolClient.d.ts +3 -3
  168. package/dist/types/clients/mocks/MockSvmSpokePoolClient.d.ts.map +1 -1
  169. package/dist/types/interfaces/HubPool.d.ts +19 -14
  170. package/dist/types/interfaces/HubPool.d.ts.map +1 -1
  171. package/dist/types/interfaces/SpokePool.d.ts +13 -13
  172. package/dist/types/interfaces/SpokePool.d.ts.map +1 -1
  173. package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts +6 -6
  174. package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts.map +1 -1
  175. package/dist/types/relayFeeCalculator/chain-queries/svmQuery.d.ts +6 -6
  176. package/dist/types/relayFeeCalculator/chain-queries/svmQuery.d.ts.map +1 -1
  177. package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts +5 -5
  178. package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts.map +1 -1
  179. package/dist/types/utils/AddressUtils.d.ts +13 -14
  180. package/dist/types/utils/AddressUtils.d.ts.map +1 -1
  181. package/dist/types/utils/SpokeUtils.d.ts +3 -8
  182. package/dist/types/utils/SpokeUtils.d.ts.map +1 -1
  183. package/dist/types/utils/TokenUtils.d.ts +4 -16
  184. package/dist/types/utils/TokenUtils.d.ts.map +1 -1
  185. package/package.json +2 -3
  186. package/src/arch/evm/SpokeUtils.ts +52 -12
  187. package/src/arch/svm/SpokeUtils.ts +108 -59
  188. package/src/arch/svm/utils.ts +11 -20
  189. package/src/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.ts +7 -4
  190. package/src/clients/BundleDataClient/BundleDataClient.ts +57 -53
  191. package/src/clients/BundleDataClient/utils/DataworkerUtils.ts +28 -13
  192. package/src/clients/BundleDataClient/utils/FillUtils.ts +10 -4
  193. package/src/clients/BundleDataClient/utils/MerkleTreeUtils.ts +7 -1
  194. package/src/clients/BundleDataClient/utils/PoolRebalanceUtils.ts +4 -4
  195. package/src/clients/BundleDataClient/utils/SuperstructUtils.ts +13 -9
  196. package/src/clients/HubPoolClient.ts +126 -82
  197. package/src/clients/SpokePoolClient/EVMSpokePoolClient.ts +6 -0
  198. package/src/clients/SpokePoolClient/SpokePoolClient.ts +118 -35
  199. package/src/clients/mocks/MockHubPoolClient.ts +24 -19
  200. package/src/clients/mocks/MockSpokePoolClient.ts +39 -27
  201. package/src/clients/mocks/MockSvmCpiEventsClient.ts +3 -5
  202. package/src/clients/mocks/MockSvmSpokePoolClient.ts +12 -3
  203. package/src/interfaces/HubPool.ts +23 -14
  204. package/src/interfaces/SpokePool.ts +13 -13
  205. package/src/relayFeeCalculator/chain-queries/baseQuery.ts +14 -12
  206. package/src/relayFeeCalculator/chain-queries/svmQuery.ts +42 -46
  207. package/src/relayFeeCalculator/relayFeeCalculator.ts +20 -12
  208. package/src/utils/AddressUtils.ts +58 -60
  209. package/src/utils/EventUtils.ts +2 -2
  210. package/src/utils/SpokeUtils.ts +11 -33
  211. package/src/utils/TokenUtils.ts +10 -11
@@ -1,8 +1,9 @@
1
1
  import assert from "assert";
2
2
  import { BytesLike, Contract, PopulatedTransaction, providers } from "ethers";
3
3
  import { CHAIN_IDs } from "../../constants";
4
- import { Deposit, FillStatus, FillWithBlock, RelayData } from "../../interfaces";
4
+ import { Deposit, FillStatus, FillWithBlock, RelayData, RelayExecutionEventInfo } from "../../interfaces";
5
5
  import {
6
+ EvmAddress,
6
7
  bnUint32Max,
7
8
  BigNumber,
8
9
  toBN,
@@ -13,11 +14,11 @@ import {
13
14
  isDefined,
14
15
  isUnsafeDepositId,
15
16
  isZeroAddress,
16
- getDepositRelayData,
17
17
  getNetworkName,
18
18
  paginatedEventQuery,
19
19
  spreadEventWithBlockNumber,
20
- toBytes32,
20
+ Address,
21
+ toAddressType,
21
22
  } from "../../utils";
22
23
 
23
24
  type BlockTag = providers.BlockTag;
@@ -30,11 +31,32 @@ type BlockTag = providers.BlockTag;
30
31
  */
31
32
  export function populateV3Relay(
32
33
  spokePool: Contract,
33
- deposit: Omit<Deposit, "messageHash">,
34
- relayer: string,
34
+ deposit: Omit<Deposit, "messageHash" | "fromLiteChain" | "toLiteChain"> & {
35
+ recipient: EvmAddress;
36
+ outputToken: EvmAddress;
37
+ exclusiveRelayer: EvmAddress;
38
+ },
39
+ repaymentAddress: Address,
35
40
  repaymentChainId = deposit.destinationChainId
36
41
  ): Promise<PopulatedTransaction> {
37
- const relayData = getDepositRelayData(deposit);
42
+ assert(
43
+ repaymentAddress.isValidOn(repaymentChainId),
44
+ `Invalid repayment address for chain ${repaymentChainId}: ${repaymentAddress.toNative()}.`
45
+ );
46
+ const relayData = {
47
+ depositor: deposit.depositor.toBytes32(),
48
+ recipient: deposit.recipient.toBytes32(),
49
+ inputToken: deposit.inputToken.toBytes32(),
50
+ outputToken: deposit.outputToken.toBytes32(),
51
+ inputAmount: deposit.inputAmount,
52
+ outputAmount: deposit.outputAmount,
53
+ originChainId: deposit.originChainId,
54
+ depositId: deposit.depositId,
55
+ fillDeadline: deposit.fillDeadline,
56
+ exclusivityDeadline: deposit.exclusivityDeadline,
57
+ message: deposit.message,
58
+ exclusiveRelayer: deposit.exclusiveRelayer.toBytes32(),
59
+ };
38
60
 
39
61
  if (isDefined(deposit.speedUpSignature)) {
40
62
  assert(isDefined(deposit.updatedRecipient) && !isZeroAddress(deposit.updatedRecipient));
@@ -43,16 +65,15 @@ export function populateV3Relay(
43
65
  return spokePool.populateTransaction.fillRelayWithUpdatedDeposit(
44
66
  relayData,
45
67
  repaymentChainId,
46
- toBytes32(relayer),
68
+ repaymentAddress.toBytes32(),
47
69
  deposit.updatedOutputAmount,
48
- toBytes32(deposit.updatedRecipient),
70
+ deposit.updatedRecipient.toBytes32(),
49
71
  deposit.updatedMessage,
50
- deposit.speedUpSignature,
51
- { from: relayer }
72
+ deposit.speedUpSignature
52
73
  );
53
74
  }
54
75
 
55
- return spokePool.populateTransaction.fillRelay(relayData, repaymentChainId, toBytes32(relayer), { from: relayer });
76
+ return spokePool.populateTransaction.fillRelay(relayData, repaymentChainId, repaymentAddress.toBytes32());
56
77
  }
57
78
 
58
79
  /**
@@ -315,8 +336,27 @@ export async function findFillEvent(
315
336
  const destinationChainId = Object.values(CHAIN_IDs).includes(relayData.originChainId)
316
337
  ? (await spokePool.provider.getNetwork()).chainId
317
338
  : Number(await spokePool.chainId());
339
+ const fillEvent = spreadEventWithBlockNumber(event) as FillWithBlock & {
340
+ depositor: string;
341
+ recipient: string;
342
+ inputToken: string;
343
+ outputToken: string;
344
+ exclusiveRelayer: string;
345
+ relayer: string;
346
+ relayExecutionInfo: RelayExecutionEventInfo & { updatedRecipient: string };
347
+ };
318
348
  const fill = {
319
- ...spreadEventWithBlockNumber(event),
349
+ ...fillEvent,
350
+ inputToken: toAddressType(fillEvent.inputToken, relayData.originChainId),
351
+ outputToken: toAddressType(fillEvent.outputToken, destinationChainId),
352
+ depositor: toAddressType(fillEvent.depositor, relayData.originChainId),
353
+ recipient: toAddressType(fillEvent.recipient, destinationChainId),
354
+ exclusiveRelayer: toAddressType(fillEvent.exclusiveRelayer, destinationChainId),
355
+ relayer: toAddressType(fillEvent.relayer, destinationChainId),
356
+ relayExecutionInfo: {
357
+ ...fillEvent.relayExecutionInfo,
358
+ updatedRecipient: toAddressType(fillEvent.relayExecutionInfo.updatedRecipient, destinationChainId),
359
+ },
320
360
  destinationChainId,
321
361
  messageHash: getMessageHash(event.args.message),
322
362
  } as FillWithBlock;
@@ -10,7 +10,6 @@ import {
10
10
  } from "@solana-program/token";
11
11
  import {
12
12
  Address,
13
- address,
14
13
  appendTransactionMessageInstruction,
15
14
  fetchEncodedAccount,
16
15
  fetchEncodedAccounts,
@@ -19,26 +18,41 @@ import {
19
18
  getU32Encoder,
20
19
  getU64Encoder,
21
20
  pipe,
22
- ReadonlyUint8Array,
23
21
  some,
24
22
  type TransactionSigner,
25
23
  } from "@solana/kit";
26
24
  import assert from "assert";
27
25
  import { arrayify, hexZeroPad, hexlify } from "ethers/lib/utils";
28
26
  import { Logger } from "winston";
29
-
30
27
  import { SYSTEM_PROGRAM_ADDRESS } from "@solana-program/system";
31
- import { Deposit, DepositWithBlock, FillStatus, FillWithBlock, RelayData } from "../../interfaces";
32
- import { BigNumber, SvmAddress, chainIsSvm, chunk, isUnsafeDepositId, keccak256, toAddressType } from "../../utils";
28
+ import {
29
+ Deposit,
30
+ DepositWithBlock,
31
+ FillStatus,
32
+ FillWithBlock,
33
+ RelayData,
34
+ RelayExecutionEventInfo,
35
+ } from "../../interfaces";
36
+ import {
37
+ BigNumber,
38
+ EvmAddress,
39
+ SvmAddress,
40
+ chainIsSvm,
41
+ chunk,
42
+ isUnsafeDepositId,
43
+ keccak256,
44
+ toAddressType,
45
+ } from "../../utils";
33
46
  import {
34
47
  SvmCpiEventsClient,
35
- bigToU8a32,
36
48
  createDefaultTransaction,
37
49
  getEventAuthority,
38
50
  getFillStatusPda,
39
51
  getStatePda,
52
+ toAddress,
40
53
  unwrapEventData,
41
54
  } from "./";
55
+ import { CHAIN_IDs } from "../../constants";
42
56
  import { SVMEventNames, SVMProvider } from "./types";
43
57
 
44
58
  /**
@@ -138,13 +152,20 @@ export async function findDeposit(
138
152
  return undefined;
139
153
  }
140
154
 
155
+ const unwrappedDepositEvent = unwrapEventData(depositEvent.data) as Record<string, unknown>;
156
+ const destinationChainId = unwrappedDepositEvent.destinationChainId as number;
141
157
  // Return the deposit event with block info
142
158
  return {
143
159
  txnRef: depositEvent.signature.toString(),
144
160
  blockNumber: Number(depositEvent.slot),
145
161
  txnIndex: 0,
146
162
  logIndex: 0,
147
- ...(unwrapEventData(depositEvent.data) as Record<string, unknown>),
163
+ ...unwrappedDepositEvent,
164
+ depositor: toAddressType(unwrappedDepositEvent.depositor as string, CHAIN_IDs.SOLANA),
165
+ recipient: toAddressType(unwrappedDepositEvent.recipient as string, destinationChainId),
166
+ inputToken: toAddressType(unwrappedDepositEvent.inputToken as string, CHAIN_IDs.SOLANA),
167
+ outputToken: toAddressType(unwrappedDepositEvent.outputToken as string, destinationChainId),
168
+ exclusiveRelayer: toAddressType(unwrappedDepositEvent.exclusiveRelayer as string, destinationChainId),
148
169
  } as DepositWithBlock;
149
170
  }
150
171
 
@@ -320,14 +341,34 @@ export async function findFillEvent(
320
341
 
321
342
  if (fillEvents.length > 0) {
322
343
  const rawFillEvent = fillEvents[0];
344
+ const eventData = unwrapEventData(rawFillEvent.data) as FillWithBlock & {
345
+ depositor: string;
346
+ recipient: string;
347
+ inputToken: string;
348
+ outputToken: string;
349
+ exclusiveRelayer: string;
350
+ relayer: string;
351
+ relayExecutionInfo: RelayExecutionEventInfo & { updatedRecipient: string };
352
+ };
353
+ const originChainId = eventData.originChainId;
323
354
  const parsedFillEvent = {
355
+ ...eventData,
324
356
  transactionHash: rawFillEvent.signature,
325
357
  blockNumber: Number(rawFillEvent.slot),
326
358
  transactionIndex: 0,
327
359
  logIndex: 0,
328
360
  destinationChainId,
329
- ...(unwrapEventData(rawFillEvent.data) as Record<string, unknown>),
330
- } as unknown as FillWithBlock;
361
+ inputToken: toAddressType(eventData.inputToken, originChainId),
362
+ outputToken: toAddressType(eventData.outputToken, destinationChainId),
363
+ relayer: toAddressType(eventData.relayer, destinationChainId),
364
+ exclusiveRelayer: toAddressType(eventData.exclusiveRelayer, destinationChainId),
365
+ depositor: toAddressType(eventData.depositor, originChainId),
366
+ recipient: toAddressType(eventData.recipient, destinationChainId),
367
+ relayExecutionInfo: {
368
+ ...eventData.relayExecutionInfo,
369
+ updatedRecipient: eventData.relayExecutionInfo.updatedRecipient,
370
+ },
371
+ } as FillWithBlock;
331
372
  return parsedFillEvent;
332
373
  }
333
374
 
@@ -343,35 +384,36 @@ export async function findFillEvent(
343
384
  */
344
385
  export async function fillRelayInstruction(
345
386
  spokePool: SvmAddress,
346
- deposit: Omit<Deposit, "messageHash">,
347
- relayer: TransactionSigner<string>,
387
+ deposit: Omit<Deposit, "messageHash" | "fromLiteChain" | "toLiteChain"> & {
388
+ recipient: SvmAddress;
389
+ outputToken: SvmAddress;
390
+ exclusiveRelayer: SvmAddress;
391
+ },
392
+ signer: TransactionSigner<string>,
348
393
  recipientTokenAccount: Address<string>,
394
+ repaymentAddress: EvmAddress | SvmAddress = SvmAddress.from(signer.address),
349
395
  repaymentChainId = deposit.destinationChainId
350
396
  ) {
351
- const programId = spokePool.toBase58();
352
- const relayerAddress = SvmAddress.from(relayer.address);
397
+ const program = toAddress(spokePool);
353
398
 
354
- // @todo we need to convert the deposit's relayData to svm-like since the interface assumes the data originates from an EVM Spoke pool.
355
- // Once we migrate to `Address` types, this can be modified/removed.
356
- const [depositor, recipient, exclusiveRelayer, inputToken, outputToken] = [
357
- deposit.depositor,
358
- deposit.recipient,
359
- deposit.exclusiveRelayer,
360
- deposit.inputToken,
361
- deposit.outputToken,
362
- ].map((addr) => toAddressType(addr).forceSvmAddress());
399
+ assert(
400
+ repaymentAddress.isValidOn(repaymentChainId),
401
+ `Invalid repayment address for chain ${repaymentChainId}: ${repaymentAddress.toNative()}.`
402
+ );
363
403
 
364
404
  const _relayDataHash = getRelayDataHash(deposit, deposit.destinationChainId);
365
405
  const relayDataHash = new Uint8Array(Buffer.from(_relayDataHash.slice(2), "hex"));
366
406
 
407
+ const relayer = SvmAddress.from(signer.address);
367
408
  // Create ATA for the relayer and recipient token accounts
368
- const relayerTokenAccount = await getAssociatedTokenAddress(relayerAddress, outputToken);
409
+ const relayerTokenAccount = await getAssociatedTokenAddress(relayer, deposit.outputToken);
369
410
 
370
411
  const [statePda, fillStatusPda, eventAuthority] = await Promise.all([
371
- getStatePda(spokePool.toV2Address()),
372
- getFillStatusPda(spokePool.toV2Address(), deposit, deposit.destinationChainId),
373
- getEventAuthority(),
412
+ getStatePda(program),
413
+ getFillStatusPda(program, deposit, deposit.destinationChainId),
414
+ getEventAuthority(program),
374
415
  ]);
416
+
375
417
  const depositIdBuffer = new Uint8Array(32);
376
418
  const shortenedBuffer = new Uint8Array(Buffer.from(deposit.depositId.toHexString().slice(2), "hex"));
377
419
  depositIdBuffer.set(shortenedBuffer, 32 - shortenedBuffer.length);
@@ -379,28 +421,37 @@ export async function fillRelayInstruction(
379
421
  const delegatePda = await getFillRelayDelegatePda(
380
422
  relayDataHash,
381
423
  BigInt(repaymentChainId),
382
- relayerAddress.toV2Address(),
383
- spokePool.toV2Address()
424
+ toAddress(relayer),
425
+ program
384
426
  );
385
427
 
428
+ // @todo we need to convert the deposit's relayData to svm-like since the interface assumes the data originates
429
+ // from an EVM Spoke pool. Once we migrate to `Address` types, this can be modified/removed.
430
+ const [depositor, inputToken] = [deposit.depositor, deposit.inputToken].map(toAddress);
431
+ const [recipient, outputToken, exclusiveRelayer] = [
432
+ deposit.recipient,
433
+ deposit.outputToken,
434
+ deposit.exclusiveRelayer,
435
+ ].map(toAddress);
436
+
386
437
  return SvmSpokeClient.getFillRelayInstruction({
387
- signer: relayer,
438
+ signer,
388
439
  state: statePda,
389
- delegate: SvmAddress.from(delegatePda.toString()).toV2Address(),
390
- mint: outputToken.toV2Address(),
440
+ delegate: toAddress(SvmAddress.from(delegatePda.toString())),
441
+ mint: outputToken,
391
442
  relayerTokenAccount: relayerTokenAccount,
392
443
  recipientTokenAccount: recipientTokenAccount,
393
444
  fillStatus: fillStatusPda,
394
445
  eventAuthority,
395
- program: address(programId),
446
+ program,
396
447
  relayHash: relayDataHash,
397
448
  relayData: some({
398
- depositor: depositor.toV2Address(),
399
- recipient: recipient.toV2Address(),
400
- exclusiveRelayer: exclusiveRelayer.toV2Address(),
401
- inputToken: inputToken.toV2Address(),
402
- outputToken: outputToken.toV2Address(),
403
- inputAmount: bigToU8a32(deposit.inputAmount),
449
+ depositor,
450
+ recipient,
451
+ exclusiveRelayer,
452
+ inputToken,
453
+ outputToken,
454
+ inputAmount: deposit.inputAmount.toBigInt(),
404
455
  outputAmount: deposit.outputAmount.toBigInt(),
405
456
  originChainId: BigInt(deposit.originChainId),
406
457
  fillDeadline: deposit.fillDeadline,
@@ -409,7 +460,7 @@ export async function fillRelayInstruction(
409
460
  message: new Uint8Array(Buffer.from(deposit.message.slice(2), "hex")),
410
461
  }),
411
462
  repaymentChainId: some(BigInt(repaymentChainId)),
412
- repaymentAddress: some(relayerAddress.toV2Address()),
463
+ repaymentAddress: toAddress(repaymentAddress),
413
464
  });
414
465
  }
415
466
 
@@ -424,7 +475,7 @@ export function createTokenAccountsInstruction(
424
475
  ): SvmSpokeClient.CreateTokenAccountsInstruction {
425
476
  return SvmSpokeClient.getCreateTokenAccountsInstruction({
426
477
  signer: relayer,
427
- mint: mint.toV2Address(),
478
+ mint: toAddress(mint),
428
479
  });
429
480
  }
430
481
 
@@ -469,7 +520,7 @@ export const createFillInstruction = async (
469
520
  tokenProgram: fillInput.tokenProgram,
470
521
  });
471
522
 
472
- const createFillIx = await SvmSpokeClient.getFillRelayInstruction(fillInput);
523
+ const createFillIx = SvmSpokeClient.getFillRelayInstruction(fillInput);
473
524
 
474
525
  return pipe(
475
526
  await createDefaultTransaction(solanaClient, signer),
@@ -519,7 +570,7 @@ export const createDepositInstruction = async (
519
570
  programAddress: mintInfo.programAddress,
520
571
  }
521
572
  );
522
- const depositIx = await SvmSpokeClient.getDepositInstruction(depositInput);
573
+ const depositIx = SvmSpokeClient.getDepositInstruction(depositInput);
523
574
  return pipe(
524
575
  await createDefaultTransaction(solanaClient, signer),
525
576
  (tx) =>
@@ -541,7 +592,7 @@ export const createRequestSlowFillInstruction = async (
541
592
  solanaClient: SVMProvider,
542
593
  depositInput: SvmSpokeClient.RequestSlowFillInput
543
594
  ) => {
544
- const requestSlowFillIx = await SvmSpokeClient.getRequestSlowFillInstruction(depositInput);
595
+ const requestSlowFillIx = SvmSpokeClient.getRequestSlowFillInstruction(depositInput);
545
596
 
546
597
  return pipe(await createDefaultTransaction(solanaClient, signer), (tx) =>
547
598
  appendTransactionMessageInstruction(requestSlowFillIx, tx)
@@ -560,7 +611,7 @@ export const createCloseFillPdaInstruction = async (
560
611
  solanaClient: SVMProvider,
561
612
  fillStatusPda: Address
562
613
  ) => {
563
- const closeFillPdaIx = await SvmSpokeClient.getCloseFillPdaInstruction({
614
+ const closeFillPdaIx = SvmSpokeClient.getCloseFillPdaInstruction({
564
615
  signer,
565
616
  state: await getStatePda(SvmSpokeClient.SVM_SPOKE_PROGRAM_ADDRESS),
566
617
  fillStatus: fillStatusPda,
@@ -574,13 +625,10 @@ export async function getAssociatedTokenAddress(
574
625
  mint: SvmAddress,
575
626
  tokenProgramId: Address<string> = TOKEN_PROGRAM_ADDRESS
576
627
  ): Promise<Address<string>> {
628
+ const encoder = getAddressEncoder();
577
629
  const [associatedToken] = await getProgramDerivedAddress({
578
630
  programAddress: ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
579
- seeds: [
580
- new Uint8Array(owner.toBuffer()),
581
- new Uint8Array(SvmAddress.from(tokenProgramId).toBuffer()),
582
- new Uint8Array(mint.toBuffer()),
583
- ],
631
+ seeds: [encoder.encode(toAddress(owner)), encoder.encode(tokenProgramId), encoder.encode(toAddress(mint))],
584
632
  });
585
633
  return associatedToken;
586
634
  }
@@ -591,14 +639,15 @@ export function getRelayDataHash(relayData: RelayData, destinationChainId: numbe
591
639
  const uint32Encoder = getU32Encoder();
592
640
 
593
641
  assert(relayData.message.startsWith("0x"), "Message must be a hex string");
642
+ const encodeAddress = (data: SvmAddress) => Uint8Array.from(addressEncoder.encode(toAddress(data)));
594
643
 
595
644
  const contentToHash = Buffer.concat([
596
- Uint8Array.from(addressEncoder.encode(SvmAddress.from(relayData.depositor, "base16").toV2Address())),
597
- Uint8Array.from(addressEncoder.encode(SvmAddress.from(relayData.recipient, "base16").toV2Address())),
598
- Uint8Array.from(addressEncoder.encode(SvmAddress.from(relayData.exclusiveRelayer, "base16").toV2Address())),
599
- Uint8Array.from(addressEncoder.encode(SvmAddress.from(relayData.inputToken, "base16").toV2Address())),
600
- Uint8Array.from(addressEncoder.encode(SvmAddress.from(relayData.outputToken, "base16").toV2Address())),
601
- arrayify(hexZeroPad(hexlify(relayData.inputAmount), 32)),
645
+ encodeAddress(relayData.depositor),
646
+ encodeAddress(relayData.recipient),
647
+ encodeAddress(relayData.exclusiveRelayer),
648
+ encodeAddress(relayData.inputToken),
649
+ encodeAddress(relayData.outputToken),
650
+ Uint8Array.from(uint64Encoder.encode(BigInt(relayData.inputAmount.toString()))),
602
651
  Uint8Array.from(uint64Encoder.encode(BigInt(relayData.outputAmount.toString()))),
603
652
  Uint8Array.from(uint64Encoder.encode(BigInt(relayData.originChainId.toString()))),
604
653
  arrayify(hexZeroPad(hexlify(relayData.depositId), 32)),
@@ -706,7 +755,7 @@ export async function getDepositDelegatePda(
706
755
  inputToken: Address<string>;
707
756
  outputToken: Address<string>;
708
757
  inputAmount: bigint;
709
- outputAmount: ReadonlyUint8Array;
758
+ outputAmount: bigint;
710
759
  destinationChainId: bigint;
711
760
  exclusiveRelayer: Address<string>;
712
761
  quoteTimestamp: bigint;
@@ -726,7 +775,7 @@ export async function getDepositDelegatePda(
726
775
  Uint8Array.from(addrEnc.encode(depositData.inputToken)),
727
776
  Uint8Array.from(addrEnc.encode(depositData.outputToken)),
728
777
  Uint8Array.from(u64.encode(depositData.inputAmount)),
729
- Uint8Array.from(depositData.outputAmount),
778
+ Uint8Array.from(u64.encode(depositData.outputAmount)),
730
779
  Uint8Array.from(u64.encode(depositData.destinationChainId)),
731
780
  Uint8Array.from(addrEnc.encode(depositData.exclusiveRelayer)),
732
781
  Uint8Array.from(u32.encode(depositData.quoteTimestamp)),
@@ -756,7 +805,7 @@ export async function getDepositNowDelegatePda(
756
805
  inputToken: Address<string>;
757
806
  outputToken: Address<string>;
758
807
  inputAmount: bigint;
759
- outputAmount: ReadonlyUint8Array;
808
+ outputAmount: bigint;
760
809
  destinationChainId: bigint;
761
810
  exclusiveRelayer: Address<string>;
762
811
  fillDeadlineOffset: bigint;
@@ -775,7 +824,7 @@ export async function getDepositNowDelegatePda(
775
824
  Uint8Array.from(addrEnc.encode(depositData.inputToken)),
776
825
  Uint8Array.from(addrEnc.encode(depositData.outputToken)),
777
826
  Uint8Array.from(u64.encode(depositData.inputAmount)),
778
- Uint8Array.from(depositData.outputAmount),
827
+ Uint8Array.from(u64.encode(depositData.outputAmount)),
779
828
  Uint8Array.from(u64.encode(depositData.destinationChainId)),
780
829
  Uint8Array.from(addrEnc.encode(depositData.exclusiveRelayer)),
781
830
  Uint8Array.from(u32.encode(depositData.fillDeadlineOffset)),
@@ -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 } from "../../utils";
20
+ import { BigNumber, EvmAddress, SvmAddress, getRelayDataHash, isUint8Array } from "../../utils";
21
21
  import { EventName, SVMEventNames, SVMProvider } from "./types";
22
22
 
23
23
  /**
@@ -42,6 +42,13 @@ export async function isDevnet(rpc: SVMProvider): Promise<boolean> {
42
42
  return genesisHash === "EtWTRABZaYq6iMfeYKouRu166VU2xqa1wcaWoxPkrZBG";
43
43
  }
44
44
 
45
+ /**
46
+ * Small utility to convert an Address to a Solana Kit branded type.
47
+ */
48
+ export function toAddress(address: EvmAddress | SvmAddress): Address<string> {
49
+ return address.toBase58() as Address<string>;
50
+ }
51
+
45
52
  /**
46
53
  * Parses event data from a transaction.
47
54
  */
@@ -273,13 +280,13 @@ export async function getInstructionParamsPda(programId: Address, signer: Addres
273
280
  * Returns the PDA for the Event Authority.
274
281
  * @returns The PDA for the Event Authority.
275
282
  */
276
- export const getEventAuthority = async () => {
283
+ export async function getEventAuthority(programId: Address): Promise<Address> {
277
284
  const [eventAuthority] = await getProgramDerivedAddress({
278
- programAddress: address(SvmSpokeClient.SVM_SPOKE_PROGRAM_ADDRESS),
285
+ programAddress: programId,
279
286
  seeds: ["__event_authority"],
280
287
  });
281
288
  return eventAuthority;
282
- };
289
+ }
283
290
 
284
291
  /**
285
292
  * Returns a random SVM address.
@@ -304,19 +311,3 @@ export const createDefaultTransaction = async (rpcClient: SVMProvider, signer: T
304
311
  (tx) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx)
305
312
  );
306
313
  };
307
-
308
- /**
309
- * Convert a bigint (0 ≤ n < 2^256) to a 32-byte Uint8Array (big-endian).
310
- */
311
- export function bigintToU8a32(n: bigint): Uint8Array {
312
- if (n < BigInt(0) || n > ethers.constants.MaxUint256.toBigInt()) {
313
- throw new RangeError("Value must fit in 256 bits");
314
- }
315
- const hexPadded = ethers.utils.hexZeroPad("0x" + n.toString(16), 32);
316
- return ethers.utils.arrayify(hexPadded);
317
- }
318
-
319
- export const bigToU8a32 = (bn: bigint | BigNumber) =>
320
- bigintToU8a32(typeof bn === "bigint" ? bn : BigInt(bn.toString()));
321
-
322
- export const numberToU8a32 = (n: number) => bigintToU8a32(BigInt(n));
@@ -5,6 +5,7 @@ import winston from "winston";
5
5
  import { isError } from "../../typeguards";
6
6
  import {
7
7
  EventSearchConfig,
8
+ EvmAddress,
8
9
  MakeOptional,
9
10
  isArrayOf,
10
11
  isDefined,
@@ -107,7 +108,7 @@ export class AcrossConfigStoreClient extends BaseAbstractClient {
107
108
  }
108
109
 
109
110
  getRateModelForBlockNumber(
110
- l1Token: string,
111
+ l1Token: EvmAddress,
111
112
  originChainId: number | string,
112
113
  destinationChainId: number | string,
113
114
  blockNumber: number | undefined = undefined
@@ -121,7 +122,9 @@ export class AcrossConfigStoreClient extends BaseAbstractClient {
121
122
 
122
123
  const defaultRateModelUpdate = sortEventsDescending(this.cumulativeRateModelUpdates).find(
123
124
  (config) =>
124
- config.blockNumber <= (blockNumber ?? 0) && config.l1Token === l1Token && config.rateModel !== undefined
125
+ config.blockNumber <= (blockNumber ?? 0) &&
126
+ config.l1Token === l1Token.toEvmAddress() &&
127
+ config.rateModel !== undefined
125
128
  );
126
129
  if (!defaultRateModelUpdate) {
127
130
  throw new Error(`Could not find TokenConfig update for ${l1Token} at block ${blockNumber}`);
@@ -130,12 +133,12 @@ export class AcrossConfigStoreClient extends BaseAbstractClient {
130
133
  }
131
134
 
132
135
  getRouteRateModelForBlockNumber(
133
- l1Token: string,
136
+ l1Token: EvmAddress,
134
137
  route: string,
135
138
  blockNumber: number | undefined = undefined
136
139
  ): RateModel | undefined {
137
140
  const config = (sortEventsDescending(this.cumulativeRouteRateModelUpdates) as RouteRateModelUpdate[]).find(
138
- (config) => config.blockNumber <= (blockNumber ?? 0) && config.l1Token === l1Token
141
+ (config) => config.blockNumber <= (blockNumber ?? 0) && config.l1Token === l1Token.toEvmAddress()
139
142
  );
140
143
  if (config?.routeRateModel[route] === undefined) {
141
144
  return undefined;