@across-protocol/sdk 4.2.6 → 4.2.8

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 (40) hide show
  1. package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js +1 -1
  2. package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
  3. package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.d.ts +3 -1
  4. package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js +5 -13
  5. package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
  6. package/dist/cjs/clients/mocks/MockSpokePoolClient.d.ts +5 -11
  7. package/dist/cjs/clients/mocks/MockSpokePoolClient.js +18 -35
  8. package/dist/cjs/clients/mocks/MockSpokePoolClient.js.map +1 -1
  9. package/dist/cjs/interfaces/SpokePool.d.ts +1 -3
  10. package/dist/cjs/interfaces/SpokePool.js.map +1 -1
  11. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.d.ts +3 -3
  12. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js +24 -22
  13. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  14. package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js +1 -1
  15. package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
  16. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.d.ts +3 -1
  17. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js +5 -13
  18. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
  19. package/dist/esm/clients/mocks/MockSpokePoolClient.d.ts +5 -11
  20. package/dist/esm/clients/mocks/MockSpokePoolClient.js +21 -38
  21. package/dist/esm/clients/mocks/MockSpokePoolClient.js.map +1 -1
  22. package/dist/esm/interfaces/SpokePool.d.ts +1 -3
  23. package/dist/esm/interfaces/SpokePool.js.map +1 -1
  24. package/dist/esm/relayFeeCalculator/relayFeeCalculator.d.ts +4 -13
  25. package/dist/esm/relayFeeCalculator/relayFeeCalculator.js +25 -23
  26. package/dist/esm/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  27. package/dist/types/clients/SpokePoolClient/SpokePoolClient.d.ts +3 -1
  28. package/dist/types/clients/SpokePoolClient/SpokePoolClient.d.ts.map +1 -1
  29. package/dist/types/clients/mocks/MockSpokePoolClient.d.ts +5 -11
  30. package/dist/types/clients/mocks/MockSpokePoolClient.d.ts.map +1 -1
  31. package/dist/types/interfaces/SpokePool.d.ts +1 -3
  32. package/dist/types/interfaces/SpokePool.d.ts.map +1 -1
  33. package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts +4 -13
  34. package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts.map +1 -1
  35. package/package.json +1 -1
  36. package/src/clients/SpokePoolClient/EVMSpokePoolClient.ts +1 -1
  37. package/src/clients/SpokePoolClient/SpokePoolClient.ts +8 -16
  38. package/src/clients/mocks/MockSpokePoolClient.ts +36 -66
  39. package/src/interfaces/SpokePool.ts +1 -4
  40. package/src/relayFeeCalculator/relayFeeCalculator.ts +25 -22
@@ -25,7 +25,6 @@ import {
25
25
  BigNumber,
26
26
  bnZero,
27
27
  bnOne,
28
- toAddress,
29
28
  toBytes32,
30
29
  spreadEventWithBlockNumber,
31
30
  } from "../../utils";
@@ -85,6 +84,7 @@ export class MockSpokePoolClient extends EVMSpokePoolClient {
85
84
  lastDepositId = _depositIds[i];
86
85
  }
87
86
  }
87
+
88
88
  _getDepositIdAtBlock(blockTag: number): Promise<BigNumber> {
89
89
  return Promise.resolve(this.depositIdAtBlock[blockTag]);
90
90
  }
@@ -129,10 +129,6 @@ export class MockSpokePoolClient extends EVMSpokePoolClient {
129
129
  return this._deposit("FundsDeposited", deposit);
130
130
  }
131
131
 
