proof-of-take-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.
- package/FINAL_USAGE.md +342 -0
- package/LIBRARY_GUIDE.md +400 -0
- package/LICENSE +22 -0
- package/README.md +370 -0
- package/dist/client.d.ts +32 -0
- package/dist/client.js +47 -0
- package/dist/constants/season.d.ts +18 -0
- package/dist/constants/season.js +22 -0
- package/dist/getters/getMiztake.d.ts +11 -0
- package/dist/getters/getMiztake.js +34 -0
- package/dist/getters/getMiztakeStatistics.d.ts +10 -0
- package/dist/getters/getMiztakeStatistics.js +20 -0
- package/dist/getters/getTokenVault.d.ts +30 -0
- package/dist/getters/getTokenVault.js +56 -0
- package/dist/getters/getUserStats.d.ts +21 -0
- package/dist/getters/getUserStats.js +43 -0
- package/dist/getters/index.d.ts +7 -0
- package/dist/getters/index.js +23 -0
- package/dist/idl/idl.d.ts +2 -0
- package/dist/idl/idl.js +8 -0
- package/dist/idl/proof_of_take.json +3803 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.js +92 -0
- package/dist/instructions/claimReferralPenaltyForWindow.d.ts +38 -0
- package/dist/instructions/claimReferralPenaltyForWindow.js +72 -0
- package/dist/instructions/claimWindowRewards.d.ts +48 -0
- package/dist/instructions/claimWindowRewards.js +94 -0
- package/dist/instructions/confirmedPostOnX.d.ts +51 -0
- package/dist/instructions/confirmedPostOnX.js +78 -0
- package/dist/instructions/createMiztake.d.ts +90 -0
- package/dist/instructions/createMiztake.js +166 -0
- package/dist/instructions/initializeEscrowVault.d.ts +15 -0
- package/dist/instructions/initializeEscrowVault.js +36 -0
- package/dist/instructions/initializeSeasonSettings.d.ts +20 -0
- package/dist/instructions/initializeSeasonSettings.js +39 -0
- package/dist/instructions/initializeSeasonVault.d.ts +20 -0
- package/dist/instructions/initializeSeasonVault.js +43 -0
- package/dist/instructions/initializeStatistics.d.ts +32 -0
- package/dist/instructions/initializeStatistics.js +73 -0
- package/dist/instructions/joinSeason.d.ts +50 -0
- package/dist/instructions/joinSeason.js +120 -0
- package/dist/instructions/toggleSeasonPause.d.ts +22 -0
- package/dist/instructions/toggleSeasonPause.js +42 -0
- package/dist/instructions/updateSeasonAdmin.d.ts +23 -0
- package/dist/instructions/updateSeasonAdmin.js +43 -0
- package/dist/instructions/viewCurrentSeason.d.ts +12 -0
- package/dist/instructions/viewCurrentSeason.js +30 -0
- package/dist/instructions/viewSeasonMembershipStatus.d.ts +16 -0
- package/dist/instructions/viewSeasonMembershipStatus.js +33 -0
- package/dist/instructions/viewWindowStatus.d.ts +15 -0
- package/dist/instructions/viewWindowStatus.js +28 -0
- package/dist/instructions/withdrawSeasonDeposit.d.ts +38 -0
- package/dist/instructions/withdrawSeasonDeposit.js +66 -0
- package/dist/optimistic/index.d.ts +7 -0
- package/dist/optimistic/index.js +33 -0
- package/dist/types/accountTypes.d.ts +121 -0
- package/dist/types/accountTypes.js +2 -0
- package/dist/types/instructionResults.d.ts +44 -0
- package/dist/types/instructionResults.js +2 -0
- package/dist/types/proof_of_take.d.ts +3809 -0
- package/dist/types/proof_of_take.js +2 -0
- package/dist/types.d.ts +232 -0
- package/dist/types.js +16 -0
- package/dist/utils/accountUpdates.d.ts +245 -0
- package/dist/utils/accountUpdates.js +611 -0
- package/dist/utils/anchorHelpers.d.ts +7 -0
- package/dist/utils/anchorHelpers.js +21 -0
- package/dist/utils/constants.d.ts +21 -0
- package/dist/utils/constants.js +31 -0
- package/dist/utils/conversions.d.ts +25 -0
- package/dist/utils/conversions.js +53 -0
- package/dist/utils/enumHelpers.d.ts +63 -0
- package/dist/utils/enumHelpers.js +110 -0
- package/dist/utils/index.d.ts +0 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/pdaManager.d.ts +106 -0
- package/dist/utils/pdaManager.js +89 -0
- package/dist/utils/pdas.d.ts +68 -0
- package/dist/utils/pdas.js +128 -0
- package/dist/utils/programHelpers.d.ts +9 -0
- package/dist/utils/programHelpers.js +18 -0
- package/dist/utils/signerHelpers.d.ts +17 -0
- package/dist/utils/signerHelpers.js +21 -0
- package/dist/utils/simulationHelpers.d.ts +121 -0
- package/dist/utils/simulationHelpers.js +183 -0
- package/dist/utils/tierPenalty.d.ts +9 -0
- package/dist/utils/tierPenalty.js +24 -0
- package/dist/utils/transactionBuilder.d.ts +77 -0
- package/dist/utils/transactionBuilder.js +147 -0
- package/package.json +50 -0
package/README.md
ADDED
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
# Proof of Miztake SDK
|
|
2
|
+
|
|
3
|
+
TypeScript/JavaScript SDK for interacting with the Proof of Miztake Solana program.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @proof-of-miztake/sdk
|
|
9
|
+
# or
|
|
10
|
+
yarn add @proof-of-miztake/sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { AnchorProvider, Program } from "@coral-xyz/anchor";
|
|
17
|
+
import { Connection, Keypair } from "@solana/web3.js";
|
|
18
|
+
import { BN } from "@coral-xyz/anchor";
|
|
19
|
+
import {
|
|
20
|
+
createMiztake,
|
|
21
|
+
claimReward,
|
|
22
|
+
depositTokens,
|
|
23
|
+
initializeStatistics,
|
|
24
|
+
PROGRAM_ID
|
|
25
|
+
} from "@proof-of-miztake/sdk";
|
|
26
|
+
|
|
27
|
+
// Setup
|
|
28
|
+
const connection = new Connection("https://api.mainnet-beta.solana.com");
|
|
29
|
+
const wallet = // your wallet
|
|
30
|
+
const provider = new AnchorProvider(connection, wallet, {});
|
|
31
|
+
const idl = // load your IDL
|
|
32
|
+
const program = new Program(idl, provider);
|
|
33
|
+
|
|
34
|
+
// Create a miztake
|
|
35
|
+
const tx = await createMiztake(program, {
|
|
36
|
+
telegramId: new BN(12345678),
|
|
37
|
+
telegramUsername: "myusername",
|
|
38
|
+
perceptualHash: "hash1",
|
|
39
|
+
averageHash: "hash2",
|
|
40
|
+
differenceHash: "hash3",
|
|
41
|
+
waveletHash: "hash4",
|
|
42
|
+
shaHash: "sha256_hash_must_be_at_least_32_characters_long",
|
|
43
|
+
computedAt: new Date().toISOString()
|
|
44
|
+
}, wallet.publicKey);
|
|
45
|
+
|
|
46
|
+
console.log("Miztake created:", tx);
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## API Reference
|
|
50
|
+
|
|
51
|
+
### User Operations
|
|
52
|
+
|
|
53
|
+
#### `createMiztake()`
|
|
54
|
+
Create a new miztake with metadata and hashes.
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
await createMiztake(program, {
|
|
58
|
+
telegramId: new BN(12345678),
|
|
59
|
+
telegramUsername: "username",
|
|
60
|
+
perceptualHash: "hash1",
|
|
61
|
+
averageHash: "hash2",
|
|
62
|
+
differenceHash: "hash3",
|
|
63
|
+
waveletHash: "hash4",
|
|
64
|
+
shaHash: "sha256_hash_32_chars_minimum...",
|
|
65
|
+
computedAt: "2025-10-26T12:00:00Z"
|
|
66
|
+
}, userWallet.publicKey);
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
**Parameters**:
|
|
70
|
+
- `telegramId`: User's Telegram ID
|
|
71
|
+
- `telegramUsername`: Max 21 characters
|
|
72
|
+
- `shaHash`: Min 32 characters (used for PDA)
|
|
73
|
+
- Other hashes and metadata
|
|
74
|
+
|
|
75
|
+
**Fee**: Dynamic (default 0.0001 SOL)
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
#### `claimReward()`
|
|
80
|
+
Claim MIZD token rewards (requires user + admin signatures).
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
await claimReward(program, {
|
|
84
|
+
miztakePda: miztakeAddress,
|
|
85
|
+
userTokenAccount: userMizdTokenAccount,
|
|
86
|
+
amount: new BN(100_000_000) // 10 tokens with 7 decimals
|
|
87
|
+
}, userWallet, adminWallet);
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
**Requires**:
|
|
91
|
+
- User signature (miztake owner)
|
|
92
|
+
- Admin signature
|
|
93
|
+
- Amount within max_claimable limit
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
#### `canClaim()`
|
|
98
|
+
Check if a claim is possible before attempting.
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
const result = await canClaim(program, miztakePda, new BN(100_000_000));
|
|
102
|
+
if (result.canClaim) {
|
|
103
|
+
console.log("Can claim! Remaining:", result.remainingClaimable);
|
|
104
|
+
} else {
|
|
105
|
+
console.log("Cannot claim:", result.reason);
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
### Token Operations
|
|
112
|
+
|
|
113
|
+
#### `depositTokens()`
|
|
114
|
+
Deposit MIZD tokens to the vault (anyone can deposit).
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
await depositTokens(program, {
|
|
118
|
+
amount: new BN(1_000_000_000_000), // 100,000 tokens
|
|
119
|
+
depositorTokenAccount: depositorMizdAccount
|
|
120
|
+
}, depositorWallet);
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
#### `getVaultBalance()`
|
|
126
|
+
Get current vault balance.
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
const balance = await getVaultBalance(program);
|
|
130
|
+
console.log("Vault balance:", balance.toString());
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
### Admin Operations
|
|
136
|
+
|
|
137
|
+
#### `initializeStatistics()`
|
|
138
|
+
Initialize the program (admin only, one-time).
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
await initializeStatistics(program, adminWallet);
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
#### `updateConfig()`
|
|
147
|
+
Update program configuration (admin only).
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
// Update fee
|
|
151
|
+
await updateConfig(program, {
|
|
152
|
+
newFee: new BN(150_000) // 0.00015 SOL
|
|
153
|
+
}, adminWallet);
|
|
154
|
+
|
|
155
|
+
// Update max claimable
|
|
156
|
+
await updateConfig(program, {
|
|
157
|
+
newDefaultMaxClaimable: new BN(20_000_000_000) // 2000 tokens
|
|
158
|
+
}, adminWallet);
|
|
159
|
+
|
|
160
|
+
// Update multiple fields
|
|
161
|
+
await updateConfig(program, {
|
|
162
|
+
newFee: new BN(200_000),
|
|
163
|
+
newFeeRecipient: new PublicKey("..."),
|
|
164
|
+
newDefaultMaxClaimable: new BN(50_000_000_000)
|
|
165
|
+
}, adminWallet);
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
#### `togglePause()`
|
|
171
|
+
Emergency pause/unpause (admin only).
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
await togglePause(program, adminWallet);
|
|
175
|
+
|
|
176
|
+
// Check status
|
|
177
|
+
const isPaused = await isProgramPaused(program);
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
#### `withdrawTokens()`
|
|
183
|
+
Withdraw from vault (admin only).
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
await withdrawTokens(program, {
|
|
187
|
+
amount: new BN(500_000_000_000),
|
|
188
|
+
adminTokenAccount: adminMizdAccount
|
|
189
|
+
}, adminWallet);
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
### Utility Functions
|
|
195
|
+
|
|
196
|
+
#### PDA Derivation
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
import {
|
|
200
|
+
getMiztakeStatisticsPda,
|
|
201
|
+
getTokenVaultPda,
|
|
202
|
+
getUserStatsPda,
|
|
203
|
+
getMiztakePda
|
|
204
|
+
} from "@proof-of-miztake/sdk";
|
|
205
|
+
|
|
206
|
+
// Get statistics PDA
|
|
207
|
+
const [statisticsPda, bump] = getMiztakeStatisticsPda();
|
|
208
|
+
|
|
209
|
+
// Get user stats PDA
|
|
210
|
+
const [userStatsPda] = getUserStatsPda(new BN(telegramId));
|
|
211
|
+
|
|
212
|
+
// Get miztake PDA
|
|
213
|
+
const [miztakePda] = getMiztakePda(shaHash);
|
|
214
|
+
|
|
215
|
+
// Get vault PDA
|
|
216
|
+
const [vaultPda] = getTokenVaultPda();
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
#### Query Functions
|
|
222
|
+
|
|
223
|
+
```typescript
|
|
224
|
+
// Check if initialized
|
|
225
|
+
const initialized = await isInitialized(program);
|
|
226
|
+
|
|
227
|
+
// Get configuration
|
|
228
|
+
const config = await getConfig(program);
|
|
229
|
+
console.log("Current fee:", config.fee.toString());
|
|
230
|
+
console.log("Fee recipient:", config.feeRecipient.toBase58());
|
|
231
|
+
console.log("Default max claimable:", config.defaultMaxClaimable.toString());
|
|
232
|
+
console.log("Is paused:", config.isPaused);
|
|
233
|
+
|
|
234
|
+
// Check pause status
|
|
235
|
+
const paused = await isProgramPaused(program);
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
---
|
|
239
|
+
|
|
240
|
+
## Constants
|
|
241
|
+
|
|
242
|
+
```typescript
|
|
243
|
+
import {
|
|
244
|
+
PROGRAM_ID,
|
|
245
|
+
ADMIN_PUBLIC_KEY,
|
|
246
|
+
MIZD_TOKEN_MINT,
|
|
247
|
+
DEFAULT_FEE_RECIPIENT,
|
|
248
|
+
DEFAULT_MIZTAKE_FEE,
|
|
249
|
+
DEFAULT_MAX_CLAIMABLE,
|
|
250
|
+
MIN_FEE,
|
|
251
|
+
MAX_FEE,
|
|
252
|
+
MAX_USERNAME_LENGTH,
|
|
253
|
+
MIN_HASH_LENGTH
|
|
254
|
+
} from "@proof-of-miztake/sdk";
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
## Types
|
|
260
|
+
|
|
261
|
+
All TypeScript types are exported:
|
|
262
|
+
|
|
263
|
+
```typescript
|
|
264
|
+
import {
|
|
265
|
+
CreateMiztakeParams,
|
|
266
|
+
ClaimRewardParams,
|
|
267
|
+
DepositTokensParams,
|
|
268
|
+
WithdrawTokensParams,
|
|
269
|
+
UpdateConfigParams,
|
|
270
|
+
MiztakeStatistics,
|
|
271
|
+
UserStats,
|
|
272
|
+
Miztake
|
|
273
|
+
} from "@proof-of-miztake/sdk";
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
---
|
|
277
|
+
|
|
278
|
+
## Error Handling
|
|
279
|
+
|
|
280
|
+
```typescript
|
|
281
|
+
try {
|
|
282
|
+
await createMiztake(program, params, wallet.publicKey);
|
|
283
|
+
} catch (error) {
|
|
284
|
+
if (error.message.includes("UsernameTooLong")) {
|
|
285
|
+
console.error("Username exceeds 21 characters");
|
|
286
|
+
} else if (error.message.includes("ProgramPaused")) {
|
|
287
|
+
console.error("Program is currently paused");
|
|
288
|
+
} else if (error.message.includes("InvalidHashLength")) {
|
|
289
|
+
console.error("SHA hash must be at least 32 characters");
|
|
290
|
+
}
|
|
291
|
+
// Handle other errors...
|
|
292
|
+
}
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
---
|
|
296
|
+
|
|
297
|
+
## Examples
|
|
298
|
+
|
|
299
|
+
### Complete Flow Example
|
|
300
|
+
|
|
301
|
+
```typescript
|
|
302
|
+
import { Program, BN } from "@coral-xyz/anchor";
|
|
303
|
+
import {
|
|
304
|
+
createMiztake,
|
|
305
|
+
depositTokens,
|
|
306
|
+
claimReward,
|
|
307
|
+
getMiztakePda,
|
|
308
|
+
PROGRAM_ID
|
|
309
|
+
} from "@proof-of-miztake/sdk";
|
|
310
|
+
|
|
311
|
+
// 1. Deposit tokens to vault (admin)
|
|
312
|
+
await depositTokens(program, {
|
|
313
|
+
amount: new BN(10_000_000_000_000), // 1M tokens
|
|
314
|
+
depositorTokenAccount: adminMizdAccount
|
|
315
|
+
}, adminWallet);
|
|
316
|
+
|
|
317
|
+
// 2. User creates miztake
|
|
318
|
+
const miztakeParams = {
|
|
319
|
+
telegramId: new BN(12345678),
|
|
320
|
+
telegramUsername: "cryptouser",
|
|
321
|
+
perceptualHash: "abc123...",
|
|
322
|
+
averageHash: "def456...",
|
|
323
|
+
differenceHash: "ghi789...",
|
|
324
|
+
waveletHash: "jkl012...",
|
|
325
|
+
shaHash: "sha256_hash_exactly_32_chars_min",
|
|
326
|
+
computedAt: new Date().toISOString()
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
await createMiztake(program, miztakeParams, userWallet.publicKey);
|
|
330
|
+
|
|
331
|
+
// 3. Admin + User claim reward
|
|
332
|
+
const [miztakePda] = getMiztakePda(miztakeParams.shaHash);
|
|
333
|
+
await claimReward(program, {
|
|
334
|
+
miztakePda,
|
|
335
|
+
userTokenAccount: userMizdAccount,
|
|
336
|
+
amount: new BN(100_000_000) // 10 tokens
|
|
337
|
+
}, userWallet, adminWallet);
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
---
|
|
341
|
+
|
|
342
|
+
## Building from Source
|
|
343
|
+
|
|
344
|
+
```bash
|
|
345
|
+
# Clone and install
|
|
346
|
+
git clone ...
|
|
347
|
+
cd proof_of_miztake_library
|
|
348
|
+
npm install
|
|
349
|
+
|
|
350
|
+
# Build
|
|
351
|
+
npm run build
|
|
352
|
+
|
|
353
|
+
# The dist/ folder contains the compiled JavaScript
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
---
|
|
357
|
+
|
|
358
|
+
## License
|
|
359
|
+
|
|
360
|
+
MIT
|
|
361
|
+
|
|
362
|
+
---
|
|
363
|
+
|
|
364
|
+
## Support
|
|
365
|
+
|
|
366
|
+
For issues and questions:
|
|
367
|
+
- GitHub: [Your repo]
|
|
368
|
+
- Documentation: See project README
|
|
369
|
+
- Security: See SECURITY_AUDIT.md
|
|
370
|
+
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Program, AnchorProvider } from "@coral-xyz/anchor";
|
|
2
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
|
3
|
+
import { ProofOfTake } from "./types/proof_of_take";
|
|
4
|
+
/**
|
|
5
|
+
* Create a Proof of Take program instance
|
|
6
|
+
*
|
|
7
|
+
* @param provider - Anchor provider with connection and wallet
|
|
8
|
+
* @returns Program instance
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { createProgram } from "@proof-of-take/sdk";
|
|
13
|
+
*
|
|
14
|
+
* const program = createProgram(provider);
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function createProgram(provider: AnchorProvider): Program<ProofOfTake>;
|
|
18
|
+
/**
|
|
19
|
+
* Create a Proof of Take program instance with custom program ID
|
|
20
|
+
*
|
|
21
|
+
* @param provider - Anchor provider
|
|
22
|
+
* @param programId - Custom program ID
|
|
23
|
+
* @returns Program instance
|
|
24
|
+
*/
|
|
25
|
+
export declare function createProgramWithId(provider: AnchorProvider, programId: PublicKey): Program<ProofOfTake>;
|
|
26
|
+
/**
|
|
27
|
+
* Get the program instance with just a connection
|
|
28
|
+
*
|
|
29
|
+
* @param connection - Solana connection
|
|
30
|
+
* @returns Program instance (read-only, no wallet)
|
|
31
|
+
*/
|
|
32
|
+
export declare function getProgramReadOnly(connection: Connection): Program<ProofOfTake>;
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createProgram = createProgram;
|
|
4
|
+
exports.createProgramWithId = createProgramWithId;
|
|
5
|
+
exports.getProgramReadOnly = getProgramReadOnly;
|
|
6
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
7
|
+
const idl_1 = require("./idl/idl");
|
|
8
|
+
const anchorHelpers_1 = require("./utils/anchorHelpers");
|
|
9
|
+
/**
|
|
10
|
+
* Create a Proof of Take program instance
|
|
11
|
+
*
|
|
12
|
+
* @param provider - Anchor provider with connection and wallet
|
|
13
|
+
* @returns Program instance
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import { createProgram } from "@proof-of-take/sdk";
|
|
18
|
+
*
|
|
19
|
+
* const program = createProgram(provider);
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
function createProgram(provider) {
|
|
23
|
+
return new anchor_1.Program(idl_1.IDL, provider);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Create a Proof of Take program instance with custom program ID
|
|
27
|
+
*
|
|
28
|
+
* @param provider - Anchor provider
|
|
29
|
+
* @param programId - Custom program ID
|
|
30
|
+
* @returns Program instance
|
|
31
|
+
*/
|
|
32
|
+
function createProgramWithId(provider, programId) {
|
|
33
|
+
// Anchor v0.32 Program ctor does not accept a programId param; it uses `idl.address`.
|
|
34
|
+
// So we clone the IDL and override its address to point at the provided programId.
|
|
35
|
+
const idlWithAddress = (0, anchorHelpers_1.withIdlAddress)(idl_1.IDL, programId);
|
|
36
|
+
return new anchor_1.Program(idlWithAddress, provider);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Get the program instance with just a connection
|
|
40
|
+
*
|
|
41
|
+
* @param connection - Solana connection
|
|
42
|
+
* @returns Program instance (read-only, no wallet)
|
|
43
|
+
*/
|
|
44
|
+
function getProgramReadOnly(connection) {
|
|
45
|
+
const provider = (0, anchorHelpers_1.createReadOnlyProvider)(connection, "confirmed");
|
|
46
|
+
return new anchor_1.Program(idl_1.IDL, provider);
|
|
47
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Season system constants
|
|
3
|
+
* These values match the constants defined in the Rust program
|
|
4
|
+
*/
|
|
5
|
+
export declare const SEASON_CONSTANTS: {
|
|
6
|
+
/** Cost to join a season (100 MIZD with decimals) */
|
|
7
|
+
readonly MEMBERSHIP_COST: any;
|
|
8
|
+
/** Penalty per missed window (1.375 MIZD with decimals) */
|
|
9
|
+
readonly PENALTY_PER_WINDOW: any;
|
|
10
|
+
/** Duration of entire season in seconds (7 days) */
|
|
11
|
+
readonly SEASON_DURATION: 604800;
|
|
12
|
+
/** Duration of each window in seconds (8 hours) */
|
|
13
|
+
readonly WINDOW_DURATION: 28800;
|
|
14
|
+
/** Total number of windows per season */
|
|
15
|
+
readonly TOTAL_WINDOWS_PER_SEASON: 21;
|
|
16
|
+
/** Maximum members allowed per season (DOS protection) */
|
|
17
|
+
readonly MAX_MEMBERS_PER_SEASON: any;
|
|
18
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SEASON_CONSTANTS = void 0;
|
|
4
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
5
|
+
/**
|
|
6
|
+
* Season system constants
|
|
7
|
+
* These values match the constants defined in the Rust program
|
|
8
|
+
*/
|
|
9
|
+
exports.SEASON_CONSTANTS = {
|
|
10
|
+
/** Cost to join a season (100 MIZD with decimals) */
|
|
11
|
+
MEMBERSHIP_COST: new anchor_1.BN(100000000000),
|
|
12
|
+
/** Penalty per missed window (1.375 MIZD with decimals) */
|
|
13
|
+
PENALTY_PER_WINDOW: new anchor_1.BN(1375000000),
|
|
14
|
+
/** Duration of entire season in seconds (7 days) */
|
|
15
|
+
SEASON_DURATION: 604800,
|
|
16
|
+
/** Duration of each window in seconds (8 hours) */
|
|
17
|
+
WINDOW_DURATION: 28800,
|
|
18
|
+
/** Total number of windows per season */
|
|
19
|
+
TOTAL_WINDOWS_PER_SEASON: 21,
|
|
20
|
+
/** Maximum members allowed per season (DOS protection) */
|
|
21
|
+
MAX_MEMBERS_PER_SEASON: new anchor_1.BN(10000),
|
|
22
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
|
2
|
+
import { Miztake } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* Get a miztake account by SHA hash
|
|
5
|
+
* @param connection - Solana connection
|
|
6
|
+
* @param shaHash - SHA hash of the miztake
|
|
7
|
+
* @returns Miztake account data
|
|
8
|
+
*/
|
|
9
|
+
export declare function getMiztake(connection: Connection, shaHash: string): Promise<Miztake & {
|
|
10
|
+
publicKey: PublicKey;
|
|
11
|
+
}>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMiztake = getMiztake;
|
|
4
|
+
const pdas_1 = require("../utils/pdas");
|
|
5
|
+
const programHelpers_1 = require("../utils/programHelpers");
|
|
6
|
+
/**
|
|
7
|
+
* Get a miztake account by SHA hash
|
|
8
|
+
* @param connection - Solana connection
|
|
9
|
+
* @param shaHash - SHA hash of the miztake
|
|
10
|
+
* @returns Miztake account data
|
|
11
|
+
*/
|
|
12
|
+
async function getMiztake(connection, shaHash) {
|
|
13
|
+
const program = (0, programHelpers_1.getProgram)(connection);
|
|
14
|
+
const [miztakePda] = (0, pdas_1.getMiztakePda)(shaHash);
|
|
15
|
+
const miztake = await program.account.miztake.fetch(miztakePda);
|
|
16
|
+
return {
|
|
17
|
+
publicKey: miztakePda,
|
|
18
|
+
id: miztake.id,
|
|
19
|
+
telegramId: miztake.telegramId,
|
|
20
|
+
telegramUsername: miztake.telegramUsername,
|
|
21
|
+
perceptualHash: miztake.perceptualHash,
|
|
22
|
+
averageHash: miztake.averageHash,
|
|
23
|
+
differenceHash: miztake.differenceHash,
|
|
24
|
+
waveletHash: miztake.waveletHash,
|
|
25
|
+
shaHash: miztake.shaHash,
|
|
26
|
+
computedAt: miztake.computedAt,
|
|
27
|
+
creator: miztake.creator,
|
|
28
|
+
userStats: miztake.userStats,
|
|
29
|
+
userKey: miztake.userKey,
|
|
30
|
+
onchainCreatedAt: miztake.onchainCreatedAt,
|
|
31
|
+
usedInSeason: miztake.usedInSeason,
|
|
32
|
+
usedInWindow: miztake.usedInWindow,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
|
2
|
+
import { MiztakeStatistics } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* Get miztake statistics account
|
|
5
|
+
* @param connection - Solana connection
|
|
6
|
+
* @returns MiztakeStatistics account data
|
|
7
|
+
*/
|
|
8
|
+
export declare function getMiztakeStatistics(connection: Connection): Promise<MiztakeStatistics & {
|
|
9
|
+
publicKey: PublicKey;
|
|
10
|
+
}>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMiztakeStatistics = getMiztakeStatistics;
|
|
4
|
+
const pdas_1 = require("../utils/pdas");
|
|
5
|
+
const programHelpers_1 = require("../utils/programHelpers");
|
|
6
|
+
/**
|
|
7
|
+
* Get miztake statistics account
|
|
8
|
+
* @param connection - Solana connection
|
|
9
|
+
* @returns MiztakeStatistics account data
|
|
10
|
+
*/
|
|
11
|
+
async function getMiztakeStatistics(connection) {
|
|
12
|
+
const program = (0, programHelpers_1.getProgram)(connection);
|
|
13
|
+
const [statisticsPda] = (0, pdas_1.getMiztakeStatisticsPda)();
|
|
14
|
+
const statistics = await program.account.miztakeStatistics.fetch(statisticsPda);
|
|
15
|
+
return {
|
|
16
|
+
publicKey: statisticsPda,
|
|
17
|
+
totalMiztakes: statistics.totalMiztakes,
|
|
18
|
+
bump: statistics.bump,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Connection } from "@solana/web3.js";
|
|
2
|
+
import { BN } from "@coral-xyz/anchor";
|
|
3
|
+
/**
|
|
4
|
+
* Get the token vault account information
|
|
5
|
+
*
|
|
6
|
+
* @param connection - Solana connection
|
|
7
|
+
* @returns Token vault account data
|
|
8
|
+
*/
|
|
9
|
+
export declare function getTokenVault(connection: Connection): Promise<{
|
|
10
|
+
address: import("@solana/web3.js").PublicKey;
|
|
11
|
+
data: {
|
|
12
|
+
mint: import("@solana/web3.js").PublicKey;
|
|
13
|
+
owner: import("@solana/web3.js").PublicKey;
|
|
14
|
+
amount: any;
|
|
15
|
+
delegate: import("@solana/web3.js").PublicKey;
|
|
16
|
+
delegatedAmount: bigint;
|
|
17
|
+
isInitialized: boolean;
|
|
18
|
+
isFrozen: boolean;
|
|
19
|
+
isNative: boolean;
|
|
20
|
+
closeAuthority: import("@solana/web3.js").PublicKey;
|
|
21
|
+
};
|
|
22
|
+
}>;
|
|
23
|
+
/**
|
|
24
|
+
* Check if token vault is initialized
|
|
25
|
+
*/
|
|
26
|
+
export declare function isVaultInitialized(connection: Connection): Promise<boolean>;
|
|
27
|
+
/**
|
|
28
|
+
* Get vault balance (amount of MIZD tokens in vault)
|
|
29
|
+
*/
|
|
30
|
+
export declare function getVaultTokenBalance(connection: Connection): Promise<BN>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTokenVault = getTokenVault;
|
|
4
|
+
exports.isVaultInitialized = isVaultInitialized;
|
|
5
|
+
exports.getVaultTokenBalance = getVaultTokenBalance;
|
|
6
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
7
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
8
|
+
const pdas_1 = require("../utils/pdas");
|
|
9
|
+
/**
|
|
10
|
+
* Get the token vault account information
|
|
11
|
+
*
|
|
12
|
+
* @param connection - Solana connection
|
|
13
|
+
* @returns Token vault account data
|
|
14
|
+
*/
|
|
15
|
+
async function getTokenVault(connection) {
|
|
16
|
+
const [vaultPda] = (0, pdas_1.getTokenVaultPda)();
|
|
17
|
+
try {
|
|
18
|
+
const vaultAccount = await (0, spl_token_1.getAccount)(connection, vaultPda);
|
|
19
|
+
return {
|
|
20
|
+
address: vaultPda,
|
|
21
|
+
data: {
|
|
22
|
+
mint: vaultAccount.mint,
|
|
23
|
+
owner: vaultAccount.owner,
|
|
24
|
+
amount: new anchor_1.BN(vaultAccount.amount.toString()),
|
|
25
|
+
delegate: vaultAccount.delegate,
|
|
26
|
+
delegatedAmount: vaultAccount.delegatedAmount,
|
|
27
|
+
isInitialized: vaultAccount.isInitialized,
|
|
28
|
+
isFrozen: vaultAccount.isFrozen,
|
|
29
|
+
isNative: vaultAccount.isNative,
|
|
30
|
+
closeAuthority: vaultAccount.closeAuthority,
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
throw new Error(`Token vault not found or not initialized: ${error}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Check if token vault is initialized
|
|
40
|
+
*/
|
|
41
|
+
async function isVaultInitialized(connection) {
|
|
42
|
+
try {
|
|
43
|
+
await getTokenVault(connection);
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Get vault balance (amount of MIZD tokens in vault)
|
|
52
|
+
*/
|
|
53
|
+
async function getVaultTokenBalance(connection) {
|
|
54
|
+
const vault = await getTokenVault(connection);
|
|
55
|
+
return vault.data.amount;
|
|
56
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
|
2
|
+
import { BN } from "@coral-xyz/anchor";
|
|
3
|
+
import { UserStats } from "../types";
|
|
4
|
+
/**
|
|
5
|
+
* Get user stats account by telegram ID
|
|
6
|
+
* @param connection - Solana connection
|
|
7
|
+
* @param telegramId - Telegram ID of the user
|
|
8
|
+
* @returns UserStats account data
|
|
9
|
+
*/
|
|
10
|
+
export declare function getUserStats(connection: Connection, telegramId: BN): Promise<UserStats & {
|
|
11
|
+
publicKey: PublicKey;
|
|
12
|
+
}>;
|
|
13
|
+
/**
|
|
14
|
+
* Get user stats by public key (if you already have the PDA)
|
|
15
|
+
* @param connection - Solana connection
|
|
16
|
+
* @param userStatsPda - User stats PDA
|
|
17
|
+
* @returns UserStats account data
|
|
18
|
+
*/
|
|
19
|
+
export declare function getUserStatsByPda(connection: Connection, userStatsPda: PublicKey): Promise<UserStats & {
|
|
20
|
+
publicKey: PublicKey;
|
|
21
|
+
}>;
|