@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
package/utils/eth.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { GAS_PRICE_RATIO, NETWORK_MULTI_GAS_FEE } from '@subwallet/extension-base/constants';
|
|
5
4
|
import BigN from 'bignumber.js';
|
|
6
5
|
import { ethers } from 'ethers';
|
|
7
6
|
import { hexStripPrefix, numberToHex } from '@polkadot/util';
|
|
8
|
-
import { BN_ZERO } from "./number.js";
|
|
9
7
|
const hexToNumberString = s => {
|
|
10
8
|
const temp = parseInt(s, 16);
|
|
11
9
|
if (isNaN(temp)) {
|
|
@@ -60,103 +58,4 @@ export const signatureToHex = sig => {
|
|
|
60
58
|
const hexS = s.length % 2 === 1 ? `0${s}` : s;
|
|
61
59
|
const hexV = hexStripPrefix(numberToHex(v));
|
|
62
60
|
return hexR + hexS + hexV;
|
|
63
|
-
};
|
|
64
|
-
export const recalculateGasPrice = (_price, chain) => {
|
|
65
|
-
const needMulti = NETWORK_MULTI_GAS_FEE.includes(chain) || NETWORK_MULTI_GAS_FEE.includes('*');
|
|
66
|
-
return needMulti ? new BigN(_price).multipliedBy(GAS_PRICE_RATIO).toFixed(0) : _price;
|
|
67
|
-
};
|
|
68
|
-
export const calculateGasFeeParams = async (web3, networkKey) => {
|
|
69
|
-
try {
|
|
70
|
-
const numBlock = 20;
|
|
71
|
-
const rewardPercent = [];
|
|
72
|
-
for (let i = 0; i <= 100; i = i + 5) {
|
|
73
|
-
rewardPercent.push(i);
|
|
74
|
-
}
|
|
75
|
-
const history = await web3.api.eth.getFeeHistory(numBlock, 'latest', rewardPercent);
|
|
76
|
-
const baseGasFee = new BigN(history.baseFeePerGas[history.baseFeePerGas.length - 1]); // Last element is latest
|
|
77
|
-
|
|
78
|
-
const blocksBusy = history.reward.reduce((previous, rewards, currentIndex) => {
|
|
79
|
-
const [firstPriority] = rewards;
|
|
80
|
-
const base = history.baseFeePerGas[currentIndex];
|
|
81
|
-
const priorityBN = new BigN(firstPriority);
|
|
82
|
-
const baseBN = new BigN(base);
|
|
83
|
-
|
|
84
|
-
/*
|
|
85
|
-
* True if priority >= 0.3 * base
|
|
86
|
-
* */
|
|
87
|
-
const blockIsBusy = baseBN.gt(BN_ZERO) ? priorityBN.dividedBy(baseBN).gte(0.3) ? 1 : 0 : 0; // Special for bsc, base fee = 0
|
|
88
|
-
|
|
89
|
-
return previous + blockIsBusy;
|
|
90
|
-
}, 0);
|
|
91
|
-
const busyNetwork = blocksBusy >= numBlock / 2; // True, if half of block is busy
|
|
92
|
-
|
|
93
|
-
const maxPriorityFeePerGas = history.reward.reduce((previous, rewards) => {
|
|
94
|
-
let firstBN = BN_ZERO;
|
|
95
|
-
let firstIndex = 0;
|
|
96
|
-
|
|
97
|
-
/* Get first priority which greater than 0 */
|
|
98
|
-
for (let i = 0; i < rewards.length; i++) {
|
|
99
|
-
firstIndex = i;
|
|
100
|
-
const current = rewards[i];
|
|
101
|
-
const currentBN = new BigN(current);
|
|
102
|
-
if (currentBN.gt(BN_ZERO)) {
|
|
103
|
-
firstBN = currentBN;
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
let secondBN = firstBN;
|
|
108
|
-
|
|
109
|
-
/* Get second priority which greater than first priority */
|
|
110
|
-
for (let i = firstIndex; i < rewards.length; i++) {
|
|
111
|
-
const current = rewards[i];
|
|
112
|
-
const currentBN = new BigN(current);
|
|
113
|
-
if (currentBN.gt(firstBN)) {
|
|
114
|
-
secondBN = currentBN;
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
let current;
|
|
119
|
-
if (busyNetwork) {
|
|
120
|
-
current = secondBN.dividedBy(2).gte(firstBN) ? firstBN : secondBN; // second too larger than first (> 2 times), use first else use second
|
|
121
|
-
} else {
|
|
122
|
-
current = firstBN;
|
|
123
|
-
}
|
|
124
|
-
if (busyNetwork) {
|
|
125
|
-
/* Get max value */
|
|
126
|
-
return current.gte(previous) ? current : previous; // get max priority
|
|
127
|
-
} else {
|
|
128
|
-
/* Get min value which greater than 0 */
|
|
129
|
-
if (previous.eq(BN_ZERO)) {
|
|
130
|
-
return current; // get min priority
|
|
131
|
-
} else if (current.eq(BN_ZERO)) {
|
|
132
|
-
return previous;
|
|
133
|
-
}
|
|
134
|
-
return current.lte(previous) ? current : previous; // get min priority
|
|
135
|
-
}
|
|
136
|
-
}, BN_ZERO);
|
|
137
|
-
if (maxPriorityFeePerGas.eq(BN_ZERO)) {
|
|
138
|
-
const _price = await web3.api.eth.getGasPrice();
|
|
139
|
-
const gasPrice = recalculateGasPrice(_price, networkKey);
|
|
140
|
-
return {
|
|
141
|
-
gasPrice,
|
|
142
|
-
busyNetwork: false
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/* Max gas = (base + priority) * 1.5 (if not busy or 2 when busy); */
|
|
147
|
-
const maxFeePerGas = baseGasFee.plus(maxPriorityFeePerGas).multipliedBy(busyNetwork ? 2 : 1.5).decimalPlaces(0);
|
|
148
|
-
return {
|
|
149
|
-
maxFeePerGas,
|
|
150
|
-
maxPriorityFeePerGas,
|
|
151
|
-
baseGasFee,
|
|
152
|
-
busyNetwork
|
|
153
|
-
};
|
|
154
|
-
} catch (e) {
|
|
155
|
-
const _price = await web3.api.eth.getGasPrice();
|
|
156
|
-
const gasPrice = recalculateGasPrice(_price, networkKey);
|
|
157
|
-
return {
|
|
158
|
-
gasPrice,
|
|
159
|
-
busyNetwork: false
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
61
|
};
|
package/utils/index.d.ts
CHANGED
|
@@ -43,6 +43,7 @@ export declare function wait(milliseconds: number): Promise<void>;
|
|
|
43
43
|
export * from './account';
|
|
44
44
|
export * from './array';
|
|
45
45
|
export * from './environment';
|
|
46
|
+
export * from './eth';
|
|
46
47
|
export * from './number';
|
|
47
48
|
export * from './lazy';
|
|
48
49
|
export * from './promise';
|
package/utils/index.js
CHANGED
|
@@ -345,6 +345,7 @@ export function wait(milliseconds) {
|
|
|
345
345
|
export * from "./account.js";
|
|
346
346
|
export * from "./array.js";
|
|
347
347
|
export * from "./environment.js";
|
|
348
|
+
export * from "./eth.js";
|
|
348
349
|
export * from "./number.js";
|
|
349
350
|
export * from "./lazy.js";
|
|
350
351
|
export * from "./promise.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const reportError: (e: Error, pathName: string) => Promise<void>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { TARGET_ENV } from '@subwallet/extension-base/utils/environment';
|
|
5
|
+
import fetch from 'cross-fetch';
|
|
6
|
+
const EXTENSION_REPORT_ERROR_URL = 'https://extension-feedback.subwallet.app/gelf';
|
|
7
|
+
const WEBAPP_REPORT_ERROR_URL = 'https://web-feedback.subwallet.app/gelf';
|
|
8
|
+
export const reportError = async (e, pathName) => {
|
|
9
|
+
const errorContent = JSON.stringify(e.stack);
|
|
10
|
+
const errorShortMessage = e.message;
|
|
11
|
+
const body = {
|
|
12
|
+
content: errorContent,
|
|
13
|
+
short_message: errorShortMessage,
|
|
14
|
+
platform: TARGET_ENV,
|
|
15
|
+
device_version: '',
|
|
16
|
+
app_version: JSON.stringify(process.env.PKG_VERSION),
|
|
17
|
+
current_routes: pathName
|
|
18
|
+
};
|
|
19
|
+
await fetch(TARGET_ENV === 'extension' ? EXTENSION_REPORT_ERROR_URL : WEBAPP_REPORT_ERROR_URL, {
|
|
20
|
+
method: 'POST',
|
|
21
|
+
body: JSON.stringify(body)
|
|
22
|
+
});
|
|
23
|
+
};
|