@subwallet/extension-base 1.1.35-beta.2 → 1.1.35-beta.3
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 +12 -0
- package/background/KoniTypes.js +3 -0
- package/cjs/background/KoniTypes.js +3 -0
- package/cjs/koni/api/staking/bonding/utils.js +44 -0
- package/cjs/koni/api/tokens/evm/transfer.js +35 -19
- package/cjs/koni/api/yield/helper/utils.js +6 -3
- package/cjs/koni/background/handlers/Extension.js +20 -12
- package/cjs/koni/background/handlers/State.js +15 -5
- package/cjs/services/chain-service/index.js +0 -3
- package/cjs/services/earning-service/handlers/liquid-staking/base.js +2 -1
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +2 -1
- package/cjs/services/earning-service/handlers/liquid-staking/index.js +7 -0
- package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +2 -2
- package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +10 -2
- package/cjs/services/earning-service/handlers/nomination-pool/index.js +10 -2
- package/cjs/services/earning-service/handlers/special.js +7 -3
- package/cjs/services/earning-service/service.js +9 -2
- package/cjs/services/notification-service/NotificationService.js +7 -4
- package/cjs/services/request-service/handler/EvmRequestHandler.js +46 -29
- package/cjs/services/transaction-service/index.js +43 -14
- package/cjs/signers/web3/QrSigner.js +2 -0
- package/cjs/types/yield/actions/join/step.js +1 -0
- package/cjs/utils/eth/mergeTransactionAndSignature.js +25 -10
- package/cjs/utils/eth.js +51 -2
- package/cjs/utils/number.js +5 -1
- package/cjs/utils/yield/index.js +3 -0
- package/koni/api/staking/bonding/utils.d.ts +5 -0
- package/koni/api/staking/bonding/utils.js +40 -0
- package/koni/api/tokens/evm/transfer.js +36 -21
- package/koni/api/yield/helper/utils.d.ts +1 -1
- package/koni/api/yield/helper/utils.js +5 -3
- package/koni/background/handlers/Extension.js +21 -13
- package/koni/background/handlers/State.js +16 -6
- package/package.json +11 -7
- package/services/chain-service/index.js +0 -3
- package/services/earning-service/handlers/liquid-staking/base.d.ts +1 -1
- package/services/earning-service/handlers/liquid-staking/base.js +2 -1
- package/services/earning-service/handlers/liquid-staking/bifrost-manta.d.ts +37 -0
- package/services/earning-service/handlers/liquid-staking/bifrost-manta.js +132 -0
- package/services/earning-service/handlers/liquid-staking/bifrost.d.ts +3 -3
- package/services/earning-service/handlers/liquid-staking/bifrost.js +2 -1
- package/services/earning-service/handlers/liquid-staking/index.d.ts +1 -0
- package/services/earning-service/handlers/liquid-staking/index.js +1 -0
- package/services/earning-service/handlers/liquid-staking/stella-swap.js +2 -2
- package/services/earning-service/handlers/native-staking/relay-chain.js +11 -3
- package/services/earning-service/handlers/nomination-pool/index.js +11 -3
- package/services/earning-service/handlers/special.js +7 -3
- package/services/earning-service/service.d.ts +2 -1
- package/services/earning-service/service.js +10 -3
- package/services/notification-service/NotificationService.js +7 -4
- package/services/request-service/handler/EvmRequestHandler.d.ts +2 -2
- package/services/request-service/handler/EvmRequestHandler.js +46 -29
- package/services/transaction-service/index.js +44 -15
- package/services/transaction-service/types.d.ts +2 -2
- package/signers/types.d.ts +2 -0
- package/signers/web3/QrSigner.js +2 -0
- package/types/yield/actions/join/step.d.ts +1 -0
- package/types/yield/actions/join/step.js +1 -0
- package/utils/eth/mergeTransactionAndSignature.js +25 -10
- package/utils/eth.d.ts +14 -0
- package/utils/eth.js +48 -0
- package/utils/number.d.ts +2 -0
- package/utils/number.js +2 -0
- package/cjs/koni/api/dotsama/balance.js +0 -464
- package/cjs/services/migration-service/scripts/MigrateEthProvider.js +0 -17
- package/cjs/services/migration-service/scripts/MigratePioneerProvider.js +0 -17
- package/cjs/services/migration-service/scripts/MigrateProvider.js +0 -29
- package/cjs/services/storage-service/index.js +0 -241
- package/cjs/types.js +0 -1
- package/cjs/utils/address.js +0 -34
- package/cjs/utils/keyring.js +0 -57
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
|
-
var _chainList = require("@subwallet/chain-list");
|
|
9
8
|
var _TransactionError = require("@subwallet/extension-base/background/errors/TransactionError");
|
|
10
9
|
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
11
10
|
var _constants = require("@subwallet/extension-base/constants");
|
|
@@ -208,13 +207,16 @@ class BaseSpecialStakingPoolHandler extends _base.default {
|
|
|
208
207
|
const altInputTokenBalance = await this.state.balanceService.getTokenFreeBalance(address, altInputTokenInfo.originChain, altInputTokenSlug);
|
|
209
208
|
const bnAltInputTokenBalance = new _util.BN(altInputTokenBalance.value || '0');
|
|
210
209
|
if (bnAltInputTokenBalance.gt(_util.BN_ZERO)) {
|
|
210
|
+
const altChainInfo = this.state.getChainInfo(altInputTokenInfo.originChain);
|
|
211
|
+
const symbol = altInputTokenInfo.symbol;
|
|
212
|
+
const networkName = altChainInfo.name;
|
|
211
213
|
const step = {
|
|
212
214
|
metadata: {
|
|
213
215
|
sendingValue: bnAmount.toString(),
|
|
214
216
|
originTokenInfo: altInputTokenInfo,
|
|
215
217
|
destinationTokenInfo: inputTokenInfo
|
|
216
218
|
},
|
|
217
|
-
name:
|
|
219
|
+
name: `Transfer ${symbol} from ${networkName}`,
|
|
218
220
|
type: _types.YieldStepType.XCM
|
|
219
221
|
};
|
|
220
222
|
const xcmOriginSubstrateApi = await this.state.getSubstrateApi(altInputTokenInfo.originChain).isReady;
|
|
@@ -411,7 +413,9 @@ class BaseSpecialStakingPoolHandler extends _base.default {
|
|
|
411
413
|
amount
|
|
412
414
|
} = data;
|
|
413
415
|
const destinationTokenSlug = this.inputAsset;
|
|
414
|
-
const
|
|
416
|
+
const altInputTokenSlug = this.altInputAsset || '';
|
|
417
|
+
const altInputTokenInfo = this.state.getAssetBySlug(altInputTokenSlug);
|
|
418
|
+
const originChainInfo = this.state.getChainInfo(altInputTokenInfo.originChain);
|
|
415
419
|
const originTokenSlug = (0, _utils2._getChainNativeTokenSlug)(originChainInfo);
|
|
416
420
|
const originTokenInfo = this.state.getAssetBySlug(originTokenSlug);
|
|
417
421
|
const destinationTokenInfo = this.state.getAssetBySlug(destinationTokenSlug);
|
|
@@ -74,6 +74,7 @@ class EarningService {
|
|
|
74
74
|
if (_constants2._STAKING_CHAIN_GROUP.liquidStaking.includes(chain)) {
|
|
75
75
|
if (chain === 'bifrost_dot') {
|
|
76
76
|
handlers.push(new _handlers.BifrostLiquidStakingPoolHandler(this.state, chain));
|
|
77
|
+
handlers.push(new _handlers.BifrostMantaLiquidStakingPoolHandler(this.state, chain));
|
|
77
78
|
}
|
|
78
79
|
if (chain === 'acala') {
|
|
79
80
|
handlers.push(new _handlers.AcalaLiquidStakingPoolHandler(this.state, chain));
|
|
@@ -413,9 +414,10 @@ class EarningService {
|
|
|
413
414
|
resetYieldPositionQueue() {
|
|
414
415
|
this.yieldPositionPersistQueue = [];
|
|
415
416
|
}
|
|
416
|
-
resetYieldPosition() {
|
|
417
|
+
async resetYieldPosition() {
|
|
417
418
|
this.yieldPositionSubject.next({});
|
|
418
419
|
this.yieldPositionPersistQueue = [];
|
|
420
|
+
await this.dbService.stores.yieldPosition.clear();
|
|
419
421
|
}
|
|
420
422
|
_getYieldPositionKey(slug, address) {
|
|
421
423
|
return `${slug}---${address}`;
|
|
@@ -443,7 +445,7 @@ class EarningService {
|
|
|
443
445
|
this.runUnsubscribePoolsPosition();
|
|
444
446
|
this.runUnsubscribeStakingRewardInterval();
|
|
445
447
|
this.runUnsubscribeEarningRewardHistoryInterval();
|
|
446
|
-
reset && this.resetYieldPosition();
|
|
448
|
+
reset && (await this.resetYieldPosition());
|
|
447
449
|
await this.runSubscribePoolsPosition();
|
|
448
450
|
this.runSubscribeStakingRewardInterval();
|
|
449
451
|
this.runSubscribeEarningRewardHistoryInterval();
|
|
@@ -729,5 +731,10 @@ class EarningService {
|
|
|
729
731
|
/* Other */
|
|
730
732
|
|
|
731
733
|
/* Handle actions */
|
|
734
|
+
|
|
735
|
+
// Clear wallet data
|
|
736
|
+
async resetWallet() {
|
|
737
|
+
await this.resetYieldPosition();
|
|
738
|
+
}
|
|
732
739
|
}
|
|
733
740
|
exports.default = EarningService;
|
|
@@ -36,15 +36,18 @@ class NotificationService {
|
|
|
36
36
|
const link = action === null || action === void 0 ? void 0 : action.url;
|
|
37
37
|
const onClick = action === null || action === void 0 ? void 0 : action.click;
|
|
38
38
|
const onButtonClick = action === null || action === void 0 ? void 0 : action.buttonClick;
|
|
39
|
-
|
|
39
|
+
const options = {
|
|
40
40
|
type: 'basic',
|
|
41
41
|
title,
|
|
42
42
|
message,
|
|
43
43
|
iconUrl: '/images/icon-128.png',
|
|
44
44
|
priority: 2,
|
|
45
|
-
isClickable: !!link || !!onClick
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
isClickable: !!link || !!onClick
|
|
46
|
+
};
|
|
47
|
+
if (!_utils.isFirefox) {
|
|
48
|
+
options.buttons = buttons;
|
|
49
|
+
}
|
|
50
|
+
(_chrome = chrome) === null || _chrome === void 0 ? void 0 : (_chrome$notifications = _chrome.notifications) === null || _chrome$notifications === void 0 ? void 0 : _chrome$notifications.create(options, notificationId => {
|
|
48
51
|
if (link || onClick) {
|
|
49
52
|
chrome.notifications.onClicked.addListener(nId => {
|
|
50
53
|
if (nId === notificationId) {
|
|
@@ -5,14 +5,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
|
-
var _common =
|
|
8
|
+
var _common = require("@ethereumjs/common");
|
|
9
|
+
var _tx = require("@ethereumjs/tx");
|
|
9
10
|
var _EvmProviderError = require("@subwallet/extension-base/background/errors/EvmProviderError");
|
|
10
11
|
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
11
12
|
var _eth = require("@subwallet/extension-base/utils/eth");
|
|
12
13
|
var _request = require("@subwallet/extension-base/utils/request");
|
|
13
14
|
var _uiKeyring = _interopRequireDefault(require("@subwallet/ui-keyring"));
|
|
14
|
-
var
|
|
15
|
-
var _ethereumjsTx = require("ethereumjs-tx");
|
|
15
|
+
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
16
16
|
var _ethereumjsUtil = require("ethereumjs-util");
|
|
17
17
|
var _i18next = require("i18next");
|
|
18
18
|
var _rxjs = require("rxjs");
|
|
@@ -137,35 +137,48 @@ class EvmRequestHandler {
|
|
|
137
137
|
}
|
|
138
138
|
configToTransaction(config) {
|
|
139
139
|
function formatField(input) {
|
|
140
|
-
if (typeof input === 'string') {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
return new _bn.default(input);
|
|
145
|
-
}
|
|
140
|
+
if (typeof input === 'string' || typeof input === 'number') {
|
|
141
|
+
return (0, _util.hexAddPrefix)(new _bignumber.default(input).toString(16));
|
|
142
|
+
} else if (typeof input === 'undefined') {
|
|
143
|
+
return undefined;
|
|
146
144
|
}
|
|
147
|
-
return input;
|
|
145
|
+
return (0, _util.bnToHex)(input);
|
|
148
146
|
}
|
|
149
|
-
|
|
150
|
-
// Convert any string, number to number with BigN exclude hex string
|
|
151
|
-
const txData = {
|
|
152
|
-
from: config.from,
|
|
153
|
-
nonce: formatField(config.nonce),
|
|
154
|
-
gasPrice: formatField(config.gasPrice),
|
|
155
|
-
gasLimit: formatField(config.gas),
|
|
156
|
-
to: config.to,
|
|
157
|
-
value: formatField(config.value),
|
|
158
|
-
data: (0, _ethereumjsUtil.toBuffer)(config.data)
|
|
159
|
-
};
|
|
160
|
-
const common = _common.default.custom({
|
|
147
|
+
const common = _common.Common.custom({
|
|
161
148
|
chainId: config.chainId,
|
|
162
|
-
defaultHardfork: '
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
return new _ethereumjsTx.Transaction(txData, {
|
|
167
|
-
common
|
|
149
|
+
defaultHardfork: 'london',
|
|
150
|
+
networkId: config.chainId
|
|
151
|
+
}, {
|
|
152
|
+
eips: [1559]
|
|
168
153
|
});
|
|
154
|
+
if (config.maxFeePerGas) {
|
|
155
|
+
const txData = {
|
|
156
|
+
nonce: formatField(config.nonce),
|
|
157
|
+
gasLimit: formatField(config.gas),
|
|
158
|
+
to: config.to,
|
|
159
|
+
value: formatField(config.value),
|
|
160
|
+
data: (0, _ethereumjsUtil.toBuffer)(config.data),
|
|
161
|
+
maxFeePerGas: formatField(config.maxFeePerGas),
|
|
162
|
+
maxPriorityFeePerGas: formatField(config.maxPriorityFeePerGas),
|
|
163
|
+
chainId: config.chainId
|
|
164
|
+
};
|
|
165
|
+
return new _tx.FeeMarketEIP1559Transaction(txData, {
|
|
166
|
+
common
|
|
167
|
+
});
|
|
168
|
+
} else {
|
|
169
|
+
// Convert any string, number to number with BigN exclude hex string
|
|
170
|
+
const txData = {
|
|
171
|
+
nonce: formatField(config.nonce),
|
|
172
|
+
gasLimit: formatField(config.gas),
|
|
173
|
+
gasPrice: formatField(config.gasPrice),
|
|
174
|
+
to: config.to,
|
|
175
|
+
value: formatField(config.value),
|
|
176
|
+
data: (0, _ethereumjsUtil.toBuffer)(config.data)
|
|
177
|
+
};
|
|
178
|
+
return new _tx.LegacyTransaction(txData, {
|
|
179
|
+
common
|
|
180
|
+
});
|
|
181
|
+
}
|
|
169
182
|
}
|
|
170
183
|
async signTransaction(confirmation) {
|
|
171
184
|
const transaction = confirmation.payload;
|
|
@@ -174,6 +187,8 @@ class EvmRequestHandler {
|
|
|
174
187
|
from,
|
|
175
188
|
gas,
|
|
176
189
|
gasPrice,
|
|
190
|
+
maxFeePerGas,
|
|
191
|
+
maxPriorityFeePerGas,
|
|
177
192
|
value
|
|
178
193
|
} = transaction;
|
|
179
194
|
const pair = _uiKeyring.default.getPair(from);
|
|
@@ -182,7 +197,9 @@ class EvmRequestHandler {
|
|
|
182
197
|
gas: (0, _eth.anyNumberToBN)(gas).toNumber(),
|
|
183
198
|
value: (0, _eth.anyNumberToBN)(value).toNumber(),
|
|
184
199
|
gasPrice: (0, _eth.anyNumberToBN)(gasPrice).toNumber(),
|
|
185
|
-
gasLimit: (0, _eth.anyNumberToBN)(estimateGas).toNumber()
|
|
200
|
+
gasLimit: (0, _eth.anyNumberToBN)(estimateGas).toNumber(),
|
|
201
|
+
maxFeePerGas: (0, _eth.anyNumberToBN)(maxFeePerGas).toNumber(),
|
|
202
|
+
maxPriorityFeePerGas: (0, _eth.anyNumberToBN)(maxPriorityFeePerGas).toNumber()
|
|
186
203
|
// nonce: await web3.eth.getTransactionCount(from) // Todo: fill this value from transaction service
|
|
187
204
|
};
|
|
188
205
|
|
|
@@ -22,6 +22,7 @@ var _utils3 = require("@subwallet/extension-base/utils");
|
|
|
22
22
|
var _eth = require("@subwallet/extension-base/utils/eth");
|
|
23
23
|
var _mergeTransactionAndSignature = require("@subwallet/extension-base/utils/eth/mergeTransactionAndSignature");
|
|
24
24
|
var _parseTransaction = require("@subwallet/extension-base/utils/eth/parseTransaction");
|
|
25
|
+
var _number = require("@subwallet/extension-base/utils/number");
|
|
25
26
|
var _uiKeyring = _interopRequireDefault(require("@subwallet/ui-keyring"));
|
|
26
27
|
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
27
28
|
var _ethereumjsUtil = require("ethereumjs-util");
|
|
@@ -100,7 +101,8 @@ class TransactionService {
|
|
|
100
101
|
const estimateFee = {
|
|
101
102
|
symbol: '',
|
|
102
103
|
decimals: 0,
|
|
103
|
-
value: ''
|
|
104
|
+
value: '',
|
|
105
|
+
tooHigh: false
|
|
104
106
|
};
|
|
105
107
|
const chainInfo = this.state.chainService.getChainInfoByKey(chain);
|
|
106
108
|
if (!chainInfo) {
|
|
@@ -121,10 +123,16 @@ class TransactionService {
|
|
|
121
123
|
if (!web3) {
|
|
122
124
|
validationResponse.errors.push(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.CHAIN_DISCONNECTED, undefined));
|
|
123
125
|
} else {
|
|
124
|
-
const _price = await web3.api.eth.getGasPrice();
|
|
125
|
-
const gasPrice = (0, _eth.recalculateGasPrice)(_price, chainInfo.slug);
|
|
126
126
|
const gasLimit = await web3.api.eth.estimateGas(transaction);
|
|
127
|
-
|
|
127
|
+
const priority = await (0, _eth.calculateGasFeeParams)(web3, chainInfo.slug);
|
|
128
|
+
if (priority.baseGasFee) {
|
|
129
|
+
const priorityFee = priority.baseGasFee.plus(priority.maxPriorityFeePerGas);
|
|
130
|
+
const maxFee = priority.maxFeePerGas.lte(priorityFee) ? priority.maxFeePerGas : priorityFee;
|
|
131
|
+
estimateFee.value = maxFee.multipliedBy(gasLimit).toFixed(0);
|
|
132
|
+
} else {
|
|
133
|
+
estimateFee.value = new _bignumber.default(priority.gasPrice).multipliedBy(gasLimit).toFixed(0);
|
|
134
|
+
}
|
|
135
|
+
estimateFee.tooHigh = priority.busyNetwork;
|
|
128
136
|
}
|
|
129
137
|
}
|
|
130
138
|
} catch (e) {
|
|
@@ -529,6 +537,7 @@ class TransactionService {
|
|
|
529
537
|
case _KoniTypes.ExtrinsicType.MINT_QDOT:
|
|
530
538
|
case _KoniTypes.ExtrinsicType.MINT_LDOT:
|
|
531
539
|
case _KoniTypes.ExtrinsicType.MINT_SDOT:
|
|
540
|
+
case _KoniTypes.ExtrinsicType.MINT_VMANTA:
|
|
532
541
|
|
|
533
542
|
// eslint-disable-next-line no-fallthrough
|
|
534
543
|
case _KoniTypes.ExtrinsicType.MINT_VDOT:
|
|
@@ -582,12 +591,14 @@ class TransactionService {
|
|
|
582
591
|
break;
|
|
583
592
|
}
|
|
584
593
|
case _KoniTypes.ExtrinsicType.UNSTAKE_VDOT:
|
|
594
|
+
case _KoniTypes.ExtrinsicType.UNSTAKE_VMANTA:
|
|
585
595
|
case _KoniTypes.ExtrinsicType.UNSTAKE_LDOT:
|
|
586
596
|
case _KoniTypes.ExtrinsicType.UNSTAKE_SDOT:
|
|
587
597
|
case _KoniTypes.ExtrinsicType.UNSTAKE_STDOT:
|
|
588
598
|
case _KoniTypes.ExtrinsicType.REDEEM_STDOT:
|
|
589
599
|
case _KoniTypes.ExtrinsicType.REDEEM_LDOT:
|
|
590
600
|
case _KoniTypes.ExtrinsicType.REDEEM_SDOT:
|
|
601
|
+
case _KoniTypes.ExtrinsicType.REDEEM_VMANTA:
|
|
591
602
|
|
|
592
603
|
// eslint-disable-next-line no-fallthrough
|
|
593
604
|
case _KoniTypes.ExtrinsicType.REDEEM_VDOT:
|
|
@@ -850,17 +861,33 @@ class TransactionService {
|
|
|
850
861
|
this.eventService.emit('transaction.timeout', transaction);
|
|
851
862
|
}
|
|
852
863
|
generateHashPayload(chain, transaction) {
|
|
853
|
-
var _transaction$nonce;
|
|
854
864
|
const chainInfo = this.state.chainService.getChainInfoByKey(chain);
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
865
|
+
let txObject;
|
|
866
|
+
const max = (0, _eth.anyNumberToBN)(transaction.maxFeePerGas);
|
|
867
|
+
if (max.gt(_number.BN_ZERO)) {
|
|
868
|
+
var _transaction$nonce;
|
|
869
|
+
txObject = {
|
|
870
|
+
nonce: (_transaction$nonce = transaction.nonce) !== null && _transaction$nonce !== void 0 ? _transaction$nonce : 0,
|
|
871
|
+
maxFeePerGas: (0, _ethereumjsUtil.addHexPrefix)((0, _eth.anyNumberToBN)(transaction.maxFeePerGas).toString(16)),
|
|
872
|
+
maxPriorityFeePerGas: (0, _ethereumjsUtil.addHexPrefix)((0, _eth.anyNumberToBN)(transaction.maxPriorityFeePerGas).toString(16)),
|
|
873
|
+
gasLimit: (0, _ethereumjsUtil.addHexPrefix)((0, _eth.anyNumberToBN)(transaction.gas).toString(16)),
|
|
874
|
+
to: transaction.to !== undefined ? transaction.to : '',
|
|
875
|
+
value: (0, _ethereumjsUtil.addHexPrefix)((0, _eth.anyNumberToBN)(transaction.value).toString(16)),
|
|
876
|
+
data: transaction.data,
|
|
877
|
+
chainId: (0, _utils._getEvmChainId)(chainInfo)
|
|
878
|
+
};
|
|
879
|
+
} else {
|
|
880
|
+
var _transaction$nonce2;
|
|
881
|
+
txObject = {
|
|
882
|
+
nonce: (_transaction$nonce2 = transaction.nonce) !== null && _transaction$nonce2 !== void 0 ? _transaction$nonce2 : 0,
|
|
883
|
+
gasPrice: (0, _ethereumjsUtil.addHexPrefix)((0, _eth.anyNumberToBN)(transaction.gasPrice).toString(16)),
|
|
884
|
+
gasLimit: (0, _ethereumjsUtil.addHexPrefix)((0, _eth.anyNumberToBN)(transaction.gas).toString(16)),
|
|
885
|
+
to: transaction.to !== undefined ? transaction.to : '',
|
|
886
|
+
value: (0, _ethereumjsUtil.addHexPrefix)((0, _eth.anyNumberToBN)(transaction.value).toString(16)),
|
|
887
|
+
data: transaction.data,
|
|
888
|
+
chainId: (0, _utils._getEvmChainId)(chainInfo)
|
|
889
|
+
};
|
|
890
|
+
}
|
|
864
891
|
return _ethers.ethers.Transaction.from(txObject).unsignedSerialized;
|
|
865
892
|
}
|
|
866
893
|
async signAndSendEvmTransaction(_ref7) {
|
|
@@ -926,6 +953,8 @@ class TransactionService {
|
|
|
926
953
|
nonce: (_payload$nonce = payload.nonce) !== null && _payload$nonce !== void 0 ? _payload$nonce : 0,
|
|
927
954
|
from: payload.from,
|
|
928
955
|
gasPrice: (0, _eth.anyNumberToBN)(payload.gasPrice).toNumber(),
|
|
956
|
+
maxFeePerGas: (0, _eth.anyNumberToBN)(payload.maxFeePerGas).toNumber(),
|
|
957
|
+
maxPriorityFeePerGas: (0, _eth.anyNumberToBN)(payload.maxPriorityFeePerGas).toNumber(),
|
|
929
958
|
gasLimit: (0, _eth.anyNumberToBN)(payload.gas).toNumber(),
|
|
930
959
|
to: payload.to !== undefined ? payload.to : '',
|
|
931
960
|
value: (0, _eth.anyNumberToBN)(payload.value).toNumber(),
|
|
@@ -33,6 +33,8 @@ class QrSigner {
|
|
|
33
33
|
const txObject = {
|
|
34
34
|
nonce: (_tx$nonce = tx.nonce) !== null && _tx$nonce !== void 0 ? _tx$nonce : 0,
|
|
35
35
|
gasPrice: (0, _ethereumjsUtil.addHexPrefix)(tx.gasPrice.toString(16)),
|
|
36
|
+
maxPriorityFeePerGas: (0, _ethereumjsUtil.addHexPrefix)(tx.maxPriorityFeePerGas.toString(16)),
|
|
37
|
+
maxFeePerGas: (0, _ethereumjsUtil.addHexPrefix)(tx.maxFeePerGas.toString(16)),
|
|
36
38
|
gasLimit: (0, _ethereumjsUtil.addHexPrefix)(tx.gasLimit.toString(16)),
|
|
37
39
|
to: tx.to !== undefined ? tx.to : '',
|
|
38
40
|
value: (0, _ethereumjsUtil.addHexPrefix)(tx.value.toString(16)),
|
|
@@ -39,6 +39,7 @@ exports.YieldStepType = YieldStepType;
|
|
|
39
39
|
YieldStepType["NOMINATE"] = "NOMINATE";
|
|
40
40
|
YieldStepType["JOIN_NOMINATION_POOL"] = "JOIN_NOMINATION_POOL";
|
|
41
41
|
YieldStepType["MINT_VDOT"] = "MINT_VDOT";
|
|
42
|
+
YieldStepType["MINT_VMANTA"] = "MINT_VMANTA";
|
|
42
43
|
YieldStepType["MINT_LDOT"] = "MINT_LDOT";
|
|
43
44
|
YieldStepType["MINT_QDOT"] = "MINT_QDOT";
|
|
44
45
|
YieldStepType["MINT_SDOT"] = "MINT_SDOT";
|
|
@@ -16,16 +16,31 @@ const mergeTransactionAndSignature = (tx, _rawSignature) => {
|
|
|
16
16
|
s: `0x${_signature.substring(64, 128)}`,
|
|
17
17
|
v: parseInt(`0x${_signature.substring(128)}`)
|
|
18
18
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
19
|
+
let transaction;
|
|
20
|
+
if (tx.maxFeePerGas) {
|
|
21
|
+
transaction = {
|
|
22
|
+
nonce: tx.nonce,
|
|
23
|
+
maxFeePerGas: (0, _ethereumjsUtil.addHexPrefix)(tx.maxFeePerGas.toString(16)),
|
|
24
|
+
maxPriorityFeePerGas: (0, _ethereumjsUtil.addHexPrefix)(tx.maxPriorityFeePerGas.toString(16)),
|
|
25
|
+
gasLimit: (0, _ethereumjsUtil.addHexPrefix)(tx.gasLimit.toString(16)),
|
|
26
|
+
to: tx.to,
|
|
27
|
+
value: (0, _ethereumjsUtil.addHexPrefix)(tx.value.toString(16)),
|
|
28
|
+
data: tx.data,
|
|
29
|
+
chainId: tx.chainId,
|
|
30
|
+
signature: signature
|
|
31
|
+
};
|
|
32
|
+
} else {
|
|
33
|
+
transaction = {
|
|
34
|
+
nonce: tx.nonce,
|
|
35
|
+
gasPrice: (0, _ethereumjsUtil.addHexPrefix)(tx.gasPrice.toString(16)),
|
|
36
|
+
gasLimit: (0, _ethereumjsUtil.addHexPrefix)(tx.gasLimit.toString(16)),
|
|
37
|
+
to: tx.to,
|
|
38
|
+
value: (0, _ethereumjsUtil.addHexPrefix)(tx.value.toString(16)),
|
|
39
|
+
data: tx.data,
|
|
40
|
+
chainId: tx.chainId,
|
|
41
|
+
signature: signature
|
|
42
|
+
};
|
|
43
|
+
}
|
|
29
44
|
return _ethers.ethers.Transaction.from(transaction).serialized;
|
|
30
45
|
};
|
|
31
46
|
exports.mergeTransactionAndSignature = mergeTransactionAndSignature;
|
package/cjs/utils/eth.js
CHANGED
|
@@ -4,11 +4,12 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.signatureToHex = exports.recalculateGasPrice = exports.createTransactionFromRLP = exports.anyNumberToBN = exports.Transaction = void 0;
|
|
7
|
+
exports.signatureToHex = exports.recalculateGasPrice = exports.createTransactionFromRLP = exports.calculateGasFeeParams = exports.anyNumberToBN = exports.Transaction = void 0;
|
|
8
8
|
var _constants = require("@subwallet/extension-base/constants");
|
|
9
9
|
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
10
10
|
var _ethers = require("ethers");
|
|
11
11
|
var _util = require("@polkadot/util");
|
|
12
|
+
var _number = require("./number");
|
|
12
13
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
13
14
|
// SPDX-License-Identifier: Apache-2.0
|
|
14
15
|
|
|
@@ -75,4 +76,52 @@ const recalculateGasPrice = (_price, chain) => {
|
|
|
75
76
|
const needMulti = _constants.NETWORK_MULTI_GAS_FEE.includes(chain) || _constants.NETWORK_MULTI_GAS_FEE.includes('*');
|
|
76
77
|
return needMulti ? new _bignumber.default(_price).multipliedBy(_constants.GAS_PRICE_RATIO).toFixed(0) : _price;
|
|
77
78
|
};
|
|
78
|
-
exports.recalculateGasPrice = recalculateGasPrice;
|
|
79
|
+
exports.recalculateGasPrice = recalculateGasPrice;
|
|
80
|
+
const calculateGasFeeParams = async (web3, networkKey) => {
|
|
81
|
+
try {
|
|
82
|
+
const numBlock = 20;
|
|
83
|
+
const history = await web3.api.eth.getFeeHistory(numBlock, 'latest', [0, 25, 50, 75, 100]);
|
|
84
|
+
const baseGasFee = new _bignumber.default(history.baseFeePerGas[history.baseFeePerGas.length - 1]); // Last element is latest
|
|
85
|
+
|
|
86
|
+
const blocksBusy = history.reward.reduce((previous, rewards, currentIndex) => {
|
|
87
|
+
const [priority] = rewards;
|
|
88
|
+
const base = history.baseFeePerGas[currentIndex];
|
|
89
|
+
const priorityBN = new _bignumber.default(priority);
|
|
90
|
+
const baseBN = new _bignumber.default(base);
|
|
91
|
+
const blockIsBusy = priorityBN.dividedBy(baseBN).gte(0.3) ? 1 : 0; // True if priority >= 0.5 * base
|
|
92
|
+
|
|
93
|
+
return previous + blockIsBusy;
|
|
94
|
+
}, 0);
|
|
95
|
+
const busyNetwork = blocksBusy >= numBlock / 2; // True if half of block is busy
|
|
96
|
+
|
|
97
|
+
const maxPriorityFeePerGas = history.reward.reduce((previous, rewards) => {
|
|
98
|
+
const [first, second] = rewards;
|
|
99
|
+
const firstBN = new _bignumber.default(first);
|
|
100
|
+
const secondBN = new _bignumber.default(second);
|
|
101
|
+
if (busyNetwork) {
|
|
102
|
+
const current = secondBN.dividedBy(2).gte(firstBN) ? firstBN : secondBN; // second too larger than first (> 2 times), use first else use second
|
|
103
|
+
|
|
104
|
+
return current.gte(previous) ? current : previous; // get max priority
|
|
105
|
+
} else {
|
|
106
|
+
const current = firstBN;
|
|
107
|
+
return current.lte(previous) ? current : previous; // get min priority
|
|
108
|
+
}
|
|
109
|
+
}, _number.BN_ZERO);
|
|
110
|
+
const maxFeePerGas = baseGasFee.plus(maxPriorityFeePerGas).multipliedBy(busyNetwork ? 2 : 1.5).decimalPlaces(0); // Max gas =(base + priority) * 1.5(if not busy or 2 when busy);
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
maxFeePerGas,
|
|
114
|
+
maxPriorityFeePerGas,
|
|
115
|
+
baseGasFee,
|
|
116
|
+
busyNetwork
|
|
117
|
+
};
|
|
118
|
+
} catch (e) {
|
|
119
|
+
const _price = await web3.api.eth.getGasPrice();
|
|
120
|
+
const gasPrice = recalculateGasPrice(_price, networkKey);
|
|
121
|
+
return {
|
|
122
|
+
gasPrice,
|
|
123
|
+
busyNetwork: false
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
exports.calculateGasFeeParams = calculateGasFeeParams;
|
package/cjs/utils/number.js
CHANGED
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.toBNString = exports.formatNumber = exports.balanceFormatter = exports.PREDEFINED_FORMATTER = exports.BN_ZERO = exports.BN_TEN = void 0;
|
|
7
|
+
exports.toBNString = exports.formatNumber = exports.balanceFormatter = exports.PREDEFINED_FORMATTER = exports.BN_ZERO = exports.BN_WEI = exports.BN_TEN = exports.BN_ONE = void 0;
|
|
8
8
|
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
9
9
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
10
10
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -13,6 +13,10 @@ const BN_ZERO = new _bignumber.default(0);
|
|
|
13
13
|
exports.BN_ZERO = BN_ZERO;
|
|
14
14
|
const BN_TEN = new _bignumber.default(10);
|
|
15
15
|
exports.BN_TEN = BN_TEN;
|
|
16
|
+
const BN_ONE = new _bignumber.default(1);
|
|
17
|
+
exports.BN_ONE = BN_ONE;
|
|
18
|
+
const BN_WEI = BN_TEN.pow(9);
|
|
19
|
+
exports.BN_WEI = BN_WEI;
|
|
16
20
|
// Clear zero from end, use with decimal only
|
|
17
21
|
const clearZero = result => {
|
|
18
22
|
let index = result.length - 1;
|
|
@@ -3,7 +3,9 @@ import { _ChainInfo } from '@subwallet/chain-list/types';
|
|
|
3
3
|
import { NominationInfo, NominatorMetadata, StakingType, UnstakingInfo } from '@subwallet/extension-base/background/KoniTypes';
|
|
4
4
|
import { _SubstrateInflationParams } from '@subwallet/extension-base/services/chain-service/constants';
|
|
5
5
|
import { EarningStatus, YieldPoolInfo, YieldPositionInfo } from '@subwallet/extension-base/types';
|
|
6
|
+
import BigNumber from 'bignumber.js';
|
|
6
7
|
import { ApiPromise } from '@polkadot/api';
|
|
8
|
+
import { Codec } from '@polkadot/types/types';
|
|
7
9
|
import { BN } from '@polkadot/util';
|
|
8
10
|
export interface PalletDappsStakingDappInfo {
|
|
9
11
|
address: string;
|
|
@@ -97,6 +99,7 @@ export declare function calcInflationUniformEraPayout(totalIssuance: BN, yearlyI
|
|
|
97
99
|
export declare function calcInflationRewardCurve(minInflation: number, stakedFraction: number, idealStake: number, idealInterest: number, falloff: number): number;
|
|
98
100
|
export declare function calculateInflation(totalEraStake: BN, totalIssuance: BN, numAuctions: number, networkKey: string): number;
|
|
99
101
|
export declare function calculateChainStakedReturn(inflation: number, totalEraStake: BN, totalIssuance: BN, networkKey: string): number;
|
|
102
|
+
export declare function calculateChainStakedReturnV2(chainInfo: _ChainInfo, totalIssuance: string, erasPerDay: number, lastTotalStaked: string, validatorEraReward: BigNumber, isCompound?: boolean): number;
|
|
100
103
|
export declare function calculateAlephZeroValidatorReturn(chainStakedReturn: number, commission: number): number;
|
|
101
104
|
export declare function calculateTernoaValidatorReturn(rewardPerValidator: number, validatorStake: number, commission: number): number;
|
|
102
105
|
export declare function calculateValidatorStakedReturn(chainStakedReturn: number, totalValidatorStake: BN, avgStake: BN, commission: number): number;
|
|
@@ -154,6 +157,8 @@ export declare function isActionFromValidator(stakingType: StakingType, chain: s
|
|
|
154
157
|
export declare function getWithdrawalInfo(nominatorMetadata: NominatorMetadata): UnstakingInfo | undefined;
|
|
155
158
|
export declare function getEarningStatusByNominations(bnTotalActiveStake: BN, nominationList: NominationInfo[]): EarningStatus;
|
|
156
159
|
export declare function getValidatorLabel(chain: string): "dApp" | "Validator" | "Collator";
|
|
160
|
+
export declare function getAvgValidatorEraReward(supportedDays: number, eraRewardHistory: Codec[]): BigNumber;
|
|
161
|
+
export declare function getSupportedDaysByHistoryDepth(erasPerDay: number, maxSupportedEras: number): 15 | 30;
|
|
157
162
|
export declare const getMinStakeErrorMessage: (chainInfo: _ChainInfo, bnMinStake: BN) => string;
|
|
158
163
|
export declare const getMaxValidatorErrorMessage: (chainInfo: _ChainInfo, max: number) => string;
|
|
159
164
|
export declare const getExistUnstakeErrorMessage: (chain: string, type?: StakingType, isStakeMore?: boolean) => string;
|
|
@@ -9,6 +9,7 @@ import { _STAKING_CHAIN_GROUP } from '@subwallet/extension-base/services/earning
|
|
|
9
9
|
import { EarningStatus, UnstakingStatus, YieldPoolType } from '@subwallet/extension-base/types';
|
|
10
10
|
import { detectTranslate, parseRawNumber, reformatAddress } from '@subwallet/extension-base/utils';
|
|
11
11
|
import { balanceFormatter, formatNumber } from '@subwallet/extension-base/utils/number';
|
|
12
|
+
import BigNumber from 'bignumber.js';
|
|
12
13
|
import { t } from 'i18next';
|
|
13
14
|
import { BN, BN_BILLION, BN_HUNDRED, BN_MILLION, BN_THOUSAND, BN_ZERO, bnToU8a, stringToU8a, u8aConcat } from '@polkadot/util';
|
|
14
15
|
export let PalletParachainStakingRequestType;
|
|
@@ -71,6 +72,24 @@ export function calculateChainStakedReturn(inflation, totalEraStake, totalIssuan
|
|
|
71
72
|
|
|
72
73
|
return stakedReturn;
|
|
73
74
|
}
|
|
75
|
+
export function calculateChainStakedReturnV2(chainInfo, totalIssuance, erasPerDay, lastTotalStaked, validatorEraReward, isCompound) {
|
|
76
|
+
const DAYS_PER_YEAR = 365;
|
|
77
|
+
// @ts-ignore
|
|
78
|
+
const DECIMAL = chainInfo.substrateInfo.decimals;
|
|
79
|
+
const lastTotalStakedUnit = new BigNumber(lastTotalStaked).dividedBy(new BigNumber(10 ** DECIMAL));
|
|
80
|
+
const totalIssuanceUnit = new BigNumber(totalIssuance).dividedBy(new BigNumber(10 ** DECIMAL));
|
|
81
|
+
const supplyStaked = lastTotalStakedUnit.dividedBy(totalIssuanceUnit);
|
|
82
|
+
const dayRewardRate = validatorEraReward.multipliedBy(erasPerDay).dividedBy(totalIssuance).multipliedBy(100);
|
|
83
|
+
let inflationToStakers = new BigNumber(0);
|
|
84
|
+
if (!isCompound) {
|
|
85
|
+
inflationToStakers = dayRewardRate.multipliedBy(DAYS_PER_YEAR);
|
|
86
|
+
} else {
|
|
87
|
+
const multiplier = dayRewardRate.dividedBy(100).plus(1).exponentiatedBy(365);
|
|
88
|
+
inflationToStakers = new BigNumber(100).multipliedBy(multiplier).minus(100);
|
|
89
|
+
}
|
|
90
|
+
const averageRewardRate = inflationToStakers.dividedBy(supplyStaked);
|
|
91
|
+
return averageRewardRate.toNumber();
|
|
92
|
+
}
|
|
74
93
|
export function calculateAlephZeroValidatorReturn(chainStakedReturn, commission) {
|
|
75
94
|
return chainStakedReturn * (100 - commission) / 100;
|
|
76
95
|
}
|
|
@@ -310,6 +329,27 @@ export function getValidatorLabel(chain) {
|
|
|
310
329
|
}
|
|
311
330
|
return 'Collator';
|
|
312
331
|
}
|
|
332
|
+
export function getAvgValidatorEraReward(supportedDays, eraRewardHistory) {
|
|
333
|
+
let sumEraReward = new BigNumber(0);
|
|
334
|
+
let failEra = 0;
|
|
335
|
+
for (const _item of eraRewardHistory) {
|
|
336
|
+
const item = _item.toString();
|
|
337
|
+
if (!item) {
|
|
338
|
+
failEra += 1;
|
|
339
|
+
} else {
|
|
340
|
+
const eraReward = new BigNumber(item);
|
|
341
|
+
sumEraReward = sumEraReward.plus(eraReward);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
return sumEraReward.dividedBy(new BigNumber(supportedDays - failEra));
|
|
345
|
+
}
|
|
346
|
+
export function getSupportedDaysByHistoryDepth(erasPerDay, maxSupportedEras) {
|
|
347
|
+
if (maxSupportedEras / erasPerDay > 30) {
|
|
348
|
+
return 30;
|
|
349
|
+
} else {
|
|
350
|
+
return 15;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
313
353
|
export const getMinStakeErrorMessage = (chainInfo, bnMinStake) => {
|
|
314
354
|
const tokenInfo = _getChainNativeTokenBasicInfo(chainInfo);
|
|
315
355
|
const number = formatNumber(bnMinStake.toString(), tokenInfo.decimals || 0, balanceFormatter);
|