@cowprotocol/sdk-bridging 0.1.0-monorepo.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.
- package/README.md +156 -0
- package/dist/index.d.mts +634 -0
- package/dist/index.d.ts +634 -0
- package/dist/index.js +2946 -0
- package/dist/index.mjs +2924 -0
- package/package.json +50 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,634 @@
|
|
|
1
|
+
import { latest } from '@cowprotocol/sdk-app-data';
|
|
2
|
+
import { Amounts, OrderKind, Address, EnrichedOrder, OrderBookApi } from '@cowprotocol/sdk-order-book';
|
|
3
|
+
import { ChainInfo, TargetChainId, TokenInfo, SupportedChainId, EvmCall, CowEnv, ChainId } from '@cowprotocol/sdk-config';
|
|
4
|
+
import { QuoterParameters, TraderParameters, TradeOptionalParameters, QuoteAndPost, QuoteResults, SwapAdvancedSettings, OrderPostingResult, TradingSdk } from '@cowprotocol/sdk-trading';
|
|
5
|
+
import { AccountAddress, SignerLike, AbstractProviderAdapter, Signer } from '@cowprotocol/sdk-common';
|
|
6
|
+
import { CowShedSdk, CowShedSdkOptions } from '@cowprotocol/sdk-cow-shed';
|
|
7
|
+
|
|
8
|
+
interface BridgeProviderInfo {
|
|
9
|
+
name: string;
|
|
10
|
+
logoUrl: string;
|
|
11
|
+
}
|
|
12
|
+
interface WithSellToken {
|
|
13
|
+
sellTokenChainId: SupportedChainId;
|
|
14
|
+
sellTokenAddress: Address;
|
|
15
|
+
sellTokenDecimals: number;
|
|
16
|
+
}
|
|
17
|
+
interface WithBuyToken {
|
|
18
|
+
buyTokenChainId: TargetChainId;
|
|
19
|
+
buyTokenAddress: Address;
|
|
20
|
+
buyTokenDecimals: number;
|
|
21
|
+
}
|
|
22
|
+
type WithQuoter = Omit<QuoterParameters, 'chainId'>;
|
|
23
|
+
type WithTrader = Pick<TraderParameters, 'signer'>;
|
|
24
|
+
/**
|
|
25
|
+
* Parameters for getting a bridge quote
|
|
26
|
+
*/
|
|
27
|
+
type QuoteBridgeRequest = {
|
|
28
|
+
kind: OrderKind;
|
|
29
|
+
amount: bigint;
|
|
30
|
+
owner?: AccountAddress;
|
|
31
|
+
} & WithSellToken & WithBuyToken & WithQuoter & WithTrader & TradeOptionalParameters;
|
|
32
|
+
type QuoteBridgeRequestWithoutAmount = Omit<QuoteBridgeRequest, 'amount'>;
|
|
33
|
+
interface BridgeQuoteResult {
|
|
34
|
+
/**
|
|
35
|
+
* Whether the quote is a sell or buy order.
|
|
36
|
+
*/
|
|
37
|
+
isSell: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Costs and amounts of the bridging.
|
|
40
|
+
*/
|
|
41
|
+
amountsAndCosts: BridgeQuoteAmountsAndCosts;
|
|
42
|
+
/**
|
|
43
|
+
* The estimated time in seconds it takes to fill the order.
|
|
44
|
+
*/
|
|
45
|
+
expectedFillTimeSeconds?: number;
|
|
46
|
+
/**
|
|
47
|
+
* The timestamp of the quote.
|
|
48
|
+
*/
|
|
49
|
+
quoteTimestamp: number;
|
|
50
|
+
fees: {
|
|
51
|
+
/**
|
|
52
|
+
* The amount that should go to the relayer as a fee to cover relayer capital costs.
|
|
53
|
+
* In token atoms.
|
|
54
|
+
*/
|
|
55
|
+
bridgeFee: bigint;
|
|
56
|
+
/**
|
|
57
|
+
* The amount that should go to the relayer as a fee to cover relayer gas costs.
|
|
58
|
+
* In token atoms.
|
|
59
|
+
*/
|
|
60
|
+
destinationGasFee: bigint;
|
|
61
|
+
};
|
|
62
|
+
limits: {
|
|
63
|
+
/**
|
|
64
|
+
* The minimum amount that should be deposited in the source chain.
|
|
65
|
+
* In token atoms.
|
|
66
|
+
*/
|
|
67
|
+
minDeposit: bigint;
|
|
68
|
+
/**
|
|
69
|
+
* The maximum amount that can be deposited in the source chain.
|
|
70
|
+
* In token atoms.
|
|
71
|
+
*/
|
|
72
|
+
maxDeposit: bigint;
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
interface BridgeHook {
|
|
76
|
+
postHook: latest.CoWHook;
|
|
77
|
+
recipient: string;
|
|
78
|
+
}
|
|
79
|
+
declare enum BridgeStatus {
|
|
80
|
+
NOT_INITIATED = "not_initiated",
|
|
81
|
+
IN_PROGRESS = "in_progress",
|
|
82
|
+
EXECUTED = "executed",
|
|
83
|
+
FAILED = "failed",
|
|
84
|
+
EXPIRED = "expired"
|
|
85
|
+
}
|
|
86
|
+
interface BridgeStatusResult {
|
|
87
|
+
status: BridgeStatus;
|
|
88
|
+
fillTimeInSeconds?: number;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* A bridge deposit. It includes the provideer information, sell amount and the minimum buy amount.
|
|
92
|
+
*
|
|
93
|
+
* It models the minimal information for a bridging order.
|
|
94
|
+
*
|
|
95
|
+
*/
|
|
96
|
+
interface BridgeDeposit extends Omit<QuoteBridgeRequest, 'amount'> {
|
|
97
|
+
readonly provider: BridgeProviderInfo;
|
|
98
|
+
sellTokenAmount: string;
|
|
99
|
+
minBuyAmount: string;
|
|
100
|
+
}
|
|
101
|
+
interface BridgeProvider<Q extends BridgeQuoteResult> {
|
|
102
|
+
info: BridgeProviderInfo;
|
|
103
|
+
/**
|
|
104
|
+
* Get basic supported chains
|
|
105
|
+
*/
|
|
106
|
+
getNetworks(): Promise<ChainInfo[]>;
|
|
107
|
+
/**
|
|
108
|
+
* Get supported tokens for a chain
|
|
109
|
+
*/
|
|
110
|
+
getBuyTokens(targetChainId: TargetChainId): Promise<TokenInfo[]>;
|
|
111
|
+
/**
|
|
112
|
+
* Get intermediate tokens given a quote request.
|
|
113
|
+
*
|
|
114
|
+
* An intermediate token, is a token in the source chain, that could be used to bridge the tokens to the destination chain.
|
|
115
|
+
* This method returns a sorted list of tokens, they are sorted by priority, so first tokens are more likely to be more liquid.
|
|
116
|
+
*
|
|
117
|
+
* @param request - The quote request
|
|
118
|
+
*/
|
|
119
|
+
getIntermediateTokens(request: QuoteBridgeRequest): Promise<string[]>;
|
|
120
|
+
/**
|
|
121
|
+
* Get a quote for a bridge request.
|
|
122
|
+
*
|
|
123
|
+
* @param request - The quote request
|
|
124
|
+
*/
|
|
125
|
+
getQuote(request: QuoteBridgeRequest): Promise<Q>;
|
|
126
|
+
/**
|
|
127
|
+
* Get an unsigned bridge call for a quote.
|
|
128
|
+
*
|
|
129
|
+
* The transaction details should be executed in the context of cow-shed account.
|
|
130
|
+
*
|
|
131
|
+
* @param request - The quote request
|
|
132
|
+
* @param quote - The quote
|
|
133
|
+
* @returns The unsigned transaction details that cow-shed needs to sign
|
|
134
|
+
*/
|
|
135
|
+
getUnsignedBridgeCall(request: QuoteBridgeRequest, quote: Q): Promise<EvmCall>;
|
|
136
|
+
/**
|
|
137
|
+
* Returns the estimated gas cost for executing the bridge hook.
|
|
138
|
+
*
|
|
139
|
+
* This method helps calculate the final amount of tokens the user will receive more accurately.
|
|
140
|
+
* The estimation is done without the amount parameter to break a circular dependency:
|
|
141
|
+
* 1. Hook gas costs affect the final amount
|
|
142
|
+
* 2. The final amount could affect hook gas costs
|
|
143
|
+
*
|
|
144
|
+
* By estimating gas costs independently, we can resolve this dependency cycle.
|
|
145
|
+
*/
|
|
146
|
+
getGasLimitEstimationForHook(request: Omit<QuoteBridgeRequest, 'amount'>): number;
|
|
147
|
+
/**
|
|
148
|
+
* Get a pre-authorized hook for initiating a bridge.
|
|
149
|
+
*
|
|
150
|
+
* The hook contains the ethereum call that the trampoline contract will need to execute during the settlement to initate the bridge.
|
|
151
|
+
*
|
|
152
|
+
* Typically, this hook will:
|
|
153
|
+
* - Get the balance of cow-shed account
|
|
154
|
+
* - Ensure the approval for the bridge lock contract is set
|
|
155
|
+
* - Deposit into the bridge contract
|
|
156
|
+
*
|
|
157
|
+
* This hook will include the pre-authorization (signature) of the owner of the cow-shed account (the trader).
|
|
158
|
+
* The signer is optional, if not provided, the signer will be the trader's account from adapter.
|
|
159
|
+
*/
|
|
160
|
+
getSignedHook(chainId: SupportedChainId, unsignedCall: EvmCall, defaultGasLimit?: bigint, signer?: SignerLike): Promise<BridgeHook>;
|
|
161
|
+
/**
|
|
162
|
+
* Decode a bridge hook into a bridge deposit information.
|
|
163
|
+
*
|
|
164
|
+
* This method is used to recover the information about the limit order placed into the bridge locking contract.
|
|
165
|
+
* This allows to load an order from the orderbook and decode the bridging hook and understand what was the minimum buy amount the user signed to receive in the destination chain.
|
|
166
|
+
*
|
|
167
|
+
* @param hook - The bridge hook
|
|
168
|
+
*/
|
|
169
|
+
decodeBridgeHook(hook: latest.CoWHook): Promise<BridgeDeposit>;
|
|
170
|
+
/**
|
|
171
|
+
* Get the identifier of the bridging transaction from the settlement transaction.
|
|
172
|
+
* @param orderUid - The unique identifier of the order
|
|
173
|
+
* @param settlementTx - The settlement transaction in which the bridging post-hook was executed
|
|
174
|
+
* @param logIndex - The log index of the trade within the settlement transaction
|
|
175
|
+
*/
|
|
176
|
+
getBridgingId(orderUid: string, settlementTx: string, logIndex: number): Promise<string>;
|
|
177
|
+
/**
|
|
178
|
+
* Get the explorer url for a bridging id.
|
|
179
|
+
*
|
|
180
|
+
* @param bridgingId - The bridging id
|
|
181
|
+
*/
|
|
182
|
+
getExplorerUrl(bridgingId: string): string;
|
|
183
|
+
/**
|
|
184
|
+
* Get the status of a bridging transaction.
|
|
185
|
+
*
|
|
186
|
+
* @param bridgingId - The bridging id
|
|
187
|
+
*/
|
|
188
|
+
getStatus(bridgingId: string): Promise<BridgeStatusResult>;
|
|
189
|
+
getCancelBridgingTx(bridgingId: string): Promise<EvmCall>;
|
|
190
|
+
getRefundBridgingTx(bridgingId: string): Promise<EvmCall>;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* A quote and post for a cross-chain swap.
|
|
194
|
+
*
|
|
195
|
+
* If the order happens in a single chain, it returns the quote and post details for CoW Protocol.
|
|
196
|
+
* If the order happens in multiple chains, it returns the quote and post details for CoW Protocol, the bridging
|
|
197
|
+
* details, and a summary of the overall multi-step order.
|
|
198
|
+
*/
|
|
199
|
+
type CrossChainQuoteAndPost = QuoteAndPost | BridgeQuoteAndPost;
|
|
200
|
+
interface BridgeQuoteAndPost {
|
|
201
|
+
/**
|
|
202
|
+
* The quote results for the CoW Protocol order.
|
|
203
|
+
*/
|
|
204
|
+
swap: QuoteResults;
|
|
205
|
+
/**
|
|
206
|
+
* The quote results for the bridging.
|
|
207
|
+
*
|
|
208
|
+
* Includes the bridging details.
|
|
209
|
+
*/
|
|
210
|
+
bridge: BridgeQuoteResults;
|
|
211
|
+
/**
|
|
212
|
+
* Callback to post the swap order.
|
|
213
|
+
*/
|
|
214
|
+
postSwapOrderFromQuote(advancedSettings?: SwapAdvancedSettings): Promise<OrderPostingResult>;
|
|
215
|
+
}
|
|
216
|
+
interface BridgeCosts<T = bigint> {
|
|
217
|
+
bridgingFee: {
|
|
218
|
+
feeBps: number;
|
|
219
|
+
amountInSellCurrency: T;
|
|
220
|
+
amountInBuyCurrency: T;
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
interface BridgeQuoteAmountsAndCosts<T = bigint> {
|
|
224
|
+
/**
|
|
225
|
+
* Costs of the bridging.
|
|
226
|
+
*/
|
|
227
|
+
costs: BridgeCosts<T>;
|
|
228
|
+
/**
|
|
229
|
+
* Amounts before fees
|
|
230
|
+
*/
|
|
231
|
+
beforeFee: Amounts<T>;
|
|
232
|
+
/**
|
|
233
|
+
* Amounts after fees.
|
|
234
|
+
*/
|
|
235
|
+
afterFee: Amounts<T>;
|
|
236
|
+
/**
|
|
237
|
+
* Amounts after slippage tolerance.
|
|
238
|
+
*
|
|
239
|
+
* It includes the fees and the slippage tolerance, so its the minimum amount that the user will receive.
|
|
240
|
+
*/
|
|
241
|
+
afterSlippage: Amounts<T>;
|
|
242
|
+
/**
|
|
243
|
+
* The slippage tolerance in basis points.
|
|
244
|
+
*/
|
|
245
|
+
slippageBps: number;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Details about the bridge call.
|
|
249
|
+
*/
|
|
250
|
+
interface BridgeCallDetails {
|
|
251
|
+
/**
|
|
252
|
+
* Unsigned call to initiate the bridge. This call should be executed in the context of user's cow-shed account.
|
|
253
|
+
*/
|
|
254
|
+
unsignedBridgeCall: EvmCall;
|
|
255
|
+
/**
|
|
256
|
+
* Pre-authorized hook to initiate the bridge. This hook has been signed, and is ready to be executed by the
|
|
257
|
+
* CoW Protocol Trampoline contract after settling the swap order that buys the intermediate token.
|
|
258
|
+
*/
|
|
259
|
+
preAuthorizedBridgingHook: BridgeHook;
|
|
260
|
+
}
|
|
261
|
+
interface BridgeQuoteResults extends BridgeQuoteResult {
|
|
262
|
+
/**
|
|
263
|
+
* Bridge provider information
|
|
264
|
+
*/
|
|
265
|
+
providerInfo: BridgeProviderInfo;
|
|
266
|
+
/**
|
|
267
|
+
* Trade parameters
|
|
268
|
+
*/
|
|
269
|
+
tradeParameters: QuoteBridgeRequest;
|
|
270
|
+
/**
|
|
271
|
+
* Bridge call details
|
|
272
|
+
*/
|
|
273
|
+
bridgeCallDetails: BridgeCallDetails;
|
|
274
|
+
}
|
|
275
|
+
type GetErc20Decimals = (chainId: TargetChainId, tokenAddress: string) => Promise<number>;
|
|
276
|
+
interface CrossChainOrder {
|
|
277
|
+
chainId: SupportedChainId;
|
|
278
|
+
order: EnrichedOrder;
|
|
279
|
+
status: BridgeStatus;
|
|
280
|
+
bridgingId?: string;
|
|
281
|
+
explorerUrl?: string;
|
|
282
|
+
fillTimeInSeconds?: number;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
declare class BridgeProviderQuoteError extends Error {
|
|
286
|
+
readonly context: unknown;
|
|
287
|
+
constructor(message: string, context: unknown);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
declare function isBridgeQuoteAndPost(quote: CrossChainQuoteAndPost): quote is BridgeQuoteAndPost;
|
|
291
|
+
declare function isQuoteAndPost(quote: CrossChainQuoteAndPost): quote is QuoteAndPost;
|
|
292
|
+
declare function assertIsBridgeQuoteAndPost(quote: CrossChainQuoteAndPost): asserts quote is BridgeQuoteAndPost;
|
|
293
|
+
declare function assertIsQuoteAndPost(quote: CrossChainQuoteAndPost): asserts quote is QuoteAndPost;
|
|
294
|
+
declare function getPostHooks(fullAppData?: string): latest.CoWHook[];
|
|
295
|
+
declare function isAppDoc(appData: unknown): appData is latest.AppDataRootSchema;
|
|
296
|
+
|
|
297
|
+
declare function getHookMockForCostEstimation(gasLimit: number): latest.CoWHook;
|
|
298
|
+
declare function areHooksEqual(hookA: latest.CoWHook, hookB: latest.CoWHook): boolean;
|
|
299
|
+
|
|
300
|
+
interface BridgingSdkOptions {
|
|
301
|
+
/**
|
|
302
|
+
* Providers for the bridging.
|
|
303
|
+
*/
|
|
304
|
+
providers: BridgeProvider<BridgeQuoteResult>[];
|
|
305
|
+
/**
|
|
306
|
+
* Function to get the decimals of the ERC20 tokens
|
|
307
|
+
*/
|
|
308
|
+
getErc20Decimals?: GetErc20Decimals;
|
|
309
|
+
/**
|
|
310
|
+
* Trading SDK.
|
|
311
|
+
*/
|
|
312
|
+
tradingSdk?: TradingSdk;
|
|
313
|
+
/**
|
|
314
|
+
* Order book API.
|
|
315
|
+
*/
|
|
316
|
+
orderBookApi?: OrderBookApi;
|
|
317
|
+
/**
|
|
318
|
+
* Enable logging for the bridging SDK.
|
|
319
|
+
*/
|
|
320
|
+
enableLogging?: boolean;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Parameters for the `getOrder` method.
|
|
324
|
+
*/
|
|
325
|
+
interface GetOrderParams {
|
|
326
|
+
/**
|
|
327
|
+
* The unique identifier of the order.
|
|
328
|
+
*/
|
|
329
|
+
orderId: string;
|
|
330
|
+
/**
|
|
331
|
+
* The chain ID of the order.
|
|
332
|
+
*/
|
|
333
|
+
chainId: SupportedChainId;
|
|
334
|
+
/**
|
|
335
|
+
* The environment of the order
|
|
336
|
+
*/
|
|
337
|
+
env?: CowEnv;
|
|
338
|
+
}
|
|
339
|
+
type BridgingSdkConfig = Required<Omit<BridgingSdkOptions, 'enableLogging' | 'getErc20Decimals'>> & Pick<BridgingSdkOptions, 'getErc20Decimals'>;
|
|
340
|
+
/**
|
|
341
|
+
* SDK for bridging for swapping tokens between different chains.
|
|
342
|
+
*/
|
|
343
|
+
declare class BridgingSdk {
|
|
344
|
+
readonly options: BridgingSdkOptions;
|
|
345
|
+
protected config: BridgingSdkConfig;
|
|
346
|
+
constructor(options: BridgingSdkOptions, adapter?: AbstractProviderAdapter);
|
|
347
|
+
private get provider();
|
|
348
|
+
/**
|
|
349
|
+
* Get the providers for the bridging.
|
|
350
|
+
*/
|
|
351
|
+
getProviders(): BridgeProvider<BridgeQuoteResult>[];
|
|
352
|
+
/**
|
|
353
|
+
* Get the available sources networks for the bridging.
|
|
354
|
+
*/
|
|
355
|
+
getSourceNetworks(): Promise<ChainInfo[]>;
|
|
356
|
+
/**
|
|
357
|
+
* Get the available target networks for the bridging.
|
|
358
|
+
*/
|
|
359
|
+
getTargetNetworks(): Promise<ChainInfo[]>;
|
|
360
|
+
/**
|
|
361
|
+
* Get the available buy tokens for buying in a specific target chain
|
|
362
|
+
*
|
|
363
|
+
* @param param
|
|
364
|
+
* @returns
|
|
365
|
+
*/
|
|
366
|
+
getBuyTokens(targetChainId: TargetChainId): Promise<TokenInfo[]>;
|
|
367
|
+
/**
|
|
368
|
+
* Get quote details, including a callback function to post the order on-chain.
|
|
369
|
+
*
|
|
370
|
+
* This method support both, cross-chain swaps and single-chain swap.
|
|
371
|
+
*
|
|
372
|
+
* The return type will be either `QuoteAndPost` or `BridgeQuoteAndPost`.
|
|
373
|
+
*
|
|
374
|
+
* To safely assert the type in Typescript, you can use:
|
|
375
|
+
* - `isBridgeQuoteAndPost(result)` utility.
|
|
376
|
+
* - `isQuoteAndPost(result)` utility.
|
|
377
|
+
* - `assertIsBridgeQuoteAndPost(result)` assertion.
|
|
378
|
+
* - `assertIsQuoteAndPost(result)` assertion.
|
|
379
|
+
*
|
|
380
|
+
* @throws Error if no path is found
|
|
381
|
+
*/
|
|
382
|
+
getQuote(quoteBridgeRequest: QuoteBridgeRequest, advancedSettings?: SwapAdvancedSettings): Promise<CrossChainQuoteAndPost>;
|
|
383
|
+
getOrder(params: GetOrderParams): Promise<CrossChainOrder>;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
declare class MockBridgeProvider implements BridgeProvider<BridgeQuoteResult> {
|
|
387
|
+
info: BridgeProviderInfo;
|
|
388
|
+
getNetworks(): Promise<ChainInfo[]>;
|
|
389
|
+
getBuyTokens(targetChainId: TargetChainId): Promise<TokenInfo[]>;
|
|
390
|
+
getIntermediateTokens({ sellTokenChainId }: QuoteBridgeRequest): Promise<string[]>;
|
|
391
|
+
getQuote(_request: QuoteBridgeRequest): Promise<BridgeQuoteResult>;
|
|
392
|
+
getGasLimitEstimationForHook(_request: QuoteBridgeRequest): number;
|
|
393
|
+
getUnsignedBridgeCall(_request: QuoteBridgeRequest, _quote: BridgeQuoteResult): Promise<EvmCall>;
|
|
394
|
+
getSignedHook(_chainId: SupportedChainId, _unsignedCall: EvmCall, _signer: Signer): Promise<BridgeHook>;
|
|
395
|
+
decodeBridgeHook(_hook: latest.CoWHook): Promise<BridgeDeposit>;
|
|
396
|
+
getBridgingId(_orderUid: string, _settlementTx: string, _logIndex: number): Promise<string>;
|
|
397
|
+
getExplorerUrl(bridgingId: string): string;
|
|
398
|
+
getStatus(_bridgingId: string): Promise<BridgeStatusResult>;
|
|
399
|
+
getCancelBridgingTx(_bridgingId: string): Promise<EvmCall>;
|
|
400
|
+
getRefundBridgingTx(_bridgingId: string): Promise<EvmCall>;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
interface AvailableRoutesRequest {
|
|
404
|
+
originChainId: string;
|
|
405
|
+
originToken: string;
|
|
406
|
+
destinationChainId: string;
|
|
407
|
+
destinationToken: string;
|
|
408
|
+
}
|
|
409
|
+
interface Route {
|
|
410
|
+
originChainId: string;
|
|
411
|
+
originToken: string;
|
|
412
|
+
destinationChainId: string;
|
|
413
|
+
destinationToken: string;
|
|
414
|
+
originTokenSymbol: string;
|
|
415
|
+
destinationTokenSymbol: string;
|
|
416
|
+
}
|
|
417
|
+
interface SuggestedFeesRequest {
|
|
418
|
+
token: string;
|
|
419
|
+
originChainId: TargetChainId;
|
|
420
|
+
destinationChainId: TargetChainId;
|
|
421
|
+
/**
|
|
422
|
+
* Amount of the token to transfer.
|
|
423
|
+
*
|
|
424
|
+
* Note that this amount is in the native decimals of the token. So, for WETH, this would be the amount of
|
|
425
|
+
* human-readable WETH multiplied by 1e18.
|
|
426
|
+
*
|
|
427
|
+
* For USDC, you would multiply the number of human-readable USDC by 1e6.
|
|
428
|
+
*
|
|
429
|
+
* Example: 1000000000000000000
|
|
430
|
+
*/
|
|
431
|
+
amount: bigint;
|
|
432
|
+
/**
|
|
433
|
+
* Recipient of the deposit. Can be an EOA or a contract. If this is an EOA and message is defined, then the API will throw a 4xx error.
|
|
434
|
+
*
|
|
435
|
+
* Example: 0xc186fA914353c44b2E33eBE05f21846F1048bEda
|
|
436
|
+
*/
|
|
437
|
+
recipient?: string;
|
|
438
|
+
/**
|
|
439
|
+
* The quote timestamp used to compute the LP fees. When bridging with across, the user only specifies the quote
|
|
440
|
+
* timestamp in their transaction. The relayer then determines the utilization at that timestamp to determine the
|
|
441
|
+
* user's fee. This timestamp must be close (within 10 minutes or so) to the current time on the chain where the
|
|
442
|
+
* user is depositing funds and it should be <= the current block timestamp on mainnet. This allows the user to know
|
|
443
|
+
* exactly what LP fee they will pay before sending the transaction.
|
|
444
|
+
*
|
|
445
|
+
* If this value isn't provided in the request, the API will assume the latest block timestamp on mainnet.
|
|
446
|
+
*
|
|
447
|
+
* Example: 1653547649
|
|
448
|
+
*/
|
|
449
|
+
timestamp?: number;
|
|
450
|
+
/**
|
|
451
|
+
* Optionally override the relayer address used to simulate the fillRelay() call that estimates the gas costs
|
|
452
|
+
* needed to fill a deposit. This simulation result impacts the returned suggested-fees. The reason to customize the
|
|
453
|
+
* EOA would be primarily if the recipientAddress is a contract and requires a certain relayer to submit the fill,
|
|
454
|
+
* or if one specific relayer has the necessary token balance to make the fill.
|
|
455
|
+
*
|
|
456
|
+
* Example: 0x428AB2BA90Eba0a4Be7aF34C9Ac451ab061AC010
|
|
457
|
+
*/
|
|
458
|
+
relayer?: string;
|
|
459
|
+
}
|
|
460
|
+
interface SuggestedFeesLimits {
|
|
461
|
+
/**
|
|
462
|
+
* The minimum deposit size in the tokens' units.
|
|
463
|
+
*
|
|
464
|
+
* Note: USDC has 6 decimals, so this value would be the number of USDC multiplied by 1e6. For WETH, that would be 1e18.
|
|
465
|
+
*/
|
|
466
|
+
minDeposit: string;
|
|
467
|
+
/**
|
|
468
|
+
* The maximum deposit size in the tokens' units. Note: The formatting of this number is the same as minDeposit.
|
|
469
|
+
*/
|
|
470
|
+
maxDeposit: string;
|
|
471
|
+
/**
|
|
472
|
+
* The max deposit size that can be relayed "instantly" on the destination chain.
|
|
473
|
+
*
|
|
474
|
+
* Instantly means that there is relayer capital readily available and that a relayer is expected to relay within
|
|
475
|
+
* seconds to 5 minutes of the deposit.
|
|
476
|
+
*/
|
|
477
|
+
maxDepositInstant: string;
|
|
478
|
+
/**
|
|
479
|
+
* The max deposit size that can be relayed with a "short delay" on the destination chain.
|
|
480
|
+
*
|
|
481
|
+
* This means that there is relayer capital available on mainnet and that a relayer will immediately begin moving
|
|
482
|
+
* that capital over the canonical bridge to relay the deposit. Depending on the chain, the time for this can vary.
|
|
483
|
+
*
|
|
484
|
+
* Polygon is the worst case where it can take between 20 and 35 minutes for the relayer to receive the funds
|
|
485
|
+
* and relay.
|
|
486
|
+
*
|
|
487
|
+
* Arbitrum is much faster, with a range between 5 and 15 minutes. Note: if the transfer size is greater than this,
|
|
488
|
+
* the estimate should be between 2-4 hours for a slow relay to be processed from the mainnet pool.
|
|
489
|
+
*/
|
|
490
|
+
maxDepositShortDelay: string;
|
|
491
|
+
/**
|
|
492
|
+
* The recommended deposit size that can be relayed "instantly" on the destination chain.
|
|
493
|
+
*
|
|
494
|
+
* Instantly means that there is relayer capital readily available and that a relayer is expected to relay
|
|
495
|
+
* within seconds to 5 minutes of the deposit. Value is in the smallest unit of the respective token.
|
|
496
|
+
*/
|
|
497
|
+
recommendedDepositInstant: string;
|
|
498
|
+
}
|
|
499
|
+
interface SuggestedFeesResponse {
|
|
500
|
+
/**
|
|
501
|
+
* Percentage of the transfer amount that should go to the relayer as a fee in total. The value is inclusive of lpFee.pct.
|
|
502
|
+
*
|
|
503
|
+
* This is the strongly recommended minimum value to ensure a relayer will perform the transfer under the current
|
|
504
|
+
* network conditions.
|
|
505
|
+
*
|
|
506
|
+
* The value returned in this field is guaranteed to be at least 0.03% in order to meet minimum relayer fee requirements
|
|
507
|
+
*/
|
|
508
|
+
totalRelayFee: PctFee;
|
|
509
|
+
/**
|
|
510
|
+
* The percentage of the transfer amount that should go the relayer as a fee to cover relayer capital costs.
|
|
511
|
+
*/
|
|
512
|
+
relayerCapitalFee: PctFee;
|
|
513
|
+
/**
|
|
514
|
+
* The percentage of the transfer amount that should go the relayer as a fee to cover relayer gas costs.
|
|
515
|
+
*/
|
|
516
|
+
relayerGasFee: PctFee;
|
|
517
|
+
/**
|
|
518
|
+
* The percent of the amount that will go to the LPs as a fee for borrowing their funds.
|
|
519
|
+
*/
|
|
520
|
+
lpFee: PctFee;
|
|
521
|
+
/**
|
|
522
|
+
* The quote timestamp that was used to compute the lpFeePct. To pay the quoted LP fee, the user would need to pass
|
|
523
|
+
* this quote timestamp to the protocol when sending their bridge transaction.
|
|
524
|
+
*/
|
|
525
|
+
timestamp: string;
|
|
526
|
+
/**
|
|
527
|
+
* Is the input amount below the minimum transfer amount.
|
|
528
|
+
*/
|
|
529
|
+
isAmountTooLow: boolean;
|
|
530
|
+
/**
|
|
531
|
+
* The block used associated with this quote, used to compute lpFeePct.
|
|
532
|
+
*/
|
|
533
|
+
quoteBlock: string;
|
|
534
|
+
/**
|
|
535
|
+
* The contract address of the origin SpokePool.
|
|
536
|
+
*/
|
|
537
|
+
spokePoolAddress: string;
|
|
538
|
+
/**
|
|
539
|
+
* The relayer that is suggested to be set as the exclusive relayer for in the depositV3 call for the fastest fill.
|
|
540
|
+
*
|
|
541
|
+
* Note: when set to "0x0000000000000000000000000000000000000000", relayer exclusivity will be disabled.
|
|
542
|
+
* This value is returned in cases where using an exclusive relayer is not recommended.
|
|
543
|
+
*/
|
|
544
|
+
exclusiveRelayer: string;
|
|
545
|
+
/**
|
|
546
|
+
* The suggested exclusivity period (in seconds) the exclusive relayer should be given to fill before other relayers
|
|
547
|
+
* are allowed to take the fill. Note: when set to "0", relayer exclusivity will be disabled.
|
|
548
|
+
*
|
|
549
|
+
* This value is returned in cases where using an exclusive relayer is not recommended.
|
|
550
|
+
*/
|
|
551
|
+
exclusivityDeadline: string;
|
|
552
|
+
/**
|
|
553
|
+
* The expected time (in seconds) for a fill to be made. Represents 75th percentile of the 7-day rolling average of times (updated daily). Times are dynamic by origin/destination token/chain for a given amount.
|
|
554
|
+
*/
|
|
555
|
+
estimatedFillTimeSec: string;
|
|
556
|
+
/**
|
|
557
|
+
* The recommended deadline (UNIX timestamp in seconds) for the relayer to fill the deposit. After this destination chain timestamp, the fill will revert on the destination chain.
|
|
558
|
+
*/
|
|
559
|
+
fillDeadline: string;
|
|
560
|
+
limits: SuggestedFeesLimits;
|
|
561
|
+
}
|
|
562
|
+
interface PctFee {
|
|
563
|
+
/**
|
|
564
|
+
* Note: 1% is represented as 1e16, 100% is 1e18, 50% is 5e17, etc. These values are in the same format that the contract understands.
|
|
565
|
+
*
|
|
566
|
+
* Example: 100200000000000
|
|
567
|
+
*/
|
|
568
|
+
pct: string;
|
|
569
|
+
total: string;
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
interface AcrossApiOptions {
|
|
573
|
+
apiBaseUrl?: string;
|
|
574
|
+
}
|
|
575
|
+
declare class AcrossApi {
|
|
576
|
+
private readonly options;
|
|
577
|
+
constructor(options?: AcrossApiOptions);
|
|
578
|
+
/**
|
|
579
|
+
* Retrieve available routes for transfers
|
|
580
|
+
*
|
|
581
|
+
* Returns available routes based on specified parameters. If no parameters are provided, available routes on all
|
|
582
|
+
* chains are returned.
|
|
583
|
+
*
|
|
584
|
+
* See https://docs.across.to/reference/api-reference#available-routes
|
|
585
|
+
*/
|
|
586
|
+
getAvailableRoutes({ originChainId, originToken, destinationChainId, destinationToken, }: AvailableRoutesRequest): Promise<Route[]>;
|
|
587
|
+
/**
|
|
588
|
+
* Retrieve suggested fee quote for a deposit.
|
|
589
|
+
*
|
|
590
|
+
* Returns suggested fees based inputToken+outputToken, originChainId, destinationChainId, and amount.
|
|
591
|
+
* Also includes data used to compute the fees.
|
|
592
|
+
*
|
|
593
|
+
* * See https://docs.across.to/reference/api-reference#suggested-fees
|
|
594
|
+
*/
|
|
595
|
+
getSuggestedFees(request: SuggestedFeesRequest): Promise<SuggestedFeesResponse>;
|
|
596
|
+
protected fetchApi<T>(path: string, params: Record<string, string>, isValidResponse?: (response: unknown) => response is T): Promise<T>;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
interface AcrossBridgeProviderOptions {
|
|
600
|
+
/**
|
|
601
|
+
* Token info provider
|
|
602
|
+
* @param chainId - The chain ID
|
|
603
|
+
* @param addresses - The addresses of the tokens to get the info for
|
|
604
|
+
* @returns The token infos
|
|
605
|
+
*/
|
|
606
|
+
getTokenInfos?: (chainId: ChainId, addresses: string[]) => Promise<TokenInfo[]>;
|
|
607
|
+
apiOptions?: AcrossApiOptions;
|
|
608
|
+
cowShedOptions?: CowShedSdkOptions;
|
|
609
|
+
}
|
|
610
|
+
interface AcrossQuoteResult extends BridgeQuoteResult {
|
|
611
|
+
suggestedFees: SuggestedFeesResponse;
|
|
612
|
+
}
|
|
613
|
+
declare class AcrossBridgeProvider implements BridgeProvider<AcrossQuoteResult> {
|
|
614
|
+
private options;
|
|
615
|
+
protected api: AcrossApi;
|
|
616
|
+
protected cowShedSdk: CowShedSdk;
|
|
617
|
+
constructor(options?: AcrossBridgeProviderOptions, adapter?: AbstractProviderAdapter);
|
|
618
|
+
info: BridgeProviderInfo;
|
|
619
|
+
getNetworks(): Promise<ChainInfo[]>;
|
|
620
|
+
getBuyTokens(targetChainId: TargetChainId): Promise<TokenInfo[]>;
|
|
621
|
+
getIntermediateTokens(request: QuoteBridgeRequest): Promise<string[]>;
|
|
622
|
+
getQuote(request: QuoteBridgeRequest): Promise<AcrossQuoteResult>;
|
|
623
|
+
getUnsignedBridgeCall(request: QuoteBridgeRequest, quote: AcrossQuoteResult): Promise<EvmCall>;
|
|
624
|
+
getGasLimitEstimationForHook(_request: QuoteBridgeRequest): number;
|
|
625
|
+
getSignedHook(chainId: SupportedChainId, unsignedCall: EvmCall, defaultGasLimit?: bigint, signer?: SignerLike): Promise<BridgeHook>;
|
|
626
|
+
decodeBridgeHook(_hook: latest.CoWHook): Promise<BridgeDeposit>;
|
|
627
|
+
getBridgingId(_orderUid: string, _settlementTx: string, _logIndex: number): Promise<string>;
|
|
628
|
+
getExplorerUrl(bridgingId: string): string;
|
|
629
|
+
getStatus(_bridgingId: string): Promise<BridgeStatusResult>;
|
|
630
|
+
getCancelBridgingTx(_bridgingId: string): Promise<EvmCall>;
|
|
631
|
+
getRefundBridgingTx(_bridgingId: string): Promise<EvmCall>;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
export { AcrossBridgeProvider, type AcrossBridgeProviderOptions, type AcrossQuoteResult, type BridgeCallDetails, type BridgeCosts, type BridgeDeposit, type BridgeHook, type BridgeProvider, type BridgeProviderInfo, BridgeProviderQuoteError, type BridgeQuoteAmountsAndCosts, type BridgeQuoteAndPost, type BridgeQuoteResult, type BridgeQuoteResults, BridgeStatus, type BridgeStatusResult, BridgingSdk, type BridgingSdkConfig, type BridgingSdkOptions, type CrossChainOrder, type CrossChainQuoteAndPost, type GetErc20Decimals, type GetOrderParams, MockBridgeProvider, type QuoteBridgeRequest, type QuoteBridgeRequestWithoutAmount, areHooksEqual, assertIsBridgeQuoteAndPost, assertIsQuoteAndPost, getHookMockForCostEstimation, getPostHooks, isAppDoc, isBridgeQuoteAndPost, isQuoteAndPost };
|