@cowprotocol/sdk-bridging 1.4.0 → 1.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 +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +25 -12
- package/dist/index.mjs +25 -12
- package/package.json +7 -7
package/dist/index.d.mts
CHANGED
|
@@ -1272,6 +1272,7 @@ interface GetAttestationResponse {
|
|
|
1272
1272
|
}
|
|
1273
1273
|
declare class NearIntentsApi {
|
|
1274
1274
|
private cachedTokens;
|
|
1275
|
+
constructor(apiKey?: string);
|
|
1275
1276
|
getTokens(): Promise<TokenResponse[]>;
|
|
1276
1277
|
getQuote(request: QuoteRequest): Promise<QuoteResponse>;
|
|
1277
1278
|
getStatus(depositAddress: string): Promise<GetExecutionStatusResponse>;
|
|
@@ -1291,6 +1292,7 @@ interface NearIntentsQuoteResult extends BridgeQuoteResult {
|
|
|
1291
1292
|
}
|
|
1292
1293
|
interface NearIntentsBridgeProviderOptions {
|
|
1293
1294
|
cowShedOptions?: CowShedSdkOptions;
|
|
1295
|
+
apiKey?: string;
|
|
1294
1296
|
}
|
|
1295
1297
|
declare class NearIntentsBridgeProvider implements ReceiverAccountBridgeProvider<NearIntentsQuoteResult> {
|
|
1296
1298
|
type: "ReceiverAccountBridgeProvider";
|
package/dist/index.d.ts
CHANGED
|
@@ -1272,6 +1272,7 @@ interface GetAttestationResponse {
|
|
|
1272
1272
|
}
|
|
1273
1273
|
declare class NearIntentsApi {
|
|
1274
1274
|
private cachedTokens;
|
|
1275
|
+
constructor(apiKey?: string);
|
|
1275
1276
|
getTokens(): Promise<TokenResponse[]>;
|
|
1276
1277
|
getQuote(request: QuoteRequest): Promise<QuoteResponse>;
|
|
1277
1278
|
getStatus(depositAddress: string): Promise<GetExecutionStatusResponse>;
|
|
@@ -1291,6 +1292,7 @@ interface NearIntentsQuoteResult extends BridgeQuoteResult {
|
|
|
1291
1292
|
}
|
|
1292
1293
|
interface NearIntentsBridgeProviderOptions {
|
|
1293
1294
|
cowShedOptions?: CowShedSdkOptions;
|
|
1295
|
+
apiKey?: string;
|
|
1294
1296
|
}
|
|
1295
1297
|
declare class NearIntentsBridgeProvider implements ReceiverAccountBridgeProvider<NearIntentsQuoteResult> {
|
|
1296
1298
|
type: "ReceiverAccountBridgeProvider";
|
package/dist/index.js
CHANGED
|
@@ -383,7 +383,7 @@ function isCorrelatedToken(tokenAddress, correlatedTokens) {
|
|
|
383
383
|
}
|
|
384
384
|
|
|
385
385
|
// src/BridgingSdk/determineIntermediateToken.ts
|
|
386
|
-
async function determineIntermediateToken(sourceChainId, sourceTokenAddress, intermediateTokens, getCorrelatedTokens) {
|
|
386
|
+
async function determineIntermediateToken(sourceChainId, sourceTokenAddress, intermediateTokens, getCorrelatedTokens, allowIntermediateEqSellToken) {
|
|
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 });
|
|
@@ -394,7 +394,8 @@ async function determineIntermediateToken(sourceChainId, sourceTokenAddress, int
|
|
|
394
394
|
const correlatedTokens = await resolveCorrelatedTokens(sourceChainId, getCorrelatedTokens);
|
|
395
395
|
const sellTokenLike = { chainId: sourceChainId, address: sourceTokenAddress };
|
|
396
396
|
const isSellNativeOrWrapped = (0, import_sdk_common3.isNativeToken)(sellTokenLike) || (0, import_sdk_common3.isWrappedNativeToken)(sellTokenLike);
|
|
397
|
-
const
|
|
397
|
+
const filteredTokens = allowIntermediateEqSellToken ? intermediateTokens : intermediateTokens.filter((token) => !(0, import_sdk_common3.areAddressesEqual)(token.address, sourceTokenAddress));
|
|
398
|
+
const tokensWithPriority = filteredTokens.map((token) => {
|
|
398
399
|
const isNativeOrWrapped = (0, import_sdk_common3.isNativeToken)(token) || (0, import_sdk_common3.isWrappedNativeToken)(token);
|
|
399
400
|
if ((0, import_sdk_common3.areAddressesEqual)(token.address, sourceTokenAddress)) {
|
|
400
401
|
if (!(isSellNativeOrWrapped && isNativeOrWrapped)) {
|
|
@@ -416,11 +417,11 @@ async function determineIntermediateToken(sourceChainId, sourceTokenAddress, int
|
|
|
416
417
|
if (a.priority !== b.priority) {
|
|
417
418
|
return b.priority - a.priority;
|
|
418
419
|
}
|
|
419
|
-
return
|
|
420
|
+
return filteredTokens.indexOf(a.token) - filteredTokens.indexOf(b.token);
|
|
420
421
|
});
|
|
421
422
|
const result = tokensWithPriority[0]?.token;
|
|
422
423
|
if (!result) {
|
|
423
|
-
throw new BridgeProviderQuoteError("NO_INTERMEDIATE_TOKENS" /* NO_INTERMEDIATE_TOKENS */, { intermediateTokens });
|
|
424
|
+
throw new BridgeProviderQuoteError("NO_INTERMEDIATE_TOKENS" /* NO_INTERMEDIATE_TOKENS */, { intermediateTokens: filteredTokens });
|
|
424
425
|
}
|
|
425
426
|
return result;
|
|
426
427
|
}
|
|
@@ -445,7 +446,7 @@ async function getIntermediateSwapResult({
|
|
|
445
446
|
params,
|
|
446
447
|
getBridgeHook
|
|
447
448
|
}) {
|
|
448
|
-
const { swapAndBridgeRequest, advancedSettings, tradingSdk } = params;
|
|
449
|
+
const { swapAndBridgeRequest, advancedSettings, tradingSdk, allowIntermediateEqSellToken } = params;
|
|
449
450
|
const {
|
|
450
451
|
kind,
|
|
451
452
|
sellTokenChainId,
|
|
@@ -469,7 +470,8 @@ async function getIntermediateSwapResult({
|
|
|
469
470
|
sellTokenChainId,
|
|
470
471
|
sellTokenAddress,
|
|
471
472
|
intermediateTokens,
|
|
472
|
-
params.advancedSettings?.getCorrelatedTokens
|
|
473
|
+
params.advancedSettings?.getCorrelatedTokens,
|
|
474
|
+
allowIntermediateEqSellToken
|
|
473
475
|
);
|
|
474
476
|
(0, import_sdk_common4.log)(`Using ${intermediateToken?.name ?? intermediateToken?.address} as intermediate tokens`);
|
|
475
477
|
const bridgeRequestWithoutAmount = {
|
|
@@ -885,7 +887,8 @@ var SingleQuoteStrategy = class extends BaseSingleQuoteStrategy {
|
|
|
885
887
|
swapAndBridgeRequest: quoteBridgeRequest,
|
|
886
888
|
advancedSettings,
|
|
887
889
|
tradingSdk,
|
|
888
|
-
quoteSigner: advancedSettings?.quoteSigner
|
|
890
|
+
quoteSigner: advancedSettings?.quoteSigner,
|
|
891
|
+
allowIntermediateEqSellToken: advancedSettings?.allowIntermediateEqSellToken
|
|
889
892
|
};
|
|
890
893
|
const request2 = this.intermediateTokensCache ? {
|
|
891
894
|
...baseParams,
|
|
@@ -1021,7 +1024,8 @@ async function fetchMultiQuote(context, tradingSdk, intermediateTokensCache) {
|
|
|
1021
1024
|
swapAndBridgeRequest: quoteBridgeRequest,
|
|
1022
1025
|
advancedSettings,
|
|
1023
1026
|
tradingSdk,
|
|
1024
|
-
quoteSigner: advancedSettings?.quoteSigner
|
|
1027
|
+
quoteSigner: advancedSettings?.quoteSigner,
|
|
1028
|
+
allowIntermediateEqSellToken: advancedSettings?.allowIntermediateEqSellToken
|
|
1025
1029
|
};
|
|
1026
1030
|
const request = intermediateTokensCache ? {
|
|
1027
1031
|
...baseParams,
|
|
@@ -4976,6 +4980,11 @@ var import_one_click_sdk_typescript2 = require("@defuse-protocol/one-click-sdk-t
|
|
|
4976
4980
|
var import_one_click_sdk_typescript = require("@defuse-protocol/one-click-sdk-typescript");
|
|
4977
4981
|
var NearIntentsApi = class {
|
|
4978
4982
|
cachedTokens = [];
|
|
4983
|
+
constructor(apiKey) {
|
|
4984
|
+
if (apiKey) {
|
|
4985
|
+
import_one_click_sdk_typescript.OpenAPI.TOKEN = apiKey;
|
|
4986
|
+
}
|
|
4987
|
+
}
|
|
4979
4988
|
async getTokens() {
|
|
4980
4989
|
if (this.cachedTokens.length === 0) {
|
|
4981
4990
|
const response = await import_one_click_sdk_typescript.OneClickService.getTokens();
|
|
@@ -5005,11 +5014,15 @@ var NearIntentsApi = class {
|
|
|
5005
5014
|
return await import_one_click_sdk_typescript.OneClickService.getExecutionStatus(depositAddress);
|
|
5006
5015
|
}
|
|
5007
5016
|
async getAttestation(request) {
|
|
5017
|
+
const headers = {
|
|
5018
|
+
"Content-Type": "application/json"
|
|
5019
|
+
};
|
|
5020
|
+
if (import_one_click_sdk_typescript.OpenAPI.TOKEN) {
|
|
5021
|
+
headers["Authorization"] = `Bearer ${import_one_click_sdk_typescript.OpenAPI.TOKEN}`;
|
|
5022
|
+
}
|
|
5008
5023
|
const response = await fetch(`${import_one_click_sdk_typescript.OpenAPI.BASE}/v0/attestation`, {
|
|
5009
5024
|
method: "POST",
|
|
5010
|
-
headers
|
|
5011
|
-
"Content-Type": "application/json"
|
|
5012
|
-
},
|
|
5025
|
+
headers,
|
|
5013
5026
|
body: JSON.stringify(request)
|
|
5014
5027
|
});
|
|
5015
5028
|
if (!response.ok) {
|
|
@@ -5168,7 +5181,7 @@ var NearIntentsBridgeProvider = class {
|
|
|
5168
5181
|
if (adapter) {
|
|
5169
5182
|
(0, import_sdk_common18.setGlobalAdapter)(adapter);
|
|
5170
5183
|
}
|
|
5171
|
-
this.api = new NearIntentsApi();
|
|
5184
|
+
this.api = new NearIntentsApi(options?.apiKey);
|
|
5172
5185
|
this.cowShedSdk = new import_sdk_cow_shed3.CowShedSdk(adapter, options?.cowShedOptions?.factoryOptions);
|
|
5173
5186
|
}
|
|
5174
5187
|
async getNetworks() {
|
package/dist/index.mjs
CHANGED
|
@@ -326,7 +326,7 @@ function isCorrelatedToken(tokenAddress, correlatedTokens) {
|
|
|
326
326
|
}
|
|
327
327
|
|
|
328
328
|
// src/BridgingSdk/determineIntermediateToken.ts
|
|
329
|
-
async function determineIntermediateToken(sourceChainId, sourceTokenAddress, intermediateTokens, getCorrelatedTokens) {
|
|
329
|
+
async function determineIntermediateToken(sourceChainId, sourceTokenAddress, intermediateTokens, getCorrelatedTokens, allowIntermediateEqSellToken) {
|
|
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 });
|
|
@@ -337,7 +337,8 @@ async function determineIntermediateToken(sourceChainId, sourceTokenAddress, int
|
|
|
337
337
|
const correlatedTokens = await resolveCorrelatedTokens(sourceChainId, getCorrelatedTokens);
|
|
338
338
|
const sellTokenLike = { chainId: sourceChainId, address: sourceTokenAddress };
|
|
339
339
|
const isSellNativeOrWrapped = isNativeToken(sellTokenLike) || isWrappedNativeToken(sellTokenLike);
|
|
340
|
-
const
|
|
340
|
+
const filteredTokens = allowIntermediateEqSellToken ? intermediateTokens : intermediateTokens.filter((token) => !areAddressesEqual(token.address, sourceTokenAddress));
|
|
341
|
+
const tokensWithPriority = filteredTokens.map((token) => {
|
|
341
342
|
const isNativeOrWrapped = isNativeToken(token) || isWrappedNativeToken(token);
|
|
342
343
|
if (areAddressesEqual(token.address, sourceTokenAddress)) {
|
|
343
344
|
if (!(isSellNativeOrWrapped && isNativeOrWrapped)) {
|
|
@@ -359,11 +360,11 @@ async function determineIntermediateToken(sourceChainId, sourceTokenAddress, int
|
|
|
359
360
|
if (a.priority !== b.priority) {
|
|
360
361
|
return b.priority - a.priority;
|
|
361
362
|
}
|
|
362
|
-
return
|
|
363
|
+
return filteredTokens.indexOf(a.token) - filteredTokens.indexOf(b.token);
|
|
363
364
|
});
|
|
364
365
|
const result = tokensWithPriority[0]?.token;
|
|
365
366
|
if (!result) {
|
|
366
|
-
throw new BridgeProviderQuoteError("NO_INTERMEDIATE_TOKENS" /* NO_INTERMEDIATE_TOKENS */, { intermediateTokens });
|
|
367
|
+
throw new BridgeProviderQuoteError("NO_INTERMEDIATE_TOKENS" /* NO_INTERMEDIATE_TOKENS */, { intermediateTokens: filteredTokens });
|
|
367
368
|
}
|
|
368
369
|
return result;
|
|
369
370
|
}
|
|
@@ -388,7 +389,7 @@ async function getIntermediateSwapResult({
|
|
|
388
389
|
params,
|
|
389
390
|
getBridgeHook
|
|
390
391
|
}) {
|
|
391
|
-
const { swapAndBridgeRequest, advancedSettings, tradingSdk } = params;
|
|
392
|
+
const { swapAndBridgeRequest, advancedSettings, tradingSdk, allowIntermediateEqSellToken } = params;
|
|
392
393
|
const {
|
|
393
394
|
kind,
|
|
394
395
|
sellTokenChainId,
|
|
@@ -412,7 +413,8 @@ async function getIntermediateSwapResult({
|
|
|
412
413
|
sellTokenChainId,
|
|
413
414
|
sellTokenAddress,
|
|
414
415
|
intermediateTokens,
|
|
415
|
-
params.advancedSettings?.getCorrelatedTokens
|
|
416
|
+
params.advancedSettings?.getCorrelatedTokens,
|
|
417
|
+
allowIntermediateEqSellToken
|
|
416
418
|
);
|
|
417
419
|
log2(`Using ${intermediateToken?.name ?? intermediateToken?.address} as intermediate tokens`);
|
|
418
420
|
const bridgeRequestWithoutAmount = {
|
|
@@ -828,7 +830,8 @@ var SingleQuoteStrategy = class extends BaseSingleQuoteStrategy {
|
|
|
828
830
|
swapAndBridgeRequest: quoteBridgeRequest,
|
|
829
831
|
advancedSettings,
|
|
830
832
|
tradingSdk,
|
|
831
|
-
quoteSigner: advancedSettings?.quoteSigner
|
|
833
|
+
quoteSigner: advancedSettings?.quoteSigner,
|
|
834
|
+
allowIntermediateEqSellToken: advancedSettings?.allowIntermediateEqSellToken
|
|
832
835
|
};
|
|
833
836
|
const request2 = this.intermediateTokensCache ? {
|
|
834
837
|
...baseParams,
|
|
@@ -964,7 +967,8 @@ async function fetchMultiQuote(context, tradingSdk, intermediateTokensCache) {
|
|
|
964
967
|
swapAndBridgeRequest: quoteBridgeRequest,
|
|
965
968
|
advancedSettings,
|
|
966
969
|
tradingSdk,
|
|
967
|
-
quoteSigner: advancedSettings?.quoteSigner
|
|
970
|
+
quoteSigner: advancedSettings?.quoteSigner,
|
|
971
|
+
allowIntermediateEqSellToken: advancedSettings?.allowIntermediateEqSellToken
|
|
968
972
|
};
|
|
969
973
|
const request = intermediateTokensCache ? {
|
|
970
974
|
...baseParams,
|
|
@@ -4934,6 +4938,11 @@ import { QuoteRequest } from "@defuse-protocol/one-click-sdk-typescript";
|
|
|
4934
4938
|
import { ApiError, OneClickService, OpenAPI } from "@defuse-protocol/one-click-sdk-typescript";
|
|
4935
4939
|
var NearIntentsApi = class {
|
|
4936
4940
|
cachedTokens = [];
|
|
4941
|
+
constructor(apiKey) {
|
|
4942
|
+
if (apiKey) {
|
|
4943
|
+
OpenAPI.TOKEN = apiKey;
|
|
4944
|
+
}
|
|
4945
|
+
}
|
|
4937
4946
|
async getTokens() {
|
|
4938
4947
|
if (this.cachedTokens.length === 0) {
|
|
4939
4948
|
const response = await OneClickService.getTokens();
|
|
@@ -4963,11 +4972,15 @@ var NearIntentsApi = class {
|
|
|
4963
4972
|
return await OneClickService.getExecutionStatus(depositAddress);
|
|
4964
4973
|
}
|
|
4965
4974
|
async getAttestation(request) {
|
|
4975
|
+
const headers = {
|
|
4976
|
+
"Content-Type": "application/json"
|
|
4977
|
+
};
|
|
4978
|
+
if (OpenAPI.TOKEN) {
|
|
4979
|
+
headers["Authorization"] = `Bearer ${OpenAPI.TOKEN}`;
|
|
4980
|
+
}
|
|
4966
4981
|
const response = await fetch(`${OpenAPI.BASE}/v0/attestation`, {
|
|
4967
4982
|
method: "POST",
|
|
4968
|
-
headers
|
|
4969
|
-
"Content-Type": "application/json"
|
|
4970
|
-
},
|
|
4983
|
+
headers,
|
|
4971
4984
|
body: JSON.stringify(request)
|
|
4972
4985
|
});
|
|
4973
4986
|
if (!response.ok) {
|
|
@@ -5126,7 +5139,7 @@ var NearIntentsBridgeProvider = class {
|
|
|
5126
5139
|
if (adapter) {
|
|
5127
5140
|
setGlobalAdapter4(adapter);
|
|
5128
5141
|
}
|
|
5129
|
-
this.api = new NearIntentsApi();
|
|
5142
|
+
this.api = new NearIntentsApi(options?.apiKey);
|
|
5130
5143
|
this.cowShedSdk = new CowShedSdk3(adapter, options?.cowShedOptions?.factoryOptions);
|
|
5131
5144
|
}
|
|
5132
5145
|
async getNetworks() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cowprotocol/sdk-bridging",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.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.1",
|
|
20
19
|
"@cowprotocol/sdk-common": "0.5.0",
|
|
20
|
+
"@cowprotocol/sdk-app-data": "4.5.1",
|
|
21
21
|
"@cowprotocol/sdk-config": "0.6.3",
|
|
22
|
-
"@cowprotocol/sdk-contracts-ts": "1.
|
|
22
|
+
"@cowprotocol/sdk-contracts-ts": "1.2.0",
|
|
23
23
|
"@cowprotocol/sdk-order-book": "0.5.1",
|
|
24
|
-
"@cowprotocol/sdk-cow-shed": "0.2.
|
|
25
|
-
"@cowprotocol/sdk-
|
|
26
|
-
"@cowprotocol/sdk-
|
|
24
|
+
"@cowprotocol/sdk-cow-shed": "0.2.12",
|
|
25
|
+
"@cowprotocol/sdk-trading": "0.9.0",
|
|
26
|
+
"@cowprotocol/sdk-weiroll": "0.1.12"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/jest": "^29.4.0",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"viem": "^2.28.4",
|
|
41
41
|
"@cow-sdk/typescript-config": "0.0.0-beta.0",
|
|
42
42
|
"@cowprotocol/sdk-ethers-v5-adapter": "0.3.1",
|
|
43
|
-
"@cowprotocol/sdk-order-signing": "0.1.
|
|
43
|
+
"@cowprotocol/sdk-order-signing": "0.1.26",
|
|
44
44
|
"@cowprotocol/sdk-viem-adapter": "0.3.1",
|
|
45
45
|
"@cowprotocol/sdk-ethers-v6-adapter": "0.3.1"
|
|
46
46
|
},
|