@sun-protocol/sun-sdk-protocols 0.1.0-beta.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.
Files changed (60) hide show
  1. package/README.md +30 -0
  2. package/dist/chunk-5XDX5563.js +99 -0
  3. package/dist/chunk-5XDX5563.js.map +1 -0
  4. package/dist/chunk-C2YCVBPI.js +212 -0
  5. package/dist/chunk-C2YCVBPI.js.map +1 -0
  6. package/dist/chunk-ECCGOXNA.js +1317 -0
  7. package/dist/chunk-ECCGOXNA.js.map +1 -0
  8. package/dist/chunk-HD2S3Q7L.js +746 -0
  9. package/dist/chunk-HD2S3Q7L.js.map +1 -0
  10. package/dist/chunk-L5TZCDPH.js +561 -0
  11. package/dist/chunk-L5TZCDPH.js.map +1 -0
  12. package/dist/chunk-OM4OW4KB.js +224 -0
  13. package/dist/chunk-OM4OW4KB.js.map +1 -0
  14. package/dist/chunk-PEGREDLT.js +935 -0
  15. package/dist/chunk-PEGREDLT.js.map +1 -0
  16. package/dist/chunk-TSHXXRH2.js +103 -0
  17. package/dist/chunk-TSHXXRH2.js.map +1 -0
  18. package/dist/chunk-VFVKMC4H.js +521 -0
  19. package/dist/chunk-VFVKMC4H.js.map +1 -0
  20. package/dist/chunk-YMGZDXI4.js +1209 -0
  21. package/dist/chunk-YMGZDXI4.js.map +1 -0
  22. package/dist/common-8VQQ0FSU.d.cts +146 -0
  23. package/dist/common-8VQQ0FSU.d.ts +146 -0
  24. package/dist/execute-BNKh6dT6.d.cts +187 -0
  25. package/dist/execute-CVhcKZxF.d.ts +187 -0
  26. package/dist/index.cjs +5619 -0
  27. package/dist/index.cjs.map +1 -0
  28. package/dist/index.d.cts +139 -0
  29. package/dist/index.d.ts +139 -0
  30. package/dist/index.js +200 -0
  31. package/dist/index.js.map +1 -0
  32. package/dist/intents-BSXq1HvW.d.cts +200 -0
  33. package/dist/intents-CwOttD75.d.ts +200 -0
  34. package/dist/liquidity/index.cjs +2441 -0
  35. package/dist/liquidity/index.cjs.map +1 -0
  36. package/dist/liquidity/index.d.cts +83 -0
  37. package/dist/liquidity/index.d.ts +83 -0
  38. package/dist/liquidity/index.js +32 -0
  39. package/dist/liquidity/index.js.map +1 -0
  40. package/dist/positions/index.cjs +1544 -0
  41. package/dist/positions/index.cjs.map +1 -0
  42. package/dist/positions/index.d.cts +159 -0
  43. package/dist/positions/index.d.ts +159 -0
  44. package/dist/positions/index.js +25 -0
  45. package/dist/positions/index.js.map +1 -0
  46. package/dist/pump/index.cjs +1178 -0
  47. package/dist/pump/index.cjs.map +1 -0
  48. package/dist/pump/index.d.cts +16 -0
  49. package/dist/pump/index.d.ts +16 -0
  50. package/dist/pump/index.js +29 -0
  51. package/dist/pump/index.js.map +1 -0
  52. package/dist/swap/index.cjs +2259 -0
  53. package/dist/swap/index.cjs.map +1 -0
  54. package/dist/swap/index.d.cts +33 -0
  55. package/dist/swap/index.d.ts +33 -0
  56. package/dist/swap/index.js +61 -0
  57. package/dist/swap/index.js.map +1 -0
  58. package/dist/types-BTPdCC7k.d.cts +160 -0
  59. package/dist/types-BfrouFmO.d.ts +160 -0
  60. package/package.json +94 -0
