@solana/rpc-graphql 2.0.0-experimental.eb5fd16 → 2.0.0-experimental.ed41fe2

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 (75) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1088 -30
  3. package/dist/index.browser.cjs +3364 -51
  4. package/dist/index.browser.cjs.map +1 -1
  5. package/dist/index.browser.js +3361 -53
  6. package/dist/index.browser.js.map +1 -1
  7. package/dist/index.native.js +3365 -53
  8. package/dist/index.native.js.map +1 -1
  9. package/dist/index.node.cjs +3365 -48
  10. package/dist/index.node.cjs.map +1 -1
  11. package/dist/index.node.js +3365 -53
  12. package/dist/index.node.js.map +1 -1
  13. package/dist/types/context.d.ts +17 -6
  14. package/dist/types/context.d.ts.map +1 -0
  15. package/dist/types/index.d.ts +6 -1
  16. package/dist/types/index.d.ts.map +1 -0
  17. package/dist/types/loaders/account.d.ts +14 -0
  18. package/dist/types/loaders/account.d.ts.map +1 -0
  19. package/dist/types/loaders/block.d.ts +4 -0
  20. package/dist/types/loaders/block.d.ts.map +1 -0
  21. package/dist/types/loaders/coalescer.d.ts +55 -0
  22. package/dist/types/loaders/coalescer.d.ts.map +1 -0
  23. package/dist/types/loaders/index.d.ts +6 -0
  24. package/dist/types/loaders/index.d.ts.map +1 -0
  25. package/dist/types/loaders/loader.d.ts +82 -0
  26. package/dist/types/loaders/loader.d.ts.map +1 -0
  27. package/dist/types/loaders/program-accounts.d.ts +8 -0
  28. package/dist/types/loaders/program-accounts.d.ts.map +1 -0
  29. package/dist/types/loaders/transaction.d.ts +4 -0
  30. package/dist/types/loaders/transaction.d.ts.map +1 -0
  31. package/dist/types/resolvers/account.d.ts +232 -0
  32. package/dist/types/resolvers/account.d.ts.map +1 -0
  33. package/dist/types/resolvers/block.d.ts +104 -0
  34. package/dist/types/resolvers/block.d.ts.map +1 -0
  35. package/dist/types/resolvers/index.d.ts +3 -0
  36. package/dist/types/resolvers/index.d.ts.map +1 -0
  37. package/dist/types/resolvers/instruction.d.ts +2220 -0
  38. package/dist/types/resolvers/instruction.d.ts.map +1 -0
  39. package/dist/types/resolvers/program-accounts.d.ts +19 -0
  40. package/dist/types/resolvers/program-accounts.d.ts.map +1 -0
  41. package/dist/types/resolvers/resolve-info/account.d.ts +15 -0
  42. package/dist/types/resolvers/resolve-info/account.d.ts.map +1 -0
  43. package/dist/types/resolvers/resolve-info/block.d.ts +13 -0
  44. package/dist/types/resolvers/resolve-info/block.d.ts.map +1 -0
  45. package/dist/types/resolvers/resolve-info/index.d.ts +6 -0
  46. package/dist/types/resolvers/resolve-info/index.d.ts.map +1 -0
  47. package/dist/types/resolvers/resolve-info/program-accounts.d.ts +20 -0
  48. package/dist/types/resolvers/resolve-info/program-accounts.d.ts.map +1 -0
  49. package/dist/types/resolvers/resolve-info/transaction.d.ts +15 -0
  50. package/dist/types/resolvers/resolve-info/transaction.d.ts.map +1 -0
  51. package/dist/types/resolvers/resolve-info/visitor.d.ts +18 -0
  52. package/dist/types/resolvers/resolve-info/visitor.d.ts.map +1 -0
  53. package/dist/types/resolvers/root.d.ts +3 -0
  54. package/dist/types/resolvers/root.d.ts.map +1 -0
  55. package/dist/types/resolvers/transaction.d.ts +42 -0
  56. package/dist/types/resolvers/transaction.d.ts.map +1 -0
  57. package/dist/types/resolvers/types.d.ts +94 -0
  58. package/dist/types/resolvers/types.d.ts.map +1 -0
  59. package/dist/types/schema/account.d.ts +2 -0
  60. package/dist/types/schema/account.d.ts.map +1 -0
  61. package/dist/types/schema/block.d.ts +2 -0
  62. package/dist/types/schema/block.d.ts.map +1 -0
  63. package/dist/types/schema/index.d.ts +2 -0
  64. package/dist/types/schema/index.d.ts.map +1 -0
  65. package/dist/types/schema/instruction.d.ts +2 -0
  66. package/dist/types/schema/instruction.d.ts.map +1 -0
  67. package/dist/types/schema/root.d.ts +2 -0
  68. package/dist/types/schema/root.d.ts.map +1 -0
  69. package/dist/types/schema/transaction.d.ts +2 -0
  70. package/dist/types/schema/transaction.d.ts.map +1 -0
  71. package/dist/types/schema/types.d.ts +2 -0
  72. package/dist/types/schema/types.d.ts.map +1 -0
  73. package/package.json +15 -36
  74. package/dist/types/cache.d.ts +0 -7
  75. package/dist/types/rpc.d.ts +0 -13
