@across-protocol/sdk 4.1.63-beta.1 → 4.1.63-beta.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 (40) hide show
  1. package/dist/cjs/constants.d.ts +1 -0
  2. package/dist/cjs/constants.js +2 -1
  3. package/dist/cjs/constants.js.map +1 -1
  4. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js +5 -4
  5. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  6. package/dist/cjs/relayFeeCalculator/chain-queries/factory.js +1 -1
  7. package/dist/cjs/relayFeeCalculator/chain-queries/factory.js.map +1 -1
  8. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.d.ts +6 -0
  9. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js +69 -34
  10. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
  11. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.d.ts +2 -0
  12. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js +9 -3
  13. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  14. package/dist/esm/constants.d.ts +1 -0
  15. package/dist/esm/constants.js +1 -0
  16. package/dist/esm/constants.js.map +1 -1
  17. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js +6 -5
  18. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  19. package/dist/esm/relayFeeCalculator/chain-queries/factory.js +3 -3
  20. package/dist/esm/relayFeeCalculator/chain-queries/factory.js.map +1 -1
  21. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.d.ts +18 -0
  22. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js +83 -36
  23. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
  24. package/dist/esm/relayFeeCalculator/relayFeeCalculator.d.ts +12 -1
  25. package/dist/esm/relayFeeCalculator/relayFeeCalculator.js +9 -4
  26. package/dist/esm/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  27. package/dist/types/constants.d.ts +1 -0
  28. package/dist/types/constants.d.ts.map +1 -1
  29. package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts.map +1 -1
  30. package/dist/types/relayFeeCalculator/chain-queries/factory.d.ts.map +1 -1
  31. package/dist/types/relayFeeCalculator/chain-queries/svmQuery.d.ts +18 -0
  32. package/dist/types/relayFeeCalculator/chain-queries/svmQuery.d.ts.map +1 -1
  33. package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts +12 -1
  34. package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts.map +1 -1
  35. package/package.json +1 -1
  36. package/src/constants.ts +1 -0
  37. package/src/relayFeeCalculator/chain-queries/baseQuery.ts +6 -6
  38. package/src/relayFeeCalculator/chain-queries/factory.ts +3 -3
  39. package/src/relayFeeCalculator/chain-queries/svmQuery.ts +59 -27
  40. package/src/relayFeeCalculator/relayFeeCalculator.ts +15 -3
@@ -1,7 +1,7 @@
1
1
  import { pipe } from "@solana/functional";
2
2
  import { Coingecko } from "../../coingecko";
3
3
  import { SymbolMappingType } from "./";
4
- import { CHAIN_IDs, DEFAULT_SIMULATED_RELAYER_ADDRESS } from "../../constants";
4
+ import { CHAIN_IDs } from "../../constants";
5
5
  import { Deposit } from "../../interfaces";
6
6
  import { getGasPriceEstimate, SvmGasPriceEstimate } from "../../gasPriceOracle";
