@prb/effect-solana 1.0.0-beta.3 → 1.0.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/README.md +48 -3
  2. package/dist/balance/index.js.map +1 -1
  3. package/dist/balance/service.d.ts +2 -2
  4. package/dist/balance/service.d.ts.map +1 -1
  5. package/dist/balance/service.js +3 -3
  6. package/dist/balance/service.js.map +1 -1
  7. package/dist/constants/index.js.map +1 -1
  8. package/dist/core/errors/account.js.map +1 -1
  9. package/dist/core/errors/index.js.map +1 -1
  10. package/dist/core/errors/predicates.js.map +1 -1
  11. package/dist/core/errors/rpc.js.map +1 -1
  12. package/dist/core/errors/transaction.js.map +1 -1
  13. package/dist/core/errors/wallet.js.map +1 -1
  14. package/dist/core/index.js.map +1 -1
  15. package/dist/index.js.map +1 -1
  16. package/dist/internal/index.js.map +1 -1
  17. package/dist/internal/kit-effect.d.ts +2 -2
  18. package/dist/internal/kit-effect.d.ts.map +1 -1
  19. package/dist/internal/kit-effect.js +1 -1
  20. package/dist/internal/kit-effect.js.map +1 -1
  21. package/dist/pda/index.js.map +1 -1
  22. package/dist/pda/service.js +1 -1
  23. package/dist/pda/service.js.map +1 -1
  24. package/dist/pda/types.js.map +1 -1
  25. package/dist/presets/index.js.map +1 -1
  26. package/dist/presets/layers.d.ts +10 -10
  27. package/dist/presets/layers.d.ts.map +1 -1
  28. package/dist/presets/layers.js +8 -8
  29. package/dist/presets/layers.js.map +1 -1
  30. package/dist/program/index.d.ts +1 -0
  31. package/dist/program/index.d.ts.map +1 -1
  32. package/dist/program/index.js +1 -0
  33. package/dist/program/index.js.map +1 -1
  34. package/dist/program/internal/anchor-helpers.d.ts +20 -0
  35. package/dist/program/internal/anchor-helpers.d.ts.map +1 -0
  36. package/dist/program/internal/anchor-helpers.js +64 -0
  37. package/dist/program/internal/anchor-helpers.js.map +1 -0
  38. package/dist/program/reader.d.ts +19 -0
  39. package/dist/program/reader.d.ts.map +1 -0
  40. package/dist/program/reader.js +288 -0
  41. package/dist/program/reader.js.map +1 -0
  42. package/dist/program/service.d.ts +1 -1
  43. package/dist/program/service.d.ts.map +1 -1
  44. package/dist/program/service.js +18 -37
  45. package/dist/program/service.js.map +1 -1
  46. package/dist/program/types.d.ts +48 -13
  47. package/dist/program/types.d.ts.map +1 -1
  48. package/dist/program/types.js +27 -28
  49. package/dist/program/types.js.map +1 -1
  50. package/dist/react-hooks/index.js.map +1 -1
  51. package/dist/react-hooks/internal/error.js.map +1 -1
  52. package/dist/react-hooks/internal/is-dev.js.map +1 -1
  53. package/dist/react-hooks/internal/runtime.js.map +1 -1
  54. package/dist/react-hooks/internal/scoped-run.js.map +1 -1
  55. package/dist/react-hooks/internal/stable.js.map +1 -1
  56. package/dist/react-hooks/primitives/use-effect-memo-factory.js.map +1 -1
  57. package/dist/react-hooks/primitives/use-effect.js.map +1 -1
  58. package/dist/react-hooks/primitives/use-fork-effect.js.map +1 -1
  59. package/dist/react-hooks/primitives/use-stream.js.map +1 -1
  60. package/dist/react-hooks/primitives.js.map +1 -1
  61. package/dist/react-hooks/provider.js.map +1 -1
  62. package/dist/rpc/index.js.map +1 -1
  63. package/dist/rpc/service.d.ts +2 -2
  64. package/dist/rpc/service.d.ts.map +1 -1
  65. package/dist/rpc/service.js +1 -1
  66. package/dist/rpc/service.js.map +1 -1
  67. package/dist/signer/index.js.map +1 -1
  68. package/dist/signer/service.d.ts +1 -1
  69. package/dist/signer/service.d.ts.map +1 -1
  70. package/dist/signer/service.js +2 -2
  71. package/dist/signer/service.js.map +1 -1
  72. package/dist/telemetry/index.js.map +1 -1
  73. package/dist/telemetry/logger.js.map +1 -1
  74. package/dist/telemetry/tracer.d.ts +3 -0
  75. package/dist/telemetry/tracer.d.ts.map +1 -1
  76. package/dist/telemetry/tracer.js +3 -0
  77. package/dist/telemetry/tracer.js.map +1 -1
  78. package/dist/testing-kit/_fixtures/addresses.js.map +1 -1
  79. package/dist/testing-kit/helpers.js.map +1 -1
  80. package/dist/testing-kit/index.js.map +1 -1
  81. package/dist/testing-kit/mock-balance-service.d.ts +2 -2
  82. package/dist/testing-kit/mock-balance-service.d.ts.map +1 -1
  83. package/dist/testing-kit/mock-balance-service.js +1 -1
  84. package/dist/testing-kit/mock-balance-service.js.map +1 -1
  85. package/dist/testing-kit/mock-pda-service.d.ts +2 -2
  86. package/dist/testing-kit/mock-pda-service.d.ts.map +1 -1
  87. package/dist/testing-kit/mock-pda-service.js +1 -1
  88. package/dist/testing-kit/mock-pda-service.js.map +1 -1
  89. package/dist/testing-kit/mock-rpc-service.d.ts +3 -3
  90. package/dist/testing-kit/mock-rpc-service.d.ts.map +1 -1
  91. package/dist/testing-kit/mock-rpc-service.js +2 -2
  92. package/dist/testing-kit/mock-rpc-service.js.map +1 -1
  93. package/dist/testing-kit/mock-signer-service.d.ts +3 -3
  94. package/dist/testing-kit/mock-signer-service.d.ts.map +1 -1
  95. package/dist/testing-kit/mock-signer-service.js +2 -2
  96. package/dist/testing-kit/mock-signer-service.js.map +1 -1
  97. package/dist/testing-kit/mock-token-service.d.ts +3 -3
  98. package/dist/testing-kit/mock-token-service.d.ts.map +1 -1
  99. package/dist/testing-kit/mock-token-service.js +1 -1
  100. package/dist/testing-kit/mock-token-service.js.map +1 -1
  101. package/dist/testing-kit/mock-transaction-service.d.ts +7 -8
  102. package/dist/testing-kit/mock-transaction-service.d.ts.map +1 -1
  103. package/dist/testing-kit/mock-transaction-service.js +1 -1
  104. package/dist/testing-kit/mock-transaction-service.js.map +1 -1
  105. package/dist/testing-kit/test-layer.d.ts +11 -7
  106. package/dist/testing-kit/test-layer.d.ts.map +1 -1
  107. package/dist/testing-kit/test-layer.js +12 -5
  108. package/dist/testing-kit/test-layer.js.map +1 -1
  109. package/dist/token/index.js.map +1 -1
  110. package/dist/token/service.d.ts +2 -2
  111. package/dist/token/service.d.ts.map +1 -1
  112. package/dist/token/service.js +4 -4
  113. package/dist/token/service.js.map +1 -1
  114. package/dist/tx/index.js.map +1 -1
  115. package/dist/tx/service.d.ts +9 -10
  116. package/dist/tx/service.d.ts.map +1 -1
  117. package/dist/tx/service.js +4 -4
  118. package/dist/tx/service.js.map +1 -1
  119. package/dist/tx/types.d.ts +2 -0
  120. package/dist/tx/types.d.ts.map +1 -1
  121. package/dist/tx/types.js.map +1 -1
  122. package/dist/types/index.js.map +1 -1
  123. package/dist/web3.js/_fixtures.js.map +1 -1
  124. package/dist/web3.js/index.js.map +1 -1
  125. package/dist/web3.js/layers.d.ts +9 -9
  126. package/dist/web3.js/layers.d.ts.map +1 -1
  127. package/dist/web3.js/layers.js +1 -1
  128. package/dist/web3.js/layers.js.map +1 -1
  129. package/dist/web3.js/legacy-signer.d.ts +1 -1
  130. package/dist/web3.js/legacy-signer.d.ts.map +1 -1
  131. package/dist/web3.js/legacy-signer.js +3 -3
  132. package/dist/web3.js/legacy-signer.js.map +1 -1
  133. package/dist/web3.js/transaction-bridge.js.map +1 -1
  134. package/dist/web3.js/types.js.map +1 -1
  135. package/package.json +38 -22
