AECGambit.sol
Quick Links
VIEW CONTRACT ON GITHUB
The AECGambit.sol contract is a provably fair, time-locked lottery game that serves as a utility and revenue source for the ecosystem. It offers a gamified way for users to participate in the protocol, with a sustainable economic model where 50% of every bet is sent directly to the PerpetualEngine as protocol revenue. The remaining 50% funds the prize pool.
Inherits from: ReentrancyGuard
Key State Variables & Constants
MIN_BET
uint256
Constant: The minimum allowed bet (100 AEC).
MAX_BET
uint256
Constant: The maximum allowed bet (10,000 AEC).
POOL_DURATION
uint256
Constant: The duration of each betting pool in blocks (approx. 2 minutes).
INITIAL_ALLOCATION
uint256
Constant: The initial prize allocation from the TokenDistributor (8,888,889 AEC).
perpetualEngine
address
The immutable address of the PerpetualEngine that receives 50% of every bet.
pools
mapping(uint256 => Pool)
A mapping from a poolId to a Pool struct containing its details (start/end block, seed, etc.).
poolBets
mapping(uint256 => mapping(address => Bet))
A nested mapping storing a user's Bet info for a specific poolId.
prizePool
uint256
The current total amount of AEC available in the prize pool to be won.
remainingAllocation
uint256
The remaining balance of the initial prize allocation from genesis.
Write Functions
User-Facing Functions
placeBet(uint256 amount): Allows a user to place a bet in the current active pool. The user must approve the contract to spend theamountof AEC. Reverts if the amount is outside theMIN_BETandMAX_BETrange or if the user has already bet in the current pool.claimWin(uint256 poolId): After a pool is drawn, a user calls this function to calculate their result and claim any winnings. The user's unique result is calculated on-the-fly using the pool's seed. Winnings are paid from theprizePooland the contract'sremainingAllocation.
Public Functions
drawPool(uint256 poolId): A permissionless function that can be called by anyone after a pool'sendBlockhas passed. It uses a future blockhash as a source of randomness to generate the pool'sseed, which is then used to determine individual results. This makes the draw provably fair.
View Functions
getCurrentPoolStatus(): Returns the status of the current lottery pool, including its ID, how many blocks remain, the total bets placed, and whether it is open for betting or ready to be drawn.getUserBet(address user, uint256 poolId): Retrieves a user's complete bet information for a specific pool, including the bet amount, claim status, and, if the pool is drawn, their calculated result, multiplier, and potential win amount.getGambitStats(): Provides an overview of the Gambit contract's lifetime statistics, including remaining allocation, current prize pool balance, total bets placed, total winnings paid out, and total revenue sent to the Engine.calculatePotentialWin(uint256 betAmount): A helper function that returns the potential prize tiers for a given bet amount, showing the multipliers, win amounts, and the chance of hitting each tier.
Events
PoolCreated(uint256 indexed poolId, uint256 endBlock): Emitted whenever a new lottery pool is created.BetPlaced(address indexed player, uint256 indexed poolId, uint256 amount, uint256 toEngine, uint256 toPool): Emitted for every bet, detailing the 50/50 split.PoolDrawn(uint256 indexed poolId, bytes32 seed): Emitted when a pool's result is finalized.WinClaimed(address indexed player, uint256 indexed poolId, uint256 betAmount, uint256 multiplier, uint256 winAmount): Emitted when a user claims their result, showing the outcome.MegaWin(): A special event emitted for very large multiplier wins (100x or more).AllocationDepleted(uint256 remainingAmount): Emitted as a warning when the initial prize allocation is running low.
Last updated