@grapenpm/gpass-sdk 0.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 ADDED
@@ -0,0 +1,251 @@
1
+ # @grape-protocol/gpass-sdk
2
+
3
+ TypeScript SDK for the **Grape Gating Protocol** — composable access control for Solana DAOs.
4
+
5
+ **Program ID:** `GPASSzQQF1H8cdj5pUwFkeYEE4VdMQtCrYtUaMXvPz48`
6
+
7
+ ---
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ npm install @grape-protocol/gpass-sdk
13
+ # peer deps
14
+ npm install @coral-xyz/anchor @solana/web3.js
15
+ ```
16
+
17
+ ---
18
+
19
+ ## Quick Start
20
+
21
+ ```typescript
22
+ import { GpassClient, GateCriteriaFactory, GateTypeFactory, VerificationPlatform } from "@grape-protocol/gpass-sdk";
23
+ import { AnchorProvider } from "@coral-xyz/anchor";
24
+ import { Keypair } from "@solana/web3.js";
25
+
26
+ const provider = AnchorProvider.env();
27
+ const client = new GpassClient(provider);
28
+
29
+ // 1. Create a gate — require 500 Vine reputation + Discord verified
30
+ const gateId = Keypair.generate().publicKey;
31
+
32
+ const { tx, gate } = await client.initializeGate({
33
+ gateId,
34
+ criteria: GateCriteriaFactory.combined({
35
+ vineConfig: myVineConfigPda,
36
+ minPoints: 500,
37
+ season: 1,
38
+ grapeSpace: myGrapeSpacePda,
39
+ platforms: [VerificationPlatform.Discord],
40
+ requireWalletLink: true,
41
+ }),
42
+ gateType: GateTypeFactory.reusable(),
43
+ });
44
+
45
+ // 2. Check if a user passes
46
+ await client.checkGate({
47
+ gateId,
48
+ user: userWallet,
49
+ reputationAccount: vineRepPda,
50
+ identityAccount: grapeIdentityPda,
51
+ linkAccount: grapeLinkPda,
52
+ storeRecord: true,
53
+ });
54
+
55
+ // 3. Simulate without submitting (great for UI)
56
+ const passes = await client.simulateCheckGate({
57
+ gateId,
58
+ user: userWallet,
59
+ reputationAccount: vineRepPda,
60
+ identityAccount: grapeIdentityPda,
61
+ });
62
+ console.log("User passes gate:", passes);
63
+ ```
64
+
65
+ ---
66
+
67
+ ## Gate Criteria
68
+
69
+ ### `MinReputation`
70
+ Require a minimum Vine reputation score for a season.
71
+ ```typescript
72
+ GateCriteriaFactory.minReputation({
73
+ vineConfig: vineConfigPda,
74
+ minPoints: 1000,
75
+ season: 2,
76
+ })
77
+ ```
78
+
79
+ ### `VerifiedIdentity`
80
+ Require a verified Grape identity on one or more platforms.
81
+ ```typescript
82
+ GateCriteriaFactory.verifiedIdentity({
83
+ grapeSpace: grapeSpacePda,
84
+ platforms: [VerificationPlatform.Discord, VerificationPlatform.Twitter],
85
+ })
86
+ ```
87
+
88
+ ### `VerifiedWithWallet`
89
+ Require a verified identity AND a wallet link.
90
+ ```typescript
91
+ GateCriteriaFactory.verifiedWithWallet({
92
+ grapeSpace: grapeSpacePda,
93
+ platforms: [VerificationPlatform.Discord],
94
+ })
95
+ ```
96
+
97
+ ### `Combined` ⭐ Most powerful
98
+ Require reputation + verification together.
99
+ ```typescript
100
+ GateCriteriaFactory.combined({
101
+ vineConfig: vineConfigPda,
102
+ minPoints: 500,
103
+ season: 1,
104
+ grapeSpace: grapeSpacePda,
105
+ platforms: [VerificationPlatform.Discord],
106
+ requireWalletLink: true,
107
+ })
108
+ ```
109
+
110
+ ### `TimeLockedReputation`
111
+ Require the user to have held reputation for a minimum duration.
112
+ ```typescript
113
+ GateCriteriaFactory.timeLockedReputation({
114
+ vineConfig: vineConfigPda,
115
+ minPoints: 100,
116
+ season: 1,
117
+ minHoldDurationSeconds: 30 * 24 * 60 * 60, // 30 days
118
+ })
119
+ ```
120
+
121
+ ### `MultiDao`
122
+ Require passing gates from multiple DAOs (AND / OR logic).
123
+ ```typescript
124
+ GateCriteriaFactory.multiDao({
125
+ requiredGates: [daoAGate, daoBGate, daoCGate],
126
+ requireAll: true, // AND — user must pass all gates
127
+ })
128
+ ```
129
+
130
+ ### `TokenHolding`
131
+ Require holding a minimum amount of a specific token.
132
+ ```typescript
133
+ GateCriteriaFactory.tokenHolding({
134
+ mint: tokenMint,
135
+ minAmount: 100_000_000, // 100 tokens (with 6 decimals)
136
+ checkAta: true,
137
+ })
138
+ ```
139
+
140
+ ### `NftCollection`
141
+ Require owning NFTs from a collection.
142
+ ```typescript
143
+ GateCriteriaFactory.nftCollection({
144
+ collectionMint: collectionMint,
145
+ minCount: 1,
146
+ })
147
+ ```
148
+
149
+ ---
150
+
151
+ ## Gate Types
152
+
153
+ | Type | Description |
154
+ |------|-------------|
155
+ | `GateTypeFactory.singleUse()` | One-time access check |
156
+ | `GateTypeFactory.reusable()` | Unlimited checks |
157
+ | `GateTypeFactory.timeLimited(86400)` | Valid 24h after check |
158
+ | `GateTypeFactory.subscription(604800)` | Must re-check weekly |
159
+
160
+ ---
161
+
162
+ ## PDA Helpers
163
+
164
+ ```typescript
165
+ import {
166
+ findGatePda,
167
+ findCheckRecordPda,
168
+ findVineReputationPda,
169
+ findGrapeIdentityPda,
170
+ findGrapeLinkPda,
171
+ } from "@grape-protocol/gpass-sdk";
172
+
173
+ // Gate PDA
174
+ const [gatePda] = await findGatePda(gateId);
175
+
176
+ // Check record PDA
177
+ const [checkRecordPda] = await findCheckRecordPda(gatePda, userWallet);
178
+
179
+ // Vine reputation PDA
180
+ const [repPda] = await findVineReputationPda(vineConfigPda, userWallet, season);
181
+
182
+ // Grape identity PDA
183
+ const [identityPda] = await findGrapeIdentityPda(
184
+ grapeSpacePda,
185
+ VerificationPlatform.Discord, // platformSeed
186
+ idHash // Uint8Array[32]
187
+ );
188
+ ```
189
+
190
+ ---
191
+
192
+ ## Composing with Other Instructions
193
+
194
+ Gate checks can be bundled with your own instructions in a single atomic transaction:
195
+
196
+ ```typescript
197
+ // Build a gated mint transaction
198
+ const mintIx = await myNftProgram.methods.mint().accounts({...}).instruction();
199
+
200
+ const tx = await client.buildGatedTransaction(
201
+ {
202
+ gateId,
203
+ user: userWallet,
204
+ reputationAccount: repPda,
205
+ identityAccount: identityPda,
206
+ },
207
+ mintIx // only executes if gate check passes
208
+ );
209
+
210
+ await provider.sendAndConfirm(tx);
211
+ ```
212
+
213
+ ---
214
+
215
+ ## Fetching Accounts
216
+
217
+ ```typescript
218
+ // Fetch a gate
219
+ const gate = await client.fetchGate(gateId);
220
+ console.log("Pass rate:", gate.successfulChecks / gate.totalChecks);
221
+
222
+ // Fetch a user's check record
223
+ const record = await client.fetchCheckRecord(gateId, userWallet);
224
+ console.log("Last checked:", new Date(record.checkedAt.toNumber() * 1000));
225
+
226
+ // Fetch all gates owned by an authority
227
+ const myGates = await client.fetchGatesByAuthority(myWallet);
228
+ ```
229
+
230
+ ---
231
+
232
+ ## Error Codes
233
+
234
+ | Code | Name | Description |
235
+ |------|------|-------------|
236
+ | 6000 | Unauthorized | Wrong authority |
237
+ | 6001 | GateInactive | Gate has been disabled |
238
+ | 6002 | GateCheckFailed | User did not pass criteria |
239
+ | 6003 | ReputationAccountRequired | Missing Vine account |
240
+ | 6004 | IdentityAccountRequired | Missing Grape identity |
241
+ | 6005 | LinkAccountRequired | Missing wallet link |
242
+ | 6006 | TokenAccountRequired | Missing token account |
243
+ | 6015 | IdentityNotVerified | Identity exists but unverified |
244
+ | 6016 | IdentityExpired | Verification has expired |
245
+ | 6012 | SeasonMismatch | Wrong reputation season |
246
+
247
+ ---
248
+
249
+ ## License
250
+
251
+ MIT — Grape Protocol