Skip to content

Commit 0854320

Browse files
authored
Add --tip flag (#3635)
<!-- Reference any GitHub issues resolved by this PR --> Closes #3516 ## Introduced changes <!-- A brief description of the changes --> - Add a `--tip` flag to relevant commands. If not provided set it to 0 (passing `None` will result in tip estimation on the starknet-rs side)
1 parent 2b91778 commit 0854320

File tree

20 files changed

+165
-56
lines changed

20 files changed

+165
-56
lines changed

CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919
#### Added
2020

2121
- `--test-files` flag to `verify` command to include test files under src/ for verification (only applies to voyager)
22-
23-
### Cast
22+
- `--tip` flag to `invoke`, `declare`, `deploy`, `multicall run` and `account deploy` commands to set the transaction tip
2423

2524
#### Changed
2625

Cargo.lock

Lines changed: 9 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ regex = "1.11.1"
6565
serde = { version = "1.0.219", features = ["derive"] }
6666
serde_json = "1.0.140"
6767
starknet = "0.17.0-rc.3"
68-
starknet-crypto = { git = "https://github.com/xJonathanLEI/starknet-rs", rev = "a70f4ce" }
68+
starknet-crypto = "0.7.4"
6969
tempfile = "3.20.0"
7070
thiserror = "2.0.12"
7171
ctor = "0.4.1"

crates/sncast/src/helpers/fee.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ pub struct FeeArgs {
3333
/// Max L1 data gas price in Fri. If not provided, will be automatically estimated.
3434
#[arg(long)]
3535
pub l1_data_gas_price: Option<u128>,
36+
37+
/// Tip for the transaction. If not provided, it will be set to 0.
38+
#[arg(long)]
39+
pub tip: Option<u64>,
3640
}
3741

3842
impl From<ScriptFeeSettings> for FeeArgs {
@@ -54,6 +58,7 @@ impl From<ScriptFeeSettings> for FeeArgs {
5458
l2_gas_price,
5559
l1_data_gas,
5660
l1_data_gas_price,
61+
tip: Some(0),
5762
}
5863
}
5964
}
@@ -75,7 +80,9 @@ impl FeeArgs {
7580
);
7681

7782
let fee_settings = FeeSettings::try_from(fee_estimate.clone())
78-
.expect("Failed to convert FeeEstimate to FeeSettings");
83+
.expect("Failed to convert FeeEstimate to FeeSettings")
84+
.update_tip(self.tip.unwrap_or(0)); // If a tip is not provided, set it to 0
85+
7986
Ok(fee_settings)
8087
} else {
8188
let fee_settings = FeeSettings::from(self.clone());
@@ -105,6 +112,17 @@ pub struct FeeSettings {
105112
pub l2_gas_price: Option<u128>,
106113
pub l1_data_gas: Option<u64>,
107114
pub l1_data_gas_price: Option<u128>,
115+
pub tip: Option<u64>,
116+
}
117+
118+
impl FeeSettings {
119+
#[must_use]
120+
pub fn update_tip(&self, tip: u64) -> FeeSettings {
121+
FeeSettings {
122+
tip: Some(tip),
123+
..*self
124+
}
125+
}
108126
}
109127

110128
impl TryFrom<FeeEstimate> for FeeSettings {
@@ -117,6 +135,7 @@ impl TryFrom<FeeEstimate> for FeeSettings {
117135
l2_gas_price: Some(fee_estimate.l2_gas_price),
118136
l1_data_gas: Some(fee_estimate.l1_data_gas_consumed),
119137
l1_data_gas_price: Some(fee_estimate.l1_data_gas_price),
138+
tip: None,
120139
})
121140
}
122141
}
@@ -130,6 +149,7 @@ impl From<FeeArgs> for FeeSettings {
130149
l2_gas_price: fee_args.l2_gas_price,
131150
l1_data_gas: fee_args.l1_data_gas,
132151
l1_data_gas_price: fee_args.l1_data_gas_price,
152+
tip: Some(fee_args.tip.unwrap_or(0)),
133153
}
134154
}
135155
}
@@ -168,6 +188,7 @@ mod tests {
168188
l2_gas_price: Some(4),
169189
l1_data_gas: Some(5),
170190
l1_data_gas_price: Some(6),
191+
tip: None,
171192
}
172193
);
173194
}

crates/sncast/src/starknet_commands/account/deploy.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ where
304304
l2_gas_price,
305305
l1_data_gas,
306306
l1_data_gas_price,
307+
tip,
307308
} = fee_settings.expect("Failed to convert to fee settings");
308309

309310
let deployment = apply_optional_fields!(
@@ -313,7 +314,8 @@ where
313314
l2_gas => AccountDeploymentV3::l2_gas,
314315
l2_gas_price => AccountDeploymentV3::l2_gas_price,
315316
l1_data_gas => AccountDeploymentV3::l1_data_gas,
316-
l1_data_gas_price => AccountDeploymentV3::l1_data_gas_price
317+
l1_data_gas_price => AccountDeploymentV3::l1_data_gas_price,
318+
tip => AccountDeploymentV3::tip
317319
);
318320
let result = deployment.send().await;
319321

crates/sncast/src/starknet_commands/declare.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ pub async fn declare(
9797
l2_gas_price,
9898
l1_data_gas,
9999
l1_data_gas_price,
100+
tip,
100101
} = fee_settings.expect("Failed to convert to fee settings");
101102

