@zebec-network/zebec-vault-sdk 2.0.0 → 3.1.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.
- package/README.md +219 -219
- package/dist/artifacts/index.d.ts +7 -3
- package/dist/artifacts/index.js +9 -3
- package/dist/artifacts/zebec_instant_card.d.ts +1690 -0
- package/dist/artifacts/zebec_instant_card.js +2 -0
- package/dist/artifacts/zebec_instant_card.json +1444 -0
- package/dist/artifacts/zebec_stream.d.ts +1902 -0
- package/dist/artifacts/zebec_stream.js +2 -0
- package/dist/artifacts/zebec_stream.json +1596 -0
- package/dist/artifacts/zebec_vault.d.ts +1442 -169
- package/dist/artifacts/zebec_vault.json +1178 -891
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +3 -1
- package/dist/pda.d.ts +6 -0
- package/dist/pda.js +40 -3
- package/dist/service.d.ts +152 -8
- package/dist/service.js +396 -35
- package/dist/types.d.ts +1 -1
- package/package.json +12 -11
package/README.md
CHANGED
|
@@ -1,219 +1,219 @@
|
|
|
1
|
-
# Zebec Vault Sdk
|
|
2
|
-
|
|
3
|
-
## Installation
|
|
4
|
-
|
|
5
|
-
```bash
|
|
6
|
-
yarn add @zebec-network/zebec-vault-sdk
|
|
7
|
-
```
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
npm install @zebec-network/zebec-vault-sdk
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## Dependency Map
|
|
14
|
-
|
|
15
|
-

