@across-protocol/sdk 3.1.26 → 3.1.28-beta.1

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 (181) hide show
  1. package/dist/cjs/clients/BundleDataClient/BundleDataClient.d.ts +59 -0
  2. package/dist/cjs/clients/BundleDataClient/BundleDataClient.js +926 -0
  3. package/dist/cjs/clients/BundleDataClient/BundleDataClient.js.map +1 -0
  4. package/dist/cjs/clients/BundleDataClient/index.d.ts +2 -0
  5. package/dist/cjs/clients/BundleDataClient/index.js +6 -0
  6. package/dist/cjs/clients/BundleDataClient/index.js.map +1 -0
  7. package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.d.ts +15 -0
  8. package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js +131 -0
  9. package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -0
  10. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.d.ts +6 -0
  11. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js +19 -0
  12. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js.map +1 -0
  13. package/dist/cjs/clients/BundleDataClient/utils/MerkleTreeUtils.d.ts +3 -0
  14. package/dist/cjs/clients/BundleDataClient/utils/MerkleTreeUtils.js +23 -0
  15. package/dist/cjs/clients/BundleDataClient/utils/MerkleTreeUtils.js.map +1 -0
  16. package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.d.ts +24 -0
  17. package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js +129 -0
  18. package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -0
  19. package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.d.ts +302 -0
  20. package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.js +77 -0
  21. package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -0
  22. package/dist/cjs/clients/BundleDataClient/utils/index.d.ts +6 -0
  23. package/dist/cjs/clients/BundleDataClient/utils/index.js +10 -0
  24. package/dist/cjs/clients/BundleDataClient/utils/index.js.map +1 -0
  25. package/dist/cjs/clients/BundleDataClient/utils/shims.d.ts +8 -0
  26. package/dist/cjs/clients/BundleDataClient/utils/shims.js +3 -0
  27. package/dist/cjs/clients/BundleDataClient/utils/shims.js.map +1 -0
  28. package/dist/cjs/clients/index.d.ts +1 -0
  29. package/dist/cjs/clients/index.js +2 -1
  30. package/dist/cjs/clients/index.js.map +1 -1
  31. package/dist/cjs/interfaces/BundleData.d.ts +63 -0
  32. package/dist/cjs/interfaces/BundleData.js +3 -0
  33. package/dist/cjs/interfaces/BundleData.js.map +1 -0
  34. package/dist/cjs/interfaces/index.d.ts +1 -0
  35. package/dist/cjs/interfaces/index.js +1 -0
  36. package/dist/cjs/interfaces/index.js.map +1 -1
  37. package/dist/cjs/providers/alchemy.d.ts +2 -0
  38. package/dist/cjs/providers/alchemy.js +28 -0
  39. package/dist/cjs/providers/alchemy.js.map +1 -0
  40. package/dist/cjs/providers/index.d.ts +1 -0
  41. package/dist/cjs/providers/index.js +1 -0
  42. package/dist/cjs/providers/index.js.map +1 -1
  43. package/dist/cjs/providers/infura.d.ts +2 -0
  44. package/dist/cjs/providers/infura.js +23 -0
  45. package/dist/cjs/providers/infura.js.map +1 -0
  46. package/dist/cjs/providers/types.d.ts +2 -0
  47. package/dist/cjs/providers/types.js +3 -0
  48. package/dist/cjs/providers/types.js.map +1 -0
  49. package/dist/cjs/providers/utils.d.ts +3 -0
  50. package/dist/cjs/providers/utils.js +21 -2
  51. package/dist/cjs/providers/utils.js.map +1 -1
  52. package/dist/cjs/utils/AddressUtils.d.ts +1 -0
  53. package/dist/cjs/utils/AddressUtils.js +15 -1
  54. package/dist/cjs/utils/AddressUtils.js.map +1 -1
  55. package/dist/cjs/utils/ContractUtils.d.ts +1 -0
  56. package/dist/cjs/utils/ContractUtils.js +12 -0
  57. package/dist/cjs/utils/ContractUtils.js.map +1 -0
  58. package/dist/cjs/utils/ObjectUtils.d.ts +18 -0
  59. package/dist/cjs/utils/ObjectUtils.js +27 -1
  60. package/dist/cjs/utils/ObjectUtils.js.map +1 -1
  61. package/dist/esm/clients/BundleDataClient/BundleDataClient.d.ts +59 -0
  62. package/dist/esm/clients/BundleDataClient/BundleDataClient.js +1090 -0
  63. package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -0
  64. package/dist/esm/clients/BundleDataClient/index.d.ts +2 -0
  65. package/dist/esm/clients/BundleDataClient/index.js +3 -0
  66. package/dist/esm/clients/BundleDataClient/index.js.map +1 -0
  67. package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.d.ts +15 -0
  68. package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js +182 -0
  69. package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -0
  70. package/dist/esm/clients/BundleDataClient/utils/FillUtils.d.ts +6 -0
  71. package/dist/esm/clients/BundleDataClient/utils/FillUtils.js +20 -0
  72. package/dist/esm/clients/BundleDataClient/utils/FillUtils.js.map +1 -0
  73. package/dist/esm/clients/BundleDataClient/utils/MerkleTreeUtils.d.ts +3 -0
  74. package/dist/esm/clients/BundleDataClient/utils/MerkleTreeUtils.js +20 -0
  75. package/dist/esm/clients/BundleDataClient/utils/MerkleTreeUtils.js.map +1 -0
  76. package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.d.ts +24 -0
  77. package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js +157 -0
  78. package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -0
  79. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.d.ts +302 -0
  80. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js +79 -0
  81. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -0
  82. package/dist/esm/clients/BundleDataClient/utils/index.d.ts +6 -0
  83. package/dist/esm/clients/BundleDataClient/utils/index.js +7 -0
  84. package/dist/esm/clients/BundleDataClient/utils/index.js.map +1 -0
  85. package/dist/esm/clients/BundleDataClient/utils/shims.d.ts +8 -0
  86. package/dist/esm/clients/BundleDataClient/utils/shims.js +2 -0
  87. package/dist/esm/clients/BundleDataClient/utils/shims.js.map +1 -0
  88. package/dist/esm/clients/index.d.ts +1 -0
  89. package/dist/esm/clients/index.js +2 -0
  90. package/dist/esm/clients/index.js.map +1 -1
  91. package/dist/esm/interfaces/BundleData.d.ts +63 -0
  92. package/dist/esm/interfaces/BundleData.js +2 -0
  93. package/dist/esm/interfaces/BundleData.js.map +1 -0
  94. package/dist/esm/interfaces/index.d.ts +1 -0
  95. package/dist/esm/interfaces/index.js +1 -0
  96. package/dist/esm/interfaces/index.js.map +1 -1
  97. package/dist/esm/providers/alchemy.d.ts +2 -0
  98. package/dist/esm/providers/alchemy.js +25 -0
  99. package/dist/esm/providers/alchemy.js.map +1 -0
  100. package/dist/esm/providers/index.d.ts +1 -0
  101. package/dist/esm/providers/index.js +1 -0
  102. package/dist/esm/providers/index.js.map +1 -1
  103. package/dist/esm/providers/infura.d.ts +2 -0
  104. package/dist/esm/providers/infura.js +20 -0
  105. package/dist/esm/providers/infura.js.map +1 -0
  106. package/dist/esm/providers/types.d.ts +2 -0
  107. package/dist/esm/providers/types.js +2 -0
  108. package/dist/esm/providers/types.js.map +1 -0
  109. package/dist/esm/providers/utils.d.ts +16 -0
  110. package/dist/esm/providers/utils.js +35 -2
  111. package/dist/esm/providers/utils.js.map +1 -1
  112. package/dist/esm/utils/AddressUtils.d.ts +1 -0
  113. package/dist/esm/utils/AddressUtils.js +16 -1
  114. package/dist/esm/utils/AddressUtils.js.map +1 -1
  115. package/dist/esm/utils/ContractUtils.d.ts +1 -0
  116. package/dist/esm/utils/ContractUtils.js +8 -0
  117. package/dist/esm/utils/ContractUtils.js.map +1 -0
  118. package/dist/esm/utils/ObjectUtils.d.ts +18 -0
  119. package/dist/esm/utils/ObjectUtils.js +24 -0
  120. package/dist/esm/utils/ObjectUtils.js.map +1 -1
  121. package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts +60 -0
  122. package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -0
  123. package/dist/types/clients/BundleDataClient/index.d.ts +3 -0
  124. package/dist/types/clients/BundleDataClient/index.d.ts.map +1 -0
  125. package/dist/types/clients/BundleDataClient/utils/DataworkerUtils.d.ts +16 -0
  126. package/dist/types/clients/BundleDataClient/utils/DataworkerUtils.d.ts.map +1 -0
  127. package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts +7 -0
  128. package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts.map +1 -0
  129. package/dist/types/clients/BundleDataClient/utils/MerkleTreeUtils.d.ts +4 -0
  130. package/dist/types/clients/BundleDataClient/utils/MerkleTreeUtils.d.ts.map +1 -0
  131. package/dist/types/clients/BundleDataClient/utils/PoolRebalanceUtils.d.ts +25 -0
  132. package/dist/types/clients/BundleDataClient/utils/PoolRebalanceUtils.d.ts.map +1 -0
  133. package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts +303 -0
  134. package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts.map +1 -0
  135. package/dist/types/clients/BundleDataClient/utils/index.d.ts +7 -0
  136. package/dist/types/clients/BundleDataClient/utils/index.d.ts.map +1 -0
  137. package/dist/types/clients/BundleDataClient/utils/shims.d.ts +9 -0
  138. package/dist/types/clients/BundleDataClient/utils/shims.d.ts.map +1 -0
  139. package/dist/types/clients/index.d.ts +1 -0
  140. package/dist/types/clients/index.d.ts.map +1 -1
  141. package/dist/types/interfaces/BundleData.d.ts +64 -0
  142. package/dist/types/interfaces/BundleData.d.ts.map +1 -0
  143. package/dist/types/interfaces/index.d.ts +1 -0
  144. package/dist/types/interfaces/index.d.ts.map +1 -1
  145. package/dist/types/providers/alchemy.d.ts +3 -0
  146. package/dist/types/providers/alchemy.d.ts.map +1 -0
  147. package/dist/types/providers/index.d.ts +1 -0
  148. package/dist/types/providers/index.d.ts.map +1 -1
  149. package/dist/types/providers/infura.d.ts +3 -0
  150. package/dist/types/providers/infura.d.ts.map +1 -0
  151. package/dist/types/providers/types.d.ts +3 -0
  152. package/dist/types/providers/types.d.ts.map +1 -0
  153. package/dist/types/providers/utils.d.ts +16 -0
  154. package/dist/types/providers/utils.d.ts.map +1 -1
  155. package/dist/types/utils/AddressUtils.d.ts +1 -0
  156. package/dist/types/utils/AddressUtils.d.ts.map +1 -1
  157. package/dist/types/utils/ContractUtils.d.ts +2 -0
  158. package/dist/types/utils/ContractUtils.d.ts.map +1 -0
  159. package/dist/types/utils/ObjectUtils.d.ts +18 -0
  160. package/dist/types/utils/ObjectUtils.d.ts.map +1 -1
  161. package/package.json +1 -1
  162. package/src/clients/BundleDataClient/BundleDataClient.ts +1297 -0
  163. package/src/clients/BundleDataClient/index.ts +2 -0
  164. package/src/clients/BundleDataClient/utils/DataworkerUtils.ts +268 -0
  165. package/src/clients/BundleDataClient/utils/FillUtils.ts +46 -0
  166. package/src/clients/BundleDataClient/utils/MerkleTreeUtils.ts +26 -0
  167. package/src/clients/BundleDataClient/utils/PoolRebalanceUtils.ts +238 -0
  168. package/src/clients/BundleDataClient/utils/SuperstructUtils.ts +132 -0
  169. package/src/clients/BundleDataClient/utils/index.ts +6 -0
  170. package/src/clients/BundleDataClient/utils/shims.ts +10 -0
  171. package/src/clients/index.ts +1 -0
  172. package/src/interfaces/BundleData.ts +68 -0
  173. package/src/interfaces/index.ts +1 -0
  174. package/src/providers/alchemy.ts +28 -0
  175. package/src/providers/index.ts +1 -0
  176. package/src/providers/infura.ts +23 -0
  177. package/src/providers/types.ts +2 -0
  178. package/src/providers/utils.ts +42 -2
  179. package/src/utils/AddressUtils.ts +15 -1
  180. package/src/utils/ContractUtils.ts +8 -0
  181. package/src/utils/ObjectUtils.ts +23 -0
