@subwallet/extension-base 1.0.1 → 1.0.2-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/background/KoniTypes.d.ts +10 -3
- package/background/KoniTypes.js +6 -0
- package/cjs/background/KoniTypes.js +8 -1
- package/cjs/constants/index.js +6 -3
- package/cjs/koni/api/dotsama/balance.js +11 -0
- package/cjs/koni/api/staking/bonding/amplitude.js +6 -2
- package/cjs/koni/api/staking/bonding/astar.js +40 -243
- package/cjs/koni/api/staking/bonding/index.js +4 -4
- package/cjs/koni/api/staking/bonding/paraChain.js +16 -10
- package/cjs/koni/api/staking/bonding/relayChain.js +62 -7
- package/cjs/koni/api/staking/bonding/utils.js +29 -3
- package/cjs/koni/api/xcm/index.js +0 -111
- package/cjs/koni/api/xcm/polkadotXcm.js +1 -1
- package/cjs/koni/api/xcm/xTokens.js +2 -4
- package/cjs/koni/background/cron.js +61 -62
- package/cjs/koni/background/handlers/Extension.js +143 -149
- package/cjs/koni/background/handlers/State.js +129 -91
- package/cjs/koni/background/handlers/Tabs.js +40 -38
- package/cjs/koni/background/subscription.js +48 -43
- package/cjs/packageInfo.js +1 -1
- package/cjs/page/index.js +5 -0
- package/cjs/services/chain-service/constants.js +1 -11
- package/cjs/services/chain-service/index.js +39 -5
- package/cjs/services/chain-service/utils.js +4 -0
- package/cjs/services/event-service/index.js +71 -0
- package/cjs/services/event-service/types.js +1 -0
- package/cjs/services/history-service/index.js +36 -17
- package/cjs/services/history-service/subsquid-multi-chain-history.js +7 -2
- package/cjs/services/keyring-service/index.js +101 -0
- package/cjs/services/migration-service/index.js +13 -10
- package/cjs/{koni/migration/scripts/RemoveWrongCrowdloan.js → services/migration-service/scripts/AutoEnableChainsTokens.js} +11 -6
- package/cjs/services/migration-service/scripts/MigrateNetworkSettings.js +39 -19
- package/cjs/services/migration-service/scripts/MigrateSettings.js +31 -0
- package/cjs/services/migration-service/scripts/MigrateTransactionHistory.js +72 -0
- package/cjs/services/migration-service/scripts/index.js +13 -4
- package/cjs/services/price-service/coingecko.js +16 -3
- package/cjs/services/price-service/index.js +15 -17
- package/cjs/services/request-service/constants.js +8 -2
- package/cjs/services/request-service/handler/AuthRequestHandler.js +39 -12
- package/cjs/services/request-service/index.js +3 -0
- package/cjs/services/storage-service/DatabaseService.js +1 -1
- package/cjs/services/storage-service/databases/index.js +1 -1
- package/cjs/services/storage-service/db-stores/BaseStoreWithAddressAndChain.js +2 -8
- package/cjs/services/storage-service/db-stores/Nft.js +4 -1
- package/cjs/services/storage-service/db-stores/Transaction.js +10 -7
- package/cjs/services/subscan-service/index.js +107 -0
- package/cjs/services/subscan-service/subscan-chain-map.js +74 -0
- package/cjs/services/subscan-service/types.js +1 -0
- package/cjs/services/transaction-service/index.js +45 -10
- package/cjs/services/transaction-service/utils.js +4 -6
- package/cjs/utils/address.js +9 -1
- package/cjs/utils/index.js +24 -13
- package/constants/index.d.ts +1 -0
- package/constants/index.js +1 -0
- package/koni/api/dotsama/balance.js +11 -0
- package/koni/api/staking/bonding/amplitude.d.ts +1 -1
- package/koni/api/staking/bonding/amplitude.js +8 -4
- package/koni/api/staking/bonding/astar.d.ts +2 -11
- package/koni/api/staking/bonding/astar.js +35 -229
- package/koni/api/staking/bonding/index.d.ts +1 -1
- package/koni/api/staking/bonding/index.js +4 -4
- package/koni/api/staking/bonding/paraChain.d.ts +1 -1
- package/koni/api/staking/bonding/paraChain.js +17 -11
- package/koni/api/staking/bonding/relayChain.d.ts +1 -1
- package/koni/api/staking/bonding/relayChain.js +63 -8
- package/koni/api/staking/bonding/utils.d.ts +13 -1
- package/koni/api/staking/bonding/utils.js +27 -3
- package/koni/api/xcm/index.js +1 -112
- package/koni/api/xcm/polkadotXcm.js +1 -1
- package/koni/api/xcm/xTokens.js +3 -5
- package/koni/background/cron.js +60 -60
- package/koni/background/handlers/Extension.js +71 -76
- package/koni/background/handlers/State.d.ts +16 -14
- package/koni/background/handlers/State.js +126 -91
- package/koni/background/handlers/Tabs.js +22 -19
- package/koni/background/subscription.d.ts +1 -1
- package/koni/background/subscription.js +49 -44
- package/package.json +56 -16
- package/packageInfo.js +1 -1
- package/page/index.d.ts +2 -0
- package/page/index.js +4 -0
- package/services/chain-service/constants.d.ts +0 -1
- package/services/chain-service/constants.js +0 -9
- package/services/chain-service/index.d.ts +6 -4
- package/services/chain-service/index.js +39 -7
- package/services/chain-service/utils.d.ts +1 -0
- package/services/chain-service/utils.js +3 -0
- package/services/event-service/index.d.ts +22 -0
- package/services/event-service/index.js +59 -0
- package/services/event-service/types.d.ts +32 -0
- package/services/event-service/types.js +1 -0
- package/services/history-service/index.d.ts +5 -3
- package/services/history-service/index.js +36 -17
- package/services/history-service/subsquid-multi-chain-history.js +7 -2
- package/services/keyring-service/index.d.ts +19 -0
- package/services/keyring-service/index.js +93 -0
- package/services/migration-service/index.js +11 -9
- package/services/migration-service/scripts/AutoEnableChainsTokens.d.ts +4 -0
- package/services/migration-service/scripts/AutoEnableChainsTokens.js +13 -0
- package/services/migration-service/scripts/MigrateNetworkSettings.js +37 -18
- package/services/migration-service/scripts/MigrateSettings.d.ts +4 -0
- package/services/migration-service/scripts/MigrateSettings.js +23 -0
- package/services/migration-service/scripts/MigrateTransactionHistory.d.ts +4 -0
- package/services/migration-service/scripts/MigrateTransactionHistory.js +64 -0
- package/services/migration-service/scripts/index.d.ts +1 -0
- package/services/migration-service/scripts/index.js +10 -3
- package/services/price-service/coingecko.js +16 -3
- package/services/price-service/index.d.ts +5 -3
- package/services/price-service/index.js +15 -17
- package/services/request-service/constants.d.ts +1 -0
- package/services/request-service/constants.js +6 -1
- package/services/request-service/handler/AuthRequestHandler.d.ts +8 -1
- package/services/request-service/handler/AuthRequestHandler.js +40 -13
- package/services/request-service/index.d.ts +7 -1
- package/services/request-service/index.js +3 -0
- package/services/storage-service/DatabaseService.js +1 -1
- package/services/storage-service/databases/index.js +1 -1
- package/services/storage-service/db-stores/BaseStoreWithAddressAndChain.d.ts +1 -1
- package/services/storage-service/db-stores/BaseStoreWithAddressAndChain.js +2 -8
- package/services/storage-service/db-stores/Nft.d.ts +2 -1
- package/services/storage-service/db-stores/Nft.js +4 -1
- package/services/storage-service/db-stores/Transaction.js +10 -7
- package/services/subscan-service/index.d.ts +20 -0
- package/services/subscan-service/index.js +99 -0
- package/services/subscan-service/subscan-chain-map.d.ts +5 -0
- package/services/subscan-service/subscan-chain-map.js +63 -0
- package/services/subscan-service/types.d.ts +27 -0
- package/services/subscan-service/types.js +1 -0
- package/services/transaction-service/event-parser/index.d.ts +2 -2
- package/services/transaction-service/index.d.ts +4 -2
- package/services/transaction-service/index.js +45 -10
- package/services/transaction-service/utils.js +5 -6
- package/utils/address.d.ts +1 -0
- package/utils/address.js +9 -2
- package/utils/index.d.ts +1 -0
- package/utils/index.js +21 -12
- package/cjs/background/errors/EvmRpcError.js +0 -21
- package/cjs/background/errors/SubWalletProviderError.js +0 -17
- package/cjs/constants/ethereum.js +0 -19
- package/cjs/errors/SubWalletProviderError.js +0 -17
- package/cjs/koni/api/xcm/astar.js +0 -160
- package/cjs/koni/api/xcm/moonbeamXcm.js +0 -80
- package/cjs/koni/api/xcm/statemintXcm.js +0 -197
- package/cjs/koni/api/xcm/substrateXcm.js +0 -213
- package/cjs/koni/migration/Base.js +0 -20
- package/cjs/koni/migration/index.js +0 -45
- package/cjs/koni/migration/scripts/ChangeRouteToHome.js +0 -22
- package/cjs/koni/migration/scripts/ClearOldStorage.js +0 -24
- package/cjs/koni/migration/scripts/RemoveWrongTransactionHistoriesFromStore.js +0 -36
- package/cjs/koni/migration/scripts/ResetTransactionHistoryEventIdx.js +0 -21
- package/cjs/koni/migration/scripts/index.js +0 -22
- package/cjs/koni/page/index.js +0 -16
- package/cjs/services/asset-service/index.js +0 -91
- package/cjs/services/storage-service/db-stores/ExtraDelegationInfo.js +0 -17
- package/cjs/stores/Balance.js +0 -18
- package/cjs/stores/Crowdloan.js +0 -18
- package/cjs/stores/CustomEvmToken.js +0 -18
- package/cjs/stores/NetworkMap.js +0 -18
- package/cjs/stores/Nft.js +0 -18
- package/cjs/stores/NftCollection.js +0 -18
- package/cjs/stores/Price.js +0 -18
- package/cjs/stores/Staking.js +0 -18
- package/cjs/stores/StakingReward.js +0 -18
- package/cjs/utils/eth/parseTransactionData.js +0 -284
- package/koni/page/index.d.ts +0 -2
- package/koni/page/index.js +0 -9
- /package/cjs/{koni/page → page}/SubWalleEvmProvider.js +0 -0
- /package/{koni/page → page}/SubWalleEvmProvider.d.ts +0 -0
- /package/{koni/page → page}/SubWalleEvmProvider.js +0 -0
|
@@ -103,7 +103,6 @@ export interface StakingItem {
|
|
|
103
103
|
nativeToken: string;
|
|
104
104
|
unit?: string;
|
|
105
105
|
state: APIItemState;
|
|
106
|
-
rewardInfo?: StakingRewardItem;
|
|
107
106
|
}
|
|
108
107
|
export interface StakingJson {
|
|
109
108
|
reset?: boolean;
|
|
@@ -379,14 +378,14 @@ export interface AmountData extends BasicTokenInfo {
|
|
|
379
378
|
}
|
|
380
379
|
export interface XCMTransactionAdditionalInfo {
|
|
381
380
|
destinationChain: string;
|
|
382
|
-
fee
|
|
381
|
+
fee?: AmountData;
|
|
383
382
|
}
|
|
384
383
|
export interface NFTTransactionAdditionalInfo {
|
|
385
384
|
collectionName: string;
|
|
386
385
|
}
|
|
387
386
|
export declare type TransactionAdditionalInfo<T extends ExtrinsicType> = T extends ExtrinsicType.TRANSFER_XCM ? XCMTransactionAdditionalInfo : T extends ExtrinsicType.SEND_NFT ? NFTTransactionAdditionalInfo : undefined;
|
|
388
387
|
export interface TransactionHistoryItem<ET extends ExtrinsicType = ExtrinsicType.TRANSFER_BALANCE> {
|
|
389
|
-
origin?:
|
|
388
|
+
origin?: 'app' | 'migration' | 'subsquid';
|
|
390
389
|
callhash?: string;
|
|
391
390
|
signature?: string;
|
|
392
391
|
chain: string;
|
|
@@ -1057,6 +1056,7 @@ export interface NominationInfo {
|
|
|
1057
1056
|
activeStake: string;
|
|
1058
1057
|
hasUnstaking?: boolean;
|
|
1059
1058
|
validatorMinStake?: string;
|
|
1059
|
+
status: StakingStatus;
|
|
1060
1060
|
}
|
|
1061
1061
|
export interface PalletNominationPoolsBondedPoolInner {
|
|
1062
1062
|
points: number;
|
|
@@ -1086,9 +1086,15 @@ export interface UnstakingInfo {
|
|
|
1086
1086
|
waitingTime: number;
|
|
1087
1087
|
validatorAddress?: string;
|
|
1088
1088
|
}
|
|
1089
|
+
export declare enum StakingStatus {
|
|
1090
|
+
EARNING_REWARD = "EARNING_REWARD",
|
|
1091
|
+
PARTIALLY_EARNING = "PARTIALLY_EARNING",
|
|
1092
|
+
NOT_EARNING = "NOT_EARNING"
|
|
1093
|
+
}
|
|
1089
1094
|
export interface NominatorMetadata {
|
|
1090
1095
|
chain: string;
|
|
1091
1096
|
type: StakingType;
|
|
1097
|
+
status: StakingStatus;
|
|
1092
1098
|
address: string;
|
|
1093
1099
|
activeStake: string;
|
|
1094
1100
|
nominations: NominationInfo[];
|
|
@@ -1138,6 +1144,7 @@ export interface BondingSubmitParams extends BaseRequestSign {
|
|
|
1138
1144
|
type: StakingType;
|
|
1139
1145
|
nominatorMetadata?: NominatorMetadata;
|
|
1140
1146
|
amount: string;
|
|
1147
|
+
address: string;
|
|
1141
1148
|
selectedValidators: ValidatorInfo[];
|
|
1142
1149
|
lockPeriod?: number;
|
|
1143
1150
|
}
|
package/background/KoniTypes.js
CHANGED
|
@@ -204,6 +204,12 @@ export let UnstakingStatus;
|
|
|
204
204
|
UnstakingStatus["CLAIMABLE"] = "CLAIMABLE";
|
|
205
205
|
UnstakingStatus["UNLOCKING"] = "UNLOCKING";
|
|
206
206
|
})(UnstakingStatus || (UnstakingStatus = {}));
|
|
207
|
+
export let StakingStatus;
|
|
208
|
+
(function (StakingStatus) {
|
|
209
|
+
StakingStatus["EARNING_REWARD"] = "EARNING_REWARD";
|
|
210
|
+
StakingStatus["PARTIALLY_EARNING"] = "PARTIALLY_EARNING";
|
|
211
|
+
StakingStatus["NOT_EARNING"] = "NOT_EARNING";
|
|
212
|
+
})(StakingStatus || (StakingStatus = {}));
|
|
207
213
|
export let ChainEditStandard;
|
|
208
214
|
|
|
209
215
|
// ChainService
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.UnstakingStatus = exports.TransferTxErrorType = exports.TransactionDirection = exports.ThemeNames = exports.StakingType = exports.StakingTxErrorType = exports.RMRK_VER = exports.ProviderErrorType = exports.NotificationType = exports.NETWORK_STATUS = exports.NETWORK_ERROR = exports.ExtrinsicType = exports.ExtrinsicStatus = exports.ExternalRequestPromiseStatus = exports.EvmProviderErrorType = exports.CrowdloanParaState = exports.ContractType = exports.ChainType = exports.ChainEditStandard = exports.BasicTxWarningCode = exports.BasicTxErrorType = exports.BalanceErrorType = exports.AccountExternalErrorCode = exports.APIItemState = void 0;
|
|
6
|
+
exports.UnstakingStatus = exports.TransferTxErrorType = exports.TransactionDirection = exports.ThemeNames = exports.StakingType = exports.StakingTxErrorType = exports.StakingStatus = exports.RMRK_VER = exports.ProviderErrorType = exports.NotificationType = exports.NETWORK_STATUS = exports.NETWORK_ERROR = exports.ExtrinsicType = exports.ExtrinsicStatus = exports.ExternalRequestPromiseStatus = exports.EvmProviderErrorType = exports.CrowdloanParaState = exports.ContractType = exports.ChainType = exports.ChainEditStandard = exports.BasicTxWarningCode = exports.BasicTxErrorType = exports.BalanceErrorType = exports.AccountExternalErrorCode = exports.APIItemState = void 0;
|
|
7
7
|
// Copyright 2019-2022 @polkadot/extension-koni authors & contributors
|
|
8
8
|
// SPDX-License-Identifier: Apache-2.0
|
|
9
9
|
/// Request Auth
|
|
@@ -211,6 +211,13 @@ exports.UnstakingStatus = UnstakingStatus;
|
|
|
211
211
|
UnstakingStatus["CLAIMABLE"] = "CLAIMABLE";
|
|
212
212
|
UnstakingStatus["UNLOCKING"] = "UNLOCKING";
|
|
213
213
|
})(UnstakingStatus || (exports.UnstakingStatus = UnstakingStatus = {}));
|
|
214
|
+
let StakingStatus;
|
|
215
|
+
exports.StakingStatus = StakingStatus;
|
|
216
|
+
(function (StakingStatus) {
|
|
217
|
+
StakingStatus["EARNING_REWARD"] = "EARNING_REWARD";
|
|
218
|
+
StakingStatus["PARTIALLY_EARNING"] = "PARTIALLY_EARNING";
|
|
219
|
+
StakingStatus["NOT_EARNING"] = "NOT_EARNING";
|
|
220
|
+
})(StakingStatus || (exports.StakingStatus = StakingStatus = {}));
|
|
214
221
|
let ChainEditStandard; // ChainService
|
|
215
222
|
// for custom network
|
|
216
223
|
exports.ChainEditStandard = ChainEditStandard;
|
package/cjs/constants/index.js
CHANGED
|
@@ -27,9 +27,10 @@ var _exportNames = {
|
|
|
27
27
|
ALL_NETWORK_KEY: true,
|
|
28
28
|
ALL_GENESIS_HASH: true,
|
|
29
29
|
IGNORE_GET_SUBSTRATE_FEATURES_LIST: true,
|
|
30
|
-
IGNORE_QR_SIGNER: true
|
|
30
|
+
IGNORE_QR_SIGNER: true,
|
|
31
|
+
DEFAULT_TIME_AUTO_LOCK: true
|
|
31
32
|
};
|
|
32
|
-
exports.SUB_TOKEN_REFRESH_BALANCE_INTERVAL = exports.SUBSCRIBE_BALANCE_FAST_INTERVAL = exports.IGNORE_QR_SIGNER = exports.IGNORE_GET_SUBSTRATE_FEATURES_LIST = exports.DOTSAMA_MAX_CONTINUE_RETRY = exports.DOTSAMA_AUTO_CONNECT_MS = exports.DOTSAMA_API_TIMEOUT = exports.CRON_REFRESH_STAKING_REWARD_INTERVAL = exports.CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL = exports.CRON_REFRESH_STAKING_DATA = exports.CRON_REFRESH_PRICE_INTERVAL = exports.CRON_REFRESH_NFT_INTERVAL = exports.CRON_REFRESH_HISTORY_INTERVAL = exports.CRON_REFRESH_CHAIN_STAKING_METADATA = exports.CRON_REFRESH_CHAIN_NOMINATOR_METADATA = exports.CRON_GET_API_MAP_STATUS = exports.CRON_AUTO_RECOVER_WEB3_INTERVAL = exports.CRON_AUTO_RECOVER_DOTSAMA_INTERVAL = exports.ASTAR_REFRESH_BALANCE_INTERVAL = exports.ALL_NETWORK_KEY = exports.ALL_GENESIS_HASH = exports.ALL_ACCOUNT_KEY = exports.ACALA_REFRESH_CROWDLOAN_INTERVAL = exports.ACALA_REFRESH_BALANCE_INTERVAL = void 0;
|
|
33
|
+
exports.SUB_TOKEN_REFRESH_BALANCE_INTERVAL = exports.SUBSCRIBE_BALANCE_FAST_INTERVAL = exports.IGNORE_QR_SIGNER = exports.IGNORE_GET_SUBSTRATE_FEATURES_LIST = exports.DOTSAMA_MAX_CONTINUE_RETRY = exports.DOTSAMA_AUTO_CONNECT_MS = exports.DOTSAMA_API_TIMEOUT = exports.DEFAULT_TIME_AUTO_LOCK = exports.CRON_REFRESH_STAKING_REWARD_INTERVAL = exports.CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL = exports.CRON_REFRESH_STAKING_DATA = exports.CRON_REFRESH_PRICE_INTERVAL = exports.CRON_REFRESH_NFT_INTERVAL = exports.CRON_REFRESH_HISTORY_INTERVAL = exports.CRON_REFRESH_CHAIN_STAKING_METADATA = exports.CRON_REFRESH_CHAIN_NOMINATOR_METADATA = exports.CRON_GET_API_MAP_STATUS = exports.CRON_AUTO_RECOVER_WEB3_INTERVAL = exports.CRON_AUTO_RECOVER_DOTSAMA_INTERVAL = exports.ASTAR_REFRESH_BALANCE_INTERVAL = exports.ALL_NETWORK_KEY = exports.ALL_GENESIS_HASH = exports.ALL_ACCOUNT_KEY = exports.ACALA_REFRESH_CROWDLOAN_INTERVAL = exports.ACALA_REFRESH_BALANCE_INTERVAL = void 0;
|
|
33
34
|
var _staking = require("./staking");
|
|
34
35
|
Object.keys(_staking).forEach(function (key) {
|
|
35
36
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -92,4 +93,6 @@ exports.ALL_GENESIS_HASH = ALL_GENESIS_HASH;
|
|
|
92
93
|
const IGNORE_GET_SUBSTRATE_FEATURES_LIST = ['astarEvm', 'ethereum', 'ethereum_goerli', 'binance', 'binance_test', 'boba_rinkeby', 'boba', 'bobabase', 'bobabeam'];
|
|
93
94
|
exports.IGNORE_GET_SUBSTRATE_FEATURES_LIST = IGNORE_GET_SUBSTRATE_FEATURES_LIST;
|
|
94
95
|
const IGNORE_QR_SIGNER = [];
|
|
95
|
-
exports.IGNORE_QR_SIGNER = IGNORE_QR_SIGNER;
|
|
96
|
+
exports.IGNORE_QR_SIGNER = IGNORE_QR_SIGNER;
|
|
97
|
+
const DEFAULT_TIME_AUTO_LOCK = 15 * 60 * 1000;
|
|
98
|
+
exports.DEFAULT_TIME_AUTO_LOCK = DEFAULT_TIME_AUTO_LOCK;
|
|
@@ -35,6 +35,17 @@ function subscribeBalance(addresses, chainInfoMap, substrateApiMap, evmApiMap, c
|
|
|
35
35
|
return subscribeEVMBalance(chainSlug, useAddresses, evmApiMap, callback, nativeTokenInfo);
|
|
36
36
|
}
|
|
37
37
|
if (!useAddresses || useAddresses.length === 0 || _constants2._PURE_EVM_CHAINS.indexOf(chainSlug) > -1) {
|
|
38
|
+
const fungibleTokensByChain = _handlers.state.chainService.getFungibleTokensByChain(chainSlug, true);
|
|
39
|
+
const now = new Date().getTime();
|
|
40
|
+
Object.values(fungibleTokensByChain).map(token => {
|
|
41
|
+
return {
|
|
42
|
+
tokenSlug: token.slug,
|
|
43
|
+
free: '0',
|
|
44
|
+
locked: '0',
|
|
45
|
+
state: _KoniTypes.APIItemState.READY,
|
|
46
|
+
timestamp: now
|
|
47
|
+
};
|
|
48
|
+
}).forEach(callback);
|
|
38
49
|
return undefined;
|
|
39
50
|
}
|
|
40
51
|
const networkAPI = await substrateApiMap[chainSlug].isReady;
|
|
@@ -64,6 +64,7 @@ async function getAmplitudeNominatorMetadata(chainInfo, address, substrateApi) {
|
|
|
64
64
|
const identity = (0, _utils.parseIdentity)(identityInfo);
|
|
65
65
|
activeStake = delegatorState.amount.toString();
|
|
66
66
|
nominationList.push({
|
|
67
|
+
status: _KoniTypes.StakingStatus.NOT_EARNING,
|
|
67
68
|
chain,
|
|
68
69
|
validatorAddress: delegatorState.owner,
|
|
69
70
|
activeStake: delegatorState.amount.toString(),
|
|
@@ -134,13 +135,16 @@ async function getAmplitudeCollatorsInfo(chain, substrateApi) {
|
|
|
134
135
|
}
|
|
135
136
|
return allCollators;
|
|
136
137
|
}
|
|
137
|
-
async function getAmplitudeBondingExtrinsic(
|
|
138
|
+
async function getAmplitudeBondingExtrinsic(substrateApi, amount, selectedValidatorInfo, nominatorMetadata) {
|
|
138
139
|
const chainApi = await substrateApi.isReady;
|
|
139
140
|
const binaryAmount = new _util.BN(amount);
|
|
141
|
+
if (!nominatorMetadata) {
|
|
142
|
+
return chainApi.api.tx.parachainStaking.joinDelegators(selectedValidatorInfo.address, binaryAmount);
|
|
143
|
+
}
|
|
140
144
|
const {
|
|
141
145
|
bondedValidators
|
|
142
146
|
} = (0, _utils.getBondedValidators)(nominatorMetadata.nominations);
|
|
143
|
-
if (!bondedValidators.includes(selectedValidatorInfo.address)) {
|
|
147
|
+
if (!bondedValidators.includes((0, _utils2.reformatAddress)(selectedValidatorInfo.address, 0))) {
|
|
144
148
|
return chainApi.api.tx.parachainStaking.joinDelegators(selectedValidatorInfo.address, binaryAmount);
|
|
145
149
|
} else {
|
|
146
150
|
const _params = chainApi.api.tx.parachainStaking.delegatorStakeMore.toJSON();
|
|
@@ -5,26 +5,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.getAstarBondingExtrinsic = getAstarBondingExtrinsic;
|
|
8
|
-
exports.getAstarBondingTxInfo = getAstarBondingTxInfo;
|
|
9
8
|
exports.getAstarClaimRewardExtrinsic = getAstarClaimRewardExtrinsic;
|
|
10
|
-
exports.getAstarClaimRewardTxInfo = getAstarClaimRewardTxInfo;
|
|
11
9
|
exports.getAstarDappsInfo = getAstarDappsInfo;
|
|
12
10
|
exports.getAstarNominatorMetadata = getAstarNominatorMetadata;
|
|
13
11
|
exports.getAstarStakingMetadata = getAstarStakingMetadata;
|
|
14
12
|
exports.getAstarUnbondingExtrinsic = getAstarUnbondingExtrinsic;
|
|
15
|
-
exports.getAstarUnbondingTxInfo = getAstarUnbondingTxInfo;
|
|
16
13
|
exports.getAstarWithdrawalExtrinsic = getAstarWithdrawalExtrinsic;
|
|
17
|
-
exports.getAstarWithdrawalTxInfo = getAstarWithdrawalTxInfo;
|
|
18
|
-
exports.handleAstarBondingTxInfo = handleAstarBondingTxInfo;
|
|
19
|
-
exports.handleAstarClaimRewardTxInfo = handleAstarClaimRewardTxInfo;
|
|
20
|
-
exports.handleAstarUnbondingTxInfo = handleAstarUnbondingTxInfo;
|
|
21
|
-
exports.handleAstarUnlockingInfo = handleAstarUnlockingInfo;
|
|
22
|
-
exports.handleAstarWithdrawalTxInfo = handleAstarWithdrawalTxInfo;
|
|
23
14
|
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
24
|
-
var _balance = require("@subwallet/extension-base/koni/api/dotsama/balance");
|
|
25
15
|
var _constants = require("@subwallet/extension-base/services/chain-service/constants");
|
|
26
|
-
var _utils = require("@subwallet/extension-base/
|
|
27
|
-
var _utils2 = require("@subwallet/extension-base/utils");
|
|
16
|
+
var _utils = require("@subwallet/extension-base/utils");
|
|
28
17
|
var _crossFetch = _interopRequireDefault(require("cross-fetch"));
|
|
29
18
|
var _util = require("@polkadot/util");
|
|
30
19
|
var _utilCrypto = require("@polkadot/util-crypto");
|
|
@@ -103,6 +92,8 @@ async function getAstarNominatorMetadata(chainInfo, address, substrateApi) {
|
|
|
103
92
|
bnTotalActiveStake = bnTotalActiveStake.add(bnCurrentStake);
|
|
104
93
|
const dappInfo = dAppInfoMap[dappAddress];
|
|
105
94
|
nominationList.push({
|
|
95
|
+
status: _KoniTypes.StakingStatus.NOT_EARNING,
|
|
96
|
+
// TODO
|
|
106
97
|
chain,
|
|
107
98
|
validatorAddress: dappAddress,
|
|
108
99
|
activeStake: currentStake,
|
|
@@ -137,14 +128,16 @@ async function getAstarNominatorMetadata(chainInfo, address, substrateApi) {
|
|
|
137
128
|
address: address,
|
|
138
129
|
activeStake: bnTotalActiveStake.toString(),
|
|
139
130
|
nominations: nominationList,
|
|
140
|
-
unstakings: unstakingList
|
|
131
|
+
unstakings: unstakingList,
|
|
132
|
+
status: _KoniTypes.StakingStatus.NOT_EARNING // TODO
|
|
141
133
|
};
|
|
142
134
|
}
|
|
135
|
+
|
|
143
136
|
async function getAstarDappsInfo(networkKey, substrateApi) {
|
|
144
137
|
const chainApi = await substrateApi.isReady;
|
|
145
138
|
const rawMaxStakerPerContract = chainApi.api.consts.dappsStaking.maxNumberOfStakersPerContract.toHuman();
|
|
146
139
|
const allDappsInfo = [];
|
|
147
|
-
const maxStakerPerContract = (0,
|
|
140
|
+
const maxStakerPerContract = (0, _utils.parseRawNumber)(rawMaxStakerPerContract);
|
|
148
141
|
const allDappsReq = new Promise(function (resolve) {
|
|
149
142
|
(0, _crossFetch.default)(`https://api.astar.network/api/v1/${networkKey}/dapps-staking/dapps`, {
|
|
150
143
|
method: 'GET'
|
|
@@ -153,27 +146,32 @@ async function getAstarDappsInfo(networkKey, substrateApi) {
|
|
|
153
146
|
}).catch(console.error);
|
|
154
147
|
});
|
|
155
148
|
const [_era, _allDapps] = await Promise.all([chainApi.api.query.dappsStaking.currentEra(), allDappsReq]);
|
|
156
|
-
const era = (0,
|
|
149
|
+
const era = (0, _utils.parseRawNumber)(_era.toHuman());
|
|
157
150
|
const allDapps = _allDapps;
|
|
158
151
|
await Promise.all(allDapps.map(async dapp => {
|
|
159
152
|
const dappName = dapp.name;
|
|
160
153
|
const dappAddress = dapp.address;
|
|
161
|
-
const dappIcon = (0,
|
|
162
|
-
const
|
|
154
|
+
const dappIcon = (0, _utils.isUrl)(dapp.iconUrl) ? dapp.iconUrl : undefined;
|
|
155
|
+
const contractParam = (0, _utilCrypto.isEthereumAddress)(dappAddress) ? {
|
|
163
156
|
Evm: dappAddress
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
157
|
+
} : {
|
|
158
|
+
Wasm: dappAddress
|
|
159
|
+
};
|
|
160
|
+
const _contractInfo = await chainApi.api.query.dappsStaking.contractEraStake(contractParam, era);
|
|
161
|
+
const contractInfo = _contractInfo.toPrimitive();
|
|
162
|
+
let totalStake = '0';
|
|
167
163
|
let stakerCount = 0;
|
|
168
164
|
if (contractInfo !== null) {
|
|
169
|
-
|
|
170
|
-
|
|
165
|
+
var _contractInfo$total;
|
|
166
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
|
167
|
+
totalStake = contractInfo === null || contractInfo === void 0 ? void 0 : (_contractInfo$total = contractInfo.total) === null || _contractInfo$total === void 0 ? void 0 : _contractInfo$total.toString();
|
|
168
|
+
stakerCount = contractInfo.numberOfStakers;
|
|
171
169
|
}
|
|
172
170
|
allDappsInfo.push({
|
|
173
171
|
commission: 0,
|
|
174
172
|
expectedReturn: 0,
|
|
175
173
|
address: dappAddress,
|
|
176
|
-
totalStake: totalStake
|
|
174
|
+
totalStake: totalStake,
|
|
177
175
|
ownStake: '0',
|
|
178
176
|
otherStake: totalStake.toString(),
|
|
179
177
|
nominatorCount: stakerCount,
|
|
@@ -188,175 +186,34 @@ async function getAstarDappsInfo(networkKey, substrateApi) {
|
|
|
188
186
|
}));
|
|
189
187
|
return allDappsInfo;
|
|
190
188
|
}
|
|
191
|
-
async function getAstarBondingTxInfo(chainInfo, substrateApi, stakerAddress, amount, dappInfo) {
|
|
192
|
-
const apiPromise = await substrateApi.isReady;
|
|
193
|
-
const {
|
|
194
|
-
decimals
|
|
195
|
-
} = (0, _utils._getChainNativeTokenBasicInfo)(chainInfo);
|
|
196
|
-
const parsedAmount = amount * 10 ** decimals;
|
|
197
|
-
const binaryAmount = new _util.BN(parsedAmount.toString());
|
|
198
|
-
const extrinsic = apiPromise.api.tx.dappsStaking.bondAndStake({
|
|
199
|
-
Evm: dappInfo.address
|
|
200
|
-
}, binaryAmount);
|
|
201
|
-
return extrinsic.paymentInfo(stakerAddress);
|
|
202
|
-
}
|
|
203
|
-
async function handleAstarBondingTxInfo(chainInfo, amount, networkKey, stakerAddress, dappInfo, substrateApiMap, evmApiMap) {
|
|
204
|
-
const {
|
|
205
|
-
decimals,
|
|
206
|
-
symbol
|
|
207
|
-
} = (0, _utils._getChainNativeTokenBasicInfo)(chainInfo);
|
|
208
|
-
try {
|
|
209
|
-
const [txInfo, balance] = await Promise.all([getAstarBondingTxInfo(chainInfo, substrateApiMap[networkKey], stakerAddress, amount, dappInfo), (0, _balance.getFreeBalance)(networkKey, stakerAddress, substrateApiMap, evmApiMap)]);
|
|
210
|
-
const feeString = (0, _utils2.parseNumberToDisplay)(txInfo.partialFee, decimals) + ` ${symbol}`;
|
|
211
|
-
const rawFee = (0, _utils2.parseRawNumber)(txInfo.partialFee.toString());
|
|
212
|
-
const binaryBalance = new _util.BN(balance);
|
|
213
|
-
const sumAmount = txInfo.partialFee.addn(amount);
|
|
214
|
-
const balanceError = sumAmount.gt(binaryBalance);
|
|
215
|
-
return {
|
|
216
|
-
rawFee,
|
|
217
|
-
fee: feeString,
|
|
218
|
-
balanceError
|
|
219
|
-
};
|
|
220
|
-
} catch (e) {
|
|
221
|
-
return {
|
|
222
|
-
fee: `0.0000 ${symbol}`,
|
|
223
|
-
balanceError: false
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
189
|
async function getAstarBondingExtrinsic(substrateApi, amount, dappInfo) {
|
|
228
190
|
const chainApi = await substrateApi.isReady;
|
|
229
191
|
const binaryAmount = new _util.BN(amount);
|
|
230
|
-
|
|
192
|
+
const dappParam = (0, _utilCrypto.isEthereumAddress)(dappInfo.address) ? {
|
|
231
193
|
Evm: dappInfo.address
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
const {
|
|
237
|
-
decimals
|
|
238
|
-
} = (0, _utils._getChainNativeTokenBasicInfo)(chainInfo);
|
|
239
|
-
const parsedAmount = amount * 10 ** decimals;
|
|
240
|
-
const binaryAmount = new _util.BN(parsedAmount.toString());
|
|
241
|
-
const extrinsic = apiPromise.api.tx.dappsStaking.unbondAndUnstake({
|
|
242
|
-
Evm: dappAddress
|
|
243
|
-
}, binaryAmount);
|
|
244
|
-
return extrinsic.paymentInfo(stakerAddress);
|
|
245
|
-
}
|
|
246
|
-
async function handleAstarUnbondingTxInfo(chainInfo, amount, networkKey, stakerAddress, dappAddress, substrateApiMap, evmApiMap) {
|
|
247
|
-
const {
|
|
248
|
-
decimals,
|
|
249
|
-
symbol
|
|
250
|
-
} = (0, _utils._getChainNativeTokenBasicInfo)(chainInfo);
|
|
251
|
-
try {
|
|
252
|
-
const [txInfo, balance] = await Promise.all([getAstarUnbondingTxInfo(chainInfo, substrateApiMap[networkKey], stakerAddress, amount, dappAddress), (0, _balance.getFreeBalance)(networkKey, stakerAddress, substrateApiMap, evmApiMap)]);
|
|
253
|
-
const feeString = (0, _utils2.parseNumberToDisplay)(txInfo.partialFee, decimals) + ` ${symbol}`;
|
|
254
|
-
const rawFee = (0, _utils2.parseRawNumber)(txInfo.partialFee.toString());
|
|
255
|
-
const binaryBalance = new _util.BN(balance);
|
|
256
|
-
const balanceError = txInfo.partialFee.gt(binaryBalance);
|
|
257
|
-
return {
|
|
258
|
-
rawFee,
|
|
259
|
-
fee: feeString,
|
|
260
|
-
balanceError
|
|
261
|
-
};
|
|
262
|
-
} catch (e) {
|
|
263
|
-
return {
|
|
264
|
-
fee: `0.0000 ${symbol}`,
|
|
265
|
-
balanceError: false
|
|
266
|
-
};
|
|
267
|
-
}
|
|
194
|
+
} : {
|
|
195
|
+
Wasm: dappInfo.address
|
|
196
|
+
};
|
|
197
|
+
return chainApi.api.tx.dappsStaking.bondAndStake(dappParam, binaryAmount);
|
|
268
198
|
}
|
|
269
199
|
async function getAstarUnbondingExtrinsic(substrateApi, amount, dappAddress) {
|
|
270
200
|
const apiPromise = await substrateApi.isReady;
|
|
271
201
|
const binaryAmount = new _util.BN(amount);
|
|
272
|
-
|
|
202
|
+
const dappParam = (0, _utilCrypto.isEthereumAddress)(dappAddress) ? {
|
|
273
203
|
Evm: dappAddress
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
async function getAstarUnlockingInfo(substrateApi, address, networkKey) {
|
|
277
|
-
const chainApi = await substrateApi.isReady;
|
|
278
|
-
const [_stakingInfo, _era] = await Promise.all([chainApi.api.query.dappsStaking.ledger(address), chainApi.api.query.dappsStaking.currentEra()]);
|
|
279
|
-
const currentEra = (0, _utils2.parseRawNumber)(_era.toHuman());
|
|
280
|
-
const stakingInfo = _stakingInfo.toHuman();
|
|
281
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
282
|
-
const unlockingChunks = stakingInfo.unbondingInfo.unlockingChunks;
|
|
283
|
-
let nextWithdrawalEra = -1;
|
|
284
|
-
let nextWithdrawalAmount = 0;
|
|
285
|
-
let redeemable = 0;
|
|
286
|
-
for (const chunk of unlockingChunks) {
|
|
287
|
-
const unlockEra = (0, _utils2.parseRawNumber)(chunk.unlockEra);
|
|
288
|
-
const amount = (0, _utils2.parseRawNumber)(chunk.amount);
|
|
289
|
-
|
|
290
|
-
// Find next withdrawal
|
|
291
|
-
if (nextWithdrawalEra === -1) {
|
|
292
|
-
nextWithdrawalEra = unlockEra;
|
|
293
|
-
nextWithdrawalAmount = amount;
|
|
294
|
-
} else if (unlockEra <= nextWithdrawalEra) {
|
|
295
|
-
nextWithdrawalEra = unlockEra;
|
|
296
|
-
nextWithdrawalAmount += amount;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
// Find redeemable
|
|
300
|
-
if (unlockEra - currentEra <= 0) {
|
|
301
|
-
redeemable += amount;
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
const nextWithdrawal = (nextWithdrawalEra - currentEra) * _constants._STAKING_ERA_LENGTH_MAP[networkKey];
|
|
305
|
-
return {
|
|
306
|
-
nextWithdrawal,
|
|
307
|
-
nextWithdrawalAmount,
|
|
308
|
-
redeemable
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
async function handleAstarUnlockingInfo(substrateApi, chainInfo, networkKey, address, type) {
|
|
312
|
-
const {
|
|
313
|
-
nextWithdrawal,
|
|
314
|
-
nextWithdrawalAmount,
|
|
315
|
-
redeemable
|
|
316
|
-
} = await getAstarUnlockingInfo(substrateApi, address, networkKey);
|
|
317
|
-
const {
|
|
318
|
-
decimals
|
|
319
|
-
} = (0, _utils._getChainNativeTokenBasicInfo)(chainInfo);
|
|
320
|
-
const parsedRedeemable = redeemable / 10 ** decimals;
|
|
321
|
-
const parsedNextWithdrawalAmount = nextWithdrawalAmount / 10 ** decimals;
|
|
322
|
-
return {
|
|
323
|
-
address,
|
|
324
|
-
type,
|
|
325
|
-
chain: networkKey,
|
|
326
|
-
nextWithdrawal: nextWithdrawal,
|
|
327
|
-
redeemable: parsedRedeemable,
|
|
328
|
-
nextWithdrawalAmount: parsedNextWithdrawalAmount
|
|
329
|
-
};
|
|
330
|
-
}
|
|
331
|
-
async function getAstarWithdrawalTxInfo(substrateApi, address) {
|
|
332
|
-
const apiPromise = await substrateApi.isReady;
|
|
333
|
-
const extrinsic = apiPromise.api.tx.dappsStaking.withdrawUnbonded();
|
|
334
|
-
return extrinsic.paymentInfo(address);
|
|
335
|
-
}
|
|
336
|
-
async function handleAstarWithdrawalTxInfo(networkKey, chainInfo, substrateApiMap, evmApiMap, address) {
|
|
337
|
-
const [txInfo, balance] = await Promise.all([getAstarWithdrawalTxInfo(substrateApiMap[networkKey], address), (0, _balance.getFreeBalance)(networkKey, address, substrateApiMap, evmApiMap)]);
|
|
338
|
-
const {
|
|
339
|
-
decimals,
|
|
340
|
-
symbol
|
|
341
|
-
} = (0, _utils._getChainNativeTokenBasicInfo)(chainInfo);
|
|
342
|
-
const feeString = (0, _utils2.parseNumberToDisplay)(txInfo.partialFee, decimals) + ` ${symbol}`;
|
|
343
|
-
const rawFee = (0, _utils2.parseRawNumber)(txInfo.partialFee.toString());
|
|
344
|
-
const binaryBalance = new _util.BN(balance);
|
|
345
|
-
const balanceError = txInfo.partialFee.gt(binaryBalance);
|
|
346
|
-
return {
|
|
347
|
-
rawFee,
|
|
348
|
-
fee: feeString,
|
|
349
|
-
balanceError
|
|
204
|
+
} : {
|
|
205
|
+
Wasm: dappAddress
|
|
350
206
|
};
|
|
207
|
+
return apiPromise.api.tx.dappsStaking.unbondAndUnstake(dappParam, binaryAmount);
|
|
351
208
|
}
|
|
352
209
|
async function getAstarWithdrawalExtrinsic(substrateApi) {
|
|
353
210
|
const chainApi = await substrateApi.isReady;
|
|
354
211
|
return chainApi.api.tx.dappsStaking.withdrawUnbonded();
|
|
355
212
|
}
|
|
356
|
-
async function
|
|
213
|
+
async function getAstarClaimRewardExtrinsic(substrateApi, address) {
|
|
357
214
|
const apiPromise = await substrateApi.isReady;
|
|
358
215
|
const [_stakedDapps, _currentEra] = await Promise.all([apiPromise.api.query.dappsStaking.generalStakerInfo.entries(address), apiPromise.api.query.dappsStaking.currentEra()]);
|
|
359
|
-
const currentEra = (0,
|
|
216
|
+
const currentEra = (0, _utils.parseRawNumber)(_currentEra.toHuman());
|
|
360
217
|
const transactions = [];
|
|
361
218
|
for (const item of _stakedDapps) {
|
|
362
219
|
const data = item[0].toHuman();
|
|
@@ -365,6 +222,7 @@ async function getAstarClaimRewardTxInfo(substrateApi, address) {
|
|
|
365
222
|
const stakes = stakeData.stakes;
|
|
366
223
|
const dappAddress = stakedDapp.Evm.toLowerCase();
|
|
367
224
|
let numberOfUnclaimedEra = 0;
|
|
225
|
+
const maxTx = 50;
|
|
368
226
|
for (let i = 0; i < stakes.length; i++) {
|
|
369
227
|
var _stakes;
|
|
370
228
|
const {
|
|
@@ -372,84 +230,23 @@ async function getAstarClaimRewardTxInfo(substrateApi, address) {
|
|
|
372
230
|
staked
|
|
373
231
|
} = stakes[i];
|
|
374
232
|
const bnStaked = new _util.BN(staked.replaceAll(',', ''));
|
|
375
|
-
const parsedEra = (0,
|
|
233
|
+
const parsedEra = (0, _utils.parseRawNumber)(era);
|
|
376
234
|
if (bnStaked.eq(new _util.BN(0))) {
|
|
377
235
|
continue;
|
|
378
236
|
}
|
|
379
237
|
const nextEraData = (_stakes = stakes[i + 1]) !== null && _stakes !== void 0 ? _stakes : null;
|
|
380
|
-
const nextEra = nextEraData && (0,
|
|
238
|
+
const nextEra = nextEraData && (0, _utils.parseRawNumber)(nextEraData.era);
|
|
381
239
|
const isLastEra = i === stakes.length - 1;
|
|
382
240
|
const eraToClaim = isLastEra ? currentEra - parsedEra : nextEra - parsedEra;
|
|
383
241
|
numberOfUnclaimedEra += eraToClaim;
|
|
384
242
|
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
transactions.push(tx);
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
console.log('no of tx: ', transactions.length);
|
|
393
|
-
const extrinsic = apiPromise.api.tx.utility.batch(transactions);
|
|
394
|
-
return extrinsic.paymentInfo(address);
|
|
395
|
-
}
|
|
396
|
-
async function handleAstarClaimRewardTxInfo(address, networkKey, chainInfo, substrateApiMap, evmApiMap) {
|
|
397
|
-
const {
|
|
398
|
-
decimals,
|
|
399
|
-
symbol
|
|
400
|
-
} = (0, _utils._getChainNativeTokenBasicInfo)(chainInfo);
|
|
401
|
-
try {
|
|
402
|
-
const [txInfo, balance] = await Promise.all([getAstarClaimRewardTxInfo(substrateApiMap[networkKey], address), (0, _balance.getFreeBalance)(networkKey, address, substrateApiMap, evmApiMap)]);
|
|
403
|
-
const feeString = (0, _utils2.parseNumberToDisplay)(txInfo.partialFee, decimals) + ` ${symbol}`;
|
|
404
|
-
const rawFee = (0, _utils2.parseRawNumber)(txInfo.partialFee.toString());
|
|
405
|
-
const binaryBalance = new _util.BN(balance);
|
|
406
|
-
const balanceError = txInfo.partialFee.gt(binaryBalance);
|
|
407
|
-
return {
|
|
408
|
-
rawFee,
|
|
409
|
-
fee: feeString,
|
|
410
|
-
balanceError
|
|
411
|
-
};
|
|
412
|
-
} catch (e) {
|
|
413
|
-
return {
|
|
414
|
-
fee: `0.0000 ${symbol}`,
|
|
415
|
-
balanceError: false
|
|
243
|
+
const dappParam = (0, _utilCrypto.isEthereumAddress)(dappAddress) ? {
|
|
244
|
+
Evm: dappAddress
|
|
245
|
+
} : {
|
|
246
|
+
Wasm: dappAddress
|
|
416
247
|
};
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
async function getAstarClaimRewardExtrinsic(substrateApi, address) {
|
|
420
|
-
const apiPromise = await substrateApi.isReady;
|
|
421
|
-
const [_stakedDapps, _currentEra] = await Promise.all([apiPromise.api.query.dappsStaking.generalStakerInfo.entries(address), apiPromise.api.query.dappsStaking.currentEra()]);
|
|
422
|
-
const currentEra = (0, _utils2.parseRawNumber)(_currentEra.toHuman());
|
|
423
|
-
const transactions = [];
|
|
424
|
-
for (const item of _stakedDapps) {
|
|
425
|
-
const data = item[0].toHuman();
|
|
426
|
-
const stakedDapp = data[1];
|
|
427
|
-
const stakeData = item[1].toHuman();
|
|
428
|
-
const stakes = stakeData.stakes;
|
|
429
|
-
const dappAddress = stakedDapp.Evm.toLowerCase();
|
|
430
|
-
let numberOfUnclaimedEra = 0;
|
|
431
|
-
const maxTx = 50;
|
|
432
|
-
for (let i = 0; i < stakes.length; i++) {
|
|
433
|
-
var _stakes2;
|
|
434
|
-
const {
|
|
435
|
-
era,
|
|
436
|
-
staked
|
|
437
|
-
} = stakes[i];
|
|
438
|
-
const bnStaked = new _util.BN(staked.replaceAll(',', ''));
|
|
439
|
-
const parsedEra = (0, _utils2.parseRawNumber)(era);
|
|
440
|
-
if (bnStaked.eq(new _util.BN(0))) {
|
|
441
|
-
continue;
|
|
442
|
-
}
|
|
443
|
-
const nextEraData = (_stakes2 = stakes[i + 1]) !== null && _stakes2 !== void 0 ? _stakes2 : null;
|
|
444
|
-
const nextEra = nextEraData && (0, _utils2.parseRawNumber)(nextEraData.era);
|
|
445
|
-
const isLastEra = i === stakes.length - 1;
|
|
446
|
-
const eraToClaim = isLastEra ? currentEra - parsedEra : nextEra - parsedEra;
|
|
447
|
-
numberOfUnclaimedEra += eraToClaim;
|
|
448
|
-
}
|
|
449
248
|
for (let i = 0; i < Math.min(numberOfUnclaimedEra, maxTx); i++) {
|
|
450
|
-
const tx = apiPromise.api.tx.dappsStaking.claimStaker(
|
|
451
|
-
Evm: dappAddress
|
|
452
|
-
});
|
|
249
|
+
const tx = apiPromise.api.tx.dappsStaking.claimStaker(dappParam);
|
|
453
250
|
transactions.push(tx);
|
|
454
251
|
}
|
|
455
252
|
}
|
|
@@ -56,15 +56,15 @@ async function getValidatorsInfo(networkKey, substrateApi, decimals, chainStakin
|
|
|
56
56
|
async function getNominationPoolsInfo(chain, substrateApi) {
|
|
57
57
|
return (0, _relayChain.getRelayPoolsInfo)(chain, substrateApi);
|
|
58
58
|
}
|
|
59
|
-
async function getBondingExtrinsic(chainInfo, amount,
|
|
59
|
+
async function getBondingExtrinsic(chainInfo, amount, selectedValidators, substrateApi, address, nominatorMetadata) {
|
|
60
60
|
if (_constants._STAKING_CHAIN_GROUP.para.includes(chainInfo.slug)) {
|
|
61
|
-
return (0, _paraChain.getParaBondingExtrinsic)(
|
|
61
|
+
return (0, _paraChain.getParaBondingExtrinsic)(chainInfo, substrateApi, amount, selectedValidators[0], nominatorMetadata); // only select 1 validator at a time
|
|
62
62
|
} else if (_constants._STAKING_CHAIN_GROUP.astar.includes(chainInfo.slug)) {
|
|
63
63
|
return (0, _astar.getAstarBondingExtrinsic)(substrateApi, amount, selectedValidators[0]);
|
|
64
64
|
} else if (_constants._STAKING_CHAIN_GROUP.amplitude.includes(chainInfo.slug)) {
|
|
65
|
-
return (0, _amplitude.getAmplitudeBondingExtrinsic)(
|
|
65
|
+
return (0, _amplitude.getAmplitudeBondingExtrinsic)(substrateApi, amount, selectedValidators[0], nominatorMetadata);
|
|
66
66
|
}
|
|
67
|
-
return (0, _relayChain.getRelayBondingExtrinsic)(substrateApi, amount, selectedValidators,
|
|
67
|
+
return (0, _relayChain.getRelayBondingExtrinsic)(substrateApi, amount, selectedValidators, chainInfo, address, nominatorMetadata);
|
|
68
68
|
}
|
|
69
69
|
async function getUnbondingExtrinsic(nominatorMetadata, amount, chain, substrateApi, selectedValidator) {
|
|
70
70
|
if (_constants._STAKING_CHAIN_GROUP.para.includes(chain)) {
|
|
@@ -111,6 +111,7 @@ async function getParaChainNominatorMetadata(chainInfo, address, substrateApi) {
|
|
|
111
111
|
bnTotalActiveStake = bnTotalActiveStake.add(bnActiveStake);
|
|
112
112
|
nominationList.push({
|
|
113
113
|
chain,
|
|
114
|
+
status: _KoniTypes.StakingStatus.NOT_EARNING,
|
|
114
115
|
validatorAddress: delegation.owner,
|
|
115
116
|
validatorIdentity: identity,
|
|
116
117
|
activeStake: bnActiveStake.toString(),
|
|
@@ -133,15 +134,16 @@ async function getParaChainNominatorMetadata(chainInfo, address, substrateApi) {
|
|
|
133
134
|
}
|
|
134
135
|
async function getParachainCollatorsInfo(chain, substrateApi) {
|
|
135
136
|
const apiProps = await substrateApi.isReady;
|
|
136
|
-
const
|
|
137
|
+
const allCollators = [];
|
|
137
138
|
const [_allCollators, _collatorCommission] = await Promise.all([apiProps.api.query.parachainStaking.candidateInfo.entries(), apiProps.api.query.parachainStaking.collatorCommission()]);
|
|
138
139
|
const maxDelegationPerCollator = apiProps.api.consts.parachainStaking.maxTopDelegationsPerCandidate.toString();
|
|
139
140
|
const rawCollatorCommission = _collatorCommission.toHuman();
|
|
140
141
|
const collatorCommission = parseFloat(rawCollatorCommission.split('%')[0]);
|
|
141
142
|
for (const collator of _allCollators) {
|
|
142
|
-
const
|
|
143
|
+
const _collatorAddress = collator[0].toHuman();
|
|
144
|
+
const collatorAddress = _collatorAddress[0];
|
|
143
145
|
const collatorInfo = collator[1].toPrimitive();
|
|
144
|
-
|
|
146
|
+
allCollators.push({
|
|
145
147
|
commission: 0,
|
|
146
148
|
expectedReturn: 0,
|
|
147
149
|
address: collatorAddress,
|
|
@@ -157,9 +159,9 @@ async function getParachainCollatorsInfo(chain, substrateApi) {
|
|
|
157
159
|
});
|
|
158
160
|
}
|
|
159
161
|
const extraInfoMap = {};
|
|
160
|
-
await Promise.all(
|
|
162
|
+
await Promise.all(allCollators.map(async collator => {
|
|
161
163
|
var _apiProps$api$query, _apiProps$api$query$i;
|
|
162
|
-
const [_info, _identity] = await Promise.all([apiProps.api.query.parachainStaking.candidateInfo(
|
|
164
|
+
const [_info, _identity] = await Promise.all([apiProps.api.query.parachainStaking.candidateInfo(collator.address), (_apiProps$api$query = apiProps.api.query) === null || _apiProps$api$query === void 0 ? void 0 : (_apiProps$api$query$i = _apiProps$api$query.identity) === null || _apiProps$api$query$i === void 0 ? void 0 : _apiProps$api$query$i.identityOf(collator.address) // some chains might not have identity pallet
|
|
163
165
|
]);
|
|
164
166
|
const rawInfo = _info.toHuman();
|
|
165
167
|
const rawIdentity = _identity ? _identity.toHuman() : null;
|
|
@@ -175,7 +177,7 @@ async function getParachainCollatorsInfo(chain, substrateApi) {
|
|
|
175
177
|
isReasonable = rawIdentity.judgements.length > 0;
|
|
176
178
|
identity = (0, _utils.parseIdentity)(rawIdentity);
|
|
177
179
|
}
|
|
178
|
-
extraInfoMap[
|
|
180
|
+
extraInfoMap[collator.address] = {
|
|
179
181
|
identity,
|
|
180
182
|
isVerified: isReasonable,
|
|
181
183
|
bond: bond.toString(),
|
|
@@ -184,7 +186,7 @@ async function getParachainCollatorsInfo(chain, substrateApi) {
|
|
|
184
186
|
active
|
|
185
187
|
};
|
|
186
188
|
}));
|
|
187
|
-
for (const validator of
|
|
189
|
+
for (const validator of allCollators) {
|
|
188
190
|
validator.minBond = extraInfoMap[validator.address].minDelegation.toString();
|
|
189
191
|
validator.ownStake = extraInfoMap[validator.address].bond.toString();
|
|
190
192
|
validator.blocked = !extraInfoMap[validator.address].active;
|
|
@@ -195,16 +197,20 @@ async function getParachainCollatorsInfo(chain, substrateApi) {
|
|
|
195
197
|
validator.nominatorCount = extraInfoMap[validator.address].delegationCount;
|
|
196
198
|
validator.commission = collatorCommission;
|
|
197
199
|
}
|
|
198
|
-
return
|
|
200
|
+
return allCollators;
|
|
199
201
|
}
|
|
200
|
-
async function getParaBondingExtrinsic(
|
|
202
|
+
async function getParaBondingExtrinsic(chainInfo, substrateApi, amount, selectedCollatorInfo, nominatorMetadata) {
|
|
201
203
|
const apiPromise = await substrateApi.isReady;
|
|
202
204
|
const binaryAmount = new _util.BN(amount);
|
|
205
|
+
if (!nominatorMetadata) {
|
|
206
|
+
return apiPromise.api.tx.parachainStaking.delegate(selectedCollatorInfo.address, binaryAmount, new _util.BN(selectedCollatorInfo.nominatorCount), 0);
|
|
207
|
+
}
|
|
203
208
|
const {
|
|
204
209
|
bondedValidators,
|
|
205
210
|
nominationCount
|
|
206
211
|
} = (0, _utils.getBondedValidators)(nominatorMetadata.nominations);
|
|
207
|
-
|
|
212
|
+
const parsedSelectedCollatorAddress = (0, _utils3.reformatAddress)(selectedCollatorInfo.address, 0);
|
|
213
|
+
if (!bondedValidators.includes(parsedSelectedCollatorAddress)) {
|
|
208
214
|
return apiPromise.api.tx.parachainStaking.delegate(selectedCollatorInfo.address, binaryAmount, new _util.BN(selectedCollatorInfo.nominatorCount), nominationCount);
|
|
209
215
|
} else {
|
|
210
216
|
return apiPromise.api.tx.parachainStaking.delegatorBondMore(selectedCollatorInfo.address, binaryAmount);
|