@voidifydao/sdk 1.0.0

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 (115) hide show
  1. package/dist/cli/config/command.d.ts +2 -0
  2. package/dist/cli/config/command.js +91 -0
  3. package/dist/cli/config/init.d.ts +3 -0
  4. package/dist/cli/config/init.js +88 -0
  5. package/dist/cli/config/keypair.d.ts +4 -0
  6. package/dist/cli/config/keypair.js +35 -0
  7. package/dist/cli/config/loader.d.ts +11 -0
  8. package/dist/cli/config/loader.js +65 -0
  9. package/dist/cli/config/types.d.ts +50 -0
  10. package/dist/cli/config/types.js +33 -0
  11. package/dist/cli/deposit.d.ts +2 -0
  12. package/dist/cli/deposit.js +58 -0
  13. package/dist/cli/helpers.d.ts +12 -0
  14. package/dist/cli/helpers.js +53 -0
  15. package/dist/cli/note.d.ts +2 -0
  16. package/dist/cli/note.js +50 -0
  17. package/dist/cli/relayer.d.ts +2 -0
  18. package/dist/cli/relayer.js +60 -0
  19. package/dist/cli/substream.d.ts +2 -0
  20. package/dist/cli/substream.js +35 -0
  21. package/dist/cli/withdraw.d.ts +2 -0
  22. package/dist/cli/withdraw.js +23 -0
  23. package/dist/cli.d.ts +2 -0
  24. package/dist/cli.js +30 -0
  25. package/dist/context.d.ts +45 -0
  26. package/dist/context.js +77 -0
  27. package/dist/idl/voidify/idl.d.ts +1313 -0
  28. package/dist/idl/voidify/idl.js +1 -0
  29. package/dist/idl/voidify/idl.json +1307 -0
  30. package/dist/idl/voidify-staking/idl.d.ts +93 -0
  31. package/dist/idl/voidify-staking/idl.js +1 -0
  32. package/dist/idl/voidify-staking/idl.json +87 -0
  33. package/dist/index.d.ts +17 -0
  34. package/dist/index.js +10 -0
  35. package/dist/relayer/server/index.d.ts +6 -0
  36. package/dist/relayer/server/index.js +32 -0
  37. package/dist/relayer/server/server.d.ts +24 -0
  38. package/dist/relayer/server/server.js +158 -0
  39. package/dist/relayer/server/switchboard.d.ts +2 -0
  40. package/dist/relayer/server/switchboard.js +42 -0
  41. package/dist/relayer/types.d.ts +21 -0
  42. package/dist/relayer/types.js +1 -0
  43. package/dist/staking/commands.d.ts +3 -0
  44. package/dist/staking/commands.js +13 -0
  45. package/dist/staking/index.d.ts +2 -0
  46. package/dist/staking/index.js +2 -0
  47. package/dist/staking/program.d.ts +18 -0
  48. package/dist/staking/program.js +40 -0
  49. package/dist/substream/chain/events.d.ts +4 -0
  50. package/dist/substream/chain/events.js +50 -0
  51. package/dist/substream/chain/index.d.ts +24 -0
  52. package/dist/substream/chain/index.js +79 -0
  53. package/dist/substream/chain/registry.d.ts +44 -0
  54. package/dist/substream/chain/registry.js +28 -0
  55. package/dist/substream/chain/utils.d.ts +9 -0
  56. package/dist/substream/chain/utils.js +41 -0
  57. package/dist/substream/client.d.ts +27 -0
  58. package/dist/substream/client.js +28 -0
  59. package/dist/substream/database/indexeddb.d.ts +2 -0
  60. package/dist/substream/database/indexeddb.js +242 -0
  61. package/dist/substream/database/sqlite.d.ts +26 -0
  62. package/dist/substream/database/sqlite.js +275 -0
  63. package/dist/substream/modules/deposit.d.ts +14 -0
  64. package/dist/substream/modules/deposit.js +123 -0
  65. package/dist/substream/modules/index.d.ts +11 -0
  66. package/dist/substream/modules/index.js +7 -0
  67. package/dist/substream/modules/relayer.d.ts +10 -0
  68. package/dist/substream/modules/relayer.js +290 -0
  69. package/dist/substream/runtime.d.ts +38 -0
  70. package/dist/substream/runtime.js +163 -0
  71. package/dist/substream/server/event-listener.d.ts +18 -0
  72. package/dist/substream/server/event-listener.js +68 -0
  73. package/dist/substream/server/index.d.ts +3 -0
  74. package/dist/substream/server/index.js +30 -0
  75. package/dist/substream/server/server.d.ts +43 -0
  76. package/dist/substream/server/server.js +216 -0
  77. package/dist/substream/types.d.ts +94 -0
  78. package/dist/substream/types.js +1 -0
  79. package/dist/types/errors.d.ts +1 -0
  80. package/dist/types/errors.js +16 -0
  81. package/dist/types/events.d.ts +13 -0
  82. package/dist/types/events.js +1 -0
  83. package/dist/types/index.d.ts +3 -0
  84. package/dist/types/index.js +1 -0
  85. package/dist/utils/amount.d.ts +4 -0
  86. package/dist/utils/amount.js +41 -0
  87. package/dist/utils/anchor-events.d.ts +13 -0
  88. package/dist/utils/anchor-events.js +28 -0
  89. package/dist/utils/bytes.d.ts +10 -0
  90. package/dist/utils/bytes.js +29 -0
  91. package/dist/utils/idl-seed.d.ts +17 -0
  92. package/dist/utils/idl-seed.js +15 -0
  93. package/dist/utils/index.d.ts +2 -0
  94. package/dist/utils/index.js +2 -0
  95. package/dist/utils/logger.d.ts +3 -0
  96. package/dist/utils/logger.js +19 -0
  97. package/dist/utils/note.d.ts +19 -0
  98. package/dist/utils/note.js +83 -0
  99. package/dist/utils/proof.d.ts +11 -0
  100. package/dist/utils/proof.js +91 -0
  101. package/dist/utils/tx.d.ts +11 -0
  102. package/dist/utils/tx.js +62 -0
  103. package/dist/voidify/deposit.d.ts +10 -0
  104. package/dist/voidify/deposit.js +40 -0
  105. package/dist/voidify/index.d.ts +4 -0
  106. package/dist/voidify/index.js +4 -0
  107. package/dist/voidify/program.d.ts +36 -0
  108. package/dist/voidify/program.js +87 -0
  109. package/dist/voidify/relayer/index.d.ts +1 -0
  110. package/dist/voidify/relayer/index.js +1 -0
  111. package/dist/voidify/relayer/list.d.ts +5 -0
  112. package/dist/voidify/relayer/list.js +16 -0
  113. package/dist/voidify/withdraw.d.ts +16 -0
  114. package/dist/voidify/withdraw.js +188 -0
  115. package/package.json +79 -0
