0x0::supply

Module containing Supply type

Supply tracks the supply of a given object type or an accumualtion of actions. It tracks the current supply and guarantees that it cannot surpass the maximum supply defined. Among others, this is used to keep track of NFT supply for collections.

Structs

supply::Supply has drop, store

Fields:

Name Type Description
frozen bool
max u64
current u64

Supply tracks supply parameters

Supply can be frozen, therefore making it impossible to change the maximum supply.

Methods

public fun new(max: u64, frozen: bool): supply::Supply

Creates a new Supply object

public fun max(supply: &supply::Supply): u64

Maximum supply

public fun current(supply: &supply::Supply): u64

Current supply

public fun supply(supply: &supply::Supply): u64

Return remaining supply

public fun increase_maximum(
    supply: &mut supply::Supply,
    value: u64,
)

Increases maximum supply

Panics

Panics if supply is frozen.

public fun decrease_maximum(
    supply: &mut supply::Supply,
    value: u64,
)

Decreases maximum supply

Panics

Panics if supply is frozen or if new maximum supply is smaller than current supply.

public fun increment(supply: &mut supply::Supply, value: u64)

Increments current supply

Panics

Panics if new maximum supply exceeds maximum.

public fun decrement(supply: &mut supply::Supply, value: u64)

Decrements current supply

public fun freeze_supply(supply: &mut supply::Supply)

Freeze Supply

Panics

Panics if already frozen

public fun extend(supply: &mut supply::Supply, value: u64): 
    supply::Supply

Creates a new Supply which is extended from the current Supply

The extend value is used as the maximum supply for the new Supply, while the current supply of the existing supply is incremented by the value.

The existing Supply must be frozen, thus the extended Supply will also be frozen.

Panics

Panics if not frozen or if value will cause maximum supply to be exceeded.

public fun merge(
    supply: &mut supply::Supply,
    other: supply::Supply,
)

Merge two Supply to one

Ideally, the merged Supply will have been extended from the original Supply, as otherwise it may not be possible to merge the two supplies.

Any excess supply on the merged Supply will be decremented from the original supply.

Panics

Panics if total supply will cause maximum or zero supply to be exceeded.

public fun assert_zero(supply: &supply::Supply)

Asserts that current supply is zero

public fun assert_frozen(supply: &supply::Supply)

Asserts that supply is frozen

public fun assert_not_frozen(supply: &supply::Supply)

Asserts that supply is not frozen