@minswap/noodles-sdk 0.0.29 → 0.0.31-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +74 -58
- package/dist/index.js +1 -1
- package/dist/pay.cjs +1 -0
- package/dist/pay.d.ts +541 -0
- package/dist/pay.js +1 -0
- package/package.json +13 -8
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";import{Transaction as r}from"@mysten/sui/transactions";import a from"bignumber.js";import{Aftermath as o,Helpers as s}from"aftermath-ts-sdk";import{buildSwapPTBFromQuote as u,getCoins as l,getQuote as c}from"@naviprotocol/astros-aggregator-sdk";import{AggregatorClient as d,Env as g}from"@cetusprotocol/aggregator-sdk";import p from"bn.js";import{AggregatorQuoter as f,Coin as m,Commission as h,CommissionType as _,TradeBuilder as A}from"@flowx-finance/sdk";import I from"@minswap/tiny-invariant";import{fromBase64 as C,normalizeStructTag as b}from"@mysten/sui/utils";import{MemezPumpSDK as T}from"@interest-protocol/memez-fun-sdk";import{Network as y}from"@interest-protocol/sui-core-sdk";import{SuiClient as w,getFullnodeUrl as B}from"@mysten/sui/client";import{Ed25519Keypair as v}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:a}){try{this._config.sevenKApiKey&&t.setApiKey(this._config.sevenKApiKey);let o=a?a.tradeFeePercent:this._config.defaultTradeFee.tradeFeePercent;return await i({tokenIn:n,tokenOut:r,amountIn:e.toString(),commissionBps:1e4*o})}catch(e){return null}}async getTransaction({walletAddress:t,completeRoute:i,slippage:a,tradeFee:o}){let s,u;o?(s=o.tradeFeePercent,u=o.tradeFeeRecipientAddress):(s=this._config.defaultTradeFee.tradeFeePercent,u=this._config.defaultTradeFee.tradeFeeRecipientAddress);let l=await n({quoteResponse:i,slippage:a,accountAddress:t,commission:{partner:u,commissionBps:1e4*s}});return l.tx instanceof e?r.from(l.tx.txBytes).build({client:this._suiClient}):(l.tx.setSender(t),l.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,o=BigInt(new a(t.tokenInAmount).multipliedBy(10**n).toFixed(0,3)),s=BigInt(new a(t.tokenOutAmount).multipliedBy(10**r).toFixed(0,3));e.push({poolAddress:t.poolId,coinIn:t.tokenIn,coinOut:t.tokenOut,amountIn:o,amountOut:s})}if(0===e.length)continue;let r=i[n.tokenIn]??0,o=i[n.tokenOut]??0,s=BigInt(new a(n.tokenInAmount).multipliedBy(10**r).toFixed(0,3)),u=BigInt(new a(n.tokenOutAmount).multipliedBy(10**o).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 F{_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 o(this._config.aftermathApiEndpoint):this._aftermathClient=new o("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}){try{let r;r=i?{recipient:i.tradeFeeRecipientAddress,feePercentage:i.tradeFeePercent}:{recipient:this._config.defaultTradeFee.tradeFeeRecipientAddress,feePercentage:this._config.defaultTradeFee.tradeFeePercent};let a=await this.aftermathClient();return await a.Router().getCompleteTradeRouteGivenAmountIn({coinInAmount:e,coinInType:t,coinOutType:n,externalFee:r})}catch(e){return null}}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})}}(F||(F={})).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},await c(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 a=t[0].coinObjectId;return e.mergeCoins(a,r),e.object(a)}async getTransaction({completeRoute:e,walletAddress:t,slippage:n,tradeFee:i}){var o;let s,c;s=i?{fee:i.tradeFeePercent,receiverAddress:i.tradeFeeRecipientAddress}:{fee:this._config.defaultTradeFee.tradeFeePercent,receiverAddress:this._config.defaultTradeFee.tradeFeeRecipientAddress};let d=new a(e.amount_out).multipliedBy(1-n-s.fee).toNumber(),g=new r;if("0x2::sui::SUI"===(o=e.from)||"0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI"===o)c=g.splitCoins(g.gas,[g.pure.u64(e.amount_in)]);else{let n=await l(this._suiClient,t,e.from),i=this.returnMergedCoins(g,n.data,Number.parseFloat(e.amount_in));c=g.splitCoins(i,[g.pure.u64(e.amount_in)])}let p=await u(t,g,d,c,e,void 0,!1,this._config.astrosApiKey,{serviceFee:s});return g.transferObjects([p],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}},(z||(z={})).equals=function(e,t){return e.tradeFeePercent===t.tradeFeePercent&&e.tradeFeeRecipientAddress===t.tradeFeeRecipientAddress};class x{_config;_suiClient;_cetusClient;constructor(e,t){this._config=e,this._suiClient=t}cetusClient(e,t){return t&&!z.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}){try{let r=this.cetusClient(void 0,i);return await r.findRouters({from:t,target:n,amount:new p(e.toString()),byAmountIn:!0})}catch(e){return null}}async getTransaction({completeRoute:e,walletAddress:t,slippage:n,tradeFee:i}){let a=new r,o=this.cetusClient(t,i);return await o.fastRouterSwap({router:e,txb:a,slippage:n}),await o.devInspectTransactionBlock(a),a.setSender(t),a.build({client:this._suiClient})}}(x||(x={})).toCommonTradeRoutes=function(e,t,n){if(0===e.paths.length)return null;let i=[],r=[],a=[];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(a.push(i),t===e.paths.length-1)r.push([...a]);else{let i=e.paths[t+1];n.target!==i.from&&(r.push([...a]),a=[])}}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 k,R,E,P,D,j,M,N,U,K,G,q,$,L,z,W,J,V,X,Y,Z,H,Q,ee,et,en,ei,er,ea=((L={}).ASTROS="ASTROS",L.AFTERMATH="AFTERMATH",L.SEVENK="7K",L.CETUS="CETUS",L.FLOWX="FLOWX",L);class eo{_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 h(i,new m(e),_.PERCENTAGE,1e6*n,!0)}async getTradeRoute({coinInAmount:e,coinInType:t,coinOutType:n,tradeFee:i}){let r=new f("mainnet",this._config.flowxApiKey);try{return await 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 I(i,"Pool object not found or has no content"),I("moveObject"===i.dataType,"Object is not a Move object"),i}function el(e,t){let n=BigInt(e),i=BigInt(1e4*Number(t));if(i===BigInt(0))return[n.toString()];let r=n*i/BigInt(1e4);return[(n-r).toString(),r.toString()]}function ec(e,t){if(!t||0>=Number(t))return BigInt(e);let n=BigInt(e),i=BigInt(1e4*Number(t));if(i===BigInt(0))return n;let r=n*i/BigInt(1e4);return n-r}async function ed(e,t,n,i){let{effects:{gasUsed:r,status:a}}=await e.devInspectTransactionBlock({sender:n,transactionBlock:t});if("success"!==a.status)throw Error(`Transaction failed during dev inspect: ${a.error??""}`);let o=BigInt(r.computationCost)+BigInt(r.storageCost)-BigInt(r.storageRebate),s=BigInt(1e4*Number(i));return o*(BigInt(1e4)+s)/BigInt(1e4)}(eo||(eo={})).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}},(k=W||(W={})).PACKAGE_ID_V4="0x7e6aa6e179466ab2814425a780b122575296d011119fa69d27f289f5a28814bd",k.MEMEZ_AV_OBJECT_ID="0x2319e3e76dfad73d8f4684bdbf42be4f32d8ce4521dd61becc8261dc918d82c0",((R=J||(J={})).U64||(R.U64={})).mulDivUp=function(e,t,n){let i=BigInt(0);return e*t%n>BigInt(0)&&(i=BigInt(1)),e*t/n+i};var eg=V||(V={});function ep(e){return I(BigInt(e)<=BigInt(1e4),"Bps overflow"),BigInt(e)}eg.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},eg.sub=function(e,t){return I(BigInt(e.pos0)>=BigInt(t.pos0),"Bps underflow"),{pos0:(BigInt(e.pos0)-BigInt(t.pos0)).toString()}},eg.value=function(e){return BigInt(e.pos0)},eg.new_=function(e){return{pos0:ep(e).toString()}},eg.assertOverflow=ep,((E=X||(X={})).MemezFun||(E.MemezFun={})).isSniperProtectedMemezFun=async function(e,t){return(await es(e,t)).public_key.length>0},(P=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 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")},(E.MemezBurner||(E.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_(J.U64.mulDivUp(V.value(e.fee.fields),J.U64.mulDivUp(t,n,BigInt(e.target_liquidity)),n))},(D=E.MemezPump||(E.MemezPump={})).getPumpState=async function(e,t){return await es(e,t.inner_state)},D.pump=function(e,t){let n=e.constant_product.fields,i=E.MemezFees.takeWithDiscount(n.quote_swap_fee,t,n.quote_referrer_fee.fields),r=t-i,a=BigInt(n.meme_balance),o=BigInt(n.quote_balance),s=a*r/(BigInt(n.virtual_liquidity)+o+r),u=E.MemezFees.takeWithDiscount(n.meme_swap_fee,s,n.meme_referrer_fee.fields);return s-u},D.dump=function(e,t){let n=e.constant_product.fields,i=E.MemezFees.takeWithDiscount(n.meme_swap_fee,t,n.meme_referrer_fee.fields),r=t-i,a=BigInt(n.meme_balance),o=BigInt(n.quote_balance),s=BigInt(n.virtual_liquidity),u=E.MemezBurner.calculate(n.burner.fields,o),l=V.calcUp(u,r),c=r-(V.value(u)!==BigInt(0)?l:BigInt(0)),d=(s+o)*c/(a+c);d>o&&(d=o);let g=E.MemezFees.takeWithDiscount(n.quote_swap_fee,d,n.quote_referrer_fee.fields);return d-g},(j=Y||(Y={})).getCurveAmountAfterBuy=async function(e,t){let{suiAmount:n,poolId:i,frontendFee:r}=e,a=await es(t,i),o=await X.MemezPump.getPumpState(t,a);return n=ec(n,r),X.MemezPump.pump(o,n)},j.getSuiAmountAfterSell=async function(e,t){let{curveAmount:n,poolId:i,frontendFee:r}=e,a=await es(t,i),o=await X.MemezPump.getPumpState(t,a);return ec(X.MemezPump.dump(o,n),r)};let ef="0x2::sui::SUI",em="0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",eh="0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN",e_="0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",eA="0x9258181f5ceac8dbffb7030890243caed69a9599d2886d957a9cb7656af3bdb3",eI="0x0000000000000000000000000000000000000000000000000000000000000006",eC=async(e,t,n,i)=>{let r,a=[],o=!0;for(;o;)try{let n=await e.getCoins({owner:t,coinType:i,cursor:r});a=[...a,...n.data],o=n.hasNextPage,r=n.nextCursor}catch(e){console.error("Error fetching data:",e),o=!1}let s=((e,t,n)=>{let i;if(e?.length){do{i=!1;for(let r=0;r<e.length-1;r++){let a=BigInt(e[r][t]),o=BigInt(e[r+1][t]);if("desc"===n?a<o:a>o){let t=e[r];e[r]=e[r+1],e[r+1]=t,i=!0}}}while(i);return e}})(a.map(e=>({...e,balance:e.balance})),"balance","desc")??[],u="0",l=[],c=[];for(let e of s)if(u=(BigInt(e.balance)+BigInt(u)).toString(10),l.push(e.coinObjectId),c.push(e),BigInt(u)>=BigInt(n))break;return{objectIds:l,balance:u,objectCoins:c}};async function eb(e,t){let{account:n,amount:i,splits:a,coinType:o,inheritTx:s,inspecTransaction:u,isSponsored:l=!1}=e,c=s??new r,{objectIds:d}=await eC(t,n,i,o),g=d[0];if(b(o)===b(em)&&!l){let e;return u?(d.length>1&&c.mergeCoins(c.object(g),d.slice(1).map(e=>c.object(e))),e=c.splitCoins(c.object(g),a)):e=c.splitCoins(c.gas,a),{tx:c,coinData:e}}d.length>1&&c.mergeCoins(c.object(g),d.slice(1).map(e=>c.object(e)));let p=c.splitCoins(c.object(g),a);return{tx:c,coinData:p}}let eT="0x62412b7268c35f3808336aee57a52836501f40b8ba5d936f8ad275e672befd04";async function ey(e,t){let n,i,{inputAmount:a,accountAddress:o,frontendFee:s,frontendFeeRecipient:u,extendTx:l,isSponsored:c}=e;I(e.inCoinType===em||e.inCoinType===ef,"Input must be SUI");let{tx:d,coinIn:g}=l||{},p=el(a,s||"0"),f=d||new r;if(g)n=f.splitCoins(g,p),Z.transferOrDestroyZeroCoin(f,em,g,o);else{let{coinData:e}=await eb({account:o,amount:a,splits:p,coinType:em,inheritTx:f,isSponsored:c||!1},t);n=e}if(s&&u){let[e,t]=n;i=e,f.transferObjects([t],f.pure.address(u||o))}else[i]=n;return{tx:f,coinOut:i}}async function ew(e,t,n){if(I(t.outCoinType===em||t.outCoinType===ef,"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:`${eT}::math::mul_div_u64`,typeArguments:[],arguments:[i,e.pure.u64(BigInt(1e4*Number(t.frontendFee||"0"))),e.pure.u64(BigInt(1e4))]}),a=e.moveCall({target:"0x2::coin::split",typeArguments:[t.outCoinType],arguments:[n,r]});return e.transferObjects([a],e.pure.address(t.frontendFeeRecipient||t.accountAddress)),{tx:e,coinOut:n}}(Z||(Z={})).transferOrDestroyZeroCoin=function(e,t,n,i){e.moveCall({target:`${eT}::utils::transfer_or_destroy`,typeArguments:[t],arguments:[n,e.pure.address(i)]})};var eB=H||(H={});async function ev(e){let t=e||new r;return t.moveCall({target:`${W.PACKAGE_ID_V4}::memez_allowed_versions::get_allowed_versions`,arguments:[t.object(W.MEMEZ_AV_OBJECT_ID)],typeArguments:[]})}eB.getAllowedVersions=ev,eB.buildBuyTx=async function(e,t){I(!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 ey(e,t);I(i,"Coin out is required");let r=n.moveCall({target:`${W.PACKAGE_ID_V4}::memez_pump::pump`,typeArguments:[e.outCoinType,em],arguments:[n.object(e.poolId),i,n.pure.vector("address",[]),n.pure.vector("vector<u8>",[]),n.pure.u64(e.minAmountOut),await ev(n)]});return{tx:n,coinOut:r}},eB.buildSellTx=async function(e,t){I(e.outCoinType===em||e.outCoinType===ef,"Output must be SUI");let n=await es(t,e.poolId),{tx:i,coinData:r}=await eb({amount:e.inputAmount,coinType:e.inCoinType,inheritTx:e.extendTx?.tx,account:e.accountAddress,splits:[e.inputAmount]},t),[a]=r,[o]=i.moveCall({target:`${W.PACKAGE_ID_V4}::memez_pump::dump`,typeArguments:[e.inCoinType,e.outCoinType],arguments:[i.object(e.poolId),i.object(n.ipx_meme_coin_treasury),a,i.pure.vector("address",[]),i.pure.u64(e.minAmountOut),await ev(i)]});return await ew(i,e,o)};let eO=new T({network:y.MAINNET,fullNodeUrl:B("mainnet")});function eF(){return eO}async function eS(e,t){let{inheritTx:n,sender:i,feeAmount:a,suiInputAmount:o}=e,s=n||new r;s.setGasBudget(a);let{objectCoins:u}=await eC(t,i,(BigInt(o||"0")+a).toString(),em);return s.setGasPayment(u.map(e=>({objectId:e.coinObjectId,version:e.version,digest:e.digest}))),s}(M=Q||(Q={})).getCurveAmountAfterBuy=async function(e){let{suiAmount:t,poolId:n,frontendFee:i}=e;t=ec(t,i);let{memeAmountOut:r}=await eF().quotePump({pool:n,amount:t});return r},M.getSuiAmountAfterSell=async function(e){let{curveAmount:t,poolId:n,frontendFee:i}=e,{quoteAmountOut:r}=await eF().quoteDump({pool:n,amount:t});return ec(r,i)};var ex=ee||(ee={});async function ek(e,t){let{tx:n,coinOut:i}=await ey(e,t);I(i,"Coin out is required");let{memeCoin:r,tx:a}=await eF().pump({pool:e.poolId,quoteCoin:i,minAmountOut:e.minAmountOut,tx:n});return{tx:a,coinOut:r}}async function eR(e,t){I(e.outCoinType===em||e.outCoinType===ef,"Output must be SUI");let{tx:n,coinData:i}=await eb({amount:e.inputAmount,coinType:e.inCoinType,inheritTx:e.extendTx?.tx,account:e.accountAddress,splits:[e.inputAmount]},t),[r]=i,{quoteCoin:a,tx:o}=await eF().dump({pool:e.poolId,memeCoin:r,tx:n,minAmountOut:e.minAmountOut});return await ew(o,e,a)}ex.buildBuyTx=ek,ex.buildSellTx=eR,ex.getBuyTransaction=async function({coinInAmount:e,coinInType:t,coinOutType:n,poolId:i,slippage:r,walletAddress:o,tradeFee:s},u){I(t===ef,"coinInType must be SUI for buy transaction"),I(n!==t,"coinOutType must be different from coinInType"),I(r>=0&&r<1,"slippage must be between 0 (inclusive) and 1 (exclusive)"),I(e>0,"coinInAmount must be greater than 0");let l=BigInt(new a((await Q.getCurveAmountAfterBuy({poolId:i,suiAmount:e,frontendFee:s?s.tradeFeePercent:void 0})).toString()).multipliedBy(1-r).toFixed(0,3)),{tx:c,coinOut:d}=await ek({accountAddress:o,inCoinType:t,outCoinType:n,inputAmount:e.toString(),minAmountOut:l.toString(),poolId:i,frontendFee:s?s.tradeFeePercent:void 0,frontendFeeRecipient:s?s.tradeFeeRecipientAddress:void 0,extendTx:void 0,isSponsored:!1},u);I(d,"Coin out is required"),c.transferObjects([d],c.pure.address(o)),c.setSender(o);let g=await ed(u,c,o,0);return(c=await eS({inheritTx:c,sender:o,feeAmount:g,suiInputAmount:e},u)).build({client:u})},ex.getSellTransaction=async function({coinInAmount:e,coinInType:t,coinOutType:n,poolId:i,slippage:r,walletAddress:o,tradeFee:s},u){I(n===ef,"coinOutType must be SUI for sell transaction"),I(n!==t,"coinOutType must be different from coinInType"),I(r>=0&&r<1,"slippage must be between 0 (inclusive) and 1 (exclusive)"),I(e>0,"coinInAmount must be greater than 0");let l=BigInt(new a((await Q.getSuiAmountAfterSell({poolId:i,curveAmount:e,frontendFee:s?s.tradeFeePercent:void 0})).toString()).multipliedBy(1-r).toFixed(0,3)),{tx:c,coinOut:d}=await eR({accountAddress:o,inCoinType:t,outCoinType:n,inputAmount:e.toString(),minAmountOut:l.toString(),poolId:i,frontendFee:s?s.tradeFeePercent:void 0,frontendFeeRecipient:s?s.tradeFeeRecipientAddress:void 0,extendTx:void 0,isSponsored:!1},u);I(d,"Coin out is required"),c.transferObjects([d],c.pure.address(o)),c.setSender(o);let g=await ed(u,c,o,0);return(c=await eS({inheritTx:c,sender:o,feeAmount:g},u)).build({client:u})};var eE=((N={}).BLAST_FUN="BLAST_FUN",N.MOONBAGS="MOONBAGS",N);(U=et||(et={})).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),(G=(K=en||(en={})).Curves||(K.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=K.Moonbags||(K.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:a}=e,o=BigInt(i.virtual_sui_reserves),s=BigInt(i.virtual_token_reserves),u=BigInt(i.remain_token_reserves.fields.balance),l=K.Curves.calculateRemoveLiquidityReturn(o,s,n),c=s-(a||u),d=l,g=n;l>c&&(d=c,g=K.Curves.calculateAddLiquidityCost(o,s,c)+BigInt(1));let p=g*BigInt(r.platform_fee)/et.FEE_DENOMINATOR;return I(t>=g+p,"Input amount is less than used SUI + fee"),{receivedCurve:d,receivedSui:t-g-p}},q.sellReturns=function(e){let{amountIn:t,pool:n,config:i}=e,r=BigInt(n.virtual_sui_reserves),a=BigInt(n.virtual_token_reserves),o=BigInt(n.real_sui_reserves.fields.balance),s=K.Curves.calculateRemoveLiquidityReturn(a,r,t);s>o&&(s=o);let u=s*BigInt(i.platform_fee)/et.FEE_DENOMINATOR,l=s-u;return{receivedCurve:BigInt(0),receivedSui:l}},($=ei||(ei={})).getCurveAmountAfterBuy=async function(e,t){let{suiAmount:n,poolId:i,frontendFee:r}=e,[a,o,s]=await Promise.all([es(t,i),es(t,et.CONFIG_OBJECT_ID),en.Moonbags.getDynamicVirtualTokenReserves(t,i)]);void 0!==r&&(n=ec(n,r));let u=n*et.FEE_DENOMINATOR/(et.FEE_DENOMINATOR+BigInt(o.platform_fee)),{receivedCurve:l}=en.Moonbags.buyExactInReturnsWithLock({inputAmount:n,amountIn:u,pool:a,config:o,dynamicVirtualTokenReserves:s});return l},$.getSuiAmountAfterSell=async function(e,t){let{curveAmount:n,poolId:i,frontendFee:r}=e,[a,o]=await Promise.all([es(t,i),es(t,et.CONFIG_OBJECT_ID)]),{receivedSui:s}=en.Moonbags.sellReturns({amountIn:n,pool:a,config:o});return void 0!==r?ec(s,r):s},$.getUsedSuiForTx=async function(e,t){let{suiAmount:n,frontendFee:i}=e,r=await es(t,et.CONFIG_OBJECT_ID);return void 0!==i&&(n=ec(n,i)),n*et.FEE_DENOMINATOR/(et.FEE_DENOMINATOR+BigInt(r.platform_fee))};var eP=er||(er={});async function eD(e,t){let{tx:n,coinOut:i}=await ey(e,t);I(i,"Coin out is required");let r=await ei.getUsedSuiForTx({suiAmount:BigInt(e.inputAmount),frontendFee:e.frontendFee},t),[a,o]=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(eA),n.object(eI)]});return Z.transferOrDestroyZeroCoin(n,em,a,e.accountAddress),{tx:n,coinOut:o}}async function ej(e,t){I(e.outCoinType===em||e.outCoinType===ef,"Output must be SUI");let{tx:n,coinData:i}=await eb({amount:e.inputAmount,coinType:e.inCoinType,inheritTx:e.extendTx?.tx,account:e.accountAddress,splits:[e.inputAmount]},t),[r]=i,[a,o]=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(eI)]});return Z.transferOrDestroyZeroCoin(n,e.inCoinType,o,e.accountAddress),await ew(n,e,a)}function eM(e){return e}function eN(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}})}eP.buildBuyTx=eD,eP.buildSellTx=ej,eP.getBuyTransaction=async function({coinInAmount:e,coinInType:t,coinOutType:n,poolId:i,slippage:r,walletAddress:o,tradeFee:s},u){I(t===ef,"coinInType must be SUI for buy transaction"),I(n!==t,"coinOutType must be different from coinInType"),I(r>=0&&r<1,"slippage must be between 0 (inclusive) and 1 (exclusive)"),I(e>0,"coinInAmount must be greater than 0");let l=BigInt(new a((await ei.getCurveAmountAfterBuy({poolId:i,suiAmount:e,frontendFee:s?s.tradeFeePercent:void 0},u)).toString()).multipliedBy(1-r).toFixed(0,3)),{tx:c,coinOut:d}=await eD({accountAddress:o,inCoinType:t,outCoinType:n,inputAmount:e.toString(),minAmountOut:l.toString(),poolId:i,frontendFee:s?s.tradeFeePercent:void 0,frontendFeeRecipient:s?s.tradeFeeRecipientAddress:void 0,extendTx:void 0,isSponsored:!1},u);I(d,"Coin out is required"),c.transferObjects([d],c.pure.address(o)),c.setSender(o);let g=await ed(u,c,o,0);return(c=await eS({inheritTx:c,sender:o,feeAmount:g,suiInputAmount:e},u)).build({client:u})},eP.getSellTransaction=async function({coinInAmount:e,coinInType:t,coinOutType:n,poolId:i,slippage:r,walletAddress:o,tradeFee:s},u){I(n===ef,"coinOutType must be SUI for sell transaction"),I(n!==t,"coinOutType must be different from coinInType"),I(r>=0&&r<1,"slippage must be between 0 (inclusive) and 1 (exclusive)"),I(e>0,"coinInAmount must be greater than 0");let l=BigInt(new a((await ei.getSuiAmountAfterSell({poolId:i,curveAmount:e,frontendFee:s?s.tradeFeePercent:void 0},u)).toString()).multipliedBy(1-r).toFixed(0,3)),{tx:c,coinOut:d}=await ej({accountAddress:o,inCoinType:t,outCoinType:n,inputAmount:e.toString(),minAmountOut:l.toString(),poolId:i,frontendFee:s?s.tradeFeePercent:void 0,frontendFeeRecipient:s?s.tradeFeeRecipientAddress:void 0,extendTx:void 0,isSponsored:!1},u);I(d,"Coin out is required"),c.transferObjects([d],c.pure.address(o)),c.setSender(o);let g=await ed(u,c,o,0);return(c=await eS({inheritTx:c,sender:o,feeAmount:g},u)).build({client:u})};class eK{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 F({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 x({defaultTradeFee:e.options.tradeFee,cetusApiKey:e.options.cetusApiKey,cetusApiEndpoint:e.options.cetusApiEndpoint,cetusPartnerId:e.options.cetusPartnerId},e.suiClient),this._flowXAggregator=new eo({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 ea.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 a(i.amount_out).multipliedBy(1-e).toFixed(0,3)),n={route:r,aggregatorRoute:i};break}case ea.AFTERMATH:{let e=await this._aftermathAggregator.getTradeRoute(t);if(!e)return null;let i=F.toCommonTradeRoutes(e);if(!i)return null;n={route:i,aggregatorRoute:e};break}case ea.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 ea.CETUS:{let e=await this._cetusAggregator.getTradeRoute(t);if(!e)return null;let i=x.toCommonTradeRoutes(e,t.coinInType,t.coinOutType);if(!i)return null;n={route:i,aggregatorRoute:e};break}case ea.FLOWX:{let e=await this._flowXAggregator.getTradeRoute(t);if(!e)return null;let i=eo.toCommonTradeRoutes(e);if(!i)return null;n={route:i,aggregatorRoute:e}}}return n}async getTransactionByRoute(e,t){switch(e){case ea.ASTROS:return this._astrosAggregator.getTransaction({walletAddress:t.walletAddress,completeRoute:t.completeRoute,slippage:t.slippage,tradeFee:t.tradeFee});case ea.AFTERMATH:return this._aftermathAggregator.getTransaction({walletAddress:t.walletAddress,completeRoute:t.completeRoute,slippage:t.slippage});case ea.SEVENK:return this._sevenkAggregator.getTransaction({walletAddress:t.walletAddress,completeRoute:t.completeRoute,slippage:t.slippage,tradeFee:t.tradeFee});case ea.CETUS:return this._cetusAggregator.getTransaction({walletAddress:t.walletAddress,completeRoute:t.completeRoute,slippage:t.slippage,tradeFee:t.tradeFee});case ea.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(ea),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 a=n[e],o=t[e];if(a&&(!i||a.route.amountOut>i.route.amountOut)){i=a,r=o;continue}}if(!i||!r)return null;let a=await this.getTransactionByRoute(r,{walletAddress:e.walletAddress,completeRoute:i.aggregatorRoute,slippage:e.slippage,tradeFee:e.tradeFee});return{route:i.route,aggregatorRoute:i.aggregatorRoute,transaction:a}}async getAmountOut(e,t){let n=await this.getTradeRoute(e,t);return n?n.route.amountOut:null}async getBestAmountOut(e){let t=Object.keys(ea),n=null,i=null;for(let r of t){let t=await this.getAmountOut(r,e);null!==t&&(null===n||t>n)&&(n=t,i=r)}return null===n||null===i?null:{amountOut:n,aggregator:i}}}let eG="0x25fa0eb553dd69fa6a8028f73a38f1df7f289fa88a58ed3d7dc5a5360155bb19",eq="0x8b1a8ac6e34688cd8f8f8e5fefa9d5fb9e1ff74d2f132f8e208ae5ac9cc530bb",e$="0x13d101f44a0710a5475bec5f492a87b80e03d92d1cf540f26096f65850b23d26";class eL{sdk;constructor(e){this.sdk=e}async getConfig(){let e=await this.sdk.suiClient.getObject({id:eq,options:{showContent:!0}});I(e.data?.content,"Config object not found or has no content"),I(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,a={};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,o=e.fields.value.fields.original_amount;a[t]={duration:BigInt(n),amount:BigInt(i),point:BigInt(r),originalAmount:BigInt(o)}}return{id:n,receiverAddress:i,tiers:a}}async buildPayBoostingTx({walletAddress:e,tierId:t,boostingCoinType:n,currentTx:i}){let a=await this.getConfig();I(t in a.tiers,"Invalid tier ID");let o=a.tiers[t].amount,s=i||new r,u=s.splitCoins(s.gas,[s.pure.u64(o)]);s.moveCall({target:`${eG}::boosting::pay`,typeArguments:[b(n)],arguments:[s.object(eq),s.pure.u64(t),u]}),s.setSender(e);let l=await ed(this.sdk.suiClient,s,e,0);return eS({inheritTx:s,sender:e,feeAmount:l},this.sdk.suiClient)}async buildAddTierTx({adminAddress:e,tierId:t,duration:n,point:i,originalAmount:a,amount:o,currentTx:s}){let u=s||new r;u.moveCall({target:`${eG}::config::add_tier`,typeArguments:[],arguments:[u.object(eq),u.object(e$),u.pure.u64(t),u.pure.u64(i),u.pure.u64(n),u.pure.u64(a),u.pure.u64(o)]}),u.setSender(e);let l=await ed(this.sdk.suiClient,u,e,0);return eS({inheritTx:u,sender:e,feeAmount:l},this.sdk.suiClient)}async buildUpdateTierTx({adminAddress:e,tierId:t,duration:n,amount:i,originalAmount:a,point:o,currentTx:s}){let u=s||new r;u.moveCall({target:`${eG}::config::update_tier`,typeArguments:[],arguments:[u.object(eq),u.object(e$),u.pure.u64(t),u.pure.u64(n),u.pure.u64(i),u.pure.u64(o),u.pure.u64(a)]}),u.setSender(e);let l=await ed(this.sdk.suiClient,u,e,0);return eS({inheritTx:u,sender:e,feeAmount:l},this.sdk.suiClient)}async buildRemoveTierTx({adminAddress:e,tierId:t,currentTx:n}){let i=n||new r;i.moveCall({target:`${eG}::config::remove_tier`,typeArguments:[],arguments:[i.object(eq),i.object(e$),i.pure.u64(t)]}),i.setSender(e);let a=await ed(this.sdk.suiClient,i,e,0);return eS({inheritTx:i,sender:e,feeAmount:a},this.sdk.suiClient)}async buildUpdateFeeReceiver({adminAddress:e,newReceiverAddress:t,currentTx:n}){let i=n||new r;i.moveCall({target:`${eG}::config::update_fee_receiver`,typeArguments:[],arguments:[i.object(eq),i.object(e$),i.pure.address(t)]}),i.setSender(e);let a=await ed(this.sdk.suiClient,i,e,0);return eS({inheritTx:i,sender:e,feeAmount:a},this.sdk.suiClient)}async buildPayBoostingWithAdminTx({walletAddress:e,tierId:t,customAmount:n,boostingCoinType:i,currentTx:a}){let o=a||new r,s=o.splitCoins(o.gas,[o.pure.u64(n)]);o.moveCall({target:`${eG}::boosting::pay_with_admin`,typeArguments:[b(i)],arguments:[o.object(e$),o.object(eq),o.pure.u64(t),o.pure.u64(n),s]}),o.setSender(e);let u=await ed(this.sdk.suiClient,o,e,0);return eS({inheritTx:o,sender:e,feeAmount:u},this.sdk.suiClient)}}class ez{sdk;constructor(e){this.sdk=e}async getTradeTransaction(e,t){let n,{coinInType:i,coinOutType:r}=t;I(i!==r,"coinInType and coinOutType must be different"),I(i===ef||r===ef,"One of coinInType or coinOutType must be SUI");let a=i===ef;switch(e){case eE.MOONBAGS:n=a?await er.getBuyTransaction(t,this.sdk.suiClient):await er.getSellTransaction(t,this.sdk.suiClient);break;case eE.BLAST_FUN:n=a?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="0xb1a68620fe46c47c311b9e55f3861f39402467b8be99ac8117850dca0572ee9b",eJ="0xed705a72f66c5cdd596b240ff2547408852af34c35388bb29943b5635e4d5d18",eV="0xa5ac31061914e13b63b7d232c52d5690b8579022fe18645f320a7680973f51ad",eX="0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC";class eY{sdk;constructor(e){this.sdk=e}async getConfig(){let e=await this.sdk.suiClient.getObject({id:eJ,options:{showContent:!0}});I(e.data,"Config object not found"),I(e.data.content,"Config object has no content"),I(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.paused,a=t.accepted_payment_type,o=t.plans.fields.contents,s={};for(let e of o){let t=e.fields.key,n=e.fields.value.fields.id,i=e.fields.value.fields.price;s[t]={id:BigInt(n),price:BigInt(i)}}return{id:n,plans:s,feeReceiverWallet:i,paused:r,acceptedPaymentType:a}}async buildSubscribePlanTx({walletAddress:e,planId:t,userReference:n,paymentCoinType:i=eX,currentTx:r}){let a=await this.getConfig();I(!a.paused,"Contract is paused"),I(t in a.plans,"Invalid plan ID");let o=a.plans[t].price,{tx:s,coinData:u}=await eb({account:e,amount:o.toString(),splits:[o.toString()],coinType:i,inheritTx:r},this.sdk.suiClient);s.moveCall({target:`${eW}::subscription::subscribe_plan`,typeArguments:[i],arguments:[s.object(eJ),s.pure.u64(t),s.pure.string(n),u]}),s.setSender(e);let l=await ed(this.sdk.suiClient,s,e,0);return eS({inheritTx:s,sender:e,feeAmount:l},this.sdk.suiClient)}async buildUpgradePlanTx({walletAddress:e,currentPlanId:t,targetPlanId:n,userReference:i,paymentCoinType:r=eX,currentTx:a}){let o=await this.getConfig();I(!o.paused,"Contract is paused"),I(t in o.plans,"Invalid current plan ID"),I(n in o.plans,"Invalid target plan ID"),I(t!==n,"Current and target plan IDs must be different");let s=o.plans[n].price,{tx:u,coinData:l}=await eb({account:e,amount:s.toString(),splits:[s.toString()],coinType:r,inheritTx:a},this.sdk.suiClient);u.moveCall({target:`${eW}::subscription::upgrade_plan`,typeArguments:[r],arguments:[u.object(eJ),u.pure.u64(t),u.pure.u64(n),u.pure.string(i),l]}),u.setSender(e);let c=await ed(this.sdk.suiClient,u,e,0);return eS({inheritTx:u,sender:e,feeAmount:c},this.sdk.suiClient)}async buildUpgradePlanImmediatelyTx({walletAddress:e,currentPlanId:t,targetPlanId:n,userReference:i,paymentCoinType:r=eX,currentTx:a}){let o=await this.getConfig();I(!o.paused,"Contract is paused"),I(t in o.plans,"Invalid current plan ID"),I(n in o.plans,"Invalid target plan ID"),I(t!==n,"Current and target plan IDs must be different");let s=o.plans[t],u=o.plans[n].price-s.price;I(u>0n,"Target plan price must be higher than current plan price");let{tx:l,coinData:c}=await eb({account:e,amount:u.toString(),splits:[u.toString()],coinType:r,inheritTx:a},this.sdk.suiClient);l.moveCall({target:`${eW}::subscription::upgrade_plan_immediately`,typeArguments:[r],arguments:[l.object(eJ),l.pure.u64(t),l.pure.u64(n),l.pure.string(i),c]}),l.setSender(e);let d=await ed(this.sdk.suiClient,l,e,0);return eS({inheritTx:l,sender:e,feeAmount:d},this.sdk.suiClient)}async buildSubscribePlanWithAdminTx({walletAddress:e,planId:t,userReference:n,customAmount:i,paymentCoinType:r=eX,currentTx:a}){I(!(await this.getConfig()).paused,"Contract is paused");let{tx:o,coinData:s}=await eb({account:e,amount:i.toString(),splits:[i.toString()],coinType:r,inheritTx:a},this.sdk.suiClient);o.moveCall({target:`${eW}::subscription::subscribe_plan_with_admin`,typeArguments:[r],arguments:[o.object(eV),o.object(eJ),o.pure.u64(t),o.pure.string(n),o.pure.u64(i),s]}),o.setSender(e);let u=await ed(this.sdk.suiClient,o,e,0);return eS({inheritTx:o,sender:e,feeAmount:u},this.sdk.suiClient)}async buildAddPlanTx({adminAddress:e,planId:t,price:n,currentTx:i}){let a=i||new r;a.moveCall({target:`${eW}::config::add_plan`,typeArguments:[],arguments:[a.object(eJ),a.object(eV),a.pure.u64(BigInt(t)),a.pure.u64(n)]}),a.setSender(e);let o=await ed(this.sdk.suiClient,a,e,0);return eS({inheritTx:a,sender:e,feeAmount:o},this.sdk.suiClient)}async buildUpdatePlanTx({adminAddress:e,planId:t,price:n,currentTx:i}){let a=i||new r;a.moveCall({target:`${eW}::config::update_plan`,typeArguments:[],arguments:[a.object(eJ),a.object(eV),a.pure.u64(BigInt(t)),a.pure.u64(n)]}),a.setSender(e);let o=await ed(this.sdk.suiClient,a,e,0);return eS({inheritTx:a,sender:e,feeAmount:o},this.sdk.suiClient)}async buildRemovePlanTx({adminAddress:e,planId:t,currentTx:n}){let i=n||new r;i.moveCall({target:`${eW}::config::remove_plan`,typeArguments:[],arguments:[i.object(eJ),i.object(eV),i.pure.u64(BigInt(t))]}),i.setSender(e);let a=await ed(this.sdk.suiClient,i,e,0);return eS({inheritTx:i,sender:e,feeAmount:a},this.sdk.suiClient)}async buildUpdateFeeReceiverWalletTx({adminAddress:e,newFeeReceiverWallet:t,currentTx:n}){let i=n||new r;i.moveCall({target:`${eW}::config::update_fee_receiver`,typeArguments:[],arguments:[i.object(eJ),i.object(eV),i.pure.address(t)]}),i.setSender(e);let a=await ed(this.sdk.suiClient,i,e,0);return eS({inheritTx:i,sender:e,feeAmount:a},this.sdk.suiClient)}async buildSetPausedTx({adminAddress:e,paused:t,currentTx:n}){let i=n||new r;i.moveCall({target:`${eW}::config::set_paused`,typeArguments:[],arguments:[i.object(eJ),i.object(eV),i.pure.bool(t)]}),i.setSender(e);let a=await ed(this.sdk.suiClient,i,e,0);return eS({inheritTx:i,sender:e,feeAmount:a},this.sdk.suiClient)}async buildSetAcceptedPaymentTypeTx({adminAddress:e,paymentCoinType:t,currentTx:n}){let i=n||new r;i.moveCall({target:`${eW}::config::set_accepted_payment_type`,typeArguments:[t],arguments:[i.object(eJ),i.object(eV)]}),i.setSender(e);let a=await ed(this.sdk.suiClient,i,e,0);return eS({inheritTx:i,sender:e,feeAmount:a},this.sdk.suiClient)}}let eZ={tradeFeePercent:.01,tradeFeeRecipientAddress:"0xdaf1c8ed29d89cd8f217f609bad0a668fa6f158c12000bfa5f93e670c99e24ff"};class eH{options;_suiClient;aggregatorModule;curveModule;boostingModule;subscriptionModule;constructor(e){this.options=e,this._suiClient=new w({url:B("mainnet")}),this.aggregatorModule=new eK(this),this.curveModule=new ez(this),this.boostingModule=new eL(this),this.subscriptionModule=new eY(this)}get suiClient(){return this._suiClient}}class eQ{suiClient;constructor(e){this.suiClient=e}validatePrivateKey(e,t){I(e?.trim(),"Private key is required");let n=v.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){I(e?.trim(),"Sender address is required"),I(t?.trim(),"Recipient address is required"),I(e!==t,"Sender and recipient cannot be the same"),I(n>0n,"Transfer amount must be at least 1 MIST");try{let i=new r,[a]=i.splitCoins(i.gas,[n]);i.transferObjects([a],t),i.setSender(e);let o=await this.suiClient.getReferenceGasPrice();i.setGasPrice(o);let s=await ed(this.suiClient,i,e,.1);i=await eS({inheritTx:i,sender:e,feeAmount:s,suiInputAmount:n},this.suiClient);let u=await i.build({client:this.suiClient}),l=Buffer.from(u).toString("base64"),c=await i.getDigest();return{sender:e,recipient:t,amountMIST:n,txDraftBase64:l,txDigest:c}}catch(e){throw Error(`Failed to create draft transaction: ${e instanceof Error?e.message:"Unknown error"}`)}}async execute(e,t){try{I(e,"Draft transaction is required"),I(e.txDraftBase64?.trim(),"Transaction data is required");let n=this.validatePrivateKey(t,e.sender),i=C(e.txDraftBase64),{signature:r}=await n.signTransaction(i),a=await this.suiClient.executeTransactionBlock({transactionBlock:i,signature:r});return{success:!0,txDigest:a.digest,effects:a.effects}}catch(e){return{success:!1,error:e instanceof Error?e.message:"Unknown error occurred"}}}async getTransactionStatus(e){I(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"}}}var e0=1e4;export{e$ as ADMIN_CAP_ID,F as AftermathAggregator,eK as AggregatorModule,S as AstrosAggregator,eT as BLUEFIN_PACKAGE_ID,eG as BOOSTING_PACKAGE_ID,W as BlastFunConstants,Y as BlastFunCustomCalculation,H as BlastFunCustomTransaction,X as BlastFunPackage,Q as BlastFunSDKCalculation,ee as BlastFunSDKTransaction,Z as BluefinTx,eL as BoostingModule,V as Bps,eI as CLOCK_OBJECT_ID,eq as CONFIG_ID,x as CetusAggregator,ez as CurveModule,eZ as DEFAULT_TRADE_FEE,eQ as DraftTransferTx,eo as FlowXAggregator,J as MathUtils,ei as MoonbagsCalculation,et as MoonbagsConstants,en as MoonbagsPackage,er as MoonbagsTransaction,e_ as NATIVE_USDC_TOKEN_TYPE,eH as NoodlesSdk,eX as PAYMENT_COIN_TYPE,eV as SUBSCRIPTION_ADMIN_CAP_ID,eJ as SUBSCRIPTION_CONFIG_ID,eW as SUBSCRIPTION_PACKAGE_ID,em as SUI_FULL_TYPE,eA as SUI_METADATA_OBJECT_ID,ef as SUI_TYPE,O as SevenKAggregator,eY as SubscriptionModule,ea as SupportedAggregator,eE as SupportedBondingCurve,z as TradeFeeOptions,eh as USDC_TOKEN_TYPE,eM as adaptSuiClient,eN as adaptTransaction,eS as addGasFee,eU as createCompatibleSuiClient,ec as getAmountAfterFee,eC as getCoinObjectIdsByAmount,eF as getMemezPumpSDK,eu as getMoveObject,es as getMoveObjectContent,ed as getNeededGasFee,eb as getSplitCoinForTx,el as getSplitCoinsAfterFee,ey as splitSuiCoinAfterFeeFromBuyTx,ew as splitSuiCoinAfterFeeFromSellTx,e0 as BASE_BPS};
|
|
1
|
+
import{BluefinXTx as e,Config as t,buildTx as n,getQuote as i}from"@7kprotocol/sdk-ts";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 l,getQuote as c}from"@naviprotocol/astros-aggregator-sdk";import{AggregatorClient as d,Env as g}from"@cetusprotocol/aggregator-sdk";import p from"bn.js";import{AggregatorQuoter as f,Coin as m,Commission as h,CommissionType as _,TradeBuilder as A}from"@flowx-finance/sdk";import C from"@minswap/tiny-invariant";import{fromBase64 as I,normalizeStructTag as b}from"@mysten/sui/utils";import{MemezPumpSDK as y}from"@interest-protocol/memez-fun-sdk";import{Network as T}from"@interest-protocol/sui-core-sdk";import{SuiClient as w,getFullnodeUrl as B}from"@mysten/sui/client";import{Ed25519Keypair as v}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 await 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 l=await n({quoteResponse:i,slippage:o,accountAddress:t,commission:{partner:u,commissionBps:1e4*s}});return l.tx instanceof e?r.from(l.tx.txBytes).build({client:this._suiClient}):(l.tx.setSender(t),l.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 F{_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}){try{let r;r=i?{recipient:i.tradeFeeRecipientAddress,feePercentage:i.tradeFeePercent}:{recipient:this._config.defaultTradeFee.tradeFeeRecipientAddress,feePercentage:this._config.defaultTradeFee.tradeFeePercent};let o=await this.aftermathClient();return await o.Router().getCompleteTradeRouteGivenAmountIn({coinInAmount:e,coinInType:t,coinOutType:n,externalFee:r})}catch(e){return null}}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})}}(F||(F={})).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},await c(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,c;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)c=g.splitCoins(g.gas,[g.pure.u64(e.amount_in)]);else{let n=await l(this._suiClient,t,e.from),i=this.returnMergedCoins(g,n.data,Number.parseFloat(e.amount_in));c=g.splitCoins(i,[g.pure.u64(e.amount_in)])}let p=await u(t,g,d,c,e,void 0,!1,this._config.astrosApiKey,{serviceFee:s});return g.transferObjects([p],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}},(z||(z={})).equals=function(e,t){return e.tradeFeePercent===t.tradeFeePercent&&e.tradeFeeRecipientAddress===t.tradeFeeRecipientAddress};class x{_config;_suiClient;_cetusClient;constructor(e,t){this._config=e,this._suiClient=t}cetusClient(e,t){return t&&!z.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}){try{let r=this.cetusClient(void 0,i);return await r.findRouters({from:t,target:n,amount:new p(e.toString()),byAmountIn:!0})}catch(e){return null}}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})}}(x||(x={})).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 k,R,E,P,j,D,M,N,U,K,G,q,$,L,z,W,J,V,X,Y,Z,H,Q,ee,et,en,ei,er,eo=((L={}).ASTROS="ASTROS",L.AFTERMATH="AFTERMATH",L.SEVENK="7K",L.CETUS="CETUS",L.FLOWX="FLOWX",L);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 h(i,new m(e),_.PERCENTAGE,1e6*n,!0)}async getTradeRoute({coinInAmount:e,coinInType:t,coinOutType:n,tradeFee:i}){let r=new f("mainnet",this._config.flowxApiKey);try{return await 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 C(i,"Pool object not found or has no content"),C("moveObject"===i.dataType,"Object is not a Move object"),i}function el(e,t){let n=BigInt(e),i=BigInt(1e4*Number(t));if(i===BigInt(0))return[n.toString()];let r=n*i/BigInt(1e4);return[(n-r).toString(),r.toString()]}function ec(e,t){if(!t||0>=Number(t))return BigInt(e);let n=BigInt(e),i=BigInt(1e4*Number(t));if(i===BigInt(0))return n;let r=n*i/BigInt(1e4);return n-r}async function ed(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(1e4*Number(i));return a*(BigInt(1e4)+s)/BigInt(1e4)}(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}},(k=W||(W={})).PACKAGE_ID_V4="0x7e6aa6e179466ab2814425a780b122575296d011119fa69d27f289f5a28814bd",k.MEMEZ_AV_OBJECT_ID="0x2319e3e76dfad73d8f4684bdbf42be4f32d8ce4521dd61becc8261dc918d82c0",((R=J||(J={})).U64||(R.U64={})).mulDivUp=function(e,t,n){let i=BigInt(0);return e*t%n>BigInt(0)&&(i=BigInt(1)),e*t/n+i};var eg=V||(V={});function ep(e){return C(BigInt(e)<=BigInt(1e4),"Bps overflow"),BigInt(e)}eg.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},eg.sub=function(e,t){return C(BigInt(e.pos0)>=BigInt(t.pos0),"Bps underflow"),{pos0:(BigInt(e.pos0)-BigInt(t.pos0)).toString()}},eg.value=function(e){return BigInt(e.pos0)},eg.new_=function(e){return{pos0:ep(e).toString()}},eg.assertOverflow=ep,((E=X||(X={})).MemezFun||(E.MemezFun={})).isSniperProtectedMemezFun=async function(e,t){return(await es(e,t)).public_key.length>0},(P=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 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")},(E.MemezBurner||(E.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_(J.U64.mulDivUp(V.value(e.fee.fields),J.U64.mulDivUp(t,n,BigInt(e.target_liquidity)),n))},(j=E.MemezPump||(E.MemezPump={})).getPumpState=async function(e,t){return await es(e,t.inner_state)},j.pump=function(e,t){let n=e.constant_product.fields,i=E.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=E.MemezFees.takeWithDiscount(n.meme_swap_fee,s,n.meme_referrer_fee.fields);return s-u},j.dump=function(e,t){let n=e.constant_product.fields,i=E.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=E.MemezBurner.calculate(n.burner.fields,a),l=V.calcUp(u,r),c=r-(V.value(u)!==BigInt(0)?l:BigInt(0)),d=(s+a)*c/(o+c);d>a&&(d=a);let g=E.MemezFees.takeWithDiscount(n.quote_swap_fee,d,n.quote_referrer_fee.fields);return d-g},(D=Y||(Y={})).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=ec(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 ec(X.MemezPump.dump(a,n),r)};let ef="0x2::sui::SUI",em="0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",eh="0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN",e_="0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",eA="0x9258181f5ceac8dbffb7030890243caed69a9599d2886d957a9cb7656af3bdb3",eC="0x0000000000000000000000000000000000000000000000000000000000000006",eI=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",l=[],c=[];for(let e of s)if(u=(BigInt(e.balance)+BigInt(u)).toString(10),l.push(e.coinObjectId),c.push(e),BigInt(u)>=BigInt(n))break;return{objectIds:l,balance:u,objectCoins:c}};async function eb(e,t){let{account:n,amount:i,splits:o,coinType:a,inheritTx:s,inspecTransaction:u,isSponsored:l=!1}=e,c=s??new r,{objectIds:d}=await eI(t,n,i,a),g=d[0];if(b(a)===b(em)&&!l){let e;return u?(d.length>1&&c.mergeCoins(c.object(g),d.slice(1).map(e=>c.object(e))),e=c.splitCoins(c.object(g),o)):e=c.splitCoins(c.gas,o),{tx:c,coinData:e}}d.length>1&&c.mergeCoins(c.object(g),d.slice(1).map(e=>c.object(e)));let p=c.splitCoins(c.object(g),o);return{tx:c,coinData:p}}let ey="0x62412b7268c35f3808336aee57a52836501f40b8ba5d936f8ad275e672befd04";async function eT(e,t){let n,i,{inputAmount:o,accountAddress:a,frontendFee:s,frontendFeeRecipient:u,extendTx:l,isSponsored:c}=e;C(e.inCoinType===em||e.inCoinType===ef,"Input must be SUI");let{tx:d,coinIn:g}=l||{},p=el(o,s||"0"),f=d||new r;if(g)n=f.splitCoins(g,p),Z.transferOrDestroyZeroCoin(f,em,g,a);else{let{coinData:e}=await eb({account:a,amount:o,splits:p,coinType:em,inheritTx:f,isSponsored:c||!1},t);n=e}if(s&&u){let[e,t]=n;i=e,f.transferObjects([t],f.pure.address(u||a))}else[i]=n;return{tx:f,coinOut:i}}async function ew(e,t,n){if(C(t.outCoinType===em||t.outCoinType===ef,"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:`${ey}::math::mul_div_u64`,typeArguments:[],arguments:[i,e.pure.u64(BigInt(1e4*Number(t.frontendFee||"0"))),e.pure.u64(BigInt(1e4))]}),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}}(Z||(Z={})).transferOrDestroyZeroCoin=function(e,t,n,i){e.moveCall({target:`${ey}::utils::transfer_or_destroy`,typeArguments:[t],arguments:[n,e.pure.address(i)]})};var eB=H||(H={});async function ev(e){let t=e||new r;return t.moveCall({target:`${W.PACKAGE_ID_V4}::memez_allowed_versions::get_allowed_versions`,arguments:[t.object(W.MEMEZ_AV_OBJECT_ID)],typeArguments:[]})}eB.getAllowedVersions=ev,eB.buildBuyTx=async function(e,t){C(!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 eT(e,t);C(i,"Coin out is required");let r=n.moveCall({target:`${W.PACKAGE_ID_V4}::memez_pump::pump`,typeArguments:[e.outCoinType,em],arguments:[n.object(e.poolId),i,n.pure.vector("address",[]),n.pure.vector("vector<u8>",[]),n.pure.u64(e.minAmountOut),await ev(n)]});return{tx:n,coinOut:r}},eB.buildSellTx=async function(e,t){C(e.outCoinType===em||e.outCoinType===ef,"Output must be SUI");let n=await es(t,e.poolId),{tx:i,coinData:r}=await eb({amount:e.inputAmount,coinType:e.inCoinType,inheritTx:e.extendTx?.tx,account:e.accountAddress,splits:[e.inputAmount]},t),[o]=r,[a]=i.moveCall({target:`${W.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 ev(i)]});return await ew(i,e,a)};let eO=new y({network:T.MAINNET,fullNodeUrl:B("mainnet")});function eF(){return eO}async function eS(e,t){let{inheritTx:n,sender:i,feeAmount:o,suiInputAmount:a}=e,s=n||new r;s.setGasBudget(o);let{objectCoins:u}=await eI(t,i,(BigInt(a||"0")+o).toString(),em);return s.setGasPayment(u.map(e=>({objectId:e.coinObjectId,version:e.version,digest:e.digest}))),s}(M=Q||(Q={})).getCurveAmountAfterBuy=async function(e){let{suiAmount:t,poolId:n,frontendFee:i}=e;t=ec(t,i);let{memeAmountOut:r}=await eF().quotePump({pool:n,amount:t});return r},M.getSuiAmountAfterSell=async function(e){let{curveAmount:t,poolId:n,frontendFee:i}=e,{quoteAmountOut:r}=await eF().quoteDump({pool:n,amount:t});return ec(r,i)};var ex=ee||(ee={});async function ek(e,t){let{tx:n,coinOut:i}=await eT(e,t);C(i,"Coin out is required");let{memeCoin:r,tx:o}=await eF().pump({pool:e.poolId,quoteCoin:i,minAmountOut:e.minAmountOut,tx:n});return{tx:o,coinOut:r}}async function eR(e,t){C(e.outCoinType===em||e.outCoinType===ef,"Output must be SUI");let{tx:n,coinData:i}=await eb({amount:e.inputAmount,coinType:e.inCoinType,inheritTx:e.extendTx?.tx,account:e.accountAddress,splits:[e.inputAmount]},t),[r]=i,{quoteCoin:o,tx:a}=await eF().dump({pool:e.poolId,memeCoin:r,tx:n,minAmountOut:e.minAmountOut});return await ew(a,e,o)}ex.buildBuyTx=ek,ex.buildSellTx=eR,ex.getBuyTransaction=async function({coinInAmount:e,coinInType:t,coinOutType:n,poolId:i,slippage:r,walletAddress:a,tradeFee:s},u){C(t===ef,"coinInType must be SUI for buy transaction"),C(n!==t,"coinOutType must be different from coinInType"),C(r>=0&&r<1,"slippage must be between 0 (inclusive) and 1 (exclusive)"),C(e>0,"coinInAmount must be greater than 0");let l=BigInt(new o((await Q.getCurveAmountAfterBuy({poolId:i,suiAmount:e,frontendFee:s?s.tradeFeePercent:void 0})).toString()).multipliedBy(1-r).toFixed(0,3)),{tx:c,coinOut:d}=await ek({accountAddress:a,inCoinType:t,outCoinType:n,inputAmount:e.toString(),minAmountOut:l.toString(),poolId:i,frontendFee:s?s.tradeFeePercent:void 0,frontendFeeRecipient:s?s.tradeFeeRecipientAddress:void 0,extendTx:void 0,isSponsored:!1},u);C(d,"Coin out is required"),c.transferObjects([d],c.pure.address(a)),c.setSender(a);let g=await ed(u,c,a,0);return(c=await eS({inheritTx:c,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){C(n===ef,"coinOutType must be SUI for sell transaction"),C(n!==t,"coinOutType must be different from coinInType"),C(r>=0&&r<1,"slippage must be between 0 (inclusive) and 1 (exclusive)"),C(e>0,"coinInAmount must be greater than 0");let l=BigInt(new o((await Q.getSuiAmountAfterSell({poolId:i,curveAmount:e,frontendFee:s?s.tradeFeePercent:void 0})).toString()).multipliedBy(1-r).toFixed(0,3)),{tx:c,coinOut:d}=await eR({accountAddress:a,inCoinType:t,outCoinType:n,inputAmount:e.toString(),minAmountOut:l.toString(),poolId:i,frontendFee:s?s.tradeFeePercent:void 0,frontendFeeRecipient:s?s.tradeFeeRecipientAddress:void 0,extendTx:void 0,isSponsored:!1},u);C(d,"Coin out is required"),c.transferObjects([d],c.pure.address(a)),c.setSender(a);let g=await ed(u,c,a,0);return(c=await eS({inheritTx:c,sender:a,feeAmount:g},u)).build({client:u})};var eE=((N={}).BLAST_FUN="BLAST_FUN",N.MOONBAGS="MOONBAGS",N);(U=et||(et={})).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),(G=(K=en||(en={})).Curves||(K.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=K.Moonbags||(K.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),l=K.Curves.calculateRemoveLiquidityReturn(a,s,n),c=s-(o||u),d=l,g=n;l>c&&(d=c,g=K.Curves.calculateAddLiquidityCost(a,s,c)+BigInt(1));let p=g*BigInt(r.platform_fee)/et.FEE_DENOMINATOR;return C(t>=g+p,"Input amount is less than used SUI + fee"),{receivedCurve:d,receivedSui:t-g-p}},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=K.Curves.calculateRemoveLiquidityReturn(o,r,t);s>a&&(s=a);let u=s*BigInt(i.platform_fee)/et.FEE_DENOMINATOR,l=s-u;return{receivedCurve:BigInt(0),receivedSui: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=ec(n,r));let u=n*et.FEE_DENOMINATOR/(et.FEE_DENOMINATOR+BigInt(a.platform_fee)),{receivedCurve:l}=en.Moonbags.buyExactInReturnsWithLock({inputAmount:n,amountIn:u,pool:o,config:a,dynamicVirtualTokenReserves:s});return 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?ec(s,r):s},$.getUsedSuiForTx=async function(e,t){let{suiAmount:n,frontendFee:i}=e,r=await es(t,et.CONFIG_OBJECT_ID);return void 0!==i&&(n=ec(n,i)),n*et.FEE_DENOMINATOR/(et.FEE_DENOMINATOR+BigInt(r.platform_fee))};var eP=er||(er={});async function ej(e,t){let{tx:n,coinOut:i}=await eT(e,t);C(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(eA),n.object(eC)]});return Z.transferOrDestroyZeroCoin(n,em,o,e.accountAddress),{tx:n,coinOut:a}}async function eD(e,t){C(e.outCoinType===em||e.outCoinType===ef,"Output must be SUI");let{tx:n,coinData:i}=await eb({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(eC)]});return Z.transferOrDestroyZeroCoin(n,e.inCoinType,a,e.accountAddress),await ew(n,e,o)}function eM(e){return e}function eN(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}})}eP.buildBuyTx=ej,eP.buildSellTx=eD,eP.getBuyTransaction=async function({coinInAmount:e,coinInType:t,coinOutType:n,poolId:i,slippage:r,walletAddress:a,tradeFee:s},u){C(t===ef,"coinInType must be SUI for buy transaction"),C(n!==t,"coinOutType must be different from coinInType"),C(r>=0&&r<1,"slippage must be between 0 (inclusive) and 1 (exclusive)"),C(e>0,"coinInAmount must be greater than 0");let l=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:c,coinOut:d}=await ej({accountAddress:a,inCoinType:t,outCoinType:n,inputAmount:e.toString(),minAmountOut:l.toString(),poolId:i,frontendFee:s?s.tradeFeePercent:void 0,frontendFeeRecipient:s?s.tradeFeeRecipientAddress:void 0,extendTx:void 0,isSponsored:!1},u);C(d,"Coin out is required"),c.transferObjects([d],c.pure.address(a)),c.setSender(a);let g=await ed(u,c,a,0);return(c=await eS({inheritTx:c,sender:a,feeAmount:g,suiInputAmount:e},u)).build({client:u})},eP.getSellTransaction=async function({coinInAmount:e,coinInType:t,coinOutType:n,poolId:i,slippage:r,walletAddress:a,tradeFee:s},u){C(n===ef,"coinOutType must be SUI for sell transaction"),C(n!==t,"coinOutType must be different from coinInType"),C(r>=0&&r<1,"slippage must be between 0 (inclusive) and 1 (exclusive)"),C(e>0,"coinInAmount must be greater than 0");let l=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:c,coinOut:d}=await eD({accountAddress:a,inCoinType:t,outCoinType:n,inputAmount:e.toString(),minAmountOut:l.toString(),poolId:i,frontendFee:s?s.tradeFeePercent:void 0,frontendFeeRecipient:s?s.tradeFeeRecipientAddress:void 0,extendTx:void 0,isSponsored:!1},u);C(d,"Coin out is required"),c.transferObjects([d],c.pure.address(a)),c.setSender(a);let g=await ed(u,c,a,0);return(c=await eS({inheritTx:c,sender:a,feeAmount:g},u)).build({client:u})};class eK{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 F({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 x({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);if(!e)return null;let i=F.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=x.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}}async getAmountOut(e,t){let n=await this.getTradeRoute(e,t);return n?n.route.amountOut:null}async getBestAmountOut(e){let t=Object.keys(eo),n=null,i=null;for(let r of t){let t=await this.getAmountOut(r,e);null!==t&&(null===n||t>n)&&(n=t,i=r)}return null===n||null===i?null:{amountOut:n,aggregator:i}}}let eG="0x25fa0eb553dd69fa6a8028f73a38f1df7f289fa88a58ed3d7dc5a5360155bb19",eq="0x8b1a8ac6e34688cd8f8f8e5fefa9d5fb9e1ff74d2f132f8e208ae5ac9cc530bb",e$="0x13d101f44a0710a5475bec5f492a87b80e03d92d1cf540f26096f65850b23d26";class eL{sdk;constructor(e){this.sdk=e}async getConfig(){let e=await this.sdk.suiClient.getObject({id:eq,options:{showContent:!0}});C(e.data?.content,"Config object not found or has no content"),C(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();C(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:`${eG}::boosting::pay`,typeArguments:[b(n)],arguments:[s.object(eq),s.pure.u64(t),u]}),s.setSender(e);let l=await ed(this.sdk.suiClient,s,e,0);return eS({inheritTx:s,sender:e,feeAmount:l},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:`${eG}::config::add_tier`,typeArguments:[],arguments:[u.object(eq),u.object(e$),u.pure.u64(t),u.pure.u64(i),u.pure.u64(n),u.pure.u64(o),u.pure.u64(a)]}),u.setSender(e);let l=await ed(this.sdk.suiClient,u,e,0);return eS({inheritTx:u,sender:e,feeAmount:l},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:`${eG}::config::update_tier`,typeArguments:[],arguments:[u.object(eq),u.object(e$),u.pure.u64(t),u.pure.u64(n),u.pure.u64(i),u.pure.u64(a),u.pure.u64(o)]}),u.setSender(e);let l=await ed(this.sdk.suiClient,u,e,0);return eS({inheritTx:u,sender:e,feeAmount:l},this.sdk.suiClient)}async buildRemoveTierTx({adminAddress:e,tierId:t,currentTx:n}){let i=n||new r;i.moveCall({target:`${eG}::config::remove_tier`,typeArguments:[],arguments:[i.object(eq),i.object(e$),i.pure.u64(t)]}),i.setSender(e);let o=await ed(this.sdk.suiClient,i,e,0);return eS({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:`${eG}::config::update_fee_receiver`,typeArguments:[],arguments:[i.object(eq),i.object(e$),i.pure.address(t)]}),i.setSender(e);let o=await ed(this.sdk.suiClient,i,e,0);return eS({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:`${eG}::boosting::pay_with_admin`,typeArguments:[b(i)],arguments:[a.object(e$),a.object(eq),a.pure.u64(t),a.pure.u64(n),s]}),a.setSender(e);let u=await ed(this.sdk.suiClient,a,e,0);return eS({inheritTx:a,sender:e,feeAmount:u},this.sdk.suiClient)}}class ez{sdk;constructor(e){this.sdk=e}async getTradeTransaction(e,t){let n,{coinInType:i,coinOutType:r}=t;C(i!==r,"coinInType and coinOutType must be different"),C(i===ef||r===ef,"One of coinInType or coinOutType must be SUI");let o=i===ef;switch(e){case eE.MOONBAGS:n=o?await er.getBuyTransaction(t,this.sdk.suiClient):await er.getSellTransaction(t,this.sdk.suiClient);break;case eE.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="0xaedb9a4330883c91769c99e7d2a7ea573b686504daf11d13353141260736a902",eJ="0xe88e0d6792c2bef3f54d594ef26d8df85c6227f5370c200b860d8264f5d78744",eV="0x4d15fc6c181efbe82020697705d37b29154edecb4c682b502bd8f0136d4dd7bf",eX="0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC";class eY{sdk;constructor(e){this.sdk=e}async getConfig(){let e=await this.sdk.suiClient.getObject({id:eJ,options:{showContent:!0}});C(e.data,"Config object not found"),C(e.data.content,"Config object has no content"),C(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.paused,o=t.accepted_payment_type,a=t.plans.fields.contents,s={};for(let e of a){let t=e.fields.key,n=e.fields.value.fields.id,i=e.fields.value.fields.price,r=e.fields.value.fields.month_interval,o=e.fields.value.fields.ptype;s[t]={id:BigInt(n),price:BigInt(i),monthInterval:r,planType:o}}return{id:n,plans:s,feeReceiverWallet:i,paused:r,acceptedPaymentType:o}}async buildSubscribeCyclePlanTx({walletAddress:e,planId:t,reference:n,paymentCoinType:i=eX,currentTx:r}){let o=await this.getConfig();C(!o.paused,"Contract is paused"),C(t in o.plans,"Invalid plan ID");let a=o.plans[t].price,{tx:s,coinData:u}=await eb({account:e,amount:a.toString(),splits:[a.toString()],coinType:i,inheritTx:r},this.sdk.suiClient);s.moveCall({target:`${eW}::subscription::subscribe_cycle_plan`,typeArguments:[i],arguments:[s.object(eJ),s.pure.u64(t),s.pure.string(n),u]}),s.setSender(e);let l=await ed(this.sdk.suiClient,s,e,0);return eS({inheritTx:s,sender:e,feeAmount:l},this.sdk.suiClient)}async buildUpgradeCyclePlanTx({walletAddress:e,currentPlanId:t,targetPlanId:n,reference:i,isNextCycle:r,paymentCoinType:o=eX,currentTx:a}){let s=await this.getConfig();C(!s.paused,"Contract is paused"),C(t in s.plans,"Invalid current plan ID"),C(n in s.plans,"Invalid target plan ID"),C(t!==n,"Current and target plan IDs must be different");let u=s.plans[n].price,{tx:l,coinData:c}=await eb({account:e,amount:u.toString(),splits:[u.toString()],coinType:o,inheritTx:a},this.sdk.suiClient);l.moveCall({target:`${eW}::subscription::upgrade_cycle_plan`,typeArguments:[o],arguments:[l.object(eJ),l.pure.u64(t),l.pure.u64(n),l.pure.string(i),l.pure.bool(r),c]}),l.setSender(e);let d=await ed(this.sdk.suiClient,l,e,0);return eS({inheritTx:l,sender:e,feeAmount:d},this.sdk.suiClient)}async buildBuyMoreCUPlanTx({walletAddress:e,planId:t,reference:n,paidAmount:i,paymentCoinType:r=eX,currentTx:o}){let a=await this.getConfig();C(!a.paused,"Contract is paused"),C(t in a.plans,"Invalid plan ID");let{tx:s,coinData:u}=await eb({account:e,amount:i.toString(),splits:[i.toString()],coinType:r,inheritTx:o},this.sdk.suiClient);s.moveCall({target:`${eW}::subscription::buy_more_cu`,typeArguments:[r],arguments:[s.object(eJ),s.pure.u64(t),s.pure.string(n),s.pure.u64(i),u]}),s.setSender(e);let l=await ed(this.sdk.suiClient,s,e,0);return eS({inheritTx:s,sender:e,feeAmount:l},this.sdk.suiClient)}async buildSubscribePlanWithAdminTx({walletAddress:e,planId:t,reference:n,customAmount:i,paymentCoinType:r=eX,currentTx:o}){C(!(await this.getConfig()).paused,"Contract is paused");let{tx:a,coinData:s}=await eb({account:e,amount:i.toString(),splits:[i.toString()],coinType:r,inheritTx:o},this.sdk.suiClient);a.moveCall({target:`${eW}::subscription::subscribe_plan_with_admin`,typeArguments:[r],arguments:[a.object(eV),a.object(eJ),a.pure.u64(t),a.pure.string(n),a.pure.u64(i),s]}),a.setSender(e);let u=await ed(this.sdk.suiClient,a,e,0);return eS({inheritTx:a,sender:e,feeAmount:u},this.sdk.suiClient)}async buildAddPlanTx({adminAddress:e,planId:t,planType:n,monthInterval:i,price:o,currentTx:a}){let s=a||new r;s.moveCall({target:`${eW}::config::add_plan`,typeArguments:[],arguments:[s.object(eJ),s.object(eV),s.pure.u64(t),s.pure.u8(n),s.pure.u8(i),s.pure.u64(o)]}),s.setSender(e);let u=await ed(this.sdk.suiClient,s,e,0);return eS({inheritTx:s,sender:e,feeAmount:u},this.sdk.suiClient)}async buildUpdatePlanTx({adminAddress:e,planId:t,planType:n,monthInterval:i,price:o,currentTx:a}){let s=a||new r;s.moveCall({target:`${eW}::config::update_plan`,typeArguments:[],arguments:[s.object(eJ),s.object(eV),s.pure.u64(BigInt(t)),s.pure.u8(n),s.pure.u8(i),s.pure.u64(o)]}),s.setSender(e);let u=await ed(this.sdk.suiClient,s,e,0);return eS({inheritTx:s,sender:e,feeAmount:u},this.sdk.suiClient)}async buildRemovePlanTx({adminAddress:e,planId:t,currentTx:n}){let i=n||new r;i.moveCall({target:`${eW}::config::remove_plan`,typeArguments:[],arguments:[i.object(eJ),i.object(eV),i.pure.u64(BigInt(t))]}),i.setSender(e);let o=await ed(this.sdk.suiClient,i,e,0);return eS({inheritTx:i,sender:e,feeAmount:o},this.sdk.suiClient)}async buildUpdateFeeReceiverWalletTx({adminAddress:e,newFeeReceiverWallet:t,currentTx:n}){let i=n||new r;i.moveCall({target:`${eW}::config::update_fee_receiver`,typeArguments:[],arguments:[i.object(eJ),i.object(eV),i.pure.address(t)]}),i.setSender(e);let o=await ed(this.sdk.suiClient,i,e,0);return eS({inheritTx:i,sender:e,feeAmount:o},this.sdk.suiClient)}async buildSetPausedTx({adminAddress:e,paused:t,currentTx:n}){let i=n||new r;i.moveCall({target:`${eW}::config::set_paused`,typeArguments:[],arguments:[i.object(eJ),i.object(eV),i.pure.bool(t)]}),i.setSender(e);let o=await ed(this.sdk.suiClient,i,e,0);return eS({inheritTx:i,sender:e,feeAmount:o},this.sdk.suiClient)}async buildSetAcceptedPaymentTypeTx({adminAddress:e,paymentCoinType:t,currentTx:n}){let i=n||new r;i.moveCall({target:`${eW}::config::set_accepted_payment_type`,typeArguments:[t],arguments:[i.object(eJ),i.object(eV)]}),i.setSender(e);let o=await ed(this.sdk.suiClient,i,e,0);return eS({inheritTx:i,sender:e,feeAmount:o},this.sdk.suiClient)}}class eZ{_suiClient;boostingModule;subscriptionModule;constructor(){this._suiClient=new w({url:B("mainnet")}),this.subscriptionModule=new eY(this),this.boostingModule=new eL(this)}get suiClient(){return this._suiClient}}let eH={tradeFeePercent:.01,tradeFeeRecipientAddress:"0xdaf1c8ed29d89cd8f217f609bad0a668fa6f158c12000bfa5f93e670c99e24ff"};class eQ{options;_suiClient;aggregatorModule;curveModule;constructor(e){this.options=e,this._suiClient=new w({url:B("mainnet")}),this.aggregatorModule=new eK(this),this.curveModule=new ez(this)}get suiClient(){return this._suiClient}}class e0{suiClient;constructor(e){this.suiClient=e}validatePrivateKey(e,t){C(e?.trim(),"Private key is required");let n=v.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){C(e?.trim(),"Sender address is required"),C(t?.trim(),"Recipient address is required"),C(e!==t,"Sender and recipient cannot be the same"),C(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 ed(this.suiClient,i,e,.1);i=await eS({inheritTx:i,sender:e,feeAmount:s,suiInputAmount:n},this.suiClient);let u=await i.build({client:this.suiClient}),l=Buffer.from(u).toString("base64"),c=await i.getDigest();return{sender:e,recipient:t,amountMIST:n,txDraftBase64:l,txDigest:c}}catch(e){throw Error(`Failed to create draft transaction: ${e instanceof Error?e.message:"Unknown error"}`)}}async execute(e,t){try{C(e,"Draft transaction is required"),C(e.txDraftBase64?.trim(),"Transaction data is required");let n=this.validatePrivateKey(t,e.sender),i=I(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){C(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"}}}var e1=1e4;export{e$ as ADMIN_CAP_ID,F as AftermathAggregator,eK as AggregatorModule,S as AstrosAggregator,ey as BLUEFIN_PACKAGE_ID,eG as BOOSTING_PACKAGE_ID,W as BlastFunConstants,Y as BlastFunCustomCalculation,H as BlastFunCustomTransaction,X as BlastFunPackage,Q as BlastFunSDKCalculation,ee as BlastFunSDKTransaction,Z as BluefinTx,eL as BoostingModule,V as Bps,eC as CLOCK_OBJECT_ID,eq as CONFIG_ID,x as CetusAggregator,ez as CurveModule,eH as DEFAULT_TRADE_FEE,e0 as DraftTransferTx,ea as FlowXAggregator,J as MathUtils,ei as MoonbagsCalculation,et as MoonbagsConstants,en as MoonbagsPackage,er as MoonbagsTransaction,e_ as NATIVE_USDC_TOKEN_TYPE,eZ as NoodlesPaySdk,eQ as NoodlesSdk,eX as PAYMENT_COIN_TYPE,eV as SUBSCRIPTION_ADMIN_CAP_ID,eJ as SUBSCRIPTION_CONFIG_ID,eW as SUBSCRIPTION_PACKAGE_ID,em as SUI_FULL_TYPE,eA as SUI_METADATA_OBJECT_ID,ef as SUI_TYPE,O as SevenKAggregator,eY as SubscriptionModule,eo as SupportedAggregator,eE as SupportedBondingCurve,z as TradeFeeOptions,eh as USDC_TOKEN_TYPE,eM as adaptSuiClient,eN as adaptTransaction,eS as addGasFee,eU as createCompatibleSuiClient,ec as getAmountAfterFee,eI as getCoinObjectIdsByAmount,eF as getMemezPumpSDK,eu as getMoveObject,es as getMoveObjectContent,ed as getNeededGasFee,eb as getSplitCoinForTx,el as getSplitCoinsAfterFee,eT as splitSuiCoinAfterFeeFromBuyTx,ew as splitSuiCoinAfterFeeFromSellTx,e1 as BASE_BPS};
|
package/dist/pay.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const __rslib_import_meta_url__="u"<typeof document?new(require("url".replace("",""))).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href;var __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=>{"u">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__,{ADMIN_CAP_ID:()=>ADMIN_CAP_ID,CONFIG_ID:()=>CONFIG_ID,BOOSTING_PACKAGE_ID:()=>BOOSTING_PACKAGE_ID,SUBSCRIPTION_PACKAGE_ID:()=>SUBSCRIPTION_PACKAGE_ID,SUBSCRIPTION_ADMIN_CAP_ID:()=>SUBSCRIPTION_ADMIN_CAP_ID,SUBSCRIPTION_CONFIG_ID:()=>SUBSCRIPTION_CONFIG_ID,SubscriptionModule:()=>SubscriptionModule,PAYMENT_COIN_TYPE:()=>PAYMENT_COIN_TYPE,BoostingModule:()=>BoostingModule,NoodlesPaySdk:()=>NoodlesPaySdk});const tiny_invariant_namespaceObject=require("@minswap/tiny-invariant");var tiny_invariant_default=__webpack_require__.n(tiny_invariant_namespaceObject);const transactions_namespaceObject=require("@mysten/sui/transactions"),utils_namespaceObject=require("@mysten/sui/utils"),BASE_BPS=1e4;function getSplitCoinsAfterFee(e,t){let n=BigInt(e),i=BigInt(1e4*Number(t));if(i===BigInt(0))return[n.toString()];let a=n*i/BigInt(1e4);return[(n-a).toString(),a.toString()]}function getAmountAfterFee(e,t){if(!t||0>=Number(t))return BigInt(e);let n=BigInt(e),i=BigInt(1e4*Number(t));if(i===BigInt(0))return n;let a=n*i/BigInt(1e4);return n-a}async function getNeededGasFee(e,t,n,i){let{effects:{gasUsed:a,status:s}}=await e.devInspectTransactionBlock({sender:n,transactionBlock:t});if("success"!==s.status)throw Error(`Transaction failed during dev inspect: ${s.error??""}`);let r=BigInt(a.computationCost)+BigInt(a.storageCost)-BigInt(a.storageRebate),_=BigInt(1e4*Number(i));return r*(BigInt(1e4)+_)/BigInt(1e4)}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",orderByKey=(e,t,n)=>{let i;if(e?.length){do{i=!1;for(let a=0;a<e.length-1;a++){let s=BigInt(e[a][t]),r=BigInt(e[a+1][t]);if("desc"===n?s<r:s>r){let t=e[a];e[a]=e[a+1],e[a+1]=t,i=!0}}}while(i);return e}},getCoinObjectIdsByAmount=async(e,t,n,i)=>{let a,s=[],r=!0;for(;r;)try{let n=await e.getCoins({owner:t,coinType:i,cursor:a});s=[...s,...n.data],r=n.hasNextPage,a=n.nextCursor}catch(e){console.error("Error fetching data:",e),r=!1}let _=orderByKey(s.map(e=>({...e,balance:e.balance})),"balance","desc")??[],o="0",u=[],d=[];for(let e of _)if(o=(BigInt(e.balance)+BigInt(o)).toString(10),u.push(e.coinObjectId),d.push(e),BigInt(o)>=BigInt(n))break;return{objectIds:u,balance:o,objectCoins:d}};async function addGasFee(e,t){let{inheritTx:n,sender:i,feeAmount:a,suiInputAmount:s}=e,r=n||new transactions_namespaceObject.Transaction;r.setGasBudget(a);let{objectCoins:_}=await getCoinObjectIdsByAmount(t,i,(BigInt(s||"0")+a).toString(),SUI_FULL_TYPE);return r.setGasPayment(_.map(e=>({objectId:e.coinObjectId,version:e.version,digest:e.digest}))),r}const BOOSTING_PACKAGE_ID="0x25fa0eb553dd69fa6a8028f73a38f1df7f289fa88a58ed3d7dc5a5360155bb19",CONFIG_ID="0x8b1a8ac6e34688cd8f8f8e5fefa9d5fb9e1ff74d2f132f8e208ae5ac9cc530bb",ADMIN_CAP_ID="0x13d101f44a0710a5475bec5f492a87b80e03d92d1cf540f26096f65850b23d26";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,i=t.fee_receiver,a=t.tiers.fields.contents,s={};for(let e of a){let t=e.fields.key,n=e.fields.value.fields.duration,i=e.fields.value.fields.amount,a=e.fields.value.fields.point,r=e.fields.value.fields.original_amount;s[t]={duration:BigInt(n),amount:BigInt(i),point:BigInt(a),originalAmount:BigInt(r)}}return{id:n,receiverAddress:i,tiers:s}}async buildPayBoostingTx({walletAddress:e,tierId:t,boostingCoinType:n,currentTx:i}){let a=await this.getConfig();tiny_invariant_default()(t in a.tiers,"Invalid tier ID");let s=a.tiers[t].amount,r=i||new transactions_namespaceObject.Transaction,_=r.splitCoins(r.gas,[r.pure.u64(s)]);r.moveCall({target:`${BOOSTING_PACKAGE_ID}::boosting::pay`,typeArguments:[(0,utils_namespaceObject.normalizeStructTag)(n)],arguments:[r.object(CONFIG_ID),r.pure.u64(t),_]}),r.setSender(e);let o=await getNeededGasFee(this.sdk.suiClient,r,e,0);return addGasFee({inheritTx:r,sender:e,feeAmount:o},this.sdk.suiClient)}async buildAddTierTx({adminAddress:e,tierId:t,duration:n,point:i,originalAmount:a,amount:s,currentTx:r}){let _=r||new transactions_namespaceObject.Transaction;_.moveCall({target:`${BOOSTING_PACKAGE_ID}::config::add_tier`,typeArguments:[],arguments:[_.object(CONFIG_ID),_.object(ADMIN_CAP_ID),_.pure.u64(t),_.pure.u64(i),_.pure.u64(n),_.pure.u64(a),_.pure.u64(s)]}),_.setSender(e);let o=await getNeededGasFee(this.sdk.suiClient,_,e,0);return addGasFee({inheritTx:_,sender:e,feeAmount:o},this.sdk.suiClient)}async buildUpdateTierTx({adminAddress:e,tierId:t,duration:n,amount:i,originalAmount:a,point:s,currentTx:r}){let _=r||new transactions_namespaceObject.Transaction;_.moveCall({target:`${BOOSTING_PACKAGE_ID}::config::update_tier`,typeArguments:[],arguments:[_.object(CONFIG_ID),_.object(ADMIN_CAP_ID),_.pure.u64(t),_.pure.u64(n),_.pure.u64(i),_.pure.u64(s),_.pure.u64(a)]}),_.setSender(e);let o=await getNeededGasFee(this.sdk.suiClient,_,e,0);return addGasFee({inheritTx:_,sender:e,feeAmount:o},this.sdk.suiClient)}async buildRemoveTierTx({adminAddress:e,tierId:t,currentTx:n}){let i=n||new transactions_namespaceObject.Transaction;i.moveCall({target:`${BOOSTING_PACKAGE_ID}::config::remove_tier`,typeArguments:[],arguments:[i.object(CONFIG_ID),i.object(ADMIN_CAP_ID),i.pure.u64(t)]}),i.setSender(e);let a=await getNeededGasFee(this.sdk.suiClient,i,e,0);return addGasFee({inheritTx:i,sender:e,feeAmount:a},this.sdk.suiClient)}async buildUpdateFeeReceiver({adminAddress:e,newReceiverAddress:t,currentTx:n}){let i=n||new transactions_namespaceObject.Transaction;i.moveCall({target:`${BOOSTING_PACKAGE_ID}::config::update_fee_receiver`,typeArguments:[],arguments:[i.object(CONFIG_ID),i.object(ADMIN_CAP_ID),i.pure.address(t)]}),i.setSender(e);let a=await getNeededGasFee(this.sdk.suiClient,i,e,0);return addGasFee({inheritTx:i,sender:e,feeAmount:a},this.sdk.suiClient)}async buildPayBoostingWithAdminTx({walletAddress:e,tierId:t,customAmount:n,boostingCoinType:i,currentTx:a}){let s=a||new transactions_namespaceObject.Transaction,r=s.splitCoins(s.gas,[s.pure.u64(n)]);s.moveCall({target:`${BOOSTING_PACKAGE_ID}::boosting::pay_with_admin`,typeArguments:[(0,utils_namespaceObject.normalizeStructTag)(i)],arguments:[s.object(ADMIN_CAP_ID),s.object(CONFIG_ID),s.pure.u64(t),s.pure.u64(n),r]}),s.setSender(e);let _=await getNeededGasFee(this.sdk.suiClient,s,e,0);return addGasFee({inheritTx:s,sender:e,feeAmount:_},this.sdk.suiClient)}}async function getSplitCoinForTx(e,t){let{account:n,amount:i,splits:a,coinType:s,inheritTx:r,inspecTransaction:_,isSponsored:o=!1}=e,u=r??new transactions_namespaceObject.Transaction,{objectIds:d}=await getCoinObjectIdsByAmount(t,n,i,s),c=d[0];if((0,utils_namespaceObject.normalizeStructTag)(s)===(0,utils_namespaceObject.normalizeStructTag)(SUI_FULL_TYPE)&&!o){let e;return _?(d.length>1&&u.mergeCoins(u.object(c),d.slice(1).map(e=>u.object(e))),e=u.splitCoins(u.object(c),a)):e=u.splitCoins(u.gas,a),{tx:u,coinData:e}}d.length>1&&u.mergeCoins(u.object(c),d.slice(1).map(e=>u.object(e)));let l=u.splitCoins(u.object(c),a);return{tx:u,coinData:l}}const SUBSCRIPTION_PACKAGE_ID="0xaedb9a4330883c91769c99e7d2a7ea573b686504daf11d13353141260736a902",SUBSCRIPTION_CONFIG_ID="0xe88e0d6792c2bef3f54d594ef26d8df85c6227f5370c200b860d8264f5d78744",SUBSCRIPTION_ADMIN_CAP_ID="0x4d15fc6c181efbe82020697705d37b29154edecb4c682b502bd8f0136d4dd7bf",PAYMENT_COIN_TYPE="0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC";class SubscriptionModule{sdk;constructor(e){this.sdk=e}async getConfig(){let e=await this.sdk.suiClient.getObject({id:SUBSCRIPTION_CONFIG_ID,options:{showContent:!0}});tiny_invariant_default()(e.data,"Config object not found"),tiny_invariant_default()(e.data.content,"Config object 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,i=t.fee_receiver,a=t.paused,s=t.accepted_payment_type,r=t.plans.fields.contents,_={};for(let e of r){let t=e.fields.key,n=e.fields.value.fields.id,i=e.fields.value.fields.price,a=e.fields.value.fields.month_interval,s=e.fields.value.fields.ptype;_[t]={id:BigInt(n),price:BigInt(i),monthInterval:a,planType:s}}return{id:n,plans:_,feeReceiverWallet:i,paused:a,acceptedPaymentType:s}}async buildSubscribeCyclePlanTx({walletAddress:e,planId:t,reference:n,paymentCoinType:i=PAYMENT_COIN_TYPE,currentTx:a}){let s=await this.getConfig();tiny_invariant_default()(!s.paused,"Contract is paused"),tiny_invariant_default()(t in s.plans,"Invalid plan ID");let r=s.plans[t].price,{tx:_,coinData:o}=await getSplitCoinForTx({account:e,amount:r.toString(),splits:[r.toString()],coinType:i,inheritTx:a},this.sdk.suiClient);_.moveCall({target:`${SUBSCRIPTION_PACKAGE_ID}::subscription::subscribe_cycle_plan`,typeArguments:[i],arguments:[_.object(SUBSCRIPTION_CONFIG_ID),_.pure.u64(t),_.pure.string(n),o]}),_.setSender(e);let u=await getNeededGasFee(this.sdk.suiClient,_,e,0);return addGasFee({inheritTx:_,sender:e,feeAmount:u},this.sdk.suiClient)}async buildUpgradeCyclePlanTx({walletAddress:e,currentPlanId:t,targetPlanId:n,reference:i,isNextCycle:a,paymentCoinType:s=PAYMENT_COIN_TYPE,currentTx:r}){let _=await this.getConfig();tiny_invariant_default()(!_.paused,"Contract is paused"),tiny_invariant_default()(t in _.plans,"Invalid current plan ID"),tiny_invariant_default()(n in _.plans,"Invalid target plan ID"),tiny_invariant_default()(t!==n,"Current and target plan IDs must be different");let o=_.plans[n].price,{tx:u,coinData:d}=await getSplitCoinForTx({account:e,amount:o.toString(),splits:[o.toString()],coinType:s,inheritTx:r},this.sdk.suiClient);u.moveCall({target:`${SUBSCRIPTION_PACKAGE_ID}::subscription::upgrade_cycle_plan`,typeArguments:[s],arguments:[u.object(SUBSCRIPTION_CONFIG_ID),u.pure.u64(t),u.pure.u64(n),u.pure.string(i),u.pure.bool(a),d]}),u.setSender(e);let c=await getNeededGasFee(this.sdk.suiClient,u,e,0);return addGasFee({inheritTx:u,sender:e,feeAmount:c},this.sdk.suiClient)}async buildBuyMoreCUPlanTx({walletAddress:e,planId:t,reference:n,paidAmount:i,paymentCoinType:a=PAYMENT_COIN_TYPE,currentTx:s}){let r=await this.getConfig();tiny_invariant_default()(!r.paused,"Contract is paused"),tiny_invariant_default()(t in r.plans,"Invalid plan ID");let{tx:_,coinData:o}=await getSplitCoinForTx({account:e,amount:i.toString(),splits:[i.toString()],coinType:a,inheritTx:s},this.sdk.suiClient);_.moveCall({target:`${SUBSCRIPTION_PACKAGE_ID}::subscription::buy_more_cu`,typeArguments:[a],arguments:[_.object(SUBSCRIPTION_CONFIG_ID),_.pure.u64(t),_.pure.string(n),_.pure.u64(i),o]}),_.setSender(e);let u=await getNeededGasFee(this.sdk.suiClient,_,e,0);return addGasFee({inheritTx:_,sender:e,feeAmount:u},this.sdk.suiClient)}async buildSubscribePlanWithAdminTx({walletAddress:e,planId:t,reference:n,customAmount:i,paymentCoinType:a=PAYMENT_COIN_TYPE,currentTx:s}){let r=await this.getConfig();tiny_invariant_default()(!r.paused,"Contract is paused");let{tx:_,coinData:o}=await getSplitCoinForTx({account:e,amount:i.toString(),splits:[i.toString()],coinType:a,inheritTx:s},this.sdk.suiClient);_.moveCall({target:`${SUBSCRIPTION_PACKAGE_ID}::subscription::subscribe_plan_with_admin`,typeArguments:[a],arguments:[_.object(SUBSCRIPTION_ADMIN_CAP_ID),_.object(SUBSCRIPTION_CONFIG_ID),_.pure.u64(t),_.pure.string(n),_.pure.u64(i),o]}),_.setSender(e);let u=await getNeededGasFee(this.sdk.suiClient,_,e,0);return addGasFee({inheritTx:_,sender:e,feeAmount:u},this.sdk.suiClient)}async buildAddPlanTx({adminAddress:e,planId:t,planType:n,monthInterval:i,price:a,currentTx:s}){let r=s||new transactions_namespaceObject.Transaction;r.moveCall({target:`${SUBSCRIPTION_PACKAGE_ID}::config::add_plan`,typeArguments:[],arguments:[r.object(SUBSCRIPTION_CONFIG_ID),r.object(SUBSCRIPTION_ADMIN_CAP_ID),r.pure.u64(t),r.pure.u8(n),r.pure.u8(i),r.pure.u64(a)]}),r.setSender(e);let _=await getNeededGasFee(this.sdk.suiClient,r,e,0);return addGasFee({inheritTx:r,sender:e,feeAmount:_},this.sdk.suiClient)}async buildUpdatePlanTx({adminAddress:e,planId:t,planType:n,monthInterval:i,price:a,currentTx:s}){let r=s||new transactions_namespaceObject.Transaction;r.moveCall({target:`${SUBSCRIPTION_PACKAGE_ID}::config::update_plan`,typeArguments:[],arguments:[r.object(SUBSCRIPTION_CONFIG_ID),r.object(SUBSCRIPTION_ADMIN_CAP_ID),r.pure.u64(BigInt(t)),r.pure.u8(n),r.pure.u8(i),r.pure.u64(a)]}),r.setSender(e);let _=await getNeededGasFee(this.sdk.suiClient,r,e,0);return addGasFee({inheritTx:r,sender:e,feeAmount:_},this.sdk.suiClient)}async buildRemovePlanTx({adminAddress:e,planId:t,currentTx:n}){let i=n||new transactions_namespaceObject.Transaction;i.moveCall({target:`${SUBSCRIPTION_PACKAGE_ID}::config::remove_plan`,typeArguments:[],arguments:[i.object(SUBSCRIPTION_CONFIG_ID),i.object(SUBSCRIPTION_ADMIN_CAP_ID),i.pure.u64(BigInt(t))]}),i.setSender(e);let a=await getNeededGasFee(this.sdk.suiClient,i,e,0);return addGasFee({inheritTx:i,sender:e,feeAmount:a},this.sdk.suiClient)}async buildUpdateFeeReceiverWalletTx({adminAddress:e,newFeeReceiverWallet:t,currentTx:n}){let i=n||new transactions_namespaceObject.Transaction;i.moveCall({target:`${SUBSCRIPTION_PACKAGE_ID}::config::update_fee_receiver`,typeArguments:[],arguments:[i.object(SUBSCRIPTION_CONFIG_ID),i.object(SUBSCRIPTION_ADMIN_CAP_ID),i.pure.address(t)]}),i.setSender(e);let a=await getNeededGasFee(this.sdk.suiClient,i,e,0);return addGasFee({inheritTx:i,sender:e,feeAmount:a},this.sdk.suiClient)}async buildSetPausedTx({adminAddress:e,paused:t,currentTx:n}){let i=n||new transactions_namespaceObject.Transaction;i.moveCall({target:`${SUBSCRIPTION_PACKAGE_ID}::config::set_paused`,typeArguments:[],arguments:[i.object(SUBSCRIPTION_CONFIG_ID),i.object(SUBSCRIPTION_ADMIN_CAP_ID),i.pure.bool(t)]}),i.setSender(e);let a=await getNeededGasFee(this.sdk.suiClient,i,e,0);return addGasFee({inheritTx:i,sender:e,feeAmount:a},this.sdk.suiClient)}async buildSetAcceptedPaymentTypeTx({adminAddress:e,paymentCoinType:t,currentTx:n}){let i=n||new transactions_namespaceObject.Transaction;i.moveCall({target:`${SUBSCRIPTION_PACKAGE_ID}::config::set_accepted_payment_type`,typeArguments:[t],arguments:[i.object(SUBSCRIPTION_CONFIG_ID),i.object(SUBSCRIPTION_ADMIN_CAP_ID)]}),i.setSender(e);let a=await getNeededGasFee(this.sdk.suiClient,i,e,0);return addGasFee({inheritTx:i,sender:e,feeAmount:a},this.sdk.suiClient)}}const client_namespaceObject=require("@mysten/sui/client");class NoodlesPaySdk{_suiClient;boostingModule;subscriptionModule;constructor(){this._suiClient=new client_namespaceObject.SuiClient({url:(0,client_namespaceObject.getFullnodeUrl)("mainnet")}),this.subscriptionModule=new SubscriptionModule(this),this.boostingModule=new BoostingModule(this)}get suiClient(){return this._suiClient}}for(var __rspack_i in exports.ADMIN_CAP_ID=__webpack_exports__.ADMIN_CAP_ID,exports.BOOSTING_PACKAGE_ID=__webpack_exports__.BOOSTING_PACKAGE_ID,exports.BoostingModule=__webpack_exports__.BoostingModule,exports.CONFIG_ID=__webpack_exports__.CONFIG_ID,exports.NoodlesPaySdk=__webpack_exports__.NoodlesPaySdk,exports.PAYMENT_COIN_TYPE=__webpack_exports__.PAYMENT_COIN_TYPE,exports.SUBSCRIPTION_ADMIN_CAP_ID=__webpack_exports__.SUBSCRIPTION_ADMIN_CAP_ID,exports.SUBSCRIPTION_CONFIG_ID=__webpack_exports__.SUBSCRIPTION_CONFIG_ID,exports.SUBSCRIPTION_PACKAGE_ID=__webpack_exports__.SUBSCRIPTION_PACKAGE_ID,exports.SubscriptionModule=__webpack_exports__.SubscriptionModule,__webpack_exports__)-1===["ADMIN_CAP_ID","BOOSTING_PACKAGE_ID","BoostingModule","CONFIG_ID","NoodlesPaySdk","PAYMENT_COIN_TYPE","SUBSCRIPTION_ADMIN_CAP_ID","SUBSCRIPTION_CONFIG_ID","SUBSCRIPTION_PACKAGE_ID","SubscriptionModule"].indexOf(__rspack_i)&&(exports[__rspack_i]=__webpack_exports__[__rspack_i]);Object.defineProperty(exports,"__esModule",{value:!0});
|