@subwallet/extension-base 1.3.53-0 → 1.3.54-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 +10 -3
- package/cjs/koni/background/handlers/Extension.js +4 -4
- package/cjs/koni/background/handlers/State.js +1 -0
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/transfer/xcm/snowBridge.js +21 -10
- package/cjs/services/chain-online-service/index.js +168 -15
- package/cjs/services/chain-service/index.js +39 -10
- package/cjs/services/chain-service/utils/patch.js +2 -2
- package/cjs/services/earning-service/constants/chains.js +2 -4
- package/cjs/services/earning-service/handlers/base.js +1 -1
- package/cjs/services/earning-service/handlers/native-staking/base.js +4 -2
- package/cjs/services/earning-service/handlers/native-staking/dtao.js +9 -3
- package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +1 -10
- package/cjs/services/earning-service/handlers/native-staking/tao.js +24 -14
- package/cjs/services/earning-service/service.js +2 -2
- package/cjs/services/migration-service/scripts/MigrateTransactionHistoryBySymbol.js +6 -2
- package/cjs/services/migration-service/scripts/databases/MigrateAssetSetting.js +6 -2
- package/cjs/services/migration-service/scripts/index.js +2 -2
- package/cjs/services/swap-service/index.js +24 -18
- package/cjs/services/transaction-service/utils.js +25 -16
- package/koni/background/handlers/Extension.d.ts +1 -1
- package/koni/background/handlers/Extension.js +4 -4
- package/koni/background/handlers/State.js +1 -0
- package/package.json +8 -6
- package/packageInfo.js +1 -1
- package/services/balance-service/transfer/xcm/snowBridge.js +21 -10
- package/services/chain-online-service/index.d.ts +4 -1
- package/services/chain-online-service/index.js +168 -15
- package/services/chain-service/index.js +39 -10
- package/services/chain-service/utils/patch.d.ts +1 -1
- package/services/chain-service/utils/patch.js +2 -2
- package/services/earning-service/constants/chains.d.ts +0 -1
- package/services/earning-service/constants/chains.js +1 -2
- package/services/earning-service/handlers/base.d.ts +3 -3
- package/services/earning-service/handlers/base.js +1 -1
- package/services/earning-service/handlers/native-staking/base.js +4 -2
- package/services/earning-service/handlers/native-staking/dtao.d.ts +4 -3
- package/services/earning-service/handlers/native-staking/dtao.js +9 -3
- package/services/earning-service/handlers/native-staking/relay-chain.d.ts +0 -2
- package/services/earning-service/handlers/native-staking/relay-chain.js +2 -11
- package/services/earning-service/handlers/native-staking/tao.d.ts +1 -0
- package/services/earning-service/handlers/native-staking/tao.js +24 -14
- package/services/earning-service/service.d.ts +3 -3
- package/services/earning-service/service.js +2 -2
- package/services/migration-service/scripts/MigrateTransactionHistoryBySymbol.js +6 -2
- package/services/migration-service/scripts/databases/MigrateAssetSetting.js +6 -2
- package/services/migration-service/scripts/index.js +2 -2
- package/services/swap-service/index.js +24 -18
- package/services/transaction-service/utils.js +25 -16
- package/types/yield/actions/join/submit.d.ts +5 -0
- package/types/yield/actions/others.d.ts +7 -2
- package/types/yield/info/account/info.d.ts +1 -0
|
@@ -14,6 +14,7 @@ var _basePara = _interopRequireDefault(require("@subwallet/extension-base/servic
|
|
|
14
14
|
var _types = require("@subwallet/extension-base/types");
|
|
15
15
|
var _environment = require("@subwallet/extension-base/types/environment");
|
|
16
16
|
var _utils3 = require("@subwallet/extension-base/utils");
|
|
17
|
+
var _fetchStaticCache = require("@subwallet/extension-base/utils/fetchStaticCache");
|
|
17
18
|
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
18
19
|
var _i18next = require("i18next");
|
|
19
20
|
var _rxjs = require("rxjs");
|
|
@@ -52,21 +53,12 @@ class BittensorCache {
|
|
|
52
53
|
}
|
|
53
54
|
async fetchData() {
|
|
54
55
|
try {
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
headers: {
|
|
58
|
-
'Content-Type': 'application/json'
|
|
59
|
-
}
|
|
56
|
+
const fetchData = await (0, _fetchStaticCache.fetchStaticCache)('earning/dtao/validator.json', {
|
|
57
|
+
data: {}
|
|
60
58
|
});
|
|
61
|
-
|
|
62
|
-
console.error('Fetch bittensor delegates fail:', resp.status);
|
|
63
|
-
return this.cache || {
|
|
64
|
-
data: []
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
const rawData = await resp.json();
|
|
59
|
+
const validators = Object.values(fetchData.data);
|
|
68
60
|
const data = {
|
|
69
|
-
data:
|
|
61
|
+
data: validators.filter(validator => parseFloat(validator.root_stake) > 0)
|
|
70
62
|
};
|
|
71
63
|
this.cache = data;
|
|
72
64
|
this.promise = null;
|
|
@@ -79,7 +71,8 @@ class BittensorCache {
|
|
|
79
71
|
this.cache = newData;
|
|
80
72
|
}
|
|
81
73
|
}).catch(console.error);
|
|
82
|
-
}, 60 *
|
|
74
|
+
}, 60 * 1000); // Cache 1 minute
|
|
75
|
+
|
|
83
76
|
return data;
|
|
84
77
|
} catch (error) {
|
|
85
78
|
console.error(error);
|
|
@@ -110,6 +103,23 @@ class BittensorCache {
|
|
|
110
103
|
};
|
|
111
104
|
}
|
|
112
105
|
}
|
|
106
|
+
async fetchSubnetFeeRate(netuid) {
|
|
107
|
+
try {
|
|
108
|
+
var _subnet$fee_rate;
|
|
109
|
+
const resp = await (0, _utils3.fetchFromProxyService)(_environment.ProxyServiceRoute.BITTENSOR, '/subnet/latest/v1', {
|
|
110
|
+
method: 'GET',
|
|
111
|
+
headers: {
|
|
112
|
+
'Content-Type': 'application/json'
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
const rawData = await resp.json();
|
|
116
|
+
const subnet = rawData.data.find(item => item.netuid === netuid);
|
|
117
|
+
return (_subnet$fee_rate = subnet === null || subnet === void 0 ? void 0 : subnet.fee_rate) !== null && _subnet$fee_rate !== void 0 ? _subnet$fee_rate : '0.0005';
|
|
118
|
+
} catch (error) {
|
|
119
|
+
console.error(error);
|
|
120
|
+
return '0.0005'; // Default fee rate if fetch fails
|
|
121
|
+
}
|
|
122
|
+
}
|
|
113
123
|
}
|
|
114
124
|
|
|
115
125
|
// export async function fetchTaoDelegateState (address: string): Promise<RawDelegateState> {
|
|
@@ -959,14 +959,14 @@ class EarningService {
|
|
|
959
959
|
return Promise.reject(new _TransactionError.TransactionError(_types2.BasicTxErrorType.INTERNAL_ERROR));
|
|
960
960
|
}
|
|
961
961
|
}
|
|
962
|
-
async
|
|
962
|
+
async yieldGetEarningImpact(params) {
|
|
963
963
|
await this.eventService.waitChainReady;
|
|
964
964
|
const {
|
|
965
965
|
slug
|
|
966
966
|
} = params;
|
|
967
967
|
const handler = this.getPoolHandler(slug);
|
|
968
968
|
if (handler) {
|
|
969
|
-
return handler.
|
|
969
|
+
return handler.getEarningImpact(params);
|
|
970
970
|
} else {
|
|
971
971
|
return Promise.reject(new _TransactionError.TransactionError(_types2.BasicTxErrorType.INTERNAL_ERROR));
|
|
972
972
|
}
|
|
@@ -14,8 +14,12 @@ class MigrateTransactionHistoryBySymbol extends _Base.default {
|
|
|
14
14
|
const state = this.state;
|
|
15
15
|
try {
|
|
16
16
|
const changeSlugsMap = {
|
|
17
|
-
'
|
|
18
|
-
'
|
|
17
|
+
'bifrost_testnet-NATIVE-BNC': 'bifrost_testnet-NATIVE-BFC',
|
|
18
|
+
'energy_web_x_rococo-NATIVE-VT': 'energy_web_x_rococo-NATIVE-EWT',
|
|
19
|
+
'chainflip_dot-NATIVE-DOT': 'chainflip_dot-NATIVE-Unit',
|
|
20
|
+
'autonomys_taurus-NATIVE-AI3': 'autonomys_taurus-NATIVE-tAI3',
|
|
21
|
+
'fraxtal-NATIVE-frxETH': 'fraxtal-ERC20-frxETH-0xFC00000000000000000000000000000000000006',
|
|
22
|
+
'arbitrum_one-ERC20-USDT-0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9': 'arbitrum_one-ERC20-USD₮0-0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9'
|
|
19
23
|
};
|
|
20
24
|
const allTxs = [];
|
|
21
25
|
await Promise.all(Object.entries(changeSlugsMap).map(async (_ref, i) => {
|
|
@@ -13,8 +13,12 @@ class MigrateAssetSetting extends _Base.default {
|
|
|
13
13
|
async run() {
|
|
14
14
|
try {
|
|
15
15
|
const changeSlugsMap = {
|
|
16
|
-
'
|
|
17
|
-
'
|
|
16
|
+
'bifrost_testnet-NATIVE-BNC': 'bifrost_testnet-NATIVE-BFC',
|
|
17
|
+
'energy_web_x_rococo-NATIVE-VT': 'energy_web_x_rococo-NATIVE-EWT',
|
|
18
|
+
'chainflip_dot-NATIVE-DOT': 'chainflip_dot-NATIVE-Unit',
|
|
19
|
+
'autonomys_taurus-NATIVE-AI3': 'autonomys_taurus-NATIVE-tAI3',
|
|
20
|
+
'fraxtal-NATIVE-frxETH': 'fraxtal-ERC20-frxETH-0xFC00000000000000000000000000000000000006',
|
|
21
|
+
'arbitrum_one-ERC20-USDT-0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9': 'arbitrum_one-ERC20-USD₮0-0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9'
|
|
18
22
|
};
|
|
19
23
|
const assetSetting = await this.state.chainService.getAssetSettings();
|
|
20
24
|
const migratedAssetSetting = {};
|
|
@@ -63,8 +63,8 @@ var _default = {
|
|
|
63
63
|
'1.1.33-01': _MigrateLedgerAccountV.default,
|
|
64
64
|
'1.1.41-01': _DeleteChainStaking.default,
|
|
65
65
|
// '1.1.46-01': AutoEnableSomeTokens,
|
|
66
|
-
'1.
|
|
67
|
-
'1.
|
|
66
|
+
'1.3.53-01': _MigrateAssetSetting.default,
|
|
67
|
+
'1.3.53-02': _MigrateTransactionHistoryBySymbol.default,
|
|
68
68
|
'1.2.69-01': _MigrateRemoveGenesisHash.default,
|
|
69
69
|
'1.2.13-01': _ReloadMetadata.default,
|
|
70
70
|
'1.2.32-01': _MigratePairData.default,
|
|
@@ -50,24 +50,30 @@ class SwapService {
|
|
|
50
50
|
..._request,
|
|
51
51
|
isSupportKyberVersion: true
|
|
52
52
|
};
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
53
|
+
try {
|
|
54
|
+
const quotes = await _subwalletServicesSdk.default.swapApi.fetchSwapQuoteData(request);
|
|
55
|
+
if (Array.isArray(quotes)) {
|
|
56
|
+
quotes.forEach(quoteData => {
|
|
57
|
+
if (!_swap._SUPPORTED_SWAP_PROVIDERS.includes(quoteData.provider)) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (!quoteData.quote || Object.keys(quoteData.quote).length === 0) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (!('errorClass' in quoteData.quote)) {
|
|
64
|
+
availableQuotes.push({
|
|
65
|
+
quote: quoteData.quote
|
|
66
|
+
});
|
|
67
|
+
} else {
|
|
68
|
+
availableQuotes.push({
|
|
69
|
+
error: new _SwapError.SwapError(quoteData.quote.errorType, quoteData.quote.message)
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
} catch (err) {
|
|
75
|
+
availableQuotes.push({
|
|
76
|
+
error: new _SwapError.SwapError(_swap.SwapErrorType.ASSET_NOT_SUPPORTED)
|
|
71
77
|
});
|
|
72
78
|
}
|
|
73
79
|
return availableQuotes;
|
|
@@ -24,6 +24,21 @@ function getBlockExplorerAccountRoute(explorerLink) {
|
|
|
24
24
|
if (explorerLink.includes('explorer.subspace.network')) {
|
|
25
25
|
return 'accounts';
|
|
26
26
|
}
|
|
27
|
+
if (explorerLink.includes('edgscan.ink')) {
|
|
28
|
+
return 'accounts';
|
|
29
|
+
}
|
|
30
|
+
if (explorerLink.includes('devnet-explorer.mosaicchain.io')) {
|
|
31
|
+
return 'accounts';
|
|
32
|
+
}
|
|
33
|
+
if (explorerLink.includes('statescan.io')) {
|
|
34
|
+
return '#/accounts';
|
|
35
|
+
}
|
|
36
|
+
if (explorerLink.includes('explorer.joystream.org')) {
|
|
37
|
+
return '#/accounts';
|
|
38
|
+
}
|
|
39
|
+
if (explorerLink.includes('explorer.gen6.app')) {
|
|
40
|
+
return '#/accounts';
|
|
41
|
+
}
|
|
27
42
|
if (explorerLink.includes('deeperscan.io')) {
|
|
28
43
|
return 'account';
|
|
29
44
|
}
|
|
@@ -33,24 +48,18 @@ function getBlockExplorerAccountRoute(explorerLink) {
|
|
|
33
48
|
if (explorerLink.includes('3dpscan.io')) {
|
|
34
49
|
return 'account';
|
|
35
50
|
}
|
|
36
|
-
if (explorerLink.includes('
|
|
37
|
-
return '
|
|
38
|
-
}
|
|
39
|
-
if (explorerLink.includes('explorer.gen6.app')) {
|
|
40
|
-
return '#/accounts';
|
|
41
|
-
}
|
|
42
|
-
if (explorerLink.includes('astral.autonomys')) {
|
|
43
|
-
return 'accounts';
|
|
51
|
+
if (explorerLink.includes('main.dentnet.io')) {
|
|
52
|
+
return 'account';
|
|
44
53
|
}
|
|
45
54
|
if (explorerLink.includes('taostats.io')) {
|
|
46
55
|
return 'account';
|
|
47
56
|
}
|
|
57
|
+
if (explorerLink.includes('uniquescan.io')) {
|
|
58
|
+
return 'account';
|
|
59
|
+
}
|
|
48
60
|
if (explorerLink.includes('tonviewer.com')) {
|
|
49
61
|
return '';
|
|
50
62
|
}
|
|
51
|
-
if (explorerLink.includes('devnet-explorer.mosaicchain.io')) {
|
|
52
|
-
return 'accounts';
|
|
53
|
-
}
|
|
54
63
|
if (explorerLink.includes('pdexmon.com')) {
|
|
55
64
|
return 'holders';
|
|
56
65
|
}
|
|
@@ -60,7 +69,7 @@ function getBlockExplorerTxRoute(chainInfo) {
|
|
|
60
69
|
if ((0, _utils._isPureEvmChain)(chainInfo) || (0, _utils._isPureBitcoinChain)(chainInfo)) {
|
|
61
70
|
return 'tx';
|
|
62
71
|
}
|
|
63
|
-
if (['moonbeam'].includes(chainInfo.slug)) {
|
|
72
|
+
if (['moonbeam', 'crabParachain'].includes(chainInfo.slug)) {
|
|
64
73
|
return 'tx';
|
|
65
74
|
}
|
|
66
75
|
if ((0, _utils._isPureCardanoChain)(chainInfo) || (0, _utils._isPureTonChain)(chainInfo)) {
|
|
@@ -69,15 +78,15 @@ function getBlockExplorerTxRoute(chainInfo) {
|
|
|
69
78
|
if (['aventus', 'deeper_network'].includes(chainInfo.slug)) {
|
|
70
79
|
return 'transaction';
|
|
71
80
|
}
|
|
72
|
-
if (['gen6_public'].includes(chainInfo.slug)) {
|
|
81
|
+
if (['gen6_public', 'joystream'].includes(chainInfo.slug)) {
|
|
73
82
|
return '#/extrinsics';
|
|
74
83
|
}
|
|
84
|
+
if (['edgeware'].includes(chainInfo.slug)) {
|
|
85
|
+
return 'extrinsics';
|
|
86
|
+
}
|
|
75
87
|
if (['mosaicTest', 'polkadex'].includes(chainInfo.slug)) {
|
|
76
88
|
return 'transactions';
|
|
77
89
|
}
|
|
78
|
-
if (['autonomys'].includes(chainInfo.slug)) {
|
|
79
|
-
return 'extrinsics';
|
|
80
|
-
}
|
|
81
90
|
const explorerLink = (0, _utils._getBlockExplorerFromChain)(chainInfo);
|
|
82
91
|
if (explorerLink && explorerLink.includes('statescan.io')) {
|
|
83
92
|
return '#/extrinsics';
|
|
@@ -252,7 +252,7 @@ export default class KoniExtension {
|
|
|
252
252
|
private yieldSubmitWithdrawal;
|
|
253
253
|
private yieldSubmitCancelWithdrawal;
|
|
254
254
|
private yieldSubmitClaimReward;
|
|
255
|
-
private
|
|
255
|
+
private yieldGetEarningImpact;
|
|
256
256
|
private handleYieldChangeValidator;
|
|
257
257
|
private unlockDotCheckCanMint;
|
|
258
258
|
private unlockDotSubscribeMintedData;
|
|
@@ -3960,7 +3960,7 @@ export default class KoniExtension {
|
|
|
3960
3960
|
chainType: (poolHandler === null || poolHandler === void 0 ? void 0 : poolHandler.transactionChainType) || ChainType.SUBSTRATE
|
|
3961
3961
|
});
|
|
3962
3962
|
}
|
|
3963
|
-
async
|
|
3963
|
+
async yieldGetEarningImpact(params) {
|
|
3964
3964
|
const {
|
|
3965
3965
|
slug
|
|
3966
3966
|
} = params;
|
|
@@ -3968,7 +3968,7 @@ export default class KoniExtension {
|
|
|
3968
3968
|
if (!poolHandler) {
|
|
3969
3969
|
return this.#koniState.transactionService.generateBeforeHandleResponseErrors([new TransactionError(BasicTxErrorType.INVALID_PARAMS)]);
|
|
3970
3970
|
}
|
|
3971
|
-
const slippage = await this.#koniState.earningService.
|
|
3971
|
+
const slippage = await this.#koniState.earningService.yieldGetEarningImpact(params);
|
|
3972
3972
|
return slippage;
|
|
3973
3973
|
}
|
|
3974
3974
|
async handleYieldChangeValidator(params) {
|
|
@@ -4857,8 +4857,8 @@ export default class KoniExtension {
|
|
|
4857
4857
|
return await this.yieldSubmitCancelWithdrawal(request);
|
|
4858
4858
|
case 'pri(yield.claimReward.submit)':
|
|
4859
4859
|
return await this.yieldSubmitClaimReward(request);
|
|
4860
|
-
case 'pri(yield.
|
|
4861
|
-
return await this.
|
|
4860
|
+
case 'pri(yield.getEarningImpact)':
|
|
4861
|
+
return await this.yieldGetEarningImpact(request);
|
|
4862
4862
|
case 'pri(yield.changeValidator.submit)':
|
|
4863
4863
|
return await this.handleYieldChangeValidator(request);
|
|
4864
4864
|
/* Others */
|
|
@@ -1803,6 +1803,7 @@ export default class KoniState {
|
|
|
1803
1803
|
this.chainService.resetWallet(resetAll);
|
|
1804
1804
|
await this.walletConnectService.resetWallet(resetAll);
|
|
1805
1805
|
await this.chainService.init();
|
|
1806
|
+
this.chainOnlineService.resetFirstApplied();
|
|
1806
1807
|
this.chainOnlineService.checkLatestData();
|
|
1807
1808
|
this.chainService.checkLatestData();
|
|
1808
1809
|
this.chainService.subscribeChainInfoMap().subscribe(() => {
|
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.54-0",
|
|
21
21
|
"main": "./cjs/index.js",
|
|
22
22
|
"module": "./index.js",
|
|
23
23
|
"types": "./index.d.ts",
|
|
@@ -2868,14 +2868,16 @@
|
|
|
2868
2868
|
"@polkadot/util-crypto": "^13.5.3",
|
|
2869
2869
|
"@polkadot/x-global": "^13.5.3",
|
|
2870
2870
|
"@reduxjs/toolkit": "^1.9.1",
|
|
2871
|
+
"@snowbridge/api": "^0.2.0",
|
|
2872
|
+
"@snowbridge/registry": "^0.2.0",
|
|
2871
2873
|
"@sora-substrate/type-definitions": "^1.17.7",
|
|
2872
2874
|
"@substrate/connect": "^0.8.9",
|
|
2873
2875
|
"@subwallet-monorepos/subwallet-services-sdk": "^0.1.8",
|
|
2874
|
-
"@subwallet/chain-list": "0.2.
|
|
2875
|
-
"@subwallet/extension-base": "^1.3.
|
|
2876
|
-
"@subwallet/extension-chains": "^1.3.
|
|
2877
|
-
"@subwallet/extension-dapp": "^1.3.
|
|
2878
|
-
"@subwallet/extension-inject": "^1.3.
|
|
2876
|
+
"@subwallet/chain-list": "0.2.112-beta.9",
|
|
2877
|
+
"@subwallet/extension-base": "^1.3.54-0",
|
|
2878
|
+
"@subwallet/extension-chains": "^1.3.54-0",
|
|
2879
|
+
"@subwallet/extension-dapp": "^1.3.54-0",
|
|
2880
|
+
"@subwallet/extension-inject": "^1.3.54-0",
|
|
2879
2881
|
"@subwallet/keyring": "^0.1.13",
|
|
2880
2882
|
"@subwallet/ui-keyring": "^0.1.13",
|
|
2881
2883
|
"@ton/core": "^0.56.3",
|
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.54-0'
|
|
11
11
|
};
|
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import { Context, contextConfigFor, toPolkadotV2 } from '@snowbridge/api';
|
|
5
|
+
import { assetRegistryFor } from '@snowbridge/registry';
|
|
4
6
|
import { getWeb3Contract } from '@subwallet/extension-base/koni/api/contract-handler/evm/web3';
|
|
5
7
|
import { _SNOWBRIDGE_GATEWAY_ABI, getSnowBridgeGatewayContract } from '@subwallet/extension-base/koni/api/contract-handler/utils';
|
|
6
8
|
import { _getContractAddressOfToken, _getSubstrateParaId, _isChainEvmCompatible } from '@subwallet/extension-base/services/chain-service/utils';
|
|
7
9
|
import { combineEthFee } from '@subwallet/extension-base/utils';
|
|
8
10
|
import { u8aToHex } from '@polkadot/util';
|
|
9
11
|
import { decodeAddress } from '@polkadot/util-crypto';
|
|
10
|
-
async function getSendFeeToken(contract, tokenContract, destChainParaId, destinationFee) {
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
|
12
|
-
const quoteSendTokenFee = contract.methods.quoteSendTokenFee(tokenContract, destChainParaId, destinationFee);
|
|
13
|
-
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
15
|
-
return await quoteSendTokenFee.call();
|
|
16
|
-
}
|
|
17
12
|
export async function getSnowBridgeEvmTransfer(tokenInfo, originChainInfo, destinationChainInfo, sender, recipientAddress, value, evmApi, _feeInfo, feeCustom, feeOption) {
|
|
18
13
|
const snowBridgeContractAddress = getSnowBridgeGatewayContract(originChainInfo.slug);
|
|
19
14
|
const snowBridgeContract = getWeb3Contract(snowBridgeContractAddress, evmApi, _SNOWBRIDGE_GATEWAY_ABI);
|
|
@@ -23,7 +18,24 @@ export async function getSnowBridgeEvmTransfer(tokenInfo, originChainInfo, desti
|
|
|
23
18
|
kind: 1,
|
|
24
19
|
data: _isChainEvmCompatible(destinationChainInfo) ? recipientAddress : u8aToHex(decodeAddress(recipientAddress))
|
|
25
20
|
};
|
|
26
|
-
|
|
21
|
+
let destinationFee;
|
|
22
|
+
let totalFee;
|
|
23
|
+
try {
|
|
24
|
+
const environment = 'polkadot_mainnet';
|
|
25
|
+
const context = new Context(contextConfigFor(environment));
|
|
26
|
+
const registry = assetRegistryFor(environment);
|
|
27
|
+
const deliveryFee = await toPolkadotV2.getDeliveryFee(context, registry, tokenContract, destinationChainParaId);
|
|
28
|
+
console.log('deliveryFee', deliveryFee);
|
|
29
|
+
totalFee = deliveryFee.totalFeeInWei.toString();
|
|
30
|
+
destinationFee = (deliveryFee.destinationDeliveryFeeDOT + deliveryFee.destinationExecutionFeeDOT).toString();
|
|
31
|
+
|
|
32
|
+
// Clean up all open connections
|
|
33
|
+
await context.destroyContext();
|
|
34
|
+
} catch (error) {
|
|
35
|
+
console.error('Cannot get snow-bridge delivery fees with error:', error);
|
|
36
|
+
totalFee = '0';
|
|
37
|
+
destinationFee = '0';
|
|
38
|
+
}
|
|
27
39
|
|
|
28
40
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
|
29
41
|
const transferCall = snowBridgeContract.methods.sendToken(tokenContract, destinationChainParaId, recipient, destinationFee, value);
|
|
@@ -32,11 +44,10 @@ export async function getSnowBridgeEvmTransfer(tokenInfo, originChainInfo, desti
|
|
|
32
44
|
const feeInfo = _feeInfo;
|
|
33
45
|
const _feeCustom = feeCustom;
|
|
34
46
|
const feeCombine = combineEthFee(feeInfo, feeOption, _feeCustom);
|
|
35
|
-
const sendTokenFee = await getSendFeeToken(snowBridgeContract, tokenContract, destinationChainParaId, destinationFee);
|
|
36
47
|
const transactionConfig = {
|
|
37
48
|
from: sender,
|
|
38
49
|
to: snowBridgeContractAddress,
|
|
39
|
-
value:
|
|
50
|
+
value: totalFee,
|
|
40
51
|
data: transferEncodedCall,
|
|
41
52
|
...feeCombine
|
|
42
53
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
|
+
import { _AssetType, _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
|
|
3
3
|
import { ChainService } from '@subwallet/extension-base/services/chain-service';
|
|
4
4
|
import { PatchInfo } from '@subwallet/extension-base/services/chain-service/utils';
|
|
5
5
|
import { EventService } from '@subwallet/extension-base/services/event-service';
|
|
@@ -13,9 +13,12 @@ export declare class ChainOnlineService {
|
|
|
13
13
|
private firstApplied;
|
|
14
14
|
refreshLatestChainDataTimeOut: NodeJS.Timer | undefined;
|
|
15
15
|
constructor(chainService: ChainService, settingService: SettingService, eventService: EventService, dbService: DatabaseService);
|
|
16
|
+
resetFirstApplied(): void;
|
|
16
17
|
validatePatchWithHash(latestPatch: PatchInfo): boolean;
|
|
17
18
|
validatePatchBeforeStore(candidateChainInfoMap: Record<string, _ChainInfo>, candidateAssetRegistry: Record<string, _ChainAsset>, latestPatch: PatchInfo): boolean;
|
|
18
19
|
mergeChainList(oldChainInfoMap: Record<string, _ChainInfo>, latestChainInfo: Record<string, _ChainInfo>): Record<string, _ChainInfo>;
|
|
20
|
+
checkExistedPredefinedChain(latestChainInfoMap: Record<string, _ChainInfo>, genesisHash?: string, evmChainId?: number): string;
|
|
21
|
+
generateSlugForSmartContractAsset(originChain: string, assetType: _AssetType, symbol: string, contractAddress: string): string;
|
|
19
22
|
handleLatestPatch(latestPatch: PatchInfo): Promise<void>;
|
|
20
23
|
private fetchLatestPatchData;
|
|
21
24
|
handleLatestPatchData(): void;
|