@coinbarrel/sdk 3.2.6 → 3.2.7

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 (2) hide show
  1. package/README.md +180 -161
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @coinbarrel/sdk
2
2
 
3
- SDK for integrating with CoinBarrel AMM - bonding curves and liquidity pools on Solana.
3
+ SDK for launching and trading tokens on CoinBarrel instant Meteora DAMM V2 pools on Solana.
4
4
 
5
5
  ## Installation
6
6
 
@@ -11,87 +11,87 @@ npm install @coinbarrel/sdk @solana/web3.js @solana/spl-token
11
11
  ## Quick Start
12
12
 
13
13
  ```typescript
14
- import { Connection, Keypair, Transaction } from '@solana/web3.js';
15
- import { CoinBarrel, solToLamports } from '@coinbarrel/sdk';
14
+ import { Connection, Keypair, PublicKey, Transaction, sendAndConfirmTransaction } from '@solana/web3.js';
15
+ import { CoinBarrel, solToLamports, InstantTokenVariant, LaunchTier } from '@coinbarrel/sdk';
16
16
 
17
- // Initialize SDK
18
17
  const connection = new Connection('https://api.mainnet-beta.solana.com');
19
18
  const sdk = new CoinBarrel({
20
19
  connection,
21
20
  network: 'mainnet', // or 'devnet'
22
21
  });
23
-
24
- // Token to trade
25
- const tokenMint = new PublicKey('YOUR_TOKEN_MINT');
26
22
  ```
27
23
 
28
- ## Bonding Curve Trading (Pre-Graduation)
24
+ ## Launch a Token
29
25
 
30
- ### Get Buy Quote
26
+ Tokens launch directly to Meteora DAMM V2 pools using Token2022 with native metadata — no bonding curve, no graduation.
31
27
 
32
28
  ```typescript
33
- const quote = await sdk.curve.getBuyQuote(
34
- tokenMint,
35
- solToLamports(0.1) // 0.1 SOL
36
- );
29
+ const { instructions, mintKeypair, adminTokenAccount } = sdk.buildCreateInstantTokenV2Instruction({
30
+ payer: wallet.publicKey,
31
+ creator: wallet.publicKey,
32
+ name: 'My Token',
33
+ symbol: 'MTK',
34
+ uri: 'https://arweave.net/...', // Metadata JSON URI
35
+ variant: InstantTokenVariant.Standard,
36
+ traderRewardsShareBps: 2500, // 25% of fees to holders
37
+ launchTier: LaunchTier.Standard,
38
+ });
37
39
 
38
- if (quote) {
39
- console.log(`Tokens out: ${quote.tokensOut}`);
40
- console.log(`Price impact: ${quote.priceImpactBps / 100}%`);
41
- }
40
+ const tx = new Transaction().add(...instructions);
41
+ const signature = await sendAndConfirmTransaction(connection, tx, [wallet, mintKeypair]);
42
+
43
+ console.log(`Token created: ${mintKeypair.publicKey.toBase58()}`);
42
44
  ```
43
45
 
44
- ### Buy Tokens
46
+ The token is created with:
45
47
 
46
- ```typescript
47
- import { Transaction, sendAndConfirmTransaction } from '@solana/web3.js';
48
+ - **Token Program**: Token2022 (with native metadata extension — no Metaplex)
49
+ - **Mint authority**: Revoked immediately after minting 1B tokens
50
+ - **Freeze authority**: Never set
51
+ - **Total supply**: 1,000,000,000 tokens (6 decimals)
52
+ - **Creation fee**: 0.03 SOL
53
+ - **Pool creation**: Backend automatically creates the Meteora pool after token creation
48
54
 
49
- // Get quote first to calculate minimum output with slippage
50
- const quote = await sdk.curve.getBuyQuote(tokenMint, solToLamports(0.1));
51
- const slippageBps = 100; // 1%
52
- const minimumTokensOut = quote
53
- ? (quote.tokensOut * BigInt(10000 - slippageBps)) / 10000n
54
- : 0n;
55
+ ### Variants
55
56
 
56
- const instructions = await sdk.curve.buildBuyInstruction({
57
- tokenMint,
58
- buyer: wallet.publicKey,
59
- lamportsIn: solToLamports(0.1),
60
- minimumTokensOut, // Slippage protection - tx fails if output is less
61
- });
57
+ | Variant | Virtual Liquidity | Use Case |
58
+ |---------|------------------|----------|
59
+ | Standard (0) | 90 SOL | Normal launches |
60
+ | Deep (1) | 120 SOL | Lower price impact |
62
61
 
63
- const tx = new Transaction().add(...instructions);
64
- const signature = await sendAndConfirmTransaction(connection, tx, [wallet]);
65
- ```
62
+ ### Launch Tiers
66
63
 
