feat: typed instruction construction & execution pipeline (IDL → codegen → SDK → adapters)#115
Draft
adiman9 wants to merge 5 commits into
Draft
feat: typed instruction construction & execution pipeline (IDL → codegen → SDK → adapters)#115adiman9 wants to merge 5 commits into
adiman9 wants to merge 5 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
End-to-end typed instruction construction & execution: round-trip an Anchor/Steel IDL all the way from a stack spec through codegen into a callable, type-safe TypeScript client surface that signs and broadcasts transactions via pluggable wallet adapters. The core SDK stays RPC-free; everything network-related lives behind a
WalletAdapterboundary.1. Richer IDL metadata in stack specs
arete-idlnow preserves the metadata required to build instructions, not just read state.IdlEnumVariant/IdlEnumVariantSnapshotcarryfields(named struct fields or tuple elements). Fieldless variants serialize byte-identically to older snapshots (skip_serializing_if = "Vec::is_empty"), so existing stack specs don't churn.global:{name}is now snake_cased before hashing, matching Anchor's runtime discriminator derivation.pdas!macro (new inarete-macros) lets a stack declare program-derived addresses the IDL doesn't embed (e.g. Steel programs). ORE declarestreasury,config,board,miner,automation.arete-macros/src/stream_spec/idl_spec.rs,writer.rs,versioned.rs) andinterpreterversioned AST carry the new shapes through to codegen.stacks/ore/.arete/OreStream.stack.jsonregenerated from the richer snapshot.2. Typed instruction runtime in the TypeScript SDK
The core SDK gains a data-driven instruction runtime. No imperative serialization code is shipped — handlers are metadata consumed by a factory.
instructions/executor.ts—createInstructionHandlerfactory +executeInstruction/buildInstruction. Handlers expose orderedaccounts,argNames,errors, and a genericbuild; the executor resolves accounts, serializes args, and broadcasts via theWalletAdapter.instructions/serializer.ts— Borsh arg serialization driven by anArgSchema[](primitives, structs, enums, arrays, options).instructions/seed-serializer.ts+pda.ts+pda-dsl.ts— canonical PDA seed serialization and a small DSL (literal,account,arg,bytes,pda).instructions/account-resolver.ts— categorizes accounts (signer,pda,known,userProvided) and resolves them in order, withvalidateAccountResolution.instructions/error-parser.ts— parses program errors against IDL error metadata; throws typedInstructionErrorcarryingprogramError.wallet/types.ts— theWalletAdapterboundary,BuiltInstruction/BuiltAccountMeta,SendOptions,ConfirmationLevel,SendResult. Core is RPC-free by design.client.ts—Arete.connect(stack, { wallet })exposes a typedclient.instructions.<name>(params)surface (with.build()for batching) andclient.transaction([...]). Default wallet is overridable per call. Removed the oldinstructions/confirmation.ts(now adapter-owned).react/—useInstructionMutationhook (idle/pending/success/error, signature, reset) and provider/stack wiring.client.test.ts,instructions.test.ts,seed-serializer.test.ts(~760 new test lines).3. Reference wallet adapters
Two adapter packages implementing
WalletAdapter, owning blockhash, message compilation, signing, send, and confirmation.@usearete/adapter-web3js—@solana/web3.jsv0-message-based adapter.createKeypairWalletAdapterfor Node/bots andcreateWalletAdapterfor browser/wallet-standard signers. Supports batching viaclient.transaction([...]).@usearete/adapter-kit—@solana/kit(functional web3.js successor) adapter usingcreateSolanaRpc/createSolanaRpcSubscriptions.4. Typed instruction handler codegen
interpreter/src/typescript_instructions.rs(new, ~1970 lines) consumesInstructionDef[]from a stack spec and emits data-driven handlers targeting the corecreateInstructionHandlerfactory.Params/Errortypes and a handler const (discriminator, ordered accounts with PDA configs, arg schema, error table).<Stack><Program>ProgramError) for multi-program stacks.cli/src/commands/sdk.rssoa4 sdkemits the handlers.interpreter/tests/golden/ore-close-instruction.expected.ts— shows the generatedoreCloseInstructionhandler (board/treasury PDAs, system program,OreCloseParams).5. Ore stack update
stacks/ore/.arete/OreStream.stack.jsonrefreshed with the richer instruction/PDA metadata that the rest of the PR consumes.Architecture notes
BuiltInstructionobjects; adapters own all network semantics. This keeps the core testable and library-agnostic.signer/pda/known/userProvideddrive resolution; user-provided accounts are passed alongside args in a single flat params object.client.instructions.<name>.build(...)returns aBuiltInstruction;client.transaction([...])composes them into one transaction.Known follow-ups
round = ["round", round_id]PDA is intentionally omitted from the orepdas!block — some ORE instructions derive it from a cross-account field (board.round_id), which needs per-instruction seed binding (not yet expressible). Codegen emits a warning and falls back touserProvidedfor these.Test plan
cargo test -p interpreter(golden:ore-close-instruction.expected.ts)cargo test -p arete-idlpnpm --filter @usearete/sdk test(client.test.ts,instructions.test.ts,seed-serializer.test.ts)pnpm --filter @usearete/adapter-web3js build/@usearete/adapter-kit builda4 sdkand confirm handlers match the golden fixture