Skip to content

Commit b9317a2

Browse files
committed
Add AMM swap helpers and update documentation
Introduces AMM swap helper functions (`ammBuy`, `ammSell`) and supporting modules. Updates README to clarify curve vs AMM swap APIs and usage. Adds new tests and configuration for AMM swaps. Refactors code to separate curve and AMM logic for improved clarity and maintainability.
1 parent 272d0b7 commit b9317a2

18 files changed

Lines changed: 3553 additions & 775 deletions

README.md

Lines changed: 60 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,17 @@ A TypeScript SDK for Pump.fun built on **Solana Kit 5.0**. Designed for high-per
2424

2525
- **Solana Kit 5.0** – Built on the latest Solana development framework
2626
- **Modern transaction patterns** – Optimized for speed and reliability
27-
- **Human-readable API** – Work with SOL amounts and percentages instead of raw lamports
27+
- **Unified swaps**`buy`/`sell` auto-route between bonding curves and AMM pools
28+
- **Curve helpers** – Direct access to bonding-curve instructions when you need them (`curveBuy`, `curveSell`)
29+
- **AMM helpers** – Deterministic AMM operations with percentage-aware selling (`ammBuy`, `ammSell`)
2830
- **Automatic slippage protection** – Built-in guards for buy/sell operations
29-
- **Launch capabilities** – Create and buy tokens in one atomic transaction
30-
- **Liquidity operations** – Add/remove liquidity with simple helpers
3131
- **Full TypeScript support** – Strongly typed throughout with complete type coverage
3232

33+
### Coming Soon
34+
35+
- **Launch & mint helpers** – Create and seed new Pump.fun tokens once integration is ready
36+
- **Liquidity tooling** – Add/remove liquidity with tested helpers
37+
3338
---
3439

3540
## Installation
@@ -50,12 +55,12 @@ import { createSolanaRpc } from "@solana/kit";
5055
const rpc = createSolanaRpc("https://api.mainnet-beta.solana.com");
5156
```
5257

53-
### Buy Tokens
58+
### Buy Tokens (Curve)
5459

5560
```ts
56-
import { buy } from "pump-kit";
61+
import { curveBuy } from "pump-kit";
5762

