UpVsDownGameV1
Inherits: Ownable
State Variables
gameController
address public gameController;
pools
mapping(bytes => Round) public pools;
feePercentage
uint8 public feePercentage = 5;
feeAddress
address public feeAddress = msg.sender;
isRunning
bool public isRunning;
notRunningReason
bytes public notRunningReason;
Functions
onlyGameController
modifier onlyGameController();
onlyOpenPool
modifier onlyOpenPool(bytes calldata poolId);
onlyGameRunning
modifier onlyGameRunning();
onlyPoolExists
modifier onlyPoolExists(bytes calldata poolId);
constructor
constructor(address newGameController);
changeGameControllerAddress
function changeGameControllerAddress(address newGameController) public onlyOwner;
changeGameFeePercentage
function changeGameFeePercentage(uint8 newFeePercentage) public onlyOwner;
changeGameFeeAddress
function changeGameFeeAddress(address newFeeAddress) public onlyOwner;
stopGame
function stopGame(bytes calldata reason) public onlyOwner;
startGame
function startGame() public onlyOwner;
createPool
function createPool(bytes calldata poolId, uint256 minBetAmount, uint256 maxBetAmount, uint256 poolBetsLimit)
public
onlyGameController;
trigger
function trigger(bytes calldata poolId, int64 timeMS, int32 price, uint32 batchSize)
public
onlyGameController
onlyPoolExists(poolId);
returnBets
function returnBets(bytes calldata poolId, BetGroup storage group, uint32 batchSize) private;
distribute
function distribute(bytes calldata poolId, uint32 batchSize, int64 timeMS)
public
onlyGameController
onlyPoolExists(poolId);
calculateDistribution
function calculateDistribution(BetGroup storage winners, BetGroup storage losers)
private
view
returns (Distribution memory);
clearPool
function clearPool(bytes calldata poolId) private;
hasPendingDistributions
function hasPendingDistributions(bytes calldata poolId) public view returns (bool);
isPoolOpen
function isPoolOpen(bytes calldata poolId) public view returns (bool);
addBet
function addBet(BetGroup storage betGroup, uint256 amount, string calldata avatar, string calldata countryCode)
private
returns (uint256);
makeTrade
function makeTrade(makeTradeStruct calldata userTrade)
public
payable
onlyOpenPool(userTrade.poolId)
onlyGameRunning
onlyPoolExists(userTrade.poolId);
sendEther
function sendEther(address to, uint256 amount) private;
Events
RoundStarted
event RoundStarted(
bytes poolId,
int64 timestamp,
int32 price,
uint256 minTradeAmount,
uint256 maxTradeAmount,
uint256 poolTradesLimit,
bytes indexed indexedPoolId
);
RoundEnded
event RoundEnded(bytes poolId, int64 timestamp, int32 startPrice, int32 endPrice, bytes indexed indexedPoolId);
TradePlaced
event TradePlaced(
bytes poolId,
address sender,
uint256 amount,
string prediction,
uint256 newTotal,
bytes indexed indexedPoolId,
address indexed indexedSender,
string avatarUrl,
string countryCode,
int64 roundStartTime
);
TradeReturned
event TradeReturned(bytes poolId, address sender, uint256 amount);
GameStopped
event GameStopped(bytes reason);
GameStarted
event GameStarted();
RoundDistributed
event RoundDistributed(bytes poolId, uint256 totalWinners, uint256 from, uint256 to, int64 timestamp);
TradeWinningsSent
event TradeWinningsSent(
bytes poolId, address sender, uint256 tradeAmount, uint256 winningsAmount, address indexed indexedSender
);
Errors
PendingDistributions
error PendingDistributions();
Structs
BetGroup
struct BetGroup {
uint256[] bets;
address[] addresses;
string[] avatars;
string[] countries;
uint256 total;
uint256 distributedCount;
uint256 totalDistributed;
}
Round
struct Round {
bool created;
int32 startPrice;
int32 endPrice;
uint256 minBetAmount;
uint256 maxBetAmount;
uint256 poolBetsLimit;
BetGroup upBetGroup;
BetGroup downBetGroup;
int64 roundStartTime;
}
Distribution
struct Distribution {
uint256 fee;
uint256 totalMinusFee;
uint256 pending;
}
makeTradeStruct
struct makeTradeStruct {
bytes poolId;
string avatarUrl;
string countryCode;
bool upOrDown;
}