github codama-idl/codama @codama/nodes-from-anchor@2.0.0-rc.0

latest release: codama@2.0.0-rc.0
pre-release3 hours ago

Major Changes

  • #1157 64d52eb Thanks @codama-releases! - Release Codama v2, supporting IDLs of the v2 standard. Upgrade v1 IDLs with the codama upgrade command or the @codama/upgrade package.

  • #1248 7f8beda Thanks @lorisleiva! - Convert Anchor IDLs into Codama v2 IDLs. Alongside the new node model, the conversion now captures more of the Anchor IDL:

    • Instruction account relations become anchor.relations plugins listing the accounts that must hold the account's address in their data. Legacy (v00) relations are flipped to follow the direction of current (v01) IDLs.
    • PDA seeds can point to nested instruction arguments, following links to defined types, e.g. a params.seed seed becomes a params_seed seed whose value is dataValueNode('params.seed'). Only the PDAs of nested account seeds, e.g. mint.authority, are still skipped, since they require fetching the account.
    • Legacy (v00) instruction accounts get PDA default values from their pda attribute.
    • Instruction returns become the instruction's returnData.
    • Type aliases (kind: 'type') of current (v01) IDLs resolve to their aliased type.
    • Programs, accounts and events carry their docs.

    BREAKING CHANGES

    Identifiers keep the IDL's casing. Names are no longer camelCased, so the identifiers of programs, accounts, instructions, arguments, types, events, errors and PDAs match the Anchor IDL, e.g. transfer_tokens in current (v01) IDLs. Discriminators are still derived from the names Anchor hashes.

    Instruction arguments become instruction data. Instructions store their discriminator and arguments as the fields of a data struct, and PDA seeds refer to them through dataValueNodes. The instructionArgumentNodeFromAnchorV00 and instructionArgumentNodeFromAnchorV01 helpers are removed: use structFieldTypeNodeFromAnchorV00 and structFieldTypeNodeFromAnchorV01 instead. The instruction account helpers take these data fields and an options bag instead of a positional prefix, and pdaSeedNodeFromAnchorV01 returns undefined for seeds that cannot be expressed statically.

    - instructionAccountNodesFromAnchorV00(accounts, prefix);
    + instructionAccountNodesFromAnchorV00(accounts, dataFields, { definedTypes, prefix });
    - instructionAccountNodesFromAnchorV01(accounts, instructionArguments, prefix);
    + instructionAccountNodesFromAnchorV01(accounts, dataFields, { definedTypes, prefix });
    - pdaSeedNodeFromAnchorV01(seed, instructionArguments, prefix);
    + pdaSeedNodeFromAnchorV01(seed, dataFields, { definedTypes, prefix });

    The same applies to instructionAccountNodeFromAnchorV00 and instructionAccountNodeFromAnchorV01.

    Enum variant helpers unified. The enumEmptyVariantTypeNodeFromAnchorV0x, enumStructVariantTypeNodeFromAnchorV0x and enumTupleVariantTypeNodeFromAnchorV0x helpers are replaced by enumVariantTypeNodeFromAnchorV00 and enumVariantTypeNodeFromAnchorV01, which return an enumVariantTypeNode with a struct, tuple or no data.

    Lossless numbers. Numbers become integerTypeNodes or floatTypeNodes, and integer constants become string-encoded integerValueNodes, so 64- and 128-bit constants are no longer rounded.

    No program origin. Programs no longer carry an origin, which v2 removes.

  • #1264 909960f Thanks @lorisleiva! - Trim public exports that were only meant for internal use, so the public API only exposes what consumers need.

    BREAKING CHANGES

    @codama/errors no longer exports safeCaptureStackTrace. It was unused, even by CodamaError, and is also gone from codama, which re-exports it. Call Error.captureStackTrace directly if you need it.

    @codama/fragments/javascript no longer exports preferIncoming. Use mergeImportMaps or addToImportMap, which apply the same conflict-resolution rule.

    @codama/dynamic-address-resolution no longer exports OPTIONAL_NODE_KINDS. Check the type node kind directly, e.g. isNode(type, ['optionTypeNode', 'remainderOptionTypeNode', 'zeroableOptionTypeNode']).

    @codama/nodes-from-anchor only exports its root and program converters. The per-node converters, their options types and the generics helpers are now internal. Convert whole IDLs with rootNodeFromAnchor (or rootNodeFromAnchorV00, rootNodeFromAnchorV01, programNodeFromAnchorV00 and programNodeFromAnchorV01) and pick the nodes you need from the result. The removed exports are:

    • accountNodeFromAnchorV00, arrayTypeNodeFromAnchorV00, constantNodeFromAnchorV00, definedTypeNodeFromAnchorV00, enumTypeNodeFromAnchorV00, enumVariantTypeNodeFromAnchorV00, errorNodeFromAnchorV00, eventNodeFromAnchorV00, instructionAccountNodeFromAnchorV00, instructionAccountNodesFromAnchorV00, instructionNodeFromAnchorV00, mapTypeNodeFromAnchorV00, optionTypeNodeFromAnchorV00, pdaNodeFromAnchorV00, pdaSeedTypeNodeFromAnchorV00, setTypeNodeFromAnchorV00, structFieldTypeNodeFromAnchorV00, structTypeNodeFromAnchorV00, tupleTypeNodeFromAnchorV00, typeNodeFromAnchorV00 and InstructionAccountNodeFromAnchorV00Options.
    • accountNodeFromAnchorV01, arrayTypeNodeFromAnchorV01, constantNodeFromAnchorV01, definedTypeNodeFromAnchorV01, enumTypeNodeFromAnchorV01, enumVariantTypeNodeFromAnchorV01, errorNodeFromAnchorV01, eventNodeFromAnchorV01, instructionAccountNodeFromAnchorV01, instructionAccountNodesFromAnchorV01, instructionNodeFromAnchorV01, optionTypeNodeFromAnchorV01, pdaSeedNodeFromAnchorV01, structFieldTypeNodeFromAnchorV01, structTypeNodeFromAnchorV01, tupleTypeNodeFromAnchorV01, typeNodeFromAnchorV01, unwrapGenericTypeFromAnchorV01, extractGenerics, GenericsV01, InstructionAccountNodeFromAnchorV01Options and PdaSeedNodeFromAnchorV01Options.
    • extractPdasFromProgram: use extractPdasVisitor instead.
    - import { accountNodeFromAnchorV01 } from '@codama/nodes-from-anchor';
    - const account = accountNodeFromAnchorV01(idl.accounts[0], idl.types, generics);
    + import { rootNodeFromAnchor } from '@codama/nodes-from-anchor';
    + const account = rootNodeFromAnchor(idl).program.accounts?.[0];

    @codama/visitors-core no longer exports LINKABLE_NODES, getDependencies and assertNodePathHasProgram. These are also gone from @codama/visitors and codama, which re-export it. Use findProgramNodeFromPath to check that a path has a program, and getResolvedInstructionInputsVisitor to resolve instruction input dependencies.

  • #1260 3ad402a Thanks @lorisleiva! - Require Node.js 22.12.0 or later.

    BREAKING CHANGES

    Node.js 20 is no longer supported. Every package now declares "engines": { "node": ">=22.12.0" }, the first Node.js 22 release that supports require(esm) by default. Node.js 20 reached its end of life in April 2026, and some dependencies (e.g. commander) already require Node.js 22.12.0.

