🚶♂

# Minter Reward Model (the Math)

The mechanism of how mint attempts are resolved.

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 will have.

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".
- 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.

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".
- 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.

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. 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.If the mint is unsuccessful, the second random number

$p_{2}$

is used to determine the rarity of the consolation prize that is minted. The consolation assets have five tiers with the following probabilities:

$\text{Tier 1: } P(T1) = \frac{500000000}{1000000000} = 50\%$

,

$\text{Tier 2: } P(T2) = \frac{330000000}{1000000000} = 33\%$

,

$\text{Tier 3: } P(T3) = \frac{125000000}{1000000000} = 12.5\%$

,

$\text{Tier 4: } P(T4) = \frac{40000000}{1000000000} = 4\%$

, and

$\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)$

. 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.