-
Notifications
You must be signed in to change notification settings - Fork 3
Draft: adjust EVM feeInformation #123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
b46300b
05f7ed4
6b1ab42
d508556
cbaa9a5
630904c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,10 +45,20 @@ sealed class FeeInformation { | |
| 'gasLimit': int gasLimit, | ||
| 'gasPrice': Map gasPrice, | ||
| } => | ||
| EvmFeeInformation( | ||
| EvmLegacyFeeInformation( | ||
| gasLimit: gasLimit, | ||
| gasPrice: Amount.fromJson(gasPrice), | ||
| ), | ||
| { | ||
| 'gasLimit': int gasLimit, | ||
| 'maxFeePerGas': Map maxFeePerGas, | ||
| 'maxPriorityFeePerGas': Map maxPriorityFeePerGas, | ||
| } => | ||
| EvmType2FeeInformation( | ||
| gasLimit: gasLimit, | ||
| maxFeePerGas: Amount.fromJson(maxFeePerGas), | ||
| maxPriorityFeePerGas: Amount.fromJson(maxPriorityFeePerGas), | ||
| ), | ||
| { | ||
| 'feePerByte': Map feePerByte, | ||
| 'fee': Map? fee, | ||
|
|
@@ -68,18 +78,28 @@ sealed class FeeInformation { | |
| } | ||
| } | ||
|
|
||
| final class EvmFeeInformation extends FeeInformation { | ||
| sealed class EvmFeeInformation extends FeeInformation { | ||
| final int? gasLimit; | ||
| final Amount? gasPrice; | ||
|
|
||
| Amount? get maxFee; | ||
|
|
||
| const EvmFeeInformation({ | ||
| required this.gasLimit, | ||
| required this.gasPrice, | ||
| }); | ||
| } | ||
|
|
||
| final class EvmLegacyFeeInformation extends EvmFeeInformation { | ||
| final Amount? gasPrice; | ||
|
|
||
| Amount get fee { | ||
| return gasPrice ?? | ||
| Amount.zero * Amount.convert(value: gasLimit ?? 0, decimals: 0); | ||
| Amount? get maxFee { | ||
| if (gasPrice == null) { | ||
| return null; | ||
| } | ||
| if (gasLimit == null) { | ||
| return null; | ||
| } | ||
|
|
||
| return gasPrice! * Amount.convert(value: gasLimit!, decimals: 0); | ||
| } | ||
|
|
||
| Json toJson() { | ||
|
|
@@ -89,54 +109,60 @@ final class EvmFeeInformation extends FeeInformation { | |
| }; | ||
| } | ||
|
|
||
| EvmFeeInformation copyWith({ | ||
| EvmLegacyFeeInformation copyWith({ | ||
| int? gasLimit, | ||
| Amount? gasPrice, | ||
| }) { | ||
| return EvmFeeInformation( | ||
| return EvmLegacyFeeInformation( | ||
| gasLimit: gasLimit ?? this.gasLimit, | ||
| gasPrice: gasPrice ?? this.gasPrice, | ||
| ); | ||
| } | ||
|
|
||
| static EvmFeeInformation get zero { | ||
| return EvmFeeInformation(gasLimit: null, gasPrice: null); | ||
| } | ||
| const EvmLegacyFeeInformation({ | ||
| required super.gasLimit, | ||
| required this.gasPrice, | ||
| }); | ||
| } | ||
|
|
||
| final class EvmType2FeeInformation extends EvmFeeInformation { | ||
| final Amount? maxFeePerGas; | ||
| final Amount? maxPriorityFeePerGas; | ||
|
|
||
| Amount? get maxFee { | ||
| if (gasLimit == null) { | ||
| return null; | ||
| } | ||
|
|
||
| if (maxFeePerGas == null) { | ||
| return null; | ||
| } | ||
|
|
||
| return maxFeePerGas! * Amount.convert(value: gasLimit!, decimals: 0); | ||
| } | ||
|
|
||
| const EvmType2FeeInformation({ | ||
| required super.gasLimit, | ||
| required super.gasPrice, | ||
| required this.maxFeePerGas, | ||
| required this.maxPriorityFeePerGas, | ||
| }); | ||
|
|
||
| static EvmType2FeeInformation get zero { | ||
| return EvmType2FeeInformation( | ||
| gasLimit: null, | ||
| gasPrice: null, | ||
| maxPriorityFeePerGas: null, | ||
| ); | ||
| } | ||
|
|
||
| Json toJson() { | ||
| return { | ||
| 'gasLimit': gasLimit, | ||
| 'maxPriorityFeePerGas': maxPriorityFeePerGas.toString(), | ||
| 'gasPrice': gasPrice?.toJson() ?? Amount.zero.toJson(), | ||
| 'maxFeePerGas': maxFeePerGas.toString(), | ||
|
Comment on lines
160
to
+161
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Inconsistent serialization in In Apply this diff to ensure consistent serialization: Json toJson() {
return {
'gasLimit': gasLimit,
- 'maxPriorityFeePerGas': maxPriorityFeePerGas.toString(),
- 'maxFeePerGas': maxFeePerGas.toString(),
+ 'maxPriorityFeePerGas': maxPriorityFeePerGas?.toJson() ?? Amount.zero.toJson(),
+ 'maxFeePerGas': maxFeePerGas?.toJson() ?? Amount.zero.toJson(),
};
}
|
||
| }; | ||
| } | ||
|
|
||
| EvmType2FeeInformation copyWith({ | ||
| int? gasLimit, | ||
| Amount? gasPrice, | ||
| Amount? maxFeePerGas, | ||
| Amount? maxPriorityFeePerGas, | ||
| }) { | ||
| return EvmType2FeeInformation( | ||
| gasLimit: gasLimit ?? this.gasLimit, | ||
| gasPrice: gasPrice ?? this.gasPrice, | ||
| maxFeePerGas: maxFeePerGas ?? this.maxFeePerGas, | ||
| maxPriorityFeePerGas: maxPriorityFeePerGas ?? this.maxPriorityFeePerGas, | ||
| ); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -37,6 +37,10 @@ final class EvmNetworkFees extends NetworkFees { | |||||||||||||||
| final BigInt average; | ||||||||||||||||
| final BigInt fast; | ||||||||||||||||
|
|
||||||||||||||||
| BigInt get safePriority => safe - lastBlock; | ||||||||||||||||
| BigInt get averagePriority => average - lastBlock; | ||||||||||||||||
| BigInt get fastPriority => fast - lastBlock; | ||||||||||||||||
|
|
||||||||||||||||
|
||||||||||||||||
| BigInt get safePriority => safe - lastBlock; | |
| BigInt get averagePriority => average - lastBlock; | |
| BigInt get fastPriority => fast - lastBlock; | |
| BigInt get safePriority => (safe - lastBlock).isNegative ? BigInt.zero : safe - lastBlock; | |
| BigInt get averagePriority => (average - lastBlock).isNegative ? BigInt.zero : average - lastBlock; | |
| BigInt get fastPriority => (fast - lastBlock).isNegative ? BigInt.zero : fast - lastBlock; | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Based on the search results from multiple verification attempts, I can now generate a final response:
Add validation for gasLimit and Amount values
The codebase shows no existing validation for gasLimit or Amount values in the FeeInformation class. Since gas values are critical for transaction execution, validation should be added:
factory FeeInformation.fromJson(Map json) { return switch (json) { { 'gasLimit': int gasLimit, 'gasPrice': Map gasPrice, } => + gasLimit <= 0 ? throw FormatException('Invalid gasLimit: must be positive') : EvmLegacyFeeInformation( gasLimit: gasLimit, gasPrice: Amount.fromJson(gasPrice), ), { 'gasLimit': int gasLimit, 'maxFeePerGas': Map maxFeePerGas, 'maxPriorityFeePerGas': Map maxPriorityFeePerGas, } => + gasLimit <= 0 ? throw FormatException('Invalid gasLimit: must be positive') : EvmType2FeeInformation( gasLimit: gasLimit, maxFeePerGas: Amount.fromJson(maxFeePerGas), maxPriorityFeePerGas: Amount.fromJson(maxPriorityFeePerGas), ),🔗 Analysis chain
Verify type safety in fromJson factory
The factory method should validate the numeric ranges for gasLimit and ensure Amount values are non-negative.
Add validation:
factory FeeInformation.fromJson(Map json) { return switch (json) { { 'gasLimit': int gasLimit, 'gasPrice': Map gasPrice, } => + gasLimit <= 0 ? throw FormatException('Invalid gasLimit') : EvmLegacyFeeInformation( gasLimit: gasLimit, gasPrice: Amount.fromJson(gasPrice), ), { 'gasLimit': int gasLimit, 'maxFeePerGas': Map maxFeePerGas, 'maxPriorityFeePerGas': Map maxPriorityFeePerGas, } => + gasLimit <= 0 ? throw FormatException('Invalid gasLimit') : EvmType2FeeInformation( gasLimit: gasLimit, maxFeePerGas: Amount.fromJson(maxFeePerGas), maxPriorityFeePerGas: Amount.fromJson(maxPriorityFeePerGas), ),🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 104
Script:
Length of output: 112122
Script:
Length of output: 6468
Script:
Length of output: 1796