102103
let declaration = apply_optional_fields!(
@@ -107,6 +108,7 @@ pub async fn declare(
107108
l2_gas_price => DeclarationV3::l2_gas_price,
108109
l1_data_gas => DeclarationV3::l1_data_gas,
109110
l1_data_gas_price => DeclarationV3::l1_data_gas_price,
111+
tip => DeclarationV3::tip,
110112
declare.nonce => DeclarationV3::nonce
111113
);
112114

crates/sncast/src/starknet_commands/deploy.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ pub async fn deploy(
9292
l2_gas_price,
9393
l1_data_gas,
9494
l1_data_gas_price,
95+
tip,
9596
} = fee_settings.expect("Failed to convert to fee settings");
9697

9798
let deployment = apply_optional_fields!(
@@ -102,6 +103,7 @@ pub async fn deploy(
102103
l2_gas_price => DeploymentV3::l2_gas_price,
103104
l1_data_gas => DeploymentV3::l1_data_gas,
104105
l1_data_gas_price => DeploymentV3::l1_data_gas_price,
106+
tip => DeploymentV3::tip,
105107
nonce => DeploymentV3::nonce
106108
);
107109
let result = deployment.send().await;

crates/sncast/src/starknet_commands/invoke.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ pub async fn execute_calls(
8888
l2_gas_price,
8989
l1_data_gas,
9090
l1_data_gas_price,
91+
tip,
9192
} = fee_settings.expect("Failed to convert to fee settings");
9293

9394
let execution = apply_optional_fields!(
@@ -98,6 +99,7 @@ pub async fn execute_calls(
9899
l2_gas_price => ExecutionV3::l2_gas_price,
99100
l1_data_gas => ExecutionV3::l1_data_gas,
100101
l1_data_gas_price => ExecutionV3::l1_data_gas_price,
102+
tip => ExecutionV3::tip,
101103
nonce => ExecutionV3::nonce
102104
);
103105
let result = execution.send().await;

crates/sncast/tests/e2e/call.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ async fn test_call_after_storage_changed() {
7272
l2_gas_price: Some(100_000_000_000_000_000),
7373
l1_data_gas: Some(100_000),
7474
l1_data_gas_price: Some(10_000_000_000_000),
75+
tip: Some(100_000),
7576
};
7677
invoke_contract(
7778
"user2",

crates/sncast/tests/e2e/declare.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use crate::helpers::constants::{CONTRACTS_DIR, DEVNET_OZ_CLASS_HASH_CAIRO_0, URL
22
use crate::helpers::fee::apply_test_resource_bounds_flags;
33
use crate::helpers::fixtures::{
44
copy_directory_to_tempdir, create_and_deploy_account, create_and_deploy_oz_account,
5-
duplicate_contract_directory_with_salt, get_accounts_path, get_transaction_hash,
6-
get_transaction_receipt, join_tempdirs,
5+
duplicate_contract_directory_with_salt, get_accounts_path, get_transaction_by_hash,
6+
get_transaction_hash, get_transaction_receipt, join_tempdirs,
77
};
88
use crate::helpers::runner::runner;
99
use configuration::CONFIG_FILENAME;
@@ -13,6 +13,7 @@ use sncast::AccountType;
1313
use sncast::helpers::constants::{BRAAVOS_CLASS_HASH, OZ_CLASS_HASH, READY_CLASS_HASH};
1414
use sncast::helpers::fee::FeeArgs;
1515
use starknet::core::types::TransactionReceipt::Declare;
16+
use starknet::core::types::{DeclareTransaction, Transaction, TransactionExecutionStatus};
1617
use starknet_types_core::felt::{Felt, NonZeroFelt};
1718
use std::fs;
1819
use test_case::test_case;
@@ -105,6 +106,7 @@ async fn test_happy_case(class_hash: Felt, account_type: AccountType) {
105106
l1_gas_price: None,
106107
l2_gas: None,
107108
l2_gas_price: None,
109+
tip: Some(100_000),
108110
}; "max_fee")]
109111
#[test_case(FeeArgs{
110112
max_fee: None,
@@ -114,6 +116,7 @@ async fn test_happy_case(class_hash: Felt, account_type: AccountType) {
114116
l1_gas_price: Some(10_000_000_000_000),
115117
l2_gas: Some(1_000_000_000),
116118
l2_gas_price: Some(100_000_000_000_000_000_000),
119+
tip: None,
117120
}; "resource_bounds")]
118121
#[tokio::test]
119122
async fn test_happy_case_different_fees(fee_args: FeeArgs) {
@@ -166,6 +169,7 @@ async fn test_happy_case_different_fees(fee_args: FeeArgs) {
166169
"--l2-gas-price",
167170
fee_args.l2_gas_price.map(|x| x.to_string()),
168171
),
172+
("--tip", fee_args.tip.map(|x| x.to_string())),
169173
];
170174

171175
for &(key, ref value) in &options {
@@ -176,14 +180,22 @@ async fn test_happy_case_different_fees(fee_args: FeeArgs) {
176180
}
177181

178182
let snapbox = runner(&args).current_dir(tempdir.path());
179-
let output = snapbox.assert().success();
180-
181-
let output = output.get_output().stdout.clone();
183+
let output = snapbox.assert().success().get_output().stdout.clone();
182184

183185
let hash = get_transaction_hash(&output);
184-
let receipt = get_transaction_receipt(hash).await;
186+
let Declare(receipt) = get_transaction_receipt(hash).await else {
187+
panic!("Should be Declare receipt");
188+
};
189+
assert_eq!(
190+
receipt.execution_result.status(),
191+
TransactionExecutionStatus::Succeeded
192+
);
185193

186-
assert!(matches!(receipt, Declare(_)));
194+
let Transaction::Declare(DeclareTransaction::V3(tx)) = get_transaction_by_hash(hash).await
195+
else {
196+
panic!("Expected Declare V3 transaction")
197+
};
198+
assert_eq!(tx.tip, fee_args.tip.unwrap_or(0));
187199
}
188200

189201
#[tokio::test]

0 commit comments

Comments
 (0)