@subwallet/extension-base 1.3.33-0 → 1.3.35-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/background/KoniTypes.d.ts +2 -0
- package/cjs/core/logic-validation/request.js +1 -1
- package/cjs/koni/background/handlers/Extension.js +11 -4
- package/cjs/koni/background/utils.js +64 -29
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/process.js +1 -5
- package/cjs/services/balance-service/index.js +20 -1
- package/cjs/services/balance-service/transfer/xcm/acrossBridge/index.js +91 -175
- package/cjs/services/balance-service/transfer/xcm/index.js +7 -6
- package/cjs/services/price-service/coingecko.js +22 -15
- package/cjs/services/price-service/index.js +12 -0
- package/cjs/services/swap-service/handler/uniswap-handler.js +14 -1
- package/cjs/services/swap-service/index.js +6 -0
- package/cjs/services/transaction-service/index.js +49 -28
- package/core/logic-validation/request.js +1 -1
- package/koni/background/handlers/Extension.d.ts +1 -0
- package/koni/background/handlers/Extension.js +11 -4
- package/koni/background/utils.d.ts +3 -5
- package/koni/background/utils.js +64 -29
- package/package.json +6 -6
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/process.d.ts +2 -2
- package/services/balance-service/helpers/process.js +1 -5
- package/services/balance-service/index.js +21 -2
- package/services/balance-service/transfer/xcm/acrossBridge/index.d.ts +9 -8
- package/services/balance-service/transfer/xcm/acrossBridge/index.js +91 -174
- package/services/balance-service/transfer/xcm/index.js +7 -6
- package/services/price-service/coingecko.d.ts +1 -1
- package/services/price-service/coingecko.js +22 -16
- package/services/price-service/index.d.ts +1 -0
- package/services/price-service/index.js +12 -0
- package/services/swap-service/handler/uniswap-handler.js +15 -2
- package/services/swap-service/index.js +6 -0
- package/services/transaction-service/index.js +45 -24
|
@@ -142,6 +142,7 @@ export interface PriceJson {
|
|
|
142
142
|
exchangeRateMap: Record<string, ExchangeRateJSON>;
|
|
143
143
|
priceMap: Record<string, number>;
|
|
144
144
|
price24hMap: Record<string, number>;
|
|
145
|
+
priceCoinGeckoSupported: string[];
|
|
145
146
|
lastUpdatedMap: Record<string, Date>;
|
|
146
147
|
}
|
|
147
148
|
export interface HistoryTokenPriceJSON {
|
|
@@ -1674,6 +1675,7 @@ export interface KoniRequestSignatures {
|
|
|
1674
1675
|
'pri(price.getPrice)': [RequestPrice, PriceJson];
|
|
1675
1676
|
'pri(price.getSubscription)': [RequestSubscribePrice, PriceJson, PriceJson];
|
|
1676
1677
|
'pri(price.getHistory)': [RequestGetHistoryTokenPriceData, HistoryTokenPriceJSON];
|
|
1678
|
+
'pri(price.checkCoinGeckoPriceSupport)': [string, boolean];
|
|
1677
1679
|
'pri(price.subscribeCurrentTokenPrice)': [string, ResponseSubscribeCurrentTokenPrice, CurrentTokenPrice];
|
|
1678
1680
|
'pri(balance.getBalance)': [RequestBalance, BalanceJson];
|
|
1679
1681
|
'pri(balance.getSubscription)': [RequestSubscribeBalance, BalanceJson, BalanceJson];
|
|
@@ -371,7 +371,7 @@ async function validationEvmDataTransactionMiddleware(koni, url, payload) {
|
|
|
371
371
|
transaction.maxPriorityFeePerGas = feeCombine.maxPriorityFeePerGas;
|
|
372
372
|
} else if (feeCombine.gasPrice) {
|
|
373
373
|
estimateGas = new _bignumber.default(feeCombine.gasPrice || 0).multipliedBy(gasLimit).toFixed(0);
|
|
374
|
-
transaction.
|
|
374
|
+
transaction.gasPrice = feeCombine.gasPrice;
|
|
375
375
|
}
|
|
376
376
|
}
|
|
377
377
|
} catch (e) {
|
|
@@ -925,6 +925,9 @@ class KoniExtension {
|
|
|
925
925
|
} = _ref29;
|
|
926
926
|
return this.#koniState.priceService.getHistoryTokenPriceData(priceId, timeframe);
|
|
927
927
|
}
|
|
928
|
+
checkCoinGeckoPriceSupport(priceId) {
|
|
929
|
+
return this.#koniState.priceService.checkCoinGeckoPriceSupport(priceId);
|
|
930
|
+
}
|
|
928
931
|
subscribeCurrentTokenPrice(priceId, id, port) {
|
|
929
932
|
const cb = (0, _subscriptions.createSubscription)(id, port);
|
|
930
933
|
const {
|
|
@@ -1490,7 +1493,8 @@ class KoniExtension {
|
|
|
1490
1493
|
xcmFeeDryRun = dryRunInfo.fee;
|
|
1491
1494
|
}
|
|
1492
1495
|
if (isAcrossBridgeTransfer) {
|
|
1493
|
-
const
|
|
1496
|
+
const data = await (0, _acrossBridge.getAcrossQuote)(params);
|
|
1497
|
+
const metadata = data.metadata;
|
|
1494
1498
|
inputData.metadata = {
|
|
1495
1499
|
amountOut: metadata.outputAmount,
|
|
1496
1500
|
rate: metadata.rate,
|
|
@@ -2648,11 +2652,12 @@ class KoniExtension {
|
|
|
2648
2652
|
let registry = new _types5.TypeRegistry();
|
|
2649
2653
|
if (isJsonPayload(payload)) {
|
|
2650
2654
|
const [, chainInfo] = this.#koniState.findNetworkKeyByGenesisHash(payload.genesisHash);
|
|
2651
|
-
const
|
|
2652
|
-
|
|
2655
|
+
const registries = await Promise.all([(0, _utils9.setupApiRegistry)(chainInfo, this.#koniState), (0, _utils9.setupDatabaseRegistry)(chainInfo, payload, this.#koniState), (0, _utils9.setupDappRegistry)(payload, this.#koniState)]);
|
|
2656
|
+
const validRegistries = registries.filter(item => !!(item !== null && item !== void 0 && item.registry));
|
|
2657
|
+
if (validRegistries.length === 0) {
|
|
2653
2658
|
registry.setSignedExtensions(payload.signedExtensions);
|
|
2654
2659
|
} else {
|
|
2655
|
-
registry = (0, _utils9.getSuitableRegistry)(
|
|
2660
|
+
registry = (0, _utils9.getSuitableRegistry)(validRegistries, payload);
|
|
2656
2661
|
}
|
|
2657
2662
|
}
|
|
2658
2663
|
const result = request.sign(registry, pair);
|
|
@@ -4360,6 +4365,8 @@ class KoniExtension {
|
|
|
4360
4365
|
return await this.subscribePrice(id, port);
|
|
4361
4366
|
case 'pri(price.getHistory)':
|
|
4362
4367
|
return await this.getHistoryTokenPrice(request);
|
|
4368
|
+
case 'pri(price.checkCoinGeckoPriceSupport)':
|
|
4369
|
+
return this.checkCoinGeckoPriceSupport(request);
|
|
4363
4370
|
case 'pri(price.subscribeCurrentTokenPrice)':
|
|
4364
4371
|
return this.subscribeCurrentTokenPrice(request, id, port);
|
|
4365
4372
|
case 'pri(settings.savePriceCurrency)':
|
|
@@ -7,6 +7,7 @@ exports.getSuitableRegistry = getSuitableRegistry;
|
|
|
7
7
|
exports.setupApiRegistry = setupApiRegistry;
|
|
8
8
|
exports.setupDappRegistry = setupDappRegistry;
|
|
9
9
|
exports.setupDatabaseRegistry = setupDatabaseRegistry;
|
|
10
|
+
var _utils = require("@subwallet/extension-base/utils");
|
|
10
11
|
var _bundle = require("@subwallet/extension-chains/bundle");
|
|
11
12
|
var _types = require("@polkadot/types");
|
|
12
13
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
@@ -32,41 +33,75 @@ function getSuitableRegistry(registries, payload) {
|
|
|
32
33
|
});
|
|
33
34
|
return sortedRegistries[0].registry;
|
|
34
35
|
}
|
|
35
|
-
function setupApiRegistry(chainInfo, koniState) {
|
|
36
|
+
async function setupApiRegistry(chainInfo, koniState) {
|
|
36
37
|
if (!chainInfo) {
|
|
37
38
|
return null;
|
|
38
39
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
40
|
+
try {
|
|
41
|
+
const api = koniState.getSubstrateApi(chainInfo.slug).api;
|
|
42
|
+
if (!api) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Wait for the API to be ready or timeout after 1 second
|
|
47
|
+
await Promise.race([(0, _utils.wait)(1000).then(() => {
|
|
48
|
+
throw new Error('Timeout waiting for API to be ready');
|
|
49
|
+
}), api.isReady]);
|
|
50
|
+
|
|
51
|
+
// Extract the spec version and registry
|
|
52
|
+
const apiSpecVersion = api.runtimeVersion.specVersion.toString();
|
|
53
|
+
const registry = api.registry;
|
|
54
|
+
return {
|
|
55
|
+
registry,
|
|
56
|
+
specVersion: apiSpecVersion
|
|
57
|
+
};
|
|
58
|
+
} catch (e) {
|
|
59
|
+
console.error('Error in setupApiRegistry:', e);
|
|
49
60
|
return null;
|
|
50
61
|
}
|
|
51
|
-
const registry = new _types.TypeRegistry();
|
|
52
|
-
const _metadata = new _types.Metadata(registry, metadata.hexValue);
|
|
53
|
-
registry.register(metadata.types);
|
|
54
|
-
registry.setChainProperties(registry.createType('ChainProperties', metadata.tokenInfo));
|
|
55
|
-
registry.setMetadata(_metadata, payload.signedExtensions, metadata.userExtensions);
|
|
56
|
-
return {
|
|
57
|
-
registry,
|
|
58
|
-
specVersion: metadata.specVersion
|
|
59
|
-
};
|
|
60
62
|
}
|
|
61
|
-
function
|
|
62
|
-
if (!
|
|
63
|
+
async function setupDatabaseRegistry(chainInfo, payload, koniState) {
|
|
64
|
+
if (!chainInfo) {
|
|
65
|
+
console.warn('setupDatabaseRegistry: Missing chainInfo');
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
const metadata = await koniState.chainService.getMetadataByHash(payload.genesisHash);
|
|
70
|
+
if (!(metadata !== null && metadata !== void 0 && metadata.genesisHash)) {
|
|
71
|
+
console.warn('setupDatabaseRegistry: Metadata not found or invalid for genesisHash:', payload.genesisHash);
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
const registry = new _types.TypeRegistry();
|
|
75
|
+
const _metadata = new _types.Metadata(registry, metadata.hexValue);
|
|
76
|
+
registry.register(metadata.types);
|
|
77
|
+
registry.setChainProperties(registry.createType('ChainProperties', metadata.tokenInfo));
|
|
78
|
+
registry.setMetadata(_metadata, payload.signedExtensions, metadata.userExtensions);
|
|
79
|
+
return {
|
|
80
|
+
registry,
|
|
81
|
+
specVersion: metadata.specVersion
|
|
82
|
+
};
|
|
83
|
+
} catch (e) {
|
|
84
|
+
console.error('setupDatabaseRegistry: Error setting up database registry:', e);
|
|
63
85
|
return null;
|
|
64
86
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
87
|
+
}
|
|
88
|
+
function setupDappRegistry(payload, koniState) {
|
|
89
|
+
return new Promise(resolve => {
|
|
90
|
+
const metadata = koniState.knownMetadata.find(meta => meta.genesisHash === payload.genesisHash);
|
|
91
|
+
if (!(metadata !== null && metadata !== void 0 && metadata.genesisHash)) {
|
|
92
|
+
return resolve(null);
|
|
93
|
+
}
|
|
94
|
+
try {
|
|
95
|
+
const expanded = (0, _bundle.metadataExpand)(metadata, false);
|
|
96
|
+
const registry = expanded.registry;
|
|
97
|
+
registry.setSignedExtensions(payload.signedExtensions, expanded.definition.userExtensions);
|
|
98
|
+
resolve({
|
|
99
|
+
registry,
|
|
100
|
+
specVersion: metadata.specVersion
|
|
101
|
+
});
|
|
102
|
+
} catch (e) {
|
|
103
|
+
console.error('setupDappRegistry: Error setting up DApp registry:', e);
|
|
104
|
+
resolve(null);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
72
107
|
}
|
package/cjs/packageInfo.js
CHANGED
|
@@ -8,8 +8,6 @@ exports.getDefaultTransferProcess = getDefaultTransferProcess;
|
|
|
8
8
|
exports.getSnowbridgeTransferProcessFromEvm = getSnowbridgeTransferProcessFromEvm;
|
|
9
9
|
var _chainList = require("@subwallet/chain-list");
|
|
10
10
|
var _serviceBase = require("@subwallet/extension-base/types/service-base");
|
|
11
|
-
var _utils = require("../../chain-service/utils");
|
|
12
|
-
var _acrossBridge = require("../transfer/xcm/acrossBridge");
|
|
13
11
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
14
12
|
// SPDX-License-Identifier: Apache-2.0
|
|
15
13
|
|
|
@@ -52,9 +50,7 @@ async function getSnowbridgeTransferProcessFromEvm(address, evmApi, tokenInfo, a
|
|
|
52
50
|
result.totalFee.push(_serviceBase.MOCK_STEP_FEE);
|
|
53
51
|
return Promise.resolve(result);
|
|
54
52
|
}
|
|
55
|
-
async function getAcrossbridgeTransferProcessFromEvm(
|
|
56
|
-
const chainId = (0, _utils._getEvmChainId)(originChainInfo);
|
|
57
|
-
const SpokePoolAddress = _acrossBridge.SpokePoolMapping[chainId].SpokePool.address;
|
|
53
|
+
async function getAcrossbridgeTransferProcessFromEvm(SpokePoolAddress) {
|
|
58
54
|
const result = {
|
|
59
55
|
totalFee: [_serviceBase.MOCK_STEP_FEE],
|
|
60
56
|
steps: [_serviceBase.DEFAULT_FIRST_STEP]
|
|
@@ -586,7 +586,26 @@ class BalanceService {
|
|
|
586
586
|
if ((0, _acrossBridge._isAcrossChainBridge)(originChainInfo.slug, destChainInfo.slug)) {
|
|
587
587
|
const tokenInfo = this.state.chainService.getAssetBySlug(params.tokenSlug);
|
|
588
588
|
if (!(0, _utils._isNativeToken)(tokenInfo)) {
|
|
589
|
-
|
|
589
|
+
const chainInfoMap = this.state.getChainInfoMap();
|
|
590
|
+
const originTokenInfo = this.state.getAssetBySlug(params.tokenSlug);
|
|
591
|
+
const destinationTokenInfo = this.state.getXcmEqualAssetByChain(params.destChain, params.tokenSlug);
|
|
592
|
+
if (!destinationTokenInfo) {
|
|
593
|
+
throw new Error('Destination token info not found');
|
|
594
|
+
}
|
|
595
|
+
const inputData = {
|
|
596
|
+
destinationTokenInfo,
|
|
597
|
+
originTokenInfo,
|
|
598
|
+
sendingValue: params.amount,
|
|
599
|
+
sender: params.address,
|
|
600
|
+
recipient: params.address,
|
|
601
|
+
destinationChain: chainInfoMap[destinationTokenInfo.originChain],
|
|
602
|
+
originChain: chainInfoMap[originTokenInfo.originChain]
|
|
603
|
+
};
|
|
604
|
+
const data = await (0, _acrossBridge.getAcrossQuote)(inputData);
|
|
605
|
+
if (!data) {
|
|
606
|
+
throw new Error('Failed to fetch Across Bridge Data. Please try again later');
|
|
607
|
+
}
|
|
608
|
+
return (0, _process.getAcrossbridgeTransferProcessFromEvm)(data.to);
|
|
590
609
|
}
|
|
591
610
|
}
|
|
592
611
|
return (0, _process.getDefaultTransferProcess)();
|
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.
|
|
7
|
+
exports.AcrossErrorMsg = void 0;
|
|
8
8
|
exports._isAcrossChainBridge = _isAcrossChainBridge;
|
|
9
9
|
exports._isAcrossTestnetBridge = _isAcrossTestnetBridge;
|
|
10
10
|
exports.getAcrossQuote = void 0;
|
|
@@ -25,177 +25,6 @@ function _isAcrossChainBridge(srcChain, destChain) {
|
|
|
25
25
|
function _isAcrossTestnetBridge(srcChain) {
|
|
26
26
|
return srcChain === 'base_sepolia' || srcChain === 'arbitrum_sepolia' || srcChain === _chainList.COMMON_CHAIN_SLUGS.ETHEREUM_SEPOLIA;
|
|
27
27
|
}
|
|
28
|
-
const SpokePoolMapping = {
|
|
29
|
-
1: {
|
|
30
|
-
SpokePool: {
|
|
31
|
-
address: '0x5c7BCd6E7De5423a257D81B442095A1a6ced35C5',
|
|
32
|
-
blockNumber: 17117454
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
10: {
|
|
36
|
-
SpokePool: {
|
|
37
|
-
address: '0x6f26Bf09B1C792e3228e5467807a900A503c0281',
|
|
38
|
-
blockNumber: 93903076
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
11155111: {
|
|
42
|
-
SpokePool: {
|
|
43
|
-
address: '0x5ef6C01E11889d86803e0B23e3cB3F9E9d97B662',
|
|
44
|
-
blockNumber: 5288470
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
11155420: {
|
|
48
|
-
SpokePool: {
|
|
49
|
-
address: '0x4e8E101924eDE233C13e2D8622DC8aED2872d505',
|
|
50
|
-
blockNumber: 7762656
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
1135: {
|
|
54
|
-
SpokePool: {
|
|
55
|
-
address: '0x9552a0a6624A23B848060AE5901659CDDa1f83f8',
|
|
56
|
-
blockNumber: 2602337
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
130: {
|
|
60
|
-
SpokePool: {
|
|
61
|
-
address: '0x09aea4b2242abC8bb4BB78D537A67a245A7bEC64',
|
|
62
|
-
blockNumber: 7915488
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
137: {
|
|
66
|
-
SpokePool: {
|
|
67
|
-
address: '0x9295ee1d8C5b022Be115A2AD3c30C72E34e7F096',
|
|
68
|
-
blockNumber: 41908657
|
|
69
|
-
}
|
|
70
|
-
},
|
|
71
|
-
168587773: {
|
|
72
|
-
SpokePool: {
|
|
73
|
-
address: '0x5545092553Cf5Bf786e87a87192E902D50D8f022',
|
|
74
|
-
blockNumber: 7634204
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
1868: {
|
|
78
|
-
SpokePool: {
|
|
79
|
-
address: '0x3baD7AD0728f9917d1Bf08af5782dCbD516cDd96',
|
|
80
|
-
blockNumber: 1709997
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
288: {
|
|
84
|
-
SpokePool: {
|
|
85
|
-
address: '0xBbc6009fEfFc27ce705322832Cb2068F8C1e0A58',
|
|
86
|
-
blockNumber: 619993
|
|
87
|
-
}
|
|
88
|
-
},
|
|
89
|
-
324: {
|
|
90
|
-
SpokePool: {
|
|
91
|
-
address: '0xE0B015E54d54fc84a6cB9B666099c46adE9335FF',
|
|
92
|
-
blockNumber: 10352565
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
34443: {
|
|
96
|
-
SpokePool: {
|
|
97
|
-
address: '0x3baD7AD0728f9917d1Bf08af5782dCbD516cDd96',
|
|
98
|
-
blockNumber: 8043187
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
37111: {
|
|
102
|
-
SpokePool: {
|
|
103
|
-
address: '0x6A0a7f39530923911832Dd60667CE5da5449967B',
|
|
104
|
-
blockNumber: 156275
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
41455: {
|
|
108
|
-
SpokePool: {
|
|
109
|
-
address: '0x13fDac9F9b4777705db45291bbFF3c972c6d1d97',
|
|
110
|
-
blockNumber: 4240318
|
|
111
|
-
}
|
|
112
|
-
},
|
|
113
|
-
4202: {
|
|
114
|
-
SpokePool: {
|
|
115
|
-
address: '0xeF684C38F94F48775959ECf2012D7E864ffb9dd4',
|
|
116
|
-
blockNumber: 7267988
|
|
117
|
-
}
|
|
118
|
-
},
|
|
119
|
-
42161: {
|
|
120
|
-
SpokePool: {
|
|
121
|
-
address: '0xe35e9842fceaCA96570B734083f4a58e8F7C5f2A',
|
|
122
|
-
blockNumber: 83868041
|
|
123
|
-
}
|
|
124
|
-
},
|
|
125
|
-
421614: {
|
|
126
|
-
SpokePool: {
|
|
127
|
-
address: '0x7E63A5f1a8F0B4d0934B2f2327DAED3F6bb2ee75',
|
|
128
|
-
blockNumber: 12411026
|
|
129
|
-
}
|
|
130
|
-
},
|
|
131
|
-
480: {
|
|
132
|
-
SpokePool: {
|
|
133
|
-
address: '0x09aea4b2242abC8bb4BB78D537A67a245A7bEC64',
|
|
134
|
-
blockNumber: 4524742
|
|
135
|
-
}
|
|
136
|
-
},
|
|
137
|
-
534352: {
|
|
138
|
-
SpokePool: {
|
|
139
|
-
address: '0x3baD7AD0728f9917d1Bf08af5782dCbD516cDd96',
|
|
140
|
-
blockNumber: 7489705
|
|
141
|
-
}
|
|
142
|
-
},
|
|
143
|
-
57073: {
|
|
144
|
-
SpokePool: {
|
|
145
|
-
address: '0xeF684C38F94F48775959ECf2012D7E864ffb9dd4',
|
|
146
|
-
blockNumber: 1139240
|
|
147
|
-
}
|
|
148
|
-
},
|
|
149
|
-
59144: {
|
|
150
|
-
SpokePool: {
|
|
151
|
-
address: '0x7E63A5f1a8F0B4d0934B2f2327DAED3F6bb2ee75',
|
|
152
|
-
blockNumber: 2721169
|
|
153
|
-
}
|
|
154
|
-
},
|
|
155
|
-
690: {
|
|
156
|
-
SpokePool: {
|
|
157
|
-
address: '0x13fDac9F9b4777705db45291bbFF3c972c6d1d97',
|
|
158
|
-
blockNumber: 5512122
|
|
159
|
-
}
|
|
160
|
-
},
|
|
161
|
-
7777777: {
|
|
162
|
-
SpokePool: {
|
|
163
|
-
address: '0x13fDac9F9b4777705db45291bbFF3c972c6d1d97',
|
|
164
|
-
blockNumber: 18382867
|
|
165
|
-
}
|
|
166
|
-
},
|
|
167
|
-
80002: {
|
|
168
|
-
SpokePool: {
|
|
169
|
-
address: '0xd08baaE74D6d2eAb1F3320B2E1a53eeb391ce8e5',
|
|
170
|
-
blockNumber: 7529960
|
|
171
|
-
}
|
|
172
|
-
},
|
|
173
|
-
81457: {
|
|
174
|
-
SpokePool: {
|
|
175
|
-
address: '0x2D509190Ed0172ba588407D4c2df918F955Cc6E1',
|
|
176
|
-
blockNumber: 5574280
|
|
177
|
-
}
|
|
178
|
-
},
|
|
179
|
-
8453: {
|
|
180
|
-
SpokePool: {
|
|
181
|
-
address: '0x09aea4b2242abC8bb4BB78D537A67a245A7bEC64',
|
|
182
|
-
blockNumber: 2164878
|
|
183
|
-
}
|
|
184
|
-
},
|
|
185
|
-
84532: {
|
|
186
|
-
SpokePool: {
|
|
187
|
-
address: '0x82B564983aE7274c86695917BBf8C99ECb6F0F8F',
|
|
188
|
-
blockNumber: 6082004
|
|
189
|
-
}
|
|
190
|
-
},
|
|
191
|
-
919: {
|
|
192
|
-
SpokePool: {
|
|
193
|
-
address: '0xbd886FC0725Cc459b55BbFEb3E4278610331f83b',
|
|
194
|
-
blockNumber: 13999465
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
exports.SpokePoolMapping = SpokePoolMapping;
|
|
199
28
|
const AcrossErrorMsg = {
|
|
200
29
|
AMOUNT_TOO_LOW: 'amount too low',
|
|
201
30
|
AMOUNT_TOO_HIGH: 'amount too high'
|
|
@@ -222,12 +51,99 @@ const getAcrossQuote = async _ref => {
|
|
|
222
51
|
try {
|
|
223
52
|
var _subwalletApiSdk$xcmA;
|
|
224
53
|
const data = await ((_subwalletApiSdk$xcmA = _subwalletApiSdk.default.xcmApi) === null || _subwalletApiSdk$xcmA === void 0 ? void 0 : _subwalletApiSdk$xcmA.fetchXcmData(sender, originTokenInfo.slug, destinationTokenInfo.slug, recipient, sendingValue));
|
|
225
|
-
if (!data
|
|
226
|
-
throw new Error('Failed to
|
|
54
|
+
if (!data) {
|
|
55
|
+
throw new Error('Failed to fetch Across Bridge Data. Please try again later');
|
|
227
56
|
}
|
|
228
|
-
return data
|
|
57
|
+
return data;
|
|
229
58
|
} catch (error) {
|
|
230
59
|
return Promise.reject(error);
|
|
231
60
|
}
|
|
232
61
|
};
|
|
62
|
+
|
|
63
|
+
// export const SpokePoolMapping: Record<number, { SpokePool: { address: string; blockNumber: number } }> = {
|
|
64
|
+
// 1: {
|
|
65
|
+
// SpokePool: { address: '0x5c7BCd6E7De5423a257D81B442095A1a6ced35C5', blockNumber: 17117454 }
|
|
66
|
+
// },
|
|
67
|
+
// 10: {
|
|
68
|
+
// SpokePool: { address: '0x6f26Bf09B1C792e3228e5467807a900A503c0281', blockNumber: 93903076 }
|
|
69
|
+
// },
|
|
70
|
+
// 11155111: {
|
|
71
|
+
// SpokePool: { address: '0x5ef6C01E11889d86803e0B23e3cB3F9E9d97B662', blockNumber: 5288470 }
|
|
72
|
+
// },
|
|
73
|
+
// 11155420: {
|
|
74
|
+
// SpokePool: { address: '0x4e8E101924eDE233C13e2D8622DC8aED2872d505', blockNumber: 7762656 }
|
|
75
|
+
// },
|
|
76
|
+
// 1135: {
|
|
77
|
+
// SpokePool: { address: '0x9552a0a6624A23B848060AE5901659CDDa1f83f8', blockNumber: 2602337 }
|
|
78
|
+
// },
|
|
79
|
+
// 130: {
|
|
80
|
+
// SpokePool: { address: '0x09aea4b2242abC8bb4BB78D537A67a245A7bEC64', blockNumber: 7915488 }
|
|
81
|
+
// },
|
|
82
|
+
// 137: {
|
|
83
|
+
// SpokePool: { address: '0x9295ee1d8C5b022Be115A2AD3c30C72E34e7F096', blockNumber: 41908657 }
|
|
84
|
+
// },
|
|
85
|
+
// 168587773: {
|
|
86
|
+
// SpokePool: { address: '0x5545092553Cf5Bf786e87a87192E902D50D8f022', blockNumber: 7634204 }
|
|
87
|
+
// },
|
|
88
|
+
// 1868: {
|
|
89
|
+
// SpokePool: { address: '0x3baD7AD0728f9917d1Bf08af5782dCbD516cDd96', blockNumber: 1709997 }
|
|
90
|
+
// },
|
|
91
|
+
// 288: {
|
|
92
|
+
// SpokePool: { address: '0xBbc6009fEfFc27ce705322832Cb2068F8C1e0A58', blockNumber: 619993 }
|
|
93
|
+
// },
|
|
94
|
+
// 324: {
|
|
95
|
+
// SpokePool: { address: '0xE0B015E54d54fc84a6cB9B666099c46adE9335FF', blockNumber: 10352565 }
|
|
96
|
+
// },
|
|
97
|
+
// 34443: {
|
|
98
|
+
// SpokePool: { address: '0x3baD7AD0728f9917d1Bf08af5782dCbD516cDd96', blockNumber: 8043187 }
|
|
99
|
+
// },
|
|
100
|
+
// 37111: {
|
|
101
|
+
// SpokePool: { address: '0x6A0a7f39530923911832Dd60667CE5da5449967B', blockNumber: 156275 }
|
|
102
|
+
// },
|
|
103
|
+
// 41455: {
|
|
104
|
+
// SpokePool: { address: '0x13fDac9F9b4777705db45291bbFF3c972c6d1d97', blockNumber: 4240318 }
|
|
105
|
+
// },
|
|
106
|
+
// 4202: {
|
|
107
|
+
// SpokePool: { address: '0xeF684C38F94F48775959ECf2012D7E864ffb9dd4', blockNumber: 7267988 }
|
|
108
|
+
// },
|
|
109
|
+
// 42161: {
|
|
110
|
+
// SpokePool: { address: '0xe35e9842fceaCA96570B734083f4a58e8F7C5f2A', blockNumber: 83868041 }
|
|
111
|
+
// },
|
|
112
|
+
// 421614: {
|
|
113
|
+
// SpokePool: { address: '0x7E63A5f1a8F0B4d0934B2f2327DAED3F6bb2ee75', blockNumber: 12411026 }
|
|
114
|
+
// },
|
|
115
|
+
// 480: {
|
|
116
|
+
// SpokePool: { address: '0x09aea4b2242abC8bb4BB78D537A67a245A7bEC64', blockNumber: 4524742 }
|
|
117
|
+
// },
|
|
118
|
+
// 534352: {
|
|
119
|
+
// SpokePool: { address: '0x3baD7AD0728f9917d1Bf08af5782dCbD516cDd96', blockNumber: 7489705 }
|
|
120
|
+
// },
|
|
121
|
+
// 57073: {
|
|
122
|
+
// SpokePool: { address: '0xeF684C38F94F48775959ECf2012D7E864ffb9dd4', blockNumber: 1139240 }
|
|
123
|
+
// },
|
|
124
|
+
// 59144: {
|
|
125
|
+
// SpokePool: { address: '0x7E63A5f1a8F0B4d0934B2f2327DAED3F6bb2ee75', blockNumber: 2721169 }
|
|
126
|
+
// },
|
|
127
|
+
// 690: {
|
|
128
|
+
// SpokePool: { address: '0x13fDac9F9b4777705db45291bbFF3c972c6d1d97', blockNumber: 5512122 }
|
|
129
|
+
// },
|
|
130
|
+
// 7777777: {
|
|
131
|
+
// SpokePool: { address: '0x13fDac9F9b4777705db45291bbFF3c972c6d1d97', blockNumber: 18382867 }
|
|
132
|
+
// },
|
|
133
|
+
// 80002: {
|
|
134
|
+
// SpokePool: { address: '0xd08baaE74D6d2eAb1F3320B2E1a53eeb391ce8e5', blockNumber: 7529960 }
|
|
135
|
+
// },
|
|
136
|
+
// 81457: {
|
|
137
|
+
// SpokePool: { address: '0x2D509190Ed0172ba588407D4c2df918F955Cc6E1', blockNumber: 5574280 }
|
|
138
|
+
// },
|
|
139
|
+
// 8453: {
|
|
140
|
+
// SpokePool: { address: '0x09aea4b2242abC8bb4BB78D537A67a245A7bEC64', blockNumber: 2164878 }
|
|
141
|
+
// },
|
|
142
|
+
// 84532: {
|
|
143
|
+
// SpokePool: { address: '0x82B564983aE7274c86695917BBf8C99ECb6F0F8F', blockNumber: 6082004 }
|
|
144
|
+
// },
|
|
145
|
+
// 919: {
|
|
146
|
+
// SpokePool: { address: '0xbd886FC0725Cc459b55BbFEb3E4278610331f83b', blockNumber: 13999465 }
|
|
147
|
+
// }
|
|
148
|
+
// };
|
|
233
149
|
exports.getAcrossQuote = getAcrossQuote;
|
|
@@ -202,13 +202,14 @@ const createAcrossBridgeExtrinsic = async _ref6 => {
|
|
|
202
202
|
const data = await ((_subwalletApiSdk$xcmA = _subwalletApiSdk.default.xcmApi) === null || _subwalletApiSdk$xcmA === void 0 ? void 0 : _subwalletApiSdk$xcmA.fetchXcmData(sender, originTokenInfo.slug, destinationTokenInfo.slug, recipient, sendingValue));
|
|
203
203
|
const _feeCustom = feeCustom;
|
|
204
204
|
const feeCombine = (0, _utils3.combineEthFee)(feeInfo, feeOption, _feeCustom);
|
|
205
|
-
|
|
206
|
-
|
|
205
|
+
if (!data) {
|
|
206
|
+
throw new Error('Failed to fetch Across Bridge Data. Please try again later');
|
|
207
|
+
}
|
|
207
208
|
const transactionConfig = {
|
|
208
|
-
from: data
|
|
209
|
-
to: data
|
|
210
|
-
value: data
|
|
211
|
-
data: data
|
|
209
|
+
from: data.sender,
|
|
210
|
+
to: data.to,
|
|
211
|
+
value: data.value,
|
|
212
|
+
data: data.transferEncodedCall,
|
|
212
213
|
...feeCombine
|
|
213
214
|
};
|
|
214
215
|
const gasLimit = await evmApi.api.eth.estimateGas(transactionConfig).catch(() => 200000);
|
|
@@ -60,28 +60,33 @@ const fetchDerivativeTokenSlugs = async () => {
|
|
|
60
60
|
};
|
|
61
61
|
const getPriceMap = async function (priceIds) {
|
|
62
62
|
let currency = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'USD';
|
|
63
|
+
let skipDerivativePrice = arguments.length > 2 ? arguments[2] : undefined;
|
|
63
64
|
const idStr = Array.from(priceIds).join(',');
|
|
64
65
|
let response;
|
|
65
66
|
try {
|
|
66
67
|
var _response3, _response5;
|
|
67
68
|
const derivativePriceMap = {};
|
|
69
|
+
const lastUpdatedMap = {};
|
|
68
70
|
let derivativeApiError = false;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
71
|
+
if (!skipDerivativePrice) {
|
|
72
|
+
try {
|
|
73
|
+
const responseDerivativeTokens = await fetch(`${apiCacheDomain}/api/price/derivative-get`);
|
|
74
|
+
const generateDerivativePriceRaw = (await (responseDerivativeTokens === null || responseDerivativeTokens === void 0 ? void 0 : responseDerivativeTokens.json())) || [];
|
|
75
|
+
if (Array.isArray(generateDerivativePriceRaw)) {
|
|
76
|
+
generateDerivativePriceRaw.forEach(token => {
|
|
77
|
+
if (token.id) {
|
|
78
|
+
derivativePriceMap[token.id] = token.derived_price;
|
|
79
|
+
lastUpdatedMap[token.id] = new Date(token.cached_at || Date.now());
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
} else {
|
|
83
|
+
console.warn('Invalid data from derivative API:', generateDerivativePriceRaw);
|
|
84
|
+
derivativeApiError = true;
|
|
85
|
+
}
|
|
86
|
+
} catch (error) {
|
|
87
|
+
console.error('Error fetching derivative API:', error);
|
|
80
88
|
derivativeApiError = true;
|
|
81
89
|
}
|
|
82
|
-
} catch (error) {
|
|
83
|
-
console.error('Error fetching derivative API:', error);
|
|
84
|
-
derivativeApiError = true;
|
|
85
90
|
}
|
|
86
91
|
if (!useBackupApi) {
|
|
87
92
|
try {
|
|
@@ -113,10 +118,11 @@ const getPriceMap = async function (priceIds) {
|
|
|
113
118
|
const currencyData = _staticData.staticData[_staticData.StaticKey.CURRENCY_SYMBOL][currency || DEFAULT_CURRENCY];
|
|
114
119
|
const priceMap = {};
|
|
115
120
|
const price24hMap = {};
|
|
116
|
-
const
|
|
121
|
+
const priceCoinGeckoSupported = [];
|
|
117
122
|
responseDataPrice.forEach(val => {
|
|
118
123
|
const currentPrice = val.current_price || 0;
|
|
119
124
|
const price24h = currentPrice - (val.price_change_24h || 0);
|
|
125
|
+
priceCoinGeckoSupported.push(val.id);
|
|
120
126
|
priceMap[val.id] = currentPrice;
|
|
121
127
|
price24hMap[val.id] = price24h;
|
|
122
128
|
lastUpdatedMap[val.id] = new Date(val.last_updated || val.last_updated_at || Date.now());
|
|
@@ -139,6 +145,7 @@ const getPriceMap = async function (priceIds) {
|
|
|
139
145
|
currencyData,
|
|
140
146
|
priceMap,
|
|
141
147
|
price24hMap,
|
|
148
|
+
priceCoinGeckoSupported,
|
|
142
149
|
lastUpdatedMap
|
|
143
150
|
};
|
|
144
151
|
} catch (e) {
|
|
@@ -26,6 +26,7 @@ const DEFAULT_PRICE_SUBJECT = {
|
|
|
26
26
|
isPrefix: true
|
|
27
27
|
},
|
|
28
28
|
priceMap: {},
|
|
29
|
+
priceCoinGeckoSupported: [],
|
|
29
30
|
price24hMap: {},
|
|
30
31
|
exchangeRateMap: {},
|
|
31
32
|
lastUpdatedMap: {}
|
|
@@ -103,6 +104,7 @@ class PriceService {
|
|
|
103
104
|
let {
|
|
104
105
|
lastUpdatedMap,
|
|
105
106
|
price24hMap,
|
|
107
|
+
priceCoinGeckoSupported,
|
|
106
108
|
priceMap
|
|
107
109
|
} = this.rawPriceSubject.value;
|
|
108
110
|
let exchangeRateData = this.rawExchangeRateMap.value;
|
|
@@ -132,6 +134,7 @@ class PriceService {
|
|
|
132
134
|
},
|
|
133
135
|
currency: currencyKey,
|
|
134
136
|
exchangeRateMap: exchangeRateData,
|
|
137
|
+
priceCoinGeckoSupported,
|
|
135
138
|
currencyData: _staticData.staticData[_staticData.StaticKey.CURRENCY_SYMBOL][currencyKey || DEFAULT_CURRENCY],
|
|
136
139
|
lastUpdatedMap: {
|
|
137
140
|
...lastUpdatedMap
|
|
@@ -268,6 +271,15 @@ class PriceService {
|
|
|
268
271
|
this.status = _types.ServiceStatus.INITIALIZED;
|
|
269
272
|
this.eventService.on('asset.updateState', eventHandler);
|
|
270
273
|
}
|
|
274
|
+
checkCoinGeckoPriceSupport(priceId) {
|
|
275
|
+
const {
|
|
276
|
+
priceCoinGeckoSupported
|
|
277
|
+
} = this.priceSubject.value;
|
|
278
|
+
if (!priceCoinGeckoSupported) {
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
return priceCoinGeckoSupported.includes(priceId);
|
|
282
|
+
}
|
|
271
283
|
async loadData() {
|
|
272
284
|
const data = await this.dbService.getPriceStore(this.priceSubject.value.currency);
|
|
273
285
|
this.priceSubject.next(data || DEFAULT_PRICE_SUBJECT);
|