Skip to content

Commit

Permalink
Prettify Stored Mana calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippGackstatter committed Oct 27, 2023
1 parent a5a5e2d commit fe7705d
Showing 1 changed file with 17 additions and 50 deletions.
67 changes: 17 additions & 50 deletions tips/TIP-0039/tip-0039.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ It is an essential element of the IOTA protocol, as it is used:
- [**Block Issuance Credit**](#block-issuance-credit) (BIC) is the form of Mana that can be used to issue blocks. During
a transaction, Stored or Potential Mana can be _allotted_ which moves the Mana off the UTXO ledger and converts it to
BIC. Only this form of Mana be used to issue blocks.
- [**Mana Rewards**](#mana-rewards) reward participation in staking for validation and delegating IOTA tokens. The Mana
- [**Mana Rewards**](#mana-rewards) reward participation in staking for validation and delegating IOTA coins. The Mana
rewarded from these activities is not registered in the UTXO ledger and must be moved to it when claiming rewards as
described in [TIP-40](../TIP-0040/tip-0040.md##mana-rewards).

Expand Down Expand Up @@ -312,60 +312,27 @@ applies the decay to the result, where:

## Stored Mana

_Stored Mana_ is the main form of Mana. It is a UTXO-based form (i.e., it is contained in outputs, just like IOTA
tokens) of Mana that can be transferred within certain rules between different users, which allows for Mana market
development.
_Stored Mana_ is the main form of Mana. It is a UTXO-based form (i.e., it is contained in outputs, just like IOTA coins)
of Mana that can be transferred within certain rules between different users, which allows for the development of a Mana
market.

All output types, except Foundry and Delegation Outputs, can hold stored Mana in the _Mana_ field. This field represents
All output types, except Foundry and Delegation Outputs, can hold Stored Mana in the _Mana_ field. This field represents
the amount of stored Mana at the output's creation time until the time when the output is consumed without decay applied
to it.

Decay must, therefore, be applied whenever an output containing Stored Mana is consumed. The creation slot of each
output with stored Mana.

### Stored Mana Semantic Validation

- Stored Mana must be decayed before it is transferred into a new output as follows:
- Let `manaAmount`, `consumptionSlot`, and `creationSlot`, be
<table>
<tr>
<td><b>Name</b></td>
<td><b>Type</b></td>
<td><b>Description</b></td>
</tr>
<tr>
<td>manaAmount</td>
<td>uint64</td>
<td>
The amount of stored Mana held by the output.
</td>
</tr>
<tr>
<td>creationSlot</td>
<td>uint64</td>
<td>
The index of slot in which the output was created.
</td>
</tr>
<tr>
<td>consumptionSlot</td>
<td>uint64</td>
<td>
The index of slot in which the output is consumed.
</td>
</tr>
</table>

The algorithm to decay the Stored Mana is as follows:
Decay must, therefore, be applied whenever an output containing Stored Mana is consumed.

```go
creationEpoch = epoch(creationSlot)
consumptionEpoch = epoch(consumptionSlot)
if creationEpoch == consumptionEpoch:
newManaAmount = manaAmount
else:
newManaAmount = Decay(manaAmount, consumptionEpoch - creationEpoch)
```
Let `Stored Mana(Mana Amount, Output Creation Slot, Transaction Creation Slot)` be the procedure that calculates the
decay whenever Stored Mana is consumed, where:

- `Mana Amount` is the amount of Stored Mana held in an output.
- `Output Creation Slot` is the slot index in which the output was created.
- `Transaction Creation Slot` is the slot index in which the output is consumed.
- Let `Output Creation Epoch` be the epoch to which `Output Creation Slot` belongs.
- Let `Transaction Creation Epoch` be the epoch to which `Transaction Creation Slot` belongs.
- See [TIP-46 (Time)](TIP-0046/tip-0046.md#time) for the conversion procedure.
- If `Output Creation Epoch == Transaction Creation Epoch` return `Mana Amount`.
- Otherwise return `Decay(Mana Amount, Transaction Creation Epoch - Output Creation Epoch)`.

## Block Issuance Credit

Expand Down

0 comments on commit fe7705d

Please sign in to comment.