@@ -0,0 +1,746 @@
1
+ import {
2
+ createDeferredV2SwapAction,
3
+ createV2SwapExecutor
4
+ } from "./chunk-TSHXXRH2.js";
5
+ import {
6
+ attachApprovalIntent,
7
+ executePlanAction,
8
+ executePlanTransactions,
9
+ executeTransactionPlan,
10
+ isTransactionPlan,
11
+ nextPlanId,
12
+ normalizeBaseUnitAmount,
13
+ normalizeRecipient,
14
+ normalizeTransactionValidForSeconds,
15
+ requireRuntime,
16
+ requireWalletSnapshot,
17
+ slippageToBips
18
+ } from "./chunk-VFVKMC4H.js";
19
+
20
+ // src/pump/execute.ts
21
+ function createPumpExecutor(context) {
22
+ return createV2SwapExecutor(context);
23
+ }
24
+
25
+ // src/pump/intents.ts
26
+ var SUNPUMP_LAUNCHPAD_PROTOCOL_ID = "sunpump-launchpad";
27
+ var SUNPUMP_V2_PROTOCOL_ID = "sunpump-v2";
28
+ function pumpIntentScope(protocol, operation) {
29
+ return { domain: "pump", protocol, operation };
30
+ }
31
+
32
+ // src/pump/plan-buy.ts
33
+ import {
34
+ applySlippageMax,
35
+ applySlippageMin,
36
+ createLaunchpadBuyAction,
37
+ getLaunchpadTokenState,
38
+ LaunchpadTokenState,
39
+ quoteLaunchpadBuyExactToken,
40
+ quoteLaunchpadBuyExactTrx
41
+ } from "@sun-protocol/sun-sdk-launchpad";
42
+ import { SDKError as SDKError2, assertTronAddress } from "@sun-protocol/sun-sdk-core";
43
+
44
+ // src/pump/v2.ts
45
+ import {
46
+ buildV2RouterAmountsInRead,
47
+ buildV2RouterAmountsOutRead,
48
+ normalizeV2AmountsResult
49
+ } from "@sun-protocol/sun-sdk-sunswap-v2";
50
+ import { SDKError } from "@sun-protocol/sun-sdk-core";
51
+ function pumpV2BuyPath(context, token) {
52
+ return [context.chain.contracts.wtrx, token];
53
+ }
54
+ function pumpV2SellPath(context, token) {
55
+ return [token, context.chain.contracts.wtrx];
56
+ }
57
+ async function readPumpV2AmountsOut(context, runtime, amountIn, path) {
58
+ const result = await runtime.readContract(
59
+ buildV2RouterAmountsOutRead({
60
+ network: context.network,
61
+ amountIn,
62
+ path
63
+ })
64
+ );
65
+ return normalizeV2AmountsResult(result);
66
+ }
67
+ async function readPumpV2AmountsIn(context, runtime, amountOut, path) {
68
+ const result = await runtime.readContract(
69
+ buildV2RouterAmountsInRead({
70
+ network: context.network,
71
+ amountOut,
72
+ path
73
+ })
74
+ );
75
+ return normalizeV2AmountsResult(result);
76
+ }
77
+ function requirePumpV2Amount(amounts, index, operation) {
78
+ const amount = amounts[index];
79
+ if (amount === void 0) {
80
+ throw new SDKError("SDK_NO_ROUTE", "SunSwap V2 returned no Pump route amount", {
81
+ operation,
82
+ index,
83
+ amounts
84
+ });
85
+ }
86
+ return amount;
87
+ }
88
+
89
+ // src/pump/plan-buy.ts
90
+ function normalizePumpBuyMode(input) {
91
+ const trxAmount = input.trxAmount;
92
+ const tokenAmount = input.tokenAmount;
93
+ if (trxAmount === void 0 === (tokenAmount === void 0)) {
94
+ throw new SDKError2("SDK_INVALID_ARGUMENT", "Pump buy requires exactly one of trxAmount or tokenAmount", {
95
+ trxAmount,
96
+ tokenAmount
97
+ });
98
+ }
99
+ if (trxAmount !== void 0) {
100
+ return {
101
+ kind: "exact-trx",
102
+ trxAmount: normalizeBaseUnitAmount(trxAmount, "trxAmount")
103
+ };
104
+ }
105
+ if (tokenAmount === void 0) {
106
+ throw new SDKError2("SDK_INVALID_ARGUMENT", "Pump buy requires tokenAmount", {
107
+ trxAmount,
108
+ tokenAmount
109
+ });
110
+ }
111
+ return {
112
+ kind: "exact-token",
113
+ tokenAmount: normalizeBaseUnitAmount(tokenAmount, "tokenAmount")
114
+ };
115
+ }
116
+ async function planPumpBuy(context, input) {
117
+ const runtime = requireRuntime(context, "Pump buy planning");
118
+ const { address: owner } = await requireWalletSnapshot(context, "Pump buy planning");
119
+ const token = assertTronAddress(input.token, "token");
120
+ const mode = normalizePumpBuyMode(input);
121
+ const state = await getLaunchpadTokenState(runtime, token);
122
+ if (state !== LaunchpadTokenState.TRADING && state !== LaunchpadTokenState.LAUNCHED) {
123
+ throw new SDKError2("SDK_CONTRACT_ERROR", "Token is not trading on SunPump", {
124
+ token,
125
+ state
126
+ });
127
+ }
128
+ const slippageBips = slippageToBips(input.slippage ?? "5%");
129
+ if (state === LaunchpadTokenState.TRADING) {
130
+ let trxAmount;
131
+ let quotedTokenAmount;
132
+ let fee;
133
+ let operation;
134
+ let requestedTokenAmount;
135
+ if (mode.kind === "exact-trx") {
136
+ const quote = await quoteLaunchpadBuyExactTrx(runtime, token, mode.trxAmount);
137
+ trxAmount = mode.trxAmount;
138
+ quotedTokenAmount = quote.tokenAmount;
139
+ fee = quote.fee;
140
+ operation = "launchpad-buy-exact-trx";
141
+ } else {
142
+ const quote = await quoteLaunchpadBuyExactToken(runtime, token, mode.tokenAmount);
143
+ trxAmount = quote.trxAmount;
144
+ quotedTokenAmount = mode.tokenAmount;
145
+ fee = quote.fee;
146
+ operation = "launchpad-buy-exact-token";
147
+ requestedTokenAmount = mode.tokenAmount;
148
+ }
149
+ const minTokenOut = applySlippageMin(BigInt(quotedTokenAmount), slippageBips).toString();
150
+ const transaction2 = {
151
+ ...createLaunchpadBuyAction({
152
+ launchpad: context.chain.contracts.launchpad,
153
+ token,
154
+ trxAmount,
155
+ minTokenOut
156
+ }),
157
+ intent: {
158
+ kind: "pump-buy",
159
+ scope: pumpIntentScope(SUNPUMP_LAUNCHPAD_PROTOCOL_ID, operation),
160
+ token
161
+ }
162
+ };
163
+ return {
164
+ id: nextPlanId(context, "pump-buy"),
165
+ kind: "pump",
166
+ network: context.network,
167
+ owner,
168
+ summary: {
169
+ title: "Buy SunPump token",
170
+ lines: [`Spend ${trxAmount} sun`, `Receive at least ${minTokenOut} token units`]
171
+ },
172
+ approvals: [],
173
+ transactions: [transaction2],
174
+ metadata: {
175
+ operation,
176
+ token,
177
+ trxAmount,
178
+ ...requestedTokenAmount ? { tokenAmount: requestedTokenAmount } : {},
179
+ quotedTokenAmount,
180
+ quotedTrxAmount: trxAmount,
181
+ fee,
182
+ minTokenOut,
183
+ slippageBips
184
+ }
185
+ };
186
+ }
187
+ const path = pumpV2BuyPath(context, token);
188
+ const recipient = await normalizeRecipient(context, input.recipient, "Pump V2 buy recipient", owner);
189
+ const transactionValidForSeconds = normalizeTransactionValidForSeconds(input.transactionValidForSeconds);
190
+ if (mode.kind === "exact-trx") {
191
+ const amounts2 = await readPumpV2AmountsOut(context, runtime, mode.trxAmount, path);
192
+ const quotedTokenAmount = requirePumpV2Amount(amounts2, amounts2.length - 1, "pump-v2-buy-exact-trx");
193
+ const minTokenOut = applySlippageMin(BigInt(quotedTokenAmount), slippageBips).toString();
194
+ const transaction2 = {
195
+ ...createDeferredV2SwapAction({
196
+ data: {
197
+ operation: "swap-exact-eth-for-tokens",
198
+ amountIn: mode.trxAmount,
199
+ amountOutMin: minTokenOut,
200
+ path,
201
+ recipient,
202
+ transactionValidForSeconds
203
+ }
204
+ }),
205
+ intent: {
206
+ kind: "pump-buy",
207
+ scope: pumpIntentScope(SUNPUMP_V2_PROTOCOL_ID, "buy-exact-trx"),
208
+ token
209
+ }
210
+ };
211
+ return {
212
+ id: nextPlanId(context, "pump-buy"),
213
+ kind: "pump",
214
+ network: context.network,
215
+ owner,
216
+ summary: {
217
+ title: "Buy launched Pump token",
218
+ lines: [`Spend ${mode.trxAmount} sun`, `Receive at least ${minTokenOut} token units`]
219
+ },
220
+ approvals: [],
221
+ transactions: [transaction2],
222
+ metadata: {
223
+ operation: "pump-v2-buy-exact-trx",
224
+ token,
225
+ trxAmount: mode.trxAmount,
226
+ quotedTokenAmount,
227
+ minTokenOut,
228
+ slippageBips,
229
+ path,
230
+ recipient,
231
+ transactionValidForSeconds
232
+ }
233
+ };
234
+ }
235
+ const amounts = await readPumpV2AmountsIn(context, runtime, mode.tokenAmount, path);
236
+ const quotedTrxAmount = requirePumpV2Amount(amounts, 0, "pump-v2-buy-exact-token");
237
+ const maxTrxIn = applySlippageMax(BigInt(quotedTrxAmount), slippageBips).toString();
238
+ const transaction = {
239
+ ...createDeferredV2SwapAction({
240
+ data: {
241
+ operation: "swap-eth-for-exact-tokens",
242
+ amountOut: mode.tokenAmount,
243
+ amountInMax: maxTrxIn,
244
+ path,
245
+ recipient,
246
+ transactionValidForSeconds
247
+ }
248
+ }),
249
+ intent: {
250
+ kind: "pump-buy",
251
+ scope: pumpIntentScope(SUNPUMP_V2_PROTOCOL_ID, "buy-exact-token"),
252
+ token
253
+ }
254
+ };
255
+ return {
256
+ id: nextPlanId(context, "pump-buy"),
257
+ kind: "pump",
258
+ network: context.network,
259
+ owner,
260
+ summary: {
261
+ title: "Buy launched Pump token",
262
+ lines: [`Spend at most ${maxTrxIn} sun`, `Receive ${mode.tokenAmount} token units`]
263
+ },
264
+ approvals: [],
265
+ transactions: [transaction],
266
+ metadata: {
267
+ operation: "pump-v2-buy-exact-token",
268
+ token,
269
+ tokenAmount: mode.tokenAmount,
270
+ quotedTrxAmount,
271
+ maxTrxIn,
272
+ slippageBips,
273
+ path,
274
+ recipient,
275
+ transactionValidForSeconds
276
+ }
277
+ };
278
+ }
279
+
280
+ // src/pump/buy.ts
281
+ import {
282
+ getLaunchpadTokenState as getLaunchpadTokenState2,
283
+ LaunchpadTokenState as LaunchpadTokenState2,
284
+ quoteLaunchpadBuyExactToken as quoteLaunchpadBuyExactToken2,
285
+ quoteLaunchpadBuyExactTrx as quoteLaunchpadBuyExactTrx2
286
+ } from "@sun-protocol/sun-sdk-launchpad";
287
+ import {
288
+ SDKError as SDKError4,
289
+ assertTronAddress as assertTronAddress2
290
+ } from "@sun-protocol/sun-sdk-core";
291
+
292
+ // src/pump/workflow.ts
293
+ import { SDKError as SDKError3 } from "@sun-protocol/sun-sdk-core";
294
+ function assertPumpPlan(plan, operations, clientName) {
295
+ const operation = plan.metadata.operation;
296
+ if (plan.kind !== "pump" || typeof operation !== "string" || !operations.includes(operation) || plan.transactions.length === 0) {
297
+ throw new SDKError3("SDK_INVALID_ARGUMENT", `Expected a ${clientName} plan`, {
298
+ planId: plan.id,
299
+ kind: plan.kind,
300
+ operation,
301
+ transactionCount: plan.transactions.length
302
+ });
303
+ }
304
+ }
305
+
306
+ // src/pump/buy.ts
307
+ var PUMP_BUY_OPERATIONS = [
308
+ "launchpad-buy-exact-trx",
309
+ "launchpad-buy-exact-token",
310
+ "pump-v2-buy-exact-trx",
311
+ "pump-v2-buy-exact-token"
312
+ ];
313
+ async function quotePumpBuyByTrx(context, input) {
314
+ const runtime = requireRuntime(context, "Pump buy quote");
315
+ const token = assertTronAddress2(input.token, "token");
316
+ const trxAmount = normalizeBaseUnitAmount(input.trxAmount, "trxAmount");
317
+ const state = await getLaunchpadTokenState2(runtime, token);
318
+ if (state === LaunchpadTokenState2.TRADING) {
319
+ return quoteLaunchpadBuyExactTrx2(runtime, token, trxAmount);
320
+ }
321
+ if (state === LaunchpadTokenState2.LAUNCHED) {
322
+ const path = pumpV2BuyPath(context, token);
323
+ const amounts = await readPumpV2AmountsOut(context, runtime, trxAmount, path);
324
+ return {
325
+ tokenAmount: requirePumpV2Amount(amounts, amounts.length - 1, "pump-v2-buy-quote"),
326
+ fee: "0"
327
+ };
328
+ }
329
+ throw new SDKError4("SDK_CONTRACT_ERROR", "Token is not trading on SunPump", { token, state });
330
+ }
331
+ async function quotePumpBuyByToken(context, input) {
332
+ const runtime = requireRuntime(context, "Pump exact-token buy quote");
333
+ const token = assertTronAddress2(input.token, "token");
334
+ const tokenAmount = normalizeBaseUnitAmount(input.tokenAmount, "tokenAmount");
335
+ const state = await getLaunchpadTokenState2(runtime, token);
336
+ if (state === LaunchpadTokenState2.TRADING) {
337
+ return quoteLaunchpadBuyExactToken2(runtime, token, tokenAmount);
338
+ }
339
+ if (state === LaunchpadTokenState2.LAUNCHED) {
340
+ const path = pumpV2BuyPath(context, token);
341
+ const amounts = await readPumpV2AmountsIn(context, runtime, tokenAmount, path);
342
+ return {
343
+ trxAmount: requirePumpV2Amount(amounts, 0, "pump-v2-buy-exact-token-quote"),
344
+ fee: "0"
345
+ };
346
+ }
347
+ throw new SDKError4("SDK_CONTRACT_ERROR", "Token is not trading on SunPump", { token, state });
348
+ }
349
+ var PumpBuyClient = class {
350
+ constructor(context) {
351
+ this.context = context;
352
+ }
353
+ context;
354
+ quote(input) {
355
+ const candidate = input;
356
+ const hasTrxAmount = candidate.trxAmount !== void 0;
357
+ const hasTokenAmount = candidate.tokenAmount !== void 0;
358
+ if (hasTrxAmount === hasTokenAmount) {
359
+ throw new SDKError4(
360
+ "SDK_INVALID_ARGUMENT",
361
+ "Pump buy quote requires exactly one of trxAmount or tokenAmount"
362
+ );
363
+ }
364
+ return hasTrxAmount ? quotePumpBuyByTrx(this.context, input) : quotePumpBuyByToken(this.context, input);
365
+ }
366
+ plan(input) {
367
+ return planPumpBuy(this.context, input);
368
+ }
369
+ executeAction(action) {
370
+ return executePlanAction(action, createPumpExecutor(this.context));
371
+ }
372
+ submit(plan) {
373
+ assertPumpPlan(plan, PUMP_BUY_OPERATIONS, "Pump buy");
374
+ return executePlanTransactions(plan, createPumpExecutor(this.context));
375
+ }
376
+ async execute(input) {
377
+ const plan = isTransactionPlan(input) ? input : await planPumpBuy(this.context, input);
378
+ assertPumpPlan(plan, PUMP_BUY_OPERATIONS, "Pump buy");
379
+ return executeTransactionPlan(plan, createPumpExecutor(this.context));
380
+ }
381
+ };
382
+
383
+ // src/pump/launch.ts
384
+ import { createHttpRequestAction, SDKError as SDKError5 } from "@sun-protocol/sun-sdk-core";
385
+ function planPumpAgentLaunch(context, input) {
386
+ const baseUrl = context.endpoints.sunPump;
387
+ if (!baseUrl) {
388
+ throw new SDKError5("SDK_UNSUPPORTED_NETWORK", "SunPump API is unavailable on this network", {
389
+ network: context.network
390
+ });
391
+ }
392
+ const normalizedBaseUrl = baseUrl.replace(/\/+$/, "");
393
+ const transaction = createHttpRequestAction({
394
+ id: `pump-agent-launch-${input.symbol}`,
395
+ request: {
396
+ method: "POST",
397
+ url: `${normalizedBaseUrl}/ai/agentTokenLaunch`,
398
+ headers: {
399
+ Accept: "application/json",
400
+ "Content-Type": "application/json"
401
+ },
402
+ body: input
403
+ }
404
+ });
405
+ return {
406
+ id: nextPlanId(context, "pump-launch"),
407
+ kind: "pump",
408
+ network: context.network,
409
+ summary: {
410
+ title: "Launch SunPump token",
411
+ lines: [`Launch ${input.name} (${input.symbol})`]
412
+ },
413
+ approvals: [],
414
+ transactions: [transaction],
415
+ metadata: {
416
+ operation: "pump-agent-launch",
417
+ symbol: input.symbol
418
+ }
419
+ };
420
+ }
421
+
422
+ // src/pump/launch-client.ts
423
+ var PUMP_LAUNCH_OPERATIONS = ["pump-agent-launch"];
424
+ var PumpLaunchClient = class {
425
+ constructor(context) {
426
+ this.context = context;
427
+ }
428
+ context;
429
+ plan(input) {
430
+ return Promise.resolve(planPumpAgentLaunch(this.context, input));
431
+ }
432
+ executeAction(action) {
433
+ return executePlanAction(action, createPumpExecutor(this.context));
434
+ }
435
+ submit(plan) {
436
+ assertPumpPlan(plan, PUMP_LAUNCH_OPERATIONS, "Pump launch");
437
+ return executePlanTransactions(plan, createPumpExecutor(this.context));
438
+ }
439
+ async execute(input) {
440
+ const plan = isTransactionPlan(input) ? input : planPumpAgentLaunch(this.context, input);
441
+ assertPumpPlan(plan, PUMP_LAUNCH_OPERATIONS, "Pump launch");
442
+ return executeTransactionPlan(plan, createPumpExecutor(this.context));
443
+ }
444
+ };
445
+
446
+ // src/pump/plan-sell.ts
447
+ import {
448
+ applySlippageMin as applySlippageMin2,
449
+ createLaunchpadApproveAction,
450
+ createLaunchpadSellAction,
451
+ getLaunchpadTokenState as getLaunchpadTokenState3,
452
+ LaunchpadTokenState as LaunchpadTokenState3,
453
+ quoteLaunchpadSellExactToken,
454
+ readLaunchpadAllowance
455
+ } from "@sun-protocol/sun-sdk-launchpad";
456
+ import {
457
+ SDKError as SDKError6,
458
+ assertTronAddress as assertTronAddress3,
459
+ createApproveAction
460
+ } from "@sun-protocol/sun-sdk-core";
461
+ async function planPumpSell(context, input) {
462
+ const runtime = requireRuntime(context, "Pump sell planning");
463
+ const { address: walletAddress } = await requireWalletSnapshot(context, "Pump sell planning");
464
+ const token = assertTronAddress3(input.token, "token");
465
+ const tokenAmount = normalizeBaseUnitAmount(input.tokenAmount, "tokenAmount");
466
+ const state = await getLaunchpadTokenState3(runtime, token);
467
+ if (state !== LaunchpadTokenState3.TRADING && state !== LaunchpadTokenState3.LAUNCHED) {
468
+ throw new SDKError6("SDK_CONTRACT_ERROR", "Token is not trading on SunPump", {
469
+ token,
470
+ state
471
+ });
472
+ }
473
+ const slippageBips = slippageToBips(input.slippage ?? "5%");
474
+ const approvalMode = input.approval ?? "auto";
475
+ const approvals = [];
476
+ const owner = input.owner !== void 0 ? assertTronAddress3(input.owner, "owner") : walletAddress;
477
+ if (owner !== walletAddress) {
478
+ throw new SDKError6("SDK_WALLET_ACCOUNT_MISMATCH", "Pump sell owner does not match the connected wallet", {
479
+ expectedAddress: owner,
480
+ actualAddress: walletAddress
481
+ });
482
+ }
483
+ let allowance;
484
+ const spender = state === LaunchpadTokenState3.TRADING ? context.chain.contracts.launchpad : context.chain.contracts.sunswapV2Router;
485
+ const scope = pumpIntentScope(
486
+ state === LaunchpadTokenState3.TRADING ? SUNPUMP_LAUNCHPAD_PROTOCOL_ID : SUNPUMP_V2_PROTOCOL_ID,
487
+ "sell-exact-token"
488
+ );
489
+ if (approvalMode !== "none") {
490
+ allowance = await readLaunchpadAllowance(
491
+ runtime,
492
+ token,
493
+ owner,
494
+ spender
495
+ );
496
+ if (BigInt(allowance) < BigInt(tokenAmount)) {
497
+ approvals.push(state === LaunchpadTokenState3.TRADING ? createLaunchpadApproveAction(token, spender) : createApproveAction({
498
+ id: `pump-v2-approve-${token}`,
499
+ target: token,
500
+ spender,
501
+ amount: tokenAmount
502
+ }));
503
+ }
504
+ }
505
+ if (state === LaunchpadTokenState3.TRADING) {
506
+ const quote = await quoteLaunchpadSellExactToken(runtime, token, tokenAmount);
507
+ const minTrxOut2 = applySlippageMin2(BigInt(quote.trxAmount), slippageBips).toString();
508
+ const transaction2 = {
509
+ ...createLaunchpadSellAction({
510
+ launchpad: context.chain.contracts.launchpad,
511
+ token,
512
+ tokenAmount,
513
+ minTrxOut: minTrxOut2
514
+ }),
515
+ intent: {
516
+ kind: "pump-sell",
517
+ scope,
518
+ token
519
+ }
520
+ };
521
+ return {
522
+ id: nextPlanId(context, "pump-sell"),
523
+ kind: "pump",
524
+ network: context.network,
525
+ owner,
526
+ summary: {
527
+ title: "Sell SunPump token",
528
+ lines: [`Sell ${tokenAmount} token units`, `Receive at least ${minTrxOut2} sun`]
529
+ },
530
+ approvals: attachApprovalIntent(approvals, scope, token),
531
+ transactions: [transaction2],
532
+ metadata: {
533
+ operation: "launchpad-sell-exact-token",
534
+ token,
535
+ tokenAmount,
536
+ quotedTrxAmount: quote.trxAmount,
537
+ fee: quote.fee,
538
+ minTrxOut: minTrxOut2,
539
+ slippageBips,
540
+ approvalMode,
541
+ spender,
542
+ ...owner ? { owner } : {},
543
+ ...allowance ? { allowance } : {}
544
+ }
545
+ };
546
+ }
547
+ const path = pumpV2SellPath(context, token);
548
+ const amounts = await readPumpV2AmountsOut(context, runtime, tokenAmount, path);
549
+ const quotedTrxAmount = requirePumpV2Amount(amounts, amounts.length - 1, "pump-v2-sell-exact-token");
550
+ const minTrxOut = applySlippageMin2(BigInt(quotedTrxAmount), slippageBips).toString();
551
+ const recipient = await normalizeRecipient(context, input.recipient, "Pump V2 sell recipient", owner);
552
+ const transactionValidForSeconds = normalizeTransactionValidForSeconds(input.transactionValidForSeconds);
553
+ const transaction = {
554
+ ...createDeferredV2SwapAction({
555
+ data: {
556
+ operation: "swap-exact-tokens-for-eth",
557
+ amountIn: tokenAmount,
558
+ amountOutMin: minTrxOut,
559
+ path,
560
+ recipient,
561
+ transactionValidForSeconds
562
+ }
563
+ }),
564
+ intent: {
565
+ kind: "pump-sell",
566
+ scope,
567
+ token
568
+ }
569
+ };
570
+ return {
571
+ id: nextPlanId(context, "pump-sell"),
572
+ kind: "pump",
573
+ network: context.network,
574
+ owner,
575
+ summary: {
576
+ title: "Sell launched Pump token",
577
+ lines: [`Sell ${tokenAmount} token units`, `Receive at least ${minTrxOut} sun`]
578
+ },
579
+ approvals: attachApprovalIntent(approvals, scope, token),
580
+ transactions: [transaction],
581
+ metadata: {
582
+ operation: "pump-v2-sell-exact-token",
583
+ token,
584
+ tokenAmount,
585
+ quotedTrxAmount,
586
+ minTrxOut,
587
+ slippageBips,
588
+ approvalMode,
589
+ spender,
590
+ path,
591
+ recipient,
592
+ transactionValidForSeconds,
593
+ ...owner ? { owner } : {},
594
+ ...allowance ? { allowance } : {}
595
+ }
596
+ };
597
+ }
598
+
599
+ // src/pump/sell.ts
600
+ import {
601
+ getLaunchpadTokenState as getLaunchpadTokenState4,
602
+ LaunchpadTokenState as LaunchpadTokenState4,
603
+ quoteLaunchpadSellExactToken as quoteLaunchpadSellExactToken2
604
+ } from "@sun-protocol/sun-sdk-launchpad";
605
+ import {
606
+ SDKError as SDKError7,
607
+ assertTronAddress as assertTronAddress4
608
+ } from "@sun-protocol/sun-sdk-core";
609
+ var PUMP_SELL_OPERATIONS = [
610
+ "launchpad-sell-exact-token",
611
+ "pump-v2-sell-exact-token"
612
+ ];
613
+ async function quotePumpSell(context, input) {
614
+ const runtime = requireRuntime(context, "Pump sell quote");
615
+ const token = assertTronAddress4(input.token, "token");
616
+ const tokenAmount = normalizeBaseUnitAmount(input.tokenAmount, "tokenAmount");
617
+ const state = await getLaunchpadTokenState4(runtime, token);
618
+ if (state === LaunchpadTokenState4.TRADING) {
619
+ return quoteLaunchpadSellExactToken2(runtime, token, tokenAmount);
620
+ }
621
+ if (state === LaunchpadTokenState4.LAUNCHED) {
622
+ const path = pumpV2SellPath(context, token);
623
+ const amounts = await readPumpV2AmountsOut(context, runtime, tokenAmount, path);
624
+ return {
625
+ trxAmount: requirePumpV2Amount(amounts, amounts.length - 1, "pump-v2-sell-quote"),
626
+ fee: "0"
627
+ };
628
+ }
629
+ throw new SDKError7("SDK_CONTRACT_ERROR", "Token is not trading on SunPump", { token, state });
630
+ }
631
+ var PumpSellClient = class {
632
+ constructor(context) {
633
+ this.context = context;
634
+ }
635
+ context;
636
+ quote(input) {
637
+ return quotePumpSell(this.context, input);
638
+ }
639
+ plan(input) {
640
+ return planPumpSell(this.context, input);
641
+ }
642
+ executeAction(action) {
643
+ return executePlanAction(action, createPumpExecutor(this.context));
644
+ }
645
+ submit(plan) {
646
+ assertPumpPlan(plan, PUMP_SELL_OPERATIONS, "Pump sell");
647
+ return executePlanTransactions(plan, createPumpExecutor(this.context));
648
+ }
649
+ async execute(input) {
650
+ const plan = isTransactionPlan(input) ? input : await planPumpSell(this.context, input);
651
+ assertPumpPlan(plan, PUMP_SELL_OPERATIONS, "Pump sell");
652
+ return executeTransactionPlan(plan, createPumpExecutor(this.context));
653
+ }
654
+ };
655
+
656
+ // src/pump/client.ts
657
+ import {
658
+ getLaunchpadTokenBalance,
659
+ getLaunchpadTokenInfo,
660
+ getLaunchpadTokenState as getLaunchpadTokenState5,
661
+ readLaunchpadAllowance as readLaunchpadAllowance2
662
+ } from "@sun-protocol/sun-sdk-launchpad";
663
+ import { SDKError as SDKError8, assertTronAddress as assertTronAddress5 } from "@sun-protocol/sun-sdk-core";
664
+ var PumpClient = class {
665
+ constructor(context) {
666
+ this.context = context;
667
+ this.buy = new PumpBuyClient(context);
668
+ this.sell = new PumpSellClient(context);
669
+ this.launch = new PumpLaunchClient(context);
670
+ }
671
+ context;
672
+ buy;
673
+ sell;
674
+ launch;
675
+ tokens = {
676
+ list: async (query = {}) => this.requireApi().listTokens(query),
677
+ get: async (token) => this.requireApi().getToken(token),
678
+ search: async (query = {}) => this.requireApi().searchTokens(query),
679
+ searchV2: async (query = {}) => this.requireApi().searchTokensV2(query),
680
+ byOwner: async (query) => this.requireApi().tokensByOwner(query),
681
+ holders: async (query) => this.requireApi().tokenHolders(query),
682
+ holdersV2: async (query) => this.requireApi().tokenHoldersV2(query),
683
+ favors: async (query) => this.requireApi().userFavors(query),
684
+ ranking: async (query) => this.requireApi().ranking(query),
685
+ kingOfHill: async () => this.requireApi().kingOfHill(),
686
+ pumpList: async () => this.requireApi().pumpTokenList(),
687
+ transactions: async (token, query = {}) => this.requireApi().tokenTransactions(token, query),
688
+ ownerTransactions: async (owner, query = {}) => this.requireApi().userTransactions(owner, query)
689
+ };
690
+ state(input) {
691
+ return getLaunchpadTokenState5(
692
+ requireRuntime(this.context, "Pump state read"),
693
+ assertTronAddress5(input.token, "token")
694
+ );
695
+ }
696
+ info(input) {
697
+ return getLaunchpadTokenInfo(
698
+ requireRuntime(this.context, "Pump token info read"),
699
+ assertTronAddress5(input.token, "token")
700
+ );
701
+ }
702
+ balance(input) {
703
+ return getLaunchpadTokenBalance(
704
+ requireRuntime(this.context, "Pump balance read"),
705
+ assertTronAddress5(input.token, "token"),
706
+ input.owner
707
+ );
708
+ }
709
+ allowance(input) {
710
+ return readLaunchpadAllowance2(
711
+ requireRuntime(this.context, "Pump allowance read"),
712
+ assertTronAddress5(input.token, "token"),
713
+ input.owner,
714
+ input.spender ?? this.context.chain.contracts.launchpad
715
+ );
716
+ }
717
+ async portfolio(owner, query = {}) {
718
+ return this.requireApi().portfolio(owner, query);
719
+ }
720
+ requireApi() {
721
+ if (!this.context.sunPumpApi) {
722
+ throw new SDKError8("SDK_UNSUPPORTED_NETWORK", "SunPump API is unavailable on this network", {
723
+ network: this.context.network
724
+ });
725
+ }
726
+ return this.context.sunPumpApi;
727
+ }
728
+ };
729
+ function createPumpClient(context) {
730
+ return new PumpClient(context);
731
+ }
732
+
733
+ export {
734
+ createPumpExecutor,
735
+ SUNPUMP_LAUNCHPAD_PROTOCOL_ID,
736
+ SUNPUMP_V2_PROTOCOL_ID,
737
+ planPumpBuy,
738
+ PumpBuyClient,
739
+ planPumpAgentLaunch,
740
+ PumpLaunchClient,
741
+ planPumpSell,
742
+ PumpSellClient,
743
+ PumpClient,
744
+ createPumpClient
745
+ };
746
+ //# sourceMappingURL=chunk-HD2S3Q7L.js.map