@coinbarrel/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 +220 -0
- package/dist/accounts.d.ts +35 -0
- package/dist/accounts.d.ts.map +1 -0
- package/dist/accounts.js +185 -0
- package/dist/accounts.js.map +1 -0
- package/dist/constants.d.ts +79 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +96 -0
- package/dist/constants.js.map +1 -0
- package/dist/curve.d.ts +33 -0
- package/dist/curve.d.ts.map +1 -0
- package/dist/curve.js +218 -0
- package/dist/curve.js.map +1 -0
- package/dist/index.d.ts +184 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +254 -0
- package/dist/index.js.map +1 -0
- package/dist/pda.d.ts +51 -0
- package/dist/pda.d.ts.map +1 -0
- package/dist/pda.js +86 -0
- package/dist/pda.js.map +1 -0
- package/dist/pool.d.ts +32 -0
- package/dist/pool.d.ts.map +1 -0
- package/dist/pool.js +242 -0
- package/dist/pool.js.map +1 -0
- package/dist/types.d.ts +162 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/package.json +45 -0
package/README.md
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
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
|
+
## Market Info
|
|
120
|
+
|
|
121
|
+
### Get Token Market State
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
const info = await sdk.getMarketInfo(tokenMint);
|
|
125
|
+
|
|
126
|
+
if (info) {
|
|
127
|
+
console.log(`Phase: ${info.phase}`); // 'curve' or 'pool'
|
|
128
|
+
console.log(`Price: ${info.price} lamports/token`);
|
|
129
|
+
console.log(`Market Cap: ${info.marketCapSol} lamports`);
|
|
130
|
+
console.log(`Fee: ${info.feeBps / 100}%`);
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Check Token Phase
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
if (await sdk.isOnCurve(tokenMint)) {
|
|
138
|
+
// Use curve methods
|
|
139
|
+
} else if (await sdk.isOnPool(tokenMint)) {
|
|
140
|
+
// Use pool methods
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Networks
|
|
145
|
+
|
|
146
|
+
The SDK supports both devnet and mainnet:
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
// Devnet
|
|
150
|
+
const devnetSdk = new CoinBarrel({
|
|
151
|
+
connection: new Connection('https://api.devnet.solana.com'),
|
|
152
|
+
network: 'devnet'
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
// Mainnet
|
|
156
|
+
const mainnetSdk = new CoinBarrel({
|
|
157
|
+
connection: new Connection('https://api.mainnet-beta.solana.com'),
|
|
158
|
+
network: 'mainnet'
|
|
159
|
+
});
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Utility Functions
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
import {
|
|
166
|
+
solToLamports,
|
|
167
|
+
lamportsToSol,
|
|
168
|
+
toRawAmount,
|
|
169
|
+
toUiAmount
|
|
170
|
+
} from '@coinbarrel/sdk';
|
|
171
|
+
|
|
172
|
+
// SOL conversions
|
|
173
|
+
const lamports = solToLamports(1.5); // 1_500_000_000n
|
|
174
|
+
const sol = lamportsToSol(1_500_000_000n); // 1.5
|
|
175
|
+
|
|
176
|
+
// Token amount conversions (default 6 decimals)
|
|
177
|
+
const raw = toRawAmount(100); // 100_000_000n
|
|
178
|
+
const ui = toUiAmount(100_000_000n); // 100
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## PDA Helpers
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
// Get PDAs for a token
|
|
185
|
+
const bondingCurve = sdk.getBondingCurvePda(tokenMint);
|
|
186
|
+
const pool = sdk.getPoolPda(tokenMint);
|
|
187
|
+
const holderReward = sdk.getHolderRewardPda(tokenMint, wallet.publicKey);
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## Fee Structure
|
|
191
|
+
|
|
192
|
+
CoinBarrel fees are enforced at the program level and cannot be bypassed:
|
|
193
|
+
|
|
194
|
+
- **1% total fee** on all trades
|
|
195
|
+
- **40%** goes to CoinBarrel (protocol)
|
|
196
|
+
- **30%** goes to token creator
|
|
197
|
+
- **30%** goes to holder rewards pool
|
|
198
|
+
|
|
199
|
+
The SDK reads fee recipients from on-chain state. Integrators cannot modify or bypass fees.
|
|
200
|
+
|
|
201
|
+
## TypeScript
|
|
202
|
+
|
|
203
|
+
The SDK is fully typed:
|
|
204
|
+
|
|
205
|
+
```typescript
|
|
206
|
+
import type {
|
|
207
|
+
BondingCurveState,
|
|
208
|
+
PoolState,
|
|
209
|
+
MarketInfo,
|
|
210
|
+
BuyQuote,
|
|
211
|
+
SellQuote,
|
|
212
|
+
SwapQuote,
|
|
213
|
+
Network
|
|
214
|
+
} from '@coinbarrel/sdk';
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## License
|
|
218
|
+
|
|
219
|
+
MIT
|
|
220
|
+
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Account Fetching and Parsing
|
|
3
|
+
* Read on-chain account data for bonding curves and pools
|
|
4
|
+
*/
|
|
5
|
+
import { Connection, PublicKey } from '@solana/web3.js';
|
|
6
|
+
import type { BondingCurveState, PoolState, MarketInfo } from './types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Fetch and parse bonding curve state
|
|
9
|
+
*/
|
|
10
|
+
export declare function getBondingCurveState(connection: Connection, tokenMint: PublicKey, programId: PublicKey): Promise<BondingCurveState | null>;
|
|
11
|
+
/**
|
|
12
|
+
* Get SOL balance in bonding curve escrow
|
|
13
|
+
*/
|
|
14
|
+
export declare function getCurveSolBalance(connection: Connection, tokenMint: PublicKey, programId: PublicKey): Promise<bigint>;
|
|
15
|
+
/**
|
|
16
|
+
* Fetch and parse pool state
|
|
17
|
+
*/
|
|
18
|
+
export declare function getPoolState(connection: Connection, tokenMint: PublicKey, programId: PublicKey): Promise<PoolState | null>;
|
|
19
|
+
/**
|
|
20
|
+
* Get pool vault balances
|
|
21
|
+
*/
|
|
22
|
+
export declare function getPoolBalances(connection: Connection, tokenMint: PublicKey, programId: PublicKey): Promise<{
|
|
23
|
+
solBalance: bigint;
|
|
24
|
+
tokenBalance: bigint;
|
|
25
|
+
} | null>;
|
|
26
|
+
/**
|
|
27
|
+
* Get comprehensive market info for a token
|
|
28
|
+
* Automatically detects if on bonding curve or AMM pool
|
|
29
|
+
*/
|
|
30
|
+
export declare function getMarketInfo(connection: Connection, tokenMint: PublicKey, programId: PublicKey): Promise<MarketInfo | null>;
|
|
31
|
+
/**
|
|
32
|
+
* Get user's token balance
|
|
33
|
+
*/
|
|
34
|
+
export declare function getUserTokenBalance(connection: Connection, tokenMint: PublicKey, user: PublicKey): Promise<bigint>;
|
|
35
|
+
//# sourceMappingURL=accounts.d.ts.map
|
|
@@ -0,0 +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;AAUxD,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,CA4BnC;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;;GAEG;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,CAkB9D;AAID;;;GAGG;AACH,wBAAsB,aAAa,CAClC,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,SAAS,EACpB,SAAS,EAAE,SAAS,GAClB,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAgE5B;AAED;;GAEG;AACH,wBAAsB,mBAAmB,CACxC,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE,SAAS,GACb,OAAO,CAAC,MAAM,CAAC,CAQjB"}
|
package/dist/accounts.js
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Account Fetching and Parsing
|
|
3
|
+
* Read on-chain account data for bonding curves and pools
|
|
4
|
+
*/
|
|
5
|
+
import { PublicKey } from '@solana/web3.js';
|
|
6
|
+
import { getAssociatedTokenAddressSync, getAccount } from '@solana/spl-token';
|
|
7
|
+
import { BONDING_CURVE_OFFSETS, POOL_OFFSETS, LAMPORTS_PER_SOL } from './constants.js';
|
|
8
|
+
import { getBondingCurvePda, getPoolPda, getSolEscrowPda, getPoolWsolVaultPda, getPoolTokenVaultPda, } from './pda.js';
|
|
9
|
+
// ============= Buffer Helpers =============
|
|
10
|
+
function readU16LE(data, offset) {
|
|
11
|
+
return data.readUInt16LE(offset);
|
|
12
|
+
}
|
|
13
|
+
function readU64LE(data, offset) {
|
|
14
|
+
return data.readBigUInt64LE(offset);
|
|
15
|
+
}
|
|
16
|
+
function readU128LE(data, offset) {
|
|
17
|
+
const low = data.readBigUInt64LE(offset);
|
|
18
|
+
const high = data.readBigUInt64LE(offset + 8);
|
|
19
|
+
return low + (high << 64n);
|
|
20
|
+
}
|
|
21
|
+
function readPubkey(data, offset) {
|
|
22
|
+
return new PublicKey(data.subarray(offset, offset + 32));
|
|
23
|
+
}
|
|
24
|
+
function readBool(data, offset) {
|
|
25
|
+
return data[offset] !== 0;
|
|
26
|
+
}
|
|
27
|
+
// ============= Bonding Curve =============
|
|
28
|
+
/**
|
|
29
|
+
* Fetch and parse bonding curve state
|
|
30
|
+
*/
|
|
31
|
+
export async function getBondingCurveState(connection, tokenMint, programId) {
|
|
32
|
+
const bondingCurve = getBondingCurvePda(tokenMint, programId);
|
|
33
|
+
const accountInfo = await connection.getAccountInfo(bondingCurve);
|
|
34
|
+
if (!accountInfo || accountInfo.data.length < 209) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
const data = accountInfo.data;
|
|
38
|
+
const O = BONDING_CURVE_OFFSETS;
|
|
39
|
+
return {
|
|
40
|
+
tokenMint: readPubkey(data, O.TOKEN_MINT),
|
|
41
|
+
tokenVault: readPubkey(data, O.TOKEN_VAULT),
|
|
42
|
+
adminFeeRecipient: readPubkey(data, O.ADMIN_FEE_RECIPIENT),
|
|
43
|
+
creatorFeeRecipient: readPubkey(data, O.CREATOR_FEE_RECIPIENT),
|
|
44
|
+
feeBps: readU16LE(data, O.FEE_BPS),
|
|
45
|
+
variant: data[O.VARIANT],
|
|
46
|
+
bump: data[O.BUMP],
|
|
47
|
+
vToken: readU128LE(data, O.V_TOKEN),
|
|
48
|
+
vSol: readU128LE(data, O.V_SOL),
|
|
49
|
+
ampBps: readU16LE(data, O.AMP_BPS),
|
|
50
|
+
traderRewardsShareBps: readU16LE(data, O.TRADER_REWARDS_SHARE_BPS),
|
|
51
|
+
minPriceLamportsPerToken: readU64LE(data, O.MIN_PRICE),
|
|
52
|
+
maxSupply: readU128LE(data, O.MAX_SUPPLY),
|
|
53
|
+
totalSold: readU128LE(data, O.TOTAL_SOLD),
|
|
54
|
+
paused: readBool(data, O.PAUSED),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Get SOL balance in bonding curve escrow
|
|
59
|
+
*/
|
|
60
|
+
export async function getCurveSolBalance(connection, tokenMint, programId) {
|
|
61
|
+
const bondingCurve = getBondingCurvePda(tokenMint, programId);
|
|
62
|
+
const solEscrow = getSolEscrowPda(bondingCurve, programId);
|
|
63
|
+
const balance = await connection.getBalance(solEscrow);
|
|
64
|
+
return BigInt(balance);
|
|
65
|
+
}
|
|
66
|
+
// ============= AMM Pool =============
|
|
67
|
+
/**
|
|
68
|
+
* Fetch and parse pool state
|
|
69
|
+
*/
|
|
70
|
+
export async function getPoolState(connection, tokenMint, programId) {
|
|
71
|
+
const pool = getPoolPda(tokenMint, programId);
|
|
72
|
+
const accountInfo = await connection.getAccountInfo(pool);
|
|
73
|
+
if (!accountInfo || accountInfo.data.length < 269) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
const data = accountInfo.data;
|
|
77
|
+
const O = POOL_OFFSETS;
|
|
78
|
+
return {
|
|
79
|
+
tokenAMint: readPubkey(data, O.TOKEN_A_MINT),
|
|
80
|
+
tokenBMint: readPubkey(data, O.TOKEN_B_MINT),
|
|
81
|
+
tokenAVault: readPubkey(data, O.TOKEN_A_VAULT),
|
|
82
|
+
tokenBVault: readPubkey(data, O.TOKEN_B_VAULT),
|
|
83
|
+
lpMint: readPubkey(data, O.LP_MINT),
|
|
84
|
+
feeRate: readU64LE(data, O.FEE_RATE),
|
|
85
|
+
authority: readPubkey(data, O.AUTHORITY),
|
|
86
|
+
bump: data[O.BUMP],
|
|
87
|
+
isLocked: readBool(data, O.IS_LOCKED),
|
|
88
|
+
poolType: data[O.POOL_TYPE],
|
|
89
|
+
traderRewardsShareBps: readU16LE(data, O.TRADER_REWARDS_SHARE_BPS),
|
|
90
|
+
adminFeeRecipient: readPubkey(data, O.ADMIN_FEE_RECIPIENT),
|
|
91
|
+
creatorFeeRecipient: readPubkey(data, O.CREATOR_FEE_RECIPIENT),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Get pool vault balances
|
|
96
|
+
*/
|
|
97
|
+
export async function getPoolBalances(connection, tokenMint, programId) {
|
|
98
|
+
const pool = getPoolPda(tokenMint, programId);
|
|
99
|
+
const wsolVault = getPoolWsolVaultPda(pool, programId);
|
|
100
|
+
const tokenVault = getPoolTokenVaultPda(pool, tokenMint, programId);
|
|
101
|
+
try {
|
|
102
|
+
const [wsolAccount, tokenAccount] = await Promise.all([
|
|
103
|
+
getAccount(connection, wsolVault),
|
|
104
|
+
getAccount(connection, tokenVault),
|
|
105
|
+
]);
|
|
106
|
+
return {
|
|
107
|
+
solBalance: wsolAccount.amount,
|
|
108
|
+
tokenBalance: tokenAccount.amount,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
// ============= Market Info =============
|
|
116
|
+
/**
|
|
117
|
+
* Get comprehensive market info for a token
|
|
118
|
+
* Automatically detects if on bonding curve or AMM pool
|
|
119
|
+
*/
|
|
120
|
+
export async function getMarketInfo(connection, tokenMint, programId) {
|
|
121
|
+
// Try bonding curve first
|
|
122
|
+
const curveState = await getBondingCurveState(connection, tokenMint, programId);
|
|
123
|
+
if (curveState && !curveState.paused) {
|
|
124
|
+
// Check if curve has been migrated (total_sold >= max_supply means graduated)
|
|
125
|
+
if (curveState.totalSold < curveState.maxSupply) {
|
|
126
|
+
// Still on bonding curve
|
|
127
|
+
const solBalance = await getCurveSolBalance(connection, tokenMint, programId);
|
|
128
|
+
// Calculate price from virtual reserves: price = vSol / vToken
|
|
129
|
+
const price = curveState.vToken > 0n ? (curveState.vSol * LAMPORTS_PER_SOL) / curveState.vToken : 0n;
|
|
130
|
+
// Market cap = circulating supply * price
|
|
131
|
+
const marketCapSol = curveState.totalSold > 0n ? (curveState.totalSold * price) / LAMPORTS_PER_SOL : 0n;
|
|
132
|
+
return {
|
|
133
|
+
tokenMint,
|
|
134
|
+
phase: 'curve',
|
|
135
|
+
price,
|
|
136
|
+
solReserve: solBalance,
|
|
137
|
+
tokenReserve: curveState.maxSupply - curveState.totalSold,
|
|
138
|
+
marketCapSol,
|
|
139
|
+
circulatingSupply: curveState.totalSold,
|
|
140
|
+
feeBps: curveState.feeBps,
|
|
141
|
+
paused: curveState.paused,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// Try AMM pool
|
|
146
|
+
const poolState = await getPoolState(connection, tokenMint, programId);
|
|
147
|
+
const poolBalances = poolState ? await getPoolBalances(connection, tokenMint, programId) : null;
|
|
148
|
+
if (poolState && poolBalances) {
|
|
149
|
+
// Calculate price from reserves: price = solReserve / tokenReserve
|
|
150
|
+
const price = poolBalances.tokenBalance > 0n
|
|
151
|
+
? (poolBalances.solBalance * LAMPORTS_PER_SOL) / poolBalances.tokenBalance
|
|
152
|
+
: 0n;
|
|
153
|
+
// For pool, circulating = total supply - vault balance
|
|
154
|
+
// We'd need to fetch total supply, for now use a placeholder
|
|
155
|
+
const marketCapSol = poolBalances.tokenBalance > 0n
|
|
156
|
+
? poolBalances.solBalance * 2n // Approximate: 2x the SOL in pool
|
|
157
|
+
: 0n;
|
|
158
|
+
return {
|
|
159
|
+
tokenMint,
|
|
160
|
+
phase: 'pool',
|
|
161
|
+
price,
|
|
162
|
+
solReserve: poolBalances.solBalance,
|
|
163
|
+
tokenReserve: poolBalances.tokenBalance,
|
|
164
|
+
marketCapSol,
|
|
165
|
+
circulatingSupply: 0n, // Would need total supply query
|
|
166
|
+
feeBps: Number(poolState.feeRate),
|
|
167
|
+
paused: false,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Get user's token balance
|
|
174
|
+
*/
|
|
175
|
+
export async function getUserTokenBalance(connection, tokenMint, user) {
|
|
176
|
+
try {
|
|
177
|
+
const ata = getAssociatedTokenAddressSync(tokenMint, user);
|
|
178
|
+
const account = await getAccount(connection, ata);
|
|
179
|
+
return account.amount;
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
return 0n;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
//# sourceMappingURL=accounts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accounts.js","sourceRoot":"","sources":["../src/accounts.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAc,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,6BAA6B,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC9E,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAe,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACpG,OAAO,EACN,kBAAkB,EAClB,UAAU,EACV,eAAe,EACf,mBAAmB,EACnB,oBAAoB,GACpB,MAAM,UAAU,CAAC;AAGlB,6CAA6C;AAE7C,SAAS,SAAS,CAAC,IAAY,EAAE,MAAc;IAC9C,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;AAClC,CAAC;AAED,SAAS,SAAS,CAAC,IAAY,EAAE,MAAc;IAC9C,OAAO,IAAI,CAAC,eAAe,CAAC,MAAM,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AC;QAEP,OAAO;YACN,SAAS;YACT,KAAK,EAAE,MAAM;YACb,KAAK;YACL,UAAU,EAAE,YAAY,CAAC,UAAU;YACnC,YAAY,EAAE,YAAY,CAAC,YAAY;YACvC,YAAY;YACZ,iBAAiB,EAAE,EAAE,EAAE,gCAAgC;YACvD,MAAM,EAAE,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC;YACjC,MAAM,EAAE,KAAK;SACb,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACb,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACxC,UAAsB,EACtB,SAAoB,EACpB,IAAe;IAEf,IAAI,CAAC;QACJ,MAAM,GAAG,GAAG,6BAA6B,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;QAC3D,MAAM,OAAO,GAAG,MAAM,UAAU,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;QAClD,OAAO,OAAO,CAAC,MAAM,CAAC;IACvB,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,EAAE,CAAC;IACX,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CoinBarrel SDK Constants
|
|
3
|
+
* Network-specific program IDs and configuration
|
|
4
|
+
*/
|
|
5
|
+
import { PublicKey } from '@solana/web3.js';
|
|
6
|
+
export type Network = 'devnet' | 'mainnet';
|
|
7
|
+
export declare const PROGRAM_IDS: Record<Network, PublicKey>;
|
|
8
|
+
export declare const ADMIN_FEE_RECIPIENTS: Record<Network, PublicKey>;
|
|
9
|
+
export declare const NATIVE_MINT: PublicKey;
|
|
10
|
+
export declare const SEEDS: {
|
|
11
|
+
readonly BONDING: Buffer<ArrayBuffer>;
|
|
12
|
+
readonly BONDING_AUTHORITY: Buffer<ArrayBuffer>;
|
|
13
|
+
readonly BONDING_SOL: Buffer<ArrayBuffer>;
|
|
14
|
+
readonly POOL: Buffer<ArrayBuffer>;
|
|
15
|
+
readonly AUTHORITY: Buffer<ArrayBuffer>;
|
|
16
|
+
readonly VAULT: Buffer<ArrayBuffer>;
|
|
17
|
+
readonly LP_MINT: Buffer<ArrayBuffer>;
|
|
18
|
+
readonly LP_VAULT: Buffer<ArrayBuffer>;
|
|
19
|
+
readonly HOLDER_REWARD: Buffer<ArrayBuffer>;
|
|
20
|
+
};
|
|
21
|
+
export declare const DISCRIMINATORS: {
|
|
22
|
+
readonly initialize_barrel_curve: Buffer<ArrayBuffer>;
|
|
23
|
+
readonly buy_on_curve: Buffer<ArrayBuffer>;
|
|
24
|
+
readonly sell_on_curve: Buffer<ArrayBuffer>;
|
|
25
|
+
readonly sell_max_on_curve: Buffer<ArrayBuffer>;
|
|
26
|
+
readonly configure_bonding_fees: Buffer<ArrayBuffer>;
|
|
27
|
+
readonly configure_virtual_curve: Buffer<ArrayBuffer>;
|
|
28
|
+
readonly initialize_pool: Buffer<ArrayBuffer>;
|
|
29
|
+
readonly swap_sol_to_token: Buffer<ArrayBuffer>;
|
|
30
|
+
readonly swap_token_to_sol: Buffer<ArrayBuffer>;
|
|
31
|
+
readonly swap_token_to_sol_max: Buffer<ArrayBuffer>;
|
|
32
|
+
readonly swap: Buffer<ArrayBuffer>;
|
|
33
|
+
readonly add_liquidity: Buffer<ArrayBuffer>;
|
|
34
|
+
readonly remove_liquidity: Buffer<ArrayBuffer>;
|
|
35
|
+
readonly migrate_barrel: Buffer<ArrayBuffer>;
|
|
36
|
+
readonly claim_holder_rewards: Buffer<ArrayBuffer>;
|
|
37
|
+
readonly claim_holder_rewards_curve: Buffer<ArrayBuffer>;
|
|
38
|
+
readonly init_holder_reward_account_curve: Buffer<ArrayBuffer>;
|
|
39
|
+
readonly init_holder_reward_account_pool: Buffer<ArrayBuffer>;
|
|
40
|
+
};
|
|
41
|
+
export declare const BONDING_CURVE_OFFSETS: {
|
|
42
|
+
readonly DISCRIMINATOR: 0;
|
|
43
|
+
readonly TOKEN_MINT: 8;
|
|
44
|
+
readonly TOKEN_VAULT: number;
|
|
45
|
+
readonly ADMIN_FEE_RECIPIENT: number;
|
|
46
|
+
readonly CREATOR_FEE_RECIPIENT: number;
|
|
47
|
+
readonly FEE_BPS: number;
|
|
48
|
+
readonly VARIANT: number;
|
|
49
|
+
readonly BUMP: number;
|
|
50
|
+
readonly V_TOKEN: number;
|
|
51
|
+
readonly V_SOL: number;
|
|
52
|
+
readonly AMP_BPS: number;
|
|
53
|
+
readonly TRADER_REWARDS_SHARE_BPS: number;
|
|
54
|
+
readonly MIN_PRICE: number;
|
|
55
|
+
readonly MAX_SUPPLY: number;
|
|
56
|
+
readonly TOTAL_SOLD: number;
|
|
57
|
+
readonly PAUSED: number;
|
|
58
|
+
};
|
|
59
|
+
export declare const POOL_OFFSETS: {
|
|
60
|
+
readonly DISCRIMINATOR: 0;
|
|
61
|
+
readonly TOKEN_A_MINT: 8;
|
|
62
|
+
readonly TOKEN_B_MINT: number;
|
|
63
|
+
readonly TOKEN_A_VAULT: number;
|
|
64
|
+
readonly TOKEN_B_VAULT: number;
|
|
65
|
+
readonly LP_MINT: number;
|
|
66
|
+
readonly FEE_RATE: number;
|
|
67
|
+
readonly AUTHORITY: number;
|
|
68
|
+
readonly BUMP: number;
|
|
69
|
+
readonly IS_LOCKED: number;
|
|
70
|
+
readonly POOL_TYPE: number;
|
|
71
|
+
readonly TRADER_REWARDS_SHARE_BPS: number;
|
|
72
|
+
readonly ADMIN_FEE_RECIPIENT: number;
|
|
73
|
+
readonly CREATOR_FEE_RECIPIENT: number;
|
|
74
|
+
};
|
|
75
|
+
export declare const DEFAULT_DECIMALS = 6;
|
|
76
|
+
export declare const DEFAULT_SLIPPAGE_BPS = 100;
|
|
77
|
+
export declare const LAMPORTS_PER_SOL = 1000000000n;
|
|
78
|
+
export declare const TOKEN_DECIMALS_MULTIPLIER = 1000000n;
|
|
79
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,MAAM,MAAM,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE3C,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,OAAO,EAAE,SAAS,CAGlD,CAAC;AAGF,eAAO,MAAM,oBAAoB,EAAE,MAAM,CAAC,OAAO,EAAE,SAAS,CAG3D,CAAC;AAGF,eAAO,MAAM,WAAW,WAA+D,CAAC;AAIxF,eAAO,MAAM,KAAK;;;;;;;;;;CAUR,CAAC;AAKX,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;CA0BjB,CAAC;AAKX,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;CAiBxB,CAAC;AAEX,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;CAef,CAAC;AAIX,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAClC,eAAO,MAAM,oBAAoB,MAAM,CAAC;AACxC,eAAO,MAAM,gBAAgB,cAAiB,CAAC;AAC/C,eAAO,MAAM,yBAAyB,WAAa,CAAC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CoinBarrel SDK Constants
|
|
3
|
+
* Network-specific program IDs and configuration
|
|
4
|
+
*/
|
|
5
|
+
import { PublicKey } from '@solana/web3.js';
|
|
6
|
+
export const PROGRAM_IDS = {
|
|
7
|
+
devnet: new PublicKey('AhfARnaxxX61YotZw3mZWLLUFpF8UV6pZmWJBEZCbVC4'),
|
|
8
|
+
mainnet: new PublicKey('7HxbxHnTUBaUfWjVPbPLs8gqqScmjmBWjRnETBjS9DMj'),
|
|
9
|
+
};
|
|
10
|
+
// Admin fee recipient (CoinBarrel protocol fee wallet)
|
|
11
|
+
export const ADMIN_FEE_RECIPIENTS = {
|
|
12
|
+
devnet: new PublicKey('4Uw8XhtqVBEXEkjZfWb7agyrhxbSmfDSGWEdxbWonhwu'),
|
|
13
|
+
mainnet: new PublicKey('4Uw8XhtqVBEXEkjZfWb7agyrhxbSmfDSGWEdxbWonhwu'),
|
|
14
|
+
};
|
|
15
|
+
// WSOL mint (same on all networks)
|
|
16
|
+
export const NATIVE_MINT = new PublicKey('So11111111111111111111111111111111111111112');
|
|
17
|
+
// ============= PDA Seeds =============
|
|
18
|
+
export const SEEDS = {
|
|
19
|
+
BONDING: Buffer.from('bonding'),
|
|
20
|
+
BONDING_AUTHORITY: Buffer.from('bonding_authority'),
|
|
21
|
+
BONDING_SOL: Buffer.from('bonding_sol'),
|
|
22
|
+
POOL: Buffer.from('pool'),
|
|
23
|
+
AUTHORITY: Buffer.from('authority'),
|
|
24
|
+
VAULT: Buffer.from('vault'),
|
|
25
|
+
LP_MINT: Buffer.from('lp_mint'),
|
|
26
|
+
LP_VAULT: Buffer.from('lp_vault'),
|
|
27
|
+
HOLDER_REWARD: Buffer.from('holder_reward'),
|
|
28
|
+
};
|
|
29
|
+
// ============= Instruction Discriminators =============
|
|
30
|
+
// Pre-computed Anchor discriminators (first 8 bytes of sha256("global:<instruction_name>"))
|
|
31
|
+
export const DISCRIMINATORS = {
|
|
32
|
+
// Bonding curve
|
|
33
|
+
initialize_barrel_curve: Buffer.from([158, 16, 141, 14, 53, 250, 33, 42]),
|
|
34
|
+
buy_on_curve: Buffer.from([6, 20, 84, 191, 116, 79, 21, 147]),
|
|
35
|
+
sell_on_curve: Buffer.from([158, 242, 158, 47, 48, 215, 214, 209]),
|
|
36
|
+
sell_max_on_curve: Buffer.from([42, 184, 90, 220, 13, 36, 18, 77]),
|
|
37
|
+
configure_bonding_fees: Buffer.from([39, 149, 134, 140, 64, 79, 195, 33]),
|
|
38
|
+
configure_virtual_curve: Buffer.from([255, 246, 25, 13, 216, 123, 41, 156]),
|
|
39
|
+
// AMM Pool
|
|
40
|
+
initialize_pool: Buffer.from([95, 180, 10, 172, 84, 174, 232, 40]),
|
|
41
|
+
swap_sol_to_token: Buffer.from([252, 172, 143, 68, 115, 103, 158, 1]),
|
|
42
|
+
swap_token_to_sol: Buffer.from([254, 7, 53, 81, 205, 228, 75, 82]),
|
|
43
|
+
swap_token_to_sol_max: Buffer.from([212, 28, 154, 232, 215, 75, 99, 145]),
|
|
44
|
+
swap: Buffer.from([248, 198, 158, 145, 225, 117, 135, 200]),
|
|
45
|
+
add_liquidity: Buffer.from([181, 157, 89, 67, 143, 182, 52, 72]),
|
|
46
|
+
remove_liquidity: Buffer.from([80, 85, 209, 72, 24, 206, 177, 108]),
|
|
47
|
+
// Migration
|
|
48
|
+
migrate_barrel: Buffer.from([223, 146, 165, 248, 109, 255, 136, 150]),
|
|
49
|
+
// Rewards
|
|
50
|
+
claim_holder_rewards: Buffer.from([79, 182, 142, 158, 108, 127, 120, 174]),
|
|
51
|
+
claim_holder_rewards_curve: Buffer.from([124, 102, 68, 253, 240, 13, 253, 60]),
|
|
52
|
+
init_holder_reward_account_curve: Buffer.from([236, 127, 142, 26, 253, 32, 239, 130]),
|
|
53
|
+
init_holder_reward_account_pool: Buffer.from([76, 108, 116, 44, 219, 202, 244, 57]),
|
|
54
|
+
};
|
|
55
|
+
// ============= Account Data Offsets =============
|
|
56
|
+
// For parsing on-chain account data
|
|
57
|
+
export const BONDING_CURVE_OFFSETS = {
|
|
58
|
+
DISCRIMINATOR: 0,
|
|
59
|
+
TOKEN_MINT: 8,
|
|
60
|
+
TOKEN_VAULT: 8 + 32,
|
|
61
|
+
ADMIN_FEE_RECIPIENT: 8 + 64,
|
|
62
|
+
CREATOR_FEE_RECIPIENT: 8 + 96,
|
|
63
|
+
FEE_BPS: 8 + 128,
|
|
64
|
+
VARIANT: 8 + 130,
|
|
65
|
+
BUMP: 8 + 131,
|
|
66
|
+
V_TOKEN: 8 + 132,
|
|
67
|
+
V_SOL: 8 + 148,
|
|
68
|
+
AMP_BPS: 8 + 164,
|
|
69
|
+
TRADER_REWARDS_SHARE_BPS: 8 + 166,
|
|
70
|
+
MIN_PRICE: 8 + 168,
|
|
71
|
+
MAX_SUPPLY: 8 + 176,
|
|
72
|
+
TOTAL_SOLD: 8 + 192,
|
|
73
|
+
PAUSED: 8 + 208,
|
|
74
|
+
};
|
|
75
|
+
export const POOL_OFFSETS = {
|
|
76
|
+
DISCRIMINATOR: 0,
|
|
77
|
+
TOKEN_A_MINT: 8,
|
|
78
|
+
TOKEN_B_MINT: 8 + 32,
|
|
79
|
+
TOKEN_A_VAULT: 8 + 64,
|
|
80
|
+
TOKEN_B_VAULT: 8 + 96,
|
|
81
|
+
LP_MINT: 8 + 128,
|
|
82
|
+
FEE_RATE: 8 + 160,
|
|
83
|
+
AUTHORITY: 8 + 168,
|
|
84
|
+
BUMP: 8 + 200,
|
|
85
|
+
IS_LOCKED: 8 + 201,
|
|
86
|
+
POOL_TYPE: 8 + 202,
|
|
87
|
+
TRADER_REWARDS_SHARE_BPS: 8 + 203,
|
|
88
|
+
ADMIN_FEE_RECIPIENT: 8 + 205,
|
|
89
|
+
CREATOR_FEE_RECIPIENT: 8 + 237,
|
|
90
|
+
};
|
|
91
|
+
// ============= Defaults =============
|
|
92
|
+
export const DEFAULT_DECIMALS = 6;
|
|
93
|
+
export const DEFAULT_SLIPPAGE_BPS = 100; // 1%
|
|
94
|
+
export const LAMPORTS_PER_SOL = 1000000000n;
|
|
95
|
+
export const TOKEN_DECIMALS_MULTIPLIER = 1000000n; // 10^6 for 6 decimals
|
|
96
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAM5C,MAAM,CAAC,MAAM,WAAW,GAA+B;IACtD,MAAM,EAAE,IAAI,SAAS,CAAC,8CAA8C,CAAC;IACrE,OAAO,EAAE,IAAI,SAAS,CAAC,8CAA8C,CAAC;CACtE,CAAC;AAEF,uDAAuD;AACvD,MA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AAM,oBAAoB,GAAG,GAAG,CAAC,CAAC,KAAK;AAC9C,MAAM,CAAC,MAAM,gBAAgB,GAAG,WAAc,CAAC;AAC/C,MAAM,CAAC,MAAM,yBAAyB,GAAG,QAAU,CAAC,CAAC,sBAAsB"}
|
package/dist/curve.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bonding Curve Operations
|
|
3
|
+
* Buy and sell tokens on the bonding curve
|
|
4
|
+
*/
|
|
5
|
+
import { Connection, PublicKey, TransactionInstruction } from '@solana/web3.js';
|
|
6
|
+
import type { BuyOnCurveParams, SellOnCurveParams, SellMaxOnCurveParams, BuyQuote, SellQuote } from './types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Calculate buy quote for bonding curve
|
|
9
|
+
* Uses constant product formula: (vSol + solIn) * (vToken - tokensOut) = k
|
|
10
|
+
*/
|
|
11
|
+
export declare function getBuyQuote(connection: Connection, tokenMint: PublicKey, solIn: bigint, programId: PublicKey): Promise<BuyQuote | null>;
|
|
12
|
+
/**
|
|
13
|
+
* Calculate sell quote for bonding curve
|
|
14
|
+
*/
|
|
15
|
+
export declare function getSellQuote(connection: Connection, tokenMint: PublicKey, tokensIn: bigint, programId: PublicKey): Promise<SellQuote | null>;
|
|
16
|
+
/**
|
|
17
|
+
* Build buy_on_curve instruction
|
|
18
|
+
*
|
|
19
|
+
* IMPORTANT: Fee recipients are read from on-chain state and cannot be modified.
|
|
20
|
+
* The program enforces that fees go to the correct recipients.
|
|
21
|
+
*/
|
|
22
|
+
export declare function buildBuyOnCurveInstruction(connection: Connection, params: BuyOnCurveParams, programId: PublicKey): Promise<TransactionInstruction[]>;
|
|
23
|
+
/**
|
|
24
|
+
* Build sell_on_curve instruction
|
|
25
|
+
*
|
|
26
|
+
* IMPORTANT: Fee recipients are read from on-chain state and cannot be modified.
|
|
27
|
+
*/
|
|
28
|
+
export declare function buildSellOnCurveInstruction(connection: Connection, params: SellOnCurveParams, programId: PublicKey): Promise<TransactionInstruction[]>;
|
|
29
|
+
/**
|
|
30
|
+
* Build sell_max_on_curve instruction (sell entire balance)
|
|
31
|
+
*/
|
|
32
|
+
export declare function buildSellMaxOnCurveInstruction(connection: Connection, params: SellMaxOnCurveParams, programId: PublicKey): Promise<TransactionInstruction[]>;
|
|
33
|
+
//# sourceMappingURL=curve.d.ts.map
|