Lending

Instructions for collateral, borrowing and repayment.

Updated Sep 25, 2026

Public credit: a position holds collateral on either side and debt on either side, each debt side secured by the opposite collateral. Admission uses the shadow curve; the stored liquidation factor judges the position afterwards. See Borrow and Borrowing and rates.

deposit_collateral

Deposit one market asset as collateral into a borrow position, creating the position if needed.

Caller
The position owner
In the app
Borrow · Portfolio
Discriminator
9c838e7492f7a278

Arguments

args: DepositCollateralArgs

FieldTypeNotes
position_idpubkeyAny public key the owner chooses; it seeds the position address.
deposit_amountu64Collateral atoms to deposit.

Accounts

AccountFlagsResolutionNotes
marketwritablePDA ["market_v2", market.base_side.asset_mint, market.quote_side.asset_mint, market.params_hash]
futarchy_authorityPDA ["futarchy_authority"]
ownerwritable · signer
asset_mint
collateral_vaultwritable
owner_asset_accountwritable
borrow_positionwritablePDA ["borrow_position_v2", market, owner, args.args.position_id]
token_programTokenkeg…Q5DA
token_2022_programTokenzQd…xuEb
system_program11111111…1111
event_authorityPDA ["__event_authority"]
program

withdraw_collateral

Withdraw collateral while the position stays within its buffered borrow limit.

The check uses the greater of the stored liquidation factor and a freshly computed one, then tests capacity after the withdrawal. Blocked in reduce-only mode while debt remains.

Caller
The position owner
In the app
Portfolio
Discriminator
7387a86a8bd68a96

Arguments

args: WithdrawCollateralArgs

FieldTypeNotes
withdraw_amountu64Collateral atoms to withdraw.
min_asset_amount_outu64Minimum received after transfer fees.
min_liquidation_cf_bpsu16Lowest liquidation collateral factor the owner accepts for the recomputed terms.

Accounts

AccountFlagsResolutionNotes
marketwritablePDA ["market_v2", market.base_side.asset_mint, market.quote_side.asset_mint, market.params_hash]
futarchy_authorityPDA ["futarchy_authority"]
ownerwritable · signer
asset_mint
collateral_vaultwritable
owner_asset_accountwritable
borrow_positionwritablePDA ["borrow_position_v2", market, borrow_position.owner, borrow_position.position_id]
token_programTokenkeg…Q5DA
token_2022_programTokenzQd…xuEb
event_authorityPDA ["__event_authority"]
program

borrow

Borrow the opposite asset against a position's collateral and store the resulting liquidation factor.

Admission uses the shadow constant-product curve at the pessimistic price and depth. Consumes the asset's daily borrow bucket. An optional referral partner can be bound the first time a debt side is opened.

Caller
The position owner
In the app
Borrow
Discriminator
e4fd83cacf745912

Arguments

args: BorrowArgs

FieldTypeNotes
borrow_amountu64Debt atoms to draw.
min_debt_amount_outu64Minimum net receipt after transfer fees.
min_liquidation_cf_bpsu16Lowest liquidation collateral factor the borrower accepts; the program stores the computed factor.
referrerOption<pubkey>Optional listed referral partner authority.

Accounts

AccountFlagsResolutionNotes
marketwritablePDA ["market_v2", market.base_side.asset_mint, market.quote_side.asset_mint, market.params_hash]
futarchy_authorityPDA ["futarchy_authority"]
ownerwritable · signer
debt_asset_mint
collateral_asset_mint
reserve_vaultwritable
owner_debt_accountwritable
borrow_positionwritablePDA ["borrow_position_v2", market, borrow_position.owner, borrow_position.position_id]
referral_partneroptionalOptional; required together with referral_accrual when a referrer is passed.
referral_accrualoptional
token_programTokenkeg…Q5DA
token_2022_programTokenzQd…xuEb
event_authorityPDA ["__event_authority"]
program

repay

Repay part or all of a position's debt on one side; anyone may pay.

Pass u64::MAX to clear the side exactly. The payer's amount is a maximum gross debit; the program takes only what the burnable shares need. Realized interest follows the interest distribution path.

