Market
Purpose: Core lending protocol. Manages collateral, borrowing, repayment, liquidation, and oracle integration. Routes operations to vaults.
List of Core Functions
Admin
set-pause-liquidation — Pause/unpause liquidations with optional grace period
set-liquidation-grace-period — Set asset-specific liquidation grace period
set-max-confidence-ratio — Update oracle confidence threshold
Queries
get-pause-liquidation — Check if liquidations paused
get-liquidation-grace-end — Get global liquidation grace period end time
get-liquidation-grace-period-asset — Get asset-specific grace period
get-max-confidence-ratio — Get oracle confidence threshold
oracle-last-update — Get last oracle update timestamp
get-cached-indexes — Get cached borrow/liquidity indexes for asset
call-ststx-ratio — Get current stSTX/STX ratio from oracle
User Operations
collateral-add — Add collateral to position
collateral-remove — Remove collateral from position
supply-collateral-add — Supply underlying + add as collateral (combined operation)
collateral-remove-redeem — Remove collateral + redeem to underlying (combined operation)
borrow — Borrow against collateral
repay — Repay borrowed debt
liquidate — Liquidate unhealthy position
liquidate-multi — Batch liquidate multiple positions
liquidate-redeem — Liquidate + automatically redeem vault shares to underlying
Function Parameters
set-pause-liquidation
Pause or unpause liquidations globally. Requires DAO authorization.
paused
bool
True to pause liquidations, false to unpause
grace-period
uint
Grace period in seconds before liquidations active (applies when unpausing)
Returns: (response bool uint) — Success or error
Authorization: DAO executor only
set-liquidation-grace-period
Set asset-specific liquidation grace period.
id
uint
Asset ID
grace-period
uint
Grace period in seconds before liquidations active for this asset
Returns: (response bool uint) — Success or error
Authorization: DAO executor only
set-max-confidence-ratio
Update oracle confidence threshold (BPS). Default 1000 = 10%.
ratio
uint
Confidence ratio in basis points (10000 = 100%)
Returns: (response bool uint) — Success or error
Authorization: DAO executor only
Note: Confidence interval must be ≤ ratio × price
get-pause-liquidation
Check if liquidations are currently paused.
(none)
-
No parameters
Returns: (response bool uint) — True if paused, false otherwise
get-liquidation-grace-end
Get global liquidation grace period end timestamp.
(none)
-
No parameters
Returns: (response (optional uint) uint) — Grace period end time or none
get-liquidation-grace-period-asset
Get asset-specific liquidation grace period end time.
id
uint
Asset ID
Returns: (response (optional uint) uint) — Grace period end time or none
get-max-confidence-ratio
Get oracle confidence threshold in basis points.
(none)
-
No parameters
Returns: uint — Confidence ratio (BPS)
oracle-last-update
Get last oracle update timestamp for specific feed.
f
{ type: (buff 1), ident: (buff 32) }
Oracle feed identifier (type + feed ID)
Returns: (optional uint) — Last update timestamp or none
get-cached-indexes
Get cached borrow and liquidity indexes for asset.
aid
uint
Asset ID
Returns: (optional { index: uint, lindex: uint }) — Indexes or none
call-ststx-ratio
Get current stSTX/STX ratio from oracle.
(none)
-
No parameters
Returns: (response uint uint) — stSTX ratio (6 decimals) or error
collateral-add
Add collateral to user's position. Can optionally update Pyth price feeds.
ft
Asset token contract
amount
uint
Amount to add as collateral
price-feeds
(optional (list 3 (buff 8192)))
Optional Pyth price feed updates (up to 3)
Returns: (response uint uint) — Updated collateral amount or error
Authorization: User must be contract-caller = tx-sender
Note: Updates position health after operation
collateral-remove
Remove collateral from user's position.
ft
Asset token contract
amount
uint
Amount to remove
receiver
(optional principal)
Optional recipient (defaults to caller)
price-feeds
(optional (list 3 (buff 8192)))
Optional Pyth price feed updates
Returns: (response uint uint) — Remaining collateral amount or error
Authorization: User must be contract-caller = tx-sender
Note: Checks position health remains adequate after removal
supply-collateral-add
Combined operation: supply underlying to vault + add resulting shares as collateral.
ft
Underlying asset token contract
amount
uint
Amount of underlying to supply
min-shares
uint
Minimum vault shares expected (slippage protection)
price-feeds
(optional (list 3 (buff 8192)))
Optional Pyth price feed updates
Returns: (response uint uint) — Vault shares received and added as collateral or error
Authorization: User must be contract-caller = tx-sender
collateral-remove-redeem
Combined operation: remove collateral (vault shares) + redeem to underlying.
ft
Vault token contract (zToken)
amount
uint
Amount of vault shares to remove and redeem
min-underlying
uint
Minimum underlying expected (slippage protection)
receiver
(optional principal)
Optional recipient (defaults to caller)
price-feeds
(optional (list 3 (buff 8192)))
Optional Pyth price feed updates
Returns: (response uint uint) — Underlying tokens received or error
Authorization: User must be contract-caller = tx-sender
borrow
Borrow assets against collateral. Creates or increases debt position.
ft
Asset token contract to borrow
amount
uint
Amount to borrow
receiver
(optional principal)
Optional recipient (defaults to caller)
price-feeds
(optional (list 3 (buff 8192)))
Optional Pyth price feed updates
Returns: (response bool uint) — Success or error
Authorization: User must be contract-caller = tx-sender
Constraints:
Must have sufficient collateral
Position must remain healthy after borrow
Cannot liquidate same block as borrow
repay
Repay borrowed debt, reducing user's debt position.
ft
Asset token contract to repay
amount
uint
Amount to repay (will be capped at actual debt)
on-behalf-of
(optional principal)
Optional account to repay for (defaults to caller)
Returns: (response uint uint) — Actual amount repaid or error
Note: Automatically caps repayment at user's actual debt
liquidate
Liquidate an unhealthy position, seizing collateral in exchange for repaying debt.
borrower
principal
Address of position to liquidate
collateral-ft
Collateral asset to seize
debt-ft
Debt asset to repay
debt-amount
uint
Amount of debt to repay
min-collateral-expected
uint
Minimum collateral to receive (slippage protection)
receiver
(optional principal)
Optional recipient for seized collateral (defaults to caller)
price-feeds
(optional (list 3 (buff 8192)))
Optional Pyth price feed updates
Returns: (response { debt: uint, collateral: uint } uint) — Amounts or error
Conditions:
Liquidations not paused
Position must be unhealthy
Grace period must have passed
Cannot liquidate same block as borrow
liquidate-multi
Batch liquidate multiple positions atomically.
positions
(list 64 {...})
List of position specs (borrower, collateral-ft, debt-ft, debt-amount, min-collateral-expected)
Returns: (response (list 64 (response {...} uint)) uint) — List of results per position
Note: Price feeds not supported in batch - update prices separately or use individual liquidate()
liquidate-redeem
Liquidate position and automatically redeem seized collateral (if vault shares) to underlying.
borrower
principal
Address of position to liquidate
collateral-ft
Collateral asset (vault token) to seize and redeem
debt-ft
Debt asset to repay
debt-amount
uint
Amount of debt to repay
min-underlying-expected
uint
Minimum underlying expected after redemption
receiver
(optional principal)
Optional recipient (defaults to caller)
price-feeds
(optional (list 3 (buff 8192)))
Optional Pyth price feed updates
Returns: (response { debt: uint, underlying: uint } uint) — Debt repaid and underlying received
Note: Combines liquidation + redemption for gas efficiency
Last updated