Contract 6beba0da35a8458b5d0b819f5db98d3aed2a1489e2ec9ea0441c3ed565ca665f

← Back to Index 📥 Download WASM

Meta

rssdkver 22.0.8#f46e9e0610213bbb72285566f9dd960ff96d03d8
rsver 1.90.0

Instances

  • CAFKOBNXGWOKQZ4EJFPBMNXX4ONQCUMLDPXCSTPOX4SV5DVHZBMKNI54
  • CD224YAPQ4RQXHIAZ6OOMHRQYM6WQJTRQ2MRGUFYAFXMIAHRLSMRAGUM

Interface

Initialize the treasury contract with an admin address.

The admin address is a single account. Once initialized, the contract cannot be reinitialized. This ensures the admin address remains consistent and prevents accidental reconfiguration.

Arguments

  • env - The execution environment
  • admin - Address of the admin (can be multisig contract for enhanced security)

Returns

  • Ok(()) - Treasury initialized successfully
  • Err(TreasuryError) - Initialization failed (e.g., already initialized)
fn initialize(
    env: soroban_sdk::Env,
    admin: soroban_sdk::Address,
) -> Result<(), TreasuryError>

Record a deposit of tokens to the treasury.

This function updates internal balance tracking after tokens have been transferred to the treasury contract address. The actual token transfer must occur via the token contract's transfer function before calling this method. This separation allows the treasury to track protocol fees collected from various sources.

Arguments

  • env - The execution environment
  • asset - Address of the token contract
  • amount - Amount of tokens being deposited (must be > 0)
  • from - Address that sent the tokens (for event tracking and audit trail)

Returns

  • Ok(()) - Deposit recorded successfully
  • Err(TreasuryError) - Deposit failed (not initialized, invalid amount, or overflow)
fn deposit(
    env: soroban_sdk::Env,
    asset: soroban_sdk::Address,
    amount: u128,
    from: soroban_sdk::Address,
) -> Result<(), TreasuryError>

Sync balance from token contract and update internal tracking.

This function queries the token contract's balance function to reconcile the actual balance held by the treasury with internal tracking. Use this when tokens are transferred directly to the treasury address without calling deposit(), such as when protocol fees are collected automatically.

Arguments

  • env - The execution environment
  • asset - Address of the token contract

Returns

  • Ok(u128) - Current balance synced from token contract
  • Err(TreasuryError) - Sync failed (not initialized or token contract query failed)
fn sync_balance(
    env: soroban_sdk::Env,
    asset: soroban_sdk::Address,
) -> Result

Withdraw tokens from the treasury (admin only).

This function performs two critical operations atomically: it updates internal balance tracking and transfers tokens to the recipient. If the token transfer fails, the balance update is reverted, ensuring consistency. Only authorized admins (or multisig contract if configured) can perform withdrawals.

Arguments

  • env - The execution environment
  • caller - Admin address (must be authorized - regular admin or multisig contract)
  • asset - Address of the token contract to withdraw
  • amount - Amount of tokens to withdraw (must be > 0 and <= available balance)
  • to - Address to receive the tokens

Returns

  • Ok(()) - Withdrawal successful (balance updated and tokens transferred)
  • Err(TreasuryError) - Withdrawal failed (unauthorized, insufficient balance, or transfer failed)
fn withdraw(
    env: soroban_sdk::Env,
    caller: soroban_sdk::Address,
    asset: soroban_sdk::Address,
    amount: u128,
    to: soroban_sdk::Address,
) -> Result<(), TreasuryError>

Get the balance of a specific asset in the treasury.

Returns the internally tracked balance for the given asset. This may differ from the actual token contract balance if sync_balance() hasn't been called after direct transfers to the treasury address.

Arguments

  • env - The execution environment
  • asset - Address of the token contract

Returns

  • u128 - Balance of the asset (0 if asset has never been deposited)
fn get_balance(env: soroban_sdk::Env, asset: soroban_sdk::Address) -> u128

Get all balances in the treasury.

Returns a map of all assets that have been deposited to the treasury along with their tracked balances. Assets with zero balance are not included in the map.

Arguments

  • env - The execution environment

Returns

  • Map<Address, u128> - Map of asset addresses to their balances
fn get_all_balances(
    env: soroban_sdk::Env,
) -> soroban_sdk::Map

Get the admin address.

Arguments

  • env - The execution environment

Returns

  • Address - Admin address
fn get_admin(env: soroban_sdk::Env) -> soroban_sdk::Address

Imports

WebAssembly Text (WAT) ▶