@vleap/warps-adapter-multiversx 0.2.0-beta.92 → 0.2.0-beta.93

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
- "use strict";var rt=Object.create;var Te=Object.defineProperty;var nt=Object.getOwnPropertyDescriptor;var at=Object.getOwnPropertyNames;var it=Object.getPrototypeOf,st=Object.prototype.hasOwnProperty;var ot=(s,e)=>{for(var t in e)Te(s,t,{get:e[t],enumerable:!0})},Oe=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of at(e))!st.call(s,n)&&n!==t&&Te(s,n,{get:()=>e[n],enumerable:!(r=nt(e,n))||r.enumerable});return s};var ct=(s,e,t)=>(t=s!=null?rt(it(s)):{},Oe(e||!s||!s.__esModule?Te(t,"default",{value:s,enumerable:!0}):t,s)),lt=s=>Oe(Te({},"__esModule",{value:!0}),s);var Dt={};ot(Dt,{ExplorerUrls:()=>H,KnownTokens:()=>Ie,MultiversxAdapter:()=>Ue,MultiversxExplorers:()=>Qe,MultiversxExplorersConfig:()=>Be,NativeTokenEgld:()=>Ae,NativeTokenVibe:()=>et,VibechainAdapter:()=>Fe,VibechainExplorers:()=>Xe,WarpMultiversxAbiBuilder:()=>R,WarpMultiversxBrandBuilder:()=>me,WarpMultiversxBuilder:()=>de,WarpMultiversxConstants:()=>mt,WarpMultiversxContractLoader:()=>ue,WarpMultiversxDataLoader:()=>he,WarpMultiversxExecutor:()=>ge,WarpMultiversxExplorer:()=>fe,WarpMultiversxInputTypes:()=>v,WarpMultiversxOutput:()=>J,WarpMultiversxRegistry:()=>We,WarpMultiversxSerializer:()=>D,WarpMultiversxWallet:()=>ve,address_value:()=>Ut,asset_value:()=>Ot,biguint_value:()=>Nt,boolean_value:()=>Vt,codemeta:()=>Wt,codemeta_value:()=>Mt,composite_value:()=>Et,createMultiversxAdapter:()=>we,findKnownTokenById:()=>Se,getAllMultiversxAdapters:()=>ft,getAllMultiversxChainNames:()=>pt,getKnownTokensForChain:()=>ut,getMultiversxEntrypoint:()=>C,getMultiversxRegistryAddress:()=>I,getNormalizedTokenIdentifier:()=>pe,hex_value:()=>Ft,isNativeToken:()=>j,list:()=>wt,list_value:()=>At,nothing_value:()=>Rt,option_value:()=>Tt,optional:()=>vt,optional_value:()=>Ct,string_value:()=>bt,toTypedConfigInfo:()=>Ve,toTypedRegistryInfo:()=>ye,token:()=>yt,token_value:()=>kt,u16_value:()=>It,u32_value:()=>St,u64_value:()=>Bt,u8_value:()=>Pt,variadic_value:()=>xt});module.exports=lt(Dt);var Ee=require("@vleap/warps"),pt=()=>[Ee.WarpChainName.Multiversx,Ee.WarpChainName.Vibechain];var Ze=require("@vleap/warps");var F=require("@multiversx/sdk-core"),E=require("@vleap/warps");var te=require("@multiversx/sdk-core"),Me=require("@vleap/warps"),j=s=>!s.includes("-"),pe=s=>j(s)?`${s}-000000`:s,C=(s,e,t)=>{let r="warp-sdk",i=t?(0,Me.getProviderConfig)(t,s.name,e,s.defaultApiUrl):{url:s.defaultApiUrl},o=i.url,c={headers:i.headers};return e==="devnet"?new te.DevnetEntrypoint({url:o,kind:"api",clientName:r,networkProviderConfig:c}):e==="testnet"?new te.TestnetEntrypoint({url:o,kind:"api",clientName:r,networkProviderConfig:c}):new te.MainnetEntrypoint({url:o,kind:"api",clientName:r,networkProviderConfig:c})};var be=require("@vleap/warps");var ue=class{constructor(e){this.config=e}async getContract(e,t){try{let i=await C(t,this.config.env,this.config).createNetworkProvider().doGetGeneric(`accounts/${e}`);return{address:e,owner:i.ownerAddress,verified:i.isVerified||!1}}catch(r){return be.WarpLogger.error("WarpContractLoader: getContract error",r),null}}async getVerificationInfo(e,t){try{let i=await C(t,this.config.env,this.config).createNetworkProvider().doGetGeneric(`accounts/${e}/verification`);return{codeHash:i.codeHash,abi:i.source.abi}}catch(r){return be.WarpLogger.error("WarpContractLoader: getVerificationInfo error",r),null}}};var R=class{constructor(e,t){this.config=e;this.chain=t;this.contractLoader=new ue(this.config),this.cache=new E.WarpCache(this.config.cache?.type)}async createInscriptionTransaction(e){let t=(0,E.getWarpWalletAddressFromConfig)(this.config,this.chain.name);if(!t)throw new Error("WarpBuilder: user address not set");let r=new F.TransactionsFactoryConfig({chainID:this.chain.chainId}),n=new F.TransferTransactionsFactory({config:r}),i=F.Address.newFromBech32(t),o={protocol:(0,E.getLatestProtocolIdentifier)("abi"),content:e},c=JSON.stringify(o),l=await n.createTransactionForTransfer(i,{receiver:i,nativeAmount:BigInt(0),data:Uint8Array.from(Buffer.from(c))});return l.gasLimit=l.gasLimit+BigInt(2e6),l}async createFromRaw(e){return JSON.parse(e)}async createFromTransaction(e){let t=await this.createFromRaw(e.data.toString());return t.meta={chain:this.chain.name,identifier:(0,E.createWarpIdentifier)(this.chain.name,"hash",e.hash),query:null,hash:e.hash,creator:e.sender.toBech32(),createdAt:new Date(e.timestamp*1e3).toISOString()},t}async createFromTransactionHash(e,t){let r=E.WarpCacheKey.WarpAbi(this.config.env,e);if(t){let o=this.cache.get(r);if(o)return E.WarpLogger.info(`WarpAbiBuilder (createFromTransactionHash): Warp abi found in cache: ${e}`),o}let i=C(this.chain,this.config.env,this.config).createNetworkProvider();try{let o=await i.getTransaction(e),c=await this.createFromTransaction(o);return t&&t.ttl&&c&&this.cache.set(r,c,t.ttl),c}catch(o){return E.WarpLogger.error("WarpAbiBuilder: Error creating from transaction hash",o),null}}async getAbiForAction(e){if(e.abi)return await this.fetchAbi(e);if(!e.address)throw new Error("WarpActionExecutor: Address not found");let t=await this.contractLoader.getVerificationInfo(e.address,this.chain);if(!t)throw new Error("WarpActionExecutor: Verification info not found");return F.AbiRegistry.create(t.abi)}async fetchAbi(e){if(!e.abi)throw new Error("WarpActionExecutor: ABI not found");if(e.abi.startsWith(E.WarpConstants.IdentifierType.Hash)){let t=e.abi.split(E.WarpConstants.ArgParamsSeparator)[1],r=await this.createFromTransactionHash(t);if(!r)throw new Error(`WarpActionExecutor: ABI not found for hash: ${e.abi}`);return F.AbiRegistry.create(r.content)}else{let r=await(await fetch(e.abi)).json();return F.AbiRegistry.create(r)}}};var Q=require("@multiversx/sdk-core"),_=require("@vleap/warps"),Re=require("buffer");var me=class{constructor(e,t){this.config=e;this.chain=t;this.core=new _.WarpBrandBuilder(e)}async createInscriptionTransaction(e){let t=(0,_.getWarpWalletAddressFromConfig)(this.config,this.chain.name);if(!t)throw new Error("BrandBuilder: user address not set");let r=new Q.TransactionsFactoryConfig({chainID:this.chain.chainId}),n=new Q.TransferTransactionsFactory({config:r}),i=Q.Address.newFromBech32(t),o=JSON.stringify(e);return await n.createTransactionForNativeTokenTransfer(i,{receiver:Q.Address.newFromBech32(t),nativeAmount:BigInt(0),data:Uint8Array.from(Re.Buffer.from(o))})}async createFromTransaction(e,t=!1){let r=await this.core.createFromRaw(e.data.toString(),t);return r.meta={query:null,chain:this.chain.name,identifier:(0,_.createWarpIdentifier)(this.chain.name,"hash",e.hash),hash:e.hash,creator:e.sender.toBech32(),createdAt:new Date(e.timestamp*1e3).toISOString()},r}async createFromTransactionHash(e){let r=C(this.chain,this.config.env,this.config).createNetworkProvider();try{let n=await r.getTransaction(e);return this.createFromTransaction(n)}catch(n){return _.WarpLogger.error("BrandBuilder: Error creating from transaction hash",n),null}}};var X=require("@multiversx/sdk-core"),B=require("@vleap/warps");var de=class extends B.WarpBuilder{constructor(t,r){super(t);this.config=t;this.chain=r;this.cache=new B.WarpCache(t.cache?.type),this.core=new B.WarpBuilder(t)}async createInscriptionTransaction(t){let r=(0,B.getWarpWalletAddressFromConfig)(this.config,this.chain.name);if(!r)throw new Error("WarpBuilder: user address not set");let n=new X.TransactionsFactoryConfig({chainID:this.chain.chainId}),i=new X.TransferTransactionsFactory({config:n}),o=X.Address.newFromBech32(r),c=JSON.stringify(t),l=await i.createTransactionForTransfer(o,{receiver:X.Address.newFromBech32(r),nativeAmount:BigInt(0),data:Uint8Array.from(Buffer.from(c))});return l.gasLimit=l.gasLimit+BigInt(2e6),l}async createFromTransaction(t,r=!1){let n=await this.core.createFromRaw(t.data.toString(),r);return n.meta={chain:this.chain.name,identifier:(0,B.createWarpIdentifier)(this.chain.name,"hash",t.hash),query:null,hash:t.hash,creator:t.sender.toBech32(),createdAt:new Date(t.timestamp*1e3).toISOString()},n}async createFromTransactionHash(t,r){let n=B.WarpCacheKey.Warp(this.config.env,t);if(r){let c=this.cache.get(n);if(c)return B.WarpLogger.info(`WarpBuilder (createFromTransactionHash): Warp found in cache: ${t}`),c}let o=C(this.chain,this.config.env,this.config).createNetworkProvider();try{let c=await o.getTransaction(t),l=await this.createFromTransaction(c);return r&&r.ttl&&l&&this.cache.set(n,l,r.ttl),l}catch(c){return B.WarpLogger.error("WarpBuilder: Error creating from transaction hash",c),null}}};var $=require("@multiversx/sdk-core"),re=require("@vleap/warps");var Pe=require("@vleap/warps");var Le=require("@vleap/warps"),De=Le.WarpChainName.Multiversx,Ke=[{chain:De,identifier:"EGLD",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"},{chain:De,identifier:"EGLD-000000",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"}];var _e=require("@vleap/warps"),P=_e.WarpChainName.Multiversx,$e=[{chain:P,identifier:"EGLD",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"},{chain:P,identifier:"EGLD-000000",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"},{chain:P,identifier:"SEGLD-3ad2d0",name:"StakedEGLD",symbol:"SEGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/SEGLD-3ad2d0/icon.png"},{chain:P,identifier:"HSEGLD-c13a4e",name:"HatomSEGLD",symbol:"HSEGLD",decimals:8,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/HSEGLD-c13a4e/icon.png"},{chain:P,identifier:"UTK-2f80e9",name:"xMoney UTK",symbol:"UTK",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/UTK-2f80e9/icon.png"},{chain:P,identifier:"USDC-c76f1f",name:"WrappedUSDC",symbol:"USDC",decimals:6,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/USDC-c76f1f/icon.png"},{chain:P,identifier:"WEGLD-bd4d79",name:"WrappedEGLD",symbol:"WEGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/WEGLD-bd4d79/icon.png"},{chain:P,identifier:"HTM-f51d55",name:"Hatom",symbol:"HTM",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/HTM-f51d55/icon.png"},{chain:P,identifier:"MEX-455c57",name:"MEX",symbol:"MEX",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/MEX-455c57/icon.png"},{chain:P,identifier:"WTAO-4f5363",name:"WrappedTAO",symbol:"WTAO",decimals:9,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/WTAO-4f5363/icon.png"},{chain:P,identifier:"HEGLD-d61095",name:"HatomEGLD",symbol:"HEGLD",decimals:8,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/HEGLD-d61095/icon.png"},{chain:P,identifier:"WBTC-5349b3",name:"WrappedBTC",symbol:"WBTC",decimals:8,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/WBTC-5349b3/icon.png"},{chain:P,identifier:"WETH-b4ca29",name:"WrappedETH",symbol:"WETH",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/WETH-b4ca29/icon.png"},{chain:P,identifier:"USH-111e09",name:"HatomUSD",symbol:"USH",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/USH-111e09/icon.png"},{chain:P,identifier:"USDT-f8c08c",name:"WrappedUSDT",symbol:"USDT",decimals:6,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/USDT-f8c08c/icon.png"}];var Ge=require("@vleap/warps"),He=Ge.WarpChainName.Multiversx,ze=[{chain:He,identifier:"EGLD",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"},{chain:He,identifier:"EGLD-000000",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"}];var je=require("@vleap/warps"),qe=je.WarpChainName.Vibechain,Ce=[{chain:qe,identifier:"VIBE",name:"VIBE",symbol:"VIBE",decimals:18,logoUrl:"https://joai.ai/images/tokens/vibe.svg"},{chain:qe,identifier:"VIBE-000000",name:"VIBE",symbol:"VIBE",decimals:18,logoUrl:"https://joai.ai/images/tokens/vibe.svg"}];var Ie={[Pe.WarpChainName.Multiversx]:{mainnet:$e,testnet:ze,devnet:Ke},[Pe.WarpChainName.Vibechain]:{mainnet:Ce,testnet:Ce,devnet:Ce}},Se=(s,e,t)=>(Ie[s]?.[e]||[]).find(n=>n.identifier===t)||null,ut=(s,e)=>Ie[s]?.[e]||[];var he=class{constructor(e,t){this.config=e;this.chain=t;this.cache=new re.WarpCache(e.cache?.type)}async getAccount(e){let r=await C(this.chain,this.config.env,this.config).createNetworkProvider().getAccount($.Address.newFromBech32(e));return{chain:this.chain.name,address:r.address.toBech32(),balance:r.balance}}async getAccountAssets(e){let t=C(this.chain,this.config.env,this.config).createNetworkProvider(),r=t.getAccount($.Address.newFromBech32(e)),n=t.getFungibleTokensOfAccount($.Address.newFromBech32(e)),[i,o]=await Promise.all([r,n]),c=i.balance>0?[{...this.chain.nativeToken,amount:i.balance}]:[];return c.push(...o.map(l=>({chain:this.chain.name,identifier:l.token.identifier,name:l.raw.name,symbol:l.raw.ticker,amount:l.amount,decimals:l.raw.decimals,logoUrl:l.raw.assets?.pngUrl||"",price:l.raw.price?Number(l.raw.price):void 0,supply:l.raw.supply?BigInt(l.raw.supply):void 0}))),c}async getAsset(e){let t=re.WarpCacheKey.Asset(this.config.env,this.chain.name,e),r=this.cache.get(t);if(r)return r;let n=Se(this.chain.name,this.config.env,e);if(n)return{chain:this.chain.name,identifier:e,name:n.name,symbol:n.symbol,amount:0n,decimals:n.decimals,logoUrl:n.logoUrl};let i=new $.TokenComputer,o=j(e)?0n:i.extractNonceFromExtendedIdentifier(e),c=new $.Token({identifier:e,nonce:BigInt(o||0)}),l=i.isFungible(c),f=C(this.chain,this.config.env,this.config).createNetworkProvider(),g=pe(e),d=await f.doGetGeneric(`tokens/${g}`),T={chain:this.chain.name,identifier:c.identifier,name:d.name,symbol:d.ticker,amount:0n,decimals:d.decimals,logoUrl:d.assets?.pngUrl||null,price:d.price?Number(d.price):void 0,supply:d.supply?BigInt(d.supply):void 0};return this.cache.set(t,T,re.CacheTtl.OneHour),T}async getAction(e,t=!1){let r=C(this.chain,this.config.env,this.config),n=t?await r.awaitCompletedTransaction(e):await r.getTransaction(e);return{chain:this.chain.name,id:n.hash,receiver:n.receiver.toBech32(),sender:n.sender.toBech32(),value:n.value,function:n.function,status:this.toActionStatus(n),createdAt:this.toActionCreatedAt(n),error:n?.smartContractResults.map(i=>i.raw.returnMessage)[0]||null,tx:n}}async getAccountActions(e,t){let r=C(this.chain,this.config.env,this.config).createNetworkProvider(),n=`accounts/${e}/transactions`,i=new URLSearchParams,o=t?.size||25,c=t?.page||0;if(c>0){let f=c*o;i.append("from",f.toString())}return o!==25&&i.append("size",o.toString()),i.toString()&&(n+=`?${i.toString()}`),(await r.doGetGeneric(n)).map(f=>({chain:this.chain.name,id:f.txHash,receiver:f.receiver,sender:f.sender,value:f.value,function:f.function,status:this.toActionStatus(f),createdAt:this.toActionCreatedAt(f)}))}toActionStatus(e){return e.status.isSuccessful()?"success":e.status.isFailed()?"failed":"pending"}toActionCreatedAt(e){return new Date(e.timestamp||e.timestamp*1e3).toISOString()}};var A=require("@multiversx/sdk-core"),N=require("@vleap/warps");var ne=require("@multiversx/sdk-core"),w=require("@vleap/warps");var a=require("@multiversx/sdk-core"),Je=require("@vleap/warps");var h={HttpProtocolPrefix:"http",IdentifierParamName:"warp",IdentifierParamSeparator:":",IdentifierChainDefault:"multiversx",IdentifierType:{Alias:"alias",Hash:"hash"},IdentifierAliasMarker:"@",Globals:{UserWallet:{Placeholder:"USER_WALLET",Accessor:s=>s.config.user?.wallets?.[s.adapter.chainInfo.name]},UserWalletPublicKey:{Placeholder:"USER_WALLET_PUBLICKEY",Accessor:s=>{if(!s.adapter.wallet)return null;try{return s.adapter.wallet.getPublicKey()||null}catch{return null}}},ChainApiUrl:{Placeholder:"CHAIN_API",Accessor:s=>s.adapter.chainInfo.defaultApiUrl},ChainAddressHrp:{Placeholder:"CHAIN_ADDRESS_HRP",Accessor:s=>s.adapter.chainInfo.addressHrp}},Vars:{Query:"query",Env:"env"},ArgParamsSeparator:":",ArgCompositeSeparator:"|",ArgListSeparator:",",ArgStructSeparator:";",Transform:{Prefix:"transform:"},Source:{UserWallet:"user:wallet"},Position:{Payload:"payload:"},Alerts:{TriggerEventPrefix:"event"}},u={Option:"option",Vector:"vector",Tuple:"tuple",Struct:"struct",String:"string",Uint8:"uint8",Uint16:"uint16",Uint32:"uint32",Uint64:"uint64",Uint128:"uint128",Uint256:"uint256",Biguint:"biguint",Bool:"bool",Address:"address",Asset:"asset",Hex:"hex"};var mt={Egld:{Identifier:"EGLD",EsdtIdentifier:"EGLD-000000",DisplayName:"eGold",Decimals:18}},v={Null:"null",Optional:"optional",List:"list",Token:"token",CodeMeta:"codemeta"},Qe=(r=>(r.MultiversxExplorer="multiversx_explorer",r.MultiversxExplorerDevnet="multiversx_explorer_devnet",r.MultiversxExplorerTestnet="multiversx_explorer_testnet",r))(Qe||{}),Xe=(r=>(r.VibechainExplorer="vibechain_explorer",r.VibechainExplorerDevnet="vibechain_explorer_devnet",r.VibechainExplorerTestnet="vibechain_explorer_testnet",r))(Xe||{}),Be={multiversx:{mainnet:["multiversx_explorer"],testnet:["multiversx_explorer_testnet"],devnet:["multiversx_explorer_devnet"]},vibechain:{mainnet:["vibechain_explorer"],testnet:["vibechain_explorer_testnet"],devnet:["vibechain_explorer_devnet"]}},H={multiversx_explorer:"https://explorer.multiversx.com",multiversx_explorer_devnet:"https://devnet-explorer.multiversx.com",multiversx_explorer_testnet:"https://testnet-explorer.multiversx.com",vibechain_explorer:"https://vibeox-explorer.multiversx.com",vibechain_explorer_devnet:"https://vibeox-explorer.multiversx.com",vibechain_explorer_testnet:"https://vibeox-explorer.multiversx.com"};var dt=new RegExp(`${h.ArgParamsSeparator}(.*)`),D=class{constructor(e){this.coreSerializer=new Je.WarpSerializer(e)}typedToString(e){let t=e.getType();if(t.hasExactClass(a.OptionType.ClassName)||e.hasClassOrSuperclass(a.OptionValue.ClassName)){if(!e.isSet())return u.Option+h.ArgParamsSeparator+"null";let r=this.typedToString(e.getTypedValue());return u.Option+h.ArgParamsSeparator+r}if(t.hasExactClass(a.VariadicType.ClassName)||e.hasClassOrSuperclass(a.VariadicValue.ClassName)){let r=e.getItems();if(r.length===0){let g=this.typeToString(t.getFirstTypeParameter());return u.Vector+h.ArgParamsSeparator+g+h.ArgParamsSeparator}let n=r.map(g=>this.typedToString(g));if(n.every(g=>g.startsWith(u.Tuple)))return u.Vector+h.ArgParamsSeparator+n.join(",");let i=n[0],o=i.indexOf(h.ArgParamsSeparator),c=i.substring(0,o),l=n.map(g=>{let d=g.indexOf(h.ArgParamsSeparator);return g.substring(d+1)}),f=c.startsWith(u.Struct)?h.ArgStructSeparator:h.ArgListSeparator;return u.Vector+h.ArgParamsSeparator+c+h.ArgParamsSeparator+l.join(f)}if(t.hasExactClass(a.OptionalType.ClassName)||e.hasClassOrSuperclass(a.OptionalValue.ClassName)){if(!e.isSet())return v.Optional+h.ArgParamsSeparator+"null";let r=this.typedToString(e.getTypedValue());return v.Optional+h.ArgParamsSeparator+r}if(t.hasExactClass(a.ListType.ClassName)||e.hasClassOrSuperclass(a.List.ClassName)){let n=e.getItems().map(l=>this.typedToString(l));if(n.every(l=>l.startsWith(u.Tuple)))return v.List+h.ArgParamsSeparator+n.join(",");let o=n.map(l=>l.split(h.ArgParamsSeparator)[0])[0],c=n.map(l=>l.split(h.ArgParamsSeparator)[1]);return v.List+h.ArgParamsSeparator+o+h.ArgParamsSeparator+c.join(h.ArgListSeparator)}if(t.hasExactClass(a.CompositeType.ClassName)||e.hasClassOrSuperclass(a.CompositeValue.ClassName)){let n=e.getItems().map(i=>{let o=this.typedToString(i),c=o.indexOf(h.ArgParamsSeparator),l=o.substring(0,c),f=o.substring(c+1);return`${l},${f}`});return`${u.Tuple}(${n.join(",")})`}if(t.hasExactClass(a.BigUIntType.ClassName)||e.hasClassOrSuperclass(a.BigUIntValue.ClassName)||t.getName()==="BigUint")return u.Biguint+h.ArgParamsSeparator+BigInt(e.valueOf().toFixed());if(t.hasExactClass(a.U8Type.ClassName)||e.hasClassOrSuperclass(a.U8Value.ClassName))return u.Uint8+h.ArgParamsSeparator+e.valueOf().toNumber();if(t.hasExactClass(a.U16Type.ClassName)||e.hasClassOrSuperclass(a.U16Value.ClassName))return u.Uint16+h.ArgParamsSeparator+e.valueOf().toNumber();if(t.hasExactClass(a.U32Type.ClassName)||e.hasClassOrSuperclass(a.U32Value.ClassName))return u.Uint32+h.ArgParamsSeparator+e.valueOf().toNumber();if(t.hasExactClass(a.U64Type.ClassName)||e.hasClassOrSuperclass(a.U64Value.ClassName))return u.Uint64+h.ArgParamsSeparator+BigInt(e.valueOf().toFixed());if(t.hasExactClass(a.StringType.ClassName)||e.hasClassOrSuperclass(a.StringValue.ClassName))return u.String+h.ArgParamsSeparator+e.valueOf();if(t.hasExactClass(a.BooleanType.ClassName)||e.hasClassOrSuperclass(a.BooleanValue.ClassName))return u.Bool+h.ArgParamsSeparator+e.valueOf();if(t.hasExactClass(a.AddressType.ClassName)||e.hasClassOrSuperclass(a.AddressValue.ClassName))return u.Address+h.ArgParamsSeparator+e.valueOf().toBech32();if(t.hasExactClass(a.BytesType.ClassName)||e.hasClassOrSuperclass(a.BytesValue.ClassName))return u.Hex+h.ArgParamsSeparator+e.valueOf().toString("hex");if(t.getName()==="EsdtTokenPayment"){let r=e.getFieldValue("token_identifier").valueOf(),n=e.getFieldValue("token_nonce").valueOf(),i=e.getFieldValue("amount").valueOf(),c=new a.TokenComputer().computeExtendedIdentifier(new a.Token({identifier:r,nonce:BigInt(n)}));return u.Asset+h.ArgParamsSeparator+c+h.ArgCompositeSeparator+i}if(t.hasExactClass(a.StructType.ClassName)||e.hasClassOrSuperclass(a.Struct.ClassName)){let r=e,i=r.getType().getName(),o=r.getFields();if(o.length===0)return`${u.Struct}(${i})${h.ArgParamsSeparator}`;let c=o.map(l=>{let f=l.value.getType(),d=this.typedToString(l.value).split(h.ArgParamsSeparator),T=d.length>2?d.slice(2).join(h.ArgParamsSeparator):d[1]||"";return`(${l.name}${h.ArgParamsSeparator}${this.typeToString(f)})${T}`});return`${u.Struct}(${i})${h.ArgParamsSeparator}${c.join(h.ArgListSeparator)}`}if(t.hasExactClass(a.TokenIdentifierType.ClassName)||e.hasClassOrSuperclass(a.TokenIdentifierValue.ClassName))return v.Token+h.ArgParamsSeparator+e.valueOf();if(t.hasExactClass(a.CodeMetadataType.ClassName)||e.hasClassOrSuperclass(a.CodeMetadataValue.ClassName))return v.CodeMeta+h.ArgParamsSeparator+e.valueOf().toString();throw new Error(`WarpArgSerializer (typedToString): Unsupported input type: ${e.getClassName()}`)}typedToNative(e){let t=this.typedToString(e);return this.coreSerializer.stringToNative(t)}nativeToTyped(e,t){if(e.startsWith(u.Tuple))return this.stringToTyped(e+":");let r=this.coreSerializer.nativeToString(e,t);return this.stringToTyped(r)}nativeToType(e){if(e.startsWith(u.Tuple)){let t=e.match(/\(([^)]+)\)/)?.[1];if(!t)throw new Error(`Invalid tuple type format: ${e}`);let r=t.split(","),n=[];for(let i=0;i<r.length;i+=2)n.push(r[i]);return new a.CompositeType(...n.map(i=>this.nativeToType(i)))}if(e.startsWith(u.Struct)){let t=e.match(/\(([^)]+)\)/);if(!t)throw new Error("Struct type must include a name in the format struct(Name)");let r=t[1];return new a.StructType(r,[])}if(e===u.String)return new a.StringType;if(e===u.Uint8)return new a.U8Type;if(e===u.Uint16)return new a.U16Type;if(e===u.Uint32)return new a.U32Type;if(e===u.Uint64)return new a.U64Type;if(e===u.Biguint)return new a.BigUIntType;if(e===u.Bool)return new a.BooleanType;if(e===u.Address)return new a.AddressType;if(e===u.Hex)return new a.BytesType;if(e===u.Asset)return new a.StructType("EsdtTokenPayment",[new a.FieldDefinition("token_identifier","",new a.TokenIdentifierType),new a.FieldDefinition("token_nonce","",new a.U64Type),new a.FieldDefinition("amount","",new a.BigUIntType)]);if(e===v.Token)return new a.TokenIdentifierType;if(e===v.CodeMeta)return new a.CodeMetadataType;throw new Error(`WarpArgSerializer (nativeToType): Unsupported input type: ${e}`)}stringToTyped(e){let[t,r]=e.split(/:(.*)/,2);if(t===u.Option){let n=this.stringToTyped(r);return n instanceof a.NothingValue?a.OptionValue.newMissingTyped(n.getType()):a.OptionValue.newProvided(n)}if(t===u.Vector){let n=r.indexOf(h.ArgParamsSeparator),i=r.substring(0,n),o=r.substring(n+1);if(i.startsWith(u.Tuple)){let d=o.split(",").map(T=>this.stringToTyped(T));return new a.VariadicValue(new a.VariadicType(this.nativeToType(i)),d)}if(o.includes("tuple(")){let g=this.splitTupleStrings(o),d=g.map(x=>this.stringToTyped(x)),b=g[0].match(/^(tuple\([^)]+\))/),y=b?b[1]:"tuple";return new a.VariadicValue(new a.VariadicType(this.nativeToType(y)),d)}let c=i.startsWith(u.Struct)?h.ArgStructSeparator:h.ArgListSeparator,f=o.split(c).map(g=>this.stringToTyped(`${i}:${g}`));return new a.VariadicValue(new a.VariadicType(this.nativeToType(i)),f)}if(t.startsWith(u.Tuple)){let n=t.match(/\(([^)]+)\)/)?.[1];if(!n)throw new Error(`Invalid tuple format: ${t}`);let i=n.split(","),o=[];for(let l=0;l<i.length;l+=2){let f=i[l],g=i[l+1];o.push(this.stringToTyped(`${f}:${g}`))}let c=o.map(l=>l.getType());return new a.CompositeValue(new a.CompositeType(...c),o)}if(t.startsWith(u.Struct)){let n=t.match(/\(([^)]+)\)/),i=n?n[1]:"CustomStruct";if(!r)return new a.Struct(new a.StructType(i,[]),[]);let o=r.split(h.ArgListSeparator),c=[],l=[];return o.forEach(f=>{let g=f.match(new RegExp(`^\\(([^${h.ArgParamsSeparator}]+)${h.ArgParamsSeparator}([^)]+)\\)(.+)$`));if(g){let[,d,T,b]=g,y=this.stringToTyped(`${T}${h.ArgParamsSeparator}${b}`);c.push(new a.FieldDefinition(d,"",y.getType())),l.push(new a.Field(y,d))}}),new a.Struct(new a.StructType(i,c),l)}if(t===u.String)return r?a.StringValue.fromUTF8(r):new a.NothingValue;if(t===u.Uint8)return r?new a.U8Value(Number(r)):new a.NothingValue;if(t===u.Uint16)return r?new a.U16Value(Number(r)):new a.NothingValue;if(t===u.Uint32)return r?new a.U32Value(Number(r)):new a.NothingValue;if(t===u.Uint64)return r?new a.U64Value(BigInt(r)):new a.NothingValue;if(t===u.Biguint)return r?new a.BigUIntValue(BigInt(r)):new a.NothingValue;if(t===u.Bool)return r?new a.BooleanValue(typeof r=="boolean"?r:r==="true"):new a.NothingValue;if(t===u.Address)return r?new a.AddressValue(a.Address.newFromBech32(r)):new a.NothingValue;if(t===u.Hex)return r?a.BytesValue.fromHex(r):new a.NothingValue;if(t===u.Asset){let[n,i]=r.split(h.ArgCompositeSeparator),o=new a.TokenComputer,c=j(n)?pe(n):o.extractIdentifierFromExtendedIdentifier(n),l=j(n)?0n:o.extractNonceFromExtendedIdentifier(n);return new a.Struct(this.nativeToType("asset"),[new a.Field(new a.TokenIdentifierValue(c),"token_identifier"),new a.Field(new a.U64Value(BigInt(l)),"token_nonce"),new a.Field(new a.BigUIntValue(BigInt(i)),"amount")])}if(t===v.Null)return new a.NothingValue;if(t===v.Optional){let n=this.stringToTyped(r);return n instanceof a.NothingValue?a.OptionalValue.newMissing():new a.OptionalValue(n.getType(),n)}if(t===v.List){let[n,i]=r.split(dt,2),c=i.split(h.ArgListSeparator).map(l=>this.stringToTyped(n+h.ArgParamsSeparator+l));return new a.List(this.nativeToType(n),c)}if(t===v.Token)return r?new a.TokenIdentifierValue(r):new a.NothingValue;if(t===v.CodeMeta)return new a.CodeMetadataValue(a.CodeMetadata.newFromBytes(Uint8Array.from(Buffer.from(r,"hex"))));throw new Error(`WarpArgSerializer (stringToTyped): Unsupported input type: ${t}`)}splitTupleStrings(e){let t=[],r="",n=0;for(let i=0;i<e.length;i++){let o=e[i];if(o==="(")n++;else if(o===")")n--;else if(o===","&&n===0){t.push(r.trim()),r="";continue}r+=o}return r.trim()&&t.push(r.trim()),t}typeToString(e){if(e.hasExactClass(a.OptionType.ClassName))return u.Option+h.ArgParamsSeparator+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(a.VariadicType.ClassName))return u.Vector+h.ArgParamsSeparator+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(a.StringType.ClassName))return u.String;if(e.hasExactClass(a.U8Type.ClassName))return u.Uint8;if(e.hasExactClass(a.U16Type.ClassName))return u.Uint16;if(e.hasExactClass(a.U32Type.ClassName))return u.Uint32;if(e.hasExactClass(a.U64Type.ClassName))return u.Uint64;if(e.hasExactClass(a.BigUIntType.ClassName))return u.Biguint;if(e.hasExactClass(a.BooleanType.ClassName))return u.Bool;if(e.hasExactClass(a.AddressType.ClassName))return u.Address;if(e.hasExactClass(a.BytesType.ClassName))return u.Hex;if(e.hasExactClass(a.TokenIdentifierType.ClassName))return v.Token;if(e.hasExactClass(a.OptionalType.ClassName))return v.Optional+h.ArgParamsSeparator+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(a.ListType.ClassName))return v.List+h.ArgParamsSeparator+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(a.CodeMetadataType.ClassName))return v.CodeMeta;if(e.hasExactClass(a.StructType.ClassName)&&e.getClassName()==="EsdtTokenPayment")return u.Asset;if(e.hasExactClass(a.StructType.ClassName))return`${u.Struct}(${e.getName()})`;throw new Error(`WarpArgSerializer (typeToString): Unsupported input type: ${e.getClassName()}`)}};var J=class{constructor(e,t,r){this.config=e;this.chain=t;this.typeRegistry=r;this.abi=new R(e,t),this.serializer=new D({typeRegistry:this.typeRegistry}),this.cache=new w.WarpCache(e.cache?.type)}async getActionExecution(e,t,r){let n=this.cache.get(w.WarpCacheKey.WarpExecutable(this.config.env,e.meta?.hash||"",t))??[],i=await this.extractContractOutput(e,t,r,n),o=(0,w.getNextInfo)(this.config,[],e,t,i.output),c=(0,w.applyOutputToMessages)(e,i.output,this.config),l=(0,w.extractResolvedInputValues)(n);return{status:r.status.isSuccessful()?"success":"error",warp:e,action:t,user:(0,w.getWarpWalletAddressFromConfig)(this.config,this.chain.name),txHash:r.hash,tx:r,next:o,values:i.values,output:i.output,messages:c,destination:null,resolvedInputs:l}}async extractContractOutput(e,t,r,n){let i=(0,w.getWarpActionByIndex)(e,t),o=[],c=[],l={};if(!e.output||i.type!=="contract")return{values:{string:o,native:c,mapped:{}},output:l};if(!Object.values(e.output).some(y=>y.includes("out")||y.includes("event"))){for(let[y,x]of Object.entries(e.output))l[y]=x;return{values:{string:o,native:c,mapped:{}},output:await(0,w.evaluateOutputCommon)(e,l,t,n,this.serializer.coreSerializer,this.config)}}let g=await this.abi.getAbiForAction(i),d=new ne.TransactionEventsParser({abi:g}),b=new ne.SmartContractTransactionsOutcomeParser({abi:g}).parseExecute({transactionOnNetwork:r,function:i.func||void 0});for(let[y,x]of Object.entries(e.output)){if(x.startsWith(w.WarpConstants.Transform.Prefix))continue;if(x.startsWith("input.")){l[y]=x;continue}let S=(0,w.parseOutputOutIndex)(x);if(S!==null&&S!==t){l[y]=null;continue}let[k,z,q]=x.split(".");if(k==="event"){if(!z||isNaN(Number(q)))continue;let K=Number(q),W=(0,ne.findEventsByFirstTopic)(r,z),tt=d.parseEvents({events:W})[0],le=Object.values(tt)[K]||null;o.push(String(le)),c.push(le),l[y]=le&&le.valueOf()}else if(k==="out"||k.startsWith("out[")){if(!z)continue;let K=Number(z),W=b.values[K-1]||null;q&&(W=W[q]||null),W&&typeof W=="object"&&(W="toFixed"in W?W.toFixed():W.valueOf()),o.push(String(W)),c.push(W),l[y]=W&&W.valueOf()}else l[y]=x}return{values:{string:o,native:c,mapped:{}},output:await(0,w.evaluateOutputCommon)(e,l,t,n,this.serializer.coreSerializer,this.config)}}async extractQueryOutput(e,t,r,n){let i=t.map(g=>this.serializer.typedToString(g)),o=t.map(g=>this.serializer.typedToNative(g)[1]),c={string:i,native:o,mapped:{}},l={};if(!e.output)return{values:c,output:l};let f=g=>{let d=g.split(".").slice(1).map(b=>parseInt(b)-1);if(d.length===0)return;let T=o[d[0]];for(let b=1;b<d.length;b++){if(T==null)return;T=T[d[b]]}return T};for(let[g,d]of Object.entries(e.output)){if(d.startsWith(w.WarpConstants.Transform.Prefix))continue;let T=(0,w.parseOutputOutIndex)(d);if(T!==null&&T!==r){l[g]=null;continue}d.startsWith("out.")||d==="out"||d.startsWith("out[")?l[g]=f(d)||null:l[g]=d}return l=await(0,w.evaluateOutputCommon)(e,l,r,n,this.serializer.coreSerializer,this.config),{values:c,output:l}}async resolveWarpOutputRecursively(e){let t=e.warp,r=e.entryActionIndex,n=e.executor,i=e.inputs,o=e.meta,c=new Map,l=new Set,f=this;async function g(y,x=[]){if(c.has(y))return c.get(y);if(l.has(y))throw new Error(`Circular dependency detected at action ${y}`);l.add(y);let S=t.actions[y-1];if(!S)throw new Error(`Action ${y} not found`);let k;if(S.type==="query")k=await n.executeQuery(t,y,x);else if(S.type==="collect")k=await n.executeCollect(t,y,x,o);else throw new Error(`Unsupported or interactive action type: ${S.type}`);if(c.set(y,k),t.output)for(let z of Object.values(t.output)){let K=String(z).match(/^out\[(\d+)\]/);if(K){let W=parseInt(K[1],10);W!==y&&!c.has(W)&&await g(W)}}return l.delete(y),k}await g(r,i);let d={};for(let y of c.values())for(let[x,S]of Object.entries(y.output))S!==null?d[x]=S:x in d||(d[x]=null);let T=await(0,w.evaluateOutputCommon)(t,d,r,i,this.serializer.coreSerializer,this.config);return{...c.get(r),action:r,output:T}}};var ht="EGLD-000000",ge=class{constructor(e,t,r){this.config=e;this.chain=t;this.typeRegistry=r;this.serializer=new D({typeRegistry:this.typeRegistry}),this.abi=new R(this.config,this.chain),this.output=new J(this.config,this.chain,this.typeRegistry)}async createTransaction(e){let t=(0,N.getWarpActionByIndex)(e.warp,e.action),r=null;if(t.type==="transfer")r=await this.createTransferTransaction(e);else if(t.type==="contract")r=await this.createContractCallTransaction(e);else{if(t.type==="query")throw new Error("WarpMultiversxExecutor: Invalid action type for createTransactionForExecute; Use executeQuery instead");if(t.type==="collect")throw new Error("WarpMultiversxExecutor: Invalid action type for createTransactionForExecute; Use executeCollect instead")}if(!r)throw new Error(`WarpMultiversxExecutor: Invalid action type (${t.type})`);return r}async createTransferTransaction(e){if(!e.destination)throw new Error("WarpMultiversxExecutor: createTransfer - destination not set");let t=(0,N.getWarpWalletAddressFromConfig)(this.config,e.chain.name);if(!t)throw new Error("WarpMultiversxExecutor: createTransfer - user address not set");let r=A.Address.newFromBech32(t),n=new A.TransactionsFactoryConfig({chainID:e.chain.chainId}),i=e.data?Buffer.from(this.serializer.stringToTyped(e.data).valueOf()):null,o=e.transfers.length===1&&e.transfers[0].identifier===this.chain.nativeToken?.identifier,l=(o?e.transfers[0].amount:0n)+e.value;return await new A.TransferTransactionsFactory({config:n}).createTransactionForTransfer(r,{receiver:A.Address.newFromBech32(e.destination),nativeAmount:l,tokenTransfers:o?[]:this.toTokenTransfers(e.transfers),data:i?new Uint8Array(i):void 0})}async createContractCallTransaction(e){if(!e.destination)throw new Error("WarpMultiversxExecutor: createContractCall - destination not set");let t=(0,N.getWarpWalletAddressFromConfig)(this.config,e.chain.name);if(!t)throw new Error("WarpMultiversxExecutor: createContractCall - user address not set");let r=(0,N.getWarpActionByIndex)(e.warp,e.action),n=A.Address.newFromBech32(t),i=e.args.map(c=>this.serializer.stringToTyped(c)),o=new A.TransactionsFactoryConfig({chainID:e.chain.chainId});return new A.SmartContractTransactionsFactory({config:o}).createTransactionForExecute(n,{contract:A.Address.newFromBech32(e.destination),function:"func"in r&&r.func||"",gasLimit:"gasLimit"in r?BigInt(r.gasLimit||0):0n,arguments:i,tokenTransfers:this.toTokenTransfers(e.transfers),nativeTransferAmount:e.value})}async executeQuery(e){if(!e.destination)throw new Error("WarpMultiversxExecutor: executeQuery - destination not set");let t=(0,N.getWarpActionByIndex)(e.warp,e.action);if(t.type!=="query")throw new Error(`WarpMultiversxExecutor: Invalid action type for executeQuery: ${t.type}`);let r=await this.abi.getAbiForAction(t),n=e.args.map(W=>this.serializer.stringToTyped(W)),i=C(e.chain,this.config.env,this.config),o=A.Address.newFromBech32(e.destination),c=i.createSmartContractController(r),l=c.createQuery({contract:o,function:t.func||"",arguments:n}),f=await c.runQuery(l),g=f.returnCode==="ok",d=new A.ArgSerializer,T=r.getEndpoint(f.function||t.func||""),b=(f.returnDataParts||[]).map(W=>Buffer.from(W)),y=d.buffersToValues(b,T.output),{values:x,output:S}=await this.output.extractQueryOutput(e.warp,y,e.action,e.resolvedInputs),k=(0,N.getNextInfo)(this.config,[],e.warp,e.action,S),q=e.resolvedInputs.find(W=>W.input.position==="receiver"||W.input.position==="destination")?.value||e.destination,K=(0,N.extractResolvedInputValues)(e.resolvedInputs);return{status:g?"success":"error",warp:e.warp,action:e.action,user:(0,N.getWarpWalletAddressFromConfig)(this.config,e.chain.name),txHash:null,tx:null,next:k,values:x,output:{...S,_DATA:y},messages:(0,N.applyOutputToMessages)(e.warp,S,this.config),destination:q,resolvedInputs:K}}toTokenTransfers(e){return e.map(t=>t.identifier===this.chain.nativeToken.identifier?{...t,identifier:ht}:t).map(t=>{let n=new A.TokenComputer().extractNonceFromExtendedIdentifier(t.identifier);return new A.TokenTransfer({token:new A.Token({identifier:t.identifier,nonce:BigInt(n||0)}),amount:t.amount})})}};var fe=class{constructor(e,t){this.chain=e;this.config=t}getExplorers(){let e=Be[this.chain];if(!e)return["multiversx_explorer"];let t=e[this.config.env];return t||["multiversx_explorer"]}getPrimaryExplorer(){return this.getExplorers()[0]}getExplorerUrlByName(e){let t=this.config.preferences?.explorers?.[this.chain];if(t&&!e){let i=H[t];if(i)return i}if(e){let i=H[e];if(i)return i}let r=this.getPrimaryExplorer();return H[r]||H[r]}getAccountUrl(e,t){return`${this.getExplorerUrlByName(t)}/accounts/${e}`}getTransactionUrl(e,t){return`${this.getExplorerUrlByName(t)}/transactions/${e}`}getBlockUrl(e,t){return`${this.getExplorerUrlByName(t)}/blocks/${e}`}getAssetUrl(e,t){return`${this.getExplorerUrlByName(t)}/tokens/${e}`}getContractUrl(e,t){return`${this.getExplorerUrlByName(t)}/accounts/${e}`}getAllExplorers(){return this.getExplorers()}getExplorerByName(e){return this.getExplorers().find(r=>r.toLowerCase()===e.toLowerCase())}getAccountUrls(e){let t=this.getAllExplorers(),r={};return t.forEach(n=>{let i=H[n];i&&(r[n]=`${i}/accounts/${e}`)}),r}getTransactionUrls(e){let t=this.getAllExplorers(),r={};return t.forEach(n=>{let i=H[n];i&&(r[n]=`${i}/transactions/${e}`)}),r}};var m=require("@multiversx/sdk-core"),V=require("@vleap/warps");var Ne={buildInfo:{rustc:{version:"1.86.0",commitHash:"05f9846f893b09a1be1fc8560e33fc3c815cfecb",commitDate:"2025-03-31",channel:"Stable",short:"rustc 1.86.0 (05f9846f8 2025-03-31)"},contractCrate:{name:"registry",version:"0.0.1"},framework:{name:"multiversx-sc",version:"0.51.1"}},name:"RegistryContract",constructor:{inputs:[{name:"unit_price",type:"BigUint"},{name:"vault",type:"Address"}],outputs:[]},upgradeConstructor:{inputs:[],outputs:[]},endpoints:[{name:"registerWarp",mutability:"mutable",payableInTokens:["EGLD"],inputs:[{name:"hash",type:"bytes"},{name:"alias_opt",type:"optional<bytes>",multi_arg:!0},{name:"brand_opt",type:"optional<bytes>",multi_arg:!0}],outputs:[],allow_multiple_var_args:!0},{name:"unregisterWarp",mutability:"mutable",inputs:[{name:"warp",type:"bytes"}],outputs:[]},{name:"upgradeWarp",mutability:"mutable",payableInTokens:["EGLD"],inputs:[{name:"alias",type:"bytes"},{name:"new_warp",type:"bytes"},{name:"brand_opt",type:"optional<bytes>",multi_arg:!0}],outputs:[]},{name:"setWarpAlias",mutability:"mutable",payableInTokens:["EGLD"],inputs:[{name:"hash",type:"bytes"},{name:"alias",type:"bytes"}],outputs:[]},{name:"forceRemoveAlias",mutability:"mutable",inputs:[{name:"hash",type:"bytes"}],outputs:[]},{name:"verifyWarp",mutability:"mutable",inputs:[{name:"warp",type:"bytes"}],outputs:[]},{name:"transferOwnership",mutability:"mutable",inputs:[{name:"warp",type:"bytes"},{name:"new_owner",type:"Address"}],outputs:[]},{name:"getUserWarps",mutability:"readonly",inputs:[{name:"address",type:"Address"}],outputs:[{type:"variadic<InfoView>",multi_result:!0}]},{name:"getInfoByAlias",mutability:"readonly",inputs:[{name:"alias",type:"bytes"}],outputs:[{type:"InfoView"}]},{name:"getInfoByHash",mutability:"readonly",inputs:[{name:"hash",type:"bytes"}],outputs:[{type:"InfoView"}]},{name:"setVault",onlyOwner:!0,mutability:"mutable",inputs:[{name:"vault",type:"Address"}],outputs:[]},{name:"setUnitPrice",onlyOwner:!0,mutability:"mutable",inputs:[{name:"amount",type:"BigUint"}],outputs:[]},{name:"addAdmin",onlyOwner:!0,mutability:"mutable",inputs:[{name:"address",type:"Address"}],outputs:[]},{name:"removeAdmin",onlyOwner:!0,mutability:"mutable",inputs:[{name:"address",type:"Address"}],outputs:[]},{name:"getConfig",mutability:"readonly",inputs:[],outputs:[{type:"ConfigView"}]},{name:"registerBrand",mutability:"mutable",payableInTokens:["EGLD"],inputs:[{name:"hash",type:"bytes"}],outputs:[]},{name:"brandWarp",mutability:"mutable",payableInTokens:["EGLD"],inputs:[{name:"warp",type:"bytes"},{name:"brand",type:"bytes"}],outputs:[]},{name:"getUserBrands",mutability:"readonly",inputs:[{name:"user",type:"Address"}],outputs:[{type:"variadic<bytes>",multi_result:!0}]}],events:[{identifier:"warpRegistered",inputs:[{name:"hash",type:"bytes",indexed:!0},{name:"alias",type:"bytes",indexed:!0},{name:"trust",type:"bytes",indexed:!0}]},{identifier:"warpUnregistered",inputs:[{name:"hash",type:"bytes",indexed:!0}]},{identifier:"warpUpgraded",inputs:[{name:"alias",type:"bytes",indexed:!0},{name:"new_warp",type:"bytes",indexed:!0},{name:"trust",type:"bytes",indexed:!0}]},{identifier:"warpVerified",inputs:[{name:"hash",type:"bytes",indexed:!0}]},{identifier:"aliasUpdated",inputs:[{name:"hash",type:"bytes",indexed:!0},{name:"alias",type:"bytes",indexed:!0}]},{identifier:"ownershipTransferred",inputs:[{name:"warp",type:"bytes",indexed:!0},{name:"old_owner",type:"Address",indexed:!0},{name:"new_owner",type:"Address",indexed:!0}]}],esdtAttributes:[],hasCallback:!1,types:{ConfigView:{type:"struct",fields:[{name:"unit_price",type:"BigUint"},{name:"admins",type:"List<Address>"}]},InfoView:{type:"struct",fields:[{name:"hash",type:"bytes"},{name:"alias",type:"Option<bytes>"},{name:"trust",type:"bytes"},{name:"owner",type:"Address"},{name:"created_at",type:"u64"},{name:"upgraded_at",type:"u64"},{name:"brand",type:"Option<bytes>"},{name:"upgrade",type:"Option<bytes>"}]}}};var I=s=>{if(s==="devnet")return"erd1qqqqqqqqqqqqqpgqje2f99vr6r7sk54thg03c9suzcvwr4nfl3tsfkdl36";if(s==="testnet")throw new Error("Multiversx testnet is not supported");return"erd1qqqqqqqqqqqqqpgq3mrpj3u6q7tejv6d7eqhnyd27n9v5c5tl3ts08mffe"};var ye=s=>({hash:s.hash.toString("hex"),alias:s.alias?.toString()||null,trust:s.trust.toString(),owner:s.owner.toString(),createdAt:s.created_at.toNumber(),upgradedAt:s.upgraded_at?.toNumber(),brand:s.brand?.toString("hex")||null,upgrade:s.upgrade?.toString("hex")||null}),Ve=s=>({unitPrice:BigInt(s.unit_price.toString()),admins:s.admins.map(e=>e.toBech32())});var We=class{constructor(e,t){this.config=e;this.chain=t;this.cache=new V.WarpCache(e.cache?.type),this.registryConfig={unitPrice:BigInt(0),admins:[]},this.userWallet=(0,V.getWarpWalletAddressFromConfig)(this.config,this.chain.name)}async init(){await this.loadRegistryConfigs()}getRegistryConfig(){return this.registryConfig}async createWarpRegisterTransaction(e,t,r){if(this.registryConfig.unitPrice===BigInt(0))throw new Error("WarpRegistry: config not loaded. forgot to call init()?");if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let n=m.Address.newFromBech32(this.userWallet),i=()=>this.isCurrentUserAdmin()?BigInt(0):t&&r?this.registryConfig.unitPrice*BigInt(3):t?this.registryConfig.unitPrice*BigInt(2):this.registryConfig.unitPrice,o=()=>t&&r?[m.BytesValue.fromHex(e),m.BytesValue.fromUTF8(t),m.BytesValue.fromHex(r)]:t?[m.BytesValue.fromHex(e),m.BytesValue.fromUTF8(t)]:[m.BytesValue.fromHex(e)];return await this.getFactory().createTransactionForExecute(n,{contract:m.Address.newFromBech32(I(this.config.env)),function:"registerWarp",gasLimit:BigInt(1e7),nativeTransferAmount:i(),arguments:o()})}async createWarpUnregisterTransaction(e){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let t=m.Address.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(t,{contract:m.Address.newFromBech32(I(this.config.env)),function:"unregisterWarp",gasLimit:BigInt(1e7),arguments:[m.BytesValue.fromHex(e)]})}async createWarpUpgradeTransaction(e,t,r){if(this.registryConfig.unitPrice===BigInt(0))throw new Error("WarpRegistry: config not loaded. forgot to call init()?");if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let n=m.Address.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(n,{contract:m.Address.newFromBech32(I(this.config.env)),function:"upgradeWarp",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:r?[m.BytesValue.fromUTF8(e),m.BytesValue.fromHex(t),m.BytesValue.fromHex(r)]:[m.BytesValue.fromUTF8(e),m.BytesValue.fromHex(t)]})}async createWarpAliasSetTransaction(e,t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let r=m.Address.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(r,{contract:m.Address.newFromBech32(I(this.config.env)),function:"setWarpAlias",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[m.BytesValue.fromHex(e),m.BytesValue.fromUTF8(t)]})}async createWarpVerifyTransaction(e){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let t=m.Address.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(t,{contract:m.Address.newFromBech32(I(this.config.env)),function:"verifyWarp",gasLimit:BigInt(1e7),arguments:[m.BytesValue.fromHex(e)]})}async createWarpTransferOwnershipTransaction(e,t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let r=m.Address.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(r,{contract:m.Address.newFromBech32(I(this.config.env)),function:"transferOwnership",gasLimit:BigInt(1e7),arguments:[m.BytesValue.fromHex(e),new m.AddressValue(new m.Address(t))]})}async createBrandRegisterTransaction(e){if(this.registryConfig.unitPrice===BigInt(0))throw new Error("WarpRegistry: config not loaded. forgot to call init()?");if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let t=m.Address.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(t,{contract:m.Address.newFromBech32(I(this.config.env)),function:"registerBrand",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[m.BytesValue.fromHex(e)]})}async createWarpBrandingTransaction(e,t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let r=m.Address.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(r,{contract:m.Address.newFromBech32(I(this.config.env)),function:"brandWarp",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[m.BytesValue.fromHex(e),m.BytesValue.fromHex(t)]})}async getInfoByAlias(e,t){try{let r=V.WarpCacheKey.RegistryInfo(this.config.env,e),n=t?this.cache.get(r):null;if(n)return V.WarpLogger.info(`WarpRegistry (getInfoByAlias): RegistryInfo found in cache: ${e}`),n;let i=m.Address.newFromBech32(I(this.config.env)),o=this.getController(),c=o.createQuery({contract:i,function:"getInfoByAlias",arguments:[m.BytesValue.fromUTF8(e)]}),l=await o.runQuery(c),[f]=o.parseQueryResponse(l),g=f?ye(f):null,d=g?.brand?await this.fetchBrand(g.brand):null;return t&&t.ttl&&this.cache.set(r,{registryInfo:g,brand:d},t.ttl),{registryInfo:g,brand:d}}catch{return{registryInfo:null,brand:null}}}async getInfoByHash(e,t){try{let r=V.WarpCacheKey.RegistryInfo(this.config.env,e);if(t){let d=this.cache.get(r);if(d)return V.WarpLogger.info(`WarpRegistry (getInfoByHash): RegistryInfo found in cache: ${e}`),d}let n=m.Address.newFromBech32(I(this.config.env)),i=this.getController(),o=i.createQuery({contract:n,function:"getInfoByHash",arguments:[m.BytesValue.fromHex(e)]}),c=await i.runQuery(o),[l]=i.parseQueryResponse(c),f=l?ye(l):null,g=f?.brand?await this.fetchBrand(f.brand):null;return t&&t.ttl&&this.cache.set(r,{registryInfo:f,brand:g},t.ttl),{registryInfo:f,brand:g}}catch{return{registryInfo:null,brand:null}}}async getUserWarpRegistryInfos(e){try{let t=e||this.userWallet;if(!t)throw new Error("WarpRegistry: user address not set");let r=m.Address.newFromBech32(I(this.config.env)),n=this.getController(),i=n.createQuery({contract:r,function:"getUserWarps",arguments:[new m.AddressValue(new m.Address(t))]}),o=await n.runQuery(i),[c]=n.parseQueryResponse(o);return c.map(ye)}catch{return[]}}async getUserBrands(e){try{let t=e||this.userWallet;if(!t)throw new Error("WarpRegistry: user address not set");let r=m.Address.newFromBech32(I(this.config.env)),n=this.getController(),i=n.createQuery({contract:r,function:"getUserBrands",arguments:[new m.AddressValue(new m.Address(t))]}),o=await n.runQuery(i),[c]=n.parseQueryResponse(o),l=c.map(d=>d.toString("hex")),f={ttl:365*24*60*60};return(await Promise.all(l.map(d=>this.fetchBrand(d,f)))).filter(d=>d!==null)}catch{return[]}}async fetchBrand(e,t){let r=V.WarpCacheKey.Brand(this.config.env,e),n=t?this.cache.get(r):null;if(n)return V.WarpLogger.info(`WarpRegistry (fetchBrand): Brand found in cache: ${e}`),n;let o=C(this.chain,this.config.env,this.config).createNetworkProvider();try{let c=await o.getTransaction(e),l=JSON.parse(c.data.toString());return l.meta={query:null,chain:this.chain.name,identifier:(0,V.createWarpIdentifier)(this.chain.name,"hash",e),hash:c.hash,creator:c.sender.toBech32(),createdAt:new Date(c.timestamp*1e3).toISOString()},t&&t.ttl&&this.cache.set(r,l,t.ttl),l}catch{return null}}async loadRegistryConfigs(){let e=m.Address.newFromBech32(I(this.config.env)),t=this.getController(),[r]=await t.query({contract:e,function:"getConfig",arguments:[]}),n=r?Ve(r):null;this.registryConfig=n||{unitPrice:BigInt(0),admins:[]}}getFactory(){let e=new m.TransactionsFactoryConfig({chainID:this.chain.chainId}),t=m.AbiRegistry.create(Ne);return new m.SmartContractTransactionsFactory({config:e,abi:t})}getController(){let e=C(this.chain,this.config.env,this.config),t=m.AbiRegistry.create(Ne);return e.createSmartContractController(t)}isCurrentUserAdmin(){return!!this.userWallet&&this.registryConfig.admins.includes(this.userWallet)}};var Ye=require("@multiversx/sdk-core"),ee=require("@vleap/warps");var G=require("@multiversx/sdk-core"),O=require("@vleap/warps"),Y=class Y{constructor(e,t){this.config=e;this.chain=t;this.account=null}async getAddress(){let e=(0,O.getWarpWalletAddressFromConfig)(this.config,this.chain.name);if(e)return e;try{return this.getAccount().address.toBech32()}catch{return null}}async getPublicKey(){try{return this.getAccount().publicKey.hex()}catch{return null}}async signTransaction(e){return await this.getAccount().signTransaction(e),e}async signMessage(e){let t=this.getAccount(),r=new TextEncoder().encode(e),n=await t.signMessage(new G.Message({data:r}));return Buffer.from(n).toString("hex")}getAccountInstance(){return this.getAccount()}async importFromMnemonic(e){let r=G.Mnemonic.fromString(e).deriveKey(0),n=r.hex(),o=r.generatePublicKey().toAddress(this.chain.addressHrp).toBech32(),c={provider:Y.PROVIDER_NAME,address:o,privateKey:n,mnemonic:e};return(0,O.setWarpWalletInConfig)(this.config,this.chain.name,c),c}async importFromPrivateKey(e){let{UserSecretKey:t}=await import("@multiversx/sdk-wallet"),r=t.fromString(e),n=r.hex(),o=r.generatePublicKey().toAddress(this.chain.addressHrp).toBech32(),c={provider:Y.PROVIDER_NAME,address:o,privateKey:n,mnemonic:null};return(0,O.setWarpWalletInConfig)(this.config,this.chain.name,c),c}async export(){let e=this.getAccount(),t=(0,O.getWarpWalletMnemonicFromConfig)(this.config,this.chain.name),r=(0,O.getWarpWalletPrivateKeyFromConfig)(this.config,this.chain.name);return{provider:Y.PROVIDER_NAME,address:e.address.toBech32(),privateKey:r||null,mnemonic:t||null}}async generate(){let e=G.Mnemonic.generate(),t=e.toString(),i=e.deriveKey(0).generatePublicKey().toAddress(this.chain.addressHrp).toBech32();return{provider:Y.PROVIDER_NAME,address:i,privateKey:null,mnemonic:t}}getAccount(){if(this.account)return this.account;let e=(0,O.getWarpWalletMnemonicFromConfig)(this.config,this.chain.name);if(!e)throw new Error("No mnemonic provided");let r=G.Mnemonic.fromString(e).deriveKey(0);return this.account=new G.Account(r),this.account}};Y.PROVIDER_NAME="mnemonic";var ae=Y;var U=require("@multiversx/sdk-core"),M=require("@vleap/warps"),Z=class Z{constructor(e,t){this.config=e;this.chain=t;this.account=null}async getAddress(){let e=(0,M.getWarpWalletAddressFromConfig)(this.config,this.chain.name);if(e)return e;try{return this.getAccount().address.toBech32()}catch{return null}}async getPublicKey(){try{return this.getAccount().publicKey.hex()}catch{return null}}async signTransaction(e){return await this.getAccount().signTransaction(e),e}async signMessage(e){let t=this.getAccount(),r=new TextEncoder().encode(e),n=await t.signMessage(new U.Message({data:r}));return Buffer.from(n).toString("hex")}getAccountInstance(){return this.getAccount()}async importFromMnemonic(e){let r=U.Mnemonic.fromString(e).deriveKey(0),n=r.hex(),o=r.generatePublicKey().toAddress(this.chain.addressHrp).toBech32(),c={provider:Z.PROVIDER_NAME,address:o,privateKey:n,mnemonic:e};return(0,M.setWarpWalletInConfig)(this.config,this.chain.name,c),c}async importFromPrivateKey(e){let r=e.startsWith("-----")?U.UserSecretKey.fromPem(e):U.UserSecretKey.fromString(e),n=r.hex(),o=r.generatePublicKey().toAddress(this.chain.addressHrp).toBech32(),c={provider:Z.PROVIDER_NAME,address:o,privateKey:n,mnemonic:null};return(0,M.setWarpWalletInConfig)(this.config,this.chain.name,c),c}async export(){let e=this.getAccount(),t=(0,M.getWarpWalletPrivateKeyFromConfig)(this.config,this.chain.name),r=(0,M.getWarpWalletMnemonicFromConfig)(this.config,this.chain.name);return{provider:Z.PROVIDER_NAME,address:e.address.toBech32(),privateKey:t||null,mnemonic:r||null}}async generate(){let e=U.UserSecretKey.generate(),t=e.hex(),n=e.generatePublicKey().toAddress(this.chain.addressHrp).toBech32();return{provider:Z.PROVIDER_NAME,address:n,privateKey:t,mnemonic:null}}getAccount(){if(this.account)return this.account;let e=(0,M.getWarpWalletPrivateKeyFromConfig)(this.config,this.chain.name);if(!e)throw new Error("No private key provided");let r=e.startsWith("-----")?U.UserSecretKey.fromPem(e):U.UserSecretKey.fromString(e);return this.account=new U.Account(r),this.account}};Z.PROVIDER_NAME="privateKey";var ie=Z;var se=require("@vleap/warps"),oe=class{constructor(e,t){this.config=e;this.chain=t}async getAddress(){return(0,se.getWarpWalletAddressFromConfig)(this.config,this.chain.name)}async getPublicKey(){return null}async signTransaction(e){let t=await this.getAddress();throw new Error(`Wallet can not be used for signing: ${t}`)}async signMessage(e){let t=await this.getAddress();throw new Error(`Wallet can not be used for signing: ${t}`)}async importFromMnemonic(e){let t=(0,se.getWarpWalletAddressFromConfig)(this.config,this.chain.name);throw new Error(`Wallet can not be used for signing: ${t}`)}async importFromPrivateKey(e){let t=(0,se.getWarpWalletAddressFromConfig)(this.config,this.chain.name);throw new Error(`Wallet can not be used for signing: ${t}`)}async export(){let e=(0,se.getWarpWalletAddressFromConfig)(this.config,this.chain.name);throw new Error(`Wallet can not be used for signing: ${e}`)}async generate(){let e=(0,se.getWarpWalletAddressFromConfig)(this.config,this.chain.name);throw new Error(`Wallet can not be used for signing: ${e}`)}};var ve=class{constructor(e,t){this.config=e;this.chain=t;this.cachedAddress=null;this.cachedPublicKey=null;this.entry=C(t,e.env,e),this.cache=new ee.WarpCache(e.cache?.type),this.walletProvider=this.createProvider(),this.initializeCache()}async signTransaction(e){if(!e||typeof e!="object")throw new Error("Invalid transaction object");if(!this.walletProvider)throw new Error("No wallet provider available");if(this.walletProvider instanceof oe)throw new Error(`Wallet (${this.chain.name}) is read-only`);if(this.walletProvider instanceof ie||this.walletProvider instanceof ae){let r=this.walletProvider.getAccountInstance();if(e.nonce===0n){let n=await this.entry.recallAccountNonce(r.address),i=this.cache.get(`nonce:${r.address.toBech32()}`)||0,o=BigInt(Math.max(i,Number(n)));e.nonce=o}}else if(e.nonce===0n&&this.cachedAddress){let r=Ye.Address.newFromBech32(this.cachedAddress),n=await this.entry.recallAccountNonce(r),i=this.cache.get(`nonce:${this.cachedAddress}`)||0,o=BigInt(Math.max(i,Number(n)));e.nonce=o}let t=await this.walletProvider.signTransaction(e);if(this.walletProvider instanceof ie||this.walletProvider instanceof ae){let r=this.walletProvider.getAccountInstance(),n=Number(r.nonce)+1;this.cache.set(`nonce:${r.address.toBech32()}`,n,ee.CacheTtl.OneMinute)}else if(this.cachedAddress){let r=e.nonce?Number(e.nonce):0;this.cache.set(`nonce:${this.cachedAddress}`,r+1,ee.CacheTtl.OneMinute)}return t}async signTransactions(e){let t=[];for(let r of e)t.push(await this.signTransaction(r));return t}async signMessage(e){if(!this.walletProvider)throw new Error("No wallet provider available");if(this.walletProvider instanceof oe)throw new Error(`Wallet (${this.chain.name}) is read-only`);return await this.walletProvider.signMessage(e)}async sendTransactions(e){return Promise.all(e.map(async t=>this.sendTransaction(t)))}async sendTransaction(e){if(!e||typeof e!="object")throw new Error("Invalid transaction object");if(!e.signature)throw new Error("Transaction must be signed before sending");return await this.entry.sendTransaction(e)}async importFromMnemonic(e){return await this.createProviderForOperation("mnemonic").importFromMnemonic(e)}async importFromPrivateKey(e){return await this.createProviderForOperation("privateKey").importFromPrivateKey(e)}async export(e){return await this.createProviderForOperation(e).export()}async generate(e){return await this.createProviderForOperation(e).generate()}getAddress(){return this.cachedAddress}getPublicKey(){return this.cachedPublicKey}createProvider(){let e=this.config.user?.wallets?.[this.chain.name];return e?typeof e=="string"?new oe(this.config,this.chain):this.createProviderForOperation(e.provider):null}initializeCache(){(0,ee.initializeWalletCache)(this.walletProvider).then(e=>{this.cachedAddress=e.address,this.cachedPublicKey=e.publicKey})}createProviderForOperation(e){let r=this.config.walletProviders?.[this.chain.name]?.[e];if(r){let n=r(this.config,this.chain);if(!n)throw new Error(`Custom wallet provider factory returned null for ${e}`);return n}if(e==="privateKey")return new ie(this.config,this.chain);if(e==="mnemonic")return new ae(this.config,this.chain);throw new Error(`Unsupported wallet provider for ${this.chain.name}: ${e}`)}};var we=(s,e)=>(t,r)=>{let n=e[t.env],i=new Ze.WarpTypeRegistry;return i.registerType("token",{stringToNative:o=>o,nativeToString:o=>`token:${o}`}),i.registerType("codemeta",{stringToNative:o=>o,nativeToString:o=>`codemeta:${o}`}),i.registerTypeAlias("list","vector"),{chainInfo:n,builder:()=>new de(t,n),executor:new ge(t,n,i),output:new J(t,n,i),serializer:new D({typeRegistry:i}),registry:new We(t,n),explorer:new fe(s,t),abiBuilder:()=>new R(t,n),brandBuilder:()=>new me(t,n),dataLoader:new he(t,n),wallet:new ve(t,n)}};var ce=require("@vleap/warps");var Ae={chain:ce.WarpChainName.Multiversx,identifier:"EGLD",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://joai.ai/images/tokens/egld.svg"},Ue=we(ce.WarpChainName.Multiversx,{mainnet:{name:ce.WarpChainName.Multiversx,displayName:"MultiversX",chainId:"1",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://api.multiversx.com",logoUrl:"https://joai.ai/images/chains/multiversx.svg",nativeToken:Ae},testnet:{name:ce.WarpChainName.Multiversx,displayName:"MultiversX Testnet",chainId:"T",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://testnet-api.multiversx.com",logoUrl:"https://joai.ai/images/chains/multiversx.svg",nativeToken:Ae},devnet:{name:ce.WarpChainName.Multiversx,displayName:"MultiversX Devnet",chainId:"D",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://devnet-api.multiversx.com",logoUrl:"https://joai.ai/images/chains/multiversx.svg",nativeToken:Ae}});var xe=require("@vleap/warps");var et={chain:xe.WarpChainName.Vibechain,identifier:"VIBE",name:"VIBE",symbol:"VIBE",decimals:18,logoUrl:"https://joai.ai/images/tokens/vibe.svg"},ke={name:xe.WarpChainName.Vibechain,displayName:"VibeChain",chainId:"V",blockTime:600,addressHrp:"vibe",defaultApiUrl:"https://vibeox-api.multiversx.com",logoUrl:"https://joai.ai/images/chains/vibechain.svg",nativeToken:et},Fe=we(xe.WarpChainName.Vibechain,{mainnet:ke,testnet:ke,devnet:ke});var ft=()=>[Ue,Fe];var L=require("@vleap/warps");var yt=s=>new L.WarpSerializer().nativeToString(v.Token,s),Wt=s=>new L.WarpSerializer().nativeToString(v.CodeMeta,s),vt=(s,e)=>{if(e===null)return v.Optional+L.WarpConstants.ArgParamsSeparator;let t=s(e),r=t.indexOf(L.WarpConstants.ArgParamsSeparator),n=t.substring(0,r),i=t.substring(r+1);return v.Optional+L.WarpConstants.ArgParamsSeparator+n+L.WarpConstants.ArgParamsSeparator+i},wt=s=>new L.WarpSerializer().nativeToString(v.List,s);var p=require("@multiversx/sdk-core"),Tt=(s,e)=>s?p.OptionValue.newProvided(s):e?p.OptionValue.newMissingTyped(e):p.OptionValue.newMissing(),Ct=(s,e)=>s?new p.OptionalValue(s.getType(),s):e?new p.OptionalValue(e):p.OptionalValue.newMissing(),At=s=>{if(s.length===0)throw new Error("Cannot create a list from an empty array");let e=s[0].getType();return new p.List(e,s)},xt=s=>p.VariadicValue.fromItems(...s),Et=s=>{let e=s.map(t=>t.getType());return new p.CompositeValue(new p.CompositeType(...e),s)},bt=s=>p.StringValue.fromUTF8(s),Pt=s=>new p.U8Value(s),It=s=>new p.U16Value(s),St=s=>new p.U32Value(s),Bt=s=>new p.U64Value(s),Nt=s=>new p.BigUIntValue(BigInt(s)),Vt=s=>new p.BooleanValue(s),Ut=s=>new p.AddressValue(p.Address.newFromBech32(s)),kt=s=>new p.TokenIdentifierValue(s),Ft=s=>p.BytesValue.fromHex(s),Ot=s=>new p.Struct(new p.StructType("EsdtTokenPayment",[new p.FieldDefinition("token_identifier","",new p.TokenIdentifierType),new p.FieldDefinition("token_nonce","",new p.U64Type),new p.FieldDefinition("amount","",new p.BigUIntType)]),[new p.Field(new p.TokenIdentifierValue(s.token.identifier),"token_identifier"),new p.Field(new p.U64Value(BigInt(s.token.nonce)),"token_nonce"),new p.Field(new p.BigUIntValue(BigInt(s.amount)),"amount")]),Mt=s=>new p.CodeMetadataValue(p.CodeMetadata.newFromBytes(Uint8Array.from(Buffer.from(s,"hex")))),Rt=()=>new p.NothingValue;0&&(module.exports={ExplorerUrls,KnownTokens,MultiversxAdapter,MultiversxExplorers,MultiversxExplorersConfig,NativeTokenEgld,NativeTokenVibe,VibechainAdapter,VibechainExplorers,WarpMultiversxAbiBuilder,WarpMultiversxBrandBuilder,WarpMultiversxBuilder,WarpMultiversxConstants,WarpMultiversxContractLoader,WarpMultiversxDataLoader,WarpMultiversxExecutor,WarpMultiversxExplorer,WarpMultiversxInputTypes,WarpMultiversxOutput,WarpMultiversxRegistry,WarpMultiversxSerializer,WarpMultiversxWallet,address_value,asset_value,biguint_value,boolean_value,codemeta,codemeta_value,composite_value,createMultiversxAdapter,findKnownTokenById,getAllMultiversxAdapters,getAllMultiversxChainNames,getKnownTokensForChain,getMultiversxEntrypoint,getMultiversxRegistryAddress,getNormalizedTokenIdentifier,hex_value,isNativeToken,list,list_value,nothing_value,option_value,optional,optional_value,string_value,toTypedConfigInfo,toTypedRegistryInfo,token,token_value,u16_value,u32_value,u64_value,u8_value,variadic_value});
1
+ "use strict";var xe=Object.defineProperty;var tt=Object.getOwnPropertyDescriptor;var rt=Object.getOwnPropertyNames;var nt=Object.prototype.hasOwnProperty;var at=(o,e)=>{for(var t in e)xe(o,t,{get:e[t],enumerable:!0})},it=(o,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of rt(e))!nt.call(o,n)&&n!==t&&xe(o,n,{get:()=>e[n],enumerable:!(r=tt(e,n))||r.enumerable});return o};var st=o=>it(xe({},"__esModule",{value:!0}),o);var Ot={};at(Ot,{ExplorerUrls:()=>G,KnownTokens:()=>Ie,MultiversxAdapter:()=>Ue,MultiversxExplorers:()=>je,MultiversxExplorersConfig:()=>Be,NativeTokenEgld:()=>Ce,NativeTokenVibe:()=>Ze,VibechainAdapter:()=>Fe,VibechainExplorers:()=>Qe,WarpMultiversxAbiBuilder:()=>D,WarpMultiversxBrandBuilder:()=>me,WarpMultiversxBuilder:()=>de,WarpMultiversxConstants:()=>lt,WarpMultiversxContractLoader:()=>ue,WarpMultiversxDataLoader:()=>he,WarpMultiversxExecutor:()=>ge,WarpMultiversxExplorer:()=>fe,WarpMultiversxInputTypes:()=>v,WarpMultiversxOutput:()=>J,WarpMultiversxRegistry:()=>We,WarpMultiversxSerializer:()=>L,WarpMultiversxWallet:()=>ve,address_value:()=>Bt,asset_value:()=>Ut,biguint_value:()=>It,boolean_value:()=>St,codemeta:()=>gt,codemeta_value:()=>kt,composite_value:()=>Ct,createMultiversxAdapter:()=>we,findKnownTokenById:()=>Se,getAllMultiversxAdapters:()=>dt,getAllMultiversxChainNames:()=>ot,getKnownTokensForChain:()=>ct,getMultiversxEntrypoint:()=>C,getMultiversxRegistryAddress:()=>I,getNormalizedTokenIdentifier:()=>pe,hex_value:()=>Vt,isNativeToken:()=>j,list:()=>yt,list_value:()=>wt,nothing_value:()=>Ft,option_value:()=>Wt,optional:()=>ft,optional_value:()=>vt,string_value:()=>At,toTypedConfigInfo:()=>Ve,toTypedRegistryInfo:()=>ye,token:()=>ht,token_value:()=>Nt,u16_value:()=>Et,u32_value:()=>bt,u64_value:()=>Pt,u8_value:()=>xt,variadic_value:()=>Tt});module.exports=st(Ot);var Ee=require("@vleap/warps"),ot=()=>[Ee.WarpChainName.Multiversx,Ee.WarpChainName.Vibechain];var Ye=require("@vleap/warps");var F=require("@multiversx/sdk-core"),E=require("@vleap/warps");var te=require("@multiversx/sdk-core"),Oe=require("@vleap/warps"),j=o=>!o.includes("-"),pe=o=>j(o)?`${o}-000000`:o,C=(o,e,t)=>{let r="warp-sdk",i=t?(0,Oe.getProviderConfig)(t,o.name,e,o.defaultApiUrl):{url:o.defaultApiUrl},s=i.url,c={headers:i.headers};return e==="devnet"?new te.DevnetEntrypoint({url:s,kind:"api",clientName:r,networkProviderConfig:c}):e==="testnet"?new te.TestnetEntrypoint({url:s,kind:"api",clientName:r,networkProviderConfig:c}):new te.MainnetEntrypoint({url:s,kind:"api",clientName:r,networkProviderConfig:c})};var be=require("@vleap/warps");var ue=class{constructor(e){this.config=e}async getContract(e,t){try{let i=await C(t,this.config.env,this.config).createNetworkProvider().doGetGeneric(`accounts/${e}`);return{address:e,owner:i.ownerAddress,verified:i.isVerified||!1}}catch(r){return be.WarpLogger.error("WarpContractLoader: getContract error",r),null}}async getVerificationInfo(e,t){try{let i=await C(t,this.config.env,this.config).createNetworkProvider().doGetGeneric(`accounts/${e}/verification`);return{codeHash:i.codeHash,abi:i.source.abi}}catch(r){return be.WarpLogger.error("WarpContractLoader: getVerificationInfo error",r),null}}};var D=class{constructor(e,t){this.config=e;this.chain=t;this.contractLoader=new ue(this.config),this.cache=new E.WarpCache(this.config.cache?.type)}async createInscriptionTransaction(e){let t=(0,E.getWarpWalletAddressFromConfig)(this.config,this.chain.name);if(!t)throw new Error("WarpBuilder: user address not set");let r=new F.TransactionsFactoryConfig({chainID:this.chain.chainId}),n=new F.TransferTransactionsFactory({config:r}),i=F.Address.newFromBech32(t),s={protocol:(0,E.getLatestProtocolIdentifier)("abi"),content:e},c=JSON.stringify(s),l=await n.createTransactionForTransfer(i,{receiver:i,nativeAmount:BigInt(0),data:Uint8Array.from(Buffer.from(c))});return l.gasLimit=l.gasLimit+BigInt(2e6),l}async createFromRaw(e){return JSON.parse(e)}async createFromTransaction(e){let t=await this.createFromRaw(e.data.toString());return t.meta={chain:this.chain.name,identifier:(0,E.createWarpIdentifier)(this.chain.name,"hash",e.hash),query:null,hash:e.hash,creator:e.sender.toBech32(),createdAt:new Date(e.timestamp*1e3).toISOString()},t}async createFromTransactionHash(e,t){let r=E.WarpCacheKey.WarpAbi(this.config.env,e);if(t){let s=this.cache.get(r);if(s)return E.WarpLogger.info(`WarpAbiBuilder (createFromTransactionHash): Warp abi found in cache: ${e}`),s}let i=C(this.chain,this.config.env,this.config).createNetworkProvider();try{let s=await i.getTransaction(e),c=await this.createFromTransaction(s);return t&&t.ttl&&c&&this.cache.set(r,c,t.ttl),c}catch(s){return E.WarpLogger.error("WarpAbiBuilder: Error creating from transaction hash",s),null}}async getAbiForAction(e){if(e.abi)return await this.fetchAbi(e);if(!e.address)throw new Error("WarpActionExecutor: Address not found");let t=await this.contractLoader.getVerificationInfo(e.address,this.chain);if(!t)throw new Error("WarpActionExecutor: Verification info not found");return F.AbiRegistry.create(t.abi)}async fetchAbi(e){if(!e.abi)throw new Error("WarpActionExecutor: ABI not found");if(e.abi.startsWith(E.WarpConstants.IdentifierType.Hash)){let t=e.abi.split(E.WarpConstants.ArgParamsSeparator)[1],r=await this.createFromTransactionHash(t);if(!r)throw new Error(`WarpActionExecutor: ABI not found for hash: ${e.abi}`);return F.AbiRegistry.create(r.content)}else{let r=await(await fetch(e.abi)).json();return F.AbiRegistry.create(r)}}};var Q=require("@multiversx/sdk-core"),$=require("@vleap/warps"),Me=require("buffer");var me=class{constructor(e,t){this.config=e;this.chain=t;this.core=new $.WarpBrandBuilder(e)}async createInscriptionTransaction(e){let t=(0,$.getWarpWalletAddressFromConfig)(this.config,this.chain.name);if(!t)throw new Error("BrandBuilder: user address not set");let r=new Q.TransactionsFactoryConfig({chainID:this.chain.chainId}),n=new Q.TransferTransactionsFactory({config:r}),i=Q.Address.newFromBech32(t),s=JSON.stringify(e);return await n.createTransactionForNativeTokenTransfer(i,{receiver:Q.Address.newFromBech32(t),nativeAmount:BigInt(0),data:Uint8Array.from(Me.Buffer.from(s))})}async createFromTransaction(e,t=!1){let r=await this.core.createFromRaw(e.data.toString(),t);return r.meta={query:null,chain:this.chain.name,identifier:(0,$.createWarpIdentifier)(this.chain.name,"hash",e.hash),hash:e.hash,creator:e.sender.toBech32(),createdAt:new Date(e.timestamp*1e3).toISOString()},r}async createFromTransactionHash(e){let r=C(this.chain,this.config.env,this.config).createNetworkProvider();try{let n=await r.getTransaction(e);return this.createFromTransaction(n)}catch(n){return $.WarpLogger.error("BrandBuilder: Error creating from transaction hash",n),null}}};var X=require("@multiversx/sdk-core"),B=require("@vleap/warps");var de=class extends B.WarpBuilder{constructor(t,r){super(t);this.config=t;this.chain=r;this.cache=new B.WarpCache(t.cache?.type),this.core=new B.WarpBuilder(t)}async createInscriptionTransaction(t){let r=(0,B.getWarpWalletAddressFromConfig)(this.config,this.chain.name);if(!r)throw new Error("WarpBuilder: user address not set");let n=new X.TransactionsFactoryConfig({chainID:this.chain.chainId}),i=new X.TransferTransactionsFactory({config:n}),s=X.Address.newFromBech32(r),c=JSON.stringify(t),l=await i.createTransactionForTransfer(s,{receiver:X.Address.newFromBech32(r),nativeAmount:BigInt(0),data:Uint8Array.from(Buffer.from(c))});return l.gasLimit=l.gasLimit+BigInt(2e6),l}async createFromTransaction(t,r=!1){let n=await this.core.createFromRaw(t.data.toString(),r);return n.meta={chain:this.chain.name,identifier:(0,B.createWarpIdentifier)(this.chain.name,"hash",t.hash),query:null,hash:t.hash,creator:t.sender.toBech32(),createdAt:new Date(t.timestamp*1e3).toISOString()},n}async createFromTransactionHash(t,r){let n=B.WarpCacheKey.Warp(this.config.env,t);if(r){let c=this.cache.get(n);if(c)return B.WarpLogger.info(`WarpBuilder (createFromTransactionHash): Warp found in cache: ${t}`),c}let s=C(this.chain,this.config.env,this.config).createNetworkProvider();try{let c=await s.getTransaction(t),l=await this.createFromTransaction(c);return r&&r.ttl&&l&&this.cache.set(n,l,r.ttl),l}catch(c){return B.WarpLogger.error("WarpBuilder: Error creating from transaction hash",c),null}}};var H=require("@multiversx/sdk-core"),re=require("@vleap/warps");var Pe=require("@vleap/warps");var De=require("@vleap/warps"),Re=De.WarpChainName.Multiversx,Le=[{chain:Re,identifier:"EGLD",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"},{chain:Re,identifier:"EGLD-000000",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"}];var Ke=require("@vleap/warps"),P=Ke.WarpChainName.Multiversx,_e=[{chain:P,identifier:"EGLD",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"},{chain:P,identifier:"EGLD-000000",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"},{chain:P,identifier:"SEGLD-3ad2d0",name:"StakedEGLD",symbol:"SEGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/SEGLD-3ad2d0/icon.png"},{chain:P,identifier:"HSEGLD-c13a4e",name:"HatomSEGLD",symbol:"HSEGLD",decimals:8,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/HSEGLD-c13a4e/icon.png"},{chain:P,identifier:"UTK-2f80e9",name:"xMoney UTK",symbol:"UTK",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/UTK-2f80e9/icon.png"},{chain:P,identifier:"USDC-c76f1f",name:"WrappedUSDC",symbol:"USDC",decimals:6,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/USDC-c76f1f/icon.png"},{chain:P,identifier:"WEGLD-bd4d79",name:"WrappedEGLD",symbol:"WEGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/WEGLD-bd4d79/icon.png"},{chain:P,identifier:"HTM-f51d55",name:"Hatom",symbol:"HTM",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/HTM-f51d55/icon.png"},{chain:P,identifier:"MEX-455c57",name:"MEX",symbol:"MEX",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/MEX-455c57/icon.png"},{chain:P,identifier:"WTAO-4f5363",name:"WrappedTAO",symbol:"WTAO",decimals:9,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/WTAO-4f5363/icon.png"},{chain:P,identifier:"HEGLD-d61095",name:"HatomEGLD",symbol:"HEGLD",decimals:8,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/HEGLD-d61095/icon.png"},{chain:P,identifier:"WBTC-5349b3",name:"WrappedBTC",symbol:"WBTC",decimals:8,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/WBTC-5349b3/icon.png"},{chain:P,identifier:"WETH-b4ca29",name:"WrappedETH",symbol:"WETH",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/WETH-b4ca29/icon.png"},{chain:P,identifier:"USH-111e09",name:"HatomUSD",symbol:"USH",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/USH-111e09/icon.png"},{chain:P,identifier:"USDT-f8c08c",name:"WrappedUSDT",symbol:"USDT",decimals:6,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/USDT-f8c08c/icon.png"}];var He=require("@vleap/warps"),$e=He.WarpChainName.Multiversx,Ge=[{chain:$e,identifier:"EGLD",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"},{chain:$e,identifier:"EGLD-000000",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"}];var qe=require("@vleap/warps"),ze=qe.WarpChainName.Vibechain,Te=[{chain:ze,identifier:"VIBE",name:"VIBE",symbol:"VIBE",decimals:18,logoUrl:"https://joai.ai/images/tokens/vibe.svg"},{chain:ze,identifier:"VIBE-000000",name:"VIBE",symbol:"VIBE",decimals:18,logoUrl:"https://joai.ai/images/tokens/vibe.svg"}];var Ie={[Pe.WarpChainName.Multiversx]:{mainnet:_e,testnet:Ge,devnet:Le},[Pe.WarpChainName.Vibechain]:{mainnet:Te,testnet:Te,devnet:Te}},Se=(o,e,t)=>(Ie[o]?.[e]||[]).find(n=>n.identifier===t)||null,ct=(o,e)=>Ie[o]?.[e]||[];var he=class{constructor(e,t){this.config=e;this.chain=t;this.cache=new re.WarpCache(e.cache?.type)}async getAccount(e){let r=await C(this.chain,this.config.env,this.config).createNetworkProvider().getAccount(H.Address.newFromBech32(e));return{chain:this.chain.name,address:r.address.toBech32(),balance:r.balance}}async getAccountAssets(e){let t=C(this.chain,this.config.env,this.config).createNetworkProvider(),r=t.getAccount(H.Address.newFromBech32(e)),n=t.getFungibleTokensOfAccount(H.Address.newFromBech32(e)),[i,s]=await Promise.all([r,n]),c=i.balance>0?[{...this.chain.nativeToken,amount:i.balance}]:[];return c.push(...s.map(l=>({chain:this.chain.name,identifier:l.token.identifier,name:l.raw.name,symbol:l.raw.ticker,amount:l.amount,decimals:l.raw.decimals,logoUrl:l.raw.assets?.pngUrl||"",price:l.raw.price?Number(l.raw.price):void 0,supply:l.raw.supply?BigInt(l.raw.supply):void 0}))),c}async getAsset(e){let t=re.WarpCacheKey.Asset(this.config.env,this.chain.name,e),r=this.cache.get(t);if(r)return r;let n=Se(this.chain.name,this.config.env,e);if(n)return{chain:this.chain.name,identifier:e,name:n.name,symbol:n.symbol,amount:0n,decimals:n.decimals,logoUrl:n.logoUrl};let i=new H.TokenComputer,s=j(e)?0n:i.extractNonceFromExtendedIdentifier(e),c=new H.Token({identifier:e,nonce:BigInt(s||0)}),l=i.isFungible(c),f=C(this.chain,this.config.env,this.config).createNetworkProvider(),g=pe(e),d=await f.doGetGeneric(`tokens/${g}`),T={chain:this.chain.name,identifier:c.identifier,name:d.name,symbol:d.ticker,amount:0n,decimals:d.decimals,logoUrl:d.assets?.pngUrl||null,price:d.price?Number(d.price):void 0,supply:d.supply?BigInt(d.supply):void 0};return this.cache.set(t,T,re.CacheTtl.OneHour),T}async getAction(e,t=!1){let r=C(this.chain,this.config.env,this.config),n=t?await r.awaitCompletedTransaction(e):await r.getTransaction(e);return{chain:this.chain.name,id:n.hash,receiver:n.receiver.toBech32(),sender:n.sender.toBech32(),value:n.value,function:n.function,status:this.toActionStatus(n),createdAt:this.toActionCreatedAt(n),error:n?.smartContractResults.map(i=>i.raw.returnMessage)[0]||null,tx:n}}async getAccountActions(e,t){let r=C(this.chain,this.config.env,this.config).createNetworkProvider(),n=`accounts/${e}/transactions`,i=new URLSearchParams,s=t?.size||25,c=t?.page||0;if(c>0){let f=c*s;i.append("from",f.toString())}return s!==25&&i.append("size",s.toString()),i.toString()&&(n+=`?${i.toString()}`),(await r.doGetGeneric(n)).map(f=>({chain:this.chain.name,id:f.txHash,receiver:f.receiver,sender:f.sender,value:f.value,function:f.function,status:this.toActionStatus(f),createdAt:this.toActionCreatedAt(f)}))}toActionStatus(e){return e.status.isSuccessful()?"success":e.status.isFailed()?"failed":"pending"}toActionCreatedAt(e){return new Date(e.timestamp||e.timestamp*1e3).toISOString()}};var A=require("@multiversx/sdk-core"),N=require("@vleap/warps");var ne=require("@multiversx/sdk-core"),w=require("@vleap/warps");var a=require("@multiversx/sdk-core"),Xe=require("@vleap/warps");var h={HttpProtocolPrefix:"http",IdentifierParamName:"warp",IdentifierParamSeparator:":",IdentifierChainDefault:"multiversx",IdentifierType:{Alias:"alias",Hash:"hash"},IdentifierAliasMarker:"@",Globals:{UserWallet:{Placeholder:"USER_WALLET",Accessor:o=>o.config.user?.wallets?.[o.adapter.chainInfo.name]},UserWalletPublicKey:{Placeholder:"USER_WALLET_PUBLICKEY",Accessor:o=>{if(!o.adapter.wallet)return null;try{return o.adapter.wallet.getPublicKey()||null}catch{return null}}},ChainApiUrl:{Placeholder:"CHAIN_API",Accessor:o=>o.adapter.chainInfo.defaultApiUrl},ChainAddressHrp:{Placeholder:"CHAIN_ADDRESS_HRP",Accessor:o=>o.adapter.chainInfo.addressHrp}},Vars:{Query:"query",Env:"env"},ArgParamsSeparator:":",ArgCompositeSeparator:"|",ArgListSeparator:",",ArgStructSeparator:";",Transform:{Prefix:"transform:"},Source:{UserWallet:"user:wallet"},Position:{Payload:"payload:"},Alerts:{TriggerEventPrefix:"event"}},u={Option:"option",Vector:"vector",Tuple:"tuple",Struct:"struct",String:"string",Uint8:"uint8",Uint16:"uint16",Uint32:"uint32",Uint64:"uint64",Uint128:"uint128",Uint256:"uint256",Biguint:"biguint",Bool:"bool",Address:"address",Asset:"asset",Hex:"hex"};var lt={Egld:{Identifier:"EGLD",EsdtIdentifier:"EGLD-000000",DisplayName:"eGold",Decimals:18}},v={Null:"null",Optional:"optional",List:"list",Token:"token",CodeMeta:"codemeta"},je=(r=>(r.MultiversxExplorer="multiversx_explorer",r.MultiversxExplorerDevnet="multiversx_explorer_devnet",r.MultiversxExplorerTestnet="multiversx_explorer_testnet",r))(je||{}),Qe=(r=>(r.VibechainExplorer="vibechain_explorer",r.VibechainExplorerDevnet="vibechain_explorer_devnet",r.VibechainExplorerTestnet="vibechain_explorer_testnet",r))(Qe||{}),Be={multiversx:{mainnet:["multiversx_explorer"],testnet:["multiversx_explorer_testnet"],devnet:["multiversx_explorer_devnet"]},vibechain:{mainnet:["vibechain_explorer"],testnet:["vibechain_explorer_testnet"],devnet:["vibechain_explorer_devnet"]}},G={multiversx_explorer:"https://explorer.multiversx.com",multiversx_explorer_devnet:"https://devnet-explorer.multiversx.com",multiversx_explorer_testnet:"https://testnet-explorer.multiversx.com",vibechain_explorer:"https://vibeox-explorer.multiversx.com",vibechain_explorer_devnet:"https://vibeox-explorer.multiversx.com",vibechain_explorer_testnet:"https://vibeox-explorer.multiversx.com"};var pt=new RegExp(`${h.ArgParamsSeparator}(.*)`),L=class{constructor(e){this.coreSerializer=new Xe.WarpSerializer(e)}typedToString(e){let t=e.getType();if(t.hasExactClass(a.OptionType.ClassName)||e.hasClassOrSuperclass(a.OptionValue.ClassName)){if(!e.isSet())return u.Option+h.ArgParamsSeparator+"null";let r=this.typedToString(e.getTypedValue());return u.Option+h.ArgParamsSeparator+r}if(t.hasExactClass(a.VariadicType.ClassName)||e.hasClassOrSuperclass(a.VariadicValue.ClassName)){let r=e.getItems();if(r.length===0){let g=this.typeToString(t.getFirstTypeParameter());return u.Vector+h.ArgParamsSeparator+g+h.ArgParamsSeparator}let n=r.map(g=>this.typedToString(g));if(n.every(g=>g.startsWith(u.Tuple)))return u.Vector+h.ArgParamsSeparator+n.join(",");let i=n[0],s=i.indexOf(h.ArgParamsSeparator),c=i.substring(0,s),l=n.map(g=>{let d=g.indexOf(h.ArgParamsSeparator);return g.substring(d+1)}),f=c.startsWith(u.Struct)?h.ArgStructSeparator:h.ArgListSeparator;return u.Vector+h.ArgParamsSeparator+c+h.ArgParamsSeparator+l.join(f)}if(t.hasExactClass(a.OptionalType.ClassName)||e.hasClassOrSuperclass(a.OptionalValue.ClassName)){if(!e.isSet())return v.Optional+h.ArgParamsSeparator+"null";let r=this.typedToString(e.getTypedValue());return v.Optional+h.ArgParamsSeparator+r}if(t.hasExactClass(a.ListType.ClassName)||e.hasClassOrSuperclass(a.List.ClassName)){let n=e.getItems().map(l=>this.typedToString(l));if(n.every(l=>l.startsWith(u.Tuple)))return v.List+h.ArgParamsSeparator+n.join(",");let s=n.map(l=>l.split(h.ArgParamsSeparator)[0])[0],c=n.map(l=>l.split(h.ArgParamsSeparator)[1]);return v.List+h.ArgParamsSeparator+s+h.ArgParamsSeparator+c.join(h.ArgListSeparator)}if(t.hasExactClass(a.CompositeType.ClassName)||e.hasClassOrSuperclass(a.CompositeValue.ClassName)){let n=e.getItems().map(i=>{let s=this.typedToString(i),c=s.indexOf(h.ArgParamsSeparator),l=s.substring(0,c),f=s.substring(c+1);return`${l},${f}`});return`${u.Tuple}(${n.join(",")})`}if(t.hasExactClass(a.BigUIntType.ClassName)||e.hasClassOrSuperclass(a.BigUIntValue.ClassName)||t.getName()==="BigUint")return u.Biguint+h.ArgParamsSeparator+BigInt(e.valueOf().toFixed());if(t.hasExactClass(a.U8Type.ClassName)||e.hasClassOrSuperclass(a.U8Value.ClassName))return u.Uint8+h.ArgParamsSeparator+e.valueOf().toNumber();if(t.hasExactClass(a.U16Type.ClassName)||e.hasClassOrSuperclass(a.U16Value.ClassName))return u.Uint16+h.ArgParamsSeparator+e.valueOf().toNumber();if(t.hasExactClass(a.U32Type.ClassName)||e.hasClassOrSuperclass(a.U32Value.ClassName))return u.Uint32+h.ArgParamsSeparator+e.valueOf().toNumber();if(t.hasExactClass(a.U64Type.ClassName)||e.hasClassOrSuperclass(a.U64Value.ClassName))return u.Uint64+h.ArgParamsSeparator+BigInt(e.valueOf().toFixed());if(t.hasExactClass(a.StringType.ClassName)||e.hasClassOrSuperclass(a.StringValue.ClassName))return u.String+h.ArgParamsSeparator+e.valueOf();if(t.hasExactClass(a.BooleanType.ClassName)||e.hasClassOrSuperclass(a.BooleanValue.ClassName))return u.Bool+h.ArgParamsSeparator+e.valueOf();if(t.hasExactClass(a.AddressType.ClassName)||e.hasClassOrSuperclass(a.AddressValue.ClassName))return u.Address+h.ArgParamsSeparator+e.valueOf().toBech32();if(t.hasExactClass(a.BytesType.ClassName)||e.hasClassOrSuperclass(a.BytesValue.ClassName))return u.Hex+h.ArgParamsSeparator+e.valueOf().toString("hex");if(t.getName()==="EsdtTokenPayment"){let r=e.getFieldValue("token_identifier").valueOf(),n=e.getFieldValue("token_nonce").valueOf(),i=e.getFieldValue("amount").valueOf(),c=new a.TokenComputer().computeExtendedIdentifier(new a.Token({identifier:r,nonce:BigInt(n)}));return u.Asset+h.ArgParamsSeparator+c+h.ArgCompositeSeparator+i}if(t.hasExactClass(a.StructType.ClassName)||e.hasClassOrSuperclass(a.Struct.ClassName)){let r=e,i=r.getType().getName(),s=r.getFields();if(s.length===0)return`${u.Struct}(${i})${h.ArgParamsSeparator}`;let c=s.map(l=>{let f=l.value.getType(),d=this.typedToString(l.value).split(h.ArgParamsSeparator),T=d.length>2?d.slice(2).join(h.ArgParamsSeparator):d[1]||"";return`(${l.name}${h.ArgParamsSeparator}${this.typeToString(f)})${T}`});return`${u.Struct}(${i})${h.ArgParamsSeparator}${c.join(h.ArgListSeparator)}`}if(t.hasExactClass(a.TokenIdentifierType.ClassName)||e.hasClassOrSuperclass(a.TokenIdentifierValue.ClassName))return v.Token+h.ArgParamsSeparator+e.valueOf();if(t.hasExactClass(a.CodeMetadataType.ClassName)||e.hasClassOrSuperclass(a.CodeMetadataValue.ClassName))return v.CodeMeta+h.ArgParamsSeparator+e.valueOf().toString();throw new Error(`WarpArgSerializer (typedToString): Unsupported input type: ${e.getClassName()}`)}typedToNative(e){let t=this.typedToString(e);return this.coreSerializer.stringToNative(t)}nativeToTyped(e,t){if(e.startsWith(u.Tuple))return this.stringToTyped(e+":");let r=this.coreSerializer.nativeToString(e,t);return this.stringToTyped(r)}nativeToType(e){if(e.startsWith(u.Tuple)){let t=e.match(/\(([^)]+)\)/)?.[1];if(!t)throw new Error(`Invalid tuple type format: ${e}`);let r=t.split(","),n=[];for(let i=0;i<r.length;i+=2)n.push(r[i]);return new a.CompositeType(...n.map(i=>this.nativeToType(i)))}if(e.startsWith(u.Struct)){let t=e.match(/\(([^)]+)\)/);if(!t)throw new Error("Struct type must include a name in the format struct(Name)");let r=t[1];return new a.StructType(r,[])}if(e===u.String)return new a.StringType;if(e===u.Uint8)return new a.U8Type;if(e===u.Uint16)return new a.U16Type;if(e===u.Uint32)return new a.U32Type;if(e===u.Uint64)return new a.U64Type;if(e===u.Biguint)return new a.BigUIntType;if(e===u.Bool)return new a.BooleanType;if(e===u.Address)return new a.AddressType;if(e===u.Hex)return new a.BytesType;if(e===u.Asset)return new a.StructType("EsdtTokenPayment",[new a.FieldDefinition("token_identifier","",new a.TokenIdentifierType),new a.FieldDefinition("token_nonce","",new a.U64Type),new a.FieldDefinition("amount","",new a.BigUIntType)]);if(e===v.Token)return new a.TokenIdentifierType;if(e===v.CodeMeta)return new a.CodeMetadataType;throw new Error(`WarpArgSerializer (nativeToType): Unsupported input type: ${e}`)}stringToTyped(e){let[t,r]=e.split(/:(.*)/,2);if(t===u.Option){let n=this.stringToTyped(r);return n instanceof a.NothingValue?a.OptionValue.newMissingTyped(n.getType()):a.OptionValue.newProvided(n)}if(t===u.Vector){let n=r.indexOf(h.ArgParamsSeparator),i=r.substring(0,n),s=r.substring(n+1);if(i.startsWith(u.Tuple)){let d=s.split(",").map(T=>this.stringToTyped(T));return new a.VariadicValue(new a.VariadicType(this.nativeToType(i)),d)}if(s.includes("tuple(")){let g=this.splitTupleStrings(s),d=g.map(x=>this.stringToTyped(x)),b=g[0].match(/^(tuple\([^)]+\))/),y=b?b[1]:"tuple";return new a.VariadicValue(new a.VariadicType(this.nativeToType(y)),d)}let c=i.startsWith(u.Struct)?h.ArgStructSeparator:h.ArgListSeparator,f=s.split(c).map(g=>this.stringToTyped(`${i}:${g}`));return new a.VariadicValue(new a.VariadicType(this.nativeToType(i)),f)}if(t.startsWith(u.Tuple)){let n=t.match(/\(([^)]+)\)/)?.[1];if(!n)throw new Error(`Invalid tuple format: ${t}`);let i=n.split(","),s=[];for(let l=0;l<i.length;l+=2){let f=i[l],g=i[l+1];s.push(this.stringToTyped(`${f}:${g}`))}let c=s.map(l=>l.getType());return new a.CompositeValue(new a.CompositeType(...c),s)}if(t.startsWith(u.Struct)){let n=t.match(/\(([^)]+)\)/),i=n?n[1]:"CustomStruct";if(!r)return new a.Struct(new a.StructType(i,[]),[]);let s=r.split(h.ArgListSeparator),c=[],l=[];return s.forEach(f=>{let g=f.match(new RegExp(`^\\(([^${h.ArgParamsSeparator}]+)${h.ArgParamsSeparator}([^)]+)\\)(.+)$`));if(g){let[,d,T,b]=g,y=this.stringToTyped(`${T}${h.ArgParamsSeparator}${b}`);c.push(new a.FieldDefinition(d,"",y.getType())),l.push(new a.Field(y,d))}}),new a.Struct(new a.StructType(i,c),l)}if(t===u.String)return r?a.StringValue.fromUTF8(r):new a.NothingValue;if(t===u.Uint8)return r?new a.U8Value(Number(r)):new a.NothingValue;if(t===u.Uint16)return r?new a.U16Value(Number(r)):new a.NothingValue;if(t===u.Uint32)return r?new a.U32Value(Number(r)):new a.NothingValue;if(t===u.Uint64)return r?new a.U64Value(BigInt(r)):new a.NothingValue;if(t===u.Biguint)return r?new a.BigUIntValue(BigInt(r)):new a.NothingValue;if(t===u.Bool)return r?new a.BooleanValue(typeof r=="boolean"?r:r==="true"):new a.NothingValue;if(t===u.Address)return r?new a.AddressValue(a.Address.newFromBech32(r)):new a.NothingValue;if(t===u.Hex)return r?a.BytesValue.fromHex(r):new a.NothingValue;if(t===u.Asset){let[n,i]=r.split(h.ArgCompositeSeparator),s=new a.TokenComputer,c=j(n)?pe(n):s.extractIdentifierFromExtendedIdentifier(n),l=j(n)?0n:s.extractNonceFromExtendedIdentifier(n);return new a.Struct(this.nativeToType("asset"),[new a.Field(new a.TokenIdentifierValue(c),"token_identifier"),new a.Field(new a.U64Value(BigInt(l)),"token_nonce"),new a.Field(new a.BigUIntValue(BigInt(i)),"amount")])}if(t===v.Null)return new a.NothingValue;if(t===v.Optional){let n=this.stringToTyped(r);return n instanceof a.NothingValue?a.OptionalValue.newMissing():new a.OptionalValue(n.getType(),n)}if(t===v.List){let[n,i]=r.split(pt,2),c=i.split(h.ArgListSeparator).map(l=>this.stringToTyped(n+h.ArgParamsSeparator+l));return new a.List(this.nativeToType(n),c)}if(t===v.Token)return r?new a.TokenIdentifierValue(r):new a.NothingValue;if(t===v.CodeMeta)return new a.CodeMetadataValue(a.CodeMetadata.newFromBytes(Uint8Array.from(Buffer.from(r,"hex"))));throw new Error(`WarpArgSerializer (stringToTyped): Unsupported input type: ${t}`)}splitTupleStrings(e){let t=[],r="",n=0;for(let i=0;i<e.length;i++){let s=e[i];if(s==="(")n++;else if(s===")")n--;else if(s===","&&n===0){t.push(r.trim()),r="";continue}r+=s}return r.trim()&&t.push(r.trim()),t}typeToString(e){if(e.hasExactClass(a.OptionType.ClassName))return u.Option+h.ArgParamsSeparator+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(a.VariadicType.ClassName))return u.Vector+h.ArgParamsSeparator+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(a.StringType.ClassName))return u.String;if(e.hasExactClass(a.U8Type.ClassName))return u.Uint8;if(e.hasExactClass(a.U16Type.ClassName))return u.Uint16;if(e.hasExactClass(a.U32Type.ClassName))return u.Uint32;if(e.hasExactClass(a.U64Type.ClassName))return u.Uint64;if(e.hasExactClass(a.BigUIntType.ClassName))return u.Biguint;if(e.hasExactClass(a.BooleanType.ClassName))return u.Bool;if(e.hasExactClass(a.AddressType.ClassName))return u.Address;if(e.hasExactClass(a.BytesType.ClassName))return u.Hex;if(e.hasExactClass(a.TokenIdentifierType.ClassName))return v.Token;if(e.hasExactClass(a.OptionalType.ClassName))return v.Optional+h.ArgParamsSeparator+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(a.ListType.ClassName))return v.List+h.ArgParamsSeparator+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(a.CodeMetadataType.ClassName))return v.CodeMeta;if(e.hasExactClass(a.StructType.ClassName)&&e.getClassName()==="EsdtTokenPayment")return u.Asset;if(e.hasExactClass(a.StructType.ClassName))return`${u.Struct}(${e.getName()})`;throw new Error(`WarpArgSerializer (typeToString): Unsupported input type: ${e.getClassName()}`)}};var J=class{constructor(e,t,r){this.config=e;this.chain=t;this.typeRegistry=r;this.abi=new D(e,t),this.serializer=new L({typeRegistry:this.typeRegistry}),this.cache=new w.WarpCache(e.cache?.type)}async getActionExecution(e,t,r){let n=this.cache.get(w.WarpCacheKey.WarpExecutable(this.config.env,e.meta?.hash||"",t))??[],i=await this.extractContractOutput(e,t,r,n),s=(0,w.getNextInfo)(this.config,[],e,t,i.output),c=(0,w.applyOutputToMessages)(e,i.output,this.config),l=(0,w.extractResolvedInputValues)(n);return{status:r.status.isSuccessful()?"success":"error",warp:e,action:t,user:(0,w.getWarpWalletAddressFromConfig)(this.config,this.chain.name),txHash:r.hash,tx:r,next:s,values:i.values,output:i.output,messages:c,destination:null,resolvedInputs:l}}async extractContractOutput(e,t,r,n){let i=(0,w.getWarpActionByIndex)(e,t),s=[],c=[],l={};if(!e.output||i.type!=="contract")return{values:{string:s,native:c,mapped:{}},output:l};if(!Object.values(e.output).some(y=>y.includes("out")||y.includes("event"))){for(let[y,x]of Object.entries(e.output))l[y]=x;return{values:{string:s,native:c,mapped:{}},output:await(0,w.evaluateOutputCommon)(e,l,t,n,this.serializer.coreSerializer,this.config)}}let g=await this.abi.getAbiForAction(i),d=new ne.TransactionEventsParser({abi:g}),b=new ne.SmartContractTransactionsOutcomeParser({abi:g}).parseExecute({transactionOnNetwork:r,function:i.func||void 0});for(let[y,x]of Object.entries(e.output)){if(x.startsWith(w.WarpConstants.Transform.Prefix))continue;if(x.startsWith("input.")){l[y]=x;continue}let S=(0,w.parseOutputOutIndex)(x);if(S!==null&&S!==t){l[y]=null;continue}let[k,z,q]=x.split(".");if(k==="event"){if(!z||isNaN(Number(q)))continue;let _=Number(q),W=(0,ne.findEventsByFirstTopic)(r,z),et=d.parseEvents({events:W})[0],le=Object.values(et)[_]||null;s.push(String(le)),c.push(le),l[y]=le&&le.valueOf()}else if(k==="out"||k.startsWith("out[")){if(!z)continue;let _=Number(z),W=b.values[_-1]||null;q&&(W=W[q]||null),W&&typeof W=="object"&&(W="toFixed"in W?W.toFixed():W.valueOf()),s.push(String(W)),c.push(W),l[y]=W&&W.valueOf()}else l[y]=x}return{values:{string:s,native:c,mapped:{}},output:await(0,w.evaluateOutputCommon)(e,l,t,n,this.serializer.coreSerializer,this.config)}}async extractQueryOutput(e,t,r,n){let i=t.map(g=>this.serializer.typedToString(g)),s=t.map(g=>this.serializer.typedToNative(g)[1]),c={string:i,native:s,mapped:{}},l={};if(!e.output)return{values:c,output:l};let f=g=>{let d=g.split(".").slice(1).map(b=>parseInt(b)-1);if(d.length===0)return;let T=s[d[0]];for(let b=1;b<d.length;b++){if(T==null)return;T=T[d[b]]}return T};for(let[g,d]of Object.entries(e.output)){if(d.startsWith(w.WarpConstants.Transform.Prefix))continue;let T=(0,w.parseOutputOutIndex)(d);if(T!==null&&T!==r){l[g]=null;continue}d.startsWith("out.")||d==="out"||d.startsWith("out[")?l[g]=f(d)||null:l[g]=d}return l=await(0,w.evaluateOutputCommon)(e,l,r,n,this.serializer.coreSerializer,this.config),{values:c,output:l}}async resolveWarpOutputRecursively(e){let t=e.warp,r=e.entryActionIndex,n=e.executor,i=e.inputs,s=e.meta,c=new Map,l=new Set,f=this;async function g(y,x=[]){if(c.has(y))return c.get(y);if(l.has(y))throw new Error(`Circular dependency detected at action ${y}`);l.add(y);let S=t.actions[y-1];if(!S)throw new Error(`Action ${y} not found`);let k;if(S.type==="query")k=await n.executeQuery(t,y,x);else if(S.type==="collect")k=await n.executeCollect(t,y,x,s);else throw new Error(`Unsupported or interactive action type: ${S.type}`);if(c.set(y,k),t.output)for(let z of Object.values(t.output)){let _=String(z).match(/^out\[(\d+)\]/);if(_){let W=parseInt(_[1],10);W!==y&&!c.has(W)&&await g(W)}}return l.delete(y),k}await g(r,i);let d={};for(let y of c.values())for(let[x,S]of Object.entries(y.output))S!==null?d[x]=S:x in d||(d[x]=null);let T=await(0,w.evaluateOutputCommon)(t,d,r,i,this.serializer.coreSerializer,this.config);return{...c.get(r),action:r,output:T}}};var ut="EGLD-000000",ge=class{constructor(e,t,r){this.config=e;this.chain=t;this.typeRegistry=r;this.serializer=new L({typeRegistry:this.typeRegistry}),this.abi=new D(this.config,this.chain),this.output=new J(this.config,this.chain,this.typeRegistry)}async createTransaction(e){let t=(0,N.getWarpActionByIndex)(e.warp,e.action),r=null;if(t.type==="transfer")r=await this.createTransferTransaction(e);else if(t.type==="contract")r=await this.createContractCallTransaction(e);else{if(t.type==="query")throw new Error("WarpMultiversxExecutor: Invalid action type for createTransactionForExecute; Use executeQuery instead");if(t.type==="collect")throw new Error("WarpMultiversxExecutor: Invalid action type for createTransactionForExecute; Use executeCollect instead")}if(!r)throw new Error(`WarpMultiversxExecutor: Invalid action type (${t.type})`);return r}async createTransferTransaction(e){if(!e.destination)throw new Error("WarpMultiversxExecutor: createTransfer - destination not set");let t=(0,N.getWarpWalletAddressFromConfig)(this.config,e.chain.name);if(!t)throw new Error("WarpMultiversxExecutor: createTransfer - user address not set");let r=A.Address.newFromBech32(t),n=new A.TransactionsFactoryConfig({chainID:e.chain.chainId}),i=e.data?Buffer.from(this.serializer.stringToTyped(e.data).valueOf()):null,s=e.transfers.length===1&&e.transfers[0].identifier===this.chain.nativeToken?.identifier,l=(s?e.transfers[0].amount:0n)+e.value;return await new A.TransferTransactionsFactory({config:n}).createTransactionForTransfer(r,{receiver:A.Address.newFromBech32(e.destination),nativeAmount:l,tokenTransfers:s?[]:this.toTokenTransfers(e.transfers),data:i?new Uint8Array(i):void 0})}async createContractCallTransaction(e){if(!e.destination)throw new Error("WarpMultiversxExecutor: createContractCall - destination not set");let t=(0,N.getWarpWalletAddressFromConfig)(this.config,e.chain.name);if(!t)throw new Error("WarpMultiversxExecutor: createContractCall - user address not set");let r=(0,N.getWarpActionByIndex)(e.warp,e.action),n=A.Address.newFromBech32(t),i=e.args.map(c=>this.serializer.stringToTyped(c)),s=new A.TransactionsFactoryConfig({chainID:e.chain.chainId});return new A.SmartContractTransactionsFactory({config:s}).createTransactionForExecute(n,{contract:A.Address.newFromBech32(e.destination),function:"func"in r&&r.func||"",gasLimit:"gasLimit"in r?BigInt(r.gasLimit||0):0n,arguments:i,tokenTransfers:this.toTokenTransfers(e.transfers),nativeTransferAmount:e.value})}async executeQuery(e){if(!e.destination)throw new Error("WarpMultiversxExecutor: executeQuery - destination not set");let t=(0,N.getWarpActionByIndex)(e.warp,e.action);if(t.type!=="query")throw new Error(`WarpMultiversxExecutor: Invalid action type for executeQuery: ${t.type}`);let r=await this.abi.getAbiForAction(t),n=e.args.map(W=>this.serializer.stringToTyped(W)),i=C(e.chain,this.config.env,this.config),s=A.Address.newFromBech32(e.destination),c=i.createSmartContractController(r),l=c.createQuery({contract:s,function:t.func||"",arguments:n}),f=await c.runQuery(l),g=f.returnCode==="ok",d=new A.ArgSerializer,T=r.getEndpoint(f.function||t.func||""),b=(f.returnDataParts||[]).map(W=>Buffer.from(W)),y=d.buffersToValues(b,T.output),{values:x,output:S}=await this.output.extractQueryOutput(e.warp,y,e.action,e.resolvedInputs),k=(0,N.getNextInfo)(this.config,[],e.warp,e.action,S),q=e.resolvedInputs.find(W=>W.input.position==="receiver"||W.input.position==="destination")?.value||e.destination,_=(0,N.extractResolvedInputValues)(e.resolvedInputs);return{status:g?"success":"error",warp:e.warp,action:e.action,user:(0,N.getWarpWalletAddressFromConfig)(this.config,e.chain.name),txHash:null,tx:null,next:k,values:x,output:{...S,_DATA:y},messages:(0,N.applyOutputToMessages)(e.warp,S,this.config),destination:q,resolvedInputs:_}}toTokenTransfers(e){return e.map(t=>t.identifier===this.chain.nativeToken.identifier?{...t,identifier:ut}:t).map(t=>{let n=new A.TokenComputer().extractNonceFromExtendedIdentifier(t.identifier);return new A.TokenTransfer({token:new A.Token({identifier:t.identifier,nonce:BigInt(n||0)}),amount:t.amount})})}};var fe=class{constructor(e,t){this.chain=e;this.config=t}getExplorers(){let e=Be[this.chain];if(!e)return["multiversx_explorer"];let t=e[this.config.env];return t||["multiversx_explorer"]}getPrimaryExplorer(){return this.getExplorers()[0]}getExplorerUrlByName(e){let t=this.config.preferences?.explorers?.[this.chain];if(t&&!e){let i=G[t];if(i)return i}if(e){let i=G[e];if(i)return i}let r=this.getPrimaryExplorer();return G[r]||G[r]}getAccountUrl(e,t){return`${this.getExplorerUrlByName(t)}/accounts/${e}`}getTransactionUrl(e,t){return`${this.getExplorerUrlByName(t)}/transactions/${e}`}getBlockUrl(e,t){return`${this.getExplorerUrlByName(t)}/blocks/${e}`}getAssetUrl(e,t){return`${this.getExplorerUrlByName(t)}/tokens/${e}`}getContractUrl(e,t){return`${this.getExplorerUrlByName(t)}/accounts/${e}`}getAllExplorers(){return this.getExplorers()}getExplorerByName(e){return this.getExplorers().find(r=>r.toLowerCase()===e.toLowerCase())}getAccountUrls(e){let t=this.getAllExplorers(),r={};return t.forEach(n=>{let i=G[n];i&&(r[n]=`${i}/accounts/${e}`)}),r}getTransactionUrls(e){let t=this.getAllExplorers(),r={};return t.forEach(n=>{let i=G[n];i&&(r[n]=`${i}/transactions/${e}`)}),r}};var m=require("@multiversx/sdk-core"),V=require("@vleap/warps");var Ne={buildInfo:{rustc:{version:"1.86.0",commitHash:"05f9846f893b09a1be1fc8560e33fc3c815cfecb",commitDate:"2025-03-31",channel:"Stable",short:"rustc 1.86.0 (05f9846f8 2025-03-31)"},contractCrate:{name:"registry",version:"0.0.1"},framework:{name:"multiversx-sc",version:"0.51.1"}},name:"RegistryContract",constructor:{inputs:[{name:"unit_price",type:"BigUint"},{name:"vault",type:"Address"}],outputs:[]},upgradeConstructor:{inputs:[],outputs:[]},endpoints:[{name:"registerWarp",mutability:"mutable",payableInTokens:["EGLD"],inputs:[{name:"hash",type:"bytes"},{name:"alias_opt",type:"optional<bytes>",multi_arg:!0},{name:"brand_opt",type:"optional<bytes>",multi_arg:!0}],outputs:[],allow_multiple_var_args:!0},{name:"unregisterWarp",mutability:"mutable",inputs:[{name:"warp",type:"bytes"}],outputs:[]},{name:"upgradeWarp",mutability:"mutable",payableInTokens:["EGLD"],inputs:[{name:"alias",type:"bytes"},{name:"new_warp",type:"bytes"},{name:"brand_opt",type:"optional<bytes>",multi_arg:!0}],outputs:[]},{name:"setWarpAlias",mutability:"mutable",payableInTokens:["EGLD"],inputs:[{name:"hash",type:"bytes"},{name:"alias",type:"bytes"}],outputs:[]},{name:"forceRemoveAlias",mutability:"mutable",inputs:[{name:"hash",type:"bytes"}],outputs:[]},{name:"verifyWarp",mutability:"mutable",inputs:[{name:"warp",type:"bytes"}],outputs:[]},{name:"transferOwnership",mutability:"mutable",inputs:[{name:"warp",type:"bytes"},{name:"new_owner",type:"Address"}],outputs:[]},{name:"getUserWarps",mutability:"readonly",inputs:[{name:"address",type:"Address"}],outputs:[{type:"variadic<InfoView>",multi_result:!0}]},{name:"getInfoByAlias",mutability:"readonly",inputs:[{name:"alias",type:"bytes"}],outputs:[{type:"InfoView"}]},{name:"getInfoByHash",mutability:"readonly",inputs:[{name:"hash",type:"bytes"}],outputs:[{type:"InfoView"}]},{name:"setVault",onlyOwner:!0,mutability:"mutable",inputs:[{name:"vault",type:"Address"}],outputs:[]},{name:"setUnitPrice",onlyOwner:!0,mutability:"mutable",inputs:[{name:"amount",type:"BigUint"}],outputs:[]},{name:"addAdmin",onlyOwner:!0,mutability:"mutable",inputs:[{name:"address",type:"Address"}],outputs:[]},{name:"removeAdmin",onlyOwner:!0,mutability:"mutable",inputs:[{name:"address",type:"Address"}],outputs:[]},{name:"getConfig",mutability:"readonly",inputs:[],outputs:[{type:"ConfigView"}]},{name:"registerBrand",mutability:"mutable",payableInTokens:["EGLD"],inputs:[{name:"hash",type:"bytes"}],outputs:[]},{name:"brandWarp",mutability:"mutable",payableInTokens:["EGLD"],inputs:[{name:"warp",type:"bytes"},{name:"brand",type:"bytes"}],outputs:[]},{name:"getUserBrands",mutability:"readonly",inputs:[{name:"user",type:"Address"}],outputs:[{type:"variadic<bytes>",multi_result:!0}]}],events:[{identifier:"warpRegistered",inputs:[{name:"hash",type:"bytes",indexed:!0},{name:"alias",type:"bytes",indexed:!0},{name:"trust",type:"bytes",indexed:!0}]},{identifier:"warpUnregistered",inputs:[{name:"hash",type:"bytes",indexed:!0}]},{identifier:"warpUpgraded",inputs:[{name:"alias",type:"bytes",indexed:!0},{name:"new_warp",type:"bytes",indexed:!0},{name:"trust",type:"bytes",indexed:!0}]},{identifier:"warpVerified",inputs:[{name:"hash",type:"bytes",indexed:!0}]},{identifier:"aliasUpdated",inputs:[{name:"hash",type:"bytes",indexed:!0},{name:"alias",type:"bytes",indexed:!0}]},{identifier:"ownershipTransferred",inputs:[{name:"warp",type:"bytes",indexed:!0},{name:"old_owner",type:"Address",indexed:!0},{name:"new_owner",type:"Address",indexed:!0}]}],esdtAttributes:[],hasCallback:!1,types:{ConfigView:{type:"struct",fields:[{name:"unit_price",type:"BigUint"},{name:"admins",type:"List<Address>"}]},InfoView:{type:"struct",fields:[{name:"hash",type:"bytes"},{name:"alias",type:"Option<bytes>"},{name:"trust",type:"bytes"},{name:"owner",type:"Address"},{name:"created_at",type:"u64"},{name:"upgraded_at",type:"u64"},{name:"brand",type:"Option<bytes>"},{name:"upgrade",type:"Option<bytes>"}]}}};var I=o=>{if(o==="devnet")return"erd1qqqqqqqqqqqqqpgqje2f99vr6r7sk54thg03c9suzcvwr4nfl3tsfkdl36";if(o==="testnet")throw new Error("Multiversx testnet is not supported");return"erd1qqqqqqqqqqqqqpgq3mrpj3u6q7tejv6d7eqhnyd27n9v5c5tl3ts08mffe"};var ye=o=>({hash:o.hash.toString("hex"),alias:o.alias?.toString()||null,trust:o.trust.toString(),owner:o.owner.toString(),createdAt:o.created_at.toNumber(),upgradedAt:o.upgraded_at?.toNumber(),brand:o.brand?.toString("hex")||null,upgrade:o.upgrade?.toString("hex")||null}),Ve=o=>({unitPrice:BigInt(o.unit_price.toString()),admins:o.admins.map(e=>e.toBech32())});var We=class{constructor(e,t){this.config=e;this.chain=t;this.cache=new V.WarpCache(e.cache?.type),this.registryConfig={unitPrice:BigInt(0),admins:[]},this.userWallet=(0,V.getWarpWalletAddressFromConfig)(this.config,this.chain.name)}async init(){await this.loadRegistryConfigs()}getRegistryConfig(){return this.registryConfig}async createWarpRegisterTransaction(e,t,r){if(this.registryConfig.unitPrice===BigInt(0))throw new Error("WarpRegistry: config not loaded. forgot to call init()?");if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let n=m.Address.newFromBech32(this.userWallet),i=()=>this.isCurrentUserAdmin()?BigInt(0):t&&r?this.registryConfig.unitPrice*BigInt(3):t?this.registryConfig.unitPrice*BigInt(2):this.registryConfig.unitPrice,s=()=>t&&r?[m.BytesValue.fromHex(e),m.BytesValue.fromUTF8(t),m.BytesValue.fromHex(r)]:t?[m.BytesValue.fromHex(e),m.BytesValue.fromUTF8(t)]:[m.BytesValue.fromHex(e)];return await this.getFactory().createTransactionForExecute(n,{contract:m.Address.newFromBech32(I(this.config.env)),function:"registerWarp",gasLimit:BigInt(1e7),nativeTransferAmount:i(),arguments:s()})}async createWarpUnregisterTransaction(e){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let t=m.Address.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(t,{contract:m.Address.newFromBech32(I(this.config.env)),function:"unregisterWarp",gasLimit:BigInt(1e7),arguments:[m.BytesValue.fromHex(e)]})}async createWarpUpgradeTransaction(e,t,r){if(this.registryConfig.unitPrice===BigInt(0))throw new Error("WarpRegistry: config not loaded. forgot to call init()?");if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let n=m.Address.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(n,{contract:m.Address.newFromBech32(I(this.config.env)),function:"upgradeWarp",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:r?[m.BytesValue.fromUTF8(e),m.BytesValue.fromHex(t),m.BytesValue.fromHex(r)]:[m.BytesValue.fromUTF8(e),m.BytesValue.fromHex(t)]})}async createWarpAliasSetTransaction(e,t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let r=m.Address.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(r,{contract:m.Address.newFromBech32(I(this.config.env)),function:"setWarpAlias",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[m.BytesValue.fromHex(e),m.BytesValue.fromUTF8(t)]})}async createWarpVerifyTransaction(e){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let t=m.Address.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(t,{contract:m.Address.newFromBech32(I(this.config.env)),function:"verifyWarp",gasLimit:BigInt(1e7),arguments:[m.BytesValue.fromHex(e)]})}async createWarpTransferOwnershipTransaction(e,t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let r=m.Address.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(r,{contract:m.Address.newFromBech32(I(this.config.env)),function:"transferOwnership",gasLimit:BigInt(1e7),arguments:[m.BytesValue.fromHex(e),new m.AddressValue(new m.Address(t))]})}async createBrandRegisterTransaction(e){if(this.registryConfig.unitPrice===BigInt(0))throw new Error("WarpRegistry: config not loaded. forgot to call init()?");if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let t=m.Address.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(t,{contract:m.Address.newFromBech32(I(this.config.env)),function:"registerBrand",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[m.BytesValue.fromHex(e)]})}async createWarpBrandingTransaction(e,t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let r=m.Address.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(r,{contract:m.Address.newFromBech32(I(this.config.env)),function:"brandWarp",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[m.BytesValue.fromHex(e),m.BytesValue.fromHex(t)]})}async getInfoByAlias(e,t){try{let r=V.WarpCacheKey.RegistryInfo(this.config.env,e),n=t?this.cache.get(r):null;if(n)return V.WarpLogger.info(`WarpRegistry (getInfoByAlias): RegistryInfo found in cache: ${e}`),n;let i=m.Address.newFromBech32(I(this.config.env)),s=this.getController(),c=s.createQuery({contract:i,function:"getInfoByAlias",arguments:[m.BytesValue.fromUTF8(e)]}),l=await s.runQuery(c),[f]=s.parseQueryResponse(l),g=f?ye(f):null,d=g?.brand?await this.fetchBrand(g.brand):null;return t&&t.ttl&&this.cache.set(r,{registryInfo:g,brand:d},t.ttl),{registryInfo:g,brand:d}}catch{return{registryInfo:null,brand:null}}}async getInfoByHash(e,t){try{let r=V.WarpCacheKey.RegistryInfo(this.config.env,e);if(t){let d=this.cache.get(r);if(d)return V.WarpLogger.info(`WarpRegistry (getInfoByHash): RegistryInfo found in cache: ${e}`),d}let n=m.Address.newFromBech32(I(this.config.env)),i=this.getController(),s=i.createQuery({contract:n,function:"getInfoByHash",arguments:[m.BytesValue.fromHex(e)]}),c=await i.runQuery(s),[l]=i.parseQueryResponse(c),f=l?ye(l):null,g=f?.brand?await this.fetchBrand(f.brand):null;return t&&t.ttl&&this.cache.set(r,{registryInfo:f,brand:g},t.ttl),{registryInfo:f,brand:g}}catch{return{registryInfo:null,brand:null}}}async getUserWarpRegistryInfos(e){try{let t=e||this.userWallet;if(!t)throw new Error("WarpRegistry: user address not set");let r=m.Address.newFromBech32(I(this.config.env)),n=this.getController(),i=n.createQuery({contract:r,function:"getUserWarps",arguments:[new m.AddressValue(new m.Address(t))]}),s=await n.runQuery(i),[c]=n.parseQueryResponse(s);return c.map(ye)}catch{return[]}}async getUserBrands(e){try{let t=e||this.userWallet;if(!t)throw new Error("WarpRegistry: user address not set");let r=m.Address.newFromBech32(I(this.config.env)),n=this.getController(),i=n.createQuery({contract:r,function:"getUserBrands",arguments:[new m.AddressValue(new m.Address(t))]}),s=await n.runQuery(i),[c]=n.parseQueryResponse(s),l=c.map(d=>d.toString("hex")),f={ttl:365*24*60*60};return(await Promise.all(l.map(d=>this.fetchBrand(d,f)))).filter(d=>d!==null)}catch{return[]}}async fetchBrand(e,t){let r=V.WarpCacheKey.Brand(this.config.env,e),n=t?this.cache.get(r):null;if(n)return V.WarpLogger.info(`WarpRegistry (fetchBrand): Brand found in cache: ${e}`),n;let s=C(this.chain,this.config.env,this.config).createNetworkProvider();try{let c=await s.getTransaction(e),l=JSON.parse(c.data.toString());return l.meta={query:null,chain:this.chain.name,identifier:(0,V.createWarpIdentifier)(this.chain.name,"hash",e),hash:c.hash,creator:c.sender.toBech32(),createdAt:new Date(c.timestamp*1e3).toISOString()},t&&t.ttl&&this.cache.set(r,l,t.ttl),l}catch{return null}}async loadRegistryConfigs(){let e=m.Address.newFromBech32(I(this.config.env)),t=this.getController(),[r]=await t.query({contract:e,function:"getConfig",arguments:[]}),n=r?Ve(r):null;this.registryConfig=n||{unitPrice:BigInt(0),admins:[]}}getFactory(){let e=new m.TransactionsFactoryConfig({chainID:this.chain.chainId}),t=m.AbiRegistry.create(Ne);return new m.SmartContractTransactionsFactory({config:e,abi:t})}getController(){let e=C(this.chain,this.config.env,this.config),t=m.AbiRegistry.create(Ne);return e.createSmartContractController(t)}isCurrentUserAdmin(){return!!this.userWallet&&this.registryConfig.admins.includes(this.userWallet)}};var Je=require("@multiversx/sdk-core"),ee=require("@vleap/warps");var O=require("@multiversx/sdk-core"),M=require("@vleap/warps"),Y=class Y{constructor(e,t){this.config=e;this.chain=t;this.account=null}async getAddress(){let e=(0,M.getWarpWalletAddressFromConfig)(this.config,this.chain.name);if(e)return e;try{return this.getAccount().address.toBech32()}catch{return null}}async getPublicKey(){try{return this.getAccount().publicKey.hex()}catch{return null}}async signTransaction(e){return await this.getAccount().signTransaction(e),e}async signMessage(e){let t=this.getAccount(),r=new TextEncoder().encode(e),n=await t.signMessage(new O.Message({data:r}));return Buffer.from(n).toString("hex")}getAccountInstance(){return this.getAccount()}async importFromMnemonic(e){let r=O.Mnemonic.fromString(e).deriveKey(0),n=r.hex(),s=r.generatePublicKey().toAddress(this.chain.addressHrp).toBech32(),c={provider:Y.PROVIDER_NAME,address:s,privateKey:n,mnemonic:e};return(0,M.setWarpWalletInConfig)(this.config,this.chain.name,c),c}async importFromPrivateKey(e){let t=O.UserSecretKey.fromString(e),r=t.hex(),i=t.generatePublicKey().toAddress(this.chain.addressHrp).toBech32(),s={provider:Y.PROVIDER_NAME,address:i,privateKey:r,mnemonic:null};return(0,M.setWarpWalletInConfig)(this.config,this.chain.name,s),s}async export(){let e=this.getAccount(),t=(0,M.getWarpWalletMnemonicFromConfig)(this.config,this.chain.name),r=(0,M.getWarpWalletPrivateKeyFromConfig)(this.config,this.chain.name);return{provider:Y.PROVIDER_NAME,address:e.address.toBech32(),privateKey:r||null,mnemonic:t||null}}async generate(){let e=O.Mnemonic.generate(),t=e.toString(),i=e.deriveKey(0).generatePublicKey().toAddress(this.chain.addressHrp).toBech32();return{provider:Y.PROVIDER_NAME,address:i,privateKey:null,mnemonic:t}}getAccount(){if(this.account)return this.account;let e=(0,M.getWarpWalletMnemonicFromConfig)(this.config,this.chain.name);if(!e)throw new Error("No mnemonic provided");let r=O.Mnemonic.fromString(e).deriveKey(0);return this.account=new O.Account(r),this.account}};Y.PROVIDER_NAME="mnemonic";var ae=Y;var U=require("@multiversx/sdk-core"),R=require("@vleap/warps"),Z=class Z{constructor(e,t){this.config=e;this.chain=t;this.account=null}async getAddress(){let e=(0,R.getWarpWalletAddressFromConfig)(this.config,this.chain.name);if(e)return e;try{return this.getAccount().address.toBech32()}catch{return null}}async getPublicKey(){try{return this.getAccount().publicKey.hex()}catch{return null}}async signTransaction(e){return await this.getAccount().signTransaction(e),e}async signMessage(e){let t=this.getAccount(),r=new TextEncoder().encode(e),n=await t.signMessage(new U.Message({data:r}));return Buffer.from(n).toString("hex")}getAccountInstance(){return this.getAccount()}async importFromMnemonic(e){let r=U.Mnemonic.fromString(e).deriveKey(0),n=r.hex(),s=r.generatePublicKey().toAddress(this.chain.addressHrp).toBech32(),c={provider:Z.PROVIDER_NAME,address:s,privateKey:n,mnemonic:e};return(0,R.setWarpWalletInConfig)(this.config,this.chain.name,c),c}async importFromPrivateKey(e){let r=e.startsWith("-----")?U.UserSecretKey.fromPem(e):U.UserSecretKey.fromString(e),n=r.hex(),s=r.generatePublicKey().toAddress(this.chain.addressHrp).toBech32(),c={provider:Z.PROVIDER_NAME,address:s,privateKey:n,mnemonic:null};return(0,R.setWarpWalletInConfig)(this.config,this.chain.name,c),c}async export(){let e=this.getAccount(),t=(0,R.getWarpWalletPrivateKeyFromConfig)(this.config,this.chain.name),r=(0,R.getWarpWalletMnemonicFromConfig)(this.config,this.chain.name);return{provider:Z.PROVIDER_NAME,address:e.address.toBech32(),privateKey:t||null,mnemonic:r||null}}async generate(){let e=U.UserSecretKey.generate(),t=e.hex(),n=e.generatePublicKey().toAddress(this.chain.addressHrp).toBech32();return{provider:Z.PROVIDER_NAME,address:n,privateKey:t,mnemonic:null}}getAccount(){if(this.account)return this.account;let e=(0,R.getWarpWalletPrivateKeyFromConfig)(this.config,this.chain.name);if(!e)throw new Error("No private key provided");let r=e.startsWith("-----")?U.UserSecretKey.fromPem(e):U.UserSecretKey.fromString(e);return this.account=new U.Account(r),this.account}};Z.PROVIDER_NAME="privateKey";var ie=Z;var se=require("@vleap/warps"),oe=class{constructor(e,t){this.config=e;this.chain=t}async getAddress(){return(0,se.getWarpWalletAddressFromConfig)(this.config,this.chain.name)}async getPublicKey(){return null}async signTransaction(e){let t=await this.getAddress();throw new Error(`Wallet can not be used for signing: ${t}`)}async signMessage(e){let t=await this.getAddress();throw new Error(`Wallet can not be used for signing: ${t}`)}async importFromMnemonic(e){let t=(0,se.getWarpWalletAddressFromConfig)(this.config,this.chain.name);throw new Error(`Wallet can not be used for signing: ${t}`)}async importFromPrivateKey(e){let t=(0,se.getWarpWalletAddressFromConfig)(this.config,this.chain.name);throw new Error(`Wallet can not be used for signing: ${t}`)}async export(){let e=(0,se.getWarpWalletAddressFromConfig)(this.config,this.chain.name);throw new Error(`Wallet can not be used for signing: ${e}`)}async generate(){let e=(0,se.getWarpWalletAddressFromConfig)(this.config,this.chain.name);throw new Error(`Wallet can not be used for signing: ${e}`)}};var ve=class{constructor(e,t){this.config=e;this.chain=t;this.cachedAddress=null;this.cachedPublicKey=null;this.entry=C(t,e.env,e),this.cache=new ee.WarpCache(e.cache?.type),this.walletProvider=this.createProvider(),this.initializeCache()}async signTransaction(e){if(!e||typeof e!="object")throw new Error("Invalid transaction object");if(!this.walletProvider)throw new Error("No wallet provider available");if(this.walletProvider instanceof oe)throw new Error(`Wallet (${this.chain.name}) is read-only`);if(this.walletProvider instanceof ie||this.walletProvider instanceof ae){let r=this.walletProvider.getAccountInstance();if(e.nonce===0n){let n=await this.entry.recallAccountNonce(r.address),i=this.cache.get(`nonce:${r.address.toBech32()}`)||0,s=BigInt(Math.max(i,Number(n)));e.nonce=s}}else if(e.nonce===0n&&this.cachedAddress){let r=Je.Address.newFromBech32(this.cachedAddress),n=await this.entry.recallAccountNonce(r),i=this.cache.get(`nonce:${this.cachedAddress}`)||0,s=BigInt(Math.max(i,Number(n)));e.nonce=s}let t=await this.walletProvider.signTransaction(e);if(this.walletProvider instanceof ie||this.walletProvider instanceof ae){let r=this.walletProvider.getAccountInstance(),n=Number(r.nonce)+1;this.cache.set(`nonce:${r.address.toBech32()}`,n,ee.CacheTtl.OneMinute)}else if(this.cachedAddress){let r=e.nonce?Number(e.nonce):0;this.cache.set(`nonce:${this.cachedAddress}`,r+1,ee.CacheTtl.OneMinute)}return t}async signTransactions(e){let t=[];for(let r of e)t.push(await this.signTransaction(r));return t}async signMessage(e){if(!this.walletProvider)throw new Error("No wallet provider available");if(this.walletProvider instanceof oe)throw new Error(`Wallet (${this.chain.name}) is read-only`);return await this.walletProvider.signMessage(e)}async sendTransactions(e){return Promise.all(e.map(async t=>this.sendTransaction(t)))}async sendTransaction(e){if(!e||typeof e!="object")throw new Error("Invalid transaction object");if(!e.signature)throw new Error("Transaction must be signed before sending");return await this.entry.sendTransaction(e)}async importFromMnemonic(e){return await this.createProviderForOperation("mnemonic").importFromMnemonic(e)}async importFromPrivateKey(e){return await this.createProviderForOperation("privateKey").importFromPrivateKey(e)}async export(e){return await this.createProviderForOperation(e).export()}async generate(e){return await this.createProviderForOperation(e).generate()}getAddress(){return this.cachedAddress}getPublicKey(){return this.cachedPublicKey}createProvider(){let e=this.config.user?.wallets?.[this.chain.name];return e?typeof e=="string"?new oe(this.config,this.chain):this.createProviderForOperation(e.provider):null}initializeCache(){(0,ee.initializeWalletCache)(this.walletProvider).then(e=>{this.cachedAddress=e.address,this.cachedPublicKey=e.publicKey})}createProviderForOperation(e){let r=this.config.walletProviders?.[this.chain.name]?.[e];if(r){let n=r(this.config,this.chain);if(!n)throw new Error(`Custom wallet provider factory returned null for ${e}`);return n}if(e==="privateKey")return new ie(this.config,this.chain);if(e==="mnemonic")return new ae(this.config,this.chain);throw new Error(`Unsupported wallet provider for ${this.chain.name}: ${e}`)}};var we=(o,e)=>(t,r)=>{let n=e[t.env],i=new Ye.WarpTypeRegistry;return i.registerType("token",{stringToNative:s=>s,nativeToString:s=>`token:${s}`}),i.registerType("codemeta",{stringToNative:s=>s,nativeToString:s=>`codemeta:${s}`}),i.registerTypeAlias("list","vector"),{chainInfo:n,builder:()=>new de(t,n),executor:new ge(t,n,i),output:new J(t,n,i),serializer:new L({typeRegistry:i}),registry:new We(t,n),explorer:new fe(o,t),abiBuilder:()=>new D(t,n),brandBuilder:()=>new me(t,n),dataLoader:new he(t,n),wallet:new ve(t,n)}};var ce=require("@vleap/warps");var Ce={chain:ce.WarpChainName.Multiversx,identifier:"EGLD",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://joai.ai/images/tokens/egld.svg"},Ue=we(ce.WarpChainName.Multiversx,{mainnet:{name:ce.WarpChainName.Multiversx,displayName:"MultiversX",chainId:"1",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://api.multiversx.com",logoUrl:"https://joai.ai/images/chains/multiversx.svg",nativeToken:Ce},testnet:{name:ce.WarpChainName.Multiversx,displayName:"MultiversX Testnet",chainId:"T",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://testnet-api.multiversx.com",logoUrl:"https://joai.ai/images/chains/multiversx.svg",nativeToken:Ce},devnet:{name:ce.WarpChainName.Multiversx,displayName:"MultiversX Devnet",chainId:"D",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://devnet-api.multiversx.com",logoUrl:"https://joai.ai/images/chains/multiversx.svg",nativeToken:Ce}});var Ae=require("@vleap/warps");var Ze={chain:Ae.WarpChainName.Vibechain,identifier:"VIBE",name:"VIBE",symbol:"VIBE",decimals:18,logoUrl:"https://joai.ai/images/tokens/vibe.svg"},ke={name:Ae.WarpChainName.Vibechain,displayName:"VibeChain",chainId:"V",blockTime:600,addressHrp:"vibe",defaultApiUrl:"https://vibeox-api.multiversx.com",logoUrl:"https://joai.ai/images/chains/vibechain.svg",nativeToken:Ze},Fe=we(Ae.WarpChainName.Vibechain,{mainnet:ke,testnet:ke,devnet:ke});var dt=()=>[Ue,Fe];var K=require("@vleap/warps");var ht=o=>new K.WarpSerializer().nativeToString(v.Token,o),gt=o=>new K.WarpSerializer().nativeToString(v.CodeMeta,o),ft=(o,e)=>{if(e===null)return v.Optional+K.WarpConstants.ArgParamsSeparator;let t=o(e),r=t.indexOf(K.WarpConstants.ArgParamsSeparator),n=t.substring(0,r),i=t.substring(r+1);return v.Optional+K.WarpConstants.ArgParamsSeparator+n+K.WarpConstants.ArgParamsSeparator+i},yt=o=>new K.WarpSerializer().nativeToString(v.List,o);var p=require("@multiversx/sdk-core"),Wt=(o,e)=>o?p.OptionValue.newProvided(o):e?p.OptionValue.newMissingTyped(e):p.OptionValue.newMissing(),vt=(o,e)=>o?new p.OptionalValue(o.getType(),o):e?new p.OptionalValue(e):p.OptionalValue.newMissing(),wt=o=>{if(o.length===0)throw new Error("Cannot create a list from an empty array");let e=o[0].getType();return new p.List(e,o)},Tt=o=>p.VariadicValue.fromItems(...o),Ct=o=>{let e=o.map(t=>t.getType());return new p.CompositeValue(new p.CompositeType(...e),o)},At=o=>p.StringValue.fromUTF8(o),xt=o=>new p.U8Value(o),Et=o=>new p.U16Value(o),bt=o=>new p.U32Value(o),Pt=o=>new p.U64Value(o),It=o=>new p.BigUIntValue(BigInt(o)),St=o=>new p.BooleanValue(o),Bt=o=>new p.AddressValue(p.Address.newFromBech32(o)),Nt=o=>new p.TokenIdentifierValue(o),Vt=o=>p.BytesValue.fromHex(o),Ut=o=>new p.Struct(new p.StructType("EsdtTokenPayment",[new p.FieldDefinition("token_identifier","",new p.TokenIdentifierType),new p.FieldDefinition("token_nonce","",new p.U64Type),new p.FieldDefinition("amount","",new p.BigUIntType)]),[new p.Field(new p.TokenIdentifierValue(o.token.identifier),"token_identifier"),new p.Field(new p.U64Value(BigInt(o.token.nonce)),"token_nonce"),new p.Field(new p.BigUIntValue(BigInt(o.amount)),"amount")]),kt=o=>new p.CodeMetadataValue(p.CodeMetadata.newFromBytes(Uint8Array.from(Buffer.from(o,"hex")))),Ft=()=>new p.NothingValue;0&&(module.exports={ExplorerUrls,KnownTokens,MultiversxAdapter,MultiversxExplorers,MultiversxExplorersConfig,NativeTokenEgld,NativeTokenVibe,VibechainAdapter,VibechainExplorers,WarpMultiversxAbiBuilder,WarpMultiversxBrandBuilder,WarpMultiversxBuilder,WarpMultiversxConstants,WarpMultiversxContractLoader,WarpMultiversxDataLoader,WarpMultiversxExecutor,WarpMultiversxExplorer,WarpMultiversxInputTypes,WarpMultiversxOutput,WarpMultiversxRegistry,WarpMultiversxSerializer,WarpMultiversxWallet,address_value,asset_value,biguint_value,boolean_value,codemeta,codemeta_value,composite_value,createMultiversxAdapter,findKnownTokenById,getAllMultiversxAdapters,getAllMultiversxChainNames,getKnownTokensForChain,getMultiversxEntrypoint,getMultiversxRegistryAddress,getNormalizedTokenIdentifier,hex_value,isNativeToken,list,list_value,nothing_value,option_value,optional,optional_value,string_value,toTypedConfigInfo,toTypedRegistryInfo,token,token_value,u16_value,u32_value,u64_value,u8_value,variadic_value});
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{WarpChainName as ze}from"@vleap/warps";var Fn=()=>[ze.Multiversx,ze.Vibechain];import{WarpTypeRegistry as mn}from"@vleap/warps";import{AbiRegistry as ge,Address as Ht,TransactionsFactoryConfig as Gt,TransferTransactionsFactory as zt}from"@multiversx/sdk-core";import{createWarpIdentifier as qt,getLatestProtocolIdentifier as jt,getWarpWalletAddressFromConfig as Qt,WarpCache as Xt,WarpCacheKey as Jt,WarpConstants as je,WarpLogger as Qe}from"@vleap/warps";import{DevnetEntrypoint as Lt,MainnetEntrypoint as Kt,TestnetEntrypoint as _t}from"@multiversx/sdk-core";import{getProviderConfig as $t}from"@vleap/warps";var M=s=>!s.includes("-"),j=s=>M(s)?`${s}-000000`:s,v=(s,e,t)=>{let r="warp-sdk",a=t?$t(t,s.name,e,s.defaultApiUrl):{url:s.defaultApiUrl},i=a.url,o={headers:a.headers};return e==="devnet"?new Lt({url:i,kind:"api",clientName:r,networkProviderConfig:o}):e==="testnet"?new _t({url:i,kind:"api",clientName:r,networkProviderConfig:o}):new Kt({url:i,kind:"api",clientName:r,networkProviderConfig:o})};import{WarpLogger as qe}from"@vleap/warps";var Q=class{constructor(e){this.config=e}async getContract(e,t){try{let a=await v(t,this.config.env,this.config).createNetworkProvider().doGetGeneric(`accounts/${e}`);return{address:e,owner:a.ownerAddress,verified:a.isVerified||!1}}catch(r){return qe.error("WarpContractLoader: getContract error",r),null}}async getVerificationInfo(e,t){try{let a=await v(t,this.config.env,this.config).createNetworkProvider().doGetGeneric(`accounts/${e}/verification`);return{codeHash:a.codeHash,abi:a.source.abi}}catch(r){return qe.error("WarpContractLoader: getVerificationInfo error",r),null}}};var S=class{constructor(e,t){this.config=e;this.chain=t;this.contractLoader=new Q(this.config),this.cache=new Xt(this.config.cache?.type)}async createInscriptionTransaction(e){let t=Qt(this.config,this.chain.name);if(!t)throw new Error("WarpBuilder: user address not set");let r=new Gt({chainID:this.chain.chainId}),n=new zt({config:r}),a=Ht.newFromBech32(t),i={protocol:jt("abi"),content:e},o=JSON.stringify(i),c=await n.createTransactionForTransfer(a,{receiver:a,nativeAmount:BigInt(0),data:Uint8Array.from(Buffer.from(o))});return c.gasLimit=c.gasLimit+BigInt(2e6),c}async createFromRaw(e){return JSON.parse(e)}async createFromTransaction(e){let t=await this.createFromRaw(e.data.toString());return t.meta={chain:this.chain.name,identifier:qt(this.chain.name,"hash",e.hash),query:null,hash:e.hash,creator:e.sender.toBech32(),createdAt:new Date(e.timestamp*1e3).toISOString()},t}async createFromTransactionHash(e,t){let r=Jt.WarpAbi(this.config.env,e);if(t){let i=this.cache.get(r);if(i)return Qe.info(`WarpAbiBuilder (createFromTransactionHash): Warp abi found in cache: ${e}`),i}let a=v(this.chain,this.config.env,this.config).createNetworkProvider();try{let i=await a.getTransaction(e),o=await this.createFromTransaction(i);return t&&t.ttl&&o&&this.cache.set(r,o,t.ttl),o}catch(i){return Qe.error("WarpAbiBuilder: Error creating from transaction hash",i),null}}async getAbiForAction(e){if(e.abi)return await this.fetchAbi(e);if(!e.address)throw new Error("WarpActionExecutor: Address not found");let t=await this.contractLoader.getVerificationInfo(e.address,this.chain);if(!t)throw new Error("WarpActionExecutor: Verification info not found");return ge.create(t.abi)}async fetchAbi(e){if(!e.abi)throw new Error("WarpActionExecutor: ABI not found");if(e.abi.startsWith(je.IdentifierType.Hash)){let t=e.abi.split(je.ArgParamsSeparator)[1],r=await this.createFromTransactionHash(t);if(!r)throw new Error(`WarpActionExecutor: ABI not found for hash: ${e.abi}`);return ge.create(r.content)}else{let r=await(await fetch(e.abi)).json();return ge.create(r)}}};import{Address as Xe,TransactionsFactoryConfig as Yt,TransferTransactionsFactory as Zt}from"@multiversx/sdk-core";import{createWarpIdentifier as er,getWarpWalletAddressFromConfig as tr,WarpBrandBuilder as rr,WarpLogger as nr}from"@vleap/warps";import{Buffer as ar}from"buffer";var X=class{constructor(e,t){this.config=e;this.chain=t;this.core=new rr(e)}async createInscriptionTransaction(e){let t=tr(this.config,this.chain.name);if(!t)throw new Error("BrandBuilder: user address not set");let r=new Yt({chainID:this.chain.chainId}),n=new Zt({config:r}),a=Xe.newFromBech32(t),i=JSON.stringify(e);return await n.createTransactionForNativeTokenTransfer(a,{receiver:Xe.newFromBech32(t),nativeAmount:BigInt(0),data:Uint8Array.from(ar.from(i))})}async createFromTransaction(e,t=!1){let r=await this.core.createFromRaw(e.data.toString(),t);return r.meta={query:null,chain:this.chain.name,identifier:er(this.chain.name,"hash",e.hash),hash:e.hash,creator:e.sender.toBech32(),createdAt:new Date(e.timestamp*1e3).toISOString()},r}async createFromTransactionHash(e){let r=v(this.chain,this.config.env,this.config).createNetworkProvider();try{let n=await r.getTransaction(e);return this.createFromTransaction(n)}catch(n){return nr.error("BrandBuilder: Error creating from transaction hash",n),null}}};import{Address as Je,TransactionsFactoryConfig as ir,TransferTransactionsFactory as sr}from"@multiversx/sdk-core";import{createWarpIdentifier as or,getWarpWalletAddressFromConfig as cr,WarpBuilder as Ye,WarpCache as lr,WarpCacheKey as pr,WarpLogger as Ze}from"@vleap/warps";var J=class extends Ye{constructor(t,r){super(t);this.config=t;this.chain=r;this.cache=new lr(t.cache?.type),this.core=new Ye(t)}async createInscriptionTransaction(t){let r=cr(this.config,this.chain.name);if(!r)throw new Error("WarpBuilder: user address not set");let n=new ir({chainID:this.chain.chainId}),a=new sr({config:n}),i=Je.newFromBech32(r),o=JSON.stringify(t),c=await a.createTransactionForTransfer(i,{receiver:Je.newFromBech32(r),nativeAmount:BigInt(0),data:Uint8Array.from(Buffer.from(o))});return c.gasLimit=c.gasLimit+BigInt(2e6),c}async createFromTransaction(t,r=!1){let n=await this.core.createFromRaw(t.data.toString(),r);return n.meta={chain:this.chain.name,identifier:or(this.chain.name,"hash",t.hash),query:null,hash:t.hash,creator:t.sender.toBech32(),createdAt:new Date(t.timestamp*1e3).toISOString()},n}async createFromTransactionHash(t,r){let n=pr.Warp(this.config.env,t);if(r){let o=this.cache.get(n);if(o)return Ze.info(`WarpBuilder (createFromTransactionHash): Warp found in cache: ${t}`),o}let i=v(this.chain,this.config.env,this.config).createNetworkProvider();try{let o=await i.getTransaction(t),c=await this.createFromTransaction(o);return r&&r.ttl&&c&&this.cache.set(n,c,r.ttl),c}catch(o){return Ze.error("WarpBuilder: Error creating from transaction hash",o),null}}};import{Address as fe,Token as gr,TokenComputer as fr}from"@multiversx/sdk-core";import{CacheTtl as yr,WarpCache as Wr,WarpCacheKey as vr}from"@vleap/warps";import{WarpChainName as st}from"@vleap/warps";import{WarpChainName as ur}from"@vleap/warps";var et=ur.Multiversx,tt=[{chain:et,identifier:"EGLD",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"},{chain:et,identifier:"EGLD-000000",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"}];import{WarpChainName as mr}from"@vleap/warps";var A=mr.Multiversx,rt=[{chain:A,identifier:"EGLD",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"},{chain:A,identifier:"EGLD-000000",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"},{chain:A,identifier:"SEGLD-3ad2d0",name:"StakedEGLD",symbol:"SEGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/SEGLD-3ad2d0/icon.png"},{chain:A,identifier:"HSEGLD-c13a4e",name:"HatomSEGLD",symbol:"HSEGLD",decimals:8,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/HSEGLD-c13a4e/icon.png"},{chain:A,identifier:"UTK-2f80e9",name:"xMoney UTK",symbol:"UTK",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/UTK-2f80e9/icon.png"},{chain:A,identifier:"USDC-c76f1f",name:"WrappedUSDC",symbol:"USDC",decimals:6,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/USDC-c76f1f/icon.png"},{chain:A,identifier:"WEGLD-bd4d79",name:"WrappedEGLD",symbol:"WEGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/WEGLD-bd4d79/icon.png"},{chain:A,identifier:"HTM-f51d55",name:"Hatom",symbol:"HTM",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/HTM-f51d55/icon.png"},{chain:A,identifier:"MEX-455c57",name:"MEX",symbol:"MEX",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/MEX-455c57/icon.png"},{chain:A,identifier:"WTAO-4f5363",name:"WrappedTAO",symbol:"WTAO",decimals:9,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/WTAO-4f5363/icon.png"},{chain:A,identifier:"HEGLD-d61095",name:"HatomEGLD",symbol:"HEGLD",decimals:8,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/HEGLD-d61095/icon.png"},{chain:A,identifier:"WBTC-5349b3",name:"WrappedBTC",symbol:"WBTC",decimals:8,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/WBTC-5349b3/icon.png"},{chain:A,identifier:"WETH-b4ca29",name:"WrappedETH",symbol:"WETH",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/WETH-b4ca29/icon.png"},{chain:A,identifier:"USH-111e09",name:"HatomUSD",symbol:"USH",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/USH-111e09/icon.png"},{chain:A,identifier:"USDT-f8c08c",name:"WrappedUSDT",symbol:"USDT",decimals:6,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/USDT-f8c08c/icon.png"}];import{WarpChainName as dr}from"@vleap/warps";var nt=dr.Multiversx,at=[{chain:nt,identifier:"EGLD",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"},{chain:nt,identifier:"EGLD-000000",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"}];import{WarpChainName as hr}from"@vleap/warps";var it=hr.Vibechain,Y=[{chain:it,identifier:"VIBE",name:"VIBE",symbol:"VIBE",decimals:18,logoUrl:"https://joai.ai/images/tokens/vibe.svg"},{chain:it,identifier:"VIBE-000000",name:"VIBE",symbol:"VIBE",decimals:18,logoUrl:"https://joai.ai/images/tokens/vibe.svg"}];var ot={[st.Multiversx]:{mainnet:rt,testnet:at,devnet:tt},[st.Vibechain]:{mainnet:Y,testnet:Y,devnet:Y}},ct=(s,e,t)=>(ot[s]?.[e]||[]).find(n=>n.identifier===t)||null,Ja=(s,e)=>ot[s]?.[e]||[];var Z=class{constructor(e,t){this.config=e;this.chain=t;this.cache=new Wr(e.cache?.type)}async getAccount(e){let r=await v(this.chain,this.config.env,this.config).createNetworkProvider().getAccount(fe.newFromBech32(e));return{chain:this.chain.name,address:r.address.toBech32(),balance:r.balance}}async getAccountAssets(e){let t=v(this.chain,this.config.env,this.config).createNetworkProvider(),r=t.getAccount(fe.newFromBech32(e)),n=t.getFungibleTokensOfAccount(fe.newFromBech32(e)),[a,i]=await Promise.all([r,n]),o=a.balance>0?[{...this.chain.nativeToken,amount:a.balance}]:[];return o.push(...i.map(c=>({chain:this.chain.name,identifier:c.token.identifier,name:c.raw.name,symbol:c.raw.ticker,amount:c.amount,decimals:c.raw.decimals,logoUrl:c.raw.assets?.pngUrl||"",price:c.raw.price?Number(c.raw.price):void 0,supply:c.raw.supply?BigInt(c.raw.supply):void 0}))),o}async getAsset(e){let t=vr.Asset(this.config.env,this.chain.name,e),r=this.cache.get(t);if(r)return r;let n=ct(this.chain.name,this.config.env,e);if(n)return{chain:this.chain.name,identifier:e,name:n.name,symbol:n.symbol,amount:0n,decimals:n.decimals,logoUrl:n.logoUrl};let a=new fr,i=M(e)?0n:a.extractNonceFromExtendedIdentifier(e),o=new gr({identifier:e,nonce:BigInt(i||0)}),c=a.isFungible(o),d=v(this.chain,this.config.env,this.config).createNetworkProvider(),m=j(e),p=await d.doGetGeneric(`tokens/${m}`),W={chain:this.chain.name,identifier:o.identifier,name:p.name,symbol:p.ticker,amount:0n,decimals:p.decimals,logoUrl:p.assets?.pngUrl||null,price:p.price?Number(p.price):void 0,supply:p.supply?BigInt(p.supply):void 0};return this.cache.set(t,W,yr.OneHour),W}async getAction(e,t=!1){let r=v(this.chain,this.config.env,this.config),n=t?await r.awaitCompletedTransaction(e):await r.getTransaction(e);return{chain:this.chain.name,id:n.hash,receiver:n.receiver.toBech32(),sender:n.sender.toBech32(),value:n.value,function:n.function,status:this.toActionStatus(n),createdAt:this.toActionCreatedAt(n),error:n?.smartContractResults.map(a=>a.raw.returnMessage)[0]||null,tx:n}}async getAccountActions(e,t){let r=v(this.chain,this.config.env,this.config).createNetworkProvider(),n=`accounts/${e}/transactions`,a=new URLSearchParams,i=t?.size||25,o=t?.page||0;if(o>0){let d=o*i;a.append("from",d.toString())}return i!==25&&a.append("size",i.toString()),a.toString()&&(n+=`?${a.toString()}`),(await r.doGetGeneric(n)).map(d=>({chain:this.chain.name,id:d.txHash,receiver:d.receiver,sender:d.sender,value:d.value,function:d.function,status:this.toActionStatus(d),createdAt:this.toActionCreatedAt(d)}))}toActionStatus(e){return e.status.isSuccessful()?"success":e.status.isFailed()?"failed":"pending"}toActionCreatedAt(e){return new Date(e.timestamp||e.timestamp*1e3).toISOString()}};import{Address as H,ArgSerializer as Mr,SmartContractTransactionsFactory as Rr,Token as Dr,TokenComputer as Lr,TokenTransfer as Kr,TransactionsFactoryConfig as bt,TransferTransactionsFactory as _r}from"@multiversx/sdk-core";import{applyOutputToMessages as $r,extractResolvedInputValues as Hr,getNextInfo as Gr,getWarpActionByIndex as Ne,getWarpWalletAddressFromConfig as Ve}from"@vleap/warps";import{findEventsByFirstTopic as Pr,SmartContractTransactionsOutcomeParser as Ir,TransactionEventsParser as Sr}from"@multiversx/sdk-core";import{applyOutputToMessages as Br,evaluateOutputCommon as oe,extractResolvedInputValues as Nr,getNextInfo as Vr,getWarpActionByIndex as Ur,getWarpWalletAddressFromConfig as kr,parseOutputOutIndex as xt,WarpCache as Fr,WarpCacheKey as Or,WarpConstants as Et}from"@vleap/warps";import{Address as Cr,AddressType as ye,AddressValue as pt,BigUIntType as ee,BigUIntValue as We,BooleanType as ve,BooleanValue as ut,BytesType as we,BytesValue as mt,CodeMetadata as Ar,CodeMetadataType as Te,CodeMetadataValue as dt,CompositeType as Ce,CompositeValue as ht,Field as te,FieldDefinition as re,List as gt,ListType as ft,NothingValue as b,OptionalType as yt,OptionalValue as Ae,OptionType as Wt,OptionValue as xe,StringType as Ee,StringValue as vt,Struct as ne,StructType as k,Token as xr,TokenComputer as wt,TokenIdentifierType as ae,TokenIdentifierValue as be,U16Type as Pe,U16Value as Tt,U32Type as Ie,U32Value as Ct,U64Type as ie,U64Value as Se,U8Type as Be,U8Value as At,VariadicType as $,VariadicValue as se}from"@multiversx/sdk-core";import{WarpSerializer as Er}from"@vleap/warps";var u={HttpProtocolPrefix:"http",IdentifierParamName:"warp",IdentifierParamSeparator:":",IdentifierChainDefault:"multiversx",IdentifierType:{Alias:"alias",Hash:"hash"},IdentifierAliasMarker:"@",Globals:{UserWallet:{Placeholder:"USER_WALLET",Accessor:s=>s.config.user?.wallets?.[s.adapter.chainInfo.name]},UserWalletPublicKey:{Placeholder:"USER_WALLET_PUBLICKEY",Accessor:s=>{if(!s.adapter.wallet)return null;try{return s.adapter.wallet.getPublicKey()||null}catch{return null}}},ChainApiUrl:{Placeholder:"CHAIN_API",Accessor:s=>s.adapter.chainInfo.defaultApiUrl},ChainAddressHrp:{Placeholder:"CHAIN_ADDRESS_HRP",Accessor:s=>s.adapter.chainInfo.addressHrp}},Vars:{Query:"query",Env:"env"},ArgParamsSeparator:":",ArgCompositeSeparator:"|",ArgListSeparator:",",ArgStructSeparator:";",Transform:{Prefix:"transform:"},Source:{UserWallet:"user:wallet"},Position:{Payload:"payload:"},Alerts:{TriggerEventPrefix:"event"}},l={Option:"option",Vector:"vector",Tuple:"tuple",Struct:"struct",String:"string",Uint8:"uint8",Uint16:"uint16",Uint32:"uint32",Uint64:"uint64",Uint128:"uint128",Uint256:"uint256",Biguint:"biguint",Bool:"bool",Address:"address",Asset:"asset",Hex:"hex"};var hi={Egld:{Identifier:"EGLD",EsdtIdentifier:"EGLD-000000",DisplayName:"eGold",Decimals:18}},f={Null:"null",Optional:"optional",List:"list",Token:"token",CodeMeta:"codemeta"},wr=(r=>(r.MultiversxExplorer="multiversx_explorer",r.MultiversxExplorerDevnet="multiversx_explorer_devnet",r.MultiversxExplorerTestnet="multiversx_explorer_testnet",r))(wr||{}),Tr=(r=>(r.VibechainExplorer="vibechain_explorer",r.VibechainExplorerDevnet="vibechain_explorer_devnet",r.VibechainExplorerTestnet="vibechain_explorer_testnet",r))(Tr||{}),lt={multiversx:{mainnet:["multiversx_explorer"],testnet:["multiversx_explorer_testnet"],devnet:["multiversx_explorer_devnet"]},vibechain:{mainnet:["vibechain_explorer"],testnet:["vibechain_explorer_testnet"],devnet:["vibechain_explorer_devnet"]}},U={multiversx_explorer:"https://explorer.multiversx.com",multiversx_explorer_devnet:"https://devnet-explorer.multiversx.com",multiversx_explorer_testnet:"https://testnet-explorer.multiversx.com",vibechain_explorer:"https://vibeox-explorer.multiversx.com",vibechain_explorer_devnet:"https://vibeox-explorer.multiversx.com",vibechain_explorer_testnet:"https://vibeox-explorer.multiversx.com"};var br=new RegExp(`${u.ArgParamsSeparator}(.*)`),B=class{constructor(e){this.coreSerializer=new Er(e)}typedToString(e){let t=e.getType();if(t.hasExactClass(Wt.ClassName)||e.hasClassOrSuperclass(xe.ClassName)){if(!e.isSet())return l.Option+u.ArgParamsSeparator+"null";let r=this.typedToString(e.getTypedValue());return l.Option+u.ArgParamsSeparator+r}if(t.hasExactClass($.ClassName)||e.hasClassOrSuperclass(se.ClassName)){let r=e.getItems();if(r.length===0){let m=this.typeToString(t.getFirstTypeParameter());return l.Vector+u.ArgParamsSeparator+m+u.ArgParamsSeparator}let n=r.map(m=>this.typedToString(m));if(n.every(m=>m.startsWith(l.Tuple)))return l.Vector+u.ArgParamsSeparator+n.join(",");let a=n[0],i=a.indexOf(u.ArgParamsSeparator),o=a.substring(0,i),c=n.map(m=>{let p=m.indexOf(u.ArgParamsSeparator);return m.substring(p+1)}),d=o.startsWith(l.Struct)?u.ArgStructSeparator:u.ArgListSeparator;return l.Vector+u.ArgParamsSeparator+o+u.ArgParamsSeparator+c.join(d)}if(t.hasExactClass(yt.ClassName)||e.hasClassOrSuperclass(Ae.ClassName)){if(!e.isSet())return f.Optional+u.ArgParamsSeparator+"null";let r=this.typedToString(e.getTypedValue());return f.Optional+u.ArgParamsSeparator+r}if(t.hasExactClass(ft.ClassName)||e.hasClassOrSuperclass(gt.ClassName)){let n=e.getItems().map(c=>this.typedToString(c));if(n.every(c=>c.startsWith(l.Tuple)))return f.List+u.ArgParamsSeparator+n.join(",");let i=n.map(c=>c.split(u.ArgParamsSeparator)[0])[0],o=n.map(c=>c.split(u.ArgParamsSeparator)[1]);return f.List+u.ArgParamsSeparator+i+u.ArgParamsSeparator+o.join(u.ArgListSeparator)}if(t.hasExactClass(Ce.ClassName)||e.hasClassOrSuperclass(ht.ClassName)){let n=e.getItems().map(a=>{let i=this.typedToString(a),o=i.indexOf(u.ArgParamsSeparator),c=i.substring(0,o),d=i.substring(o+1);return`${c},${d}`});return`${l.Tuple}(${n.join(",")})`}if(t.hasExactClass(ee.ClassName)||e.hasClassOrSuperclass(We.ClassName)||t.getName()==="BigUint")return l.Biguint+u.ArgParamsSeparator+BigInt(e.valueOf().toFixed());if(t.hasExactClass(Be.ClassName)||e.hasClassOrSuperclass(At.ClassName))return l.Uint8+u.ArgParamsSeparator+e.valueOf().toNumber();if(t.hasExactClass(Pe.ClassName)||e.hasClassOrSuperclass(Tt.ClassName))return l.Uint16+u.ArgParamsSeparator+e.valueOf().toNumber();if(t.hasExactClass(Ie.ClassName)||e.hasClassOrSuperclass(Ct.ClassName))return l.Uint32+u.ArgParamsSeparator+e.valueOf().toNumber();if(t.hasExactClass(ie.ClassName)||e.hasClassOrSuperclass(Se.ClassName))return l.Uint64+u.ArgParamsSeparator+BigInt(e.valueOf().toFixed());if(t.hasExactClass(Ee.ClassName)||e.hasClassOrSuperclass(vt.ClassName))return l.String+u.ArgParamsSeparator+e.valueOf();if(t.hasExactClass(ve.ClassName)||e.hasClassOrSuperclass(ut.ClassName))return l.Bool+u.ArgParamsSeparator+e.valueOf();if(t.hasExactClass(ye.ClassName)||e.hasClassOrSuperclass(pt.ClassName))return l.Address+u.ArgParamsSeparator+e.valueOf().toBech32();if(t.hasExactClass(we.ClassName)||e.hasClassOrSuperclass(mt.ClassName))return l.Hex+u.ArgParamsSeparator+e.valueOf().toString("hex");if(t.getName()==="EsdtTokenPayment"){let r=e.getFieldValue("token_identifier").valueOf(),n=e.getFieldValue("token_nonce").valueOf(),a=e.getFieldValue("amount").valueOf(),o=new wt().computeExtendedIdentifier(new xr({identifier:r,nonce:BigInt(n)}));return l.Asset+u.ArgParamsSeparator+o+u.ArgCompositeSeparator+a}if(t.hasExactClass(k.ClassName)||e.hasClassOrSuperclass(ne.ClassName)){let r=e,a=r.getType().getName(),i=r.getFields();if(i.length===0)return`${l.Struct}(${a})${u.ArgParamsSeparator}`;let o=i.map(c=>{let d=c.value.getType(),p=this.typedToString(c.value).split(u.ArgParamsSeparator),W=p.length>2?p.slice(2).join(u.ArgParamsSeparator):p[1]||"";return`(${c.name}${u.ArgParamsSeparator}${this.typeToString(d)})${W}`});return`${l.Struct}(${a})${u.ArgParamsSeparator}${o.join(u.ArgListSeparator)}`}if(t.hasExactClass(ae.ClassName)||e.hasClassOrSuperclass(be.ClassName))return f.Token+u.ArgParamsSeparator+e.valueOf();if(t.hasExactClass(Te.ClassName)||e.hasClassOrSuperclass(dt.ClassName))return f.CodeMeta+u.ArgParamsSeparator+e.valueOf().toString();throw new Error(`WarpArgSerializer (typedToString): Unsupported input type: ${e.getClassName()}`)}typedToNative(e){let t=this.typedToString(e);return this.coreSerializer.stringToNative(t)}nativeToTyped(e,t){if(e.startsWith(l.Tuple))return this.stringToTyped(e+":");let r=this.coreSerializer.nativeToString(e,t);return this.stringToTyped(r)}nativeToType(e){if(e.startsWith(l.Tuple)){let t=e.match(/\(([^)]+)\)/)?.[1];if(!t)throw new Error(`Invalid tuple type format: ${e}`);let r=t.split(","),n=[];for(let a=0;a<r.length;a+=2)n.push(r[a]);return new Ce(...n.map(a=>this.nativeToType(a)))}if(e.startsWith(l.Struct)){let t=e.match(/\(([^)]+)\)/);if(!t)throw new Error("Struct type must include a name in the format struct(Name)");let r=t[1];return new k(r,[])}if(e===l.String)return new Ee;if(e===l.Uint8)return new Be;if(e===l.Uint16)return new Pe;if(e===l.Uint32)return new Ie;if(e===l.Uint64)return new ie;if(e===l.Biguint)return new ee;if(e===l.Bool)return new ve;if(e===l.Address)return new ye;if(e===l.Hex)return new we;if(e===l.Asset)return new k("EsdtTokenPayment",[new re("token_identifier","",new ae),new re("token_nonce","",new ie),new re("amount","",new ee)]);if(e===f.Token)return new ae;if(e===f.CodeMeta)return new Te;throw new Error(`WarpArgSerializer (nativeToType): Unsupported input type: ${e}`)}stringToTyped(e){let[t,r]=e.split(/:(.*)/,2);if(t===l.Option){let n=this.stringToTyped(r);return n instanceof b?xe.newMissingTyped(n.getType()):xe.newProvided(n)}if(t===l.Vector){let n=r.indexOf(u.ArgParamsSeparator),a=r.substring(0,n),i=r.substring(n+1);if(a.startsWith(l.Tuple)){let p=i.split(",").map(W=>this.stringToTyped(W));return new se(new $(this.nativeToType(a)),p)}if(i.includes("tuple(")){let m=this.splitTupleStrings(i),p=m.map(T=>this.stringToTyped(T)),C=m[0].match(/^(tuple\([^)]+\))/),h=C?C[1]:"tuple";return new se(new $(this.nativeToType(h)),p)}let o=a.startsWith(l.Struct)?u.ArgStructSeparator:u.ArgListSeparator,d=i.split(o).map(m=>this.stringToTyped(`${a}:${m}`));return new se(new $(this.nativeToType(a)),d)}if(t.startsWith(l.Tuple)){let n=t.match(/\(([^)]+)\)/)?.[1];if(!n)throw new Error(`Invalid tuple format: ${t}`);let a=n.split(","),i=[];for(let c=0;c<a.length;c+=2){let d=a[c],m=a[c+1];i.push(this.stringToTyped(`${d}:${m}`))}let o=i.map(c=>c.getType());return new ht(new Ce(...o),i)}if(t.startsWith(l.Struct)){let n=t.match(/\(([^)]+)\)/),a=n?n[1]:"CustomStruct";if(!r)return new ne(new k(a,[]),[]);let i=r.split(u.ArgListSeparator),o=[],c=[];return i.forEach(d=>{let m=d.match(new RegExp(`^\\(([^${u.ArgParamsSeparator}]+)${u.ArgParamsSeparator}([^)]+)\\)(.+)$`));if(m){let[,p,W,C]=m,h=this.stringToTyped(`${W}${u.ArgParamsSeparator}${C}`);o.push(new re(p,"",h.getType())),c.push(new te(h,p))}}),new ne(new k(a,o),c)}if(t===l.String)return r?vt.fromUTF8(r):new b;if(t===l.Uint8)return r?new At(Number(r)):new b;if(t===l.Uint16)return r?new Tt(Number(r)):new b;if(t===l.Uint32)return r?new Ct(Number(r)):new b;if(t===l.Uint64)return r?new Se(BigInt(r)):new b;if(t===l.Biguint)return r?new We(BigInt(r)):new b;if(t===l.Bool)return r?new ut(typeof r=="boolean"?r:r==="true"):new b;if(t===l.Address)return r?new pt(Cr.newFromBech32(r)):new b;if(t===l.Hex)return r?mt.fromHex(r):new b;if(t===l.Asset){let[n,a]=r.split(u.ArgCompositeSeparator),i=new wt,o=M(n)?j(n):i.extractIdentifierFromExtendedIdentifier(n),c=M(n)?0n:i.extractNonceFromExtendedIdentifier(n);return new ne(this.nativeToType("asset"),[new te(new be(o),"token_identifier"),new te(new Se(BigInt(c)),"token_nonce"),new te(new We(BigInt(a)),"amount")])}if(t===f.Null)return new b;if(t===f.Optional){let n=this.stringToTyped(r);return n instanceof b?Ae.newMissing():new Ae(n.getType(),n)}if(t===f.List){let[n,a]=r.split(br,2),o=a.split(u.ArgListSeparator).map(c=>this.stringToTyped(n+u.ArgParamsSeparator+c));return new gt(this.nativeToType(n),o)}if(t===f.Token)return r?new be(r):new b;if(t===f.CodeMeta)return new dt(Ar.newFromBytes(Uint8Array.from(Buffer.from(r,"hex"))));throw new Error(`WarpArgSerializer (stringToTyped): Unsupported input type: ${t}`)}splitTupleStrings(e){let t=[],r="",n=0;for(let a=0;a<e.length;a++){let i=e[a];if(i==="(")n++;else if(i===")")n--;else if(i===","&&n===0){t.push(r.trim()),r="";continue}r+=i}return r.trim()&&t.push(r.trim()),t}typeToString(e){if(e.hasExactClass(Wt.ClassName))return l.Option+u.ArgParamsSeparator+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass($.ClassName))return l.Vector+u.ArgParamsSeparator+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(Ee.ClassName))return l.String;if(e.hasExactClass(Be.ClassName))return l.Uint8;if(e.hasExactClass(Pe.ClassName))return l.Uint16;if(e.hasExactClass(Ie.ClassName))return l.Uint32;if(e.hasExactClass(ie.ClassName))return l.Uint64;if(e.hasExactClass(ee.ClassName))return l.Biguint;if(e.hasExactClass(ve.ClassName))return l.Bool;if(e.hasExactClass(ye.ClassName))return l.Address;if(e.hasExactClass(we.ClassName))return l.Hex;if(e.hasExactClass(ae.ClassName))return f.Token;if(e.hasExactClass(yt.ClassName))return f.Optional+u.ArgParamsSeparator+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(ft.ClassName))return f.List+u.ArgParamsSeparator+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(Te.ClassName))return f.CodeMeta;if(e.hasExactClass(k.ClassName)&&e.getClassName()==="EsdtTokenPayment")return l.Asset;if(e.hasExactClass(k.ClassName))return`${l.Struct}(${e.getName()})`;throw new Error(`WarpArgSerializer (typeToString): Unsupported input type: ${e.getClassName()}`)}};var R=class{constructor(e,t,r){this.config=e;this.chain=t;this.typeRegistry=r;this.abi=new S(e,t),this.serializer=new B({typeRegistry:this.typeRegistry}),this.cache=new Fr(e.cache?.type)}async getActionExecution(e,t,r){let n=this.cache.get(Or.WarpExecutable(this.config.env,e.meta?.hash||"",t))??[],a=await this.extractContractOutput(e,t,r,n),i=Vr(this.config,[],e,t,a.output),o=Br(e,a.output,this.config),c=Nr(n);return{status:r.status.isSuccessful()?"success":"error",warp:e,action:t,user:kr(this.config,this.chain.name),txHash:r.hash,tx:r,next:i,values:a.values,output:a.output,messages:o,destination:null,resolvedInputs:c}}async extractContractOutput(e,t,r,n){let a=Ur(e,t),i=[],o=[],c={};if(!e.output||a.type!=="contract")return{values:{string:i,native:o,mapped:{}},output:c};if(!Object.values(e.output).some(h=>h.includes("out")||h.includes("event"))){for(let[h,T]of Object.entries(e.output))c[h]=T;return{values:{string:i,native:o,mapped:{}},output:await oe(e,c,t,n,this.serializer.coreSerializer,this.config)}}let m=await this.abi.getAbiForAction(a),p=new Sr({abi:m}),C=new Ir({abi:m}).parseExecute({transactionOnNetwork:r,function:a.func||void 0});for(let[h,T]of Object.entries(e.output)){if(T.startsWith(Et.Transform.Prefix))continue;if(T.startsWith("input.")){c[h]=T;continue}let x=xt(T);if(x!==null&&x!==t){c[h]=null;continue}let[P,N,V]=T.split(".");if(P==="event"){if(!N||isNaN(Number(V)))continue;let I=Number(V),g=Pr(r,N),Dt=p.parseEvents({events:g})[0],_=Object.values(Dt)[I]||null;i.push(String(_)),o.push(_),c[h]=_&&_.valueOf()}else if(P==="out"||P.startsWith("out[")){if(!N)continue;let I=Number(N),g=C.values[I-1]||null;V&&(g=g[V]||null),g&&typeof g=="object"&&(g="toFixed"in g?g.toFixed():g.valueOf()),i.push(String(g)),o.push(g),c[h]=g&&g.valueOf()}else c[h]=T}return{values:{string:i,native:o,mapped:{}},output:await oe(e,c,t,n,this.serializer.coreSerializer,this.config)}}async extractQueryOutput(e,t,r,n){let a=t.map(m=>this.serializer.typedToString(m)),i=t.map(m=>this.serializer.typedToNative(m)[1]),o={string:a,native:i,mapped:{}},c={};if(!e.output)return{values:o,output:c};let d=m=>{let p=m.split(".").slice(1).map(C=>parseInt(C)-1);if(p.length===0)return;let W=i[p[0]];for(let C=1;C<p.length;C++){if(W==null)return;W=W[p[C]]}return W};for(let[m,p]of Object.entries(e.output)){if(p.startsWith(Et.Transform.Prefix))continue;let W=xt(p);if(W!==null&&W!==r){c[m]=null;continue}p.startsWith("out.")||p==="out"||p.startsWith("out[")?c[m]=d(p)||null:c[m]=p}return c=await oe(e,c,r,n,this.serializer.coreSerializer,this.config),{values:o,output:c}}async resolveWarpOutputRecursively(e){let t=e.warp,r=e.entryActionIndex,n=e.executor,a=e.inputs,i=e.meta,o=new Map,c=new Set,d=this;async function m(h,T=[]){if(o.has(h))return o.get(h);if(c.has(h))throw new Error(`Circular dependency detected at action ${h}`);c.add(h);let x=t.actions[h-1];if(!x)throw new Error(`Action ${h} not found`);let P;if(x.type==="query")P=await n.executeQuery(t,h,T);else if(x.type==="collect")P=await n.executeCollect(t,h,T,i);else throw new Error(`Unsupported or interactive action type: ${x.type}`);if(o.set(h,P),t.output)for(let N of Object.values(t.output)){let I=String(N).match(/^out\[(\d+)\]/);if(I){let g=parseInt(I[1],10);g!==h&&!o.has(g)&&await m(g)}}return c.delete(h),P}await m(r,a);let p={};for(let h of o.values())for(let[T,x]of Object.entries(h.output))x!==null?p[T]=x:T in p||(p[T]=null);let W=await oe(t,p,r,a,this.serializer.coreSerializer,this.config);return{...o.get(r),action:r,output:W}}};var zr="EGLD-000000",ce=class{constructor(e,t,r){this.config=e;this.chain=t;this.typeRegistry=r;this.serializer=new B({typeRegistry:this.typeRegistry}),this.abi=new S(this.config,this.chain),this.output=new R(this.config,this.chain,this.typeRegistry)}async createTransaction(e){let t=Ne(e.warp,e.action),r=null;if(t.type==="transfer")r=await this.createTransferTransaction(e);else if(t.type==="contract")r=await this.createContractCallTransaction(e);else{if(t.type==="query")throw new Error("WarpMultiversxExecutor: Invalid action type for createTransactionForExecute; Use executeQuery instead");if(t.type==="collect")throw new Error("WarpMultiversxExecutor: Invalid action type for createTransactionForExecute; Use executeCollect instead")}if(!r)throw new Error(`WarpMultiversxExecutor: Invalid action type (${t.type})`);return r}async createTransferTransaction(e){if(!e.destination)throw new Error("WarpMultiversxExecutor: createTransfer - destination not set");let t=Ve(this.config,e.chain.name);if(!t)throw new Error("WarpMultiversxExecutor: createTransfer - user address not set");let r=H.newFromBech32(t),n=new bt({chainID:e.chain.chainId}),a=e.data?Buffer.from(this.serializer.stringToTyped(e.data).valueOf()):null,i=e.transfers.length===1&&e.transfers[0].identifier===this.chain.nativeToken?.identifier,c=(i?e.transfers[0].amount:0n)+e.value;return await new _r({config:n}).createTransactionForTransfer(r,{receiver:H.newFromBech32(e.destination),nativeAmount:c,tokenTransfers:i?[]:this.toTokenTransfers(e.transfers),data:a?new Uint8Array(a):void 0})}async createContractCallTransaction(e){if(!e.destination)throw new Error("WarpMultiversxExecutor: createContractCall - destination not set");let t=Ve(this.config,e.chain.name);if(!t)throw new Error("WarpMultiversxExecutor: createContractCall - user address not set");let r=Ne(e.warp,e.action),n=H.newFromBech32(t),a=e.args.map(o=>this.serializer.stringToTyped(o)),i=new bt({chainID:e.chain.chainId});return new Rr({config:i}).createTransactionForExecute(n,{contract:H.newFromBech32(e.destination),function:"func"in r&&r.func||"",gasLimit:"gasLimit"in r?BigInt(r.gasLimit||0):0n,arguments:a,tokenTransfers:this.toTokenTransfers(e.transfers),nativeTransferAmount:e.value})}async executeQuery(e){if(!e.destination)throw new Error("WarpMultiversxExecutor: executeQuery - destination not set");let t=Ne(e.warp,e.action);if(t.type!=="query")throw new Error(`WarpMultiversxExecutor: Invalid action type for executeQuery: ${t.type}`);let r=await this.abi.getAbiForAction(t),n=e.args.map(g=>this.serializer.stringToTyped(g)),a=v(e.chain,this.config.env,this.config),i=H.newFromBech32(e.destination),o=a.createSmartContractController(r),c=o.createQuery({contract:i,function:t.func||"",arguments:n}),d=await o.runQuery(c),m=d.returnCode==="ok",p=new Mr,W=r.getEndpoint(d.function||t.func||""),C=(d.returnDataParts||[]).map(g=>Buffer.from(g)),h=p.buffersToValues(C,W.output),{values:T,output:x}=await this.output.extractQueryOutput(e.warp,h,e.action,e.resolvedInputs),P=Gr(this.config,[],e.warp,e.action,x),V=e.resolvedInputs.find(g=>g.input.position==="receiver"||g.input.position==="destination")?.value||e.destination,I=Hr(e.resolvedInputs);return{status:m?"success":"error",warp:e.warp,action:e.action,user:Ve(this.config,e.chain.name),txHash:null,tx:null,next:P,values:T,output:{...x,_DATA:h},messages:$r(e.warp,x,this.config),destination:V,resolvedInputs:I}}toTokenTransfers(e){return e.map(t=>t.identifier===this.chain.nativeToken.identifier?{...t,identifier:zr}:t).map(t=>{let n=new Lr().extractNonceFromExtendedIdentifier(t.identifier);return new Kr({token:new Dr({identifier:t.identifier,nonce:BigInt(n||0)}),amount:t.amount})})}};var le=class{constructor(e,t){this.chain=e;this.config=t}getExplorers(){let e=lt[this.chain];if(!e)return["multiversx_explorer"];let t=e[this.config.env];return t||["multiversx_explorer"]}getPrimaryExplorer(){return this.getExplorers()[0]}getExplorerUrlByName(e){let t=this.config.preferences?.explorers?.[this.chain];if(t&&!e){let a=U[t];if(a)return a}if(e){let a=U[e];if(a)return a}let r=this.getPrimaryExplorer();return U[r]||U[r]}getAccountUrl(e,t){return`${this.getExplorerUrlByName(t)}/accounts/${e}`}getTransactionUrl(e,t){return`${this.getExplorerUrlByName(t)}/transactions/${e}`}getBlockUrl(e,t){return`${this.getExplorerUrlByName(t)}/blocks/${e}`}getAssetUrl(e,t){return`${this.getExplorerUrlByName(t)}/tokens/${e}`}getContractUrl(e,t){return`${this.getExplorerUrlByName(t)}/accounts/${e}`}getAllExplorers(){return this.getExplorers()}getExplorerByName(e){return this.getExplorers().find(r=>r.toLowerCase()===e.toLowerCase())}getAccountUrls(e){let t=this.getAllExplorers(),r={};return t.forEach(n=>{let a=U[n];a&&(r[n]=`${a}/accounts/${e}`)}),r}getTransactionUrls(e){let t=this.getAllExplorers(),r={};return t.forEach(n=>{let a=U[n];a&&(r[n]=`${a}/transactions/${e}`)}),r}};import{AbiRegistry as It,Address as y,AddressValue as ke,BytesValue as w,SmartContractTransactionsFactory as jr,TransactionsFactoryConfig as Qr}from"@multiversx/sdk-core";import{createWarpIdentifier as Xr,getWarpWalletAddressFromConfig as Jr,WarpCache as Yr,WarpCacheKey as Fe,WarpLogger as Oe}from"@vleap/warps";var Ue={buildInfo:{rustc:{version:"1.86.0",commitHash:"05f9846f893b09a1be1fc8560e33fc3c815cfecb",commitDate:"2025-03-31",channel:"Stable",short:"rustc 1.86.0 (05f9846f8 2025-03-31)"},contractCrate:{name:"registry",version:"0.0.1"},framework:{name:"multiversx-sc",version:"0.51.1"}},name:"RegistryContract",constructor:{inputs:[{name:"unit_price",type:"BigUint"},{name:"vault",type:"Address"}],outputs:[]},upgradeConstructor:{inputs:[],outputs:[]},endpoints:[{name:"registerWarp",mutability:"mutable",payableInTokens:["EGLD"],inputs:[{name:"hash",type:"bytes"},{name:"alias_opt",type:"optional<bytes>",multi_arg:!0},{name:"brand_opt",type:"optional<bytes>",multi_arg:!0}],outputs:[],allow_multiple_var_args:!0},{name:"unregisterWarp",mutability:"mutable",inputs:[{name:"warp",type:"bytes"}],outputs:[]},{name:"upgradeWarp",mutability:"mutable",payableInTokens:["EGLD"],inputs:[{name:"alias",type:"bytes"},{name:"new_warp",type:"bytes"},{name:"brand_opt",type:"optional<bytes>",multi_arg:!0}],outputs:[]},{name:"setWarpAlias",mutability:"mutable",payableInTokens:["EGLD"],inputs:[{name:"hash",type:"bytes"},{name:"alias",type:"bytes"}],outputs:[]},{name:"forceRemoveAlias",mutability:"mutable",inputs:[{name:"hash",type:"bytes"}],outputs:[]},{name:"verifyWarp",mutability:"mutable",inputs:[{name:"warp",type:"bytes"}],outputs:[]},{name:"transferOwnership",mutability:"mutable",inputs:[{name:"warp",type:"bytes"},{name:"new_owner",type:"Address"}],outputs:[]},{name:"getUserWarps",mutability:"readonly",inputs:[{name:"address",type:"Address"}],outputs:[{type:"variadic<InfoView>",multi_result:!0}]},{name:"getInfoByAlias",mutability:"readonly",inputs:[{name:"alias",type:"bytes"}],outputs:[{type:"InfoView"}]},{name:"getInfoByHash",mutability:"readonly",inputs:[{name:"hash",type:"bytes"}],outputs:[{type:"InfoView"}]},{name:"setVault",onlyOwner:!0,mutability:"mutable",inputs:[{name:"vault",type:"Address"}],outputs:[]},{name:"setUnitPrice",onlyOwner:!0,mutability:"mutable",inputs:[{name:"amount",type:"BigUint"}],outputs:[]},{name:"addAdmin",onlyOwner:!0,mutability:"mutable",inputs:[{name:"address",type:"Address"}],outputs:[]},{name:"removeAdmin",onlyOwner:!0,mutability:"mutable",inputs:[{name:"address",type:"Address"}],outputs:[]},{name:"getConfig",mutability:"readonly",inputs:[],outputs:[{type:"ConfigView"}]},{name:"registerBrand",mutability:"mutable",payableInTokens:["EGLD"],inputs:[{name:"hash",type:"bytes"}],outputs:[]},{name:"brandWarp",mutability:"mutable",payableInTokens:["EGLD"],inputs:[{name:"warp",type:"bytes"},{name:"brand",type:"bytes"}],outputs:[]},{name:"getUserBrands",mutability:"readonly",inputs:[{name:"user",type:"Address"}],outputs:[{type:"variadic<bytes>",multi_result:!0}]}],events:[{identifier:"warpRegistered",inputs:[{name:"hash",type:"bytes",indexed:!0},{name:"alias",type:"bytes",indexed:!0},{name:"trust",type:"bytes",indexed:!0}]},{identifier:"warpUnregistered",inputs:[{name:"hash",type:"bytes",indexed:!0}]},{identifier:"warpUpgraded",inputs:[{name:"alias",type:"bytes",indexed:!0},{name:"new_warp",type:"bytes",indexed:!0},{name:"trust",type:"bytes",indexed:!0}]},{identifier:"warpVerified",inputs:[{name:"hash",type:"bytes",indexed:!0}]},{identifier:"aliasUpdated",inputs:[{name:"hash",type:"bytes",indexed:!0},{name:"alias",type:"bytes",indexed:!0}]},{identifier:"ownershipTransferred",inputs:[{name:"warp",type:"bytes",indexed:!0},{name:"old_owner",type:"Address",indexed:!0},{name:"new_owner",type:"Address",indexed:!0}]}],esdtAttributes:[],hasCallback:!1,types:{ConfigView:{type:"struct",fields:[{name:"unit_price",type:"BigUint"},{name:"admins",type:"List<Address>"}]},InfoView:{type:"struct",fields:[{name:"hash",type:"bytes"},{name:"alias",type:"Option<bytes>"},{name:"trust",type:"bytes"},{name:"owner",type:"Address"},{name:"created_at",type:"u64"},{name:"upgraded_at",type:"u64"},{name:"brand",type:"Option<bytes>"},{name:"upgrade",type:"Option<bytes>"}]}}};var E=s=>{if(s==="devnet")return"erd1qqqqqqqqqqqqqpgqje2f99vr6r7sk54thg03c9suzcvwr4nfl3tsfkdl36";if(s==="testnet")throw new Error("Multiversx testnet is not supported");return"erd1qqqqqqqqqqqqqpgq3mrpj3u6q7tejv6d7eqhnyd27n9v5c5tl3ts08mffe"};var pe=s=>({hash:s.hash.toString("hex"),alias:s.alias?.toString()||null,trust:s.trust.toString(),owner:s.owner.toString(),createdAt:s.created_at.toNumber(),upgradedAt:s.upgraded_at?.toNumber(),brand:s.brand?.toString("hex")||null,upgrade:s.upgrade?.toString("hex")||null}),Pt=s=>({unitPrice:BigInt(s.unit_price.toString()),admins:s.admins.map(e=>e.toBech32())});var ue=class{constructor(e,t){this.config=e;this.chain=t;this.cache=new Yr(e.cache?.type),this.registryConfig={unitPrice:BigInt(0),admins:[]},this.userWallet=Jr(this.config,this.chain.name)}async init(){await this.loadRegistryConfigs()}getRegistryConfig(){return this.registryConfig}async createWarpRegisterTransaction(e,t,r){if(this.registryConfig.unitPrice===BigInt(0))throw new Error("WarpRegistry: config not loaded. forgot to call init()?");if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let n=y.newFromBech32(this.userWallet),a=()=>this.isCurrentUserAdmin()?BigInt(0):t&&r?this.registryConfig.unitPrice*BigInt(3):t?this.registryConfig.unitPrice*BigInt(2):this.registryConfig.unitPrice,i=()=>t&&r?[w.fromHex(e),w.fromUTF8(t),w.fromHex(r)]:t?[w.fromHex(e),w.fromUTF8(t)]:[w.fromHex(e)];return await this.getFactory().createTransactionForExecute(n,{contract:y.newFromBech32(E(this.config.env)),function:"registerWarp",gasLimit:BigInt(1e7),nativeTransferAmount:a(),arguments:i()})}async createWarpUnregisterTransaction(e){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let t=y.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(t,{contract:y.newFromBech32(E(this.config.env)),function:"unregisterWarp",gasLimit:BigInt(1e7),arguments:[w.fromHex(e)]})}async createWarpUpgradeTransaction(e,t,r){if(this.registryConfig.unitPrice===BigInt(0))throw new Error("WarpRegistry: config not loaded. forgot to call init()?");if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let n=y.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(n,{contract:y.newFromBech32(E(this.config.env)),function:"upgradeWarp",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:r?[w.fromUTF8(e),w.fromHex(t),w.fromHex(r)]:[w.fromUTF8(e),w.fromHex(t)]})}async createWarpAliasSetTransaction(e,t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let r=y.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(r,{contract:y.newFromBech32(E(this.config.env)),function:"setWarpAlias",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[w.fromHex(e),w.fromUTF8(t)]})}async createWarpVerifyTransaction(e){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let t=y.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(t,{contract:y.newFromBech32(E(this.config.env)),function:"verifyWarp",gasLimit:BigInt(1e7),arguments:[w.fromHex(e)]})}async createWarpTransferOwnershipTransaction(e,t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let r=y.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(r,{contract:y.newFromBech32(E(this.config.env)),function:"transferOwnership",gasLimit:BigInt(1e7),arguments:[w.fromHex(e),new ke(new y(t))]})}async createBrandRegisterTransaction(e){if(this.registryConfig.unitPrice===BigInt(0))throw new Error("WarpRegistry: config not loaded. forgot to call init()?");if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let t=y.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(t,{contract:y.newFromBech32(E(this.config.env)),function:"registerBrand",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[w.fromHex(e)]})}async createWarpBrandingTransaction(e,t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let r=y.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(r,{contract:y.newFromBech32(E(this.config.env)),function:"brandWarp",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[w.fromHex(e),w.fromHex(t)]})}async getInfoByAlias(e,t){try{let r=Fe.RegistryInfo(this.config.env,e),n=t?this.cache.get(r):null;if(n)return Oe.info(`WarpRegistry (getInfoByAlias): RegistryInfo found in cache: ${e}`),n;let a=y.newFromBech32(E(this.config.env)),i=this.getController(),o=i.createQuery({contract:a,function:"getInfoByAlias",arguments:[w.fromUTF8(e)]}),c=await i.runQuery(o),[d]=i.parseQueryResponse(c),m=d?pe(d):null,p=m?.brand?await this.fetchBrand(m.brand):null;return t&&t.ttl&&this.cache.set(r,{registryInfo:m,brand:p},t.ttl),{registryInfo:m,brand:p}}catch{return{registryInfo:null,brand:null}}}async getInfoByHash(e,t){try{let r=Fe.RegistryInfo(this.config.env,e);if(t){let p=this.cache.get(r);if(p)return Oe.info(`WarpRegistry (getInfoByHash): RegistryInfo found in cache: ${e}`),p}let n=y.newFromBech32(E(this.config.env)),a=this.getController(),i=a.createQuery({contract:n,function:"getInfoByHash",arguments:[w.fromHex(e)]}),o=await a.runQuery(i),[c]=a.parseQueryResponse(o),d=c?pe(c):null,m=d?.brand?await this.fetchBrand(d.brand):null;return t&&t.ttl&&this.cache.set(r,{registryInfo:d,brand:m},t.ttl),{registryInfo:d,brand:m}}catch{return{registryInfo:null,brand:null}}}async getUserWarpRegistryInfos(e){try{let t=e||this.userWallet;if(!t)throw new Error("WarpRegistry: user address not set");let r=y.newFromBech32(E(this.config.env)),n=this.getController(),a=n.createQuery({contract:r,function:"getUserWarps",arguments:[new ke(new y(t))]}),i=await n.runQuery(a),[o]=n.parseQueryResponse(i);return o.map(pe)}catch{return[]}}async getUserBrands(e){try{let t=e||this.userWallet;if(!t)throw new Error("WarpRegistry: user address not set");let r=y.newFromBech32(E(this.config.env)),n=this.getController(),a=n.createQuery({contract:r,function:"getUserBrands",arguments:[new ke(new y(t))]}),i=await n.runQuery(a),[o]=n.parseQueryResponse(i),c=o.map(p=>p.toString("hex")),d={ttl:365*24*60*60};return(await Promise.all(c.map(p=>this.fetchBrand(p,d)))).filter(p=>p!==null)}catch{return[]}}async fetchBrand(e,t){let r=Fe.Brand(this.config.env,e),n=t?this.cache.get(r):null;if(n)return Oe.info(`WarpRegistry (fetchBrand): Brand found in cache: ${e}`),n;let i=v(this.chain,this.config.env,this.config).createNetworkProvider();try{let o=await i.getTransaction(e),c=JSON.parse(o.data.toString());return c.meta={query:null,chain:this.chain.name,identifier:Xr(this.chain.name,"hash",e),hash:o.hash,creator:o.sender.toBech32(),createdAt:new Date(o.timestamp*1e3).toISOString()},t&&t.ttl&&this.cache.set(r,c,t.ttl),c}catch{return null}}async loadRegistryConfigs(){let e=y.newFromBech32(E(this.config.env)),t=this.getController(),[r]=await t.query({contract:e,function:"getConfig",arguments:[]}),n=r?Pt(r):null;this.registryConfig=n||{unitPrice:BigInt(0),admins:[]}}getFactory(){let e=new Qr({chainID:this.chain.chainId}),t=It.create(Ue);return new jr({config:e,abi:t})}getController(){let e=v(this.chain,this.config.env,this.config),t=It.create(Ue);return e.createSmartContractController(t)}isCurrentUserAdmin(){return!!this.userWallet&&this.registryConfig.admins.includes(this.userWallet)}};import{Address as ln}from"@multiversx/sdk-core";import{CacheTtl as Ut,initializeWalletCache as pn,WarpCache as un}from"@vleap/warps";import{Account as Zr,Message as en,Mnemonic as Me}from"@multiversx/sdk-core";import{getWarpWalletAddressFromConfig as tn,getWarpWalletMnemonicFromConfig as St,getWarpWalletPrivateKeyFromConfig as rn,setWarpWalletInConfig as Bt}from"@vleap/warps";var F=class F{constructor(e,t){this.config=e;this.chain=t;this.account=null}async getAddress(){let e=tn(this.config,this.chain.name);if(e)return e;try{return this.getAccount().address.toBech32()}catch{return null}}async getPublicKey(){try{return this.getAccount().publicKey.hex()}catch{return null}}async signTransaction(e){return await this.getAccount().signTransaction(e),e}async signMessage(e){let t=this.getAccount(),r=new TextEncoder().encode(e),n=await t.signMessage(new en({data:r}));return Buffer.from(n).toString("hex")}getAccountInstance(){return this.getAccount()}async importFromMnemonic(e){let r=Me.fromString(e).deriveKey(0),n=r.hex(),i=r.generatePublicKey().toAddress(this.chain.addressHrp).toBech32(),o={provider:F.PROVIDER_NAME,address:i,privateKey:n,mnemonic:e};return Bt(this.config,this.chain.name,o),o}async importFromPrivateKey(e){let{UserSecretKey:t}=await import("@multiversx/sdk-wallet"),r=t.fromString(e),n=r.hex(),i=r.generatePublicKey().toAddress(this.chain.addressHrp).toBech32(),o={provider:F.PROVIDER_NAME,address:i,privateKey:n,mnemonic:null};return Bt(this.config,this.chain.name,o),o}async export(){let e=this.getAccount(),t=St(this.config,this.chain.name),r=rn(this.config,this.chain.name);return{provider:F.PROVIDER_NAME,address:e.address.toBech32(),privateKey:r||null,mnemonic:t||null}}async generate(){let e=Me.generate(),t=e.toString(),a=e.deriveKey(0).generatePublicKey().toAddress(this.chain.addressHrp).toBech32();return{provider:F.PROVIDER_NAME,address:a,privateKey:null,mnemonic:t}}getAccount(){if(this.account)return this.account;let e=St(this.config,this.chain.name);if(!e)throw new Error("No mnemonic provided");let r=Me.fromString(e).deriveKey(0);return this.account=new Zr(r),this.account}};F.PROVIDER_NAME="mnemonic";var D=F;import{Account as nn,Message as an,Mnemonic as sn,UserSecretKey as G}from"@multiversx/sdk-core";import{getWarpWalletAddressFromConfig as on,getWarpWalletMnemonicFromConfig as cn,getWarpWalletPrivateKeyFromConfig as Nt,setWarpWalletInConfig as Vt}from"@vleap/warps";var O=class O{constructor(e,t){this.config=e;this.chain=t;this.account=null}async getAddress(){let e=on(this.config,this.chain.name);if(e)return e;try{return this.getAccount().address.toBech32()}catch{return null}}async getPublicKey(){try{return this.getAccount().publicKey.hex()}catch{return null}}async signTransaction(e){return await this.getAccount().signTransaction(e),e}async signMessage(e){let t=this.getAccount(),r=new TextEncoder().encode(e),n=await t.signMessage(new an({data:r}));return Buffer.from(n).toString("hex")}getAccountInstance(){return this.getAccount()}async importFromMnemonic(e){let r=sn.fromString(e).deriveKey(0),n=r.hex(),i=r.generatePublicKey().toAddress(this.chain.addressHrp).toBech32(),o={provider:O.PROVIDER_NAME,address:i,privateKey:n,mnemonic:e};return Vt(this.config,this.chain.name,o),o}async importFromPrivateKey(e){let r=e.startsWith("-----")?G.fromPem(e):G.fromString(e),n=r.hex(),i=r.generatePublicKey().toAddress(this.chain.addressHrp).toBech32(),o={provider:O.PROVIDER_NAME,address:i,privateKey:n,mnemonic:null};return Vt(this.config,this.chain.name,o),o}async export(){let e=this.getAccount(),t=Nt(this.config,this.chain.name),r=cn(this.config,this.chain.name);return{provider:O.PROVIDER_NAME,address:e.address.toBech32(),privateKey:t||null,mnemonic:r||null}}async generate(){let e=G.generate(),t=e.hex(),n=e.generatePublicKey().toAddress(this.chain.addressHrp).toBech32();return{provider:O.PROVIDER_NAME,address:n,privateKey:t,mnemonic:null}}getAccount(){if(this.account)return this.account;let e=Nt(this.config,this.chain.name);if(!e)throw new Error("No private key provided");let r=e.startsWith("-----")?G.fromPem(e):G.fromString(e);return this.account=new nn(r),this.account}};O.PROVIDER_NAME="privateKey";var L=O;import{getWarpWalletAddressFromConfig as z}from"@vleap/warps";var K=class{constructor(e,t){this.config=e;this.chain=t}async getAddress(){return z(this.config,this.chain.name)}async getPublicKey(){return null}async signTransaction(e){let t=await this.getAddress();throw new Error(`Wallet can not be used for signing: ${t}`)}async signMessage(e){let t=await this.getAddress();throw new Error(`Wallet can not be used for signing: ${t}`)}async importFromMnemonic(e){let t=z(this.config,this.chain.name);throw new Error(`Wallet can not be used for signing: ${t}`)}async importFromPrivateKey(e){let t=z(this.config,this.chain.name);throw new Error(`Wallet can not be used for signing: ${t}`)}async export(){let e=z(this.config,this.chain.name);throw new Error(`Wallet can not be used for signing: ${e}`)}async generate(){let e=z(this.config,this.chain.name);throw new Error(`Wallet can not be used for signing: ${e}`)}};var me=class{constructor(e,t){this.config=e;this.chain=t;this.cachedAddress=null;this.cachedPublicKey=null;this.entry=v(t,e.env,e),this.cache=new un(e.cache?.type),this.walletProvider=this.createProvider(),this.initializeCache()}async signTransaction(e){if(!e||typeof e!="object")throw new Error("Invalid transaction object");if(!this.walletProvider)throw new Error("No wallet provider available");if(this.walletProvider instanceof K)throw new Error(`Wallet (${this.chain.name}) is read-only`);if(this.walletProvider instanceof L||this.walletProvider instanceof D){let r=this.walletProvider.getAccountInstance();if(e.nonce===0n){let n=await this.entry.recallAccountNonce(r.address),a=this.cache.get(`nonce:${r.address.toBech32()}`)||0,i=BigInt(Math.max(a,Number(n)));e.nonce=i}}else if(e.nonce===0n&&this.cachedAddress){let r=ln.newFromBech32(this.cachedAddress),n=await this.entry.recallAccountNonce(r),a=this.cache.get(`nonce:${this.cachedAddress}`)||0,i=BigInt(Math.max(a,Number(n)));e.nonce=i}let t=await this.walletProvider.signTransaction(e);if(this.walletProvider instanceof L||this.walletProvider instanceof D){let r=this.walletProvider.getAccountInstance(),n=Number(r.nonce)+1;this.cache.set(`nonce:${r.address.toBech32()}`,n,Ut.OneMinute)}else if(this.cachedAddress){let r=e.nonce?Number(e.nonce):0;this.cache.set(`nonce:${this.cachedAddress}`,r+1,Ut.OneMinute)}return t}async signTransactions(e){let t=[];for(let r of e)t.push(await this.signTransaction(r));return t}async signMessage(e){if(!this.walletProvider)throw new Error("No wallet provider available");if(this.walletProvider instanceof K)throw new Error(`Wallet (${this.chain.name}) is read-only`);return await this.walletProvider.signMessage(e)}async sendTransactions(e){return Promise.all(e.map(async t=>this.sendTransaction(t)))}async sendTransaction(e){if(!e||typeof e!="object")throw new Error("Invalid transaction object");if(!e.signature)throw new Error("Transaction must be signed before sending");return await this.entry.sendTransaction(e)}async importFromMnemonic(e){return await this.createProviderForOperation("mnemonic").importFromMnemonic(e)}async importFromPrivateKey(e){return await this.createProviderForOperation("privateKey").importFromPrivateKey(e)}async export(e){return await this.createProviderForOperation(e).export()}async generate(e){return await this.createProviderForOperation(e).generate()}getAddress(){return this.cachedAddress}getPublicKey(){return this.cachedPublicKey}createProvider(){let e=this.config.user?.wallets?.[this.chain.name];return e?typeof e=="string"?new K(this.config,this.chain):this.createProviderForOperation(e.provider):null}initializeCache(){pn(this.walletProvider).then(e=>{this.cachedAddress=e.address,this.cachedPublicKey=e.publicKey})}createProviderForOperation(e){let r=this.config.walletProviders?.[this.chain.name]?.[e];if(r){let n=r(this.config,this.chain);if(!n)throw new Error(`Custom wallet provider factory returned null for ${e}`);return n}if(e==="privateKey")return new L(this.config,this.chain);if(e==="mnemonic")return new D(this.config,this.chain);throw new Error(`Unsupported wallet provider for ${this.chain.name}: ${e}`)}};var de=(s,e)=>(t,r)=>{let n=e[t.env],a=new mn;return a.registerType("token",{stringToNative:i=>i,nativeToString:i=>`token:${i}`}),a.registerType("codemeta",{stringToNative:i=>i,nativeToString:i=>`codemeta:${i}`}),a.registerTypeAlias("list","vector"),{chainInfo:n,builder:()=>new J(t,n),executor:new ce(t,n,a),output:new R(t,n,a),serializer:new B({typeRegistry:a}),registry:new ue(t,n),explorer:new le(s,t),abiBuilder:()=>new S(t,n),brandBuilder:()=>new X(t,n),dataLoader:new Z(t,n),wallet:new me(t,n)}};import{WarpChainName as q}from"@vleap/warps";var Re={chain:q.Multiversx,identifier:"EGLD",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://joai.ai/images/tokens/egld.svg"},kt=de(q.Multiversx,{mainnet:{name:q.Multiversx,displayName:"MultiversX",chainId:"1",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://api.multiversx.com",logoUrl:"https://joai.ai/images/chains/multiversx.svg",nativeToken:Re},testnet:{name:q.Multiversx,displayName:"MultiversX Testnet",chainId:"T",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://testnet-api.multiversx.com",logoUrl:"https://joai.ai/images/chains/multiversx.svg",nativeToken:Re},devnet:{name:q.Multiversx,displayName:"MultiversX Devnet",chainId:"D",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://devnet-api.multiversx.com",logoUrl:"https://joai.ai/images/chains/multiversx.svg",nativeToken:Re}});import{WarpChainName as Le}from"@vleap/warps";var dn={chain:Le.Vibechain,identifier:"VIBE",name:"VIBE",symbol:"VIBE",decimals:18,logoUrl:"https://joai.ai/images/tokens/vibe.svg"},De={name:Le.Vibechain,displayName:"VibeChain",chainId:"V",blockTime:600,addressHrp:"vibe",defaultApiUrl:"https://vibeox-api.multiversx.com",logoUrl:"https://joai.ai/images/chains/vibechain.svg",nativeToken:dn},Ft=de(Le.Vibechain,{mainnet:De,testnet:De,devnet:De});var jo=()=>[kt,Ft];import{WarpConstants as he,WarpSerializer as Ke}from"@vleap/warps";var Zo=s=>new Ke().nativeToString(f.Token,s),ec=s=>new Ke().nativeToString(f.CodeMeta,s),tc=(s,e)=>{if(e===null)return f.Optional+he.ArgParamsSeparator;let t=s(e),r=t.indexOf(he.ArgParamsSeparator),n=t.substring(0,r),a=t.substring(r+1);return f.Optional+he.ArgParamsSeparator+n+he.ArgParamsSeparator+a},rc=s=>new Ke().nativeToString(f.List,s);import{Address as hn,AddressValue as gn,BigUIntType as fn,BigUIntValue as Ot,BooleanValue as yn,BytesValue as Wn,CodeMetadata as vn,CodeMetadataValue as wn,CompositeType as Tn,CompositeValue as Cn,Field as _e,FieldDefinition as $e,List as An,NothingValue as xn,OptionalValue as He,OptionValue as Ge,StringValue as En,Struct as bn,StructType as Pn,TokenIdentifierType as In,TokenIdentifierValue as Mt,U16Value as Sn,U32Value as Bn,U64Type as Nn,U64Value as Rt,U8Value as Vn,VariadicValue as Un}from"@multiversx/sdk-core";var cc=(s,e)=>s?Ge.newProvided(s):e?Ge.newMissingTyped(e):Ge.newMissing(),lc=(s,e)=>s?new He(s.getType(),s):e?new He(e):He.newMissing(),pc=s=>{if(s.length===0)throw new Error("Cannot create a list from an empty array");let e=s[0].getType();return new An(e,s)},uc=s=>Un.fromItems(...s),mc=s=>{let e=s.map(t=>t.getType());return new Cn(new Tn(...e),s)},dc=s=>En.fromUTF8(s),hc=s=>new Vn(s),gc=s=>new Sn(s),fc=s=>new Bn(s),yc=s=>new Rt(s),Wc=s=>new Ot(BigInt(s)),vc=s=>new yn(s),wc=s=>new gn(hn.newFromBech32(s)),Tc=s=>new Mt(s),Cc=s=>Wn.fromHex(s),Ac=s=>new bn(new Pn("EsdtTokenPayment",[new $e("token_identifier","",new In),new $e("token_nonce","",new Nn),new $e("amount","",new fn)]),[new _e(new Mt(s.token.identifier),"token_identifier"),new _e(new Rt(BigInt(s.token.nonce)),"token_nonce"),new _e(new Ot(BigInt(s.amount)),"amount")]),xc=s=>new wn(vn.newFromBytes(Uint8Array.from(Buffer.from(s,"hex")))),Ec=()=>new xn;export{U as ExplorerUrls,ot as KnownTokens,kt as MultiversxAdapter,wr as MultiversxExplorers,lt as MultiversxExplorersConfig,Re as NativeTokenEgld,dn as NativeTokenVibe,Ft as VibechainAdapter,Tr as VibechainExplorers,S as WarpMultiversxAbiBuilder,X as WarpMultiversxBrandBuilder,J as WarpMultiversxBuilder,hi as WarpMultiversxConstants,Q as WarpMultiversxContractLoader,Z as WarpMultiversxDataLoader,ce as WarpMultiversxExecutor,le as WarpMultiversxExplorer,f as WarpMultiversxInputTypes,R as WarpMultiversxOutput,ue as WarpMultiversxRegistry,B as WarpMultiversxSerializer,me as WarpMultiversxWallet,wc as address_value,Ac as asset_value,Wc as biguint_value,vc as boolean_value,ec as codemeta,xc as codemeta_value,mc as composite_value,de as createMultiversxAdapter,ct as findKnownTokenById,jo as getAllMultiversxAdapters,Fn as getAllMultiversxChainNames,Ja as getKnownTokensForChain,v as getMultiversxEntrypoint,E as getMultiversxRegistryAddress,j as getNormalizedTokenIdentifier,Cc as hex_value,M as isNativeToken,rc as list,pc as list_value,Ec as nothing_value,cc as option_value,tc as optional,lc as optional_value,dc as string_value,Pt as toTypedConfigInfo,pe as toTypedRegistryInfo,Zo as token,Tc as token_value,gc as u16_value,fc as u32_value,yc as u64_value,hc as u8_value,uc as variadic_value};
1
+ import{WarpChainName as ze}from"@vleap/warps";var On=()=>[ze.Multiversx,ze.Vibechain];import{WarpTypeRegistry as dn}from"@vleap/warps";import{AbiRegistry as ge,Address as Ht,TransactionsFactoryConfig as Gt,TransferTransactionsFactory as zt}from"@multiversx/sdk-core";import{createWarpIdentifier as qt,getLatestProtocolIdentifier as jt,getWarpWalletAddressFromConfig as Qt,WarpCache as Xt,WarpCacheKey as Jt,WarpConstants as je,WarpLogger as Qe}from"@vleap/warps";import{DevnetEntrypoint as Lt,MainnetEntrypoint as Kt,TestnetEntrypoint as _t}from"@multiversx/sdk-core";import{getProviderConfig as $t}from"@vleap/warps";var M=s=>!s.includes("-"),j=s=>M(s)?`${s}-000000`:s,v=(s,e,t)=>{let r="warp-sdk",a=t?$t(t,s.name,e,s.defaultApiUrl):{url:s.defaultApiUrl},i=a.url,o={headers:a.headers};return e==="devnet"?new Lt({url:i,kind:"api",clientName:r,networkProviderConfig:o}):e==="testnet"?new _t({url:i,kind:"api",clientName:r,networkProviderConfig:o}):new Kt({url:i,kind:"api",clientName:r,networkProviderConfig:o})};import{WarpLogger as qe}from"@vleap/warps";var Q=class{constructor(e){this.config=e}async getContract(e,t){try{let a=await v(t,this.config.env,this.config).createNetworkProvider().doGetGeneric(`accounts/${e}`);return{address:e,owner:a.ownerAddress,verified:a.isVerified||!1}}catch(r){return qe.error("WarpContractLoader: getContract error",r),null}}async getVerificationInfo(e,t){try{let a=await v(t,this.config.env,this.config).createNetworkProvider().doGetGeneric(`accounts/${e}/verification`);return{codeHash:a.codeHash,abi:a.source.abi}}catch(r){return qe.error("WarpContractLoader: getVerificationInfo error",r),null}}};var S=class{constructor(e,t){this.config=e;this.chain=t;this.contractLoader=new Q(this.config),this.cache=new Xt(this.config.cache?.type)}async createInscriptionTransaction(e){let t=Qt(this.config,this.chain.name);if(!t)throw new Error("WarpBuilder: user address not set");let r=new Gt({chainID:this.chain.chainId}),n=new zt({config:r}),a=Ht.newFromBech32(t),i={protocol:jt("abi"),content:e},o=JSON.stringify(i),c=await n.createTransactionForTransfer(a,{receiver:a,nativeAmount:BigInt(0),data:Uint8Array.from(Buffer.from(o))});return c.gasLimit=c.gasLimit+BigInt(2e6),c}async createFromRaw(e){return JSON.parse(e)}async createFromTransaction(e){let t=await this.createFromRaw(e.data.toString());return t.meta={chain:this.chain.name,identifier:qt(this.chain.name,"hash",e.hash),query:null,hash:e.hash,creator:e.sender.toBech32(),createdAt:new Date(e.timestamp*1e3).toISOString()},t}async createFromTransactionHash(e,t){let r=Jt.WarpAbi(this.config.env,e);if(t){let i=this.cache.get(r);if(i)return Qe.info(`WarpAbiBuilder (createFromTransactionHash): Warp abi found in cache: ${e}`),i}let a=v(this.chain,this.config.env,this.config).createNetworkProvider();try{let i=await a.getTransaction(e),o=await this.createFromTransaction(i);return t&&t.ttl&&o&&this.cache.set(r,o,t.ttl),o}catch(i){return Qe.error("WarpAbiBuilder: Error creating from transaction hash",i),null}}async getAbiForAction(e){if(e.abi)return await this.fetchAbi(e);if(!e.address)throw new Error("WarpActionExecutor: Address not found");let t=await this.contractLoader.getVerificationInfo(e.address,this.chain);if(!t)throw new Error("WarpActionExecutor: Verification info not found");return ge.create(t.abi)}async fetchAbi(e){if(!e.abi)throw new Error("WarpActionExecutor: ABI not found");if(e.abi.startsWith(je.IdentifierType.Hash)){let t=e.abi.split(je.ArgParamsSeparator)[1],r=await this.createFromTransactionHash(t);if(!r)throw new Error(`WarpActionExecutor: ABI not found for hash: ${e.abi}`);return ge.create(r.content)}else{let r=await(await fetch(e.abi)).json();return ge.create(r)}}};import{Address as Xe,TransactionsFactoryConfig as Yt,TransferTransactionsFactory as Zt}from"@multiversx/sdk-core";import{createWarpIdentifier as er,getWarpWalletAddressFromConfig as tr,WarpBrandBuilder as rr,WarpLogger as nr}from"@vleap/warps";import{Buffer as ar}from"buffer";var X=class{constructor(e,t){this.config=e;this.chain=t;this.core=new rr(e)}async createInscriptionTransaction(e){let t=tr(this.config,this.chain.name);if(!t)throw new Error("BrandBuilder: user address not set");let r=new Yt({chainID:this.chain.chainId}),n=new Zt({config:r}),a=Xe.newFromBech32(t),i=JSON.stringify(e);return await n.createTransactionForNativeTokenTransfer(a,{receiver:Xe.newFromBech32(t),nativeAmount:BigInt(0),data:Uint8Array.from(ar.from(i))})}async createFromTransaction(e,t=!1){let r=await this.core.createFromRaw(e.data.toString(),t);return r.meta={query:null,chain:this.chain.name,identifier:er(this.chain.name,"hash",e.hash),hash:e.hash,creator:e.sender.toBech32(),createdAt:new Date(e.timestamp*1e3).toISOString()},r}async createFromTransactionHash(e){let r=v(this.chain,this.config.env,this.config).createNetworkProvider();try{let n=await r.getTransaction(e);return this.createFromTransaction(n)}catch(n){return nr.error("BrandBuilder: Error creating from transaction hash",n),null}}};import{Address as Je,TransactionsFactoryConfig as ir,TransferTransactionsFactory as sr}from"@multiversx/sdk-core";import{createWarpIdentifier as or,getWarpWalletAddressFromConfig as cr,WarpBuilder as Ye,WarpCache as lr,WarpCacheKey as pr,WarpLogger as Ze}from"@vleap/warps";var J=class extends Ye{constructor(t,r){super(t);this.config=t;this.chain=r;this.cache=new lr(t.cache?.type),this.core=new Ye(t)}async createInscriptionTransaction(t){let r=cr(this.config,this.chain.name);if(!r)throw new Error("WarpBuilder: user address not set");let n=new ir({chainID:this.chain.chainId}),a=new sr({config:n}),i=Je.newFromBech32(r),o=JSON.stringify(t),c=await a.createTransactionForTransfer(i,{receiver:Je.newFromBech32(r),nativeAmount:BigInt(0),data:Uint8Array.from(Buffer.from(o))});return c.gasLimit=c.gasLimit+BigInt(2e6),c}async createFromTransaction(t,r=!1){let n=await this.core.createFromRaw(t.data.toString(),r);return n.meta={chain:this.chain.name,identifier:or(this.chain.name,"hash",t.hash),query:null,hash:t.hash,creator:t.sender.toBech32(),createdAt:new Date(t.timestamp*1e3).toISOString()},n}async createFromTransactionHash(t,r){let n=pr.Warp(this.config.env,t);if(r){let o=this.cache.get(n);if(o)return Ze.info(`WarpBuilder (createFromTransactionHash): Warp found in cache: ${t}`),o}let i=v(this.chain,this.config.env,this.config).createNetworkProvider();try{let o=await i.getTransaction(t),c=await this.createFromTransaction(o);return r&&r.ttl&&c&&this.cache.set(n,c,r.ttl),c}catch(o){return Ze.error("WarpBuilder: Error creating from transaction hash",o),null}}};import{Address as fe,Token as gr,TokenComputer as fr}from"@multiversx/sdk-core";import{CacheTtl as yr,WarpCache as Wr,WarpCacheKey as vr}from"@vleap/warps";import{WarpChainName as st}from"@vleap/warps";import{WarpChainName as ur}from"@vleap/warps";var et=ur.Multiversx,tt=[{chain:et,identifier:"EGLD",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"},{chain:et,identifier:"EGLD-000000",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"}];import{WarpChainName as mr}from"@vleap/warps";var A=mr.Multiversx,rt=[{chain:A,identifier:"EGLD",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"},{chain:A,identifier:"EGLD-000000",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"},{chain:A,identifier:"SEGLD-3ad2d0",name:"StakedEGLD",symbol:"SEGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/SEGLD-3ad2d0/icon.png"},{chain:A,identifier:"HSEGLD-c13a4e",name:"HatomSEGLD",symbol:"HSEGLD",decimals:8,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/HSEGLD-c13a4e/icon.png"},{chain:A,identifier:"UTK-2f80e9",name:"xMoney UTK",symbol:"UTK",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/UTK-2f80e9/icon.png"},{chain:A,identifier:"USDC-c76f1f",name:"WrappedUSDC",symbol:"USDC",decimals:6,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/USDC-c76f1f/icon.png"},{chain:A,identifier:"WEGLD-bd4d79",name:"WrappedEGLD",symbol:"WEGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/WEGLD-bd4d79/icon.png"},{chain:A,identifier:"HTM-f51d55",name:"Hatom",symbol:"HTM",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/HTM-f51d55/icon.png"},{chain:A,identifier:"MEX-455c57",name:"MEX",symbol:"MEX",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/MEX-455c57/icon.png"},{chain:A,identifier:"WTAO-4f5363",name:"WrappedTAO",symbol:"WTAO",decimals:9,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/WTAO-4f5363/icon.png"},{chain:A,identifier:"HEGLD-d61095",name:"HatomEGLD",symbol:"HEGLD",decimals:8,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/HEGLD-d61095/icon.png"},{chain:A,identifier:"WBTC-5349b3",name:"WrappedBTC",symbol:"WBTC",decimals:8,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/WBTC-5349b3/icon.png"},{chain:A,identifier:"WETH-b4ca29",name:"WrappedETH",symbol:"WETH",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/WETH-b4ca29/icon.png"},{chain:A,identifier:"USH-111e09",name:"HatomUSD",symbol:"USH",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/USH-111e09/icon.png"},{chain:A,identifier:"USDT-f8c08c",name:"WrappedUSDT",symbol:"USDT",decimals:6,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/USDT-f8c08c/icon.png"}];import{WarpChainName as dr}from"@vleap/warps";var nt=dr.Multiversx,at=[{chain:nt,identifier:"EGLD",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"},{chain:nt,identifier:"EGLD-000000",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"}];import{WarpChainName as hr}from"@vleap/warps";var it=hr.Vibechain,Y=[{chain:it,identifier:"VIBE",name:"VIBE",symbol:"VIBE",decimals:18,logoUrl:"https://joai.ai/images/tokens/vibe.svg"},{chain:it,identifier:"VIBE-000000",name:"VIBE",symbol:"VIBE",decimals:18,logoUrl:"https://joai.ai/images/tokens/vibe.svg"}];var ot={[st.Multiversx]:{mainnet:rt,testnet:at,devnet:tt},[st.Vibechain]:{mainnet:Y,testnet:Y,devnet:Y}},ct=(s,e,t)=>(ot[s]?.[e]||[]).find(n=>n.identifier===t)||null,Ya=(s,e)=>ot[s]?.[e]||[];var Z=class{constructor(e,t){this.config=e;this.chain=t;this.cache=new Wr(e.cache?.type)}async getAccount(e){let r=await v(this.chain,this.config.env,this.config).createNetworkProvider().getAccount(fe.newFromBech32(e));return{chain:this.chain.name,address:r.address.toBech32(),balance:r.balance}}async getAccountAssets(e){let t=v(this.chain,this.config.env,this.config).createNetworkProvider(),r=t.getAccount(fe.newFromBech32(e)),n=t.getFungibleTokensOfAccount(fe.newFromBech32(e)),[a,i]=await Promise.all([r,n]),o=a.balance>0?[{...this.chain.nativeToken,amount:a.balance}]:[];return o.push(...i.map(c=>({chain:this.chain.name,identifier:c.token.identifier,name:c.raw.name,symbol:c.raw.ticker,amount:c.amount,decimals:c.raw.decimals,logoUrl:c.raw.assets?.pngUrl||"",price:c.raw.price?Number(c.raw.price):void 0,supply:c.raw.supply?BigInt(c.raw.supply):void 0}))),o}async getAsset(e){let t=vr.Asset(this.config.env,this.chain.name,e),r=this.cache.get(t);if(r)return r;let n=ct(this.chain.name,this.config.env,e);if(n)return{chain:this.chain.name,identifier:e,name:n.name,symbol:n.symbol,amount:0n,decimals:n.decimals,logoUrl:n.logoUrl};let a=new fr,i=M(e)?0n:a.extractNonceFromExtendedIdentifier(e),o=new gr({identifier:e,nonce:BigInt(i||0)}),c=a.isFungible(o),d=v(this.chain,this.config.env,this.config).createNetworkProvider(),m=j(e),p=await d.doGetGeneric(`tokens/${m}`),W={chain:this.chain.name,identifier:o.identifier,name:p.name,symbol:p.ticker,amount:0n,decimals:p.decimals,logoUrl:p.assets?.pngUrl||null,price:p.price?Number(p.price):void 0,supply:p.supply?BigInt(p.supply):void 0};return this.cache.set(t,W,yr.OneHour),W}async getAction(e,t=!1){let r=v(this.chain,this.config.env,this.config),n=t?await r.awaitCompletedTransaction(e):await r.getTransaction(e);return{chain:this.chain.name,id:n.hash,receiver:n.receiver.toBech32(),sender:n.sender.toBech32(),value:n.value,function:n.function,status:this.toActionStatus(n),createdAt:this.toActionCreatedAt(n),error:n?.smartContractResults.map(a=>a.raw.returnMessage)[0]||null,tx:n}}async getAccountActions(e,t){let r=v(this.chain,this.config.env,this.config).createNetworkProvider(),n=`accounts/${e}/transactions`,a=new URLSearchParams,i=t?.size||25,o=t?.page||0;if(o>0){let d=o*i;a.append("from",d.toString())}return i!==25&&a.append("size",i.toString()),a.toString()&&(n+=`?${a.toString()}`),(await r.doGetGeneric(n)).map(d=>({chain:this.chain.name,id:d.txHash,receiver:d.receiver,sender:d.sender,value:d.value,function:d.function,status:this.toActionStatus(d),createdAt:this.toActionCreatedAt(d)}))}toActionStatus(e){return e.status.isSuccessful()?"success":e.status.isFailed()?"failed":"pending"}toActionCreatedAt(e){return new Date(e.timestamp||e.timestamp*1e3).toISOString()}};import{Address as H,ArgSerializer as Mr,SmartContractTransactionsFactory as Rr,Token as Dr,TokenComputer as Lr,TokenTransfer as Kr,TransactionsFactoryConfig as bt,TransferTransactionsFactory as _r}from"@multiversx/sdk-core";import{applyOutputToMessages as $r,extractResolvedInputValues as Hr,getNextInfo as Gr,getWarpActionByIndex as Ne,getWarpWalletAddressFromConfig as Ve}from"@vleap/warps";import{findEventsByFirstTopic as Pr,SmartContractTransactionsOutcomeParser as Ir,TransactionEventsParser as Sr}from"@multiversx/sdk-core";import{applyOutputToMessages as Br,evaluateOutputCommon as oe,extractResolvedInputValues as Nr,getNextInfo as Vr,getWarpActionByIndex as Ur,getWarpWalletAddressFromConfig as kr,parseOutputOutIndex as xt,WarpCache as Fr,WarpCacheKey as Or,WarpConstants as Et}from"@vleap/warps";import{Address as Cr,AddressType as ye,AddressValue as pt,BigUIntType as ee,BigUIntValue as We,BooleanType as ve,BooleanValue as ut,BytesType as we,BytesValue as mt,CodeMetadata as Ar,CodeMetadataType as Te,CodeMetadataValue as dt,CompositeType as Ce,CompositeValue as ht,Field as te,FieldDefinition as re,List as gt,ListType as ft,NothingValue as b,OptionalType as yt,OptionalValue as Ae,OptionType as Wt,OptionValue as xe,StringType as Ee,StringValue as vt,Struct as ne,StructType as k,Token as xr,TokenComputer as wt,TokenIdentifierType as ae,TokenIdentifierValue as be,U16Type as Pe,U16Value as Tt,U32Type as Ie,U32Value as Ct,U64Type as ie,U64Value as Se,U8Type as Be,U8Value as At,VariadicType as $,VariadicValue as se}from"@multiversx/sdk-core";import{WarpSerializer as Er}from"@vleap/warps";var u={HttpProtocolPrefix:"http",IdentifierParamName:"warp",IdentifierParamSeparator:":",IdentifierChainDefault:"multiversx",IdentifierType:{Alias:"alias",Hash:"hash"},IdentifierAliasMarker:"@",Globals:{UserWallet:{Placeholder:"USER_WALLET",Accessor:s=>s.config.user?.wallets?.[s.adapter.chainInfo.name]},UserWalletPublicKey:{Placeholder:"USER_WALLET_PUBLICKEY",Accessor:s=>{if(!s.adapter.wallet)return null;try{return s.adapter.wallet.getPublicKey()||null}catch{return null}}},ChainApiUrl:{Placeholder:"CHAIN_API",Accessor:s=>s.adapter.chainInfo.defaultApiUrl},ChainAddressHrp:{Placeholder:"CHAIN_ADDRESS_HRP",Accessor:s=>s.adapter.chainInfo.addressHrp}},Vars:{Query:"query",Env:"env"},ArgParamsSeparator:":",ArgCompositeSeparator:"|",ArgListSeparator:",",ArgStructSeparator:";",Transform:{Prefix:"transform:"},Source:{UserWallet:"user:wallet"},Position:{Payload:"payload:"},Alerts:{TriggerEventPrefix:"event"}},l={Option:"option",Vector:"vector",Tuple:"tuple",Struct:"struct",String:"string",Uint8:"uint8",Uint16:"uint16",Uint32:"uint32",Uint64:"uint64",Uint128:"uint128",Uint256:"uint256",Biguint:"biguint",Bool:"bool",Address:"address",Asset:"asset",Hex:"hex"};var gi={Egld:{Identifier:"EGLD",EsdtIdentifier:"EGLD-000000",DisplayName:"eGold",Decimals:18}},f={Null:"null",Optional:"optional",List:"list",Token:"token",CodeMeta:"codemeta"},wr=(r=>(r.MultiversxExplorer="multiversx_explorer",r.MultiversxExplorerDevnet="multiversx_explorer_devnet",r.MultiversxExplorerTestnet="multiversx_explorer_testnet",r))(wr||{}),Tr=(r=>(r.VibechainExplorer="vibechain_explorer",r.VibechainExplorerDevnet="vibechain_explorer_devnet",r.VibechainExplorerTestnet="vibechain_explorer_testnet",r))(Tr||{}),lt={multiversx:{mainnet:["multiversx_explorer"],testnet:["multiversx_explorer_testnet"],devnet:["multiversx_explorer_devnet"]},vibechain:{mainnet:["vibechain_explorer"],testnet:["vibechain_explorer_testnet"],devnet:["vibechain_explorer_devnet"]}},U={multiversx_explorer:"https://explorer.multiversx.com",multiversx_explorer_devnet:"https://devnet-explorer.multiversx.com",multiversx_explorer_testnet:"https://testnet-explorer.multiversx.com",vibechain_explorer:"https://vibeox-explorer.multiversx.com",vibechain_explorer_devnet:"https://vibeox-explorer.multiversx.com",vibechain_explorer_testnet:"https://vibeox-explorer.multiversx.com"};var br=new RegExp(`${u.ArgParamsSeparator}(.*)`),B=class{constructor(e){this.coreSerializer=new Er(e)}typedToString(e){let t=e.getType();if(t.hasExactClass(Wt.ClassName)||e.hasClassOrSuperclass(xe.ClassName)){if(!e.isSet())return l.Option+u.ArgParamsSeparator+"null";let r=this.typedToString(e.getTypedValue());return l.Option+u.ArgParamsSeparator+r}if(t.hasExactClass($.ClassName)||e.hasClassOrSuperclass(se.ClassName)){let r=e.getItems();if(r.length===0){let m=this.typeToString(t.getFirstTypeParameter());return l.Vector+u.ArgParamsSeparator+m+u.ArgParamsSeparator}let n=r.map(m=>this.typedToString(m));if(n.every(m=>m.startsWith(l.Tuple)))return l.Vector+u.ArgParamsSeparator+n.join(",");let a=n[0],i=a.indexOf(u.ArgParamsSeparator),o=a.substring(0,i),c=n.map(m=>{let p=m.indexOf(u.ArgParamsSeparator);return m.substring(p+1)}),d=o.startsWith(l.Struct)?u.ArgStructSeparator:u.ArgListSeparator;return l.Vector+u.ArgParamsSeparator+o+u.ArgParamsSeparator+c.join(d)}if(t.hasExactClass(yt.ClassName)||e.hasClassOrSuperclass(Ae.ClassName)){if(!e.isSet())return f.Optional+u.ArgParamsSeparator+"null";let r=this.typedToString(e.getTypedValue());return f.Optional+u.ArgParamsSeparator+r}if(t.hasExactClass(ft.ClassName)||e.hasClassOrSuperclass(gt.ClassName)){let n=e.getItems().map(c=>this.typedToString(c));if(n.every(c=>c.startsWith(l.Tuple)))return f.List+u.ArgParamsSeparator+n.join(",");let i=n.map(c=>c.split(u.ArgParamsSeparator)[0])[0],o=n.map(c=>c.split(u.ArgParamsSeparator)[1]);return f.List+u.ArgParamsSeparator+i+u.ArgParamsSeparator+o.join(u.ArgListSeparator)}if(t.hasExactClass(Ce.ClassName)||e.hasClassOrSuperclass(ht.ClassName)){let n=e.getItems().map(a=>{let i=this.typedToString(a),o=i.indexOf(u.ArgParamsSeparator),c=i.substring(0,o),d=i.substring(o+1);return`${c},${d}`});return`${l.Tuple}(${n.join(",")})`}if(t.hasExactClass(ee.ClassName)||e.hasClassOrSuperclass(We.ClassName)||t.getName()==="BigUint")return l.Biguint+u.ArgParamsSeparator+BigInt(e.valueOf().toFixed());if(t.hasExactClass(Be.ClassName)||e.hasClassOrSuperclass(At.ClassName))return l.Uint8+u.ArgParamsSeparator+e.valueOf().toNumber();if(t.hasExactClass(Pe.ClassName)||e.hasClassOrSuperclass(Tt.ClassName))return l.Uint16+u.ArgParamsSeparator+e.valueOf().toNumber();if(t.hasExactClass(Ie.ClassName)||e.hasClassOrSuperclass(Ct.ClassName))return l.Uint32+u.ArgParamsSeparator+e.valueOf().toNumber();if(t.hasExactClass(ie.ClassName)||e.hasClassOrSuperclass(Se.ClassName))return l.Uint64+u.ArgParamsSeparator+BigInt(e.valueOf().toFixed());if(t.hasExactClass(Ee.ClassName)||e.hasClassOrSuperclass(vt.ClassName))return l.String+u.ArgParamsSeparator+e.valueOf();if(t.hasExactClass(ve.ClassName)||e.hasClassOrSuperclass(ut.ClassName))return l.Bool+u.ArgParamsSeparator+e.valueOf();if(t.hasExactClass(ye.ClassName)||e.hasClassOrSuperclass(pt.ClassName))return l.Address+u.ArgParamsSeparator+e.valueOf().toBech32();if(t.hasExactClass(we.ClassName)||e.hasClassOrSuperclass(mt.ClassName))return l.Hex+u.ArgParamsSeparator+e.valueOf().toString("hex");if(t.getName()==="EsdtTokenPayment"){let r=e.getFieldValue("token_identifier").valueOf(),n=e.getFieldValue("token_nonce").valueOf(),a=e.getFieldValue("amount").valueOf(),o=new wt().computeExtendedIdentifier(new xr({identifier:r,nonce:BigInt(n)}));return l.Asset+u.ArgParamsSeparator+o+u.ArgCompositeSeparator+a}if(t.hasExactClass(k.ClassName)||e.hasClassOrSuperclass(ne.ClassName)){let r=e,a=r.getType().getName(),i=r.getFields();if(i.length===0)return`${l.Struct}(${a})${u.ArgParamsSeparator}`;let o=i.map(c=>{let d=c.value.getType(),p=this.typedToString(c.value).split(u.ArgParamsSeparator),W=p.length>2?p.slice(2).join(u.ArgParamsSeparator):p[1]||"";return`(${c.name}${u.ArgParamsSeparator}${this.typeToString(d)})${W}`});return`${l.Struct}(${a})${u.ArgParamsSeparator}${o.join(u.ArgListSeparator)}`}if(t.hasExactClass(ae.ClassName)||e.hasClassOrSuperclass(be.ClassName))return f.Token+u.ArgParamsSeparator+e.valueOf();if(t.hasExactClass(Te.ClassName)||e.hasClassOrSuperclass(dt.ClassName))return f.CodeMeta+u.ArgParamsSeparator+e.valueOf().toString();throw new Error(`WarpArgSerializer (typedToString): Unsupported input type: ${e.getClassName()}`)}typedToNative(e){let t=this.typedToString(e);return this.coreSerializer.stringToNative(t)}nativeToTyped(e,t){if(e.startsWith(l.Tuple))return this.stringToTyped(e+":");let r=this.coreSerializer.nativeToString(e,t);return this.stringToTyped(r)}nativeToType(e){if(e.startsWith(l.Tuple)){let t=e.match(/\(([^)]+)\)/)?.[1];if(!t)throw new Error(`Invalid tuple type format: ${e}`);let r=t.split(","),n=[];for(let a=0;a<r.length;a+=2)n.push(r[a]);return new Ce(...n.map(a=>this.nativeToType(a)))}if(e.startsWith(l.Struct)){let t=e.match(/\(([^)]+)\)/);if(!t)throw new Error("Struct type must include a name in the format struct(Name)");let r=t[1];return new k(r,[])}if(e===l.String)return new Ee;if(e===l.Uint8)return new Be;if(e===l.Uint16)return new Pe;if(e===l.Uint32)return new Ie;if(e===l.Uint64)return new ie;if(e===l.Biguint)return new ee;if(e===l.Bool)return new ve;if(e===l.Address)return new ye;if(e===l.Hex)return new we;if(e===l.Asset)return new k("EsdtTokenPayment",[new re("token_identifier","",new ae),new re("token_nonce","",new ie),new re("amount","",new ee)]);if(e===f.Token)return new ae;if(e===f.CodeMeta)return new Te;throw new Error(`WarpArgSerializer (nativeToType): Unsupported input type: ${e}`)}stringToTyped(e){let[t,r]=e.split(/:(.*)/,2);if(t===l.Option){let n=this.stringToTyped(r);return n instanceof b?xe.newMissingTyped(n.getType()):xe.newProvided(n)}if(t===l.Vector){let n=r.indexOf(u.ArgParamsSeparator),a=r.substring(0,n),i=r.substring(n+1);if(a.startsWith(l.Tuple)){let p=i.split(",").map(W=>this.stringToTyped(W));return new se(new $(this.nativeToType(a)),p)}if(i.includes("tuple(")){let m=this.splitTupleStrings(i),p=m.map(T=>this.stringToTyped(T)),C=m[0].match(/^(tuple\([^)]+\))/),h=C?C[1]:"tuple";return new se(new $(this.nativeToType(h)),p)}let o=a.startsWith(l.Struct)?u.ArgStructSeparator:u.ArgListSeparator,d=i.split(o).map(m=>this.stringToTyped(`${a}:${m}`));return new se(new $(this.nativeToType(a)),d)}if(t.startsWith(l.Tuple)){let n=t.match(/\(([^)]+)\)/)?.[1];if(!n)throw new Error(`Invalid tuple format: ${t}`);let a=n.split(","),i=[];for(let c=0;c<a.length;c+=2){let d=a[c],m=a[c+1];i.push(this.stringToTyped(`${d}:${m}`))}let o=i.map(c=>c.getType());return new ht(new Ce(...o),i)}if(t.startsWith(l.Struct)){let n=t.match(/\(([^)]+)\)/),a=n?n[1]:"CustomStruct";if(!r)return new ne(new k(a,[]),[]);let i=r.split(u.ArgListSeparator),o=[],c=[];return i.forEach(d=>{let m=d.match(new RegExp(`^\\(([^${u.ArgParamsSeparator}]+)${u.ArgParamsSeparator}([^)]+)\\)(.+)$`));if(m){let[,p,W,C]=m,h=this.stringToTyped(`${W}${u.ArgParamsSeparator}${C}`);o.push(new re(p,"",h.getType())),c.push(new te(h,p))}}),new ne(new k(a,o),c)}if(t===l.String)return r?vt.fromUTF8(r):new b;if(t===l.Uint8)return r?new At(Number(r)):new b;if(t===l.Uint16)return r?new Tt(Number(r)):new b;if(t===l.Uint32)return r?new Ct(Number(r)):new b;if(t===l.Uint64)return r?new Se(BigInt(r)):new b;if(t===l.Biguint)return r?new We(BigInt(r)):new b;if(t===l.Bool)return r?new ut(typeof r=="boolean"?r:r==="true"):new b;if(t===l.Address)return r?new pt(Cr.newFromBech32(r)):new b;if(t===l.Hex)return r?mt.fromHex(r):new b;if(t===l.Asset){let[n,a]=r.split(u.ArgCompositeSeparator),i=new wt,o=M(n)?j(n):i.extractIdentifierFromExtendedIdentifier(n),c=M(n)?0n:i.extractNonceFromExtendedIdentifier(n);return new ne(this.nativeToType("asset"),[new te(new be(o),"token_identifier"),new te(new Se(BigInt(c)),"token_nonce"),new te(new We(BigInt(a)),"amount")])}if(t===f.Null)return new b;if(t===f.Optional){let n=this.stringToTyped(r);return n instanceof b?Ae.newMissing():new Ae(n.getType(),n)}if(t===f.List){let[n,a]=r.split(br,2),o=a.split(u.ArgListSeparator).map(c=>this.stringToTyped(n+u.ArgParamsSeparator+c));return new gt(this.nativeToType(n),o)}if(t===f.Token)return r?new be(r):new b;if(t===f.CodeMeta)return new dt(Ar.newFromBytes(Uint8Array.from(Buffer.from(r,"hex"))));throw new Error(`WarpArgSerializer (stringToTyped): Unsupported input type: ${t}`)}splitTupleStrings(e){let t=[],r="",n=0;for(let a=0;a<e.length;a++){let i=e[a];if(i==="(")n++;else if(i===")")n--;else if(i===","&&n===0){t.push(r.trim()),r="";continue}r+=i}return r.trim()&&t.push(r.trim()),t}typeToString(e){if(e.hasExactClass(Wt.ClassName))return l.Option+u.ArgParamsSeparator+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass($.ClassName))return l.Vector+u.ArgParamsSeparator+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(Ee.ClassName))return l.String;if(e.hasExactClass(Be.ClassName))return l.Uint8;if(e.hasExactClass(Pe.ClassName))return l.Uint16;if(e.hasExactClass(Ie.ClassName))return l.Uint32;if(e.hasExactClass(ie.ClassName))return l.Uint64;if(e.hasExactClass(ee.ClassName))return l.Biguint;if(e.hasExactClass(ve.ClassName))return l.Bool;if(e.hasExactClass(ye.ClassName))return l.Address;if(e.hasExactClass(we.ClassName))return l.Hex;if(e.hasExactClass(ae.ClassName))return f.Token;if(e.hasExactClass(yt.ClassName))return f.Optional+u.ArgParamsSeparator+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(ft.ClassName))return f.List+u.ArgParamsSeparator+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(Te.ClassName))return f.CodeMeta;if(e.hasExactClass(k.ClassName)&&e.getClassName()==="EsdtTokenPayment")return l.Asset;if(e.hasExactClass(k.ClassName))return`${l.Struct}(${e.getName()})`;throw new Error(`WarpArgSerializer (typeToString): Unsupported input type: ${e.getClassName()}`)}};var R=class{constructor(e,t,r){this.config=e;this.chain=t;this.typeRegistry=r;this.abi=new S(e,t),this.serializer=new B({typeRegistry:this.typeRegistry}),this.cache=new Fr(e.cache?.type)}async getActionExecution(e,t,r){let n=this.cache.get(Or.WarpExecutable(this.config.env,e.meta?.hash||"",t))??[],a=await this.extractContractOutput(e,t,r,n),i=Vr(this.config,[],e,t,a.output),o=Br(e,a.output,this.config),c=Nr(n);return{status:r.status.isSuccessful()?"success":"error",warp:e,action:t,user:kr(this.config,this.chain.name),txHash:r.hash,tx:r,next:i,values:a.values,output:a.output,messages:o,destination:null,resolvedInputs:c}}async extractContractOutput(e,t,r,n){let a=Ur(e,t),i=[],o=[],c={};if(!e.output||a.type!=="contract")return{values:{string:i,native:o,mapped:{}},output:c};if(!Object.values(e.output).some(h=>h.includes("out")||h.includes("event"))){for(let[h,T]of Object.entries(e.output))c[h]=T;return{values:{string:i,native:o,mapped:{}},output:await oe(e,c,t,n,this.serializer.coreSerializer,this.config)}}let m=await this.abi.getAbiForAction(a),p=new Sr({abi:m}),C=new Ir({abi:m}).parseExecute({transactionOnNetwork:r,function:a.func||void 0});for(let[h,T]of Object.entries(e.output)){if(T.startsWith(Et.Transform.Prefix))continue;if(T.startsWith("input.")){c[h]=T;continue}let x=xt(T);if(x!==null&&x!==t){c[h]=null;continue}let[P,N,V]=T.split(".");if(P==="event"){if(!N||isNaN(Number(V)))continue;let I=Number(V),g=Pr(r,N),Dt=p.parseEvents({events:g})[0],_=Object.values(Dt)[I]||null;i.push(String(_)),o.push(_),c[h]=_&&_.valueOf()}else if(P==="out"||P.startsWith("out[")){if(!N)continue;let I=Number(N),g=C.values[I-1]||null;V&&(g=g[V]||null),g&&typeof g=="object"&&(g="toFixed"in g?g.toFixed():g.valueOf()),i.push(String(g)),o.push(g),c[h]=g&&g.valueOf()}else c[h]=T}return{values:{string:i,native:o,mapped:{}},output:await oe(e,c,t,n,this.serializer.coreSerializer,this.config)}}async extractQueryOutput(e,t,r,n){let a=t.map(m=>this.serializer.typedToString(m)),i=t.map(m=>this.serializer.typedToNative(m)[1]),o={string:a,native:i,mapped:{}},c={};if(!e.output)return{values:o,output:c};let d=m=>{let p=m.split(".").slice(1).map(C=>parseInt(C)-1);if(p.length===0)return;let W=i[p[0]];for(let C=1;C<p.length;C++){if(W==null)return;W=W[p[C]]}return W};for(let[m,p]of Object.entries(e.output)){if(p.startsWith(Et.Transform.Prefix))continue;let W=xt(p);if(W!==null&&W!==r){c[m]=null;continue}p.startsWith("out.")||p==="out"||p.startsWith("out[")?c[m]=d(p)||null:c[m]=p}return c=await oe(e,c,r,n,this.serializer.coreSerializer,this.config),{values:o,output:c}}async resolveWarpOutputRecursively(e){let t=e.warp,r=e.entryActionIndex,n=e.executor,a=e.inputs,i=e.meta,o=new Map,c=new Set,d=this;async function m(h,T=[]){if(o.has(h))return o.get(h);if(c.has(h))throw new Error(`Circular dependency detected at action ${h}`);c.add(h);let x=t.actions[h-1];if(!x)throw new Error(`Action ${h} not found`);let P;if(x.type==="query")P=await n.executeQuery(t,h,T);else if(x.type==="collect")P=await n.executeCollect(t,h,T,i);else throw new Error(`Unsupported or interactive action type: ${x.type}`);if(o.set(h,P),t.output)for(let N of Object.values(t.output)){let I=String(N).match(/^out\[(\d+)\]/);if(I){let g=parseInt(I[1],10);g!==h&&!o.has(g)&&await m(g)}}return c.delete(h),P}await m(r,a);let p={};for(let h of o.values())for(let[T,x]of Object.entries(h.output))x!==null?p[T]=x:T in p||(p[T]=null);let W=await oe(t,p,r,a,this.serializer.coreSerializer,this.config);return{...o.get(r),action:r,output:W}}};var zr="EGLD-000000",ce=class{constructor(e,t,r){this.config=e;this.chain=t;this.typeRegistry=r;this.serializer=new B({typeRegistry:this.typeRegistry}),this.abi=new S(this.config,this.chain),this.output=new R(this.config,this.chain,this.typeRegistry)}async createTransaction(e){let t=Ne(e.warp,e.action),r=null;if(t.type==="transfer")r=await this.createTransferTransaction(e);else if(t.type==="contract")r=await this.createContractCallTransaction(e);else{if(t.type==="query")throw new Error("WarpMultiversxExecutor: Invalid action type for createTransactionForExecute; Use executeQuery instead");if(t.type==="collect")throw new Error("WarpMultiversxExecutor: Invalid action type for createTransactionForExecute; Use executeCollect instead")}if(!r)throw new Error(`WarpMultiversxExecutor: Invalid action type (${t.type})`);return r}async createTransferTransaction(e){if(!e.destination)throw new Error("WarpMultiversxExecutor: createTransfer - destination not set");let t=Ve(this.config,e.chain.name);if(!t)throw new Error("WarpMultiversxExecutor: createTransfer - user address not set");let r=H.newFromBech32(t),n=new bt({chainID:e.chain.chainId}),a=e.data?Buffer.from(this.serializer.stringToTyped(e.data).valueOf()):null,i=e.transfers.length===1&&e.transfers[0].identifier===this.chain.nativeToken?.identifier,c=(i?e.transfers[0].amount:0n)+e.value;return await new _r({config:n}).createTransactionForTransfer(r,{receiver:H.newFromBech32(e.destination),nativeAmount:c,tokenTransfers:i?[]:this.toTokenTransfers(e.transfers),data:a?new Uint8Array(a):void 0})}async createContractCallTransaction(e){if(!e.destination)throw new Error("WarpMultiversxExecutor: createContractCall - destination not set");let t=Ve(this.config,e.chain.name);if(!t)throw new Error("WarpMultiversxExecutor: createContractCall - user address not set");let r=Ne(e.warp,e.action),n=H.newFromBech32(t),a=e.args.map(o=>this.serializer.stringToTyped(o)),i=new bt({chainID:e.chain.chainId});return new Rr({config:i}).createTransactionForExecute(n,{contract:H.newFromBech32(e.destination),function:"func"in r&&r.func||"",gasLimit:"gasLimit"in r?BigInt(r.gasLimit||0):0n,arguments:a,tokenTransfers:this.toTokenTransfers(e.transfers),nativeTransferAmount:e.value})}async executeQuery(e){if(!e.destination)throw new Error("WarpMultiversxExecutor: executeQuery - destination not set");let t=Ne(e.warp,e.action);if(t.type!=="query")throw new Error(`WarpMultiversxExecutor: Invalid action type for executeQuery: ${t.type}`);let r=await this.abi.getAbiForAction(t),n=e.args.map(g=>this.serializer.stringToTyped(g)),a=v(e.chain,this.config.env,this.config),i=H.newFromBech32(e.destination),o=a.createSmartContractController(r),c=o.createQuery({contract:i,function:t.func||"",arguments:n}),d=await o.runQuery(c),m=d.returnCode==="ok",p=new Mr,W=r.getEndpoint(d.function||t.func||""),C=(d.returnDataParts||[]).map(g=>Buffer.from(g)),h=p.buffersToValues(C,W.output),{values:T,output:x}=await this.output.extractQueryOutput(e.warp,h,e.action,e.resolvedInputs),P=Gr(this.config,[],e.warp,e.action,x),V=e.resolvedInputs.find(g=>g.input.position==="receiver"||g.input.position==="destination")?.value||e.destination,I=Hr(e.resolvedInputs);return{status:m?"success":"error",warp:e.warp,action:e.action,user:Ve(this.config,e.chain.name),txHash:null,tx:null,next:P,values:T,output:{...x,_DATA:h},messages:$r(e.warp,x,this.config),destination:V,resolvedInputs:I}}toTokenTransfers(e){return e.map(t=>t.identifier===this.chain.nativeToken.identifier?{...t,identifier:zr}:t).map(t=>{let n=new Lr().extractNonceFromExtendedIdentifier(t.identifier);return new Kr({token:new Dr({identifier:t.identifier,nonce:BigInt(n||0)}),amount:t.amount})})}};var le=class{constructor(e,t){this.chain=e;this.config=t}getExplorers(){let e=lt[this.chain];if(!e)return["multiversx_explorer"];let t=e[this.config.env];return t||["multiversx_explorer"]}getPrimaryExplorer(){return this.getExplorers()[0]}getExplorerUrlByName(e){let t=this.config.preferences?.explorers?.[this.chain];if(t&&!e){let a=U[t];if(a)return a}if(e){let a=U[e];if(a)return a}let r=this.getPrimaryExplorer();return U[r]||U[r]}getAccountUrl(e,t){return`${this.getExplorerUrlByName(t)}/accounts/${e}`}getTransactionUrl(e,t){return`${this.getExplorerUrlByName(t)}/transactions/${e}`}getBlockUrl(e,t){return`${this.getExplorerUrlByName(t)}/blocks/${e}`}getAssetUrl(e,t){return`${this.getExplorerUrlByName(t)}/tokens/${e}`}getContractUrl(e,t){return`${this.getExplorerUrlByName(t)}/accounts/${e}`}getAllExplorers(){return this.getExplorers()}getExplorerByName(e){return this.getExplorers().find(r=>r.toLowerCase()===e.toLowerCase())}getAccountUrls(e){let t=this.getAllExplorers(),r={};return t.forEach(n=>{let a=U[n];a&&(r[n]=`${a}/accounts/${e}`)}),r}getTransactionUrls(e){let t=this.getAllExplorers(),r={};return t.forEach(n=>{let a=U[n];a&&(r[n]=`${a}/transactions/${e}`)}),r}};import{AbiRegistry as It,Address as y,AddressValue as ke,BytesValue as w,SmartContractTransactionsFactory as jr,TransactionsFactoryConfig as Qr}from"@multiversx/sdk-core";import{createWarpIdentifier as Xr,getWarpWalletAddressFromConfig as Jr,WarpCache as Yr,WarpCacheKey as Fe,WarpLogger as Oe}from"@vleap/warps";var Ue={buildInfo:{rustc:{version:"1.86.0",commitHash:"05f9846f893b09a1be1fc8560e33fc3c815cfecb",commitDate:"2025-03-31",channel:"Stable",short:"rustc 1.86.0 (05f9846f8 2025-03-31)"},contractCrate:{name:"registry",version:"0.0.1"},framework:{name:"multiversx-sc",version:"0.51.1"}},name:"RegistryContract",constructor:{inputs:[{name:"unit_price",type:"BigUint"},{name:"vault",type:"Address"}],outputs:[]},upgradeConstructor:{inputs:[],outputs:[]},endpoints:[{name:"registerWarp",mutability:"mutable",payableInTokens:["EGLD"],inputs:[{name:"hash",type:"bytes"},{name:"alias_opt",type:"optional<bytes>",multi_arg:!0},{name:"brand_opt",type:"optional<bytes>",multi_arg:!0}],outputs:[],allow_multiple_var_args:!0},{name:"unregisterWarp",mutability:"mutable",inputs:[{name:"warp",type:"bytes"}],outputs:[]},{name:"upgradeWarp",mutability:"mutable",payableInTokens:["EGLD"],inputs:[{name:"alias",type:"bytes"},{name:"new_warp",type:"bytes"},{name:"brand_opt",type:"optional<bytes>",multi_arg:!0}],outputs:[]},{name:"setWarpAlias",mutability:"mutable",payableInTokens:["EGLD"],inputs:[{name:"hash",type:"bytes"},{name:"alias",type:"bytes"}],outputs:[]},{name:"forceRemoveAlias",mutability:"mutable",inputs:[{name:"hash",type:"bytes"}],outputs:[]},{name:"verifyWarp",mutability:"mutable",inputs:[{name:"warp",type:"bytes"}],outputs:[]},{name:"transferOwnership",mutability:"mutable",inputs:[{name:"warp",type:"bytes"},{name:"new_owner",type:"Address"}],outputs:[]},{name:"getUserWarps",mutability:"readonly",inputs:[{name:"address",type:"Address"}],outputs:[{type:"variadic<InfoView>",multi_result:!0}]},{name:"getInfoByAlias",mutability:"readonly",inputs:[{name:"alias",type:"bytes"}],outputs:[{type:"InfoView"}]},{name:"getInfoByHash",mutability:"readonly",inputs:[{name:"hash",type:"bytes"}],outputs:[{type:"InfoView"}]},{name:"setVault",onlyOwner:!0,mutability:"mutable",inputs:[{name:"vault",type:"Address"}],outputs:[]},{name:"setUnitPrice",onlyOwner:!0,mutability:"mutable",inputs:[{name:"amount",type:"BigUint"}],outputs:[]},{name:"addAdmin",onlyOwner:!0,mutability:"mutable",inputs:[{name:"address",type:"Address"}],outputs:[]},{name:"removeAdmin",onlyOwner:!0,mutability:"mutable",inputs:[{name:"address",type:"Address"}],outputs:[]},{name:"getConfig",mutability:"readonly",inputs:[],outputs:[{type:"ConfigView"}]},{name:"registerBrand",mutability:"mutable",payableInTokens:["EGLD"],inputs:[{name:"hash",type:"bytes"}],outputs:[]},{name:"brandWarp",mutability:"mutable",payableInTokens:["EGLD"],inputs:[{name:"warp",type:"bytes"},{name:"brand",type:"bytes"}],outputs:[]},{name:"getUserBrands",mutability:"readonly",inputs:[{name:"user",type:"Address"}],outputs:[{type:"variadic<bytes>",multi_result:!0}]}],events:[{identifier:"warpRegistered",inputs:[{name:"hash",type:"bytes",indexed:!0},{name:"alias",type:"bytes",indexed:!0},{name:"trust",type:"bytes",indexed:!0}]},{identifier:"warpUnregistered",inputs:[{name:"hash",type:"bytes",indexed:!0}]},{identifier:"warpUpgraded",inputs:[{name:"alias",type:"bytes",indexed:!0},{name:"new_warp",type:"bytes",indexed:!0},{name:"trust",type:"bytes",indexed:!0}]},{identifier:"warpVerified",inputs:[{name:"hash",type:"bytes",indexed:!0}]},{identifier:"aliasUpdated",inputs:[{name:"hash",type:"bytes",indexed:!0},{name:"alias",type:"bytes",indexed:!0}]},{identifier:"ownershipTransferred",inputs:[{name:"warp",type:"bytes",indexed:!0},{name:"old_owner",type:"Address",indexed:!0},{name:"new_owner",type:"Address",indexed:!0}]}],esdtAttributes:[],hasCallback:!1,types:{ConfigView:{type:"struct",fields:[{name:"unit_price",type:"BigUint"},{name:"admins",type:"List<Address>"}]},InfoView:{type:"struct",fields:[{name:"hash",type:"bytes"},{name:"alias",type:"Option<bytes>"},{name:"trust",type:"bytes"},{name:"owner",type:"Address"},{name:"created_at",type:"u64"},{name:"upgraded_at",type:"u64"},{name:"brand",type:"Option<bytes>"},{name:"upgrade",type:"Option<bytes>"}]}}};var E=s=>{if(s==="devnet")return"erd1qqqqqqqqqqqqqpgqje2f99vr6r7sk54thg03c9suzcvwr4nfl3tsfkdl36";if(s==="testnet")throw new Error("Multiversx testnet is not supported");return"erd1qqqqqqqqqqqqqpgq3mrpj3u6q7tejv6d7eqhnyd27n9v5c5tl3ts08mffe"};var pe=s=>({hash:s.hash.toString("hex"),alias:s.alias?.toString()||null,trust:s.trust.toString(),owner:s.owner.toString(),createdAt:s.created_at.toNumber(),upgradedAt:s.upgraded_at?.toNumber(),brand:s.brand?.toString("hex")||null,upgrade:s.upgrade?.toString("hex")||null}),Pt=s=>({unitPrice:BigInt(s.unit_price.toString()),admins:s.admins.map(e=>e.toBech32())});var ue=class{constructor(e,t){this.config=e;this.chain=t;this.cache=new Yr(e.cache?.type),this.registryConfig={unitPrice:BigInt(0),admins:[]},this.userWallet=Jr(this.config,this.chain.name)}async init(){await this.loadRegistryConfigs()}getRegistryConfig(){return this.registryConfig}async createWarpRegisterTransaction(e,t,r){if(this.registryConfig.unitPrice===BigInt(0))throw new Error("WarpRegistry: config not loaded. forgot to call init()?");if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let n=y.newFromBech32(this.userWallet),a=()=>this.isCurrentUserAdmin()?BigInt(0):t&&r?this.registryConfig.unitPrice*BigInt(3):t?this.registryConfig.unitPrice*BigInt(2):this.registryConfig.unitPrice,i=()=>t&&r?[w.fromHex(e),w.fromUTF8(t),w.fromHex(r)]:t?[w.fromHex(e),w.fromUTF8(t)]:[w.fromHex(e)];return await this.getFactory().createTransactionForExecute(n,{contract:y.newFromBech32(E(this.config.env)),function:"registerWarp",gasLimit:BigInt(1e7),nativeTransferAmount:a(),arguments:i()})}async createWarpUnregisterTransaction(e){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let t=y.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(t,{contract:y.newFromBech32(E(this.config.env)),function:"unregisterWarp",gasLimit:BigInt(1e7),arguments:[w.fromHex(e)]})}async createWarpUpgradeTransaction(e,t,r){if(this.registryConfig.unitPrice===BigInt(0))throw new Error("WarpRegistry: config not loaded. forgot to call init()?");if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let n=y.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(n,{contract:y.newFromBech32(E(this.config.env)),function:"upgradeWarp",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:r?[w.fromUTF8(e),w.fromHex(t),w.fromHex(r)]:[w.fromUTF8(e),w.fromHex(t)]})}async createWarpAliasSetTransaction(e,t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let r=y.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(r,{contract:y.newFromBech32(E(this.config.env)),function:"setWarpAlias",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[w.fromHex(e),w.fromUTF8(t)]})}async createWarpVerifyTransaction(e){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let t=y.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(t,{contract:y.newFromBech32(E(this.config.env)),function:"verifyWarp",gasLimit:BigInt(1e7),arguments:[w.fromHex(e)]})}async createWarpTransferOwnershipTransaction(e,t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let r=y.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(r,{contract:y.newFromBech32(E(this.config.env)),function:"transferOwnership",gasLimit:BigInt(1e7),arguments:[w.fromHex(e),new ke(new y(t))]})}async createBrandRegisterTransaction(e){if(this.registryConfig.unitPrice===BigInt(0))throw new Error("WarpRegistry: config not loaded. forgot to call init()?");if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let t=y.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(t,{contract:y.newFromBech32(E(this.config.env)),function:"registerBrand",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[w.fromHex(e)]})}async createWarpBrandingTransaction(e,t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let r=y.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(r,{contract:y.newFromBech32(E(this.config.env)),function:"brandWarp",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[w.fromHex(e),w.fromHex(t)]})}async getInfoByAlias(e,t){try{let r=Fe.RegistryInfo(this.config.env,e),n=t?this.cache.get(r):null;if(n)return Oe.info(`WarpRegistry (getInfoByAlias): RegistryInfo found in cache: ${e}`),n;let a=y.newFromBech32(E(this.config.env)),i=this.getController(),o=i.createQuery({contract:a,function:"getInfoByAlias",arguments:[w.fromUTF8(e)]}),c=await i.runQuery(o),[d]=i.parseQueryResponse(c),m=d?pe(d):null,p=m?.brand?await this.fetchBrand(m.brand):null;return t&&t.ttl&&this.cache.set(r,{registryInfo:m,brand:p},t.ttl),{registryInfo:m,brand:p}}catch{return{registryInfo:null,brand:null}}}async getInfoByHash(e,t){try{let r=Fe.RegistryInfo(this.config.env,e);if(t){let p=this.cache.get(r);if(p)return Oe.info(`WarpRegistry (getInfoByHash): RegistryInfo found in cache: ${e}`),p}let n=y.newFromBech32(E(this.config.env)),a=this.getController(),i=a.createQuery({contract:n,function:"getInfoByHash",arguments:[w.fromHex(e)]}),o=await a.runQuery(i),[c]=a.parseQueryResponse(o),d=c?pe(c):null,m=d?.brand?await this.fetchBrand(d.brand):null;return t&&t.ttl&&this.cache.set(r,{registryInfo:d,brand:m},t.ttl),{registryInfo:d,brand:m}}catch{return{registryInfo:null,brand:null}}}async getUserWarpRegistryInfos(e){try{let t=e||this.userWallet;if(!t)throw new Error("WarpRegistry: user address not set");let r=y.newFromBech32(E(this.config.env)),n=this.getController(),a=n.createQuery({contract:r,function:"getUserWarps",arguments:[new ke(new y(t))]}),i=await n.runQuery(a),[o]=n.parseQueryResponse(i);return o.map(pe)}catch{return[]}}async getUserBrands(e){try{let t=e||this.userWallet;if(!t)throw new Error("WarpRegistry: user address not set");let r=y.newFromBech32(E(this.config.env)),n=this.getController(),a=n.createQuery({contract:r,function:"getUserBrands",arguments:[new ke(new y(t))]}),i=await n.runQuery(a),[o]=n.parseQueryResponse(i),c=o.map(p=>p.toString("hex")),d={ttl:365*24*60*60};return(await Promise.all(c.map(p=>this.fetchBrand(p,d)))).filter(p=>p!==null)}catch{return[]}}async fetchBrand(e,t){let r=Fe.Brand(this.config.env,e),n=t?this.cache.get(r):null;if(n)return Oe.info(`WarpRegistry (fetchBrand): Brand found in cache: ${e}`),n;let i=v(this.chain,this.config.env,this.config).createNetworkProvider();try{let o=await i.getTransaction(e),c=JSON.parse(o.data.toString());return c.meta={query:null,chain:this.chain.name,identifier:Xr(this.chain.name,"hash",e),hash:o.hash,creator:o.sender.toBech32(),createdAt:new Date(o.timestamp*1e3).toISOString()},t&&t.ttl&&this.cache.set(r,c,t.ttl),c}catch{return null}}async loadRegistryConfigs(){let e=y.newFromBech32(E(this.config.env)),t=this.getController(),[r]=await t.query({contract:e,function:"getConfig",arguments:[]}),n=r?Pt(r):null;this.registryConfig=n||{unitPrice:BigInt(0),admins:[]}}getFactory(){let e=new Qr({chainID:this.chain.chainId}),t=It.create(Ue);return new jr({config:e,abi:t})}getController(){let e=v(this.chain,this.config.env,this.config),t=It.create(Ue);return e.createSmartContractController(t)}isCurrentUserAdmin(){return!!this.userWallet&&this.registryConfig.admins.includes(this.userWallet)}};import{Address as pn}from"@multiversx/sdk-core";import{CacheTtl as Ut,initializeWalletCache as un,WarpCache as mn}from"@vleap/warps";import{Account as Zr,Message as en,Mnemonic as Me,UserSecretKey as tn}from"@multiversx/sdk-core";import{getWarpWalletAddressFromConfig as rn,getWarpWalletMnemonicFromConfig as St,getWarpWalletPrivateKeyFromConfig as nn,setWarpWalletInConfig as Bt}from"@vleap/warps";var F=class F{constructor(e,t){this.config=e;this.chain=t;this.account=null}async getAddress(){let e=rn(this.config,this.chain.name);if(e)return e;try{return this.getAccount().address.toBech32()}catch{return null}}async getPublicKey(){try{return this.getAccount().publicKey.hex()}catch{return null}}async signTransaction(e){return await this.getAccount().signTransaction(e),e}async signMessage(e){let t=this.getAccount(),r=new TextEncoder().encode(e),n=await t.signMessage(new en({data:r}));return Buffer.from(n).toString("hex")}getAccountInstance(){return this.getAccount()}async importFromMnemonic(e){let r=Me.fromString(e).deriveKey(0),n=r.hex(),i=r.generatePublicKey().toAddress(this.chain.addressHrp).toBech32(),o={provider:F.PROVIDER_NAME,address:i,privateKey:n,mnemonic:e};return Bt(this.config,this.chain.name,o),o}async importFromPrivateKey(e){let t=tn.fromString(e),r=t.hex(),a=t.generatePublicKey().toAddress(this.chain.addressHrp).toBech32(),i={provider:F.PROVIDER_NAME,address:a,privateKey:r,mnemonic:null};return Bt(this.config,this.chain.name,i),i}async export(){let e=this.getAccount(),t=St(this.config,this.chain.name),r=nn(this.config,this.chain.name);return{provider:F.PROVIDER_NAME,address:e.address.toBech32(),privateKey:r||null,mnemonic:t||null}}async generate(){let e=Me.generate(),t=e.toString(),a=e.deriveKey(0).generatePublicKey().toAddress(this.chain.addressHrp).toBech32();return{provider:F.PROVIDER_NAME,address:a,privateKey:null,mnemonic:t}}getAccount(){if(this.account)return this.account;let e=St(this.config,this.chain.name);if(!e)throw new Error("No mnemonic provided");let r=Me.fromString(e).deriveKey(0);return this.account=new Zr(r),this.account}};F.PROVIDER_NAME="mnemonic";var D=F;import{Account as an,Message as sn,Mnemonic as on,UserSecretKey as G}from"@multiversx/sdk-core";import{getWarpWalletAddressFromConfig as cn,getWarpWalletMnemonicFromConfig as ln,getWarpWalletPrivateKeyFromConfig as Nt,setWarpWalletInConfig as Vt}from"@vleap/warps";var O=class O{constructor(e,t){this.config=e;this.chain=t;this.account=null}async getAddress(){let e=cn(this.config,this.chain.name);if(e)return e;try{return this.getAccount().address.toBech32()}catch{return null}}async getPublicKey(){try{return this.getAccount().publicKey.hex()}catch{return null}}async signTransaction(e){return await this.getAccount().signTransaction(e),e}async signMessage(e){let t=this.getAccount(),r=new TextEncoder().encode(e),n=await t.signMessage(new sn({data:r}));return Buffer.from(n).toString("hex")}getAccountInstance(){return this.getAccount()}async importFromMnemonic(e){let r=on.fromString(e).deriveKey(0),n=r.hex(),i=r.generatePublicKey().toAddress(this.chain.addressHrp).toBech32(),o={provider:O.PROVIDER_NAME,address:i,privateKey:n,mnemonic:e};return Vt(this.config,this.chain.name,o),o}async importFromPrivateKey(e){let r=e.startsWith("-----")?G.fromPem(e):G.fromString(e),n=r.hex(),i=r.generatePublicKey().toAddress(this.chain.addressHrp).toBech32(),o={provider:O.PROVIDER_NAME,address:i,privateKey:n,mnemonic:null};return Vt(this.config,this.chain.name,o),o}async export(){let e=this.getAccount(),t=Nt(this.config,this.chain.name),r=ln(this.config,this.chain.name);return{provider:O.PROVIDER_NAME,address:e.address.toBech32(),privateKey:t||null,mnemonic:r||null}}async generate(){let e=G.generate(),t=e.hex(),n=e.generatePublicKey().toAddress(this.chain.addressHrp).toBech32();return{provider:O.PROVIDER_NAME,address:n,privateKey:t,mnemonic:null}}getAccount(){if(this.account)return this.account;let e=Nt(this.config,this.chain.name);if(!e)throw new Error("No private key provided");let r=e.startsWith("-----")?G.fromPem(e):G.fromString(e);return this.account=new an(r),this.account}};O.PROVIDER_NAME="privateKey";var L=O;import{getWarpWalletAddressFromConfig as z}from"@vleap/warps";var K=class{constructor(e,t){this.config=e;this.chain=t}async getAddress(){return z(this.config,this.chain.name)}async getPublicKey(){return null}async signTransaction(e){let t=await this.getAddress();throw new Error(`Wallet can not be used for signing: ${t}`)}async signMessage(e){let t=await this.getAddress();throw new Error(`Wallet can not be used for signing: ${t}`)}async importFromMnemonic(e){let t=z(this.config,this.chain.name);throw new Error(`Wallet can not be used for signing: ${t}`)}async importFromPrivateKey(e){let t=z(this.config,this.chain.name);throw new Error(`Wallet can not be used for signing: ${t}`)}async export(){let e=z(this.config,this.chain.name);throw new Error(`Wallet can not be used for signing: ${e}`)}async generate(){let e=z(this.config,this.chain.name);throw new Error(`Wallet can not be used for signing: ${e}`)}};var me=class{constructor(e,t){this.config=e;this.chain=t;this.cachedAddress=null;this.cachedPublicKey=null;this.entry=v(t,e.env,e),this.cache=new mn(e.cache?.type),this.walletProvider=this.createProvider(),this.initializeCache()}async signTransaction(e){if(!e||typeof e!="object")throw new Error("Invalid transaction object");if(!this.walletProvider)throw new Error("No wallet provider available");if(this.walletProvider instanceof K)throw new Error(`Wallet (${this.chain.name}) is read-only`);if(this.walletProvider instanceof L||this.walletProvider instanceof D){let r=this.walletProvider.getAccountInstance();if(e.nonce===0n){let n=await this.entry.recallAccountNonce(r.address),a=this.cache.get(`nonce:${r.address.toBech32()}`)||0,i=BigInt(Math.max(a,Number(n)));e.nonce=i}}else if(e.nonce===0n&&this.cachedAddress){let r=pn.newFromBech32(this.cachedAddress),n=await this.entry.recallAccountNonce(r),a=this.cache.get(`nonce:${this.cachedAddress}`)||0,i=BigInt(Math.max(a,Number(n)));e.nonce=i}let t=await this.walletProvider.signTransaction(e);if(this.walletProvider instanceof L||this.walletProvider instanceof D){let r=this.walletProvider.getAccountInstance(),n=Number(r.nonce)+1;this.cache.set(`nonce:${r.address.toBech32()}`,n,Ut.OneMinute)}else if(this.cachedAddress){let r=e.nonce?Number(e.nonce):0;this.cache.set(`nonce:${this.cachedAddress}`,r+1,Ut.OneMinute)}return t}async signTransactions(e){let t=[];for(let r of e)t.push(await this.signTransaction(r));return t}async signMessage(e){if(!this.walletProvider)throw new Error("No wallet provider available");if(this.walletProvider instanceof K)throw new Error(`Wallet (${this.chain.name}) is read-only`);return await this.walletProvider.signMessage(e)}async sendTransactions(e){return Promise.all(e.map(async t=>this.sendTransaction(t)))}async sendTransaction(e){if(!e||typeof e!="object")throw new Error("Invalid transaction object");if(!e.signature)throw new Error("Transaction must be signed before sending");return await this.entry.sendTransaction(e)}async importFromMnemonic(e){return await this.createProviderForOperation("mnemonic").importFromMnemonic(e)}async importFromPrivateKey(e){return await this.createProviderForOperation("privateKey").importFromPrivateKey(e)}async export(e){return await this.createProviderForOperation(e).export()}async generate(e){return await this.createProviderForOperation(e).generate()}getAddress(){return this.cachedAddress}getPublicKey(){return this.cachedPublicKey}createProvider(){let e=this.config.user?.wallets?.[this.chain.name];return e?typeof e=="string"?new K(this.config,this.chain):this.createProviderForOperation(e.provider):null}initializeCache(){un(this.walletProvider).then(e=>{this.cachedAddress=e.address,this.cachedPublicKey=e.publicKey})}createProviderForOperation(e){let r=this.config.walletProviders?.[this.chain.name]?.[e];if(r){let n=r(this.config,this.chain);if(!n)throw new Error(`Custom wallet provider factory returned null for ${e}`);return n}if(e==="privateKey")return new L(this.config,this.chain);if(e==="mnemonic")return new D(this.config,this.chain);throw new Error(`Unsupported wallet provider for ${this.chain.name}: ${e}`)}};var de=(s,e)=>(t,r)=>{let n=e[t.env],a=new dn;return a.registerType("token",{stringToNative:i=>i,nativeToString:i=>`token:${i}`}),a.registerType("codemeta",{stringToNative:i=>i,nativeToString:i=>`codemeta:${i}`}),a.registerTypeAlias("list","vector"),{chainInfo:n,builder:()=>new J(t,n),executor:new ce(t,n,a),output:new R(t,n,a),serializer:new B({typeRegistry:a}),registry:new ue(t,n),explorer:new le(s,t),abiBuilder:()=>new S(t,n),brandBuilder:()=>new X(t,n),dataLoader:new Z(t,n),wallet:new me(t,n)}};import{WarpChainName as q}from"@vleap/warps";var Re={chain:q.Multiversx,identifier:"EGLD",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://joai.ai/images/tokens/egld.svg"},kt=de(q.Multiversx,{mainnet:{name:q.Multiversx,displayName:"MultiversX",chainId:"1",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://api.multiversx.com",logoUrl:"https://joai.ai/images/chains/multiversx.svg",nativeToken:Re},testnet:{name:q.Multiversx,displayName:"MultiversX Testnet",chainId:"T",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://testnet-api.multiversx.com",logoUrl:"https://joai.ai/images/chains/multiversx.svg",nativeToken:Re},devnet:{name:q.Multiversx,displayName:"MultiversX Devnet",chainId:"D",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://devnet-api.multiversx.com",logoUrl:"https://joai.ai/images/chains/multiversx.svg",nativeToken:Re}});import{WarpChainName as Le}from"@vleap/warps";var hn={chain:Le.Vibechain,identifier:"VIBE",name:"VIBE",symbol:"VIBE",decimals:18,logoUrl:"https://joai.ai/images/tokens/vibe.svg"},De={name:Le.Vibechain,displayName:"VibeChain",chainId:"V",blockTime:600,addressHrp:"vibe",defaultApiUrl:"https://vibeox-api.multiversx.com",logoUrl:"https://joai.ai/images/chains/vibechain.svg",nativeToken:hn},Ft=de(Le.Vibechain,{mainnet:De,testnet:De,devnet:De});var Qo=()=>[kt,Ft];import{WarpConstants as he,WarpSerializer as Ke}from"@vleap/warps";var ec=s=>new Ke().nativeToString(f.Token,s),tc=s=>new Ke().nativeToString(f.CodeMeta,s),rc=(s,e)=>{if(e===null)return f.Optional+he.ArgParamsSeparator;let t=s(e),r=t.indexOf(he.ArgParamsSeparator),n=t.substring(0,r),a=t.substring(r+1);return f.Optional+he.ArgParamsSeparator+n+he.ArgParamsSeparator+a},nc=s=>new Ke().nativeToString(f.List,s);import{Address as gn,AddressValue as fn,BigUIntType as yn,BigUIntValue as Ot,BooleanValue as Wn,BytesValue as vn,CodeMetadata as wn,CodeMetadataValue as Tn,CompositeType as Cn,CompositeValue as An,Field as _e,FieldDefinition as $e,List as xn,NothingValue as En,OptionalValue as He,OptionValue as Ge,StringValue as bn,Struct as Pn,StructType as In,TokenIdentifierType as Sn,TokenIdentifierValue as Mt,U16Value as Bn,U32Value as Nn,U64Type as Vn,U64Value as Rt,U8Value as Un,VariadicValue as kn}from"@multiversx/sdk-core";var lc=(s,e)=>s?Ge.newProvided(s):e?Ge.newMissingTyped(e):Ge.newMissing(),pc=(s,e)=>s?new He(s.getType(),s):e?new He(e):He.newMissing(),uc=s=>{if(s.length===0)throw new Error("Cannot create a list from an empty array");let e=s[0].getType();return new xn(e,s)},mc=s=>kn.fromItems(...s),dc=s=>{let e=s.map(t=>t.getType());return new An(new Cn(...e),s)},hc=s=>bn.fromUTF8(s),gc=s=>new Un(s),fc=s=>new Bn(s),yc=s=>new Nn(s),Wc=s=>new Rt(s),vc=s=>new Ot(BigInt(s)),wc=s=>new Wn(s),Tc=s=>new fn(gn.newFromBech32(s)),Cc=s=>new Mt(s),Ac=s=>vn.fromHex(s),xc=s=>new Pn(new In("EsdtTokenPayment",[new $e("token_identifier","",new Sn),new $e("token_nonce","",new Vn),new $e("amount","",new yn)]),[new _e(new Mt(s.token.identifier),"token_identifier"),new _e(new Rt(BigInt(s.token.nonce)),"token_nonce"),new _e(new Ot(BigInt(s.amount)),"amount")]),Ec=s=>new Tn(wn.newFromBytes(Uint8Array.from(Buffer.from(s,"hex")))),bc=()=>new En;export{U as ExplorerUrls,ot as KnownTokens,kt as MultiversxAdapter,wr as MultiversxExplorers,lt as MultiversxExplorersConfig,Re as NativeTokenEgld,hn as NativeTokenVibe,Ft as VibechainAdapter,Tr as VibechainExplorers,S as WarpMultiversxAbiBuilder,X as WarpMultiversxBrandBuilder,J as WarpMultiversxBuilder,gi as WarpMultiversxConstants,Q as WarpMultiversxContractLoader,Z as WarpMultiversxDataLoader,ce as WarpMultiversxExecutor,le as WarpMultiversxExplorer,f as WarpMultiversxInputTypes,R as WarpMultiversxOutput,ue as WarpMultiversxRegistry,B as WarpMultiversxSerializer,me as WarpMultiversxWallet,Tc as address_value,xc as asset_value,vc as biguint_value,wc as boolean_value,tc as codemeta,Ec as codemeta_value,dc as composite_value,de as createMultiversxAdapter,ct as findKnownTokenById,Qo as getAllMultiversxAdapters,On as getAllMultiversxChainNames,Ya as getKnownTokensForChain,v as getMultiversxEntrypoint,E as getMultiversxRegistryAddress,j as getNormalizedTokenIdentifier,Ac as hex_value,M as isNativeToken,nc as list,uc as list_value,bc as nothing_value,lc as option_value,rc as optional,pc as optional_value,hc as string_value,Pt as toTypedConfigInfo,pe as toTypedRegistryInfo,ec as token,Cc as token_value,fc as u16_value,yc as u32_value,Wc as u64_value,gc as u8_value,mc as variadic_value};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vleap/warps-adapter-multiversx",
3
- "version": "0.2.0-beta.92",
3
+ "version": "0.2.0-beta.93",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",