@subwallet/extension-base 1.1.35-beta.1 → 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/environment.js +16 -14
- package/cjs/utils/eth/mergeTransactionAndSignature.js +25 -10
- package/cjs/utils/eth.js +51 -2
- package/cjs/utils/mv3.js +1 -1
- 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/environment.js +16 -11
- package/utils/eth/mergeTransactionAndSignature.js +25 -10
- package/utils/eth.d.ts +14 -0
- package/utils/eth.js +48 -0
- package/utils/mv3.js +1 -1
- 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
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
5
5
|
import { BasicTxErrorType, ExtrinsicType, StakingTxErrorType } from '@subwallet/extension-base/background/KoniTypes';
|
|
6
|
-
import { calculateAlephZeroValidatorReturn,
|
|
6
|
+
import { calculateAlephZeroValidatorReturn, calculateChainStakedReturnV2, calculateInflation, calculateTernoaValidatorReturn, calculateValidatorStakedReturn, getAvgValidatorEraReward, getCommission, getMaxValidatorErrorMessage, getMinStakeErrorMessage, getSupportedDaysByHistoryDepth } from '@subwallet/extension-base/koni/api/staking/bonding/utils';
|
|
7
7
|
import { _EXPECTED_BLOCK_TIME, _STAKING_ERA_LENGTH_MAP } from '@subwallet/extension-base/services/chain-service/constants';
|
|
8
8
|
import { _getChainSubstrateAddressPrefix } from '@subwallet/extension-base/services/chain-service/utils';
|
|
9
9
|
import { _STAKING_CHAIN_GROUP } from '@subwallet/extension-base/services/earning-service/constants';
|
|
@@ -53,7 +53,15 @@ export default class RelayNativeStakingPoolHandler extends BaseNativeStakingPool
|
|
|
53
53
|
const maxNominations = ((_substrateApi$api$con = substrateApi.api.consts.staking) === null || _substrateApi$api$con === void 0 ? void 0 : (_substrateApi$api$con2 = _substrateApi$api$con.maxNominations) === null || _substrateApi$api$con2 === void 0 ? void 0 : _substrateApi$api$con2.toString()) || '16'; // TODO
|
|
54
54
|
const maxUnlockingChunks = substrateApi.api.consts.staking.maxUnlockingChunks.toString();
|
|
55
55
|
const unlockingEras = substrateApi.api.consts.staking.bondingDuration.toString();
|
|
56
|
-
const
|
|
56
|
+
const maxSupportedEras = substrateApi.api.consts.staking.historyDepth.toString();
|
|
57
|
+
const erasPerDay = 24 / _STAKING_ERA_LENGTH_MAP[chainInfo.slug]; // Can be exactly calculate from epochDuration, blockTime, sessionsPerEra
|
|
58
|
+
|
|
59
|
+
const supportedDays = getSupportedDaysByHistoryDepth(erasPerDay, parseInt(maxSupportedEras));
|
|
60
|
+
const startEra = parseInt(currentEra) - supportedDays * erasPerDay;
|
|
61
|
+
const [_EraStakeInfo, _totalIssuance, _auctionCounter, _minNominatorBond, _counterForNominators, _minimumActiveStake, ..._eraReward] = await Promise.all([substrateApi.api.query.staking.erasTotalStake.multi([parseInt(currentEra), parseInt(currentEra) - 1]), substrateApi.api.query.balances.totalIssuance(), (_substrateApi$api$que2 = substrateApi.api.query.auctions) === null || _substrateApi$api$que2 === void 0 ? void 0 : _substrateApi$api$que2.auctionCounter(), substrateApi.api.query.staking.minNominatorBond(), substrateApi.api.query.staking.counterForNominators(), ((_substrateApi$api$que3 = substrateApi.api.query) === null || _substrateApi$api$que3 === void 0 ? void 0 : (_substrateApi$api$que4 = _substrateApi$api$que3.staking) === null || _substrateApi$api$que4 === void 0 ? void 0 : _substrateApi$api$que4.minimumActiveStake) && ((_substrateApi$api$que5 = substrateApi.api.query) === null || _substrateApi$api$que5 === void 0 ? void 0 : (_substrateApi$api$que6 = _substrateApi$api$que5.staking) === null || _substrateApi$api$que6 === void 0 ? void 0 : _substrateApi$api$que6.minimumActiveStake()), substrateApi.api.query.staking.erasValidatorReward.multi([...Array(supportedDays).keys()].map(i => i + startEra))]);
|
|
62
|
+
const [_totalEraStake, _lastTotalStaked] = _EraStakeInfo;
|
|
63
|
+
const validatorEraReward = getAvgValidatorEraReward(supportedDays, _eraReward[0]);
|
|
64
|
+
const lastTotalStaked = _lastTotalStaked.toString();
|
|
57
65
|
const minActiveStake = (_minimumActiveStake === null || _minimumActiveStake === void 0 ? void 0 : _minimumActiveStake.toString()) || '0';
|
|
58
66
|
const minNominatorBond = _minNominatorBond.toString();
|
|
59
67
|
const bnMinActiveStake = new BN(minActiveStake);
|
|
@@ -65,7 +73,7 @@ export default class RelayNativeStakingPoolHandler extends BaseNativeStakingPool
|
|
|
65
73
|
const bnTotalEraStake = new BN(rawTotalEraStake);
|
|
66
74
|
const bnTotalIssuance = new BN(rawTotalIssuance);
|
|
67
75
|
const inflation = calculateInflation(bnTotalEraStake, bnTotalIssuance, numAuctions, chainInfo.slug);
|
|
68
|
-
const expectedReturn =
|
|
76
|
+
const expectedReturn = calculateChainStakedReturnV2(chainInfo, rawTotalIssuance, erasPerDay, lastTotalStaked, validatorEraReward, true);
|
|
69
77
|
const eraTime = _STAKING_ERA_LENGTH_MAP[chainInfo.slug] || _STAKING_ERA_LENGTH_MAP.default; // in hours
|
|
70
78
|
const unlockingPeriod = parseInt(unlockingEras) * eraTime; // in hours
|
|
71
79
|
const farmerCount = _counterForNominators.toPrimitive();
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
5
5
|
import { APIItemState, BasicTxErrorType, ChainType, ExtrinsicType, StakingTxErrorType, StakingType } from '@subwallet/extension-base/background/KoniTypes';
|
|
6
|
-
import {
|
|
6
|
+
import { calculateChainStakedReturnV2, calculateInflation, getAvgValidatorEraReward, getExistUnstakeErrorMessage, getMinStakeErrorMessage, getSupportedDaysByHistoryDepth, parsePoolStashAddress } from '@subwallet/extension-base/koni/api/staking/bonding/utils';
|
|
7
7
|
import { _EXPECTED_BLOCK_TIME, _STAKING_ERA_LENGTH_MAP } from '@subwallet/extension-base/services/chain-service/constants';
|
|
8
8
|
import { _getChainSubstrateAddressPrefix } from '@subwallet/extension-base/services/chain-service/utils';
|
|
9
9
|
import { EarningStatus, UnstakingStatus, YieldPoolType, YieldStepType } from '@subwallet/extension-base/types';
|
|
@@ -78,7 +78,15 @@ export default class NominationPoolHandler extends BasePoolHandler {
|
|
|
78
78
|
const currentEra = _currentEra.toString();
|
|
79
79
|
const maxUnlockingChunks = substrateApi.api.consts.staking.maxUnlockingChunks.toString();
|
|
80
80
|
const unlockingEras = substrateApi.api.consts.staking.bondingDuration.toString();
|
|
81
|
-
const
|
|
81
|
+
const maxSupportedEras = substrateApi.api.consts.staking.historyDepth.toString();
|
|
82
|
+
const erasPerDay = 24 / _STAKING_ERA_LENGTH_MAP[chainInfo.slug]; // Can be exactly calculate from epochDuration, blockTime, sessionsPerEra
|
|
83
|
+
|
|
84
|
+
const supportedDays = getSupportedDaysByHistoryDepth(erasPerDay, parseInt(maxSupportedEras));
|
|
85
|
+
const startEra = parseInt(currentEra) - supportedDays * erasPerDay;
|
|
86
|
+
const [_EraStakeInfo, _totalIssuance, _auctionCounter, _minPoolJoin, ..._eraReward] = await Promise.all([substrateApi.api.query.staking.erasTotalStake.multi([parseInt(currentEra), parseInt(currentEra) - 1]), substrateApi.api.query.balances.totalIssuance(), (_substrateApi$api$que2 = substrateApi.api.query.auctions) === null || _substrateApi$api$que2 === void 0 ? void 0 : _substrateApi$api$que2.auctionCounter(), (_substrateApi$api$que3 = substrateApi.api.query) === null || _substrateApi$api$que3 === void 0 ? void 0 : (_substrateApi$api$que4 = _substrateApi$api$que3.nominationPools) === null || _substrateApi$api$que4 === void 0 ? void 0 : _substrateApi$api$que4.minJoinBond(), substrateApi.api.query.staking.erasValidatorReward.multi([...Array(supportedDays).keys()].map(i => i + startEra))]);
|
|
87
|
+
const [_totalEraStake, _lastTotalStaked] = _EraStakeInfo;
|
|
88
|
+
const validatorEraReward = getAvgValidatorEraReward(supportedDays, _eraReward[0]);
|
|
89
|
+
const lastTotalStaked = _lastTotalStaked.toString();
|
|
82
90
|
const rawTotalEraStake = _totalEraStake.toString();
|
|
83
91
|
const rawTotalIssuance = _totalIssuance.toString();
|
|
84
92
|
const numAuctions = _auctionCounter ? _auctionCounter.toHuman() : 0;
|
|
@@ -86,7 +94,7 @@ export default class NominationPoolHandler extends BasePoolHandler {
|
|
|
86
94
|
const bnTotalIssuance = new BN(rawTotalIssuance);
|
|
87
95
|
const inflation = calculateInflation(bnTotalEraStake, bnTotalIssuance, numAuctions, chainInfo.slug);
|
|
88
96
|
const minPoolJoin = (_minPoolJoin === null || _minPoolJoin === void 0 ? void 0 : _minPoolJoin.toString()) || undefined;
|
|
89
|
-
const expectedReturn =
|
|
97
|
+
const expectedReturn = calculateChainStakedReturnV2(chainInfo, rawTotalIssuance, erasPerDay, lastTotalStaked, validatorEraReward, true);
|
|
90
98
|
const eraTime = _STAKING_ERA_LENGTH_MAP[this.chain] || _STAKING_ERA_LENGTH_MAP.default; // in hours
|
|
91
99
|
const unlockingPeriod = parseInt(unlockingEras) * eraTime; // in hours
|
|
92
100
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { COMMON_CHAIN_SLUGS } from '@subwallet/chain-list';
|
|
5
4
|
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
6
5
|
import { BasicTxErrorType, ChainType, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
7
6
|
import { ALL_ACCOUNT_KEY } from '@subwallet/extension-base/constants';
|
|
@@ -201,13 +200,16 @@ export default class BaseSpecialStakingPoolHandler extends BasePoolHandler {
|
|
|
201
200
|
const altInputTokenBalance = await this.state.balanceService.getTokenFreeBalance(address, altInputTokenInfo.originChain, altInputTokenSlug);
|
|
202
201
|
const bnAltInputTokenBalance = new BN(altInputTokenBalance.value || '0');
|
|
203
202
|
if (bnAltInputTokenBalance.gt(BN_ZERO)) {
|
|
203
|
+
const altChainInfo = this.state.getChainInfo(altInputTokenInfo.originChain);
|
|
204
|
+
const symbol = altInputTokenInfo.symbol;
|
|
205
|
+
const networkName = altChainInfo.name;
|
|
204
206
|
const step = {
|
|
205
207
|
metadata: {
|
|
206
208
|
sendingValue: bnAmount.toString(),
|
|
207
209
|
originTokenInfo: altInputTokenInfo,
|
|
208
210
|
destinationTokenInfo: inputTokenInfo
|
|
209
211
|
},
|
|
210
|
-
name:
|
|
212
|
+
name: `Transfer ${symbol} from ${networkName}`,
|
|
211
213
|
type: YieldStepType.XCM
|
|
212
214
|
};
|
|
213
215
|
const xcmOriginSubstrateApi = await this.state.getSubstrateApi(altInputTokenInfo.originChain).isReady;
|
|
@@ -404,7 +406,9 @@ export default class BaseSpecialStakingPoolHandler extends BasePoolHandler {
|
|
|
404
406
|
amount
|
|
405
407
|
} = data;
|
|
406
408
|
const destinationTokenSlug = this.inputAsset;
|
|
407
|
-
const
|
|
409
|
+
const altInputTokenSlug = this.altInputAsset || '';
|
|
410
|
+
const altInputTokenInfo = this.state.getAssetBySlug(altInputTokenSlug);
|
|
411
|
+
const originChainInfo = this.state.getChainInfo(altInputTokenInfo.originChain);
|
|
408
412
|
const originTokenSlug = _getChainNativeTokenSlug(originChainInfo);
|
|
409
413
|
const originTokenInfo = this.state.getAssetBySlug(originTokenSlug);
|
|
410
414
|
const destinationTokenInfo = this.state.getAssetBySlug(destinationTokenSlug);
|
|
@@ -54,7 +54,7 @@ export default class EarningService implements StoppableServiceInterface, Persis
|
|
|
54
54
|
getYieldPositionInfo(): Promise<YieldPositionInfo[]>;
|
|
55
55
|
yieldPositionPersistQueue: YieldPositionInfo[];
|
|
56
56
|
resetYieldPositionQueue(): void;
|
|
57
|
-
resetYieldPosition(): void
|
|
57
|
+
resetYieldPosition(): Promise<void>;
|
|
58
58
|
private _getYieldPositionKey;
|
|
59
59
|
updateYieldPosition(data: YieldPositionInfo): void;
|
|
60
60
|
reloadEarning(reset?: boolean): Promise<void>;
|
|
@@ -91,4 +91,5 @@ export default class EarningService implements StoppableServiceInterface, Persis
|
|
|
91
91
|
handleYieldWithdraw(params: RequestYieldWithdrawal): Promise<TransactionData>;
|
|
92
92
|
handleYieldCancelUnstake(params: RequestStakeCancelWithdrawal): Promise<TransactionData>;
|
|
93
93
|
handleYieldClaimReward(params: RequestStakeClaimReward): Promise<TransactionData>;
|
|
94
|
+
resetWallet(): Promise<void>;
|
|
94
95
|
}
|
|
@@ -12,7 +12,7 @@ import { YieldPoolType } from '@subwallet/extension-base/types';
|
|
|
12
12
|
import { addLazy, categoryAddresses, createPromiseHandler } from '@subwallet/extension-base/utils';
|
|
13
13
|
import { fetchStaticCache } from '@subwallet/extension-base/utils/fetchStaticCache';
|
|
14
14
|
import { BehaviorSubject } from 'rxjs';
|
|
15
|
-
import { AcalaLiquidStakingPoolHandler, AmplitudeNativeStakingPoolHandler, AstarNativeStakingPoolHandler, BifrostLiquidStakingPoolHandler, InterlayLendingPoolHandler, NominationPoolHandler, ParallelLiquidStakingPoolHandler, ParaNativeStakingPoolHandler, RelayNativeStakingPoolHandler, StellaSwapLiquidStakingPoolHandler } from "./handlers/index.js";
|
|
15
|
+
import { AcalaLiquidStakingPoolHandler, AmplitudeNativeStakingPoolHandler, AstarNativeStakingPoolHandler, BifrostLiquidStakingPoolHandler, BifrostMantaLiquidStakingPoolHandler, InterlayLendingPoolHandler, NominationPoolHandler, ParallelLiquidStakingPoolHandler, ParaNativeStakingPoolHandler, RelayNativeStakingPoolHandler, StellaSwapLiquidStakingPoolHandler } from "./handlers/index.js";
|
|
16
16
|
const fetchPoolsData = async () => {
|
|
17
17
|
const fetchData = await fetchStaticCache('earning/yield-pools.json', {
|
|
18
18
|
data: {}
|
|
@@ -67,6 +67,7 @@ export default class EarningService {
|
|
|
67
67
|
if (_STAKING_CHAIN_GROUP.liquidStaking.includes(chain)) {
|
|
68
68
|
if (chain === 'bifrost_dot') {
|
|
69
69
|
handlers.push(new BifrostLiquidStakingPoolHandler(this.state, chain));
|
|
70
|
+
handlers.push(new BifrostMantaLiquidStakingPoolHandler(this.state, chain));
|
|
70
71
|
}
|
|
71
72
|
if (chain === 'acala') {
|
|
72
73
|
handlers.push(new AcalaLiquidStakingPoolHandler(this.state, chain));
|
|
@@ -404,9 +405,10 @@ export default class EarningService {
|
|
|
404
405
|
resetYieldPositionQueue() {
|
|
405
406
|
this.yieldPositionPersistQueue = [];
|
|
406
407
|
}
|
|
407
|
-
resetYieldPosition() {
|
|
408
|
+
async resetYieldPosition() {
|
|
408
409
|
this.yieldPositionSubject.next({});
|
|
409
410
|
this.yieldPositionPersistQueue = [];
|
|
411
|
+
await this.dbService.stores.yieldPosition.clear();
|
|
410
412
|
}
|
|
411
413
|
_getYieldPositionKey(slug, address) {
|
|
412
414
|
return `${slug}---${address}`;
|
|
@@ -433,7 +435,7 @@ export default class EarningService {
|
|
|
433
435
|
this.runUnsubscribePoolsPosition();
|
|
434
436
|
this.runUnsubscribeStakingRewardInterval();
|
|
435
437
|
this.runUnsubscribeEarningRewardHistoryInterval();
|
|
436
|
-
reset && this.resetYieldPosition();
|
|
438
|
+
reset && (await this.resetYieldPosition());
|
|
437
439
|
await this.runSubscribePoolsPosition();
|
|
438
440
|
this.runSubscribeStakingRewardInterval();
|
|
439
441
|
this.runSubscribeEarningRewardHistoryInterval();
|
|
@@ -719,4 +721,9 @@ export default class EarningService {
|
|
|
719
721
|
/* Other */
|
|
720
722
|
|
|
721
723
|
/* Handle actions */
|
|
724
|
+
|
|
725
|
+
// Clear wallet data
|
|
726
|
+
async resetWallet() {
|
|
727
|
+
await this.resetYieldPosition();
|
|
728
|
+
}
|
|
722
729
|
}
|
|
@@ -30,15 +30,18 @@ export default class NotificationService {
|
|
|
30
30
|
const link = action === null || action === void 0 ? void 0 : action.url;
|
|
31
31
|
const onClick = action === null || action === void 0 ? void 0 : action.click;
|
|
32
32
|
const onButtonClick = action === null || action === void 0 ? void 0 : action.buttonClick;
|
|
33
|
-
|
|
33
|
+
const options = {
|
|
34
34
|
type: 'basic',
|
|
35
35
|
title,
|
|
36
36
|
message,
|
|
37
37
|
iconUrl: '/images/icon-128.png',
|
|
38
38
|
priority: 2,
|
|
39
|
-
isClickable: !!link || !!onClick
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
isClickable: !!link || !!onClick
|
|
40
|
+
};
|
|
41
|
+
if (!isFirefox) {
|
|
42
|
+
options.buttons = buttons;
|
|
43
|
+
}
|
|
44
|
+
(_chrome = chrome) === null || _chrome === void 0 ? void 0 : (_chrome$notifications = _chrome.notifications) === null || _chrome$notifications === void 0 ? void 0 : _chrome$notifications.create(options, notificationId => {
|
|
42
45
|
if (link || onClick) {
|
|
43
46
|
chrome.notifications.onClicked.addListener(nId => {
|
|
44
47
|
if (nId === notificationId) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { TypedTransaction } from '@ethereumjs/tx';
|
|
1
2
|
import { ConfirmationDefinitions, ConfirmationsQueue, ConfirmationsQueueItemOptions, ConfirmationType, RequestConfirmationComplete } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
3
|
import RequestService from '@subwallet/extension-base/services/request-service';
|
|
3
|
-
import { Transaction } from 'ethereumjs-tx';
|
|
4
4
|
import { BehaviorSubject } from 'rxjs';
|
|
5
5
|
import { TransactionConfig } from 'web3-core';
|
|
6
6
|
export default class EvmRequestHandler {
|
|
@@ -13,7 +13,7 @@ export default class EvmRequestHandler {
|
|
|
13
13
|
addConfirmation<CT extends ConfirmationType>(id: string, url: string, type: CT, payload: ConfirmationDefinitions[CT][0]['payload'], options?: ConfirmationsQueueItemOptions, validator?: (input: ConfirmationDefinitions[CT][1]) => Error | undefined): Promise<ConfirmationDefinitions[CT][1]>;
|
|
14
14
|
updateConfirmation<CT extends ConfirmationType>(id: string, type: CT, payload: ConfirmationDefinitions[CT][0]['payload'], options?: ConfirmationsQueueItemOptions, validator?: (input: ConfirmationDefinitions[CT][1]) => Error | undefined): void;
|
|
15
15
|
private signMessage;
|
|
16
|
-
configToTransaction(config: TransactionConfig):
|
|
16
|
+
configToTransaction(config: TransactionConfig): TypedTransaction;
|
|
17
17
|
private signTransaction;
|
|
18
18
|
private decorateResult;
|
|
19
19
|
completeConfirmation(request: RequestConfirmationComplete): Promise<boolean>;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import Common from '@ethereumjs/common';
|
|
4
|
+
import { Common } from '@ethereumjs/common';
|
|
5
|
+
import { FeeMarketEIP1559Transaction, LegacyTransaction } from '@ethereumjs/tx';
|
|
5
6
|
import { EvmProviderError } from '@subwallet/extension-base/background/errors/EvmProviderError';
|
|
6
7
|
import { EvmProviderErrorType } from '@subwallet/extension-base/background/KoniTypes';
|
|
7
8
|
import { anyNumberToBN } from '@subwallet/extension-base/utils/eth';
|
|
8
9
|
import { isInternalRequest } from '@subwallet/extension-base/utils/request';
|
|
9
10
|
import keyring from '@subwallet/ui-keyring';
|
|
10
|
-
import
|
|
11
|
-
import { Transaction } from 'ethereumjs-tx';
|
|
11
|
+
import BigN from 'bignumber.js';
|
|
12
12
|
import { toBuffer } from 'ethereumjs-util';
|
|
13
13
|
import { t } from 'i18next';
|
|
14
14
|
import { BehaviorSubject } from 'rxjs';
|
|
15
|
-
import { logger as createLogger } from '@polkadot/util';
|
|
15
|
+
import { bnToHex, hexAddPrefix, logger as createLogger } from '@polkadot/util';
|
|
16
16
|
export default class EvmRequestHandler {
|
|
17
17
|
#requestService;
|
|
18
18
|
#logger;
|
|
@@ -126,35 +126,48 @@ export default class EvmRequestHandler {
|
|
|
126
126
|
}
|
|
127
127
|
configToTransaction(config) {
|
|
128
128
|
function formatField(input) {
|
|
129
|
-
if (typeof input === 'string') {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
return new BN(input);
|
|
134
|
-
}
|
|
129
|
+
if (typeof input === 'string' || typeof input === 'number') {
|
|
130
|
+
return hexAddPrefix(new BigN(input).toString(16));
|
|
131
|
+
} else if (typeof input === 'undefined') {
|
|
132
|
+
return undefined;
|
|
135
133
|
}
|
|
136
|
-
return input;
|
|
134
|
+
return bnToHex(input);
|
|
137
135
|
}
|
|
138
|
-
|
|
139
|
-
// Convert any string, number to number with BigN exclude hex string
|
|
140
|
-
const txData = {
|
|
141
|
-
from: config.from,
|
|
142
|
-
nonce: formatField(config.nonce),
|
|
143
|
-
gasPrice: formatField(config.gasPrice),
|
|
144
|
-
gasLimit: formatField(config.gas),
|
|
145
|
-
to: config.to,
|
|
146
|
-
value: formatField(config.value),
|
|
147
|
-
data: toBuffer(config.data)
|
|
148
|
-
};
|
|
149
136
|
const common = Common.custom({
|
|
150
137
|
chainId: config.chainId,
|
|
151
|
-
defaultHardfork: '
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
return new Transaction(txData, {
|
|
156
|
-
common
|
|
138
|
+
defaultHardfork: 'london',
|
|
139
|
+
networkId: config.chainId
|
|
140
|
+
}, {
|
|
141
|
+
eips: [1559]
|
|
157
142
|
});
|
|
143
|
+
if (config.maxFeePerGas) {
|
|
144
|
+
const txData = {
|
|
145
|
+
nonce: formatField(config.nonce),
|
|
146
|
+
gasLimit: formatField(config.gas),
|
|
147
|
+
to: config.to,
|
|
148
|
+
value: formatField(config.value),
|
|
149
|
+
data: toBuffer(config.data),
|
|
150
|
+
maxFeePerGas: formatField(config.maxFeePerGas),
|
|
151
|
+
maxPriorityFeePerGas: formatField(config.maxPriorityFeePerGas),
|
|
152
|
+
chainId: config.chainId
|
|
153
|
+
};
|
|
154
|
+
return new FeeMarketEIP1559Transaction(txData, {
|
|
155
|
+
common
|
|
156
|
+
});
|
|
157
|
+
} else {
|
|
158
|
+
// Convert any string, number to number with BigN exclude hex string
|
|
159
|
+
const txData = {
|
|
160
|
+
nonce: formatField(config.nonce),
|
|
161
|
+
gasLimit: formatField(config.gas),
|
|
162
|
+
gasPrice: formatField(config.gasPrice),
|
|
163
|
+
to: config.to,
|
|
164
|
+
value: formatField(config.value),
|
|
165
|
+
data: toBuffer(config.data)
|
|
166
|
+
};
|
|
167
|
+
return new LegacyTransaction(txData, {
|
|
168
|
+
common
|
|
169
|
+
});
|
|
170
|
+
}
|
|
158
171
|
}
|
|
159
172
|
async signTransaction(confirmation) {
|
|
160
173
|
const transaction = confirmation.payload;
|
|
@@ -163,6 +176,8 @@ export default class EvmRequestHandler {
|
|
|
163
176
|
from,
|
|
164
177
|
gas,
|
|
165
178
|
gasPrice,
|
|
179
|
+
maxFeePerGas,
|
|
180
|
+
maxPriorityFeePerGas,
|
|
166
181
|
value
|
|
167
182
|
} = transaction;
|
|
168
183
|
const pair = keyring.getPair(from);
|
|
@@ -171,7 +186,9 @@ export default class EvmRequestHandler {
|
|
|
171
186
|
gas: anyNumberToBN(gas).toNumber(),
|
|
172
187
|
value: anyNumberToBN(value).toNumber(),
|
|
173
188
|
gasPrice: anyNumberToBN(gasPrice).toNumber(),
|
|
174
|
-
gasLimit: anyNumberToBN(estimateGas).toNumber()
|
|
189
|
+
gasLimit: anyNumberToBN(estimateGas).toNumber(),
|
|
190
|
+
maxFeePerGas: anyNumberToBN(maxFeePerGas).toNumber(),
|
|
191
|
+
maxPriorityFeePerGas: anyNumberToBN(maxPriorityFeePerGas).toNumber()
|
|
175
192
|
// nonce: await web3.eth.getTransactionCount(from) // Todo: fill this value from transaction service
|
|
176
193
|
};
|
|
177
194
|
|
|
@@ -15,9 +15,10 @@ import { getExplorerLink, parseTransactionData } from '@subwallet/extension-base
|
|
|
15
15
|
import { isWalletConnectRequest } from '@subwallet/extension-base/services/wallet-connect-service/helpers';
|
|
16
16
|
import { YieldPoolType } from '@subwallet/extension-base/types';
|
|
17
17
|
import { reformatAddress } from '@subwallet/extension-base/utils';
|
|
18
|
-
import { anyNumberToBN,
|
|
18
|
+
import { anyNumberToBN, calculateGasFeeParams } from '@subwallet/extension-base/utils/eth';
|
|
19
19
|
import { mergeTransactionAndSignature } from '@subwallet/extension-base/utils/eth/mergeTransactionAndSignature';
|
|
20
20
|
import { isContractAddress, parseContractInput } from '@subwallet/extension-base/utils/eth/parseTransaction';
|
|
21
|
+
import { BN_ZERO } from '@subwallet/extension-base/utils/number';
|
|
21
22
|
import keyring from '@subwallet/ui-keyring';
|
|
22
23
|
import BigN from 'bignumber.js';
|
|
23
24
|
import { addHexPrefix } from 'ethereumjs-util';
|
|
@@ -93,7 +94,8 @@ export default class TransactionService {
|
|
|
93
94
|
const estimateFee = {
|
|
94
95
|
symbol: '',
|
|
95
96
|
decimals: 0,
|
|
96
|
-
value: ''
|
|
97
|
+
value: '',
|
|
98
|
+
tooHigh: false
|
|
97
99
|
};
|
|
98
100
|
const chainInfo = this.state.chainService.getChainInfoByKey(chain);
|
|
99
101
|
if (!chainInfo) {
|
|
@@ -114,10 +116,16 @@ export default class TransactionService {
|
|
|
114
116
|
if (!web3) {
|
|
115
117
|
validationResponse.errors.push(new TransactionError(BasicTxErrorType.CHAIN_DISCONNECTED, undefined));
|
|
116
118
|
} else {
|
|
117
|
-
const _price = await web3.api.eth.getGasPrice();
|
|
118
|
-
const gasPrice = recalculateGasPrice(_price, chainInfo.slug);
|
|
119
119
|
const gasLimit = await web3.api.eth.estimateGas(transaction);
|
|
120
|
-
|
|
120
|
+
const priority = await calculateGasFeeParams(web3, chainInfo.slug);
|
|
121
|
+
if (priority.baseGasFee) {
|
|
122
|
+
const priorityFee = priority.baseGasFee.plus(priority.maxPriorityFeePerGas);
|
|
123
|
+
const maxFee = priority.maxFeePerGas.lte(priorityFee) ? priority.maxFeePerGas : priorityFee;
|
|
124
|
+
estimateFee.value = maxFee.multipliedBy(gasLimit).toFixed(0);
|
|
125
|
+
} else {
|
|
126
|
+
estimateFee.value = new BigN(priority.gasPrice).multipliedBy(gasLimit).toFixed(0);
|
|
127
|
+
}
|
|
128
|
+
estimateFee.tooHigh = priority.busyNetwork;
|
|
121
129
|
}
|
|
122
130
|
}
|
|
123
131
|
} catch (e) {
|
|
@@ -522,6 +530,7 @@ export default class TransactionService {
|
|
|
522
530
|
case ExtrinsicType.MINT_QDOT:
|
|
523
531
|
case ExtrinsicType.MINT_LDOT:
|
|
524
532
|
case ExtrinsicType.MINT_SDOT:
|
|
533
|
+
case ExtrinsicType.MINT_VMANTA:
|
|
525
534
|
|
|
526
535
|
// eslint-disable-next-line no-fallthrough
|
|
527
536
|
case ExtrinsicType.MINT_VDOT:
|
|
@@ -575,12 +584,14 @@ export default class TransactionService {
|
|
|
575
584
|
break;
|
|
576
585
|
}
|
|
577
586
|
case ExtrinsicType.UNSTAKE_VDOT:
|
|
587
|
+
case ExtrinsicType.UNSTAKE_VMANTA:
|
|
578
588
|
case ExtrinsicType.UNSTAKE_LDOT:
|
|
579
589
|
case ExtrinsicType.UNSTAKE_SDOT:
|
|
580
590
|
case ExtrinsicType.UNSTAKE_STDOT:
|
|
581
591
|
case ExtrinsicType.REDEEM_STDOT:
|
|
582
592
|
case ExtrinsicType.REDEEM_LDOT:
|
|
583
593
|
case ExtrinsicType.REDEEM_SDOT:
|
|
594
|
+
case ExtrinsicType.REDEEM_VMANTA:
|
|
584
595
|
|
|
585
596
|
// eslint-disable-next-line no-fallthrough
|
|
586
597
|
case ExtrinsicType.REDEEM_VDOT:
|
|
@@ -837,17 +848,33 @@ export default class TransactionService {
|
|
|
837
848
|
this.eventService.emit('transaction.timeout', transaction);
|
|
838
849
|
}
|
|
839
850
|
generateHashPayload(chain, transaction) {
|
|
840
|
-
var _transaction$nonce;
|
|
841
851
|
const chainInfo = this.state.chainService.getChainInfoByKey(chain);
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
852
|
+
let txObject;
|
|
853
|
+
const max = anyNumberToBN(transaction.maxFeePerGas);
|
|
854
|
+
if (max.gt(BN_ZERO)) {
|
|
855
|
+
var _transaction$nonce;
|
|
856
|
+
txObject = {
|
|
857
|
+
nonce: (_transaction$nonce = transaction.nonce) !== null && _transaction$nonce !== void 0 ? _transaction$nonce : 0,
|
|
858
|
+
maxFeePerGas: addHexPrefix(anyNumberToBN(transaction.maxFeePerGas).toString(16)),
|
|
859
|
+
maxPriorityFeePerGas: addHexPrefix(anyNumberToBN(transaction.maxPriorityFeePerGas).toString(16)),
|
|
860
|
+
gasLimit: addHexPrefix(anyNumberToBN(transaction.gas).toString(16)),
|
|
861
|
+
to: transaction.to !== undefined ? transaction.to : '',
|
|
862
|
+
value: addHexPrefix(anyNumberToBN(transaction.value).toString(16)),
|
|
863
|
+
data: transaction.data,
|
|
864
|
+
chainId: _getEvmChainId(chainInfo)
|
|
865
|
+
};
|
|
866
|
+
} else {
|
|
867
|
+
var _transaction$nonce2;
|
|
868
|
+
txObject = {
|
|
869
|
+
nonce: (_transaction$nonce2 = transaction.nonce) !== null && _transaction$nonce2 !== void 0 ? _transaction$nonce2 : 0,
|
|
870
|
+
gasPrice: addHexPrefix(anyNumberToBN(transaction.gasPrice).toString(16)),
|
|
871
|
+
gasLimit: addHexPrefix(anyNumberToBN(transaction.gas).toString(16)),
|
|
872
|
+
to: transaction.to !== undefined ? transaction.to : '',
|
|
873
|
+
value: addHexPrefix(anyNumberToBN(transaction.value).toString(16)),
|
|
874
|
+
data: transaction.data,
|
|
875
|
+
chainId: _getEvmChainId(chainInfo)
|
|
876
|
+
};
|
|
877
|
+
}
|
|
851
878
|
return ethers.Transaction.from(txObject).unsignedSerialized;
|
|
852
879
|
}
|
|
853
880
|
async signAndSendEvmTransaction({
|
|
@@ -912,6 +939,8 @@ export default class TransactionService {
|
|
|
912
939
|
nonce: (_payload$nonce = payload.nonce) !== null && _payload$nonce !== void 0 ? _payload$nonce : 0,
|
|
913
940
|
from: payload.from,
|
|
914
941
|
gasPrice: anyNumberToBN(payload.gasPrice).toNumber(),
|
|
942
|
+
maxFeePerGas: anyNumberToBN(payload.maxFeePerGas).toNumber(),
|
|
943
|
+
maxPriorityFeePerGas: anyNumberToBN(payload.maxPriorityFeePerGas).toNumber(),
|
|
915
944
|
gasLimit: anyNumberToBN(payload.gas).toNumber(),
|
|
916
945
|
to: payload.to !== undefined ? payload.to : '',
|
|
917
946
|
value: anyNumberToBN(payload.value).toNumber(),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseRequestSign, ChainType, ExtrinsicDataTypeMap, ExtrinsicStatus, ExtrinsicType, FeeData, ValidateTransactionResponse } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
2
|
import EventEmitter from 'eventemitter3';
|
|
3
3
|
import { TransactionConfig } from 'web3-core';
|
|
4
4
|
import { SubmittableExtrinsic } from '@polkadot/api/promise/types';
|
|
@@ -16,7 +16,7 @@ export interface SWTransaction extends ValidateTransactionResponse, Partial<Pick
|
|
|
16
16
|
extrinsicType: ExtrinsicType;
|
|
17
17
|
createdAt: number;
|
|
18
18
|
updatedAt: number;
|
|
19
|
-
estimateFee?:
|
|
19
|
+
estimateFee?: FeeData;
|
|
20
20
|
transaction: SubmittableExtrinsic | TransactionConfig;
|
|
21
21
|
additionalValidator?: (inputTransaction: SWTransactionResponse) => Promise<void>;
|
|
22
22
|
eventsHandler?: (eventEmitter: TransactionEmitter) => void;
|
package/signers/types.d.ts
CHANGED
package/signers/web3/QrSigner.js
CHANGED
|
@@ -26,6 +26,8 @@ export default class QrSigner {
|
|
|
26
26
|
const txObject = {
|
|
27
27
|
nonce: (_tx$nonce = tx.nonce) !== null && _tx$nonce !== void 0 ? _tx$nonce : 0,
|
|
28
28
|
gasPrice: addHexPrefix(tx.gasPrice.toString(16)),
|
|
29
|
+
maxPriorityFeePerGas: addHexPrefix(tx.maxPriorityFeePerGas.toString(16)),
|
|
30
|
+
maxFeePerGas: addHexPrefix(tx.maxFeePerGas.toString(16)),
|
|
29
31
|
gasLimit: addHexPrefix(tx.gasLimit.toString(16)),
|
|
30
32
|
to: tx.to !== undefined ? tx.to : '',
|
|
31
33
|
value: addHexPrefix(tx.value.toString(16)),
|
|
@@ -38,6 +38,7 @@ export let YieldStepType;
|
|
|
38
38
|
YieldStepType["NOMINATE"] = "NOMINATE";
|
|
39
39
|
YieldStepType["JOIN_NOMINATION_POOL"] = "JOIN_NOMINATION_POOL";
|
|
40
40
|
YieldStepType["MINT_VDOT"] = "MINT_VDOT";
|
|
41
|
+
YieldStepType["MINT_VMANTA"] = "MINT_VMANTA";
|
|
41
42
|
YieldStepType["MINT_LDOT"] = "MINT_LDOT";
|
|
42
43
|
YieldStepType["MINT_QDOT"] = "MINT_QDOT";
|
|
43
44
|
YieldStepType["MINT_SDOT"] = "MINT_SDOT";
|
package/utils/environment.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
var _navigator3;
|
|
1
2
|
// Copyright 2019-2022 @polkadot/extension authors & contributors
|
|
2
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
4
|
|
|
@@ -5,20 +6,22 @@ import { isSupportWindow } from '@subwallet/extension-base/utils/mv3';
|
|
|
5
6
|
import Bowser from 'bowser';
|
|
6
7
|
import { RuntimeEnvironment } from "../background/KoniTypes.js";
|
|
7
8
|
function detectRuntimeEnvironment() {
|
|
8
|
-
if (isSupportWindow) {
|
|
9
|
+
if (isSupportWindow && typeof document !== 'undefined') {
|
|
10
|
+
var _navigator, _window$location, _window$location2;
|
|
9
11
|
// Web environment
|
|
10
12
|
return {
|
|
11
13
|
environment: RuntimeEnvironment.Web,
|
|
12
|
-
version: navigator.userAgent,
|
|
13
|
-
host: window.location.host,
|
|
14
|
-
protocol: window.location.protocol
|
|
14
|
+
version: (_navigator = navigator) === null || _navigator === void 0 ? void 0 : _navigator.userAgent,
|
|
15
|
+
host: (_window$location = window.location) === null || _window$location === void 0 ? void 0 : _window$location.host,
|
|
16
|
+
protocol: (_window$location2 = window.location) === null || _window$location2 === void 0 ? void 0 : _window$location2.protocol
|
|
15
17
|
};
|
|
16
18
|
} else if (typeof self !== 'undefined' && typeof importScripts !== 'undefined') {
|
|
19
|
+
var _navigator2, _self$location;
|
|
17
20
|
// Service Worker environment
|
|
18
21
|
return {
|
|
19
22
|
environment: RuntimeEnvironment.ServiceWorker,
|
|
20
|
-
version: navigator.userAgent,
|
|
21
|
-
host: self.location.host,
|
|
23
|
+
version: (_navigator2 = navigator) === null || _navigator2 === void 0 ? void 0 : _navigator2.userAgent,
|
|
24
|
+
host: (_self$location = self.location) === null || _self$location === void 0 ? void 0 : _self$location.host,
|
|
22
25
|
protocol: 'https'
|
|
23
26
|
};
|
|
24
27
|
} else if (typeof process !== 'undefined' && process.versions && process.versions.node) {
|
|
@@ -28,20 +31,22 @@ function detectRuntimeEnvironment() {
|
|
|
28
31
|
version: process.versions.node
|
|
29
32
|
};
|
|
30
33
|
} else if (typeof chrome !== 'undefined' && typeof chrome.runtime !== 'undefined') {
|
|
34
|
+
var _window$location3, _window$location4;
|
|
31
35
|
// Extension environment (Chrome)
|
|
32
36
|
return {
|
|
33
37
|
environment: RuntimeEnvironment.ExtensionChrome,
|
|
34
38
|
version: chrome.runtime.getManifest().version,
|
|
35
|
-
host: window.location.host,
|
|
36
|
-
protocol: window.location.protocol
|
|
39
|
+
host: (_window$location3 = window.location) === null || _window$location3 === void 0 ? void 0 : _window$location3.host,
|
|
40
|
+
protocol: (_window$location4 = window.location) === null || _window$location4 === void 0 ? void 0 : _window$location4.protocol
|
|
37
41
|
};
|
|
38
42
|
} else if (typeof browser !== 'undefined' && typeof browser.runtime !== 'undefined') {
|
|
43
|
+
var _window$location5, _window$location6;
|
|
39
44
|
// Extension environment (Firefox)
|
|
40
45
|
return {
|
|
41
46
|
environment: RuntimeEnvironment.ExtensionFirefox,
|
|
42
47
|
version: browser.runtime.getManifest().version,
|
|
43
|
-
host: window.location.host,
|
|
44
|
-
protocol: window.location.protocol
|
|
48
|
+
host: (_window$location5 = window.location) === null || _window$location5 === void 0 ? void 0 : _window$location5.host,
|
|
49
|
+
protocol: (_window$location6 = window.location) === null || _window$location6 === void 0 ? void 0 : _window$location6.protocol
|
|
45
50
|
};
|
|
46
51
|
// @ts-ignore
|
|
47
52
|
} else if (typeof WorkerGlobalScope !== 'undefined') {
|
|
@@ -61,7 +66,7 @@ function detectRuntimeEnvironment() {
|
|
|
61
66
|
export const RuntimeInfo = detectRuntimeEnvironment();
|
|
62
67
|
|
|
63
68
|
// Todo: Support more in backend case
|
|
64
|
-
export const BowserParser = Bowser.getParser(typeof navigator !== 'undefined' ? navigator.userAgent : '');
|
|
69
|
+
export const BowserParser = Bowser.getParser(typeof navigator !== 'undefined' ? ((_navigator3 = navigator) === null || _navigator3 === void 0 ? void 0 : _navigator3.userAgent) + '' : '');
|
|
65
70
|
export const isFirefox = BowserParser.getBrowserName(true) === 'firefox';
|
|
66
71
|
export const osName = BowserParser.getOSName();
|
|
67
72
|
export const isMobile = BowserParser.getPlatform().type === 'mobile';
|
|
@@ -10,15 +10,30 @@ export const mergeTransactionAndSignature = (tx, _rawSignature) => {
|
|
|
10
10
|
s: `0x${_signature.substring(64, 128)}`,
|
|
11
11
|
v: parseInt(`0x${_signature.substring(128)}`)
|
|
12
12
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
13
|
+
let transaction;
|
|
14
|
+
if (tx.maxFeePerGas) {
|
|
15
|
+
transaction = {
|
|
16
|
+
nonce: tx.nonce,
|
|
17
|
+
maxFeePerGas: addHexPrefix(tx.maxFeePerGas.toString(16)),
|
|
18
|
+
maxPriorityFeePerGas: addHexPrefix(tx.maxPriorityFeePerGas.toString(16)),
|
|
19
|
+
gasLimit: addHexPrefix(tx.gasLimit.toString(16)),
|
|
20
|
+
to: tx.to,
|
|
21
|
+
value: addHexPrefix(tx.value.toString(16)),
|
|
22
|
+
data: tx.data,
|
|
23
|
+
chainId: tx.chainId,
|
|
24
|
+
signature: signature
|
|
25
|
+
};
|
|
26
|
+
} else {
|
|
27
|
+
transaction = {
|
|
28
|
+
nonce: tx.nonce,
|
|
29
|
+
gasPrice: addHexPrefix(tx.gasPrice.toString(16)),
|
|
30
|
+
gasLimit: addHexPrefix(tx.gasLimit.toString(16)),
|
|
31
|
+
to: tx.to,
|
|
32
|
+
value: addHexPrefix(tx.value.toString(16)),
|
|
33
|
+
data: tx.data,
|
|
34
|
+
chainId: tx.chainId,
|
|
35
|
+
signature: signature
|
|
36
|
+
};
|
|
37
|
+
}
|
|
23
38
|
return ethers.Transaction.from(transaction).serialized;
|
|
24
39
|
};
|
package/utils/eth.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { _EvmApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
1
2
|
import BigN from 'bignumber.js';
|
|
2
3
|
import BNEther from 'bn.js';
|
|
3
4
|
import { SignedTransaction } from 'web3-core';
|
|
@@ -16,3 +17,16 @@ export declare const anyNumberToBN: (value?: string | number | BNEther) => BigN;
|
|
|
16
17
|
export declare const createTransactionFromRLP: (rlp: string) => Transaction | null;
|
|
17
18
|
export declare const signatureToHex: (sig: SignedTransaction) => string;
|
|
18
19
|
export declare const recalculateGasPrice: (_price: string, chain: string) => string;
|
|
20
|
+
export declare const calculateGasFeeParams: (web3: _EvmApi, networkKey: string) => Promise<{
|
|
21
|
+
maxFeePerGas: BigN;
|
|
22
|
+
maxPriorityFeePerGas: BigN;
|
|
23
|
+
baseGasFee: BigN;
|
|
24
|
+
busyNetwork: boolean;
|
|
25
|
+
gasPrice?: undefined;
|
|
26
|
+
} | {
|
|
27
|
+
gasPrice: string;
|
|
28
|
+
busyNetwork: boolean;
|
|
29
|
+
maxFeePerGas?: undefined;
|
|
30
|
+
maxPriorityFeePerGas?: undefined;
|
|
31
|
+
baseGasFee?: undefined;
|
|
32
|
+
}>;
|