Skip to content

Commit 0ef8c41

Browse files
authored
Fix type conversion in script "deploy" that resulted in max_fee being omitted (#2888)
<!-- Reference any GitHub issues resolved by this PR --> Closes # ## Introduced changes <!-- A brief description of the changes --> This came up from #2865 Conversion from `ScriptFeeSettings` to `FeeSettings` resulted in value for `max_fee` being dropped completely. This conversion was only in cast script "deploy" function. If deploy was used with Strk token, any value passed to `max_fee` was completely ignored. Removed the conversion entirely and used correct structure in deploy. ## Checklist <!-- Make sure all of these are complete --> - [x] Linked relevant issue - [x] Updated relevant documentation - [x] Added relevant tests - [x] Performed self-review of the code - [x] Added changes to `CHANGELOG.md`
1 parent a47c6a4 commit 0ef8c41

File tree

5 files changed

+17
-27
lines changed

5 files changed

+17
-27
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2323

2424
- Renamed `--network` flag to `--network-name` in `sncast account delete` command
2525

26+
#### Fixed
27+
28+
- Bug resulting in value passed for `max_fee` being ignored in cast scripts when using `deploy` with STRK token
29+
2630
## [0.36.0] - 2025-01-15
2731

2832
### Forge

crates/sncast/src/helpers/fee.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -198,22 +198,6 @@ pub enum FeeSettings {
198198
},
199199
}
200200

201-
impl From<ScriptFeeSettings> for FeeSettings {
202-
fn from(value: ScriptFeeSettings) -> Self {
203-
match value {
204-
ScriptFeeSettings::Eth { max_fee } => FeeSettings::Eth { max_fee },
205-
ScriptFeeSettings::Strk {
206-
max_gas,
207-
max_gas_unit_price,
208-
..
209-
} => FeeSettings::Strk {
210-
max_gas,
211-
max_gas_unit_price,
212-
},
213-
}
214-
}
215-
}
216-
217201
pub trait PayableTransaction {
218202
fn error_message(&self, token: &str, version: &str) -> String;
219203
fn validate_and_get_token(&self) -> Result<FeeToken>;

crates/sncast/src/main.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ use sncast::{
2828
chain_id_to_network_name, get_account, get_block_id, get_chain_id, get_class_hash_by_address,
2929
get_contract_class, get_default_state_file_name, NumbersFormat, ValidatedWaitParams, WaitForTx,
3030
};
31-
use starknet::accounts::ConnectedAccount;
3231
use starknet::core::types::ContractClass;
3332
use starknet::core::utils::get_selector_from_name;
3433
use starknet::providers::Provider;
@@ -309,12 +308,6 @@ async fn run_async_command(
309308
)
310309
.await?;
311310

312-
let fee_settings = fee_args
313-
.clone()
314-
.fee_token(fee_token)
315-
.try_into_fee_settings(&provider, account.block_id())
316-
.await?;
317-
318311
// safe to unwrap because "constructor" is a standardized name
319312
let selector = get_selector_from_name("constructor").unwrap();
320313

@@ -328,10 +321,11 @@ async fn run_async_command(
328321
&calldata,
329322
deploy.salt,
330323
deploy.unique,
331-
fee_settings,
324+
fee_args,
332325
deploy.nonce,
333326
&account,
334327
wait_config,
328+
fee_token,
335329
)
336330
.await
337331
.map_err(handle_starknet_command_error);

crates/sncast/src/starknet_commands/deploy.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,17 @@ pub async fn deploy(
8080
calldata: &Vec<Felt>,
8181
salt: Option<Felt>,
8282
unique: bool,
83-
fee_settings: FeeSettings,
83+
fee_args: FeeArgs,
8484
nonce: Option<Felt>,
8585
account: &SingleOwnerAccount<&JsonRpcClient<HttpTransport>, LocalWallet>,
8686
wait_config: WaitForTx,
87+
fee_token: FeeToken,
8788
) -> Result<DeployResponse, StarknetCommandError> {
89+
let fee_settings = fee_args
90+
.fee_token(fee_token)
91+
.try_into_fee_settings(account.provider(), account.block_id())
92+
.await?;
93+
8894
let salt = extract_or_generate_salt(salt);
8995
let factory = ContractFactory::new(class_hash, account);
9096
let result = match fee_settings {

crates/sncast/src/starknet_commands/script/run.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use shared::utils::build_readable_text;
3535
use sncast::get_nonce;
3636
use sncast::helpers::configuration::CastConfig;
3737
use sncast::helpers::constants::SCRIPT_LIB_ARTIFACT_NAME;
38-
use sncast::helpers::fee::{FeeArgs, FeeSettings, ScriptFeeSettings};
38+
use sncast::helpers::fee::{FeeArgs, ScriptFeeSettings};
3939
use sncast::helpers::rpc::RpcArgs;
4040
use sncast::response::structs::ScriptRunResponse;
4141
use sncast::state::hashing::{
@@ -161,8 +161,9 @@ impl<'a> ExtensionLogic for CastScriptExtension<'a> {
161161
let constructor_calldata = input_reader.read::<Vec<Felt>>()?;
162162
let salt = input_reader.read()?;
163163
let unique = input_reader.read()?;
164-
let fee_args: FeeSettings = input_reader.read::<ScriptFeeSettings>()?.into();
164+
let fee_args: FeeArgs = input_reader.read::<ScriptFeeSettings>()?.into();
165165
let nonce = input_reader.read()?;
166+
let fee_token = fee_args.fee_token.clone().unwrap_or_default();
166167

167168
let deploy_tx_id =
168169
generate_deploy_tx_id(class_hash, &constructor_calldata, salt, unique);
@@ -185,6 +186,7 @@ impl<'a> ExtensionLogic for CastScriptExtension<'a> {
185186
wait: true,
186187
wait_params: self.config.wait_params,
187188
},
189+
fee_token,
188190
));
189191

190192
self.state.maybe_insert_tx_entry(

0 commit comments

Comments
 (0)