@subwallet/extension-base 1.0.1 → 1.0.2-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.
- package/background/KoniTypes.d.ts +10 -3
- package/background/KoniTypes.js +6 -0
- package/cjs/background/KoniTypes.js +8 -1
- package/cjs/constants/index.js +6 -3
- package/cjs/koni/api/dotsama/balance.js +11 -0
- package/cjs/koni/api/staking/bonding/amplitude.js +6 -2
- package/cjs/koni/api/staking/bonding/astar.js +40 -243
- package/cjs/koni/api/staking/bonding/index.js +4 -4
- package/cjs/koni/api/staking/bonding/paraChain.js +16 -10
- package/cjs/koni/api/staking/bonding/relayChain.js +62 -7
- package/cjs/koni/api/staking/bonding/utils.js +29 -3
- package/cjs/koni/api/xcm/index.js +0 -111
- package/cjs/koni/api/xcm/polkadotXcm.js +1 -1
- package/cjs/koni/api/xcm/xTokens.js +2 -4
- package/cjs/koni/background/cron.js +61 -62
- package/cjs/koni/background/handlers/Extension.js +143 -149
- package/cjs/koni/background/handlers/State.js +129 -91
- package/cjs/koni/background/handlers/Tabs.js +40 -38
- package/cjs/koni/background/subscription.js +48 -43
- package/cjs/packageInfo.js +1 -1
- package/cjs/page/index.js +5 -0
- package/cjs/services/chain-service/constants.js +1 -11
- package/cjs/services/chain-service/index.js +39 -5
- package/cjs/services/chain-service/utils.js +4 -0
- package/cjs/services/event-service/index.js +71 -0
- package/cjs/services/event-service/types.js +1 -0
- package/cjs/services/history-service/index.js +36 -17
- package/cjs/services/history-service/subsquid-multi-chain-history.js +7 -2
- package/cjs/services/keyring-service/index.js +101 -0
- package/cjs/services/migration-service/index.js +13 -10
- package/cjs/{koni/migration/scripts/RemoveWrongCrowdloan.js → services/migration-service/scripts/AutoEnableChainsTokens.js} +11 -6
- package/cjs/services/migration-service/scripts/MigrateNetworkSettings.js +39 -19
- package/cjs/services/migration-service/scripts/MigrateSettings.js +31 -0
- package/cjs/services/migration-service/scripts/MigrateTransactionHistory.js +72 -0
- package/cjs/services/migration-service/scripts/index.js +13 -4
- package/cjs/services/price-service/coingecko.js +16 -3
- package/cjs/services/price-service/index.js +15 -17
- package/cjs/services/request-service/constants.js +8 -2
- package/cjs/services/request-service/handler/AuthRequestHandler.js +39 -12
- package/cjs/services/request-service/index.js +3 -0
- package/cjs/services/storage-service/DatabaseService.js +1 -1
- package/cjs/services/storage-service/databases/index.js +1 -1
- package/cjs/services/storage-service/db-stores/BaseStoreWithAddressAndChain.js +2 -8
- package/cjs/services/storage-service/db-stores/Nft.js +4 -1
- package/cjs/services/storage-service/db-stores/Transaction.js +10 -7
- package/cjs/services/subscan-service/index.js +107 -0
- package/cjs/services/subscan-service/subscan-chain-map.js +74 -0
- package/cjs/services/subscan-service/types.js +1 -0
- package/cjs/services/transaction-service/index.js +45 -10
- package/cjs/services/transaction-service/utils.js +4 -6
- package/cjs/utils/address.js +9 -1
- package/cjs/utils/index.js +24 -13
- package/constants/index.d.ts +1 -0
- package/constants/index.js +1 -0
- package/koni/api/dotsama/balance.js +11 -0
- package/koni/api/staking/bonding/amplitude.d.ts +1 -1
- package/koni/api/staking/bonding/amplitude.js +8 -4
- package/koni/api/staking/bonding/astar.d.ts +2 -11
- package/koni/api/staking/bonding/astar.js +35 -229
- package/koni/api/staking/bonding/index.d.ts +1 -1
- package/koni/api/staking/bonding/index.js +4 -4
- package/koni/api/staking/bonding/paraChain.d.ts +1 -1
- package/koni/api/staking/bonding/paraChain.js +17 -11
- package/koni/api/staking/bonding/relayChain.d.ts +1 -1
- package/koni/api/staking/bonding/relayChain.js +63 -8
- package/koni/api/staking/bonding/utils.d.ts +13 -1
- package/koni/api/staking/bonding/utils.js +27 -3
- package/koni/api/xcm/index.js +1 -112
- package/koni/api/xcm/polkadotXcm.js +1 -1
- package/koni/api/xcm/xTokens.js +3 -5
- package/koni/background/cron.js +60 -60
- package/koni/background/handlers/Extension.js +71 -76
- package/koni/background/handlers/State.d.ts +16 -14
- package/koni/background/handlers/State.js +126 -91
- package/koni/background/handlers/Tabs.js +22 -19
- package/koni/background/subscription.d.ts +1 -1
- package/koni/background/subscription.js +49 -44
- package/package.json +56 -16
- package/packageInfo.js +1 -1
- package/page/index.d.ts +2 -0
- package/page/index.js +4 -0
- package/services/chain-service/constants.d.ts +0 -1
- package/services/chain-service/constants.js +0 -9
- package/services/chain-service/index.d.ts +6 -4
- package/services/chain-service/index.js +39 -7
- package/services/chain-service/utils.d.ts +1 -0
- package/services/chain-service/utils.js +3 -0
- package/services/event-service/index.d.ts +22 -0
- package/services/event-service/index.js +59 -0
- package/services/event-service/types.d.ts +32 -0
- package/services/event-service/types.js +1 -0
- package/services/history-service/index.d.ts +5 -3
- package/services/history-service/index.js +36 -17
- package/services/history-service/subsquid-multi-chain-history.js +7 -2
- package/services/keyring-service/index.d.ts +19 -0
- package/services/keyring-service/index.js +93 -0
- package/services/migration-service/index.js +11 -9
- package/services/migration-service/scripts/AutoEnableChainsTokens.d.ts +4 -0
- package/services/migration-service/scripts/AutoEnableChainsTokens.js +13 -0
- package/services/migration-service/scripts/MigrateNetworkSettings.js +37 -18
- package/services/migration-service/scripts/MigrateSettings.d.ts +4 -0
- package/services/migration-service/scripts/MigrateSettings.js +23 -0
- package/services/migration-service/scripts/MigrateTransactionHistory.d.ts +4 -0
- package/services/migration-service/scripts/MigrateTransactionHistory.js +64 -0
- package/services/migration-service/scripts/index.d.ts +1 -0
- package/services/migration-service/scripts/index.js +10 -3
- package/services/price-service/coingecko.js +16 -3
- package/services/price-service/index.d.ts +5 -3
- package/services/price-service/index.js +15 -17
- package/services/request-service/constants.d.ts +1 -0
- package/services/request-service/constants.js +6 -1
- package/services/request-service/handler/AuthRequestHandler.d.ts +8 -1
- package/services/request-service/handler/AuthRequestHandler.js +40 -13
- package/services/request-service/index.d.ts +7 -1
- package/services/request-service/index.js +3 -0
- package/services/storage-service/DatabaseService.js +1 -1
- package/services/storage-service/databases/index.js +1 -1
- package/services/storage-service/db-stores/BaseStoreWithAddressAndChain.d.ts +1 -1
- package/services/storage-service/db-stores/BaseStoreWithAddressAndChain.js +2 -8
- package/services/storage-service/db-stores/Nft.d.ts +2 -1
- package/services/storage-service/db-stores/Nft.js +4 -1
- package/services/storage-service/db-stores/Transaction.js +10 -7
- package/services/subscan-service/index.d.ts +20 -0
- package/services/subscan-service/index.js +99 -0
- package/services/subscan-service/subscan-chain-map.d.ts +5 -0
- package/services/subscan-service/subscan-chain-map.js +63 -0
- package/services/subscan-service/types.d.ts +27 -0
- package/services/subscan-service/types.js +1 -0
- package/services/transaction-service/event-parser/index.d.ts +2 -2
- package/services/transaction-service/index.d.ts +4 -2
- package/services/transaction-service/index.js +45 -10
- package/services/transaction-service/utils.js +5 -6
- package/utils/address.d.ts +1 -0
- package/utils/address.js +9 -2
- package/utils/index.d.ts +1 -0
- package/utils/index.js +21 -12
- package/cjs/background/errors/EvmRpcError.js +0 -21
- package/cjs/background/errors/SubWalletProviderError.js +0 -17
- package/cjs/constants/ethereum.js +0 -19
- package/cjs/errors/SubWalletProviderError.js +0 -17
- package/cjs/koni/api/xcm/astar.js +0 -160
- package/cjs/koni/api/xcm/moonbeamXcm.js +0 -80
- package/cjs/koni/api/xcm/statemintXcm.js +0 -197
- package/cjs/koni/api/xcm/substrateXcm.js +0 -213
- package/cjs/koni/migration/Base.js +0 -20
- package/cjs/koni/migration/index.js +0 -45
- package/cjs/koni/migration/scripts/ChangeRouteToHome.js +0 -22
- package/cjs/koni/migration/scripts/ClearOldStorage.js +0 -24
- package/cjs/koni/migration/scripts/RemoveWrongTransactionHistoriesFromStore.js +0 -36
- package/cjs/koni/migration/scripts/ResetTransactionHistoryEventIdx.js +0 -21
- package/cjs/koni/migration/scripts/index.js +0 -22
- package/cjs/koni/page/index.js +0 -16
- package/cjs/services/asset-service/index.js +0 -91
- package/cjs/services/storage-service/db-stores/ExtraDelegationInfo.js +0 -17
- package/cjs/stores/Balance.js +0 -18
- package/cjs/stores/Crowdloan.js +0 -18
- package/cjs/stores/CustomEvmToken.js +0 -18
- package/cjs/stores/NetworkMap.js +0 -18
- package/cjs/stores/Nft.js +0 -18
- package/cjs/stores/NftCollection.js +0 -18
- package/cjs/stores/Price.js +0 -18
- package/cjs/stores/Staking.js +0 -18
- package/cjs/stores/StakingReward.js +0 -18
- package/cjs/utils/eth/parseTransactionData.js +0 -284
- package/koni/page/index.d.ts +0 -2
- package/koni/page/index.js +0 -9
- /package/cjs/{koni/page → page}/SubWalleEvmProvider.js +0 -0
- /package/{koni/page → page}/SubWalleEvmProvider.d.ts +0 -0
- /package/{koni/page → page}/SubWalleEvmProvider.js +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="bn.js" />
|
|
2
2
|
import { NominationInfo, NominatorMetadata, StakingType, UnstakingInfo } from '@subwallet/extension-base/background/KoniTypes';
|
|
3
3
|
import { _SubstrateInflationParams } from '@subwallet/extension-base/services/chain-service/constants';
|
|
4
|
+
import { ApiPromise } from '@polkadot/api';
|
|
4
5
|
import { BN } from '@polkadot/util';
|
|
5
6
|
export interface PalletNominationPoolsPoolMember {
|
|
6
7
|
poolId: number;
|
|
@@ -64,6 +65,15 @@ export interface PalletParachainStakingDelegator {
|
|
|
64
65
|
lessTotal: number;
|
|
65
66
|
status: number;
|
|
66
67
|
}
|
|
68
|
+
export interface PalletStakingExposureItem {
|
|
69
|
+
who: string;
|
|
70
|
+
value: number;
|
|
71
|
+
}
|
|
72
|
+
export interface PalletStakingExposure {
|
|
73
|
+
total: number;
|
|
74
|
+
own: number;
|
|
75
|
+
others: PalletStakingExposureItem[];
|
|
76
|
+
}
|
|
67
77
|
export interface PalletIdentityRegistration {
|
|
68
78
|
judgements: any[];
|
|
69
79
|
deposit: number;
|
|
@@ -92,6 +102,7 @@ export interface Unlocking {
|
|
|
92
102
|
remainingEras: BN;
|
|
93
103
|
value: BN;
|
|
94
104
|
}
|
|
105
|
+
export declare function parsePoolStashAddress(api: ApiPromise, index: number, poolId: number, poolsPalletId: string): string;
|
|
95
106
|
export declare function transformPoolName(input: string): string;
|
|
96
107
|
export declare function parseIdentity(identityInfo: PalletIdentityRegistration | null): string | undefined;
|
|
97
108
|
export declare function getInflationParams(networkKey: string): _SubstrateInflationParams;
|
|
@@ -137,6 +148,7 @@ export declare enum StakingAction {
|
|
|
137
148
|
CLAIM_REWARD = "CLAIM_REWARD",
|
|
138
149
|
CANCEL_UNSTAKE = "CANCEL_UNSTAKE"
|
|
139
150
|
}
|
|
140
|
-
export declare function
|
|
151
|
+
export declare function getStakingAvailableActionsByChain(chain: string, type: StakingType): StakingAction[];
|
|
152
|
+
export declare function getStakingAvailableActionsByNominator(nominatorMetadata: NominatorMetadata): StakingAction[];
|
|
141
153
|
export declare function isActionFromValidator(stakingType: StakingType, chain: string): boolean;
|
|
142
154
|
export declare function getWithdrawalInfo(nominatorMetadata: NominatorMetadata): UnstakingInfo | undefined;
|
|
@@ -4,13 +4,22 @@
|
|
|
4
4
|
import { StakingType, UnstakingStatus } from '@subwallet/extension-base/background/KoniTypes';
|
|
5
5
|
import { _KNOWN_CHAIN_INFLATION_PARAMS, _STAKING_CHAIN_GROUP, _SUBSTRATE_DEFAULT_INFLATION_PARAMS } from '@subwallet/extension-base/services/chain-service/constants';
|
|
6
6
|
import { parseRawNumber, reformatAddress } from '@subwallet/extension-base/utils';
|
|
7
|
-
import { BN, BN_BILLION, BN_HUNDRED, BN_MILLION, BN_THOUSAND, BN_ZERO } from '@polkadot/util';
|
|
7
|
+
import { BN, BN_BILLION, BN_HUNDRED, BN_MILLION, BN_THOUSAND, BN_ZERO, bnToU8a, stringToU8a, u8aConcat } from '@polkadot/util';
|
|
8
8
|
export let PalletParachainStakingRequestType;
|
|
9
9
|
(function (PalletParachainStakingRequestType) {
|
|
10
10
|
PalletParachainStakingRequestType["REVOKE"] = "revoke";
|
|
11
11
|
PalletParachainStakingRequestType["DECREASE"] = "decrease";
|
|
12
12
|
PalletParachainStakingRequestType["BOND_LESS"] = "bondLess";
|
|
13
13
|
})(PalletParachainStakingRequestType || (PalletParachainStakingRequestType = {}));
|
|
14
|
+
export function parsePoolStashAddress(api, index, poolId, poolsPalletId) {
|
|
15
|
+
const ModPrefix = stringToU8a('modl');
|
|
16
|
+
const U32Opts = {
|
|
17
|
+
bitLength: 32,
|
|
18
|
+
isLe: true
|
|
19
|
+
};
|
|
20
|
+
const EmptyH256 = new Uint8Array(32);
|
|
21
|
+
return api.registry.createType('AccountId32', u8aConcat(ModPrefix, poolsPalletId, new Uint8Array([index]), bnToU8a(new BN(poolId.toString()), U32Opts), EmptyH256)).toString();
|
|
22
|
+
}
|
|
14
23
|
export function transformPoolName(input) {
|
|
15
24
|
return input.replace(/[^\x20-\x7E]/g, '');
|
|
16
25
|
}
|
|
@@ -130,7 +139,9 @@ export function getBondedValidators(nominations) {
|
|
|
130
139
|
export function isUnstakeAll(selectedValidator, nominations, unstakeAmount) {
|
|
131
140
|
let isUnstakeAll = false;
|
|
132
141
|
for (const nomination of nominations) {
|
|
133
|
-
|
|
142
|
+
const parsedValidatorAddress = reformatAddress(nomination.validatorAddress, 0);
|
|
143
|
+
const parsedSelectedValidator = reformatAddress(selectedValidator, 0);
|
|
144
|
+
if (parsedValidatorAddress === parsedSelectedValidator) {
|
|
134
145
|
if (unstakeAmount === nomination.activeStake) {
|
|
135
146
|
isUnstakeAll = true;
|
|
136
147
|
}
|
|
@@ -147,7 +158,20 @@ export let StakingAction;
|
|
|
147
158
|
StakingAction["CLAIM_REWARD"] = "CLAIM_REWARD";
|
|
148
159
|
StakingAction["CANCEL_UNSTAKE"] = "CANCEL_UNSTAKE";
|
|
149
160
|
})(StakingAction || (StakingAction = {}));
|
|
150
|
-
export function
|
|
161
|
+
export function getStakingAvailableActionsByChain(chain, type) {
|
|
162
|
+
if (type === StakingType.POOLED) {
|
|
163
|
+
return [StakingAction.STAKE, StakingAction.UNSTAKE, StakingAction.WITHDRAW, StakingAction.CLAIM_REWARD];
|
|
164
|
+
}
|
|
165
|
+
if (_STAKING_CHAIN_GROUP.para.includes(chain)) {
|
|
166
|
+
return [StakingAction.STAKE, StakingAction.UNSTAKE, StakingAction.WITHDRAW, StakingAction.CANCEL_UNSTAKE];
|
|
167
|
+
} else if (_STAKING_CHAIN_GROUP.astar.includes(chain)) {
|
|
168
|
+
return [StakingAction.STAKE, StakingAction.UNSTAKE, StakingAction.WITHDRAW, StakingAction.CLAIM_REWARD];
|
|
169
|
+
} else if (_STAKING_CHAIN_GROUP.amplitude.includes(chain)) {
|
|
170
|
+
return [StakingAction.STAKE, StakingAction.UNSTAKE, StakingAction.WITHDRAW];
|
|
171
|
+
}
|
|
172
|
+
return [StakingAction.STAKE, StakingAction.UNSTAKE, StakingAction.WITHDRAW, StakingAction.CANCEL_UNSTAKE];
|
|
173
|
+
}
|
|
174
|
+
export function getStakingAvailableActionsByNominator(nominatorMetadata) {
|
|
151
175
|
const result = [StakingAction.STAKE];
|
|
152
176
|
const bnActiveStake = new BN(nominatorMetadata.activeStake);
|
|
153
177
|
if (nominatorMetadata.activeStake && bnActiveStake.gt(BN_ZERO)) {
|
package/koni/api/xcm/index.js
CHANGED
|
@@ -27,115 +27,4 @@ export const createXcmExtrinsic = async ({
|
|
|
27
27
|
}
|
|
28
28
|
console.log('XCM extrinsic: ', extrinsic.toHex());
|
|
29
29
|
return extrinsic;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
// TODO: add + refine logic for more chains
|
|
33
|
-
// export function updateXcmResponseTxResult (
|
|
34
|
-
// networkKey: string,
|
|
35
|
-
// tokenInfo: _ChainAsset,
|
|
36
|
-
// response: TransactionResponse,
|
|
37
|
-
// records: EventRecord[]
|
|
38
|
-
// ) {
|
|
39
|
-
// if (!response.txResult) {
|
|
40
|
-
// response.txResult = { change: '0' };
|
|
41
|
-
// }
|
|
42
|
-
//
|
|
43
|
-
// let isFeeUseMainTokenSymbol = true;
|
|
44
|
-
//
|
|
45
|
-
// for (let index = 0; index < records.length; index++) {
|
|
46
|
-
// const record = records[index];
|
|
47
|
-
//
|
|
48
|
-
// if (_XCM_CHAIN_GROUP.acala.includes(networkKey) && !_isNativeToken(tokenInfo)) {
|
|
49
|
-
// if (record.event.section === 'currencies' &&
|
|
50
|
-
// record.event.method.toLowerCase() === 'transferred') {
|
|
51
|
-
// if (index === 0) {
|
|
52
|
-
// // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
53
|
-
// response.txResult.fee = record.event.data[3]?.toString() || '0';
|
|
54
|
-
// response.txResult.feeSymbol = tokenInfo.symbol;
|
|
55
|
-
//
|
|
56
|
-
// isFeeUseMainTokenSymbol = false;
|
|
57
|
-
// } else {
|
|
58
|
-
// response.txResult.change = record.event.data[3]?.toString() || '0';
|
|
59
|
-
// response.txResult.changeSymbol = tokenInfo.symbol;
|
|
60
|
-
// }
|
|
61
|
-
// }
|
|
62
|
-
//
|
|
63
|
-
// if (record.event.section === 'tokens' &&
|
|
64
|
-
// record.event.method.toLowerCase() === 'withdrawn') {
|
|
65
|
-
// response.txResult.change = record.event.data[2]?.toString() || '0';
|
|
66
|
-
// response.txResult.changeSymbol = tokenInfo.symbol;
|
|
67
|
-
// }
|
|
68
|
-
// } else if (_XCM_CHAIN_GROUP.kintsugi.includes(networkKey) && !_isNativeToken(tokenInfo)) {
|
|
69
|
-
// if (record.event.section === 'tokens' &&
|
|
70
|
-
// record.event.method.toLowerCase() === 'transfer') {
|
|
71
|
-
// response.txResult.change = record.event.data[3]?.toString() || '0';
|
|
72
|
-
// response.txResult.changeSymbol = tokenInfo.symbol;
|
|
73
|
-
// }
|
|
74
|
-
// } else if (_XCM_CHAIN_GROUP.genshiro.includes(networkKey) && !_isNativeToken(tokenInfo)) {
|
|
75
|
-
// if (record.event.section === 'eqBalances' &&
|
|
76
|
-
// record.event.method.toLowerCase() === 'transfer') {
|
|
77
|
-
// response.txResult.change = record.event.data[3]?.toString() || '0';
|
|
78
|
-
// response.txResult.changeSymbol = tokenInfo.symbol;
|
|
79
|
-
// }
|
|
80
|
-
// } else if (_XCM_CHAIN_GROUP.bifrost.includes(networkKey) && !_isNativeToken(tokenInfo)) {
|
|
81
|
-
// if (record.event.section === 'tokens' &&
|
|
82
|
-
// record.event.method.toLowerCase() === 'withdrawn') {
|
|
83
|
-
// response.txResult.change = record.event.data[2]?.toString() || '0';
|
|
84
|
-
// response.txResult.changeSymbol = tokenInfo.symbol;
|
|
85
|
-
// } else if (record.event.section === 'balances' &&
|
|
86
|
-
// record.event.method.toLowerCase() === 'transfer') {
|
|
87
|
-
// // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
88
|
-
// response.txResult.change = record.event.data[2]?.toString() || '0';
|
|
89
|
-
// response.txResult.changeSymbol = tokenInfo.symbol;
|
|
90
|
-
// }
|
|
91
|
-
// } else if (_XCM_CHAIN_GROUP.astar.includes(networkKey) && !_isNativeToken(tokenInfo)) {
|
|
92
|
-
// if (record.event.section === 'assets' &&
|
|
93
|
-
// record.event.method.toLowerCase() === 'burned') {
|
|
94
|
-
// response.txResult.change = record.event.data[2]?.toString() || '0';
|
|
95
|
-
// response.txResult.changeSymbol = tokenInfo.symbol;
|
|
96
|
-
// }
|
|
97
|
-
// } else if (_XCM_CHAIN_GROUP.moonbeam.includes(networkKey) && !_isNativeToken(tokenInfo)) {
|
|
98
|
-
// if (record.event.section === 'assets' &&
|
|
99
|
-
// record.event.method.toLowerCase() === 'burned') {
|
|
100
|
-
// response.txResult.change = record.event.data[2]?.toString() || '0';
|
|
101
|
-
// response.txResult.changeSymbol = tokenInfo.symbol;
|
|
102
|
-
// }
|
|
103
|
-
// } else if (_XCM_CHAIN_GROUP.statemine.includes(networkKey)) {
|
|
104
|
-
// if (!_isNativeToken(tokenInfo)) {
|
|
105
|
-
// if (record.event.section === 'assets' &&
|
|
106
|
-
// record.event.method.toLowerCase() === 'transferred') {
|
|
107
|
-
// response.txResult.change = record.event.data[3]?.toString() || '0';
|
|
108
|
-
// response.txResult.changeSymbol = tokenInfo.symbol;
|
|
109
|
-
// }
|
|
110
|
-
// } else {
|
|
111
|
-
// if (record.event.section === 'balances' &&
|
|
112
|
-
// record.event.method.toLowerCase() === 'withdraw') {
|
|
113
|
-
// response.txResult.change = record.event.data[1]?.toString() || '0';
|
|
114
|
-
// response.txResult.changeSymbol = tokenInfo.symbol;
|
|
115
|
-
// }
|
|
116
|
-
// }
|
|
117
|
-
// } else {
|
|
118
|
-
// if (record.event.section === 'balances' &&
|
|
119
|
-
// record.event.method.toLowerCase() === 'transfer') {
|
|
120
|
-
// // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
121
|
-
// response.txResult.change = record.event.data[2]?.toString() || '0';
|
|
122
|
-
// } else if (record.event.section === 'xTokens' &&
|
|
123
|
-
// record.event.method.toLowerCase() === 'transferred') {
|
|
124
|
-
// // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
125
|
-
// response.txResult.change = record.event.data[2]?.toString() || '0';
|
|
126
|
-
// }
|
|
127
|
-
// }
|
|
128
|
-
//
|
|
129
|
-
// if (isFeeUseMainTokenSymbol && record.event.section === 'balances' && record.event.method.toLowerCase() === 'withdraw') {
|
|
130
|
-
// if (!response.txResult.fee) {
|
|
131
|
-
// // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
132
|
-
// response.txResult.fee = record.event.data[1]?.toString() || '0';
|
|
133
|
-
// }
|
|
134
|
-
// } else if (isFeeUseMainTokenSymbol && record.event.section === 'tokens' && record.event.method.toLowerCase() === 'withdrawn') {
|
|
135
|
-
// if (!response.txResult.fee) {
|
|
136
|
-
// // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
137
|
-
// response.txResult.fee = record.event.data[2]?.toString() || '0';
|
|
138
|
-
// }
|
|
139
|
-
// }
|
|
140
|
-
// }
|
|
141
|
-
// }
|
|
30
|
+
};
|
|
@@ -42,7 +42,7 @@ export function getExtrinsicByPolkadotXcmPallet(tokenInfo, originChainInfo, dest
|
|
|
42
42
|
const assetLocation = getAssetLocation(tokenInfo, value);
|
|
43
43
|
let method = 'limitedReserveTransferAssets';
|
|
44
44
|
if (['astar', 'shiden'].includes(originChainInfo.slug)) {
|
|
45
|
-
method = '
|
|
45
|
+
method = 'limitedReserveWithdrawAssets';
|
|
46
46
|
} else if (_isSubstrateRelayChain(destinationChainInfo)) {
|
|
47
47
|
method = 'limitedTeleportAssets';
|
|
48
48
|
}
|
package/koni/api/xcm/xTokens.js
CHANGED
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
import { FOUR_INSTRUCTIONS_WEIGHT, getReceiverLocation, NETWORK_USE_UNLIMITED_WEIGHT, POLKADOT_UNLIMITED_WEIGHT } from '@subwallet/extension-base/koni/api/xcm/utils';
|
|
5
5
|
import { _XCM_TYPE } from '@subwallet/extension-base/services/chain-service/constants';
|
|
6
|
-
import { _getSubstrateParaId, _getXcmAssetId, _getXcmAssetMultilocation, _getXcmAssetType, _getXcmTransferType, _isNativeToken } from '@subwallet/extension-base/services/chain-service/utils';
|
|
6
|
+
import { _getSubstrateParaId, _getTokenOnChainInfo, _getXcmAssetId, _getXcmAssetMultilocation, _getXcmAssetType, _getXcmTransferType, _isNativeToken } from '@subwallet/extension-base/services/chain-service/utils';
|
|
7
7
|
function getCurrencyId(tokenInfo) {
|
|
8
|
-
var _tokenInfo$metadata2;
|
|
9
8
|
if (['acala', 'karura'].includes(tokenInfo.originChain) && _isNativeToken(tokenInfo)) {
|
|
10
9
|
return _getXcmAssetMultilocation(tokenInfo);
|
|
11
10
|
} else if (['moonbeam', 'moonbase', 'moonriver'].includes(tokenInfo.originChain)) {
|
|
@@ -15,10 +14,9 @@ function getCurrencyId(tokenInfo) {
|
|
|
15
14
|
[tokenType]: assetId
|
|
16
15
|
};
|
|
17
16
|
} else if (['pioneer'].includes(tokenInfo.originChain)) {
|
|
18
|
-
|
|
19
|
-
return (_tokenInfo$metadata = tokenInfo.metadata) === null || _tokenInfo$metadata === void 0 ? void 0 : _tokenInfo$metadata.multilocation;
|
|
17
|
+
return _getXcmAssetMultilocation(tokenInfo);
|
|
20
18
|
}
|
|
21
|
-
return (
|
|
19
|
+
return _getTokenOnChainInfo(tokenInfo);
|
|
22
20
|
}
|
|
23
21
|
function getMultiLocationForXtokensPallet(originChainInfo, destinationChainInfo, toAddress) {
|
|
24
22
|
const xcmType = _getXcmTransferType(originChainInfo, destinationChainInfo);
|
package/koni/background/cron.js
CHANGED
|
@@ -48,73 +48,74 @@ export class KoniCron {
|
|
|
48
48
|
});
|
|
49
49
|
};
|
|
50
50
|
init = () => {
|
|
51
|
-
this.state.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
});
|
|
51
|
+
const currentAccountInfo = this.state.keyringService.currentAccount;
|
|
52
|
+
if (!(currentAccountInfo !== null && currentAccountInfo !== void 0 && currentAccountInfo.address)) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (Object.keys(this.state.getSubstrateApiMap()).length !== 0 || Object.keys(this.state.getEvmApiMap()).length !== 0) {
|
|
56
|
+
this.refreshNft(currentAccountInfo.address, this.state.getApiMap(), this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap());
|
|
57
|
+
this.refreshStakingReward(currentAccountInfo.address);
|
|
58
|
+
this.refreshStakingRewardFastInterval(currentAccountInfo.address);
|
|
59
|
+
this.updateChainStakingMetadata(this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap());
|
|
60
|
+
this.updateNominatorMetadata(currentAccountInfo.address, this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap());
|
|
61
|
+
} else {
|
|
62
|
+
this.setStakingRewardReady();
|
|
63
|
+
}
|
|
65
64
|
};
|
|
66
65
|
start = () => {
|
|
67
66
|
if (this.status === 'running') {
|
|
68
67
|
return;
|
|
69
68
|
}
|
|
70
69
|
this.logger.log('Starting cron jobs');
|
|
71
|
-
this.state.
|
|
72
|
-
|
|
70
|
+
const currentAccountInfo = this.state.keyringService.currentAccount;
|
|
71
|
+
if (!(currentAccountInfo !== null && currentAccountInfo !== void 0 && currentAccountInfo.address)) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (Object.keys(this.state.getSubstrateApiMap()).length !== 0 || Object.keys(this.state.getEvmApiMap()).length !== 0) {
|
|
75
|
+
this.resetNft(currentAccountInfo.address);
|
|
76
|
+
this.addCron('refreshNft', this.refreshNft(currentAccountInfo.address, this.state.getApiMap(), this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap()), CRON_REFRESH_NFT_INTERVAL);
|
|
77
|
+
this.addCron('recoverApiMap', this.recoverApiMap, CRON_AUTO_RECOVER_DOTSAMA_INTERVAL, false);
|
|
78
|
+
this.addCron('refreshStakingReward', this.refreshStakingReward(currentAccountInfo.address), CRON_REFRESH_STAKING_REWARD_INTERVAL);
|
|
79
|
+
this.addCron('refreshPoolingStakingReward', this.refreshStakingRewardFastInterval(currentAccountInfo.address), CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL);
|
|
80
|
+
this.addCron('updateChainStakingMetadata', this.updateChainStakingMetadata(this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap()), CRON_REFRESH_CHAIN_STAKING_METADATA);
|
|
81
|
+
this.addCron('updateNominatorMetadata', this.updateNominatorMetadata(currentAccountInfo.address, this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap()), CRON_REFRESH_CHAIN_NOMINATOR_METADATA);
|
|
82
|
+
} else {
|
|
83
|
+
this.setStakingRewardReady();
|
|
84
|
+
}
|
|
85
|
+
const reloadEvents = ['account.add', 'account.remove', 'account.updateCurrent', 'chain.add', 'chain.update', 'chain.enable', 'asset.update', 'asset.enable', 'transaction.done', 'transaction.failed'];
|
|
86
|
+
this.state.eventService.onLazy((events, eventTypes) => {
|
|
87
|
+
var _serviceInfo$currentA;
|
|
88
|
+
const serviceInfo = this.state.getServiceInfo();
|
|
89
|
+
const needReload = eventTypes.some(eT => reloadEvents.includes(eT));
|
|
90
|
+
if (!needReload) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
this.logger.log('ServiceInfo updated, restarting...');
|
|
94
|
+
const address = (_serviceInfo$currentA = serviceInfo.currentAccountInfo) === null || _serviceInfo$currentA === void 0 ? void 0 : _serviceInfo$currentA.address;
|
|
95
|
+
if (!address) {
|
|
73
96
|
return;
|
|
74
97
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
98
|
+
this.resetStakingReward();
|
|
99
|
+
this.resetNft(address);
|
|
100
|
+
this.removeCron('refreshNft');
|
|
101
|
+
this.removeCron('refreshStakingReward');
|
|
102
|
+
this.removeCron('refreshPoolingStakingReward');
|
|
103
|
+
this.removeCron('checkStatusApiMap');
|
|
104
|
+
this.removeCron('recoverApiMap');
|
|
105
|
+
this.removeCron('updateChainStakingMetadata');
|
|
106
|
+
this.removeCron('updateNominatorMetadata');
|
|
107
|
+
if (this.checkNetworkAvailable(serviceInfo)) {
|
|
108
|
+
// only add cron job if there's at least 1 active network
|
|
109
|
+
this.addCron('refreshNft', this.refreshNft(address, serviceInfo.chainApiMap, this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap()), CRON_REFRESH_NFT_INTERVAL);
|
|
78
110
|
this.addCron('recoverApiMap', this.recoverApiMap, CRON_AUTO_RECOVER_DOTSAMA_INTERVAL, false);
|
|
79
|
-
this.addCron('refreshStakingReward', this.refreshStakingReward(
|
|
80
|
-
this.addCron('refreshPoolingStakingReward', this.refreshStakingRewardFastInterval(
|
|
81
|
-
this.addCron('updateChainStakingMetadata', this.updateChainStakingMetadata(
|
|
82
|
-
this.addCron('updateNominatorMetadata', this.updateNominatorMetadata(
|
|
111
|
+
this.addCron('refreshStakingReward', this.refreshStakingReward(address), CRON_REFRESH_STAKING_REWARD_INTERVAL);
|
|
112
|
+
this.addCron('refreshPoolingStakingReward', this.refreshStakingRewardFastInterval(address), CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL);
|
|
113
|
+
this.addCron('updateChainStakingMetadata', this.updateChainStakingMetadata(serviceInfo.chainInfoMap, serviceInfo.chainStateMap, serviceInfo.chainApiMap.substrate), CRON_REFRESH_CHAIN_STAKING_METADATA);
|
|
114
|
+
this.addCron('updateNominatorMetadata', this.updateNominatorMetadata(address, serviceInfo.chainInfoMap, serviceInfo.chainStateMap, serviceInfo.chainApiMap.substrate), CRON_REFRESH_CHAIN_NOMINATOR_METADATA);
|
|
83
115
|
} else {
|
|
84
116
|
this.setStakingRewardReady();
|
|
85
117
|
}
|
|
86
118
|
});
|
|
87
|
-
this.serviceSubscription = this.state.subscribeServiceInfo().subscribe({
|
|
88
|
-
next: serviceInfo => {
|
|
89
|
-
var _serviceInfo$currentA;
|
|
90
|
-
this.logger.log('ServiceInfo updated, restarting...');
|
|
91
|
-
const address = (_serviceInfo$currentA = serviceInfo.currentAccountInfo) === null || _serviceInfo$currentA === void 0 ? void 0 : _serviceInfo$currentA.address;
|
|
92
|
-
if (!address) {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
this.resetStakingReward();
|
|
96
|
-
this.resetNft(address);
|
|
97
|
-
this.removeCron('refreshNft');
|
|
98
|
-
this.removeCron('refreshStakingReward');
|
|
99
|
-
this.removeCron('refreshPoolingStakingReward');
|
|
100
|
-
this.removeCron('refreshPrice');
|
|
101
|
-
this.removeCron('checkStatusApiMap');
|
|
102
|
-
this.removeCron('recoverApiMap');
|
|
103
|
-
this.removeCron('updateChainStakingMetadata');
|
|
104
|
-
this.removeCron('updateNominatorMetadata');
|
|
105
|
-
if (this.checkNetworkAvailable(serviceInfo)) {
|
|
106
|
-
// only add cron job if there's at least 1 active network
|
|
107
|
-
this.addCron('refreshNft', this.refreshNft(address, serviceInfo.chainApiMap, this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap()), CRON_REFRESH_NFT_INTERVAL);
|
|
108
|
-
this.addCron('recoverApiMap', this.recoverApiMap, CRON_AUTO_RECOVER_DOTSAMA_INTERVAL, false);
|
|
109
|
-
this.addCron('refreshStakingReward', this.refreshStakingReward(address), CRON_REFRESH_STAKING_REWARD_INTERVAL);
|
|
110
|
-
this.addCron('refreshPoolingStakingReward', this.refreshStakingRewardFastInterval(address), CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL);
|
|
111
|
-
this.addCron('updateChainStakingMetadata', this.updateChainStakingMetadata(serviceInfo.chainInfoMap, serviceInfo.chainStateMap, serviceInfo.chainApiMap.substrate), CRON_REFRESH_CHAIN_STAKING_METADATA);
|
|
112
|
-
this.addCron('updateNominatorMetadata', this.updateNominatorMetadata(address, serviceInfo.chainInfoMap, serviceInfo.chainStateMap, serviceInfo.chainApiMap.substrate), CRON_REFRESH_CHAIN_NOMINATOR_METADATA);
|
|
113
|
-
} else {
|
|
114
|
-
this.setStakingRewardReady();
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
119
|
this.status = 'running';
|
|
119
120
|
};
|
|
120
121
|
stop = () => {
|
|
@@ -130,6 +131,7 @@ export class KoniCron {
|
|
|
130
131
|
this.status = 'stopped';
|
|
131
132
|
};
|
|
132
133
|
recoverApiMap = () => {
|
|
134
|
+
var _this$subscriptions;
|
|
133
135
|
const apiMap = this.state.getApiMap();
|
|
134
136
|
for (const [networkKey, apiProp] of Object.entries(apiMap.substrate)) {
|
|
135
137
|
if (!apiProp.isApiConnected) {
|
|
@@ -141,12 +143,10 @@ export class KoniCron {
|
|
|
141
143
|
this.state.refreshWeb3Api(key);
|
|
142
144
|
});
|
|
143
145
|
}
|
|
144
|
-
|
|
146
|
+
const {
|
|
145
147
|
address
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
((_this$subscriptions = this.subscriptions) === null || _this$subscriptions === void 0 ? void 0 : _this$subscriptions.subscribeBalancesAndCrowdloans) && this.subscriptions.subscribeBalancesAndCrowdloans(address, this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap(), this.state.getEvmApiMap());
|
|
149
|
-
});
|
|
148
|
+
} = this.state.keyringService.currentAccount;
|
|
149
|
+
((_this$subscriptions = this.subscriptions) === null || _this$subscriptions === void 0 ? void 0 : _this$subscriptions.subscribeBalancesAndCrowdloans) && this.subscriptions.subscribeBalancesAndCrowdloans(address, this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap(), this.state.getEvmApiMap());
|
|
150
150
|
};
|
|
151
151
|
refreshNft = (address, apiMap, smartContractNfts, chainInfoMap) => {
|
|
152
152
|
return () => {
|
|
@@ -156,7 +156,7 @@ export class KoniCron {
|
|
|
156
156
|
};
|
|
157
157
|
resetNft = newAddress => {
|
|
158
158
|
this.logger.log('Reset Nft state');
|
|
159
|
-
this.state.resetNft(newAddress)
|
|
159
|
+
this.state.resetNft(newAddress);
|
|
160
160
|
};
|
|
161
161
|
resetStakingReward = () => {
|
|
162
162
|
this.logger.log('Reset Staking Reward State');
|