|
|
16
|
-
|
|
17
|
-
## Development
|
|
18
|
-
|
|
19
|
-
To build the package
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
yarn build
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
To run specific test filess
|
|
26
|
-
|
|
27
|
-
```bash
|
|
28
|
-
yarn test <test file path> -f "<regex for test name>"
|
|
29
|
-
// example:
|
|
30
|
-
// yarn test ./test/<filename>.test.ts
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
## publish
|
|
34
|
-
|
|
35
|
-
Build package and bump package version to specific need and publish
|
|
36
|
-
|
|
37
|
-
```bash
|
|
38
|
-
npm publish --access public
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
## Usage
|
|
42
|
-
|
|
43
|
-
### Create Vault Instance
|
|
44
|
-
|
|
45
|
-
```ts
|
|
46
|
-
const network = "devnet";
|
|
47
|
-
const wallet = <Anchor wallet>;
|
|
48
|
-
const connection = <Connection Instance>;
|
|
49
|
-
const provider = createAnchorProvider(connection, wallet);
|
|
50
|
-
const service = await ZebecVaultService.create(provider, network);
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
### Create Vault
|
|
54
|
-
|
|
55
|
-
```ts
|
|
56
|
-
const vaultKeypair = Keypair.generate();
|
|
57
|
-
console.log("Vault Keypair:", vaultKeypair.publicKey.toBase58());
|
|
58
|
-
const payload = await service.createVault({
|
|
59
|
-
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
const signature = await payload.execute({ commitment: "finalized" });
|
|
63
|
-
console.log("Signature:", signature);
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
### Get Vault Info of User
|
|
67
|
-
|
|
68
|
-
```ts
|
|
69
|
-
const vaultsInfo = await service.getVaultsInfoOfUser(wallet.publicKey);
|
|
70
|
-
console.log("vaults info:", JSON.stringify(vaultsInfo, null, 2));
|
|
71
|
-
const vault = vaultsInfo[0].vault;
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
### Deposit Sol
|
|
75
|
-
|
|
76
|
-
```ts
|
|
77
|
-
const vault = <vault public key>;
|
|
78
|
-
const amount = 2;
|
|
79
|
-
const payload = await service.depositSol({ amount, vault });
|
|
80
|
-
const signature = await payload.execute({ commitment: "finalized" });
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
### Withdraw Sol
|
|
84
|
-
|
|
85
|
-
```ts
|
|
86
|
-
const vault = <vault public key>;
|
|
87
|
-
const amount = 0.01;
|
|
88
|
-
const payload = await service.withdrawSol({ amount, vault });
|
|
89
|
-
const signature = await payload.execute({ commitment: "finalized" });
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
### Deposit Token
|
|
93
|
-
|
|
94
|
-
```ts
|
|
95
|
-
const tokenMint = "De31sBPcDejCVpZZh1fq8SNs7AcuWcBKuU3k2jqnkmKc";
|
|
96
|
-
const vault = <vault public key>;
|
|
97
|
-
const amount = 1000
|
|
98
|
-
const payload = await service.depositToken({ amount, vault, tokenMint });
|
|
99
|
-
const signature = await payload.execute({ commitment: "finalized" });
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
### Withdraw Token
|
|
103
|
-
|
|
104
|
-
```ts
|
|
105
|
-
const vault = <vault public key>;
|
|
106
|
-
const tokenMint = "De31sBPcDejCVpZZh1fq8SNs7AcuWcBKuU3k2jqnkmKc";
|
|
107
|
-
const amount = 1;
|
|
108
|
-
const payload = await service.withdrawToken({ amount, vault, tokenMint });
|
|
109
|
-
const signature = await payload.execute({ commitment: "finalized" });
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
### Execute Proposal Direct
|
|
113
|
-
|
|
114
|
-
```ts
|
|
115
|
-
const proposer = <wallet public key>;
|
|
116
|
-
const vault = <vault public key>;
|
|
117
|
-
|
|
118
|
-
const memoInstruction = new TransactionInstruction({
|
|
119
|
-
keys: [],
|
|
120
|
-
programId: MEMO_PROGRAM_ID,
|
|
121
|
-
data: Buffer.from("This is test memo", "utf8"),
|
|
122
|
-
});
|
|
123
|
-
const actions = [memoInstruction];
|
|
124
|
-
|
|
125
|
-
const payload = await service.executeProposalDirect({
|
|
126
|
-
actions,
|
|
127
|
-
proposer,
|
|
128
|
-
vault,
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
const signature = await payload.execute({ commitment: "finalized" });
|
|
132
|
-
console.log("Execute Proposal Direct Signature:", signature);
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
### Create Proposal
|
|
136
|
-
|
|
137
|
-
```ts
|
|
138
|
-
const proposer = <wallet public key>;
|
|
139
|
-
const receiver = <wallet public Key>;
|
|
140
|
-
const vault = <vault public key>;
|
|
141
|
-
|
|
142
|
-
const [vaultSigner] = deriveVaultSigner(vault, service.programId);
|
|
143
|
-
const name = "Transfer Funds";
|
|
144
|
-
const ix = SystemProgram.transfer({
|
|
145
|
-
fromPubkey: vaultSigner,
|
|
146
|
-
toPubkey: receiver,
|
|
147
|
-
lamports: Number(parseSol(1)),
|
|
148
|
-
});
|
|
149
|
-
const actions = [ix];
|
|
150
|
-
const proposalKeypair = Keypair.generate();
|
|
151
|
-
|
|
152
|
-
const createProposalPayload = await service.createProposal({
|
|
153
|
-
actions,
|
|
154
|
-
name,
|
|
155
|
-
proposer,
|
|
156
|
-
vault,
|
|
157
|
-
proposalKeypair,
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
const signature = await createProposalPayload.execute({ commitment: "finalized" });
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
### Append Actions
|
|
164
|
-
|
|
165
|
-
```ts
|
|
166
|
-
const proposal = <proposal public key>;
|
|
167
|
-
|
|
168
|
-
const ixB = new TransactionInstruction({
|
|
169
|
-
keys: [],
|
|
170
|
-
programId: MEMO_PROGRAM_ID,
|
|
171
|
-
data: Buffer.from("This is test memo", "utf8"),
|
|
172
|
-
});
|
|
173
|
-
const actionsB = [ixB];
|
|
174
|
-
|
|
175
|
-
const appendActionsPayload = await service.appendActions({
|
|
176
|
-
actions: actionsB,
|
|
177
|
-
proposal,
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
const appendActionsSignature = await appendActionsPayload.execute({ commitment: "confirmed" });
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
### Execute Proposal
|
|
184
|
-
|
|
185
|
-
```ts
|
|
186
|
-
const proposal = <proposal public key>;
|
|
187
|
-
const payload = await service.executeProposal({
|
|
188
|
-
proposal,
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
const signature = await payload.execute({ commitment: "confirmed" });
|
|
192
|
-
console.log("Execute Proposal Signature:", signature);
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
### Delete Proposal
|
|
196
|
-
|
|
197
|
-
```ts
|
|
198
|
-
const proposal = <proposal public key>;
|
|
199
|
-
|
|
200
|
-
const deleteProposalPayload = await service.deleteProposal({ proposal });
|
|
201
|
-
const deleteProposalSignature = await deleteProposalPayload.execute({
|
|
202
|
-
commitment: "confirmed",
|
|
203
|
-
});
|
|
204
|
-
console.log("Delete Proposal Signature:", deleteProposalSignature);
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
### Get Proposals Info of a Vault
|
|
208
|
-
|
|
209
|
-
```ts
|
|
210
|
-
const vault = <vault public key>;
|
|
211
|
-
|
|
212
|
-
const proposalsInfo = await service.getProposalsInfoOfVault(vault);
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
### Get All Vaults Info
|
|
216
|
-
|
|
217
|
-
```ts
|
|
218
|
-
const vaultsInfo = await service.getAllVaultsInfo();
|
|
219
|
-
```
|
|
1
|
+
# Zebec Vault Sdk
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
yarn add @zebec-network/zebec-vault-sdk
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @zebec-network/zebec-vault-sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Dependency Map
|
|
14
|
+
|
|
15
|
+

|
|
16
|
+
|
|
17
|
+
## Development
|
|
18
|
+
|
|
19
|
+
To build the package
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
yarn build
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
To run specific test filess
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
yarn test <test file path> -f "<regex for test name>"
|
|
29
|
+
// example:
|
|
30
|
+
// yarn test ./test/<filename>.test.ts
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## publish
|
|
34
|
+
|
|
35
|
+
Build package and bump package version to specific need and publish
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npm publish --access public
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Usage
|
|
42
|
+
|
|
43
|
+
### Create Vault Instance
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
const network = "devnet";
|
|
47
|
+
const wallet = <Anchor wallet>;
|
|
48
|
+
const connection = <Connection Instance>;
|
|
49
|
+
const provider = createAnchorProvider(connection, wallet);
|
|
50
|
+
const service = await ZebecVaultService.create(provider, network);
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Create Vault
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
const vaultKeypair = Keypair.generate();
|
|
57
|
+
console.log("Vault Keypair:", vaultKeypair.publicKey.toBase58());
|
|
58
|
+
const payload = await service.createVault({
|
|
59
|
+
vaultKeypair,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const signature = await payload.execute({ commitment: "finalized" });
|
|
63
|
+
console.log("Signature:", signature);
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Get Vault Info of User
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
const vaultsInfo = await service.getVaultsInfoOfUser(wallet.publicKey);
|
|
70
|
+
console.log("vaults info:", JSON.stringify(vaultsInfo, null, 2));
|
|
71
|
+
const vault = vaultsInfo[0].vault;
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Deposit Sol
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
const vault = <vault public key>;
|
|
78
|
+
const amount = 2;
|
|
79
|
+
const payload = await service.depositSol({ amount, vault });
|
|
80
|
+
const signature = await payload.execute({ commitment: "finalized" });
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Withdraw Sol
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
const vault = <vault public key>;
|
|
87
|
+
const amount = 0.01;
|
|
88
|
+
const payload = await service.withdrawSol({ amount, vault });
|
|
89
|
+
const signature = await payload.execute({ commitment: "finalized" });
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Deposit Token
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
const tokenMint = "De31sBPcDejCVpZZh1fq8SNs7AcuWcBKuU3k2jqnkmKc";
|
|
96
|
+
const vault = <vault public key>;
|
|
97
|
+
const amount = 1000
|
|
98
|
+
const payload = await service.depositToken({ amount, vault, tokenMint });
|
|
99
|
+
const signature = await payload.execute({ commitment: "finalized" });
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Withdraw Token
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
const vault = <vault public key>;
|
|
106
|
+
const tokenMint = "De31sBPcDejCVpZZh1fq8SNs7AcuWcBKuU3k2jqnkmKc";
|
|
107
|
+
const amount = 1;
|
|
108
|
+
const payload = await service.withdrawToken({ amount, vault, tokenMint });
|
|
109
|
+
const signature = await payload.execute({ commitment: "finalized" });
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Execute Proposal Direct
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
const proposer = <wallet public key>;
|
|
116
|
+
const vault = <vault public key>;
|
|
117
|
+
|
|
118
|
+
const memoInstruction = new TransactionInstruction({
|
|
119
|
+
keys: [],
|
|
120
|
+
programId: MEMO_PROGRAM_ID,
|
|
121
|
+
data: Buffer.from("This is test memo", "utf8"),
|
|
122
|
+
});
|
|
123
|
+
const actions = [memoInstruction];
|
|
124
|
+
|
|
125
|
+
const payload = await service.executeProposalDirect({
|
|
126
|
+
actions,
|
|
127
|
+
proposer,
|
|
128
|
+
vault,
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
const signature = await payload.execute({ commitment: "finalized" });
|
|
132
|
+
console.log("Execute Proposal Direct Signature:", signature);
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Create Proposal
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
const proposer = <wallet public key>;
|
|
139
|
+
const receiver = <wallet public Key>;
|
|
140
|
+
const vault = <vault public key>;
|
|
141
|
+
|
|
142
|
+
const [vaultSigner] = deriveVaultSigner(vault, service.programId);
|
|
143
|
+
const name = "Transfer Funds";
|
|
144
|
+
const ix = SystemProgram.transfer({
|
|
145
|
+
fromPubkey: vaultSigner,
|
|
146
|
+
toPubkey: receiver,
|
|
147
|
+
lamports: Number(parseSol(1)),
|
|
148
|
+
});
|
|
149
|
+
const actions = [ix];
|
|
150
|
+
const proposalKeypair = Keypair.generate();
|
|
151
|
+
|
|
152
|
+
const createProposalPayload = await service.createProposal({
|
|
153
|
+
actions,
|
|
154
|
+
name,
|
|
155
|
+
proposer,
|
|
156
|
+
vault,
|
|
157
|
+
proposalKeypair,
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
const signature = await createProposalPayload.execute({ commitment: "finalized" });
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Append Actions
|
|
164
|
+
|
|
165
|
+
```ts
|
|
166
|
+
const proposal = <proposal public key>;
|
|
167
|
+
|
|
168
|
+
const ixB = new TransactionInstruction({
|
|
169
|
+
keys: [],
|
|
170
|
+
programId: MEMO_PROGRAM_ID,
|
|
171
|
+
data: Buffer.from("This is test memo", "utf8"),
|
|
172
|
+
});
|
|
173
|
+
const actionsB = [ixB];
|
|
174
|
+
|
|
175
|
+
const appendActionsPayload = await service.appendActions({
|
|
176
|
+
actions: actionsB,
|
|
177
|
+
proposal,
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
const appendActionsSignature = await appendActionsPayload.execute({ commitment: "confirmed" });
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Execute Proposal
|
|
184
|
+
|
|
185
|
+
```ts
|
|
186
|
+
const proposal = <proposal public key>;
|
|
187
|
+
const payload = await service.executeProposal({
|
|
188
|
+
proposal,
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
const signature = await payload.execute({ commitment: "confirmed" });
|
|
192
|
+
console.log("Execute Proposal Signature:", signature);
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Delete Proposal
|
|
196
|
+
|
|
197
|
+
```ts
|
|
198
|
+
const proposal = <proposal public key>;
|
|
199
|
+
|
|
200
|
+
const deleteProposalPayload = await service.deleteProposal({ proposal });
|
|
201
|
+
const deleteProposalSignature = await deleteProposalPayload.execute({
|
|
202
|
+
commitment: "confirmed",
|
|
203
|
+
});
|
|
204
|
+
console.log("Delete Proposal Signature:", deleteProposalSignature);
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### Get Proposals Info of a Vault
|
|
208
|
+
|
|
209
|
+
```ts
|
|
210
|
+
const vault = <vault public key>;
|
|
211
|
+
|
|
212
|
+
const proposalsInfo = await service.getProposalsInfoOfVault(vault);
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### Get All Vaults Info
|
|
216
|
+
|
|
217
|
+
```ts
|
|
218
|
+
const vaultsInfo = await service.getAllVaultsInfo();
|
|
219
|
+
```
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { ZebecInstantCard as ZebecCardV2Idl } from "./zebec_instant_card";
|
|
2
|
+
import { ZebecStream as ZebecStreamIdl } from "./zebec_stream";
|
|
3
|
+
import { ZebecVault as ZebecVaultV1Idl } from "./zebec_vault";
|
|
4
|
+
declare const ZEBEC_VAULT_V1_IDL: ZebecVaultV1Idl;
|
|
5
|
+
declare const ZEBEC_CARD_V2_IDL: ZebecCardV2Idl;
|
|
6
|
+
declare const ZEBEC_STREAM_IDL: ZebecStreamIdl;
|
|
7
|
+
export { ZEBEC_CARD_V2_IDL, ZEBEC_STREAM_IDL, ZEBEC_VAULT_V1_IDL, ZebecCardV2Idl, ZebecStreamIdl, ZebecVaultV1Idl };
|
package/dist/artifacts/index.js
CHANGED
|
@@ -3,7 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.ZEBEC_VAULT_V1_IDL = exports.ZEBEC_STREAM_IDL = exports.ZEBEC_CARD_V2_IDL = void 0;
|
|
7
|
+
const zebec_instant_card_json_1 = __importDefault(require("./zebec_instant_card.json"));
|
|
8
|
+
const zebec_stream_json_1 = __importDefault(require("./zebec_stream.json"));
|
|
7
9
|
const zebec_vault_json_1 = __importDefault(require("./zebec_vault.json"));
|
|
8
|
-
const
|
|
9
|
-
exports.
|
|
10
|
+
const ZEBEC_VAULT_V1_IDL = zebec_vault_json_1.default;
|
|
11
|
+
exports.ZEBEC_VAULT_V1_IDL = ZEBEC_VAULT_V1_IDL;
|
|
12
|
+
const ZEBEC_CARD_V2_IDL = zebec_instant_card_json_1.default;
|
|
13
|
+
exports.ZEBEC_CARD_V2_IDL = ZEBEC_CARD_V2_IDL;
|
|
14
|
+
const ZEBEC_STREAM_IDL = zebec_stream_json_1.default;
|
|
15
|
+
exports.ZEBEC_STREAM_IDL = ZEBEC_STREAM_IDL;
|