Skip to main content

NetworkTreasury

Struct NetworkTreasury 

Source
pub struct NetworkTreasury {
    pub treasury_address: Address,
    /* private fields */
}
Expand description

Network treasury

Manages multi-asset treasury accumulating network fees and supporting treasury-based operations.

Fields§

§treasury_address: Address

Treasury address

Implementations§

Source§

impl NetworkTreasury

Source

pub fn new(treasury_address: Address) -> Self

Creates a new network treasury (in-memory only)

Source

pub fn with_storage( treasury_address: Address, storage: Arc<TreasuryStorageBackend>, ) -> Self

Creates a new network treasury with persistent storage

Source

pub fn bridge_sponsorship_pools_snapshot( &self, ) -> HashMap<String, BridgeSponsorshipPoolRecord>

Get a snapshot of all per-bridge sponsorship pools. Read-only.

Source

pub fn get_or_create_bridge_sponsorship_pool( &self, adapter: &str, ) -> BridgeSponsorshipPoolRecord

Get the per-adapter sponsorship pool record, creating it lazily from the canonical vault-address derivation.

Source

pub fn sponsor_bridge_fee( &self, adapter: &str, tnzo_paid_wei: u128, native_committed_smallest_unit: u128, )

Credit a user TNZO sponsorship + record the outstanding destination-native commitment. Called by the bridge-fee sponsor RPC on a successful debit.

Source

pub fn drain_bridge_sponsorship_outstanding( &self, adapter: &str, native_amount: u128, )

Drain the outstanding-native commitment after the relayer submits delivery proof. Does NOT touch the TNZO balance — that is paid out to the relayer via a separate explicit drain step to keep the audit trail clean.

Source

pub fn set_bridge_sponsorship_refill_threshold(&self, adapter: &str, bps: u32)

Set the per-adapter refill threshold (bps). Governance-tunable via the GovernanceEngine; off-chain rebalancer triggers a treasury top-up when the relayer’s destination-native balance drops below outstanding * refill_threshold_bps / 10000.

Source

pub fn set_withdrawal_threshold(&self, threshold: usize) -> Result<()>

Sets the multisig withdrawal threshold

Requires that threshold <= number of authorized withdrawers

Source

pub fn approve_withdrawal( &self, withdrawal_id: &str, approver: &Address, ) -> Result<bool>

Approves a pending withdrawal (multisig step)

Returns true if the withdrawal has reached threshold and should be executed.

Source

pub fn clear_approval(&self, withdrawal_id: &str)

Clears pending approvals for a withdrawal (after execution or cancellation)

Source

pub fn deposit_fee(&self, asset_id: &AssetId, amount: u128) -> Result<()>

Deposits a fee into the treasury

§Arguments
  • asset_id - Asset being deposited
  • amount - Amount to deposit
Source

pub fn withdraw( &self, asset_id: &AssetId, amount: u128, caller: &Address, ) -> Result<()>

Withdraws from treasury (requires authorization)

When withdrawal_threshold > 1, the caller must first gather approvals via approve_withdrawal() before calling this method.

§Arguments
  • asset_id - Asset to withdraw
  • amount - Amount to withdraw
  • caller - Address requesting withdrawal (must be authorized)
  • withdrawal_id - Unique identifier for multisig tracking (optional for threshold=1)
Source

pub fn execute_withdrawal( &self, withdrawal_id: &str, asset_id: &AssetId, amount: u128, ) -> Result<()>

Executes a withdrawal after multisig approval has been reached.

Verifies that the withdrawal_id has sufficient approvals, then executes.

Source

pub fn balance(&self, asset_id: &AssetId) -> u128

Returns the balance for a specific asset

Source

pub fn total_value(&self) -> u128

Returns the total value across all assets (in TNZO equivalent)

Note: This is a simplified version. In production, you’d use an oracle or price feed to convert different assets to TNZO equivalent.

Source

pub fn backing_ratio(&self, tnzo_supply: u128) -> f64

Calculates the backing ratio (treasury_value / tnzo_supply)

§Arguments
  • tnzo_supply - Current TNZO supply
Source

pub fn process_network_fee( &self, asset_id: &AssetId, total_fee: u128, ) -> Result<FeeDistribution>

Processes a network fee according to the distribution config

§Arguments
  • asset_id - Asset of the fee
  • total_fee - Total fee amount

Returns the calculated distribution

Source

pub fn update_distribution_config( &self, config: FeeDistributionConfig, ) -> Result<()>

Updates the fee distribution configuration

Source

pub fn add_authorized_withdrawer(&self, address: Address)

Adds an authorized withdrawer

Source

pub fn remove_authorized_withdrawer(&self, address: &Address)

Removes an authorized withdrawer

Source

pub fn audit_supply(&self, asset_id: &AssetId) -> Result<()>

Audits the treasury’s supply invariant

Verifies that: total_collected = current_balance + total_distributed

§Arguments
  • asset_id - Asset to audit

Returns Ok(()) if the invariant holds, or an error with details if it doesn’t.

Source

pub fn audit_all_supplies(&self) -> Vec<(AssetId, String)>

Audits all assets in the treasury

Returns the list of assets that failed the audit.

Source

pub fn stats(&self) -> TreasuryStats

Returns treasury statistics

Trait Implementations§

Source§

impl Debug for NetworkTreasury

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more