@subwallet/extension-base 1.1.28-beta.1 → 1.1.30-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 +70 -93
- package/background/KoniTypes.js +14 -16
- package/background/errors/TransactionError.js +4 -9
- package/cjs/background/KoniTypes.js +17 -17
- package/cjs/background/errors/TransactionError.js +4 -9
- package/cjs/constants/index.js +3 -9
- 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 +15 -17
- package/cjs/koni/api/staking/bonding/astar.js +10 -11
- package/cjs/koni/api/staking/bonding/index.js +1 -4
- package/cjs/koni/api/staking/bonding/paraChain.js +23 -25
- 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 +5 -6
- package/cjs/koni/api/staking/relayChain.js +2 -3
- package/cjs/koni/background/cron.js +0 -2
- package/cjs/koni/background/handlers/Extension.js +88 -326
- package/cjs/koni/background/handlers/State.js +3 -51
- package/cjs/koni/background/handlers/index.js +2 -4
- package/cjs/koni/background/subscription.js +18 -88
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/campaign-service/index.js +6 -9
- package/cjs/services/chain-service/constants.js +16 -2
- package/cjs/services/chain-service/utils.js +1 -7
- package/cjs/services/event-service/index.js +0 -4
- 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 +0 -4
- package/cjs/services/notification-service/NotificationService.js +1 -1
- package/cjs/services/storage-service/DatabaseService.js +0 -47
- package/cjs/services/storage-service/databases/index.js +0 -4
- package/cjs/services/storage-service/db-stores/NominatorMetadata.js +3 -3
- 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 +74 -180
- package/cjs/services/transaction-service/utils.js +0 -1
- package/cjs/types/index.js +0 -44
- package/cjs/utils/fetchStaticData.js +1 -2
- package/cjs/utils/index.js +1 -89
- package/constants/index.d.ts +0 -2
- package/constants/index.js +0 -2
- 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.js +9 -11
- package/koni/api/staking/bonding/astar.js +8 -9
- package/koni/api/staking/bonding/index.d.ts +1 -1
- package/koni/api/staking/bonding/index.js +1 -5
- package/koni/api/staking/bonding/paraChain.js +10 -12
- 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 +38 -15
- package/koni/api/staking/bonding/utils.js +69 -85
- package/koni/api/staking/index.js +1 -2
- package/koni/api/staking/paraChain.js +6 -7
- package/koni/api/staking/relayChain.js +3 -4
- package/koni/background/cron.js +0 -2
- package/koni/background/handlers/Extension.d.ts +1 -14
- package/koni/background/handlers/Extension.js +50 -286
- package/koni/background/handlers/State.d.ts +2 -18
- package/koni/background/handlers/State.js +3 -50
- package/koni/background/handlers/index.js +2 -4
- package/koni/background/subscription.d.ts +1 -5
- package/koni/background/subscription.js +20 -90
- package/package.json +8 -311
- package/packageInfo.js +1 -1
- package/services/campaign-service/index.js +6 -9
- package/services/chain-service/constants.d.ts +11 -0
- package/services/chain-service/constants.js +14 -1
- 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 +0 -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 +0 -4
- package/services/notification-service/NotificationService.js +1 -1
- package/services/storage-service/DatabaseService.d.ts +1 -17
- package/services/storage-service/DatabaseService.js +0 -47
- 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/NominatorMetadata.js +3 -3
- package/services/subscan-service/index.d.ts +2 -2
- 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 +15 -4
- package/services/transaction-service/index.js +72 -178
- package/services/transaction-service/types.d.ts +0 -2
- package/services/transaction-service/utils.js +0 -1
- package/types/index.d.ts +0 -5
- package/types/index.js +1 -5
- package/utils/fetchStaticData.js +1 -2
- package/utils/index.d.ts +0 -5
- package/utils/index.js +1 -53
- 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 -202
- 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 -168
- package/cjs/services/earning-service/handlers/liquid-staking/acala.js +0 -196
- package/cjs/services/earning-service/handlers/liquid-staking/base.js +0 -39
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +0 -257
- package/cjs/services/earning-service/handlers/liquid-staking/index.js +0 -34
- package/cjs/services/earning-service/handlers/liquid-staking/parallel.js +0 -180
- package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +0 -373
- package/cjs/services/earning-service/handlers/native-staking/amplitude.js +0 -359
- package/cjs/services/earning-service/handlers/native-staking/astar.js +0 -426
- package/cjs/services/earning-service/handlers/native-staking/base-para.js +0 -137
- package/cjs/services/earning-service/handlers/native-staking/base.js +0 -109
- package/cjs/services/earning-service/handlers/native-staking/index.js +0 -34
- package/cjs/services/earning-service/handlers/native-staking/para-chain.js +0 -361
- package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +0 -512
- package/cjs/services/earning-service/handlers/nomination-pool/index.js +0 -501
- package/cjs/services/earning-service/handlers/special.js +0 -387
- package/cjs/services/earning-service/service.js +0 -327
- package/cjs/services/earning-service/utils/index.js +0 -111
- 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/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 -37
- 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 -34
- 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 -105
- package/services/earning-service/handlers/base.js +0 -195
- 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 -22
- package/services/earning-service/handlers/lending/interlay.js +0 -160
- package/services/earning-service/handlers/liquid-staking/acala.d.ts +0 -27
- package/services/earning-service/handlers/liquid-staking/acala.js +0 -188
- package/services/earning-service/handlers/liquid-staking/base.d.ts +0 -8
- package/services/earning-service/handlers/liquid-staking/base.js +0 -31
- package/services/earning-service/handlers/liquid-staking/bifrost.d.ts +0 -44
- package/services/earning-service/handlers/liquid-staking/bifrost.js +0 -246
- 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 -27
- package/services/earning-service/handlers/liquid-staking/parallel.js +0 -172
- package/services/earning-service/handlers/liquid-staking/stella-swap.d.ts +0 -36
- package/services/earning-service/handlers/liquid-staking/stella-swap.js +0 -363
- package/services/earning-service/handlers/native-staking/amplitude.d.ts +0 -22
- package/services/earning-service/handlers/native-staking/amplitude.js +0 -350
- package/services/earning-service/handlers/native-staking/astar.d.ts +0 -18
- package/services/earning-service/handlers/native-staking/astar.js +0 -416
- package/services/earning-service/handlers/native-staking/base-para.d.ts +0 -11
- package/services/earning-service/handlers/native-staking/base-para.js +0 -129
- package/services/earning-service/handlers/native-staking/base.d.ts +0 -19
- package/services/earning-service/handlers/native-staking/base.js +0 -101
- 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 -353
- package/services/earning-service/handlers/native-staking/relay-chain.d.ts +0 -21
- package/services/earning-service/handlers/native-staking/relay-chain.js +0 -503
- package/services/earning-service/handlers/nomination-pool/index.d.ts +0 -33
- package/services/earning-service/handlers/nomination-pool/index.js +0 -492
- package/services/earning-service/handlers/special.d.ts +0 -56
- package/services/earning-service/handlers/special.js +0 -379
- package/services/earning-service/service.d.ts +0 -36
- package/services/earning-service/service.js +0 -320
- package/services/earning-service/utils/index.d.ts +0 -14
- package/services/earning-service/utils/index.js +0 -100
- 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/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 -75
- package/types/yield/actions/join/step.js +0 -34
- package/types/yield/actions/join/submit.d.ts +0 -53
- 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 -60
- 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 -112
- package/types/yield/info/account/info.js +0 -1
- package/types/yield/info/account/reward.d.ts +0 -41
- 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 -28
- package/types/yield/info/base.js +0 -28
- 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 -190
- package/types/yield/info/chain/info.js +0 -1
- package/types/yield/info/chain/target.d.ts +0 -33
- 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
|
@@ -1,387 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
var _chainList = require("@subwallet/chain-list");
|
|
9
|
-
var _TransactionError = require("@subwallet/extension-base/background/errors/TransactionError");
|
|
10
|
-
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
11
|
-
var _xcm = require("@subwallet/extension-base/koni/api/xcm");
|
|
12
|
-
var _utils = require("@subwallet/extension-base/koni/api/yield/helper/utils");
|
|
13
|
-
var _utils2 = require("@subwallet/extension-base/services/chain-service/utils");
|
|
14
|
-
var _types = require("@subwallet/extension-base/types");
|
|
15
|
-
var _bn = _interopRequireDefault(require("bn.js"));
|
|
16
|
-
var _i18next = require("i18next");
|
|
17
|
-
var _util = require("@polkadot/util");
|
|
18
|
-
var _base = _interopRequireDefault(require("./base"));
|
|
19
|
-
// Copyright 2019-2022 @subwallet/extension-base
|
|
20
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
21
|
-
|
|
22
|
-
class BaseSpecialStakingPoolHandler extends _base.default {
|
|
23
|
-
/** Allow to create default unstake transaction */
|
|
24
|
-
allowDefaultUnstake = false;
|
|
25
|
-
/** Allow to create fast unstake transaction */
|
|
26
|
-
allowFastUnstake = true;
|
|
27
|
-
get baseMetadata() {
|
|
28
|
-
return {
|
|
29
|
-
altInputAssets: this.altInputAsset,
|
|
30
|
-
derivativeAssets: this.derivativeAssets,
|
|
31
|
-
inputAsset: this.inputAsset,
|
|
32
|
-
rewardAssets: this.rewardAssets,
|
|
33
|
-
feeAssets: this.feeAssets
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
get isPoolSupportAlternativeFee() {
|
|
37
|
-
return this.feeAssets.length > 1;
|
|
38
|
-
}
|
|
39
|
-
get group() {
|
|
40
|
-
const inputAsset = this.state.getAssetBySlug(this.inputAsset);
|
|
41
|
-
const groupSlug = inputAsset.multiChainAsset;
|
|
42
|
-
return groupSlug || this.inputAsset;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/* Subscribe pool info */
|
|
46
|
-
|
|
47
|
-
async subscribePoolInfo(callback) {
|
|
48
|
-
let cancel = false;
|
|
49
|
-
const getStatInterval = () => {
|
|
50
|
-
this.getPoolStat().then(rs => {
|
|
51
|
-
if (!cancel) {
|
|
52
|
-
callback(rs);
|
|
53
|
-
}
|
|
54
|
-
}).catch(console.error);
|
|
55
|
-
};
|
|
56
|
-
getStatInterval();
|
|
57
|
-
const interval = setInterval(() => {
|
|
58
|
-
if (cancel) {
|
|
59
|
-
clearInterval(interval);
|
|
60
|
-
} else {
|
|
61
|
-
getStatInterval();
|
|
62
|
-
}
|
|
63
|
-
}, _utils.YIELD_POOL_STAT_REFRESH_INTERVAL);
|
|
64
|
-
return new Promise(resolve => {
|
|
65
|
-
const rs = () => {
|
|
66
|
-
cancel = true;
|
|
67
|
-
clearInterval(interval);
|
|
68
|
-
};
|
|
69
|
-
resolve(rs);
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/* Subscribe pool info */
|
|
74
|
-
|
|
75
|
-
/* Get pool reward */
|
|
76
|
-
|
|
77
|
-
async getPoolReward() {
|
|
78
|
-
return new Promise(resolve => resolve(_util.noop));
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/* Get pool reward */
|
|
82
|
-
|
|
83
|
-
/* Get pool targets */
|
|
84
|
-
|
|
85
|
-
async getPoolTargets() {
|
|
86
|
-
return new Promise(resolve => resolve([]));
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/* Get pool targets */
|
|
90
|
-
|
|
91
|
-
/* Join pool action */
|
|
92
|
-
|
|
93
|
-
/* Generate steps */
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* @async
|
|
97
|
-
* @function getXcmStep
|
|
98
|
-
* */
|
|
99
|
-
async getXcmStep(params) {
|
|
100
|
-
const {
|
|
101
|
-
address,
|
|
102
|
-
amount
|
|
103
|
-
} = params;
|
|
104
|
-
const bnAmount = new _bn.default(amount);
|
|
105
|
-
const inputTokenSlug = this.inputAsset; // assume that the pool only has 1 input token, will update later
|
|
106
|
-
const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
|
|
107
|
-
const inputTokenBalance = await this.state.balanceService.getTokenFreeBalance(address, inputTokenInfo.originChain, inputTokenSlug);
|
|
108
|
-
const bnInputTokenBalance = new _bn.default(inputTokenBalance.value);
|
|
109
|
-
if (!bnInputTokenBalance.gte(bnAmount)) {
|
|
110
|
-
if (this.altInputAsset) {
|
|
111
|
-
const altInputTokenSlug = this.altInputAsset;
|
|
112
|
-
const altInputTokenInfo = this.state.getAssetBySlug(altInputTokenSlug);
|
|
113
|
-
const altInputTokenBalance = await this.state.balanceService.getTokenFreeBalance(address, altInputTokenInfo.originChain, altInputTokenSlug);
|
|
114
|
-
const bnAltInputTokenBalance = new _bn.default(altInputTokenBalance.value || '0');
|
|
115
|
-
if (bnAltInputTokenBalance.gt(_util.BN_ZERO)) {
|
|
116
|
-
const step = {
|
|
117
|
-
metadata: {
|
|
118
|
-
sendingValue: bnAmount.toString(),
|
|
119
|
-
originTokenInfo: altInputTokenInfo,
|
|
120
|
-
destinationTokenInfo: inputTokenInfo
|
|
121
|
-
},
|
|
122
|
-
name: 'Transfer DOT from Polkadot',
|
|
123
|
-
type: _types.YieldStepType.XCM
|
|
124
|
-
};
|
|
125
|
-
const xcmOriginSubstrateApi = await this.state.getSubstrateApi(altInputTokenInfo.originChain).isReady;
|
|
126
|
-
const xcmTransfer = await (0, _xcm.createXcmExtrinsic)({
|
|
127
|
-
originTokenInfo: altInputTokenInfo,
|
|
128
|
-
destinationTokenInfo: inputTokenInfo,
|
|
129
|
-
sendingValue: bnAmount.toString(),
|
|
130
|
-
recipient: address,
|
|
131
|
-
chainInfoMap: this.state.getChainInfoMap(),
|
|
132
|
-
substrateApi: xcmOriginSubstrateApi
|
|
133
|
-
});
|
|
134
|
-
const _xcmFeeInfo = await xcmTransfer.paymentInfo(address);
|
|
135
|
-
const xcmFeeInfo = _xcmFeeInfo.toPrimitive();
|
|
136
|
-
// TODO: calculate fee for destination chain
|
|
137
|
-
|
|
138
|
-
const fee = {
|
|
139
|
-
slug: altInputTokenSlug,
|
|
140
|
-
amount: Math.round(xcmFeeInfo.partialFee * 1.2).toString() // TODO
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
return [step, fee];
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
return undefined;
|
|
148
|
-
}
|
|
149
|
-
get defaultSubmitStep() {
|
|
150
|
-
return [this.submitJoinStepInfo, {
|
|
151
|
-
slug: this.feeAssets[0],
|
|
152
|
-
amount: '0'
|
|
153
|
-
}];
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* @function submitJoinStepInfo
|
|
158
|
-
* @description Base info of submit step
|
|
159
|
-
* @return Fee of the submitting step
|
|
160
|
-
* */
|
|
161
|
-
|
|
162
|
-
async getSubmitStep(params) {
|
|
163
|
-
const fee = await this.getSubmitStepFee(params);
|
|
164
|
-
return [this.submitJoinStepInfo, fee];
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/* Generate steps */
|
|
168
|
-
|
|
169
|
-
/* Validate join action */
|
|
170
|
-
|
|
171
|
-
async validateTokenApproveStep(params, path) {
|
|
172
|
-
return Promise.resolve([new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.UNSUPPORTED)]);
|
|
173
|
-
}
|
|
174
|
-
async validateXcmStep(params, path, bnInputTokenBalance) {
|
|
175
|
-
const processValidation = {
|
|
176
|
-
ok: true,
|
|
177
|
-
status: _types.YieldValidationStatus.OK
|
|
178
|
-
};
|
|
179
|
-
const bnAmount = new _bn.default(params.amount);
|
|
180
|
-
const altInputTokenSlug = this.altInputAsset || '';
|
|
181
|
-
const altInputTokenInfo = this.state.getAssetBySlug(altInputTokenSlug);
|
|
182
|
-
const altInputTokenBalance = await this.state.balanceService.getTokenFreeBalance(params.address, altInputTokenInfo.originChain, altInputTokenSlug);
|
|
183
|
-
const missingAmount = bnAmount.sub(bnInputTokenBalance); // TODO: what if input token is not LOCAL ??
|
|
184
|
-
const xcmFee = new _bn.default(path.totalFee[1].amount || '0');
|
|
185
|
-
const xcmAmount = missingAmount.add(xcmFee);
|
|
186
|
-
const bnAltInputTokenBalance = new _bn.default(altInputTokenBalance.value || '0');
|
|
187
|
-
const altInputTokenMinAmount = new _bn.default(altInputTokenInfo.minAmount || '0');
|
|
188
|
-
if (!bnAltInputTokenBalance.sub(xcmAmount).gte(altInputTokenMinAmount)) {
|
|
189
|
-
processValidation.failedStep = path.steps[1];
|
|
190
|
-
processValidation.ok = false;
|
|
191
|
-
processValidation.status = _types.YieldValidationStatus.NOT_ENOUGH_BALANCE;
|
|
192
|
-
return [new _TransactionError.TransactionError(_types.YieldValidationStatus.NOT_ENOUGH_BALANCE, processValidation.message, processValidation)];
|
|
193
|
-
}
|
|
194
|
-
return [];
|
|
195
|
-
}
|
|
196
|
-
async validateJoinStep(id, params, path, bnInputTokenBalance, isXcmOk) {
|
|
197
|
-
const _poolInfo = await this.getPoolInfo();
|
|
198
|
-
if (!_poolInfo) {
|
|
199
|
-
return [new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.INTERNAL_ERROR)];
|
|
200
|
-
}
|
|
201
|
-
const poolInfo = _poolInfo;
|
|
202
|
-
const processValidation = {
|
|
203
|
-
ok: true,
|
|
204
|
-
status: _types.YieldValidationStatus.OK
|
|
205
|
-
};
|
|
206
|
-
const feeTokenSlug = path.totalFee[id].slug;
|
|
207
|
-
const feeTokenInfo = this.state.getAssetBySlug(feeTokenSlug);
|
|
208
|
-
const defaultFeeTokenSlug = this.feeAssets[0];
|
|
209
|
-
const bnAmount = new _bn.default(params.amount);
|
|
210
|
-
if (this.feeAssets.length === 1 && feeTokenSlug === defaultFeeTokenSlug) {
|
|
211
|
-
var _path$totalFee$id;
|
|
212
|
-
const bnFeeAmount = new _bn.default(((_path$totalFee$id = path.totalFee[id]) === null || _path$totalFee$id === void 0 ? void 0 : _path$totalFee$id.amount) || '0');
|
|
213
|
-
const feeTokenBalance = await this.state.balanceService.getTokenFreeBalance(params.address, feeTokenInfo.originChain, feeTokenSlug);
|
|
214
|
-
const bnFeeTokenBalance = new _bn.default(feeTokenBalance.value || '0');
|
|
215
|
-
const bnFeeTokenMinAmount = new _bn.default((feeTokenInfo === null || feeTokenInfo === void 0 ? void 0 : feeTokenInfo.minAmount) || '0');
|
|
216
|
-
if (!bnFeeTokenBalance.sub(bnFeeAmount).gte(bnFeeTokenMinAmount)) {
|
|
217
|
-
processValidation.failedStep = path.steps[id];
|
|
218
|
-
processValidation.ok = false;
|
|
219
|
-
processValidation.status = _types.YieldValidationStatus.NOT_ENOUGH_FEE;
|
|
220
|
-
return [new _TransactionError.TransactionError(_types.YieldValidationStatus.NOT_ENOUGH_FEE, processValidation.message, processValidation)];
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
if (!bnAmount.gte(new _bn.default(poolInfo.metadata.minJoinPool || '0'))) {
|
|
224
|
-
processValidation.failedStep = path.steps[id];
|
|
225
|
-
processValidation.ok = false;
|
|
226
|
-
processValidation.status = _types.YieldValidationStatus.NOT_ENOUGH_MIN_JOIN_POOL;
|
|
227
|
-
return [new _TransactionError.TransactionError(_types.YieldValidationStatus.NOT_ENOUGH_MIN_JOIN_POOL, processValidation.message, processValidation)];
|
|
228
|
-
}
|
|
229
|
-
if (!isXcmOk && bnAmount.gt(bnInputTokenBalance)) {
|
|
230
|
-
processValidation.failedStep = path.steps[id];
|
|
231
|
-
processValidation.ok = false;
|
|
232
|
-
processValidation.status = _types.YieldValidationStatus.NOT_ENOUGH_BALANCE;
|
|
233
|
-
return [new _TransactionError.TransactionError(_types.YieldValidationStatus.NOT_ENOUGH_BALANCE, processValidation.message, processValidation)];
|
|
234
|
-
}
|
|
235
|
-
return [];
|
|
236
|
-
}
|
|
237
|
-
async validateYieldJoin(params, path) {
|
|
238
|
-
const inputTokenSlug = this.inputAsset;
|
|
239
|
-
const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
|
|
240
|
-
const balanceService = this.state.balanceService;
|
|
241
|
-
const inputTokenBalance = await balanceService.getTokenFreeBalance(params.address, inputTokenInfo.originChain, inputTokenSlug);
|
|
242
|
-
const bnInputTokenBalance = new _bn.default(inputTokenBalance.value || '0');
|
|
243
|
-
let isXcmOk = false;
|
|
244
|
-
for (const step of path.steps) {
|
|
245
|
-
const getErrors = async () => {
|
|
246
|
-
switch (step.type) {
|
|
247
|
-
case _types.YieldStepType.DEFAULT:
|
|
248
|
-
return Promise.resolve([]);
|
|
249
|
-
case _types.YieldStepType.XCM:
|
|
250
|
-
return this.validateXcmStep(params, path, bnInputTokenBalance);
|
|
251
|
-
case _types.YieldStepType.TOKEN_APPROVAL:
|
|
252
|
-
return this.validateTokenApproveStep(params, path);
|
|
253
|
-
default:
|
|
254
|
-
return this.validateJoinStep(step.id, params, path, bnInputTokenBalance, isXcmOk);
|
|
255
|
-
}
|
|
256
|
-
};
|
|
257
|
-
const errors = await getErrors();
|
|
258
|
-
if (errors.length) {
|
|
259
|
-
return errors;
|
|
260
|
-
} else if (step.type === _types.YieldStepType.XCM) {
|
|
261
|
-
isXcmOk = true;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
return [];
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
/* Validate join action */
|
|
268
|
-
|
|
269
|
-
/* Submit join action */
|
|
270
|
-
|
|
271
|
-
async handleTokenApproveStep(data, path) {
|
|
272
|
-
return Promise.reject(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.UNSUPPORTED));
|
|
273
|
-
}
|
|
274
|
-
async handleXcmStep(data, path, xcmFee) {
|
|
275
|
-
const {
|
|
276
|
-
address,
|
|
277
|
-
amount
|
|
278
|
-
} = data;
|
|
279
|
-
const destinationTokenSlug = this.inputAsset;
|
|
280
|
-
const originChainInfo = this.state.getChainInfo(_chainList.COMMON_CHAIN_SLUGS.POLKADOT);
|
|
281
|
-
const originTokenSlug = (0, _utils2._getChainNativeTokenSlug)(originChainInfo);
|
|
282
|
-
const originTokenInfo = this.state.getAssetBySlug(originTokenSlug);
|
|
283
|
-
const destinationTokenInfo = this.state.getAssetBySlug(destinationTokenSlug);
|
|
284
|
-
const substrateApi = this.state.getSubstrateApi(originChainInfo.slug);
|
|
285
|
-
const inputTokenBalance = await this.state.balanceService.getTokenFreeBalance(address, destinationTokenInfo.originChain, destinationTokenSlug);
|
|
286
|
-
const bnInputTokenBalance = new _bn.default(inputTokenBalance.value);
|
|
287
|
-
const bnXcmFee = new _bn.default(xcmFee);
|
|
288
|
-
const bnAmount = new _bn.default(amount);
|
|
289
|
-
const bnTotalAmount = bnAmount.sub(bnInputTokenBalance).add(bnXcmFee);
|
|
290
|
-
const extrinsic = await (0, _xcm.createXcmExtrinsic)({
|
|
291
|
-
chainInfoMap: this.state.getChainInfoMap(),
|
|
292
|
-
destinationTokenInfo,
|
|
293
|
-
originTokenInfo,
|
|
294
|
-
recipient: address,
|
|
295
|
-
sendingValue: bnTotalAmount.toString(),
|
|
296
|
-
substrateApi
|
|
297
|
-
});
|
|
298
|
-
const xcmData = {
|
|
299
|
-
originNetworkKey: originChainInfo.slug,
|
|
300
|
-
destinationNetworkKey: destinationTokenInfo.originChain,
|
|
301
|
-
from: address,
|
|
302
|
-
to: address,
|
|
303
|
-
value: bnTotalAmount.toString(),
|
|
304
|
-
tokenSlug: originTokenSlug,
|
|
305
|
-
showExtraWarning: true
|
|
306
|
-
};
|
|
307
|
-
return {
|
|
308
|
-
txChain: originChainInfo.slug,
|
|
309
|
-
extrinsicType: _KoniTypes.ExtrinsicType.TRANSFER_XCM,
|
|
310
|
-
extrinsic,
|
|
311
|
-
txData: xcmData,
|
|
312
|
-
transferNativeAmount: bnTotalAmount.toString()
|
|
313
|
-
};
|
|
314
|
-
}
|
|
315
|
-
handleYieldJoin(data, path, currentStep) {
|
|
316
|
-
const type = path.steps[currentStep].type;
|
|
317
|
-
switch (type) {
|
|
318
|
-
case _types.YieldStepType.DEFAULT:
|
|
319
|
-
return Promise.reject(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.UNSUPPORTED));
|
|
320
|
-
case _types.YieldStepType.TOKEN_APPROVAL:
|
|
321
|
-
return this.handleTokenApproveStep(data, path);
|
|
322
|
-
case _types.YieldStepType.XCM:
|
|
323
|
-
{
|
|
324
|
-
const xcmFee = path.totalFee[currentStep].amount || '0';
|
|
325
|
-
return this.handleXcmStep(data, path, xcmFee);
|
|
326
|
-
}
|
|
327
|
-
default:
|
|
328
|
-
return this.handleSubmitStep(data, path);
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
/* Submit join action */
|
|
333
|
-
|
|
334
|
-
/* Join pool action */
|
|
335
|
-
|
|
336
|
-
/* Leave pool action */
|
|
337
|
-
|
|
338
|
-
async validateYieldLeave(amount, address, fastLeave, selectedTarget) {
|
|
339
|
-
const poolInfo = await this.getPoolInfo();
|
|
340
|
-
const poolPosition = await this.getPoolPosition(address);
|
|
341
|
-
if (!poolInfo || !poolPosition) {
|
|
342
|
-
return [new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.INTERNAL_ERROR)];
|
|
343
|
-
}
|
|
344
|
-
if (!this.allowDefaultUnstake && !fastLeave) {
|
|
345
|
-
return [new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.INTERNAL_ERROR)];
|
|
346
|
-
}
|
|
347
|
-
if (!this.allowFastUnstake && fastLeave) {
|
|
348
|
-
return [new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.INTERNAL_ERROR)];
|
|
349
|
-
}
|
|
350
|
-
const errors = [];
|
|
351
|
-
const bnActiveStake = new _bn.default(poolPosition.activeStake);
|
|
352
|
-
const bnRemainingStake = bnActiveStake.sub(new _bn.default(amount));
|
|
353
|
-
const minStake = new _bn.default(poolInfo.metadata.minJoinPool || '0');
|
|
354
|
-
const maxUnstake = poolInfo.metadata.maxWithdrawalRequestPerFarmer;
|
|
355
|
-
if (!(bnRemainingStake.isZero() || bnRemainingStake.gte(minStake))) {
|
|
356
|
-
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.INVALID_ACTIVE_STAKE));
|
|
357
|
-
}
|
|
358
|
-
if (poolPosition.unstakings.length > maxUnstake) {
|
|
359
|
-
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.EXCEED_MAX_UNSTAKING, (0, _i18next.t)('You cannot unstake more than {{number}} times', {
|
|
360
|
-
replace: {
|
|
361
|
-
number: maxUnstake
|
|
362
|
-
}
|
|
363
|
-
})));
|
|
364
|
-
}
|
|
365
|
-
return Promise.resolve(errors);
|
|
366
|
-
}
|
|
367
|
-
handleYieldUnstake(amount, address, selectedTarget) {
|
|
368
|
-
return Promise.reject(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.UNSUPPORTED));
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
/* Leave pool action */
|
|
372
|
-
|
|
373
|
-
/* Other action */
|
|
374
|
-
|
|
375
|
-
handleYieldCancelUnstake() {
|
|
376
|
-
return Promise.reject(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.UNSUPPORTED));
|
|
377
|
-
}
|
|
378
|
-
handleYieldClaimReward(address, bondReward) {
|
|
379
|
-
return Promise.reject(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.UNSUPPORTED));
|
|
380
|
-
}
|
|
381
|
-
handleYieldWithdraw(address, unstakingInfo) {
|
|
382
|
-
return Promise.reject(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.UNSUPPORTED));
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
/* Other actions */
|
|
386
|
-
}
|
|
387
|
-
exports.default = BaseSpecialStakingPoolHandler;
|