@@ -0,0 +1,35 @@
1
+ import { startSubstream } from "../substream/server/index.js";
2
+ import { contextFromConfig, expandHome, loadCliConfig, } from "../cli/helpers.js";
3
+ export function registerSubstreamCommands(program) {
4
+ program
5
+ .command("substream")
6
+ .description("Start the Substream service")
7
+ .option("--port <number>", "Service port")
8
+ .option("--host <host>", "Service listen address")
9
+ .option("--db <path>", "Database path")
10
+ .action(async (options) => {
11
+ try {
12
+ const opts = program.opts();
13
+ const cfg = loadCliConfig(opts);
14
+ if (!cfg.substreamServer) {
15
+ throw new Error("substreamServer is not configured. Set substreamServer to {port, host, dbPath}, or rerun `voidify-cli config init --type substream`.");
16
+ }
17
+ const dbPath = options.db ?? cfg.substreamServer.dbPath;
18
+ if (!dbPath) {
19
+ throw new Error("substreamServer.dbPath is not configured, and --db was not provided. Choose one of them.");
20
+ }
21
+ const ctx = await contextFromConfig(cfg, opts.keypair);
22
+ await startSubstream(ctx, {
23
+ port: options.port
24
+ ? parseInt(options.port)
25
+ : cfg.substreamServer.port,
26
+ host: options.host ?? cfg.substreamServer.host,
27
+ dbPath: expandHome(dbPath),
28
+ });
29
+ }
30
+ catch (error) {
31
+ console.error("Substream service failed:", error);
32
+ process.exit(1);
33
+ }
34
+ });
35
+ }
@@ -0,0 +1,2 @@
1
+ import { Command } from "commander";
2
+ export declare function registerWithdrawCommands(program: Command): void;
@@ -0,0 +1,23 @@
1
+ import { withdraw } from "../voidify/withdraw.js";
2
+ import { createServiceContext } from "../cli/helpers.js";
3
+ export function registerWithdrawCommands(program) {
4
+ program
5
+ .command("withdraw")
6
+ .description("Withdraw through a relayer")
7
+ .requiredOption("--note <string>", "Note generated when depositing")
8
+ .requiredOption("--recipient <pubkey>", "Recipient address")
9
+ .requiredOption("--relayer <pubkey>", "Relayer address")
10
+ .option("--dry", "Dry run: print withdraw information without generating a proof")
11
+ .action(async (options) => {
12
+ try {
13
+ const ctx = await createServiceContext(program.opts());
14
+ const result = await withdraw(ctx, options.note, options.recipient, options.relayer, options.dry ?? false);
15
+ console.log("Withdraw successful:", { txSignature: result });
16
+ process.exit(0);
17
+ }
18
+ catch (error) {
19
+ console.error("Withdraw failed:", error);
20
+ process.exit(1);
21
+ }
22
+ });
23
+ }
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/cli.js ADDED
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from "commander";
3
+ import { registerDepositCommands } from "./cli/deposit.js";
4
+ import { registerNoteCommands } from "./cli/note.js";
5
+ import { registerWithdrawCommands } from "./cli/withdraw.js";
6
+ import { registerRelayerCommands } from "./cli/relayer.js";
7
+ import { registerSubstreamCommands } from "./cli/substream.js";
8
+ import { registerConfigCommand } from "./cli/config/command.js";
9
+ const program = new Command();
10
+ program
11
+ .enablePositionalOptions()
12
+ .option("-k, --keypair <path>", "Specify the keypair file path")
13
+ .option("--url <url>", "Specify the RPC URL")
14
+ .option("-c, --config <path>", "Specify the client config file path")
15
+ .description("Command-line tool for interacting with the Anchor voidify program");
16
+ registerDepositCommands(program);
17
+ registerNoteCommands(program);
18
+ registerWithdrawCommands(program);
19
+ registerConfigCommand(program);
20
+ registerRelayerCommands(program);
21
+ registerSubstreamCommands(program);
22
+ process.on("unhandledRejection", (reason) => {
23
+ console.error("Unhandled rejection:", reason instanceof Error ? reason.message : reason);
24
+ process.exitCode = 1;
25
+ });
26
+ process.on("uncaughtException", (err) => {
27
+ console.error("Uncaught exception:", err instanceof Error ? err.message : err);
28
+ process.exit(1);
29
+ });
30
+ program.parse();
@@ -0,0 +1,45 @@
1
+ import * as anchor from "@coral-xyz/anchor";
2
+ import { Connection, Keypair, PublicKey } from "@solana/web3.js";
3
+ import type { SubstreamRepos } from "./substream/types.js";
4
+ export type SubstreamMode = "remote" | "local" | "auto";
5
+ export type SubstreamConfig = {
6
+ type: "remote";
7
+ url: string;
8
+ makeRepos?: () => SubstreamRepos;
9
+ } | {
10
+ type: "local";
11
+ makeRepos?: () => SubstreamRepos;
12
+ } | {
13
+ type: "auto";
14
+ url: string;
15
+ makeRepos?: () => SubstreamRepos;
16
+ };
17
+ export interface ContextOptions {
18
+ rpcUrl?: string;
19
+ programId?: PublicKey;
20
+ stakingProgramId?: PublicKey;
21
+ wallet?: anchor.Wallet | Keypair | null;
22
+ substream?: SubstreamConfig;
23
+ wasmPath?: string;
24
+ zkeyPath?: string;
25
+ }
26
+ export declare class Context {
27
+ private readonly _rpcUrl;
28
+ private readonly _connection;
29
+ private readonly _programId;
30
+ private readonly _stakingProgramId;
31
+ private readonly _substream;
32
+ private readonly _wasmPath;
33
+ private readonly _zkeyPath;
34
+ readonly wallet: anchor.Wallet | null;
35
+ constructor(opts?: ContextOptions);
36
+ get rpcUrl(): string;
37
+ get connection(): Connection;
38
+ get programId(): PublicKey;
39
+ get stakingProgramId(): PublicKey;
40
+ hasStakingProgramId(): boolean;
41
+ get substream(): SubstreamConfig;
42
+ get wasmPath(): string;
43
+ get zkeyPath(): string;
44
+ get publicKey(): PublicKey;
45
+ }
@@ -0,0 +1,77 @@
1
+ import * as anchor from "@coral-xyz/anchor";
2
+ import { Connection, Keypair } from "@solana/web3.js";
3
+ export class Context {
4
+ _rpcUrl;
5
+ _connection;
6
+ _programId;
7
+ _stakingProgramId;
8
+ _substream;
9
+ _wasmPath;
10
+ _zkeyPath;
11
+ wallet;
12
+ constructor(opts = {}) {
13
+ this._rpcUrl = opts.rpcUrl ?? null;
14
+ this._connection = opts.rpcUrl
15
+ ? new Connection(opts.rpcUrl, "confirmed")
16
+ : null;
17
+ this._programId = opts.programId ?? null;
18
+ this._stakingProgramId = opts.stakingProgramId ?? null;
19
+ this._substream = opts.substream ?? null;
20
+ this._wasmPath = opts.wasmPath ?? null;
21
+ this._zkeyPath = opts.zkeyPath ?? null;
22
+ const w = opts.wallet ?? null;
23
+ this.wallet =
24
+ w === null ? null : w instanceof Keypair ? new anchor.Wallet(w) : w;
25
+ }
26
+ get rpcUrl() {
27
+ if (!this._rpcUrl) {
28
+ throw new Error("rpcUrl is required for this operation");
29
+ }
30
+ return this._rpcUrl;
31
+ }
32
+ get connection() {
33
+ if (!this._connection) {
34
+ throw new Error("rpcUrl/connection is required for this operation");
35
+ }
36
+ return this._connection;
37
+ }
38
+ get programId() {
39
+ if (!this._programId) {
40
+ throw new Error("programId is required for this operation");
41
+ }
42
+ return this._programId;
43
+ }
44
+ get stakingProgramId() {
45
+ if (!this._stakingProgramId) {
46
+ throw new Error("stakingProgramId is required for this operation");
47
+ }
48
+ return this._stakingProgramId;
49
+ }
50
+ hasStakingProgramId() {
51
+ return this._stakingProgramId !== null;
52
+ }
53
+ get substream() {
54
+ if (!this._substream) {
55
+ throw new Error("substream config is required for this operation");
56
+ }
57
+ return this._substream;
58
+ }
59
+ get wasmPath() {
60
+ if (!this._wasmPath) {
61
+ throw new Error("wasmPath is required for this operation (proof generation)");
62
+ }
63
+ return this._wasmPath;
64
+ }
65
+ get zkeyPath() {
66
+ if (!this._zkeyPath) {
67
+ throw new Error("zkeyPath is required for this operation (proof generation)");
68
+ }
69
+ return this._zkeyPath;
70
+ }
71
+ get publicKey() {
72
+ if (!this.wallet) {
73
+ throw new Error("wallet is required for this operation");
74
+ }
75
+ return this.wallet.publicKey;
76
+ }
77
+ }