Skip to content

Commit 91cfa5c

Browse files
committed
feat(suite): eip1559 network feature
1 parent e946e6d commit 91cfa5c

File tree

7 files changed

+67
-40
lines changed

7 files changed

+67
-40
lines changed

packages/connect/src/api/ethereum/EthereumFees.ts

+1-19
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { BigNumber } from '@trezor/utils/src/bigNumber';
22

33
import { Blockchain } from '../../backend/BlockchainLink';
44
import type { EthereumNetworkInfo, FeeLevel } from '../../types';
5-
import { Blocks, MiscFeeLevels, findBlocksForFee } from '../common/MiscFees';
5+
import { Blocks, MiscFeeLevels } from '../common/MiscFees';
66

77
type EipResponse1559Level = 'low' | 'medium' | 'high';
88
type Eip1559Level = 'low' | 'normal' | 'high';
@@ -72,22 +72,4 @@ export class EthereumFeeLevels extends MiscFeeLevels {
7272

7373
return this.levels;
7474
}
75-
76-
updateEthereumCustomFee(
77-
feePerUnit: string,
78-
effectiveGasPrice?: string,
79-
maxPriorityFeePerGas?: string,
80-
) {
81-
// remove "custom" level from list
82-
this.levels = this.levels.filter(l => l.label !== 'custom');
83-
// recreate "custom" level
84-
const blocks = findBlocksForFee(feePerUnit, this.blocks);
85-
this.levels.push({
86-
label: 'custom',
87-
feePerUnit,
88-
blocks,
89-
maxPriorityFeePerGas,
90-
effectiveGasPrice,
91-
});
92-
}
9375
}

packages/connect/src/types/fees.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@ export const FeeInfo = Type.Object({
88
dustLimit: Type.Number(),
99
});
1010