Caller
The owner or any payer
In the app
Portfolio
Discriminator
ea674352d0eadba6

Arguments

args: RepayArgs

FieldTypeNotes
repay_amountu64Maximum atoms to debit from the payer.

Accounts

AccountFlagsResolutionNotes
marketwritablePDA ["market_v2", market.base_side.asset_mint, market.quote_side.asset_mint, market.params_hash]
futarchy_authorityPDA ["futarchy_authority"]
ownerwritable · signerToken payer; need not own the borrow position.
debt_asset_mint
collateral_asset_mint
reserve_vaultwritable
interest_vaultwritable
owner_debt_accountwritable
borrow_positionwritablePDA ["borrow_position_v2", market, borrow_position.owner, borrow_position.position_id]
referral_partneroptional
referral_accrualwritable · optional
token_programTokenkeg…Q5DA
token_2022_programTokenzQd…xuEb
event_authorityPDA ["__event_authority"]
program

preview_borrow_capacity

Read-only: for a collateral amount, the maximum debt by health, by cash and by the daily limit, with the collateral factors that would apply.

Caller
Any client, by simulation
Discriminator
cbaa1c4f20b4b146

Arguments

args: PreviewBorrowCapacityArgs

FieldTypeNotes
collateral_amountu64Net deposit credit in the collateral vault. Capacity also accounts for the current fee when that collateral later exits the vault.
projected_borrow_amountOption<u64>

Accounts

AccountFlagsResolutionNotes
marketwritablePDA ["market_v2", market.base_side.asset_mint, market.quote_side.asset_mint, market.params_hash]
collateral_asset_mint
debt_asset_mint

preview_borrow_position

Read-only: an existing position with interest accrued and its health terms.

Caller
Any client, by simulation
Discriminator
f0ec2d1eac922da3

Arguments

None.

Accounts

AccountFlagsResolutionNotes
marketwritablePDA ["market_v2", market.base_side.asset_mint, market.quote_side.asset_mint, market.params_hash]
borrow_positionPDA ["borrow_position_v2", market, borrow_position.owner, borrow_position.position_id]
base_mintLiquidation values each side's collateral after its mint's current transfer fee, so the preview reads both mints.
quote_mint

preview_borrow_position_capacity

Read-only: additional borrow or collateral withdrawal capacity for an existing position, using the instructions' own calculations.

Choose borrow or withdraw mode; only that limit is computed to stay within the compute budget.

Caller
Any client, by simulation
Discriminator
753f948ac925bd01

Arguments

args: PreviewBorrowPositionCapacityArgs

FieldTypeNotes
capacity_kindBorrowPositionCapacityKind
collateral_changei128Net collateral credit (positive) or vault debit (negative), in raw mint units.
projected_borrow_amountOption<u64>Additional debt to draw. None quotes the maximum additional draw.
BorrowPositionCapacityKind
VariantFields
Borrowunit
Withdrawunit

Accounts

AccountFlagsResolutionNotes
marketPDA ["market_v2", market.base_side.asset_mint, market.quote_side.asset_mint, market.params_hash]
borrow_positionPDA ["borrow_position_v2", market, borrow_position.owner, borrow_position.position_id]
collateral_asset_mint
debt_asset_mint

withdraw_all_collateral

Sweep both collateral balances and close a borrow position after its debt is fully repaid.

Caller
The position owner
Discriminator
25b99fd6251ea392

Arguments

args: WithdrawAllCollateralArgs

FieldTypeNotes
min_base_outu64
min_quote_outu64

Accounts

AccountFlagsResolutionNotes
marketwritablePDA ["market_v2", market.base_side.asset_mint, market.quote_side.asset_mint, market.params_hash]
ownerwritable · signer
borrow_positionwritablePDA ["borrow_position_v2", market, borrow_position.owner, borrow_position.position_id]
base_mint
quote_mint
base_collateral_vaultwritable
quote_collateral_vaultwritable
owner_base_accountwritable
owner_quote_accountwritable
token_programTokenkeg…Q5DA
token_2022_programTokenzQd…xuEb
event_authorityPDA ["__event_authority"]
program