Vaults

Purpose: Individual asset vaults issuing ztokens (vault shares). Manages lending, interest accrual, flashloans. All 6 vaults share the same interface.

Vault Contracts

  • vault-stx: STX vault, issues zSTX (6 decimals)

  • vault-sbtc: sBTC vault, issues zsBTC (8 decimals)

  • vault-ststx: stSTX vault, issues zstSTX (6 decimals)

  • vault-usdc: USDC vault, issues zUSDC (6 decimals)

  • vault-usdh: USDH vault, issues zUSDH (6 decimals)

  • vault-ststxbtc: stSTXbtc vault, issues zstSTXbtc (6 decimals)

Note: All vaults are 6 decimals except vault-sbtc (8 decimals, matching Bitcoin).


List of Core Functions

SIP-10 Token Standard:

  • get-name β€” Vault token name

  • get-symbol β€” Vault token symbol

  • get-token-uri β€” Token metadata URI

  • get-decimals β€” Token decimals

  • get-total-supply β€” Total zToken shares

  • get-balance β€” User's zToken balance

  • transfer β€” Transfer zTokens

Configuration:

  • initialize β€” Initialize vault (one-time, deployer only)

  • set-authorized-contract β€” Authorize contract for special permissions

  • set-flashloan-permissions β€” Set flashloan permissions for account

  • set-flashloan-permissions-many β€” Batch set flashloan permissions

  • set-cap-debt β€” Update borrow cap

  • set-cap-supply β€” Update supply cap

  • set-fee-flash β€” Update flashloan fee

  • set-fee-reserve β€” Update reserve fee

  • set-default-flashloan-permissions β€” Set default flashloan permissions

  • set-points-util β€” Update utilization breakpoints

  • set-points-rate β€” Update interest rates

  • set-token-uri β€” Update token URI

  • set-pause-states β€” Pause/unpause operations

Queries:

  • is-authorized-contract β€” Check if contract is authorized

  • get-cap-debt β€” Get borrow cap

  • get-cap-supply β€” Get supply cap

  • get-fee-flash β€” Get flashloan fee (BPS)

  • get-fee-reserve β€” Get reserve fee (BPS)

  • get-default-flashloan-permissions β€” Get default flashloan permissions

  • get-flashloan-permissions β€” Get account-specific flashloan permissions

  • get-points-util β€” Get utilization breakpoints

  • get-points-rate β€” Get interest rates

  • get-pause-states β€” Get pause configuration

  • get-available-assets β€” Get available liquidity for borrowing

Vault Operations:

  • get-assets β€” Total underlying assets in vault

  • get-total-assets β€” Preview total assets (includes accrued interest)

  • convert-to-shares β€” Convert underlying to zToken shares

  • convert-to-assets β€” Convert zToken shares to underlying

  • deposit β€” Supply underlying, receive zTokens

  • redeem β€” Burn zTokens, receive underlying

Lending Operations:

  • get-principal-scaled β€” Scaled debt (principal)

  • get-index β€” Borrow index (compound interest accrual)

  • get-last-update β€” Last accrual timestamp

  • get-debt β€” Total borrowed

  • get-utilization β€” Utilization ratio (borrowed / assets)

  • get-interest-rate β€” Current borrow APR (BPS)

  • get-next-index β€” Next borrow index after accrual

  • get-principal-ratio-reduction β€” Ratio reduction calculation

  • get-liquidity-index β€” Liquidity index (for zToken pricing)

  • get-underlying β€” Underlying token contract

  • accrue β€” Accrue interest and update indexes

  • system-borrow β€” Borrow (market auth only)

  • system-repay β€” Repay (market auth only)

  • socialize-debt β€” Distribute bad debt to suppliers (market auth only)

Flashloan:

  • flashloan β€” Execute flashloan with callback


Function Parameters

SIP-10 Functions

get-name

Get vault token name (e.g., "Zest STX").

Parameters: none

Returns: (response (string-ascii 32) uint) β€” Token name


get-symbol