67
- ### Sell Tokens
64
+ | Tier | Trading Fee | Use Case |
65
+ |------|-------------|----------|
66
+ | Standard (0) | 1.25% | Default, lower fees |
67
+ | Premium (1) | 5% | Higher creator revenue |
68
68
 
69
- ```typescript
70
- // Get quote first to calculate minimum output with slippage
71
- const sellQuote = await sdk.curve.getSellQuote(tokenMint, BigInt(1_000_000));
72
- const slippageBps = 100; // 1%
73
- const minimumLamportsOut = sellQuote
74
- ? (sellQuote.solOut * BigInt(10000 - slippageBps)) / 10000n
75
- : 0n;
69
+ ### Advanced Options
76
70
 
77
- const instructions = await sdk.curve.buildSellInstruction({
78
- tokenMint,
79
- seller: wallet.publicKey,
80
- tokenAmount: BigInt(1_000_000), // 1 token (6 decimals)
81
- minimumLamportsOut, // Slippage protection
82
- });
83
-
84
- // Or sell entire balance
85
- const sellMaxIx = await sdk.curve.buildSellMaxInstruction({
86
- tokenMint,
87
- seller: wallet.publicKey,
88
- minimumLamportsOut: 0n, // Use 0 to accept any amount, or calculate from quote
71
+ ```typescript
72
+ sdk.buildCreateInstantTokenV2Instruction({
73
+ payer: wallet.publicKey,
74
+ creator: wallet.publicKey,
75
+ name: 'My Token',
76
+ symbol: 'MTK',
77
+ uri: 'https://arweave.net/...',
78
+ variant: InstantTokenVariant.Deep, // 120 SOL virtual liquidity
79
+ traderRewardsShareBps: 3000, // 30% of fees to holders
80
+ launchTier: LaunchTier.Premium, // 5% trading fee
81
+ burnFeeBps: 1000, // 10% burn fee
82
+ devBuyAmountLamports: solToLamports(1), // 1 SOL dev buy
83
+ recipients: [ // Multi-recipient fee split (up to 25)
84
+ { recipientType: 0, twitterId: 0n, wallet: wallet1, bps: 7000 },
85
+ { recipientType: 0, twitterId: 0n, wallet: wallet2, bps: 3000 },
86
+ ],
89
87
  });
90
88
  ```
91
89
 
92
- ## AMM Pool Trading (Post-Graduation)
90
+ ## Trading
93
91
 
94
- ### Get Swap Quote
92
+ Once the Meteora pool is live, use pool methods to trade.
93
+
94
+ ### Get a Buy Quote
95
95
 
96
96
  ```typescript
