@subwallet/extension-base 1.1.40-1 → 1.1.42-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 +3 -1
- package/cjs/constants/index.js +1 -1
- package/cjs/koni/api/dotsama/transfer.js +1 -1
- package/cjs/koni/api/nft/bit.country/index.js +2 -0
- package/cjs/koni/api/nft/config.js +3 -1
- package/cjs/koni/api/tokens/evm/transfer.js +4 -4
- package/cjs/koni/background/handlers/Extension.js +32 -17
- package/cjs/koni/background/handlers/State.js +42 -10
- package/cjs/packageInfo.js +1 -1
- package/cjs/page/SubWalleEvmProvider.js +5 -9
- package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +58 -0
- package/cjs/services/chain-service/constants.js +11 -7
- package/cjs/services/chain-service/handler/chain-spec/goldberg.js +75 -8
- package/cjs/services/chain-service/index.js +88 -79
- package/cjs/services/chain-service/utils.js +11 -6
- package/cjs/services/earning-service/constants/chains.js +10 -5
- package/cjs/services/earning-service/handlers/liquid-staking/acala.js +9 -3
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +8 -1
- package/cjs/services/earning-service/handlers/liquid-staking/parallel.js +6 -1
- package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +25 -17
- package/cjs/services/earning-service/handlers/native-staking/amplitude.js +4 -0
- package/cjs/services/earning-service/handlers/native-staking/astar.js +6 -2
- package/cjs/services/earning-service/handlers/native-staking/para-chain.js +144 -45
- package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +14 -16
- package/cjs/services/earning-service/handlers/nomination-pool/index.js +9 -11
- package/cjs/services/earning-service/handlers/special.js +2 -0
- package/cjs/services/earning-service/service.js +51 -18
- package/cjs/services/fee-service/service.js +70 -0
- package/cjs/services/fee-service/utils/index.js +209 -0
- package/cjs/services/migration-service/scripts/DeleteChainStaking.js +23 -0
- package/cjs/services/migration-service/scripts/databases/MigrateAssetSetting.js +50 -0
- package/cjs/services/migration-service/scripts/index.js +6 -1
- package/cjs/services/transaction-service/index.js +37 -37
- package/cjs/types/fee/index.js +1 -0
- package/cjs/types/index.js +11 -0
- package/cjs/utils/eth.js +2 -105
- package/cjs/utils/index.js +12 -0
- package/cjs/utils/reportError.js +31 -0
- package/constants/index.d.ts +1 -1
- package/constants/index.js +1 -1
- package/koni/api/dotsama/transfer.js +1 -1
- package/koni/api/nft/bit.country/index.js +3 -1
- package/koni/api/nft/config.d.ts +1 -0
- package/koni/api/nft/config.js +1 -0
- package/koni/api/tokens/evm/transfer.js +1 -1
- package/koni/background/handlers/Extension.d.ts +1 -0
- package/koni/background/handlers/Extension.js +18 -3
- package/koni/background/handlers/State.d.ts +4 -1
- package/koni/background/handlers/State.js +33 -2
- package/package.json +36 -6
- package/packageInfo.js +1 -1
- package/page/SubWalleEvmProvider.d.ts +0 -1
- package/page/SubWalleEvmProvider.js +5 -9
- package/services/balance-service/helpers/subscribe/substrate/index.js +59 -1
- package/services/chain-service/constants.d.ts +2 -0
- package/services/chain-service/constants.js +11 -7
- package/services/chain-service/handler/chain-spec/goldberg.d.ts +70 -1
- package/services/chain-service/handler/chain-spec/goldberg.js +75 -8
- package/services/chain-service/index.d.ts +8 -4
- package/services/chain-service/index.js +74 -67
- package/services/chain-service/types.d.ts +4 -0
- package/services/chain-service/utils.d.ts +1 -0
- package/services/chain-service/utils.js +10 -6
- package/services/earning-service/constants/chains.d.ts +3 -0
- package/services/earning-service/constants/chains.js +7 -4
- package/services/earning-service/handlers/liquid-staking/acala.js +9 -3
- package/services/earning-service/handlers/liquid-staking/bifrost.js +8 -1
- package/services/earning-service/handlers/liquid-staking/parallel.d.ts +1 -1
- package/services/earning-service/handlers/liquid-staking/parallel.js +6 -1
- package/services/earning-service/handlers/liquid-staking/stella-swap.js +25 -17
- package/services/earning-service/handlers/native-staking/amplitude.js +4 -0
- package/services/earning-service/handlers/native-staking/astar.js +6 -2
- package/services/earning-service/handlers/native-staking/para-chain.js +144 -45
- package/services/earning-service/handlers/native-staking/relay-chain.js +15 -17
- package/services/earning-service/handlers/nomination-pool/index.js +10 -12
- package/services/earning-service/handlers/special.d.ts +1 -0
- package/services/earning-service/handlers/special.js +2 -0
- package/services/earning-service/service.d.ts +4 -1
- package/services/earning-service/service.js +52 -19
- package/services/fee-service/service.d.ts +12 -0
- package/services/fee-service/service.js +63 -0
- package/services/fee-service/utils/index.d.ts +8 -0
- package/services/fee-service/utils/index.js +193 -0
- package/services/migration-service/scripts/DeleteChainStaking.d.ts +4 -0
- package/services/migration-service/scripts/DeleteChainStaking.js +15 -0
- package/services/migration-service/scripts/databases/MigrateAssetSetting.d.ts +4 -0
- package/services/migration-service/scripts/databases/MigrateAssetSetting.js +42 -0
- package/services/migration-service/scripts/index.js +5 -1
- package/services/transaction-service/index.js +2 -2
- package/types/fee/index.d.ts +49 -0
- package/types/fee/index.js +1 -0
- package/types/index.d.ts +1 -0
- package/types/index.js +1 -0
- package/types/yield/info/account/unstake.d.ts +2 -0
- package/types/yield/info/pallet.d.ts +4 -0
- package/utils/eth.d.ts +0 -15
- package/utils/eth.js +0 -101
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/utils/reportError.d.ts +1 -0
- package/utils/reportError.js +23 -0
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
5
|
-
import { BasicTxErrorType } from '@subwallet/extension-base/background/KoniTypes';
|
|
5
|
+
import { BasicTxErrorType, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
6
6
|
import { CRON_REFRESH_CHAIN_STAKING_METADATA, CRON_REFRESH_EARNING_REWARD_HISTORY_INTERVAL, CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL } from '@subwallet/extension-base/constants';
|
|
7
7
|
import { ServiceStatus } from '@subwallet/extension-base/services/base/types';
|
|
8
8
|
import { _isChainEnabled, _isChainEvmCompatible } from '@subwallet/extension-base/services/chain-service/utils';
|
|
@@ -33,11 +33,15 @@ export default class EarningService {
|
|
|
33
33
|
yieldPositionSubject = new BehaviorSubject({});
|
|
34
34
|
yieldPositionListSubject = new BehaviorSubject([]); // virtual list of yieldPositionSubject with filter values
|
|
35
35
|
|
|
36
|
+
useOnlineCacheOnly = true;
|
|
36
37
|
constructor(state) {
|
|
37
38
|
this.state = state;
|
|
38
39
|
this.dbService = state.dbService;
|
|
39
40
|
this.eventService = state.eventService;
|
|
40
41
|
}
|
|
42
|
+
disableOnlineCacheOnly() {
|
|
43
|
+
this.useOnlineCacheOnly = false;
|
|
44
|
+
}
|
|
41
45
|
async initHandlers() {
|
|
42
46
|
await this.eventService.waitChainReady;
|
|
43
47
|
const chains = [];
|
|
@@ -125,6 +129,7 @@ export default class EarningService {
|
|
|
125
129
|
}
|
|
126
130
|
handleActions() {
|
|
127
131
|
this.eventService.onLazy((events, eventTypes) => {
|
|
132
|
+
let delayReload = false;
|
|
128
133
|
(async () => {
|
|
129
134
|
const removedAddresses = [];
|
|
130
135
|
const removeChains = [];
|
|
@@ -138,6 +143,13 @@ export default class EarningService {
|
|
|
138
143
|
removeChains.push(event.data[0]);
|
|
139
144
|
}
|
|
140
145
|
}
|
|
146
|
+
if (event.type === 'transaction.done') {
|
|
147
|
+
const transactionData = event.data[0];
|
|
148
|
+
const notRequireReloadTypes = [ExtrinsicType.TRANSFER_BALANCE, ExtrinsicType.TRANSFER_TOKEN, ExtrinsicType.TRANSFER_XCM, ExtrinsicType.SEND_NFT, ExtrinsicType.CROWDLOAN];
|
|
149
|
+
if (notRequireReloadTypes.indexOf(transactionData.extrinsicType) === -1) {
|
|
150
|
+
delayReload = true;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
141
153
|
});
|
|
142
154
|
if (removeChains.length || removedAddresses.length) {
|
|
143
155
|
await this.removeYieldPositions(removeChains, removedAddresses);
|
|
@@ -146,8 +158,16 @@ export default class EarningService {
|
|
|
146
158
|
// Account changed or chain changed (active or inactive)
|
|
147
159
|
// Chain changed (active or inactive)
|
|
148
160
|
// Todo: Optimize performance of chain active or inactive in the future
|
|
149
|
-
if (eventTypes.includes('account.updateCurrent') || eventTypes.includes('account.remove') || eventTypes.includes('chain.updateState')) {
|
|
150
|
-
|
|
161
|
+
if (eventTypes.includes('account.updateCurrent') || eventTypes.includes('account.remove') || eventTypes.includes('chain.updateState') || delayReload) {
|
|
162
|
+
if (delayReload) {
|
|
163
|
+
this.delayReloadTimeout = setTimeout(() => {
|
|
164
|
+
this.reloadEarning().catch(console.error); // Timeout is removed inside reloadEarning > runUnsubscribePoolsPosition
|
|
165
|
+
}, 3000);
|
|
166
|
+
} else {
|
|
167
|
+
this.delayReloadTimeout && clearTimeout(this.delayReloadTimeout);
|
|
168
|
+
this.delayReloadTimeout = undefined;
|
|
169
|
+
await this.reloadEarning();
|
|
170
|
+
}
|
|
151
171
|
}
|
|
152
172
|
})().catch(console.error);
|
|
153
173
|
});
|
|
@@ -241,20 +261,25 @@ export default class EarningService {
|
|
|
241
261
|
}
|
|
242
262
|
async getYieldPool(slug) {
|
|
243
263
|
await this.eventService.waitEarningReady;
|
|
244
|
-
|
|
264
|
+
const poolInfoMap = this.yieldPoolInfoSubject.getValue();
|
|
265
|
+
return poolInfoMap[slug];
|
|
245
266
|
}
|
|
246
|
-
async subscribePoolsInfo(callback) {
|
|
267
|
+
async subscribePoolsInfo(onlineData, callback) {
|
|
247
268
|
let cancel = false;
|
|
248
269
|
await this.eventService.waitChainReady;
|
|
249
270
|
const unsubList = [];
|
|
250
271
|
for (const handler of Object.values(this.handlers)) {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
272
|
+
// Force subscribe onchain data
|
|
273
|
+
const forceSubscribe = handler.type === YieldPoolType.LIQUID_STAKING || handler.type === YieldPoolType.LENDING;
|
|
274
|
+
if (!this.useOnlineCacheOnly || forceSubscribe) {
|
|
275
|
+
handler.subscribePoolInfo(callback).then(unsub => {
|
|
276
|
+
if (!cancel) {
|
|
277
|
+
unsubList.push(unsub);
|
|
278
|
+
} else {
|
|
279
|
+
unsub();
|
|
280
|
+
}
|
|
281
|
+
}).catch(console.error);
|
|
282
|
+
}
|
|
258
283
|
}
|
|
259
284
|
return () => {
|
|
260
285
|
cancel = true;
|
|
@@ -306,19 +331,20 @@ export default class EarningService {
|
|
|
306
331
|
Object.values(onlineData).forEach(item => {
|
|
307
332
|
this.updateYieldPoolInfo(item);
|
|
308
333
|
});
|
|
334
|
+
return onlineData;
|
|
309
335
|
}
|
|
310
336
|
async runSubscribePoolsInfo() {
|
|
311
337
|
await this.eventService.waitChainReady;
|
|
312
338
|
this.runUnsubscribePoolsInfo();
|
|
313
339
|
|
|
314
340
|
// Fetching online data
|
|
315
|
-
this.fetchingPoolsInfoOnline()
|
|
341
|
+
const onlineData = await this.fetchingPoolsInfoOnline();
|
|
316
342
|
const interval = setInterval(() => {
|
|
317
343
|
this.fetchingPoolsInfoOnline().catch(console.error);
|
|
318
344
|
}, CRON_REFRESH_CHAIN_STAKING_METADATA);
|
|
319
345
|
|
|
320
346
|
// Fetching from chains
|
|
321
|
-
this.subscribePoolsInfo(data => {
|
|
347
|
+
this.subscribePoolsInfo(onlineData, data => {
|
|
322
348
|
data.lastUpdated = Date.now();
|
|
323
349
|
this.updateYieldPoolInfo(data);
|
|
324
350
|
}).then(rs => {
|
|
@@ -460,6 +486,10 @@ export default class EarningService {
|
|
|
460
486
|
(_this$yieldPositionUn = this.yieldPositionUnsub) === null || _this$yieldPositionUn === void 0 ? void 0 : _this$yieldPositionUn.call(this);
|
|
461
487
|
removeLazy('persistYieldPositionInfo');
|
|
462
488
|
this.yieldPositionPersistQueue = [];
|
|
489
|
+
|
|
490
|
+
// Remove delay reload
|
|
491
|
+
this.delayReloadTimeout && clearTimeout(this.delayReloadTimeout);
|
|
492
|
+
this.delayReloadTimeout = undefined;
|
|
463
493
|
}
|
|
464
494
|
|
|
465
495
|
/* Pools' position methods */
|
|
@@ -608,13 +638,16 @@ export default class EarningService {
|
|
|
608
638
|
* @return {Promise<YieldPoolTarget[]>} List of pool's target
|
|
609
639
|
* */
|
|
610
640
|
async getPoolTargets(slug) {
|
|
611
|
-
|
|
641
|
+
let targets = [];
|
|
642
|
+
if (this.useOnlineCacheOnly) {
|
|
643
|
+
targets = await fetchStaticCache(`earning/targets/${slug}.json`, []);
|
|
644
|
+
}
|
|
612
645
|
const handler = this.getPoolHandler(slug);
|
|
613
|
-
if (handler) {
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
return [];
|
|
646
|
+
if (!targets.length && handler) {
|
|
647
|
+
await this.eventService.waitChainReady;
|
|
648
|
+
targets = await handler.getPoolTargets();
|
|
617
649
|
}
|
|
650
|
+
return targets;
|
|
618
651
|
}
|
|
619
652
|
|
|
620
653
|
/* Get pool's targets */
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import KoniState from '@subwallet/extension-base/koni/background/handlers/State';
|
|
2
|
+
import { EvmFeeInfo } from '@subwallet/extension-base/types';
|
|
3
|
+
export default class FeeService {
|
|
4
|
+
protected readonly state: KoniState;
|
|
5
|
+
private evmFeeSubject;
|
|
6
|
+
private useInfura;
|
|
7
|
+
constructor(state: KoniState);
|
|
8
|
+
changeMode(useInfura: boolean): void;
|
|
9
|
+
private updateFees;
|
|
10
|
+
private updateChainFee;
|
|
11
|
+
subscribeFees(callback: (data: Record<string, EvmFeeInfo>) => void): () => void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { _isChainEvmCompatible } from '@subwallet/extension-base/services/chain-service/utils';
|
|
5
|
+
import { calculateGasFeeParams } from '@subwallet/extension-base/services/fee-service/utils';
|
|
6
|
+
import { BehaviorSubject } from 'rxjs';
|
|
7
|
+
export default class FeeService {
|
|
8
|
+
evmFeeSubject = new BehaviorSubject({});
|
|
9
|
+
constructor(state) {
|
|
10
|
+
this.state = state;
|
|
11
|
+
this.useInfura = true;
|
|
12
|
+
}
|
|
13
|
+
changeMode(useInfura) {
|
|
14
|
+
this.useInfura = useInfura;
|
|
15
|
+
}
|
|
16
|
+
async updateFees() {
|
|
17
|
+
await this.state.eventService.waitChainReady;
|
|
18
|
+
const activeNetworks = this.state.activeNetworks;
|
|
19
|
+
const chains = Object.values(activeNetworks).filter(chainInfo => _isChainEvmCompatible(chainInfo)).map(chainInfo => chainInfo.slug);
|
|
20
|
+
const promises = [];
|
|
21
|
+
for (const chain of chains) {
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises,no-async-promise-executor
|
|
23
|
+
const promise = new Promise(async resolve => {
|
|
24
|
+
const api = this.state.getEvmApi(chain);
|
|
25
|
+
const result = await calculateGasFeeParams(api, chain, this.useInfura);
|
|
26
|
+
this.updateChainFee(chain, result);
|
|
27
|
+
resolve();
|
|
28
|
+
});
|
|
29
|
+
promises.push(promise);
|
|
30
|
+
}
|
|
31
|
+
await Promise.all(promises);
|
|
32
|
+
}
|
|
33
|
+
updateChainFee(chain, info) {
|
|
34
|
+
const rs = Object.assign({}, this.evmFeeSubject.getValue());
|
|
35
|
+
rs[chain] = info;
|
|
36
|
+
this.evmFeeSubject.next(rs);
|
|
37
|
+
}
|
|
38
|
+
subscribeFees(callback) {
|
|
39
|
+
let cancel = false;
|
|
40
|
+
|
|
41
|
+
// eslint-disable-next-line prefer-const
|
|
42
|
+
|
|
43
|
+
const fetchData = () => {
|
|
44
|
+
this.updateFees().finally(() => {
|
|
45
|
+
if (!cancel) {
|
|
46
|
+
callback(this.evmFeeSubject.getValue());
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
fetchData();
|
|
51
|
+
const interval = setInterval(() => {
|
|
52
|
+
if (cancel) {
|
|
53
|
+
clearInterval(interval);
|
|
54
|
+
} else {
|
|
55
|
+
fetchData();
|
|
56
|
+
}
|
|
57
|
+
}, 30 * 1000);
|
|
58
|
+
return () => {
|
|
59
|
+
cancel = true;
|
|
60
|
+
clearInterval(interval);
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { _EvmApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
2
|
+
import { EvmFeeInfo, InfuraFeeInfo } from '@subwallet/extension-base/types';
|
|
3
|
+
export declare const parseInfuraFee: (info: InfuraFeeInfo) => EvmFeeInfo;
|
|
4
|
+
export declare const fetchInfuraFeeData: (chainId: number, infuraAuth?: string) => Promise<EvmFeeInfo | null>;
|
|
5
|
+
export declare const fetchSubWalletFeeData: (chainId: number, networkKey: string) => Promise<EvmFeeInfo | null>;
|
|
6
|
+
export declare const fetchOnlineFeeData: (chainId: number, networkKey: string, useInfura?: boolean) => Promise<EvmFeeInfo | null>;
|
|
7
|
+
export declare const recalculateGasPrice: (_price: string, chain: string) => string;
|
|
8
|
+
export declare const calculateGasFeeParams: (web3: _EvmApi, networkKey: string, useOnline?: boolean, useInfura?: boolean) => Promise<EvmFeeInfo>;
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { GAS_PRICE_RATIO, NETWORK_MULTI_GAS_FEE } from '@subwallet/extension-base/constants';
|
|
5
|
+
import { BN_WEI, BN_ZERO } from '@subwallet/extension-base/utils';
|
|
6
|
+
import BigN from 'bignumber.js';
|
|
7
|
+
const INFURA_API_KEY = process.env.INFURA_API_KEY || '';
|
|
8
|
+
const INFURA_API_KEY_SECRET = process.env.INFURA_API_KEY_SECRET || '';
|
|
9
|
+
const INFURA_AUTH = 'Basic ' + Buffer.from(INFURA_API_KEY + ':' + INFURA_API_KEY_SECRET).toString('base64');
|
|
10
|
+
export const parseInfuraFee = info => {
|
|
11
|
+
const base = new BigN(info.estimatedBaseFee).multipliedBy(BN_WEI);
|
|
12
|
+
const low = new BigN(info.low.suggestedMaxPriorityFeePerGas).multipliedBy(BN_WEI);
|
|
13
|
+
const busyNetwork = base.gt(BN_ZERO) ? low.dividedBy(base).gte(0.3) : false;
|
|
14
|
+
const data = !busyNetwork ? info.low : info.medium;
|
|
15
|
+
return {
|
|
16
|
+
busyNetwork,
|
|
17
|
+
gasPrice: undefined,
|
|
18
|
+
baseGasFee: base,
|
|
19
|
+
maxFeePerGas: new BigN(data.suggestedMaxFeePerGas).multipliedBy(BN_WEI).integerValue(BigN.ROUND_UP),
|
|
20
|
+
maxPriorityFeePerGas: new BigN(data.suggestedMaxPriorityFeePerGas).multipliedBy(BN_WEI).integerValue(BigN.ROUND_UP)
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
export const fetchInfuraFeeData = async (chainId, infuraAuth) => {
|
|
24
|
+
return await new Promise(resolve => {
|
|
25
|
+
const baseUrl = 'https://gas.api.infura.io/networks/{{chainId}}/suggestedGasFees';
|
|
26
|
+
const url = baseUrl.replaceAll('{{chainId}}', chainId.toString());
|
|
27
|
+
fetch(url, {
|
|
28
|
+
method: 'GET',
|
|
29
|
+
headers: {
|
|
30
|
+
Authorization: infuraAuth || INFURA_AUTH
|
|
31
|
+
}
|
|
32
|
+
}).then(rs => {
|
|
33
|
+
return rs.json();
|
|
34
|
+
}).then(info => {
|
|
35
|
+
resolve(parseInfuraFee(info));
|
|
36
|
+
}).catch(e => {
|
|
37
|
+
console.warn(e);
|
|
38
|
+
resolve(null);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
export const fetchSubWalletFeeData = async (chainId, networkKey) => {
|
|
43
|
+
return await new Promise(resolve => {
|
|
44
|
+
const baseUrl = 'https://api-cache.subwallet.app/sw-evm-gas/{{chain}}';
|
|
45
|
+
const url = baseUrl.replaceAll('{{chain}}', networkKey);
|
|
46
|
+
fetch(url, {
|
|
47
|
+
method: 'GET'
|
|
48
|
+
}).then(rs => {
|
|
49
|
+
return rs.json();
|
|
50
|
+
}).then(info => {
|
|
51
|
+
if (info.gasPrice !== undefined) {
|
|
52
|
+
resolve(info);
|
|
53
|
+
} else {
|
|
54
|
+
resolve({
|
|
55
|
+
busyNetwork: info.busyNetwork,
|
|
56
|
+
gasPrice: info.gasPrice,
|
|
57
|
+
baseGasFee: new BigN(info.baseGasFee),
|
|
58
|
+
maxFeePerGas: new BigN(info.maxFeePerGas),
|
|
59
|
+
maxPriorityFeePerGas: new BigN(info.maxPriorityFeePerGas)
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}).catch(e => {
|
|
63
|
+
console.warn(e);
|
|
64
|
+
resolve(null);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
export const fetchOnlineFeeData = async (chainId, networkKey, useInfura = false) => {
|
|
69
|
+
return await new Promise(resolve => {
|
|
70
|
+
const fetchFunction = useInfura ? fetchInfuraFeeData : fetchSubWalletFeeData;
|
|
71
|
+
fetchFunction(chainId, networkKey).then(info => {
|
|
72
|
+
resolve(info);
|
|
73
|
+
}).catch(e => {
|
|
74
|
+
console.warn(e);
|
|
75
|
+
resolve(null);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
export const recalculateGasPrice = (_price, chain) => {
|
|
80
|
+
const needMulti = NETWORK_MULTI_GAS_FEE.includes(chain) || NETWORK_MULTI_GAS_FEE.includes('*');
|
|
81
|
+
return needMulti ? new BigN(_price).multipliedBy(GAS_PRICE_RATIO).toFixed(0) : _price;
|
|
82
|
+
};
|
|
83
|
+
export const calculateGasFeeParams = async (web3, networkKey, useOnline = true, useInfura = false) => {
|
|
84
|
+
if (useOnline) {
|
|
85
|
+
try {
|
|
86
|
+
const chainId = await web3.api.eth.getChainId();
|
|
87
|
+
const onlineData = await fetchOnlineFeeData(chainId, networkKey, useInfura);
|
|
88
|
+
if (onlineData) {
|
|
89
|
+
return onlineData;
|
|
90
|
+
}
|
|
91
|
+
} catch (e) {}
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
const numBlock = 20;
|
|
95
|
+
const rewardPercent = [];
|
|
96
|
+
for (let i = 0; i <= 100; i = i + 5) {
|
|
97
|
+
rewardPercent.push(i);
|
|
98
|
+
}
|
|
99
|
+
const history = await web3.api.eth.getFeeHistory(numBlock, 'latest', rewardPercent);
|
|
100
|
+
const baseGasFee = new BigN(history.baseFeePerGas[history.baseFeePerGas.length - 1]); // Last element is latest
|
|
101
|
+
|
|
102
|
+
const blocksBusy = history.reward.reduce((previous, rewards, currentIndex) => {
|
|
103
|
+
const [firstPriority] = rewards;
|
|
104
|
+
const base = history.baseFeePerGas[currentIndex];
|
|
105
|
+
const priorityBN = new BigN(firstPriority);
|
|
106
|
+
const baseBN = new BigN(base);
|
|
107
|
+
|
|
108
|
+
/*
|
|
109
|
+
* True if priority >= 0.3 * base
|
|
110
|
+
* */
|
|
111
|
+
const blockIsBusy = baseBN.gt(BN_ZERO) ? priorityBN.dividedBy(baseBN).gte(0.3) ? 1 : 0 : 0; // Special for bsc, base fee = 0
|
|
112
|
+
|
|
113
|
+
return previous + blockIsBusy;
|
|
114
|
+
}, 0);
|
|
115
|
+
const busyNetwork = blocksBusy >= numBlock / 2; // True, if half of block is busy
|
|
116
|
+
|
|
117
|
+
const maxPriorityFeePerGas = history.reward.reduce((previous, rewards) => {
|
|
118
|
+
let firstBN = BN_ZERO;
|
|
119
|
+
let firstIndex = 0;
|
|
120
|
+
|
|
121
|
+
/* Get first priority which greater than 0 */
|
|
122
|
+
for (let i = 0; i < rewards.length; i++) {
|
|
123
|
+
firstIndex = i;
|
|
124
|
+
const current = rewards[i];
|
|
125
|
+
const currentBN = new BigN(current);
|
|
126
|
+
if (currentBN.gt(BN_ZERO)) {
|
|
127
|
+
firstBN = currentBN;
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
let secondBN = firstBN;
|
|
132
|
+
|
|
133
|
+
/* Get second priority which greater than first priority */
|
|
134
|
+
for (let i = firstIndex; i < rewards.length; i++) {
|
|
135
|
+
const current = rewards[i];
|
|
136
|
+
const currentBN = new BigN(current);
|
|
137
|
+
if (currentBN.gt(firstBN)) {
|
|
138
|
+
secondBN = currentBN;
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
let current;
|
|
143
|
+
if (busyNetwork) {
|
|
144
|
+
current = secondBN.dividedBy(2).gte(firstBN) ? firstBN : secondBN; // second too larger than first (> 2 times), use first else use second
|
|
145
|
+
} else {
|
|
146
|
+
current = firstBN;
|
|
147
|
+
}
|
|
148
|
+
if (busyNetwork) {
|
|
149
|
+
/* Get max value */
|
|
150
|
+
return current.gte(previous) ? current : previous; // get max priority
|
|
151
|
+
} else {
|
|
152
|
+
/* Get min value which greater than 0 */
|
|
153
|
+
if (previous.eq(BN_ZERO)) {
|
|
154
|
+
return current; // get min priority
|
|
155
|
+
} else if (current.eq(BN_ZERO)) {
|
|
156
|
+
return previous;
|
|
157
|
+
}
|
|
158
|
+
return current.lte(previous) ? current : previous; // get min priority
|
|
159
|
+
}
|
|
160
|
+
}, BN_ZERO);
|
|
161
|
+
if (maxPriorityFeePerGas.eq(BN_ZERO)) {
|
|
162
|
+
const _price = await web3.api.eth.getGasPrice();
|
|
163
|
+
const gasPrice = recalculateGasPrice(_price, networkKey);
|
|
164
|
+
return {
|
|
165
|
+
gasPrice,
|
|
166
|
+
maxFeePerGas: undefined,
|
|
167
|
+
maxPriorityFeePerGas: undefined,
|
|
168
|
+
baseGasFee: undefined,
|
|
169
|
+
busyNetwork: false
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/* Max gas = (base + priority) * 1.5 (if not busy or 2 when busy); */
|
|
174
|
+
const maxFeePerGas = baseGasFee.plus(maxPriorityFeePerGas).multipliedBy(busyNetwork ? 2 : 1.5).decimalPlaces(0);
|
|
175
|
+
return {
|
|
176
|
+
gasPrice: undefined,
|
|
177
|
+
maxFeePerGas,
|
|
178
|
+
maxPriorityFeePerGas,
|
|
179
|
+
baseGasFee,
|
|
180
|
+
busyNetwork
|
|
181
|
+
};
|
|
182
|
+
} catch (e) {
|
|
183
|
+
const _price = await web3.api.eth.getGasPrice();
|
|
184
|
+
const gasPrice = recalculateGasPrice(_price, networkKey);
|
|
185
|
+
return {
|
|
186
|
+
gasPrice,
|
|
187
|
+
maxFeePerGas: undefined,
|
|
188
|
+
maxPriorityFeePerGas: undefined,
|
|
189
|
+
baseGasFee: undefined,
|
|
190
|
+
busyNetwork: false
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import BaseMigrationJob from '@subwallet/extension-base/services/migration-service/Base';
|
|
5
|
+
export default class DeleteChainStaking extends BaseMigrationJob {
|
|
6
|
+
async run() {
|
|
7
|
+
try {
|
|
8
|
+
await this.state.dbService.stores.yieldPoolInfo.table.where({
|
|
9
|
+
slug: 'CAPS___native_staking___ternoa_alphanet'
|
|
10
|
+
}).delete();
|
|
11
|
+
} catch (e) {
|
|
12
|
+
console.error(e);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import BaseMigrationJob from '@subwallet/extension-base/services/migration-service/Base';
|
|
5
|
+
export default class MigrateAssetSetting extends BaseMigrationJob {
|
|
6
|
+
async run() {
|
|
7
|
+
try {
|
|
8
|
+
const oldSlugs = ['ethereum-ERC20-WFTM-0x4E15361FD6b4BB609Fa63C81A2be19d873717870', 'moonbeam-ERC20-CSG-0x2Dfc76901bB2ac2A5fA5fc479590A490BBB10a5F', 'astar-LOCAL-aUSD', 'astarEvm-ERC20-aUSD-0xfFFFFfFF00000000000000010000000000000001',
|
|
9
|
+
//
|
|
10
|
+
'moonriver-LOCAL-xcaUSD',
|
|
11
|
+
//
|
|
12
|
+
'moonriver-LOCAL-xckBTC', 'bifrost-LOCAL-aUSD', 'calamari-LOCAL-AUSD', 'shiden-LOCAL-aUSD', 'shidenEvm-ERC20-aUSD-0xfFFfFFfF00000000000000010000000000000000',
|
|
13
|
+
//
|
|
14
|
+
'ethereum_goerli-NATIVE-GoerliETH', 'binance_test-NATIVE-BNB',
|
|
15
|
+
//
|
|
16
|
+
'pangolin-LOCAL-CKTON',
|
|
17
|
+
//
|
|
18
|
+
'zeta_test-NATIVE-aZETA' //
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
const newSlugs = ['ethereum-ERC20-FTM-0x4E15361FD6b4BB609Fa63C81A2be19d873717870', 'moonbeam-ERC20-CGS-0x2Dfc76901bB2ac2A5fA5fc479590A490BBB10a5F', 'astar-LOCAL-aSEED', 'astarEvm-ERC20-aSEED-0xfFFFFfFF00000000000000010000000000000001', 'moonriver-LOCAL-xcaSeed', 'moonriver-LOCAL-xcKBTC', 'bifrost-LOCAL-KUSD', 'calamari-LOCAL-AUSD', 'shiden-LOCAL-aSEED', 'shidenEvm-ERC20-aSEED-0xfFFfFFfF00000000000000010000000000000000', 'ethereum_goerli-NATIVE-ETH', 'binance_test-NATIVE-tBNB', 'pangolin-LOCAL-PKTON', 'zeta_test-NATIVE-ZETA'];
|
|
22
|
+
const assetSetting = await this.state.chainService.getAssetSettings();
|
|
23
|
+
const migratedAssetSetting = {};
|
|
24
|
+
for (let i = 0; i < oldSlugs.length; i++) {
|
|
25
|
+
const slug = oldSlugs[i];
|
|
26
|
+
if (Object.keys(assetSetting).includes(slug)) {
|
|
27
|
+
const isVisible = assetSetting[slug].visible;
|
|
28
|
+
const newSlug = newSlugs[i];
|
|
29
|
+
migratedAssetSetting[newSlug] = {
|
|
30
|
+
visible: isVisible
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
this.state.chainService.setAssetSettings({
|
|
35
|
+
...assetSetting,
|
|
36
|
+
...migratedAssetSetting
|
|
37
|
+
});
|
|
38
|
+
} catch (e) {
|
|
39
|
+
console.error(e);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import DeleteEarningData from '@subwallet/extension-base/services/migration-service/scripts/DeleteEarningData';
|
|
5
|
+
// import MigrateAssetSetting from './databases/MigrateAssetSetting';
|
|
5
6
|
import MigrateEarningVersion from "./databases/MigrateEarningVersion.js";
|
|
6
7
|
import MigrateEthProvider from "./providers/MigrateEthProvider.js";
|
|
7
8
|
import MigratePioneerProvider from "./providers/MigratePioneerProvider.js";
|
|
@@ -9,6 +10,7 @@ import MigrateProvidersV1M1P24 from "./providers/MigrateProvidersV1M1P24.js";
|
|
|
9
10
|
import MigratePolygonUSDCProvider from "./tokens/MigratePolygonUSDCProvider.js";
|
|
10
11
|
import AutoEnableChainsTokens from "./AutoEnableChainsTokens.js";
|
|
11
12
|
import DeleteChain from "./DeleteChain.js";
|
|
13
|
+
import DeleteChainStaking from "./DeleteChainStaking.js";
|
|
12
14
|
import EnableVaraChain from "./EnableVaraChain.js";
|
|
13
15
|
import MigrateAuthUrls from "./MigrateAuthUrls.js";
|
|
14
16
|
import MigrateAutoLock from "./MigrateAutoLock.js";
|
|
@@ -41,6 +43,8 @@ export default {
|
|
|
41
43
|
'1.1.17-03': EnableVaraChain,
|
|
42
44
|
'1.1.24-01': MigrateProvidersV1M1P24,
|
|
43
45
|
'1.1.26-01': MigratePolygonUSDCProvider,
|
|
44
|
-
'1.1.28-01': MigrateEarningVersion
|
|
46
|
+
'1.1.28-01': MigrateEarningVersion,
|
|
47
|
+
'1.1.41-01': DeleteChainStaking
|
|
48
|
+
// '1.1.41-02': MigrateAssetSetting
|
|
45
49
|
// [`${EVERYTIME}-1`]: AutoEnableChainsTokens
|
|
46
50
|
};
|
|
@@ -7,6 +7,7 @@ import { BasicTxErrorType, BasicTxWarningCode, ChainType, EvmProviderErrorType,
|
|
|
7
7
|
import { TransactionWarning } from '@subwallet/extension-base/background/warnings/TransactionWarning';
|
|
8
8
|
import { ALL_ACCOUNT_KEY } from '@subwallet/extension-base/constants';
|
|
9
9
|
import { _getAssetDecimals, _getAssetSymbol, _getChainNativeTokenBasicInfo, _getEvmChainId, _isChainEvmCompatible } from '@subwallet/extension-base/services/chain-service/utils';
|
|
10
|
+
import { calculateGasFeeParams } from '@subwallet/extension-base/services/fee-service/utils';
|
|
10
11
|
import { EXTENSION_REQUEST_URL } from '@subwallet/extension-base/services/request-service/constants';
|
|
11
12
|
import { TRANSACTION_TIMEOUT } from '@subwallet/extension-base/services/transaction-service/constants';
|
|
12
13
|
import { parseLiquidStakingEvents, parseLiquidStakingFastUnstakeEvents, parseTransferEventLogs, parseXcmEventLogs } from '@subwallet/extension-base/services/transaction-service/event-parser';
|
|
@@ -14,8 +15,7 @@ import { getBaseTransactionInfo, getTransactionId, isSubstrateTransaction } from
|
|
|
14
15
|
import { getExplorerLink, parseTransactionData } from '@subwallet/extension-base/services/transaction-service/utils';
|
|
15
16
|
import { isWalletConnectRequest } from '@subwallet/extension-base/services/wallet-connect-service/helpers';
|
|
16
17
|
import { YieldPoolType } from '@subwallet/extension-base/types';
|
|
17
|
-
import { reformatAddress } from '@subwallet/extension-base/utils';
|
|
18
|
-
import { anyNumberToBN, calculateGasFeeParams } from '@subwallet/extension-base/utils/eth';
|
|
18
|
+
import { anyNumberToBN, reformatAddress } from '@subwallet/extension-base/utils';
|
|
19
19
|
import { mergeTransactionAndSignature } from '@subwallet/extension-base/utils/eth/mergeTransactionAndSignature';
|
|
20
20
|
import { isContractAddress, parseContractInput } from '@subwallet/extension-base/utils/eth/parseTransaction';
|
|
21
21
|
import { BN_ZERO } from '@subwallet/extension-base/utils/number';
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import BigN from 'bignumber.js';
|
|
2
|
+
interface BaseFeeInfo {
|
|
3
|
+
busyNetwork: boolean;
|
|
4
|
+
}
|
|
5
|
+
export interface EvmLegacyFeeInfo extends BaseFeeInfo {
|
|
6
|
+
gasPrice: string;
|
|
7
|
+
maxFeePerGas: undefined;
|
|
8
|
+
maxPriorityFeePerGas: undefined;
|
|
9
|
+
baseGasFee: undefined;
|
|
10
|
+
}
|
|
11
|
+
export interface EvmEIP1995FeeInfo extends BaseFeeInfo {
|
|
12
|
+
gasPrice: undefined;
|
|
13
|
+
maxFeePerGas: BigN;
|
|
14
|
+
maxPriorityFeePerGas: BigN;
|
|
15
|
+
baseGasFee: BigN;
|
|
16
|
+
}
|
|
17
|
+
export declare type EvmFeeInfo = EvmLegacyFeeInfo | EvmEIP1995FeeInfo;
|
|
18
|
+
export interface EvmLegacyFeeInfoCache extends BaseFeeInfo {
|
|
19
|
+
gasPrice: string;
|
|
20
|
+
maxFeePerGas: undefined;
|
|
21
|
+
maxPriorityFeePerGas: undefined;
|
|
22
|
+
baseGasFee: undefined;
|
|
23
|
+
}
|
|
24
|
+
export interface EvmEIP1995FeeInfoCache extends BaseFeeInfo {
|
|
25
|
+
gasPrice: undefined;
|
|
26
|
+
maxFeePerGas: string;
|
|
27
|
+
maxPriorityFeePerGas: string;
|
|
28
|
+
baseGasFee: string;
|
|
29
|
+
}
|
|
30
|
+
export declare type EvmFeeInfoCache = EvmLegacyFeeInfoCache | EvmEIP1995FeeInfoCache;
|
|
31
|
+
export interface InfuraFeeDetail {
|
|
32
|
+
suggestedMaxPriorityFeePerGas: string;
|
|
33
|
+
suggestedMaxFeePerGas: string;
|
|
34
|
+
minWaitTimeEstimate: number;
|
|
35
|
+
maxWaitTimeEstimate: number;
|
|
36
|
+
}
|
|
37
|
+
export interface InfuraFeeInfo {
|
|
38
|
+
low: InfuraFeeDetail;
|
|
39
|
+
medium: InfuraFeeDetail;
|
|
40
|
+
high: InfuraFeeDetail;
|
|
41
|
+
networkCongestion: number;
|
|
42
|
+
estimatedBaseFee: string;
|
|
43
|
+
latestPriorityFeeRange: [string, string];
|
|
44
|
+
historicalPriorityFeeRange: [string, string];
|
|
45
|
+
historicalBaseFeeRange: [string, string];
|
|
46
|
+
priorityFeeTrend: 'down' | 'up';
|
|
47
|
+
baseFeeTrend: 'down' | 'up';
|
|
48
|
+
}
|
|
49
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/types/index.d.ts
CHANGED
package/types/index.js
CHANGED
|
@@ -136,6 +136,10 @@ export interface PalletStakingStakingLedger {
|
|
|
136
136
|
unlocking: UnlockingChunk[];
|
|
137
137
|
claimedRewards: number[];
|
|
138
138
|
}
|
|
139
|
+
export interface PalletStakingActiveEraInfo {
|
|
140
|
+
index: string;
|
|
141
|
+
start: string;
|
|
142
|
+
}
|
|
139
143
|
export interface RuntimeDispatchInfo {
|
|
140
144
|
weight: {
|
|
141
145
|
refTime: number;
|
package/utils/eth.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { _EvmApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
2
1
|
import BigN from 'bignumber.js';
|
|
3
2
|
import BNEther from 'bn.js';
|
|
4
3
|
import { SignedTransaction } from 'web3-core';
|
|
@@ -16,17 +15,3 @@ export declare class Transaction {
|
|
|
16
15
|
export declare const anyNumberToBN: (value?: string | number | BNEther) => BigN;
|
|
17
16
|
export declare const createTransactionFromRLP: (rlp: string) => Transaction | null;
|
|
18
17
|
export declare const signatureToHex: (sig: SignedTransaction) => string;
|
|
19
|
-
export declare const recalculateGasPrice: (_price: string, chain: string) => string;
|
|
20
|
-
export declare const calculateGasFeeParams: (web3: _EvmApi, networkKey: string) => Promise<{
|
|
21
|
-
gasPrice: string;
|
|
22
|
-
busyNetwork: boolean;
|
|
23
|
-
maxFeePerGas?: undefined;
|
|
24
|
-
maxPriorityFeePerGas?: undefined;
|
|
25
|
-
baseGasFee?: undefined;
|
|
26
|
-
} | {
|
|
27
|
-
maxFeePerGas: BigN;
|
|
28
|
-
maxPriorityFeePerGas: BigN;
|
|
29
|
-
baseGasFee: BigN;
|
|
30
|
-
busyNetwork: boolean;
|
|
31
|
-
gasPrice?: undefined;
|
|
32
|
-
}>;
|