@subwallet/extension-base 1.2.3-0 → 1.2.4-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 +4 -153
- package/background/KoniTypes.js +0 -21
- package/cjs/background/KoniTypes.js +1 -22
- package/cjs/core/logic-validation/earning.js +47 -0
- package/cjs/core/logic-validation/swap.js +99 -0
- package/cjs/core/logic-validation/transfer.js +212 -0
- package/cjs/core/substrate/nominationpools-pallet.js +22 -0
- package/cjs/core/substrate/system-pallet.js +77 -0
- package/cjs/core/substrate/xcm-parser.js +190 -0
- package/cjs/koni/api/dotsama/transfer.js +58 -122
- package/cjs/koni/api/staking/bonding/utils.js +1 -1
- package/cjs/koni/api/xcm/index.js +30 -2
- package/cjs/koni/api/xcm/polkadotXcm.js +12 -20
- package/cjs/koni/api/xcm/utils.js +8 -126
- package/cjs/koni/api/xcm/xTokens.js +10 -8
- package/cjs/koni/api/xcm/xcmPallet.js +6 -6
- package/cjs/koni/background/handlers/Extension.js +223 -356
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/group.js +4 -27
- package/cjs/services/balance-service/helpers/subscribe/index.js +2 -30
- package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +46 -82
- package/cjs/services/balance-service/index.js +11 -9
- package/cjs/services/chain-service/constants.js +2 -2
- package/cjs/services/chain-service/index.js +0 -1
- package/cjs/services/chain-service/utils/index.js +13 -2
- package/cjs/services/earning-service/handlers/base.js +1 -1
- package/cjs/services/earning-service/handlers/special.js +11 -12
- package/cjs/services/migration-service/scripts/MigrateTransactionHistoryBySymbol.js +2 -1
- package/cjs/services/migration-service/scripts/databases/MigrateAssetSetting.js +2 -1
- package/cjs/services/migration-service/scripts/index.js +2 -2
- package/cjs/services/swap-service/handler/base-handler.js +30 -44
- package/cjs/services/swap-service/handler/chainflip-handler.js +23 -21
- package/cjs/services/swap-service/handler/hydradx-handler.js +41 -39
- package/cjs/services/swap-service/index.js +6 -0
- package/cjs/services/swap-service/utils.js +8 -49
- package/cjs/services/transaction-service/index.js +66 -155
- package/core/logic-validation/earning.d.ts +10 -0
- package/core/logic-validation/earning.js +37 -0
- package/core/logic-validation/swap.d.ts +8 -0
- package/core/logic-validation/swap.js +89 -0
- package/core/logic-validation/transfer.d.ts +16 -0
- package/core/logic-validation/transfer.js +199 -0
- package/core/substrate/nominationpools-pallet.d.ts +10 -0
- package/core/substrate/nominationpools-pallet.js +13 -0
- package/core/substrate/system-pallet.d.ts +27 -0
- package/core/substrate/system-pallet.js +70 -0
- package/core/substrate/xcm-parser.d.ts +49 -0
- package/core/substrate/xcm-parser.js +181 -0
- package/koni/api/dotsama/transfer.d.ts +3 -4
- package/koni/api/dotsama/transfer.js +54 -118
- package/koni/api/staking/bonding/relayChain.d.ts +2 -1
- package/koni/api/staking/bonding/utils.js +1 -1
- package/koni/api/xcm/index.d.ts +2 -0
- package/koni/api/xcm/index.js +27 -1
- package/koni/api/xcm/polkadotXcm.js +14 -22
- package/koni/api/xcm/utils.d.ts +3 -48
- package/koni/api/xcm/utils.js +5 -114
- package/koni/api/xcm/xTokens.js +12 -10
- package/koni/api/xcm/xcmPallet.js +7 -7
- package/koni/background/handlers/Extension.d.ts +6 -8
- package/koni/background/handlers/Extension.js +117 -247
- package/package.json +39 -9
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/group.js +4 -27
- package/services/balance-service/helpers/subscribe/index.d.ts +2 -1
- package/services/balance-service/helpers/subscribe/index.js +2 -30
- package/services/balance-service/helpers/subscribe/substrate/index.d.ts +2 -1
- package/services/balance-service/helpers/subscribe/substrate/index.js +31 -66
- package/services/balance-service/index.d.ts +7 -6
- package/services/balance-service/index.js +12 -10
- package/services/chain-service/constants.js +2 -2
- package/services/chain-service/index.js +0 -1
- package/services/chain-service/utils/index.d.ts +4 -2
- package/services/chain-service/utils/index.js +9 -2
- package/services/earning-service/handlers/base.js +1 -1
- package/services/earning-service/handlers/nomination-pool/index.d.ts +2 -1
- package/services/earning-service/handlers/special.js +11 -12
- package/services/migration-service/scripts/MigrateTransactionHistoryBySymbol.js +2 -1
- package/services/migration-service/scripts/databases/MigrateAssetSetting.js +2 -1
- package/services/migration-service/scripts/index.js +2 -2
- package/services/swap-service/handler/base-handler.d.ts +3 -2
- package/services/swap-service/handler/base-handler.js +28 -42
- package/services/swap-service/handler/chainflip-handler.d.ts +2 -1
- package/services/swap-service/handler/chainflip-handler.js +4 -2
- package/services/swap-service/handler/hydradx-handler.d.ts +2 -1
- package/services/swap-service/handler/hydradx-handler.js +8 -6
- package/services/swap-service/index.js +7 -1
- package/services/swap-service/utils.d.ts +2 -4
- package/services/swap-service/utils.js +7 -47
- package/services/transaction-service/index.d.ts +1 -1
- package/services/transaction-service/index.js +30 -119
- package/services/transaction-service/types.d.ts +1 -0
- package/types/balance/index.d.ts +6 -10
- package/types/yield/info/pallet.d.ts +0 -6
package/cjs/packageInfo.js
CHANGED
|
@@ -6,8 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.groupBalance = void 0;
|
|
8
8
|
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
9
|
-
var
|
|
10
|
-
var _bn = _interopRequireDefault(require("bn.js"));
|
|
9
|
+
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
11
10
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
12
11
|
// SPDX-License-Identifier: Apache-2.0
|
|
13
12
|
|
|
@@ -20,34 +19,12 @@ var _bn = _interopRequireDefault(require("bn.js"));
|
|
|
20
19
|
*/
|
|
21
20
|
const groupBalance = (items, address, token) => {
|
|
22
21
|
const states = items.map(item => item.state);
|
|
23
|
-
|
|
22
|
+
return {
|
|
24
23
|
address,
|
|
25
24
|
tokenSlug: token,
|
|
26
|
-
free: (
|
|
27
|
-
locked: (
|
|
25
|
+
free: _bignumber.default.sum.apply(null, items.map(item => item.free)).toFixed(),
|
|
26
|
+
locked: _bignumber.default.sum.apply(null, items.map(item => item.locked)).toFixed(),
|
|
28
27
|
state: states.every(item => item === _KoniTypes.APIItemState.NOT_SUPPORT) ? _KoniTypes.APIItemState.NOT_SUPPORT : states.some(item => item === _KoniTypes.APIItemState.READY) ? _KoniTypes.APIItemState.READY : _KoniTypes.APIItemState.PENDING
|
|
29
28
|
};
|
|
30
|
-
for (const item of items) {
|
|
31
|
-
if (item.substrateInfo) {
|
|
32
|
-
if (!result.substrateInfo) {
|
|
33
|
-
result.substrateInfo = {
|
|
34
|
-
...item.substrateInfo
|
|
35
|
-
};
|
|
36
|
-
} else {
|
|
37
|
-
const old = {
|
|
38
|
-
...result.substrateInfo
|
|
39
|
-
};
|
|
40
|
-
const _new = {
|
|
41
|
-
...item.substrateInfo
|
|
42
|
-
};
|
|
43
|
-
result.substrateInfo = {
|
|
44
|
-
reserved: new _bn.default(old.reserved || '0').add(new _bn.default(_new.reserved || '0')).toString(),
|
|
45
|
-
feeFrozen: new _bn.default(old.feeFrozen || '0').add(new _bn.default(_new.feeFrozen || '0')).toString(),
|
|
46
|
-
miscFrozen: new _bn.default(old.miscFrozen || '0').add(new _bn.default(_new.miscFrozen || '0')).toString()
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return result;
|
|
52
29
|
};
|
|
53
30
|
exports.groupBalance = groupBalance;
|
|
@@ -75,18 +75,8 @@ const filterAddress = (addresses, chainInfo) => {
|
|
|
75
75
|
}
|
|
76
76
|
};
|
|
77
77
|
|
|
78
|
-
// interface SubscribeBlanceOptions {
|
|
79
|
-
// addresses: string[];
|
|
80
|
-
// chains: string[];
|
|
81
|
-
// tokens: string[];
|
|
82
|
-
// chainInfoMap: Record<string, _ChainInfo>;
|
|
83
|
-
// substrateApiMap: Record<string, _SubstrateApi>;
|
|
84
|
-
// evmApiMap: Record<string, _EvmApi>;
|
|
85
|
-
// callback: (rs: BalanceItem[]) => void;
|
|
86
|
-
// }
|
|
87
|
-
|
|
88
78
|
// main subscription, use for multiple chains, multiple addresses and multiple tokens
|
|
89
|
-
function subscribeBalance(addresses, chains, tokens, _chainAssetMap, _chainInfoMap, substrateApiMap, evmApiMap, callback) {
|
|
79
|
+
function subscribeBalance(addresses, chains, tokens, _chainAssetMap, _chainInfoMap, substrateApiMap, evmApiMap, callback, extrinsicType) {
|
|
90
80
|
// Filter chain and token
|
|
91
81
|
const chainAssetMap = Object.fromEntries(Object.entries(_chainAssetMap).filter(_ref => {
|
|
92
82
|
let [token] = _ref;
|
|
@@ -126,26 +116,8 @@ function subscribeBalance(addresses, chains, tokens, _chainAssetMap, _chainInfoM
|
|
|
126
116
|
evmApi
|
|
127
117
|
});
|
|
128
118
|
}
|
|
129
|
-
|
|
130
|
-
// if (!useAddresses || useAddresses.length === 0 || _PURE_EVM_CHAINS.indexOf(chainSlug) > -1) {
|
|
131
|
-
// const fungibleTokensByChain = state.chainService.getFungibleTokensByChain(chainSlug, true);
|
|
132
|
-
// const now = new Date().getTime();
|
|
133
|
-
//
|
|
134
|
-
// Object.values(fungibleTokensByChain).map((token) => {
|
|
135
|
-
// return {
|
|
136
|
-
// tokenSlug: token.slug,
|
|
137
|
-
// free: '0',
|
|
138
|
-
// locked: '0',
|
|
139
|
-
// state: APIItemState.READY,
|
|
140
|
-
// timestamp: now
|
|
141
|
-
// } as BalanceItem;
|
|
142
|
-
// }).forEach(callback);
|
|
143
|
-
//
|
|
144
|
-
// return undefined;
|
|
145
|
-
// }
|
|
146
|
-
|
|
147
119
|
const substrateApi = await substrateApiMap[chainSlug].isReady;
|
|
148
|
-
return (0, _substrate.subscribeSubstrateBalance)(useAddresses, chainInfo, chainAssetMap, substrateApi, evmApi, callback);
|
|
120
|
+
return (0, _substrate.subscribeSubstrateBalance)(useAddresses, chainInfo, chainAssetMap, substrateApi, evmApi, callback, extrinsicType);
|
|
149
121
|
});
|
|
150
122
|
return () => {
|
|
151
123
|
unsubList.forEach(subProm => {
|
|
@@ -9,6 +9,8 @@ var _api = require("@gear-js/api");
|
|
|
9
9
|
var _types = require("@subwallet/chain-list/types");
|
|
10
10
|
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
11
11
|
var _constants = require("@subwallet/extension-base/constants");
|
|
12
|
+
var _nominationpoolsPallet = require("@subwallet/extension-base/core/substrate/nominationpools-pallet");
|
|
13
|
+
var _systemPallet = require("@subwallet/extension-base/core/substrate/system-pallet");
|
|
12
14
|
var _wasm = require("@subwallet/extension-base/koni/api/tokens/wasm");
|
|
13
15
|
var _utils = require("@subwallet/extension-base/koni/api/tokens/wasm/utils");
|
|
14
16
|
var _constants2 = require("@subwallet/extension-base/services/chain-service/constants");
|
|
@@ -23,7 +25,7 @@ var _equilibrium = require("./equilibrium");
|
|
|
23
25
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
24
26
|
// SPDX-License-Identifier: Apache-2.0
|
|
25
27
|
|
|
26
|
-
const subscribeSubstrateBalance = async (addresses, chainInfo, assetMap, substrateApi, evmApi, callback) => {
|
|
28
|
+
const subscribeSubstrateBalance = async (addresses, chainInfo, assetMap, substrateApi, evmApi, callback, extrinsicType) => {
|
|
27
29
|
let unsubNativeToken;
|
|
28
30
|
let unsubLocalToken;
|
|
29
31
|
let unsubEvmContractToken;
|
|
@@ -35,7 +37,8 @@ const subscribeSubstrateBalance = async (addresses, chainInfo, assetMap, substra
|
|
|
35
37
|
addresses,
|
|
36
38
|
chainInfo,
|
|
37
39
|
assetMap,
|
|
38
|
-
callback
|
|
40
|
+
callback,
|
|
41
|
+
extrinsicType
|
|
39
42
|
};
|
|
40
43
|
const substrateParams = {
|
|
41
44
|
...baseParams,
|
|
@@ -107,11 +110,13 @@ const subscribeWithSystemAccountPallet = async _ref => {
|
|
|
107
110
|
addresses,
|
|
108
111
|
callback,
|
|
109
112
|
chainInfo,
|
|
113
|
+
extrinsicType,
|
|
110
114
|
substrateApi
|
|
111
115
|
} = _ref;
|
|
112
116
|
const chainNativeTokenSlug = (0, _utils2._getChainNativeTokenSlug)(chainInfo);
|
|
113
117
|
const balanceSubscribe = substrateApi.rx.query.system.account.multi(addresses);
|
|
114
|
-
let poolSubscribe;
|
|
118
|
+
let poolSubscribe; // add points in nomination pool back to user's balance
|
|
119
|
+
|
|
115
120
|
if ((0, _utils2._isSubstrateRelayChain)(chainInfo) && substrateApi.query.nominationPools) {
|
|
116
121
|
var _substrateApi$rx$quer;
|
|
117
122
|
poolSubscribe = (_substrateApi$rx$quer = substrateApi.rx.query.nominationPools.poolMembers) === null || _substrateApi$rx$quer === void 0 ? void 0 : _substrateApi$rx$quer.multi(addresses);
|
|
@@ -127,54 +132,26 @@ const subscribeWithSystemAccountPallet = async _ref => {
|
|
|
127
132
|
}
|
|
128
133
|
const subscription = (0, _rxjs.combineLatest)({
|
|
129
134
|
balances: balanceSubscribe,
|
|
130
|
-
|
|
135
|
+
poolMemberInfos: poolSubscribe
|
|
131
136
|
}).subscribe(_ref2 => {
|
|
132
137
|
let {
|
|
133
|
-
balances
|
|
134
|
-
|
|
138
|
+
balances,
|
|
139
|
+
poolMemberInfos
|
|
135
140
|
} = _ref2;
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
let [, amount] = _ref3;
|
|
144
|
-
pooled = pooled.add(new _util.BN(amount));
|
|
145
|
-
});
|
|
146
|
-
pooledStakingBalances.push(pooled);
|
|
147
|
-
} else {
|
|
148
|
-
pooledStakingBalances.push(_util.BN_ZERO);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
const items = balances.map((balance, index) => {
|
|
152
|
-
var _balance$data, _balance$data$free, _balance$data2, _balance$data2$reserv, _balance$data3, _balance$data3$miscFr, _balance$data4, _balance$data4$frozen, _balance$data5, _balance$data5$feeFro;
|
|
153
|
-
let total = ((_balance$data = balance.data) === null || _balance$data === void 0 ? void 0 : (_balance$data$free = _balance$data.free) === null || _balance$data$free === void 0 ? void 0 : _balance$data$free.toBn()) || new _util.BN(0);
|
|
154
|
-
const reserved = ((_balance$data2 = balance.data) === null || _balance$data2 === void 0 ? void 0 : (_balance$data2$reserv = _balance$data2.reserved) === null || _balance$data2$reserv === void 0 ? void 0 : _balance$data2$reserv.toBn()) || new _util.BN(0);
|
|
155
|
-
// @ts-ignore
|
|
156
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
157
|
-
const miscFrozen = ((_balance$data3 = balance.data) === null || _balance$data3 === void 0 ? void 0 : (_balance$data3$miscFr = _balance$data3.miscFrozen) === null || _balance$data3$miscFr === void 0 ? void 0 : _balance$data3$miscFr.toBn()) || (balance === null || balance === void 0 ? void 0 : (_balance$data4 = balance.data) === null || _balance$data4 === void 0 ? void 0 : (_balance$data4$frozen = _balance$data4.frozen) === null || _balance$data4$frozen === void 0 ? void 0 : _balance$data4$frozen.toBn()) || new _util.BN(0);
|
|
158
|
-
const feeFrozen = ((_balance$data5 = balance.data) === null || _balance$data5 === void 0 ? void 0 : (_balance$data5$feeFro = _balance$data5.feeFrozen) === null || _balance$data5$feeFro === void 0 ? void 0 : _balance$data5$feeFro.toBn()) || new _util.BN(0);
|
|
159
|
-
let locked = reserved.add(miscFrozen);
|
|
160
|
-
total = total.add(reserved);
|
|
161
|
-
const pooledStakingBalance = pooledStakingBalances[index] || _util.BN_ZERO;
|
|
162
|
-
if (pooledStakingBalance.gt(_util.BN_ZERO)) {
|
|
163
|
-
total = total.add(pooledStakingBalance);
|
|
164
|
-
locked = locked.add(pooledStakingBalance);
|
|
165
|
-
}
|
|
166
|
-
const free = total.sub(locked);
|
|
141
|
+
const items = balances.map((_balance, index) => {
|
|
142
|
+
const balanceInfo = _balance.toPrimitive();
|
|
143
|
+
const poolMemberInfo = poolMemberInfos[index].toPrimitive();
|
|
144
|
+
const nominationPoolBalance = poolMemberInfo ? (0, _nominationpoolsPallet._getTotalStakeInNominationPool)(poolMemberInfo) : new _bignumber.default(0);
|
|
145
|
+
const transferableBalance = (0, _systemPallet._getSystemPalletTransferable)(balanceInfo, (0, _utils2._getChainExistentialDeposit)(chainInfo), extrinsicType);
|
|
146
|
+
const totalBalance = (0, _systemPallet._getSystemPalletTotalBalance)(balanceInfo);
|
|
147
|
+
const totalLockedFromTransfer = new _bignumber.default(totalBalance).minus(transferableBalance).plus(nominationPoolBalance);
|
|
167
148
|
return {
|
|
168
149
|
address: addresses[index],
|
|
169
150
|
tokenSlug: chainNativeTokenSlug,
|
|
170
|
-
free:
|
|
171
|
-
locked:
|
|
151
|
+
free: transferableBalance,
|
|
152
|
+
locked: totalLockedFromTransfer.toFixed(),
|
|
172
153
|
state: _KoniTypes.APIItemState.READY,
|
|
173
|
-
|
|
174
|
-
miscFrozen: miscFrozen.toString(),
|
|
175
|
-
reserved: reserved.toString(),
|
|
176
|
-
feeFrozen: feeFrozen.toString()
|
|
177
|
-
}
|
|
154
|
+
metadata: balanceInfo
|
|
178
155
|
};
|
|
179
156
|
});
|
|
180
157
|
callback(items);
|
|
@@ -183,14 +160,14 @@ const subscribeWithSystemAccountPallet = async _ref => {
|
|
|
183
160
|
subscription.unsubscribe();
|
|
184
161
|
};
|
|
185
162
|
};
|
|
186
|
-
const subscribeBridgedBalance = async
|
|
163
|
+
const subscribeBridgedBalance = async _ref3 => {
|
|
187
164
|
let {
|
|
188
165
|
addresses,
|
|
189
166
|
assetMap,
|
|
190
167
|
callback,
|
|
191
168
|
chainInfo,
|
|
192
169
|
substrateApi
|
|
193
|
-
} =
|
|
170
|
+
} = _ref3;
|
|
194
171
|
const chain = chainInfo.slug;
|
|
195
172
|
const tokenMap = (0, _utils3.filterAssetsByChainAndType)(assetMap, chain, [_types._AssetType.LOCAL]);
|
|
196
173
|
|
|
@@ -199,8 +176,8 @@ const subscribeBridgedBalance = async _ref4 => {
|
|
|
199
176
|
try {
|
|
200
177
|
const isBridgedToken = (0, _utils2._isBridgedToken)(tokenInfo);
|
|
201
178
|
if (isBridgedToken) {
|
|
202
|
-
const
|
|
203
|
-
return await substrateApi.query.foreignAssets.account.multi(addresses.map(address => [
|
|
179
|
+
const onChainInfo = (0, _utils2._getTokenOnChainInfo)(tokenInfo);
|
|
180
|
+
return await substrateApi.query.foreignAssets.account.multi(addresses.map(address => [onChainInfo, address]), balances => {
|
|
204
181
|
const items = balances.map((balance, index) => {
|
|
205
182
|
const bdata = balance === null || balance === void 0 ? void 0 : balance.toHuman();
|
|
206
183
|
let frozen = _util.BN_ZERO;
|
|
@@ -223,11 +200,7 @@ const subscribeBridgedBalance = async _ref4 => {
|
|
|
223
200
|
tokenSlug: tokenInfo.slug,
|
|
224
201
|
free: free.toString(),
|
|
225
202
|
locked: frozen.toString(),
|
|
226
|
-
state: _KoniTypes.APIItemState.READY
|
|
227
|
-
substrateInfo: {
|
|
228
|
-
miscFrozen: frozen.toString(),
|
|
229
|
-
reserved: '0'
|
|
230
|
-
}
|
|
203
|
+
state: _KoniTypes.APIItemState.READY
|
|
231
204
|
};
|
|
232
205
|
});
|
|
233
206
|
callback(items);
|
|
@@ -253,19 +226,19 @@ function extractOkResponse(response) {
|
|
|
253
226
|
}
|
|
254
227
|
return undefined;
|
|
255
228
|
}
|
|
256
|
-
const subscribePSP22Balance =
|
|
229
|
+
const subscribePSP22Balance = _ref4 => {
|
|
257
230
|
let {
|
|
258
231
|
addresses,
|
|
259
232
|
assetMap,
|
|
260
233
|
callback,
|
|
261
234
|
chainInfo,
|
|
262
235
|
substrateApi
|
|
263
|
-
} =
|
|
236
|
+
} = _ref4;
|
|
264
237
|
const chain = chainInfo.slug;
|
|
265
238
|
const psp22ContractMap = {};
|
|
266
239
|
const tokenList = (0, _utils3.filterAssetsByChainAndType)(assetMap, chain, [_types._AssetType.PSP22]);
|
|
267
|
-
Object.entries(tokenList).forEach(
|
|
268
|
-
let [slug, tokenInfo] =
|
|
240
|
+
Object.entries(tokenList).forEach(_ref5 => {
|
|
241
|
+
let [slug, tokenInfo] = _ref5;
|
|
269
242
|
psp22ContractMap[slug] = (0, _wasm.getPSP22ContractPromise)(substrateApi, (0, _utils2._getContractAddressOfToken)(tokenInfo));
|
|
270
243
|
});
|
|
271
244
|
const getTokenBalances = () => {
|
|
@@ -312,7 +285,7 @@ const subscribePSP22Balance = _ref5 => {
|
|
|
312
285
|
clearInterval(interval);
|
|
313
286
|
};
|
|
314
287
|
};
|
|
315
|
-
const subscribeTokensAccountsPallet = async
|
|
288
|
+
const subscribeTokensAccountsPallet = async _ref6 => {
|
|
316
289
|
let {
|
|
317
290
|
addresses,
|
|
318
291
|
assetMap,
|
|
@@ -320,7 +293,7 @@ const subscribeTokensAccountsPallet = async _ref7 => {
|
|
|
320
293
|
chainInfo,
|
|
321
294
|
includeNativeToken,
|
|
322
295
|
substrateApi
|
|
323
|
-
} =
|
|
296
|
+
} = _ref6;
|
|
324
297
|
const chain = chainInfo.slug;
|
|
325
298
|
const tokenTypes = includeNativeToken ? [_types._AssetType.NATIVE, _types._AssetType.LOCAL] : [_types._AssetType.LOCAL];
|
|
326
299
|
const tokenMap = (0, _utils3.filterAssetsByChainAndType)(assetMap, chain, tokenTypes);
|
|
@@ -346,11 +319,7 @@ const subscribeTokensAccountsPallet = async _ref7 => {
|
|
|
346
319
|
tokenSlug: tokenInfo.slug,
|
|
347
320
|
state: _KoniTypes.APIItemState.READY,
|
|
348
321
|
free: freeBalance.toString(),
|
|
349
|
-
locked: lockedBalance.toString()
|
|
350
|
-
substrateInfo: {
|
|
351
|
-
reserved: tokenBalance.reserved.toString(),
|
|
352
|
-
miscFrozen: tokenBalance.frozen.toString()
|
|
353
|
-
}
|
|
322
|
+
locked: lockedBalance.toString()
|
|
354
323
|
};
|
|
355
324
|
});
|
|
356
325
|
callback(items);
|
|
@@ -366,7 +335,7 @@ const subscribeTokensAccountsPallet = async _ref7 => {
|
|
|
366
335
|
});
|
|
367
336
|
};
|
|
368
337
|
};
|
|
369
|
-
const subscribeAssetsAccountPallet = async
|
|
338
|
+
const subscribeAssetsAccountPallet = async _ref7 => {
|
|
370
339
|
let {
|
|
371
340
|
addresses,
|
|
372
341
|
assetMap,
|
|
@@ -374,7 +343,7 @@ const subscribeAssetsAccountPallet = async _ref8 => {
|
|
|
374
343
|
chainInfo,
|
|
375
344
|
includeNativeToken,
|
|
376
345
|
substrateApi
|
|
377
|
-
} =
|
|
346
|
+
} = _ref7;
|
|
378
347
|
const chain = chainInfo.slug;
|
|
379
348
|
const tokenMap = (0, _utils3.filterAssetsByChainAndType)(assetMap, chain, [_types._AssetType.LOCAL]);
|
|
380
349
|
Object.values(tokenMap).forEach(token => {
|
|
@@ -385,6 +354,9 @@ const subscribeAssetsAccountPallet = async _ref8 => {
|
|
|
385
354
|
const unsubList = await Promise.all(Object.values(tokenMap).map(async tokenInfo => {
|
|
386
355
|
try {
|
|
387
356
|
const assetIndex = (0, _utils2._getTokenOnChainAssetId)(tokenInfo);
|
|
357
|
+
if (assetIndex === '-1') {
|
|
358
|
+
return undefined;
|
|
359
|
+
}
|
|
388
360
|
|
|
389
361
|
// Get Token Balance
|
|
390
362
|
return await substrateApi.query.assets.account.multi(addresses.map(address => [assetIndex, address]), balances => {
|
|
@@ -409,11 +381,7 @@ const subscribeAssetsAccountPallet = async _ref8 => {
|
|
|
409
381
|
tokenSlug: tokenInfo.slug,
|
|
410
382
|
free: free.toString(),
|
|
411
383
|
locked: frozen.toString(),
|
|
412
|
-
state: _KoniTypes.APIItemState.READY
|
|
413
|
-
substrateInfo: {
|
|
414
|
-
miscFrozen: frozen.toString(),
|
|
415
|
-
reserved: '0'
|
|
416
|
-
}
|
|
384
|
+
state: _KoniTypes.APIItemState.READY
|
|
417
385
|
};
|
|
418
386
|
});
|
|
419
387
|
callback(items);
|
|
@@ -431,14 +399,14 @@ const subscribeAssetsAccountPallet = async _ref8 => {
|
|
|
431
399
|
};
|
|
432
400
|
|
|
433
401
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
434
|
-
const subscribeOrmlTokensPallet = async
|
|
402
|
+
const subscribeOrmlTokensPallet = async _ref8 => {
|
|
435
403
|
let {
|
|
436
404
|
addresses,
|
|
437
405
|
assetMap,
|
|
438
406
|
callback,
|
|
439
407
|
chainInfo,
|
|
440
408
|
substrateApi
|
|
441
|
-
} =
|
|
409
|
+
} = _ref8;
|
|
442
410
|
const chain = chainInfo.slug;
|
|
443
411
|
const tokenTypes = [_types._AssetType.LOCAL];
|
|
444
412
|
const tokenMap = (0, _utils3.filterAssetsByChainAndType)(assetMap, chain, tokenTypes);
|
|
@@ -465,11 +433,7 @@ const subscribeOrmlTokensPallet = async _ref9 => {
|
|
|
465
433
|
tokenSlug: tokenInfo.slug,
|
|
466
434
|
state: _KoniTypes.APIItemState.READY,
|
|
467
435
|
free: freeBalance.toString(),
|
|
468
|
-
locked: lockedBalance.toString()
|
|
469
|
-
substrateInfo: {
|
|
470
|
-
reserved: tokenBalance.reserved.toString(),
|
|
471
|
-
miscFrozen: tokenBalance.frozen.toString()
|
|
472
|
-
}
|
|
436
|
+
locked: lockedBalance.toString()
|
|
473
437
|
};
|
|
474
438
|
});
|
|
475
439
|
callback(items);
|
|
@@ -488,14 +452,14 @@ const subscribeOrmlTokensPallet = async _ref9 => {
|
|
|
488
452
|
});
|
|
489
453
|
};
|
|
490
454
|
};
|
|
491
|
-
const subscribeGRC20Balance =
|
|
455
|
+
const subscribeGRC20Balance = _ref9 => {
|
|
492
456
|
let {
|
|
493
457
|
addresses,
|
|
494
458
|
assetMap,
|
|
495
459
|
callback,
|
|
496
460
|
chainInfo,
|
|
497
461
|
substrateApi
|
|
498
|
-
} =
|
|
462
|
+
} = _ref9;
|
|
499
463
|
if (!(substrateApi instanceof _api.GearApi)) {
|
|
500
464
|
console.warn('Cannot subscribe GRC20 balance without GearApi instance');
|
|
501
465
|
return _util.noop;
|
|
@@ -503,8 +467,8 @@ const subscribeGRC20Balance = _ref10 => {
|
|
|
503
467
|
const chain = chainInfo.slug;
|
|
504
468
|
const psp22ContractMap = {};
|
|
505
469
|
const tokenList = (0, _utils3.filterAssetsByChainAndType)(assetMap, chain, [_types._AssetType.GRC20]);
|
|
506
|
-
Object.entries(tokenList).forEach(
|
|
507
|
-
let [slug, tokenInfo] =
|
|
470
|
+
Object.entries(tokenList).forEach(_ref10 => {
|
|
471
|
+
let [slug, tokenInfo] = _ref10;
|
|
508
472
|
psp22ContractMap[slug] = (0, _utils3.getGRC20ContractPromise)(substrateApi, (0, _utils2._getContractAddressOfToken)(tokenInfo));
|
|
509
473
|
});
|
|
510
474
|
const getTokenBalances = () => {
|
|
@@ -165,8 +165,8 @@ class BalanceService {
|
|
|
165
165
|
});
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
-
/** Subscribe token free balance of
|
|
169
|
-
async
|
|
168
|
+
/** Subscribe token free balance of an address on chain */
|
|
169
|
+
async subscribeTransferableBalance(address, chain, tokenSlug, extrinsicType, callback) {
|
|
170
170
|
const chainInfo = this.state.chainService.getChainInfoByKey(chain);
|
|
171
171
|
const chainState = this.state.chainService.getChainStateByKey(chain);
|
|
172
172
|
if (!chainInfo || !chainState || !chainState.active) {
|
|
@@ -199,7 +199,8 @@ class BalanceService {
|
|
|
199
199
|
const balance = {
|
|
200
200
|
value: rs.free,
|
|
201
201
|
decimals: tokenInfo.decimals || 0,
|
|
202
|
-
symbol: tokenInfo.symbol
|
|
202
|
+
symbol: tokenInfo.symbol,
|
|
203
|
+
metadata: rs.metadata
|
|
203
204
|
};
|
|
204
205
|
if (callback) {
|
|
205
206
|
callback(balance);
|
|
@@ -210,7 +211,7 @@ class BalanceService {
|
|
|
210
211
|
}
|
|
211
212
|
resolve([unsub, balance]);
|
|
212
213
|
}
|
|
213
|
-
});
|
|
214
|
+
}, extrinsicType);
|
|
214
215
|
setTimeout(() => {
|
|
215
216
|
if (hasError) {
|
|
216
217
|
var _unsub2;
|
|
@@ -224,15 +225,16 @@ class BalanceService {
|
|
|
224
225
|
/**
|
|
225
226
|
* @public
|
|
226
227
|
* @async
|
|
227
|
-
* @function
|
|
228
|
+
* @function getTransferableBalance
|
|
228
229
|
* @desc Fetch free balance on chain
|
|
229
230
|
* @param {string} address - Address
|
|
230
231
|
* @param {string} chain - Slug of chain
|
|
231
232
|
* @param {string} [tokenSlug] - Slug of token
|
|
233
|
+
* @param extrinsicType - Customize transferable based on context
|
|
232
234
|
* @return {Promise<AmountData>} - Free token balance of address on chain
|
|
233
|
-
|
|
234
|
-
async
|
|
235
|
-
const [, balance] = await this.
|
|
235
|
+
*/
|
|
236
|
+
async getTransferableBalance(address, chain, tokenSlug, extrinsicType) {
|
|
237
|
+
const [, balance] = await this.subscribeTransferableBalance(address, chain, tokenSlug, extrinsicType);
|
|
236
238
|
return balance;
|
|
237
239
|
}
|
|
238
240
|
|
|
@@ -334,7 +336,7 @@ class BalanceService {
|
|
|
334
336
|
}).map(asset => asset.slug);
|
|
335
337
|
const unsub = (0, _helpers.subscribeBalance)(addresses, activeChainSlugs, assets, assetMap, chainInfoMap, substrateApiMap, evmApiMap, result => {
|
|
336
338
|
!cancel && this.setBalanceItem(result);
|
|
337
|
-
});
|
|
339
|
+
}, _KoniTypes.ExtrinsicType.TRANSFER_BALANCE);
|
|
338
340
|
const unsub2 = this.state.subscribeMantaPayBalance();
|
|
339
341
|
this._unsubscribeBalance = () => {
|
|
340
342
|
cancel = true;
|
|
@@ -45,7 +45,7 @@ const _BALANCE_CHAIN_GROUP = {
|
|
|
45
45
|
kusama: ['kusama', 'kintsugi', 'kintsugi_test', 'interlay', 'acala', 'statemint', 'karura', 'bifrost'],
|
|
46
46
|
// perhaps there are some runtime updates
|
|
47
47
|
centrifuge: ['centrifuge'],
|
|
48
|
-
supportBridged: ['rococo_assethub']
|
|
48
|
+
supportBridged: ['rococo_assethub', 'statemint', 'statemine']
|
|
49
49
|
};
|
|
50
50
|
exports._BALANCE_CHAIN_GROUP = _BALANCE_CHAIN_GROUP;
|
|
51
51
|
const _BALANCE_TOKEN_GROUP = {
|
|
@@ -271,7 +271,7 @@ const _DEFAULT_MANTA_ZK_CHAIN = 'calamari';
|
|
|
271
271
|
// XCM------------------------------------------------------------------------------------------------------------------
|
|
272
272
|
exports._DEFAULT_MANTA_ZK_CHAIN = _DEFAULT_MANTA_ZK_CHAIN;
|
|
273
273
|
const _XCM_CHAIN_GROUP = {
|
|
274
|
-
polkadotXcm: ['astar', 'shiden', 'statemine', 'statemint', 'equilibrium_parachain'],
|
|
274
|
+
polkadotXcm: ['astar', 'shiden', 'statemine', 'statemint', 'equilibrium_parachain', 'rococo_assethub'],
|
|
275
275
|
xcmPallet: ['polkadot', 'kusama']
|
|
276
276
|
// default is xTokens pallet
|
|
277
277
|
};
|
|
@@ -497,7 +497,6 @@ class ChainService {
|
|
|
497
497
|
needUpdateChainApiList,
|
|
498
498
|
storedChainInfoList
|
|
499
499
|
} = (0, _utils.updateLatestChainInfo)(this.dataMap, latestChainInfo);
|
|
500
|
-
console.log('here', needUpdateChainApiList, storedChainInfoList);
|
|
501
500
|
this.dbService.bulkUpdateChainStore(storedChainInfoList).catch(console.error);
|
|
502
501
|
this.updateChainSubscription();
|
|
503
502
|
needUpdateChainApiList.forEach(chainInfo => {
|
|
@@ -54,6 +54,7 @@ var _exportNames = {
|
|
|
54
54
|
_getXcmAssetId: true,
|
|
55
55
|
_getXcmAssetMultilocation: true,
|
|
56
56
|
_getXcmTransferType: true,
|
|
57
|
+
_isRelayChain: true,
|
|
57
58
|
_isSubstrateRelayChain: true,
|
|
58
59
|
_isSubstrateParaChain: true,
|
|
59
60
|
_getEvmAbiExplorer: true,
|
|
@@ -78,6 +79,7 @@ var _exportNames = {
|
|
|
78
79
|
findChainInfoByHalfGenesisHash: true,
|
|
79
80
|
findChainInfoByChainId: true,
|
|
80
81
|
_isMantaZkAsset: true,
|
|
82
|
+
_getChainExistentialDeposit: true,
|
|
81
83
|
randomizeProvider: true,
|
|
82
84
|
_isAssetCanPayTxFee: true,
|
|
83
85
|
updateLatestChainInfo: true
|
|
@@ -90,6 +92,7 @@ exports._getAssetOriginChain = _getAssetOriginChain;
|
|
|
90
92
|
exports._getAssetPriceId = _getAssetPriceId;
|
|
91
93
|
exports._getAssetSymbol = _getAssetSymbol;
|
|
92
94
|
exports._getBlockExplorerFromChain = _getBlockExplorerFromChain;
|
|
95
|
+
exports._getChainExistentialDeposit = _getChainExistentialDeposit;
|
|
93
96
|
exports._getChainName = _getChainName;
|
|
94
97
|
exports._getChainNativeTokenBasicInfo = _getChainNativeTokenBasicInfo;
|
|
95
98
|
exports._getChainNativeTokenSlug = _getChainNativeTokenSlug;
|
|
@@ -143,6 +146,7 @@ exports._isNativeTokenBySlug = _isNativeTokenBySlug;
|
|
|
143
146
|
exports._isNativeTokenTransferredByEvm = _isNativeTokenTransferredByEvm;
|
|
144
147
|
exports._isPureEvmChain = _isPureEvmChain;
|
|
145
148
|
exports._isPureSubstrateChain = _isPureSubstrateChain;
|
|
149
|
+
exports._isRelayChain = _isRelayChain;
|
|
146
150
|
exports._isSmartContractToken = _isSmartContractToken;
|
|
147
151
|
exports._isSubstrateChain = _isSubstrateChain;
|
|
148
152
|
exports._isSubstrateParaChain = _isSubstrateParaChain;
|
|
@@ -303,7 +307,7 @@ function _isSubstrateChain(chainInfo) {
|
|
|
303
307
|
|
|
304
308
|
function _getEvmChainId(chainInfo) {
|
|
305
309
|
var _chainInfo$evmInfo;
|
|
306
|
-
return (
|
|
310
|
+
return (_chainInfo$evmInfo = chainInfo.evmInfo) === null || _chainInfo$evmInfo === void 0 ? void 0 : _chainInfo$evmInfo.evmChainId; // fallback to Ethereum
|
|
307
311
|
}
|
|
308
312
|
|
|
309
313
|
function _getSubstrateParaId(chainInfo) {
|
|
@@ -312,7 +316,7 @@ function _getSubstrateParaId(chainInfo) {
|
|
|
312
316
|
}
|
|
313
317
|
function _getSubstrateRelayParent(chainInfo) {
|
|
314
318
|
var _chainInfo$substrateI2;
|
|
315
|
-
return (
|
|
319
|
+
return (_chainInfo$substrateI2 = chainInfo.substrateInfo) === null || _chainInfo$substrateI2 === void 0 ? void 0 : _chainInfo$substrateI2.relaySlug;
|
|
316
320
|
}
|
|
317
321
|
function _getSubstrateGenesisHash(chainInfo) {
|
|
318
322
|
var _chainInfo$substrateI3;
|
|
@@ -465,6 +469,9 @@ function _getXcmTransferType(originChainInfo, destinationChainInfo) {
|
|
|
465
469
|
var _originChainInfo$subs, _destinationChainInfo;
|
|
466
470
|
return `${((_originChainInfo$subs = originChainInfo.substrateInfo) === null || _originChainInfo$subs === void 0 ? void 0 : _originChainInfo$subs.chainType) || ''}-${((_destinationChainInfo = destinationChainInfo.substrateInfo) === null || _destinationChainInfo === void 0 ? void 0 : _destinationChainInfo.chainType) || ''}`;
|
|
467
471
|
}
|
|
472
|
+
function _isRelayChain(chainInfo) {
|
|
473
|
+
return _isSubstrateRelayChain(chainInfo) || _isPureEvmChain(chainInfo);
|
|
474
|
+
}
|
|
468
475
|
function _isSubstrateRelayChain(chainInfo) {
|
|
469
476
|
var _chainInfo$substrateI14;
|
|
470
477
|
return ((_chainInfo$substrateI14 = chainInfo.substrateInfo) === null || _chainInfo$substrateI14 === void 0 ? void 0 : _chainInfo$substrateI14.chainType) === _types._SubstrateChainType.RELAYCHAIN;
|
|
@@ -582,6 +589,10 @@ exports.findChainInfoByChainId = findChainInfoByChainId;
|
|
|
582
589
|
function _isMantaZkAsset(chainAsset) {
|
|
583
590
|
return _constants._MANTA_ZK_CHAIN_GROUP.includes(chainAsset.originChain) && chainAsset.symbol.startsWith(_constants._ZK_ASSET_PREFIX);
|
|
584
591
|
}
|
|
592
|
+
function _getChainExistentialDeposit(chainInfo) {
|
|
593
|
+
var _chainInfo$substrateI18;
|
|
594
|
+
return (chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$substrateI18 = chainInfo.substrateInfo) === null || _chainInfo$substrateI18 === void 0 ? void 0 : _chainInfo$substrateI18.existentialDeposit) || '0';
|
|
595
|
+
}
|
|
585
596
|
function randomizeProvider(providers, excludedKeys) {
|
|
586
597
|
if (Object.keys(providers).length === 0) {
|
|
587
598
|
return {
|
|
@@ -134,7 +134,7 @@ class BasePoolHandler {
|
|
|
134
134
|
};
|
|
135
135
|
}
|
|
136
136
|
const nativeTokenInfo = this.state.chainService.getNativeTokenInfo(this.chain);
|
|
137
|
-
const nativeTokenBalance = await this.state.balanceService.
|
|
137
|
+
const nativeTokenBalance = await this.state.balanceService.getTransferableBalance(request.address, this.chain);
|
|
138
138
|
const bnNativeTokenBalance = new _util.BN(nativeTokenBalance.value);
|
|
139
139
|
const bnMinBalanceToJoin = new _util.BN(((_poolInfo$statistic2 = poolInfo.statistic) === null || _poolInfo$statistic2 === void 0 ? void 0 : (_poolInfo$statistic2$ = _poolInfo$statistic2.earningThreshold) === null || _poolInfo$statistic2$ === void 0 ? void 0 : _poolInfo$statistic2$.join) || '0').add(new _util.BN(poolInfo.metadata.maintainBalance));
|
|
140
140
|
if (bnNativeTokenBalance.lte(bnMinBalanceToJoin)) {
|