7
7
  import {
@@ -13,7 +13,7 @@ import {
13
13
  isDefined,
14
14
  toAddressType,
15
15
  } from "../../utils";
16
- import { Logger, QueryInterface } from "../relayFeeCalculator";
16
+ import { getDefaultSimulatedRelayerAddress, Logger, QueryInterface } from "../relayFeeCalculator";
17
17
  import {
18
18
  fillRelayInstruction,
19
19
  createApproveInstruction,
@@ -79,7 +79,7 @@ export class SvmQuery implements QueryInterface {
79
79
  */
80
80
  async getGasCosts(
81
81
  deposit: Omit<Deposit, "messageHash">,
82
- _relayer = DEFAULT_SIMULATED_RELAYER_ADDRESS,
82
+ _relayer = getDefaultSimulatedRelayerAddress(deposit.destinationChainId),
83
83
  options: Partial<{
84
84
  gasPrice: BigNumberish;
85
85
  gasUnits: BigNumberish;
@@ -87,11 +87,64 @@ export class SvmQuery implements QueryInterface {
87
87
  priorityFeeMultiplier: BigNumber;
88
88
  }> = {}
89
89
  ): Promise<TransactionCostEstimate> {
90
+ const relayer = _relayer ? toAddressType(_relayer).forceSvmAddress() : this.simulatedRelayerAddress;
91
+
92
+ const fillRelayTx = await this.getFillRelayTx(deposit, relayer.toBase58());
93
+
94
+ const [computeUnitsConsumed, _gasPriceEstimate] = await Promise.all([
95
+ toBN(await this.computeUnitEstimator(fillRelayTx)),
96
+ getGasPriceEstimate(this.provider, {
97
+ unsignedTx: fillRelayTx,
98
+ baseFeeMultiplier: options.baseFeeMultiplier,
99
+ priorityFeeMultiplier: options.priorityFeeMultiplier,
100
+ }),
101
+ ]);
102
+
103
+ // We can cast the gas price estimate to an SvmGasPriceEstimate here since the oracle should always
104
+ // query the Solana adapter.
105
+ const gasPriceEstimate = _gasPriceEstimate as SvmGasPriceEstimate;
106
+ const gasPrice = gasPriceEstimate.baseFee.add(
107
+ gasPriceEstimate.microLamportsPerComputeUnit.mul(computeUnitsConsumed).div(toBN(1_000_000)) // 1_000_000 microLamports/lamport.
108
+ );
109
+
110
+ return {
111
+ nativeGasCost: computeUnitsConsumed,
112
+ tokenGasCost: gasPrice,
113
+ gasPrice,
114
+ };
115
+ }
116
+
117
+ /**
118
+ * @notice Return the gas cost of a simulated transaction
119
+ * @param fillRelayTx FillRelay transaction
120
+ * @param relayer SVM address of the relayer
121
+ * @returns Estimated gas cost in compute units
122
+ */
123
+ async getNativeGasCost(
124
+ deposit: Omit<Deposit, "messageHash">,
125
+ _relayer = getDefaultSimulatedRelayerAddress(deposit.destinationChainId)
126
+ ): Promise<BigNumber> {
127
+ const fillRelayTx = await this.getFillRelayTx(deposit, _relayer);
128
+ const computeUnitsConsumed = toBN(await this.computeUnitEstimator(fillRelayTx));
129
+ return computeUnitsConsumed;
130
+ }
131
+
132
+ /**
133
+ * @notice Return the fillRelay transaction for a given deposit
134
+ * @param deposit
135
+ * @param relayer SVM address of the relayer
136
+ * @returns FillRelay transaction
137
+ */
138
+ async getFillRelayTx(
139
+ deposit: Omit<Deposit, "messageHash">,
140
+ _relayer = getDefaultSimulatedRelayerAddress(deposit.destinationChainId)
141
+ ) {
142
+ const relayer = _relayer ? toAddressType(_relayer).forceSvmAddress() : this.simulatedRelayerAddress;
90
143
  // If the user did not have a token account created on destination, then we need to include this as a gas cost.
91
144
  const mint = toAddressType(deposit.outputToken).forceSvmAddress();
92
145
  const owner = toAddressType(deposit.recipient).forceSvmAddress();
93
146
  const associatedToken = await getAssociatedTokenAddress(owner, mint);
94
- const simulatedSigner = SolanaVoidSigner(this.simulatedRelayerAddress.toBase58());
147
+ const simulatedSigner = SolanaVoidSigner(relayer.toBase58());
95
148
 
96
149
  // If the recipient has an associated token account on destination, then skip generating the instruction for creating a new token account.
97
150
  let recipientCreateTokenAccountInstructions: IInstruction[] | undefined = undefined;
@@ -134,7 +187,7 @@ export class SvmQuery implements QueryInterface {
134
187
  const recentBlockhash = await this.provider.getLatestBlockhash().send();
135
188
  const fillRelayTx = pipe(
136
189
  createTransactionMessage({ version: 0 }),
137
- (tx) => setTransactionMessageFeePayer(this.simulatedRelayerAddress.toV2Address(), tx),
190
+ (tx) => setTransactionMessageFeePayer(relayer.toV2Address(), tx),
138
191
  (tx) => setTransactionMessageLifetimeUsingBlockhash(recentBlockhash.value, tx),
139
192
  (tx) =>
140
193
  isDefined(recipientCreateTokenAccountInstructions)
@@ -142,28 +195,7 @@ export class SvmQuery implements QueryInterface {
142
195
  : tx,
143
196
  (tx) => appendTransactionMessageInstructions([createTokenAccountsIx, approveIx, fillIx], tx)
144
197
  );
145
-
146
- const [computeUnitsConsumed, _gasPriceEstimate] = await Promise.all([
147
- toBN(await this.computeUnitEstimator(fillRelayTx)),
148
- getGasPriceEstimate(this.provider, {
149
- unsignedTx: fillRelayTx,
150
- baseFeeMultiplier: options.baseFeeMultiplier,
151
- priorityFeeMultiplier: options.priorityFeeMultiplier,
152
- }),
153
- ]);
154
-
155
- // We can cast the gas price estimate to an SvmGasPriceEstimate here since the oracle should always
156
- // query the Solana adapter.
157
- const gasPriceEstimate = _gasPriceEstimate as SvmGasPriceEstimate;
158
- const gasPrice = gasPriceEstimate.baseFee.add(
159
- gasPriceEstimate.microLamportsPerComputeUnit.mul(computeUnitsConsumed).div(toBN(1_000_000)) // 1_000_000 microLamports/lamport.
160
- );
161
-
162
- return {
163
- nativeGasCost: computeUnitsConsumed,
164
- tokenGasCost: gasPrice,
165
- gasPrice,
166
- };
198
+ return fillRelayTx;
167
199
  }
168
200
 
169
201
  /**
@@ -1,5 +1,9 @@
1
1
  import assert from "assert";
2
- import { DEFAULT_SIMULATED_RELAYER_ADDRESS, TOKEN_SYMBOLS_MAP } from "../constants";
2
+ import {
3
+ DEFAULT_SIMULATED_RELAYER_ADDRESS,
4
+ DEFAULT_SIMULATED_RELAYER_ADDRESS_SVM,
5
+ TOKEN_SYMBOLS_MAP,
6
+ } from "../constants";
3
7
  import { Deposit } from "../interfaces";
4
8
  import {
5
9
  BigNumber,
@@ -18,6 +22,7 @@ import {
18
22
  toBNWei,
19
23
  isZeroAddress,
20
24
  compareAddressesSimple,
25
+ chainIsSvm,
21
26
  } from "../utils";
22
27
  import { Transport } from "viem";
23
28
 
@@ -36,6 +41,7 @@ export interface QueryInterface {
36
41
  }>
37
42
  ) => Promise<TransactionCostEstimate>;
38
43
  getTokenPrice: (tokenSymbol: string) => Promise<number>;
44
+ getNativeGasCost: (deposit: Omit<Deposit, "messageHash">, relayer: string) => Promise<BigNumber>;
39
45
  }
40
46
 
41
47
  export const expectedCapitalCostsKeys = ["lowerBound", "upperBound", "cutoff", "decimals"];
@@ -105,6 +111,12 @@ export const DEFAULT_LOGGER: Logger = {
105
111
  error: (...args) => console.error(args),
106
112
  };
107
113
 
114
+ export function getDefaultSimulatedRelayerAddress(chainId?: number) {
115
+ return isDefined(chainId) && chainIsSvm(chainId)
116
+ ? DEFAULT_SIMULATED_RELAYER_ADDRESS_SVM
117
+ : DEFAULT_SIMULATED_RELAYER_ADDRESS;
118
+ }
119
+
108
120
  // Small amount to simulate filling with. Should be low enough to guarantee a successful fill.
109
121
  const safeOutputAmount = toBN(100);
110
122
 
@@ -241,7 +253,7 @@ export class RelayFeeCalculator {
241
253
  deposit: Deposit,
242
254
  amountToRelay: BigNumberish,
243
255
  simulateZeroFill = false,
244
- relayerAddress = DEFAULT_SIMULATED_RELAYER_ADDRESS,
256
+ relayerAddress = getDefaultSimulatedRelayerAddress(deposit.destinationChainId),
245
257
  _tokenPrice?: number,
246
258
  tokenMapping = TOKEN_SYMBOLS_MAP,
247
259
  gasPrice?: BigNumberish,
@@ -480,7 +492,7 @@ export class RelayFeeCalculator {
480
492
  deposit: Deposit,
481
493
  amountToRelay?: BigNumberish,
482
494
  simulateZeroFill = false,
483
- relayerAddress = DEFAULT_SIMULATED_RELAYER_ADDRESS,
495
+ relayerAddress = getDefaultSimulatedRelayerAddress(deposit.destinationChainId),
484
496
  _tokenPrice?: number,
485
497
  gasPrice?: BigNumberish,
486
498
  gasUnits?: BigNumberish,