Skip to content
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

feat: add raw max fee to TransactionsOptions #1856

Merged
merged 6 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions bin/sozo/src/commands/options/transaction.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use clap::Args;
use dojo_world::migration::TxnConfig;
use starknet::core::types::FieldElement;

#[derive(Debug, Args)]
#[command(next_help_heading = "Transaction options")]
Expand All @@ -10,8 +11,14 @@ pub struct TransactionOptions {
#[arg(long_help = "The multiplier to use for the fee estimate. This value will be used on \
the estimated fee which will be used as the max fee for the transaction. \
(max_fee = estimated_fee * multiplier)")]
#[arg(conflicts_with = "max_fee_raw")]
pub fee_estimate_multiplier: Option<f64>,

#[arg(short, long)]
#[arg(help = "Maximum raw value to be used for fees, in Wei.")]
#[arg(conflicts_with = "fee_estimate_multiplier")]
pub max_fee_raw: Option<FieldElement>,

#[arg(short, long)]
#[arg(help = "Wait until the transaction is accepted by the sequencer, returning the status \
and hash.")]
Expand All @@ -35,6 +42,7 @@ impl From<TransactionOptions> for TxnConfig {
fee_estimate_multiplier: value.fee_estimate_multiplier,
wait: value.wait,
receipt: value.receipt,
max_fee_raw: value.max_fee_raw,
}
}
}
1 change: 1 addition & 0 deletions crates/dojo-world/src/migration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ pub struct TxnConfig {
pub fee_estimate_multiplier: Option<f64>,
pub wait: bool,
pub receipt: bool,
pub max_fee_raw: Option<FieldElement>,
}

#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
Expand Down
14 changes: 12 additions & 2 deletions crates/dojo-world/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,10 @@
{
type R;

/// Sets `fee_estimate_multiplier` from `TxnConfig` if its present before calling `send` method
/// on the respective type.
/// Sets `fee_estimate_multiplier` and `max_fee_raw` from `TxnConfig` if its present before
/// calling `send` method on the respective type.
/// NOTE: If both are specified `max_fee_raw` will take precedence and `fee_estimate_multiplier`
/// will be ignored by `starknet-rs`
async fn send_with_cfg(
self,
txn_config: &TxnConfig,
Expand All @@ -363,6 +365,10 @@
self = self.fee_estimate_multiplier(*fee_est_mul);
}

if let TxnConfig { max_fee_raw: Some(max_fee_r), .. } = txn_config {
self = self.max_fee(*max_fee_r);

Check warning on line 369 in crates/dojo-world/src/utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/dojo-world/src/utils.rs#L369

Added line #L369 was not covered by tests
}

self.send().await
}
}
Expand All @@ -381,6 +387,10 @@
self = self.fee_estimate_multiplier(*fee_est_mul);
}

if let TxnConfig { max_fee_raw: Some(max_raw_f), .. } = txn_config {
self = self.max_fee(*max_raw_f);

Check warning on line 391 in crates/dojo-world/src/utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/dojo-world/src/utils.rs#L391

Added line #L391 was not covered by tests
}

self.send().await
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/sozo/ops/src/tests/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ async fn migrate_with_small_fee_multiplier_will_fail() {
&ws,
&mut migration,
&account,
TxnConfig { fee_estimate_multiplier: Some(0.2f64), wait: false, receipt: false },
TxnConfig { fee_estimate_multiplier: Some(0.2f64), ..Default::default() },
)
.await
.is_err()
Expand Down
Loading