@@ -0,0 +1,132 @@
1
+ import {
2
+ object,
3
+ number,
4
+ optional,
5
+ string,
6
+ array,
7
+ record,
8
+ coerce,
9
+ instance,
10
+ pattern,
11
+ boolean,
12
+ defaulted,
13
+ } from "superstruct";
14
+ import { BigNumber } from "ethers";
15
+
16
+ const PositiveIntegerStringSS = pattern(string(), /\d+/);
17
+ const Web3AddressSS = pattern(string(), /^0x[a-fA-F0-9]{40}$/);
18
+
19
+ const BigNumberType = coerce(instance(BigNumber), string(), (value) => {
20
+ try {
21
+ // Attempt to convert the string to a BigNumber
22
+ return BigNumber.from(value);
23
+ } catch (error) {
24
+ // In case of any error during conversion, return the original value
25
+ // This will lead to a validation error, as the resulting value won't match the expected BigNumber type
26
+ return value;
27
+ }
28
+ });
29
+
30
+ const FillTypeSS = number();
31
+
32
+ const V3RelayDataSS = {
33
+ inputToken: string(),
34
+ inputAmount: BigNumberType,
35
+ outputToken: string(),
36
+ outputAmount: BigNumberType,
37
+ fillDeadline: number(),
38
+ exclusiveRelayer: string(),
39
+ exclusivityDeadline: number(),
40
+ originChainId: number(),
41
+ depositor: string(),
42
+ recipient: string(),
43
+ depositId: number(),
44
+ message: string(),
45
+ };
46
+
47
+ const SortableEventSS = {
48
+ blockNumber: number(),
49
+ transactionIndex: number(),
50
+ logIndex: number(),
51
+ transactionHash: string(),
52
+ };
53
+
54
+ const V3DepositSS = {
55
+ fromLiteChain: defaulted(boolean(), false),
56
+ toLiteChain: defaulted(boolean(), false),
57
+ destinationChainId: number(),
58
+ quoteTimestamp: number(),
59
+ relayerFeePct: optional(BigNumberType),
60
+ speedUpSignature: optional(string()),
61
+ updatedRecipient: optional(string()),
62
+ updatedOutputAmount: optional(BigNumberType),
63
+ updatedMessage: optional(string()),
64
+ };
65
+
66
+ const _V3DepositWithBlockSS = {
67
+ quoteBlockNumber: number(),
68
+ ...V3DepositSS,
69
+ ...SortableEventSS,
70
+ ...V3RelayDataSS,
71
+ };
72
+
73
+ const V3DepositWithBlockSS = object(_V3DepositWithBlockSS);
74
+ const V3DepositWithBlockLpFeeSS = object({
75
+ ..._V3DepositWithBlockSS,
76
+ lpFeePct: BigNumberType,
77
+ });
78
+
79
+ const V3RelayExecutionEventInfoSS = object({
80
+ updatedOutputAmount: BigNumberType,
81
+ fillType: FillTypeSS,
82
+ updatedRecipient: string(),
83
+ updatedMessage: string(),
84
+ });
85
+
86
+ const V3FillSS = {
87
+ ...V3RelayDataSS,
88
+ destinationChainId: number(),
89
+ relayer: string(),
90
+ repaymentChainId: number(),
91
+ relayExecutionInfo: V3RelayExecutionEventInfoSS,
92
+ quoteTimestamp: number(),
93
+ };
94
+
95
+ const V3FillWithBlockSS = {
96
+ ...SortableEventSS,
97
+ ...V3FillSS,
98
+ };
99
+
100
+ const BundleFillV3SS = object({
101
+ ...V3FillWithBlockSS,
102
+ lpFeePct: BigNumberType,
103
+ });
104
+
105
+ const nestedV3DepositRecordSS = record(PositiveIntegerStringSS, record(Web3AddressSS, array(V3DepositWithBlockSS)));
106
+ const nestedV3DepositRecordWithLpFeePctSS = record(
107
+ PositiveIntegerStringSS,
108
+ record(Web3AddressSS, array(V3DepositWithBlockLpFeeSS))
109
+ );
110
+
111
+ const nestedV3BundleFillsSS = record(
112
+ // Must be a chainId
113
+ PositiveIntegerStringSS,
114
+ record(
115
+ Web3AddressSS,
116
+ object({
117
+ fills: array(BundleFillV3SS),
118
+ refunds: record(string(), BigNumberType),
119
+ totalRefundAmount: BigNumberType,
120
+ realizedLpFees: BigNumberType,
121
+ })
122
+ )
123
+ );
124
+
125
+ export const BundleDataSS = object({
126
+ bundleBlockRanges: array(array(number())),
127
+ bundleDepositsV3: nestedV3DepositRecordSS,
128
+ expiredDepositsToRefundV3: nestedV3DepositRecordSS,
129
+ unexecutableSlowFills: nestedV3DepositRecordWithLpFeePctSS,
130
+ bundleSlowFillsV3: nestedV3DepositRecordWithLpFeePctSS,
131
+ bundleFillsV3: nestedV3BundleFillsSS,
132
+ });
@@ -0,0 +1,6 @@
1
+ export * from "./shims";
2
+ export * from "./FillUtils";
3
+ export * from "./DataworkerUtils";
4
+ export * from "./PoolRebalanceUtils";
5
+ export * from "./SuperstructUtils";
6
+ export * from "./MerkleTreeUtils";
@@ -0,0 +1,10 @@
1
+ import { RelayData, Deposit, DepositWithBlock, SpeedUp, Fill, FillWithBlock, SlowFillLeaf } from "../../../interfaces";
2
+
3
+ // V3 shims (to be removed later)
4
+ export type V3RelayData = RelayData;
5
+ export type V3Deposit = Deposit;
6
+ export type V3DepositWithBlock = DepositWithBlock;
7
+ export type V3SpeedUp = SpeedUp;
8
+ export type V3Fill = Fill;
9
+ export type V3FillWithBlock = FillWithBlock;
10
+ export type V3SlowFillLeaf = SlowFillLeaf;
@@ -6,4 +6,5 @@ export {
6
6
  } from "./AcrossConfigStoreClient";