132
- depositV3(deposit: Omit<Deposit, "messageHash"> & Partial<SortableEvent>): Log {
133
- return this._deposit("V3FundsDeposited", deposit);
134
- }
135
-
136
132
  protected _deposit(event: string, deposit: Omit<Deposit, "messageHash"> & Partial<SortableEvent>): Log {
137
133
  const { blockNumber, txnIndex } = deposit;
138
134
  let { depositId, destinationChainId, inputAmount, outputAmount } = deposit;
@@ -140,12 +136,11 @@ export class MockSpokePoolClient extends EVMSpokePoolClient {
140
136
  this.numberOfDeposits = depositId.add(bnOne);
141
137
 
142
138
  destinationChainId ??= random(1, 42161, false);
143
- const addressModifier = event === "FundsDeposited" ? toBytes32 : toAddress;
144
- const depositor = addressModifier(deposit.depositor ?? randomAddress());
145
- const recipient = addressModifier(deposit.recipient ?? depositor);
146
- const inputToken = addressModifier(deposit.inputToken ?? randomAddress());
147
- const outputToken = addressModifier(deposit.outputToken ?? inputToken);
148
- const exclusiveRelayer = addressModifier(deposit.exclusiveRelayer ?? ZERO_ADDRESS);
139
+ const depositor = toBytes32(deposit.depositor ?? randomAddress());
140
+ const recipient = toBytes32(deposit.recipient ?? depositor);
141
+ const inputToken = toBytes32(deposit.inputToken ?? randomAddress());
142
+ const outputToken = toBytes32(deposit.outputToken ?? inputToken);
143
+ const exclusiveRelayer = toBytes32(deposit.exclusiveRelayer ?? ZERO_ADDRESS);
149
144
 
150
145
  inputAmount ??= toBNWei(random(1, 1000, false));
151
146
  outputAmount ??= inputAmount.mul(toBN("0.95"));
@@ -180,17 +175,13 @@ export class MockSpokePoolClient extends EVMSpokePoolClient {
180
175
  });
181
176
  }
182
177
 
