Skip to content

Generate Anchor program interface from IDL

License

Notifications You must be signed in to change notification settings

labeleven-dev/anchorgen

Repository files navigation

ANCHORGEN

Publish Status npm version Known Vulnerabilities Code Style: Google

This is a work-in-progress. Use at your own risk.

Reverse engineers an Anchor program's interface from its IDL.

This could be useful when invoking CPIs on a closed-source Anchor program.

Try it

anchor init jupiter

anchor idl fetch --provider.cluster mainnet JUP2jxvXaqu7NQY1GmNF4m1vodw12LVXYxbFL2uJvfo | \
npx @lab11/anchorgen JUP2jxvXaqu7NQY1GmNF4m1vodw12LVXYxbFL2uJvfo > jupiter/programs/jupiter/src/lib.rs

anchor build

Now you can use reference it in your program's Cargo.toml as a depedency:

[dependencies]
jupiter = { path = "../../../jupiter/programs/jupiter", features = ["cpi", "no-entrypoint"] }

See npx @lab11/anchorgen --help for more info.

Features

Tested with Anchor 0.24.x.

  • Instrcutions
  • Accounts
  • Accounts: Nested
  • Types: Primitives
  • Types: Struct
  • Types: Enum
  • Types: Option & COption
  • Types: Vector & Array
  • Errors
  • Constants
  • State
  • Events
  • Metadata
  • Docs (waiting for coral-xyz/anchor#1561 to make it to a canonical release)

Contributing

Pull requests and GitHub Issues are welcome.