@@ -0,0 +1,288 @@
1
+ import { Program } from "@coral-xyz/anchor";
2
+ import { Buffer } from "buffer";
3
+ import { Cause, Context, Effect, Exit, Layer, Option, Runtime } from "effect";
4
+ import { WalletNotConnectedError } from "#src/core/errors/index.js";
5
+ import { RpcService } from "#src/rpc/index.js";
6
+ import { SignerService } from "#src/signer/index.js";
7
+ import { SpanNames } from "#src/telemetry/index.js";
8
+ import { makeProgramConnectionShim, toAnchorAccounts, toAnchorArgs, toPublicKey, } from "./internal/anchor-helpers.js";
9
+ import { InstructionNotFoundError, ProgramCreationError, ProgramReadError, ViewNotSupportedError, } from "./types.js";
10
+ function mutateTransactionForSimulation(tx, feePayer, blockhash, signers) {
11
+ if ("feePayer" in tx) {
12
+ tx.feePayer = feePayer;
13
+ }
14
+ if ("recentBlockhash" in tx) {
15
+ tx.recentBlockhash = blockhash;
16
+ }
17
+ if (signers && signers.length > 0 && "partialSign" in tx) {
18
+ tx.partialSign(...signers);
19
+ }
20
+ }
21
+ function toBase64WireTransaction(tx) {
22
+ const wireTransaction = "version" in tx
23
+ ? tx.serialize()
24
+ : tx.serialize({
25
+ requireAllSignatures: false,
26
+ verifySignatures: false,
27
+ });
28
+ return Buffer.from(wireTransaction).toString("base64");
29
+ }
30
+ function hasWritableAccounts(accounts) {
31
+ return accounts.some((account) => {
32
+ if (typeof account !== "object" || account === null) {
33
+ return false;
34
+ }
35
+ if ("accounts" in account && Array.isArray(account.accounts)) {
36
+ return hasWritableAccounts(account.accounts);
37
+ }
38
+ if ("writable" in account && account.writable === true) {
39
+ return true;
40
+ }
41
+ return "isMut" in account && account.isMut === true;
42
+ });
43
+ }
44
+ function getIdlName(program) {
45
+ return program.idl.metadata?.name ?? "unknown";
46
+ }
47
+ function resolveProgramIdAttribute(programId, idlAddress) {
48
+ if (programId) {
49
+ return String(programId);
50
+ }
51
+ if (typeof idlAddress === "string") {
52
+ return idlAddress;
53
+ }
54
+ return "unknown";
55
+ }
56
+ function makeInstructionNotFoundError(method, idlName) {
57
+ return new InstructionNotFoundError({
58
+ idlName,
59
+ message: `Instruction "${method}" not found in IDL "${idlName}"`,
60
+ method,
61
+ });
62
+ }
63
+ function makeViewNotSupportedError(method, idlName) {
64
+ return new ViewNotSupportedError({
65
+ idlName,
66
+ message: `Method "${method}" in IDL "${idlName}" does not support .view()`,
67
+ method,
68
+ });
69
+ }
70
+ function makeProgramReadError(method, cause) {
71
+ return new ProgramReadError({
72
+ cause,
73
+ message: `Failed to read "${method}" via .view()`,
74
+ method,
75
+ });
76
+ }
77
+ class SignerSimulationDefectError extends Error {
78
+ defect;
79
+ constructor(defect) {
80
+ super("Signer service defect during ProgramReader simulation");
81
+ this.name = "SignerSimulationDefectError";
82
+ this.defect = defect;
83
+ }
84
+ }
85
+ function isWalletNotConnectedError(error) {
86
+ return ((typeof error === "object" &&
87
+ error !== null &&
88
+ error._tag === "WalletNotConnectedError") ||
89
+ error instanceof WalletNotConnectedError);
90
+ }
91
+ function getTransactionBlockhash(tx) {
92
+ if ("recentBlockhash" in tx &&
93
+ typeof tx.recentBlockhash === "string" &&
94
+ tx.recentBlockhash.length > 0) {
95
+ return tx.recentBlockhash;
96
+ }
97
+ if ("message" in tx &&
98
+ typeof tx.message?.recentBlockhash === "string") {
99
+ return tx.message.recentBlockhash;
100
+ }
101
+ return undefined;
102
+ }
103
+ function toWeb3SimulationResponse(value) {
104
+ const returnData = value.returnData
105
+ ? {
106
+ data: [value.returnData.data[0], "base64"],
107
+ programId: String(value.returnData.programId),
108
+ }
109
+ : null;
110
+ return {
111
+ logs: value.logs ?? null,
112
+ returnData,
113
+ unitsConsumed: value.unitsConsumed === undefined ? undefined : Number(value.unitsConsumed),
114
+ };
115
+ }
116
+ function formatSimulationError(error) {
117
+ const MAX_ERROR_MESSAGE_LENGTH = 500;
118
+ if (typeof error === "string") {
119
+ return error.slice(0, MAX_ERROR_MESSAGE_LENGTH);
120
+ }
121
+ if (error instanceof Error) {
122
+ return error.message.slice(0, MAX_ERROR_MESSAGE_LENGTH);
123
+ }
124
+ try {
125
+ return JSON.stringify(error, null, 2).slice(0, MAX_ERROR_MESSAGE_LENGTH);
126
+ }
127
+ catch {
128
+ return String(error).slice(0, MAX_ERROR_MESSAGE_LENGTH);
129
+ }
130
+ }
131
+ function normalizeSimulationCommitment(commitment) {
132
+ if (!commitment) {
133
+ return undefined;
134
+ }
135
+ switch (commitment) {
136
+ case "processed":
137
+ case "confirmed":
138
+ case "finalized":
139
+ return commitment;
140
+ case "recent":
141
+ return "processed";
142
+ case "single":
143
+ case "singleGossip":
144
+ return "confirmed";
145
+ case "max":
146
+ case "root":
147
+ return "finalized";
148
+ default:
149
+ return undefined;
150
+ }
151
+ }
152
+ function normalizeMethodName(name) {
153
+ return name.replaceAll("_", "").toLowerCase();
154
+ }
155
+ function resolveViewBuilder(program, params) {
156
+ return Effect.gen(function* () {
157
+ const { method, args, accounts } = params;
158
+ const idlName = getIdlName(program);
159
+ const methodFn = program.methods[method];
160
+ if (!methodFn || typeof methodFn !== "function") {
161
+ return yield* Effect.fail(makeInstructionNotFoundError(method, idlName));
162
+ }
163
+ const normalizedMethod = normalizeMethodName(method);
164
+ const exactInstruction = program.idl.instructions.find((instruction) => instruction.name === method);
165
+ const normalizedMatches = program.idl.instructions.filter((instruction) => normalizeMethodName(instruction.name) === normalizedMethod);
166
+ const idlInstruction = exactInstruction ?? (normalizedMatches.length === 1 ? normalizedMatches[0] : undefined);
167
+ if (idlInstruction) {
168
+ const hasWritableAccount = hasWritableAccounts(idlInstruction.accounts);
169
+ const hasReturnType = Boolean(idlInstruction.returns);
170
+ if (hasWritableAccount) {
171
+ return yield* Effect.fail(makeViewNotSupportedError(method, idlName));
172
+ }
173
+ if (!hasReturnType) {
174
+ yield* Effect.logWarning(`ProgramReader found instruction "${idlInstruction.name}" in "${idlName}" without IDL return metadata. Skipping return-type pre-validation and deferring to Anchor runtime.`);
175
+ }
176
+ }
177
+ else if (normalizedMatches.length > 1) {
178
+ yield* Effect.logWarning(`ProgramReader found ambiguous normalized IDL matches for method "${method}" in "${idlName}". Skipping pre-validation and deferring to Anchor runtime.`);
179
+ }
180
+ else {
181
+ yield* Effect.logWarning(`ProgramReader could not match method "${method}" to an IDL instruction in "${idlName}". Skipping pre-validation and deferring to Anchor runtime.`);
182
+ }
183
+ const anchorArgs = toAnchorArgs(args);
184
+ const anchorAccounts = toAnchorAccounts(accounts);
185
+ const builder = methodFn(...anchorArgs);
186
+ const withAccounts = builder.accountsPartial(anchorAccounts);
187
+ if (!withAccounts || typeof withAccounts.view !== "function") {
188
+ return yield* Effect.fail(makeViewNotSupportedError(method, idlName));
189
+ }
190
+ return withAccounts;
191
+ });
192
+ }
193
+ export class ProgramReader extends Context.Tag("esolana/ProgramReader")() {
194
+ }
195
+ export const ProgramReaderLive = Layer.effect(ProgramReader, Effect.gen(function* () {
196
+ const rpcService = yield* RpcService;
197
+ const signerService = yield* SignerService;
198
+ const runtime = yield* Effect.runtime();
199
+ const service = {
200
+ createProgram: (params) => Effect.gen(function* () {
201
+ const { idl, programId } = params;
202
+ const rpc = yield* rpcService.getRpc();
203
+ const initialWalletAddress = yield* signerService.getAddress();
204
+ const resolveSimulationFeePayer = async () => {
205
+ const exit = await Runtime.runPromiseExit(runtime, signerService.getAddress());
206
+ if (Exit.isSuccess(exit)) {
207
+ return toPublicKey(exit.value);
208
+ }
209
+ const failure = Cause.failureOption(exit.cause);
210
+ if (Option.isSome(failure)) {
211
+ throw failure.value;
212
+ }
213
+ throw new SignerSimulationDefectError(Cause.squash(exit.cause));
214
+ };
215
+ const idlWithAddress = programId ? { ...idl, address: programId } : idl;
216
+ return yield* Effect.try({
217
+ catch: (error) => new ProgramCreationError({
218
+ cause: error,
219
+ message: "Failed to create Anchor program",
220
+ }),
221
+ try: () => new Program(idlWithAddress, {
222
+ connection: makeProgramConnectionShim(rpc, "ProgramReader"),
223
+ publicKey: toPublicKey(initialWalletAddress),
224
+ simulate: async (tx, signers, commitment) => {
225
+ const feePayer = await resolveSimulationFeePayer();
226
+ const transactionBlockhash = getTransactionBlockhash(tx) ??
227
+ (await rpc.getLatestBlockhash().send()).value.blockhash;
228
+ mutateTransactionForSimulation(tx, feePayer, transactionBlockhash, signers);
229
+ const base64WireTransaction = toBase64WireTransaction(tx);
230
+ const normalizedCommitment = normalizeSimulationCommitment(commitment);
231
+ const simulation = await rpc
232
+ .simulateTransaction(base64WireTransaction, {
233
+ ...(normalizedCommitment ? { commitment: normalizedCommitment } : {}),
234
+ encoding: "base64",
235
+ })
236
+ .send();
237
+ if (simulation.value.err) {
238
+ throw new Error(`View simulation failed: ${formatSimulationError(simulation.value.err)}`, { cause: simulation.value.err });
239
+ }
240
+ return toWeb3SimulationResponse(simulation.value);
241
+ },
242
+ }),
243
+ });
244
+ }).pipe(Effect.withSpan(SpanNames.PROGRAM_CREATE_FOR_READ, {
245
+ attributes: {
246
+ programId: resolveProgramIdAttribute(params.programId, params.idl.address),
247
+ },
248
+ })),
249
+ view: (params) => Effect.gen(function* () {
250
+ const { idl, method, args, accounts, programId } = params;
251
+ const program = yield* service.createProgram({ idl, programId });
252
+ return yield* service.viewWithProgram(program, { accounts, args, method });
253
+ }).pipe(Effect.withSpan(SpanNames.PROGRAM_VIEW, {
254
+ attributes: {
255
+ method: params.method,
256
+ programId: resolveProgramIdAttribute(params.programId, params.idl.address),
257
+ },
258
+ })),
259
+ viewWithProgram: (program, params) => Effect.gen(function* () {
260
+ const { method } = params;
261
+ const idlName = getIdlName(program);
262
+ const withAccounts = yield* resolveViewBuilder(program, params);
263
+ return yield* Effect.tryPromise({
264
+ catch: (error) => {
265
+ if (error instanceof SignerSimulationDefectError) {
266
+ throw error.defect;
267
+ }
268
+ if (isWalletNotConnectedError(error)) {
269
+ return error;
270
+ }
271
+ if (error instanceof Error &&
272
+ error.message.includes("Method does not support views")) {
273
+ return makeViewNotSupportedError(method, idlName);
274
+ }
275
+ return makeProgramReadError(method, error);
276
+ },
277
+ try: () => withAccounts.view(),
278
+ });
279
+ }).pipe(Effect.withSpan(SpanNames.PROGRAM_VIEW_WITH_PROGRAM, {
280
+ attributes: {
281
+ method: params.method,
282
+ programId: resolveProgramIdAttribute(undefined, program.idl.address),
283
+ },
284
+ })),
285
+ };
286
+ return ProgramReader.of(service);
287
+ }));
288
+ //# sourceMappingURL=reader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reader.js","sourceRoot":"","sources":["../../src/program/reader.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAa5C,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAC9E,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB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esContent":["/**\n * ProgramReader - Effect-based Anchor program read service using `.view()`.\n *\n * Provides first-class signer-path `.view()` support for Anchor programs.\n * This is the read counterpart to ProgramWriter (instruction building).\n *\n * `.view()` requires a connected wallet (signer) because Anchor constructs\n * a transaction internally and simulates it on behalf of the signer.\n *\n * @module program/reader\n */\n\nimport type { Idl } from \"@coral-xyz/anchor\";\nimport { Program } from \"@coral-xyz/anchor\";\nimport type { Address } from \"@solana/addresses\";\nimport type { Rpc, SolanaRpcApi } from \"@solana/kit\";\nimport type { Commitment } from \"@solana/rpc-types\";\nimport type { Base64EncodedWireTransaction } from \"@solana/transactions\";\nimport type {\n Signer as AnchorSigner,\n PublicKey,\n SimulatedTransactionResponse,\n Transaction,\n TransactionReturnData,\n VersionedTransaction,\n} from \"@solana/web3.js\";\nimport { Buffer } from \"buffer\";\nimport { Cause, Context, Effect, Exit, Layer, Option, Runtime } from \"effect\";\nimport { WalletNotConnectedError } from \"#src/core/errors/index.js\";\nimport { RpcService } from \"#src/rpc/index.js\";\nimport { SignerService } from \"#src/signer/index.js\";\nimport { SpanNames } from \"#src/telemetry/index.js\";\nimport {\n makeProgramConnectionShim,\n toAnchorAccounts,\n toAnchorArgs,\n toPublicKey,\n} from \"./internal/anchor-helpers.js\";\nimport type { CreateProgramParams, ViewParams } from \"./types.js\";\nimport {\n InstructionNotFoundError,\n ProgramCreationError,\n ProgramReadError,\n ViewNotSupportedError,\n} from \"./types.js\";\n\n// =============================================================================\n// Helpers\n// =============================================================================\n\nfunction mutateTransactionForSimulation(\n tx: Transaction | VersionedTransaction,\n feePayer: PublicKey,\n blockhash: string,\n signers?: readonly AnchorSigner[]\n): void {\n if (\"feePayer\" in tx) {\n tx.feePayer = feePayer;\n }\n if (\"recentBlockhash\" in tx) {\n tx.recentBlockhash = blockhash;\n }\n if (signers && signers.length > 0 && \"partialSign\" in tx) {\n tx.partialSign(...signers);\n }\n}\n\nfunction toBase64WireTransaction(\n tx: Transaction | VersionedTransaction\n): Base64EncodedWireTransaction {\n const wireTransaction =\n \"version\" in tx\n ? tx.serialize()\n : tx.serialize({\n requireAllSignatures: false,\n verifySignatures: false,\n });\n\n return Buffer.from(wireTransaction).toString(\"base64\") as Base64EncodedWireTransaction;\n}\n\nfunction hasWritableAccounts(accounts: readonly unknown[]): boolean {\n // Support both modern Anchor IDL (`writable`) and legacy IDL (`isMut`) shapes.\n // Nested account groups appear for composite account declarations.\n return accounts.some((account) => {\n if (typeof account !== \"object\" || account === null) {\n return false;\n }\n\n if (\"accounts\" in account && Array.isArray(account.accounts)) {\n return hasWritableAccounts(account.accounts);\n }\n\n if (\"writable\" in account && account.writable === true) {\n return true;\n }\n\n return \"isMut\" in account && account.isMut === true;\n });\n}\n\nfunction getIdlName<T extends Idl>(program: Program<T>): string {\n return program.idl.metadata?.name ?? \"unknown\";\n}\n\nfunction resolveProgramIdAttribute(programId?: Address, idlAddress?: unknown): string {\n if (programId) {\n return String(programId);\n }\n if (typeof idlAddress === \"string\") {\n return idlAddress;\n }\n return \"unknown\";\n}\n\nfunction makeInstructionNotFoundError(method: string, idlName: string): InstructionNotFoundError {\n return new InstructionNotFoundError({\n idlName,\n message: `Instruction \"${method}\" not found in IDL \"${idlName}\"`,\n method,\n });\n}\n\nfunction makeViewNotSupportedError(method: string, idlName: string): ViewNotSupportedError {\n return new ViewNotSupportedError({\n idlName,\n message: `Method \"${method}\" in IDL \"${idlName}\" does not support .view()`,\n method,\n });\n}\n\nfunction makeProgramReadError(method: string, cause: unknown): ProgramReadError {\n return new ProgramReadError({\n cause,\n message: `Failed to read \"${method}\" via .view()`,\n method,\n });\n}\n\nclass SignerSimulationDefectError extends Error {\n readonly defect: unknown;\n\n constructor(defect: unknown) {\n super(\"Signer service defect during ProgramReader simulation\");\n this.name = \"SignerSimulationDefectError\";\n this.defect = defect;\n }\n}\n\nfunction isWalletNotConnectedError(error: unknown): error is WalletNotConnectedError {\n return (\n (typeof error === \"object\" &&\n error !== null &&\n (error as { readonly _tag?: unknown })._tag === \"WalletNotConnectedError\") ||\n error instanceof WalletNotConnectedError\n );\n}\n\nfunction getTransactionBlockhash(tx: Transaction | VersionedTransaction): string | undefined {\n // Supports @solana/web3.js 1.95.x transaction shapes used by Anchor 0.31.x.\n // Re-check these guards if web3.js changes message/blockhash field layouts.\n if (\n \"recentBlockhash\" in tx &&\n typeof tx.recentBlockhash === \"string\" &&\n tx.recentBlockhash.length > 0\n ) {\n return tx.recentBlockhash;\n }\n\n if (\n \"message\" in tx &&\n typeof (\n tx as {\n readonly message?: { readonly recentBlockhash?: unknown };\n }\n ).message?.recentBlockhash === \"string\"\n ) {\n return (\n tx as {\n readonly message: { readonly recentBlockhash: string };\n }\n ).message.recentBlockhash;\n }\n\n return undefined;\n}\n\nfunction toWeb3SimulationResponse(\n value: Awaited<ReturnType<ReturnType<Rpc<SolanaRpcApi>[\"simulateTransaction\"]>[\"send\"]>>[\"value\"]\n): Omit<SimulatedTransactionResponse, \"err\"> {\n // ProgramReader requests simulation with { encoding: \"base64\" } only.\n // We map only the response fields Anchor currently reads (logs/returnData) and\n // normalize unitsConsumed to web3.js' number shape.\n const returnData: TransactionReturnData | null = value.returnData\n ? {\n data: [value.returnData.data[0], \"base64\"] as [string, \"base64\"],\n programId: String(value.returnData.programId),\n }\n : null;\n\n return {\n logs: value.logs ?? null,\n returnData,\n unitsConsumed: value.unitsConsumed === undefined ? undefined : Number(value.unitsConsumed),\n };\n}\n\nfunction formatSimulationError(error: unknown): string {\n const MAX_ERROR_MESSAGE_LENGTH = 500;\n\n if (typeof error === \"string\") {\n return error.slice(0, MAX_ERROR_MESSAGE_LENGTH);\n }\n\n if (error instanceof Error) {\n return error.message.slice(0, MAX_ERROR_MESSAGE_LENGTH);\n }\n\n try {\n return JSON.stringify(error, null, 2).slice(0, MAX_ERROR_MESSAGE_LENGTH);\n } catch {\n return String(error).slice(0, MAX_ERROR_MESSAGE_LENGTH);\n }\n}\n\nfunction normalizeSimulationCommitment(commitment?: string): Commitment | undefined {\n if (!commitment) {\n return undefined;\n }\n\n switch (commitment) {\n case \"processed\":\n case \"confirmed\":\n case \"finalized\":\n return commitment;\n case \"recent\":\n return \"processed\";\n case \"single\":\n case \"singleGossip\":\n return \"confirmed\";\n case \"max\":\n case \"root\":\n return \"finalized\";\n default:\n return undefined;\n }\n}\n\nfunction normalizeMethodName(name: string): string {\n // Keep normalization intentionally simple for snake_case vs camelCase IDL/method parity.\n // Normalization may produce collisions; ambiguity is handled by skipping pre-validation.\n return name.replaceAll(\"_\", \"\").toLowerCase();\n}\n\nfunction resolveViewBuilder<T extends Idl>(\n program: Program<T>,\n params: Pick<ViewParams, \"method\" | \"args\" | \"accounts\">\n): Effect.Effect<\n { view: () => Promise<unknown> },\n InstructionNotFoundError | ViewNotSupportedError\n> {\n return Effect.gen(function* () {\n const { method, args, accounts } = params;\n const idlName = getIdlName(program);\n\n const methodFn = (program.methods as Record<string, unknown>)[method];\n if (!methodFn || typeof methodFn !== \"function\") {\n return yield* Effect.fail(makeInstructionNotFoundError(method, idlName));\n }\n\n const normalizedMethod = normalizeMethodName(method);\n const exactInstruction = program.idl.instructions.find(\n (instruction) => instruction.name === method\n );\n const normalizedMatches = program.idl.instructions.filter(\n (instruction) => normalizeMethodName(instruction.name) === normalizedMethod\n );\n const idlInstruction =\n exactInstruction ?? (normalizedMatches.length === 1 ? normalizedMatches[0] : undefined);\n\n // Keep pre-validation when we can confidently match an IDL instruction.\n // If no match is found, defer to Anchor's runtime .view() support checks.\n if (idlInstruction) {\n const hasWritableAccount = hasWritableAccounts(idlInstruction.accounts);\n const hasReturnType = Boolean(idlInstruction.returns);\n if (hasWritableAccount) {\n return yield* Effect.fail(makeViewNotSupportedError(method, idlName));\n }\n if (!hasReturnType) {\n yield* Effect.logWarning(\n `ProgramReader found instruction \"${idlInstruction.name}\" in \"${idlName}\" without IDL return metadata. Skipping return-type pre-validation and deferring to Anchor runtime.`\n );\n }\n } else if (normalizedMatches.length > 1) {\n yield* Effect.logWarning(\n `ProgramReader found ambiguous normalized IDL matches for method \"${method}\" in \"${idlName}\". Skipping pre-validation and deferring to Anchor runtime.`\n );\n } else {\n yield* Effect.logWarning(\n `ProgramReader could not match method \"${method}\" to an IDL instruction in \"${idlName}\". Skipping pre-validation and deferring to Anchor runtime.`\n );\n }\n\n const anchorArgs = toAnchorArgs(args);\n const anchorAccounts = toAnchorAccounts(accounts);\n const builder = (methodFn as (...methodArgs: unknown[]) => unknown)(...anchorArgs);\n const withAccounts = (builder as { accountsPartial: (a: unknown) => unknown }).accountsPartial(\n anchorAccounts\n );\n\n if (!withAccounts || typeof (withAccounts as { view?: unknown }).view !== \"function\") {\n return yield* Effect.fail(makeViewNotSupportedError(method, idlName));\n }\n\n return withAccounts as { view: () => Promise<unknown> };\n });\n}\n\n// =============================================================================\n// Service Definition\n// =============================================================================\n\n/**\n * Shape of the ProgramReader for type inference.\n *\n * @category Services\n */\nexport type ProgramReaderShape = {\n /**\n * Create an Anchor Program instance with a signer-backed provider.\n *\n * Unlike ProgramWriter's createProgram (which uses a minimal connection-only provider),\n * this creates a provider with wallet capabilities required for `.view()`.\n */\n readonly createProgram: <T extends Idl>(\n params: CreateProgramParams<T>\n ) => Effect.Effect<Program<T>, ProgramCreationError | WalletNotConnectedError>;\n\n /**\n * Call `.view()` on an Anchor program method.\n *\n * Requires a connected wallet — Anchor uses the signer's publicKey\n * as the payer for the simulated transaction.\n */\n readonly view: (\n params: ViewParams\n ) => Effect.Effect<\n unknown,\n | ProgramCreationError\n | InstructionNotFoundError\n | ViewNotSupportedError\n | ProgramReadError\n | WalletNotConnectedError\n >;\n\n /**\n * Call `.view()` on a pre-created Program instance.\n *\n * Useful for batched reads where the program is already constructed.\n */\n readonly viewWithProgram: <T extends Idl>(\n program: Program<T>,\n params: Pick<ViewParams, \"method\" | \"args\" | \"accounts\">\n ) => Effect.Effect<\n unknown,\n InstructionNotFoundError | ViewNotSupportedError | ProgramReadError | WalletNotConnectedError\n >;\n};\n\n/**\n * Service tag for program read operations.\n *\n * @category Services\n */\nexport class ProgramReader extends Context.Tag(\"esolana/ProgramReader\")<\n ProgramReader,\n ProgramReaderShape\n>() {}\n\n// =============================================================================\n// Service Implementation\n// =============================================================================\n\n/**\n * Create a ProgramReader layer.\n *\n * Requires RpcService (connection) and SignerService (wallet) to construct\n * Anchor providers that support `.view()`.\n *\n * @category Layers\n */\nexport const ProgramReaderLive = Layer.effect(\n ProgramReader,\n Effect.gen(function* () {\n const rpcService = yield* RpcService;\n const signerService = yield* SignerService;\n const runtime = yield* Effect.runtime();\n\n const service: ProgramReaderShape = {\n createProgram: (params) =>\n Effect.gen(function* () {\n const { idl, programId } = params;\n\n const rpc = yield* rpcService.getRpc();\n const initialWalletAddress = yield* signerService.getAddress();\n const resolveSimulationFeePayer = async (): Promise<PublicKey> => {\n // Anchor invokes provider.simulate outside Effect. Use the captured runtime\n // so logger/tracer configuration remains consistent with this layer.\n const exit = await Runtime.runPromiseExit(runtime, signerService.getAddress());\n if (Exit.isSuccess(exit)) {\n return toPublicKey(exit.value);\n }\n\n const failure = Cause.failureOption(exit.cause);\n if (Option.isSome(failure)) {\n throw failure.value;\n }\n\n throw new SignerSimulationDefectError(Cause.squash(exit.cause));\n };\n\n const idlWithAddress = programId ? { ...idl, address: programId as string } : idl;\n\n return yield* Effect.try({\n catch: (error) =>\n new ProgramCreationError({\n cause: error,\n message: \"Failed to create Anchor program\",\n }),\n try: () =>\n new Program(\n idlWithAddress as Idl,\n {\n connection: makeProgramConnectionShim(rpc, \"ProgramReader\"),\n // Observed on @coral-xyz/anchor 0.31.x: provider.publicKey is read when\n // constructing simulation transactions, and this value is captured at\n // Program creation time. We intentionally keep this static and refresh the\n // effective fee payer in `simulate` for wallet-switch safety, so the two\n // addresses can diverge by design.\n publicKey: toPublicKey(initialWalletAddress),\n simulate: async (\n tx: Transaction | VersionedTransaction,\n signers?: readonly AnchorSigner[],\n commitment?: string\n ): Promise<Omit<SimulatedTransactionResponse, \"err\">> => {\n // Resolve the signer lazily on each simulation to avoid stale\n // fee payer when a pre-created Program is reused across wallet changes.\n const feePayer = await resolveSimulationFeePayer();\n const transactionBlockhash =\n getTransactionBlockhash(tx) ??\n (await rpc.getLatestBlockhash().send()).value.blockhash;\n mutateTransactionForSimulation(tx, feePayer, transactionBlockhash, signers);\n\n const base64WireTransaction = toBase64WireTransaction(tx);\n const normalizedCommitment = normalizeSimulationCommitment(commitment);\n const simulation = await rpc\n .simulateTransaction(base64WireTransaction, {\n ...(normalizedCommitment ? { commitment: normalizedCommitment } : {}),\n encoding: \"base64\",\n })\n .send();\n\n if (simulation.value.err) {\n throw new Error(\n `View simulation failed: ${formatSimulationError(simulation.value.err)}`,\n { cause: simulation.value.err }\n );\n }\n\n return toWeb3SimulationResponse(simulation.value);\n },\n } as unknown as Program[\"provider\"]\n ) as unknown as Program<typeof params.idl>,\n });\n }).pipe(\n Effect.withSpan(SpanNames.PROGRAM_CREATE_FOR_READ, {\n attributes: {\n programId: resolveProgramIdAttribute(params.programId, params.idl.address),\n },\n })\n ),\n\n view: (params) =>\n Effect.gen(function* () {\n const { idl, method, args, accounts, programId } = params;\n const program = yield* service.createProgram({ idl, programId });\n return yield* service.viewWithProgram(program, { accounts, args, method });\n }).pipe(\n Effect.withSpan(SpanNames.PROGRAM_VIEW, {\n attributes: {\n method: params.method,\n programId: resolveProgramIdAttribute(params.programId, params.idl.address),\n },\n })\n ),\n\n viewWithProgram: (program, params) =>\n Effect.gen(function* () {\n const { method } = params;\n const idlName = getIdlName(program);\n const withAccounts = yield* resolveViewBuilder(program, params);\n\n return yield* Effect.tryPromise({\n catch: (error) => {\n if (error instanceof SignerSimulationDefectError) {\n throw error.defect;\n }\n if (isWalletNotConnectedError(error)) {\n return error;\n }\n // Anchor currently surfaces this as an untyped Error message (observed on 0.31.x).\n // Re-validate this guard if Anchor changes .view() failure message semantics.\n if (\n error instanceof Error &&\n error.message.includes(\"Method does not support views\")\n ) {\n return makeViewNotSupportedError(method, idlName);\n }\n return makeProgramReadError(method, error);\n },\n try: () => withAccounts.view(),\n });\n }).pipe(\n Effect.withSpan(SpanNames.PROGRAM_VIEW_WITH_PROGRAM, {\n attributes: {\n method: params.method,\n programId: resolveProgramIdAttribute(undefined, program.idl.address),\n },\n })\n ),\n };\n\n return ProgramReader.of(service);\n })\n);\n"]}
@@ -3,7 +3,7 @@ import { Program } from "@coral-xyz/anchor";
3
3
  import type { Address } from "@solana/addresses";
