@coinbarrel/sdk 1.0.1 → 1.2.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 +85 -0
- package/dist/accounts.js +33 -26
- package/dist/constants.js +22 -17
- package/dist/create.js +100 -0
- package/dist/curve.js +57 -51
- package/dist/index.js +167 -21
- package/dist/metadata.js +211 -0
- package/dist/pda.js +36 -24
- package/dist/pool.js +61 -55
- package/dist/rewards.js +97 -0
- package/dist/types.js +2 -2
- package/package.json +2 -3
- package/dist/accounts.d.ts +0 -36
- package/dist/accounts.d.ts.map +0 -1
- package/dist/accounts.js.map +0 -1
- package/dist/constants.d.ts +0 -79
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants.js.map +0 -1
- package/dist/curve.d.ts +0 -37
- package/dist/curve.d.ts.map +0 -1
- package/dist/curve.js.map +0 -1
- package/dist/index.d.ts +0 -184
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/pda.d.ts +0 -51
- package/dist/pda.d.ts.map +0 -1
- package/dist/pda.js.map +0 -1
- package/dist/pool.d.ts +0 -32
- package/dist/pool.d.ts.map +0 -1
- package/dist/pool.js.map +0 -1
- package/dist/types.d.ts +0 -162
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
package/dist/curve.js
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Bonding Curve Operations
|
|
3
4
|
* Buy and sell tokens on the bonding curve
|
|
4
5
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.getBuyQuote = getBuyQuote;
|
|
8
|
+
exports.getSellQuote = getSellQuote;
|
|
9
|
+
exports.buildBuyOnCurveInstruction = buildBuyOnCurveInstruction;
|
|
10
|
+
exports.buildSellOnCurveInstruction = buildSellOnCurveInstruction;
|
|
11
|
+
exports.buildSellMaxOnCurveInstruction = buildSellMaxOnCurveInstruction;
|
|
12
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
13
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
14
|
+
const constants_js_1 = require("./constants.js");
|
|
15
|
+
const pda_js_1 = require("./pda.js");
|
|
16
|
+
const accounts_js_1 = require("./accounts.js");
|
|
10
17
|
// ============= Buffer Helpers =============
|
|
11
18
|
function writeU64LE(n) {
|
|
12
19
|
const b = Buffer.alloc(8);
|
|
@@ -19,8 +26,8 @@ function writeU64LE(n) {
|
|
|
19
26
|
* Uses amplified constant product formula matching the program:
|
|
20
27
|
* k = vSol_eff * vToken_eff where _eff = base * amp_bps / 10000
|
|
21
28
|
*/
|
|
22
|
-
|
|
23
|
-
const state = await getBondingCurveState(connection, tokenMint, programId);
|
|
29
|
+
async function getBuyQuote(connection, tokenMint, solIn, programId) {
|
|
30
|
+
const state = await (0, accounts_js_1.getBondingCurveState)(connection, tokenMint, programId);
|
|
24
31
|
if (!state || state.paused)
|
|
25
32
|
return null;
|
|
26
33
|
const feeBps = BigInt(state.feeBps);
|
|
@@ -46,8 +53,8 @@ export async function getBuyQuote(connection, tokenMint, solIn, programId) {
|
|
|
46
53
|
const newVSolEff = vSolEff + netCost;
|
|
47
54
|
const newVTokenEff = kDiv;
|
|
48
55
|
// Price impact
|
|
49
|
-
const priceBeforeLamports = vTokenEff > 0n ? (vSolEff * LAMPORTS_PER_SOL) / vTokenEff : 0n;
|
|
50
|
-
const priceAfterLamports = newVTokenEff > 0n ? (newVSolEff * LAMPORTS_PER_SOL) / newVTokenEff : 0n;
|
|
56
|
+
const priceBeforeLamports = vTokenEff > 0n ? (vSolEff * constants_js_1.LAMPORTS_PER_SOL) / vTokenEff : 0n;
|
|
57
|
+
const priceAfterLamports = newVTokenEff > 0n ? (newVSolEff * constants_js_1.LAMPORTS_PER_SOL) / newVTokenEff : 0n;
|
|
51
58
|
const priceImpactBps = priceBeforeLamports > 0n
|
|
52
59
|
? Number(((priceAfterLamports - priceBeforeLamports) * 10000n) / priceBeforeLamports)
|
|
53
60
|
: 0;
|
|
@@ -57,7 +64,7 @@ export async function getBuyQuote(connection, tokenMint, solIn, programId) {
|
|
|
57
64
|
adminFee,
|
|
58
65
|
creatorFee,
|
|
59
66
|
holderRewards,
|
|
60
|
-
pricePerToken: tokensOut > 0n ? (solIn * TOKEN_DECIMALS_MULTIPLIER) / tokensOut : 0n,
|
|
67
|
+
pricePerToken: tokensOut > 0n ? (solIn * constants_js_1.TOKEN_DECIMALS_MULTIPLIER) / tokensOut : 0n,
|
|
61
68
|
priceImpactBps,
|
|
62
69
|
};
|
|
63
70
|
}
|
|
@@ -65,8 +72,8 @@ export async function getBuyQuote(connection, tokenMint, solIn, programId) {
|
|
|
65
72
|
* Calculate sell quote for bonding curve
|
|
66
73
|
* Uses amplified constant product formula matching the program
|
|
67
74
|
*/
|
|
68
|
-
|
|
69
|
-
const state = await getBondingCurveState(connection, tokenMint, programId);
|
|
75
|
+
async function getSellQuote(connection, tokenMint, tokensIn, programId) {
|
|
76
|
+
const state = await (0, accounts_js_1.getBondingCurveState)(connection, tokenMint, programId);
|
|
70
77
|
if (!state || state.paused)
|
|
71
78
|
return null;
|
|
72
79
|
// Amplified constant product formula (matches program)
|
|
@@ -90,8 +97,8 @@ export async function getSellQuote(connection, tokenMint, tokensIn, programId) {
|
|
|
90
97
|
const newVTokenEff = denominator;
|
|
91
98
|
const newVSolEff = kDiv;
|
|
92
99
|
// Price impact
|
|
93
|
-
const priceBeforeLamports = vTokenEff > 0n ? (vSolEff * LAMPORTS_PER_SOL) / vTokenEff : 0n;
|
|
94
|
-
const priceAfterLamports = newVTokenEff > 0n ? (newVSolEff * LAMPORTS_PER_SOL) / newVTokenEff : 0n;
|
|
100
|
+
const priceBeforeLamports = vTokenEff > 0n ? (vSolEff * constants_js_1.LAMPORTS_PER_SOL) / vTokenEff : 0n;
|
|
101
|
+
const priceAfterLamports = newVTokenEff > 0n ? (newVSolEff * constants_js_1.LAMPORTS_PER_SOL) / newVTokenEff : 0n;
|
|
95
102
|
const priceImpactBps = priceBeforeLamports > 0n
|
|
96
103
|
? Number(((priceBeforeLamports - priceAfterLamports) * 10000n) / priceBeforeLamports)
|
|
97
104
|
: 0;
|
|
@@ -101,7 +108,7 @@ export async function getSellQuote(connection, tokenMint, tokensIn, programId) {
|
|
|
101
108
|
adminFee,
|
|
102
109
|
creatorFee,
|
|
103
110
|
holderRewards,
|
|
104
|
-
pricePerToken: tokensIn > 0n ? (solOutNetEff * TOKEN_DECIMALS_MULTIPLIER) / tokensIn : 0n,
|
|
111
|
+
pricePerToken: tokensIn > 0n ? (solOutNetEff * constants_js_1.TOKEN_DECIMALS_MULTIPLIER) / tokensIn : 0n,
|
|
105
112
|
priceImpactBps,
|
|
106
113
|
};
|
|
107
114
|
}
|
|
@@ -112,31 +119,31 @@ export async function getSellQuote(connection, tokenMint, tokensIn, programId) {
|
|
|
112
119
|
* IMPORTANT: Fee recipients are read from on-chain state and cannot be modified.
|
|
113
120
|
* The program enforces that fees go to the correct recipients.
|
|
114
121
|
*/
|
|
115
|
-
|
|
122
|
+
async function buildBuyOnCurveInstruction(connection, params, programId) {
|
|
116
123
|
const { tokenMint, buyer, lamportsIn } = params;
|
|
117
124
|
// Fetch curve state to get fee recipients (enforced on-chain)
|
|
118
|
-
const state = await getBondingCurveState(connection, tokenMint, programId);
|
|
125
|
+
const state = await (0, accounts_js_1.getBondingCurveState)(connection, tokenMint, programId);
|
|
119
126
|
if (!state) {
|
|
120
127
|
throw new Error('Bonding curve not found for this token');
|
|
121
128
|
}
|
|
122
129
|
if (state.paused) {
|
|
123
130
|
throw new Error('Bonding curve is paused');
|
|
124
131
|
}
|
|
125
|
-
const bondingCurve = getBondingCurvePda(tokenMint, programId);
|
|
126
|
-
const bondingAuthority = getBondingAuthorityPda(bondingCurve, programId);
|
|
127
|
-
const solEscrow = getSolEscrowPda(bondingCurve, programId);
|
|
128
|
-
const buyerAta = getAssociatedTokenAddressSync(tokenMint, buyer);
|
|
129
|
-
const holderRewardAccount = getHolderRewardPda(tokenMint, buyer, programId);
|
|
132
|
+
const bondingCurve = (0, pda_js_1.getBondingCurvePda)(tokenMint, programId);
|
|
133
|
+
const bondingAuthority = (0, pda_js_1.getBondingAuthorityPda)(bondingCurve, programId);
|
|
134
|
+
const solEscrow = (0, pda_js_1.getSolEscrowPda)(bondingCurve, programId);
|
|
135
|
+
const buyerAta = (0, spl_token_1.getAssociatedTokenAddressSync)(tokenMint, buyer);
|
|
136
|
+
const holderRewardAccount = (0, pda_js_1.getHolderRewardPda)(tokenMint, buyer, programId);
|
|
130
137
|
const instructions = [];
|
|
131
138
|
// Check if buyer's ATA exists, create if needed
|
|
132
139
|
try {
|
|
133
|
-
await getAccount(connection, buyerAta);
|
|
140
|
+
await (0, spl_token_1.getAccount)(connection, buyerAta);
|
|
134
141
|
}
|
|
135
142
|
catch {
|
|
136
|
-
instructions.push(createAssociatedTokenAccountInstruction(buyer, buyerAta, buyer, tokenMint));
|
|
143
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(buyer, buyerAta, buyer, tokenMint));
|
|
137
144
|
}
|
|
138
145
|
// Build buy instruction with fee recipients from on-chain state
|
|
139
|
-
const buyIx = new TransactionInstruction({
|
|
146
|
+
const buyIx = new web3_js_1.TransactionInstruction({
|
|
140
147
|
programId,
|
|
141
148
|
keys: [
|
|
142
149
|
{ pubkey: bondingCurve, isWritable: true, isSigner: false },
|
|
@@ -151,10 +158,10 @@ export async function buildBuyOnCurveInstruction(connection, params, programId)
|
|
|
151
158
|
{ pubkey: state.creatorFeeRecipient, isWritable: true, isSigner: false },
|
|
152
159
|
// Holder reward account - auto-initialized by program
|
|
153
160
|
{ pubkey: holderRewardAccount, isWritable: true, isSigner: false },
|
|
154
|
-
{ pubkey: TOKEN_PROGRAM_ID, isWritable: false, isSigner: false },
|
|
155
|
-
{ pubkey: SystemProgram.programId, isWritable: false, isSigner: false },
|
|
161
|
+
{ pubkey: spl_token_1.TOKEN_PROGRAM_ID, isWritable: false, isSigner: false },
|
|
162
|
+
{ pubkey: web3_js_1.SystemProgram.programId, isWritable: false, isSigner: false },
|
|
156
163
|
],
|
|
157
|
-
data: Buffer.concat([DISCRIMINATORS.buy_on_curve, writeU64LE(lamportsIn)]),
|
|
164
|
+
data: Buffer.concat([constants_js_1.DISCRIMINATORS.buy_on_curve, writeU64LE(lamportsIn)]),
|
|
158
165
|
});
|
|
159
166
|
instructions.push(buyIx);
|
|
160
167
|
return instructions;
|
|
@@ -165,22 +172,22 @@ export async function buildBuyOnCurveInstruction(connection, params, programId)
|
|
|
165
172
|
* IMPORTANT: Fee recipients are read from on-chain state and cannot be modified.
|
|
166
173
|
* Includes holder reward account in remaining_accounts for auto-payout.
|
|
167
174
|
*/
|
|
168
|
-
|
|
175
|
+
async function buildSellOnCurveInstruction(connection, params, programId) {
|
|
169
176
|
const { tokenMint, seller, tokenAmount } = params;
|
|
170
177
|
// Fetch curve state to get fee recipients (enforced on-chain)
|
|
171
|
-
const state = await getBondingCurveState(connection, tokenMint, programId);
|
|
178
|
+
const state = await (0, accounts_js_1.getBondingCurveState)(connection, tokenMint, programId);
|
|
172
179
|
if (!state) {
|
|
173
180
|
throw new Error('Bonding curve not found for this token');
|
|
174
181
|
}
|
|
175
182
|
if (state.paused) {
|
|
176
183
|
throw new Error('Bonding curve is paused');
|
|
177
184
|
}
|
|
178
|
-
const bondingCurve = getBondingCurvePda(tokenMint, programId);
|
|
179
|
-
const bondingAuthority = getBondingAuthorityPda(bondingCurve, programId);
|
|
180
|
-
const solEscrow = getSolEscrowPda(bondingCurve, programId);
|
|
181
|
-
const sellerAta = getAssociatedTokenAddressSync(tokenMint, seller);
|
|
182
|
-
const holderRewardAccount = getHolderRewardPda(tokenMint, seller, programId);
|
|
183
|
-
const sellIx = new TransactionInstruction({
|
|
185
|
+
const bondingCurve = (0, pda_js_1.getBondingCurvePda)(tokenMint, programId);
|
|
186
|
+
const bondingAuthority = (0, pda_js_1.getBondingAuthorityPda)(bondingCurve, programId);
|
|
187
|
+
const solEscrow = (0, pda_js_1.getSolEscrowPda)(bondingCurve, programId);
|
|
188
|
+
const sellerAta = (0, spl_token_1.getAssociatedTokenAddressSync)(tokenMint, seller);
|
|
189
|
+
const holderRewardAccount = (0, pda_js_1.getHolderRewardPda)(tokenMint, seller, programId);
|
|
190
|
+
const sellIx = new web3_js_1.TransactionInstruction({
|
|
184
191
|
programId,
|
|
185
192
|
keys: [
|
|
186
193
|
{ pubkey: bondingCurve, isWritable: true, isSigner: false },
|
|
@@ -193,12 +200,12 @@ export async function buildSellOnCurveInstruction(connection, params, programId)
|
|
|
193
200
|
// Fee recipients - read from on-chain state, cannot be modified
|
|
194
201
|
{ pubkey: state.adminFeeRecipient, isWritable: true, isSigner: false },
|
|
195
202
|
{ pubkey: state.creatorFeeRecipient, isWritable: true, isSigner: false },
|
|
196
|
-
{ pubkey: TOKEN_PROGRAM_ID, isWritable: false, isSigner: false },
|
|
197
|
-
{ pubkey: SystemProgram.programId, isWritable: false, isSigner: false },
|
|
203
|
+
{ pubkey: spl_token_1.TOKEN_PROGRAM_ID, isWritable: false, isSigner: false },
|
|
204
|
+
{ pubkey: web3_js_1.SystemProgram.programId, isWritable: false, isSigner: false },
|
|
198
205
|
// Holder reward account in remaining_accounts for auto-payout
|
|
199
206
|
{ pubkey: holderRewardAccount, isWritable: true, isSigner: false },
|
|
200
207
|
],
|
|
201
|
-
data: Buffer.concat([DISCRIMINATORS.sell_on_curve, writeU64LE(tokenAmount)]),
|
|
208
|
+
data: Buffer.concat([constants_js_1.DISCRIMINATORS.sell_on_curve, writeU64LE(tokenAmount)]),
|
|
202
209
|
});
|
|
203
210
|
return [sellIx];
|
|
204
211
|
}
|
|
@@ -206,22 +213,22 @@ export async function buildSellOnCurveInstruction(connection, params, programId)
|
|
|
206
213
|
* Build sell_max_on_curve instruction (sell entire balance)
|
|
207
214
|
* Includes holder reward account in remaining_accounts for auto-payout.
|
|
208
215
|
*/
|
|
209
|
-
|
|
216
|
+
async function buildSellMaxOnCurveInstruction(connection, params, programId) {
|
|
210
217
|
const { tokenMint, seller } = params;
|
|
211
218
|
// Fetch curve state to get fee recipients (enforced on-chain)
|
|
212
|
-
const state = await getBondingCurveState(connection, tokenMint, programId);
|
|
219
|
+
const state = await (0, accounts_js_1.getBondingCurveState)(connection, tokenMint, programId);
|
|
213
220
|
if (!state) {
|
|
214
221
|
throw new Error('Bonding curve not found for this token');
|
|
215
222
|
}
|
|
216
223
|
if (state.paused) {
|
|
217
224
|
throw new Error('Bonding curve is paused');
|
|
218
225
|
}
|
|
219
|
-
const bondingCurve = getBondingCurvePda(tokenMint, programId);
|
|
220
|
-
const bondingAuthority = getBondingAuthorityPda(bondingCurve, programId);
|
|
221
|
-
const solEscrow = getSolEscrowPda(bondingCurve, programId);
|
|
222
|
-
const sellerAta = getAssociatedTokenAddressSync(tokenMint, seller);
|
|
223
|
-
const holderRewardAccount = getHolderRewardPda(tokenMint, seller, programId);
|
|
224
|
-
const sellMaxIx = new TransactionInstruction({
|
|
226
|
+
const bondingCurve = (0, pda_js_1.getBondingCurvePda)(tokenMint, programId);
|
|
227
|
+
const bondingAuthority = (0, pda_js_1.getBondingAuthorityPda)(bondingCurve, programId);
|
|
228
|
+
const solEscrow = (0, pda_js_1.getSolEscrowPda)(bondingCurve, programId);
|
|
229
|
+
const sellerAta = (0, spl_token_1.getAssociatedTokenAddressSync)(tokenMint, seller);
|
|
230
|
+
const holderRewardAccount = (0, pda_js_1.getHolderRewardPda)(tokenMint, seller, programId);
|
|
231
|
+
const sellMaxIx = new web3_js_1.TransactionInstruction({
|
|
225
232
|
programId,
|
|
226
233
|
keys: [
|
|
227
234
|
{ pubkey: bondingCurve, isWritable: true, isSigner: false },
|
|
@@ -234,13 +241,12 @@ export async function buildSellMaxOnCurveInstruction(connection, params, program
|
|
|
234
241
|
// Fee recipients - read from on-chain state, cannot be modified
|
|
235
242
|
{ pubkey: state.adminFeeRecipient, isWritable: true, isSigner: false },
|
|
236
243
|
{ pubkey: state.creatorFeeRecipient, isWritable: true, isSigner: false },
|
|
237
|
-
{ pubkey: TOKEN_PROGRAM_ID, isWritable: false, isSigner: false },
|
|
238
|
-
{ pubkey: SystemProgram.programId, isWritable: false, isSigner: false },
|
|
244
|
+
{ pubkey: spl_token_1.TOKEN_PROGRAM_ID, isWritable: false, isSigner: false },
|
|
245
|
+
{ pubkey: web3_js_1.SystemProgram.programId, isWritable: false, isSigner: false },
|
|
239
246
|
// Holder reward account in remaining_accounts for auto-payout
|
|
240
247
|
{ pubkey: holderRewardAccount, isWritable: true, isSigner: false },
|
|
241
248
|
],
|
|
242
|
-
data: DISCRIMINATORS.sell_max_on_curve,
|
|
249
|
+
data: constants_js_1.DISCRIMINATORS.sell_max_on_curve,
|
|
243
250
|
});
|
|
244
251
|
return [sellMaxIx];
|
|
245
252
|
}
|
|
246
|
-
//# sourceMappingURL=curve.js.map
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* CoinBarrel SDK
|
|
3
4
|
*
|
|
@@ -26,18 +27,82 @@
|
|
|
26
27
|
*
|
|
27
28
|
* @packageDocumentation
|
|
28
29
|
*/
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
31
|
+
if (k2 === undefined) k2 = k;
|
|
32
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
33
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
34
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
35
|
+
}
|
|
36
|
+
Object.defineProperty(o, k2, desc);
|
|
37
|
+
}) : (function(o, m, k, k2) {
|
|
38
|
+
if (k2 === undefined) k2 = k;
|
|
39
|
+
o[k2] = m[k];
|
|
40
|
+
}));
|
|
41
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
42
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
43
|
+
}) : function(o, v) {
|
|
44
|
+
o["default"] = v;
|
|
45
|
+
});
|
|
46
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
47
|
+
var ownKeys = function(o) {
|
|
48
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
49
|
+
var ar = [];
|
|
50
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
51
|
+
return ar;
|
|
52
|
+
};
|
|
53
|
+
return ownKeys(o);
|
|
54
|
+
};
|
|
55
|
+
return function (mod) {
|
|
56
|
+
if (mod && mod.__esModule) return mod;
|
|
57
|
+
var result = {};
|
|
58
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
59
|
+
__setModuleDefault(result, mod);
|
|
60
|
+
return result;
|
|
61
|
+
};
|
|
62
|
+
})();
|
|
63
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
64
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
65
|
+
};
|
|
66
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
67
|
+
exports.CoinBarrel = exports.buildClaimHolderRewardsInstruction = exports.buildClaimHolderRewardsCurveInstruction = exports.buildCreateBarrelTokenInstruction = exports.parseMetaplexMetadata = exports.getMetadataPda = exports.batchGetTokenMetadata = exports.getTokenMetadataJson = exports.getTokenMetadata = exports.getSwapTokenToSolQuote = exports.getSwapSolToTokenQuote = exports.getSellQuote = exports.getBuyQuote = exports.getUserTokenBalance = exports.getMarketInfo = exports.getPoolState = exports.getBondingCurveState = void 0;
|
|
68
|
+
exports.solToLamports = solToLamports;
|
|
69
|
+
exports.lamportsToSol = lamportsToSol;
|
|
70
|
+
exports.toRawAmount = toRawAmount;
|
|
71
|
+
exports.toUiAmount = toUiAmount;
|
|
72
|
+
const constants_js_1 = require("./constants.js");
|
|
73
|
+
const pda = __importStar(require("./pda.js"));
|
|
74
|
+
const accounts = __importStar(require("./accounts.js"));
|
|
75
|
+
const curve = __importStar(require("./curve.js"));
|
|
76
|
+
const pool = __importStar(require("./pool.js"));
|
|
77
|
+
const metadata = __importStar(require("./metadata.js"));
|
|
78
|
+
const create = __importStar(require("./create.js"));
|
|
79
|
+
const rewards = __importStar(require("./rewards.js"));
|
|
34
80
|
// ============= Re-exports =============
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
81
|
+
__exportStar(require("./constants.js"), exports);
|
|
82
|
+
__exportStar(require("./types.js"), exports);
|
|
83
|
+
__exportStar(require("./pda.js"), exports);
|
|
84
|
+
var accounts_js_1 = require("./accounts.js");
|
|
85
|
+
Object.defineProperty(exports, "getBondingCurveState", { enumerable: true, get: function () { return accounts_js_1.getBondingCurveState; } });
|
|
86
|
+
Object.defineProperty(exports, "getPoolState", { enumerable: true, get: function () { return accounts_js_1.getPoolState; } });
|
|
87
|
+
Object.defineProperty(exports, "getMarketInfo", { enumerable: true, get: function () { return accounts_js_1.getMarketInfo; } });
|
|
88
|
+
Object.defineProperty(exports, "getUserTokenBalance", { enumerable: true, get: function () { return accounts_js_1.getUserTokenBalance; } });
|
|
89
|
+
var curve_js_1 = require("./curve.js");
|
|
90
|
+
Object.defineProperty(exports, "getBuyQuote", { enumerable: true, get: function () { return curve_js_1.getBuyQuote; } });
|
|
91
|
+
Object.defineProperty(exports, "getSellQuote", { enumerable: true, get: function () { return curve_js_1.getSellQuote; } });
|
|
92
|
+
var pool_js_1 = require("./pool.js");
|
|
93
|
+
Object.defineProperty(exports, "getSwapSolToTokenQuote", { enumerable: true, get: function () { return pool_js_1.getSwapSolToTokenQuote; } });
|
|
94
|
+
Object.defineProperty(exports, "getSwapTokenToSolQuote", { enumerable: true, get: function () { return pool_js_1.getSwapTokenToSolQuote; } });
|
|
95
|
+
var metadata_js_1 = require("./metadata.js");
|
|
96
|
+
Object.defineProperty(exports, "getTokenMetadata", { enumerable: true, get: function () { return metadata_js_1.getTokenMetadata; } });
|
|
97
|
+
Object.defineProperty(exports, "getTokenMetadataJson", { enumerable: true, get: function () { return metadata_js_1.getTokenMetadataJson; } });
|
|
98
|
+
Object.defineProperty(exports, "batchGetTokenMetadata", { enumerable: true, get: function () { return metadata_js_1.batchGetTokenMetadata; } });
|
|
99
|
+
Object.defineProperty(exports, "getMetadataPda", { enumerable: true, get: function () { return metadata_js_1.getMetadataPda; } });
|
|
100
|
+
Object.defineProperty(exports, "parseMetaplexMetadata", { enumerable: true, get: function () { return metadata_js_1.parseMetaplexMetadata; } });
|
|
101
|
+
var create_js_1 = require("./create.js");
|
|
102
|
+
Object.defineProperty(exports, "buildCreateBarrelTokenInstruction", { enumerable: true, get: function () { return create_js_1.buildCreateBarrelTokenInstruction; } });
|
|
103
|
+
var rewards_js_1 = require("./rewards.js");
|
|
104
|
+
Object.defineProperty(exports, "buildClaimHolderRewardsCurveInstruction", { enumerable: true, get: function () { return rewards_js_1.buildClaimHolderRewardsCurveInstruction; } });
|
|
105
|
+
Object.defineProperty(exports, "buildClaimHolderRewardsInstruction", { enumerable: true, get: function () { return rewards_js_1.buildClaimHolderRewardsInstruction; } });
|
|
41
106
|
// ============= SDK Class =============
|
|
42
107
|
/**
|
|
43
108
|
* CoinBarrel SDK - Main entry point
|
|
@@ -51,7 +116,7 @@ export { getSwapSolToTokenQuote, getSwapTokenToSolQuote } from "./pool.js";
|
|
|
51
116
|
* Fee recipients are read from on-chain state and cannot be modified.
|
|
52
117
|
* The program enforces that all fees go to the correct recipients.
|
|
53
118
|
*/
|
|
54
|
-
|
|
119
|
+
class CoinBarrel {
|
|
55
120
|
/** Solana RPC connection */
|
|
56
121
|
connection;
|
|
57
122
|
/** Network (devnet or mainnet) */
|
|
@@ -67,8 +132,8 @@ export class CoinBarrel {
|
|
|
67
132
|
constructor(config) {
|
|
68
133
|
this.connection = config.connection;
|
|
69
134
|
this.network = config.network;
|
|
70
|
-
this.programId = PROGRAM_IDS[config.network];
|
|
71
|
-
this.adminFeeRecipient = ADMIN_FEE_RECIPIENTS[config.network];
|
|
135
|
+
this.programId = constants_js_1.PROGRAM_IDS[config.network];
|
|
136
|
+
this.adminFeeRecipient = constants_js_1.ADMIN_FEE_RECIPIENTS[config.network];
|
|
72
137
|
this.curve = new CurveModule(this);
|
|
73
138
|
this.pool = new PoolModule(this);
|
|
74
139
|
}
|
|
@@ -103,6 +168,43 @@ export class CoinBarrel {
|
|
|
103
168
|
const poolState = await accounts.getPoolState(this.connection, tokenMint, this.programId);
|
|
104
169
|
return poolState !== null;
|
|
105
170
|
}
|
|
171
|
+
// ============= Token Metadata =============
|
|
172
|
+
/**
|
|
173
|
+
* Get on-chain token metadata (name, symbol, uri)
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```typescript
|
|
177
|
+
* const meta = await sdk.getTokenMetadata(tokenMint);
|
|
178
|
+
* console.log(meta?.name, meta?.symbol);
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
async getTokenMetadata(tokenMint) {
|
|
182
|
+
return metadata.getTokenMetadata(this.connection, tokenMint);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Get full token metadata including off-chain JSON (image, description, socials)
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```typescript
|
|
189
|
+
* const meta = await sdk.getTokenMetadataJson(tokenMint);
|
|
190
|
+
* console.log(meta?.name, meta?.image, meta?.twitter);
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
async getTokenMetadataJson(tokenMint, options) {
|
|
194
|
+
return metadata.getTokenMetadataJson(this.connection, tokenMint, options);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Batch fetch metadata for multiple tokens (more efficient)
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```typescript
|
|
201
|
+
* const mints = [mint1, mint2, mint3];
|
|
202
|
+
* const metadataMap = await sdk.batchGetTokenMetadata(mints);
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
async batchGetTokenMetadata(mints) {
|
|
206
|
+
return metadata.batchGetTokenMetadata(this.connection, mints);
|
|
207
|
+
}
|
|
106
208
|
// ============= PDA Helpers =============
|
|
107
209
|
/** Get bonding curve PDA for a token */
|
|
108
210
|
getBondingCurvePda(tokenMint) {
|
|
@@ -116,7 +218,52 @@ export class CoinBarrel {
|
|
|
116
218
|
getHolderRewardPda(tokenMint, holder) {
|
|
117
219
|
return pda.getHolderRewardPda(tokenMint, holder, this.programId);
|
|
118
220
|
}
|
|
221
|
+
/** Get Metaplex metadata PDA for a token */
|
|
222
|
+
getMetadataPda(tokenMint) {
|
|
223
|
+
return metadata.getMetadataPda(tokenMint);
|
|
224
|
+
}
|
|
225
|
+
// ============= Token Creation =============
|
|
226
|
+
/**
|
|
227
|
+
* Build create barrel token instruction
|
|
228
|
+
*
|
|
229
|
+
* Creates a new token with atomically revoked mint/freeze authority.
|
|
230
|
+
* Returns the instruction and a mint keypair that must sign the transaction.
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* ```typescript
|
|
234
|
+
* const { instructions, mintKeypair } = sdk.buildCreateTokenInstruction({
|
|
235
|
+
* payer: wallet.publicKey,
|
|
236
|
+
* name: "My Token",
|
|
237
|
+
* symbol: "MTK",
|
|
238
|
+
* uri: "https://...",
|
|
239
|
+
* creatorFeeRecipient: wallet.publicKey,
|
|
240
|
+
* });
|
|
241
|
+
*
|
|
242
|
+
* // Add mintKeypair as signer when sending transaction
|
|
243
|
+
* ```
|
|
244
|
+
*/
|
|
245
|
+
buildCreateTokenInstruction(params) {
|
|
246
|
+
return create.buildCreateBarrelTokenInstruction(params, this.programId, this.network);
|
|
247
|
+
}
|
|
248
|
+
// ============= Rewards =============
|
|
249
|
+
/**
|
|
250
|
+
* Build claim holder rewards instruction for bonding curve
|
|
251
|
+
*
|
|
252
|
+
* Claims accumulated holder rewards paid in SOL.
|
|
253
|
+
*/
|
|
254
|
+
async buildClaimRewardsCurveInstruction(tokenMint, holder) {
|
|
255
|
+
return rewards.buildClaimHolderRewardsCurveInstruction(this.connection, { tokenMint, holder }, this.programId);
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Build claim holder rewards instruction for AMM pool
|
|
259
|
+
*
|
|
260
|
+
* Claims accumulated holder rewards (WSOL unwrapped to SOL).
|
|
261
|
+
*/
|
|
262
|
+
async buildClaimRewardsPoolInstruction(tokenMint, holder) {
|
|
263
|
+
return rewards.buildClaimHolderRewardsInstruction(this.connection, { tokenMint, holder }, this.programId);
|
|
264
|
+
}
|
|
119
265
|
}
|
|
266
|
+
exports.CoinBarrel = CoinBarrel;
|
|
120
267
|
// ============= Curve Module =============
|
|
121
268
|
/**
|
|
122
269
|
* Bonding Curve Operations
|
|
@@ -230,25 +377,24 @@ class PoolModule {
|
|
|
230
377
|
/**
|
|
231
378
|
* Convert SOL to lamports
|
|
232
379
|
*/
|
|
233
|
-
|
|
234
|
-
return BigInt(Math.floor(sol * Number(LAMPORTS_PER_SOL)));
|
|
380
|
+
function solToLamports(sol) {
|
|
381
|
+
return BigInt(Math.floor(sol * Number(constants_js_1.LAMPORTS_PER_SOL)));
|
|
235
382
|
}
|
|
236
383
|
/**
|
|
237
384
|
* Convert lamports to SOL
|
|
238
385
|
*/
|
|
239
|
-
|
|
240
|
-
return Number(lamports) / Number(LAMPORTS_PER_SOL);
|
|
386
|
+
function lamportsToSol(lamports) {
|
|
387
|
+
return Number(lamports) / Number(constants_js_1.LAMPORTS_PER_SOL);
|
|
241
388
|
}
|
|
242
389
|
/**
|
|
243
390
|
* Convert token amount to raw (with decimals)
|
|
244
391
|
*/
|
|
245
|
-
|
|
392
|
+
function toRawAmount(amount, decimals = 6) {
|
|
246
393
|
return BigInt(Math.floor(amount * 10 ** decimals));
|
|
247
394
|
}
|
|
248
395
|
/**
|
|
249
396
|
* Convert raw amount to UI (without decimals)
|
|
250
397
|
*/
|
|
251
|
-
|
|
398
|
+
function toUiAmount(rawAmount, decimals = 6) {
|
|
252
399
|
return Number(rawAmount) / 10 ** decimals;
|
|
253
400
|
}
|
|
254
|
-
//# sourceMappingURL=index.js.map
|