7
7
  export { HubPoolClient, LpFeeRequest } from "./HubPoolClient";
8
8
  export { SpokePoolClient, SpokePoolUpdate } from "./SpokePoolClient";
9
+ export * as BundleDataClient from "./BundleDataClient";
9
10
  export * as mocks from "./mocks";
@@ -0,0 +1,68 @@
1
+ import { BigNumber, Signer } from "ethers";
2
+ import { DepositWithBlock, FillWithBlock, Refund } from "./SpokePool";
3
+ import { HubPoolClient } from "../clients/HubPoolClient";
4
+ import { AcrossConfigStoreClient } from "../clients";
5
+ import { ArweaveClient } from "../caching";
6
+
7
+ export type ExpiredDepositsToRefundV3 = {
8
+ [originChainId: number]: {
9
+ [originToken: string]: DepositWithBlock[];
10
+ };
11
+ };
12
+
13
+ export type BundleDepositsV3 = {
14
+ [originChainId: number]: {
15
+ [originToken: string]: DepositWithBlock[];
16
+ };
17
+ };
18
+
19
+ export interface BundleFillV3 extends FillWithBlock {
20
+ lpFeePct: BigNumber;
21
+ }
22
+
23
+ export type BundleFillsV3 = {
24
+ [repaymentChainId: number]: {
25
+ [repaymentToken: string]: {
26
+ fills: BundleFillV3[];
27
+ refunds: Refund;
28
+ totalRefundAmount: BigNumber;
29
+ realizedLpFees: BigNumber;
30
+ };
31
+ };
32
+ };
33
+
34
+ export type BundleExcessSlowFills = {
35
+ [destinationChainId: number]: {
36
+ [destinationToken: string]: (DepositWithBlock & { lpFeePct: BigNumber })[];
37
+ };
38
+ };
39
+ export type BundleSlowFills = {
40
+ [destinationChainId: number]: {
41
+ [destinationToken: string]: (DepositWithBlock & { lpFeePct: BigNumber })[];
42
+ };
43
+ };
44
+
45
+ export type LoadDataReturnValue = {
46
+ bundleDepositsV3: BundleDepositsV3;
47
+ expiredDepositsToRefundV3: ExpiredDepositsToRefundV3;
48
+ bundleFillsV3: BundleFillsV3;
49
+ unexecutableSlowFills: BundleExcessSlowFills;
50
+ bundleSlowFillsV3: BundleSlowFills;
51
+ };
52
+
53
+ export type BundleData = LoadDataReturnValue & {
54
+ bundleBlockRanges: number[][];
55
+ };
56
+
57
+ export interface Clients {
58
+ hubPoolClient: HubPoolClient;
59
+ configStoreClient: AcrossConfigStoreClient;
60
+ hubSigner?: Signer;
61
+ arweaveClient: ArweaveClient;
62
+ }
63
+
64
+ export type CombinedRefunds = {
65
+ [repaymentChainId: number]: {
66
+ [repaymentToken: string]: Refund;
67
+ };
68
+ };
@@ -6,3 +6,4 @@ export * from "./Bridge";
6
6
  export * from "./Error";