Patch Changes

  • #1260 3ad402a Thanks @lorisleiva! - Inline @noble/hashes in CommonJS builds so require works on Node.js versions without require(esm) support.

  • #1248 7f8beda Thanks @lorisleiva! - Fix the instruction discriminators of legacy (v00) IDLs and the error thrown for unknown generic types:

    • Instruction names containing acronyms now hash to the name Anchor uses, e.g. setHTTPConfig hashes global:set_http_config instead of global:set_h_t_t_p_config.
    • Shank instruction discriminators below 16 are zero-padded to a full byte, e.g. 0a instead of a.
    • References to an unknown generic type in current (v01) IDLs throw a CODAMA_ERROR__ANCHOR__GENERIC_TYPE_MISSING error instead of a TypeError.
  • Updated dependencies [cedeb1e, 1f0fb88, 3f76a7f, e1cce0d, 64d52eb, e92df74, 7f8beda, 7f8beda, cedeb1e, 7f8beda, 909960f, 3f76a7f, bb09077, bb09077, 3ad402a, 7f8beda, 7f8beda, b869cef, 7f8beda, 7f8beda, 08d72e7, 7f8beda]:

    • @codama/visitors@2.0.0-rc.0
    • @codama/errors@2.0.0-rc.0
    • @codama/fragments@2.0.0-rc.0
    • @codama/nodes@2.0.0-rc.0

Don't miss a new codama release

NewReleases is sending notifications on new releases.