Get vault token symbol (e.g., "zSTX").

Parameters: none

Returns: (response (string-ascii 32) uint) β€” Token symbol


get-token-uri

Get token metadata URI.

Parameters: none

Returns: (response (optional (string-utf8 256)) uint) β€” Token URI or none


get-decimals

Get token decimals (6 for most vaults, 8 for sBTC).

Parameters: none

Returns: (response uint uint) β€” Decimals


get-total-supply

Get total zToken shares outstanding.

Parameters: none

Returns: (response uint uint) β€” Total supply


get-balance

Get user's zToken balance.

Parameters:

  • account β€” principal β€” User address

Returns: (response uint uint) β€” Balance


transfer

Transfer zTokens between accounts.

Parameters:

  • amount β€” uint β€” Amount to transfer

  • from β€” principal β€” Sender address

  • to β€” principal β€” Recipient address

  • memo β€” (optional (buff 34)) β€” Optional memo

Returns: (response bool uint) β€” Success or error

Authorization: Must be called by 'from' address


Configuration Functions

initialize

Initialize vault. One-time setup by deployer.

Parameters: none

Returns: (response bool uint) β€” Success or error

Authorization: Deployer only, one-time


set-authorized-contract

Authorize contract for special permissions (e.g., whitelisted flashloan access).

Parameters:

  • contract β€” principal β€” Contract address

  • authorized β€” bool β€” True to authorize, false to revoke

Returns: (response bool uint) β€” Success or error

Authorization: DAO executor only


set-flashloan-permissions

Set flashloan permissions for specific account.

Parameters:

  • account β€” principal β€” Account address

  • perms β€” { allowed: bool, fee: uint } β€” Permissions (allowed flag + custom fee in BPS)

Returns: (response bool uint) β€” Success or error

Authorization: DAO executor only


set-flashloan-permissions-many

Batch set flashloan permissions for multiple accounts.

Parameters:

  • entries β€” (list 64 { account: principal, perms: {...} }) β€” List of account permission pairs

Returns: (response bool uint) β€” Success or error

Authorization: DAO executor only


set-cap-debt

Update borrow cap for vault.

Parameters:

  • val β€” uint β€” New borrow cap (max total debt allowed)

Returns: (response bool uint) β€” Success or error

Authorization: DAO executor only


set-cap-supply

Update supply cap for vault.

Parameters:

  • val β€” uint β€” New supply cap (max total assets allowed)

Returns: (response bool uint) β€” Success or error

Authorization: DAO executor only


set-fee-flash

Update flashloan fee.

Parameters:

  • val β€” uint β€” New flashloan fee (BPS, e.g., 9 = 0.09%)

Returns: (response bool uint) β€” Success or error

Authorization: DAO executor only


set-default-flashloan-permissions

Set default flashloan permissions for accounts without specific settings.

Parameters:

  • perms β€” { allowed: bool, fee: uint } β€” Default permissions

Returns: (response bool uint) β€” Success or error

Authorization: DAO executor only


set-fee-reserve

Update reserve fee (protocol fee on interest).

Parameters:

  • val β€” uint β€” New reserve fee (BPS, e.g., 1000 = 10% of interest)

Returns: (response bool uint) β€” Success or error

Authorization: DAO executor only


set-points-util

Update utilization breakpoints for interest rate curve.

Parameters:

  • points β€” (list 8 uint) β€” List of 8 utilization breakpoints (BPS, ascending order)

Returns: (response bool uint) β€” Success or error

Authorization: DAO executor only

Example: [0, 4000, 7000, 9000, 10000, 10000, 10000, 10000] = [0%, 40%, 70%, 90%, 100%, ...]


set-points-rate

Update interest rates at utilization breakpoints.

Parameters:

  • points β€” (list 8 uint) β€” List of 8 interest rates (BPS APR) at corresponding utilization breakpoints

Returns: (response bool uint) β€” Success or error

Authorization: DAO executor only

Example: [200, 500, 1000, 2000, 3000, 3000, 3000, 3000] = [2%, 5%, 10%, 20%, 30%, ...]