183
- fillV3Relay(fill: Omit<Fill, "messageHash"> & { message: string } & Partial<SortableEvent>): Log {
184
- return this._fillRelay("FilledV3Relay", fill);
185
- }
186
-
187
- fillRelay(fill: Omit<Fill, "messageHash"> & { message: string } & Partial<SortableEvent>): Log {
178
+ fillRelay(fill: Omit<Fill, "messageHash"> & { message?: string } & Partial<SortableEvent>): Log {
188
179
  return this._fillRelay("FilledRelay", fill);
189
180
  }
190
181
 
191
182
  protected _fillRelay(
192
183
  event: string,
193
- fill: Omit<Fill, "messageHash"> & { message: string } & Partial<SortableEvent>
184
+ fill: Omit<Fill, "messageHash"> & { message?: string } & Partial<SortableEvent>
194
185
  ): Log {
195
186
  const { blockNumber, txnIndex } = fill;
196
187
  let { originChainId, depositId, inputAmount, outputAmount, fillDeadline } = fill;
@@ -200,15 +191,14 @@ export class MockSpokePoolClient extends EVMSpokePoolClient {
200
191
  outputAmount ??= inputAmount;
201
192
  fillDeadline ??= getCurrentTime() + 60;
202
193
 
203
- const addressModifier = event === "FilledRelay" ? toBytes32 : toAddress;
204
- const depositor = addressModifier(fill.depositor ?? randomAddress());
205
- const recipient = addressModifier(fill.recipient ?? depositor);
206
- const inputToken = addressModifier(fill.inputToken ?? randomAddress());
207
- const outputToken = addressModifier(fill.outputToken ?? ZERO_ADDRESS);
208
- const exclusiveRelayer = addressModifier(fill.exclusiveRelayer ?? ZERO_ADDRESS);
209
- const relayer = addressModifier(fill.relayer ?? randomAddress());
194
+ const depositor = toBytes32(fill.depositor ?? randomAddress());
195
+ const recipient = toBytes32(fill.recipient ?? depositor);
196
+ const inputToken = toBytes32(fill.inputToken ?? randomAddress());
197
+ const outputToken = toBytes32(fill.outputToken ?? ZERO_ADDRESS);
198
+ const exclusiveRelayer = toBytes32(fill.exclusiveRelayer ?? ZERO_ADDRESS);
199
+ const relayer = toBytes32(fill.relayer ?? randomAddress());
210
200
 
211
- const topics = [originChainId, depositId, relayer]; // @todo verify
201
+ const topics = [originChainId, depositId, relayer];
212
202
  const message = fill.message ?? EMPTY_MESSAGE;
213
203
  const updatedMessage = fill.relayExecutionInfo?.updatedMessage ?? message;
214
204
 
@@ -239,25 +229,14 @@ export class MockSpokePoolClient extends EVMSpokePoolClient {
239
229
  },
240
230
  };
241
231
 
242
- const args =
243
- event === "FilledRelay"
244
- ? {
245
- ..._args,
246
- messageHash: getMessageHash(message),
247
- relayExecutionInfo: {
248
- ...relayExecutionInfo,
249
- updatedMessageHash: getMessageHash(updatedMessage),
250
- },
251
- }
252
- : {
253
- // FilledV3Relay
254
- ..._args,
255
- message,
256
- relayExecutionInfo: {
257
- ...relayExecutionInfo,
258
- updatedMessage,
259
- },
260
- };
232
+ const args = {
233
+ ..._args,
234
+ messageHash: getMessageHash(message),
235
+ relayExecutionInfo: {
236
+ ...relayExecutionInfo,
237
+ updatedMessageHash: getMessageHash(updatedMessage),
238
+ },
239
+ };
261
240
 
262
241
  return this.eventManager.generateEvent({
263
242
  event,
@@ -269,17 +248,12 @@ export class MockSpokePoolClient extends EVMSpokePoolClient {
269
248
  });
270
249
  }
271
250
 
272
- speedUpV3Deposit(speedUp: SpeedUp): Log {
273
- return this._speedUpDeposit("RequestedSpeedUpV3Deposit", speedUp);
274
- }
275
-
276
251
  speedUpDeposit(speedUp: SpeedUp): Log {
277
252
  return this._speedUpDeposit("RequestedSpeedUpDeposit", speedUp);
278
253
  }
279
254
 
280
255
  protected _speedUpDeposit(event: string, speedUp: SpeedUp): Log {
281
- const addressModifier = event === "RequestedSpeedUpDeposit" ? toBytes32 : toAddress;
282
- const depositor = addressModifier(speedUp.depositor);
256
+ const depositor = toBytes32(speedUp.depositor);
283
257
  const topics = [speedUp.depositId, depositor];
284
258
  const args = { ...speedUp };
285
259
 
@@ -290,7 +264,7 @@ export class MockSpokePoolClient extends EVMSpokePoolClient {
290
264
  args: {
291
265
  ...args,
292
266
  depositor,
293
- updatedRecipient: addressModifier(speedUp.updatedRecipient),
267
+ updatedRecipient: toBytes32(speedUp.updatedRecipient),
294
268
  },
295
269
  });
296
270
  }
@@ -308,24 +282,19 @@ export class MockSpokePoolClient extends EVMSpokePoolClient {
308
282
  });
309
283
  }
310
284
 
