@minswap/noodles-sdk 0.0.6 → 0.0.7

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