@minswap/noodles-sdk 0.0.14 → 0.0.16

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 +1 @@
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});
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__,{getNeededGasFee:()=>getNeededGasFee,TradeFeeOptions:()=>types_TradeFeeOptions,DEFAULT_TRADE_FEE:()=>DEFAULT_TRADE_FEE,getMoveObjectContent:()=>getMoveObjectContent,MoonbagsCalculation:()=>calculation_MoonbagsCalculation,CONFIG_ID:()=>CONFIG_ID,SevenKAggregator:()=>_7k_SevenKAggregator,SupportedBondingCurve:()=>types_SupportedBondingCurve,MoonbagsConstants:()=>constants_MoonbagsConstants,BASE_BPS:()=>BASE_BPS,BlastFunCustomCalculation:()=>custom_calculation_BlastFunCustomCalculation,BluefinTx:()=>bluefin_BluefinTx,BlastFunCustomTransaction:()=>custom_transaction_BlastFunCustomTransaction,Bps:()=>package_Bps,CLOCK_OBJECT_ID:()=>CLOCK_OBJECT_ID,CurveModule:()=>CurveModule,DraftTransferTx:()=>DraftTransferTx,SUI_FULL_TYPE:()=>SUI_FULL_TYPE,AggregatorModule:()=>AggregatorModule,getSplitCoinForTx:()=>getSplitCoinForTx,splitSuiCoinAfterFeeFromBuyTx:()=>splitSuiCoinAfterFeeFromBuyTx,BlastFunSDKTransaction:()=>sdk_transaction_BlastFunSDKTransaction,AstrosAggregator:()=>astros_AstrosAggregator,AftermathAggregator:()=>aftermath_AftermathAggregator,SUI_TYPE:()=>SUI_TYPE,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,BOOSTING_PACKAGE_ID:()=>BOOSTING_PACKAGE_ID,splitSuiCoinAfterFeeFromSellTx:()=>splitSuiCoinAfterFeeFromSellTx,createCompatibleSuiClient:()=>createCompatibleSuiClient,BLUEFIN_PACKAGE_ID:()=>BLUEFIN_PACKAGE_ID,MoonbagsTransaction:()=>transaction_MoonbagsTransaction,ADMIN_CAP_ID:()=>ADMIN_CAP_ID,BlastFunConstants:()=>constants_BlastFunConstants,CetusAggregator:()=>cetus_CetusAggregator,adaptSuiClient:()=>adaptSuiClient,getCoinObjectIdsByAmount:()=>getCoinObjectIdsByAmount,NoodlesSdk:()=>NoodlesSdk,getMoveObject:()=>getMoveObject,FlowXAggregator:()=>flowx_FlowXAggregator,adaptTransaction:()=>adaptTransaction,MathUtils:()=>package_MathUtils,BlastFunSDKCalculation:()=>sdk_calculation_BlastFunSDKCalculation,BlastFunPackage:()=>package_BlastFunPackage,BoostingModule:()=>BoostingModule,getMemezPumpSDK:()=>getMemezPumpSDK});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,r;a?(o=a.tradeFeePercent,r=a.tradeFeeRecipientAddress):(o=this._config.defaultTradeFee.tradeFeePercent,r=this._config.defaultTradeFee.tradeFeeRecipientAddress);let i=await (0,cjs_namespaceObject.buildTx)({quoteResponse:t,slippage:n,accountAddress:e,commission:{partner:r,commissionBps:1e4*o}});return i.tx instanceof cjs_namespaceObject.BluefinXTx?transactions_namespaceObject.Transaction.from(i.tx.txBytes).build({client:this._suiClient}):(i.tx.setSender(e),i.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,r=BigInt(new(external_bignumber_js_default())(t.tokenInAmount).multipliedBy(10**n).toFixed(0,3)),i=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:r,amountOut:i})}if(0===e.length)continue;let o=a[n.tokenIn]??0,r=a[n.tokenOut]??0,i=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**r).toFixed(0,3));t.push({paths:e,coinIn:n.tokenIn,coinOut:n.tokenOut,amountIn:i,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 r=t[0].coinObjectId;return e.mergeCoins(r,o),e.object(r)}async getTransaction({completeRoute:e,walletAddress:t,slippage:n,tradeFee:a}){let o,r;o=a?{fee:a.tradeFeePercent,receiverAddress:a.tradeFeeRecipientAddress}:{fee:this._config.defaultTradeFee.tradeFeePercent,receiverAddress:this._config.defaultTradeFee.tradeFeeRecipientAddress};let i=new(external_bignumber_js_default())(e.amount_out).multipliedBy(1-n-o.fee).toNumber(),s=new transactions_namespaceObject.Transaction;if(isSuiCoin(e.from))r=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));r=s.splitCoins(a,[s.pure.u64(e.amount_in)])}let u=await (0,astros_aggregator_sdk_namespaceObject.buildSwapPTBFromQuote)(t,s,i,r,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,r=this.cetusClient(t,a);return await r.fastRouterSwap({router:e,txb:o,slippage:n}),await r.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=[],r=[];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(r.push(a),t===e.paths.length-1)o.push([...r]);else{let a=e.paths[t+1];n.target!==a.from&&(o.push([...r]),r=[])}}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:r}}=await e.devInspectTransactionBlock({sender:n,transactionBlock:t});if("success"!==r.status)throw Error(`Transaction failed during dev inspect: ${r.error??""}`);let i=BigInt(o.computationCost)+BigInt(o.storageCost)-BigInt(o.storageRebate),s=BigInt(Number(a)*BASE_BPS);return i*(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),r=n-o,i=BigInt(a.meme_balance),s=BigInt(a.quote_balance),u=i*r/(BigInt(a.virtual_liquidity)+s+r),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),r=n-o,i=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,r),l=r-(package_Bps.value(c)!==BigInt(0)?_:BigInt(0)),g=(u+s)*l/(i+l);g>s&&(g=s);let d=e.MemezFees.takeWithDiscount(a.quote_swap_fee,g,a.quote_referrer_fee.fields);return g-d}}(package_BlastFunPackage||(package_BlastFunPackage={})),function(e){e.getCurveAmountAfterBuy=async function(e,t){let{suiAmount:n,poolId:a,frontendFee:o}=e,r=await getMoveObjectContent(t,a),i=await package_BlastFunPackage.MemezPump.getPumpState(t,r);return n=getAmountAfterFee(n,o),package_BlastFunPackage.MemezPump.pump(i,n)},e.getSuiAmountAfterSell=async function(e,t){let{curveAmount:n,poolId:a,frontendFee:o}=e,r=await getMoveObjectContent(t,a),i=await package_BlastFunPackage.MemezPump.getPumpState(t,r);return getAmountAfterFee(package_BlastFunPackage.MemezPump.dump(i,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 r=BigInt(e[o][t]),i=BigInt(e[o+1][t]);if("desc"===n?r<i:r>i){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,r=[],i=!0;for(;i;)try{let n=await e.getCoins({owner:t,coinType:a,cursor:o});r=[...r,...n.data],i=n.hasNextPage,o=n.nextCursor}catch(e){console.error("Error fetching data:",e),i=!1}let s=orderByKey(r.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:r,inheritTx:i,inspecTransaction:s,isSponsored:u=!1}=e,c=i??new transactions_namespaceObject.Transaction,{objectIds:_}=await getCoinObjectIdsByAmount(t,n,a,r),l=_[0];if((0,utils_namespaceObject.normalizeStructTag)(r)===(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 g=c.splitCoins(c.object(l),o);return{tx:c,coinData:g}}const BLUEFIN_PACKAGE_ID="0x62412b7268c35f3808336aee57a52836501f40b8ba5d936f8ad275e672befd04";async function splitSuiCoinAfterFeeFromBuyTx(e,t){let n,a,{inputAmount:o,accountAddress:r,frontendFee:i,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||{},g=getSplitCoinsAfterFee(o,i||"0"),d=_||new transactions_namespaceObject.Transaction;if(l)n=d.splitCoins(l,g),bluefin_BluefinTx.transferOrDestroyZeroCoin(d,SUI_FULL_TYPE,l,r);else{let{coinData:e}=await getSplitCoinForTx({account:r,amount:o,splits:g,coinType:SUI_FULL_TYPE,inheritTx:d,isSponsored:c||!1},t);n=e}if(i&&s){let[e,t]=n;a=e,d.transferObjects([t],d.pure.address(s||r))}else[a]=n;return{tx:d,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))]}),r=e.moveCall({target:"0x2::coin::split",typeArguments:[t.outCoinType],arguments:[n,o]});return e.transferObjects([r],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 r=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:r}},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:r}=await getSplitCoinForTx({amount:e.inputAmount,coinType:e.inCoinType,inheritTx:e.extendTx?.tx,account:e.accountAddress,splits:[e.inputAmount]},n),[i]=r,[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),i,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:r}=e,i=n||new transactions_namespaceObject.Transaction;i.setGasBudget(o);let{objectCoins:s}=await getCoinObjectIdsByAmount(t,a,(BigInt(r||"0")+o).toString(),SUI_FULL_TYPE);return i.setGasPayment(s.map(e=>({objectId:e.coinObjectId,version:e.version,digest:e.digest}))),i}!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:r}=await getMemezPumpSDK().pump({pool:e.poolId,quoteCoin:a,minAmountOut:e.minAmountOut,tx:n});return{tx:r,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:r,tx:i}=await getMemezPumpSDK().dump({pool:e.poolId,memeCoin:o,tx:n,minAmountOut:e.minAmountOut});return await splitSuiCoinAfterFeeFromSellTx(i,e,r)}e.buildBuyTx=t,e.buildSellTx=n,e.getBuyTransaction=async function({coinInAmount:e,coinInType:n,coinOutType:a,poolId:o,slippage:r,walletAddress:i,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()(r>=0&&r<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-r).toFixed(0,3)),{tx:l,coinOut:g}=await t({accountAddress:i,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()(g,"Coin out is required"),l.transferObjects([g],l.pure.address(i)),l.setSender(i);let d=await getNeededGasFee(u,l,i,0);return(l=await addGasFee({inheritTx:l,sender:i,feeAmount:d,suiInputAmount:e},u)).build({client:u})},e.getSellTransaction=async function({coinInAmount:e,coinInType:t,coinOutType:a,poolId:o,slippage:r,walletAddress:i,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()(r>=0&&r<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-r).toFixed(0,3)),{tx:l,coinOut:g}=await n({accountAddress:i,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()(g,"Coin out is required"),l.transferObjects([g],l.pure.address(i)),l.setSender(i);let d=await getNeededGasFee(u,l,i,0);return(l=await addGasFee({inheritTx:l,sender:i,feeAmount:d},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:r,dynamicVirtualTokenReserves:i}=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-(i||c),g=_,d=a;_>l&&(g=l,d=e.Curves.calculateAddLiquidityCost(s,u,l)+BigInt(1));let p=d*BigInt(r.platform_fee)/constants_MoonbagsConstants.FEE_DENOMINATOR;return tiny_invariant_default()(n>=d+p,"Input amount is less than used SUI + fee"),{receivedCurve:g,receivedSui:n-d-p}},n.sellReturns=function(t){let{amountIn:n,pool:a,config:o}=t,r=BigInt(a.virtual_sui_reserves),i=BigInt(a.virtual_token_reserves),s=BigInt(a.real_sui_reserves.fields.balance),u=e.Curves.calculateRemoveLiquidityReturn(i,r,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,[r,i,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(i.platform_fee)),{receivedCurve:c}=package_MoonbagsPackage.Moonbags.buyExactInReturnsWithLock({inputAmount:n,amountIn:u,pool:r,config:i,dynamicVirtualTokenReserves:s});return c},e.getSuiAmountAfterSell=async function(e,t){let{curveAmount:n,poolId:a,frontendFee:o}=e,[r,i]=await Promise.all([getMoveObjectContent(t,a),getMoveObjectContent(t,constants_MoonbagsConstants.CONFIG_OBJECT_ID)]),{receivedSui:s}=package_MoonbagsPackage.Moonbags.sellReturns({amountIn:n,pool:r,config:i});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),[r,i]=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,r,e.accountAddress),{tx:n,coinOut:i}}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,[r,i]=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,i,e.accountAddress),await splitSuiCoinAfterFeeFromSellTx(n,e,r)}e.buildBuyTx=t,e.buildSellTx=n,e.getBuyTransaction=async function({coinInAmount:e,coinInType:n,coinOutType:a,poolId:o,slippage:r,walletAddress:i,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()(r>=0&&r<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-r).toFixed(0,3)),{tx:l,coinOut:g}=await t({accountAddress:i,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()(g,"Coin out is required"),l.transferObjects([g],l.pure.address(i)),l.setSender(i);let d=await getNeededGasFee(u,l,i,0);return(l=await addGasFee({inheritTx:l,sender:i,feeAmount:d,suiInputAmount:e},u)).build({client:u})},e.getSellTransaction=async function({coinInAmount:e,coinInType:t,coinOutType:a,poolId:o,slippage:r,walletAddress:i,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()(r>=0&&r<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-r).toFixed(0,3)),{tx:l,coinOut:g}=await n({accountAddress:i,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()(g,"Coin out is required"),l.transferObjects([g],l.pure.address(i)),l.setSender(i);let d=await getNeededGasFee(u,l,i,0);return(l=await addGasFee({inheritTx:l,sender:i,feeAmount:d},u)).build({client:u})}}(transaction_MoonbagsTransaction||(transaction_MoonbagsTransaction={}));class AggregatorModule{sdk;_astrosAggregator;_aftermathAggregator;_sevenkAggregator;_cetusAggregator;_flowXAggregator;constructor(e){this.sdk=e,this._astrosAggregator=new astros_AstrosAggregator({defaultTradeFee:e.options.tradeFee,astrosApiKey:e.options.astrosApiKey},e.suiClient),this._aftermathAggregator=new aftermath_AftermathAggregator({defaultTradeFee:e.options.tradeFee,aftermathApiKey:e.options.aftermathApiKey,aftermathApiEndpoint:e.options.aftermathApiEndpoint},e.suiClient),this._sevenkAggregator=new _7k_SevenKAggregator({defaultTradeFee:e.options.tradeFee,sevenKApiKey:e.options.sevenKApiKey},e.suiClient),this._cetusAggregator=new cetus_CetusAggregator({defaultTradeFee:e.options.tradeFee,cetusApiKey:e.options.cetusApiKey,cetusApiEndpoint:e.options.cetusApiEndpoint,cetusPartnerId:e.options.cetusPartnerId},e.suiClient),this._flowXAggregator=new flowx_FlowXAggregator({defaultTradeFee:e.options.tradeFee,flowxApiKey:e.options.flowxApiKey},e.suiClient)}get astrosAggregator(){return this._astrosAggregator}get aftermathAggregator(){return this._aftermathAggregator}get sevenkAggregator(){return this._sevenkAggregator}get cetusAggregator(){return this._cetusAggregator}get flowXAggregator(){return this._flowXAggregator}async getTradeRoute(e,t){let n;switch(e){case common_SupportedAggregator.ASTROS:{let e,a=await this._astrosAggregator.getTradeRoute(t);if(!a)return null;let o=astros_AstrosAggregator.toCommonTradeRoutes(a,t.coinInType,t.coinOutType);if(!o)return null;e=t.tradeFee?t.tradeFee.tradeFeePercent:this.sdk.options.tradeFee.tradeFeePercent,o.amountOut=BigInt(new(external_bignumber_js_default())(a.amount_out).multipliedBy(1-e).toFixed(0,3)),n={route:o,aggregatorRoute:a};break}case common_SupportedAggregator.AFTERMATH:{let e=await this._aftermathAggregator.getTradeRoute(t),a=aftermath_AftermathAggregator.toCommonTradeRoutes(e);if(!a)return null;n={route:a,aggregatorRoute:e};break}case common_SupportedAggregator.SEVENK:{let e=await this._sevenkAggregator.getTradeRoute(t);if(!e)return null;let a=_7k_SevenKAggregator.toCommonTradeRoutes(e);if(!a)return null;n={route:a,aggregatorRoute:e};break}case common_SupportedAggregator.CETUS:{let e=await this._cetusAggregator.getTradeRoute(t);if(!e)return null;let a=cetus_CetusAggregator.toCommonTradeRoutes(e,t.coinInType,t.coinOutType);if(!a)return null;n={route:a,aggregatorRoute:e};break}case common_SupportedAggregator.FLOWX:{let e=await this._flowXAggregator.getTradeRoute(t);if(!e)return null;let a=flowx_FlowXAggregator.toCommonTradeRoutes(e);if(!a)return null;n={route:a,aggregatorRoute:e}}}return n}async getTransactionByRoute(e,t){switch(e){case common_SupportedAggregator.ASTROS:return this._astrosAggregator.getTransaction({walletAddress:t.walletAddress,completeRoute:t.completeRoute,slippage:t.slippage,tradeFee:t.tradeFee});case common_SupportedAggregator.AFTERMATH:return this._aftermathAggregator.getTransaction({walletAddress:t.walletAddress,completeRoute:t.completeRoute,slippage:t.slippage});case common_SupportedAggregator.SEVENK:return this._sevenkAggregator.getTransaction({walletAddress:t.walletAddress,completeRoute:t.completeRoute,slippage:t.slippage,tradeFee:t.tradeFee});case common_SupportedAggregator.CETUS:return this._cetusAggregator.getTransaction({walletAddress:t.walletAddress,completeRoute:t.completeRoute,slippage:t.slippage,tradeFee:t.tradeFee});case common_SupportedAggregator.FLOWX:return this._flowXAggregator.getTransaction({walletAddress:t.walletAddress,completeRoute:t.completeRoute,slippage:t.slippage,tradeFee:t.tradeFee})}}async getTradeTransaction(e,t){let n=await this.getTradeRoute(e,{coinInAmount:t.coinInAmount,coinInType:t.coinInType,coinOutType:t.coinOutType,tradeFee:t.tradeFee});if(!n)return null;let a=await this.getTransactionByRoute(e,{walletAddress:t.walletAddress,completeRoute:n.aggregatorRoute,slippage:t.slippage,tradeFee:t.tradeFee});return{route:n.route,aggregatorRoute:n.aggregatorRoute,transaction:a}}async getTradeTransactionWithBestRate(e){let t=Object.keys(common_SupportedAggregator),n=await Promise.all(t.map(async t=>{try{return await this.getTradeRoute(t,e)}catch{return null}})),a=null,o=null;for(let e=0;e<n.length;e++){let r=n[e],i=t[e];if(r&&(!a||r.route.amountOut>a.route.amountOut)){a=r,o=i;continue}}if(!a||!o)return null;let r=await this.getTransactionByRoute(o,{walletAddress:e.walletAddress,completeRoute:a.aggregatorRoute,slippage:e.slippage,tradeFee:e.tradeFee});return{route:a.route,aggregatorRoute:a.aggregatorRoute,transaction:r}}}const BOOSTING_PACKAGE_ID="0x3cebf157c3595b2b5a590a506c60128506237d889917a0f7317a2c7bf6ed0289",CONFIG_ID="0x1a502860215ca71a83fd8e0e09e6bb640d0faef35ddd385cea744d06f18dcfdb",ADMIN_CAP_ID="0xefa0c0ee48ad31da2e9f4ef2eef96834857bde142317edcc0f787076fbf077fd";class BoostingModule{sdk;constructor(e){this.sdk=e}async getConfig(){let e=await this.sdk.suiClient.getObject({id:CONFIG_ID,options:{showContent:!0}});tiny_invariant_default()(e.data?.content,"Config object not found or has no content"),tiny_invariant_default()(e.data?.content.dataType==="moveObject","Config object is not a Move object");let t=e.data.content.fields,n=t.id.id,a=t.fee_receiver,o=t.tiers.fields.contents,r={};for(let e of o){let t=e.fields.key,n=e.fields.value.fields.duration,a=e.fields.value.fields.amount,o=e.fields.value.fields.point,i=e.fields.value.fields.original_amount;r[t]={duration:BigInt(n),amount:BigInt(a),point:BigInt(o),originalAmount:BigInt(i)}}return{id:n,receiverAddress:a,tiers:r}}async buildPayBoostingTx({walletAddress:e,tierId:t,boostingCoinType:n,currentTx:a}){let o=await this.getConfig();tiny_invariant_default()(t in o.tiers,"Invalid tier ID");let r=o.tiers[t].amount,i=a||new transactions_namespaceObject.Transaction,s=i.splitCoins(i.gas,[i.pure.u64(r)]);i.moveCall({target:`${BOOSTING_PACKAGE_ID}::boosting::pay`,typeArguments:[(0,utils_namespaceObject.normalizeStructTag)(n)],arguments:[i.object(CONFIG_ID),i.pure.u64(t),s]}),i.setSender(e);let u=await getNeededGasFee(this.sdk.suiClient,i,e,0);return addGasFee({inheritTx:i,sender:e,feeAmount:u},this.sdk.suiClient)}async buildAddTierTx({adminAddress:e,tierId:t,duration:n,point:a,originalAmount:o,amount:r,currentTx:i}){let s=i||new transactions_namespaceObject.Transaction;s.moveCall({target:`${BOOSTING_PACKAGE_ID}::config::add_tier`,typeArguments:[],arguments:[s.object(CONFIG_ID),s.object(ADMIN_CAP_ID),s.pure.u64(t),s.pure.u64(a),s.pure.u64(n),s.pure.u64(o),s.pure.u64(r)]}),s.setSender(e);let u=await getNeededGasFee(this.sdk.suiClient,s,e,0);return addGasFee({inheritTx:s,sender:e,feeAmount:u},this.sdk.suiClient)}async buildUpdateTierTx({adminAddress:e,tierId:t,duration:n,amount:a,originalAmount:o,point:r,currentTx:i}){let s=i||new transactions_namespaceObject.Transaction;s.moveCall({target:`${BOOSTING_PACKAGE_ID}::config::update_tier`,typeArguments:[],arguments:[s.object(CONFIG_ID),s.object(ADMIN_CAP_ID),s.pure.u64(t),s.pure.u64(n),s.pure.u64(a),s.pure.u64(r),s.pure.u64(o)]}),s.setSender(e);let u=await getNeededGasFee(this.sdk.suiClient,s,e,0);return addGasFee({inheritTx:s,sender:e,feeAmount:u},this.sdk.suiClient)}async buildRemoveTierTx({adminAddress:e,tierId:t,currentTx:n}){let a=n||new transactions_namespaceObject.Transaction;a.moveCall({target:`${BOOSTING_PACKAGE_ID}::config::remove_tier`,typeArguments:[],arguments:[a.object(CONFIG_ID),a.object(ADMIN_CAP_ID),a.pure.u64(t)]}),a.setSender(e);let o=await getNeededGasFee(this.sdk.suiClient,a,e,0);return addGasFee({inheritTx:a,sender:e,feeAmount:o},this.sdk.suiClient)}async buildUpdateFeeReceiver({adminAddress:e,newReceiverAddress:t,currentTx:n}){let a=n||new transactions_namespaceObject.Transaction;a.moveCall({target:`${BOOSTING_PACKAGE_ID}::config::update_fee_receiver`,typeArguments:[],arguments:[a.object(CONFIG_ID),a.object(ADMIN_CAP_ID),a.pure.address(t)]}),a.setSender(e);let o=await getNeededGasFee(this.sdk.suiClient,a,e,0);return addGasFee({inheritTx:a,sender:e,feeAmount:o},this.sdk.suiClient)}async buildPayBoostingWithAdminTx({walletAddress:e,tierId:t,customAmount:n,boostingCoinType:a,currentTx:o}){let r=o||new transactions_namespaceObject.Transaction,i=r.splitCoins(r.gas,[r.pure.u64(n)]);r.moveCall({target:`${BOOSTING_PACKAGE_ID}::boosting::pay_with_admin`,typeArguments:[(0,utils_namespaceObject.normalizeStructTag)(a)],arguments:[r.object(ADMIN_CAP_ID),r.object(CONFIG_ID),r.pure.u64(t),r.pure.u64(n),i]}),r.setSender(e);let s=await getNeededGasFee(this.sdk.suiClient,r,e,0);return addGasFee({inheritTx:r,sender:e,feeAmount:s},this.sdk.suiClient)}}class CurveModule{sdk;constructor(e){this.sdk=e}async getTradeTransaction(e,t){let n,{coinInType:a,coinOutType:o}=t;tiny_invariant_default()(a!==o,"coinInType and coinOutType must be different"),tiny_invariant_default()(a===SUI_TYPE||o===SUI_TYPE,"One of coinInType or coinOutType must be SUI");let r=a===SUI_TYPE;switch(e){case types_SupportedBondingCurve.MOONBAGS:n=r?await transaction_MoonbagsTransaction.getBuyTransaction(t,this.sdk.suiClient):await transaction_MoonbagsTransaction.getSellTransaction(t,this.sdk.suiClient);break;case types_SupportedBondingCurve.BLAST_FUN:n=r?await sdk_transaction_BlastFunSDKTransaction.getBuyTransaction(t,this.sdk.suiClient):await sdk_transaction_BlastFunSDKTransaction.getSellTransaction(t,this.sdk.suiClient);break;default:throw Error(`Unsupported bonding curve platform: ${e}`)}return n}}const DEFAULT_TRADE_FEE={tradeFeePercent:.01,tradeFeeRecipientAddress:"0xdaf1c8ed29d89cd8f217f609bad0a668fa6f158c12000bfa5f93e670c99e24ff"};class NoodlesSdk{options;_suiClient;aggregatorModule;curveModule;boostingModule;constructor(e){this.options=e,this._suiClient=new client_namespaceObject.SuiClient({url:(0,client_namespaceObject.getFullnodeUrl)("mainnet")}),this.aggregatorModule=new AggregatorModule(this),this.curveModule=new CurveModule(this),this.boostingModule=new BoostingModule(this)}get suiClient(){return this._suiClient}}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 r=await this.suiClient.getReferenceGasPrice();a.setGasPrice(r);let i=await getNeededGasFee(this.suiClient,a,e,CONSTANTS.GAS_FEE_BUFFER_PERCENTAGE);a=await addGasFee({inheritTx:a,sender:e,feeAmount:i,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),r=await this.suiClient.executeTransactionBlock({transactionBlock:a,signature:o});return{success:!0,txDigest:r.digest,effects:r.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.ADMIN_CAP_ID=__webpack_exports__.ADMIN_CAP_ID,exports.AftermathAggregator=__webpack_exports__.AftermathAggregator,exports.AggregatorModule=__webpack_exports__.AggregatorModule,exports.AstrosAggregator=__webpack_exports__.AstrosAggregator,exports.BASE_BPS=__webpack_exports__.BASE_BPS,exports.BLUEFIN_PACKAGE_ID=__webpack_exports__.BLUEFIN_PACKAGE_ID,exports.BOOSTING_PACKAGE_ID=__webpack_exports__.BOOSTING_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.BoostingModule=__webpack_exports__.BoostingModule,exports.Bps=__webpack_exports__.Bps,exports.CLOCK_OBJECT_ID=__webpack_exports__.CLOCK_OBJECT_ID,exports.CONFIG_ID=__webpack_exports__.CONFIG_ID,exports.CetusAggregator=__webpack_exports__.CetusAggregator,exports.CurveModule=__webpack_exports__.CurveModule,exports.DEFAULT_TRADE_FEE=__webpack_exports__.DEFAULT_TRADE_FEE,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.NoodlesSdk=__webpack_exports__.NoodlesSdk,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===["ADMIN_CAP_ID","AftermathAggregator","AggregatorModule","AstrosAggregator","BASE_BPS","BLUEFIN_PACKAGE_ID","BOOSTING_PACKAGE_ID","BlastFunConstants","BlastFunCustomCalculation","BlastFunCustomTransaction","BlastFunPackage","BlastFunSDKCalculation","BlastFunSDKTransaction","BluefinTx","BoostingModule","Bps","CLOCK_OBJECT_ID","CONFIG_ID","CetusAggregator","CurveModule","DEFAULT_TRADE_FEE","DraftTransferTx","FlowXAggregator","MathUtils","MoonbagsCalculation","MoonbagsConstants","MoonbagsPackage","MoonbagsTransaction","NATIVE_USDC_TOKEN_TYPE","NoodlesSdk","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});
package/dist/index.d.ts CHANGED
@@ -7,7 +7,7 @@ import type { Quote } from '@naviprotocol/astros-aggregator-sdk';
7
7
  import type { QuoteResponse } from '@7kprotocol/sdk-ts';
8
8
  import type { RouterCompleteTradeRoute } from 'aftermath-ts-sdk';
9
9
  import type { RouterDataV3 } from '@cetusprotocol/aggregator-sdk';
10
- import type { SuiClient } from '@mysten/sui/client';
10
+ import { SuiClient } from '@mysten/sui/client';
11
11
  import { Transaction } from '@mysten/sui/transactions';
12
12
  import type { TransactionArgument } from '@mysten/sui/transactions';
13
13
  import { TransactionObjectArgument } from '@mysten/sui/transactions';
@@ -32,6 +32,29 @@ export declare function addGasFee(params: {
32
32
  suiInputAmount?: bigint;
33
33
  }, suiClient: SuiClient): Promise<Transaction>;
34
34
 
35
+ /**
36
+ * Parameters for adding a new boosting tier (admin only).
37
+ */
38
+ export declare type AddTierRequest = {
39
+ /** Address of the admin performing the operation */
40
+ adminAddress: string;
41
+ /** Unique identifier for the new tier */
42
+ tierId: bigint;
43
+ /** Duration of the boosting effect in milliseconds */
44
+ duration: bigint;
45
+ /** Point value for the boosting tier */
46
+ point: bigint;
47
+ /** Original amount for the boosting tier */
48
+ originalAmount: bigint;
49
+ /** Amount required to purchase this tier */
50
+ amount: bigint;
51
+ /** Optional existing transaction to append to (for composability) */
52
+ currentTx?: Transaction;
53
+ };
54
+
55
+ /** Admin capability object ID for privileged operations */
56
+ export declare const ADMIN_CAP_ID = "0xefa0c0ee48ad31da2e9f4ef2eef96834857bde142317edcc0f787076fbf077fd";
57
+
35
58
  /**
36
59
  * Aftermath DEX aggregator client for routing trades across multiple pools
37
60
  */
@@ -62,7 +85,7 @@ export declare class AftermathAggregator {
62
85
  * @param params.coinOutType - Type/address of output token
63
86
  * @returns Promise resolving to complete trade route with pricing and path information
64
87
  */
65
- getTradeRoute({ coinInAmount, coinInType, coinOutType, tradeFee, }: GetTradeRouteRequest_2): Promise<RouterCompleteTradeRoute>;
88
+ getTradeRoute({ coinInAmount, coinInType, coinOutType, tradeFee, }: GetTradeRouteRequest_3): Promise<RouterCompleteTradeRoute>;
66
89
  /**
67
90
  * Builds a transaction for executing a trade route
68
91
  * @param params - Transaction parameters
@@ -90,6 +113,70 @@ export declare type AftermathAggregatorConfig = {
90
113
  aftermathApiEndpoint?: string;
91
114
  };
92
115
 
116
+ /**
117
+ * Main aggregator module that provides unified access to multiple DEX aggregators
118
+ * Supports routing trades through Cetus, FlowX, Astros, Aftermath, and 7K Protocol
119
+ */
120
+ export declare class AggregatorModule implements IModule {
121
+ /** Reference to the main Noodles SDK instance */
122
+ readonly sdk: NoodlesSdk;
123
+ /** Astros/Navi Protocol aggregator instance */
124
+ private _astrosAggregator;
125
+ /** Aftermath Finance aggregator instance */
126
+ private _aftermathAggregator;
127
+ /** 7K Protocol aggregator instance */
128
+ private _sevenkAggregator;
129
+ /** Cetus Protocol aggregator instance */
130
+ private _cetusAggregator;
131
+ /** FlowX Finance aggregator instance */
132
+ private _flowXAggregator;
133
+ /**
134
+ * Creates a new AggregatorModule instance with all supported aggregators
135
+ * @param sdk - The main Noodles SDK instance containing configuration
136
+ * @param suiClient - Sui client for blockchain interactions
137
+ */
138
+ constructor(sdk: NoodlesSdk);
139
+ /** Gets the Astros/Navi Protocol aggregator instance */
140
+ get astrosAggregator(): AstrosAggregator;
141
+ /** Gets the Aftermath Finance aggregator instance */
142
+ get aftermathAggregator(): AftermathAggregator;
143
+ /** Gets the 7K Protocol aggregator instance */
144
+ get sevenkAggregator(): SevenKAggregator;
145
+ /** Gets the Cetus Protocol aggregator instance */
146
+ get cetusAggregator(): CetusAggregator;
147
+ /** Gets the FlowX Finance aggregator instance */
148
+ get flowXAggregator(): FlowXAggregator;
149
+ /**
150
+ * Finds the optimal trade route using the specified aggregator
151
+ * @param aggregator - The aggregator to use for route finding
152
+ * @param params - Trade route parameters including token types and amounts
153
+ * @returns Promise resolving to route response with both standardized and raw data, or null if no route found
154
+ */
155
+ getTradeRoute(aggregator: SupportedAggregator, params: GetTradeRouteRequest): Promise<GetTradeRouteResponse | null>;
156
+ /**
157
+ * Builds a transaction from an existing trade route
158
+ * @param aggregator - The aggregator that generated the route
159
+ * @param params - Transaction parameters including wallet address, route, and slippage
160
+ * @returns Promise resolving to built transaction bytes ready for signing and execution
161
+ */
162
+ getTransactionByRoute(aggregator: SupportedAggregator, params: GetTransactionByRouteRequest): Promise<Uint8Array>;
163
+ /**
164
+ * Combines route finding and transaction building into a single operation
165
+ * This is a convenience method that calls getTradeRoute followed by getTransactionByRoute
166
+ * @param aggregator - The aggregator to use for both route finding and transaction building
167
+ * @param params - Combined parameters including trade details, wallet address, and slippage
168
+ * @returns Promise resolving to complete response with route info and built transaction, or null if no route found
169
+ */
170
+ getTradeTransaction(aggregator: SupportedAggregator, params: GetTradeTransactionRequest): Promise<GetTradeTransactionResponse | null>;
171
+ /**
172
+ * Finds the best rate across all aggregators and returns the optimal trade transaction
173
+ * This method queries all available aggregators and selects the one with the best output amount
174
+ * @param params - Combined parameters including trade details, wallet address, and slippage
175
+ * @returns Promise resolving to complete response with route info and built transaction from the best aggregator, or null if no routes found
176
+ */
177
+ getTradeTransactionWithBestRate(params: GetTradeTransactionRequest): Promise<GetTradeTransactionResponse | null>;
178
+ }
179
+
93
180
  /**
94
181
  * Astros DEX aggregator client for routing trades across multiple pools
95
182
  * Provides access to liquidity aggregation from various DEX protocols
@@ -113,7 +200,7 @@ export declare class AstrosAggregator {
113
200
  * @param params.coinOutType - Type/address of output token
114
201
  * @returns Promise resolving to quote with pricing and route information, or null if no route found
115
202
  */
116
- getTradeRoute({ coinInAmount, coinInType, coinOutType, tradeFee, }: GetTradeRouteRequest_3): Promise<Quote | null>;
203
+ getTradeRoute({ coinInAmount, coinInType, coinOutType, tradeFee, }: GetTradeRouteRequest_4): Promise<Quote | null>;
117
204
  /**
118
205
  * Merges multiple coin objects into a single coin for trading
119
206
  * Optimizes coin usage by merging smaller coins into larger ones
@@ -299,6 +386,103 @@ export declare namespace BluefinTx {
299
386
  export function transferOrDestroyZeroCoin(tx: Transaction, coinType: string, coin: TransactionArgument, address: string): void;
300
387
  }
301
388
 
389
+ /** Sui package ID for the boosting protocol */
390
+ export declare const BOOSTING_PACKAGE_ID = "0x3cebf157c3595b2b5a590a506c60128506237d889917a0f7317a2c7bf6ed0289";
391
+
392
+ /**
393
+ * Complete boosting protocol configuration.
394
+ */
395
+ export declare type BoostingConfig = {
396
+ /** Configuration object ID */
397
+ id: string;
398
+ /** Map of tier ID to tier information */
399
+ tiers: Record<string, TierInfo>;
400
+ /** Address that receives boosting payment fees */
401
+ receiverAddress: string;
402
+ };
403
+
404
+ /**
405
+ * Module for managing boosting functionality in the Noodles SDK.
406
+ *
407
+ * This module provides methods for:
408
+ * - Paying boosting fees for different tiers
409
+ * - Managing boosting tiers (admin functions)
410
+ * - Retrieving boosting configuration
411
+ * - Updating fee receiver settings
412
+ */
413
+ export declare class BoostingModule implements IModule {
414
+ /** Reference to the main SDK instance */
415
+ sdk: NoodlesSdk;
416
+ /**
417
+ * Creates a new BoostingModule instance.
418
+ *
419
+ * @param sdk - The main Noodles SDK instance
420
+ */
421
+ constructor(sdk: NoodlesSdk);
422
+ /**
423
+ * Retrieves the current boosting configuration from the blockchain.
424
+ *
425
+ * @returns Promise resolving to the current boosting configuration
426
+ * @throws Error if config object is not found or invalid
427
+ */
428
+ getConfig(): Promise<BoostingConfig>;
429
+ /**
430
+ * Builds a transaction for paying boosting fees for a specific tier.
431
+ * The payment amount is determined by the tier configuration.
432
+ *
433
+ * @param request - Payment request parameters
434
+ * @returns Promise resolving to a transaction ready for execution
435
+ * @throws Error if tier ID is invalid
436
+ */
437
+ buildPayBoostingTx({ walletAddress, tierId, boostingCoinType, currentTx, }: PayBoostingRequest): Promise<Transaction>;
438
+ /**
439
+ * Builds a transaction for adding a new boosting tier.
440
+ *
441
+ * **Requires admin capability.**
442
+ *
443
+ * @param request - Add tier request parameters
444
+ * @returns Promise resolving to a transaction ready for execution
445
+ */
446
+ buildAddTierTx({ adminAddress, tierId, duration, point, originalAmount, amount, currentTx, }: AddTierRequest): Promise<Transaction>;
447
+ /**
448
+ * Builds a transaction for updating an existing boosting tier.
449
+ *
450
+ * **Requires admin capability.**
451
+ *
452
+ * @param request - Update tier request parameters
453
+ * @returns Promise resolving to a transaction ready for execution
454
+ */
455
+ buildUpdateTierTx({ adminAddress, tierId, duration, amount, originalAmount, point, currentTx, }: UpdateTierRequest): Promise<Transaction>;
456
+ /**
457
+ * Builds a transaction for removing a boosting tier.
458
+ *
459
+ * **Requires admin capability.**
460
+ *
461
+ * @param request - Remove tier request parameters
462
+ * @returns Promise resolving to a transaction ready for execution
463
+ */
464
+ buildRemoveTierTx({ adminAddress, tierId, currentTx }: RemoveTierRequest): Promise<Transaction>;
465
+ /**
466
+ * Builds a transaction for updating the fee receiver address.
467
+ *
468
+ * **Requires admin capability.**
469
+ *
470
+ * @param request - Update fee receiver request parameters
471
+ * @returns Promise resolving to a transaction ready for execution
472
+ */
473
+ buildUpdateFeeReceiver({ adminAddress, newReceiverAddress, currentTx, }: UpdateFeeReceiverRequest): Promise<Transaction>;
474
+ /**
475
+ * Builds a transaction for paying boosting fees with admin privileges.
476
+ * Allows specifying a custom payment amount instead of using the tier's default amount.
477
+ *
478
+ * **Requires admin capability.**
479
+ *
480
+ * @param request - Admin payment request parameters
481
+ * @returns Promise resolving to a transaction ready for execution
482
+ */
483
+ buildPayBoostingWithAdminTx({ walletAddress, tierId, customAmount, boostingCoinType, currentTx, }: PayBoostingWithAdminRequest): Promise<Transaction>;
484
+ }
485
+
302
486
  export declare namespace Bps {
303
487
  export type BPS = {
304
488
  pos0: string;
@@ -356,7 +540,7 @@ export declare class CetusAggregator {
356
540
  * @param params.coinOutType - Type/address of output token
357
541
  * @returns Promise resolving to router data with pricing and route information, or null if no route found
358
542
  */
359
- getTradeRoute({ coinInAmount, coinInType, coinOutType, tradeFee, }: GetTradeRouteRequest_4): Promise<RouterDataV3 | null>;
543
+ getTradeRoute({ coinInAmount, coinInType, coinOutType, tradeFee, }: GetTradeRouteRequest_5): Promise<RouterDataV3 | null>;
360
544
  /**
361
545
  * Builds a transaction for executing a trade route from Cetus aggregator
362
546
  * @param params - Transaction parameters
@@ -430,11 +614,22 @@ export declare interface CommonTxParams {
430
614
  isSponsored?: boolean;
431
615
  }
432
616
 
617
+ /** Configuration object ID for boosting settings */
618
+ export declare const CONFIG_ID = "0x1a502860215ca71a83fd8e0e09e6bb640d0faef35ddd385cea744d06f18dcfdb";
619
+
433
620
  /**
434
621
  * Alternative: Create a proxy that ensures compatibility
435
622
  */
436
623
  export declare function createCompatibleSuiClient(client: SuiClient): LegacySuiClient;
437
624
 
625
+ export declare class CurveModule implements IModule {
626
+ readonly sdk: NoodlesSdk;
627
+ constructor(sdk: NoodlesSdk);
628
+ getTradeTransaction(platform: SupportedBondingCurve, params: GetTradeTransactionRequest): Promise<Uint8Array>;
629
+ }
630
+
631
+ export declare const DEFAULT_TRADE_FEE: TradeFeeOptions;
632
+
438
633
  export declare type DraftTransaction = {
439
634
  readonly sender: string;
440
635
  readonly recipient: string;
@@ -518,7 +713,7 @@ export declare class FlowXAggregator {
518
713
  * @param params.coinOutType - Type/address of output token
519
714
  * @returns Promise resolving to routes result with pricing and path information, or null if no route found
520
715
  */
521
- getTradeRoute({ coinInAmount, coinInType, coinOutType, tradeFee, }: GetTradeRouteRequest_5): Promise<GetRoutesResult<Coin, Coin> | null>;
716
+ getTradeRoute({ coinInAmount, coinInType, coinOutType, tradeFee, }: GetTradeRouteRequest_6): Promise<GetRoutesResult<Coin, Coin> | null>;
522
717
  /**
523
718
  * Builds a transaction for executing a trade route from FlowX aggregator
524
719
  * @param params - Transaction parameters
@@ -590,9 +785,9 @@ export declare type GetSuiAmountAfterSellParams = {
590
785
  };
591
786
 
592
787
  /**
593
- * Request parameters for getting a trade route
788
+ * Request parameters for getting a trade route from an aggregator
594
789
  */
595
- declare type GetTradeRouteRequest = {
790
+ export declare type GetTradeRouteRequest = {
596
791
  /** Amount of input coin to trade (in smallest unit) */
597
792
  coinInAmount: bigint;
598
793
  /** Type/address of the input coin */
@@ -659,6 +854,30 @@ declare type GetTradeRouteRequest_5 = {
659
854
  tradeFee?: TradeFeeOptions;
660
855
  };
661
856
 
857
+ /**
858
+ * Request parameters for getting a trade route
859
+ */
860
+ declare type GetTradeRouteRequest_6 = {
861
+ /** Amount of input coin to trade (in smallest unit) */
862
+ coinInAmount: bigint;
863
+ /** Type/address of the input coin */
864
+ coinInType: string;
865
+ /** Type/address of the output coin */
866
+ coinOutType: string;
867
+ /** Custom trade fee for this request, if not provided, the default trade fee will be applied */
868
+ tradeFee?: TradeFeeOptions;
869
+ };
870
+
871
+ /**
872
+ * Response from getting a trade route, containing both standardized and raw route data
873
+ */
874
+ export declare type GetTradeRouteResponse = {
875
+ /** The standardized trade route information across all aggregators */
876
+ route: FinalTradeRoute;
877
+ /** The raw route response from the specific aggregator (format varies by aggregator) */
878
+ aggregatorRoute: any;
879
+ };
880
+
662
881
  export declare type GetTradeTransactionRequest = {
663
882
  /** Amount of input coin to trade (in smallest unit) */
664
883
  coinInAmount: bigint;
@@ -676,6 +895,32 @@ export declare type GetTradeTransactionRequest = {
676
895
  poolId: string;
677
896
  };
678
897
 
898
+ /**
899
+ * Response from getting both route and transaction, containing route info and built transaction
900
+ */
901
+ export declare type GetTradeTransactionResponse = {
902
+ /** The standardized trade route information */
903
+ route: FinalTradeRoute;
904
+ /** The raw route response from the aggregator */
905
+ aggregatorRoute: any;
906
+ /** The built transaction bytes ready for signing and execution */
907
+ transaction: Uint8Array;
908
+ };
909
+
910
+ /**
911
+ * Request parameters for building a transaction from an existing route
912
+ */
913
+ export declare type GetTransactionByRouteRequest = {
914
+ /** Wallet address that will execute the transaction */
915
+ walletAddress: string;
916
+ /** Complete trade route from aggregator router (raw aggregator response) */
917
+ completeRoute: any;
918
+ /** Slippage tolerance as decimal (e.g., 0.01 for 1%) */
919
+ slippage: number;
920
+ /** Custom trade fee for this request, if not provided, the default trade fee will be applied */
921
+ tradeFee?: TradeFeeOptions;
922
+ };
923
+
679
924
  /**
680
925
  * Request parameters for getting a transaction
681
926
  */
@@ -744,6 +989,10 @@ declare type GetTransactionRequest_5 = {
744
989
  tradeFee?: TradeFeeOptions;
745
990
  };
746
991
 
992
+ export declare interface IModule {
993
+ readonly sdk: NoodlesSdk;
994
+ }
995
+
747
996
  declare type LegacySuiClient = SuiClient;
748
997
 
749
998
  export declare namespace MathUtils {
@@ -844,6 +1093,78 @@ export declare type MoveObjectStruct<Content> = {
844
1093
 
845
1094
  export declare const NATIVE_USDC_TOKEN_TYPE = "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC";
846
1095
 
1096
+ export declare class NoodlesSdk {
1097
+ readonly options: SdkOptions;
1098
+ private _suiClient;
1099
+ readonly aggregatorModule: AggregatorModule;
1100
+ readonly curveModule: CurveModule;
1101
+ readonly boostingModule: BoostingModule;
1102
+ constructor(options: SdkOptions);
1103
+ get suiClient(): SuiClient;
1104
+ }
1105
+
1106
+ /**
1107
+ * Parameters for paying boosting fees for a specific tier.
1108
+ */
1109
+ export declare type PayBoostingRequest = {
1110
+ /** Address of the wallet making the payment */
1111
+ walletAddress: string;
1112
+ /** ID of the boosting tier to pay for */
1113
+ tierId: string;
1114
+ /** Type of coin used for boosting payment */
1115
+ boostingCoinType: string;
1116
+ /** Optional existing transaction to append to (for composability) */
1117
+ currentTx?: Transaction;
1118
+ };
1119
+
1120
+ /**
1121
+ * Parameters for paying boosting fees with admin privileges using custom amount.
1122
+ */
1123
+ export declare type PayBoostingWithAdminRequest = {
1124
+ /** Address of the wallet making the payment */
1125
+ walletAddress: string;
1126
+ /** ID of the boosting tier */
1127
+ tierId: string;
1128
+ /** Custom payment amount (overrides tier amount) */
1129
+ customAmount: bigint;
1130
+ /** Type of coin used for boosting payment */
1131
+ boostingCoinType: string;
1132
+ /** Optional existing transaction to append to (for composability) */
1133
+ currentTx?: Transaction;
1134
+ };
1135
+
1136
+ /**
1137
+ * Parameters for removing a boosting tier (admin only).
1138
+ */
1139
+ export declare type RemoveTierRequest = {
1140
+ /** Address of the admin performing the operation */
1141
+ adminAddress: string;
1142
+ /** ID of the tier to remove */
1143
+ tierId: bigint;
1144
+ /** Optional existing transaction to append to (for composability) */
1145
+ currentTx?: Transaction;
1146
+ };
1147
+
1148
+ export declare type SdkOptions = {
1149
+ tradeFee: TradeFeeOptions;
1150
+ /** Optional API key for Astros aggregator access */
1151
+ astrosApiKey?: string;
1152
+ /** Optional API key for authenticated Aftermath API access */
1153
+ aftermathApiKey?: string;
1154
+ /** Optional custom Aftermath API endpoint (defaults to MAINNET if not provided) */
1155
+ aftermathApiEndpoint?: string;
1156
+ /** Optional API key for 7K Protocol access */
1157
+ sevenKApiKey?: string;
1158
+ /** Optional API key for Cetus aggregator access */
1159
+ cetusApiKey?: string;
1160
+ /** Optional custom Cetus API endpoint */
1161
+ cetusApiEndpoint?: string;
1162
+ /** Optional partner ID for Cetus integration */
1163
+ cetusPartnerId?: string;
1164
+ /** Optional API key for FlowX aggregator access */
1165
+ flowxApiKey?: string;
1166
+ };
1167
+
847
1168
  /**
848
1169
  * 7K Protocol DEX aggregator client for routing trades across multiple pools
849
1170
  * 7K Protocol aggregates liquidity from various DEXs to find optimal trade routes
@@ -867,7 +1188,7 @@ export declare class SevenKAggregator {
867
1188
  * @param params.coinOutType - Type/address of output token
868
1189
  * @returns Promise resolving to quote response with pricing and route information, or null if no route found
869
1190
  */
870
- getTradeRoute({ coinInAmount, coinInType, coinOutType, tradeFee, }: GetTradeRouteRequest): Promise<QuoteResponse | null>;
1191
+ getTradeRoute({ coinInAmount, coinInType, coinOutType, tradeFee, }: GetTradeRouteRequest_2): Promise<QuoteResponse | null>;
871
1192
  /**
872
1193
  * Builds a transaction for executing a trade route from 7K Protocol
873
1194
  * @param params - Transaction parameters
@@ -916,6 +1237,20 @@ export declare enum SupportedBondingCurve {
916
1237
  MOONBAGS = "MOONBAGS"
917
1238
  }
918
1239
 
1240
+ /**
1241
+ * Information about a specific boosting tier.
1242
+ */
1243
+ export declare type TierInfo = {
1244
+ /** Duration of the boosting effect in milliseconds */
1245
+ duration: bigint;
1246
+ /** Amount required to purchase this tier */
1247
+ amount: bigint;
1248
+ /** Point value associated with this tier */
1249
+ point: bigint;
1250
+ /** Original amount for the boosting tier */
1251
+ originalAmount: bigint;
1252
+ };
1253
+
919
1254
  /**
920
1255
  * Configuration options for trade fees applied to aggregator transactions
921
1256
  */
@@ -948,6 +1283,38 @@ export declare type TradeRoute = {
948
1283
 
949
1284
  export declare type TransactionStatus = "success" | "failure" | "pending";
950
1285
 
1286
+ /**
1287
+ * Parameters for updating the fee receiver address (admin only).
1288
+ */
1289
+ export declare type UpdateFeeReceiverRequest = {
1290
+ /** Address of the admin performing the operation */
1291
+ adminAddress: string;
1292
+ /** New address to receive boosting fees */
1293
+ newReceiverAddress: string;
1294
+ /** Optional existing transaction to append to (for composability) */
1295
+ currentTx?: Transaction;
1296
+ };
1297
+
1298
+ /**
1299
+ * Parameters for updating an existing boosting tier (admin only).
1300
+ */
1301
+ export declare type UpdateTierRequest = {
1302
+ /** Address of the admin performing the operation */
1303
+ adminAddress: string;
1304
+ /** ID of the tier to update */
1305
+ tierId: bigint;
1306
+ /** New duration of the boosting effect in milliseconds */
1307
+ duration: bigint;
1308
+ /** New point value for the boosting tier */
1309
+ point: bigint;
1310
+ /** New original amount for the boosting tier */
1311
+ originalAmount: bigint;
1312
+ /** New amount required to purchase this tier */
1313
+ amount: bigint;
1314
+ /** Optional existing transaction to append to (for composability) */
1315
+ currentTx?: Transaction;
1316
+ };
1317
+
951
1318
  export declare const USDC_TOKEN_TYPE = "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN";
952
1319
 
953
1320
  export { }
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{BluefinXTx as e,Config as t,buildTx as n,getQuote as i}from"@7kprotocol/sdk-ts/cjs";import{Transaction as o}from"@mysten/sui/transactions";import r from"bignumber.js";import{Aftermath as a,Helpers as u}from"aftermath-ts-sdk";import{buildSwapPTBFromQuote as s,getCoins as c,getQuote as l}from"@naviprotocol/astros-aggregator-sdk";import{AggregatorClient as d,Env as f}from"@cetusprotocol/aggregator-sdk";import m from"bn.js";import{AggregatorQuoter as g,Coin as p,Commission as I,CommissionType as _,TradeBuilder as C}from"@flowx-finance/sdk";import A from"@minswap/tiny-invariant";import{fromBase64 as h,normalizeStructTag as y}from"@mysten/sui/utils";import{MemezPumpSDK as b}from"@interest-protocol/memez-fun-sdk";import{Network as T}from"@interest-protocol/sui-core-sdk";import{getFullnodeUrl as B}from"@mysten/sui/client";import{Ed25519Keypair as O}from"@mysten/sui/keypairs/ed25519";class F{_config;_suiClient;constructor(e,t){this._config=e,this._suiClient=t}async getTradeRoute({coinInAmount:e,coinInType:n,coinOutType:o,tradeFee:r}){try{this._config.sevenKApiKey&&t.setApiKey(this._config.sevenKApiKey);let a=r?r.tradeFeePercent:this._config.defaultTradeFee.tradeFeePercent;return i({tokenIn:n,tokenOut:o,amountIn:e.toString(),commissionBps:1e4*a})}catch(e){return null}}async getTransaction({walletAddress:t,completeRoute:i,slippage:r,tradeFee:a}){let u,s;a?(u=a.tradeFeePercent,s=a.tradeFeeRecipientAddress):(u=this._config.defaultTradeFee.tradeFeePercent,s=this._config.defaultTradeFee.tradeFeeRecipientAddress);let c=await n({quoteResponse:i,slippage:r,accountAddress:t,commission:{partner:s,commissionBps:1e4*u}});return c.tx instanceof e?o.from(c.tx.txBytes).build({client:this._suiClient}):(c.tx.setSender(t),c.tx.build({client:this._suiClient}))}}(F||(F={})).toCommonTradeRoutes=function(e){let t=[];if(!e.routes||0===e.routes.length)return null;for(let n of e.routes){let e=[],i={};for(let t of n.hops){for(let e of t.pool.allTokens)i[e.address]=e.decimal;let n=i[t.tokenIn]??0,o=i[t.tokenOut]??0,a=BigInt(new r(t.tokenInAmount).multipliedBy(10**n).toFixed(0,3)),u=BigInt(new r(t.tokenOutAmount).multipliedBy(10**o).toFixed(0,3));e.push({poolAddress:t.poolId,coinIn:t.tokenIn,coinOut:t.tokenOut,amountIn:a,amountOut:u})}if(0===e.length)continue;let o=i[n.tokenIn]??0,a=i[n.tokenOut]??0,u=BigInt(new r(n.tokenInAmount).multipliedBy(10**o).toFixed(0,3)),s=BigInt(new r(n.tokenOutAmount).multipliedBy(10**a).toFixed(0,3));t.push({paths:e,coinIn:n.tokenIn,coinOut:n.tokenOut,amountIn:u,amountOut:s})}return 0===t.length?null:{coinIn:e.tokenIn,coinOut:e.tokenOut,amountIn:BigInt(e.swapAmountWithDecimal),amountOut:BigInt(e.returnAmountWithDecimal),routes:t}};class v{_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 a(this._config.aftermathApiEndpoint):this._aftermathClient=new a("MAINNET"),await this._aftermathClient.init(),this._config.aftermathApiKey){let e=u.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:i}){let o;return o=i?{recipient:i.tradeFeeRecipientAddress,feePercentage:i.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 i=await this.aftermathClient(),o=await i.Router().getTransactionForCompleteTradeRoute({completeRoute:e,walletAddress:t,slippage:n,isSponsoredTx:!1});return o.setSender(t),o.build({client:this._suiClient})}}(v||(v={})).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}};class w{_config;_suiClient;constructor(e,t){this._config=e,this._suiClient=t}async getTradeRoute({coinInAmount:e,coinInType:t,coinOutType:n,tradeFee:i}){try{let o;return o=i?{fee:i.tradeFeePercent,receiverAddress:i.tradeFeeRecipientAddress}:{fee:this._config.defaultTradeFee.tradeFeePercent,receiverAddress:this._config.defaultTradeFee.tradeFeeRecipientAddress},l(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 i=0,o=[];t.sort((e,t)=>Number(t.balance)-Number(e.balance)).slice(1).forEach(e=>{i>=n||(i+=Number(e.balance),o.push(e.coinObjectId))});let r=t[0].coinObjectId;return e.mergeCoins(r,o),e.object(r)}async getTransaction({completeRoute:e,walletAddress:t,slippage:n,tradeFee:i}){var a;let u,l;u=i?{fee:i.tradeFeePercent,receiverAddress:i.tradeFeeRecipientAddress}:{fee:this._config.defaultTradeFee.tradeFeePercent,receiverAddress:this._config.defaultTradeFee.tradeFeeRecipientAddress};let d=new r(e.amount_out).multipliedBy(1-n-u.fee).toNumber(),f=new o;if("0x2::sui::SUI"===(a=e.from)||"0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI"===a)l=f.splitCoins(f.gas,[f.pure.u64(e.amount_in)]);else{let n=await c(this._suiClient,t,e.from),i=this.returnMergedCoins(f,n.data,Number.parseFloat(e.amount_in));l=f.splitCoins(i,[f.pure.u64(e.amount_in)])}let m=await s(t,f,d,l,e,void 0,!1,this._config.astrosApiKey,{serviceFee:u});return f.transferObjects([m],t),f.setSender(t),f.build({client:this._suiClient})}}(w||(w={})).toCommonTradeRoutes=function(e,t,n){if(0===e.routes.length)return null;let i=[];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&&i.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===i.length?null:{coinIn:t,coinOut:n,amountIn:BigInt(e.amount_in),amountOut:BigInt(e.amount_out),routes:i}},(L||(L={})).equals=function(e,t){return e.tradeFeePercent===t.tradeFeePercent&&e.tradeFeeRecipientAddress===t.tradeFeeRecipientAddress};class S{_config;_suiClient;_cetusClient;constructor(e,t){this._config=e,this._suiClient=t}cetusClient(e,t){return t&&!L.equals(t,this._config.defaultTradeFee)?new d({client:this._suiClient,overlayFeeReceiver:t.tradeFeeRecipientAddress,overlayFeeRate:t.tradeFeePercent,env:f.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 d({client:this._suiClient,overlayFeeReceiver:this._config.defaultTradeFee.tradeFeeRecipientAddress,overlayFeeRate:this._config.defaultTradeFee.tradeFeePercent,env:f.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:i}){return this.cetusClient(void 0,i).findRouters({from:t,target:n,amount:new m(e.toString()),byAmountIn:!0})}async getTransaction({completeRoute:e,walletAddress:t,slippage:n,tradeFee:i}){let r=new o,a=this.cetusClient(t,i);return await a.fastRouterSwap({router:e,txb:r,slippage:n}),await a.devInspectTransactionBlock(r),r.setSender(t),r.build({client:this._suiClient})}}(S||(S={})).toCommonTradeRoutes=function(e,t,n){if(0===e.paths.length)return null;let i=[],o=[],r=[];for(let t=0;t<e.paths.length;t++){let n=e.paths[t],i={poolAddress:n.id,amountIn:BigInt(n.amountIn),amountOut:BigInt(n.amountOut),coinIn:n.from,coinOut:n.target};if(r.push(i),t===e.paths.length-1)o.push([...r]);else{let i=e.paths[t+1];n.target!==i.from&&(o.push([...r]),r=[])}}for(let e of o)0!==e.length&&i.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===i.length?null:{coinIn:t,coinOut:n,amountIn:BigInt(e.amountIn.toString(10)),amountOut:BigInt(e.amountOut.toString(10)),routes:i}};var x,E,R,P,k,D,M,N,U,j,K,q,G,z,L,J,$,V,W,Z,X,Y,H,Q,ee,et,en,ei,eo=((z={}).ASTROS="ASTROS",z.AFTERMATH="AFTERMATH",z.SEVENK="7K",z.CETUS="CETUS",z.FLOWX="FLOWX",z);class er{_config;_suiClient;constructor(e,t){this._config=e,this._suiClient=t}getCommission(e,t){let n,i;return t?(n=t.tradeFeePercent,i=t.tradeFeeRecipientAddress):(n=this._config.defaultTradeFee.tradeFeePercent,i=this._config.defaultTradeFee.tradeFeeRecipientAddress),new I(i,new p(e),_.PERCENTAGE,1e6*n,!0)}async getTradeRoute({coinInAmount:e,coinInType:t,coinOutType:n,tradeFee:i}){let o=new g("mainnet",this._config.flowxApiKey);try{return o.getRoutes({tokenIn:t,tokenOut:n,amountIn:e.toString(),commission:this.getCommission(t,i)})}catch(e){return null}}async getTransaction({walletAddress:e,completeRoute:t,slippage:n,tradeFee:i}){return new C("mainnet",t.routes).sender(e).slippage(1e6*n).commission(this.getCommission(t.coinIn.coinType,i)).build().buildTransaction({client:this._suiClient}).then(t=>(t.setSender(e),t.build({client:this._suiClient})))}}async function ea(e,t){return(await eu(e,t)).fields}async function eu(e,t){let n=await e.getObject({id:t,options:{showContent:!0}}),i=n.data?.content;return A(i,"Pool object not found or has no content"),A("moveObject"===i.dataType,"Object is not a Move object"),i}(er||(er={})).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}},(x=J||(J={})).PACKAGE_ID_V4="0x7e6aa6e179466ab2814425a780b122575296d011119fa69d27f289f5a28814bd",x.MEMEZ_AV_OBJECT_ID="0x2319e3e76dfad73d8f4684bdbf42be4f32d8ce4521dd61becc8261dc918d82c0";let es=1e4;function ec(e,t){let n=BigInt(e),i=BigInt(Number(t)*es);if(i===BigInt(0))return[n.toString()];let o=n*i/BigInt(es);return[(n-o).toString(),o.toString()]}function el(e,t){if(!t||0>=Number(t))return BigInt(e);let n=BigInt(e),i=BigInt(Number(t)*es);if(i===BigInt(0))return n;let o=n*i/BigInt(es);return n-o}async function ed(e,t,n,i){let{effects:{gasUsed:o,status:r}}=await e.devInspectTransactionBlock({sender:n,transactionBlock:t});if("success"!==r.status)throw Error(`Transaction failed during dev inspect: ${r.error??""}`);let a=BigInt(o.computationCost)+BigInt(o.storageCost)-BigInt(o.storageRebate),u=BigInt(Number(i)*es);return a*(BigInt(es)+u)/BigInt(es)}((E=$||($={})).U64||(E.U64={})).mulDivUp=function(e,t,n){let i=BigInt(0);return e*t%n>BigInt(0)&&(i=BigInt(1)),e*t/n+i};var ef=V||(V={});function em(e){return A(BigInt(e)<=BigInt(1e4),"Bps overflow"),BigInt(e)}ef.calcUp=function(e,t){let n,i=BigInt(e.pos0),o=BigInt(1e4);return n=i*t%o!==BigInt(0)?BigInt(1):BigInt(0),i*t/o+n},ef.sub=function(e,t){return A(BigInt(e.pos0)>=BigInt(t.pos0),"Bps underflow"),{pos0:(BigInt(e.pos0)-BigInt(t.pos0)).toString()}},ef.value=function(e){return BigInt(e.pos0)},ef.new_=function(e){return{pos0:em(e).toString()}},ef.assertOverflow=em,((R=W||(W={})).MemezFun||(R.MemezFun={})).isSniperProtectedMemezFun=async function(e,t){return(await ea(e,t)).public_key.length>0},(P=R.MemezFees||(R.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 i=e.fields.pos0.fields;if(BigInt(i.pos0)===BigInt(0))return BigInt(0);let o=V.calcUp(V.sub(i,n),t);if(t>=o)return o;throw Error(`Insufficient amount to cover fee. Required: ${o}, provided: ${t}`)}throw Error("Unknown fee variant")},P.calculateWithDiscount=function(e,t,n){if("Value"===e.variant)return BigInt(e.fields.pos0);if("Percentage"===e.variant){let i=e.fields.pos0.fields;return V.calcUp(V.sub(i,t),n)}throw Error("Unknown fee variant")},(R.MemezBurner||(R.MemezBurner={})).calculate=function(e,t){if(V.value(e.fee.fields)===BigInt(0)||t===BigInt(0)||t>=BigInt(e.target_liquidity))return V.new_(0);let n=BigInt(1e4);return V.new_($.U64.mulDivUp(V.value(e.fee.fields),$.U64.mulDivUp(t,n,BigInt(e.target_liquidity)),n))},(k=R.MemezPump||(R.MemezPump={})).getPumpState=async function(e,t){return await ea(e,t.inner_state)},k.pump=function(e,t){let n=e.constant_product.fields,i=R.MemezFees.takeWithDiscount(n.quote_swap_fee,t,n.quote_referrer_fee.fields),o=t-i,r=BigInt(n.meme_balance),a=BigInt(n.quote_balance),u=r*o/(BigInt(n.virtual_liquidity)+a+o),s=R.MemezFees.takeWithDiscount(n.meme_swap_fee,u,n.meme_referrer_fee.fields);return u-s},k.dump=function(e,t){let n=e.constant_product.fields,i=R.MemezFees.takeWithDiscount(n.meme_swap_fee,t,n.meme_referrer_fee.fields),o=t-i,r=BigInt(n.meme_balance),a=BigInt(n.quote_balance),u=BigInt(n.virtual_liquidity),s=R.MemezBurner.calculate(n.burner.fields,a),c=V.calcUp(s,o),l=o-(V.value(s)!==BigInt(0)?c:BigInt(0)),d=(u+a)*l/(r+l);d>a&&(d=a);let f=R.MemezFees.takeWithDiscount(n.quote_swap_fee,d,n.quote_referrer_fee.fields);return d-f},(D=Z||(Z={})).getCurveAmountAfterBuy=async function(e,t){let{suiAmount:n,poolId:i,frontendFee:o}=e,r=await ea(t,i),a=await W.MemezPump.getPumpState(t,r);return n=el(n,o),W.MemezPump.pump(a,n)},D.getSuiAmountAfterSell=async function(e,t){let{curveAmount:n,poolId:i,frontendFee:o}=e,r=await ea(t,i),a=await W.MemezPump.getPumpState(t,r);return el(W.MemezPump.dump(a,n),o)};let eg="0x2::sui::SUI",ep="0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",eI="0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN",e_="0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",eC="0x9258181f5ceac8dbffb7030890243caed69a9599d2886d957a9cb7656af3bdb3",eA="0x0000000000000000000000000000000000000000000000000000000000000006",eh=async(e,t,n,i)=>{let o,r=[],a=!0;for(;a;)try{let n=await e.getCoins({owner:t,coinType:i,cursor:o});r=[...r,...n.data],a=n.hasNextPage,o=n.nextCursor}catch(e){console.error("Error fetching data:",e),a=!1}let u=((e,t,n)=>{let i;if(e?.length){do{i=!1;for(let o=0;o<e.length-1;o++){let r=BigInt(e[o][t]),a=BigInt(e[o+1][t]);if("desc"===n?r<a:r>a){let t=e[o];e[o]=e[o+1],e[o+1]=t,i=!0}}}while(i);return e}})(r.map(e=>({...e,balance:e.balance})),"balance","desc")??[],s="0",c=[],l=[];for(let e of u)if(s=(BigInt(e.balance)+BigInt(s)).toString(10),c.push(e.coinObjectId),l.push(e),BigInt(s)>=BigInt(n))break;return{objectIds:c,balance:s,objectCoins:l}};async function ey(e,t){let{account:n,amount:i,splits:r,coinType:a,inheritTx:u,inspecTransaction:s,isSponsored:c=!1}=e,l=u??new o,{objectIds:d}=await eh(t,n,i,a),f=d[0];if(y(a)===y(ep)&&!c){let e;return s?(d.length>1&&l.mergeCoins(l.object(f),d.slice(1).map(e=>l.object(e))),e=l.splitCoins(l.object(f),r)):e=l.splitCoins(l.gas,r),{tx:l,coinData:e}}d.length>1&&l.mergeCoins(l.object(f),d.slice(1).map(e=>l.object(e)));let m=l.splitCoins(l.object(f),r);return{tx:l,coinData:m}}let eb="0x62412b7268c35f3808336aee57a52836501f40b8ba5d936f8ad275e672befd04";async function eT(e,t){let n,i,{inputAmount:r,accountAddress:a,frontendFee:u,frontendFeeRecipient:s,extendTx:c,isSponsored:l}=e;A(e.inCoinType===ep||e.inCoinType===eg,"Input must be SUI");let{tx:d,coinIn:f}=c||{},m=ec(r,u||"0"),g=d||new o;if(f)n=g.splitCoins(f,m),X.transferOrDestroyZeroCoin(g,ep,f,a);else{let{coinData:e}=await ey({account:a,amount:r,splits:m,coinType:ep,inheritTx:g,isSponsored:l||!1},t);n=e}if(u&&s){let[e,t]=n;i=e,g.transferObjects([t],g.pure.address(s||a))}else[i]=n;return{tx:g,coinOut:i}}async function eB(e,t,n){if(A(t.outCoinType===ep||t.outCoinType===eg,"Output must be SUI"),0>=Number(t.frontendFee||0))return{tx:e,coinOut:n};let i=e.moveCall({target:"0x2::coin::value",typeArguments:[t.outCoinType],arguments:[n]}),o=e.moveCall({target:`${eb}::math::mul_div_u64`,typeArguments:[],arguments:[i,e.pure.u64(BigInt(Number(t.frontendFee||"0")*es)),e.pure.u64(BigInt(es))]}),r=e.moveCall({target:"0x2::coin::split",typeArguments:[t.outCoinType],arguments:[n,o]});return e.transferObjects([r],e.pure.address(t.frontendFeeRecipient||t.accountAddress)),{tx:e,coinOut:n}}(X||(X={})).transferOrDestroyZeroCoin=function(e,t,n,i){e.moveCall({target:`${eb}::utils::transfer_or_destroy`,typeArguments:[t],arguments:[n,e.pure.address(i)]})};var eO=Y||(Y={});async function eF(e){let t=e||new o;return t.moveCall({target:`${J.PACKAGE_ID_V4}::memez_allowed_versions::get_allowed_versions`,arguments:[t.object(J.MEMEZ_AV_OBJECT_ID)],typeArguments:[]})}eO.getAllowedVersions=eF,eO.buildBuyTx=async function(e,t){A(!await W.MemezFun.isSniperProtectedMemezFun(t,e.poolId),"This coin is a sniper protected coin, please use the Blast Fun website to trade it.");let{tx:n,coinOut:i}=await eT(e,t);A(i,"Coin out is required");let o=n.moveCall({target:`${J.PACKAGE_ID_V4}::memez_pump::pump`,typeArguments:[e.outCoinType,ep],arguments:[n.object(e.poolId),i,n.pure.vector("address",[]),n.pure.vector("vector<u8>",[]),n.pure.u64(e.minAmountOut),await eF(n)]});return{tx:n,coinOut:o}},eO.buildSellTx=async function(e,t){A(e.outCoinType===ep||e.outCoinType===eg,"Output must be SUI");let n=await ea(t,e.poolId),{tx:i,coinData:o}=await ey({amount:e.inputAmount,coinType:e.inCoinType,inheritTx:e.extendTx?.tx,account:e.accountAddress,splits:[e.inputAmount]},t),[r]=o,[a]=i.moveCall({target:`${J.PACKAGE_ID_V4}::memez_pump::dump`,typeArguments:[e.inCoinType,e.outCoinType],arguments:[i.object(e.poolId),i.object(n.ipx_meme_coin_treasury),r,i.pure.vector("address",[]),i.pure.u64(e.minAmountOut),await eF(i)]});return await eB(i,e,a)};let ev=new b({network:T.MAINNET,fullNodeUrl:B("mainnet")});function ew(){return ev}async function eS(e,t){let{inheritTx:n,sender:i,feeAmount:r,suiInputAmount:a}=e,u=n||new o;u.setGasBudget(r);let{objectCoins:s}=await eh(t,i,(BigInt(a||"0")+r).toString(),ep);return u.setGasPayment(s.map(e=>({objectId:e.coinObjectId,version:e.version,digest:e.digest}))),u}(M=H||(H={})).getCurveAmountAfterBuy=async function(e){let{suiAmount:t,poolId:n,frontendFee:i}=e;t=el(t,i);let{memeAmountOut:o}=await ew().quotePump({pool:n,amount:t});return o},M.getSuiAmountAfterSell=async function(e){let{curveAmount:t,poolId:n,frontendFee:i}=e,{quoteAmountOut:o}=await ew().quoteDump({pool:n,amount:t});return el(o,i)};var ex=Q||(Q={});async function eE(e,t){let{tx:n,coinOut:i}=await eT(e,t);A(i,"Coin out is required");let{memeCoin:o,tx:r}=await ew().pump({pool:e.poolId,quoteCoin:i,minAmountOut:e.minAmountOut,tx:n});return{tx:r,coinOut:o}}async function eR(e,t){A(e.outCoinType===ep||e.outCoinType===eg,"Output must be SUI");let{tx:n,coinData:i}=await ey({amount:e.inputAmount,coinType:e.inCoinType,inheritTx:e.extendTx?.tx,account:e.accountAddress,splits:[e.inputAmount]},t),[o]=i,{quoteCoin:r,tx:a}=await ew().dump({pool:e.poolId,memeCoin:o,tx:n,minAmountOut:e.minAmountOut});return await eB(a,e,r)}ex.buildBuyTx=eE,ex.buildSellTx=eR,ex.getBuyTransaction=async function({coinInAmount:e,coinInType:t,coinOutType:n,poolId:i,slippage:o,walletAddress:a,tradeFee:u},s){A(t===eg,"coinInType must be SUI for buy transaction"),A(n!==t,"coinOutType must be different from coinInType"),A(o>=0&&o<1,"slippage must be between 0 (inclusive) and 1 (exclusive)"),A(e>0,"coinInAmount must be greater than 0");let c=BigInt(new r((await H.getCurveAmountAfterBuy({poolId:i,suiAmount:e,frontendFee:u?u.tradeFeePercent:void 0})).toString()).multipliedBy(1-o).toFixed(0,3)),{tx:l,coinOut:d}=await eE({accountAddress:a,inCoinType:t,outCoinType:n,inputAmount:e.toString(),minAmountOut:c.toString(),poolId:i,frontendFee:u?u.tradeFeePercent:void 0,frontendFeeRecipient:u?u.tradeFeeRecipientAddress:void 0,extendTx:void 0,isSponsored:!1},s);A(d,"Coin out is required"),l.transferObjects([d],l.pure.address(a)),l.setSender(a);let f=await ed(s,l,a,0);return(l=await eS({inheritTx:l,sender:a,feeAmount:f,suiInputAmount:e},s)).build({client:s})},ex.getSellTransaction=async function({coinInAmount:e,coinInType:t,coinOutType:n,poolId:i,slippage:o,walletAddress:a,tradeFee:u},s){A(n===eg,"coinOutType must be SUI for sell transaction"),A(n!==t,"coinOutType must be different from coinInType"),A(o>=0&&o<1,"slippage must be between 0 (inclusive) and 1 (exclusive)"),A(e>0,"coinInAmount must be greater than 0");let c=BigInt(new r((await H.getSuiAmountAfterSell({poolId:i,curveAmount:e,frontendFee:u?u.tradeFeePercent:void 0})).toString()).multipliedBy(1-o).toFixed(0,3)),{tx:l,coinOut:d}=await eR({accountAddress:a,inCoinType:t,outCoinType:n,inputAmount:e.toString(),minAmountOut:c.toString(),poolId:i,frontendFee:u?u.tradeFeePercent:void 0,frontendFeeRecipient:u?u.tradeFeeRecipientAddress:void 0,extendTx:void 0,isSponsored:!1},s);A(d,"Coin out is required"),l.transferObjects([d],l.pure.address(a)),l.setSender(a);let f=await ed(s,l,a,0);return(l=await eS({inheritTx:l,sender:a,feeAmount:f},s)).build({client:s})};var eP=((N={}).BLAST_FUN="BLAST_FUN",N.MOONBAGS="MOONBAGS",N);(U=ee||(ee={})).PACKAGE_ID="0xb8df325010942634a4afb3db3901ee215546af43a4ec4af781e7213b0bba7290",U.CONFIG_OBJECT_ID="0x74aecf86067c6913960ba4925333aefd2b1f929cafca7e21fd55a8f244b70499",U.LOCK_CONFIG_OBJECT_ID="0xfb09822d9808980abd04c51321adb850701f5f55535c6206658ef4d910c3e9be",U.BURN_MANAGER_OBJECT_ID="0x1d94aa32518d0cb00f9de6ed60d450c9a2090761f326752ffad06b2e9404f845",U.POOLS_OBJECT_ID="0xf699e7f2276f5c9a75944b37a0c5b5d9ddfd2471bf6242483b03ab2887d198d0",U.GLOBAL_CONFIG_OBJECT_ID="0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f",U.FEE_DENOMINATOR=BigInt(1e4),(K=(j=et||(et={})).Curves||(j.Curves={})).calculateAddLiquidityCost=function(e,t,n){return e*t/(t-n)-e},K.calculateRemoveLiquidityReturn=function(e,t,n){return t-e*t/(e+n)},K.calculateTokenAmountReceived=function(e,t,n){return t-e*t/(e+n)},(q=j.Moonbags||(j.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)},q.buyExactInReturnsWithLock=function(e){let{inputAmount:t,amountIn:n,pool:i,config:o,dynamicVirtualTokenReserves:r}=e,a=BigInt(i.virtual_sui_reserves),u=BigInt(i.virtual_token_reserves),s=BigInt(i.remain_token_reserves.fields.balance),c=j.Curves.calculateRemoveLiquidityReturn(a,u,n),l=u-(r||s),d=c,f=n;c>l&&(d=l,f=j.Curves.calculateAddLiquidityCost(a,u,l)+BigInt(1));let m=f*BigInt(o.platform_fee)/ee.FEE_DENOMINATOR;return A(t>=f+m,"Input amount is less than used SUI + fee"),{receivedCurve:d,receivedSui:t-f-m}},q.sellReturns=function(e){let{amountIn:t,pool:n,config:i}=e,o=BigInt(n.virtual_sui_reserves),r=BigInt(n.virtual_token_reserves),a=BigInt(n.real_sui_reserves.fields.balance),u=j.Curves.calculateRemoveLiquidityReturn(r,o,t);u>a&&(u=a);let s=u*BigInt(i.platform_fee)/ee.FEE_DENOMINATOR,c=u-s;return{receivedCurve:BigInt(0),receivedSui:c}},(G=en||(en={})).getCurveAmountAfterBuy=async function(e,t){let{suiAmount:n,poolId:i,frontendFee:o}=e,[r,a,u]=await Promise.all([ea(t,i),ea(t,ee.CONFIG_OBJECT_ID),et.Moonbags.getDynamicVirtualTokenReserves(t,i)]);void 0!==o&&(n=el(n,o));let s=n*ee.FEE_DENOMINATOR/(ee.FEE_DENOMINATOR+BigInt(a.platform_fee)),{receivedCurve:c}=et.Moonbags.buyExactInReturnsWithLock({inputAmount:n,amountIn:s,pool:r,config:a,dynamicVirtualTokenReserves:u});return c},G.getSuiAmountAfterSell=async function(e,t){let{curveAmount:n,poolId:i,frontendFee:o}=e,[r,a]=await Promise.all([ea(t,i),ea(t,ee.CONFIG_OBJECT_ID)]),{receivedSui:u}=et.Moonbags.sellReturns({amountIn:n,pool:r,config:a});return void 0!==o?el(u,o):u},G.getUsedSuiForTx=async function(e,t){let{suiAmount:n,frontendFee:i}=e,o=await ea(t,ee.CONFIG_OBJECT_ID);return void 0!==i&&(n=el(n,i)),n*ee.FEE_DENOMINATOR/(ee.FEE_DENOMINATOR+BigInt(o.platform_fee))};var ek=ei||(ei={});async function eD(e,t){let{tx:n,coinOut:i}=await eT(e,t);A(i,"Coin out is required");let o=await en.getUsedSuiForTx({suiAmount:BigInt(e.inputAmount),frontendFee:e.frontendFee},t),[r,a]=n.moveCall({target:`${ee.PACKAGE_ID}::moonbags::buy_exact_in_returns_with_lock`,typeArguments:[e.outCoinType],arguments:[n.object(ee.CONFIG_OBJECT_ID),n.object(ee.LOCK_CONFIG_OBJECT_ID),i,n.pure.u64(o),n.pure.u64(e.minAmountOut),n.object(ee.BURN_MANAGER_OBJECT_ID),n.object(ee.POOLS_OBJECT_ID),n.object(ee.GLOBAL_CONFIG_OBJECT_ID),n.object(eC),n.object(eA)]});return X.transferOrDestroyZeroCoin(n,ep,r,e.accountAddress),{tx:n,coinOut:a}}async function eM(e,t){A(e.outCoinType===ep||e.outCoinType===eg,"Output must be SUI");let{tx:n,coinData:i}=await ey({amount:e.inputAmount,coinType:e.inCoinType,inheritTx:e.extendTx?.tx,account:e.accountAddress,splits:[e.inputAmount]},t),[o]=i,[r,a]=n.moveCall({target:`${ee.PACKAGE_ID}::moonbags::sell_returns`,typeArguments:[e.inCoinType],arguments:[n.object(ee.CONFIG_OBJECT_ID),o,n.pure.u64(e.minAmountOut),n.object(eA)]});return X.transferOrDestroyZeroCoin(n,e.inCoinType,a,e.accountAddress),await eB(n,e,r)}function eN(e){return e}function eU(e){return e}function ej(e){return new Proxy(e,{get(e,t){let n=e[t];return"function"==typeof n?n.bind(e):n}})}ek.buildBuyTx=eD,ek.buildSellTx=eM,ek.getBuyTransaction=async function({coinInAmount:e,coinInType:t,coinOutType:n,poolId:i,slippage:o,walletAddress:a,tradeFee:u},s){A(t===eg,"coinInType must be SUI for buy transaction"),A(n!==t,"coinOutType must be different from coinInType"),A(o>=0&&o<1,"slippage must be between 0 (inclusive) and 1 (exclusive)"),A(e>0,"coinInAmount must be greater than 0");let c=BigInt(new r((await en.getCurveAmountAfterBuy({poolId:i,suiAmount:e,frontendFee:u?u.tradeFeePercent:void 0},s)).toString()).multipliedBy(1-o).toFixed(0,3)),{tx:l,coinOut:d}=await eD({accountAddress:a,inCoinType:t,outCoinType:n,inputAmount:e.toString(),minAmountOut:c.toString(),poolId:i,frontendFee:u?u.tradeFeePercent:void 0,frontendFeeRecipient:u?u.tradeFeeRecipientAddress:void 0,extendTx:void 0,isSponsored:!1},s);A(d,"Coin out is required"),l.transferObjects([d],l.pure.address(a)),l.setSender(a);let f=await ed(s,l,a,0);return(l=await eS({inheritTx:l,sender:a,feeAmount:f,suiInputAmount:e},s)).build({client:s})},ek.getSellTransaction=async function({coinInAmount:e,coinInType:t,coinOutType:n,poolId:i,slippage:o,walletAddress:a,tradeFee:u},s){A(n===eg,"coinOutType must be SUI for sell transaction"),A(n!==t,"coinOutType must be different from coinInType"),A(o>=0&&o<1,"slippage must be between 0 (inclusive) and 1 (exclusive)"),A(e>0,"coinInAmount must be greater than 0");let c=BigInt(new r((await en.getSuiAmountAfterSell({poolId:i,curveAmount:e,frontendFee:u?u.tradeFeePercent:void 0},s)).toString()).multipliedBy(1-o).toFixed(0,3)),{tx:l,coinOut:d}=await eM({accountAddress:a,inCoinType:t,outCoinType:n,inputAmount:e.toString(),minAmountOut:c.toString(),poolId:i,frontendFee:u?u.tradeFeePercent:void 0,frontendFeeRecipient:u?u.tradeFeeRecipientAddress:void 0,extendTx:void 0,isSponsored:!1},s);A(d,"Coin out is required"),l.transferObjects([d],l.pure.address(a)),l.setSender(a);let f=await ed(s,l,a,0);return(l=await eS({inheritTx:l,sender:a,feeAmount:f},s)).build({client:s})};class eK{suiClient;constructor(e){this.suiClient=e}validatePrivateKey(e,t){A(e?.trim(),"Private key is required");let n=O.fromSecretKey(e),i=n.getPublicKey().toSuiAddress();if(i!==t)throw Error(`Private key mismatch. Expected: ${t}, Got: ${i}`);return n}async createDraft(e,t,n){A(e?.trim(),"Sender address is required"),A(t?.trim(),"Recipient address is required"),A(e!==t,"Sender and recipient cannot be the same"),A(n>0n,"Transfer amount must be at least 1 MIST");try{let i=new o,[r]=i.splitCoins(i.gas,[n]);i.transferObjects([r],t),i.setSender(e);let a=await this.suiClient.getReferenceGasPrice();i.setGasPrice(a);let u=await ed(this.suiClient,i,e,.1);i=await eS({inheritTx:i,sender:e,feeAmount:u,suiInputAmount:n},this.suiClient);let s=await i.build({client:this.suiClient}),c=Buffer.from(s).toString("base64"),l=await i.getDigest();return{sender:e,recipient:t,amountMIST:n,txDraftBase64:c,txDigest:l}}catch(e){throw Error(`Failed to create draft transaction: ${e instanceof Error?e.message:"Unknown error"}`)}}async execute(e,t){try{A(e,"Draft transaction is required"),A(e.txDraftBase64?.trim(),"Transaction data is required");let n=this.validatePrivateKey(t,e.sender),i=h(e.txDraftBase64),{signature:o}=await n.signTransaction(i),r=await this.suiClient.executeTransactionBlock({transactionBlock:i,signature:o});return{success:!0,txDigest:r.digest,effects:r.effects}}catch(e){return{success:!1,error:e instanceof Error?e.message:"Unknown error occurred"}}}async getTransactionStatus(e){A(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"}}}export{v as AftermathAggregator,w as AstrosAggregator,es as BASE_BPS,eb as BLUEFIN_PACKAGE_ID,J as BlastFunConstants,Z as BlastFunCustomCalculation,Y as BlastFunCustomTransaction,W as BlastFunPackage,H as BlastFunSDKCalculation,Q as BlastFunSDKTransaction,X as BluefinTx,V as Bps,eA as CLOCK_OBJECT_ID,S as CetusAggregator,eK as DraftTransferTx,er as FlowXAggregator,$ as MathUtils,en as MoonbagsCalculation,ee as MoonbagsConstants,et as MoonbagsPackage,ei as MoonbagsTransaction,e_ as NATIVE_USDC_TOKEN_TYPE,ep as SUI_FULL_TYPE,eC as SUI_METADATA_OBJECT_ID,eg as SUI_TYPE,F as SevenKAggregator,eo as SupportedAggregator,eP as SupportedBondingCurve,L as TradeFeeOptions,eI as USDC_TOKEN_TYPE,eN as adaptSuiClient,eU as adaptTransaction,eS as addGasFee,ej as createCompatibleSuiClient,el as getAmountAfterFee,eh as getCoinObjectIdsByAmount,ew as getMemezPumpSDK,eu as getMoveObject,ea as getMoveObjectContent,ed as getNeededGasFee,ey as getSplitCoinForTx,ec as getSplitCoinsAfterFee,eT as splitSuiCoinAfterFeeFromBuyTx,eB as splitSuiCoinAfterFeeFromSellTx};
1
+ import{BluefinXTx as e,Config as t,buildTx as n,getQuote as i}from"@7kprotocol/sdk-ts/cjs";import{Transaction as r}from"@mysten/sui/transactions";import o from"bignumber.js";import{Aftermath as a,Helpers as s}from"aftermath-ts-sdk";import{buildSwapPTBFromQuote as u,getCoins as c,getQuote as l}from"@naviprotocol/astros-aggregator-sdk";import{AggregatorClient as d,Env as g}from"@cetusprotocol/aggregator-sdk";import f from"bn.js";import{AggregatorQuoter as p,Coin as m,Commission as _,CommissionType as I,TradeBuilder as A}from"@flowx-finance/sdk";import h from"@minswap/tiny-invariant";import{fromBase64 as T,normalizeStructTag as C}from"@mysten/sui/utils";import{MemezPumpSDK as y}from"@interest-protocol/memez-fun-sdk";import{Network as b}from"@interest-protocol/sui-core-sdk";import{SuiClient as B,getFullnodeUrl as w}from"@mysten/sui/client";import{Ed25519Keypair as F}from"@mysten/sui/keypairs/ed25519";class O{_config;_suiClient;constructor(e,t){this._config=e,this._suiClient=t}async getTradeRoute({coinInAmount:e,coinInType:n,coinOutType:r,tradeFee:o}){try{this._config.sevenKApiKey&&t.setApiKey(this._config.sevenKApiKey);let a=o?o.tradeFeePercent:this._config.defaultTradeFee.tradeFeePercent;return i({tokenIn:n,tokenOut:r,amountIn:e.toString(),commissionBps:1e4*a})}catch(e){return null}}async getTransaction({walletAddress:t,completeRoute:i,slippage:o,tradeFee:a}){let s,u;a?(s=a.tradeFeePercent,u=a.tradeFeeRecipientAddress):(s=this._config.defaultTradeFee.tradeFeePercent,u=this._config.defaultTradeFee.tradeFeeRecipientAddress);let c=await n({quoteResponse:i,slippage:o,accountAddress:t,commission:{partner:u,commissionBps:1e4*s}});return c.tx instanceof e?r.from(c.tx.txBytes).build({client:this._suiClient}):(c.tx.setSender(t),c.tx.build({client:this._suiClient}))}}(O||(O={})).toCommonTradeRoutes=function(e){let t=[];if(!e.routes||0===e.routes.length)return null;for(let n of e.routes){let e=[],i={};for(let t of n.hops){for(let e of t.pool.allTokens)i[e.address]=e.decimal;let n=i[t.tokenIn]??0,r=i[t.tokenOut]??0,a=BigInt(new o(t.tokenInAmount).multipliedBy(10**n).toFixed(0,3)),s=BigInt(new o(t.tokenOutAmount).multipliedBy(10**r).toFixed(0,3));e.push({poolAddress:t.poolId,coinIn:t.tokenIn,coinOut:t.tokenOut,amountIn:a,amountOut:s})}if(0===e.length)continue;let r=i[n.tokenIn]??0,a=i[n.tokenOut]??0,s=BigInt(new o(n.tokenInAmount).multipliedBy(10**r).toFixed(0,3)),u=BigInt(new o(n.tokenOutAmount).multipliedBy(10**a).toFixed(0,3));t.push({paths:e,coinIn:n.tokenIn,coinOut:n.tokenOut,amountIn:s,amountOut:u})}return 0===t.length?null:{coinIn:e.tokenIn,coinOut:e.tokenOut,amountIn:BigInt(e.swapAmountWithDecimal),amountOut:BigInt(e.returnAmountWithDecimal),routes:t}};class v{_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 a(this._config.aftermathApiEndpoint):this._aftermathClient=new a("MAINNET"),await this._aftermathClient.init(),this._config.aftermathApiKey){let e=s.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:i}){let r;return r=i?{recipient:i.tradeFeeRecipientAddress,feePercentage:i.tradeFeePercent}:{recipient:this._config.defaultTradeFee.tradeFeeRecipientAddress,feePercentage:this._config.defaultTradeFee.tradeFeePercent},(await this.aftermathClient()).Router().getCompleteTradeRouteGivenAmountIn({coinInAmount:e,coinInType:t,coinOutType:n,externalFee:r})}async getTransaction({completeRoute:e,walletAddress:t,slippage:n}){let i=await this.aftermathClient(),r=await i.Router().getTransactionForCompleteTradeRoute({completeRoute:e,walletAddress:t,slippage:n,isSponsoredTx:!1});return r.setSender(t),r.build({client:this._suiClient})}}(v||(v={})).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}};class S{_config;_suiClient;constructor(e,t){this._config=e,this._suiClient=t}async getTradeRoute({coinInAmount:e,coinInType:t,coinOutType:n,tradeFee:i}){try{let r;return r=i?{fee:i.tradeFeePercent,receiverAddress:i.tradeFeeRecipientAddress}:{fee:this._config.defaultTradeFee.tradeFeePercent,receiverAddress:this._config.defaultTradeFee.tradeFeeRecipientAddress},l(t,n,e,this._config.astrosApiKey,{byAmountIn:!0,serviceFee:r})}catch(e){return null}}returnMergedCoins(e,t,n){if(t.length<2)return e.object(t[0].coinObjectId);let i=0,r=[];t.sort((e,t)=>Number(t.balance)-Number(e.balance)).slice(1).forEach(e=>{i>=n||(i+=Number(e.balance),r.push(e.coinObjectId))});let o=t[0].coinObjectId;return e.mergeCoins(o,r),e.object(o)}async getTransaction({completeRoute:e,walletAddress:t,slippage:n,tradeFee:i}){var a;let s,l;s=i?{fee:i.tradeFeePercent,receiverAddress:i.tradeFeeRecipientAddress}:{fee:this._config.defaultTradeFee.tradeFeePercent,receiverAddress:this._config.defaultTradeFee.tradeFeeRecipientAddress};let d=new o(e.amount_out).multipliedBy(1-n-s.fee).toNumber(),g=new r;if("0x2::sui::SUI"===(a=e.from)||"0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI"===a)l=g.splitCoins(g.gas,[g.pure.u64(e.amount_in)]);else{let n=await c(this._suiClient,t,e.from),i=this.returnMergedCoins(g,n.data,Number.parseFloat(e.amount_in));l=g.splitCoins(i,[g.pure.u64(e.amount_in)])}let f=await u(t,g,d,l,e,void 0,!1,this._config.astrosApiKey,{serviceFee:s});return g.transferObjects([f],t),g.setSender(t),g.build({client:this._suiClient})}}(S||(S={})).toCommonTradeRoutes=function(e,t,n){if(0===e.routes.length)return null;let i=[];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&&i.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===i.length?null:{coinIn:t,coinOut:n,amountIn:BigInt(e.amount_in),amountOut:BigInt(e.amount_out),routes:i}},($||($={})).equals=function(e,t){return e.tradeFeePercent===t.tradeFeePercent&&e.tradeFeeRecipientAddress===t.tradeFeeRecipientAddress};class R{_config;_suiClient;_cetusClient;constructor(e,t){this._config=e,this._suiClient=t}cetusClient(e,t){return t&&!$.equals(t,this._config.defaultTradeFee)?new d({client:this._suiClient,overlayFeeReceiver:t.tradeFeeRecipientAddress,overlayFeeRate:t.tradeFeePercent,env:g.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 d({client:this._suiClient,overlayFeeReceiver:this._config.defaultTradeFee.tradeFeeRecipientAddress,overlayFeeRate:this._config.defaultTradeFee.tradeFeePercent,env:g.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:i}){return this.cetusClient(void 0,i).findRouters({from:t,target:n,amount:new f(e.toString()),byAmountIn:!0})}async getTransaction({completeRoute:e,walletAddress:t,slippage:n,tradeFee:i}){let o=new r,a=this.cetusClient(t,i);return await a.fastRouterSwap({router:e,txb:o,slippage:n}),await a.devInspectTransactionBlock(o),o.setSender(t),o.build({client:this._suiClient})}}(R||(R={})).toCommonTradeRoutes=function(e,t,n){if(0===e.paths.length)return null;let i=[],r=[],o=[];for(let t=0;t<e.paths.length;t++){let n=e.paths[t],i={poolAddress:n.id,amountIn:BigInt(n.amountIn),amountOut:BigInt(n.amountOut),coinIn:n.from,coinOut:n.target};if(o.push(i),t===e.paths.length-1)r.push([...o]);else{let i=e.paths[t+1];n.target!==i.from&&(r.push([...o]),o=[])}}for(let e of r)0!==e.length&&i.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===i.length?null:{coinIn:t,coinOut:n,amountIn:BigInt(e.amountIn.toString(10)),amountOut:BigInt(e.amountOut.toString(10)),routes:i}};var x,E,k,P,M,D,N,j,K,U,G,q,L,z,$,J,W,V,X,Z,H,Y,Q,ee,et,en,ei,er,eo=((z={}).ASTROS="ASTROS",z.AFTERMATH="AFTERMATH",z.SEVENK="7K",z.CETUS="CETUS",z.FLOWX="FLOWX",z);class ea{_config;_suiClient;constructor(e,t){this._config=e,this._suiClient=t}getCommission(e,t){let n,i;return t?(n=t.tradeFeePercent,i=t.tradeFeeRecipientAddress):(n=this._config.defaultTradeFee.tradeFeePercent,i=this._config.defaultTradeFee.tradeFeeRecipientAddress),new _(i,new m(e),I.PERCENTAGE,1e6*n,!0)}async getTradeRoute({coinInAmount:e,coinInType:t,coinOutType:n,tradeFee:i}){let r=new p("mainnet",this._config.flowxApiKey);try{return r.getRoutes({tokenIn:t,tokenOut:n,amountIn:e.toString(),commission:this.getCommission(t,i)})}catch(e){return null}}async getTransaction({walletAddress:e,completeRoute:t,slippage:n,tradeFee:i}){return new A("mainnet",t.routes).sender(e).slippage(1e6*n).commission(this.getCommission(t.coinIn.coinType,i)).build().buildTransaction({client:this._suiClient}).then(t=>(t.setSender(e),t.build({client:this._suiClient})))}}async function es(e,t){return(await eu(e,t)).fields}async function eu(e,t){let n=await e.getObject({id:t,options:{showContent:!0}}),i=n.data?.content;return h(i,"Pool object not found or has no content"),h("moveObject"===i.dataType,"Object is not a Move object"),i}(ea||(ea={})).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}},(x=J||(J={})).PACKAGE_ID_V4="0x7e6aa6e179466ab2814425a780b122575296d011119fa69d27f289f5a28814bd",x.MEMEZ_AV_OBJECT_ID="0x2319e3e76dfad73d8f4684bdbf42be4f32d8ce4521dd61becc8261dc918d82c0";let ec=1e4;function el(e,t){let n=BigInt(e),i=BigInt(Number(t)*ec);if(i===BigInt(0))return[n.toString()];let r=n*i/BigInt(ec);return[(n-r).toString(),r.toString()]}function ed(e,t){if(!t||0>=Number(t))return BigInt(e);let n=BigInt(e),i=BigInt(Number(t)*ec);if(i===BigInt(0))return n;let r=n*i/BigInt(ec);return n-r}async function eg(e,t,n,i){let{effects:{gasUsed:r,status:o}}=await e.devInspectTransactionBlock({sender:n,transactionBlock:t});if("success"!==o.status)throw Error(`Transaction failed during dev inspect: ${o.error??""}`);let a=BigInt(r.computationCost)+BigInt(r.storageCost)-BigInt(r.storageRebate),s=BigInt(Number(i)*ec);return a*(BigInt(ec)+s)/BigInt(ec)}((E=W||(W={})).U64||(E.U64={})).mulDivUp=function(e,t,n){let i=BigInt(0);return e*t%n>BigInt(0)&&(i=BigInt(1)),e*t/n+i};var ef=V||(V={});function ep(e){return h(BigInt(e)<=BigInt(1e4),"Bps overflow"),BigInt(e)}ef.calcUp=function(e,t){let n,i=BigInt(e.pos0),r=BigInt(1e4);return n=i*t%r!==BigInt(0)?BigInt(1):BigInt(0),i*t/r+n},ef.sub=function(e,t){return h(BigInt(e.pos0)>=BigInt(t.pos0),"Bps underflow"),{pos0:(BigInt(e.pos0)-BigInt(t.pos0)).toString()}},ef.value=function(e){return BigInt(e.pos0)},ef.new_=function(e){return{pos0:ep(e).toString()}},ef.assertOverflow=ep,((k=X||(X={})).MemezFun||(k.MemezFun={})).isSniperProtectedMemezFun=async function(e,t){return(await es(e,t)).public_key.length>0},(P=k.MemezFees||(k.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 i=e.fields.pos0.fields;if(BigInt(i.pos0)===BigInt(0))return BigInt(0);let r=V.calcUp(V.sub(i,n),t);if(t>=r)return r;throw Error(`Insufficient amount to cover fee. Required: ${r}, provided: ${t}`)}throw Error("Unknown fee variant")},P.calculateWithDiscount=function(e,t,n){if("Value"===e.variant)return BigInt(e.fields.pos0);if("Percentage"===e.variant){let i=e.fields.pos0.fields;return V.calcUp(V.sub(i,t),n)}throw Error("Unknown fee variant")},(k.MemezBurner||(k.MemezBurner={})).calculate=function(e,t){if(V.value(e.fee.fields)===BigInt(0)||t===BigInt(0)||t>=BigInt(e.target_liquidity))return V.new_(0);let n=BigInt(1e4);return V.new_(W.U64.mulDivUp(V.value(e.fee.fields),W.U64.mulDivUp(t,n,BigInt(e.target_liquidity)),n))},(M=k.MemezPump||(k.MemezPump={})).getPumpState=async function(e,t){return await es(e,t.inner_state)},M.pump=function(e,t){let n=e.constant_product.fields,i=k.MemezFees.takeWithDiscount(n.quote_swap_fee,t,n.quote_referrer_fee.fields),r=t-i,o=BigInt(n.meme_balance),a=BigInt(n.quote_balance),s=o*r/(BigInt(n.virtual_liquidity)+a+r),u=k.MemezFees.takeWithDiscount(n.meme_swap_fee,s,n.meme_referrer_fee.fields);return s-u},M.dump=function(e,t){let n=e.constant_product.fields,i=k.MemezFees.takeWithDiscount(n.meme_swap_fee,t,n.meme_referrer_fee.fields),r=t-i,o=BigInt(n.meme_balance),a=BigInt(n.quote_balance),s=BigInt(n.virtual_liquidity),u=k.MemezBurner.calculate(n.burner.fields,a),c=V.calcUp(u,r),l=r-(V.value(u)!==BigInt(0)?c:BigInt(0)),d=(s+a)*l/(o+l);d>a&&(d=a);let g=k.MemezFees.takeWithDiscount(n.quote_swap_fee,d,n.quote_referrer_fee.fields);return d-g},(D=Z||(Z={})).getCurveAmountAfterBuy=async function(e,t){let{suiAmount:n,poolId:i,frontendFee:r}=e,o=await es(t,i),a=await X.MemezPump.getPumpState(t,o);return n=ed(n,r),X.MemezPump.pump(a,n)},D.getSuiAmountAfterSell=async function(e,t){let{curveAmount:n,poolId:i,frontendFee:r}=e,o=await es(t,i),a=await X.MemezPump.getPumpState(t,o);return ed(X.MemezPump.dump(a,n),r)};let em="0x2::sui::SUI",e_="0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",eI="0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN",eA="0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",eh="0x9258181f5ceac8dbffb7030890243caed69a9599d2886d957a9cb7656af3bdb3",eT="0x0000000000000000000000000000000000000000000000000000000000000006",eC=async(e,t,n,i)=>{let r,o=[],a=!0;for(;a;)try{let n=await e.getCoins({owner:t,coinType:i,cursor:r});o=[...o,...n.data],a=n.hasNextPage,r=n.nextCursor}catch(e){console.error("Error fetching data:",e),a=!1}let s=((e,t,n)=>{let i;if(e?.length){do{i=!1;for(let r=0;r<e.length-1;r++){let o=BigInt(e[r][t]),a=BigInt(e[r+1][t]);if("desc"===n?o<a:o>a){let t=e[r];e[r]=e[r+1],e[r+1]=t,i=!0}}}while(i);return e}})(o.map(e=>({...e,balance:e.balance})),"balance","desc")??[],u="0",c=[],l=[];for(let e of s)if(u=(BigInt(e.balance)+BigInt(u)).toString(10),c.push(e.coinObjectId),l.push(e),BigInt(u)>=BigInt(n))break;return{objectIds:c,balance:u,objectCoins:l}};async function ey(e,t){let{account:n,amount:i,splits:o,coinType:a,inheritTx:s,inspecTransaction:u,isSponsored:c=!1}=e,l=s??new r,{objectIds:d}=await eC(t,n,i,a),g=d[0];if(C(a)===C(e_)&&!c){let e;return u?(d.length>1&&l.mergeCoins(l.object(g),d.slice(1).map(e=>l.object(e))),e=l.splitCoins(l.object(g),o)):e=l.splitCoins(l.gas,o),{tx:l,coinData:e}}d.length>1&&l.mergeCoins(l.object(g),d.slice(1).map(e=>l.object(e)));let f=l.splitCoins(l.object(g),o);return{tx:l,coinData:f}}let eb="0x62412b7268c35f3808336aee57a52836501f40b8ba5d936f8ad275e672befd04";async function eB(e,t){let n,i,{inputAmount:o,accountAddress:a,frontendFee:s,frontendFeeRecipient:u,extendTx:c,isSponsored:l}=e;h(e.inCoinType===e_||e.inCoinType===em,"Input must be SUI");let{tx:d,coinIn:g}=c||{},f=el(o,s||"0"),p=d||new r;if(g)n=p.splitCoins(g,f),H.transferOrDestroyZeroCoin(p,e_,g,a);else{let{coinData:e}=await ey({account:a,amount:o,splits:f,coinType:e_,inheritTx:p,isSponsored:l||!1},t);n=e}if(s&&u){let[e,t]=n;i=e,p.transferObjects([t],p.pure.address(u||a))}else[i]=n;return{tx:p,coinOut:i}}async function ew(e,t,n){if(h(t.outCoinType===e_||t.outCoinType===em,"Output must be SUI"),0>=Number(t.frontendFee||0))return{tx:e,coinOut:n};let i=e.moveCall({target:"0x2::coin::value",typeArguments:[t.outCoinType],arguments:[n]}),r=e.moveCall({target:`${eb}::math::mul_div_u64`,typeArguments:[],arguments:[i,e.pure.u64(BigInt(Number(t.frontendFee||"0")*ec)),e.pure.u64(BigInt(ec))]}),o=e.moveCall({target:"0x2::coin::split",typeArguments:[t.outCoinType],arguments:[n,r]});return e.transferObjects([o],e.pure.address(t.frontendFeeRecipient||t.accountAddress)),{tx:e,coinOut:n}}(H||(H={})).transferOrDestroyZeroCoin=function(e,t,n,i){e.moveCall({target:`${eb}::utils::transfer_or_destroy`,typeArguments:[t],arguments:[n,e.pure.address(i)]})};var eF=Y||(Y={});async function eO(e){let t=e||new r;return t.moveCall({target:`${J.PACKAGE_ID_V4}::memez_allowed_versions::get_allowed_versions`,arguments:[t.object(J.MEMEZ_AV_OBJECT_ID)],typeArguments:[]})}eF.getAllowedVersions=eO,eF.buildBuyTx=async function(e,t){h(!await X.MemezFun.isSniperProtectedMemezFun(t,e.poolId),"This coin is a sniper protected coin, please use the Blast Fun website to trade it.");let{tx:n,coinOut:i}=await eB(e,t);h(i,"Coin out is required");let r=n.moveCall({target:`${J.PACKAGE_ID_V4}::memez_pump::pump`,typeArguments:[e.outCoinType,e_],arguments:[n.object(e.poolId),i,n.pure.vector("address",[]),n.pure.vector("vector<u8>",[]),n.pure.u64(e.minAmountOut),await eO(n)]});return{tx:n,coinOut:r}},eF.buildSellTx=async function(e,t){h(e.outCoinType===e_||e.outCoinType===em,"Output must be SUI");let n=await es(t,e.poolId),{tx:i,coinData:r}=await ey({amount:e.inputAmount,coinType:e.inCoinType,inheritTx:e.extendTx?.tx,account:e.accountAddress,splits:[e.inputAmount]},t),[o]=r,[a]=i.moveCall({target:`${J.PACKAGE_ID_V4}::memez_pump::dump`,typeArguments:[e.inCoinType,e.outCoinType],arguments:[i.object(e.poolId),i.object(n.ipx_meme_coin_treasury),o,i.pure.vector("address",[]),i.pure.u64(e.minAmountOut),await eO(i)]});return await ew(i,e,a)};let ev=new y({network:b.MAINNET,fullNodeUrl:w("mainnet")});function eS(){return ev}async function eR(e,t){let{inheritTx:n,sender:i,feeAmount:o,suiInputAmount:a}=e,s=n||new r;s.setGasBudget(o);let{objectCoins:u}=await eC(t,i,(BigInt(a||"0")+o).toString(),e_);return s.setGasPayment(u.map(e=>({objectId:e.coinObjectId,version:e.version,digest:e.digest}))),s}(N=Q||(Q={})).getCurveAmountAfterBuy=async function(e){let{suiAmount:t,poolId:n,frontendFee:i}=e;t=ed(t,i);let{memeAmountOut:r}=await eS().quotePump({pool:n,amount:t});return r},N.getSuiAmountAfterSell=async function(e){let{curveAmount:t,poolId:n,frontendFee:i}=e,{quoteAmountOut:r}=await eS().quoteDump({pool:n,amount:t});return ed(r,i)};var ex=ee||(ee={});async function eE(e,t){let{tx:n,coinOut:i}=await eB(e,t);h(i,"Coin out is required");let{memeCoin:r,tx:o}=await eS().pump({pool:e.poolId,quoteCoin:i,minAmountOut:e.minAmountOut,tx:n});return{tx:o,coinOut:r}}async function ek(e,t){h(e.outCoinType===e_||e.outCoinType===em,"Output must be SUI");let{tx:n,coinData:i}=await ey({amount:e.inputAmount,coinType:e.inCoinType,inheritTx:e.extendTx?.tx,account:e.accountAddress,splits:[e.inputAmount]},t),[r]=i,{quoteCoin:o,tx:a}=await eS().dump({pool:e.poolId,memeCoin:r,tx:n,minAmountOut:e.minAmountOut});return await ew(a,e,o)}ex.buildBuyTx=eE,ex.buildSellTx=ek,ex.getBuyTransaction=async function({coinInAmount:e,coinInType:t,coinOutType:n,poolId:i,slippage:r,walletAddress:a,tradeFee:s},u){h(t===em,"coinInType must be SUI for buy transaction"),h(n!==t,"coinOutType must be different from coinInType"),h(r>=0&&r<1,"slippage must be between 0 (inclusive) and 1 (exclusive)"),h(e>0,"coinInAmount must be greater than 0");let c=BigInt(new o((await Q.getCurveAmountAfterBuy({poolId:i,suiAmount:e,frontendFee:s?s.tradeFeePercent:void 0})).toString()).multipliedBy(1-r).toFixed(0,3)),{tx:l,coinOut:d}=await eE({accountAddress:a,inCoinType:t,outCoinType:n,inputAmount:e.toString(),minAmountOut:c.toString(),poolId:i,frontendFee:s?s.tradeFeePercent:void 0,frontendFeeRecipient:s?s.tradeFeeRecipientAddress:void 0,extendTx:void 0,isSponsored:!1},u);h(d,"Coin out is required"),l.transferObjects([d],l.pure.address(a)),l.setSender(a);let g=await eg(u,l,a,0);return(l=await eR({inheritTx:l,sender:a,feeAmount:g,suiInputAmount:e},u)).build({client:u})},ex.getSellTransaction=async function({coinInAmount:e,coinInType:t,coinOutType:n,poolId:i,slippage:r,walletAddress:a,tradeFee:s},u){h(n===em,"coinOutType must be SUI for sell transaction"),h(n!==t,"coinOutType must be different from coinInType"),h(r>=0&&r<1,"slippage must be between 0 (inclusive) and 1 (exclusive)"),h(e>0,"coinInAmount must be greater than 0");let c=BigInt(new o((await Q.getSuiAmountAfterSell({poolId:i,curveAmount:e,frontendFee:s?s.tradeFeePercent:void 0})).toString()).multipliedBy(1-r).toFixed(0,3)),{tx:l,coinOut:d}=await ek({accountAddress:a,inCoinType:t,outCoinType:n,inputAmount:e.toString(),minAmountOut:c.toString(),poolId:i,frontendFee:s?s.tradeFeePercent:void 0,frontendFeeRecipient:s?s.tradeFeeRecipientAddress:void 0,extendTx:void 0,isSponsored:!1},u);h(d,"Coin out is required"),l.transferObjects([d],l.pure.address(a)),l.setSender(a);let g=await eg(u,l,a,0);return(l=await eR({inheritTx:l,sender:a,feeAmount:g},u)).build({client:u})};var eP=((j={}).BLAST_FUN="BLAST_FUN",j.MOONBAGS="MOONBAGS",j);(K=et||(et={})).PACKAGE_ID="0xb8df325010942634a4afb3db3901ee215546af43a4ec4af781e7213b0bba7290",K.CONFIG_OBJECT_ID="0x74aecf86067c6913960ba4925333aefd2b1f929cafca7e21fd55a8f244b70499",K.LOCK_CONFIG_OBJECT_ID="0xfb09822d9808980abd04c51321adb850701f5f55535c6206658ef4d910c3e9be",K.BURN_MANAGER_OBJECT_ID="0x1d94aa32518d0cb00f9de6ed60d450c9a2090761f326752ffad06b2e9404f845",K.POOLS_OBJECT_ID="0xf699e7f2276f5c9a75944b37a0c5b5d9ddfd2471bf6242483b03ab2887d198d0",K.GLOBAL_CONFIG_OBJECT_ID="0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f",K.FEE_DENOMINATOR=BigInt(1e4),(G=(U=en||(en={})).Curves||(U.Curves={})).calculateAddLiquidityCost=function(e,t,n){return e*t/(t-n)-e},G.calculateRemoveLiquidityReturn=function(e,t,n){return t-e*t/(e+n)},G.calculateTokenAmountReceived=function(e,t,n){return t-e*t/(e+n)},(q=U.Moonbags||(U.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)},q.buyExactInReturnsWithLock=function(e){let{inputAmount:t,amountIn:n,pool:i,config:r,dynamicVirtualTokenReserves:o}=e,a=BigInt(i.virtual_sui_reserves),s=BigInt(i.virtual_token_reserves),u=BigInt(i.remain_token_reserves.fields.balance),c=U.Curves.calculateRemoveLiquidityReturn(a,s,n),l=s-(o||u),d=c,g=n;c>l&&(d=l,g=U.Curves.calculateAddLiquidityCost(a,s,l)+BigInt(1));let f=g*BigInt(r.platform_fee)/et.FEE_DENOMINATOR;return h(t>=g+f,"Input amount is less than used SUI + fee"),{receivedCurve:d,receivedSui:t-g-f}},q.sellReturns=function(e){let{amountIn:t,pool:n,config:i}=e,r=BigInt(n.virtual_sui_reserves),o=BigInt(n.virtual_token_reserves),a=BigInt(n.real_sui_reserves.fields.balance),s=U.Curves.calculateRemoveLiquidityReturn(o,r,t);s>a&&(s=a);let u=s*BigInt(i.platform_fee)/et.FEE_DENOMINATOR,c=s-u;return{receivedCurve:BigInt(0),receivedSui:c}},(L=ei||(ei={})).getCurveAmountAfterBuy=async function(e,t){let{suiAmount:n,poolId:i,frontendFee:r}=e,[o,a,s]=await Promise.all([es(t,i),es(t,et.CONFIG_OBJECT_ID),en.Moonbags.getDynamicVirtualTokenReserves(t,i)]);void 0!==r&&(n=ed(n,r));let u=n*et.FEE_DENOMINATOR/(et.FEE_DENOMINATOR+BigInt(a.platform_fee)),{receivedCurve:c}=en.Moonbags.buyExactInReturnsWithLock({inputAmount:n,amountIn:u,pool:o,config:a,dynamicVirtualTokenReserves:s});return c},L.getSuiAmountAfterSell=async function(e,t){let{curveAmount:n,poolId:i,frontendFee:r}=e,[o,a]=await Promise.all([es(t,i),es(t,et.CONFIG_OBJECT_ID)]),{receivedSui:s}=en.Moonbags.sellReturns({amountIn:n,pool:o,config:a});return void 0!==r?ed(s,r):s},L.getUsedSuiForTx=async function(e,t){let{suiAmount:n,frontendFee:i}=e,r=await es(t,et.CONFIG_OBJECT_ID);return void 0!==i&&(n=ed(n,i)),n*et.FEE_DENOMINATOR/(et.FEE_DENOMINATOR+BigInt(r.platform_fee))};var eM=er||(er={});async function eD(e,t){let{tx:n,coinOut:i}=await eB(e,t);h(i,"Coin out is required");let r=await ei.getUsedSuiForTx({suiAmount:BigInt(e.inputAmount),frontendFee:e.frontendFee},t),[o,a]=n.moveCall({target:`${et.PACKAGE_ID}::moonbags::buy_exact_in_returns_with_lock`,typeArguments:[e.outCoinType],arguments:[n.object(et.CONFIG_OBJECT_ID),n.object(et.LOCK_CONFIG_OBJECT_ID),i,n.pure.u64(r),n.pure.u64(e.minAmountOut),n.object(et.BURN_MANAGER_OBJECT_ID),n.object(et.POOLS_OBJECT_ID),n.object(et.GLOBAL_CONFIG_OBJECT_ID),n.object(eh),n.object(eT)]});return H.transferOrDestroyZeroCoin(n,e_,o,e.accountAddress),{tx:n,coinOut:a}}async function eN(e,t){h(e.outCoinType===e_||e.outCoinType===em,"Output must be SUI");let{tx:n,coinData:i}=await ey({amount:e.inputAmount,coinType:e.inCoinType,inheritTx:e.extendTx?.tx,account:e.accountAddress,splits:[e.inputAmount]},t),[r]=i,[o,a]=n.moveCall({target:`${et.PACKAGE_ID}::moonbags::sell_returns`,typeArguments:[e.inCoinType],arguments:[n.object(et.CONFIG_OBJECT_ID),r,n.pure.u64(e.minAmountOut),n.object(eT)]});return H.transferOrDestroyZeroCoin(n,e.inCoinType,a,e.accountAddress),await ew(n,e,o)}function ej(e){return e}function eK(e){return e}function eU(e){return new Proxy(e,{get(e,t){let n=e[t];return"function"==typeof n?n.bind(e):n}})}eM.buildBuyTx=eD,eM.buildSellTx=eN,eM.getBuyTransaction=async function({coinInAmount:e,coinInType:t,coinOutType:n,poolId:i,slippage:r,walletAddress:a,tradeFee:s},u){h(t===em,"coinInType must be SUI for buy transaction"),h(n!==t,"coinOutType must be different from coinInType"),h(r>=0&&r<1,"slippage must be between 0 (inclusive) and 1 (exclusive)"),h(e>0,"coinInAmount must be greater than 0");let c=BigInt(new o((await ei.getCurveAmountAfterBuy({poolId:i,suiAmount:e,frontendFee:s?s.tradeFeePercent:void 0},u)).toString()).multipliedBy(1-r).toFixed(0,3)),{tx:l,coinOut:d}=await eD({accountAddress:a,inCoinType:t,outCoinType:n,inputAmount:e.toString(),minAmountOut:c.toString(),poolId:i,frontendFee:s?s.tradeFeePercent:void 0,frontendFeeRecipient:s?s.tradeFeeRecipientAddress:void 0,extendTx:void 0,isSponsored:!1},u);h(d,"Coin out is required"),l.transferObjects([d],l.pure.address(a)),l.setSender(a);let g=await eg(u,l,a,0);return(l=await eR({inheritTx:l,sender:a,feeAmount:g,suiInputAmount:e},u)).build({client:u})},eM.getSellTransaction=async function({coinInAmount:e,coinInType:t,coinOutType:n,poolId:i,slippage:r,walletAddress:a,tradeFee:s},u){h(n===em,"coinOutType must be SUI for sell transaction"),h(n!==t,"coinOutType must be different from coinInType"),h(r>=0&&r<1,"slippage must be between 0 (inclusive) and 1 (exclusive)"),h(e>0,"coinInAmount must be greater than 0");let c=BigInt(new o((await ei.getSuiAmountAfterSell({poolId:i,curveAmount:e,frontendFee:s?s.tradeFeePercent:void 0},u)).toString()).multipliedBy(1-r).toFixed(0,3)),{tx:l,coinOut:d}=await eN({accountAddress:a,inCoinType:t,outCoinType:n,inputAmount:e.toString(),minAmountOut:c.toString(),poolId:i,frontendFee:s?s.tradeFeePercent:void 0,frontendFeeRecipient:s?s.tradeFeeRecipientAddress:void 0,extendTx:void 0,isSponsored:!1},u);h(d,"Coin out is required"),l.transferObjects([d],l.pure.address(a)),l.setSender(a);let g=await eg(u,l,a,0);return(l=await eR({inheritTx:l,sender:a,feeAmount:g},u)).build({client:u})};class eG{sdk;_astrosAggregator;_aftermathAggregator;_sevenkAggregator;_cetusAggregator;_flowXAggregator;constructor(e){this.sdk=e,this._astrosAggregator=new S({defaultTradeFee:e.options.tradeFee,astrosApiKey:e.options.astrosApiKey},e.suiClient),this._aftermathAggregator=new v({defaultTradeFee:e.options.tradeFee,aftermathApiKey:e.options.aftermathApiKey,aftermathApiEndpoint:e.options.aftermathApiEndpoint},e.suiClient),this._sevenkAggregator=new O({defaultTradeFee:e.options.tradeFee,sevenKApiKey:e.options.sevenKApiKey},e.suiClient),this._cetusAggregator=new R({defaultTradeFee:e.options.tradeFee,cetusApiKey:e.options.cetusApiKey,cetusApiEndpoint:e.options.cetusApiEndpoint,cetusPartnerId:e.options.cetusPartnerId},e.suiClient),this._flowXAggregator=new ea({defaultTradeFee:e.options.tradeFee,flowxApiKey:e.options.flowxApiKey},e.suiClient)}get astrosAggregator(){return this._astrosAggregator}get aftermathAggregator(){return this._aftermathAggregator}get sevenkAggregator(){return this._sevenkAggregator}get cetusAggregator(){return this._cetusAggregator}get flowXAggregator(){return this._flowXAggregator}async getTradeRoute(e,t){let n;switch(e){case eo.ASTROS:{let e,i=await this._astrosAggregator.getTradeRoute(t);if(!i)return null;let r=S.toCommonTradeRoutes(i,t.coinInType,t.coinOutType);if(!r)return null;e=t.tradeFee?t.tradeFee.tradeFeePercent:this.sdk.options.tradeFee.tradeFeePercent,r.amountOut=BigInt(new o(i.amount_out).multipliedBy(1-e).toFixed(0,3)),n={route:r,aggregatorRoute:i};break}case eo.AFTERMATH:{let e=await this._aftermathAggregator.getTradeRoute(t),i=v.toCommonTradeRoutes(e);if(!i)return null;n={route:i,aggregatorRoute:e};break}case eo.SEVENK:{let e=await this._sevenkAggregator.getTradeRoute(t);if(!e)return null;let i=O.toCommonTradeRoutes(e);if(!i)return null;n={route:i,aggregatorRoute:e};break}case eo.CETUS:{let e=await this._cetusAggregator.getTradeRoute(t);if(!e)return null;let i=R.toCommonTradeRoutes(e,t.coinInType,t.coinOutType);if(!i)return null;n={route:i,aggregatorRoute:e};break}case eo.FLOWX:{let e=await this._flowXAggregator.getTradeRoute(t);if(!e)return null;let i=ea.toCommonTradeRoutes(e);if(!i)return null;n={route:i,aggregatorRoute:e}}}return n}async getTransactionByRoute(e,t){switch(e){case eo.ASTROS:return this._astrosAggregator.getTransaction({walletAddress:t.walletAddress,completeRoute:t.completeRoute,slippage:t.slippage,tradeFee:t.tradeFee});case eo.AFTERMATH:return this._aftermathAggregator.getTransaction({walletAddress:t.walletAddress,completeRoute:t.completeRoute,slippage:t.slippage});case eo.SEVENK:return this._sevenkAggregator.getTransaction({walletAddress:t.walletAddress,completeRoute:t.completeRoute,slippage:t.slippage,tradeFee:t.tradeFee});case eo.CETUS:return this._cetusAggregator.getTransaction({walletAddress:t.walletAddress,completeRoute:t.completeRoute,slippage:t.slippage,tradeFee:t.tradeFee});case eo.FLOWX:return this._flowXAggregator.getTransaction({walletAddress:t.walletAddress,completeRoute:t.completeRoute,slippage:t.slippage,tradeFee:t.tradeFee})}}async getTradeTransaction(e,t){let n=await this.getTradeRoute(e,{coinInAmount:t.coinInAmount,coinInType:t.coinInType,coinOutType:t.coinOutType,tradeFee:t.tradeFee});if(!n)return null;let i=await this.getTransactionByRoute(e,{walletAddress:t.walletAddress,completeRoute:n.aggregatorRoute,slippage:t.slippage,tradeFee:t.tradeFee});return{route:n.route,aggregatorRoute:n.aggregatorRoute,transaction:i}}async getTradeTransactionWithBestRate(e){let t=Object.keys(eo),n=await Promise.all(t.map(async t=>{try{return await this.getTradeRoute(t,e)}catch{return null}})),i=null,r=null;for(let e=0;e<n.length;e++){let o=n[e],a=t[e];if(o&&(!i||o.route.amountOut>i.route.amountOut)){i=o,r=a;continue}}if(!i||!r)return null;let o=await this.getTransactionByRoute(r,{walletAddress:e.walletAddress,completeRoute:i.aggregatorRoute,slippage:e.slippage,tradeFee:e.tradeFee});return{route:i.route,aggregatorRoute:i.aggregatorRoute,transaction:o}}}let eq="0x3cebf157c3595b2b5a590a506c60128506237d889917a0f7317a2c7bf6ed0289",eL="0x1a502860215ca71a83fd8e0e09e6bb640d0faef35ddd385cea744d06f18dcfdb",ez="0xefa0c0ee48ad31da2e9f4ef2eef96834857bde142317edcc0f787076fbf077fd";class e${sdk;constructor(e){this.sdk=e}async getConfig(){let e=await this.sdk.suiClient.getObject({id:eL,options:{showContent:!0}});h(e.data?.content,"Config object not found or has no content"),h(e.data?.content.dataType==="moveObject","Config object is not a Move object");let t=e.data.content.fields,n=t.id.id,i=t.fee_receiver,r=t.tiers.fields.contents,o={};for(let e of r){let t=e.fields.key,n=e.fields.value.fields.duration,i=e.fields.value.fields.amount,r=e.fields.value.fields.point,a=e.fields.value.fields.original_amount;o[t]={duration:BigInt(n),amount:BigInt(i),point:BigInt(r),originalAmount:BigInt(a)}}return{id:n,receiverAddress:i,tiers:o}}async buildPayBoostingTx({walletAddress:e,tierId:t,boostingCoinType:n,currentTx:i}){let o=await this.getConfig();h(t in o.tiers,"Invalid tier ID");let a=o.tiers[t].amount,s=i||new r,u=s.splitCoins(s.gas,[s.pure.u64(a)]);s.moveCall({target:`${eq}::boosting::pay`,typeArguments:[C(n)],arguments:[s.object(eL),s.pure.u64(t),u]}),s.setSender(e);let c=await eg(this.sdk.suiClient,s,e,0);return eR({inheritTx:s,sender:e,feeAmount:c},this.sdk.suiClient)}async buildAddTierTx({adminAddress:e,tierId:t,duration:n,point:i,originalAmount:o,amount:a,currentTx:s}){let u=s||new r;u.moveCall({target:`${eq}::config::add_tier`,typeArguments:[],arguments:[u.object(eL),u.object(ez),u.pure.u64(t),u.pure.u64(i),u.pure.u64(n),u.pure.u64(o),u.pure.u64(a)]}),u.setSender(e);let c=await eg(this.sdk.suiClient,u,e,0);return eR({inheritTx:u,sender:e,feeAmount:c},this.sdk.suiClient)}async buildUpdateTierTx({adminAddress:e,tierId:t,duration:n,amount:i,originalAmount:o,point:a,currentTx:s}){let u=s||new r;u.moveCall({target:`${eq}::config::update_tier`,typeArguments:[],arguments:[u.object(eL),u.object(ez),u.pure.u64(t),u.pure.u64(n),u.pure.u64(i),u.pure.u64(a),u.pure.u64(o)]}),u.setSender(e);let c=await eg(this.sdk.suiClient,u,e,0);return eR({inheritTx:u,sender:e,feeAmount:c},this.sdk.suiClient)}async buildRemoveTierTx({adminAddress:e,tierId:t,currentTx:n}){let i=n||new r;i.moveCall({target:`${eq}::config::remove_tier`,typeArguments:[],arguments:[i.object(eL),i.object(ez),i.pure.u64(t)]}),i.setSender(e);let o=await eg(this.sdk.suiClient,i,e,0);return eR({inheritTx:i,sender:e,feeAmount:o},this.sdk.suiClient)}async buildUpdateFeeReceiver({adminAddress:e,newReceiverAddress:t,currentTx:n}){let i=n||new r;i.moveCall({target:`${eq}::config::update_fee_receiver`,typeArguments:[],arguments:[i.object(eL),i.object(ez),i.pure.address(t)]}),i.setSender(e);let o=await eg(this.sdk.suiClient,i,e,0);return eR({inheritTx:i,sender:e,feeAmount:o},this.sdk.suiClient)}async buildPayBoostingWithAdminTx({walletAddress:e,tierId:t,customAmount:n,boostingCoinType:i,currentTx:o}){let a=o||new r,s=a.splitCoins(a.gas,[a.pure.u64(n)]);a.moveCall({target:`${eq}::boosting::pay_with_admin`,typeArguments:[C(i)],arguments:[a.object(ez),a.object(eL),a.pure.u64(t),a.pure.u64(n),s]}),a.setSender(e);let u=await eg(this.sdk.suiClient,a,e,0);return eR({inheritTx:a,sender:e,feeAmount:u},this.sdk.suiClient)}}class eJ{sdk;constructor(e){this.sdk=e}async getTradeTransaction(e,t){let n,{coinInType:i,coinOutType:r}=t;h(i!==r,"coinInType and coinOutType must be different"),h(i===em||r===em,"One of coinInType or coinOutType must be SUI");let o=i===em;switch(e){case eP.MOONBAGS:n=o?await er.getBuyTransaction(t,this.sdk.suiClient):await er.getSellTransaction(t,this.sdk.suiClient);break;case eP.BLAST_FUN:n=o?await ee.getBuyTransaction(t,this.sdk.suiClient):await ee.getSellTransaction(t,this.sdk.suiClient);break;default:throw Error(`Unsupported bonding curve platform: ${e}`)}return n}}let eW={tradeFeePercent:.01,tradeFeeRecipientAddress:"0xdaf1c8ed29d89cd8f217f609bad0a668fa6f158c12000bfa5f93e670c99e24ff"};class eV{options;_suiClient;aggregatorModule;curveModule;boostingModule;constructor(e){this.options=e,this._suiClient=new B({url:w("mainnet")}),this.aggregatorModule=new eG(this),this.curveModule=new eJ(this),this.boostingModule=new e$(this)}get suiClient(){return this._suiClient}}class eX{suiClient;constructor(e){this.suiClient=e}validatePrivateKey(e,t){h(e?.trim(),"Private key is required");let n=F.fromSecretKey(e),i=n.getPublicKey().toSuiAddress();if(i!==t)throw Error(`Private key mismatch. Expected: ${t}, Got: ${i}`);return n}async createDraft(e,t,n){h(e?.trim(),"Sender address is required"),h(t?.trim(),"Recipient address is required"),h(e!==t,"Sender and recipient cannot be the same"),h(n>0n,"Transfer amount must be at least 1 MIST");try{let i=new r,[o]=i.splitCoins(i.gas,[n]);i.transferObjects([o],t),i.setSender(e);let a=await this.suiClient.getReferenceGasPrice();i.setGasPrice(a);let s=await eg(this.suiClient,i,e,.1);i=await eR({inheritTx:i,sender:e,feeAmount:s,suiInputAmount:n},this.suiClient);let u=await i.build({client:this.suiClient}),c=Buffer.from(u).toString("base64"),l=await i.getDigest();return{sender:e,recipient:t,amountMIST:n,txDraftBase64:c,txDigest:l}}catch(e){throw Error(`Failed to create draft transaction: ${e instanceof Error?e.message:"Unknown error"}`)}}async execute(e,t){try{h(e,"Draft transaction is required"),h(e.txDraftBase64?.trim(),"Transaction data is required");let n=this.validatePrivateKey(t,e.sender),i=T(e.txDraftBase64),{signature:r}=await n.signTransaction(i),o=await this.suiClient.executeTransactionBlock({transactionBlock:i,signature:r});return{success:!0,txDigest:o.digest,effects:o.effects}}catch(e){return{success:!1,error:e instanceof Error?e.message:"Unknown error occurred"}}}async getTransactionStatus(e){h(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"}}}export{ez as ADMIN_CAP_ID,v as AftermathAggregator,eG as AggregatorModule,S as AstrosAggregator,ec as BASE_BPS,eb as BLUEFIN_PACKAGE_ID,eq as BOOSTING_PACKAGE_ID,J as BlastFunConstants,Z as BlastFunCustomCalculation,Y as BlastFunCustomTransaction,X as BlastFunPackage,Q as BlastFunSDKCalculation,ee as BlastFunSDKTransaction,H as BluefinTx,e$ as BoostingModule,V as Bps,eT as CLOCK_OBJECT_ID,eL as CONFIG_ID,R as CetusAggregator,eJ as CurveModule,eW as DEFAULT_TRADE_FEE,eX as DraftTransferTx,ea as FlowXAggregator,W as MathUtils,ei as MoonbagsCalculation,et as MoonbagsConstants,en as MoonbagsPackage,er as MoonbagsTransaction,eA as NATIVE_USDC_TOKEN_TYPE,eV as NoodlesSdk,e_ as SUI_FULL_TYPE,eh as SUI_METADATA_OBJECT_ID,em as SUI_TYPE,O as SevenKAggregator,eo as SupportedAggregator,eP as SupportedBondingCurve,$ as TradeFeeOptions,eI as USDC_TOKEN_TYPE,ej as adaptSuiClient,eK as adaptTransaction,eR as addGasFee,eU as createCompatibleSuiClient,ed as getAmountAfterFee,eC as getCoinObjectIdsByAmount,eS as getMemezPumpSDK,eu as getMoveObject,es as getMoveObjectContent,eg as getNeededGasFee,ey as getSplitCoinForTx,el as getSplitCoinsAfterFee,eB as splitSuiCoinAfterFeeFromBuyTx,ew as splitSuiCoinAfterFeeFromSellTx};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@minswap/noodles-sdk",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "exports": {
@@ -34,18 +34,17 @@
34
34
  "@alphafi/alphalend-sdk": "^1.1.20",
35
35
  "@cetusprotocol/aggregator-sdk": "1.2.1",
36
36
  "@cetusprotocol/cetus-sui-clmm-sdk": "^5.4.0",
37
- "@flowx-finance/sdk": "1.13.4",
38
- "@interest-protocol/memez-fun-sdk": "^16.6.0",
37
+ "@flowx-finance/sdk": "1.13.5",
38
+ "@interest-protocol/memez-fun-sdk": "^17.0.0",
39
39
  "@interest-protocol/sui-core-sdk": "^0.0.1",
40
40
  "@minswap/tiny-invariant": "^1.2.0",
41
41
  "@mysten/sui": "1.38.0",
42
42
  "@naviprotocol/astros-aggregator-sdk": "^1.7.0",
43
- "@scallop-io/sui-scallop-sdk": "^2.2.9",
43
+ "@scallop-io/sui-scallop-sdk": "^2.3.0",
44
44
  "@suilend/sdk": "^1.1.84",
45
45
  "aftermath-ts-sdk": "1.3.22",
46
46
  "bignumber.js": "^9.3.1",
47
- "bn.js": "^5.2.2",
48
- "navi-sdk": "^1.6.22"
47
+ "bn.js": "^5.2.2"
49
48
  },
50
49
  "publishConfig": {
51
50
  "access": "public"