@subwallet/extension-base 1.2.24-0 → 1.2.24-2
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/cjs/core/substrate/assets-pallet.js +35 -0
- package/cjs/core/substrate/foreign-asset-pallet.js +13 -3
- package/cjs/core/substrate/nominationpools-pallet.js +4 -6
- package/cjs/core/substrate/ormlTokens-pallet.js +24 -0
- package/cjs/core/substrate/system-pallet.js +18 -18
- package/cjs/core/substrate/tokens-pallet.js +24 -0
- package/cjs/core/substrate/types.js +19 -0
- package/cjs/core/substrate/xcm-parser.js +16 -2
- package/cjs/core/utils.js +25 -0
- package/cjs/koni/background/handlers/Extension.js +1 -1
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/subscribe/substrate/equilibrium.js +2 -2
- package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +120 -133
- package/cjs/services/balance-service/transfer/xcm/index.js +2 -1
- package/cjs/services/balance-service/transfer/xcm/polkadotXcm.js +1 -1
- package/cjs/services/balance-service/transfer/xcm/utils.js +3 -2
- package/cjs/services/chain-service/constants.js +1 -1
- package/cjs/services/chain-service/handler/SubstrateApi.js +128 -34
- package/cjs/services/chain-service/handler/SubstrateChainHandler.js +26 -9
- package/cjs/services/chain-service/utils/index.js +5 -0
- package/core/substrate/assets-pallet.d.ts +4 -0
- package/core/substrate/assets-pallet.js +28 -0
- package/core/substrate/foreign-asset-pallet.d.ts +4 -8
- package/core/substrate/foreign-asset-pallet.js +13 -3
- package/core/substrate/nominationpools-pallet.d.ts +4 -10
- package/core/substrate/nominationpools-pallet.js +4 -5
- package/core/substrate/ormlTokens-pallet.d.ts +4 -0
- package/core/substrate/ormlTokens-pallet.js +17 -0
- package/core/substrate/system-pallet.d.ts +4 -24
- package/core/substrate/system-pallet.js +18 -21
- package/core/substrate/tokens-pallet.d.ts +5 -0
- package/core/substrate/tokens-pallet.js +16 -0
- package/core/substrate/types.d.ts +43 -0
- package/core/substrate/types.js +12 -0
- package/core/substrate/xcm-parser.d.ts +1 -0
- package/core/substrate/xcm-parser.js +15 -2
- package/core/utils.d.ts +4 -0
- package/core/utils.js +17 -0
- package/koni/api/staking/bonding/relayChain.d.ts +1 -1
- package/koni/background/handlers/Extension.js +1 -1
- package/koni/background/handlers/State.d.ts +2 -2
- package/package.json +31 -6
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/subscribe/substrate/equilibrium.js +2 -2
- package/services/balance-service/helpers/subscribe/substrate/index.js +109 -121
- package/services/balance-service/transfer/xcm/index.d.ts +1 -1
- package/services/balance-service/transfer/xcm/index.js +2 -1
- package/services/balance-service/transfer/xcm/polkadotXcm.js +1 -1
- package/services/balance-service/transfer/xcm/utils.d.ts +1 -1
- package/services/balance-service/transfer/xcm/utils.js +3 -2
- package/services/chain-service/constants.js +1 -1
- package/services/chain-service/handler/SubstrateApi.d.ts +5 -7
- package/services/chain-service/handler/SubstrateApi.js +128 -35
- package/services/chain-service/handler/SubstrateChainHandler.d.ts +5 -6
- package/services/chain-service/handler/SubstrateChainHandler.js +26 -9
- package/services/chain-service/index.d.ts +3 -3
- package/services/chain-service/types.d.ts +22 -5
- package/services/chain-service/utils/index.d.ts +1 -0
- package/services/chain-service/utils/index.js +3 -0
- package/services/earning-service/handlers/nomination-pool/index.d.ts +1 -1
- package/types/balance/index.d.ts +2 -3
package/core/utils.d.ts
ADDED
|
@@ -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,17 @@
|
|
|
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 (type === BalanceAccountType.FrameSystemAccountInfo) {
|
|
8
|
+
return !extrinsicType || ![ExtrinsicType.TRANSFER_BALANCE].includes(extrinsicType);
|
|
9
|
+
}
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
export function _getAppliedExistentialDeposit(existentialDeposit, strictMode) {
|
|
13
|
+
return strictMode ? BigInt(existentialDeposit) : BigInt(0);
|
|
14
|
+
}
|
|
15
|
+
export function getMaxBigInt(a, b) {
|
|
16
|
+
return a > b ? a : b;
|
|
17
|
+
}
|
|
@@ -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/
|
|
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 {
|
|
@@ -1938,7 +1938,7 @@ export default class KoniExtension {
|
|
|
1938
1938
|
if (destinationTokenInfo) {
|
|
1939
1939
|
const [bnMockFee, {
|
|
1940
1940
|
value
|
|
1941
|
-
}] = await Promise.all([getXcmMockTxFee(substrateApi, chainInfoMap,
|
|
1941
|
+
}] = await Promise.all([getXcmMockTxFee(substrateApi, chainInfoMap, originTokenInfo, destinationTokenInfo), this.getAddressTransferableBalance({
|
|
1942
1942
|
extrinsicType: ExtrinsicType.TRANSFER_XCM,
|
|
1943
1943
|
address,
|
|
1944
1944
|
networkKey: originTokenInfo.originChain,
|
|
@@ -194,8 +194,8 @@ export default class KoniState {
|
|
|
194
194
|
disableChain(chainSlug: string): Promise<boolean>;
|
|
195
195
|
enableChain(chainSlug: string, enableTokens?: boolean): Promise<boolean>;
|
|
196
196
|
resetDefaultChains(): boolean;
|
|
197
|
-
getSubstrateApiMap(): Record<string, import("
|
|
198
|
-
getSubstrateApi(networkKey: string): import("
|
|
197
|
+
getSubstrateApiMap(): Record<string, import("@subwallet/extension-base/services/chain-service/types")._SubstrateApi>;
|
|
198
|
+
getSubstrateApi(networkKey: string): import("@subwallet/extension-base/services/chain-service/types")._SubstrateApi;
|
|
199
199
|
getEvmApiMap(): Record<string, import("../../../services/chain-service/handler/EvmApi").EvmApi>;
|
|
200
200
|
getEvmApi(networkKey: string): import("../../../services/chain-service/handler/EvmApi").EvmApi;
|
|
201
201
|
getApiMap(): ApiMap;
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"./cjs/detectPackage.js"
|
|
18
18
|
],
|
|
19
19
|
"type": "module",
|
|
20
|
-
"version": "1.2.24-
|
|
20
|
+
"version": "1.2.24-2",
|
|
21
21
|
"main": "./cjs/index.js",
|
|
22
22
|
"module": "./index.js",
|
|
23
23
|
"types": "./index.d.ts",
|
|
@@ -144,6 +144,11 @@
|
|
|
144
144
|
"require": "./cjs/core/logic-validation/transfer.js",
|
|
145
145
|
"default": "./core/logic-validation/transfer.js"
|
|
146
146
|
},
|
|
147
|
+
"./core/substrate/assets-pallet": {
|
|
148
|
+
"types": "./core/substrate/assets-pallet.d.ts",
|
|
149
|
+
"require": "./cjs/core/substrate/assets-pallet.js",
|
|
150
|
+
"default": "./core/substrate/assets-pallet.js"
|
|
151
|
+
},
|
|
147
152
|
"./core/substrate/foreign-asset-pallet": {
|
|
148
153
|
"types": "./core/substrate/foreign-asset-pallet.d.ts",
|
|
149
154
|
"require": "./cjs/core/substrate/foreign-asset-pallet.js",
|
|
@@ -154,16 +159,36 @@
|
|
|
154
159
|
"require": "./cjs/core/substrate/nominationpools-pallet.js",
|
|
155
160
|
"default": "./core/substrate/nominationpools-pallet.js"
|
|
156
161
|
},
|
|
162
|
+
"./core/substrate/ormlTokens-pallet": {
|
|
163
|
+
"types": "./core/substrate/ormlTokens-pallet.d.ts",
|
|
164
|
+
"require": "./cjs/core/substrate/ormlTokens-pallet.js",
|
|
165
|
+
"default": "./core/substrate/ormlTokens-pallet.js"
|
|
166
|
+
},
|
|
157
167
|
"./core/substrate/system-pallet": {
|
|
158
168
|
"types": "./core/substrate/system-pallet.d.ts",
|
|
159
169
|
"require": "./cjs/core/substrate/system-pallet.js",
|
|
160
170
|
"default": "./core/substrate/system-pallet.js"
|
|
161
171
|
},
|
|
172
|
+
"./core/substrate/tokens-pallet": {
|
|
173
|
+
"types": "./core/substrate/tokens-pallet.d.ts",
|
|
174
|
+
"require": "./cjs/core/substrate/tokens-pallet.js",
|
|
175
|
+
"default": "./core/substrate/tokens-pallet.js"
|
|
176
|
+
},
|
|
177
|
+
"./core/substrate/types": {
|
|
178
|
+
"types": "./core/substrate/types.d.ts",
|
|
179
|
+
"require": "./cjs/core/substrate/types.js",
|
|
180
|
+
"default": "./core/substrate/types.js"
|
|
181
|
+
},
|
|
162
182
|
"./core/substrate/xcm-parser": {
|
|
163
183
|
"types": "./core/substrate/xcm-parser.d.ts",
|
|
164
184
|
"require": "./cjs/core/substrate/xcm-parser.js",
|
|
165
185
|
"default": "./core/substrate/xcm-parser.js"
|
|
166
186
|
},
|
|
187
|
+
"./core/utils": {
|
|
188
|
+
"types": "./core/utils.d.ts",
|
|
189
|
+
"require": "./cjs/core/utils.js",
|
|
190
|
+
"default": "./core/utils.js"
|
|
191
|
+
},
|
|
167
192
|
"./defaults": {
|
|
168
193
|
"types": "./defaults.d.ts",
|
|
169
194
|
"require": "./cjs/defaults.js",
|
|
@@ -2034,11 +2059,11 @@
|
|
|
2034
2059
|
"@reduxjs/toolkit": "^1.9.1",
|
|
2035
2060
|
"@sora-substrate/type-definitions": "^1.17.7",
|
|
2036
2061
|
"@substrate/connect": "^0.8.9",
|
|
2037
|
-
"@subwallet/chain-list": "0.2.
|
|
2038
|
-
"@subwallet/extension-base": "^1.2.24-
|
|
2039
|
-
"@subwallet/extension-chains": "^1.2.24-
|
|
2040
|
-
"@subwallet/extension-dapp": "^1.2.24-
|
|
2041
|
-
"@subwallet/extension-inject": "^1.2.24-
|
|
2062
|
+
"@subwallet/chain-list": "0.2.81",
|
|
2063
|
+
"@subwallet/extension-base": "^1.2.24-2",
|
|
2064
|
+
"@subwallet/extension-chains": "^1.2.24-2",
|
|
2065
|
+
"@subwallet/extension-dapp": "^1.2.24-2",
|
|
2066
|
+
"@subwallet/extension-inject": "^1.2.24-2",
|
|
2042
2067
|
"@subwallet/keyring": "^0.1.5",
|
|
2043
2068
|
"@subwallet/ui-keyring": "^0.1.5",
|
|
2044
2069
|
"@walletconnect/keyvaluestorage": "^1.1.1",
|
package/packageInfo.js
CHANGED
|
@@ -7,5 +7,5 @@ export const packageInfo = {
|
|
|
7
7
|
name: '@subwallet/extension-base',
|
|
8
8
|
path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
|
|
9
9
|
type: 'esm',
|
|
10
|
-
version: '1.2.24-
|
|
10
|
+
version: '1.2.24-2'
|
|
11
11
|
};
|
|
@@ -19,7 +19,7 @@ export const subscribeEquilibriumTokenBalance = async ({
|
|
|
19
19
|
const tokenTypes = includeNativeToken ? [_AssetType.NATIVE, _AssetType.LOCAL] : [_AssetType.LOCAL];
|
|
20
20
|
const tokenMap = filterAssetsByChainAndType(assetMap, chain, tokenTypes);
|
|
21
21
|
try {
|
|
22
|
-
const unsub = await substrateApi.query.system.account.multi(addresses, balances => {
|
|
22
|
+
const unsub = await substrateApi.api.query.system.account.multi(addresses, balances => {
|
|
23
23
|
// Equilibrium customizes the SystemAccount pallet
|
|
24
24
|
Object.values(tokenMap).forEach(tokenInfo => {
|
|
25
25
|
const assetId = _getTokenOnChainAssetId(tokenInfo);
|
|
@@ -81,7 +81,7 @@ export const subscribeEqBalanceAccountPallet = async ({
|
|
|
81
81
|
const unsubList = Object.values(tokenMap).map(async tokenInfo => {
|
|
82
82
|
try {
|
|
83
83
|
const assetId = _getTokenOnChainAssetId(tokenInfo);
|
|
84
|
-
const unsub = await substrateApi.query.eqBalances.account.multi(addresses.map(address => [address, [assetId]]), balances => {
|
|
84
|
+
const unsub = await substrateApi.api.query.eqBalances.account.multi(addresses.map(address => [address, [assetId]]), balances => {
|
|
85
85
|
const items = balances.map((balance, index) => {
|
|
86
86
|
return {
|
|
87
87
|
address: addresses[index],
|
|
@@ -4,17 +4,19 @@
|
|
|
4
4
|
import { _AssetType } from '@subwallet/chain-list/types';
|
|
5
5
|
import { APIItemState } from '@subwallet/extension-base/background/KoniTypes';
|
|
6
6
|
import { SUB_TOKEN_REFRESH_BALANCE_INTERVAL } from '@subwallet/extension-base/constants';
|
|
7
|
+
import { _getAssetsPalletLockedBalance, _getAssetsPalletTransferable } from '@subwallet/extension-base/core/substrate/assets-pallet';
|
|
7
8
|
import { _getForeignAssetPalletLockedBalance, _getForeignAssetPalletTransferable } from '@subwallet/extension-base/core/substrate/foreign-asset-pallet';
|
|
8
9
|
import { _getTotalStakeInNominationPool } from '@subwallet/extension-base/core/substrate/nominationpools-pallet';
|
|
10
|
+
import { _getOrmlTokensPalletLockedBalance, _getOrmlTokensPalletTransferable } from '@subwallet/extension-base/core/substrate/ormlTokens-pallet';
|
|
9
11
|
import { _getSystemPalletTotalBalance, _getSystemPalletTransferable } from '@subwallet/extension-base/core/substrate/system-pallet';
|
|
12
|
+
import { _getTokensPalletLocked, _getTokensPalletTransferable } from '@subwallet/extension-base/core/substrate/tokens-pallet';
|
|
13
|
+
import { _adaptX1Interior } from '@subwallet/extension-base/core/substrate/xcm-parser';
|
|
10
14
|
import { getPSP22ContractPromise } from '@subwallet/extension-base/koni/api/contract-handler/wasm';
|
|
11
15
|
import { getDefaultWeightV2 } from '@subwallet/extension-base/koni/api/contract-handler/wasm/utils';
|
|
12
16
|
import { _BALANCE_CHAIN_GROUP, _MANTA_ZK_CHAIN_GROUP, _ZK_ASSET_PREFIX } from '@subwallet/extension-base/services/chain-service/constants';
|
|
13
|
-
import { _checkSmartContractSupportByChain, _getChainExistentialDeposit, _getChainNativeTokenSlug, _getContractAddressOfToken, _getTokenOnChainAssetId, _getTokenOnChainInfo, _getTokenTypesSupportedByChain, _getXcmAssetMultilocation, _isBridgedToken, _isChainEvmCompatible
|
|
17
|
+
import { _checkSmartContractSupportByChain, _getAssetExistentialDeposit, _getChainExistentialDeposit, _getChainNativeTokenSlug, _getContractAddressOfToken, _getTokenOnChainAssetId, _getTokenOnChainInfo, _getTokenTypesSupportedByChain, _getXcmAssetMultilocation, _isBridgedToken, _isChainEvmCompatible } from '@subwallet/extension-base/services/chain-service/utils';
|
|
14
18
|
import { filterAssetsByChainAndType } from '@subwallet/extension-base/utils';
|
|
15
19
|
import BigN from 'bignumber.js';
|
|
16
|
-
import { combineLatest, Observable } from 'rxjs';
|
|
17
|
-
import { BN, BN_ZERO } from '@polkadot/util';
|
|
18
20
|
import { subscribeERC20Interval } from "../evm.js";
|
|
19
21
|
import { subscribeEquilibriumTokenBalance } from "./equilibrium.js";
|
|
20
22
|
import { subscribeGRC20Balance, subscribeVftBalance } from "./gear.js";
|
|
@@ -36,7 +38,7 @@ export const subscribeSubstrateBalance = async (addresses, chainInfo, assetMap,
|
|
|
36
38
|
};
|
|
37
39
|
const substrateParams = {
|
|
38
40
|
...baseParams,
|
|
39
|
-
substrateApi
|
|
41
|
+
substrateApi
|
|
40
42
|
};
|
|
41
43
|
if (!_BALANCE_CHAIN_GROUP.kintsugi.includes(chain) && !_BALANCE_CHAIN_GROUP.genshiro.includes(chain) && !_BALANCE_CHAIN_GROUP.equilibrium_parachain.includes(chain)) {
|
|
42
44
|
unsubNativeToken = await subscribeWithSystemAccountPallet(substrateParams);
|
|
@@ -110,42 +112,34 @@ const subscribeWithSystemAccountPallet = async ({
|
|
|
110
112
|
extrinsicType,
|
|
111
113
|
substrateApi
|
|
112
114
|
}) => {
|
|
113
|
-
const
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
const subscription = combineLatest({
|
|
131
|
-
balances: balanceSubscribe,
|
|
132
|
-
poolMemberInfos: poolSubscribe
|
|
133
|
-
}).subscribe(({
|
|
134
|
-
balances,
|
|
135
|
-
poolMemberInfos
|
|
136
|
-
}) => {
|
|
115
|
+
const systemAccountKey = 'query_system_account';
|
|
116
|
+
const poolMembersKey = 'query_nominationPools_poolMembers';
|
|
117
|
+
const params = [{
|
|
118
|
+
section: 'query',
|
|
119
|
+
module: systemAccountKey.split('_')[1],
|
|
120
|
+
method: systemAccountKey.split('_')[2],
|
|
121
|
+
args: addresses
|
|
122
|
+
}, {
|
|
123
|
+
section: 'query',
|
|
124
|
+
module: poolMembersKey.split('_')[1],
|
|
125
|
+
method: poolMembersKey.split('_')[2],
|
|
126
|
+
args: addresses
|
|
127
|
+
}];
|
|
128
|
+
const subscription = substrateApi.subscribeDataWithMulti(params, rs => {
|
|
129
|
+
const balances = rs[systemAccountKey];
|
|
130
|
+
const poolMemberInfos = rs[poolMembersKey];
|
|
137
131
|
const items = balances.map((_balance, index) => {
|
|
138
|
-
const balanceInfo = _balance
|
|
139
|
-
const poolMemberInfo = poolMemberInfos[index]
|
|
140
|
-
const nominationPoolBalance = poolMemberInfo ? _getTotalStakeInNominationPool(poolMemberInfo) :
|
|
132
|
+
const balanceInfo = _balance;
|
|
133
|
+
const poolMemberInfo = poolMemberInfos[index];
|
|
134
|
+
const nominationPoolBalance = poolMemberInfo ? _getTotalStakeInNominationPool(poolMemberInfo) : BigInt(0);
|
|
141
135
|
const transferableBalance = _getSystemPalletTransferable(balanceInfo, _getChainExistentialDeposit(chainInfo), extrinsicType);
|
|
142
136
|
const totalBalance = _getSystemPalletTotalBalance(balanceInfo);
|
|
143
|
-
const totalLockedFromTransfer =
|
|
137
|
+
const totalLockedFromTransfer = totalBalance - transferableBalance + nominationPoolBalance;
|
|
144
138
|
return {
|
|
145
139
|
address: addresses[index],
|
|
146
|
-
tokenSlug:
|
|
147
|
-
free: transferableBalance,
|
|
148
|
-
locked: totalLockedFromTransfer.
|
|
140
|
+
tokenSlug: _getChainNativeTokenSlug(chainInfo),
|
|
141
|
+
free: transferableBalance.toString(),
|
|
142
|
+
locked: totalLockedFromTransfer.toString(),
|
|
149
143
|
state: APIItemState.READY,
|
|
150
144
|
metadata: balanceInfo
|
|
151
145
|
};
|
|
@@ -161,25 +155,31 @@ const subscribeForeignAssetBalance = async ({
|
|
|
161
155
|
assetMap,
|
|
162
156
|
callback,
|
|
163
157
|
chainInfo,
|
|
158
|
+
extrinsicType,
|
|
164
159
|
substrateApi
|
|
165
160
|
}) => {
|
|
166
|
-
const
|
|
167
|
-
const tokenMap = filterAssetsByChainAndType(assetMap,
|
|
168
|
-
|
|
169
|
-
// @ts-ignore
|
|
170
|
-
const unsubList = await Promise.all(Object.values(tokenMap).map(async tokenInfo => {
|
|
161
|
+
const foreignAssetsAccountKey = 'query_foreignAssets_account';
|
|
162
|
+
const tokenMap = filterAssetsByChainAndType(assetMap, chainInfo.slug, [_AssetType.LOCAL]);
|
|
163
|
+
const unsubList = await Promise.all(Object.values(tokenMap).map(tokenInfo => {
|
|
171
164
|
try {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
165
|
+
if (_isBridgedToken(tokenInfo)) {
|
|
166
|
+
const params = [{
|
|
167
|
+
section: 'query',
|
|
168
|
+
module: foreignAssetsAccountKey.split('_')[1],
|
|
169
|
+
method: foreignAssetsAccountKey.split('_')[2],
|
|
170
|
+
args: addresses.map(address => [_getTokenOnChainInfo(tokenInfo) || _adaptX1Interior(_getXcmAssetMultilocation(tokenInfo), 3), address])
|
|
171
|
+
}];
|
|
172
|
+
return substrateApi.subscribeDataWithMulti(params, rs => {
|
|
173
|
+
const balances = rs[foreignAssetsAccountKey];
|
|
174
|
+
const items = balances.map((_balance, index) => {
|
|
175
|
+
const balanceInfo = _balance;
|
|
176
|
+
const transferableBalance = _getForeignAssetPalletTransferable(balanceInfo, _getAssetExistentialDeposit(tokenInfo), extrinsicType);
|
|
177
|
+
const totalLockedFromTransfer = _getForeignAssetPalletLockedBalance(balanceInfo);
|
|
178
178
|
return {
|
|
179
179
|
address: addresses[index],
|
|
180
180
|
tokenSlug: tokenInfo.slug,
|
|
181
|
-
free:
|
|
182
|
-
locked:
|
|
181
|
+
free: transferableBalance.toString(),
|
|
182
|
+
locked: totalLockedFromTransfer.toString(),
|
|
183
183
|
state: APIItemState.READY
|
|
184
184
|
};
|
|
185
185
|
});
|
|
@@ -193,7 +193,7 @@ const subscribeForeignAssetBalance = async ({
|
|
|
193
193
|
}));
|
|
194
194
|
return () => {
|
|
195
195
|
unsubList.forEach(unsub => {
|
|
196
|
-
unsub && unsub();
|
|
196
|
+
unsub && unsub.unsubscribe();
|
|
197
197
|
});
|
|
198
198
|
};
|
|
199
199
|
};
|
|
@@ -217,7 +217,7 @@ const subscribePSP22Balance = ({
|
|
|
217
217
|
const psp22ContractMap = {};
|
|
218
218
|
const tokenList = filterAssetsByChainAndType(assetMap, chain, [_AssetType.PSP22]);
|
|
219
219
|
Object.entries(tokenList).forEach(([slug, tokenInfo]) => {
|
|
220
|
-
psp22ContractMap[slug] = getPSP22ContractPromise(substrateApi, _getContractAddressOfToken(tokenInfo));
|
|
220
|
+
psp22ContractMap[slug] = getPSP22ContractPromise(substrateApi.api, _getContractAddressOfToken(tokenInfo));
|
|
221
221
|
});
|
|
222
222
|
const getTokenBalances = () => {
|
|
223
223
|
Object.values(tokenList).map(async tokenInfo => {
|
|
@@ -227,7 +227,7 @@ const subscribePSP22Balance = ({
|
|
|
227
227
|
try {
|
|
228
228
|
var _balanceOf$output;
|
|
229
229
|
const _balanceOf = await contract.query['psp22::balanceOf'](address, {
|
|
230
|
-
gasLimit: getDefaultWeightV2(substrateApi)
|
|
230
|
+
gasLimit: getDefaultWeightV2(substrateApi.api)
|
|
231
231
|
}, address);
|
|
232
232
|
const balanceObj = _balanceOf === null || _balanceOf === void 0 ? void 0 : (_balanceOf$output = _balanceOf.output) === null || _balanceOf$output === void 0 ? void 0 : _balanceOf$output.toPrimitive();
|
|
233
233
|
const freeResponse = extractOkResponse(balanceObj);
|
|
@@ -268,35 +268,33 @@ const subscribeTokensAccountsPallet = async ({
|
|
|
268
268
|
assetMap,
|
|
269
269
|
callback,
|
|
270
270
|
chainInfo,
|
|
271
|
+
extrinsicType,
|
|
271
272
|
includeNativeToken,
|
|
272
273
|
substrateApi
|
|
273
274
|
}) => {
|
|
274
|
-
const
|
|
275
|
+
const tokensAccountsKey = 'query_tokens_accounts';
|
|
275
276
|
const tokenTypes = includeNativeToken ? [_AssetType.NATIVE, _AssetType.LOCAL] : [_AssetType.LOCAL];
|
|
276
|
-
const tokenMap = filterAssetsByChainAndType(assetMap,
|
|
277
|
-
const unsubList = await Promise.all(Object.values(tokenMap).map(
|
|
277
|
+
const tokenMap = filterAssetsByChainAndType(assetMap, chainInfo.slug, tokenTypes);
|
|
278
|
+
const unsubList = await Promise.all(Object.values(tokenMap).map(tokenInfo => {
|
|
278
279
|
try {
|
|
279
|
-
const
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
const freeBalance = tokenBalance.free.sub(tokenBalance.frozen);
|
|
293
|
-
const lockedBalance = tokenBalance.frozen.add(tokenBalance.reserved);
|
|
280
|
+
const params = [{
|
|
281
|
+
section: 'query',
|
|
282
|
+
module: tokensAccountsKey.split('_')[1],
|
|
283
|
+
method: tokensAccountsKey.split('_')[2],
|
|
284
|
+
args: addresses.map(address => [address, _getTokenOnChainInfo(tokenInfo) || _getTokenOnChainAssetId(tokenInfo)])
|
|
285
|
+
}];
|
|
286
|
+
return substrateApi.subscribeDataWithMulti(params, rs => {
|
|
287
|
+
const balances = rs[tokensAccountsKey];
|
|
288
|
+
const items = balances.map((_balance, index) => {
|
|
289
|
+
const balanceInfo = _balance;
|
|
290
|
+
const transferableBalance = _getTokensPalletTransferable(balanceInfo, _getAssetExistentialDeposit(tokenInfo), extrinsicType);
|
|
291
|
+
const totalLockedFromTransfer = _getTokensPalletLocked(balanceInfo);
|
|
294
292
|
return {
|
|
295
293
|
address: addresses[index],
|
|
296
294
|
tokenSlug: tokenInfo.slug,
|
|
297
295
|
state: APIItemState.READY,
|
|
298
|
-
free:
|
|
299
|
-
locked:
|
|
296
|
+
free: transferableBalance.toString(),
|
|
297
|
+
locked: totalLockedFromTransfer.toString()
|
|
300
298
|
};
|
|
301
299
|
});
|
|
302
300
|
callback(items);
|
|
@@ -308,7 +306,7 @@ const subscribeTokensAccountsPallet = async ({
|
|
|
308
306
|
}));
|
|
309
307
|
return () => {
|
|
310
308
|
unsubList.forEach(unsub => {
|
|
311
|
-
unsub && unsub();
|
|
309
|
+
unsub && unsub.unsubscribe();
|
|
312
310
|
});
|
|
313
311
|
};
|
|
314
312
|
};
|
|
@@ -317,46 +315,41 @@ const subscribeAssetsAccountPallet = async ({
|
|
|
317
315
|
assetMap,
|
|
318
316
|
callback,
|
|
319
317
|
chainInfo,
|
|
320
|
-
|
|
318
|
+
extrinsicType,
|
|
321
319
|
substrateApi
|
|
322
320
|
}) => {
|
|
323
|
-
const
|
|
324
|
-
const tokenMap = filterAssetsByChainAndType(assetMap,
|
|
321
|
+
const assetsAccountKey = 'query_assets_account';
|
|
322
|
+
const tokenMap = filterAssetsByChainAndType(assetMap, chainInfo.slug, [_AssetType.LOCAL]);
|
|
325
323
|
Object.values(tokenMap).forEach(token => {
|
|
326
324
|
if (_MANTA_ZK_CHAIN_GROUP.includes(token.originChain) && token.symbol.startsWith(_ZK_ASSET_PREFIX)) {
|
|
327
325
|
delete tokenMap[token.slug];
|
|
328
326
|
}
|
|
329
327
|
});
|
|
330
|
-
const unsubList = await Promise.all(Object.values(tokenMap).map(
|
|
328
|
+
const unsubList = await Promise.all(Object.values(tokenMap).map(tokenInfo => {
|
|
331
329
|
try {
|
|
332
330
|
const assetIndex = _getTokenOnChainAssetId(tokenInfo);
|
|
333
331
|
if (assetIndex === '-1') {
|
|
334
332
|
return undefined;
|
|
335
333
|
}
|
|
334
|
+
const params = [{
|
|
335
|
+
section: 'query',
|
|
336
|
+
module: assetsAccountKey.split('_')[1],
|
|
337
|
+
method: assetsAccountKey.split('_')[2],
|
|
338
|
+
args: addresses.map(address => [assetIndex, address])
|
|
339
|
+
}];
|
|
336
340
|
|
|
337
341
|
// Get Token Balance
|
|
338
|
-
return
|
|
339
|
-
const
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
// @ts-ignore
|
|
345
|
-
const addressBalance = new BN(String(bdata === null || bdata === void 0 ? void 0 : bdata.balance).replaceAll(',', '') || '0');
|
|
346
|
-
|
|
347
|
-
// @ts-ignore
|
|
348
|
-
if (bdata !== null && bdata !== void 0 && bdata.isFrozen || ['Blocked', 'Frozen'].includes(bdata === null || bdata === void 0 ? void 0 : bdata.status)) {
|
|
349
|
-
// Status 'Frozen' and 'Blocked' are for frozen balance
|
|
350
|
-
frozen = addressBalance;
|
|
351
|
-
}
|
|
352
|
-
total = addressBalance;
|
|
353
|
-
}
|
|
354
|
-
const free = total.sub(frozen);
|
|
342
|
+
return substrateApi.subscribeDataWithMulti(params, rs => {
|
|
343
|
+
const balances = rs[assetsAccountKey];
|
|
344
|
+
const items = balances.map((_balance, index) => {
|
|
345
|
+
const balanceInfo = _balance;
|
|
346
|
+
const transferableBalance = _getAssetsPalletTransferable(balanceInfo, _getAssetExistentialDeposit(tokenInfo), extrinsicType);
|
|
347
|
+
const totalLockedFromTransfer = _getAssetsPalletLockedBalance(balanceInfo);
|
|
355
348
|
return {
|
|
356
349
|
address: addresses[index],
|
|
357
350
|
tokenSlug: tokenInfo.slug,
|
|
358
|
-
free:
|
|
359
|
-
locked:
|
|
351
|
+
free: transferableBalance.toString(),
|
|
352
|
+
locked: totalLockedFromTransfer.toString(),
|
|
360
353
|
state: APIItemState.READY
|
|
361
354
|
};
|
|
362
355
|
});
|
|
@@ -369,7 +362,7 @@ const subscribeAssetsAccountPallet = async ({
|
|
|
369
362
|
}));
|
|
370
363
|
return () => {
|
|
371
364
|
unsubList.forEach(unsub => {
|
|
372
|
-
unsub && unsub();
|
|
365
|
+
unsub && unsub.unsubscribe();
|
|
373
366
|
});
|
|
374
367
|
};
|
|
375
368
|
};
|
|
@@ -380,50 +373,45 @@ const subscribeOrmlTokensPallet = async ({
|
|
|
380
373
|
assetMap,
|
|
381
374
|
callback,
|
|
382
375
|
chainInfo,
|
|
376
|
+
extrinsicType,
|
|
383
377
|
substrateApi
|
|
384
378
|
}) => {
|
|
385
|
-
const
|
|
386
|
-
const
|
|
387
|
-
const
|
|
388
|
-
const unsubList = Object.values(tokenMap).map(async tokenInfo => {
|
|
379
|
+
const ormlTokensAccountsKey = 'query_ormlTokens_accounts';
|
|
380
|
+
const tokenMap = filterAssetsByChainAndType(assetMap, chainInfo.slug, [_AssetType.LOCAL]);
|
|
381
|
+
const unsubList = Object.values(tokenMap).map(tokenInfo => {
|
|
389
382
|
try {
|
|
390
|
-
const
|
|
383
|
+
const params = [{
|
|
384
|
+
section: 'query',
|
|
385
|
+
module: ormlTokensAccountsKey.split('_')[1],
|
|
386
|
+
method: ormlTokensAccountsKey.split('_')[2],
|
|
387
|
+
args: addresses.map(address => [address, _getTokenOnChainInfo(tokenInfo)])
|
|
388
|
+
}];
|
|
391
389
|
|
|
392
|
-
// Get Token Balance
|
|
393
390
|
// @ts-ignore
|
|
394
|
-
|
|
395
|
-
const
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
};
|
|
401
|
-
|
|
402
|
-
// free balance = total balance - frozen misc
|
|
403
|
-
// locked balance = reserved + frozen misc
|
|
404
|
-
const freeBalance = tokenBalance.free.sub(tokenBalance.frozen);
|
|
405
|
-
const lockedBalance = tokenBalance.frozen.add(tokenBalance.reserved);
|
|
391
|
+
return substrateApi.subscribeDataWithMulti(params, rs => {
|
|
392
|
+
const balances = rs[ormlTokensAccountsKey];
|
|
393
|
+
const items = balances.map((_balance, index) => {
|
|
394
|
+
const balanceInfo = _balance;
|
|
395
|
+
const transferableBalance = _getOrmlTokensPalletTransferable(balanceInfo, _getAssetExistentialDeposit(tokenInfo), extrinsicType);
|
|
396
|
+
const totalLockedFromTransfer = _getOrmlTokensPalletLockedBalance(balanceInfo);
|
|
406
397
|
return {
|
|
407
398
|
address: addresses[index],
|
|
408
399
|
tokenSlug: tokenInfo.slug,
|
|
409
400
|
state: APIItemState.READY,
|
|
410
|
-
free:
|
|
411
|
-
locked:
|
|
401
|
+
free: transferableBalance.toString(),
|
|
402
|
+
locked: totalLockedFromTransfer.toString()
|
|
412
403
|
};
|
|
413
404
|
});
|
|
414
405
|
callback(items);
|
|
415
406
|
});
|
|
416
|
-
return unsub;
|
|
417
407
|
} catch (err) {
|
|
418
408
|
console.warn(err);
|
|
419
409
|
return undefined;
|
|
420
410
|
}
|
|
421
411
|
});
|
|
422
412
|
return () => {
|
|
423
|
-
unsubList.forEach(
|
|
424
|
-
|
|
425
|
-
unsub && unsub();
|
|
426
|
-
}).catch(console.error);
|
|
413
|
+
unsubList.forEach(unsub => {
|
|
414
|
+
unsub && unsub.unsubscribe();
|
|
427
415
|
});
|
|
428
416
|
};
|
|
429
417
|
};
|
|
@@ -17,5 +17,5 @@ declare type CreateSnowBridgeExtrinsicProps = Omit<CreateXcmExtrinsicProps, 'sub
|
|
|
17
17
|
};
|
|
18
18
|
export declare const createSnowBridgeExtrinsic: ({ chainInfoMap, destinationTokenInfo, evmApi, originTokenInfo, recipient, sender, sendingValue }: CreateSnowBridgeExtrinsicProps) => Promise<TransactionConfig>;
|
|
19
19
|
export declare const createXcmExtrinsic: ({ chainInfoMap, destinationTokenInfo, originTokenInfo, recipient, sendingValue, substrateApi }: CreateXcmExtrinsicProps) => Promise<SubmittableExtrinsic<'promise'>>;
|
|
20
|
-
export declare const getXcmMockTxFee: (substrateApi: _SubstrateApi, chainInfoMap: Record<string, _ChainInfo>,
|
|
20
|
+
export declare const getXcmMockTxFee: (substrateApi: _SubstrateApi, chainInfoMap: Record<string, _ChainInfo>, originTokenInfo: _ChainAsset, destinationTokenInfo: _ChainAsset) => Promise<BigN>;
|
|
21
21
|
export {};
|
|
@@ -53,11 +53,12 @@ export const createXcmExtrinsic = async ({
|
|
|
53
53
|
}
|
|
54
54
|
return extrinsic;
|
|
55
55
|
};
|
|
56
|
-
export const getXcmMockTxFee = async (substrateApi, chainInfoMap,
|
|
56
|
+
export const getXcmMockTxFee = async (substrateApi, chainInfoMap, originTokenInfo, destinationTokenInfo) => {
|
|
57
57
|
try {
|
|
58
58
|
var _paymentInfo$partialF;
|
|
59
59
|
const destChainInfo = chainInfoMap[destinationTokenInfo.originChain];
|
|
60
60
|
const originChainInfo = chainInfoMap[originTokenInfo.originChain];
|
|
61
|
+
const address = '5DRewsYzhJqZXU3SRaWy1FSt5iDr875ao91aw5fjrJmDG4Ap';
|
|
61
62
|
|
|
62
63
|
// mock receiving account from sender
|
|
63
64
|
const recipient = !isEthereumAddress(address) && _isChainEvmCompatible(destChainInfo) && !_isChainEvmCompatible(originChainInfo) ? u8aToHex(addressToEvm(address)) : address;
|
|
@@ -11,7 +11,7 @@ export function getExtrinsicByPolkadotXcmPallet(tokenInfo, originChainInfo, dest
|
|
|
11
11
|
version = 4;
|
|
12
12
|
method = 'transferAssets';
|
|
13
13
|
}
|
|
14
|
-
if (isUseTeleportProtocol(originChainInfo, destinationChainInfo)) {
|
|
14
|
+
if (isUseTeleportProtocol(originChainInfo, destinationChainInfo, tokenInfo.slug)) {
|
|
15
15
|
method = 'limitedTeleportAssets';
|
|
16
16
|
}
|
|
17
17
|
const weightParam = _getXcmDestWeight(originChainInfo);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
2
|
export declare const STABLE_XCM_VERSION = 3;
|
|
3
|
-
export declare function isUseTeleportProtocol(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo): boolean;
|
|
3
|
+
export declare function isUseTeleportProtocol(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo, tokenSlug?: string): boolean;
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
export const STABLE_XCM_VERSION = 3;
|
|
5
|
-
export function isUseTeleportProtocol(originChainInfo, destChainInfo) {
|
|
5
|
+
export function isUseTeleportProtocol(originChainInfo, destChainInfo, tokenSlug) {
|
|
6
6
|
const relayChainToSystemChain = ['polkadot'].includes(originChainInfo.slug) && ['statemint'].includes(destChainInfo.slug) || ['kusama'].includes(originChainInfo.slug) && ['statemine'].includes(destChainInfo.slug) || ['rococo'].includes(originChainInfo.slug) && ['rococo_assethub'].includes(destChainInfo.slug);
|
|
7
7
|
const systemChainToRelayChain = ['polkadot'].includes(destChainInfo.slug) && ['statemint'].includes(originChainInfo.slug) || ['kusama'].includes(destChainInfo.slug) && ['statemine'].includes(originChainInfo.slug) || ['rococo'].includes(destChainInfo.slug) && ['rococo_assethub'].includes(originChainInfo.slug);
|
|
8
|
-
|
|
8
|
+
const isXcmMythos = originChainInfo.slug === 'mythos' && destChainInfo.slug === 'statemint' && tokenSlug === 'mythos-NATIVE-MYTH' || originChainInfo.slug === 'statemint' && destChainInfo.slug === 'mythos' && tokenSlug === 'statemint-LOCAL-MYTH';
|
|
9
|
+
return relayChainToSystemChain || systemChainToRelayChain || isXcmMythos;
|
|
9
10
|
}
|
|
@@ -256,7 +256,7 @@ export const _DEFAULT_MANTA_ZK_CHAIN = 'calamari';
|
|
|
256
256
|
// XCM------------------------------------------------------------------------------------------------------------------
|
|
257
257
|
|
|
258
258
|
export const _XCM_CHAIN_GROUP = {
|
|
259
|
-
polkadotXcm: ['astar', 'shiden', 'statemine', 'statemint', 'equilibrium_parachain', 'rococo_assethub'],
|
|
259
|
+
polkadotXcm: ['astar', 'shiden', 'statemine', 'statemint', 'equilibrium_parachain', 'rococo_assethub', 'mythos'],
|
|
260
260
|
xcmPallet: ['polkadot', 'kusama', 'rococo']
|
|
261
261
|
// default is xTokens pallet
|
|
262
262
|
};
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import '@polkadot/types-augment';
|
|
2
2
|
import { MetadataItem } from '@subwallet/extension-base/background/KoniTypes';
|
|
3
3
|
import { _ApiOptions } from '@subwallet/extension-base/services/chain-service/handler/types';
|
|
4
|
-
import { _ChainConnectionStatus,
|
|
5
|
-
import { BehaviorSubject } from 'rxjs';
|
|
4
|
+
import { _ChainConnectionStatus, _SubstrateAdapterQueryArgs, _SubstrateAdapterSubscriptionArgs, _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
5
|
+
import { BehaviorSubject, Subscription } from 'rxjs';
|
|
6
6
|
import { ApiPromise } from '@polkadot/api';
|
|
7
|
-
import { SubmittableExtrinsicFunction } from '@polkadot/api/promise/types';
|
|
8
7
|
import { ProviderInterface } from '@polkadot/rpc-provider/types';
|
|
9
|
-
import { Registry } from '@polkadot/types/types';
|
|
8
|
+
import { AnyJson, Registry } from '@polkadot/types/types';
|
|
10
9
|
export declare class SubstrateApi implements _SubstrateApi {
|
|
11
10
|
chainSlug: string;
|
|
12
11
|
api: ApiPromise;
|
|
@@ -25,9 +24,6 @@ export declare class SubstrateApi implements _SubstrateApi {
|
|
|
25
24
|
substrateRetry: number;
|
|
26
25
|
get connectionStatus(): _ChainConnectionStatus;
|
|
27
26
|
private updateConnectionStatus;
|
|
28
|
-
apiDefaultTx?: SubmittableExtrinsicFunction;
|
|
29
|
-
apiDefaultTxSudo?: SubmittableExtrinsicFunction;
|
|
30
|
-
defaultFormatBalance?: _SubstrateDefaultFormatBalance;
|
|
31
27
|
registry: Registry;
|
|
32
28
|
specName: string;
|
|
33
29
|
specVersion: string;
|
|
@@ -48,4 +44,6 @@ export declare class SubstrateApi implements _SubstrateApi {
|
|
|
48
44
|
onDisconnect(): void;
|
|
49
45
|
onError(e: Error): void;
|
|
50
46
|
fillApiInfo(): Promise<void>;
|
|
47
|
+
makeRpcQuery<T>({ args, method, module, section }: _SubstrateAdapterQueryArgs): Promise<T>;
|
|
48
|
+
subscribeDataWithMulti(params: _SubstrateAdapterSubscriptionArgs[], callback: (rs: Record<string, AnyJson[]>) => void): Subscription;
|
|
51
49
|
}
|