@subwallet/extension-base 1.1.31-beta.0 → 1.1.33-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 +71 -111
- package/background/KoniTypes.js +14 -19
- package/background/errors/TransactionError.js +0 -9
- package/cjs/background/KoniTypes.js +17 -20
- package/cjs/background/errors/TransactionError.js +0 -9
- package/cjs/constants/index.js +4 -19
- package/cjs/koni/api/nft/config.js +23 -33
- package/cjs/koni/api/nft/index.js +0 -14
- package/cjs/koni/api/nft/nft.js +22 -1
- package/cjs/koni/api/staking/bonding/amplitude.js +108 -76
- package/cjs/koni/api/staking/bonding/astar.js +10 -11
- package/cjs/koni/api/staking/bonding/index.js +3 -4
- package/cjs/koni/api/staking/bonding/paraChain.js +29 -28
- package/cjs/koni/api/staking/bonding/relayChain.js +45 -48
- package/cjs/koni/api/staking/bonding/utils.js +86 -104
- package/cjs/koni/api/staking/index.js +5 -6
- package/cjs/koni/api/staking/paraChain.js +36 -11
- package/cjs/koni/api/staking/relayChain.js +2 -3
- package/cjs/koni/api/xcm/xTokens.js +1 -1
- package/cjs/koni/background/cron.js +1 -11
- package/cjs/koni/background/handlers/Extension.js +69 -362
- package/cjs/koni/background/handlers/State.js +3 -51
- package/cjs/koni/background/handlers/Tabs.js +19 -2
- package/cjs/koni/background/handlers/index.js +2 -4
- package/cjs/koni/background/subscription.js +37 -95
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/campaign-service/index.js +25 -9
- package/cjs/services/chain-service/constants.js +21 -4
- package/cjs/services/chain-service/index.js +2 -3
- package/cjs/services/chain-service/utils.js +1 -7
- package/cjs/services/event-service/index.js +0 -4
- package/cjs/services/history-service/index.js +12 -8
- package/cjs/services/keyring-service/index.js +2 -14
- package/cjs/services/migration-service/scripts/MigrateLedgerAccount.js +1 -1
- package/cjs/services/migration-service/scripts/MigrateTransactionHistory.js +1 -1
- package/cjs/services/migration-service/scripts/index.js +1 -7
- package/cjs/services/notification-service/NotificationService.js +1 -1
- package/cjs/services/storage-service/DatabaseService.js +3 -51
- package/cjs/services/storage-service/databases/index.js +0 -4
- package/cjs/services/storage-service/db-stores/Campaign.js +9 -3
- package/cjs/services/storage-service/db-stores/NominatorMetadata.js +3 -3
- package/cjs/services/subscan-service/index.js +0 -16
- package/cjs/services/transaction-service/event-parser/index.js +0 -58
- package/cjs/services/transaction-service/helpers/index.js +1 -3
- package/cjs/services/transaction-service/index.js +131 -242
- package/cjs/services/transaction-service/utils.js +0 -1
- package/cjs/types/index.js +0 -44
- package/cjs/utils/fetchEvmChainInfo.js +20 -0
- package/cjs/utils/fetchStaticData.js +1 -2
- package/cjs/utils/index.js +17 -81
- package/cjs/utils/number.js +1 -3
- package/constants/index.d.ts +1 -6
- package/constants/index.js +1 -6
- package/koni/api/nft/config.js +23 -33
- package/koni/api/nft/index.js +1 -15
- package/koni/api/nft/nft.js +23 -2
- package/koni/api/staking/bonding/amplitude.d.ts +1 -1
- package/koni/api/staking/bonding/amplitude.js +105 -73
- package/koni/api/staking/bonding/astar.js +8 -9
- package/koni/api/staking/bonding/index.d.ts +2 -1
- package/koni/api/staking/bonding/index.js +3 -5
- package/koni/api/staking/bonding/paraChain.js +16 -15
- package/koni/api/staking/bonding/relayChain.d.ts +2 -2
- package/koni/api/staking/bonding/relayChain.js +30 -33
- package/koni/api/staking/bonding/utils.d.ts +42 -15
- package/koni/api/staking/bonding/utils.js +69 -85
- package/koni/api/staking/index.js +1 -2
- package/koni/api/staking/paraChain.js +37 -12
- package/koni/api/staking/relayChain.js +3 -4
- package/koni/api/xcm/xTokens.js +1 -1
- package/koni/background/cron.d.ts +0 -1
- package/koni/background/cron.js +2 -12
- package/koni/background/handlers/Extension.d.ts +1 -17
- package/koni/background/handlers/Extension.js +30 -321
- package/koni/background/handlers/State.d.ts +2 -18
- package/koni/background/handlers/State.js +3 -50
- package/koni/background/handlers/Tabs.js +20 -3
- package/koni/background/handlers/index.js +2 -4
- package/koni/background/subscription.d.ts +1 -6
- package/koni/background/subscription.js +38 -97
- package/package.json +13 -321
- package/packageInfo.js +1 -1
- package/services/campaign-service/index.js +25 -9
- package/services/chain-service/constants.d.ts +12 -0
- package/services/chain-service/constants.js +19 -3
- package/services/chain-service/index.js +2 -3
- package/services/chain-service/utils.d.ts +0 -1
- package/services/chain-service/utils.js +1 -5
- package/services/event-service/index.d.ts +0 -1
- package/services/event-service/index.js +0 -4
- package/services/event-service/types.d.ts +1 -8
- package/services/history-service/index.js +12 -8
- package/services/keyring-service/index.d.ts +1 -2
- package/services/keyring-service/index.js +2 -14
- package/services/migration-service/scripts/MigrateLedgerAccount.js +1 -1
- package/services/migration-service/scripts/MigrateTransactionHistory.js +1 -1
- package/services/migration-service/scripts/index.js +1 -7
- package/services/notification-service/NotificationService.js +1 -1
- package/services/storage-service/DatabaseService.d.ts +2 -18
- package/services/storage-service/DatabaseService.js +3 -51
- package/services/storage-service/databases/index.d.ts +1 -3
- package/services/storage-service/databases/index.js +0 -4
- package/services/storage-service/db-stores/Campaign.js +9 -3
- package/services/storage-service/db-stores/NominatorMetadata.js +3 -3
- package/services/subscan-service/index.d.ts +2 -3
- package/services/subscan-service/index.js +0 -15
- package/services/subscan-service/types.d.ts +0 -20
- package/services/transaction-service/event-parser/index.d.ts +1 -3
- package/services/transaction-service/event-parser/index.js +1 -57
- package/services/transaction-service/helpers/index.js +1 -3
- package/services/transaction-service/index.d.ts +16 -4
- package/services/transaction-service/index.js +118 -230
- package/services/transaction-service/types.d.ts +1 -2
- package/services/transaction-service/utils.js +0 -1
- package/types/index.d.ts +0 -5
- package/types/index.js +1 -5
- package/utils/fetchEvmChainInfo.d.ts +17 -0
- package/utils/fetchEvmChainInfo.js +14 -0
- package/utils/fetchStaticData.js +1 -2
- package/utils/index.d.ts +2 -5
- package/utils/index.js +2 -52
- package/utils/number.d.ts +1 -1
- package/utils/number.js +1 -1
- package/cjs/koni/api/dotsama/balance.js +0 -464
- package/cjs/koni/api/nft/ordinal_nft/constants.js +0 -21
- package/cjs/koni/api/nft/ordinal_nft/index.js +0 -121
- package/cjs/koni/api/nft/ordinal_nft/utils.js +0 -41
- package/cjs/koni/api/yield/helper/utils.js +0 -46
- package/cjs/services/earning-service/constants/chains.js +0 -29
- package/cjs/services/earning-service/constants/index.js +0 -27
- package/cjs/services/earning-service/constants/step.js +0 -18
- package/cjs/services/earning-service/handlers/base.js +0 -259
- package/cjs/services/earning-service/handlers/index.js +0 -60
- package/cjs/services/earning-service/handlers/lending/base.js +0 -20
- package/cjs/services/earning-service/handlers/lending/index.js +0 -13
- package/cjs/services/earning-service/handlers/lending/interlay.js +0 -191
- package/cjs/services/earning-service/handlers/liquid-staking/acala.js +0 -239
- package/cjs/services/earning-service/handlers/liquid-staking/base.js +0 -43
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +0 -297
- package/cjs/services/earning-service/handlers/liquid-staking/index.js +0 -34
- package/cjs/services/earning-service/handlers/liquid-staking/parallel.js +0 -226
- package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +0 -395
- package/cjs/services/earning-service/handlers/native-staking/amplitude.js +0 -384
- package/cjs/services/earning-service/handlers/native-staking/astar.js +0 -461
- package/cjs/services/earning-service/handlers/native-staking/base-para.js +0 -146
- package/cjs/services/earning-service/handlers/native-staking/base.js +0 -159
- package/cjs/services/earning-service/handlers/native-staking/index.js +0 -34
- package/cjs/services/earning-service/handlers/native-staking/para-chain.js +0 -385
- package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +0 -558
- package/cjs/services/earning-service/handlers/nomination-pool/index.js +0 -560
- package/cjs/services/earning-service/handlers/special.js +0 -503
- package/cjs/services/earning-service/service.js +0 -387
- package/cjs/services/earning-service/utils/index.js +0 -128
- package/cjs/services/migration-service/scripts/DeleteEarningData.js +0 -21
- package/cjs/services/migration-service/scripts/EnableEarningChains.js +0 -21
- package/cjs/services/migration-service/scripts/MigrateEthProvider.js +0 -17
- package/cjs/services/migration-service/scripts/MigratePioneerProvider.js +0 -17
- package/cjs/services/migration-service/scripts/MigrateProvider.js +0 -29
- package/cjs/services/migration-service/scripts/databases/MigrateEarningHistory.js +0 -21
- package/cjs/services/migration-service/scripts/databases/MigrateEarningVersion.js +0 -21
- package/cjs/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +0 -149
- package/cjs/services/mint-campaign-service/campaigns/index.js +0 -13
- package/cjs/services/mint-campaign-service/constants.js +0 -11
- package/cjs/services/mint-campaign-service/index.js +0 -18
- package/cjs/services/storage-service/db-stores/YieldPoolStore.js +0 -36
- package/cjs/services/storage-service/db-stores/YieldPositionStore.js +0 -65
- package/cjs/services/storage-service/index.js +0 -241
- package/cjs/types/campaigns/index.js +0 -16
- package/cjs/types/campaigns/unlock-dot.js +0 -1
- package/cjs/types/ordinal.js +0 -1
- package/cjs/types/transaction.js +0 -1
- package/cjs/types/yield/actions/index.js +0 -27
- package/cjs/types/yield/actions/join/index.js +0 -38
- package/cjs/types/yield/actions/join/step.js +0 -47
- package/cjs/types/yield/actions/join/submit.js +0 -1
- package/cjs/types/yield/actions/join/validate.js +0 -16
- package/cjs/types/yield/actions/others.js +0 -1
- package/cjs/types/yield/index.js +0 -27
- package/cjs/types/yield/info/account/index.js +0 -49
- package/cjs/types/yield/info/account/info.js +0 -1
- package/cjs/types/yield/info/account/reward.js +0 -1
- package/cjs/types/yield/info/account/target.js +0 -32
- package/cjs/types/yield/info/account/unstake.js +0 -27
- package/cjs/types/yield/info/base.js +0 -41
- package/cjs/types/yield/info/chain/index.js +0 -27
- package/cjs/types/yield/info/chain/info.js +0 -1
- package/cjs/types/yield/info/chain/target.js +0 -1
- package/cjs/types/yield/info/index.js +0 -49
- package/cjs/types/yield/info/pallet.js +0 -15
- package/cjs/types.js +0 -1
- package/cjs/utils/address.js +0 -34
- package/cjs/utils/keyring.js +0 -57
- package/cjs/utils/object.js +0 -12
- package/koni/api/nft/ordinal_nft/constants.d.ts +0 -9
- package/koni/api/nft/ordinal_nft/constants.js +0 -12
- package/koni/api/nft/ordinal_nft/index.d.ts +0 -8
- package/koni/api/nft/ordinal_nft/index.js +0 -114
- package/koni/api/nft/ordinal_nft/utils.d.ts +0 -2
- package/koni/api/nft/ordinal_nft/utils.js +0 -33
- package/koni/api/yield/helper/utils.d.ts +0 -10
- package/koni/api/yield/helper/utils.js +0 -32
- package/services/earning-service/constants/abis/compound_finance_v2_abi.json +0 -1235
- package/services/earning-service/constants/abis/st_liquid_token_abi.json +0 -1355
- package/services/earning-service/constants/chains.d.ts +0 -14
- package/services/earning-service/constants/chains.js +0 -21
- package/services/earning-service/constants/index.d.ts +0 -2
- package/services/earning-service/constants/index.js +0 -5
- package/services/earning-service/constants/step.d.ts +0 -3
- package/services/earning-service/constants/step.js +0 -10
- package/services/earning-service/handlers/base.d.ts +0 -112
- package/services/earning-service/handlers/base.js +0 -253
- package/services/earning-service/handlers/index.d.ts +0 -5
- package/services/earning-service/handlers/index.js +0 -8
- package/services/earning-service/handlers/lending/base.d.ts +0 -6
- package/services/earning-service/handlers/lending/base.js +0 -12
- package/services/earning-service/handlers/lending/index.d.ts +0 -1
- package/services/earning-service/handlers/lending/index.js +0 -4
- package/services/earning-service/handlers/lending/interlay.d.ts +0 -24
- package/services/earning-service/handlers/lending/interlay.js +0 -183
- package/services/earning-service/handlers/liquid-staking/acala.d.ts +0 -27
- package/services/earning-service/handlers/liquid-staking/acala.js +0 -231
- package/services/earning-service/handlers/liquid-staking/base.d.ts +0 -9
- package/services/earning-service/handlers/liquid-staking/base.js +0 -35
- package/services/earning-service/handlers/liquid-staking/bifrost.d.ts +0 -46
- package/services/earning-service/handlers/liquid-staking/bifrost.js +0 -286
- package/services/earning-service/handlers/liquid-staking/index.d.ts +0 -4
- package/services/earning-service/handlers/liquid-staking/index.js +0 -7
- package/services/earning-service/handlers/liquid-staking/parallel.d.ts +0 -26
- package/services/earning-service/handlers/liquid-staking/parallel.js +0 -218
- package/services/earning-service/handlers/liquid-staking/stella-swap.d.ts +0 -34
- package/services/earning-service/handlers/liquid-staking/stella-swap.js +0 -385
- package/services/earning-service/handlers/native-staking/amplitude.d.ts +0 -22
- package/services/earning-service/handlers/native-staking/amplitude.js +0 -375
- package/services/earning-service/handlers/native-staking/astar.d.ts +0 -19
- package/services/earning-service/handlers/native-staking/astar.js +0 -451
- package/services/earning-service/handlers/native-staking/base-para.d.ts +0 -11
- package/services/earning-service/handlers/native-staking/base-para.js +0 -138
- package/services/earning-service/handlers/native-staking/base.d.ts +0 -21
- package/services/earning-service/handlers/native-staking/base.js +0 -150
- package/services/earning-service/handlers/native-staking/index.d.ts +0 -4
- package/services/earning-service/handlers/native-staking/index.js +0 -7
- package/services/earning-service/handlers/native-staking/para-chain.d.ts +0 -15
- package/services/earning-service/handlers/native-staking/para-chain.js +0 -377
- package/services/earning-service/handlers/native-staking/relay-chain.d.ts +0 -21
- package/services/earning-service/handlers/native-staking/relay-chain.js +0 -549
- package/services/earning-service/handlers/nomination-pool/index.d.ts +0 -36
- package/services/earning-service/handlers/nomination-pool/index.js +0 -550
- package/services/earning-service/handlers/special.d.ts +0 -65
- package/services/earning-service/handlers/special.js +0 -495
- package/services/earning-service/service.d.ts +0 -45
- package/services/earning-service/service.js +0 -379
- package/services/earning-service/utils/index.d.ts +0 -18
- package/services/earning-service/utils/index.js +0 -112
- package/services/migration-service/scripts/DeleteEarningData.d.ts +0 -4
- package/services/migration-service/scripts/DeleteEarningData.js +0 -13
- package/services/migration-service/scripts/EnableEarningChains.d.ts +0 -4
- package/services/migration-service/scripts/EnableEarningChains.js +0 -13
- package/services/migration-service/scripts/databases/MigrateEarningHistory.d.ts +0 -4
- package/services/migration-service/scripts/databases/MigrateEarningHistory.js +0 -13
- package/services/migration-service/scripts/databases/MigrateEarningVersion.d.ts +0 -4
- package/services/migration-service/scripts/databases/MigrateEarningVersion.js +0 -13
- package/services/mint-campaign-service/campaigns/UnlockDotCampaign.d.ts +0 -13
- package/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +0 -139
- package/services/mint-campaign-service/campaigns/index.d.ts +0 -1
- package/services/mint-campaign-service/campaigns/index.js +0 -4
- package/services/mint-campaign-service/constants.d.ts +0 -1
- package/services/mint-campaign-service/constants.js +0 -4
- package/services/mint-campaign-service/index.d.ts +0 -7
- package/services/mint-campaign-service/index.js +0 -11
- package/services/storage-service/db-stores/YieldPoolStore.d.ts +0 -10
- package/services/storage-service/db-stores/YieldPoolStore.js +0 -28
- package/services/storage-service/db-stores/YieldPositionStore.d.ts +0 -9
- package/services/storage-service/db-stores/YieldPositionStore.js +0 -57
- package/types/campaigns/index.d.ts +0 -1
- package/types/campaigns/index.js +0 -4
- package/types/campaigns/unlock-dot.d.ts +0 -71
- package/types/campaigns/unlock-dot.js +0 -1
- package/types/ordinal.d.ts +0 -69
- package/types/ordinal.js +0 -1
- package/types/transaction.d.ts +0 -3
- package/types/transaction.js +0 -1
- package/types/yield/actions/index.d.ts +0 -2
- package/types/yield/actions/index.js +0 -5
- package/types/yield/actions/join/index.d.ts +0 -3
- package/types/yield/actions/join/index.js +0 -6
- package/types/yield/actions/join/step.d.ts +0 -95
- package/types/yield/actions/join/step.js +0 -46
- package/types/yield/actions/join/submit.d.ts +0 -57
- package/types/yield/actions/join/submit.js +0 -1
- package/types/yield/actions/join/validate.d.ts +0 -18
- package/types/yield/actions/join/validate.js +0 -10
- package/types/yield/actions/others.d.ts +0 -85
- package/types/yield/actions/others.js +0 -1
- package/types/yield/index.d.ts +0 -2
- package/types/yield/index.js +0 -5
- package/types/yield/info/account/index.d.ts +0 -4
- package/types/yield/info/account/index.js +0 -7
- package/types/yield/info/account/info.d.ts +0 -92
- package/types/yield/info/account/info.js +0 -1
- package/types/yield/info/account/reward.d.ts +0 -45
- package/types/yield/info/account/reward.js +0 -1
- package/types/yield/info/account/target.d.ts +0 -43
- package/types/yield/info/account/target.js +0 -27
- package/types/yield/info/account/unstake.d.ts +0 -31
- package/types/yield/info/account/unstake.js +0 -22
- package/types/yield/info/base.d.ts +0 -45
- package/types/yield/info/base.js +0 -36
- package/types/yield/info/chain/index.d.ts +0 -2
- package/types/yield/info/chain/index.js +0 -5
- package/types/yield/info/chain/info.d.ts +0 -251
- package/types/yield/info/chain/info.js +0 -1
- package/types/yield/info/chain/target.d.ts +0 -37
- package/types/yield/info/chain/target.js +0 -1
- package/types/yield/info/index.d.ts +0 -4
- package/types/yield/info/index.js +0 -7
- package/types/yield/info/pallet.d.ts +0 -143
- package/types/yield/info/pallet.js +0 -9
- package/utils/object.d.ts +0 -1
- package/utils/object.js +0 -6
|
@@ -2,14 +2,11 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
5
|
-
import { StakingTxErrorType, StakingType } from '@subwallet/extension-base/background/KoniTypes';
|
|
5
|
+
import { StakingStatus, StakingTxErrorType, StakingType, UnstakingStatus } from '@subwallet/extension-base/background/KoniTypes';
|
|
6
6
|
import { MAX_NOMINATIONS } from '@subwallet/extension-base/constants';
|
|
7
|
-
import { calculateAlephZeroValidatorReturn, calculateChainStakedReturn, calculateInflation, calculateTernoaValidatorReturn, calculateValidatorStakedReturn, getCommission, getExistUnstakeErrorMessage, getMaxValidatorErrorMessage, getMinStakeErrorMessage, parsePoolStashAddress } from '@subwallet/extension-base/koni/api/staking/bonding/utils';
|
|
8
|
-
import { _EXPECTED_BLOCK_TIME, _STAKING_ERA_LENGTH_MAP } from '@subwallet/extension-base/services/chain-service/constants';
|
|
7
|
+
import { calculateAlephZeroValidatorReturn, calculateChainStakedReturn, calculateInflation, calculateTernoaValidatorReturn, calculateValidatorStakedReturn, getCommission, getExistUnstakeErrorMessage, getMaxValidatorErrorMessage, getMinStakeErrorMessage, parseIdentity, parsePoolStashAddress } from '@subwallet/extension-base/koni/api/staking/bonding/utils';
|
|
8
|
+
import { _EXPECTED_BLOCK_TIME, _STAKING_CHAIN_GROUP, _STAKING_ERA_LENGTH_MAP } from '@subwallet/extension-base/services/chain-service/constants';
|
|
9
9
|
import { _getChainSubstrateAddressPrefix } from '@subwallet/extension-base/services/chain-service/utils';
|
|
10
|
-
import { _STAKING_CHAIN_GROUP } from '@subwallet/extension-base/services/earning-service/constants';
|
|
11
|
-
import { parseIdentity } from '@subwallet/extension-base/services/earning-service/utils';
|
|
12
|
-
import { EarningStatus, UnstakingStatus } from '@subwallet/extension-base/types';
|
|
13
10
|
import { reformatAddress } from '@subwallet/extension-base/utils';
|
|
14
11
|
import BigN from 'bignumber.js';
|
|
15
12
|
import { t } from 'i18next';
|
|
@@ -61,7 +58,7 @@ export function validateRelayBondingCondition(chainInfo, amount, selectedValidat
|
|
|
61
58
|
const bnMinStake = new BN(chainStakingMetadata.minStake);
|
|
62
59
|
const minStakeErrorMessage = getMinStakeErrorMessage(chainInfo, bnMinStake);
|
|
63
60
|
const maxValidatorErrorMessage = getMaxValidatorErrorMessage(chainInfo, chainStakingMetadata.maxValidatorPerNominator);
|
|
64
|
-
if (!nominatorMetadata || nominatorMetadata.status ===
|
|
61
|
+
if (!nominatorMetadata || nominatorMetadata.status === StakingStatus.NOT_STAKING) {
|
|
65
62
|
if (!bnTotalStake.gte(bnMinStake)) {
|
|
66
63
|
errors.push(new TransactionError(StakingTxErrorType.NOT_ENOUGH_MIN_STAKE, minStakeErrorMessage));
|
|
67
64
|
}
|
|
@@ -120,12 +117,12 @@ export function subscribeRelayChainStakingMetadata(chainInfo, substrateApi, call
|
|
|
120
117
|
});
|
|
121
118
|
}
|
|
122
119
|
export async function getRelayChainStakingMetadata(chainInfo, substrateApi) {
|
|
123
|
-
var _chainApi$api$
|
|
120
|
+
var _chainApi$api$query$a, _chainApi$api$query, _chainApi$api$query$s, _chainApi$api$query2, _chainApi$api$query2$, _chainApi$api$query3, _chainApi$api$query3$;
|
|
124
121
|
const chain = chainInfo.slug;
|
|
125
122
|
const chainApi = await substrateApi.isReady;
|
|
126
123
|
const _era = await chainApi.api.query.staking.currentEra();
|
|
127
124
|
const currentEra = _era.toString();
|
|
128
|
-
const maxNominations =
|
|
125
|
+
const maxNominations = chainApi.api.consts.staking.maxNominations.toString();
|
|
129
126
|
const maxUnlockingChunks = chainApi.api.consts.staking.maxUnlockingChunks.toString();
|
|
130
127
|
const unlockingEras = chainApi.api.consts.staking.bondingDuration.toString();
|
|
131
128
|
const [_totalEraStake, _totalIssuance, _auctionCounter, _minimumActiveStake, _minNominatorBond, _minPoolJoin, _eraStakers] = await Promise.all([chainApi.api.query.staking.erasTotalStake(parseInt(currentEra)), chainApi.api.query.balances.totalIssuance(), (_chainApi$api$query$a = chainApi.api.query.auctions) === null || _chainApi$api$query$a === void 0 ? void 0 : _chainApi$api$query$a.auctionCounter(), ((_chainApi$api$query = chainApi.api.query) === null || _chainApi$api$query === void 0 ? void 0 : (_chainApi$api$query$s = _chainApi$api$query.staking) === null || _chainApi$api$query$s === void 0 ? void 0 : _chainApi$api$query$s.minimumActiveStake) && ((_chainApi$api$query2 = chainApi.api.query) === null || _chainApi$api$query2 === void 0 ? void 0 : (_chainApi$api$query2$ = _chainApi$api$query2.staking) === null || _chainApi$api$query2$ === void 0 ? void 0 : _chainApi$api$query2$.minimumActiveStake()), chainApi.api.query.staking.minNominatorBond(), (_chainApi$api$query3 = chainApi.api.query) === null || _chainApi$api$query3 === void 0 ? void 0 : (_chainApi$api$query3$ = _chainApi$api$query3.nominationPools) === null || _chainApi$api$query3$ === void 0 ? void 0 : _chainApi$api$query3$.minJoinBond(), chainApi.api.query.staking.erasStakers.entries(parseInt(currentEra))]);
|
|
@@ -196,7 +193,7 @@ export async function subscribeRelayChainNominatorMetadata(chainInfo, address, s
|
|
|
196
193
|
if (nominations) {
|
|
197
194
|
const validatorList = nominations.targets;
|
|
198
195
|
await Promise.all(validatorList.map(async validatorAddress => {
|
|
199
|
-
let nominationStatus =
|
|
196
|
+
let nominationStatus = StakingStatus.NOT_EARNING;
|
|
200
197
|
const [[identity], _eraStaker] = await Promise.all([parseIdentity(chainApi, validatorAddress), chainApi.api.query.staking.erasStakers(currentEra, validatorAddress)]);
|
|
201
198
|
const eraStaker = _eraStaker.toPrimitive();
|
|
202
199
|
const sortedNominators = eraStaker.others.sort((a, b) => {
|
|
@@ -207,10 +204,10 @@ export async function subscribeRelayChainNominatorMetadata(chainInfo, address, s
|
|
|
207
204
|
});
|
|
208
205
|
if (!topNominators.includes(reformatAddress(address, _getChainSubstrateAddressPrefix(chainInfo)))) {
|
|
209
206
|
// if nominator has target but not in nominator list
|
|
210
|
-
nominationStatus =
|
|
207
|
+
nominationStatus = StakingStatus.WAITING;
|
|
211
208
|
} else if (topNominators.slice(0, unlimitedNominatorRewarded ? undefined : maxNominatorRewardedPerValidator).includes(reformatAddress(address, _getChainSubstrateAddressPrefix(chainInfo)))) {
|
|
212
209
|
// if address in top nominators
|
|
213
|
-
nominationStatus =
|
|
210
|
+
nominationStatus = StakingStatus.EARNING_REWARD;
|
|
214
211
|
}
|
|
215
212
|
nominationList.push({
|
|
216
213
|
chain,
|
|
@@ -222,20 +219,20 @@ export async function subscribeRelayChainNominatorMetadata(chainInfo, address, s
|
|
|
222
219
|
}));
|
|
223
220
|
}
|
|
224
221
|
|
|
225
|
-
let stakingStatus =
|
|
222
|
+
let stakingStatus = StakingStatus.NOT_EARNING;
|
|
226
223
|
const bnActiveStake = new BN(activeStake);
|
|
227
224
|
let waitingNominationCount = 0;
|
|
228
225
|
if (bnActiveStake.gte(minStake)) {
|
|
229
226
|
for (const nomination of nominationList) {
|
|
230
|
-
if (nomination.status ===
|
|
227
|
+
if (nomination.status === StakingStatus.EARNING_REWARD) {
|
|
231
228
|
// only need 1 earning nomination to count
|
|
232
|
-
stakingStatus =
|
|
233
|
-
} else if (nomination.status ===
|
|
229
|
+
stakingStatus = StakingStatus.EARNING_REWARD;
|
|
230
|
+
} else if (nomination.status === StakingStatus.WAITING) {
|
|
234
231
|
waitingNominationCount += 1;
|
|
235
232
|
}
|
|
236
233
|
}
|
|
237
234
|
if (waitingNominationCount === nominationList.length) {
|
|
238
|
-
stakingStatus =
|
|
235
|
+
stakingStatus = StakingStatus.WAITING;
|
|
239
236
|
}
|
|
240
237
|
}
|
|
241
238
|
ledger.unlocking.forEach(unlockingChunk => {
|
|
@@ -296,7 +293,7 @@ export async function getRelayChainNominatorMetadata(chainInfo, address, substra
|
|
|
296
293
|
return {
|
|
297
294
|
chain,
|
|
298
295
|
type: StakingType.NOMINATED,
|
|
299
|
-
status:
|
|
296
|
+
status: StakingStatus.NOT_STAKING,
|
|
300
297
|
address: address,
|
|
301
298
|
activeStake: '0',
|
|
302
299
|
nominations: [],
|
|
@@ -309,7 +306,7 @@ export async function getRelayChainNominatorMetadata(chainInfo, address, substra
|
|
|
309
306
|
if (nominations) {
|
|
310
307
|
const validatorList = nominations.targets;
|
|
311
308
|
await Promise.all(validatorList.map(async validatorAddress => {
|
|
312
|
-
let nominationStatus =
|
|
309
|
+
let nominationStatus = StakingStatus.NOT_EARNING;
|
|
313
310
|
const [[identity], _eraStaker] = await Promise.all([parseIdentity(chainApi, validatorAddress), chainApi.api.query.staking.erasStakers(currentEra, validatorAddress)]);
|
|
314
311
|
const eraStaker = _eraStaker.toPrimitive();
|
|
315
312
|
const sortedNominators = eraStaker.others.sort((a, b) => {
|
|
@@ -320,10 +317,10 @@ export async function getRelayChainNominatorMetadata(chainInfo, address, substra
|
|
|
320
317
|
});
|
|
321
318
|
if (!topNominators.includes(reformatAddress(address, _getChainSubstrateAddressPrefix(chainInfo)))) {
|
|
322
319
|
// if nominator has target but not in nominator list
|
|
323
|
-
nominationStatus =
|
|
320
|
+
nominationStatus = StakingStatus.WAITING;
|
|
324
321
|
} else if (topNominators.slice(0, unlimitedNominatorRewarded ? undefined : maxNominatorRewardedPerValidator).includes(reformatAddress(address, _getChainSubstrateAddressPrefix(chainInfo)))) {
|
|
325
322
|
// if address in top nominators
|
|
326
|
-
nominationStatus =
|
|
323
|
+
nominationStatus = StakingStatus.EARNING_REWARD;
|
|
327
324
|
}
|
|
328
325
|
nominationList.push({
|
|
329
326
|
chain,
|
|
@@ -335,20 +332,20 @@ export async function getRelayChainNominatorMetadata(chainInfo, address, substra
|
|
|
335
332
|
}));
|
|
336
333
|
}
|
|
337
334
|
|
|
338
|
-
let stakingStatus =
|
|
335
|
+
let stakingStatus = StakingStatus.NOT_EARNING;
|
|
339
336
|
const bnActiveStake = new BN(activeStake);
|
|
340
337
|
let waitingNominationCount = 0;
|
|
341
338
|
if (bnActiveStake.gte(minStake)) {
|
|
342
339
|
for (const nomination of nominationList) {
|
|
343
|
-
if (nomination.status ===
|
|
340
|
+
if (nomination.status === StakingStatus.EARNING_REWARD) {
|
|
344
341
|
// only need 1 earning nomination to count
|
|
345
|
-
stakingStatus =
|
|
346
|
-
} else if (nomination.status ===
|
|
342
|
+
stakingStatus = StakingStatus.EARNING_REWARD;
|
|
343
|
+
} else if (nomination.status === StakingStatus.WAITING) {
|
|
347
344
|
waitingNominationCount += 1;
|
|
348
345
|
}
|
|
349
346
|
}
|
|
350
347
|
if (waitingNominationCount === nominationList.length) {
|
|
351
|
-
stakingStatus =
|
|
348
|
+
stakingStatus = StakingStatus.WAITING;
|
|
352
349
|
}
|
|
353
350
|
}
|
|
354
351
|
ledger.unlocking.forEach(unlockingChunk => {
|
|
@@ -384,7 +381,7 @@ export async function subscribeRelayChainPoolMemberMetadata(chainInfo, address,
|
|
|
384
381
|
const poolMetadata = _poolMetadata.toPrimitive();
|
|
385
382
|
const currentEra = _currentEra.toString();
|
|
386
383
|
const nominations = _nominations.toJSON();
|
|
387
|
-
let stakingStatus =
|
|
384
|
+
let stakingStatus = StakingStatus.NOT_EARNING;
|
|
388
385
|
const getPoolName = () => {
|
|
389
386
|
if (poolMetadata.isUtf8) {
|
|
390
387
|
return poolMetadata.toUtf8();
|
|
@@ -407,7 +404,7 @@ export async function subscribeRelayChainPoolMemberMetadata(chainInfo, address,
|
|
|
407
404
|
}).slice(0, unlimitedNominatorRewarded ? undefined : maxNominatorRewardedPerValidator);
|
|
408
405
|
if (topNominators.includes(reformatAddress(poolStashAccount, _getChainSubstrateAddressPrefix(chainInfo)))) {
|
|
409
406
|
// if address in top nominators
|
|
410
|
-
stakingStatus =
|
|
407
|
+
stakingStatus = StakingStatus.EARNING_REWARD;
|
|
411
408
|
}
|
|
412
409
|
}));
|
|
413
410
|
}
|
|
@@ -442,7 +439,7 @@ export async function subscribeRelayChainPoolMemberMetadata(chainInfo, address,
|
|
|
442
439
|
});
|
|
443
440
|
const bnActiveStake = new BN(poolMemberInfo.points.toString());
|
|
444
441
|
if (!bnActiveStake.gt(BN_ZERO)) {
|
|
445
|
-
stakingStatus =
|
|
442
|
+
stakingStatus = StakingStatus.NOT_EARNING;
|
|
446
443
|
}
|
|
447
444
|
return {
|
|
448
445
|
chain: chainInfo.slug,
|
|
@@ -473,14 +470,14 @@ export async function getRelayChainPoolMemberMetadata(chainInfo, address, substr
|
|
|
473
470
|
chain: chainInfo.slug,
|
|
474
471
|
type: StakingType.POOLED,
|
|
475
472
|
address,
|
|
476
|
-
status:
|
|
473
|
+
status: StakingStatus.NOT_STAKING,
|
|
477
474
|
activeStake: '0',
|
|
478
475
|
nominations: [],
|
|
479
476
|
// can only join 1 pool at a time
|
|
480
477
|
unstakings: []
|
|
481
478
|
};
|
|
482
479
|
}
|
|
483
|
-
let stakingStatus =
|
|
480
|
+
let stakingStatus = StakingStatus.NOT_EARNING;
|
|
484
481
|
const _poolMetadata = await chainApi.api.query.nominationPools.metadata(poolMemberInfo.poolId);
|
|
485
482
|
const poolMetadata = _poolMetadata.toPrimitive();
|
|
486
483
|
const getPoolName = () => {
|
|
@@ -508,7 +505,7 @@ export async function getRelayChainPoolMemberMetadata(chainInfo, address, substr
|
|
|
508
505
|
}).slice(0, unlimitedNominatorRewarded ? undefined : maxNominatorRewardedPerValidator);
|
|
509
506
|
if (topNominators.includes(reformatAddress(poolStashAccount, _getChainSubstrateAddressPrefix(chainInfo)))) {
|
|
510
507
|
// if address in top nominators
|
|
511
|
-
stakingStatus =
|
|
508
|
+
stakingStatus = StakingStatus.EARNING_REWARD;
|
|
512
509
|
}
|
|
513
510
|
}));
|
|
514
511
|
}
|
|
@@ -535,7 +532,7 @@ export async function getRelayChainPoolMemberMetadata(chainInfo, address, substr
|
|
|
535
532
|
});
|
|
536
533
|
const bnActiveStake = new BN(poolMemberInfo.points.toString());
|
|
537
534
|
if (!bnActiveStake.gt(BN_ZERO)) {
|
|
538
|
-
stakingStatus =
|
|
535
|
+
stakingStatus = StakingStatus.NOT_EARNING;
|
|
539
536
|
}
|
|
540
537
|
return {
|
|
541
538
|
chain: chainInfo.slug,
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
/// <reference types="bn.js" />
|
|
2
2
|
import { _ChainInfo } from '@subwallet/chain-list/types';
|
|
3
|
-
import { NominationInfo, NominatorMetadata, StakingType, UnstakingInfo } from '@subwallet/extension-base/background/KoniTypes';
|
|
3
|
+
import { NominationInfo, NominatorMetadata, StakingStatus, StakingType, UnstakingInfo } from '@subwallet/extension-base/background/KoniTypes';
|
|
4
4
|
import { _SubstrateInflationParams } from '@subwallet/extension-base/services/chain-service/constants';
|
|
5
|
-
import {
|
|
5
|
+
import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
6
6
|
import { ApiPromise } from '@polkadot/api';
|
|
7
7
|
import { BN } from '@polkadot/util';
|
|
8
|
+
export interface PalletNominationPoolsPoolMember {
|
|
9
|
+
poolId: number;
|
|
10
|
+
points: number;
|
|
11
|
+
lasRecordedRewardCounter: number;
|
|
12
|
+
unbondingEras: Record<string, number>;
|
|
13
|
+
}
|
|
8
14
|
export interface PalletDappsStakingDappInfo {
|
|
9
15
|
address: string;
|
|
10
16
|
name: string;
|
|
@@ -33,6 +39,10 @@ export interface ParachainStakingStakeOption {
|
|
|
33
39
|
owner: string;
|
|
34
40
|
amount: number;
|
|
35
41
|
}
|
|
42
|
+
export interface KrestDelegateState {
|
|
43
|
+
delegations: ParachainStakingStakeOption[];
|
|
44
|
+
total: string;
|
|
45
|
+
}
|
|
36
46
|
export interface ParachainStakingCandidateMetadata {
|
|
37
47
|
bond: string;
|
|
38
48
|
delegationCount: number;
|
|
@@ -61,6 +71,15 @@ export interface PalletParachainStakingDelegator {
|
|
|
61
71
|
lessTotal: number;
|
|
62
72
|
status: number;
|
|
63
73
|
}
|
|
74
|
+
export interface PalletStakingExposureItem {
|
|
75
|
+
who: string;
|
|
76
|
+
value: number;
|
|
77
|
+
}
|
|
78
|
+
export interface PalletStakingExposure {
|
|
79
|
+
total: number;
|
|
80
|
+
own: number;
|
|
81
|
+
others: PalletStakingExposureItem[];
|
|
82
|
+
}
|
|
64
83
|
export interface PalletIdentityRegistration {
|
|
65
84
|
judgements: any[];
|
|
66
85
|
deposit: number;
|
|
@@ -82,12 +101,32 @@ export interface PalletIdentityRegistration {
|
|
|
82
101
|
export declare type PalletIdentitySuper = [string, {
|
|
83
102
|
Raw: string;
|
|
84
103
|
}];
|
|
104
|
+
export interface ValidatorExtraInfo {
|
|
105
|
+
commission: string;
|
|
106
|
+
blocked: false;
|
|
107
|
+
identity?: string;
|
|
108
|
+
isVerified: boolean;
|
|
109
|
+
}
|
|
85
110
|
export interface Unlocking {
|
|
86
111
|
remainingEras: BN;
|
|
87
112
|
value: BN;
|
|
88
113
|
}
|
|
114
|
+
export interface TernoaStakingRewardsStakingRewardsData {
|
|
115
|
+
sessionEraPayout: string;
|
|
116
|
+
sessionExtraRewardPayout: string;
|
|
117
|
+
}
|
|
89
118
|
export declare function parsePoolStashAddress(api: ApiPromise, index: number, poolId: number, poolsPalletId: string): string;
|
|
90
119
|
export declare function transformPoolName(input: string): string;
|
|
120
|
+
/**
|
|
121
|
+
* @returns
|
|
122
|
+
* <p>
|
|
123
|
+
* [0] - identity
|
|
124
|
+
* </p>
|
|
125
|
+
* <p>
|
|
126
|
+
* [1] - isReasonable (isVerified)
|
|
127
|
+
* </p>
|
|
128
|
+
* */
|
|
129
|
+
export declare function parseIdentity(substrateApi: _SubstrateApi, address: string, children?: string): Promise<[string | undefined, boolean]>;
|
|
91
130
|
export declare function getInflationParams(networkKey: string): _SubstrateInflationParams;
|
|
92
131
|
export declare function calcInflationUniformEraPayout(totalIssuance: BN, yearlyInflationInTokens: number): number;
|
|
93
132
|
export declare function calcInflationRewardCurve(minInflation: number, stakedFraction: number, idealStake: number, idealInterest: number, falloff: number): number;
|
|
@@ -125,18 +164,6 @@ export declare function getBondedValidators(nominations: NominationInfo[]): {
|
|
|
125
164
|
bondedValidators: string[];
|
|
126
165
|
};
|
|
127
166
|
export declare function isUnstakeAll(selectedValidator: string, nominations: NominationInfo[], unstakeAmount: string): boolean;
|
|
128
|
-
export declare enum YieldAction {
|
|
129
|
-
STAKE = "STAKE",
|
|
130
|
-
UNSTAKE = "UNSTAKE",
|
|
131
|
-
WITHDRAW = "WITHDRAW",
|
|
132
|
-
CLAIM_REWARD = "CLAIM_REWARD",
|
|
133
|
-
CANCEL_UNSTAKE = "CANCEL_UNSTAKE",
|
|
134
|
-
START_EARNING = "EARN",
|
|
135
|
-
WITHDRAW_EARNING = "WITHDRAW_EARNING",
|
|
136
|
-
CUSTOM_ACTION = "CUSTOM_ACTION"
|
|
137
|
-
}
|
|
138
|
-
export declare function getYieldAvailableActionsByType(yieldPoolInfo: YieldPoolInfo): YieldAction[];
|
|
139
|
-
export declare function getYieldAvailableActionsByPosition(yieldPosition: YieldPositionInfo, yieldPoolInfo: YieldPoolInfo, unclaimedReward?: string): YieldAction[];
|
|
140
167
|
export declare enum StakingAction {
|
|
141
168
|
STAKE = "STAKE",
|
|
142
169
|
UNSTAKE = "UNSTAKE",
|
|
@@ -148,7 +175,7 @@ export declare function getStakingAvailableActionsByChain(chain: string, type: S
|
|
|
148
175
|
export declare function getStakingAvailableActionsByNominator(nominatorMetadata: NominatorMetadata, unclaimedReward?: string): StakingAction[];
|
|
149
176
|
export declare function isActionFromValidator(stakingType: StakingType, chain: string): boolean;
|
|
150
177
|
export declare function getWithdrawalInfo(nominatorMetadata: NominatorMetadata): UnstakingInfo | undefined;
|
|
151
|
-
export declare function
|
|
178
|
+
export declare function getStakingStatusByNominations(bnTotalActiveStake: BN, nominationList: NominationInfo[]): StakingStatus;
|
|
152
179
|
export declare function getValidatorLabel(chain: string): "dApp" | "Validator" | "Collator";
|
|
153
180
|
export declare const getMinStakeErrorMessage: (chainInfo: _ChainInfo, bnMinStake: BN) => string;
|
|
154
181
|
export declare const getMaxValidatorErrorMessage: (chainInfo: _ChainInfo, max: number) => string;
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { StakingType } from '@subwallet/extension-base/background/KoniTypes';
|
|
4
|
+
import { StakingStatus, StakingType, UnstakingStatus } from '@subwallet/extension-base/background/KoniTypes';
|
|
5
5
|
import { getAstarWithdrawable } from '@subwallet/extension-base/koni/api/staking/bonding/astar';
|
|
6
|
-
import { _KNOWN_CHAIN_INFLATION_PARAMS, _SUBSTRATE_DEFAULT_INFLATION_PARAMS } from '@subwallet/extension-base/services/chain-service/constants';
|
|
6
|
+
import { _KNOWN_CHAIN_INFLATION_PARAMS, _STAKING_CHAIN_GROUP, _SUBSTRATE_DEFAULT_INFLATION_PARAMS } from '@subwallet/extension-base/services/chain-service/constants';
|
|
7
7
|
import { _getChainNativeTokenBasicInfo } from '@subwallet/extension-base/services/chain-service/utils';
|
|
8
|
-
import {
|
|
9
|
-
import { EarningStatus, UnstakingStatus, YieldPoolType } from '@subwallet/extension-base/types';
|
|
10
|
-
import { detectTranslate, parseRawNumber, reformatAddress } from '@subwallet/extension-base/utils';
|
|
8
|
+
import { detectTranslate, isSameAddress, parseRawNumber, reformatAddress } from '@subwallet/extension-base/utils';
|
|
11
9
|
import { balanceFormatter, formatNumber } from '@subwallet/extension-base/utils/number';
|
|
12
10
|
import { t } from 'i18next';
|
|
13
|
-
import { BN, BN_BILLION, BN_HUNDRED, BN_MILLION, BN_THOUSAND, BN_ZERO, bnToU8a, stringToU8a, u8aConcat } from '@polkadot/util';
|
|
11
|
+
import { BN, BN_BILLION, BN_HUNDRED, BN_MILLION, BN_THOUSAND, BN_ZERO, bnToU8a, hexToString, isHex, stringToU8a, u8aConcat } from '@polkadot/util';
|
|
14
12
|
export let PalletParachainStakingRequestType;
|
|
15
13
|
(function (PalletParachainStakingRequestType) {
|
|
16
14
|
PalletParachainStakingRequestType["REVOKE"] = "revoke";
|
|
@@ -29,6 +27,64 @@ export function parsePoolStashAddress(api, index, poolId, poolsPalletId) {
|
|
|
29
27
|
export function transformPoolName(input) {
|
|
30
28
|
return input.replace(/[^\x20-\x7E]/g, '');
|
|
31
29
|
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @returns
|
|
33
|
+
* <p>
|
|
34
|
+
* [0] - identity
|
|
35
|
+
* </p>
|
|
36
|
+
* <p>
|
|
37
|
+
* [1] - isReasonable (isVerified)
|
|
38
|
+
* </p>
|
|
39
|
+
* */
|
|
40
|
+
export async function parseIdentity(substrateApi, address, children) {
|
|
41
|
+
const compactResult = rs => {
|
|
42
|
+
const result = [];
|
|
43
|
+
if (rs) {
|
|
44
|
+
result.push(rs);
|
|
45
|
+
}
|
|
46
|
+
if (children) {
|
|
47
|
+
result.push(children);
|
|
48
|
+
}
|
|
49
|
+
if (result.length > 0) {
|
|
50
|
+
return result.join('/');
|
|
51
|
+
} else {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
if (substrateApi.api.query.identity) {
|
|
56
|
+
let identity;
|
|
57
|
+
const _parent = await substrateApi.api.query.identity.superOf(address);
|
|
58
|
+
const parentInfo = _parent.toHuman();
|
|
59
|
+
if (parentInfo) {
|
|
60
|
+
const [parentAddress, {
|
|
61
|
+
Raw: data
|
|
62
|
+
}] = parentInfo;
|
|
63
|
+
const child = isHex(data) ? hexToString(data) : data;
|
|
64
|
+
if (!isSameAddress(address, parentAddress)) {
|
|
65
|
+
const [rs, isReasonable] = await parseIdentity(substrateApi, parentAddress, child);
|
|
66
|
+
return [compactResult(rs), isReasonable];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const _identity = await substrateApi.api.query.identity.identityOf(address);
|
|
70
|
+
const identityInfo = _identity.toHuman();
|
|
71
|
+
if (identityInfo) {
|
|
72
|
+
var _identityInfo$info, _identityInfo$info$di, _identityInfo$info2, _identityInfo$info2$w, _identityInfo$info3, _identityInfo$info3$r, _identityInfo$info4, _identityInfo$info4$t;
|
|
73
|
+
const displayName = (_identityInfo$info = identityInfo.info) === null || _identityInfo$info === void 0 ? void 0 : (_identityInfo$info$di = _identityInfo$info.display) === null || _identityInfo$info$di === void 0 ? void 0 : _identityInfo$info$di.Raw;
|
|
74
|
+
const web = (_identityInfo$info2 = identityInfo.info) === null || _identityInfo$info2 === void 0 ? void 0 : (_identityInfo$info2$w = _identityInfo$info2.web) === null || _identityInfo$info2$w === void 0 ? void 0 : _identityInfo$info2$w.Raw;
|
|
75
|
+
const riot = (_identityInfo$info3 = identityInfo.info) === null || _identityInfo$info3 === void 0 ? void 0 : (_identityInfo$info3$r = _identityInfo$info3.riot) === null || _identityInfo$info3$r === void 0 ? void 0 : _identityInfo$info3$r.Raw;
|
|
76
|
+
const twitter = (_identityInfo$info4 = identityInfo.info) === null || _identityInfo$info4 === void 0 ? void 0 : (_identityInfo$info4$t = _identityInfo$info4.twitter) === null || _identityInfo$info4$t === void 0 ? void 0 : _identityInfo$info4$t.Raw;
|
|
77
|
+
const isReasonable = identityInfo.judgements.length > 0;
|
|
78
|
+
if (displayName) {
|
|
79
|
+
identity = isHex(displayName) ? hexToString(displayName) : displayName;
|
|
80
|
+
} else {
|
|
81
|
+
identity = twitter || web || riot;
|
|
82
|
+
}
|
|
83
|
+
return [compactResult(identity), isReasonable];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return [undefined, false];
|
|
87
|
+
}
|
|
32
88
|
export function getInflationParams(networkKey) {
|
|
33
89
|
return _KNOWN_CHAIN_INFLATION_PARAMS[networkKey] || _SUBSTRATE_DEFAULT_INFLATION_PARAMS;
|
|
34
90
|
}
|
|
@@ -142,78 +198,6 @@ export function isUnstakeAll(selectedValidator, nominations, unstakeAmount) {
|
|
|
142
198
|
}
|
|
143
199
|
return isUnstakeAll;
|
|
144
200
|
}
|
|
145
|
-
export let YieldAction;
|
|
146
|
-
(function (YieldAction) {
|
|
147
|
-
YieldAction["STAKE"] = "STAKE";
|
|
148
|
-
YieldAction["UNSTAKE"] = "UNSTAKE";
|
|
149
|
-
YieldAction["WITHDRAW"] = "WITHDRAW";
|
|
150
|
-
YieldAction["CLAIM_REWARD"] = "CLAIM_REWARD";
|
|
151
|
-
YieldAction["CANCEL_UNSTAKE"] = "CANCEL_UNSTAKE";
|
|
152
|
-
YieldAction["START_EARNING"] = "EARN";
|
|
153
|
-
YieldAction["WITHDRAW_EARNING"] = "WITHDRAW_EARNING";
|
|
154
|
-
YieldAction["CUSTOM_ACTION"] = "CUSTOM_ACTION";
|
|
155
|
-
})(YieldAction || (YieldAction = {}));
|
|
156
|
-
export function getYieldAvailableActionsByType(yieldPoolInfo) {
|
|
157
|
-
if ([YieldPoolType.NATIVE_STAKING, YieldPoolType.NOMINATION_POOL].includes(yieldPoolInfo.type)) {
|
|
158
|
-
if (yieldPoolInfo.type === YieldPoolType.NOMINATION_POOL) {
|
|
159
|
-
return [YieldAction.STAKE, YieldAction.CLAIM_REWARD, YieldAction.UNSTAKE, YieldAction.WITHDRAW];
|
|
160
|
-
}
|
|
161
|
-
const chain = yieldPoolInfo.chain;
|
|
162
|
-
if (_STAKING_CHAIN_GROUP.para.includes(chain)) {
|
|
163
|
-
return [YieldAction.STAKE, YieldAction.UNSTAKE, YieldAction.WITHDRAW, YieldAction.CANCEL_UNSTAKE];
|
|
164
|
-
} else if (_STAKING_CHAIN_GROUP.astar.includes(chain)) {
|
|
165
|
-
return [YieldAction.STAKE, YieldAction.CLAIM_REWARD, YieldAction.UNSTAKE, YieldAction.WITHDRAW];
|
|
166
|
-
} else if (_STAKING_CHAIN_GROUP.amplitude.includes(chain)) {
|
|
167
|
-
return [YieldAction.STAKE, YieldAction.UNSTAKE, YieldAction.WITHDRAW];
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
if (yieldPoolInfo.type === YieldPoolType.LENDING) {
|
|
171
|
-
return [YieldAction.START_EARNING, YieldAction.WITHDRAW_EARNING];
|
|
172
|
-
} else if (yieldPoolInfo.type === YieldPoolType.LIQUID_STAKING) {
|
|
173
|
-
return [YieldAction.START_EARNING, YieldAction.UNSTAKE, YieldAction.WITHDRAW];
|
|
174
|
-
}
|
|
175
|
-
return [YieldAction.STAKE, YieldAction.UNSTAKE, YieldAction.WITHDRAW, YieldAction.CANCEL_UNSTAKE];
|
|
176
|
-
}
|
|
177
|
-
export function getYieldAvailableActionsByPosition(yieldPosition, yieldPoolInfo, unclaimedReward) {
|
|
178
|
-
const result = [];
|
|
179
|
-
if ([YieldPoolType.NATIVE_STAKING, YieldPoolType.NOMINATION_POOL].includes(yieldPoolInfo.type)) {
|
|
180
|
-
result.push(YieldAction.STAKE);
|
|
181
|
-
const bnActiveStake = new BN(yieldPosition.activeStake);
|
|
182
|
-
if (yieldPosition.activeStake && bnActiveStake.gt(BN_ZERO)) {
|
|
183
|
-
result.push(YieldAction.UNSTAKE);
|
|
184
|
-
const isAstarNetwork = _STAKING_CHAIN_GROUP.astar.includes(yieldPosition.chain);
|
|
185
|
-
const isAmplitudeNetwork = _STAKING_CHAIN_GROUP.amplitude.includes(yieldPosition.chain);
|
|
186
|
-
const bnUnclaimedReward = new BN(unclaimedReward || '0');
|
|
187
|
-
if ((yieldPosition.type === YieldPoolType.NOMINATION_POOL || isAmplitudeNetwork) && bnUnclaimedReward.gt(BN_ZERO) || isAstarNetwork) {
|
|
188
|
-
result.push(YieldAction.CLAIM_REWARD);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
if (yieldPosition.unstakings.length > 0) {
|
|
192
|
-
result.push(YieldAction.CANCEL_UNSTAKE);
|
|
193
|
-
const hasClaimable = yieldPosition.unstakings.some(unstaking => unstaking.status === UnstakingStatus.CLAIMABLE);
|
|
194
|
-
if (hasClaimable) {
|
|
195
|
-
result.push(YieldAction.WITHDRAW);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
} else if (yieldPoolInfo.type === YieldPoolType.LIQUID_STAKING) {
|
|
199
|
-
result.push(YieldAction.START_EARNING);
|
|
200
|
-
const activeBalance = new BN(yieldPosition.activeStake || '0');
|
|
201
|
-
if (activeBalance.gt(BN_ZERO)) {
|
|
202
|
-
result.push(YieldAction.UNSTAKE);
|
|
203
|
-
}
|
|
204
|
-
const hasWithdrawal = yieldPosition.unstakings.some(unstakingInfo => unstakingInfo.status === UnstakingStatus.CLAIMABLE);
|
|
205
|
-
if (hasWithdrawal) {
|
|
206
|
-
result.push(YieldAction.WITHDRAW);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
// TODO: check has unstakings to withdraw
|
|
210
|
-
} else {
|
|
211
|
-
result.push(YieldAction.START_EARNING);
|
|
212
|
-
result.push(YieldAction.WITHDRAW_EARNING); // TODO
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
return result;
|
|
216
|
-
}
|
|
217
201
|
export let StakingAction;
|
|
218
202
|
(function (StakingAction) {
|
|
219
203
|
StakingAction["STAKE"] = "STAKE";
|
|
@@ -257,7 +241,7 @@ export function getStakingAvailableActionsByNominator(nominatorMetadata, unclaim
|
|
|
257
241
|
return result;
|
|
258
242
|
}
|
|
259
243
|
export function isActionFromValidator(stakingType, chain) {
|
|
260
|
-
if (stakingType === StakingType.POOLED
|
|
244
|
+
if (stakingType === StakingType.POOLED) {
|
|
261
245
|
return false;
|
|
262
246
|
}
|
|
263
247
|
if (_STAKING_CHAIN_GROUP.astar.includes(chain)) {
|
|
@@ -283,21 +267,21 @@ export function getWithdrawalInfo(nominatorMetadata) {
|
|
|
283
267
|
}
|
|
284
268
|
return result;
|
|
285
269
|
}
|
|
286
|
-
export function
|
|
287
|
-
let stakingStatus =
|
|
270
|
+
export function getStakingStatusByNominations(bnTotalActiveStake, nominationList) {
|
|
271
|
+
let stakingStatus = StakingStatus.EARNING_REWARD;
|
|
288
272
|
if (bnTotalActiveStake.isZero()) {
|
|
289
|
-
stakingStatus =
|
|
273
|
+
stakingStatus = StakingStatus.NOT_EARNING;
|
|
290
274
|
} else {
|
|
291
275
|
let invalidDelegationCount = 0;
|
|
292
276
|
for (const nomination of nominationList) {
|
|
293
|
-
if (nomination.status ===
|
|
277
|
+
if (nomination.status === StakingStatus.NOT_EARNING) {
|
|
294
278
|
invalidDelegationCount += 1;
|
|
295
279
|
}
|
|
296
280
|
}
|
|
297
281
|
if (invalidDelegationCount > 0 && invalidDelegationCount < nominationList.length) {
|
|
298
|
-
stakingStatus =
|
|
282
|
+
stakingStatus = StakingStatus.PARTIALLY_EARNING;
|
|
299
283
|
} else if (invalidDelegationCount === nominationList.length) {
|
|
300
|
-
stakingStatus =
|
|
284
|
+
stakingStatus = StakingStatus.NOT_EARNING;
|
|
301
285
|
}
|
|
302
286
|
}
|
|
303
287
|
return stakingStatus;
|
|
@@ -4,9 +4,8 @@
|
|
|
4
4
|
import { getAmplitudeStakingOnChain, getAstarStakingOnChain, getParaStakingOnChain } from '@subwallet/extension-base/koni/api/staking/paraChain';
|
|
5
5
|
import { getNominationPoolReward, getRelayPoolingOnChain, getRelayStakingOnChain } from '@subwallet/extension-base/koni/api/staking/relayChain';
|
|
6
6
|
import { getAllSubsquidStaking } from '@subwallet/extension-base/koni/api/staking/subsquidStaking';
|
|
7
|
-
import { _PURE_EVM_CHAINS } from '@subwallet/extension-base/services/chain-service/constants';
|
|
7
|
+
import { _PURE_EVM_CHAINS, _STAKING_CHAIN_GROUP } from '@subwallet/extension-base/services/chain-service/constants';
|
|
8
8
|
import { _isChainEvmCompatible, _isChainSupportSubstrateStaking, _isSubstrateRelayChain } from '@subwallet/extension-base/services/chain-service/utils';
|
|
9
|
-
import { _STAKING_CHAIN_GROUP } from '@subwallet/extension-base/services/earning-service/constants';
|
|
10
9
|
import { categoryAddresses } from '@subwallet/extension-base/utils';
|
|
11
10
|
export function stakingOnChainApi(addresses, substrateApiMap, chainInfoMap, stakingCallback, nominatorStateCallback) {
|
|
12
11
|
const filteredApiMap = [];
|
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { APIItemState, StakingType } from '@subwallet/extension-base/background/KoniTypes';
|
|
4
|
+
import { APIItemState, StakingStatus, StakingType } from '@subwallet/extension-base/background/KoniTypes';
|
|
5
5
|
import { subscribeAmplitudeNominatorMetadata } from '@subwallet/extension-base/koni/api/staking/bonding/amplitude';
|
|
6
6
|
import { subscribeAstarNominatorMetadata } from '@subwallet/extension-base/koni/api/staking/bonding/astar';
|
|
7
7
|
import { subscribeParaChainNominatorMetadata } from '@subwallet/extension-base/koni/api/staking/bonding/paraChain';
|
|
8
|
+
import { _STAKING_CHAIN_GROUP } from '@subwallet/extension-base/services/chain-service/constants';
|
|
8
9
|
import { _getChainNativeTokenBasicInfo } from '@subwallet/extension-base/services/chain-service/utils';
|
|
9
|
-
import { _STAKING_CHAIN_GROUP } from '@subwallet/extension-base/services/earning-service/constants';
|
|
10
|
-
import { EarningStatus } from '@subwallet/extension-base/types';
|
|
11
10
|
import { reformatAddress } from '@subwallet/extension-base/utils';
|
|
12
11
|
import { BN, BN_ZERO } from '@polkadot/util';
|
|
13
12
|
import { isEthereumAddress } from '@polkadot/util-crypto';
|
|
14
13
|
function getSingleStakingAmplitude(substrateApi, address, chainInfoMap, chain, stakingCallback, nominatorStateCallback) {
|
|
15
14
|
return substrateApi.api.queryMulti([[substrateApi.api.query.parachainStaking.delegatorState, address], [substrateApi.api.query.parachainStaking.unstaking, address]], async ([_delegatorState, _unstaking]) => {
|
|
16
|
-
|
|
15
|
+
let delegatorState = [];
|
|
16
|
+
if (_STAKING_CHAIN_GROUP.krest_network.includes(chain)) {
|
|
17
|
+
const krestDelegatorState = _delegatorState.toPrimitive();
|
|
18
|
+
const delegates = krestDelegatorState === null || krestDelegatorState === void 0 ? void 0 : krestDelegatorState.delegations;
|
|
19
|
+
delegatorState = delegatorState.concat(delegates);
|
|
20
|
+
} else {
|
|
21
|
+
const delegate = _delegatorState.toPrimitive();
|
|
22
|
+
delegatorState.push(delegate);
|
|
23
|
+
}
|
|
17
24
|
const unstakingInfo = _unstaking.toPrimitive();
|
|
18
25
|
const {
|
|
19
26
|
symbol
|
|
@@ -36,14 +43,19 @@ function getSingleStakingAmplitude(substrateApi, address, chainInfoMap, chain, s
|
|
|
36
43
|
chain,
|
|
37
44
|
type: StakingType.NOMINATED,
|
|
38
45
|
address: owner,
|
|
39
|
-
status:
|
|
46
|
+
status: StakingStatus.NOT_STAKING,
|
|
40
47
|
activeStake: '0',
|
|
41
48
|
nominations: [],
|
|
42
49
|
unstakings: []
|
|
43
50
|
});
|
|
44
51
|
} else {
|
|
45
|
-
|
|
52
|
+
let activeBalance = BN_ZERO;
|
|
46
53
|
let unstakingBalance = BN_ZERO;
|
|
54
|
+
for (const delegate of delegatorState) {
|
|
55
|
+
var _delegate$amount;
|
|
56
|
+
const amount = new BN((_delegate$amount = delegate.amount) === null || _delegate$amount === void 0 ? void 0 : _delegate$amount.toString());
|
|
57
|
+
activeBalance = activeBalance.add(amount);
|
|
58
|
+
}
|
|
47
59
|
if (unstakingInfo) {
|
|
48
60
|
Object.values(unstakingInfo).forEach(unstakingAmount => {
|
|
49
61
|
const bnUnstakingAmount = new BN(unstakingAmount.toString());
|
|
@@ -78,7 +90,15 @@ function getMultiStakingAmplitude(substrateApi, useAddresses, chainInfoMap, chai
|
|
|
78
90
|
const _unstakingStates = await substrateApi.api.query.parachainStaking.unstaking.multi(useAddresses);
|
|
79
91
|
await Promise.all(ledgers.map(async (_delegatorState, i) => {
|
|
80
92
|
const owner = reformatAddress(useAddresses[i], 42);
|
|
81
|
-
|
|
93
|
+
let delegatorState = [];
|
|
94
|
+
if (_STAKING_CHAIN_GROUP.krest_network.includes(chain)) {
|
|
95
|
+
const krestDelegatorState = _delegatorState.toPrimitive();
|
|
96
|
+
const delegates = krestDelegatorState === null || krestDelegatorState === void 0 ? void 0 : krestDelegatorState.delegations;
|
|
97
|
+
delegatorState = delegatorState.concat(delegates);
|
|
98
|
+
} else {
|
|
99
|
+
const delegate = _delegatorState.toPrimitive();
|
|
100
|
+
delegatorState.push(delegate);
|
|
101
|
+
}
|
|
82
102
|
const unstakingInfo = _unstakingStates[i].toPrimitive();
|
|
83
103
|
if (!delegatorState && !unstakingInfo) {
|
|
84
104
|
stakingCallback(chain, {
|
|
@@ -97,14 +117,19 @@ function getMultiStakingAmplitude(substrateApi, useAddresses, chainInfoMap, chai
|
|
|
97
117
|
chain,
|
|
98
118
|
type: StakingType.NOMINATED,
|
|
99
119
|
address: owner,
|
|
100
|
-
status:
|
|
120
|
+
status: StakingStatus.NOT_STAKING,
|
|
101
121
|
activeStake: '0',
|
|
102
122
|
nominations: [],
|
|
103
123
|
unstakings: []
|
|
104
124
|
});
|
|
105
125
|
} else {
|
|
106
|
-
|
|
126
|
+
let activeBalance = BN_ZERO;
|
|
107
127
|
let unstakingBalance = BN_ZERO;
|
|
128
|
+
for (const delegate of delegatorState) {
|
|
129
|
+
var _delegate$amount2;
|
|
130
|
+
const amount = new BN((_delegate$amount2 = delegate.amount) === null || _delegate$amount2 === void 0 ? void 0 : _delegate$amount2.toString());
|
|
131
|
+
activeBalance = activeBalance.add(amount);
|
|
132
|
+
}
|
|
108
133
|
if (unstakingInfo) {
|
|
109
134
|
Object.values(unstakingInfo).forEach(unstakingAmount => {
|
|
110
135
|
const bnUnstakingAmount = new BN(unstakingAmount.toString());
|
|
@@ -150,7 +175,7 @@ export async function getAmplitudeUnclaimedStakingReward(substrateApiMap, addres
|
|
|
150
175
|
});
|
|
151
176
|
const unclaimedRewardList = [];
|
|
152
177
|
await Promise.all(chains.map(async chain => {
|
|
153
|
-
if (_STAKING_CHAIN_GROUP.amplitude.includes(chain) && !_STAKING_CHAIN_GROUP.kilt.includes(chain)) {
|
|
178
|
+
if (_STAKING_CHAIN_GROUP.amplitude.includes(chain) && !_STAKING_CHAIN_GROUP.kilt.includes(chain) && !_STAKING_CHAIN_GROUP.krest_network.includes(chain)) {
|
|
154
179
|
const networkInfo = networks[chain];
|
|
155
180
|
const apiProps = await substrateApiMap[chain].isReady;
|
|
156
181
|
await Promise.all(useAddresses.map(async address => {
|
|
@@ -215,7 +240,7 @@ export function getParaStakingOnChain(substrateApi, useAddresses, chainInfoMap,
|
|
|
215
240
|
chain,
|
|
216
241
|
type: StakingType.NOMINATED,
|
|
217
242
|
address: owner,
|
|
218
|
-
status:
|
|
243
|
+
status: StakingStatus.NOT_STAKING,
|
|
219
244
|
activeStake: '0',
|
|
220
245
|
nominations: [],
|
|
221
246
|
unstakings: []
|
|
@@ -275,7 +300,7 @@ export function getAstarStakingOnChain(substrateApi, useAddresses, chainInfoMap,
|
|
|
275
300
|
chain,
|
|
276
301
|
type: StakingType.NOMINATED,
|
|
277
302
|
address: owner,
|
|
278
|
-
status:
|
|
303
|
+
status: StakingStatus.NOT_STAKING,
|
|
279
304
|
activeStake: '0',
|
|
280
305
|
nominations: [],
|
|
281
306
|
unstakings: []
|