@zcomb/programs-sdk 1.7.0 → 1.8.1

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 (44) hide show
  1. package/dist/futarchy/client.d.ts +113 -1
  2. package/dist/futarchy/client.js +13 -3
  3. package/dist/futarchy/instructions.d.ts +109 -1
  4. package/dist/futarchy/instructions.js +17 -3
  5. package/dist/generated/idls/futarchy.json +112 -0
  6. package/dist/generated/types/futarchy.d.ts +112 -0
  7. package/dist/generated/types/futarchy.js +1 -1
  8. package/package.json +1 -2
  9. package/src/amm/client.ts +0 -485
  10. package/src/amm/constants.ts +0 -31
  11. package/src/amm/index.ts +0 -5
  12. package/src/amm/instructions.ts +0 -139
  13. package/src/amm/types.ts +0 -62
  14. package/src/amm/utils.ts +0 -263
  15. package/src/futarchy/client.ts +0 -1100
  16. package/src/futarchy/constants.ts +0 -28
  17. package/src/futarchy/index.ts +0 -5
  18. package/src/futarchy/instructions.ts +0 -235
  19. package/src/futarchy/types.ts +0 -54
  20. package/src/futarchy/utils.ts +0 -108
  21. package/src/generated/idls/amm.json +0 -1252
  22. package/src/generated/idls/futarchy.json +0 -1763
  23. package/src/generated/idls/index.ts +0 -4
  24. package/src/generated/idls/svault.json +0 -2228
  25. package/src/generated/idls/vault.json +0 -1501
  26. package/src/generated/types/amm.ts +0 -1258
  27. package/src/generated/types/futarchy.ts +0 -1769
  28. package/src/generated/types/index.ts +0 -4
  29. package/src/generated/types/svault.ts +0 -2234
  30. package/src/generated/types/vault.ts +0 -1507
  31. package/src/index.ts +0 -163
  32. package/src/svault/client.ts +0 -401
  33. package/src/svault/constants.ts +0 -23
  34. package/src/svault/index.ts +0 -5
  35. package/src/svault/instructions.ts +0 -258
  36. package/src/svault/types.ts +0 -45
  37. package/src/svault/utils.ts +0 -145
  38. package/src/utils.ts +0 -41
  39. package/src/vault/client.ts +0 -333
  40. package/src/vault/constants.ts +0 -23
  41. package/src/vault/index.ts +0 -5
  42. package/src/vault/instructions.ts +0 -170
  43. package/src/vault/types.ts +0 -54
  44. package/src/vault/utils.ts +0 -70