@@ -1,69 +1,3381 @@
1
- import { GraphQLSchema, GraphQLObjectType, graphql } from 'graphql';
2
-
3
- // src/rpc.ts
4
-
5
- // src/cache.ts
6
- var inMemoryCache = {};
7
- var stringifyValue = (value) => JSON.stringify(value, (_, value2) => {
8
- if (typeof value2 === "bigint") {
9
- return value2.toString() + "n";
10
- }
11
- return value2;
12
- });
13
- var parseValue = (value) => JSON.parse(value, (_, value2) => {
14
- if (typeof value2 === "string" && /\d+n$/.test(value2)) {
15
- return BigInt(value2.slice(0, -1));
16
- }
17
- return value2;
18
- });
19
- var cacheKey = (key, variables) => `GraphQLCache:${stringifyValue(key)}:${stringifyValue(variables)}`;
20
- function createGraphQLCache() {
1
+ import { makeExecutableSchema } from '@graphql-tools/schema';
2
+ import { graphql, Kind, visit, BREAK, isInterfaceType } from 'graphql';
3
+ import { getBase64Codec, getBase58Codec } from '@solana/codecs-strings';
4
+ import DataLoader from 'dataloader';
5
+ import stringify from 'json-stable-stringify';
6
+
7
+ // src/index.ts
8
+ function replacer(_, value) {
9
+ if (typeof value === "bigint") {
10
+ return value.toString() + "n";
11
+ }
12
+ return value;
13
+ }
14
+ var cacheKeyFn = (obj) => stringify(obj, { replacer });
15
+
16
+ // src/loaders/coalescer.ts
17
+ var hashOmit = (args, omit) => {
18
+ const argsObj = {};
19
+ for (const [key, value] of Object.entries(args)) {
20
+ if (!omit.includes(key)) {
21
+ argsObj[key] = value;
22
+ }
23
+ }
24
+ return cacheKeyFn(argsObj);
25
+ };
26
+ function buildCoalescedFetchesByArgsHash(toFetchMap, orphanConfig) {
27
+ const fetchesByArgsHash = {};
28
+ const orphanedFetches = {};
29
+ Object.entries(toFetchMap).forEach(([signature, toFetch]) => {
30
+ toFetch.forEach(({ args, promiseCallback }) => {
31
+ if (orphanConfig.criteria(args)) {
32
+ const toFetch2 = orphanedFetches[signature] ||= [];
33
+ toFetch2.push({ args, promiseCallback });
34
+ return;
35
+ }
36
+ const argsHash = hashOmit(args, []);
37
+ const transactionFetches = fetchesByArgsHash[argsHash] ||= {
38
+ args,
39
+ fetches: {}
40
+ };
41
+ const { callbacks: promiseCallbacksForSignature } = transactionFetches.fetches[signature] ||= {
42
+ callbacks: []
43
+ };
44
+ promiseCallbacksForSignature.push(promiseCallback);
45
+ });
46
+ });
47
+ Object.entries(orphanedFetches).forEach(([signature, toFetch]) => {
48
+ toFetch.forEach(({ args: orphanArgs, promiseCallback: orphanPromiseCallback }) => {
49
+ if (Object.keys(fetchesByArgsHash).length !== 0) {
50
+ for (const { fetches, args: args2 } of Object.values(fetchesByArgsHash)) {
51
+ if (hashOmit(orphanArgs, orphanConfig.hashOmit) === hashOmit(args2, orphanConfig.hashOmit)) {
52
+ const { callbacks: promiseCallbacksForSignature2 } = fetches[signature] ||= {
53
+ callbacks: []
54
+ };
55
+ promiseCallbacksForSignature2.push(orphanPromiseCallback);
56
+ return;
57
+ }
58
+ }
59
+ }
60
+ const args = orphanConfig.defaults(orphanArgs);
61
+ const argsHash = hashOmit(args, []);
62
+ const transactionFetches = fetchesByArgsHash[argsHash] ||= {
63
+ args,
64
+ fetches: {}
65
+ };
66
+ const { callbacks: promiseCallbacksForSignature } = transactionFetches.fetches[signature] ||= {
67
+ callbacks: []
68
+ };
69
+ promiseCallbacksForSignature.push(orphanPromiseCallback);
70
+ });
71
+ });
72
+ return fetchesByArgsHash;
73
+ }
74
+ function buildCoalescedFetchesByArgsHashWithDataSlice(toFetchMap, maxDataSliceByteRange) {
75
+ const fetchesByArgsHash = {};
76
+ const orphanedFetches = {};
77
+ Object.entries(toFetchMap).forEach(([address, toFetch]) => {
78
+ toFetch.forEach(({ args, promiseCallback }) => {
79
+ if (!args.encoding) {
80
+ const toFetch2 = orphanedFetches[address] ||= [];
81
+ toFetch2.push({ args, promiseCallback });
82
+ return;
83
+ }
84
+ if (args.encoding != "base64+zstd" && args.dataSlice) {
85
+ const r = args.dataSlice;
86
+ for (const { fetches: fetchAddresses, args: fetchArgs } of Object.values(fetchesByArgsHash)) {
87
+ const addCallbackWithDataSlice = (updateDataSlice) => {
88
+ const { callbacks: promiseCallbacksForAddress2 } = fetchAddresses[address] ||= {
89
+ callbacks: []
90
+ };
91
+ promiseCallbacksForAddress2.push({
92
+ callback: promiseCallback,
93
+ dataSlice: args.dataSlice ?? null
94
+ });
95
+ if (fetchArgs.dataSlice && updateDataSlice) {
96
+ fetchArgs.dataSlice = updateDataSlice;
97
+ }
98
+ };
99
+ if (hashOmit(args, ["dataSlice"]) === hashOmit(fetchArgs, ["dataSlice"])) {
100
+ if (fetchArgs.dataSlice) {
101
+ const g = fetchArgs.dataSlice;
102
+ if (r.offset <= g.offset && g.offset - r.offset + r.length <= maxDataSliceByteRange) {
103
+ const length = Math.max(r.length, g.offset + g.length - r.offset);
104
+ const offset = r.offset;
105
+ addCallbackWithDataSlice({ length, offset });
106
+ return;
107
+ }
108
+ if (r.offset >= g.offset && r.offset - g.offset + g.length <= maxDataSliceByteRange) {
109
+ const length = Math.max(g.length, r.offset + r.length - g.offset);
110
+ const offset = g.offset;
111
+ addCallbackWithDataSlice({ length, offset });
112
+ return;
113
+ }
114
+ } else {
115
+ const { length, offset } = r;
116
+ addCallbackWithDataSlice({ length, offset });
117
+ return;
118
+ }
119
+ }
120
+ }
121
+ }
122
+ const argsHash = hashOmit(args, []);
123
+ const accountFetches = fetchesByArgsHash[argsHash] ||= {
124
+ args,
125
+ fetches: {}
126
+ };
127
+ const { callbacks: promiseCallbacksForAddress } = accountFetches.fetches[address] ||= {
128
+ callbacks: []
129
+ };
130
+ promiseCallbacksForAddress.push({ callback: promiseCallback, dataSlice: args.dataSlice ?? null });
131
+ });
132
+ });
133
+ Object.entries(orphanedFetches).forEach(([address, toFetch]) => {
134
+ toFetch.forEach(({ args: orphanedArgs, promiseCallback: orphanPromiseCallback }) => {
135
+ if (Object.keys(fetchesByArgsHash).length !== 0) {
136
+ for (const { fetches, args: args2 } of Object.values(fetchesByArgsHash)) {
137
+ if (hashOmit(orphanedArgs, ["encoding", "dataSlice"]) === hashOmit(args2, ["encoding", "dataSlice"])) {
138
+ const { callbacks: promiseCallbacksForAddress2 } = fetches[address] ||= {
139
+ callbacks: []
140
+ };
141
+ promiseCallbacksForAddress2.push({ callback: orphanPromiseCallback });
142
+ return;
143
+ }
144
+ }
145
+ }
146
+ const args = { ...orphanedArgs, encoding: "base64" };
147
+ const argsHash = hashOmit(args, []);
148
+ const accountFetches = fetchesByArgsHash[argsHash] ||= {
149
+ args,
150
+ fetches: {}
151
+ };
152
+ const { callbacks: promiseCallbacksForAddress } = accountFetches.fetches[address] ||= {
153
+ callbacks: []
154
+ };
155
+ promiseCallbacksForAddress.push({ callback: orphanPromiseCallback });
156
+ });
157
+ });
158
+ return fetchesByArgsHash;
159
+ }
160
+
161
+ // src/loaders/account.ts
162
+ function getCodec(encoding) {
163
+ switch (encoding) {
164
+ case "base58":
165
+ return getBase58Codec();
166
+ default:
167
+ return getBase64Codec();
168
+ }
169
+ }
170
+ function sliceData(account, dataSlice, masterDataSlice) {
171
+ if (dataSlice) {
172
+ const masterOffset = masterDataSlice ? masterDataSlice.offset : 0;
173
+ const slicedData = (data, encoding) => {
174
+ if (encoding === "base64+zstd") {
175
+ return data;
176
+ }
177
+ const { offset, length } = dataSlice;
178
+ const trueOffset = offset - masterOffset;
179
+ const codec = getCodec(encoding);
180
+ return codec.decode(codec.encode(data).slice(trueOffset, trueOffset + length));
181
+ };
182
+ if (Array.isArray(account.data)) {
183
+ const [data, encoding] = account.data;
184
+ return {
185
+ ...account,
186
+ data: [slicedData(data, encoding), encoding]
187
+ };
188
+ } else if (typeof account.data === "string") {
189
+ const data = account.data;
190
+ return {
191
+ ...account,
192
+ data: slicedData(data, "base58")
193
+ };
194
+ }
195
+ }
196
+ return account;
197
+ }
198
+ async function loadAccount(rpc, { address, ...config }) {
199
+ return await rpc.getAccountInfo(address, config).send().then((res) => res.value);
200
+ }
201
+ async function loadMultipleAccounts(rpc, { addresses, ...config }) {
202
+ return await rpc.getMultipleAccounts(addresses, config).send().then((res) => res.value);
203
+ }
204
+ function createAccountBatchLoadFn(rpc, config) {
205
+ const resolveAccountUsingRpc = loadAccount.bind(null, rpc);
206
+ const resolveMultipleAccountsUsingRpc = loadMultipleAccounts.bind(null, rpc);
207
+ return async (accountQueryArgs) => {
208
+ const accountsToFetch = {};
209
+ try {
210
+ return Promise.all(
211
+ accountQueryArgs.map(
212
+ ({ address, ...args }) => new Promise((resolve, reject) => {
213
+ const accountRecords = accountsToFetch[address] ||= [];
214
+ if (!args.commitment) {
215
+ args.commitment = "confirmed";
216
+ }
217
+ accountRecords.push({ args, promiseCallback: { reject, resolve } });
218
+ })
219
+ )
220
+ );
221
+ } finally {
222
+ const { maxDataSliceByteRange, maxMultipleAccountsBatchSize } = config;
223
+ const accountFetchesByArgsHash = buildCoalescedFetchesByArgsHashWithDataSlice(
224
+ accountsToFetch,
225
+ maxDataSliceByteRange
226
+ );
227
+ Object.values(accountFetchesByArgsHash).map(({ args, fetches: addressCallbacks }) => {
228
+ const addresses = Object.keys(addressCallbacks);
229
+ if (addresses.length === 1) {
230
+ const address = addresses[0];
231
+ return Array.from({ length: 1 }, async () => {
232
+ try {
233
+ const result = await resolveAccountUsingRpc({ address, ...args });
234
+ addressCallbacks[address].callbacks.forEach(({ callback, dataSlice }) => {
235
+ callback.resolve(sliceData(result, dataSlice, args.dataSlice));
236
+ });
237
+ } catch (e) {
238
+ addressCallbacks[address].callbacks.forEach(({ callback }) => {
239
+ callback.reject(e);
240
+ });
241
+ }
242
+ });
243
+ } else {
244
+ return Array.from(
245
+ { length: Math.ceil(addresses.length / maxMultipleAccountsBatchSize) },
246
+ async (_, ii) => {
247
+ const startIndex = ii * maxMultipleAccountsBatchSize;
248
+ const endIndex = startIndex + maxMultipleAccountsBatchSize;
249
+ const chunk = addresses.slice(startIndex, endIndex);
250
+ try {
251
+ const results = await resolveMultipleAccountsUsingRpc({
252
+ addresses: chunk,
253
+ ...args
254
+ });
255
+ chunk.forEach((address, ii2) => {
256
+ const result = results[ii2];
257
+ addressCallbacks[address].callbacks.forEach(({ callback, dataSlice }) => {
258
+ callback.resolve(sliceData(result, dataSlice, args.dataSlice));
259
+ });
260
+ });
261
+ } catch (e) {
262
+ chunk.forEach((address) => {
263
+ addressCallbacks[address].callbacks.forEach(({ callback }) => {
264
+ callback.reject(e);
265
+ });
266
+ });
267
+ }
268
+ }
269
+ );
270
+ }
271
+ });
272
+ }
273
+ };
274
+ }
275
+ function createAccountLoader(rpc, config) {
276
+ const loader = new DataLoader(createAccountBatchLoadFn(rpc, config), { cacheKeyFn });
21
277
  return {
22
- // Node.js
23
- flush: () => {
24
- Object.keys(inMemoryCache).forEach((key) => delete inMemoryCache[key]);
25
- },
26
- get: (key, variables) => {
27
- const value = inMemoryCache[cacheKey(key, variables)];
28
- return value === void 0 ? null : parseValue(value);
29
- },
30
- insert: (key, variables, value) => {
31
- inMemoryCache[cacheKey(key, variables)] = stringifyValue(value);
278
+ load: async (args) => loader.load(args),
279
+ loadMany: async (args) => loader.loadMany(args)
280
+ };
281
+ }
282
+ async function loadBlock(rpc, { slot, ...config }) {
283
+ return await rpc.getBlock(
284
+ slot,
285
+ // @ts-expect-error FIX ME: https://github.com/microsoft/TypeScript/issues/43187
286
+ config
287
+ ).send();
288
+ }
289
+ function createBlockBatchLoadFn(rpc) {
290
+ const resolveBlockUsingRpc = loadBlock.bind(null, rpc);
291
+ return async (blockQueryArgs) => {
292
+ const blocksToFetch = {};
293
+ try {
294
+ return Promise.all(
295
+ blockQueryArgs.map(
296
+ ({ slot, ...args }) => new Promise((resolve, reject) => {
297
+ const blockRecords = blocksToFetch[slot.toString()] ||= [];
298
+ if (!args.commitment) {
299
+ args.commitment = "confirmed";
300
+ }
301
+ blockRecords.push({ args, promiseCallback: { reject, resolve } });
302
+ })
303
+ )
304
+ );
305
+ } finally {
306
+ const blockFetchesByArgsHash = buildCoalescedFetchesByArgsHash(blocksToFetch, {
307
+ criteria: (args) => args.encoding === void 0 && args.transactionDetails !== "signatures",
308
+ defaults: (args) => ({
309
+ ...args,
310
+ transactionDetails: "none"
311
+ }),
312
+ hashOmit: ["encoding", "transactionDetails"]
313
+ });
314
+ Object.values(blockFetchesByArgsHash).map(({ args, fetches: blockCallbacks }) => {
315
+ return Object.entries(blockCallbacks).map(([slot, { callbacks }]) => {
316
+ return Array.from({ length: 1 }, async () => {
317
+ try {
318
+ const result = await resolveBlockUsingRpc({
319
+ slot: BigInt(slot),
320
+ ...args
321
+ });
322
+ callbacks.forEach((c) => c.resolve(result));
323
+ } catch (e) {
324
+ callbacks.forEach((c) => c.reject(e));
325
+ }
326
+ });
327
+ });
328
+ });
329
+ }
330
+ };
331
+ }
332
+ function createBlockLoader(rpc) {
333
+ const loader = new DataLoader(createBlockBatchLoadFn(rpc), { cacheKeyFn });
334
+ return {
335
+ load: async (args) => loader.load({ ...args, maxSupportedTransactionVersion: 0 }),
336
+ loadMany: async (args) => loader.loadMany(args.map((a) => ({ ...a, maxSupportedTransactionVersion: 0 })))
337
+ };
338
+ }
339
+ async function loadProgramAccounts(rpc, { programAddress, ...config }) {
340
+ return await rpc.getProgramAccounts(
341
+ programAddress,
342
+ // @ts-expect-error FIX ME: https://github.com/microsoft/TypeScript/issues/43187
343
+ config
344
+ ).send();
345
+ }
346
+ function createProgramAccountsBatchLoadFn(rpc, config) {
347
+ const resolveProgramAccountsUsingRpc = loadProgramAccounts.bind(null, rpc);
348
+ return async (accountQueryArgs) => {
349
+ const programAccountsToFetch = {};
350
+ try {
351
+ return Promise.all(
352
+ accountQueryArgs.map(
353
+ ({ programAddress, ...args }) => new Promise((resolve, reject) => {
354
+ const accountRecords = programAccountsToFetch[programAddress] ||= [];
355
+ if (!args.commitment) {
356
+ args.commitment = "confirmed";
357
+ }
358
+ accountRecords.push({ args, promiseCallback: { reject, resolve } });
359
+ })
360
+ )
361
+ );
362
+ } finally {
363
+ const { maxDataSliceByteRange } = config;
364
+ const programAccountsFetchesByArgsHash = buildCoalescedFetchesByArgsHashWithDataSlice(
365
+ programAccountsToFetch,
366
+ maxDataSliceByteRange
367
+ );
368
+ Object.values(programAccountsFetchesByArgsHash).map(({ args, fetches: programAddressCallbacks }) => {
369
+ return Object.entries(programAddressCallbacks).map(([programAddress, { callbacks }]) => {
370
+ return Array.from({ length: 1 }, async () => {
371
+ try {
372
+ const result = await resolveProgramAccountsUsingRpc({
373
+ programAddress,
374
+ ...args
375
+ });
376
+ callbacks.forEach(({ callback, dataSlice }) => {
377
+ callback.resolve(sliceData(result, dataSlice, args.dataSlice));
378
+ });
379
+ } catch (e) {
380
+ callbacks.forEach(({ callback }) => {
381
+ callback.reject(e);
382
+ });
383
+ }
384
+ });
385
+ });
386
+ });
387
+ }
388
+ };
389
+ }
390
+ function createProgramAccountsLoader(rpc, config) {
391
+ const loader = new DataLoader(createProgramAccountsBatchLoadFn(rpc, config), { cacheKeyFn });
392
+ return {
393
+ load: async (args) => loader.load(args),
394
+ loadMany: async (args) => loader.loadMany(args)
395
+ };
396
+ }
397
+ async function loadTransaction(rpc, { signature, ...config }) {
398
+ return await rpc.getTransaction(
399
+ signature,
400
+ // @ts-expect-error FIX ME: https://github.com/microsoft/TypeScript/issues/43187
401
+ config
402
+ ).send();
403
+ }
404
+ function createTransactionBatchLoadFn(rpc) {
405
+ const resolveTransactionUsingRpc = loadTransaction.bind(null, rpc);
406
+ return async (transactionQueryArgs) => {
407
+ const transactionsToFetch = {};
408
+ try {
409
+ return Promise.all(
410
+ transactionQueryArgs.map(
411
+ ({ signature, ...args }) => new Promise((resolve, reject) => {
412
+ const transactionRecords = transactionsToFetch[signature] ||= [];
413
+ if (!args.commitment) {
414
+ args.commitment = "confirmed";
415
+ }
416
+ transactionRecords.push({ args, promiseCallback: { reject, resolve } });
417
+ })
418
+ )
419
+ );
420
+ } finally {
421
+ const transactionFetchesByArgsHash = buildCoalescedFetchesByArgsHash(transactionsToFetch, {
422
+ criteria: (args) => args.encoding === void 0,
423
+ defaults: (args) => ({ ...args, encoding: "base64" }),
424
+ hashOmit: ["encoding"]
425
+ });
426
+ Object.values(transactionFetchesByArgsHash).map(({ args, fetches: transactionCallbacks }) => {
427
+ return Object.entries(transactionCallbacks).map(([signature, { callbacks }]) => {
428
+ return Array.from({ length: 1 }, async () => {
429
+ try {
430
+ const result = await resolveTransactionUsingRpc({
431
+ signature,
432
+ ...args
433
+ });
434
+ callbacks.forEach((c) => c.resolve(result));
435
+ } catch (e) {
436
+ callbacks.forEach((c) => c.reject(e));
437
+ }
438
+ });
439
+ });
440
+ });
32
441
  }
33
442
  };
34
443
  }
444
+ function createTransactionLoader(rpc) {
445
+ const loader = new DataLoader(createTransactionBatchLoadFn(rpc), { cacheKeyFn });
446
+ return {
447
+ load: async (args) => loader.load(args),
448
+ loadMany: async (args) => loader.loadMany(args)
449
+ };
450
+ }
35
451
 
36
452
  // src/context.ts
37
- function createSolanaGraphQLContext(rpc) {
38
- const cache = createGraphQLCache();
39
- return { cache, rpc };
40
- }
41
-
42
- // src/rpc.ts
43
- function createRpcGraphQL(rpc) {
44
- const context = createSolanaGraphQLContext(rpc);
45
- const schema = new GraphQLSchema({
46
- query: new GraphQLObjectType({
47
- fields: {
48
- /** Root queries */
453
+ function createSolanaGraphQLContext(rpc, config) {
454
+ return {
455
+ loaders: {
456
+ account: createAccountLoader(rpc, config),
457
+ block: createBlockLoader(rpc),
458
+ programAccounts: createProgramAccountsLoader(rpc, config),
459
+ transaction: createTransactionLoader(rpc)
460
+ }
461
+ };
462
+ }
463
+ function injectableRootVisitor(info, rootNode, operations) {
464
+ const { fieldNodes } = info;
465
+ const root = rootNode ?? fieldNodes[0];
466
+ const parentIsRoot = (ancestors) => (Array.isArray(ancestors) ? ancestors[0] : ancestors) === root;
467
+ visit(root, {
468
+ Field(node, key, parent, path, ancestors) {
469
+ if (!parentIsRoot(ancestors))
470
+ return;
471
+ return operations.fieldNodeOperation(info, node, key, parent, path, ancestors);
472
+ },
473
+ FragmentSpread(node, key, parent, path, ancestors) {
474
+ const fragmentDefinition = info.fragments[node.name.value];
475
+ return operations.fragmentSpreadNodeOperation(info, fragmentDefinition, node, key, parent, path, ancestors);
476
+ },
477
+ InlineFragment(node, key, parent, path, ancestors) {
478
+ if (!parentIsRoot(ancestors))
479
+ return;
480
+ return operations.inlineFragmentNodeOperation(info, node, key, parent, path, ancestors);
481
+ }
482
+ });
483
+ }
484
+ function onlyFieldsRequested(fieldNames, info, rootNode) {
485
+ let onlyFieldsRequested2 = true;
486
+ function checkFieldsWithVisitor(root) {
487
+ injectableRootVisitor(info, root, {
488
+ fieldNodeOperation(_info, node) {
489
+ onlyFieldsRequested2 = fieldNames.includes(node.name.value);
490
+ if (!onlyFieldsRequested2) {
491
+ return BREAK;
492
+ }
49
493
  },
50
- name: "RootQuery"
51
- }),
52
- types: []
494
+ fragmentSpreadNodeOperation(_info, fragment) {
495
+ checkFieldsWithVisitor(fragment);
496
+ },
497
+ inlineFragmentNodeOperation(_info, node) {
498
+ checkFieldsWithVisitor(node);
499
+ }
500
+ });
501
+ }
502
+ checkFieldsWithVisitor(rootNode ?? null);
503
+ return onlyFieldsRequested2;
504
+ }
505
+
506
+ // src/resolvers/resolve-info/account.ts
507
+ function findArgumentNodeByName(argumentNodes, name) {
508
+ return argumentNodes.find((argumentNode) => argumentNode.name.value === name);
509
+ }
510
+ function parseAccountEncodingArgument(argumentNodes, variableValues) {
511
+ const argumentNode = findArgumentNodeByName(argumentNodes, "encoding");
512
+ if (argumentNode) {
513
+ if (argumentNode.value.kind === "EnumValue") {
514
+ if (argumentNode.value.value === "BASE_58") {
515
+ return "base58";
516
+ }
517
+ if (argumentNode.value.value === "BASE_64") {
518
+ return "base64";
519
+ }
520
+ if (argumentNode.value.value === "BASE_64_ZSTD") {
521
+ return "base64+zstd";
522
+ }
523
+ }
524
+ if (argumentNode.value.kind === "Variable") {
525
+ return variableValues[argumentNode.value.name.value];
526
+ }
527
+ } else {
528
+ return void 0;
529
+ }
530
+ }
531
+ function parseAccountDataSliceArgument(argumentNodes, variableValues) {
532
+ const argumentNode = findArgumentNodeByName(argumentNodes, "dataSlice");
533
+ if (argumentNode) {
534
+ if (argumentNode.value.kind === "ObjectValue") {
535
+ const offsetArg = argumentNode.value.fields?.find((field) => field.name.value === "offset");
536
+ const lengthArg = argumentNode.value.fields?.find((field) => field.name.value === "length");
537
+ const length = lengthArg?.value.kind === "IntValue" ? parseInt(lengthArg.value.value) : lengthArg?.value.kind === "Variable" ? variableValues[lengthArg.value.name.value] : void 0;
538
+ const offset = offsetArg?.value.kind === "IntValue" ? parseInt(offsetArg.value.value) : offsetArg?.value.kind === "Variable" ? variableValues[offsetArg.value.name.value] : void 0;
539
+ return length !== void 0 && length !== null && offset !== void 0 && offset !== null ? { length, offset } : void 0;
540
+ }
541
+ if (argumentNode.value.kind === "Variable") {
542
+ return variableValues[argumentNode.value.name.value];
543
+ }
544
+ } else {
545
+ return void 0;
546
+ }
547
+ }
548
+ function buildAccountArgSetWithVisitor(args, info) {
549
+ const argSet = [args];
550
+ function buildArgSetWithVisitor(root) {
551
+ injectableRootVisitor(info, root, {
552
+ fieldNodeOperation(info2, node) {
553
+ if (node.name.value !== "data") {
554
+ return;
555
+ }
556
+ if (node.arguments) {
557
+ const { variableValues } = info2;
558
+ const encoding = parseAccountEncodingArgument(node.arguments, variableValues);
559
+ const dataSlice = parseAccountDataSliceArgument(node.arguments, variableValues);
560
+ argSet.push({ ...args, dataSlice, encoding });
561
+ }
562
+ },
563
+ fragmentSpreadNodeOperation(_info, fragment) {
564
+ buildArgSetWithVisitor(fragment);
565
+ },
566
+ inlineFragmentNodeOperation(info2, node) {
567
+ const { schema } = info2;
568
+ const accountInterface = schema.getType("Account");
569
+ if (isInterfaceType(accountInterface) && // Recursively check if the inline fragment requests any
570
+ // fields outside of the `Account` interface.
571
+ !onlyFieldsRequested(Object.keys(accountInterface.getFields()), info2, node)) {
572
+ argSet.push({ ...args, encoding: "jsonParsed" });
573
+ }
574
+ }
575
+ });
576
+ }
577
+ buildArgSetWithVisitor(null);
578
+ return argSet;
579
+ }
580
+ function buildAccountLoaderArgSetFromResolveInfo(args, info) {
581
+ return buildAccountArgSetWithVisitor(args, info);
582
+ }
583
+
584
+ // src/resolvers/resolve-info/transaction.ts
585
+ function findArgumentNodeByName2(argumentNodes, name) {
586
+ return argumentNodes.find((argumentNode) => argumentNode.name.value === name);
587
+ }
588
+ function parseTransactionEncodingArgument(argumentNodes, variableValues) {
589
+ const argumentNode = findArgumentNodeByName2(argumentNodes, "encoding");
590
+ if (argumentNode) {
591
+ if (argumentNode.value.kind === "EnumValue") {
592
+ if (argumentNode.value.value === "BASE_58") {
593
+ return "base58";
594
+ }
595
+ if (argumentNode.value.value === "BASE_64") {
596
+ return "base64";
597
+ }
598
+ }
599
+ if (argumentNode.value.kind === "Variable") {
600
+ return variableValues[argumentNode.value.name.value];
601
+ }
602
+ } else {
603
+ return void 0;
604
+ }
605
+ }
606
+ function buildTransactionArgSetWithVisitor(args, info) {
607
+ const argSet = [args];
608
+ function buildArgSetWithVisitor(root) {
609
+ injectableRootVisitor(info, root, {
610
+ fieldNodeOperation(info2, node) {
611
+ if (node.name.value === "message" || node.name.value === "meta") {
612
+ argSet.push({ ...args, encoding: "jsonParsed" });
613
+ } else if (node.name.value === "data") {
614
+ if (node.arguments) {
615
+ const { variableValues } = info2;
616
+ const encoding = parseTransactionEncodingArgument(
617
+ node.arguments,
618
+ variableValues
619
+ );
620
+ argSet.push({ ...args, encoding });
621
+ }
622
+ }
623
+ },
624
+ fragmentSpreadNodeOperation(_info, fragment) {
625
+ buildArgSetWithVisitor(fragment);
626
+ },
627
+ inlineFragmentNodeOperation(_info, _node) {
628
+ return;
629
+ }
630
+ });
631
+ }
632
+ buildArgSetWithVisitor(null);
633
+ return argSet;
634
+ }
635
+ function buildTransactionLoaderArgSetFromResolveInfo(args, info) {
636
+ return buildTransactionArgSetWithVisitor(args, info);
637
+ }
638
+
639
+ // src/resolvers/resolve-info/block.ts
640
+ function buildBlockLoaderArgSetFromResolveInfo(args, info) {
641
+ const argSet = [args];
642
+ function buildArgSetWithVisitor(root) {
643
+ injectableRootVisitor(info, root, {
644
+ fieldNodeOperation(info2, node) {
645
+ if (node.name.value === "signatures") {
646
+ argSet.push({ ...args, transactionDetails: "signatures" });
647
+ } else if (node.name.value === "transactions") {
648
+ argSet.push(...buildTransactionArgSetWithVisitor({ ...args, transactionDetails: "full" }, info2));
649
+ }
650
+ },
651
+ fragmentSpreadNodeOperation(_info, fragment) {
652
+ buildArgSetWithVisitor(fragment);
653
+ },
654
+ inlineFragmentNodeOperation(_info, _node) {
655
+ return;
656
+ }
657
+ });
658
+ }
659
+ buildArgSetWithVisitor(null);
660
+ return argSet;
661
+ }
662
+
663
+ // src/resolvers/resolve-info/program-accounts.ts
664
+ function buildProgramAccountsLoaderArgSetFromResolveInfo(args, info) {
665
+ return buildAccountArgSetWithVisitor(args, info);
666
+ }
667
+
668
+ // src/resolvers/account.ts
669
+ var resolveAccountData = () => {
670
+ return (parent, args) => {
671
+ return parent === null ? null : parent.encodedData ? parent.encodedData[cacheKeyFn(args)] : null;
672
+ };
673
+ };
674
+ var resolveAccount = (fieldName) => {
675
+ return async (parent, args, context, info) => {
676
+ const address = fieldName ? parent[fieldName] : args.address;
677
+ if (address) {
678
+ if (onlyFieldsRequested(["address"], info)) {
679
+ return { address };
680
+ }
681
+ const argsSet = buildAccountLoaderArgSetFromResolveInfo({ ...args, address }, info);
682
+ const loadedAccounts = await context.loaders.account.loadMany(argsSet);
683
+ let result = {
684
+ address,
685
+ encodedData: {}
686
+ };
687
+ loadedAccounts.forEach((account, i) => {
688
+ if (account instanceof Error) {
689
+ console.error(account);
690
+ return;
691
+ }
692
+ if (account === null) {
693
+ return;
694
+ }
695
+ if (!result.ownerProgram) {
696
+ result = {
697
+ ...result,
698
+ ...account,
699
+ ownerProgram: account.owner
700
+ };
701
+ }
702
+ const { data } = account;
703
+ const { encoding, dataSlice } = argsSet[i];
704
+ if (encoding && result.encodedData) {
705
+ if (Array.isArray(data)) {
706
+ result.encodedData[cacheKeyFn({
707
+ dataSlice,
708
+ encoding: encoding === "jsonParsed" ? "base64" : encoding
709
+ })] = data[0];
710
+ } else if (typeof data === "string") {
711
+ result.encodedData[cacheKeyFn({
712
+ dataSlice,
713
+ encoding: "base58"
714
+ })] = data;
715
+ } else if (typeof data === "object") {
716
+ const {
717
+ parsed: { info: parsedData, type: accountType },
718
+ program: programName,
719
+ programId
720
+ } = data;
721
+ result.jsonParsedConfigs = {
722
+ accountType,
723
+ programId,
724
+ programName
725
+ };
726
+ result = {
727
+ ...result,
728
+ ...parsedData
729
+ };
730
+ }
731
+ }
732
+ });
733
+ return result;
734
+ }
735
+ return null;
736
+ };
737
+ };
738
+ function resolveAccountType(accountResult) {
739
+ const { jsonParsedConfigs } = accountResult;
740
+ if (jsonParsedConfigs) {
741
+ if (jsonParsedConfigs.programName === "nonce") {
742
+ return "NonceAccount";
743
+ }
744
+ if (jsonParsedConfigs.accountType === "mint" && jsonParsedConfigs.programName === "spl-token") {
745
+ return "MintAccount";
746
+ }
747
+ if (jsonParsedConfigs.accountType === "account" && jsonParsedConfigs.programName === "spl-token") {
748
+ return "TokenAccount";
749
+ }
750
+ if (jsonParsedConfigs.programName === "stake") {
751
+ return "StakeAccount";
752
+ }
753
+ if (jsonParsedConfigs.accountType === "vote" && jsonParsedConfigs.programName === "vote") {
754
+ return "VoteAccount";
755
+ }
756
+ if (jsonParsedConfigs.accountType === "lookupTable" && jsonParsedConfigs.programName === "address-lookup-table") {
757
+ return "LookupTableAccount";
758
+ }
759
+ }
760
+ return "GenericAccount";
761
+ }
762
+ var accountResolvers = {
763
+ Account: {
764
+ __resolveType: resolveAccountType,
765
+ data: resolveAccountData()
766
+ },
767
+ GenericAccount: {
768
+ data: resolveAccountData(),
769
+ ownerProgram: resolveAccount("ownerProgram")
770
+ },
771
+ LookupTableAccount: {
772
+ authority: resolveAccount("authority"),
773
+ data: resolveAccountData(),
774
+ ownerProgram: resolveAccount("ownerProgram")
775
+ },
776
+ MintAccount: {
777
+ data: resolveAccountData(),
778
+ freezeAuthority: resolveAccount("freezeAuthority"),
779
+ mintAuthority: resolveAccount("mintAuthority"),
780
+ ownerProgram: resolveAccount("ownerProgram")
781
+ },
782
+ NonceAccount: {
783
+ authority: resolveAccount("authority"),
784
+ data: resolveAccountData(),
785
+ ownerProgram: resolveAccount("ownerProgram")
786
+ },
787
+ StakeAccount: {
788
+ data: resolveAccountData(),
789
+ ownerProgram: resolveAccount("ownerProgram")
790
+ },
791
+ StakeAccountDataMetaAuthorized: {
792
+ staker: resolveAccount("staker"),
793
+ withdrawer: resolveAccount("withdrawer")
794
+ },
795
+ StakeAccountDataMetaLockup: {
796
+ custodian: resolveAccount("custodian")
797
+ },
798
+ StakeAccountDataStakeDelegation: {
799
+ voter: resolveAccount("voter")
800
+ },
801
+ TokenAccount: {
802
+ data: resolveAccountData(),
803
+ mint: resolveAccount("mint"),
804
+ owner: resolveAccount("owner"),
805
+ ownerProgram: resolveAccount("ownerProgram")
806
+ },
807
+ VoteAccount: {
808
+ authorizedWithdrawer: resolveAccount("authorizedWithdrawer"),
809
+ data: resolveAccountData(),
810
+ node: resolveAccount("nodePubkey"),
811
+ ownerProgram: resolveAccount("ownerProgram")
812
+ },
813
+ VoteAccountDataAuthorizedVoter: {
814
+ authorizedVoter: resolveAccount("authorizedVoter")
815
+ }
816
+ };
817
+
818
+ // src/resolvers/transaction.ts
819
+ function mapJsonParsedInstructions(instructions) {
820
+ return instructions.map((instruction) => {
821
+ if ("parsed" in instruction) {
822
+ if (typeof instruction.parsed === "string" && instruction.program === "spl-memo") {
823
+ const { parsed: memo, program: programName2, programId: programId2 } = instruction;
824
+ const instructionType2 = "memo";
825
+ const jsonParsedConfigs2 = {
826
+ instructionType: instructionType2,
827
+ programId: programId2,
828
+ programName: programName2
829
+ };
830
+ return { jsonParsedConfigs: jsonParsedConfigs2, memo, programId: programId2 };
831
+ }
832
+ const {
833
+ parsed: { info: data, type: instructionType },
834
+ program: programName,
835
+ programId
836
+ } = instruction;
837
+ const jsonParsedConfigs = {
838
+ instructionType,
839
+ programId,
840
+ programName
841
+ };
842
+ return { jsonParsedConfigs, ...data, programId };
843
+ } else {
844
+ return instruction;
845
+ }
846
+ });
847
+ }
848
+ function mapJsonParsedInnerInstructions(innerInstructions) {
849
+ return innerInstructions.map(({ index, instructions }) => ({
850
+ index,
851
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
852
+ instructions: mapJsonParsedInstructions(instructions)
853
+ }));
854
+ }
855
+ var resolveTransactionData = () => {
856
+ return (parent, args) => {
857
+ return parent === null ? null : parent.encodedData ? parent.encodedData[cacheKeyFn(args)] : null;
858
+ };
859
+ };
860
+ function resolveTransaction(fieldName) {
861
+ return async (parent, args, context, info) => {
862
+ const signature = fieldName ? parent[fieldName] : args.signature;
863
+ if (signature) {
864
+ if (onlyFieldsRequested(["signature"], info)) {
865
+ return { signature };
866
+ }
867
+ const argsSet = buildTransactionLoaderArgSetFromResolveInfo({ ...args, signature }, info);
868
+ const loadedTransactions = await context.loaders.transaction.loadMany(argsSet);
869
+ let result = {
870
+ encodedData: {},
871
+ signature
872
+ };
873
+ loadedTransactions.forEach((loadedTransaction, i) => {
874
+ if (loadedTransaction instanceof Error) {
875
+ console.error(loadedTransaction);
876
+ return;
877
+ }
878
+ if (loadedTransaction === null) {
879
+ return;
880
+ }
881
+ if (!result.slot) {
882
+ result = {
883
+ ...result,
884
+ ...loadedTransaction
885
+ };
886
+ }
887
+ const { transaction: data } = loadedTransaction;
888
+ const { encoding } = argsSet[i];
889
+ if (encoding && result.encodedData) {
890
+ if (Array.isArray(data)) {
891
+ result.encodedData[cacheKeyFn({
892
+ encoding
893
+ })] = data[0];
894
+ } else if (typeof data === "object") {
895
+ const jsonParsedData = data;
896
+ jsonParsedData.message.instructions = mapJsonParsedInstructions(
897
+ jsonParsedData.message.instructions
898
+ );
899
+ const loadedInnerInstructions = loadedTransaction.meta?.innerInstructions;
900
+ if (loadedInnerInstructions) {
901
+ const innerInstructions = mapJsonParsedInnerInstructions(loadedInnerInstructions);
902
+ const jsonParsedMeta = {
903
+ ...loadedTransaction.meta,
904
+ innerInstructions
905
+ };
906
+ result = {
907
+ ...result,
908
+ ...jsonParsedData,
909
+ meta: jsonParsedMeta
910
+ };
911
+ } else {
912
+ result = {
913
+ ...result,
914
+ ...jsonParsedData
915
+ };
916
+ }
917
+ }
918
+ }
919
+ });
920
+ return result;
921
+ }
922
+ return null;
923
+ };
924
+ }
925
+ var transactionResolvers = {
926
+ Transaction: {
927
+ data: resolveTransactionData()
928
+ }
929
+ };
930
+
931
+ // src/resolvers/block.ts
932
+ var resolveBlock = (fieldName) => {
933
+ return async (parent, args, context, info) => {
934
+ const slot = fieldName ? parent[fieldName] : args.slot;
935
+ if (slot) {
936
+ if (onlyFieldsRequested(["slot"], info)) {
937
+ return { slot };
938
+ }
939
+ const argsSet = buildBlockLoaderArgSetFromResolveInfo({ ...args, slot }, info);
940
+ const loadedBlocks = await context.loaders.block.loadMany(argsSet);
941
+ let result = {
942
+ slot
943
+ };
944
+ loadedBlocks.forEach((loadedBlock, i) => {
945
+ if (loadedBlock instanceof Error) {
946
+ console.error(loadedBlock);
947
+ return;
948
+ }
949
+ if (loadedBlock === null) {
950
+ return;
951
+ }
952
+ if (!result.blockhash) {
953
+ result = {
954
+ ...result,
955
+ ...loadedBlock
956
+ };
957
+ }
958
+ if (!result.signatures && loadedBlock.signatures) {
959
+ result = {
960
+ ...result,
961
+ // @ts-expect-error FIX ME: https://github.com/solana-labs/solana-web3.js/pull/2052
962
+ signatures: loadedBlock.signatures
963
+ };
964
+ }
965
+ if (!result.transactionResults && loadedBlock.transactions) {
966
+ result.transactionResults = Array.from({ length: loadedBlock.transactions.length }, (_, i2) => ({
967
+ [i2]: { encodedData: {} }
968
+ }));
969
+ }
970
+ const { transactions } = loadedBlock;
971
+ const { encoding } = argsSet[i];
972
+ if (encoding) {
973
+ transactions.forEach((loadedTransaction, j) => {
974
+ const { transaction: data } = loadedTransaction;
975
+ if (result.transactionResults) {
976
+ const thisTransactionResult = result.transactionResults[j] ||= {
977
+ encodedData: {}
978
+ };
979
+ if (Array.isArray(data)) {
980
+ const thisEncodedData = thisTransactionResult.encodedData ||= {};
981
+ thisEncodedData[cacheKeyFn({
982
+ encoding
983
+ })] = data[0];
984
+ } else if (typeof data === "object") {
985
+ const jsonParsedData = data;
986
+ jsonParsedData.message.instructions = mapJsonParsedInstructions(
987
+ jsonParsedData.message.instructions
988
+ );
989
+ const loadedInnerInstructions = loadedTransaction.meta?.innerInstructions;
990
+ if (loadedInnerInstructions) {
991
+ const innerInstructions = mapJsonParsedInnerInstructions(loadedInnerInstructions);
992
+ const jsonParsedMeta = {
993
+ ...loadedTransaction.meta,
994
+ innerInstructions
995
+ };
996
+ result.transactionResults[j] = {
997
+ ...thisTransactionResult,
998
+ ...jsonParsedData,
999
+ meta: jsonParsedMeta
1000
+ };
1001
+ } else {
1002
+ result.transactionResults[j] = {
1003
+ ...thisTransactionResult,
1004
+ ...jsonParsedData
1005
+ };
1006
+ }
1007
+ }
1008
+ }
1009
+ });
1010
+ }
1011
+ });
1012
+ return result;
1013
+ }
1014
+ return null;
1015
+ };
1016
+ };
1017
+ var blockResolvers = {
1018
+ Block: {
1019
+ transactions: (parent) => parent?.transactionResults ? Object.values(parent.transactionResults) : null
1020
+ }
1021
+ };
1022
+
1023
+ // src/resolvers/instruction.ts
1024
+ var instructionResolvers = {
1025
+ AdvanceNonceAccountInstruction: {
1026
+ nonceAccount: resolveAccount("nonceAccount"),
1027
+ nonceAuthority: resolveAccount("nonceAuthority"),
1028
+ recentBlockhashesSysvar: resolveAccount("recentBlockhashesSysvar")
1029
+ },
1030
+ AllocateInstruction: {
1031
+ account: resolveAccount("account")
1032
+ },
1033
+ AllocateWithSeedInstruction: {
1034
+ account: resolveAccount("account"),
1035
+ owner: resolveAccount("owner")
1036
+ },
1037
+ AssignInstruction: {
1038
+ account: resolveAccount("account"),
1039
+ owner: resolveAccount("owner")
1040
+ },
1041
+ AssignWithSeedInstruction: {
1042
+ account: resolveAccount("account"),
1043
+ owner: resolveAccount("owner")
1044
+ },
1045
+ AuthorizeNonceAccountInstruction: {
1046
+ newAuthorized: resolveAccount("newAuthorized"),
1047
+ nonceAccount: resolveAccount("nonceAccount"),
1048
+ nonceAuthority: resolveAccount("nonceAuthority")
1049
+ },
1050
+ BpfLoaderFinalizeInstruction: {
1051
+ account: resolveAccount("account")
1052
+ },
1053
+ BpfLoaderWriteInstruction: {
1054
+ account: resolveAccount("account")
1055
+ },
1056
+ BpfUpgradeableLoaderCloseInstruction: {
1057
+ account: resolveAccount("account"),
1058
+ authority: resolveAccount("authority"),
1059
+ programAccount: resolveAccount("programAccount"),
1060
+ recipient: resolveAccount("recipient")
1061
+ },
1062
+ BpfUpgradeableLoaderDeployWithMaxDataLenInstruction: {
1063
+ authority: resolveAccount("authority"),
1064
+ bufferAccount: resolveAccount("bufferAccount"),
1065
+ clockSysvar: resolveAccount("clockSysvar"),
1066
+ payerAccount: resolveAccount("payerAccount"),
1067
+ programAccount: resolveAccount("programAccount"),
1068
+ programDataAccount: resolveAccount("programDataAccount"),
1069
+ rentSysvar: resolveAccount("rentSysvar")
1070
+ },
1071
+ BpfUpgradeableLoaderExtendProgramInstruction: {
1072
+ payerAccount: resolveAccount("payerAccount"),
1073
+ programAccount: resolveAccount("programAccount"),
1074
+ programDataAccount: resolveAccount("programDataAccount"),
1075
+ systemProgram: resolveAccount("systemProgram")
1076
+ },
1077
+ BpfUpgradeableLoaderInitializeBufferInstruction: {
1078
+ account: resolveAccount("account")
1079
+ },
1080
+ BpfUpgradeableLoaderSetAuthorityCheckedInstruction: {
1081
+ account: resolveAccount("account"),
1082
+ authority: resolveAccount("authority"),
1083
+ newAuthority: resolveAccount("newAuthority")
1084
+ },
1085
+ BpfUpgradeableLoaderSetAuthorityInstruction: {
1086
+ account: resolveAccount("account"),
1087
+ authority: resolveAccount("authority"),
1088
+ newAuthority: resolveAccount("newAuthority")
1089
+ },
1090
+ BpfUpgradeableLoaderUpgradeInstruction: {
1091
+ authority: resolveAccount("authority"),
1092
+ bufferAccount: resolveAccount("bufferAccount"),
1093
+ clockSysvar: resolveAccount("clockSysvar"),
1094
+ programAccount: resolveAccount("programAccount"),
1095
+ programDataAccount: resolveAccount("programDataAccount"),
1096
+ rentSysvar: resolveAccount("rentSysvar")
1097
+ },
1098
+ BpfUpgradeableLoaderWriteInstruction: {
1099
+ account: resolveAccount("account"),
1100
+ authority: resolveAccount("authority")
1101
+ },
1102
+ CloseLookupTableInstruction: {
1103
+ lookupTableAccount: resolveAccount("lookupTableAccount"),
1104
+ lookupTableAuthority: resolveAccount("lookupTableAuthority"),
1105
+ recipient: resolveAccount("recipient")
1106
+ },
1107
+ CreateAccountInstruction: {
1108
+ newAccount: resolveAccount("newAccount"),
1109
+ owner: resolveAccount("owner"),
1110
+ source: resolveAccount("source")
1111
+ },
1112
+ CreateAccountWithSeedInstruction: {
1113
+ base: resolveAccount("base"),
1114
+ owner: resolveAccount("owner"),
1115
+ seed: resolveAccount("seed")
1116
+ },
1117
+ CreateLookupTableInstruction: {
1118
+ lookupTableAccount: resolveAccount("lookupTableAccount"),
1119
+ lookupTableAuthority: resolveAccount("lookupTableAuthority"),
1120
+ payerAccount: resolveAccount("payerAccount"),
1121
+ systemProgram: resolveAccount("systemProgram")
1122
+ },
1123
+ DeactivateLookupTableInstruction: {
1124
+ lookupTableAccount: resolveAccount("lookupTableAccount"),
1125
+ lookupTableAuthority: resolveAccount("lookupTableAuthority")
1126
+ },
1127
+ ExtendLookupTableInstruction: {
1128
+ lookupTableAccount: resolveAccount("lookupTableAccount"),
1129
+ lookupTableAuthority: resolveAccount("lookupTableAuthority"),
1130
+ payerAccount: resolveAccount("payerAccount"),
1131
+ systemProgram: resolveAccount("systemProgram")
1132
+ },
1133
+ FreezeLookupTableInstruction: {
1134
+ lookupTableAccount: resolveAccount("lookupTableAccount"),
1135
+ lookupTableAuthority: resolveAccount("lookupTableAuthority")
1136
+ },
1137
+ InitializeNonceAccountInstruction: {
1138
+ nonceAccount: resolveAccount("nonceAccount"),
1139
+ nonceAuthority: resolveAccount("nonceAuthority"),
1140
+ recentBlockhashesSysvar: resolveAccount("recentBlockhashesSysvar"),
1141
+ rentSysvar: resolveAccount("rentSysvar")
1142
+ },
1143
+ Lockup: {
1144
+ custodian: resolveAccount("custodian")
1145
+ },
1146
+ SplAssociatedTokenCreateIdempotentInstruction: {
1147
+ account: resolveAccount("account"),
1148
+ mint: resolveAccount("mint"),
1149
+ source: resolveAccount("source"),
1150
+ systemProgram: resolveAccount("systemProgram"),
1151
+ tokenProgram: resolveAccount("tokenProgram"),
1152
+ wallet: resolveAccount("wallet")
1153
+ },
1154
+ SplAssociatedTokenCreateInstruction: {
1155
+ account: resolveAccount("account"),
1156
+ mint: resolveAccount("mint"),
1157
+ source: resolveAccount("source"),
1158
+ systemProgram: resolveAccount("systemProgram"),
1159
+ tokenProgram: resolveAccount("tokenProgram"),
1160
+ wallet: resolveAccount("wallet")
1161
+ },
1162
+ SplAssociatedTokenRecoverNestedInstruction: {
1163
+ destination: resolveAccount("destination"),
1164
+ nestedMint: resolveAccount("nestedMint"),
1165
+ nestedOwner: resolveAccount("nestedOwner"),
1166
+ nestedSource: resolveAccount("nestedSource"),
1167
+ ownerMint: resolveAccount("ownerMint"),
1168
+ tokenProgram: resolveAccount("tokenProgram"),
1169
+ wallet: resolveAccount("wallet")
1170
+ },
1171
+ SplTokenAmountToUiAmountInstruction: {
1172
+ mint: resolveAccount("mint")
1173
+ },
1174
+ SplTokenApproveCheckedInstruction: {
1175
+ delegate: resolveAccount("delegate"),
1176
+ mint: resolveAccount("mint"),
1177
+ multisigOwner: resolveAccount("multisigOwner"),
1178
+ owner: resolveAccount("owner"),
1179
+ source: resolveAccount("source")
1180
+ },
1181
+ SplTokenApproveInstruction: {
1182
+ delegate: resolveAccount("delegate"),
1183
+ multisigOwner: resolveAccount("multisigOwner"),
1184
+ owner: resolveAccount("owner"),
1185
+ source: resolveAccount("source")
1186
+ },
1187
+ SplTokenBurnCheckedInstruction: {
1188
+ account: resolveAccount("account"),
1189
+ authority: resolveAccount("authority"),
1190
+ mint: resolveAccount("mint"),
1191
+ multisigAuthority: resolveAccount("multisigAuthority")
1192
+ },
1193
+ SplTokenBurnInstruction: {
1194
+ account: resolveAccount("account"),
1195
+ authority: resolveAccount("authority"),
1196
+ mint: resolveAccount("mint"),
1197
+ multisigAuthority: resolveAccount("multisigAuthority")
1198
+ },
1199
+ SplTokenCloseAccountInstruction: {
1200
+ account: resolveAccount("account"),
1201
+ destination: resolveAccount("destination"),
1202
+ multisigOwner: resolveAccount("multisigOwner"),
1203
+ owner: resolveAccount("owner")
1204
+ },
1205
+ SplTokenFreezeAccountInstruction: {
1206
+ account: resolveAccount("account"),
1207
+ freezeAuthority: resolveAccount("freezeAuthority"),
1208
+ mint: resolveAccount("mint"),
1209
+ multisigFreezeAuthority: resolveAccount("multisigFreezeAuthority")
1210
+ },
1211
+ SplTokenGetAccountDataSizeInstruction: {
1212
+ mint: resolveAccount("mint")
1213
+ },
1214
+ SplTokenInitializeAccount2Instruction: {
1215
+ account: resolveAccount("account"),
1216
+ mint: resolveAccount("mint"),
1217
+ owner: resolveAccount("owner"),
1218
+ rentSysvar: resolveAccount("rentSysvar")
1219
+ },
1220
+ SplTokenInitializeAccount3Instruction: {
1221
+ account: resolveAccount("account"),
1222
+ mint: resolveAccount("mint"),
1223
+ owner: resolveAccount("owner")
1224
+ },
1225
+ SplTokenInitializeAccountInstruction: {
1226
+ account: resolveAccount("account"),
1227
+ mint: resolveAccount("mint"),
1228
+ owner: resolveAccount("owner"),
1229
+ rentSysvar: resolveAccount("rentSysvar")
1230
+ },
1231
+ SplTokenInitializeMint2Instruction: {
1232
+ freezeAuthority: resolveAccount("freezeAuthority"),
1233
+ mint: resolveAccount("mint"),
1234
+ mintAuthority: resolveAccount("mintAuthority")
1235
+ },
1236
+ SplTokenInitializeMintCloseAuthorityInstruction: {
1237
+ mint: resolveAccount("mint"),
1238
+ newAuthority: resolveAccount("newAuthority")
1239
+ },
1240
+ SplTokenInitializeMintInstruction: {
1241
+ freezeAuthority: resolveAccount("freezeAuthority"),
1242
+ mint: resolveAccount("mint"),
1243
+ mintAuthority: resolveAccount("mintAuthority"),
1244
+ rentSysvar: resolveAccount("rentSysvar")
1245
+ },
1246
+ SplTokenInitializeMultisig2Instruction: {
1247
+ multisig: resolveAccount("multisig")
1248
+ },
1249
+ SplTokenInitializeMultisigInstruction: {
1250
+ multisig: resolveAccount("multisig"),
1251
+ rentSysvar: resolveAccount("rentSysvar")
1252
+ },
1253
+ SplTokenMintToCheckedInstruction: {
1254
+ account: resolveAccount("account"),
1255
+ authority: resolveAccount("authority"),
1256
+ mint: resolveAccount("mint"),
1257
+ mintAuthority: resolveAccount("mintAuthority"),
1258
+ multisigMintAuthority: resolveAccount("multisigMintAuthority")
1259
+ },
1260
+ SplTokenMintToInstruction: {
1261
+ account: resolveAccount("account"),
1262
+ authority: resolveAccount("authority"),
1263
+ mint: resolveAccount("mint"),
1264
+ mintAuthority: resolveAccount("mintAuthority"),
1265
+ multisigMintAuthority: resolveAccount("multisigMintAuthority")
1266
+ },
1267
+ SplTokenRevokeInstruction: {
1268
+ multisigOwner: resolveAccount("multisigOwner"),
1269
+ owner: resolveAccount("owner"),
1270
+ source: resolveAccount("source")
1271
+ },
1272
+ SplTokenSetAuthorityInstruction: {
1273
+ authority: resolveAccount("authority"),
1274
+ multisigAuthority: resolveAccount("multisigAuthority"),
1275
+ newAuthority: resolveAccount("newAuthority")
1276
+ },
1277
+ SplTokenSyncNativeInstruction: {
1278
+ account: resolveAccount("account")
1279
+ },
1280
+ SplTokenThawAccountInstruction: {
1281
+ account: resolveAccount("account"),
1282
+ freezeAuthority: resolveAccount("freezeAuthority"),
1283
+ mint: resolveAccount("mint"),
1284
+ multisigFreezeAuthority: resolveAccount("multisigFreezeAuthority")
1285
+ },
1286
+ SplTokenTransferCheckedInstruction: {
1287
+ authority: resolveAccount("authority"),
1288
+ destination: resolveAccount("destination"),
1289
+ mint: resolveAccount("mint"),
1290
+ multisigAuthority: resolveAccount("multisigAuthority"),
1291
+ source: resolveAccount("source")
1292
+ },
1293
+ SplTokenTransferInstruction: {
1294
+ authority: resolveAccount("authority"),
1295
+ destination: resolveAccount("destination"),
1296
+ multisigAuthority: resolveAccount("multisigAuthority"),
1297
+ source: resolveAccount("source")
1298
+ },
1299
+ SplTokenUiAmountToAmountInstruction: {
1300
+ mint: resolveAccount("mint")
1301
+ },
1302
+ StakeAuthorizeCheckedInstruction: {
1303
+ authority: resolveAccount("authority"),
1304
+ clockSysvar: resolveAccount("clockSysvar"),
1305
+ custodian: resolveAccount("custodian"),
1306
+ newAuthority: resolveAccount("newAuthority"),
1307
+ stakeAccount: resolveAccount("stakeAccount")
1308
+ },
1309
+ StakeAuthorizeCheckedWithSeedInstruction: {
1310
+ authorityBase: resolveAccount("authorityBase"),
1311
+ authorityOwner: resolveAccount("authorityOwner"),
1312
+ clockSysvar: resolveAccount("clockSysvar"),
1313
+ custodian: resolveAccount("custodian"),
1314
+ newAuthorized: resolveAccount("newAuthorized"),
1315
+ stakeAccount: resolveAccount("stakeAccount")
1316
+ },
1317
+ StakeAuthorizeInstruction: {
1318
+ authority: resolveAccount("authority"),
1319
+ clockSysvar: resolveAccount("clockSysvar"),
1320
+ custodian: resolveAccount("custodian"),
1321
+ newAuthority: resolveAccount("newAuthority"),
1322
+ stakeAccount: resolveAccount("stakeAccount")
1323
+ },
1324
+ StakeAuthorizeWithSeedInstruction: {
1325
+ authorityBase: resolveAccount("authorityBase"),
1326
+ authorityOwner: resolveAccount("authorityOwner"),
1327
+ clockSysvar: resolveAccount("clockSysvar"),
1328
+ custodian: resolveAccount("custodian"),
1329
+ newAuthorized: resolveAccount("newAuthorized"),
1330
+ stakeAccount: resolveAccount("stakeAccount")
1331
+ },
1332
+ StakeDeactivateDelinquentInstruction: {
1333
+ referenceVoteAccount: resolveAccount("referenceVoteAccount"),
1334
+ stakeAccount: resolveAccount("stakeAccount"),
1335
+ voteAccount: resolveAccount("voteAccount")
1336
+ },
1337
+ StakeDeactivateInstruction: {
1338
+ clockSysvar: resolveAccount("clockSysvar"),
1339
+ stakeAccount: resolveAccount("stakeAccount"),
1340
+ stakeAuthority: resolveAccount("stakeAuthority")
1341
+ },
1342
+ StakeDelegateStakeInstruction: {
1343
+ clockSysvar: resolveAccount("clockSysvar"),
1344
+ stakeAccount: resolveAccount("stakeAccount"),
1345
+ stakeAuthority: resolveAccount("stakeAuthority"),
1346
+ stakeConfigAccount: resolveAccount("stakeConfigAccount"),
1347
+ stakeHistorySysvar: resolveAccount("stakeHistorySysvar"),
1348
+ voteAccount: resolveAccount("voteAccount")
1349
+ },
1350
+ StakeInitializeCheckedInstruction: {
1351
+ rentSysvar: resolveAccount("rentSysvar"),
1352
+ stakeAccount: resolveAccount("stakeAccount")
1353
+ },
1354
+ StakeInitializeCheckedInstructionDataAuthorized: {
1355
+ staker: resolveAccount("staker"),
1356
+ withdrawer: resolveAccount("withdrawer")
1357
+ },
1358
+ StakeInitializeInstruction: {
1359
+ rentSysvar: resolveAccount("rentSysvar"),
1360
+ stakeAccount: resolveAccount("stakeAccount")
1361
+ },
1362
+ StakeInitializeInstructionDataAuthorized: {
1363
+ staker: resolveAccount("staker"),
1364
+ withdrawer: resolveAccount("withdrawer")
1365
+ },
1366
+ StakeMergeInstruction: {
1367
+ clockSysvar: resolveAccount("clockSysvar"),
1368
+ destination: resolveAccount("destination"),
1369
+ source: resolveAccount("source"),
1370
+ stakeAuthority: resolveAccount("stakeAuthority"),
1371
+ stakeHistorySysvar: resolveAccount("stakeHistorySysvar")
1372
+ },
1373
+ StakeRedelegateInstruction: {
1374
+ newStakeAccount: resolveAccount("newStakeAccount"),
1375
+ stakeAccount: resolveAccount("stakeAccount"),
1376
+ stakeAuthority: resolveAccount("stakeAuthority"),
1377
+ stakeConfigAccount: resolveAccount("stakeConfigAccount"),
1378
+ voteAccount: resolveAccount("voteAccount")
1379
+ },
1380
+ StakeSetLockupCheckedInstruction: {
1381
+ custodian: resolveAccount("custodian"),
1382
+ stakeAccount: resolveAccount("stakeAccount")
1383
+ },
1384
+ StakeSetLockupInstruction: {
1385
+ custodian: resolveAccount("custodian"),
1386
+ stakeAccount: resolveAccount("stakeAccount")
1387
+ },
1388
+ StakeSplitInstruction: {
1389
+ newSplitAccount: resolveAccount("newSplitAccount"),
1390
+ stakeAccount: resolveAccount("stakeAccount"),
1391
+ stakeAuthority: resolveAccount("stakeAuthority")
1392
+ },
1393
+ StakeWithdrawInstruction: {
1394
+ clockSysvar: resolveAccount("clockSysvar"),
1395
+ destination: resolveAccount("destination"),
1396
+ stakeAccount: resolveAccount("stakeAccount"),
1397
+ withdrawAuthority: resolveAccount("withdrawAuthority")
1398
+ },
1399
+ TransactionInstruction: {
1400
+ __resolveType(instructionResult) {
1401
+ const { jsonParsedConfigs } = instructionResult;
1402
+ if (jsonParsedConfigs) {
1403
+ if (jsonParsedConfigs.programName === "address-lookup-table") {
1404
+ if (jsonParsedConfigs.instructionType === "createLookupTable") {
1405
+ return "CreateLookupTableInstruction";
1406
+ }
1407
+ if (jsonParsedConfigs.instructionType === "freezeLookupTable") {
1408
+ return "FreezeLookupTableInstruction";
1409
+ }
1410
+ if (jsonParsedConfigs.instructionType === "extendLookupTable") {
1411
+ return "ExtendLookupTableInstruction";
1412
+ }
1413
+ if (jsonParsedConfigs.instructionType === "deactivateLookupTable") {
1414
+ return "DeactivateLookupTableInstruction";
1415
+ }
1416
+ if (jsonParsedConfigs.instructionType === "closeLookupTable") {
1417
+ return "CloseLookupTableInstruction";
1418
+ }
1419
+ }
1420
+ if (jsonParsedConfigs.programName === "bpf-loader") {
1421
+ if (jsonParsedConfigs.instructionType === "write") {
1422
+ return "BpfLoaderWriteInstruction";
1423
+ }
1424
+ if (jsonParsedConfigs.instructionType === "finalize") {
1425
+ return "BpfLoaderFinalizeInstruction";
1426
+ }
1427
+ }
1428
+ if (jsonParsedConfigs.programName === "bpf-upgradeable-loader") {
1429
+ if (jsonParsedConfigs.instructionType === "initializeBuffer") {
1430
+ return "BpfUpgradeableLoaderInitializeBufferInstruction";
1431
+ }
1432
+ if (jsonParsedConfigs.instructionType === "write") {
1433
+ return "BpfUpgradeableLoaderWriteInstruction";
1434
+ }
1435
+ if (jsonParsedConfigs.instructionType === "deployWithMaxDataLen") {
1436
+ return "BpfUpgradeableLoaderDeployWithMaxDataLenInstruction";
1437
+ }
1438
+ if (jsonParsedConfigs.instructionType === "upgrade") {
1439
+ return "BpfUpgradeableLoaderUpgradeInstruction";
1440
+ }
1441
+ if (jsonParsedConfigs.instructionType === "setAuthority") {
1442
+ return "BpfUpgradeableLoaderSetAuthorityInstruction";
1443
+ }
1444
+ if (jsonParsedConfigs.instructionType === "setAuthorityChecked") {
1445
+ return "BpfUpgradeableLoaderSetAuthorityCheckedInstruction";
1446
+ }
1447
+ if (jsonParsedConfigs.instructionType === "close") {
1448
+ return "BpfUpgradeableLoaderCloseInstruction";
1449
+ }
1450
+ if (jsonParsedConfigs.instructionType === "extendProgram") {
1451
+ return "BpfUpgradeableLoaderExtendProgramInstruction";
1452
+ }
1453
+ }
1454
+ if (jsonParsedConfigs.programName === "spl-associated-token-account") {
1455
+ if (jsonParsedConfigs.instructionType === "create") {
1456
+ return "SplAssociatedTokenCreateInstruction";
1457
+ }
1458
+ if (jsonParsedConfigs.instructionType === "createIdempotent") {
1459
+ return "SplAssociatedTokenCreateIdempotentInstruction";
1460
+ }
1461
+ if (jsonParsedConfigs.instructionType === "recoverNested") {
1462
+ return "SplAssociatedTokenRecoverNestedInstruction";
1463
+ }
1464
+ }
1465
+ if (jsonParsedConfigs.programName === "spl-memo") {
1466
+ return "SplMemoInstruction";
1467
+ }
1468
+ if (jsonParsedConfigs.programName === "spl-token") {
1469
+ if (jsonParsedConfigs.instructionType === "initializeMint") {
1470
+ return "SplTokenInitializeMintInstruction";
1471
+ }
1472
+ if (jsonParsedConfigs.instructionType === "initializeMint2") {
1473
+ return "SplTokenInitializeMint2Instruction";
1474
+ }
1475
+ if (jsonParsedConfigs.instructionType === "initializeAccount") {
1476
+ return "SplTokenInitializeAccountInstruction";
1477
+ }
1478
+ if (jsonParsedConfigs.instructionType === "initializeAccount2") {
1479
+ return "SplTokenInitializeAccount2Instruction";
1480
+ }
1481
+ if (jsonParsedConfigs.instructionType === "initializeAccount3") {
1482
+ return "SplTokenInitializeAccount3Instruction";
1483
+ }
1484
+ if (jsonParsedConfigs.instructionType === "initializeMultisig") {
1485
+ return "SplTokenInitializeMultisigInstruction";
1486
+ }
1487
+ if (jsonParsedConfigs.instructionType === "initializeMultisig2") {
1488
+ return "SplTokenInitializeMultisig2Instruction";
1489
+ }
1490
+ if (jsonParsedConfigs.instructionType === "transfer") {
1491
+ return "SplTokenTransferInstruction";
1492
+ }
1493
+ if (jsonParsedConfigs.instructionType === "approve") {
1494
+ return "SplTokenApproveInstruction";
1495
+ }
1496
+ if (jsonParsedConfigs.instructionType === "revoke") {
1497
+ return "SplTokenRevokeInstruction";
1498
+ }
1499
+ if (jsonParsedConfigs.instructionType === "setAuthority") {
1500
+ return "SplTokenSetAuthorityInstruction";
1501
+ }
1502
+ if (jsonParsedConfigs.instructionType === "mintTo") {
1503
+ return "SplTokenMintToInstruction";
1504
+ }
1505
+ if (jsonParsedConfigs.instructionType === "burn") {
1506
+ return "SplTokenBurnInstruction";
1507
+ }
1508
+ if (jsonParsedConfigs.instructionType === "closeAccount") {
1509
+ return "SplTokenCloseAccountInstruction";
1510
+ }
1511
+ if (jsonParsedConfigs.instructionType === "freezeAccount") {
1512
+ return "SplTokenFreezeAccountInstruction";
1513
+ }
1514
+ if (jsonParsedConfigs.instructionType === "thawAccount") {
1515
+ return "SplTokenThawAccountInstruction";
1516
+ }
1517
+ if (jsonParsedConfigs.instructionType === "transferChecked") {
1518
+ return "SplTokenTransferCheckedInstruction";
1519
+ }
1520
+ if (jsonParsedConfigs.instructionType === "approveChecked") {
1521
+ return "SplTokenApproveCheckedInstruction";
1522
+ }
1523
+ if (jsonParsedConfigs.instructionType === "mintToChecked") {
1524
+ return "SplTokenMintToCheckedInstruction";
1525
+ }
1526
+ if (jsonParsedConfigs.instructionType === "burnChecked") {
1527
+ return "SplTokenBurnCheckedInstruction";
1528
+ }
1529
+ if (jsonParsedConfigs.instructionType === "syncNative") {
1530
+ return "SplTokenSyncNativeInstruction";
1531
+ }
1532
+ if (jsonParsedConfigs.instructionType === "getAccountDataSize") {
1533
+ return "SplTokenGetAccountDataSizeInstruction";
1534
+ }
1535
+ if (jsonParsedConfigs.instructionType === "initializeImmutableOwner") {
1536
+ return "SplTokenInitializeImmutableOwnerInstruction";
1537
+ }
1538
+ if (jsonParsedConfigs.instructionType === "amountToUiAmount") {
1539
+ return "SplTokenAmountToUiAmountInstruction";
1540
+ }
1541
+ if (jsonParsedConfigs.instructionType === "uiAmountToAmount") {
1542
+ return "SplTokenUiAmountToAmountInstruction";
1543
+ }
1544
+ if (jsonParsedConfigs.instructionType === "initializeMintCloseAuthority") {
1545
+ return "SplTokenInitializeMintCloseAuthorityInstruction";
1546
+ }
1547
+ }
1548
+ if (jsonParsedConfigs.programName === "stake") {
1549
+ if (jsonParsedConfigs.instructionType === "initialize") {
1550
+ return "StakeInitializeInstruction";
1551
+ }
1552
+ if (jsonParsedConfigs.instructionType === "authorize") {
1553
+ return "StakeAuthorizeInstruction";
1554
+ }
1555
+ if (jsonParsedConfigs.instructionType === "delegate") {
1556
+ return "StakeDelegateStakeInstruction";
1557
+ }
1558
+ if (jsonParsedConfigs.instructionType === "split") {
1559
+ return "StakeSplitInstruction";
1560
+ }
1561
+ if (jsonParsedConfigs.instructionType === "withdraw") {
1562
+ return "StakeWithdrawInstruction";
1563
+ }
1564
+ if (jsonParsedConfigs.instructionType === "deactivate") {
1565
+ return "StakeDeactivateInstruction";
1566
+ }
1567
+ if (jsonParsedConfigs.instructionType === "setLockup") {
1568
+ return "StakeSetLockupInstruction";
1569
+ }
1570
+ if (jsonParsedConfigs.instructionType === "merge") {
1571
+ return "StakeMergeInstruction";
1572
+ }
1573
+ if (jsonParsedConfigs.instructionType === "authorizeWithSeed") {
1574
+ return "StakeAuthorizeWithSeedInstruction";
1575
+ }
1576
+ if (jsonParsedConfigs.instructionType === "initializeChecked") {
1577
+ return "StakeInitializeCheckedInstruction";
1578
+ }
1579
+ if (jsonParsedConfigs.instructionType === "authorizeChecked") {
1580
+ return "StakeAuthorizeCheckedInstruction";
1581
+ }
1582
+ if (jsonParsedConfigs.instructionType === "authorizeCheckedWithSeed") {
1583
+ return "StakeAuthorizeCheckedWithSeedInstruction";
1584
+ }
1585
+ if (jsonParsedConfigs.instructionType === "setLockupChecked") {
1586
+ return "StakeSetLockupCheckedInstruction";
1587
+ }
1588
+ if (jsonParsedConfigs.instructionType === "deactivateDelinquent") {
1589
+ return "StakeDeactivateDelinquentInstruction";
1590
+ }
1591
+ if (jsonParsedConfigs.instructionType === "redelegate") {
1592
+ return "StakeRedelegateInstruction";
1593
+ }
1594
+ }
1595
+ if (jsonParsedConfigs.programName === "system") {
1596
+ if (jsonParsedConfigs.instructionType === "createAccount") {
1597
+ return "CreateAccountInstruction";
1598
+ }
1599
+ if (jsonParsedConfigs.instructionType === "assign") {
1600
+ return "AssignInstruction";
1601
+ }
1602
+ if (jsonParsedConfigs.instructionType === "transfer") {
1603
+ return "TransferInstruction";
1604
+ }
1605
+ if (jsonParsedConfigs.instructionType === "createAccountWithSeed") {
1606
+ return "CreateAccountWithSeedInstruction";
1607
+ }
1608
+ if (jsonParsedConfigs.instructionType === "advanceNonceAccount") {
1609
+ return "AdvanceNonceAccountInstruction";
1610
+ }
1611
+ if (jsonParsedConfigs.instructionType === "withdrawNonceAccount") {
1612
+ return "WithdrawNonceAccountInstruction";
1613
+ }
1614
+ if (jsonParsedConfigs.instructionType === "initializeNonceAccount") {
1615
+ return "InitializeNonceAccountInstruction";
1616
+ }
1617
+ if (jsonParsedConfigs.instructionType === "authorizeNonceAccount") {
1618
+ return "AuthorizeNonceAccountInstruction";
1619
+ }
1620
+ if (jsonParsedConfigs.instructionType === "upgradeNonceAccount") {
1621
+ return "UpgradeNonceAccountInstruction";
1622
+ }
1623
+ if (jsonParsedConfigs.instructionType === "allocate") {
1624
+ return "AllocateInstruction";
1625
+ }
1626
+ if (jsonParsedConfigs.instructionType === "allocateWithSeed") {
1627
+ return "AllocateWithSeedInstruction";
1628
+ }
1629
+ if (jsonParsedConfigs.instructionType === "assignWithSeed") {
1630
+ return "AssignWithSeedInstruction";
1631
+ }
1632
+ if (jsonParsedConfigs.instructionType === "transferWithSeed") {
1633
+ return "TransferWithSeedInstruction";
1634
+ }
1635
+ }
1636
+ if (jsonParsedConfigs.programName === "vote") {
1637
+ if (jsonParsedConfigs.instructionType === "initialize") {
1638
+ return "VoteInitializeAccountInstruction";
1639
+ }
1640
+ if (jsonParsedConfigs.instructionType === "authorize") {
1641
+ return "VoteAuthorizeInstruction";
1642
+ }
1643
+ if (jsonParsedConfigs.instructionType === "authorizeWithSeed") {
1644
+ return "VoteAuthorizeWithSeedInstruction";
1645
+ }
1646
+ if (jsonParsedConfigs.instructionType === "authorizeCheckedWithSeed") {
1647
+ return "VoteAuthorizeCheckedWithSeedInstruction";
1648
+ }
1649
+ if (jsonParsedConfigs.instructionType === "vote") {
1650
+ return "VoteVoteInstruction";
1651
+ }
1652
+ if (jsonParsedConfigs.instructionType === "updatevotestate") {
1653
+ return "VoteUpdateVoteStateInstruction";
1654
+ }
1655
+ if (jsonParsedConfigs.instructionType === "updatevotestateswitch") {
1656
+ return "VoteUpdateVoteStateSwitchInstruction";
1657
+ }
1658
+ if (jsonParsedConfigs.instructionType === "compactupdatevotestate") {
1659
+ return "VoteCompactUpdateVoteStateInstruction";
1660
+ }
1661
+ if (jsonParsedConfigs.instructionType === "compactupdatevotestateswitch") {
1662
+ return "VoteCompactUpdateVoteStateSwitchInstruction";
1663
+ }
1664
+ if (jsonParsedConfigs.instructionType === "withdraw") {
1665
+ return "VoteWithdrawInstruction";
1666
+ }
1667
+ if (jsonParsedConfigs.instructionType === "updateValidatorIdentity") {
1668
+ return "VoteUpdateValidatorIdentityInstruction";
1669
+ }
1670
+ if (jsonParsedConfigs.instructionType === "updateCommission") {
1671
+ return "VoteUpdateCommissionInstruction";
1672
+ }
1673
+ if (jsonParsedConfigs.instructionType === "voteSwitch") {
1674
+ return "VoteVoteSwitchInstruction";
1675
+ }
1676
+ if (jsonParsedConfigs.instructionType === "authorizeChecked") {
1677
+ return "VoteAuthorizeCheckedInstruction";
1678
+ }
1679
+ }
1680
+ }
1681
+ return "GenericInstruction";
1682
+ }
1683
+ },
1684
+ TransferInstruction: {
1685
+ destination: resolveAccount("destination"),
1686
+ source: resolveAccount("source")
1687
+ },
1688
+ TransferWithSeedInstruction: {
1689
+ destination: resolveAccount("destination"),
1690
+ source: resolveAccount("source"),
1691
+ sourceOwner: resolveAccount("sourceOwner")
1692
+ },
1693
+ UpgradeNonceAccountInstruction: {
1694
+ nonceAccount: resolveAccount("nonceAccount"),
1695
+ nonceAuthority: resolveAccount("nonceAuthority")
1696
+ },
1697
+ VoteAuthorizeCheckedInstruction: {
1698
+ authority: resolveAccount("authority"),
1699
+ clockSysvar: resolveAccount("clockSysvar"),
1700
+ newAuthority: resolveAccount("newAuthority"),
1701
+ voteAccount: resolveAccount("voteAccount")
1702
+ },
1703
+ VoteAuthorizeCheckedWithSeedInstruction: {
1704
+ authorityOwner: resolveAccount("authorityOwner"),
1705
+ clockSysvar: resolveAccount("clockSysvar"),
1706
+ newAuthority: resolveAccount("newAuthority"),
1707
+ voteAccount: resolveAccount("voteAccount")
1708
+ },
1709
+ VoteAuthorizeInstruction: {
1710
+ authority: resolveAccount("authority"),
1711
+ clockSysvar: resolveAccount("clockSysvar"),
1712
+ newAuthority: resolveAccount("newAuthority"),
1713
+ voteAccount: resolveAccount("voteAccount")
1714
+ },
1715
+ VoteAuthorizeWithSeedInstruction: {
1716
+ authorityOwner: resolveAccount("authorityOwner"),
1717
+ clockSysvar: resolveAccount("clockSysvar"),
1718
+ newAuthority: resolveAccount("newAuthority"),
1719
+ voteAccount: resolveAccount("voteAccount")
1720
+ },
1721
+ VoteCompactUpdateVoteStateInstruction: {
1722
+ voteAccount: resolveAccount("voteAccount"),
1723
+ voteAuthority: resolveAccount("voteAuthority")
1724
+ },
1725
+ VoteCompactUpdateVoteStateSwitchInstruction: {
1726
+ voteAccount: resolveAccount("voteAccount"),
1727
+ voteAuthority: resolveAccount("voteAuthority")
1728
+ },
1729
+ VoteInitializeAccountInstruction: {
1730
+ authorizedVoter: resolveAccount("authorizedVoter"),
1731
+ authorizedWithdrawer: resolveAccount("authorizedWithdrawer"),
1732
+ clockSysvar: resolveAccount("clockSysvar"),
1733
+ node: resolveAccount("node"),
1734
+ rentSysvar: resolveAccount("rentSysvar"),
1735
+ voteAccount: resolveAccount("voteAccount")
1736
+ },
1737
+ VoteUpdateCommissionInstruction: {
1738
+ voteAccount: resolveAccount("voteAccount"),
1739
+ withdrawAuthority: resolveAccount("withdrawAuthority")
1740
+ },
1741
+ VoteUpdateValidatorIdentityInstruction: {
1742
+ newValidatorIdentity: resolveAccount("newValidatorIdentity"),
1743
+ voteAccount: resolveAccount("voteAccount"),
1744
+ withdrawAuthority: resolveAccount("withdrawAuthority")
1745
+ },
1746
+ VoteUpdateVoteStateInstruction: {
1747
+ voteAccount: resolveAccount("voteAccount"),
1748
+ voteAuthority: resolveAccount("voteAuthority")
1749
+ },
1750
+ VoteUpdateVoteStateSwitchInstruction: {
1751
+ voteAccount: resolveAccount("voteAccount"),
1752
+ voteAuthority: resolveAccount("voteAuthority")
1753
+ },
1754
+ VoteVoteInstruction: {
1755
+ clockSysvar: resolveAccount("clockSysvar"),
1756
+ slotHashesSysvar: resolveAccount("slotHashesSysvar"),
1757
+ voteAccount: resolveAccount("voteAccount"),
1758
+ voteAuthority: resolveAccount("voteAuthority")
1759
+ },
1760
+ VoteVoteSwitchInstruction: {
1761
+ clockSysvar: resolveAccount("clockSysvar"),
1762
+ slotHashesSysvar: resolveAccount("slotHashesSysvar"),
1763
+ voteAccount: resolveAccount("voteAccount"),
1764
+ voteAuthority: resolveAccount("voteAuthority")
1765
+ },
1766
+ VoteWithdrawInstruction: {
1767
+ voteAccount: resolveAccount("voteAccount"),
1768
+ withdrawAuthority: resolveAccount("withdrawAuthority")
1769
+ },
1770
+ WithdrawNonceAccountInstruction: {
1771
+ destination: resolveAccount("destination"),
1772
+ nonceAccount: resolveAccount("nonceAccount"),
1773
+ nonceAuthority: resolveAccount("nonceAuthority"),
1774
+ recentBlockhashesSysvar: resolveAccount("recentBlockhashesSysvar"),
1775
+ rentSysvar: resolveAccount("rentSysvar")
1776
+ }
1777
+ };
1778
+
1779
+ // src/resolvers/program-accounts.ts
1780
+ function resolveProgramAccounts(fieldName) {
1781
+ return async (parent, args, context, info) => {
1782
+ const programAddress = fieldName ? parent[fieldName] : args.programAddress;
1783
+ if (programAddress) {
1784
+ const argsSet = buildProgramAccountsLoaderArgSetFromResolveInfo({ ...args, programAddress }, info);
1785
+ const loadedProgramAccountsLists = await context.loaders.programAccounts.loadMany(argsSet);
1786
+ const result = {};
1787
+ loadedProgramAccountsLists.forEach((programAccounts, i) => {
1788
+ if (programAccounts instanceof Error) {
1789
+ console.error(programAccounts);
1790
+ return;
1791
+ }
1792
+ programAccounts.forEach((programAccount) => {
1793
+ const { account, pubkey: address } = programAccount;
1794
+ const thisResult = result[address] ||= {
1795
+ ...account,
1796
+ address,
1797
+ encodedData: {},
1798
+ ownerProgram: account.owner
1799
+ };
1800
+ const { data } = account;
1801
+ const { encoding, dataSlice } = argsSet[i];
1802
+ if (encoding && thisResult.encodedData) {
1803
+ if (Array.isArray(data)) {
1804
+ thisResult.encodedData[cacheKeyFn({
1805
+ dataSlice,
1806
+ encoding: encoding === "jsonParsed" ? "base64" : encoding
1807
+ })] = data[0];
1808
+ } else if (typeof data === "string") {
1809
+ thisResult.encodedData[cacheKeyFn({
1810
+ dataSlice,
1811
+ encoding: "base58"
1812
+ })] = data;
1813
+ } else if (typeof data === "object") {
1814
+ const {
1815
+ parsed: { info: parsedData, type: accountType },
1816
+ program: programName,
1817
+ programId
1818
+ } = data;
1819
+ thisResult.jsonParsedConfigs = {
1820
+ accountType,
1821
+ programId,
1822
+ programName
1823
+ };
1824
+ for (const key in parsedData) {
1825
+ thisResult[key] = parsedData[key];
1826
+ }
1827
+ }
1828
+ }
1829
+ });
1830
+ });
1831
+ return Object.values(result);
1832
+ }
1833
+ return null;
1834
+ };
1835
+ }
1836
+
1837
+ // src/resolvers/root.ts
1838
+ var rootResolvers = {
1839
+ Query: {
1840
+ account: resolveAccount(),
1841
+ block: resolveBlock(),
1842
+ programAccounts: resolveProgramAccounts(),
1843
+ transaction: resolveTransaction()
1844
+ }
1845
+ };
1846
+ var stringScalarAlias = {
1847
+ __parseLiteral(ast) {
1848
+ if (ast.kind === Kind.STRING) {
1849
+ return ast.value.toString();
1850
+ }
1851
+ return null;
1852
+ },
1853
+ __parseValue(value) {
1854
+ return value;
1855
+ },
1856
+ __serialize(value) {
1857
+ return value;
1858
+ }
1859
+ };
1860
+ var bigIntScalarAlias = {
1861
+ __parseLiteral(ast) {
1862
+ if (ast.kind === Kind.STRING || ast.kind === Kind.INT || ast.kind === Kind.FLOAT) {
1863
+ return BigInt(ast.value);
1864
+ }
1865
+ return null;
1866
+ },
1867
+ __parseValue(value) {
1868
+ return BigInt(value);
1869
+ },
1870
+ __serialize(value) {
1871
+ return BigInt(value);
1872
+ }
1873
+ };
1874
+ var typeTypeResolvers = {
1875
+ AccountEncoding: {
1876
+ BASE_58: "base58",
1877
+ BASE_64: "base64",
1878
+ BASE_64_ZSTD: "base64+zstd"
1879
+ },
1880
+ Address: stringScalarAlias,
1881
+ Base58EncodedBytes: stringScalarAlias,
1882
+ Base64EncodedBytes: stringScalarAlias,
1883
+ Base64ZstdEncodedBytes: stringScalarAlias,
1884
+ BigInt: bigIntScalarAlias,
1885
+ Commitment: {
1886
+ CONFIRMED: "confirmed",
1887
+ FINALIZED: "finalized",
1888
+ PROCESSED: "processed"
1889
+ },
1890
+ CommitmentWithoutProcessed: {
1891
+ CONFIRMED: "confirmed",
1892
+ FINALIZED: "finalized"
1893
+ },
1894
+ Signature: stringScalarAlias,
1895
+ Slot: bigIntScalarAlias,
1896
+ TokenBalance: {
1897
+ mint: resolveAccount("mint"),
1898
+ owner: resolveAccount("owner")
1899
+ },
1900
+ TransactionEncoding: {
1901
+ BASE_58: "base58",
1902
+ BASE_64: "base64"
1903
+ }
1904
+ };
1905
+
1906
+ // src/resolvers/index.ts
1907
+ function createSolanaGraphQLResolvers() {
1908
+ return {
1909
+ ...accountResolvers,
1910
+ ...blockResolvers,
1911
+ ...instructionResolvers,
1912
+ ...rootResolvers,
1913
+ ...transactionResolvers,
1914
+ ...typeTypeResolvers
1915
+ };
1916
+ }
1917
+
1918
+ // src/schema/account.ts
1919
+ var accountTypeDefs = (
1920
+ /* GraphQL */
1921
+ `
1922
+ """
1923
+ Account interface
1924
+ """
1925
+ interface Account {
1926
+ address: Address
1927
+ data(encoding: AccountEncoding!, dataSlice: DataSlice): String
1928
+ executable: Boolean
1929
+ lamports: BigInt
1930
+ ownerProgram: Account
1931
+ space: BigInt
1932
+ rentEpoch: BigInt
1933
+ }
1934
+
1935
+ """
1936
+ Generic base account type
1937
+ """
1938
+ type GenericAccount implements Account {
1939
+ address: Address
1940
+ data(encoding: AccountEncoding!, dataSlice: DataSlice): String
1941
+ executable: Boolean
1942
+ lamports: BigInt
1943
+ ownerProgram: Account
1944
+ space: BigInt
1945
+ rentEpoch: BigInt
1946
+ }
1947
+
1948
+ type NonceAccountFeeCalculator {
1949
+ lamportsPerSignature: String
1950
+ }
1951
+ """
1952
+ A nonce account
1953
+ """
1954
+ type NonceAccount implements Account {
1955
+ address: Address
1956
+ data(encoding: AccountEncoding!, dataSlice: DataSlice): String
1957
+ executable: Boolean
1958
+ lamports: BigInt
1959
+ ownerProgram: Account
1960
+ space: BigInt
1961
+ rentEpoch: BigInt
1962
+ authority: Account
1963
+ blockhash: String
1964
+ feeCalculator: NonceAccountFeeCalculator
1965
+ }
1966
+
1967
+ """
1968
+ A lookup table account
1969
+ """
1970
+ type LookupTableAccount implements Account {
1971
+ address: Address
1972
+ data(encoding: AccountEncoding!, dataSlice: DataSlice): String
1973
+ executable: Boolean
1974
+ lamports: BigInt
1975
+ ownerProgram: Account
1976
+ space: BigInt
1977
+ rentEpoch: BigInt
1978
+ addresses: [Address]
1979
+ authority: Account
1980
+ deactivationSlot: String
1981
+ lastExtendedSlot: String
1982
+ lastExtendedSlotStartIndex: Int
1983
+ }
1984
+
1985
+ """
1986
+ A mint account
1987
+ """
1988
+ type MintAccount implements Account {
1989
+ address: Address
1990
+ data(encoding: AccountEncoding!, dataSlice: DataSlice): String
1991
+ executable: Boolean
1992
+ lamports: BigInt
1993
+ ownerProgram: Account
1994
+ space: BigInt
1995
+ rentEpoch: BigInt
1996
+ decimals: Int
1997
+ freezeAuthority: Account
1998
+ isInitialized: Boolean
1999
+ mintAuthority: Account
2000
+ supply: String
2001
+ }
2002
+
2003
+ """
2004
+ A token account
2005
+ """
2006
+ type TokenAccount implements Account {
2007
+ address: Address
2008
+ data(encoding: AccountEncoding!, dataSlice: DataSlice): String
2009
+ executable: Boolean
2010
+ lamports: BigInt
2011
+ ownerProgram: Account
2012
+ space: BigInt
2013
+ rentEpoch: BigInt
2014
+ isNative: Boolean
2015
+ mint: Account
2016
+ owner: Account
2017
+ state: String
2018
+ tokenAmount: TokenAmount
2019
+ }
2020
+
2021
+ type StakeAccountDataMetaAuthorized {
2022
+ staker: Account
2023
+ withdrawer: Account
2024
+ }
2025
+ type StakeAccountDataMetaLockup {
2026
+ custodian: Account
2027
+ epoch: BigInt
2028
+ unixTimestamp: BigInt
2029
+ }
2030
+ type StakeAccountDataMeta {
2031
+ authorized: StakeAccountDataMetaAuthorized
2032
+ lockup: StakeAccountDataMetaLockup
2033
+ rentExemptReserve: String
2034
+ }
2035
+ type StakeAccountDataStakeDelegation {
2036
+ activationEpoch: BigInt
2037
+ deactivationEpoch: BigInt
2038
+ stake: String
2039
+ voter: Account
2040
+ warmupCooldownRate: Int
2041
+ }
2042
+ type StakeAccountDataStake {
2043
+ creditsObserved: BigInt
2044
+ delegation: StakeAccountDataStakeDelegation
2045
+ }
2046
+ """
2047
+ A stake account
2048
+ """
2049
+ type StakeAccount implements Account {
2050
+ address: Address
2051
+ data(encoding: AccountEncoding!, dataSlice: DataSlice): String
2052
+ executable: Boolean
2053
+ lamports: BigInt
2054
+ ownerProgram: Account
2055
+ space: BigInt
2056
+ rentEpoch: BigInt
2057
+ meta: StakeAccountDataMeta
2058
+ stake: StakeAccountDataStake
2059
+ }
2060
+
2061
+ type VoteAccountDataAuthorizedVoter {
2062
+ authorizedVoter: Account
2063
+ epoch: BigInt
2064
+ }
2065
+ type VoteAccountDataEpochCredit {
2066
+ credits: String
2067
+ epoch: BigInt
2068
+ previousCredits: String
2069
+ }
2070
+ type VoteAccountDataLastTimestamp {
2071
+ slot: BigInt
2072
+ timestamp: BigInt
2073
+ }
2074
+ type VoteAccountDataVote {
2075
+ confirmationCount: Int
2076
+ slot: BigInt
2077
+ }
2078
+ """
2079
+ A vote account
2080
+ """
2081
+ type VoteAccount implements Account {
2082
+ address: Address
2083
+ data(encoding: AccountEncoding!, dataSlice: DataSlice): String
2084
+ executable: Boolean
2085
+ lamports: BigInt
2086
+ ownerProgram: Account
2087
+ space: BigInt
2088
+ rentEpoch: BigInt
2089
+ authorizedVoters: [VoteAccountDataAuthorizedVoter]
2090
+ authorizedWithdrawer: Account
2091
+ commission: Int
2092
+ epochCredits: [VoteAccountDataEpochCredit]
2093
+ lastTimestamp: VoteAccountDataLastTimestamp
2094
+ node: Account
2095
+ priorVoters: [Address]
2096
+ rootSlot: BigInt
2097
+ votes: [VoteAccountDataVote]
2098
+ }
2099
+ `
2100
+ );
2101
+
2102
+ // src/schema/block.ts
2103
+ var blockTypeDefs = (
2104
+ /* GraphQL */
2105
+ `
2106
+ """
2107
+ A Solana block
2108
+ """
2109
+ type Block {
2110
+ blockhash: String
2111
+ blockHeight: BigInt
2112
+ blockTime: BigInt
2113
+ parentSlot: Slot
2114
+ previousBlockhash: String
2115
+ rewards: [Reward]
2116
+ signatures: [Signature]
2117
+ transactions: [Transaction]
2118
+ }
2119
+ `
2120
+ );
2121
+
2122
+ // src/schema/instruction.ts
2123
+ var instructionTypeDefs = (
2124
+ /* GraphQL */
2125
+ `
2126
+ """
2127
+ Transaction instruction interface
2128
+ """
2129
+ interface TransactionInstruction {
2130
+ programId: Address
2131
+ }
2132
+
2133
+ """
2134
+ Generic transaction instruction
2135
+ """
2136
+ type GenericInstruction implements TransactionInstruction {
2137
+ accounts: [Address]
2138
+ data: Base64EncodedBytes
2139
+ programId: Address
2140
+ }
2141
+
2142
+ """
2143
+ AddressLookupTable: CreateLookupTable instruction
2144
+ """
2145
+ type CreateLookupTableInstruction implements TransactionInstruction {
2146
+ programId: Address
2147
+ bumpSeed: BigInt # FIXME:*
2148
+ lookupTableAccount: Account
2149
+ lookupTableAuthority: Account
2150
+ payerAccount: Account
2151
+ recentSlot: BigInt
2152
+ systemProgram: Account
2153
+ }
2154
+
2155
+ """
2156
+ AddressLookupTable: ExtendLookupTable instruction
2157
+ """
2158
+ type ExtendLookupTableInstruction implements TransactionInstruction {
2159
+ programId: Address
2160
+ lookupTableAccount: Account
2161
+ lookupTableAuthority: Account
2162
+ newAddresses: [Address]
2163
+ payerAccount: Account
2164
+ systemProgram: Account
2165
+ }
2166
+
2167
+ """
2168
+ AddressLookupTable: FreezeLookupTable instruction
2169
+ """
2170
+ type FreezeLookupTableInstruction implements TransactionInstruction {
2171
+ programId: Address
2172
+ lookupTableAccount: Account
2173
+ lookupTableAuthority: Account
2174
+ }
2175
+
2176
+ """
2177
+ AddressLookupTable: DeactivateLookupTable instruction
2178
+ """
2179
+ type DeactivateLookupTableInstruction implements TransactionInstruction {
2180
+ programId: Address
2181
+ lookupTableAccount: Account
2182
+ lookupTableAuthority: Account
2183
+ }
2184
+
2185
+ """
2186
+ AddressLookupTable: CloseLookupTable instruction
2187
+ """
2188
+ type CloseLookupTableInstruction implements TransactionInstruction {
2189
+ programId: Address
2190
+ lookupTableAccount: Account
2191
+ lookupTableAuthority: Account
2192
+ recipient: Account
2193
+ }
2194
+
2195
+ """
2196
+ BpfLoader: Write instruction
2197
+ """
2198
+ type BpfLoaderWriteInstruction implements TransactionInstruction {
2199
+ programId: Address
2200
+ account: Account
2201
+ bytes: Base64EncodedBytes
2202
+ offset: BigInt # FIXME:*
2203
+ }
2204
+
2205
+ """
2206
+ BpfLoader: Finalize instruction
2207
+ """
2208
+ type BpfLoaderFinalizeInstruction implements TransactionInstruction {
2209
+ programId: Address
2210
+ account: Account
2211
+ }
2212
+
2213
+ """
2214
+ BpfUpgradeableLoader: InitializeBuffer instruction
2215
+ """
2216
+ type BpfUpgradeableLoaderInitializeBufferInstruction implements TransactionInstruction {
2217
+ programId: Address
2218
+ account: Account
2219
+ }
2220
+
2221
+ """
2222
+ BpfUpgradeableLoader: Write instruction
2223
+ """
2224
+ type BpfUpgradeableLoaderWriteInstruction implements TransactionInstruction {
2225
+ programId: Address
2226
+ account: Account
2227
+ authority: Account
2228
+ bytes: Base64EncodedBytes
2229
+ offset: BigInt # FIXME:*
2230
+ }
2231
+
2232
+ """
2233
+ BpfUpgradeableLoader: DeployWithMaxDataLen instruction
2234
+ """
2235
+ type BpfUpgradeableLoaderDeployWithMaxDataLenInstruction implements TransactionInstruction {
2236
+ programId: Address
2237
+ authority: Account
2238
+ bufferAccount: Account
2239
+ clockSysvar: Account
2240
+ maxDataLen: BigInt
2241
+ payerAccount: Account
2242
+ programAccount: Account
2243
+ programDataAccount: Account
2244
+ rentSysvar: Account
2245
+ }
2246
+
2247
+ """
2248
+ BpfUpgradeableLoader: Upgrade instruction
2249
+ """
2250
+ type BpfUpgradeableLoaderUpgradeInstruction implements TransactionInstruction {
2251
+ programId: Address
2252
+ authority: Account
2253
+ bufferAccount: Account
2254
+ clockSysvar: Account
2255
+ programAccount: Account
2256
+ programDataAccount: Account
2257
+ rentSysvar: Account
2258
+ spillAccount: Account
2259
+ }
2260
+
2261
+ """
2262
+ BpfUpgradeableLoader: SetAuthority instruction
2263
+ """
2264
+ type BpfUpgradeableLoaderSetAuthorityInstruction implements TransactionInstruction {
2265
+ programId: Address
2266
+ account: Account
2267
+ authority: Account
2268
+ newAuthority: Account
2269
+ }
2270
+
2271
+ """
2272
+ BpfUpgradeableLoader: SetAuthorityChecked instruction
2273
+ """
2274
+ type BpfUpgradeableLoaderSetAuthorityCheckedInstruction implements TransactionInstruction {
2275
+ programId: Address
2276
+ account: Account
2277
+ authority: Account
2278
+ newAuthority: Account
2279
+ }
2280
+
2281
+ """
2282
+ BpfUpgradeableLoader: Close instruction
2283
+ """
2284
+ type BpfUpgradeableLoaderCloseInstruction implements TransactionInstruction {
2285
+ programId: Address
2286
+ account: Account
2287
+ authority: Account
2288
+ programAccount: Account
2289
+ recipient: Account
2290
+ }
2291
+
2292
+ """
2293
+ BpfUpgradeableLoader: ExtendProgram instruction
2294
+ """
2295
+ type BpfUpgradeableLoaderExtendProgramInstruction implements TransactionInstruction {
2296
+ programId: Address
2297
+ additionalBytes: BigInt
2298
+ payerAccount: Account
2299
+ programAccount: Account
2300
+ programDataAccount: Account
2301
+ systemProgram: Account
2302
+ }
2303
+
2304
+ """
2305
+ SplAssociatedTokenAccount: Create instruction
2306
+ """
2307
+ type SplAssociatedTokenCreateInstruction implements TransactionInstruction {
2308
+ programId: Address
2309
+ account: Account
2310
+ mint: Account
2311
+ source: Account
2312
+ systemProgram: Account
2313
+ tokenProgram: Account
2314
+ wallet: Account
2315
+ }
2316
+
2317
+ """
2318
+ SplAssociatedTokenAccount: CreateIdempotent instruction
2319
+ """
2320
+ type SplAssociatedTokenCreateIdempotentInstruction implements TransactionInstruction {
2321
+ programId: Address
2322
+ account: Account
2323
+ mint: Account
2324
+ source: Account
2325
+ systemProgram: Account
2326
+ tokenProgram: Account
2327
+ wallet: Account
2328
+ }
2329
+
2330
+ """
2331
+ SplAssociatedTokenAccount: RecoverNested instruction
2332
+ """
2333
+ type SplAssociatedTokenRecoverNestedInstruction implements TransactionInstruction {
2334
+ programId: Address
2335
+ destination: Account
2336
+ nestedMint: Account
2337
+ nestedOwner: Account
2338
+ nestedSource: Account
2339
+ ownerMint: Account
2340
+ tokenProgram: Account
2341
+ wallet: Account
2342
+ }
2343
+
2344
+ """
2345
+ SplMemo instruction
2346
+ """
2347
+ type SplMemoInstruction implements TransactionInstruction {
2348
+ programId: Address
2349
+ memo: String
2350
+ }
2351
+
2352
+ """
2353
+ SplToken: InitializeMint instruction
2354
+ """
2355
+ type SplTokenInitializeMintInstruction implements TransactionInstruction {
2356
+ programId: Address
2357
+ decimals: BigInt # FIXME:*
2358
+ freezeAuthority: Account
2359
+ mint: Account
2360
+ mintAuthority: Account
2361
+ rentSysvar: Account
2362
+ }
2363
+
2364
+ """
2365
+ SplToken: InitializeMint2 instruction
2366
+ """
2367
+ type SplTokenInitializeMint2Instruction implements TransactionInstruction {
2368
+ programId: Address
2369
+ decimals: BigInt # FIXME:*
2370
+ freezeAuthority: Account
2371
+ mint: Account
2372
+ mintAuthority: Account
2373
+ }
2374
+
2375
+ """
2376
+ SplToken: InitializeAccount instruction
2377
+ """
2378
+ type SplTokenInitializeAccountInstruction implements TransactionInstruction {
2379
+ programId: Address
2380
+ account: Account
2381
+ mint: Account
2382
+ owner: Account
2383
+ rentSysvar: Account
2384
+ }
2385
+
2386
+ """
2387
+ SplToken: InitializeAccount2 instruction
2388
+ """
2389
+ type SplTokenInitializeAccount2Instruction implements TransactionInstruction {
2390
+ programId: Address
2391
+ account: Account
2392
+ mint: Account
2393
+ owner: Account
2394
+ rentSysvar: Account
2395
+ }
2396
+
2397
+ """
2398
+ SplToken: InitializeAccount3 instruction
2399
+ """
2400
+ type SplTokenInitializeAccount3Instruction implements TransactionInstruction {
2401
+ programId: Address
2402
+ account: Account
2403
+ mint: Account
2404
+ owner: Account
2405
+ }
2406
+
2407
+ """
2408
+ SplToken: InitializeMultisig instruction
2409
+ """
2410
+ type SplTokenInitializeMultisigInstruction implements TransactionInstruction {
2411
+ programId: Address
2412
+ m: BigInt # FIXME:*
2413
+ multisig: Account
2414
+ rentSysvar: Account
2415
+ signers: [Address]
2416
+ }
2417
+
2418
+ """
2419
+ SplToken: InitializeMultisig2 instruction
2420
+ """
2421
+ type SplTokenInitializeMultisig2Instruction implements TransactionInstruction {
2422
+ programId: Address
2423
+ m: BigInt # FIXME:*
2424
+ multisig: Account
2425
+ signers: [Address]
2426
+ }
2427
+
2428
+ """
2429
+ SplToken: Transfer instruction
2430
+ """
2431
+ type SplTokenTransferInstruction implements TransactionInstruction {
2432
+ programId: Address
2433
+ amount: String
2434
+ authority: Account
2435
+ destination: Account
2436
+ multisigAuthority: Account
2437
+ source: Account
2438
+ }
2439
+
2440
+ """
2441
+ SplToken: Approve instruction
2442
+ """
2443
+ type SplTokenApproveInstruction implements TransactionInstruction {
2444
+ programId: Address
2445
+ amount: String
2446
+ delegate: Account
2447
+ multisigOwner: Account
2448
+ owner: Account
2449
+ source: Account
2450
+ }
2451
+
2452
+ """
2453
+ SplToken: Revoke instruction
2454
+ """
2455
+ type SplTokenRevokeInstruction implements TransactionInstruction {
2456
+ programId: Address
2457
+ multisigOwner: Account
2458
+ owner: Account
2459
+ source: Account
2460
+ }
2461
+
2462
+ """
2463
+ SplToken: SetAuthority instruction
2464
+ """
2465
+ type SplTokenSetAuthorityInstruction implements TransactionInstruction {
2466
+ programId: Address
2467
+ authority: Account
2468
+ authorityType: String
2469
+ multisigAuthority: Account
2470
+ newAuthority: Account
2471
+ }
2472
+
2473
+ """
2474
+ SplToken: MintTo instruction
2475
+ """
2476
+ type SplTokenMintToInstruction implements TransactionInstruction {
2477
+ programId: Address
2478
+ account: Account
2479
+ amount: String
2480
+ authority: Account
2481
+ mint: Account
2482
+ mintAuthority: Account
2483
+ multisigMintAuthority: Account
2484
+ }
2485
+
2486
+ """
2487
+ SplToken: Burn instruction
2488
+ """
2489
+ type SplTokenBurnInstruction implements TransactionInstruction {
2490
+ programId: Address
2491
+ account: Account
2492
+ amount: String
2493
+ authority: Account
2494
+ mint: Account
2495
+ multisigAuthority: Account
2496
+ }
2497
+
2498
+ """
2499
+ SplToken: CloseAccount instruction
2500
+ """
2501
+ type SplTokenCloseAccountInstruction implements TransactionInstruction {
2502
+ programId: Address
2503
+ account: Account
2504
+ destination: Account
2505
+ multisigOwner: Account
2506
+ owner: Account
2507
+ }
2508
+
2509
+ """
2510
+ SplToken: FreezeAccount instruction
2511
+ """
2512
+ type SplTokenFreezeAccountInstruction implements TransactionInstruction {
2513
+ programId: Address
2514
+ account: Account
2515
+ freezeAuthority: Account
2516
+ mint: Account
2517
+ multisigFreezeAuthority: Account
2518
+ }
2519
+
2520
+ """
2521
+ SplToken: ThawAccount instruction
2522
+ """
2523
+ type SplTokenThawAccountInstruction implements TransactionInstruction {
2524
+ programId: Address
2525
+ account: Account
2526
+ freezeAuthority: Account
2527
+ mint: Account
2528
+ multisigFreezeAuthority: Account
2529
+ }
2530
+
2531
+ """
2532
+ SplToken: TransferChecked instruction
2533
+ """
2534
+ type SplTokenTransferCheckedInstruction implements TransactionInstruction {
2535
+ programId: Address
2536
+ amount: String
2537
+ authority: Account
2538
+ decimals: BigInt # FIXME:*
2539
+ destination: Account
2540
+ mint: Account
2541
+ multisigAuthority: Account
2542
+ source: Account
2543
+ tokenAmount: String
2544
+ }
2545
+
2546
+ """
2547
+ SplToken: ApproveChecked instruction
2548
+ """
2549
+ type SplTokenApproveCheckedInstruction implements TransactionInstruction {
2550
+ programId: Address
2551
+ delegate: Account
2552
+ mint: Account
2553
+ multisigOwner: Account
2554
+ owner: Account
2555
+ source: Account
2556
+ tokenAmount: String
2557
+ }
2558
+
2559
+ """
2560
+ SplToken: MintToChecked instruction
2561
+ """
2562
+ type SplTokenMintToCheckedInstruction implements TransactionInstruction {
2563
+ programId: Address
2564
+ account: Account
2565
+ authority: Account
2566
+ mint: Account
2567
+ mintAuthority: Account
2568
+ multisigMintAuthority: Account
2569
+ tokenAmount: String
2570
+ }
2571
+
2572
+ """
2573
+ SplToken: BurnChecked instruction
2574
+ """
2575
+ type SplTokenBurnCheckedInstruction implements TransactionInstruction {
2576
+ programId: Address
2577
+ account: Account
2578
+ authority: Account
2579
+ mint: Account
2580
+ multisigAuthority: Account
2581
+ tokenAmount: String
2582
+ }
2583
+
2584
+ """
2585
+ SplToken: SyncNative instruction
2586
+ """
2587
+ type SplTokenSyncNativeInstruction implements TransactionInstruction {
2588
+ programId: Address
2589
+ account: Account
2590
+ }
2591
+
2592
+ """
2593
+ SplToken: GetAccountDataSize instruction
2594
+ """
2595
+ type SplTokenGetAccountDataSizeInstruction implements TransactionInstruction {
2596
+ programId: Address
2597
+ extensionTypes: [String]
2598
+ mint: Account
2599
+ }
2600
+
2601
+ """
2602
+ SplToken: InitializeImmutableOwner instruction
2603
+ """
2604
+ type SplTokenInitializeImmutableOwnerInstruction implements TransactionInstruction {
2605
+ programId: Address
2606
+ account: Account
2607
+ }
2608
+
2609
+ """
2610
+ SplToken: AmountToUiAmount instruction
2611
+ """
2612
+ type SplTokenAmountToUiAmountInstruction implements TransactionInstruction {
2613
+ programId: Address
2614
+ amount: String
2615
+ mint: Account
2616
+ }
2617
+
2618
+ """
2619
+ SplToken: UiAmountToAmount instruction
2620
+ """
2621
+ type SplTokenUiAmountToAmountInstruction implements TransactionInstruction {
2622
+ programId: Address
2623
+ mint: Account
2624
+ uiAmount: String
2625
+ }
2626
+
2627
+ """
2628
+ SplToken: InitializeMintCloseAuthority instruction
2629
+ """
2630
+ type SplTokenInitializeMintCloseAuthorityInstruction implements TransactionInstruction {
2631
+ programId: Address
2632
+ mint: Account
2633
+ newAuthority: Account
2634
+ }
2635
+
2636
+ # TODO: Extensions!
2637
+ # - TransferFeeExtension
2638
+ # - ConfidentialTransferFeeExtension
2639
+ # - DefaultAccountStateExtension
2640
+ # - Reallocate
2641
+ # - MemoTransferExtension
2642
+ # - CreateNativeMint
2643
+ # - InitializeNonTransferableMint
2644
+ # - InterestBearingMintExtension
2645
+ # - CpiGuardExtension
2646
+ # - InitializePermanentDelegate
2647
+ # - TransferHookExtension
2648
+ # - ConfidentialTransferFeeExtension
2649
+ # - WithdrawExcessLamports
2650
+ # - MetadataPointerExtension
2651
+
2652
+ type Lockup {
2653
+ custodian: Account
2654
+ epoch: BigInt
2655
+ unixTimestamp: BigInt
2656
+ }
2657
+
2658
+ """
2659
+ Stake: Initialize instruction
2660
+ """
2661
+ type StakeInitializeInstructionDataAuthorized {
2662
+ staker: Account
2663
+ withdrawer: Account
2664
+ }
2665
+ type StakeInitializeInstruction implements TransactionInstruction {
2666
+ programId: Address
2667
+ authorized: StakeInitializeInstructionDataAuthorized
2668
+ lockup: Lockup
2669
+ rentSysvar: Account
2670
+ stakeAccount: Account
2671
+ }
2672
+
2673
+ """
2674
+ Stake: Authorize instruction
2675
+ """
2676
+ type StakeAuthorizeInstruction implements TransactionInstruction {
2677
+ programId: Address
2678
+ authority: Account
2679
+ authorityType: String
2680
+ clockSysvar: Account
2681
+ custodian: Account
2682
+ newAuthority: Account
2683
+ stakeAccount: Account
2684
+ }
2685
+
2686
+ """
2687
+ Stake: DelegateStake instruction
2688
+ """
2689
+ type StakeDelegateStakeInstruction implements TransactionInstruction {
2690
+ programId: Address
2691
+ clockSysvar: Account
2692
+ stakeAccount: Account
2693
+ stakeAuthority: Account
2694
+ stakeConfigAccount: Account
2695
+ stakeHistorySysvar: Account
2696
+ voteAccount: Account
2697
+ }
2698
+
2699
+ """
2700
+ Stake: Split instruction
2701
+ """
2702
+ type StakeSplitInstruction implements TransactionInstruction {
2703
+ programId: Address
2704
+ lamports: BigInt
2705
+ newSplitAccount: Account
2706
+ stakeAccount: Account
2707
+ stakeAuthority: Account
2708
+ }
2709
+
2710
+ """
2711
+ Stake: Withdraw instruction
2712
+ """
2713
+ type StakeWithdrawInstruction implements TransactionInstruction {
2714
+ programId: Address
2715
+ clockSysvar: Account
2716
+ destination: Account
2717
+ lamports: BigInt
2718
+ stakeAccount: Account
2719
+ withdrawAuthority: Account
2720
+ }
2721
+
2722
+ """
2723
+ Stake: Deactivate instruction
2724
+ """
2725
+ type StakeDeactivateInstruction implements TransactionInstruction {
2726
+ programId: Address
2727
+ clockSysvar: Account
2728
+ stakeAccount: Account
2729
+ stakeAuthority: Account
2730
+ }
2731
+
2732
+ """
2733
+ Stake: SetLockup instruction
2734
+ """
2735
+ type StakeSetLockupInstruction implements TransactionInstruction {
2736
+ programId: Address
2737
+ custodian: Account
2738
+ lockup: Lockup
2739
+ stakeAccount: Account
2740
+ }
2741
+
2742
+ """
2743
+ Stake: Merge instruction
2744
+ """
2745
+ type StakeMergeInstruction implements TransactionInstruction {
2746
+ programId: Address
2747
+ clockSysvar: Account
2748
+ destination: Account
2749
+ source: Account
2750
+ stakeAuthority: Account
2751
+ stakeHistorySysvar: Account
2752
+ }
2753
+
2754
+ """
2755
+ Stake: AuthorizeWithSeed instruction
2756
+ """
2757
+ type StakeAuthorizeWithSeedInstruction implements TransactionInstruction {
2758
+ programId: Address
2759
+ authorityBase: Account
2760
+ authorityOwner: Account
2761
+ authoritySeed: String
2762
+ authorityType: String
2763
+ clockSysvar: Account
2764
+ custodian: Account
2765
+ newAuthorized: Account
2766
+ stakeAccount: Account
2767
+ }
2768
+
2769
+ """
2770
+ Stake: InitializeChecked instruction
2771
+ """
2772
+ type StakeInitializeCheckedInstructionDataAuthorized {
2773
+ staker: Account
2774
+ withdrawer: Account
2775
+ }
2776
+ type StakeInitializeCheckedInstruction implements TransactionInstruction {
2777
+ programId: Address
2778
+ authorized: StakeInitializeCheckedInstructionDataAuthorized
2779
+ lockup: Lockup
2780
+ rentSysvar: Account
2781
+ stakeAccount: Account
2782
+ }
2783
+
2784
+ """
2785
+ Stake: AuthorizeChecked instruction
2786
+ """
2787
+ type StakeAuthorizeCheckedInstruction implements TransactionInstruction {
2788
+ programId: Address
2789
+ authority: Account
2790
+ authorityType: String
2791
+ clockSysvar: Account
2792
+ custodian: Account
2793
+ newAuthority: Account
2794
+ stakeAccount: Account
2795
+ }
2796
+
2797
+ """
2798
+ Stake: AuthorizeCheckedWithSeed instruction
2799
+ """
2800
+ type StakeAuthorizeCheckedWithSeedInstruction implements TransactionInstruction {
2801
+ programId: Address
2802
+ authorityBase: Account
2803
+ authorityOwner: Account
2804
+ authoritySeed: String
2805
+ authorityType: String
2806
+ clockSysvar: Account
2807
+ custodian: Account
2808
+ newAuthorized: Account
2809
+ stakeAccount: Account
2810
+ }
2811
+
2812
+ """
2813
+ Stake: SetLockupChecked instruction
2814
+ """
2815
+ type StakeSetLockupCheckedInstruction implements TransactionInstruction {
2816
+ programId: Address
2817
+ custodian: Account
2818
+ lockup: Lockup
2819
+ stakeAccount: Account
2820
+ }
2821
+
2822
+ """
2823
+ Stake: DeactivateDelinquent instruction
2824
+ """
2825
+ type StakeDeactivateDelinquentInstruction implements TransactionInstruction {
2826
+ programId: Address
2827
+ referenceVoteAccount: Account
2828
+ stakeAccount: Account
2829
+ voteAccount: Account
2830
+ }
2831
+
2832
+ """
2833
+ Stake: Redelegate instruction
2834
+ """
2835
+ type StakeRedelegateInstruction implements TransactionInstruction {
2836
+ programId: Address
2837
+ newStakeAccount: Account
2838
+ stakeAccount: Account
2839
+ stakeAuthority: Account
2840
+ stakeConfigAccount: Account
2841
+ voteAccount: Account
2842
+ }
2843
+
2844
+ """
2845
+ System: CreateAccount instruction
2846
+ """
2847
+ type CreateAccountInstruction implements TransactionInstruction {
2848
+ programId: Address
2849
+ lamports: BigInt
2850
+ newAccount: Account
2851
+ owner: Account
2852
+ source: Account
2853
+ space: BigInt
2854
+ }
2855
+
2856
+ """
2857
+ System: Assign instruction
2858
+ """
2859
+ type AssignInstruction implements TransactionInstruction {
2860
+ programId: Address
2861
+ account: Account
2862
+ owner: Account
2863
+ }
2864
+
2865
+ """
2866
+ System: Transfer instruction
2867
+ """
2868
+ type TransferInstruction implements TransactionInstruction {
2869
+ programId: Address
2870
+ destination: Account
2871
+ lamports: BigInt
2872
+ source: Account
2873
+ }
2874
+
2875
+ """
2876
+ System: CreateAccountWithSeed instruction
2877
+ """
2878
+ type CreateAccountWithSeedInstruction implements TransactionInstruction {
2879
+ programId: Address
2880
+ base: Account
2881
+ lamports: BigInt
2882
+ owner: Account
2883
+ seed: String
2884
+ space: BigInt
2885
+ }
2886
+
2887
+ """
2888
+ System: AdvanceNonceAccount instruction
2889
+ """
2890
+ type AdvanceNonceAccountInstruction implements TransactionInstruction {
2891
+ programId: Address
2892
+ nonceAccount: Account
2893
+ nonceAuthority: Account
2894
+ recentBlockhashesSysvar: Account
2895
+ }
2896
+
2897
+ """
2898
+ System: WithdrawNonceAccount instruction
2899
+ """
2900
+ type WithdrawNonceAccountInstruction implements TransactionInstruction {
2901
+ programId: Address
2902
+ destination: Account
2903
+ lamports: BigInt
2904
+ nonceAccount: Account
2905
+ nonceAuthority: Account
2906
+ recentBlockhashesSysvar: Account
2907
+ rentSysvar: Account
2908
+ }
2909
+
2910
+ """
2911
+ System: InitializeNonceAccount instruction
2912
+ """
2913
+ type InitializeNonceAccountInstruction implements TransactionInstruction {
2914
+ programId: Address
2915
+ nonceAccount: Account
2916
+ nonceAuthority: Account
2917
+ recentBlockhashesSysvar: Account
2918
+ rentSysvar: Account
2919
+ }
2920
+
2921
+ """
2922
+ System: AuthorizeNonceAccount instruction
2923
+ """
2924
+ type AuthorizeNonceAccountInstruction implements TransactionInstruction {
2925
+ programId: Address
2926
+ newAuthorized: Account
2927
+ nonceAccount: Account
2928
+ nonceAuthority: Account
2929
+ }
2930
+
2931
+ """
2932
+ System: UpgradeNonceAccount instruction
2933
+ """
2934
+ type UpgradeNonceAccountInstruction implements TransactionInstruction {
2935
+ programId: Address
2936
+ nonceAccount: Account
2937
+ nonceAuthority: Account
2938
+ }
2939
+
2940
+ """
2941
+ System: Allocate instruction
2942
+ """
2943
+ type AllocateInstruction implements TransactionInstruction {
2944
+ programId: Address
2945
+ account: Account
2946
+ space: BigInt
2947
+ }
2948
+
2949
+ """
2950
+ System: AllocateWithSeed instruction
2951
+ """
2952
+ type AllocateWithSeedInstruction implements TransactionInstruction {
2953
+ programId: Address
2954
+ account: Account
2955
+ base: Address
2956
+ owner: Account
2957
+ seed: String
2958
+ space: BigInt
2959
+ }
2960
+
2961
+ """
2962
+ System: AssignWithSeed instruction
2963
+ """
2964
+ type AssignWithSeedInstruction implements TransactionInstruction {
2965
+ programId: Address
2966
+ account: Account
2967
+ base: Address
2968
+ owner: Account
2969
+ seed: String
2970
+ }
2971
+
2972
+ """
2973
+ System: TransferWithSeed instruction
2974
+ """
2975
+ type TransferWithSeedInstruction implements TransactionInstruction {
2976
+ programId: Address
2977
+ destination: Account
2978
+ lamports: BigInt
2979
+ source: Account
2980
+ sourceBase: Address
2981
+ sourceOwner: Account
2982
+ sourceSeed: String
2983
+ }
2984
+
2985
+ """
2986
+ Vote: InitializeAccount instruction
2987
+ """
2988
+ type VoteInitializeAccountInstruction implements TransactionInstruction {
2989
+ programId: Address
2990
+ authorizedVoter: Account
2991
+ authorizedWithdrawer: Account
2992
+ clockSysvar: Account
2993
+ commission: BigInt # FIXME:*
2994
+ node: Account
2995
+ rentSysvar: Account
2996
+ voteAccount: Account
2997
+ }
2998
+
2999
+ """
3000
+ Vote: Authorize instruction
3001
+ """
3002
+ type VoteAuthorizeInstruction implements TransactionInstruction {
3003
+ programId: Address
3004
+ authority: Account
3005
+ authorityType: String
3006
+ clockSysvar: Account
3007
+ newAuthority: Account
3008
+ voteAccount: Account
3009
+ }
3010
+
3011
+ """
3012
+ Vote: AuthorizeWithSeed instruction
3013
+ """
3014
+ type VoteAuthorizeWithSeedInstruction implements TransactionInstruction {
3015
+ programId: Address
3016
+ authorityBaseKey: String
3017
+ authorityOwner: Account
3018
+ authoritySeed: String
3019
+ authorityType: String
3020
+ clockSysvar: Account
3021
+ newAuthority: Account
3022
+ voteAccount: Account
3023
+ }
3024
+
3025
+ """
3026
+ Vote: AuthorizeCheckedWithSeed instruction
3027
+ """
3028
+ type VoteAuthorizeCheckedWithSeedInstruction implements TransactionInstruction {
3029
+ programId: Address
3030
+ authorityBaseKey: String
3031
+ authorityOwner: Account
3032
+ authoritySeed: String
3033
+ authorityType: String
3034
+ clockSysvar: Account
3035
+ newAuthority: Account
3036
+ voteAccount: Account
3037
+ }
3038
+
3039
+ type Vote {
3040
+ hash: String
3041
+ slots: [BigInt]
3042
+ timestamp: BigInt
3043
+ }
3044
+
3045
+ """
3046
+ Vote: Vote instruction
3047
+ """
3048
+ type VoteVoteInstruction implements TransactionInstruction {
3049
+ programId: Address
3050
+ clockSysvar: Account
3051
+ slotHashesSysvar: Account
3052
+ vote: Vote
3053
+ voteAccount: Account
3054
+ voteAuthority: Account
3055
+ }
3056
+
3057
+ type VoteStateUpdateLockout {
3058
+ confirmationCount: BigInt # FIXME:*
3059
+ slot: BigInt
3060
+ }
3061
+ type VoteStateUpdate {
3062
+ hash: String
3063
+ lockouts: [VoteStateUpdateLockout]
3064
+ root: BigInt
3065
+ timestamp: BigInt
3066
+ }
3067
+
3068
+ """
3069
+ Vote: UpdateVoteState instruction
3070
+ """
3071
+ type VoteUpdateVoteStateInstruction implements TransactionInstruction {
3072
+ programId: Address
3073
+ hash: String
3074
+ voteAccount: Account
3075
+ voteAuthority: Account
3076
+ voteStateUpdate: VoteStateUpdate
3077
+ }
3078
+
3079
+ """
3080
+ Vote: UpdateVoteStateSwitch instruction
3081
+ """
3082
+ type VoteUpdateVoteStateSwitchInstruction implements TransactionInstruction {
3083
+ programId: Address
3084
+ hash: String
3085
+ voteAccount: Account
3086
+ voteAuthority: Account
3087
+ voteStateUpdate: VoteStateUpdate
3088
+ }
3089
+
3090
+ """
3091
+ Vote: CompactUpdateVoteState instruction
3092
+ """
3093
+ type VoteCompactUpdateVoteStateInstruction implements TransactionInstruction {
3094
+ programId: Address
3095
+ hash: String
3096
+ voteAccount: Account
3097
+ voteAuthority: Account
3098
+ voteStateUpdate: VoteStateUpdate
3099
+ }
3100
+
3101
+ """
3102
+ Vote: CompactUpdateVoteStateSwitch instruction
3103
+ """
3104
+ type VoteCompactUpdateVoteStateSwitchInstruction implements TransactionInstruction {
3105
+ programId: Address
3106
+ hash: String
3107
+ voteAccount: Account
3108
+ voteAuthority: Account
3109
+ voteStateUpdate: VoteStateUpdate
3110
+ }
3111
+
3112
+ """
3113
+ Vote: Withdraw instruction
3114
+ """
3115
+ type VoteWithdrawInstruction implements TransactionInstruction {
3116
+ programId: Address
3117
+ destination: Account
3118
+ lamports: BigInt
3119
+ voteAccount: Account
3120
+ withdrawAuthority: Account
3121
+ }
3122
+
3123
+ """
3124
+ Vote: UpdateValidatorIdentity instruction
3125
+ """
3126
+ type VoteUpdateValidatorIdentityInstruction implements TransactionInstruction {
3127
+ programId: Address
3128
+ newValidatorIdentity: Account
3129
+ voteAccount: Account
3130
+ withdrawAuthority: Account
3131
+ }
3132
+
3133
+ """
3134
+ Vote: UpdateCommission instruction
3135
+ """
3136
+ type VoteUpdateCommissionInstruction implements TransactionInstruction {
3137
+ programId: Address
3138
+ commission: BigInt # FIXME:*
3139
+ voteAccount: Account
3140
+ withdrawAuthority: Account
3141
+ }
3142
+
3143
+ """
3144
+ Vote: VoteSwitch instruction
3145
+ """
3146
+ type VoteVoteSwitchInstruction implements TransactionInstruction {
3147
+ programId: Address
3148
+ clockSysvar: Account
3149
+ hash: String
3150
+ slotHashesSysvar: Account
3151
+ vote: Vote
3152
+ voteAccount: Account
3153
+ voteAuthority: Account
3154
+ }
3155
+
3156
+ """
3157
+ Vote: AuthorizeChecked instruction
3158
+ """
3159
+ type VoteAuthorizeCheckedInstruction implements TransactionInstruction {
3160
+ programId: Address
3161
+ authority: Account
3162
+ authorityType: String
3163
+ clockSysvar: Account
3164
+ newAuthority: Account
3165
+ voteAccount: Account
3166
+ }
3167
+ `
3168
+ );
3169
+
3170
+ // src/schema/root.ts
3171
+ var rootTypeDefs = (
3172
+ /* GraphQL */
3173
+ `
3174
+ type Query {
3175
+ account(address: Address!, commitment: Commitment, minContextSlot: Slot): Account
3176
+ block(slot: Slot!, commitment: CommitmentWithoutProcessed): Block
3177
+ programAccounts(
3178
+ programAddress: Address!
3179
+ commitment: Commitment
3180
+ filters: [ProgramAccountsFilter]
3181
+ minContextSlot: Slot
3182
+ ): [Account]
3183
+ transaction(signature: Signature!, commitment: CommitmentWithoutProcessed): Transaction
3184
+ }
3185
+
3186
+ schema {
3187
+ query: Query
3188
+ }
3189
+ `
3190
+ );
3191
+
3192
+ // src/schema/transaction.ts
3193
+ var transactionTypeDefs = (
3194
+ /* GraphQL */
3195
+ `
3196
+ type TransactionStatusOk {
3197
+ Ok: String
3198
+ }
3199
+ type TransactionStatusErr {
3200
+ Err: String
3201
+ }
3202
+ union TransactionStatus = TransactionStatusOk | TransactionStatusErr
3203
+
3204
+ type TransactionLoadedAddresses {
3205
+ readonly: [String]
3206
+ writable: [String]
3207
+ }
3208
+
3209
+ type TransactionInnerInstruction {
3210
+ index: Int
3211
+ instructions: [TransactionInstruction]
3212
+ }
3213
+
3214
+ type TransactionMeta {
3215
+ computeUnitsConsumed: BigInt
3216
+ err: String
3217
+ fee: BigInt
3218
+ innerInstructions: [TransactionInnerInstruction]
3219
+ loadedAddresses: TransactionLoadedAddresses
3220
+ logMessages: [String]
3221
+ postBalances: [BigInt]
3222
+ postTokenBalances: [TokenBalance]
3223
+ preBalances: [BigInt]
3224
+ preTokenBalances: [TokenBalance]
3225
+ returnData: ReturnData
3226
+ rewards: [Reward]
3227
+ status: TransactionStatus
3228
+ }
3229
+
3230
+ type TransactionMessageAccountKey {
3231
+ pubkey: Address
3232
+ signer: Boolean
3233
+ source: String
3234
+ writable: Boolean
3235
+ }
3236
+
3237
+ type TransactionMessageAddressTableLookup {
3238
+ accountKey: Address
3239
+ readableIndexes: [Int]
3240
+ writableIndexes: [Int]
3241
+ }
3242
+
3243
+ type TransactionMessageHeader {
3244
+ numReadonlySignedAccounts: Int
3245
+ numReadonlyUnsignedAccounts: Int
3246
+ numRequiredSignatures: Int
3247
+ }
3248
+
3249
+ type TransactionMessage {
3250
+ accountKeys: [TransactionMessageAccountKey]
3251
+ addressTableLookups: [TransactionMessageAddressTableLookup]
3252
+ header: TransactionMessageHeader
3253
+ instructions: [TransactionInstruction]
3254
+ recentBlockhash: String
3255
+ }
3256
+
3257
+ """
3258
+ A Solana transaction
3259
+ """
3260
+ type Transaction {
3261
+ blockTime: BigInt
3262
+ data(encoding: TransactionEncoding!): String
3263
+ message: TransactionMessage
3264
+ meta: TransactionMeta
3265
+ signatures: [Signature]
3266
+ slot: Slot
3267
+ version: String
3268
+ }
3269
+ `
3270
+ );
3271
+
3272
+ // src/schema/types.ts
3273
+ var typeTypeDefs = (
3274
+ /* GraphQL */
3275
+ `
3276
+ enum AccountEncoding {
3277
+ BASE_58
3278
+ BASE_64
3279
+ BASE_64_ZSTD
3280
+ }
3281
+
3282
+ scalar Address
3283
+
3284
+ scalar Base58EncodedBytes
3285
+
3286
+ scalar Base64EncodedBytes
3287
+
3288
+ scalar Base64ZstdEncodedBytes
3289
+
3290
+ scalar BigInt
3291
+
3292
+ enum Commitment {
3293
+ CONFIRMED
3294
+ FINALIZED
3295
+ PROCESSED
3296
+ }
3297
+
3298
+ enum CommitmentWithoutProcessed {
3299
+ CONFIRMED
3300
+ FINALIZED
3301
+ }
3302
+
3303
+ input DataSlice {
3304
+ offset: Int!
3305
+ length: Int!
3306
+ }
3307
+
3308
+ input ProgramAccountsFilter {
3309
+ bytes: BigInt
3310
+ dataSize: BigInt
3311
+ encoding: AccountEncoding
3312
+ offset: BigInt
3313
+ }
3314
+
3315
+ type ReturnData {
3316
+ data: Base64EncodedBytes
3317
+ programId: Address
3318
+ }
3319
+
3320
+ type Reward {
3321
+ commission: Int
3322
+ lamports: BigInt
3323
+ postBalance: BigInt
3324
+ pubkey: Address
3325
+ rewardType: String
3326
+ }
3327
+
3328
+ scalar Signature
3329
+
3330
+ scalar Slot
3331
+
3332
+ type TokenAmount {
3333
+ amount: String
3334
+ decimals: Int
3335
+ uiAmount: BigInt
3336
+ uiAmountString: String
3337
+ }
3338
+
3339
+ type TokenBalance {
3340
+ accountIndex: Int
3341
+ mint: Account
3342
+ owner: Account
3343
+ programId: Address
3344
+ uiTokenAmount: TokenAmount
3345
+ }
3346
+
3347
+ enum TransactionEncoding {
3348
+ BASE_58
3349
+ BASE_64
3350
+ }
3351
+ `
3352
+ );
3353
+
3354
+ // src/schema/index.ts
3355
+ function createSolanaGraphQLTypeDefs() {
3356
+ return [accountTypeDefs, blockTypeDefs, instructionTypeDefs, rootTypeDefs, typeTypeDefs, transactionTypeDefs];
3357
+ }
3358
+
3359
+ // src/index.ts
3360
+ function createRpcGraphQL(rpc, config) {
3361
+ const rpcGraphQLConfig = {
3362
+ maxDataSliceByteRange: config?.maxDataSliceByteRange ?? 200,
3363
+ maxMultipleAccountsBatchSize: config?.maxMultipleAccountsBatchSize ?? 100
3364
+ };
3365
+ const schema = makeExecutableSchema({
3366
+ resolvers: createSolanaGraphQLResolvers(),
3367
+ typeDefs: createSolanaGraphQLTypeDefs()
53
3368
  });
54
3369
  return {
55
- context,
56
3370
  async query(source, variableValues) {
57
- const result = await graphql({
58
- contextValue: this.context,
59
- schema: this.schema,
3371
+ const contextValue = createSolanaGraphQLContext(rpc, rpcGraphQLConfig);
3372
+ return graphql({
3373
+ contextValue,
3374
+ schema,
60
3375
  source,
61
3376
  variableValues
62
3377
  });
63
- this.context.cache.flush();
64
- return result;
65
- },
66
- schema
3378
+ }
67
3379
  };
68
3380
  }
69
3381