Skip to content

add max borrow withdraw query - #640

Open
ashleychandy wants to merge 2 commits into
0dotxyz:0.1.10-mainfrom
ashleychandy:add-max-borrow-withdraw-query
Open

add max borrow withdraw query#640
ashleychandy wants to merge 2 commits into
0dotxyz:0.1.10-mainfrom
ashleychandy:add-max-borrow-withdraw-query

Conversation

@ashleychandy

@ashleychandy ashleychandy commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Description

Adds a no-op instruction to query the maximum amount a marginfi account can borrow or withdraw from a given bank without reproducing the on-chain risk engine off-chain.

The instruction simulates borrow/withdraw operations using the existing risk checks and emits the result as an event, making it easy to consume via RPC simulation.

Changes

  • Add lending_account_query_max_borrow_withdraw instruction
  • Add QueryMaxBorrowWithdrawEvent for RPC simulation output
  • Implement binary search to determine the maximum borrow amount
  • Implement binary search to determine the maximum withdraw amount
  • Return is_all when the entire user balance can be withdrawn
  • Reuse existing borrow/withdraw logic and health checks without mutating state
  • Export the new instruction through the program entrypoint

Fixes #627

@ashleychandy
ashleychandy changed the base branch from main to 0.1.10-main August 2, 2026 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant