@viwoapp/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,310 @@
1
+ # @viwoapp/sdk
2
+
3
+ TypeScript SDK for VCoin Protocol Integration on Solana.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @viwoapp/sdk
9
+ # or
10
+ yarn add @viwoapp/sdk
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ ```typescript
16
+ import { ViWoClient, parseVCoin, formatVCoin, LOCK_DURATIONS } from "@viwoapp/sdk";
17
+
18
+ // Initialize client
19
+ const client = new ViWoClient({
20
+ connection: { endpoint: "https://api.devnet.solana.com" },
21
+ wallet: walletAdapter, // Your wallet adapter
22
+ });
23
+
24
+ // Get VCoin balance
25
+ const balance = await client.getVCoinBalance();
26
+ console.log("Balance:", formatVCoin(balance));
27
+
28
+ // Stake VCoin
29
+ const stakeTx = await client.staking.buildStakeTransaction({
30
+ amount: parseVCoin("1000"),
31
+ lockDuration: LOCK_DURATIONS.threeMonths,
32
+ });
33
+ await client.sendTransaction(stakeTx);
34
+ ```
35
+
36
+ ## Modules
37
+
38
+ ### Core (`@viwoapp/sdk`)
39
+
40
+ Connection management, utilities, and PDA derivation.
41
+
42
+ ```typescript
43
+ import { ViWoClient, PDAs, formatVCoin, parseVCoin } from "@viwoapp/sdk";
44
+
45
+ const client = new ViWoClient({ connection, wallet });
46
+
47
+ // Check connection health
48
+ const health = await client.healthCheck();
49
+
50
+ // Get PDAs
51
+ const stakingPool = client.pdas.getStakingPool();
52
+ const userStake = client.pdas.getUserStake(walletPubkey);
53
+ ```
54
+
55
+ ### Staking (`client.staking`)
56
+
57
+ VCoin staking operations for veVCoin.
58
+
59
+ ```typescript
60
+ // Get staking pool info
61
+ const pool = await client.staking.getPool();
62
+
63
+ // Get user stake
64
+ const stake = await client.staking.getUserStake();
65
+ console.log("Staked:", formatVCoin(stake.stakedAmount));
66
+ console.log("Tier:", client.staking.getTierName(stake.tier));
67
+
68
+ // Calculate veVCoin for stake
69
+ const vevcoin = client.staking.calculateVeVCoin(amount, lockDuration);
70
+
71
+ // Build transactions
72
+ const stakeTx = await client.staking.buildStakeTransaction({ amount, lockDuration });
73
+ const unstakeTx = await client.staking.buildUnstakeTransaction();
74
+ ```
75
+
76
+ ### Governance (`client.governance`)
77
+
78
+ Proposal creation and voting.
79
+
80
+ ```typescript
81
+ // Get active proposals
82
+ const proposals = await client.governance.getActiveProposals();
83
+
84
+ // Get proposal details
85
+ const proposal = await client.governance.getProposal(proposalId);
86
+ const progress = await client.governance.getProposalProgress(proposalId);
87
+
88
+ // Check voting power
89
+ const votingPower = await client.governance.getVotingPower();
90
+
91
+ // Build transactions
92
+ const voteTx = await client.governance.buildVoteTransaction(proposalId, true);
93
+ ```
94
+
95
+ ### Rewards (`client.rewards`)
96
+
97
+ SSCRE rewards claiming.
98
+
99
+ ```typescript
100
+ // Get pool stats
101
+ const stats = await client.rewards.getStats();
102
+
103
+ // Get user claim history
104
+ const claims = await client.rewards.getUserClaim();
105
+
106
+ // Get unclaimed epochs
107
+ const unclaimed = await client.rewards.getUnclaimedEpochs();
108
+
109
+ // Build claim transaction
110
+ const claimTx = await client.rewards.buildClaimTransaction({
111
+ epoch,
112
+ amount,
113
+ merkleProof,
114
+ });
115
+ ```
116
+
117
+ ### ViLink (`client.vilink`)
118
+
119
+ Cross-dApp action deep links.
120
+
121
+ ```typescript
122
+ // Create tip action
123
+ const tipTx = await client.vilink.buildCreateTipAction({
124
+ target: recipientPubkey,
125
+ amount: parseVCoin("10"),
126
+ expirySeconds: 86400, // 1 day
127
+ });
128
+
129
+ // Generate shareable URI
130
+ const uri = client.vilink.generateUri(actionId);
131
+ // => viwo://action/abc123...
132
+
133
+ // Generate QR code data
134
+ const qrData = client.vilink.generateQRData(actionId);
135
+
136
+ // Check action validity
137
+ const { valid, reason } = await client.vilink.isActionValid(creator, timestamp);
138
+ ```
139
+
140
+ ### Gasless (`client.gasless`)
141
+
142
+ Session keys and gasless transactions.
143
+
144
+ ```typescript
145
+ import { ACTION_SCOPES, FeeMethod } from "@viwoapp/sdk";
146
+
147
+ // Create session key
148
+ const sessionKeypair = Keypair.generate();
149
+ const scope = ACTION_SCOPES.tip | ACTION_SCOPES.vouch;
150
+
151
+ const sessionTx = await client.gasless.buildCreateSessionTransaction({
152
+ sessionPubkey: sessionKeypair.publicKey,
153
+ scope,
154
+ durationSeconds: 24 * 3600,
155
+ maxActions: 100,
156
+ feeMethod: FeeMethod.VCoinDeduction,
157
+ });
158
+
159
+ // Check session validity
160
+ const { valid } = await client.gasless.isSessionValid(user, sessionPubkey);
161
+
162
+ // Revoke session
163
+ const revokeTx = await client.gasless.buildRevokeSessionTransaction(sessionPubkey);
164
+ ```
165
+
166
+ ### Identity (`client.identity`)
167
+
168
+ User identity management.
169
+
170
+ ```typescript
171
+ // Get identity
172
+ const identity = await client.identity.getIdentity();
173
+ console.log("Level:", client.identity.getVerificationLevelName(identity.verificationLevel));
174
+
175
+ // Get verification requirements
176
+ const reqs = client.identity.getVerificationRequirements(level);
177
+ ```
178
+
179
+ ### 5A Protocol (`client.fivea`)
180
+
181
+ Reputation scoring.
182
+
183
+ ```typescript
184
+ // Get 5A score
185
+ const score = await client.fivea.getScore();
186
+ console.log("Composite:", client.fivea.formatScore(score.composite));
187
+ console.log("Tier:", client.fivea.getScoreTier(score.composite));
188
+
189
+ // Get score breakdown
190
+ const breakdown = client.fivea.getScoreBreakdown(score);
191
+
192
+ // Get reward multiplier
193
+ const multiplier = client.fivea.getRewardMultiplier(score.composite);
194
+
195
+ // Check vouch capability
196
+ const { canVouch, reason } = await client.fivea.canVouchFor(target);
197
+ ```
198
+
199
+ ### Content (`client.content`)
200
+
201
+ Content registry operations.
202
+
203
+ ```typescript
204
+ // Get user energy
205
+ const energy = await client.content.getEnergy();
206
+ const currentEnergy = client.content.calculateRegenEnergy(energy);
207
+
208
+ // Check create capability
209
+ const { canCreate } = await client.content.canCreateContent();
210
+
211
+ // Build transactions
212
+ const createTx = await client.content.buildCreateContentTransaction(contentHash);
213
+ const editTx = await client.content.buildEditContentTransaction(contentId, newHash);
214
+ ```
215
+
216
+ ## Constants
217
+
218
+ ```typescript
219
+ import {
220
+ PROGRAM_IDS,
221
+ SEEDS,
222
+ VCOIN_DECIMALS,
223
+ STAKING_TIERS,
224
+ LOCK_DURATIONS,
225
+ SSCRE_CONSTANTS,
226
+ VILINK_CONSTANTS,
227
+ GASLESS_CONSTANTS,
228
+ ACTION_SCOPES,
229
+ FIVE_A_CONSTANTS,
230
+ GOVERNANCE_CONSTANTS,
231
+ CONTENT_CONSTANTS,
232
+ } from "@viwoapp/sdk";
233
+ ```
234
+
235
+ ## Types
236
+
237
+ ```typescript
238
+ import type {
239
+ // Staking
240
+ StakingPool,
241
+ UserStake,
242
+ StakingTier,
243
+ StakeParams,
244
+
245
+ // Governance
246
+ Proposal,
247
+ VoteRecord,
248
+ ProposalStatus,
249
+
250
+ // Rewards
251
+ RewardsPoolConfig,
252
+ EpochDistribution,
253
+ UserClaim,
254
+ ClaimRewardsParams,
255
+
256
+ // ViLink
257
+ ViLinkConfig,
258
+ ViLinkAction,
259
+ ActionType,
260
+ CreateActionParams,
261
+
262
+ // Gasless
263
+ GaslessConfig,
264
+ SessionKey,
265
+ FeeMethod,
266
+ CreateSessionParams,
267
+
268
+ // Identity
269
+ Identity,
270
+ VerificationLevel,
271
+
272
+ // 5A
273
+ FiveAScore,
274
+ VouchRecord,
275
+
276
+ // Content
277
+ ContentRecord,
278
+ UserEnergy,
279
+ ContentState,
280
+ } from "@viwoapp/sdk";
281
+ ```
282
+
283
+ ## Utilities
284
+
285
+ ```typescript
286
+ import {
287
+ formatVCoin,
288
+ parseVCoin,
289
+ getCurrentTimestamp,
290
+ timestampToDate,
291
+ dateToTimestamp,
292
+ TransactionBuilder,
293
+ } from "@viwoapp/sdk";
294
+
295
+ // Format VCoin amount
296
+ formatVCoin(new BN(1000000000)); // "1.000000000"
297
+
298
+ // Parse VCoin string to BN
299
+ parseVCoin("100.5"); // BN
300
+
301
+ // Transaction builder
302
+ const builder = new TransactionBuilder();
303
+ builder.add(instruction1).add(instruction2);
304
+ const tx = builder.build();
305
+ ```
306
+
307
+ ## License
308
+
309
+ MIT
310
+