@subwallet/extension-base 1.1.22-0 → 1.1.23-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 +10 -1
- package/cjs/koni/api/dotsama/balance.js +49 -0
- package/cjs/koni/api/dotsama/crowdloan.js +29 -3
- package/cjs/koni/api/dotsama/transfer.js +10 -3
- package/cjs/koni/api/staking/bonding/astar.js +9 -5
- package/cjs/koni/api/xcm/index.js +6 -1
- package/cjs/koni/api/xcm/polkadotXcm.js +1 -3
- package/cjs/koni/api/xcm/xTokens.js +1 -1
- package/cjs/koni/background/handlers/Extension.js +114 -96
- package/cjs/koni/background/handlers/State.js +12 -6
- package/cjs/koni/background/subscription.js +1 -1
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/chain-service/constants.js +5 -2
- package/cjs/services/chain-service/index.js +18 -0
- package/cjs/services/history-service/helpers/subscan-extrinsic-parser-helper.js +53 -0
- package/cjs/services/history-service/index.js +78 -21
- package/cjs/services/history-service/subscan-history.js +107 -0
- package/cjs/services/subscan-service/index.js +109 -4
- package/cjs/services/subscan-service/subscan-chain-map.js +82 -8
- package/cjs/utils/index.js +10 -1
- package/koni/api/dotsama/balance.js +49 -0
- package/koni/api/dotsama/crowdloan.d.ts +2 -2
- package/koni/api/dotsama/crowdloan.js +29 -2
- package/koni/api/dotsama/transfer.js +10 -3
- package/koni/api/staking/bonding/astar.js +9 -5
- package/koni/api/xcm/index.js +6 -1
- package/koni/api/xcm/polkadotXcm.js +2 -4
- package/koni/api/xcm/xTokens.js +1 -1
- package/koni/background/handlers/Extension.d.ts +1 -0
- package/koni/background/handlers/Extension.js +17 -0
- package/koni/background/handlers/State.d.ts +1 -0
- package/koni/background/handlers/State.js +13 -7
- package/koni/background/subscription.js +1 -1
- package/package.json +16 -6
- package/packageInfo.js +1 -1
- package/services/chain-service/constants.d.ts +2 -0
- package/services/chain-service/constants.js +5 -3
- package/services/chain-service/index.d.ts +1 -0
- package/services/chain-service/index.js +18 -0
- package/services/history-service/helpers/subscan-extrinsic-parser-helper.d.ts +6 -0
- package/services/history-service/helpers/subscan-extrinsic-parser-helper.js +44 -0
- package/services/history-service/index.d.ts +10 -6
- package/services/history-service/index.js +79 -22
- package/services/history-service/subscan-history.d.ts +5 -0
- package/services/history-service/subscan-history.js +100 -0
- package/services/subscan-service/index.d.ts +10 -2
- package/services/subscan-service/index.js +105 -4
- package/services/subscan-service/subscan-chain-map.d.ts +9 -3
- package/services/subscan-service/subscan-chain-map.js +78 -5
- package/services/subscan-service/types.d.ts +146 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.js +7 -0
|
@@ -450,7 +450,7 @@ export interface NFTTransactionAdditionalInfo {
|
|
|
450
450
|
}
|
|
451
451
|
export declare type TransactionAdditionalInfo<T extends ExtrinsicType> = T extends ExtrinsicType.TRANSFER_XCM ? XCMTransactionAdditionalInfo : T extends ExtrinsicType.SEND_NFT ? NFTTransactionAdditionalInfo : undefined;
|
|
452
452
|
export interface TransactionHistoryItem<ET extends ExtrinsicType = ExtrinsicType.TRANSFER_BALANCE> {
|
|
453
|
-
origin?: 'app' | 'migration' | 'subsquid';
|
|
453
|
+
origin?: 'app' | 'migration' | 'subsquid' | 'subscan';
|
|
454
454
|
callhash?: string;
|
|
455
455
|
signature?: string;
|
|
456
456
|
chain: string;
|
|
@@ -1603,6 +1603,14 @@ export declare type CampaignData = CampaignBanner | CampaignNotification;
|
|
|
1603
1603
|
export interface RequestCampaignBannerComplete {
|
|
1604
1604
|
slug: string;
|
|
1605
1605
|
}
|
|
1606
|
+
export interface RequestSubscribeHistory {
|
|
1607
|
+
address: string;
|
|
1608
|
+
chain: string;
|
|
1609
|
+
}
|
|
1610
|
+
export interface ResponseSubscribeHistory {
|
|
1611
|
+
id: string;
|
|
1612
|
+
items: TransactionHistoryItem[];
|
|
1613
|
+
}
|
|
1606
1614
|
export interface KoniRequestSignatures {
|
|
1607
1615
|
'pri(staking.submitTuringCancelCompound)': [RequestTuringCancelStakeCompound, SWTransactionResponse];
|
|
1608
1616
|
'pri(staking.submitTuringCompound)': [RequestTuringStakeCompound, SWTransactionResponse];
|
|
@@ -1716,6 +1724,7 @@ export interface KoniRequestSignatures {
|
|
|
1716
1724
|
'pri(settings.saveShowZeroBalance)': [RequestChangeShowZeroBalance, boolean];
|
|
1717
1725
|
'pri(settings.saveShowBalance)': [RequestChangeShowBalance, boolean];
|
|
1718
1726
|
'pri(transaction.history.getSubscription)': [null, TransactionHistoryItem[], TransactionHistoryItem[]];
|
|
1727
|
+
'pri(transaction.history.subscribe)': [RequestSubscribeHistory, ResponseSubscribeHistory, TransactionHistoryItem[]];
|
|
1719
1728
|
'pri(transfer.checkReferenceCount)': [RequestTransferCheckReferenceCount, boolean];
|
|
1720
1729
|
'pri(transfer.checkSupporting)': [RequestTransferCheckSupporting, SupportTransferResponse];
|
|
1721
1730
|
'pri(transfer.getExistentialDeposit)': [RequestTransferExistentialDeposit, string];
|
|
@@ -79,6 +79,8 @@ async function subscribeSubstrateBalance(addresses, chainInfo, chain, networkAPI
|
|
|
79
79
|
unsubLocalToken = await subscribeEqBalanceAccountPallet(addresses, chain, networkAPI.api, callBack, true);
|
|
80
80
|
} else if (_constants2._BALANCE_CHAIN_GROUP.equilibrium_parachain.includes(chain)) {
|
|
81
81
|
unsubLocalToken = await subscribeEquilibriumTokenBalance(addresses, chain, networkAPI.api, callBack, true);
|
|
82
|
+
} else if (_constants2._BALANCE_CHAIN_GROUP.centrifuge.includes(chain)) {
|
|
83
|
+
unsubLocalToken = await subscribeOrmlTokensPallet(addresses, chain, networkAPI.api, callBack);
|
|
82
84
|
}
|
|
83
85
|
if ((0, _utils2._isChainEvmCompatible)(chainInfo)) {
|
|
84
86
|
unsubEvmContractToken = subscribeERC20Interval(addresses, chain, evmApiMap, callBack);
|
|
@@ -293,6 +295,53 @@ async function subscribeEqBalanceAccountPallet(addresses, chain, api, callBack,
|
|
|
293
295
|
});
|
|
294
296
|
};
|
|
295
297
|
}
|
|
298
|
+
|
|
299
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
300
|
+
async function subscribeOrmlTokensPallet(addresses, chain, api, callBack) {
|
|
301
|
+
const tokenTypes = [_types._AssetType.LOCAL];
|
|
302
|
+
const tokenMap = _handlers.state.getAssetByChainAndAsset(chain, tokenTypes);
|
|
303
|
+
const unsubList = Object.values(tokenMap).map(async tokenInfo => {
|
|
304
|
+
try {
|
|
305
|
+
const onChainInfo = (0, _utils2._getTokenOnChainInfo)(tokenInfo);
|
|
306
|
+
|
|
307
|
+
// Get Token Balance
|
|
308
|
+
// @ts-ignore
|
|
309
|
+
const unsub = await api.query.ormlTokens.accounts.multi(addresses.map(address => [address, onChainInfo]), balances => {
|
|
310
|
+
const tokenBalance = {
|
|
311
|
+
reserved: (0, _utils3.sumBN)(balances.map(b => b.reserved || new _util.BN(0))),
|
|
312
|
+
frozen: (0, _utils3.sumBN)(balances.map(b => b.frozen || new _util.BN(0))),
|
|
313
|
+
free: (0, _utils3.sumBN)(balances.map(b => b.free || new _util.BN(0))) // free is actually total balance
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
// free balance = total balance - frozen misc
|
|
317
|
+
// locked balance = reserved + frozen misc
|
|
318
|
+
const freeBalance = tokenBalance.free.sub(tokenBalance.frozen);
|
|
319
|
+
const lockedBalance = tokenBalance.frozen.add(tokenBalance.reserved);
|
|
320
|
+
callBack({
|
|
321
|
+
tokenSlug: tokenInfo.slug,
|
|
322
|
+
state: _KoniTypes.APIItemState.READY,
|
|
323
|
+
free: freeBalance.toString(),
|
|
324
|
+
locked: lockedBalance.toString(),
|
|
325
|
+
substrateInfo: {
|
|
326
|
+
reserved: tokenBalance.reserved.toString(),
|
|
327
|
+
miscFrozen: tokenBalance.frozen.toString()
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
});
|
|
331
|
+
return unsub;
|
|
332
|
+
} catch (err) {
|
|
333
|
+
console.warn(err);
|
|
334
|
+
return undefined;
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
return () => {
|
|
338
|
+
unsubList.forEach(subProm => {
|
|
339
|
+
subProm.then(unsub => {
|
|
340
|
+
unsub && unsub();
|
|
341
|
+
}).catch(console.error);
|
|
342
|
+
});
|
|
343
|
+
};
|
|
344
|
+
}
|
|
296
345
|
async function subscribeTokensAccountsPallet(addresses, chain, api, callBack, includeNativeToken) {
|
|
297
346
|
const tokenTypes = includeNativeToken ? [_types._AssetType.NATIVE, _types._AssetType.LOCAL] : [_types._AssetType.LOCAL];
|
|
298
347
|
const tokenMap = _handlers.state.getAssetByChainAndAsset(chain, tokenTypes);
|
|
@@ -24,7 +24,20 @@ const STATUS_MAP = {
|
|
|
24
24
|
[_types._FundStatus.FAILED]: _KoniTypes.CrowdloanParaState.FAILED,
|
|
25
25
|
[_types._FundStatus.WON]: _KoniTypes.CrowdloanParaState.COMPLETED
|
|
26
26
|
};
|
|
27
|
+
function getChainInfoMap(chainInfoList) {
|
|
28
|
+
const result = {};
|
|
29
|
+
chainInfoList.forEach(ci => {
|
|
30
|
+
if (ci.slug) {
|
|
31
|
+
result[ci.slug] = ci;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
27
36
|
const getOnlineFundList = (0, _fetchStaticData.fetchStaticData)('crowdloan-funds');
|
|
37
|
+
const getOnlineChainInfoMap = (async () => {
|
|
38
|
+
const chainInfoList = await (0, _fetchStaticData.fetchStaticData)('chains');
|
|
39
|
+
return getChainInfoMap(chainInfoList);
|
|
40
|
+
})();
|
|
28
41
|
function getRPCCrowdloan(parentAPI, fundInfo, hexAddresses, callback) {
|
|
29
42
|
const {
|
|
30
43
|
auctionIndex,
|
|
@@ -130,16 +143,29 @@ const subscribeAcalaContributeInterval = (polkadotAddresses, fundInfo, callback)
|
|
|
130
143
|
// return stateMap;
|
|
131
144
|
// }, {} as Record<string, CrowdloanParaState>);
|
|
132
145
|
// }
|
|
146
|
+
exports.subscribeAcalaContributeInterval = subscribeAcalaContributeInterval;
|
|
147
|
+
function isNeedToUpdateLatestFundInfoMap(latestMap, chainSlug, fundInfo) {
|
|
148
|
+
if (!latestMap[chainSlug]) {
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
if (!fundInfo.auctionIndex && fundInfo.status === _types._FundStatus.IN_AUCTION) {
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
if (fundInfo.auctionIndex > latestMap[chainSlug].auctionIndex) {
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
133
159
|
|
|
134
160
|
// Get All crowdloan
|
|
135
|
-
|
|
136
|
-
async function subscribeCrowdloan(addresses, substrateApiMap, callback, chainInfoMap) {
|
|
161
|
+
async function subscribeCrowdloan(addresses, substrateApiMap, callback) {
|
|
137
162
|
const unsubMap = {};
|
|
138
163
|
const latestMap = {};
|
|
139
164
|
const rawFundList = await getOnlineFundList;
|
|
165
|
+
const chainInfoMap = await getOnlineChainInfoMap;
|
|
140
166
|
rawFundList.forEach(fundInfo => {
|
|
141
167
|
const chainSlug = fundInfo.chain;
|
|
142
|
-
if (
|
|
168
|
+
if (isNeedToUpdateLatestFundInfoMap(latestMap, chainSlug, fundInfo)) {
|
|
143
169
|
latestMap[chainSlug] = fundInfo;
|
|
144
170
|
}
|
|
145
171
|
});
|
|
@@ -105,8 +105,11 @@ async function checkSupportTransfer(networkKey, tokenInfo, substrateApiMap, chai
|
|
|
105
105
|
// result.supportTransfer = true;
|
|
106
106
|
// result.supportTransferAll = true;
|
|
107
107
|
} else if (_constants._TRANSFER_CHAIN_GROUP.avail.includes(networkKey)) {
|
|
108
|
-
result.supportTransfer =
|
|
109
|
-
result.supportTransferAll =
|
|
108
|
+
result.supportTransfer = true;
|
|
109
|
+
result.supportTransferAll = true;
|
|
110
|
+
} else if (_constants._TRANSFER_CHAIN_GROUP.centrifuge.includes(networkKey)) {
|
|
111
|
+
result.supportTransfer = true;
|
|
112
|
+
result.supportTransferAll = true;
|
|
110
113
|
}
|
|
111
114
|
return result;
|
|
112
115
|
}
|
|
@@ -190,7 +193,11 @@ const createTransferExtrinsic = async _ref => {
|
|
|
190
193
|
if (transferAll) {
|
|
191
194
|
transfer = api.tx.balances.transferAll(to, false);
|
|
192
195
|
} else if (value) {
|
|
193
|
-
|
|
196
|
+
if (api.tx.balances.transferKeepAlive) {
|
|
197
|
+
transfer = api.tx.balances.transferKeepAlive(to, new _util.BN(value));
|
|
198
|
+
} else {
|
|
199
|
+
transfer = api.tx.balances.transfer(to, new _util.BN(value));
|
|
200
|
+
}
|
|
194
201
|
}
|
|
195
202
|
}
|
|
196
203
|
return [transfer, transferAmount || value];
|
|
@@ -79,6 +79,9 @@ async function getAstarStakingMetadata(chain, substrateApi) {
|
|
|
79
79
|
unstakingPeriod
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
|
+
const convertAddress = address => {
|
|
83
|
+
return (0, _utilCrypto.isEthereumAddress)(address) ? address.toLowerCase() : address;
|
|
84
|
+
};
|
|
82
85
|
async function subscribeAstarNominatorMetadata(chainInfo, address, substrateApi, ledger) {
|
|
83
86
|
const nominationList = [];
|
|
84
87
|
const unstakingList = [];
|
|
@@ -97,14 +100,15 @@ async function subscribeAstarNominatorMetadata(chainInfo, address, substrateApi,
|
|
|
97
100
|
if (_stakerInfo.length > 0) {
|
|
98
101
|
const dAppInfoMap = {};
|
|
99
102
|
allDapps.forEach(dappInfo => {
|
|
100
|
-
dAppInfoMap[dappInfo.address
|
|
103
|
+
dAppInfoMap[convertAddress(dappInfo.address)] = dappInfo;
|
|
101
104
|
});
|
|
102
105
|
for (const item of _stakerInfo) {
|
|
103
106
|
const data = item[0].toHuman();
|
|
104
107
|
const stakedDapp = data[1];
|
|
105
108
|
const stakeData = item[1].toPrimitive();
|
|
106
109
|
const stakeList = stakeData.stakes;
|
|
107
|
-
const
|
|
110
|
+
const _dappAddress = stakedDapp.Evm ? stakedDapp.Evm.toLowerCase() : stakedDapp.Wasm;
|
|
111
|
+
const dappAddress = convertAddress(_dappAddress);
|
|
108
112
|
const currentStake = stakeList.slice(-1)[0].staked.toString() || '0';
|
|
109
113
|
const bnCurrentStake = new _util.BN(currentStake);
|
|
110
114
|
if (bnCurrentStake.gt(_util.BN_ZERO)) {
|
|
@@ -114,7 +118,7 @@ async function subscribeAstarNominatorMetadata(chainInfo, address, substrateApi,
|
|
|
114
118
|
nominationList.push({
|
|
115
119
|
status: dappStakingStatus,
|
|
116
120
|
chain: chainInfo.slug,
|
|
117
|
-
validatorAddress:
|
|
121
|
+
validatorAddress: dappAddress,
|
|
118
122
|
activeStake: currentStake,
|
|
119
123
|
validatorMinStake: '0',
|
|
120
124
|
validatorIdentity: dappInfo === null || dappInfo === void 0 ? void 0 : dappInfo.name,
|
|
@@ -192,7 +196,7 @@ async function getAstarNominatorMetadata(chainInfo, address, substrateApi) {
|
|
|
192
196
|
const stakedDapp = data[1];
|
|
193
197
|
const stakeData = item[1].toPrimitive();
|
|
194
198
|
const stakeList = stakeData.stakes;
|
|
195
|
-
const dappAddress = (
|
|
199
|
+
const dappAddress = convertAddress(stakedDapp.Evm);
|
|
196
200
|
const currentStake = stakeList.slice(-1)[0].staked.toString() || '0';
|
|
197
201
|
const bnCurrentStake = new _util.BN(currentStake);
|
|
198
202
|
if (bnCurrentStake.gt(_util.BN_ZERO)) {
|
|
@@ -285,7 +289,7 @@ async function getAstarDappsInfo(networkKey, substrateApi) {
|
|
|
285
289
|
allDappsInfo.push({
|
|
286
290
|
commission: 0,
|
|
287
291
|
expectedReturn: 0,
|
|
288
|
-
address: (
|
|
292
|
+
address: convertAddress(dappAddress),
|
|
289
293
|
totalStake: totalStake,
|
|
290
294
|
ownStake: '0',
|
|
291
295
|
otherStake: totalStake.toString(),
|
|
@@ -8,6 +8,7 @@ var _polkadotXcm = require("@subwallet/extension-base/koni/api/xcm/polkadotXcm")
|
|
|
8
8
|
var _xcmPallet = require("@subwallet/extension-base/koni/api/xcm/xcmPallet");
|
|
9
9
|
var _xTokens = require("@subwallet/extension-base/koni/api/xcm/xTokens");
|
|
10
10
|
var _constants = require("@subwallet/extension-base/services/chain-service/constants");
|
|
11
|
+
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
11
12
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
12
13
|
// SPDX-License-Identifier: Apache-2.0
|
|
13
14
|
|
|
@@ -26,7 +27,11 @@ const createXcmExtrinsic = async _ref => {
|
|
|
26
27
|
const api = chainApi.api;
|
|
27
28
|
let extrinsic;
|
|
28
29
|
if (_constants._XCM_CHAIN_GROUP.polkadotXcm.includes(originTokenInfo.originChain)) {
|
|
29
|
-
|
|
30
|
+
if (['astar', 'shiden'].includes(originChainInfo.slug) && !(0, _utils._isNativeToken)(originTokenInfo)) {
|
|
31
|
+
extrinsic = (0, _xTokens.getExtrinsicByXtokensPallet)(originTokenInfo, originChainInfo, destinationChainInfo, recipient, sendingValue, api);
|
|
32
|
+
} else {
|
|
33
|
+
extrinsic = (0, _polkadotXcm.getExtrinsicByPolkadotXcmPallet)(originTokenInfo, originChainInfo, destinationChainInfo, recipient, sendingValue, api);
|
|
34
|
+
}
|
|
30
35
|
} else if (_constants._XCM_CHAIN_GROUP.xcmPallet.includes(originTokenInfo.originChain)) {
|
|
31
36
|
extrinsic = (0, _xcmPallet.getExtrinsicByXcmPalletPallet)(originTokenInfo, originChainInfo, destinationChainInfo, recipient, sendingValue, api);
|
|
32
37
|
} else {
|
|
@@ -16,9 +16,7 @@ function getExtrinsicByPolkadotXcmPallet(tokenInfo, originChainInfo, destination
|
|
|
16
16
|
const destination = (0, _utils.getDestinationChainLocation)(originChainInfo, destinationChainInfo, version);
|
|
17
17
|
let assetLocation = (0, _utils.getTokenLocation)(tokenInfo, value, version);
|
|
18
18
|
let method = 'limitedReserveTransferAssets';
|
|
19
|
-
if (['
|
|
20
|
-
method = 'limitedReserveWithdrawAssets';
|
|
21
|
-
} else if (['statemint', 'statemine'].includes(originChainInfo.slug) && (0, _utils2._isSubstrateRelayChain)(destinationChainInfo)) {
|
|
19
|
+
if (['statemint', 'statemine'].includes(originChainInfo.slug) && (0, _utils2._isSubstrateRelayChain)(destinationChainInfo)) {
|
|
22
20
|
assetLocation = {
|
|
23
21
|
[version]: [{
|
|
24
22
|
id: {
|
|
@@ -25,6 +25,6 @@ function getCurrencyId(tokenInfo) {
|
|
|
25
25
|
}
|
|
26
26
|
function getExtrinsicByXtokensPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
|
|
27
27
|
const weightParam = ['pioneer'].includes(originChainInfo.slug) ? _utils.FOUR_INSTRUCTIONS_WEIGHT : (0, _utils.getDestWeight)();
|
|
28
|
-
const destVersion = ['moonbeam', 'moonriver', 'bifrost_dot', 'interlay', 'hydradx_main', 'acala', 'parallel'].includes(originChainInfo.slug) ? 'V3' : undefined;
|
|
28
|
+
const destVersion = ['moonbeam', 'moonriver', 'bifrost_dot', 'interlay', 'hydradx_main', 'acala', 'parallel', 'astar', 'shiden'].includes(originChainInfo.slug) ? 'V3' : undefined;
|
|
29
29
|
return api.tx.xTokens.transfer(getCurrencyId(tokenInfo), value, (0, _utils.getDestMultilocation)(destinationChainInfo, recipientAddress, destVersion), weightParam);
|
|
30
30
|
}
|