@coinbarrel/sdk 1.3.0 → 2.0.1
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 +305 -305
- package/dist/accounts.d.ts.map +1 -1
- package/dist/accounts.js +48 -62
- package/dist/accounts.js.map +1 -1
- package/dist/constants.d.ts +2 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +20 -21
- package/dist/constants.js.map +1 -1
- package/dist/create.js +18 -21
- package/dist/create.js.map +1 -1
- package/dist/curve.d.ts +25 -2
- package/dist/curve.d.ts.map +1 -1
- package/dist/curve.js +121 -73
- package/dist/curve.js.map +1 -1
- package/dist/index.d.ts +22 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +54 -92
- package/dist/index.js.map +1 -1
- package/dist/metadata.js +8 -15
- package/dist/metadata.js.map +1 -1
- package/dist/pda.d.ts +18 -0
- package/dist/pda.d.ts.map +1 -1
- package/dist/pda.js +54 -36
- package/dist/pda.js.map +1 -1
- package/dist/pool.js +54 -61
- package/dist/pool.js.map +1 -1
- package/dist/rewards.js +28 -32
- package/dist/rewards.js.map +1 -1
- package/dist/types.d.ts +2 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -2
- package/dist/types.js.map +1 -1
- package/package.json +45 -44
package/README.md
CHANGED
|
@@ -1,305 +1,305 @@
|
|
|
1
|
-
# @coinbarrel/sdk
|
|
2
|
-
|
|
3
|
-
SDK for integrating with CoinBarrel AMM - bonding curves and liquidity pools on Solana.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install @coinbarrel/sdk @solana/web3.js @solana/spl-token
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Quick Start
|
|
12
|
-
|
|
13
|
-
```typescript
|
|
14
|
-
import { Connection, Keypair, Transaction } from '@solana/web3.js';
|
|
15
|
-
import { CoinBarrel, solToLamports } from '@coinbarrel/sdk';
|
|
16
|
-
|
|
17
|
-
// Initialize SDK
|
|
18
|
-
const connection = new Connection('https://api.mainnet-beta.solana.com');
|
|
19
|
-
const sdk = new CoinBarrel({
|
|
20
|
-
connection,
|
|
21
|
-
network: 'mainnet', // or 'devnet'
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
// Token to trade
|
|
25
|
-
const tokenMint = new PublicKey('YOUR_TOKEN_MINT');
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
## Bonding Curve Trading (Pre-Graduation)
|
|
29
|
-
|
|
30
|
-
### Get Buy Quote
|
|
31
|
-
|
|
32
|
-
```typescript
|
|
33
|
-
const quote = await sdk.curve.getBuyQuote(
|
|
34
|
-
tokenMint,
|
|
35
|
-
solToLamports(0.1) // 0.1 SOL
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
if (quote) {
|
|
39
|
-
console.log(`Tokens out: ${quote.tokensOut}`);
|
|
40
|
-
console.log(`Price impact: ${quote.priceImpactBps / 100}%`);
|
|
41
|
-
}
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
### Buy Tokens
|
|
45
|
-
|
|
46
|
-
```typescript
|
|
47
|
-
import { Transaction, sendAndConfirmTransaction } from '@solana/web3.js';
|
|
48
|
-
|
|
49
|
-
const instructions = await sdk.curve.buildBuyInstruction({
|
|
50
|
-
tokenMint,
|
|
51
|
-
buyer: wallet.publicKey,
|
|
52
|
-
lamportsIn: solToLamports(0.1),
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
const tx = new Transaction().add(...instructions);
|
|
56
|
-
const signature = await sendAndConfirmTransaction(connection, tx, [wallet]);
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
### Sell Tokens
|
|
60
|
-
|
|
61
|
-
```typescript
|
|
62
|
-
const instructions = await sdk.curve.buildSellInstruction({
|
|
63
|
-
tokenMint,
|
|
64
|
-
seller: wallet.publicKey,
|
|
65
|
-
tokenAmount: BigInt(1_000_000), // 1 token (6 decimals)
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
// Or sell entire balance
|
|
69
|
-
const sellMaxIx = await sdk.curve.buildSellMaxInstruction({
|
|
70
|
-
tokenMint,
|
|
71
|
-
seller: wallet.publicKey,
|
|
72
|
-
});
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
## AMM Pool Trading (Post-Graduation)
|
|
76
|
-
|
|
77
|
-
### Get Swap Quote
|
|
78
|
-
|
|
79
|
-
```typescript
|
|
80
|
-
const quote = await sdk.pool.getSwapSolToTokenQuote(
|
|
81
|
-
tokenMint,
|
|
82
|
-
solToLamports(1.0) // 1 SOL
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
if (quote) {
|
|
86
|
-
console.log(`Tokens out: ${quote.amountOut}`);
|
|
87
|
-
console.log(`Fee: ${quote.fee} lamports`);
|
|
88
|
-
}
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
### Swap SOL for Tokens
|
|
92
|
-
|
|
93
|
-
```typescript
|
|
94
|
-
const instructions = await sdk.pool.buildSwapSolToTokenInstruction({
|
|
95
|
-
tokenMint,
|
|
96
|
-
user: wallet.publicKey,
|
|
97
|
-
lamportsIn: solToLamports(1.0),
|
|
98
|
-
minimumAmountOut: BigInt(900_000), // Slippage protection
|
|
99
|
-
});
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
### Swap Tokens for SOL
|
|
103
|
-
|
|
104
|
-
```typescript
|
|
105
|
-
const instructions = await sdk.pool.buildSwapTokenToSolInstruction({
|
|
106
|
-
tokenMint,
|
|
107
|
-
user: wallet.publicKey,
|
|
108
|
-
amountIn: BigInt(1_000_000),
|
|
109
|
-
minimumLamportsOut: solToLamports(0.09),
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
// Or sell entire balance
|
|
113
|
-
const sellMaxIx = await sdk.pool.buildSwapTokenToSolMaxInstruction({
|
|
114
|
-
tokenMint,
|
|
115
|
-
user: wallet.publicKey,
|
|
116
|
-
});
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
## Token Creation
|
|
120
|
-
|
|
121
|
-
### Create a New Token
|
|
122
|
-
|
|
123
|
-
```typescript
|
|
124
|
-
// Build create token instruction
|
|
125
|
-
const { instructions, mintKeypair } = sdk.buildCreateTokenInstruction({
|
|
126
|
-
payer: wallet.publicKey,
|
|
127
|
-
name: 'My Token',
|
|
128
|
-
symbol: 'MTK',
|
|
129
|
-
uri: 'https://arweave.net/...', // Metadata JSON URI
|
|
130
|
-
creatorFeeRecipient: wallet.publicKey,
|
|
131
|
-
traderRewardsShareBps: 3000, // 30% of fees to holders (optional, default 2500)
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
// Build and send transaction
|
|
135
|
-
const tx = new Transaction().add(...instructions);
|
|
136
|
-
const signature = await sendAndConfirmTransaction(connection, tx, [wallet, mintKeypair]);
|
|
137
|
-
|
|
138
|
-
console.log(`Token created: ${mintKeypair.publicKey.toBase58()}`);
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
The token is created with:
|
|
142
|
-
|
|
143
|
-
- **Mint authority**: Revoked immediately after minting 1B tokens
|
|
144
|
-
- **Freeze authority**: Never set (null from creation)
|
|
145
|
-
- **Total supply**: 1,000,000,000 tokens (6 decimals)
|
|
146
|
-
- **Metadata**: Created via Metaplex (update_authority = creator)
|
|
147
|
-
|
|
148
|
-
## Holder Rewards
|
|
149
|
-
|
|
150
|
-
### Claim Rewards from Bonding Curve
|
|
151
|
-
|
|
152
|
-
```typescript
|
|
153
|
-
const instructions = await sdk.buildClaimRewardsCurveInstruction(tokenMint, wallet.publicKey);
|
|
154
|
-
|
|
155
|
-
const tx = new Transaction().add(...instructions);
|
|
156
|
-
const signature = await sendAndConfirmTransaction(connection, tx, [wallet]);
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
### Claim Rewards from AMM Pool (Post-Graduation)
|
|
160
|
-
|
|
161
|
-
```typescript
|
|
162
|
-
const instructions = await sdk.buildClaimRewardsPoolInstruction(tokenMint, wallet.publicKey);
|
|
163
|
-
|
|
164
|
-
const tx = new Transaction().add(...instructions);
|
|
165
|
-
const signature = await sendAndConfirmTransaction(connection, tx, [wallet]);
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
## Market Info
|
|
169
|
-
|
|
170
|
-
### Get Token Market State
|
|
171
|
-
|
|
172
|
-
```typescript
|
|
173
|
-
const info = await sdk.getMarketInfo(tokenMint);
|
|
174
|
-
|
|
175
|
-
if (info) {
|
|
176
|
-
console.log(`Phase: ${info.phase}`); // 'curve' or 'pool'
|
|
177
|
-
console.log(`Price: ${info.price} lamports/token`);
|
|
178
|
-
console.log(`Market Cap: ${info.marketCapSol} lamports`);
|
|
179
|
-
console.log(`Fee: ${info.feeBps / 100}%`);
|
|
180
|
-
}
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
### Check Token Phase
|
|
184
|
-
|
|
185
|
-
```typescript
|
|
186
|
-
if (await sdk.isOnCurve(tokenMint)) {
|
|
187
|
-
// Use curve methods
|
|
188
|
-
} else if (await sdk.isOnPool(tokenMint)) {
|
|
189
|
-
// Use pool methods
|
|
190
|
-
}
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
## Networks
|
|
194
|
-
|
|
195
|
-
The SDK supports both devnet and mainnet:
|
|
196
|
-
|
|
197
|
-
```typescript
|
|
198
|
-
// Devnet
|
|
199
|
-
const devnetSdk = new CoinBarrel({
|
|
200
|
-
connection: new Connection('https://api.devnet.solana.com'),
|
|
201
|
-
network: 'devnet',
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
// Mainnet
|
|
205
|
-
const mainnetSdk = new CoinBarrel({
|
|
206
|
-
connection: new Connection('https://api.mainnet-beta.solana.com'),
|
|
207
|
-
network: 'mainnet',
|
|
208
|
-
});
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
## Utility Functions
|
|
212
|
-
|
|
213
|
-
```typescript
|
|
214
|
-
import { solToLamports, lamportsToSol, toRawAmount, toUiAmount } from '@coinbarrel/sdk';
|
|
215
|
-
|
|
216
|
-
// SOL conversions
|
|
217
|
-
const lamports = solToLamports(1.5); // 1_500_000_000n
|
|
218
|
-
const sol = lamportsToSol(1_500_000_000n); // 1.5
|
|
219
|
-
|
|
220
|
-
// Token amount conversions (default 6 decimals)
|
|
221
|
-
const raw = toRawAmount(100); // 100_000_000n
|
|
222
|
-
const ui = toUiAmount(100_000_000n); // 100
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
## Token Metadata
|
|
226
|
-
|
|
227
|
-
Fetch token metadata from the Metaplex Token Metadata program:
|
|
228
|
-
|
|
229
|
-
```typescript
|
|
230
|
-
// Get on-chain metadata (fast - just name, symbol, uri)
|
|
231
|
-
const metadata = await sdk.getTokenMetadata(tokenMint);
|
|
232
|
-
if (metadata) {
|
|
233
|
-
console.log(metadata.name); // "My Token"
|
|
234
|
-
console.log(metadata.symbol); // "MTK"
|
|
235
|
-
console.log(metadata.uri); // "https://..."
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
// Get full metadata including off-chain JSON (image, socials)
|
|
239
|
-
const fullMetadata = await sdk.getTokenMetadataJson(tokenMint);
|
|
240
|
-
if (fullMetadata) {
|
|
241
|
-
console.log(fullMetadata.image); // "https://..." or "ipfs://..."
|
|
242
|
-
console.log(fullMetadata.description); // "A cool token"
|
|
243
|
-
console.log(fullMetadata.twitter); // "@mytoken"
|
|
244
|
-
console.log(fullMetadata.website); // "https://..."
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
// Batch fetch for multiple tokens (more efficient)
|
|
248
|
-
const mints = [mint1, mint2, mint3];
|
|
249
|
-
const metadataMap = await sdk.batchGetTokenMetadata(mints);
|
|
250
|
-
for (const [mintStr, meta] of metadataMap) {
|
|
251
|
-
console.log(`${mintStr}: ${meta?.name}`);
|
|
252
|
-
}
|
|
253
|
-
```
|
|
254
|
-
|
|
255
|
-
## PDA Helpers
|
|
256
|
-
|
|
257
|
-
```typescript
|
|
258
|
-
// Get PDAs for a token
|
|
259
|
-
const bondingCurve = sdk.getBondingCurvePda(tokenMint);
|
|
260
|
-
const pool = sdk.getPoolPda(tokenMint);
|
|
261
|
-
const holderReward = sdk.getHolderRewardPda(tokenMint, wallet.publicKey);
|
|
262
|
-
const metadataPda = sdk.getMetadataPda(tokenMint); // Metaplex metadata PDA
|
|
263
|
-
```
|
|
264
|
-
|
|
265
|
-
## Fee Structure
|
|
266
|
-
|
|
267
|
-
CoinBarrel fees are enforced at the program level and cannot be bypassed:
|
|
268
|
-
|
|
269
|
-
- **1% total fee** on all trades
|
|
270
|
-
- **50%** goes to CoinBarrel (protocol) - fixed
|
|
271
|
-
- **25-40%** goes to holder rewards pool (of total fee, configured by token launcher via `trader_rewards_share_bps`)
|
|
272
|
-
- **10-25%** goes to token creator (remainder: 50% - holder%)
|
|
273
|
-
|
|
274
|
-
Example: If `trader_rewards_share_bps = 3000` (30%):
|
|
275
|
-
|
|
276
|
-
- Platform: 50% of fee
|
|
277
|
-
- Holders: 30% of fee
|
|
278
|
-
- Creator: 20% of fee
|
|
279
|
-
|
|
280
|
-
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.
|
|
281
|
-
|
|
282
|
-
## TypeScript
|
|
283
|
-
|
|
284
|
-
The SDK is fully typed:
|
|
285
|
-
|
|
286
|
-
```typescript
|
|
287
|
-
import type {
|
|
288
|
-
BondingCurveState,
|
|
289
|
-
PoolState,
|
|
290
|
-
MarketInfo,
|
|
291
|
-
BuyQuote,
|
|
292
|
-
SellQuote,
|
|
293
|
-
SwapQuote,
|
|
294
|
-
Network,
|
|
295
|
-
TokenMetadata,
|
|
296
|
-
TokenMetadataJson,
|
|
297
|
-
CreateBarrelTokenParams,
|
|
298
|
-
ClaimHolderRewardsParams,
|
|
299
|
-
ClaimHolderRewardsCurveParams,
|
|
300
|
-
} from '@coinbarrel/sdk';
|
|
301
|
-
```
|
|
302
|
-
|
|
303
|
-
## License
|
|
304
|
-
|
|
305
|
-
MIT
|
|
1
|
+
# @coinbarrel/sdk
|
|
2
|
+
|
|
3
|
+
SDK for integrating with CoinBarrel AMM - bonding curves and liquidity pools on Solana.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @coinbarrel/sdk @solana/web3.js @solana/spl-token
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { Connection, Keypair, Transaction } from '@solana/web3.js';
|
|
15
|
+
import { CoinBarrel, solToLamports } from '@coinbarrel/sdk';
|
|
16
|
+
|
|
17
|
+
// Initialize SDK
|
|
18
|
+
const connection = new Connection('https://api.mainnet-beta.solana.com');
|
|
19
|
+
const sdk = new CoinBarrel({
|
|
20
|
+
connection,
|
|
21
|
+
network: 'mainnet', // or 'devnet'
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// Token to trade
|
|
25
|
+
const tokenMint = new PublicKey('YOUR_TOKEN_MINT');
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Bonding Curve Trading (Pre-Graduation)
|
|
29
|
+
|
|
30
|
+
### Get Buy Quote
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
const quote = await sdk.curve.getBuyQuote(
|
|
34
|
+
tokenMint,
|
|
35
|
+
solToLamports(0.1) // 0.1 SOL
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
if (quote) {
|
|
39
|
+
console.log(`Tokens out: ${quote.tokensOut}`);
|
|
40
|
+
console.log(`Price impact: ${quote.priceImpactBps / 100}%`);
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Buy Tokens
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import { Transaction, sendAndConfirmTransaction } from '@solana/web3.js';
|
|
48
|
+
|
|
49
|
+
const instructions = await sdk.curve.buildBuyInstruction({
|
|
50
|
+
tokenMint,
|
|
51
|
+
buyer: wallet.publicKey,
|
|
52
|
+
lamportsIn: solToLamports(0.1),
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const tx = new Transaction().add(...instructions);
|
|
56
|
+
const signature = await sendAndConfirmTransaction(connection, tx, [wallet]);
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Sell Tokens
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
const instructions = await sdk.curve.buildSellInstruction({
|
|
63
|
+
tokenMint,
|
|
64
|
+
seller: wallet.publicKey,
|
|
65
|
+
tokenAmount: BigInt(1_000_000), // 1 token (6 decimals)
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// Or sell entire balance
|
|
69
|
+
const sellMaxIx = await sdk.curve.buildSellMaxInstruction({
|
|
70
|
+
tokenMint,
|
|
71
|
+
seller: wallet.publicKey,
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## AMM Pool Trading (Post-Graduation)
|
|
76
|
+
|
|
77
|
+
### Get Swap Quote
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
const quote = await sdk.pool.getSwapSolToTokenQuote(
|
|
81
|
+
tokenMint,
|
|
82
|
+
solToLamports(1.0) // 1 SOL
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
if (quote) {
|
|
86
|
+
console.log(`Tokens out: ${quote.amountOut}`);
|
|
87
|
+
console.log(`Fee: ${quote.fee} lamports`);
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Swap SOL for Tokens
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
const instructions = await sdk.pool.buildSwapSolToTokenInstruction({
|
|
95
|
+
tokenMint,
|
|
96
|
+
user: wallet.publicKey,
|
|
97
|
+
lamportsIn: solToLamports(1.0),
|
|
98
|
+
minimumAmountOut: BigInt(900_000), // Slippage protection
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Swap Tokens for SOL
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
const instructions = await sdk.pool.buildSwapTokenToSolInstruction({
|
|
106
|
+
tokenMint,
|
|
107
|
+
user: wallet.publicKey,
|
|
108
|
+
amountIn: BigInt(1_000_000),
|
|
109
|
+
minimumLamportsOut: solToLamports(0.09),
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// Or sell entire balance
|
|
113
|
+
const sellMaxIx = await sdk.pool.buildSwapTokenToSolMaxInstruction({
|
|
114
|
+
tokenMint,
|
|
115
|
+
user: wallet.publicKey,
|
|
116
|
+
});
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Token Creation
|
|
120
|
+
|
|
121
|
+
### Create a New Token
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
// Build create token instruction
|
|
125
|
+
const { instructions, mintKeypair } = sdk.buildCreateTokenInstruction({
|
|
126
|
+
payer: wallet.publicKey,
|
|
127
|
+
name: 'My Token',
|
|
128
|
+
symbol: 'MTK',
|
|
129
|
+
uri: 'https://arweave.net/...', // Metadata JSON URI
|
|
130
|
+
creatorFeeRecipient: wallet.publicKey,
|
|
131
|
+
traderRewardsShareBps: 3000, // 30% of fees to holders (optional, default 2500)
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// Build and send transaction
|
|
135
|
+
const tx = new Transaction().add(...instructions);
|
|
136
|
+
const signature = await sendAndConfirmTransaction(connection, tx, [wallet, mintKeypair]);
|
|
137
|
+
|
|
138
|
+
console.log(`Token created: ${mintKeypair.publicKey.toBase58()}`);
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
The token is created with:
|
|
142
|
+
|
|
143
|
+
- **Mint authority**: Revoked immediately after minting 1B tokens
|
|
144
|
+
- **Freeze authority**: Never set (null from creation)
|
|
145
|
+
- **Total supply**: 1,000,000,000 tokens (6 decimals)
|
|
146
|
+
- **Metadata**: Created via Metaplex (update_authority = creator)
|
|
147
|
+
|
|
148
|
+
## Holder Rewards
|
|
149
|
+
|
|
150
|
+
### Claim Rewards from Bonding Curve
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
const instructions = await sdk.buildClaimRewardsCurveInstruction(tokenMint, wallet.publicKey);
|
|
154
|
+
|
|
155
|
+
const tx = new Transaction().add(...instructions);
|
|
156
|
+
const signature = await sendAndConfirmTransaction(connection, tx, [wallet]);
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Claim Rewards from AMM Pool (Post-Graduation)
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
const instructions = await sdk.buildClaimRewardsPoolInstruction(tokenMint, wallet.publicKey);
|
|
163
|
+
|
|
164
|
+
const tx = new Transaction().add(...instructions);
|
|
165
|
+
const signature = await sendAndConfirmTransaction(connection, tx, [wallet]);
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Market Info
|
|
169
|
+
|
|
170
|
+
### Get Token Market State
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
const info = await sdk.getMarketInfo(tokenMint);
|
|
174
|
+
|
|
175
|
+
if (info) {
|
|
176
|
+
console.log(`Phase: ${info.phase}`); // 'curve' or 'pool'
|
|
177
|
+
console.log(`Price: ${info.price} lamports/token`);
|
|
178
|
+
console.log(`Market Cap: ${info.marketCapSol} lamports`);
|
|
179
|
+
console.log(`Fee: ${info.feeBps / 100}%`);
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Check Token Phase
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
if (await sdk.isOnCurve(tokenMint)) {
|
|
187
|
+
// Use curve methods
|
|
188
|
+
} else if (await sdk.isOnPool(tokenMint)) {
|
|
189
|
+
// Use pool methods
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Networks
|
|
194
|
+
|
|
195
|
+
The SDK supports both devnet and mainnet:
|
|
196
|
+
|
|
197
|
+
```typescript
|
|
198
|
+
// Devnet
|
|
199
|
+
const devnetSdk = new CoinBarrel({
|
|
200
|
+
connection: new Connection('https://api.devnet.solana.com'),
|
|
201
|
+
network: 'devnet',
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
// Mainnet
|
|
205
|
+
const mainnetSdk = new CoinBarrel({
|
|
206
|
+
connection: new Connection('https://api.mainnet-beta.solana.com'),
|
|
207
|
+
network: 'mainnet',
|
|
208
|
+
});
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## Utility Functions
|
|
212
|
+
|
|
213
|
+
```typescript
|
|
214
|
+
import { solToLamports, lamportsToSol, toRawAmount, toUiAmount } from '@coinbarrel/sdk';
|
|
215
|
+
|
|
216
|
+
// SOL conversions
|
|
217
|
+
const lamports = solToLamports(1.5); // 1_500_000_000n
|
|
218
|
+
const sol = lamportsToSol(1_500_000_000n); // 1.5
|
|
219
|
+
|
|
220
|
+
// Token amount conversions (default 6 decimals)
|
|
221
|
+
const raw = toRawAmount(100); // 100_000_000n
|
|
222
|
+
const ui = toUiAmount(100_000_000n); // 100
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## Token Metadata
|
|
226
|
+
|
|
227
|
+
Fetch token metadata from the Metaplex Token Metadata program:
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
// Get on-chain metadata (fast - just name, symbol, uri)
|
|
231
|
+
const metadata = await sdk.getTokenMetadata(tokenMint);
|
|
232
|
+
if (metadata) {
|
|
233
|
+
console.log(metadata.name); // "My Token"
|
|
234
|
+
console.log(metadata.symbol); // "MTK"
|
|
235
|
+
console.log(metadata.uri); // "https://..."
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// Get full metadata including off-chain JSON (image, socials)
|
|
239
|
+
const fullMetadata = await sdk.getTokenMetadataJson(tokenMint);
|
|
240
|
+
if (fullMetadata) {
|
|
241
|
+
console.log(fullMetadata.image); // "https://..." or "ipfs://..."
|
|
242
|
+
console.log(fullMetadata.description); // "A cool token"
|
|
243
|
+
console.log(fullMetadata.twitter); // "@mytoken"
|
|
244
|
+
console.log(fullMetadata.website); // "https://..."
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// Batch fetch for multiple tokens (more efficient)
|
|
248
|
+
const mints = [mint1, mint2, mint3];
|
|
249
|
+
const metadataMap = await sdk.batchGetTokenMetadata(mints);
|
|
250
|
+
for (const [mintStr, meta] of metadataMap) {
|
|
251
|
+
console.log(`${mintStr}: ${meta?.name}`);
|
|
252
|
+
}
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
## PDA Helpers
|
|
256
|
+
|
|
257
|
+
```typescript
|
|
258
|
+
// Get PDAs for a token
|
|
259
|
+
const bondingCurve = sdk.getBondingCurvePda(tokenMint);
|
|
260
|
+
const pool = sdk.getPoolPda(tokenMint);
|
|
261
|
+
const holderReward = sdk.getHolderRewardPda(tokenMint, wallet.publicKey);
|
|
262
|
+
const metadataPda = sdk.getMetadataPda(tokenMint); // Metaplex metadata PDA
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
## Fee Structure
|
|
266
|
+
|
|
267
|
+
CoinBarrel fees are enforced at the program level and cannot be bypassed:
|
|
268
|
+
|
|
269
|
+
- **1% total fee** on all trades
|
|
270
|
+
- **50%** goes to CoinBarrel (protocol) - fixed
|
|
271
|
+
- **25-40%** goes to holder rewards pool (of total fee, configured by token launcher via `trader_rewards_share_bps`)
|
|
272
|
+
- **10-25%** goes to token creator (remainder: 50% - holder%)
|
|
273
|
+
|
|
274
|
+
Example: If `trader_rewards_share_bps = 3000` (30%):
|
|
275
|
+
|
|
276
|
+
- Platform: 50% of fee
|
|
277
|
+
- Holders: 30% of fee
|
|
278
|
+
- Creator: 20% of fee
|
|
279
|
+
|
|
280
|
+
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.
|
|
281
|
+
|
|
282
|
+
## TypeScript
|
|
283
|
+
|
|
284
|
+
The SDK is fully typed:
|
|
285
|
+
|
|
286
|
+
```typescript
|
|
287
|
+
import type {
|
|
288
|
+
BondingCurveState,
|
|
289
|
+
PoolState,
|
|
290
|
+
MarketInfo,
|
|
291
|
+
BuyQuote,
|
|
292
|
+
SellQuote,
|
|
293
|
+
SwapQuote,
|
|
294
|
+
Network,
|
|
295
|
+
TokenMetadata,
|
|
296
|
+
TokenMetadataJson,
|
|
297
|
+
CreateBarrelTokenParams,
|
|
298
|
+
ClaimHolderRewardsParams,
|
|
299
|
+
ClaimHolderRewardsCurveParams,
|
|
300
|
+
} from '@coinbarrel/sdk';
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
## License
|
|
304
|
+
|
|
305
|
+
MIT
|
package/dist/accounts.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accounts.d.ts","sourceRoot":"","sources":["../src/accounts.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAIxD,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AA4B3E;;GAEG;AACH,wBAAsB,oBAAoB,CACzC,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,SAAS,EACpB,SAAS,EAAE,SAAS,GAClB,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"accounts.d.ts","sourceRoot":"","sources":["../src/accounts.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAIxD,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AA4B3E;;GAEG;AACH,wBAAsB,oBAAoB,CACzC,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,SAAS,EACpB,SAAS,EAAE,SAAS,GAClB,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,CA8BnC;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CACvC,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,SAAS,EACpB,SAAS,EAAE,SAAS,GAClB,OAAO,CAAC,MAAM,CAAC,CAKjB;AAID;;GAEG;AACH,wBAAsB,YAAY,CACjC,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,SAAS,EACpB,SAAS,EAAE,SAAS,GAClB,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CA0B3B;AAED;;;GAGG;AACH,wBAAsB,eAAe,CACpC,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,SAAS,EACpB,SAAS,EAAE,SAAS,GAClB,OAAO,CAAC;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,CAyB9D;AAID;;;GAGG;AACH,wBAAsB,aAAa,CAClC,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,SAAS,EACpB,SAAS,EAAE,SAAS,GAClB,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAwD5B;AAED;;GAEG;AACH,wBAAsB,mBAAmB,CACxC,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE,SAAS,GACb,OAAO,CAAC,MAAM,CAAC,CAQjB"}
|