set-token-uri

Update token metadata URI.

Parameters:

  • new-uri β€” (optional (string-utf8 256)) β€” New URI or none

Returns: (response bool uint) β€” Success or error

Authorization: DAO executor only


set-pause-states

Configure pause states for operations.

Parameters:

  • states β€” { deposit: bool, redeem: bool, borrow: bool, repay: bool, accrue: bool, flashloan: bool } β€” Pause configuration for each operation

Returns: (response bool uint) β€” Success or error

Authorization: DAO executor only


Query Functions

is-authorized-contract

Check if contract is authorized for special permissions.

Parameters:

  • contract β€” principal β€” Contract address

Returns: bool β€” True if authorized


get-cap-debt

Get current borrow cap.

Parameters: none

Returns: (response uint uint) β€” Borrow cap


get-cap-supply

Get current supply cap.

Parameters: none

Returns: (response uint uint) β€” Supply cap


get-fee-flash

Get flashloan fee in basis points.

Parameters: none

Returns: (response uint uint) β€” Fee (BPS)


get-fee-reserve

Get reserve fee in basis points.

Parameters: none

Returns: (response uint uint) β€” Fee (BPS)


get-default-flashloan-permissions

Get default flashloan permissions.

Parameters: none

Returns: { allowed: bool, fee: uint } β€” Default permissions


get-flashloan-permissions

Get flashloan permissions for specific account.

Parameters:

  • account β€” principal β€” Account address

Returns: { allowed: bool, fee: uint } β€” Permissions (falls back to default if not set)


get-points-util

Get utilization breakpoints for interest rate curve.

Parameters: none

Returns: (response (list 8 uint) uint) β€” Utilization breakpoints (BPS)


get-points-rate

Get interest rates at utilization breakpoints.

Parameters: none

Returns: (response (list 8 uint) uint) β€” Interest rates (BPS APR)


get-pause-states

Get pause configuration for operations.

Parameters: none

Returns: (response {...} uint) β€” Pause states for all operations


get-available-assets

Get available liquidity for borrowing (total assets - debt).

Parameters: none

Returns: (response uint uint) β€” Available assets


Vault Operations

get-assets

Get total underlying assets in vault (excludes accrued interest).

Parameters: none

Returns: (response uint uint) β€” Total assets


get-total-assets

Preview total assets including accrued interest (without updating state).

Parameters: none

Returns: (response uint uint) β€” Total assets with accrued interest


convert-to-shares

Convert underlying amount to zToken shares.

Parameters:

  • amount β€” uint β€” Underlying amount

Returns: (response uint uint) β€” zToken shares

Formula: shares = amount Γ— total_supply / total_assets


convert-to-assets

Convert zToken shares to underlying amount.

Parameters:

  • amount β€” uint β€” zToken shares

Returns: (response uint uint) β€” Underlying amount

Formula: assets = shares Γ— total_assets / total_supply


deposit

Supply underlying tokens, receive zToken shares.

Parameters:

  • amount β€” uint β€” Underlying amount to deposit

  • min-out β€” uint β€” Minimum zToken shares expected (slippage protection)

  • recipient β€” principal β€” Address to receive zTokens

Returns: (response uint uint) β€” zToken shares minted

Note: Transfers underlying from caller to vault, mints zTokens to recipient


redeem

Burn zToken shares, receive underlying tokens.

Parameters:

  • amount β€” uint β€” zToken shares to redeem

  • min-out β€” uint β€” Minimum underlying expected (slippage protection)

  • recipient β€” principal β€” Address to receive underlying

Returns: (response uint uint) β€” Underlying tokens received

Note: Burns zTokens from caller, transfers underlying to recipient


Lending Operations

get-principal-scaled

Get scaled debt principal (before interest accrual).

Parameters: none

Returns: (response uint uint) β€” Scaled debt


get-index

Get current borrow index for compound interest accrual.

Parameters: none

Returns: (response uint uint) β€” Borrow index


