@across-protocol/sdk 4.3.139 → 4.3.140-alpha.0

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 (163) hide show
  1. package/dist/cjs/src/arch/evm/SpokeUtils.d.ts +3 -3
  2. package/dist/cjs/src/arch/evm/SpokeUtils.js +1 -1
  3. package/dist/cjs/src/arch/evm/SpokeUtils.js.map +1 -1
  4. package/dist/cjs/src/arch/evm/UpgradeUtils.d.ts +2 -0
  5. package/dist/cjs/src/arch/evm/UpgradeUtils.js +11 -0
  6. package/dist/cjs/src/arch/evm/UpgradeUtils.js.map +1 -0
  7. package/dist/cjs/src/arch/evm/index.d.ts +1 -0
  8. package/dist/cjs/src/arch/evm/index.js +1 -0
  9. package/dist/cjs/src/arch/evm/index.js.map +1 -1
  10. package/dist/cjs/src/arch/index.d.ts +1 -0
  11. package/dist/cjs/src/arch/index.js +2 -1
  12. package/dist/cjs/src/arch/index.js.map +1 -1
  13. package/dist/cjs/src/arch/tvm/SpokeUtils.d.ts +12 -0
  14. package/dist/cjs/src/arch/tvm/SpokeUtils.js +101 -0
  15. package/dist/cjs/src/arch/tvm/SpokeUtils.js.map +1 -0
  16. package/dist/cjs/src/arch/tvm/TransactionUtils.d.ts +7 -0
  17. package/dist/cjs/src/arch/tvm/TransactionUtils.js +28 -0
  18. package/dist/cjs/src/arch/tvm/TransactionUtils.js.map +1 -0
  19. package/dist/cjs/src/arch/tvm/index.d.ts +2 -0
  20. package/dist/cjs/src/arch/tvm/index.js +6 -0
  21. package/dist/cjs/src/arch/tvm/index.js.map +1 -0
  22. package/dist/cjs/src/clients/BundleDataClient/BundleDataClient.js +3 -1
  23. package/dist/cjs/src/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  24. package/dist/cjs/src/clients/SpokePoolClient/EVMSpokePoolClient.d.ts +10 -2
  25. package/dist/cjs/src/clients/SpokePoolClient/EVMSpokePoolClient.js +40 -14
  26. package/dist/cjs/src/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
  27. package/dist/cjs/src/gasPriceOracle/oracle.js +1 -0
  28. package/dist/cjs/src/gasPriceOracle/oracle.js.map +1 -1
  29. package/dist/cjs/src/relayFeeCalculator/chain-queries/baseQuery.d.ts +3 -3
  30. package/dist/cjs/src/relayFeeCalculator/chain-queries/baseQuery.js +6 -6
  31. package/dist/cjs/src/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  32. package/dist/cjs/src/utils/AddressUtils.d.ts +11 -0
  33. package/dist/cjs/src/utils/AddressUtils.js +47 -2
  34. package/dist/cjs/src/utils/AddressUtils.js.map +1 -1
  35. package/dist/cjs/src/utils/Multicall.js +1 -0
  36. package/dist/cjs/src/utils/Multicall.js.map +1 -1
  37. package/dist/cjs/src/utils/NetworkUtils.d.ts +1 -0
  38. package/dist/cjs/src/utils/NetworkUtils.js +8 -3
  39. package/dist/cjs/src/utils/NetworkUtils.js.map +1 -1
  40. package/dist/cjs/src/utils/TypeGuards.d.ts +3 -1
  41. package/dist/cjs/src/utils/TypeGuards.js +4 -0
  42. package/dist/cjs/src/utils/TypeGuards.js.map +1 -1
  43. package/dist/cjs/src/utils/abi/typechain/SP1AutoVerifier.d.ts +42 -0
  44. package/dist/cjs/src/utils/abi/typechain/SP1AutoVerifier.js +3 -0
  45. package/dist/cjs/src/utils/abi/typechain/SP1AutoVerifier.js.map +1 -0
  46. package/dist/cjs/src/utils/abi/typechain/factories/SP1AutoVerifier__factory.d.ts +26 -0
  47. package/dist/cjs/src/utils/abi/typechain/factories/SP1AutoVerifier__factory.js +40 -0
  48. package/dist/cjs/src/utils/abi/typechain/factories/SP1AutoVerifier__factory.js.map +1 -0
  49. package/dist/cjs/src/utils/abi/typechain/factories/index.d.ts +1 -0
  50. package/dist/cjs/src/utils/abi/typechain/factories/index.js +4 -2
  51. package/dist/cjs/src/utils/abi/typechain/factories/index.js.map +1 -1
  52. package/dist/cjs/src/utils/abi/typechain/index.d.ts +2 -0
  53. package/dist/cjs/src/utils/abi/typechain/index.js +4 -2
  54. package/dist/cjs/src/utils/abi/typechain/index.js.map +1 -1
  55. package/dist/esm/src/arch/evm/SpokeUtils.d.ts +3 -3
  56. package/dist/esm/src/arch/evm/SpokeUtils.js +1 -1
  57. package/dist/esm/src/arch/evm/SpokeUtils.js.map +1 -1
  58. package/dist/esm/src/arch/evm/UpgradeUtils.d.ts +9 -0
  59. package/dist/esm/src/arch/evm/UpgradeUtils.js +15 -0
  60. package/dist/esm/src/arch/evm/UpgradeUtils.js.map +1 -0
  61. package/dist/esm/src/arch/evm/index.d.ts +1 -0
  62. package/dist/esm/src/arch/evm/index.js +1 -0
  63. package/dist/esm/src/arch/evm/index.js.map +1 -1
  64. package/dist/esm/src/arch/index.d.ts +1 -0
  65. package/dist/esm/src/arch/index.js +2 -0
  66. package/dist/esm/src/arch/index.js.map +1 -1
  67. package/dist/esm/src/arch/tvm/SpokeUtils.d.ts +48 -0
  68. package/dist/esm/src/arch/tvm/SpokeUtils.js +138 -0
  69. package/dist/esm/src/arch/tvm/SpokeUtils.js.map +1 -0
  70. package/dist/esm/src/arch/tvm/TransactionUtils.d.ts +20 -0
  71. package/dist/esm/src/arch/tvm/TransactionUtils.js +42 -0
  72. package/dist/esm/src/arch/tvm/TransactionUtils.js.map +1 -0
  73. package/dist/esm/src/arch/tvm/index.d.ts +2 -0
  74. package/dist/esm/src/arch/tvm/index.js +3 -0
  75. package/dist/esm/src/arch/tvm/index.js.map +1 -0
  76. package/dist/esm/src/clients/BundleDataClient/BundleDataClient.js +4 -2
  77. package/dist/esm/src/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  78. package/dist/esm/src/clients/SpokePoolClient/EVMSpokePoolClient.d.ts +21 -2
  79. package/dist/esm/src/clients/SpokePoolClient/EVMSpokePoolClient.js +52 -15
  80. package/dist/esm/src/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
  81. package/dist/esm/src/gasPriceOracle/oracle.js +1 -0
  82. package/dist/esm/src/gasPriceOracle/oracle.js.map +1 -1
  83. package/dist/esm/src/relayFeeCalculator/chain-queries/baseQuery.d.ts +3 -3
  84. package/dist/esm/src/relayFeeCalculator/chain-queries/baseQuery.js +6 -6
  85. package/dist/esm/src/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  86. package/dist/esm/src/utils/AddressUtils.d.ts +11 -0
  87. package/dist/esm/src/utils/AddressUtils.js +53 -2
  88. package/dist/esm/src/utils/AddressUtils.js.map +1 -1
  89. package/dist/esm/src/utils/Multicall.js +1 -0
  90. package/dist/esm/src/utils/Multicall.js.map +1 -1
  91. package/dist/esm/src/utils/NetworkUtils.d.ts +6 -0
  92. package/dist/esm/src/utils/NetworkUtils.js +12 -3
  93. package/dist/esm/src/utils/NetworkUtils.js.map +1 -1
  94. package/dist/esm/src/utils/TypeGuards.d.ts +3 -1
  95. package/dist/esm/src/utils/TypeGuards.js +3 -0
  96. package/dist/esm/src/utils/TypeGuards.js.map +1 -1
  97. package/dist/esm/src/utils/abi/typechain/SP1AutoVerifier.d.ts +42 -0
  98. package/dist/esm/src/utils/abi/typechain/SP1AutoVerifier.js +2 -0
  99. package/dist/esm/src/utils/abi/typechain/SP1AutoVerifier.js.map +1 -0
  100. package/dist/esm/src/utils/abi/typechain/factories/SP1AutoVerifier__factory.d.ts +26 -0
  101. package/dist/esm/src/utils/abi/typechain/factories/SP1AutoVerifier__factory.js +39 -0
  102. package/dist/esm/src/utils/abi/typechain/factories/SP1AutoVerifier__factory.js.map +1 -0
  103. package/dist/esm/src/utils/abi/typechain/factories/index.d.ts +1 -0
  104. package/dist/esm/src/utils/abi/typechain/factories/index.js +1 -0
  105. package/dist/esm/src/utils/abi/typechain/factories/index.js.map +1 -1
  106. package/dist/esm/src/utils/abi/typechain/index.d.ts +2 -0
  107. package/dist/esm/src/utils/abi/typechain/index.js +1 -0
  108. package/dist/esm/src/utils/abi/typechain/index.js.map +1 -1
  109. package/dist/types/src/arch/evm/SpokeUtils.d.ts +3 -3
  110. package/dist/types/src/arch/evm/SpokeUtils.d.ts.map +1 -1
  111. package/dist/types/src/arch/evm/UpgradeUtils.d.ts +10 -0
  112. package/dist/types/src/arch/evm/UpgradeUtils.d.ts.map +1 -0
  113. package/dist/types/src/arch/evm/index.d.ts +1 -0
  114. package/dist/types/src/arch/evm/index.d.ts.map +1 -1
  115. package/dist/types/src/arch/index.d.ts +1 -0
  116. package/dist/types/src/arch/index.d.ts.map +1 -1
  117. package/dist/types/src/arch/tvm/SpokeUtils.d.ts +49 -0
  118. package/dist/types/src/arch/tvm/SpokeUtils.d.ts.map +1 -0
  119. package/dist/types/src/arch/tvm/TransactionUtils.d.ts +21 -0
  120. package/dist/types/src/arch/tvm/TransactionUtils.d.ts.map +1 -0
  121. package/dist/types/src/arch/tvm/index.d.ts +3 -0
  122. package/dist/types/src/arch/tvm/index.d.ts.map +1 -0
  123. package/dist/types/src/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -1
  124. package/dist/types/src/clients/SpokePoolClient/EVMSpokePoolClient.d.ts +21 -2
  125. package/dist/types/src/clients/SpokePoolClient/EVMSpokePoolClient.d.ts.map +1 -1
  126. package/dist/types/src/relayFeeCalculator/chain-queries/baseQuery.d.ts +3 -3
  127. package/dist/types/src/relayFeeCalculator/chain-queries/baseQuery.d.ts.map +1 -1
  128. package/dist/types/src/utils/AddressUtils.d.ts +11 -0
  129. package/dist/types/src/utils/AddressUtils.d.ts.map +1 -1
  130. package/dist/types/src/utils/Multicall.d.ts.map +1 -1
  131. package/dist/types/src/utils/NetworkUtils.d.ts +6 -0
  132. package/dist/types/src/utils/NetworkUtils.d.ts.map +1 -1
  133. package/dist/types/src/utils/TypeGuards.d.ts +3 -1
  134. package/dist/types/src/utils/TypeGuards.d.ts.map +1 -1
  135. package/dist/types/src/utils/abi/typechain/SP1AutoVerifier.d.ts +43 -0
  136. package/dist/types/src/utils/abi/typechain/SP1AutoVerifier.d.ts.map +1 -0
  137. package/dist/types/src/utils/abi/typechain/factories/SP1AutoVerifier__factory.d.ts +27 -0
  138. package/dist/types/src/utils/abi/typechain/factories/SP1AutoVerifier__factory.d.ts.map +1 -0
  139. package/dist/types/src/utils/abi/typechain/factories/index.d.ts +1 -0
  140. package/dist/types/src/utils/abi/typechain/factories/index.d.ts.map +1 -1
  141. package/dist/types/src/utils/abi/typechain/index.d.ts +2 -0
  142. package/dist/types/src/utils/abi/typechain/index.d.ts.map +1 -1
  143. package/package.json +3 -2
  144. package/src/arch/evm/SpokeUtils.ts +3 -4
  145. package/src/arch/evm/UpgradeUtils.ts +18 -0
  146. package/src/arch/evm/index.ts +1 -0
  147. package/src/arch/index.ts +1 -0
  148. package/src/arch/tvm/SpokeUtils.ts +225 -0
  149. package/src/arch/tvm/TransactionUtils.ts +64 -0
  150. package/src/arch/tvm/index.ts +2 -0
  151. package/src/clients/BundleDataClient/BundleDataClient.ts +4 -1
  152. package/src/clients/SpokePoolClient/EVMSpokePoolClient.ts +69 -21
  153. package/src/gasPriceOracle/oracle.ts +1 -0
  154. package/src/relayFeeCalculator/chain-queries/baseQuery.ts +24 -8
  155. package/src/utils/AddressUtils.ts +62 -2
  156. package/src/utils/Multicall.ts +1 -0
  157. package/src/utils/NetworkUtils.ts +13 -3
  158. package/src/utils/TypeGuards.ts +6 -1
  159. package/src/utils/abi/contracts/SP1AutoVerifier.json +25 -0
  160. package/src/utils/abi/typechain/SP1AutoVerifier.ts +112 -0
  161. package/src/utils/abi/typechain/factories/SP1AutoVerifier__factory.ts +49 -0
  162. package/src/utils/abi/typechain/factories/index.ts +1 -0
  163. package/src/utils/abi/typechain/index.ts +2 -0
