@subwallet/extension-base 1.2.23-0 → 1.2.24-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/background/KoniTypes.d.ts +14 -0
  2. package/cjs/constants/index.js +4 -1
  3. package/cjs/core/substrate/assets-pallet.js +35 -0
  4. package/cjs/core/substrate/foreign-asset-pallet.js +13 -3
  5. package/cjs/core/substrate/nominationpools-pallet.js +4 -6
  6. package/cjs/core/substrate/ormlTokens-pallet.js +24 -0
  7. package/cjs/core/substrate/system-pallet.js +16 -18
  8. package/cjs/core/substrate/tokens-pallet.js +24 -0
  9. package/cjs/core/substrate/types.js +19 -0
  10. package/cjs/core/substrate/xcm-parser.js +16 -2
  11. package/cjs/core/utils.js +31 -0
  12. package/cjs/koni/background/cron.js +10 -0
  13. package/cjs/koni/background/handlers/Extension.js +61 -5
  14. package/cjs/koni/background/handlers/State.js +3 -0
  15. package/cjs/packageInfo.js +1 -1
  16. package/cjs/services/balance-service/helpers/subscribe/substrate/equilibrium.js +2 -2
  17. package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +120 -133
  18. package/cjs/services/balance-service/transfer/xcm/index.js +2 -1
  19. package/cjs/services/balance-service/transfer/xcm/polkadotXcm.js +1 -1
  20. package/cjs/services/balance-service/transfer/xcm/utils.js +3 -2
  21. package/cjs/services/chain-service/constants.js +1 -1
  22. package/cjs/services/chain-service/handler/SubstrateApi.js +128 -34
  23. package/cjs/services/chain-service/handler/SubstrateChainHandler.js +26 -9
  24. package/cjs/services/chain-service/utils/index.js +5 -0
  25. package/cjs/services/migration-service/scripts/MigrateLedgerAccountV2.js +3 -3
  26. package/cjs/services/mkt-campaign-service/index.js +284 -0
  27. package/cjs/services/mkt-campaign-service/types.js +17 -0
  28. package/cjs/services/storage-service/DatabaseService.js +115 -0
  29. package/cjs/services/storage-service/db-stores/Balance.js +6 -0
  30. package/cjs/services/storage-service/db-stores/Crowdloan.js +8 -0
  31. package/cjs/services/storage-service/db-stores/Nft.js +12 -0
  32. package/cjs/services/storage-service/db-stores/NftCollection.js +11 -0
  33. package/cjs/services/storage-service/db-stores/YieldPositionStore.js +6 -0
  34. package/constants/index.d.ts +1 -0
  35. package/constants/index.js +1 -0
  36. package/core/substrate/assets-pallet.d.ts +4 -0
  37. package/core/substrate/assets-pallet.js +28 -0
  38. package/core/substrate/foreign-asset-pallet.d.ts +4 -8
  39. package/core/substrate/foreign-asset-pallet.js +13 -3
  40. package/core/substrate/nominationpools-pallet.d.ts +4 -10
  41. package/core/substrate/nominationpools-pallet.js +4 -5
  42. package/core/substrate/ormlTokens-pallet.d.ts +4 -0
  43. package/core/substrate/ormlTokens-pallet.js +17 -0
  44. package/core/substrate/system-pallet.d.ts +4 -24
  45. package/core/substrate/system-pallet.js +16 -21
  46. package/core/substrate/tokens-pallet.d.ts +5 -0
  47. package/core/substrate/tokens-pallet.js +16 -0
  48. package/core/substrate/types.d.ts +43 -0
  49. package/core/substrate/types.js +12 -0
  50. package/core/substrate/xcm-parser.d.ts +1 -0
  51. package/core/substrate/xcm-parser.js +15 -2
  52. package/core/utils.d.ts +4 -0
  53. package/core/utils.js +23 -0
  54. package/koni/api/staking/bonding/relayChain.d.ts +1 -1
  55. package/koni/background/cron.d.ts +1 -0
  56. package/koni/background/cron.js +11 -1
  57. package/koni/background/handlers/Extension.d.ts +3 -0
  58. package/koni/background/handlers/Extension.js +61 -5
  59. package/koni/background/handlers/State.d.ts +4 -2
  60. package/koni/background/handlers/State.js +3 -0
  61. package/package.json +41 -6
  62. package/packageInfo.js +1 -1
  63. package/services/balance-service/helpers/subscribe/substrate/equilibrium.js +2 -2
  64. package/services/balance-service/helpers/subscribe/substrate/index.js +109 -121
  65. package/services/balance-service/transfer/xcm/index.d.ts +1 -1
  66. package/services/balance-service/transfer/xcm/index.js +2 -1
  67. package/services/balance-service/transfer/xcm/polkadotXcm.js +1 -1
  68. package/services/balance-service/transfer/xcm/utils.d.ts +1 -1
  69. package/services/balance-service/transfer/xcm/utils.js +3 -2
  70. package/services/chain-service/constants.js +1 -1
  71. package/services/chain-service/handler/SubstrateApi.d.ts +5 -7
  72. package/services/chain-service/handler/SubstrateApi.js +128 -35
  73. package/services/chain-service/handler/SubstrateChainHandler.d.ts +5 -6
  74. package/services/chain-service/handler/SubstrateChainHandler.js +26 -9
  75. package/services/chain-service/index.d.ts +3 -3
  76. package/services/chain-service/types.d.ts +22 -5
  77. package/services/chain-service/utils/index.d.ts +1 -0
  78. package/services/chain-service/utils/index.js +3 -0
  79. package/services/earning-service/handlers/nomination-pool/index.d.ts +1 -1
  80. package/services/migration-service/scripts/MigrateLedgerAccountV2.js +3 -3
  81. package/services/mkt-campaign-service/index.d.ts +30 -0
  82. package/services/mkt-campaign-service/index.js +275 -0
  83. package/services/mkt-campaign-service/types.d.ts +107 -0
  84. package/services/mkt-campaign-service/types.js +11 -0
  85. package/services/storage-service/DatabaseService.d.ts +5 -0
  86. package/services/storage-service/DatabaseService.js +116 -1
  87. package/services/storage-service/db-stores/Balance.d.ts +2 -0
  88. package/services/storage-service/db-stores/Balance.js +6 -0
  89. package/services/storage-service/db-stores/Crowdloan.d.ts +2 -0
  90. package/services/storage-service/db-stores/Crowdloan.js +8 -0
  91. package/services/storage-service/db-stores/Nft.d.ts +2 -0
  92. package/services/storage-service/db-stores/Nft.js +12 -0
  93. package/services/storage-service/db-stores/NftCollection.d.ts +1 -0
  94. package/services/storage-service/db-stores/NftCollection.js +11 -0
  95. package/services/storage-service/db-stores/YieldPositionStore.d.ts +2 -0
  96. package/services/storage-service/db-stores/YieldPositionStore.js +6 -0
  97. package/types/balance/index.d.ts +2 -3
