Treasury

Git Source

Inherits: ERC20, ITreasury

Implementation of a single-asset treasury that manages deposits and withdrawals

This contract extends ERC20 to implement a treasury system for a single underlying asset

State Variables

_asset

The single underlying asset token managed by this treasury

IERC20 private immutable _asset;

_valocracy

The Valocracy contract address that controls deposits

address private _valocracy;

Functions

constructor

Initializes the contract by setting a name and a symbol for the treasury shares. Also sets the Valocracy contract and the single underlying asset token.

constructor(IERC20 asset_, address valocracy, string memory name, string memory symbol) ERC20(name, symbol);

Parameters

NameTypeDescription
asset_IERC20The single underlying asset token to be managed
valocracyaddressThe address of the Valocracy contract that controls deposits
namestringThe name of the treasury shares
symbolstringThe symbol of the treasury shares

asset

Returns the address of the single underlying asset token.

function asset() public view virtual returns (address);

Returns

NameTypeDescription
<none>addressThe address of the asset token

totalAssets

Returns the total amount of the single asset held by the treasury.

function totalAssets() public view virtual returns (uint256);

Returns

NameTypeDescription
<none>uint256The total balance of the underlying asset

previewWithdraw

Calculates the amount of the underlying asset that would be returned for burning the given amount of shares. The calculation is based on the proportion of total assets to total shares. For example, if there are 2000 assets and 1000 shares, each share represents 2 assets.

function previewWithdraw(uint256 shares) public view virtual returns (uint256);

Parameters

NameTypeDescription
sharesuint256The amount of shares to calculate assets for

Returns

NameTypeDescription
<none>uint256The amount of the underlying asset that would be returned

deposit

Deposits the underlying asset into the treasury and mints shares to the receiver. Only callable by the Valocracy contract.

function deposit(address receiver, uint256 shares) public;

Parameters

NameTypeDescription
receiveraddressThe address that will receive the shares
sharesuint256The amount of shares to mint

withdraw

Withdraws the underlying asset from the treasury by burning shares. Transfers the corresponding amount of the underlying asset to the receiver.

function withdraw(address receiver, uint256 shares) public;

Parameters

NameTypeDescription
receiveraddressThe address that will receive the underlying asset
sharesuint256The amount of shares to burn