get-last-update

Get timestamp of last interest accrual.

Parameters: none

Returns: (response uint uint) β€” Timestamp


get-debt

Get total actual debt (scaled Γ— index, includes accrued interest).

Parameters: none

Returns: (response uint uint) β€” Total debt


get-utilization

Get utilization ratio (borrowed / total_assets).

Parameters: none

Returns: (response uint uint) β€” Utilization (BPS, 10000 = 100%)


get-interest-rate

Get current borrow APR based on utilization and interest rate curve.

Parameters: none

Returns: (response uint uint) β€” Borrow APR (BPS)


get-next-index

Preview next borrow index after accrual (without updating state).

Parameters: none

Returns: (response uint uint) β€” Next index


get-principal-ratio-reduction

Calculate principal ratio reduction for given amount.

Parameters:

  • amount β€” uint β€” Amount to calculate ratio for

Returns: (response uint uint) β€” Ratio reduction


get-liquidity-index

Get liquidity index for zToken pricing (supply side interest accrual).

Parameters: none

Returns: (response uint uint) β€” Liquidity index


get-underlying

Get underlying token contract address.

Parameters: none

Returns: (response principal uint) β€” Underlying token address


accrue

Accrue interest and update borrow and liquidity indexes.

Parameters: none

Returns: (response { index: uint, lindex: uint } uint) β€” Updated indexes

Note: Public function, anyone can call to update interest accrual


system-borrow

Borrow underlying from vault. Market contract authorization required.

Parameters:

  • amount β€” uint β€” Amount to borrow

  • receiver β€” principal β€” Address to receive borrowed tokens

Returns: (response bool uint) β€” Success or error

Authorization: Market contract only

Note: Increases scaled debt, transfers underlying to receiver


system-repay

Repay borrowed debt. Market contract authorization required.

Parameters:

  • amount β€” uint β€” Amount to repay

Returns: (response bool uint) β€” Success or error

Authorization: Market contract only

Note: Decreases scaled debt, transfers tokens from market-vault to vault


socialize-debt

Distribute bad debt across all suppliers. Market contract authorization required.

Parameters:

  • scaled-amount β€” uint β€” Scaled debt amount to socialize

Returns: (response bool uint) β€” Success or error

Authorization: Market contract only

Note: Reduces scaled debt without repayment, socializing loss to zToken holders


Flashloan

flashloan

Execute flashloan with callback. Borrower must repay amount + fee in same transaction.

Parameters:

  • amount β€” uint β€” Amount to borrow

  • receiver β€” (optional principal) β€” Optional recipient (defaults to caller)

  • callback β€” β€” Callback contract implementing flash-callback trait

  • data β€” (optional (buff 4096)) β€” Optional data passed to callback

Returns: (response bool uint) β€” Success or error

Process:

  1. Transfers amount to receiver

  2. Calls callback.callback(amount, fee, data)

  3. Verifies amount + fee repaid

Note: Flashloan permissions and fees checked per account or default settings


Vault Traits

tokenized-vault

SIP-10 + vault share operations: get-name, get-symbol, get-token-uri, get-decimals, get-total-supply, get-balance, transfer, get-assets, convert-to-shares, convert-to-assets, deposit, redeem

flash-callback

Callback interface for flashloan recipients. Must implement: callback(amount, fee, data) -> (response bool uint)

flashloan

Flashloan interface. Must implement: flashloan(amount, receiver, callback, data) -> (response bool uint)

lending

Lending operations interface: get-principal-scaled, get-index, get-last-update, get-debt, get-utilization, get-interest-rate, get-next-index, get-principal-ratio-reduction, get-liquidity-index, get-underlying, accrue, system-borrow, system-repay, socialize-debt

reserve

Reserve configuration interface (caps, fees, interest curve): get-cap-debt, get-cap-supply, set-cap-debt, set-cap-supply, get-fee-flash, get-fee-reserve, set-fee-flash, set-fee-reserve, get-points-util, get-points-rate, set-points-util, set-points-rate

Last updated