311
- requestV3SlowFill(request: Omit<SlowFillRequest, "messageHash"> & Partial<SortableEvent>): Log {
312
- return this._requestSlowFill("RequestedV3SlowFill", request);
313
- }
314
-
315
- requestSlowFill(request: Omit<SlowFillRequest, "messageHash"> & Partial<SortableEvent>): Log {
285
+ requestSlowFill(request: Omit<SlowFillRequest, "destinationChainId"> & Partial<SortableEvent>): Log {
316
286
  return this._requestSlowFill("RequestedSlowFill", request);
317
287
  }
318
288
 
319
289
  protected _requestSlowFill(
320
290
  event: string,
321
- request: Omit<SlowFillRequest, "messageHash"> & Partial<SortableEvent>
291
+ request: Omit<SlowFillRequest, "destinationChainId"> & Partial<SortableEvent>
322
292
  ): Log {
323
293
  const { originChainId, depositId } = request;
324
294
  const topics = [originChainId, depositId];
325
295
  const args = { ...request };
326
296
 
327
- const addressModifier = event === "RequestedSlowFill" ? toBytes32 : toAddress;
328
- const depositor = addressModifier(args.depositor ?? randomAddress());
297
+ const depositor = toBytes32(args.depositor ?? randomAddress());
329
298
 
330
299
  return this.eventManager.generateEvent({
331
300
  event,
@@ -333,20 +302,21 @@ export class MockSpokePoolClient extends EVMSpokePoolClient {
333
302
  topics: topics.map((topic) => topic.toString()),
334
303
  args: {
335
304
  ...args,
305
+ destinationChainId: this.chainId,
336
306
  depositor,
337
- recipient: addressModifier(args.recipient ?? depositor),
338
- inputToken: addressModifier(args.inputToken ?? randomAddress()),
339
- outputToken: addressModifier(args.outputToken ?? ZERO_ADDRESS),
340
- exclusiveRelayer: addressModifier(args.exclusiveRelayer ?? ZERO_ADDRESS),
307
+ recipient: toBytes32(args.recipient ?? depositor),
308
+ inputToken: toBytes32(args.inputToken ?? randomAddress()),
309
+ outputToken: toBytes32(args.outputToken ?? ZERO_ADDRESS),
310
+ exclusiveRelayer: toBytes32(args.exclusiveRelayer ?? ZERO_ADDRESS),
341
311
  },
342
312
  blockNumber: request.blockNumber,
343
313
  transactionIndex: request.txnIndex,
344
314
  });
345
315
  }
346
316
 
347
- // This is a simple wrapper around fillV3Relay().
317
+ // This is a simple wrapper around fillRelay().
348
318
  // rootBundleId and proof are discarded here - we have no interest in verifying that.
349
- executeV3SlowRelayLeaf(leaf: Omit<SlowFillLeaf, "messageHash">): Log {
319
+ executeSlowRelayLeaf(leaf: Omit<SlowFillLeaf, "messageHash">): Log {
350
320
  const fill = {
351
321
  ...leaf.relayData,
352
322
  destinationChainId: this.chainId,
@@ -361,7 +331,7 @@ export class MockSpokePoolClient extends EVMSpokePoolClient {
361
331
  },
362
332
  };
363
333
 
364
- return this.fillV3Relay(fill);
334
+ return this.fillRelay(fill);
365
335
  }
366
336
 
367
337
  executeRelayerRefundLeaf(refund: RelayerRefundExecution & Partial<SortableEvent>): Log {
@@ -1,11 +1,8 @@
1
1
  import { SortableEvent } from "./Common";
2
- import { FilledV3RelayEvent, V3FundsDepositedEvent } from "../typechain";
3
2
  import { SpokePoolClient } from "../clients";
4
3
  import { BigNumber } from "../utils";
5
4
  import { RelayerRefundLeaf } from "./HubPool";
6
5
 
7
- export type { FilledV3RelayEvent, V3FundsDepositedEvent };
8
-
9
6
  export interface RelayData {
10
7
  originChainId: number;
11
8
  depositor: string;
@@ -93,7 +90,7 @@ export interface SpeedUp {
93
90
 
94
91
  export interface SpeedUpWithBlock extends SpeedUp, SortableEvent {}
95
92
 
96
- export interface SlowFillRequest extends RelayData {
93
+ export interface SlowFillRequest extends Omit<RelayData, "message"> {
97
94
  messageHash: string;
98
95
  destinationChainId: number;
99
96
  }
@@ -22,6 +22,7 @@ import {
22
22
  toBNWei,
23
23
  isZeroAddress,
24
24
  compareAddressesSimple,
25
+ ConvertDecimals,
25
26
  chainIsSvm,
26
27
  } from "../utils";
27
28
  import { Transport } from "viem";
@@ -251,7 +252,7 @@ export class RelayFeeCalculator {
251
252
  */
252
253
  async gasFeePercent(
253
254
  deposit: Deposit,
254
- amountToRelay: BigNumberish,
255
+ outputAmount: BigNumberish,
255
256
  simulateZeroFill = false,
256
257
  relayerAddress = getDefaultSimulatedRelayerAddress(deposit.destinationChainId),
257
258
  _tokenPrice?: number,
@@ -261,7 +262,7 @@ export class RelayFeeCalculator {
261
262
  _tokenGasCost?: BigNumberish,
262
263
  transport?: Transport
263
264
  ): Promise<BigNumber> {
264
- if (toBN(amountToRelay).eq(bnZero)) return MAX_BIG_INT;
265
+ if (toBN(outputAmount).eq(bnZero)) return MAX_BIG_INT;
265
266
 
266
267
  const { inputToken, destinationChainId, originChainId } = deposit;
267
268
  // It's fine if we resolve a destination token which is not the "canonical" L1 token (e.g. USDB for DAI or USDC.e for USDC), since `getTokenInfo` will re-map
@@ -284,7 +285,7 @@ export class RelayFeeCalculator {
284
285
 
285
286
  // Reduce the output amount to simulate a full fill with a lower value to estimate
286
287
  // the fill cost accurately without risking a failure due to insufficient balance.
287
- const simulatedAmount = simulateZeroFill ? safeOutputAmount : toBN(amountToRelay);
288
+ const simulatedAmount = simulateZeroFill ? safeOutputAmount : toBN(outputAmount);
288
289
  deposit = { ...deposit, outputAmount: simulatedAmount };
289
290
 
290
291
  const getGasCosts = this.queries
@@ -314,19 +315,19 @@ export class RelayFeeCalculator {
314
315
  throw error;
315
316
  }),
316
317
  ]);
317
- const gasFeesInToken = nativeToToken(tokenGasCost, tokenPrice, inputTokenInfo.decimals, this.nativeTokenDecimals);
318
- return percent(gasFeesInToken, amountToRelay.toString());
318
+ const gasFeesInToken = nativeToToken(tokenGasCost, tokenPrice, outputTokenInfo.decimals, this.nativeTokenDecimals);
319
+ return percent(gasFeesInToken, outputAmount.toString());
319
320
  }
320
321
 
321
322
  // Note: these variables are unused now, but may be needed in future versions of this function that are more complex.
322
323
  capitalFeePercent(
323
- _amountToRelay: BigNumberish,
324
+ _outputAmount: BigNumberish,
324
325
  _tokenSymbol: string,
325
326
  _originRoute?: ChainIdAsString,
326
327
  _destinationRoute?: ChainIdAsString
327
328
  ): BigNumber {
328
329
  // If amount is 0, then the capital fee % should be the max 100%
329
- if (toBN(_amountToRelay).eq(toBN(0))) return MAX_BIG_INT;
330
+ if (toBN(_outputAmount).eq(toBN(0))) return MAX_BIG_INT;
330
331
 
331
332
  // V0: Ensure that there is a capital fee available for the token.
332
333
  // If not, then we should throw an error because this is indicative
@@ -366,7 +367,7 @@ export class RelayFeeCalculator {
366
367
  );
367
368
 
368
369
  // Scale amount "y" to 18 decimals.
369
- const y = toBN(_amountToRelay).mul(toBNWei("1", 18 - config.decimals));
370
+ const y = toBN(_outputAmount).mul(toBNWei("1", 18 - config.decimals));
370
371
  // At a minimum, the fee will be equal to lower bound fee * y
371
372
  const minCharge = toBN(config.lowerBound).mul(y).div(fixedPointAdjustment);
372
373
 
@@ -490,7 +491,7 @@ export class RelayFeeCalculator {
490
491
  */
491
492
  async relayerFeeDetails(
492
493
  deposit: Deposit,
493
- amountToRelay?: BigNumberish,
494
+ outputAmount?: BigNumberish,
494
495
  simulateZeroFill = false,
495
496
  relayerAddress = getDefaultSimulatedRelayerAddress(deposit.destinationChainId),
496
497
  _tokenPrice?: number,
@@ -500,18 +501,19 @@ export class RelayFeeCalculator {
500
501
  ): Promise<RelayerFeeDetails> {
501
502
  // If the amount to relay is not provided, then we
502
503
  // should use the full deposit amount.
503
- amountToRelay ??= deposit.outputAmount;
504
- const { inputToken, originChainId } = deposit;
504
+ outputAmount ??= deposit.outputAmount;
505
+ const { inputToken, originChainId, outputToken, destinationChainId } = deposit;
505
506
  // We can perform a simple lookup with `getTokenInfo` here without resolving the exact token to resolve since we only need to
506
507
  // resolve the L1 token symbol and not the L2 token decimals.
507
- const token = getTokenInfo(inputToken, originChainId);
508
- if (!isDefined(token)) {
509
- throw new Error(`Could not find token information for ${inputToken}`);
508
+ const inputTokenInfo = getTokenInfo(inputToken, originChainId);
509
+ const outputTokenInfo = getTokenInfo(outputToken, destinationChainId);
510
+ if (!isDefined(inputTokenInfo) || !isDefined(outputTokenInfo)) {
511
+ throw new Error(`Could not find token information for ${inputToken} or ${outputToken}`);
510
512
  }
511
513
 
512
514
  const gasFeePercent = await this.gasFeePercent(
513
515
  deposit,
514
- amountToRelay,
516
+ outputAmount,
515
517
  simulateZeroFill,
516
518
  relayerAddress,
517
519
  _tokenPrice,
@@ -520,14 +522,15 @@ export class RelayFeeCalculator {
520
522
  gasUnits,
521
523
  tokenGasCost
522
524
  );
523
- const gasFeeTotal = gasFeePercent.mul(amountToRelay).div(fixedPointAdjustment);
525
+ const outToInDecimals = ConvertDecimals(outputTokenInfo.decimals, inputTokenInfo.decimals);
526
+ const gasFeeTotal = gasFeePercent.mul(outToInDecimals(outputAmount.toString())).div(fixedPointAdjustment);
524
527
  const capitalFeePercent = this.capitalFeePercent(
525
- amountToRelay,
526
- token.symbol,
528
+ outputAmount,
529
+ inputTokenInfo.symbol,
527
530
  deposit.originChainId.toString(),
528
531
  deposit.destinationChainId.toString()
529
532
  );
530
- const capitalFeeTotal = capitalFeePercent.mul(amountToRelay).div(fixedPointAdjustment);
533
+ const capitalFeeTotal = capitalFeePercent.mul(outToInDecimals(outputAmount.toString())).div(fixedPointAdjustment);
531
534
  const relayFeePercent = gasFeePercent.add(capitalFeePercent);
532
535
  const relayFeeTotal = gasFeeTotal.add(capitalFeeTotal);
533
536
 
@@ -546,12 +549,12 @@ export class RelayFeeCalculator {
546
549
  isAmountTooLow = true;
547
550
  } else {
548
551
  minDeposit = gasFeeTotal.mul(fixedPointAdjustment).div(maxGasFeePercent);
549
- isAmountTooLow = toBN(amountToRelay).lt(minDeposit);
552
+ isAmountTooLow = toBN(outputAmount).lt(minDeposit);
550
553
  }
551
554
 
552
555
  return {
553
- amountToRelay: amountToRelay.toString(),
554
- tokenSymbol: token.symbol,
556
+ amountToRelay: outputAmount.toString(),
557
+ tokenSymbol: inputTokenInfo.symbol,
555
558
  gasFeePercent: gasFeePercent.toString(),
556
559
  gasFeeTotal: gasFeeTotal.toString(),
557
560
  gasDiscountPercent: this.gasDiscountPercent,