7
7
  export * from "./TypedData";
8
8
  export * from "./CachingMechanism";
9
+ export * from "./BundleData";
@@ -0,0 +1,28 @@
1
+ import { CHAIN_IDs, MAINNET_CHAIN_IDs as _MAINNET_CHAIN_IDs, PUBLIC_NETWORKS } from "../constants";
2
+ import { RPCTransport } from "./types";
3
+
4
+ const MAINNET_CHAIN_IDs = Object.values(_MAINNET_CHAIN_IDs);
5
+
6
+ // Chain-specific overrides for when the Alchemy endpoint does not match the canonical chain name.
7
+ const endpoints: { [chainId: string]: string } = {
8
+ [CHAIN_IDs.ARBITRUM]: "arb",
9
+ [CHAIN_IDs.ARBITRUM_SEPOLIA]: "arb-sepolia",
10
+ [CHAIN_IDs.MAINNET]: "eth",
11
+ [CHAIN_IDs.SEPOLIA]: "eth-sepolia",
12
+ [CHAIN_IDs.OPTIMISM]: "opt",
13
+ [CHAIN_IDs.OPTIMISM_SEPOLIA]: "opt-sepolia",
14
+ };
15
+
16
+ export function getURL(chainId: number, apiKey: string, transport: RPCTransport): string {
17
+ let host = endpoints[chainId] ?? PUBLIC_NETWORKS[chainId]?.name;
18
+ if (!host) {
19
+ throw new Error(`No known Alchemy provider for chainId ${chainId}`);
20
+ }
21
+
22
+ if (MAINNET_CHAIN_IDs.includes(chainId)) {
23
+ host = `${host}-mainnet`;
24
+ }
25
+ host = host.toLowerCase().replace(" ", "-");
26
+
27
+ return `${transport}://${host}.g.alchemy.com/v2/${apiKey}`;
28
+ }
@@ -2,4 +2,5 @@ export * from "./rateLimitedProvider";
2
2
  export * from "./cachedProvider";
