@cowprotocol/sdk-bridging 0.6.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +77 -8
- package/dist/index.d.mts +64 -13
- package/dist/index.d.ts +64 -13
- package/dist/index.js +560 -80
- package/dist/index.mjs +608 -139
- package/package.json +20 -18
package/dist/index.mjs
CHANGED
|
@@ -18,6 +18,7 @@ var BridgeQuoteErrors = /* @__PURE__ */ ((BridgeQuoteErrors2) => {
|
|
|
18
18
|
BridgeQuoteErrors2["QUOTE_ERROR"] = "QUOTE_ERROR";
|
|
19
19
|
BridgeQuoteErrors2["NO_ROUTES"] = "NO_ROUTES";
|
|
20
20
|
BridgeQuoteErrors2["INVALID_BRIDGE"] = "INVALID_BRIDGE";
|
|
21
|
+
BridgeQuoteErrors2["QUOTE_DOES_NOT_MATCH_DEPOSIT_ADDRESS"] = "QUOTE_DOES_NOT_MATCH_DEPOSIT_ADDRESS";
|
|
21
22
|
return BridgeQuoteErrors2;
|
|
22
23
|
})(BridgeQuoteErrors || {});
|
|
23
24
|
var BridgeProviderQuoteError = class extends Error {
|
|
@@ -63,7 +64,7 @@ function getPostHooks(fullAppData) {
|
|
|
63
64
|
if (!fullAppData) {
|
|
64
65
|
return [];
|
|
65
66
|
}
|
|
66
|
-
const appData = JSON.parse(fullAppData);
|
|
67
|
+
const appData = typeof fullAppData === "string" ? JSON.parse(fullAppData) : fullAppData;
|
|
67
68
|
if (!isAppDoc(appData)) {
|
|
68
69
|
return [];
|
|
69
70
|
}
|
|
@@ -93,14 +94,18 @@ var HOOK_DAPP_BRIDGE_PROVIDER_PREFIX = "cow-sdk://bridging/providers";
|
|
|
93
94
|
|
|
94
95
|
// src/BridgingSdk/findBridgeProviderFromHook.ts
|
|
95
96
|
function findBridgeProviderFromHook(fullAppData, providers) {
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
97
|
+
const appDataObj = JSON.parse(fullAppData);
|
|
98
|
+
let bridgeProviderDappId = appDataObj?.metadata?.bridging?.providerId;
|
|
99
|
+
if (!bridgeProviderDappId) {
|
|
100
|
+
const postHooks = getPostHooks(appDataObj);
|
|
101
|
+
const bridgingHook = postHooks.find((hook) => {
|
|
102
|
+
return hook.dappId?.startsWith(HOOK_DAPP_BRIDGE_PROVIDER_PREFIX);
|
|
103
|
+
});
|
|
104
|
+
if (!bridgingHook) {
|
|
105
|
+
return void 0;
|
|
106
|
+
}
|
|
107
|
+
bridgeProviderDappId = bridgingHook.dappId;
|
|
102
108
|
}
|
|
103
|
-
const bridgeProviderDappId = bridgingHook.dappId;
|
|
104
109
|
return providers.find((provider) => provider.info.dappId === bridgeProviderDappId);
|
|
105
110
|
}
|
|
106
111
|
|
|
@@ -124,7 +129,7 @@ async function getCrossChainOrder(params) {
|
|
|
124
129
|
`No tx hash found for order ${orderId} . First trade, with log index ${firstTrade?.logIndex}`
|
|
125
130
|
);
|
|
126
131
|
}
|
|
127
|
-
const { params: bridgingParams, status: statusResult } = await provider.getBridgingParams(chainId,
|
|
132
|
+
const { params: bridgingParams, status: statusResult } = await provider.getBridgingParams(chainId, order, tradeTxHash) || {};
|
|
128
133
|
if (!bridgingParams || !statusResult) {
|
|
129
134
|
throw new BridgeOrderParsingError(`Bridging params cannot be derived from transaction: ${tradeTxHash}`);
|
|
130
135
|
}
|
|
@@ -282,6 +287,7 @@ async function getIntermediateSwapResult({
|
|
|
282
287
|
metadata: {
|
|
283
288
|
hooks,
|
|
284
289
|
bridging: {
|
|
290
|
+
providerId: provider.info.dappId,
|
|
285
291
|
destinationChainId: buyTokenChainId.toString(),
|
|
286
292
|
destinationTokenAddress: buyTokenAddress
|
|
287
293
|
}
|
|
@@ -323,7 +329,9 @@ async function getIntermediateTokens(params) {
|
|
|
323
329
|
intermediateTokens = cached;
|
|
324
330
|
} else {
|
|
325
331
|
intermediateTokens = await provider.getIntermediateTokens(quoteBridgeRequest);
|
|
326
|
-
|
|
332
|
+
if (intermediateTokens?.length) {
|
|
333
|
+
intermediateTokensCache?.set(cacheKey, intermediateTokens);
|
|
334
|
+
}
|
|
327
335
|
}
|
|
328
336
|
if (intermediateTokens.length === 0) {
|
|
329
337
|
throw new BridgeProviderQuoteError("NO_INTERMEDIATE_TOKENS" /* NO_INTERMEDIATE_TOKENS */);
|
|
@@ -378,13 +386,22 @@ async function getQuoteWithBridge(provider, params) {
|
|
|
378
386
|
throw new Error("Provider type is unknown: " + provider.type);
|
|
379
387
|
}
|
|
380
388
|
function createPostSwapOrderFromQuote(params) {
|
|
381
|
-
const { getBridgeProviderQuote, signer, sellTokenAddress, orderBookApi } = params;
|
|
389
|
+
const { provider, getBridgeProviderQuote, signer, sellTokenAddress, orderBookApi, initialSwapResult } = params;
|
|
382
390
|
return async function postSwapOrderFromQuote(advancedSettings, signingStepManager) {
|
|
383
391
|
await signingStepManager?.beforeBridgingSign?.();
|
|
384
|
-
const
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
392
|
+
const skipQuoteRefetch = isReceiverAccountBridgeProvider(provider);
|
|
393
|
+
const appDataOverride = advancedSettings?.appData;
|
|
394
|
+
const appDataInfo = appDataOverride && skipQuoteRefetch ? await mergeAppDataDoc(initialSwapResult.appDataInfo.doc, appDataOverride) : initialSwapResult.appDataInfo;
|
|
395
|
+
const swapResult = skipQuoteRefetch ? {
|
|
396
|
+
...initialSwapResult,
|
|
397
|
+
appDataInfo
|
|
398
|
+
} : (
|
|
399
|
+
// Sign the hooks with the real signer
|
|
400
|
+
(await getBridgeProviderQuote(signer, advancedSettings).catch((error) => {
|
|
401
|
+
signingStepManager?.onBridgingSignError?.();
|
|
402
|
+
throw error;
|
|
403
|
+
})).swapResult
|
|
404
|
+
);
|
|
388
405
|
await signingStepManager?.afterBridgingSign?.();
|
|
389
406
|
const quoteResults = {
|
|
390
407
|
result: {
|
|
@@ -451,10 +468,12 @@ async function getQuoteWithReceiverAccountBridge(provider, params) {
|
|
|
451
468
|
swap: result.swapResult,
|
|
452
469
|
bridge: result.bridgeResult,
|
|
453
470
|
postSwapOrderFromQuote: createPostSwapOrderFromQuote({
|
|
471
|
+
provider,
|
|
454
472
|
getBridgeProviderQuote,
|
|
455
473
|
signer,
|
|
456
474
|
sellTokenAddress: swapAndBridgeRequest.sellTokenAddress,
|
|
457
|
-
orderBookApi
|
|
475
|
+
orderBookApi,
|
|
476
|
+
initialSwapResult: result.swapResult
|
|
458
477
|
})
|
|
459
478
|
};
|
|
460
479
|
}
|
|
@@ -533,7 +552,9 @@ async function getQuoteWithHookBridge(provider, params) {
|
|
|
533
552
|
getBridgeProviderQuote: (signer2, advancedSettings) => getBridgeProviderQuote(signer2, hookEstimatedGasLimit, advancedSettings),
|
|
534
553
|
signer,
|
|
535
554
|
sellTokenAddress: swapAndBridgeRequest.sellTokenAddress,
|
|
536
|
-
orderBookApi
|
|
555
|
+
orderBookApi,
|
|
556
|
+
provider,
|
|
557
|
+
initialSwapResult: result.swapResult
|
|
537
558
|
})
|
|
538
559
|
};
|
|
539
560
|
}
|
|
@@ -620,10 +641,9 @@ var SingleQuoteStrategy = class extends BaseSingleQuoteStrategy {
|
|
|
620
641
|
constructor(intermediateTokensCache) {
|
|
621
642
|
super(intermediateTokensCache);
|
|
622
643
|
}
|
|
623
|
-
async execute(request,
|
|
644
|
+
async execute(request, tradingSdk, providers) {
|
|
624
645
|
const { quoteBridgeRequest, advancedSettings } = request;
|
|
625
646
|
const { sellTokenChainId, buyTokenChainId } = quoteBridgeRequest;
|
|
626
|
-
const { tradingSdk, providers } = config;
|
|
627
647
|
if (sellTokenChainId !== buyTokenChainId) {
|
|
628
648
|
const provider = providers[0];
|
|
629
649
|
if (!provider) {
|
|
@@ -659,7 +679,7 @@ function validateCrossChainRequest(sellTokenChainId, buyTokenChainId) {
|
|
|
659
679
|
);
|
|
660
680
|
}
|
|
661
681
|
}
|
|
662
|
-
function
|
|
682
|
+
function createBridgeRequestTimeoutPromise(timeoutMs, prefix) {
|
|
663
683
|
return new Promise((_, reject) => {
|
|
664
684
|
setTimeout(() => {
|
|
665
685
|
reject(new BridgeProviderError(`${prefix} timeout after ${timeoutMs}ms`, {}));
|
|
@@ -688,11 +708,11 @@ function fillTimeoutResults(results, providersToQuery) {
|
|
|
688
708
|
}
|
|
689
709
|
}
|
|
690
710
|
}
|
|
691
|
-
async function executeProviderQuotes(promises, timeout,
|
|
711
|
+
async function executeProviderQuotes(promises, timeout, providers) {
|
|
692
712
|
try {
|
|
693
713
|
await Promise.race([
|
|
694
714
|
Promise.allSettled(promises),
|
|
695
|
-
|
|
715
|
+
createBridgeRequestTimeoutPromise(timeout, `Multi-quote with ${providers.length}`)
|
|
696
716
|
]);
|
|
697
717
|
} catch {
|
|
698
718
|
console.warn("getMultiQuotes timeout occurred, returning partial results");
|
|
@@ -743,11 +763,11 @@ var MultiQuoteStrategy = class extends BaseMultiQuoteStrategy {
|
|
|
743
763
|
constructor(intermediateTokensCache) {
|
|
744
764
|
super(intermediateTokensCache);
|
|
745
765
|
}
|
|
746
|
-
async execute(request,
|
|
766
|
+
async execute(request, tradingSdk, providers) {
|
|
747
767
|
const { quoteBridgeRequest, providerDappIds, advancedSettings, options } = request;
|
|
748
768
|
const { sellTokenChainId, buyTokenChainId } = quoteBridgeRequest;
|
|
749
769
|
validateCrossChainRequest(sellTokenChainId, buyTokenChainId);
|
|
750
|
-
const providersToQuery = resolveProvidersToQuery(providerDappIds,
|
|
770
|
+
const providersToQuery = resolveProvidersToQuery(providerDappIds, providers);
|
|
751
771
|
const {
|
|
752
772
|
onQuoteResult,
|
|
753
773
|
totalTimeout = DEFAULT_TOTAL_TIMEOUT_MS,
|
|
@@ -769,10 +789,10 @@ var MultiQuoteStrategy = class extends BaseMultiQuoteStrategy {
|
|
|
769
789
|
results,
|
|
770
790
|
index: i
|
|
771
791
|
};
|
|
772
|
-
const promise = this.createProviderQuotePromise(context,
|
|
792
|
+
const promise = this.createProviderQuotePromise(context, tradingSdk);
|
|
773
793
|
promises.push(promise);
|
|
774
794
|
}
|
|
775
|
-
await executeProviderQuotes(promises, totalTimeout,
|
|
795
|
+
await executeProviderQuotes(promises, totalTimeout, providers);
|
|
776
796
|
fillTimeoutResults(results, providersToQuery);
|
|
777
797
|
results.sort((a, b) => {
|
|
778
798
|
if (isBetterQuote(a, b))
|
|
@@ -783,14 +803,14 @@ var MultiQuoteStrategy = class extends BaseMultiQuoteStrategy {
|
|
|
783
803
|
});
|
|
784
804
|
return results;
|
|
785
805
|
}
|
|
786
|
-
createProviderQuotePromise(context,
|
|
806
|
+
createProviderQuotePromise(context, tradingSdk) {
|
|
787
807
|
const { provider, quoteBridgeRequest, advancedSettings, providerTimeout, onQuoteResult, results, index } = context;
|
|
788
808
|
return (async () => {
|
|
789
809
|
try {
|
|
790
810
|
const baseParams = {
|
|
791
811
|
swapAndBridgeRequest: quoteBridgeRequest,
|
|
792
812
|
advancedSettings,
|
|
793
|
-
tradingSdk
|
|
813
|
+
tradingSdk,
|
|
794
814
|
quoteSigner: advancedSettings?.quoteSigner
|
|
795
815
|
};
|
|
796
816
|
const request = this.intermediateTokensCache ? {
|
|
@@ -799,7 +819,7 @@ var MultiQuoteStrategy = class extends BaseMultiQuoteStrategy {
|
|
|
799
819
|
} : baseParams;
|
|
800
820
|
const quote = await Promise.race([
|
|
801
821
|
getQuoteWithBridge(provider, request),
|
|
802
|
-
|
|
822
|
+
createBridgeRequestTimeoutPromise(providerTimeout, `Provider ${provider.info.dappId}`)
|
|
803
823
|
]);
|
|
804
824
|
const result = {
|
|
805
825
|
providerDappId: provider.info.dappId,
|
|
@@ -829,11 +849,11 @@ var BestQuoteStrategy = class extends BaseBestQuoteStrategy {
|
|
|
829
849
|
constructor(intermediateTokensCache) {
|
|
830
850
|
super(intermediateTokensCache);
|
|
831
851
|
}
|
|
832
|
-
async execute(request,
|
|
852
|
+
async execute(request, tradingSdk, providers) {
|
|
833
853
|
const { quoteBridgeRequest, providerDappIds, advancedSettings, options } = request;
|
|
834
854
|
const { sellTokenChainId, buyTokenChainId } = quoteBridgeRequest;
|
|
835
855
|
validateCrossChainRequest(sellTokenChainId, buyTokenChainId);
|
|
836
|
-
const providersToQuery = resolveProvidersToQuery(providerDappIds,
|
|
856
|
+
const providersToQuery = resolveProvidersToQuery(providerDappIds, providers);
|
|
837
857
|
const {
|
|
838
858
|
onQuoteResult,
|
|
839
859
|
totalTimeout = DEFAULT_TOTAL_TIMEOUT_MS2,
|
|
@@ -852,20 +872,20 @@ var BestQuoteStrategy = class extends BaseBestQuoteStrategy {
|
|
|
852
872
|
bestResult,
|
|
853
873
|
firstError
|
|
854
874
|
};
|
|
855
|
-
const promise = this.createBestQuoteProviderPromise(context,
|
|
875
|
+
const promise = this.createBestQuoteProviderPromise(context, tradingSdk);
|
|
856
876
|
promises.push(promise);
|
|
857
877
|
}
|
|
858
|
-
await executeProviderQuotes(promises, totalTimeout,
|
|
878
|
+
await executeProviderQuotes(promises, totalTimeout, providers);
|
|
859
879
|
return bestResult.current || firstError.current;
|
|
860
880
|
}
|
|
861
|
-
createBestQuoteProviderPromise(context,
|
|
881
|
+
createBestQuoteProviderPromise(context, tradingSdk) {
|
|
862
882
|
const { provider, quoteBridgeRequest, advancedSettings, providerTimeout, onQuoteResult, bestResult, firstError } = context;
|
|
863
883
|
return (async () => {
|
|
864
884
|
try {
|
|
865
885
|
const baseParams = {
|
|
866
886
|
swapAndBridgeRequest: quoteBridgeRequest,
|
|
867
887
|
advancedSettings,
|
|
868
|
-
tradingSdk
|
|
888
|
+
tradingSdk,
|
|
869
889
|
provider,
|
|
870
890
|
quoteSigner: advancedSettings?.quoteSigner
|
|
871
891
|
};
|
|
@@ -875,7 +895,7 @@ var BestQuoteStrategy = class extends BaseBestQuoteStrategy {
|
|
|
875
895
|
} : baseParams;
|
|
876
896
|
const quote = await Promise.race([
|
|
877
897
|
getQuoteWithBridge(provider, request),
|
|
878
|
-
|
|
898
|
+
createBridgeRequestTimeoutPromise(providerTimeout, `Provider ${provider.info.dappId}`)
|
|
879
899
|
]);
|
|
880
900
|
const result = {
|
|
881
901
|
providerDappId: provider.info.dappId,
|
|
@@ -913,10 +933,11 @@ function createStrategies(intermediateTokensCache) {
|
|
|
913
933
|
var DEFAULT_CACHE_CONFIG = {
|
|
914
934
|
enabled: true,
|
|
915
935
|
intermediateTokensTtl: 5 * 60 * 1e3,
|
|
916
|
-
//
|
|
936
|
+
// 2 minutes
|
|
917
937
|
buyTokensTtl: 2 * 60 * 1e3
|
|
918
938
|
// 2 minutes
|
|
919
939
|
};
|
|
940
|
+
var DEFAULT_MULTI_PROVIDER_REQUEST_TIMEOUT = 10 * 1e3;
|
|
920
941
|
var BridgingSdk = class {
|
|
921
942
|
constructor(options, adapter) {
|
|
922
943
|
this.options = options;
|
|
@@ -963,18 +984,18 @@ var BridgingSdk = class {
|
|
|
963
984
|
singleQuoteStrategy;
|
|
964
985
|
multiQuoteStrategy;
|
|
965
986
|
bestQuoteStrategy;
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
throw new BridgeProviderError("No provider found", { config: this.config });
|
|
970
|
-
}
|
|
971
|
-
return providers[0];
|
|
987
|
+
availableProvidersIds = [];
|
|
988
|
+
setAvailableProviders(ids) {
|
|
989
|
+
this.availableProvidersIds = ids;
|
|
972
990
|
}
|
|
973
991
|
/**
|
|
974
992
|
* Get the providers for the bridging.
|
|
975
993
|
*/
|
|
976
|
-
|
|
977
|
-
|
|
994
|
+
getAvailableProviders() {
|
|
995
|
+
if (this.availableProvidersIds.length === 0) {
|
|
996
|
+
return this.config.providers;
|
|
997
|
+
}
|
|
998
|
+
return this.config.providers.filter((provider) => this.availableProvidersIds.includes(provider.info.dappId));
|
|
978
999
|
}
|
|
979
1000
|
/**
|
|
980
1001
|
* Get the available sources networks for the bridging.
|
|
@@ -986,7 +1007,21 @@ var BridgingSdk = class {
|
|
|
986
1007
|
* Get the available target networks for the bridging.
|
|
987
1008
|
*/
|
|
988
1009
|
async getTargetNetworks() {
|
|
989
|
-
|
|
1010
|
+
const providers = this.getAvailableProviders();
|
|
1011
|
+
const results = await Promise.race([
|
|
1012
|
+
Promise.allSettled(providers.map((provider) => provider.getNetworks())),
|
|
1013
|
+
createBridgeRequestTimeoutPromise(
|
|
1014
|
+
DEFAULT_MULTI_PROVIDER_REQUEST_TIMEOUT,
|
|
1015
|
+
`Multi-provider getTargetNetworks with ${providers.length}`
|
|
1016
|
+
)
|
|
1017
|
+
]);
|
|
1018
|
+
return results.reduce((acc, result) => {
|
|
1019
|
+
if (result.status === "fulfilled") {
|
|
1020
|
+
const networksToAdd = (result.value || []).filter((network) => !acc.includes(network));
|
|
1021
|
+
return acc.concat(networksToAdd);
|
|
1022
|
+
}
|
|
1023
|
+
return acc;
|
|
1024
|
+
}, []);
|
|
990
1025
|
}
|
|
991
1026
|
/**
|
|
992
1027
|
* Get the available buy tokens for buying in a specific target chain
|
|
@@ -994,22 +1029,32 @@ var BridgingSdk = class {
|
|
|
994
1029
|
* @param params
|
|
995
1030
|
*/
|
|
996
1031
|
async getBuyTokens(params) {
|
|
997
|
-
const
|
|
998
|
-
const
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1032
|
+
const providers = this.getAvailableProviders();
|
|
1033
|
+
const results = await Promise.race([
|
|
1034
|
+
Promise.allSettled(providers.map((provider) => this.getBuyTokensFromProvider(provider, params))),
|
|
1035
|
+
createBridgeRequestTimeoutPromise(
|
|
1036
|
+
DEFAULT_MULTI_PROVIDER_REQUEST_TIMEOUT,
|
|
1037
|
+
`Multi-provider getBuyTokens with ${providers.length}`
|
|
1038
|
+
)
|
|
1039
|
+
]);
|
|
1040
|
+
const isRouteAvailable = results.reduce((isRouteAvailable2, result) => {
|
|
1041
|
+
if (result.status === "fulfilled" && result.value.isRouteAvailable) {
|
|
1042
|
+
return true;
|
|
1043
|
+
}
|
|
1044
|
+
return isRouteAvailable2;
|
|
1045
|
+
}, false);
|
|
1046
|
+
const tokens = results.reduce((tokens2, result) => {
|
|
1047
|
+
if (result.status === "fulfilled" && result.value.tokens) {
|
|
1048
|
+
result.value.tokens.forEach((token) => {
|
|
1049
|
+
const addressLower = token.address.toLowerCase();
|
|
1050
|
+
if (!tokens2.get(addressLower)) {
|
|
1051
|
+
tokens2.set(addressLower, token);
|
|
1052
|
+
}
|
|
1053
|
+
});
|
|
1054
|
+
}
|
|
1055
|
+
return tokens2;
|
|
1056
|
+
}, /* @__PURE__ */ new Map());
|
|
1057
|
+
return { isRouteAvailable, tokens: [...tokens.values()] };
|
|
1013
1058
|
}
|
|
1014
1059
|
/**
|
|
1015
1060
|
* Get quote details, including a callback function to post the order on-chain.
|
|
@@ -1032,7 +1077,8 @@ var BridgingSdk = class {
|
|
|
1032
1077
|
quoteBridgeRequest,
|
|
1033
1078
|
advancedSettings
|
|
1034
1079
|
},
|
|
1035
|
-
this.config
|
|
1080
|
+
this.config.tradingSdk,
|
|
1081
|
+
this.getAvailableProviders()
|
|
1036
1082
|
);
|
|
1037
1083
|
}
|
|
1038
1084
|
/**
|
|
@@ -1051,7 +1097,7 @@ var BridgingSdk = class {
|
|
|
1051
1097
|
* ```
|
|
1052
1098
|
*/
|
|
1053
1099
|
async getMultiQuotes(request) {
|
|
1054
|
-
return this.multiQuoteStrategy.execute(request, this.config);
|
|
1100
|
+
return this.multiQuoteStrategy.execute(request, this.config.tradingSdk, this.getAvailableProviders());
|
|
1055
1101
|
}
|
|
1056
1102
|
/**
|
|
1057
1103
|
* Get the best quote from multiple bridge providers with progressive updates.
|
|
@@ -1069,7 +1115,7 @@ var BridgingSdk = class {
|
|
|
1069
1115
|
* @throws Error if the request is for a single-chain swap (sellTokenChainId === buyTokenChainId)
|
|
1070
1116
|
*/
|
|
1071
1117
|
async getBestQuote(request) {
|
|
1072
|
-
return this.bestQuoteStrategy.execute(request, this.config);
|
|
1118
|
+
return this.bestQuoteStrategy.execute(request, this.config.tradingSdk, this.getAvailableProviders());
|
|
1073
1119
|
}
|
|
1074
1120
|
async getOrder(params) {
|
|
1075
1121
|
const { orderBookApi } = this.config;
|
|
@@ -1079,14 +1125,11 @@ var BridgingSdk = class {
|
|
|
1079
1125
|
orderId,
|
|
1080
1126
|
orderBookApi,
|
|
1081
1127
|
env,
|
|
1082
|
-
providers: this.
|
|
1128
|
+
providers: this.getAvailableProviders()
|
|
1083
1129
|
});
|
|
1084
1130
|
}
|
|
1085
|
-
async getOrderBridgingStatus(bridgingId, originChainId) {
|
|
1086
|
-
return this.provider.getStatus(bridgingId, originChainId);
|
|
1087
|
-
}
|
|
1088
1131
|
getProviderFromAppData(fullAppData) {
|
|
1089
|
-
return findBridgeProviderFromHook(fullAppData, this.
|
|
1132
|
+
return findBridgeProviderFromHook(fullAppData, this.getAvailableProviders());
|
|
1090
1133
|
}
|
|
1091
1134
|
/**
|
|
1092
1135
|
* Clear all caches. Useful for testing and debugging.
|
|
@@ -1112,7 +1155,25 @@ var BridgingSdk = class {
|
|
|
1112
1155
|
};
|
|
1113
1156
|
}
|
|
1114
1157
|
getProviderByDappId(dappId) {
|
|
1115
|
-
return this.
|
|
1158
|
+
return this.getAvailableProviders().find((provider) => provider.info.dappId === dappId);
|
|
1159
|
+
}
|
|
1160
|
+
async getBuyTokensFromProvider(provider, params) {
|
|
1161
|
+
const providerId = provider.info.dappId;
|
|
1162
|
+
const cacheKey = getCacheKey({
|
|
1163
|
+
id: providerId,
|
|
1164
|
+
buyChainId: params.buyChainId.toString(),
|
|
1165
|
+
sellChainId: params.sellChainId?.toString(),
|
|
1166
|
+
tokenAddress: params.sellTokenAddress
|
|
1167
|
+
});
|
|
1168
|
+
const cached = this.cacheConfig.enabled && this.buyTokensCache.get(cacheKey);
|
|
1169
|
+
if (cached) {
|
|
1170
|
+
return cached;
|
|
1171
|
+
}
|
|
1172
|
+
const result = await provider.getBuyTokens(params);
|
|
1173
|
+
if (this.cacheConfig.enabled) {
|
|
1174
|
+
this.buyTokensCache.set(cacheKey, result);
|
|
1175
|
+
}
|
|
1176
|
+
return result;
|
|
1116
1177
|
}
|
|
1117
1178
|
};
|
|
1118
1179
|
|
|
@@ -1230,55 +1291,55 @@ var ACROSS_DEPOSIT_EVENT_INTERFACE = () => {
|
|
|
1230
1291
|
};
|
|
1231
1292
|
var COW_TRADE_EVENT_INTERFACE = () => {
|
|
1232
1293
|
return getGlobalAdapter4().utils.createInterface([
|
|
1233
|
-
"event Trade(address owner, address sellToken, address buyToken, uint256 sellAmount, uint256 buyAmount, uint256 feeAmount, bytes orderUid)"
|
|
1294
|
+
"event Trade(address indexed owner, address sellToken, address buyToken, uint256 sellAmount, uint256 buyAmount, uint256 feeAmount, bytes orderUid)"
|
|
1234
1295
|
]);
|
|
1235
1296
|
};
|
|
1236
1297
|
|
|
1237
1298
|
// src/providers/across/const/contracts.ts
|
|
1238
|
-
import { AdditionalTargetChainId, SupportedChainId
|
|
1299
|
+
import { AdditionalTargetChainId, SupportedChainId } from "@cowprotocol/sdk-config";
|
|
1239
1300
|
var ACROSS_SPOOK_CONTRACT_ADDRESSES = {
|
|
1240
1301
|
// https://docs.across.to/reference/contract-addresses/mainnet-chain-id-1
|
|
1241
|
-
[
|
|
1302
|
+
[SupportedChainId.MAINNET]: "0x5c7BCd6E7De5423a257D81B442095A1a6ced35C5",
|
|
1242
1303
|
// https://docs.across.to/reference/contract-addresses/arbitrum-chain-id-42161-1
|
|
1243
|
-
[
|
|
1304
|
+
[SupportedChainId.ARBITRUM_ONE]: "0xe35e9842fceaca96570b734083f4a58e8f7c5f2a",
|
|
1244
1305
|
// https://docs.across.to/reference/contract-addresses/base-chain-id-8453
|
|
1245
|
-
[
|
|
1306
|
+
[SupportedChainId.BASE]: "0x09aea4b2242abC8bb4BB78D537A67a245A7bEC64",
|
|
1246
1307
|
// // https://docs.across.to/reference/contract-addresses/mainnet-chain-id-1
|
|
1247
|
-
[
|
|
1308
|
+
[SupportedChainId.SEPOLIA]: "0x5ef6C01E11889d86803e0B23e3cB3F9E9d97B662",
|
|
1248
1309
|
// https://docs.across.to/reference/contract-addresses/polygon-chain-id-137
|
|
1249
|
-
[
|
|
1310
|
+
[SupportedChainId.POLYGON]: "0x9295ee1d8C5b022Be115A2AD3c30C72E34e7F096",
|
|
1250
1311
|
// https://docs.across.to/reference/contract-addresses/lens-chain-id-232
|
|
1251
|
-
[
|
|
1312
|
+
[SupportedChainId.LENS]: "0xe7cb3e167e7475dE1331Cf6E0CEb187654619E12",
|
|
1252
1313
|
// https://docs.across.to/reference/contract-addresses/bnb-smart-chain
|
|
1253
|
-
[
|
|
1314
|
+
[SupportedChainId.BNB]: "0x4e8E101924eDE233C13e2D8622DC8aED2872d505",
|
|
1254
1315
|
// https://docs.across.to/reference/contract-addresses/linea-chain-id-59144
|
|
1255
|
-
[
|
|
1316
|
+
[SupportedChainId.LINEA]: "0xE0BCff426509723B18D6b2f0D8F4602d143bE3e0",
|
|
1256
1317
|
// https://docs.across.to/reference/contract-addresses/plasma
|
|
1257
|
-
[
|
|
1318
|
+
[SupportedChainId.PLASMA]: "0x50039fAEfebef707cFD94D6d462fE6D10B39207a",
|
|
1258
1319
|
// Not supported chains
|
|
1259
1320
|
// TODO: This first integration is a draft, some of this chains might be supported, so we will need to update here as we iterate on the provider
|
|
1260
|
-
[
|
|
1261
|
-
[
|
|
1321
|
+
[SupportedChainId.GNOSIS_CHAIN]: void 0,
|
|
1322
|
+
[SupportedChainId.AVALANCHE]: void 0,
|
|
1262
1323
|
[AdditionalTargetChainId.OPTIMISM]: void 0
|
|
1263
1324
|
};
|
|
1264
1325
|
var ACROSS_MATH_CONTRACT_ADDRESSES = {
|
|
1265
|
-
[
|
|
1266
|
-
[
|
|
1267
|
-
[
|
|
1326
|
+
[SupportedChainId.MAINNET]: "0xf2ae6728b6f146556977Af0A68bFbf5bADA22863",
|
|
1327
|
+
[SupportedChainId.ARBITRUM_ONE]: "0x5771A4b4029832e79a75De7B485E5fBbec28848f",
|
|
1328
|
+
[SupportedChainId.BASE]: "0xd4e943dc6ddc885f6229ce33c2e3dfe402a12c81",
|
|
1268
1329
|
// Not supported chains
|
|
1269
1330
|
// TODO: This first integration is a draft, some of this chains might be supported, so we will need to update here as we iterate on the provider
|
|
1270
|
-
[
|
|
1271
|
-
[
|
|
1272
|
-
[
|
|
1331
|
+
[SupportedChainId.GNOSIS_CHAIN]: void 0,
|
|
1332
|
+
[SupportedChainId.SEPOLIA]: void 0,
|
|
1333
|
+
[SupportedChainId.POLYGON]: void 0,
|
|
1273
1334
|
[AdditionalTargetChainId.OPTIMISM]: void 0,
|
|
1274
|
-
[
|
|
1275
|
-
[
|
|
1335
|
+
[SupportedChainId.AVALANCHE]: void 0,
|
|
1336
|
+
[SupportedChainId.LENS]: void 0,
|
|
1276
1337
|
// TODO: confirm
|
|
1277
|
-
[
|
|
1338
|
+
[SupportedChainId.BNB]: void 0,
|
|
1278
1339
|
// TODO: confirm
|
|
1279
|
-
[
|
|
1340
|
+
[SupportedChainId.LINEA]: void 0,
|
|
1280
1341
|
// TODO: confirm
|
|
1281
|
-
[
|
|
1342
|
+
[SupportedChainId.PLASMA]: void 0
|
|
1282
1343
|
// TODO: confirm
|
|
1283
1344
|
};
|
|
1284
1345
|
|
|
@@ -3360,8 +3421,9 @@ import { OrderKind as OrderKind3 } from "@cowprotocol/sdk-order-book";
|
|
|
3360
3421
|
var ACROSS_HOOK_DAPP_ID = `${HOOK_DAPP_BRIDGE_PROVIDER_PREFIX}/across`;
|
|
3361
3422
|
var ACROSS_SUPPORTED_NETWORKS = [mainnet, polygon, arbitrumOne, base, optimism];
|
|
3362
3423
|
var SLIPPAGE_TOLERANCE_BPS = 0;
|
|
3424
|
+
var providerType = "HookBridgeProvider";
|
|
3363
3425
|
var AcrossBridgeProvider = class {
|
|
3364
|
-
type =
|
|
3426
|
+
type = providerType;
|
|
3365
3427
|
api;
|
|
3366
3428
|
cowShedSdk;
|
|
3367
3429
|
supportedTokens = null;
|
|
@@ -3377,7 +3439,8 @@ var AcrossBridgeProvider = class {
|
|
|
3377
3439
|
name: "Across",
|
|
3378
3440
|
logoUrl: `${RAW_PROVIDERS_FILES_PATH}/across/across-logo.png`,
|
|
3379
3441
|
dappId: ACROSS_HOOK_DAPP_ID,
|
|
3380
|
-
website: "https://across.to"
|
|
3442
|
+
website: "https://across.to",
|
|
3443
|
+
type: providerType
|
|
3381
3444
|
};
|
|
3382
3445
|
async getNetworks() {
|
|
3383
3446
|
return ACROSS_SUPPORTED_NETWORKS;
|
|
@@ -3462,7 +3525,8 @@ var AcrossBridgeProvider = class {
|
|
|
3462
3525
|
async decodeBridgeHook(_hook) {
|
|
3463
3526
|
throw new Error("Not implemented");
|
|
3464
3527
|
}
|
|
3465
|
-
async getBridgingParams(chainId,
|
|
3528
|
+
async getBridgingParams(chainId, order, txHash) {
|
|
3529
|
+
const orderUid = order.uid;
|
|
3466
3530
|
const adapter = getGlobalAdapter8();
|
|
3467
3531
|
const txReceipt = await adapter.getTransactionReceipt(txHash);
|
|
3468
3532
|
if (!txReceipt)
|
|
@@ -3650,7 +3714,7 @@ function toAmountsAndCosts2(request, slippageBps, bungeeQuote) {
|
|
|
3650
3714
|
const buyAmountBeforeFee = getBigNumber2(buyAmountFromBungeeQuote, buyTokenDecimals).big;
|
|
3651
3715
|
const buyAmountAfterFee = buyAmountBeforeFee;
|
|
3652
3716
|
const feeSellToken = bungeeQuote.route.routeDetails.routeFee.amount;
|
|
3653
|
-
const feeBuyToken =
|
|
3717
|
+
const feeBuyToken = sellAmountBeforeFee > 0n ? BigInt(feeSellToken) * buyAmountBeforeFee / sellAmountBeforeFee : 0n;
|
|
3654
3718
|
const buyAmountAfterSlippage = applyBps2(buyAmountAfterFee, slippageBps);
|
|
3655
3719
|
const bridgeFeeBps = calculateFeeBps(BigInt(bungeeQuote.route.routeDetails.routeFee.amount), BigInt(amount));
|
|
3656
3720
|
return {
|
|
@@ -3670,7 +3734,7 @@ function toAmountsAndCosts2(request, slippageBps, bungeeQuote) {
|
|
|
3670
3734
|
bridgingFee: {
|
|
3671
3735
|
feeBps: bridgeFeeBps,
|
|
3672
3736
|
amountInSellCurrency: BigInt(feeSellToken),
|
|
3673
|
-
amountInBuyCurrency:
|
|
3737
|
+
amountInBuyCurrency: feeBuyToken
|
|
3674
3738
|
}
|
|
3675
3739
|
},
|
|
3676
3740
|
slippageBps
|
|
@@ -3723,62 +3787,62 @@ var getBungeeBridgeFromDisplayName = (displayName) => {
|
|
|
3723
3787
|
};
|
|
3724
3788
|
|
|
3725
3789
|
// src/providers/bungee/const/contracts.ts
|
|
3726
|
-
import { AdditionalTargetChainId as AdditionalTargetChainId2, SupportedChainId as
|
|
3790
|
+
import { AdditionalTargetChainId as AdditionalTargetChainId2, SupportedChainId as SupportedChainId4 } from "@cowprotocol/sdk-config";
|
|
3727
3791
|
var BUNGEE_COWSWAP_LIB_ADDRESS = "0x75b6ba5fcab20848ca00f132d253638fea82e598";
|
|
3728
3792
|
var BungeeCowswapLibAddresses = {
|
|
3729
|
-
[
|
|
3730
|
-
[
|
|
3731
|
-
[
|
|
3732
|
-
[
|
|
3733
|
-
[
|
|
3734
|
-
[
|
|
3735
|
-
[
|
|
3793
|
+
[SupportedChainId4.MAINNET]: BUNGEE_COWSWAP_LIB_ADDRESS,
|
|
3794
|
+
[SupportedChainId4.GNOSIS_CHAIN]: BUNGEE_COWSWAP_LIB_ADDRESS,
|
|
3795
|
+
[SupportedChainId4.ARBITRUM_ONE]: BUNGEE_COWSWAP_LIB_ADDRESS,
|
|
3796
|
+
[SupportedChainId4.BASE]: BUNGEE_COWSWAP_LIB_ADDRESS,
|
|
3797
|
+
[SupportedChainId4.AVALANCHE]: BUNGEE_COWSWAP_LIB_ADDRESS,
|
|
3798
|
+
[SupportedChainId4.POLYGON]: BUNGEE_COWSWAP_LIB_ADDRESS,
|
|
3799
|
+
[SupportedChainId4.LENS]: void 0,
|
|
3736
3800
|
// TODO: confirm
|
|
3737
|
-
[
|
|
3801
|
+
[SupportedChainId4.BNB]: void 0,
|
|
3738
3802
|
// TODO: confirm
|
|
3739
|
-
[
|
|
3803
|
+
[SupportedChainId4.LINEA]: void 0,
|
|
3740
3804
|
// TODO: confirm
|
|
3741
|
-
[
|
|
3805
|
+
[SupportedChainId4.PLASMA]: void 0,
|
|
3742
3806
|
// TODO: confirm
|
|
3743
|
-
[
|
|
3807
|
+
[SupportedChainId4.SEPOLIA]: void 0,
|
|
3744
3808
|
[AdditionalTargetChainId2.OPTIMISM]: BUNGEE_COWSWAP_LIB_ADDRESS
|
|
3745
3809
|
};
|
|
3746
3810
|
var SOCKET_VERIFIER_ADDRESS = "0xa27A3f5A96DF7D8Be26EE2790999860C00eb688D";
|
|
3747
3811
|
var SocketVerifierAddresses = {
|
|
3748
|
-
[
|
|
3749
|
-
[
|
|
3750
|
-
[
|
|
3751
|
-
[
|
|
3752
|
-
[
|
|
3753
|
-
[
|
|
3754
|
-
[
|
|
3812
|
+
[SupportedChainId4.MAINNET]: SOCKET_VERIFIER_ADDRESS,
|
|
3813
|
+
[SupportedChainId4.GNOSIS_CHAIN]: SOCKET_VERIFIER_ADDRESS,
|
|
3814
|
+
[SupportedChainId4.ARBITRUM_ONE]: SOCKET_VERIFIER_ADDRESS,
|
|
3815
|
+
[SupportedChainId4.BASE]: SOCKET_VERIFIER_ADDRESS,
|
|
3816
|
+
[SupportedChainId4.AVALANCHE]: SOCKET_VERIFIER_ADDRESS,
|
|
3817
|
+
[SupportedChainId4.POLYGON]: SOCKET_VERIFIER_ADDRESS,
|
|
3818
|
+
[SupportedChainId4.LENS]: void 0,
|
|
3755
3819
|
// TODO: confirm
|
|
3756
|
-
[
|
|
3820
|
+
[SupportedChainId4.BNB]: void 0,
|
|
3757
3821
|
// TODO: confirm
|
|
3758
|
-
[
|
|
3822
|
+
[SupportedChainId4.LINEA]: void 0,
|
|
3759
3823
|
// TODO: confirm
|
|
3760
|
-
[
|
|
3824
|
+
[SupportedChainId4.PLASMA]: void 0,
|
|
3761
3825
|
// TODO: confirm
|
|
3762
|
-
[
|
|
3826
|
+
[SupportedChainId4.SEPOLIA]: void 0,
|
|
3763
3827
|
[AdditionalTargetChainId2.OPTIMISM]: SOCKET_VERIFIER_ADDRESS
|
|
3764
3828
|
};
|
|
3765
3829
|
var BUNGEE_APPROVE_AND_BRIDGE_V1_ADDRESS = "0xD06a673fe1fa27B1b9E5BA0be980AB15Dbce85cc";
|
|
3766
3830
|
var BungeeApproveAndBridgeV1Addresses = {
|
|
3767
|
-
[
|
|
3768
|
-
[
|
|
3769
|
-
[
|
|
3770
|
-
[
|
|
3771
|
-
[
|
|
3772
|
-
[
|
|
3773
|
-
[
|
|
3831
|
+
[SupportedChainId4.MAINNET]: BUNGEE_APPROVE_AND_BRIDGE_V1_ADDRESS,
|
|
3832
|
+
[SupportedChainId4.GNOSIS_CHAIN]: BUNGEE_APPROVE_AND_BRIDGE_V1_ADDRESS,
|
|
3833
|
+
[SupportedChainId4.ARBITRUM_ONE]: BUNGEE_APPROVE_AND_BRIDGE_V1_ADDRESS,
|
|
3834
|
+
[SupportedChainId4.BASE]: BUNGEE_APPROVE_AND_BRIDGE_V1_ADDRESS,
|
|
3835
|
+
[SupportedChainId4.AVALANCHE]: BUNGEE_APPROVE_AND_BRIDGE_V1_ADDRESS,
|
|
3836
|
+
[SupportedChainId4.POLYGON]: BUNGEE_APPROVE_AND_BRIDGE_V1_ADDRESS,
|
|
3837
|
+
[SupportedChainId4.LENS]: void 0,
|
|
3774
3838
|
// TODO: confirm
|
|
3775
|
-
[
|
|
3839
|
+
[SupportedChainId4.BNB]: void 0,
|
|
3776
3840
|
// TODO: confirm
|
|
3777
|
-
[
|
|
3841
|
+
[SupportedChainId4.LINEA]: void 0,
|
|
3778
3842
|
// TODO: confirm
|
|
3779
|
-
[
|
|
3843
|
+
[SupportedChainId4.PLASMA]: void 0,
|
|
3780
3844
|
// TODO: confirm
|
|
3781
|
-
[
|
|
3845
|
+
[SupportedChainId4.SEPOLIA]: void 0,
|
|
3782
3846
|
[AdditionalTargetChainId2.OPTIMISM]: BUNGEE_APPROVE_AND_BRIDGE_V1_ADDRESS
|
|
3783
3847
|
};
|
|
3784
3848
|
|
|
@@ -4521,13 +4585,14 @@ import {
|
|
|
4521
4585
|
mainnet as mainnet2,
|
|
4522
4586
|
optimism as optimism2,
|
|
4523
4587
|
polygon as polygon2,
|
|
4524
|
-
SupportedChainId as
|
|
4588
|
+
SupportedChainId as SupportedChainId5
|
|
4525
4589
|
} from "@cowprotocol/sdk-config";
|
|
4526
4590
|
import { CowShedSdk as CowShedSdk2 } from "@cowprotocol/sdk-cow-shed";
|
|
4527
4591
|
import { setGlobalAdapter as setGlobalAdapter3 } from "@cowprotocol/sdk-common";
|
|
4528
4592
|
var BUNGEE_HOOK_DAPP_ID = `${HOOK_DAPP_BRIDGE_PROVIDER_PREFIX2}/bungee`;
|
|
4529
4593
|
var BUNGEE_SUPPORTED_NETWORKS = [mainnet2, polygon2, arbitrumOne2, base2, optimism2, avalanche, gnosisChain];
|
|
4530
4594
|
var SLIPPAGE_TOLERANCE_BPS2 = 0;
|
|
4595
|
+
var providerType2 = "HookBridgeProvider";
|
|
4531
4596
|
var BungeeBridgeProvider = class {
|
|
4532
4597
|
constructor(options, _adapter) {
|
|
4533
4598
|
this.options = options;
|
|
@@ -4538,14 +4603,15 @@ var BungeeBridgeProvider = class {
|
|
|
4538
4603
|
this.api = new BungeeApi(options.apiOptions);
|
|
4539
4604
|
this.cowShedSdk = new CowShedSdk2(adapter, options.cowShedOptions?.factoryOptions);
|
|
4540
4605
|
}
|
|
4541
|
-
type =
|
|
4606
|
+
type = providerType2;
|
|
4542
4607
|
api;
|
|
4543
4608
|
cowShedSdk;
|
|
4544
4609
|
info = {
|
|
4545
4610
|
name: "Bungee",
|
|
4546
4611
|
logoUrl: `${RAW_PROVIDERS_FILES_PATH}/bungee/bungee-logo.png`,
|
|
4547
4612
|
dappId: BUNGEE_HOOK_DAPP_ID,
|
|
4548
|
-
website: "https://www.bungee.exchange"
|
|
4613
|
+
website: "https://www.bungee.exchange",
|
|
4614
|
+
type: providerType2
|
|
4549
4615
|
};
|
|
4550
4616
|
async getNetworks() {
|
|
4551
4617
|
return BUNGEE_SUPPORTED_NETWORKS;
|
|
@@ -4639,7 +4705,8 @@ var BungeeBridgeProvider = class {
|
|
|
4639
4705
|
recipient: cowShedAccount
|
|
4640
4706
|
};
|
|
4641
4707
|
}
|
|
4642
|
-
async getBridgingParams(_chainId,
|
|
4708
|
+
async getBridgingParams(_chainId, order, _txHash) {
|
|
4709
|
+
const orderId = order.uid;
|
|
4643
4710
|
const events = await this.api.getEvents({ orderId });
|
|
4644
4711
|
const event = events?.[0];
|
|
4645
4712
|
if (!event)
|
|
@@ -4678,7 +4745,408 @@ var BungeeBridgeProvider = class {
|
|
|
4678
4745
|
}
|
|
4679
4746
|
isExtraGasRequired(request) {
|
|
4680
4747
|
const { sellTokenChainId, buyTokenChainId } = request;
|
|
4681
|
-
return sellTokenChainId ===
|
|
4748
|
+
return sellTokenChainId === SupportedChainId5.MAINNET && buyTokenChainId === SupportedChainId5.GNOSIS_CHAIN;
|
|
4749
|
+
}
|
|
4750
|
+
};
|
|
4751
|
+
|
|
4752
|
+
// src/providers/near-intents/NearIntentsBridgeProvider.ts
|
|
4753
|
+
import { getGlobalAdapter as getGlobalAdapter12, setGlobalAdapter as setGlobalAdapter4 } from "@cowprotocol/sdk-common";
|
|
4754
|
+
import { ETH_ADDRESS as ETH_ADDRESS3 } from "@cowprotocol/sdk-config";
|
|
4755
|
+
import { CowShedSdk as CowShedSdk3 } from "@cowprotocol/sdk-cow-shed";
|
|
4756
|
+
import { OrderKind as OrderKind6 } from "@cowprotocol/sdk-order-book";
|
|
4757
|
+
import { QuoteRequest } from "@defuse-protocol/one-click-sdk-typescript";
|
|
4758
|
+
|
|
4759
|
+
// src/providers/near-intents/NearIntentsApi.ts
|
|
4760
|
+
import { OneClickService, OpenAPI } from "@defuse-protocol/one-click-sdk-typescript";
|
|
4761
|
+
var NearIntentsApi = class {
|
|
4762
|
+
cachedTokens = [];
|
|
4763
|
+
async getTokens() {
|
|
4764
|
+
if (this.cachedTokens.length === 0) {
|
|
4765
|
+
const response = await OneClickService.getTokens();
|
|
4766
|
+
this.cachedTokens = response;
|
|
4767
|
+
}
|
|
4768
|
+
return this.cachedTokens;
|
|
4769
|
+
}
|
|
4770
|
+
async getQuote(request) {
|
|
4771
|
+
return await OneClickService.getQuote(request);
|
|
4772
|
+
}
|
|
4773
|
+
async getStatus(depositAddress) {
|
|
4774
|
+
return await OneClickService.getExecutionStatus(depositAddress);
|
|
4775
|
+
}
|
|
4776
|
+
async getAttestation(request) {
|
|
4777
|
+
const response = await fetch(`${OpenAPI.BASE}/v0/attestation`, {
|
|
4778
|
+
method: "POST",
|
|
4779
|
+
headers: {
|
|
4780
|
+
"Content-Type": "application/json"
|
|
4781
|
+
},
|
|
4782
|
+
body: JSON.stringify(request)
|
|
4783
|
+
});
|
|
4784
|
+
if (!response.ok) {
|
|
4785
|
+
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
4786
|
+
}
|
|
4787
|
+
return await response.json();
|
|
4788
|
+
}
|
|
4789
|
+
};
|
|
4790
|
+
|
|
4791
|
+
// src/providers/near-intents/const/index.ts
|
|
4792
|
+
import { arbitrumOne as arbitrumOne3, avalanche as avalanche2, base as base3, bnb, gnosisChain as gnosisChain2, mainnet as mainnet3, optimism as optimism3, polygon as polygon3 } from "@cowprotocol/sdk-config";
|
|
4793
|
+
var NEAR_INTENTS_HOOK_DAPP_ID = `${HOOK_DAPP_BRIDGE_PROVIDER_PREFIX}/near-intents`;
|
|
4794
|
+
var NEAR_INTENTS_SUPPORTED_NETWORKS = [
|
|
4795
|
+
arbitrumOne3,
|
|
4796
|
+
avalanche2,
|
|
4797
|
+
base3,
|
|
4798
|
+
bnb,
|
|
4799
|
+
gnosisChain2,
|
|
4800
|
+
mainnet3,
|
|
4801
|
+
optimism3,
|
|
4802
|
+
polygon3
|
|
4803
|
+
];
|
|
4804
|
+
var NEAR_INTENTS_BLOCKCHAIN_CHAIN_IDS = {
|
|
4805
|
+
arb: arbitrumOne3.id,
|
|
4806
|
+
avax: avalanche2.id,
|
|
4807
|
+
base: base3.id,
|
|
4808
|
+
bsc: bnb.id,
|
|
4809
|
+
eth: mainnet3.id,
|
|
4810
|
+
gnosis: gnosisChain2.id,
|
|
4811
|
+
op: optimism3.id,
|
|
4812
|
+
pol: polygon3.id
|
|
4813
|
+
};
|
|
4814
|
+
var NEAR_INTENTS_STATUS_TO_COW_STATUS = {
|
|
4815
|
+
KNOWN_DEPOSIT_TX: "in_progress" /* IN_PROGRESS */,
|
|
4816
|
+
PENDING_DEPOSIT: "in_progress" /* IN_PROGRESS */,
|
|
4817
|
+
INCOMPLETE_DEPOSIT: "unknown" /* UNKNOWN */,
|
|
4818
|
+
PROCESSING: "in_progress" /* IN_PROGRESS */,
|
|
4819
|
+
SUCCESS: "executed" /* EXECUTED */,
|
|
4820
|
+
REFUNDED: "refund" /* REFUND */,
|
|
4821
|
+
FAILED: "unknown" /* UNKNOWN */
|
|
4822
|
+
};
|
|
4823
|
+
var ATTESTATION_PREFIX_CONST = "0x0a773570";
|
|
4824
|
+
var ATTESTION_VERSION_BYTE = "0x00";
|
|
4825
|
+
var ATTESTATOR_ADDRESS = "0x0073DD100b51C555E41B2a452E5933ef76F42790";
|
|
4826
|
+
|
|
4827
|
+
// src/providers/near-intents/util.ts
|
|
4828
|
+
import stringify from "json-stable-stringify";
|
|
4829
|
+
import { getGlobalAdapter as getGlobalAdapter11 } from "@cowprotocol/sdk-common";
|
|
4830
|
+
import { ETH_ADDRESS as ETH_ADDRESS2 } from "@cowprotocol/sdk-config";
|
|
4831
|
+
var calculateDeadline = (seconds) => {
|
|
4832
|
+
const secs = Number(seconds);
|
|
4833
|
+
if (!Number.isFinite(secs)) {
|
|
4834
|
+
throw new Error(`Invalid seconds value: ${seconds}`);
|
|
4835
|
+
}
|
|
4836
|
+
const d = new Date(Date.now() + secs * 1e3);
|
|
4837
|
+
return d.toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
4838
|
+
};
|
|
4839
|
+
var adaptToken = (token) => {
|
|
4840
|
+
const chainId = NEAR_INTENTS_BLOCKCHAIN_CHAIN_IDS[token.blockchain];
|
|
4841
|
+
if (!chainId)
|
|
4842
|
+
return null;
|
|
4843
|
+
const tokenAddress = token.contractAddress || ETH_ADDRESS2;
|
|
4844
|
+
if (!tokenAddress)
|
|
4845
|
+
return null;
|
|
4846
|
+
return {
|
|
4847
|
+
chainId,
|
|
4848
|
+
decimals: token.decimals,
|
|
4849
|
+
address: tokenAddress,
|
|
4850
|
+
name: token.symbol,
|
|
4851
|
+
// TODO: how to handle? v0/tokens doesn't return the token name
|
|
4852
|
+
symbol: token.symbol
|
|
4853
|
+
};
|
|
4854
|
+
};
|
|
4855
|
+
var adaptTokens = (tokens) => tokens.reduce((acc, token) => {
|
|
4856
|
+
const adaptedToken = adaptToken(token);
|
|
4857
|
+
if (!adaptedToken)
|
|
4858
|
+
return acc;
|
|
4859
|
+
acc.push(adaptedToken);
|
|
4860
|
+
return acc;
|
|
4861
|
+
}, []);
|
|
4862
|
+
var getTokenByAddressAndChainId = (tokens, targetTokenAddress, targetTokenChainId) => {
|
|
4863
|
+
return tokens.find((token) => {
|
|
4864
|
+
const chainId = NEAR_INTENTS_BLOCKCHAIN_CHAIN_IDS[token.blockchain];
|
|
4865
|
+
if (!chainId)
|
|
4866
|
+
return false;
|
|
4867
|
+
if (targetTokenAddress.toLowerCase() === ETH_ADDRESS2.toLowerCase()) {
|
|
4868
|
+
return chainId === targetTokenChainId && !token.contractAddress;
|
|
4869
|
+
}
|
|
4870
|
+
const tokenAddress = token.contractAddress || ETH_ADDRESS2;
|
|
4871
|
+
return tokenAddress?.toLowerCase() === targetTokenAddress.toLowerCase() && chainId === targetTokenChainId;
|
|
4872
|
+
});
|
|
4873
|
+
};
|
|
4874
|
+
var hashQuote = ({
|
|
4875
|
+
quote,
|
|
4876
|
+
quoteRequest,
|
|
4877
|
+
timestamp
|
|
4878
|
+
}) => {
|
|
4879
|
+
const adapter = getGlobalAdapter11();
|
|
4880
|
+
const data = stringify({
|
|
4881
|
+
dry: false,
|
|
4882
|
+
swapType: quoteRequest.swapType,
|
|
4883
|
+
slippageTolerance: quoteRequest.slippageTolerance,
|
|
4884
|
+
originAsset: quoteRequest.originAsset,
|
|
4885
|
+
depositType: quoteRequest.depositType,
|
|
4886
|
+
destinationAsset: quoteRequest.destinationAsset,
|
|
4887
|
+
amount: quoteRequest.amount,
|
|
4888
|
+
refundTo: quoteRequest.refundTo,
|
|
4889
|
+
refundType: quoteRequest.refundType,
|
|
4890
|
+
recipient: quoteRequest.recipient,
|
|
4891
|
+
recipientType: quoteRequest.recipientType,
|
|
4892
|
+
deadline: quoteRequest.deadline,
|
|
4893
|
+
quoteWaitingTimeMs: !!quoteRequest.quoteWaitingTimeMs ? quoteRequest.quoteWaitingTimeMs : void 0,
|
|
4894
|
+
referral: !!quoteRequest.referral ? quoteRequest.referral : void 0,
|
|
4895
|
+
virtualChainRecipient: !!quoteRequest.virtualChainRecipient ? quoteRequest.virtualChainRecipient : void 0,
|
|
4896
|
+
virtualChainRefundRecipient: !!quoteRequest.virtualChainRefundRecipient ? quoteRequest.virtualChainRefundRecipient : void 0,
|
|
4897
|
+
customRecipientMsg: void 0,
|
|
4898
|
+
sessionId: void 0,
|
|
4899
|
+
connectedWallets: void 0,
|
|
4900
|
+
depositMode: quoteRequest.depositMode,
|
|
4901
|
+
amountIn: quote.amountIn,
|
|
4902
|
+
amountInFormatted: quote.amountInFormatted,
|
|
4903
|
+
amountInUsd: quote.amountInUsd,
|
|
4904
|
+
minAmountIn: quote.minAmountIn,
|
|
4905
|
+
amountOut: quote.amountOut,
|
|
4906
|
+
amountOutFormatted: quote.amountOutFormatted,
|
|
4907
|
+
amountOutUsd: quote.amountOutUsd,
|
|
4908
|
+
minAmountOut: quote.minAmountOut,
|
|
4909
|
+
timestamp
|
|
4910
|
+
});
|
|
4911
|
+
if (!data) {
|
|
4912
|
+
throw new Error("Failed to serialize quote data: quote or quoteRequest may be undefined or invalid");
|
|
4913
|
+
}
|
|
4914
|
+
return adapter.utils.sha256(adapter.utils.toUtf8Bytes(data));
|
|
4915
|
+
};
|
|
4916
|
+
|
|
4917
|
+
// src/providers/near-intents/NearIntentsBridgeProvider.ts
|
|
4918
|
+
var NEAR_INTENTS_HOOK_DAPP_ID2 = `${HOOK_DAPP_BRIDGE_PROVIDER_PREFIX}/near-intents`;
|
|
4919
|
+
var REFERRAL = "cow";
|
|
4920
|
+
var providerType3 = "ReceiverAccountBridgeProvider";
|
|
4921
|
+
var NearIntentsBridgeProvider = class {
|
|
4922
|
+
type = providerType3;
|
|
4923
|
+
api;
|
|
4924
|
+
cowShedSdk;
|
|
4925
|
+
info = {
|
|
4926
|
+
name: "Near Intents",
|
|
4927
|
+
logoUrl: `${RAW_PROVIDERS_FILES_PATH}/near-intents/near-intents-logo.png`,
|
|
4928
|
+
dappId: NEAR_INTENTS_HOOK_DAPP_ID2,
|
|
4929
|
+
website: "https://www.near.org/intents",
|
|
4930
|
+
type: providerType3
|
|
4931
|
+
};
|
|
4932
|
+
constructor(options, _adapter) {
|
|
4933
|
+
const adapter = _adapter || options?.cowShedOptions?.adapter;
|
|
4934
|
+
if (adapter) {
|
|
4935
|
+
setGlobalAdapter4(adapter);
|
|
4936
|
+
}
|
|
4937
|
+
this.api = new NearIntentsApi();
|
|
4938
|
+
this.cowShedSdk = new CowShedSdk3(adapter, options?.cowShedOptions?.factoryOptions);
|
|
4939
|
+
}
|
|
4940
|
+
async getNetworks() {
|
|
4941
|
+
return NEAR_INTENTS_SUPPORTED_NETWORKS;
|
|
4942
|
+
}
|
|
4943
|
+
async getBuyTokens(params) {
|
|
4944
|
+
const tokens = adaptTokens(await this.api.getTokens());
|
|
4945
|
+
const filteredTokens = tokens.filter((token) => token.chainId === params.buyChainId);
|
|
4946
|
+
return {
|
|
4947
|
+
tokens: filteredTokens,
|
|
4948
|
+
isRouteAvailable: filteredTokens.length > 0
|
|
4949
|
+
};
|
|
4950
|
+
}
|
|
4951
|
+
async getIntermediateTokens(request) {
|
|
4952
|
+
if (request.kind !== OrderKind6.SELL) {
|
|
4953
|
+
throw new BridgeProviderQuoteError("ONLY_SELL_ORDER_SUPPORTED" /* ONLY_SELL_ORDER_SUPPORTED */, { kind: request.kind });
|
|
4954
|
+
}
|
|
4955
|
+
const { sellTokenChainId, buyTokenChainId, buyTokenAddress, sellTokenAddress } = request;
|
|
4956
|
+
const tokens = adaptTokens(await this.api.getTokens());
|
|
4957
|
+
const { sourceTokens, targetTokens } = tokens.reduce(
|
|
4958
|
+
(acc, token) => {
|
|
4959
|
+
if (token.chainId === sellTokenChainId) {
|
|
4960
|
+
acc.sourceTokens.set(token.address.toLowerCase(), token);
|
|
4961
|
+
}
|
|
4962
|
+
if (token.chainId === buyTokenChainId) {
|
|
4963
|
+
acc.targetTokens.set(token.address.toLowerCase(), token);
|
|
4964
|
+
}
|
|
4965
|
+
return acc;
|
|
4966
|
+
},
|
|
4967
|
+
{
|
|
4968
|
+
sourceTokens: /* @__PURE__ */ new Map(),
|
|
4969
|
+
targetTokens: /* @__PURE__ */ new Map()
|
|
4970
|
+
}
|
|
4971
|
+
);
|
|
4972
|
+
const targetToken = targetTokens.get(buyTokenAddress.toLowerCase());
|
|
4973
|
+
if (!targetToken)
|
|
4974
|
+
return [];
|
|
4975
|
+
return Array.from(sourceTokens.values()).filter((token) => {
|
|
4976
|
+
return token.address?.toLowerCase() !== sellTokenAddress.toLowerCase();
|
|
4977
|
+
});
|
|
4978
|
+
}
|
|
4979
|
+
async getQuote(request) {
|
|
4980
|
+
const {
|
|
4981
|
+
sellTokenAddress,
|
|
4982
|
+
sellTokenChainId,
|
|
4983
|
+
buyTokenAddress,
|
|
4984
|
+
buyTokenChainId,
|
|
4985
|
+
account,
|
|
4986
|
+
amount,
|
|
4987
|
+
receiver,
|
|
4988
|
+
validFor,
|
|
4989
|
+
owner
|
|
4990
|
+
} = request;
|
|
4991
|
+
const tokens = await this.api.getTokens();
|
|
4992
|
+
const sellToken = getTokenByAddressAndChainId(tokens, sellTokenAddress, sellTokenChainId);
|
|
4993
|
+
const buyToken = getTokenByAddressAndChainId(tokens, buyTokenAddress, buyTokenChainId);
|
|
4994
|
+
if (!sellToken || !buyToken)
|
|
4995
|
+
throw new BridgeProviderQuoteError("NO_ROUTES" /* NO_ROUTES */);
|
|
4996
|
+
const quoteResponse = await this.api.getQuote({
|
|
4997
|
+
dry: false,
|
|
4998
|
+
swapType: QuoteRequest.swapType.EXACT_INPUT,
|
|
4999
|
+
slippageTolerance: request.slippageBps ?? 100,
|
|
5000
|
+
originAsset: sellToken.assetId,
|
|
5001
|
+
depositType: QuoteRequest.depositType.ORIGIN_CHAIN,
|
|
5002
|
+
destinationAsset: buyToken.assetId,
|
|
5003
|
+
amount: amount.toString(),
|
|
5004
|
+
refundTo: owner || account,
|
|
5005
|
+
refundType: QuoteRequest.refundType.ORIGIN_CHAIN,
|
|
5006
|
+
recipient: receiver || account,
|
|
5007
|
+
recipientType: QuoteRequest.recipientType.DESTINATION_CHAIN,
|
|
5008
|
+
deadline: calculateDeadline(validFor || 3600),
|
|
5009
|
+
referral: REFERRAL
|
|
5010
|
+
});
|
|
5011
|
+
const recoveredDepositAddress = await this.recoverDepositAddress(quoteResponse);
|
|
5012
|
+
if (recoveredDepositAddress?.toLowerCase() !== ATTESTATOR_ADDRESS.toLowerCase()) {
|
|
5013
|
+
throw new BridgeProviderQuoteError("QUOTE_DOES_NOT_MATCH_DEPOSIT_ADDRESS" /* QUOTE_DOES_NOT_MATCH_DEPOSIT_ADDRESS */);
|
|
5014
|
+
}
|
|
5015
|
+
const { quote, timestamp: isoDate } = quoteResponse;
|
|
5016
|
+
const payoutRatio = Number(quote.amountOutUsd) / Number(quote.amountInUsd);
|
|
5017
|
+
const slippage = 1 - payoutRatio;
|
|
5018
|
+
const slippageBps = Math.trunc(slippage * 1e4);
|
|
5019
|
+
const feeAmountInBuyCurrency = Math.trunc(Number(quote.amountIn) * slippage);
|
|
5020
|
+
const feeAmountInSellCurrency = Math.trunc(Number(quote.amountOut) * slippage);
|
|
5021
|
+
const bridgeFee = Math.trunc(Number(quote.amountIn) * slippage);
|
|
5022
|
+
return {
|
|
5023
|
+
isSell: request.kind === OrderKind6.SELL,
|
|
5024
|
+
depositAddress: quote.depositAddress,
|
|
5025
|
+
quoteTimestamp: new Date(isoDate).getTime(),
|
|
5026
|
+
expectedFillTimeSeconds: quote.timeEstimate,
|
|
5027
|
+
limits: {
|
|
5028
|
+
minDeposit: BigInt(quote.minAmountIn),
|
|
5029
|
+
maxDeposit: BigInt(quote.amountIn)
|
|
5030
|
+
},
|
|
5031
|
+
fees: {
|
|
5032
|
+
bridgeFee: BigInt(bridgeFee),
|
|
5033
|
+
// The bridge fee is already included in `minAmountOut`. This means `bridgeFee` represents the maximum possible fee (worst case), but the actual fee may be lower.
|
|
5034
|
+
destinationGasFee: BigInt(0)
|
|
5035
|
+
},
|
|
5036
|
+
amountsAndCosts: {
|
|
5037
|
+
beforeFee: {
|
|
5038
|
+
sellAmount: BigInt(quote.amountIn),
|
|
5039
|
+
buyAmount: BigInt(quote.amountOut)
|
|
5040
|
+
},
|
|
5041
|
+
afterFee: {
|
|
5042
|
+
sellAmount: BigInt(quote.amountIn),
|
|
5043
|
+
buyAmount: BigInt(quote.minAmountOut)
|
|
5044
|
+
},
|
|
5045
|
+
afterSlippage: {
|
|
5046
|
+
sellAmount: BigInt(quote.amountIn),
|
|
5047
|
+
buyAmount: BigInt(quote.minAmountOut)
|
|
5048
|
+
},
|
|
5049
|
+
slippageBps,
|
|
5050
|
+
costs: {
|
|
5051
|
+
bridgingFee: {
|
|
5052
|
+
feeBps: slippageBps,
|
|
5053
|
+
amountInSellCurrency: BigInt(feeAmountInSellCurrency),
|
|
5054
|
+
amountInBuyCurrency: BigInt(feeAmountInBuyCurrency)
|
|
5055
|
+
}
|
|
5056
|
+
}
|
|
5057
|
+
}
|
|
5058
|
+
};
|
|
5059
|
+
}
|
|
5060
|
+
async getBridgeReceiverOverride(_request, quote) {
|
|
5061
|
+
return quote.depositAddress;
|
|
5062
|
+
}
|
|
5063
|
+
async getBridgingParams(_chainId, order, _txHash) {
|
|
5064
|
+
const depositAddress = order.receiver;
|
|
5065
|
+
if (!depositAddress)
|
|
5066
|
+
return null;
|
|
5067
|
+
const [tokens, status] = await Promise.all([this.api.getTokens(), this.api.getStatus(depositAddress)]);
|
|
5068
|
+
const qr = status.quoteResponse?.quoteRequest;
|
|
5069
|
+
const swapDetails = status.swapDetails;
|
|
5070
|
+
const quote = status.quoteResponse?.quote;
|
|
5071
|
+
const timestampMs = Date.parse(status.quoteResponse?.timestamp ?? "");
|
|
5072
|
+
if (!qr || !quote || Number.isNaN(timestampMs)) {
|
|
5073
|
+
throw new Error("Malformed quote response from NEAR Intents");
|
|
5074
|
+
}
|
|
5075
|
+
const quoteTimestamp = Math.floor(timestampMs / 1e3);
|
|
5076
|
+
const inputToken = tokens.find((t) => t.assetId === qr.originAsset);
|
|
5077
|
+
const outputToken = tokens.find((t) => t.assetId === qr.destinationAsset);
|
|
5078
|
+
if (!inputToken || !outputToken)
|
|
5079
|
+
throw new Error("Token not supported");
|
|
5080
|
+
const adaptedInput = adaptToken(inputToken);
|
|
5081
|
+
const adaptedOutput = adaptToken(outputToken);
|
|
5082
|
+
if (!adaptedInput?.chainId || !adaptedOutput?.chainId) {
|
|
5083
|
+
throw new Error("Token not supported");
|
|
5084
|
+
}
|
|
5085
|
+
return {
|
|
5086
|
+
status: {
|
|
5087
|
+
fillTimeInSeconds: quote.timeEstimate,
|
|
5088
|
+
status: NEAR_INTENTS_STATUS_TO_COW_STATUS[status.status] ?? "unknown" /* UNKNOWN */,
|
|
5089
|
+
fillTxHash: status.swapDetails?.destinationChainTxHashes?.[0]?.hash
|
|
5090
|
+
},
|
|
5091
|
+
params: {
|
|
5092
|
+
inputTokenAddress: inputToken.contractAddress ?? ETH_ADDRESS3,
|
|
5093
|
+
outputTokenAddress: outputToken.contractAddress ?? ETH_ADDRESS3,
|
|
5094
|
+
inputAmount: BigInt(quote.amountIn),
|
|
5095
|
+
outputAmount: swapDetails.amountOut ? BigInt(swapDetails.amountOut) : BigInt(quote.amountOut),
|
|
5096
|
+
owner: order.owner,
|
|
5097
|
+
quoteTimestamp,
|
|
5098
|
+
fillDeadline: quoteTimestamp + quote.timeEstimate,
|
|
5099
|
+
recipient: qr.recipient,
|
|
5100
|
+
sourceChainId: adaptedInput.chainId,
|
|
5101
|
+
destinationChainId: adaptedOutput.chainId,
|
|
5102
|
+
bridgingId: depositAddress
|
|
5103
|
+
// NEAR Intents deposit address
|
|
5104
|
+
}
|
|
5105
|
+
};
|
|
5106
|
+
}
|
|
5107
|
+
getExplorerUrl(bridgingId) {
|
|
5108
|
+
return `https://explorer.near-intents.org/transactions/${bridgingId}`;
|
|
5109
|
+
}
|
|
5110
|
+
async getStatus(bridgingId, _originChainId) {
|
|
5111
|
+
try {
|
|
5112
|
+
const statusResponse = await this.api.getStatus(bridgingId);
|
|
5113
|
+
return {
|
|
5114
|
+
status: NEAR_INTENTS_STATUS_TO_COW_STATUS[statusResponse.status] || "unknown" /* UNKNOWN */,
|
|
5115
|
+
depositTxHash: statusResponse.swapDetails?.originChainTxHashes[0]?.hash,
|
|
5116
|
+
fillTxHash: statusResponse.swapDetails?.destinationChainTxHashes[0]?.hash
|
|
5117
|
+
};
|
|
5118
|
+
} catch {
|
|
5119
|
+
return {
|
|
5120
|
+
status: "unknown" /* UNKNOWN */
|
|
5121
|
+
};
|
|
5122
|
+
}
|
|
5123
|
+
}
|
|
5124
|
+
getCancelBridgingTx(_bridgingId) {
|
|
5125
|
+
throw new Error("Not implemented");
|
|
5126
|
+
}
|
|
5127
|
+
getRefundBridgingTx(_bridgingId) {
|
|
5128
|
+
throw new Error("Not implemented");
|
|
5129
|
+
}
|
|
5130
|
+
async recoverDepositAddress({ quote, quoteRequest, timestamp }) {
|
|
5131
|
+
try {
|
|
5132
|
+
if (!quote?.depositAddress)
|
|
5133
|
+
return null;
|
|
5134
|
+
const utils = getGlobalAdapter12().utils;
|
|
5135
|
+
const quoteHash = hashQuote({ quote, quoteRequest, timestamp });
|
|
5136
|
+
const depositAddr = utils.getChecksumAddress(quote.depositAddress);
|
|
5137
|
+
const { signature } = await this.api.getAttestation({
|
|
5138
|
+
quoteHash,
|
|
5139
|
+
depositAddress: depositAddr
|
|
5140
|
+
});
|
|
5141
|
+
if (!signature || !utils.isHexString(signature))
|
|
5142
|
+
return null;
|
|
5143
|
+
const payload = utils.hexConcat([depositAddr, quoteHash]);
|
|
5144
|
+
const messageBytes = utils.hexConcat([ATTESTATION_PREFIX_CONST, ATTESTION_VERSION_BYTE, payload]);
|
|
5145
|
+
const hash = utils.keccak256(messageBytes);
|
|
5146
|
+
return utils.recoverAddress(hash, signature);
|
|
5147
|
+
} catch {
|
|
5148
|
+
return null;
|
|
5149
|
+
}
|
|
4682
5150
|
}
|
|
4683
5151
|
};
|
|
4684
5152
|
export {
|
|
@@ -4695,6 +5163,7 @@ export {
|
|
|
4695
5163
|
DEFAULT_EXTRA_GAS_PROXY_CREATION,
|
|
4696
5164
|
DEFAULT_GAS_COST_FOR_HOOK_ESTIMATION,
|
|
4697
5165
|
HOOK_DAPP_BRIDGE_PROVIDER_PREFIX,
|
|
5166
|
+
NearIntentsBridgeProvider,
|
|
4698
5167
|
RAW_PROVIDERS_FILES_PATH,
|
|
4699
5168
|
assertIsBridgeQuoteAndPost,
|
|
4700
5169
|
assertIsQuoteAndPost,
|