miden-protocol 0.14.5

Core components of the Miden protocol
Documentation
use miden::protocol::asset
use miden::protocol::active_account
use miden::protocol::kernel_proc_offsets::FAUCET_MINT_ASSET_OFFSET
use miden::protocol::kernel_proc_offsets::FAUCET_BURN_ASSET_OFFSET
use miden::protocol::kernel_proc_offsets::FAUCET_HAS_CALLBACKS_OFFSET

#! Creates a fungible asset for the faucet the transaction is being executed against.
#!
#! Inputs:  [amount]
#! Outputs: [ASSET_KEY, ASSET_VALUE]
#!
#! Where:
#! - amount is the amount of the asset to create.
#! - ASSET_KEY is the vault key of the created fungible asset.
#! - ASSET_VALUE is the value of the created fungible asset.
#!
#! Panics if:
#! - the active account is not a fungible faucet.
#!
#! Invocation: exec
pub proc create_fungible_asset
    # fetch the id of the faucet the transaction is being executed against.
    exec.active_account::get_id
    # => [id_suffix, id_prefix, amount]

    # check whether the faucet has callbacks defined
    exec.has_callbacks
    # => [has_callbacks, id_suffix, id_prefix, amount]

    # create the fungible asset
    exec.asset::create_fungible_asset
    # => [ASSET_KEY, ASSET_VALUE]
end

#! Creates a non-fungible asset for the faucet the transaction is being executed against.
#!
#! Inputs:  [DATA_HASH]
#! Outputs: [ASSET_KEY, ASSET_VALUE]
#!
#! Where:
#! - DATA_HASH is the data hash of the non-fungible asset to create.
#! - ASSET_KEY is the vault key of the created non-fungible asset.
#! - ASSET_VALUE is the value of the created non-fungible asset.
#!
#! Panics if:
#! - the active account is not a non-fungible faucet.
#!
#! Invocation: exec
pub proc create_non_fungible_asset
    # fetch the id of the faucet the transaction is being executed against
    exec.active_account::get_id
    # => [id_suffix, id_prefix, DATA_HASH]

    # check whether the faucet has callbacks defined
    exec.has_callbacks
    # => [has_callbacks, id_suffix, id_prefix, DATA_HASH]

    # build the non-fungible asset
    exec.asset::create_non_fungible_asset
    # => [ASSET_KEY, ASSET_VALUE]
end

#! Mint an asset from the faucet the transaction is being executed against.
#!
#! Inputs:  [ASSET_KEY, ASSET_VALUE]
#! Outputs: [NEW_ASSET_VALUE]
#!
#! Where:
#! - ASSET_KEY is the vault key of the asset to mint.
#! - ASSET_VALUE is the value of the asset that was minted.
#! - NEW_ASSET_VALUE is:
#!   - For fungible assets: the ASSET_VALUE merged with the existing vault asset value, if any.
#!   - For non-fungible assets: identical to ASSET_VALUE.
#!
#! Panics if:
#! - the transaction is not being executed against a faucet.
#! - the asset being minted is not associated with the faucet the transaction is being executed
#!   against.
#! - the asset is not well formed.
#! - for fungible faucets if the total issuance after minting is greater than the maximum amount
#!   allowed.
#! - for non-fungible faucets if the non-fungible asset being minted already exists.
#!
#! Invocation: exec
pub proc mint
    # pad the stack
    padw padw swapdw movup.8 drop
    # => [ASSET_KEY, ASSET_VALUE, pad(7)]

    push.FAUCET_MINT_ASSET_OFFSET
    # => [offset, ASSET_KEY, ASSET_VALUE, pad(7)]

    syscall.exec_kernel_proc
    # => [ASSET_VALUE, pad(12)]

    # clean the stack
    swapdw dropw dropw swapw dropw
    # => [ASSET_VALUE]
end

#! Burn an asset from the faucet the transaction is being executed against.
#!
#! Inputs:  [ASSET_KEY, ASSET_VALUE]
#! Outputs: []
#!
#! Where:
#! - ASSET_KEY is the vault key of the asset to burn.
#! - ASSET_VALUE is the value of the asset to burn.
#!
#! Panics if:
#! - the transaction is not being executed against a faucet.
#! - the asset being burned is not associated with the faucet the transaction is being executed
#!   against.
#! - the asset is not well formed.
#! - for fungible faucets if the amount being burned is greater than the total input to the
#!   transaction.
#! - for non-fungible faucets if the non-fungible asset being burned does not exist or was not
#!   provided as input to the transaction via a note or the accounts vault.
#!
#! Invocation: exec
pub proc burn
    # pad the stack
    padw padw swapdw movup.8 drop
    # => [ASSET_KEY, ASSET_VALUE, pad(7)]

    push.FAUCET_BURN_ASSET_OFFSET
    # => [offset, ASSET_KEY, ASSET_VALUE, pad(7)]

    syscall.exec_kernel_proc
    # => [pad(16)]

    # clean the stack
    dropw dropw dropw dropw
    # => []
end

#! Returns whether the active account defines callbacks.
#!
#! The account defines callbacks if any callback storage slot is present and it contains not the
#! empty word.
#!
#! Inputs:  []
#! Outputs: [has_callbacks]
#!
#! Where:
#! - has_callbacks is 1 if the account defines callbacks, 0 otherwise.
#!
#! Invocation: exec
pub proc has_callbacks
    # pad the stack
    padw padw padw push.0.0.0
    # => [pad(15)]

    push.FAUCET_HAS_CALLBACKS_OFFSET
    # => [offset, pad(15)]

    syscall.exec_kernel_proc
    # => [has_callbacks, pad(15)]

    # clean the stack
    swapdw dropw dropw swapw dropw movdn.3 drop drop drop
    # => [has_callbacks]
end