3
3
  export * from "./retryProvider";
4
4
  export * from "./constants";
5
+ export * from "./types";
5
6
  export * from "./utils";
@@ -0,0 +1,23 @@
1
+ import { CHAIN_IDs, MAINNET_CHAIN_IDs as _MAINNET_CHAIN_IDs, PUBLIC_NETWORKS } from "../constants";
2
+ import { RPCTransport } from "./types";
3
+
4
+ const MAINNET_CHAIN_IDs = Object.values(_MAINNET_CHAIN_IDs);
5
+
6
+ // Chain-specific overrides for when the Infura endpoint does not match the canonical chain name.
7
+ const endpoints: { [chainId: string]: string } = {
8
+ [CHAIN_IDs.ARBITRUM]: "arbitrum",
9
+ };
10
+
11
+ export function getURL(chainId: number, apiKey: string, transport: RPCTransport): string {
12
+ let host = endpoints[chainId] ?? PUBLIC_NETWORKS[chainId]?.name;
13
+ if (!host) {
14
+ throw new Error(`No known Infura provider for chainId ${chainId}`);
15
+ }
16
+
17
+ if (chainId !== CHAIN_IDs.MAINNET && MAINNET_CHAIN_IDs.includes(chainId)) {
18
+ host = `${host}-mainnet`;
19
+ }
20
+ host = host.toLowerCase().replace(" ", "-");
21
+
22
+ return transport === "https" ? `https://${host}.infura.io/v3/${apiKey}` : `wss://${host}.infura.io/ws/v3/${apiKey}`;
23
+ }
@@ -0,0 +1,2 @@
1
+ export type RPCProvider = "INFURA" | "ALCHEMY";
2
+ export type RPCTransport = "https" | "wss";
@@ -1,8 +1,48 @@
1
1
  // The async/queue library has a task-based interface for building a concurrent queue.