@@ -1,28 +0,0 @@
1
- /*
2
- * Constants for the Futarchy program.
3
- * Parsed from the generated IDL to stay in sync with the Rust program.
4
- */
5
-
6
- import { PublicKey } from "@solana/web3.js";
7
- import { FutarchyIDL } from "../generated/idls";
8
- import { parseIdlBytes, getIdlConstant } from "../utils";
9
-
10
- /* Program ID */
11
-
12
- export const PROGRAM_ID = new PublicKey(FutarchyIDL.address);
13
-
14
- /* PDA Seeds */
15
-
16
- export const DAO_SEED = parseIdlBytes(getIdlConstant(FutarchyIDL, "DAO_SEED"));
17
- export const MODERATOR_SEED = parseIdlBytes(getIdlConstant(FutarchyIDL, "MODERATOR_SEED"));
18
- export const PROPOSAL_SEED = parseIdlBytes(getIdlConstant(FutarchyIDL, "PROPOSAL_SEED"));
19
-
20
- /* Numeric Constants */
21
-
22
- export const MAX_OPTIONS = Number(getIdlConstant(FutarchyIDL, "MAX_OPTIONS"));
23
- export const MIN_OPTIONS = Number(getIdlConstant(FutarchyIDL, "MIN_OPTIONS"));
24
-
25
- /* Squads Integration */
26
-
27
- export const SQUADS_PROGRAM_ID = new PublicKey("SQDS4ep65T869zMMBKyuUq6aD6EgTu8psMjkvj52pCf");
28
- export const MINT_CREATE_KEY_SEED = parseIdlBytes(getIdlConstant(FutarchyIDL, "MINT_CREATE_KEY_SEED"));
@@ -1,5 +0,0 @@
1
- export * from "./constants";
2
- export * from "./types";
3
- export * from "./utils";
4
- export * from "./instructions";
5
- export * from "./client";
@@ -1,235 +0,0 @@
1
- /*
2
- * Low-level instruction builders for the Futarchy program.
3
- * These are thin wrappers around the program methods - use FutarchyClient for higher-level operations.
4
- */
5
-
6
- import { Program, BN } from "@coral-xyz/anchor";
7
- import { PublicKey } from "@solana/web3.js";
8
- import { Futarchy, ProposalParams, PoolType } from "./types";
9
-
10
- /* Instruction Builders */
11
-
12
- export function initializeModerator(
13
- program: Program<Futarchy>,
14
- admin: PublicKey,
15
- baseMint: PublicKey,
16
- quoteMint: PublicKey,
17
- moderator: PublicKey,
18
- name: string
19
- ) {
20
- return program.methods.initializeModerator(name).accountsPartial({
21
- admin,
22
- baseMint,
23
- quoteMint,
24
- moderator,
25
- });
26
- }
27
-
28
- export function initializeProposal(
29
- program: Program<Futarchy>,
30
- creator: PublicKey,
31
- moderator: PublicKey,
32
- proposal: PublicKey,
33
- proposalParams: ProposalParams,
34
- metadata: string | null,
35
- remainingAccounts: { pubkey: PublicKey; isSigner: boolean; isWritable: boolean }[]
36
- ) {
37
- return program.methods
38
- .initializeProposal(proposalParams, metadata)
39
- .accountsPartial({
40
- creator,
41
- moderator,
42
- proposal,
43
- })
44
- .remainingAccounts(remainingAccounts);
45
- }
46
-
47
- export function addOption(
48
- program: Program<Futarchy>,
49
- creator: PublicKey,
50
- proposal: PublicKey,
51
- remainingAccounts: { pubkey: PublicKey; isSigner: boolean; isWritable: boolean }[]
52
- ) {
53
- return program.methods
54
- .addOption()
55
- .accountsPartial({
56
- creator,
57
- proposal,
58
- })
59
- .remainingAccounts(remainingAccounts);
60
- }
61
-
62
- export function launchProposal(
63
- program: Program<Futarchy>,
64
- creator: PublicKey,
65
- proposal: PublicKey,
66
- vault: PublicKey,
67
- baseAmount: BN | number,
68
- quoteAmount: BN | number,
69
- remainingAccounts: { pubkey: PublicKey; isSigner: boolean; isWritable: boolean }[]
70
- ) {
71
- const baseAmountBN = typeof baseAmount === "number" ? new BN(baseAmount) : baseAmount;
72
- const quoteAmountBN = typeof quoteAmount === "number" ? new BN(quoteAmount) : quoteAmount;
73
-
74
- return program.methods
75
- .launchProposal(baseAmountBN, quoteAmountBN)
76
- .accountsPartial({
77
- creator,
78
- proposal,
79
- vault,
80
- })
81
- .remainingAccounts(remainingAccounts);
82
- }
83
-
84
- export function finalizeProposal(
85
- program: Program<Futarchy>,
86
- signer: PublicKey,
87
- proposal: PublicKey,
88
- vault: PublicKey,
89
- remainingAccounts: { pubkey: PublicKey; isSigner: boolean; isWritable: boolean }[]
90
- ) {
91
- return program.methods
92
- .finalizeProposal()
93
- .accountsPartial({
94
- signer,
95
- proposal,
96
- vault,
97
- })
98
- .remainingAccounts(remainingAccounts);
99
- }
100
-
101
- export function redeemLiquidity(
102
- program: Program<Futarchy>,
103
- creator: PublicKey,
104
- proposal: PublicKey,
105
- vault: PublicKey,
106
- pool: PublicKey,
107
- remainingAccounts: { pubkey: PublicKey; isSigner: boolean; isWritable: boolean }[]
108
- ) {
109
- return program.methods
110
- .redeemLiquidity()
111
- .accountsPartial({
112
- creator,
113
- proposal,
114
- vault,
115
- pool,
116
- })
117
- .remainingAccounts(remainingAccounts);
118
- }
119
-
120
- export function addHistoricalProposal(
121
- program: Program<Futarchy>,
122
- admin: PublicKey,
123
- moderator: PublicKey,
124
- proposal: PublicKey,
125
- numOptions: number,
126
- winningIdx: number,
127
- length: number,
128
- createdAt: BN | number
129
- ) {
130
- const createdAtBN = typeof createdAt === "number" ? new BN(createdAt) : createdAt;
131
- return program.methods
132
- .addHistoricalProposal(numOptions, winningIdx, length, createdAtBN)
133
- .accountsPartial({
134
- admin,
135
- moderator,
136
- proposal,
137
- });
138
- }
139
-
140
- /* DAO Instruction Builders */
141
-
142
- export function initializeParentDAO(
143
- program: Program<Futarchy>,
144
- admin: PublicKey,
145
- parentAdmin: PublicKey,
146
- dao: PublicKey,
147
- moderator: PublicKey,
148
- baseMint: PublicKey,
149
- quoteMint: PublicKey,
150
- programConfig: PublicKey,
151
- programConfigTreasury: PublicKey,
152
- treasuryMultisig: PublicKey,
153
- mintMultisig: PublicKey,
154
- mintCreateKey: PublicKey,
155
- squadsProgram: PublicKey,
156
- name: string,
157
- treasuryCosigner: PublicKey,
158
- pool: PublicKey,
159
- poolType: PoolType
160
- ) {
161
- return program.methods
162
- .initializeParentDao(name, treasuryCosigner, pool, poolType)
163
- .accountsPartial({
164
- admin,
165
- parentAdmin,
166
- dao,
167
- moderator,
168
- baseMint,
169
- quoteMint,
170
- programConfig,
171
- programConfigTreasury,
172
- treasuryMultisig,
173
- mintMultisig,
174
- mintCreateKey,
175
- squadsProgram,
176
- });
177
- }
178
-
179
- export function initializeChildDAO(
180
- program: Program<Futarchy>,
181
- admin: PublicKey,
182
- parentAdmin: PublicKey,
183
- dao: PublicKey,
184
- parentDao: PublicKey,
185
- tokenMint: PublicKey,
186
- programConfig: PublicKey,
187
- programConfigTreasury: PublicKey,
188
- treasuryMultisig: PublicKey,
189
- mintMultisig: PublicKey,
190
- mintCreateKey: PublicKey,
191
- squadsProgram: PublicKey,
192
- name: string,
193
- treasuryCosigner: PublicKey
194
- ) {
195
- return program.methods
196
- .initializeChildDao(name, treasuryCosigner)
197
- .accountsPartial({
198
- admin,
199
- parentAdmin,
200
- dao,
201
- parentDao,
202
- tokenMint,
203
- programConfig,
204
- programConfigTreasury,
205
- treasuryMultisig,
206
- mintMultisig,
207
- mintCreateKey,
208
- squadsProgram,
209
- });
210
- }
211
-
212
- export function upgradeDAO(
213
- program: Program<Futarchy>,
214
- admin: PublicKey,
215
- parentAdmin: PublicKey,
216
- dao: PublicKey,
217
- parentDao: PublicKey,
218
- moderator: PublicKey,
219
- baseMint: PublicKey,
220
- quoteMint: PublicKey,
221
- pool: PublicKey,
222
- poolType: PoolType
223
- ) {
224
- return program.methods
225
- .upgradeDao(pool, poolType)
226
- .accountsPartial({
227
- admin,
228
- parentAdmin,
229
- dao,
230
- parentDao,
231
- moderator,
232
- baseMint,
233
- quoteMint,
234
- });
235
- }
@@ -1,54 +0,0 @@
1
- /*
2
- * Type definitions for the Futarchy program.
3
- * Derived from the generated IDL types.
4
- */
5
-
6
- import { IdlAccounts, IdlEvents, IdlTypes } from "@coral-xyz/anchor";
7
-
8
- // Re-export the generated IDL type
9
- export { Futarchy } from "../generated/types";
10
- import type { Futarchy } from "../generated/types";
11
-
12
- /* Account Types */
13
-
14
- export type DAOAccount = IdlAccounts<Futarchy>["daoAccount"];
15
- export type ModeratorAccount = IdlAccounts<Futarchy>["moderatorAccount"];
16
- export type ProposalAccount = IdlAccounts<Futarchy>["proposalAccount"];
17
-
18
- /* IDL Types */
19
-
20
- export type ProposalParams = IdlTypes<Futarchy>["proposalParams"];
21
- export type ProposalStateRaw = IdlTypes<Futarchy>["proposalState"];
22
- export type DAOType = IdlTypes<Futarchy>["daoType"];
23
- export type PoolType = IdlTypes<Futarchy>["poolType"];
24
-
25
- /* Event Types */
26
-
27
- export type DAOInitializedEvent = IdlEvents<Futarchy>["daoInitialized"];
28
- export type DAOUpgradedEvent = IdlEvents<Futarchy>["daoUpgraded"];
29
- export type ModeratorInitializedEvent = IdlEvents<Futarchy>["moderatorInitialized"];
30
- export type ProposalInitializedEvent = IdlEvents<Futarchy>["proposalInitialized"];
31
- export type ProposalLaunchedEvent = IdlEvents<Futarchy>["proposalLaunched"];
32
- export type OptionAddedEvent = IdlEvents<Futarchy>["optionAdded"];
33
- export type ProposalFinalizedEvent = IdlEvents<Futarchy>["proposalFinalized"];
34
- export type LiquidityRedeemedEvent = IdlEvents<Futarchy>["liquidityRedeemed"];
35
-
36
- /* Enums */
37
-
38
- export enum ProposalState {
39
- Setup = "setup",
40
- Pending = "pending",
41
- Resolved = "resolved",
42
- }
43
-
44
- /* Event Union Type */
45
-
46
- export type FutarchyEvent =
47
- | { name: "DAOInitialized"; data: DAOInitializedEvent }
48
- | { name: "DAOUpgraded"; data: DAOUpgradedEvent }
49
- | { name: "ModeratorInitialized"; data: ModeratorInitializedEvent }
50
- | { name: "ProposalInitialized"; data: ProposalInitializedEvent }
51
- | { name: "ProposalLaunched"; data: ProposalLaunchedEvent }
52
- | { name: "OptionAdded"; data: OptionAddedEvent }
53
- | { name: "ProposalFinalized"; data: ProposalFinalizedEvent }
54
- | { name: "LiquidityRedeemed"; data: LiquidityRedeemedEvent };
@@ -1,108 +0,0 @@
1
- /*
2
- * Utility functions for the Futarchy program.
3
- * Includes PDA derivation, parsers, and fetch helpers.
4
- */
5
-
6
- import { Program } from "@coral-xyz/anchor";
7
- import { PublicKey } from "@solana/web3.js";
8
- import { DAO_SEED, MODERATOR_SEED, PROPOSAL_SEED, MINT_CREATE_KEY_SEED, PROGRAM_ID } from "./constants";
9
- import { Futarchy, DAOAccount, ModeratorAccount, ProposalAccount, ProposalState } from "./types";
10
-
11
- /* PDA Derivation */
12
-
13
- export function deriveDAOPDA(
14
- name: string,
15
- programId: PublicKey = PROGRAM_ID
16
- ): [PublicKey, number] {
17
- return PublicKey.findProgramAddressSync(
18
- [DAO_SEED, Buffer.from(name)],
19
- programId
20
- );
21
- }
22
-
23
- export function deriveModeratorPDA(
24
- name: string,
25
- programId: PublicKey = PROGRAM_ID
26
- ): [PublicKey, number] {
27
- return PublicKey.findProgramAddressSync(
28
- [MODERATOR_SEED, Buffer.from(name)],
29
- programId
30
- );
31
- }
32
-
33
- export function deriveProposalPDA(
34
- moderator: PublicKey,
35
- proposalId: number,
36
- programId: PublicKey = PROGRAM_ID
37
- ): [PublicKey, number] {
38
- const proposalIdBuffer = Buffer.alloc(2);
39
- proposalIdBuffer.writeUInt16LE(proposalId);
40
- return PublicKey.findProgramAddressSync(
41
- [PROPOSAL_SEED, moderator.toBuffer(), proposalIdBuffer],
42
- programId
43
- );
44
- }
45
-
46
- export function deriveMintCreateKeyPDA(
47
- daoPda: PublicKey,
48
- name: string,
49
- programId: PublicKey = PROGRAM_ID
50
- ): [PublicKey, number] {
51
- return PublicKey.findProgramAddressSync(
52
- [daoPda.toBuffer(), MINT_CREATE_KEY_SEED, Buffer.from(name)],
53
- programId
54
- );
55
- }
56
-
57
- /* Parsers */
58
-
59
- export function parseProposalState(state: any): { state: ProposalState; winningIdx: number | null } {
60
- if ("setup" in state) {
61
- return { state: ProposalState.Setup, winningIdx: null };
62
- }
63
- if ("pending" in state) {
64
- return { state: ProposalState.Pending, winningIdx: null };
65
- }
66
- if ("resolved" in state) {
67
- const winningIdx = state.resolved[0] ?? state.resolved;
68
- return { state: ProposalState.Resolved, winningIdx };
69
- }
70
- throw new Error("Unknown proposal state");
71
- }
72
-
73
- /* Fetchers */
74
-
75
- export async function fetchDAOAccount(
76
- program: Program<Futarchy>,
77
- daoPda: PublicKey
78
- ): Promise<DAOAccount> {
79
- return program.account.daoAccount.fetch(daoPda);
80
- }
81
-
82
- export async function fetchModeratorAccount(
83
- program: Program<Futarchy>,
84
- moderatorPda: PublicKey
85
- ): Promise<ModeratorAccount> {
86
- return program.account.moderatorAccount.fetch(moderatorPda);
87
- }
88
-
89
- export async function fetchProposalAccount(
90
- program: Program<Futarchy>,
91
- proposalPda: PublicKey
92
- ): Promise<ProposalAccount> {
93
- return program.account.proposalAccount.fetch(proposalPda);
94
- }
95
-
96
- /* Proposal Helpers */
97
-
98
- export function isProposalExpired(proposal: ProposalAccount, currentTime?: number): boolean {
99
- const now = currentTime ?? Math.floor(Date.now() / 1000);
100
- const endTime = proposal.createdAt.toNumber() + proposal.config.length;
101
- return now >= endTime;
102
- }
103
-
104
- export function getTimeRemaining(proposal: ProposalAccount, currentTime?: number): number {
105
- const now = currentTime ?? Math.floor(Date.now() / 1000);
106
- const endTime = proposal.createdAt.toNumber() + proposal.config.length;
107
- return Math.max(0, endTime - now);
108
- }