Skip to content

feat: Solana State SDK — Jupiter, Drift, Kamino protocol wrappers#11

Open
skansal-rome wants to merge 8 commits into
masterfrom
feat/solana-state-sdk
Open

feat: Solana State SDK — Jupiter, Drift, Kamino protocol wrappers#11
skansal-rome wants to merge 8 commits into
masterfrom
feat/solana-state-sdk

Conversation

@skansal-rome
Copy link
Copy Markdown
Contributor

Summary

  • Convert library extensions: Added read_u16le, read_u128le, u16le to contracts/convert.sol. Refactored existing read_i128le to use read_u128le.
  • Jupiter v6 passthrough: JupiterLib execute_route helper + JupiterSwap convenience contract for forwarding pre-computed Jupiter API routes via CPI.
  • Drift v2 full integration: Account parsers (PerpMarket, SpotMarket, User positions), PDA derivation, instruction builders (deposit, withdraw, place_perp_order, cancel_order), DriftOrderBuilder for market/limit orders, DriftController + DriftFactory.
  • Kamino Lending + Vault: Reserve and Obligation parsers with health factor computation, PDA derivation, instruction builders (deposit, withdraw, borrow, repay), KaminoLending contract. Vault strategy parser + KaminoVault contract for LP provision.
  • Unified DeFi interfaces: ISwap, ILending, IPerpetuals, ILiquidity protocol-agnostic interfaces + DeFiRouter implementing all four, delegating to protocol-specific libraries.
  • Hardhat config: Enabled viaIR: true + optimizer for stack depth support in complex CPI account builders.

Architecture

┌──────────────────────────────────────────────────┐
│  Unified DeFi Layer                              │
│  ISwap · ILending · IPerpetuals · ILiquidity     │
│              DeFiRouter (delegates)              │
└──────────┬──────────┬──────────┬─────────────────┘
           │          │          │
┌──────────┴──┐ ┌─────┴──────┐ ┌┴─────────────────┐
│ JupiterLib  │ │ DriftLib   │ │ KaminoLendingLib  │
│ (passthru)  │ │ DriftIx    │ │ KaminoLendingIx   │
│             │ │ DriftPDA   │ │ KaminoVaultLib    │
│             │ │ DriftCtrl  │ │ KaminoVaultIx     │
└─────────────┘ └────────────┘ └───────────────────┘
                       │
         Rome CPI Precompile (0xFF...08)

⚠️ Before merging

  • All byte offsets in parsers are marked VERIFY — must be validated against live Solana account dumps before production use
  • Jupiter/Drift/Kamino may not be deployed on monti_spl; integration testing requires mock accounts or mainnet forks
  • Program IDs are hardcoded from mainnet base58 addresses

Test plan

  • npx hardhat compile — 49 files compile cleanly (solc 0.8.28, viaIR)
  • Validate parser offsets against Anchor IDL account snapshots
  • Deploy to monti_spl and run integration tests (blocked on protocol availability)
  • Unit tests for Convert extensions with boundary values
  • Unit tests for instruction builder discriminators

🤖 Generated with Claude Code

Sattvik Kansal and others added 8 commits April 1, 2026 17:25
…rough

Add read_u16le, read_u128le, u16le to Convert library (read_i64le and
read_i128le already existed, refactored read_i128le to use read_u128le).
Add Jupiter v6 passthrough invoke helper and JupiterSwap convenience contract.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add full Drift v2 protocol wrappers: PDA derivation, account parsers
(PerpMarket, SpotMarket, User positions), instruction builders (deposit,
withdraw, place_perp_order, cancel_order), DriftOrderBuilder for market
and limit orders, DriftController high-level contract, and DriftFactory.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add Kamino Lending wrappers: Reserve and Obligation parsers with health
factor computation, PDA derivation, instruction builders (deposit,
withdraw, borrow, repay), and KaminoLending high-level contract.
Add Kamino Vault wrappers: Strategy parser, vault instruction builders,
and KaminoVault contract for LP provision.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add protocol-agnostic interfaces: ISwap (Jupiter/Meteora), ILending
(Kamino), IPerpetuals (Drift), ILiquidity (Kamino Vault). DeFiRouter
implements all four interfaces and delegates to protocol-specific
libraries. Enable viaIR in hardhat config for stack depth support.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…innet

Drift PerpMarket: All offsets shifted due to self-pubkey field at [8].
Corrected: oracle→40, base_asset_reserve→176, quote_asset_reserve→192,
cumulative_funding_long→560, cumulative_funding_short→576,
last_funding_rate_ts→792, market_index→1160, status→1162.
Removed open_interest (not a real Drift field).

Drift SpotMarket: oracle→40, mint→72, vault→104, deposit_balance→432,
borrow_balance→448, cum_deposit_interest→464, cum_borrow_interest→480,
decimals→680 (u32 low byte), market_index→684, status→688.

Kamino Lending: Corrected program ID to KLend2g3cP87fffoy8q1mQqGKjrxjC8boSyAYavgmjD,
RESERVE_MIN_LEN to 8624. Header offsets (25-225) validated. Collateral/config
offsets (520, 700) marked as unverified pending USDC reserve validation.

All 51 offset checks pass against live mainnet Solana accounts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Deployed addresses:
- JupiterSwap: 0x1f67cfdfe9545f79e4f2de7243f4350d8c044d84
- DriftFactory: 0x7e8d277ecc3da14718fda1a4066002e206aa0244
- KaminoLending: 0xad9432a6d2c52e540df1c81a44dac0b05998f985
- KaminoVault: 0x8dddf7d1b8ade2c8b3230a4fa4b626c8c7d0b03c
- DeFiRouter: 0x893297525024de0dc3de44cde83b1b939a0db6bc

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
DriftController reads live data: PerpMarket 0 (SOL-PERP) and 1 (ETH-PERP)
return correct market_index, non-zero reserves, recent funding timestamps.
SpotMarket 0 (USDC, decimals=6) and 1 (SOL, decimals=9) validated.
DriftFactory: controller creation + duplicate prevention verified.
KaminoLending/Vault: correctly revert (Kamino not on monti_spl Solana).
DeFiRouter: all delegated functions tested, swap/cancel correctly revert.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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