@subwallet/extension-base 1.3.22-0 → 1.3.24-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 +77 -4
- package/background/KoniTypes.js +2 -0
- package/cjs/background/KoniTypes.js +2 -0
- package/cjs/constants/environment.js +4 -2
- package/cjs/constants/index.js +21 -4
- package/cjs/constants/signing.js +6 -2
- package/cjs/core/logic-validation/recipientAddress.js +9 -1
- package/cjs/core/logic-validation/transfer.js +57 -36
- package/cjs/core/types.js +1 -0
- package/cjs/core/utils.js +12 -1
- package/cjs/defaults.js +1 -1
- package/cjs/koni/api/dotsama/crowdloan.js +1 -1
- package/cjs/koni/api/nft/index.js +9 -16
- package/cjs/koni/api/staking/index.js +3 -4
- package/cjs/koni/background/handlers/Extension.js +343 -185
- package/cjs/koni/background/handlers/State.js +17 -2
- package/cjs/koni/background/handlers/Tabs.js +1 -1
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/subscribe/cardano/consts.js +11 -0
- package/cjs/services/balance-service/helpers/subscribe/cardano/index.js +63 -0
- package/cjs/services/balance-service/helpers/subscribe/cardano/types.js +1 -0
- package/cjs/services/balance-service/helpers/subscribe/cardano/utils.js +74 -0
- package/cjs/services/balance-service/helpers/subscribe/index.js +21 -7
- package/cjs/services/balance-service/helpers/subscribe/ton/utils.js +2 -2
- package/cjs/services/balance-service/index.js +4 -2
- package/cjs/services/balance-service/transfer/cardano-transfer.js +122 -0
- package/cjs/services/balance-service/transfer/smart-contract.js +24 -3
- package/cjs/services/balance-service/transfer/token.js +4 -4
- package/cjs/services/chain-service/handler/CardanoApi.js +176 -0
- package/cjs/services/chain-service/handler/CardanoChainHandler.js +83 -0
- package/cjs/services/chain-service/handler/TonApi.js +2 -5
- package/cjs/services/chain-service/index.js +40 -7
- package/cjs/services/chain-service/utils/index.js +40 -11
- package/cjs/services/chain-service/utils/patch.js +1 -1
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost-manta.js +1 -1
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +1 -1
- package/cjs/services/earning-service/service.js +6 -12
- package/cjs/services/fee-service/service.js +19 -8
- package/cjs/services/fee-service/utils/tokenPayFee.js +151 -0
- package/cjs/services/history-service/index.js +4 -6
- package/cjs/services/inapp-notification-service/index.js +12 -4
- package/cjs/services/keyring-service/context/account-context.js +17 -2
- package/cjs/services/keyring-service/context/handlers/Derive.js +10 -7
- package/cjs/services/keyring-service/context/handlers/Migration.js +268 -0
- package/cjs/services/keyring-service/context/handlers/Mnemonic.js +2 -2
- package/cjs/services/keyring-service/context/handlers/Secret.js +1 -1
- package/cjs/services/keyring-service/utils.js +18 -0
- package/cjs/services/request-service/handler/CardanoRequestHandler.js +172 -0
- package/cjs/services/request-service/handler/EvmRequestHandler.js +1 -1
- package/cjs/services/request-service/handler/MetadataRequestHandler.js +5 -13
- package/cjs/services/request-service/index.js +22 -4
- package/cjs/services/setting-service/constants.js +10 -1
- package/cjs/services/storage-service/DatabaseService.js +3 -0
- package/cjs/services/storage-service/db-stores/InappNotification.js +6 -0
- package/cjs/services/swap-service/handler/asset-hub/handler.js +0 -59
- package/cjs/services/swap-service/handler/chainflip-handler.js +33 -281
- package/cjs/services/swap-service/handler/hydradx-handler.js +23 -190
- package/cjs/services/swap-service/handler/simpleswap-handler.js +1 -222
- package/cjs/services/swap-service/handler/uniswap-handler.js +331 -0
- package/cjs/services/swap-service/index.js +31 -22
- package/cjs/services/swap-service/utils.js +21 -38
- package/cjs/services/transaction-service/helpers/index.js +6 -1
- package/cjs/services/transaction-service/index.js +286 -26
- package/cjs/services/transaction-service/utils.js +5 -1
- package/cjs/types/account/info/keyring.js +12 -1
- package/cjs/types/fee/cardano.js +1 -0
- package/cjs/types/swap/index.js +7 -2
- package/cjs/utils/account/analyze.js +2 -1
- package/cjs/utils/account/common.js +29 -20
- package/cjs/utils/account/derive/info/solo.js +9 -4
- package/cjs/utils/account/derive/validate.js +36 -2
- package/cjs/utils/account/transform.js +38 -13
- package/cjs/utils/fee/transfer.js +87 -21
- package/cjs/utils/index.js +2 -2
- package/cjs/utils/staticData/index.js +7 -2
- package/constants/environment.d.ts +1 -0
- package/constants/environment.js +2 -1
- package/constants/index.d.ts +6 -1
- package/constants/index.js +14 -1
- package/constants/signing.js +6 -2
- package/core/logic-validation/recipientAddress.js +11 -3
- package/core/logic-validation/transfer.d.ts +1 -1
- package/core/logic-validation/transfer.js +33 -12
- package/core/substrate/xcm-parser.d.ts +1 -1
- package/core/types.d.ts +1 -0
- package/core/types.js +1 -0
- package/core/utils.d.ts +1 -0
- package/core/utils.js +13 -3
- package/defaults.d.ts +1 -1
- package/defaults.js +1 -1
- package/koni/api/dotsama/crowdloan.js +3 -3
- package/koni/api/nft/index.js +10 -16
- package/koni/api/nft/story_odyssey_nft/index.d.ts +1 -1
- package/koni/api/staking/index.js +4 -5
- package/koni/background/handlers/Extension.d.ts +9 -0
- package/koni/background/handlers/Extension.js +225 -69
- package/koni/background/handlers/State.d.ts +6 -2
- package/koni/background/handlers/State.js +18 -3
- package/koni/background/handlers/Tabs.js +1 -1
- package/package.json +76 -9
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/subscribe/cardano/consts.d.ts +1 -0
- package/services/balance-service/helpers/subscribe/cardano/consts.js +4 -0
- package/services/balance-service/helpers/subscribe/cardano/index.d.ts +2 -0
- package/services/balance-service/helpers/subscribe/cardano/index.js +57 -0
- package/services/balance-service/helpers/subscribe/cardano/types.d.ts +34 -0
- package/services/balance-service/helpers/subscribe/cardano/types.js +1 -0
- package/services/balance-service/helpers/subscribe/cardano/utils.d.ts +15 -0
- package/services/balance-service/helpers/subscribe/cardano/utils.js +62 -0
- package/services/balance-service/helpers/subscribe/index.d.ts +2 -2
- package/services/balance-service/helpers/subscribe/index.js +23 -9
- package/services/balance-service/helpers/subscribe/ton/utils.d.ts +1 -1
- package/services/balance-service/helpers/subscribe/ton/utils.js +1 -1
- package/services/balance-service/index.js +4 -2
- package/services/balance-service/transfer/cardano-transfer.d.ts +24 -0
- package/services/balance-service/transfer/cardano-transfer.js +114 -0
- package/services/balance-service/transfer/smart-contract.d.ts +4 -2
- package/services/balance-service/transfer/smart-contract.js +24 -3
- package/services/balance-service/transfer/token.d.ts +1 -1
- package/services/balance-service/transfer/token.js +2 -2
- package/services/chain-service/handler/CardanoApi.d.ts +38 -0
- package/services/chain-service/handler/CardanoApi.js +167 -0
- package/services/chain-service/handler/CardanoChainHandler.d.ts +17 -0
- package/services/chain-service/handler/CardanoChainHandler.js +75 -0
- package/services/chain-service/handler/TonApi.js +3 -6
- package/services/chain-service/handler/types.d.ts +1 -0
- package/services/chain-service/index.d.ts +4 -1
- package/services/chain-service/index.js +41 -8
- package/services/chain-service/types.d.ts +9 -1
- package/services/chain-service/utils/index.d.ts +4 -0
- package/services/chain-service/utils/index.js +32 -11
- package/services/chain-service/utils/patch.js +1 -1
- package/services/earning-service/handlers/liquid-staking/bifrost-manta.js +1 -1
- package/services/earning-service/handlers/liquid-staking/bifrost.js +1 -1
- package/services/earning-service/service.js +8 -14
- package/services/fee-service/interfaces.d.ts +25 -0
- package/services/fee-service/service.js +19 -8
- package/services/fee-service/utils/tokenPayFee.d.ts +8 -0
- package/services/fee-service/utils/tokenPayFee.js +141 -0
- package/services/history-service/index.js +6 -8
- package/services/inapp-notification-service/index.d.ts +3 -4
- package/services/inapp-notification-service/index.js +14 -6
- package/services/keyring-service/context/account-context.d.ts +6 -2
- package/services/keyring-service/context/account-context.js +17 -2
- package/services/keyring-service/context/handlers/Derive.d.ts +1 -1
- package/services/keyring-service/context/handlers/Derive.js +10 -8
- package/services/keyring-service/context/handlers/Migration.d.ts +17 -0
- package/services/keyring-service/context/handlers/Migration.js +258 -0
- package/services/keyring-service/context/handlers/Mnemonic.js +2 -2
- package/services/keyring-service/context/handlers/Secret.js +2 -2
- package/services/keyring-service/utils.d.ts +2 -0
- package/services/keyring-service/utils.js +11 -0
- package/services/request-service/handler/CardanoRequestHandler.d.ts +16 -0
- package/services/request-service/handler/CardanoRequestHandler.js +163 -0
- package/services/request-service/handler/EvmRequestHandler.js +1 -1
- package/services/request-service/handler/MetadataRequestHandler.d.ts +1 -1
- package/services/request-service/handler/MetadataRequestHandler.js +5 -13
- package/services/request-service/index.d.ts +7 -4
- package/services/request-service/index.js +21 -7
- package/services/setting-service/constants.d.ts +3 -0
- package/services/setting-service/constants.js +6 -0
- package/services/storage-service/DatabaseService.d.ts +1 -0
- package/services/storage-service/DatabaseService.js +3 -0
- package/services/storage-service/db-stores/InappNotification.d.ts +1 -0
- package/services/storage-service/db-stores/InappNotification.js +6 -0
- package/services/swap-service/handler/asset-hub/handler.d.ts +1 -4
- package/services/swap-service/handler/asset-hub/handler.js +2 -61
- package/services/swap-service/handler/base-handler.d.ts +1 -4
- package/services/swap-service/handler/chainflip-handler.d.ts +2 -9
- package/services/swap-service/handler/chainflip-handler.js +31 -280
- package/services/swap-service/handler/hydradx-handler.d.ts +1 -6
- package/services/swap-service/handler/hydradx-handler.js +13 -180
- package/services/swap-service/handler/simpleswap-handler.d.ts +1 -4
- package/services/swap-service/handler/simpleswap-handler.js +5 -226
- package/services/swap-service/handler/uniswap-handler.d.ts +41 -0
- package/services/swap-service/handler/uniswap-handler.js +323 -0
- package/services/swap-service/index.js +30 -22
- package/services/swap-service/utils.d.ts +1 -5
- package/services/swap-service/utils.js +7 -21
- package/services/transaction-service/helpers/index.d.ts +2 -0
- package/services/transaction-service/helpers/index.js +4 -0
- package/services/transaction-service/index.d.ts +8 -2
- package/services/transaction-service/index.js +273 -17
- package/services/transaction-service/types.d.ts +7 -0
- package/services/transaction-service/utils.js +7 -2
- package/types/account/info/keyring.d.ts +4 -1
- package/types/account/info/keyring.js +9 -0
- package/types/account/info/proxy.d.ts +2 -0
- package/types/balance/index.d.ts +4 -1
- package/types/fee/base.d.ts +1 -1
- package/types/fee/cardano.d.ts +18 -0
- package/types/fee/cardano.js +1 -0
- package/types/fee/option.d.ts +1 -1
- package/types/fee/subscription.d.ts +4 -3
- package/types/swap/index.d.ts +11 -3
- package/types/swap/index.js +7 -2
- package/utils/account/analyze.js +2 -1
- package/utils/account/common.d.ts +11 -6
- package/utils/account/common.js +28 -19
- package/utils/account/derive/info/solo.js +10 -5
- package/utils/account/derive/validate.d.ts +1 -0
- package/utils/account/derive/validate.js +34 -1
- package/utils/account/transform.d.ts +2 -1
- package/utils/account/transform.js +37 -13
- package/utils/fee/transfer.d.ts +3 -2
- package/utils/fee/transfer.js +90 -24
- package/utils/index.js +4 -4
- package/utils/staticData/index.d.ts +4 -1
- package/utils/staticData/index.js +5 -1
- package/utils/staticData/oldChainPrefix.json +1 -0
|
@@ -4,13 +4,14 @@
|
|
|
4
4
|
import { AssetLogoMap, AssetRefMap, ChainAssetMap, ChainInfoMap, ChainLogoMap, MultiChainAssetMap } from '@subwallet/chain-list';
|
|
5
5
|
import { _AssetRefPath, _AssetType, _ChainStatus, _SubstrateChainType } from '@subwallet/chain-list/types';
|
|
6
6
|
import { _DEFAULT_ACTIVE_CHAINS, _ZK_ASSET_PREFIX, LATEST_CHAIN_DATA_FETCHING_INTERVAL } from '@subwallet/extension-base/services/chain-service/constants';
|
|
7
|
+
import { CardanoChainHandler } from '@subwallet/extension-base/services/chain-service/handler/CardanoChainHandler';
|
|
7
8
|
import { EvmChainHandler } from '@subwallet/extension-base/services/chain-service/handler/EvmChainHandler';
|
|
8
9
|
import { MantaPrivateHandler } from '@subwallet/extension-base/services/chain-service/handler/manta/MantaPrivateHandler';
|
|
9
10
|
import { SubstrateChainHandler } from '@subwallet/extension-base/services/chain-service/handler/SubstrateChainHandler';
|
|
10
11
|
import { TonChainHandler } from '@subwallet/extension-base/services/chain-service/handler/TonChainHandler';
|
|
11
12
|
import { _CHAIN_VALIDATION_ERROR } from '@subwallet/extension-base/services/chain-service/handler/types';
|
|
12
13
|
import { _ChainConnectionStatus, _CUSTOM_PREFIX, _NFT_CONTRACT_STANDARDS, _SMART_CONTRACT_STANDARDS } from '@subwallet/extension-base/services/chain-service/types';
|
|
13
|
-
import { _isAssetAutoEnable, _isAssetCanPayTxFee, _isAssetFungibleToken, _isChainEnabled, _isCustomAsset, _isCustomChain, _isCustomProvider, _isEqualContractAddress, _isEqualSmartContractAsset, _isLocalToken, _isMantaZkAsset, _isPureEvmChain, _isPureSubstrateChain, _parseAssetRefKey, randomizeProvider, updateLatestChainInfo } from '@subwallet/extension-base/services/chain-service/utils';
|
|
14
|
+
import { _getAssetOriginChain, _getTokenOnChainAssetId, _isAssetAutoEnable, _isAssetCanPayTxFee, _isAssetFungibleToken, _isChainEnabled, _isCustomAsset, _isCustomChain, _isCustomProvider, _isEqualContractAddress, _isEqualSmartContractAsset, _isLocalToken, _isMantaZkAsset, _isPureEvmChain, _isPureSubstrateChain, _parseAssetRefKey, randomizeProvider, updateLatestChainInfo } from '@subwallet/extension-base/services/chain-service/utils';
|
|
14
15
|
import { MYTHOS_MIGRATION_KEY } from '@subwallet/extension-base/services/migration-service/scripts';
|
|
15
16
|
import AssetSettingStore from '@subwallet/extension-base/stores/AssetSetting';
|
|
16
17
|
import { addLazy, calculateMetadataHash, fetchStaticData, filterAssetsByChainAndType, getShortMetadata, MODULE_SUPPORT } from '@subwallet/extension-base/utils';
|
|
@@ -68,6 +69,7 @@ export class ChainService {
|
|
|
68
69
|
this.substrateChainHandler = new SubstrateChainHandler(this);
|
|
69
70
|
this.evmChainHandler = new EvmChainHandler(this);
|
|
70
71
|
this.tonChainHandler = new TonChainHandler(this);
|
|
72
|
+
this.cardanoChainHandler = new CardanoChainHandler(this);
|
|
71
73
|
this.logger = createLogger('chain-service');
|
|
72
74
|
}
|
|
73
75
|
get value() {
|
|
@@ -141,6 +143,12 @@ export class ChainService {
|
|
|
141
143
|
getTonApiMap() {
|
|
142
144
|
return this.tonChainHandler.getTonApiMap();
|
|
143
145
|
}
|
|
146
|
+
getCardanoApi(slug) {
|
|
147
|
+
return this.cardanoChainHandler.getCardanoApiByChain(slug);
|
|
148
|
+
}
|
|
149
|
+
getCardanoApiMap() {
|
|
150
|
+
return this.cardanoChainHandler.getCardanoApiMap();
|
|
151
|
+
}
|
|
144
152
|
getChainCurrentProviderByKey(slug) {
|
|
145
153
|
const providerName = this.getChainStateByKey(slug).currentProvider;
|
|
146
154
|
const providerMap = this.getChainInfoByKey(slug).providers;
|
|
@@ -195,6 +203,17 @@ export class ChainService {
|
|
|
195
203
|
});
|
|
196
204
|
return assetHubToken;
|
|
197
205
|
}
|
|
206
|
+
getHydrationAssetIdMap(chain) {
|
|
207
|
+
const hydrationAssetIdMap = {};
|
|
208
|
+
Object.values(this.getAssetRegistry()).forEach(asset => {
|
|
209
|
+
const originChain = _getAssetOriginChain(asset);
|
|
210
|
+
const assetId = _getTokenOnChainAssetId(asset);
|
|
211
|
+
if (originChain === chain && assetId !== '-1') {
|
|
212
|
+
hydrationAssetIdMap[asset.slug] = assetId;
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
return hydrationAssetIdMap;
|
|
216
|
+
}
|
|
198
217
|
getChainInfoMap() {
|
|
199
218
|
return this.dataMap.chainInfoMap;
|
|
200
219
|
}
|
|
@@ -719,6 +738,15 @@ export class ChainService {
|
|
|
719
738
|
});
|
|
720
739
|
this.tonChainHandler.setTonApi(chainInfo.slug, chainApi);
|
|
721
740
|
}
|
|
741
|
+
if (chainInfo.cardanoInfo !== null && chainInfo.cardanoInfo !== undefined) {
|
|
742
|
+
const isTestnet = chainInfo.isTestnet;
|
|
743
|
+
const chainApi = await this.cardanoChainHandler.initApi(chainInfo.slug, endpoint, {
|
|
744
|
+
isTestnet,
|
|
745
|
+
providerName,
|
|
746
|
+
onUpdateStatus
|
|
747
|
+
});
|
|
748
|
+
this.cardanoChainHandler.setCardanoApi(chainInfo.slug, chainApi);
|
|
749
|
+
}
|
|
722
750
|
}
|
|
723
751
|
destroyApiForChain(chainInfo) {
|
|
724
752
|
if (chainInfo.substrateInfo !== null) {
|
|
@@ -730,6 +758,9 @@ export class ChainService {
|
|
|
730
758
|
if (chainInfo.tonInfo !== null) {
|
|
731
759
|
this.tonChainHandler.destroyTonApi(chainInfo.slug);
|
|
732
760
|
}
|
|
761
|
+
if (chainInfo.cardanoInfo !== null) {
|
|
762
|
+
this.cardanoChainHandler.destroyCardanoApi(chainInfo.slug);
|
|
763
|
+
}
|
|
733
764
|
}
|
|
734
765
|
async enableChain(chainSlug) {
|
|
735
766
|
const chainInfo = this.getChainInfoByKey(chainSlug);
|
|
@@ -1000,7 +1031,7 @@ export class ChainService {
|
|
|
1000
1031
|
deprecatedChainMap[storedSlug] = duplicatedDefaultSlug;
|
|
1001
1032
|
deprecatedChains.push(storedSlug);
|
|
1002
1033
|
} else {
|
|
1003
|
-
var _storedChainInfo$bitc;
|
|
1034
|
+
var _storedChainInfo$bitc, _storedChainInfo$card;
|
|
1004
1035
|
mergedChainInfoMap[storedSlug] = {
|
|
1005
1036
|
slug: storedSlug,
|
|
1006
1037
|
name: storedChainInfo.name,
|
|
@@ -1010,6 +1041,7 @@ export class ChainService {
|
|
|
1010
1041
|
substrateInfo: storedChainInfo.substrateInfo,
|
|
1011
1042
|
bitcoinInfo: (_storedChainInfo$bitc = storedChainInfo.bitcoinInfo) !== null && _storedChainInfo$bitc !== void 0 ? _storedChainInfo$bitc : null,
|
|
1012
1043
|
tonInfo: storedChainInfo.tonInfo,
|
|
1044
|
+
cardanoInfo: (_storedChainInfo$card = storedChainInfo.cardanoInfo) !== null && _storedChainInfo$card !== void 0 ? _storedChainInfo$card : null,
|
|
1013
1045
|
isTestnet: storedChainInfo.isTestnet,
|
|
1014
1046
|
chainStatus: storedChainInfo.chainStatus,
|
|
1015
1047
|
icon: storedChainInfo.icon,
|
|
@@ -1028,7 +1060,7 @@ export class ChainService {
|
|
|
1028
1060
|
this.updateChainConnectionStatus(storedSlug, _ChainConnectionStatus.DISCONNECTED);
|
|
1029
1061
|
}
|
|
1030
1062
|
} else {
|
|
1031
|
-
var _storedChainInfo$bitc2;
|
|
1063
|
+
var _storedChainInfo$bitc2, _storedChainInfo$card2;
|
|
1032
1064
|
// added chain from patch
|
|
1033
1065
|
mergedChainInfoMap[storedSlug] = {
|
|
1034
1066
|
slug: storedSlug,
|
|
@@ -1038,6 +1070,7 @@ export class ChainService {
|
|
|
1038
1070
|
substrateInfo: storedChainInfo.substrateInfo,
|
|
1039
1071
|
bitcoinInfo: (_storedChainInfo$bitc2 = storedChainInfo.bitcoinInfo) !== null && _storedChainInfo$bitc2 !== void 0 ? _storedChainInfo$bitc2 : null,
|
|
1040
1072
|
tonInfo: storedChainInfo.tonInfo,
|
|
1073
|
+
cardanoInfo: (_storedChainInfo$card2 = storedChainInfo.cardanoInfo) !== null && _storedChainInfo$card2 !== void 0 ? _storedChainInfo$card2 : null,
|
|
1041
1074
|
isTestnet: storedChainInfo.isTestnet,
|
|
1042
1075
|
chainStatus: storedChainInfo.chainStatus,
|
|
1043
1076
|
icon: storedChainInfo.icon,
|
|
@@ -1207,6 +1240,7 @@ export class ChainService {
|
|
|
1207
1240
|
let substrateInfo = null;
|
|
1208
1241
|
let evmInfo = null;
|
|
1209
1242
|
const tonInfo = null;
|
|
1243
|
+
const cardanoInfo = null;
|
|
1210
1244
|
if (params.chainSpec.genesisHash !== '') {
|
|
1211
1245
|
substrateInfo = {
|
|
1212
1246
|
crowdloanFunds: params.chainSpec.crowdloanFunds || null,
|
|
@@ -1245,6 +1279,7 @@ export class ChainService {
|
|
|
1245
1279
|
evmInfo,
|
|
1246
1280
|
bitcoinInfo: null,
|
|
1247
1281
|
tonInfo,
|
|
1282
|
+
cardanoInfo,
|
|
1248
1283
|
isTestnet: false,
|
|
1249
1284
|
chainStatus: _ChainStatus.ACTIVE,
|
|
1250
1285
|
icon: '',
|
|
@@ -1356,6 +1391,7 @@ export class ChainService {
|
|
|
1356
1391
|
// TODO: EVM chain might have WS provider
|
|
1357
1392
|
if (provider.startsWith('http')) {
|
|
1358
1393
|
// todo: handle validate ton provider
|
|
1394
|
+
// todo: handle validate cardano provider
|
|
1359
1395
|
|
|
1360
1396
|
// HTTP provider is EVM by default
|
|
1361
1397
|
api = await this.evmChainHandler.initApi('custom', provider);
|
|
@@ -1572,15 +1608,12 @@ export class ChainService {
|
|
|
1572
1608
|
refreshEvmApi(slug) {
|
|
1573
1609
|
this.evmChainHandler.recoverApi(slug).catch(console.error);
|
|
1574
1610
|
}
|
|
1575
|
-
refreshTonApi(slug) {
|
|
1576
|
-
this.tonChainHandler.recoverApi(slug).catch(console.error);
|
|
1577
|
-
}
|
|
1578
1611
|
async stopAllChainApis() {
|
|
1579
|
-
await Promise.all([this.substrateChainHandler.sleep(), this.evmChainHandler.sleep(), this.tonChainHandler.sleep()]);
|
|
1612
|
+
await Promise.all([this.substrateChainHandler.sleep(), this.evmChainHandler.sleep(), this.tonChainHandler.sleep(), this.cardanoChainHandler.sleep()]);
|
|
1580
1613
|
this.stopCheckLatestChainData();
|
|
1581
1614
|
}
|
|
1582
1615
|
async resumeAllChainApis() {
|
|
1583
|
-
await Promise.all([this.substrateChainHandler.wakeUp(), this.evmChainHandler.wakeUp(), this.tonChainHandler.wakeUp()]);
|
|
1616
|
+
await Promise.all([this.substrateChainHandler.wakeUp(), this.evmChainHandler.wakeUp(), this.tonChainHandler.wakeUp(), this.cardanoChainHandler.wakeUp()]);
|
|
1584
1617
|
this.checkLatestData();
|
|
1585
1618
|
}
|
|
1586
1619
|
async initAssetSettings() {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
|
2
2
|
import { _AssetRef, _AssetType, _ChainAsset, _ChainInfo, _CrowdloanFund } from '@subwallet/chain-list/types';
|
|
3
|
+
import { CardanoBalanceItem } from '@subwallet/extension-base/services/balance-service/helpers/subscribe/cardano/types';
|
|
3
4
|
import { AccountState, TxByMsgResponse } from '@subwallet/extension-base/services/balance-service/helpers/subscribe/ton/types';
|
|
4
5
|
import { _CHAIN_VALIDATION_ERROR } from '@subwallet/extension-base/services/chain-service/handler/types';
|
|
5
6
|
import { TonWalletContract } from '@subwallet/keyring/types';
|
|
@@ -107,7 +108,7 @@ export interface _EvmApi extends _ChainBaseApi {
|
|
|
107
108
|
export interface _TonApi extends _ChainBaseApi, _TonUtilsApi {
|
|
108
109
|
isReady: Promise<_TonApi>;
|
|
109
110
|
}
|
|
110
|
-
|
|
111
|
+
interface _TonUtilsApi {
|
|
111
112
|
getBalance(address: Address): Promise<bigint>;
|
|
112
113
|
open<T extends Contract>(src: T): OpenedContract<T>;
|
|
113
114
|
estimateExternalMessageFee(walletContract: TonWalletContract, body: Cell, isInit: boolean, ignoreSignature?: boolean): Promise<EstimateExternalMessageFee>;
|
|
@@ -116,6 +117,12 @@ export interface _TonUtilsApi {
|
|
|
116
117
|
getStatusByExtMsgHash(extMsgHash: string): Promise<[boolean, string]>;
|
|
117
118
|
getAccountState(address: string): Promise<AccountState>;
|
|
118
119
|
}
|
|
120
|
+
export interface _CardanoApi extends _ChainBaseApi, _CardanoUtilsApi {
|
|
121
|
+
isReady: Promise<_CardanoApi>;
|
|
122
|
+
}
|
|
123
|
+
interface _CardanoUtilsApi {
|
|
124
|
+
getBalanceMap(address: string): Promise<CardanoBalanceItem[]>;
|
|
125
|
+
}
|
|
119
126
|
export interface EstimateExternalMessageFee {
|
|
120
127
|
source_fees: {
|
|
121
128
|
in_fwd_fee: number;
|
|
@@ -179,3 +186,4 @@ export interface _ValidateCustomAssetResponse extends _SmartContractTokenInfo {
|
|
|
179
186
|
export declare const _FUNGIBLE_CONTRACT_STANDARDS: _AssetType[];
|
|
180
187
|
export declare const _NFT_CONTRACT_STANDARDS: _AssetType[];
|
|
181
188
|
export declare const _SMART_CONTRACT_STANDARDS: _AssetType[];
|
|
189
|
+
export {};
|
|
@@ -11,6 +11,7 @@ export declare function _isEqualSmartContractAsset(asset1: _ChainAsset, asset2:
|
|
|
11
11
|
export declare function _isPureEvmChain(chainInfo: _ChainInfo): boolean;
|
|
12
12
|
export declare function _isPureSubstrateChain(chainInfo: _ChainInfo): boolean;
|
|
13
13
|
export declare function _isPureTonChain(chainInfo: _ChainInfo): boolean;
|
|
14
|
+
export declare function _isPureCardanoChain(chainInfo: _ChainInfo): boolean;
|
|
14
15
|
export declare function _getOriginChainOfAsset(assetSlug: string): string;
|
|
15
16
|
export declare function _getContractAddressOfToken(tokenInfo: _ChainAsset): string;
|
|
16
17
|
/**
|
|
@@ -30,6 +31,7 @@ export declare function _isTokenTransferredByEvm(tokenInfo: _ChainAsset): boolea
|
|
|
30
31
|
export declare function _checkSmartContractSupportByChain(chainInfo: _ChainInfo, contractType: _AssetType): boolean;
|
|
31
32
|
export declare function _isJettonToken(tokenInfo: _ChainAsset): boolean;
|
|
32
33
|
export declare function _isTokenTransferredByTon(tokenInfo: _ChainAsset): boolean;
|
|
34
|
+
export declare function _isTokenTransferredByCardano(tokenInfo: _ChainAsset): boolean;
|
|
33
35
|
export declare function _getTokenOnChainAssetId(tokenInfo: _ChainAsset): string;
|
|
34
36
|
export declare function _getTokenOnChainInfo(tokenInfo: _ChainAsset): Record<string, any>;
|
|
35
37
|
export declare function _isBridgedToken(tokenInfo: _ChainAsset): boolean;
|
|
@@ -37,6 +39,7 @@ export declare function _getTokenMinAmount(tokenInfo: _ChainAsset): string;
|
|
|
37
39
|
export declare function _isChainEvmCompatible(chainInfo: _ChainInfo): boolean;
|
|
38
40
|
export declare function _isChainBitcoinCompatible(chainInfo: _ChainInfo): boolean;
|
|
39
41
|
export declare function _isChainTonCompatible(chainInfo: _ChainInfo): boolean;
|
|
42
|
+
export declare function _isChainCardanoCompatible(chainInfo: _ChainInfo): boolean;
|
|
40
43
|
export declare function _isNativeToken(tokenInfo: _ChainAsset): boolean;
|
|
41
44
|
export declare function _isNativeTokenBySlug(tokenSlug: string): boolean;
|
|
42
45
|
export declare function _isSmartContractToken(tokenInfo: _ChainAsset): boolean;
|
|
@@ -65,6 +68,7 @@ export declare function _getChainNativeTokenSlug(chainInfo: _ChainInfo): string;
|
|
|
65
68
|
export declare function _isLocalToken(tokenInfo: _ChainAsset): boolean;
|
|
66
69
|
export declare function _isTokenEvmSmartContract(tokenInfo: _ChainAsset): boolean;
|
|
67
70
|
export declare function _isTokenTonSmartContract(tokenInfo: _ChainAsset): boolean;
|
|
71
|
+
export declare function _isCIP26Token(tokenInfo: _ChainAsset): boolean;
|
|
68
72
|
export declare function _isTokenWasmSmartContract(tokenInfo: _ChainAsset): boolean;
|
|
69
73
|
export declare function _isAssetSmartContractNft(assetInfo: _ChainAsset): boolean;
|
|
70
74
|
export declare function _isTokenGearSmartContract(tokenInfo: _ChainAsset): boolean;
|
|
@@ -48,13 +48,16 @@ export function _isEqualSmartContractAsset(asset1, asset2) {
|
|
|
48
48
|
return false;
|
|
49
49
|
}
|
|
50
50
|
export function _isPureEvmChain(chainInfo) {
|
|
51
|
-
return !!chainInfo.evmInfo && !chainInfo.substrateInfo && !chainInfo.tonInfo;
|
|
51
|
+
return !!chainInfo.evmInfo && !chainInfo.substrateInfo && !chainInfo.tonInfo && !chainInfo.cardanoInfo;
|
|
52
52
|
}
|
|
53
53
|
export function _isPureSubstrateChain(chainInfo) {
|
|
54
|
-
return !chainInfo.evmInfo && !!chainInfo.substrateInfo && !chainInfo.tonInfo;
|
|
54
|
+
return !chainInfo.evmInfo && !!chainInfo.substrateInfo && !chainInfo.tonInfo && !chainInfo.cardanoInfo;
|
|
55
55
|
}
|
|
56
56
|
export function _isPureTonChain(chainInfo) {
|
|
57
|
-
return !chainInfo.evmInfo && !chainInfo.substrateInfo && !!chainInfo.tonInfo;
|
|
57
|
+
return !chainInfo.evmInfo && !chainInfo.substrateInfo && !!chainInfo.tonInfo && !chainInfo.cardanoInfo;
|
|
58
|
+
}
|
|
59
|
+
export function _isPureCardanoChain(chainInfo) {
|
|
60
|
+
return !chainInfo.evmInfo && !chainInfo.substrateInfo && !chainInfo.tonInfo && !!chainInfo.cardanoInfo;
|
|
58
61
|
}
|
|
59
62
|
export function _getOriginChainOfAsset(assetSlug) {
|
|
60
63
|
if (assetSlug.startsWith(_CUSTOM_PREFIX)) {
|
|
@@ -107,6 +110,9 @@ export function _isJettonToken(tokenInfo) {
|
|
|
107
110
|
export function _isTokenTransferredByTon(tokenInfo) {
|
|
108
111
|
return _isJettonToken(tokenInfo) || _isNativeToken(tokenInfo);
|
|
109
112
|
}
|
|
113
|
+
export function _isTokenTransferredByCardano(tokenInfo) {
|
|
114
|
+
return _isCIP26Token(tokenInfo) || _isNativeToken(tokenInfo);
|
|
115
|
+
}
|
|
110
116
|
|
|
111
117
|
// Utils for balance functions
|
|
112
118
|
export function _getTokenOnChainAssetId(tokenInfo) {
|
|
@@ -133,6 +139,9 @@ export function _isChainBitcoinCompatible(chainInfo) {
|
|
|
133
139
|
export function _isChainTonCompatible(chainInfo) {
|
|
134
140
|
return !!chainInfo.tonInfo;
|
|
135
141
|
}
|
|
142
|
+
export function _isChainCardanoCompatible(chainInfo) {
|
|
143
|
+
return !!chainInfo.cardanoInfo;
|
|
144
|
+
}
|
|
136
145
|
export function _isNativeToken(tokenInfo) {
|
|
137
146
|
return tokenInfo.assetType === _AssetType.NATIVE;
|
|
138
147
|
}
|
|
@@ -252,11 +261,12 @@ export function _getTokenTypesSupportedByChain(chainInfo) {
|
|
|
252
261
|
return result;
|
|
253
262
|
}
|
|
254
263
|
export function _getChainNativeTokenBasicInfo(chainInfo) {
|
|
264
|
+
const defaultTokenInfo = {
|
|
265
|
+
symbol: '',
|
|
266
|
+
decimals: -1
|
|
267
|
+
};
|
|
255
268
|
if (!chainInfo) {
|
|
256
|
-
return
|
|
257
|
-
symbol: '',
|
|
258
|
-
decimals: -1
|
|
259
|
-
};
|
|
269
|
+
return defaultTokenInfo;
|
|
260
270
|
}
|
|
261
271
|
if (chainInfo.substrateInfo) {
|
|
262
272
|
// substrate by default
|
|
@@ -274,11 +284,13 @@ export function _getChainNativeTokenBasicInfo(chainInfo) {
|
|
|
274
284
|
symbol: chainInfo.tonInfo.symbol,
|
|
275
285
|
decimals: chainInfo.tonInfo.decimals
|
|
276
286
|
};
|
|
287
|
+
} else if (chainInfo.cardanoInfo) {
|
|
288
|
+
return {
|
|
289
|
+
symbol: chainInfo.cardanoInfo.symbol,
|
|
290
|
+
decimals: chainInfo.cardanoInfo.decimals
|
|
291
|
+
};
|
|
277
292
|
}
|
|
278
|
-
return
|
|
279
|
-
symbol: '',
|
|
280
|
-
decimals: -1
|
|
281
|
-
};
|
|
293
|
+
return defaultTokenInfo;
|
|
282
294
|
}
|
|
283
295
|
export function _getChainNativeTokenSlug(chainInfo) {
|
|
284
296
|
if (_isCustomChain(chainInfo.slug)) {
|
|
@@ -296,6 +308,9 @@ export function _isTokenTonSmartContract(tokenInfo) {
|
|
|
296
308
|
return [_AssetType.TEP74].includes(tokenInfo.assetType); // add TEP-62 when supporting
|
|
297
309
|
}
|
|
298
310
|
|
|
311
|
+
export function _isCIP26Token(tokenInfo) {
|
|
312
|
+
return [_AssetType.CIP26].includes(tokenInfo.assetType);
|
|
313
|
+
}
|
|
299
314
|
export function _isTokenWasmSmartContract(tokenInfo) {
|
|
300
315
|
return [_AssetType.PSP22, _AssetType.PSP34].includes(tokenInfo.assetType);
|
|
301
316
|
}
|
|
@@ -384,6 +399,9 @@ export function _getBlockExplorerFromChain(chainInfo) {
|
|
|
384
399
|
if (_isPureEvmChain(chainInfo)) {
|
|
385
400
|
var _chainInfo$evmInfo5;
|
|
386
401
|
blockExplorer = chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$evmInfo5 = chainInfo.evmInfo) === null || _chainInfo$evmInfo5 === void 0 ? void 0 : _chainInfo$evmInfo5.blockExplorer;
|
|
402
|
+
} else if (_isPureCardanoChain(chainInfo)) {
|
|
403
|
+
var _chainInfo$cardanoInf;
|
|
404
|
+
blockExplorer = chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$cardanoInf = chainInfo.cardanoInfo) === null || _chainInfo$cardanoInf === void 0 ? void 0 : _chainInfo$cardanoInf.blockExplorer;
|
|
387
405
|
} else {
|
|
388
406
|
var _chainInfo$substrateI18;
|
|
389
407
|
blockExplorer = chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$substrateI18 = chainInfo.substrateInfo) === null || _chainInfo$substrateI18 === void 0 ? void 0 : _chainInfo$substrateI18.blockExplorer;
|
|
@@ -551,6 +569,9 @@ export const _chainInfoToChainType = chainInfo => {
|
|
|
551
569
|
if (_isChainTonCompatible(chainInfo)) {
|
|
552
570
|
return AccountChainType.TON;
|
|
553
571
|
}
|
|
572
|
+
if (_isChainCardanoCompatible(chainInfo)) {
|
|
573
|
+
return AccountChainType.CARDANO;
|
|
574
|
+
}
|
|
554
575
|
if (_isChainBitcoinCompatible(chainInfo)) {
|
|
555
576
|
return AccountChainType.BITCOIN;
|
|
556
577
|
}
|
|
@@ -5,7 +5,7 @@ const PRODUCTION_BRANCHES = ['master', 'webapp', 'webapp-dev'];
|
|
|
5
5
|
const branchName = process.env.BRANCH_NAME || 'subwallet-dev';
|
|
6
6
|
const fetchDomain = PRODUCTION_BRANCHES.indexOf(branchName) > -1 ? 'https://chain-list-assets.subwallet.app' : 'https://dev.sw-chain-list-assets.pages.dev';
|
|
7
7
|
const fetchFile = PRODUCTION_BRANCHES.indexOf(branchName) > -1 ? 'list.json' : 'preview.json';
|
|
8
|
-
const ChainListVersion = '0.2.
|
|
8
|
+
const ChainListVersion = '0.2.101'; // update this when build chainlist
|
|
9
9
|
|
|
10
10
|
// todo: move this interface to chainlist
|
|
11
11
|
|
|
@@ -124,7 +124,7 @@ export default class BifrostMantaLiquidStakingPoolHandler extends BifrostLiquidS
|
|
|
124
124
|
const chainApi = await this.substrateApi.isReady;
|
|
125
125
|
const derivativeTokenSlug = this.derivativeAssets[0];
|
|
126
126
|
const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
|
|
127
|
-
const extrinsic = chainApi.api.tx.vtokenMinting.redeem(_getTokenOnChainInfo(derivativeTokenInfo), amount);
|
|
127
|
+
const extrinsic = chainApi.api.tx.vtokenMinting.redeem(null, _getTokenOnChainInfo(derivativeTokenInfo), amount);
|
|
128
128
|
return [ExtrinsicType.UNSTAKE_VMANTA, extrinsic];
|
|
129
129
|
}
|
|
130
130
|
|
|
@@ -286,7 +286,7 @@ export default class BifrostLiquidStakingPoolHandler extends BaseLiquidStakingPo
|
|
|
286
286
|
const chainApi = await this.substrateApi.isReady;
|
|
287
287
|
const derivativeTokenSlug = this.derivativeAssets[0];
|
|
288
288
|
const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
|
|
289
|
-
const extrinsic = chainApi.api.tx.vtokenMinting.redeem(_getTokenOnChainInfo(derivativeTokenInfo), amount);
|
|
289
|
+
const extrinsic = chainApi.api.tx.vtokenMinting.redeem(null, _getTokenOnChainInfo(derivativeTokenInfo), amount);
|
|
290
290
|
return [ExtrinsicType.UNSTAKE_VDOT, extrinsic];
|
|
291
291
|
}
|
|
292
292
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
5
|
-
import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
5
|
+
import { ChainType, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
6
6
|
import { CRON_REFRESH_CHAIN_STAKING_METADATA, CRON_REFRESH_EARNING_REWARD_HISTORY_INTERVAL, CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL } from '@subwallet/extension-base/constants';
|
|
7
7
|
import { ServiceStatus } from '@subwallet/extension-base/services/base/types';
|
|
8
8
|
import { _isChainEnabled, _isChainEvmCompatible } from '@subwallet/extension-base/services/chain-service/utils';
|
|
@@ -10,7 +10,7 @@ import { _STAKING_CHAIN_GROUP } from '@subwallet/extension-base/services/earning
|
|
|
10
10
|
import BaseLiquidStakingPoolHandler from '@subwallet/extension-base/services/earning-service/handlers/liquid-staking/base';
|
|
11
11
|
import MythosNativeStakingPoolHandler from '@subwallet/extension-base/services/earning-service/handlers/native-staking/mythos';
|
|
12
12
|
import { BasicTxErrorType, YieldPoolType } from '@subwallet/extension-base/types';
|
|
13
|
-
import { addLazy,
|
|
13
|
+
import { addLazy, createPromiseHandler, getAddressesByChainType, removeLazy } from '@subwallet/extension-base/utils';
|
|
14
14
|
import { fetchStaticCache } from '@subwallet/extension-base/utils/fetchStaticCache';
|
|
15
15
|
import { BehaviorSubject } from 'rxjs';
|
|
16
16
|
import { AcalaLiquidStakingPoolHandler, AmplitudeNativeStakingPoolHandler, AstarNativeStakingPoolHandler, BifrostLiquidStakingPoolHandler, BifrostMantaLiquidStakingPoolHandler, InterlayLendingPoolHandler, NominationPoolHandler, ParallelLiquidStakingPoolHandler, ParaNativeStakingPoolHandler, RelayNativeStakingPoolHandler, StellaSwapLiquidStakingPoolHandler, TaoNativeStakingPoolHandler } from "./handlers/index.js";
|
|
@@ -380,10 +380,8 @@ export default class EarningService {
|
|
|
380
380
|
async subscribePoolPositions(addresses, callback) {
|
|
381
381
|
let cancel = false;
|
|
382
382
|
await this.eventService.waitChainReady;
|
|
383
|
-
const
|
|
384
|
-
|
|
385
|
-
substrate: substrateAddresses
|
|
386
|
-
} = categoryAddresses(addresses);
|
|
383
|
+
const evmAddresses = getAddressesByChainType(addresses, [ChainType.EVM]);
|
|
384
|
+
const substrateAddresses = getAddressesByChainType(addresses, [ChainType.SUBSTRATE]);
|
|
387
385
|
const activeChains = this.state.activeChainSlugs;
|
|
388
386
|
const unsubList = [];
|
|
389
387
|
for (const handler of Object.values(this.handlers)) {
|
|
@@ -526,10 +524,8 @@ export default class EarningService {
|
|
|
526
524
|
async getPoolReward(addresses, callback) {
|
|
527
525
|
let cancel = false;
|
|
528
526
|
await this.eventService.waitChainReady;
|
|
529
|
-
const
|
|
530
|
-
|
|
531
|
-
substrate: substrateAddresses
|
|
532
|
-
} = categoryAddresses(addresses);
|
|
527
|
+
const evmAddresses = getAddressesByChainType(addresses, [ChainType.EVM]);
|
|
528
|
+
const substrateAddresses = getAddressesByChainType(addresses, [ChainType.SUBSTRATE]);
|
|
533
529
|
const activeChains = this.state.activeChainSlugs;
|
|
534
530
|
const unsubList = [];
|
|
535
531
|
for (const handler of Object.values(this.handlers)) {
|
|
@@ -584,10 +580,8 @@ export default class EarningService {
|
|
|
584
580
|
async fetchPoolRewardHistory(addresses, callback) {
|
|
585
581
|
let cancel = false;
|
|
586
582
|
await this.eventService.waitChainReady;
|
|
587
|
-
const
|
|
588
|
-
|
|
589
|
-
substrate: substrateAddresses
|
|
590
|
-
} = categoryAddresses(addresses);
|
|
583
|
+
const evmAddresses = getAddressesByChainType(addresses, [ChainType.EVM]);
|
|
584
|
+
const substrateAddresses = getAddressesByChainType(addresses, [ChainType.SUBSTRATE]);
|
|
591
585
|
const activeChains = this.state.activeChainSlugs;
|
|
592
586
|
const unsubList = [];
|
|
593
587
|
for (const handler of Object.values(this.handlers)) {
|
|
@@ -1,5 +1,30 @@
|
|
|
1
|
+
import { _ChainAsset } from '@subwallet/chain-list/types';
|
|
2
|
+
import { ChainService } from '@subwallet/extension-base/services/chain-service';
|
|
3
|
+
import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
4
|
+
import { BalanceItem } from '@subwallet/extension-base/types';
|
|
1
5
|
export interface TokenHasBalanceInfo {
|
|
2
6
|
slug: string;
|
|
3
7
|
free: string;
|
|
4
8
|
rate: string;
|
|
5
9
|
}
|
|
10
|
+
export interface TokenPayFeeInfo {
|
|
11
|
+
tokensCanPayFee: TokenHasBalanceInfo[];
|
|
12
|
+
defaultTokenSlug: string;
|
|
13
|
+
}
|
|
14
|
+
export interface RequestAssetHubTokensCanPayFee {
|
|
15
|
+
substrateApi: _SubstrateApi;
|
|
16
|
+
chainService: ChainService;
|
|
17
|
+
nativeTokenInfo: _ChainAsset;
|
|
18
|
+
nativeBalanceInfo: TokenHasBalanceInfo;
|
|
19
|
+
tokensHasBalanceInfoMap: Record<string, BalanceItem>;
|
|
20
|
+
feeAmount?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface RequestHydrationTokensCanPayFee {
|
|
23
|
+
substrateApi: _SubstrateApi;
|
|
24
|
+
chainService: ChainService;
|
|
25
|
+
nativeTokenInfo: _ChainAsset;
|
|
26
|
+
nativeBalanceInfo: TokenHasBalanceInfo;
|
|
27
|
+
tokensHasBalanceInfoMap: Record<string, BalanceItem>;
|
|
28
|
+
address: string;
|
|
29
|
+
feeAmount?: string;
|
|
30
|
+
}
|
|
@@ -9,7 +9,8 @@ export default class FeeService {
|
|
|
9
9
|
chainFeeSubscriptionMap = {
|
|
10
10
|
evm: {},
|
|
11
11
|
substrate: {},
|
|
12
|
-
ton: {}
|
|
12
|
+
ton: {},
|
|
13
|
+
cardano: {}
|
|
13
14
|
};
|
|
14
15
|
constructor(state) {
|
|
15
16
|
this.state = state;
|
|
@@ -103,21 +104,31 @@ export default class FeeService {
|
|
|
103
104
|
const api = this.state.getEvmApi(chain);
|
|
104
105
|
|
|
105
106
|
// TODO: Handle case type === evm and not have api
|
|
106
|
-
if (type === 'evm'
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
107
|
+
if (type === 'evm') {
|
|
108
|
+
if (api) {
|
|
109
|
+
calculateGasFeeParams(api, chain).then(info => {
|
|
110
|
+
observer.next(info);
|
|
111
|
+
}).catch(e => {
|
|
112
|
+
console.warn(`Cannot get fee param for ${chain}`, e);
|
|
113
|
+
observer.next({
|
|
114
|
+
type: 'evm',
|
|
115
|
+
gasPrice: '0',
|
|
116
|
+
baseGasFee: undefined,
|
|
117
|
+
options: undefined
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
} else {
|
|
121
|
+
console.warn(`Cannot get fee param for ${chain}`, 'Cannot get api');
|
|
111
122
|
observer.next({
|
|
112
123
|
type: 'evm',
|
|
113
124
|
gasPrice: '0',
|
|
114
125
|
baseGasFee: undefined,
|
|
115
126
|
options: undefined
|
|
116
127
|
});
|
|
117
|
-
}
|
|
128
|
+
}
|
|
118
129
|
} else {
|
|
119
130
|
observer.next({
|
|
120
|
-
type
|
|
131
|
+
type,
|
|
121
132
|
busyNetwork: false,
|
|
122
133
|
options: {
|
|
123
134
|
slow: {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { _ChainAsset } from '@subwallet/chain-list/types';
|
|
2
|
+
import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
3
|
+
import { RequestAssetHubTokensCanPayFee, RequestHydrationTokensCanPayFee, TokenHasBalanceInfo } from '@subwallet/extension-base/services/fee-service/interfaces';
|
|
4
|
+
import { SubmittableExtrinsic } from '@polkadot/api/promise/types';
|
|
5
|
+
export declare function getAssetHubTokensCanPayFee(request: RequestAssetHubTokensCanPayFee): Promise<TokenHasBalanceInfo[]>;
|
|
6
|
+
export declare function getHydrationTokensCanPayFee(request: RequestHydrationTokensCanPayFee): Promise<TokenHasBalanceInfo[]>;
|
|
7
|
+
export declare function batchExtrinsicSetFeeHydration(substrateApi: _SubstrateApi, tx: SubmittableExtrinsic | null, feeSetting: number | null, assetId?: string): SubmittableExtrinsic | null;
|
|
8
|
+
export declare function getHydrationRate(address: string, hdx: _ChainAsset, desToken: _ChainAsset): Promise<string | undefined>;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { _AssetType } from '@subwallet/chain-list/types';
|
|
5
|
+
import { _getAssetDecimals, _getAssetPriceId, _getTokenOnChainAssetId } from '@subwallet/extension-base/services/chain-service/utils';
|
|
6
|
+
import { checkLiquidityForPool, estimateTokensForPool, getReserveForPool } from '@subwallet/extension-base/services/swap-service/handler/asset-hub/utils';
|
|
7
|
+
import subwalletApiSdk from '@subwallet/subwallet-api-sdk';
|
|
8
|
+
import BigN from 'bignumber.js';
|
|
9
|
+
export async function getAssetHubTokensCanPayFee(request) {
|
|
10
|
+
const {
|
|
11
|
+
chainService,
|
|
12
|
+
feeAmount,
|
|
13
|
+
nativeBalanceInfo,
|
|
14
|
+
nativeTokenInfo,
|
|
15
|
+
substrateApi,
|
|
16
|
+
tokensHasBalanceInfoMap
|
|
17
|
+
} = request;
|
|
18
|
+
const tokensList = [nativeBalanceInfo];
|
|
19
|
+
if (!(nativeTokenInfo.metadata && nativeTokenInfo.metadata.multilocation)) {
|
|
20
|
+
return tokensList;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// ensure nativeTokenInfo and localTokenInfo have multi-location metadata beforehand to improve performance.
|
|
24
|
+
const tokensHasBalanceSlug = Object.keys(tokensHasBalanceInfoMap);
|
|
25
|
+
const tokenInfos = tokensHasBalanceSlug.map(tokenSlug => chainService.getAssetBySlug(tokenSlug)).filter(token => token.originChain === substrateApi.chainSlug && token.assetType !== _AssetType.NATIVE && token.metadata && token.metadata.multilocation);
|
|
26
|
+
await Promise.all(tokenInfos.map(async tokenInfo => {
|
|
27
|
+
try {
|
|
28
|
+
const tokenSlug = tokenInfo.slug;
|
|
29
|
+
const reserve = await getReserveForPool(substrateApi.api, nativeTokenInfo, tokenInfo);
|
|
30
|
+
if (!reserve || !reserve[0] || !reserve[1] || reserve[0] === '0' || reserve[1] === '0') {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const rate = new BigN(reserve[1]).div(reserve[0]).toFixed();
|
|
34
|
+
const tokenCanPayFee = {
|
|
35
|
+
slug: tokenSlug,
|
|
36
|
+
free: tokensHasBalanceInfoMap[tokenSlug].free,
|
|
37
|
+
rate
|
|
38
|
+
};
|
|
39
|
+
if (feeAmount === undefined) {
|
|
40
|
+
tokensList.push(tokenCanPayFee);
|
|
41
|
+
} else {
|
|
42
|
+
const amount = estimateTokensForPool(feeAmount, reserve);
|
|
43
|
+
const liquidityError = checkLiquidityForPool(amount, reserve[0], reserve[1]);
|
|
44
|
+
if (!liquidityError) {
|
|
45
|
+
tokensList.push(tokenCanPayFee);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
} catch (e) {
|
|
49
|
+
console.error('error when fetching pool with token', tokenInfo.slug, e);
|
|
50
|
+
}
|
|
51
|
+
}));
|
|
52
|
+
return tokensList;
|
|
53
|
+
}
|
|
54
|
+
export async function getHydrationTokensCanPayFee(request) {
|
|
55
|
+
const {
|
|
56
|
+
address,
|
|
57
|
+
chainService,
|
|
58
|
+
nativeBalanceInfo,
|
|
59
|
+
nativeTokenInfo,
|
|
60
|
+
substrateApi,
|
|
61
|
+
tokensHasBalanceInfoMap
|
|
62
|
+
} = request;
|
|
63
|
+
const tokensList = [nativeBalanceInfo];
|
|
64
|
+
const _acceptedCurrencies = await substrateApi.api.query.multiTransactionPayment.acceptedCurrencies.entries();
|
|
65
|
+
const supportedAssetIds = _acceptedCurrencies.map(_assetId => {
|
|
66
|
+
const assetId = _assetId[0].toHuman();
|
|
67
|
+
return assetId[0].replaceAll(',', '');
|
|
68
|
+
});
|
|
69
|
+
const nativePriceId = _getAssetPriceId(nativeTokenInfo);
|
|
70
|
+
if (!nativePriceId) {
|
|
71
|
+
return tokensList;
|
|
72
|
+
}
|
|
73
|
+
const tokenInfos = Object.keys(tokensHasBalanceInfoMap).map(tokenSlug => chainService.getAssetBySlug(tokenSlug)).filter(token => token.originChain === substrateApi.chainSlug && token.assetType !== _AssetType.NATIVE && !!token.metadata && !!token.metadata.assetId);
|
|
74
|
+
await Promise.all(tokenInfos.map(async tokenInfo => {
|
|
75
|
+
const priceId = _getAssetPriceId(tokenInfo);
|
|
76
|
+
const rate = await getHydrationRate(address, nativeTokenInfo, tokenInfo);
|
|
77
|
+
if (priceId && rate) {
|
|
78
|
+
if (supportedAssetIds.includes(_getTokenOnChainAssetId(tokenInfo))) {
|
|
79
|
+
tokensList.push({
|
|
80
|
+
slug: tokenInfo.slug,
|
|
81
|
+
free: tokensHasBalanceInfoMap[tokenInfo.slug].free,
|
|
82
|
+
rate: rate.toString()
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}));
|
|
87
|
+
return tokensList;
|
|
88
|
+
}
|
|
89
|
+
export function batchExtrinsicSetFeeHydration(substrateApi, tx, feeSetting, assetId) {
|
|
90
|
+
const api = substrateApi.api;
|
|
91
|
+
const isSettingLocalFee = feeSetting && feeSetting !== 0;
|
|
92
|
+
const isAttendToSetLocalFee = assetId && assetId !== '0';
|
|
93
|
+
if (!tx) {
|
|
94
|
+
return tx;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// current native - set native
|
|
98
|
+
if (!isSettingLocalFee && !isAttendToSetLocalFee) {
|
|
99
|
+
return tx;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// current native - set local
|
|
103
|
+
if (!isSettingLocalFee && isAttendToSetLocalFee) {
|
|
104
|
+
return api.tx.utility.batchAll([api.tx.multiTransactionPayment.setCurrency(assetId), tx, api.tx.multiTransactionPayment.setCurrency('0')]);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// current local - set native
|
|
108
|
+
if (isSettingLocalFee && !isAttendToSetLocalFee) {
|
|
109
|
+
return api.tx.utility.batchAll([api.tx.multiTransactionPayment.setCurrency('0'), tx]);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// current local - set local
|
|
113
|
+
if (isSettingLocalFee && isAttendToSetLocalFee) {
|
|
114
|
+
if (assetId === feeSetting.toString()) {
|
|
115
|
+
// current local = set local
|
|
116
|
+
return api.tx.utility.batchAll([tx, api.tx.multiTransactionPayment.setCurrency('0')]);
|
|
117
|
+
} else {
|
|
118
|
+
// current local != set local
|
|
119
|
+
return api.tx.utility.batchAll([api.tx.multiTransactionPayment.setCurrency(assetId), tx, api.tx.multiTransactionPayment.setCurrency('0')]);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return tx;
|
|
123
|
+
}
|
|
124
|
+
export async function getHydrationRate(address, hdx, desToken) {
|
|
125
|
+
var _subwalletApiSdk$swap;
|
|
126
|
+
const quoteRate = await ((_subwalletApiSdk$swap = subwalletApiSdk.swapApi) === null || _subwalletApiSdk$swap === void 0 ? void 0 : _subwalletApiSdk$swap.getHydrationRate({
|
|
127
|
+
address,
|
|
128
|
+
pair: {
|
|
129
|
+
slug: `${hdx.slug}___${desToken.slug}`,
|
|
130
|
+
from: hdx.slug,
|
|
131
|
+
to: desToken.slug
|
|
132
|
+
}
|
|
133
|
+
}));
|
|
134
|
+
if (!quoteRate) {
|
|
135
|
+
return undefined;
|
|
136
|
+
} else {
|
|
137
|
+
const hdxDecimal = _getAssetDecimals(hdx);
|
|
138
|
+
const desTokenDecimal = _getAssetDecimals(desToken);
|
|
139
|
+
return new BigN(quoteRate).multipliedBy(10 ** (desTokenDecimal - hdxDecimal)).toFixed();
|
|
140
|
+
}
|
|
141
|
+
}
|