2
-
2
+ import assert from "assert";
3
3
  import { providers } from "ethers";
4
- import { isDefined } from "../utils";
5
4
  import { isEqual } from "lodash";
5
+ import { isDefined } from "../utils";
6
+ import { RPCProvider, RPCTransport } from "./types";
7
+ import * as alchemy from "./alchemy";
8
+ import * as infura from "./infura";
9
+
10
+ /**
11
+ * Infura DIN is identified separately to allow it to be configured explicitly.
12
+ */
13
+ const PROVIDERS = {
14
+ ALCHEMY: alchemy.getURL,
15
+ INFURA: infura.getURL,
16
+ INFURA_DIN: infura.getURL,
17
+ };
18
+
19
+ /**
20
+ * Type predicate for RPCProvider type.
21
+ * @param provider Provider string (ALCHEMY, INFURA, ...).
22
+ * @returns True if the provider string is a supported provider.
23
+ */
24
+ export function isSupportedProvider(provider: string): provider is RPCProvider {
25
+ return ["ALCHEMY", "INFURA", "INFURA_DIN"].includes(provider);
26
+ }
27
+
28
+ /**
29
+ * Produce an RPC for a given RPC provider, chainId API key and transport.
30
+ * @param provider RPC provider identifier (ALCHEMY, INFURA, ...)
31
+ * @param chainId Chain ID to obtain a URL for.
32
+ * @param apiKey API key for provider.
33
+ * @param transport Optional transport specifier (HTTPS or WSS).
34
+ * @returns An RPC URL confirming to the specified inputs.
35
+ */
36
+ export function getURL(
37
+ provider: RPCProvider,
38
+ chainId: number,
39
+ apiKey: string,
40
+ transport: RPCTransport = "https"
41
+ ): string {
42
+ const getURL = PROVIDERS[provider];
43
+ assert(getURL, `Unsupported RPC provider (${provider})`);
44
+ return getURL(chainId, apiKey, transport);
45
+ }
6
46
 
