Instructions#

All 20 instructions in the Coalesce Finance program (discriminators 0–16, 18–20).

Admin/Setup Instructions#

0. InitializeProtocol#

Creates the global ProtocolConfig. Can only be called by the program's upgrade authority.

Accounts:

#AccountWritableSignerDescription
0protocol_configYesNoProtocolConfig PDA
1adminYesYesProgram upgrade authority (pays rent)
2fee_authorityNoNoAddress to receive fees
3whitelist_managerNoNoWhitelist manager address
4blacklist_programNoNoExternal blacklist program
5system_programNoNoSystem Program
6program_dataNoNoBPF Loader upgrade data

Data:

  • fee_rate_bps: u16 — Protocol fee rate in basis points

1. SetFeeConfig#

Updates protocol fee configuration.

Accounts:

#AccountWritableSignerDescription
0protocol_configYesNoProtocolConfig PDA
1adminNoYesAdmin signer
2new_fee_authorityNoNoNew fee authority address

Data:

  • new_fee_rate_bps: u16 — New protocol fee rate in basis points

2. CreateMarket#

Creates a new lending market.

Accounts:

#AccountWritableSignerDescription
0marketYesNoMarket PDA
1borrowerYesYesBorrower / market creator
2mintNoNoToken mint (USDC)
3vaultYesNoVault PDA (token account)
4market_authorityNoNoMarket authority PDA
5protocol_configNoNoProtocolConfig
6borrower_whitelistNoNoBorrowerWhitelist
7blacklist_checkNoNoBlacklist validation account
8system_programNoNoSystem Program
9token_programNoNoSPL Token Program
10haircut_stateYesNoHaircutState PDA

Data:

  • market_nonce: u64 — Unique nonce for PDA derivation
  • annual_interest_bps: u16 — Fixed annual interest rate
  • maturity_timestamp: i64 — Unix timestamp of loan maturity
  • max_total_supply: u64 — Maximum deposit capacity

Core Lending Instructions#

3. Deposit#

Lender deposits USDC into a market.

Accounts:

#AccountWritableSignerDescription
0marketYesNoTarget market
1lenderYesYesLender signer
2lender_tokenYesNoLender's USDC token account
3vaultYesNoMarket vault
4lender_positionYesNoLenderPosition PDA
5blacklist_checkNoNoBlacklist validation account
6protocol_configNoNoProtocolConfig
7mintNoNoToken mint
8token_programNoNoSPL Token Program
9system_programNoNoSystem Program

Data:

  • amount: u64 — USDC amount to deposit

4. Borrow#

Borrower takes funds from their market.

Accounts:

#AccountWritableSignerDescription
0marketYesNoTarget market
1borrowerNoYesBorrower signer
2borrower_tokenYesNoBorrower's USDC token account
3vaultYesNoMarket vault
4market_authorityNoNoMarket authority PDA
5borrower_whitelistYesNoBorrowerWhitelist (debt tracking)
6blacklist_checkNoNoBlacklist validation account
7protocol_configNoNoProtocolConfig
8token_programNoNoSPL Token Program

Data:

  • amount: u64 — USDC amount to borrow

5. Repay#

Repays borrowed principal. Anyone can call (not just the borrower).

Accounts:

#AccountWritableSignerDescription
0marketYesNoTarget market
1payerNoYesToken holder repaying
2payer_tokenYesNoPayer's USDC token account
3vaultYesNoMarket vault
4protocol_configNoNoProtocolConfig
5mintNoNoToken mint
6borrower_whitelistYesNoBorrowerWhitelist (debt tracking)
7token_programNoNoSPL Token Program

Data:

  • amount: u64 — USDC amount to repay

6. RepayInterest#

