@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.
- package/README.md +30 -0
- package/dist/chunk-5XDX5563.js +99 -0
- package/dist/chunk-5XDX5563.js.map +1 -0
- package/dist/chunk-C2YCVBPI.js +212 -0
- package/dist/chunk-C2YCVBPI.js.map +1 -0
- package/dist/chunk-ECCGOXNA.js +1317 -0
- package/dist/chunk-ECCGOXNA.js.map +1 -0
- package/dist/chunk-HD2S3Q7L.js +746 -0
- package/dist/chunk-HD2S3Q7L.js.map +1 -0
- package/dist/chunk-L5TZCDPH.js +561 -0
- package/dist/chunk-L5TZCDPH.js.map +1 -0
- package/dist/chunk-OM4OW4KB.js +224 -0
- package/dist/chunk-OM4OW4KB.js.map +1 -0
- package/dist/chunk-PEGREDLT.js +935 -0
- package/dist/chunk-PEGREDLT.js.map +1 -0
- package/dist/chunk-TSHXXRH2.js +103 -0
- package/dist/chunk-TSHXXRH2.js.map +1 -0
- package/dist/chunk-VFVKMC4H.js +521 -0
- package/dist/chunk-VFVKMC4H.js.map +1 -0
- package/dist/chunk-YMGZDXI4.js +1209 -0
- package/dist/chunk-YMGZDXI4.js.map +1 -0
- package/dist/common-8VQQ0FSU.d.cts +146 -0
- package/dist/common-8VQQ0FSU.d.ts +146 -0
- package/dist/execute-BNKh6dT6.d.cts +187 -0
- package/dist/execute-CVhcKZxF.d.ts +187 -0
- package/dist/index.cjs +5619 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +139 -0
- package/dist/index.d.ts +139 -0
- package/dist/index.js +200 -0
- package/dist/index.js.map +1 -0
- package/dist/intents-BSXq1HvW.d.cts +200 -0
- package/dist/intents-CwOttD75.d.ts +200 -0
- package/dist/liquidity/index.cjs +2441 -0
- package/dist/liquidity/index.cjs.map +1 -0
- package/dist/liquidity/index.d.cts +83 -0
- package/dist/liquidity/index.d.ts +83 -0
- package/dist/liquidity/index.js +32 -0
- package/dist/liquidity/index.js.map +1 -0
- package/dist/positions/index.cjs +1544 -0
- package/dist/positions/index.cjs.map +1 -0
- package/dist/positions/index.d.cts +159 -0
- package/dist/positions/index.d.ts +159 -0
- package/dist/positions/index.js +25 -0
- package/dist/positions/index.js.map +1 -0
- package/dist/pump/index.cjs +1178 -0
- package/dist/pump/index.cjs.map +1 -0
- package/dist/pump/index.d.cts +16 -0
- package/dist/pump/index.d.ts +16 -0
- package/dist/pump/index.js +29 -0
- package/dist/pump/index.js.map +1 -0
- package/dist/swap/index.cjs +2259 -0
- package/dist/swap/index.cjs.map +1 -0
- package/dist/swap/index.d.cts +33 -0
- package/dist/swap/index.d.ts +33 -0
- package/dist/swap/index.js +61 -0
- package/dist/swap/index.js.map +1 -0
- package/dist/types-BTPdCC7k.d.cts +160 -0
- package/dist/types-BfrouFmO.d.ts +160 -0
- package/package.json +94 -0
|
@@ -0,0 +1,1178 @@
|
|
|
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/pump/index.ts
|
|
21
|
+
var pump_exports = {};
|
|
22
|
+
__export(pump_exports, {
|
|
23
|
+
PumpBuyClient: () => PumpBuyClient,
|
|
24
|
+
PumpClient: () => PumpClient,
|
|
25
|
+
PumpLaunchClient: () => PumpLaunchClient,
|
|
26
|
+
PumpSellClient: () => PumpSellClient,
|
|
27
|
+
SUNPUMP_LAUNCHPAD_PROTOCOL_ID: () => SUNPUMP_LAUNCHPAD_PROTOCOL_ID,
|
|
28
|
+
SUNPUMP_V2_PROTOCOL_ID: () => SUNPUMP_V2_PROTOCOL_ID,
|
|
29
|
+
createPumpClient: () => createPumpClient,
|
|
30
|
+
createPumpExecutor: () => createPumpExecutor,
|
|
31
|
+
planPumpAgentLaunch: () => planPumpAgentLaunch,
|
|
32
|
+
planPumpBuy: () => planPumpBuy,
|
|
33
|
+
planPumpSell: () => planPumpSell
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(pump_exports);
|
|
36
|
+
|
|
37
|
+
// src/pump/client.ts
|
|
38
|
+
var import_sun_sdk_launchpad5 = require("@sun-protocol/sun-sdk-launchpad");
|
|
39
|
+
var import_sun_sdk_core14 = require("@sun-protocol/sun-sdk-core");
|
|
40
|
+
|
|
41
|
+
// src/context.ts
|
|
42
|
+
var import_sun_sdk_api2 = require("@sun-protocol/sun-sdk-api");
|
|
43
|
+
var import_sun_sdk_chains = require("@sun-protocol/sun-sdk-chains");
|
|
44
|
+
var import_sun_sdk_core2 = require("@sun-protocol/sun-sdk-core");
|
|
45
|
+
var import_sun_sdk_runtime = require("@sun-protocol/sun-sdk-runtime");
|
|
46
|
+
|
|
47
|
+
// src/execute-http-action.ts
|
|
48
|
+
var import_sun_sdk_api = require("@sun-protocol/sun-sdk-api");
|
|
49
|
+
var import_sun_sdk_core = require("@sun-protocol/sun-sdk-core");
|
|
50
|
+
async function executeHttpAction(action, fetchImpl, jsonParser = import_sun_sdk_api.defaultJsonParser) {
|
|
51
|
+
if (action.type !== "http-request" || action.execute !== "api") {
|
|
52
|
+
throw new import_sun_sdk_core.SDKError("SDK_INVALID_ARGUMENT", `Action ${action.id} is not an HTTP action`, {
|
|
53
|
+
actionId: action.id,
|
|
54
|
+
actionType: action.type
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
const request = action.request;
|
|
58
|
+
const headers = {
|
|
59
|
+
Accept: "application/json",
|
|
60
|
+
...request.headers
|
|
61
|
+
};
|
|
62
|
+
let body;
|
|
63
|
+
if (request.body !== void 0) {
|
|
64
|
+
if (typeof request.body === "string") {
|
|
65
|
+
body = request.body;
|
|
66
|
+
} else {
|
|
67
|
+
body = JSON.stringify(request.body);
|
|
68
|
+
if (!headers["Content-Type"]) headers["Content-Type"] = "application/json";
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return (0, import_sun_sdk_api.requestJson)(request.url, {
|
|
72
|
+
service: "Protocols HTTP action",
|
|
73
|
+
fetchImpl,
|
|
74
|
+
jsonParser,
|
|
75
|
+
init: {
|
|
76
|
+
method: request.method,
|
|
77
|
+
headers,
|
|
78
|
+
...body !== void 0 ? { body } : {}
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// src/context.ts
|
|
84
|
+
function requireRuntime(context, operation) {
|
|
85
|
+
if (!context.runtime) {
|
|
86
|
+
throw new import_sun_sdk_core2.SDKError("SDK_RUNTIME_ERROR", `${operation} requires a runtime`, {
|
|
87
|
+
operation,
|
|
88
|
+
network: context.network
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return context.runtime;
|
|
92
|
+
}
|
|
93
|
+
async function requireWalletAddress(context, operation) {
|
|
94
|
+
return (await requireWalletSnapshot(context, operation)).address;
|
|
95
|
+
}
|
|
96
|
+
async function requireWalletSnapshot(context, operation) {
|
|
97
|
+
const runtime = requireRuntime(context, operation);
|
|
98
|
+
const wallet = await runtime.requireWallet(operation);
|
|
99
|
+
return {
|
|
100
|
+
wallet,
|
|
101
|
+
address: (0, import_sun_sdk_core2.assertTronAddress)(await wallet.getAddress(), "wallet address")
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function createContextExecutor(context) {
|
|
105
|
+
const runtime = context.runtime;
|
|
106
|
+
let walletPromise;
|
|
107
|
+
const requireExecutionWallet = () => {
|
|
108
|
+
walletPromise ??= runtime?.requireWallet("transaction plan execution");
|
|
109
|
+
if (!walletPromise) {
|
|
110
|
+
return Promise.reject(new import_sun_sdk_core2.SDKError("SDK_RUNTIME_ERROR", "Transaction plan execution requires a runtime"));
|
|
111
|
+
}
|
|
112
|
+
return walletPromise;
|
|
113
|
+
};
|
|
114
|
+
return {
|
|
115
|
+
network: context.network,
|
|
116
|
+
...runtime ? {
|
|
117
|
+
getAddress: async () => {
|
|
118
|
+
const wallet = await requireExecutionWallet();
|
|
119
|
+
return (0, import_sun_sdk_core2.assertTronAddress)(await wallet.getAddress(), "wallet address");
|
|
120
|
+
},
|
|
121
|
+
sendAction: async (action) => {
|
|
122
|
+
const wallet = await requireExecutionWallet();
|
|
123
|
+
return runtime.sendAction(action, { wallet });
|
|
124
|
+
},
|
|
125
|
+
...runtime.waitForTransactionReceipt ? { waitForTransactionReceipt: runtime.waitForTransactionReceipt.bind(runtime) } : {},
|
|
126
|
+
signTypedData: async (payload) => {
|
|
127
|
+
const wallet = await requireExecutionWallet();
|
|
128
|
+
return runtime.signTypedData(payload, { wallet });
|
|
129
|
+
}
|
|
130
|
+
} : {},
|
|
131
|
+
executeHttpAction: (action) => executeHttpAction(action, context.fetchImpl, context.jsonParser)
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// src/pump/buy.ts
|
|
136
|
+
var import_sun_sdk_launchpad2 = require("@sun-protocol/sun-sdk-launchpad");
|
|
137
|
+
var import_sun_sdk_core10 = require("@sun-protocol/sun-sdk-core");
|
|
138
|
+
|
|
139
|
+
// src/common.ts
|
|
140
|
+
var import_sun_sdk_core3 = require("@sun-protocol/sun-sdk-core");
|
|
141
|
+
var PERCENT_PATTERN = /^(\d+)(?:\.(\d+))?%$/;
|
|
142
|
+
var BASE_UNIT_PATTERN = /^\d+$/;
|
|
143
|
+
function parseSlippage(value) {
|
|
144
|
+
if (value instanceof import_sun_sdk_core3.Percent) {
|
|
145
|
+
validateSlippage(value);
|
|
146
|
+
return value;
|
|
147
|
+
}
|
|
148
|
+
const match = PERCENT_PATTERN.exec(value);
|
|
149
|
+
if (!match) {
|
|
150
|
+
throw new import_sun_sdk_core3.SDKError("SDK_INVALID_ARGUMENT", "Slippage must be a percentage string", {
|
|
151
|
+
slippage: value
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
const whole = match[1] ?? "0";
|
|
155
|
+
const fraction = match[2] ?? "";
|
|
156
|
+
const scale = 10n ** BigInt(fraction.length);
|
|
157
|
+
const percentageUnits = BigInt(whole) * scale + BigInt(fraction || "0");
|
|
158
|
+
const percent = new import_sun_sdk_core3.Percent(percentageUnits.toString(), (100n * scale).toString());
|
|
159
|
+
validateSlippage(percent);
|
|
160
|
+
return percent;
|
|
161
|
+
}
|
|
162
|
+
function validateSlippage(value) {
|
|
163
|
+
if (value.lessThan(0) || value.greaterThan(1)) {
|
|
164
|
+
throw new import_sun_sdk_core3.SDKError("SDK_INVALID_ARGUMENT", "Slippage must be between 0% and 100%", {
|
|
165
|
+
slippage: value.toSignificant()
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
function slippageToBips(value) {
|
|
170
|
+
const percent = parseSlippage(value);
|
|
171
|
+
const numerator = BigInt(percent.numerator.toString()) * 10000n;
|
|
172
|
+
const denominator = BigInt(percent.denominator.toString());
|
|
173
|
+
if (numerator % denominator !== 0n) {
|
|
174
|
+
throw new import_sun_sdk_core3.SDKError("SDK_INVALID_ARGUMENT", "Slippage must resolve to a whole basis point", {
|
|
175
|
+
slippage: typeof value === "string" ? value : value.toSignificant()
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
return Number(numerator / denominator);
|
|
179
|
+
}
|
|
180
|
+
function normalizeBaseUnitAmount(value, label = "amount", options = {}) {
|
|
181
|
+
if (typeof value === "number" && !Number.isSafeInteger(value)) {
|
|
182
|
+
throw new import_sun_sdk_core3.SDKError("SDK_INVALID_ARGUMENT", `${label} must be a safe integer`, {
|
|
183
|
+
label,
|
|
184
|
+
value
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
const text = value.toString();
|
|
188
|
+
if (!BASE_UNIT_PATTERN.test(text)) {
|
|
189
|
+
throw new import_sun_sdk_core3.SDKError("SDK_INVALID_ARGUMENT", `${label} must be an unsigned base-unit integer`, {
|
|
190
|
+
label,
|
|
191
|
+
value: text
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
const amount = BigInt(text);
|
|
195
|
+
if (options.allowZero ? amount < 0n : amount <= 0n) {
|
|
196
|
+
throw new import_sun_sdk_core3.SDKError("SDK_INVALID_ARGUMENT", `${label} must be ${options.allowZero ? "non-negative" : "positive"}`, {
|
|
197
|
+
label,
|
|
198
|
+
value: text
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
return amount.toString();
|
|
202
|
+
}
|
|
203
|
+
function normalizeTransactionValidForSeconds(value) {
|
|
204
|
+
const transactionValidForSeconds = value ?? 1200;
|
|
205
|
+
if (!Number.isSafeInteger(transactionValidForSeconds) || transactionValidForSeconds <= 0) {
|
|
206
|
+
throw new import_sun_sdk_core3.SDKError(
|
|
207
|
+
"SDK_INVALID_ARGUMENT",
|
|
208
|
+
"transactionValidForSeconds must be a positive safe integer",
|
|
209
|
+
{ transactionValidForSeconds }
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
return transactionValidForSeconds;
|
|
213
|
+
}
|
|
214
|
+
async function resolveTransactionDeadline(context, transactionValidForSeconds) {
|
|
215
|
+
const nowSeconds = BigInt(Math.ceil(await context.getTransactionTime() / 1e3));
|
|
216
|
+
return (nowSeconds + BigInt(transactionValidForSeconds)).toString();
|
|
217
|
+
}
|
|
218
|
+
async function normalizeRecipient(context, recipient, operation, walletAddress) {
|
|
219
|
+
if (recipient !== void 0) return (0, import_sun_sdk_core3.assertTronAddress)(recipient, "recipient");
|
|
220
|
+
if (walletAddress !== void 0) return walletAddress;
|
|
221
|
+
return requireWalletAddress(context, operation);
|
|
222
|
+
}
|
|
223
|
+
function nextPlanId(context, prefix) {
|
|
224
|
+
return `${prefix}-${context.idFactory()}`;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// src/execute-plan.ts
|
|
228
|
+
var import_sun_sdk_core5 = require("@sun-protocol/sun-sdk-core");
|
|
229
|
+
|
|
230
|
+
// src/errors.ts
|
|
231
|
+
var import_sun_sdk_core4 = require("@sun-protocol/sun-sdk-core");
|
|
232
|
+
function isWalletRejection(error) {
|
|
233
|
+
if (!error || typeof error !== "object") return false;
|
|
234
|
+
const candidate = error;
|
|
235
|
+
return candidate.code === 4001 || typeof candidate.message === "string" && /reject|denied|cancel/i.test(candidate.message);
|
|
236
|
+
}
|
|
237
|
+
function normalizeProtocolError(error, fallbackCode, message, context = {}) {
|
|
238
|
+
if (error instanceof import_sun_sdk_core4.SDKError) return error;
|
|
239
|
+
const code = isWalletRejection(error) ? "SDK_WALLET_REJECTED" : fallbackCode;
|
|
240
|
+
return new import_sun_sdk_core4.SDKError(code, message, { ...context, cause: error });
|
|
241
|
+
}
|
|
242
|
+
function withExecutionContext(error, context) {
|
|
243
|
+
return new import_sun_sdk_core4.SDKError(error.code, error.message, {
|
|
244
|
+
...error.context,
|
|
245
|
+
actionId: context.actionId,
|
|
246
|
+
completedActionIds: context.completedActionIds,
|
|
247
|
+
cause: error
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// src/execute-plan.ts
|
|
252
|
+
async function executePlanAction(action, executor, completedActions = []) {
|
|
253
|
+
try {
|
|
254
|
+
if (action.waitForReceipt && !executor.waitForTransactionReceipt) {
|
|
255
|
+
throw new import_sun_sdk_core5.SDKError(
|
|
256
|
+
"SDK_RUNTIME_ERROR",
|
|
257
|
+
`Action ${action.id} requires transaction receipt waiting capability`,
|
|
258
|
+
{ actionId: action.id, finality: action.waitForReceipt }
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
if (action.execute === "runtime") {
|
|
262
|
+
let actionToSend;
|
|
263
|
+
let materializedAction;
|
|
264
|
+
if (action.type === "deferred-contract-call") {
|
|
265
|
+
if (!executor.materializeAction) {
|
|
266
|
+
throw new import_sun_sdk_core5.SDKError("SDK_RUNTIME_ERROR", `Action ${action.id} requires a deferred action materializer`);
|
|
267
|
+
}
|
|
268
|
+
const resolvedAction = await executor.materializeAction(action, completedActions);
|
|
269
|
+
materializedAction = {
|
|
270
|
+
...resolvedAction,
|
|
271
|
+
id: action.id,
|
|
272
|
+
...action.intent === void 0 ? {} : { intent: action.intent }
|
|
273
|
+
};
|
|
274
|
+
actionToSend = materializedAction;
|
|
275
|
+
} else if (action.type === "contract-call" || action.type === "approve") {
|
|
276
|
+
actionToSend = action;
|
|
277
|
+
} else {
|
|
278
|
+
throw new import_sun_sdk_core5.SDKError(
|
|
279
|
+
"SDK_RUNTIME_ERROR",
|
|
280
|
+
`Runtime action ${action.id} materialized to unsupported type: ${action.type}`
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
if (!executor.sendAction) {
|
|
284
|
+
throw new import_sun_sdk_core5.SDKError("SDK_RUNTIME_ERROR", `Action ${action.id} requires a runtime executor`);
|
|
285
|
+
}
|
|
286
|
+
const result = await executor.sendAction(actionToSend);
|
|
287
|
+
const receipt = action.waitForReceipt && executor.waitForTransactionReceipt ? await executor.waitForTransactionReceipt(result.txid, { finality: action.waitForReceipt }) : void 0;
|
|
288
|
+
if (receipt && !receipt.success) {
|
|
289
|
+
throw new import_sun_sdk_core5.SDKError("SDK_CONTRACT_ERROR", `Transaction ${result.txid} failed`, {
|
|
290
|
+
actionId: action.id,
|
|
291
|
+
txid: result.txid,
|
|
292
|
+
receipt
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
return {
|
|
296
|
+
action,
|
|
297
|
+
result,
|
|
298
|
+
txid: result.txid,
|
|
299
|
+
...receipt ? { receipt } : {},
|
|
300
|
+
...materializedAction ? { materializedAction } : {}
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
if (action.execute === "wallet-signature") {
|
|
304
|
+
if (!action.typedData) {
|
|
305
|
+
throw new import_sun_sdk_core5.SDKError("SDK_INVALID_ARGUMENT", `Action ${action.id} is missing typedData`);
|
|
306
|
+
}
|
|
307
|
+
if (!executor.signTypedData) {
|
|
308
|
+
throw new import_sun_sdk_core5.SDKError("SDK_WALLET_CAPABILITY_ERROR", `Action ${action.id} requires typed-data signing`);
|
|
309
|
+
}
|
|
310
|
+
const signature = await executor.signTypedData(action.typedData);
|
|
311
|
+
return { action, result: signature };
|
|
312
|
+
}
|
|
313
|
+
if (action.execute === "api") {
|
|
314
|
+
if (!executor.executeHttpAction) {
|
|
315
|
+
throw new import_sun_sdk_core5.SDKError("SDK_RUNTIME_ERROR", `Action ${action.id} requires an API executor`);
|
|
316
|
+
}
|
|
317
|
+
return { action, result: await executor.executeHttpAction(action) };
|
|
318
|
+
}
|
|
319
|
+
throw new import_sun_sdk_core5.SDKError("SDK_RUNTIME_ERROR", "Unsupported action executor");
|
|
320
|
+
} catch (error) {
|
|
321
|
+
const normalized = normalizeProtocolError(
|
|
322
|
+
error,
|
|
323
|
+
action.execute === "api" ? "SDK_API_ERROR" : "SDK_RUNTIME_ERROR",
|
|
324
|
+
`Failed to execute action ${action.id}`
|
|
325
|
+
);
|
|
326
|
+
throw withExecutionContext(normalized, {
|
|
327
|
+
actionId: action.id,
|
|
328
|
+
completedActionIds: completedActions.map((result) => result.action.id)
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
async function executeTransactionPlan(plan, executor) {
|
|
333
|
+
if (executor.network && executor.network !== plan.network) {
|
|
334
|
+
throw new import_sun_sdk_core5.SDKError("SDK_INVALID_ARGUMENT", "Plan and executor network mismatch", {
|
|
335
|
+
planNetwork: plan.network,
|
|
336
|
+
executorNetwork: executor.network
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
if (plan.owner) {
|
|
340
|
+
if (!executor.getAddress) {
|
|
341
|
+
throw new import_sun_sdk_core5.SDKError("SDK_RUNTIME_ERROR", `Plan ${plan.id} requires a wallet address`, {
|
|
342
|
+
planId: plan.id,
|
|
343
|
+
owner: plan.owner
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
const actualAddress = await executor.getAddress();
|
|
347
|
+
if (actualAddress !== plan.owner) {
|
|
348
|
+
throw new import_sun_sdk_core5.SDKError(
|
|
349
|
+
"SDK_WALLET_ACCOUNT_MISMATCH",
|
|
350
|
+
"Transaction plan was created for a different wallet",
|
|
351
|
+
{
|
|
352
|
+
planId: plan.id,
|
|
353
|
+
expectedAddress: plan.owner,
|
|
354
|
+
actualAddress
|
|
355
|
+
}
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
const orderedActions = [...plan.approvals, ...plan.transactions];
|
|
360
|
+
const receiptAction = orderedActions.find((action) => action.waitForReceipt !== void 0);
|
|
361
|
+
if (receiptAction && !executor.waitForTransactionReceipt) {
|
|
362
|
+
throw new import_sun_sdk_core5.SDKError(
|
|
363
|
+
"SDK_RUNTIME_ERROR",
|
|
364
|
+
`Action ${receiptAction.id} requires transaction receipt waiting capability`,
|
|
365
|
+
{ planId: plan.id, actionId: receiptAction.id, finality: receiptAction.waitForReceipt }
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
const actionResults = [];
|
|
369
|
+
const txids = [];
|
|
370
|
+
let finalResult;
|
|
371
|
+
for (const action of orderedActions) {
|
|
372
|
+
const actionResult = await executePlanAction(action, executor, actionResults);
|
|
373
|
+
actionResults.push(actionResult);
|
|
374
|
+
if (action.execute === "runtime") {
|
|
375
|
+
if (!actionResult.txid) {
|
|
376
|
+
throw new import_sun_sdk_core5.SDKError("SDK_RUNTIME_ERROR", `Runtime action ${action.id} did not return a transaction id`);
|
|
377
|
+
}
|
|
378
|
+
txids.push(actionResult.txid);
|
|
379
|
+
const raw = typeof actionResult.result === "object" && actionResult.result !== null ? actionResult.result.raw : void 0;
|
|
380
|
+
finalResult = { type: "transaction", txid: actionResult.txid, raw };
|
|
381
|
+
continue;
|
|
382
|
+
}
|
|
383
|
+
if (action.execute === "wallet-signature") {
|
|
384
|
+
finalResult = { type: "signature", signature: actionResult.result };
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
387
|
+
finalResult = { type: "api", data: actionResult.result };
|
|
388
|
+
}
|
|
389
|
+
return {
|
|
390
|
+
plan,
|
|
391
|
+
actions: actionResults,
|
|
392
|
+
txids,
|
|
393
|
+
finalResult
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
function isTransactionPlan(input) {
|
|
397
|
+
if (typeof input !== "object" || input === null) return false;
|
|
398
|
+
const candidate = input;
|
|
399
|
+
return Array.isArray(candidate.approvals) && Array.isArray(candidate.transactions);
|
|
400
|
+
}
|
|
401
|
+
async function executePlanTransactions(plan, executor) {
|
|
402
|
+
const result = await executeTransactionPlan(
|
|
403
|
+
{ ...plan, approvals: [] },
|
|
404
|
+
executor
|
|
405
|
+
);
|
|
406
|
+
return { ...result, plan };
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// src/internal/v2-swap-action.ts
|
|
410
|
+
var import_sun_sdk_sunswap_v2 = require("@sun-protocol/sun-sdk-sunswap-v2");
|
|
411
|
+
var import_sun_sdk_core6 = require("@sun-protocol/sun-sdk-core");
|
|
412
|
+
var V2_SWAP_MATERIALIZATION_KIND = "sunswap-v2-swap";
|
|
413
|
+
function requireAmount(data, key) {
|
|
414
|
+
const value = data[key];
|
|
415
|
+
if (value === void 0) {
|
|
416
|
+
throw new import_sun_sdk_core6.SDKError("SDK_RUNTIME_ERROR", `Deferred V2 swap is missing ${key}`, {
|
|
417
|
+
operation: data.operation,
|
|
418
|
+
key
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
return value;
|
|
422
|
+
}
|
|
423
|
+
function createDeferredV2SwapAction(input) {
|
|
424
|
+
return (0, import_sun_sdk_core6.createDeferredContractCallAction)({
|
|
425
|
+
id: `sunswap-v2-${input.data.operation}`,
|
|
426
|
+
materialization: {
|
|
427
|
+
kind: V2_SWAP_MATERIALIZATION_KIND,
|
|
428
|
+
data: input.data
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
async function materializeV2SwapAction(context, action) {
|
|
433
|
+
if (action.materialization.kind !== V2_SWAP_MATERIALIZATION_KIND) {
|
|
434
|
+
throw new import_sun_sdk_core6.SDKError("SDK_RUNTIME_ERROR", `Unsupported deferred action kind: ${action.materialization.kind}`);
|
|
435
|
+
}
|
|
436
|
+
const data = action.materialization.data;
|
|
437
|
+
const options = {
|
|
438
|
+
network: context.network,
|
|
439
|
+
id: action.id,
|
|
440
|
+
path: data.path,
|
|
441
|
+
recipient: data.recipient,
|
|
442
|
+
deadline: await resolveTransactionDeadline(context, data.transactionValidForSeconds)
|
|
443
|
+
};
|
|
444
|
+
switch (data.operation) {
|
|
445
|
+
case "swap-exact-eth-for-tokens":
|
|
446
|
+
return (0, import_sun_sdk_sunswap_v2.buildV2SwapExactEthForTokensAction)({
|
|
447
|
+
...options,
|
|
448
|
+
amountIn: requireAmount(data, "amountIn"),
|
|
449
|
+
amountOutMin: requireAmount(data, "amountOutMin")
|
|
450
|
+
});
|
|
451
|
+
case "swap-eth-for-exact-tokens":
|
|
452
|
+
return (0, import_sun_sdk_sunswap_v2.buildV2SwapEthForExactTokensAction)({
|
|
453
|
+
...options,
|
|
454
|
+
amountOut: requireAmount(data, "amountOut"),
|
|
455
|
+
amountInMax: requireAmount(data, "amountInMax")
|
|
456
|
+
});
|
|
457
|
+
case "swap-exact-tokens-for-eth":
|
|
458
|
+
return (0, import_sun_sdk_sunswap_v2.buildV2SwapExactTokensForEthAction)({
|
|
459
|
+
...options,
|
|
460
|
+
amountIn: requireAmount(data, "amountIn"),
|
|
461
|
+
amountOutMin: requireAmount(data, "amountOutMin")
|
|
462
|
+
});
|
|
463
|
+
case "swap-exact-tokens-for-tokens":
|
|
464
|
+
return (0, import_sun_sdk_sunswap_v2.buildV2SwapExactTokensForTokensAction)({
|
|
465
|
+
...options,
|
|
466
|
+
amountIn: requireAmount(data, "amountIn"),
|
|
467
|
+
amountOutMin: requireAmount(data, "amountOutMin")
|
|
468
|
+
});
|
|
469
|
+
case "swap-tokens-for-exact-eth":
|
|
470
|
+
return (0, import_sun_sdk_sunswap_v2.buildV2SwapTokensForExactEthAction)({
|
|
471
|
+
...options,
|
|
472
|
+
amountOut: requireAmount(data, "amountOut"),
|
|
473
|
+
amountInMax: requireAmount(data, "amountInMax")
|
|
474
|
+
});
|
|
475
|
+
case "swap-tokens-for-exact-tokens":
|
|
476
|
+
return (0, import_sun_sdk_sunswap_v2.buildV2SwapTokensForExactTokensAction)({
|
|
477
|
+
...options,
|
|
478
|
+
amountOut: requireAmount(data, "amountOut"),
|
|
479
|
+
amountInMax: requireAmount(data, "amountInMax")
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
// src/swap/v2-execute.ts
|
|
485
|
+
function createV2SwapExecutor(context) {
|
|
486
|
+
return {
|
|
487
|
+
...createContextExecutor(context),
|
|
488
|
+
materializeAction: (action) => materializeV2SwapAction(context, action)
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
// src/pump/execute.ts
|
|
493
|
+
function createPumpExecutor(context) {
|
|
494
|
+
return createV2SwapExecutor(context);
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
// src/pump/plan-buy.ts
|
|
498
|
+
var import_sun_sdk_launchpad = require("@sun-protocol/sun-sdk-launchpad");
|
|
499
|
+
var import_sun_sdk_core8 = require("@sun-protocol/sun-sdk-core");
|
|
500
|
+
|
|
501
|
+
// src/pump/v2.ts
|
|
502
|
+
var import_sun_sdk_sunswap_v22 = require("@sun-protocol/sun-sdk-sunswap-v2");
|
|
503
|
+
var import_sun_sdk_core7 = require("@sun-protocol/sun-sdk-core");
|
|
504
|
+
function pumpV2BuyPath(context, token) {
|
|
505
|
+
return [context.chain.contracts.wtrx, token];
|
|
506
|
+
}
|
|
507
|
+
function pumpV2SellPath(context, token) {
|
|
508
|
+
return [token, context.chain.contracts.wtrx];
|
|
509
|
+
}
|
|
510
|
+
async function readPumpV2AmountsOut(context, runtime, amountIn, path) {
|
|
511
|
+
const result = await runtime.readContract(
|
|
512
|
+
(0, import_sun_sdk_sunswap_v22.buildV2RouterAmountsOutRead)({
|
|
513
|
+
network: context.network,
|
|
514
|
+
amountIn,
|
|
515
|
+
path
|
|
516
|
+
})
|
|
517
|
+
);
|
|
518
|
+
return (0, import_sun_sdk_sunswap_v22.normalizeV2AmountsResult)(result);
|
|
519
|
+
}
|
|
520
|
+
async function readPumpV2AmountsIn(context, runtime, amountOut, path) {
|
|
521
|
+
const result = await runtime.readContract(
|
|
522
|
+
(0, import_sun_sdk_sunswap_v22.buildV2RouterAmountsInRead)({
|
|
523
|
+
network: context.network,
|
|
524
|
+
amountOut,
|
|
525
|
+
path
|
|
526
|
+
})
|
|
527
|
+
);
|
|
528
|
+
return (0, import_sun_sdk_sunswap_v22.normalizeV2AmountsResult)(result);
|
|
529
|
+
}
|
|
530
|
+
function requirePumpV2Amount(amounts, index, operation) {
|
|
531
|
+
const amount = amounts[index];
|
|
532
|
+
if (amount === void 0) {
|
|
533
|
+
throw new import_sun_sdk_core7.SDKError("SDK_NO_ROUTE", "SunSwap V2 returned no Pump route amount", {
|
|
534
|
+
operation,
|
|
535
|
+
index,
|
|
536
|
+
amounts
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
return amount;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
// src/pump/intents.ts
|
|
543
|
+
var SUNPUMP_LAUNCHPAD_PROTOCOL_ID = "sunpump-launchpad";
|
|
544
|
+
var SUNPUMP_V2_PROTOCOL_ID = "sunpump-v2";
|
|
545
|
+
function pumpIntentScope(protocol, operation) {
|
|
546
|
+
return { domain: "pump", protocol, operation };
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
// src/pump/plan-buy.ts
|
|
550
|
+
function normalizePumpBuyMode(input) {
|
|
551
|
+
const trxAmount = input.trxAmount;
|
|
552
|
+
const tokenAmount = input.tokenAmount;
|
|
553
|
+
if (trxAmount === void 0 === (tokenAmount === void 0)) {
|
|
554
|
+
throw new import_sun_sdk_core8.SDKError("SDK_INVALID_ARGUMENT", "Pump buy requires exactly one of trxAmount or tokenAmount", {
|
|
555
|
+
trxAmount,
|
|
556
|
+
tokenAmount
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
if (trxAmount !== void 0) {
|
|
560
|
+
return {
|
|
561
|
+
kind: "exact-trx",
|
|
562
|
+
trxAmount: normalizeBaseUnitAmount(trxAmount, "trxAmount")
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
if (tokenAmount === void 0) {
|
|
566
|
+
throw new import_sun_sdk_core8.SDKError("SDK_INVALID_ARGUMENT", "Pump buy requires tokenAmount", {
|
|
567
|
+
trxAmount,
|
|
568
|
+
tokenAmount
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
return {
|
|
572
|
+
kind: "exact-token",
|
|
573
|
+
tokenAmount: normalizeBaseUnitAmount(tokenAmount, "tokenAmount")
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
async function planPumpBuy(context, input) {
|
|
577
|
+
const runtime = requireRuntime(context, "Pump buy planning");
|
|
578
|
+
const { address: owner } = await requireWalletSnapshot(context, "Pump buy planning");
|
|
579
|
+
const token = (0, import_sun_sdk_core8.assertTronAddress)(input.token, "token");
|
|
580
|
+
const mode = normalizePumpBuyMode(input);
|
|
581
|
+
const state = await (0, import_sun_sdk_launchpad.getLaunchpadTokenState)(runtime, token);
|
|
582
|
+
if (state !== import_sun_sdk_launchpad.LaunchpadTokenState.TRADING && state !== import_sun_sdk_launchpad.LaunchpadTokenState.LAUNCHED) {
|
|
583
|
+
throw new import_sun_sdk_core8.SDKError("SDK_CONTRACT_ERROR", "Token is not trading on SunPump", {
|
|
584
|
+
token,
|
|
585
|
+
state
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
const slippageBips = slippageToBips(input.slippage ?? "5%");
|
|
589
|
+
if (state === import_sun_sdk_launchpad.LaunchpadTokenState.TRADING) {
|
|
590
|
+
let trxAmount;
|
|
591
|
+
let quotedTokenAmount;
|
|
592
|
+
let fee;
|
|
593
|
+
let operation;
|
|
594
|
+
let requestedTokenAmount;
|
|
595
|
+
if (mode.kind === "exact-trx") {
|
|
596
|
+
const quote = await (0, import_sun_sdk_launchpad.quoteLaunchpadBuyExactTrx)(runtime, token, mode.trxAmount);
|
|
597
|
+
trxAmount = mode.trxAmount;
|
|
598
|
+
quotedTokenAmount = quote.tokenAmount;
|
|
599
|
+
fee = quote.fee;
|
|
600
|
+
operation = "launchpad-buy-exact-trx";
|
|
601
|
+
} else {
|
|
602
|
+
const quote = await (0, import_sun_sdk_launchpad.quoteLaunchpadBuyExactToken)(runtime, token, mode.tokenAmount);
|
|
603
|
+
trxAmount = quote.trxAmount;
|
|
604
|
+
quotedTokenAmount = mode.tokenAmount;
|
|
605
|
+
fee = quote.fee;
|
|
606
|
+
operation = "launchpad-buy-exact-token";
|
|
607
|
+
requestedTokenAmount = mode.tokenAmount;
|
|
608
|
+
}
|
|
609
|
+
const minTokenOut = (0, import_sun_sdk_launchpad.applySlippageMin)(BigInt(quotedTokenAmount), slippageBips).toString();
|
|
610
|
+
const transaction2 = {
|
|
611
|
+
...(0, import_sun_sdk_launchpad.createLaunchpadBuyAction)({
|
|
612
|
+
launchpad: context.chain.contracts.launchpad,
|
|
613
|
+
token,
|
|
614
|
+
trxAmount,
|
|
615
|
+
minTokenOut
|
|
616
|
+
}),
|
|
617
|
+
intent: {
|
|
618
|
+
kind: "pump-buy",
|
|
619
|
+
scope: pumpIntentScope(SUNPUMP_LAUNCHPAD_PROTOCOL_ID, operation),
|
|
620
|
+
token
|
|
621
|
+
}
|
|
622
|
+
};
|
|
623
|
+
return {
|
|
624
|
+
id: nextPlanId(context, "pump-buy"),
|
|
625
|
+
kind: "pump",
|
|
626
|
+
network: context.network,
|
|
627
|
+
owner,
|
|
628
|
+
summary: {
|
|
629
|
+
title: "Buy SunPump token",
|
|
630
|
+
lines: [`Spend ${trxAmount} sun`, `Receive at least ${minTokenOut} token units`]
|
|
631
|
+
},
|
|
632
|
+
approvals: [],
|
|
633
|
+
transactions: [transaction2],
|
|
634
|
+
metadata: {
|
|
635
|
+
operation,
|
|
636
|
+
token,
|
|
637
|
+
trxAmount,
|
|
638
|
+
...requestedTokenAmount ? { tokenAmount: requestedTokenAmount } : {},
|
|
639
|
+
quotedTokenAmount,
|
|
640
|
+
quotedTrxAmount: trxAmount,
|
|
641
|
+
fee,
|
|
642
|
+
minTokenOut,
|
|
643
|
+
slippageBips
|
|
644
|
+
}
|
|
645
|
+
};
|
|
646
|
+
}
|
|
647
|
+
const path = pumpV2BuyPath(context, token);
|
|
648
|
+
const recipient = await normalizeRecipient(context, input.recipient, "Pump V2 buy recipient", owner);
|
|
649
|
+
const transactionValidForSeconds = normalizeTransactionValidForSeconds(input.transactionValidForSeconds);
|
|
650
|
+
if (mode.kind === "exact-trx") {
|
|
651
|
+
const amounts2 = await readPumpV2AmountsOut(context, runtime, mode.trxAmount, path);
|
|
652
|
+
const quotedTokenAmount = requirePumpV2Amount(amounts2, amounts2.length - 1, "pump-v2-buy-exact-trx");
|
|
653
|
+
const minTokenOut = (0, import_sun_sdk_launchpad.applySlippageMin)(BigInt(quotedTokenAmount), slippageBips).toString();
|
|
654
|
+
const transaction2 = {
|
|
655
|
+
...createDeferredV2SwapAction({
|
|
656
|
+
data: {
|
|
657
|
+
operation: "swap-exact-eth-for-tokens",
|
|
658
|
+
amountIn: mode.trxAmount,
|
|
659
|
+
amountOutMin: minTokenOut,
|
|
660
|
+
path,
|
|
661
|
+
recipient,
|
|
662
|
+
transactionValidForSeconds
|
|
663
|
+
}
|
|
664
|
+
}),
|
|
665
|
+
intent: {
|
|
666
|
+
kind: "pump-buy",
|
|
667
|
+
scope: pumpIntentScope(SUNPUMP_V2_PROTOCOL_ID, "buy-exact-trx"),
|
|
668
|
+
token
|
|
669
|
+
}
|
|
670
|
+
};
|
|
671
|
+
return {
|
|
672
|
+
id: nextPlanId(context, "pump-buy"),
|
|
673
|
+
kind: "pump",
|
|
674
|
+
network: context.network,
|
|
675
|
+
owner,
|
|
676
|
+
summary: {
|
|
677
|
+
title: "Buy launched Pump token",
|
|
678
|
+
lines: [`Spend ${mode.trxAmount} sun`, `Receive at least ${minTokenOut} token units`]
|
|
679
|
+
},
|
|
680
|
+
approvals: [],
|
|
681
|
+
transactions: [transaction2],
|
|
682
|
+
metadata: {
|
|
683
|
+
operation: "pump-v2-buy-exact-trx",
|
|
684
|
+
token,
|
|
685
|
+
trxAmount: mode.trxAmount,
|
|
686
|
+
quotedTokenAmount,
|
|
687
|
+
minTokenOut,
|
|
688
|
+
slippageBips,
|
|
689
|
+
path,
|
|
690
|
+
recipient,
|
|
691
|
+
transactionValidForSeconds
|
|
692
|
+
}
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
const amounts = await readPumpV2AmountsIn(context, runtime, mode.tokenAmount, path);
|
|
696
|
+
const quotedTrxAmount = requirePumpV2Amount(amounts, 0, "pump-v2-buy-exact-token");
|
|
697
|
+
const maxTrxIn = (0, import_sun_sdk_launchpad.applySlippageMax)(BigInt(quotedTrxAmount), slippageBips).toString();
|
|
698
|
+
const transaction = {
|
|
699
|
+
...createDeferredV2SwapAction({
|
|
700
|
+
data: {
|
|
701
|
+
operation: "swap-eth-for-exact-tokens",
|
|
702
|
+
amountOut: mode.tokenAmount,
|
|
703
|
+
amountInMax: maxTrxIn,
|
|
704
|
+
path,
|
|
705
|
+
recipient,
|
|
706
|
+
transactionValidForSeconds
|
|
707
|
+
}
|
|
708
|
+
}),
|
|
709
|
+
intent: {
|
|
710
|
+
kind: "pump-buy",
|
|
711
|
+
scope: pumpIntentScope(SUNPUMP_V2_PROTOCOL_ID, "buy-exact-token"),
|
|
712
|
+
token
|
|
713
|
+
}
|
|
714
|
+
};
|
|
715
|
+
return {
|
|
716
|
+
id: nextPlanId(context, "pump-buy"),
|
|
717
|
+
kind: "pump",
|
|
718
|
+
network: context.network,
|
|
719
|
+
owner,
|
|
720
|
+
summary: {
|
|
721
|
+
title: "Buy launched Pump token",
|
|
722
|
+
lines: [`Spend at most ${maxTrxIn} sun`, `Receive ${mode.tokenAmount} token units`]
|
|
723
|
+
},
|
|
724
|
+
approvals: [],
|
|
725
|
+
transactions: [transaction],
|
|
726
|
+
metadata: {
|
|
727
|
+
operation: "pump-v2-buy-exact-token",
|
|
728
|
+
token,
|
|
729
|
+
tokenAmount: mode.tokenAmount,
|
|
730
|
+
quotedTrxAmount,
|
|
731
|
+
maxTrxIn,
|
|
732
|
+
slippageBips,
|
|
733
|
+
path,
|
|
734
|
+
recipient,
|
|
735
|
+
transactionValidForSeconds
|
|
736
|
+
}
|
|
737
|
+
};
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
// src/pump/workflow.ts
|
|
741
|
+
var import_sun_sdk_core9 = require("@sun-protocol/sun-sdk-core");
|
|
742
|
+
function assertPumpPlan(plan, operations, clientName) {
|
|
743
|
+
const operation = plan.metadata.operation;
|
|
744
|
+
if (plan.kind !== "pump" || typeof operation !== "string" || !operations.includes(operation) || plan.transactions.length === 0) {
|
|
745
|
+
throw new import_sun_sdk_core9.SDKError("SDK_INVALID_ARGUMENT", `Expected a ${clientName} plan`, {
|
|
746
|
+
planId: plan.id,
|
|
747
|
+
kind: plan.kind,
|
|
748
|
+
operation,
|
|
749
|
+
transactionCount: plan.transactions.length
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
// src/pump/buy.ts
|
|
755
|
+
var PUMP_BUY_OPERATIONS = [
|
|
756
|
+
"launchpad-buy-exact-trx",
|
|
757
|
+
"launchpad-buy-exact-token",
|
|
758
|
+
"pump-v2-buy-exact-trx",
|
|
759
|
+
"pump-v2-buy-exact-token"
|
|
760
|
+
];
|
|
761
|
+
async function quotePumpBuyByTrx(context, input) {
|
|
762
|
+
const runtime = requireRuntime(context, "Pump buy quote");
|
|
763
|
+
const token = (0, import_sun_sdk_core10.assertTronAddress)(input.token, "token");
|
|
764
|
+
const trxAmount = normalizeBaseUnitAmount(input.trxAmount, "trxAmount");
|
|
765
|
+
const state = await (0, import_sun_sdk_launchpad2.getLaunchpadTokenState)(runtime, token);
|
|
766
|
+
if (state === import_sun_sdk_launchpad2.LaunchpadTokenState.TRADING) {
|
|
767
|
+
return (0, import_sun_sdk_launchpad2.quoteLaunchpadBuyExactTrx)(runtime, token, trxAmount);
|
|
768
|
+
}
|
|
769
|
+
if (state === import_sun_sdk_launchpad2.LaunchpadTokenState.LAUNCHED) {
|
|
770
|
+
const path = pumpV2BuyPath(context, token);
|
|
771
|
+
const amounts = await readPumpV2AmountsOut(context, runtime, trxAmount, path);
|
|
772
|
+
return {
|
|
773
|
+
tokenAmount: requirePumpV2Amount(amounts, amounts.length - 1, "pump-v2-buy-quote"),
|
|
774
|
+
fee: "0"
|
|
775
|
+
};
|
|
776
|
+
}
|
|
777
|
+
throw new import_sun_sdk_core10.SDKError("SDK_CONTRACT_ERROR", "Token is not trading on SunPump", { token, state });
|
|
778
|
+
}
|
|
779
|
+
async function quotePumpBuyByToken(context, input) {
|
|
780
|
+
const runtime = requireRuntime(context, "Pump exact-token buy quote");
|
|
781
|
+
const token = (0, import_sun_sdk_core10.assertTronAddress)(input.token, "token");
|
|
782
|
+
const tokenAmount = normalizeBaseUnitAmount(input.tokenAmount, "tokenAmount");
|
|
783
|
+
const state = await (0, import_sun_sdk_launchpad2.getLaunchpadTokenState)(runtime, token);
|
|
784
|
+
if (state === import_sun_sdk_launchpad2.LaunchpadTokenState.TRADING) {
|
|
785
|
+
return (0, import_sun_sdk_launchpad2.quoteLaunchpadBuyExactToken)(runtime, token, tokenAmount);
|
|
786
|
+
}
|
|
787
|
+
if (state === import_sun_sdk_launchpad2.LaunchpadTokenState.LAUNCHED) {
|
|
788
|
+
const path = pumpV2BuyPath(context, token);
|
|
789
|
+
const amounts = await readPumpV2AmountsIn(context, runtime, tokenAmount, path);
|
|
790
|
+
return {
|
|
791
|
+
trxAmount: requirePumpV2Amount(amounts, 0, "pump-v2-buy-exact-token-quote"),
|
|
792
|
+
fee: "0"
|
|
793
|
+
};
|
|
794
|
+
}
|
|
795
|
+
throw new import_sun_sdk_core10.SDKError("SDK_CONTRACT_ERROR", "Token is not trading on SunPump", { token, state });
|
|
796
|
+
}
|
|
797
|
+
var PumpBuyClient = class {
|
|
798
|
+
constructor(context) {
|
|
799
|
+
this.context = context;
|
|
800
|
+
}
|
|
801
|
+
context;
|
|
802
|
+
quote(input) {
|
|
803
|
+
const candidate = input;
|
|
804
|
+
const hasTrxAmount = candidate.trxAmount !== void 0;
|
|
805
|
+
const hasTokenAmount = candidate.tokenAmount !== void 0;
|
|
806
|
+
if (hasTrxAmount === hasTokenAmount) {
|
|
807
|
+
throw new import_sun_sdk_core10.SDKError(
|
|
808
|
+
"SDK_INVALID_ARGUMENT",
|
|
809
|
+
"Pump buy quote requires exactly one of trxAmount or tokenAmount"
|
|
810
|
+
);
|
|
811
|
+
}
|
|
812
|
+
return hasTrxAmount ? quotePumpBuyByTrx(this.context, input) : quotePumpBuyByToken(this.context, input);
|
|
813
|
+
}
|
|
814
|
+
plan(input) {
|
|
815
|
+
return planPumpBuy(this.context, input);
|
|
816
|
+
}
|
|
817
|
+
executeAction(action) {
|
|
818
|
+
return executePlanAction(action, createPumpExecutor(this.context));
|
|
819
|
+
}
|
|
820
|
+
submit(plan) {
|
|
821
|
+
assertPumpPlan(plan, PUMP_BUY_OPERATIONS, "Pump buy");
|
|
822
|
+
return executePlanTransactions(plan, createPumpExecutor(this.context));
|
|
823
|
+
}
|
|
824
|
+
async execute(input) {
|
|
825
|
+
const plan = isTransactionPlan(input) ? input : await planPumpBuy(this.context, input);
|
|
826
|
+
assertPumpPlan(plan, PUMP_BUY_OPERATIONS, "Pump buy");
|
|
827
|
+
return executeTransactionPlan(plan, createPumpExecutor(this.context));
|
|
828
|
+
}
|
|
829
|
+
};
|
|
830
|
+
|
|
831
|
+
// src/pump/launch.ts
|
|
832
|
+
var import_sun_sdk_core11 = require("@sun-protocol/sun-sdk-core");
|
|
833
|
+
function planPumpAgentLaunch(context, input) {
|
|
834
|
+
const baseUrl = context.endpoints.sunPump;
|
|
835
|
+
if (!baseUrl) {
|
|
836
|
+
throw new import_sun_sdk_core11.SDKError("SDK_UNSUPPORTED_NETWORK", "SunPump API is unavailable on this network", {
|
|
837
|
+
network: context.network
|
|
838
|
+
});
|
|
839
|
+
}
|
|
840
|
+
const normalizedBaseUrl = baseUrl.replace(/\/+$/, "");
|
|
841
|
+
const transaction = (0, import_sun_sdk_core11.createHttpRequestAction)({
|
|
842
|
+
id: `pump-agent-launch-${input.symbol}`,
|
|
843
|
+
request: {
|
|
844
|
+
method: "POST",
|
|
845
|
+
url: `${normalizedBaseUrl}/ai/agentTokenLaunch`,
|
|
846
|
+
headers: {
|
|
847
|
+
Accept: "application/json",
|
|
848
|
+
"Content-Type": "application/json"
|
|
849
|
+
},
|
|
850
|
+
body: input
|
|
851
|
+
}
|
|
852
|
+
});
|
|
853
|
+
return {
|
|
854
|
+
id: nextPlanId(context, "pump-launch"),
|
|
855
|
+
kind: "pump",
|
|
856
|
+
network: context.network,
|
|
857
|
+
summary: {
|
|
858
|
+
title: "Launch SunPump token",
|
|
859
|
+
lines: [`Launch ${input.name} (${input.symbol})`]
|
|
860
|
+
},
|
|
861
|
+
approvals: [],
|
|
862
|
+
transactions: [transaction],
|
|
863
|
+
metadata: {
|
|
864
|
+
operation: "pump-agent-launch",
|
|
865
|
+
symbol: input.symbol
|
|
866
|
+
}
|
|
867
|
+
};
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
// src/pump/launch-client.ts
|
|
871
|
+
var PUMP_LAUNCH_OPERATIONS = ["pump-agent-launch"];
|
|
872
|
+
var PumpLaunchClient = class {
|
|
873
|
+
constructor(context) {
|
|
874
|
+
this.context = context;
|
|
875
|
+
}
|
|
876
|
+
context;
|
|
877
|
+
plan(input) {
|
|
878
|
+
return Promise.resolve(planPumpAgentLaunch(this.context, input));
|
|
879
|
+
}
|
|
880
|
+
executeAction(action) {
|
|
881
|
+
return executePlanAction(action, createPumpExecutor(this.context));
|
|
882
|
+
}
|
|
883
|
+
submit(plan) {
|
|
884
|
+
assertPumpPlan(plan, PUMP_LAUNCH_OPERATIONS, "Pump launch");
|
|
885
|
+
return executePlanTransactions(plan, createPumpExecutor(this.context));
|
|
886
|
+
}
|
|
887
|
+
async execute(input) {
|
|
888
|
+
const plan = isTransactionPlan(input) ? input : planPumpAgentLaunch(this.context, input);
|
|
889
|
+
assertPumpPlan(plan, PUMP_LAUNCH_OPERATIONS, "Pump launch");
|
|
890
|
+
return executeTransactionPlan(plan, createPumpExecutor(this.context));
|
|
891
|
+
}
|
|
892
|
+
};
|
|
893
|
+
|
|
894
|
+
// src/pump/sell.ts
|
|
895
|
+
var import_sun_sdk_launchpad4 = require("@sun-protocol/sun-sdk-launchpad");
|
|
896
|
+
var import_sun_sdk_core13 = require("@sun-protocol/sun-sdk-core");
|
|
897
|
+
|
|
898
|
+
// src/pump/plan-sell.ts
|
|
899
|
+
var import_sun_sdk_launchpad3 = require("@sun-protocol/sun-sdk-launchpad");
|
|
900
|
+
var import_sun_sdk_core12 = require("@sun-protocol/sun-sdk-core");
|
|
901
|
+
|
|
902
|
+
// src/internal/intents.ts
|
|
903
|
+
function attachApprovalIntent(actions, scope, tokenSymbol) {
|
|
904
|
+
const intent = { kind: "approve", scope, tokenSymbol };
|
|
905
|
+
return actions.map((action) => action.execute === "runtime" ? { ...action, intent } : action);
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
// src/pump/plan-sell.ts
|
|
909
|
+
async function planPumpSell(context, input) {
|
|
910
|
+
const runtime = requireRuntime(context, "Pump sell planning");
|
|
911
|
+
const { address: walletAddress } = await requireWalletSnapshot(context, "Pump sell planning");
|
|
912
|
+
const token = (0, import_sun_sdk_core12.assertTronAddress)(input.token, "token");
|
|
913
|
+
const tokenAmount = normalizeBaseUnitAmount(input.tokenAmount, "tokenAmount");
|
|
914
|
+
const state = await (0, import_sun_sdk_launchpad3.getLaunchpadTokenState)(runtime, token);
|
|
915
|
+
if (state !== import_sun_sdk_launchpad3.LaunchpadTokenState.TRADING && state !== import_sun_sdk_launchpad3.LaunchpadTokenState.LAUNCHED) {
|
|
916
|
+
throw new import_sun_sdk_core12.SDKError("SDK_CONTRACT_ERROR", "Token is not trading on SunPump", {
|
|
917
|
+
token,
|
|
918
|
+
state
|
|
919
|
+
});
|
|
920
|
+
}
|
|
921
|
+
const slippageBips = slippageToBips(input.slippage ?? "5%");
|
|
922
|
+
const approvalMode = input.approval ?? "auto";
|
|
923
|
+
const approvals = [];
|
|
924
|
+
const owner = input.owner !== void 0 ? (0, import_sun_sdk_core12.assertTronAddress)(input.owner, "owner") : walletAddress;
|
|
925
|
+
if (owner !== walletAddress) {
|
|
926
|
+
throw new import_sun_sdk_core12.SDKError("SDK_WALLET_ACCOUNT_MISMATCH", "Pump sell owner does not match the connected wallet", {
|
|
927
|
+
expectedAddress: owner,
|
|
928
|
+
actualAddress: walletAddress
|
|
929
|
+
});
|
|
930
|
+
}
|
|
931
|
+
let allowance;
|
|
932
|
+
const spender = state === import_sun_sdk_launchpad3.LaunchpadTokenState.TRADING ? context.chain.contracts.launchpad : context.chain.contracts.sunswapV2Router;
|
|
933
|
+
const scope = pumpIntentScope(
|
|
934
|
+
state === import_sun_sdk_launchpad3.LaunchpadTokenState.TRADING ? SUNPUMP_LAUNCHPAD_PROTOCOL_ID : SUNPUMP_V2_PROTOCOL_ID,
|
|
935
|
+
"sell-exact-token"
|
|
936
|
+
);
|
|
937
|
+
if (approvalMode !== "none") {
|
|
938
|
+
allowance = await (0, import_sun_sdk_launchpad3.readLaunchpadAllowance)(
|
|
939
|
+
runtime,
|
|
940
|
+
token,
|
|
941
|
+
owner,
|
|
942
|
+
spender
|
|
943
|
+
);
|
|
944
|
+
if (BigInt(allowance) < BigInt(tokenAmount)) {
|
|
945
|
+
approvals.push(state === import_sun_sdk_launchpad3.LaunchpadTokenState.TRADING ? (0, import_sun_sdk_launchpad3.createLaunchpadApproveAction)(token, spender) : (0, import_sun_sdk_core12.createApproveAction)({
|
|
946
|
+
id: `pump-v2-approve-${token}`,
|
|
947
|
+
target: token,
|
|
948
|
+
spender,
|
|
949
|
+
amount: tokenAmount
|
|
950
|
+
}));
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
if (state === import_sun_sdk_launchpad3.LaunchpadTokenState.TRADING) {
|
|
954
|
+
const quote = await (0, import_sun_sdk_launchpad3.quoteLaunchpadSellExactToken)(runtime, token, tokenAmount);
|
|
955
|
+
const minTrxOut2 = (0, import_sun_sdk_launchpad3.applySlippageMin)(BigInt(quote.trxAmount), slippageBips).toString();
|
|
956
|
+
const transaction2 = {
|
|
957
|
+
...(0, import_sun_sdk_launchpad3.createLaunchpadSellAction)({
|
|
958
|
+
launchpad: context.chain.contracts.launchpad,
|
|
959
|
+
token,
|
|
960
|
+
tokenAmount,
|
|
961
|
+
minTrxOut: minTrxOut2
|
|
962
|
+
}),
|
|
963
|
+
intent: {
|
|
964
|
+
kind: "pump-sell",
|
|
965
|
+
scope,
|
|
966
|
+
token
|
|
967
|
+
}
|
|
968
|
+
};
|
|
969
|
+
return {
|
|
970
|
+
id: nextPlanId(context, "pump-sell"),
|
|
971
|
+
kind: "pump",
|
|
972
|
+
network: context.network,
|
|
973
|
+
owner,
|
|
974
|
+
summary: {
|
|
975
|
+
title: "Sell SunPump token",
|
|
976
|
+
lines: [`Sell ${tokenAmount} token units`, `Receive at least ${minTrxOut2} sun`]
|
|
977
|
+
},
|
|
978
|
+
approvals: attachApprovalIntent(approvals, scope, token),
|
|
979
|
+
transactions: [transaction2],
|
|
980
|
+
metadata: {
|
|
981
|
+
operation: "launchpad-sell-exact-token",
|
|
982
|
+
token,
|
|
983
|
+
tokenAmount,
|
|
984
|
+
quotedTrxAmount: quote.trxAmount,
|
|
985
|
+
fee: quote.fee,
|
|
986
|
+
minTrxOut: minTrxOut2,
|
|
987
|
+
slippageBips,
|
|
988
|
+
approvalMode,
|
|
989
|
+
spender,
|
|
990
|
+
...owner ? { owner } : {},
|
|
991
|
+
...allowance ? { allowance } : {}
|
|
992
|
+
}
|
|
993
|
+
};
|
|
994
|
+
}
|
|
995
|
+
const path = pumpV2SellPath(context, token);
|
|
996
|
+
const amounts = await readPumpV2AmountsOut(context, runtime, tokenAmount, path);
|
|
997
|
+
const quotedTrxAmount = requirePumpV2Amount(amounts, amounts.length - 1, "pump-v2-sell-exact-token");
|
|
998
|
+
const minTrxOut = (0, import_sun_sdk_launchpad3.applySlippageMin)(BigInt(quotedTrxAmount), slippageBips).toString();
|
|
999
|
+
const recipient = await normalizeRecipient(context, input.recipient, "Pump V2 sell recipient", owner);
|
|
1000
|
+
const transactionValidForSeconds = normalizeTransactionValidForSeconds(input.transactionValidForSeconds);
|
|
1001
|
+
const transaction = {
|
|
1002
|
+
...createDeferredV2SwapAction({
|
|
1003
|
+
data: {
|
|
1004
|
+
operation: "swap-exact-tokens-for-eth",
|
|
1005
|
+
amountIn: tokenAmount,
|
|
1006
|
+
amountOutMin: minTrxOut,
|
|
1007
|
+
path,
|
|
1008
|
+
recipient,
|
|
1009
|
+
transactionValidForSeconds
|
|
1010
|
+
}
|
|
1011
|
+
}),
|
|
1012
|
+
intent: {
|
|
1013
|
+
kind: "pump-sell",
|
|
1014
|
+
scope,
|
|
1015
|
+
token
|
|
1016
|
+
}
|
|
1017
|
+
};
|
|
1018
|
+
return {
|
|
1019
|
+
id: nextPlanId(context, "pump-sell"),
|
|
1020
|
+
kind: "pump",
|
|
1021
|
+
network: context.network,
|
|
1022
|
+
owner,
|
|
1023
|
+
summary: {
|
|
1024
|
+
title: "Sell launched Pump token",
|
|
1025
|
+
lines: [`Sell ${tokenAmount} token units`, `Receive at least ${minTrxOut} sun`]
|
|
1026
|
+
},
|
|
1027
|
+
approvals: attachApprovalIntent(approvals, scope, token),
|
|
1028
|
+
transactions: [transaction],
|
|
1029
|
+
metadata: {
|
|
1030
|
+
operation: "pump-v2-sell-exact-token",
|
|
1031
|
+
token,
|
|
1032
|
+
tokenAmount,
|
|
1033
|
+
quotedTrxAmount,
|
|
1034
|
+
minTrxOut,
|
|
1035
|
+
slippageBips,
|
|
1036
|
+
approvalMode,
|
|
1037
|
+
spender,
|
|
1038
|
+
path,
|
|
1039
|
+
recipient,
|
|
1040
|
+
transactionValidForSeconds,
|
|
1041
|
+
...owner ? { owner } : {},
|
|
1042
|
+
...allowance ? { allowance } : {}
|
|
1043
|
+
}
|
|
1044
|
+
};
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
// src/pump/sell.ts
|
|
1048
|
+
var PUMP_SELL_OPERATIONS = [
|
|
1049
|
+
"launchpad-sell-exact-token",
|
|
1050
|
+
"pump-v2-sell-exact-token"
|
|
1051
|
+
];
|
|
1052
|
+
async function quotePumpSell(context, input) {
|
|
1053
|
+
const runtime = requireRuntime(context, "Pump sell quote");
|
|
1054
|
+
const token = (0, import_sun_sdk_core13.assertTronAddress)(input.token, "token");
|
|
1055
|
+
const tokenAmount = normalizeBaseUnitAmount(input.tokenAmount, "tokenAmount");
|
|
1056
|
+
const state = await (0, import_sun_sdk_launchpad4.getLaunchpadTokenState)(runtime, token);
|
|
1057
|
+
if (state === import_sun_sdk_launchpad4.LaunchpadTokenState.TRADING) {
|
|
1058
|
+
return (0, import_sun_sdk_launchpad4.quoteLaunchpadSellExactToken)(runtime, token, tokenAmount);
|
|
1059
|
+
}
|
|
1060
|
+
if (state === import_sun_sdk_launchpad4.LaunchpadTokenState.LAUNCHED) {
|
|
1061
|
+
const path = pumpV2SellPath(context, token);
|
|
1062
|
+
const amounts = await readPumpV2AmountsOut(context, runtime, tokenAmount, path);
|
|
1063
|
+
return {
|
|
1064
|
+
trxAmount: requirePumpV2Amount(amounts, amounts.length - 1, "pump-v2-sell-quote"),
|
|
1065
|
+
fee: "0"
|
|
1066
|
+
};
|
|
1067
|
+
}
|
|
1068
|
+
throw new import_sun_sdk_core13.SDKError("SDK_CONTRACT_ERROR", "Token is not trading on SunPump", { token, state });
|
|
1069
|
+
}
|
|
1070
|
+
var PumpSellClient = class {
|
|
1071
|
+
constructor(context) {
|
|
1072
|
+
this.context = context;
|
|
1073
|
+
}
|
|
1074
|
+
context;
|
|
1075
|
+
quote(input) {
|
|
1076
|
+
return quotePumpSell(this.context, input);
|
|
1077
|
+
}
|
|
1078
|
+
plan(input) {
|
|
1079
|
+
return planPumpSell(this.context, input);
|
|
1080
|
+
}
|
|
1081
|
+
executeAction(action) {
|
|
1082
|
+
return executePlanAction(action, createPumpExecutor(this.context));
|
|
1083
|
+
}
|
|
1084
|
+
submit(plan) {
|
|
1085
|
+
assertPumpPlan(plan, PUMP_SELL_OPERATIONS, "Pump sell");
|
|
1086
|
+
return executePlanTransactions(plan, createPumpExecutor(this.context));
|
|
1087
|
+
}
|
|
1088
|
+
async execute(input) {
|
|
1089
|
+
const plan = isTransactionPlan(input) ? input : await planPumpSell(this.context, input);
|
|
1090
|
+
assertPumpPlan(plan, PUMP_SELL_OPERATIONS, "Pump sell");
|
|
1091
|
+
return executeTransactionPlan(plan, createPumpExecutor(this.context));
|
|
1092
|
+
}
|
|
1093
|
+
};
|
|
1094
|
+
|
|
1095
|
+
// src/pump/client.ts
|
|
1096
|
+
var PumpClient = class {
|
|
1097
|
+
constructor(context) {
|
|
1098
|
+
this.context = context;
|
|
1099
|
+
this.buy = new PumpBuyClient(context);
|
|
1100
|
+
this.sell = new PumpSellClient(context);
|
|
1101
|
+
this.launch = new PumpLaunchClient(context);
|
|
1102
|
+
}
|
|
1103
|
+
context;
|
|
1104
|
+
buy;
|
|
1105
|
+
sell;
|
|
1106
|
+
launch;
|
|
1107
|
+
tokens = {
|
|
1108
|
+
list: async (query = {}) => this.requireApi().listTokens(query),
|
|
1109
|
+
get: async (token) => this.requireApi().getToken(token),
|
|
1110
|
+
search: async (query = {}) => this.requireApi().searchTokens(query),
|
|
1111
|
+
searchV2: async (query = {}) => this.requireApi().searchTokensV2(query),
|
|
1112
|
+
byOwner: async (query) => this.requireApi().tokensByOwner(query),
|
|
1113
|
+
holders: async (query) => this.requireApi().tokenHolders(query),
|
|
1114
|
+
holdersV2: async (query) => this.requireApi().tokenHoldersV2(query),
|
|
1115
|
+
favors: async (query) => this.requireApi().userFavors(query),
|
|
1116
|
+
ranking: async (query) => this.requireApi().ranking(query),
|
|
1117
|
+
kingOfHill: async () => this.requireApi().kingOfHill(),
|
|
1118
|
+
pumpList: async () => this.requireApi().pumpTokenList(),
|
|
1119
|
+
transactions: async (token, query = {}) => this.requireApi().tokenTransactions(token, query),
|
|
1120
|
+
ownerTransactions: async (owner, query = {}) => this.requireApi().userTransactions(owner, query)
|
|
1121
|
+
};
|
|
1122
|
+
state(input) {
|
|
1123
|
+
return (0, import_sun_sdk_launchpad5.getLaunchpadTokenState)(
|
|
1124
|
+
requireRuntime(this.context, "Pump state read"),
|
|
1125
|
+
(0, import_sun_sdk_core14.assertTronAddress)(input.token, "token")
|
|
1126
|
+
);
|
|
1127
|
+
}
|
|
1128
|
+
info(input) {
|
|
1129
|
+
return (0, import_sun_sdk_launchpad5.getLaunchpadTokenInfo)(
|
|
1130
|
+
requireRuntime(this.context, "Pump token info read"),
|
|
1131
|
+
(0, import_sun_sdk_core14.assertTronAddress)(input.token, "token")
|
|
1132
|
+
);
|
|
1133
|
+
}
|
|
1134
|
+
balance(input) {
|
|
1135
|
+
return (0, import_sun_sdk_launchpad5.getLaunchpadTokenBalance)(
|
|
1136
|
+
requireRuntime(this.context, "Pump balance read"),
|
|
1137
|
+
(0, import_sun_sdk_core14.assertTronAddress)(input.token, "token"),
|
|
1138
|
+
input.owner
|
|
1139
|
+
);
|
|
1140
|
+
}
|
|
1141
|
+
allowance(input) {
|
|
1142
|
+
return (0, import_sun_sdk_launchpad5.readLaunchpadAllowance)(
|
|
1143
|
+
requireRuntime(this.context, "Pump allowance read"),
|
|
1144
|
+
(0, import_sun_sdk_core14.assertTronAddress)(input.token, "token"),
|
|
1145
|
+
input.owner,
|
|
1146
|
+
input.spender ?? this.context.chain.contracts.launchpad
|
|
1147
|
+
);
|
|
1148
|
+
}
|
|
1149
|
+
async portfolio(owner, query = {}) {
|
|
1150
|
+
return this.requireApi().portfolio(owner, query);
|
|
1151
|
+
}
|
|
1152
|
+
requireApi() {
|
|
1153
|
+
if (!this.context.sunPumpApi) {
|
|
1154
|
+
throw new import_sun_sdk_core14.SDKError("SDK_UNSUPPORTED_NETWORK", "SunPump API is unavailable on this network", {
|
|
1155
|
+
network: this.context.network
|
|
1156
|
+
});
|
|
1157
|
+
}
|
|
1158
|
+
return this.context.sunPumpApi;
|
|
1159
|
+
}
|
|
1160
|
+
};
|
|
1161
|
+
function createPumpClient(context) {
|
|
1162
|
+
return new PumpClient(context);
|
|
1163
|
+
}
|
|
1164
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1165
|
+
0 && (module.exports = {
|
|
1166
|
+
PumpBuyClient,
|
|
1167
|
+
PumpClient,
|
|
1168
|
+
PumpLaunchClient,
|
|
1169
|
+
PumpSellClient,
|
|
1170
|
+
SUNPUMP_LAUNCHPAD_PROTOCOL_ID,
|
|
1171
|
+
SUNPUMP_V2_PROTOCOL_ID,
|
|
1172
|
+
createPumpClient,
|
|
1173
|
+
createPumpExecutor,
|
|
1174
|
+
planPumpAgentLaunch,
|
|
1175
|
+
planPumpBuy,
|
|
1176
|
+
planPumpSell
|
|
1177
|
+
});
|
|
1178
|
+
//# sourceMappingURL=index.cjs.map
|