@minswap/noodles-sdk 0.0.11 → 0.0.13

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/dist/index.cjs CHANGED
@@ -1,1697 +1 @@
1
- "use strict";
2
- var __webpack_require__ = {};
3
- (()=>{
4
- __webpack_require__.n = (module)=>{
5
- var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
- __webpack_require__.d(getter, {
7
- a: getter
8
- });
9
- return getter;
10
- };
11
- })();
12
- (()=>{
13
- __webpack_require__.d = (exports1, definition)=>{
14
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
15
- enumerable: true,
16
- get: definition[key]
17
- });
18
- };
19
- })();
20
- (()=>{
21
- __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
22
- })();
23
- (()=>{
24
- __webpack_require__.r = (exports1)=>{
25
- if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
26
- value: 'Module'
27
- });
28
- Object.defineProperty(exports1, '__esModule', {
29
- value: true
30
- });
31
- };
32
- })();
33
- var __webpack_exports__ = {};
34
- __webpack_require__.r(__webpack_exports__);
35
- __webpack_require__.d(__webpack_exports__, {
36
- TradeFeeOptions: ()=>types_TradeFeeOptions,
37
- getMoveObjectContent: ()=>getMoveObjectContent,
38
- MoonbagsCalculation: ()=>calculation_MoonbagsCalculation,
39
- SevenKAggregator: ()=>_7k_SevenKAggregator,
40
- SupportedBondingCurve: ()=>types_SupportedBondingCurve,
41
- CLOCK_OBJECT_ID: ()=>CLOCK_OBJECT_ID,
42
- BlastFunCustomCalculation: ()=>custom_calculation_BlastFunCustomCalculation,
43
- BluefinTx: ()=>bluefin_BluefinTx,
44
- Bps: ()=>package_Bps,
45
- BlastFunCustomTransaction: ()=>custom_transaction_BlastFunCustomTransaction,
46
- BASE_BPS: ()=>BASE_BPS,
47
- MoonbagsConstants: ()=>constants_MoonbagsConstants,
48
- getSuiClient: ()=>getSuiClient,
49
- DraftTransferTx: ()=>DraftTransferTx,
50
- SUI_FULL_TYPE: ()=>SUI_FULL_TYPE,
51
- getSplitCoinForTx: ()=>getSplitCoinForTx,
52
- splitSuiCoinAfterFeeFromBuyTx: ()=>splitSuiCoinAfterFeeFromBuyTx,
53
- BlastFunSDKTransaction: ()=>sdk_transaction_BlastFunSDKTransaction,
54
- AstrosAggregator: ()=>astros_AstrosAggregator,
55
- SUI_TYPE: ()=>SUI_TYPE,
56
- AftermathAggregator: ()=>aftermath_AftermathAggregator,
57
- getSplitCoinsAfterFee: ()=>getSplitCoinsAfterFee,
58
- addGasFee: ()=>addGasFee,
59
- MoonbagsPackage: ()=>package_MoonbagsPackage,
60
- NATIVE_USDC_TOKEN_TYPE: ()=>NATIVE_USDC_TOKEN_TYPE,
61
- USDC_TOKEN_TYPE: ()=>USDC_TOKEN_TYPE,
62
- getAmountAfterFee: ()=>getAmountAfterFee,
63
- SUI_METADATA_OBJECT_ID: ()=>SUI_METADATA_OBJECT_ID,
64
- SupportedAggregator: ()=>common_SupportedAggregator,
65
- splitSuiCoinAfterFeeFromSellTx: ()=>splitSuiCoinAfterFeeFromSellTx,
66
- createCompatibleSuiClient: ()=>createCompatibleSuiClient,
67
- BLUEFIN_PACKAGE_ID: ()=>BLUEFIN_PACKAGE_ID,
68
- MoonbagsTransaction: ()=>transaction_MoonbagsTransaction,
69
- BlastFunConstants: ()=>constants_BlastFunConstants,
70
- CetusAggregator: ()=>cetus_CetusAggregator,
71
- adaptSuiClient: ()=>adaptSuiClient,
72
- getCoinObjectIdsByAmount: ()=>getCoinObjectIdsByAmount,
73
- getMoveObject: ()=>getMoveObject,
74
- FlowXAggregator: ()=>flowx_FlowXAggregator,
75
- adaptTransaction: ()=>adaptTransaction,
76
- MathUtils: ()=>package_MathUtils,
77
- BlastFunSDKCalculation: ()=>sdk_calculation_BlastFunSDKCalculation,
78
- BlastFunPackage: ()=>package_BlastFunPackage,
79
- getMemezPumpSDK: ()=>getMemezPumpSDK,
80
- getNeededGasFee: ()=>getNeededGasFee
81
- });
82
- const cjs_namespaceObject = require("@7kprotocol/sdk-ts/cjs");
83
- const transactions_namespaceObject = require("@mysten/sui/transactions");
84
- const external_bignumber_js_namespaceObject = require("bignumber.js");
85
- var external_bignumber_js_default = /*#__PURE__*/ __webpack_require__.n(external_bignumber_js_namespaceObject);
86
- class _7k_SevenKAggregator {
87
- _config;
88
- _suiClient;
89
- constructor(config, suiClient){
90
- this._config = config;
91
- this._suiClient = suiClient;
92
- }
93
- async getTradeRoute({ coinInAmount, coinInType, coinOutType, tradeFee }) {
94
- try {
95
- if (this._config.sevenKApiKey) cjs_namespaceObject.Config.setApiKey(this._config.sevenKApiKey);
96
- const tradeFeePercent = tradeFee ? tradeFee.tradeFeePercent : this._config.defaultTradeFee.tradeFeePercent;
97
- return (0, cjs_namespaceObject.getQuote)({
98
- tokenIn: coinInType,
99
- tokenOut: coinOutType,
100
- amountIn: coinInAmount.toString(),
101
- commissionBps: 10000 * tradeFeePercent
102
- });
103
- } catch (_err) {
104
- return null;
105
- }
106
- }
107
- async getTransaction({ walletAddress, completeRoute, slippage, tradeFee }) {
108
- let tradeFeePercent;
109
- let tradeFeeRecipientAddress;
110
- if (tradeFee) {
111
- tradeFeePercent = tradeFee.tradeFeePercent;
112
- tradeFeeRecipientAddress = tradeFee.tradeFeeRecipientAddress;
113
- } else {
114
- tradeFeePercent = this._config.defaultTradeFee.tradeFeePercent;
115
- tradeFeeRecipientAddress = this._config.defaultTradeFee.tradeFeeRecipientAddress;
116
- }
117
- const transaction = await (0, cjs_namespaceObject.buildTx)({
118
- quoteResponse: completeRoute,
119
- slippage,
120
- accountAddress: walletAddress,
121
- commission: {
122
- partner: tradeFeeRecipientAddress,
123
- commissionBps: 10000 * tradeFeePercent
124
- }
125
- });
126
- if (transaction.tx instanceof cjs_namespaceObject.BluefinXTx) {
127
- const newTransaction = transactions_namespaceObject.Transaction.from(transaction.tx.txBytes);
128
- return newTransaction.build({
129
- client: this._suiClient
130
- });
131
- }
132
- transaction.tx.setSender(walletAddress);
133
- return transaction.tx.build({
134
- client: this._suiClient
135
- });
136
- }
137
- }
138
- (function(SevenKAggregator) {
139
- function toCommonTradeRoutes(tradeRouteResponse) {
140
- const routes = [];
141
- if (!tradeRouteResponse.routes || 0 === tradeRouteResponse.routes.length) return null;
142
- for (const route of tradeRouteResponse.routes){
143
- const paths = [];
144
- const allTokenDecimal = {};
145
- for (const path of route.hops){
146
- for (const t of path.pool.allTokens)allTokenDecimal[t.address] = t.decimal;
147
- const pathDecimalIn = allTokenDecimal[path.tokenIn] ?? 0;
148
- const pathDecimalOut = allTokenDecimal[path.tokenOut] ?? 0;
149
- const pathAmountIn = BigInt(new (external_bignumber_js_default())(path.tokenInAmount).multipliedBy(10 ** pathDecimalIn).toFixed(0, 3));
150
- const pathAmountOut = BigInt(new (external_bignumber_js_default())(path.tokenOutAmount).multipliedBy(10 ** pathDecimalOut).toFixed(0, 3));
151
- paths.push({
152
- poolAddress: path.poolId,
153
- coinIn: path.tokenIn,
154
- coinOut: path.tokenOut,
155
- amountIn: pathAmountIn,
156
- amountOut: pathAmountOut
157
- });
158
- }
159
- if (0 === paths.length) continue;
160
- const routeDecimalIn = allTokenDecimal[route.tokenIn] ?? 0;
161
- const routeDecimalOut = allTokenDecimal[route.tokenOut] ?? 0;
162
- const routeAmountIn = BigInt(new (external_bignumber_js_default())(route.tokenInAmount).multipliedBy(10 ** routeDecimalIn).toFixed(0, 3));
163
- const routeAmountOut = BigInt(new (external_bignumber_js_default())(route.tokenOutAmount).multipliedBy(10 ** routeDecimalOut).toFixed(0, 3));
164
- routes.push({
165
- paths: paths,
166
- coinIn: route.tokenIn,
167
- coinOut: route.tokenOut,
168
- amountIn: routeAmountIn,
169
- amountOut: routeAmountOut
170
- });
171
- }
172
- if (0 === routes.length) return null;
173
- return {
174
- coinIn: tradeRouteResponse.tokenIn,
175
- coinOut: tradeRouteResponse.tokenOut,
176
- amountIn: BigInt(tradeRouteResponse.swapAmountWithDecimal),
177
- amountOut: BigInt(tradeRouteResponse.returnAmountWithDecimal),
178
- routes: routes
179
- };
180
- }
181
- SevenKAggregator.toCommonTradeRoutes = toCommonTradeRoutes;
182
- })(_7k_SevenKAggregator || (_7k_SevenKAggregator = {}));
183
- const external_aftermath_ts_sdk_namespaceObject = require("aftermath-ts-sdk");
184
- class aftermath_AftermathAggregator {
185
- _config;
186
- _aftermathClient;
187
- _suiClient;
188
- constructor(config, suiClient){
189
- this._config = config;
190
- this._suiClient = suiClient;
191
- }
192
- async aftermathClient() {
193
- if (this._aftermathClient) return this._aftermathClient;
194
- if (this._config.aftermathApiEndpoint) this._aftermathClient = new external_aftermath_ts_sdk_namespaceObject.Aftermath(this._config.aftermathApiEndpoint);
195
- else this._aftermathClient = new external_aftermath_ts_sdk_namespaceObject.Aftermath("MAINNET");
196
- await this._aftermathClient.init();
197
- if (this._config.aftermathApiKey) {
198
- const keypair = external_aftermath_ts_sdk_namespaceObject.Helpers.keypairFromPrivateKey(this._config.aftermathApiKey);
199
- await this._aftermathClient.Auth().init({
200
- async signMessageCallback ({ message }) {
201
- const { signature } = await keypair.signPersonalMessage(message);
202
- return {
203
- signature
204
- };
205
- },
206
- walletAddress: keypair.toSuiAddress()
207
- });
208
- }
209
- return this._aftermathClient;
210
- }
211
- async getTradeRoute({ coinInAmount, coinInType, coinOutType, tradeFee }) {
212
- let externalFee;
213
- externalFee = tradeFee ? {
214
- recipient: tradeFee.tradeFeeRecipientAddress,
215
- feePercentage: tradeFee.tradeFeePercent
216
- } : {
217
- recipient: this._config.defaultTradeFee.tradeFeeRecipientAddress,
218
- feePercentage: this._config.defaultTradeFee.tradeFeePercent
219
- };
220
- const client = await this.aftermathClient();
221
- return client.Router().getCompleteTradeRouteGivenAmountIn({
222
- coinInAmount,
223
- coinInType,
224
- coinOutType,
225
- externalFee
226
- });
227
- }
228
- async getTransaction({ completeRoute, walletAddress, slippage }) {
229
- const client = await this.aftermathClient();
230
- const transaction = await client.Router().getTransactionForCompleteTradeRoute({
231
- completeRoute,
232
- walletAddress,
233
- slippage,
234
- isSponsoredTx: false
235
- });
236
- transaction.setSender(walletAddress);
237
- return transaction.build({
238
- client: this._suiClient
239
- });
240
- }
241
- }
242
- (function(AftermathAggregator) {
243
- function toCommonTradeRoutes(tradeRoute) {
244
- if (0 === tradeRoute.routes.length) return null;
245
- const routes = [];
246
- for (const route of tradeRoute.routes){
247
- const paths = [];
248
- for (const path of route.paths)paths.push({
249
- poolAddress: path.poolId,
250
- coinIn: path.coinIn.type,
251
- coinOut: path.coinOut.type,
252
- amountIn: BigInt(path.coinIn.amount),
253
- amountOut: BigInt(path.coinOut.amount)
254
- });
255
- if (0 !== paths.length) routes.push({
256
- paths: paths,
257
- coinIn: route.coinIn.type,
258
- coinOut: route.coinOut.type,
259
- amountIn: route.coinIn.amount,
260
- amountOut: route.coinOut.amount
261
- });
262
- }
263
- if (0 === routes.length) return null;
264
- return {
265
- coinIn: tradeRoute.coinIn.type,
266
- coinOut: tradeRoute.coinOut.type,
267
- amountIn: tradeRoute.coinIn.amount,
268
- amountOut: tradeRoute.coinOut.amount,
269
- routes: routes
270
- };
271
- }
272
- AftermathAggregator.toCommonTradeRoutes = toCommonTradeRoutes;
273
- })(aftermath_AftermathAggregator || (aftermath_AftermathAggregator = {}));
274
- const astros_aggregator_sdk_namespaceObject = require("@naviprotocol/astros-aggregator-sdk");
275
- function isSuiCoin(coin) {
276
- return "0x2::sui::SUI" === coin || "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI" === coin;
277
- }
278
- class astros_AstrosAggregator {
279
- _config;
280
- _suiClient;
281
- constructor(config, suiClient){
282
- this._config = config;
283
- this._suiClient = suiClient;
284
- }
285
- async getTradeRoute({ coinInAmount, coinInType, coinOutType, tradeFee }) {
286
- try {
287
- let serviceFee;
288
- serviceFee = tradeFee ? {
289
- fee: tradeFee.tradeFeePercent,
290
- receiverAddress: tradeFee.tradeFeeRecipientAddress
291
- } : {
292
- fee: this._config.defaultTradeFee.tradeFeePercent,
293
- receiverAddress: this._config.defaultTradeFee.tradeFeeRecipientAddress
294
- };
295
- return (0, astros_aggregator_sdk_namespaceObject.getQuote)(coinInType, coinOutType, coinInAmount, this._config.astrosApiKey, {
296
- byAmountIn: true,
297
- serviceFee: serviceFee
298
- });
299
- } catch (_err) {
300
- return null;
301
- }
302
- }
303
- returnMergedCoins(txb, coins, amount) {
304
- if (coins.length < 2) return txb.object(coins[0].coinObjectId);
305
- let mergedBalance = 0;
306
- const mergeList = [];
307
- coins.sort((a, b)=>Number(b.balance) - Number(a.balance)).slice(1).forEach((coin)=>{
308
- if (mergedBalance >= amount) return;
309
- mergedBalance += Number(coin.balance);
310
- mergeList.push(coin.coinObjectId);
311
- });
312
- const baseObj = coins[0].coinObjectId;
313
- txb.mergeCoins(baseObj, mergeList);
314
- return txb.object(baseObj);
315
- }
316
- async getTransaction({ completeRoute: quote, walletAddress, slippage, tradeFee }) {
317
- let serviceFee;
318
- serviceFee = tradeFee ? {
319
- fee: tradeFee.tradeFeePercent,
320
- receiverAddress: tradeFee.tradeFeeRecipientAddress
321
- } : {
322
- fee: this._config.defaultTradeFee.tradeFeePercent,
323
- receiverAddress: this._config.defaultTradeFee.tradeFeeRecipientAddress
324
- };
325
- const minAmountOut = new (external_bignumber_js_default())(quote.amount_out).multipliedBy(1 - slippage - serviceFee.fee).toNumber();
326
- const txb = new transactions_namespaceObject.Transaction();
327
- let coinIn;
328
- if (isSuiCoin(quote.from)) coinIn = txb.splitCoins(txb.gas, [
329
- txb.pure.u64(quote.amount_in)
330
- ]);
331
- else {
332
- const coins = await (0, astros_aggregator_sdk_namespaceObject.getCoins)(this._suiClient, walletAddress, quote.from);
333
- const mergedCoins = this.returnMergedCoins(txb, coins.data, Number.parseFloat(quote.amount_in));
334
- coinIn = txb.splitCoins(mergedCoins, [
335
- txb.pure.u64(quote.amount_in)
336
- ]);
337
- }
338
- const coinB = await (0, astros_aggregator_sdk_namespaceObject.buildSwapPTBFromQuote)(walletAddress, txb, minAmountOut, coinIn, quote, void 0, false, this._config.astrosApiKey, {
339
- serviceFee: serviceFee
340
- });
341
- txb.transferObjects([
342
- coinB
343
- ], walletAddress);
344
- txb.setSender(walletAddress);
345
- return txb.build({
346
- client: this._suiClient
347
- });
348
- }
349
- }
350
- (function(AstrosAggregator) {
351
- function toCommonTradeRoutes(tradeRoute, coinInType, coinOutType) {
352
- if (0 === tradeRoute.routes.length) return null;
353
- const routes = [];
354
- for (const route of tradeRoute.routes){
355
- const paths = [];
356
- for (const path of route.path)paths.push({
357
- poolAddress: path.id,
358
- coinIn: path.from,
359
- coinOut: path.target,
360
- amountIn: BigInt(path.amount_in),
361
- amountOut: BigInt(path.amount_out)
362
- });
363
- if (0 !== paths.length) routes.push({
364
- amountIn: BigInt(route.amount_in),
365
- amountOut: BigInt(route.amount_out),
366
- coinIn: paths[0].coinIn,
367
- coinOut: paths[paths.length - 1].coinOut,
368
- paths: paths
369
- });
370
- }
371
- if (0 === routes.length) return null;
372
- return {
373
- coinIn: coinInType,
374
- coinOut: coinOutType,
375
- amountIn: BigInt(tradeRoute.amount_in),
376
- amountOut: BigInt(tradeRoute.amount_out),
377
- routes: routes
378
- };
379
- }
380
- AstrosAggregator.toCommonTradeRoutes = toCommonTradeRoutes;
381
- })(astros_AstrosAggregator || (astros_AstrosAggregator = {}));
382
- const aggregator_sdk_namespaceObject = require("@cetusprotocol/aggregator-sdk");
383
- const external_bn_js_namespaceObject = require("bn.js");
384
- var external_bn_js_default = /*#__PURE__*/ __webpack_require__.n(external_bn_js_namespaceObject);
385
- (function(TradeFeeOptions) {
386
- function equals(a, b) {
387
- return a.tradeFeePercent === b.tradeFeePercent && a.tradeFeeRecipientAddress === b.tradeFeeRecipientAddress;
388
- }
389
- TradeFeeOptions.equals = equals;
390
- })(types_TradeFeeOptions || (types_TradeFeeOptions = {}));
391
- var types_TradeFeeOptions;
392
- class cetus_CetusAggregator {
393
- _config;
394
- _suiClient;
395
- _cetusClient;
396
- constructor(config, suiClient){
397
- this._config = config;
398
- this._suiClient = suiClient;
399
- }
400
- cetusClient(walletAddress, tradeFee) {
401
- if (tradeFee && !types_TradeFeeOptions.equals(tradeFee, this._config.defaultTradeFee)) return new aggregator_sdk_namespaceObject.AggregatorClient({
402
- client: this._suiClient,
403
- overlayFeeReceiver: tradeFee.tradeFeeRecipientAddress,
404
- overlayFeeRate: tradeFee.tradeFeePercent,
405
- env: aggregator_sdk_namespaceObject.Env.Mainnet,
406
- signer: walletAddress,
407
- ...this._config.cetusApiKey && this._config.cetusApiEndpoint ? {
408
- apiKey: this._config.cetusApiKey,
409
- endpoint: this._config.cetusApiEndpoint
410
- } : {},
411
- partner: this._config.cetusPartnerId
412
- });
413
- if (this._cetusClient) return this._cetusClient;
414
- this._cetusClient = new aggregator_sdk_namespaceObject.AggregatorClient({
415
- client: this._suiClient,
416
- overlayFeeReceiver: this._config.defaultTradeFee.tradeFeeRecipientAddress,
417
- overlayFeeRate: this._config.defaultTradeFee.tradeFeePercent,
418
- env: aggregator_sdk_namespaceObject.Env.Mainnet,
419
- signer: walletAddress,
420
- ...this._config.cetusApiKey && this._config.cetusApiEndpoint ? {
421
- apiKey: this._config.cetusApiKey,
422
- endpoint: this._config.cetusApiEndpoint
423
- } : {},
424
- partner: this._config.cetusPartnerId
425
- });
426
- return this._cetusClient;
427
- }
428
- async getTradeRoute({ coinInAmount, coinInType, coinOutType, tradeFee }) {
429
- const client = this.cetusClient(void 0, tradeFee);
430
- return client.findRouters({
431
- from: coinInType,
432
- target: coinOutType,
433
- amount: new (external_bn_js_default())(coinInAmount.toString()),
434
- byAmountIn: true
435
- });
436
- }
437
- async getTransaction({ completeRoute: routers, walletAddress, slippage, tradeFee }) {
438
- const txb = new transactions_namespaceObject.Transaction();
439
- const client = this.cetusClient(walletAddress, tradeFee);
440
- await client.fastRouterSwap({
441
- router: routers,
442
- txb,
443
- slippage
444
- });
445
- await client.devInspectTransactionBlock(txb);
446
- txb.setSender(walletAddress);
447
- return txb.build({
448
- client: this._suiClient
449
- });
450
- }
451
- }
452
- (function(CetusAggregator) {
453
- function toCommonTradeRoutes(tradeRoute, coinInType, coinOutType) {
454
- if (0 === tradeRoute.paths.length) return null;
455
- const routes = [];
456
- const allPaths = [];
457
- let currentRoute = [];
458
- for(let i = 0; i < tradeRoute.paths.length; i++){
459
- const currentPath = tradeRoute.paths[i];
460
- const tradePath = {
461
- poolAddress: currentPath.id,
462
- amountIn: BigInt(currentPath.amountIn),
463
- amountOut: BigInt(currentPath.amountOut),
464
- coinIn: currentPath.from,
465
- coinOut: currentPath.target
466
- };
467
- currentRoute.push(tradePath);
468
- if (i === tradeRoute.paths.length - 1) allPaths.push([
469
- ...currentRoute
470
- ]);
471
- else {
472
- const nextPath = tradeRoute.paths[i + 1];
473
- if (currentPath.target !== nextPath.from) {
474
- allPaths.push([
475
- ...currentRoute
476
- ]);
477
- currentRoute = [];
478
- }
479
- }
480
- }
481
- for (const pathGroup of allPaths)if (0 !== pathGroup.length) routes.push({
482
- amountIn: pathGroup[0].amountIn,
483
- amountOut: pathGroup[pathGroup.length - 1].amountOut,
484
- coinIn: pathGroup[0].coinIn,
485
- coinOut: pathGroup[pathGroup.length - 1].coinOut,
486
- paths: pathGroup
487
- });
488
- if (0 === routes.length) return null;
489
- return {
490
- coinIn: coinInType,
491
- coinOut: coinOutType,
492
- amountIn: BigInt(tradeRoute.amountIn.toString(10)),
493
- amountOut: BigInt(tradeRoute.amountOut.toString(10)),
494
- routes: routes
495
- };
496
- }
497
- CetusAggregator.toCommonTradeRoutes = toCommonTradeRoutes;
498
- })(cetus_CetusAggregator || (cetus_CetusAggregator = {}));
499
- var common_SupportedAggregator = /*#__PURE__*/ function(SupportedAggregator) {
500
- SupportedAggregator["ASTROS"] = "ASTROS";
501
- SupportedAggregator["AFTERMATH"] = "AFTERMATH";
502
- SupportedAggregator["SEVENK"] = "7K";
503
- SupportedAggregator["CETUS"] = "CETUS";
504
- SupportedAggregator["FLOWX"] = "FLOWX";
505
- return SupportedAggregator;
506
- }({});
507
- const sdk_namespaceObject = require("@flowx-finance/sdk");
508
- function getInputPercent(percent) {
509
- return 1e6 * percent;
510
- }
511
- class flowx_FlowXAggregator {
512
- _config;
513
- _suiClient;
514
- constructor(config, suiClient){
515
- this._config = config;
516
- this._suiClient = suiClient;
517
- }
518
- getCommission(coinInType, tradeFee) {
519
- let tradeFeePercent;
520
- let tradeFeeRecipientAddress;
521
- if (tradeFee) {
522
- tradeFeePercent = tradeFee.tradeFeePercent;
523
- tradeFeeRecipientAddress = tradeFee.tradeFeeRecipientAddress;
524
- } else {
525
- tradeFeePercent = this._config.defaultTradeFee.tradeFeePercent;
526
- tradeFeeRecipientAddress = this._config.defaultTradeFee.tradeFeeRecipientAddress;
527
- }
528
- return new sdk_namespaceObject.Commission(tradeFeeRecipientAddress, new sdk_namespaceObject.Coin(coinInType), sdk_namespaceObject.CommissionType.PERCENTAGE, getInputPercent(tradeFeePercent), true);
529
- }
530
- async getTradeRoute({ coinInAmount, coinInType, coinOutType, tradeFee }) {
531
- const quoter = new sdk_namespaceObject.AggregatorQuoter("mainnet", this._config.flowxApiKey);
532
- try {
533
- return quoter.getRoutes({
534
- tokenIn: coinInType,
535
- tokenOut: coinOutType,
536
- amountIn: coinInAmount.toString(),
537
- commission: this.getCommission(coinInType, tradeFee)
538
- });
539
- } catch (_err) {
540
- return null;
541
- }
542
- }
543
- async getTransaction({ walletAddress, completeRoute, slippage, tradeFee }) {
544
- const tradeBuilder = new sdk_namespaceObject.TradeBuilder("mainnet", completeRoute.routes);
545
- const result = tradeBuilder.sender(walletAddress).slippage(getInputPercent(slippage)).commission(this.getCommission(completeRoute.coinIn.coinType, tradeFee)).build();
546
- return result.buildTransaction({
547
- client: this._suiClient
548
- }).then((tx)=>{
549
- tx.setSender(walletAddress);
550
- return tx.build({
551
- client: this._suiClient
552
- });
553
- });
554
- }
555
- }
556
- (function(FlowXAggregator) {
557
- function toCommonTradeRoutes(tradeRoute) {
558
- if (0 === tradeRoute.routes.length) return null;
559
- const routes = [];
560
- for (const route of tradeRoute.routes){
561
- const paths = [];
562
- for (const path of route.paths)paths.push({
563
- amountIn: BigInt(path.amountIn.toString()),
564
- amountOut: BigInt(path.amountOut.toString()),
565
- coinIn: path.input.coinType,
566
- coinOut: path.output.coinType,
567
- poolAddress: path.pool.id
568
- });
569
- if (0 !== paths.length) routes.push({
570
- amountIn: BigInt(route.amountIn.toString()),
571
- amountOut: BigInt(route.amountOut.toString()),
572
- coinIn: route.input.coinType,
573
- coinOut: route.output.coinType,
574
- paths: paths
575
- });
576
- }
577
- if (0 === routes.length) return null;
578
- return {
579
- coinIn: tradeRoute.coinIn.coinType,
580
- coinOut: tradeRoute.coinOut.coinType,
581
- amountIn: BigInt(tradeRoute.amountIn.toString()),
582
- amountOut: BigInt(tradeRoute.amountOut.toString()),
583
- routes: routes
584
- };
585
- }
586
- FlowXAggregator.toCommonTradeRoutes = toCommonTradeRoutes;
587
- })(flowx_FlowXAggregator || (flowx_FlowXAggregator = {}));
588
- (function(BlastFunConstants) {
589
- BlastFunConstants.PACKAGE_ID_V4 = "0x7e6aa6e179466ab2814425a780b122575296d011119fa69d27f289f5a28814bd";
590
- BlastFunConstants.MEMEZ_AV_OBJECT_ID = "0x2319e3e76dfad73d8f4684bdbf42be4f32d8ce4521dd61becc8261dc918d82c0";
591
- })(constants_BlastFunConstants || (constants_BlastFunConstants = {}));
592
- var constants_BlastFunConstants;
593
- const SUI_TYPE = "0x2::sui::SUI";
594
- const SUI_FULL_TYPE = "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI";
595
- const USDC_TOKEN_TYPE = "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN";
596
- const NATIVE_USDC_TOKEN_TYPE = "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC";
597
- const SUI_METADATA_OBJECT_ID = "0x9258181f5ceac8dbffb7030890243caed69a9599d2886d957a9cb7656af3bdb3";
598
- const CLOCK_OBJECT_ID = "0x0000000000000000000000000000000000000000000000000000000000000006";
599
- const client_namespaceObject = require("@mysten/sui/client");
600
- const config_suiClient = new client_namespaceObject.SuiClient({
601
- url: (0, client_namespaceObject.getFullnodeUrl)("mainnet")
602
- });
603
- function getSuiClient() {
604
- return config_suiClient;
605
- }
606
- const orderByKey = (array, key, sortBy)=>{
607
- if (!array?.length) return;
608
- let swapped;
609
- do {
610
- swapped = false;
611
- for(let i = 0; i < array.length - 1; i++){
612
- const a = BigInt(array[i][key]);
613
- const b = BigInt(array[i + 1][key]);
614
- if ("desc" === sortBy ? a < b : a > b) {
615
- const temp = array[i];
616
- array[i] = array[i + 1];
617
- array[i + 1] = temp;
618
- swapped = true;
619
- }
620
- }
621
- }while (swapped);
622
- return array;
623
- };
624
- const getCoinObjectIdsByAmount = async (address, amount, coinType)=>{
625
- let coinBalances = [];
626
- let hasNextPage = true;
627
- let nextCursor;
628
- while(hasNextPage)try {
629
- const coins = await getSuiClient().getCoins({
630
- owner: address,
631
- coinType,
632
- cursor: nextCursor
633
- });
634
- coinBalances = [
635
- ...coinBalances,
636
- ...coins.data
637
- ];
638
- hasNextPage = coins.hasNextPage;
639
- nextCursor = coins.nextCursor;
640
- } catch (error) {
641
- console.error("Error fetching data:", error);
642
- hasNextPage = false;
643
- }
644
- const coinObj = orderByKey(coinBalances.map((item)=>({
645
- ...item,
646
- balance: item.balance
647
- })), "balance", "desc") ?? [];
648
- let balance = "0";
649
- const objectIds = [];
650
- const objectCoins = [];
651
- for (const coin of coinObj){
652
- balance = (BigInt(coin.balance) + BigInt(balance)).toString(10);
653
- objectIds.push(coin.coinObjectId);
654
- objectCoins.push(coin);
655
- if (BigInt(balance) >= BigInt(amount)) break;
656
- }
657
- return {
658
- objectIds,
659
- balance,
660
- objectCoins
661
- };
662
- };
663
- async function addGasFee(params) {
664
- const { inheritTx, sender, feeAmount, suiInputAmount } = params;
665
- const tx = inheritTx || new transactions_namespaceObject.Transaction();
666
- tx.setGasBudget(feeAmount);
667
- const { objectCoins } = await getCoinObjectIdsByAmount(sender, (BigInt(suiInputAmount || "0") + feeAmount).toString(), SUI_FULL_TYPE);
668
- tx.setGasPayment(objectCoins.map((c)=>({
669
- objectId: c.coinObjectId,
670
- version: c.version,
671
- digest: c.digest
672
- })));
673
- return tx;
674
- }
675
- const BLUEFIN_PACKAGE_ID = "0x62412b7268c35f3808336aee57a52836501f40b8ba5d936f8ad275e672befd04";
676
- (function(BluefinTx) {
677
- function transferOrDestroyZeroCoin(tx, coinType, coin, address) {
678
- tx.moveCall({
679
- target: `${BLUEFIN_PACKAGE_ID}::utils::transfer_or_destroy`,
680
- typeArguments: [
681
- coinType
682
- ],
683
- arguments: [
684
- coin,
685
- tx.pure.address(address)
686
- ]
687
- });
688
- }
689
- BluefinTx.transferOrDestroyZeroCoin = transferOrDestroyZeroCoin;
690
- })(bluefin_BluefinTx || (bluefin_BluefinTx = {}));
691
- var bluefin_BluefinTx;
692
- const utils_namespaceObject = require("@mysten/sui/utils");
693
- async function getSplitCoinForTx(params) {
694
- const { account, amount, splits, coinType, inheritTx, inspecTransaction, isSponsored = false } = params;
695
- const tx = inheritTx ?? new transactions_namespaceObject.Transaction();
696
- const { objectIds } = await getCoinObjectIdsByAmount(account, amount, coinType);
697
- const coinObjectId = objectIds[0];
698
- if ((0, utils_namespaceObject.normalizeStructTag)(coinType) === (0, utils_namespaceObject.normalizeStructTag)(SUI_FULL_TYPE) && !isSponsored) {
699
- let coin;
700
- if (inspecTransaction) {
701
- if (objectIds.length > 1) tx.mergeCoins(tx.object(coinObjectId), objectIds.slice(1).map((item)=>tx.object(item)));
702
- coin = tx.splitCoins(tx.object(coinObjectId), splits);
703
- } else coin = tx.splitCoins(tx.gas, splits);
704
- return {
705
- tx,
706
- coinData: coin
707
- };
708
- }
709
- if (objectIds.length > 1) tx.mergeCoins(tx.object(coinObjectId), objectIds.slice(1).map((item)=>tx.object(item)));
710
- const coinData = tx.splitCoins(tx.object(coinObjectId), splits);
711
- return {
712
- tx,
713
- coinData
714
- };
715
- }
716
- const BASE_BPS = 10000;
717
- function getSplitCoinsAfterFee(amount, fee) {
718
- const amountNum = BigInt(amount);
719
- const feeNum = BigInt(Number(fee) * BASE_BPS);
720
- if (feeNum === BigInt(0)) return [
721
- amountNum.toString()
722
- ];
723
- const feeAmount = amountNum * feeNum / BigInt(BASE_BPS);
724
- const remainingAmount = amountNum - feeAmount;
725
- return [
726
- remainingAmount.toString(),
727
- feeAmount.toString()
728
- ];
729
- }
730
- function getAmountAfterFee(amount, fee) {
731
- if (!fee || Number(fee) <= 0) return BigInt(amount);
732
- const amountNum = BigInt(amount);
733
- const feeNum = BigInt(Number(fee) * BASE_BPS);
734
- if (feeNum === BigInt(0)) return amountNum;
735
- const feeAmount = amountNum * feeNum / BigInt(BASE_BPS);
736
- return amountNum - feeAmount;
737
- }
738
- async function getNeededGasFee(tx, sender, bufferPercent) {
739
- const { effects: { gasUsed, status } } = await getSuiClient().devInspectTransactionBlock({
740
- sender,
741
- transactionBlock: tx
742
- });
743
- if ("success" !== status.status) throw new Error(`Transaction failed during dev inspect: ${status.error ?? ""}`);
744
- const fee = BigInt(gasUsed.computationCost) + BigInt(gasUsed.storageCost) - BigInt(gasUsed.storageRebate);
745
- const feeNum = BigInt(Number(bufferPercent) * BASE_BPS);
746
- return fee * (BigInt(BASE_BPS) + feeNum) / BigInt(BASE_BPS);
747
- }
748
- const tiny_invariant_namespaceObject = require("@minswap/tiny-invariant");
749
- var tiny_invariant_default = /*#__PURE__*/ __webpack_require__.n(tiny_invariant_namespaceObject);
750
- async function getMoveObjectContent(objectId) {
751
- const moveObject = await getMoveObject(objectId);
752
- return moveObject.fields;
753
- }
754
- async function getMoveObject(objectId) {
755
- const client = getSuiClient();
756
- const objRes = await client.getObject({
757
- id: objectId,
758
- options: {
759
- showContent: true
760
- }
761
- });
762
- const content = objRes.data?.content;
763
- tiny_invariant_default()(content, "Pool object not found or has no content");
764
- tiny_invariant_default()("moveObject" === content.dataType, "Object is not a Move object");
765
- return content;
766
- }
767
- function adaptSuiClient(client) {
768
- return client;
769
- }
770
- function adaptTransaction(transaction) {
771
- return transaction;
772
- }
773
- function createCompatibleSuiClient(client) {
774
- return new Proxy(client, {
775
- get (target, prop) {
776
- const value = target[prop];
777
- if ("function" == typeof value) return value.bind(target);
778
- return value;
779
- }
780
- });
781
- }
782
- (function(MathUtils) {
783
- (function(U64) {
784
- function mulDivUp(a, b, c) {
785
- let roundUp = BigInt(0);
786
- if (a * b % c > BigInt(0)) roundUp = BigInt(1);
787
- return a * b / c + roundUp;
788
- }
789
- U64.mulDivUp = mulDivUp;
790
- })(MathUtils.U64 || (MathUtils.U64 = {}));
791
- })(package_MathUtils || (package_MathUtils = {}));
792
- (function(Bps) {
793
- function calcUp(bps, amount) {
794
- const bpsValue = BigInt(bps.pos0);
795
- const denominator = BigInt(10000);
796
- let roundUp;
797
- roundUp = bpsValue * amount % denominator !== BigInt(0) ? BigInt(1) : BigInt(0);
798
- return bpsValue * amount / denominator + roundUp;
799
- }
800
- Bps.calcUp = calcUp;
801
- function sub(lhs, rhs) {
802
- tiny_invariant_default()(BigInt(lhs.pos0) >= BigInt(rhs.pos0), "Bps underflow");
803
- return {
804
- pos0: (BigInt(lhs.pos0) - BigInt(rhs.pos0)).toString()
805
- };
806
- }
807
- Bps.sub = sub;
808
- function value(bps) {
809
- return BigInt(bps.pos0);
810
- }
811
- Bps.value = value;
812
- function new_(bps) {
813
- return {
814
- pos0: assertOverflow(bps).toString()
815
- };
816
- }
817
- Bps.new_ = new_;
818
- function assertOverflow(bps) {
819
- tiny_invariant_default()(BigInt(bps) <= BigInt(10000), "Bps overflow");
820
- return BigInt(bps);
821
- }
822
- Bps.assertOverflow = assertOverflow;
823
- })(package_Bps || (package_Bps = {}));
824
- (function(BlastFunPackage) {
825
- (function(MemezFun) {
826
- async function isSniperProtectedMemezFun(poolId) {
827
- const memezFun = await getMoveObjectContent(poolId);
828
- return memezFun.public_key.length > 0;
829
- }
830
- MemezFun.isSniperProtectedMemezFun = isSniperProtectedMemezFun;
831
- })(BlastFunPackage.MemezFun || (BlastFunPackage.MemezFun = {}));
832
- (function(MemezFees) {
833
- function takeWithDiscount(fee, amount, discountBps) {
834
- if ("Value" === fee.variant) {
835
- const amountRequired = BigInt(fee.fields.pos0);
836
- if (amountRequired === BigInt(0)) return BigInt(0);
837
- if (amount >= amountRequired) return amountRequired;
838
- throw new Error(`Insufficient amount to cover fee. Required: ${amountRequired}, provided: ${amount}`);
839
- }
840
- if ("Percentage" === fee.variant) {
841
- const feeBps = fee.fields.pos0.fields;
842
- if (BigInt(feeBps.pos0) === BigInt(0)) return BigInt(0);
843
- const discountedFee = package_Bps.calcUp(package_Bps.sub(feeBps, discountBps), amount);
844
- if (amount >= discountedFee) return discountedFee;
845
- throw new Error(`Insufficient amount to cover fee. Required: ${discountedFee}, provided: ${amount}`);
846
- }
847
- throw new Error("Unknown fee variant");
848
- }
849
- MemezFees.takeWithDiscount = takeWithDiscount;
850
- function calculateWithDiscount(fee, discountBps, amount) {
851
- if ("Value" === fee.variant) return BigInt(fee.fields.pos0);
852
- if ("Percentage" === fee.variant) {
853
- const feeBps = fee.fields.pos0.fields;
854
- return package_Bps.calcUp(package_Bps.sub(feeBps, discountBps), amount);
855
- }
856
- throw new Error("Unknown fee variant");
857
- }
858
- MemezFees.calculateWithDiscount = calculateWithDiscount;
859
- })(BlastFunPackage.MemezFees || (BlastFunPackage.MemezFees = {}));
860
- (function(MemezBurner) {
861
- function calculate(burner, poolMemeBalance) {
862
- const burnerFee = package_Bps.value(burner.fee.fields);
863
- if (burnerFee === BigInt(0) || poolMemeBalance === BigInt(0)) return package_Bps.new_(0);
864
- if (poolMemeBalance >= BigInt(burner.target_liquidity)) return package_Bps.new_(0);
865
- const baseBps = BigInt(10000);
866
- return package_Bps.new_(package_MathUtils.U64.mulDivUp(package_Bps.value(burner.fee.fields), package_MathUtils.U64.mulDivUp(poolMemeBalance, baseBps, BigInt(burner.target_liquidity)), baseBps));
867
- }
868
- MemezBurner.calculate = calculate;
869
- })(BlastFunPackage.MemezBurner || (BlastFunPackage.MemezBurner = {}));
870
- (function(MemezPump) {
871
- async function getPumpState(memezFun) {
872
- return await getMoveObjectContent(memezFun.inner_state);
873
- }
874
- MemezPump.getPumpState = getPumpState;
875
- function pump(pumpState, quoteAmount) {
876
- const constantProduct = pumpState.constant_product.fields;
877
- const quoteSwapFee = BlastFunPackage.MemezFees.takeWithDiscount(constantProduct.quote_swap_fee, quoteAmount, constantProduct.quote_referrer_fee.fields);
878
- const quoteAfterFee = quoteAmount - quoteSwapFee;
879
- const memeBalance = BigInt(constantProduct.meme_balance);
880
- const quoteBalance = BigInt(constantProduct.quote_balance);
881
- const virtualLiquidity = BigInt(constantProduct.virtual_liquidity);
882
- const memeOutExpected = memeBalance * quoteAfterFee / (virtualLiquidity + quoteBalance + quoteAfterFee);
883
- const memeSwapFee = BlastFunPackage.MemezFees.takeWithDiscount(constantProduct.meme_swap_fee, memeOutExpected, constantProduct.meme_referrer_fee.fields);
884
- return memeOutExpected - memeSwapFee;
885
- }
886
- MemezPump.pump = pump;
887
- function dump(pumpState, memeAmount) {
888
- const constantProduct = pumpState.constant_product.fields;
889
- const memeSwapFee = BlastFunPackage.MemezFees.takeWithDiscount(constantProduct.meme_swap_fee, memeAmount, constantProduct.meme_referrer_fee.fields);
890
- const inputAmount = memeAmount - memeSwapFee;
891
- const memeBalance = BigInt(constantProduct.meme_balance);
892
- const quoteBalance = BigInt(constantProduct.quote_balance);
893
- const virtualLiquidity = BigInt(constantProduct.virtual_liquidity);
894
- const burnBps = BlastFunPackage.MemezBurner.calculate(constantProduct.burner.fields, quoteBalance);
895
- const burnAmount = package_Bps.calcUp(burnBps, inputAmount);
896
- const inputAmountAfterFee = inputAmount - (package_Bps.value(burnBps) !== BigInt(0) ? burnAmount : BigInt(0));
897
- let quoteOutBeforeFee = (virtualLiquidity + quoteBalance) * inputAmountAfterFee / (memeBalance + inputAmountAfterFee);
898
- if (quoteOutBeforeFee > quoteBalance) quoteOutBeforeFee = quoteBalance;
899
- const quoteSwapFee = BlastFunPackage.MemezFees.takeWithDiscount(constantProduct.quote_swap_fee, quoteOutBeforeFee, constantProduct.quote_referrer_fee.fields);
900
- return quoteOutBeforeFee - quoteSwapFee;
901
- }
902
- MemezPump.dump = dump;
903
- })(BlastFunPackage.MemezPump || (BlastFunPackage.MemezPump = {}));
904
- })(package_BlastFunPackage || (package_BlastFunPackage = {}));
905
- var package_MathUtils, package_Bps, package_BlastFunPackage;
906
- (function(BlastFunCustomCalculation) {
907
- async function getCurveAmountAfterBuy(params) {
908
- let { suiAmount, poolId, frontendFee } = params;
909
- const memezFun = await getMoveObjectContent(poolId);
910
- const pumpState = await package_BlastFunPackage.MemezPump.getPumpState(memezFun);
911
- suiAmount = getAmountAfterFee(suiAmount, frontendFee);
912
- return package_BlastFunPackage.MemezPump.pump(pumpState, suiAmount);
913
- }
914
- BlastFunCustomCalculation.getCurveAmountAfterBuy = getCurveAmountAfterBuy;
915
- async function getSuiAmountAfterSell(params) {
916
- const { curveAmount, poolId, frontendFee } = params;
917
- const memezFun = await getMoveObjectContent(poolId);
918
- const pumpState = await package_BlastFunPackage.MemezPump.getPumpState(memezFun);
919
- const suiAmount = package_BlastFunPackage.MemezPump.dump(pumpState, curveAmount);
920
- return getAmountAfterFee(suiAmount, frontendFee);
921
- }
922
- BlastFunCustomCalculation.getSuiAmountAfterSell = getSuiAmountAfterSell;
923
- })(custom_calculation_BlastFunCustomCalculation || (custom_calculation_BlastFunCustomCalculation = {}));
924
- var custom_calculation_BlastFunCustomCalculation;
925
- async function splitSuiCoinAfterFeeFromBuyTx(params) {
926
- const { inputAmount, accountAddress, frontendFee, frontendFeeRecipient, extendTx, isSponsored } = params;
927
- tiny_invariant_default()(params.inCoinType === SUI_FULL_TYPE || params.inCoinType === SUI_TYPE, "Input must be SUI");
928
- const { tx: _tx, coinIn } = extendTx || {};
929
- const splitSui = getSplitCoinsAfterFee(inputAmount, frontendFee || "0");
930
- const tx = _tx || new transactions_namespaceObject.Transaction();
931
- let coinData;
932
- if (coinIn) {
933
- coinData = tx.splitCoins(coinIn, splitSui);
934
- bluefin_BluefinTx.transferOrDestroyZeroCoin(tx, SUI_FULL_TYPE, coinIn, accountAddress);
935
- } else {
936
- const { coinData: _data } = await getSplitCoinForTx({
937
- account: accountAddress,
938
- amount: inputAmount,
939
- splits: splitSui,
940
- coinType: SUI_FULL_TYPE,
941
- inheritTx: tx,
942
- isSponsored: isSponsored || false
943
- });
944
- coinData = _data;
945
- }
946
- let inputSuiCoin;
947
- if (frontendFee && frontendFeeRecipient) {
948
- const [_inputSuiCoin, frontendFeeCoin] = coinData;
949
- inputSuiCoin = _inputSuiCoin;
950
- tx.transferObjects([
951
- frontendFeeCoin
952
- ], tx.pure.address(frontendFeeRecipient || accountAddress));
953
- } else [inputSuiCoin] = coinData;
954
- return {
955
- tx,
956
- coinOut: inputSuiCoin
957
- };
958
- }
959
- async function splitSuiCoinAfterFeeFromSellTx(tx, params, suiCoin) {
960
- tiny_invariant_default()(params.outCoinType === SUI_FULL_TYPE || params.outCoinType === SUI_TYPE, "Output must be SUI");
961
- if (Number(params.frontendFee || 0) <= 0) return {
962
- tx,
963
- coinOut: suiCoin
964
- };
965
- const suiCoinValue = tx.moveCall({
966
- target: "0x2::coin::value",
967
- typeArguments: [
968
- params.outCoinType
969
- ],
970
- arguments: [
971
- suiCoin
972
- ]
973
- });
974
- const suiCoinFeeValue = tx.moveCall({
975
- target: `${BLUEFIN_PACKAGE_ID}::math::mul_div_u64`,
976
- typeArguments: [],
977
- arguments: [
978
- suiCoinValue,
979
- tx.pure.u64(BigInt(Number(params.frontendFee || "0") * BASE_BPS)),
980
- tx.pure.u64(BigInt(BASE_BPS))
981
- ]
982
- });
983
- const suiCoinFee = tx.moveCall({
984
- target: "0x2::coin::split",
985
- typeArguments: [
986
- params.outCoinType
987
- ],
988
- arguments: [
989
- suiCoin,
990
- suiCoinFeeValue
991
- ]
992
- });
993
- tx.transferObjects([
994
- suiCoinFee
995
- ], tx.pure.address(params.frontendFeeRecipient || params.accountAddress));
996
- return {
997
- tx,
998
- coinOut: suiCoin
999
- };
1000
- }
1001
- var types_SupportedBondingCurve = /*#__PURE__*/ function(SupportedBondingCurve) {
1002
- SupportedBondingCurve["BLAST_FUN"] = "BLAST_FUN";
1003
- SupportedBondingCurve["MOONBAGS"] = "MOONBAGS";
1004
- return SupportedBondingCurve;
1005
- }({});
1006
- (function(BlastFunCustomTransaction) {
1007
- async function getAllowedVersions(_tx) {
1008
- const tx = _tx || new transactions_namespaceObject.Transaction();
1009
- return tx.moveCall({
1010
- target: `${constants_BlastFunConstants.PACKAGE_ID_V4}::memez_allowed_versions::get_allowed_versions`,
1011
- arguments: [
1012
- tx.object(constants_BlastFunConstants.MEMEZ_AV_OBJECT_ID)
1013
- ],
1014
- typeArguments: []
1015
- });
1016
- }
1017
- BlastFunCustomTransaction.getAllowedVersions = getAllowedVersions;
1018
- async function buildBuyTx(params) {
1019
- tiny_invariant_default()(!await package_BlastFunPackage.MemezFun.isSniperProtectedMemezFun(params.poolId), "This coin is a sniper protected coin, please use the Blast Fun website to trade it.");
1020
- const { tx, coinOut: suiCoinIn } = await splitSuiCoinAfterFeeFromBuyTx(params);
1021
- tiny_invariant_default()(suiCoinIn, "Coin out is required");
1022
- const curveCoin = tx.moveCall({
1023
- target: `${constants_BlastFunConstants.PACKAGE_ID_V4}::memez_pump::pump`,
1024
- typeArguments: [
1025
- params.outCoinType,
1026
- SUI_FULL_TYPE
1027
- ],
1028
- arguments: [
1029
- tx.object(params.poolId),
1030
- suiCoinIn,
1031
- tx.pure.vector("address", []),
1032
- tx.pure.vector("vector<u8>", []),
1033
- tx.pure.u64(params.minAmountOut),
1034
- await getAllowedVersions(tx)
1035
- ]
1036
- });
1037
- return {
1038
- tx,
1039
- coinOut: curveCoin
1040
- };
1041
- }
1042
- BlastFunCustomTransaction.buildBuyTx = buildBuyTx;
1043
- async function buildSellTx(params) {
1044
- tiny_invariant_default()(params.outCoinType === SUI_FULL_TYPE || params.outCoinType === SUI_TYPE, "Output must be SUI");
1045
- const memezFun = await getMoveObjectContent(params.poolId);
1046
- const { tx, coinData } = await getSplitCoinForTx({
1047
- amount: params.inputAmount,
1048
- coinType: params.inCoinType,
1049
- inheritTx: params.extendTx?.tx,
1050
- account: params.accountAddress,
1051
- splits: [
1052
- params.inputAmount
1053
- ]
1054
- });
1055
- const [inputCoin] = coinData;
1056
- const [suiCoin] = tx.moveCall({
1057
- target: `${constants_BlastFunConstants.PACKAGE_ID_V4}::memez_pump::dump`,
1058
- typeArguments: [
1059
- params.inCoinType,
1060
- params.outCoinType
1061
- ],
1062
- arguments: [
1063
- tx.object(params.poolId),
1064
- tx.object(memezFun.ipx_meme_coin_treasury),
1065
- inputCoin,
1066
- tx.pure.vector("address", []),
1067
- tx.pure.u64(params.minAmountOut),
1068
- await getAllowedVersions(tx)
1069
- ]
1070
- });
1071
- return await splitSuiCoinAfterFeeFromSellTx(tx, params, suiCoin);
1072
- }
1073
- BlastFunCustomTransaction.buildSellTx = buildSellTx;
1074
- })(custom_transaction_BlastFunCustomTransaction || (custom_transaction_BlastFunCustomTransaction = {}));
1075
- var custom_transaction_BlastFunCustomTransaction;
1076
- const memez_fun_sdk_namespaceObject = require("@interest-protocol/memez-fun-sdk");
1077
- const sui_core_sdk_namespaceObject = require("@interest-protocol/sui-core-sdk");
1078
- const payload = {
1079
- network: sui_core_sdk_namespaceObject.Network.MAINNET,
1080
- fullNodeUrl: (0, client_namespaceObject.getFullnodeUrl)("mainnet")
1081
- };
1082
- const memezPump = new memez_fun_sdk_namespaceObject.MemezPumpSDK(payload);
1083
- function getMemezPumpSDK() {
1084
- return memezPump;
1085
- }
1086
- (function(BlastFunSDKCalculation) {
1087
- async function getCurveAmountAfterBuy(params) {
1088
- let { suiAmount, poolId, frontendFee } = params;
1089
- suiAmount = getAmountAfterFee(suiAmount, frontendFee);
1090
- const { memeAmountOut } = await getMemezPumpSDK().quotePump({
1091
- pool: poolId,
1092
- amount: suiAmount
1093
- });
1094
- return memeAmountOut;
1095
- }
1096
- BlastFunSDKCalculation.getCurveAmountAfterBuy = getCurveAmountAfterBuy;
1097
- async function getSuiAmountAfterSell(params) {
1098
- const { curveAmount, poolId, frontendFee } = params;
1099
- const { quoteAmountOut } = await getMemezPumpSDK().quoteDump({
1100
- pool: poolId,
1101
- amount: curveAmount
1102
- });
1103
- return getAmountAfterFee(quoteAmountOut, frontendFee);
1104
- }
1105
- BlastFunSDKCalculation.getSuiAmountAfterSell = getSuiAmountAfterSell;
1106
- })(sdk_calculation_BlastFunSDKCalculation || (sdk_calculation_BlastFunSDKCalculation = {}));
1107
- var sdk_calculation_BlastFunSDKCalculation;
1108
- (function(BlastFunSDKTransaction) {
1109
- async function buildBuyTx(params) {
1110
- const { tx, coinOut: suiCoinIn } = await splitSuiCoinAfterFeeFromBuyTx(params);
1111
- tiny_invariant_default()(suiCoinIn, "Coin out is required");
1112
- const { memeCoin, tx: tx2 } = await getMemezPumpSDK().pump({
1113
- pool: params.poolId,
1114
- quoteCoin: suiCoinIn,
1115
- minAmountOut: params.minAmountOut,
1116
- tx
1117
- });
1118
- return {
1119
- tx: tx2,
1120
- coinOut: memeCoin
1121
- };
1122
- }
1123
- BlastFunSDKTransaction.buildBuyTx = buildBuyTx;
1124
- async function buildSellTx(params) {
1125
- tiny_invariant_default()(params.outCoinType === SUI_FULL_TYPE || params.outCoinType === SUI_TYPE, "Output must be SUI");
1126
- const { tx, coinData } = await getSplitCoinForTx({
1127
- amount: params.inputAmount,
1128
- coinType: params.inCoinType,
1129
- inheritTx: params.extendTx?.tx,
1130
- account: params.accountAddress,
1131
- splits: [
1132
- params.inputAmount
1133
- ]
1134
- });
1135
- const [inputCoin] = coinData;
1136
- const { quoteCoin, tx: tx2 } = await getMemezPumpSDK().dump({
1137
- pool: params.poolId,
1138
- memeCoin: inputCoin,
1139
- tx,
1140
- minAmountOut: params.minAmountOut
1141
- });
1142
- return await splitSuiCoinAfterFeeFromSellTx(tx2, params, quoteCoin);
1143
- }
1144
- BlastFunSDKTransaction.buildSellTx = buildSellTx;
1145
- async function getBuyTransaction({ coinInAmount, coinInType, coinOutType, poolId, slippage, walletAddress, tradeFee }, suiClient) {
1146
- tiny_invariant_default()(coinInType === SUI_TYPE, "coinInType must be SUI for buy transaction");
1147
- tiny_invariant_default()(coinOutType !== coinInType, "coinOutType must be different from coinInType");
1148
- tiny_invariant_default()(slippage >= 0 && slippage < 1, "slippage must be between 0 (inclusive) and 1 (exclusive)");
1149
- tiny_invariant_default()(coinInAmount > 0, "coinInAmount must be greater than 0");
1150
- const inputAmount = coinInAmount;
1151
- const outputAmount = await sdk_calculation_BlastFunSDKCalculation.getCurveAmountAfterBuy({
1152
- poolId: poolId,
1153
- suiAmount: inputAmount,
1154
- frontendFee: tradeFee ? tradeFee.tradeFeePercent : void 0
1155
- });
1156
- const minAmountOut = BigInt(new (external_bignumber_js_default())(outputAmount.toString()).multipliedBy(1 - slippage).toFixed(0, 3));
1157
- let { tx, coinOut } = await buildBuyTx({
1158
- accountAddress: walletAddress,
1159
- inCoinType: coinInType,
1160
- outCoinType: coinOutType,
1161
- inputAmount: inputAmount.toString(),
1162
- minAmountOut: minAmountOut.toString(),
1163
- poolId: poolId,
1164
- frontendFee: tradeFee ? tradeFee.tradeFeePercent : void 0,
1165
- frontendFeeRecipient: tradeFee ? tradeFee.tradeFeeRecipientAddress : void 0,
1166
- extendTx: void 0,
1167
- isSponsored: false
1168
- });
1169
- tiny_invariant_default()(coinOut, "Coin out is required");
1170
- tx.transferObjects([
1171
- coinOut
1172
- ], tx.pure.address(walletAddress));
1173
- tx.setSender(walletAddress);
1174
- const feeAmount = await getNeededGasFee(tx, walletAddress, 0);
1175
- tx = await addGasFee({
1176
- inheritTx: tx,
1177
- sender: walletAddress,
1178
- feeAmount,
1179
- suiInputAmount: inputAmount
1180
- });
1181
- return tx.build({
1182
- client: suiClient
1183
- });
1184
- }
1185
- BlastFunSDKTransaction.getBuyTransaction = getBuyTransaction;
1186
- async function getSellTransaction({ coinInAmount, coinInType, coinOutType, poolId, slippage, walletAddress, tradeFee }, suiClient) {
1187
- tiny_invariant_default()(coinOutType === SUI_TYPE, "coinOutType must be SUI for sell transaction");
1188
- tiny_invariant_default()(coinOutType !== coinInType, "coinOutType must be different from coinInType");
1189
- tiny_invariant_default()(slippage >= 0 && slippage < 1, "slippage must be between 0 (inclusive) and 1 (exclusive)");
1190
- tiny_invariant_default()(coinInAmount > 0, "coinInAmount must be greater than 0");
1191
- const inputAmount = coinInAmount;
1192
- const outputAmount = await sdk_calculation_BlastFunSDKCalculation.getSuiAmountAfterSell({
1193
- poolId: poolId,
1194
- curveAmount: inputAmount,
1195
- frontendFee: tradeFee ? tradeFee.tradeFeePercent : void 0
1196
- });
1197
- const minAmountOut = BigInt(new (external_bignumber_js_default())(outputAmount.toString()).multipliedBy(1 - slippage).toFixed(0, 3));
1198
- let { tx, coinOut } = await buildSellTx({
1199
- accountAddress: walletAddress,
1200
- inCoinType: coinInType,
1201
- outCoinType: coinOutType,
1202
- inputAmount: inputAmount.toString(),
1203
- minAmountOut: minAmountOut.toString(),
1204
- poolId: poolId,
1205
- frontendFee: tradeFee ? tradeFee.tradeFeePercent : void 0,
1206
- frontendFeeRecipient: tradeFee ? tradeFee.tradeFeeRecipientAddress : void 0,
1207
- extendTx: void 0,
1208
- isSponsored: false
1209
- });
1210
- tiny_invariant_default()(coinOut, "Coin out is required");
1211
- tx.transferObjects([
1212
- coinOut
1213
- ], tx.pure.address(walletAddress));
1214
- tx.setSender(walletAddress);
1215
- const feeAmount = await getNeededGasFee(tx, walletAddress, 0);
1216
- tx = await addGasFee({
1217
- inheritTx: tx,
1218
- sender: walletAddress,
1219
- feeAmount
1220
- });
1221
- return tx.build({
1222
- client: suiClient
1223
- });
1224
- }
1225
- BlastFunSDKTransaction.getSellTransaction = getSellTransaction;
1226
- })(sdk_transaction_BlastFunSDKTransaction || (sdk_transaction_BlastFunSDKTransaction = {}));
1227
- var sdk_transaction_BlastFunSDKTransaction;
1228
- (function(MoonbagsConstants) {
1229
- MoonbagsConstants.PACKAGE_ID = "0xb8df325010942634a4afb3db3901ee215546af43a4ec4af781e7213b0bba7290";
1230
- MoonbagsConstants.CONFIG_OBJECT_ID = "0x74aecf86067c6913960ba4925333aefd2b1f929cafca7e21fd55a8f244b70499";
1231
- MoonbagsConstants.LOCK_CONFIG_OBJECT_ID = "0xfb09822d9808980abd04c51321adb850701f5f55535c6206658ef4d910c3e9be";
1232
- MoonbagsConstants.BURN_MANAGER_OBJECT_ID = "0x1d94aa32518d0cb00f9de6ed60d450c9a2090761f326752ffad06b2e9404f845";
1233
- MoonbagsConstants.POOLS_OBJECT_ID = "0xf699e7f2276f5c9a75944b37a0c5b5d9ddfd2471bf6242483b03ab2887d198d0";
1234
- MoonbagsConstants.GLOBAL_CONFIG_OBJECT_ID = "0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f";
1235
- MoonbagsConstants.FEE_DENOMINATOR = BigInt(10000);
1236
- })(constants_MoonbagsConstants || (constants_MoonbagsConstants = {}));
1237
- var constants_MoonbagsConstants;
1238
- (function(MoonbagsPackage) {
1239
- (function(Curves) {
1240
- function calculateAddLiquidityCost(tokenIn, tokenReserve, tokenAmount) {
1241
- const availableReserve = tokenReserve - tokenAmount;
1242
- const numerator = tokenIn * tokenReserve;
1243
- const fraction = numerator / availableReserve;
1244
- return fraction - tokenIn;
1245
- }
1246
- Curves.calculateAddLiquidityCost = calculateAddLiquidityCost;
1247
- function calculateRemoveLiquidityReturn(tokenIn, tokenReserve, tokenRemoved) {
1248
- const denominator = tokenIn + tokenRemoved;
1249
- const fraction = tokenIn * tokenReserve / denominator;
1250
- return tokenReserve - fraction;
1251
- }
1252
- Curves.calculateRemoveLiquidityReturn = calculateRemoveLiquidityReturn;
1253
- function calculateTokenAmountReceived(tokenIn, tokenReserve, tokenOutReserve) {
1254
- const denominator = tokenIn + tokenOutReserve;
1255
- const fraction = tokenIn * tokenReserve / denominator;
1256
- return tokenReserve - fraction;
1257
- }
1258
- Curves.calculateTokenAmountReceived = calculateTokenAmountReceived;
1259
- })(MoonbagsPackage.Curves || (MoonbagsPackage.Curves = {}));
1260
- (function(Moonbags) {
1261
- async function getDynamicVirtualTokenReserves(poolId) {
1262
- const result = await getSuiClient().getDynamicFieldObject({
1263
- parentId: poolId,
1264
- name: {
1265
- type: "vector<u8>",
1266
- value: "virtual_token_reserves"
1267
- }
1268
- });
1269
- if (!result.data) return;
1270
- return BigInt(result.data.content.fields.value);
1271
- }
1272
- Moonbags.getDynamicVirtualTokenReserves = getDynamicVirtualTokenReserves;
1273
- function buyExactInReturnsWithLock(params) {
1274
- const { inputAmount, amountIn, pool, config, dynamicVirtualTokenReserves } = params;
1275
- const virtualSuiReserves = BigInt(pool.virtual_sui_reserves);
1276
- const virtualTokenReserves = BigInt(pool.virtual_token_reserves);
1277
- const remainTokenReserves = BigInt(pool.remain_token_reserves.fields.balance);
1278
- const expectedOut = MoonbagsPackage.Curves.calculateRemoveLiquidityReturn(virtualSuiReserves, virtualTokenReserves, amountIn);
1279
- const availableOut = virtualTokenReserves - (dynamicVirtualTokenReserves || remainTokenReserves);
1280
- let finalOut = expectedOut;
1281
- let usedSui = amountIn;
1282
- if (expectedOut > availableOut) {
1283
- finalOut = availableOut;
1284
- usedSui = MoonbagsPackage.Curves.calculateAddLiquidityCost(virtualSuiReserves, virtualTokenReserves, availableOut) + BigInt(1);
1285
- }
1286
- const feeAmount = usedSui * BigInt(config.platform_fee) / constants_MoonbagsConstants.FEE_DENOMINATOR;
1287
- tiny_invariant_default()(inputAmount >= usedSui + feeAmount, "Input amount is less than used SUI + fee");
1288
- return {
1289
- receivedCurve: finalOut,
1290
- receivedSui: inputAmount - usedSui - feeAmount
1291
- };
1292
- }
1293
- Moonbags.buyExactInReturnsWithLock = buyExactInReturnsWithLock;
1294
- function sellReturns(params) {
1295
- const { amountIn, pool, config } = params;
1296
- const virtualSuiReserves = BigInt(pool.virtual_sui_reserves);
1297
- const virtualTokenReserves = BigInt(pool.virtual_token_reserves);
1298
- const realSuiReserves = BigInt(pool.real_sui_reserves.fields.balance);
1299
- let rawSuiOut = MoonbagsPackage.Curves.calculateRemoveLiquidityReturn(virtualTokenReserves, virtualSuiReserves, amountIn);
1300
- if (rawSuiOut > realSuiReserves) rawSuiOut = realSuiReserves;
1301
- const feeAmount = rawSuiOut * BigInt(config.platform_fee) / constants_MoonbagsConstants.FEE_DENOMINATOR;
1302
- const finalSuiOut = rawSuiOut - feeAmount;
1303
- return {
1304
- receivedCurve: BigInt(0),
1305
- receivedSui: finalSuiOut
1306
- };
1307
- }
1308
- Moonbags.sellReturns = sellReturns;
1309
- })(MoonbagsPackage.Moonbags || (MoonbagsPackage.Moonbags = {}));
1310
- })(package_MoonbagsPackage || (package_MoonbagsPackage = {}));
1311
- var package_MoonbagsPackage;
1312
- (function(MoonbagsCalculation) {
1313
- async function getCurveAmountAfterBuy(params) {
1314
- let { suiAmount, poolId, frontendFee } = params;
1315
- const [poolMoveStruct, configMoveStruct, dynamicVirtualTokenReserves] = await Promise.all([
1316
- getMoveObjectContent(poolId),
1317
- getMoveObjectContent(constants_MoonbagsConstants.CONFIG_OBJECT_ID),
1318
- package_MoonbagsPackage.Moonbags.getDynamicVirtualTokenReserves(poolId)
1319
- ]);
1320
- const pool = poolMoveStruct;
1321
- const config = configMoveStruct;
1322
- if (void 0 !== frontendFee) suiAmount = getAmountAfterFee(suiAmount, frontendFee);
1323
- const usedSui = suiAmount * constants_MoonbagsConstants.FEE_DENOMINATOR / (constants_MoonbagsConstants.FEE_DENOMINATOR + BigInt(config.platform_fee));
1324
- const { receivedCurve } = package_MoonbagsPackage.Moonbags.buyExactInReturnsWithLock({
1325
- inputAmount: suiAmount,
1326
- amountIn: usedSui,
1327
- pool,
1328
- config,
1329
- dynamicVirtualTokenReserves
1330
- });
1331
- return receivedCurve;
1332
- }
1333
- MoonbagsCalculation.getCurveAmountAfterBuy = getCurveAmountAfterBuy;
1334
- async function getSuiAmountAfterSell(params) {
1335
- const { curveAmount, poolId, frontendFee } = params;
1336
- const [poolMoveStruct, configMoveStruct] = await Promise.all([
1337
- getMoveObjectContent(poolId),
1338
- getMoveObjectContent(constants_MoonbagsConstants.CONFIG_OBJECT_ID)
1339
- ]);
1340
- const pool = poolMoveStruct;
1341
- const config = configMoveStruct;
1342
- const { receivedSui } = package_MoonbagsPackage.Moonbags.sellReturns({
1343
- amountIn: curveAmount,
1344
- pool,
1345
- config
1346
- });
1347
- if (void 0 !== frontendFee) return getAmountAfterFee(receivedSui, frontendFee);
1348
- return receivedSui;
1349
- }
1350
- MoonbagsCalculation.getSuiAmountAfterSell = getSuiAmountAfterSell;
1351
- async function getUsedSuiForTx(params) {
1352
- let { suiAmount, frontendFee } = params;
1353
- const configMoveStruct = await getMoveObjectContent(constants_MoonbagsConstants.CONFIG_OBJECT_ID);
1354
- const config = configMoveStruct;
1355
- if (void 0 !== frontendFee) suiAmount = getAmountAfterFee(suiAmount, frontendFee);
1356
- return suiAmount * constants_MoonbagsConstants.FEE_DENOMINATOR / (constants_MoonbagsConstants.FEE_DENOMINATOR + BigInt(config.platform_fee));
1357
- }
1358
- MoonbagsCalculation.getUsedSuiForTx = getUsedSuiForTx;
1359
- })(calculation_MoonbagsCalculation || (calculation_MoonbagsCalculation = {}));
1360
- var calculation_MoonbagsCalculation;
1361
- (function(MoonbagsTransaction) {
1362
- async function buildBuyTx(params) {
1363
- const { tx, coinOut } = await splitSuiCoinAfterFeeFromBuyTx(params);
1364
- tiny_invariant_default()(coinOut, "Coin out is required");
1365
- const usedSui = await calculation_MoonbagsCalculation.getUsedSuiForTx({
1366
- suiAmount: BigInt(params.inputAmount),
1367
- frontendFee: params.frontendFee
1368
- });
1369
- const [suiCoin, curveCoin] = tx.moveCall({
1370
- target: `${constants_MoonbagsConstants.PACKAGE_ID}::moonbags::buy_exact_in_returns_with_lock`,
1371
- typeArguments: [
1372
- params.outCoinType
1373
- ],
1374
- arguments: [
1375
- tx.object(constants_MoonbagsConstants.CONFIG_OBJECT_ID),
1376
- tx.object(constants_MoonbagsConstants.LOCK_CONFIG_OBJECT_ID),
1377
- coinOut,
1378
- tx.pure.u64(usedSui),
1379
- tx.pure.u64(params.minAmountOut),
1380
- tx.object(constants_MoonbagsConstants.BURN_MANAGER_OBJECT_ID),
1381
- tx.object(constants_MoonbagsConstants.POOLS_OBJECT_ID),
1382
- tx.object(constants_MoonbagsConstants.GLOBAL_CONFIG_OBJECT_ID),
1383
- tx.object(SUI_METADATA_OBJECT_ID),
1384
- tx.object(CLOCK_OBJECT_ID)
1385
- ]
1386
- });
1387
- bluefin_BluefinTx.transferOrDestroyZeroCoin(tx, SUI_FULL_TYPE, suiCoin, params.accountAddress);
1388
- return {
1389
- tx,
1390
- coinOut: curveCoin
1391
- };
1392
- }
1393
- MoonbagsTransaction.buildBuyTx = buildBuyTx;
1394
- async function buildSellTx(params) {
1395
- tiny_invariant_default()(params.outCoinType === SUI_FULL_TYPE || params.outCoinType === SUI_TYPE, "Output must be SUI");
1396
- const { tx, coinData } = await getSplitCoinForTx({
1397
- amount: params.inputAmount,
1398
- coinType: params.inCoinType,
1399
- inheritTx: params.extendTx?.tx,
1400
- account: params.accountAddress,
1401
- splits: [
1402
- params.inputAmount
1403
- ]
1404
- });
1405
- const [inputCoin] = coinData;
1406
- const [suiCoin, curveCoin] = tx.moveCall({
1407
- target: `${constants_MoonbagsConstants.PACKAGE_ID}::moonbags::sell_returns`,
1408
- typeArguments: [
1409
- params.inCoinType
1410
- ],
1411
- arguments: [
1412
- tx.object(constants_MoonbagsConstants.CONFIG_OBJECT_ID),
1413
- inputCoin,
1414
- tx.pure.u64(params.minAmountOut),
1415
- tx.object(CLOCK_OBJECT_ID)
1416
- ]
1417
- });
1418
- bluefin_BluefinTx.transferOrDestroyZeroCoin(tx, params.inCoinType, curveCoin, params.accountAddress);
1419
- return await splitSuiCoinAfterFeeFromSellTx(tx, params, suiCoin);
1420
- }
1421
- MoonbagsTransaction.buildSellTx = buildSellTx;
1422
- async function getBuyTransaction({ coinInAmount, coinInType, coinOutType, poolId, slippage, walletAddress, tradeFee }, suiClient) {
1423
- tiny_invariant_default()(coinInType === SUI_TYPE, "coinInType must be SUI for buy transaction");
1424
- tiny_invariant_default()(coinOutType !== coinInType, "coinOutType must be different from coinInType");
1425
- tiny_invariant_default()(slippage >= 0 && slippage < 1, "slippage must be between 0 (inclusive) and 1 (exclusive)");
1426
- tiny_invariant_default()(coinInAmount > 0, "coinInAmount must be greater than 0");
1427
- const inputAmount = coinInAmount;
1428
- const outputAmount = await calculation_MoonbagsCalculation.getCurveAmountAfterBuy({
1429
- poolId: poolId,
1430
- suiAmount: inputAmount,
1431
- frontendFee: tradeFee ? tradeFee.tradeFeePercent : void 0
1432
- });
1433
- const minAmountOut = BigInt(new (external_bignumber_js_default())(outputAmount.toString()).multipliedBy(1 - slippage).toFixed(0, 3));
1434
- let { tx, coinOut } = await buildBuyTx({
1435
- accountAddress: walletAddress,
1436
- inCoinType: coinInType,
1437
- outCoinType: coinOutType,
1438
- inputAmount: inputAmount.toString(),
1439
- minAmountOut: minAmountOut.toString(),
1440
- poolId: poolId,
1441
- frontendFee: tradeFee ? tradeFee.tradeFeePercent : void 0,
1442
- frontendFeeRecipient: tradeFee ? tradeFee.tradeFeeRecipientAddress : void 0,
1443
- extendTx: void 0,
1444
- isSponsored: false
1445
- });
1446
- tiny_invariant_default()(coinOut, "Coin out is required");
1447
- tx.transferObjects([
1448
- coinOut
1449
- ], tx.pure.address(walletAddress));
1450
- tx.setSender(walletAddress);
1451
- const feeAmount = await getNeededGasFee(tx, walletAddress, 0);
1452
- tx = await addGasFee({
1453
- inheritTx: tx,
1454
- sender: walletAddress,
1455
- feeAmount,
1456
- suiInputAmount: inputAmount
1457
- });
1458
- return tx.build({
1459
- client: suiClient
1460
- });
1461
- }
1462
- MoonbagsTransaction.getBuyTransaction = getBuyTransaction;
1463
- async function getSellTransaction({ coinInAmount, coinInType, coinOutType, poolId, slippage, walletAddress, tradeFee }, suiClient) {
1464
- tiny_invariant_default()(coinOutType === SUI_TYPE, "coinOutType must be SUI for sell transaction");
1465
- tiny_invariant_default()(coinOutType !== coinInType, "coinOutType must be different from coinInType");
1466
- tiny_invariant_default()(slippage >= 0 && slippage < 1, "slippage must be between 0 (inclusive) and 1 (exclusive)");
1467
- tiny_invariant_default()(coinInAmount > 0, "coinInAmount must be greater than 0");
1468
- const inputAmount = coinInAmount;
1469
- const outputAmount = await calculation_MoonbagsCalculation.getSuiAmountAfterSell({
1470
- poolId: poolId,
1471
- curveAmount: inputAmount,
1472
- frontendFee: tradeFee ? tradeFee.tradeFeePercent : void 0
1473
- });
1474
- const minAmountOut = BigInt(new (external_bignumber_js_default())(outputAmount.toString()).multipliedBy(1 - slippage).toFixed(0, 3));
1475
- let { tx, coinOut } = await buildSellTx({
1476
- accountAddress: walletAddress,
1477
- inCoinType: coinInType,
1478
- outCoinType: coinOutType,
1479
- inputAmount: inputAmount.toString(),
1480
- minAmountOut: minAmountOut.toString(),
1481
- poolId: poolId,
1482
- frontendFee: tradeFee ? tradeFee.tradeFeePercent : void 0,
1483
- frontendFeeRecipient: tradeFee ? tradeFee.tradeFeeRecipientAddress : void 0,
1484
- extendTx: void 0,
1485
- isSponsored: false
1486
- });
1487
- tiny_invariant_default()(coinOut, "Coin out is required");
1488
- tx.transferObjects([
1489
- coinOut
1490
- ], tx.pure.address(walletAddress));
1491
- tx.setSender(walletAddress);
1492
- const feeAmount = await getNeededGasFee(tx, walletAddress, 0);
1493
- tx = await addGasFee({
1494
- inheritTx: tx,
1495
- sender: walletAddress,
1496
- feeAmount
1497
- });
1498
- return tx.build({
1499
- client: suiClient
1500
- });
1501
- }
1502
- MoonbagsTransaction.getSellTransaction = getSellTransaction;
1503
- })(transaction_MoonbagsTransaction || (transaction_MoonbagsTransaction = {}));
1504
- var transaction_MoonbagsTransaction;
1505
- const ed25519_namespaceObject = require("@mysten/sui/keypairs/ed25519");
1506
- const CONSTANTS = {
1507
- GAS_FEE_BUFFER_PERCENTAGE: 0.1
1508
- };
1509
- class DraftTransferTx {
1510
- suiClient;
1511
- constructor(suiClient){
1512
- this.suiClient = suiClient;
1513
- }
1514
- validatePrivateKey(privateKey, expectedSender) {
1515
- tiny_invariant_default()(privateKey?.trim(), "Private key is required");
1516
- const keypair = ed25519_namespaceObject.Ed25519Keypair.fromSecretKey(privateKey);
1517
- const derivedAddress = keypair.getPublicKey().toSuiAddress();
1518
- if (derivedAddress !== expectedSender) throw new Error(`Private key mismatch. Expected: ${expectedSender}, Got: ${derivedAddress}`);
1519
- return keypair;
1520
- }
1521
- async createDraft(sender, recipient, amountMIST) {
1522
- tiny_invariant_default()(sender?.trim(), "Sender address is required");
1523
- tiny_invariant_default()(recipient?.trim(), "Recipient address is required");
1524
- tiny_invariant_default()(sender !== recipient, "Sender and recipient cannot be the same");
1525
- tiny_invariant_default()(amountMIST > 0n, "Transfer amount must be at least 1 MIST");
1526
- try {
1527
- let transaction = new transactions_namespaceObject.Transaction();
1528
- const [coin] = transaction.splitCoins(transaction.gas, [
1529
- amountMIST
1530
- ]);
1531
- transaction.transferObjects([
1532
- coin
1533
- ], recipient);
1534
- transaction.setSender(sender);
1535
- const referenceGasPrice = await this.suiClient.getReferenceGasPrice();
1536
- transaction.setGasPrice(referenceGasPrice);
1537
- const feeAmount = await getNeededGasFee(transaction, sender, CONSTANTS.GAS_FEE_BUFFER_PERCENTAGE);
1538
- transaction = await addGasFee({
1539
- inheritTx: transaction,
1540
- sender,
1541
- feeAmount,
1542
- suiInputAmount: amountMIST
1543
- });
1544
- const txBytes = await transaction.build({
1545
- client: this.suiClient
1546
- });
1547
- const txDraftBase64 = Buffer.from(txBytes).toString("base64");
1548
- const txDigest = await transaction.getDigest();
1549
- return {
1550
- sender,
1551
- recipient,
1552
- amountMIST,
1553
- txDraftBase64,
1554
- txDigest
1555
- };
1556
- } catch (error) {
1557
- throw new Error(`Failed to create draft transaction: ${error instanceof Error ? error.message : "Unknown error"}`);
1558
- }
1559
- }
1560
- async execute(draftTx, privateKey) {
1561
- try {
1562
- tiny_invariant_default()(draftTx, "Draft transaction is required");
1563
- tiny_invariant_default()(draftTx.txDraftBase64?.trim(), "Transaction data is required");
1564
- const keypair = this.validatePrivateKey(privateKey, draftTx.sender);
1565
- const txBytes = (0, utils_namespaceObject.fromBase64)(draftTx.txDraftBase64);
1566
- const { signature } = await keypair.signTransaction(txBytes);
1567
- const result = await this.suiClient.executeTransactionBlock({
1568
- transactionBlock: txBytes,
1569
- signature
1570
- });
1571
- return {
1572
- success: true,
1573
- txDigest: result.digest,
1574
- effects: result.effects
1575
- };
1576
- } catch (error) {
1577
- const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
1578
- return {
1579
- success: false,
1580
- error: errorMessage
1581
- };
1582
- }
1583
- }
1584
- async getTransactionStatus(txDigest) {
1585
- tiny_invariant_default()(txDigest?.trim(), "Transaction digest is required");
1586
- try {
1587
- const txResponse = await this.suiClient.getTransactionBlock({
1588
- digest: txDigest,
1589
- options: {
1590
- showEffects: true
1591
- }
1592
- });
1593
- if (!txResponse?.effects?.status) return "pending";
1594
- return "success" === txResponse.effects.status.status ? "success" : "failure";
1595
- } catch (error) {
1596
- if (error instanceof Error) {
1597
- if (error.message.includes("not found") || error.message.includes("Could not find")) return "pending";
1598
- }
1599
- return "failure";
1600
- }
1601
- }
1602
- }
1603
- exports.AftermathAggregator = __webpack_exports__.AftermathAggregator;
1604
- exports.AstrosAggregator = __webpack_exports__.AstrosAggregator;
1605
- exports.BASE_BPS = __webpack_exports__.BASE_BPS;
1606
- exports.BLUEFIN_PACKAGE_ID = __webpack_exports__.BLUEFIN_PACKAGE_ID;
1607
- exports.BlastFunConstants = __webpack_exports__.BlastFunConstants;
1608
- exports.BlastFunCustomCalculation = __webpack_exports__.BlastFunCustomCalculation;
1609
- exports.BlastFunCustomTransaction = __webpack_exports__.BlastFunCustomTransaction;
1610
- exports.BlastFunPackage = __webpack_exports__.BlastFunPackage;
1611
- exports.BlastFunSDKCalculation = __webpack_exports__.BlastFunSDKCalculation;
1612
- exports.BlastFunSDKTransaction = __webpack_exports__.BlastFunSDKTransaction;
1613
- exports.BluefinTx = __webpack_exports__.BluefinTx;
1614
- exports.Bps = __webpack_exports__.Bps;
1615
- exports.CLOCK_OBJECT_ID = __webpack_exports__.CLOCK_OBJECT_ID;
1616
- exports.CetusAggregator = __webpack_exports__.CetusAggregator;
1617
- exports.DraftTransferTx = __webpack_exports__.DraftTransferTx;
1618
- exports.FlowXAggregator = __webpack_exports__.FlowXAggregator;
1619
- exports.MathUtils = __webpack_exports__.MathUtils;
1620
- exports.MoonbagsCalculation = __webpack_exports__.MoonbagsCalculation;
1621
- exports.MoonbagsConstants = __webpack_exports__.MoonbagsConstants;
1622
- exports.MoonbagsPackage = __webpack_exports__.MoonbagsPackage;
1623
- exports.MoonbagsTransaction = __webpack_exports__.MoonbagsTransaction;
1624
- exports.NATIVE_USDC_TOKEN_TYPE = __webpack_exports__.NATIVE_USDC_TOKEN_TYPE;
1625
- exports.SUI_FULL_TYPE = __webpack_exports__.SUI_FULL_TYPE;
1626
- exports.SUI_METADATA_OBJECT_ID = __webpack_exports__.SUI_METADATA_OBJECT_ID;
1627
- exports.SUI_TYPE = __webpack_exports__.SUI_TYPE;
1628
- exports.SevenKAggregator = __webpack_exports__.SevenKAggregator;
1629
- exports.SupportedAggregator = __webpack_exports__.SupportedAggregator;
1630
- exports.SupportedBondingCurve = __webpack_exports__.SupportedBondingCurve;
1631
- exports.TradeFeeOptions = __webpack_exports__.TradeFeeOptions;
1632
- exports.USDC_TOKEN_TYPE = __webpack_exports__.USDC_TOKEN_TYPE;
1633
- exports.adaptSuiClient = __webpack_exports__.adaptSuiClient;
1634
- exports.adaptTransaction = __webpack_exports__.adaptTransaction;
1635
- exports.addGasFee = __webpack_exports__.addGasFee;
1636
- exports.createCompatibleSuiClient = __webpack_exports__.createCompatibleSuiClient;
1637
- exports.getAmountAfterFee = __webpack_exports__.getAmountAfterFee;
1638
- exports.getCoinObjectIdsByAmount = __webpack_exports__.getCoinObjectIdsByAmount;
1639
- exports.getMemezPumpSDK = __webpack_exports__.getMemezPumpSDK;
1640
- exports.getMoveObject = __webpack_exports__.getMoveObject;
1641
- exports.getMoveObjectContent = __webpack_exports__.getMoveObjectContent;
1642
- exports.getNeededGasFee = __webpack_exports__.getNeededGasFee;
1643
- exports.getSplitCoinForTx = __webpack_exports__.getSplitCoinForTx;
1644
- exports.getSplitCoinsAfterFee = __webpack_exports__.getSplitCoinsAfterFee;
1645
- exports.getSuiClient = __webpack_exports__.getSuiClient;
1646
- exports.splitSuiCoinAfterFeeFromBuyTx = __webpack_exports__.splitSuiCoinAfterFeeFromBuyTx;
1647
- exports.splitSuiCoinAfterFeeFromSellTx = __webpack_exports__.splitSuiCoinAfterFeeFromSellTx;
1648
- for(var __webpack_i__ in __webpack_exports__)if (-1 === [
1649
- "AftermathAggregator",
1650
- "AstrosAggregator",
1651
- "BASE_BPS",
1652
- "BLUEFIN_PACKAGE_ID",
1653
- "BlastFunConstants",
1654
- "BlastFunCustomCalculation",
1655
- "BlastFunCustomTransaction",
1656
- "BlastFunPackage",
1657
- "BlastFunSDKCalculation",
1658
- "BlastFunSDKTransaction",
1659
- "BluefinTx",
1660
- "Bps",
1661
- "CLOCK_OBJECT_ID",
1662
- "CetusAggregator",
1663
- "DraftTransferTx",
1664
- "FlowXAggregator",
1665
- "MathUtils",
1666
- "MoonbagsCalculation",
1667
- "MoonbagsConstants",
1668
- "MoonbagsPackage",
1669
- "MoonbagsTransaction",
1670
- "NATIVE_USDC_TOKEN_TYPE",
1671
- "SUI_FULL_TYPE",
1672
- "SUI_METADATA_OBJECT_ID",
1673
- "SUI_TYPE",
1674
- "SevenKAggregator",
1675
- "SupportedAggregator",
1676
- "SupportedBondingCurve",
1677
- "TradeFeeOptions",
1678
- "USDC_TOKEN_TYPE",
1679
- "adaptSuiClient",
1680
- "adaptTransaction",
1681
- "addGasFee",
1682
- "createCompatibleSuiClient",
1683
- "getAmountAfterFee",
1684
- "getCoinObjectIdsByAmount",
1685
- "getMemezPumpSDK",
1686
- "getMoveObject",
1687
- "getMoveObjectContent",
1688
- "getNeededGasFee",
1689
- "getSplitCoinForTx",
1690
- "getSplitCoinsAfterFee",
1691
- "getSuiClient",
1692
- "splitSuiCoinAfterFeeFromBuyTx",
1693
- "splitSuiCoinAfterFeeFromSellTx"
1694
- ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
1695
- Object.defineProperty(exports, '__esModule', {
1696
- value: true
1697
- });
1
+ "use strict";const __rslib_import_meta_url__="undefined"==typeof document?new(require("url".replace("",""))).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href;var types_TradeFeeOptions,constants_BlastFunConstants,package_MathUtils,package_Bps,package_BlastFunPackage,custom_calculation_BlastFunCustomCalculation,bluefin_BluefinTx,custom_transaction_BlastFunCustomTransaction,sdk_calculation_BlastFunSDKCalculation,sdk_transaction_BlastFunSDKTransaction,constants_MoonbagsConstants,package_MoonbagsPackage,calculation_MoonbagsCalculation,transaction_MoonbagsTransaction,__webpack_require__={};__webpack_require__.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return __webpack_require__.d(t,{a:t}),t},__webpack_require__.d=(e,t)=>{for(var n in t)__webpack_require__.o(t,n)&&!__webpack_require__.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},__webpack_require__.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),__webpack_require__.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var __webpack_exports__={};__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,{TradeFeeOptions:()=>types_TradeFeeOptions,getMoveObjectContent:()=>getMoveObjectContent,MoonbagsCalculation:()=>calculation_MoonbagsCalculation,SevenKAggregator:()=>_7k_SevenKAggregator,SupportedBondingCurve:()=>types_SupportedBondingCurve,CLOCK_OBJECT_ID:()=>CLOCK_OBJECT_ID,BlastFunCustomCalculation:()=>custom_calculation_BlastFunCustomCalculation,BluefinTx:()=>bluefin_BluefinTx,Bps:()=>package_Bps,BlastFunCustomTransaction:()=>custom_transaction_BlastFunCustomTransaction,BASE_BPS:()=>BASE_BPS,MoonbagsConstants:()=>constants_MoonbagsConstants,splitSuiCoinAfterFeeFromBuyTx:()=>splitSuiCoinAfterFeeFromBuyTx,DraftTransferTx:()=>DraftTransferTx,SUI_FULL_TYPE:()=>SUI_FULL_TYPE,getSplitCoinForTx:()=>getSplitCoinForTx,BlastFunSDKTransaction:()=>sdk_transaction_BlastFunSDKTransaction,AstrosAggregator:()=>astros_AstrosAggregator,SUI_TYPE:()=>SUI_TYPE,AftermathAggregator:()=>aftermath_AftermathAggregator,getSplitCoinsAfterFee:()=>getSplitCoinsAfterFee,addGasFee:()=>addGasFee,MoonbagsPackage:()=>package_MoonbagsPackage,NATIVE_USDC_TOKEN_TYPE:()=>NATIVE_USDC_TOKEN_TYPE,USDC_TOKEN_TYPE:()=>USDC_TOKEN_TYPE,getAmountAfterFee:()=>getAmountAfterFee,SUI_METADATA_OBJECT_ID:()=>SUI_METADATA_OBJECT_ID,SupportedAggregator:()=>common_SupportedAggregator,splitSuiCoinAfterFeeFromSellTx:()=>splitSuiCoinAfterFeeFromSellTx,createCompatibleSuiClient:()=>createCompatibleSuiClient,BLUEFIN_PACKAGE_ID:()=>BLUEFIN_PACKAGE_ID,MoonbagsTransaction:()=>transaction_MoonbagsTransaction,BlastFunConstants:()=>constants_BlastFunConstants,CetusAggregator:()=>cetus_CetusAggregator,adaptSuiClient:()=>adaptSuiClient,getCoinObjectIdsByAmount:()=>getCoinObjectIdsByAmount,getMoveObject:()=>getMoveObject,FlowXAggregator:()=>flowx_FlowXAggregator,adaptTransaction:()=>adaptTransaction,MathUtils:()=>package_MathUtils,BlastFunSDKCalculation:()=>sdk_calculation_BlastFunSDKCalculation,BlastFunPackage:()=>package_BlastFunPackage,getMemezPumpSDK:()=>getMemezPumpSDK,getNeededGasFee:()=>getNeededGasFee});const cjs_namespaceObject=require("@7kprotocol/sdk-ts/cjs"),transactions_namespaceObject=require("@mysten/sui/transactions"),external_bignumber_js_namespaceObject=require("bignumber.js");var external_bignumber_js_default=__webpack_require__.n(external_bignumber_js_namespaceObject);class _7k_SevenKAggregator{_config;_suiClient;constructor(e,t){this._config=e,this._suiClient=t}async getTradeRoute({coinInAmount:e,coinInType:t,coinOutType:n,tradeFee:a}){try{this._config.sevenKApiKey&&cjs_namespaceObject.Config.setApiKey(this._config.sevenKApiKey);let o=a?a.tradeFeePercent:this._config.defaultTradeFee.tradeFeePercent;return(0,cjs_namespaceObject.getQuote)({tokenIn:t,tokenOut:n,amountIn:e.toString(),commissionBps:1e4*o})}catch(e){return null}}async getTransaction({walletAddress:e,completeRoute:t,slippage:n,tradeFee:a}){let o,i;a?(o=a.tradeFeePercent,i=a.tradeFeeRecipientAddress):(o=this._config.defaultTradeFee.tradeFeePercent,i=this._config.defaultTradeFee.tradeFeeRecipientAddress);let r=await (0,cjs_namespaceObject.buildTx)({quoteResponse:t,slippage:n,accountAddress:e,commission:{partner:i,commissionBps:1e4*o}});return r.tx instanceof cjs_namespaceObject.BluefinXTx?transactions_namespaceObject.Transaction.from(r.tx.txBytes).build({client:this._suiClient}):(r.tx.setSender(e),r.tx.build({client:this._suiClient}))}}(_7k_SevenKAggregator||(_7k_SevenKAggregator={})).toCommonTradeRoutes=function(e){let t=[];if(!e.routes||0===e.routes.length)return null;for(let n of e.routes){let e=[],a={};for(let t of n.hops){for(let e of t.pool.allTokens)a[e.address]=e.decimal;let n=a[t.tokenIn]??0,o=a[t.tokenOut]??0,i=BigInt(new(external_bignumber_js_default())(t.tokenInAmount).multipliedBy(10**n).toFixed(0,3)),r=BigInt(new(external_bignumber_js_default())(t.tokenOutAmount).multipliedBy(10**o).toFixed(0,3));e.push({poolAddress:t.poolId,coinIn:t.tokenIn,coinOut:t.tokenOut,amountIn:i,amountOut:r})}if(0===e.length)continue;let o=a[n.tokenIn]??0,i=a[n.tokenOut]??0,r=BigInt(new(external_bignumber_js_default())(n.tokenInAmount).multipliedBy(10**o).toFixed(0,3)),s=BigInt(new(external_bignumber_js_default())(n.tokenOutAmount).multipliedBy(10**i).toFixed(0,3));t.push({paths:e,coinIn:n.tokenIn,coinOut:n.tokenOut,amountIn:r,amountOut:s})}return 0===t.length?null:{coinIn:e.tokenIn,coinOut:e.tokenOut,amountIn:BigInt(e.swapAmountWithDecimal),amountOut:BigInt(e.returnAmountWithDecimal),routes:t}};const external_aftermath_ts_sdk_namespaceObject=require("aftermath-ts-sdk");class aftermath_AftermathAggregator{_config;_aftermathClient;_suiClient;constructor(e,t){this._config=e,this._suiClient=t}async aftermathClient(){if(this._aftermathClient)return this._aftermathClient;if(this._config.aftermathApiEndpoint?this._aftermathClient=new external_aftermath_ts_sdk_namespaceObject.Aftermath(this._config.aftermathApiEndpoint):this._aftermathClient=new external_aftermath_ts_sdk_namespaceObject.Aftermath("MAINNET"),await this._aftermathClient.init(),this._config.aftermathApiKey){let e=external_aftermath_ts_sdk_namespaceObject.Helpers.keypairFromPrivateKey(this._config.aftermathApiKey);await this._aftermathClient.Auth().init({async signMessageCallback({message:t}){let{signature:n}=await e.signPersonalMessage(t);return{signature:n}},walletAddress:e.toSuiAddress()})}return this._aftermathClient}async getTradeRoute({coinInAmount:e,coinInType:t,coinOutType:n,tradeFee:a}){let o;return o=a?{recipient:a.tradeFeeRecipientAddress,feePercentage:a.tradeFeePercent}:{recipient:this._config.defaultTradeFee.tradeFeeRecipientAddress,feePercentage:this._config.defaultTradeFee.tradeFeePercent},(await this.aftermathClient()).Router().getCompleteTradeRouteGivenAmountIn({coinInAmount:e,coinInType:t,coinOutType:n,externalFee:o})}async getTransaction({completeRoute:e,walletAddress:t,slippage:n}){let a=await this.aftermathClient(),o=await a.Router().getTransactionForCompleteTradeRoute({completeRoute:e,walletAddress:t,slippage:n,isSponsoredTx:!1});return o.setSender(t),o.build({client:this._suiClient})}}(aftermath_AftermathAggregator||(aftermath_AftermathAggregator={})).toCommonTradeRoutes=function(e){if(0===e.routes.length)return null;let t=[];for(let n of e.routes){let e=[];for(let t of n.paths)e.push({poolAddress:t.poolId,coinIn:t.coinIn.type,coinOut:t.coinOut.type,amountIn:BigInt(t.coinIn.amount),amountOut:BigInt(t.coinOut.amount)});0!==e.length&&t.push({paths:e,coinIn:n.coinIn.type,coinOut:n.coinOut.type,amountIn:n.coinIn.amount,amountOut:n.coinOut.amount})}return 0===t.length?null:{coinIn:e.coinIn.type,coinOut:e.coinOut.type,amountIn:e.coinIn.amount,amountOut:e.coinOut.amount,routes:t}};const astros_aggregator_sdk_namespaceObject=require("@naviprotocol/astros-aggregator-sdk");function isSuiCoin(e){return"0x2::sui::SUI"===e||"0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI"===e}class astros_AstrosAggregator{_config;_suiClient;constructor(e,t){this._config=e,this._suiClient=t}async getTradeRoute({coinInAmount:e,coinInType:t,coinOutType:n,tradeFee:a}){try{let o;return o=a?{fee:a.tradeFeePercent,receiverAddress:a.tradeFeeRecipientAddress}:{fee:this._config.defaultTradeFee.tradeFeePercent,receiverAddress:this._config.defaultTradeFee.tradeFeeRecipientAddress},(0,astros_aggregator_sdk_namespaceObject.getQuote)(t,n,e,this._config.astrosApiKey,{byAmountIn:!0,serviceFee:o})}catch(e){return null}}returnMergedCoins(e,t,n){if(t.length<2)return e.object(t[0].coinObjectId);let a=0,o=[];t.sort((e,t)=>Number(t.balance)-Number(e.balance)).slice(1).forEach(e=>{a>=n||(a+=Number(e.balance),o.push(e.coinObjectId))});let i=t[0].coinObjectId;return e.mergeCoins(i,o),e.object(i)}async getTransaction({completeRoute:e,walletAddress:t,slippage:n,tradeFee:a}){let o,i;o=a?{fee:a.tradeFeePercent,receiverAddress:a.tradeFeeRecipientAddress}:{fee:this._config.defaultTradeFee.tradeFeePercent,receiverAddress:this._config.defaultTradeFee.tradeFeeRecipientAddress};let r=new(external_bignumber_js_default())(e.amount_out).multipliedBy(1-n-o.fee).toNumber(),s=new transactions_namespaceObject.Transaction;if(isSuiCoin(e.from))i=s.splitCoins(s.gas,[s.pure.u64(e.amount_in)]);else{let n=await (0,astros_aggregator_sdk_namespaceObject.getCoins)(this._suiClient,t,e.from),a=this.returnMergedCoins(s,n.data,Number.parseFloat(e.amount_in));i=s.splitCoins(a,[s.pure.u64(e.amount_in)])}let u=await (0,astros_aggregator_sdk_namespaceObject.buildSwapPTBFromQuote)(t,s,r,i,e,void 0,!1,this._config.astrosApiKey,{serviceFee:o});return s.transferObjects([u],t),s.setSender(t),s.build({client:this._suiClient})}}(astros_AstrosAggregator||(astros_AstrosAggregator={})).toCommonTradeRoutes=function(e,t,n){if(0===e.routes.length)return null;let a=[];for(let t of e.routes){let e=[];for(let n of t.path)e.push({poolAddress:n.id,coinIn:n.from,coinOut:n.target,amountIn:BigInt(n.amount_in),amountOut:BigInt(n.amount_out)});0!==e.length&&a.push({amountIn:BigInt(t.amount_in),amountOut:BigInt(t.amount_out),coinIn:e[0].coinIn,coinOut:e[e.length-1].coinOut,paths:e})}return 0===a.length?null:{coinIn:t,coinOut:n,amountIn:BigInt(e.amount_in),amountOut:BigInt(e.amount_out),routes:a}};const aggregator_sdk_namespaceObject=require("@cetusprotocol/aggregator-sdk"),external_bn_js_namespaceObject=require("bn.js");var external_bn_js_default=__webpack_require__.n(external_bn_js_namespaceObject);(types_TradeFeeOptions||(types_TradeFeeOptions={})).equals=function(e,t){return e.tradeFeePercent===t.tradeFeePercent&&e.tradeFeeRecipientAddress===t.tradeFeeRecipientAddress};class cetus_CetusAggregator{_config;_suiClient;_cetusClient;constructor(e,t){this._config=e,this._suiClient=t}cetusClient(e,t){return t&&!types_TradeFeeOptions.equals(t,this._config.defaultTradeFee)?new aggregator_sdk_namespaceObject.AggregatorClient({client:this._suiClient,overlayFeeReceiver:t.tradeFeeRecipientAddress,overlayFeeRate:t.tradeFeePercent,env:aggregator_sdk_namespaceObject.Env.Mainnet,signer:e,...this._config.cetusApiKey&&this._config.cetusApiEndpoint?{apiKey:this._config.cetusApiKey,endpoint:this._config.cetusApiEndpoint}:{},partner:this._config.cetusPartnerId}):(this._cetusClient||(this._cetusClient=new aggregator_sdk_namespaceObject.AggregatorClient({client:this._suiClient,overlayFeeReceiver:this._config.defaultTradeFee.tradeFeeRecipientAddress,overlayFeeRate:this._config.defaultTradeFee.tradeFeePercent,env:aggregator_sdk_namespaceObject.Env.Mainnet,signer:e,...this._config.cetusApiKey&&this._config.cetusApiEndpoint?{apiKey:this._config.cetusApiKey,endpoint:this._config.cetusApiEndpoint}:{},partner:this._config.cetusPartnerId})),this._cetusClient)}async getTradeRoute({coinInAmount:e,coinInType:t,coinOutType:n,tradeFee:a}){return this.cetusClient(void 0,a).findRouters({from:t,target:n,amount:new(external_bn_js_default())(e.toString()),byAmountIn:!0})}async getTransaction({completeRoute:e,walletAddress:t,slippage:n,tradeFee:a}){let o=new transactions_namespaceObject.Transaction,i=this.cetusClient(t,a);return await i.fastRouterSwap({router:e,txb:o,slippage:n}),await i.devInspectTransactionBlock(o),o.setSender(t),o.build({client:this._suiClient})}}(cetus_CetusAggregator||(cetus_CetusAggregator={})).toCommonTradeRoutes=function(e,t,n){if(0===e.paths.length)return null;let a=[],o=[],i=[];for(let t=0;t<e.paths.length;t++){let n=e.paths[t],a={poolAddress:n.id,amountIn:BigInt(n.amountIn),amountOut:BigInt(n.amountOut),coinIn:n.from,coinOut:n.target};if(i.push(a),t===e.paths.length-1)o.push([...i]);else{let a=e.paths[t+1];n.target!==a.from&&(o.push([...i]),i=[])}}for(let e of o)0!==e.length&&a.push({amountIn:e[0].amountIn,amountOut:e[e.length-1].amountOut,coinIn:e[0].coinIn,coinOut:e[e.length-1].coinOut,paths:e});return 0===a.length?null:{coinIn:t,coinOut:n,amountIn:BigInt(e.amountIn.toString(10)),amountOut:BigInt(e.amountOut.toString(10)),routes:a}};var common_SupportedAggregator=function(e){return e.ASTROS="ASTROS",e.AFTERMATH="AFTERMATH",e.SEVENK="7K",e.CETUS="CETUS",e.FLOWX="FLOWX",e}({});const sdk_namespaceObject=require("@flowx-finance/sdk");function getInputPercent(e){return 1e6*e}class flowx_FlowXAggregator{_config;_suiClient;constructor(e,t){this._config=e,this._suiClient=t}getCommission(e,t){let n,a;return t?(n=t.tradeFeePercent,a=t.tradeFeeRecipientAddress):(n=this._config.defaultTradeFee.tradeFeePercent,a=this._config.defaultTradeFee.tradeFeeRecipientAddress),new sdk_namespaceObject.Commission(a,new sdk_namespaceObject.Coin(e),sdk_namespaceObject.CommissionType.PERCENTAGE,getInputPercent(n),!0)}async getTradeRoute({coinInAmount:e,coinInType:t,coinOutType:n,tradeFee:a}){let o=new sdk_namespaceObject.AggregatorQuoter("mainnet",this._config.flowxApiKey);try{return o.getRoutes({tokenIn:t,tokenOut:n,amountIn:e.toString(),commission:this.getCommission(t,a)})}catch(e){return null}}async getTransaction({walletAddress:e,completeRoute:t,slippage:n,tradeFee:a}){return new sdk_namespaceObject.TradeBuilder("mainnet",t.routes).sender(e).slippage(getInputPercent(n)).commission(this.getCommission(t.coinIn.coinType,a)).build().buildTransaction({client:this._suiClient}).then(t=>(t.setSender(e),t.build({client:this._suiClient})))}}(flowx_FlowXAggregator||(flowx_FlowXAggregator={})).toCommonTradeRoutes=function(e){if(0===e.routes.length)return null;let t=[];for(let n of e.routes){let e=[];for(let t of n.paths)e.push({amountIn:BigInt(t.amountIn.toString()),amountOut:BigInt(t.amountOut.toString()),coinIn:t.input.coinType,coinOut:t.output.coinType,poolAddress:t.pool.id});0!==e.length&&t.push({amountIn:BigInt(n.amountIn.toString()),amountOut:BigInt(n.amountOut.toString()),coinIn:n.input.coinType,coinOut:n.output.coinType,paths:e})}return 0===t.length?null:{coinIn:e.coinIn.coinType,coinOut:e.coinOut.coinType,amountIn:BigInt(e.amountIn.toString()),amountOut:BigInt(e.amountOut.toString()),routes:t}},function(e){e.PACKAGE_ID_V4="0x7e6aa6e179466ab2814425a780b122575296d011119fa69d27f289f5a28814bd",e.MEMEZ_AV_OBJECT_ID="0x2319e3e76dfad73d8f4684bdbf42be4f32d8ce4521dd61becc8261dc918d82c0"}(constants_BlastFunConstants||(constants_BlastFunConstants={}));const tiny_invariant_namespaceObject=require("@minswap/tiny-invariant");var tiny_invariant_default=__webpack_require__.n(tiny_invariant_namespaceObject);async function getMoveObjectContent(e,t){return(await getMoveObject(e,t)).fields}async function getMoveObject(e,t){let n=await e.getObject({id:t,options:{showContent:!0}}),a=n.data?.content;return tiny_invariant_default()(a,"Pool object not found or has no content"),tiny_invariant_default()("moveObject"===a.dataType,"Object is not a Move object"),a}const BASE_BPS=1e4;function getSplitCoinsAfterFee(e,t){let n=BigInt(e),a=BigInt(Number(t)*BASE_BPS);if(a===BigInt(0))return[n.toString()];let o=n*a/BigInt(BASE_BPS);return[(n-o).toString(),o.toString()]}function getAmountAfterFee(e,t){if(!t||0>=Number(t))return BigInt(e);let n=BigInt(e),a=BigInt(Number(t)*BASE_BPS);if(a===BigInt(0))return n;let o=n*a/BigInt(BASE_BPS);return n-o}async function getNeededGasFee(e,t,n,a){let{effects:{gasUsed:o,status:i}}=await e.devInspectTransactionBlock({sender:n,transactionBlock:t});if("success"!==i.status)throw Error(`Transaction failed during dev inspect: ${i.error??""}`);let r=BigInt(o.computationCost)+BigInt(o.storageCost)-BigInt(o.storageRebate),s=BigInt(Number(a)*BASE_BPS);return r*(BigInt(BASE_BPS)+s)/BigInt(BASE_BPS)}!function(e){(e.U64||(e.U64={})).mulDivUp=function(e,t,n){let a=BigInt(0);return e*t%n>BigInt(0)&&(a=BigInt(1)),e*t/n+a}}(package_MathUtils||(package_MathUtils={})),function(e){function t(e){return tiny_invariant_default()(BigInt(e)<=BigInt(1e4),"Bps overflow"),BigInt(e)}e.calcUp=function(e,t){let n,a=BigInt(e.pos0),o=BigInt(1e4);return n=a*t%o!==BigInt(0)?BigInt(1):BigInt(0),a*t/o+n},e.sub=function(e,t){return tiny_invariant_default()(BigInt(e.pos0)>=BigInt(t.pos0),"Bps underflow"),{pos0:(BigInt(e.pos0)-BigInt(t.pos0)).toString()}},e.value=function(e){return BigInt(e.pos0)},e.new_=function(e){return{pos0:t(e).toString()}},e.assertOverflow=t}(package_Bps||(package_Bps={})),function(e){var t,n;(e.MemezFun||(e.MemezFun={})).isSniperProtectedMemezFun=async function(e,t){return(await getMoveObjectContent(e,t)).public_key.length>0},(t=e.MemezFees||(e.MemezFees={})).takeWithDiscount=function(e,t,n){if("Value"===e.variant){let n=BigInt(e.fields.pos0);if(n===BigInt(0))return BigInt(0);if(t>=n)return n;throw Error(`Insufficient amount to cover fee. Required: ${n}, provided: ${t}`)}if("Percentage"===e.variant){let a=e.fields.pos0.fields;if(BigInt(a.pos0)===BigInt(0))return BigInt(0);let o=package_Bps.calcUp(package_Bps.sub(a,n),t);if(t>=o)return o;throw Error(`Insufficient amount to cover fee. Required: ${o}, provided: ${t}`)}throw Error("Unknown fee variant")},t.calculateWithDiscount=function(e,t,n){if("Value"===e.variant)return BigInt(e.fields.pos0);if("Percentage"===e.variant){let a=e.fields.pos0.fields;return package_Bps.calcUp(package_Bps.sub(a,t),n)}throw Error("Unknown fee variant")},(e.MemezBurner||(e.MemezBurner={})).calculate=function(e,t){if(package_Bps.value(e.fee.fields)===BigInt(0)||t===BigInt(0)||t>=BigInt(e.target_liquidity))return package_Bps.new_(0);let n=BigInt(1e4);return package_Bps.new_(package_MathUtils.U64.mulDivUp(package_Bps.value(e.fee.fields),package_MathUtils.U64.mulDivUp(t,n,BigInt(e.target_liquidity)),n))},(n=e.MemezPump||(e.MemezPump={})).getPumpState=async function(e,t){return await getMoveObjectContent(e,t.inner_state)},n.pump=function(t,n){let a=t.constant_product.fields,o=e.MemezFees.takeWithDiscount(a.quote_swap_fee,n,a.quote_referrer_fee.fields),i=n-o,r=BigInt(a.meme_balance),s=BigInt(a.quote_balance),u=r*i/(BigInt(a.virtual_liquidity)+s+i),c=e.MemezFees.takeWithDiscount(a.meme_swap_fee,u,a.meme_referrer_fee.fields);return u-c},n.dump=function(t,n){let a=t.constant_product.fields,o=e.MemezFees.takeWithDiscount(a.meme_swap_fee,n,a.meme_referrer_fee.fields),i=n-o,r=BigInt(a.meme_balance),s=BigInt(a.quote_balance),u=BigInt(a.virtual_liquidity),c=e.MemezBurner.calculate(a.burner.fields,s),_=package_Bps.calcUp(c,i),l=i-(package_Bps.value(c)!==BigInt(0)?_:BigInt(0)),p=(u+s)*l/(r+l);p>s&&(p=s);let g=e.MemezFees.takeWithDiscount(a.quote_swap_fee,p,a.quote_referrer_fee.fields);return p-g}}(package_BlastFunPackage||(package_BlastFunPackage={})),function(e){e.getCurveAmountAfterBuy=async function(e,t){let{suiAmount:n,poolId:a,frontendFee:o}=e,i=await getMoveObjectContent(t,a),r=await package_BlastFunPackage.MemezPump.getPumpState(t,i);return n=getAmountAfterFee(n,o),package_BlastFunPackage.MemezPump.pump(r,n)},e.getSuiAmountAfterSell=async function(e,t){let{curveAmount:n,poolId:a,frontendFee:o}=e,i=await getMoveObjectContent(t,a),r=await package_BlastFunPackage.MemezPump.getPumpState(t,i);return getAmountAfterFee(package_BlastFunPackage.MemezPump.dump(r,n),o)}}(custom_calculation_BlastFunCustomCalculation||(custom_calculation_BlastFunCustomCalculation={}));const SUI_TYPE="0x2::sui::SUI",SUI_FULL_TYPE="0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",USDC_TOKEN_TYPE="0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN",NATIVE_USDC_TOKEN_TYPE="0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",SUI_METADATA_OBJECT_ID="0x9258181f5ceac8dbffb7030890243caed69a9599d2886d957a9cb7656af3bdb3",CLOCK_OBJECT_ID="0x0000000000000000000000000000000000000000000000000000000000000006",utils_namespaceObject=require("@mysten/sui/utils"),orderByKey=(e,t,n)=>{let a;if(e?.length){do{a=!1;for(let o=0;o<e.length-1;o++){let i=BigInt(e[o][t]),r=BigInt(e[o+1][t]);if("desc"===n?i<r:i>r){let t=e[o];e[o]=e[o+1],e[o+1]=t,a=!0}}}while(a);return e}},getCoinObjectIdsByAmount=async(e,t,n,a)=>{let o,i=[],r=!0;for(;r;)try{let n=await e.getCoins({owner:t,coinType:a,cursor:o});i=[...i,...n.data],r=n.hasNextPage,o=n.nextCursor}catch(e){console.error("Error fetching data:",e),r=!1}let s=orderByKey(i.map(e=>({...e,balance:e.balance})),"balance","desc")??[],u="0",c=[],_=[];for(let e of s)if(u=(BigInt(e.balance)+BigInt(u)).toString(10),c.push(e.coinObjectId),_.push(e),BigInt(u)>=BigInt(n))break;return{objectIds:c,balance:u,objectCoins:_}};async function getSplitCoinForTx(e,t){let{account:n,amount:a,splits:o,coinType:i,inheritTx:r,inspecTransaction:s,isSponsored:u=!1}=e,c=r??new transactions_namespaceObject.Transaction,{objectIds:_}=await getCoinObjectIdsByAmount(t,n,a,i),l=_[0];if((0,utils_namespaceObject.normalizeStructTag)(i)===(0,utils_namespaceObject.normalizeStructTag)(SUI_FULL_TYPE)&&!u){let e;return s?(_.length>1&&c.mergeCoins(c.object(l),_.slice(1).map(e=>c.object(e))),e=c.splitCoins(c.object(l),o)):e=c.splitCoins(c.gas,o),{tx:c,coinData:e}}_.length>1&&c.mergeCoins(c.object(l),_.slice(1).map(e=>c.object(e)));let p=c.splitCoins(c.object(l),o);return{tx:c,coinData:p}}const BLUEFIN_PACKAGE_ID="0x62412b7268c35f3808336aee57a52836501f40b8ba5d936f8ad275e672befd04";async function splitSuiCoinAfterFeeFromBuyTx(e,t){let n,a,{inputAmount:o,accountAddress:i,frontendFee:r,frontendFeeRecipient:s,extendTx:u,isSponsored:c}=e;tiny_invariant_default()(e.inCoinType===SUI_FULL_TYPE||e.inCoinType===SUI_TYPE,"Input must be SUI");let{tx:_,coinIn:l}=u||{},p=getSplitCoinsAfterFee(o,r||"0"),g=_||new transactions_namespaceObject.Transaction;if(l)n=g.splitCoins(l,p),bluefin_BluefinTx.transferOrDestroyZeroCoin(g,SUI_FULL_TYPE,l,i);else{let{coinData:e}=await getSplitCoinForTx({account:i,amount:o,splits:p,coinType:SUI_FULL_TYPE,inheritTx:g,isSponsored:c||!1},t);n=e}if(r&&s){let[e,t]=n;a=e,g.transferObjects([t],g.pure.address(s||i))}else[a]=n;return{tx:g,coinOut:a}}async function splitSuiCoinAfterFeeFromSellTx(e,t,n){if(tiny_invariant_default()(t.outCoinType===SUI_FULL_TYPE||t.outCoinType===SUI_TYPE,"Output must be SUI"),0>=Number(t.frontendFee||0))return{tx:e,coinOut:n};let a=e.moveCall({target:"0x2::coin::value",typeArguments:[t.outCoinType],arguments:[n]}),o=e.moveCall({target:`${BLUEFIN_PACKAGE_ID}::math::mul_div_u64`,typeArguments:[],arguments:[a,e.pure.u64(BigInt(Number(t.frontendFee||"0")*BASE_BPS)),e.pure.u64(BigInt(BASE_BPS))]}),i=e.moveCall({target:"0x2::coin::split",typeArguments:[t.outCoinType],arguments:[n,o]});return e.transferObjects([i],e.pure.address(t.frontendFeeRecipient||t.accountAddress)),{tx:e,coinOut:n}}(bluefin_BluefinTx||(bluefin_BluefinTx={})).transferOrDestroyZeroCoin=function(e,t,n,a){e.moveCall({target:`${BLUEFIN_PACKAGE_ID}::utils::transfer_or_destroy`,typeArguments:[t],arguments:[n,e.pure.address(a)]})},function(e){async function t(e){let t=e||new transactions_namespaceObject.Transaction;return t.moveCall({target:`${constants_BlastFunConstants.PACKAGE_ID_V4}::memez_allowed_versions::get_allowed_versions`,arguments:[t.object(constants_BlastFunConstants.MEMEZ_AV_OBJECT_ID)],typeArguments:[]})}e.getAllowedVersions=t,e.buildBuyTx=async function(e,n){tiny_invariant_default()(!await package_BlastFunPackage.MemezFun.isSniperProtectedMemezFun(n,e.poolId),"This coin is a sniper protected coin, please use the Blast Fun website to trade it.");let{tx:a,coinOut:o}=await splitSuiCoinAfterFeeFromBuyTx(e,n);tiny_invariant_default()(o,"Coin out is required");let i=a.moveCall({target:`${constants_BlastFunConstants.PACKAGE_ID_V4}::memez_pump::pump`,typeArguments:[e.outCoinType,SUI_FULL_TYPE],arguments:[a.object(e.poolId),o,a.pure.vector("address",[]),a.pure.vector("vector<u8>",[]),a.pure.u64(e.minAmountOut),await t(a)]});return{tx:a,coinOut:i}},e.buildSellTx=async function(e,n){tiny_invariant_default()(e.outCoinType===SUI_FULL_TYPE||e.outCoinType===SUI_TYPE,"Output must be SUI");let a=await getMoveObjectContent(n,e.poolId),{tx:o,coinData:i}=await getSplitCoinForTx({amount:e.inputAmount,coinType:e.inCoinType,inheritTx:e.extendTx?.tx,account:e.accountAddress,splits:[e.inputAmount]},n),[r]=i,[s]=o.moveCall({target:`${constants_BlastFunConstants.PACKAGE_ID_V4}::memez_pump::dump`,typeArguments:[e.inCoinType,e.outCoinType],arguments:[o.object(e.poolId),o.object(a.ipx_meme_coin_treasury),r,o.pure.vector("address",[]),o.pure.u64(e.minAmountOut),await t(o)]});return await splitSuiCoinAfterFeeFromSellTx(o,e,s)}}(custom_transaction_BlastFunCustomTransaction||(custom_transaction_BlastFunCustomTransaction={}));const memez_fun_sdk_namespaceObject=require("@interest-protocol/memez-fun-sdk"),sui_core_sdk_namespaceObject=require("@interest-protocol/sui-core-sdk"),client_namespaceObject=require("@mysten/sui/client"),payload={network:sui_core_sdk_namespaceObject.Network.MAINNET,fullNodeUrl:(0,client_namespaceObject.getFullnodeUrl)("mainnet")},memezPump=new memez_fun_sdk_namespaceObject.MemezPumpSDK(payload);function getMemezPumpSDK(){return memezPump}async function addGasFee(e,t){let{inheritTx:n,sender:a,feeAmount:o,suiInputAmount:i}=e,r=n||new transactions_namespaceObject.Transaction;r.setGasBudget(o);let{objectCoins:s}=await getCoinObjectIdsByAmount(t,a,(BigInt(i||"0")+o).toString(),SUI_FULL_TYPE);return r.setGasPayment(s.map(e=>({objectId:e.coinObjectId,version:e.version,digest:e.digest}))),r}!function(e){e.getCurveAmountAfterBuy=async function(e){let{suiAmount:t,poolId:n,frontendFee:a}=e;t=getAmountAfterFee(t,a);let{memeAmountOut:o}=await getMemezPumpSDK().quotePump({pool:n,amount:t});return o},e.getSuiAmountAfterSell=async function(e){let{curveAmount:t,poolId:n,frontendFee:a}=e,{quoteAmountOut:o}=await getMemezPumpSDK().quoteDump({pool:n,amount:t});return getAmountAfterFee(o,a)}}(sdk_calculation_BlastFunSDKCalculation||(sdk_calculation_BlastFunSDKCalculation={})),function(e){async function t(e,t){let{tx:n,coinOut:a}=await splitSuiCoinAfterFeeFromBuyTx(e,t);tiny_invariant_default()(a,"Coin out is required");let{memeCoin:o,tx:i}=await getMemezPumpSDK().pump({pool:e.poolId,quoteCoin:a,minAmountOut:e.minAmountOut,tx:n});return{tx:i,coinOut:o}}async function n(e,t){tiny_invariant_default()(e.outCoinType===SUI_FULL_TYPE||e.outCoinType===SUI_TYPE,"Output must be SUI");let{tx:n,coinData:a}=await getSplitCoinForTx({amount:e.inputAmount,coinType:e.inCoinType,inheritTx:e.extendTx?.tx,account:e.accountAddress,splits:[e.inputAmount]},t),[o]=a,{quoteCoin:i,tx:r}=await getMemezPumpSDK().dump({pool:e.poolId,memeCoin:o,tx:n,minAmountOut:e.minAmountOut});return await splitSuiCoinAfterFeeFromSellTx(r,e,i)}e.buildBuyTx=t,e.buildSellTx=n,e.getBuyTransaction=async function({coinInAmount:e,coinInType:n,coinOutType:a,poolId:o,slippage:i,walletAddress:r,tradeFee:s},u){tiny_invariant_default()(n===SUI_TYPE,"coinInType must be SUI for buy transaction"),tiny_invariant_default()(a!==n,"coinOutType must be different from coinInType"),tiny_invariant_default()(i>=0&&i<1,"slippage must be between 0 (inclusive) and 1 (exclusive)"),tiny_invariant_default()(e>0,"coinInAmount must be greater than 0");let c=await sdk_calculation_BlastFunSDKCalculation.getCurveAmountAfterBuy({poolId:o,suiAmount:e,frontendFee:s?s.tradeFeePercent:void 0}),_=BigInt(new(external_bignumber_js_default())(c.toString()).multipliedBy(1-i).toFixed(0,3)),{tx:l,coinOut:p}=await t({accountAddress:r,inCoinType:n,outCoinType:a,inputAmount:e.toString(),minAmountOut:_.toString(),poolId:o,frontendFee:s?s.tradeFeePercent:void 0,frontendFeeRecipient:s?s.tradeFeeRecipientAddress:void 0,extendTx:void 0,isSponsored:!1},u);tiny_invariant_default()(p,"Coin out is required"),l.transferObjects([p],l.pure.address(r)),l.setSender(r);let g=await getNeededGasFee(u,l,r,0);return(l=await addGasFee({inheritTx:l,sender:r,feeAmount:g,suiInputAmount:e},u)).build({client:u})},e.getSellTransaction=async function({coinInAmount:e,coinInType:t,coinOutType:a,poolId:o,slippage:i,walletAddress:r,tradeFee:s},u){tiny_invariant_default()(a===SUI_TYPE,"coinOutType must be SUI for sell transaction"),tiny_invariant_default()(a!==t,"coinOutType must be different from coinInType"),tiny_invariant_default()(i>=0&&i<1,"slippage must be between 0 (inclusive) and 1 (exclusive)"),tiny_invariant_default()(e>0,"coinInAmount must be greater than 0");let c=await sdk_calculation_BlastFunSDKCalculation.getSuiAmountAfterSell({poolId:o,curveAmount:e,frontendFee:s?s.tradeFeePercent:void 0}),_=BigInt(new(external_bignumber_js_default())(c.toString()).multipliedBy(1-i).toFixed(0,3)),{tx:l,coinOut:p}=await n({accountAddress:r,inCoinType:t,outCoinType:a,inputAmount:e.toString(),minAmountOut:_.toString(),poolId:o,frontendFee:s?s.tradeFeePercent:void 0,frontendFeeRecipient:s?s.tradeFeeRecipientAddress:void 0,extendTx:void 0,isSponsored:!1},u);tiny_invariant_default()(p,"Coin out is required"),l.transferObjects([p],l.pure.address(r)),l.setSender(r);let g=await getNeededGasFee(u,l,r,0);return(l=await addGasFee({inheritTx:l,sender:r,feeAmount:g},u)).build({client:u})}}(sdk_transaction_BlastFunSDKTransaction||(sdk_transaction_BlastFunSDKTransaction={}));var types_SupportedBondingCurve=function(e){return e.BLAST_FUN="BLAST_FUN",e.MOONBAGS="MOONBAGS",e}({});function adaptSuiClient(e){return e}function adaptTransaction(e){return e}function createCompatibleSuiClient(e){return new Proxy(e,{get(e,t){let n=e[t];return"function"==typeof n?n.bind(e):n}})}!function(e){e.PACKAGE_ID="0xb8df325010942634a4afb3db3901ee215546af43a4ec4af781e7213b0bba7290",e.CONFIG_OBJECT_ID="0x74aecf86067c6913960ba4925333aefd2b1f929cafca7e21fd55a8f244b70499",e.LOCK_CONFIG_OBJECT_ID="0xfb09822d9808980abd04c51321adb850701f5f55535c6206658ef4d910c3e9be",e.BURN_MANAGER_OBJECT_ID="0x1d94aa32518d0cb00f9de6ed60d450c9a2090761f326752ffad06b2e9404f845",e.POOLS_OBJECT_ID="0xf699e7f2276f5c9a75944b37a0c5b5d9ddfd2471bf6242483b03ab2887d198d0",e.GLOBAL_CONFIG_OBJECT_ID="0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f",e.FEE_DENOMINATOR=BigInt(1e4)}(constants_MoonbagsConstants||(constants_MoonbagsConstants={})),function(e){var t,n;(t=e.Curves||(e.Curves={})).calculateAddLiquidityCost=function(e,t,n){return e*t/(t-n)-e},t.calculateRemoveLiquidityReturn=function(e,t,n){return t-e*t/(e+n)},t.calculateTokenAmountReceived=function(e,t,n){return t-e*t/(e+n)},(n=e.Moonbags||(e.Moonbags={})).getDynamicVirtualTokenReserves=async function(e,t){let n=await e.getDynamicFieldObject({parentId:t,name:{type:"vector<u8>",value:"virtual_token_reserves"}});if(n.data)return BigInt(n.data.content.fields.value)},n.buyExactInReturnsWithLock=function(t){let{inputAmount:n,amountIn:a,pool:o,config:i,dynamicVirtualTokenReserves:r}=t,s=BigInt(o.virtual_sui_reserves),u=BigInt(o.virtual_token_reserves),c=BigInt(o.remain_token_reserves.fields.balance),_=e.Curves.calculateRemoveLiquidityReturn(s,u,a),l=u-(r||c),p=_,g=a;_>l&&(p=l,g=e.Curves.calculateAddLiquidityCost(s,u,l)+BigInt(1));let d=g*BigInt(i.platform_fee)/constants_MoonbagsConstants.FEE_DENOMINATOR;return tiny_invariant_default()(n>=g+d,"Input amount is less than used SUI + fee"),{receivedCurve:p,receivedSui:n-g-d}},n.sellReturns=function(t){let{amountIn:n,pool:a,config:o}=t,i=BigInt(a.virtual_sui_reserves),r=BigInt(a.virtual_token_reserves),s=BigInt(a.real_sui_reserves.fields.balance),u=e.Curves.calculateRemoveLiquidityReturn(r,i,n);u>s&&(u=s);let c=u*BigInt(o.platform_fee)/constants_MoonbagsConstants.FEE_DENOMINATOR,_=u-c;return{receivedCurve:BigInt(0),receivedSui:_}}}(package_MoonbagsPackage||(package_MoonbagsPackage={})),function(e){e.getCurveAmountAfterBuy=async function(e,t){let{suiAmount:n,poolId:a,frontendFee:o}=e,[i,r,s]=await Promise.all([getMoveObjectContent(t,a),getMoveObjectContent(t,constants_MoonbagsConstants.CONFIG_OBJECT_ID),package_MoonbagsPackage.Moonbags.getDynamicVirtualTokenReserves(t,a)]);void 0!==o&&(n=getAmountAfterFee(n,o));let u=n*constants_MoonbagsConstants.FEE_DENOMINATOR/(constants_MoonbagsConstants.FEE_DENOMINATOR+BigInt(r.platform_fee)),{receivedCurve:c}=package_MoonbagsPackage.Moonbags.buyExactInReturnsWithLock({inputAmount:n,amountIn:u,pool:i,config:r,dynamicVirtualTokenReserves:s});return c},e.getSuiAmountAfterSell=async function(e,t){let{curveAmount:n,poolId:a,frontendFee:o}=e,[i,r]=await Promise.all([getMoveObjectContent(t,a),getMoveObjectContent(t,constants_MoonbagsConstants.CONFIG_OBJECT_ID)]),{receivedSui:s}=package_MoonbagsPackage.Moonbags.sellReturns({amountIn:n,pool:i,config:r});return void 0!==o?getAmountAfterFee(s,o):s},e.getUsedSuiForTx=async function(e,t){let{suiAmount:n,frontendFee:a}=e,o=await getMoveObjectContent(t,constants_MoonbagsConstants.CONFIG_OBJECT_ID);return void 0!==a&&(n=getAmountAfterFee(n,a)),n*constants_MoonbagsConstants.FEE_DENOMINATOR/(constants_MoonbagsConstants.FEE_DENOMINATOR+BigInt(o.platform_fee))}}(calculation_MoonbagsCalculation||(calculation_MoonbagsCalculation={})),function(e){async function t(e,t){let{tx:n,coinOut:a}=await splitSuiCoinAfterFeeFromBuyTx(e,t);tiny_invariant_default()(a,"Coin out is required");let o=await calculation_MoonbagsCalculation.getUsedSuiForTx({suiAmount:BigInt(e.inputAmount),frontendFee:e.frontendFee},t),[i,r]=n.moveCall({target:`${constants_MoonbagsConstants.PACKAGE_ID}::moonbags::buy_exact_in_returns_with_lock`,typeArguments:[e.outCoinType],arguments:[n.object(constants_MoonbagsConstants.CONFIG_OBJECT_ID),n.object(constants_MoonbagsConstants.LOCK_CONFIG_OBJECT_ID),a,n.pure.u64(o),n.pure.u64(e.minAmountOut),n.object(constants_MoonbagsConstants.BURN_MANAGER_OBJECT_ID),n.object(constants_MoonbagsConstants.POOLS_OBJECT_ID),n.object(constants_MoonbagsConstants.GLOBAL_CONFIG_OBJECT_ID),n.object(SUI_METADATA_OBJECT_ID),n.object(CLOCK_OBJECT_ID)]});return bluefin_BluefinTx.transferOrDestroyZeroCoin(n,SUI_FULL_TYPE,i,e.accountAddress),{tx:n,coinOut:r}}async function n(e,t){tiny_invariant_default()(e.outCoinType===SUI_FULL_TYPE||e.outCoinType===SUI_TYPE,"Output must be SUI");let{tx:n,coinData:a}=await getSplitCoinForTx({amount:e.inputAmount,coinType:e.inCoinType,inheritTx:e.extendTx?.tx,account:e.accountAddress,splits:[e.inputAmount]},t),[o]=a,[i,r]=n.moveCall({target:`${constants_MoonbagsConstants.PACKAGE_ID}::moonbags::sell_returns`,typeArguments:[e.inCoinType],arguments:[n.object(constants_MoonbagsConstants.CONFIG_OBJECT_ID),o,n.pure.u64(e.minAmountOut),n.object(CLOCK_OBJECT_ID)]});return bluefin_BluefinTx.transferOrDestroyZeroCoin(n,e.inCoinType,r,e.accountAddress),await splitSuiCoinAfterFeeFromSellTx(n,e,i)}e.buildBuyTx=t,e.buildSellTx=n,e.getBuyTransaction=async function({coinInAmount:e,coinInType:n,coinOutType:a,poolId:o,slippage:i,walletAddress:r,tradeFee:s},u){tiny_invariant_default()(n===SUI_TYPE,"coinInType must be SUI for buy transaction"),tiny_invariant_default()(a!==n,"coinOutType must be different from coinInType"),tiny_invariant_default()(i>=0&&i<1,"slippage must be between 0 (inclusive) and 1 (exclusive)"),tiny_invariant_default()(e>0,"coinInAmount must be greater than 0");let c=await calculation_MoonbagsCalculation.getCurveAmountAfterBuy({poolId:o,suiAmount:e,frontendFee:s?s.tradeFeePercent:void 0},u),_=BigInt(new(external_bignumber_js_default())(c.toString()).multipliedBy(1-i).toFixed(0,3)),{tx:l,coinOut:p}=await t({accountAddress:r,inCoinType:n,outCoinType:a,inputAmount:e.toString(),minAmountOut:_.toString(),poolId:o,frontendFee:s?s.tradeFeePercent:void 0,frontendFeeRecipient:s?s.tradeFeeRecipientAddress:void 0,extendTx:void 0,isSponsored:!1},u);tiny_invariant_default()(p,"Coin out is required"),l.transferObjects([p],l.pure.address(r)),l.setSender(r);let g=await getNeededGasFee(u,l,r,0);return(l=await addGasFee({inheritTx:l,sender:r,feeAmount:g,suiInputAmount:e},u)).build({client:u})},e.getSellTransaction=async function({coinInAmount:e,coinInType:t,coinOutType:a,poolId:o,slippage:i,walletAddress:r,tradeFee:s},u){tiny_invariant_default()(a===SUI_TYPE,"coinOutType must be SUI for sell transaction"),tiny_invariant_default()(a!==t,"coinOutType must be different from coinInType"),tiny_invariant_default()(i>=0&&i<1,"slippage must be between 0 (inclusive) and 1 (exclusive)"),tiny_invariant_default()(e>0,"coinInAmount must be greater than 0");let c=await calculation_MoonbagsCalculation.getSuiAmountAfterSell({poolId:o,curveAmount:e,frontendFee:s?s.tradeFeePercent:void 0},u),_=BigInt(new(external_bignumber_js_default())(c.toString()).multipliedBy(1-i).toFixed(0,3)),{tx:l,coinOut:p}=await n({accountAddress:r,inCoinType:t,outCoinType:a,inputAmount:e.toString(),minAmountOut:_.toString(),poolId:o,frontendFee:s?s.tradeFeePercent:void 0,frontendFeeRecipient:s?s.tradeFeeRecipientAddress:void 0,extendTx:void 0,isSponsored:!1},u);tiny_invariant_default()(p,"Coin out is required"),l.transferObjects([p],l.pure.address(r)),l.setSender(r);let g=await getNeededGasFee(u,l,r,0);return(l=await addGasFee({inheritTx:l,sender:r,feeAmount:g},u)).build({client:u})}}(transaction_MoonbagsTransaction||(transaction_MoonbagsTransaction={}));const ed25519_namespaceObject=require("@mysten/sui/keypairs/ed25519"),CONSTANTS={GAS_FEE_BUFFER_PERCENTAGE:.1};class DraftTransferTx{suiClient;constructor(e){this.suiClient=e}validatePrivateKey(e,t){tiny_invariant_default()(e?.trim(),"Private key is required");let n=ed25519_namespaceObject.Ed25519Keypair.fromSecretKey(e),a=n.getPublicKey().toSuiAddress();if(a!==t)throw Error(`Private key mismatch. Expected: ${t}, Got: ${a}`);return n}async createDraft(e,t,n){tiny_invariant_default()(e?.trim(),"Sender address is required"),tiny_invariant_default()(t?.trim(),"Recipient address is required"),tiny_invariant_default()(e!==t,"Sender and recipient cannot be the same"),tiny_invariant_default()(n>0n,"Transfer amount must be at least 1 MIST");try{let a=new transactions_namespaceObject.Transaction,[o]=a.splitCoins(a.gas,[n]);a.transferObjects([o],t),a.setSender(e);let i=await this.suiClient.getReferenceGasPrice();a.setGasPrice(i);let r=await getNeededGasFee(this.suiClient,a,e,CONSTANTS.GAS_FEE_BUFFER_PERCENTAGE);a=await addGasFee({inheritTx:a,sender:e,feeAmount:r,suiInputAmount:n},this.suiClient);let s=await a.build({client:this.suiClient}),u=Buffer.from(s).toString("base64"),c=await a.getDigest();return{sender:e,recipient:t,amountMIST:n,txDraftBase64:u,txDigest:c}}catch(e){throw Error(`Failed to create draft transaction: ${e instanceof Error?e.message:"Unknown error"}`)}}async execute(e,t){try{tiny_invariant_default()(e,"Draft transaction is required"),tiny_invariant_default()(e.txDraftBase64?.trim(),"Transaction data is required");let n=this.validatePrivateKey(t,e.sender),a=(0,utils_namespaceObject.fromBase64)(e.txDraftBase64),{signature:o}=await n.signTransaction(a),i=await this.suiClient.executeTransactionBlock({transactionBlock:a,signature:o});return{success:!0,txDigest:i.digest,effects:i.effects}}catch(e){return{success:!1,error:e instanceof Error?e.message:"Unknown error occurred"}}}async getTransactionStatus(e){tiny_invariant_default()(e?.trim(),"Transaction digest is required");try{let t=await this.suiClient.getTransactionBlock({digest:e,options:{showEffects:!0}});if(!t?.effects?.status)return"pending";return"success"===t.effects.status.status?"success":"failure"}catch(e){if(e instanceof Error&&(e.message.includes("not found")||e.message.includes("Could not find")))return"pending";return"failure"}}}for(var __webpack_i__ in exports.AftermathAggregator=__webpack_exports__.AftermathAggregator,exports.AstrosAggregator=__webpack_exports__.AstrosAggregator,exports.BASE_BPS=__webpack_exports__.BASE_BPS,exports.BLUEFIN_PACKAGE_ID=__webpack_exports__.BLUEFIN_PACKAGE_ID,exports.BlastFunConstants=__webpack_exports__.BlastFunConstants,exports.BlastFunCustomCalculation=__webpack_exports__.BlastFunCustomCalculation,exports.BlastFunCustomTransaction=__webpack_exports__.BlastFunCustomTransaction,exports.BlastFunPackage=__webpack_exports__.BlastFunPackage,exports.BlastFunSDKCalculation=__webpack_exports__.BlastFunSDKCalculation,exports.BlastFunSDKTransaction=__webpack_exports__.BlastFunSDKTransaction,exports.BluefinTx=__webpack_exports__.BluefinTx,exports.Bps=__webpack_exports__.Bps,exports.CLOCK_OBJECT_ID=__webpack_exports__.CLOCK_OBJECT_ID,exports.CetusAggregator=__webpack_exports__.CetusAggregator,exports.DraftTransferTx=__webpack_exports__.DraftTransferTx,exports.FlowXAggregator=__webpack_exports__.FlowXAggregator,exports.MathUtils=__webpack_exports__.MathUtils,exports.MoonbagsCalculation=__webpack_exports__.MoonbagsCalculation,exports.MoonbagsConstants=__webpack_exports__.MoonbagsConstants,exports.MoonbagsPackage=__webpack_exports__.MoonbagsPackage,exports.MoonbagsTransaction=__webpack_exports__.MoonbagsTransaction,exports.NATIVE_USDC_TOKEN_TYPE=__webpack_exports__.NATIVE_USDC_TOKEN_TYPE,exports.SUI_FULL_TYPE=__webpack_exports__.SUI_FULL_TYPE,exports.SUI_METADATA_OBJECT_ID=__webpack_exports__.SUI_METADATA_OBJECT_ID,exports.SUI_TYPE=__webpack_exports__.SUI_TYPE,exports.SevenKAggregator=__webpack_exports__.SevenKAggregator,exports.SupportedAggregator=__webpack_exports__.SupportedAggregator,exports.SupportedBondingCurve=__webpack_exports__.SupportedBondingCurve,exports.TradeFeeOptions=__webpack_exports__.TradeFeeOptions,exports.USDC_TOKEN_TYPE=__webpack_exports__.USDC_TOKEN_TYPE,exports.adaptSuiClient=__webpack_exports__.adaptSuiClient,exports.adaptTransaction=__webpack_exports__.adaptTransaction,exports.addGasFee=__webpack_exports__.addGasFee,exports.createCompatibleSuiClient=__webpack_exports__.createCompatibleSuiClient,exports.getAmountAfterFee=__webpack_exports__.getAmountAfterFee,exports.getCoinObjectIdsByAmount=__webpack_exports__.getCoinObjectIdsByAmount,exports.getMemezPumpSDK=__webpack_exports__.getMemezPumpSDK,exports.getMoveObject=__webpack_exports__.getMoveObject,exports.getMoveObjectContent=__webpack_exports__.getMoveObjectContent,exports.getNeededGasFee=__webpack_exports__.getNeededGasFee,exports.getSplitCoinForTx=__webpack_exports__.getSplitCoinForTx,exports.getSplitCoinsAfterFee=__webpack_exports__.getSplitCoinsAfterFee,exports.splitSuiCoinAfterFeeFromBuyTx=__webpack_exports__.splitSuiCoinAfterFeeFromBuyTx,exports.splitSuiCoinAfterFeeFromSellTx=__webpack_exports__.splitSuiCoinAfterFeeFromSellTx,__webpack_exports__)-1===["AftermathAggregator","AstrosAggregator","BASE_BPS","BLUEFIN_PACKAGE_ID","BlastFunConstants","BlastFunCustomCalculation","BlastFunCustomTransaction","BlastFunPackage","BlastFunSDKCalculation","BlastFunSDKTransaction","BluefinTx","Bps","CLOCK_OBJECT_ID","CetusAggregator","DraftTransferTx","FlowXAggregator","MathUtils","MoonbagsCalculation","MoonbagsConstants","MoonbagsPackage","MoonbagsTransaction","NATIVE_USDC_TOKEN_TYPE","SUI_FULL_TYPE","SUI_METADATA_OBJECT_ID","SUI_TYPE","SevenKAggregator","SupportedAggregator","SupportedBondingCurve","TradeFeeOptions","USDC_TOKEN_TYPE","adaptSuiClient","adaptTransaction","addGasFee","createCompatibleSuiClient","getAmountAfterFee","getCoinObjectIdsByAmount","getMemezPumpSDK","getMoveObject","getMoveObjectContent","getNeededGasFee","getSplitCoinForTx","getSplitCoinsAfterFee","splitSuiCoinAfterFeeFromBuyTx","splitSuiCoinAfterFeeFromSellTx"].indexOf(__webpack_i__)&&(exports[__webpack_i__]=__webpack_exports__[__webpack_i__]);Object.defineProperty(exports,"__esModule",{value:!0});