@cowprotocol/sdk-bridging 0.4.6 → 0.5.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/dist/index.d.mts +66 -30
- package/dist/index.d.ts +66 -30
- package/dist/index.js +315 -162
- package/dist/index.mjs +307 -156
- package/package.json +14 -14
package/dist/index.js
CHANGED
|
@@ -40,7 +40,9 @@ __export(src_exports, {
|
|
|
40
40
|
getPostHooks: () => getPostHooks,
|
|
41
41
|
isAppDoc: () => isAppDoc,
|
|
42
42
|
isBridgeQuoteAndPost: () => isBridgeQuoteAndPost,
|
|
43
|
-
|
|
43
|
+
isHookBridgeProvider: () => isHookBridgeProvider,
|
|
44
|
+
isQuoteAndPost: () => isQuoteAndPost,
|
|
45
|
+
isReceiverAccountBridgeProvider: () => isReceiverAccountBridgeProvider
|
|
44
46
|
});
|
|
45
47
|
module.exports = __toCommonJS(src_exports);
|
|
46
48
|
|
|
@@ -121,6 +123,12 @@ function getPostHooks(fullAppData) {
|
|
|
121
123
|
function isAppDoc(appData) {
|
|
122
124
|
return typeof appData === "object" && appData !== null && "version" in appData && "metadata" in appData;
|
|
123
125
|
}
|
|
126
|
+
function isHookBridgeProvider(provider) {
|
|
127
|
+
return provider.type === "HookBridgeProvider";
|
|
128
|
+
}
|
|
129
|
+
function isReceiverAccountBridgeProvider(provider) {
|
|
130
|
+
return provider.type === "ReceiverAccountBridgeProvider";
|
|
131
|
+
}
|
|
124
132
|
|
|
125
133
|
// src/const.ts
|
|
126
134
|
var import_sdk_config = require("@cowprotocol/sdk-config");
|
|
@@ -197,7 +205,7 @@ async function getCrossChainOrder(params) {
|
|
|
197
205
|
var import_sdk_trading2 = require("@cowprotocol/sdk-trading");
|
|
198
206
|
var import_sdk_order_book2 = require("@cowprotocol/sdk-order-book");
|
|
199
207
|
var import_sdk_config2 = require("@cowprotocol/sdk-config");
|
|
200
|
-
var
|
|
208
|
+
var import_sdk_common5 = require("@cowprotocol/sdk-common");
|
|
201
209
|
|
|
202
210
|
// src/BridgingSdk/helpers.ts
|
|
203
211
|
var getCacheKey = ({
|
|
@@ -228,12 +236,12 @@ function getQuoteWithoutBridge(params) {
|
|
|
228
236
|
|
|
229
237
|
// src/BridgingSdk/getQuoteWithBridge.ts
|
|
230
238
|
var import_sdk_trading = require("@cowprotocol/sdk-trading");
|
|
231
|
-
var
|
|
239
|
+
var import_sdk_common4 = require("@cowprotocol/sdk-common");
|
|
232
240
|
var import_sdk_order_book = require("@cowprotocol/sdk-order-book");
|
|
233
241
|
|
|
234
242
|
// src/BridgingSdk/getBridgeSignedHook.ts
|
|
235
243
|
var import_sdk_common2 = require("@cowprotocol/sdk-common");
|
|
236
|
-
async function getBridgeSignedHook(bridgeRequest, {
|
|
244
|
+
async function getBridgeSignedHook(provider, bridgeRequest, { signer, hookGasLimit, swapResult, validToOverride }) {
|
|
237
245
|
const adapter = (0, import_sdk_common2.getGlobalAdapter)();
|
|
238
246
|
const bridgingQuote = await provider.getQuote(bridgeRequest);
|
|
239
247
|
const unsignedBridgeCall = await provider.getUnsignedBridgeCall(bridgeRequest, bridgingQuote);
|
|
@@ -267,9 +275,14 @@ function getHookMockForCostEstimation(gasLimit) {
|
|
|
267
275
|
};
|
|
268
276
|
}
|
|
269
277
|
|
|
270
|
-
// src/BridgingSdk/
|
|
271
|
-
|
|
272
|
-
|
|
278
|
+
// src/BridgingSdk/getIntermediateSwapResult.ts
|
|
279
|
+
var import_sdk_common3 = require("@cowprotocol/sdk-common");
|
|
280
|
+
async function getIntermediateSwapResult({
|
|
281
|
+
provider,
|
|
282
|
+
params,
|
|
283
|
+
getBridgeHook
|
|
284
|
+
}) {
|
|
285
|
+
const { swapAndBridgeRequest, advancedSettings, tradingSdk } = params;
|
|
273
286
|
const {
|
|
274
287
|
kind,
|
|
275
288
|
sellTokenChainId,
|
|
@@ -277,25 +290,101 @@ async function getQuoteWithBridge(params) {
|
|
|
277
290
|
buyTokenChainId,
|
|
278
291
|
buyTokenAddress,
|
|
279
292
|
amount,
|
|
280
|
-
signer: signerLike
|
|
281
|
-
...rest
|
|
293
|
+
signer: signerLike
|
|
282
294
|
} = swapAndBridgeRequest;
|
|
283
295
|
const adapter = (0, import_sdk_common3.getGlobalAdapter)();
|
|
284
296
|
const signer = signerLike ? adapter.createSigner(signerLike) : adapter.signer;
|
|
285
|
-
if (kind !== import_sdk_order_book.OrderKind.SELL) {
|
|
286
|
-
throw new Error("Bridging only support SELL orders");
|
|
287
|
-
}
|
|
288
297
|
(0, import_sdk_common3.log)(
|
|
289
298
|
`Cross-chain ${kind} ${amount} ${sellTokenAddress} (source chain ${sellTokenChainId}) for ${buyTokenAddress} (target chain ${buyTokenChainId})`
|
|
290
299
|
);
|
|
291
|
-
const
|
|
292
|
-
swapAndBridgeRequest,
|
|
300
|
+
const intermediateTokens = await getIntermediateTokens({
|
|
293
301
|
provider,
|
|
302
|
+
quoteBridgeRequest: swapAndBridgeRequest,
|
|
294
303
|
intermediateTokensCache: params.intermediateTokensCache
|
|
295
304
|
});
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
(
|
|
305
|
+
const intermediateToken = intermediateTokens[0];
|
|
306
|
+
(0, import_sdk_common3.log)(`Using ${intermediateToken?.name ?? intermediateToken?.address} as intermediate tokens`);
|
|
307
|
+
if (!intermediateToken) {
|
|
308
|
+
throw new BridgeProviderQuoteError("NO_INTERMEDIATE_TOKENS" /* NO_INTERMEDIATE_TOKENS */, { intermediateTokens });
|
|
309
|
+
}
|
|
310
|
+
const bridgeRequestWithoutAmount = {
|
|
311
|
+
...swapAndBridgeRequest,
|
|
312
|
+
sellTokenAddress: intermediateToken.address,
|
|
313
|
+
sellTokenDecimals: intermediateToken.decimals
|
|
314
|
+
};
|
|
315
|
+
const { sellTokenDecimals: intermediaryTokenDecimals } = bridgeRequestWithoutAmount;
|
|
316
|
+
const bridgeHook = getBridgeHook ? await getBridgeHook(bridgeRequestWithoutAmount) : void 0;
|
|
317
|
+
const advancedSettingsHooks = advancedSettings?.appData?.metadata?.hooks;
|
|
318
|
+
const hooks = bridgeHook ? {
|
|
319
|
+
pre: advancedSettingsHooks?.pre,
|
|
320
|
+
post: [...advancedSettingsHooks?.post || [], bridgeHook]
|
|
321
|
+
} : advancedSettingsHooks;
|
|
322
|
+
const finalAdvancedSettings = {
|
|
323
|
+
...advancedSettings,
|
|
324
|
+
appData: {
|
|
325
|
+
...advancedSettings?.appData,
|
|
326
|
+
metadata: {
|
|
327
|
+
hooks,
|
|
328
|
+
bridging: {
|
|
329
|
+
destinationChainId: buyTokenChainId.toString(),
|
|
330
|
+
destinationTokenAddress: buyTokenAddress
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
const { swapResult, orderBookApi } = await getSwapQuote({
|
|
336
|
+
swapAndBridgeRequest,
|
|
337
|
+
bridgeRequestWithoutAmount,
|
|
338
|
+
tradingSdk,
|
|
339
|
+
advancedSettings: finalAdvancedSettings,
|
|
340
|
+
signer
|
|
341
|
+
});
|
|
342
|
+
const intermediateTokenAmount = swapResult.amountsAndCosts.afterSlippage.buyAmount;
|
|
343
|
+
(0, import_sdk_common3.log)(
|
|
344
|
+
`Expected to receive ${intermediateTokenAmount} of the intermediate token (${(intermediateTokenAmount / 10n ** BigInt(intermediaryTokenDecimals)).toString()} formatted)`
|
|
345
|
+
);
|
|
346
|
+
return {
|
|
347
|
+
swapAndBridgeRequest,
|
|
348
|
+
signer,
|
|
349
|
+
bridgeRequestWithoutAmount,
|
|
350
|
+
intermediateTokenAmount,
|
|
351
|
+
intermediaryTokenDecimals,
|
|
352
|
+
swapResult,
|
|
353
|
+
orderBookApi
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
async function getIntermediateTokens(params) {
|
|
357
|
+
const { provider, quoteBridgeRequest, intermediateTokensCache } = params;
|
|
358
|
+
let intermediateTokens = [];
|
|
359
|
+
const cacheKey = getCacheKey({
|
|
360
|
+
id: provider.info.dappId,
|
|
361
|
+
buyChainId: quoteBridgeRequest.buyTokenChainId.toString(),
|
|
362
|
+
sellChainId: quoteBridgeRequest.sellTokenChainId.toString(),
|
|
363
|
+
tokenAddress: quoteBridgeRequest.buyTokenAddress
|
|
364
|
+
});
|
|
365
|
+
const cached = intermediateTokensCache?.get(cacheKey);
|
|
366
|
+
if (cached) {
|
|
367
|
+
intermediateTokens = cached;
|
|
368
|
+
} else {
|
|
369
|
+
intermediateTokens = await provider.getIntermediateTokens(quoteBridgeRequest);
|
|
370
|
+
intermediateTokensCache?.set(cacheKey, intermediateTokens);
|
|
371
|
+
}
|
|
372
|
+
if (intermediateTokens.length === 0) {
|
|
373
|
+
throw new BridgeProviderQuoteError("NO_INTERMEDIATE_TOKENS" /* NO_INTERMEDIATE_TOKENS */);
|
|
374
|
+
}
|
|
375
|
+
return intermediateTokens;
|
|
376
|
+
}
|
|
377
|
+
async function getSwapQuote(params) {
|
|
378
|
+
const { swapAndBridgeRequest, bridgeRequestWithoutAmount, tradingSdk, advancedSettings, signer } = params;
|
|
379
|
+
const {
|
|
380
|
+
kind,
|
|
381
|
+
sellTokenChainId,
|
|
382
|
+
sellTokenAddress,
|
|
383
|
+
buyTokenChainId: _buyTokenChainId,
|
|
384
|
+
buyTokenAddress: _buyTokenAddress,
|
|
385
|
+
amount,
|
|
386
|
+
...rest
|
|
387
|
+
} = swapAndBridgeRequest;
|
|
299
388
|
const { sellTokenAddress: intermediateToken, sellTokenDecimals: intermediaryTokenDecimals } = bridgeRequestWithoutAmount;
|
|
300
389
|
const swapParams = {
|
|
301
390
|
...rest,
|
|
@@ -314,52 +403,149 @@ async function getQuoteWithBridge(params) {
|
|
|
314
403
|
import_sdk_common3.jsonWithBigintReplacer
|
|
315
404
|
)}`
|
|
316
405
|
);
|
|
317
|
-
const
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
406
|
+
const { result: swapResult, orderBookApi } = await tradingSdk.getQuoteResults(swapParams, advancedSettings);
|
|
407
|
+
return { swapResult, orderBookApi };
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// src/BridgingSdk/getQuoteWithBridge.ts
|
|
411
|
+
async function getQuoteWithBridge(provider, params) {
|
|
412
|
+
const { kind } = params.swapAndBridgeRequest;
|
|
413
|
+
if (kind !== import_sdk_order_book.OrderKind.SELL) {
|
|
414
|
+
throw new Error("Bridging only support SELL orders");
|
|
415
|
+
}
|
|
416
|
+
if (isHookBridgeProvider(provider)) {
|
|
417
|
+
return getQuoteWithHookBridge(provider, params);
|
|
418
|
+
}
|
|
419
|
+
if (isReceiverAccountBridgeProvider(provider)) {
|
|
420
|
+
return getQuoteWithReceiverAccountBridge(provider, params);
|
|
421
|
+
}
|
|
422
|
+
throw new Error("Provider type is unknown: " + provider.type);
|
|
423
|
+
}
|
|
424
|
+
function createPostSwapOrderFromQuote(params) {
|
|
425
|
+
const { getBridgeProviderQuote, signer, sellTokenAddress, orderBookApi } = params;
|
|
426
|
+
return async function postSwapOrderFromQuote(advancedSettings, signingStepManager) {
|
|
427
|
+
await signingStepManager?.beforeBridgingSign?.();
|
|
428
|
+
const { swapResult } = await getBridgeProviderQuote(signer, advancedSettings).catch((error) => {
|
|
429
|
+
signingStepManager?.onBridgingSignError?.();
|
|
430
|
+
throw error;
|
|
431
|
+
});
|
|
432
|
+
await signingStepManager?.afterBridgingSign?.();
|
|
433
|
+
const quoteResults = {
|
|
434
|
+
result: {
|
|
435
|
+
...swapResult,
|
|
436
|
+
tradeParameters: (0, import_sdk_trading.getTradeParametersAfterQuote)({
|
|
437
|
+
quoteParameters: swapResult.tradeParameters,
|
|
438
|
+
sellToken: sellTokenAddress
|
|
439
|
+
}),
|
|
440
|
+
signer
|
|
441
|
+
},
|
|
442
|
+
orderBookApi
|
|
443
|
+
};
|
|
444
|
+
await signingStepManager?.beforeOrderSign?.();
|
|
445
|
+
return (0, import_sdk_trading.postSwapOrderFromQuote)(quoteResults, {
|
|
446
|
+
...advancedSettings,
|
|
447
|
+
appData: swapResult.appDataInfo.doc,
|
|
448
|
+
quoteRequest: {
|
|
449
|
+
...advancedSettings?.quoteRequest,
|
|
450
|
+
// Changing receiver back for the quote request
|
|
451
|
+
receiver: swapResult.tradeParameters.receiver
|
|
452
|
+
}
|
|
453
|
+
}).then(async (result) => {
|
|
454
|
+
await signingStepManager?.afterOrderSign?.();
|
|
455
|
+
return result;
|
|
456
|
+
}).catch((error) => {
|
|
457
|
+
signingStepManager?.onOrderSignError?.();
|
|
458
|
+
throw error;
|
|
459
|
+
});
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
async function getQuoteWithReceiverAccountBridge(provider, params) {
|
|
463
|
+
const {
|
|
464
|
+
swapAndBridgeRequest,
|
|
465
|
+
signer,
|
|
466
|
+
bridgeRequestWithoutAmount,
|
|
467
|
+
intermediateTokenAmount,
|
|
468
|
+
swapResult,
|
|
469
|
+
orderBookApi
|
|
470
|
+
} = await getIntermediateSwapResult({
|
|
471
|
+
provider,
|
|
472
|
+
params
|
|
473
|
+
});
|
|
474
|
+
async function getBridgeProviderQuote() {
|
|
475
|
+
const { bridgeReceiverOverride, bridgeResult } = await getAccountBridgeResult(provider, {
|
|
476
|
+
swapAndBridgeRequest,
|
|
477
|
+
bridgeRequestWithoutAmount,
|
|
478
|
+
intermediateTokenAmount
|
|
479
|
+
});
|
|
480
|
+
(0, import_sdk_common4.log)(`Bridge receiver override: ${bridgeReceiverOverride}`);
|
|
481
|
+
swapResult.tradeParameters.receiver = bridgeReceiverOverride;
|
|
482
|
+
return {
|
|
483
|
+
bridgeResult,
|
|
484
|
+
swapResult: {
|
|
485
|
+
...swapResult,
|
|
486
|
+
tradeParameters: {
|
|
487
|
+
...swapResult.tradeParameters,
|
|
488
|
+
receiver: bridgeReceiverOverride
|
|
330
489
|
}
|
|
331
490
|
}
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
const result = await getBridgeProviderQuote();
|
|
494
|
+
return {
|
|
495
|
+
swap: result.swapResult,
|
|
496
|
+
bridge: result.bridgeResult,
|
|
497
|
+
postSwapOrderFromQuote: createPostSwapOrderFromQuote({
|
|
498
|
+
getBridgeProviderQuote,
|
|
499
|
+
signer,
|
|
500
|
+
sellTokenAddress: swapAndBridgeRequest.sellTokenAddress,
|
|
501
|
+
orderBookApi
|
|
502
|
+
})
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
async function getQuoteWithHookBridge(provider, params) {
|
|
506
|
+
const { quoteSigner } = params;
|
|
507
|
+
const {
|
|
508
|
+
signer,
|
|
509
|
+
swapAndBridgeRequest,
|
|
510
|
+
bridgeRequestWithoutAmount,
|
|
511
|
+
intermediateTokenAmount,
|
|
512
|
+
orderBookApi,
|
|
513
|
+
swapResult
|
|
514
|
+
} = await getIntermediateSwapResult({
|
|
515
|
+
provider,
|
|
516
|
+
params,
|
|
517
|
+
getBridgeHook: async (bridgeRequestWithoutAmount2) => {
|
|
518
|
+
const hookEstimatedGasLimit2 = await provider.getGasLimitEstimationForHook(bridgeRequestWithoutAmount2);
|
|
519
|
+
const mockedHook = getHookMockForCostEstimation(hookEstimatedGasLimit2);
|
|
520
|
+
(0, import_sdk_common4.log)(`Using mocked hook for swap gas estimation: ${JSON.stringify(mockedHook)}`);
|
|
521
|
+
return mockedHook;
|
|
332
522
|
}
|
|
333
523
|
});
|
|
334
|
-
const
|
|
335
|
-
(
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
const appDataOverride = advancedSettings2?.appData;
|
|
340
|
-
const receiverOverride = advancedSettings2?.quoteRequest?.receiver;
|
|
341
|
-
const validToOverride = advancedSettings2?.quoteRequest?.validTo;
|
|
524
|
+
const hookEstimatedGasLimit = await provider.getGasLimitEstimationForHook(bridgeRequestWithoutAmount);
|
|
525
|
+
async function getBridgeProviderQuote(signer2, hookGasLimit, advancedSettings) {
|
|
526
|
+
const appDataOverride = advancedSettings?.appData;
|
|
527
|
+
const receiverOverride = advancedSettings?.quoteRequest?.receiver;
|
|
528
|
+
const validToOverride = advancedSettings?.quoteRequest?.validTo;
|
|
342
529
|
const {
|
|
343
530
|
bridgeHook,
|
|
344
531
|
appDataInfo: { doc: appData, fullAppData, appDataKeccak256 },
|
|
345
532
|
bridgeResult
|
|
346
|
-
} = await
|
|
347
|
-
swapAndBridgeRequest
|
|
533
|
+
} = await getHookBridgeResult(provider, {
|
|
534
|
+
swapAndBridgeRequest,
|
|
348
535
|
swapResult,
|
|
349
536
|
bridgeRequestWithoutAmount: {
|
|
350
537
|
...bridgeRequestWithoutAmount,
|
|
351
538
|
receiver: receiverOverride || bridgeRequestWithoutAmount.receiver
|
|
352
539
|
},
|
|
353
|
-
provider,
|
|
354
540
|
intermediateTokenAmount,
|
|
355
541
|
signer: signer2,
|
|
356
542
|
appDataOverride,
|
|
357
543
|
validToOverride,
|
|
358
544
|
hookGasLimit
|
|
359
545
|
});
|
|
360
|
-
(0,
|
|
546
|
+
(0, import_sdk_common4.log)(`Bridge hook for swap: ${JSON.stringify(bridgeHook)}`);
|
|
361
547
|
swapResult.tradeParameters.receiver = bridgeHook.recipient;
|
|
362
|
-
(0,
|
|
548
|
+
(0, import_sdk_common4.log)(`App data for swap: appDataKeccak256=${appDataKeccak256}, fullAppData="${fullAppData}"`);
|
|
363
549
|
swapResult.appDataInfo = {
|
|
364
550
|
fullAppData,
|
|
365
551
|
appDataKeccak256,
|
|
@@ -376,93 +562,58 @@ async function getQuoteWithBridge(params) {
|
|
|
376
562
|
}
|
|
377
563
|
};
|
|
378
564
|
}
|
|
379
|
-
(0,
|
|
380
|
-
const result = await
|
|
381
|
-
// Sign the hooks with
|
|
382
|
-
|
|
383
|
-
// Use estimated hook gas limit if
|
|
384
|
-
// Moreover, since
|
|
565
|
+
(0, import_sdk_common4.log)(`Using gas limit: ${hookEstimatedGasLimit}`);
|
|
566
|
+
const result = await getBridgeProviderQuote(
|
|
567
|
+
// Sign the hooks with quoteSigner if provided
|
|
568
|
+
quoteSigner ? (0, import_sdk_common4.getGlobalAdapter)().createSigner(quoteSigner) : signer,
|
|
569
|
+
// Use estimated hook gas limit if quoteSigner is provided, so we don't have to estimate the hook gas limit twice
|
|
570
|
+
// Moreover, since quoteSigner is not the real signer, the estimation will fail
|
|
385
571
|
hookEstimatedGasLimit
|
|
386
572
|
);
|
|
387
573
|
return {
|
|
388
574
|
swap: result.swapResult,
|
|
389
575
|
bridge: result.bridgeResult,
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
}
|
|
397
|
-
);
|
|
398
|
-
await signingStepManager?.afterBridgingSign?.();
|
|
399
|
-
const quoteResults = {
|
|
400
|
-
result: {
|
|
401
|
-
...swapResult2,
|
|
402
|
-
tradeParameters: (0, import_sdk_trading.getTradeParametersAfterQuote)({
|
|
403
|
-
quoteParameters: swapResult2.tradeParameters,
|
|
404
|
-
sellToken: sellTokenAddress
|
|
405
|
-
}),
|
|
406
|
-
signer
|
|
407
|
-
},
|
|
408
|
-
orderBookApi
|
|
409
|
-
};
|
|
410
|
-
await signingStepManager?.beforeOrderSign?.();
|
|
411
|
-
return (0, import_sdk_trading.postSwapOrderFromQuote)(quoteResults, {
|
|
412
|
-
...advancedSettings2,
|
|
413
|
-
appData: swapResult2.appDataInfo.doc,
|
|
414
|
-
quoteRequest: {
|
|
415
|
-
...advancedSettings2?.quoteRequest,
|
|
416
|
-
// Changing receiver back to account proxy
|
|
417
|
-
receiver: swapResult2.tradeParameters.receiver
|
|
418
|
-
}
|
|
419
|
-
}).catch((error) => {
|
|
420
|
-
signingStepManager?.onOrderSignError?.();
|
|
421
|
-
throw error;
|
|
422
|
-
}).then(async (result2) => {
|
|
423
|
-
await signingStepManager?.afterOrderSign?.();
|
|
424
|
-
return result2;
|
|
425
|
-
});
|
|
426
|
-
}
|
|
576
|
+
postSwapOrderFromQuote: createPostSwapOrderFromQuote({
|
|
577
|
+
getBridgeProviderQuote: (signer2, advancedSettings) => getBridgeProviderQuote(signer2, hookEstimatedGasLimit, advancedSettings),
|
|
578
|
+
signer,
|
|
579
|
+
sellTokenAddress: swapAndBridgeRequest.sellTokenAddress,
|
|
580
|
+
orderBookApi
|
|
581
|
+
})
|
|
427
582
|
};
|
|
428
583
|
}
|
|
429
|
-
async function
|
|
430
|
-
const {
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
buyChainId: quoteBridgeRequest.buyTokenChainId.toString(),
|
|
435
|
-
sellChainId: quoteBridgeRequest.sellTokenChainId.toString(),
|
|
436
|
-
tokenAddress: quoteBridgeRequest.buyTokenAddress
|
|
437
|
-
});
|
|
438
|
-
const cached = intermediateTokensCache?.get(cacheKey);
|
|
439
|
-
if (cached) {
|
|
440
|
-
intermediateTokens = cached;
|
|
441
|
-
} else {
|
|
442
|
-
intermediateTokens = await provider.getIntermediateTokens(quoteBridgeRequest);
|
|
443
|
-
intermediateTokensCache?.set(cacheKey, intermediateTokens);
|
|
444
|
-
}
|
|
445
|
-
if (intermediateTokens.length === 0) {
|
|
446
|
-
throw new BridgeProviderQuoteError("NO_INTERMEDIATE_TOKENS" /* NO_INTERMEDIATE_TOKENS */);
|
|
447
|
-
}
|
|
448
|
-
const intermediateToken = intermediateTokens[0];
|
|
449
|
-
(0, import_sdk_common3.log)(`Using ${intermediateToken?.name ?? intermediateToken?.address} as intermediate tokens`);
|
|
450
|
-
if (!intermediateToken) {
|
|
451
|
-
throw new BridgeProviderQuoteError("NO_INTERMEDIATE_TOKENS" /* NO_INTERMEDIATE_TOKENS */, { intermediateTokens });
|
|
452
|
-
}
|
|
453
|
-
return {
|
|
454
|
-
...quoteBridgeRequest,
|
|
455
|
-
sellTokenAddress: intermediateToken.address,
|
|
456
|
-
sellTokenDecimals: intermediateToken.decimals
|
|
584
|
+
async function getAccountBridgeResult(provider, context) {
|
|
585
|
+
const { bridgeRequestWithoutAmount, intermediateTokenAmount } = context;
|
|
586
|
+
const bridgeRequest = {
|
|
587
|
+
...bridgeRequestWithoutAmount,
|
|
588
|
+
amount: intermediateTokenAmount
|
|
457
589
|
};
|
|
590
|
+
const bridgingQuote = await provider.getQuote(bridgeRequest);
|
|
591
|
+
const bridgeReceiverOverride = await provider.getBridgeReceiverOverride(bridgeRequest, bridgingQuote);
|
|
592
|
+
const bridgeResult = {
|
|
593
|
+
providerInfo: provider.info,
|
|
594
|
+
tradeParameters: bridgeRequest,
|
|
595
|
+
// Just the bridge (not the swap & bridge)
|
|
596
|
+
bridgeReceiverOverride,
|
|
597
|
+
isSell: bridgingQuote.isSell,
|
|
598
|
+
expectedFillTimeSeconds: bridgingQuote.expectedFillTimeSeconds,
|
|
599
|
+
fees: bridgingQuote.fees,
|
|
600
|
+
limits: bridgingQuote.limits,
|
|
601
|
+
quoteTimestamp: bridgingQuote.quoteTimestamp,
|
|
602
|
+
amountsAndCosts: bridgingQuote.amountsAndCosts
|
|
603
|
+
};
|
|
604
|
+
return { bridgeResult, bridgeReceiverOverride };
|
|
458
605
|
}
|
|
459
|
-
async function
|
|
460
|
-
const { swapResult, bridgeRequestWithoutAmount,
|
|
606
|
+
async function getHookBridgeResult(provider, context) {
|
|
607
|
+
const { swapResult, bridgeRequestWithoutAmount, intermediateTokenAmount, appDataOverride } = context;
|
|
461
608
|
const bridgeRequest = {
|
|
462
609
|
...bridgeRequestWithoutAmount,
|
|
463
610
|
amount: intermediateTokenAmount
|
|
464
611
|
};
|
|
465
|
-
const {
|
|
612
|
+
const {
|
|
613
|
+
hook: bridgeHook,
|
|
614
|
+
unsignedBridgeCall,
|
|
615
|
+
bridgingQuote
|
|
616
|
+
} = await getBridgeSignedHook(provider, bridgeRequest, context);
|
|
466
617
|
const swapAppData = await (0, import_sdk_trading.mergeAppDataDoc)(swapResult.appDataInfo.doc, appDataOverride || {});
|
|
467
618
|
const swapResultHooks = swapAppData.doc.metadata.hooks;
|
|
468
619
|
const postHooks = (swapResultHooks?.post || []).filter((hook) => {
|
|
@@ -526,14 +677,13 @@ var SingleQuoteStrategy = class extends BaseSingleQuoteStrategy {
|
|
|
526
677
|
swapAndBridgeRequest: quoteBridgeRequest,
|
|
527
678
|
advancedSettings,
|
|
528
679
|
tradingSdk,
|
|
529
|
-
|
|
530
|
-
bridgeHookSigner: advancedSettings?.quoteSigner
|
|
680
|
+
quoteSigner: advancedSettings?.quoteSigner
|
|
531
681
|
};
|
|
532
682
|
const request2 = this.intermediateTokensCache ? {
|
|
533
683
|
...baseParams,
|
|
534
684
|
intermediateTokensCache: this.intermediateTokensCache
|
|
535
685
|
} : baseParams;
|
|
536
|
-
return getQuoteWithBridge(request2);
|
|
686
|
+
return getQuoteWithBridge(provider, request2);
|
|
537
687
|
} else {
|
|
538
688
|
return getQuoteWithoutBridge({
|
|
539
689
|
quoteBridgeRequest,
|
|
@@ -685,15 +835,14 @@ var MultiQuoteStrategy = class extends BaseMultiQuoteStrategy {
|
|
|
685
835
|
swapAndBridgeRequest: quoteBridgeRequest,
|
|
686
836
|
advancedSettings,
|
|
687
837
|
tradingSdk: config.tradingSdk,
|
|
688
|
-
|
|
689
|
-
bridgeHookSigner: advancedSettings?.quoteSigner
|
|
838
|
+
quoteSigner: advancedSettings?.quoteSigner
|
|
690
839
|
};
|
|
691
840
|
const request = this.intermediateTokensCache ? {
|
|
692
841
|
...baseParams,
|
|
693
842
|
intermediateTokensCache: this.intermediateTokensCache
|
|
694
843
|
} : baseParams;
|
|
695
844
|
const quote = await Promise.race([
|
|
696
|
-
getQuoteWithBridge(request),
|
|
845
|
+
getQuoteWithBridge(provider, request),
|
|
697
846
|
createBridgeQuoteTimeoutPromise(providerTimeout, `Provider ${provider.info.dappId}`)
|
|
698
847
|
]);
|
|
699
848
|
const result = {
|
|
@@ -762,14 +911,14 @@ var BestQuoteStrategy = class extends BaseBestQuoteStrategy {
|
|
|
762
911
|
advancedSettings,
|
|
763
912
|
tradingSdk: config.tradingSdk,
|
|
764
913
|
provider,
|
|
765
|
-
|
|
914
|
+
quoteSigner: advancedSettings?.quoteSigner
|
|
766
915
|
};
|
|
767
916
|
const request = this.intermediateTokensCache ? {
|
|
768
917
|
...baseParams,
|
|
769
918
|
intermediateTokensCache: this.intermediateTokensCache
|
|
770
919
|
} : baseParams;
|
|
771
920
|
const quote = await Promise.race([
|
|
772
|
-
getQuoteWithBridge(request),
|
|
921
|
+
getQuoteWithBridge(provider, request),
|
|
773
922
|
createBridgeQuoteTimeoutPromise(providerTimeout, `Provider ${provider.info.dappId}`)
|
|
774
923
|
]);
|
|
775
924
|
const result = {
|
|
@@ -816,14 +965,14 @@ var BridgingSdk = class {
|
|
|
816
965
|
constructor(options, adapter) {
|
|
817
966
|
this.options = options;
|
|
818
967
|
if (adapter) {
|
|
819
|
-
(0,
|
|
968
|
+
(0, import_sdk_common5.setGlobalAdapter)(adapter);
|
|
820
969
|
}
|
|
821
970
|
const { providers, cacheConfig, ...restOptions } = options;
|
|
822
971
|
if (!providers || providers.length === 0) {
|
|
823
972
|
throw new Error("At least one bridge provider is required");
|
|
824
973
|
}
|
|
825
974
|
if (options.enableLogging !== void 0) {
|
|
826
|
-
(0,
|
|
975
|
+
(0, import_sdk_common5.enableLogging)(options.enableLogging);
|
|
827
976
|
}
|
|
828
977
|
const tradingSdk = options.tradingSdk ?? new import_sdk_trading2.TradingSdk();
|
|
829
978
|
const orderBookApi = tradingSdk?.options.orderBookApi ?? new import_sdk_order_book2.OrderBookApi();
|
|
@@ -834,12 +983,12 @@ var BridgingSdk = class {
|
|
|
834
983
|
orderBookApi
|
|
835
984
|
};
|
|
836
985
|
this.cacheConfig = { ...DEFAULT_CACHE_CONFIG, ...cacheConfig };
|
|
837
|
-
this.intermediateTokensCache = new
|
|
986
|
+
this.intermediateTokensCache = new import_sdk_common5.TTLCache(
|
|
838
987
|
"bridging-intermediate-tokens",
|
|
839
988
|
this.cacheConfig.enabled,
|
|
840
989
|
this.cacheConfig.intermediateTokensTtl
|
|
841
990
|
);
|
|
842
|
-
this.buyTokensCache = new
|
|
991
|
+
this.buyTokensCache = new import_sdk_common5.TTLCache(
|
|
843
992
|
"bridging-buy-tokens",
|
|
844
993
|
this.cacheConfig.enabled,
|
|
845
994
|
this.cacheConfig.buyTokensTtl
|
|
@@ -1012,7 +1161,7 @@ var BridgingSdk = class {
|
|
|
1012
1161
|
};
|
|
1013
1162
|
|
|
1014
1163
|
// src/providers/across/AcrossApi.ts
|
|
1015
|
-
var
|
|
1164
|
+
var import_sdk_common6 = require("@cowprotocol/sdk-common");
|
|
1016
1165
|
var ACROSS_API_URL = "https://app.across.to/api";
|
|
1017
1166
|
var AcrossApi = class {
|
|
1018
1167
|
constructor(options = {}) {
|
|
@@ -1078,7 +1227,7 @@ var AcrossApi = class {
|
|
|
1078
1227
|
async fetchApi(path, params, isValidResponse) {
|
|
1079
1228
|
const baseUrl = this.options.apiBaseUrl || ACROSS_API_URL;
|
|
1080
1229
|
const url = `${baseUrl}${path}?${new URLSearchParams(params).toString()}`;
|
|
1081
|
-
(0,
|
|
1230
|
+
(0, import_sdk_common6.log)(`Fetching Across API: GET ${url}. Params: ${JSON.stringify(params)}`);
|
|
1082
1231
|
const response = await fetch(url, {
|
|
1083
1232
|
method: "GET"
|
|
1084
1233
|
});
|
|
@@ -1117,14 +1266,14 @@ function isValidRoute(item) {
|
|
|
1117
1266
|
}
|
|
1118
1267
|
|
|
1119
1268
|
// src/providers/across/const/interfaces.ts
|
|
1120
|
-
var
|
|
1269
|
+
var import_sdk_common7 = require("@cowprotocol/sdk-common");
|
|
1121
1270
|
var ACROSS_DEPOSIT_EVENT_INTERFACE = () => {
|
|
1122
|
-
return (0,
|
|
1271
|
+
return (0, import_sdk_common7.getGlobalAdapter)().utils.createInterface([
|
|
1123
1272
|
"event FundsDeposited(bytes32 inputToken, bytes32 outputToken, uint256 inputAmount, uint256 outputAmount, uint256 indexed destinationChainId, uint256 indexed depositId, uint32 quoteTimestamp, uint32 fillDeadline, uint32 exclusivityDeadline, bytes32 indexed depositor, bytes32 recipient, bytes32 exclusiveRelayer, bytes message)"
|
|
1124
1273
|
]);
|
|
1125
1274
|
};
|
|
1126
1275
|
var COW_TRADE_EVENT_INTERFACE = () => {
|
|
1127
|
-
return (0,
|
|
1276
|
+
return (0, import_sdk_common7.getGlobalAdapter)().utils.createInterface([
|
|
1128
1277
|
"event Trade(address owner, address sellToken, address buyToken, uint256 sellAmount, uint256 buyAmount, uint256 feeAmount, bytes orderUid)"
|
|
1129
1278
|
]);
|
|
1130
1279
|
};
|
|
@@ -1172,7 +1321,7 @@ var ACROSS_MATH_CONTRACT_ADDRESSES = {
|
|
|
1172
1321
|
// src/providers/across/util.ts
|
|
1173
1322
|
var import_sdk_config4 = require("@cowprotocol/sdk-config");
|
|
1174
1323
|
var import_sdk_order_book3 = require("@cowprotocol/sdk-order-book");
|
|
1175
|
-
var
|
|
1324
|
+
var import_sdk_common8 = require("@cowprotocol/sdk-common");
|
|
1176
1325
|
var PCT_100_PERCENT = 10n ** 18n;
|
|
1177
1326
|
function toBridgeQuoteResult(request, slippageBps, suggestedFees) {
|
|
1178
1327
|
const { kind } = request;
|
|
@@ -1229,7 +1378,7 @@ function toAmountsAndCosts(request, slippageBps, suggestedFees) {
|
|
|
1229
1378
|
};
|
|
1230
1379
|
}
|
|
1231
1380
|
function bytes32ToAddress(address) {
|
|
1232
|
-
return (0,
|
|
1381
|
+
return (0, import_sdk_common8.getGlobalAdapter)().utils.decodeAbi(["address"], address).toString();
|
|
1233
1382
|
}
|
|
1234
1383
|
function assertValidPct(pct) {
|
|
1235
1384
|
if (pct > PCT_100_PERCENT || pct < 0n) {
|
|
@@ -1264,8 +1413,8 @@ function getAcrossDepositEvents(chainId, logs) {
|
|
|
1264
1413
|
}
|
|
1265
1414
|
const acrossDepositInterface = ACROSS_DEPOSIT_EVENT_INTERFACE();
|
|
1266
1415
|
const ACROSS_DEPOSIT_EVENT_TOPIC = acrossDepositInterface.getEventTopic("FundsDeposited");
|
|
1267
|
-
const depositEvents = logs.filter((
|
|
1268
|
-
return
|
|
1416
|
+
const depositEvents = logs.filter((log7) => {
|
|
1417
|
+
return log7.address.toLocaleLowerCase() === spookContractAddress && log7.topics[0] === ACROSS_DEPOSIT_EVENT_TOPIC;
|
|
1269
1418
|
});
|
|
1270
1419
|
return depositEvents.map((event) => {
|
|
1271
1420
|
const parsedLog = acrossDepositInterface.parseLog(event);
|
|
@@ -1306,8 +1455,8 @@ function getAcrossDepositEvents(chainId, logs) {
|
|
|
1306
1455
|
}
|
|
1307
1456
|
function getCowTradeEvents(chainId, logs) {
|
|
1308
1457
|
const COW_TRADE_EVENT_TOPIC = COW_TRADE_EVENT_INTERFACE().getEventTopic("Trade");
|
|
1309
|
-
const cowTradeEvents = logs.filter((
|
|
1310
|
-
return
|
|
1458
|
+
const cowTradeEvents = logs.filter((log7) => {
|
|
1459
|
+
return log7.address.toLowerCase() === import_sdk_config4.COW_PROTOCOL_SETTLEMENT_CONTRACT_ADDRESS[chainId].toLowerCase() && log7.topics[0] === COW_TRADE_EVENT_TOPIC;
|
|
1311
1460
|
});
|
|
1312
1461
|
return cowTradeEvents.map((event) => {
|
|
1313
1462
|
const parsedLog = COW_TRADE_EVENT_INTERFACE().parseLog(event);
|
|
@@ -3107,11 +3256,11 @@ var ACROSS_SPOKE_POOL_ABI = [
|
|
|
3107
3256
|
];
|
|
3108
3257
|
|
|
3109
3258
|
// src/providers/across/createAcrossDepositCall.ts
|
|
3110
|
-
var
|
|
3259
|
+
var import_sdk_common9 = require("@cowprotocol/sdk-common");
|
|
3111
3260
|
var ERC20_BALANCE_OF_ABI = ["function balanceOf(address account) external view returns (uint256)"];
|
|
3112
3261
|
var ERC20_APPROVE_OF_ABI = ["function approve(address spender, uint256 amount) external returns (bool)"];
|
|
3113
3262
|
function getSpookPoolContract(sellTokenChainId) {
|
|
3114
|
-
const adapter = (0,
|
|
3263
|
+
const adapter = (0, import_sdk_common9.getGlobalAdapter)();
|
|
3115
3264
|
const spokePoolAddress = ACROSS_SPOOK_CONTRACT_ADDRESSES[sellTokenChainId];
|
|
3116
3265
|
if (!spokePoolAddress) {
|
|
3117
3266
|
throw new Error("Spoke pool address not found for chain: " + sellTokenChainId);
|
|
@@ -3122,7 +3271,7 @@ function getSpookPoolContract(sellTokenChainId) {
|
|
|
3122
3271
|
);
|
|
3123
3272
|
}
|
|
3124
3273
|
function getMathContract(sellTokenChainId) {
|
|
3125
|
-
const adapter = (0,
|
|
3274
|
+
const adapter = (0, import_sdk_common9.getGlobalAdapter)();
|
|
3126
3275
|
const mathContractAddress = ACROSS_MATH_CONTRACT_ADDRESSES[sellTokenChainId];
|
|
3127
3276
|
if (!mathContractAddress) {
|
|
3128
3277
|
throw new Error("Math contract address not found for chain: " + sellTokenChainId);
|
|
@@ -3133,14 +3282,14 @@ function getMathContract(sellTokenChainId) {
|
|
|
3133
3282
|
);
|
|
3134
3283
|
}
|
|
3135
3284
|
function getBalanceOfSellTokenContract(sellTokenAddress) {
|
|
3136
|
-
const adapter = (0,
|
|
3285
|
+
const adapter = (0, import_sdk_common9.getGlobalAdapter)();
|
|
3137
3286
|
return (0, import_sdk_weiroll.createWeirollContract)(
|
|
3138
3287
|
adapter.getContract(sellTokenAddress, ERC20_BALANCE_OF_ABI),
|
|
3139
3288
|
import_sdk_weiroll.WeirollCommandFlags.STATICCALL
|
|
3140
3289
|
);
|
|
3141
3290
|
}
|
|
3142
3291
|
function getApproveSellTokenContract(sellTokenAddress) {
|
|
3143
|
-
const adapter = (0,
|
|
3292
|
+
const adapter = (0, import_sdk_common9.getGlobalAdapter)();
|
|
3144
3293
|
return (0, import_sdk_weiroll.createWeirollContract)(adapter.getContract(sellTokenAddress, ERC20_APPROVE_OF_ABI), import_sdk_weiroll.WeirollCommandFlags.CALL);
|
|
3145
3294
|
}
|
|
3146
3295
|
function createAcrossDepositCall(params) {
|
|
@@ -3185,7 +3334,7 @@ function createAcrossDepositCall(params) {
|
|
|
3185
3334
|
}
|
|
3186
3335
|
|
|
3187
3336
|
// src/providers/across/getDepositParams.ts
|
|
3188
|
-
var
|
|
3337
|
+
var import_sdk_common10 = require("@cowprotocol/sdk-common");
|
|
3189
3338
|
async function getDepositParams(chainId, orderId, txReceipt) {
|
|
3190
3339
|
const depositEvents = getAcrossDepositEvents(chainId, txReceipt.logs);
|
|
3191
3340
|
if (depositEvents.length === 0) {
|
|
@@ -3197,7 +3346,7 @@ async function getDepositParams(chainId, orderId, txReceipt) {
|
|
|
3197
3346
|
return null;
|
|
3198
3347
|
const depositEvent = depositEvents[orderTradeIndex];
|
|
3199
3348
|
if (!depositEvent) {
|
|
3200
|
-
(0,
|
|
3349
|
+
(0, import_sdk_common10.log)(`Trade event found at index ${orderTradeIndex} but only ${depositEvents.length} deposit events available`);
|
|
3201
3350
|
return null;
|
|
3202
3351
|
}
|
|
3203
3352
|
return {
|
|
@@ -3216,14 +3365,14 @@ async function getDepositParams(chainId, orderId, txReceipt) {
|
|
|
3216
3365
|
}
|
|
3217
3366
|
|
|
3218
3367
|
// src/providers/utils/getGasLimitEstimationForHook.ts
|
|
3219
|
-
var
|
|
3368
|
+
var import_sdk_common11 = require("@cowprotocol/sdk-common");
|
|
3220
3369
|
async function getGasLimitEstimationForHook({
|
|
3221
3370
|
cowShedSdk,
|
|
3222
3371
|
request,
|
|
3223
3372
|
extraGas,
|
|
3224
3373
|
extraGasProxyCreation
|
|
3225
3374
|
}) {
|
|
3226
|
-
const adapter = (0,
|
|
3375
|
+
const adapter = (0, import_sdk_common11.getGlobalAdapter)();
|
|
3227
3376
|
const proxyAddress = cowShedSdk.getCowShedAccount(request.sellTokenChainId, request.owner || request.account);
|
|
3228
3377
|
const proxyCode = await adapter.getCode(proxyAddress);
|
|
3229
3378
|
if (!proxyCode || proxyCode === "0x") {
|
|
@@ -3234,7 +3383,7 @@ async function getGasLimitEstimationForHook({
|
|
|
3234
3383
|
}
|
|
3235
3384
|
|
|
3236
3385
|
// src/providers/across/AcrossBridgeProvider.ts
|
|
3237
|
-
var
|
|
3386
|
+
var import_sdk_common12 = require("@cowprotocol/sdk-common");
|
|
3238
3387
|
var import_sdk_config5 = require("@cowprotocol/sdk-config");
|
|
3239
3388
|
var import_sdk_cow_shed = require("@cowprotocol/sdk-cow-shed");
|
|
3240
3389
|
var import_sdk_order_book4 = require("@cowprotocol/sdk-order-book");
|
|
@@ -3242,13 +3391,14 @@ var ACROSS_HOOK_DAPP_ID = `${HOOK_DAPP_BRIDGE_PROVIDER_PREFIX}/across`;
|
|
|
3242
3391
|
var ACROSS_SUPPORTED_NETWORKS = [import_sdk_config5.mainnet, import_sdk_config5.polygon, import_sdk_config5.arbitrumOne, import_sdk_config5.base, import_sdk_config5.optimism];
|
|
3243
3392
|
var SLIPPAGE_TOLERANCE_BPS = 0;
|
|
3244
3393
|
var AcrossBridgeProvider = class {
|
|
3394
|
+
type = "HookBridgeProvider";
|
|
3245
3395
|
api;
|
|
3246
3396
|
cowShedSdk;
|
|
3247
3397
|
supportedTokens = null;
|
|
3248
3398
|
constructor(options = {}, _adapter) {
|
|
3249
3399
|
const adapter = _adapter || options.cowShedOptions?.adapter;
|
|
3250
3400
|
if (adapter) {
|
|
3251
|
-
(0,
|
|
3401
|
+
(0, import_sdk_common12.setGlobalAdapter)(adapter);
|
|
3252
3402
|
}
|
|
3253
3403
|
this.api = new AcrossApi(options.apiOptions);
|
|
3254
3404
|
this.cowShedSdk = new import_sdk_cow_shed.CowShedSdk(adapter, options.cowShedOptions?.factoryOptions);
|
|
@@ -3343,7 +3493,7 @@ var AcrossBridgeProvider = class {
|
|
|
3343
3493
|
throw new Error("Not implemented");
|
|
3344
3494
|
}
|
|
3345
3495
|
async getBridgingParams(chainId, orderUid, txHash) {
|
|
3346
|
-
const adapter = (0,
|
|
3496
|
+
const adapter = (0, import_sdk_common12.getGlobalAdapter)();
|
|
3347
3497
|
const txReceipt = await adapter.getTransactionReceipt(txHash);
|
|
3348
3498
|
if (!txReceipt)
|
|
3349
3499
|
return null;
|
|
@@ -3861,7 +4011,7 @@ var BUNGEE_APPROVE_AND_BRIDGE_V1_ABI = [
|
|
|
3861
4011
|
];
|
|
3862
4012
|
|
|
3863
4013
|
// src/providers/bungee/BungeeApi.ts
|
|
3864
|
-
var
|
|
4014
|
+
var import_sdk_common13 = require("@cowprotocol/sdk-common");
|
|
3865
4015
|
|
|
3866
4016
|
// src/providers/bungee/consts.ts
|
|
3867
4017
|
var BUNGEE_API_PATH = "/api/v1/bungee";
|
|
@@ -4135,7 +4285,7 @@ var BungeeApi = class {
|
|
|
4135
4285
|
* @returns True if the bungee tx data is valid, false otherwise
|
|
4136
4286
|
*/
|
|
4137
4287
|
async verifyBungeeBuildTxData(originChainId, txData, routeId, expectedSocketRequest) {
|
|
4138
|
-
const adapter = (0,
|
|
4288
|
+
const adapter = (0, import_sdk_common13.getGlobalAdapter)();
|
|
4139
4289
|
const socketVerifierAddress = SocketVerifierAddresses[originChainId];
|
|
4140
4290
|
if (!socketVerifierAddress) {
|
|
4141
4291
|
throw new BridgeProviderQuoteError("TX_BUILD_ERROR" /* TX_BUILD_ERROR */, {
|
|
@@ -4256,13 +4406,13 @@ var BungeeApi = class {
|
|
|
4256
4406
|
if (this.shouldAddAffiliate(apiType, baseUrl) && this.options.affiliate) {
|
|
4257
4407
|
headers["affiliate"] = this.options.affiliate;
|
|
4258
4408
|
}
|
|
4259
|
-
(0,
|
|
4409
|
+
(0, import_sdk_common13.log)(`Fetching ${apiType} API: GET ${url}. Params: ${JSON.stringify(params)}`);
|
|
4260
4410
|
try {
|
|
4261
4411
|
const response = await fetch(url, { method: "GET", headers });
|
|
4262
4412
|
if (!response.ok) {
|
|
4263
4413
|
if (isInfrastructureError(response.status) && !useFallback) {
|
|
4264
4414
|
this.enableFallback(apiType);
|
|
4265
|
-
(0,
|
|
4415
|
+
(0, import_sdk_common13.log)(
|
|
4266
4416
|
`Infrastructure error (${response.status}) detected for ${apiType} API. Enabling fallback for ${this.fallbackTimeoutMs}ms`
|
|
4267
4417
|
);
|
|
4268
4418
|
return this.makeApiCall(apiType, path, params, isValidResponse);
|
|
@@ -4278,7 +4428,7 @@ var BungeeApi = class {
|
|
|
4278
4428
|
} catch (error) {
|
|
4279
4429
|
if (!useFallback && isClientFetchError(error)) {
|
|
4280
4430
|
this.enableFallback(apiType);
|
|
4281
|
-
(0,
|
|
4431
|
+
(0, import_sdk_common13.log)(`Network error detected for ${apiType} API. Enabling fallback for ${this.fallbackTimeoutMs}ms`);
|
|
4282
4432
|
return this.makeApiCall(apiType, path, params, isValidResponse);
|
|
4283
4433
|
}
|
|
4284
4434
|
throw error;
|
|
@@ -4288,9 +4438,9 @@ var BungeeApi = class {
|
|
|
4288
4438
|
|
|
4289
4439
|
// src/providers/bungee/createBungeeDepositCall.ts
|
|
4290
4440
|
var import_sdk_config7 = require("@cowprotocol/sdk-config");
|
|
4291
|
-
var
|
|
4441
|
+
var import_sdk_common14 = require("@cowprotocol/sdk-common");
|
|
4292
4442
|
async function createBungeeDepositCall(params) {
|
|
4293
|
-
const adapter = (0,
|
|
4443
|
+
const adapter = (0, import_sdk_common14.getGlobalAdapter)();
|
|
4294
4444
|
const { request, quote } = params;
|
|
4295
4445
|
const { bungeeQuote, buildTx } = quote;
|
|
4296
4446
|
const bridge = bungeeQuote.routeBridge;
|
|
@@ -4383,7 +4533,7 @@ async function getBridgingStatusFromEvents(events, getAcrossStatus) {
|
|
|
4383
4533
|
// src/providers/bungee/BungeeBridgeProvider.ts
|
|
4384
4534
|
var import_sdk_config8 = require("@cowprotocol/sdk-config");
|
|
4385
4535
|
var import_sdk_cow_shed2 = require("@cowprotocol/sdk-cow-shed");
|
|
4386
|
-
var
|
|
4536
|
+
var import_sdk_common15 = require("@cowprotocol/sdk-common");
|
|
4387
4537
|
var BUNGEE_HOOK_DAPP_ID = `${HOOK_DAPP_BRIDGE_PROVIDER_PREFIX2}/bungee`;
|
|
4388
4538
|
var BUNGEE_SUPPORTED_NETWORKS = [import_sdk_config8.mainnet, import_sdk_config8.polygon, import_sdk_config8.arbitrumOne, import_sdk_config8.base, import_sdk_config8.optimism, import_sdk_config8.avalanche, import_sdk_config8.gnosisChain];
|
|
4389
4539
|
var SLIPPAGE_TOLERANCE_BPS2 = 0;
|
|
@@ -4392,11 +4542,12 @@ var BungeeBridgeProvider = class {
|
|
|
4392
4542
|
this.options = options;
|
|
4393
4543
|
const adapter = _adapter || options.cowShedOptions?.adapter;
|
|
4394
4544
|
if (adapter) {
|
|
4395
|
-
(0,
|
|
4545
|
+
(0, import_sdk_common15.setGlobalAdapter)(adapter);
|
|
4396
4546
|
}
|
|
4397
4547
|
this.api = new BungeeApi(options.apiOptions);
|
|
4398
4548
|
this.cowShedSdk = new import_sdk_cow_shed2.CowShedSdk(adapter, options.cowShedOptions?.factoryOptions);
|
|
4399
4549
|
}
|
|
4550
|
+
type = "HookBridgeProvider";
|
|
4400
4551
|
api;
|
|
4401
4552
|
cowShedSdk;
|
|
4402
4553
|
info = {
|
|
@@ -4561,5 +4712,7 @@ var BungeeBridgeProvider = class {
|
|
|
4561
4712
|
getPostHooks,
|
|
4562
4713
|
isAppDoc,
|
|
4563
4714
|
isBridgeQuoteAndPost,
|
|
4564
|
-
|
|
4715
|
+
isHookBridgeProvider,
|
|
4716
|
+
isQuoteAndPost,
|
|
4717
|
+
isReceiverAccountBridgeProvider
|
|
4565
4718
|
});
|