@zebec-network/zebec-vault-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.
@@ -0,0 +1,3 @@
1
+ export type RpcNetwork = "mainnet-beta" | "devnet";
2
+ export declare const ZEBEC_VAULT_PROGRAM_ID: Record<RpcNetwork, string>;
3
+ export declare const TEN_BIGNUM: BigNumber;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TEN_BIGNUM = exports.ZEBEC_VAULT_PROGRAM_ID = void 0;
4
+ const bignumber_js_1 = require("bignumber.js");
5
+ exports.ZEBEC_VAULT_PROGRAM_ID = {
6
+ "mainnet-beta": "Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS",
7
+ devnet: "Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS",
8
+ };
9
+ exports.TEN_BIGNUM = (0, bignumber_js_1.BigNumber)(10);
@@ -0,0 +1 @@
1
+ export * from "./artifacts";
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./artifacts"), exports);
package/dist/pda.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { Address } from "@coral-xyz/anchor";
2
+ import { PublicKey } from "@solana/web3.js";
3
+ export declare function deriveVaultSigner(vault: Address, programId: Address): [PublicKey, number];
package/dist/pda.js ADDED
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deriveVaultSigner = deriveVaultSigner;
4
+ const anchor_1 = require("@coral-xyz/anchor");
5
+ const web3_js_1 = require("@solana/web3.js");
6
+ const SEEDS = {
7
+ VAULT_SIGNER: [97, 97, 99, 115, 95, 118, 97, 117, 108, 116, 95, 115, 105, 103, 110, 101, 114],
8
+ };
9
+ function deriveVaultSigner(vault, programId) {
10
+ const addressAndBump = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(SEEDS.VAULT_SIGNER), (0, anchor_1.translateAddress)(vault).toBuffer()], (0, anchor_1.translateAddress)(programId));
11
+ return addressAndBump;
12
+ }
@@ -0,0 +1,91 @@
1
+ import { Address, BN, Program, Provider } from "@coral-xyz/anchor";
2
+ import { AccountMeta, Keypair, PublicKey, TransactionInstruction } from "@solana/web3.js";
3
+ import { TransactionPayload } from "@zebec-network/solana-common";
4
+ import { ZebecVaultIdlV1 } from "./artifacts";
5
+ import { RpcNetwork } from "./constants";
6
+ export type Numeric = number | string | bigint;
7
+ export type ProposalAction = {
8
+ programId: PublicKey;
9
+ accountSpecs: {
10
+ pubkey: PublicKey;
11
+ isSigner: boolean;
12
+ isWritable: boolean;
13
+ }[];
14
+ data: Buffer;
15
+ };
16
+ export type VaultInfo = {
17
+ vault: string;
18
+ owner: string;
19
+ createdAt: number;
20
+ signerBump: number;
21
+ };
22
+ export declare class ZebecVaultService {
23
+ readonly provider: Provider;
24
+ readonly program: Program<ZebecVaultIdlV1>;
25
+ readonly network: RpcNetwork;
26
+ constructor(provider: Provider, program: Program<ZebecVaultIdlV1>, network: RpcNetwork);
27
+ static create(provider: Provider, network: RpcNetwork, program?: Program<ZebecVaultIdlV1>): Promise<ZebecVaultService>;
28
+ getCreateVaultInstruction(payer: PublicKey, vault: PublicKey, owner: PublicKey, signerBump: number): Promise<TransactionInstruction>;
29
+ getDepositSolInstruction(depositor: PublicKey, vault: PublicKey, amount: BN): Promise<TransactionInstruction>;
30
+ getWithdrawSolInstruction(withdrawer: PublicKey, vault: PublicKey, amount: BN): Promise<TransactionInstruction>;
31
+ getDepositTokenInstruction(depositor: PublicKey, vault: PublicKey, tokenMint: PublicKey, amount: BN, decimals: number): Promise<TransactionInstruction>;
32
+ getWithdrawTokenInstruction(withdrawer: PublicKey, vault: PublicKey, tokenMint: PublicKey, amount: BN, decimals: number): Promise<TransactionInstruction>;
33
+ getCreateProposalInstruction(proposer: PublicKey, vault: PublicKey, proposal: PublicKey, name: string, actions: ProposalAction[], proposalAccountSize: number): Promise<TransactionInstruction>;
34
+ getAppendActionInstruction(proposer: PublicKey, proposal: PublicKey, actions: ProposalAction[], newProposalAccountSize: number): Promise<TransactionInstruction>;
35
+ getExecuteProposalInstruction(caller: PublicKey, proposal: PublicKey, remainingAccounts: AccountMeta[]): Promise<TransactionInstruction>;
36
+ getExecuteProposalDirectInstruction(vault: PublicKey, proposer: PublicKey, actions: ProposalAction[], remainingAccounts: AccountMeta[]): Promise<TransactionInstruction>;
37
+ createVault(params: {
38
+ payer?: Address;
39
+ vaultKeypair?: Keypair;
40
+ }): Promise<TransactionPayload>;
41
+ depositSol(params: {
42
+ depositor?: Address;
43
+ vault: Address;
44
+ amount: Numeric;
45
+ }): Promise<TransactionPayload>;
46
+ withdrawSol(params: {
47
+ withdrawer?: Address;
48
+ vault: Address;
49
+ amount: Numeric;
50
+ }): Promise<TransactionPayload>;
51
+ depositToken(params: {
52
+ depositor?: Address;
53
+ vault: Address;
54
+ tokenMint: Address;
55
+ amount: Numeric;
56
+ }): Promise<TransactionPayload>;
57
+ withdrawToken(params: {
58
+ withdrawer?: Address;
59
+ vault: Address;
60
+ tokenMint: Address;
61
+ amount: Numeric;
62
+ }): Promise<TransactionPayload>;
63
+ createProposal(params: {
64
+ proposer: Address;
65
+ vault: Address;
66
+ proposalKeypair?: Keypair;
67
+ name: string;
68
+ actions: TransactionInstruction[];
69
+ }): Promise<TransactionPayload>;
70
+ appendActions(params: {
71
+ proposer: Address;
72
+ proposal: Address;
73
+ actions: TransactionInstruction[];
74
+ }): Promise<TransactionPayload>;
75
+ executeProposal(params: {
76
+ caller: Address;
77
+ proposal: Address;
78
+ remainingAccounts: AccountMeta[];
79
+ }): Promise<TransactionPayload>;
80
+ executeProposalDirect(params: {
81
+ vault: Address;
82
+ proposer?: Address;
83
+ actions: TransactionInstruction[];
84
+ }): Promise<TransactionPayload>;
85
+ private _createTransactionPayload;
86
+ getVaultInfosOfUser(user?: Address): Promise<VaultInfo[]>;
87
+ getAllVaultsInfo(): Promise<VaultInfo[]>;
88
+ getAllProposalOfVault(vault: Address): Promise<any>;
89
+ get programId(): PublicKey;
90
+ get connection(): import("@solana/web3.js").Connection;
91
+ }
@@ -0,0 +1,379 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ZebecVaultService = void 0;
4
+ const anchor_1 = require("@coral-xyz/anchor");
5
+ const web3_js_1 = require("@solana/web3.js");
6
+ const solana_common_1 = require("@zebec-network/solana-common");
7
+ const artifacts_1 = require("./artifacts");
8
+ const pda_1 = require("./pda");
9
+ const utils_1 = require("./utils");
10
+ class ZebecVaultService {
11
+ provider;
12
+ program;
13
+ network;
14
+ constructor(provider, program, network) {
15
+ this.provider = provider;
16
+ this.program = program;
17
+ this.network = network;
18
+ }
19
+ static async create(provider, network, program) {
20
+ program = program ?? new anchor_1.Program(artifacts_1.ZEBEC_STAKE_VAULT_IDL_V1, provider);
21
+ return new ZebecVaultService(provider, program, network);
22
+ }
23
+ async getCreateVaultInstruction(payer, vault, owner, signerBump) {
24
+ return this.program.methods
25
+ .createVault({
26
+ owner,
27
+ signerBump,
28
+ })
29
+ .accounts({
30
+ payer,
31
+ vault,
32
+ })
33
+ .instruction();
34
+ }
35
+ async getDepositSolInstruction(depositor, vault, amount) {
36
+ return this.program.methods
37
+ .depositSol({
38
+ amount,
39
+ })
40
+ .accounts({
41
+ vault,
42
+ depositor,
43
+ })
44
+ .instruction();
45
+ }
46
+ async getWithdrawSolInstruction(withdrawer, vault, amount) {
47
+ return this.program.methods
48
+ .withdrawSol({
49
+ amount,
50
+ })
51
+ .accounts({
52
+ vault,
53
+ withdrawer,
54
+ })
55
+ .instruction();
56
+ }
57
+ async getDepositTokenInstruction(depositor, vault, tokenMint, amount, decimals) {
58
+ return this.program.methods
59
+ .depositToken({
60
+ amount,
61
+ decimals,
62
+ })
63
+ .accounts({
64
+ vault,
65
+ depositor,
66
+ tokenMint,
67
+ })
68
+ .instruction();
69
+ }
70
+ async getWithdrawTokenInstruction(withdrawer, vault, tokenMint, amount, decimals) {
71
+ return this.program.methods
72
+ .withdrawToken({
73
+ amount,
74
+ decimals,
75
+ })
76
+ .accounts({
77
+ vault,
78
+ withdrawer,
79
+ tokenMint,
80
+ })
81
+ .instruction();
82
+ }
83
+ async getCreateProposalInstruction(proposer, vault, proposal, name, actions, proposalAccountSize) {
84
+ return this.program.methods
85
+ .createProposal({
86
+ actions,
87
+ name,
88
+ proposalAccountSize,
89
+ })
90
+ .accounts({
91
+ vault,
92
+ proposal,
93
+ proposer,
94
+ })
95
+ .instruction();
96
+ }
97
+ async getAppendActionInstruction(proposer, proposal, actions, newProposalAccountSize) {
98
+ return this.program.methods
99
+ .appendActions({
100
+ actions,
101
+ proposalAccountSize: newProposalAccountSize,
102
+ })
103
+ .accounts({
104
+ proposal,
105
+ proposer,
106
+ })
107
+ .instruction();
108
+ }
109
+ async getExecuteProposalInstruction(caller, proposal, remainingAccounts) {
110
+ return this.program.methods
111
+ .executeProposal()
112
+ .accounts({
113
+ proposal,
114
+ caller,
115
+ })
116
+ .remainingAccounts(remainingAccounts)
117
+ .instruction();
118
+ }
119
+ async getExecuteProposalDirectInstruction(vault, proposer, actions, remainingAccounts) {
120
+ return this.program.methods
121
+ .executeProposalDirect({
122
+ actions,
123
+ })
124
+ .accounts({
125
+ vault,
126
+ proposer,
127
+ })
128
+ .remainingAccounts(remainingAccounts)
129
+ .instruction();
130
+ }
131
+ async createVault(params) {
132
+ const payer = params.payer ? (0, anchor_1.translateAddress)(params.payer) : this.provider.publicKey;
133
+ if (!payer) {
134
+ throw new Error("Either provide a payer or use AnchorProvider for provider in the service");
135
+ }
136
+ const vaultKeypair = params.vaultKeypair ?? web3_js_1.Keypair.generate();
137
+ const [, signerBump] = (0, pda_1.deriveVaultSigner)(vaultKeypair.publicKey, this.programId);
138
+ const ix = await this.getCreateVaultInstruction(payer, vaultKeypair.publicKey, payer, signerBump);
139
+ return this._createTransactionPayload(payer, [ix], [vaultKeypair]);
140
+ }
141
+ async depositSol(params) {
142
+ const depositor = params.depositor ? (0, anchor_1.translateAddress)(params.depositor) : this.provider.publicKey;
143
+ if (!depositor) {
144
+ throw new Error("Either provide a depositor or use AnchorProvider for provider in the service");
145
+ }
146
+ const vault = (0, anchor_1.translateAddress)(params.vault);
147
+ const amount = new anchor_1.BN((0, solana_common_1.parseSol)(params.amount).toString());
148
+ const ix = await this.getDepositSolInstruction(depositor, vault, amount);
149
+ return this._createTransactionPayload(depositor, [ix]);
150
+ }
151
+ async withdrawSol(params) {
152
+ const withdrawer = params.withdrawer ? (0, anchor_1.translateAddress)(params.withdrawer) : this.provider.publicKey;
153
+ if (!withdrawer) {
154
+ throw new Error("Either provide a withdrawer or use AnchorProvider for provider in the service");
155
+ }
156
+ const vault = (0, anchor_1.translateAddress)(params.vault);
157
+ const amount = new anchor_1.BN((0, solana_common_1.parseSol)(params.amount).toString());
158
+ const ix = await this.getWithdrawSolInstruction(withdrawer, vault, amount);
159
+ return this._createTransactionPayload(withdrawer, [ix]);
160
+ }
161
+ async depositToken(params) {
162
+ const depositor = params.depositor ? (0, anchor_1.translateAddress)(params.depositor) : this.provider.publicKey;
163
+ if (!depositor) {
164
+ throw new Error("Either provide a depositor or use AnchorProvider for provider in the service");
165
+ }
166
+ const vault = (0, anchor_1.translateAddress)(params.vault);
167
+ const tokenMint = (0, anchor_1.translateAddress)(params.tokenMint);
168
+ const decimals = await (0, solana_common_1.getMintDecimals)(this.provider.connection, tokenMint);
169
+ const amount = new anchor_1.BN((0, solana_common_1.parseToken)(params.amount, decimals).toString());
170
+ const ix = await this.getDepositTokenInstruction(depositor, vault, tokenMint, amount, decimals);
171
+ return this._createTransactionPayload(depositor, [ix]);
172
+ }
173
+ async withdrawToken(params) {
174
+ const withdrawer = params.withdrawer ? (0, anchor_1.translateAddress)(params.withdrawer) : this.provider.publicKey;
175
+ if (!withdrawer) {
176
+ throw new Error("Either provide a withdrawer or use AnchorProvider for provider in the service");
177
+ }
178
+ const vault = (0, anchor_1.translateAddress)(params.vault);
179
+ const tokenMint = (0, anchor_1.translateAddress)(params.tokenMint);
180
+ const decimals = await (0, solana_common_1.getMintDecimals)(this.provider.connection, tokenMint);
181
+ const amount = new anchor_1.BN((0, solana_common_1.parseToken)(params.amount, decimals).toString());
182
+ const ix = await this.getWithdrawTokenInstruction(withdrawer, vault, tokenMint, amount, decimals);
183
+ return this._createTransactionPayload(withdrawer, [ix]);
184
+ }
185
+ async createProposal(params) {
186
+ const proposer = params.proposer ? (0, anchor_1.translateAddress)(params.proposer) : this.provider.publicKey;
187
+ if (!proposer) {
188
+ throw new Error("Either provide a proposer or use AnchorProvider for provider in the service");
189
+ }
190
+ const vault = (0, anchor_1.translateAddress)(params.vault);
191
+ const proposalKeypair = params.proposalKeypair ?? web3_js_1.Keypair.generate();
192
+ const actions = params.actions.map((ix) => ({
193
+ accountSpecs: ix.keys,
194
+ data: ix.data,
195
+ programId: ix.programId,
196
+ }));
197
+ const proposalAccountSize = (0, utils_1.calculateProposalSize)(actions);
198
+ if (proposalAccountSize > 10_000) {
199
+ throw new Error("Proposal size exceeds maximum allowed size of 10,000 bytes");
200
+ }
201
+ const ix = await this.getCreateProposalInstruction(proposer, vault, proposalKeypair.publicKey, params.name, actions, proposalAccountSize);
202
+ return this._createTransactionPayload(proposer, [ix]);
203
+ }
204
+ async appendActions(params) {
205
+ const proposer = params.proposer ? (0, anchor_1.translateAddress)(params.proposer) : this.provider.publicKey;
206
+ if (!proposer) {
207
+ throw new Error("Either provide a proposer or use AnchorProvider for provider in the service");
208
+ }
209
+ const proposal = (0, anchor_1.translateAddress)(params.proposal);
210
+ const proposalAccount = await this.program.account.proposal.fetchNullable(proposal, this.connection.commitment);
211
+ if (!proposalAccount) {
212
+ throw new Error("Proposal account not found");
213
+ }
214
+ const newActions = params.actions.map((ix) => ({
215
+ accountSpecs: ix.keys,
216
+ data: ix.data,
217
+ programId: ix.programId,
218
+ }));
219
+ const actions = proposalAccount.actions;
220
+ actions.push(...newActions);
221
+ const newProposalAccountSize = (0, utils_1.calculateProposalSize)(actions);
222
+ if (newProposalAccountSize > 10_000) {
223
+ throw new Error("Proposal size exceeds maximum allowed size of 10,000 bytes");
224
+ }
225
+ const ix = await this.getAppendActionInstruction(proposer, proposal, actions, newProposalAccountSize);
226
+ return this._createTransactionPayload(proposer, [ix]);
227
+ }
228
+ async executeProposal(params) {
229
+ const caller = params.caller ? (0, anchor_1.translateAddress)(params.caller) : this.provider.publicKey;
230
+ if (!caller) {
231
+ throw new Error("Either provide a caller or use AnchorProvider for provider in the service");
232
+ }
233
+ const proposal = (0, anchor_1.translateAddress)(params.proposal);
234
+ const proposalAccount = await this.program.account.proposal.fetchNullable(proposal, this.connection.commitment);
235
+ if (!proposalAccount) {
236
+ throw new Error("Proposal account not found");
237
+ }
238
+ const remainingAccounts = proposalAccount.actions.reduce((acc, current) => {
239
+ const accounts = current.accountSpecs.map((spec) => ({
240
+ pubkey: spec.pubkey,
241
+ isSigner: spec.isSigner,
242
+ isWritable: spec.isWritable,
243
+ }));
244
+ acc.push(...accounts);
245
+ return acc;
246
+ }, []);
247
+ const ix = await this.getExecuteProposalInstruction(caller, proposal, remainingAccounts);
248
+ return this._createTransactionPayload(caller, [ix]);
249
+ }
250
+ async executeProposalDirect(params) {
251
+ const proposer = params.proposer ? (0, anchor_1.translateAddress)(params.proposer) : this.provider.publicKey;
252
+ if (!proposer) {
253
+ throw new Error("Either provide a caller or use AnchorProvider for provider in the service");
254
+ }
255
+ const vault = (0, anchor_1.translateAddress)(params.vault);
256
+ const actions = params.actions.map((ix) => ({
257
+ accountSpecs: ix.keys,
258
+ data: ix.data,
259
+ programId: ix.programId,
260
+ }));
261
+ const remainingAccounts = actions.reduce((acc, current) => {
262
+ const accounts = current.accountSpecs.map((spec) => ({
263
+ pubkey: spec.pubkey,
264
+ isSigner: spec.isSigner,
265
+ isWritable: spec.isWritable,
266
+ }));
267
+ acc.push(...accounts);
268
+ return acc;
269
+ }, []);
270
+ const ix = await this.getExecuteProposalDirectInstruction(vault, proposer, actions, remainingAccounts);
271
+ return this._createTransactionPayload(proposer, [ix]);
272
+ }
273
+ async _createTransactionPayload(payerKey, instructions, signers, addressLookupTableAccounts) {
274
+ const errorMap = new Map();
275
+ this.program.idl.errors.forEach((error) => errorMap.set(error.code, error.msg));
276
+ let signTransaction = undefined;
277
+ const provider = this.provider;
278
+ if (provider instanceof anchor_1.AnchorProvider) {
279
+ signTransaction = async (tx) => {
280
+ return provider.wallet.signTransaction(tx);
281
+ };
282
+ }
283
+ return new solana_common_1.TransactionPayload(this.provider.connection, errorMap, instructions, payerKey, signers, addressLookupTableAccounts, signTransaction);
284
+ }
285
+ async getVaultInfosOfUser(user) {
286
+ user = user ? (0, anchor_1.translateAddress)(user) : this.provider.publicKey;
287
+ if (!user) {
288
+ throw new Error("Either provide a user or use AnchorProvider for provider in the service");
289
+ }
290
+ const accountInfos = await this.connection.getProgramAccounts(this.programId, {
291
+ commitment: this.connection.commitment,
292
+ filters: [
293
+ {
294
+ dataSize: 8 + 32 + 8 + 1, // size of Vault
295
+ },
296
+ {
297
+ memcmp: {
298
+ offset: 8, // offset for owner field in Vault
299
+ bytes: user.toBase58(),
300
+ encoding: "base58",
301
+ },
302
+ },
303
+ ],
304
+ });
305
+ const vaults = accountInfos.map((accountInfo) => {
306
+ const vaultAccount = this.program.coder.accounts.decode(this.program.idl.accounts[1].name, accountInfo.account.data);
307
+ return {
308
+ vault: accountInfo.pubkey.toString(),
309
+ owner: vaultAccount.owner.toString(),
310
+ createdAt: vaultAccount.createdAt.toNumber(),
311
+ signerBump: vaultAccount.signerBump,
312
+ };
313
+ });
314
+ return vaults;
315
+ }
316
+ async getAllVaultsInfo() {
317
+ const accountInfos = await this.connection.getProgramAccounts(this.programId, {
318
+ commitment: this.connection.commitment,
319
+ filters: [
320
+ {
321
+ dataSize: 8 + 32 + 8 + 1, // size of Vault
322
+ },
323
+ ],
324
+ });
325
+ const vaults = accountInfos.map((accountInfo) => {
326
+ const vaultAccount = this.program.coder.accounts.decode(this.program.idl.accounts[1].name, accountInfo.account.data);
327
+ return {
328
+ vault: accountInfo.pubkey.toString(),
329
+ owner: vaultAccount.owner.toString(),
330
+ createdAt: vaultAccount.createdAt.toNumber(),
331
+ signerBump: vaultAccount.signerBump,
332
+ };
333
+ });
334
+ return vaults;
335
+ }
336
+ async getAllProposalOfVault(vault) {
337
+ const _vault = (0, anchor_1.translateAddress)(vault);
338
+ const accountInfos = await this.connection.getProgramAccounts(this.programId, {
339
+ commitment: this.connection.commitment,
340
+ filters: [
341
+ {
342
+ memcmp: {
343
+ offset: 0, // offset for discriminator in Vault
344
+ bytes: anchor_1.utils.bytes.bs58.encode(this.program.idl.accounts[0].discriminator),
345
+ encoding: "base58",
346
+ },
347
+ },
348
+ {
349
+ memcmp: {
350
+ offset: 8, // offset for owner field in Vault
351
+ bytes: _vault.toBase58(),
352
+ encoding: "base58",
353
+ },
354
+ },
355
+ ],
356
+ });
357
+ const proposals = accountInfos.map((accountInfo) => {
358
+ const proposalAccount = this.program.coder.accounts.decode(this.program.idl.accounts[0].name, accountInfo.account.data);
359
+ return {
360
+ proposal: accountInfo.pubkey.toString(),
361
+ vault: proposalAccount.vault.toString(),
362
+ proposalStage: proposalAccount.proposalState,
363
+ createdDate: proposalAccount.createdDate.toNumber(),
364
+ expiryDate: proposalAccount.expiryDate.toNumber(),
365
+ isExecuted: proposalAccount.isExecuted,
366
+ name: proposalAccount.name,
367
+ actions: proposalAccount.actions,
368
+ };
369
+ });
370
+ return proposals;
371
+ }
372
+ get programId() {
373
+ return this.program.programId;
374
+ }
375
+ get connection() {
376
+ return this.provider.connection;
377
+ }
378
+ }
379
+ exports.ZebecVaultService = ZebecVaultService;
File without changes
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,3 @@
1
+ import { ProposalAction } from "./service";
2
+ export declare function calculateActionsSize(actions: ProposalAction[]): number;
3
+ export declare function calculateProposalSize(actions: ProposalAction[]): number;
package/dist/utils.js ADDED
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calculateActionsSize = calculateActionsSize;
4
+ exports.calculateProposalSize = calculateProposalSize;
5
+ function calculateActionsSize(actions) {
6
+ return actions
7
+ .map((ix) => 4 + ix.accountSpecs.length * 34 + 4 + ix.data.length + 32)
8
+ .reduce((acc, curr) => acc + curr, 0);
9
+ }
10
+ function calculateProposalSize(actions) {
11
+ const ix_size = calculateActionsSize(actions);
12
+ const withExtraSpace = 32 + 1 + 8 + 8 + 1 + /** name */ 4 + 60 + /** actions */ 4 + ix_size + /** extra */ 20;
13
+ return withExtraSpace;
14
+ }
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@zebec-network/zebec-vault-sdk",
3
+ "version": "1.0.0",
4
+ "description": "An SDK for zebec vault solana program",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "author": "Ashish Sapkota",
8
+ "license": "MIT",
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "keywords": [
13
+ "solana",
14
+ "zebec",
15
+ "zebec network",
16
+ "vualt",
17
+ "zebec vault"
18
+ ],
19
+ "scripts": {
20
+ "build": "npm run clean && tsc",
21
+ "clean": "rimraf ./dist",
22
+ "format": "prettier --write .",
23
+ "test": "ts-mocha -p ./tsconfig.json -t 1000000000"
24
+ },
25
+ "devDependencies": {
26
+ "@types/mocha": "^10.0.10",
27
+ "@types/node": "^24.0.1",
28
+ "mocha": "^11.6.0",
29
+ "prettier": "^3.5.3",
30
+ "rimraf": "^6.0.1",
31
+ "ts-mocha": "^11.1.0",
32
+ "ts-node": "^10.9.2",
33
+ "typescript": "^5.8.3"
34
+ },
35
+ "dependencies": {
36
+ "@coral-xyz/anchor": "^0.31.1",
37
+ "@solana/web3.js": "^1.98.2",
38
+ "@types/bn.js": "^5.2.0",
39
+ "@zebec-network/solana-common": "^1.3.0",
40
+ "bignumber.js": "^9.3.0",
41
+ "buffer": "^6.0.3"
42
+ }
43
+ }