@pbpcanada/projectdam-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/README.md ADDED
@@ -0,0 +1,304 @@
1
+ # @pbpcanada/projectdam-sdk
2
+
3
+ TypeScript SDK for **ProjectDAM** - Agent-operated NFT AMM on Solana
4
+
5
+ ProjectDAM is a decentralized NFT Automated Market Maker (AMM) built on Solana that enables instant NFT liquidity through algorithmic pricing curves.
6
+
7
+ ## Features
8
+
9
+ - 🔍 **Account Decoders** - Parse all ProjectDAM account types from raw buffer data
10
+ - 🔑 **PDA Helpers** - Generate Program Derived Addresses for all seeds
11
+ - 📝 **Instruction Builders** - Create transactions for all core operations
12
+ - 🛡️ **Type Safety** - Full TypeScript interfaces and enums
13
+ - 📋 **IDL Export** - Complete program interface definition
14
+ - 🚀 **Client Class** - High-level API for common operations
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ npm install @pbpcanada/projectdam-sdk @solana/web3.js @coral-xyz/anchor
20
+ ```
21
+
22
+ ## Quick Start
23
+
24
+ ```typescript
25
+ import { Connection, PublicKey } from '@solana/web3.js';
26
+ import {
27
+ ProjectDAMClient,
28
+ PROGRAM_ID,
29
+ findPoolPDA,
30
+ decodePool,
31
+ CurveType,
32
+ PoolType
33
+ } from '@pbpcanada/projectdam-sdk';
34
+
35
+ // Initialize connection and client
36
+ const connection = new Connection('https://api.mainnet-beta.solana.com');
37
+ const client = new ProjectDAMClient(connection);
38
+
39
+ // Get protocol configuration
40
+ const config = await client.getConfig();
41
+ console.log('Protocol fee:', config?.protocolFeeBps, 'bps');
42
+
43
+ // Find a pool PDA
44
+ const owner = new PublicKey('...');
45
+ const uuid = Buffer.from([1, 2, 3, 4, 5, 6]);
46
+ const [poolPDA, bump] = findPoolPDA(owner, uuid);
47
+
48
+ // Decode pool data
49
+ const poolAccount = await connection.getAccountInfo(poolPDA);
50
+ if (poolAccount) {
51
+ const pool = decodePool(poolAccount.data);
52
+ console.log('Pool type:', PoolType[pool.poolType]);
53
+ console.log('Curve type:', CurveType[pool.curveType.type]);
54
+ console.log('Spot price:', pool.spotPrice, 'lamports');
55
+ }
56
+
57
+ // Get all pools by collection
58
+ const collectionMint = new PublicKey('...');
59
+ const pools = await client.getPoolsByCollection(collectionMint);
60
+ console.log(`Found ${pools.length} pools for collection`);
61
+ ```
62
+
63
+ ## Core Concepts
64
+
65
+ ### Pool Types
66
+
67
+ ```typescript
68
+ enum PoolType {
69
+ Nft = 0, // Buy NFTs from pool
70
+ Token = 1, // Sell NFTs to pool
71
+ Trade = 2 // Both buy and sell
72
+ }
73
+ ```
74
+
75
+ ### Curve Types
76
+
77
+ ```typescript
78
+ enum CurveType {
79
+ Fixed = 0, // Constant price
80
+ Linear = 1, // Price increases linearly
81
+ Exponential = 2 // Price increases exponentially
82
+ }
83
+ ```
84
+
85
+ ### Account Types
86
+
87
+ - **Config** - Protocol configuration and global stats
88
+ - **Pool** - Individual liquidity pool for a collection
89
+ - **PoolNft** - NFT deposit tracking
90
+ - **Season** - Monthly trading competitions
91
+ - **TraderVolume** - Individual trader statistics
92
+ - **CollectionStats** - Collection-wide analytics
93
+
94
+ ## API Reference
95
+
96
+ ### Client Methods
97
+
98
+ ```typescript
99
+ const client = new ProjectDAMClient(connection, programId?);
100
+
101
+ // Account fetching
102
+ await client.getConfig()
103
+ await client.getPool(poolAddress)
104
+ await client.getPoolNft(poolNftAddress)
105
+
106
+ // Bulk queries
107
+ await client.getPoolsByOwner(owner)
108
+ await client.getPoolsByCollection(collection)
109
+ await client.getPoolNfts(pool)
110
+ ```
111
+
112
+ ### PDA Helpers
113
+
114
+ ```typescript
115
+ import {
116
+ findConfigPDA,
117
+ findPoolPDA,
118
+ findSolVaultPDA,
119
+ findPoolNftPDA,
120
+ findSeasonPDA,
121
+ generatePoolUuid
122
+ } from '@pbpcanada/projectdam-sdk';
123
+
124
+ // Generate PDAs
125
+ const [config] = findConfigPDA();
126
+ const [pool] = findPoolPDA(owner, uuid);
127
+ const [vault] = findSolVaultPDA(pool);
128
+ const [poolNft] = findPoolNftPDA(pool, nftMint);
129
+
130
+ // Generate random UUID for new pools
131
+ const uuid = generatePoolUuid();
132
+ ```
133
+
134
+ ### Instruction Builders
135
+
136
+ ```typescript
137
+ import {
138
+ createPoolInstruction,
139
+ buyInstruction,
140
+ sellInstruction,
141
+ depositSolInstruction,
142
+ depositNftInstruction
143
+ } from '@pbpcanada/projectdam-sdk';
144
+
145
+ // Create a new pool
146
+ const createPoolIx = createPoolInstruction(
147
+ {
148
+ uuid: generatePoolUuid(),
149
+ curveType: { type: CurveType.Linear, delta: 100000000n }, // 0.1 SOL
150
+ spotPrice: 1000000000n, // 1 SOL
151
+ spreadBps: 50, // 0.5%
152
+ poolType: PoolType.Trade
153
+ },
154
+ owner.publicKey,
155
+ collectionMint
156
+ );
157
+
158
+ // Buy an NFT
159
+ const buyIx = buyInstruction(
160
+ pool,
161
+ nftMint,
162
+ buyer.publicKey,
163
+ poolOwner,
164
+ feeBuffer,
165
+ creatorWallet,
166
+ { maxPrice: 2000000000n } // 2 SOL max
167
+ );
168
+ ```
169
+
170
+ ### Account Decoders
171
+
172
+ ```typescript
173
+ import {
174
+ decodeConfig,
175
+ decodePool,
176
+ decodePoolNft,
177
+ parseAccount,
178
+ fromBase64
179
+ } from '@pbpcanada/projectdam-sdk';
180
+
181
+ // Decode specific account types
182
+ const config = decodeConfig(accountData);
183
+ const pool = decodePool(accountData);
184
+ const poolNft = decodePoolNft(accountData);
185
+
186
+ // Auto-detect account type
187
+ const parsed = parseAccount(accountData);
188
+ if (parsed.type === 'pool') {
189
+ console.log('Pool owner:', parsed.data.owner.toBase58());
190
+ }
191
+
192
+ // Decode from base64 string
193
+ const buffer = fromBase64(base64String);
194
+ const pool = decodePool(buffer);
195
+ ```
196
+
197
+ ## Program IDs
198
+
199
+ ```typescript
200
+ import { PROGRAM_IDS, PROGRAM_ID } from '@pbpcanada/projectdam-sdk';
201
+
202
+ // Mainnet: DAmKEbaRoFMKRqdYb6zSrfYvH7Zyx1VLBoixKenii25e
203
+ console.log(PROGRAM_IDS.MAINNET);
204
+
205
+ // Devnet: GyX8E52YsmuaojfbhGo6Y5ey8Qg31nbkvYUydEtfY4Ci
206
+ console.log(PROGRAM_IDS.DEVNET);
207
+
208
+ // Default (mainnet)
209
+ console.log(PROGRAM_ID);
210
+ ```
211
+
212
+ ## Advanced Usage
213
+
214
+ ### Working with Curves
215
+
216
+ ```typescript
217
+ import { CurveType } from '@pbpcanada/projectdam-sdk';
218
+
219
+ // Fixed price pool
220
+ const fixedCurve = { type: CurveType.Fixed };
221
+
222
+ // Linear bonding curve (price increases by delta each trade)
223
+ const linearCurve = {
224
+ type: CurveType.Linear,
225
+ delta: 50000000n // 0.05 SOL increase per trade
226
+ };
227
+
228
+ // Exponential bonding curve (price multiplies by factor each trade)
229
+ const expCurve = {
230
+ type: CurveType.Exponential,
231
+ delta: 110 // 1.1% increase per trade (110 bps)
232
+ };
233
+ ```
234
+
235
+ ### Event Parsing
236
+
237
+ ```typescript
238
+ import { DAM_PROTOCOL_IDL } from '@pbpcanada/projectdam-sdk';
239
+
240
+ // Use IDL with Anchor for event parsing
241
+ import { Program } from '@coral-xyz/anchor';
242
+
243
+ const program = new Program(DAM_PROTOCOL_IDL, PROGRAM_ID, provider);
244
+
245
+ // Listen to trade events
246
+ program.addEventListener('TradeEvent', (event) => {
247
+ console.log('Trade:', {
248
+ pool: event.pool.toBase58(),
249
+ nftMint: event.nftMint.toBase58(),
250
+ price: event.price.toString(),
251
+ isBuy: event.isBuy
252
+ });
253
+ });
254
+ ```
255
+
256
+ ### Error Handling
257
+
258
+ ```typescript
259
+ import { DAM_PROTOCOL_IDL } from '@pbpcanada/projectdam-sdk';
260
+
261
+ // Error codes from IDL
262
+ const ERRORS = {
263
+ InvalidPrice: 6000,
264
+ SpreadTooHigh: 6001,
265
+ PoolInactive: 6002,
266
+ ProtocolPaused: 6003,
267
+ Unauthorized: 6004,
268
+ SlippageExceeded: 6005,
269
+ PoolCantBuy: 6006,
270
+ InsufficientLiquidity: 6007,
271
+ InvalidAmount: 6008,
272
+ InvalidCollection: 6009,
273
+ MathOverflow: 6010
274
+ };
275
+ ```
276
+
277
+ ## Examples
278
+
279
+ Check out the [examples directory](./examples) for complete working examples:
280
+
281
+ - **Pool Creation** - Create new liquidity pools
282
+ - **Trading** - Buy and sell NFTs through pools
283
+ - **Liquidity Management** - Deposit/withdraw SOL and NFTs
284
+ - **Analytics** - Query pool statistics and performance
285
+ - **Season Tracking** - Volume competitions and leaderboards
286
+
287
+ ## Contributing
288
+
289
+ 1. Fork the repository
290
+ 2. Create a feature branch
291
+ 3. Make your changes
292
+ 4. Add tests
293
+ 5. Submit a pull request
294
+
295
+ ## License
296
+
297
+ MIT License - see [LICENSE](./LICENSE) for details.
298
+
299
+ ## Links
300
+
301
+ - **Program:** [DAmKEbaRoFMKRqdYb6zSrfYvH7Zyx1VLBoixKenii25e](https://solscan.io/account/DAmKEbaRoFMKRqdYb6zSrfYvH7Zyx1VLBoixKenii25e)
302
+ - **Documentation:** [ProjectDAM Docs](https://docs.projectdam.io)
303
+ - **Discord:** [PBP Canada](https://discord.gg/pbpcanada)
304
+ - **Twitter:** [@ProjectDAM_io](https://twitter.com/ProjectDAM_io)
@@ -0,0 +1,71 @@
1
+ import type { Config, Pool, PoolNft, Season, TraderVolume, CollectionStats } from './types.js';
2
+ /**
3
+ * Decode Config account data from raw buffer
4
+ * @param data - Raw account data buffer
5
+ * @returns Parsed Config object
6
+ */
7
+ export declare function decodeConfig(data: Buffer): Config;
8
+ /**
9
+ * Decode Pool account data from raw buffer
10
+ * @param data - Raw account data buffer
11
+ * @returns Parsed Pool object
12
+ */
13
+ export declare function decodePool(data: Buffer): Pool;
14
+ /**
15
+ * Decode PoolNft account data from raw buffer
16
+ * @param data - Raw account data buffer
17
+ * @returns Parsed PoolNft object
18
+ */
19
+ export declare function decodePoolNft(data: Buffer): PoolNft;
20
+ /**
21
+ * Decode Season account data from raw buffer
22
+ * @param data - Raw account data buffer
23
+ * @returns Parsed Season object
24
+ */
25
+ export declare function decodeSeason(data: Buffer): Season;
26
+ /**
27
+ * Decode TraderVolume account data from raw buffer
28
+ * @param data - Raw account data buffer
29
+ * @returns Parsed TraderVolume object
30
+ */
31
+ export declare function decodeTraderVolume(data: Buffer): TraderVolume;
32
+ /**
33
+ * Decode CollectionStats account data from raw buffer
34
+ * @param data - Raw account data buffer
35
+ * @returns Parsed CollectionStats object
36
+ */
37
+ export declare function decodeCollectionStats(data: Buffer): CollectionStats;
38
+ /**
39
+ * Parse account data based on discriminator
40
+ * @param data - Raw account data buffer
41
+ * @returns Parsed account object with type information
42
+ */
43
+ export declare function parseAccount(data: Buffer): {
44
+ type: 'config';
45
+ data: Config;
46
+ } | {
47
+ type: 'pool';
48
+ data: Pool;
49
+ } | {
50
+ type: 'poolNft';
51
+ data: PoolNft;
52
+ } | {
53
+ type: 'season';
54
+ data: Season;
55
+ } | {
56
+ type: 'traderVolume';
57
+ data: TraderVolume;
58
+ } | {
59
+ type: 'collectionStats';
60
+ data: CollectionStats;
61
+ } | {
62
+ type: 'unknown';
63
+ discriminator: Buffer;
64
+ };
65
+ /**
66
+ * Utility function to convert base64 string to Buffer
67
+ * @param base64 - Base64 encoded string
68
+ * @returns Buffer
69
+ */
70
+ export declare function fromBase64(base64: string): Buffer;
71
+ //# sourceMappingURL=accounts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accounts.d.ts","sourceRoot":"","sources":["../src/accounts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,MAAM,EACN,IAAI,EACJ,OAAO,EACP,MAAM,EACN,YAAY,EACZ,eAAe,EAEhB,MAAM,YAAY,CAAC;AAGpB;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAgDjD;AA+BD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAkE7C;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAgCnD;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAqCjD;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAgC7D;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAoCnE;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GACrC;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAChC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,IAAI,CAAA;CAAE,GAC5B;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAClC;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAChC;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,IAAI,EAAE,YAAY,CAAA;CAAE,GAC5C;IAAE,IAAI,EAAE,iBAAiB,CAAC;IAAC,IAAI,EAAE,eAAe,CAAA;CAAE,GAClD;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE,CAyB7C;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEjD"}
@@ -0,0 +1,286 @@
1
+ import { PublicKey } from '@solana/web3.js';
2
+ import { CurveType } from './types.js';
3
+ /**
4
+ * Decode Config account data from raw buffer
5
+ * @param data - Raw account data buffer
6
+ * @returns Parsed Config object
7
+ */
8
+ export function decodeConfig(data) {
9
+ if (data.length < 155) {
10
+ throw new Error('Invalid Config account data: insufficient length');
11
+ }
12
+ let offset = 8; // Skip discriminator
13
+ const bump = data.readUInt8(offset);
14
+ offset += 1;
15
+ const authority = new PublicKey(data.subarray(offset, offset + 32));
16
+ offset += 32;
17
+ const protocolFeeBps = data.readUInt16LE(offset);
18
+ offset += 2;
19
+ const buybackBps = data.readUInt16LE(offset);
20
+ offset += 2;
21
+ const feeTreasury = new PublicKey(data.subarray(offset, offset + 32));
22
+ offset += 32;
23
+ const pbpBuybackWallet = new PublicKey(data.subarray(offset, offset + 32));
24
+ offset += 32;
25
+ const totalPools = data.readBigUInt64LE(offset);
26
+ offset += 8;
27
+ const totalTrades = data.readBigUInt64LE(offset);
28
+ offset += 8;
29
+ const feeBuffer = data.readBigUInt64LE(offset);
30
+ offset += 8;
31
+ const paused = data.readUInt8(offset) === 1;
32
+ return {
33
+ bump,
34
+ authority,
35
+ protocolFeeBps,
36
+ buybackBps,
37
+ feeTreasury,
38
+ pbpBuybackWallet,
39
+ totalPools,
40
+ totalTrades,
41
+ feeBuffer,
42
+ paused,
43
+ };
44
+ }
45
+ /**
46
+ * Decode curve type from buffer
47
+ * @param data - Buffer containing curve data
48
+ * @param offset - Starting offset
49
+ * @returns [CurveConfig, newOffset] - Parsed curve config and updated offset
50
+ */
51
+ function decodeCurveType(data, offset) {
52
+ const curveTypeVariant = data.readUInt8(offset);
53
+ offset += 1;
54
+ switch (curveTypeVariant) {
55
+ case 0: // Fixed
56
+ return [{ type: CurveType.Fixed }, offset];
57
+ case 1: // Linear
58
+ const linearDelta = data.readBigUInt64LE(offset);
59
+ offset += 8;
60
+ return [{ type: CurveType.Linear, delta: linearDelta }, offset];
61
+ case 2: // Exponential
62
+ const expDelta = data.readUInt16LE(offset);
63
+ offset += 2;
64
+ return [{ type: CurveType.Exponential, delta: expDelta }, offset];
65
+ default:
66
+ throw new Error(`Unknown curve type: ${curveTypeVariant}`);
67
+ }
68
+ }
69
+ /**
70
+ * Decode Pool account data from raw buffer
71
+ * @param data - Raw account data buffer
72
+ * @returns Parsed Pool object
73
+ */
74
+ export function decodePool(data) {
75
+ if (data.length < 144) {
76
+ throw new Error('Invalid Pool account data: insufficient length');
77
+ }
78
+ let offset = 8; // Skip discriminator
79
+ const bump = data.readUInt8(offset);
80
+ offset += 1;
81
+ const owner = new PublicKey(data.subarray(offset, offset + 32));
82
+ offset += 32;
83
+ const uuid = data.subarray(offset, offset + 6);
84
+ offset += 6;
85
+ const collection = new PublicKey(data.subarray(offset, offset + 32));
86
+ offset += 32;
87
+ // Decode curve type (variable length)
88
+ const [curveType, newOffset] = decodeCurveType(data, offset);
89
+ offset = newOffset;
90
+ const spotPrice = data.readBigUInt64LE(offset);
91
+ offset += 8;
92
+ const spreadBps = data.readUInt16LE(offset);
93
+ offset += 2;
94
+ const nftCount = data.readUInt16LE(offset);
95
+ offset += 2;
96
+ const solBalance = data.readBigUInt64LE(offset);
97
+ offset += 8;
98
+ const buyCount = data.readBigUInt64LE(offset);
99
+ offset += 8;
100
+ const sellCount = data.readBigUInt64LE(offset);
101
+ offset += 8;
102
+ const poolTypeVariant = data.readUInt8(offset);
103
+ offset += 1;
104
+ const poolType = poolTypeVariant;
105
+ const isActive = data.readUInt8(offset) === 1;
106
+ offset += 1;
107
+ const createdAt = data.readBigInt64LE(offset);
108
+ return {
109
+ bump,
110
+ owner,
111
+ uuid,
112
+ collection,
113
+ curveType,
114
+ spotPrice,
115
+ spreadBps,
116
+ nftCount,
117
+ solBalance,
118
+ buyCount,
119
+ sellCount,
120
+ poolType,
121
+ isActive,
122
+ createdAt,
123
+ };
124
+ }
125
+ /**
126
+ * Decode PoolNft account data from raw buffer
127
+ * @param data - Raw account data buffer
128
+ * @returns Parsed PoolNft object
129
+ */
130
+ export function decodePoolNft(data) {
131
+ if (data.length < 113) {
132
+ throw new Error('Invalid PoolNft account data: insufficient length');
133
+ }
134
+ let offset = 8; // Skip discriminator
135
+ const bump = data.readUInt8(offset);
136
+ offset += 1;
137
+ const pool = new PublicKey(data.subarray(offset, offset + 32));
138
+ offset += 32;
139
+ const nftMint = new PublicKey(data.subarray(offset, offset + 32));
140
+ offset += 32;
141
+ const depositor = new PublicKey(data.subarray(offset, offset + 32));
142
+ offset += 32;
143
+ const depositedAt = data.readBigInt64LE(offset);
144
+ offset += 8;
145
+ const priceAtDeposit = data.readBigUInt64LE(offset);
146
+ return {
147
+ bump,
148
+ pool,
149
+ nftMint,
150
+ depositor,
151
+ depositedAt,
152
+ priceAtDeposit,
153
+ };
154
+ }
155
+ /**
156
+ * Decode Season account data from raw buffer
157
+ * @param data - Raw account data buffer
158
+ * @returns Parsed Season object
159
+ */
160
+ export function decodeSeason(data) {
161
+ if (data.length < 75) {
162
+ throw new Error('Invalid Season account data: insufficient length');
163
+ }
164
+ let offset = 8; // Skip discriminator
165
+ const month = data.readUInt8(offset);
166
+ offset += 1;
167
+ const year = data.readUInt16LE(offset);
168
+ offset += 2;
169
+ const totalVolume = data.readBigUInt64LE(offset);
170
+ offset += 8;
171
+ const totalTrades = data.readBigUInt64LE(offset);
172
+ offset += 8;
173
+ // Read top traders (assuming max 10 traders, 32 bytes each)
174
+ const topTraders = [];
175
+ const numTraders = Math.min(10, (data.length - offset - 1) / 32);
176
+ for (let i = 0; i < numTraders; i++) {
177
+ topTraders.push(new PublicKey(data.subarray(offset, offset + 32)));
178
+ offset += 32;
179
+ }
180
+ const isActive = data.readUInt8(offset) === 1;
181
+ return {
182
+ month,
183
+ year,
184
+ totalVolume,
185
+ totalTrades,
186
+ topTraders,
187
+ isActive,
188
+ };
189
+ }
190
+ /**
191
+ * Decode TraderVolume account data from raw buffer
192
+ * @param data - Raw account data buffer
193
+ * @returns Parsed TraderVolume object
194
+ */
195
+ export function decodeTraderVolume(data) {
196
+ if (data.length < 59) {
197
+ throw new Error('Invalid TraderVolume account data: insufficient length');
198
+ }
199
+ let offset = 8; // Skip discriminator
200
+ const trader = new PublicKey(data.subarray(offset, offset + 32));
201
+ offset += 32;
202
+ const month = data.readUInt8(offset);
203
+ offset += 1;
204
+ const year = data.readUInt16LE(offset);
205
+ offset += 2;
206
+ const totalVolume = data.readBigUInt64LE(offset);
207
+ offset += 8;
208
+ const tradeCount = data.readBigUInt64LE(offset);
209
+ offset += 8;
210
+ const lastTradeAt = data.readBigInt64LE(offset);
211
+ return {
212
+ trader,
213
+ month,
214
+ year,
215
+ totalVolume,
216
+ tradeCount,
217
+ lastTradeAt,
218
+ };
219
+ }
220
+ /**
221
+ * Decode CollectionStats account data from raw buffer
222
+ * @param data - Raw account data buffer
223
+ * @returns Parsed CollectionStats object
224
+ */
225
+ export function decodeCollectionStats(data) {
226
+ if (data.length < 88) {
227
+ throw new Error('Invalid CollectionStats account data: insufficient length');
228
+ }
229
+ let offset = 8; // Skip discriminator
230
+ const collection = new PublicKey(data.subarray(offset, offset + 32));
231
+ offset += 32;
232
+ const totalVolume = data.readBigUInt64LE(offset);
233
+ offset += 8;
234
+ const totalTrades = data.readBigUInt64LE(offset);
235
+ offset += 8;
236
+ const floorPrice = data.readBigUInt64LE(offset);
237
+ offset += 8;
238
+ const averagePrice = data.readBigUInt64LE(offset);
239
+ offset += 8;
240
+ const poolCount = data.readUInt32LE(offset);
241
+ offset += 4;
242
+ const lastUpdateAt = data.readBigInt64LE(offset);
243
+ return {
244
+ collection,
245
+ totalVolume,
246
+ totalTrades,
247
+ floorPrice,
248
+ averagePrice,
249
+ poolCount,
250
+ lastUpdateAt,
251
+ };
252
+ }
253
+ /**
254
+ * Parse account data based on discriminator
255
+ * @param data - Raw account data buffer
256
+ * @returns Parsed account object with type information
257
+ */
258
+ export function parseAccount(data) {
259
+ if (data.length < 8) {
260
+ throw new Error('Account data too short to contain discriminator');
261
+ }
262
+ const discriminator = data.subarray(0, 8);
263
+ // Config discriminator: [155, 12, 170, 224, 30, 250, 204, 130]
264
+ if (discriminator.equals(Buffer.from([155, 12, 170, 224, 30, 250, 204, 130]))) {
265
+ return { type: 'config', data: decodeConfig(data) };
266
+ }
267
+ // Pool discriminator: [241, 154, 109, 4, 17, 177, 109, 188]
268
+ if (discriminator.equals(Buffer.from([241, 154, 109, 4, 17, 177, 109, 188]))) {
269
+ return { type: 'pool', data: decodePool(data) };
270
+ }
271
+ // PoolNft discriminator: [45, 198, 65, 11, 29, 13, 209, 1]
272
+ if (discriminator.equals(Buffer.from([45, 198, 65, 11, 29, 13, 209, 1]))) {
273
+ return { type: 'poolNft', data: decodePoolNft(data) };
274
+ }
275
+ // For accounts not defined in IDL, we return unknown
276
+ return { type: 'unknown', discriminator };
277
+ }
278
+ /**
279
+ * Utility function to convert base64 string to Buffer
280
+ * @param base64 - Base64 encoded string
281
+ * @returns Buffer
282
+ */
283
+ export function fromBase64(base64) {
284
+ return Buffer.from(base64, 'base64');
285
+ }
286
+ //# sourceMappingURL=accounts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accounts.js","sourceRoot":"","sources":["../src/accounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAU5C,OAAO,EAAE,SAAS,EAAY,MAAM,YAAY,CAAC;AAEjD;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,IAAI,IAAI,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;IACtE,CAAC;IAED,IAAI,MAAM,GAAG,CAAC,CAAC,CAAC,qBAAqB;IAErC,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACpC,MAAM,IAAI,CAAC,CAAC;IAEZ,MAAM,SAAS,GAAG,IAAI,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC;IACpE,MAAM,IAAI,EAAE,CAAC;IAEb,MAAM,cAAc,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IACjD,MAAM,IAAI,CAAC,CAAC;IAEZ,MAAM,UAAU,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,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