58-
await buy({
63+
await curveBuy({
5964
user: myWallet,
6065
mint: "TokenMintAddress",
6166
solAmount: 0.5, // 0.5 SOL
@@ -64,21 +69,21 @@ await buy({
6469
});
6570
```
6671

67-
### Sell Tokens
72+
### Sell Tokens (Curve)
6873

6974
```ts
70-
import { sell } from "pump-kit";
75+
import { curveSell } from "pump-kit";
7176

7277
// Sell specific amount
73-
await sell({
78+
await curveSell({
7479
user: myWallet,
7580
mint: "TokenMintAddress",
7681
tokenAmount: 125_000,
7782
rpc,
7883
});
7984

8085
// Sell percentage of wallet
81-
await sell({
86+
await curveSell({
8287
user: myWallet,
8388
mint: "TokenMintAddress",
8489
useWalletPercentage: true,
@@ -87,68 +92,78 @@ await sell({
8792
});
8893
```
8994

90-
### Create and Buy Token
95+
### Buy Tokens (AMM)
9196

9297
```ts
93-
import { mintWithFirstBuy } from "pump-kit";
94-
import { generateKeyPair } from "@solana/kit";
98+
import { ammBuy } from "pump-kit";
9599

96-
const mintKeypair = await generateKeyPair();
97-
98-
const { createInstruction, buyInstruction } = await mintWithFirstBuy({
100+
await ammBuy({
99101
user: myWallet,
100-
mint: mintKeypair,
101-
mintAuthority: myWallet.address,
102-
name: "My Token",
103-
symbol: "MTK",
104-
uri: "https://arweave.net/metadata.json",
105-
firstBuyTokenAmount: 1_000_000,
106-
firstBuySolBudget: 1.0,
102+
mint: "TokenMintAddress",
103+
solAmount: 0.5,
104+
poolCreator: "CreatorAddress", // optional if auto detection works
107105
rpc,
108106
});
109107
```
110108

111-
### Quick Helpers
109+
### Sell Tokens (AMM)
112110

113111
```ts
114-
import { quickBuy, quickSell } from "pump-kit";
112+
import { ammSell } from "pump-kit";
115113

116-
// Get buy instruction
117-
const buyIx = await quickBuy(myWallet, "TokenMint", 0.25, { rpc });
118-
119-
// Get sell instruction
120-
const sellIx = await quickSell(myWallet, "TokenMint", 100_000, { rpc });
114+
await ammSell({
115+
user: myWallet,
116+
mint: "TokenMintAddress",
117+
useWalletPercentage: true,
118+
walletPercentage: 100,
119+
poolCreator: "CreatorAddress",
120+
rpc,
121+
});
121122
```
122123

123124
---
124125

125126
## API Reference
126127

127-
### Core Functions
128+
### Curve Swap Helpers
128129

129130
```ts
130-
// Buy tokens
131-
buy({ user, mint, solAmount, slippageBps?, rpc, ... })
131+
// Buy tokens on the bonding curve
132+
curveBuy({ user, mint, solAmount, slippageBps?, rpc, ... })
132133

133-
// Sell tokens
134-
sell({ user, mint, tokenAmount?, useWalletPercentage?, walletPercentage?, rpc, ... })
134+
// Sell tokens on the bonding curve
135+
curveSell({ user, mint, tokenAmount?, useWalletPercentage?, walletPercentage?, rpc, ... })
136+
```
135137

136-
// Quick helpers (return instructions only)
137-
quickBuy(wallet, mint, solAmount, { rpc, ...options })
138-
quickSell(wallet, mint, tokenAmount, { rpc, ...options })
138+
### AMM Swap Helpers
139139

140-
// Create token with initial buy
141-
mintWithFirstBuy({ user, mint, name, symbol, uri, firstBuyTokenAmount, firstBuySolBudget, rpc, ... })
140+
```ts
141+
// Buy tokens from the AMM pool using a SOL budget
142+
ammBuy({ user, mint, solAmount, rpc, quoteMint?, poolCreator?, poolAddress? })
143+
144+
// Sell tokens into the AMM pool (supports percentage-based selling)
145+
ammSell({
146+
user,
147+
mint,
148+
tokenAmount?,
149+
useWalletPercentage?,
150+
walletPercentage?,
151+
rpc,
152+
quoteMint?,
153+
poolCreator?,
154+
poolAddress?,
155+
})
142156
```
143157

144-
### Liquidity Management
158+
### Coming Soon
145159

146160
```ts
147-
// Add liquidity to pool
148-
addLiquidity({ user, baseMint, quoteMint?, maxBaseAmountIn, maxQuoteAmountIn, rpc, ... })
161+
// Create token with initial buy
162+
mintWithFirstBuy({ ... })
149163

150-
// Remove liquidity from pool
151-
removeLiquidity({ user, baseMint, quoteMint?, lpAmountIn, rpc, ... })
164+
// Liquidity helpers
165+
addLiquidity({ ... })
166+
removeLiquidity({ ... })
152167
```
153168

154169
### Transaction Utilities

idl/pumpfun.idl.json

Lines changed: 2218 additions & 1 deletion
Large diffs are not rendered by default.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pump-kit",
3-
"version": "0.0.8",
3+
"version": "0.1.0",
44
"type": "module",
55
"exports": {
66
".": {
@@ -29,8 +29,8 @@
2929
"build:types": "tsc -p tsconfig.build.json",
3030
"build": "rm -rf dist && bun run build:js && bun run build:types",
3131
"release:prepare": "bun run build && bun run test",
32-
"release:publish": "npm publish --access public",
33-
"release:dry-run": "npm publish --access public --dry-run",
32+
"release:publish": "bun run npm publish --access public",
33+
"release:dry-run": "bun run npm publish --access public --dry-run",
3434
"codegen": "bun run scripts/codama-generate.ts",
3535
"test": "bun test",
3636
"test:unit": "bun test tests/unit",

src/ammsdk/bondingCurveMath.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ const BPS_DENOMINATOR = 10_000n;
1111

1212
export type BondingCurveState = Pick<
1313
BondingCurve,
14-
"virtualTokenReserves" | "virtualSolReserves" | "realTokenReserves" | "realSolReserves" | "creator"
14+
| "virtualTokenReserves"
15+
| "virtualSolReserves"
16+
| "realTokenReserves"
17+
| "realSolReserves"
18+
| "creator"
19+
| "complete"
1520
>;
1621

1722
export type FeeStructure = Pick<Fees, "lpFeeBps" | "protocolFeeBps" | "creatorFeeBps">;

src/index.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,23 @@ import "./config/polyfills";
1010
// Simple API (recommended - start here!)
1111
// ============================================================================
1212

13-
export { buy, sell, quickBuy, quickSell } from "./swap";
14-
export type { BuyParams, SellParams } from "./swap";
13+
export {
14+
buy,
15+
sell,
16+
curveBuy,
17+
curveSell,
18+
ammBuy,
19+
ammSell,
20+
} from "./swap";
21+
22+
export type {
23+
BuyParams,
24+
SellParams,
25+
CurveBuyParams,
26+
CurveSellParams,
27+
AmmBuyParams,
28+
AmmSellParams,
29+
} from "./swap";
1530

1631
export {
1732
mintWithFirstBuy,

src/recipes/buy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,4 @@ export async function buySimple(params: SimpleBuyParams): Promise<Instruction> {
138138
rpc,
139139
commitment,
140140
});
141-
}
141+
}

src/recipes/mintFirstBuy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,4 @@ export function validateMintParams(params: {
122122
if (!uri.startsWith("http://") && !uri.startsWith("https://") && !uri.startsWith("ipfs://")) {
123123
throw new Error("Metadata URI must be a valid URL or IPFS link");
124124
}
125-
}
125+
}

src/simple.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,19 @@
55

66
import "./config/polyfills";
77

8-
export { buy, sell, quickBuy, quickSell } from "./swap";
9-
export type { BuyParams, SellParams } from "./swap";
8+
export {
9+
buy,
10+
sell,
11+
curveBuy,
12+
curveSell,
13+
} from "./swap";
14+
15+
export type {
16+
BuyParams,
17+
SellParams,
18+
CurveBuyParams,
19+
CurveSellParams,
20+
} from "./swap";
1021

1122
export { mintWithFirstBuy, validateMintParams } from "./recipes/mintFirstBuy";
1223
export type { MintWithFirstBuyParams } from "./recipes/mintFirstBuy";

0 commit comments

Comments
 (0)