# Dice Game Contract

The Dice Game Contract contains the logic of the double dice game with the betting and distribution of the rewards to the players, the interaction with the reserve contract to handle the funds, and checking up the randomness from the terrand smart contract. \
This contract also handles the taxes on player wins and the casino advantage.

{% hint style="info" %}
This contract is managed by the governance contract.\
Many of its execute messages are only allowed to be called from the governance contract
{% endhint %}

| Key                    | Type          | Description                                                                               |
| ---------------------- | ------------- | ----------------------------------------------------------------------------------------- |
| gov\_contract\_address | CanonicalAddr | Address of the gov contract to be able to change parameters through voting                |
| reserve\_address       | CanonicalAddr | Address of the terra-vegas reserve contract                                               |
| terrand\_address       | CanonicalAddr | Address of the terrand contract to pull the randomness from                               |
| max\_cashflow          | Decimal       | maximum amount of UST to keep in the contract above which we send to the reserve contract |
| max\_number\_of\_bets  | Decimal       | Maximum number of bets per player per round                                               |
| win\_tax               | Decimal       | tax to be applied on the players rewards after the round bets are settled                 |
| native\_denom          | String        | the native coin to use for the bets                                                       |
| round\_duration        | vec           | duration of the round in seconds                                                          |

## InstantiateMsg <a href="#instantiatemsg" id="instantiatemsg"></a>

```rust
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct InstantiateMsg {
    pub native_denom: String,
    pub advantage_value: String,
    pub win_tax: String,
    pub max_number_of_bets: u64,
    pub max_betting_ratio: u64,
    pub round_duration: u64,
    pub max_cashflow: Uint128,
    pub terrand_address: String,
    pub reserve_address: String,
    pub gov_contract_address: String,
}
```

| Key                    | Type          | Description                                                                               |
| ---------------------- | ------------- | ----------------------------------------------------------------------------------------- |
| gov\_contract\_address | CanonicalAddr | Address of the gov contract to be able to change parameters through voting                |
| reserve\_address       | CanonicalAddr | Address of the terra-vegas reserve contract                                               |
| terrand\_address       | CanonicalAddr | Address of the terrand contract to pull the randomness from                               |
| max\_cashflow          | Decimal       | maximum amount of UST to keep in the contract above which we send to the reserve contract |
| max\_number\_of\_bets  | Decimal       | Maximum number of bets per player per round                                               |
| win\_tax               | Decimal       | tax to be applied on the players rewards after the round bets are settled                 |
| native\_denom          | String        | the native coin to use for the bets                                                       |
| round\_duration        | vec           | duration of the round in seconds                                                          |

## ExecuteMsg

### ChangeAdvantageValue <a href="#receive" id="receive"></a>

Changes the advantage ratio of the casino against the player

### ChangeMaxCashflow <a href="#receive" id="receive"></a>

chenages the maximum amount of UST to keep in the contract above which we send to the reserve contract

### Bet <a href="#receive" id="receive"></a>

To be called by a player to bet on a Live round. or to start a new round if some conditions are met.

### ReceiveRewards <a href="#receive" id="receive"></a>

To be called by a player to claim their accumulated rewards from the previous round(s) if they have any&#x20;

### DrainGame <a href="#receive" id="receive"></a>

Sends all the contract balance to the reserve contract

### StopGame <a href="#receive" id="receive"></a>

Halts the game so no player can bet anymore

## QueryMsg

```rust
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum QueryMsg {
    WinConfficients {},
    PlayerRewards {
        addr: String,
    },
    CurrentRound {},
    Bets {
        addr: String,
        round: u64,
    },
    OutcomeHistory {},
    GetConfig {},
    GetBettingLimit{},
```

### WinConfficients <a href="#receive" id="receive"></a>

Returns the winning multiplier per dice roll bet. it is a vector that depends on the distribution of probability of the double dice and the casino advantage.

### PlayerRewards <a href="#receive" id="receive"></a>

Returns the wins of the player who calls this function.

### CurrentRound <a href="#receive" id="receive"></a>

Returns the current dice game round.

### OutcomeHistory <a href="#receive" id="receive"></a>

Returns the outcome history of the dice. based on what terrand has generated.&#x20;

### Bets <a href="#receive" id="receive"></a>

Returns all the bets of a specific wallet for a specific dice round.

### GetConfig <a href="#receive" id="receive"></a>

returns the dice game contract config

### GetBettingLimit <a href="#receive" id="receive"></a>

Returns the maximum betting amount per round. This value is calculated every round based on how much money the reserve holds. This parameter is there to prevent players from betting higher than what the casino holds. The ratio is calculated based on some simulations the terra-vegas team has conducted.&#x20;


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://terra-vegas.gitbook.io/docs/contracts/dice-game-contract.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
