# BASIC FUNGIBLE FAUCET CONTRACT
# =================================================================================================
# This is a basic fungible faucet smart contract.
#
# It allows the owner of the faucet to mint, distribute, and burn tokens. Token metadata is stored
# in account storage at position 1 as [max_supply, decimals, token_symbol, 0], where:
# - max_supply is the maximum supply of the token.
# - decimals are the decimals of the token.
# - token_symbol as three chars encoded in a Felt.

use miden::standards::faucets

# CONSTANTS
# =================================================================================================

const PRIVATE_NOTE=2

# ERRORS
# =================================================================================================
const ERR_FUNGIBLE_ASSET_DISTRIBUTE_WOULD_CAUSE_MAX_SUPPLY_TO_BE_EXCEEDED="distribute would cause the maximum supply to be exceeded"

const ERR_BASIC_FUNGIBLE_BURN_WRONG_NUMBER_OF_ASSETS="burn requires exactly 1 note asset"

# CONSTANTS
# =================================================================================================

#! Distributes freshly minted fungible assets to the provided recipient by creating a note.
#!
#! Inputs:  [amount, tag, aux, note_type, execution_hint, RECIPIENT, pad(7)]
#! Outputs: [note_idx, pad(15)]
#!
#! Where:
#! - amount is the amount to be minted and sent.
#! - tag is the tag to be included in the note.
#! - aux is the auxiliary data to be included in the note.
#! - note_type is the type of the note that holds the asset.
#! - execution_hint is the execution hint of the note that holds the asset.
#! - RECIPIENT is the recipient of the asset, i.e.,
#!   hash(hash(hash(serial_num, [0; 4]), script_root), input_commitment).
#! - note_idx is the index of the created note.
#!
#! Panics if:
#! - the transaction is being executed against an account that is not a fungible asset faucet.
#! - the total issuance after minting is greater than the maximum allowed supply.
#!
#! Invocation: call
pub proc distribute
    exec.faucets::distribute
    # => [note_idx, pad(15)]
end

#! Burns the fungible asset from the active note.
#!
#! This procedure retrieves the asset from the active note and burns it. The note must contain
#! exactly one asset, which must be a fungible asset issued by this faucet.
#!
#! This is a re-export of basic_fungible::burn.
#!
#! Inputs:  [pad(16)]
#! Outputs: [pad(16)]
#!
#! Panics if:
#! - the procedure is not called from a note context (active_note::get_assets will fail).
#! - the note does not contain exactly one asset.
#! - the transaction is executed against an account which is not a fungible asset faucet.
#! - the transaction is executed against a faucet which is not the origin of the specified asset.
#! - the amount about to be burned is greater than the outstanding supply of the asset.
pub use faucets::burn
