@subwallet/extension-base 1.0.1 → 1.0.2-1b
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 +25 -36
- package/background/KoniTypes.js +12 -7
- package/background/errors/TransactionError.js +21 -1
- package/cjs/background/KoniTypes.js +14 -8
- package/cjs/background/errors/TransactionError.js +20 -0
- package/cjs/constants/index.js +13 -28
- package/cjs/koni/api/dotsama/balance.js +60 -224
- package/cjs/koni/api/dotsama/transfer.js +30 -29
- package/cjs/koni/api/nft/acala_nft/index.js +4 -1
- package/cjs/koni/api/nft/bit.country/index.js +4 -1
- package/cjs/koni/api/nft/evm_nft/index.js +7 -3
- package/cjs/koni/api/nft/index.js +3 -6
- package/cjs/koni/api/nft/karura_nft/index.js +4 -1
- package/cjs/koni/api/nft/rmrk_nft/index.js +8 -1
- package/cjs/koni/api/nft/statemine_nft/index.js +4 -1
- package/cjs/koni/api/nft/unique_nft/index.js +6 -1
- package/cjs/koni/api/nft/wasm_nft/index.js +169 -111
- package/cjs/koni/api/nft/wasm_nft/utils.js +11 -7
- package/cjs/koni/api/staking/bonding/amplitude.js +18 -10
- package/cjs/koni/api/staking/bonding/astar.js +37 -238
- package/cjs/koni/api/staking/bonding/index.js +26 -14
- package/cjs/koni/api/staking/bonding/paraChain.js +100 -11
- package/cjs/koni/api/staking/bonding/relayChain.js +174 -16
- package/cjs/koni/api/staking/bonding/utils.js +55 -10
- package/cjs/koni/api/tokens/wasm/index.js +5 -4
- package/cjs/koni/api/tokens/wasm/utils.js +63 -0
- package/cjs/koni/api/xcm/index.js +0 -111
- package/cjs/koni/api/xcm/polkadotXcm.js +2 -2
- package/cjs/koni/api/xcm/utils.js +18 -13
- package/cjs/koni/api/xcm/xTokens.js +3 -5
- package/cjs/koni/api/xcm/xcmPallet.js +9 -6
- package/cjs/koni/background/cron.js +179 -77
- package/cjs/koni/background/handlers/Extension.js +231 -195
- package/cjs/koni/background/handlers/State.js +147 -111
- package/cjs/koni/background/handlers/Tabs.js +48 -39
- package/cjs/koni/background/subscription.js +64 -56
- 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/handler/SubstrateChainHandler.js +13 -8
- package/cjs/services/chain-service/handler/light-client/index.js +2 -0
- package/cjs/services/chain-service/index.js +39 -6
- package/cjs/services/chain-service/utils.js +4 -0
- package/cjs/services/event-service/index.js +75 -0
- package/cjs/services/event-service/types.js +11 -0
- package/cjs/services/history-service/index.js +46 -21
- package/cjs/services/history-service/subsquid-multi-chain-history.js +19 -11
- 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 +15 -3
- package/cjs/services/price-service/index.js +15 -18
- package/cjs/services/request-service/constants.js +8 -2
- package/cjs/services/request-service/handler/AuthRequestHandler.js +43 -12
- package/cjs/services/request-service/index.js +3 -0
- package/cjs/services/storage-service/DatabaseService.js +53 -34
- 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 +8 -18
- 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/event-parser/index.js +20 -48
- package/cjs/services/transaction-service/index.js +66 -22
- package/cjs/services/transaction-service/utils.js +4 -6
- package/cjs/utils/address.js +9 -1
- package/cjs/utils/index.js +30 -26
- package/constants/index.d.ts +8 -13
- package/constants/index.js +8 -13
- package/koni/api/dotsama/balance.d.ts +0 -1
- package/koni/api/dotsama/balance.js +33 -197
- package/koni/api/dotsama/transfer.js +5 -4
- package/koni/api/nft/acala_nft/index.js +3 -1
- package/koni/api/nft/bit.country/index.js +3 -1
- package/koni/api/nft/evm_nft/index.js +6 -3
- package/koni/api/nft/index.d.ts +1 -2
- package/koni/api/nft/index.js +3 -6
- package/koni/api/nft/karura_nft/index.js +3 -1
- package/koni/api/nft/nft.d.ts +1 -0
- package/koni/api/nft/rmrk_nft/index.js +8 -1
- package/koni/api/nft/statemine_nft/index.js +3 -1
- package/koni/api/nft/unique_nft/index.js +5 -1
- package/koni/api/nft/wasm_nft/index.d.ts +0 -2
- package/koni/api/nft/wasm_nft/index.js +167 -109
- package/koni/api/nft/wasm_nft/utils.d.ts +7 -5
- package/koni/api/nft/wasm_nft/utils.js +7 -5
- package/koni/api/staking/bonding/amplitude.d.ts +1 -2
- package/koni/api/staking/bonding/amplitude.js +22 -13
- package/koni/api/staking/bonding/astar.d.ts +2 -11
- package/koni/api/staking/bonding/astar.js +39 -231
- package/koni/api/staking/bonding/index.d.ts +5 -2
- package/koni/api/staking/bonding/index.js +27 -17
- package/koni/api/staking/bonding/paraChain.d.ts +4 -1
- package/koni/api/staking/bonding/paraChain.js +101 -14
- package/koni/api/staking/bonding/relayChain.d.ts +6 -2
- package/koni/api/staking/bonding/relayChain.js +172 -17
- package/koni/api/staking/bonding/utils.d.ts +15 -2
- package/koni/api/staking/bonding/utils.js +53 -11
- package/koni/api/tokens/wasm/index.js +5 -4
- package/koni/api/tokens/wasm/utils.d.ts +6 -0
- package/koni/api/tokens/wasm/utils.js +54 -0
- package/koni/api/xcm/index.js +1 -112
- package/koni/api/xcm/polkadotXcm.js +3 -3
- package/koni/api/xcm/utils.d.ts +5 -6
- package/koni/api/xcm/utils.js +15 -10
- package/koni/api/xcm/xTokens.js +5 -7
- package/koni/api/xcm/xcmPallet.js +10 -9
- package/koni/background/cron.d.ts +6 -1
- package/koni/background/cron.js +179 -76
- package/koni/background/handlers/Extension.d.ts +2 -2
- package/koni/background/handlers/Extension.js +161 -125
- package/koni/background/handlers/State.d.ts +21 -20
- package/koni/background/handlers/State.js +144 -111
- package/koni/background/handlers/Tabs.js +30 -20
- package/koni/background/subscription.d.ts +1 -1
- package/koni/background/subscription.js +64 -58
- package/package.json +63 -18
- 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/handler/SubstrateChainHandler.js +14 -9
- package/services/chain-service/handler/light-client/index.d.ts +17 -1
- package/services/chain-service/handler/light-client/index.js +1 -1
- package/services/chain-service/helper/psp22_abi.json +1041 -881
- package/services/chain-service/helper/psp34_abi.json +2963 -1807
- package/services/chain-service/index.d.ts +6 -4
- package/services/chain-service/index.js +40 -9
- 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 +63 -0
- package/services/event-service/types.d.ts +28 -0
- package/services/event-service/types.js +4 -0
- package/services/history-service/index.d.ts +5 -3
- package/services/history-service/index.js +46 -21
- package/services/history-service/subsquid-multi-chain-history.js +22 -13
- 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 +15 -3
- package/services/price-service/index.d.ts +5 -3
- package/services/price-service/index.js +15 -18
- 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 +44 -13
- package/services/request-service/index.d.ts +7 -1
- package/services/request-service/index.js +3 -0
- package/services/storage-service/DatabaseService.d.ts +1 -0
- package/services/storage-service/DatabaseService.js +53 -34
- 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 +3 -3
- package/services/storage-service/db-stores/Nft.js +8 -17
- 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/event-parser/index.js +21 -49
- package/services/transaction-service/index.d.ts +4 -2
- package/services/transaction-service/index.js +66 -22
- 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 +2 -1
- package/utils/index.js +26 -23
- 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
|
@@ -16,24 +16,105 @@ exports.getRelayPoolsInfo = getRelayPoolsInfo;
|
|
|
16
16
|
exports.getRelayUnbondingExtrinsic = getRelayUnbondingExtrinsic;
|
|
17
17
|
exports.getRelayValidatorsInfo = getRelayValidatorsInfo;
|
|
18
18
|
exports.getRelayWithdrawalExtrinsic = getRelayWithdrawalExtrinsic;
|
|
19
|
+
exports.validatePoolBondingCondition = validatePoolBondingCondition;
|
|
20
|
+
exports.validateRelayBondingCondition = validateRelayBondingCondition;
|
|
21
|
+
exports.validateRelayUnbondingCondition = validateRelayUnbondingCondition;
|
|
22
|
+
var _TransactionError = require("@subwallet/extension-base/background/errors/TransactionError");
|
|
19
23
|
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
20
24
|
var _utils = require("@subwallet/extension-base/koni/api/staking/bonding/utils");
|
|
21
25
|
var _constants = require("@subwallet/extension-base/services/chain-service/constants");
|
|
26
|
+
var _utils2 = require("@subwallet/extension-base/services/chain-service/utils");
|
|
27
|
+
var _utils3 = require("@subwallet/extension-base/utils");
|
|
22
28
|
var _util = require("@polkadot/util");
|
|
23
29
|
var _utilCrypto = require("@polkadot/util-crypto");
|
|
24
30
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
25
31
|
// SPDX-License-Identifier: Apache-2.0
|
|
26
32
|
|
|
27
|
-
|
|
28
|
-
|
|
33
|
+
function validateRelayUnbondingCondition(amount, chainStakingMetadata, nominatorMetadata) {
|
|
34
|
+
const errors = [];
|
|
35
|
+
const bnActiveStake = new _util.BN(nominatorMetadata.activeStake);
|
|
36
|
+
const bnRemainingStake = bnActiveStake.sub(new _util.BN(amount));
|
|
37
|
+
const minStake = new _util.BN(chainStakingMetadata.minPoolBonding || '0');
|
|
38
|
+
if (!(bnRemainingStake.isZero() || bnRemainingStake.gte(minStake))) {
|
|
39
|
+
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.INVALID_ACTIVE_STAKE));
|
|
40
|
+
}
|
|
41
|
+
if (nominatorMetadata.unstakings.length > chainStakingMetadata.maxWithdrawalRequestPerValidator) {
|
|
42
|
+
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.EXCEED_MAX_UNSTAKING));
|
|
43
|
+
}
|
|
44
|
+
return errors;
|
|
45
|
+
}
|
|
46
|
+
function validatePoolBondingCondition(chainInfo, amount, selectedPool, address, chainStakingMetadata, nominatorMetadata) {
|
|
47
|
+
// cannot stake when unstake all
|
|
48
|
+
// amount >= min stake
|
|
49
|
+
const errors = [];
|
|
50
|
+
let bnTotalStake = new _util.BN(amount);
|
|
51
|
+
const bnMinStake = new _util.BN(chainStakingMetadata.minPoolBonding || '0');
|
|
52
|
+
if (nominatorMetadata) {
|
|
53
|
+
const bnCurrentActiveStake = new _util.BN(nominatorMetadata.activeStake);
|
|
54
|
+
bnTotalStake = bnTotalStake.add(bnCurrentActiveStake);
|
|
55
|
+
if (!bnCurrentActiveStake.gt(_util.BN_ZERO)) {
|
|
56
|
+
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.EXIST_UNSTAKING_REQUEST));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (!bnTotalStake.gte(bnMinStake)) {
|
|
60
|
+
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.NOT_ENOUGH_MIN_STAKE));
|
|
61
|
+
}
|
|
62
|
+
return errors;
|
|
63
|
+
}
|
|
64
|
+
function validateRelayBondingCondition(chainInfo, amount, selectedValidators, address, chainStakingMetadata, nominatorMetadata) {
|
|
65
|
+
const errors = [];
|
|
66
|
+
let bnTotalStake = new _util.BN(amount);
|
|
67
|
+
const bnMinStake = new _util.BN(chainStakingMetadata.minStake);
|
|
68
|
+
if (!nominatorMetadata) {
|
|
69
|
+
if (!bnTotalStake.gte(bnMinStake)) {
|
|
70
|
+
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.NOT_ENOUGH_MIN_STAKE));
|
|
71
|
+
}
|
|
72
|
+
if (selectedValidators.length > chainStakingMetadata.maxValidatorPerNominator) {
|
|
73
|
+
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.EXCEED_MAX_NOMINATIONS));
|
|
74
|
+
}
|
|
75
|
+
return errors;
|
|
76
|
+
}
|
|
77
|
+
const bnCurrentActiveStake = new _util.BN(nominatorMetadata.activeStake);
|
|
78
|
+
bnTotalStake = bnTotalStake.add(bnCurrentActiveStake);
|
|
79
|
+
if (!bnTotalStake.gte(bnMinStake)) {
|
|
80
|
+
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.NOT_ENOUGH_MIN_STAKE));
|
|
81
|
+
}
|
|
82
|
+
if (selectedValidators.length > chainStakingMetadata.maxValidatorPerNominator) {
|
|
83
|
+
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.EXCEED_MAX_NOMINATIONS));
|
|
84
|
+
}
|
|
85
|
+
return errors;
|
|
86
|
+
}
|
|
87
|
+
async function getRelayChainStakingMetadata(chainInfo, substrateApi) {
|
|
88
|
+
var _chainApi$api$query$a, _chainApi$api$query, _chainApi$api$query$s, _chainApi$api$query2, _chainApi$api$query2$, _chainApi$api$query3, _chainApi$api$query3$;
|
|
89
|
+
const chain = chainInfo.slug;
|
|
90
|
+
const {
|
|
91
|
+
decimals
|
|
92
|
+
} = (0, _utils2._getChainNativeTokenBasicInfo)(chainInfo);
|
|
29
93
|
const chainApi = await substrateApi.isReady;
|
|
30
94
|
const _era = await chainApi.api.query.staking.currentEra();
|
|
31
95
|
const currentEra = _era.toString();
|
|
32
96
|
const maxNominations = chainApi.api.consts.staking.maxNominations.toString();
|
|
33
97
|
const maxUnlockingChunks = chainApi.api.consts.staking.maxUnlockingChunks.toString();
|
|
34
98
|
const unlockingEras = chainApi.api.consts.staking.bondingDuration.toString();
|
|
35
|
-
const [_totalEraStake, _totalIssuance, _auctionCounter, _minimumActiveStake, _minPoolJoin] = 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.staking.minimumActiveStake()
|
|
36
|
-
const
|
|
99
|
+
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))]);
|
|
100
|
+
const eraStakers = _eraStakers;
|
|
101
|
+
const nominatorList = [];
|
|
102
|
+
for (const item of eraStakers) {
|
|
103
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
104
|
+
const rawValidatorStat = item[1].toHuman();
|
|
105
|
+
const eraNominators = rawValidatorStat.others;
|
|
106
|
+
for (const nominator of eraNominators) {
|
|
107
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
108
|
+
if (!nominatorList.includes(nominator.who)) {
|
|
109
|
+
nominatorList.push(nominator.who);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const minActiveStake = (_minimumActiveStake === null || _minimumActiveStake === void 0 ? void 0 : _minimumActiveStake.toString()) || '0';
|
|
114
|
+
const minNominatorBond = _minNominatorBond.toString();
|
|
115
|
+
const bnMinActiveStake = new _util.BN(minActiveStake);
|
|
116
|
+
const bnMinNominatorBond = new _util.BN(minNominatorBond);
|
|
117
|
+
const minStake = bnMinActiveStake.gt(bnMinNominatorBond) ? bnMinActiveStake : bnMinNominatorBond;
|
|
37
118
|
const minPoolJoin = (_minPoolJoin === null || _minPoolJoin === void 0 ? void 0 : _minPoolJoin.toString()) || undefined;
|
|
38
119
|
const rawTotalEraStake = _totalEraStake.toString();
|
|
39
120
|
const rawTotalIssuance = _totalIssuance.toString();
|
|
@@ -51,23 +132,34 @@ async function getRelayChainStakingMetadata(chain, substrateApi) {
|
|
|
51
132
|
expectedReturn,
|
|
52
133
|
// in %, annually
|
|
53
134
|
inflation,
|
|
54
|
-
minStake,
|
|
135
|
+
minStake: minStake.toString(),
|
|
136
|
+
minPoolBonding: (10 ** decimals).toString(),
|
|
137
|
+
// default is 1
|
|
55
138
|
maxValidatorPerNominator: parseInt(maxNominations),
|
|
56
139
|
maxWithdrawalRequestPerValidator: parseInt(maxUnlockingChunks),
|
|
57
140
|
allowCancelUnstaking: true,
|
|
58
141
|
unstakingPeriod: unlockingPeriod,
|
|
59
|
-
minJoinNominationPool: minPoolJoin
|
|
142
|
+
minJoinNominationPool: minPoolJoin,
|
|
143
|
+
nominatorCount: nominatorList.length
|
|
60
144
|
};
|
|
61
145
|
}
|
|
62
146
|
async function getRelayChainNominatorMetadata(chainInfo, address, substrateApi) {
|
|
147
|
+
var _chainApi$api$query4, _chainApi$api$query4$, _chainApi$api$query5, _chainApi$api$query5$, _chainApi$api$query6, _chainApi$api$query6$, _chainApi$api$query7, _chainApi$api$query7$, _chainApi$api$query8, _chainApi$api$query8$, _chainApi$api$query9, _chainApi$api$query9$, _chainApi$api$query10, _chainApi$api$query11;
|
|
63
148
|
if ((0, _utilCrypto.isEthereumAddress)(address)) {
|
|
64
149
|
return;
|
|
65
150
|
}
|
|
66
151
|
const chain = chainInfo.slug;
|
|
67
152
|
const chainApi = await substrateApi.isReady;
|
|
68
|
-
const [_ledger, _nominations, _currentEra, _bonded] = await Promise.all([chainApi.api.query.staking
|
|
69
|
-
const
|
|
70
|
-
const
|
|
153
|
+
const [_ledger, _nominations, _currentEra, _bonded, _minimumActiveStake, _minNominatorBond] = await Promise.all([(_chainApi$api$query4 = chainApi.api.query) === null || _chainApi$api$query4 === void 0 ? void 0 : (_chainApi$api$query4$ = _chainApi$api$query4.staking) === null || _chainApi$api$query4$ === void 0 ? void 0 : _chainApi$api$query4$.ledger(address), (_chainApi$api$query5 = chainApi.api.query) === null || _chainApi$api$query5 === void 0 ? void 0 : (_chainApi$api$query5$ = _chainApi$api$query5.staking) === null || _chainApi$api$query5$ === void 0 ? void 0 : _chainApi$api$query5$.nominators(address), (_chainApi$api$query6 = chainApi.api.query) === null || _chainApi$api$query6 === void 0 ? void 0 : (_chainApi$api$query6$ = _chainApi$api$query6.staking) === null || _chainApi$api$query6$ === void 0 ? void 0 : _chainApi$api$query6$.currentEra(), (_chainApi$api$query7 = chainApi.api.query) === null || _chainApi$api$query7 === void 0 ? void 0 : (_chainApi$api$query7$ = _chainApi$api$query7.staking) === null || _chainApi$api$query7$ === void 0 ? void 0 : _chainApi$api$query7$.bonded(address), ((_chainApi$api$query8 = chainApi.api.query) === null || _chainApi$api$query8 === void 0 ? void 0 : (_chainApi$api$query8$ = _chainApi$api$query8.staking) === null || _chainApi$api$query8$ === void 0 ? void 0 : _chainApi$api$query8$.minimumActiveStake) && ((_chainApi$api$query9 = chainApi.api.query) === null || _chainApi$api$query9 === void 0 ? void 0 : (_chainApi$api$query9$ = _chainApi$api$query9.staking) === null || _chainApi$api$query9$ === void 0 ? void 0 : _chainApi$api$query9$.minimumActiveStake()), (_chainApi$api$query10 = chainApi.api.query) === null || _chainApi$api$query10 === void 0 ? void 0 : (_chainApi$api$query11 = _chainApi$api$query10.staking) === null || _chainApi$api$query11 === void 0 ? void 0 : _chainApi$api$query11.minNominatorBond()]);
|
|
154
|
+
const minActiveStake = (_minimumActiveStake === null || _minimumActiveStake === void 0 ? void 0 : _minimumActiveStake.toString()) || '0';
|
|
155
|
+
const minNominatorBond = _minNominatorBond.toString();
|
|
156
|
+
const bnMinActiveStake = new _util.BN(minActiveStake);
|
|
157
|
+
const bnMinNominatorBond = new _util.BN(minNominatorBond);
|
|
158
|
+
const minStake = bnMinActiveStake.gt(bnMinNominatorBond) ? bnMinActiveStake : bnMinNominatorBond;
|
|
159
|
+
const _maxNominatorRewardedPerValidator = chainApi.api.consts.staking.maxNominatorRewardedPerValidator.toString();
|
|
160
|
+
const maxNominatorRewardedPerValidator = parseInt(_maxNominatorRewardedPerValidator);
|
|
161
|
+
const ledger = _ledger.toPrimitive();
|
|
162
|
+
const nominations = _nominations.toPrimitive();
|
|
71
163
|
const currentEra = _currentEra.toString();
|
|
72
164
|
const bonded = _bonded.toHuman();
|
|
73
165
|
if (!ledger) {
|
|
@@ -79,17 +171,47 @@ async function getRelayChainNominatorMetadata(chainInfo, address, substrateApi)
|
|
|
79
171
|
if (nominations) {
|
|
80
172
|
const validatorList = nominations.targets;
|
|
81
173
|
await Promise.all(validatorList.map(async validatorAddress => {
|
|
82
|
-
|
|
174
|
+
let nominationStatus = _KoniTypes.StakingStatus.NOT_EARNING;
|
|
175
|
+
const [_identityInfo, _eraStaker] = await Promise.all([chainApi.api.query.identity.identityOf(validatorAddress), chainApi.api.query.staking.erasStakers(currentEra, validatorAddress)]);
|
|
176
|
+
const eraStaker = _eraStaker.toPrimitive();
|
|
177
|
+
const identityInfo = _identityInfo.toHuman();
|
|
83
178
|
const identity = (0, _utils.parseIdentity)(identityInfo);
|
|
179
|
+
const topNominators = eraStaker.others.map(nominator => {
|
|
180
|
+
return nominator.who;
|
|
181
|
+
});
|
|
182
|
+
if (!topNominators.includes((0, _utils3.reformatAddress)(address, (0, _utils2._getChainSubstrateAddressPrefix)(chainInfo)))) {
|
|
183
|
+
// if nominator has target but not in nominator list
|
|
184
|
+
nominationStatus = _KoniTypes.StakingStatus.WAITING;
|
|
185
|
+
} else if (topNominators.slice(0, maxNominatorRewardedPerValidator).includes((0, _utils3.reformatAddress)(address, (0, _utils2._getChainSubstrateAddressPrefix)(chainInfo)))) {
|
|
186
|
+
// if address in top nominators
|
|
187
|
+
nominationStatus = _KoniTypes.StakingStatus.EARNING_REWARD;
|
|
188
|
+
}
|
|
84
189
|
nominationList.push({
|
|
85
190
|
chain,
|
|
86
191
|
validatorAddress,
|
|
192
|
+
status: nominationStatus,
|
|
87
193
|
validatorIdentity: identity,
|
|
88
194
|
activeStake: '0' // relaychain allocates stake accordingly
|
|
89
195
|
});
|
|
90
196
|
}));
|
|
91
197
|
}
|
|
92
198
|
|
|
199
|
+
let stakingStatus = _KoniTypes.StakingStatus.NOT_EARNING;
|
|
200
|
+
const bnActiveStake = new _util.BN(activeStake);
|
|
201
|
+
let waitingNominationCount = 0;
|
|
202
|
+
if (bnActiveStake.gte(minStake)) {
|
|
203
|
+
for (const nomination of nominationList) {
|
|
204
|
+
if (nomination.status === _KoniTypes.StakingStatus.EARNING_REWARD) {
|
|
205
|
+
// only need 1 earning nomination to count
|
|
206
|
+
stakingStatus = _KoniTypes.StakingStatus.EARNING_REWARD;
|
|
207
|
+
} else if (nomination.status === _KoniTypes.StakingStatus.WAITING) {
|
|
208
|
+
waitingNominationCount += 1;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
if (waitingNominationCount === nominationList.length) {
|
|
212
|
+
stakingStatus = _KoniTypes.StakingStatus.WAITING;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
93
215
|
ledger.unlocking.forEach(unlockingChunk => {
|
|
94
216
|
const isClaimable = unlockingChunk.era - parseInt(currentEra) <= 0;
|
|
95
217
|
const remainingEra = unlockingChunk.era - (parseInt(currentEra) + 1);
|
|
@@ -104,6 +226,7 @@ async function getRelayChainNominatorMetadata(chainInfo, address, substrateApi)
|
|
|
104
226
|
return {
|
|
105
227
|
chain,
|
|
106
228
|
type: _KoniTypes.StakingType.NOMINATED,
|
|
229
|
+
status: stakingStatus,
|
|
107
230
|
address: address,
|
|
108
231
|
activeStake,
|
|
109
232
|
nominations: nominationList,
|
|
@@ -114,17 +237,39 @@ async function getRelayChainNominatorMetadata(chainInfo, address, substrateApi)
|
|
|
114
237
|
async function getRelayChainPoolMemberMetadata(chainInfo, address, substrateApi) {
|
|
115
238
|
const chainApi = await substrateApi.isReady;
|
|
116
239
|
const [_poolMemberInfo, _currentEra] = await Promise.all([chainApi.api.query.nominationPools.poolMembers(address), chainApi.api.query.staking.currentEra()]);
|
|
240
|
+
const _maxNominatorRewardedPerValidator = chainApi.api.consts.staking.maxNominatorRewardedPerValidator.toString();
|
|
241
|
+
const maxNominatorRewardedPerValidator = parseInt(_maxNominatorRewardedPerValidator);
|
|
242
|
+
const poolsPalletId = chainApi.api.consts.nominationPools.palletId.toString();
|
|
117
243
|
const poolMemberInfo = _poolMemberInfo.toPrimitive();
|
|
118
244
|
const currentEra = _currentEra.toString();
|
|
119
245
|
if (!poolMemberInfo) {
|
|
120
246
|
return;
|
|
121
247
|
}
|
|
248
|
+
let stakingStatus = _KoniTypes.StakingStatus.NOT_EARNING;
|
|
122
249
|
const _poolMetadata = await chainApi.api.query.nominationPools.metadata(poolMemberInfo.poolId);
|
|
123
250
|
const poolMetadata = _poolMetadata.toPrimitive();
|
|
124
251
|
const poolName = (0, _utils.transformPoolName)(poolMetadata.isUtf8 ? poolMetadata.toUtf8() : poolMetadata.toString());
|
|
252
|
+
const poolStashAccount = (0, _utils.parsePoolStashAddress)(chainApi.api, 0, poolMemberInfo.poolId, poolsPalletId);
|
|
253
|
+
const _nominations = await chainApi.api.query.staking.nominators(poolStashAccount);
|
|
254
|
+
const nominations = _nominations.toJSON();
|
|
255
|
+
if (nominations) {
|
|
256
|
+
const validatorList = nominations.targets;
|
|
257
|
+
await Promise.all(validatorList.map(async validatorAddress => {
|
|
258
|
+
const _eraStaker = await chainApi.api.query.staking.erasStakers(currentEra, validatorAddress);
|
|
259
|
+
const eraStaker = _eraStaker.toPrimitive();
|
|
260
|
+
const topNominators = eraStaker.others.map(nominator => {
|
|
261
|
+
return nominator.who;
|
|
262
|
+
}).slice(0, maxNominatorRewardedPerValidator);
|
|
263
|
+
if (topNominators.includes((0, _utils3.reformatAddress)(poolStashAccount, (0, _utils2._getChainSubstrateAddressPrefix)(chainInfo)))) {
|
|
264
|
+
// if address in top nominators
|
|
265
|
+
stakingStatus = _KoniTypes.StakingStatus.EARNING_REWARD;
|
|
266
|
+
}
|
|
267
|
+
}));
|
|
268
|
+
}
|
|
125
269
|
const joinedPoolInfo = {
|
|
126
270
|
activeStake: poolMemberInfo.points.toString(),
|
|
127
271
|
chain: chainInfo.slug,
|
|
272
|
+
status: stakingStatus,
|
|
128
273
|
validatorIdentity: poolName,
|
|
129
274
|
validatorAddress: poolMemberInfo.poolId.toString(),
|
|
130
275
|
// use poolId
|
|
@@ -143,10 +288,15 @@ async function getRelayChainPoolMemberMetadata(chainInfo, address, substrateApi)
|
|
|
143
288
|
waitingTime: waitingTime > 0 ? waitingTime : 0
|
|
144
289
|
});
|
|
145
290
|
});
|
|
291
|
+
const bnActiveStake = new _util.BN(poolMemberInfo.points.toString());
|
|
292
|
+
if (!bnActiveStake.gt(_util.BN_ZERO)) {
|
|
293
|
+
stakingStatus = _KoniTypes.StakingStatus.NOT_EARNING;
|
|
294
|
+
}
|
|
146
295
|
return {
|
|
147
296
|
chain: chainInfo.slug,
|
|
148
297
|
type: _KoniTypes.StakingType.POOLED,
|
|
149
298
|
address,
|
|
299
|
+
status: stakingStatus,
|
|
150
300
|
activeStake: poolMemberInfo.points.toString(),
|
|
151
301
|
nominations: [joinedPoolInfo],
|
|
152
302
|
// can only join 1 pool at a time
|
|
@@ -202,9 +352,9 @@ async function getRelayValidatorsInfo(chain, substrateApi, decimals, chainStakin
|
|
|
202
352
|
}
|
|
203
353
|
const extraInfoMap = {};
|
|
204
354
|
await Promise.all(allValidators.map(async address => {
|
|
205
|
-
var _chainApi$api$
|
|
355
|
+
var _chainApi$api$query12, _chainApi$api$query13, _identityInfo$judgeme;
|
|
206
356
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
207
|
-
const [_commissionInfo, _identityInfo] = await Promise.all([chainApi.api.query.staking.validators(address), (_chainApi$api$
|
|
357
|
+
const [_commissionInfo, _identityInfo] = await Promise.all([chainApi.api.query.staking.validators(address), (_chainApi$api$query12 = chainApi.api.query) === null || _chainApi$api$query12 === void 0 ? void 0 : (_chainApi$api$query13 = _chainApi$api$query12.identity) === null || _chainApi$api$query13 === void 0 ? void 0 : _chainApi$api$query13.identityOf(address)]);
|
|
208
358
|
const commissionInfo = _commissionInfo.toHuman();
|
|
209
359
|
const identityInfo = _identityInfo ? _identityInfo.toHuman() : null;
|
|
210
360
|
let identity;
|
|
@@ -255,23 +405,31 @@ async function getRelayPoolsInfo(chain, substrateApi) {
|
|
|
255
405
|
}));
|
|
256
406
|
return nominationPools;
|
|
257
407
|
}
|
|
258
|
-
async function getRelayBondingExtrinsic(substrateApi, amount, targetValidators,
|
|
259
|
-
let bondDest = arguments.length >
|
|
408
|
+
async function getRelayBondingExtrinsic(substrateApi, amount, targetValidators, chainInfo, address, nominatorMetadata) {
|
|
409
|
+
let bondDest = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : 'Staked';
|
|
260
410
|
const chainApi = await substrateApi.isReady;
|
|
261
411
|
const binaryAmount = new _util.BN(amount);
|
|
262
412
|
let bondTx;
|
|
263
413
|
let nominateTx;
|
|
414
|
+
const validatorParamList = targetValidators.map(validator => {
|
|
415
|
+
return validator.address;
|
|
416
|
+
});
|
|
417
|
+
if (!nominatorMetadata) {
|
|
418
|
+
bondTx = chainApi.api.tx.staking.bond(address, binaryAmount, bondDest);
|
|
419
|
+
nominateTx = chainApi.api.tx.staking.nominate(validatorParamList);
|
|
420
|
+
return chainApi.api.tx.utility.batchAll([bondTx, nominateTx]);
|
|
421
|
+
}
|
|
264
422
|
if (!nominatorMetadata.isBondedBefore) {
|
|
265
423
|
// first time
|
|
266
424
|
bondTx = chainApi.api.tx.staking.bond(nominatorMetadata.address, binaryAmount, bondDest);
|
|
267
|
-
nominateTx = chainApi.api.tx.staking.nominate(
|
|
425
|
+
nominateTx = chainApi.api.tx.staking.nominate(validatorParamList);
|
|
268
426
|
return chainApi.api.tx.utility.batchAll([bondTx, nominateTx]);
|
|
269
427
|
} else {
|
|
270
428
|
if (binaryAmount.gt(_util.BN_ZERO)) {
|
|
271
429
|
bondTx = chainApi.api.tx.staking.bondExtra(binaryAmount);
|
|
272
430
|
}
|
|
273
431
|
if (nominatorMetadata.isBondedBefore && targetValidators.length > 0) {
|
|
274
|
-
nominateTx = chainApi.api.tx.staking.nominate(
|
|
432
|
+
nominateTx = chainApi.api.tx.staking.nominate(validatorParamList);
|
|
275
433
|
}
|
|
276
434
|
}
|
|
277
435
|
if (bondTx && !nominateTx) {
|
|
@@ -14,12 +14,15 @@ exports.getBondedValidators = getBondedValidators;
|
|
|
14
14
|
exports.getCommission = getCommission;
|
|
15
15
|
exports.getInflationParams = getInflationParams;
|
|
16
16
|
exports.getParaCurrentInflation = getParaCurrentInflation;
|
|
17
|
-
exports.
|
|
17
|
+
exports.getStakingAvailableActionsByChain = getStakingAvailableActionsByChain;
|
|
18
|
+
exports.getStakingAvailableActionsByNominator = getStakingAvailableActionsByNominator;
|
|
19
|
+
exports.getStakingStatusByNominations = getStakingStatusByNominations;
|
|
18
20
|
exports.getWithdrawalInfo = getWithdrawalInfo;
|
|
19
21
|
exports.isActionFromValidator = isActionFromValidator;
|
|
20
22
|
exports.isShowNominationByValidator = isShowNominationByValidator;
|
|
21
23
|
exports.isUnstakeAll = isUnstakeAll;
|
|
22
24
|
exports.parseIdentity = parseIdentity;
|
|
25
|
+
exports.parsePoolStashAddress = parsePoolStashAddress;
|
|
23
26
|
exports.transformPoolName = transformPoolName;
|
|
24
27
|
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
25
28
|
var _constants = require("@subwallet/extension-base/services/chain-service/constants");
|
|
@@ -34,6 +37,15 @@ exports.PalletParachainStakingRequestType = PalletParachainStakingRequestType;
|
|
|
34
37
|
PalletParachainStakingRequestType["DECREASE"] = "decrease";
|
|
35
38
|
PalletParachainStakingRequestType["BOND_LESS"] = "bondLess";
|
|
36
39
|
})(PalletParachainStakingRequestType || (exports.PalletParachainStakingRequestType = PalletParachainStakingRequestType = {}));
|
|
40
|
+
function parsePoolStashAddress(api, index, poolId, poolsPalletId) {
|
|
41
|
+
const ModPrefix = (0, _util.stringToU8a)('modl');
|
|
42
|
+
const U32Opts = {
|
|
43
|
+
bitLength: 32,
|
|
44
|
+
isLe: true
|
|
45
|
+
};
|
|
46
|
+
const EmptyH256 = new Uint8Array(32);
|
|
47
|
+
return api.registry.createType('AccountId32', (0, _util.u8aConcat)(ModPrefix, poolsPalletId, new Uint8Array([index]), (0, _util.bnToU8a)(new _util.BN(poolId.toString()), U32Opts), EmptyH256)).toString();
|
|
48
|
+
}
|
|
37
49
|
function transformPoolName(input) {
|
|
38
50
|
return input.replace(/[^\x20-\x7E]/g, '');
|
|
39
51
|
}
|
|
@@ -139,11 +151,8 @@ function getBondedValidators(nominations) {
|
|
|
139
151
|
const bondedValidators = [];
|
|
140
152
|
let nominationCount = 0;
|
|
141
153
|
for (const nomination of nominations) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
nominationCount += 1;
|
|
145
|
-
bondedValidators.push((0, _utils.reformatAddress)(nomination.validatorAddress, 0));
|
|
146
|
-
}
|
|
154
|
+
nominationCount += 1;
|
|
155
|
+
bondedValidators.push((0, _utils.reformatAddress)(nomination.validatorAddress, 0));
|
|
147
156
|
}
|
|
148
157
|
return {
|
|
149
158
|
nominationCount,
|
|
@@ -153,7 +162,9 @@ function getBondedValidators(nominations) {
|
|
|
153
162
|
function isUnstakeAll(selectedValidator, nominations, unstakeAmount) {
|
|
154
163
|
let isUnstakeAll = false;
|
|
155
164
|
for (const nomination of nominations) {
|
|
156
|
-
|
|
165
|
+
const parsedValidatorAddress = (0, _utils.reformatAddress)(nomination.validatorAddress, 0);
|
|
166
|
+
const parsedSelectedValidator = (0, _utils.reformatAddress)(selectedValidator, 0);
|
|
167
|
+
if (parsedValidatorAddress === parsedSelectedValidator) {
|
|
157
168
|
if (unstakeAmount === nomination.activeStake) {
|
|
158
169
|
isUnstakeAll = true;
|
|
159
170
|
}
|
|
@@ -171,13 +182,28 @@ exports.StakingAction = StakingAction;
|
|
|
171
182
|
StakingAction["CLAIM_REWARD"] = "CLAIM_REWARD";
|
|
172
183
|
StakingAction["CANCEL_UNSTAKE"] = "CANCEL_UNSTAKE";
|
|
173
184
|
})(StakingAction || (exports.StakingAction = StakingAction = {}));
|
|
174
|
-
function
|
|
185
|
+
function getStakingAvailableActionsByChain(chain, type) {
|
|
186
|
+
if (type === _KoniTypes.StakingType.POOLED) {
|
|
187
|
+
return [StakingAction.STAKE, StakingAction.UNSTAKE, StakingAction.WITHDRAW, StakingAction.CLAIM_REWARD];
|
|
188
|
+
}
|
|
189
|
+
if (_constants._STAKING_CHAIN_GROUP.para.includes(chain)) {
|
|
190
|
+
return [StakingAction.STAKE, StakingAction.UNSTAKE, StakingAction.WITHDRAW, StakingAction.CANCEL_UNSTAKE];
|
|
191
|
+
} else if (_constants._STAKING_CHAIN_GROUP.astar.includes(chain)) {
|
|
192
|
+
return [StakingAction.STAKE, StakingAction.UNSTAKE, StakingAction.WITHDRAW, StakingAction.CLAIM_REWARD];
|
|
193
|
+
} else if (_constants._STAKING_CHAIN_GROUP.amplitude.includes(chain)) {
|
|
194
|
+
return [StakingAction.STAKE, StakingAction.UNSTAKE, StakingAction.WITHDRAW];
|
|
195
|
+
}
|
|
196
|
+
return [StakingAction.STAKE, StakingAction.UNSTAKE, StakingAction.WITHDRAW, StakingAction.CANCEL_UNSTAKE];
|
|
197
|
+
}
|
|
198
|
+
function getStakingAvailableActionsByNominator(nominatorMetadata, unclaimedReward) {
|
|
175
199
|
const result = [StakingAction.STAKE];
|
|
176
200
|
const bnActiveStake = new _util.BN(nominatorMetadata.activeStake);
|
|
177
201
|
if (nominatorMetadata.activeStake && bnActiveStake.gt(_util.BN_ZERO)) {
|
|
178
202
|
result.push(StakingAction.UNSTAKE);
|
|
179
|
-
const
|
|
180
|
-
|
|
203
|
+
const isAstarNetwork = _constants._STAKING_CHAIN_GROUP.astar.includes(nominatorMetadata.chain);
|
|
204
|
+
const isAmplitudeNetwork = _constants._STAKING_CHAIN_GROUP.amplitude.includes(nominatorMetadata.chain);
|
|
205
|
+
const bnUnclaimedReward = new _util.BN(unclaimedReward || '0');
|
|
206
|
+
if ((nominatorMetadata.type === _KoniTypes.StakingType.POOLED || isAmplitudeNetwork) && bnUnclaimedReward.gt(_util.BN_ZERO) || isAstarNetwork) {
|
|
181
207
|
result.push(StakingAction.CLAIM_REWARD);
|
|
182
208
|
}
|
|
183
209
|
}
|
|
@@ -219,4 +245,23 @@ function getWithdrawalInfo(nominatorMetadata) {
|
|
|
219
245
|
}
|
|
220
246
|
}
|
|
221
247
|
return result;
|
|
248
|
+
}
|
|
249
|
+
function getStakingStatusByNominations(bnTotalActiveStake, nominationList) {
|
|
250
|
+
let stakingStatus = _KoniTypes.StakingStatus.EARNING_REWARD;
|
|
251
|
+
if (bnTotalActiveStake.isZero()) {
|
|
252
|
+
stakingStatus = _KoniTypes.StakingStatus.NOT_EARNING;
|
|
253
|
+
} else {
|
|
254
|
+
let invalidDelegationCount = 0;
|
|
255
|
+
for (const nomination of nominationList) {
|
|
256
|
+
if (nomination.status === _KoniTypes.StakingStatus.NOT_EARNING) {
|
|
257
|
+
invalidDelegationCount += 1;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
if (invalidDelegationCount > 0 && invalidDelegationCount < nominationList.length) {
|
|
261
|
+
stakingStatus = _KoniTypes.StakingStatus.PARTIALLY_EARNING;
|
|
262
|
+
} else if (invalidDelegationCount === nominationList.length) {
|
|
263
|
+
stakingStatus = _KoniTypes.StakingStatus.NOT_EARNING;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return stakingStatus;
|
|
222
267
|
}
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.getPSP22ContractPromise = getPSP22ContractPromise;
|
|
7
7
|
exports.getPSP34ContractPromise = getPSP34ContractPromise;
|
|
8
8
|
exports.getPSP34TransferExtrinsic = getPSP34TransferExtrinsic;
|
|
9
|
+
var _utils = require("@subwallet/extension-base/koni/api/tokens/wasm/utils");
|
|
9
10
|
var _helper = require("@subwallet/extension-base/services/chain-service/helper");
|
|
10
11
|
var _apiContract = require("@polkadot/api-contract");
|
|
11
12
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
@@ -22,10 +23,10 @@ async function getPSP34TransferExtrinsic(networkKey, substrateApi, senderAddress
|
|
|
22
23
|
const onChainOption = params.onChainOption;
|
|
23
24
|
try {
|
|
24
25
|
const contractPromise = getPSP34ContractPromise(substrateApi.api, contractAddress);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
// @ts-ignore
|
|
27
|
+
const gasLimit = await (0, _utils.getWasmContractGasLimit)(substrateApi.api, senderAddress, 'psp34::transfer', contractPromise, {}, [recipientAddress, onChainOption, {}]);
|
|
28
|
+
|
|
29
|
+
// @ts-ignore
|
|
29
30
|
return contractPromise.tx['psp34::transfer']({
|
|
30
31
|
gasLimit
|
|
31
32
|
}, recipientAddress, onChainOption, {});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getDefaultWeightV2 = getDefaultWeightV2;
|
|
7
|
+
exports.getWasmContractGasLimit = getWasmContractGasLimit;
|
|
8
|
+
var _util = require("@polkadot/util");
|
|
9
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
10
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
11
|
+
|
|
12
|
+
const MAX_CALL_WEIGHT = '5000000000000';
|
|
13
|
+
const DEFAULT_REF_TIME = '1000000000000';
|
|
14
|
+
const toContractAbiMessage = (contractPromise, message) => {
|
|
15
|
+
const value = contractPromise.abi.messages.find(m => m.method === message);
|
|
16
|
+
if (!value) {
|
|
17
|
+
const messages = contractPromise === null || contractPromise === void 0 ? void 0 : contractPromise.abi.messages.map(m => m.method).join(', ');
|
|
18
|
+
const error = `"${message}" not found in metadata.spec.messages: [${messages}]`;
|
|
19
|
+
console.error(error);
|
|
20
|
+
return {
|
|
21
|
+
ok: false,
|
|
22
|
+
error
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
ok: true,
|
|
27
|
+
value
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
async function getWasmContractGasLimit(api, callerAddress, message, contract) {
|
|
31
|
+
let options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
32
|
+
let args = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : [];
|
|
33
|
+
try {
|
|
34
|
+
var _abiMessage$value;
|
|
35
|
+
const abiMessage = toContractAbiMessage(contract, message);
|
|
36
|
+
if (!abiMessage.ok) {
|
|
37
|
+
return getDefaultWeightV2(api, true);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// @ts-ignore
|
|
41
|
+
const {
|
|
42
|
+
gasLimit,
|
|
43
|
+
storageDepositLimit,
|
|
44
|
+
value
|
|
45
|
+
} = options;
|
|
46
|
+
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
const {
|
|
49
|
+
gasRequired
|
|
50
|
+
} = await api.call.contractsApi.call(callerAddress, contract.address, value !== null && value !== void 0 ? value : new _util.BN(0), gasLimit !== null && gasLimit !== void 0 ? gasLimit : null, storageDepositLimit !== null && storageDepositLimit !== void 0 ? storageDepositLimit : null, abiMessage === null || abiMessage === void 0 ? void 0 : (_abiMessage$value = abiMessage.value) === null || _abiMessage$value === void 0 ? void 0 : _abiMessage$value.toU8a(args));
|
|
51
|
+
return gasRequired;
|
|
52
|
+
} catch {
|
|
53
|
+
return getDefaultWeightV2(api, true);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function getDefaultWeightV2(apiPromise, isFallback) {
|
|
57
|
+
const proofSize = isFallback ? 3407872 : MAX_CALL_WEIGHT; // TODO: handle error better
|
|
58
|
+
const refTime = isFallback ? 32490000000 : DEFAULT_REF_TIME;
|
|
59
|
+
return apiPromise.registry.createType('WeightV2', {
|
|
60
|
+
refTime,
|
|
61
|
+
proofSize
|
|
62
|
+
});
|
|
63
|
+
}
|
|
@@ -35,115 +35,4 @@ const createXcmExtrinsic = async _ref => {
|
|
|
35
35
|
console.log('XCM extrinsic: ', extrinsic.toHex());
|
|
36
36
|
return extrinsic;
|
|
37
37
|
};
|
|
38
|
-
|
|
39
|
-
// TODO: add + refine logic for more chains
|
|
40
|
-
// export function updateXcmResponseTxResult (
|
|
41
|
-
// networkKey: string,
|
|
42
|
-
// tokenInfo: _ChainAsset,
|
|
43
|
-
// response: TransactionResponse,
|
|
44
|
-
// records: EventRecord[]
|
|
45
|
-
// ) {
|
|
46
|
-
// if (!response.txResult) {
|
|
47
|
-
// response.txResult = { change: '0' };
|
|
48
|
-
// }
|
|
49
|
-
//
|
|
50
|
-
// let isFeeUseMainTokenSymbol = true;
|
|
51
|
-
//
|
|
52
|
-
// for (let index = 0; index < records.length; index++) {
|
|
53
|
-
// const record = records[index];
|
|
54
|
-
//
|
|
55
|
-
// if (_XCM_CHAIN_GROUP.acala.includes(networkKey) && !_isNativeToken(tokenInfo)) {
|
|
56
|
-
// if (record.event.section === 'currencies' &&
|
|
57
|
-
// record.event.method.toLowerCase() === 'transferred') {
|
|
58
|
-
// if (index === 0) {
|
|
59
|
-
// // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
60
|
-
// response.txResult.fee = record.event.data[3]?.toString() || '0';
|
|
61
|
-
// response.txResult.feeSymbol = tokenInfo.symbol;
|
|
62
|
-
//
|
|
63
|
-
// isFeeUseMainTokenSymbol = false;
|
|
64
|
-
// } else {
|
|
65
|
-
// response.txResult.change = record.event.data[3]?.toString() || '0';
|
|
66
|
-
// response.txResult.changeSymbol = tokenInfo.symbol;
|
|
67
|
-
// }
|
|
68
|
-
// }
|
|
69
|
-
//
|
|
70
|
-
// if (record.event.section === 'tokens' &&
|
|
71
|
-
// record.event.method.toLowerCase() === 'withdrawn') {
|
|
72
|
-
// response.txResult.change = record.event.data[2]?.toString() || '0';
|
|
73
|
-
// response.txResult.changeSymbol = tokenInfo.symbol;
|
|
74
|
-
// }
|
|
75
|
-
// } else if (_XCM_CHAIN_GROUP.kintsugi.includes(networkKey) && !_isNativeToken(tokenInfo)) {
|
|
76
|
-
// if (record.event.section === 'tokens' &&
|
|
77
|
-
// record.event.method.toLowerCase() === 'transfer') {
|
|
78
|
-
// response.txResult.change = record.event.data[3]?.toString() || '0';
|
|
79
|
-
// response.txResult.changeSymbol = tokenInfo.symbol;
|
|
80
|
-
// }
|
|
81
|
-
// } else if (_XCM_CHAIN_GROUP.genshiro.includes(networkKey) && !_isNativeToken(tokenInfo)) {
|
|
82
|
-
// if (record.event.section === 'eqBalances' &&
|
|
83
|
-
// record.event.method.toLowerCase() === 'transfer') {
|
|
84
|
-
// response.txResult.change = record.event.data[3]?.toString() || '0';
|
|
85
|
-
// response.txResult.changeSymbol = tokenInfo.symbol;
|
|
86
|
-
// }
|
|
87
|
-
// } else if (_XCM_CHAIN_GROUP.bifrost.includes(networkKey) && !_isNativeToken(tokenInfo)) {
|
|
88
|
-
// if (record.event.section === 'tokens' &&
|
|
89
|
-
// record.event.method.toLowerCase() === 'withdrawn') {
|
|
90
|
-
// response.txResult.change = record.event.data[2]?.toString() || '0';
|
|
91
|
-
// response.txResult.changeSymbol = tokenInfo.symbol;
|
|
92
|
-
// } else if (record.event.section === 'balances' &&
|
|
93
|
-
// record.event.method.toLowerCase() === 'transfer') {
|
|
94
|
-
// // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
95
|
-
// response.txResult.change = record.event.data[2]?.toString() || '0';
|
|
96
|
-
// response.txResult.changeSymbol = tokenInfo.symbol;
|
|
97
|
-
// }
|
|
98
|
-
// } else if (_XCM_CHAIN_GROUP.astar.includes(networkKey) && !_isNativeToken(tokenInfo)) {
|
|
99
|
-
// if (record.event.section === 'assets' &&
|
|
100
|
-
// record.event.method.toLowerCase() === 'burned') {
|
|
101
|
-
// response.txResult.change = record.event.data[2]?.toString() || '0';
|
|
102
|
-
// response.txResult.changeSymbol = tokenInfo.symbol;
|
|
103
|
-
// }
|
|
104
|
-
// } else if (_XCM_CHAIN_GROUP.moonbeam.includes(networkKey) && !_isNativeToken(tokenInfo)) {
|
|
105
|
-
// if (record.event.section === 'assets' &&
|
|
106
|
-
// record.event.method.toLowerCase() === 'burned') {
|
|
107
|
-
// response.txResult.change = record.event.data[2]?.toString() || '0';
|
|
108
|
-
// response.txResult.changeSymbol = tokenInfo.symbol;
|
|
109
|
-
// }
|
|
110
|
-
// } else if (_XCM_CHAIN_GROUP.statemine.includes(networkKey)) {
|
|
111
|
-
// if (!_isNativeToken(tokenInfo)) {
|
|
112
|
-
// if (record.event.section === 'assets' &&
|
|
113
|
-
// record.event.method.toLowerCase() === 'transferred') {
|
|
114
|
-
// response.txResult.change = record.event.data[3]?.toString() || '0';
|
|
115
|
-
// response.txResult.changeSymbol = tokenInfo.symbol;
|
|
116
|
-
// }
|
|
117
|
-
// } else {
|
|
118
|
-
// if (record.event.section === 'balances' &&
|
|
119
|
-
// record.event.method.toLowerCase() === 'withdraw') {
|
|
120
|
-
// response.txResult.change = record.event.data[1]?.toString() || '0';
|
|
121
|
-
// response.txResult.changeSymbol = tokenInfo.symbol;
|
|
122
|
-
// }
|
|
123
|
-
// }
|
|
124
|
-
// } else {
|
|
125
|
-
// if (record.event.section === 'balances' &&
|
|
126
|
-
// record.event.method.toLowerCase() === 'transfer') {
|
|
127
|
-
// // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
128
|
-
// response.txResult.change = record.event.data[2]?.toString() || '0';
|
|
129
|
-
// } else if (record.event.section === 'xTokens' &&
|
|
130
|
-
// record.event.method.toLowerCase() === 'transferred') {
|
|
131
|
-
// // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
132
|
-
// response.txResult.change = record.event.data[2]?.toString() || '0';
|
|
133
|
-
// }
|
|
134
|
-
// }
|
|
135
|
-
//
|
|
136
|
-
// if (isFeeUseMainTokenSymbol && record.event.section === 'balances' && record.event.method.toLowerCase() === 'withdraw') {
|
|
137
|
-
// if (!response.txResult.fee) {
|
|
138
|
-
// // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
139
|
-
// response.txResult.fee = record.event.data[1]?.toString() || '0';
|
|
140
|
-
// }
|
|
141
|
-
// } else if (isFeeUseMainTokenSymbol && record.event.section === 'tokens' && record.event.method.toLowerCase() === 'withdrawn') {
|
|
142
|
-
// if (!response.txResult.fee) {
|
|
143
|
-
// // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
144
|
-
// response.txResult.fee = record.event.data[2]?.toString() || '0';
|
|
145
|
-
// }
|
|
146
|
-
// }
|
|
147
|
-
// }
|
|
148
|
-
// }
|
|
149
38
|
exports.createXcmExtrinsic = createXcmExtrinsic;
|
|
@@ -42,13 +42,13 @@ function getAssetLocation(tokenInfo, sendingValue) {
|
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
44
|
function getExtrinsicByPolkadotXcmPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
|
|
45
|
-
const weightParam = _utils.
|
|
45
|
+
const weightParam = (0, _utils.getDestWeight)();
|
|
46
46
|
const beneficiary = (0, _utils.getBeneficiary)(originChainInfo, destinationChainInfo, recipientAddress);
|
|
47
47
|
const destination = getDestinationChainLocation(destinationChainInfo);
|
|
48
48
|
const assetLocation = getAssetLocation(tokenInfo, value);
|
|
49
49
|
let method = 'limitedReserveTransferAssets';
|
|
50
50
|
if (['astar', 'shiden'].includes(originChainInfo.slug)) {
|
|
51
|
-
method = '
|
|
51
|
+
method = 'limitedReserveWithdrawAssets';
|
|
52
52
|
} else if ((0, _utils2._isSubstrateRelayChain)(destinationChainInfo)) {
|
|
53
53
|
method = 'limitedTeleportAssets';
|
|
54
54
|
}
|