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
49 changes: 47 additions & 2 deletions contracts/game_contract/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ const TREASURY: Symbol = symbol_short!("TREASURY"); // i128 treasury reserve
const BALANCES: Symbol = symbol_short!("BALANCES"); // Map<Address, i128>
const USED_NONCE: Symbol = symbol_short!("NONCES"); // Map<u64, bool>
const MAX_STAKE: Symbol = symbol_short!("MAXSTAKE");
const MAX_PRIZE_POOL: Symbol = symbol_short!("MAXPOOL");

// Maximum number of proofs accepted by a single claim_puzzle_rewards_batch call.
// Keeps per-invocation resource usage (CPU/memory/events) bounded.
Expand Down Expand Up @@ -230,10 +231,12 @@ pub enum ContractError {
EscrowStillLocked = 34,
/// Tournament escrow already released (#532)
EscrowAlreadyReleased = 35,
/// Total prize pool would exceed the configured limit
PrizePoolLimitExceeded = 36,
/// claim_puzzle_rewards_batch called with an empty proof list
EmptyBatch = 36,
EmptyBatch = 37,
/// claim_puzzle_rewards_batch called with more proofs than MAX_BATCH_SIZE
BatchTooLarge = 37,
BatchTooLarge = 38,
}

#[contract]
Expand Down Expand Up @@ -348,6 +351,18 @@ impl GameContract {
return Err(ContractError::StakeLimitExceeded);
}

let max_prize_pool: i128 = env
.storage()
.instance()
.get(&MAX_PRIZE_POOL)
.unwrap_or(2_000);
let expected_pool = wager_amount
.checked_mul(2)
.ok_or(ContractError::InvalidAmount)?;
if expected_pool > max_prize_pool {
return Err(ContractError::PrizePoolLimitExceeded);
}

player1.require_auth();

let token_client = Self::token_client(&env);
Expand Down Expand Up @@ -420,6 +435,19 @@ impl GameContract {
return Err(ContractError::StakeLimitExceeded);
}

let max_prize_pool: i128 = env
.storage()
.instance()
.get(&MAX_PRIZE_POOL)
.unwrap_or(2_000);
let total_pool = game
.wager_amount
.checked_mul(2)
.ok_or(ContractError::InvalidAmount)?;
if total_pool > max_prize_pool {
return Err(ContractError::PrizePoolLimitExceeded);
}

player2.require_auth();
let token_client = Self::token_client(&env);
let contract_address = env.current_contract_address();
Expand Down Expand Up @@ -957,6 +985,7 @@ impl GameContract {
.instance()
.set(&TREASURY_ADDR, &treasury_address);
env.storage().instance().set(&MAX_STAKE, &1_000i128);
env.storage().instance().set(&MAX_PRIZE_POOL, &2_000i128);
}

pub fn set_max_stake(env: Env, admin: Address, new_limit: i128) {
Expand All @@ -975,6 +1004,22 @@ impl GameContract {
env.storage().instance().set(&MAX_STAKE, &new_limit);
}

pub fn set_max_prize_pool(env: Env, admin: Address, new_limit: i128) {
let current_admin: Address = env
.storage()
.instance()
.get(&CONTRACT_ADMIN)
.expect("Not initialized");
current_admin.require_auth();
if admin != current_admin {
panic!("Unauthorized admin address");
}
if new_limit <= 0 {
panic!("Max prize pool must be positive");
}
env.storage().instance().set(&MAX_PRIZE_POOL, &new_limit);
}

pub fn configure_fees(env: Env, admin: Address, fee_bips: u32, treasury_address: Address) {
let current_admin: Address = env
.storage()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,17 @@
"u32": 50
}
},
{
"key": {
"symbol": "MAXPOOL"
},
"val": {
"i128": {
"hi": 0,
"lo": 2000
}
}
},
{
"key": {
"symbol": "MAXSTAKE"
Expand Down Expand Up @@ -515,4 +526,4 @@
"failed_call": false
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,17 @@
"u64": 1
}
},
{
"key": {
"symbol": "MAXPOOL"
},
"val": {
"i128": {
"hi": 0,
"lo": 2000
}
}
},
{
"key": {
"symbol": "MAXSTAKE"
Expand Down Expand Up @@ -2287,4 +2298,4 @@
"failed_call": false
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,17 @@
"u64": 1
}
},
{
"key": {
"symbol": "MAXPOOL"
},
"val": {
"i128": {
"hi": 0,
"lo": 2000
}
}
},
{
"key": {
"symbol": "MAXSTAKE"
Expand Down Expand Up @@ -1643,4 +1654,4 @@
"failed_call": false
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@
"u32": 0
}
},
{
"key": {
"symbol": "MAXPOOL"
},
"val": {
"i128": {
"hi": 0,
"lo": 2000
}
}
},
{
"key": {
"symbol": "MAXSTAKE"
Expand Down Expand Up @@ -400,4 +411,4 @@
"failed_call": false
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@
"u32": 0
}
},
{
"key": {
"symbol": "MAXPOOL"
},
"val": {
"i128": {
"hi": 0,
"lo": 2000
}
}
},
{
"key": {
"symbol": "MAXSTAKE"
Expand Down Expand Up @@ -404,4 +415,4 @@
"failed_call": false
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@
"u32": 0
}
},
{
"key": {
"symbol": "MAXPOOL"
},
"val": {
"i128": {
"hi": 0,
"lo": 2000
}
}
},
{
"key": {
"symbol": "MAXSTAKE"
Expand Down Expand Up @@ -454,4 +465,4 @@
"failed_call": false
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@
"u32": 0
}
},
{
"key": {
"symbol": "MAXPOOL"
},
"val": {
"i128": {
"hi": 0,
"lo": 2000
}
}
},
{
"key": {
"symbol": "MAXSTAKE"
Expand Down Expand Up @@ -531,4 +542,4 @@
"failed_call": false
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@
"u32": 0
}
},
{
"key": {
"symbol": "MAXPOOL"
},
"val": {
"i128": {
"hi": 0,
"lo": 2000
}
}
},
{
"key": {
"symbol": "MAXSTAKE"
Expand Down Expand Up @@ -491,4 +502,4 @@
"failed_call": false
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,17 @@
"u64": 1
}
},
{
"key": {
"symbol": "MAXPOOL"
},
"val": {
"i128": {
"hi": 0,
"lo": 2000
}
}
},
{
"key": {
"symbol": "MAXSTAKE"
Expand Down Expand Up @@ -2264,4 +2275,4 @@
"failed_call": false
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,17 @@
"u64": 1
}
},
{
"key": {
"symbol": "MAXPOOL"
},
"val": {
"i128": {
"hi": 0,
"lo": 2000
}
}
},
{
"key": {
"symbol": "MAXSTAKE"
Expand Down Expand Up @@ -2265,4 +2276,4 @@
"failed_call": false
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,17 @@
"u64": 1
}
},
{
"key": {
"symbol": "MAXPOOL"
},
"val": {
"i128": {
"hi": 0,
"lo": 2000
}
}
},
{
"key": {
"symbol": "MAXSTAKE"
Expand Down Expand Up @@ -2425,4 +2436,4 @@
"failed_call": false
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@
"u32": 0
}
},
{
"key": {
"symbol": "MAXPOOL"
},
"val": {
"i128": {
"hi": 0,
"lo": 2000
}
}
},
{
"key": {
"symbol": "MAXSTAKE"
Expand Down Expand Up @@ -377,4 +388,4 @@
"failed_call": false
}
]
}
}
Loading
Loading