@@ -16,6 +16,7 @@ var _YieldPoolStore = _interopRequireDefault(require("@subwallet/extension-base/
16
16
  var _YieldPositionStore = _interopRequireDefault(require("@subwallet/extension-base/services/storage-service/db-stores/YieldPositionStore"));
17
17
  var _utils = require("@subwallet/extension-base/utils");
18
18
  var _uiKeyring = _interopRequireDefault(require("@subwallet/ui-keyring"));
19
+ var _bignumber = _interopRequireDefault(require("bignumber.js"));
19
20
  var _dexieExportImport = require("dexie-export-import");
20
21
  var _util = require("@polkadot/util");
21
22
  // Copyright 2019-2022 @subwallet/extension-base authors & contributors
@@ -81,6 +82,120 @@ class DatabaseService {
81
82
  // Filter not exist address
82
83
  return this.stores.balance.table.filter(obj => addresses.includes(obj.address)).toArray();
83
84
  }
85
+ async checkBalanceByTokens(tokens, comparison, addresses, amount) {
86
+ const filterFunc = item => {
87
+ const freeBalance = item === null || item === void 0 ? void 0 : item.free;
88
+ const lockedBalance = item === null || item === void 0 ? void 0 : item.locked;
89
+ const value = new _bignumber.default(freeBalance).plus(lockedBalance);
90
+ if (!addresses.includes(item.address)) {
91
+ return false;
92
+ }
93
+ switch (comparison) {
94
+ case 'eq':
95
+ return value.eq(amount || 0);
96
+ case 'gt':
97
+ return value.gt(amount || 0);
98
+ case 'gte':
99
+ return value.gte(amount || 0);
100
+ case 'lt':
101
+ return value.lt(amount || 0);
102
+ case 'lte':
103
+ return value.lte(amount || 0);
104
+ }
105
+ };
106
+ return this.stores.balance.checkBalanceByTokens(tokens, filterFunc);
107
+ }
108
+ async checkEarningByTokens(slug, comparison, addresses, amount) {
109
+ const filterFunc = item => {
110
+ if (!addresses.includes(item.address)) {
111
+ return false;
112
+ }
113
+ const value = new _bignumber.default(item.activeStake);
114
+ switch (comparison) {
115
+ case 'eq':
116
+ return value.eq(amount || 0);
117
+ case 'gt':
118
+ return value.gt(amount || 0);
119
+ case 'gte':
120
+ return value.gte(amount || 0);
121
+ case 'lt':
122
+ return value.lt(amount || 0);
123
+ case 'lte':
124
+ return value.lte(amount || 0);
125
+ }
126
+ };
127
+ return this.stores.yieldPosition.checkPositionByPoolSlug(slug, filterFunc);
128
+ }
129
+ async checkNftByTokens(chain, addresses, collectionId) {
130
+ const filterFunc = item => {
131
+ if (!addresses.includes(item.address)) {
132
+ return false;
133
+ } else {
134
+ return true;
135
+ }
136
+ };
137
+ return this.stores.nft.checkNftsByChainAndCollection(chain, filterFunc, collectionId);
138
+ }
139
+ async checkCrowdloanByChain(chain, addresses) {
140
+ const filterFunc = item => {
141
+ if (!addresses.includes(item.address)) {
142
+ return false;
143
+ } else {
144
+ return true;
145
+ }
146
+ };
147
+ return this.stores.crowdloan.checkCrowdloanExist(filterFunc);
148
+ }
149
+ async checkHasMoneyByTokens(types, addresses) {
150
+ const allHasMoneysConditionValid = [];
151
+ if (types.includes('balance')) {
152
+ const filterFunc = item => {
153
+ if (!addresses.includes(item.address)) {
154
+ return false;
155
+ }
156
+ const freeBalance = item === null || item === void 0 ? void 0 : item.free;
157
+ const lockedBalance = item === null || item === void 0 ? void 0 : item.locked;
158
+ const value = new _bignumber.default(freeBalance).plus(lockedBalance);
159
+ return value.gt(_utils.BN_ZERO);
160
+ };
161
+ const balanceResult = await this.stores.balance.checkBalanceExist(filterFunc);
162
+ balanceResult > 0 && allHasMoneysConditionValid.push('balance');
163
+ }
164
+ if (types.includes('earning')) {
165
+ const filterFunc = item => {
166
+ if (!addresses.includes(item.address)) {
167
+ return false;
168
+ }
169
+ const value = new _bignumber.default(item.activeStake);
170
+ return value.gt(_utils.BN_ZERO);
171
+ };
172
+ const earningResult = await this.stores.yieldPosition.checkPositionExist(filterFunc);
173
+ earningResult > 0 && allHasMoneysConditionValid.push('earning');
174
+ }
175
+ if (types.includes('nft')) {
176
+ const filterFunc = item => {
177
+ if (!addresses.includes(item.address)) {
178
+ return false;
179
+ } else {
180
+ return true;
181
+ }
182
+ };
183
+ const nftResult = await this.stores.nft.checkNftExist(filterFunc);
184
+ nftResult > 0 && allHasMoneysConditionValid.push('nft');
185
+ }
186
+ if (types.includes('crowdloan')) {
187
+ const filterFunc = item => {
188
+ if (!addresses.includes(item.address)) {
189
+ return false;
190
+ } else {
191
+ return true;
192
+ }
193
+ };
194
+ const crowdloanResult = await this.stores.crowdloan.checkCrowdloanExist(filterFunc);
195
+ crowdloanResult > 0 && allHasMoneysConditionValid.push('crowdloan');
196
+ }
197
+ return allHasMoneysConditionValid.length;
198
+ }
84
199
  async updateBalanceStore(item) {
85
200
  if (item.state === _KoniTypes.APIItemState.READY) {
86
201
  return this.stores.balance.upsert({
@@ -19,5 +19,11 @@ class BalanceStore extends _BaseStoreWithAddress.default {
19
19
  async removeByAddresses(addresses) {
20
20
  return this.table.where('address').anyOfIgnoreCase(addresses).delete();
21
21
  }
22
+ async checkBalanceByTokens(tokens, filterFunc) {
23
+ return this.table.where('tokenSlug').anyOfIgnoreCase(tokens).filter(filterFunc).count();
24
+ }
25
+ async checkBalanceExist(filterFunc) {
26
+ return this.table.filter(item => filterFunc(item)).count();
27
+ }
22
28
  }
23
29
  exports.default = BalanceStore;
@@ -33,5 +33,13 @@ class CrowdloanStore extends _BaseStoreWithAddressAndChain.default {
33
33
  address
34
34
  }).delete();
35
35
  }
36
+ checkCrowdloanByChain(chain, filterFunc) {
37
+ return this.table.where({
38
+ chain
39
+ }).filter(filterFunc).count();
40
+ }
41
+ checkCrowdloanExist(filterFunc) {
42
+ return this.table.filter(filterFunc).count();
43
+ }
36
44
  }
37
45
  exports.default = CrowdloanStore;
@@ -58,6 +58,18 @@ class NftStore extends _BaseStoreWithAddressAndChain.default {
58
58
  removeNftsByAddress(addresses) {
59
59
  return this.table.where('address').anyOfIgnoreCase(addresses).delete();
60
60
  }
61
+ checkNftsByChainAndCollection(chain, filterFunc, collectionId) {
62
+ const data = collectionId ? this.table.where({
63
+ chain,
64
+ collectionId
65
+ }) : this.table.where({
66
+ chain
67
+ });
68
+ return data.filter(item => filterFunc(item)).count();
69
+ }
70
+ checkNftExist(filterFunc) {
71
+ return this.table.filter(filterFunc).count();
72
+ }
61
73
 
62
74
  // reformatCollectionIds (items: INft[]) {
63
75
  // return items.map((item) => {
@@ -26,5 +26,16 @@ class NftCollectionStore extends _BaseStoreWithChain.default {
26
26
  collectionId
27
27
  }).delete();
28
28
  }
29
+ async checkNftByChainOrCollectionId(chain, collectionId) {
30
+ if (collectionId) {
31
+ return this.table.where({
32
+ chain,
33
+ collectionId
34
+ }).count();
35
+ }
36
+ return this.table.where({
37
+ chain
38
+ }).count();
39
+ }
29
40
  }
30
41
  exports.default = NftCollectionStore;
@@ -67,5 +67,11 @@ class YieldPositionStore extends _BaseStore.default {
67
67
  subscribeYieldPositions(addresses) {
68
68
  return (0, _dexie.liveQuery)(() => this.getByAddress(addresses));
69
69
  }
70
+ async checkPositionByPoolSlug(slug, filterFunc) {
71
+ return this.table.where('slug').anyOfIgnoreCase(slug).filter(filterFunc).limit(1).count();
72
+ }
73
+ async checkPositionExist(filterFunc) {
74
+ return this.table.filter(filterFunc).limit(1).count();
75
+ }
70
76
  }
71
77
  exports.default = YieldPositionStore;
@@ -7,6 +7,7 @@ export declare const ACALA_REFRESH_CROWDLOAN_INTERVAL = 300000;
7
7
  export declare const ASTAR_REFRESH_BALANCE_INTERVAL = 60000;
8
8
  export declare const SUB_TOKEN_REFRESH_BALANCE_INTERVAL = 60000;
9
9
  export declare const CRON_REFRESH_NFT_INTERVAL = 7200000;
10
+ export declare const CRON_REFRESH_MKT_CAMPAIGN_INTERVAL: number;
10
11
  export declare const CRON_REFRESH_STAKING_REWARD_INTERVAL = 900000;
11
12
  export declare const CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL = 90000;
12
13
  export declare const CRON_REFRESH_HISTORY_INTERVAL = 900000;
@@ -10,6 +10,7 @@ export const ACALA_REFRESH_CROWDLOAN_INTERVAL = 300000;
10
10
  export const ASTAR_REFRESH_BALANCE_INTERVAL = 60000;
11
11
  export const SUB_TOKEN_REFRESH_BALANCE_INTERVAL = 60000;
12
12
  export const CRON_REFRESH_NFT_INTERVAL = 7200000;
13
+ export const CRON_REFRESH_MKT_CAMPAIGN_INTERVAL = 15 * BASE_MINUTE_INTERVAL;
13
14
  export const CRON_REFRESH_STAKING_REWARD_INTERVAL = 900000;
14
15
  export const CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL = 90000;
15
16
  export const CRON_REFRESH_HISTORY_INTERVAL = 900000;
@@ -0,0 +1,4 @@
1
+ import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
2
+ import { PalletAssetsAssetAccount } from '@subwallet/extension-base/core/substrate/types';
3
+ export declare function _getAssetsPalletTransferable(accountInfo: PalletAssetsAssetAccount | undefined, existentialDeposit: string, extrinsicType?: ExtrinsicType): bigint;
4
+ export declare function _getAssetsPalletLockedBalance(accountInfo: PalletAssetsAssetAccount | undefined): bigint;
@@ -0,0 +1,28 @@
1
+ // Copyright 2019-2022 @subwallet/extension-base
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { BalanceAccountType } from '@subwallet/extension-base/core/substrate/types';
5
+ import { _getAppliedExistentialDeposit, getStrictMode } from '@subwallet/extension-base/core/utils';
6
+ export function _getAssetsPalletTransferable(accountInfo, existentialDeposit, extrinsicType) {
7
+ const strictMode = getStrictMode(BalanceAccountType.PalletAssetsAssetAccount, extrinsicType);
8
+ const bnAppliedExistentialDeposit = _getAppliedExistentialDeposit(existentialDeposit, strictMode);
9
+ let bnTransferable = BigInt(0);
10
+ if (!accountInfo) {
11
+ return BigInt(0);
12
+ }
13
+ if (['Liquid'].includes(accountInfo.status)) {
14
+ bnTransferable = BigInt(accountInfo.balance) - bnAppliedExistentialDeposit;
15
+ }
16
+ return bnTransferable;
17
+ }
18
+ export function _getAssetsPalletLockedBalance(accountInfo) {
19
+ let bnLocked = BigInt(0);
20
+ if (!accountInfo) {
21
+ return bnLocked;
22
+ }
23
+ if (!['Liquid'].includes(accountInfo.status)) {
24
+ // todo: check case accountInfo has isFrozen?
25
+ bnLocked = BigInt(accountInfo.balance);
26
+ }
27
+ return bnLocked;
28
+ }
@@ -1,8 +1,4 @@
1
- export declare type PalletAssetsAssetAccount = {
2
- balance: number | string;
3
- status: 'Frozen' | 'Liquid' | 'Blocked';
4
- reason: Record<string, unknown>;
5
- extra: unknown;
6
- };
7
- export declare function _getForeignAssetPalletTransferable(accountInfo: PalletAssetsAssetAccount): bigint;
8
- export declare function _getForeignAssetPalletLockedBalance(accountInfo: PalletAssetsAssetAccount): bigint;
1
+ import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
2
+ import { PalletAssetsAssetAccount } from '@subwallet/extension-base/core/substrate/types';
3
+ export declare function _getForeignAssetPalletTransferable(accountInfo: PalletAssetsAssetAccount | undefined, existentialDeposit: string, extrinsicType?: ExtrinsicType): bigint;
4
+ export declare function _getForeignAssetPalletLockedBalance(accountInfo: PalletAssetsAssetAccount | undefined): bigint;
@@ -1,9 +1,19 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- export function _getForeignAssetPalletTransferable(accountInfo) {
5
- return accountInfo.status !== 'Liquid' ? BigInt(0) : BigInt(accountInfo.balance);
4
+ import { BalanceAccountType } from '@subwallet/extension-base/core/substrate/types';
5
+ import { _getAppliedExistentialDeposit, getStrictMode } from '@subwallet/extension-base/core/utils';
6
+ export function _getForeignAssetPalletTransferable(accountInfo, existentialDeposit, extrinsicType) {
7
+ const strictMode = getStrictMode(BalanceAccountType.PalletAssetsAssetAccount, extrinsicType);
8
+ if (!accountInfo || accountInfo.status !== 'Liquid') {
9
+ return BigInt(0);
10
+ }
11
+ const bnAppliedExistentialDeposit = _getAppliedExistentialDeposit(existentialDeposit, strictMode);
12
+ return BigInt(accountInfo.balance) - bnAppliedExistentialDeposit;
6
13
  }
7
14
  export function _getForeignAssetPalletLockedBalance(accountInfo) {
8
- return accountInfo.status === 'Liquid' ? BigInt(0) : BigInt(accountInfo.balance);
15
+ if (!accountInfo || accountInfo.status === 'Liquid') {
16
+ return BigInt(0);
17
+ }
18
+ return BigInt(accountInfo.balance);
9
19
  }
@@ -1,10 +1,4 @@
1
- import BigN from 'bignumber.js';
2
- export declare type PalletNominationPoolsPoolMember = {
3
- poolId: number;
4
- points: number;
5
- lastRecordedRewardCounter: number;
6
- unbondingEras: Record<string, number>;
7
- };
8
- export declare function _getActiveStakeInNominationPool(memberInfo: PalletNominationPoolsPoolMember): BigN;
9
- export declare function _getUnbondingStakeInNominationPool(memberInfo: PalletNominationPoolsPoolMember): BigN;
10
- export declare function _getTotalStakeInNominationPool(memberInfo: PalletNominationPoolsPoolMember): BigN;
1
+ import { PalletNominationPoolsPoolMember } from '@subwallet/extension-base/core/substrate/types';
2
+ export declare function _getActiveStakeInNominationPool(memberInfo: PalletNominationPoolsPoolMember): bigint;
3
+ export declare function _getUnbondingStakeInNominationPool(memberInfo: PalletNominationPoolsPoolMember): bigint;
4
+ export declare function _getTotalStakeInNominationPool(memberInfo: PalletNominationPoolsPoolMember): bigint;
@@ -1,14 +1,13 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import BigN from 'bignumber.js';
5
4
  export function _getActiveStakeInNominationPool(memberInfo) {
6
- return new BigN(memberInfo.points.toString());
5
+ return BigInt(memberInfo.points);
7
6
  }
8
7
  export function _getUnbondingStakeInNominationPool(memberInfo) {
9
- const unbondingValues = Object.values(memberInfo.unbondingEras).map(unbonding => new BigN(unbonding));
10
- return new BigN(Object.values(unbondingValues).reduce((a, b) => a.plus(b), new BigN(0)));
8
+ const unbondingValues = Object.values(memberInfo.unbondingEras).map(unbonding => BigInt(unbonding));
9
+ return unbondingValues.reduce((a, b) => a + b, BigInt(0));
11
10
  }
12
11
  export function _getTotalStakeInNominationPool(memberInfo) {
13
- return _getActiveStakeInNominationPool(memberInfo).plus(_getUnbondingStakeInNominationPool(memberInfo));
12
+ return _getActiveStakeInNominationPool(memberInfo) + _getUnbondingStakeInNominationPool(memberInfo);
14
13
  }
@@ -0,0 +1,4 @@
1
+ import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
2
+ import { OrmlTokensAccountData } from '@subwallet/extension-base/core/substrate/types';
3
+ export declare function _getOrmlTokensPalletTransferable(accountInfo: OrmlTokensAccountData, existentialDeposit: string, extrinsicType?: ExtrinsicType): bigint;
4
+ export declare function _getOrmlTokensPalletLockedBalance(accountInfo: OrmlTokensAccountData): bigint;
@@ -0,0 +1,17 @@
1
+ // Copyright 2019-2022 @subwallet/extension-base
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { BalanceAccountType } from '@subwallet/extension-base/core/substrate/types';
5
+ import { _getAppliedExistentialDeposit, getMaxBigint, getStrictMode } from '@subwallet/extension-base/core/utils';
6
+ export function _getOrmlTokensPalletTransferable(accountInfo, existentialDeposit, extrinsicType) {
7
+ const strictMode = getStrictMode(BalanceAccountType.OrmlTokensAccountData, extrinsicType);
8
+ const bnAppliedExistentialDeposit = _getAppliedExistentialDeposit(existentialDeposit, strictMode);
9
+ const bnFrozen = BigInt(accountInfo.frozen);
10
+ const bnFree = BigInt(accountInfo.free);
11
+ return bnFree - getMaxBigint(bnFrozen, bnAppliedExistentialDeposit);
12
+ }
13
+ export function _getOrmlTokensPalletLockedBalance(accountInfo) {
14
+ const bnFrozen = BigInt(accountInfo.frozen);
15
+ const bnReserved = BigInt(accountInfo.reserved);
16
+ return bnReserved + bnFrozen;
17
+ }
@@ -1,27 +1,7 @@
1
1
  import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
2
- export declare type FrameSystemAccountInfoV2 = Omit<FrameSystemAccountInfoV1, 'data'> & {
3
- data: {
4
- free: number;
5
- reserved: number;
6
- frozen: number;
7
- flags: number;
8
- };
9
- };
10
- export declare type FrameSystemAccountInfoV1 = {
11
- nonce: number;
12
- consumers: number;
13
- providers: number;
14
- sufficients: number;
15
- data: {
16
- free: number | string;
17
- reserved: number;
18
- miscFrozen: number;
19
- feeFrozen: number;
20
- };
21
- };
22
- export declare type FrameSystemAccountInfo = FrameSystemAccountInfoV1 | FrameSystemAccountInfoV2;
23
- export declare function _getSystemPalletTransferable(accountInfo: FrameSystemAccountInfo, existentialDeposit: string, extrinsicType?: ExtrinsicType): string;
2
+ import { FrameSystemAccountInfo } from '@subwallet/extension-base/core/substrate/types';
3
+ export declare function _getSystemPalletTransferable(accountInfo: FrameSystemAccountInfo, existentialDeposit: string, extrinsicType?: ExtrinsicType): bigint;
24
4
  export declare function _canAccountBeReaped(accountInfo: FrameSystemAccountInfo): boolean;
25
5
  export declare function _isAccountActive(accountInfo: FrameSystemAccountInfo): boolean;
26
- export declare function _getSystemPalletTotalBalance(accountInfo: FrameSystemAccountInfo): string;
27
- export declare function _getAppliedExistentialDepositWithExtrinsicType(accountInfo: FrameSystemAccountInfo, existentialDeposit: string, extrinsicType?: ExtrinsicType): string;
6
+ export declare function _getSystemPalletTotalBalance(accountInfo: FrameSystemAccountInfo): bigint;
7
+ export declare function _getAppliedExistentialDepositWithExtrinsicType(accountInfo: FrameSystemAccountInfo, existentialDeposit: string, extrinsicType?: ExtrinsicType): bigint;
@@ -1,17 +1,13 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
5
- import BigN from 'bignumber.js';
6
-
7
- // https://crates.parity.io/frame_system/struct.AccountInfo.html
8
- // https://wiki.polkadot.network/docs/learn-account-balances
9
-
4
+ import { BalanceAccountType } from '@subwallet/extension-base/core/substrate/types';
5
+ import { getMaxBigint, getStrictMode } from '@subwallet/extension-base/core/utils';
10
6
  function isV1(accountInfo) {
11
7
  return accountInfo.data.miscFrozen !== undefined && accountInfo.data.feeFrozen !== undefined;
12
8
  }
13
9
  export function _getSystemPalletTransferable(accountInfo, existentialDeposit, extrinsicType) {
14
- const strictMode = !extrinsicType || ![ExtrinsicType.TRANSFER_BALANCE].includes(extrinsicType); // always apply strict mode to keep account alive unless explicitly specified otherwise
10
+ const strictMode = getStrictMode(BalanceAccountType.FrameSystemAccountInfo, extrinsicType); // always apply strict mode to keep account alive unless explicitly specified otherwise
15
11
 
16
12
  if (isV1(accountInfo)) {
17
13
  return _getSystemPalletTransferableV1(accountInfo, existentialDeposit, strictMode);
@@ -34,7 +30,7 @@ export function _getSystemPalletTotalBalance(accountInfo) {
34
30
  }
35
31
  }
36
32
  export function _getAppliedExistentialDepositWithExtrinsicType(accountInfo, existentialDeposit, extrinsicType) {
37
- const strictMode = !extrinsicType || ![ExtrinsicType.TRANSFER_BALANCE].includes(extrinsicType); // always apply strict mode to keep account alive unless explicitly specified otherwise
33
+ const strictMode = getStrictMode(BalanceAccountType.FrameSystemAccountInfo, extrinsicType); // always apply strict mode to keep account alive unless explicitly specified otherwise
38
34
 
39
35
  return _getAppliedExistentialDeposit(accountInfo, existentialDeposit, strictMode);
40
36
  }
@@ -42,29 +38,28 @@ export function _getAppliedExistentialDepositWithExtrinsicType(accountInfo, exis
42
38
  // ----------------------------------------------------------------------
43
39
 
44
40
  function _getAppliedExistentialDeposit(accountInfo, existentialDeposit, strictMode) {
41
+ const bnExistentialDeposit = BigInt(existentialDeposit);
42
+
45
43
  // strict mode will always apply existential deposit to keep account alive
46
44
  if (strictMode) {
47
- return existentialDeposit;
45
+ return bnExistentialDeposit;
48
46
  }
49
- return _canAccountBeReaped(accountInfo) ? '0' : existentialDeposit; // account for ED here will go better with max transfer logic
47
+ return _canAccountBeReaped(accountInfo) ? BigInt(0) : bnExistentialDeposit; // account for ED here will go better with max transfer logic
50
48
  }
51
49
 
52
50
  function _getSystemPalletTransferableV2(accountInfo, existentialDeposit, strictMode) {
53
- const bnFree = new BigN(accountInfo.data.free);
54
- const bnLocked = new BigN(accountInfo.data.frozen).minus(accountInfo.data.reserved); // locked can go below 0 but this shouldn't matter
55
- const bnAppliedExistentialDeposit = new BigN(_getAppliedExistentialDeposit(accountInfo, existentialDeposit, strictMode));
56
- const bnTransferableBalance = bnFree.minus(BigN.max(bnLocked, bnAppliedExistentialDeposit));
57
- return BigN.max(bnTransferableBalance, 0).toFixed();
51
+ const bnLocked = BigInt(accountInfo.data.frozen) - BigInt(accountInfo.data.reserved); // locked can go below 0 but this shouldn't matter
52
+ const bnAppliedExistentialDeposit = _getAppliedExistentialDeposit(accountInfo, existentialDeposit, strictMode);
53
+ return BigInt(accountInfo.data.free) - getMaxBigint(bnLocked, bnAppliedExistentialDeposit);
58
54
  }
59
55
  function _getSystemPalletTotalBalanceV2(accountInfo) {
60
- return new BigN(accountInfo.data.free).plus(accountInfo.data.reserved).toFixed();
56
+ return BigInt(accountInfo.data.free) + BigInt(accountInfo.data.reserved);
61
57
  }
62
58
  function _getSystemPalletTransferableV1(accountInfo, existentialDeposit, strictMode) {
63
- const bnAppliedExistentialDeposit = new BigN(_getAppliedExistentialDeposit(accountInfo, existentialDeposit, strictMode));
64
- const bnAppliedFrozen = BigN.max(accountInfo.data.feeFrozen, accountInfo.data.miscFrozen);
65
- const bnTransferableBalance = new BigN(accountInfo.data.free).minus(BigN.max(bnAppliedFrozen, bnAppliedExistentialDeposit));
66
- return BigN.max(bnTransferableBalance, 0).toFixed();
59
+ const bnAppliedExistentialDeposit = BigInt(_getAppliedExistentialDeposit(accountInfo, existentialDeposit, strictMode));
60
+ const bnAppliedFrozen = getMaxBigint(BigInt(accountInfo.data.feeFrozen), BigInt(accountInfo.data.miscFrozen));
61
+ return BigInt(accountInfo.data.free) - getMaxBigint(bnAppliedFrozen, bnAppliedExistentialDeposit);
67
62
  }
68
63
  function _getSystemPalletTotalBalanceV1(accountInfo) {
69
- return new BigN(accountInfo.data.free).plus(accountInfo.data.reserved).toFixed();
64
+ return BigInt(accountInfo.data.free) + BigInt(accountInfo.data.reserved);
70
65
  }
@@ -0,0 +1,5 @@
1
+ import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
2
+ import { OrmlTokensAccountData } from '@subwallet/extension-base/core/substrate/types';
3
+ export declare function _getTokensPalletTransferable(accountInfo: OrmlTokensAccountData, existentialDeposit: string, extrinsicType?: ExtrinsicType): bigint;
4
+ export declare function _getTokensPalletLocked(accountInfo: OrmlTokensAccountData): bigint;
5
+ export declare function _getTokensPalletTotalBalance(accountInfo: OrmlTokensAccountData): bigint;
@@ -0,0 +1,16 @@
1
+ // Copyright 2019-2022 @subwallet/extension-base
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { BalanceAccountType } from '@subwallet/extension-base/core/substrate/types';
5
+ import { _getAppliedExistentialDeposit, getMaxBigint, getStrictMode } from '@subwallet/extension-base/core/utils';
6
+ export function _getTokensPalletTransferable(accountInfo, existentialDeposit, extrinsicType) {
7
+ const strictMode = getStrictMode(BalanceAccountType.OrmlTokensAccountData, extrinsicType);
8
+ const bnAppliedExistentialDeposit = _getAppliedExistentialDeposit(existentialDeposit, strictMode);
9
+ return BigInt(accountInfo.free) - getMaxBigint(BigInt(accountInfo.frozen), bnAppliedExistentialDeposit);
10
+ }
11
+ export function _getTokensPalletLocked(accountInfo) {
12
+ return BigInt(accountInfo.reserved) + BigInt(accountInfo.frozen);
13
+ }
14
+ export function _getTokensPalletTotalBalance(accountInfo) {
15
+ return BigInt(accountInfo.free) + BigInt(accountInfo.reserved);
16
+ }
@@ -0,0 +1,43 @@
1
+ export declare type FrameSystemAccountInfoV2 = Omit<FrameSystemAccountInfoV1, 'data'> & {
2
+ data: {
3
+ free: number;
4
+ reserved: number;
5
+ frozen: number;
6
+ flags: number;
7
+ };
8
+ };
9
+ export declare type FrameSystemAccountInfoV1 = {
10
+ nonce: number;
11
+ consumers: number;
12
+ providers: number;
13
+ sufficients: number;
14
+ data: {
15
+ free: number | string;
16
+ reserved: number;
17
+ miscFrozen: number;
18
+ feeFrozen: number;
19
+ };
20
+ };
21
+ export declare type FrameSystemAccountInfo = FrameSystemAccountInfoV1 | FrameSystemAccountInfoV2;
22
+ export declare type OrmlTokensAccountData = {
23
+ free: number;
24
+ reserved: number;
25
+ frozen: number;
26
+ };
27
+ export declare type PalletAssetsAssetAccount = {
28
+ balance: number | string;
29
+ status: 'Frozen' | 'Liquid' | 'Blocked';
30
+ reason: Record<string, unknown>;
31
+ extra: unknown;
32
+ };
33
+ export declare type PalletNominationPoolsPoolMember = {
34
+ poolId: number;
35
+ points: number;
36
+ lastRecordedRewardCounter: number;
37
+ unbondingEras: Record<string, number>;
38
+ };
39
+ export declare const BalanceAccountType: {
40
+ FrameSystemAccountInfo: string;
41
+ OrmlTokensAccountData: string;
42
+ PalletAssetsAssetAccount: string;
43
+ };
@@ -0,0 +1,12 @@
1
+ // Copyright 2019-2022 @subwallet/extension-base
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ // https://crates.parity.io/frame_system/struct.AccountInfo.html
5
+ // https://wiki.polkadot.network/docs/learn-account-balances
6
+
7
+ // export type BalanceAccountType = 'FrameSystemAccountInfo' | 'OrmlTokensAccountData' | 'PalletAssetsAssetAccount' | 'PalletNominationPoolsPoolMember';
8
+ export const BalanceAccountType = {
9
+ FrameSystemAccountInfo: 'FrameSystemAccountInfo',
10
+ OrmlTokensAccountData: 'OrmlTokensAccountData',
11
+ PalletAssetsAssetAccount: 'PalletAssetsAssetAccount'
12
+ };
@@ -51,3 +51,4 @@ export declare function _isXcmTransferUnstable(originChainInfo: _ChainInfo, dest
51
51
  export declare function _getXcmUnstableWarning(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo): string;
52
52
  export declare function _isXcmWithinSameConsensus(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo): boolean;
53
53
  export declare function _isSnowBridgeXcm(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo): boolean;
54
+ export declare function _adaptX1Interior(assetIdentifier: Record<string, any>, version: number): Record<string, any>;
@@ -191,15 +191,28 @@ function _getRecipientLocation(destChainInfo, recipient, version) {
191
191
  };
192
192
  }
193
193
  function _getAssetIdentifier(tokenInfo, version) {
194
- const assetIdentifier = _getXcmAssetMultilocation(tokenInfo);
195
- if (!assetIdentifier) {
194
+ const _assetIdentifier = _getXcmAssetMultilocation(tokenInfo);
195
+ if (!_assetIdentifier) {
196
196
  throw new Error('Asset must have multilocation');
197
197
  }
198
+ const assetIdentifier = _adaptX1Interior(structuredClone(_assetIdentifier), version);
198
199
  return version >= 4 // from V4, Concrete is removed
199
200
  ? assetIdentifier : {
200
201
  Concrete: assetIdentifier
201
202
  };
202
203
  }
204
+ export function _adaptX1Interior(assetIdentifier, version) {
205
+ const interior = assetIdentifier.interior;
206
+ const isInteriorObj = typeof interior === 'object' && interior !== null;
207
+ const isX1 = isInteriorObj && 'X1' in interior;
208
+ const needModifyX1 = version <= 4 && Array.isArray(interior.X1);
209
+ if (isInteriorObj && isX1 && needModifyX1) {
210
+ // X1 is an object for version < 4. From V4, it's an array
211
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
212
+ interior.X1 = interior.X1[0];
213
+ }
214
+ return assetIdentifier;
215
+ }
203
216
  function _getNetworkByVersion(version) {
204
217
  switch (version) {
205
218
  case 1:
@@ -0,0 +1,4 @@
1
+ import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
2
+ export declare function getStrictMode(type: string, extrinsicType?: ExtrinsicType): boolean;
3
+ export declare function _getAppliedExistentialDeposit(existentialDeposit: string, strictMode?: boolean): bigint;
4
+ export declare function getMaxBigint(a: bigint, b: bigint): bigint;
package/core/utils.js ADDED
@@ -0,0 +1,23 @@
1
+ // Copyright 2019-2022 @subwallet/extension-base
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
5
+ import { BalanceAccountType } from '@subwallet/extension-base/core/substrate/types';
6
+ export function getStrictMode(type, extrinsicType) {
7
+ if (!extrinsicType) {
8
+ return true;
9
+ }
10
+ if (type === BalanceAccountType.FrameSystemAccountInfo) {
11
+ return ![ExtrinsicType.TRANSFER_BALANCE].includes(extrinsicType);
12
+ }
13
+ if (type === BalanceAccountType.OrmlTokensAccountData || type === BalanceAccountType.PalletAssetsAssetAccount) {
14
+ return ![ExtrinsicType.TRANSFER_TOKEN, ExtrinsicType.TRANSFER_BALANCE].includes(extrinsicType);
15
+ }
16
+ return true;
17
+ }
18
+ export function _getAppliedExistentialDeposit(existentialDeposit, strictMode) {
19
+ return strictMode ? BigInt(existentialDeposit) : BigInt(0);
20
+ }
21
+ export function getMaxBigint(a, b) {
22
+ return a > b ? a : b;
23
+ }
@@ -1,7 +1,7 @@
1
1
  import { _ChainInfo } from '@subwallet/chain-list/types';
2
2
  import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
3
3
  import { ChainStakingMetadata, NominatorMetadata, UnstakingInfo, ValidatorInfo } from '@subwallet/extension-base/background/KoniTypes';
4
- import { PalletNominationPoolsPoolMember } from '@subwallet/extension-base/core/substrate/nominationpools-pallet';
4
+ import { PalletNominationPoolsPoolMember } from '@subwallet/extension-base/core/substrate/types';
5
5
  import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
6
6
  import { NominationPoolInfo } from '@subwallet/extension-base/types';
7
7
  export interface PalletStakingNominations {
@@ -24,6 +24,7 @@ export declare class KoniCron {
24
24
  stop: () => Promise<void>;
25
25
  syncMantaPay: () => void;
26
26
  fetchPoolInfo: () => void;
27
+ fetchMktCampaignData: () => void;
27
28
  stopPoolInfo: () => void;
28
29
  refreshNft: (address: string, apiMap: ApiMap, smartContractNfts: _ChainAsset[], chainInfoMap: Record<string, _ChainInfo>) => () => void;
29
30
  resetNft: (newAddress: string) => void;