# Minter Reward Model (the Math)

### Summary

Upon mint attempt, the PerpetualMint contracts request a random number from ChainlinkVRF. The random number is used to determine whether the mint attempt is successful, and then, if the attempt was successful, which of the deposited tokens is minted. If the attempt is unsuccessful, an alternative prize is minted, and the random number is used to determine what rarity the [prize](/key-sections/usdmint-token.md) will have.&#x20;

### Determining Mint Outcome

This is an outline of what the protocol does upon a user minting:

1. When a user requests to mint, Insrt fetches a random number from ChainlinkVRF.
2. The size of the random number is between `0` and `2^256 - 1`. This range is far too large for our purposes, since all probabilities are determined relative to a denominator or basis $$B$$, which for PerpetualMint, is $$B = 1000000000$$. This means the random number can be "Chunked" and maintain its randomness. "Chunking" is the process where a number is split up into its bit constituents. Since the bits are random to begin with, splitting them maintains the original randomness, so long as no bit shifting is done. For example, if a number `1289312375` is random, and it is chunked into `12893` and `12375`, then those two numbers are also random. The amount of chunks depends on how many random numbers are needed overall. In the case of an ERC721 asset mint, this is two numbers, so the random number is chunked into two. The first number $$t$$ is used to determine whether the mint is successful and the second random number $$p$$ is used to determine which of the deposited assets is picked.
3. The method to determine the outcome of the mint attempt using $$t$$ is outlined below:
   1. Each deposited NFT has a risk parameter $$R\_{i} \in (0,B]$$associated with it.
   2. The chance for a mint to be successful, denoted by $$P(M)$$, is the average risk parameter across all deposited assets in a pool. Given that each deposited NFT has a risk parameter $$R\_{i}$$ assigned to it, the total risk across all assets is $$S = \sum\limits\_{i=1}^{N}R\_{i}$$ where $$N$$ is the number of deposited assets. Hence, $$P(M)$$ is found to be $$P(M) = \frac{1}{N}\sum\limits\_{i=1}^{N}R\_{i}$$, where $$0 < P(M) \leq B$$.
   3. Since the random number $$t \in \[0, 2^{128}-1]$$ may be larger than the basis $$B$$, we normalize it by taking $$\tilde{t} = t \mod (B)$$ in order to ensure $$\tilde{t} \in \[0, B-1]$$. This number $$\tilde{t}$$ is referred to as the "mint number".&#x20;
   4. If $$\tilde{t}$$ is greater than or equal to the average risk, $$\tilde{t} \geq P(M)$$, the mint is deemed successful. Otherwise, the mint is deemed unsuccessful and no deposited NFT is minted.

### Determining Minted Asset Upon Successful Mint

In the case of a successful mint, another random number is used to select which deposited NFT is assigned from a collection.

1. Recall that each deposited NFT has a risk parameter $$R\_{i} \in (0,B]$$ associated with it, and that the total risk across all assets is $$S = \sum\limits\_{i=1}^{N}R\_{i}$$, where $$N$$ is the number of deposited assets.
2. Since the random number $$p$$ may be larger than the sum of risks $$S$$, we once again normalize it by taking $$\tilde{p} = p \mod (S)$$, where $$\tilde{p} \in \[0, S-1]$$. This number $$\tilde{p}$$ is referred to as the "picking number".&#x20;
3. We then compare the sampled value of $$\tilde{p}$$ to the cumulative sums of the risks $$R\_{i}$$. The selected index is the smallest $$i$$  which satisfies the condition $$\tilde{p} < \sum\limits\_{j=1}^{i}R\_{j}$$. In other words, if $$\tilde{p}$$ lies in the interval $$\[\sum\limits\_{j=1}^{i-1} R\_j,, ,\sum\limits\_{j=1}^{i} R\_j)$$, the index $$i$$ is selected.

### Determining ERC1155 Minted Asset Owner

The process for determining whether an ERC1155 asset is minted, and which token from the collection is minted, is similar to the steps taken for ERC721 collections outlined above. The key difference is that since more than one Depositor may have deposited the same token ID, it is necessary to determine which Depositor is chosen out of those who have deposited the minted token ID.

If the mint attempt pertains to an ERC1155 collection, the second random number $$p$$ is further chunked into $$p\_{1}$$ and $$p\_{2}$$, which are used to select the minted token, and the depositor of the minted token respectively, as there may be more than one depositor.

Each Depositor is associated with a "total risk", denoted by $$R\_{d}$$, corresponding to the selected token ID that is to be paid out as a prize. $$R\_{d}$$ represents the aggregate risk of a Depositor for a specific token ID, accounting for the possibility that a single user may deposit more than one token with the same ID. Formally, we can say $$R\_{d} = K \cdot R\_{i}$$, where $$K$$ is the number of tokens deposited, and $$R\_{i}$$ is the user-defined risk parameter for the NFT.&#x20;

The random number $$p\_{1}$$ is normalized with respect to the sum of depositor risks $$R = \sum\limits\_{d=0}^{D}R\_{d}$$, where $$D$$ is the number of depositors; giving us $$\tilde{p\_{1}} = p\_{1} \bmod(R)$$.

The individual depositor risks $$R\_{d}$$ are added until $$\tilde{p\_{1}}$$ exceeds the cumulative risk. At that point, the depositor matching the last added risk value is selected as the depositor of the minted asset.

### Determining Consolation Asset

If the mint is unsuccessful, the second random number $$p\_{2}$$ is used to determine the rarity of the consolation prize that is minted.&#x20;

The consolation assets have five tiers with the following probabilities:

$$\text{Tier 1: } P(T1) = \frac{500000000}{1000000000} = 50%$$ ,&#x20;

$$\text{Tier 2: } P(T2) = \frac{330000000}{1000000000} = 33%$$ ,&#x20;

$$\text{Tier 3: } P(T3) = \frac{125000000}{1000000000} = 12.5%$$ ,&#x20;

$$\text{Tier 4: } P(T4) = \frac{40000000}{1000000000} = 4%$$ , and &#x20;

$$\text{Tier 5: } P(T5) = \frac{5000000}{1000000000} = 0.5%$$ .

The number $$p\_{2}$$ is then normalized to be smaller than the sample space $$S$$, which in this case is the basis $$B$$; resulting in a "picking number" of $$\tilde{p\_{2}} = p\_{2} \bmod(B)$$.&#x20;

The number $$\tilde{p\_{2}}$$ is then compared to $$T1, T2, T3, T4, T5$$ so that, for example, if $$\tilde{p\_{2}} < T1$$ a tier 1 asset is minted, if $$T3 < \tilde{p\_{2}} < T2$$ a tier 2 asset is minted and if $$\tilde{p\_{2}}< T5$$ a tier 5 asset is minted.\
\
The method of value determination for the consolation assets may be found [here](/key-sections/usdmint-token.md).


---

# 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://docs.insrt.fun/key-sections/minter-reward-model-the-math.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.
