Treasury
Extension that manages DAO assets including STX, SIP-010 FTs, and SIP-009 NFTs
Last updated
Extension that manages DAO assets including STX, SIP-010 FTs, and SIP-009 NFTs
Last updated
The Treasury extension (aibtc-treasury
) manages all assets owned by the DAO, including STX, SIP-010 fungible tokens, and SIP-009 non-fungible tokens. It provides controlled access to these assets through DAO governance, ensuring that all financial operations are executed securely and transparently. This extension serves as the financial backbone of the DAO, enabling it to receive, hold, and distribute various digital assets.
Multi-Asset Support: Manages STX, fungible tokens (FTs), and non-fungible tokens (NFTs)
Asset Allowlist: Controls which assets can be deposited and withdrawn
Secure Withdrawals: Ensures only the DAO or authorized extensions can withdraw assets
STX Stacking: Enables the DAO to participate in Stacks consensus through delegation
Transparent Operations: Emits detailed events for all financial transactions
Contract Name
aibtc-treasury
Version
1.0.0
Implements
extension
, treasury
traits
Key Parameters
Allowlist of approved asset contracts
The Treasury extension acts as the financial hub for the DAO. Users can deposit assets directly into the treasury. However, withdrawals and asset management operations can only be performed through DAO governance. The extension maintains an allowlist of approved assets to ensure only recognized tokens can be deposited or withdrawn. For STX, the extension also provides functionality to participate in Stacks consensus through delegation.
callback
Purpose: Standard extension callback function required by the extension trait
Parameters:
sender
: principal - The principal that triggered the callback
memo
: (buff 34) - Optional memo data
Returns: (response bool) - Returns true on success
Example:
allow-asset
Purpose: Adds or updates an asset in the allowed list
Parameters:
token
: principal - The principal of the asset contract
enabled
: bool - Whether the asset is allowed (true) or disallowed (false)
Returns: (response bool) - Returns true on success or an error
Example:
This function can only be called by the DAO or an authorized extension. It controls which assets can be deposited into and withdrawn from the treasury.
allow-assets
Purpose: Adds or updates multiple assets in the allowed list at once
Parameters:
allowList
: (list 100 {token: principal, enabled: bool}) - List of assets to allow/disallow
Returns: (response bool) - Returns true on success or an error
Example:
This function provides a convenient way to manage multiple assets in a single transaction.
deposit-stx
Purpose: Deposits STX into the treasury
Parameters:
amount
: uint - The amount of STX to deposit
Returns: (response bool) - Returns true on success or an error
Example:
Anyone can deposit STX into the treasury. The function transfers STX from the caller to the treasury contract.
deposit-ft
Purpose: Deposits fungible tokens into the treasury
Parameters:
ft
: ft-trait - The fungible token contract
amount
: uint - The amount of tokens to deposit
Returns: (response bool) - Returns true on success or an error
Example:
This function allows depositing SIP-010 fungible tokens into the treasury. The token must be in the allowed list.
deposit-nft
Purpose: Deposits a non-fungible token into the treasury
Parameters:
nft
: nft-trait - The non-fungible token contract
id
: uint - The ID of the NFT to deposit
Returns: (response bool) - Returns true on success or an error
Example:
This function allows depositing SIP-009 non-fungible tokens into the treasury. The NFT contract must be in the allowed list.
withdraw-stx
Purpose: Withdraws STX from the treasury
Parameters:
amount
: uint - The amount of STX to withdraw
recipient
: principal - The recipient of the STX
Returns: (response bool) - Returns true on success or an error
Example:
This function can only be called by the DAO or an authorized extension. It transfers STX from the treasury to the specified recipient.
withdraw-ft
Purpose: Withdraws fungible tokens from the treasury
Parameters:
ft
: ft-trait - The fungible token contract
amount
: uint - The amount of tokens to withdraw
recipient
: principal - The recipient of the tokens
Returns: (response bool) - Returns true on success or an error
Example:
This function can only be called by the DAO or an authorized extension. It transfers fungible tokens from the treasury to the specified recipient.
withdraw-nft
Purpose: Withdraws a non-fungible token from the treasury
Parameters:
nft
: nft-trait - The non-fungible token contract
id
: uint - The ID of the NFT to withdraw
recipient
: principal - The recipient of the NFT
Returns: (response bool) - Returns true on success or an error
Example:
This function can only be called by the DAO or an authorized extension. It transfers an NFT from the treasury to the specified recipient.
delegate-stx
Purpose: Delegates STX for stacking
Parameters:
maxAmount
: uint - The maximum amount of STX to delegate
to
: principal - The principal to delegate to
Returns: (response bool) - Returns true on success or an error
Example:
This function can only be called by the DAO or an authorized extension. It delegates STX from the treasury for stacking, allowing the DAO to participate in Stacks consensus.
revoke-delegate-stx
Purpose: Revokes STX delegation
Parameters: None
Returns: (response bool) - Returns true on success or an error
Example:
This function can only be called by the DAO or an authorized extension. It revokes the STX delegation, which will unlock the STX after the current cycle ends.
is-allowed-asset
Purpose: Checks if an asset is allowed
Parameters:
assetContract
: principal - The principal of the asset contract
Returns: bool - Returns true if the asset is allowed, false otherwise
Example:
get-allowed-asset
Purpose: Gets the allowed status of an asset
Parameters:
assetContract
: principal - The principal of the asset contract
Returns: (optional bool) - Returns the allowed status if the asset is in the list, none otherwise
Example:
is-dao-or-extension
Purpose: Internal authorization check to ensure only the DAO or authorized extensions can call sensitive functions
Parameters: None
Returns: (response bool) - Returns ok true if authorized, or err u6000 if unauthorized
allow-assets-iter
Purpose: Helper function for processing each item in the allow-assets list
Parameters:
item
: {token: principal, enabled: bool} - The asset item to process
Returns: None
allow-asset
Asset allowed/disallowed
Token principal, enabled status
deposit-stx
STX deposited
Amount, sender, recipient
deposit-ft
Fungible token deposited
Amount, asset contract, sender, recipient
deposit-nft
Non-fungible token deposited
Asset contract, token ID, sender, recipient
withdraw-stx
STX withdrawn
Amount, recipient, sender
withdraw-ft
Fungible token withdrawn
Asset contract, recipient, sender
withdraw-nft
Non-fungible token withdrawn
Asset contract, token ID, recipient, sender
delegate-stx
STX delegated for stacking
Amount, delegate address, sender
revoke-delegate-stx
STX delegation revoked
Sender
u6000
ERR_UNAUTHORIZED
Caller is not the DAO or a valid extension
Ensure the function is called through proper DAO governance
u6001
ERR_UNKNOWN_ASSSET
Asset is not in the allowed list
Add the asset to the allowed list before attempting to deposit or withdraw
Authorization Control: All withdrawal and management functions are protected by the is-dao-or-extension
check, ensuring only authorized entities can access treasury funds
Asset Allowlist: The treasury maintains an explicit allowlist of approved assets, preventing unauthorized tokens from being deposited or withdrawn
Contract-Call Pattern: Uses the as-contract
pattern for withdrawals to ensure proper permissions
Governance Protection: Changes to treasury settings and withdrawals require going through the DAO's proposal and voting process
Explicit Asset Verification: All deposit and withdrawal functions verify that the asset is in the allowed list
STX Stacking Security: Stacking operations are protected by governance controls to prevent unauthorized delegation
Last Updated: April 2025
Contract Version: 1.0.0
Documentation Version: 1.1.0
Changes from Previous Version: Updated to match new documentation template format
: The core DAO contract that authorizes this extension
: Defines the traits implemented by this extension
: Works with the treasury for automated payments
: Manages the DAO token that may be held in the treasury