Skip to content

Commit

Permalink
feat: Rework genesis supply minting and burning
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippGackstatter committed Jul 2, 2024
1 parent af21774 commit 46d16ca
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 40 deletions.
31 changes: 31 additions & 0 deletions crates/iota-framework/docs/iota-framework/iota.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ It has 9 decimals, and the smallest unit (10^-9) is called "nano".
- [Struct `IOTA`](#0x2_iota_IOTA)
- [Constants](#@Constants_0)
- [Function `new`](#0x2_iota_new)
- [Function `mint_genesis_supply`](#0x2_iota_mint_genesis_supply)
- [Function `transfer`](#0x2_iota_transfer)


<pre><code><b>use</b> <a href="../move-stdlib/option.md#0x1_option">0x1::option</a>;
<b>use</b> <a href="../iota-framework/balance.md#0x2_balance">0x2::balance</a>;
<b>use</b> <a href="../iota-framework/coin.md#0x2_coin">0x2::coin</a>;
<b>use</b> <a href="../iota-framework/transfer.md#0x2_transfer">0x2::transfer</a>;
<b>use</b> <a href="../iota-framework/tx_context.md#0x2_tx_context">0x2::tx_context</a>;
Expand Down Expand Up @@ -133,6 +135,35 @@ This should be called only once during genesis creation.



</details>

<a name="0x2_iota_mint_genesis_supply"></a>

## Function `mint_genesis_supply`

Increase the IOTA supply.
This should be called only once during genesis creation.


<pre><code><b>fun</b> <a href="../iota-framework/iota.md#0x2_iota_mint_genesis_supply">mint_genesis_supply</a>(cap: &<b>mut</b> <a href="../iota-framework/coin.md#0x2_coin_TreasuryCap">coin::TreasuryCap</a>&lt;<a href="../iota-framework/iota.md#0x2_iota_IOTA">iota::IOTA</a>&gt;, amount: u64, ctx: &<a href="../iota-framework/tx_context.md#0x2_tx_context_TxContext">tx_context::TxContext</a>): <a href="../iota-framework/balance.md#0x2_balance_Balance">balance::Balance</a>&lt;<a href="../iota-framework/iota.md#0x2_iota_IOTA">iota::IOTA</a>&gt;
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>fun</b> <a href="../iota-framework/iota.md#0x2_iota_mint_genesis_supply">mint_genesis_supply</a>(cap: &<b>mut</b> TreasuryCap&lt;<a href="../iota-framework/iota.md#0x2_iota_IOTA">IOTA</a>&gt;, amount: u64, ctx: &TxContext): Balance&lt;<a href="../iota-framework/iota.md#0x2_iota_IOTA">IOTA</a>&gt; {
<b>assert</b>!(ctx.sender() == @0x0, <a href="../iota-framework/iota.md#0x2_iota_ENotSystemAddress">ENotSystemAddress</a>);
<b>assert</b>!(ctx.epoch() == 0, <a href="../iota-framework/iota.md#0x2_iota_EAlreadyMinted">EAlreadyMinted</a>);

cap.supply_mut().increase_supply(amount)
}
</code></pre>



</details>

<a name="0x2_iota_transfer"></a>
Expand Down
11 changes: 11 additions & 0 deletions crates/iota-framework/packages/iota-framework/sources/iota.move
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
/// It has 9 decimals, and the smallest unit (10^-9) is called "nano".
module iota::iota {
use iota::coin::{Self, TreasuryCap};
use iota::balance::Balance;
use iota::url;

const EAlreadyMinted: u64 = 0;
Expand Down Expand Up @@ -46,6 +47,16 @@ module iota::iota {
treasury
}

#[allow(unused_function)]
/// Increase the IOTA supply.
/// This should be called only once during genesis creation.
fun mint_genesis_supply(cap: &mut TreasuryCap<IOTA>, amount: u64, ctx: &TxContext): Balance<IOTA> {
assert!(ctx.sender() == @0x0, ENotSystemAddress);
assert!(ctx.epoch() == 0, EAlreadyMinted);

cap.supply_mut().increase_supply(amount)
}

public entry fun transfer(c: coin::Coin<IOTA>, recipient: address) {
transfer::public_transfer(c, recipient)
}
Expand Down
49 changes: 9 additions & 40 deletions crates/iota-genesis-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1091,53 +1091,22 @@ pub fn generate_genesis_system_object(
vec![],
);

let iota_supply = builder.programmable_move_call(
IOTA_FRAMEWORK_PACKAGE_ID,
ident_str!("coin").to_owned(),
ident_str!("supply_mut").to_owned(),
vec![GAS::type_().into()],
vec![iota_treasury_cap],
);

// TODO: This is will need to be modified after the timelock staking changes and
// to account for the migration objects with pre-allocated funds.
let total_iota_supply = builder
.input(CallArg::Pure(
bcs::to_bytes(&TOTAL_SUPPLY_NANOS).expect("serialization of u64 should succeed"),
))
.expect("adding the total IOTA supply argument should succeed");
.pure(&(TOTAL_SUPPLY_NANOS - token_distribution_schedule.funds_to_burn))
.expect("serialization of u64 should succeed");
let total_iota = builder.programmable_move_call(
IOTA_FRAMEWORK_PACKAGE_ID,
ident_str!("balance").to_owned(),
ident_str!("increase_supply").to_owned(),
vec![GAS::type_().into()],
vec![iota_supply, total_iota_supply],
);

// Step 5: Burn the tokens that are marked as such, according to the token distribution schedule.
let iotas_to_burn_arg = builder
.input(CallArg::Pure(
bcs::to_bytes(&token_distribution_schedule.funds_to_burn)
.expect("serialization of u64 should succeed"),
))
.expect("adding the funds to burn argument should succeed");
let iotas_to_burn_balance = builder.programmable_move_call(
IOTA_FRAMEWORK_PACKAGE_ID,
ident_str!("balance").to_owned(),
ident_str!("split").to_owned(),
vec![GAS::type_().into()],
vec![total_iota, iotas_to_burn_arg],
);

builder.programmable_move_call(
IOTA_FRAMEWORK_PACKAGE_ID,
ident_str!("balance").to_owned(),
ident_str!("decrease_supply").to_owned(),
vec![GAS::type_().into()],
vec![iota_supply, iotas_to_burn_balance],
ident_str!("iota").to_owned(),
ident_str!("mint_genesis_supply").to_owned(),
vec![],
vec![iota_treasury_cap, total_iota_supply],
);

// TODO: Rename the `destroy_storage_rebates` function or create a specific one.

// Step 6: Run genesis.
// Step 5: Run genesis.
// The first argument is the system state uid we got from step 1 and the second
// one is the IOTA `TreasuryCap` we got from step 4.
let mut arguments = vec![iota_system_state_uid, iota_treasury_cap, total_iota];
Expand Down

0 comments on commit 46d16ca

Please sign in to comment.