UpVsDownGameV2

Git Source

Inherits: Ownable

State Variables

GAME_DURATION

int32 public GAME_DURATION = 30;

gameController

address public gameController;

pools

mapping(bytes => Round) public pools;

feePercentage

uint256 public feePercentage = 5;

isRunning

bool public isRunning;

notRunningReason

bytes public notRunningReason;

gold

IGold public immutable gold;

priceFeed

IPriceFeed public immutable priceFeed;

WBTC

IERC20 public immutable WBTC;

usdc

IERC20 public immutable usdc;

lostGold

mapping(address => uint256) public lostGold;

Functions

onlyGameController

modifier onlyGameController();

onlyOpenPool

modifier onlyOpenPool(bytes calldata poolId);

onlyGameRunning

modifier onlyGameRunning();

onlyPoolExists

modifier onlyPoolExists(bytes calldata poolId);

constructor

constructor(IGold gold_, IPriceFeed oneInchPriceFeed_, IERC20 WBTC_, IERC20 usdc_);

changeGameDuration

function changeGameDuration(int32 newGameDuration) public onlyOwner;

changeGameControllerAddress

function changeGameControllerAddress(address newGameController) public onlyOwner;

changeGameFeePercentage

function changeGameFeePercentage(uint256 newFeePercentage) 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, uint32 batchSize, uint256 price) public onlyPoolExists(poolId);

returnBets

function returnBets(bytes calldata poolId, BetGroup storage group, uint32 batchSize) private;

distribute

function distribute(bytes calldata poolId, uint32 batchSize) public 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);

claimLostGold

function claimLostGold() external;

sendGold

function sendGold(address to, uint256 amount) private returns (bool success);

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;
    uint256 goldBet;
}