Instructions
All 17 instructions in the Coalesce Finance program (discriminators 0–16).
Admin/Setup Instructions
0. InitializeProtocol
Creates the global ProtocolConfig. Can only be called by the program's upgrade authority.
Accounts:
| # | Account | Writable | Signer | Description |
|---|---|---|---|---|
| 0 | protocol_config | Yes | No | ProtocolConfig PDA |
| 1 | admin | Yes | Yes | Program upgrade authority (pays rent) |
| 2 | fee_authority | No | No | Address to receive fees |
| 3 | whitelist_manager | No | No | Whitelist manager address |
| 4 | blacklist_program | No | No | External blacklist program |
| 5 | system_program | No | No | System Program |
| 6 | program_data | No | No | BPF Loader upgrade data |
Data:
fee_rate_bps: u16— Protocol fee rate in basis points
1. SetFeeConfig
Updates protocol fee configuration.
Accounts:
| # | Account | Writable | Signer | Description |
|---|---|---|---|---|
| 0 | protocol_config | Yes | No | ProtocolConfig PDA |
| 1 | admin | No | Yes | Admin signer |
| 2 | new_fee_authority | No | No | New fee authority address |
Data:
new_fee_rate_bps: u16— New protocol fee rate in basis points
2. CreateMarket
Creates a new lending market.
Accounts:
| # | Account | Writable | Signer | Description |
|---|---|---|---|---|
| 0 | market | Yes | No | Market PDA |
| 1 | borrower | Yes | Yes | Borrower / market creator |
| 2 | mint | No | No | Token mint (USDC) |
| 3 | vault | Yes | No | Vault PDA (token account) |
| 4 | market_authority | No | No | Market authority PDA |
| 5 | protocol_config | No | No | ProtocolConfig |
| 6 | borrower_whitelist | No | No | BorrowerWhitelist |
| 7 | blacklist_check | No | No | Blacklist validation account |
| 8 | system_program | No | No | System Program |
| 9 | token_program | No | No | SPL Token Program |
Data:
market_nonce: u64— Unique nonce for PDA derivationannual_interest_bps: u16— Fixed annual interest ratematurity_timestamp: i64— Unix timestamp of loan maturitymax_total_supply: u64— Maximum deposit capacity
Core Lending Instructions
3. Deposit
Lender deposits USDC into a market.
Accounts:
| # | Account | Writable | Signer | Description |
|---|---|---|---|---|
| 0 | market | Yes | No | Target market |
| 1 | lender | Yes | Yes | Lender signer |
| 2 | lender_token | Yes | No | Lender's USDC token account |
| 3 | vault | Yes | No | Market vault |
| 4 | lender_position | Yes | No | LenderPosition PDA |
| 5 | blacklist_check | No | No | Blacklist validation account |
| 6 | protocol_config | No | No | ProtocolConfig |
| 7 | mint | No | No | Token mint |
| 8 | token_program | No | No | SPL Token Program |
| 9 | system_program | No | No | System Program |
Data:
amount: u64— USDC amount to deposit
4. Borrow
Borrower takes funds from their market.
Accounts:
| # | Account | Writable | Signer | Description |
|---|---|---|---|---|
| 0 | market | Yes | No | Target market |
| 1 | borrower | No | Yes | Borrower signer |
| 2 | borrower_token | Yes | No | Borrower's USDC token account |
| 3 | vault | Yes | No | Market vault |
| 4 | market_authority | No | No | Market authority PDA |
| 5 | borrower_whitelist | Yes | No | BorrowerWhitelist (debt tracking) |
| 6 | blacklist_check | No | No | Blacklist validation account |
| 7 | protocol_config | No | No | ProtocolConfig |
| 8 | token_program | No | No | SPL Token Program |
Data:
amount: u64— USDC amount to borrow
5. Repay
Repays borrowed principal. Anyone can call (not just the borrower).
Accounts:
| # | Account | Writable | Signer | Description |
|---|---|---|---|---|
| 0 | market | Yes | No | Target market |
| 1 | payer | No | Yes | Token holder repaying |
| 2 | payer_token | Yes | No | Payer's USDC token account |
| 3 | vault | Yes | No | Market vault |
| 4 | protocol_config | No | No | ProtocolConfig |
| 5 | mint | No | No | Token mint |
| 6 | borrower_whitelist | Yes | No | BorrowerWhitelist (debt tracking) |
| 7 | token_program | No | No | SPL 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:
| # | Account | Writable | Signer | Description |
|---|---|---|---|---|
| 0 | market | Yes | No | Target market |
| 1 | payer | No | Yes | Token holder paying |
| 2 | payer_token | Yes | No | Payer's USDC token account |
| 3 | vault | Yes | No | Market vault |
| 4 | protocol_config | No | No | ProtocolConfig |
| 5 | token_program | No | No | SPL Token Program |
Data:
amount: u64— USDC amount to repay as interest
7. Withdraw
Lender withdraws after maturity. First withdrawal triggers settlement factor lock.
Accounts:
| # | Account | Writable | Signer | Description |
|---|---|---|---|---|
| 0 | market | Yes | No | Target market |
| 1 | lender | No | Yes | Lender signer |
| 2 | lender_token | Yes | No | Lender's USDC token account |
| 3 | vault | Yes | No | Market vault |
| 4 | lender_position | Yes | No | LenderPosition PDA |
| 5 | market_authority | No | No | Market authority PDA |
| 6 | blacklist_check | No | No | Blacklist validation account |
| 7 | protocol_config | No | No | ProtocolConfig |
| 8 | token_program | No | No | SPL Token Program |
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:
| # | Account | Writable | Signer | Description |
|---|---|---|---|---|
| 0 | market | Yes | No | Target market |
| 1 | protocol_config | No | No | ProtocolConfig |
| 2 | fee_authority | No | Yes | Authorized fee collector |
| 3 | fee_destination | Yes | No | Fee authority's token account |
| 4 | vault | Yes | No | Market vault |
| 5 | market_authority | No | No | Market authority PDA |
| 6 | token_program | No | No | SPL Token Program |
Data: None (discriminator only)
9. ReSettle
Improves settlement factor after late repayment. Permissionless.
Accounts:
| # | Account | Writable | Signer | Description |
|---|---|---|---|---|
| 0 | market | Yes | No | Target market |
| 1 | vault | No | No | Market vault |
| 2 | protocol_config | No | No | ProtocolConfig |
Data: None (discriminator only)
10. CloseLenderPosition
Closes an empty lender position account and returns rent.
Accounts:
| # | Account | Writable | Signer | Description |
|---|---|---|---|---|
| 0 | market | No | No | Associated market |
| 1 | lender | Yes | Yes | Position owner (receives rent lamports) |
| 2 | lender_position | Yes | No | LenderPosition PDA |
| 3 | system_program | No | No | System Program |
| 4 | protocol_config | No | No | ProtocolConfig |
Data: None (discriminator only)
11. WithdrawExcess
Borrower withdraws remaining vault funds after full settlement and fee collection.
Accounts:
| # | Account | Writable | Signer | Description |
|---|---|---|---|---|
| 0 | market | No | No | Target market |
| 1 | borrower | No | Yes | Market borrower |
| 2 | borrower_token | Yes | No | Borrower's USDC token account |
| 3 | vault | Yes | No | Market vault |
| 4 | market_authority | No | No | Market authority PDA |
| 5 | token_program | No | No | SPL Token Program |
| 6 | protocol_config | No | No | ProtocolConfig |
Data: None (discriminator only)
Preconditions (all required):
borrowermust matchmarket.borrowerand 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)vaultmust match market vault and have non-zero balance
Access Control Instructions
12. SetBorrowerWhitelist
Adds or updates a borrower whitelist entry. Called by Whitelist Manager.
Accounts:
| # | Account | Writable | Signer | Description |
|---|---|---|---|---|
| 0 | borrower_whitelist | Yes | No | BorrowerWhitelist PDA |
| 1 | protocol_config | No | No | ProtocolConfig |
| 2 | whitelist_manager | Yes | Yes | Whitelist manager signer |
| 3 | borrower | No | No | Borrower address |
| 4 | system_program | No | No | System Program |
Data:
is_whitelisted: u8— 1 = whitelist, 0 = removemax_borrow_capacity: u64— Maximum outstanding borrowing capacity
13. SetPause
Pauses or unpauses the protocol. Admin only.
Accounts:
| # | Account | Writable | Signer | Description |
|---|---|---|---|---|
| 0 | protocol_config | Yes | No | ProtocolConfig |
| 1 | admin | No | Yes | Admin signer |
Data:
paused: u8— 1 = pause, 0 = unpause
14. SetBlacklistMode
Sets blacklist enforcement mode. Admin only.
Accounts:
| # | Account | Writable | Signer | Description |
|---|---|---|---|---|
| 0 | protocol_config | Yes | No | ProtocolConfig |
| 1 | admin | No | Yes | Admin signer |
Data:
fail_closed: u8— 1 = fail-closed, 0 = fail-open
15. SetAdmin
Transfers admin role to a new address. Current admin only.
Accounts:
| # | Account | Writable | Signer | Description |
|---|---|---|---|---|
| 0 | protocol_config | Yes | No | ProtocolConfig |
| 1 | current_admin | No | Yes | Current admin |
| 2 | new_admin | No | No | New admin address |
Data: None (discriminator only)
16. SetWhitelistManager
Sets the whitelist manager address. Admin only.
Accounts:
| # | Account | Writable | Signer | Description |
|---|---|---|---|---|
| 0 | protocol_config | Yes | No | ProtocolConfig |
| 1 | admin | No | Yes | Admin signer |
| 2 | new_whitelist_manager | No | No | New whitelist manager addr |
Data: None (discriminator only)