11-
export type PriorityFeeEstimationDetails = Static<typeof PriorityFeeEstimationDetails>;
12-
export const PriorityFeeEstimationDetails = Type.Object({
13-
maxFeePerGas: Type.String(),
14-
maxPriorityFeePerGas: Type.String(),
15-
maxWaitTimeEstimate: Type.Optional(Type.Number()),
16-
minWaitTimeEstimate: Type.Optional(Type.Number()),
17-
});
18-
1911
export type FeeLevel = Static<typeof FeeLevel>;
2012
export const FeeLevel = Type.Object({
2113
label: Type.Union([
@@ -32,6 +24,8 @@ export const FeeLevel = Type.Object({
3224
baseFeePerGas: Type.Optional(Type.String()),
3325
maxFeePerGas: Type.Optional(Type.String()),
3426
effectiveGasPrice: Type.Optional(Type.String()),
27+
customMaxBaseFeePerGas: Type.Optional(Type.String()),
28+
customMaxPriorityFeePerGas: Type.Optional(Type.String()),
3529
maxPriorityFeePerGas: Type.Optional(Type.String()),
3630
maxWaitTimeEstimate: Type.Optional(Type.Number()),
3731
minWaitTimeEstimate: Type.Optional(Type.Number()),

packages/suite/src/reducers/wallet/tradingReducer.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@ import { Action } from 'src/types/suite';
3636
export interface ComposedTransactionInfo {
3737
composed?: Pick<
3838
PrecomposedTransactionFinal,
39-
'feePerByte' | 'estimatedFeeLimit' | 'feeLimit' | 'token' | 'fee'
39+
| 'feePerByte'
40+
| 'estimatedFeeLimit'
41+
| 'feeLimit'
42+
| 'token'
43+
| 'fee'
44+
| 'maxFeePerGas'
45+
| 'maxPriorityFeePerGas'
46+
| 'effectiveGasPrice'
4047
>;
4148
selectedFee?: FeeLevel['label'];
4249
}

suite-common/wallet-config/src/networksConfig.ts

+39-6
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export const networks = {
5757
'coin-definitions',
5858
'nft-definitions',
5959
'staking',
60+
'eip1559',
6061
],
6162
backendTypes: ['blockbook'],
6263
accountTypes: {
@@ -87,7 +88,15 @@ export const networks = {
8788
decimals: 18,
8889
testnet: false,
8990
explorer: getExplorerUrls('https://pol1.trezor.io', 'ethereum'),
90-
features: ['rbf', 'sign-verify', 'tokens', 'nfts', 'coin-definitions', 'nft-definitions'],
91+
features: [
92+
'rbf',
93+
'sign-verify',
94+
'tokens',
95+
'nfts',
96+
'coin-definitions',
97+
'nft-definitions',
98+
'eip1559',
99+
],
91100
backendTypes: ['blockbook'],
92101
accountTypes: {
93102
ledger: {
@@ -136,7 +145,15 @@ export const networks = {
136145
decimals: 18,
137146
testnet: false,
138147
explorer: getExplorerUrls('https://arbiscan.io', 'ethereum'),
139-
features: ['rbf', 'sign-verify', 'tokens', 'nfts', 'coin-definitions', 'nft-definitions'],
148+
features: [
149+
'rbf',
150+
'sign-verify',
151+
'tokens',
152+
'nfts',
153+
'coin-definitions',
154+
'nft-definitions',
155+
'eip1559',
156+
],
140157
backendTypes: ['blockbook'],
141158
accountTypes: {
142159
ledger: {
@@ -161,7 +178,15 @@ export const networks = {
161178
decimals: 18,
162179
testnet: false,
163180
explorer: getExplorerUrls('https://basescan.org', 'ethereum'),
164-
features: ['rbf', 'sign-verify', 'tokens', 'nfts', 'coin-definitions', 'nft-definitions'],
181+
features: [
182+
'rbf',
183+
'sign-verify',
184+
'tokens',
185+
'nfts',
186+
'coin-definitions',
187+
'nft-definitions',
188+
'eip1559',
189+
],
165190
backendTypes: ['blockbook'],
166191
accountTypes: {
167192
ledger: {
@@ -186,7 +211,15 @@ export const networks = {
186211
decimals: 18,
187212
testnet: false,
188213
explorer: getExplorerUrls('https://optimistic.etherscan.io', 'ethereum'),
189-
features: ['rbf', 'sign-verify', 'tokens', 'nfts', 'coin-definitions', 'nft-definitions'],
214+
features: [
215+
'rbf',
216+
'sign-verify',
217+
'tokens',
218+
'nfts',
219+
'coin-definitions',
220+
'nft-definitions',
221+
'eip1559',
222+
],
190223
backendTypes: ['blockbook'],
191224
accountTypes: {
192225
ledger: {
@@ -446,7 +479,7 @@ export const networks = {
446479
decimals: 18,
447480
testnet: true,
448481
explorer: getExplorerUrls('https://sepolia1.trezor.io', 'ethereum'),
449-
features: ['rbf', 'sign-verify', 'tokens', 'nfts', 'nft-definitions'],
482+
features: ['rbf', 'sign-verify', 'tokens', 'nfts', 'nft-definitions', 'eip1559'],
450483
backendTypes: ['blockbook'],
451484
accountTypes: {},
452485
coingeckoId: undefined,
@@ -462,7 +495,7 @@ export const networks = {
462495
decimals: 18,
463496
testnet: true,
464497
explorer: getExplorerUrls('https://holesky1.trezor.io', 'ethereum'),
465-
features: ['rbf', 'sign-verify', 'tokens', 'staking', 'nfts', 'nft-definitions'],
498+
features: ['rbf', 'sign-verify', 'tokens', 'staking', 'nfts', 'nft-definitions', 'eip1559'],
466499
backendTypes: ['blockbook'],
467500
accountTypes: {},
468501
coingeckoId: undefined,

suite-common/wallet-config/src/types.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ export type NetworkFeature =
5757
| 'tokens'
5858
| 'staking'
5959
| 'coin-definitions'
60-
| 'nft-definitions';
60+
| 'nft-definitions'
61+
| 'eip1559';
6162

6263
type Level = `/${number}'`;
6364
type MaybeApostrophe = `'` | '';

suite-common/wallet-core/src/blockchain/blockchainThunks.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { notificationsActions } from '@suite-common/toast-notifications';
33
import {
44
NetworkSymbol,
55
externalBackendTypeNetworks,
6+
getNetworkFeatures,
67
getNetworkOptional,
78
isNetworkSymbol,
89
isTrezorInfraBasedNetwork,
@@ -126,14 +127,18 @@ export const updateFeeInfoThunk = createThunk(
126127

127128
let newFeeInfo;
128129

129-
if (network.networkType === 'ethereum') {
130-
// NOTE: ethereum smart fees are not implemented properly in @trezor/connect Issue: https://github.com/trezor/trezor-suite/issues/5340
131-
// create raw call to @trezor/blockchain-link, receive data and create FeeLevel.normal from it
130+
const feeLevels: 'preloaded' | 'smart' = getNetworkFeatures(network.symbol).includes(
131+
'eip1559',
132+
)
133+
? 'smart'
134+
: 'preloaded';
132135

136+
if (network.networkType === 'ethereum') {
133137
const result = await TrezorConnect.blockchainEstimateFee({
134138
coin: network.symbol,
135139
request: {
136140
blocks: [2],
141+
feeLevels,
137142
specific: {
138143
from: '0x0000000000000000000000000000000000000000',
139144
to: '0x0000000000000000000000000000000000000000',
@@ -146,7 +151,7 @@ export const updateFeeInfoThunk = createThunk(
146151
levels: result.payload.levels.map(l => ({
147152
...l,
148153
blocks: -1, // NOTE: @trezor/connect returns -1 for ethereum default
149-
label: 'normal' as const,
154+
label: l.label || ('normal' as const),
150155
})),
151156
};
152157
}

suite-common/wallet-types/src/transaction.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@ export type EthTransactionData = {
7777
amount: string;
7878
data?: string;
7979
gasLimit: string;
80-
gasPrice: string;
8180
nonce: string;
81+
gasPrice?: string; // this field is not used for EIP1559 transactions (See EthereumTransaction and EthereumTransactionEIP1559 types in connect)
82+
maxFeePerGas?: string;
83+
maxPriorityFeePerGas?: string;
8284
};
8385

8486
export type ExternalOutput = Exclude<ComposeOutput, { type: 'opreturn' } | { address_n: number[] }>;
@@ -107,6 +109,9 @@ type PrecomposedTransactionBase = PrecomposedTransactionConnectResponseFinal & {
107109
max?: string;
108110
feeLimit?: string;
109111
estimatedFeeLimit?: string;
112+
maxFeePerGas?: string;
113+
maxPriorityFeePerGas?: string;
114+
effectiveGasPrice?: string;
110115
token?: TokenInfo;
111116
isTokenKnown?: boolean;
112117
createdTimestamp?: number;

0 commit comments

Comments
 (0)