// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface AggregatorV3Interface {
function decimals() external view returns (uint8);
function description() external view returns (string memory);
function version() external view returns (uint256);
function getRoundData(uint80 _roundId)
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
);
function latestRoundData()
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
interface ArbGasInfo {
// return gas prices in wei, assuming the specified aggregator is used
// (
// per L2 tx,
// per L1 calldata unit, (zero byte = 4 units, nonzero byte = 16 units)
// per storage allocation,
// per ArbGas base,
// per ArbGas congestion,
// per ArbGas total
// )
function getPricesInWeiWithAggregator(
address aggregator
) external view returns (uint, uint, uint, uint, uint, uint);
// return gas prices in wei, as described above, assuming the caller's preferred aggregator is used
// if the caller hasn't specified a preferred aggregator, the default aggregator is assumed
function getPricesInWei()
external
view
returns (uint, uint, uint, uint, uint, uint);
// return prices in ArbGas (per L2 tx, per L1 calldata unit, per storage allocation),
// assuming the specified aggregator is used
function getPricesInArbGasWithAggregator(
address aggregator
) external view returns (uint, uint, uint);
// return gas prices in ArbGas, as described above, assuming the caller's preferred aggregator is used
// if the caller hasn't specified a preferred aggregator, the default aggregator is assumed
function getPricesInArbGas() external view returns (uint, uint, uint);
// return gas accounting parameters (speedLimitPerSecond, gasPoolMax, maxTxGasLimit)
function getGasAccountingParams() external view returns (uint, uint, uint);
// get ArbOS's estimate of the L1 gas price in wei
function getL1GasPriceEstimate() external view returns (uint);
// set ArbOS's estimate of the L1 gas price in wei
// reverts unless called by chain owner or designated gas oracle (if any)
function setL1GasPriceEstimate(uint priceInWei) external;
// get L1 gas fees paid by the current transaction (txBaseFeeWei, calldataFeeWei)
function getCurrentTxL1GasFees() external view returns (uint);
}
interface ArbSys {
/**
* @notice Get Arbitrum block number (distinct from L1 block number; Arbitrum genesis block has block number 0)
* @return block number as int
*/
function arbBlockNumber() external view returns (uint256);
/**
* @notice Get Arbitrum block hash (reverts unless currentBlockNum-256 <= arbBlockNum < currentBlockNum)
* @return block hash
*/
function arbBlockHash(uint256 arbBlockNum) external view returns (bytes32);
/**
* @notice Gets the rollup's unique chain identifier
* @return Chain identifier as int
*/
function arbChainID() external view returns (uint256);
/**
* @notice Get internal version number identifying an ArbOS build
* @return version number as int
*/
function arbOSVersion() external view returns (uint256);
/**
* @notice Returns 0 since Nitro has no concept of storage gas
* @return uint 0
*/
function getStorageGasAvailable() external view returns (uint256);
/**
* @notice (deprecated) check if current call is top level (meaning it was triggered by an EoA or a L1 contract)
* @dev this call has been deprecated and may be removed in a future release
* @return true if current execution frame is not a call by another L2 contract
*/
function isTopLevelCall() external view returns (bool);
/**
* @notice map L1 sender contract address to its L2 alias
* @param sender sender address
* @param unused argument no longer used
* @return aliased sender address
*/
function mapL1SenderContractAddressToL2Alias(
address sender,
address unused
) external pure returns (address);
/**
* @notice check if the caller (of this caller of this) is an aliased L1 contract address
* @return true iff the caller's address is an alias for an L1 contract address
*/
function wasMyCallersAddressAliased() external view returns (bool);
/**
* @notice return the address of the caller (of this caller of this), without applying L1 contract address aliasing
* @return address of the caller's caller, without applying L1 contract address aliasing
*/
function myCallersAddressWithoutAliasing() external view returns (address);
/**
* @notice Send given amount of Eth to dest from sender.
* This is a convenience function, which is equivalent to calling sendTxToL1 with empty data.
* @param destination recipient address on L1
* @return unique identifier for this L2-to-L1 transaction.
*/
function withdrawEth(
address destination
) external payable returns (uint256);
/**
* @notice Send a transaction to L1
* @dev it is not possible to execute on the L1 any L2-to-L1 transaction which contains data
* to a contract address without any code (as enforced by the Bridge contract).
* @param destination recipient address on L1
* @param data (optional) calldata for L1 contract call
* @return a unique identifier for this L2-to-L1 transaction.
*/
function sendTxToL1(
address destination,
bytes calldata data
) external payable returns (uint256);
/**
* @notice Get send Merkle tree state
* @return size number of sends in the history
* @return root root hash of the send history
* @return partials hashes of partial subtrees in the send history tree
*/
function sendMerkleTreeState()
external
view
returns (uint256 size, bytes32 root, bytes32[] memory partials);
/**
* @notice creates a send txn from L2 to L1
* @param position = (level << 192) + leaf = (0 << 192) + leaf = leaf
*/
event L2ToL1Tx(
address caller,
address indexed destination,
uint256 indexed hash,
uint256 indexed position,
uint256 arbBlockNum,
uint256 ethBlockNum,
uint256 timestamp,
uint256 callvalue,
bytes data
);
/// @dev DEPRECATED in favour of the new L2ToL1Tx event above after the nitro upgrade
event L2ToL1Transaction(
address caller,
address indexed destination,
uint256 indexed uniqueId,
uint256 indexed batchNumber,
uint256 indexInBatch,
uint256 arbBlockNum,
uint256 ethBlockNum,
uint256 timestamp,
uint256 callvalue,
bytes data
);
/**
* @notice logs a merkle branch for proof synthesis
* @param reserved an index meant only to align the 4th index with L2ToL1Transaction's 4th event
* @param hash the merkle hash
* @param position = (level << 192) + leaf
*/
event SendMerkleUpdate(
uint256 indexed reserved,
bytes32 indexed hash,
uint256 indexed position
);
}
//@dev A library that abstracts out opcodes that behave differently across chains.
//@dev The methods below return values that are pertinent to the given chain.
//@dev For instance, ChainSpecificUtil.getBlockNumber() returns L2 block number in L2 chains
library ChainSpecificUtil {
address private constant ARBSYS_ADDR =
address(0x0000000000000000000000000000000000000064);
ArbSys private constant ARBSYS = ArbSys(ARBSYS_ADDR);
address private constant ARBGAS_ADDR =
address(0x000000000000000000000000000000000000006C);
ArbGasInfo private constant ARBGAS = ArbGasInfo(ARBGAS_ADDR);
uint256 private constant ARB_MAINNET_CHAIN_ID = 42161;
uint256 private constant ARB_GOERLI_TESTNET_CHAIN_ID = 421613;
function getBlockhash(uint64 blockNumber) internal view returns (bytes32) {
uint256 chainid = block.chainid;
if (
chainid == ARB_MAINNET_CHAIN_ID ||
chainid == ARB_GOERLI_TESTNET_CHAIN_ID
) {
if (
(getBlockNumber() - blockNumber) > 256 ||
blockNumber >= getBlockNumber()
) {
return "";
}
return ARBSYS.arbBlockHash(blockNumber);
}
return blockhash(blockNumber);
}
function getBlockNumber() internal view returns (uint256) {
uint256 chainid = block.chainid;
if (
chainid == ARB_MAINNET_CHAIN_ID ||
chainid == ARB_GOERLI_TESTNET_CHAIN_ID
) {
return ARBSYS.arbBlockNumber();
}
return block.number;
}
function getCurrentTxL1GasFees() internal view returns (uint256) {
uint256 chainid = block.chainid;
if (
chainid == ARB_MAINNET_CHAIN_ID ||
chainid == ARB_GOERLI_TESTNET_CHAIN_ID
) {
return ARBGAS.getCurrentTxL1GasFees();
}
return 0;
}
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;
import "@chainlink/contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol";
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import {SafeERC20, IERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
//import "hardhat/console.sol";
import "./ChainSpecificUtil.sol";
interface IBankRoll {
function getIsGame(address game) external view returns (bool);
function getIsValidWager(
address game,
address tokenAddress
) external view returns (bool);
function transferPayout(
address player,
uint256 payout,
address token
) external;
function getOwner() external view returns (address);
function isPlayerSuspended(
address player
) external view returns (bool, uint256);
}
interface IVRFCoordinatorV2 is VRFCoordinatorV2Interface {
function getFeeConfig()
external
view
returns (
uint32,
uint32,
uint32,
uint32,
uint32,
uint24,
uint24,
uint24,
uint24
);
}
contract Common is ReentrancyGuard {
using SafeERC20 for IERC20;
uint256 public VRFFees;
address public ChainLinkVRF;
address public _trustedForwarder;
AggregatorV3Interface public LINK_ETH_FEED;
IVRFCoordinatorV2 public IChainLinkVRF;
IBankRoll public Bankroll;
error NotApprovedBankroll();
error InvalidValue(uint256 required, uint256 sent);
error TransferFailed();
error RefundFailed();
error NotOwner(address want, address have);
error ZeroWager();
error PlayerSuspended(uint256 suspensionTime);
/**
* @dev function to transfer the player wager to bankroll, and charge for VRF fee
* , reverts if bankroll doesn't approve game or token
* @param tokenAddress address of the token the wager is made on
* @param wager total amount wagered
*/
function _transferWager(
address tokenAddress,
uint256 wager,
uint256 gasAmount,
uint256 l1Multiplier,
address msgSender
) internal returns (uint256 VRFfee) {
if (!Bankroll.getIsValidWager(address(this), tokenAddress)) {
revert NotApprovedBankroll();
}
if (wager == 0) {
revert ZeroWager();
}
(bool suspended, uint256 suspendedTime) = Bankroll.isPlayerSuspended(
msgSender
);
if (suspended) {
revert PlayerSuspended(suspendedTime);
}
VRFfee = getVRFFee(gasAmount, l1Multiplier);
if (tokenAddress == address(0)) {
if (msg.value < wager + VRFfee) {
revert InvalidValue(wager + VRFfee, msg.value);
}
_refundExcessValue(msg.value - (VRFfee + wager));
} else {
if (msg.value < VRFfee) {
revert InvalidValue(VRFfee, msg.value);
}
IERC20(tokenAddress).safeTransferFrom(
msgSender,
address(this),
wager
);
_refundExcessValue(msg.value - VRFfee);
}
VRFFees += VRFfee;
}
/**
* @dev function to transfer the wager held by the game contract to the bankroll
* @param tokenAddress address of the token to transfer
* @param amount token amount to transfer
*/
function _transferToBankroll(
address tokenAddress,
uint256 amount
) internal {
if (tokenAddress == address(0)) {
(bool success, ) = payable(address(Bankroll)).call{value: amount}(
""
);
if (!success) {
revert RefundFailed();
}
} else {
IERC20(tokenAddress).safeTransfer(address(Bankroll), amount);
}
}
/**
* @dev calculates in form of native token the fee charged by chainlink VRF
* @return fee amount of fee user has to pay
*/
function getVRFFee(
uint256 gasAmount,
uint256 l1Multiplier
) public view returns (uint256 fee) {
(, int256 answer, , , ) = LINK_ETH_FEED.latestRoundData();
(uint32 fulfillmentFlatFeeLinkPPMTier1, , , , , , , , ) = IChainLinkVRF
.getFeeConfig();
uint256 l1CostWei = (ChainSpecificUtil.getCurrentTxL1GasFees() *
l1Multiplier) / 10;
fee =
tx.gasprice *
(gasAmount) +
l1CostWei +
((1e12 *
uint256(fulfillmentFlatFeeLinkPPMTier1) *
uint256(answer)) / 1e18);
}
/**
* @dev returns to user the excess fee sent to pay for the VRF
* @param refund amount to send back to user
*/
function _refundExcessValue(uint256 refund) internal {
if (refund == 0) {
return;
}
(bool success, ) = payable(msg.sender).call{value: refund}("");
if (!success) {
revert RefundFailed();
}
}
/**
* @dev function to charge user for VRF
*/
function _payVRFFee(
uint256 gasAmount,
uint256 l1Multiplier
) internal returns (uint256 VRFfee) {
VRFfee = getVRFFee(gasAmount, l1Multiplier);
if (msg.value < VRFfee) {
revert InvalidValue(VRFfee, msg.value);
}
_refundExcessValue(msg.value - VRFfee);
VRFFees += VRFfee;
}
/**
* @dev function to transfer VRF fees acumulated in the contract to the Bankroll
* Can only be called by owner
*/
function transferFees(address to) external nonReentrant {
if (msg.sender != Bankroll.getOwner()) {
revert NotOwner(Bankroll.getOwner(), msg.sender);
}
uint256 fee = VRFFees;
VRFFees = 0;
(bool success, ) = payable(address(to)).call{value: fee}("");
if (!success) {
revert TransferFailed();
}
}
/**
* @dev function to transfer wager to game contract, without charging for VRF
* @param tokenAddress tokenAddress the wager is made on
* @param wager wager amount
*/
function _transferWagerPvPNoVRF(
address tokenAddress,
uint256 wager
) internal {
if (!Bankroll.getIsValidWager(address(this), tokenAddress)) {
revert NotApprovedBankroll();
}
if (tokenAddress == address(0)) {
if (!(msg.value == wager)) {
revert InvalidValue(wager, msg.value);
}
} else {
IERC20(tokenAddress).safeTransferFrom(
msg.sender,
address(this),
wager
);
}
}
/**
* @dev function to transfer wager to game contract, including charge for VRF
* @param tokenAddress tokenAddress the wager is made on
* @param wager wager amount
*/
function _transferWagerPvP(
address tokenAddress,
uint256 wager,
uint256 gasAmount
) internal {
if (!Bankroll.getIsValidWager(address(this), tokenAddress)) {
revert NotApprovedBankroll();
}
uint256 VRFfee = getVRFFee(gasAmount, 20);
if (tokenAddress == address(0)) {
if (msg.value < wager + VRFfee) {
revert InvalidValue(wager, msg.value);
}
_refundExcessValue(msg.value - (VRFfee + wager));
} else {
if (msg.value < VRFfee) {
revert InvalidValue(VRFfee, msg.value);
}
IERC20(tokenAddress).safeTransferFrom(
msg.sender,
address(this),
wager
);
_refundExcessValue(msg.value - VRFfee);
}
VRFFees += VRFfee;
}
/**
* @dev transfers payout from the game contract to the players
* @param player address of the player to transfer the payout to
* @param payout amount of payout to transfer
* @param tokenAddress address of the token that payout will be transfered
*/
function _transferPayoutPvP(
address player,
uint256 payout,
address tokenAddress
) internal {
if (tokenAddress == address(0)) {
(bool success, ) = payable(player).call{value: payout}("");
if (!success) {
revert TransferFailed();
}
} else {
IERC20(tokenAddress).safeTransfer(player, payout);
}
}
/**
* @dev transfers house edge from game contract to bankroll
* @param amount amount to transfer
* @param tokenAddress address of token to transfer
*/
function _transferHouseEdgePvP(
uint256 amount,
address tokenAddress
) internal {
if (tokenAddress == address(0)) {
(bool success, ) = payable(address(Bankroll)).call{value: amount}(
""
);
if (!success) {
revert TransferFailed();
}
} else {
IERC20(tokenAddress).safeTransfer(address(Bankroll), amount);
}
}
/**
* @dev function to request bankroll to give payout to player
* @param player address of the player
* @param payout amount of payout to give
* @param tokenAddress address of the token in which to give the payout
*/
function _transferPayout(
address player,
uint256 payout,
address tokenAddress
) internal {
Bankroll.transferPayout(player, payout, tokenAddress);
}
/**
* @dev function to send the request for randomness to chainlink
* @param numWords number of random numbers required
*/
function _requestRandomWords(
uint32 numWords
) internal returns (uint256 s_requestId) {
s_requestId = VRFCoordinatorV2Interface(ChainLinkVRF)
.requestRandomWords(
0x08ba8f62ff6c40a58877a106147661db43bc58dabfb814793847a839aa03367f,
53,
1,
2500000,
numWords
);
}
function isTrustedForwarder(address forwarder) public view returns (bool) {
return forwarder == _trustedForwarder;
}
function _msgSender() internal view returns (address ret) {
if (msg.data.length >= 20 && isTrustedForwarder(msg.sender)) {
// At this point we know that the sender is a trusted forwarder,
// so we trust that the last bytes of msg.data are the verified sender address.
// extract sender address from the end of msg.data
assembly {
ret := shr(96, calldataload(sub(calldatasize(), 20)))
}
} else {
ret = msg.sender;
}
}
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;
import "./Common.sol";
/**
* @title Dice game, players predict if outcome will be over or under the selected number
*/
contract Dice is Common {
using SafeERC20 for IERC20;
constructor(
address _bankroll,
address _vrf,
address link_eth_feed,
address _forwarder
) {
Bankroll = IBankRoll(_bankroll);
IChainLinkVRF = IVRFCoordinatorV2(_vrf);
LINK_ETH_FEED = AggregatorV3Interface(link_eth_feed);
ChainLinkVRF = _vrf;
_trustedForwarder = _forwarder;
}
struct DiceGame {
uint256 wager;
uint256 stopGain;
uint256 stopLoss;
uint256 requestID;
address tokenAddress;
uint64 blockNumber;
uint32 numBets;
uint32 multiplier;
bool isOver;
}
mapping(address => DiceGame) diceGames;
mapping(uint256 => address) diceIDs;
/**
* @dev event emitted at the start of the game
* @param playerAddress address of the player that made the bet
* @param wager wagered amount
* @param multiplier selected multiplier for the wager range 10421-9900000, multiplier values divide by 10000
* @param tokenAddress address of token the wager was made, 0 address is considered the native coin
* @param isOver if true dice outcome must be over the selected number, false must be under
* @param numBets number of bets the player intends to make
* @param stopGain gain value at which the betting stop if a gain is reached
* @param stopLoss loss value at which the betting stop if a loss is reached
*/
event Dice_Play_Event(
address indexed playerAddress,
uint256 wager,
uint32 multiplier,
address tokenAddress,
bool isOver,
uint32 numBets,
uint256 stopGain,
uint256 stopLoss,
uint256 VRFFee
);
/**
* @dev event emitted by the VRF callback with the bet results
* @param playerAddress address of the player that made the bet
* @param wager wager amount
* @param payout total payout transfered to the player
* @param tokenAddress address of token the wager was made and payout, 0 address is considered the native coin
* @param diceOutcomes results of dice roll, range 0-9999
* @param payouts individual payouts for each bet
* @param numGames number of games performed
*/
event Dice_Outcome_Event(
address indexed playerAddress,
uint256 wager,
uint256 payout,
address tokenAddress,
uint32 multiplier,
bool isOver,
uint256[] diceOutcomes,
uint256[] payouts,
uint32 numGames
);
/**
* @dev event emitted when a refund is done in dice
* @param player address of the player reciving the refund
* @param wager amount of wager that was refunded
* @param tokenAddress address of token the refund was made in
*/
event Dice_Refund_Event(
address indexed player,
uint256 wager,
address tokenAddress
);
error AwaitingVRF(uint256 requestID);
error InvalidMultiplier(uint256 max, uint256 min, uint256 multiplier);
error InvalidNumBets(uint256 maxNumBets);
error WagerAboveLimit(uint256 wager, uint256 maxWager);
error NotAwaitingVRF();
error BlockNumberTooLow(uint256 have, uint256 want);
error OnlyCoordinatorCanFulfill(address have, address want);
/**
* @dev function to get current request player is await from VRF, returns 0 if none
* @param player address of the player to get the state
*/
function Dice_GetState(
address player
) external view returns (DiceGame memory) {
return (diceGames[player]);
}
/**
* @dev Function to play Dice, takes the user wager saves bet parameters and makes a request to the VRF
* @param wager wager amount
* @param tokenAddress address of token to bet, 0 address is considered the native coin
* @param numBets number of bets to make, and amount of random numbers to request
* @param stopGain treshold value at which the bets stop if a certain profit is obtained
* @param stopLoss treshold value at which the bets stop if a certain loss is obtained
* @param isOver if true dice outcome must be over the selected number, false must be under
* @param multiplier selected multiplier for the wager range 10421-9900000, multiplier values divide by 10000
*/
function Dice_Play(
uint256 wager,
uint32 multiplier,
address tokenAddress,
bool isOver,
uint32 numBets,
uint256 stopGain,
uint256 stopLoss
) external payable nonReentrant {
address msgSender = _msgSender();
if (!(multiplier >= 10421 && multiplier <= 9900000)) {
revert InvalidMultiplier(9900000, 10421, multiplier);
}
if (diceGames[msgSender].requestID != 0) {
revert AwaitingVRF(diceGames[msgSender].requestID);
}
if (!(numBets > 0 && numBets <= 100)) {
revert InvalidNumBets(100);
}
_kellyWager(wager, tokenAddress, multiplier);
uint256 fee = _transferWager(
tokenAddress,
wager * numBets,
700000,
21,
msgSender
);
uint256 id = _requestRandomWords(numBets);
diceGames[msgSender] = DiceGame(
wager,
stopGain,
stopLoss,
id,
tokenAddress,
uint64(block.number),
numBets,
multiplier,
isOver
);
diceIDs[id] = msgSender;
emit Dice_Play_Event(
msgSender,
wager,
multiplier,
tokenAddress,
isOver,
numBets,
stopGain,
stopLoss,
fee
);
}
/**
* @dev Function to refund user in case of VRF request failling
*/
function Dice_Refund() external nonReentrant {
address msgSender = _msgSender();
DiceGame storage game = diceGames[msgSender];
if (game.requestID == 0) {
revert NotAwaitingVRF();
}
if (game.blockNumber + 200 > block.number) {
revert BlockNumberTooLow(block.number, game.blockNumber + 200);
}
uint256 wager = game.wager * game.numBets;
address tokenAddress = game.tokenAddress;
delete (diceIDs[game.requestID]);
delete (diceGames[msgSender]);
if (tokenAddress == address(0)) {
(bool success, ) = payable(msgSender).call{value: wager}("");
if (!success) {
revert TransferFailed();
}
} else {
IERC20(tokenAddress).safeTransfer(msgSender, wager);
}
emit Dice_Refund_Event(msgSender, wager, tokenAddress);
}
/**
* @dev function called by Chainlink VRF with random numbers
* @param requestId id provided when the request was made
* @param randomWords array of random numbers
*/
function rawFulfillRandomWords(
uint256 requestId,
uint256[] memory randomWords
) external {
if (msg.sender != ChainLinkVRF) {
revert OnlyCoordinatorCanFulfill(msg.sender, ChainLinkVRF);
}
fulfillRandomWords(requestId, randomWords);
}
function fulfillRandomWords(
uint256 requestId,
uint256[] memory randomWords
) internal {
address playerAddress = diceIDs[requestId];
if (playerAddress == address(0)) revert();
DiceGame storage game = diceGames[playerAddress];
int256 totalValue;
uint256 payout;
uint32 i;
uint256[] memory diceOutcomes = new uint256[](game.numBets);
uint256[] memory payouts = new uint256[](game.numBets);
uint256 winChance = 99000000000 / game.multiplier;
uint256 numberToRollOver = 10000000 - winChance;
uint256 gamePayout = (game.multiplier * game.wager) / 10000;
address tokenAddress = game.tokenAddress;
for (i = 0; i < game.numBets; i++) {
if (totalValue >= int256(game.stopGain)) {
break;
}
if (totalValue <= -int256(game.stopLoss)) {
break;
}
diceOutcomes[i] = randomWords[i] % 10000000;
if (diceOutcomes[i] >= numberToRollOver && game.isOver == true) {
totalValue += int256(gamePayout - game.wager);
payout += gamePayout;
payouts[i] = gamePayout;
continue;
}
if (diceOutcomes[i] <= winChance && game.isOver == false) {
totalValue += int256(gamePayout - game.wager);
payout += gamePayout;
payouts[i] = gamePayout;
continue;
}
totalValue -= int256(game.wager);
}
payout += (game.numBets - i) * game.wager;
emit Dice_Outcome_Event(
playerAddress,
game.wager,
payout,
tokenAddress,
game.multiplier,
game.isOver,
diceOutcomes,
payouts,
i
);
_transferToBankroll(tokenAddress, game.wager * game.numBets);
delete (diceIDs[requestId]);
delete (diceGames[playerAddress]);
if (payout != 0) {
_transferPayout(playerAddress, payout, tokenAddress);
}
}
/**
* @dev calculates the maximum wager allowed based on the bankroll size
*/
function _kellyWager(
uint256 wager,
address tokenAddress,
uint256 multiplier
) internal view {
uint256 balance;
if (tokenAddress == address(0)) {
balance = address(Bankroll).balance;
} else {
balance = IERC20(tokenAddress).balanceOf(address(Bankroll));
}
uint256 maxWager = (balance * (11000 - 10890)) / (multiplier - 10000);
if (wager > maxWager) {
revert WagerAboveLimit(wager, maxWager);
}
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool);
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be _NOT_ENTERED
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/draft-IERC20Permit.sol";
import "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
function safeTransfer(
IERC20 token,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(
IERC20 token,
address spender,
uint256 value
) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
uint256 newAllowance = oldAllowance - value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
}
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
// Return data is optional
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface VRFCoordinatorV2Interface {
/**
* @notice Get configuration relevant for making requests
* @return minimumRequestConfirmations global min for request confirmations
* @return maxGasLimit global max for request gas limit
* @return s_provingKeyHashes list of registered key hashes
*/
function getRequestConfig()
external
view
returns (
uint16,
uint32,
bytes32[] memory
);
/**
* @notice Request a set of random words.
* @param keyHash - Corresponds to a particular oracle job which uses
* that key for generating the VRF proof. Different keyHash's have different gas price
* ceilings, so you can select a specific one to bound your maximum per request cost.
* @param subId - The ID of the VRF subscription. Must be funded
* with the minimum subscription balance required for the selected keyHash.
* @param minimumRequestConfirmations - How many blocks you'd like the
* oracle to wait before responding to the request. See SECURITY CONSIDERATIONS
* for why you may want to request more. The acceptable range is
* [minimumRequestBlockConfirmations, 200].
* @param callbackGasLimit - How much gas you'd like to receive in your
* fulfillRandomWords callback. Note that gasleft() inside fulfillRandomWords
* may be slightly less than this amount because of gas used calling the function
* (argument decoding etc.), so you may need to request slightly more than you expect
* to have inside fulfillRandomWords. The acceptable range is
* [0, maxGasLimit]
* @param numWords - The number of uint256 random values you'd like to receive
* in your fulfillRandomWords callback. Note these numbers are expanded in a
* secure way by the VRFCoordinator from a single random value supplied by the oracle.
* @return requestId - A unique identifier of the request. Can be used to match
* a request to a response in fulfillRandomWords.
*/
function requestRandomWords(
bytes32 keyHash,
uint64 subId,
uint16 minimumRequestConfirmations,
uint32 callbackGasLimit,
uint32 numWords
) external returns (uint256 requestId);
/**
* @notice Create a VRF subscription.
* @return subId - A unique subscription id.
* @dev You can manage the consumer set dynamically with addConsumer/removeConsumer.
* @dev Note to fund the subscription, use transferAndCall. For example
* @dev LINKTOKEN.transferAndCall(
* @dev address(COORDINATOR),
* @dev amount,
* @dev abi.encode(subId));
*/
function createSubscription() external returns (uint64 subId);
/**
* @notice Get a VRF subscription.
* @param subId - ID of the subscription
* @return balance - LINK balance of the subscription in juels.
* @return reqCount - number of requests for this subscription, determines fee tier.
* @return owner - owner of the subscription.
* @return consumers - list of consumer address which are able to use this subscription.
*/
function getSubscription(uint64 subId)
external
view
returns (
uint96 balance,
uint64 reqCount,
address owner,
address[] memory consumers
);
/**
* @notice Request subscription owner transfer.
* @param subId - ID of the subscription
* @param newOwner - proposed new owner of the subscription
*/
function requestSubscriptionOwnerTransfer(uint64 subId, address newOwner) external;
/**
* @notice Request subscription owner transfer.
* @param subId - ID of the subscription
* @dev will revert if original owner of subId has
* not requested that msg.sender become the new owner.
*/
function acceptSubscriptionOwnerTransfer(uint64 subId) external;
/**
* @notice Add a consumer to a VRF subscription.
* @param subId - ID of the subscription
* @param consumer - New consumer which can use the subscription
*/
function addConsumer(uint64 subId, address consumer) external;
/**
* @notice Remove a consumer from a VRF subscription.
* @param subId - ID of the subscription
* @param consumer - Consumer to remove from the subscription
*/
function removeConsumer(uint64 subId, address consumer) external;
/**
* @notice Cancel a subscription
* @param subId - ID of the subscription
* @param to - Where to send the remaining LINK to
*/
function cancelSubscription(uint64 subId, address to) external;
/*
* @notice Check to see if there exists a request commitment consumers
* for all consumers and keyhashes for a given sub.
* @param subId - ID of the subscription
* @return true if there exists at least one unfulfilled request for the subscription, false
* otherwise.
*/
function pendingRequestExists(uint64 subId) external view returns (bool);
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
{
"compilationTarget": {
"contracts/Dice.sol": "Dice"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 1000
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_bankroll","type":"address"},{"internalType":"address","name":"_vrf","type":"address"},{"internalType":"address","name":"link_eth_feed","type":"address"},{"internalType":"address","name":"_forwarder","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"uint256","name":"requestID","type":"uint256"}],"name":"AwaitingVRF","type":"error"},{"inputs":[{"internalType":"uint256","name":"have","type":"uint256"},{"internalType":"uint256","name":"want","type":"uint256"}],"name":"BlockNumberTooLow","type":"error"},{"inputs":[{"internalType":"uint256","name":"max","type":"uint256"},{"internalType":"uint256","name":"min","type":"uint256"},{"internalType":"uint256","name":"multiplier","type":"uint256"}],"name":"InvalidMultiplier","type":"error"},{"inputs":[{"internalType":"uint256","name":"maxNumBets","type":"uint256"}],"name":"InvalidNumBets","type":"error"},{"inputs":[{"internalType":"uint256","name":"required","type":"uint256"},{"internalType":"uint256","name":"sent","type":"uint256"}],"name":"InvalidValue","type":"error"},{"inputs":[],"name":"NotApprovedBankroll","type":"error"},{"inputs":[],"name":"NotAwaitingVRF","type":"error"},{"inputs":[{"internalType":"address","name":"want","type":"address"},{"internalType":"address","name":"have","type":"address"}],"name":"NotOwner","type":"error"},{"inputs":[{"internalType":"address","name":"have","type":"address"},{"internalType":"address","name":"want","type":"address"}],"name":"OnlyCoordinatorCanFulfill","type":"error"},{"inputs":[{"internalType":"uint256","name":"suspensionTime","type":"uint256"}],"name":"PlayerSuspended","type":"error"},{"inputs":[],"name":"RefundFailed","type":"error"},{"inputs":[],"name":"TransferFailed","type":"error"},{"inputs":[{"internalType":"uint256","name":"wager","type":"uint256"},{"internalType":"uint256","name":"maxWager","type":"uint256"}],"name":"WagerAboveLimit","type":"error"},{"inputs":[],"name":"ZeroWager","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"playerAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"wager","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"payout","type":"uint256"},{"indexed":false,"internalType":"address","name":"tokenAddress","type":"address"},{"indexed":false,"internalType":"uint32","name":"multiplier","type":"uint32"},{"indexed":false,"internalType":"bool","name":"isOver","type":"bool"},{"indexed":false,"internalType":"uint256[]","name":"diceOutcomes","type":"uint256[]"},{"indexed":false,"internalType":"uint256[]","name":"payouts","type":"uint256[]"},{"indexed":false,"internalType":"uint32","name":"numGames","type":"uint32"}],"name":"Dice_Outcome_Event","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"playerAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"wager","type":"uint256"},{"indexed":false,"internalType":"uint32","name":"multiplier","type":"uint32"},{"indexed":false,"internalType":"address","name":"tokenAddress","type":"address"},{"indexed":false,"internalType":"bool","name":"isOver","type":"bool"},{"indexed":false,"internalType":"uint32","name":"numBets","type":"uint32"},{"indexed":false,"internalType":"uint256","name":"stopGain","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"stopLoss","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"VRFFee","type":"uint256"}],"name":"Dice_Play_Event","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"player","type":"address"},{"indexed":false,"internalType":"uint256","name":"wager","type":"uint256"},{"indexed":false,"internalType":"address","name":"tokenAddress","type":"address"}],"name":"Dice_Refund_Event","type":"event"},{"inputs":[],"name":"Bankroll","outputs":[{"internalType":"contract IBankRoll","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ChainLinkVRF","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"player","type":"address"}],"name":"Dice_GetState","outputs":[{"components":[{"internalType":"uint256","name":"wager","type":"uint256"},{"internalType":"uint256","name":"stopGain","type":"uint256"},{"internalType":"uint256","name":"stopLoss","type":"uint256"},{"internalType":"uint256","name":"requestID","type":"uint256"},{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"uint64","name":"blockNumber","type":"uint64"},{"internalType":"uint32","name":"numBets","type":"uint32"},{"internalType":"uint32","name":"multiplier","type":"uint32"},{"internalType":"bool","name":"isOver","type":"bool"}],"internalType":"struct Dice.DiceGame","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"wager","type":"uint256"},{"internalType":"uint32","name":"multiplier","type":"uint32"},{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"bool","name":"isOver","type":"bool"},{"internalType":"uint32","name":"numBets","type":"uint32"},{"internalType":"uint256","name":"stopGain","type":"uint256"},{"internalType":"uint256","name":"stopLoss","type":"uint256"}],"name":"Dice_Play","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"Dice_Refund","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"IChainLinkVRF","outputs":[{"internalType":"contract IVRFCoordinatorV2","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"LINK_ETH_FEED","outputs":[{"internalType":"contract AggregatorV3Interface","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"VRFFees","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"_trustedForwarder","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"gasAmount","type":"uint256"},{"internalType":"uint256","name":"l1Multiplier","type":"uint256"}],"name":"getVRFFee","outputs":[{"internalType":"uint256","name":"fee","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"forwarder","type":"address"}],"name":"isTrustedForwarder","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"requestId","type":"uint256"},{"internalType":"uint256[]","name":"randomWords","type":"uint256[]"}],"name":"rawFulfillRandomWords","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"}],"name":"transferFees","outputs":[],"stateMutability":"nonpayable","type":"function"}]