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.
Files changed (90) hide show
  1. package/FINAL_USAGE.md +342 -0
  2. package/LIBRARY_GUIDE.md +400 -0
  3. package/LICENSE +22 -0
  4. package/README.md +370 -0
  5. package/dist/client.d.ts +32 -0
  6. package/dist/client.js +47 -0
  7. package/dist/constants/season.d.ts +18 -0
  8. package/dist/constants/season.js +22 -0
  9. package/dist/getters/getMiztake.d.ts +11 -0
  10. package/dist/getters/getMiztake.js +34 -0
  11. package/dist/getters/getMiztakeStatistics.d.ts +10 -0
  12. package/dist/getters/getMiztakeStatistics.js +20 -0
  13. package/dist/getters/getTokenVault.d.ts +30 -0
  14. package/dist/getters/getTokenVault.js +56 -0
  15. package/dist/getters/getUserStats.d.ts +21 -0
  16. package/dist/getters/getUserStats.js +43 -0
  17. package/dist/getters/index.d.ts +7 -0
  18. package/dist/getters/index.js +23 -0
  19. package/dist/idl/idl.d.ts +2 -0
  20. package/dist/idl/idl.js +8 -0
  21. package/dist/idl/proof_of_take.json +3803 -0
  22. package/dist/index.d.ts +48 -0
  23. package/dist/index.js +92 -0
  24. package/dist/instructions/claimReferralPenaltyForWindow.d.ts +38 -0
  25. package/dist/instructions/claimReferralPenaltyForWindow.js +72 -0
  26. package/dist/instructions/claimWindowRewards.d.ts +48 -0
  27. package/dist/instructions/claimWindowRewards.js +94 -0
  28. package/dist/instructions/confirmedPostOnX.d.ts +51 -0
  29. package/dist/instructions/confirmedPostOnX.js +78 -0
  30. package/dist/instructions/createMiztake.d.ts +90 -0
  31. package/dist/instructions/createMiztake.js +166 -0
  32. package/dist/instructions/initializeEscrowVault.d.ts +15 -0
  33. package/dist/instructions/initializeEscrowVault.js +36 -0
  34. package/dist/instructions/initializeSeasonSettings.d.ts +20 -0
  35. package/dist/instructions/initializeSeasonSettings.js +39 -0
  36. package/dist/instructions/initializeSeasonVault.d.ts +20 -0
  37. package/dist/instructions/initializeSeasonVault.js +43 -0
  38. package/dist/instructions/initializeStatistics.d.ts +32 -0
  39. package/dist/instructions/initializeStatistics.js +73 -0
  40. package/dist/instructions/joinSeason.d.ts +50 -0
  41. package/dist/instructions/joinSeason.js +120 -0
  42. package/dist/instructions/toggleSeasonPause.d.ts +22 -0
  43. package/dist/instructions/toggleSeasonPause.js +42 -0
  44. package/dist/instructions/updateSeasonAdmin.d.ts +23 -0
  45. package/dist/instructions/updateSeasonAdmin.js +43 -0
  46. package/dist/instructions/viewCurrentSeason.d.ts +12 -0
  47. package/dist/instructions/viewCurrentSeason.js +30 -0
  48. package/dist/instructions/viewSeasonMembershipStatus.d.ts +16 -0
  49. package/dist/instructions/viewSeasonMembershipStatus.js +33 -0
  50. package/dist/instructions/viewWindowStatus.d.ts +15 -0
  51. package/dist/instructions/viewWindowStatus.js +28 -0
  52. package/dist/instructions/withdrawSeasonDeposit.d.ts +38 -0
  53. package/dist/instructions/withdrawSeasonDeposit.js +66 -0
  54. package/dist/optimistic/index.d.ts +7 -0
  55. package/dist/optimistic/index.js +33 -0
  56. package/dist/types/accountTypes.d.ts +121 -0
  57. package/dist/types/accountTypes.js +2 -0
  58. package/dist/types/instructionResults.d.ts +44 -0
  59. package/dist/types/instructionResults.js +2 -0
  60. package/dist/types/proof_of_take.d.ts +3809 -0
  61. package/dist/types/proof_of_take.js +2 -0
  62. package/dist/types.d.ts +232 -0
  63. package/dist/types.js +16 -0
  64. package/dist/utils/accountUpdates.d.ts +245 -0
  65. package/dist/utils/accountUpdates.js +611 -0
  66. package/dist/utils/anchorHelpers.d.ts +7 -0
  67. package/dist/utils/anchorHelpers.js +21 -0
  68. package/dist/utils/constants.d.ts +21 -0
  69. package/dist/utils/constants.js +31 -0
  70. package/dist/utils/conversions.d.ts +25 -0
  71. package/dist/utils/conversions.js +53 -0
  72. package/dist/utils/enumHelpers.d.ts +63 -0
  73. package/dist/utils/enumHelpers.js +110 -0
  74. package/dist/utils/index.d.ts +0 -0
  75. package/dist/utils/index.js +2 -0
  76. package/dist/utils/pdaManager.d.ts +106 -0
  77. package/dist/utils/pdaManager.js +89 -0
  78. package/dist/utils/pdas.d.ts +68 -0
  79. package/dist/utils/pdas.js +128 -0
  80. package/dist/utils/programHelpers.d.ts +9 -0
  81. package/dist/utils/programHelpers.js +18 -0
  82. package/dist/utils/signerHelpers.d.ts +17 -0
  83. package/dist/utils/signerHelpers.js +21 -0
  84. package/dist/utils/simulationHelpers.d.ts +121 -0
  85. package/dist/utils/simulationHelpers.js +183 -0
  86. package/dist/utils/tierPenalty.d.ts +9 -0
  87. package/dist/utils/tierPenalty.js +24 -0
  88. package/dist/utils/transactionBuilder.d.ts +77 -0
  89. package/dist/utils/transactionBuilder.js +147 -0
  90. package/package.json +50 -0
