PAR docs

API reference

Every instruction of the par program, its arguments, its accounts and what it checks. Market and PriceFeeds are the shared account groups described in Integration.

Instructions

InstructionArgumentsSignerPriced with
initializenoneanyone (payer)none
create_branchnoneanyone (payer)none
open_trovebucket_index: u16, collateral: u64, debt: u64ownerBorrow
add_collateralamount: u64ownernone
withdraw_collateralamount: u64ownerBorrow
borrowamount: u64ownerBorrow
repayamount: u64ownernone
set_ratenew_index: u16ownerBorrow, only when an upfront fee is charged
close_trovenoneownernone
redeemamount: u64, max_fee_bps: u16redeemerExit
liquidatenoneanyoneExit
provide_to_poolamount: u64ownernone
withdraw_from_poolamount: u64 (u64::MAX = all, 0 = claim only)ownernone
close_depositnoneownernone

Borrow pricing needs Pyth and Switchboard fresh and within 2% and uses the lower price. Exit pricing uses the higher fresh price, or the only fresh one.

initialize

Starts the protocol and creates PAR. Callable once, by anyone, and only after the program's upgrade authority is gone.

AccountNotes
payersigner, writable
protocolinit, ["protocol"]
par_mintinit, ["par_mint"], owned by Token-2022
programthis program; its program data must match program_data
program_datamust have upgrade_authority_address == None, else ProgramUpgradeable
par_token_program, system_program

Effects: Protocol.launch_ts = now; PAR mint created with 6 decimals, mint authority = protocol, freeze authority = none.

create_branch

Opens a branch for a listed collateral. Permissionless.

AccountNotes
payersigner
protocol
collateral_mintmust be jitoSOL or mSOL (CollateralNotListed)
branchinit, ["branch", collateral_mint]
collateral_vaultinit, ["collateral_vault", branch], SPL Token
pool_vaultinit, ["pool_vault", branch], Token-2022
par_mintpinned to protocol.par_mint
rate_sourcemust be the listed rate source (WrongRateSource)

open_trove

Deposits collateral and borrows debt PAR at bucket bucket_index's rate. The trove's debt is debt plus the upfront fee (seven days of interest at that rate).

AccountNotes
ownersigner
market, feeds
bucketinit if needed, ["bucket", branch, bucket_index]
troveinit, ["trove", branch, owner]
owner_collateralowner's LST token account
owner_parowner's PAR account (Token-2022)

Checks: bucket_index < 246 (InvalidBucket), total debt at least 200 PAR (DebtBelowMinimum), ratio at least 120% (BelowMinimumCollateralRatio), branch under the ceiling (DebtCeilingExceeded), oracles usable for Borrow.

add_collateral, withdraw_collateral, borrow, repay

The four single-direction adjustments of an active trove, sharing the AdjustTrove accounts: owner, market, feeds, bucket, trove, owner_collateral, owner_par. Each first accrues the branch and brings the trove current.

  • withdraw_collateral and borrow re-check the 120% floor at the Borrow price; borrow charges the upfront fee on the new amount and checks the ceiling.
  • repay cannot take the debt under 200 PAR (RepayTooLarge); paying everything is close_trove.

set_rate

Moves the trove to bucket new_index. Free once every seven days; sooner, it charges the upfront fee at the new rate.

AccountNotes
ownersigner; the trove PDA is ["trove", branch, owner]
market, feeds
troveactive (TroveNotActive)
current_bucket["bucket", branch, trove.bucket]
new_bucketinit if needed, ["bucket", branch, new_index]; new_index < 246, different from current (SameRate)

close_trove

Active trove: burns all its debt and returns all collateral. Redeemed or liquidated trove: returns whatever collateral was left for the owner. The account closes and its rent returns to the owner.

redeem

Swaps up to amount PAR for $1 of collateral each, minus the redemption fee, taking debt from the lowest-rate troves first. Remaining accounts: [bucket, trove, trove, .., bucket, trove, ..].

AccountNotes
redeemersigner
market, feeds
redeemer_parburned with the redeemer's signature (InsufficientPar if short)
redeemer_collateralreceives the collateral

Checks: fee rate at most max_fee_bps (RedemptionFeeTooHigh); each bucket is the lowest non-empty one when reached (WrongRedemptionOrder); each trove belongs to the bucket before it (TroveNotInBucket); something was redeemed (NothingRedeemed).

liquidate

Closes out a trove under 120%. Accounts: liquidator (signer), market, feeds, trove, bucket, liquidator_collateral. See How it works for the split between pool, redistribution and the owner's surplus.

provide_to_pool, withdraw_from_pool, close_deposit

  • provide_to_pool(amount): creates or tops up ["deposit", branch, owner], pays out earned collateral and PAR, then adds amount.
  • withdraw_from_pool(amount): pays out all gains and withdraws up to amount of the compounded deposit.
  • close_deposit: closes an empty deposit account (DepositNotEmpty otherwise) and returns its rent.

Account layouts

Trove

FieldTypeMeaning
branch, ownerPubkey
statusTroveStatusActive, or closed by redemption or liquidation
bucketu16Rate bucket index
sharesu128Share of the bucket's debt
collateralu64LST base units (9 decimals)
stake, l_collateral_snapshot, l_debt_snapshotu128Redistribution bookkeeping
last_rate_change_tsi64Start of the seven-day free window

Bucket

FieldTypeMeaning
indexu160 to 245
debt, sharesu128Debt of every trove in the bucket and the shares it is split into
trovesu32Active troves
last_accrual_tsi64

Deposit

FieldTypeMeaning
amountu128Initial deposit value at the last snapshot
p_snapshot, scale_snapshotu128, u64Product snapshot
collateral_sum_snapshot, yield_sum_snapshotu128Gains snapshots