Skip to content

feat: update marginfi IDL to 0.1.8 (supports on-chain program mrgn-0.1.8-rc3) - #1138

Open
benebobaa wants to merge 1 commit into
mrgnlabs:mainfrom
benebobaa:feat/marginfi-0.1.8-idl-update
Open

feat: update marginfi IDL to 0.1.8 (supports on-chain program mrgn-0.1.8-rc3)#1138
benebobaa wants to merge 1 commit into
mrgnlabs:mainfrom
benebobaa:feat/marginfi-0.1.8-idl-update

Conversation

@benebobaa

Copy link
Copy Markdown

Summary

Updates the bundled IDL to match the on-chain program version mrgn-0.1.8-rc3 which was deployed to mainnet on March 27, 2026.

Problem

The SDK was failing with a Borsh decode error when fetching Marginfi accounts:

TypeError: Cannot read properties of null (reading 'property')
    at Union.decode (buffer-layout/lib/Layout.js:1692)

Root Cause: The SDK's IDL (0.1.7) didn't recognize the new account types added in the 0.1.8 on-chain program update:

  • Order - new stop-loss/take-profit order account
  • ExecuteOrderRecord - ephemeral account for order execution
  • Lending - appears to be a new lending account type

When AccountClient.all() fetches all program accounts, it tries to decode them all using the old IDL and crashes on the new account types.

Solution

  1. Added marginfi_0.1.8.json - the IDL fetched from the on-chain program using anchor idl fetch MFv2hWf31Z9kbCa1snEPYctwafyhdvnV7FZnsebVacA --provider.cluster mainnet
  2. Updated index.ts to export the 0.1.8 IDL

Verification

# Fetch IDL from on-chain program
anchor idl fetch MFv2hWf31Z9kbCa1snEPYctwafyhdvnV7FZnsebVacA --provider.cluster mainnet

# The fetched IDL has 15 account types vs 12 in 0.1.7:
# New accounts: Order, ExecuteOrderRecord, Lending

Known Issues

⚠️ TypeScript types need regeneration: The marginfi-types_0.1.7.ts file needs to be regenerated from the new IDL. This requires:

  1. Building the marginfi-v2 Rust program with Anchor (in the 0dotxyz/marginfi-v2 repo)
  2. Anchor will generate updated TypeScript types automatically
  3. The types export in index.ts should be updated to use the new types

Currently using as unknown as MarginfiIdlType to bypass type checking until types are regenerated.

Testing

The agent was tested with:

  • QuickNode RPC ✅
  • Helius RPC ✅
  • Both showed same BORSH_DECODE error before this fix

After this change, the AccountClient.all() should no longer crash on new account types.

Checklist

  • IDL JSON updated to 0.1.8
  • TypeScript types regenerated (needs Anchor build in marginfi-v2 repo)
  • Version bump to 6.5.0 (maintainers will do this on release)

Updates the bundled IDL to match the on-chain program version 0.1.8-rc3
which was deployed to mainnet on March 27, 2026.

Changes:
- Add marginfi_0.1.8.json with new account types: Order, ExecuteOrderRecord, Lending
- Update index.ts to export the 0.1.8 IDL
- TypeScript types (marginfi-types_0.1.7.ts) need regeneration via Anchor build

Note: The TypeScript types file requires regeneration using Anchor's
code generation. Build the marginfi-v2 Rust program with Anchor to
regenerate the types, then update the types export accordingly.

This fixes the Borsh decode error when fetching Marginfi accounts:
- Error: 'Cannot read properties of null (reading property)'
- Cause: SDK IDL 0.1.7 didn't recognize new Order/ExecuteOrderRecord/Lending accounts
  which were added in the 0.1.8 on-chain program update
@benebobaa
benebobaa requested a review from chambaz as a code owner April 3, 2026 12:19
@vercel

vercel Bot commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

@benebobaa is attempting to deploy a commit to the mrgn Team on Vercel.

A member of the Team first needs to authorize it.

@k0beLeenders

Copy link
Copy Markdown
Contributor

Please use https://github.com/0dotxyz/p0-ts-sdk for continued support for the marginfi program.

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.

2 participants