Repays interest only (does not reduce borrower's outstanding debt). Anyone can call. Updates market.total_repaid and market.total_interest_repaid.

Accounts:

#AccountWritableSignerDescription
0marketYesNoTarget market
1payerNoYesToken holder paying
2payer_tokenYesNoPayer's USDC token account
3vaultYesNoMarket vault
4protocol_configNoNoProtocolConfig
5token_programNoNoSPL Token Program

Data:

  • amount: u64 — USDC amount to repay as interest

7. Withdraw#

Lender withdraws after maturity. If the market is still unsettled, the first withdrawal after the 5-minute grace period triggers the settlement factor lock.

Accounts:

#AccountWritableSignerDescription
0marketYesNoTarget market
1lenderNoYesLender signer
2lender_tokenYesNoLender's USDC token account
3vaultYesNoMarket vault
4lender_positionYesNoLenderPosition PDA
5market_authorityNoNoMarket authority PDA
6blacklist_checkNoNoBlacklist validation account
7protocol_configNoNoProtocolConfig
8token_programNoNoSPL Token Program
9haircut_stateYesNoHaircutState PDA

Data:

  • scaled_amount: u128 — Shares to withdraw (0 = full withdrawal)
  • min_payout: u64 — Minimum USDC to receive (slippage protection)

Settlement Instructions#

8. CollectFees#

Collects accrued protocol fees from a market.

Accounts:

#AccountWritableSignerDescription
0marketYesNoTarget market
1protocol_configNoNoProtocolConfig
2fee_authorityNoYesAuthorized fee collector
3fee_destinationYesNoFee authority's token account
4vaultYesNoMarket vault
5market_authorityNoNoMarket authority PDA
6token_programNoNoSPL Token Program

Data: None (discriminator only)

9. ReSettle#

Improves settlement factor after late repayment. Permissionless.

Accounts:

#AccountWritableSignerDescription
0marketYesNoTarget market
1vaultNoNoMarket vault
2protocol_configNoNoProtocolConfig
3haircut_stateNoNoHaircutState PDA (read-only)

Data: None (discriminator only)

10. CloseLenderPosition#

Closes an empty lender position account and returns rent.

Accounts:

#AccountWritableSignerDescription
0marketNoNoAssociated market
1lenderYesYesPosition owner (receives rent lamports)
2lender_positionYesNoLenderPosition PDA
3system_programNoNoSystem Program
4protocol_configNoNoProtocolConfig

Data: None (discriminator only)

11. WithdrawExcess#

Borrower withdraws remaining vault funds after full settlement and fee collection.

Accounts:

#AccountWritableSignerDescription
0marketNoNoTarget market
1borrowerNoYesMarket borrower
2borrower_tokenYesNoBorrower's USDC token account
3vaultYesNoMarket vault
4market_authorityNoNoMarket authority PDA
5token_programNoNoSPL Token Program
6protocol_configNoNoProtocolConfig
7blacklist_checkNoNoBlacklist validation account
8borrower_whitelistNoNoBorrowerWhitelist (read-only validation)

Data: None (discriminator only)

Preconditions (all required):

  • borrower must match market.borrower and be a signer
  • Market must be matured (now >= maturity_timestamp)
  • scaled_total_supply == 0 (all lenders have withdrawn)
  • settlement_factor_wad > 0 (market settled)
  • settlement_factor_wad == WAD (full settlement only)
  • accrued_protocol_fees == 0 (fees collected first)
  • Borrower must pass blacklist check
  • vault must match market vault
  • Excess amount (vault_balance - haircut_accumulator) must be greater than zero

Access Control Instructions#

12. SetBorrowerWhitelist#

Adds or updates a borrower whitelist entry. Called by Whitelist Manager.

Accounts:

#AccountWritableSignerDescription
0borrower_whitelistYesNoBorrowerWhitelist PDA
1protocol_configNoNoProtocolConfig
2whitelist_managerYesYesWhitelist manager signer
3borrowerNoNoBorrower address
4system_programNoNoSystem Program

Data:

  • is_whitelisted: u8 — 1 = whitelist, 0 = remove
  • max_borrow_capacity: u64 — Maximum outstanding borrowing capacity

13. SetPause#

Pauses or unpauses the protocol. Admin only.

Accounts:

#AccountWritableSignerDescription
0protocol_configYesNoProtocolConfig
1adminNoYesAdmin signer

Data:

  • paused: u8 — 1 = pause, 0 = unpause

14. SetBlacklistMode#

Sets blacklist enforcement mode. Admin only.

Accounts:

#AccountWritableSignerDescription
0protocol_configYesNoProtocolConfig
1adminNoYesAdmin signer

Data:

  • fail_closed: u8 — 1 = fail-closed, 0 = fail-open

15. SetAdmin#

Transfers admin role to a new address. Current admin only.

Accounts:

#AccountWritableSignerDescription
0protocol_configYesNoProtocolConfig
1current_adminNoYesCurrent admin
2new_adminNoNoNew admin address

Data: None (discriminator only)

16. SetWhitelistManager#

Sets the whitelist manager address. Admin only.

Accounts:

#AccountWritableSignerDescription
0protocol_configYesNoProtocolConfig
1adminNoYesAdmin signer
2new_whitelist_managerNoNoNew whitelist manager addr

Data: None (discriminator only)

Post-Maturity Instructions#

18. ForceClosePosition#

Borrower force-closes a lender position after maturity + grace period. Computes payout using the same formula as Withdraw, transfers to a lender-owned token account, zeros the position, and decrements scaled_total_supply. If the market has not settled yet, the instruction computes and locks settlement_factor_wad inline. This enables withdraw_excess to succeed when dust, lost wallets, or blacklisted lenders prevent voluntary withdrawal.

Accounts:

#AccountWritableSignerDescription
0marketYesNoTarget market
1borrowerNoYesMarket borrower (signer)
2lender_positionYesNoLenderPosition PDA to force-close
3vaultYesNoMarket vault
4escrow_token_accountYesNoLender-owned token account (receives payout)
5market_authorityNoNoMarket authority PDA
6protocol_configNoNoProtocolConfig
7token_programNoNoSPL Token Program
8haircut_stateYesNoHaircutState PDA

Data: None (discriminator only)

Preconditions (all required):

  • borrower must match market.borrower and be a signer
  • Market must be past maturity_timestamp + SETTLEMENT_GRACE_PERIOD
  • settlement_factor_wad may be 0; on first eligible force-close the instruction computes and locks settlement inline
  • Lender position must have valid PDA derivation
  • If payout is zero (dust/deadlock), transfer is skipped and position is still cleared

19. ClaimHaircut#

Allows a lender to claim haircut recovery tokens when the settlement factor improves. The lender receives tokens proportional to their share of the haircut gap that has been recovered since their last claim.

Accounts:

#AccountWritableSignerDescription
0marketYesNoTarget market
1lenderNoYesLender signer
2lender_positionYesNoLenderPosition PDA
3lender_tokenYesNoLender's USDC token account
4vaultYesNoMarket vault
5market_authorityNoNoMarket authority PDA
6haircut_stateYesNoHaircutState PDA
7protocol_configNoNoProtocolConfig
8token_programNoNoSPL Token Program

Data: None (discriminator only)

20. ForceClaimHaircut#

Borrower force-claims haircut recovery on behalf of a lender, sending recovered tokens to an escrow token account. Used when a lender is unable or unwilling to claim.

Accounts:

#AccountWritableSignerDescription
0marketYesNoTarget market
1borrowerNoYesMarket borrower (signer)
2lender_positionYesNoLenderPosition PDA
3escrow_token_accountYesNoLender-owned token account (receives payout)
4vaultYesNoMarket vault
5market_authorityNoNoMarket authority PDA
6haircut_stateYesNoHaircutState PDA
7protocol_configNoNoProtocolConfig
8token_programNoNoSPL Token Program

Data: None (discriminator only)