@subwallet/extension-base 1.2.14-0 → 1.2.15-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/cjs/core/substrate/nominationpools-pallet.js +2 -1
- package/cjs/koni/api/nft/config.js +9 -5
- package/cjs/koni/api/nft/index.js +9 -1
- package/cjs/koni/api/nft/unique_network_nft/index.js +12 -20
- package/cjs/koni/background/handlers/Extension.js +12 -0
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/chain-service/constants.js +1 -0
- package/cjs/services/chain-service/health-check/constants/index.js +4 -4
- package/cjs/services/chain-service/health-check/utils/asset-info.js +23 -6
- package/cjs/services/chain-service/health-check/utils/chain-info.js +25 -2
- package/cjs/services/chain-service/health-check/utils/new-utils/asset-asset-validate.js +160 -0
- package/cjs/services/chain-service/health-check/utils/new-utils/asset-validate.js +45 -0
- package/cjs/services/chain-service/health-check/utils/new-utils/chain-asset-validate.js +73 -0
- package/cjs/services/chain-service/health-check/utils/new-utils/chain-validate.js +34 -0
- package/cjs/services/chain-service/index.js +30 -1
- package/cjs/services/earning-service/handlers/liquid-staking/acala.js +49 -19
- package/cjs/services/price-service/coingecko.js +57 -32
- package/cjs/services/price-service/index.js +30 -11
- package/core/substrate/nominationpools-pallet.js +2 -1
- package/koni/api/nft/config.d.ts +1 -0
- package/koni/api/nft/config.js +3 -1
- package/koni/api/nft/index.js +9 -1
- package/koni/api/nft/unique_network_nft/index.js +12 -20
- package/koni/background/handlers/Extension.js +12 -0
- package/package.json +26 -6
- package/packageInfo.js +1 -1
- package/services/chain-service/constants.d.ts +1 -0
- package/services/chain-service/constants.js +1 -0
- package/services/chain-service/health-check/constants/index.js +4 -4
- package/services/chain-service/health-check/utils/asset-info.d.ts +1 -0
- package/services/chain-service/health-check/utils/asset-info.js +20 -4
- package/services/chain-service/health-check/utils/chain-info.d.ts +4 -2
- package/services/chain-service/health-check/utils/chain-info.js +20 -0
- package/services/chain-service/health-check/utils/new-utils/asset-asset-validate.d.ts +10 -0
- package/services/chain-service/health-check/utils/new-utils/asset-asset-validate.js +146 -0
- package/services/chain-service/health-check/utils/new-utils/asset-validate.d.ts +3 -0
- package/services/chain-service/health-check/utils/new-utils/asset-validate.js +38 -0
- package/services/chain-service/health-check/utils/new-utils/chain-asset-validate.d.ts +5 -0
- package/services/chain-service/health-check/utils/new-utils/chain-asset-validate.js +64 -0
- package/services/chain-service/health-check/utils/new-utils/chain-validate.d.ts +4 -0
- package/services/chain-service/health-check/utils/new-utils/chain-validate.js +26 -0
- package/services/chain-service/index.js +30 -1
- package/services/chain-service/types.d.ts +5 -0
- package/services/earning-service/handlers/liquid-staking/acala.js +46 -17
- package/services/price-service/coingecko.js +54 -32
- package/services/price-service/index.js +29 -11
|
@@ -109,13 +109,12 @@ const getByAssetManagerWithAssetIdPallet = async (asset, api) => {
|
|
|
109
109
|
};
|
|
110
110
|
};
|
|
111
111
|
const getByAssetRegistryWithAssetIdPallet = async (asset, api) => {
|
|
112
|
-
const [_info
|
|
112
|
+
const [_info] = await api.queryMulti([[api.query.assetRegistry.assets, _getTokenOnChainAssetId(asset)]]);
|
|
113
113
|
const info = _info.toPrimitive();
|
|
114
|
-
const metadata = _metadata.toPrimitive();
|
|
115
114
|
return {
|
|
116
|
-
decimals:
|
|
115
|
+
decimals: info.decimals,
|
|
117
116
|
minAmount: info.existentialDeposit.toString(),
|
|
118
|
-
symbol:
|
|
117
|
+
symbol: info.symbol
|
|
119
118
|
};
|
|
120
119
|
};
|
|
121
120
|
export const getLocalAssetInfo = async (chain, asset, api) => {
|
|
@@ -264,4 +263,21 @@ export const compareAsset = (assetInfo, asset, errors) => {
|
|
|
264
263
|
var _asset$decimals;
|
|
265
264
|
errors.push(`Wrong decimals: current - ${(_asset$decimals = asset.decimals) !== null && _asset$decimals !== void 0 ? _asset$decimals : 'null'}, onChain - ${decimals}`);
|
|
266
265
|
}
|
|
266
|
+
};
|
|
267
|
+
export const validateAsset = (onchainAsset, chainlistAsset) => {
|
|
268
|
+
const {
|
|
269
|
+
decimals,
|
|
270
|
+
minAmount,
|
|
271
|
+
symbol
|
|
272
|
+
} = onchainAsset;
|
|
273
|
+
const chainlistMinAmount = chainlistAsset.minAmount || '0';
|
|
274
|
+
const chainlistDecimals = chainlistAsset.decimals || 0;
|
|
275
|
+
const chainlistSymbol = chainlistAsset.symbol;
|
|
276
|
+
console.log(`[i] minAmount: current - ${chainlistMinAmount}, onchain - ${minAmount}`);
|
|
277
|
+
console.log(`[i] decimals: current - ${chainlistDecimals}, onchain - ${decimals}`);
|
|
278
|
+
console.log(`[i] symbol: current - ${chainlistSymbol}, onchain - ${symbol}`);
|
|
279
|
+
const isValidSymbol = symbol === chainlistSymbol ? true : 'zk' + symbol === chainlistSymbol;
|
|
280
|
+
const isValidMinAmount = minAmount === chainlistMinAmount;
|
|
281
|
+
const isValidDecimal = decimals === chainlistDecimals;
|
|
282
|
+
return isValidSymbol && isValidMinAmount && isValidDecimal;
|
|
267
283
|
};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { AssetSpec } from '@subwallet/extension-base/services/chain-service/health-check/utils/asset-info';
|
|
2
|
-
interface NativeAssetInfo {
|
|
2
|
+
export interface NativeAssetInfo {
|
|
3
3
|
decimals: number;
|
|
4
4
|
existentialDeposit: string;
|
|
5
5
|
symbol: string;
|
|
6
6
|
}
|
|
7
7
|
export declare const compareNativeAsset: (assetInfo: AssetSpec, nativeAsset: NativeAssetInfo, errors: string[]) => void;
|
|
8
|
-
export
|
|
8
|
+
export declare const checkNativeAsset: (assetInfo: AssetSpec, nativeAsset: NativeAssetInfo) => boolean;
|
|
9
|
+
export declare const checkSs58Prefix: (onchainPrefix: number, chainlistPrefix: number) => boolean;
|
|
10
|
+
export declare const checkParachainId: (onchainPrefix: number | null, chainlistPrefix: number | null) => boolean;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { BIG_TEN } from '@subwallet/extension-base/services/chain-service/health-check/constants';
|
|
5
5
|
import BigN from 'bignumber.js';
|
|
6
|
+
// function for old health-check chain
|
|
6
7
|
export const compareNativeAsset = (assetInfo, nativeAsset, errors) => {
|
|
7
8
|
const {
|
|
8
9
|
decimals: _decimals,
|
|
@@ -25,4 +26,23 @@ export const compareNativeAsset = (assetInfo, nativeAsset, errors) => {
|
|
|
25
26
|
if (decimals !== _decimals) {
|
|
26
27
|
errors.push(`Wrong decimals: current - ${_decimals}, onChain - ${decimals}`);
|
|
27
28
|
}
|
|
29
|
+
};
|
|
30
|
+
export const checkNativeAsset = (assetInfo, nativeAsset) => {
|
|
31
|
+
const {
|
|
32
|
+
decimals: _decimals,
|
|
33
|
+
existentialDeposit: _minAmount,
|
|
34
|
+
symbol: _symbol
|
|
35
|
+
} = nativeAsset;
|
|
36
|
+
const {
|
|
37
|
+
decimals,
|
|
38
|
+
minAmount,
|
|
39
|
+
symbol
|
|
40
|
+
} = assetInfo;
|
|
41
|
+
return minAmount === _minAmount && symbol === _symbol && decimals === _decimals;
|
|
42
|
+
};
|
|
43
|
+
export const checkSs58Prefix = (onchainPrefix, chainlistPrefix) => {
|
|
44
|
+
return onchainPrefix === chainlistPrefix;
|
|
45
|
+
};
|
|
46
|
+
export const checkParachainId = (onchainPrefix, chainlistPrefix) => {
|
|
47
|
+
return onchainPrefix === chainlistPrefix;
|
|
28
48
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { _AssetRef, _ChainAsset, _ChainInfo, _MultiChainAsset } from '@subwallet/chain-list/types';
|
|
2
|
+
export declare function validateAssetGroupPrice(multiChainAsset: _MultiChainAsset, chainAsset: _ChainAsset): boolean;
|
|
3
|
+
export declare function validateAssetsGroupPrice(chainAsset1: _ChainAsset, chainAsset2: _ChainAsset): boolean;
|
|
4
|
+
export declare function checkMultichainAssetValid(chainAsset: _ChainAsset): boolean;
|
|
5
|
+
export declare function checkSwapAssetRef(slug: string, assetRef: _AssetRef): boolean;
|
|
6
|
+
export declare function validateNotDuplicateSmartcontract(chainAsset: _ChainAsset): boolean;
|
|
7
|
+
export declare function validateNativeLocalTransferMetadata(chainAsset: _ChainAsset): boolean;
|
|
8
|
+
export declare function validateSwapAlterAsset(assetRef: _AssetRef): boolean;
|
|
9
|
+
export declare function validateXcmMetadata(assetRef: _AssetRef): {};
|
|
10
|
+
export declare function checkValidSupportStaking(chainInfo: _ChainInfo): true | undefined;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { ChainAssetMap, MultiChainAssetMap } from '@subwallet/chain-list';
|
|
5
|
+
import { _TRANSFER_CHAIN_GROUP } from '@subwallet/extension-base/services/chain-service/constants';
|
|
6
|
+
|
|
7
|
+
// Check priceId valid in group asset
|
|
8
|
+
|
|
9
|
+
export function validateAssetGroupPrice(multiChainAsset, chainAsset) {
|
|
10
|
+
if (chainAsset.multiChainAsset !== multiChainAsset.slug) {
|
|
11
|
+
throw new Error(`Asset ${chainAsset.slug} are not in ${multiChainAsset.slug} group asset`);
|
|
12
|
+
}
|
|
13
|
+
return multiChainAsset.priceId === chainAsset.priceId;
|
|
14
|
+
}
|
|
15
|
+
export function validateAssetsGroupPrice(chainAsset1, chainAsset2) {
|
|
16
|
+
if (chainAsset1.multiChainAsset !== chainAsset2.multiChainAsset) {
|
|
17
|
+
throw new Error(`Asset ${chainAsset1.slug} and asset ${chainAsset2.slug} are not in a group asset`);
|
|
18
|
+
}
|
|
19
|
+
return chainAsset1.priceId === chainAsset2.priceId;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Check priceId valid in group asset
|
|
23
|
+
|
|
24
|
+
// Check multichainAsset valid
|
|
25
|
+
|
|
26
|
+
export function checkMultichainAssetValid(chainAsset) {
|
|
27
|
+
if (!chainAsset.multiChainAsset) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
return Object.keys(MultiChainAssetMap).includes(chainAsset.multiChainAsset);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Check multichainAsset valid
|
|
34
|
+
|
|
35
|
+
// Check slug asset ref
|
|
36
|
+
|
|
37
|
+
export function checkSwapAssetRef(slug, assetRef) {
|
|
38
|
+
return slug === `${assetRef.srcAsset}___${assetRef.destAsset}`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Check slug asset ref
|
|
42
|
+
|
|
43
|
+
// Check duplicate smartcontract
|
|
44
|
+
|
|
45
|
+
export function validateNotDuplicateSmartcontract(chainAsset) {
|
|
46
|
+
if (!['ERC20', 'ERC721', 'PSP22', 'PSP34', 'GRC20', 'GRC721'].includes(chainAsset.assetType)) {
|
|
47
|
+
throw new Error(`${chainAsset.slug} is not smart contract asset`);
|
|
48
|
+
}
|
|
49
|
+
const slug = chainAsset.slug;
|
|
50
|
+
const isDuplicate = Object.entries(ChainAssetMap).some(([key, tokenInfo]) => {
|
|
51
|
+
var _chainAsset$metadata, _tokenInfo$metadata;
|
|
52
|
+
return slug !== key && (chainAsset === null || chainAsset === void 0 ? void 0 : (_chainAsset$metadata = chainAsset.metadata) === null || _chainAsset$metadata === void 0 ? void 0 : _chainAsset$metadata.contractAddress) === (tokenInfo === null || tokenInfo === void 0 ? void 0 : (_tokenInfo$metadata = tokenInfo.metadata) === null || _tokenInfo$metadata === void 0 ? void 0 : _tokenInfo$metadata.contractAddress);
|
|
53
|
+
});
|
|
54
|
+
return !isDuplicate;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Check duplicate smartcontract
|
|
58
|
+
|
|
59
|
+
// ---------------------
|
|
60
|
+
|
|
61
|
+
// TRANSFER
|
|
62
|
+
|
|
63
|
+
export function validateNativeLocalTransferMetadata(chainAsset) {
|
|
64
|
+
if (!chainAsset.metadata) {
|
|
65
|
+
// recheck this
|
|
66
|
+
throw new Error(`Asset ${chainAsset.slug} is lack of metadata`);
|
|
67
|
+
}
|
|
68
|
+
const moonbeamGroup = ['moonbeam, moonbase, moonriver'];
|
|
69
|
+
const onChainInfoLocalGroup = [_TRANSFER_CHAIN_GROUP.centrifuge, ..._TRANSFER_CHAIN_GROUP.bitcountry, ..._TRANSFER_CHAIN_GROUP.acala, ..._TRANSFER_CHAIN_GROUP.kintsugi, 'pendulum', 'amplitude'];
|
|
70
|
+
const onChainInfoNativeGroup = [_TRANSFER_CHAIN_GROUP.centrifuge, ..._TRANSFER_CHAIN_GROUP.acala, ..._TRANSFER_CHAIN_GROUP.kintsugi];
|
|
71
|
+
const assetIdLocalGroup = [..._TRANSFER_CHAIN_GROUP.statemine, ..._TRANSFER_CHAIN_GROUP.genshiro, ...moonbeamGroup, 'hydradx'];
|
|
72
|
+
const assetIdNativeGroup = [..._TRANSFER_CHAIN_GROUP.sora_substrate, 'hydradx'];
|
|
73
|
+
const chain = chainAsset.originChain;
|
|
74
|
+
const isLocal = chainAsset.assetType === 'LOCAL';
|
|
75
|
+
const isNative = chainAsset.assetType === 'NATIVE';
|
|
76
|
+
if (isLocal && onChainInfoLocalGroup.includes(chain)) {
|
|
77
|
+
return !!chainAsset.metadata.onChainInfo;
|
|
78
|
+
}
|
|
79
|
+
if (isNative && onChainInfoNativeGroup.includes(chain)) {
|
|
80
|
+
return !!chainAsset.metadata.onChainInfo;
|
|
81
|
+
}
|
|
82
|
+
if (isLocal && assetIdLocalGroup.includes(chain)) {
|
|
83
|
+
return !!chainAsset.metadata.assetId;
|
|
84
|
+
}
|
|
85
|
+
if (isNative && assetIdNativeGroup.includes(chain)) {
|
|
86
|
+
return !!chainAsset.metadata.assetId;
|
|
87
|
+
}
|
|
88
|
+
throw new Error(`${chainAsset.slug} is not local or native asset`);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// TRANSFER
|
|
92
|
+
|
|
93
|
+
// SWAP
|
|
94
|
+
|
|
95
|
+
export function validateSwapAlterAsset(assetRef) {
|
|
96
|
+
var _assetRef$metadata;
|
|
97
|
+
if (assetRef.path !== 'SWAP') {
|
|
98
|
+
throw new Error(`${assetRef.srcAsset}___${assetRef.destAsset} is not SWAP`);
|
|
99
|
+
}
|
|
100
|
+
const srcAsset = assetRef.srcAsset;
|
|
101
|
+
const alterAsset = (_assetRef$metadata = assetRef.metadata) === null || _assetRef$metadata === void 0 ? void 0 : _assetRef$metadata.alternativeAsset;
|
|
102
|
+
if (!alterAsset) {
|
|
103
|
+
throw new Error(`${assetRef.srcAsset}___${assetRef.destAsset} does not has alternativeAsset`);
|
|
104
|
+
}
|
|
105
|
+
if (!ChainAssetMap[srcAsset] || !ChainAssetMap[alterAsset]) {
|
|
106
|
+
throw new Error(`${srcAsset} or ${alterAsset} do not exist`);
|
|
107
|
+
}
|
|
108
|
+
return ChainAssetMap[srcAsset].multiChainAsset === ChainAssetMap[alterAsset].multiChainAsset;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// SWAP
|
|
112
|
+
|
|
113
|
+
// XCM
|
|
114
|
+
|
|
115
|
+
export function validateXcmMetadata(assetRef) {
|
|
116
|
+
var _ChainAssetMap$srcAss, _ChainAssetMap$destAs;
|
|
117
|
+
if (assetRef.path !== 'XCM') {
|
|
118
|
+
throw new Error(`${assetRef.srcAsset}___${assetRef.destAsset} is not XCM`);
|
|
119
|
+
}
|
|
120
|
+
const srcAsset = assetRef.srcAsset;
|
|
121
|
+
const destAsset = assetRef.destAsset;
|
|
122
|
+
if (!ChainAssetMap[srcAsset] || !ChainAssetMap[destAsset]) {
|
|
123
|
+
throw new Error(`${srcAsset} or ${destAsset} do not exist`);
|
|
124
|
+
}
|
|
125
|
+
return ((_ChainAssetMap$srcAss = ChainAssetMap[srcAsset].metadata) === null || _ChainAssetMap$srcAss === void 0 ? void 0 : _ChainAssetMap$srcAss.multilocation) && ((_ChainAssetMap$destAs = ChainAssetMap[destAsset].metadata) === null || _ChainAssetMap$destAs === void 0 ? void 0 : _ChainAssetMap$destAs.multilocation) || false;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// XCM
|
|
129
|
+
|
|
130
|
+
// EARNING
|
|
131
|
+
|
|
132
|
+
// @ts-ignore
|
|
133
|
+
export function checkValidSupportStaking(chainInfo) {
|
|
134
|
+
if (!chainInfo.substrateInfo) {
|
|
135
|
+
throw new Error(`chain ${chainInfo.slug} is not substrate chain`);
|
|
136
|
+
}
|
|
137
|
+
if (!chainInfo.substrateInfo.supportStaking) {
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// todo: check has related pallet staking
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// todo: check alternativeAsset
|
|
145
|
+
|
|
146
|
+
// EARNING
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { _AssetType } from '@subwallet/chain-list/types';
|
|
5
|
+
export function validateAssetSlug(chainAsset) {
|
|
6
|
+
const slug = chainAsset.slug;
|
|
7
|
+
const originChain = chainAsset.originChain;
|
|
8
|
+
const assetType = chainAsset.assetType;
|
|
9
|
+
const symbol = chainAsset.symbol;
|
|
10
|
+
if ([_AssetType.LOCAL, _AssetType.NATIVE, _AssetType.BRC20].includes(assetType)) {
|
|
11
|
+
return slug === `${originChain}-${assetType}-${symbol}`;
|
|
12
|
+
}
|
|
13
|
+
if ([_AssetType.RUNE].includes(assetType)) {
|
|
14
|
+
var _chainAsset$metadata;
|
|
15
|
+
const runeId = (_chainAsset$metadata = chainAsset.metadata) === null || _chainAsset$metadata === void 0 ? void 0 : _chainAsset$metadata.runeId;
|
|
16
|
+
if (!runeId) {
|
|
17
|
+
throw new Error(`${slug} is ${assetType} but lack of runeId metadata`);
|
|
18
|
+
}
|
|
19
|
+
return slug === `${originChain}-${assetType}-${symbol}-${runeId}`;
|
|
20
|
+
}
|
|
21
|
+
if ([_AssetType.ERC20, _AssetType.ERC721, _AssetType.PSP22, _AssetType.PSP34, _AssetType.GRC20, _AssetType.GRC721].includes(assetType)) {
|
|
22
|
+
var _chainAsset$metadata2;
|
|
23
|
+
const contractAddress = (_chainAsset$metadata2 = chainAsset.metadata) === null || _chainAsset$metadata2 === void 0 ? void 0 : _chainAsset$metadata2.contractAddress;
|
|
24
|
+
if (!contractAddress) {
|
|
25
|
+
throw new Error(`${slug} is ${assetType} but lack of contractAddress metadata`);
|
|
26
|
+
}
|
|
27
|
+
return slug === `${originChain}-${assetType}-${symbol}-${contractAddress}`;
|
|
28
|
+
}
|
|
29
|
+
throw new Error(`${slug} has unknown token type ${assetType}`);
|
|
30
|
+
}
|
|
31
|
+
export function validateBrigeToken(chainAsset) {
|
|
32
|
+
var _chainAsset$metadata3, _chainAsset$metadata4;
|
|
33
|
+
const isBridged = (_chainAsset$metadata3 = chainAsset.metadata) === null || _chainAsset$metadata3 === void 0 ? void 0 : _chainAsset$metadata3.isBridged;
|
|
34
|
+
if (!isBridged) {
|
|
35
|
+
throw new Error(`${chainAsset.slug} is not bridged token`);
|
|
36
|
+
}
|
|
37
|
+
return !!((_chainAsset$metadata4 = chainAsset.metadata) !== null && _chainAsset$metadata4 !== void 0 && _chainAsset$metadata4.onChainInfo);
|
|
38
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { _ChainAsset } from '@subwallet/chain-list/types';
|
|
2
|
+
export declare function validateTokenHasValueByChain(chainAsset: _ChainAsset): boolean;
|
|
3
|
+
export declare function validateNativeInfoByChain(chainAsset: _ChainAsset): boolean;
|
|
4
|
+
export declare function validateAssetTypeSupportByChain(chainAsset: _ChainAsset): boolean;
|
|
5
|
+
export declare function validateChainDisableEvmTransfer(chainAsset: _ChainAsset): boolean | undefined;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { ChainInfoMap } from '@subwallet/chain-list';
|
|
5
|
+
import { _AssetType } from '@subwallet/chain-list/types';
|
|
6
|
+
export function validateTokenHasValueByChain(chainAsset) {
|
|
7
|
+
const chainInfo = ChainInfoMap[chainAsset.originChain];
|
|
8
|
+
const isTestnet = chainInfo && chainInfo.isTestnet;
|
|
9
|
+
if (!chainInfo) {
|
|
10
|
+
throw new Error(`${chainAsset.originChain} is not existed`);
|
|
11
|
+
}
|
|
12
|
+
return isTestnet !== chainAsset.hasValue; // todo: also check multichainAsset hasValue if has.
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function validateNativeInfoByChain(chainAsset) {
|
|
16
|
+
var _chainInfo$evmInfo, _chainInfo$substrateI, _chainInfo$bitcoinInf, _chainInfo$evmInfo2, _chainInfo$substrateI2, _chainInfo$bitcoinInf2, _chainInfo$evmInfo3, _chainInfo$substrateI3, _chainInfo$bitcoinInf3;
|
|
17
|
+
const chainInfo = ChainInfoMap[chainAsset.originChain];
|
|
18
|
+
if (!chainInfo) {
|
|
19
|
+
throw new Error(`${chainAsset.originChain} is not existed`);
|
|
20
|
+
}
|
|
21
|
+
const nativeSymbol = chainInfo !== null && chainInfo !== void 0 && chainInfo.evmInfo ? chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$evmInfo = chainInfo.evmInfo) === null || _chainInfo$evmInfo === void 0 ? void 0 : _chainInfo$evmInfo.symbol : chainInfo !== null && chainInfo !== void 0 && chainInfo.substrateInfo ? chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$substrateI = chainInfo.substrateInfo) === null || _chainInfo$substrateI === void 0 ? void 0 : _chainInfo$substrateI.symbol : chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$bitcoinInf = chainInfo.bitcoinInfo) === null || _chainInfo$bitcoinInf === void 0 ? void 0 : _chainInfo$bitcoinInf.symbol;
|
|
22
|
+
const nativeDecimal = chainInfo !== null && chainInfo !== void 0 && chainInfo.evmInfo ? chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$evmInfo2 = chainInfo.evmInfo) === null || _chainInfo$evmInfo2 === void 0 ? void 0 : _chainInfo$evmInfo2.decimals : chainInfo !== null && chainInfo !== void 0 && chainInfo.substrateInfo ? chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$substrateI2 = chainInfo.substrateInfo) === null || _chainInfo$substrateI2 === void 0 ? void 0 : _chainInfo$substrateI2.decimals : chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$bitcoinInf2 = chainInfo.bitcoinInfo) === null || _chainInfo$bitcoinInf2 === void 0 ? void 0 : _chainInfo$bitcoinInf2.decimals;
|
|
23
|
+
const nativeED = chainInfo !== null && chainInfo !== void 0 && chainInfo.evmInfo ? chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$evmInfo3 = chainInfo.evmInfo) === null || _chainInfo$evmInfo3 === void 0 ? void 0 : _chainInfo$evmInfo3.existentialDeposit : chainInfo !== null && chainInfo !== void 0 && chainInfo.substrateInfo ? chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$substrateI3 = chainInfo.substrateInfo) === null || _chainInfo$substrateI3 === void 0 ? void 0 : _chainInfo$substrateI3.existentialDeposit : chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$bitcoinInf3 = chainInfo.bitcoinInfo) === null || _chainInfo$bitcoinInf3 === void 0 ? void 0 : _chainInfo$bitcoinInf3.existentialDeposit;
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
25
|
+
const nativeTokenSlug = `${chainInfo.slug}-NATIVE-${nativeSymbol}`;
|
|
26
|
+
return nativeSymbol === chainAsset.symbol && nativeDecimal === chainAsset.decimals && nativeED === chainAsset.minAmount && nativeTokenSlug === chainAsset.slug;
|
|
27
|
+
}
|
|
28
|
+
export function validateAssetTypeSupportByChain(chainAsset) {
|
|
29
|
+
const chainInfo = ChainInfoMap[chainAsset.originChain];
|
|
30
|
+
if (!chainInfo) {
|
|
31
|
+
throw new Error(`${chainAsset.originChain} is not existed`);
|
|
32
|
+
}
|
|
33
|
+
const bitcoinSupportAssetTypes = [_AssetType.NATIVE, _AssetType.RUNE, _AssetType.BRC20];
|
|
34
|
+
const evmSupportAssetTypes = [_AssetType.NATIVE, _AssetType.ERC20, _AssetType.ERC721];
|
|
35
|
+
const substrateSupportAssetTypes = [_AssetType.NATIVE, _AssetType.LOCAL, _AssetType.PSP22, _AssetType.PSP34, _AssetType.GRC20, _AssetType.GRC721];
|
|
36
|
+
|
|
37
|
+
// recheck chain with two types.
|
|
38
|
+
if (chainInfo.substrateInfo) {
|
|
39
|
+
return substrateSupportAssetTypes.includes(chainAsset.assetType);
|
|
40
|
+
}
|
|
41
|
+
if (chainInfo.evmInfo) {
|
|
42
|
+
return evmSupportAssetTypes.includes(chainAsset.assetType);
|
|
43
|
+
}
|
|
44
|
+
if (chainInfo.bitcoinInfo) {
|
|
45
|
+
return bitcoinSupportAssetTypes.includes(chainAsset.assetType);
|
|
46
|
+
}
|
|
47
|
+
throw new Error(`${chainAsset.originChain} does not has a suitable chainInfo`);
|
|
48
|
+
}
|
|
49
|
+
export function validateChainDisableEvmTransfer(chainAsset) {
|
|
50
|
+
var _chainInfo$evmInfo4;
|
|
51
|
+
const chainInfo = ChainInfoMap[chainAsset.originChain];
|
|
52
|
+
if (!chainInfo) {
|
|
53
|
+
throw new Error(`${chainAsset.originChain} is not existed`);
|
|
54
|
+
}
|
|
55
|
+
if (!chainInfo.evmInfo) {
|
|
56
|
+
throw new Error(`${chainAsset.originChain} is not Evm chain`);
|
|
57
|
+
}
|
|
58
|
+
const isChainMatchCondition = ((_chainInfo$evmInfo4 = chainInfo.evmInfo) === null || _chainInfo$evmInfo4 === void 0 ? void 0 : _chainInfo$evmInfo4.evmChainId) === -1 && chainInfo.substrateInfo;
|
|
59
|
+
if (isChainMatchCondition) {
|
|
60
|
+
var _chainAsset$metadata;
|
|
61
|
+
return (_chainAsset$metadata = chainAsset.metadata) === null || _chainAsset$metadata === void 0 ? void 0 : _chainAsset$metadata.disableEvmTransfer;
|
|
62
|
+
}
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
|
+
export declare function validateChainHasProvider(chainInfo: _ChainInfo): boolean;
|
|
3
|
+
export declare function validateParaId(chainInfo: _ChainInfo): boolean;
|
|
4
|
+
export declare function checkEvmSupportSmartContract(chainInfo: _ChainInfo): boolean;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { _ChainStatus, _SubstrateChainType } from '@subwallet/chain-list/types';
|
|
5
|
+
export function validateChainHasProvider(chainInfo) {
|
|
6
|
+
const chainStatus = chainInfo.chainStatus;
|
|
7
|
+
const providers = Object.keys(chainInfo.providers);
|
|
8
|
+
const validChainLive = chainStatus === _ChainStatus.ACTIVE && providers.length > 0;
|
|
9
|
+
const chainNotLive = chainStatus !== _ChainStatus.ACTIVE;
|
|
10
|
+
return validChainLive || chainNotLive;
|
|
11
|
+
}
|
|
12
|
+
export function validateParaId(chainInfo) {
|
|
13
|
+
if (!chainInfo.substrateInfo) {
|
|
14
|
+
throw new Error('Not substrate chain');
|
|
15
|
+
}
|
|
16
|
+
const paraId = chainInfo.substrateInfo.paraId;
|
|
17
|
+
const chainType = chainInfo.substrateInfo.chainType;
|
|
18
|
+
const relaySlug = chainInfo.substrateInfo.relaySlug;
|
|
19
|
+
return paraId ? chainType === _SubstrateChainType.PARACHAIN && !!relaySlug : chainType === _SubstrateChainType.RELAYCHAIN && !relaySlug;
|
|
20
|
+
}
|
|
21
|
+
export function checkEvmSupportSmartContract(chainInfo) {
|
|
22
|
+
if (!chainInfo.evmInfo) {
|
|
23
|
+
throw new Error('Not Evm chain');
|
|
24
|
+
}
|
|
25
|
+
return !!chainInfo.evmInfo.supportSmartContract;
|
|
26
|
+
}
|
|
@@ -18,7 +18,7 @@ import { logger as createLogger } from '@polkadot/util/logger';
|
|
|
18
18
|
const filterChainInfoMap = (data, ignoredChains) => {
|
|
19
19
|
return Object.fromEntries(Object.entries(data).filter(([slug, info]) => !info.bitcoinInfo && !ignoredChains.includes(slug)));
|
|
20
20
|
};
|
|
21
|
-
const ignoredList = ['bevm', 'bevmTest', 'bevm_testnet', 'layerEdge_testnet', 'merlinEvm', 'botanixEvmTest', 'syscoin_evm', 'rollux_evm'];
|
|
21
|
+
const ignoredList = ['bevm', 'bevmTest', 'bevm_testnet', 'layerEdge_testnet', 'merlinEvm', 'botanixEvmTest', 'syscoin_evm', 'syscoin_evm_testnet', 'rollux_evm', 'rollux_testnet', 'boolAlpha', 'boolBeta_testnet'];
|
|
22
22
|
const filterAssetInfoMap = (chainInfo, assets) => {
|
|
23
23
|
return Object.fromEntries(Object.entries(assets).filter(([, info]) => chainInfo[info.originChain]));
|
|
24
24
|
};
|
|
@@ -655,6 +655,34 @@ export class ChainService {
|
|
|
655
655
|
}
|
|
656
656
|
const onUpdateStatus = status => {
|
|
657
657
|
const slug = chainInfo.slug;
|
|
658
|
+
const isActive = this.getChainStateByKey(slug).active;
|
|
659
|
+
const isConnectProblem = status !== _ChainConnectionStatus.CONNECTING && status !== _ChainConnectionStatus.CONNECTED;
|
|
660
|
+
const isLightRpc = endpoint.startsWith('light');
|
|
661
|
+
if (isActive && isConnectProblem && !isLightRpc) {
|
|
662
|
+
const reportApiUrl = 'https://api-cache.subwallet.app/api/health-check/report-rpc';
|
|
663
|
+
const requestBody = {
|
|
664
|
+
chainSlug: slug,
|
|
665
|
+
chainStatus: status,
|
|
666
|
+
rpcReport: {
|
|
667
|
+
[providerName]: endpoint
|
|
668
|
+
},
|
|
669
|
+
configStatus: {
|
|
670
|
+
countUnstable: 10,
|
|
671
|
+
countDie: 20
|
|
672
|
+
}
|
|
673
|
+
};
|
|
674
|
+
fetch(reportApiUrl, {
|
|
675
|
+
// can get status from this response
|
|
676
|
+
method: 'POST',
|
|
677
|
+
headers: {
|
|
678
|
+
'X-API-KEY': '9b1c94a5e1f3a2d9f8b2a4d6e1f3a2d9',
|
|
679
|
+
'Content-Type': 'application/json'
|
|
680
|
+
},
|
|
681
|
+
body: JSON.stringify(requestBody)
|
|
682
|
+
})
|
|
683
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
684
|
+
.then(() => {}).catch(error => console.error('Error connecting to the report API:', error));
|
|
685
|
+
}
|
|
658
686
|
this.updateChainConnectionStatus(slug, status);
|
|
659
687
|
};
|
|
660
688
|
if (chainInfo.substrateInfo !== null && chainInfo.substrateInfo !== undefined) {
|
|
@@ -664,6 +692,7 @@ export class ChainService {
|
|
|
664
692
|
//
|
|
665
693
|
// this.substrateChainHandler.setSubstrateApi(chainInfo.slug, chainApi);
|
|
666
694
|
// } else {
|
|
695
|
+
|
|
667
696
|
const chainApi = await this.substrateChainHandler.initApi(chainInfo.slug, endpoint, {
|
|
668
697
|
providerName,
|
|
669
698
|
onUpdateStatus
|
|
@@ -18,6 +18,11 @@ export declare enum _ChainConnectionStatus {
|
|
|
18
18
|
UNSTABLE = "UNSTABLE",
|
|
19
19
|
CONNECTING = "CONNECTING"
|
|
20
20
|
}
|
|
21
|
+
export interface ReportRpc {
|
|
22
|
+
runningRpc: Record<string, string>;
|
|
23
|
+
unstableRpc: Record<string, string>;
|
|
24
|
+
dieRpc: Record<string, string>;
|
|
25
|
+
}
|
|
21
26
|
export interface _ChainState {
|
|
22
27
|
slug: string;
|
|
23
28
|
active: boolean;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { ChainType, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
5
|
+
import { _STAKING_ERA_LENGTH_MAP } from '@subwallet/extension-base/services/chain-service/constants';
|
|
5
6
|
import { _getTokenOnChainInfo } from '@subwallet/extension-base/services/chain-service/utils';
|
|
6
7
|
import { fakeAddress } from '@subwallet/extension-base/services/earning-service/constants';
|
|
7
8
|
import { EarningStatus, UnstakingStatus, YieldStepType } from '@subwallet/extension-base/types';
|
|
@@ -9,6 +10,9 @@ import { BN, BN_TEN, BN_ZERO } from '@polkadot/util';
|
|
|
9
10
|
import BaseLiquidStakingPoolHandler from "./base.js";
|
|
10
11
|
const GRAPHQL_API = 'https://api.polkawallet.io/acala-liquid-staking-subql';
|
|
11
12
|
const EXCHANGE_RATE_REQUEST = 'query { dailySummaries(first:30, orderBy:TIMESTAMP_DESC) {nodes { exchangeRate timestamp }}}';
|
|
13
|
+
function convertDerivativeToken(amount, exchangeRate, decimals) {
|
|
14
|
+
return amount.mul(new BN(exchangeRate)).div(BN_TEN.pow(new BN(decimals)));
|
|
15
|
+
}
|
|
12
16
|
export default class AcalaLiquidStakingPoolHandler extends BaseLiquidStakingPoolHandler {
|
|
13
17
|
altInputAsset = 'polkadot-NATIVE-DOT';
|
|
14
18
|
derivativeAssets = ['acala-LOCAL-LDOT'];
|
|
@@ -22,8 +26,7 @@ export default class AcalaLiquidStakingPoolHandler extends BaseLiquidStakingPool
|
|
|
22
26
|
defaultUnstake: true,
|
|
23
27
|
fastUnstake: true,
|
|
24
28
|
cancelUnstake: false,
|
|
25
|
-
withdraw:
|
|
26
|
-
// TODO: Change after verify unstake info
|
|
29
|
+
withdraw: true,
|
|
27
30
|
claimReward: false
|
|
28
31
|
};
|
|
29
32
|
constructor(state, chain) {
|
|
@@ -111,30 +114,55 @@ export default class AcalaLiquidStakingPoolHandler extends BaseLiquidStakingPool
|
|
|
111
114
|
return;
|
|
112
115
|
}
|
|
113
116
|
const balances = _balances;
|
|
114
|
-
const redeemRequests = await substrateApi.api.query.homa.redeemRequests.multi(useAddresses);
|
|
115
|
-
|
|
116
|
-
const exchangeRate = await this.getExchangeRate();
|
|
117
|
-
const decimals = BN_TEN.pow(new BN(this.rateDecimals));
|
|
117
|
+
const [redeemRequests, exchangeRate, _currentEra] = await Promise.all([substrateApi.api.query.homa.redeemRequests.multi(useAddresses), this.getExchangeRate(), substrateApi.api.query.homa.relayChainCurrentEra()]);
|
|
118
|
+
const currentEra = _currentEra.toPrimitive();
|
|
118
119
|
for (let i = 0; i < balances.length; i++) {
|
|
119
120
|
const balanceItem = balances[i];
|
|
120
121
|
const address = useAddresses[i];
|
|
121
122
|
const activeTotalBalance = balanceItem.free || BN_ZERO;
|
|
122
|
-
let totalBalance = activeTotalBalance
|
|
123
|
+
let totalBalance = convertDerivativeToken(activeTotalBalance, exchangeRate, this.rateDecimals);
|
|
123
124
|
let unlockingBalance = BN_ZERO;
|
|
124
125
|
const unstakings = [];
|
|
126
|
+
|
|
127
|
+
// Handle redeem request
|
|
125
128
|
const redeemRequest = redeemRequests[i].toPrimitive();
|
|
126
129
|
if (redeemRequest) {
|
|
127
|
-
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
const amount = new BN(redeemAmount).mul(new BN(exchangeRate)).div(decimals);
|
|
132
|
-
totalBalance = totalBalance.add(amount);
|
|
133
|
-
unlockingBalance = unlockingBalance.add(amount);
|
|
130
|
+
const [derivativeRedeemAmount, _] = redeemRequest;
|
|
131
|
+
const redeemAmount = convertDerivativeToken(new BN(derivativeRedeemAmount), exchangeRate, this.rateDecimals);
|
|
132
|
+
totalBalance = totalBalance.add(redeemAmount);
|
|
133
|
+
unlockingBalance = unlockingBalance.add(redeemAmount);
|
|
134
134
|
unstakings.push({
|
|
135
135
|
chain: this.chain,
|
|
136
|
-
status:
|
|
137
|
-
claimable:
|
|
136
|
+
status: UnstakingStatus.UNLOCKING,
|
|
137
|
+
claimable: redeemAmount.toString(),
|
|
138
|
+
waitingTime: 28 * _STAKING_ERA_LENGTH_MAP.polkadot // up to 29 day (in case non-fast-match
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Handle unbondings
|
|
143
|
+
const unbondings = await substrateApi.api.query.homa.unbondings.entries(address);
|
|
144
|
+
if (unbondings.length > 0) {
|
|
145
|
+
unbondings.forEach(([unbondingInfo, unbondingValue]) => {
|
|
146
|
+
// @ts-ignore
|
|
147
|
+
const _targetEra = unbondingInfo.toHuman()[1];
|
|
148
|
+
const targetEra = parseInt(_targetEra.replaceAll(',', ''));
|
|
149
|
+
const amount = new BN(unbondingValue.toPrimitive());
|
|
150
|
+
totalBalance = totalBalance.add(amount);
|
|
151
|
+
unlockingBalance = unlockingBalance.add(amount);
|
|
152
|
+
if (targetEra > currentEra) {
|
|
153
|
+
unstakings.push({
|
|
154
|
+
chain: this.chain,
|
|
155
|
+
status: UnstakingStatus.UNLOCKING,
|
|
156
|
+
claimable: amount.toString(),
|
|
157
|
+
waitingTime: (targetEra - currentEra) * _STAKING_ERA_LENGTH_MAP.polkadot // Todo: Handle exact timestamp?
|
|
158
|
+
});
|
|
159
|
+
} else {
|
|
160
|
+
unstakings.push({
|
|
161
|
+
chain: this.chain,
|
|
162
|
+
status: UnstakingStatus.CLAIMABLE,
|
|
163
|
+
claimable: amount.toString()
|
|
164
|
+
});
|
|
165
|
+
}
|
|
138
166
|
});
|
|
139
167
|
}
|
|
140
168
|
const result = {
|
|
@@ -225,7 +253,8 @@ export default class AcalaLiquidStakingPoolHandler extends BaseLiquidStakingPool
|
|
|
225
253
|
}
|
|
226
254
|
async handleYieldUnstake(amount, address, selectedTarget) {
|
|
227
255
|
const chainApi = await this.substrateApi.isReady;
|
|
228
|
-
const extrinsic = chainApi.api.tx.homa.requestRedeem(amount,
|
|
256
|
+
const extrinsic = chainApi.api.tx.homa.requestRedeem(amount, true); // set true to allow fast match
|
|
257
|
+
|
|
229
258
|
return [ExtrinsicType.UNSTAKE_LDOT, extrinsic];
|
|
230
259
|
}
|
|
231
260
|
async handleYieldWithdraw(address, unstakingInfo) {
|