@subwallet/extension-base 1.3.34-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
|
@@ -140,6 +140,7 @@ class UniswapHandler {
|
|
|
140
140
|
if (!quote) {
|
|
141
141
|
return Promise.resolve(undefined);
|
|
142
142
|
}
|
|
143
|
+
console.log('params', params);
|
|
143
144
|
const sendingAmount = quote.toAmount;
|
|
144
145
|
const senderAddress = params.request.address;
|
|
145
146
|
const fromTokenInfo = this.chainService.getAssetBySlug(quote.pair.to);
|
|
@@ -147,13 +148,25 @@ class UniswapHandler {
|
|
|
147
148
|
const fromChainId = (0, _utils2._getEvmChainId)(fromChainInfo);
|
|
148
149
|
const evmApi = this.chainService.getEvmApi(fromChainInfo.slug);
|
|
149
150
|
const tokenContract = (0, _utils2._getContractAddressOfToken)(fromTokenInfo);
|
|
151
|
+
const toTokenInfo = this.chainService.getAssetBySlug(params.request.pair.to);
|
|
152
|
+
const toChainInfo = this.chainService.getChainInfoByKey((0, _utils2._getAssetOriginChain)(toTokenInfo));
|
|
150
153
|
if ((0, _utils2._isNativeToken)(fromTokenInfo)) {
|
|
151
154
|
return Promise.resolve(undefined);
|
|
152
155
|
}
|
|
153
156
|
if (!fromChainId) {
|
|
154
157
|
throw Error('Error getting Evm chain Id');
|
|
155
158
|
}
|
|
156
|
-
const
|
|
159
|
+
const inputData = {
|
|
160
|
+
destinationTokenInfo: toTokenInfo,
|
|
161
|
+
originTokenInfo: fromTokenInfo,
|
|
162
|
+
sendingValue: sendingAmount,
|
|
163
|
+
sender: senderAddress,
|
|
164
|
+
recipient: senderAddress,
|
|
165
|
+
destinationChain: toChainInfo,
|
|
166
|
+
originChain: fromChainInfo
|
|
167
|
+
};
|
|
168
|
+
const acrossQuote = await (0, _acrossBridge.getAcrossQuote)(inputData);
|
|
169
|
+
const spokePoolAddress = acrossQuote.to;
|
|
157
170
|
const allowance = await (0, _web.getERC20Allowance)(spokePoolAddress, senderAddress, tokenContract, evmApi);
|
|
158
171
|
if (allowance && (0, _bignumber.default)(allowance).gt(sendingAmount)) {
|
|
159
172
|
return Promise.resolve(undefined);
|
|
@@ -130,6 +130,12 @@ class SwapService {
|
|
|
130
130
|
} catch (e) {
|
|
131
131
|
throw new Error(e.message);
|
|
132
132
|
}
|
|
133
|
+
if (swapQuoteResponse.error) {
|
|
134
|
+
return {
|
|
135
|
+
process: optimalProcess,
|
|
136
|
+
quote: swapQuoteResponse
|
|
137
|
+
};
|
|
138
|
+
}
|
|
133
139
|
console.log('optimalProcess', optimalProcess);
|
|
134
140
|
console.groupEnd();
|
|
135
141
|
if (JSON.stringify((0, _utils2.processStepsToPathActions)(optimalProcess.steps)) !== JSON.stringify(optimalProcess.path.map(e => e.action))) {
|
|
@@ -1435,44 +1435,65 @@ class TransactionService {
|
|
|
1435
1435
|
this.handleTransactionTimeout(emitter, eventData);
|
|
1436
1436
|
emitter.emit('send', eventData); // This event is needed after sending transaction with queue
|
|
1437
1437
|
|
|
1438
|
+
let isBroadcast = false;
|
|
1439
|
+
let isInBlock = false;
|
|
1440
|
+
let isFinish = false;
|
|
1438
1441
|
rs.send(txState => {
|
|
1439
1442
|
// handle events, logs, history
|
|
1440
1443
|
if (!txState || !txState.status) {
|
|
1441
1444
|
return;
|
|
1442
1445
|
}
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
+
|
|
1447
|
+
// Broadcast transaction
|
|
1448
|
+
if (!isBroadcast) {
|
|
1449
|
+
if (txState.status.isBroadcast || txState.status.isInBlock || txState.status.isFinalized) {
|
|
1446
1450
|
eventData.extrinsicHash = txState.txHash.toHex();
|
|
1451
|
+
isBroadcast = true;
|
|
1452
|
+
if (!isFinish) {
|
|
1453
|
+
emitter.emit('extrinsicHash', eventData);
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1458
|
+
// Transaction in block
|
|
1459
|
+
if (!isInBlock) {
|
|
1460
|
+
if (txState.status.isInBlock || txState.status.isFinalized) {
|
|
1447
1461
|
eventData.blockHash = txState.status.asInBlock.toHex();
|
|
1448
|
-
|
|
1462
|
+
eventData.eventLogs = txState.events;
|
|
1463
|
+
isInBlock = true;
|
|
1449
1464
|
}
|
|
1450
1465
|
}
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
event: {
|
|
1458
|
-
section
|
|
1459
|
-
}
|
|
1460
|
-
} = _ref13;
|
|
1461
|
-
return section === 'system';
|
|
1462
|
-
}).forEach(_ref14 => {
|
|
1463
|
-
let {
|
|
1464
|
-
event: {
|
|
1465
|
-
data: [error],
|
|
1466
|
-
method
|
|
1467
|
-
}
|
|
1468
|
-
} = _ref14;
|
|
1469
|
-
if (method === 'ExtrinsicFailed') {
|
|
1470
|
-
eventData.errors.push(new _TransactionError.TransactionError(_types.BasicTxErrorType.SEND_TRANSACTION_FAILED, error.toString()));
|
|
1471
|
-
emitter.emit('error', eventData);
|
|
1472
|
-
} else if (method === 'ExtrinsicSuccess') {
|
|
1473
|
-
emitter.emit('success', eventData);
|
|
1466
|
+
|
|
1467
|
+
// Transaction finished
|
|
1468
|
+
if (!isFinish) {
|
|
1469
|
+
if (txState.status.isInBlock || txState.status.isFinalized) {
|
|
1470
|
+
if (!eventData.extrinsicHash) {
|
|
1471
|
+
eventData.extrinsicHash = txState.txHash.toHex();
|
|
1474
1472
|
}
|
|
1475
|
-
|
|
1473
|
+
txState.events.filter(_ref13 => {
|
|
1474
|
+
let {
|
|
1475
|
+
event: {
|
|
1476
|
+
section
|
|
1477
|
+
}
|
|
1478
|
+
} = _ref13;
|
|
1479
|
+
return section === 'system';
|
|
1480
|
+
}).forEach(_ref14 => {
|
|
1481
|
+
let {
|
|
1482
|
+
event: {
|
|
1483
|
+
data: [error],
|
|
1484
|
+
method
|
|
1485
|
+
}
|
|
1486
|
+
} = _ref14;
|
|
1487
|
+
if (method === 'ExtrinsicFailed') {
|
|
1488
|
+
eventData.errors.push(new _TransactionError.TransactionError(_types.BasicTxErrorType.SEND_TRANSACTION_FAILED, error.toString()));
|
|
1489
|
+
emitter.emit('error', eventData);
|
|
1490
|
+
isFinish = true;
|
|
1491
|
+
} else if (method === 'ExtrinsicSuccess') {
|
|
1492
|
+
emitter.emit('success', eventData);
|
|
1493
|
+
isFinish = true;
|
|
1494
|
+
}
|
|
1495
|
+
});
|
|
1496
|
+
}
|
|
1476
1497
|
}
|
|
1477
1498
|
}).catch(e => {
|
|
1478
1499
|
eventData.errors.push(new _TransactionError.TransactionError(_types.BasicTxErrorType.SEND_TRANSACTION_FAILED, e.message));
|
|
@@ -351,7 +351,7 @@ export async function validationEvmDataTransactionMiddleware(koni, url, payload)
|
|
|
351
351
|
transaction.maxPriorityFeePerGas = feeCombine.maxPriorityFeePerGas;
|
|
352
352
|
} else if (feeCombine.gasPrice) {
|
|
353
353
|
estimateGas = new BigN(feeCombine.gasPrice || 0).multipliedBy(gasLimit).toFixed(0);
|
|
354
|
-
transaction.
|
|
354
|
+
transaction.gasPrice = feeCombine.gasPrice;
|
|
355
355
|
}
|
|
356
356
|
}
|
|
357
357
|
} catch (e) {
|
|
@@ -880,6 +880,9 @@ export default class KoniExtension {
|
|
|
880
880
|
}) {
|
|
881
881
|
return this.#koniState.priceService.getHistoryTokenPriceData(priceId, timeframe);
|
|
882
882
|
}
|
|
883
|
+
checkCoinGeckoPriceSupport(priceId) {
|
|
884
|
+
return this.#koniState.priceService.checkCoinGeckoPriceSupport(priceId);
|
|
885
|
+
}
|
|
883
886
|
subscribeCurrentTokenPrice(priceId, id, port) {
|
|
884
887
|
const cb = createSubscription(id, port);
|
|
885
888
|
const {
|
|
@@ -1443,7 +1446,8 @@ export default class KoniExtension {
|
|
|
1443
1446
|
xcmFeeDryRun = dryRunInfo.fee;
|
|
1444
1447
|
}
|
|
1445
1448
|
if (isAcrossBridgeTransfer) {
|
|
1446
|
-
const
|
|
1449
|
+
const data = await getAcrossQuote(params);
|
|
1450
|
+
const metadata = data.metadata;
|
|
1447
1451
|
inputData.metadata = {
|
|
1448
1452
|
amountOut: metadata.outputAmount,
|
|
1449
1453
|
rate: metadata.rate,
|
|
@@ -2583,11 +2587,12 @@ export default class KoniExtension {
|
|
|
2583
2587
|
let registry = new TypeRegistry();
|
|
2584
2588
|
if (isJsonPayload(payload)) {
|
|
2585
2589
|
const [, chainInfo] = this.#koniState.findNetworkKeyByGenesisHash(payload.genesisHash);
|
|
2586
|
-
const
|
|
2587
|
-
|
|
2590
|
+
const registries = await Promise.all([setupApiRegistry(chainInfo, this.#koniState), setupDatabaseRegistry(chainInfo, payload, this.#koniState), setupDappRegistry(payload, this.#koniState)]);
|
|
2591
|
+
const validRegistries = registries.filter(item => !!(item !== null && item !== void 0 && item.registry));
|
|
2592
|
+
if (validRegistries.length === 0) {
|
|
2588
2593
|
registry.setSignedExtensions(payload.signedExtensions);
|
|
2589
2594
|
} else {
|
|
2590
|
-
registry = getSuitableRegistry(
|
|
2595
|
+
registry = getSuitableRegistry(validRegistries, payload);
|
|
2591
2596
|
}
|
|
2592
2597
|
}
|
|
2593
2598
|
const result = request.sign(registry, pair);
|
|
@@ -4271,6 +4276,8 @@ export default class KoniExtension {
|
|
|
4271
4276
|
return await this.subscribePrice(id, port);
|
|
4272
4277
|
case 'pri(price.getHistory)':
|
|
4273
4278
|
return await this.getHistoryTokenPrice(request);
|
|
4279
|
+
case 'pri(price.checkCoinGeckoPriceSupport)':
|
|
4280
|
+
return this.checkCoinGeckoPriceSupport(request);
|
|
4274
4281
|
case 'pri(price.subscribeCurrentTokenPrice)':
|
|
4275
4282
|
return this.subscribeCurrentTokenPrice(request, id, port);
|
|
4276
4283
|
case 'pri(settings.savePriceCurrency)':
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
|
-
import { MetadataItem } from '@subwallet/extension-base/background/KoniTypes';
|
|
3
|
-
import { MetadataDef } from '@subwallet/extension-inject/types';
|
|
4
2
|
import { Registry, SignerPayloadJSON } from '@polkadot/types/types';
|
|
5
3
|
import KoniState from './handlers/State';
|
|
6
4
|
export interface RegistrySource {
|
|
@@ -8,6 +6,6 @@ export interface RegistrySource {
|
|
|
8
6
|
specVersion: string | number;
|
|
9
7
|
}
|
|
10
8
|
export declare function getSuitableRegistry(registries: RegistrySource[], payload: SignerPayloadJSON): Registry;
|
|
11
|
-
export declare function setupApiRegistry(chainInfo: _ChainInfo | undefined, koniState: KoniState): RegistrySource | null
|
|
12
|
-
export declare function setupDatabaseRegistry(
|
|
13
|
-
export declare function setupDappRegistry(
|
|
9
|
+
export declare function setupApiRegistry(chainInfo: _ChainInfo | undefined, koniState: KoniState): Promise<RegistrySource | null>;
|
|
10
|
+
export declare function setupDatabaseRegistry(chainInfo: _ChainInfo | undefined, payload: SignerPayloadJSON, koniState: KoniState): Promise<RegistrySource | null>;
|
|
11
|
+
export declare function setupDappRegistry(payload: SignerPayloadJSON, koniState: KoniState): Promise<RegistrySource | null>;
|
package/koni/background/utils.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import { wait } from '@subwallet/extension-base/utils';
|
|
4
5
|
import { metadataExpand } from '@subwallet/extension-chains/bundle';
|
|
5
6
|
import { Metadata, TypeRegistry } from '@polkadot/types';
|
|
6
7
|
export function getSuitableRegistry(registries, payload) {
|
|
@@ -23,41 +24,75 @@ export function getSuitableRegistry(registries, payload) {
|
|
|
23
24
|
});
|
|
24
25
|
return sortedRegistries[0].registry;
|
|
25
26
|
}
|
|
26
|
-
export function setupApiRegistry(chainInfo, koniState) {
|
|
27
|
+
export async function setupApiRegistry(chainInfo, koniState) {
|
|
27
28
|
if (!chainInfo) {
|
|
28
29
|
return null;
|
|
29
30
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
31
|
+
try {
|
|
32
|
+
const api = koniState.getSubstrateApi(chainInfo.slug).api;
|
|
33
|
+
if (!api) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Wait for the API to be ready or timeout after 1 second
|
|
38
|
+
await Promise.race([wait(1000).then(() => {
|
|
39
|
+
throw new Error('Timeout waiting for API to be ready');
|
|
40
|
+
}), api.isReady]);
|
|
41
|
+
|
|
42
|
+
// Extract the spec version and registry
|
|
43
|
+
const apiSpecVersion = api.runtimeVersion.specVersion.toString();
|
|
44
|
+
const registry = api.registry;
|
|
45
|
+
return {
|
|
46
|
+
registry,
|
|
47
|
+
specVersion: apiSpecVersion
|
|
48
|
+
};
|
|
49
|
+
} catch (e) {
|
|
50
|
+
console.error('Error in setupApiRegistry:', e);
|
|
40
51
|
return null;
|
|
41
52
|
}
|
|
42
|
-
const registry = new TypeRegistry();
|
|
43
|
-
const _metadata = new Metadata(registry, metadata.hexValue);
|
|
44
|
-
registry.register(metadata.types);
|
|
45
|
-
registry.setChainProperties(registry.createType('ChainProperties', metadata.tokenInfo));
|
|
46
|
-
registry.setMetadata(_metadata, payload.signedExtensions, metadata.userExtensions);
|
|
47
|
-
return {
|
|
48
|
-
registry,
|
|
49
|
-
specVersion: metadata.specVersion
|
|
50
|
-
};
|
|
51
53
|
}
|
|
52
|
-
export function
|
|
53
|
-
if (!
|
|
54
|
+
export async function setupDatabaseRegistry(chainInfo, payload, koniState) {
|
|
55
|
+
if (!chainInfo) {
|
|
56
|
+
console.warn('setupDatabaseRegistry: Missing chainInfo');
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
const metadata = await koniState.chainService.getMetadataByHash(payload.genesisHash);
|
|
61
|
+
if (!(metadata !== null && metadata !== void 0 && metadata.genesisHash)) {
|
|
62
|
+
console.warn('setupDatabaseRegistry: Metadata not found or invalid for genesisHash:', payload.genesisHash);
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
const registry = new TypeRegistry();
|
|
66
|
+
const _metadata = new Metadata(registry, metadata.hexValue);
|
|
67
|
+
registry.register(metadata.types);
|
|
68
|
+
registry.setChainProperties(registry.createType('ChainProperties', metadata.tokenInfo));
|
|
69
|
+
registry.setMetadata(_metadata, payload.signedExtensions, metadata.userExtensions);
|
|
70
|
+
return {
|
|
71
|
+
registry,
|
|
72
|
+
specVersion: metadata.specVersion
|
|
73
|
+
};
|
|
74
|
+
} catch (e) {
|
|
75
|
+
console.error('setupDatabaseRegistry: Error setting up database registry:', e);
|
|
54
76
|
return null;
|
|
55
77
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
78
|
+
}
|
|
79
|
+
export function setupDappRegistry(payload, koniState) {
|
|
80
|
+
return new Promise(resolve => {
|
|
81
|
+
const metadata = koniState.knownMetadata.find(meta => meta.genesisHash === payload.genesisHash);
|
|
82
|
+
if (!(metadata !== null && metadata !== void 0 && metadata.genesisHash)) {
|
|
83
|
+
return resolve(null);
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
const expanded = metadataExpand(metadata, false);
|
|
87
|
+
const registry = expanded.registry;
|
|
88
|
+
registry.setSignedExtensions(payload.signedExtensions, expanded.definition.userExtensions);
|
|
89
|
+
resolve({
|
|
90
|
+
registry,
|
|
91
|
+
specVersion: metadata.specVersion
|
|
92
|
+
});
|
|
93
|
+
} catch (e) {
|
|
94
|
+
console.error('setupDappRegistry: Error setting up DApp registry:', e);
|
|
95
|
+
resolve(null);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
63
98
|
}
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"./cjs/detectPackage.js"
|
|
18
18
|
],
|
|
19
19
|
"type": "module",
|
|
20
|
-
"version": "1.3.
|
|
20
|
+
"version": "1.3.35-0",
|
|
21
21
|
"main": "./cjs/index.js",
|
|
22
22
|
"module": "./index.js",
|
|
23
23
|
"types": "./index.d.ts",
|
|
@@ -2705,12 +2705,12 @@
|
|
|
2705
2705
|
"@sora-substrate/type-definitions": "^1.17.7",
|
|
2706
2706
|
"@substrate/connect": "^0.8.9",
|
|
2707
2707
|
"@subwallet/chain-list": "0.2.104",
|
|
2708
|
-
"@subwallet/extension-base": "^1.3.
|
|
2709
|
-
"@subwallet/extension-chains": "^1.3.
|
|
2710
|
-
"@subwallet/extension-dapp": "^1.3.
|
|
2711
|
-
"@subwallet/extension-inject": "^1.3.
|
|
2708
|
+
"@subwallet/extension-base": "^1.3.35-0",
|
|
2709
|
+
"@subwallet/extension-chains": "^1.3.35-0",
|
|
2710
|
+
"@subwallet/extension-dapp": "^1.3.35-0",
|
|
2711
|
+
"@subwallet/extension-inject": "^1.3.35-0",
|
|
2712
2712
|
"@subwallet/keyring": "^0.1.11",
|
|
2713
|
-
"@subwallet/subwallet-api-sdk": "^1.3.
|
|
2713
|
+
"@subwallet/subwallet-api-sdk": "^1.3.35-0",
|
|
2714
2714
|
"@subwallet/ui-keyring": "^0.1.11",
|
|
2715
2715
|
"@ton/core": "^0.56.3",
|
|
2716
2716
|
"@ton/crypto": "^3.2.0",
|
package/packageInfo.js
CHANGED
|
@@ -7,5 +7,5 @@ export const packageInfo = {
|
|
|
7
7
|
name: '@subwallet/extension-base',
|
|
8
8
|
path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
|
|
9
9
|
type: 'esm',
|
|
10
|
-
version: '1.3.
|
|
10
|
+
version: '1.3.35-0'
|
|
11
11
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ChainAsset
|
|
1
|
+
import { _ChainAsset } from '@subwallet/chain-list/types';
|
|
2
2
|
import { _Address } from '@subwallet/extension-base/background/KoniTypes';
|
|
3
3
|
import { _EvmApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
4
4
|
import { CommonOptimalTransferPath } from '@subwallet/extension-base/types/service-base';
|
|
@@ -11,4 +11,4 @@ export interface RequestOptimalTransferProcess {
|
|
|
11
11
|
}
|
|
12
12
|
export declare function getDefaultTransferProcess(): CommonOptimalTransferPath;
|
|
13
13
|
export declare function getSnowbridgeTransferProcessFromEvm(address: string, evmApi: _EvmApi, tokenInfo: _ChainAsset, amount: string): Promise<CommonOptimalTransferPath>;
|
|
14
|
-
export declare function getAcrossbridgeTransferProcessFromEvm(
|
|
14
|
+
export declare function getAcrossbridgeTransferProcessFromEvm(SpokePoolAddress: string): Promise<CommonOptimalTransferPath>;
|
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
|
|
4
4
|
import { COMMON_CHAIN_SLUGS } from '@subwallet/chain-list';
|
|
5
5
|
import { CommonStepType, DEFAULT_FIRST_STEP, MOCK_STEP_FEE } from '@subwallet/extension-base/types/service-base';
|
|
6
|
-
import { _getEvmChainId } from "../../chain-service/utils/index.js";
|
|
7
|
-
import { SpokePoolMapping } from "../transfer/xcm/acrossBridge/index.js";
|
|
8
6
|
export function getDefaultTransferProcess() {
|
|
9
7
|
return {
|
|
10
8
|
totalFee: [MOCK_STEP_FEE, MOCK_STEP_FEE],
|
|
@@ -44,9 +42,7 @@ export async function getSnowbridgeTransferProcessFromEvm(address, evmApi, token
|
|
|
44
42
|
result.totalFee.push(MOCK_STEP_FEE);
|
|
45
43
|
return Promise.resolve(result);
|
|
46
44
|
}
|
|
47
|
-
export async function getAcrossbridgeTransferProcessFromEvm(
|
|
48
|
-
const chainId = _getEvmChainId(originChainInfo);
|
|
49
|
-
const SpokePoolAddress = SpokePoolMapping[chainId].SpokePool.address;
|
|
45
|
+
export async function getAcrossbridgeTransferProcessFromEvm(SpokePoolAddress) {
|
|
50
46
|
const result = {
|
|
51
47
|
totalFee: [MOCK_STEP_FEE],
|
|
52
48
|
steps: [DEFAULT_FIRST_STEP]
|
|
@@ -18,7 +18,7 @@ import BigN from 'bignumber.js';
|
|
|
18
18
|
import { t } from 'i18next';
|
|
19
19
|
import { BehaviorSubject } from 'rxjs';
|
|
20
20
|
import { noop } from '@polkadot/util';
|
|
21
|
-
import { _isAcrossChainBridge } from "./transfer/xcm/acrossBridge/index.js";
|
|
21
|
+
import { _isAcrossChainBridge, getAcrossQuote } from "./transfer/xcm/acrossBridge/index.js";
|
|
22
22
|
import { BalanceMapImpl } from "./BalanceMapImpl.js";
|
|
23
23
|
import { subscribeBalance } from "./helpers/index.js";
|
|
24
24
|
|
|
@@ -577,7 +577,26 @@ export class BalanceService {
|
|
|
577
577
|
if (_isAcrossChainBridge(originChainInfo.slug, destChainInfo.slug)) {
|
|
578
578
|
const tokenInfo = this.state.chainService.getAssetBySlug(params.tokenSlug);
|
|
579
579
|
if (!_isNativeToken(tokenInfo)) {
|
|
580
|
-
|
|
580
|
+
const chainInfoMap = this.state.getChainInfoMap();
|
|
581
|
+
const originTokenInfo = this.state.getAssetBySlug(params.tokenSlug);
|
|
582
|
+
const destinationTokenInfo = this.state.getXcmEqualAssetByChain(params.destChain, params.tokenSlug);
|
|
583
|
+
if (!destinationTokenInfo) {
|
|
584
|
+
throw new Error('Destination token info not found');
|
|
585
|
+
}
|
|
586
|
+
const inputData = {
|
|
587
|
+
destinationTokenInfo,
|
|
588
|
+
originTokenInfo,
|
|
589
|
+
sendingValue: params.amount,
|
|
590
|
+
sender: params.address,
|
|
591
|
+
recipient: params.address,
|
|
592
|
+
destinationChain: chainInfoMap[destinationTokenInfo.originChain],
|
|
593
|
+
originChain: chainInfoMap[originTokenInfo.originChain]
|
|
594
|
+
};
|
|
595
|
+
const data = await getAcrossQuote(inputData);
|
|
596
|
+
if (!data) {
|
|
597
|
+
throw new Error('Failed to fetch Across Bridge Data. Please try again later');
|
|
598
|
+
}
|
|
599
|
+
return getAcrossbridgeTransferProcessFromEvm(data.to);
|
|
581
600
|
}
|
|
582
601
|
}
|
|
583
602
|
return getDefaultTransferProcess();
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { CreateXcmExtrinsicProps } from '..';
|
|
2
2
|
export declare function _isAcrossChainBridge(srcChain: string, destChain: string): boolean;
|
|
3
3
|
export declare function _isAcrossTestnetBridge(srcChain: string): boolean;
|
|
4
|
-
export declare const SpokePoolMapping: Record<number, {
|
|
5
|
-
SpokePool: {
|
|
6
|
-
address: string;
|
|
7
|
-
blockNumber: number;
|
|
8
|
-
};
|
|
9
|
-
}>;
|
|
10
4
|
export declare const AcrossErrorMsg: {
|
|
11
5
|
AMOUNT_TOO_LOW: string;
|
|
12
6
|
AMOUNT_TOO_HIGH: string;
|
|
13
7
|
};
|
|
14
|
-
interface AcrossQuote {
|
|
8
|
+
export interface AcrossQuote {
|
|
15
9
|
outputAmount: string;
|
|
16
10
|
rate: string;
|
|
17
11
|
}
|
|
18
|
-
|
|
12
|
+
interface XcmApiResponse {
|
|
13
|
+
sender: string;
|
|
14
|
+
to: string;
|
|
15
|
+
transferEncodedCall: string;
|
|
16
|
+
value: string;
|
|
17
|
+
metadata?: any;
|
|
18
|
+
}
|
|
19
|
+
export declare const getAcrossQuote: ({ destinationChain, destinationTokenInfo, originChain, originTokenInfo, recipient, sender, sendingValue }: CreateXcmExtrinsicProps) => Promise<XcmApiResponse>;
|
|
19
20
|
export {};
|