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: AddressTreasury address
Implementations§
Source§impl NetworkTreasury
impl NetworkTreasury
Sourcepub fn with_storage(
treasury_address: Address,
storage: Arc<TreasuryStorageBackend>,
) -> Self
pub fn with_storage( treasury_address: Address, storage: Arc<TreasuryStorageBackend>, ) -> Self
Creates a new network treasury with persistent storage
Sourcepub fn bridge_sponsorship_pools_snapshot(
&self,
) -> HashMap<String, BridgeSponsorshipPoolRecord>
pub fn bridge_sponsorship_pools_snapshot( &self, ) -> HashMap<String, BridgeSponsorshipPoolRecord>
Get a snapshot of all per-bridge sponsorship pools. Read-only.
Sourcepub fn get_or_create_bridge_sponsorship_pool(
&self,
adapter: &str,
) -> BridgeSponsorshipPoolRecord
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.
Sourcepub fn sponsor_bridge_fee(
&self,
adapter: &str,
tnzo_paid_wei: u128,
native_committed_smallest_unit: u128,
)
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.
Sourcepub fn drain_bridge_sponsorship_outstanding(
&self,
adapter: &str,
native_amount: u128,
)
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.
Sourcepub fn set_bridge_sponsorship_refill_threshold(&self, adapter: &str, bps: u32)
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.
Sourcepub fn set_withdrawal_threshold(&self, threshold: usize) -> Result<()>
pub fn set_withdrawal_threshold(&self, threshold: usize) -> Result<()>
Sets the multisig withdrawal threshold
Requires that threshold <= number of authorized withdrawers
Sourcepub fn approve_withdrawal(
&self,
withdrawal_id: &str,
approver: &Address,
) -> Result<bool>
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.
Sourcepub fn clear_approval(&self, withdrawal_id: &str)
pub fn clear_approval(&self, withdrawal_id: &str)
Clears pending approvals for a withdrawal (after execution or cancellation)
Sourcepub fn deposit_fee(&self, asset_id: &AssetId, amount: u128) -> Result<()>
pub fn deposit_fee(&self, asset_id: &AssetId, amount: u128) -> Result<()>
Deposits a fee into the treasury
§Arguments
asset_id- Asset being depositedamount- Amount to deposit
Sourcepub fn withdraw(
&self,
asset_id: &AssetId,
amount: u128,
caller: &Address,
) -> Result<()>
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 withdrawamount- Amount to withdrawcaller- Address requesting withdrawal (must be authorized)withdrawal_id- Unique identifier for multisig tracking (optional for threshold=1)
Sourcepub fn execute_withdrawal(
&self,
withdrawal_id: &str,
asset_id: &AssetId,
amount: u128,
) -> Result<()>
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.
Sourcepub fn total_value(&self) -> u128
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.
Sourcepub fn backing_ratio(&self, tnzo_supply: u128) -> f64
pub fn backing_ratio(&self, tnzo_supply: u128) -> f64
Calculates the backing ratio (treasury_value / tnzo_supply)
§Arguments
tnzo_supply- Current TNZO supply
Sourcepub fn process_network_fee(
&self,
asset_id: &AssetId,
total_fee: u128,
) -> Result<FeeDistribution>
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 feetotal_fee- Total fee amount
Returns the calculated distribution
Sourcepub fn update_distribution_config(
&self,
config: FeeDistributionConfig,
) -> Result<()>
pub fn update_distribution_config( &self, config: FeeDistributionConfig, ) -> Result<()>
Updates the fee distribution configuration
Adds an authorized withdrawer
Removes an authorized withdrawer
Sourcepub fn audit_supply(&self, asset_id: &AssetId) -> Result<()>
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.
Sourcepub fn audit_all_supplies(&self) -> Vec<(AssetId, String)>
pub fn audit_all_supplies(&self) -> Vec<(AssetId, String)>
Audits all assets in the treasury
Returns the list of assets that failed the audit.
Sourcepub fn stats(&self) -> TreasuryStats
pub fn stats(&self) -> TreasuryStats
Returns treasury statistics