use miden::protocol::active_note
use miden::standards::faucets
use miden::standards::access::ownable

# PUBLIC INTERFACE
# ================================================================================================

# OWNER MANAGEMENT
# ------------------------------------------------------------------------------------------------

#! Returns the owner AccountId.
#!
#! Inputs:  []
#! Outputs: [owner_prefix, owner_suffix, pad(14)]
#!
#! Invocation: call
pub use ownable::get_owner

#! Transfers ownership to a new account.
#!
#! Can only be called by the current owner.
#!
#! Inputs:  [new_owner_prefix, new_owner_suffix, pad(14)]
#! Outputs: [pad(16)]
#!
#! Where:
#! - new_owner_{prefix, suffix} are the prefix and suffix felts of the new owner AccountId.
#!
#! Panics if:
#! - the note sender is not the owner.
#!
#! Invocation: call
pub use ownable::transfer_ownership

#! Renounces ownership, leaving the component without an owner.
#!
#! Can only be called by the current owner.
#!
#! Inputs:  [pad(16)]
#! Outputs: [pad(16)]
#!
#! Panics if:
#! - the note sender is not the owner.
#!
#! Invocation: call
pub use ownable::renounce_ownership

# ASSET DISTRIBUTION
# ------------------------------------------------------------------------------------------------

#! Distributes freshly minted fungible assets to the provided recipient.
#!
#! This procedure first checks if the note sender is the owner of the faucet, and then
#! mints the asset and creates an output note with that asset for the recipient.
#!
#! Inputs:  [amount, tag, note_type, RECIPIENT, pad(9)]
#! 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.
#! - note_type is the type of the note that holds the asset.
#! - RECIPIENT is the recipient of the asset.
#! - note_idx is the index of the created note.
#!
#! Panics if:
#! - the note sender is not the owner of this faucet.
#! - any of the validations in faucets::distribute fail.
#!
#! Invocation: call
pub proc distribute
    exec.ownable::verify_owner
    # => [amount, tag, aux, note_type, execution_hint, RECIPIENT, pad(7)]

    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.
#!
#! 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.
#!
#! Invocation: call
pub use faucets::burn
