@openpump/sdk 0.1.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 +248 -0
- package/dist/index.cjs +462 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +473 -0
- package/dist/index.d.ts +473 -0
- package/dist/index.js +428 -0
- package/dist/index.js.map +1 -0
- package/package.json +52 -0
package/README.md
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
# @openpump/sdk
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for the OpenPump REST API. Zero runtime dependencies (uses global `fetch`), dual-format (ESM + CJS), fully typed.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Internal workspace usage
|
|
9
|
+
pnpm add @openpump/sdk
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Quick Start
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { OpenPump } from '@openpump/sdk';
|
|
16
|
+
|
|
17
|
+
const op = new OpenPump({ apiKey: 'op_sk_live_...' });
|
|
18
|
+
|
|
19
|
+
const wallets = await op.wallets.list();
|
|
20
|
+
console.log(wallets);
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Configuration
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
const op = new OpenPump({
|
|
27
|
+
apiKey: 'op_sk_live_...', // Required
|
|
28
|
+
baseUrl: 'https://api.openpump.io', // Default
|
|
29
|
+
timeout: 30_000, // Default (ms)
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Resources
|
|
34
|
+
|
|
35
|
+
### Wallets
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
// List all wallets
|
|
39
|
+
const wallets = await op.wallets.list();
|
|
40
|
+
|
|
41
|
+
// Create a wallet
|
|
42
|
+
const wallet = await op.wallets.create({ label: 'Trading Wallet' });
|
|
43
|
+
|
|
44
|
+
// Get a single wallet
|
|
45
|
+
const w = await op.wallets.get('wallet-id');
|
|
46
|
+
|
|
47
|
+
// Get balances (SOL + tokens)
|
|
48
|
+
const balance = await op.wallets.getBalance('wallet-id');
|
|
49
|
+
|
|
50
|
+
// Get deposit instructions
|
|
51
|
+
const deposit = await op.wallets.getDepositInstructions('wallet-id');
|
|
52
|
+
|
|
53
|
+
// Force-refresh balance (bypass 30s cache)
|
|
54
|
+
const fresh = await op.wallets.refreshBalance('wallet-id');
|
|
55
|
+
|
|
56
|
+
// Transfer SOL or SPL tokens
|
|
57
|
+
const tx = await op.wallets.transfer('wallet-id', {
|
|
58
|
+
toAddress: 'recipient-public-key',
|
|
59
|
+
amountLamports: '100000000',
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Get transaction history
|
|
63
|
+
const history = await op.wallets.getTransactions('wallet-id', {
|
|
64
|
+
type: 'buy',
|
|
65
|
+
limit: 20,
|
|
66
|
+
offset: 0,
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Tokens
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
// List your tokens
|
|
74
|
+
const tokens = await op.tokens.list();
|
|
75
|
+
|
|
76
|
+
// Create a new PumpFun token
|
|
77
|
+
const token = await op.tokens.create({
|
|
78
|
+
name: 'My Token',
|
|
79
|
+
symbol: 'MTK',
|
|
80
|
+
description: 'A cool token',
|
|
81
|
+
imageBase64: 'base64-encoded-image...',
|
|
82
|
+
imageType: 'image/png',
|
|
83
|
+
twitter: '@mytoken',
|
|
84
|
+
website: 'https://mytoken.com',
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// Get market info (mainnet only)
|
|
88
|
+
const market = await op.tokens.getMarketInfo('mint-address');
|
|
89
|
+
|
|
90
|
+
// Get bonding curve state
|
|
91
|
+
const curve = await op.tokens.getCurveState('mint-address');
|
|
92
|
+
console.log(curve.currentPriceSOL, curve.graduationPercent);
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Trading
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
// Get a price quote
|
|
99
|
+
const quote = await op.trading.getQuote('mint-address', {
|
|
100
|
+
action: 'buy',
|
|
101
|
+
solAmount: '1000000000',
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// Get SOL cost for a specific token amount
|
|
105
|
+
const cost = await op.trading.getQuoteBuyCost('mint-address', {
|
|
106
|
+
tokenAmount: '1000000',
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// Buy tokens
|
|
110
|
+
const buy = await op.trading.buy('mint-address', {
|
|
111
|
+
walletId: 'wallet-id',
|
|
112
|
+
amountLamports: '500000000',
|
|
113
|
+
slippageBps: 500,
|
|
114
|
+
priorityLevel: 'fast',
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// Sell tokens
|
|
118
|
+
const sell = await op.trading.sell('mint-address', {
|
|
119
|
+
walletId: 'wallet-id',
|
|
120
|
+
tokenAmount: 'all',
|
|
121
|
+
slippageBps: 500,
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// Multi-wallet bundle sell (Jito bundles)
|
|
125
|
+
const bundleSell = await op.trading.bundleSell('mint-address', {
|
|
126
|
+
walletSells: [
|
|
127
|
+
{ walletId: 'w1', tokenAmount: 'all' },
|
|
128
|
+
{ walletId: 'w2', tokenAmount: '500000' },
|
|
129
|
+
],
|
|
130
|
+
slippageBps: 500,
|
|
131
|
+
});
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Bundles
|
|
135
|
+
|
|
136
|
+
```ts
|
|
137
|
+
// Launch token + multi-wallet buy in a single Jito bundle
|
|
138
|
+
const { jobId } = await op.bundles.launch({
|
|
139
|
+
devWalletId: 'wallet-1',
|
|
140
|
+
buyWalletIds: ['wallet-2', 'wallet-3'],
|
|
141
|
+
name: 'My Token',
|
|
142
|
+
symbol: 'MTK',
|
|
143
|
+
imageBase64: '...',
|
|
144
|
+
imageType: 'image/png',
|
|
145
|
+
walletBuyAmounts: ['500000000', '500000000'],
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// Poll for completion
|
|
149
|
+
const result = await op.jobs.poll(jobId, {
|
|
150
|
+
intervalMs: 2000,
|
|
151
|
+
timeoutMs: 60_000,
|
|
152
|
+
onProgress: (s) => console.log(`${s.progress}%`),
|
|
153
|
+
});
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Jobs
|
|
157
|
+
|
|
158
|
+
```ts
|
|
159
|
+
// Get job status
|
|
160
|
+
const status = await op.jobs.get('job-id');
|
|
161
|
+
|
|
162
|
+
// Poll until completion with progress callback
|
|
163
|
+
const result = await op.jobs.poll('job-id', {
|
|
164
|
+
intervalMs: 2000,
|
|
165
|
+
timeoutMs: 60_000,
|
|
166
|
+
onProgress: (s) => console.log(`${s.progress}%`),
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
// Poll with abort support
|
|
170
|
+
const controller = new AbortController();
|
|
171
|
+
const result = await op.jobs.poll('job-id', {
|
|
172
|
+
signal: controller.signal,
|
|
173
|
+
});
|
|
174
|
+
// Call controller.abort() to cancel polling
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Creator Fees
|
|
178
|
+
|
|
179
|
+
```ts
|
|
180
|
+
// Check accumulated fees
|
|
181
|
+
const fees = await op.creatorFees.getAccumulatedFees('creator-address');
|
|
182
|
+
console.log(fees.accumulatedSOL);
|
|
183
|
+
|
|
184
|
+
// Claim fees
|
|
185
|
+
const claim = await op.creatorFees.claim('creator-address');
|
|
186
|
+
console.log(claim.signature);
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## Error Handling
|
|
190
|
+
|
|
191
|
+
The SDK throws typed errors that map to HTTP status codes:
|
|
192
|
+
|
|
193
|
+
```ts
|
|
194
|
+
import {
|
|
195
|
+
OpenPumpError,
|
|
196
|
+
AuthenticationError,
|
|
197
|
+
ValidationError,
|
|
198
|
+
NotFoundError,
|
|
199
|
+
RateLimitError,
|
|
200
|
+
} from '@openpump/sdk';
|
|
201
|
+
|
|
202
|
+
try {
|
|
203
|
+
await op.wallets.list();
|
|
204
|
+
} catch (error) {
|
|
205
|
+
if (error instanceof AuthenticationError) {
|
|
206
|
+
// 401 - Invalid or expired API key
|
|
207
|
+
console.error(error.code, error.message);
|
|
208
|
+
} else if (error instanceof ValidationError) {
|
|
209
|
+
// 422 - Invalid input
|
|
210
|
+
console.error(error.details);
|
|
211
|
+
} else if (error instanceof NotFoundError) {
|
|
212
|
+
// 404 - Resource not found
|
|
213
|
+
} else if (error instanceof RateLimitError) {
|
|
214
|
+
// 429 - Too many requests
|
|
215
|
+
} else if (error instanceof OpenPumpError) {
|
|
216
|
+
// Any other API error
|
|
217
|
+
console.error(error.status, error.code, error.message);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
All error classes extend `OpenPumpError` with these properties:
|
|
223
|
+
|
|
224
|
+
| Property | Type | Description |
|
|
225
|
+
|-----------|-----------|----------------------------|
|
|
226
|
+
| `code` | `string` | Machine-readable error code |
|
|
227
|
+
| `message` | `string` | Human-readable description |
|
|
228
|
+
| `status` | `number` | HTTP status code |
|
|
229
|
+
| `details` | `unknown` | Optional validation details |
|
|
230
|
+
|
|
231
|
+
## Build
|
|
232
|
+
|
|
233
|
+
```bash
|
|
234
|
+
pnpm --filter @openpump/sdk run build
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
Outputs ESM (`.js`), CJS (`.cjs`), and TypeScript declarations (`.d.ts`, `.d.cts`) to `dist/`.
|
|
238
|
+
|
|
239
|
+
## Test
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
pnpm --filter @openpump/sdk exec npx vitest run
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
## Requirements
|
|
246
|
+
|
|
247
|
+
- Node.js 18+ (global `fetch` required)
|
|
248
|
+
- TypeScript 5.3+
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,462 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
AuthenticationError: () => AuthenticationError,
|
|
24
|
+
InsufficientFundsError: () => InsufficientFundsError,
|
|
25
|
+
NotFoundError: () => NotFoundError,
|
|
26
|
+
OpenPump: () => OpenPump,
|
|
27
|
+
OpenPumpError: () => OpenPumpError,
|
|
28
|
+
RateLimitError: () => RateLimitError,
|
|
29
|
+
TransactionError: () => TransactionError,
|
|
30
|
+
ValidationError: () => ValidationError
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(index_exports);
|
|
33
|
+
|
|
34
|
+
// src/errors.ts
|
|
35
|
+
var OpenPumpError = class extends Error {
|
|
36
|
+
constructor(code, message, status, details) {
|
|
37
|
+
super(message);
|
|
38
|
+
this.code = code;
|
|
39
|
+
this.status = status;
|
|
40
|
+
this.details = details;
|
|
41
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
42
|
+
}
|
|
43
|
+
name = "OpenPumpError";
|
|
44
|
+
};
|
|
45
|
+
var AuthenticationError = class extends OpenPumpError {
|
|
46
|
+
name = "AuthenticationError";
|
|
47
|
+
constructor(code, message, status, details) {
|
|
48
|
+
super(code, message, status, details);
|
|
49
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
var RateLimitError = class extends OpenPumpError {
|
|
53
|
+
name = "RateLimitError";
|
|
54
|
+
constructor(code, message, status, details) {
|
|
55
|
+
super(code, message, status, details);
|
|
56
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
var ValidationError = class extends OpenPumpError {
|
|
60
|
+
name = "ValidationError";
|
|
61
|
+
constructor(code, message, status, details) {
|
|
62
|
+
super(code, message, status, details);
|
|
63
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
var NotFoundError = class extends OpenPumpError {
|
|
67
|
+
name = "NotFoundError";
|
|
68
|
+
constructor(code, message, status, details) {
|
|
69
|
+
super(code, message, status, details);
|
|
70
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
var InsufficientFundsError = class extends OpenPumpError {
|
|
74
|
+
name = "InsufficientFundsError";
|
|
75
|
+
constructor(code, message, status, details) {
|
|
76
|
+
super(code, message, status, details);
|
|
77
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
var TransactionError = class extends OpenPumpError {
|
|
81
|
+
name = "TransactionError";
|
|
82
|
+
constructor(code, message, status, details) {
|
|
83
|
+
super(code, message, status, details);
|
|
84
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
// src/http.ts
|
|
89
|
+
var HttpClient = class {
|
|
90
|
+
_apiKey;
|
|
91
|
+
_baseUrl;
|
|
92
|
+
_timeout;
|
|
93
|
+
constructor(config) {
|
|
94
|
+
this._apiKey = config.apiKey;
|
|
95
|
+
this._baseUrl = config.baseUrl.replace(/\/+$/, "");
|
|
96
|
+
this._timeout = config.timeout;
|
|
97
|
+
}
|
|
98
|
+
async get(path, query) {
|
|
99
|
+
let url = `${this._baseUrl}${path}`;
|
|
100
|
+
if (query && Object.keys(query).length > 0) {
|
|
101
|
+
const params = new URLSearchParams(query);
|
|
102
|
+
url += `?${params.toString()}`;
|
|
103
|
+
}
|
|
104
|
+
const response = await fetch(url, {
|
|
105
|
+
headers: this._headers(),
|
|
106
|
+
signal: AbortSignal.timeout(this._timeout)
|
|
107
|
+
});
|
|
108
|
+
return this._handleResponse(response);
|
|
109
|
+
}
|
|
110
|
+
async post(path, body) {
|
|
111
|
+
const init = {
|
|
112
|
+
method: "POST",
|
|
113
|
+
headers: {
|
|
114
|
+
...this._headers(),
|
|
115
|
+
"Content-Type": "application/json"
|
|
116
|
+
},
|
|
117
|
+
signal: AbortSignal.timeout(this._timeout)
|
|
118
|
+
};
|
|
119
|
+
if (body !== void 0) {
|
|
120
|
+
init.body = JSON.stringify(body);
|
|
121
|
+
}
|
|
122
|
+
const response = await fetch(`${this._baseUrl}${path}`, init);
|
|
123
|
+
return this._handleResponse(response);
|
|
124
|
+
}
|
|
125
|
+
async patch(path, body) {
|
|
126
|
+
const response = await fetch(`${this._baseUrl}${path}`, {
|
|
127
|
+
method: "PATCH",
|
|
128
|
+
headers: {
|
|
129
|
+
...this._headers(),
|
|
130
|
+
"Content-Type": "application/json"
|
|
131
|
+
},
|
|
132
|
+
body: JSON.stringify(body),
|
|
133
|
+
signal: AbortSignal.timeout(this._timeout)
|
|
134
|
+
});
|
|
135
|
+
return this._handleResponse(response);
|
|
136
|
+
}
|
|
137
|
+
async delete(path) {
|
|
138
|
+
const response = await fetch(`${this._baseUrl}${path}`, {
|
|
139
|
+
method: "DELETE",
|
|
140
|
+
headers: this._headers(),
|
|
141
|
+
signal: AbortSignal.timeout(this._timeout)
|
|
142
|
+
});
|
|
143
|
+
return this._handleResponse(response);
|
|
144
|
+
}
|
|
145
|
+
_headers() {
|
|
146
|
+
return { Authorization: `Bearer ${this._apiKey}` };
|
|
147
|
+
}
|
|
148
|
+
async _handleResponse(response) {
|
|
149
|
+
if (!response.ok) {
|
|
150
|
+
await this._throwApiError(response);
|
|
151
|
+
}
|
|
152
|
+
const json = await response.json();
|
|
153
|
+
if (json !== null && typeof json === "object" && "data" in json) {
|
|
154
|
+
return json["data"];
|
|
155
|
+
}
|
|
156
|
+
return json;
|
|
157
|
+
}
|
|
158
|
+
async _throwApiError(response) {
|
|
159
|
+
let body = {};
|
|
160
|
+
try {
|
|
161
|
+
body = await response.json();
|
|
162
|
+
} catch {
|
|
163
|
+
}
|
|
164
|
+
const code = body.code ?? body.error ?? "UNKNOWN_ERROR";
|
|
165
|
+
const message = body.message ?? response.statusText;
|
|
166
|
+
const details = body.details;
|
|
167
|
+
switch (response.status) {
|
|
168
|
+
case 401: {
|
|
169
|
+
throw new AuthenticationError(code, message, 401, details);
|
|
170
|
+
}
|
|
171
|
+
case 404: {
|
|
172
|
+
throw new NotFoundError(code, message, 404, details);
|
|
173
|
+
}
|
|
174
|
+
case 422: {
|
|
175
|
+
throw new ValidationError(code, message, 422, details);
|
|
176
|
+
}
|
|
177
|
+
case 429: {
|
|
178
|
+
throw new RateLimitError(code, message, 429, details);
|
|
179
|
+
}
|
|
180
|
+
default: {
|
|
181
|
+
throw new OpenPumpError(code, message, response.status, details);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
// src/resources/wallets.ts
|
|
188
|
+
var Wallets = class {
|
|
189
|
+
constructor(_http) {
|
|
190
|
+
this._http = _http;
|
|
191
|
+
}
|
|
192
|
+
/** List all active wallets for the authenticated user. */
|
|
193
|
+
async list() {
|
|
194
|
+
return this._http.get("/api/wallets");
|
|
195
|
+
}
|
|
196
|
+
/** Create a new wallet with an optional label. */
|
|
197
|
+
async create(options) {
|
|
198
|
+
return this._http.post("/api/wallets", options ?? {});
|
|
199
|
+
}
|
|
200
|
+
/** Get a single wallet by ID. */
|
|
201
|
+
async get(walletId) {
|
|
202
|
+
return this._http.get(`/api/wallets/${walletId}`);
|
|
203
|
+
}
|
|
204
|
+
/** Get SOL + token balances for a wallet. */
|
|
205
|
+
async getBalance(walletId) {
|
|
206
|
+
return this._http.get(`/api/wallets/${walletId}/balance`);
|
|
207
|
+
}
|
|
208
|
+
/** Get deposit address and SOL minimums for a wallet. */
|
|
209
|
+
async getDepositInstructions(walletId) {
|
|
210
|
+
return this._http.get(`/api/wallets/${walletId}/deposit-instructions`);
|
|
211
|
+
}
|
|
212
|
+
/** Force a live RPC balance refresh, bypassing the 30s cache. */
|
|
213
|
+
async refreshBalance(walletId) {
|
|
214
|
+
return this._http.post(`/api/wallets/${walletId}/refresh-balance`);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Execute an on-chain SOL or SPL token transfer.
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* ```ts
|
|
221
|
+
* const result = await op.wallets.transfer('wallet-id', {
|
|
222
|
+
* toAddress: 'recipient-public-key',
|
|
223
|
+
* amountLamports: '100000000',
|
|
224
|
+
* });
|
|
225
|
+
* console.log(result.signature);
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
async transfer(walletId, options) {
|
|
229
|
+
return this._http.post(`/api/wallets/${walletId}/transfer`, options);
|
|
230
|
+
}
|
|
231
|
+
/** Get paginated transfer history for a wallet. */
|
|
232
|
+
async getTransactions(walletId, options) {
|
|
233
|
+
const query = {};
|
|
234
|
+
if (options?.type !== void 0) query["type"] = options.type;
|
|
235
|
+
if (options?.limit !== void 0) query["limit"] = String(options.limit);
|
|
236
|
+
if (options?.offset !== void 0) query["offset"] = String(options.offset);
|
|
237
|
+
return this._http.get(`/api/wallets/${walletId}/transactions`, query);
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
// src/resources/tokens.ts
|
|
242
|
+
var Tokens = class {
|
|
243
|
+
constructor(_http) {
|
|
244
|
+
this._http = _http;
|
|
245
|
+
}
|
|
246
|
+
/** List tokens created by the authenticated user. */
|
|
247
|
+
async list() {
|
|
248
|
+
return this._http.get("/api/tokens");
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Create a new PumpFun token with IPFS metadata upload.
|
|
252
|
+
*
|
|
253
|
+
* @example
|
|
254
|
+
* ```ts
|
|
255
|
+
* const token = await op.tokens.create({
|
|
256
|
+
* name: 'My Token',
|
|
257
|
+
* symbol: 'MTK',
|
|
258
|
+
* description: 'A cool token',
|
|
259
|
+
* imageBase64: 'base64-encoded-image...',
|
|
260
|
+
* imageType: 'image/png',
|
|
261
|
+
* });
|
|
262
|
+
* console.log(token.mint);
|
|
263
|
+
* ```
|
|
264
|
+
*/
|
|
265
|
+
async create(options) {
|
|
266
|
+
return this._http.post("/api/tokens/create", options);
|
|
267
|
+
}
|
|
268
|
+
/** Get market info for a token (mainnet only, returns null on devnet). */
|
|
269
|
+
async getMarketInfo(mint) {
|
|
270
|
+
return this._http.get(`/api/tokens/${mint}/market-info`);
|
|
271
|
+
}
|
|
272
|
+
/** Get bonding curve state including price, market cap, and graduation progress. */
|
|
273
|
+
async getCurveState(mint) {
|
|
274
|
+
return this._http.get(`/api/tokens/${mint}/curve-state`);
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
// src/resources/trading.ts
|
|
279
|
+
var Trading = class {
|
|
280
|
+
constructor(_http) {
|
|
281
|
+
this._http = _http;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Get a price quote for buying or selling a token.
|
|
285
|
+
*
|
|
286
|
+
* @example
|
|
287
|
+
* ```ts
|
|
288
|
+
* const quote = await op.trading.getQuote('So11...', {
|
|
289
|
+
* action: 'buy',
|
|
290
|
+
* solAmount: '1000000000',
|
|
291
|
+
* });
|
|
292
|
+
* console.log(quote.expectedTokens);
|
|
293
|
+
* ```
|
|
294
|
+
*/
|
|
295
|
+
async getQuote(mint, options) {
|
|
296
|
+
const query = { action: options.action };
|
|
297
|
+
if (options.solAmount !== void 0) query["solAmount"] = options.solAmount;
|
|
298
|
+
if (options.tokenAmount !== void 0) query["tokenAmount"] = options.tokenAmount;
|
|
299
|
+
return this._http.get(`/api/tokens/${mint}/quote`, query);
|
|
300
|
+
}
|
|
301
|
+
/** Get the SOL cost to buy a specific number of tokens (inverse quote). */
|
|
302
|
+
async getQuoteBuyCost(mint, options) {
|
|
303
|
+
return this._http.get(`/api/tokens/${mint}/quote-buy-cost`, {
|
|
304
|
+
tokenAmount: options.tokenAmount
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
/** Execute a buy transaction for a token. */
|
|
308
|
+
async buy(mint, options) {
|
|
309
|
+
return this._http.post(`/api/tokens/${mint}/buy`, options);
|
|
310
|
+
}
|
|
311
|
+
/** Execute a sell transaction for a token. */
|
|
312
|
+
async sell(mint, options) {
|
|
313
|
+
return this._http.post(`/api/tokens/${mint}/sell`, options);
|
|
314
|
+
}
|
|
315
|
+
/** Multi-wallet sell packed into Jito bundles. */
|
|
316
|
+
async bundleSell(mint, options) {
|
|
317
|
+
return this._http.post(`/api/tokens/${mint}/bundle-sell`, options);
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
// src/resources/jobs.ts
|
|
322
|
+
var Jobs = class {
|
|
323
|
+
constructor(_http) {
|
|
324
|
+
this._http = _http;
|
|
325
|
+
}
|
|
326
|
+
/** Get the current status of a job. */
|
|
327
|
+
async get(jobId) {
|
|
328
|
+
return this._http.get(`/api/jobs/${jobId}`);
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Poll a job until it completes or the timeout is reached.
|
|
332
|
+
*
|
|
333
|
+
* @param jobId - The job ID to poll.
|
|
334
|
+
* @param options - Polling configuration.
|
|
335
|
+
* @returns The final job status (completed).
|
|
336
|
+
* @throws {Error} If the job fails or the timeout is reached.
|
|
337
|
+
*
|
|
338
|
+
* @example
|
|
339
|
+
* ```ts
|
|
340
|
+
* const launch = await op.bundles.launch({ ... });
|
|
341
|
+
* const result = await op.jobs.poll(launch.jobId, {
|
|
342
|
+
* intervalMs: 2000,
|
|
343
|
+
* timeoutMs: 60000,
|
|
344
|
+
* onProgress: (s) => console.log(`Progress: ${s.progress}%`),
|
|
345
|
+
* });
|
|
346
|
+
* ```
|
|
347
|
+
*/
|
|
348
|
+
async poll(jobId, options) {
|
|
349
|
+
const intervalMs = options?.intervalMs ?? 1e3;
|
|
350
|
+
const timeoutMs = options?.timeoutMs ?? 3e4;
|
|
351
|
+
const signal = options?.signal;
|
|
352
|
+
const onProgress = options?.onProgress;
|
|
353
|
+
const deadline = Date.now() + timeoutMs;
|
|
354
|
+
while (Date.now() < deadline) {
|
|
355
|
+
if (signal?.aborted) {
|
|
356
|
+
throw new Error("Job polling aborted");
|
|
357
|
+
}
|
|
358
|
+
const status = await this.get(jobId);
|
|
359
|
+
onProgress?.(status);
|
|
360
|
+
if (status.status === "completed") {
|
|
361
|
+
return status;
|
|
362
|
+
}
|
|
363
|
+
if (status.status === "failed") {
|
|
364
|
+
throw new Error(status.error ?? `Job ${jobId} failed`);
|
|
365
|
+
}
|
|
366
|
+
await new Promise((resolve, reject) => {
|
|
367
|
+
const timer = setTimeout(resolve, intervalMs);
|
|
368
|
+
signal?.addEventListener(
|
|
369
|
+
"abort",
|
|
370
|
+
() => {
|
|
371
|
+
clearTimeout(timer);
|
|
372
|
+
reject(new Error("Job polling aborted"));
|
|
373
|
+
},
|
|
374
|
+
{ once: true }
|
|
375
|
+
);
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
throw new Error(`Job ${jobId} polling timed out after ${timeoutMs}ms`);
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
// src/resources/creator-fees.ts
|
|
383
|
+
var CreatorFees = class {
|
|
384
|
+
constructor(_http) {
|
|
385
|
+
this._http = _http;
|
|
386
|
+
}
|
|
387
|
+
/** Get accumulated creator fees for a given creator address. */
|
|
388
|
+
async getAccumulatedFees(address) {
|
|
389
|
+
return this._http.get("/api/creator-fees", { address });
|
|
390
|
+
}
|
|
391
|
+
/** Claim accumulated creator fees for a wallet you own. */
|
|
392
|
+
async claim(creatorAddress) {
|
|
393
|
+
return this._http.post("/api/creator-fees/claim", { creatorAddress });
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
// src/resources/bundles.ts
|
|
398
|
+
var Bundles = class {
|
|
399
|
+
constructor(_http) {
|
|
400
|
+
this._http = _http;
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Launch a coordinated token creation + multi-wallet bundle buy.
|
|
404
|
+
* Returns a job ID for polling.
|
|
405
|
+
*
|
|
406
|
+
* @example
|
|
407
|
+
* ```ts
|
|
408
|
+
* const { jobId } = await op.bundles.launch({
|
|
409
|
+
* devWalletId: 'wallet-1',
|
|
410
|
+
* buyWalletIds: ['wallet-2', 'wallet-3'],
|
|
411
|
+
* name: 'My Token',
|
|
412
|
+
* symbol: 'MTK',
|
|
413
|
+
* imageBase64: '...',
|
|
414
|
+
* imageType: 'image/png',
|
|
415
|
+
* walletBuyAmounts: ['500000000', '500000000'],
|
|
416
|
+
* });
|
|
417
|
+
* const result = await op.jobs.poll(jobId);
|
|
418
|
+
* ```
|
|
419
|
+
*/
|
|
420
|
+
async launch(options) {
|
|
421
|
+
return this._http.post("/api/tokens/bundle-launch", options);
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
|
|
425
|
+
// src/client.ts
|
|
426
|
+
var OpenPump = class {
|
|
427
|
+
wallets;
|
|
428
|
+
tokens;
|
|
429
|
+
trading;
|
|
430
|
+
jobs;
|
|
431
|
+
creatorFees;
|
|
432
|
+
bundles;
|
|
433
|
+
_http;
|
|
434
|
+
constructor(config) {
|
|
435
|
+
if (!config.apiKey) {
|
|
436
|
+
throw new Error("apiKey is required");
|
|
437
|
+
}
|
|
438
|
+
this._http = new HttpClient({
|
|
439
|
+
apiKey: config.apiKey,
|
|
440
|
+
baseUrl: config.baseUrl ?? "https://api.openpump.io",
|
|
441
|
+
timeout: config.timeout ?? 3e4
|
|
442
|
+
});
|
|
443
|
+
this.wallets = new Wallets(this._http);
|
|
444
|
+
this.tokens = new Tokens(this._http);
|
|
445
|
+
this.trading = new Trading(this._http);
|
|
446
|
+
this.jobs = new Jobs(this._http);
|
|
447
|
+
this.creatorFees = new CreatorFees(this._http);
|
|
448
|
+
this.bundles = new Bundles(this._http);
|
|
449
|
+
}
|
|
450
|
+
};
|
|
451
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
452
|
+
0 && (module.exports = {
|
|
453
|
+
AuthenticationError,
|
|
454
|
+
InsufficientFundsError,
|
|
455
|
+
NotFoundError,
|
|
456
|
+
OpenPump,
|
|
457
|
+
OpenPumpError,
|
|
458
|
+
RateLimitError,
|
|
459
|
+
TransactionError,
|
|
460
|
+
ValidationError
|
|
461
|
+
});
|
|
462
|
+
//# sourceMappingURL=index.cjs.map
|