@subwallet/extension-base 1.3.29-1 → 1.3.31-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 +16 -4
- package/background/errors/SwapError.js +1 -1
- package/cjs/background/errors/SwapError.js +1 -1
- package/cjs/constants/blocked-actions.js +2 -2
- package/cjs/constants/paraspell-chain-map.js +13 -0
- package/cjs/constants/remind-notification-time.js +3 -3
- package/cjs/core/logic-validation/swap.js +63 -4
- package/cjs/core/logic-validation/transfer.js +13 -1
- package/cjs/core/substrate/xcm-parser.js +5 -1
- package/cjs/core/utils.js +36 -15
- package/cjs/koni/background/handlers/Extension.js +141 -172
- package/cjs/koni/background/handlers/State.js +8 -1
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/process.js +27 -0
- package/cjs/services/balance-service/index.js +9 -0
- package/cjs/services/balance-service/transfer/xcm/acrossBridge/index.js +229 -0
- package/cjs/services/balance-service/transfer/xcm/availBridge.js +6 -6
- package/cjs/services/balance-service/transfer/xcm/index.js +96 -7
- package/cjs/services/balance-service/transfer/xcm/utils.js +213 -0
- package/cjs/services/chain-service/constants.js +2 -4
- package/cjs/services/chain-service/index.js +71 -17
- package/cjs/services/chain-service/utils/patch.js +1 -1
- package/cjs/services/earning-service/handlers/base.js +6 -3
- package/cjs/services/earning-service/handlers/native-staking/base.js +4 -1
- package/cjs/services/earning-service/handlers/native-staking/dtao.js +68 -50
- package/cjs/services/earning-service/handlers/native-staking/tao.js +12 -2
- package/cjs/services/earning-service/handlers/special.js +18 -9
- package/cjs/services/earning-service/service.js +2 -1
- package/cjs/services/fee-service/utils/index.js +16 -4
- package/cjs/services/inapp-notification-service/index.js +19 -13
- package/cjs/services/keyring-service/context/handlers/Ledger.js +1 -1
- package/cjs/services/keyring-service/context/state.js +3 -0
- package/cjs/services/migration-service/scripts/DisableZeroBalanceTokens.js +60 -0
- package/cjs/services/migration-service/scripts/EnableChain.js +1 -1
- package/cjs/services/migration-service/scripts/index.js +3 -2
- package/cjs/services/swap-service/handler/asset-hub/handler.js +61 -314
- package/cjs/services/swap-service/handler/base-handler.js +406 -231
- package/cjs/services/swap-service/handler/chainflip-handler.js +18 -40
- package/cjs/services/swap-service/handler/hydradx-handler.js +77 -269
- package/cjs/services/swap-service/handler/simpleswap-handler.js +27 -48
- package/cjs/services/swap-service/handler/uniswap-handler.js +33 -54
- package/cjs/services/swap-service/index.js +154 -143
- package/cjs/services/swap-service/utils.js +107 -17
- package/cjs/services/transaction-service/index.js +1 -1
- package/cjs/services/transaction-service/utils.js +38 -14
- package/cjs/types/swap/index.js +13 -1
- package/cjs/utils/fee/transfer.js +52 -28
- package/cjs/utils/staticData/index.js +7 -2
- package/cjs/utils/swap.js +5 -1
- package/constants/blocked-actions.d.ts +1 -1
- package/constants/blocked-actions.js +1 -1
- package/constants/paraspell-chain-map.d.ts +1 -0
- package/constants/paraspell-chain-map.js +7 -0
- package/constants/remind-notification-time.d.ts +1 -1
- package/constants/remind-notification-time.js +1 -1
- package/core/logic-validation/swap.d.ts +15 -0
- package/core/logic-validation/swap.js +60 -4
- package/core/logic-validation/transfer.d.ts +1 -0
- package/core/logic-validation/transfer.js +12 -1
- package/core/substrate/xcm-parser.d.ts +1 -0
- package/core/substrate/xcm-parser.js +4 -1
- package/core/utils.d.ts +2 -2
- package/core/utils.js +36 -15
- package/koni/background/handlers/Extension.d.ts +1 -1
- package/koni/background/handlers/Extension.js +66 -98
- package/koni/background/handlers/State.d.ts +1 -0
- package/koni/background/handlers/State.js +7 -1
- package/package.json +23 -13
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/process.d.ts +2 -1
- package/services/balance-service/helpers/process.js +26 -0
- package/services/balance-service/index.js +11 -2
- package/services/balance-service/transfer/xcm/acrossBridge/index.d.ts +15 -0
- package/services/balance-service/transfer/xcm/acrossBridge/index.js +216 -0
- package/services/balance-service/transfer/xcm/availBridge.js +6 -6
- package/services/balance-service/transfer/xcm/index.d.ts +5 -1
- package/services/balance-service/transfer/xcm/index.js +85 -1
- package/services/balance-service/transfer/xcm/utils.d.ts +11 -0
- package/services/balance-service/transfer/xcm/utils.js +208 -0
- package/services/base/types.d.ts +0 -4
- package/services/chain-service/constants.d.ts +0 -1
- package/services/chain-service/constants.js +1 -2
- package/services/chain-service/index.d.ts +9 -2
- package/services/chain-service/index.js +72 -18
- package/services/chain-service/utils/patch.js +1 -1
- package/services/earning-service/handlers/base.d.ts +4 -3
- package/services/earning-service/handlers/base.js +6 -4
- package/services/earning-service/handlers/native-staking/base.js +4 -1
- package/services/earning-service/handlers/native-staking/dtao.d.ts +9 -6
- package/services/earning-service/handlers/native-staking/dtao.js +69 -48
- package/services/earning-service/handlers/native-staking/tao.js +12 -2
- package/services/earning-service/handlers/special.js +19 -10
- package/services/earning-service/service.d.ts +2 -1
- package/services/earning-service/service.js +2 -1
- package/services/fee-service/utils/index.d.ts +1 -0
- package/services/fee-service/utils/index.js +14 -4
- package/services/inapp-notification-service/index.js +13 -7
- package/services/keyring-service/context/handlers/Ledger.js +1 -1
- package/services/keyring-service/context/state.d.ts +1 -0
- package/services/keyring-service/context/state.js +3 -0
- package/services/migration-service/scripts/DisableZeroBalanceTokens.d.ts +4 -0
- package/services/migration-service/scripts/DisableZeroBalanceTokens.js +51 -0
- package/services/migration-service/scripts/EnableChain.js +1 -1
- package/services/migration-service/scripts/index.js +3 -2
- package/services/swap-service/handler/asset-hub/handler.d.ts +2 -9
- package/services/swap-service/handler/asset-hub/handler.js +64 -317
- package/services/swap-service/handler/base-handler.d.ts +6 -9
- package/services/swap-service/handler/base-handler.js +405 -230
- package/services/swap-service/handler/chainflip-handler.d.ts +2 -4
- package/services/swap-service/handler/chainflip-handler.js +15 -37
- package/services/swap-service/handler/hydradx-handler.d.ts +3 -10
- package/services/swap-service/handler/hydradx-handler.js +78 -270
- package/services/swap-service/handler/simpleswap-handler.d.ts +2 -4
- package/services/swap-service/handler/simpleswap-handler.js +24 -45
- package/services/swap-service/handler/uniswap-handler.d.ts +4 -6
- package/services/swap-service/handler/uniswap-handler.js +25 -46
- package/services/swap-service/index.d.ts +8 -14
- package/services/swap-service/index.js +141 -129
- package/services/swap-service/utils.d.ts +11 -3
- package/services/swap-service/utils.js +96 -15
- package/services/transaction-service/index.js +2 -2
- package/services/transaction-service/types.d.ts +3 -2
- package/services/transaction-service/utils.d.ts +1 -0
- package/services/transaction-service/utils.js +38 -15
- package/types/balance/transfer.d.ts +1 -0
- package/types/service-base.d.ts +2 -3
- package/types/swap/index.d.ts +25 -9
- package/types/swap/index.js +10 -0
- package/types/transaction/process.d.ts +19 -0
- package/types/transaction/request.d.ts +7 -0
- package/types/yield/actions/join/submit.d.ts +4 -1
- package/types/yield/actions/others.d.ts +2 -0
- package/utils/fee/transfer.d.ts +1 -0
- package/utils/fee/transfer.js +54 -30
- package/utils/staticData/index.d.ts +4 -1
- package/utils/staticData/index.js +5 -1
- package/utils/staticData/paraSpellChainMap.json +1 -0
- package/utils/swap.d.ts +3 -0
- package/utils/swap.js +3 -0
- package/cjs/services/swap-service/interface.js +0 -14
- package/services/swap-service/interface.d.ts +0 -9
- package/services/swap-service/interface.js +0 -8
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { _AssetRef, _AssetType, _ChainAsset, _ChainInfo, _MultiChainAsset } from '@subwallet/chain-list/types';
|
|
3
|
-
import { AssetSetting, MetadataItem, TokenPriorityDetails, ValidateNetworkResponse } from '@subwallet/extension-base/background/KoniTypes';
|
|
3
|
+
import { AssetSetting, MetadataItem, SufficientChainsDetails, TokenPriorityDetails, ValidateNetworkResponse } from '@subwallet/extension-base/background/KoniTypes';
|
|
4
4
|
import { MantaPrivateHandler } from '@subwallet/extension-base/services/chain-service/handler/manta/MantaPrivateHandler';
|
|
5
5
|
import { _ChainApiStatus, _ChainConnectionStatus, _ChainState, _NetworkUpsertParams, _SubstrateApi, _ValidateCustomAssetRequest, _ValidateCustomAssetResponse } from '@subwallet/extension-base/services/chain-service/types';
|
|
6
6
|
import { EventService } from '@subwallet/extension-base/services/event-service';
|
|
@@ -32,6 +32,7 @@ export declare class ChainService {
|
|
|
32
32
|
private chainLogoMapSubject;
|
|
33
33
|
private ledgerGenericAllowChainsSubject;
|
|
34
34
|
private priorityTokensSubject;
|
|
35
|
+
private sufficientChainsSubject;
|
|
35
36
|
private store;
|
|
36
37
|
private assetSettingSubject;
|
|
37
38
|
private logger;
|
|
@@ -39,10 +40,12 @@ export declare class ChainService {
|
|
|
39
40
|
get value(): {
|
|
40
41
|
readonly ledgerGenericAllowChains: string[];
|
|
41
42
|
readonly priorityTokens: TokenPriorityDetails;
|
|
43
|
+
readonly sufficientChains: SufficientChainsDetails;
|
|
42
44
|
};
|
|
43
45
|
get observable(): {
|
|
44
46
|
readonly ledgerGenericAllowChains: import("rxjs").Observable<string[]>;
|
|
45
47
|
readonly priorityTokens: import("rxjs").Observable<TokenPriorityDetails>;
|
|
48
|
+
readonly sufficientChains: import("rxjs").Observable<SufficientChainsDetails>;
|
|
46
49
|
};
|
|
47
50
|
subscribeSwapRefMap(): Subject<Record<string, _AssetRef>>;
|
|
48
51
|
get xcmRefMap(): Record<string, _AssetRef>;
|
|
@@ -111,8 +114,10 @@ export declare class ChainService {
|
|
|
111
114
|
stopCheckLatestChainData(): void;
|
|
112
115
|
handleLatestChainData(latestChainInfo: _ChainInfo[]): void;
|
|
113
116
|
autoEnableTokens(): Promise<void>;
|
|
117
|
+
enablePopularTokens(): Promise<void>;
|
|
114
118
|
handleLatestLedgerGenericAllowChains(latestledgerGenericAllowChains: string[]): void;
|
|
115
119
|
handleLatestPriorityTokens(latestPriorityTokens: TokenPriorityDetails): void;
|
|
120
|
+
handleLatestSufficientChains(latestSufficientChains: SufficientChainsDetails): void;
|
|
116
121
|
handleLatestData(): void;
|
|
117
122
|
private initApis;
|
|
118
123
|
initSingleApi(slug: string): Promise<boolean>;
|
|
@@ -127,6 +132,7 @@ export declare class ChainService {
|
|
|
127
132
|
private fetchLatestPriceIdsData;
|
|
128
133
|
private fetchLatestLedgerGenericAllowChains;
|
|
129
134
|
private fetchLatestPriorityTokens;
|
|
135
|
+
private fetchLatestSufficientChains;
|
|
130
136
|
private initChains;
|
|
131
137
|
private initAssetRegistry;
|
|
132
138
|
private updateChainStateMapSubscription;
|
|
@@ -148,13 +154,14 @@ export declare class ChainService {
|
|
|
148
154
|
refreshEvmApi(slug: string): void;
|
|
149
155
|
stopAllChainApis(): Promise<void>;
|
|
150
156
|
resumeAllChainApis(): Promise<void>;
|
|
151
|
-
initAssetSettings():
|
|
157
|
+
initAssetSettings(): void;
|
|
152
158
|
setAssetSettings(assetSettings: Record<string, AssetSetting>, emitEvent?: boolean): void;
|
|
153
159
|
setMantaZkAssetSettings(visible: boolean): void;
|
|
154
160
|
getStoreAssetSettings(): Promise<Record<string, AssetSetting>>;
|
|
155
161
|
getAssetSettings(): Promise<Record<string, AssetSetting>>;
|
|
156
162
|
updateAssetSetting(assetSlug: string, assetSetting: AssetSetting, autoEnableNativeToken?: boolean): Promise<boolean | undefined>;
|
|
157
163
|
updateAssetSettingByChain(chainSlug: string, visible: boolean): Promise<void>;
|
|
164
|
+
updatePriorityAssetsByChain(chainSlug: string, visible: boolean): Promise<void>;
|
|
158
165
|
subscribeAssetSettings(): BehaviorSubject<Record<string, AssetSetting>>;
|
|
159
166
|
getAssetLogoMap(): Record<string, string>;
|
|
160
167
|
subscribeAssetLogoMap(): BehaviorSubject<Record<string, string>>;
|
|
@@ -11,7 +11,7 @@ import { SubstrateChainHandler } from '@subwallet/extension-base/services/chain-
|
|
|
11
11
|
import { TonChainHandler } from '@subwallet/extension-base/services/chain-service/handler/TonChainHandler';
|
|
12
12
|
import { _CHAIN_VALIDATION_ERROR } from '@subwallet/extension-base/services/chain-service/handler/types';
|
|
13
13
|
import { _ChainConnectionStatus, _CUSTOM_PREFIX, _NFT_CONTRACT_STANDARDS, _SMART_CONTRACT_STANDARDS } from '@subwallet/extension-base/services/chain-service/types';
|
|
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
|
+
import { _getAssetOriginChain, _getTokenOnChainAssetId, _isAssetAutoEnable, _isAssetCanPayTxFee, _isAssetFungibleToken, _isChainEnabled, _isCustomAsset, _isCustomChain, _isCustomProvider, _isEqualContractAddress, _isEqualSmartContractAsset, _isLocalToken, _isMantaZkAsset, _isNativeToken, _isPureEvmChain, _isPureSubstrateChain, _parseAssetRefKey, randomizeProvider, updateLatestChainInfo } from '@subwallet/extension-base/services/chain-service/utils';
|
|
15
15
|
import { MYTHOS_MIGRATION_KEY } from '@subwallet/extension-base/services/migration-service/scripts';
|
|
16
16
|
import AssetSettingStore from '@subwallet/extension-base/stores/AssetSetting';
|
|
17
17
|
import { addLazy, calculateMetadataHash, fetchStaticData, filterAssetsByChainAndType, getShortMetadata, MODULE_SUPPORT } from '@subwallet/extension-base/utils';
|
|
@@ -50,6 +50,7 @@ export class ChainService {
|
|
|
50
50
|
chainLogoMapSubject = new BehaviorSubject(ChainLogoMap);
|
|
51
51
|
ledgerGenericAllowChainsSubject = new BehaviorSubject([]);
|
|
52
52
|
priorityTokensSubject = new BehaviorSubject({});
|
|
53
|
+
sufficientChainsSubject = new BehaviorSubject({});
|
|
53
54
|
|
|
54
55
|
// Todo: Update to new store indexed DB
|
|
55
56
|
store = new AssetSettingStore();
|
|
@@ -75,24 +76,32 @@ export class ChainService {
|
|
|
75
76
|
get value() {
|
|
76
77
|
const ledgerGenericAllowChains = this.ledgerGenericAllowChainsSubject;
|
|
77
78
|
const priorityTokens = this.priorityTokensSubject;
|
|
79
|
+
const sufficientChains = this.sufficientChainsSubject;
|
|
78
80
|
return {
|
|
79
81
|
get ledgerGenericAllowChains() {
|
|
80
82
|
return ledgerGenericAllowChains.value;
|
|
81
83
|
},
|
|
82
84
|
get priorityTokens() {
|
|
83
85
|
return priorityTokens.value;
|
|
86
|
+
},
|
|
87
|
+
get sufficientChains() {
|
|
88
|
+
return sufficientChains.value;
|
|
84
89
|
}
|
|
85
90
|
};
|
|
86
91
|
}
|
|
87
92
|
get observable() {
|
|
88
93
|
const ledgerGenericAllowChains = this.ledgerGenericAllowChainsSubject;
|
|
89
94
|
const priorityTokens = this.priorityTokensSubject;
|
|
95
|
+
const sufficientChains = this.sufficientChainsSubject;
|
|
90
96
|
return {
|
|
91
97
|
get ledgerGenericAllowChains() {
|
|
92
98
|
return ledgerGenericAllowChains.asObservable();
|
|
93
99
|
},
|
|
94
100
|
get priorityTokens() {
|
|
95
101
|
return priorityTokens.asObservable();
|
|
102
|
+
},
|
|
103
|
+
get sufficientChains() {
|
|
104
|
+
return sufficientChains.asObservable();
|
|
96
105
|
}
|
|
97
106
|
};
|
|
98
107
|
}
|
|
@@ -526,7 +535,7 @@ export class ChainService {
|
|
|
526
535
|
this.initAssetRefMap();
|
|
527
536
|
this.xcmRefMapSubject.next(this.xcmRefMap);
|
|
528
537
|
await this.initApis();
|
|
529
|
-
|
|
538
|
+
this.initAssetSettings();
|
|
530
539
|
await this.autoEnableTokens();
|
|
531
540
|
}
|
|
532
541
|
initAssetRefMap() {
|
|
@@ -605,14 +614,47 @@ export class ChainService {
|
|
|
605
614
|
}
|
|
606
615
|
}
|
|
607
616
|
}
|
|
617
|
+
async enablePopularTokens() {
|
|
618
|
+
const assetSettings = this.assetSettingSubject.value;
|
|
619
|
+
const chainStateMap = this.getChainStateMap();
|
|
620
|
+
const priorityTokensMap = this.priorityTokensSubject.value || {};
|
|
621
|
+
const priorityTokensList = priorityTokensMap.token && typeof priorityTokensMap.token === 'object' ? Object.keys(priorityTokensMap.token) : [];
|
|
622
|
+
for (const assetSlug of priorityTokensList) {
|
|
623
|
+
const assetState = assetSettings[assetSlug];
|
|
624
|
+
const assetInfo = this.getAssetBySlug(assetSlug);
|
|
625
|
+
const chainState = chainStateMap[assetInfo.originChain];
|
|
626
|
+
if (!assetState) {
|
|
627
|
+
// If this asset not has asset setting, this token is not enabled before (not turned off before)
|
|
628
|
+
if (!chainState || !chainState.manualTurnOff) {
|
|
629
|
+
await this.updateAssetSetting(assetSlug, {
|
|
630
|
+
visible: true
|
|
631
|
+
}, true);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
}
|
|
608
636
|
handleLatestLedgerGenericAllowChains(latestledgerGenericAllowChains) {
|
|
609
637
|
this.ledgerGenericAllowChainsSubject.next(latestledgerGenericAllowChains);
|
|
610
638
|
this.eventService.emit('ledger.ready', true);
|
|
611
639
|
this.logger.log('Finished updating latest ledger generic allow chains');
|
|
612
640
|
}
|
|
613
641
|
handleLatestPriorityTokens(latestPriorityTokens) {
|
|
642
|
+
const currentTokens = this.priorityTokensSubject.value || {};
|
|
614
643
|
this.priorityTokensSubject.next(latestPriorityTokens);
|
|
615
644
|
this.logger.log('Finished updating latest popular tokens');
|
|
645
|
+
const currentTokenKeys = Object.keys(currentTokens.token || {}); // Extract keys from current tokens
|
|
646
|
+
const newTokenKeys = Object.keys(latestPriorityTokens.token || {}); // Extract keys from new tokens
|
|
647
|
+
|
|
648
|
+
if (JSON.stringify(currentTokenKeys) !== JSON.stringify(newTokenKeys)) {
|
|
649
|
+
// Check if token keys have changed
|
|
650
|
+
this.enablePopularTokens().then(() => this.logger.log('Popular tokens enabled due to priority tokens change')) // Log success after enabling tokens
|
|
651
|
+
.catch(e => console.error('Error enabling popular tokens:', e)); // Log error if enabling fails
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
handleLatestSufficientChains(latestSufficientChains) {
|
|
656
|
+
this.sufficientChainsSubject.next(latestSufficientChains);
|
|
657
|
+
this.logger.log('Finished updating latest supported sufficient chains');
|
|
616
658
|
}
|
|
617
659
|
handleLatestData() {
|
|
618
660
|
this.fetchLatestChainData().then(latestChainInfo => {
|
|
@@ -634,6 +676,9 @@ export class ChainService {
|
|
|
634
676
|
this.fetchLatestPriorityTokens().then(latestPriorityTokens => {
|
|
635
677
|
this.handleLatestPriorityTokens(latestPriorityTokens);
|
|
636
678
|
}).catch(console.error);
|
|
679
|
+
this.fetchLatestSufficientChains().then(latestSufficientChains => {
|
|
680
|
+
this.handleLatestSufficientChains(latestSufficientChains);
|
|
681
|
+
}).catch(console.error);
|
|
637
682
|
}
|
|
638
683
|
async initApis() {
|
|
639
684
|
const chainInfoMap = this.getChainInfoMap();
|
|
@@ -913,6 +958,9 @@ export class ChainService {
|
|
|
913
958
|
token: {}
|
|
914
959
|
};
|
|
915
960
|
}
|
|
961
|
+
async fetchLatestSufficientChains() {
|
|
962
|
+
return (await fetchStaticData('chains/supported-sufficient-chains')) || [];
|
|
963
|
+
}
|
|
916
964
|
async initChains() {
|
|
917
965
|
const storedChainSettings = await this.dbService.getAllChainStore();
|
|
918
966
|
const defaultChainInfoMap = filterChainInfoMap(ChainInfoMap, ignoredList);
|
|
@@ -1616,22 +1664,7 @@ export class ChainService {
|
|
|
1616
1664
|
await Promise.all([this.substrateChainHandler.wakeUp(), this.evmChainHandler.wakeUp(), this.tonChainHandler.wakeUp(), this.cardanoChainHandler.wakeUp()]);
|
|
1617
1665
|
this.checkLatestData();
|
|
1618
1666
|
}
|
|
1619
|
-
|
|
1620
|
-
const assetSettings = await this.getAssetSettings();
|
|
1621
|
-
const activeChainSlugs = this.getActiveChainSlugs();
|
|
1622
|
-
const assetRegistry = this.getAssetRegistry();
|
|
1623
|
-
Object.values(assetRegistry).forEach(assetInfo => {
|
|
1624
|
-
const isSettingExisted = (assetInfo.slug in assetSettings);
|
|
1625
|
-
|
|
1626
|
-
// Set visible for every enabled chains
|
|
1627
|
-
if (activeChainSlugs.includes(assetInfo.originChain) && !isSettingExisted) {
|
|
1628
|
-
// Setting only exist when set either by chain settings or user
|
|
1629
|
-
assetSettings[assetInfo.slug] = {
|
|
1630
|
-
visible: true
|
|
1631
|
-
};
|
|
1632
|
-
}
|
|
1633
|
-
});
|
|
1634
|
-
this.setAssetSettings(assetSettings, false);
|
|
1667
|
+
initAssetSettings() {
|
|
1635
1668
|
this.eventService.emit('asset.ready', true);
|
|
1636
1669
|
}
|
|
1637
1670
|
setAssetSettings(assetSettings, emitEvent = true) {
|
|
@@ -1719,6 +1752,27 @@ export class ChainService {
|
|
|
1719
1752
|
});
|
|
1720
1753
|
this.setAssetSettings(assetSettings);
|
|
1721
1754
|
}
|
|
1755
|
+
async updatePriorityAssetsByChain(chainSlug, visible) {
|
|
1756
|
+
const currentAssetSettings = await this.getAssetSettings();
|
|
1757
|
+
const assetsByChain = this.getFungibleTokensByChain(chainSlug);
|
|
1758
|
+
const priorityTokensMap = this.priorityTokensSubject.value || {};
|
|
1759
|
+
const priorityTokensList = priorityTokensMap.token && typeof priorityTokensMap.token === 'object' ? Object.keys(priorityTokensMap.token) : [];
|
|
1760
|
+
for (const asset of Object.values(assetsByChain)) {
|
|
1761
|
+
if (visible) {
|
|
1762
|
+
const isPriorityToken = priorityTokensList.includes(asset.slug);
|
|
1763
|
+
if (isPriorityToken || _isNativeToken(asset)) {
|
|
1764
|
+
currentAssetSettings[asset.slug] = {
|
|
1765
|
+
visible: true
|
|
1766
|
+
};
|
|
1767
|
+
}
|
|
1768
|
+
} else {
|
|
1769
|
+
currentAssetSettings[asset.slug] = {
|
|
1770
|
+
visible: false
|
|
1771
|
+
};
|
|
1772
|
+
}
|
|
1773
|
+
}
|
|
1774
|
+
this.setAssetSettings(currentAssetSettings);
|
|
1775
|
+
}
|
|
1722
1776
|
subscribeAssetSettings() {
|
|
1723
1777
|
return this.assetSettingSubject;
|
|
1724
1778
|
}
|
|
@@ -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.103'; // update this when build chainlist
|
|
9
9
|
|
|
10
10
|
// todo: move this interface to chainlist
|
|
11
11
|
|
|
@@ -4,6 +4,7 @@ import { ChainType, ExtrinsicType } from '@subwallet/extension-base/background/K
|
|
|
4
4
|
import KoniState from '@subwallet/extension-base/koni/background/handlers/State';
|
|
5
5
|
import { _EvmApi, _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
6
6
|
import { BasePoolInfo, BaseYieldPoolMetadata, EarningRewardHistoryItem, EarningRewardItem, HandleYieldStepData, OptimalYieldPath, OptimalYieldPathParams, RequestEarlyValidateYield, RequestEarningSlippage, ResponseEarlyValidateYield, StakeCancelWithdrawalParams, SubmitYieldJoinData, TransactionData, UnstakingInfo, YieldPoolInfo, YieldPoolMethodInfo, YieldPoolTarget, YieldPoolType, YieldPositionInfo, YieldStepBaseInfo, YieldTokenBaseInfo } from '@subwallet/extension-base/types';
|
|
7
|
+
import { EarningSlippageResult } from './native-staking/dtao';
|
|
7
8
|
/**
|
|
8
9
|
* @class BasePoolHandler
|
|
9
10
|
* @description Base pool handler
|
|
@@ -101,11 +102,11 @@ export default abstract class BasePoolHandler {
|
|
|
101
102
|
/** Validate param to leave the pool */
|
|
102
103
|
abstract validateYieldLeave(amount: string, address: string, fastLeave: boolean, selectedTarget?: string, slug?: string, poolInfo?: YieldPoolInfo): Promise<TransactionError[]>;
|
|
103
104
|
/** Create `transaction` to leave the pool normal (default unstake) */
|
|
104
|
-
protected abstract handleYieldUnstake(amount: string, address: string, selectedTarget?: string, netuid?: number): Promise<[ExtrinsicType, TransactionData]>;
|
|
105
|
+
protected abstract handleYieldUnstake(amount: string, address: string, selectedTarget?: string, netuid?: number, slippage?: number): Promise<[ExtrinsicType, TransactionData]>;
|
|
105
106
|
/** Create `transaction` to leave the pool fast (swap token) */
|
|
106
107
|
protected abstract handleYieldRedeem(amount: string, address: string, selectedTarget?: string): Promise<[ExtrinsicType, TransactionData]>;
|
|
107
108
|
/** Create `transaction` to leave the pool */
|
|
108
|
-
handleYieldLeave(fastLeave: boolean, amount: string, address: string, selectedTarget?: string, netuid?: number): Promise<[ExtrinsicType, TransactionData]>;
|
|
109
|
+
handleYieldLeave(fastLeave: boolean, amount: string, address: string, selectedTarget?: string, netuid?: number, slippage?: number): Promise<[ExtrinsicType, TransactionData]>;
|
|
109
110
|
/** Create `transaction` to withdraw unstaked amount */
|
|
110
111
|
abstract handleYieldWithdraw(address: string, unstakingInfo: UnstakingInfo): Promise<TransactionData>;
|
|
111
112
|
/** Create `transaction` to cancel unstake */
|
|
@@ -114,5 +115,5 @@ export default abstract class BasePoolHandler {
|
|
|
114
115
|
abstract handleYieldClaimReward(address: string, bondReward?: boolean): Promise<TransactionData>;
|
|
115
116
|
/** Check handler can handle slug */
|
|
116
117
|
canHandleSlug(slug: string): boolean;
|
|
117
|
-
getEarningSlippage(params: RequestEarningSlippage): Promise<
|
|
118
|
+
getEarningSlippage(params: RequestEarningSlippage): Promise<EarningSlippageResult>;
|
|
118
119
|
}
|
|
@@ -7,7 +7,6 @@ import { DEFAULT_YIELD_FIRST_STEP } from '@subwallet/extension-base/services/ear
|
|
|
7
7
|
import { createClaimNotification, createWithdrawNotifications } from '@subwallet/extension-base/services/inapp-notification-service/utils';
|
|
8
8
|
import { formatNumber, reformatAddress } from '@subwallet/extension-base/utils';
|
|
9
9
|
import { BN, BN_TEN } from '@polkadot/util';
|
|
10
|
-
|
|
11
10
|
/**
|
|
12
11
|
* @class BasePoolHandler
|
|
13
12
|
* @description Base pool handler
|
|
@@ -249,11 +248,11 @@ export default class BasePoolHandler {
|
|
|
249
248
|
/** Validate param to join the pool */
|
|
250
249
|
|
|
251
250
|
/** Create `transaction` to leave the pool */
|
|
252
|
-
async handleYieldLeave(fastLeave, amount, address, selectedTarget, netuid) {
|
|
251
|
+
async handleYieldLeave(fastLeave, amount, address, selectedTarget, netuid, slippage) {
|
|
253
252
|
if (fastLeave) {
|
|
254
253
|
return this.handleYieldRedeem(amount, address, selectedTarget);
|
|
255
254
|
} else {
|
|
256
|
-
return this.handleYieldUnstake(amount, address, selectedTarget, netuid);
|
|
255
|
+
return this.handleYieldUnstake(amount, address, selectedTarget, netuid, slippage);
|
|
257
256
|
}
|
|
258
257
|
}
|
|
259
258
|
|
|
@@ -268,7 +267,10 @@ export default class BasePoolHandler {
|
|
|
268
267
|
return this.slug === slug;
|
|
269
268
|
}
|
|
270
269
|
getEarningSlippage(params) {
|
|
271
|
-
return Promise.resolve(
|
|
270
|
+
return Promise.resolve({
|
|
271
|
+
slippage: 0,
|
|
272
|
+
rate: 1
|
|
273
|
+
});
|
|
272
274
|
}
|
|
273
275
|
/* Other actions */
|
|
274
276
|
}
|
|
@@ -102,7 +102,10 @@ export default class BaseNativeStakingPoolHandler extends BasePoolHandler {
|
|
|
102
102
|
address,
|
|
103
103
|
slug,
|
|
104
104
|
selectedValidators,
|
|
105
|
-
|
|
105
|
+
subnetData: {
|
|
106
|
+
netuid: netuid || 0,
|
|
107
|
+
slippage: 0
|
|
108
|
+
}
|
|
106
109
|
};
|
|
107
110
|
const positionInfo = await this.getPoolPosition(address);
|
|
108
111
|
const [, fee] = await this.createJoinExtrinsic(data, positionInfo);
|
|
@@ -2,10 +2,9 @@ import { _ChainInfo } from '@subwallet/chain-list/types';
|
|
|
2
2
|
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
3
3
|
import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
4
4
|
import KoniState from '@subwallet/extension-base/koni/background/handlers/State';
|
|
5
|
-
import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
6
5
|
import BaseParaStakingPoolHandler from '@subwallet/extension-base/services/earning-service/handlers/native-staking/base-para';
|
|
7
6
|
import { BaseYieldPositionInfo, OptimalYieldPath, RequestEarningSlippage, StakeCancelWithdrawalParams, SubmitJoinNativeStaking, TransactionData, UnstakingInfo, ValidatorInfo, YieldPoolInfo, YieldPoolMethodInfo, YieldPoolType, YieldPositionInfo, YieldTokenBaseInfo } from '@subwallet/extension-base/types';
|
|
8
|
-
import
|
|
7
|
+
import BigN from 'bignumber.js';
|
|
9
8
|
export interface SubnetData {
|
|
10
9
|
netuid: number;
|
|
11
10
|
name: string;
|
|
@@ -13,11 +12,12 @@ export interface SubnetData {
|
|
|
13
12
|
ownerHotkey: string;
|
|
14
13
|
maxAllowedValidators: number;
|
|
15
14
|
taoIn: number;
|
|
15
|
+
taoInEmission: number;
|
|
16
16
|
}
|
|
17
17
|
interface TaoStakingStakeOption {
|
|
18
18
|
owner: string;
|
|
19
19
|
amount: string;
|
|
20
|
-
rate?:
|
|
20
|
+
rate?: BigN;
|
|
21
21
|
identity?: string;
|
|
22
22
|
}
|
|
23
23
|
export interface RawDelegateState {
|
|
@@ -36,8 +36,11 @@ export interface TestnetBittensorDelegateInfo {
|
|
|
36
36
|
nominators: Nominators;
|
|
37
37
|
returnPer1000: number;
|
|
38
38
|
}
|
|
39
|
+
export interface EarningSlippageResult {
|
|
40
|
+
slippage: number;
|
|
41
|
+
rate: number;
|
|
42
|
+
}
|
|
39
43
|
export declare const DEFAULT_DTAO_MINBOND = "600000";
|
|
40
|
-
export declare const getAlphaToTaoMapping: (substrateApi: _SubstrateApi) => Promise<Record<number, string>>;
|
|
41
44
|
export default class SubnetTaoStakingPoolHandler extends BaseParaStakingPoolHandler {
|
|
42
45
|
handleYieldWithdraw(address: string, unstakingInfo: UnstakingInfo): Promise<TransactionData>;
|
|
43
46
|
handleYieldCancelUnstake(params: StakeCancelWithdrawalParams): Promise<TransactionData>;
|
|
@@ -51,7 +54,7 @@ export default class SubnetTaoStakingPoolHandler extends BaseParaStakingPoolHand
|
|
|
51
54
|
readonly availableMethod: YieldPoolMethodInfo;
|
|
52
55
|
constructor(state: KoniState, chain: string);
|
|
53
56
|
canHandleSlug(slug: string): boolean;
|
|
54
|
-
getEarningSlippage(params: RequestEarningSlippage): Promise<
|
|
57
|
+
getEarningSlippage(params: RequestEarningSlippage): Promise<EarningSlippageResult>;
|
|
55
58
|
get maintainBalance(): string;
|
|
56
59
|
private init;
|
|
57
60
|
protected getDescription(): string;
|
|
@@ -63,7 +66,7 @@ export default class SubnetTaoStakingPoolHandler extends BaseParaStakingPoolHand
|
|
|
63
66
|
getPoolTargets(): Promise<ValidatorInfo[]>;
|
|
64
67
|
createJoinExtrinsic(data: SubmitJoinNativeStaking, positionInfo?: YieldPositionInfo, bondDest?: string): Promise<[TransactionData, YieldTokenBaseInfo]>;
|
|
65
68
|
validateYieldJoin(data: SubmitJoinNativeStaking, path: OptimalYieldPath): Promise<TransactionError[]>;
|
|
66
|
-
handleYieldUnstake(amount: string, address: string, selectedTarget?: string, netuid?: number): Promise<[ExtrinsicType, TransactionData]>;
|
|
69
|
+
handleYieldUnstake(amount: string, address: string, selectedTarget?: string, netuid?: number, slippage?: number): Promise<[ExtrinsicType, TransactionData]>;
|
|
67
70
|
validateYieldLeave(amount: string, address: string, fastLeave: boolean, selectedTarget?: string, slug?: string, poolInfo?: YieldPoolInfo): Promise<TransactionError[]>;
|
|
68
71
|
}
|
|
69
72
|
export {};
|
|
@@ -9,31 +9,38 @@ import { _getAssetDecimals, _getAssetSymbol } from '@subwallet/extension-base/se
|
|
|
9
9
|
import BaseParaStakingPoolHandler from '@subwallet/extension-base/services/earning-service/handlers/native-staking/base-para';
|
|
10
10
|
import { BasicTxErrorType, EarningStatus, YieldPoolType } from '@subwallet/extension-base/types';
|
|
11
11
|
import { formatNumber, reformatAddress } from '@subwallet/extension-base/utils';
|
|
12
|
-
import BigN
|
|
12
|
+
import BigN from 'bignumber.js';
|
|
13
13
|
import { t } from 'i18next';
|
|
14
|
-
import { BN,
|
|
14
|
+
import { BN, BN_ZERO } from '@polkadot/util';
|
|
15
15
|
import { calculateReward } from "../../utils/index.js";
|
|
16
16
|
import { BittensorCache } from "./tao.js";
|
|
17
17
|
const DEFAULT_BITTENSOR_SLIPPAGE = 0.005;
|
|
18
18
|
export const DEFAULT_DTAO_MINBOND = '600000';
|
|
19
|
-
|
|
19
|
+
const getAlphaToTaoMapping = async substrateApi => {
|
|
20
20
|
const allSubnets = (await substrateApi.api.call.subnetInfoRuntimeApi.getAllDynamicInfo()).toJSON();
|
|
21
|
-
if (!allSubnets) {
|
|
21
|
+
if (!allSubnets || allSubnets.length === 0) {
|
|
22
22
|
return {};
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
const result = Object.create(null);
|
|
25
|
+
for (const subnet of allSubnets) {
|
|
25
26
|
const netuid = subnet === null || subnet === void 0 ? void 0 : subnet.netuid;
|
|
27
|
+
if (netuid === undefined) {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
26
30
|
const taoIn = subnet !== null && subnet !== void 0 && subnet.taoIn ? new BigN(subnet.taoIn) : new BigN(0);
|
|
27
31
|
const alphaIn = subnet !== null && subnet !== void 0 && subnet.alphaIn ? new BigN(subnet.alphaIn) : new BigN(0);
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return
|
|
36
|
-
}
|
|
32
|
+
result[netuid] = netuid === 0 || alphaIn.lte(0) ? '1' : taoIn.dividedBy(alphaIn).toString();
|
|
33
|
+
}
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
const getAlphaToTaoRate = async (substrateApi, netuid) => {
|
|
37
|
+
const subnetInfo = (await substrateApi.api.call.subnetInfoRuntimeApi.getDynamicInfo(netuid)).toJSON();
|
|
38
|
+
if (!subnetInfo) {
|
|
39
|
+
return '1';
|
|
40
|
+
}
|
|
41
|
+
const taoIn = subnetInfo.taoIn ? new BigN(subnetInfo.taoIn) : new BigN(0);
|
|
42
|
+
const alphaIn = subnetInfo.alphaIn ? new BigN(subnetInfo.alphaIn) : new BigN(0);
|
|
43
|
+
return netuid === 0 || alphaIn.lte(0) ? '1' : taoIn.dividedBy(alphaIn).toString();
|
|
37
44
|
};
|
|
38
45
|
export default class SubnetTaoStakingPoolHandler extends BaseParaStakingPoolHandler {
|
|
39
46
|
/* Unimplemented function */
|
|
@@ -73,30 +80,40 @@ export default class SubnetTaoStakingPoolHandler extends BaseParaStakingPoolHand
|
|
|
73
80
|
async getEarningSlippage(params) {
|
|
74
81
|
const substrateApi = await this.substrateApi.isReady;
|
|
75
82
|
const subnetInfo = (await substrateApi.api.call.subnetInfoRuntimeApi.getDynamicInfo(params.netuid)).toJSON();
|
|
76
|
-
const alphaIn = new
|
|
77
|
-
const taoIn = new
|
|
83
|
+
const alphaIn = new BigN((subnetInfo === null || subnetInfo === void 0 ? void 0 : subnetInfo.alphaIn) || 0);
|
|
84
|
+
const taoIn = new BigN((subnetInfo === null || subnetInfo === void 0 ? void 0 : subnetInfo.taoIn) || 0);
|
|
78
85
|
const k = alphaIn.multipliedBy(taoIn);
|
|
79
|
-
const value = new
|
|
86
|
+
const value = new BigN(params.value);
|
|
87
|
+
const rate = taoIn.dividedBy(alphaIn);
|
|
80
88
|
if (params.type === ExtrinsicType.STAKING_BOND) {
|
|
81
89
|
const newTaoIn = taoIn.plus(value);
|
|
82
90
|
const newAlphaIn = k.dividedBy(newTaoIn);
|
|
83
91
|
const alphaReturned = alphaIn.minus(newAlphaIn);
|
|
84
92
|
const alphaIdeal = value.multipliedBy(alphaIn).dividedBy(taoIn);
|
|
85
93
|
const slippage = alphaIdeal.minus(alphaReturned).dividedBy(alphaIdeal);
|
|
86
|
-
return
|
|
94
|
+
return {
|
|
95
|
+
slippage: slippage.plus(0.0001).toNumber(),
|
|
96
|
+
rate: rate.toNumber()
|
|
97
|
+
};
|
|
87
98
|
} else if (params.type === ExtrinsicType.STAKING_UNBOND) {
|
|
88
99
|
const newAlphaIn = alphaIn.plus(value);
|
|
89
100
|
const newTaoReserve = k.dividedBy(newAlphaIn);
|
|
90
101
|
const taoReturned = taoIn.minus(newTaoReserve);
|
|
91
102
|
const taoIdeal = value.multipliedBy(taoIn).dividedBy(alphaIn);
|
|
92
103
|
const slippage = taoIdeal.minus(taoReturned).dividedBy(taoIdeal);
|
|
93
|
-
return
|
|
104
|
+
return {
|
|
105
|
+
slippage: slippage.plus(0.0001).toNumber(),
|
|
106
|
+
rate: rate.toNumber()
|
|
107
|
+
};
|
|
94
108
|
}
|
|
95
|
-
return
|
|
109
|
+
return {
|
|
110
|
+
slippage: 0,
|
|
111
|
+
rate: 1
|
|
112
|
+
};
|
|
96
113
|
}
|
|
97
114
|
get maintainBalance() {
|
|
98
|
-
const ed = new
|
|
99
|
-
const calculateMaintainBalance = new
|
|
115
|
+
const ed = new BigN(this.nativeToken.minAmount || '0');
|
|
116
|
+
const calculateMaintainBalance = new BigN(15).multipliedBy(ed).dividedBy(10);
|
|
100
117
|
const maintainBalance = calculateMaintainBalance;
|
|
101
118
|
return maintainBalance.toString();
|
|
102
119
|
}
|
|
@@ -123,7 +140,8 @@ export default class SubnetTaoStakingPoolHandler extends BaseParaStakingPoolHand
|
|
|
123
140
|
symbol,
|
|
124
141
|
ownerHotkey: dynInfo.ownerHotkey,
|
|
125
142
|
maxAllowedValidators: extraInfo ? extraInfo.maxAllowedValidators : 0,
|
|
126
|
-
taoIn: dynInfo.taoIn
|
|
143
|
+
taoIn: dynInfo.taoIn,
|
|
144
|
+
taoInEmission: dynInfo.taoInEmission
|
|
127
145
|
};
|
|
128
146
|
});
|
|
129
147
|
this.subnetData = mergedData;
|
|
@@ -153,7 +171,8 @@ export default class SubnetTaoStakingPoolHandler extends BaseParaStakingPoolHand
|
|
|
153
171
|
const netuid = subnet.netuid.toString().padStart(2, '0');
|
|
154
172
|
const subnetSlug = `${this.slug}__subnet_${netuid.padStart(2, '0')}`;
|
|
155
173
|
const subnetName = `${subnet.name || 'Unknown'} ${netuid}`;
|
|
156
|
-
const bnTaoIn = new
|
|
174
|
+
const bnTaoIn = new BigN(subnet.taoIn);
|
|
175
|
+
const emission = new BigN(subnet.taoInEmission).dividedBy(new BigN(10).pow(new BigN(7)));
|
|
157
176
|
const data = {
|
|
158
177
|
...this.baseInfo,
|
|
159
178
|
type: this.type,
|
|
@@ -182,7 +201,8 @@ export default class SubnetTaoStakingPoolHandler extends BaseParaStakingPoolHand
|
|
|
182
201
|
eraTime: 24,
|
|
183
202
|
era: 0,
|
|
184
203
|
unstakingPeriod: 1.2,
|
|
185
|
-
tvl: bnTaoIn.toString()
|
|
204
|
+
tvl: bnTaoIn.toString(),
|
|
205
|
+
totalApy: emission.toNumber()
|
|
186
206
|
}
|
|
187
207
|
};
|
|
188
208
|
callback(data);
|
|
@@ -350,7 +370,7 @@ export default class SubnetTaoStakingPoolHandler extends BaseParaStakingPoolHand
|
|
|
350
370
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
351
371
|
async getDevnetPoolTargets() {
|
|
352
372
|
const testnetDelegate = (await this.substrateApi.api.call.delegateInfoRuntimeApi.getDelegates()).toJSON();
|
|
353
|
-
const bnMinBond = new
|
|
373
|
+
const bnMinBond = new BigN(DEFAULT_DTAO_MINBOND);
|
|
354
374
|
const filteredDelegates = testnetDelegate.filter(delegate => {
|
|
355
375
|
return delegate.returnPer1000 !== 0;
|
|
356
376
|
});
|
|
@@ -371,14 +391,14 @@ export default class SubnetTaoStakingPoolHandler extends BaseParaStakingPoolHand
|
|
|
371
391
|
async getMainnetPoolTargets() {
|
|
372
392
|
const _topValidator = await this.bittensorCache.get();
|
|
373
393
|
const topValidator = _topValidator;
|
|
374
|
-
const bnMinBond = new
|
|
394
|
+
const bnMinBond = new BigN(DEFAULT_DTAO_MINBOND);
|
|
375
395
|
const validatorList = topValidator.data;
|
|
376
396
|
const validatorAddresses = Object.keys(validatorList);
|
|
377
397
|
const results = await Promise.all(validatorAddresses.map(i => {
|
|
378
398
|
const address = validatorList[i].hotkey.ss58;
|
|
379
|
-
const bnTotalStake = new
|
|
380
|
-
const bnOwnStake = new
|
|
381
|
-
const otherStake = bnTotalStake.
|
|
399
|
+
const bnTotalStake = new BigN(validatorList[i].stake);
|
|
400
|
+
const bnOwnStake = new BigN(validatorList[i].validator_stake);
|
|
401
|
+
const otherStake = bnTotalStake.minus(bnOwnStake);
|
|
382
402
|
const nominatorCount = validatorList[i].nominators;
|
|
383
403
|
const commission = validatorList[i].take;
|
|
384
404
|
const roundedCommission = (parseFloat(commission) * 100).toFixed(0);
|
|
@@ -419,15 +439,18 @@ export default class SubnetTaoStakingPoolHandler extends BaseParaStakingPoolHand
|
|
|
419
439
|
async createJoinExtrinsic(data, positionInfo, bondDest = 'Staked') {
|
|
420
440
|
const {
|
|
421
441
|
amount,
|
|
422
|
-
|
|
423
|
-
|
|
442
|
+
selectedValidators: targetValidators,
|
|
443
|
+
subnetData
|
|
424
444
|
} = data;
|
|
445
|
+
const {
|
|
446
|
+
netuid,
|
|
447
|
+
slippage
|
|
448
|
+
} = subnetData;
|
|
425
449
|
const chainApi = await this.substrateApi.isReady;
|
|
426
|
-
const binaryAmount = new
|
|
427
|
-
const
|
|
428
|
-
const
|
|
429
|
-
const
|
|
430
|
-
const BNlimitPrice = new BN(limitPrice.integerValue(BigNumber.ROUND_CEIL).toFixed());
|
|
450
|
+
const binaryAmount = new BigN(amount);
|
|
451
|
+
const alphaToTaoPrice = new BigN(await getAlphaToTaoRate(this.substrateApi, netuid));
|
|
452
|
+
const limitPrice = alphaToTaoPrice.multipliedBy(10 ** _getAssetDecimals(this.nativeToken)).multipliedBy(1 + (slippage || DEFAULT_BITTENSOR_SLIPPAGE));
|
|
453
|
+
const BNlimitPrice = new BigN(limitPrice.integerValue(BigN.ROUND_CEIL).toFixed());
|
|
431
454
|
const selectedValidatorInfo = targetValidators[0];
|
|
432
455
|
const hotkey = selectedValidatorInfo.address;
|
|
433
456
|
const extrinsic = chainApi.api.tx.subtensorModule.addStakeLimit(hotkey, netuid, binaryAmount, BNlimitPrice, false);
|
|
@@ -444,7 +467,7 @@ export default class SubnetTaoStakingPoolHandler extends BaseParaStakingPoolHand
|
|
|
444
467
|
const {
|
|
445
468
|
amount
|
|
446
469
|
} = data;
|
|
447
|
-
if (new
|
|
470
|
+
if (new BigN(amount).lt(new BigN(DEFAULT_DTAO_MINBOND))) {
|
|
448
471
|
return [new TransactionError(BasicTxErrorType.INVALID_PARAMS, t(`Insufficient stake. You need to stake at least ${formatNumber(DEFAULT_DTAO_MINBOND, _getAssetDecimals(this.nativeToken))} ${_getAssetSymbol(this.nativeToken)} to earn rewards`))];
|
|
449
472
|
}
|
|
450
473
|
return baseErrors;
|
|
@@ -454,16 +477,15 @@ export default class SubnetTaoStakingPoolHandler extends BaseParaStakingPoolHand
|
|
|
454
477
|
|
|
455
478
|
/* Leave pool action */
|
|
456
479
|
|
|
457
|
-
async handleYieldUnstake(amount, address, selectedTarget, netuid) {
|
|
480
|
+
async handleYieldUnstake(amount, address, selectedTarget, netuid, slippage) {
|
|
458
481
|
const apiPromise = await this.substrateApi.isReady;
|
|
459
|
-
const binaryAmount = new BN(amount);
|
|
460
|
-
const price = await getAlphaToTaoMapping(this.substrateApi);
|
|
461
|
-
const alphaToTaoPrice = new BigN(price[netuid]);
|
|
462
|
-
const limitPrice = alphaToTaoPrice.multipliedBy(10 ** _getAssetDecimals(this.nativeToken)).multipliedBy(1 - DEFAULT_BITTENSOR_SLIPPAGE);
|
|
463
|
-
const BNlimitPrice = new BN(limitPrice.integerValue(BigNumber.ROUND_CEIL).toFixed());
|
|
464
482
|
if (!selectedTarget) {
|
|
465
483
|
return Promise.reject(new TransactionError(BasicTxErrorType.INVALID_PARAMS));
|
|
466
484
|
}
|
|
485
|
+
const binaryAmount = new BigN(amount);
|
|
486
|
+
const alphaToTaoPrice = new BigN(await getAlphaToTaoRate(this.substrateApi, netuid || 0));
|
|
487
|
+
const limitPrice = alphaToTaoPrice.multipliedBy(10 ** _getAssetDecimals(this.nativeToken)).multipliedBy(1 - (slippage || DEFAULT_BITTENSOR_SLIPPAGE));
|
|
488
|
+
const BNlimitPrice = new BigN(limitPrice.integerValue(BigN.ROUND_CEIL).toFixed());
|
|
467
489
|
const extrinsic = apiPromise.api.tx.subtensorModule.removeStakeLimit(selectedTarget, netuid, binaryAmount, BNlimitPrice, false);
|
|
468
490
|
return [ExtrinsicType.STAKING_UNBOND, extrinsic];
|
|
469
491
|
}
|
|
@@ -477,10 +499,9 @@ export default class SubnetTaoStakingPoolHandler extends BaseParaStakingPoolHand
|
|
|
477
499
|
return [new TransactionError(BasicTxErrorType.INVALID_PARAMS)];
|
|
478
500
|
}
|
|
479
501
|
const netuid = (_poolInfo$metadata$su = poolInfo.metadata.subnetData) === null || _poolInfo$metadata$su === void 0 ? void 0 : _poolInfo$metadata$su.netuid;
|
|
480
|
-
const
|
|
481
|
-
const minUnstake = new BigN(DEFAULT_DTAO_MINBOND).dividedBy(
|
|
482
|
-
|
|
483
|
-
const formattedMinUnstake = minUnstake.dividedBy(1000000).integerValue(BigNumber.ROUND_CEIL).dividedBy(1000);
|
|
502
|
+
const alphaToTaoPrice = new BigN(await getAlphaToTaoRate(this.substrateApi, netuid || 0));
|
|
503
|
+
const minUnstake = new BigN(DEFAULT_DTAO_MINBOND).dividedBy(alphaToTaoPrice);
|
|
504
|
+
const formattedMinUnstake = minUnstake.dividedBy(1000000).integerValue(BigN.ROUND_CEIL).dividedBy(1000);
|
|
484
505
|
if (new BigN(amount).lt(formattedMinUnstake.multipliedBy(10 ** _getAssetDecimals(this.nativeToken)))) {
|
|
485
506
|
var _poolInfo$metadata$su2;
|
|
486
507
|
return [new TransactionError(BasicTxErrorType.INVALID_PARAMS, t(`Amount too low. You need to unstake at least ${formattedMinUnstake.toString()} ${((_poolInfo$metadata$su2 = poolInfo.metadata.subnetData) === null || _poolInfo$metadata$su2 === void 0 ? void 0 : _poolInfo$metadata$su2.subnetSymbol) || ''}`))];
|
|
@@ -61,7 +61,7 @@ export class BittensorCache {
|
|
|
61
61
|
async fetchData() {
|
|
62
62
|
const apiKey = bittensorApiKey();
|
|
63
63
|
try {
|
|
64
|
-
const resp = await fetch('https://api.taostats.io/api/validator/latest/v1?limit=
|
|
64
|
+
const resp = await fetch('https://api.taostats.io/api/validator/latest/v1?limit=50', {
|
|
65
65
|
method: 'GET',
|
|
66
66
|
headers: {
|
|
67
67
|
'Content-Type': 'application/json',
|
|
@@ -173,8 +173,17 @@ export default class TaoNativeStakingPoolHandler extends BaseParaStakingPoolHand
|
|
|
173
173
|
const minDelegatorStake = (await substrateApi.api.query.subtensorModule.nominatorMinRequiredStake()).toPrimitive() || 0;
|
|
174
174
|
const maxValidatorPerNominator = (await substrateApi.api.query.subtensorModule.maxAllowedValidators(0)).toPrimitive();
|
|
175
175
|
const taoIn = (await substrateApi.api.query.subtensorModule.subnetTAO(0)).toPrimitive();
|
|
176
|
+
const _topValidator = await this.bittensorCache.get();
|
|
177
|
+
const validators = _topValidator.data;
|
|
178
|
+
let highestApr = validators[0];
|
|
179
|
+
for (let i = 1; i < validators.length; i++) {
|
|
180
|
+
if (parseFloat(validators[i].apr) > parseFloat(highestApr.apr)) {
|
|
181
|
+
highestApr = validators[i];
|
|
182
|
+
}
|
|
183
|
+
}
|
|
176
184
|
const bnTaoIn = new BN(taoIn);
|
|
177
185
|
const BNminDelegatorStake = new BigN(minDelegatorStake.toString());
|
|
186
|
+
const apr = this.chain === 'bittensor' ? Number(highestApr.apr) * 100 : 0;
|
|
178
187
|
const data = {
|
|
179
188
|
...this.baseInfo,
|
|
180
189
|
type: this.type,
|
|
@@ -196,7 +205,8 @@ export default class TaoNativeStakingPoolHandler extends BaseParaStakingPoolHand
|
|
|
196
205
|
eraTime: 24,
|
|
197
206
|
era: 0,
|
|
198
207
|
unstakingPeriod: 1.2,
|
|
199
|
-
tvl: bnTaoIn.toString()
|
|
208
|
+
tvl: bnTaoIn.toString(),
|
|
209
|
+
totalApy: apr
|
|
200
210
|
}
|
|
201
211
|
};
|
|
202
212
|
callback(data);
|