Skip to content

refactor(basics/close-account): replace borsh with kit codecs in native example - #687

Merged
amilz merged 1 commit into
mainfrom
refactor/DEV-838-close-account-kit-codecs
Aug 13, 2026
Merged

refactor(basics/close-account): replace borsh with kit codecs in native example#687
amilz merged 1 commit into
mainfrom
refactor/DEV-838-close-account-kit-codecs

Conversation

@amilz

@amilz amilz commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • basics/close-account/native was the last package pinned to borsh: ^0.7.0 — the only pre-2.x pin in the repo — and called deserialize(schema, Class, buffer), a signature that no longer exists in borsh 2.x. Dropped the dep and regenerated the lockfile.
  • Instruction data now uses getStructEncoder, with addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder()) for the name string, matching the pattern from refactor(tokens): use kit codecs for instruction data in Token-2022 and create-token examples #676.
  • ts/state/index.ts exposes a userDecoder for the on-chain User layout in place of the borsh class boilerplate.
  • Test asserts real post-state: the decoded account name after create, and the System Program owner plus zero-length data after close.

Test Plan

  • pnpm build-and-test in basics/close-account/native — 3 passing
  • pnpm exec tsc --noEmit -p tsconfig.json — clean
  • pnpm run check (prettier) — clean
  • Broke each new assertion once to confirm it fails loudly

Closes DEV-838

…ve example

The native example was the last package pinned to borsh 0.7, whose
deserialize(schema, Class, buffer) signature no longer exists in borsh 2.x.
Instruction data and the User account layout are now expressed as @solana/kit
struct codecs, and the test asserts the decoded account name plus the
post-close owner and data length.

Refs: DEV-838
@amilz
amilz requested a review from dev-jodee as a code owner August 13, 2026 19:37
@linear

linear Bot commented Aug 13, 2026

Copy link
Copy Markdown

DEV-838

@amilz amilz self-assigned this Aug 13, 2026
@greptile-apps

greptile-apps Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR replaces the native close-account example’s legacy TypeScript Borsh dependency with equivalent Solana Kit codecs and strengthens its integration assertions.

  • Encodes create and close instructions with explicit Kit struct encoders matching the native Rust Borsh wire format.
  • Exposes a Kit decoder for the on-chain User account layout.
  • Verifies decoded state after creation and zero-length, System Program-owned state after closure.
  • Removes Borsh and its transitive packages from the package manifest and lockfile.

Confidence Score: 5/5

The PR appears safe to merge, with the new codecs preserving the program’s existing wire and account-data layouts.

The create and close encoders match the Rust program’s Borsh discriminants and string representation, the decoder matches the persisted User layout, and the new post-state assertions reflect the program’s actual close behavior.

Important Files Changed

Filename Overview
basics/close-account/native/ts/instructions/create.ts Replaces Borsh serialization with an equivalent u8 discriminant and little-endian u32-prefixed UTF-8 name encoder.
basics/close-account/native/ts/instructions/close.ts Replaces the single-byte Borsh close instruction with an equivalent Kit struct encoder.
basics/close-account/native/ts/state/index.ts Replaces the unused Borsh model boilerplate with a decoder matching the program’s Borsh-serialized string field.
basics/close-account/native/tests/close-account.test.ts Adds valid assertions for created account data and the program’s resize-to-zero and System Program reassignment close behavior.
basics/close-account/native/package.json Removes the now-unused direct Borsh dependency while retaining all dependencies required by the new codecs.
basics/close-account/native/pnpm-lock.yaml Regenerates the lockfile to remove Borsh and its no-longer-needed transitive dependencies.

Reviews (1): Last reviewed commit: "refactor(basics/close-account): replace ..." | Re-trigger Greptile

@dev-jodee dev-jodee left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor borsh→kit codecs in close-account. All CI green.

@amilz
amilz merged commit cffabb1 into main Aug 13, 2026
19 checks passed
@amilz
amilz deleted the refactor/DEV-838-close-account-kit-codecs branch August 13, 2026 20:56
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