Skip to content

Commit 63b951c

Browse files
authored
Merge pull request #303 from utilityjnr/umaru
Implement cancel_market — cancel market and enable refunds
2 parents f7f4431 + ee8b8b9 commit 63b951c

1 file changed

Lines changed: 13 additions & 14 deletions

File tree

contracts/contracts/boxmeout/src/market.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,23 +1547,30 @@ impl PredictionMarket {
15471547
(yes_reserve, no_reserve, total_liquidity, yes_odds, no_odds)
15481548
}
15491549

1550-
/// Emergency function: Market creator can cancel unresolved market
1550+
/// Emergency function: Protocol Admin can cancel unresolved market
15511551
///
1552-
/// - Require creator authentication
1552+
/// - Require admin authentication
1553+
/// - Validate caller is the protocol admin via Factory
15531554
/// - Validate market state is OPEN or CLOSED (not resolved)
15541555
/// - Set market state to CANCELLED; participants claim refunds via claim_refund
15551556
/// - Emit MarketCancelled(market_id, creator, timestamp)
15561557
pub fn cancel_market(env: Env, creator: Address, market_id: BytesN<32>) {
15571558
creator.require_auth();
15581559

1559-
let stored_creator: Address = env
1560+
let factory: Address = env
15601561
.storage()
15611562
.persistent()
1562-
.get(&Symbol::new(&env, CREATOR_KEY))
1563+
.get(&Symbol::new(&env, FACTORY_KEY))
15631564
.expect("Market not initialized");
15641565

1565-
if creator != stored_creator {
1566-
panic!("Unauthorized: only creator can cancel");
1566+
// Verify the admin is indeed the protocol admin from the factory
1567+
let real_admin: Address = env.invoke_contract(
1568+
&factory,
1569+
&Symbol::new(&env, "get_admin"),
1570+
soroban_sdk::vec![&env],
1571+
);
1572+
if admin != real_admin {
1573+
panic!("Unauthorized: only admin can cancel");
15671574
}
15681575

15691576
let state: u32 = env
@@ -1586,16 +1593,8 @@ impl PredictionMarket {
15861593

15871594
let timestamp = env.ledger().timestamp();
15881595

1589-
#[contractevent]
1590-
pub struct MarketCancelledEvent {
1591-
pub market_id: BytesN<32>,
1592-
pub creator: Address,
1593-
pub timestamp: u64,
1594-
}
1595-
15961596
MarketCancelledEvent {
15971597
market_id,
1598-
creator,
15991598
timestamp,
16001599
}
16011600
.publish(&env);

0 commit comments

Comments
 (0)