@@ -0,0 +1,400 @@
1
+ # Proof of Miztake SDK - Developer Guide
2
+
3
+ ## 🎯 Overview
4
+
5
+ This TypeScript SDK provides a clean, typed interface for interacting with the Proof of Miztake Solana program.
6
+
7
+ **Package**: `@proof-of-miztake/sdk`
8
+ **Version**: 1.0.0
9
+ **Program ID**: `takeA82AwosboZgG7HQx8D3dGLbbbPUyQCva9HpLJBr`
10
+
11
+ ---
12
+
13
+ ## 📦 Installation
14
+
15
+ ### Option 1: From npm (After Publishing)
16
+ ```bash
17
+ npm install @proof-of-miztake/sdk
18
+ ```
19
+
20
+ ### Option 2: Local Development
21
+ ```bash
22
+ cd proof_of_miztake_library
23
+ npm install
24
+ npm run build
25
+ ```
26
+
27
+ Then in your project:
28
+ ```bash
29
+ npm install /path/to/proof_of_miztake_library
30
+ ```
31
+
32
+ ---
33
+
34
+ ## 🏗️ Library Structure
35
+
36
+ ```
37
+ proof_of_miztake_library/
38
+ ├── src/
39
+ │ ├── index.ts # Main exports
40
+ │ ├── types.ts # TypeScript type definitions
41
+ │ ├── instructions/
42
+ │ │ ├── createMiztake.ts # Create miztake function
43
+ │ │ ├── claimReward.ts # Claim rewards function
44
+ │ │ ├── depositTokens.ts # Deposit tokens function
45
+ │ │ ├── withdrawTokens.ts # Withdraw tokens function
46
+ │ │ ├── initializeStatistics.ts # Initialize program function
47
+ │ │ ├── updateConfig.ts # Update config function
48
+ │ │ └── togglePause.ts # Pause/unpause function
49
+ │ └── utils/
50
+ │ ├── constants.ts # Program constants
51
+ │ └── pdas.ts # PDA derivation helpers
52
+ ├── package.json
53
+ ├── tsconfig.json
54
+ ├── README.md # User documentation
55
+ ├── LIBRARY_GUIDE.md # This file
56
+ └── example.ts # Complete usage example
57
+ ```
58
+
59
+ ---
60
+
61
+ ## 🎯 Core Functions
62
+
63
+ ### All 7 Program Instructions Wrapped:
64
+
65
+ 1. **`initializeStatistics()`** - Initialize program (admin only)
66
+ 2. **`createMiztake()`** - Create new miztake (users)
67
+ 3. **`claimReward()`** - Claim rewards (dual-sig: user + admin)
68
+ 4. **`depositTokens()`** - Deposit to vault (anyone)
69
+ 5. **`withdrawTokens()`** - Withdraw from vault (admin only)
70
+ 6. **`updateConfig()`** - Update settings (admin only)
71
+ 7. **`togglePause()`** - Emergency pause (admin only)
72
+
73
+ ### Bonus Helper Functions:
74
+
75
+ 8. **`canClaim()`** - Check if claim is possible
76
+ 9. **`getConfig()`** - Get current configuration
77
+ 10. **`isProgramPaused()`** - Check pause status
78
+ 11. **`getVaultBalance()`** - Get vault balance
79
+ 12. **`isInitialized()`** - Check if initialized
80
+ 13. **PDA helpers** - All PDA derivation functions
81
+
82
+ ---
83
+
84
+ ## 💡 Usage Examples
85
+
86
+ ### Setup Your Project
87
+
88
+ ```typescript
89
+ import { Program, AnchorProvider } from "@coral-xyz/anchor";
90
+ import { Connection } from "@solana/web3.js";
91
+ import {
92
+ createMiztake,
93
+ depositTokens,
94
+ PROGRAM_ID
95
+ } from "@proof-of-miztake/sdk";
96
+
97
+ const connection = new Connection("https://api.mainnet-beta.solana.com");
98
+ const provider = new AnchorProvider(connection, wallet, {});
99
+ const idl = await Program.fetchIdl(PROGRAM_ID, provider);
100
+ const program = new Program(idl, provider);
101
+ ```
102
+
103
+ ---
104
+
105
+ ### User: Create Miztake
106
+
107
+ ```typescript
108
+ import { BN } from "@coral-xyz/anchor";
109
+ import { createMiztake } from "@proof-of-miztake/sdk";
110
+
111
+ const tx = await createMiztake(program, {
112
+ telegramId: new BN(12345678),
113
+ telegramUsername: "myusername",
114
+ perceptualHash: "hash1234567890ab",
115
+ averageHash: "hash1234567890cd",
116
+ differenceHash: "hash1234567890ef",
117
+ waveletHash: "hash1234567890gh",
118
+ shaHash: "sha256_full_hash_minimum_32_characters_required_here",
119
+ computedAt: "2025-10-26T12:00:00Z"
120
+ }, userWallet.publicKey);
121
+
122
+ console.log("Miztake created! TX:", tx);
123
+ ```
124
+
125
+ ---
126
+
127
+ ### User + Admin: Claim Reward
128
+
129
+ ```typescript
130
+ import { claimReward, canClaim, getMiztakePda } from "@proof-of-miztake/sdk";
131
+
132
+ const [miztakePda] = getMiztakePda(shaHash);
133
+ const amount = new BN(100_000_000); // 10 tokens
134
+
135
+ // Check if can claim first
136
+ const checkResult = await canClaim(program, miztakePda, amount);
137
+
138
+ if (!checkResult.canClaim) {
139
+ console.log("Cannot claim:", checkResult.reason);
140
+ return;
141
+ }
142
+
143
+ console.log("Remaining claimable:", checkResult.remainingClaimable?.toString());
144
+
145
+ // Claim (both user and admin must sign)
146
+ const tx = await claimReward(
147
+ program,
148
+ {
149
+ miztakePda,
150
+ userTokenAccount: userMizdTokenAccount,
151
+ amount
152
+ },
153
+ userWallet,
154
+ adminWallet
155
+ );
156
+
157
+ console.log("Reward claimed! TX:", tx);
158
+ ```
159
+
160
+ ---
161
+
162
+ ### Admin: Manage Vault
163
+
164
+ ```typescript
165
+ import { depositTokens, withdrawTokens, getVaultBalance } from "@proof-of-miztake/sdk";
166
+
167
+ // Deposit tokens
168
+ await depositTokens(program, {
169
+ amount: new BN(1_000_000_000_000), // 100K tokens
170
+ depositorTokenAccount: adminMizdAccount
171
+ }, adminWallet);
172
+
173
+ // Check balance
174
+ const balance = await getVaultBalance(program);
175
+ console.log("Vault balance:", balance.toString());
176
+
177
+ // Withdraw tokens
178
+ await withdrawTokens(program, {
179
+ amount: new BN(500_000_000_000), // 50K tokens
180
+ adminTokenAccount: adminMizdAccount
181
+ }, adminWallet);
182
+ ```
183
+
184
+ ---
185
+
186
+ ### Admin: Update Configuration
187
+
188
+ ```typescript
189
+ import { updateConfig, getConfig } from "@proof-of-miztake/sdk";
190
+
191
+ // Update fee
192
+ await updateConfig(program, {
193
+ newFee: new BN(200_000) // 0.0002 SOL
194
+ }, adminWallet);
195
+
196
+ // Update max claimable default
197
+ await updateConfig(program, {
198
+ newDefaultMaxClaimable: new BN(50_000_000_000) // 5000 tokens
199
+ }, adminWallet);
200
+
201
+ // Update multiple fields
202
+ await updateConfig(program, {
203
+ newFee: new BN(150_000),
204
+ newFeeRecipient: new PublicKey("..."),
205
+ newDefaultMaxClaimable: new BN(30_000_000_000)
206
+ }, adminWallet);
207
+
208
+ // Check current config
209
+ const config = await getConfig(program);
210
+ console.log("Current fee:", config.fee.toString());
211
+ console.log("Fee recipient:", config.feeRecipient.toBase58());
212
+ console.log("Default max claimable:", config.defaultMaxClaimable.toString());
213
+ ```
214
+
215
+ ---
216
+
217
+ ### Admin: Emergency Controls
218
+
219
+ ```typescript
220
+ import { togglePause, isProgramPaused } from "@proof-of-miztake/sdk";
221
+
222
+ // Pause the program
223
+ await togglePause(program, adminWallet);
224
+ console.log("Program paused");
225
+
226
+ // Check status
227
+ const paused = await isProgramPaused(program);
228
+ console.log("Is paused:", paused);
229
+
230
+ // Unpause
231
+ await togglePause(program, adminWallet);
232
+ console.log("Program unpaused");
233
+ ```
234
+
235
+ ---
236
+
237
+ ## 🔧 Building the Library
238
+
239
+ ```bash
240
+ # Install dependencies
241
+ cd proof_of_miztake_library
242
+ npm install
243
+
244
+ # Build
245
+ npm run build
246
+
247
+ # Output will be in dist/ folder
248
+ # dist/index.js - Compiled JavaScript
249
+ # dist/index.d.ts - TypeScript type definitions
250
+ ```
251
+
252
+ ---
253
+
254
+ ## 📝 Publishing (Optional)
255
+
256
+ ### To npm:
257
+
258
+ ```bash
259
+ # Login to npm
260
+ npm login
261
+
262
+ # Update version in package.json
263
+ npm version patch # or minor, or major
264
+
265
+ # Publish
266
+ npm publish --access public
267
+ ```
268
+
269
+ ### To GitHub Packages:
270
+
271
+ Update package.json name:
272
+ ```json
273
+ {
274
+ "name": "@your-org/proof-of-miztake-sdk"
275
+ }
276
+ ```
277
+
278
+ Then publish:
279
+ ```bash
280
+ npm publish
281
+ ```
282
+
283
+ ---
284
+
285
+ ## 🎯 Integration in Your App
286
+
287
+ ### React Example:
288
+
289
+ ```typescript
290
+ import { useWallet } from "@solana/wallet-adapter-react";
291
+ import { createMiztake } from "@proof-of-miztake/sdk";
292
+
293
+ function CreateMiztakeButton() {
294
+ const wallet = useWallet();
295
+
296
+ const handleCreate = async () => {
297
+ if (!wallet.publicKey) return;
298
+
299
+ try {
300
+ const tx = await createMiztake(program, {
301
+ telegramId: new BN(user.telegramId),
302
+ telegramUsername: user.username,
303
+ // ... other params
304
+ }, wallet.publicKey);
305
+
306
+ toast.success(`Miztake created! TX: ${tx}`);
307
+ } catch (error) {
308
+ toast.error(`Failed: ${error.message}`);
309
+ }
310
+ };
311
+
312
+ return <button onClick={handleCreate}>Create Miztake</button>;
313
+ }
314
+ ```
315
+
316
+ ---
317
+
318
+ ## 🔍 Advanced Usage
319
+
320
+ ### Event Listening:
321
+
322
+ ```typescript
323
+ // Subscribe to events (requires program.addEventListener)
324
+ program.addEventListener("MiztakeCreated", (event, slot) => {
325
+ console.log("New miztake:", event.miztakeId.toString());
326
+ console.log("Creator:", event.creator.toBase58());
327
+ console.log("Timestamp:", new Date(event.timestamp.toNumber() * 1000));
328
+ });
329
+
330
+ program.addEventListener("RewardClaimed", (event, slot) => {
331
+ console.log("Reward claimed:", event.amount.toString());
332
+ console.log("Miztake ID:", event.miztakeId.toString());
333
+ console.log("Total user claimed:", event.totalUserClaimed.toString());
334
+ });
335
+ ```
336
+
337
+ ---
338
+
339
+ ### Query All User Miztakes:
340
+
341
+ ```typescript
342
+ import { getUserStatsPda } from "@proof-of-miztake/sdk";
343
+
344
+ const [userStatsPda] = getUserStatsPda(new BN(telegramId));
345
+ const userStats = await program.account.userStats.fetch(userStatsPda);
346
+
347
+ console.log("User has created", userStats.totalNumberOfMiztakes.toString(), "miztakes");
348
+ console.log("User has claimed", userStats.claimedMizd.toString(), "tokens");
349
+
350
+ // You would need to track miztake PDAs separately
351
+ // or query all miztake accounts filtered by user_key
352
+ ```
353
+
354
+ ---
355
+
356
+ ## ✅ What's Included
357
+
358
+ ### ✅ All Instructions
359
+ - Complete wrapper for all 7 program instructions
360
+ - Proper parameter validation
361
+ - Error handling
362
+ - TypeScript types
363
+
364
+ ### ✅ PDA Helpers
365
+ - Automatic PDA derivation
366
+ - Correct seeds for all account types
367
+ - No manual PDA calculation needed
368
+
369
+ ### ✅ Query Functions
370
+ - Check claim eligibility
371
+ - Get configuration
372
+ - Get vault balance
373
+ - Check pause status
374
+ - Check initialization
375
+
376
+ ### ✅ Validation
377
+ - Input validation before sending transactions
378
+ - Clear error messages
379
+ - Type safety
380
+
381
+ ### ✅ Documentation
382
+ - JSDoc comments on all functions
383
+ - Usage examples
384
+ - Complete type definitions
385
+ - Integration guides
386
+
387
+ ---
388
+
389
+ ## 🎉 You're Ready!
390
+
391
+ The SDK provides everything needed to interact with Proof of Miztake:
392
+
393
+ ✅ **Clean API** - Simple function calls
394
+ ✅ **Type Safe** - Full TypeScript support
395
+ ✅ **Validated** - Input checking built-in
396
+ ✅ **Documented** - Examples and guides
397
+ ✅ **Production Ready** - Matches deployed program
398
+
399
+ **Start building your frontend with confidence!** 🚀
400
+
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Proof of Miztake
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+