Skip to content
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
3 changes: 3 additions & 0 deletions contracts/markets/benches/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};

Check failure on line 1 in contracts/markets/benches/main.rs

View workflow job for this annotation

GitHub Actions / Markets Benchmark & Regression Check (5% threshold)

unresolved import `criterion`
use markets::{MarketsContract, MarketsContractClient};
use soroban_sdk::{testutils::Address as _, Address, Env, String, Vec};

Expand Down Expand Up @@ -88,6 +88,7 @@
&end_time,
&resolution_source,
&outcome_tags,
&black_box(1i128),
))
})
});
Expand Down Expand Up @@ -120,6 +121,7 @@
&end_time,
&resolution_source,
&outcome_tags,
&1i128,
);

c.bench_function("contract_place_bet", |b| {
Expand Down Expand Up @@ -158,6 +160,7 @@
&end_time,
&resolution_source,
&outcome_tags,
&1i128,
);
black_box(client.resolve_market(&creator, &market_id, &0u32))
})
Expand Down
13 changes: 12 additions & 1 deletion contracts/markets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ pub struct MarketData {
pub winning_outcome: u32,
/// Whether the market has been cancelled.
pub cancelled: bool,
/// Minimum bet amount in stroops. Any `place_bet` call with `amount < min_bet`
/// is rejected with `StakeTooSmall`. Must be >= 1.
pub min_bet: i128,
}

/// On-chain record of a user's bet on a market.
Expand Down Expand Up @@ -845,6 +848,7 @@ impl MarketsContract {
end_time: u64,
resolution_source: String,
outcome_tags: Vec<String>,
min_bet: i128,
) -> u32 {
Self::create_market_with_curve(
env.clone(),
Expand All @@ -855,6 +859,7 @@ impl MarketsContract {
resolution_source,
outcome_tags,
PayoutCurveConfig::winner_takes_all(&env),
min_bet,
)
}

Expand All @@ -868,13 +873,18 @@ impl MarketsContract {
resolution_source: String,
outcome_tags: Vec<String>,
curve: PayoutCurveConfig,
min_bet: i128,
) -> u32 {
creator.require_auth();

if outcome_tags.len() < 2 {
panic_with_error!(env, ContractError::InvalidConfig);
}

if min_bet < 1 {
panic_with_error!(env, ContractError::InvalidConfig);
}

Self::validate_payout_curve(&env, &curve, outcome_tags.len());

let counter: u32 = env
Expand Down Expand Up @@ -905,6 +915,7 @@ impl MarketsContract {
resolved: false,
winning_outcome: 0,
cancelled: false,
min_bet,
};
env.storage()
.persistent()
Expand Down Expand Up @@ -1001,7 +1012,7 @@ impl MarketsContract {
panic_with_error!(env, ContractError::InvalidOutcome);
}

if amount <= 0 {
if amount <= 0 || amount < market.min_bet {
panic_with_error!(env, ContractError::StakeTooSmall);
}

Expand Down
7 changes: 7 additions & 0 deletions contracts/markets/tests/auth_boundary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ fn create_market_with_mock_auth(setup: &TestSetup<'_>) -> u32 {
end_time,
resolution_source.clone(),
outcome_tags.clone(),
1i128,
)
.into_val(env),
sub_invokes: &[],
Expand All @@ -104,6 +105,7 @@ fn create_market_with_mock_auth(setup: &TestSetup<'_>) -> u32 {
&end_time,
&resolution_source,
&outcome_tags,
&1i128,
)
}

Expand All @@ -126,6 +128,7 @@ fn create_market_with_auth_check(setup: &TestSetup<'_>) -> u32 {
&end_time,
&resolution_source,
&outcome_tags,
&1i128,
)
}

Expand Down Expand Up @@ -159,6 +162,7 @@ fn test_create_market_requires_auth() {
&end_time,
&resolution_source,
&outcome_tags,
&1i128,
);
assert!(
result.is_err(),
Expand Down Expand Up @@ -213,6 +217,7 @@ fn test_market_limit_blocks_both_creation_entrypoints() {
&end_time,
&resolution_source,
&outcome_tags,
&1i128,
);
assert_eq!(
regular_result.unwrap_err().unwrap(),
Expand All @@ -228,6 +233,7 @@ fn test_market_limit_blocks_both_creation_entrypoints() {
&resolution_source,
&outcome_tags,
&curve,
&1i128,
);
assert_eq!(
curve_result.unwrap_err().unwrap(),
Expand Down Expand Up @@ -280,6 +286,7 @@ fn test_create_market_requires_auth_market_creator() {
&end_time,
&resolution_source,
&outcome_tags,
&1i128,
);
assert!(result.is_ok(), "Authorized market creator should succeed");
}
Expand Down
Loading
Loading