@cowprotocol/sdk-bridging 1.3.0 → 1.4.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.js +71 -64
- package/dist/index.mjs +21 -14
- package/package.json +13 -13
package/dist/index.js
CHANGED
|
@@ -237,7 +237,7 @@ async function getCrossChainOrder(params) {
|
|
|
237
237
|
var import_sdk_trading2 = require("@cowprotocol/sdk-trading");
|
|
238
238
|
var import_sdk_order_book3 = require("@cowprotocol/sdk-order-book");
|
|
239
239
|
var import_sdk_config3 = require("@cowprotocol/sdk-config");
|
|
240
|
-
var
|
|
240
|
+
var import_sdk_common6 = require("@cowprotocol/sdk-common");
|
|
241
241
|
|
|
242
242
|
// src/BridgingSdk/helpers.ts
|
|
243
243
|
var getCacheKey = ({
|
|
@@ -269,7 +269,7 @@ function getQuoteWithoutBridge(params) {
|
|
|
269
269
|
|
|
270
270
|
// src/BridgingSdk/getQuoteWithBridge.ts
|
|
271
271
|
var import_sdk_trading = require("@cowprotocol/sdk-trading");
|
|
272
|
-
var
|
|
272
|
+
var import_sdk_common5 = require("@cowprotocol/sdk-common");
|
|
273
273
|
var import_sdk_order_book = require("@cowprotocol/sdk-order-book");
|
|
274
274
|
|
|
275
275
|
// src/BridgingSdk/getBridgeSignedHook.ts
|
|
@@ -309,6 +309,9 @@ function getHookMockForCostEstimation(gasLimit) {
|
|
|
309
309
|
}
|
|
310
310
|
|
|
311
311
|
// src/BridgingSdk/getIntermediateSwapResult.ts
|
|
312
|
+
var import_sdk_common4 = require("@cowprotocol/sdk-common");
|
|
313
|
+
|
|
314
|
+
// src/BridgingSdk/determineIntermediateToken.ts
|
|
312
315
|
var import_sdk_common3 = require("@cowprotocol/sdk-common");
|
|
313
316
|
|
|
314
317
|
// src/BridgingSdk/tokenPriority.ts
|
|
@@ -378,12 +381,9 @@ function isStablecoinPriorityToken(chainId, tokenAddress) {
|
|
|
378
381
|
function isCorrelatedToken(tokenAddress, correlatedTokens) {
|
|
379
382
|
return correlatedTokens.has(tokenAddress.toLowerCase());
|
|
380
383
|
}
|
|
381
|
-
function isNativeToken(tokenAddress) {
|
|
382
|
-
return tokenAddress.toLowerCase() === import_sdk_config2.NATIVE_CURRENCY_ADDRESS.toLowerCase();
|
|
383
|
-
}
|
|
384
384
|
|
|
385
385
|
// src/BridgingSdk/determineIntermediateToken.ts
|
|
386
|
-
async function determineIntermediateToken(sourceChainId, intermediateTokens, getCorrelatedTokens) {
|
|
386
|
+
async function determineIntermediateToken(sourceChainId, sourceTokenAddress, intermediateTokens, getCorrelatedTokens) {
|
|
387
387
|
const firstToken = intermediateTokens[0];
|
|
388
388
|
if (intermediateTokens.length === 0 || !firstToken) {
|
|
389
389
|
throw new BridgeProviderQuoteError("NO_INTERMEDIATE_TOKENS" /* NO_INTERMEDIATE_TOKENS */, { intermediateTokens });
|
|
@@ -392,17 +392,25 @@ async function determineIntermediateToken(sourceChainId, intermediateTokens, get
|
|
|
392
392
|
return firstToken;
|
|
393
393
|
}
|
|
394
394
|
const correlatedTokens = await resolveCorrelatedTokens(sourceChainId, getCorrelatedTokens);
|
|
395
|
+
const sellTokenLike = { chainId: sourceChainId, address: sourceTokenAddress };
|
|
396
|
+
const isSellNativeOrWrapped = (0, import_sdk_common3.isNativeToken)(sellTokenLike) || (0, import_sdk_common3.isWrappedNativeToken)(sellTokenLike);
|
|
395
397
|
const tokensWithPriority = intermediateTokens.map((token) => {
|
|
398
|
+
const isNativeOrWrapped = (0, import_sdk_common3.isNativeToken)(token) || (0, import_sdk_common3.isWrappedNativeToken)(token);
|
|
399
|
+
if ((0, import_sdk_common3.areAddressesEqual)(token.address, sourceTokenAddress)) {
|
|
400
|
+
if (!(isSellNativeOrWrapped && isNativeOrWrapped)) {
|
|
401
|
+
return { token, priority: 5 /* HIGHEST */ };
|
|
402
|
+
}
|
|
403
|
+
}
|
|
396
404
|
if (isStablecoinPriorityToken(token.chainId, token.address)) {
|
|
397
|
-
return { token, priority: 4 /*
|
|
405
|
+
return { token, priority: 4 /* HIGH */ };
|
|
398
406
|
}
|
|
399
407
|
if (isCorrelatedToken(token.address, correlatedTokens)) {
|
|
400
|
-
return { token, priority: 3 /*
|
|
408
|
+
return { token, priority: 3 /* MEDIUM */ };
|
|
401
409
|
}
|
|
402
|
-
if (isNativeToken(token
|
|
403
|
-
return { token, priority: 2 /*
|
|
410
|
+
if ((0, import_sdk_common3.isNativeToken)(token) && !isSellNativeOrWrapped) {
|
|
411
|
+
return { token, priority: 2 /* LOW */ };
|
|
404
412
|
}
|
|
405
|
-
return { token, priority: 1 /*
|
|
413
|
+
return { token, priority: 1 /* LOWEST */ };
|
|
406
414
|
});
|
|
407
415
|
tokensWithPriority.sort((a, b) => {
|
|
408
416
|
if (a.priority !== b.priority) {
|
|
@@ -447,9 +455,9 @@ async function getIntermediateSwapResult({
|
|
|
447
455
|
amount,
|
|
448
456
|
signer: signerLike
|
|
449
457
|
} = swapAndBridgeRequest;
|
|
450
|
-
const adapter = (0,
|
|
458
|
+
const adapter = (0, import_sdk_common4.getGlobalAdapter)();
|
|
451
459
|
const signer = signerLike ? adapter.createSigner(signerLike) : adapter.signer;
|
|
452
|
-
(0,
|
|
460
|
+
(0, import_sdk_common4.log)(
|
|
453
461
|
`Cross-chain ${kind} ${amount} ${sellTokenAddress} (source chain ${sellTokenChainId}) for ${buyTokenAddress} (target chain ${buyTokenChainId})`
|
|
454
462
|
);
|
|
455
463
|
const intermediateTokens = await getIntermediateTokens({
|
|
@@ -459,10 +467,11 @@ async function getIntermediateSwapResult({
|
|
|
459
467
|
});
|
|
460
468
|
const intermediateToken = await determineIntermediateToken(
|
|
461
469
|
sellTokenChainId,
|
|
470
|
+
sellTokenAddress,
|
|
462
471
|
intermediateTokens,
|
|
463
472
|
params.advancedSettings?.getCorrelatedTokens
|
|
464
473
|
);
|
|
465
|
-
(0,
|
|
474
|
+
(0, import_sdk_common4.log)(`Using ${intermediateToken?.name ?? intermediateToken?.address} as intermediate tokens`);
|
|
466
475
|
const bridgeRequestWithoutAmount = {
|
|
467
476
|
...swapAndBridgeRequest,
|
|
468
477
|
sellTokenAddress: intermediateToken.address,
|
|
@@ -497,7 +506,7 @@ async function getIntermediateSwapResult({
|
|
|
497
506
|
signer
|
|
498
507
|
});
|
|
499
508
|
const intermediateTokenAmount = swapResult.amountsAndCosts.afterSlippage.buyAmount;
|
|
500
|
-
(0,
|
|
509
|
+
(0, import_sdk_common4.log)(
|
|
501
510
|
`Expected to receive ${intermediateTokenAmount} of the intermediate token (${(intermediateTokenAmount / 10n ** BigInt(intermediaryTokenDecimals)).toString()} formatted)`
|
|
502
511
|
);
|
|
503
512
|
return {
|
|
@@ -559,10 +568,10 @@ async function getSwapQuote(params) {
|
|
|
559
568
|
signer
|
|
560
569
|
};
|
|
561
570
|
const { signer: _, ...swapParamsToLog } = swapParams;
|
|
562
|
-
(0,
|
|
571
|
+
(0, import_sdk_common4.log)(
|
|
563
572
|
`Getting a quote for the swap (sell token to buy intermediate token). Delegate to trading SDK with params: ${JSON.stringify(
|
|
564
573
|
swapParamsToLog,
|
|
565
|
-
|
|
574
|
+
import_sdk_common4.jsonWithBigintReplacer
|
|
566
575
|
)}`
|
|
567
576
|
);
|
|
568
577
|
const { result: swapResult, orderBookApi } = await tradingSdk.getQuoteResults(swapParams, advancedSettings);
|
|
@@ -648,7 +657,7 @@ async function getQuoteWithReceiverAccountBridge(provider, params) {
|
|
|
648
657
|
bridgeRequestWithoutAmount,
|
|
649
658
|
intermediateTokenAmount
|
|
650
659
|
});
|
|
651
|
-
(0,
|
|
660
|
+
(0, import_sdk_common5.log)(`Bridge receiver override: ${bridgeReceiverOverride}`);
|
|
652
661
|
swapResult.tradeParameters.receiver = bridgeReceiverOverride;
|
|
653
662
|
swapResult.appDataInfo = await (0, import_sdk_trading.mergeAppDataDoc)(swapResult.appDataInfo.doc, {
|
|
654
663
|
metadata: {
|
|
@@ -695,7 +704,7 @@ async function getQuoteWithHookBridge(provider, params) {
|
|
|
695
704
|
getBridgeHook: async (bridgeRequestWithoutAmount2) => {
|
|
696
705
|
const hookEstimatedGasLimit2 = await provider.getGasLimitEstimationForHook(bridgeRequestWithoutAmount2);
|
|
697
706
|
const mockedHook = getHookMockForCostEstimation(hookEstimatedGasLimit2);
|
|
698
|
-
(0,
|
|
707
|
+
(0, import_sdk_common5.log)(`Using mocked hook for swap gas estimation: ${JSON.stringify(mockedHook)}`);
|
|
699
708
|
return mockedHook;
|
|
700
709
|
}
|
|
701
710
|
});
|
|
@@ -721,9 +730,9 @@ async function getQuoteWithHookBridge(provider, params) {
|
|
|
721
730
|
validToOverride,
|
|
722
731
|
hookGasLimit
|
|
723
732
|
});
|
|
724
|
-
(0,
|
|
733
|
+
(0, import_sdk_common5.log)(`Bridge hook for swap: ${JSON.stringify(bridgeHook)}`);
|
|
725
734
|
swapResult.tradeParameters.receiver = bridgeHook.recipient;
|
|
726
|
-
(0,
|
|
735
|
+
(0, import_sdk_common5.log)(`App data for swap: appDataKeccak256=${appDataKeccak256}, fullAppData="${fullAppData}"`);
|
|
727
736
|
swapResult.appDataInfo = {
|
|
728
737
|
fullAppData,
|
|
729
738
|
appDataKeccak256,
|
|
@@ -740,10 +749,10 @@ async function getQuoteWithHookBridge(provider, params) {
|
|
|
740
749
|
}
|
|
741
750
|
};
|
|
742
751
|
}
|
|
743
|
-
(0,
|
|
752
|
+
(0, import_sdk_common5.log)(`Using gas limit: ${hookEstimatedGasLimit}`);
|
|
744
753
|
const result = await getBridgeProviderQuote(
|
|
745
754
|
// Sign the hooks with quoteSigner if provided
|
|
746
|
-
quoteSigner ? (0,
|
|
755
|
+
quoteSigner ? (0, import_sdk_common5.getGlobalAdapter)().createSigner(quoteSigner) : signer,
|
|
747
756
|
// Use estimated hook gas limit if quoteSigner is provided, so we don't have to estimate the hook gas limit twice
|
|
748
757
|
// Moreover, since quoteSigner is not the real signer, the estimation will fail
|
|
749
758
|
hookEstimatedGasLimit
|
|
@@ -1183,14 +1192,14 @@ var BridgingSdk = class {
|
|
|
1183
1192
|
constructor(options, adapter) {
|
|
1184
1193
|
this.options = options;
|
|
1185
1194
|
if (adapter) {
|
|
1186
|
-
(0,
|
|
1195
|
+
(0, import_sdk_common6.setGlobalAdapter)(adapter);
|
|
1187
1196
|
}
|
|
1188
1197
|
const { providers, cacheConfig, ...restOptions } = options;
|
|
1189
1198
|
if (!providers || providers.length === 0) {
|
|
1190
1199
|
throw new Error("At least one bridge provider is required");
|
|
1191
1200
|
}
|
|
1192
1201
|
if (options.enableLogging !== void 0) {
|
|
1193
|
-
(0,
|
|
1202
|
+
(0, import_sdk_common6.enableLogging)(options.enableLogging);
|
|
1194
1203
|
}
|
|
1195
1204
|
const tradingSdk = options.tradingSdk ?? new import_sdk_trading2.TradingSdk();
|
|
1196
1205
|
const orderBookApi = tradingSdk?.options.orderBookApi ?? new import_sdk_order_book3.OrderBookApi();
|
|
@@ -1201,12 +1210,12 @@ var BridgingSdk = class {
|
|
|
1201
1210
|
orderBookApi
|
|
1202
1211
|
};
|
|
1203
1212
|
this.cacheConfig = { ...DEFAULT_CACHE_CONFIG, ...cacheConfig };
|
|
1204
|
-
this.intermediateTokensCache = new
|
|
1213
|
+
this.intermediateTokensCache = new import_sdk_common6.TTLCache(
|
|
1205
1214
|
"bridging-intermediate-tokens",
|
|
1206
1215
|
this.cacheConfig.enabled,
|
|
1207
1216
|
this.cacheConfig.intermediateTokensTtl
|
|
1208
1217
|
);
|
|
1209
|
-
this.buyTokensCache = new
|
|
1218
|
+
this.buyTokensCache = new import_sdk_common6.TTLCache(
|
|
1210
1219
|
"bridging-buy-tokens",
|
|
1211
1220
|
this.cacheConfig.enabled,
|
|
1212
1221
|
this.cacheConfig.buyTokensTtl
|
|
@@ -1419,7 +1428,7 @@ var BridgingSdk = class {
|
|
|
1419
1428
|
};
|
|
1420
1429
|
|
|
1421
1430
|
// src/providers/across/AcrossApi.ts
|
|
1422
|
-
var
|
|
1431
|
+
var import_sdk_common7 = require("@cowprotocol/sdk-common");
|
|
1423
1432
|
var ACROSS_API_URL = "https://app.across.to/api";
|
|
1424
1433
|
var AcrossApi = class {
|
|
1425
1434
|
constructor(options = {}) {
|
|
@@ -1485,7 +1494,7 @@ var AcrossApi = class {
|
|
|
1485
1494
|
async fetchApi(path, params, isValidResponse) {
|
|
1486
1495
|
const baseUrl = this.options.apiBaseUrl || ACROSS_API_URL;
|
|
1487
1496
|
const url = `${baseUrl}${path}?${new URLSearchParams(params).toString()}`;
|
|
1488
|
-
(0,
|
|
1497
|
+
(0, import_sdk_common7.log)(`Fetching Across API: GET ${url}. Params: ${JSON.stringify(params)}`);
|
|
1489
1498
|
const response = await fetch(url, {
|
|
1490
1499
|
method: "GET"
|
|
1491
1500
|
});
|
|
@@ -1524,14 +1533,14 @@ function isValidRoute(item) {
|
|
|
1524
1533
|
}
|
|
1525
1534
|
|
|
1526
1535
|
// src/providers/across/const/interfaces.ts
|
|
1527
|
-
var
|
|
1536
|
+
var import_sdk_common8 = require("@cowprotocol/sdk-common");
|
|
1528
1537
|
var ACROSS_DEPOSIT_EVENT_INTERFACE = () => {
|
|
1529
|
-
return (0,
|
|
1538
|
+
return (0, import_sdk_common8.getGlobalAdapter)().utils.createInterface([
|
|
1530
1539
|
"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)"
|
|
1531
1540
|
]);
|
|
1532
1541
|
};
|
|
1533
1542
|
var COW_TRADE_EVENT_INTERFACE = () => {
|
|
1534
|
-
return (0,
|
|
1543
|
+
return (0, import_sdk_common8.getGlobalAdapter)().utils.createInterface([
|
|
1535
1544
|
"event Trade(address indexed owner, address sellToken, address buyToken, uint256 sellAmount, uint256 buyAmount, uint256 feeAmount, bytes orderUid)"
|
|
1536
1545
|
]);
|
|
1537
1546
|
};
|
|
@@ -1587,7 +1596,7 @@ var ACROSS_MATH_CONTRACT_ADDRESSES = {
|
|
|
1587
1596
|
// src/providers/across/util.ts
|
|
1588
1597
|
var import_sdk_config5 = require("@cowprotocol/sdk-config");
|
|
1589
1598
|
var import_sdk_order_book4 = require("@cowprotocol/sdk-order-book");
|
|
1590
|
-
var
|
|
1599
|
+
var import_sdk_common9 = require("@cowprotocol/sdk-common");
|
|
1591
1600
|
var import_json_stable_stringify = __toESM(require("json-stable-stringify"));
|
|
1592
1601
|
var PCT_100_PERCENT = 10n ** 18n;
|
|
1593
1602
|
function toBridgeQuoteResult(request, slippageBps, suggestedFees) {
|
|
@@ -1646,7 +1655,7 @@ function toAmountsAndCosts(request, slippageBps, suggestedFees) {
|
|
|
1646
1655
|
};
|
|
1647
1656
|
}
|
|
1648
1657
|
function bytes32ToAddress(address) {
|
|
1649
|
-
return (0,
|
|
1658
|
+
return (0, import_sdk_common9.getGlobalAdapter)().utils.decodeAbi(["address"], address).toString();
|
|
1650
1659
|
}
|
|
1651
1660
|
function assertValidPct(pct) {
|
|
1652
1661
|
if (pct > PCT_100_PERCENT || pct < 0n) {
|
|
@@ -3524,11 +3533,11 @@ var ACROSS_SPOKE_POOL_ABI = [
|
|
|
3524
3533
|
];
|
|
3525
3534
|
|
|
3526
3535
|
// src/providers/across/createAcrossDepositCall.ts
|
|
3527
|
-
var
|
|
3536
|
+
var import_sdk_common10 = require("@cowprotocol/sdk-common");
|
|
3528
3537
|
var ERC20_BALANCE_OF_ABI = ["function balanceOf(address account) external view returns (uint256)"];
|
|
3529
3538
|
var ERC20_APPROVE_OF_ABI = ["function approve(address spender, uint256 amount) external returns (bool)"];
|
|
3530
3539
|
function getSpookPoolContract(sellTokenChainId) {
|
|
3531
|
-
const adapter = (0,
|
|
3540
|
+
const adapter = (0, import_sdk_common10.getGlobalAdapter)();
|
|
3532
3541
|
const spokePoolAddress = ACROSS_SPOOK_CONTRACT_ADDRESSES[sellTokenChainId];
|
|
3533
3542
|
if (!spokePoolAddress) {
|
|
3534
3543
|
throw new Error("Spoke pool address not found for chain: " + sellTokenChainId);
|
|
@@ -3539,7 +3548,7 @@ function getSpookPoolContract(sellTokenChainId) {
|
|
|
3539
3548
|
);
|
|
3540
3549
|
}
|
|
3541
3550
|
function getMathContract(sellTokenChainId) {
|
|
3542
|
-
const adapter = (0,
|
|
3551
|
+
const adapter = (0, import_sdk_common10.getGlobalAdapter)();
|
|
3543
3552
|
const mathContractAddress = ACROSS_MATH_CONTRACT_ADDRESSES[sellTokenChainId];
|
|
3544
3553
|
if (!mathContractAddress) {
|
|
3545
3554
|
throw new Error("Math contract address not found for chain: " + sellTokenChainId);
|
|
@@ -3550,14 +3559,14 @@ function getMathContract(sellTokenChainId) {
|
|
|
3550
3559
|
);
|
|
3551
3560
|
}
|
|
3552
3561
|
function getBalanceOfSellTokenContract(sellTokenAddress) {
|
|
3553
|
-
const adapter = (0,
|
|
3562
|
+
const adapter = (0, import_sdk_common10.getGlobalAdapter)();
|
|
3554
3563
|
return (0, import_sdk_weiroll.createWeirollContract)(
|
|
3555
3564
|
adapter.getContract(sellTokenAddress, ERC20_BALANCE_OF_ABI),
|
|
3556
3565
|
import_sdk_weiroll.WeirollCommandFlags.STATICCALL
|
|
3557
3566
|
);
|
|
3558
3567
|
}
|
|
3559
3568
|
function getApproveSellTokenContract(sellTokenAddress) {
|
|
3560
|
-
const adapter = (0,
|
|
3569
|
+
const adapter = (0, import_sdk_common10.getGlobalAdapter)();
|
|
3561
3570
|
return (0, import_sdk_weiroll.createWeirollContract)(adapter.getContract(sellTokenAddress, ERC20_APPROVE_OF_ABI), import_sdk_weiroll.WeirollCommandFlags.CALL);
|
|
3562
3571
|
}
|
|
3563
3572
|
function createAcrossDepositCall(params) {
|
|
@@ -3602,7 +3611,7 @@ function createAcrossDepositCall(params) {
|
|
|
3602
3611
|
}
|
|
3603
3612
|
|
|
3604
3613
|
// src/providers/across/getDepositParams.ts
|
|
3605
|
-
var
|
|
3614
|
+
var import_sdk_common11 = require("@cowprotocol/sdk-common");
|
|
3606
3615
|
async function getDepositParams(chainId, orderId, txReceipt) {
|
|
3607
3616
|
const depositEvents = getAcrossDepositEvents(chainId, txReceipt.logs);
|
|
3608
3617
|
if (depositEvents.length === 0) {
|
|
@@ -3614,7 +3623,7 @@ async function getDepositParams(chainId, orderId, txReceipt) {
|
|
|
3614
3623
|
return null;
|
|
3615
3624
|
const depositEvent = depositEvents[orderTradeIndex];
|
|
3616
3625
|
if (!depositEvent) {
|
|
3617
|
-
(0,
|
|
3626
|
+
(0, import_sdk_common11.log)(`Trade event found at index ${orderTradeIndex} but only ${depositEvents.length} deposit events available`);
|
|
3618
3627
|
return null;
|
|
3619
3628
|
}
|
|
3620
3629
|
return {
|
|
@@ -3633,14 +3642,14 @@ async function getDepositParams(chainId, orderId, txReceipt) {
|
|
|
3633
3642
|
}
|
|
3634
3643
|
|
|
3635
3644
|
// src/providers/utils/getGasLimitEstimationForHook.ts
|
|
3636
|
-
var
|
|
3645
|
+
var import_sdk_common12 = require("@cowprotocol/sdk-common");
|
|
3637
3646
|
async function getGasLimitEstimationForHook({
|
|
3638
3647
|
cowShedSdk,
|
|
3639
3648
|
request,
|
|
3640
3649
|
extraGas,
|
|
3641
3650
|
extraGasProxyCreation
|
|
3642
3651
|
}) {
|
|
3643
|
-
const adapter = (0,
|
|
3652
|
+
const adapter = (0, import_sdk_common12.getGlobalAdapter)();
|
|
3644
3653
|
const proxyAddress = cowShedSdk.getCowShedAccount(request.sellTokenChainId, request.owner || request.account);
|
|
3645
3654
|
const proxyCode = await adapter.getCode(proxyAddress);
|
|
3646
3655
|
if (!proxyCode || proxyCode === "0x") {
|
|
@@ -3651,7 +3660,7 @@ async function getGasLimitEstimationForHook({
|
|
|
3651
3660
|
}
|
|
3652
3661
|
|
|
3653
3662
|
// src/providers/across/AcrossBridgeProvider.ts
|
|
3654
|
-
var
|
|
3663
|
+
var import_sdk_common13 = require("@cowprotocol/sdk-common");
|
|
3655
3664
|
var import_sdk_config6 = require("@cowprotocol/sdk-config");
|
|
3656
3665
|
var import_sdk_cow_shed = require("@cowprotocol/sdk-cow-shed");
|
|
3657
3666
|
var import_sdk_order_book5 = require("@cowprotocol/sdk-order-book");
|
|
@@ -3667,7 +3676,7 @@ var AcrossBridgeProvider = class {
|
|
|
3667
3676
|
constructor(options = {}, _adapter) {
|
|
3668
3677
|
const adapter = _adapter || options.cowShedOptions?.adapter;
|
|
3669
3678
|
if (adapter) {
|
|
3670
|
-
(0,
|
|
3679
|
+
(0, import_sdk_common13.setGlobalAdapter)(adapter);
|
|
3671
3680
|
}
|
|
3672
3681
|
this.api = new AcrossApi(options.apiOptions);
|
|
3673
3682
|
this.cowShedSdk = new import_sdk_cow_shed.CowShedSdk(adapter, options.cowShedOptions?.factoryOptions);
|
|
@@ -3764,7 +3773,7 @@ var AcrossBridgeProvider = class {
|
|
|
3764
3773
|
}
|
|
3765
3774
|
async getBridgingParams(chainId, order, txHash) {
|
|
3766
3775
|
const orderUid = order.uid;
|
|
3767
|
-
const adapter = (0,
|
|
3776
|
+
const adapter = (0, import_sdk_common13.getGlobalAdapter)();
|
|
3768
3777
|
const txReceipt = await adapter.getTransactionReceipt(txHash);
|
|
3769
3778
|
if (!txReceipt)
|
|
3770
3779
|
return null;
|
|
@@ -4277,7 +4286,7 @@ var BUNGEE_APPROVE_AND_BRIDGE_V1_ABI = [
|
|
|
4277
4286
|
];
|
|
4278
4287
|
|
|
4279
4288
|
// src/providers/bungee/BungeeApi.ts
|
|
4280
|
-
var
|
|
4289
|
+
var import_sdk_common14 = require("@cowprotocol/sdk-common");
|
|
4281
4290
|
|
|
4282
4291
|
// src/providers/bungee/consts.ts
|
|
4283
4292
|
var BUNGEE_API_PATH = "/api/v1/bungee";
|
|
@@ -4551,7 +4560,7 @@ var BungeeApi = class {
|
|
|
4551
4560
|
* @returns True if the bungee tx data is valid, false otherwise
|
|
4552
4561
|
*/
|
|
4553
4562
|
async verifyBungeeBuildTxData(originChainId, txData, routeId, expectedSocketRequest) {
|
|
4554
|
-
const adapter = (0,
|
|
4563
|
+
const adapter = (0, import_sdk_common14.getGlobalAdapter)();
|
|
4555
4564
|
const socketVerifierAddress = SocketVerifierAddresses[originChainId];
|
|
4556
4565
|
if (!socketVerifierAddress) {
|
|
4557
4566
|
throw new BridgeProviderQuoteError("TX_BUILD_ERROR" /* TX_BUILD_ERROR */, {
|
|
@@ -4672,13 +4681,13 @@ var BungeeApi = class {
|
|
|
4672
4681
|
if (this.shouldAddAffiliate(apiType, baseUrl) && this.options.affiliate) {
|
|
4673
4682
|
headers["affiliate"] = this.options.affiliate;
|
|
4674
4683
|
}
|
|
4675
|
-
(0,
|
|
4684
|
+
(0, import_sdk_common14.log)(`Fetching ${apiType} API: GET ${url}. Params: ${JSON.stringify(params)}`);
|
|
4676
4685
|
try {
|
|
4677
4686
|
const response = await fetch(url, { method: "GET", headers });
|
|
4678
4687
|
if (!response.ok) {
|
|
4679
4688
|
if (isInfrastructureError(response.status) && !useFallback) {
|
|
4680
4689
|
this.enableFallback(apiType);
|
|
4681
|
-
(0,
|
|
4690
|
+
(0, import_sdk_common14.log)(
|
|
4682
4691
|
`Infrastructure error (${response.status}) detected for ${apiType} API. Enabling fallback for ${this.fallbackTimeoutMs}ms`
|
|
4683
4692
|
);
|
|
4684
4693
|
return this.makeApiCall(apiType, path, params, isValidResponse);
|
|
@@ -4694,7 +4703,7 @@ var BungeeApi = class {
|
|
|
4694
4703
|
} catch (error) {
|
|
4695
4704
|
if (!useFallback && isClientFetchError(error)) {
|
|
4696
4705
|
this.enableFallback(apiType);
|
|
4697
|
-
(0,
|
|
4706
|
+
(0, import_sdk_common14.log)(`Network error detected for ${apiType} API. Enabling fallback for ${this.fallbackTimeoutMs}ms`);
|
|
4698
4707
|
return this.makeApiCall(apiType, path, params, isValidResponse);
|
|
4699
4708
|
}
|
|
4700
4709
|
throw error;
|
|
@@ -4704,9 +4713,9 @@ var BungeeApi = class {
|
|
|
4704
4713
|
|
|
4705
4714
|
// src/providers/bungee/createBungeeDepositCall.ts
|
|
4706
4715
|
var import_sdk_config8 = require("@cowprotocol/sdk-config");
|
|
4707
|
-
var
|
|
4716
|
+
var import_sdk_common15 = require("@cowprotocol/sdk-common");
|
|
4708
4717
|
async function createBungeeDepositCall(params) {
|
|
4709
|
-
const adapter = (0,
|
|
4718
|
+
const adapter = (0, import_sdk_common15.getGlobalAdapter)();
|
|
4710
4719
|
const { request, quote } = params;
|
|
4711
4720
|
const { bungeeQuote, buildTx } = quote;
|
|
4712
4721
|
const bridge = bungeeQuote.routeBridge;
|
|
@@ -4795,7 +4804,7 @@ async function getBridgingStatusFromEvents(events, getAcrossStatus) {
|
|
|
4795
4804
|
// src/providers/bungee/BungeeBridgeProvider.ts
|
|
4796
4805
|
var import_sdk_config9 = require("@cowprotocol/sdk-config");
|
|
4797
4806
|
var import_sdk_cow_shed2 = require("@cowprotocol/sdk-cow-shed");
|
|
4798
|
-
var
|
|
4807
|
+
var import_sdk_common16 = require("@cowprotocol/sdk-common");
|
|
4799
4808
|
var BUNGEE_HOOK_DAPP_ID = `${HOOK_DAPP_BRIDGE_PROVIDER_PREFIX2}/bungee`;
|
|
4800
4809
|
var BUNGEE_SUPPORTED_NETWORKS = [import_sdk_config9.mainnet, import_sdk_config9.polygon, import_sdk_config9.arbitrumOne, import_sdk_config9.base, import_sdk_config9.optimism, import_sdk_config9.avalanche, import_sdk_config9.gnosisChain];
|
|
4801
4810
|
var SLIPPAGE_TOLERANCE_BPS2 = 0;
|
|
@@ -4805,7 +4814,7 @@ var BungeeBridgeProvider = class {
|
|
|
4805
4814
|
this.options = options;
|
|
4806
4815
|
const adapter = _adapter || options.cowShedOptions?.adapter;
|
|
4807
4816
|
if (adapter) {
|
|
4808
|
-
(0,
|
|
4817
|
+
(0, import_sdk_common16.setGlobalAdapter)(adapter);
|
|
4809
4818
|
}
|
|
4810
4819
|
this.api = new BungeeApi(options.apiOptions);
|
|
4811
4820
|
this.cowShedSdk = new import_sdk_cow_shed2.CowShedSdk(adapter, options.cowShedOptions?.factoryOptions);
|
|
@@ -4957,7 +4966,7 @@ var BungeeBridgeProvider = class {
|
|
|
4957
4966
|
};
|
|
4958
4967
|
|
|
4959
4968
|
// src/providers/near-intents/NearIntentsBridgeProvider.ts
|
|
4960
|
-
var
|
|
4969
|
+
var import_sdk_common18 = require("@cowprotocol/sdk-common");
|
|
4961
4970
|
var import_sdk_config12 = require("@cowprotocol/sdk-config");
|
|
4962
4971
|
var import_sdk_cow_shed3 = require("@cowprotocol/sdk-cow-shed");
|
|
4963
4972
|
var import_sdk_order_book8 = require("@cowprotocol/sdk-order-book");
|
|
@@ -5050,7 +5059,7 @@ var ATTESTATOR_ADDRESS = "0x0073DD100b51C555E41B2a452E5933ef76F42790";
|
|
|
5050
5059
|
|
|
5051
5060
|
// src/providers/near-intents/util.ts
|
|
5052
5061
|
var import_json_stable_stringify3 = __toESM(require("json-stable-stringify"));
|
|
5053
|
-
var
|
|
5062
|
+
var import_sdk_common17 = require("@cowprotocol/sdk-common");
|
|
5054
5063
|
var import_sdk_config11 = require("@cowprotocol/sdk-config");
|
|
5055
5064
|
var calculateDeadline = (seconds) => {
|
|
5056
5065
|
const secs = Number(seconds);
|
|
@@ -5100,7 +5109,7 @@ var hashQuote = ({
|
|
|
5100
5109
|
quoteRequest,
|
|
5101
5110
|
timestamp
|
|
5102
5111
|
}) => {
|
|
5103
|
-
const adapter = (0,
|
|
5112
|
+
const adapter = (0, import_sdk_common17.getGlobalAdapter)();
|
|
5104
5113
|
const stringifiedQuote = (0, import_json_stable_stringify3.default)({
|
|
5105
5114
|
dry: false,
|
|
5106
5115
|
swapType: quoteRequest.swapType,
|
|
@@ -5157,7 +5166,7 @@ var NearIntentsBridgeProvider = class {
|
|
|
5157
5166
|
constructor(options, _adapter) {
|
|
5158
5167
|
const adapter = _adapter || options?.cowShedOptions?.adapter;
|
|
5159
5168
|
if (adapter) {
|
|
5160
|
-
(0,
|
|
5169
|
+
(0, import_sdk_common18.setGlobalAdapter)(adapter);
|
|
5161
5170
|
}
|
|
5162
5171
|
this.api = new NearIntentsApi();
|
|
5163
5172
|
this.cowShedSdk = new import_sdk_cow_shed3.CowShedSdk(adapter, options?.cowShedOptions?.factoryOptions);
|
|
@@ -5177,7 +5186,7 @@ var NearIntentsBridgeProvider = class {
|
|
|
5177
5186
|
if (request.kind !== import_sdk_order_book8.OrderKind.SELL) {
|
|
5178
5187
|
throw new BridgeProviderQuoteError("ONLY_SELL_ORDER_SUPPORTED" /* ONLY_SELL_ORDER_SUPPORTED */, { kind: request.kind });
|
|
5179
5188
|
}
|
|
5180
|
-
const { sellTokenChainId, buyTokenChainId, buyTokenAddress
|
|
5189
|
+
const { sellTokenChainId, buyTokenChainId, buyTokenAddress } = request;
|
|
5181
5190
|
const tokens = adaptTokens(await this.api.getTokens());
|
|
5182
5191
|
const { sourceTokens, targetTokens } = tokens.reduce(
|
|
5183
5192
|
(acc, token) => {
|
|
@@ -5197,9 +5206,7 @@ var NearIntentsBridgeProvider = class {
|
|
|
5197
5206
|
const targetToken = targetTokens.get(buyTokenAddress.toLowerCase());
|
|
5198
5207
|
if (!targetToken)
|
|
5199
5208
|
return [];
|
|
5200
|
-
return Array.from(sourceTokens.values())
|
|
5201
|
-
return token.address?.toLowerCase() !== sellTokenAddress.toLowerCase();
|
|
5202
|
-
});
|
|
5209
|
+
return Array.from(sourceTokens.values());
|
|
5203
5210
|
}
|
|
5204
5211
|
async getQuote(request) {
|
|
5205
5212
|
const {
|
|
@@ -5367,7 +5374,7 @@ var NearIntentsBridgeProvider = class {
|
|
|
5367
5374
|
try {
|
|
5368
5375
|
if (!quote?.depositAddress)
|
|
5369
5376
|
return null;
|
|
5370
|
-
const utils = (0,
|
|
5377
|
+
const utils = (0, import_sdk_common18.getGlobalAdapter)().utils;
|
|
5371
5378
|
const { hash: quoteHash, stringifiedQuote } = hashQuote({ quote, quoteRequest, timestamp });
|
|
5372
5379
|
const depositAddr = utils.getChecksumAddress(quote.depositAddress);
|
|
5373
5380
|
const { signature } = await this.api.getAttestation({
|
package/dist/index.mjs
CHANGED
|
@@ -254,8 +254,11 @@ function getHookMockForCostEstimation(gasLimit) {
|
|
|
254
254
|
// src/BridgingSdk/getIntermediateSwapResult.ts
|
|
255
255
|
import { getGlobalAdapter as getGlobalAdapter2, jsonWithBigintReplacer as jsonWithBigintReplacer2, log as log2 } from "@cowprotocol/sdk-common";
|
|
256
256
|
|
|
257
|
+
// src/BridgingSdk/determineIntermediateToken.ts
|
|
258
|
+
import { areAddressesEqual, isNativeToken, isWrappedNativeToken } from "@cowprotocol/sdk-common";
|
|
259
|
+
|
|
257
260
|
// src/BridgingSdk/tokenPriority.ts
|
|
258
|
-
import {
|
|
261
|
+
import { SupportedChainId } from "@cowprotocol/sdk-config";
|
|
259
262
|
var PRIORITY_STABLECOIN_TOKENS = {
|
|
260
263
|
[SupportedChainId.MAINNET]: /* @__PURE__ */ new Set([
|
|
261
264
|
"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
|
|
@@ -321,12 +324,9 @@ function isStablecoinPriorityToken(chainId, tokenAddress) {
|
|
|
321
324
|
function isCorrelatedToken(tokenAddress, correlatedTokens) {
|
|
322
325
|
return correlatedTokens.has(tokenAddress.toLowerCase());
|
|
323
326
|
}
|
|
324
|
-
function isNativeToken(tokenAddress) {
|
|
325
|
-
return tokenAddress.toLowerCase() === NATIVE_CURRENCY_ADDRESS.toLowerCase();
|
|
326
|
-
}
|
|
327
327
|
|
|
328
328
|
// src/BridgingSdk/determineIntermediateToken.ts
|
|
329
|
-
async function determineIntermediateToken(sourceChainId, intermediateTokens, getCorrelatedTokens) {
|
|
329
|
+
async function determineIntermediateToken(sourceChainId, sourceTokenAddress, intermediateTokens, getCorrelatedTokens) {
|
|
330
330
|
const firstToken = intermediateTokens[0];
|
|
331
331
|
if (intermediateTokens.length === 0 || !firstToken) {
|
|
332
332
|
throw new BridgeProviderQuoteError("NO_INTERMEDIATE_TOKENS" /* NO_INTERMEDIATE_TOKENS */, { intermediateTokens });
|
|
@@ -335,17 +335,25 @@ async function determineIntermediateToken(sourceChainId, intermediateTokens, get
|
|
|
335
335
|
return firstToken;
|
|
336
336
|
}
|
|
337
337
|
const correlatedTokens = await resolveCorrelatedTokens(sourceChainId, getCorrelatedTokens);
|
|
338
|
+
const sellTokenLike = { chainId: sourceChainId, address: sourceTokenAddress };
|
|
339
|
+
const isSellNativeOrWrapped = isNativeToken(sellTokenLike) || isWrappedNativeToken(sellTokenLike);
|
|
338
340
|
const tokensWithPriority = intermediateTokens.map((token) => {
|
|
341
|
+
const isNativeOrWrapped = isNativeToken(token) || isWrappedNativeToken(token);
|
|
342
|
+
if (areAddressesEqual(token.address, sourceTokenAddress)) {
|
|
343
|
+
if (!(isSellNativeOrWrapped && isNativeOrWrapped)) {
|
|
344
|
+
return { token, priority: 5 /* HIGHEST */ };
|
|
345
|
+
}
|
|
346
|
+
}
|
|
339
347
|
if (isStablecoinPriorityToken(token.chainId, token.address)) {
|
|
340
|
-
return { token, priority: 4 /*
|
|
348
|
+
return { token, priority: 4 /* HIGH */ };
|
|
341
349
|
}
|
|
342
350
|
if (isCorrelatedToken(token.address, correlatedTokens)) {
|
|
343
|
-
return { token, priority: 3 /*
|
|
351
|
+
return { token, priority: 3 /* MEDIUM */ };
|
|
344
352
|
}
|
|
345
|
-
if (isNativeToken(token
|
|
346
|
-
return { token, priority: 2 /*
|
|
353
|
+
if (isNativeToken(token) && !isSellNativeOrWrapped) {
|
|
354
|
+
return { token, priority: 2 /* LOW */ };
|
|
347
355
|
}
|
|
348
|
-
return { token, priority: 1 /*
|
|
356
|
+
return { token, priority: 1 /* LOWEST */ };
|
|
349
357
|
});
|
|
350
358
|
tokensWithPriority.sort((a, b) => {
|
|
351
359
|
if (a.priority !== b.priority) {
|
|
@@ -402,6 +410,7 @@ async function getIntermediateSwapResult({
|
|
|
402
410
|
});
|
|
403
411
|
const intermediateToken = await determineIntermediateToken(
|
|
404
412
|
sellTokenChainId,
|
|
413
|
+
sellTokenAddress,
|
|
405
414
|
intermediateTokens,
|
|
406
415
|
params.advancedSettings?.getCorrelatedTokens
|
|
407
416
|
);
|
|
@@ -5135,7 +5144,7 @@ var NearIntentsBridgeProvider = class {
|
|
|
5135
5144
|
if (request.kind !== OrderKind6.SELL) {
|
|
5136
5145
|
throw new BridgeProviderQuoteError("ONLY_SELL_ORDER_SUPPORTED" /* ONLY_SELL_ORDER_SUPPORTED */, { kind: request.kind });
|
|
5137
5146
|
}
|
|
5138
|
-
const { sellTokenChainId, buyTokenChainId, buyTokenAddress
|
|
5147
|
+
const { sellTokenChainId, buyTokenChainId, buyTokenAddress } = request;
|
|
5139
5148
|
const tokens = adaptTokens(await this.api.getTokens());
|
|
5140
5149
|
const { sourceTokens, targetTokens } = tokens.reduce(
|
|
5141
5150
|
(acc, token) => {
|
|
@@ -5155,9 +5164,7 @@ var NearIntentsBridgeProvider = class {
|
|
|
5155
5164
|
const targetToken = targetTokens.get(buyTokenAddress.toLowerCase());
|
|
5156
5165
|
if (!targetToken)
|
|
5157
5166
|
return [];
|
|
5158
|
-
return Array.from(sourceTokens.values())
|
|
5159
|
-
return token.address?.toLowerCase() !== sellTokenAddress.toLowerCase();
|
|
5160
|
-
});
|
|
5167
|
+
return Array.from(sourceTokens.values());
|
|
5161
5168
|
}
|
|
5162
5169
|
async getQuote(request) {
|
|
5163
5170
|
const {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cowprotocol/sdk-bridging",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Bridging for CoW Protocol",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -16,14 +16,14 @@
|
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@defuse-protocol/one-click-sdk-typescript": "0.1.1-0.2",
|
|
18
18
|
"json-stable-stringify": "^1.3.0",
|
|
19
|
-
"@cowprotocol/sdk-app-data": "4.5.
|
|
20
|
-
"@cowprotocol/sdk-common": "0.
|
|
21
|
-
"@cowprotocol/sdk-config": "0.6.
|
|
22
|
-
"@cowprotocol/sdk-contracts-ts": "1.
|
|
23
|
-
"@cowprotocol/sdk-
|
|
24
|
-
"@cowprotocol/sdk-
|
|
25
|
-
"@cowprotocol/sdk-
|
|
26
|
-
"@cowprotocol/sdk-
|
|
19
|
+
"@cowprotocol/sdk-app-data": "4.5.1",
|
|
20
|
+
"@cowprotocol/sdk-common": "0.5.0",
|
|
21
|
+
"@cowprotocol/sdk-config": "0.6.3",
|
|
22
|
+
"@cowprotocol/sdk-contracts-ts": "1.1.0",
|
|
23
|
+
"@cowprotocol/sdk-order-book": "0.5.1",
|
|
24
|
+
"@cowprotocol/sdk-cow-shed": "0.2.10",
|
|
25
|
+
"@cowprotocol/sdk-weiroll": "0.1.12",
|
|
26
|
+
"@cowprotocol/sdk-trading": "0.8.1"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/jest": "^29.4.0",
|
|
@@ -39,10 +39,10 @@
|
|
|
39
39
|
"typescript": "^5.2.2",
|
|
40
40
|
"viem": "^2.28.4",
|
|
41
41
|
"@cow-sdk/typescript-config": "0.0.0-beta.0",
|
|
42
|
-
"@cowprotocol/sdk-ethers-v5-adapter": "0.3.
|
|
43
|
-
"@cowprotocol/sdk-
|
|
44
|
-
"@cowprotocol/sdk-viem-adapter": "0.3.
|
|
45
|
-
"@cowprotocol/sdk-
|
|
42
|
+
"@cowprotocol/sdk-ethers-v5-adapter": "0.3.1",
|
|
43
|
+
"@cowprotocol/sdk-order-signing": "0.1.24",
|
|
44
|
+
"@cowprotocol/sdk-viem-adapter": "0.3.1",
|
|
45
|
+
"@cowprotocol/sdk-ethers-v6-adapter": "0.3.1"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"build": "tsup src/index.ts --format esm,cjs --dts",
|