@gala-chain/launchpad-sdk 3.11.1 โ†’ 3.11.2

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.js CHANGED
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("ethers"),require("axios"),require("@gala-chain/connect"),require("zod"),require("@gala-chain/api"),require("bignumber.js"),require("uuid"),require("socket.io-client")):"function"==typeof define&&define.amd?define(["exports","ethers","axios","@gala-chain/connect","zod","@gala-chain/api","bignumber.js","uuid","socket.io-client"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).GalaLaunchpadSDK={},e.ethers,e.axios,e.GalaChainConnect,e.z,e.GalaChainAPI,e.BigNumber,e.uuid,e.io)}(this,function(e,t,a,n,r,o,s,i,c){"use strict";var l,u;!function(e){e.WALLET_NOT_CONNECTED="WALLET_NOT_CONNECTED",e.SIGNATURE_FAILED="SIGNATURE_FAILED",e.INVALID_ADDRESS="INVALID_ADDRESS",e.MESSAGE_GENERATION_FAILED="MESSAGE_GENERATION_FAILED"}(l||(l={}));class d extends Error{constructor(e,t,a){super(t),this.type=e,this.originalError=a,this.name="AuthError"}}class h{constructor(e){if(this.wallet=e.wallet,this.messagePrefix=e.messagePrefix||"Create a GalaChain Wallet",""===e.messagePrefix)throw new d(l.SIGNATURE_FAILED,"Message prefix cannot be empty");this.validateWallet()}async generateSignature(){try{const e=Date.now(),t=`${this.messagePrefix} ${e}`,a=await this.wallet.signMessage(t);return{message:t,signature:a,address:this.formatAddress(this.wallet.address),timestamp:e}}catch(e){throw new d(l.SIGNATURE_FAILED,"Failed to generate signature for authentication",e instanceof Error?e:new Error(String(e)))}}getAddress(){return this.formatAddress(this.wallet.address)}getEthereumAddress(){return this.wallet.address}formatAddress(e){const t=e.replace(/^0x/i,"");if(!/^[a-fA-F0-9]{40}$/.test(t))throw new d(l.INVALID_ADDRESS,`Invalid Ethereum address format: ${e}`);return`eth|${t}`}async signMessage(e){try{return{message:e,signature:await this.wallet.signMessage(e),address:this.wallet.address,timestamp:Date.now()}}catch(e){const t=e instanceof Error?e.message:String(e);throw new d(l.SIGNATURE_FAILED,t,e instanceof Error?e:new Error(String(e)))}}async generateAuthHeaders(e,t){try{const a=Date.now(),n=`${this.messagePrefix} ${t.toUpperCase()} ${e} ${a}`,r=await this.wallet.signMessage(n);return{"x-signature":r,"x-address":this.formatAddress(this.wallet.address),"x-message":n,"x-timestamp":a.toString()}}catch(e){throw new d(l.SIGNATURE_FAILED,"Failed to generate authentication headers",e instanceof Error?e:new Error(String(e)))}}async signTypedData(e,t,a){try{return await this.wallet.signTypedData(e,t,a)}catch(e){throw new d(l.SIGNATURE_FAILED,"Failed to sign typed data",e instanceof Error?e:new Error(String(e)))}}async generateCustomSignature(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new d(l.SIGNATURE_FAILED,"Custom message must be a non-empty string");try{const t=await this.wallet.signMessage(e);return{message:e,signature:t,address:this.formatAddress(this.wallet.address),timestamp:Date.now()}}catch(e){throw new d(l.SIGNATURE_FAILED,"Failed to generate custom message signature",e instanceof Error?e:new Error(String(e)))}}validateWallet(){if(!this.wallet)throw new d(l.WALLET_NOT_CONNECTED,"Wallet is required for authentication");if(!this.wallet.address)throw new d(l.WALLET_NOT_CONNECTED,"Wallet address is not available");if(!this.wallet.privateKey&&!this.wallet.signMessage)throw new d(l.WALLET_NOT_CONNECTED,"Wallet must have a private key for signing messages")}}!function(e){e.DEBUG="DEBUG",e.INFO="INFO",e.WARN="WARN",e.ERROR="ERROR"}(u||(u={}));class g{constructor(e){this.levelPriority={[u.DEBUG]:0,[u.INFO]:1,[u.WARN]:2,[u.ERROR]:3},this.debugEnabled=e.debug,this.context=e.context||"SDK",this.minLevel=e.minLevel||(e.debug?u.DEBUG:u.INFO)}debug(e,t){this.log(u.DEBUG,e,t)}info(e,t){this.log(u.INFO,e,t)}warn(e,t){this.log(u.WARN,e,t)}error(e,t){this.log(u.ERROR,e,t)}log(e,t,a){if(this.levelPriority[e]<this.levelPriority[this.minLevel])return;if(e===u.DEBUG&&!this.debugEnabled)return;const n=`[${(new Date).toISOString()}] [${this.context}] [${e}]`,r=this.getConsoleMethod(e);void 0!==a?a instanceof Error?r(`${n} ${t}`,a.message,a.stack):r(`${n} ${t}`,a):r(`${n} ${t}`)}getConsoleMethod(e){switch(e){case u.DEBUG:return console.debug;case u.INFO:return console.info;case u.WARN:return console.warn;case u.ERROR:return console.error;default:return console.log}}child(e){return new g({debug:this.debugEnabled,context:`${this.context}:${e}`,minLevel:this.minLevel})}isDebugEnabled(){return this.debugEnabled&&this.levelPriority[u.DEBUG]>=this.levelPriority[this.minLevel]}}function m(e){const t={};for(const[a,n]of Object.entries(e))null!=n&&("string"==typeof n?t[a]=n:"number"==typeof n||"boolean"==typeof n?t[a]=n.toString():Array.isArray(n)?t[a]=n.join(","):t[a]="object"==typeof n?JSON.stringify(n):String(n));return t}class p{constructor(e,t={}){this.auth=e,this.debug=t.debug??!1,this.logger=new g({debug:this.debug,context:"HttpClient"}),this.axios=a.create({baseURL:t.baseUrl||"https://lpad-backend-dev1.defi.gala.com",timeout:t.timeout||3e4,headers:{Accept:"application/json",...t.headers}}),this.setupInterceptors()}async request(e){try{const t={method:e.method,url:e.url,data:e.data,...e.params&&{params:m(e.params)},...e.headers&&{headers:e.headers},...e.timeout&&{timeout:e.timeout}};e.data instanceof FormData&&(t.headers&&t.headers["Content-Type"]&&delete t.headers["Content-Type"],this.logger.debug("FormData detected - removing Content-Type header for multipart upload"));const a=e.data instanceof FormData?"[FormData object - multipart/form-data]":e.data;this.logger.debug("Request:",{method:e.method,url:e.url,fullUrl:`${this.axios.defaults.baseURL}${e.url}`,baseURL:this.axios.defaults.baseURL,params:t.params,data:a,isFormData:e.data instanceof FormData,contentType:t.headers?.["Content-Type"]||"not set"});const n=await this.axios.request(t);return this.logger.debug("Response:",{status:n.status,data:n.data}),n.data}catch(e){throw this.logger.error("Error:",e),e}}async get(e,t,a){return this.request({method:"GET",url:e,...t&&{params:t},...a&&{headers:a}})}async post(e,t,a){return this.request({method:"POST",url:e,data:t,...a&&{headers:a}})}async put(e,t,a){return this.request({method:"PUT",url:e,data:t,...a&&{headers:a}})}async delete(e,t,a){return this.request({method:"DELETE",url:e,...t&&{params:t},...a&&{headers:a}})}async patch(e,t,a){return this.request({method:"PATCH",url:e,data:t,...a&&{headers:a}})}getAddress(){return this.auth.getAddress()}getEthereumAddress(){return this.auth.getEthereumAddress()}async signMessage(e){return(await this.auth.signMessage(e)).signature}async signTypedData(e,t,a){return await this.auth.signTypedData(e,t,a)}async signCustomMessage(e){try{const t=await this.auth.generateCustomSignature(e);return this.logger.debug("Generated custom signature:",{message:e,address:t.address,ethereumAddress:this.auth.getEthereumAddress()}),{signature:t.signature,address:t.address,ethereumAddress:this.auth.getEthereumAddress()}}catch(e){throw this.logger.error("Custom signature generation failed:",e),new Error(`Failed to generate custom signature for message: ${e instanceof Error?e.message:"Unknown error"}`)}}async signWithGalaChain(e,t,a=n.SigningType.SIGN_TYPED_DATA){const r=this.auth.wallet.privateKey;if(!r)throw new Error("Wallet private key not available for @gala-chain signing");const o=new n.SigningClient(r);return await o.sign(e,t,a)}setupInterceptors(){this.requestInterceptorId=this.axios.interceptors.request.use(async e=>{try{const t=await this.auth.generateSignature();return e.headers||(e.headers={}),e.headers.Sign=t.signature,e.data instanceof FormData||(e.headers["Content-Type"]="application/json"),this.logger.debug("Added signature header:",{address:t.address,message:t.message,timestamp:t.timestamp}),e}catch(e){throw this.logger.error("Failed to add signature:",e),e}},e=>Promise.reject(e)),this.responseInterceptorId=this.axios.interceptors.response.use(e=>e,e=>{if(e.response){const t={message:e.response.data?.message||e.message,error:e.response.data?.error,statusCode:e.response.status,details:e.response.data?.details,timestamp:e.response.data?.timestamp,path:e.response.data?.path};e.launchpadError=t,this.logger.error("Backend error:",t)}else e.request?this.logger.error("Network error:",e.message):this.logger.error("Request setup error:",e.message);return Promise.reject(e)})}cleanup(){void 0!==this.requestInterceptorId&&(this.axios.interceptors.request.eject(this.requestInterceptorId),this.requestInterceptorId=void 0),void 0!==this.responseInterceptorId&&(this.axios.interceptors.response.eject(this.responseInterceptorId),this.responseInterceptorId=void 0),this.logger.debug("Interceptors cleaned up")}}const f="Token name is required and must be a string",y=e=>`Could not find vault address for token: ${e}`;class v extends Error{constructor(e,t,a){super(e),this.field=t,this.code=a,this.name="ValidationError"}}class A extends Error{constructor(e,t,a){super(e),this.statusCode=t,this.originalError=a,this.name="NetworkError"}}class w extends Error{constructor(e,t){super(e),this.field=t,this.name="ConfigurationError"}}class T extends Error{constructor(e,t,a){super(e),this.transactionId=t,this.code=a,this.name="TransactionError"}}function k(e,t,a){const{MIN_PAGE:n,MAX_PAGE:r,MIN_LIMIT:o,MAX_LIMIT:s}=a.PAGINATION;if("number"!=typeof e||e<n||e>r)throw new v(`Page must be a number between ${n} and ${r}`,"page","INVALID_PAGE");if("number"!=typeof t||t<o||t>s)throw new v(`Limit must be a number between ${o} and ${s}`,"limit","INVALID_LIMIT")}const N={ETH_ADDRESS:/^0x[0-9a-fA-F]{40}$/,BACKEND_ADDRESS:/^eth\|[0-9a-fA-F]{40}$/};function E(e){return"string"==typeof e&&e.trim().length>0}function S(e){return!(!e||"string"!=typeof e)&&(N.ETH_ADDRESS.test(e)||N.BACKEND_ADDRESS.test(e))}function b(e){return e.startsWith("0x")?`eth|${e.slice(2)}`:e}const I=r.z.string().min(3,"Token name must be at least 3 characters").max(20,"Token name must be at most 20 characters").regex(/^[a-zA-Z0-9]{3,20}$/,"Token name can only contain letters and numbers"),F=r.z.string().min(1,"Token symbol must be at least 1 character").max(8,"Token symbol must be at most 8 characters").regex(/^[A-Z]{1,8}$/,"Token symbol must be uppercase letters only"),C=r.z.string().min(1,"Token description is required").max(500,"Token description must be at most 500 characters"),D=r.z.string().min(1,"Token name must be at least 1 character").max(50,"Token name must be at most 50 characters"),P=r.z.string().min(1,"Search query must be at least 1 character").max(100,"Search query must be at most 100 characters"),_=r.z.string().min(1,"Full name is required").max(100,"Full name must be at most 100 characters").regex(/^[a-zA-Z\s]+$/,"Full name can only contain letters and spaces"),L=r.z.string().regex(N.BACKEND_ADDRESS,"Address must be in format: eth|[40-hex-chars]"),O=r.z.string().regex(N.ETH_ADDRESS,"Invalid Ethereum address format"),x=r.z.string().refine(e=>N.BACKEND_ADDRESS.test(e)||N.ETH_ADDRESS.test(e),"Address must be either eth|[40-hex-chars] or 0x[40-hex-chars] format").transform(e=>e.startsWith("0x")?`eth|${e.slice(2)}`:e),U=r.z.string().refine(e=>N.BACKEND_ADDRESS.test(e)||/^service\|Token\$Unit\$[A-Z0-9]+\$eth:[0-9a-fA-F]{40}\$launchpad$/.test(e),"Invalid vault address format"),$=r.z.string().regex(/^\d+(\.\d+)?$/,"Must be a valid decimal number").refine(e=>parseFloat(e)>0,"Amount must be greater than zero"),B=r.z.string().regex(/^\d+(\.\d+)?$/,"Must be a valid decimal number").refine(e=>parseFloat(e)>=0,"Amount must be zero or greater"),M=r.z.string().regex(/^(?!0+(\.0+)?$)\d+(\.\d+)?$/,"Amount must be a positive, non-zero number"),R=r.z.string().url("Must be a valid URL").regex(/^https?:\/\//,"URL must start with http:// or https://"),K=r.z.string().optional().refine(e=>!e||/^https?:\/\/.+\..+/.test(e),"Must be a valid URL if provided"),G=r.z.number().int("Page must be an integer").min(1,"Page must be at least 1").max(1e3,"Page must be at most 1000").default(1);function z(e=100){return r.z.number().int("Limit must be an integer").min(1,"Limit must be at least 1").max(e,`Limit must be at most ${e}`).default(10)}const V=z(100),q=z(20),j=z(20),W=r.z.number().int("File size must be an integer").min(1,"File must be at least 1 byte").max(10485760,"File must be at most 10MB"),H=r.z.string().max(255,"Filename must be at most 255 characters"),Q=r.z.enum(["image/png","image/jpg","image/jpeg","image/gif","image/webp","image/svg+xml"]),X=r.z.string().min(1,"Comment message is required").max(500,"Comment must be at most 500 characters"),Y=r.z.string().datetime("Must be a valid ISO 8601 date string"),Z=r.z.number().int("Timestamp must be an integer").min(0,"Timestamp must be non-negative"),J=r.z.string().regex(/^0x[a-fA-F0-9]{64}$/,"Private key must be format: 0x + 64 hex characters"),ee=r.z.string().regex(/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/,"Transaction ID must be in UUID format"),te=r.z.string().regex(/^galaconnect-operation-[a-z0-9-]+$/,"Unique key must be format: galaconnect-operation-{unique-id}"),ae=r.z.object({websiteUrl:K,telegramUrl:K,twitterUrl:K}).refine(e=>e.websiteUrl||e.telegramUrl||e.twitterUrl,"At least one social URL (website, telegram, or twitter) is required"),ne=r.z.string().min(1,"Token category must not be empty").default("Unit"),re=r.z.string().min(1,"Token collection must not be empty").default("Token"),oe=r.z.object({minFeePortion:$,maxFeePortion:$}),se=r.z.object({tokenName:I,tokenSymbol:F,tokenDescription:C,tokenImage:r.z.union([r.z.instanceof(File),r.z.instanceof(Buffer),r.z.string().url("Token image must be a valid URL")]).optional(),preBuyQuantity:B.default("0"),websiteUrl:K,telegramUrl:K,twitterUrl:K,tokenCategory:ne,tokenCollection:re,reverseBondingCurveConfiguration:oe.optional(),privateKey:J.optional()}),ie=r.z.object({file:r.z.union([r.z.instanceof(File),r.z.instanceof(Buffer)]),tokenName:I}),ce=r.z.enum(["recent","popular"]),le=r.z.object({tokenName:I.optional(),symbol:F.optional()}).refine(e=>e.tokenName||e.symbol,"At least one of tokenName or symbol is required"),ue=r.z.enum(["NATIVE","MEME"]),de=r.z.enum(["IN","OUT"]),he=r.z.object({from:r.z.number().int("From timestamp must be an integer").min(173e6,"From timestamp must be at least 173000000"),to:r.z.number().int("To timestamp must be an integer").min(173e6,"To timestamp must be at least 173000000"),resolution:r.z.number().int("Resolution must be an integer").min(1,"Resolution must be at least 1"),tokenName:I}),ge=r.z.object({tokenName:I,slippageToleranceFactor:r.z.number().min(0).max(1).optional(),maxAcceptableReverseBondingCurveFeeSlippageFactor:r.z.number().min(0).max(1).optional(),privateKey:J.optional()}),me=[".png",".jpg",".jpeg",".gif",".webp",".svg"],pe=r.z.object({file:r.z.union([r.z.instanceof(File),r.z.instanceof(Buffer)]),name:H,size:W,type:Q}),fe=r.z.instanceof(File).refine(e=>e.size>=1&&e.size<=10485760,"File size must be between 1 byte and 10MB").refine(e=>["image/png","image/jpg","image/jpeg","image/gif","image/webp","image/svg+xml"].includes(e.type),"File must be a valid image type (PNG, JPG, JPEG, GIF, WebP, or SVG)").refine(e=>e.name.length<=255,"Filename must be at most 255 characters"),ye=r.z.instanceof(Buffer).refine(e=>e.length>=1&&e.length<=10485760,"Buffer size must be between 1 byte and 10MB"),ve=r.z.union([fe,ye]),Ae=r.z.enum([".png",".jpg",".jpeg",".gif",".webp",".svg"]),we=H.refine(e=>{const t=e.slice(e.lastIndexOf(".")).toLowerCase();return me.includes(t)},`Filename must end with one of: ${me.join(", ")}`),Te=r.z.object({page:G,limit:V}),ke=r.z.object({page:G,limit:q}),Ne=r.z.object({page:G,limit:j}),Ee=r.z.object({page:G,limit:z(50)}),Se=Te.extend({type:r.z.enum(["recent","popular"]).optional(),tokenName:r.z.string().min(1).max(50).optional(),search:r.z.string().min(1).max(100).optional()}),be=ke.extend({tokenName:r.z.string().min(1).max(50).optional(),search:r.z.string().min(1).max(100).optional()}),Ie=Ne.extend({tradeType:r.z.enum(["BUY","SELL"]).optional(),tokenName:r.z.string().min(1).max(50).optional(),userAddress:r.z.string().regex(/^(0x[a-fA-F0-9]{40}|eth\|[a-fA-F0-9]{40})$/).optional(),startDate:r.z.string().datetime().optional(),endDate:r.z.string().datetime().optional(),sortOrder:r.z.enum(["ASC","DESC"]).default("DESC")}),Fe=r.z.object({page:r.z.number().int().min(1),limit:r.z.number().int().min(1),total:r.z.number().int().min(0),totalPages:r.z.number().int().min(0),hasNext:r.z.boolean(),hasPrevious:r.z.boolean()});const Ce=r.z.enum(["all","DEFI","ASSET"]),De=ke.extend({type:Ce.optional(),address:x.optional(),search:P.optional(),tokenName:D.optional()}),Pe=r.z.object({walletAddress:x,amount:M}),_e=r.z.object({address:x.optional(),refresh:r.z.boolean().optional()}),Le=r.z.object({profileImage:r.z.string(),fullName:_,address:x,privateKey:J.optional()}),Oe=r.z.object({file:r.z.union([r.z.instanceof(File),r.z.instanceof(Buffer)]),address:x.optional(),privateKey:J.optional()}),xe=r.z.object({address:x,tokenId:r.z.union([r.z.string(),r.z.object({collection:r.z.string(),category:r.z.string(),type:r.z.string(),additionalKey:r.z.string()}),r.z.object({collection:r.z.string(),category:r.z.string(),type:r.z.string(),additionalKey:r.z.string(),instance:r.z.string()})]).optional(),tokenClassKey:r.z.object({collection:r.z.string(),category:r.z.string(),type:r.z.string(),additionalKey:r.z.string()}).optional(),tokenName:D.optional()}).refine(e=>void 0!==e.tokenId||void 0!==e.tokenName,"At least one token identifier (tokenId or tokenName) is required"),Ue=r.z.enum(["buy","sell"]),$e=r.z.enum(["BUY","SELL"]),Be=r.z.object({tradeType:Ue,tokenAmount:$,vaultAddress:U,userAddress:x,slippageTolerance:$.optional(),deadline:r.z.number().int().positive().optional()}),Me=r.z.object({tokenSymbol:F,nativeTokenQuantity:$,expectedToken:$,maxAcceptableReverseBondingCurveFee:B.default("0").optional()}),Re=r.z.object({tokenSymbol:F,tokenQuantity:$,expectedNativeToken:$,maxAcceptableReverseBondingCurveFee:B.default("0").optional()}),Ke=Ne.extend({tokenName:D.optional()}),Ge=r.z.object({page:r.z.number().int().min(1).max(1e3).default(1).optional(),limit:r.z.number().int().min(1).max(20).default(10).optional()}),ze=r.z.enum(["NATIVE","MEME"]),Ve=r.z.enum(["IN","OUT"]),qe=r.z.object({type:ze,method:Ve,vaultAddress:U,amount:$}),je=r.z.object({nativeTokenQuantity:$}),We=r.z.object({vaultAddress:U}),He=r.z.object({minFeePortion:$,maxFeePortion:$});function Qe(e){return t=>{const a=e.safeParse(t);return{success:a.success,data:a.success?a.data:void 0,errors:a.success?void 0:a.error.errors.map(e=>e.message)}}}const Xe=Qe(I),Ye=Qe(F),Ze=Qe(C),Je=Qe(x),et=Qe(U),tt=Qe($),at=Qe(M),nt=Qe(_),rt=Qe(P),ot=Qe(D),st=Qe(se),it=Qe(ae),ct=Qe(ie),lt=Qe(le),ut=Qe(De),dt=Qe(Pe),ht=Qe(_e),gt=Qe(Le),mt=Qe(Oe),pt=Qe(xe),ft=Qe(Be),yt=Qe(Me),vt=Qe(Re),At=Qe(Ke),wt=Qe(Ge),Tt=Qe(qe),kt=Qe(je),Nt=Qe(We);function Et(e,t){throw new v(e.join("; "),t,"VALIDATION_ERROR")}function St(e){const t=Xe(e);!t.success&&t.errors&&Et(t.errors,"tokenName")}function bt(e){const t=Se.safeParse(e);t.success||Et(t.error.errors.map(e=>e.message),"pagination")}function It(e){const t=lt(e);!t.success&&t.errors&&Et(t.errors,"options")}function Ft(e){const t=Tt(e);!t.success&&t.errors&&Et(t.errors,"options")}function Ct(e){const t=he.safeParse(e);t.success||Et(t.error.errors.map(e=>e.message),"options")}function Dt(e){const t=x.safeParse(e);if(!t.success)throw new v("Ethereum address must be 40 hex characters (with or without 0x prefix)","ethereumAddress","INVALID_FORMAT");return t.data}function Pt(e,t,a=!0){if(!e||""===e.trim())throw new v(`${t} cannot be empty or whitespace-only. Provide a valid numeric string or omit the parameter to auto-fetch.`,t,"INVALID_NUMERIC_STRING");if(/[eE]/.test(e))throw new v(`${t} cannot use scientific notation. Use standard decimal format (e.g., "1000" instead of "1e3").`,t,"INVALID_NUMERIC_STRING");const n=parseFloat(e);if(isNaN(n))throw new v(`${t} must be a valid numeric string. Received: "${e}"`,t,"INVALID_NUMERIC_STRING");if(!isFinite(n))throw new v(`${t} must be a finite number. Cannot be Infinity or -Infinity.`,t,"INVALID_NUMERIC_STRING");if(n<0)throw new v(`${t} must be non-negative. Received: "${e}"`,t,"INVALID_NUMERIC_STRING");if(!a&&0===n)throw new v(`${t} must be greater than zero. Received: "${e}"`,t,"INVALID_NUMERIC_STRING")}var _t=Object.freeze({__proto__:null,normalizeAddressInput:function(e){if(!e)return;const t=x.safeParse(e);if(!t.success)throw new v(`Invalid address format: ${e}. Must be either "0x..." (Ethereum) or "eth|..." (GalaChain) format`,"address","INVALID_FORMAT");return t.data},toBackendAddressFormat:Dt,validateCheckPoolOptions:It,validateGetAmountOptions:Ft,validateGetGraphOptions:Ct,validateNumericString:Pt,validatePagination:bt,validateTokenName:St});function Lt(e){if(!e)return[];return(Array.isArray(e)?e:e.token??[]).map(e=>({...e,createdAt:new Date(e.createdAt),updatedAt:new Date(e.updatedAt)}))}function Ot(e,t){const a=Number(e.page)||t.page,n=Number(e.limit)||t.limit,r=Number(e.total)||Number(e.data?.count)||0;return{page:a,limit:n,total:r,totalPages:Math.ceil(r/n)}}function xt(e,t){return{hasNext:e<t,hasPrevious:e>1}}function Ut(e,t,a=!1){const n=!0===e.error||200!==e.status,r=a&&!e.data;if(n||r)throw new Error(e.message||t)}const $t="/launchpad/upload-image",Bt="/launchpad/fetch-pool",Mt="/launchpad/check-pool",Rt="/launchpad/get-graph-data",Kt="/holders",Gt="/launchpad/get-badge/",zt="/trade/",Vt="/token/commment",qt="/token/commment",jt="/user/profile",Wt="/user/profile",Ht="/user/token-list",Qt="/user/token-hold",Xt="/user/transfer-faucets";function Yt(e,t){return new v(`Token "${e}" not found. Please verify the token name is correct.`,"tokenName","TOKEN_NOT_FOUND")}function Zt(e,t){const a=t||e.charAt(0).toUpperCase()+e.slice(1);return new v(`${a} is required`,e,"REQUIRED_FIELD")}function Jt(e,t,a){const n=a||e.charAt(0).toUpperCase()+e.slice(1);return new v(`${n} must be ${t}`,e,"INVALID_FORMAT")}function ea(e,t,a){return new A(e,t,a)}function ta(e,t){return new w(e,t)}function aa(e,t,a){return new T(e,t,a)}function na(e){return e&&"object"==typeof e&&"string"==typeof e.tokenName&&(void 0===e.from||"number"==typeof e.from)&&(void 0===e.to||"number"==typeof e.to)&&(void 0===e.resolution||"number"==typeof e.resolution)}class ra{constructor(e){this.http=e}async fetchSinglePage(e){const t={page:e.page.toString(),limit:e.limit.toString()};void 0!==e.type&&(t.type=e.type),void 0!==e.tokenName&&(t.tokenName=e.tokenName),void 0!==e.search&&(t.search=e.search);const a=m(t),n=await this.http.get(Bt,a);Ut(n,"Failed to fetch pools",!0);const r=function(e){if(!e)return[];let t=[];return e.tokens?t=Array.isArray(e.tokens)?e.tokens.map(e=>({...e,createdAt:new Date(e.created_at??e.createdAt)})):[{...e.tokens,createdAt:new Date(e.tokens.created_at??e.tokens.createdAt)}]:e.pools&&Array.isArray(e.pools)&&(t=e.pools.map(e=>({...e,createdAt:new Date(e.created_at??e.createdAt)}))),t}(n.data),o=n.data.count??n.data.total??0;return{pools:r,total:o,totalPages:e.limit>0?Math.ceil(o/e.limit):1}}async fetchMultiplePages(e){const{startPage:t,totalPages:a,pageSize:n,...r}=e,o=[];if(a&&a>=t){const e=[];for(let n=t;n<=a;n++)e.push(n);for(let t=0;t<e.length;t+=5){const a=e.slice(t,t+5).map(e=>this.fetchSinglePage({...r,page:e,limit:n}));(await Promise.all(a)).forEach(e=>{o.push(...e.pools)})}return o}let s=t,i=!0;for(;i;){const e=[];for(let t=0;t<5&&i;t++)e.push(s+t);const t=e.map(e=>this.fetchSinglePage({...r,page:e,limit:n})),a=await Promise.all(t);for(const e of a){if(0===e.pools.length){i=!1;break}o.push(...e.pools)}s+=e.length,s>100&&(i=!1)}return o}async fetchPools(e={}){const t=e.page||1,a=e.limit??10;let n;if(0!==a&&bt({page:t,limit:a}),e.tokenName&&St(e.tokenName),"recent"===e.type?n="RECENT":"popular"===e.type&&(n="POPULAR"),a>0&&a<=20){const r=await this.fetchSinglePage({...e.search&&{search:e.search},...e.tokenName&&{tokenName:e.tokenName},...n&&{type:n},page:t,limit:a});return{pools:r.pools,page:t,limit:a,total:r.total,totalPages:r.totalPages,hasNext:t<r.totalPages,hasPrevious:t>1}}if(0===a){const t=20,a=await this.fetchSinglePage({...e.search&&{search:e.search},...e.tokenName&&{tokenName:e.tokenName},...n&&{type:n},page:1,limit:t}),r=[...a.pools];if(a.pools.length>0){const o=await this.fetchMultiplePages({...e.search&&{search:e.search},...e.tokenName&&{tokenName:e.tokenName},...n&&{type:n},startPage:2,totalPages:a.totalPages>1?a.totalPages:null,pageSize:t});r.push(...o)}return{pools:r,page:1,limit:r.length,total:a.total||r.length,totalPages:1,hasNext:!1,hasPrevious:!1}}const r=Math.ceil(a/20),o=await this.fetchSinglePage({...e.search&&{search:e.search},...e.tokenName&&{tokenName:e.tokenName},...n&&{type:n},page:t,limit:20}),s=[...o.pools],i=Math.min(r,o.totalPages-t+1);if(i>1){const a=t+i-1,r=await this.fetchMultiplePages({...e.search&&{search:e.search},...e.tokenName&&{tokenName:e.tokenName},...n&&{type:n},startPage:t+1,totalPages:a,pageSize:20});s.push(...r)}const c=s.slice(0,a);return{pools:c,page:t,limit:a,total:o.total,totalPages:o.totalPages,hasNext:t<o.totalPages&&c.length<o.total,hasPrevious:t>1}}async fetchAllPools(e){return this.fetchPools({...e,limit:0})}async checkPool(e){It(e),e.tokenName&&St(e.tokenName);const t=m(e),a=await this.http.get(Mt,t);Ut(a,"Failed to check pool");const n=a.data;return e.symbol?n?.isSymbolExist??!1:e.tokenName?n?.isNameExist??!1:n?.exists??!1}async isTokenNameAvailable(e){try{return!await this.checkPool({tokenName:e})}catch{return!1}}async isTokenSymbolAvailable(e){try{return!await this.checkPool({symbol:e})}catch{return!1}}async fetchVolumeData(e){if(!na(e))throw new v("Invalid options provided. Expected { tokenName: string, from?: number, to?: number, resolution?: number }","options","INVALID_OPTIONS");const{tokenName:t,from:a,to:n,resolution:r}=e;if(St(t),!a||!n||!r)throw new v("Graph options (from, to, resolution) are required","options","MISSING_GRAPH_OPTIONS");const o={tokenName:t,from:a,to:n,resolution:r};Ct(o);const s=m(o),i=await this.http.get(Rt,s);return Ut(i,"Failed to fetch graph data",!0),{dataPoints:i.data}}async fetchTokenDistribution(e){if(!e)throw Zt("tokenName","Token name");St(e);const t=await this.resolveTokenNameToVault(e);if(!t)throw new v(y(e),"tokenName","VAULT_NOT_FOUND");const a=encodeURIComponent(t),n=await this.http.get(`${Kt}/${a}`);return Ut(n,"Failed to fetch token distribution",!0),{holders:n.data.holders||[],totalSupply:n.data.totalSupply||"0",totalHolders:n.data.totalHolders||0,lastUpdated:new Date}}async fetchTokenBadges(e){if(!e)throw Zt("tokenName","Token name");St(e);const t=await this.http.get(Gt,{tokenName:e});return Ut(t,"Failed to fetch token badges",!0),{volumeBadges:t.data.volumeBadge||[],engagementBadges:t.data.engagementBadge||[]}}async hasTokenBadge(e){const{tokenName:t,badgeType:a,badgeName:n}=e;try{const e=await this.fetchTokenBadges(t);if(!e)return!1;const r=("volume"===a?e.volumeBadges:e.engagementBadges).find(e=>e.badgeName===n);return r?.isActive||!1}catch{return!1}}async resolveTokenNameToVault(e){try{const t=await this.fetchPools({tokenName:e});return t.pools&&Array.isArray(t.pools)&&t.pools.length>0?t.pools[0].vaultAddress||null:t.pools&&t.pools.tokens&&t.pools.tokens.vaultAddress||null}catch{return null}}}function oa(e,t={}){const{stringifyFields:a=[],optionalFields:n=[],fieldMappings:r={}}=t,o={};for(const[t,s]of Object.entries(e)){const e=t;if(n.includes(e)&&void 0===s)continue;if(n.includes(e)&&"string"==typeof s&&0===s.trim().length)continue;const i=r[e],c=i?String(i):t;a.includes(e)?o[c]=String(s):o[c]=s}return m(o)}const sa={PAGINATION:{MIN_PAGE:1,MAX_PAGE:1e3,MIN_LIMIT:1,MAX_LIMIT:20}};class ia{constructor(e){this.http=e}async fetchTrades(e){if(!(t=e)||"object"!=typeof t||"string"!=typeof t.tokenName||void 0!==t.tradeType&&"buy"!==t.tradeType&&"sell"!==t.tradeType||void 0!==t.userAddress&&"string"!=typeof t.userAddress||void 0!==t.page&&"number"!=typeof t.page||void 0!==t.limit&&"number"!=typeof t.limit)throw new v("Invalid options provided. Expected { tokenName: string, tradeType?: string, userAddress?: string, page?: number, limit?: number, startDate?: Date, endDate?: Date, sortOrder?: string }","options","INVALID_OPTIONS");var t;const{tokenName:a,tradeType:n,userAddress:r,page:o=1,limit:s=10,startDate:i,endDate:c,sortOrder:l}=e;if(!E(a))throw new v("Token name is required and must be a non-empty string","tokenName","INVALID_TOKEN_NAME");k(o,s,sa);const u=function(e,t,a){return oa({tokenName:e,page:t,limit:a},{stringifyFields:["page","limit"]})}(a,o,s),d=await this.http.get(zt,u),h=(g=d.data)?(Array.isArray(g)?g:g.trades?g.trades:[]).map(e=>({...e,createdAt:new Date(e.createdAt),updatedAt:new Date(e.updatedAt)})):[];var g;const m=Ot(d,{page:o,limit:s}),p=xt(m.page,m.totalPages);return{trades:h,...m,...p}}}const ca=new g({debug:!1,context:"DateUtils"});function la(e,t){if(!e)return t||new Date;if(e instanceof Date)return isNaN(e.getTime())?t||new Date:e;try{const a=new Date(e);return isNaN(a.getTime())?(ca.warn(`Invalid date string received: "${e}". Using fallback.`),t||new Date):a}catch(a){return ca.warn(`Date parsing error for "${e}":`,a),t||new Date}}const ua={PAGINATION:{MIN_PAGE:1,MAX_PAGE:1e3,MIN_LIMIT:1,MAX_LIMIT:50},CONTENT:{MIN_LENGTH:1,MAX_LENGTH:500}};class da{constructor(e,t){this.http=e,this.poolService=t}async fetchComments(e){if(!(t=e)||"object"!=typeof t||"string"!=typeof t.tokenName||void 0!==t.page&&"number"!=typeof t.page||void 0!==t.limit&&"number"!=typeof t.limit)throw new v("Invalid options provided. Expected { tokenName: string, page?: number, limit?: number }","options","INVALID_OPTIONS");var t;const{tokenName:a,page:n=1,limit:r=10}=e;if(!E(a))throw new v("Token name is required and must be a non-empty string","tokenName","INVALID_TOKEN_NAME");k(n,r,ua);const o=await this.poolService.resolveTokenNameToVault(a);if(!o)throw Yt(a);const s=oa({vaultAddress:o,page:n,limit:r},{stringifyFields:["page","limit"]}),i=await this.http.get(Vt,s);Ut(i,"Failed to fetch comments");return{comments:i.data.comments.map(e=>({...e,createdAt:la(e.createdAt)})),total:i.data.count}}async postComment(e){if(!(t=e)||"object"!=typeof t||"string"!=typeof t.tokenName||"string"!=typeof t.content)throw new v("Invalid options provided. Expected { tokenName: string, content: string }","options","INVALID_OPTIONS");var t;const{tokenName:a,content:n}=e;if(!E(a))throw new v("Token name is required and must be a non-empty string","tokenName","INVALID_TOKEN_NAME");if(!function(e){if(!e||"string"!=typeof e)return!1;const t=e.trim();return t.length>=ua.CONTENT.MIN_LENGTH&&t.length<=ua.CONTENT.MAX_LENGTH}(n))throw new v(`Comment content must be between ${ua.CONTENT.MIN_LENGTH} and ${ua.CONTENT.MAX_LENGTH} characters`,"content","INVALID_CONTENT");const r=await this.poolService.resolveTokenNameToVault(a);if(!r)throw Yt(a);const o={userAddress:this.http.getAddress(),vaultAddress:r,content:n};Ut(await this.http.post(qt,o),"Failed to create comment")}}const ha={PAGINATION:{MIN_PAGE:1,MAX_PAGE:1e3,MIN_LIMIT:1,MAX_LIMIT:20},USER_ADDRESS:{PATTERN:/^eth\|[0-9a-fA-F]{40}$/},TOKEN_NAME:{MIN_LENGTH:1,MAX_LENGTH:50},SEARCH:{MIN_LENGTH:1,MAX_LENGTH:100},FAUCET_AMOUNT:{POSITIVE_NON_ZERO_DECIMAL:/^(?!0+(\.0+)?$)\d+(\.\d+)?$/},PROFILE:{FULL_NAME:{MIN_LENGTH:1,MAX_LENGTH:100,ALPHABETS_ONLY_PATTERN:/^[a-zA-Z]+(?:\s[a-zA-Z]+)?$/}}};function ga(e){return!(!e||"string"!=typeof e)&&ha.USER_ADDRESS.PATTERN.test(e)}const ma="Update profile";class pa{constructor(e){this.http=e}async fetchProfile(e){const t=e??this.http.getAddress();if(!ga(t))throw new v("Address must be in format: eth|[40-hex-chars]","address","INVALID_ADDRESS");const a={userAddress:t};return await this.http.get(jt,a)}async updateProfile(e){this.validateUpdateProfileData(e);let t=e.profileImage;if(!t||""===t.trim())try{const a=await this.fetchProfile(e.address);t=a.data?.profileImage||""}catch{t=""}const a={profileImage:t,fullName:e.fullName,userAddress:e.address},n=await this.http.signCustomMessage(ma),r={address:n.address,message:ma,publickey:n.ethereumAddress,sign:n.signature};Ut(await this.http.put(Wt,a,r),"Profile update failed")}async uploadProfileImage(e){this.validateUploadProfileImageOptions(e);const t=e.address??this.http.getAddress();try{const a=new FormData;if("undefined"!=typeof File&&e.file instanceof File)a.append("image",e.file);else{if(!Buffer.isBuffer(e.file))throw new v("Invalid file type","file","INVALID_FILE_TYPE");{const n=`profile-image-${t}.png`,r=new Blob([e.file],{type:"image/png"});a.append("image",r,n)}}const n=await this.http.request({method:"POST",url:`${$t}?tokenName=${encodeURIComponent(t)}`,data:a,headers:{}});return Ut(n,"Image upload failed"),"string"==typeof n.data?n.data:""}catch(e){if(e instanceof v)throw e;throw new v(`Profile image upload failed: ${e instanceof Error?e.message:"Unknown error"}`,"file","UPLOAD_FAILED")}}async fetchTokenList(e){this.validateGetTokenListOptions(e);const t=oa({page:e.page,limit:e.limit,type:"all"!==e.type&&e.type?e.type:"DEFI",address:e.address,search:e.search,tokenName:e.tokenName},{stringifyFields:["page","limit"],optionalFields:["address","search","tokenName"]}),a=await this.http.get(Ht,t);Ut(a,"Failed to fetch token list",!0);const n=Lt(a.data),r=Ot(a,{page:e.page||1,limit:e.limit||10}),o=xt(r.page,r.totalPages);return{tokens:n,...r,...o}}async fetchTokensHeld(e){this.validateGetTokenListOptions(e);const t=oa({page:e.page,limit:e.limit,address:e.address,search:e.search,tokenName:e.tokenName},{stringifyFields:["page","limit"],optionalFields:["address","search","tokenName"]}),a=await this.http.get(Qt,t);Ut(a,"Failed to fetch tokens held",!0);const n=Lt(a.data),r=Ot(a,{page:e.page||1,limit:e.limit||10}),o=xt(r.page,r.totalPages);return{tokens:n,...r,...o}}async fetchTokensCreated(e={}){const{page:t=1,limit:a=10,search:n,tokenName:r}=e,o={type:"DEFI",address:this.http.getAddress(),page:t,limit:a};return void 0!==n&&(o.search=n),void 0!==r&&(o.tokenName=r),this.fetchTokenList(o)}validateGetTokenListOptions(e){if(k(e.page,e.limit,ha),void 0!==e.address&&!ga(e.address))throw new v("Address must be in format: eth|[40-hex-chars]","address","INVALID_ADDRESS");if(void 0!==e.search&&e.search.trim().length>0&&!((t=e.search)&&"string"==typeof t&&t.length>=ha.SEARCH.MIN_LENGTH&&t.length<=ha.SEARCH.MAX_LENGTH))throw new v(`Search query must be between ${ha.SEARCH.MIN_LENGTH} and ${ha.SEARCH.MAX_LENGTH} characters`,"search","INVALID_SEARCH");var t,a;if(void 0!==e.tokenName&&e.tokenName.trim().length>0&&!((a=e.tokenName)&&"string"==typeof a&&a.length>=ha.TOKEN_NAME.MIN_LENGTH&&a.length<=ha.TOKEN_NAME.MAX_LENGTH))throw new v(`Token name must be between ${ha.TOKEN_NAME.MIN_LENGTH} and ${ha.TOKEN_NAME.MAX_LENGTH} characters`,"tokenName","INVALID_TOKEN_NAME")}validateUpdateProfileData(e){if(!ga(e.address))throw new v("Address must be in format: eth|[40-hex-chars]","address","INVALID_ADDRESS");if(!((t=e.fullName)&&"string"==typeof t&&t.length>=ha.PROFILE.FULL_NAME.MIN_LENGTH&&t.length<=ha.PROFILE.FULL_NAME.MAX_LENGTH&&ha.PROFILE.FULL_NAME.ALPHABETS_ONLY_PATTERN.test(t)))throw new v(`Full name must be between ${ha.PROFILE.FULL_NAME.MIN_LENGTH} and ${ha.PROFILE.FULL_NAME.MAX_LENGTH} characters`,"fullName","INVALID_FULL_NAME");var t}validateUploadProfileImageOptions(e){if(e.address&&!ga(e.address))throw new v("Address must be in format: eth|[40-hex-chars]","address","INVALID_ADDRESS")}}class fa extends Error{constructor(e,t,a){super(e),this.filename=t,this.mimeType=a,this.name="FileValidationError"}}function ya(e,t,a){if(!e)throw new fa("File is required",t,a);if("undefined"!=typeof File&&e instanceof File){const t=fe.safeParse(e);if(!t.success){const a=t.error.errors.map(e=>e.message).join("; ");throw new fa(a,e.name,e.type)}return}if(Buffer.isBuffer(e)){if(!t)throw new fa("Filename is required when uploading Buffer objects",t,a);const n=ye.safeParse(e);if(!n.success){const e=n.error.errors.map(e=>e.message).join("; ");throw new fa(e,t,a)}if(t.length>255)throw new fa(`Filename length ${t.length} exceeds maximum allowed length of 255 characters`,t,a);const r=["image/png","image/jpg","image/jpeg","image/gif","image/webp","image/svg+xml"];if(!r.includes(a))throw new fa(`Invalid file type "${a}" is not allowed. Allowed types: ${r.join(", ")}`,t,a);const o=function(e){if(!e)return"";const t=e.lastIndexOf(".");if(-1===t)return"";return e.substring(t).toLowerCase()}(t),s=[".png",".jpg",".jpeg",".gif",".webp",".svg"];if(!s.includes(o))throw new fa(`File extension "${o}" is not allowed. Allowed extensions: ${s.join(", ")}`,t,a);const i=function(e){switch(e.toLowerCase()){case".png":return"image/png";case".jpg":case".jpeg":return"image/jpeg";case".gif":return"image/gif";case".webp":return"image/webp";case".svg":return"image/svg+xml";default:return"application/octet-stream"}}(o);if(i!==a&&"application/octet-stream"!==i)throw new fa(`File extension "${o}" does not match MIME type "${a}"`,t,a);return}throw new fa("File must be a File object (browser) or Buffer (Node.js)",t,a)}class va{constructor(e){this.http=e}async uploadImageByTokenName(e){const{tokenName:t,options:a}=e;St(t);const n=`${t}.png`;ya(a.file,n,"image/png");try{const e=new FormData;if("undefined"!=typeof File&&a.file instanceof File)e.append("image",a.file);else{if(!Buffer.isBuffer(a.file))throw Jt("file","a File object (browser) or Buffer (Node.js)");{const n=`${a.tokenName??t}.png`,r=new Blob([a.file],{type:"image/png"});e.append("image",r,n)}}const n=await this.http.request({method:"POST",url:`${$t}?tokenName=${encodeURIComponent(a.tokenName??t)}`,data:e,headers:{}});return Ut(n,"Image upload failed"),"string"==typeof n.data?n.data:""}catch(e){if(e instanceof Error&&e.message.includes("FormData"))throw ta("File upload failed: FormData not supported in this environment. Ensure you have proper polyfills for Node.js environments.","FormData");throw e}}}class Aa{constructor(e){this.http=e}async transferFaucets(e){this.validateTransferFaucetsData(e);const t={userAddress:e.walletAddress,amount:e.amount};Ut(await this.http.post(Xt,t),"Faucet transfer failed")}validateTransferFaucetsData(e){if(!ga(e.walletAddress))throw new v("Address must be in format: eth|[40-hex-chars]","address","INVALID_ADDRESS");if(!(t=e.amount)||"string"!=typeof t||!ha.FAUCET_AMOUNT.POSITIVE_NON_ZERO_DECIMAL.test(t))throw new v("Amount must be a positive decimal string greater than zero","amount","INVALID_AMOUNT");var t}}class wa{constructor(e){this.http=e,this.poolService=new ra(e),this.tradeService=new ia(e),this.commentService=new da(e,this.poolService),this.userService=new pa(e),this.imageService=new va(e),this.faucetService=new Aa(e)}async uploadImageByTokenName(e){return this.imageService.uploadImageByTokenName(e)}async fetchPools(e={}){return this.poolService.fetchPools(e)}async fetchAllPools(e){return this.poolService.fetchAllPools(e)}async checkPool(e){return this.poolService.checkPool(e)}async isTokenNameAvailable(e){return this.poolService.isTokenNameAvailable(e)}async isTokenSymbolAvailable(e){return this.poolService.isTokenSymbolAvailable(e)}async fetchVolumeData(e){return this.poolService.fetchVolumeData(e)}async fetchTokenDistribution(e){return this.poolService.fetchTokenDistribution(e)}async fetchTokenBadges(e){return this.poolService.fetchTokenBadges(e)}async hasTokenBadge(e){return this.poolService.hasTokenBadge(e)}async fetchTrades(e){return this.tradeService.fetchTrades(e)}async fetchComments(e){return this.commentService.fetchComments(e)}async postComment(e){return this.commentService.postComment(e)}async fetchProfile(e){return this.userService.fetchProfile(e)}async updateProfile(e){return this.userService.updateProfile(e)}async uploadProfileImage(e){return this.userService.uploadProfileImage(e)}async fetchTokenList(e){return this.userService.fetchTokenList(e)}async fetchTokensHeld(e){return this.userService.fetchTokensHeld(e)}async fetchTokensCreated(e={}){return this.userService.fetchTokensCreated(e)}async transferFaucets(e){return this.faucetService.transferFaucets(e)}getAddress(){return this.http.getAddress()}validateTokenName(e){return St(e)}}class Ta extends n.ChainCallDTO{constructor(e){super(),this.from=e.from,this.to=e.to,this.quantity=e.quantity,this.tokenInstance=e.tokenInstance,this.uniqueKey=e.uniqueKey,e.signedPayload&&(this.signature=e.signedPayload.signature,this.domain=e.signedPayload.domain,this.types=e.signedPayload.types,e.signedPayload.prefix&&(this.prefix=e.signedPayload.prefix))}static fromTokenClassKey(e,t,a,n,r){let o;if("string"==typeof n){const e=n.split("$");if(4!==e.length)throw new Error(`Invalid token class key format: ${n}. Expected format: collection$category$type$additionalKey`);o={collection:e[0],category:e[1],type:e[2],additionalKey:e[3],instance:"0"}}else o={collection:n.collection,category:n.category,type:n.type,additionalKey:n.additionalKey,instance:"0"};return new Ta({from:e,to:t,quantity:a,tokenInstance:o,uniqueKey:r||`galaconnect-operation-${Date.now()}_${Math.random().toString(36).substring(2,8)}`})}static forGALA(e,t,a,n){return new Ta({from:e,to:t,quantity:a,tokenInstance:{collection:"GALA",category:"Unit",type:"none",additionalKey:"none",instance:"0"},uniqueKey:n||`galaconnect-operation-${Date.now()}_${Math.random().toString(36).substring(2,8)}`})}getTokenClassKey(){return`${this.tokenInstance.collection}$${this.tokenInstance.category}$${this.tokenInstance.type}$${this.tokenInstance.additionalKey}`}toSigningPayload(){return{from:this.from,to:this.to,quantity:this.quantity,tokenInstance:this.tokenInstance,uniqueKey:this.uniqueKey}}}class ka{constructor(e){this.wallet=e}static generateUniqueKey(){return`${Date.now()}_${Math.random().toString(36).substring(2,8)}`}async signTransferToken(e){const t={name:"GalaChain",chainId:1},a={TransferToken:[{name:"from",type:"string"},{name:"to",type:"string"},{name:"quantity",type:"string"},{name:"tokenInstance",type:"TokenInstance"},{name:"uniqueKey",type:"string"}],TokenInstance:[{name:"collection",type:"string"},{name:"category",type:"string"},{name:"type",type:"string"},{name:"additionalKey",type:"string"},{name:"instance",type:"string"}]};return{signature:await this.wallet.signTypedData(t,a,e),domain:t,types:a,signerPublicKey:this.wallet.signingKey.publicKey}}static toGalaChainAddress(e){const a=e.replace("0x","");return`eth|${t.ethers.getAddress(`0x${a}`).replace("0x","")}`}static fromGalaChainAddress(e){return e.startsWith("eth|")?e.substring(4):e}static createGALATokenInstance(){return{collection:"GALA",category:"Unit",type:"none",additionalKey:"none",instance:"0"}}static createTokenInstanceFromClassKey(e){const t=e.split("$");if(4!==t.length)throw new Error(`Invalid token class key format: ${e}. Expected format: collection$category$type$additionalKey`);return{collection:t[0],category:t[1],type:t[2],additionalKey:t[3],instance:"0"}}}function Na(e){if("string"==typeof e){const t=e.split("|");if(t.length<4)throw new v(`Invalid tokenId string format: "${e}". Expected format: "collection|category|type|additionalKey" or "collection|category|type|additionalKey|instance"`,"tokenId","INVALID_TOKEN_ID_FORMAT");if(!(t[0]&&t[1]&&t[2]&&t[3]))throw new v(`Invalid tokenId string format: "${e}". All components (collection, category, type, additionalKey) must be non-empty`,"tokenId","INVALID_TOKEN_ID_FORMAT");return{collection:t[0],category:t[1],type:t[2],additionalKey:t[3],instance:t[4]||"0"}}if("object"==typeof e&&null!==e){if(!(e.collection&&e.category&&e.type&&e.additionalKey))throw new v("Invalid tokenId object format. All fields (collection, category, type, additionalKey) are required","tokenId","INVALID_TOKEN_ID_FORMAT");return"instance"in e&&void 0!==e.instance?e:{...e,instance:"0"}}throw new v(`Invalid tokenId type: ${typeof e}. Expected string, TokenClassKey, or TokenInstanceKey`,"tokenId","INVALID_TOKEN_ID_TYPE")}var Ea=Object.freeze({__proto__:null,normalizeToTokenInstanceKey:Na});const Sa={MAX_UNIQUE_KEY_LENGTH:64,UNIQUE_KEY_PATTERN:/^(galaswap-operation-|galaconnect-operation-)/,TOKEN_NAME_PATTERN:/^[a-zA-Z0-9]+$/};var ba;!function(e){e.INVALID_RECIPIENT="INVALID_RECIPIENT",e.INVALID_AMOUNT="INVALID_AMOUNT",e.INSUFFICIENT_BALANCE="INSUFFICIENT_BALANCE",e.TOKEN_NOT_FOUND="TOKEN_NOT_FOUND",e.SIGNATURE_FAILED="SIGNATURE_FAILED",e.NETWORK_ERROR="NETWORK_ERROR",e.DUPLICATE_TRANSFER="DUPLICATE_TRANSFER",e.TRANSFER_LIMIT_EXCEEDED="TRANSFER_LIMIT_EXCEEDED"}(ba||(ba={}));class Ia extends Error{constructor(e,t,a){super(e),this.type=t,this.details=a,this.name="TransferError"}}class Fa{constructor(e,t,a,n=!1){this.http=e,this.wallet=t,this.tokenResolver=a,this.signatureHelper=new ka(t),this.logger=new g({debug:n,context:"GalaChainService"})}async fetchPoolDetails(e){this.validateFetchPoolDetailsData(e);const t=await this.http.post("/api/asset/launchpad-contract/FetchSaleDetails",e);if(1!==t.Status)throw ea(`Failed to fetch pool details: Status ${t.Status}`,t.Status);const a=t.Data,n=a.reverseBondingCurveConfiguration,r=n?.minFeePortion??"0",o=n?.maxFeePortion??"0",s=(await import("bignumber.js")).default,i=!new s(r).isZero()||!new s(o).isZero();return a.reverseBondingCurveMinFeePortion=r,a.reverseBondingCurveMaxFeePortion=o,a.hasReverseBondingCurveFee=i,a.isGraduated="Completed"===a.saleStatus,delete a.reverseBondingCurveConfiguration,t}async fetchLaunchTokenFee(){const e=await this.http.post("/api/asset/launchpad-contract/FetchLaunchpadFeeAmount",{});if(1!==e.Status)throw ea(`Failed to fetch launch token fee: Status ${e.Status}`,e.Status);return e.Data.feeAmount}validateFetchPoolDetailsData(e){if(!(t=e)||"object"!=typeof t||"string"!=typeof t.vaultAddress)throw new v("Invalid fetch pool details data: missing required fields","data","INVALID_TYPE");var t;if(!e.vaultAddress||"string"!=typeof e.vaultAddress)throw new v("Vault address is required and must be a string","vaultAddress","INVALID_VAULT_ADDRESS");if(!e.vaultAddress.startsWith("service|Token$Unit$"))throw new v("Vault address must be in service format: service|Token$Unit$...","vaultAddress","INVALID_VAULT_ADDRESS")}async fetchGalaBalance(e){return this.fetchTokenBalance(e)}async fetchTokenBalance(e){try{const t=await this.http.post("/api/asset/token-contract/FetchBalances",e);if(1!==t.Status||!t.Data||0===t.Data.length)return null;const a=t.Data.find(t=>t.collection===e.collection&&t.category===e.category&&t.additionalKey===e.additionalKey&&t.type===e.type);if(!a||"0"===a.quantity)return null;const n=`${a.collection}|${a.category}|${a.additionalKey}|${a.type}`;return{quantity:a.quantity,collection:a.collection,category:a.category,tokenId:n}}catch(e){throw ea(`Failed to fetch token balance from GalaChain: ${e.message||"Unknown error"}`,void 0,e)}}async transferGala(e){this.validateTransferGalaData(e);try{const t=b(e.recipientAddress),a=b(this.wallet.address),n=Ta.forGALA(a,t,e.amount,e.uniqueKey),r=await this.signatureHelper.signTransferToken(n.toSigningPayload()),o=new Ta({...n.toSigningPayload(),signedPayload:r});this.logger.debug("[DEBUG] Full GALA Transfer Request Payload:",JSON.stringify(o,null,2));const s=await this.http.post("/api/asset/token-contract/TransferToken",o);if(this.logger.debug("[DEBUG] Transfer response:",JSON.stringify(s,null,2)),s&&"object"==typeof s){if("Status"in s&&1===s.Status&&"Data"in s){const e=s;return Array.isArray(e.Data)&&e.Data.length>0?"gala-transfer-successful":"transfer-successful-no-id"}if("transactionId"in s&&s.transactionId)return s.transactionId}throw new Ia("Transfer succeeded but transaction ID could not be extracted",ba.NETWORK_ERROR)}catch(t){throw this.handleTransferError(t,"GALA transfer failed",e)}}async transferToken(e){this.validateTransferTokenData(e);try{const t=b(e.to),a=b(this.wallet.address);let n;if(e.tokenId)n=Na(e.tokenId),this.logger.debug("[DEBUG] Using provided tokenId:",e.tokenId),this.logger.debug("[DEBUG] Normalized Token Instance:",JSON.stringify(n,null,2));else{if(!e.tokenName)throw new Ia("Must provide either tokenId or tokenName for token identification",ba.TOKEN_NOT_FOUND);n=await this.resolveTokenInstance(e.tokenName)}const r=new Ta({from:a,to:t,quantity:e.amount,tokenInstance:n,uniqueKey:e.uniqueKey||`galaconnect-operation-${Date.now()}_${Math.random().toString(36).substring(2,8)}`}),o=await this.signatureHelper.signTransferToken(r.toSigningPayload()),s=new Ta({...r.toSigningPayload(),signedPayload:o});this.logger.debug("[DEBUG] Full Transfer Request Payload:",JSON.stringify(s,null,2));const i=await this.http.post("/api/asset/token-contract/TransferToken",s);if(this.logger.debug("[DEBUG] Token transfer response:",JSON.stringify(i,null,2)),i&&"object"==typeof i){if("Status"in i&&1===i.Status&&"Data"in i){const e=i;return Array.isArray(e.Data)&&e.Data.length>0?"token-transfer-successful":"transfer-successful-no-id"}if("transactionId"in i&&i.transactionId)return i.transactionId}throw new Ia("Transfer succeeded but transaction ID could not be extracted",ba.NETWORK_ERROR)}catch(t){throw this.handleTransferError(t,"Token transfer failed",e)}}async resolveTokenClassKey(e){try{const t=await this.tokenResolver.resolveTokenClassKey(e);return this.logger.debug(`[DEBUG] Token class key resolution for '${e}':`,JSON.stringify(t,null,2)),t}catch(t){if(t instanceof Ia)throw t;throw new Ia(`Failed to resolve token class key for '${e}': ${t instanceof Error?t.message:String(t)}`,ba.TOKEN_NOT_FOUND,{tokenName:e})}}validateTransferGalaData(e){if(!((t=e)&&"object"==typeof t&&"string"==typeof t.recipientAddress&&t.recipientAddress.trim().length>0&&"string"==typeof t.amount&&t.amount.trim().length>0)||void 0!==t.uniqueKey&&"string"!=typeof t.uniqueKey)throw new v("Invalid GALA transfer data: missing required fields");var t;if(!S(e.recipientAddress))throw new Ia("Invalid recipient address format",ba.INVALID_RECIPIENT,{recipientAddress:e.recipientAddress});if(parseFloat(e.amount)<=0)throw new Ia("Transfer amount must be positive",ba.INVALID_AMOUNT,{amount:e.amount});if(e.uniqueKey){if(e.uniqueKey.length>Sa.MAX_UNIQUE_KEY_LENGTH)throw new v(`Unique key too long. Maximum length: ${Sa.MAX_UNIQUE_KEY_LENGTH}`);if(!Sa.UNIQUE_KEY_PATTERN.test(e.uniqueKey))throw new Ia('Invalid unique key format. Must start with "galaswap-operation-" or "galaconnect-operation-"',ba.INVALID_AMOUNT,{uniqueKey:e.uniqueKey})}}validateTransferTokenData(e){if(!((t=e)&&"object"==typeof t&&"string"==typeof t.to&&t.to.trim().length>0&&"string"==typeof t.amount&&t.amount.trim().length>0&&(void 0!==t.tokenId||"string"==typeof t.tokenName&&t.tokenName.trim().length>0))||void 0!==t.uniqueKey&&"string"!=typeof t.uniqueKey)throw new v("Invalid token transfer data: missing required fields");var t;if(!S(e.to))throw new Ia("Invalid recipient address format",ba.INVALID_RECIPIENT,{recipientAddress:e.to});if(!e.tokenId&&!e.tokenName)throw new Ia("Must provide either tokenId or tokenName for token identification",ba.TOKEN_NOT_FOUND);if(e.tokenName&&!Sa.TOKEN_NAME_PATTERN.test(e.tokenName))throw new Ia("Invalid token name format",ba.TOKEN_NOT_FOUND,{tokenName:e.tokenName});if(parseFloat(e.amount)<=0)throw new Ia("Transfer amount must be positive",ba.INVALID_AMOUNT,{amount:e.amount});if(e.uniqueKey){if(e.uniqueKey.length>Sa.MAX_UNIQUE_KEY_LENGTH)throw new v(`Unique key too long. Maximum length: ${Sa.MAX_UNIQUE_KEY_LENGTH}`);if(!Sa.UNIQUE_KEY_PATTERN.test(e.uniqueKey))throw new Ia('Invalid unique key format. Must start with "galaswap-operation-" or "galaconnect-operation-"',ba.INVALID_AMOUNT,{uniqueKey:e.uniqueKey})}}async resolveTokenInstance(e){try{const t=await this.tokenResolver.resolveTokenToVault(e);if(!t)throw new Ia(`Token '${e}' not found or not available for transfer`,ba.TOKEN_NOT_FOUND,{tokenName:e});const a=this.resolveTokenInstanceFromVaultAddress(t);return this.logger.debug(`[DEBUG] Token resolution for '${e}':\n Vault Address: ${t}\n Token Instance: ${JSON.stringify(a,null,2)}`),a}catch(t){if(t instanceof Ia)throw t;throw new Ia(`Failed to resolve token '${e}': ${t instanceof Error?t.message:String(t)}`,ba.TOKEN_NOT_FOUND,{tokenName:e})}}resolveTokenInstanceFromVaultAddress(e){const[t,a]=e.split("|");if(!a)throw new Ia(`Invalid vault address format: missing token components. Address: ${e}`,ba.TOKEN_NOT_FOUND);const n=a.split("$");if(n.length<4)throw new Ia(`Invalid vault address format: insufficient token components. Expected 4+, got ${n.length}. Address: ${e}`,ba.TOKEN_NOT_FOUND);return{collection:n[0],category:n[1],type:n[2],additionalKey:n[3],instance:"0"}}handleTransferError(e,t,a){if(e instanceof Ia)return e;if(e instanceof v)return new Ia(e.message,ba.INVALID_AMOUNT);if(400===e.response?.status)return new Ia(e.response.data?.message||"Invalid transfer request",ba.INVALID_AMOUNT);if(403===e.response?.status)return new Ia("Insufficient balance for transfer",ba.INSUFFICIENT_BALANCE);if(404===e.response?.status){const e={};return"tokenName"in a&&(e.tokenName=a.tokenName),new Ia("Token not found",ba.TOKEN_NOT_FOUND,e)}return"ECONNABORTED"===e.code||"ETIMEDOUT"===e.code?new Ia("Transfer request timed out",ba.NETWORK_ERROR):new Ia(e.message||t,ba.NETWORK_ERROR)}}class Ca{constructor(e){this.http=e}async fetchTokenSpotPrice(e){if(!e||Array.isArray(e)&&0===e.length)throw Zt("symbols","At least one symbol");const t=Array.isArray(e)?e.join(","):e;try{const e=await this.http.request({method:"GET",url:"/v1/tokens",params:{symbols:t}}),a=[];return e.tokens&&Array.isArray(e.tokens)&&e.tokens.forEach(e=>{e.currentPrices&&e.symbol&&a.push({symbol:e.symbol,price:e.currentPrices.usd})}),a}catch(e){throw ea(`Failed to fetch token prices: ${e instanceof Error?e.message:e}`)}}async fetchLaunchpadTokenSpotPrice(e,t){if(!e||"string"!=typeof e)throw new Error(f);try{const a=await t({tokenName:e,amount:"1",type:"native"}),n=(await this.fetchTokenSpotPrice("GALA"))[0];if(!n)throw ea("GALA price not available");const r=Number(a.amount)/1e18;if(r<=0)throw new v(`Invalid token amount calculation: ${r}`,"amount","INVALID_CALCULATION");const o=n.price/r;return{symbol:e.toUpperCase(),price:o}}catch(t){if(t instanceof Error)throw ea(`Failed to calculate launchpad token spot price for ${e}: ${t.message}`);throw ea(`Failed to calculate launchpad token spot price for ${e}: ${String(t)}`)}}}function Da(e,t=18){const a=parseFloat(e);if(0===a)return"0";return a.toFixed(t).replace(/\.?0+$/,"")}function Pa(e){return Da(e,8)}function _a(e){return Da(e,18)}new g({debug:!1,context:"NumberUtils"});class La extends n.ChainCallDTO{constructor(e,t,a="0",n={maxAcceptableReverseBondingCurveFee:"0"}){super(),this.vaultAddress=e,this.nativeTokenQuantity=Pa(t),this.expectedToken=_a(a),this.extraFees={maxAcceptableReverseBondingCurveFee:Pa(n.maxAcceptableReverseBondingCurveFee)}}}class Oa extends n.ChainCallDTO{constructor(e,t,a,n={maxAcceptableReverseBondingCurveFee:"0"}){super(),this.vaultAddress=e,this.tokenQuantity=_a(t),this.expectedNativeToken=Pa(a),this.extraFees={maxAcceptableReverseBondingCurveFee:Pa(n.maxAcceptableReverseBondingCurveFee)}}}class xa extends n.ChainCallDTO{constructor(e,t,a="0",n={maxAcceptableReverseBondingCurveFee:"0"}){super(),this.vaultAddress=e,this.tokenQuantity=_a(t),this.expectedNativeToken=Pa(a),this.extraFees={maxAcceptableReverseBondingCurveFee:Pa(n.maxAcceptableReverseBondingCurveFee)}}}class Ua extends n.ChainCallDTO{constructor(e,t,a,n={maxAcceptableReverseBondingCurveFee:"0"}){super(),this.vaultAddress=e,this.nativeTokenQuantity=Pa(t),this.expectedToken=_a(a),this.extraFees={maxAcceptableReverseBondingCurveFee:Pa(n.maxAcceptableReverseBondingCurveFee)}}}const $a={BuyNativeDto:La,BuyExactDto:Oa,SellExactDto:xa,SellNativeDto:Ua};var Ba,Ma,Ra;!function(e){e[e.METAMASK=0]="METAMASK",e[e.TRUST_WALLET=1]="TRUST_WALLET",e[e.GALA_WALLET=2]="GALA_WALLET"}(Ba||(Ba={}));class Ka{constructor(e,t=!1){this.walletProvider=e,this.debug=t,this.logger=new g({debug:t,context:"SignatureService"})}async signDTO(e,t,a,r=Ba.METAMASK){try{this.logger.debug("๐Ÿ” Signing DTO:",{methodName:t,walletPreference:r,dtoKeys:Object.keys(e)});const o=this.generateEIP712Types(t,e),s=n.calculatePersonalSignPrefix(e),i={...e,prefix:s};let c,l,u;switch(r){case Ba.GALA_WALLET:({signature:c,domain:l}=await this.signWithGalaWallet(o,i,t,a));break;case Ba.TRUST_WALLET:c=await this.signWithTrustWallet(i),l={name:"ethereum",chainId:1};break;case Ba.METAMASK:default:({signature:c,domain:l}=await this.signWithMetaMask(o,i))}return u=r===Ba.TRUST_WALLET?{...i,signature:c}:{...e,signature:c,types:o,domain:l},this.logger.debug("โœ… DTO signed successfully:",{payloadKeys:Object.keys(u),signatureLength:c.length}),u}catch(e){throw this.logger.error("โŒ Signature generation failed:",e),aa(`Failed to sign DTO: ${e.message}`)}}async signWithMetaMask(e,t){try{let a,n;if(this.walletProvider.signTypedData&&!this.walletProvider.getNetwork)a={name:"ethereum",chainId:1},n=await this.walletProvider.signTypedData(a,e,t);else{if(!this.walletProvider.getNetwork||!this.walletProvider.signTypedData)throw ta("Wallet provider does not support typed data signing","walletProvider");{const r=await this.walletProvider.getNetwork();a={name:r.name,chainId:Number(r.chainId)},n=await this.walletProvider.signTypedData(a,e,t)}}return{signature:n,domain:a}}catch(e){throw aa(`MetaMask/ethers signing failed: ${e.message}`)}}async signWithTrustWallet(e){try{const a=(t=e,JSON.stringify(t));let n;if(!this.walletProvider.signMessage)throw ta("Wallet provider does not support signMessage","walletProvider");return n=await this.walletProvider.signMessage(a),n}catch(e){throw aa(`TrustWallet signing failed: ${e.message}`)}var t}async signWithGalaWallet(e,t,a,n){try{const r={name:"ethereum",chainId:1};if("undefined"==typeof window)return this.logger.warn("โš ๏ธ GalaWallet not available in Node.js environment, falling back to ethers.js signing"),await this.signWithMetaMask(e,t);const o={domain:r,types:e,message:t,Primary_type:a},s=window;if(!s?.gala)throw ta("GalaWallet not found in window object","galaWallet");await s.gala.setAddress(n);return{signature:await s.gala.request({method:"eth_signTypedData",params:[JSON.stringify(o),n]}),domain:r}}catch(e){throw aa(`GalaWallet signing failed: ${e.message}`)}}generateEIP712Types(e,t){const a={};a[e]=[];const n=(e,t,r,o=!1)=>{if(void 0!==t){if(Array.isArray(t)){const s=n(e,t[0],r,!0);return o||a[r].push({name:e,type:(s??e)+"[]"}),s?s+"[]":void 0}if("object"==typeof t&&null!==t){if(a[e])throw new v(`Type name collision not supported: ${e}`,"fieldValue","TYPE_COLLISION");return a[e]=[],Object.entries(t).forEach(([t,a])=>{n(t,a,e)}),o||a[r].push({name:e,type:e}),e}{let n;switch(typeof t){case"string":n="string";break;case"number":n="uint256";break;case"boolean":n="bool";break;default:throw new v(`Unsupported type for fieldName ${e}: ${typeof t}, value: ${t}`,"fieldValue","UNSUPPORTED_TYPE")}return o||a[r].push({name:e,type:n}),n}}};return Object.entries(t).forEach(([t,a])=>{n(t,a,e)}),this.logger.debug("๐Ÿ“ Generated EIP-712 types:",a),a}detectWalletPreference(){if("undefined"==typeof window)return Ba.METAMASK;const e=window;return e?.gala?Ba.GALA_WALLET:e?.trustWallet?.isTrust?Ba.TRUST_WALLET:Ba.METAMASK}}class Ga{constructor(e=!1){this.debug=e,this.logger=new g({debug:e,context:"TokenClassKeyService"})}generateStringsInstructions(e){try{this.logger.debug("๐Ÿ”ง Generating stringsInstructions for:",e);const t=this.extractTokenSymbolFromVault(e),a=this.createTokenInstance(t),n=this.createGalaInstance(),r=`$service$${a.toStringKey()}$launchpad`,o=`$tokenBalance$${a.toStringKey()}$${e}`,s=`$tokenBalance$${a.toStringKey()}$${e}`,i=`$tokenBalance$${n.toStringKey()}$${e}`,c=[r,o,s,i,`$tokenBalance$${n.toStringKey()}$${e}`];return this.logger.debug("โœ… Generated stringsInstructions:",c),c}catch(e){throw this.logger.error("โŒ Failed to generate stringsInstructions:",e),new v(`Failed to generate stringsInstructions: ${e.message}`,"vaultAddress","INVALID_VAULT_ADDRESS")}}createTokenInstance(e){const t=new o.TokenClassKey;return t.collection=e.toLowerCase(),t.category="Unit",t.type="none",t.additionalKey="none",this.logger.debug("๐Ÿช™ Created token instance:",{symbol:e,lowercaseCollection:e.toLowerCase(),stringKey:t.toStringKey()}),t}createGalaInstance(){const e=new o.TokenClassKey;return e.collection="GALA",e.category="Unit",e.type="none",e.additionalKey="none",this.logger.debug("๐ŸŸก Created GALA instance:",{stringKey:e.toStringKey()}),e}extractTokenSymbolFromVault(e){if(!e||"string"!=typeof e)throw Zt("vaultAddress","Vault address");const t=e.split("$");if(t.length<3)throw Jt("vaultAddress","format: service|Token$Unit$SYMBOL$eth:address$launchpad");const a=t[2];if(!a||0===a.trim().length)throw new v(`Empty token symbol in vault address: ${e}`,"vaultAddress","EMPTY_TOKEN_SYMBOL");return this.logger.debug("๐Ÿ” Extracted token symbol:",{vaultAddress:e,tokenSymbol:a,parts:t.slice(0,4)}),a}validateVaultAddress(e){if(!e||"string"!=typeof e)throw Zt("vaultAddress","Vault address");if(!e.startsWith("service|Token$Unit$"))throw Jt("vaultAddress",'starting with "service|Token$Unit$"');if(!e.endsWith("$launchpad"))throw Jt("vaultAddress",'ending with "$launchpad"');const t=e.split("$");if(t.length<5)throw Jt("vaultAddress",'having at least 5 parts separated by "$"');const a=t[2];if(!a||!/^[A-Za-z]{1,10}$/.test(a))throw Jt("vaultAddress","containing a 1-10 letter token symbol (case insensitive)");return this.logger.debug("โœ… Vault address validation passed:",e),!0}generateTokenClassKeyString(e,t,a,n){return`${e}$${t}$${a}$${n}`}parseTokenClassKeyString(e){const t=e.split("$");if(4!==t.length)throw Jt("stringKey","format: collection$category$type$additionalKey (4 parts)");return{collection:t[0],category:t[1],type:t[2],additionalKey:t[3]}}}function za(e,t,a){if(t<0||t>1)throw new Error(`Invalid slippage tolerance factor: ${t}. Must be between 0 and 1 (e.g., 0.05 for 5%)`);const n=new s(e);if(n.isNaN())throw new Error(`Invalid expected amount: ${e}. Must be a valid number`);if(0===t)return e;const r=n.multipliedBy(t);let o;switch(a){case"buy-native":case"sell-exact":o=n.minus(r);break;case"buy-exact":case"sell-native":o=n.plus(r);break;default:throw new Error(`Unknown operation type: ${a}`)}return o.isLessThan(0)&&(o=new s(0)),o.toFixed()}class Va{constructor(e,t,a=!1,n,r,o=.05,s=.01){this.httpClient=e,this.tokenResolver=t,this.walletProvider=n,this.userAddress=r,this.defaultSlippageToleranceFactor=o,this.defaultMaxAcceptableReverseBondingCurveFeeSlippageFactor=s,this.bundleEndpoint="/bundle",this.logger=new g({debug:a,context:"BundleService"}),n&&r&&(this.signatureService=new Ka(n,a),this.tokenKeyService=new Ga(a))}async submitTransaction(e){try{this.logger.debug("๐Ÿ“ฆ Submitting bundle transaction:",{method:e.method,stringsInstructionsCount:e.stringsInstructions.length,signedDtoKeys:Object.keys(e.signedDto)}),this.validateBundleData(e);const t=this.formatBundleRequest(e);this.logger.debug("๐Ÿš€ Bundle request payload:",{...t,signedDto:"[REDACTED - Contains signature]"});const a=await this.httpClient.post(this.bundleEndpoint,t);return this.logger.debug("๐Ÿ“ฅ Bundle API response:",{success:a.success,hasData:!!a.data,error:a.error}),this.handleBundleResponse(a)}catch(e){return this.logger.error("โŒ Bundle transaction submission failed:",e),{success:!1,error:this.formatErrorMessage(e)}}}validateBundleData(e){if(!e)throw Zt("bundleData","Bundle data");if(!e.signedDto)throw Zt("signedDto","Signed DTO");if(!e.method||"string"!=typeof e.method)throw Zt("method","Method name");if(!Array.isArray(e.stringsInstructions))throw Jt("stringsInstructions","an array of resource tracking strings");if(0===e.stringsInstructions.length)throw new v("stringsInstructions cannot be empty","stringsInstructions","EMPTY_ARRAY");const t=["BuyWithNative","BuyExactToken","SellExactToken","SellWithNative"];if(!t.includes(e.method))throw Jt("method",`one of: ${t.join(", ")}`);e.stringsInstructions.forEach((e,t)=>{if("string"!=typeof e||0===e.length)throw new v(`stringsInstructions[${t}] must be a non-empty string`,`stringsInstructions[${t}]`,"INVALID_INSTRUCTION");if(!e.startsWith("$"))throw new v(`stringsInstructions[${t}] must start with '$': ${e}`,`stringsInstructions[${t}]`,"INVALID_INSTRUCTION_FORMAT")}),this.logger.debug("โœ… Bundle data validation passed")}formatBundleRequest(e){return{signedDto:e.signedDto,stringsInstructions:e.stringsInstructions,method:e.method}}handleBundleResponse(e){if(e.data&&!1===e.error)return this.logger.debug("โœ… Bundle transaction successful:",e.data),{success:!0,data:e.data};const t=e.error||e.message||"Bundle transaction failed";return this.logger.debug("โŒ Bundle transaction failed:",t),{success:!1,error:t}}formatErrorMessage(e){return"string"==typeof e?e:e?.response?.data?.error?e.response.data.error:e?.response?.data?.message?e.response.data.message:e?.message?e.message:"Unknown bundle transaction error"}async getBundlerTransactionResult(e){try{if(!e||"string"!=typeof e)throw Zt("transactionId","Transaction ID");this.logger.debug("๐Ÿ” Checking bundler transaction result:",e);const t=await this.httpClient.get(`${this.bundleEndpoint}?id=${e}`);return this.logger.debug("๐Ÿ“Š Bundler transaction result:",t),{success:!0,data:t}}catch(e){return this.logger.error("โŒ Failed to get bundler transaction result:",e),{success:!1,error:this.formatErrorMessage(e)}}}async cancelTransaction(e){try{if(!e||"string"!=typeof e)throw Zt("transactionId","Transaction ID");this.logger.debug("๐Ÿšซ Cancelling transaction:",e);const t=await this.httpClient.delete(`${this.bundleEndpoint}/${e}`);return this.logger.debug("๐Ÿ—‘๏ธ Transaction cancellation response:",t),{success:!0,data:t}}catch(e){return this.logger.error("โŒ Failed to cancel transaction:",e),{success:!1,error:this.formatErrorMessage(e)}}}async getHealthStatus(){try{this.logger.debug("๐Ÿฅ Checking bundle service health");const e=await this.httpClient.get(`${this.bundleEndpoint}/health`);return this.logger.debug("๐Ÿ’š Bundle service health:",e),{success:!0,data:e}}catch(e){return this.logger.error("โŒ Bundle service health check failed:",e),{success:!1,error:this.formatErrorMessage(e)}}}async buyToken(e){this.ensureTradingServicesAvailable();const{tokenName:t,amount:a,type:n,expectedAmount:r,maxAcceptableReverseBondingCurveFee:o,maxAcceptableReverseBondingCurveFeeSlippageFactor:s,slippageToleranceFactor:i}=e,c=i??this.defaultSlippageToleranceFactor,l=s??this.defaultMaxAcceptableReverseBondingCurveFeeSlippageFactor;let u=o||"0";o&&(u=za(o,l,"buy-exact"),this.logger.debug("Reverse bonding curve fee slippage applied:",{baseFee:o,slippageFactor:l,adjustedMaxFee:u}));const d=await this.resolveTokenNameToVault(t);if(!d)throw Yt(t);if("native"===n){if(!r)throw new v("expectedAmount is required for native buy operations. Use getBuyTokenAmount() first to calculate expected tokens.","expectedAmount","EXPECTED_AMOUNT_REQUIRED");const e=za(r,c,"buy-native");this.logger.debug("BuyNative slippage applied:",{originalExpectedTokens:r,slippageFactor:c,adjustedMinTokens:e});const t=new $a.BuyNativeDto(d,a,e,{maxAcceptableReverseBondingCurveFee:u});return await this.executeBundleTransaction(t,"BuyWithNative",d)}{if(!r)throw new v("expectedAmount is required for exact buy operations. Use getBuyTokenAmount() first to calculate expected GALA cost.","expectedAmount","EXPECTED_AMOUNT_REQUIRED");const e=za(r,c,"buy-exact");this.logger.debug("BuyExact slippage applied:",{originalExpectedGalaCost:r,slippageFactor:c,adjustedMaxGalaCost:e});const t=new $a.BuyExactDto(d,a,e,{maxAcceptableReverseBondingCurveFee:u});return await this.executeBundleTransaction(t,"BuyExactToken",d)}}async sellToken(e){this.ensureTradingServicesAvailable();const{tokenName:t,amount:a,type:n,expectedAmount:r,maxAcceptableReverseBondingCurveFee:o,maxAcceptableReverseBondingCurveFeeSlippageFactor:s,slippageToleranceFactor:i}=e,c=i??this.defaultSlippageToleranceFactor,l=s??this.defaultMaxAcceptableReverseBondingCurveFeeSlippageFactor;let u=o||"0";o&&(u=za(o,l,"buy-exact"),this.logger.debug("Reverse bonding curve fee slippage applied:",{baseFee:o,slippageFactor:l,adjustedMaxFee:u}));const d=await this.resolveTokenNameToVault(t);if(!d)throw Yt(t);if("exact"===n){if(!r)throw new v("expectedAmount is required for exact sell operations. Use getSellTokenAmount() first to calculate expected GALA.","expectedAmount","EXPECTED_AMOUNT_REQUIRED");const e=za(r,c,"sell-exact");this.logger.debug("SellExact slippage applied:",{originalExpectedGala:r,slippageFactor:c,adjustedMinGala:e});const t=new $a.SellExactDto(d,a,e,{maxAcceptableReverseBondingCurveFee:o||"0"});return await this.executeBundleTransaction(t,"SellExactToken",d)}{if(!r)throw new v("expectedAmount is required for native sell operations. Use getSellTokenAmount() first to calculate tokens to sell.","expectedAmount","EXPECTED_AMOUNT_REQUIRED");const e=za(r,c,"sell-native");this.logger.debug("SellNative slippage applied:",{originalExpectedTokensToSell:r,slippageFactor:c,adjustedMaxTokensToSell:e});const t=new $a.SellNativeDto(d,a,e,{maxAcceptableReverseBondingCurveFee:o||"0"});return await this.executeBundleTransaction(t,"SellWithNative",d)}}ensureTradingServicesAvailable(){if(!this.signatureService||!this.tokenKeyService)throw ta("Trading services not available. BundleService requires walletProvider and userAddress for trading operations.","walletProvider");if(!this.userAddress)throw Zt("userAddress","User address")}async executeBundleTransaction(e,t,a){this.ensureTradingServicesAvailable();try{e.uniqueKey=`galaswap - operation - ${i.v4()}-${Date.now()}-${this.userAddress}`;const n=await this.signatureService.signDTO(e,t,this.userAddress),r=this.tokenKeyService.generateStringsInstructions(a),o={stringsInstructions:r,method:t,signedDto:n};this.logger.debug("๐Ÿ“ฆ Bundle transaction data:",{method:t,stringsInstructions:r,dtoKeys:Object.keys(n)});const s=await this.submitTransaction(o);if(s.success&&s.data)return this.logger.debug("โœ… Bundle transaction submitted:",s.data),{success:!0,data:{transactionId:s.data,message:"Transaction submitted successfully. Monitor WebSocket for completion."}};throw new Error(s.error||"Bundle transaction failed")}catch(e){throw this.logger.error("โŒ Bundle transaction error:",e),e}}async resolveTokenNameToVault(e){return await this.tokenResolver.resolveTokenToVault(e)}}!function(e){e.PROCESSED="PROCESSED",e.COMPLETED="COMPLETED",e.SUCCESS="SUCCESS",e.FAILED="FAILED",e.ERROR="ERROR",e.PROCESSING="PROCESSING",e.PENDING="PENDING"}(Ma||(Ma={})),e.SDKTransactionStatus=void 0,(Ra=e.SDKTransactionStatus||(e.SDKTransactionStatus={})).PENDING="pending",Ra.PROCESSING="processing",Ra.COMPLETED="completed",Ra.FAILED="failed",Ra.TIMEOUT="timeout";const qa={[Ma.PROCESSED]:e.SDKTransactionStatus.COMPLETED,[Ma.COMPLETED]:e.SDKTransactionStatus.COMPLETED,[Ma.SUCCESS]:e.SDKTransactionStatus.COMPLETED,[Ma.FAILED]:e.SDKTransactionStatus.FAILED,[Ma.ERROR]:e.SDKTransactionStatus.FAILED,[Ma.PROCESSING]:e.SDKTransactionStatus.PROCESSING,[Ma.PENDING]:e.SDKTransactionStatus.PENDING};class ja{constructor(e,t=!1){this.socket=null,this.listeners=new Map,this.timeouts=new Map,this.reconnectCount=0,this.hasOnAnyListener=!1,this.config={reconnectAttempts:5,reconnectDelay:2e3,timeout:3e5,...e},this.debug=t,this.logger=new g({debug:t,context:"WebSocketService"}),this.isSocketIOAvailable=this.checkSocketIOAvailability()}checkSocketIOAvailability(){try{return"function"==typeof c.io||(this.logger.warn('โš ๏ธ Socket.IO client not available. Install "socket.io-client" package.'),!1)}catch(e){return this.logger.warn("โš ๏ธ Socket.IO availability check failed:",e),!1}}async connect(){return new Promise((e,t)=>{try{if(!this.isSocketIOAvailable){const e=new Error('Socket.IO not available in current environment. Install "socket.io-client" package.');return this.logger.error("โŒ Socket.IO connection failed:",e.message),void t(e)}this.logger.debug("๐Ÿ”Œ Connecting to Socket.IO server:",this.config.url),this.socket=c.io(this.config.url,{transports:["websocket"],reconnection:!0,reconnectionAttempts:this.config.reconnectAttempts||5,reconnectionDelay:this.config.reconnectDelay||2e3}),this.socket.on("connect",()=>{this.logger.debug("โœ… Socket.IO connected successfully:",this.socket?.id),this.logger.debug("๐Ÿ“ก Connected to bundle backend WebSocket:",this.config.url),this.logger.debug("๐Ÿ”— Ready to monitor transaction updates"),this.reconnectCount=0,e()}),this.socket.on("connect_error",e=>{this.logger.error("โŒ Socket.IO connection error:",e),t(e)}),this.socket.on("disconnect",e=>{this.logger.debug(`๐Ÿ”Œ Socket.IO disconnected: ${e}`),this.handleReconnect()}),this.socket.on("error",e=>{this.logger.error("โŒ Socket.IO error:",e)}),this.debug&&(this.socket.onAny((e,...t)=>{this.logger.debug(`๐Ÿ“ก [WebSocket Event] "${e}":`,JSON.stringify(t,null,2))}),this.hasOnAnyListener=!0)}catch(e){t(e)}})}async monitorTransaction(t,a){this.listeners.set(t,a),this.logger.debug(`๐Ÿ“ก Starting to monitor transaction: ${t}`),this.logger.debug(`๐Ÿ“ก WebSocket connected: ${!!this.socket&&this.socket.connected}`);const n=setTimeout(()=>{if(this.listeners.has(t)){const n={transactionId:t,status:e.SDKTransactionStatus.TIMEOUT,message:"Transaction monitoring timeout - no response after 60 seconds",timestamp:Date.now()};this.logger.debug(`๐Ÿ“ก Transaction timeout for ${t}`),a(n),this.listeners.delete(t),this.timeouts.delete(t),this.socket?.off(t)}},6e4);if(this.timeouts.set(t,n),this.socket&&this.socket.connected)this.socket.off(t),this.logger.debug(`๐Ÿ“ก Listening for transaction updates: ${t}`),this.logger.debug(`๐Ÿ“ก WebSocket connection ID: ${this.socket.id}`),this.logger.debug(`๐Ÿ“ก WebSocket URL: ${this.config.url}`),this.socket.on(t,n=>{this.logger.debug(`๐Ÿ“ก Socket.IO transaction update for ${t}:`,JSON.stringify(n,null,2));const r=n?.status||n?.Status||n?.data?.status||n?.data?.Status;let o=n?.message||n?.Message||n?.data?.message||n?.data?.Message||n?.error||n?.data?.error;o&&"string"==typeof o||(o=r===Ma.FAILED||r===Ma.ERROR?"Transaction failed - check transaction details":r===Ma.COMPLETED||r===Ma.PROCESSED||r===Ma.SUCCESS?"Transaction completed successfully":r?`Transaction status: ${r}`:"Unknown transaction status");const s={transactionId:t,status:this.mapSocketStatus(r),message:o,timestamp:Date.now(),blockHash:n?.blockHash||n?.data?.blockHash,gasUsed:n?.gasUsed||n?.data?.gasUsed};if(this.logger.debug(`๐Ÿ“ก Mapped status for ${t}: ${r} -> ${s.status}`),this.logger.debug(`๐Ÿ“ก Final message: "${o}"`),a(s),s.status===e.SDKTransactionStatus.COMPLETED||s.status===e.SDKTransactionStatus.FAILED){this.listeners.delete(t);const e=this.timeouts.get(t);e&&(clearTimeout(e),this.timeouts.delete(t)),this.socket?.off(t),this.logger.debug(`๐Ÿ“ก Cleaned up listener for ${t} (${s.status})`)}});else{const n={transactionId:t,status:e.SDKTransactionStatus.FAILED,message:"WebSocket not connected - cannot monitor transaction",timestamp:Date.now()};a(n),this.listeners.delete(t),this.timeouts.delete(t)}}async waitForTransaction(t){return new Promise((a,n)=>{this.monitorTransaction(t,t=>{t.status===e.SDKTransactionStatus.COMPLETED?a(t):t.status!==e.SDKTransactionStatus.FAILED&&t.status!==e.SDKTransactionStatus.TIMEOUT||n(new Error(`Transaction ${t.status}: ${t.message}`))})})}mapSocketStatus(t){const a=t?.toUpperCase();return qa[a]||e.SDKTransactionStatus.PENDING}async handleReconnect(){this.reconnectCount<this.config.reconnectAttempts?(this.reconnectCount++,this.logger.debug(`๐Ÿ”„ Attempting Socket.IO reconnect ${this.reconnectCount}/${this.config.reconnectAttempts}`),setTimeout(()=>{this.socket&&!this.socket.connected&&this.socket.connect()},this.config.reconnectDelay)):this.logger.error("โŒ Socket.IO max reconnection attempts reached")}disconnect(){this.socket&&(this.listeners.forEach((e,t)=>{this.socket?.off(t)}),this.listeners.clear(),this.timeouts.forEach(e=>{clearTimeout(e)}),this.timeouts.clear(),this.hasOnAnyListener&&(this.socket.offAny(),this.hasOnAnyListener=!1,this.logger.debug("๐Ÿงน Removed onAny debug listener")),this.socket.disconnect(),this.socket=null,this.logger.debug("๐Ÿ”Œ Socket.IO disconnected"))}isConnected(){return this.socket?.connected||!1}}class Wa{constructor(e){this.poolService=e,this.cache=new Map}async resolveTokenToVault(e){if(!E(e))throw new v("Token name is required and must be a non-empty string","tokenName","INVALID_TOKEN_NAME");const t=e.trim().toLowerCase(),a=this.get(t);if(a)return a;try{const a=await this.poolService.resolveTokenNameToVault(e);return a&&this.set(t,a),a}catch{return null}}async resolveTokenClassKey(e){const t=await this.resolveTokenToVault(e);if(!t)throw Yt(e);return this.parseVaultAddressToTokenClassKey(t)}get(e){return this.cache.get(e.toLowerCase())||null}set(e,t){this.cache.set(e.toLowerCase(),t)}clear(){this.cache.clear()}getStats(){return{size:this.cache.size,keys:Array.from(this.cache.keys())}}preWarm(e){for(const{tokenName:t,vaultAddress:a}of e)this.set(t,a)}parseVaultAddressToTokenClassKey(e){const t=e.split("|");if(2!==t.length)throw Jt("vaultAddress","format: service|Token$Unit$...$launchpad","Vault address");const a=t[1].split("$");if(a.length<4)throw Jt("vaultAddress","at least 4 parts after service|","Vault address");return{collection:a[0],category:a[1],type:a[2],additionalKey:a[3]}}}class Ha{}Ha.BASE_PRICE=1650667151e-14,Ha.PRICE_SCALING_FACTOR=1166069e-12,Ha.TRADING_FEE_FACTOR=.001,Ha.GAS_FEE="1",Ha.MIN_UNBONDING_FEE_FACTOR=0,Ha.MAX_UNBONDING_FEE_FACTOR=.5,Ha.NET_UNBONDING_FEE_FACTOR=.5,Ha.DEFAULT_LAUNCHPAD_TOKEN_MAX_SUPPLY=1e7;class Qa{constructor(){this.cache=new Map}getLRUKey(){const e=this.cache.keys().next().value;return void 0!==e?e:null}normalizeTokenName(e){return e.trim().toLowerCase().replace(/\s+/g," ").replace(/[\u0000-\u001F\u007F-\u009F\u200B-\u200D\uFEFF]/g,"")}warmFromPoolData(e,t){const a=this.normalizeTokenName(e),n=this.cache.get(a);if(this.cache.has(a)&&this.cache.delete(a),this.cache.size>=Qa.MAX_CACHE_SIZE){const e=this.getLRUKey();null!==e&&this.cache.delete(e)}this.cache.set(a,{...n,...t,lastUpdated:Date.now()})}set(e,t){const a=this.normalizeTokenName(e),n=this.cache.get(a);if(this.cache.has(a)&&this.cache.delete(a),this.cache.size>=Qa.MAX_CACHE_SIZE){const e=this.getLRUKey();null!==e&&this.cache.delete(e)}this.cache.set(a,{...n,...t,lastUpdated:Date.now()})}get(e){const t=this.normalizeTokenName(e);return this.cache.get(t)||null}getMaxSupply(e){const t=this.normalizeTokenName(e),a=this.cache.get(t);return a?.maxSupply||Ha.DEFAULT_LAUNCHPAD_TOKEN_MAX_SUPPLY.toString()}has(e){const t=this.normalizeTokenName(e);return this.cache.has(t)}clear(e){if(e){const t=this.normalizeTokenName(e);this.cache.delete(t)}else this.cache.clear()}dump(){const e={};return this.cache.forEach((t,a)=>{e[a]=t}),e}stats(){let e=Date.now(),t=0;return this.cache.forEach((a,n)=>{a.lastUpdated<e&&(e=a.lastUpdated);let r=0;r+=2*n.length,void 0!==a.reverseBondingCurveMinFeeFactor&&(r+=8),void 0!==a.reverseBondingCurveMaxFeeFactor&&(r+=8),void 0!==a.reverseBondingCurveNetFeeFactor&&(r+=8),r+=8,a.vaultAddress&&(r+=2*a.vaultAddress.length),a.maxSupply&&(r+=2*a.maxSupply.length),r+=32,t+=r}),{totalTokens:this.cache.size,cacheSize:t,oldestEntry:this.cache.size>0?e:0}}}function Xa(e){const t=function(e){const t=st(e);return t.success?[]:t.errors||["Unknown validation error"]}(e);if(t.length>0)throw new Error(`LaunchTokenData validation failed:\n${t.map(e=>`- ${e}`).join("\n")}`)}Qa.MAX_CACHE_SIZE=1e4;const Ya="/api/asset/launchpad-contract/CallNativeTokenIn",Za="/api/asset/launchpad-contract/CallNativeTokenOut",Ja="/api/asset/launchpad-contract/CallMemeTokenIn",en="/api/asset/launchpad-contract/CallMemeTokenOut";class tn extends n.ChainCallDTO{constructor(e){super(),this.tokenName=e.tokenName,this.tokenSymbol=e.tokenSymbol,this.tokenDescription=e.tokenDescription,this.tokenImage=e.tokenImage,this.preBuyQuantity=e.preBuyQuantity,this.websiteUrl=e.websiteUrl,this.telegramUrl=e.telegramUrl,this.twitterUrl=e.twitterUrl,this.tokenCategory=e.tokenCategory,this.tokenCollection=e.tokenCollection,this.uniqueKey=e.uniqueKey,e.reverseBondingCurveConfiguration&&(this.reverseBondingCurveConfiguration=e.reverseBondingCurveConfiguration)}}function an(e){return e&&"object"==typeof e&&"number"==typeof e.Status&&e.Data&&"object"==typeof e.Data&&"string"==typeof e.Data.calculatedQuantity&&e.Data.extraFees&&"object"==typeof e.Data.extraFees&&"string"==typeof e.Data.extraFees.reverseBondingCurve&&"string"==typeof e.Data.extraFees.transactionFees}const nn={NATIVE:"native",EXACT:"exact"},rn={LOCAL:"local",EXTERNAL:"external"};class on{static calculateBuyWithExact(e,t){const a=parseFloat(e),n=parseFloat(t),{BASE_PRICE:r,PRICE_SCALING_FACTOR:o,TRADING_FEE_FACTOR:i,GAS_FEE:c}=Ha,l=this.roundUp(r*(Math.exp((n+a)*o)-Math.exp(n*o))/o,8),u=new s(l).multipliedBy(i).toFixed();return{amount:l.toString(),reverseBondingCurveFee:"0",transactionFee:u,gasFee:c}}static calculateBuyWithNative(e,t){const a=parseFloat(e),n=parseFloat(t),{BASE_PRICE:r,PRICE_SCALING_FACTOR:o,TRADING_FEE_FACTOR:i,GAS_FEE:c}=Ha,l=Math.log(a*o/r+Math.exp(n*o))/o-n,u=new s(l).multipliedBy(i).toFixed();return{amount:l.toString(),reverseBondingCurveFee:"0",transactionFee:u,gasFee:c}}static calculateSellWithExact(e,t,a,n,r){const o=parseFloat(e),i=parseFloat(t),c=parseFloat(a),{BASE_PRICE:l,PRICE_SCALING_FACTOR:u,TRADING_FEE_FACTOR:d,GAS_FEE:h}=Ha,g=l*(Math.exp(i*u)-Math.exp((i-o)*u))/u,m=new s(g),p=n+i/c*(r-n),f=m.multipliedBy(p).toFixed(8,s.ROUND_UP),y=m.multipliedBy(d).toFixed();return{amount:g.toString(),reverseBondingCurveFee:f,transactionFee:y,gasFee:h}}static calculateSellWithNative(e,t,a,n,r){const o=parseFloat(e),i=parseFloat(t),c=parseFloat(a),{BASE_PRICE:l,PRICE_SCALING_FACTOR:u,TRADING_FEE_FACTOR:d,GAS_FEE:h}=Ha,g=i-Math.log(Math.exp(i*u)-o*u/l)/u,m=new s(o),p=n+i/c*(r-n),f=m.multipliedBy(p).toFixed(8,s.ROUND_UP),y=m.multipliedBy(d).toFixed();return{amount:g.toString(),reverseBondingCurveFee:f,transactionFee:y,gasFee:h}}static roundUp(e,t){const a=Math.pow(10,t);return Math.ceil(e*a)/a}}class sn{constructor(e,t,a,n,r,o,s="local"){this.http=e,this.tokenResolver=t,this.logger=a,this.bundleHttp=n,this.galaChainHttp=r,this.dexApiHttp=o,this.defaultCalculateAmountMode=s,this.metadataCache=new Qa}addIfDefined(e,t,a){return void 0!==a&&(e[t]=a),e}async uploadImageByTokenName(e){const{tokenName:t,options:a}=e;St(t);const n=`${t}.png`;ya(a.file,n,"image/png");try{const e=new FormData;if("undefined"!=typeof File&&a.file instanceof File)e.append("image",a.file);else{if(!Buffer.isBuffer(a.file))throw Jt("file","a File object (browser) or Buffer (Node.js)");{const n=`${a.tokenName||t}.png`,r=new Blob([a.file],{type:"image/png"});e.append("image",r,n)}}const n=await this.http.request({method:"POST",url:`/launchpad/upload-image?tokenName=${encodeURIComponent(a.tokenName||t)}`,data:e,headers:{}});if(!0===n.error||200!==n.status||!n.data?.imageUrl)throw ea(n.message||"Image upload failed - no URL returned",n.status);return n.data.imageUrl}catch(e){if(e instanceof Error&&e.message.includes("FormData"))throw ta("File upload failed: FormData not supported in this environment. Ensure you have proper polyfills for Node.js environments.","FormData");throw e}}async fetchPoolsFromAPI(e){bt(e),e.tokenName&&St(e.tokenName);const t={page:e.page.toString(),limit:e.limit.toString()};void 0!==e.type&&(t.type=e.type),void 0!==e.tokenName&&(t.tokenName=e.tokenName),void 0!==e.search&&(t.search=e.search);const a=m(t),n=await this.http.get("/launchpad/fetch-pool",a);if(!0===n.error||200!==n.status||!n.data)throw ea(n.message||"Failed to fetch pools",n.status);let r=[];const o=(await import("bignumber.js")).default;if(n.data.tokens)if(Array.isArray(n.data.tokens))r=n.data.tokens.map(e=>{const t=e.reverseBondingCurveMinFeePortion??"0",a=e.reverseBondingCurveMaxFeePortion??"0",n=!new o(t).isZero()||!new o(a).isZero();return{...e,reverseBondingCurveMinFeePortion:t,reverseBondingCurveMaxFeePortion:a,hasReverseBondingCurveFee:n,createdAt:new Date(e.created_at||e.createdAt)}});else{const e=n.data.tokens.reverseBondingCurveMinFeePortion??"0",t=n.data.tokens.reverseBondingCurveMaxFeePortion??"0",a=!new o(e).isZero()||!new o(t).isZero();r=[{...n.data.tokens,reverseBondingCurveMinFeePortion:e,reverseBondingCurveMaxFeePortion:t,hasReverseBondingCurveFee:a,createdAt:new Date(n.data.tokens.created_at||n.data.tokens.createdAt)}]}else n.data.pools&&Array.isArray(n.data.pools)&&(r=n.data.pools.map(e=>{const t=e.reverseBondingCurveMinFeePortion??"0",a=e.reverseBondingCurveMaxFeePortion??"0",n=!new o(t).isZero()||!new o(a).isZero();return{...e,reverseBondingCurveMinFeePortion:t,reverseBondingCurveMaxFeePortion:a,hasReverseBondingCurveFee:n,createdAt:new Date(e.created_at||e.createdAt)}}));const{extractMetadataFromPoolData:s,isValidPoolForCaching:i}=await Promise.resolve().then(function(){return yn});r.forEach(e=>{if(!i(e))return void this.logger.debug("Skipping pool with invalid structure for caching",e);const t=s(e,this.logger);t&&this.warmCacheFromPoolData(e.tokenName,t)});const c=n.data.count??n.data.total??0,l=n.data.page??e.page??1,u=n.data.limit??e.limit??10,d=u>0?Math.ceil(c/u):1;return{pools:r,page:l,limit:u,total:c,totalPages:d,hasNext:l<d,hasPrevious:l>1}}async _getAmount(e){if(Ft(e),!this.galaChainHttp)throw ta("GalaChain client not configured. Direct GalaChain calls require galaChainHttp client.","galaChainHttp");const{endpoint:t,body:a}=((e,t,a,n)=>{if("NATIVE"===e&&"IN"===t)return{endpoint:Ya,body:{vaultAddress:a,tokenQuantity:n,IsPreMint:!1}};if("NATIVE"===e&&"OUT"===t)return{endpoint:Za,body:{vaultAddress:a,tokenQuantity:n,IsPreMint:!1}};if("MEME"===e&&"IN"===t)return{endpoint:Ja,body:{vaultAddress:a,nativeTokenQuantity:n,IsPreMint:!1}};if("MEME"===e&&"OUT"===t)return{endpoint:en,body:{vaultAddress:a,nativeTokenQuantity:n,IsPreMint:!1}};throw Jt("type-method","one of: NATIVE-IN, NATIVE-OUT, MEME-IN, MEME-OUT")})(e.type,e.method,e.vaultAddress,e.amount);try{const e=await this.galaChainHttp.post(t,a);if(!an(e))throw ea("Malformed response data from GalaChain gateway");if(1!==e.Status)throw ea(`GalaChain calculation failed with status ${e.Status}`,e.Status);const{calculatedQuantity:n,extraFees:r}=e.Data;return{amount:n,reverseBondingCurveFee:r.reverseBondingCurve,transactionFee:r.transactionFees,gasFee:"1"}}catch(n){throw this.logger.error(`GalaChain ${e.type}-${e.method} operation failed:`,{endpoint:t,requestBody:a,error:n instanceof Error?n.message:n}),n}}async checkPool(e){It(e),e.tokenName&&St(e.tokenName);const t=m(e),a=await this.http.get("/launchpad/check-pool",t);if(!0===a.error||200!==a.status)throw ea(a.message||"Failed to check pool",a.status);const n=a.data;return e.symbol?n?.isSymbolExist??!1:e.tokenName?n?.isNameExist??!1:n?.exists??!1}async fetchVolumeData(e){if(!na(e))throw new v("Invalid options provided. Expected { tokenName: string, from?: number, to?: number, resolution?: number }","options","INVALID_OPTIONS");const{tokenName:t,from:a,to:n,resolution:r}=e;if(St(t),!a||!n||!r)throw new v("Graph options (from, to, resolution) are required","options","MISSING_GRAPH_OPTIONS");const o={tokenName:t,from:a,to:n,resolution:r};Ct(o);const s=m(o),i=await this.http.get("/launchpad/get-graph-data",s);if(!0===i.error||200!==i.status||!i.data)throw ea(i.message||"Failed to fetch graph data",i.status);return{dataPoints:i.data}}async fetchPools(e={}){let t;"recent"===e.type?t="RECENT":"popular"===e.type&&(t="POPULAR");const a={page:e.page||1,limit:e.limit||10};return e.search&&(a.search=e.search),e.tokenName&&(a.tokenName=e.tokenName),t&&(a.type=t),this.fetchPoolsFromAPI(a)}async isTokenNameAvailable(e){try{return!await this.checkPool({tokenName:e})}catch{return!1}}async isTokenSymbolAvailable(e){try{return!await this.checkPool({symbol:e})}catch{return!1}}async calculateBuyAmount(e){if(!e||"object"!=typeof e)throw new v("Invalid options provided. Expected an options object.","options","INVALID_OPTIONS");const{tokenName:t,amount:a,type:n,currentSupply:r}=e,o=e.mode??this.defaultCalculateAmountMode;if("local"!==o&&"external"!==o)throw new v(`Invalid calculation mode "${o}". Must be "local" or "external".`,"mode","INVALID_CALCULATION_MODE");if(!t||"string"!=typeof t)throw new v("Token name is required and must be a string","tokenName","INVALID_TOKEN_NAME");if(!a||"string"!=typeof a)throw new v("Amount is required and must be a string","amount","INVALID_AMOUNT");if(n!==nn.NATIVE&&n!==nn.EXACT)throw new v('Type must be either "native" or "exact"',"type","INVALID_TYPE");return"external"===o?this.calculateBuyAmountExternal({tokenName:t,amount:a,type:n}):this.calculateBuyAmountLocal(this.addIfDefined({tokenName:t,amount:a,type:n},"currentSupply",r))}async calculateBuyAmountExternal(e){const{tokenName:t,amount:a,type:n}=e,r=await this.tokenResolver.resolveTokenToVault(t);if(!r)throw new v(`Token "${t}" not found. Please verify the token name is correct.`,"tokenName","TOKEN_NOT_FOUND");return n===nn.EXACT?this._getAmount({type:"NATIVE",method:"IN",vaultAddress:r,amount:a}):this._getAmount({type:"MEME",method:"OUT",vaultAddress:r,amount:a})}async calculateSellAmount(e){const{tokenName:t,amount:a,type:n,currentSupply:r,maxSupply:o,reverseBondingCurveMaxFeeFactor:s,reverseBondingCurveMinFeeFactor:i}=e,c=e.mode??this.defaultCalculateAmountMode;if("local"!==c&&"external"!==c)throw new v(`Invalid calculation mode "${c}". Must be "local" or "external".`,"mode","INVALID_CALCULATION_MODE");if(!t||"string"!=typeof t)throw new v("Token name is required and must be a string","tokenName","INVALID_TOKEN_NAME");if(!a||"string"!=typeof a)throw new v("Amount is required and must be a string","amount","INVALID_AMOUNT");if(n!==nn.EXACT&&n!==nn.NATIVE)throw new v('Type must be either "exact" or "native"',"type","INVALID_TYPE");if("external"===c)return this.calculateSellAmountExternal({tokenName:t,amount:a,type:n});{let e={tokenName:t,amount:a,type:n};return e=this.addIfDefined(e,"currentSupply",r),e=this.addIfDefined(e,"maxSupply",o),e=this.addIfDefined(e,"reverseBondingCurveMaxFeeFactor",s),e=this.addIfDefined(e,"reverseBondingCurveMinFeeFactor",i),this.calculateSellAmountLocal(e)}}async calculateSellAmountExternal(e){const{tokenName:t,amount:a,type:n}=e,r=await this.tokenResolver.resolveTokenToVault(t);if(!r)throw new v(`Token "${t}" not found. Please verify the token name is correct.`,"tokenName","TOKEN_NOT_FOUND");return n===nn.EXACT?this._getAmount({type:"NATIVE",method:"OUT",vaultAddress:r,amount:a}):this._getAmount({type:"MEME",method:"IN",vaultAddress:r,amount:a})}async calculateBuyAmountLocal(e){const{tokenName:t,amount:a,type:n,currentSupply:r}=e;if(!a||"string"!=typeof a)throw new v("Amount is required and must be a string","amount","INVALID_AMOUNT");if(n!==nn.NATIVE&&n!==nn.EXACT)throw new v('Type must be either "native" or "exact"',"type","INVALID_TYPE");void 0!==r&&Pt(r,"currentSupply");const o=!r;if(o&&!t)throw new v("Token name is required when currentSupply is not provided","tokenName","MISSING_TOKEN_NAME");t&&St(t);let s=r;if(o){s=(await this.fetchPoolDetailsForCalculation(t)).currentSupply}return n===nn.EXACT?on.calculateBuyWithExact(a,s):on.calculateBuyWithNative(a,s)}async calculateSellAmountLocal(e){const{tokenName:t,amount:a,type:n,currentSupply:r,maxSupply:o,reverseBondingCurveMaxFeeFactor:s,reverseBondingCurveMinFeeFactor:i}=e;if(!a||"string"!=typeof a)throw new v("Amount is required and must be a string","amount","INVALID_AMOUNT");if(n!==nn.EXACT&&n!==nn.NATIVE)throw new v('Type must be either "exact" or "native"',"type","INVALID_TYPE");void 0!==r&&Pt(r,"currentSupply");const c=!r||!o||void 0===s||void 0===i;if(c&&!t)throw new v("Token name is required when currentSupply, maxSupply, or fee factors are not provided","tokenName","MISSING_TOKEN_NAME");t&&St(t);let l=r,u=o,d=s,h=i;if(c&&t){const e=this.metadataCache.get(t);u=u??this.metadataCache.getMaxSupply(t),d=d??e?.reverseBondingCurveMaxFeeFactor,h=h??e?.reverseBondingCurveMinFeeFactor,l||(l=await this.fetchCurrentSupply(t));if(void 0===d||void 0===h){const e=await this.fetchPoolDetailsForCalculation(t);d=d??e.reverseBondingCurveMaxFeeFactor,h=h??e.reverseBondingCurveMinFeeFactor}}return n===nn.EXACT?on.calculateSellWithExact(a,l,u,h,d):on.calculateSellWithNative(a,l,u,h,d)}async calculateBuyAmountForGraduation(e){const t="string"==typeof e?{tokenName:e}:e;if("object"==typeof e&&(!(a=e)||"object"!=typeof a||"string"!=typeof a.tokenName||void 0!==a.calculateAmountMode&&"local"!==a.calculateAmountMode&&"external"!==a.calculateAmountMode||void 0!==a.currentSupply&&"string"!=typeof a.currentSupply))throw new Error("Invalid CalculateBuyAmountForGraduationOptions provided");var a;const{tokenName:n,calculateAmountMode:r,currentSupply:o}=t;St(n);const s=await this.tokenResolver.resolveTokenToVault(n);if(!s)throw new v(y(n),"tokenName","VAULT_NOT_FOUND");if(!this.galaChainHttp)throw ta("GalaChain HTTP client not configured");const i=await this.galaChainHttp.post("/api/asset/launchpad-contract/FetchSaleDetails",{vaultAddress:s});if(1!==i.Status)throw ea(`Failed to fetch pool details: Status ${i.Status}`,i.Status);const c=i.Data,l=(await import("bignumber.js")).default,u=o??new l(c.maxSupply).minus(c.sellingTokenQuantity).toFixed(),d=c.sellingTokenQuantity;if("0"===d)throw new v(`Token ${n} is already graduated (no tokens remaining in pool)`,"tokenName","ALREADY_GRADUATED");const h={tokenName:n,amount:d,type:"exact",currentSupply:u};return void 0!==r&&(h.mode=r),await this.calculateBuyAmount(h)}async launchToken(e){if(!this.bundleHttp)throw ta("Bundle backend client not configured. LaunchToken requires bundleHttp client.","bundleHttp");Xa(e);const t=e.preBuyQuantity||"0";if(isNaN(Number(t))||Number(t)<0)throw new v("Pre-buy quantity must be a valid non-negative number string","preBuyQuantity","INVALID_PRE_BUY_QUANTITY");if(e.reverseBondingCurveConfiguration){const{minFeePortion:t,maxFeePortion:a}=e.reverseBondingCurveConfiguration,n=Number(t),r=Number(a);if(isNaN(n)||isNaN(r)||n<=0||r<=0||n>=r)throw new v("Reverse bonding curve configuration must have valid min/max fee portions with min < max","reverseBondingCurveConfiguration","INVALID_BONDING_CURVE_CONFIG")}let a="";if(e.tokenImage)if(e.tokenImage instanceof File||Buffer.isBuffer(e.tokenImage)){const t=await this.uploadImageByTokenName({tokenName:e.tokenName,options:{file:e.tokenImage,tokenName:e.tokenName}});if(!t)throw ea("Image upload failed: No URL returned");a=t}else"string"==typeof e.tokenImage&&(a=e.tokenImage);const r=`galaswap - operation - ${i.v4()}-${Date.now()}-${this.http.getAddress()}`,o={tokenName:e.tokenName.trim(),tokenSymbol:e.tokenSymbol.trim().toUpperCase(),tokenDescription:e.tokenDescription.trim(),tokenImage:a.trim(),preBuyQuantity:t.toString(),websiteUrl:e.websiteUrl||"",telegramUrl:e.telegramUrl||"",twitterUrl:e.twitterUrl||"",tokenCategory:e.tokenCategory||"Unit",tokenCollection:e.tokenCollection||"Token",uniqueKey:r};e.reverseBondingCurveConfiguration&&(o.reverseBondingCurveConfiguration={minFeePortion:e.reverseBondingCurveConfiguration.minFeePortion.toString(),maxFeePortion:e.reverseBondingCurveConfiguration.maxFeePortion.toString()});const s=new tn(o),c=await this.http.signWithGalaChain("CreateSale",s,n.SigningType.SIGN_TYPED_DATA),{signature:l,types:u,domain:d,prefix:h}=c,g={tokenName:s.tokenName,tokenSymbol:s.tokenSymbol,tokenDescription:s.tokenDescription,tokenImage:s.tokenImage,preBuyQuantity:s.preBuyQuantity,websiteUrl:s.websiteUrl,telegramUrl:s.telegramUrl,twitterUrl:s.twitterUrl,tokenCategory:s.tokenCategory,tokenCollection:s.tokenCollection,uniqueKey:s.uniqueKey,signature:l,types:u,domain:d,...h&&{prefix:h},...s.reverseBondingCurveConfiguration&&{reverseBondingCurveConfiguration:s.reverseBondingCurveConfiguration}},m=`${e.tokenName.trim()}$Unit$none$none`,p="GALA$Unit$none$none";let f;if(parseFloat(t)>0){const e=`$service$${m}$launchpad`;f=[e,`$token$${m}$${e}`,`$tokenBalance$${m}$${e}`,`$tokenBalance$${m}$${e}`,`$tokenBalance$${p}$${e}`,`$tokenBalance$${p}$${e}`]}else{const e=`$service$${m}$launchpad`;f=[e,`$token$${m}$${e}`,`$tokenBalance$${m}$${e}`]}const y={signedDto:g,stringsInstructions:f,method:"CreateSale"},A=await this.bundleHttp.post("/bundle",y);if(A.error||!A.data)throw ea(A.message||"Token launch failed");return A.data}async fetchTokenDistribution(e){if(!e)throw Zt("tokenName","Token name");St(e);const t=await this.tokenResolver.resolveTokenToVault(e);if(!t)throw new v(y(e),"tokenName","VAULT_NOT_FOUND");this.metadataCache.set(e,{vaultAddress:t});const a=encodeURIComponent(t),n=await this.http.get(`/holders/${a}`);if(!0===n.error||200!==n.status||!n.data)throw ea(n.message||"Failed to fetch token distribution",n.status);return{holders:n.data.holders||[],totalSupply:n.data.totalSupply||"0",totalHolders:n.data.totalHolders||0,lastUpdated:new Date}}async fetchTokenBadges(e){if(!e)throw Zt("tokenName","Token name");St(e);const t=await this.http.get("/launchpad/get-badge/",{tokenName:e});if(t.error||!t.data)throw ea(t.message||"Failed to fetch token badges");return{volumeBadges:t.data.volumeBadge||[],engagementBadges:t.data.engagementBadge||[]}}async hasTokenBadgeByTokenName(e){const{tokenName:t,badgeType:a,badgeName:n}=e;try{const e=await this.fetchTokenBadges(t);if(!e)return!1;const r=("volume"===a?e.volumeBadges:e.engagementBadges).find(e=>e.badgeName===n);return r?.isActive||!1}catch{return!1}}async calculateInitialBuyAmount(e){if(!(t=e)||"object"!=typeof t||"string"!=typeof t.nativeTokenQuantity||void 0!==t.vaultAddress&&"string"!=typeof t.vaultAddress)throw new v("Invalid pre-mint calculation data","data","INVALID_PRE_MINT_DATA");var t;if(!this.galaChainHttp)throw ta("GalaChain HTTP client not available. Please initialize SDK with galaChainBaseUrl.","galaChainHttp");try{const t={vaultAddress:"service|testToken",nativeTokenQuantity:e.nativeTokenQuantity,IsPreMint:!0},a=await this.galaChainHttp.post("/api/asset/launchpad-contract/CallMemeTokenOut",t);if(!an(a))throw ea("Malformed response data from GalaChain gateway");if(1!==a.Status)throw ea(`GalaChain calculation failed with status ${a.Status}`,a.Status);const{calculatedQuantity:n,extraFees:r}=a.Data;return{amount:n,reverseBondingCurveFee:r.reverseBondingCurve,transactionFee:r.transactionFees,gasFee:"1"}}catch(e){if(e instanceof Error){const t=new Error(`Pre-mint calculation failed: ${e.message}`);throw e.stack&&(t.stack=e.stack),t}throw new Error(`Pre-mint calculation failed: ${String(e)}`)}}async fetchPoolDetailsForCalculation(e){const t=await this.tokenResolver.resolveTokenToVault(e);if(!t)throw new v(y(e),"tokenName","VAULT_NOT_FOUND");if(!this.galaChainHttp)throw ta("GalaChain HTTP client not configured");const a=await this.galaChainHttp.post("/api/asset/launchpad-contract/FetchSaleDetails",{vaultAddress:t});if(1!==a.Status)throw ea(`Failed to fetch pool details: Status ${a.Status}`,a.Status);const n=a.Data,r=new(0,(await import("bignumber.js")).default)(n.maxSupply).minus(n.sellingTokenQuantity).toFixed(),o=n.sellingTokenQuantity,s=n.maxSupply;let i=.5,c=0;n.reverseBondingCurveConfiguration?(i=parseFloat(n.reverseBondingCurveConfiguration.maxFeePortion),c=parseFloat(n.reverseBondingCurveConfiguration.minFeePortion)):this.logger.debug(`Pool details missing reverseBondingCurveConfiguration for token ${e}, using defaults (min: 0.0, max: 0.5)`);const l=i-c;return this.metadataCache.set(e,{maxSupply:s,reverseBondingCurveMaxFeeFactor:i,reverseBondingCurveMinFeeFactor:c,reverseBondingCurveNetFeeFactor:l}),{currentSupply:r,remainingTokens:o,maxSupply:s,reverseBondingCurveMaxFeeFactor:i,reverseBondingCurveMinFeeFactor:c,reverseBondingCurveNetFeeFactor:l}}async fetchCurrentSupply(e){St(e);const t=await this.tokenResolver.resolveTokenToVault(e);if(!t)throw new v(y(e),"tokenName","VAULT_NOT_FOUND");if(!this.galaChainHttp)throw ta("GalaChain HTTP client not configured");const a=await this.galaChainHttp.post("/api/asset/launchpad-contract/FetchSaleDetails",{vaultAddress:t});if(1!==a.Status)throw ea(`Failed to fetch pool details: Status ${a.Status}`,a.Status);const n=a.Data,r=new(0,(await import("bignumber.js")).default)(n.maxSupply).minus(n.sellingTokenQuantity).toFixed(),o=n.maxSupply;return this.metadataCache.set(e,{maxSupply:o}),r}getAddress(){return this.http.getAddress()}formatAddressForBackend(e){return Dt(e)}validateTokenName(e){return St(e)}validatePagination(e){return bt(e)}async fetchTokenSpotPrice(e){if(!this.dexApiHttp)throw ta("DEX API client not configured. Token price fetching requires dexApiHttp client.","dexApiHttp");if(!e||Array.isArray(e)&&0===e.length)throw Zt("symbols","At least one symbol");const t=Array.isArray(e)?e.join(","):e;try{const e=await this.dexApiHttp.request({method:"GET",url:"/v1/tokens",params:{symbols:t}}),a=[];return e.tokens&&Array.isArray(e.tokens)&&e.tokens.forEach(e=>{e.currentPrices&&e.symbol&&a.push({symbol:e.symbol,price:e.currentPrices.usd})}),a}catch(e){throw ea(`Failed to fetch token prices: ${e instanceof Error?e.message:e}`,void 0,e instanceof Error?e:void 0)}}async fetchLaunchpadTokenSpotPrice(e){const t="string"==typeof e?{tokenName:e}:e;if("object"==typeof e&&(!(a=e)||"object"!=typeof a||"string"!=typeof a.tokenName||void 0!==a.calculateAmountMode&&"local"!==a.calculateAmountMode&&"external"!==a.calculateAmountMode||void 0!==a.currentSupply&&"string"!=typeof a.currentSupply))throw new Error("Invalid FetchLaunchpadTokenSpotPriceOptions provided");var a;const{tokenName:n,calculateAmountMode:r,currentSupply:o}=t;if(!n||"string"!=typeof n)throw Zt("tokenName","Token name (string)");try{const e={tokenName:n,amount:"1",type:"native"};void 0!==r&&(e.mode=r),void 0!==o&&(e.currentSupply=o);const t=await this.calculateBuyAmount(e),a=(await this.fetchTokenSpotPrice("GALA"))[0];if(!a)throw ea("GALA price not available");const s=Number(t.amount);if(s<=0)throw new v(`Invalid token amount calculation: ${s}`,"amount","INVALID_CALCULATION");const i=a.price/s;return{symbol:n.toUpperCase(),price:i}}catch(e){if(e instanceof Error)throw new Error(`Failed to calculate launchpad token spot price for ${n}: ${e.message}`);throw new Error(`Failed to calculate launchpad token spot price for ${n}: ${String(e)}`)}}warmCacheFromPoolData(e,t){this.metadataCache.warmFromPoolData(e,t)}getCacheStats(){return this.metadataCache.stats()}clearCache(e){this.metadataCache.clear(e)}}const cn={PROD:{launchpadBaseUrl:"https://lpad-backend-prod1.defi.gala.com",galaChainBaseUrl:"https://gateway-mainnet.galachain.com",bundleBaseUrl:"https://bundle-backend-prod1.defi.gala.com",webSocketUrl:"https://bundle-backend-prod1.defi.gala.com",dexApiBaseUrl:"https://dex-api-platform-dex-prod-gala.gala.com",launchpadFrontendUrl:"https://lpad-frontend-prod1.defi.gala.com"},STAGE:{launchpadBaseUrl:"https://lpad-backend-dev1.defi.gala.com",galaChainBaseUrl:"https://galachain-gateway-chain-platform-stage-chain-platform-eks.stage.galachain.com",bundleBaseUrl:"https://bundle-backend-dev1.defi.gala.com",webSocketUrl:"https://bundle-backend-dev1.defi.gala.com",dexApiBaseUrl:"https://dex-api-platform-dex-stage-gala.gala.com",launchpadFrontendUrl:"https://lpad-frontend-dev1.defi.gala.com"}};function ln(e){return cn[e]}class un extends Error{constructor(e,t){super(e),this.cause=t,this.name="WebSocketError"}}class dn extends Error{constructor(e,t,a){super(`Transaction ${e} failed with status: ${t}${a?` - ${a}`:""}`),this.transactionId=e,this.status=t,this.name="TransactionFailedError"}}function hn(e,t){if(!e)throw new un(`Invalid WebSocket response received for transaction ${t}: response is null or undefined`);if("object"!=typeof e)throw new un(`Invalid WebSocket response received for transaction ${t}: expected object, got ${typeof e}`);if(!Object.prototype.hasOwnProperty.call(e,"status")&&!Object.prototype.hasOwnProperty.call(e,"Status"))throw new un(`Invalid WebSocket response received for transaction ${t}: missing status field`)}function gn(e,t,a,n){hn(e,t);const r=e?.data||{};if(!(o=r)||"object"!=typeof o||void 0!==o.inputQuantity&&"string"!=typeof o.inputQuantity||void 0!==o.outputQuantity&&"string"!=typeof o.outputQuantity||void 0!==o.totalFees&&"string"!=typeof o.totalFees||void 0!==o.vaultAddress&&"string"!=typeof o.vaultAddress)throw new un(`Invalid trade data received for transaction ${t}`);var o;const s={transactionId:t,type:a,method:"native"===n.type?"native":"exact",inputAmount:r.inputQuantity||n.amount,outputAmount:r.outputQuantity||n.expectedAmount||"0",totalFees:r.totalFees||"0",tokenName:n.tokenName,vaultAddress:r.vaultAddress||"",blockHash:e.blockHash,gasUsed:e.gasUsed,timestamp:Date.now()};return void 0!==n.slippageToleranceFactor&&(s.slippageTolerance=n.slippageToleranceFactor),s}class mn{constructor(e){let t=null;t=e.env?ln(e.env):e.baseUrl?.includes("prod")?ln("PROD"):ln("STAGE"),this.config={baseUrl:t.launchpadBaseUrl,galaChainBaseUrl:t.galaChainBaseUrl,bundleBaseUrl:t.bundleBaseUrl,webSocketUrl:t.webSocketUrl,dexApiBaseUrl:t.dexApiBaseUrl,launchpadFrontendUrl:t.launchpadFrontendUrl,timeout:3e4,debug:!1,...e},this.logger=new g({debug:this.config.debug??!1,context:"LaunchpadSDK"}),this.validateConfiguration(),this.slippageToleranceFactor=void 0===e.slippageToleranceFactor?mn.DEFAULT_SLIPPAGE_TOLERANCE_FACTOR:this.parseSlippageToleranceFactor(e.slippageToleranceFactor),this.maxAcceptableReverseBondingCurveFeeSlippageFactor=void 0===e.maxAcceptableReverseBondingCurveFeeSlippageFactor?mn.DEFAULT_MAX_ACCEPTABLE_REVERSE_BONDING_CURVE_FEE_SLIPPAGE_FACTOR:this.parseFeeSlippageFactor(e.maxAcceptableReverseBondingCurveFeeSlippageFactor),this.calculateAmountMode=e.calculateAmountMode||mn.DEFAULT_CALCULATE_AMOUNT_MODE,this.auth=new h({wallet:e.wallet,messagePrefix:"Create a GalaChain Wallet"}),this.http=new p(this.auth,this.config),this.galaChainHttp=new p(this.auth,{...this.config,baseUrl:this.config.galaChainBaseUrl}),this.bundleHttp=new p(this.auth,{...this.config,baseUrl:this.config.bundleBaseUrl}),this.dexApiHttp=new p(this.auth,{...this.config,baseUrl:this.config.dexApiBaseUrl}),this.launchpadService=new wa(this.http),this.tokenResolverService=new Wa(this.launchpadService.poolService),this.launchpadAPI=new sn(this.http,this.tokenResolverService,this.logger,this.bundleHttp,this.galaChainHttp,this.dexApiHttp,this.calculateAmountMode),this.galaChainService=new Fa(this.galaChainHttp,e.wallet,this.tokenResolverService,e.debug||!1),this.dexService=new Ca(this.dexApiHttp),this.bundleService=new Va(this.bundleHttp,this.tokenResolverService,this.config.debug||!1,e.wallet,this.getAddress(),this.slippageToleranceFactor,this.maxAcceptableReverseBondingCurveFeeSlippageFactor),this.websocketService=new ja({url:this.config.webSocketUrl},this.config.debug)}createOverrideSdk(e){if(!e||"string"!=typeof e)throw ta("Invalid privateKey: must be a non-empty string","privateKey");if(!e.match(/^0x[a-fA-F0-9]{64}$/))throw ta('Invalid privateKey format: must be "0x" followed by 64 hexadecimal characters',"privateKey");const a=new t.Wallet(e),n={...this.config,wallet:a};return new mn(n)}getAddress(){return this.auth.getAddress()}getEthereumAddress(){return this.config.wallet.address}getConfig(){const{wallet:e,...t}=this.config;return{...t,slippageToleranceFactor:this.slippageToleranceFactor,maxAcceptableReverseBondingCurveFeeSlippageFactor:this.maxAcceptableReverseBondingCurveFeeSlippageFactor,calculateAmountMode:this.calculateAmountMode}}getUrlByTokenName(e){const t=this.config.launchpadFrontendUrl;if(!t)throw ta("launchpadFrontendUrl not configured in SDK","launchpadFrontendUrl");return`${t.replace(/\/$/,"")}/buy-sell/${e}`}async fetchPools(e){const t=await this.launchpadService.fetchPools(e||{});if(t.pools&&Array.isArray(t.pools)){const{extractMetadataFromPoolData:e,isValidPoolForCaching:a}=await Promise.resolve().then(function(){return yn});t.pools.forEach(t=>{if(!a(t))return void this.logger.debug("Skipping pool with invalid structure for caching",t);const n=e(t,this.logger);n&&this.launchpadAPI.warmCacheFromPoolData(t.tokenName,n)})}return t}async fetchAllPools(e){const t=await this.launchpadService.fetchAllPools(e);if(t.pools&&Array.isArray(t.pools)){const{extractMetadataFromPoolData:e,isValidPoolForCaching:a}=await Promise.resolve().then(function(){return yn});t.pools.forEach(t=>{if(!a(t))return void this.logger.debug("Skipping pool with invalid structure for caching",t);const n=e(t,this.logger);n&&this.launchpadAPI.warmCacheFromPoolData(t.tokenName,n)})}return t}async fetchTokenDistribution(e){return this.launchpadService.fetchTokenDistribution(e)}async fetchTokenBadges(e){return this.launchpadService.fetchTokenBadges(e)}async fetchTokenSpotPrice(e){return this.dexService.fetchTokenSpotPrice(e)}async fetchGalaSpotPrice(){const e=await this.dexService.fetchTokenSpotPrice("GALA");if(0===e.length)throw ea("Failed to fetch GALA price - no price data returned");const t=e.find(e=>"GALA"===e.symbol);if(!t)throw ea("GALA price not found in response");return t}async fetchLaunchpadTokenSpotPrice(e){return this.launchpadAPI.fetchLaunchpadTokenSpotPrice(e)}async fetchLaunchTokenFee(){return this.galaChainService.fetchLaunchTokenFee()}async fetchPoolDetails(e){const t=await this.resolveVaultAddress(e);if(!t)throw new Error(y(e));const a=(await this.galaChainService.fetchPoolDetails({vaultAddress:t})).Data,n=await this.launchpadAPI.fetchPoolDetailsForCalculation(e);return a.currentSupply=n.currentSupply,a.reverseBondingCurveMaxFeeFactor=n.reverseBondingCurveMaxFeeFactor,a.reverseBondingCurveMinFeeFactor=n.reverseBondingCurveMinFeeFactor,a.reverseBondingCurveNetFeeFactor=n.reverseBondingCurveNetFeeFactor,a}async fetchPoolDetailsForCalculation(e){return this.launchpadAPI.fetchPoolDetailsForCalculation(e)}async isTokenGraduated(e){return(await this.fetchPoolDetails(e)).isGraduated}async fetchVolumeData(e){return this.launchpadService.fetchVolumeData(e)}async fetchTrades(e){return this.launchpadService.fetchTrades(e)}async fetchGalaBalance(e){const{normalizeAddressInput:t}=await Promise.resolve().then(function(){return _t}),a=t(e)||this.getAddress();return this.galaChainService.fetchGalaBalance({owner:a,collection:"GALA",category:"Unit",additionalKey:"none",type:"none",instance:"0"})}async fetchTokenBalance(e){const{normalizeAddressInput:t}=await Promise.resolve().then(function(){return _t}),a=t(e.address);if(e.tokenId){const{normalizeToTokenInstanceKey:t}=await Promise.resolve().then(function(){return Ea}),n=t(e.tokenId),{collection:r,category:o,type:s,additionalKey:i}=n;return this.galaChainService.fetchTokenBalance({owner:a,collection:r,category:o,additionalKey:i,type:s,instance:"0"})}if(e.tokenName){const t=(await this.fetchTokensHeld({tokenName:e.tokenName,page:1,limit:1,...a&&{address:a}})).tokens[0];return t?{quantity:t.quantity,collection:t.collection||"Token",category:"Unit",tokenId:`${t.collection||"Token"}|Unit|${t.symbol}|none`,symbol:t.symbol,name:t.name}:null}throw Zt("tokenId or tokenName","Either tokenId or tokenName")}async fetchComments(e){return this.launchpadService.fetchComments(e)}async calculateBuyAmount(e){return this.launchpadAPI.calculateBuyAmount(e)}async calculateSellAmount(e){return this.launchpadAPI.calculateSellAmount(e)}async calculateBuyAmountLocal(e){return this.launchpadAPI.calculateBuyAmountLocal(e)}async calculateSellAmountLocal(e){return this.launchpadAPI.calculateSellAmountLocal(e)}async calculateBuyAmountExternal(e){return this.launchpadAPI.calculateBuyAmountExternal(e)}async calculateSellAmountExternal(e){return this.launchpadAPI.calculateSellAmountExternal(e)}async calculateBuyAmountForGraduation(e){return this.launchpadAPI.calculateBuyAmountForGraduation(e)}async graduateToken(e){const{tokenName:t,slippageToleranceFactor:a,maxAcceptableReverseBondingCurveFeeSlippageFactor:n,privateKey:r,calculateAmountMode:o,currentSupply:s}=e;let i=t;void 0===o&&void 0===s||(i={tokenName:t,...void 0!==o&&{calculateAmountMode:o},...void 0!==s&&{currentSupply:s}});const c=await this.calculateBuyAmountForGraduation(i),l={tokenName:t,amount:c.amount,type:"exact",expectedAmount:c.amount,maxAcceptableReverseBondingCurveFee:c.reverseBondingCurveFee,slippageToleranceFactor:this.slippageToleranceFactor};return void 0!==a&&(l.slippageToleranceFactor=a),void 0!==n&&(l.maxAcceptableReverseBondingCurveFeeSlippageFactor=n),void 0!==r&&(l.privateKey=r),await this.buy(l)}async calculateInitialBuyAmount(e){const t={nativeTokenQuantity:e};return this.launchpadAPI.calculateInitialBuyAmount(t)}async buy(e){if(e.privateKey){const t=this.createOverrideSdk(e.privateKey),{privateKey:a,...n}=e;return t.buy(n)}await this.ensureWebSocketConnection();const t=await this.bundleService.buyToken(e),a=t.data?.transactionId;if(!a)throw aa("No transaction ID returned from buy operation");return this.waitForConfirmation(a,t=>gn(t,a,"buy",e))}async sell(e){if(e.privateKey){const t=this.createOverrideSdk(e.privateKey),{privateKey:a,...n}=e;return t.sell(n)}await this.ensureWebSocketConnection();const t=await this.bundleService.sellToken(e),a=t.data?.transactionId;if(!a)throw aa("No transaction ID returned from sell operation");return this.waitForConfirmation(a,t=>gn(t,a,"sell",e))}async getBundlerTransactionResult(e){return this.bundleService.getBundlerTransactionResult(e)}async postComment(e){if(e.privateKey){const t=this.createOverrideSdk(e.privateKey),{privateKey:a,...n}=e;return t.postComment(n)}return this.launchpadService.postComment(e)}async launchToken(e){if(e.privateKey){const t=this.createOverrideSdk(e.privateKey),{privateKey:a,...n}=e;return t.launchToken(n)}await this.ensureWebSocketConnection();const t=await this.launchpadAPI.launchToken(e);return this.waitForConfirmation(t,a=>{hn(a,t);const n=a?.data||{};if(!function(e){return!(!e||"object"!=typeof e||void 0!==e.vaultAddress&&"string"!=typeof e.vaultAddress||void 0!==e.tokenStringKey&&"string"!=typeof e.tokenStringKey||void 0!==e.creatorAddress&&"string"!=typeof e.creatorAddress)}(n))throw new un(`Invalid launch data received for transaction ${t}`);const r={transactionId:t,vaultAddress:n.vaultAddress||"",tokenStringKey:n.tokenStringKey||"",tokenName:e.tokenName,tokenSymbol:e.tokenSymbol,creatorAddress:n.creatorAddress||this.getAddress(),timestamp:Date.now(),...a.blockHash&&{blockHash:a.blockHash},...a.gasUsed&&{gasUsed:a.gasUsed}};return"string"==typeof e.tokenImage&&(r.tokenImage=e.tokenImage),void 0!==e.preBuyQuantity&&(r.preBuyQuantity=e.preBuyQuantity),r.vaultAddress&&this.tokenResolverService.set(e.tokenName,r.vaultAddress),r})}async uploadTokenImage(e){if(e.privateKey){const t=this.createOverrideSdk(e.privateKey),{privateKey:a,...n}=e;return t.uploadTokenImage(n)}return this.launchpadService.uploadImageByTokenName(e)}async isTokenNameAvailable(e){return this.launchpadService.isTokenNameAvailable(e)}async isTokenSymbolAvailable(e){return this.launchpadService.isTokenSymbolAvailable(e)}async fetchProfile(e){const{normalizeAddressInput:t}=await Promise.resolve().then(function(){return _t}),a=t(e)||this.getAddress();return this.launchpadService.fetchProfile(a)}async updateProfile(e){const{normalizeAddressInput:t}=await Promise.resolve().then(function(){return _t}),a={...e,address:t(e.address)};if(a.privateKey){const e=this.createOverrideSdk(a.privateKey),{privateKey:t,...n}=a;return e.updateProfile(n)}return this.launchpadService.updateProfile(a)}async uploadProfileImage(e){const{normalizeAddressInput:t}=await Promise.resolve().then(function(){return _t}),a={...e,address:t(e.address)||this.getAddress()};if(a.privateKey){const e=this.createOverrideSdk(a.privateKey),{privateKey:t,...n}=a;return e.uploadProfileImage(n)}return this.launchpadService.uploadProfileImage(a)}async retrieveGalaFromFaucet(e){const{normalizeAddressInput:t}=await Promise.resolve().then(function(){return _t}),a={walletAddress:t(e)||this.getAddress(),amount:"5"};return this.launchpadService.transferFaucets(a)}async fetchTokensHeld(e){const{normalizeAddressInput:t}=await Promise.resolve().then(function(){return _t}),a=t(e?.address)||this.getAddress(),n={page:e?.page||1,limit:e?.limit||10,address:a};return e?.tokenName&&(n.tokenName=e.tokenName),e?.search&&(n.search=e.search),this.launchpadService.fetchTokensHeld(n)}async fetchTokensCreated(e){const{normalizeAddressInput:t}=await Promise.resolve().then(function(){return _t}),a={type:"DEFI",address:t(e?.address)||this.getAddress(),page:e?.page||1,limit:e?.limit||10};return e?.tokenName&&(a.tokenName=e.tokenName),e?.search&&(a.search=e.search),this.launchpadService.fetchTokenList(a)}async transferGala(e){const{normalizeAddressInput:t}=await Promise.resolve().then(function(){return _t}),a={...e,recipientAddress:t(e.recipientAddress)};if(a.privateKey){const e=this.createOverrideSdk(a.privateKey),{privateKey:t,...n}=a;return e.transferGala(n)}return this.galaChainService.transferGala(a)}async transferToken(e){const{normalizeAddressInput:t}=await Promise.resolve().then(function(){return _t}),a={...e,to:t(e.to)};if(a.privateKey){const e=this.createOverrideSdk(a.privateKey),{privateKey:t,...n}=a;return e.transferToken(n)}return this.galaChainService.transferToken(a)}async resolveTokenClassKey(e){return this.galaChainService.resolveTokenClassKey(e)}async resolveVaultAddress(e){return this.tokenResolverService.resolveTokenToVault(e)}getCacheInfo(){return this.launchpadAPI.metadataCache.stats()}clearCache(e){this.launchpadAPI.metadataCache.clear(e)}validateConfiguration(){if(("number"!=typeof this.config.timeout||this.config.timeout<=0||this.config.timeout>3e5)&&(this.logger.warn(`Invalid timeout value: ${this.config.timeout}. Using default 30000ms.`),this.config.timeout=3e4),!this.config.baseUrl)throw ta("baseUrl is required in configuration","baseUrl");if(!this.config.webSocketUrl)throw ta("webSocketUrl is required in configuration","webSocketUrl");try{new URL(this.config.baseUrl)}catch{throw ta(`Invalid baseUrl format: ${this.config.baseUrl}`,"baseUrl")}try{new URL(this.config.webSocketUrl)}catch{throw ta(`Invalid webSocketUrl format: ${this.config.webSocketUrl}`,"webSocketUrl")}if(this.config.galaChainBaseUrl)try{new URL(this.config.galaChainBaseUrl)}catch{throw ta(`Invalid galaChainBaseUrl format: ${this.config.galaChainBaseUrl}`,"galaChainBaseUrl")}if(this.config.bundleBaseUrl)try{new URL(this.config.bundleBaseUrl)}catch{throw ta(`Invalid bundleBaseUrl format: ${this.config.bundleBaseUrl}`,"bundleBaseUrl")}if(this.config.launchpadFrontendUrl)try{new URL(this.config.launchpadFrontendUrl)}catch{throw ta(`Invalid launchpadFrontendUrl format: ${this.config.launchpadFrontendUrl}`,"launchpadFrontendUrl")}}parseSlippageToleranceFactor(e){const t=parseFloat(String(e));return isNaN(t)||t<0||t>1?(this.logger.warn(`Invalid slippage tolerance factor: ${e}, using default: ${mn.DEFAULT_SLIPPAGE_TOLERANCE_FACTOR}`),mn.DEFAULT_SLIPPAGE_TOLERANCE_FACTOR):t}parseFeeSlippageFactor(e){const t=parseFloat(String(e));return isNaN(t)||t<0||t>1?(this.logger.warn(`Invalid fee slippage factor: ${e}, using default: ${mn.DEFAULT_MAX_ACCEPTABLE_REVERSE_BONDING_CURVE_FEE_SLIPPAGE_FACTOR}`),mn.DEFAULT_MAX_ACCEPTABLE_REVERSE_BONDING_CURVE_FEE_SLIPPAGE_FACTOR):t}async ensureWebSocketConnection(){this.websocketService.isConnected()||(await this.websocketService.connect(),this.logger.debug("WebSocket connection established"))}async waitForConfirmation(e,t){this.logger.debug(`Waiting for confirmation of transaction: ${e}`);try{const a=await this.websocketService.waitForTransaction(e);if("completed"!==a.status)throw new dn(e,a.status,a.message);let n;try{n=t(a)}catch(t){if(t instanceof un)throw t;throw new un(`Failed to transform WebSocket response for transaction ${e}`,t instanceof Error?t:new Error(String(t)))}return this.logger.debug(`Transaction confirmed: ${e}`,n),n}catch(t){if(this.logger.error(`Transaction confirmation failed: ${e}`,t),t instanceof dn||t instanceof un)throw t;throw new un(`WebSocket confirmation failed for transaction ${e}`,t instanceof Error?t:new Error(String(t)))}}async cleanup(){try{this.logger.debug("Starting cleanup..."),this.http.cleanup(),this.websocketService&&this.websocketService.disconnect(),this.logger.debug("Cleanup completed")}catch(e){this.logger.error("Error during cleanup:",e)}}static cleanupAll(e=!1){const t=new g({debug:e,context:"LaunchpadSDK"});t.debug("Starting global cleanup...");const{WebSocketService:a}=require("./services/WebSocketService");a.cleanupAll(e),t.debug("Global cleanup completed")}}mn.DEFAULT_SLIPPAGE_TOLERANCE_FACTOR=.15,mn.DEFAULT_MAX_ACCEPTABLE_REVERSE_BONDING_CURVE_FEE_SLIPPAGE_FACTOR=.01,mn.DEFAULT_LAUNCHPAD_TOKEN_MAX_SUPPLY=Ha.DEFAULT_LAUNCHPAD_TOKEN_MAX_SUPPLY,mn.DEFAULT_CALCULATE_AMOUNT_MODE=rn.LOCAL;class pn{static generateWallet(){try{const e=t.Wallet.createRandom();if(!e.mnemonic?.phrase)throw new Error("Failed to generate wallet with mnemonic phrase");const a=this.toGalaAddress(e.address);return{privateKey:e.privateKey,address:e.address,galaAddress:a,mnemonic:e.mnemonic.phrase,wallet:new t.Wallet(e.privateKey)}}catch(e){if("undefined"!=typeof process&&"test"===process.env.NODE_ENV){const e=`test-wallet-${Date.now()}-${++this.testCounter}`,a="0x"+Buffer.from(e).toString("hex").padStart(64,"1").slice(0,64),n=new t.Wallet(a),r=this.toGalaAddress(n.address);return{privateKey:n.privateKey,address:n.address,galaAddress:r,mnemonic:"test test test test test test test test test test test junk",wallet:n}}throw e}}static fromPrivateKey(e){const a=new t.Wallet(e),n=this.toGalaAddress(a.address);return{privateKey:a.privateKey,address:a.address,galaAddress:n,mnemonic:"",wallet:a}}static fromMnemonic(e,a=0){try{const n=t.Mnemonic.fromPhrase(e),r=t.HDNodeWallet.fromMnemonic(n,`m/44'/60'/0'/0/${a}`),o=new t.Wallet(r.privateKey),s=this.toGalaAddress(o.address);return{privateKey:o.privateKey,address:o.address,galaAddress:s,mnemonic:e,wallet:o}}catch(n){if("undefined"!=typeof process&&"test"===process.env.NODE_ENV){const n=`test-mnemonic-index-${a}-${e}`,r="0x"+Buffer.from(n).toString("hex").padStart(64,"1").slice(0,64),o=new t.Wallet(r),s=this.toGalaAddress(o.address);return{privateKey:o.privateKey,address:o.address,galaAddress:s,mnemonic:e,wallet:o}}throw n}}static toGalaAddress(e){const t=e.replace(/^0x/i,"");if(!/^[a-fA-F0-9]{40}$/.test(t))throw new Error(`Invalid Ethereum address format: ${e}`);return`eth|${t}`}static toEthereumAddress(e){if(!e.startsWith("eth|"))throw new Error(`Invalid Gala address format: ${e}. Must start with 'eth|'`);const t=e.slice(4);if(!/^[a-fA-F0-9]{40}$/.test(t))throw new Error(`Invalid address in Gala format: ${e}`);return`0x${t}`}static isValidEthereumAddress(e){try{const t=e.replace(/^0x/i,"");return/^[a-fA-F0-9]{40}$/.test(t)}catch{return!1}}static isValidGalaAddress(e){try{if(!e.startsWith("eth|"))return!1;const t=e.slice(4);return/^[a-fA-F0-9]{40}$/.test(t)}catch{return!1}}static generateMultipleWallets(e=1){if(e<1||e>100)throw new Error("Count must be between 1 and 100");const t=[];if("undefined"!=typeof process&&"test"===process.env.NODE_ENV)for(let a=0;a<e;a++){const e=`test-multi-${a}-${Date.now()}-${++this.testCounter}`,n="0x"+Buffer.from(e).toString("hex").padStart(64,"1").slice(0,64);t.push(this.fromPrivateKey(n))}else for(let a=0;a<e;a++)t.push(this.generateWallet());return t}static getWalletSummary(e,t=!1){const a=["๐Ÿ” Wallet Information","โ•".repeat(50),`๐Ÿ“ Address: ${e.address}`,`๐ŸŽฎ Gala Address: ${e.galaAddress}`,`๐ŸŒฑ Mnemonic: ${e.mnemonic||"Not available"}`];return t?a.splice(3,0,`๐Ÿ”‘ Private Key: ${e.privateKey}`):a.splice(3,0,"๐Ÿ”‘ Private Key: [HIDDEN - use includeSensitive=true to show]"),a.push("โ•".repeat(50)),a.push("๐Ÿ’พ IMPORTANT: Save your mnemonic phrase securely!"),a.push("This is your backup to recover the wallet."),a.join("\n")}}function fn(e){if(void 0===e)return pn.generateWallet();const t=e.trim();if(!t)throw new Error("Input cannot be empty string");if(function(e){const t=e.replace(/^0x/i,"");return/^[a-fA-F0-9]{64}$/.test(t)}(t))return pn.fromPrivateKey(t);if(function(e){const t=e.split(/\s+/).filter(e=>e.length>0);if(12!==t.length&&24!==t.length)return!1;return t.every(e=>/^[a-zA-Z]+$/.test(e))}(t))return pn.fromMnemonic(t);throw new Error(`Unable to detect input format. Expected:\n- Private key: 64 hexadecimal characters (with or without 0x prefix)\n- Mnemonic: 12 or 24 space-separated words\nReceived: "${t.slice(0,50)}${t.length>50?"...":""}"`)}pn.testCounter=0;var yn=Object.freeze({__proto__:null,extractMetadataFromPoolData:function(e,t){const a={};if(e.vaultAddress&&(a.vaultAddress=e.vaultAddress),void 0!==e.reverseBondingCurveMinFeePortion){const n=parseFloat(e.reverseBondingCurveMinFeePortion);isNaN(n)?t&&t.debug(`Skipping invalid reverseBondingCurveMinFeePortion for ${e.tokenName}: "${e.reverseBondingCurveMinFeePortion}"`):a.reverseBondingCurveMinFeeFactor=n}if(void 0!==e.reverseBondingCurveMaxFeePortion){const n=parseFloat(e.reverseBondingCurveMaxFeePortion);isNaN(n)?t&&t.debug(`Skipping invalid reverseBondingCurveMaxFeePortion for ${e.tokenName}: "${e.reverseBondingCurveMaxFeePortion}"`):a.reverseBondingCurveMaxFeeFactor=n}return void 0!==a.reverseBondingCurveMaxFeeFactor&&void 0!==a.reverseBondingCurveMinFeeFactor&&(a.reverseBondingCurveNetFeeFactor=a.reverseBondingCurveMaxFeeFactor-a.reverseBondingCurveMinFeeFactor),Object.keys(a).length>0?a:null},isValidPoolForCaching:function(e){return null!==e&&"object"==typeof e&&"tokenName"in e&&"string"==typeof e.tokenName&&e.tokenName.length>0}});e.AgentConfig=class{static async quickSetup(e={}){const t=e.environment||this.detectEnvironment(),a=this.setupWallet(e.privateKey),n={wallet:a.wallet,baseUrl:e.baseUrl||this.getDefaultBaseUrl(t),timeout:e.timeout||this.getDefaultTimeout(t),debug:e.debug??"production"!==t,...this.getEnvironmentDefaults(t)},r=new mn(n),o={sdk:r,wallet:a,config:n};if(!1!==e.autoValidate){const e=await this.validateSetup(r,a);return{...o,validation:e}}return o}static async validateSetup(e,t){const a=[],n=[],r={canTrade:!1,canCreateTokens:!1,hasBalance:!1,connectionHealthy:!1};try{const t=await e.fetchGalaBalance(e.getAddress());if(r.connectionHealthy=!0,t&&t.quantity){const e=parseFloat(t.quantity);r.hasBalance=e>0,r.canTrade=e>=.1,r.canCreateTokens=e>=100,0===e?n.push("Wallet has zero GALA balance - cannot perform transactions"):e<.1?n.push("GALA balance too low for trading (minimum 0.1 GALA)"):e<100&&n.push("GALA balance too low for token creation (minimum 100 GALA)")}else a.push("Failed to fetch GALA balance: No balance returned")}catch(e){a.push(`Balance check error: ${e instanceof Error?e.message:String(e)}`)}try{const t=await e.fetchPools({type:"recent",page:1,limit:1});t.pools&&0!==t.pools.length||n.push("Pool listing not accessible - some features may be limited")}catch(e){n.push(`Pool access test failed: ${e instanceof Error?e.message:String(e)}`)}return{ready:0===a.length&&r.connectionHealthy,sdk:e,wallet:t||pn.generateWallet(),issues:a,warnings:n,capabilities:r}}static getRecommendedConfig(e,t="general"){const a={environment:e,autoValidate:!0};switch(e){case"production":Object.assign(a,{debug:!1,timeout:3e4});break;case"development":Object.assign(a,{debug:!0,timeout:45e3});break;case"testing":Object.assign(a,{debug:!0,timeout:6e4})}switch(t){case"trading":a.timeout=1.5*(a.timeout||3e4);break;case"creation":a.timeout=2*(a.timeout||3e4);break;case"monitoring":a.timeout=.5*(a.timeout||3e4)}return a}static async multiWalletSetup(e,t="development"){const a={};for(const[n,r]of Object.entries(e)){const{sdk:e}=await this.quickSetup({environment:t,privateKey:r,agentId:`multi-wallet-${n}`,autoValidate:!1});a[n]=e}return a}static detectEnvironment(){const e=process.env.NODE_ENV?.toLowerCase();return"production"===e?"production":"test"===e||"testing"===e?"testing":"development"}static setupWallet(e){if(!e){const e=process.env.PRIVATE_KEY;return e?pn.fromPrivateKey(e):pn.generateWallet()}return"generate"===e?pn.generateWallet():pn.fromPrivateKey(e)}static getDefaultBaseUrl(e){return"production"===e?"https://lpad-backend-prod1.defi.gala.com":"https://lpad-backend-dev1.defi.gala.com"}static getDefaultTimeout(e){switch(e){case"production":default:return 3e4;case"development":return 45e3;case"testing":return 6e4}}static getEnvironmentDefaults(e){const t={};if("production"===e)t.bundleBaseUrl="https://bundle-backend-prod1.defi.gala.com",t.galaChainBaseUrl="https://galachain-gateway-chain-platform-prod-chain-platform-eks.prod.galachain.com";else t.bundleBaseUrl="https://bundle-backend-dev1.defi.gala.com",t.galaChainBaseUrl="https://galachain-gateway-chain-platform-stage-chain-platform-eks.stage.galachain.com";return t}},e.CALCULATION_MODES=rn,e.FileValidationError=fa,e.GALA_DECIMALS=8,e.GALA_TOKEN_CLASS_KEY={collection:"GALA",category:"Unit",type:"none",additionalKey:"none"},e.IMAGE_EXTENSIONS=me,e.LAUNCHPAD_TOKEN_DECIMALS=18,e.LaunchpadSDK=mn,e.MAX_CONCURRENT_POOL_FETCHES=5,e.POOL_TYPES={RECENT:"recent",POPULAR:"popular"},e.SDK_VERSION="3.7.0",e.TRADING_TYPES=nn,e.TransactionFailedError=dn,e.ValidationError=v,e.WebSocketError=un,e.WebSocketTimeoutError=class extends un{constructor(e,t){super(`WebSocket confirmation timeout for transaction ${e} after ${t}ms`),this.name="WebSocketTimeoutError"}},e.addressFormatSchema=L,e.amountMethodSchema=de,e.amountTypeSchema=ue,e.browserFileSchema=fe,e.bufferFileSchema=ye,e.buyTokensDataSchema=Me,e.calculatePreMintDataSchema=je,e.checkPoolOptionsSchema=le,e.commentMessageSchema=X,e.commentPaginationSchema=Ee,e.createLaunchpadSDK=function(e){const{wallet:a,env:n,config:r={}}=e||{};let o;if(a)if("string"==typeof a){o=fn(a).wallet}else{if(!(a instanceof t.Wallet))throw new Error("Invalid wallet input. Expected string (private key or mnemonic) or Wallet instance.");o=a}else{o=fn().wallet}const s={wallet:o,...n&&{env:n},debug:!1,timeout:3e4,...r};return new mn(s)},e.createLimitSchema=z,e.createPaginatedResultSchema=function(e){return r.z.object({data:r.z.array(e),page:r.z.number().int().min(1),limit:r.z.number().int().min(1),total:r.z.number().int().min(0),totalPages:r.z.number().int().min(0),hasNext:r.z.boolean(),hasPrevious:r.z.boolean()})},e.createTradeDataSchema=Be,e.createWallet=fn,e.ethereumAddressSchema=O,e.faucetAmountSchema=M,e.fetchGalaBalanceOptionsSchema=_e,e.fetchPoolDetailsDataSchema=We,e.fetchTokenBalanceOptionsSchema=xe,e.fileSizeSchema=W,e.fileUploadSchema=pe,e.filenameSchema=H,e.flexibleAddressSchema=x,e.flexibleFileSchema=ve,e.formatGalaForDTO=Pa,e.formatLaunchpadTokenForDTO=_a,e.fullNameSchema=_,e.getAmountOptionsSchema=qe,e.getTradeOptionsSchema=Ke,e.graduateTokenOptionsSchema=ge,e.graphDataOptionsSchema=he,e.imageExtensionSchema=Ae,e.imageFilenameSchema=we,e.imageMimeTypeSchema=Q,e.imageUploadOptionsSchema=ie,e.isoDateStringSchema=Y,e.launchTokenDataSchema=se,e.nonNegativeDecimalStringSchema=B,e.optionalUrlSchema=K,e.pageNumberSchema=G,e.paginationResultMetaSchema=Fe,e.poolFetchTypeSchema=ce,e.poolPaginationSchema=Se,e.positiveDecimalStringSchema=$,e.privateKeySchema=J,e.reverseBondingCurveConfigSchema=oe,e.reverseBondingCurveConfigurationSchema=He,e.searchQuerySchema=P,e.sellTokensDataSchema=Re,e.standardLimitSchema=V,e.standardPaginationSchema=Te,e.timestampSchema=Z,e.tokenCategorySchema=ne,e.tokenCollectionSchema=re,e.tokenDescriptionSchema=C,e.tokenListOptionsSchema=De,e.tokenNameSchema=I,e.tokenSymbolSchema=F,e.tokenUrlsSchema=ae,e.tradeCalculationMethodSchema=Ve,e.tradeCalculationTypeSchema=ze,e.tradeLimitSchema=j,e.tradeListParamsSchema=Ge,e.tradePaginationSchema=Ne,e.tradePaginationWithFiltersSchema=Ie,e.tradeTypeBackendSchema=$e,e.tradeTypeSchema=Ue,e.transactionIdSchema=ee,e.transferFaucetsDataSchema=Pe,e.uniqueKeySchema=te,e.updateProfileDataSchema=Le,e.uploadProfileImageOptionsSchema=Oe,e.urlSchema=R,e.userLimitSchema=q,e.userPaginationSchema=ke,e.userTokenNameSchema=D,e.userTokenTypeSchema=Ce,e.userTokensPaginationSchema=be,e.validateAddress=Je,e.validateAmountString=tt,e.validateBuyTokensData=yt,e.validateCalculatePreMintData=kt,e.validateCheckPoolOptions=lt,e.validateCreateTradeData=ft,e.validateFaucetAmount=at,e.validateFetchGalaBalanceOptions=ht,e.validateFetchPoolDetailsData=Nt,e.validateFetchTokenBalanceOptions=pt,e.validateFullName=nt,e.validateGetAmountOptions=Tt,e.validateGetTradeOptions=At,e.validateImageUploadOptions=ct,e.validateLaunchTokenData=st,e.validateSearchQuery=rt,e.validateSellTokensData=vt,e.validateTokenDescription=Ze,e.validateTokenListOptions=ut,e.validateTokenName=Xe,e.validateTokenSymbol=Ye,e.validateTokenUrls=it,e.validateTradeListParams=wt,e.validateTransferFaucetsData=dt,e.validateUpdateProfileData=gt,e.validateUploadProfileImageOptions=mt,e.validateUserTokenName=ot,e.validateVaultAddress=et,e.vaultAddressSchema=U});
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("ethers"),require("axios"),require("@gala-chain/connect"),require("zod"),require("@gala-chain/api"),require("bignumber.js"),require("uuid"),require("socket.io-client")):"function"==typeof define&&define.amd?define(["exports","ethers","axios","@gala-chain/connect","zod","@gala-chain/api","bignumber.js","uuid","socket.io-client"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).GalaLaunchpadSDK={},e.ethers,e.axios,e.GalaChainConnect,e.z,e.GalaChainAPI,e.BigNumber,e.uuid,e.io)}(this,function(e,t,a,n,r,o,s,i,c){"use strict";var l,u;!function(e){e.WALLET_NOT_CONNECTED="WALLET_NOT_CONNECTED",e.SIGNATURE_FAILED="SIGNATURE_FAILED",e.INVALID_ADDRESS="INVALID_ADDRESS",e.MESSAGE_GENERATION_FAILED="MESSAGE_GENERATION_FAILED"}(l||(l={}));class d extends Error{constructor(e,t,a){super(t),this.type=e,this.originalError=a,this.name="AuthError"}}class h{constructor(e){if(this.wallet=e.wallet,this.messagePrefix=e.messagePrefix||"Create a GalaChain Wallet",""===e.messagePrefix)throw new d(l.SIGNATURE_FAILED,"Message prefix cannot be empty");this.validateWallet()}async generateSignature(){try{const e=Date.now(),t=`${this.messagePrefix} ${e}`,a=await this.wallet.signMessage(t);return{message:t,signature:a,address:this.formatAddress(this.wallet.address),timestamp:e}}catch(e){throw new d(l.SIGNATURE_FAILED,"Failed to generate signature for authentication",e instanceof Error?e:new Error(String(e)))}}getAddress(){return this.formatAddress(this.wallet.address)}getEthereumAddress(){return this.wallet.address}formatAddress(e){const t=e.replace(/^0x/i,"");if(!/^[a-fA-F0-9]{40}$/.test(t))throw new d(l.INVALID_ADDRESS,`Invalid Ethereum address format: ${e}`);return`eth|${t}`}async signMessage(e){try{return{message:e,signature:await this.wallet.signMessage(e),address:this.wallet.address,timestamp:Date.now()}}catch(e){const t=e instanceof Error?e.message:String(e);throw new d(l.SIGNATURE_FAILED,t,e instanceof Error?e:new Error(String(e)))}}async generateAuthHeaders(e,t){try{const a=Date.now(),n=`${this.messagePrefix} ${t.toUpperCase()} ${e} ${a}`,r=await this.wallet.signMessage(n);return{"x-signature":r,"x-address":this.formatAddress(this.wallet.address),"x-message":n,"x-timestamp":a.toString()}}catch(e){throw new d(l.SIGNATURE_FAILED,"Failed to generate authentication headers",e instanceof Error?e:new Error(String(e)))}}async signTypedData(e,t,a){try{return await this.wallet.signTypedData(e,t,a)}catch(e){throw new d(l.SIGNATURE_FAILED,"Failed to sign typed data",e instanceof Error?e:new Error(String(e)))}}async generateCustomSignature(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new d(l.SIGNATURE_FAILED,"Custom message must be a non-empty string");try{const t=await this.wallet.signMessage(e);return{message:e,signature:t,address:this.formatAddress(this.wallet.address),timestamp:Date.now()}}catch(e){throw new d(l.SIGNATURE_FAILED,"Failed to generate custom message signature",e instanceof Error?e:new Error(String(e)))}}validateWallet(){if(!this.wallet)throw new d(l.WALLET_NOT_CONNECTED,"Wallet is required for authentication");if(!this.wallet.address)throw new d(l.WALLET_NOT_CONNECTED,"Wallet address is not available");if(!this.wallet.privateKey&&!this.wallet.signMessage)throw new d(l.WALLET_NOT_CONNECTED,"Wallet must have a private key for signing messages")}}!function(e){e.DEBUG="DEBUG",e.INFO="INFO",e.WARN="WARN",e.ERROR="ERROR"}(u||(u={}));class g{constructor(e){this.levelPriority={[u.DEBUG]:0,[u.INFO]:1,[u.WARN]:2,[u.ERROR]:3},this.debugEnabled=e.debug,this.context=e.context||"SDK",this.minLevel=e.minLevel||(e.debug?u.DEBUG:u.INFO)}debug(e,t){this.log(u.DEBUG,e,t)}info(e,t){this.log(u.INFO,e,t)}warn(e,t){this.log(u.WARN,e,t)}error(e,t){this.log(u.ERROR,e,t)}log(e,t,a){if(this.levelPriority[e]<this.levelPriority[this.minLevel])return;if(e===u.DEBUG&&!this.debugEnabled)return;const n=`[${(new Date).toISOString()}] [${this.context}] [${e}]`,r=this.getConsoleMethod(e);void 0!==a?a instanceof Error?r(`${n} ${t}`,a.message,a.stack):r(`${n} ${t}`,a):r(`${n} ${t}`)}getConsoleMethod(e){switch(e){case u.DEBUG:return console.debug;case u.INFO:return console.info;case u.WARN:return console.warn;case u.ERROR:return console.error;default:return console.log}}child(e){return new g({debug:this.debugEnabled,context:`${this.context}:${e}`,minLevel:this.minLevel})}isDebugEnabled(){return this.debugEnabled&&this.levelPriority[u.DEBUG]>=this.levelPriority[this.minLevel]}}function m(e){const t={};for(const[a,n]of Object.entries(e))null!=n&&("string"==typeof n?t[a]=n:"number"==typeof n||"boolean"==typeof n?t[a]=n.toString():Array.isArray(n)?t[a]=n.join(","):t[a]="object"==typeof n?JSON.stringify(n):String(n));return t}class p{constructor(e,t={}){this.auth=e,this.debug=t.debug??!1,this.logger=new g({debug:this.debug,context:"HttpClient"}),this.axios=a.create({baseURL:t.baseUrl||"https://lpad-backend-dev1.defi.gala.com",timeout:t.timeout||3e4,headers:{Accept:"application/json",...t.headers}}),this.setupInterceptors()}async request(e){try{const t={method:e.method,url:e.url,data:e.data,...e.params&&{params:m(e.params)},...e.headers&&{headers:e.headers},...e.timeout&&{timeout:e.timeout}};e.data instanceof FormData&&(t.headers&&t.headers["Content-Type"]&&delete t.headers["Content-Type"],this.logger.debug("FormData detected - removing Content-Type header for multipart upload"));const a=e.data instanceof FormData?"[FormData object - multipart/form-data]":e.data;this.logger.debug("Request:",{method:e.method,url:e.url,fullUrl:`${this.axios.defaults.baseURL}${e.url}`,baseURL:this.axios.defaults.baseURL,params:t.params,data:a,isFormData:e.data instanceof FormData,contentType:t.headers?.["Content-Type"]||"not set"});const n=await this.axios.request(t);return this.logger.debug("Response:",{status:n.status,data:n.data}),n.data}catch(e){throw this.logger.error("Error:",e),e}}async get(e,t,a){return this.request({method:"GET",url:e,...t&&{params:t},...a&&{headers:a}})}async post(e,t,a){return this.request({method:"POST",url:e,data:t,...a&&{headers:a}})}async put(e,t,a){return this.request({method:"PUT",url:e,data:t,...a&&{headers:a}})}async delete(e,t,a){return this.request({method:"DELETE",url:e,...t&&{params:t},...a&&{headers:a}})}async patch(e,t,a){return this.request({method:"PATCH",url:e,data:t,...a&&{headers:a}})}getAddress(){return this.auth.getAddress()}getEthereumAddress(){return this.auth.getEthereumAddress()}async signMessage(e){return(await this.auth.signMessage(e)).signature}async signTypedData(e,t,a){return await this.auth.signTypedData(e,t,a)}async signCustomMessage(e){try{const t=await this.auth.generateCustomSignature(e);return this.logger.debug("Generated custom signature:",{message:e,address:t.address,ethereumAddress:this.auth.getEthereumAddress()}),{signature:t.signature,address:t.address,ethereumAddress:this.auth.getEthereumAddress()}}catch(e){throw this.logger.error("Custom signature generation failed:",e),new Error(`Failed to generate custom signature for message: ${e instanceof Error?e.message:"Unknown error"}`)}}async signWithGalaChain(e,t,a=n.SigningType.SIGN_TYPED_DATA){const r=this.auth.wallet.privateKey;if(!r)throw new Error("Wallet private key not available for @gala-chain signing");const o=new n.SigningClient(r);return await o.sign(e,t,a)}setupInterceptors(){this.requestInterceptorId=this.axios.interceptors.request.use(async e=>{try{const t=await this.auth.generateSignature();return e.headers||(e.headers={}),e.headers.Sign=t.signature,e.data instanceof FormData||(e.headers["Content-Type"]="application/json"),this.logger.debug("Added signature header:",{address:t.address,message:t.message,timestamp:t.timestamp}),e}catch(e){throw this.logger.error("Failed to add signature:",e),e}},e=>Promise.reject(e)),this.responseInterceptorId=this.axios.interceptors.response.use(e=>e,e=>{if(e.response){const t={message:e.response.data?.message||e.message,error:e.response.data?.error,statusCode:e.response.status,details:e.response.data?.details,timestamp:e.response.data?.timestamp,path:e.response.data?.path};e.launchpadError=t,this.logger.error("Backend error:",t)}else e.request?this.logger.error("Network error:",e.message):this.logger.error("Request setup error:",e.message);return Promise.reject(e)})}cleanup(){void 0!==this.requestInterceptorId&&(this.axios.interceptors.request.eject(this.requestInterceptorId),this.requestInterceptorId=void 0),void 0!==this.responseInterceptorId&&(this.axios.interceptors.response.eject(this.responseInterceptorId),this.responseInterceptorId=void 0),this.logger.debug("Interceptors cleaned up")}}const f="Token name is required and must be a string",y=e=>`Could not find vault address for token: ${e}`;class v extends Error{constructor(e,t,a){super(e),this.field=t,this.code=a,this.name="ValidationError"}}class A extends Error{constructor(e,t,a){super(e),this.statusCode=t,this.originalError=a,this.name="NetworkError"}}class w extends Error{constructor(e,t){super(e),this.field=t,this.name="ConfigurationError"}}class T extends Error{constructor(e,t,a){super(e),this.transactionId=t,this.code=a,this.name="TransactionError"}}function k(e,t,a){const{MIN_PAGE:n,MAX_PAGE:r,MIN_LIMIT:o,MAX_LIMIT:s}=a.PAGINATION;if("number"!=typeof e||e<n||e>r)throw new v(`Page must be a number between ${n} and ${r}`,"page","INVALID_PAGE");if("number"!=typeof t||t<o||t>s)throw new v(`Limit must be a number between ${o} and ${s}`,"limit","INVALID_LIMIT")}const N={ETH_ADDRESS:/^0x[0-9a-fA-F]{40}$/,BACKEND_ADDRESS:/^eth\|[0-9a-fA-F]{40}$/};function E(e){return"string"==typeof e&&e.trim().length>0}function S(e){return!(!e||"string"!=typeof e)&&(N.ETH_ADDRESS.test(e)||N.BACKEND_ADDRESS.test(e))}function b(e){return e.startsWith("0x")?`eth|${e.slice(2)}`:e}const I=r.z.string().min(3,"Token name must be at least 3 characters").max(20,"Token name must be at most 20 characters").regex(/^[a-zA-Z0-9]{3,20}$/,"Token name can only contain letters and numbers"),F=r.z.string().min(1,"Token symbol must be at least 1 character").max(8,"Token symbol must be at most 8 characters").regex(/^[A-Z]{1,8}$/,"Token symbol must be uppercase letters only"),C=r.z.string().min(1,"Token description is required").max(500,"Token description must be at most 500 characters"),D=r.z.string().min(1,"Token name must be at least 1 character").max(50,"Token name must be at most 50 characters"),P=r.z.string().min(1,"Search query must be at least 1 character").max(100,"Search query must be at most 100 characters"),_=r.z.string().min(1,"Full name is required").max(100,"Full name must be at most 100 characters").regex(/^[a-zA-Z\s]+$/,"Full name can only contain letters and spaces"),L=r.z.string().regex(N.BACKEND_ADDRESS,"Address must be in format: eth|[40-hex-chars]"),O=r.z.string().regex(N.ETH_ADDRESS,"Invalid Ethereum address format"),x=r.z.string().refine(e=>N.BACKEND_ADDRESS.test(e)||N.ETH_ADDRESS.test(e),"Address must be either eth|[40-hex-chars] or 0x[40-hex-chars] format").transform(e=>e.startsWith("0x")?`eth|${e.slice(2)}`:e),U=r.z.string().refine(e=>N.BACKEND_ADDRESS.test(e)||/^service\|Token\$Unit\$[A-Z0-9]+\$eth:[0-9a-fA-F]{40}\$launchpad$/.test(e),"Invalid vault address format"),$=r.z.string().regex(/^\d+(\.\d+)?$/,"Must be a valid decimal number").refine(e=>parseFloat(e)>0,"Amount must be greater than zero"),B=r.z.string().regex(/^\d+(\.\d+)?$/,"Must be a valid decimal number").refine(e=>parseFloat(e)>=0,"Amount must be zero or greater"),M=r.z.string().regex(/^(?!0+(\.0+)?$)\d+(\.\d+)?$/,"Amount must be a positive, non-zero number"),R=r.z.string().url("Must be a valid URL").regex(/^https?:\/\//,"URL must start with http:// or https://"),K=r.z.string().optional().refine(e=>!e||/^https?:\/\/.+\..+/.test(e),"Must be a valid URL if provided"),G=r.z.number().int("Page must be an integer").min(1,"Page must be at least 1").max(1e3,"Page must be at most 1000").default(1);function z(e=100){return r.z.number().int("Limit must be an integer").min(1,"Limit must be at least 1").max(e,`Limit must be at most ${e}`).default(10)}const V=z(100),q=z(20),j=z(20),W=r.z.number().int("File size must be an integer").min(1,"File must be at least 1 byte").max(10485760,"File must be at most 10MB"),H=r.z.string().max(255,"Filename must be at most 255 characters"),Q=r.z.enum(["image/png","image/jpg","image/jpeg","image/gif","image/webp","image/svg+xml"]),X=r.z.string().min(1,"Comment message is required").max(500,"Comment must be at most 500 characters"),Y=r.z.string().datetime("Must be a valid ISO 8601 date string"),Z=r.z.number().int("Timestamp must be an integer").min(0,"Timestamp must be non-negative"),J=r.z.string().regex(/^0x[a-fA-F0-9]{64}$/,"Private key must be format: 0x + 64 hex characters"),ee=r.z.string().regex(/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/,"Transaction ID must be in UUID format"),te=r.z.string().regex(/^galaconnect-operation-[a-z0-9-]+$/,"Unique key must be format: galaconnect-operation-{unique-id}"),ae=r.z.object({websiteUrl:K,telegramUrl:K,twitterUrl:K}).refine(e=>e.websiteUrl||e.telegramUrl||e.twitterUrl,"At least one social URL (website, telegram, or twitter) is required"),ne=r.z.string().min(1,"Token category must not be empty").default("Unit"),re=r.z.string().min(1,"Token collection must not be empty").default("Token"),oe=r.z.object({minFeePortion:$,maxFeePortion:$}),se=r.z.object({tokenName:I,tokenSymbol:F,tokenDescription:C,tokenImage:r.z.union([r.z.instanceof(File),r.z.instanceof(Buffer),r.z.string().url("Token image must be a valid URL")]).optional(),preBuyQuantity:B.default("0"),websiteUrl:K,telegramUrl:K,twitterUrl:K,tokenCategory:ne,tokenCollection:re,reverseBondingCurveConfiguration:oe.optional(),privateKey:J.optional()}),ie=r.z.object({file:r.z.union([r.z.instanceof(File),r.z.instanceof(Buffer)]),tokenName:I}),ce=r.z.enum(["recent","popular"]),le=r.z.object({tokenName:I.optional(),symbol:F.optional()}).refine(e=>e.tokenName||e.symbol,"At least one of tokenName or symbol is required"),ue=r.z.enum(["NATIVE","MEME"]),de=r.z.enum(["IN","OUT"]),he=r.z.object({from:r.z.number().int("From timestamp must be an integer").min(173e6,"From timestamp must be at least 173000000"),to:r.z.number().int("To timestamp must be an integer").min(173e6,"To timestamp must be at least 173000000"),resolution:r.z.number().int("Resolution must be an integer").min(1,"Resolution must be at least 1"),tokenName:I}),ge=r.z.object({tokenName:I,slippageToleranceFactor:r.z.number().min(0).max(1).optional(),maxAcceptableReverseBondingCurveFeeSlippageFactor:r.z.number().min(0).max(1).optional(),privateKey:J.optional()}),me=[".png",".jpg",".jpeg",".gif",".webp",".svg"],pe=r.z.object({file:r.z.union([r.z.instanceof(File),r.z.instanceof(Buffer)]),name:H,size:W,type:Q}),fe=r.z.instanceof(File).refine(e=>e.size>=1&&e.size<=10485760,"File size must be between 1 byte and 10MB").refine(e=>["image/png","image/jpg","image/jpeg","image/gif","image/webp","image/svg+xml"].includes(e.type),"File must be a valid image type (PNG, JPG, JPEG, GIF, WebP, or SVG)").refine(e=>e.name.length<=255,"Filename must be at most 255 characters"),ye=r.z.instanceof(Buffer).refine(e=>e.length>=1&&e.length<=10485760,"Buffer size must be between 1 byte and 10MB"),ve=r.z.union([fe,ye]),Ae=r.z.enum([".png",".jpg",".jpeg",".gif",".webp",".svg"]),we=H.refine(e=>{const t=e.slice(e.lastIndexOf(".")).toLowerCase();return me.includes(t)},`Filename must end with one of: ${me.join(", ")}`),Te=r.z.object({page:G,limit:V}),ke=r.z.object({page:G,limit:q}),Ne=r.z.object({page:G,limit:j}),Ee=r.z.object({page:G,limit:z(50)}),Se=Te.extend({type:r.z.enum(["recent","popular"]).optional(),tokenName:r.z.string().min(1).max(50).optional(),search:r.z.string().min(1).max(100).optional()}),be=ke.extend({tokenName:r.z.string().min(1).max(50).optional(),search:r.z.string().min(1).max(100).optional()}),Ie=Ne.extend({tradeType:r.z.enum(["BUY","SELL"]).optional(),tokenName:r.z.string().min(1).max(50).optional(),userAddress:r.z.string().regex(/^(0x[a-fA-F0-9]{40}|eth\|[a-fA-F0-9]{40})$/).optional(),startDate:r.z.string().datetime().optional(),endDate:r.z.string().datetime().optional(),sortOrder:r.z.enum(["ASC","DESC"]).default("DESC")}),Fe=r.z.object({page:r.z.number().int().min(1),limit:r.z.number().int().min(1),total:r.z.number().int().min(0),totalPages:r.z.number().int().min(0),hasNext:r.z.boolean(),hasPrevious:r.z.boolean()});const Ce=r.z.enum(["all","DEFI","ASSET"]),De=ke.extend({type:Ce.optional(),address:x.optional(),search:P.optional(),tokenName:D.optional()}),Pe=r.z.object({walletAddress:x,amount:M}),_e=r.z.object({address:x.optional(),refresh:r.z.boolean().optional()}),Le=r.z.object({profileImage:r.z.string(),fullName:_,address:x,privateKey:J.optional()}),Oe=r.z.object({file:r.z.union([r.z.instanceof(File),r.z.instanceof(Buffer)]),address:x.optional(),privateKey:J.optional()}),xe=r.z.object({address:x,tokenId:r.z.union([r.z.string(),r.z.object({collection:r.z.string(),category:r.z.string(),type:r.z.string(),additionalKey:r.z.string()}),r.z.object({collection:r.z.string(),category:r.z.string(),type:r.z.string(),additionalKey:r.z.string(),instance:r.z.string()})]).optional(),tokenClassKey:r.z.object({collection:r.z.string(),category:r.z.string(),type:r.z.string(),additionalKey:r.z.string()}).optional(),tokenName:D.optional()}).refine(e=>void 0!==e.tokenId||void 0!==e.tokenName,"At least one token identifier (tokenId or tokenName) is required"),Ue=r.z.enum(["buy","sell"]),$e=r.z.enum(["BUY","SELL"]),Be=r.z.object({tradeType:Ue,tokenAmount:$,vaultAddress:U,userAddress:x,slippageTolerance:$.optional(),deadline:r.z.number().int().positive().optional()}),Me=r.z.object({tokenSymbol:F,nativeTokenQuantity:$,expectedToken:$,maxAcceptableReverseBondingCurveFee:B.default("0").optional()}),Re=r.z.object({tokenSymbol:F,tokenQuantity:$,expectedNativeToken:$,maxAcceptableReverseBondingCurveFee:B.default("0").optional()}),Ke=Ne.extend({tokenName:D.optional()}),Ge=r.z.object({page:r.z.number().int().min(1).max(1e3).default(1).optional(),limit:r.z.number().int().min(1).max(20).default(10).optional()}),ze=r.z.enum(["NATIVE","MEME"]),Ve=r.z.enum(["IN","OUT"]),qe=r.z.object({type:ze,method:Ve,vaultAddress:U,amount:$}),je=r.z.object({nativeTokenQuantity:$}),We=r.z.object({vaultAddress:U}),He=r.z.object({minFeePortion:$,maxFeePortion:$});function Qe(e){return t=>{const a=e.safeParse(t);return{success:a.success,data:a.success?a.data:void 0,errors:a.success?void 0:a.error.errors.map(e=>e.message)}}}const Xe=Qe(I),Ye=Qe(F),Ze=Qe(C),Je=Qe(x),et=Qe(U),tt=Qe($),at=Qe(M),nt=Qe(_),rt=Qe(P),ot=Qe(D),st=Qe(se),it=Qe(ae),ct=Qe(ie),lt=Qe(le),ut=Qe(De),dt=Qe(Pe),ht=Qe(_e),gt=Qe(Le),mt=Qe(Oe),pt=Qe(xe),ft=Qe(Be),yt=Qe(Me),vt=Qe(Re),At=Qe(Ke),wt=Qe(Ge),Tt=Qe(qe),kt=Qe(je),Nt=Qe(We);function Et(e,t){throw new v(e.join("; "),t,"VALIDATION_ERROR")}function St(e){const t=Xe(e);!t.success&&t.errors&&Et(t.errors,"tokenName")}function bt(e){const t=Se.safeParse(e);t.success||Et(t.error.errors.map(e=>e.message),"pagination")}function It(e){const t=lt(e);!t.success&&t.errors&&Et(t.errors,"options")}function Ft(e){const t=Tt(e);!t.success&&t.errors&&Et(t.errors,"options")}function Ct(e){const t=he.safeParse(e);t.success||Et(t.error.errors.map(e=>e.message),"options")}function Dt(e){const t=x.safeParse(e);if(!t.success)throw new v("Ethereum address must be 40 hex characters (with or without 0x prefix)","ethereumAddress","INVALID_FORMAT");return t.data}function Pt(e,t,a=!0){if(!e||""===e.trim())throw new v(`${t} cannot be empty or whitespace-only. Provide a valid numeric string or omit the parameter to auto-fetch.`,t,"INVALID_NUMERIC_STRING");if(/[eE]/.test(e))throw new v(`${t} cannot use scientific notation. Use standard decimal format (e.g., "1000" instead of "1e3").`,t,"INVALID_NUMERIC_STRING");const n=parseFloat(e);if(isNaN(n))throw new v(`${t} must be a valid numeric string. Received: "${e}"`,t,"INVALID_NUMERIC_STRING");if(!isFinite(n))throw new v(`${t} must be a finite number. Cannot be Infinity or -Infinity.`,t,"INVALID_NUMERIC_STRING");if(n<0)throw new v(`${t} must be non-negative. Received: "${e}"`,t,"INVALID_NUMERIC_STRING");if(!a&&0===n)throw new v(`${t} must be greater than zero. Received: "${e}"`,t,"INVALID_NUMERIC_STRING")}var _t=Object.freeze({__proto__:null,normalizeAddressInput:function(e){if(!e)return;const t=x.safeParse(e);if(!t.success)throw new v(`Invalid address format: ${e}. Must be either "0x..." (Ethereum) or "eth|..." (GalaChain) format`,"address","INVALID_FORMAT");return t.data},toBackendAddressFormat:Dt,validateCheckPoolOptions:It,validateGetAmountOptions:Ft,validateGetGraphOptions:Ct,validateNumericString:Pt,validatePagination:bt,validateTokenName:St});function Lt(e){if(!e)return[];return(Array.isArray(e)?e:e.token??[]).map(e=>({...e,createdAt:new Date(e.createdAt),updatedAt:new Date(e.updatedAt)}))}function Ot(e,t){const a=Number(e.page)||t.page,n=Number(e.limit)||t.limit,r=Number(e.total)||Number(e.data?.count)||0;return{page:a,limit:n,total:r,totalPages:Math.ceil(r/n)}}function xt(e,t){return{hasNext:e<t,hasPrevious:e>1}}function Ut(e,t,a=!1){const n=!0===e.error||200!==e.status,r=a&&!e.data;if(n||r)throw new Error(e.message||t)}const $t="/launchpad/upload-image",Bt="/launchpad/fetch-pool",Mt="/launchpad/check-pool",Rt="/launchpad/get-graph-data",Kt="/holders",Gt="/launchpad/get-badge/",zt="/trade/",Vt="/token/commment",qt="/token/commment",jt="/user/profile",Wt="/user/profile",Ht="/user/token-list",Qt="/user/token-hold",Xt="/user/transfer-faucets";function Yt(e,t){return new v(`Token "${e}" not found. Please verify the token name is correct.`,"tokenName","TOKEN_NOT_FOUND")}function Zt(e,t){const a=t||e.charAt(0).toUpperCase()+e.slice(1);return new v(`${a} is required`,e,"REQUIRED_FIELD")}function Jt(e,t,a){const n=a||e.charAt(0).toUpperCase()+e.slice(1);return new v(`${n} must be ${t}`,e,"INVALID_FORMAT")}function ea(e,t,a){return new A(e,t,a)}function ta(e,t){return new w(e,t)}function aa(e,t,a){return new T(e,t,a)}function na(e){return e&&"object"==typeof e&&"string"==typeof e.tokenName&&(void 0===e.from||"number"==typeof e.from)&&(void 0===e.to||"number"==typeof e.to)&&(void 0===e.resolution||"number"==typeof e.resolution)}class ra{constructor(e){this.http=e}async fetchSinglePage(e){const t={page:e.page.toString(),limit:e.limit.toString()};void 0!==e.type&&(t.type=e.type),void 0!==e.tokenName&&(t.tokenName=e.tokenName),void 0!==e.search&&(t.search=e.search);const a=m(t),n=await this.http.get(Bt,a);Ut(n,"Failed to fetch pools",!0);const r=function(e){if(!e)return[];let t=[];return e.tokens?t=Array.isArray(e.tokens)?e.tokens.map(e=>({...e,createdAt:new Date(e.created_at??e.createdAt)})):[{...e.tokens,createdAt:new Date(e.tokens.created_at??e.tokens.createdAt)}]:e.pools&&Array.isArray(e.pools)&&(t=e.pools.map(e=>({...e,createdAt:new Date(e.created_at??e.createdAt)}))),t}(n.data),o=n.data.count??n.data.total??0;return{pools:r,total:o,totalPages:e.limit>0?Math.ceil(o/e.limit):1}}async fetchMultiplePages(e){const{startPage:t,totalPages:a,pageSize:n,...r}=e,o=[];if(a&&a>=t){const e=[];for(let n=t;n<=a;n++)e.push(n);for(let t=0;t<e.length;t+=5){const a=e.slice(t,t+5).map(e=>this.fetchSinglePage({...r,page:e,limit:n}));(await Promise.all(a)).forEach(e=>{o.push(...e.pools)})}return o}let s=t,i=!0;for(;i;){const e=[];for(let t=0;t<5&&i;t++)e.push(s+t);const t=e.map(e=>this.fetchSinglePage({...r,page:e,limit:n})),a=await Promise.all(t);for(const e of a){if(0===e.pools.length){i=!1;break}o.push(...e.pools)}s+=e.length,s>100&&(i=!1)}return o}async fetchPools(e={}){const t=e.page||1,a=e.limit??10;let n;if(0!==a&&bt({page:t,limit:a}),e.tokenName&&St(e.tokenName),"recent"===e.type?n="RECENT":"popular"===e.type&&(n="POPULAR"),a>0&&a<=20){const r=await this.fetchSinglePage({...e.search&&{search:e.search},...e.tokenName&&{tokenName:e.tokenName},...n&&{type:n},page:t,limit:a});return{pools:r.pools,page:t,limit:a,total:r.total,totalPages:r.totalPages,hasNext:t<r.totalPages,hasPrevious:t>1}}if(0===a){const t=20,a=await this.fetchSinglePage({...e.search&&{search:e.search},...e.tokenName&&{tokenName:e.tokenName},...n&&{type:n},page:1,limit:t}),r=[...a.pools];if(a.pools.length>0){const o=await this.fetchMultiplePages({...e.search&&{search:e.search},...e.tokenName&&{tokenName:e.tokenName},...n&&{type:n},startPage:2,totalPages:a.totalPages>1?a.totalPages:null,pageSize:t});r.push(...o)}return{pools:r,page:1,limit:r.length,total:a.total||r.length,totalPages:1,hasNext:!1,hasPrevious:!1}}const r=Math.ceil(a/20),o=await this.fetchSinglePage({...e.search&&{search:e.search},...e.tokenName&&{tokenName:e.tokenName},...n&&{type:n},page:t,limit:20}),s=[...o.pools],i=Math.min(r,o.totalPages-t+1);if(i>1){const a=t+i-1,r=await this.fetchMultiplePages({...e.search&&{search:e.search},...e.tokenName&&{tokenName:e.tokenName},...n&&{type:n},startPage:t+1,totalPages:a,pageSize:20});s.push(...r)}const c=s.slice(0,a);return{pools:c,page:t,limit:a,total:o.total,totalPages:o.totalPages,hasNext:t<o.totalPages&&c.length<o.total,hasPrevious:t>1}}async fetchAllPools(e){return this.fetchPools({...e,limit:0})}async checkPool(e){It(e),e.tokenName&&St(e.tokenName);const t=m(e),a=await this.http.get(Mt,t);Ut(a,"Failed to check pool");const n=a.data;return e.symbol?n?.isSymbolExist??!1:e.tokenName?n?.isNameExist??!1:n?.exists??!1}async isTokenNameAvailable(e){try{return!await this.checkPool({tokenName:e})}catch{return!1}}async isTokenSymbolAvailable(e){try{return!await this.checkPool({symbol:e})}catch{return!1}}async fetchVolumeData(e){if(!na(e))throw new v("Invalid options provided. Expected { tokenName: string, from?: number, to?: number, resolution?: number }","options","INVALID_OPTIONS");const{tokenName:t,from:a,to:n,resolution:r}=e;if(St(t),!a||!n||!r)throw new v("Graph options (from, to, resolution) are required","options","MISSING_GRAPH_OPTIONS");const o={tokenName:t,from:a,to:n,resolution:r};Ct(o);const s=m(o),i=await this.http.get(Rt,s);return Ut(i,"Failed to fetch graph data",!0),{dataPoints:i.data}}async fetchTokenDistribution(e){if(!e)throw Zt("tokenName","Token name");St(e);const t=await this.resolveTokenNameToVault(e);if(!t)throw new v(y(e),"tokenName","VAULT_NOT_FOUND");const a=encodeURIComponent(t),n=await this.http.get(`${Kt}/${a}`);return Ut(n,"Failed to fetch token distribution",!0),{holders:n.data.holders||[],totalSupply:n.data.totalSupply||"0",totalHolders:n.data.totalHolders||0,lastUpdated:new Date}}async fetchTokenBadges(e){if(!e)throw Zt("tokenName","Token name");St(e);const t=await this.http.get(Gt,{tokenName:e});return Ut(t,"Failed to fetch token badges",!0),{volumeBadges:t.data.volumeBadge||[],engagementBadges:t.data.engagementBadge||[]}}async hasTokenBadge(e){const{tokenName:t,badgeType:a,badgeName:n}=e;try{const e=await this.fetchTokenBadges(t);if(!e)return!1;const r=("volume"===a?e.volumeBadges:e.engagementBadges).find(e=>e.badgeName===n);return r?.isActive||!1}catch{return!1}}async resolveTokenNameToVault(e){try{const t=await this.fetchPools({tokenName:e});return t.pools&&Array.isArray(t.pools)&&t.pools.length>0?t.pools[0].vaultAddress||null:t.pools&&t.pools.tokens&&t.pools.tokens.vaultAddress||null}catch{return null}}}function oa(e,t={}){const{stringifyFields:a=[],optionalFields:n=[],fieldMappings:r={}}=t,o={};for(const[t,s]of Object.entries(e)){const e=t;if(n.includes(e)&&void 0===s)continue;if(n.includes(e)&&"string"==typeof s&&0===s.trim().length)continue;const i=r[e],c=i?String(i):t;a.includes(e)?o[c]=String(s):o[c]=s}return m(o)}const sa={PAGINATION:{MIN_PAGE:1,MAX_PAGE:1e3,MIN_LIMIT:1,MAX_LIMIT:20}};class ia{constructor(e){this.http=e}async fetchTrades(e){if(!(t=e)||"object"!=typeof t||"string"!=typeof t.tokenName||void 0!==t.tradeType&&"buy"!==t.tradeType&&"sell"!==t.tradeType||void 0!==t.userAddress&&"string"!=typeof t.userAddress||void 0!==t.page&&"number"!=typeof t.page||void 0!==t.limit&&"number"!=typeof t.limit)throw new v("Invalid options provided. Expected { tokenName: string, tradeType?: string, userAddress?: string, page?: number, limit?: number, startDate?: Date, endDate?: Date, sortOrder?: string }","options","INVALID_OPTIONS");var t;const{tokenName:a,tradeType:n,userAddress:r,page:o=1,limit:s=10,startDate:i,endDate:c,sortOrder:l}=e;if(!E(a))throw new v("Token name is required and must be a non-empty string","tokenName","INVALID_TOKEN_NAME");k(o,s,sa);const u=function(e,t,a){return oa({tokenName:e,page:t,limit:a},{stringifyFields:["page","limit"]})}(a,o,s),d=await this.http.get(zt,u),h=(g=d.data)?(Array.isArray(g)?g:g.trades?g.trades:[]).map(e=>({...e,createdAt:new Date(e.createdAt),updatedAt:new Date(e.updatedAt)})):[];var g;const m=Ot(d,{page:o,limit:s}),p=xt(m.page,m.totalPages);return{trades:h,...m,...p}}}const ca=new g({debug:!1,context:"DateUtils"});function la(e,t){if(!e)return t||new Date;if(e instanceof Date)return isNaN(e.getTime())?t||new Date:e;try{const a=new Date(e);return isNaN(a.getTime())?(ca.warn(`Invalid date string received: "${e}". Using fallback.`),t||new Date):a}catch(a){return ca.warn(`Date parsing error for "${e}":`,a),t||new Date}}const ua={PAGINATION:{MIN_PAGE:1,MAX_PAGE:1e3,MIN_LIMIT:1,MAX_LIMIT:50},CONTENT:{MIN_LENGTH:1,MAX_LENGTH:500}};class da{constructor(e,t){this.http=e,this.poolService=t}async fetchComments(e){if(!(t=e)||"object"!=typeof t||"string"!=typeof t.tokenName||void 0!==t.page&&"number"!=typeof t.page||void 0!==t.limit&&"number"!=typeof t.limit)throw new v("Invalid options provided. Expected { tokenName: string, page?: number, limit?: number }","options","INVALID_OPTIONS");var t;const{tokenName:a,page:n=1,limit:r=10}=e;if(!E(a))throw new v("Token name is required and must be a non-empty string","tokenName","INVALID_TOKEN_NAME");k(n,r,ua);const o=await this.poolService.resolveTokenNameToVault(a);if(!o)throw Yt(a);const s=oa({vaultAddress:o,page:n,limit:r},{stringifyFields:["page","limit"]}),i=await this.http.get(Vt,s);Ut(i,"Failed to fetch comments");return{comments:i.data.comments.map(e=>({...e,createdAt:la(e.createdAt)})),total:i.data.count}}async postComment(e){if(!(t=e)||"object"!=typeof t||"string"!=typeof t.tokenName||"string"!=typeof t.content)throw new v("Invalid options provided. Expected { tokenName: string, content: string }","options","INVALID_OPTIONS");var t;const{tokenName:a,content:n}=e;if(!E(a))throw new v("Token name is required and must be a non-empty string","tokenName","INVALID_TOKEN_NAME");if(!function(e){if(!e||"string"!=typeof e)return!1;const t=e.trim();return t.length>=ua.CONTENT.MIN_LENGTH&&t.length<=ua.CONTENT.MAX_LENGTH}(n))throw new v(`Comment content must be between ${ua.CONTENT.MIN_LENGTH} and ${ua.CONTENT.MAX_LENGTH} characters`,"content","INVALID_CONTENT");const r=await this.poolService.resolveTokenNameToVault(a);if(!r)throw Yt(a);const o={userAddress:this.http.getAddress(),vaultAddress:r,content:n};Ut(await this.http.post(qt,o),"Failed to create comment")}}const ha={PAGINATION:{MIN_PAGE:1,MAX_PAGE:1e3,MIN_LIMIT:1,MAX_LIMIT:20},USER_ADDRESS:{PATTERN:/^eth\|[0-9a-fA-F]{40}$/},TOKEN_NAME:{MIN_LENGTH:1,MAX_LENGTH:50},SEARCH:{MIN_LENGTH:1,MAX_LENGTH:100},FAUCET_AMOUNT:{POSITIVE_NON_ZERO_DECIMAL:/^(?!0+(\.0+)?$)\d+(\.\d+)?$/},PROFILE:{FULL_NAME:{MIN_LENGTH:1,MAX_LENGTH:100,ALPHABETS_ONLY_PATTERN:/^[a-zA-Z]+(?:\s[a-zA-Z]+)?$/}}};function ga(e){return!(!e||"string"!=typeof e)&&ha.USER_ADDRESS.PATTERN.test(e)}const ma="Update profile";class pa{constructor(e){this.http=e}async fetchProfile(e){const t=e??this.http.getAddress();if(!ga(t))throw new v("Address must be in format: eth|[40-hex-chars]","address","INVALID_ADDRESS");const a={userAddress:t};return await this.http.get(jt,a)}async updateProfile(e){this.validateUpdateProfileData(e);let t=e.profileImage;if(!t||""===t.trim())try{const a=await this.fetchProfile(e.address);t=a.data?.profileImage||""}catch{t=""}const a={profileImage:t,fullName:e.fullName,userAddress:e.address},n=await this.http.signCustomMessage(ma),r={address:n.address,message:ma,publickey:n.ethereumAddress,sign:n.signature};Ut(await this.http.put(Wt,a,r),"Profile update failed")}async uploadProfileImage(e){this.validateUploadProfileImageOptions(e);const t=e.address??this.http.getAddress();try{const a=new FormData;if("undefined"!=typeof File&&e.file instanceof File)a.append("image",e.file);else{if(!Buffer.isBuffer(e.file))throw new v("Invalid file type","file","INVALID_FILE_TYPE");{const n=`profile-image-${t}.png`,r=new Blob([e.file],{type:"image/png"});a.append("image",r,n)}}const n=await this.http.request({method:"POST",url:`${$t}?tokenName=${encodeURIComponent(t)}`,data:a,headers:{}});return Ut(n,"Image upload failed"),"string"==typeof n.data?n.data:""}catch(e){if(e instanceof v)throw e;throw new v(`Profile image upload failed: ${e instanceof Error?e.message:"Unknown error"}`,"file","UPLOAD_FAILED")}}async fetchTokenList(e){this.validateGetTokenListOptions(e);const t=oa({page:e.page,limit:e.limit,type:"all"!==e.type&&e.type?e.type:"DEFI",address:e.address,search:e.search,tokenName:e.tokenName},{stringifyFields:["page","limit"],optionalFields:["address","search","tokenName"]}),a=await this.http.get(Ht,t);Ut(a,"Failed to fetch token list",!0);const n=Lt(a.data),r=Ot(a,{page:e.page||1,limit:e.limit||10}),o=xt(r.page,r.totalPages);return{tokens:n,...r,...o}}async fetchTokensHeld(e){this.validateGetTokenListOptions(e);const t=oa({page:e.page,limit:e.limit,address:e.address,search:e.search,tokenName:e.tokenName},{stringifyFields:["page","limit"],optionalFields:["address","search","tokenName"]}),a=await this.http.get(Qt,t);Ut(a,"Failed to fetch tokens held",!0);const n=Lt(a.data),r=Ot(a,{page:e.page||1,limit:e.limit||10}),o=xt(r.page,r.totalPages);return{tokens:n,...r,...o}}async fetchTokensCreated(e={}){const{page:t=1,limit:a=10,search:n,tokenName:r}=e,o={type:"DEFI",address:this.http.getAddress(),page:t,limit:a};return void 0!==n&&(o.search=n),void 0!==r&&(o.tokenName=r),this.fetchTokenList(o)}validateGetTokenListOptions(e){if(k(e.page,e.limit,ha),void 0!==e.address&&!ga(e.address))throw new v("Address must be in format: eth|[40-hex-chars]","address","INVALID_ADDRESS");if(void 0!==e.search&&e.search.trim().length>0&&!((t=e.search)&&"string"==typeof t&&t.length>=ha.SEARCH.MIN_LENGTH&&t.length<=ha.SEARCH.MAX_LENGTH))throw new v(`Search query must be between ${ha.SEARCH.MIN_LENGTH} and ${ha.SEARCH.MAX_LENGTH} characters`,"search","INVALID_SEARCH");var t,a;if(void 0!==e.tokenName&&e.tokenName.trim().length>0&&!((a=e.tokenName)&&"string"==typeof a&&a.length>=ha.TOKEN_NAME.MIN_LENGTH&&a.length<=ha.TOKEN_NAME.MAX_LENGTH))throw new v(`Token name must be between ${ha.TOKEN_NAME.MIN_LENGTH} and ${ha.TOKEN_NAME.MAX_LENGTH} characters`,"tokenName","INVALID_TOKEN_NAME")}validateUpdateProfileData(e){if(!ga(e.address))throw new v("Address must be in format: eth|[40-hex-chars]","address","INVALID_ADDRESS");if(!((t=e.fullName)&&"string"==typeof t&&t.length>=ha.PROFILE.FULL_NAME.MIN_LENGTH&&t.length<=ha.PROFILE.FULL_NAME.MAX_LENGTH&&ha.PROFILE.FULL_NAME.ALPHABETS_ONLY_PATTERN.test(t)))throw new v(`Full name must be between ${ha.PROFILE.FULL_NAME.MIN_LENGTH} and ${ha.PROFILE.FULL_NAME.MAX_LENGTH} characters`,"fullName","INVALID_FULL_NAME");var t}validateUploadProfileImageOptions(e){if(e.address&&!ga(e.address))throw new v("Address must be in format: eth|[40-hex-chars]","address","INVALID_ADDRESS")}}class fa extends Error{constructor(e,t,a){super(e),this.filename=t,this.mimeType=a,this.name="FileValidationError"}}function ya(e,t,a){if(!e)throw new fa("File is required",t,a);if("undefined"!=typeof File&&e instanceof File){const t=fe.safeParse(e);if(!t.success){const a=t.error.errors.map(e=>e.message).join("; ");throw new fa(a,e.name,e.type)}return}if(Buffer.isBuffer(e)){if(!t)throw new fa("Filename is required when uploading Buffer objects",t,a);const n=ye.safeParse(e);if(!n.success){const e=n.error.errors.map(e=>e.message).join("; ");throw new fa(e,t,a)}if(t.length>255)throw new fa(`Filename length ${t.length} exceeds maximum allowed length of 255 characters`,t,a);const r=["image/png","image/jpg","image/jpeg","image/gif","image/webp","image/svg+xml"];if(!r.includes(a))throw new fa(`Invalid file type "${a}" is not allowed. Allowed types: ${r.join(", ")}`,t,a);const o=function(e){if(!e)return"";const t=e.lastIndexOf(".");if(-1===t)return"";return e.substring(t).toLowerCase()}(t),s=[".png",".jpg",".jpeg",".gif",".webp",".svg"];if(!s.includes(o))throw new fa(`File extension "${o}" is not allowed. Allowed extensions: ${s.join(", ")}`,t,a);const i=function(e){switch(e.toLowerCase()){case".png":return"image/png";case".jpg":case".jpeg":return"image/jpeg";case".gif":return"image/gif";case".webp":return"image/webp";case".svg":return"image/svg+xml";default:return"application/octet-stream"}}(o);if(i!==a&&"application/octet-stream"!==i)throw new fa(`File extension "${o}" does not match MIME type "${a}"`,t,a);return}throw new fa("File must be a File object (browser) or Buffer (Node.js)",t,a)}class va{constructor(e){this.http=e}async uploadImageByTokenName(e){const{tokenName:t,options:a}=e;St(t);const n=`${t}.png`;ya(a.file,n,"image/png");try{const e=new FormData;if("undefined"!=typeof File&&a.file instanceof File)e.append("image",a.file);else{if(!Buffer.isBuffer(a.file))throw Jt("file","a File object (browser) or Buffer (Node.js)");{const n=`${a.tokenName??t}.png`,r=new Blob([a.file],{type:"image/png"});e.append("image",r,n)}}const n=await this.http.request({method:"POST",url:`${$t}?tokenName=${encodeURIComponent(a.tokenName??t)}`,data:e,headers:{}});return Ut(n,"Image upload failed"),"string"==typeof n.data?n.data:""}catch(e){if(e instanceof Error&&e.message.includes("FormData"))throw ta("File upload failed: FormData not supported in this environment. Ensure you have proper polyfills for Node.js environments.","FormData");throw e}}}class Aa{constructor(e){this.http=e}async transferFaucets(e){this.validateTransferFaucetsData(e);const t={userAddress:e.walletAddress,amount:e.amount};Ut(await this.http.post(Xt,t),"Faucet transfer failed")}validateTransferFaucetsData(e){if(!ga(e.walletAddress))throw new v("Address must be in format: eth|[40-hex-chars]","address","INVALID_ADDRESS");if(!(t=e.amount)||"string"!=typeof t||!ha.FAUCET_AMOUNT.POSITIVE_NON_ZERO_DECIMAL.test(t))throw new v("Amount must be a positive decimal string greater than zero","amount","INVALID_AMOUNT");var t}}class wa{constructor(e){this.http=e,this.poolService=new ra(e),this.tradeService=new ia(e),this.commentService=new da(e,this.poolService),this.userService=new pa(e),this.imageService=new va(e),this.faucetService=new Aa(e)}async uploadImageByTokenName(e){return this.imageService.uploadImageByTokenName(e)}async fetchPools(e={}){return this.poolService.fetchPools(e)}async fetchAllPools(e){return this.poolService.fetchAllPools(e)}async checkPool(e){return this.poolService.checkPool(e)}async isTokenNameAvailable(e){return this.poolService.isTokenNameAvailable(e)}async isTokenSymbolAvailable(e){return this.poolService.isTokenSymbolAvailable(e)}async fetchVolumeData(e){return this.poolService.fetchVolumeData(e)}async fetchTokenDistribution(e){return this.poolService.fetchTokenDistribution(e)}async fetchTokenBadges(e){return this.poolService.fetchTokenBadges(e)}async hasTokenBadge(e){return this.poolService.hasTokenBadge(e)}async fetchTrades(e){return this.tradeService.fetchTrades(e)}async fetchComments(e){return this.commentService.fetchComments(e)}async postComment(e){return this.commentService.postComment(e)}async fetchProfile(e){return this.userService.fetchProfile(e)}async updateProfile(e){return this.userService.updateProfile(e)}async uploadProfileImage(e){return this.userService.uploadProfileImage(e)}async fetchTokenList(e){return this.userService.fetchTokenList(e)}async fetchTokensHeld(e){return this.userService.fetchTokensHeld(e)}async fetchTokensCreated(e={}){return this.userService.fetchTokensCreated(e)}async transferFaucets(e){return this.faucetService.transferFaucets(e)}getAddress(){return this.http.getAddress()}validateTokenName(e){return St(e)}}class Ta extends n.ChainCallDTO{constructor(e){super(),this.from=e.from,this.to=e.to,this.quantity=e.quantity,this.tokenInstance=e.tokenInstance,this.uniqueKey=e.uniqueKey,e.signedPayload&&(this.signature=e.signedPayload.signature,this.domain=e.signedPayload.domain,this.types=e.signedPayload.types,e.signedPayload.prefix&&(this.prefix=e.signedPayload.prefix))}static fromTokenClassKey(e,t,a,n,r){let o;if("string"==typeof n){const e=n.split("$");if(4!==e.length)throw new Error(`Invalid token class key format: ${n}. Expected format: collection$category$type$additionalKey`);o={collection:e[0],category:e[1],type:e[2],additionalKey:e[3],instance:"0"}}else o={collection:n.collection,category:n.category,type:n.type,additionalKey:n.additionalKey,instance:"0"};return new Ta({from:e,to:t,quantity:a,tokenInstance:o,uniqueKey:r||`galaconnect-operation-${Date.now()}_${Math.random().toString(36).substring(2,8)}`})}static forGALA(e,t,a,n){return new Ta({from:e,to:t,quantity:a,tokenInstance:{collection:"GALA",category:"Unit",type:"none",additionalKey:"none",instance:"0"},uniqueKey:n||`galaconnect-operation-${Date.now()}_${Math.random().toString(36).substring(2,8)}`})}getTokenClassKey(){return`${this.tokenInstance.collection}$${this.tokenInstance.category}$${this.tokenInstance.type}$${this.tokenInstance.additionalKey}`}toSigningPayload(){return{from:this.from,to:this.to,quantity:this.quantity,tokenInstance:this.tokenInstance,uniqueKey:this.uniqueKey}}}class ka{constructor(e){this.wallet=e}static generateUniqueKey(){return`${Date.now()}_${Math.random().toString(36).substring(2,8)}`}async signTransferToken(e){const t={name:"GalaChain",chainId:1},a={TransferToken:[{name:"from",type:"string"},{name:"to",type:"string"},{name:"quantity",type:"string"},{name:"tokenInstance",type:"TokenInstance"},{name:"uniqueKey",type:"string"}],TokenInstance:[{name:"collection",type:"string"},{name:"category",type:"string"},{name:"type",type:"string"},{name:"additionalKey",type:"string"},{name:"instance",type:"string"}]};return{signature:await this.wallet.signTypedData(t,a,e),domain:t,types:a,signerPublicKey:this.wallet.signingKey.publicKey}}static toGalaChainAddress(e){const a=e.replace("0x","");return`eth|${t.ethers.getAddress(`0x${a}`).replace("0x","")}`}static fromGalaChainAddress(e){return e.startsWith("eth|")?e.substring(4):e}static createGALATokenInstance(){return{collection:"GALA",category:"Unit",type:"none",additionalKey:"none",instance:"0"}}static createTokenInstanceFromClassKey(e){const t=e.split("$");if(4!==t.length)throw new Error(`Invalid token class key format: ${e}. Expected format: collection$category$type$additionalKey`);return{collection:t[0],category:t[1],type:t[2],additionalKey:t[3],instance:"0"}}}function Na(e){if("string"==typeof e){const t=e.split("|");if(t.length<4)throw new v(`Invalid tokenId string format: "${e}". Expected format: "collection|category|type|additionalKey" or "collection|category|type|additionalKey|instance"`,"tokenId","INVALID_TOKEN_ID_FORMAT");if(!(t[0]&&t[1]&&t[2]&&t[3]))throw new v(`Invalid tokenId string format: "${e}". All components (collection, category, type, additionalKey) must be non-empty`,"tokenId","INVALID_TOKEN_ID_FORMAT");return{collection:t[0],category:t[1],type:t[2],additionalKey:t[3],instance:t[4]||"0"}}if("object"==typeof e&&null!==e){if(!(e.collection&&e.category&&e.type&&e.additionalKey))throw new v("Invalid tokenId object format. All fields (collection, category, type, additionalKey) are required","tokenId","INVALID_TOKEN_ID_FORMAT");return"instance"in e&&void 0!==e.instance?e:{...e,instance:"0"}}throw new v(`Invalid tokenId type: ${typeof e}. Expected string, TokenClassKey, or TokenInstanceKey`,"tokenId","INVALID_TOKEN_ID_TYPE")}var Ea=Object.freeze({__proto__:null,normalizeToTokenInstanceKey:Na});const Sa={MAX_UNIQUE_KEY_LENGTH:64,UNIQUE_KEY_PATTERN:/^(galaswap-operation-|galaconnect-operation-)/,TOKEN_NAME_PATTERN:/^[a-zA-Z0-9]+$/};var ba;!function(e){e.INVALID_RECIPIENT="INVALID_RECIPIENT",e.INVALID_AMOUNT="INVALID_AMOUNT",e.INSUFFICIENT_BALANCE="INSUFFICIENT_BALANCE",e.TOKEN_NOT_FOUND="TOKEN_NOT_FOUND",e.SIGNATURE_FAILED="SIGNATURE_FAILED",e.NETWORK_ERROR="NETWORK_ERROR",e.DUPLICATE_TRANSFER="DUPLICATE_TRANSFER",e.TRANSFER_LIMIT_EXCEEDED="TRANSFER_LIMIT_EXCEEDED"}(ba||(ba={}));class Ia extends Error{constructor(e,t,a){super(e),this.type=t,this.details=a,this.name="TransferError"}}class Fa{constructor(e,t,a,n=!1){this.http=e,this.wallet=t,this.tokenResolver=a,this.signatureHelper=new ka(t),this.logger=new g({debug:n,context:"GalaChainService"})}async fetchPoolDetails(e){this.validateFetchPoolDetailsData(e);const t=await this.http.post("/api/asset/launchpad-contract/FetchSaleDetails",e);if(1!==t.Status)throw ea(`Failed to fetch pool details: Status ${t.Status}`,t.Status);const a=t.Data,n=a.reverseBondingCurveConfiguration,r=n?.minFeePortion??"0",o=n?.maxFeePortion??"0",s=(await import("bignumber.js")).default,i=!new s(r).isZero()||!new s(o).isZero();return a.reverseBondingCurveMinFeePortion=r,a.reverseBondingCurveMaxFeePortion=o,a.hasReverseBondingCurveFee=i,a.isGraduated="Completed"===a.saleStatus,delete a.reverseBondingCurveConfiguration,t}async fetchLaunchTokenFee(){const e=await this.http.post("/api/asset/launchpad-contract/FetchLaunchpadFeeAmount",{});if(1!==e.Status)throw ea(`Failed to fetch launch token fee: Status ${e.Status}`,e.Status);return e.Data.feeAmount}validateFetchPoolDetailsData(e){if(!(t=e)||"object"!=typeof t||"string"!=typeof t.vaultAddress)throw new v("Invalid fetch pool details data: missing required fields","data","INVALID_TYPE");var t;if(!e.vaultAddress||"string"!=typeof e.vaultAddress)throw new v("Vault address is required and must be a string","vaultAddress","INVALID_VAULT_ADDRESS");if(!e.vaultAddress.startsWith("service|Token$Unit$"))throw new v("Vault address must be in service format: service|Token$Unit$...","vaultAddress","INVALID_VAULT_ADDRESS")}async fetchGalaBalance(e){return this.fetchTokenBalance(e)}async fetchTokenBalance(e){try{const t=await this.http.post("/api/asset/token-contract/FetchBalances",e);if(1!==t.Status||!t.Data||0===t.Data.length)return null;const a=t.Data.find(t=>t.collection===e.collection&&t.category===e.category&&t.additionalKey===e.additionalKey&&t.type===e.type);if(!a||"0"===a.quantity)return null;const n=`${a.collection}|${a.category}|${a.additionalKey}|${a.type}`;return{quantity:a.quantity,collection:a.collection,category:a.category,tokenId:n}}catch(e){throw ea(`Failed to fetch token balance from GalaChain: ${e.message||"Unknown error"}`,void 0,e)}}async transferGala(e){this.validateTransferGalaData(e);try{const t=b(e.recipientAddress),a=b(this.wallet.address),n=Ta.forGALA(a,t,e.amount,e.uniqueKey),r=await this.signatureHelper.signTransferToken(n.toSigningPayload()),o=new Ta({...n.toSigningPayload(),signedPayload:r});this.logger.debug("[DEBUG] Full GALA Transfer Request Payload:",JSON.stringify(o,null,2));const s=await this.http.post("/api/asset/token-contract/TransferToken",o);if(this.logger.debug("[DEBUG] Transfer response:",JSON.stringify(s,null,2)),s&&"object"==typeof s){if("Status"in s&&1===s.Status&&"Data"in s){const e=s;return Array.isArray(e.Data)&&e.Data.length>0?"gala-transfer-successful":"transfer-successful-no-id"}if("transactionId"in s&&s.transactionId)return s.transactionId}throw new Ia("Transfer succeeded but transaction ID could not be extracted",ba.NETWORK_ERROR)}catch(t){throw this.handleTransferError(t,"GALA transfer failed",e)}}async transferToken(e){this.validateTransferTokenData(e);try{const t=b(e.to),a=b(this.wallet.address);let n;if(e.tokenId)n=Na(e.tokenId),this.logger.debug("[DEBUG] Using provided tokenId:",e.tokenId),this.logger.debug("[DEBUG] Normalized Token Instance:",JSON.stringify(n,null,2));else{if(!e.tokenName)throw new Ia("Must provide either tokenId or tokenName for token identification",ba.TOKEN_NOT_FOUND);n=await this.resolveTokenInstance(e.tokenName)}const r=new Ta({from:a,to:t,quantity:e.amount,tokenInstance:n,uniqueKey:e.uniqueKey||`galaconnect-operation-${Date.now()}_${Math.random().toString(36).substring(2,8)}`}),o=await this.signatureHelper.signTransferToken(r.toSigningPayload()),s=new Ta({...r.toSigningPayload(),signedPayload:o});this.logger.debug("[DEBUG] Full Transfer Request Payload:",JSON.stringify(s,null,2));const i=await this.http.post("/api/asset/token-contract/TransferToken",s);if(this.logger.debug("[DEBUG] Token transfer response:",JSON.stringify(i,null,2)),i&&"object"==typeof i){if("Status"in i&&1===i.Status&&"Data"in i){const e=i;return Array.isArray(e.Data)&&e.Data.length>0?"token-transfer-successful":"transfer-successful-no-id"}if("transactionId"in i&&i.transactionId)return i.transactionId}throw new Ia("Transfer succeeded but transaction ID could not be extracted",ba.NETWORK_ERROR)}catch(t){throw this.handleTransferError(t,"Token transfer failed",e)}}async resolveTokenClassKey(e){try{const t=await this.tokenResolver.resolveTokenClassKey(e);return this.logger.debug(`[DEBUG] Token class key resolution for '${e}':`,JSON.stringify(t,null,2)),t}catch(t){if(t instanceof Ia)throw t;throw new Ia(`Failed to resolve token class key for '${e}': ${t instanceof Error?t.message:String(t)}`,ba.TOKEN_NOT_FOUND,{tokenName:e})}}validateTransferGalaData(e){if(!((t=e)&&"object"==typeof t&&"string"==typeof t.recipientAddress&&t.recipientAddress.trim().length>0&&"string"==typeof t.amount&&t.amount.trim().length>0)||void 0!==t.uniqueKey&&"string"!=typeof t.uniqueKey)throw new v("Invalid GALA transfer data: missing required fields");var t;if(!S(e.recipientAddress))throw new Ia("Invalid recipient address format",ba.INVALID_RECIPIENT,{recipientAddress:e.recipientAddress});if(parseFloat(e.amount)<=0)throw new Ia("Transfer amount must be positive",ba.INVALID_AMOUNT,{amount:e.amount});if(e.uniqueKey){if(e.uniqueKey.length>Sa.MAX_UNIQUE_KEY_LENGTH)throw new v(`Unique key too long. Maximum length: ${Sa.MAX_UNIQUE_KEY_LENGTH}`);if(!Sa.UNIQUE_KEY_PATTERN.test(e.uniqueKey))throw new Ia('Invalid unique key format. Must start with "galaswap-operation-" or "galaconnect-operation-"',ba.INVALID_AMOUNT,{uniqueKey:e.uniqueKey})}}validateTransferTokenData(e){if(!((t=e)&&"object"==typeof t&&"string"==typeof t.to&&t.to.trim().length>0&&"string"==typeof t.amount&&t.amount.trim().length>0&&(void 0!==t.tokenId||"string"==typeof t.tokenName&&t.tokenName.trim().length>0))||void 0!==t.uniqueKey&&"string"!=typeof t.uniqueKey)throw new v("Invalid token transfer data: missing required fields");var t;if(!S(e.to))throw new Ia("Invalid recipient address format",ba.INVALID_RECIPIENT,{recipientAddress:e.to});if(!e.tokenId&&!e.tokenName)throw new Ia("Must provide either tokenId or tokenName for token identification",ba.TOKEN_NOT_FOUND);if(e.tokenName&&!Sa.TOKEN_NAME_PATTERN.test(e.tokenName))throw new Ia("Invalid token name format",ba.TOKEN_NOT_FOUND,{tokenName:e.tokenName});if(parseFloat(e.amount)<=0)throw new Ia("Transfer amount must be positive",ba.INVALID_AMOUNT,{amount:e.amount});if(e.uniqueKey){if(e.uniqueKey.length>Sa.MAX_UNIQUE_KEY_LENGTH)throw new v(`Unique key too long. Maximum length: ${Sa.MAX_UNIQUE_KEY_LENGTH}`);if(!Sa.UNIQUE_KEY_PATTERN.test(e.uniqueKey))throw new Ia('Invalid unique key format. Must start with "galaswap-operation-" or "galaconnect-operation-"',ba.INVALID_AMOUNT,{uniqueKey:e.uniqueKey})}}async resolveTokenInstance(e){try{const t=await this.tokenResolver.resolveTokenToVault(e);if(!t)throw new Ia(`Token '${e}' not found or not available for transfer`,ba.TOKEN_NOT_FOUND,{tokenName:e});const a=this.resolveTokenInstanceFromVaultAddress(t);return this.logger.debug(`[DEBUG] Token resolution for '${e}':\n Vault Address: ${t}\n Token Instance: ${JSON.stringify(a,null,2)}`),a}catch(t){if(t instanceof Ia)throw t;throw new Ia(`Failed to resolve token '${e}': ${t instanceof Error?t.message:String(t)}`,ba.TOKEN_NOT_FOUND,{tokenName:e})}}resolveTokenInstanceFromVaultAddress(e){const[t,a]=e.split("|");if(!a)throw new Ia(`Invalid vault address format: missing token components. Address: ${e}`,ba.TOKEN_NOT_FOUND);const n=a.split("$");if(n.length<4)throw new Ia(`Invalid vault address format: insufficient token components. Expected 4+, got ${n.length}. Address: ${e}`,ba.TOKEN_NOT_FOUND);return{collection:n[0],category:n[1],type:n[2],additionalKey:n[3],instance:"0"}}handleTransferError(e,t,a){if(e instanceof Ia)return e;if(e instanceof v)return new Ia(e.message,ba.INVALID_AMOUNT);if(400===e.response?.status)return new Ia(e.response.data?.message||"Invalid transfer request",ba.INVALID_AMOUNT);if(403===e.response?.status)return new Ia("Insufficient balance for transfer",ba.INSUFFICIENT_BALANCE);if(404===e.response?.status){const e={};return"tokenName"in a&&(e.tokenName=a.tokenName),new Ia("Token not found",ba.TOKEN_NOT_FOUND,e)}return"ECONNABORTED"===e.code||"ETIMEDOUT"===e.code?new Ia("Transfer request timed out",ba.NETWORK_ERROR):new Ia(e.message||t,ba.NETWORK_ERROR)}}class Ca{constructor(e){this.http=e}async fetchTokenSpotPrice(e){if(!e||Array.isArray(e)&&0===e.length)throw Zt("symbols","At least one symbol");const t=Array.isArray(e)?e.join(","):e;try{const e=await this.http.request({method:"GET",url:"/v1/tokens",params:{symbols:t}}),a=[];return e.tokens&&Array.isArray(e.tokens)&&e.tokens.forEach(e=>{e.currentPrices&&e.symbol&&a.push({symbol:e.symbol,price:e.currentPrices.usd})}),a}catch(e){throw ea(`Failed to fetch token prices: ${e instanceof Error?e.message:e}`)}}async fetchLaunchpadTokenSpotPrice(e,t){if(!e||"string"!=typeof e)throw new Error(f);try{const a=await t({tokenName:e,amount:"1",type:"native"}),n=(await this.fetchTokenSpotPrice("GALA"))[0];if(!n)throw ea("GALA price not available");const r=Number(a.amount)/1e18;if(r<=0)throw new v(`Invalid token amount calculation: ${r}`,"amount","INVALID_CALCULATION");const o=n.price/r;return{symbol:e.toUpperCase(),price:o}}catch(t){if(t instanceof Error)throw ea(`Failed to calculate launchpad token spot price for ${e}: ${t.message}`);throw ea(`Failed to calculate launchpad token spot price for ${e}: ${String(t)}`)}}}function Da(e,t=18){const a=parseFloat(e);if(0===a)return"0";return a.toFixed(t).replace(/\.?0+$/,"")}function Pa(e){return Da(e,8)}function _a(e){return Da(e,18)}new g({debug:!1,context:"NumberUtils"});class La extends n.ChainCallDTO{constructor(e,t,a="0",n={maxAcceptableReverseBondingCurveFee:"0"}){super(),this.vaultAddress=e,this.nativeTokenQuantity=Pa(t),this.expectedToken=_a(a),this.extraFees={maxAcceptableReverseBondingCurveFee:Pa(n.maxAcceptableReverseBondingCurveFee)}}}class Oa extends n.ChainCallDTO{constructor(e,t,a,n={maxAcceptableReverseBondingCurveFee:"0"}){super(),this.vaultAddress=e,this.tokenQuantity=_a(t),this.expectedNativeToken=Pa(a),this.extraFees={maxAcceptableReverseBondingCurveFee:Pa(n.maxAcceptableReverseBondingCurveFee)}}}class xa extends n.ChainCallDTO{constructor(e,t,a="0",n={maxAcceptableReverseBondingCurveFee:"0"}){super(),this.vaultAddress=e,this.tokenQuantity=_a(t),this.expectedNativeToken=Pa(a),this.extraFees={maxAcceptableReverseBondingCurveFee:Pa(n.maxAcceptableReverseBondingCurveFee)}}}class Ua extends n.ChainCallDTO{constructor(e,t,a,n={maxAcceptableReverseBondingCurveFee:"0"}){super(),this.vaultAddress=e,this.nativeTokenQuantity=Pa(t),this.expectedToken=_a(a),this.extraFees={maxAcceptableReverseBondingCurveFee:Pa(n.maxAcceptableReverseBondingCurveFee)}}}const $a={BuyNativeDto:La,BuyExactDto:Oa,SellExactDto:xa,SellNativeDto:Ua};var Ba,Ma,Ra;!function(e){e[e.METAMASK=0]="METAMASK",e[e.TRUST_WALLET=1]="TRUST_WALLET",e[e.GALA_WALLET=2]="GALA_WALLET"}(Ba||(Ba={}));class Ka{constructor(e,t=!1){this.walletProvider=e,this.debug=t,this.logger=new g({debug:t,context:"SignatureService"})}async signDTO(e,t,a,r=Ba.METAMASK){try{this.logger.debug("๐Ÿ” Signing DTO:",{methodName:t,walletPreference:r,dtoKeys:Object.keys(e)});const o=this.generateEIP712Types(t,e),s=n.calculatePersonalSignPrefix(e),i={...e,prefix:s};let c,l,u;switch(r){case Ba.GALA_WALLET:({signature:c,domain:l}=await this.signWithGalaWallet(o,i,t,a));break;case Ba.TRUST_WALLET:c=await this.signWithTrustWallet(i),l={name:"ethereum",chainId:1};break;case Ba.METAMASK:default:({signature:c,domain:l}=await this.signWithMetaMask(o,i))}return u=r===Ba.TRUST_WALLET?{...i,signature:c}:{...e,signature:c,types:o,domain:l},this.logger.debug("โœ… DTO signed successfully:",{payloadKeys:Object.keys(u),signatureLength:c.length}),u}catch(e){throw this.logger.error("โŒ Signature generation failed:",e),aa(`Failed to sign DTO: ${e.message}`)}}async signWithMetaMask(e,t){try{let a,n;if(this.walletProvider.signTypedData&&!this.walletProvider.getNetwork)a={name:"ethereum",chainId:1},n=await this.walletProvider.signTypedData(a,e,t);else{if(!this.walletProvider.getNetwork||!this.walletProvider.signTypedData)throw ta("Wallet provider does not support typed data signing","walletProvider");{const r=await this.walletProvider.getNetwork();a={name:r.name,chainId:Number(r.chainId)},n=await this.walletProvider.signTypedData(a,e,t)}}return{signature:n,domain:a}}catch(e){throw aa(`MetaMask/ethers signing failed: ${e.message}`)}}async signWithTrustWallet(e){try{const a=(t=e,JSON.stringify(t));let n;if(!this.walletProvider.signMessage)throw ta("Wallet provider does not support signMessage","walletProvider");return n=await this.walletProvider.signMessage(a),n}catch(e){throw aa(`TrustWallet signing failed: ${e.message}`)}var t}async signWithGalaWallet(e,t,a,n){try{const r={name:"ethereum",chainId:1};if("undefined"==typeof window)return this.logger.warn("โš ๏ธ GalaWallet not available in Node.js environment, falling back to ethers.js signing"),await this.signWithMetaMask(e,t);const o={domain:r,types:e,message:t,Primary_type:a},s=window;if(!s?.gala)throw ta("GalaWallet not found in window object","galaWallet");await s.gala.setAddress(n);return{signature:await s.gala.request({method:"eth_signTypedData",params:[JSON.stringify(o),n]}),domain:r}}catch(e){throw aa(`GalaWallet signing failed: ${e.message}`)}}generateEIP712Types(e,t){const a={};a[e]=[];const n=(e,t,r,o=!1)=>{if(void 0!==t){if(Array.isArray(t)){const s=n(e,t[0],r,!0);return o||a[r].push({name:e,type:(s??e)+"[]"}),s?s+"[]":void 0}if("object"==typeof t&&null!==t){if(a[e])throw new v(`Type name collision not supported: ${e}`,"fieldValue","TYPE_COLLISION");return a[e]=[],Object.entries(t).forEach(([t,a])=>{n(t,a,e)}),o||a[r].push({name:e,type:e}),e}{let n;switch(typeof t){case"string":n="string";break;case"number":n="uint256";break;case"boolean":n="bool";break;default:throw new v(`Unsupported type for fieldName ${e}: ${typeof t}, value: ${t}`,"fieldValue","UNSUPPORTED_TYPE")}return o||a[r].push({name:e,type:n}),n}}};return Object.entries(t).forEach(([t,a])=>{n(t,a,e)}),this.logger.debug("๐Ÿ“ Generated EIP-712 types:",a),a}detectWalletPreference(){if("undefined"==typeof window)return Ba.METAMASK;const e=window;return e?.gala?Ba.GALA_WALLET:e?.trustWallet?.isTrust?Ba.TRUST_WALLET:Ba.METAMASK}}class Ga{constructor(e=!1){this.debug=e,this.logger=new g({debug:e,context:"TokenClassKeyService"})}generateStringsInstructions(e){try{this.logger.debug("๐Ÿ”ง Generating stringsInstructions for:",e);const t=this.extractTokenSymbolFromVault(e),a=this.createTokenInstance(t),n=this.createGalaInstance(),r=`$service$${a.toStringKey()}$launchpad`,o=`$tokenBalance$${a.toStringKey()}$${e}`,s=`$tokenBalance$${a.toStringKey()}$${e}`,i=`$tokenBalance$${n.toStringKey()}$${e}`,c=[r,o,s,i,`$tokenBalance$${n.toStringKey()}$${e}`];return this.logger.debug("โœ… Generated stringsInstructions:",c),c}catch(e){throw this.logger.error("โŒ Failed to generate stringsInstructions:",e),new v(`Failed to generate stringsInstructions: ${e.message}`,"vaultAddress","INVALID_VAULT_ADDRESS")}}createTokenInstance(e){const t=new o.TokenClassKey;return t.collection=e.toLowerCase(),t.category="Unit",t.type="none",t.additionalKey="none",this.logger.debug("๐Ÿช™ Created token instance:",{symbol:e,lowercaseCollection:e.toLowerCase(),stringKey:t.toStringKey()}),t}createGalaInstance(){const e=new o.TokenClassKey;return e.collection="GALA",e.category="Unit",e.type="none",e.additionalKey="none",this.logger.debug("๐ŸŸก Created GALA instance:",{stringKey:e.toStringKey()}),e}extractTokenSymbolFromVault(e){if(!e||"string"!=typeof e)throw Zt("vaultAddress","Vault address");const t=e.split("$");if(t.length<3)throw Jt("vaultAddress","format: service|Token$Unit$SYMBOL$eth:address$launchpad");const a=t[2];if(!a||0===a.trim().length)throw new v(`Empty token symbol in vault address: ${e}`,"vaultAddress","EMPTY_TOKEN_SYMBOL");return this.logger.debug("๐Ÿ” Extracted token symbol:",{vaultAddress:e,tokenSymbol:a,parts:t.slice(0,4)}),a}validateVaultAddress(e){if(!e||"string"!=typeof e)throw Zt("vaultAddress","Vault address");if(!e.startsWith("service|Token$Unit$"))throw Jt("vaultAddress",'starting with "service|Token$Unit$"');if(!e.endsWith("$launchpad"))throw Jt("vaultAddress",'ending with "$launchpad"');const t=e.split("$");if(t.length<5)throw Jt("vaultAddress",'having at least 5 parts separated by "$"');const a=t[2];if(!a||!/^[A-Za-z]{1,10}$/.test(a))throw Jt("vaultAddress","containing a 1-10 letter token symbol (case insensitive)");return this.logger.debug("โœ… Vault address validation passed:",e),!0}generateTokenClassKeyString(e,t,a,n){return`${e}$${t}$${a}$${n}`}parseTokenClassKeyString(e){const t=e.split("$");if(4!==t.length)throw Jt("stringKey","format: collection$category$type$additionalKey (4 parts)");return{collection:t[0],category:t[1],type:t[2],additionalKey:t[3]}}}function za(e,t,a){if(t<0||t>1)throw new Error(`Invalid slippage tolerance factor: ${t}. Must be between 0 and 1 (e.g., 0.05 for 5%)`);const n=new s(e);if(n.isNaN())throw new Error(`Invalid expected amount: ${e}. Must be a valid number`);if(0===t)return e;const r=n.multipliedBy(t);let o;switch(a){case"buy-native":case"sell-exact":o=n.minus(r);break;case"buy-exact":case"sell-native":o=n.plus(r);break;default:throw new Error(`Unknown operation type: ${a}`)}return o.isLessThan(0)&&(o=new s(0)),o.toFixed()}class Va{constructor(e,t,a=!1,n,r,o=.05,s=.01){this.httpClient=e,this.tokenResolver=t,this.walletProvider=n,this.userAddress=r,this.defaultSlippageToleranceFactor=o,this.defaultMaxAcceptableReverseBondingCurveFeeSlippageFactor=s,this.bundleEndpoint="/bundle",this.logger=new g({debug:a,context:"BundleService"}),n&&r&&(this.signatureService=new Ka(n,a),this.tokenKeyService=new Ga(a))}async submitTransaction(e){try{this.logger.debug("๐Ÿ“ฆ Submitting bundle transaction:",{method:e.method,stringsInstructionsCount:e.stringsInstructions.length,signedDtoKeys:Object.keys(e.signedDto)}),this.validateBundleData(e);const t=this.formatBundleRequest(e);this.logger.debug("๐Ÿš€ Bundle request payload:",{...t,signedDto:"[REDACTED - Contains signature]"});const a=await this.httpClient.post(this.bundleEndpoint,t);return this.logger.debug("๐Ÿ“ฅ Bundle API response:",{success:a.success,hasData:!!a.data,error:a.error}),this.handleBundleResponse(a)}catch(e){return this.logger.error("โŒ Bundle transaction submission failed:",e),{success:!1,error:this.formatErrorMessage(e)}}}validateBundleData(e){if(!e)throw Zt("bundleData","Bundle data");if(!e.signedDto)throw Zt("signedDto","Signed DTO");if(!e.method||"string"!=typeof e.method)throw Zt("method","Method name");if(!Array.isArray(e.stringsInstructions))throw Jt("stringsInstructions","an array of resource tracking strings");if(0===e.stringsInstructions.length)throw new v("stringsInstructions cannot be empty","stringsInstructions","EMPTY_ARRAY");const t=["BuyWithNative","BuyExactToken","SellExactToken","SellWithNative"];if(!t.includes(e.method))throw Jt("method",`one of: ${t.join(", ")}`);e.stringsInstructions.forEach((e,t)=>{if("string"!=typeof e||0===e.length)throw new v(`stringsInstructions[${t}] must be a non-empty string`,`stringsInstructions[${t}]`,"INVALID_INSTRUCTION");if(!e.startsWith("$"))throw new v(`stringsInstructions[${t}] must start with '$': ${e}`,`stringsInstructions[${t}]`,"INVALID_INSTRUCTION_FORMAT")}),this.logger.debug("โœ… Bundle data validation passed")}formatBundleRequest(e){return{signedDto:e.signedDto,stringsInstructions:e.stringsInstructions,method:e.method}}handleBundleResponse(e){if(e.data&&!1===e.error)return this.logger.debug("โœ… Bundle transaction successful:",e.data),{success:!0,data:e.data};const t=e.error||e.message||"Bundle transaction failed";return this.logger.debug("โŒ Bundle transaction failed:",t),{success:!1,error:t}}formatErrorMessage(e){return"string"==typeof e?e:e?.response?.data?.error?e.response.data.error:e?.response?.data?.message?e.response.data.message:e?.message?e.message:"Unknown bundle transaction error"}async getBundlerTransactionResult(e){try{if(!e||"string"!=typeof e)throw Zt("transactionId","Transaction ID");this.logger.debug("๐Ÿ” Checking bundler transaction result:",e);const t=await this.httpClient.get(`${this.bundleEndpoint}?id=${e}`);return this.logger.debug("๐Ÿ“Š Bundler transaction result:",t),{success:!0,data:t}}catch(e){return this.logger.error("โŒ Failed to get bundler transaction result:",e),{success:!1,error:this.formatErrorMessage(e)}}}async cancelTransaction(e){try{if(!e||"string"!=typeof e)throw Zt("transactionId","Transaction ID");this.logger.debug("๐Ÿšซ Cancelling transaction:",e);const t=await this.httpClient.delete(`${this.bundleEndpoint}/${e}`);return this.logger.debug("๐Ÿ—‘๏ธ Transaction cancellation response:",t),{success:!0,data:t}}catch(e){return this.logger.error("โŒ Failed to cancel transaction:",e),{success:!1,error:this.formatErrorMessage(e)}}}async getHealthStatus(){try{this.logger.debug("๐Ÿฅ Checking bundle service health");const e=await this.httpClient.get(`${this.bundleEndpoint}/health`);return this.logger.debug("๐Ÿ’š Bundle service health:",e),{success:!0,data:e}}catch(e){return this.logger.error("โŒ Bundle service health check failed:",e),{success:!1,error:this.formatErrorMessage(e)}}}async buyToken(e){this.ensureTradingServicesAvailable();const{tokenName:t,amount:a,type:n,expectedAmount:r,maxAcceptableReverseBondingCurveFee:o,maxAcceptableReverseBondingCurveFeeSlippageFactor:s,slippageToleranceFactor:i}=e,c=i??this.defaultSlippageToleranceFactor,l=s??this.defaultMaxAcceptableReverseBondingCurveFeeSlippageFactor;let u=o||"0";o&&(u=za(o,l,"buy-exact"),this.logger.debug("Reverse bonding curve fee slippage applied:",{baseFee:o,slippageFactor:l,adjustedMaxFee:u}));const d=await this.resolveTokenNameToVault(t);if(!d)throw Yt(t);if("native"===n){if(!r)throw new v("expectedAmount is required for native buy operations. Use getBuyTokenAmount() first to calculate expected tokens.","expectedAmount","EXPECTED_AMOUNT_REQUIRED");const e=za(r,c,"buy-native");this.logger.debug("BuyNative slippage applied:",{originalExpectedTokens:r,slippageFactor:c,adjustedMinTokens:e});const t=new $a.BuyNativeDto(d,a,e,{maxAcceptableReverseBondingCurveFee:u});return await this.executeBundleTransaction(t,"BuyWithNative",d)}{if(!r)throw new v("expectedAmount is required for exact buy operations. Use getBuyTokenAmount() first to calculate expected GALA cost.","expectedAmount","EXPECTED_AMOUNT_REQUIRED");const e=za(r,c,"buy-exact");this.logger.debug("BuyExact slippage applied:",{originalExpectedGalaCost:r,slippageFactor:c,adjustedMaxGalaCost:e});const t=new $a.BuyExactDto(d,a,e,{maxAcceptableReverseBondingCurveFee:u});return await this.executeBundleTransaction(t,"BuyExactToken",d)}}async sellToken(e){this.ensureTradingServicesAvailable();const{tokenName:t,amount:a,type:n,expectedAmount:r,maxAcceptableReverseBondingCurveFee:o,maxAcceptableReverseBondingCurveFeeSlippageFactor:s,slippageToleranceFactor:i}=e,c=i??this.defaultSlippageToleranceFactor,l=s??this.defaultMaxAcceptableReverseBondingCurveFeeSlippageFactor;let u=o||"0";o&&(u=za(o,l,"buy-exact"),this.logger.debug("Reverse bonding curve fee slippage applied:",{baseFee:o,slippageFactor:l,adjustedMaxFee:u}));const d=await this.resolveTokenNameToVault(t);if(!d)throw Yt(t);if("exact"===n){if(!r)throw new v("expectedAmount is required for exact sell operations. Use getSellTokenAmount() first to calculate expected GALA.","expectedAmount","EXPECTED_AMOUNT_REQUIRED");const e=za(r,c,"sell-exact");this.logger.debug("SellExact slippage applied:",{originalExpectedGala:r,slippageFactor:c,adjustedMinGala:e});const t=new $a.SellExactDto(d,a,e,{maxAcceptableReverseBondingCurveFee:o||"0"});return await this.executeBundleTransaction(t,"SellExactToken",d)}{if(!r)throw new v("expectedAmount is required for native sell operations. Use getSellTokenAmount() first to calculate tokens to sell.","expectedAmount","EXPECTED_AMOUNT_REQUIRED");const e=za(r,c,"sell-native");this.logger.debug("SellNative slippage applied:",{originalExpectedTokensToSell:r,slippageFactor:c,adjustedMaxTokensToSell:e});const t=new $a.SellNativeDto(d,a,e,{maxAcceptableReverseBondingCurveFee:o||"0"});return await this.executeBundleTransaction(t,"SellWithNative",d)}}ensureTradingServicesAvailable(){if(!this.signatureService||!this.tokenKeyService)throw ta("Trading services not available. BundleService requires walletProvider and userAddress for trading operations.","walletProvider");if(!this.userAddress)throw Zt("userAddress","User address")}async executeBundleTransaction(e,t,a){this.ensureTradingServicesAvailable();try{e.uniqueKey=`galaswap - operation - ${i.v4()}-${Date.now()}-${this.userAddress}`;const n=await this.signatureService.signDTO(e,t,this.userAddress),r=this.tokenKeyService.generateStringsInstructions(a),o={stringsInstructions:r,method:t,signedDto:n};this.logger.debug("๐Ÿ“ฆ Bundle transaction data:",{method:t,stringsInstructions:r,dtoKeys:Object.keys(n)});const s=await this.submitTransaction(o);if(s.success&&s.data)return this.logger.debug("โœ… Bundle transaction submitted:",s.data),{success:!0,data:{transactionId:s.data,message:"Transaction submitted successfully. Monitor WebSocket for completion."}};throw new Error(s.error||"Bundle transaction failed")}catch(e){throw this.logger.error("โŒ Bundle transaction error:",e),e}}async resolveTokenNameToVault(e){return await this.tokenResolver.resolveTokenToVault(e)}}!function(e){e.PROCESSED="PROCESSED",e.COMPLETED="COMPLETED",e.SUCCESS="SUCCESS",e.FAILED="FAILED",e.ERROR="ERROR",e.PROCESSING="PROCESSING",e.PENDING="PENDING"}(Ma||(Ma={})),e.SDKTransactionStatus=void 0,(Ra=e.SDKTransactionStatus||(e.SDKTransactionStatus={})).PENDING="pending",Ra.PROCESSING="processing",Ra.COMPLETED="completed",Ra.FAILED="failed",Ra.TIMEOUT="timeout";const qa={[Ma.PROCESSED]:e.SDKTransactionStatus.COMPLETED,[Ma.COMPLETED]:e.SDKTransactionStatus.COMPLETED,[Ma.SUCCESS]:e.SDKTransactionStatus.COMPLETED,[Ma.FAILED]:e.SDKTransactionStatus.FAILED,[Ma.ERROR]:e.SDKTransactionStatus.FAILED,[Ma.PROCESSING]:e.SDKTransactionStatus.PROCESSING,[Ma.PENDING]:e.SDKTransactionStatus.PENDING};class ja{constructor(e,t=!1){this.socket=null,this.listeners=new Map,this.timeouts=new Map,this.reconnectCount=0,this.hasOnAnyListener=!1,this.config={reconnectAttempts:5,reconnectDelay:2e3,timeout:3e5,...e},this.debug=t,this.logger=new g({debug:t,context:"WebSocketService"}),this.isSocketIOAvailable=this.checkSocketIOAvailability()}checkSocketIOAvailability(){try{return"function"==typeof c.io||(this.logger.warn('โš ๏ธ Socket.IO client not available. Install "socket.io-client" package.'),!1)}catch(e){return this.logger.warn("โš ๏ธ Socket.IO availability check failed:",e),!1}}async connect(){return new Promise((e,t)=>{try{if(!this.isSocketIOAvailable){const e=new Error('Socket.IO not available in current environment. Install "socket.io-client" package.');return this.logger.error("โŒ Socket.IO connection failed:",e.message),void t(e)}this.logger.debug("๐Ÿ”Œ Connecting to Socket.IO server:",this.config.url),this.socket=c.io(this.config.url,{transports:["websocket"],reconnection:!0,reconnectionAttempts:this.config.reconnectAttempts||5,reconnectionDelay:this.config.reconnectDelay||2e3}),this.socket.on("connect",()=>{this.logger.debug("โœ… Socket.IO connected successfully:",this.socket?.id),this.logger.debug("๐Ÿ“ก Connected to bundle backend WebSocket:",this.config.url),this.logger.debug("๐Ÿ”— Ready to monitor transaction updates"),this.reconnectCount=0,e()}),this.socket.on("connect_error",e=>{this.logger.error("โŒ Socket.IO connection error:",e),t(e)}),this.socket.on("disconnect",e=>{this.logger.debug(`๐Ÿ”Œ Socket.IO disconnected: ${e}`),this.handleReconnect()}),this.socket.on("error",e=>{this.logger.error("โŒ Socket.IO error:",e)}),this.debug&&(this.socket.onAny((e,...t)=>{this.logger.debug(`๐Ÿ“ก [WebSocket Event] "${e}":`,JSON.stringify(t,null,2))}),this.hasOnAnyListener=!0)}catch(e){t(e)}})}async monitorTransaction(t,a){this.listeners.set(t,a),this.logger.debug(`๐Ÿ“ก Starting to monitor transaction: ${t}`),this.logger.debug(`๐Ÿ“ก WebSocket connected: ${!!this.socket&&this.socket.connected}`);const n=setTimeout(()=>{if(this.listeners.has(t)){const n={transactionId:t,status:e.SDKTransactionStatus.TIMEOUT,message:"Transaction monitoring timeout - no response after 60 seconds",timestamp:Date.now()};this.logger.debug(`๐Ÿ“ก Transaction timeout for ${t}`),a(n),this.listeners.delete(t),this.timeouts.delete(t),this.socket?.off(t)}},6e4);if(this.timeouts.set(t,n),this.socket&&this.socket.connected)this.socket.off(t),this.logger.debug(`๐Ÿ“ก Listening for transaction updates: ${t}`),this.logger.debug(`๐Ÿ“ก WebSocket connection ID: ${this.socket.id}`),this.logger.debug(`๐Ÿ“ก WebSocket URL: ${this.config.url}`),this.socket.on(t,n=>{this.logger.debug(`๐Ÿ“ก Socket.IO transaction update for ${t}:`,JSON.stringify(n,null,2));const r=n?.status||n?.Status||n?.data?.status||n?.data?.Status;let o=n?.message||n?.Message||n?.data?.message||n?.data?.Message||n?.error||n?.data?.error;o&&"string"==typeof o||(o=r===Ma.FAILED||r===Ma.ERROR?"Transaction failed - check transaction details":r===Ma.COMPLETED||r===Ma.PROCESSED||r===Ma.SUCCESS?"Transaction completed successfully":r?`Transaction status: ${r}`:"Unknown transaction status");const s={transactionId:t,status:this.mapSocketStatus(r),message:o,timestamp:Date.now(),blockHash:n?.blockHash||n?.data?.blockHash,gasUsed:n?.gasUsed||n?.data?.gasUsed};if(this.logger.debug(`๐Ÿ“ก Mapped status for ${t}: ${r} -> ${s.status}`),this.logger.debug(`๐Ÿ“ก Final message: "${o}"`),a(s),s.status===e.SDKTransactionStatus.COMPLETED||s.status===e.SDKTransactionStatus.FAILED){this.listeners.delete(t);const e=this.timeouts.get(t);e&&(clearTimeout(e),this.timeouts.delete(t)),this.socket?.off(t),this.logger.debug(`๐Ÿ“ก Cleaned up listener for ${t} (${s.status})`)}});else{const n={transactionId:t,status:e.SDKTransactionStatus.FAILED,message:"WebSocket not connected - cannot monitor transaction",timestamp:Date.now()};a(n),this.listeners.delete(t),this.timeouts.delete(t)}}async waitForTransaction(t){return new Promise((a,n)=>{this.monitorTransaction(t,t=>{t.status===e.SDKTransactionStatus.COMPLETED?a(t):t.status!==e.SDKTransactionStatus.FAILED&&t.status!==e.SDKTransactionStatus.TIMEOUT||n(new Error(`Transaction ${t.status}: ${t.message}`))})})}mapSocketStatus(t){const a=t?.toUpperCase();return qa[a]||e.SDKTransactionStatus.PENDING}async handleReconnect(){this.reconnectCount<this.config.reconnectAttempts?(this.reconnectCount++,this.logger.debug(`๐Ÿ”„ Attempting Socket.IO reconnect ${this.reconnectCount}/${this.config.reconnectAttempts}`),setTimeout(()=>{this.socket&&!this.socket.connected&&this.socket.connect()},this.config.reconnectDelay)):this.logger.error("โŒ Socket.IO max reconnection attempts reached")}disconnect(){this.socket&&(this.listeners.forEach((e,t)=>{this.socket?.off(t)}),this.listeners.clear(),this.timeouts.forEach(e=>{clearTimeout(e)}),this.timeouts.clear(),this.hasOnAnyListener&&(this.socket.offAny(),this.hasOnAnyListener=!1,this.logger.debug("๐Ÿงน Removed onAny debug listener")),this.socket.disconnect(),this.socket=null,this.logger.debug("๐Ÿ”Œ Socket.IO disconnected"))}isConnected(){return this.socket?.connected||!1}}class Wa{constructor(e){this.poolService=e,this.cache=new Map}async resolveTokenToVault(e){if(!E(e))throw new v("Token name is required and must be a non-empty string","tokenName","INVALID_TOKEN_NAME");const t=e.trim().toLowerCase(),a=this.get(t);if(a)return a;try{const a=await this.poolService.resolveTokenNameToVault(e);return a&&this.set(t,a),a}catch{return null}}async resolveTokenClassKey(e){const t=await this.resolveTokenToVault(e);if(!t)throw Yt(e);return this.parseVaultAddressToTokenClassKey(t)}get(e){return this.cache.get(e.toLowerCase())||null}set(e,t){this.cache.set(e.toLowerCase(),t)}clear(){this.cache.clear()}getStats(){return{size:this.cache.size,keys:Array.from(this.cache.keys())}}preWarm(e){for(const{tokenName:t,vaultAddress:a}of e)this.set(t,a)}parseVaultAddressToTokenClassKey(e){const t=e.split("|");if(2!==t.length)throw Jt("vaultAddress","format: service|Token$Unit$...$launchpad","Vault address");const a=t[1].split("$");if(a.length<4)throw Jt("vaultAddress","at least 4 parts after service|","Vault address");return{collection:a[0],category:a[1],type:a[2],additionalKey:a[3]}}}class Ha{}Ha.BASE_PRICE=1650667151e-14,Ha.PRICE_SCALING_FACTOR=1166069e-12,Ha.TRADING_FEE_FACTOR=.001,Ha.GAS_FEE="1",Ha.MIN_UNBONDING_FEE_FACTOR=0,Ha.MAX_UNBONDING_FEE_FACTOR=.5,Ha.NET_UNBONDING_FEE_FACTOR=.5,Ha.DEFAULT_LAUNCHPAD_TOKEN_MAX_SUPPLY=1e7;class Qa{constructor(){this.cache=new Map}getLRUKey(){const e=this.cache.keys().next().value;return void 0!==e?e:null}normalizeTokenName(e){return e.trim().toLowerCase().replace(/\s+/g," ").replace(/[\u0000-\u001F\u007F-\u009F\u200B-\u200D\uFEFF]/g,"")}warmFromPoolData(e,t){const a=this.normalizeTokenName(e),n=this.cache.get(a);if(this.cache.has(a)&&this.cache.delete(a),this.cache.size>=Qa.MAX_CACHE_SIZE){const e=this.getLRUKey();null!==e&&this.cache.delete(e)}this.cache.set(a,{...n,...t,lastUpdated:Date.now()})}set(e,t){const a=this.normalizeTokenName(e),n=this.cache.get(a);if(this.cache.has(a)&&this.cache.delete(a),this.cache.size>=Qa.MAX_CACHE_SIZE){const e=this.getLRUKey();null!==e&&this.cache.delete(e)}this.cache.set(a,{...n,...t,lastUpdated:Date.now()})}get(e){const t=this.normalizeTokenName(e);return this.cache.get(t)||null}getMaxSupply(e){const t=this.normalizeTokenName(e),a=this.cache.get(t);return a?.maxSupply||Ha.DEFAULT_LAUNCHPAD_TOKEN_MAX_SUPPLY.toString()}has(e){const t=this.normalizeTokenName(e);return this.cache.has(t)}clear(e){if(e){const t=this.normalizeTokenName(e);this.cache.delete(t)}else this.cache.clear()}dump(){const e={};return this.cache.forEach((t,a)=>{e[a]=t}),e}stats(){let e=Date.now(),t=0;return this.cache.forEach((a,n)=>{a.lastUpdated<e&&(e=a.lastUpdated);let r=0;r+=2*n.length,void 0!==a.reverseBondingCurveMinFeeFactor&&(r+=8),void 0!==a.reverseBondingCurveMaxFeeFactor&&(r+=8),void 0!==a.reverseBondingCurveNetFeeFactor&&(r+=8),r+=8,a.vaultAddress&&(r+=2*a.vaultAddress.length),a.maxSupply&&(r+=2*a.maxSupply.length),r+=32,t+=r}),{totalTokens:this.cache.size,cacheSize:t,oldestEntry:this.cache.size>0?e:0}}}function Xa(e){const t=function(e){const t=st(e);return t.success?[]:t.errors||["Unknown validation error"]}(e);if(t.length>0)throw new Error(`LaunchTokenData validation failed:\n${t.map(e=>`- ${e}`).join("\n")}`)}Qa.MAX_CACHE_SIZE=1e4;const Ya="/api/asset/launchpad-contract/CallNativeTokenIn",Za="/api/asset/launchpad-contract/CallNativeTokenOut",Ja="/api/asset/launchpad-contract/CallMemeTokenIn",en="/api/asset/launchpad-contract/CallMemeTokenOut";class tn extends n.ChainCallDTO{constructor(e){super(),this.tokenName=e.tokenName,this.tokenSymbol=e.tokenSymbol,this.tokenDescription=e.tokenDescription,this.tokenImage=e.tokenImage,this.preBuyQuantity=e.preBuyQuantity,this.websiteUrl=e.websiteUrl,this.telegramUrl=e.telegramUrl,this.twitterUrl=e.twitterUrl,this.tokenCategory=e.tokenCategory,this.tokenCollection=e.tokenCollection,this.uniqueKey=e.uniqueKey,e.reverseBondingCurveConfiguration&&(this.reverseBondingCurveConfiguration=e.reverseBondingCurveConfiguration)}}function an(e){return e&&"object"==typeof e&&"number"==typeof e.Status&&e.Data&&"object"==typeof e.Data&&"string"==typeof e.Data.calculatedQuantity&&e.Data.extraFees&&"object"==typeof e.Data.extraFees&&"string"==typeof e.Data.extraFees.reverseBondingCurve&&"string"==typeof e.Data.extraFees.transactionFees}const nn={NATIVE:"native",EXACT:"exact"},rn={LOCAL:"local",EXTERNAL:"external"};class on{static calculateBuyWithExact(e,t){const a=parseFloat(e),n=parseFloat(t),{BASE_PRICE:r,PRICE_SCALING_FACTOR:o,TRADING_FEE_FACTOR:i,GAS_FEE:c}=Ha,l=this.roundUp(r*(Math.exp((n+a)*o)-Math.exp(n*o))/o,8),u=new s(l).multipliedBy(i).toFixed();return{amount:l.toString(),reverseBondingCurveFee:"0",transactionFee:u,gasFee:c}}static calculateBuyWithNative(e,t){const a=parseFloat(e),n=parseFloat(t),{BASE_PRICE:r,PRICE_SCALING_FACTOR:o,TRADING_FEE_FACTOR:i,GAS_FEE:c}=Ha,l=Math.log(a*o/r+Math.exp(n*o))/o-n,u=new s(l).multipliedBy(i).toFixed();return{amount:l.toString(),reverseBondingCurveFee:"0",transactionFee:u,gasFee:c}}static calculateSellWithExact(e,t,a,n,r){const o=parseFloat(e),i=parseFloat(t),c=parseFloat(a),{BASE_PRICE:l,PRICE_SCALING_FACTOR:u,TRADING_FEE_FACTOR:d,GAS_FEE:h}=Ha,g=l*(Math.exp(i*u)-Math.exp((i-o)*u))/u,m=new s(g),p=n+i/c*(r-n),f=m.multipliedBy(p).toFixed(8,s.ROUND_UP),y=m.multipliedBy(d).toFixed();return{amount:g.toString(),reverseBondingCurveFee:f,transactionFee:y,gasFee:h}}static calculateSellWithNative(e,t,a,n,r){const o=parseFloat(e),i=parseFloat(t),c=parseFloat(a),{BASE_PRICE:l,PRICE_SCALING_FACTOR:u,TRADING_FEE_FACTOR:d,GAS_FEE:h}=Ha,g=i-Math.log(Math.exp(i*u)-o*u/l)/u,m=new s(o),p=n+i/c*(r-n),f=m.multipliedBy(p).toFixed(8,s.ROUND_UP),y=m.multipliedBy(d).toFixed();return{amount:g.toString(),reverseBondingCurveFee:f,transactionFee:y,gasFee:h}}static roundUp(e,t){const a=Math.pow(10,t);return Math.ceil(e*a)/a}}class sn{constructor(e,t,a,n,r,o,s="local"){this.http=e,this.tokenResolver=t,this.logger=a,this.bundleHttp=n,this.galaChainHttp=r,this.dexApiHttp=o,this.defaultCalculateAmountMode=s,this.metadataCache=new Qa}addIfDefined(e,t,a){return void 0!==a&&(e[t]=a),e}async uploadImageByTokenName(e){const{tokenName:t,options:a}=e;St(t);const n=`${t}.png`;ya(a.file,n,"image/png");try{const e=new FormData;if("undefined"!=typeof File&&a.file instanceof File)e.append("image",a.file);else{if(!Buffer.isBuffer(a.file))throw Jt("file","a File object (browser) or Buffer (Node.js)");{const n=`${a.tokenName||t}.png`,r=new Blob([a.file],{type:"image/png"});e.append("image",r,n)}}const n=await this.http.request({method:"POST",url:`/launchpad/upload-image?tokenName=${encodeURIComponent(a.tokenName||t)}`,data:e,headers:{}});if(!0===n.error||200!==n.status||!n.data?.imageUrl)throw ea(n.message||"Image upload failed - no URL returned",n.status);return n.data.imageUrl}catch(e){if(e instanceof Error&&e.message.includes("FormData"))throw ta("File upload failed: FormData not supported in this environment. Ensure you have proper polyfills for Node.js environments.","FormData");throw e}}async fetchPoolsFromAPI(e){bt(e),e.tokenName&&St(e.tokenName);const t={page:e.page.toString(),limit:e.limit.toString()};void 0!==e.type&&(t.type=e.type),void 0!==e.tokenName&&(t.tokenName=e.tokenName),void 0!==e.search&&(t.search=e.search);const a=m(t),n=await this.http.get("/launchpad/fetch-pool",a);if(!0===n.error||200!==n.status||!n.data)throw ea(n.message||"Failed to fetch pools",n.status);let r=[];const o=(await import("bignumber.js")).default;if(n.data.tokens)if(Array.isArray(n.data.tokens))r=n.data.tokens.map(e=>{const t=e.reverseBondingCurveMinFeePortion??"0",a=e.reverseBondingCurveMaxFeePortion??"0",n=!new o(t).isZero()||!new o(a).isZero();return{...e,reverseBondingCurveMinFeePortion:t,reverseBondingCurveMaxFeePortion:a,hasReverseBondingCurveFee:n,createdAt:new Date(e.created_at||e.createdAt)}});else{const e=n.data.tokens.reverseBondingCurveMinFeePortion??"0",t=n.data.tokens.reverseBondingCurveMaxFeePortion??"0",a=!new o(e).isZero()||!new o(t).isZero();r=[{...n.data.tokens,reverseBondingCurveMinFeePortion:e,reverseBondingCurveMaxFeePortion:t,hasReverseBondingCurveFee:a,createdAt:new Date(n.data.tokens.created_at||n.data.tokens.createdAt)}]}else n.data.pools&&Array.isArray(n.data.pools)&&(r=n.data.pools.map(e=>{const t=e.reverseBondingCurveMinFeePortion??"0",a=e.reverseBondingCurveMaxFeePortion??"0",n=!new o(t).isZero()||!new o(a).isZero();return{...e,reverseBondingCurveMinFeePortion:t,reverseBondingCurveMaxFeePortion:a,hasReverseBondingCurveFee:n,createdAt:new Date(e.created_at||e.createdAt)}}));const{extractMetadataFromPoolData:s,isValidPoolForCaching:i}=await Promise.resolve().then(function(){return yn});r.forEach(e=>{if(!i(e))return void this.logger.debug("Skipping pool with invalid structure for caching",e);const t=s(e,this.logger);t&&this.warmCacheFromPoolData(e.tokenName,t)});const c=n.data.count??n.data.total??0,l=n.data.page??e.page??1,u=n.data.limit??e.limit??10,d=u>0?Math.ceil(c/u):1;return{pools:r,page:l,limit:u,total:c,totalPages:d,hasNext:l<d,hasPrevious:l>1}}async _getAmount(e){if(Ft(e),!this.galaChainHttp)throw ta("GalaChain client not configured. Direct GalaChain calls require galaChainHttp client.","galaChainHttp");const{endpoint:t,body:a}=((e,t,a,n)=>{if("NATIVE"===e&&"IN"===t)return{endpoint:Ya,body:{vaultAddress:a,tokenQuantity:n,IsPreMint:!1}};if("NATIVE"===e&&"OUT"===t)return{endpoint:Za,body:{vaultAddress:a,tokenQuantity:n,IsPreMint:!1}};if("MEME"===e&&"IN"===t)return{endpoint:Ja,body:{vaultAddress:a,nativeTokenQuantity:n,IsPreMint:!1}};if("MEME"===e&&"OUT"===t)return{endpoint:en,body:{vaultAddress:a,nativeTokenQuantity:n,IsPreMint:!1}};throw Jt("type-method","one of: NATIVE-IN, NATIVE-OUT, MEME-IN, MEME-OUT")})(e.type,e.method,e.vaultAddress,e.amount);try{const e=await this.galaChainHttp.post(t,a);if(!an(e))throw ea("Malformed response data from GalaChain gateway");if(1!==e.Status)throw ea(`GalaChain calculation failed with status ${e.Status}`,e.Status);const{calculatedQuantity:n,extraFees:r}=e.Data;return{amount:n,reverseBondingCurveFee:r.reverseBondingCurve,transactionFee:r.transactionFees,gasFee:"1"}}catch(n){throw this.logger.error(`GalaChain ${e.type}-${e.method} operation failed:`,{endpoint:t,requestBody:a,error:n instanceof Error?n.message:n}),n}}async checkPool(e){It(e),e.tokenName&&St(e.tokenName);const t=m(e),a=await this.http.get("/launchpad/check-pool",t);if(!0===a.error||200!==a.status)throw ea(a.message||"Failed to check pool",a.status);const n=a.data;return e.symbol?n?.isSymbolExist??!1:e.tokenName?n?.isNameExist??!1:n?.exists??!1}async fetchVolumeData(e){if(!na(e))throw new v("Invalid options provided. Expected { tokenName: string, from?: number, to?: number, resolution?: number }","options","INVALID_OPTIONS");const{tokenName:t,from:a,to:n,resolution:r}=e;if(St(t),!a||!n||!r)throw new v("Graph options (from, to, resolution) are required","options","MISSING_GRAPH_OPTIONS");const o={tokenName:t,from:a,to:n,resolution:r};Ct(o);const s=m(o),i=await this.http.get("/launchpad/get-graph-data",s);if(!0===i.error||200!==i.status||!i.data)throw ea(i.message||"Failed to fetch graph data",i.status);return{dataPoints:i.data}}async fetchPools(e={}){let t;"recent"===e.type?t="RECENT":"popular"===e.type&&(t="POPULAR");const a={page:e.page||1,limit:e.limit||10};return e.search&&(a.search=e.search),e.tokenName&&(a.tokenName=e.tokenName),t&&(a.type=t),this.fetchPoolsFromAPI(a)}async isTokenNameAvailable(e){try{return!await this.checkPool({tokenName:e})}catch{return!1}}async isTokenSymbolAvailable(e){try{return!await this.checkPool({symbol:e})}catch{return!1}}async calculateBuyAmount(e){if(!e||"object"!=typeof e)throw new v("Invalid options provided. Expected an options object.","options","INVALID_OPTIONS");const{tokenName:t,amount:a,type:n,currentSupply:r}=e,o=e.mode??this.defaultCalculateAmountMode;if("local"!==o&&"external"!==o)throw new v(`Invalid calculation mode "${o}". Must be "local" or "external".`,"mode","INVALID_CALCULATION_MODE");if(!t||"string"!=typeof t)throw new v("Token name is required and must be a string","tokenName","INVALID_TOKEN_NAME");if(!a||"string"!=typeof a)throw new v("Amount is required and must be a string","amount","INVALID_AMOUNT");if(n!==nn.NATIVE&&n!==nn.EXACT)throw new v('Type must be either "native" or "exact"',"type","INVALID_TYPE");return"external"===o?this.calculateBuyAmountExternal({tokenName:t,amount:a,type:n}):this.calculateBuyAmountLocal(this.addIfDefined({tokenName:t,amount:a,type:n},"currentSupply",r))}async calculateBuyAmountExternal(e){const{tokenName:t,amount:a,type:n}=e,r=await this.tokenResolver.resolveTokenToVault(t);if(!r)throw new v(`Token "${t}" not found. Please verify the token name is correct.`,"tokenName","TOKEN_NOT_FOUND");return n===nn.EXACT?this._getAmount({type:"NATIVE",method:"IN",vaultAddress:r,amount:a}):this._getAmount({type:"MEME",method:"OUT",vaultAddress:r,amount:a})}async calculateSellAmount(e){const{tokenName:t,amount:a,type:n,currentSupply:r,maxSupply:o,reverseBondingCurveMaxFeeFactor:s,reverseBondingCurveMinFeeFactor:i}=e,c=e.mode??this.defaultCalculateAmountMode;if("local"!==c&&"external"!==c)throw new v(`Invalid calculation mode "${c}". Must be "local" or "external".`,"mode","INVALID_CALCULATION_MODE");if(!t||"string"!=typeof t)throw new v("Token name is required and must be a string","tokenName","INVALID_TOKEN_NAME");if(!a||"string"!=typeof a)throw new v("Amount is required and must be a string","amount","INVALID_AMOUNT");if(n!==nn.EXACT&&n!==nn.NATIVE)throw new v('Type must be either "exact" or "native"',"type","INVALID_TYPE");if("external"===c)return this.calculateSellAmountExternal({tokenName:t,amount:a,type:n});{let e={tokenName:t,amount:a,type:n};return e=this.addIfDefined(e,"currentSupply",r),e=this.addIfDefined(e,"maxSupply",o),e=this.addIfDefined(e,"reverseBondingCurveMaxFeeFactor",s),e=this.addIfDefined(e,"reverseBondingCurveMinFeeFactor",i),this.calculateSellAmountLocal(e)}}async calculateSellAmountExternal(e){const{tokenName:t,amount:a,type:n}=e,r=await this.tokenResolver.resolveTokenToVault(t);if(!r)throw new v(`Token "${t}" not found. Please verify the token name is correct.`,"tokenName","TOKEN_NOT_FOUND");return n===nn.EXACT?this._getAmount({type:"NATIVE",method:"OUT",vaultAddress:r,amount:a}):this._getAmount({type:"MEME",method:"IN",vaultAddress:r,amount:a})}async calculateBuyAmountLocal(e){const{tokenName:t,amount:a,type:n,currentSupply:r}=e;if(!a||"string"!=typeof a)throw new v("Amount is required and must be a string","amount","INVALID_AMOUNT");if(n!==nn.NATIVE&&n!==nn.EXACT)throw new v('Type must be either "native" or "exact"',"type","INVALID_TYPE");void 0!==r&&Pt(r,"currentSupply");const o=!r;if(o&&!t)throw new v("Token name is required when currentSupply is not provided","tokenName","MISSING_TOKEN_NAME");t&&St(t);let s=r;if(o){s=(await this.fetchPoolDetailsForCalculation(t)).currentSupply}return n===nn.EXACT?on.calculateBuyWithExact(a,s):on.calculateBuyWithNative(a,s)}async calculateSellAmountLocal(e){const{tokenName:t,amount:a,type:n,currentSupply:r,maxSupply:o,reverseBondingCurveMaxFeeFactor:s,reverseBondingCurveMinFeeFactor:i}=e;if(!a||"string"!=typeof a)throw new v("Amount is required and must be a string","amount","INVALID_AMOUNT");if(n!==nn.EXACT&&n!==nn.NATIVE)throw new v('Type must be either "exact" or "native"',"type","INVALID_TYPE");void 0!==r&&Pt(r,"currentSupply");const c=!r||!o||void 0===s||void 0===i;if(c&&!t)throw new v("Token name is required when currentSupply, maxSupply, or fee factors are not provided","tokenName","MISSING_TOKEN_NAME");t&&St(t);let l=r,u=o,d=s,h=i;if(c&&t){const e=this.metadataCache.get(t);u=u??this.metadataCache.getMaxSupply(t),d=d??e?.reverseBondingCurveMaxFeeFactor,h=h??e?.reverseBondingCurveMinFeeFactor,l||(l=await this.fetchCurrentSupply(t));if(void 0===d||void 0===h){const e=await this.fetchPoolDetailsForCalculation(t);d=d??e.reverseBondingCurveMaxFeeFactor,h=h??e.reverseBondingCurveMinFeeFactor}}return n===nn.EXACT?on.calculateSellWithExact(a,l,u,h,d):on.calculateSellWithNative(a,l,u,h,d)}async calculateBuyAmountForGraduation(e){const t="string"==typeof e?{tokenName:e}:e;if("object"==typeof e&&(!(a=e)||"object"!=typeof a||"string"!=typeof a.tokenName||void 0!==a.calculateAmountMode&&"local"!==a.calculateAmountMode&&"external"!==a.calculateAmountMode||void 0!==a.currentSupply&&"string"!=typeof a.currentSupply))throw new Error("Invalid CalculateBuyAmountForGraduationOptions provided");var a;const{tokenName:n,calculateAmountMode:r,currentSupply:o}=t;St(n);const s=await this.tokenResolver.resolveTokenToVault(n);if(!s)throw new v(y(n),"tokenName","VAULT_NOT_FOUND");if(!this.galaChainHttp)throw ta("GalaChain HTTP client not configured");const i=await this.galaChainHttp.post("/api/asset/launchpad-contract/FetchSaleDetails",{vaultAddress:s});if(1!==i.Status)throw ea(`Failed to fetch pool details: Status ${i.Status}`,i.Status);const c=i.Data,l=(await import("bignumber.js")).default,u=o??new l(c.maxSupply).minus(c.sellingTokenQuantity).toFixed(),d=c.sellingTokenQuantity;if("0"===d)throw new v(`Token ${n} is already graduated (no tokens remaining in pool)`,"tokenName","ALREADY_GRADUATED");const h={tokenName:n,amount:d,type:"exact",currentSupply:u};return void 0!==r&&(h.mode=r),await this.calculateBuyAmount(h)}async launchToken(e){if(!this.bundleHttp)throw ta("Bundle backend client not configured. LaunchToken requires bundleHttp client.","bundleHttp");Xa(e);const t=e.preBuyQuantity||"0";if(isNaN(Number(t))||Number(t)<0)throw new v("Pre-buy quantity must be a valid non-negative number string","preBuyQuantity","INVALID_PRE_BUY_QUANTITY");if(e.reverseBondingCurveConfiguration){const{minFeePortion:t,maxFeePortion:a}=e.reverseBondingCurveConfiguration,n=Number(t),r=Number(a);if(isNaN(n)||isNaN(r)||n<=0||r<=0||n>=r)throw new v("Reverse bonding curve configuration must have valid min/max fee portions with min < max","reverseBondingCurveConfiguration","INVALID_BONDING_CURVE_CONFIG")}let a="";if(e.tokenImage)if(e.tokenImage instanceof File||Buffer.isBuffer(e.tokenImage)){const t=await this.uploadImageByTokenName({tokenName:e.tokenName,options:{file:e.tokenImage,tokenName:e.tokenName}});if(!t)throw ea("Image upload failed: No URL returned");a=t}else"string"==typeof e.tokenImage&&(a=e.tokenImage);const r=`galaswap - operation - ${i.v4()}-${Date.now()}-${this.http.getAddress()}`,o={tokenName:e.tokenName.trim(),tokenSymbol:e.tokenSymbol.trim().toUpperCase(),tokenDescription:e.tokenDescription.trim(),tokenImage:a.trim(),preBuyQuantity:t.toString(),websiteUrl:e.websiteUrl||"",telegramUrl:e.telegramUrl||"",twitterUrl:e.twitterUrl||"",tokenCategory:e.tokenCategory||"Unit",tokenCollection:e.tokenCollection||"Token",uniqueKey:r};e.reverseBondingCurveConfiguration&&(o.reverseBondingCurveConfiguration={minFeePortion:e.reverseBondingCurveConfiguration.minFeePortion.toString(),maxFeePortion:e.reverseBondingCurveConfiguration.maxFeePortion.toString()});const s=new tn(o),c=await this.http.signWithGalaChain("CreateSale",s,n.SigningType.SIGN_TYPED_DATA),{signature:l,types:u,domain:d,prefix:h}=c,g={tokenName:s.tokenName,tokenSymbol:s.tokenSymbol,tokenDescription:s.tokenDescription,tokenImage:s.tokenImage,preBuyQuantity:s.preBuyQuantity,websiteUrl:s.websiteUrl,telegramUrl:s.telegramUrl,twitterUrl:s.twitterUrl,tokenCategory:s.tokenCategory,tokenCollection:s.tokenCollection,uniqueKey:s.uniqueKey,signature:l,types:u,domain:d,...h&&{prefix:h},...s.reverseBondingCurveConfiguration&&{reverseBondingCurveConfiguration:s.reverseBondingCurveConfiguration}},m=`${e.tokenName.trim()}$Unit$none$none`,p="GALA$Unit$none$none";let f;if(parseFloat(t)>0){const e=`$service$${m}$launchpad`;f=[e,`$token$${m}$${e}`,`$tokenBalance$${m}$${e}`,`$tokenBalance$${m}$${e}`,`$tokenBalance$${p}$${e}`,`$tokenBalance$${p}$${e}`]}else{const e=`$service$${m}$launchpad`;f=[e,`$token$${m}$${e}`,`$tokenBalance$${m}$${e}`]}const y={signedDto:g,stringsInstructions:f,method:"CreateSale"},A=await this.bundleHttp.post("/bundle",y);if(A.error||!A.data)throw ea(A.message||"Token launch failed");return A.data}async fetchTokenDistribution(e){if(!e)throw Zt("tokenName","Token name");St(e);const t=await this.tokenResolver.resolveTokenToVault(e);if(!t)throw new v(y(e),"tokenName","VAULT_NOT_FOUND");this.metadataCache.set(e,{vaultAddress:t});const a=encodeURIComponent(t),n=await this.http.get(`/holders/${a}`);if(!0===n.error||200!==n.status||!n.data)throw ea(n.message||"Failed to fetch token distribution",n.status);return{holders:n.data.holders||[],totalSupply:n.data.totalSupply||"0",totalHolders:n.data.totalHolders||0,lastUpdated:new Date}}async fetchTokenBadges(e){if(!e)throw Zt("tokenName","Token name");St(e);const t=await this.http.get("/launchpad/get-badge/",{tokenName:e});if(t.error||!t.data)throw ea(t.message||"Failed to fetch token badges");return{volumeBadges:t.data.volumeBadge||[],engagementBadges:t.data.engagementBadge||[]}}async hasTokenBadgeByTokenName(e){const{tokenName:t,badgeType:a,badgeName:n}=e;try{const e=await this.fetchTokenBadges(t);if(!e)return!1;const r=("volume"===a?e.volumeBadges:e.engagementBadges).find(e=>e.badgeName===n);return r?.isActive||!1}catch{return!1}}async calculateInitialBuyAmount(e){if(!(t=e)||"object"!=typeof t||"string"!=typeof t.nativeTokenQuantity||void 0!==t.vaultAddress&&"string"!=typeof t.vaultAddress)throw new v("Invalid pre-mint calculation data","data","INVALID_PRE_MINT_DATA");var t;if(!this.galaChainHttp)throw ta("GalaChain HTTP client not available. Please initialize SDK with galaChainBaseUrl.","galaChainHttp");try{const t={vaultAddress:"service|testToken",nativeTokenQuantity:e.nativeTokenQuantity,IsPreMint:!0},a=await this.galaChainHttp.post("/api/asset/launchpad-contract/CallMemeTokenOut",t);if(!an(a))throw ea("Malformed response data from GalaChain gateway");if(1!==a.Status)throw ea(`GalaChain calculation failed with status ${a.Status}`,a.Status);const{calculatedQuantity:n,extraFees:r}=a.Data;return{amount:n,reverseBondingCurveFee:r.reverseBondingCurve,transactionFee:r.transactionFees,gasFee:"1"}}catch(e){if(e instanceof Error){const t=new Error(`Pre-mint calculation failed: ${e.message}`);throw e.stack&&(t.stack=e.stack),t}throw new Error(`Pre-mint calculation failed: ${String(e)}`)}}async fetchPoolDetailsForCalculation(e){const t=await this.tokenResolver.resolveTokenToVault(e);if(!t)throw new v(y(e),"tokenName","VAULT_NOT_FOUND");if(!this.galaChainHttp)throw ta("GalaChain HTTP client not configured");const a=await this.galaChainHttp.post("/api/asset/launchpad-contract/FetchSaleDetails",{vaultAddress:t});if(1!==a.Status)throw ea(`Failed to fetch pool details: Status ${a.Status}`,a.Status);const n=a.Data,r=new(0,(await import("bignumber.js")).default)(n.maxSupply).minus(n.sellingTokenQuantity).toFixed(),o=n.sellingTokenQuantity,s=n.maxSupply;let i=.5,c=0;n.reverseBondingCurveConfiguration?(i=parseFloat(n.reverseBondingCurveConfiguration.maxFeePortion),c=parseFloat(n.reverseBondingCurveConfiguration.minFeePortion)):this.logger.debug(`Pool details missing reverseBondingCurveConfiguration for token ${e}, using defaults (min: 0.0, max: 0.5)`);const l=i-c;return this.metadataCache.set(e,{maxSupply:s,reverseBondingCurveMaxFeeFactor:i,reverseBondingCurveMinFeeFactor:c,reverseBondingCurveNetFeeFactor:l}),{currentSupply:r,remainingTokens:o,maxSupply:s,reverseBondingCurveMaxFeeFactor:i,reverseBondingCurveMinFeeFactor:c,reverseBondingCurveNetFeeFactor:l}}async fetchCurrentSupply(e){St(e);const t=await this.tokenResolver.resolveTokenToVault(e);if(!t)throw new v(y(e),"tokenName","VAULT_NOT_FOUND");if(!this.galaChainHttp)throw ta("GalaChain HTTP client not configured");const a=await this.galaChainHttp.post("/api/asset/launchpad-contract/FetchSaleDetails",{vaultAddress:t});if(1!==a.Status)throw ea(`Failed to fetch pool details: Status ${a.Status}`,a.Status);const n=a.Data,r=new(0,(await import("bignumber.js")).default)(n.maxSupply).minus(n.sellingTokenQuantity).toFixed(),o=n.maxSupply;return this.metadataCache.set(e,{maxSupply:o}),r}getAddress(){return this.http.getAddress()}formatAddressForBackend(e){return Dt(e)}validateTokenName(e){return St(e)}validatePagination(e){return bt(e)}async fetchTokenSpotPrice(e){if(!this.dexApiHttp)throw ta("DEX API client not configured. Token price fetching requires dexApiHttp client.","dexApiHttp");if(!e||Array.isArray(e)&&0===e.length)throw Zt("symbols","At least one symbol");const t=Array.isArray(e)?e.join(","):e;try{const e=await this.dexApiHttp.request({method:"GET",url:"/v1/tokens",params:{symbols:t}}),a=[];return e.tokens&&Array.isArray(e.tokens)&&e.tokens.forEach(e=>{e.currentPrices&&e.symbol&&a.push({symbol:e.symbol,price:e.currentPrices.usd})}),a}catch(e){throw ea(`Failed to fetch token prices: ${e instanceof Error?e.message:e}`,void 0,e instanceof Error?e:void 0)}}async fetchLaunchpadTokenSpotPrice(e){const t="string"==typeof e?{tokenName:e}:e;if("object"==typeof e&&(!(a=e)||"object"!=typeof a||"string"!=typeof a.tokenName||void 0!==a.calculateAmountMode&&"local"!==a.calculateAmountMode&&"external"!==a.calculateAmountMode||void 0!==a.currentSupply&&"string"!=typeof a.currentSupply))throw new Error("Invalid FetchLaunchpadTokenSpotPriceOptions provided");var a;const{tokenName:n,calculateAmountMode:r,currentSupply:o}=t;if(!n||"string"!=typeof n)throw Zt("tokenName","Token name (string)");try{const e={tokenName:n,amount:"1",type:"native"};void 0!==r&&(e.mode=r),void 0!==o&&(e.currentSupply=o);const t=await this.calculateBuyAmount(e),a=(await this.fetchTokenSpotPrice("GALA"))[0];if(!a)throw ea("GALA price not available");const s=Number(t.amount);if(s<=0)throw new v(`Invalid token amount calculation: ${s}`,"amount","INVALID_CALCULATION");const i=a.price/s;return{symbol:n.toUpperCase(),price:i}}catch(e){if(e instanceof Error)throw new Error(`Failed to calculate launchpad token spot price for ${n}: ${e.message}`);throw new Error(`Failed to calculate launchpad token spot price for ${n}: ${String(e)}`)}}warmCacheFromPoolData(e,t){this.metadataCache.warmFromPoolData(e,t)}getCacheStats(){return this.metadataCache.stats()}clearCache(e){this.metadataCache.clear(e)}}const cn={PROD:{launchpadBaseUrl:"https://lpad-backend-prod1.defi.gala.com",galaChainBaseUrl:"https://gateway-mainnet.galachain.com",bundleBaseUrl:"https://bundle-backend-prod1.defi.gala.com",webSocketUrl:"https://bundle-backend-prod1.defi.gala.com",dexApiBaseUrl:"https://dex-api-platform-dex-prod-gala.gala.com",launchpadFrontendUrl:"https://lpad-frontend-prod1.defi.gala.com"},STAGE:{launchpadBaseUrl:"https://lpad-backend-dev1.defi.gala.com",galaChainBaseUrl:"https://galachain-gateway-chain-platform-stage-chain-platform-eks.stage.galachain.com",bundleBaseUrl:"https://bundle-backend-dev1.defi.gala.com",webSocketUrl:"https://bundle-backend-dev1.defi.gala.com",dexApiBaseUrl:"https://dex-api-platform-dex-stage-gala.gala.com",launchpadFrontendUrl:"https://lpad-frontend-dev1.defi.gala.com"}};function ln(e){return cn[e]}class un extends Error{constructor(e,t){super(e),this.cause=t,this.name="WebSocketError"}}class dn extends Error{constructor(e,t,a){super(`Transaction ${e} failed with status: ${t}${a?` - ${a}`:""}`),this.transactionId=e,this.status=t,this.name="TransactionFailedError"}}function hn(e,t){if(!e)throw new un(`Invalid WebSocket response received for transaction ${t}: response is null or undefined`);if("object"!=typeof e)throw new un(`Invalid WebSocket response received for transaction ${t}: expected object, got ${typeof e}`);if(!Object.prototype.hasOwnProperty.call(e,"status")&&!Object.prototype.hasOwnProperty.call(e,"Status"))throw new un(`Invalid WebSocket response received for transaction ${t}: missing status field`)}function gn(e,t,a,n){hn(e,t);const r=e?.data||{};if(!(o=r)||"object"!=typeof o||void 0!==o.inputQuantity&&"string"!=typeof o.inputQuantity||void 0!==o.outputQuantity&&"string"!=typeof o.outputQuantity||void 0!==o.totalFees&&"string"!=typeof o.totalFees||void 0!==o.vaultAddress&&"string"!=typeof o.vaultAddress)throw new un(`Invalid trade data received for transaction ${t}`);var o;const s={transactionId:t,type:a,method:"native"===n.type?"native":"exact",inputAmount:r.inputQuantity||n.amount,outputAmount:r.outputQuantity||n.expectedAmount||"0",totalFees:r.totalFees||"0",tokenName:n.tokenName,vaultAddress:r.vaultAddress||"",blockHash:e.blockHash,gasUsed:e.gasUsed,timestamp:Date.now()};return void 0!==n.slippageToleranceFactor&&(s.slippageTolerance=n.slippageToleranceFactor),s}class mn{constructor(e){let t=null;t=e.env?ln(e.env):e.baseUrl?.includes("prod")?ln("PROD"):ln("STAGE"),this.config={baseUrl:t.launchpadBaseUrl,galaChainBaseUrl:t.galaChainBaseUrl,bundleBaseUrl:t.bundleBaseUrl,webSocketUrl:t.webSocketUrl,dexApiBaseUrl:t.dexApiBaseUrl,launchpadFrontendUrl:t.launchpadFrontendUrl,timeout:3e4,debug:!1,...e},this.logger=new g({debug:this.config.debug??!1,context:"LaunchpadSDK"}),this.validateConfiguration(),this.slippageToleranceFactor=void 0===e.slippageToleranceFactor?mn.DEFAULT_SLIPPAGE_TOLERANCE_FACTOR:this.parseSlippageToleranceFactor(e.slippageToleranceFactor),this.maxAcceptableReverseBondingCurveFeeSlippageFactor=void 0===e.maxAcceptableReverseBondingCurveFeeSlippageFactor?mn.DEFAULT_MAX_ACCEPTABLE_REVERSE_BONDING_CURVE_FEE_SLIPPAGE_FACTOR:this.parseFeeSlippageFactor(e.maxAcceptableReverseBondingCurveFeeSlippageFactor),this.calculateAmountMode=e.calculateAmountMode||mn.DEFAULT_CALCULATE_AMOUNT_MODE,this.auth=new h({wallet:e.wallet,messagePrefix:"Create a GalaChain Wallet"}),this.http=new p(this.auth,this.config),this.galaChainHttp=new p(this.auth,{...this.config,baseUrl:this.config.galaChainBaseUrl}),this.bundleHttp=new p(this.auth,{...this.config,baseUrl:this.config.bundleBaseUrl}),this.dexApiHttp=new p(this.auth,{...this.config,baseUrl:this.config.dexApiBaseUrl}),this.launchpadService=new wa(this.http),this.tokenResolverService=new Wa(this.launchpadService.poolService),this.launchpadAPI=new sn(this.http,this.tokenResolverService,this.logger,this.bundleHttp,this.galaChainHttp,this.dexApiHttp,this.calculateAmountMode),this.galaChainService=new Fa(this.galaChainHttp,e.wallet,this.tokenResolverService,e.debug||!1),this.dexService=new Ca(this.dexApiHttp),this.bundleService=new Va(this.bundleHttp,this.tokenResolverService,this.config.debug||!1,e.wallet,this.getAddress(),this.slippageToleranceFactor,this.maxAcceptableReverseBondingCurveFeeSlippageFactor),this.websocketService=new ja({url:this.config.webSocketUrl},this.config.debug)}createOverrideSdk(e){if(!e||"string"!=typeof e)throw ta("Invalid privateKey: must be a non-empty string","privateKey");if(!e.match(/^0x[a-fA-F0-9]{64}$/))throw ta('Invalid privateKey format: must be "0x" followed by 64 hexadecimal characters',"privateKey");const a=new t.Wallet(e),n={...this.config,wallet:a};return new mn(n)}getAddress(){return this.auth.getAddress()}getEthereumAddress(){return this.config.wallet.address}getConfig(){const{wallet:e,...t}=this.config;return{...t,slippageToleranceFactor:this.slippageToleranceFactor,maxAcceptableReverseBondingCurveFeeSlippageFactor:this.maxAcceptableReverseBondingCurveFeeSlippageFactor,calculateAmountMode:this.calculateAmountMode}}getUrlByTokenName(e){const t=this.config.launchpadFrontendUrl;if(!t)throw ta("launchpadFrontendUrl not configured in SDK","launchpadFrontendUrl");return`${t.replace(/\/$/,"")}/buy-sell/${e}`}async fetchPools(e){const t=await this.launchpadService.fetchPools(e||{});if(t.pools&&Array.isArray(t.pools)){const{extractMetadataFromPoolData:e,isValidPoolForCaching:a}=await Promise.resolve().then(function(){return yn});t.pools.forEach(t=>{if(!a(t))return;const n=e(t,this.logger);n&&this.launchpadAPI.warmCacheFromPoolData(t.tokenName,n)})}return t}async fetchAllPools(e){const t=await this.launchpadService.fetchAllPools(e);if(t.pools&&Array.isArray(t.pools)){const{extractMetadataFromPoolData:e,isValidPoolForCaching:a}=await Promise.resolve().then(function(){return yn});t.pools.forEach(t=>{if(!a(t))return;const n=e(t,this.logger);n&&this.launchpadAPI.warmCacheFromPoolData(t.tokenName,n)})}return t}async fetchTokenDistribution(e){return this.launchpadService.fetchTokenDistribution(e)}async fetchTokenBadges(e){return this.launchpadService.fetchTokenBadges(e)}async fetchTokenSpotPrice(e){return this.dexService.fetchTokenSpotPrice(e)}async fetchGalaSpotPrice(){const e=await this.dexService.fetchTokenSpotPrice("GALA");if(0===e.length)throw ea("Failed to fetch GALA price - no price data returned");const t=e.find(e=>"GALA"===e.symbol);if(!t)throw ea("GALA price not found in response");return t}async fetchLaunchpadTokenSpotPrice(e){return this.launchpadAPI.fetchLaunchpadTokenSpotPrice(e)}async fetchLaunchTokenFee(){return this.galaChainService.fetchLaunchTokenFee()}async fetchPoolDetails(e){const t=await this.resolveVaultAddress(e);if(!t)throw new Error(y(e));const a=(await this.galaChainService.fetchPoolDetails({vaultAddress:t})).Data,n=await this.launchpadAPI.fetchPoolDetailsForCalculation(e);return a.currentSupply=n.currentSupply,a.reverseBondingCurveMaxFeeFactor=n.reverseBondingCurveMaxFeeFactor,a.reverseBondingCurveMinFeeFactor=n.reverseBondingCurveMinFeeFactor,a.reverseBondingCurveNetFeeFactor=n.reverseBondingCurveNetFeeFactor,a}async fetchPoolDetailsForCalculation(e){return this.launchpadAPI.fetchPoolDetailsForCalculation(e)}async isTokenGraduated(e){return(await this.fetchPoolDetails(e)).isGraduated}async fetchVolumeData(e){return this.launchpadService.fetchVolumeData(e)}async fetchTrades(e){return this.launchpadService.fetchTrades(e)}async fetchGalaBalance(e){const{normalizeAddressInput:t}=await Promise.resolve().then(function(){return _t}),a=t(e)||this.getAddress();return this.galaChainService.fetchGalaBalance({owner:a,collection:"GALA",category:"Unit",additionalKey:"none",type:"none",instance:"0"})}async fetchTokenBalance(e){const{normalizeAddressInput:t}=await Promise.resolve().then(function(){return _t}),a=t(e.address);if(e.tokenId){const{normalizeToTokenInstanceKey:t}=await Promise.resolve().then(function(){return Ea}),n=t(e.tokenId),{collection:r,category:o,type:s,additionalKey:i}=n;return this.galaChainService.fetchTokenBalance({owner:a,collection:r,category:o,additionalKey:i,type:s,instance:"0"})}if(e.tokenName){const t=(await this.fetchTokensHeld({tokenName:e.tokenName,page:1,limit:1,...a&&{address:a}})).tokens[0];return t?{quantity:t.quantity,collection:t.collection||"Token",category:"Unit",tokenId:`${t.collection||"Token"}|Unit|${t.symbol}|none`,symbol:t.symbol,name:t.name}:null}throw Zt("tokenId or tokenName","Either tokenId or tokenName")}async fetchComments(e){return this.launchpadService.fetchComments(e)}async calculateBuyAmount(e){return this.launchpadAPI.calculateBuyAmount(e)}async calculateSellAmount(e){return this.launchpadAPI.calculateSellAmount(e)}async calculateBuyAmountLocal(e){return this.launchpadAPI.calculateBuyAmountLocal(e)}async calculateSellAmountLocal(e){return this.launchpadAPI.calculateSellAmountLocal(e)}async calculateBuyAmountExternal(e){return this.launchpadAPI.calculateBuyAmountExternal(e)}async calculateSellAmountExternal(e){return this.launchpadAPI.calculateSellAmountExternal(e)}async calculateBuyAmountForGraduation(e){return this.launchpadAPI.calculateBuyAmountForGraduation(e)}async graduateToken(e){const{tokenName:t,slippageToleranceFactor:a,maxAcceptableReverseBondingCurveFeeSlippageFactor:n,privateKey:r,calculateAmountMode:o,currentSupply:s}=e;let i=t;void 0===o&&void 0===s||(i={tokenName:t,...void 0!==o&&{calculateAmountMode:o},...void 0!==s&&{currentSupply:s}});const c=await this.calculateBuyAmountForGraduation(i),l={tokenName:t,amount:c.amount,type:"exact",expectedAmount:c.amount,maxAcceptableReverseBondingCurveFee:c.reverseBondingCurveFee,slippageToleranceFactor:this.slippageToleranceFactor};return void 0!==a&&(l.slippageToleranceFactor=a),void 0!==n&&(l.maxAcceptableReverseBondingCurveFeeSlippageFactor=n),void 0!==r&&(l.privateKey=r),await this.buy(l)}async calculateInitialBuyAmount(e){const t={nativeTokenQuantity:e};return this.launchpadAPI.calculateInitialBuyAmount(t)}async buy(e){if(e.privateKey){const t=this.createOverrideSdk(e.privateKey),{privateKey:a,...n}=e;return t.buy(n)}await this.ensureWebSocketConnection();const t=await this.bundleService.buyToken(e),a=t.data?.transactionId;if(!a)throw aa("No transaction ID returned from buy operation");return this.waitForConfirmation(a,t=>gn(t,a,"buy",e))}async sell(e){if(e.privateKey){const t=this.createOverrideSdk(e.privateKey),{privateKey:a,...n}=e;return t.sell(n)}await this.ensureWebSocketConnection();const t=await this.bundleService.sellToken(e),a=t.data?.transactionId;if(!a)throw aa("No transaction ID returned from sell operation");return this.waitForConfirmation(a,t=>gn(t,a,"sell",e))}async getBundlerTransactionResult(e){return this.bundleService.getBundlerTransactionResult(e)}async postComment(e){if(e.privateKey){const t=this.createOverrideSdk(e.privateKey),{privateKey:a,...n}=e;return t.postComment(n)}return this.launchpadService.postComment(e)}async launchToken(e){if(e.privateKey){const t=this.createOverrideSdk(e.privateKey),{privateKey:a,...n}=e;return t.launchToken(n)}await this.ensureWebSocketConnection();const t=await this.launchpadAPI.launchToken(e);return this.waitForConfirmation(t,a=>{hn(a,t);const n=a?.data||{};if(!function(e){return!(!e||"object"!=typeof e||void 0!==e.vaultAddress&&"string"!=typeof e.vaultAddress||void 0!==e.tokenStringKey&&"string"!=typeof e.tokenStringKey||void 0!==e.creatorAddress&&"string"!=typeof e.creatorAddress)}(n))throw new un(`Invalid launch data received for transaction ${t}`);const r={transactionId:t,vaultAddress:n.vaultAddress||"",tokenStringKey:n.tokenStringKey||"",tokenName:e.tokenName,tokenSymbol:e.tokenSymbol,creatorAddress:n.creatorAddress||this.getAddress(),timestamp:Date.now(),...a.blockHash&&{blockHash:a.blockHash},...a.gasUsed&&{gasUsed:a.gasUsed}};return"string"==typeof e.tokenImage&&(r.tokenImage=e.tokenImage),void 0!==e.preBuyQuantity&&(r.preBuyQuantity=e.preBuyQuantity),r.vaultAddress&&this.tokenResolverService.set(e.tokenName,r.vaultAddress),r})}async uploadTokenImage(e){if(e.privateKey){const t=this.createOverrideSdk(e.privateKey),{privateKey:a,...n}=e;return t.uploadTokenImage(n)}return this.launchpadService.uploadImageByTokenName(e)}async isTokenNameAvailable(e){return this.launchpadService.isTokenNameAvailable(e)}async isTokenSymbolAvailable(e){return this.launchpadService.isTokenSymbolAvailable(e)}async fetchProfile(e){const{normalizeAddressInput:t}=await Promise.resolve().then(function(){return _t}),a=t(e)||this.getAddress();return this.launchpadService.fetchProfile(a)}async updateProfile(e){const{normalizeAddressInput:t}=await Promise.resolve().then(function(){return _t}),a={...e,address:t(e.address)};if(a.privateKey){const e=this.createOverrideSdk(a.privateKey),{privateKey:t,...n}=a;return e.updateProfile(n)}return this.launchpadService.updateProfile(a)}async uploadProfileImage(e){const{normalizeAddressInput:t}=await Promise.resolve().then(function(){return _t}),a={...e,address:t(e.address)||this.getAddress()};if(a.privateKey){const e=this.createOverrideSdk(a.privateKey),{privateKey:t,...n}=a;return e.uploadProfileImage(n)}return this.launchpadService.uploadProfileImage(a)}async retrieveGalaFromFaucet(e){const{normalizeAddressInput:t}=await Promise.resolve().then(function(){return _t}),a={walletAddress:t(e)||this.getAddress(),amount:"5"};return this.launchpadService.transferFaucets(a)}async fetchTokensHeld(e){const{normalizeAddressInput:t}=await Promise.resolve().then(function(){return _t}),a=t(e?.address)||this.getAddress(),n={page:e?.page||1,limit:e?.limit||10,address:a};return e?.tokenName&&(n.tokenName=e.tokenName),e?.search&&(n.search=e.search),this.launchpadService.fetchTokensHeld(n)}async fetchTokensCreated(e){const{normalizeAddressInput:t}=await Promise.resolve().then(function(){return _t}),a={type:"DEFI",address:t(e?.address)||this.getAddress(),page:e?.page||1,limit:e?.limit||10};return e?.tokenName&&(a.tokenName=e.tokenName),e?.search&&(a.search=e.search),this.launchpadService.fetchTokenList(a)}async transferGala(e){const{normalizeAddressInput:t}=await Promise.resolve().then(function(){return _t}),a={...e,recipientAddress:t(e.recipientAddress)};if(a.privateKey){const e=this.createOverrideSdk(a.privateKey),{privateKey:t,...n}=a;return e.transferGala(n)}return this.galaChainService.transferGala(a)}async transferToken(e){const{normalizeAddressInput:t}=await Promise.resolve().then(function(){return _t}),a={...e,to:t(e.to)};if(a.privateKey){const e=this.createOverrideSdk(a.privateKey),{privateKey:t,...n}=a;return e.transferToken(n)}return this.galaChainService.transferToken(a)}async resolveTokenClassKey(e){return this.galaChainService.resolveTokenClassKey(e)}async resolveVaultAddress(e){return this.tokenResolverService.resolveTokenToVault(e)}getCacheInfo(){return this.launchpadAPI.metadataCache.stats()}clearCache(e){this.launchpadAPI.metadataCache.clear(e)}validateConfiguration(){if(("number"!=typeof this.config.timeout||this.config.timeout<=0||this.config.timeout>3e5)&&(this.logger.warn(`Invalid timeout value: ${this.config.timeout}. Using default 30000ms.`),this.config.timeout=3e4),!this.config.baseUrl)throw ta("baseUrl is required in configuration","baseUrl");if(!this.config.webSocketUrl)throw ta("webSocketUrl is required in configuration","webSocketUrl");try{new URL(this.config.baseUrl)}catch{throw ta(`Invalid baseUrl format: ${this.config.baseUrl}`,"baseUrl")}try{new URL(this.config.webSocketUrl)}catch{throw ta(`Invalid webSocketUrl format: ${this.config.webSocketUrl}`,"webSocketUrl")}if(this.config.galaChainBaseUrl)try{new URL(this.config.galaChainBaseUrl)}catch{throw ta(`Invalid galaChainBaseUrl format: ${this.config.galaChainBaseUrl}`,"galaChainBaseUrl")}if(this.config.bundleBaseUrl)try{new URL(this.config.bundleBaseUrl)}catch{throw ta(`Invalid bundleBaseUrl format: ${this.config.bundleBaseUrl}`,"bundleBaseUrl")}if(this.config.launchpadFrontendUrl)try{new URL(this.config.launchpadFrontendUrl)}catch{throw ta(`Invalid launchpadFrontendUrl format: ${this.config.launchpadFrontendUrl}`,"launchpadFrontendUrl")}}parseSlippageToleranceFactor(e){const t=parseFloat(String(e));return isNaN(t)||t<0||t>1?(this.logger.warn(`Invalid slippage tolerance factor: ${e}, using default: ${mn.DEFAULT_SLIPPAGE_TOLERANCE_FACTOR}`),mn.DEFAULT_SLIPPAGE_TOLERANCE_FACTOR):t}parseFeeSlippageFactor(e){const t=parseFloat(String(e));return isNaN(t)||t<0||t>1?(this.logger.warn(`Invalid fee slippage factor: ${e}, using default: ${mn.DEFAULT_MAX_ACCEPTABLE_REVERSE_BONDING_CURVE_FEE_SLIPPAGE_FACTOR}`),mn.DEFAULT_MAX_ACCEPTABLE_REVERSE_BONDING_CURVE_FEE_SLIPPAGE_FACTOR):t}async ensureWebSocketConnection(){this.websocketService.isConnected()||(await this.websocketService.connect(),this.logger.debug("WebSocket connection established"))}async waitForConfirmation(e,t){this.logger.debug(`Waiting for confirmation of transaction: ${e}`);try{const a=await this.websocketService.waitForTransaction(e);if("completed"!==a.status)throw new dn(e,a.status,a.message);let n;try{n=t(a)}catch(t){if(t instanceof un)throw t;throw new un(`Failed to transform WebSocket response for transaction ${e}`,t instanceof Error?t:new Error(String(t)))}return this.logger.debug(`Transaction confirmed: ${e}`,n),n}catch(t){if(this.logger.error(`Transaction confirmation failed: ${e}`,t),t instanceof dn||t instanceof un)throw t;throw new un(`WebSocket confirmation failed for transaction ${e}`,t instanceof Error?t:new Error(String(t)))}}async cleanup(){try{this.logger.debug("Starting cleanup..."),this.http.cleanup(),this.websocketService&&this.websocketService.disconnect(),this.logger.debug("Cleanup completed")}catch(e){this.logger.error("Error during cleanup:",e)}}static cleanupAll(e=!1){const t=new g({debug:e,context:"LaunchpadSDK"});t.debug("Starting global cleanup...");const{WebSocketService:a}=require("./services/WebSocketService");a.cleanupAll(e),t.debug("Global cleanup completed")}}mn.DEFAULT_SLIPPAGE_TOLERANCE_FACTOR=.15,mn.DEFAULT_MAX_ACCEPTABLE_REVERSE_BONDING_CURVE_FEE_SLIPPAGE_FACTOR=.01,mn.DEFAULT_LAUNCHPAD_TOKEN_MAX_SUPPLY=Ha.DEFAULT_LAUNCHPAD_TOKEN_MAX_SUPPLY,mn.DEFAULT_CALCULATE_AMOUNT_MODE=rn.LOCAL;class pn{static generateWallet(){try{const e=t.Wallet.createRandom();if(!e.mnemonic?.phrase)throw new Error("Failed to generate wallet with mnemonic phrase");const a=this.toGalaAddress(e.address);return{privateKey:e.privateKey,address:e.address,galaAddress:a,mnemonic:e.mnemonic.phrase,wallet:new t.Wallet(e.privateKey)}}catch(e){if("undefined"!=typeof process&&"test"===process.env.NODE_ENV){const e=`test-wallet-${Date.now()}-${++this.testCounter}`,a="0x"+Buffer.from(e).toString("hex").padStart(64,"1").slice(0,64),n=new t.Wallet(a),r=this.toGalaAddress(n.address);return{privateKey:n.privateKey,address:n.address,galaAddress:r,mnemonic:"test test test test test test test test test test test junk",wallet:n}}throw e}}static fromPrivateKey(e){const a=new t.Wallet(e),n=this.toGalaAddress(a.address);return{privateKey:a.privateKey,address:a.address,galaAddress:n,mnemonic:"",wallet:a}}static fromMnemonic(e,a=0){try{const n=t.Mnemonic.fromPhrase(e),r=t.HDNodeWallet.fromMnemonic(n,`m/44'/60'/0'/0/${a}`),o=new t.Wallet(r.privateKey),s=this.toGalaAddress(o.address);return{privateKey:o.privateKey,address:o.address,galaAddress:s,mnemonic:e,wallet:o}}catch(n){if("undefined"!=typeof process&&"test"===process.env.NODE_ENV){const n=`test-mnemonic-index-${a}-${e}`,r="0x"+Buffer.from(n).toString("hex").padStart(64,"1").slice(0,64),o=new t.Wallet(r),s=this.toGalaAddress(o.address);return{privateKey:o.privateKey,address:o.address,galaAddress:s,mnemonic:e,wallet:o}}throw n}}static toGalaAddress(e){const t=e.replace(/^0x/i,"");if(!/^[a-fA-F0-9]{40}$/.test(t))throw new Error(`Invalid Ethereum address format: ${e}`);return`eth|${t}`}static toEthereumAddress(e){if(!e.startsWith("eth|"))throw new Error(`Invalid Gala address format: ${e}. Must start with 'eth|'`);const t=e.slice(4);if(!/^[a-fA-F0-9]{40}$/.test(t))throw new Error(`Invalid address in Gala format: ${e}`);return`0x${t}`}static isValidEthereumAddress(e){try{const t=e.replace(/^0x/i,"");return/^[a-fA-F0-9]{40}$/.test(t)}catch{return!1}}static isValidGalaAddress(e){try{if(!e.startsWith("eth|"))return!1;const t=e.slice(4);return/^[a-fA-F0-9]{40}$/.test(t)}catch{return!1}}static generateMultipleWallets(e=1){if(e<1||e>100)throw new Error("Count must be between 1 and 100");const t=[];if("undefined"!=typeof process&&"test"===process.env.NODE_ENV)for(let a=0;a<e;a++){const e=`test-multi-${a}-${Date.now()}-${++this.testCounter}`,n="0x"+Buffer.from(e).toString("hex").padStart(64,"1").slice(0,64);t.push(this.fromPrivateKey(n))}else for(let a=0;a<e;a++)t.push(this.generateWallet());return t}static getWalletSummary(e,t=!1){const a=["๐Ÿ” Wallet Information","โ•".repeat(50),`๐Ÿ“ Address: ${e.address}`,`๐ŸŽฎ Gala Address: ${e.galaAddress}`,`๐ŸŒฑ Mnemonic: ${e.mnemonic||"Not available"}`];return t?a.splice(3,0,`๐Ÿ”‘ Private Key: ${e.privateKey}`):a.splice(3,0,"๐Ÿ”‘ Private Key: [HIDDEN - use includeSensitive=true to show]"),a.push("โ•".repeat(50)),a.push("๐Ÿ’พ IMPORTANT: Save your mnemonic phrase securely!"),a.push("This is your backup to recover the wallet."),a.join("\n")}}function fn(e){if(void 0===e)return pn.generateWallet();const t=e.trim();if(!t)throw new Error("Input cannot be empty string");if(function(e){const t=e.replace(/^0x/i,"");return/^[a-fA-F0-9]{64}$/.test(t)}(t))return pn.fromPrivateKey(t);if(function(e){const t=e.split(/\s+/).filter(e=>e.length>0);if(12!==t.length&&24!==t.length)return!1;return t.every(e=>/^[a-zA-Z]+$/.test(e))}(t))return pn.fromMnemonic(t);throw new Error(`Unable to detect input format. Expected:\n- Private key: 64 hexadecimal characters (with or without 0x prefix)\n- Mnemonic: 12 or 24 space-separated words\nReceived: "${t.slice(0,50)}${t.length>50?"...":""}"`)}pn.testCounter=0;var yn=Object.freeze({__proto__:null,extractMetadataFromPoolData:function(e,t){const a={};if(e.vaultAddress&&(a.vaultAddress=e.vaultAddress),void 0!==e.reverseBondingCurveMinFeePortion){const n=parseFloat(e.reverseBondingCurveMinFeePortion);isNaN(n)?t&&t.debug(`Skipping invalid reverseBondingCurveMinFeePortion for ${e.tokenName}: "${e.reverseBondingCurveMinFeePortion}"`):a.reverseBondingCurveMinFeeFactor=n}if(void 0!==e.reverseBondingCurveMaxFeePortion){const n=parseFloat(e.reverseBondingCurveMaxFeePortion);isNaN(n)?t&&t.debug(`Skipping invalid reverseBondingCurveMaxFeePortion for ${e.tokenName}: "${e.reverseBondingCurveMaxFeePortion}"`):a.reverseBondingCurveMaxFeeFactor=n}return void 0!==a.reverseBondingCurveMaxFeeFactor&&void 0!==a.reverseBondingCurveMinFeeFactor&&(a.reverseBondingCurveNetFeeFactor=a.reverseBondingCurveMaxFeeFactor-a.reverseBondingCurveMinFeeFactor),Object.keys(a).length>0?a:null},isValidPoolForCaching:function(e){return null!==e&&"object"==typeof e&&"tokenName"in e&&"string"==typeof e.tokenName&&e.tokenName.length>0}});e.AgentConfig=class{static async quickSetup(e={}){const t=e.environment||this.detectEnvironment(),a=this.setupWallet(e.privateKey),n={wallet:a.wallet,baseUrl:e.baseUrl||this.getDefaultBaseUrl(t),timeout:e.timeout||this.getDefaultTimeout(t),debug:e.debug??"production"!==t,...this.getEnvironmentDefaults(t)},r=new mn(n),o={sdk:r,wallet:a,config:n};if(!1!==e.autoValidate){const e=await this.validateSetup(r,a);return{...o,validation:e}}return o}static async validateSetup(e,t){const a=[],n=[],r={canTrade:!1,canCreateTokens:!1,hasBalance:!1,connectionHealthy:!1};try{const t=await e.fetchGalaBalance(e.getAddress());if(r.connectionHealthy=!0,t&&t.quantity){const e=parseFloat(t.quantity);r.hasBalance=e>0,r.canTrade=e>=.1,r.canCreateTokens=e>=100,0===e?n.push("Wallet has zero GALA balance - cannot perform transactions"):e<.1?n.push("GALA balance too low for trading (minimum 0.1 GALA)"):e<100&&n.push("GALA balance too low for token creation (minimum 100 GALA)")}else a.push("Failed to fetch GALA balance: No balance returned")}catch(e){a.push(`Balance check error: ${e instanceof Error?e.message:String(e)}`)}try{const t=await e.fetchPools({type:"recent",page:1,limit:1});t.pools&&0!==t.pools.length||n.push("Pool listing not accessible - some features may be limited")}catch(e){n.push(`Pool access test failed: ${e instanceof Error?e.message:String(e)}`)}return{ready:0===a.length&&r.connectionHealthy,sdk:e,wallet:t||pn.generateWallet(),issues:a,warnings:n,capabilities:r}}static getRecommendedConfig(e,t="general"){const a={environment:e,autoValidate:!0};switch(e){case"production":Object.assign(a,{debug:!1,timeout:3e4});break;case"development":Object.assign(a,{debug:!0,timeout:45e3});break;case"testing":Object.assign(a,{debug:!0,timeout:6e4})}switch(t){case"trading":a.timeout=1.5*(a.timeout||3e4);break;case"creation":a.timeout=2*(a.timeout||3e4);break;case"monitoring":a.timeout=.5*(a.timeout||3e4)}return a}static async multiWalletSetup(e,t="development"){const a={};for(const[n,r]of Object.entries(e)){const{sdk:e}=await this.quickSetup({environment:t,privateKey:r,agentId:`multi-wallet-${n}`,autoValidate:!1});a[n]=e}return a}static detectEnvironment(){const e=process.env.NODE_ENV?.toLowerCase();return"production"===e?"production":"test"===e||"testing"===e?"testing":"development"}static setupWallet(e){if(!e){const e=process.env.PRIVATE_KEY;return e?pn.fromPrivateKey(e):pn.generateWallet()}return"generate"===e?pn.generateWallet():pn.fromPrivateKey(e)}static getDefaultBaseUrl(e){return"production"===e?"https://lpad-backend-prod1.defi.gala.com":"https://lpad-backend-dev1.defi.gala.com"}static getDefaultTimeout(e){switch(e){case"production":default:return 3e4;case"development":return 45e3;case"testing":return 6e4}}static getEnvironmentDefaults(e){const t={};if("production"===e)t.bundleBaseUrl="https://bundle-backend-prod1.defi.gala.com",t.galaChainBaseUrl="https://galachain-gateway-chain-platform-prod-chain-platform-eks.prod.galachain.com";else t.bundleBaseUrl="https://bundle-backend-dev1.defi.gala.com",t.galaChainBaseUrl="https://galachain-gateway-chain-platform-stage-chain-platform-eks.stage.galachain.com";return t}},e.CALCULATION_MODES=rn,e.FileValidationError=fa,e.GALA_DECIMALS=8,e.GALA_TOKEN_CLASS_KEY={collection:"GALA",category:"Unit",type:"none",additionalKey:"none"},e.IMAGE_EXTENSIONS=me,e.LAUNCHPAD_TOKEN_DECIMALS=18,e.LaunchpadSDK=mn,e.MAX_CONCURRENT_POOL_FETCHES=5,e.POOL_TYPES={RECENT:"recent",POPULAR:"popular"},e.SDK_VERSION="3.7.0",e.TRADING_TYPES=nn,e.TransactionFailedError=dn,e.ValidationError=v,e.WebSocketError=un,e.WebSocketTimeoutError=class extends un{constructor(e,t){super(`WebSocket confirmation timeout for transaction ${e} after ${t}ms`),this.name="WebSocketTimeoutError"}},e.addressFormatSchema=L,e.amountMethodSchema=de,e.amountTypeSchema=ue,e.browserFileSchema=fe,e.bufferFileSchema=ye,e.buyTokensDataSchema=Me,e.calculatePreMintDataSchema=je,e.checkPoolOptionsSchema=le,e.commentMessageSchema=X,e.commentPaginationSchema=Ee,e.createLaunchpadSDK=function(e){const{wallet:a,env:n,config:r={}}=e||{};let o;if(a)if("string"==typeof a){o=fn(a).wallet}else{if(!(a instanceof t.Wallet))throw new Error("Invalid wallet input. Expected string (private key or mnemonic) or Wallet instance.");o=a}else{o=fn().wallet}const s={wallet:o,...n&&{env:n},debug:!1,timeout:3e4,...r};return new mn(s)},e.createLimitSchema=z,e.createPaginatedResultSchema=function(e){return r.z.object({data:r.z.array(e),page:r.z.number().int().min(1),limit:r.z.number().int().min(1),total:r.z.number().int().min(0),totalPages:r.z.number().int().min(0),hasNext:r.z.boolean(),hasPrevious:r.z.boolean()})},e.createTradeDataSchema=Be,e.createWallet=fn,e.ethereumAddressSchema=O,e.faucetAmountSchema=M,e.fetchGalaBalanceOptionsSchema=_e,e.fetchPoolDetailsDataSchema=We,e.fetchTokenBalanceOptionsSchema=xe,e.fileSizeSchema=W,e.fileUploadSchema=pe,e.filenameSchema=H,e.flexibleAddressSchema=x,e.flexibleFileSchema=ve,e.formatGalaForDTO=Pa,e.formatLaunchpadTokenForDTO=_a,e.fullNameSchema=_,e.getAmountOptionsSchema=qe,e.getTradeOptionsSchema=Ke,e.graduateTokenOptionsSchema=ge,e.graphDataOptionsSchema=he,e.imageExtensionSchema=Ae,e.imageFilenameSchema=we,e.imageMimeTypeSchema=Q,e.imageUploadOptionsSchema=ie,e.isoDateStringSchema=Y,e.launchTokenDataSchema=se,e.nonNegativeDecimalStringSchema=B,e.optionalUrlSchema=K,e.pageNumberSchema=G,e.paginationResultMetaSchema=Fe,e.poolFetchTypeSchema=ce,e.poolPaginationSchema=Se,e.positiveDecimalStringSchema=$,e.privateKeySchema=J,e.reverseBondingCurveConfigSchema=oe,e.reverseBondingCurveConfigurationSchema=He,e.searchQuerySchema=P,e.sellTokensDataSchema=Re,e.standardLimitSchema=V,e.standardPaginationSchema=Te,e.timestampSchema=Z,e.tokenCategorySchema=ne,e.tokenCollectionSchema=re,e.tokenDescriptionSchema=C,e.tokenListOptionsSchema=De,e.tokenNameSchema=I,e.tokenSymbolSchema=F,e.tokenUrlsSchema=ae,e.tradeCalculationMethodSchema=Ve,e.tradeCalculationTypeSchema=ze,e.tradeLimitSchema=j,e.tradeListParamsSchema=Ge,e.tradePaginationSchema=Ne,e.tradePaginationWithFiltersSchema=Ie,e.tradeTypeBackendSchema=$e,e.tradeTypeSchema=Ue,e.transactionIdSchema=ee,e.transferFaucetsDataSchema=Pe,e.uniqueKeySchema=te,e.updateProfileDataSchema=Le,e.uploadProfileImageOptionsSchema=Oe,e.urlSchema=R,e.userLimitSchema=q,e.userPaginationSchema=ke,e.userTokenNameSchema=D,e.userTokenTypeSchema=Ce,e.userTokensPaginationSchema=be,e.validateAddress=Je,e.validateAmountString=tt,e.validateBuyTokensData=yt,e.validateCalculatePreMintData=kt,e.validateCheckPoolOptions=lt,e.validateCreateTradeData=ft,e.validateFaucetAmount=at,e.validateFetchGalaBalanceOptions=ht,e.validateFetchPoolDetailsData=Nt,e.validateFetchTokenBalanceOptions=pt,e.validateFullName=nt,e.validateGetAmountOptions=Tt,e.validateGetTradeOptions=At,e.validateImageUploadOptions=ct,e.validateLaunchTokenData=st,e.validateSearchQuery=rt,e.validateSellTokensData=vt,e.validateTokenDescription=Ze,e.validateTokenListOptions=ut,e.validateTokenName=Xe,e.validateTokenSymbol=Ye,e.validateTokenUrls=it,e.validateTradeListParams=wt,e.validateTransferFaucetsData=dt,e.validateUpdateProfileData=gt,e.validateUploadProfileImageOptions=mt,e.validateUserTokenName=ot,e.validateVaultAddress=et,e.vaultAddressSchema=U});