4
4
  import type { Instruction } from "@solana/instructions";
5
5
  import { Context, Effect, Layer } from "effect";
6
- import { RpcService } from "../rpc/index.js";
6
+ import { RpcService } from "#src/rpc/index.js";
7
7
  import type { BuildInstructionParams, CreateProgramParams } from "./types.js";
8
8
  import { InstructionBuildError, InstructionNotFoundError, ProgramCreationError } from "./types.js";
9
9
  export type ProgramWriterShape = {
@@ -1 +1 @@
1
- {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/program/service.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAKxD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,KAAK,EAAe,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAC3F,OAAO,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAgFnG,MAAM,MAAM,kBAAkB,GAAG;IAO/B,QAAQ,CAAC,aAAa,EAAE,CAAC,CAAC,SAAS,GAAG,EACpC,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAAC,KAC3B,MAAM,CAAC,MAAM,CAAC,OAAO,C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,EACpC,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAAC,KAC3B,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,oBAAoB,CAAC,CAAC;IAerD,QAAQ,CAAC,gBAAgB,EAAE,CAAC,CAAC,SAAS,GAAG,EACvC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EACnB,MAAM,EAAE,sBAAsB,KAC3B,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,wBAAwB,GAAG,qBAAqB,CAAC,CAAC;IAYlF,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,SAAS,GAAG,EAC5B,GAAG,EAAE,CAAC,EACN,MAAM,EAAE,sBAAsB,EAC9B,SAAS,CAAC,EAAE,OAAO,KAChB,MAAM,CAAC,MAAM,CAChB,WAAW,EACX,oBAAoB,GAAG,wBAAwB,GAAG,qBAAqB,CACxE,CAAC;CACH,CAAC;;AAOF,qBAAa,aAAc,SAAQ,kBAGhC;CAAG;AAWN,eAAO,MAAM,iBAAiB,+CA2F7B,CAAC"}
@@ -1,35 +1,10 @@
1
1
  import { Program } from "@coral-xyz/anchor";
2
2
  import { AccountRole } from "@solana/instructions";
3
- import { PublicKey } from "@solana/web3.js";
4
- import BN from "bn.js";
5
3
  import { Context, Effect, Layer } from "effect";
6
- import { RpcService } from "../rpc/index.js";
7
- import { SpanNames } from "../telemetry/index.js";
4
+ import { RpcService } from "#src/rpc/index.js";
5
+ import { SpanNames } from "#src/telemetry/index.js";
6
+ import { makeProgramConnectionShim, toAnchorAccounts, toAnchorArgs, } from "./internal/anchor-helpers.js";
8
7
  import { InstructionBuildError, InstructionNotFoundError, ProgramCreationError } from "./types.js";
9
- function toPublicKey(address) {
10
- return new PublicKey(address);
11
- }
12
- function toAnchorAccounts(accounts) {
13
- const result = {};
14
- for (const [key, value] of Object.entries(accounts)) {
15
- result[key] = toPublicKey(value);
16
- }
17
- return result;
18
- }
19
- function toBN(value) {
20
- return new BN(value.toString());
21
- }
22
- function toAnchorArgs(args) {
23
- return args.map((arg) => {
24
- if (typeof arg === "bigint") {
25
- return toBN(arg);
26
- }
27
- if (typeof arg === "number" && Number.isInteger(arg)) {
28
- return toBN(arg);
29
- }
30
- return arg;
31
- });
32
- }
33
8
  function getAccountRole(isSigner, isWritable) {
34
9
  if (isSigner) {
35
10
  return isWritable ? AccountRole.WRITABLE_SIGNER : AccountRole.READONLY_SIGNER;
@@ -59,14 +34,22 @@ export const ProgramWriterLive = Layer.effect(ProgramWriter, Effect.gen(function
59
34
  const { method, args, accounts } = params;
60
35
  const methodFn = program.methods[method];
61
36
  if (!methodFn || typeof methodFn !== "function") {
62
- return yield* Effect.fail(new InstructionNotFoundError(method, program.idl.metadata?.name ?? "unknown"));
37
+ return yield* Effect.fail(new InstructionNotFoundError({
38
+ idlName: program.idl.metadata?.name ?? "unknown",
39
+ message: `Instruction "${method}" not found in IDL "${program.idl.metadata?.name ?? "unknown"}"`,
40
+ method,
41
+ }));
63
42
  }
64
43
  const anchorArgs = toAnchorArgs(args);
65
44
  const anchorAccounts = toAnchorAccounts(accounts);
66
45
  const builder = methodFn(...anchorArgs);
67
46
  const withAccounts = builder.accountsPartial(anchorAccounts);
68
47
  const anchorInstruction = yield* Effect.tryPromise({
69
- catch: (error) => new InstructionBuildError(method, error),
48
+ catch: (error) => new InstructionBuildError({
49
+ cause: error,
50
+ message: `Failed to build instruction "${method}"`,
51
+ method,
52
+ }),
70
53
  try: () => withAccounts.instruction(),
71
54
  });
72
55
  return toKitInstruction(anchorInstruction);
@@ -78,14 +61,12 @@ export const ProgramWriterLive = Layer.effect(ProgramWriter, Effect.gen(function
78
61
  const rpc = yield* rpcService.getRpc();
79
62
  const idlWithAddress = programId ? { ...idl, address: programId } : idl;
80
63
  return yield* Effect.try({
81
- catch: (error) => new ProgramCreationError(error),
64
+ catch: (error) => new ProgramCreationError({
65
+ cause: error,
66
+ message: "Failed to create Anchor program",
67
+ }),
82
68
  try: () => new Program(idlWithAddress, {
83
- connection: {
84
- getAccountInfo: (pubkey) => rpc
85
- .getAccountInfo(pubkey.toBase58(), { encoding: "base64" })
86
- .send(),
87
- getLatestBlockhash: () => rpc.getLatestBlockhash().send(),
88
- },
69
+ connection: makeProgramConnectionShim(rpc, "ProgramWriter"),
89
70
  }),
90
71
  });
91
72
  }).pipe(Effect.withSpan(SpanNames.PROGRAM_CREATE)),
@@ -1 +1 @@
1
- {"version":3,"file":"service.js","sourceRoot":"","sources":["../../src/program/service.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAG5C,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,MAAM,OAAO,CAAC;AACvB,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAErD,OAAO,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AASnG,SAAS,WAAW,CAAC,OAAyB;IAC5C,OAAO,IAAI,SAAS,CAAC,OAAO,CAAC,CAAC;AAChC,CAAC;AAKD,SAAS,gBAAgB,CAAC,QAAqB;IAC7C,MAAM,MAAM,GAA8B,EAAE,CAAC;IAC7C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QACpD,MAAM,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAKD,SAAS,IAAI,CAAC,KAAsB;IAClC,OAAO,IAAI,EAAE,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC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ClB,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;YAGlC,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC;YAGvC,MAAM,cAAc,GAAG,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,GAAG,EAAE,OAAO,EAAE,SAAmB,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;YAElF,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;gBACvB,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CACf,IAAI,oBAAoB,CAAC;oBACvB,KAAK,EAAE,KAAK;oBACZ,OAAO,EAAE,iCAAiC;iBAC3C,CAAC;gBACJ,GAAG,EAAE,GAAG,EAAE,CAGR,IAAI,OAAO,CACT,cAAqB,EACrB;oBACE,UAAU,EAAE,yBAAyB,CAAC,GAAG,EAAE,eAAe,CAAC;iBAC1B,CACK;aAC7C,CAAC,CAAC;QACL,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;KACrD,CAAC;IAEF,OAAO,aAAa,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;AACnC,CAAC,CAAC,CACH,CAAC","sourcesContent":["/**\n * ProgramWriter - Effect-based Anchor program interaction service.\n *\n * Wraps @coral-xyz/anchor Program class for clean, type-safe instruction building.\n * This mirrors how ContractWriter works for EVM ABIs.\n *\n * @module program/service\n */\n\nimport type { Idl } from \"@coral-xyz/anchor\";\nimport { Program } from \"@coral-xyz/anchor\";\nimport type { Address } from \"@solana/addresses\";\nimport type { Instruction } from \"@solana/instructions\";\nimport { AccountRole } from \"@solana/instructions\";\nimport type { TransactionInstruction } from \"@solana/web3.js\";\nimport { Context, Effect, Layer } from \"effect\";\nimport { RpcService } from \"#src/rpc/index.js\";\nimport { SpanNames } from \"#src/telemetry/index.js\";\nimport {\n makeProgramConnectionShim,\n toAnchorAccounts,\n toAnchorArgs,\n} from \"./internal/anchor-helpers.js\";\nimport type { BuildInstructionParams, CreateProgramParams } from \"./types.js\";\nimport { InstructionBuildError, InstructionNotFoundError, ProgramCreationError } from \"./types.js\";\n\n// =============================================================================\n// Helpers\n// =============================================================================\n\n/**\n * Get account role from signer and writable flags.\n */\nfunction getAccountRole(isSigner: boolean, isWritable: boolean): AccountRole {\n if (isSigner) {\n return isWritable ? AccountRole.WRITABLE_SIGNER : AccountRole.READONLY_SIGNER;\n }\n return isWritable ? AccountRole.WRITABLE : AccountRole.READONLY;\n}\n\n/**\n * Convert Anchor TransactionInstruction to Solana kit Instruction format.\n */\nfunction toKitInstruction(anchorIx: TransactionInstruction): Instruction {\n return {\n accounts: anchorIx.keys.map((key) => ({\n address: key.pubkey.toBase58() as Address,\n role: getAccountRole(key.isSigner, key.isWritable),\n })),\n data: new Uint8Array(anchorIx.data),\n programAddress: anchorIx.programId.toBase58() as Address,\n };\n}\n\n// =============================================================================\n// Service Definition\n// =============================================================================\n\n/**\n * Shape of the ProgramWriter for type inference.\n *\n * @category Services\n */\nexport type ProgramWriterShape = {\n /**\n * Create an Anchor Program instance from an IDL.\n *\n * @param params - Program creation parameters\n * @returns The Anchor Program instance\n */\n readonly createProgram: <T extends Idl>(\n params: CreateProgramParams<T>\n ) => Effect.Effect<Program<T>, ProgramCreationError>;\n\n /**\n * Build an instruction using Anchor's Program.methods API.\n *\n * This is the cleanest way to build instructions - Anchor handles:\n * - Discriminator generation from method name\n * - Account ordering from IDL\n * - Argument serialization\n * - PDA derivation (for accounts with seeds in IDL)\n *\n * @param program - The Anchor Program instance\n * @param params - Instruction building parameters\n * @returns The built instruction in Solana kit format\n */\n readonly buildInstruction: <T extends Idl>(\n program: Program<T>,\n params: BuildInstructionParams\n ) => Effect.Effect<Instruction, InstructionNotFoundError | InstructionBuildError>;\n\n /**\n * Build an instruction directly from IDL (creates program internally).\n *\n * Convenience method that combines createProgram + buildInstruction.\n *\n * @param idl - The Anchor IDL\n * @param params - Instruction building parameters\n * @param programId - Optional program ID override\n * @returns The built instruction\n */\n readonly build: <T extends Idl>(\n idl: T,\n params: BuildInstructionParams,\n programId?: Address\n ) => Effect.Effect<\n Instruction,\n ProgramCreationError | InstructionNotFoundError | InstructionBuildError\n >;\n};\n\n/**\n * Service tag for program operations (Solana equivalent of ContractWriter).\n *\n * @category Services\n */\nexport class ProgramWriter extends Context.Tag(\"esolana/ProgramWriter\")<\n ProgramWriter,\n ProgramWriterShape\n>() {}\n\n// =============================================================================\n// Service Implementation\n// =============================================================================\n\n/**\n * Create a ProgramWriter layer.\n *\n * @category Layers\n */\nexport const ProgramWriterLive = Layer.effect(\n ProgramWriter,\n Effect.gen(function* () {\n const rpcService = yield* RpcService;\n\n const service: ProgramWriterShape = {\n build: (idl, params, programId) =>\n Effect.gen(function* () {\n const program = yield* service.createProgram({ idl, programId });\n return yield* service.buildInstruction(program, params);\n }).pipe(Effect.withSpan(SpanNames.PROGRAM_BUILD)),\n\n buildInstruction: (program, params) =>\n Effect.gen(function* () {\n const { method, args, accounts } = params;\n\n // Check if method exists\n const methodFn = (program.methods as Record<string, unknown>)[method];\n if (!methodFn || typeof methodFn !== \"function\") {\n return yield* Effect.fail(\n new InstructionNotFoundError({\n idlName: program.idl.metadata?.name ?? \"unknown\",\n message: `Instruction \"${method}\" not found in IDL \"${program.idl.metadata?.name ?? \"unknown\"}\"`,\n method,\n })\n );\n }\n\n // Convert args to Anchor format (bigint -> BN)\n const anchorArgs = toAnchorArgs(args);\n\n // Convert accounts to PublicKeys\n const anchorAccounts = toAnchorAccounts(accounts);\n\n // Build instruction using Anchor's fluent API\n const builder = (methodFn as (...methodArgs: unknown[]) => unknown)(...anchorArgs);\n const withAccounts = (\n builder as { accountsPartial: (a: unknown) => unknown }\n ).accountsPartial(anchorAccounts);\n\n const anchorInstruction = yield* Effect.tryPromise({\n catch: (error) =>\n new InstructionBuildError({\n cause: error,\n message: `Failed to build instruction \"${method}\"`,\n method,\n }),\n try: () =>\n (\n withAccounts as { instruction: () => Promise<TransactionInstruction> }\n ).instruction(),\n });\n\n // Convert to Solana kit format\n return toKitInstruction(anchorInstruction);\n }).pipe(\n Effect.withSpan(SpanNames.PROGRAM_BUILD_INSTRUCTION, {\n attributes: { method: params.method },\n })\n ),\n createProgram: (params) =>\n Effect.gen(function* () {\n const { idl, programId } = params;\n\n // Create a minimal provider for Anchor (it just needs the connection for PDAs)\n const rpc = yield* rpcService.getRpc();\n\n // Build IDL with address override if provided\n const idlWithAddress = programId ? { ...idl, address: programId as string } : idl;\n\n return yield* Effect.try({\n catch: (error) =>\n new ProgramCreationError({\n cause: error,\n message: \"Failed to create Anchor program\",\n }),\n try: () =>\n // Create Program with a dummy provider (we're only using it for instruction building)\n // Anchor requires a provider but we only need the IDL parsing\n new Program(\n idlWithAddress as Idl,\n {\n connection: makeProgramConnectionShim(rpc, \"ProgramWriter\"),\n } as unknown as Program[\"provider\"]\n ) as unknown as Program<typeof params.idl>,\n });\n }).pipe(Effect.withSpan(SpanNames.PROGRAM_CREATE)),\n };\n\n return ProgramWriter.of(service);\n })\n);\n"]}
@@ -1,5 +1,6 @@
1
1
  import type { Address } from "@solana/addresses";
2
2
  import type { Instruction } from "@solana/instructions";
3
+ import { Schema } from "effect";
3
4
  export type { Idl, Program } from "@coral-xyz/anchor";
4
5
  export type AccountsMap = Record<string, Address | string>;
5
6
  export type CreateProgramParams<T extends import("@coral-xyz/anchor").Idl = import("@coral-xyz/anchor").Idl> = {
@@ -14,21 +15,55 @@ export type BuildInstructionParams<TArgs extends readonly unknown[] = readonly u
14
15
  export type BuildInstructionResult = {
15
16
  readonly instruction: Instruction;
16
17
  };
17
- export declare class InstructionNotFoundError extends Error {
18
- readonly _tag = "InstructionNotFoundError";
18
+ export type ViewParams<TArgs extends readonly unknown[] = readonly unknown[]> = {
19
+ readonly idl: import("@coral-xyz/anchor").Idl;
19
20
  readonly method: string;
20
- readonly idlName: string;
21
- constructor(method: string, idlName: string);
21
+ readonly args: TArgs;
22
+ readonly accounts: AccountsMap;
23
+ readonly programId?: Address;
24
+ };
25
+ declare const InstructionNotFoundError_base: Schema.TaggedErrorClass<InstructionNotFoundError, "InstructionNotFoundError", {
26
+ readonly _tag: Schema.tag<"InstructionNotFoundError">;
27
+ } & {
28
+ idlName: typeof Schema.String;
29
+ message: typeof Schema.String;
30
+ method: typeof Schema.String;
31
+ }>;
32
+ export declare class InstructionNotFoundError extends InstructionNotFoundError_base {
22
33
  }
23
- export declare class ProgramCreationError extends Error {
24
- readonly _tag = "ProgramCreationError";
25
- readonly cause: unknown;
26
- constructor(cause: unknown, message?: string);
34
+ declare const ProgramCreationError_base: Schema.TaggedErrorClass<ProgramCreationError, "ProgramCreationError", {
35
+ readonly _tag: Schema.tag<"ProgramCreationError">;
36
+ } & {
37
+ cause: Schema.optional<typeof Schema.Unknown>;
38
+ message: typeof Schema.String;
39
+ }>;
40
+ export declare class ProgramCreationError extends ProgramCreationError_base {
27
41
  }
28
- export declare class InstructionBuildError extends Error {
29
- readonly _tag = "InstructionBuildError";
30
- readonly method: string;
31
- readonly cause: unknown;
32
- constructor(method: string, cause: unknown);
42
+ declare const InstructionBuildError_base: Schema.TaggedErrorClass<InstructionBuildError, "InstructionBuildError", {
43
+ readonly _tag: Schema.tag<"InstructionBuildError">;
44
+ } & {
45
+ cause: Schema.optional<typeof Schema.Unknown>;
46
+ message: typeof Schema.String;
47
+ method: typeof Schema.String;
48
+ }>;
49
+ export declare class InstructionBuildError extends InstructionBuildError_base {
50
+ }
51
+ declare const ProgramReadError_base: Schema.TaggedErrorClass<ProgramReadError, "ProgramReadError", {
52
+ readonly _tag: Schema.tag<"ProgramReadError">;
53
+ } & {
54
+ cause: Schema.optional<typeof Schema.Unknown>;
55
+ message: typeof Schema.String;
56
+ method: typeof Schema.String;
57
+ }>;
58
+ export declare class ProgramReadError extends ProgramReadError_base {
59
+ }
60
+ declare const ViewNotSupportedError_base: Schema.TaggedErrorClass<ViewNotSupportedError, "ViewNotSupportedError", {
61
+ readonly _tag: Schema.tag<"ViewNotSupportedError">;
62
+ } & {
63
+ idlName: typeof Schema.String;
64
+ message: typeof Schema.String;
65
+ method: typeof Schema.String;
66
+ }>;
67
+ export declare class ViewNotSupportedError extends ViewNotSupportedError_base {
33
68
  }
34
69
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/program/types.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAMxD,YAAY,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAUtD,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAAC,CAAC;AAK3D,MAAM,MAAM,mBAAmB,CAC7B,CAAC,SAAS,OAAO,mBAAmB,EAAE,GAAG,GAAG,OAAO,mBAAmB,EAAE,GAAG,IACzE;IAEF,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC;IAEhB,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;CAC9B,CAAC;AAKF,MAAM,MAAM,sBAAsB,CAAC,KAAK,SAAS,SAAS,OAAO,EAAE,GAAG,SAAS,OAAO,EAAE,IAAI;IAE1F,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IAErB,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;CAChC,CAAC;AAKF,MAAM,MAAM,sBAAsB,GAAG;IAEnC,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;CACnC,CAAC;AASF,qBAAa,wBAAyB,SAAQ,KAAK;IACjD,QAAQ,CAAC,IAAI,8BAA8B;IAC3C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,MA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