Skip to content

winrprotocol/JustBet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JUSTBET Smart Contracts

Logo

Core Contracts

Core

The Core contract serves as a foundational contract that provides shared functionality for other contracts in the system. It is imported by both Solo and Multiplayer games, with Solo games importing it via Common.sol.

In order to ensure security, Core imports the Pausable and ReentrancyGuard contracts from OpenZeppelin, as well as the Access.sol helper contract.

The Core contract acts as a mediator between games and the Vault Manager.

Vault Manager

Vault Manager that allows for the escrow of tokens and the broadcasting of information between contracts. The contract imports various functions from OpenZeppelin libraries, such as SafeERC20, which provides safe token transfers, and IERC20Metadata.

The contract includes several events that can be emitted to notify external contracts of certain events such as the escrow of tokens, payback, withdrawal and refunds.

The contract includes a mapping of the totalEscrowTokens that keeps track of the total amount of tokens that are currently held in escrow.

The contract includes several functions that allow for the escrow of tokens, such as

escrow: which allows whitelisted tokens to be escrowed by a specific sender.

setReferralReward: which allows for the assignment of referral rewards.

payback: which releases a certain amount of escrowed tokens to a recipient.

The contract also includes functions that allow for the withdrawal of tokens, such as

getEscrowedTokens: which allows the Vault to retrieve the amount of tokens needed from the escrow.

payin: which allows the Vault to deposit tokens into the escrow.

Overall, this contract is designed to simplify token transfers and provide an easy way for contracts to communicate with each other.

Randomizer Router

The main functionality of the contract is to create and manage requests for random numbers from providers. It contains the following functions:

setProvider: adds a new provider and grants the necessary role.

getDefaultProvider: returns the default provider.

updateDefaultProvider: updates the default provider.

_addRequest: adds a new request to the list.

request: creates a new immediate random number request.

scheduledRequest: creates a new scheduled random number request.

trigger: triggers a scheduled request.

reRequest: re-calls for not filled requests.

Games

The functions in both solo and multiplayer games overlap in many ways. For instance, both types of games utilize the Randomizer Router to generate random numbers, and they also rely on the Vault Manager contract for carrying out token transactions.

Solo Games

Common Solo

Common Solo that provides common functionality for different games. This contract defines some state variables, events, and modifiers that are used by child contracts to implement the game-specific functionality.

The contract defines some functions:

updateMaxGameCount: updates the maximum selectable game count

updateRefundCooldown: updates the duration to refund

shouldStop: checks the profit and loss amount to stop the game when it reaches the limits

calcWager: calculates the unused and used bet amount

refundGame: refunds the uncompleted game wagers

shareEscrow: shares the amount which was escrowed while starting the game by the player

This contract is designed to be extended by child contracts that implement game-specific functionality.

Games

CoinFlip

Coin-Flip game, where the player chooses heads or tails and bets an amount. The contract requests a random number and pays out the winnings based on the result.

Some of the main functions are

calcReward: a function that calculates the reward based on the player's wager and the win multiplier.

isWon: a function that determines whether the player has won based on their choice and the result of the coin flip.

getResultNumbers: a function that returns an array of modded numbers based on the random numbers generated by the randomizer.

play: a function that executes the game logic and calculates the payouts.

bet: a function that allows the player to bet on the game. It transfers the player's tokens to the contract and 
escrows them until the game is resolved. It then triggers the randomizer to generate a random number and pays out the winnings to the player.

Range

The contract defines a set of functions to implement a game that allows players to select a value within a certain range and win a payout if the modded random number requested by the contract falls within that range. The range is from 5 to 95 by default. The contract includes several functions to perform calculations necessary to determine payouts and winnings for players.

isWon: a function to determine whether a player has won or lost

calcSelectionRange: a function to calculate the selection range for a given choice

calcWinMultiplier: a function to calculate the winning multiplier for a given choice

calcReward: a function to calculate the reward for a given choice and wager

getResultNumbers: a function to calculate the modded random numbers based on the game and raw random numbers

play: the main game logic function, which takes a wager and a choice and calculates the payout based on the result of the game

Dice

Dice, it implements a simple dice game, where players can choose up to 5 numbers between 1 and 6 and win a payout if any of the chosen numbers matches the result of rolling a 6-sided die.

calcReward: function that calculates the payout for a given number of choices and wager, 
based on the win multipliers.
getResultNumbers: function that generates an array of random numbers between 1 and 6, 
based on raw random numbers provided by an external randomizer.

isWon: function that checks if any of the player's chosen numbers match the result of rolling the die.

play: main game logic function that implements the decision mechanism and calculates the payouts and 
profits for a given game, based on the player's choices,the random numbers generated by the randomizer, 
and the house edge. The function includes several input parameters,
such as the stop gain and stop loss limits, which restrict the maximum profits and losses for the game.

Plinko

Plinko is a game where a player selects a row at the top of a board and a ball is dropped from the top of the board. The ball bounces around on pegs until it lands in one of the slots at the bottom of the board, each of which is associated with a payout multiplier. The player's payout is determined by the payout multiplier of the slot where the ball lands.

getMultipliers: returns the payout multipliers for a particular row.

getMultiplier: returns a specific payout multiplier for a particular row and slot.

calcReward: calculates the player's payout for a given row, slot, and wager.

RPS

Rock-paper-scissors (RPS). It allows players to wager an amount of tokens on their choice of rock, paper, or scissors. The contract uses a random number generator to determine the result of each game, and payouts are determined by the game's win multipliers and the player's wager.

play function takes a Game struct as input and returns the accumulated payouts, the number of games played
and an array of payouts for each individual game.

The calcReward function calculates the reward for a particular game outcome and wager.

Limbo

In the game of Limbo, players make a wager and select a multiplier for it. A random number is then requested, and if the chosen multiplier is equal to or greater than the random number, the player wins the wager.

"calcReward" function that calculates the reward for a player based on their wager and chosen multiplier.

"isWon" function that determines whether a player has won or lost based on their choice and the result of the game.

"getResultNumbers" function that calculates the result of the game based on the random numbers generated.

"play" function that implements the game logic and returns the payout, played game count, and payouts at every step of the game.

Multiplayer Games

Moon

It defines the Moon game that involves players choosing a multiplier for their wager, and if the multiplier is greater than or equal to a random number requested after the wager period, they receive a reward.

calcReward: calculates the reward for a given wager and multiplier

getParticipant: gets the Bet struct for a player in a game

_createGame() internal: creates a new game if the previous game has timed out. 
Schedules a random number generation request for the new game.

Wheel

Wheel is a game where players place bets on a spinning wheel with 24 gray slots, 16 blue slots, 8 green slots, and 1 red slot. The outcome of the game is determined by where the wheel stops.

More

About

JustBet Repos

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published