diff --git a/CHANGELOG.md b/CHANGELOG.md index 03d87b0b4d..0805791683 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `--test-files` flag to `verify` command to include test files under src/ for verification (only applies to voyager) - `--tip` flag to `invoke`, `declare`, `deploy`, `multicall run` and `account deploy` commands to set the transaction tip +- `--estimate-tip` flag which automatically adds an estimated tip to the transaction. The tip is calculated based on the current network conditions and added to the transaction fee #### Changed diff --git a/crates/sncast/src/helpers/fee.rs b/crates/sncast/src/helpers/fee.rs index e9b759e60d..569f6439e0 100644 --- a/crates/sncast/src/helpers/fee.rs +++ b/crates/sncast/src/helpers/fee.rs @@ -34,9 +34,13 @@ pub struct FeeArgs { #[arg(long)] pub l1_data_gas_price: Option, - /// Tip for the transaction. If not provided, it will be set to 0. - #[arg(long)] + /// Tip for the transaction. Defaults to 0 unless `--estimate-tip` is used. + #[arg(long, conflicts_with = "estimate_tip")] pub tip: Option, + + /// If passed, an estimated tip will be added to pay for the transaction. + #[arg(long)] + pub estimate_tip: bool, } impl From for FeeArgs { @@ -59,6 +63,7 @@ impl From for FeeArgs { l1_data_gas, l1_data_gas_price, tip: Some(0), + estimate_tip: false, } } } @@ -81,7 +86,7 @@ impl FeeArgs { let fee_settings = FeeSettings::try_from(fee_estimate.clone()) .expect("Failed to convert FeeEstimate to FeeSettings") - .update_tip(self.tip.unwrap_or(0)); // If a tip is not provided, set it to 0 + .with_resolved_tip(self.tip, self.estimate_tip); Ok(fee_settings) } else { @@ -117,11 +122,14 @@ pub struct FeeSettings { impl FeeSettings { #[must_use] - pub fn update_tip(&self, tip: u64) -> FeeSettings { - FeeSettings { - tip: Some(tip), - ..*self - } + pub fn with_resolved_tip(self, tip: Option, estimate_tip: bool) -> FeeSettings { + let tip = if estimate_tip { + None // If we leave it as None, the tip will be estimated before sending the transaction + } else { + Some(tip.unwrap_or(0)) // If a tip is not provided, set it to 0 + }; + + FeeSettings { tip, ..self } } } @@ -149,8 +157,9 @@ impl From for FeeSettings { l2_gas_price: fee_args.l2_gas_price, l1_data_gas: fee_args.l1_data_gas, l1_data_gas_price: fee_args.l1_data_gas_price, - tip: Some(fee_args.tip.unwrap_or(0)), + tip: None, } + .with_resolved_tip(fee_args.tip, fee_args.estimate_tip) } } diff --git a/crates/sncast/tests/e2e/declare.rs b/crates/sncast/tests/e2e/declare.rs index 4bde4823e3..c0af3c520a 100644 --- a/crates/sncast/tests/e2e/declare.rs +++ b/crates/sncast/tests/e2e/declare.rs @@ -107,6 +107,7 @@ async fn test_happy_case(class_hash: Felt, account_type: AccountType) { l2_gas: None, l2_gas_price: None, tip: Some(100_000), + estimate_tip: false, }; "max_fee")] #[test_case(FeeArgs{ max_fee: None, @@ -117,6 +118,7 @@ async fn test_happy_case(class_hash: Felt, account_type: AccountType) { l2_gas: Some(1_000_000_000), l2_gas_price: Some(100_000_000_000_000_000_000), tip: None, + estimate_tip: false, }; "resource_bounds")] #[tokio::test] async fn test_happy_case_different_fees(fee_args: FeeArgs) { diff --git a/crates/sncast/tests/e2e/deploy.rs b/crates/sncast/tests/e2e/deploy.rs index 667c222bd0..47b8e105d5 100644 --- a/crates/sncast/tests/e2e/deploy.rs +++ b/crates/sncast/tests/e2e/deploy.rs @@ -104,6 +104,7 @@ async fn test_happy_case(class_hash: Felt, account_type: AccountType) { l2_gas: None, l2_gas_price: None, tip: None, + estimate_tip: false, }; "max_fee")] #[test_case(FeeArgs{ max_fee: None, @@ -114,6 +115,7 @@ async fn test_happy_case(class_hash: Felt, account_type: AccountType) { l2_gas: Some(1_000_000_000), l2_gas_price: Some(100_000_000_000_000_000_000), tip: Some(100_000), + estimate_tip: false, }; "resource_bounds")] #[tokio::test] async fn test_happy_case_different_fees(fee_args: FeeArgs) { diff --git a/crates/sncast/tests/e2e/invoke.rs b/crates/sncast/tests/e2e/invoke.rs index ace591b7cb..32eb41a037 100644 --- a/crates/sncast/tests/e2e/invoke.rs +++ b/crates/sncast/tests/e2e/invoke.rs @@ -106,6 +106,7 @@ async fn test_happy_case(class_hash: Felt, account_type: AccountType) { l2_gas: None, l2_gas_price: None, tip: None, + estimate_tip: false, }; "max_fee")] #[test_case(FeeArgs{ max_fee: None, @@ -116,6 +117,7 @@ async fn test_happy_case(class_hash: Felt, account_type: AccountType) { l2_gas: Some(1_000_000_000), l2_gas_price: Some(100_000_000_000_000_000_000), tip: Some(100_000_000), + estimate_tip: false, }; "resource_bounds")] #[tokio::test] async fn test_happy_case_different_fees(fee_args: FeeArgs) { diff --git a/crates/sncast/tests/integration/fee.rs b/crates/sncast/tests/integration/fee.rs index 760fb60df1..0ef6dceb8c 100644 --- a/crates/sncast/tests/integration/fee.rs +++ b/crates/sncast/tests/integration/fee.rs @@ -13,6 +13,7 @@ async fn test_happy_case() { l1_data_gas: Some(100), l1_data_gas_price: Some(200), tip: None, + estimate_tip: false, }; let settings = args.try_into_fee_settings(None).unwrap(); @@ -42,6 +43,7 @@ async fn test_max_fee_none() { l1_data_gas: Some(100), l1_data_gas_price: Some(100), tip: Some(100), + estimate_tip: false, }; let settings = args.try_into_fee_settings(None).unwrap(); @@ -81,6 +83,7 @@ async fn test_max_fee_set() { l1_data_gas: None, l1_data_gas_price: None, tip: None, + estimate_tip: false, }; let settings = args @@ -122,6 +125,7 @@ async fn test_max_fee_set_and_fee_estimate_higher() { l1_data_gas: None, l1_data_gas_price: None, tip: None, + estimate_tip: false, }; let err = args @@ -150,6 +154,7 @@ async fn test_max_fee_set_and_fee_estimate_none() { l1_data_gas: None, l1_data_gas_price: None, tip: None, + estimate_tip: false, }; args.try_into_fee_settings(None).unwrap(); @@ -166,6 +171,7 @@ async fn test_all_args_none() { l1_data_gas: None, l1_data_gas_price: None, tip: None, + estimate_tip: false, }; let settings = args.try_into_fee_settings(None).unwrap(); @@ -183,3 +189,33 @@ async fn test_all_args_none() { } ); } + +#[tokio::test] +async fn test_estimate_tip() { + let args = FeeArgs { + max_fee: None, + l1_gas: None, + l1_gas_price: None, + l2_gas: None, + l2_gas_price: None, + l1_data_gas: None, + l1_data_gas_price: None, + tip: None, + estimate_tip: true, + }; + + let settings = args.try_into_fee_settings(None).unwrap(); + + assert_eq!( + settings, + FeeSettings { + l1_gas: None, + l1_gas_price: None, + l2_gas: None, + l2_gas_price: None, + l1_data_gas: None, + l1_data_gas_price: None, + tip: None, + } + ); +} diff --git a/docs/src/appendix/sncast/account/deploy.md b/docs/src/appendix/sncast/account/deploy.md index d2a73a801a..7d51c45419 100644 --- a/docs/src/appendix/sncast/account/deploy.md +++ b/docs/src/appendix/sncast/account/deploy.md @@ -57,8 +57,15 @@ Maximum L1 data gas unit price for the `deploy_account` transaction. When not us ## `--tip ` Optional. +Conflicts with: [`--estimate-tip`](#--estimate-tip-estimate_tip) -Tip for the transaction. When not provided, defaults to 0. +Tip for the transaction. When not provided, defaults to 0 unless [`--estimate-tip`](#--estimate-tip-estimate_tip) is used. + +## `--estimate-tip ` +Optional. +Conflicts with: [`--tip`](#--tip-tip) + +If passed, an estimated tip will be added to pay for the transaction. The tip is estimated based on the current network conditions and added to the transaction fee. ## `--silent` Optional. diff --git a/docs/src/appendix/sncast/declare.md b/docs/src/appendix/sncast/declare.md index 16b0ede5dc..a1d6e51193 100644 --- a/docs/src/appendix/sncast/declare.md +++ b/docs/src/appendix/sncast/declare.md @@ -61,8 +61,15 @@ Maximum L1 data gas unit price for the `declare` transaction. When not used, def ## `--tip ` Optional. +Conflicts with: [`--estimate-tip`](#--estimate-tip-estimate_tip) -Tip for the transaction. When not provided, defaults to 0. +Tip for the transaction. Tip for the transaction. When not provided, defaults to 0 unless [`--estimate-tip`](#--estimate-tip-estimate_tip) is used. + +## `--estimate-tip ` +Optional. +Conflicts with: [`--tip`](#--tip-tip) + +If passed, an estimated tip will be added to pay for the transaction. The tip is estimated based on the current network conditions and added to the transaction fee. ## `--nonce, -n ` Optional. diff --git a/docs/src/appendix/sncast/deploy.md b/docs/src/appendix/sncast/deploy.md index b6cd467f95..8eacc86f0d 100644 --- a/docs/src/appendix/sncast/deploy.md +++ b/docs/src/appendix/sncast/deploy.md @@ -86,8 +86,15 @@ Maximum L1 data gas unit price for the `deploy` transaction. When not used, defa ## `--tip ` Optional. +Conflicts with: [`--estimate-tip`](#--estimate-tip-estimate_tip) -Tip for the transaction. When not provided, defaults to 0. +Tip for the transaction. When not provided, defaults to 0 unless [`--estimate-tip`](#--estimate-tip-estimate_tip) is used. + +## `--estimate-tip ` +Optional. +Conflicts with: [`--tip`](#--tip-tip) + +If passed, an estimated tip will be added to pay for the transaction. The tip is estimated based on the current network conditions and added to the transaction fee. ## `--nonce, -n ` Optional. diff --git a/docs/src/appendix/sncast/invoke.md b/docs/src/appendix/sncast/invoke.md index e1b468ae90..395862e55b 100644 --- a/docs/src/appendix/sncast/invoke.md +++ b/docs/src/appendix/sncast/invoke.md @@ -82,8 +82,15 @@ Maximum L1 data gas unit price for the `invoke` transaction. When not used, defa ## `--tip ` Optional. +Conflicts with: [`--estimate-tip`](#--estimate-tip-estimate_tip) -Tip for the transaction. When not provided, defaults to 0. +Tip for the transaction. When not provided, defaults to 0 unless [`--estimate-tip`](#--estimate-tip-estimate_tip) is used. + +## `--estimate-tip ` +Optional. +Conflicts with: [`--tip`](#--tip-tip) + +If passed, an estimated tip will be added to pay for the transaction. The tip is estimated based on the current network conditions and added to the transaction fee. ## `--nonce, -n ` Optional. diff --git a/docs/src/appendix/sncast/multicall/run.md b/docs/src/appendix/sncast/multicall/run.md index c7cfb3a476..c81ca9b3e3 100644 --- a/docs/src/appendix/sncast/multicall/run.md +++ b/docs/src/appendix/sncast/multicall/run.md @@ -62,8 +62,15 @@ Maximum L1 data gas unit price for the `invoke` transaction. When not used, defa ## `--tip ` Optional. +Conflicts with: [`--estimate-tip`](#--estimate-tip-estimate_tip) -Tip for the transaction. When not provided, defaults to 0. +Tip for the transaction. When not provided, defaults to 0 unless [`--estimate-tip`](#--estimate-tip-estimate_tip) is used. + +## `--estimate-tip ` +Optional. +Conflicts with: [`--tip`](#--tip-tip) + +If passed, an estimated tip will be added to pay for the transaction. The tip is estimated based on the current network conditions and added to the transaction fee. File example: