Skip to content

unify integration banks depsit/withdraw instructions - #535

Open
IMEF-FEMI wants to merge 12 commits into
0.1.10-mainfrom
unify-integration-deposit-withdraw
Open

unify integration banks depsit/withdraw instructions#535
IMEF-FEMI wants to merge 12 commits into
0.1.10-mainfrom
unify-integration-deposit-withdraw

Conversation

@IMEF-FEMI

Copy link
Copy Markdown
Contributor

Summary

This PR consolidates all wrapped-integration user deposit and withdraw flows behind a single interface: integration_deposit and integration_withdraw. Instead of maintaining separate entrypoints for Kamino, Drift, Solend, and JupLend, marginfi now shares one common validation, accounting, rate-limit, health-check, and event pipeline, while keeping only the protocol-specific CPI logic isolated in per-integration handlers.

Motivation

The previous pattern duplicated the most security-sensitive parts of the flow across multiple integrations. Authorization, paused-state handling, deleverage accounting, rate-limiter enforcement, health validation, cache updates, and event emission were all copied per-protocol. Every change had to be replicated across nearly-identical handlers, raising the odds of inconsistent fixes and integration-specific gaps.

Changes

  • Shared pipeline — Common pre-deposit validation, post-deposit finalization, and post-withdraw finalization (health check, rate limiting, deleverage tracking, event emission) now live in integration_common.rs and integration/mod.rs
  • Protocol handlers — Each integration (kamino_handler, drift_handler, solend_handler, juplend_handler) contains only its CPI construction, account validation, and balance computation
  • Protocol accounts via remaining_accounts — The unified IntegrationDeposit/IntegrationWithdraw Anchor structs hold common accounts; protocol-specific accounts are passed and split by withdraw_protocol_account_count
  • TS test utilities — All instruction builders now target integrationDeposit/integrationWithdraw with protocol accounts packed as remaining accounts, validated at build time against INTEGRATION_PROTOCOL_ACCOUNT_COUNTS

Advantages

  • Protocol-specific code is narrower and easier to audit
  • Future integrations only need a new handler — no new entrypoint or duplicated pipeline
  • Clients get one deposit path and one withdraw path with a clear separation between marginfi behavior and protocol account packing

@IMEF-FEMI
IMEF-FEMI marked this pull request as ready for review March 17, 2026 15:24
@IMEF-FEMI
IMEF-FEMI requested a review from jgur-psyops as a code owner March 17, 2026 15:24
Comment thread programs/marginfi/src/instructions/integration/mod.rs
Comment thread programs/marginfi/src/instructions/integration/mod.rs
Comment thread programs/marginfi/src/instructions/drift/deposit.rs
Comment thread programs/marginfi/src/instructions/integration/mod.rs
@IMEF-FEMI
IMEF-FEMI changed the base branch from 0.1.8-main to 0.1.9-main May 14, 2026 10:07
@jgur-psyops
jgur-psyops changed the base branch from 0.1.9-main to 0.1.10-main July 10, 2026 18:40
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.

4 participants