@@ -7,6 +7,12 @@ import {
7
7
  relayFillStatus,
8
8
  getTimestampForBlock as _getTimestampForBlock,
9
9
  } from "../../arch/evm";
10
+ import {
11
+ relayFillStatus as relayFillStatusTvm,
12
+ getMaxFillDeadlineInRange as getMaxFillDeadlineTvm,
13
+ getTimeAt as _getTimeAtTvm,
14
+ findDepositBlock as findDepositBlockTvm,
15
+ } from "../../arch/tvm";
10
16
  import { DepositWithBlock, FillStatus, Log, RelayData } from "../../interfaces";
11
17
  import {
12
18
  BigNumber,
@@ -17,6 +23,7 @@ import {
17
23
  toBN,
18
24
  EvmAddress,
19
25
  unpackDepositEvent,
26
+ chainIsTvm,
20
27
  } from "../../utils";
21
28
  import {
22
29
  EventSearchConfig,
@@ -36,6 +43,8 @@ import { EVM_SPOKE_POOL_CLIENT_TYPE } from "./types";
36
43
  */
37
44
  export class EVMSpokePoolClient extends SpokePoolClient {
38
45
  readonly type = EVM_SPOKE_POOL_CLIENT_TYPE;
46
+ readonly tvm: boolean;
47
+
39
48
  constructor(
40
49
  logger: winston.Logger,
41
50
  public readonly spokePool: Contract,
@@ -46,10 +55,12 @@ export class EVMSpokePoolClient extends SpokePoolClient {
46
55
  ) {
47
56
  super(logger, hubPoolClient, chainId, deploymentBlock, eventSearchConfig);
48
57
  this.spokePoolAddress = EvmAddress.from(spokePool.address);
58
+ this.tvm = chainIsTvm(this.chainId);
49
59
  }
50
60
 
51
61
  public override relayFillStatus(relayData: RelayData, atHeight?: number): Promise<FillStatus> {
52
- return relayFillStatus(this.spokePool, relayData, atHeight, this.chainId);
62
+ const fillStatusHandler = this.tvm ? relayFillStatusTvm : relayFillStatus;
63
+ return fillStatusHandler(this.spokePool, relayData, atHeight, this.chainId);
53
64
  }
54
65
 
55
66
  public override fillStatusArray(relayData: RelayData[], atHeight?: number): Promise<(FillStatus | undefined)[]> {
@@ -57,7 +68,8 @@ export class EVMSpokePoolClient extends SpokePoolClient {
57
68
  }
58
69
 
59
70
  public override getMaxFillDeadlineInRange(startBlock: number, endBlock: number): Promise<number> {
60
- return getMaxFillDeadline(this.spokePool, startBlock, endBlock);
71
+ const maxFillDeadlineInRangeHandler = this.tvm ? getMaxFillDeadlineTvm : getMaxFillDeadline;
72
+ return maxFillDeadlineInRangeHandler(this.spokePool, startBlock, endBlock);
61
73
  }
62
74
 
63
75
  private _availableEventsOnSpoke(eventNames: string[] = knownEventNames): { [eventName: string]: EventFilter } {
@@ -72,6 +84,42 @@ export class EVMSpokePoolClient extends SpokePoolClient {
72
84
  return Object.keys(this._availableEventsOnSpoke(knownEventNames));
73
85
  }
74
86
 
87
+ /**
88
+ * Retrieve the on-chain time at a specific block.
89
+ * EVM reads SpokePool.getCurrentTime() via multicall with a historical blockTag.
90
+ * @param blockNumber The block number to query.
91
+ * @returns The on-chain time as a number.
92
+ */
93
+ protected async _getCurrentTime(blockNumber: number): Promise<number> {
94
+ if (this.tvm) {
95
+ const block = await this.spokePool.provider.getBlock(blockNumber);
96
+ const currentTime = block.timestamp;
97
+ if (currentTime < this.currentTime) {
98
+ throw new Error(`EVMSpokePoolClient::_getCurrentTimeTvm: currentTime: ${currentTime} < ${this.currentTime}`);
99
+ }
100
+ return currentTime;
101
+ }
102
+ const { spokePool } = this;
103
+ const multicallFunctions = ["getCurrentTime"];
104
+ const multicallOutput = await spokePool.callStatic.multicall(
105
+ multicallFunctions.map((f) => spokePool.interface.encodeFunctionData(f)),
106
+ { blockTag: blockNumber }
107
+ );
108
+
109
+ const [currentTime] = multicallFunctions.map(
110
+ (fn, idx) => spokePool.interface.decodeFunctionResult(fn, multicallOutput[idx])[0]
111
+ );
112
+
113
+ if (!BigNumber.isBigNumber(currentTime) || currentTime.lt(this.currentTime)) {
114
+ const errMsg = BigNumber.isBigNumber(currentTime)
115
+ ? `currentTime: ${currentTime} < ${toBN(this.currentTime)}`
116
+ : `currentTime is not a BigNumber: ${JSON.stringify(currentTime)}`;
117
+ throw new Error(`EVMSpokePoolClient::update: ${errMsg}`);
118
+ }
119
+
120
+ return currentTime.toNumber();
121
+ }
122
+
75
123
  protected override async _update(eventsToQuery: string[]): Promise<SpokePoolUpdate> {
76
124
  const searchConfig = await this.updateSearchConfig(this.spokePool.provider);
77
125
  if (isUpdateFailureReason(searchConfig)) {
@@ -107,25 +155,14 @@ export class EVMSpokePoolClient extends SpokePoolClient {
107
155
  });
108
156
 
109
157
  const timerStart = Date.now();
110
- const multicallFunctions = ["getCurrentTime"];
111
- const [multicallOutput, ...events] = await Promise.all([
112
- spokePool.callStatic.multicall(
113
- multicallFunctions.map((f) => spokePool.interface.encodeFunctionData(f)),
114
- { blockTag: searchConfig.to }
115
- ),
158
+ const [currentTime, ...events] = await Promise.all([
159
+ this._getCurrentTime(searchConfig.to),
116
160
  ...eventSearchConfigs.map((config) => paginatedEventQuery(this.spokePool, config.filter, config.searchConfig)),
117
161
  ]);
118
162
  this.log("debug", `Time to query new events from RPC for ${this.chainId}: ${Date.now() - timerStart} ms`);
119
163
 
120
- const [currentTime] = multicallFunctions.map(
121
- (fn, idx) => spokePool.interface.decodeFunctionResult(fn, multicallOutput[idx])[0]
122
- );
123
-
124
- if (!BigNumber.isBigNumber(currentTime) || currentTime.lt(this.currentTime)) {
125
- const errMsg = BigNumber.isBigNumber(currentTime)
126
- ? `currentTime: ${currentTime} < ${toBN(this.currentTime)}`
127
- : `currentTime is not a BigNumber: ${JSON.stringify(currentTime)}`;
128
- throw new Error(`EVMSpokePoolClient::update: ${errMsg}`);
164
+ if (currentTime < this.currentTime) {
165
+ throw new Error(`EVMSpokePoolClient::update: currentTime: ${currentTime} < ${this.currentTime}`);
129
166
  }
130
167
 
131
168
  // Sort all events to ensure they are stored in a consistent order.
@@ -138,14 +175,15 @@ export class EVMSpokePoolClient extends SpokePoolClient {
138
175
 
139
176
  return {
140
177
  success: true,
141
- currentTime: currentTime.toNumber(), // uint32
178
+ currentTime,
142
179
  searchEndBlock: searchConfig.to,
143
180
  events: eventsWithBlockNumber,
144
181
  };
145
182
  }
146
183
 
147
184
  public override getTimeAt(blockNumber: number): Promise<number> {
148
- return _getTimeAt(this.spokePool, blockNumber);
185
+ const getTimeAtHandler = this.tvm ? _getTimeAtTvm : _getTimeAt;
186
+ return getTimeAtHandler(this.spokePool, blockNumber);
149
187
  }
150
188
 
151
189
  public override async findDeposit(depositId: BigNumber): Promise<DepositSearchResult> {
@@ -190,12 +228,22 @@ export class EVMSpokePoolClient extends SpokePoolClient {
190
228
  return _getTimestampForBlock(this.spokePool.provider, blockNumber);
191
229
  }
192
230
 
193
- private async queryDepositEvents(
231
+ /**
232
+ * Find the block at which a deposit was created.
233
+ * EVM uses a binary-search over historical numberOfDeposits().
234
+ * TVM overrides this with an event-based lookup.
235
+ */
236
+ protected _findDepositBlock(depositId: BigNumber, lowBlock: number, highBlock?: number): Promise<number | undefined> {
237
+ const findDepositBlockHandler = this.tvm ? findDepositBlockTvm : findDepositBlock;
238
+ return findDepositBlockHandler(this.spokePool, depositId, lowBlock, highBlock);
239
+ }
240
+
241
+ protected async queryDepositEvents(
194
242
  depositId: BigNumber
195
243
  ): Promise<{ event: Log; elapsedMs: number } | { reason: string }> {
196
244
  const tStart = Date.now();
197
245
  const upperBound = this.latestHeightSearched || undefined;
198
- const from = await findDepositBlock(this.spokePool, depositId, this.deploymentBlock, upperBound);
246
+ const from = await this._findDepositBlock(depositId, this.deploymentBlock, upperBound);
199
247
  const chain = getNetworkName(this.chainId);
200
248
 
201
249
  if (!from) {
@@ -113,6 +113,7 @@ function getGasPriceEthers(provider: providers.Provider, opts: GasPriceEstimateO
113
113
  [CHAIN_IDs.POLYGON]: polygon.gasStation,
114
114
  [CHAIN_IDs.SCROLL]: ethereum.legacy,
115
115
  [CHAIN_IDs.TEMPO]: ethereum.eip1559,
116
+ [CHAIN_IDs.TRON]: ethereum.legacy,
116
117
  [CHAIN_IDs.ZK_SYNC]: ethereum.legacy,
117
118
  // Testnet
118
119
  [CHAIN_IDs.POLYGON_AMOY]: polygon.gasStation,
@@ -9,6 +9,7 @@ import { populateV3Relay } from "../../arch/evm";
9
9
  import {
10
10
  BigNumberish,
11
11
  EvmAddress,
12
+ TvmAddress,
12
13
  TransactionCostEstimate,
13
14
  BigNumber,
14
15
  toBNWei,
@@ -85,9 +86,15 @@ export class QueryBase implements QueryInterface {
85
86
  const { gasPrice = this.fixedGasPrice, gasUnits, opStackL1GasCostMultiplier } = options;
86
87
 
87
88
  const { recipient, outputToken, exclusiveRelayer } = relayData;
88
- assert(recipient.isEVM(), `getGasCosts: recipient not an EVM address (${recipient})`);
89
- assert(outputToken.isEVM(), `getGasCosts: outputToken not an EVM address (${outputToken})`);
90
- assert(exclusiveRelayer.isEVM(), `getGasCosts: exclusiveRelayer not an EVM address (${exclusiveRelayer})`);
89
+ assert(recipient.isEVM() || recipient.isTVM(), `getGasCosts: recipient not an EVM-like address (${recipient})`);
90
+ assert(
91
+ outputToken.isEVM() || outputToken.isTVM(),
92
+ `getGasCosts: outputToken not an EVM-like address (${outputToken})`
93
+ );
94
+ assert(
95
+ exclusiveRelayer.isEVM() || exclusiveRelayer.isTVM(),
96
+ `getGasCosts: exclusiveRelayer not an EVM-like address (${exclusiveRelayer})`
97
+ );
91
98
 
92
99
  const tx = await this.getUnsignedTxFromDeposit({ ...relayData, recipient, outputToken, exclusiveRelayer }, relayer);
93
100
  const {
@@ -119,8 +126,8 @@ export class QueryBase implements QueryInterface {
119
126
  getUnsignedTxFromDeposit(
120
127
  relayData: Omit<RelayData, "recipient" | "outputToken"> & {
121
128
  destinationChainId: number;
122
- recipient: EvmAddress;
123
- outputToken: EvmAddress;
129
+ recipient: EvmAddress | TvmAddress;
130
+ outputToken: EvmAddress | TvmAddress;
124
131
  },
125
132
  relayer = getDefaultRelayer(relayData.destinationChainId)
126
133
  ): Promise<PopulatedTransaction> {
@@ -138,9 +145,18 @@ export class QueryBase implements QueryInterface {
138
145
  relayer = getDefaultRelayer(relayData.destinationChainId)
139
146
  ): Promise<BigNumber> {
140
147
  const { recipient, outputToken, exclusiveRelayer } = relayData;
141
- assert(recipient.isEVM(), `getNativeGasCost: recipient not an EVM address (${recipient})`);
142
- assert(outputToken.isEVM(), `getNativeGasCost: outputToken not an EVM address (${outputToken})`);
143
- assert(exclusiveRelayer.isEVM(), `getNativeGasCost: exclusiveRelayer not an EVM address (${exclusiveRelayer})`);
148
+ assert(
149
+ recipient.isEVM() || recipient.isTVM(),
150
+ `getNativeGasCost: recipient not an EVM-like address (${recipient})`
151
+ );
152
+ assert(
153
+ outputToken.isEVM() || outputToken.isTVM(),
154
+ `getNativeGasCost: outputToken not an EVM-like address (${outputToken})`
155
+ );
156
+ assert(
157
+ exclusiveRelayer.isEVM() || exclusiveRelayer.isTVM(),
158
+ `getNativeGasCost: exclusiveRelayer not an EVM-like address (${exclusiveRelayer})`
159
+ );
144
160
 
145
161
  const unsignedTx = await this.getUnsignedTxFromDeposit(
146
162
  { ...relayData, recipient, outputToken, exclusiveRelayer },
@@ -1,7 +1,8 @@
1
1
  import { isAddress } from "viem";
2
2
  import { providers, utils } from "ethers";
3
3
  import bs58 from "bs58";
4
- import { BigNumber, chainIsEvm, chainIsSvm } from "./";
4
+ import { TronWeb } from "tronweb";
5
+ import { BigNumber, chainIsEvm, chainIsSvm, chainIsTvm } from "./";
5
6
 
6
7
  /**
7
8
  * Verify whether an address' bytecode resembles an EIP-7702 delegation.
@@ -105,7 +106,8 @@ export function isValidEvmAddress(address: string): boolean {
105
106
  export function toAddressType(address: string, chainId: number): Address {
106
107
  const rawAddress = address.startsWith("0x") ? utils.arrayify(address) : bs58.decode(address);
107
108
 
108
- if (chainIsEvm(chainId) && EvmAddress.validate(rawAddress)) return new EvmAddress(rawAddress);
109
+ if (chainIsTvm(chainId)) return TvmAddress.from(address);
110
+ else if (chainIsEvm(chainId) && EvmAddress.validate(rawAddress)) return new EvmAddress(rawAddress);
109
111
  else if (chainIsSvm(chainId) && SvmAddress.validate(rawAddress)) return new SvmAddress(rawAddress);
110
112
 
111
113
  return new RawAddress(rawAddress);
@@ -187,6 +189,7 @@ export abstract class Address {
187
189
  isValidOn(chainId: number): boolean {
188
190
  if (chainIsEvm(chainId)) return EvmAddress.validate(this.rawAddress);
189
191
  if (chainIsSvm(chainId)) return SvmAddress.validate(this.rawAddress);
192
+ if (chainIsTvm(chainId)) return TvmAddress.validate(this.rawAddress);
190
193
  return false;
191
194
  }
192
195
 
@@ -227,6 +230,10 @@ export abstract class Address {
227
230
  isSVM(): this is SvmAddress {
228
231
  return false;
229
232
  }
233
+
234
+ isTVM(): this is TvmAddress {
235
+ return false;
236
+ }
230
237
  }
231
238
 
232
239
  // Subclass of address which strictly deals with 20-byte addresses. These addresses are guaranteed to be valid EVM addresses, so `toAddress` will always succeed.
@@ -304,6 +311,59 @@ export class SvmAddress extends Address {
304
311
  }
305
312
  }
306
313
 
314
+ // Subclass of address which handles TRON (TVM) addresses. Internally stores a 20-byte address (same as EVM),
315
+ // but toNative() returns the TRON Base58Check-encoded address (T...).
316
+ export class TvmAddress extends Address {
317
+ private readonly _type = "tvm";
318
+ private nativeAddress: string | undefined = undefined;
319
+
320
+ constructor(rawAddress: Uint8Array) {
321
+ if (!TvmAddress.validate(rawAddress)) {
322
+ throw new Error(`${utils.hexlify(rawAddress)} is not a valid TVM address`);
323
+ }
324
+
325
+ super(rawAddress);
326
+ this._type; // tsc noUnusedLocals appeasement.
327
+ }
328
+
329
+ static validate(rawAddress: Uint8Array): boolean {
330
+ return (
331
+ rawAddress.length == 20 || (rawAddress.length === 32 && rawAddress.slice(0, 12).every((field) => field === 0))
332
+ );
333
+ }
334
+
335
+ override isTVM(): this is TvmAddress {
336
+ return true;
337
+ }
338
+
339
+ // Returns the TRON Base58Check-encoded address (T...).
340
+ override toNative(): string {
341
+ const computeNative = () => {
342
+ const hexString = utils.hexlify(this.rawAddress);
343
+ // Strip leading zeros to get the 20-byte portion, then convert to TRON format.
344
+ const evmHex = utils.hexZeroPad(utils.hexStripZeros(hexString), 20);
345
+ return TronWeb.address.fromHex(evmHex);
346
+ };
347
+ return (this.nativeAddress ??= computeNative());
348
+ }
349
+
350
+ override toHexString(): string {
351
+ return this.toEvmAddress();
352
+ }
353
+
354
+ // Constructs a new TvmAddress from a string. Accepts both 0x-prefixed hex and TRON Base58Check addresses.
355
+ static from(address: string): TvmAddress {
356
+ if (address.startsWith("0x")) {
357
+ return new this(utils.arrayify(address));
358
+ }
359
+ // For base58 Tron addresses, convert via TronWeb to get the hex representation.
360
+ const hex = TronWeb.address.toHex(address);
361
+ // TronWeb returns hex with a 0x41 prefix (TRON's address byte). Strip 0x41 to get 20 bytes.
362
+ const rawHex = "0x" + hex.slice(2);
363
+ return new this(utils.arrayify(rawHex));
364
+ }
365
+ }
366
+
307
367
  export class RawAddress extends Address {
308
368
  private readonly _type = "raw";
309
369
 
@@ -21,6 +21,7 @@ const MULTICALL_DEPLOYER = "0x05f32B3cC3888453ff71B01135B34FF8e41263F2";
21
21
 
22
22
  const NON_DETERMINISTIC_MULTICALL_ADDRESSES = {
23
23
  [CHAIN_IDs.LENS]: "0x6b6dEa4D80e3077D076733A04c48F63c3BA49320",
24
+ [CHAIN_IDs.TRON]: "0x32a4f47a74a6810bd0bf861cabab99656a75de9e", // @todo: Base58?
24
25
  [CHAIN_IDs.ZK_SYNC]: "0xF9cda624FBC7e059355ce98a31693d299FACd963",
25
26
  [CHAIN_IDs.LENS_SEPOLIA]: "0x8A44EDE8a6843a997bC0Cc4659e4dB1Da8f91116",
26
27
  };
@@ -134,6 +134,15 @@ export function chainIsSvm(chainId: number): boolean {
134
134
  return PUBLIC_NETWORKS[chainId]?.family === ChainFamily.SVM;
135
135
  }
136
136
 
137
+ /**
138
+ * Determines whether a chain ID runs on a TVM-like execution layer (e.g. TRON).
139
+ * @param chainId Chain ID to evaluate.
140
+ * @returns True if chain corresponding to chainId has a TVM-like execution layer.
141
+ */
142
+ export function chainIsTvm(chainId: number): boolean {
143
+ return PUBLIC_NETWORKS[chainId]?.family === ChainFamily.TVM;
144
+ }
145
+
137
146
  /**
138
147
  * Determines whether a chain ID has a native gas token.
139
148
  * @param chainId Chain ID to evaluate.
@@ -166,13 +175,14 @@ export function chainIsOFTEnabled(chainId: number): boolean {
166
175
  // This is backwards vs. CCTP logic because Across support for OFTs is limited vs. OFT deployments.
167
176
  const oftEnabled = [
168
177
  CHAIN_IDs.ARBITRUM,
169
- CHAIN_IDs.POLYGON,
170
178
  CHAIN_IDs.HYPEREVM,
179
+ CHAIN_IDs.INK,
180
+ CHAIN_IDs.MEGAETH,
171
181
  CHAIN_IDs.MONAD,
172
182
  CHAIN_IDs.PLASMA,
173
- CHAIN_IDs.MEGAETH,
183
+ CHAIN_IDs.POLYGON,
184
+ CHAIN_IDs.TRON, // tbd!!!
174
185
  CHAIN_IDs.UNICHAIN,
175
- CHAIN_IDs.INK,
176
186
  ];
177
187
  return oftEnabled.includes(chainId) && PRODUCTION_NETWORKS[chainId]?.oftEid !== OFT_NO_EID;
178
188
  }
@@ -1,6 +1,7 @@
1
1
  import { SVMProvider } from "../arch/svm/types";
2
2
  import { EvmProvider } from "../arch/evm/types";
3
3
  import { providers } from "ethers";
4
+ import { TronWeb } from "tronweb";
4
5
 
5
6
  export function isPromiseFulfilled<T>(
6
7
  promiseSettledResult: PromiseSettledResult<T>
@@ -18,6 +19,10 @@ export function isDefined<T>(input: T | null | undefined): input is T {
18
19
  return input !== null && input !== undefined;
19
20
  }
20
21
 
21
- export function isEvmProvider(provider: EvmProvider | SVMProvider): provider is EvmProvider {
22
+ export function isTvmProvider(provider: EvmProvider | SVMProvider | TronWeb): provider is TronWeb {
23
+ return typeof (provider as TronWeb)?.trx?.getEnergyPrices === "function";
24
+ }
25
+
26
+ export function isEvmProvider(provider: EvmProvider | SVMProvider | TronWeb): provider is EvmProvider {
22
27
  return provider instanceof providers.Provider;
23
28
  }
@@ -0,0 +1,25 @@
1
+ [
2
+ {
3
+ "type": "function",
4
+ "name": "verifyProof",
5
+ "inputs": [
6
+ {
7
+ "name": "",
8
+ "type": "bytes32",
9
+ "internalType": "bytes32"
10
+ },
11
+ {
12
+ "name": "",
13
+ "type": "bytes",
14
+ "internalType": "bytes"
15
+ },
16
+ {
17
+ "name": "",
18
+ "type": "bytes",
19
+ "internalType": "bytes"
20
+ }
21
+ ],
22
+ "outputs": [],
23
+ "stateMutability": "pure"
24
+ }
25
+ ]
@@ -0,0 +1,112 @@
1
+ /* Autogenerated file. Do not edit manually. */
2
+ /* tslint:disable */
3
+ /* eslint-disable */
4
+ import type {
5
+ BaseContract,
6
+ BigNumber,
7
+ BytesLike,
8
+ CallOverrides,
9
+ PopulatedTransaction,
10
+ Signer,
11
+ utils,
12
+ } from "ethers";
13
+ import type { FunctionFragment, Result } from "@ethersproject/abi";
14
+ import type { Listener, Provider } from "@ethersproject/providers";
15
+ import type {
16
+ TypedEventFilter,
17
+ TypedEvent,
18
+ TypedListener,
19
+ OnEvent,
20
+ } from "./common";
21
+
22
+ export interface SP1AutoVerifierInterface extends utils.Interface {
23
+ functions: {
24
+ "verifyProof(bytes32,bytes,bytes)": FunctionFragment;
25
+ };
26
+
27
+ getFunction(nameOrSignatureOrTopic: "verifyProof"): FunctionFragment;
28
+
29
+ encodeFunctionData(
30
+ functionFragment: "verifyProof",
31
+ values: [BytesLike, BytesLike, BytesLike]
32
+ ): string;
33
+
34
+ decodeFunctionResult(
35
+ functionFragment: "verifyProof",
36
+ data: BytesLike
37
+ ): Result;
38
+
39
+ events: {};
40
+ }
41
+
42
+ export interface SP1AutoVerifier extends BaseContract {
43
+ connect(signerOrProvider: Signer | Provider | string): this;
44
+ attach(addressOrName: string): this;
45
+ deployed(): Promise<this>;
46
+
47
+ interface: SP1AutoVerifierInterface;
48
+
49
+ queryFilter<TEvent extends TypedEvent>(
50
+ event: TypedEventFilter<TEvent>,
51
+ fromBlockOrBlockhash?: string | number | undefined,
52
+ toBlock?: string | number | undefined
53
+ ): Promise<Array<TEvent>>;
54
+
55
+ listeners<TEvent extends TypedEvent>(
56
+ eventFilter?: TypedEventFilter<TEvent>
57
+ ): Array<TypedListener<TEvent>>;
58
+ listeners(eventName?: string): Array<Listener>;
59
+ removeAllListeners<TEvent extends TypedEvent>(
60
+ eventFilter: TypedEventFilter<TEvent>
61
+ ): this;
62
+ removeAllListeners(eventName?: string): this;
63
+ off: OnEvent<this>;
64
+ on: OnEvent<this>;
65
+ once: OnEvent<this>;
66
+ removeListener: OnEvent<this>;
67
+
68
+ functions: {
69
+ verifyProof(
70
+ arg0: BytesLike,
71
+ arg1: BytesLike,
72
+ arg2: BytesLike,
73
+ overrides?: CallOverrides
74
+ ): Promise<[void]>;
75
+ };
76
+
77
+ verifyProof(
78
+ arg0: BytesLike,
79
+ arg1: BytesLike,
80
+ arg2: BytesLike,
81
+ overrides?: CallOverrides
82
+ ): Promise<void>;
83
+
84
+ callStatic: {
85
+ verifyProof(
86
+ arg0: BytesLike,
87
+ arg1: BytesLike,
88
+ arg2: BytesLike,
89
+ overrides?: CallOverrides
90
+ ): Promise<void>;
91
+ };
92
+
93
+ filters: {};
94
+
95
+ estimateGas: {
96
+ verifyProof(
97
+ arg0: BytesLike,
98
+ arg1: BytesLike,
99
+ arg2: BytesLike,
100
+ overrides?: CallOverrides
101
+ ): Promise<BigNumber>;
102
+ };
103
+
104
+ populateTransaction: {
105
+ verifyProof(
106
+ arg0: BytesLike,
107
+ arg1: BytesLike,
108
+ arg2: BytesLike,
109
+ overrides?: CallOverrides
110
+ ): Promise<PopulatedTransaction>;
111
+ };
112
+ }
@@ -0,0 +1,49 @@
1
+ /* Autogenerated file. Do not edit manually. */
2
+ /* tslint:disable */
3
+ /* eslint-disable */
4
+
5
+ import { Contract, Signer, utils } from "ethers";
6
+ import type { Provider } from "@ethersproject/providers";
7
+ import type {
8
+ SP1AutoVerifier,
9
+ SP1AutoVerifierInterface,
10
+ } from "../SP1AutoVerifier";
11
+
12
+ const _abi = [
13
+ {
14
+ type: "function",
15
+ name: "verifyProof",
16
+ inputs: [
17
+ {
18
+ name: "",
19
+ type: "bytes32",
20
+ internalType: "bytes32",
21
+ },
22
+ {
23
+ name: "",
24
+ type: "bytes",
25
+ internalType: "bytes",
26
+ },
27
+ {
28
+ name: "",
29
+ type: "bytes",
30
+ internalType: "bytes",
31
+ },
32
+ ],
33
+ outputs: [],
34
+ stateMutability: "pure",
35
+ },
36
+ ] as const;
37
+
38
+ export class SP1AutoVerifier__factory {
39
+ static readonly abi = _abi;
40
+ static createInterface(): SP1AutoVerifierInterface {
41
+ return new utils.Interface(_abi) as SP1AutoVerifierInterface;
42
+ }
43
+ static connect(
44
+ address: string,
45
+ signerOrProvider: Signer | Provider
46
+ ): SP1AutoVerifier {
47
+ return new Contract(address, _abi, signerOrProvider) as SP1AutoVerifier;
48
+ }
49
+ }
@@ -254,6 +254,7 @@ export { ProxyAdmin__factory } from "./ProxyAdmin__factory";
254
254
  export { ReentrancyGuard__factory } from "./ReentrancyGuard__factory";
255
255
  export { ReentrancyGuardUpgradeable__factory } from "./ReentrancyGuardUpgradeable__factory";
256
256
  export { Router_Adapter__factory } from "./Router_Adapter__factory";
257
+ export { SP1AutoVerifier__factory } from "./SP1AutoVerifier__factory";
257
258
  export { SP1Helios__factory } from "./SP1Helios__factory";
258
259
  export { SafeCast__factory } from "./SafeCast__factory";
259
260
  export { SafeERC20__factory } from "./SafeERC20__factory";
@@ -254,6 +254,7 @@ export type { ProxyAdmin } from "./ProxyAdmin";
254
254
  export type { ReentrancyGuard } from "./ReentrancyGuard";
255
255
  export type { ReentrancyGuardUpgradeable } from "./ReentrancyGuardUpgradeable";
256
256
  export type { Router_Adapter } from "./Router_Adapter";
257
+ export type { SP1AutoVerifier } from "./SP1AutoVerifier";
257
258
  export type { SP1Helios } from "./SP1Helios";
258
259
  export type { SafeCast } from "./SafeCast";
259
260
  export type { SafeERC20 } from "./SafeERC20";
@@ -572,6 +573,7 @@ export { ShortStrings__factory } from "./factories/ShortStrings__factory";
572
573
  export { SimpleContract__factory } from "./factories/SimpleContract__factory";
573
574
  export { SkinnyOptimisticOracleInterface__factory } from "./factories/SkinnyOptimisticOracleInterface__factory";
574
575
  export { Solana_Adapter__factory } from "./factories/Solana_Adapter__factory";
576
+ export { SP1AutoVerifier__factory } from "./factories/SP1AutoVerifier__factory";
575
577
  export { SP1Helios__factory } from "./factories/SP1Helios__factory";
576
578
  export { SpokePool__factory } from "./factories/SpokePool__factory";
577
579
  export { SpokePoolEIP7702Test__factory } from "./factories/SpokePoolEIP7702Test__factory";