97
97
  const quote = await sdk.pool.getSwapSolToTokenQuote(
@@ -102,81 +102,115 @@ const quote = await sdk.pool.getSwapSolToTokenQuote(
102
102
  if (quote) {
103
103
  console.log(`Tokens out: ${quote.amountOut}`);
104
104
  console.log(`Fee: ${quote.fee} lamports`);
105
+ console.log(`Price impact: ${quote.priceImpactBps / 100}%`);
105
106
  }
106
107
  ```
107
108
 
108
- ### Swap SOL for Tokens
109
+ ### Buy Tokens (SOL -> Token)
109
110
 
110
111
  ```typescript
112
+ const quote = await sdk.pool.getSwapSolToTokenQuote(tokenMint, solToLamports(1.0));
113
+ const slippageBps = 100; // 1%
114
+ const minimumAmountOut = quote
115
+ ? (quote.amountOut * BigInt(10000 - slippageBps)) / 10000n
116
+ : 0n;
117
+
111
118
  const instructions = await sdk.pool.buildSwapSolToTokenInstruction({
112
119
  tokenMint,
113
120
  user: wallet.publicKey,
114
121
  lamportsIn: solToLamports(1.0),
115
- minimumAmountOut: BigInt(900_000), // Slippage protection
122
+ minimumAmountOut,
116
123
  });
124
+
125
+ const tx = new Transaction().add(...instructions);
126
+ const signature = await sendAndConfirmTransaction(connection, tx, [wallet]);
127
+ ```
128
+
129
+ ### Get a Sell Quote
130
+
131
+ ```typescript
132
+ const quote = await sdk.pool.getSwapTokenToSolQuote(
133
+ tokenMint,
134
+ BigInt(1_000_000) // 1 token (6 decimals)
135
+ );
136
+
137
+ if (quote) {
138
+ console.log(`SOL out: ${quote.amountOut} lamports`);
139
+ console.log(`Fee: ${quote.fee} lamports`);
140
+ }
117
141
  ```
118
142
 
119
- ### Swap Tokens for SOL
143
+ ### Sell Tokens (Token -> SOL)
120
144
 
121
145
  ```typescript
146
+ const quote = await sdk.pool.getSwapTokenToSolQuote(tokenMint, BigInt(1_000_000));
147
+ const slippageBps = 100; // 1%
148
+ const minimumLamportsOut = quote
149
+ ? (quote.amountOut * BigInt(10000 - slippageBps)) / 10000n
150
+ : 0n;
151
+
122
152
  const instructions = await sdk.pool.buildSwapTokenToSolInstruction({
123
153
  tokenMint,
124
154
  user: wallet.publicKey,
125
155
  amountIn: BigInt(1_000_000),
126
- minimumLamportsOut: solToLamports(0.09),
156
+ minimumLamportsOut,
127
157
  });
128
158
 
129
- // Or sell entire balance
130
- const sellMaxIx = await sdk.pool.buildSwapTokenToSolMaxInstruction({
131
- tokenMint,
132
- user: wallet.publicKey,
133
- });
159
+ const tx = new Transaction().add(...instructions);
160
+ const signature = await sendAndConfirmTransaction(connection, tx, [wallet]);
134
161
  ```
135
162
 
136
- ## Token Creation
137
-
138
- ### Create a New Token
163
+ ### Sell All Tokens
139
164
 
140
165
  ```typescript
141
- // Build create token instruction
142
- const { instructions, mintKeypair } = sdk.buildCreateTokenInstruction({
143
- payer: wallet.publicKey,
144
- name: 'My Token',
145
- symbol: 'MTK',
146
- uri: 'https://arweave.net/...', // Metadata JSON URI
147
- creatorFeeRecipient: wallet.publicKey,
148
- traderRewardsShareBps: 3000, // 30% of fees to holders (optional, default 2500)
166
+ const instructions = await sdk.pool.buildSwapTokenToSolMaxInstruction({
167
+ tokenMint,
168
+ user: wallet.publicKey,
149
169
  });
150
170
 
151
- // Build and send transaction
152
171
  const tx = new Transaction().add(...instructions);
153
- const signature = await sendAndConfirmTransaction(connection, tx, [wallet, mintKeypair]);
154
-
155
- console.log(`Token created: ${mintKeypair.publicKey.toBase58()}`);
172
+ const signature = await sendAndConfirmTransaction(connection, tx, [wallet]);
156
173
  ```
157
174
 
158
- The token is created with:
175
+ ## Holder Rewards
159
176
 
160
- - **Mint authority**: Revoked immediately after minting 1B tokens
161
- - **Freeze authority**: Never set (null from creation)
162
- - **Total supply**: 1,000,000,000 tokens (6 decimals)
163
- - **Metadata**: Created via Metaplex (update_authority = creator)
177
+ Token holders earn a share of trading fees. The SDK handles claiming automatically.
164
178
 
165
- ## Holder Rewards
179
+ ### Check Pending Rewards
180
+
181
+ ```typescript
182
+ const pending = await sdk.getPendingHolderRewards(tokenMint, wallet.publicKey);
166
183
 
167
- ### Claim Rewards from Bonding Curve
184
+ if (pending) {
185
+ console.log(`Pending: ${Number(pending.pendingLamports) / 1e9} SOL`);
186
+ console.log(`Token balance: ${pending.tokenBalance}`);
187
+ }
188
+ ```
189
+
190
+ ### Claim Rewards
168
191
 
169
192
  ```typescript
170
- const instructions = await sdk.buildClaimRewardsCurveInstruction(tokenMint, wallet.publicKey);
193
+ const pending = await sdk.getPendingHolderRewards(tokenMint, wallet.publicKey);
171
194
 
172
- const tx = new Transaction().add(...instructions);
173
- const signature = await sendAndConfirmTransaction(connection, tx, [wallet]);
195
+ if (pending && pending.pendingLamports > 0n) {
196
+ const instructions = await sdk.buildClaimInstructions(pending);
197
+ const tx = new Transaction().add(...instructions);
198
+ const signature = await sendAndConfirmTransaction(connection, tx, [wallet]);
199
+ }
174
200
  ```
175
201
 
176
- ### Claim Rewards from AMM Pool (Post-Graduation)
202
+ ### Claim Creator Trading Fees
203
+
204
+ Token creators can claim their accumulated trading fee share:
177
205
 
178
206
  ```typescript
179
- const instructions = await sdk.buildClaimRewardsPoolInstruction(tokenMint, wallet.publicKey);
207
+ import { buildClaimCreatorTraderFeesInstruction } from '@coinbarrel/sdk';
208
+
209
+ const instructions = await buildClaimCreatorTraderFeesInstruction(
210
+ connection,
211
+ { tokenMint, creator: wallet.publicKey },
212
+ sdk.programId
213
+ );
180
214
 
181
215
  const tx = new Transaction().add(...instructions);
182
216
  const signature = await sendAndConfirmTransaction(connection, tx, [wallet]);
@@ -184,33 +218,50 @@ const signature = await sendAndConfirmTransaction(connection, tx, [wallet]);
184
218
 
185
219
  ## Market Info
186
220
 
187
- ### Get Token Market State
188
-
189
221
  ```typescript
190
222
  const info = await sdk.getMarketInfo(tokenMint);
191
223
 
192
224
  if (info) {
193
- console.log(`Phase: ${info.phase}`); // 'curve' or 'pool'
194
225
  console.log(`Price: ${info.price} lamports/token`);
195
226
  console.log(`Market Cap: ${info.marketCapSol} lamports`);
196
227
  console.log(`Fee: ${info.feeBps / 100}%`);
228
+ console.log(`SOL reserve: ${info.solReserve}`);
229
+ console.log(`Token reserve: ${info.tokenReserve}`);
230
+ console.log(`Circulating supply: ${info.circulatingSupply}`);
197
231
  }
198
232
  ```
199
233
 
200
- ### Check Token Phase
234
+ ## Token Metadata
235
+
236
+ The SDK supports both Token2022 native metadata and Metaplex metadata. Use the universal methods to handle either automatically:
201
237
 
202
238
  ```typescript
203
- if (await sdk.isOnCurve(tokenMint)) {
204
- // Use curve methods
205
- } else if (await sdk.isOnPool(tokenMint)) {
206
- // Use pool methods
239
+ // Auto-detects Token2022 vs SPL Token
240
+ const metadata = await sdk.getUniversalTokenMetadata(tokenMint);
241
+ if (metadata) {
242
+ console.log(metadata.name); // "My Token"
243
+ console.log(metadata.symbol); // "MTK"
244
+ console.log(metadata.uri); // "https://..."
207
245
  }
246
+
247
+ // Full metadata including off-chain JSON (image, socials)
248
+ const full = await sdk.getUniversalTokenMetadataJson(tokenMint);
249
+ if (full) {
250
+ console.log(full.image); // "https://..."
251
+ console.log(full.description); // "A cool token"
252
+ console.log(full.twitter); // "@mytoken"
253
+ console.log(full.website); // "https://..."
254
+ }
255
+
256
+ // Check if a token is Token2022
257
+ const isT22 = await sdk.isToken2022Mint(tokenMint);
258
+
259
+ // Batch fetch for multiple tokens
260
+ const metadataMap = await sdk.batchGetTokenMetadata([mint1, mint2, mint3]);
208
261
  ```
209
262
 
210
263
  ## Networks
211
264
 
212
- The SDK supports both devnet and mainnet:
213
-
214
265
  ```typescript
215
266
  // Devnet
216
267
  const devnetSdk = new CoinBarrel({
@@ -231,90 +282,58 @@ const mainnetSdk = new CoinBarrel({
231
282
  import { solToLamports, lamportsToSol, toRawAmount, toUiAmount } from '@coinbarrel/sdk';
232
283
 
233
284
  // SOL conversions
234
- const lamports = solToLamports(1.5); // 1_500_000_000n
235
- const sol = lamportsToSol(1_500_000_000n); // 1.5
285
+ const lamports = solToLamports(1.5); // 1_500_000_000n
286
+ const sol = lamportsToSol(1_500_000_000n); // 1.5
236
287
 
237
288
  // Token amount conversions (default 6 decimals)
238
- const raw = toRawAmount(100); // 100_000_000n
239
- const ui = toUiAmount(100_000_000n); // 100
240
- ```
241
-
242
- ## Token Metadata
243
-
244
- Fetch token metadata from the Metaplex Token Metadata program:
245
-
246
- ```typescript
247
- // Get on-chain metadata (fast - just name, symbol, uri)
248
- const metadata = await sdk.getTokenMetadata(tokenMint);
249
- if (metadata) {
250
- console.log(metadata.name); // "My Token"
251
- console.log(metadata.symbol); // "MTK"
252
- console.log(metadata.uri); // "https://..."
253
- }
254
-
255
- // Get full metadata including off-chain JSON (image, socials)
256
- const fullMetadata = await sdk.getTokenMetadataJson(tokenMint);
257
- if (fullMetadata) {
258
- console.log(fullMetadata.image); // "https://..." or "ipfs://..."
259
- console.log(fullMetadata.description); // "A cool token"
260
- console.log(fullMetadata.twitter); // "@mytoken"
261
- console.log(fullMetadata.website); // "https://..."
262
- }
263
-
264
- // Batch fetch for multiple tokens (more efficient)
265
- const mints = [mint1, mint2, mint3];
266
- const metadataMap = await sdk.batchGetTokenMetadata(mints);
267
- for (const [mintStr, meta] of metadataMap) {
268
- console.log(`${mintStr}: ${meta?.name}`);
269
- }
289
+ const raw = toRawAmount(100); // 100_000_000n
290
+ const ui = toUiAmount(100_000_000n); // 100
270
291
  ```
271
292
 
272
- ## PDA Helpers
293
+ ## Fee Structure
273
294
 
274
- ```typescript
275
- // Get PDAs for a token
276
- const bondingCurve = sdk.getBondingCurvePda(tokenMint);
277
- const pool = sdk.getPoolPda(tokenMint);
278
- const holderReward = sdk.getHolderRewardPda(tokenMint, wallet.publicKey);
279
- const metadataPda = sdk.getMetadataPda(tokenMint); // Metaplex metadata PDA
280
- ```
295
+ Fees are enforced on-chain and cannot be bypassed:
281
296
 
282
- ## Fee Structure
297
+ - **Platform**: 50% of total fee (fixed)
298
+ - **Holder rewards**: 0–50% of total fee (set at launch via `traderRewardsShareBps`)
299
+ - **Creator**: remainder after platform + holders
300
+ - **Burn** (optional): 0–50% of creator portion (set at launch via `burnFeeBps`)
283
301
 
284
- CoinBarrel fees are enforced at the program level and cannot be bypassed:
302
+ The trading fee rate depends on the launch tier:
285
303
 
286
- - **1% total fee** on all trades
287
- - **50%** goes to CoinBarrel (protocol) - fixed
288
- - **25-40%** goes to holder rewards pool (of total fee, configured by token launcher via `trader_rewards_share_bps`)
289
- - **10-25%** goes to token creator (remainder: 50% - holder%)
304
+ | Tier | Fee Rate |
305
+ |------|----------|
306
+ | Standard | 1.25% |
307
+ | Premium | 5% |
290
308
 
291
- Example: If `trader_rewards_share_bps = 3000` (30%):
309
+ Example with `traderRewardsShareBps = 3000` (30%) on a Standard tier (1.25% fee):
292
310
 
293
311
  - Platform: 50% of fee
294
312
  - Holders: 30% of fee
295
313
  - Creator: 20% of fee
296
314
 
297
- The split is set when the token is launched (`trader_rewards_share_bps` must be 2500-4000). The SDK reads fee recipients from on-chain state. Integrators cannot modify or bypass fees.
298
-
299
315
  ## TypeScript
300
316
 
301
317
  The SDK is fully typed:
302
318
 
303
319
  ```typescript
304
320
  import type {
305
- BondingCurveState,
306
- PoolState,
307
321
  MarketInfo,
308
- BuyQuote,
309
- SellQuote,
310
322
  SwapQuote,
323
+ PoolState,
311
324
  Network,
312
325
  TokenMetadata,
313
326
  TokenMetadataJson,
314
- CreateBarrelTokenParams,
315
- ClaimHolderRewardsParams,
316
- ClaimHolderRewardsCurveParams,
327
+ CreateInstantTokenV2Params,
328
+ InstantTokenV2State,
329
+ SwapSolToTokenParams,
330
+ SwapTokenToSolParams,
331
+ SwapTokenToSolMaxParams,
332
+ PendingHolderRewards,
333
+ FeeRecipient,
317
334
  } from '@coinbarrel/sdk';
335
+
336
+ import { InstantTokenVariant, LaunchTier } from '@coinbarrel/sdk';
318
337
  ```
319
338
 
320
339
  ## License
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@coinbarrel/sdk",
3
- "version": "3.2.6",
4
- "description": "SDK for CoinBarrel AMM - bonding curves and liquidity pools on Solana",
3
+ "version": "3.2.7",
4
+ "description": "SDK for launching and trading tokens on CoinBarrel - instant Meteora DAMM V2 pools on Solana",
5
5
  "author": "CoinBarrel",
6
6
  "license": "MIT",
7
7
  "type": "module",