7
47
  /**
8
48
  * Deletes keys from an object and returns new copy of object without ignored keys
@@ -1,4 +1,4 @@
1
- import { providers, utils } from "ethers";
1
+ import { BigNumber, providers, utils } from "ethers";
2
2
 
3
3
  /**
4
4
  * Checks if a contract is deployed at the given address
@@ -17,6 +17,20 @@ export async function isContractDeployedToAddress(address: string, provider: pro
17
17
  return code !== "0x";
18
18
  }
19
19
 
20
+ export function compareAddresses(addressA: string, addressB: string): 1 | -1 | 0 {
21
+ // Convert address strings to BigNumbers and then sort numerical value of the BigNumber, which sorts the addresses
22
+ // effectively by their hex value.
23
+ const bnAddressA = BigNumber.from(addressA);
24
+ const bnAddressB = BigNumber.from(addressB);
25
+ if (bnAddressA.gt(bnAddressB)) {
26
+ return 1;
27
+ } else if (bnAddressA.lt(bnAddressB)) {
28
+ return -1;
29
+ } else {
30
+ return 0;
31
+ }
32
+ }
33
+
20
34
  export function compareAddressesSimple(addressA?: string, addressB?: string): boolean {
21
35
  if (addressA === undefined || addressB === undefined) {
22
36
  return false;
@@ -0,0 +1,8 @@
1
+ import * as typechain from "@across-protocol/contracts/dist/typechain"; // Import the typechain module
2
+
3
+ export function getParamType(contractName: string, functionName: string, paramName: string): string {
4
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
+ const artifact = (typechain as any)[`${[contractName]}__factory`];
6
+ const fragment = artifact.abi.find((fragment: { name: string }) => fragment.name === functionName);
7
+ return fragment?.inputs.find((input: { name: string }) => input.name === paramName) || "";
8
+ }
@@ -76,3 +76,26 @@ export function groupObjectCountsByProp(objects: any[], getProp: (obj: any) => s
76
76
  export function filterFalsyKeys(obj: Record<string | number, unknown>): Record<string | number, unknown> {
77
77
  return Object.fromEntries(Object.entries(obj).filter(([, v]) => v));
78
78
  }
79
+
80
+ export function count2DDictionaryValues(dictionary: { [key: string]: { [key2: string]: any[] } }): {
81
+ [key: string]: { [key2: string]: number };
82
+ } {
83
+ return Object.entries(dictionary).reduce((output, [key, innerDict]) => {
84
+ const innerDictOutput = Object.entries(innerDict).reduce((innerOutput, [key2, vals]) => {
85
+ return { ...innerOutput, [key2]: vals.length };
86
+ }, {});
87
+ return { ...output, [key]: innerDictOutput };
88
+ }, {});
89
+ }
90
+
91
+ export function count3DDictionaryValues(
92
+ dictionary: { [key: string]: { [key2: string]: any } },
93
+ innerPropName: string
94
+ ): { [key: string]: { [key2: string]: number } } {
95
+ return Object.entries(dictionary).reduce((output, [key, innerDict]) => {
96
+ const innerDictOutput = Object.entries(innerDict).reduce((innerOutput, [key2, vals]) => {
97
+ return { ...innerOutput, [key2]: vals[innerPropName].length };
98
+ }, {});
99
+ return { ...output, [key]: innerDictOutput };
100
+ }, {});
101
+ }