@vleap/warps-adapter-multiversx 0.2.0-alpha.57 → 0.2.0-alpha.58
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 +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var fe=Object.defineProperty;var Ge=Object.getOwnPropertyDescriptor;var Ke=Object.getOwnPropertyNames;var $e=Object.prototype.hasOwnProperty;var qe=(i,e)=>{for(var t in e)fe(i,t,{get:e[t],enumerable:!0})},ze=(i,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of Ke(e))!$e.call(i,a)&&a!==t&&fe(i,a,{get:()=>e[a],enumerable:!(r=Ge(e,a))||r.enumerable});return i};var Qe=i=>ze(fe({},"__esModule",{value:!0}),i);var xt={};qe(xt,{ExplorerUrls:()=>H,KnownTokens:()=>ye,MultiversxExplorers:()=>Oe,MultiversxExplorersConfig:()=>We,NativeTokenEgld:()=>de,NativeTokenVibe:()=>He,VibechainExplorers:()=>Le,WarpMultiversxAbiBuilder:()=>M,WarpMultiversxBrandBuilder:()=>te,WarpMultiversxBuilder:()=>re,WarpMultiversxConstants:()=>Xe,WarpMultiversxContractLoader:()=>ee,WarpMultiversxDataLoader:()=>ne,WarpMultiversxExecutor:()=>ae,WarpMultiversxExplorer:()=>se,WarpMultiversxInputTypes:()=>C,WarpMultiversxRegistry:()=>oe,WarpMultiversxResults:()=>q,WarpMultiversxSerializer:()=>O,WarpMultiversxWallet:()=>ce,address_value:()=>yt,asset_value:()=>vt,biguint_value:()=>ft,boolean_value:()=>gt,codemeta:()=>rt,codemeta_value:()=>Ct,composite_value:()=>pt,createMultiversxAdapter:()=>pe,findKnownTokenById:()=>we,getAllMultiversxAdapters:()=>Ze,getAllMultiversxChainNames:()=>et,getKnownTokensForChain:()=>je,getMultiversxAdapter:()=>Te,getMultiversxEntrypoint:()=>v,getMultiversxRegistryAddress:()=>A,getNormalizedTokenIdentifier:()=>Z,getVibechainAdapter:()=>Ae,hex_value:()=>Wt,isNativeToken:()=>G,list:()=>at,list_value:()=>ot,nothing_value:()=>Tt,option:()=>nt,option_value:()=>st,optional_value:()=>it,string_value:()=>lt,toTypedConfigInfo:()=>Ce,toTypedRegistryInfo:()=>ie,token:()=>tt,token_value:()=>wt,u16_value:()=>mt,u32_value:()=>dt,u64_value:()=>ht,u8_value:()=>ut,variadic_value:()=>ct});module.exports=Qe(xt);var Ee=require("@vleap/warps");var J=require("@vleap/warps");var R=require("@multiversx/sdk-core"),b=require("@vleap/warps");var z=require("@multiversx/sdk-core"),be=require("@vleap/warps"),G=i=>!i.includes("-"),Z=i=>G(i)?`${i}-000000`:i,v=(i,e,t)=>{let r="warp-sdk",s=t?(0,be.getProviderUrl)(t,i.name,e,i.defaultApiUrl):i.defaultApiUrl;return e==="devnet"?new z.DevnetEntrypoint({url:s,kind:"api",clientName:r}):e==="testnet"?new z.TestnetEntrypoint({url:s,kind:"api",clientName:r}):new z.MainnetEntrypoint({url:s,kind:"api",clientName:r})};var ge=require("@vleap/warps");var ee=class{constructor(e){this.config=e}async getContract(e,t){try{let s=await v(t,this.config.env,this.config).createNetworkProvider().doGetGeneric(`accounts/${e}`);return{address:e,owner:s.ownerAddress,verified:s.isVerified||!1}}catch(r){return ge.WarpLogger.error("WarpContractLoader: getContract error",r),null}}async getVerificationInfo(e,t){try{let s=await v(t,this.config.env,this.config).createNetworkProvider().doGetGeneric(`accounts/${e}/verification`);return{codeHash:s.codeHash,abi:s.source.abi}}catch(r){return ge.WarpLogger.error("WarpContractLoader: getVerificationInfo error",r),null}}};var M=class{constructor(e,t){this.config=e;this.chain=t;this.contractLoader=new ee(this.config),this.cache=new b.WarpCache(this.config.cache?.type)}async createInscriptionTransaction(e){let t=(0,b.getWarpWalletAddressFromConfig)(this.config,this.chain.name);if(!t)throw new Error("WarpBuilder: user address not set");let r=new R.TransactionsFactoryConfig({chainID:this.chain.chainId}),a=new R.TransferTransactionsFactory({config:r}),s=R.Address.newFromBech32(t),c={protocol:(0,b.getLatestProtocolIdentifier)("abi"),content:e},o=JSON.stringify(c),l=await a.createTransactionForTransfer(s,{receiver:s,nativeAmount:BigInt(0),data:Uint8Array.from(Buffer.from(o))});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,hash:e.hash,creator:e.sender.toBech32(),createdAt:new Date(e.timestamp*1e3).toISOString()},t}async createFromTransactionHash(e,t){let r=b.WarpCacheKey.WarpAbi(this.config.env,e);if(t){let c=this.cache.get(r);if(c)return b.WarpLogger.info(`WarpAbiBuilder (createFromTransactionHash): Warp abi found in cache: ${e}`),c}let s=v(this.chain,this.config.env,this.config).createNetworkProvider();try{let c=await s.getTransaction(e),o=await this.createFromTransaction(c);return t&&t.ttl&&o&&this.cache.set(r,o,t.ttl),o}catch(c){return b.WarpLogger.error("WarpAbiBuilder: Error creating from transaction hash",c),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 R.AbiRegistry.create(t.abi)}async fetchAbi(e){if(!e.abi)throw new Error("WarpActionExecutor: ABI not found");if(e.abi.startsWith(b.WarpConstants.IdentifierType.Hash)){let t=e.abi.split(b.WarpConstants.ArgParamsSeparator)[1],r=await this.createFromTransactionHash(t);if(!r)throw new Error(`WarpActionExecutor: ABI not found for hash: ${e.abi}`);return R.AbiRegistry.create(r.content)}else{let r=await(await fetch(e.abi)).json();return R.AbiRegistry.create(r)}}};var K=require("@multiversx/sdk-core"),Q=require("@vleap/warps"),Ie=require("buffer");var te=class{constructor(e,t){this.config=e;this.chain=t;this.core=new Q.WarpBrandBuilder(e)}async createInscriptionTransaction(e){let t=(0,Q.getWarpWalletAddressFromConfig)(this.config,this.chain.name);if(!t)throw new Error("BrandBuilder: user address not set");let r=new K.TransactionsFactoryConfig({chainID:this.chain.chainId}),a=new K.TransferTransactionsFactory({config:r}),s=K.Address.newFromBech32(t),c=JSON.stringify(e);return await a.createTransactionForNativeTokenTransfer(s,{receiver:K.Address.newFromBech32(t),nativeAmount:BigInt(0),data:Uint8Array.from(Ie.Buffer.from(c))})}async createFromTransaction(e,t=!1){let r=await this.core.createFromRaw(e.data.toString(),t);return r.meta={chain:this.chain.name,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 a=await r.getTransaction(e);return this.createFromTransaction(a)}catch(a){return Q.WarpLogger.error("BrandBuilder: Error creating from transaction hash",a),null}}};var $=require("@multiversx/sdk-core"),U=require("@vleap/warps");var re=class extends U.WarpBuilder{constructor(t,r){super(t);this.config=t;this.chain=r;this.cache=new U.WarpCache(t.cache?.type),this.core=new U.WarpBuilder(t)}async createInscriptionTransaction(t){let r=(0,U.getWarpWalletAddressFromConfig)(this.config,this.chain.name);if(!r)throw new Error("WarpBuilder: user address not set");let a=new $.TransactionsFactoryConfig({chainID:this.chain.chainId}),s=new $.TransferTransactionsFactory({config:a}),c=$.Address.newFromBech32(r),o=JSON.stringify(t),l=await s.createTransactionForTransfer(c,{receiver:$.Address.newFromBech32(r),nativeAmount:BigInt(0),data:Uint8Array.from(Buffer.from(o))});return l.gasLimit=l.gasLimit+BigInt(2e6),l}async createFromTransaction(t,r=!1){let a=await this.core.createFromRaw(t.data.toString(),r);return a.meta={chain:this.chain.name,hash:t.hash,creator:t.sender.toBech32(),createdAt:new Date(t.timestamp*1e3).toISOString()},a}async createFromTransactionHash(t,r){let a=U.WarpCacheKey.Warp(this.config.env,t);if(r){let o=this.cache.get(a);if(o)return U.WarpLogger.info(`WarpBuilder (createFromTransactionHash): Warp found in cache: ${t}`),o}let c=v(this.chain,this.config.env,this.config).createNetworkProvider();try{let o=await c.getTransaction(t),l=await this.createFromTransaction(o);return r&&r.ttl&&l&&this.cache.set(a,l,r.ttl),l}catch(o){return U.WarpLogger.error("WarpBuilder: Error creating from transaction hash",o),null}}};var _=require("@multiversx/sdk-core"),j=require("@vleap/warps");var Se=require("@vleap/warps"),Be=Se.WarpChainName.Multiversx,Ue=[{chain:Be,identifier:"EGLD",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"},{chain:Be,identifier:"EGLD-000000",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"}];var Ne=require("@vleap/warps"),x=Ne.WarpChainName.Multiversx,Pe=[{chain:x,identifier:"EGLD",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"},{chain:x,identifier:"EGLD-000000",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"},{chain:x,identifier:"SEGLD-3ad2d0",name:"StakedEGLD",symbol:"SEGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/SEGLD-3ad2d0/icon.png"},{chain:x,identifier:"HSEGLD-c13a4e",name:"HatomSEGLD",symbol:"HSEGLD",decimals:8,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/HSEGLD-c13a4e/icon.png"},{chain:x,identifier:"UTK-2f80e9",name:"xMoney UTK",symbol:"UTK",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/UTK-2f80e9/icon.png"},{chain:x,identifier:"USDC-c76f1f",name:"WrappedUSDC",symbol:"USDC",decimals:6,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/USDC-c76f1f/icon.png"},{chain:x,identifier:"WEGLD-bd4d79",name:"WrappedEGLD",symbol:"WEGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/WEGLD-bd4d79/icon.png"},{chain:x,identifier:"HTM-f51d55",name:"Hatom",symbol:"HTM",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/HTM-f51d55/icon.png"},{chain:x,identifier:"MEX-455c57",name:"MEX",symbol:"MEX",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/MEX-455c57/icon.png"},{chain:x,identifier:"WTAO-4f5363",name:"WrappedTAO",symbol:"WTAO",decimals:9,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/WTAO-4f5363/icon.png"},{chain:x,identifier:"HEGLD-d61095",name:"HatomEGLD",symbol:"HEGLD",decimals:8,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/HEGLD-d61095/icon.png"},{chain:x,identifier:"WBTC-5349b3",name:"WrappedBTC",symbol:"WBTC",decimals:8,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/WBTC-5349b3/icon.png"},{chain:x,identifier:"WETH-b4ca29",name:"WrappedETH",symbol:"WETH",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/WETH-b4ca29/icon.png"},{chain:x,identifier:"USH-111e09",name:"HatomUSD",symbol:"USH",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/USH-111e09/icon.png"},{chain:x,identifier:"USDT-f8c08c",name:"WrappedUSDT",symbol:"USDT",decimals:6,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/USDT-f8c08c/icon.png"}];var ke=require("@vleap/warps"),Ve=ke.WarpChainName.Multiversx,Fe=[{chain:Ve,identifier:"EGLD",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"},{chain:Ve,identifier:"EGLD-000000",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"}];var Me=require("@vleap/warps"),Re=Me.WarpChainName.Vibechain,me=[{chain:Re,identifier:"VIBE",name:"VIBE",symbol:"VIBE",decimals:18,logoUrl:"https://vleap.ai/images/tokens/vibe.svg"},{chain:Re,identifier:"VIBE-000000",name:"VIBE",symbol:"VIBE",decimals:18,logoUrl:"https://vleap.ai/images/tokens/vibe.svg"}];var ye={multiversx:{mainnet:Pe,testnet:Fe,devnet:Ue},vibechain:{mainnet:me,testnet:me,devnet:me}},we=(i,e,t)=>(ye[i]?.[e]||[]).find(a=>a.identifier===t)||null,je=(i,e)=>ye[i]?.[e]||[];var ne=class{constructor(e,t){this.config=e;this.chain=t;this.cache=new j.WarpCache(e.cache?.type)}async getAccount(e){let r=await v(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=v(this.chain,this.config.env,this.config).createNetworkProvider(),r=t.getAccount(_.Address.newFromBech32(e)),a=t.getFungibleTokensOfAccount(_.Address.newFromBech32(e)),[s,c]=await Promise.all([r,a]),o=s.balance>0?[{...this.chain.nativeToken,amount:s.balance}]:[];return o.push(...c.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}))),o}async getAsset(e){let t=j.WarpCacheKey.Asset(this.config.env,this.chain.name,e),r=this.cache.get(t);if(r)return r;let a=we(this.chain.name,this.config.env,e);if(a)return{chain:this.chain.name,identifier:e,name:a.name,symbol:a.symbol,amount:0n,decimals:a.decimals,logoUrl:a.logoUrl};let s=new _.TokenComputer,c=G(e)?0n:s.extractNonceFromExtendedIdentifier(e),o=new _.Token({identifier:e,nonce:BigInt(c||0)}),l=s.isFungible(o),h=v(this.chain,this.config.env,this.config).createNetworkProvider(),g=Z(e),f=await h.doGetGeneric(`tokens/${g}`),E={chain:this.chain.name,identifier:o.identifier,name:f.name,symbol:f.ticker,amount:0n,decimals:f.decimals,logoUrl:f.assets?.pngUrl||"#",price:f.price?Number(f.price):void 0,supply:f.supply?BigInt(f.supply):void 0};return this.cache.set(t,E,j.CacheTtl.OneHour),E}async getAction(e,t=!1){let r=v(this.chain,this.config.env,this.config),a=t?await r.awaitCompletedTransaction(e):await r.getTransaction(e);return{chain:this.chain.name,id:a.hash,receiver:a.receiver.toBech32(),sender:a.sender.toBech32(),value:a.value,function:a.function,status:this.toActionStatus(a),createdAt:this.toActionCreatedAt(a),error:a?.smartContractResults.map(s=>s.raw.returnMessage)[0]||null,tx:a}}async getAccountActions(e,t){let r=v(this.chain,this.config.env,this.config).createNetworkProvider(),a=`accounts/${e}/transactions`,s=new URLSearchParams,c=t?.size||25,o=t?.page||0;if(o>0){let h=o*c;s.append("from",h.toString())}return c!==25&&s.append("size",c.toString()),s.toString()&&(a+=`?${s.toString()}`),(await r.doGetGeneric(a)).map(h=>({chain:this.chain.name,id:h.txHash,receiver:h.receiver,sender:h.sender,value:h.value,function:h.function,status:this.toActionStatus(h),createdAt:this.toActionCreatedAt(h)}))}toActionStatus(e){return e.status.isSuccessful()?"success":e.status.isFailed()?"failed":"pending"}toActionCreatedAt(e){return new Date(e.timestamp||e.timestamp*1e3).toISOString()}};var w=require("@multiversx/sdk-core"),N=require("@vleap/warps");var X=require("@multiversx/sdk-core"),W=require("@vleap/warps");var n=require("@multiversx/sdk-core"),_e=require("@vleap/warps");var d={HttpProtocolPrefix:"http",IdentifierParamName:"warp",IdentifierParamSeparator:":",IdentifierChainDefault:"multiversx",IdentifierType:{Alias:"alias",Hash:"hash"},Globals:{UserWallet:{Placeholder:"USER_WALLET",Accessor:i=>i.config.user?.wallets?.[i.chain]},ChainApiUrl:{Placeholder:"CHAIN_API",Accessor:i=>i.chainInfo.defaultApiUrl},ChainAddressHrp:{Placeholder:"CHAIN_ADDRESS_HRP",Accessor:i=>i.chainInfo.addressHrp}},Vars:{Query:"query",Env:"env"},ArgParamsSeparator:":",ArgCompositeSeparator:"|",ArgListSeparator:",",Transform:{Prefix:"transform:"},Source:{UserWallet:"user:wallet"},Position:{Payload:"payload:"}},m={Option:"option",Vector:"vector",Tuple:"tuple",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 Xe={Egld:{Identifier:"EGLD",EsdtIdentifier:"EGLD-000000",DisplayName:"eGold",Decimals:18}},C={Null:"null",Optional:"optional",List:"list",Token:"token",CodeMeta:"codemeta"},Oe=(r=>(r.MultiversxExplorer="multiversx_explorer",r.MultiversxExplorerDevnet="multiversx_explorer_devnet",r.MultiversxExplorerTestnet="multiversx_explorer_testnet",r))(Oe||{}),Le=(r=>(r.VibechainExplorer="vibechain_explorer",r.VibechainExplorerDevnet="vibechain_explorer_devnet",r.VibechainExplorerTestnet="vibechain_explorer_testnet",r))(Le||{}),We={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 De=new RegExp(`${d.ArgParamsSeparator}(.*)`),O=class{constructor(){this.coreSerializer=new _e.WarpSerializer}typedToString(e){let t=e.getType();if(t.hasExactClass(n.OptionType.ClassName)||e.hasClassOrSuperclass(n.OptionValue.ClassName)){if(!e.isSet())return m.Option+d.ArgParamsSeparator+"null";let r=this.typedToString(e.getTypedValue());return m.Option+d.ArgParamsSeparator+r}if(t.hasExactClass(n.VariadicType.ClassName)||e.hasClassOrSuperclass(n.VariadicValue.ClassName)){let r=e.getItems(),s=r.map(o=>this.typedToString(o).split(d.ArgParamsSeparator)[0])[0],c=r.map(o=>this.typedToString(o).split(d.ArgParamsSeparator)[1]);return m.Vector+d.ArgParamsSeparator+s+d.ArgParamsSeparator+c.join(d.ArgListSeparator)}if(t.hasExactClass(n.OptionalType.ClassName)||e.hasClassOrSuperclass(n.OptionalValue.ClassName)){if(!e.isSet())return C.Optional+d.ArgParamsSeparator+"null";let r=this.typedToString(e.getTypedValue());return C.Optional+d.ArgParamsSeparator+r}if(t.hasExactClass(n.ListType.ClassName)||e.hasClassOrSuperclass(n.List.ClassName)){let r=e.getItems(),s=r.map(o=>this.typedToString(o).split(d.ArgParamsSeparator)[0])[0],c=r.map(o=>this.typedToString(o).split(d.ArgParamsSeparator)[1]);return C.List+d.ArgParamsSeparator+s+d.ArgParamsSeparator+c.join(d.ArgListSeparator)}if(t.hasExactClass(n.CompositeType.ClassName)||e.hasClassOrSuperclass(n.CompositeValue.ClassName)){let r=e.getItems(),a=r.map(l=>this.typedToString(l).split(d.ArgParamsSeparator)[0]),s=r.map(l=>this.typedToString(l).split(d.ArgParamsSeparator)[1]),c=a.join(d.ArgCompositeSeparator),o=s.join(d.ArgCompositeSeparator);return`${m.Tuple}(${c})${d.ArgParamsSeparator}${o}`}if(t.hasExactClass(n.BigUIntType.ClassName)||e.hasClassOrSuperclass(n.BigUIntValue.ClassName)||t.getName()==="BigUint")return m.Biguint+d.ArgParamsSeparator+BigInt(e.valueOf().toFixed());if(t.hasExactClass(n.U8Type.ClassName)||e.hasClassOrSuperclass(n.U8Value.ClassName))return m.Uint8+d.ArgParamsSeparator+e.valueOf().toNumber();if(t.hasExactClass(n.U16Type.ClassName)||e.hasClassOrSuperclass(n.U16Value.ClassName))return m.Uint16+d.ArgParamsSeparator+e.valueOf().toNumber();if(t.hasExactClass(n.U32Type.ClassName)||e.hasClassOrSuperclass(n.U32Value.ClassName))return m.Uint32+d.ArgParamsSeparator+e.valueOf().toNumber();if(t.hasExactClass(n.U64Type.ClassName)||e.hasClassOrSuperclass(n.U64Value.ClassName))return m.Uint64+d.ArgParamsSeparator+BigInt(e.valueOf().toFixed());if(t.hasExactClass(n.StringType.ClassName)||e.hasClassOrSuperclass(n.StringValue.ClassName))return m.String+d.ArgParamsSeparator+e.valueOf();if(t.hasExactClass(n.BooleanType.ClassName)||e.hasClassOrSuperclass(n.BooleanValue.ClassName))return m.Bool+d.ArgParamsSeparator+e.valueOf();if(t.hasExactClass(n.AddressType.ClassName)||e.hasClassOrSuperclass(n.AddressValue.ClassName))return m.Address+d.ArgParamsSeparator+e.valueOf().toBech32();if(t.hasExactClass(n.BytesType.ClassName)||e.hasClassOrSuperclass(n.BytesValue.ClassName))return m.Hex+d.ArgParamsSeparator+e.valueOf().toString("hex");if(t.getName()==="EsdtTokenPayment"){let r=e.getFieldValue("token_identifier").valueOf(),a=e.getFieldValue("token_nonce").valueOf(),s=e.getFieldValue("amount").valueOf(),o=new n.TokenComputer().computeExtendedIdentifier(new n.Token({identifier:r,nonce:BigInt(a)}));return m.Asset+d.ArgParamsSeparator+o+d.ArgCompositeSeparator+s}if(t.hasExactClass(n.TokenIdentifierType.ClassName)||e.hasClassOrSuperclass(n.TokenIdentifierValue.ClassName))return C.Token+d.ArgParamsSeparator+e.valueOf();if(t.hasExactClass(n.CodeMetadataType.ClassName)||e.hasClassOrSuperclass(n.CodeMetadataValue.ClassName))return C.CodeMeta+d.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){let r=this.coreSerializer.nativeToString(e,t);return this.stringToTyped(r)}nativeToType(e){if(e.startsWith(m.Tuple)){let t=e.match(/\(([^)]+)\)/)?.[1];return new n.CompositeType(...t.split(d.ArgCompositeSeparator).map(r=>this.nativeToType(r)))}if(e===m.String)return new n.StringType;if(e===m.Uint8)return new n.U8Type;if(e===m.Uint16)return new n.U16Type;if(e===m.Uint32)return new n.U32Type;if(e===m.Uint64)return new n.U64Type;if(e===m.Biguint)return new n.BigUIntType;if(e===m.Bool)return new n.BooleanType;if(e===m.Address)return new n.AddressType;if(e===m.Hex)return new n.BytesType;if(e===m.Asset)return new n.StructType("EsdtTokenPayment",[new n.FieldDefinition("token_identifier","",new n.TokenIdentifierType),new n.FieldDefinition("token_nonce","",new n.U64Type),new n.FieldDefinition("amount","",new n.BigUIntType)]);if(e===C.Token)return new n.TokenIdentifierType;if(e===C.CodeMeta)return new n.CodeMetadataType;throw new Error(`WarpArgSerializer (nativeToType): Unsupported input type: ${e}`)}stringToTyped(e){let[t,r]=e.split(/:(.*)/,2);if(t===m.Option){let a=this.stringToTyped(r);return a instanceof n.NothingValue?n.OptionValue.newMissingTyped(a.getType()):n.OptionValue.newProvided(a)}if(t===m.Vector){let[a,s]=r.split(De,2),o=s.split(d.ArgListSeparator).map(l=>this.stringToTyped(`${a}:${l}`));return new n.VariadicValue(new n.VariadicType(this.nativeToType(a)),o)}if(t.startsWith(m.Tuple)){let a=t.match(/\(([^)]+)\)/)?.[1],s=r.split(d.ArgCompositeSeparator),c=a.split(d.ArgCompositeSeparator),o=s.map((h,g)=>this.stringToTyped(c[g]+d.ArgParamsSeparator+h)),l=o.map(h=>h.getType());return new n.CompositeValue(new n.CompositeType(...l),o)}if(t===m.String)return r?n.StringValue.fromUTF8(r):new n.NothingValue;if(t===m.Uint8)return r?new n.U8Value(Number(r)):new n.NothingValue;if(t===m.Uint16)return r?new n.U16Value(Number(r)):new n.NothingValue;if(t===m.Uint32)return r?new n.U32Value(Number(r)):new n.NothingValue;if(t===m.Uint64)return r?new n.U64Value(BigInt(r)):new n.NothingValue;if(t===m.Biguint)return r?new n.BigUIntValue(BigInt(r)):new n.NothingValue;if(t===m.Bool)return r?new n.BooleanValue(typeof r=="boolean"?r:r==="true"):new n.NothingValue;if(t===m.Address)return r?new n.AddressValue(n.Address.newFromBech32(r)):new n.NothingValue;if(t===m.Hex)return r?n.BytesValue.fromHex(r):new n.NothingValue;if(t===m.Asset){let[a,s]=r.split(d.ArgCompositeSeparator),c=new n.TokenComputer,o=G(a)?Z(a):c.extractIdentifierFromExtendedIdentifier(a),l=G(a)?0n:c.extractNonceFromExtendedIdentifier(a);return new n.Struct(this.nativeToType("asset"),[new n.Field(new n.TokenIdentifierValue(o),"token_identifier"),new n.Field(new n.U64Value(BigInt(l)),"token_nonce"),new n.Field(new n.BigUIntValue(BigInt(s)),"amount")])}if(t===C.Null)return new n.NothingValue;if(t===C.Optional){let a=this.stringToTyped(r);return a instanceof n.NothingValue?n.OptionalValue.newMissing():new n.OptionalValue(a.getType(),a)}if(t===C.List){let[a,s]=r.split(De,2),o=s.split(d.ArgListSeparator).map(l=>this.stringToTyped(a+d.ArgParamsSeparator+l));return new n.List(this.nativeToType(a),o)}if(t===C.Token)return r?new n.TokenIdentifierValue(r):new n.NothingValue;if(t===C.CodeMeta)return new n.CodeMetadataValue(n.CodeMetadata.newFromBytes(Uint8Array.from(Buffer.from(r,"hex"))));throw new Error(`WarpArgSerializer (stringToTyped): Unsupported input type: ${t}`)}typeToString(e){if(e.hasExactClass(n.OptionType.ClassName))return m.Option+d.ArgParamsSeparator+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(n.VariadicType.ClassName))return m.Vector+d.ArgParamsSeparator+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(n.StringType.ClassName))return m.String;if(e.hasExactClass(n.U8Type.ClassName))return m.Uint8;if(e.hasExactClass(n.U16Type.ClassName))return m.Uint16;if(e.hasExactClass(n.U32Type.ClassName))return m.Uint32;if(e.hasExactClass(n.U64Type.ClassName))return m.Uint64;if(e.hasExactClass(n.BigUIntType.ClassName))return m.Biguint;if(e.hasExactClass(n.BooleanType.ClassName))return m.Bool;if(e.hasExactClass(n.AddressType.ClassName))return m.Address;if(e.hasExactClass(n.BytesType.ClassName))return m.Hex;if(e.hasExactClass(n.TokenIdentifierType.ClassName))return C.Token;if(e.hasExactClass(n.OptionalType.ClassName))return C.Optional+d.ArgParamsSeparator+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(n.ListType.ClassName))return C.List+d.ArgParamsSeparator+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(n.CodeMetadataType.ClassName))return C.CodeMeta;if(e.hasExactClass(n.StructType.ClassName)&&e.getClassName()==="EsdtTokenPayment")return m.Asset;throw new Error(`WarpArgSerializer (typeToString): Unsupported input type: ${e.getClassName()}`)}};var q=class{constructor(e,t){this.config=e;this.chain=t;this.abi=new M(e,t),this.serializer=new O,this.cache=new W.WarpCache(e.cache?.type)}async getTransactionExecutionResults(e,t){let{actionIndex:r}=(0,W.findWarpExecutableAction)(e),a=this.cache.get(W.WarpCacheKey.WarpExecutable(this.config.env,e.meta?.hash||"",r))??[],s=await this.extractContractResults(e,t,a),c=(0,W.getNextInfo)(this.config,[],e,r,s),o=(0,W.applyResultsToMessages)(e,s.results);return{success:t.status.isSuccessful(),warp:e,action:r,user:(0,W.getWarpWalletAddressFromConfig)(this.config,this.chain.name),txHash:t.hash,tx:t,next:c,values:s.values,valuesRaw:[],results:s.results,messages:o}}async extractContractResults(e,t,r){let{action:a,actionIndex:s}=(0,W.findWarpExecutableAction)(e),c=[],o={};if(!e.results||a.type!=="contract")return{values:c,results:o};if(!Object.values(e.results).some(I=>I.includes("out")||I.includes("event"))){for(let[I,y]of Object.entries(e.results))o[I]=y;return{values:c,results:await(0,W.evaluateResultsCommon)(e,o,s,r,this.config.transform?.runner)}}let h=await this.abi.getAbiForAction(a),g=new X.TransactionEventsParser({abi:h}),E=new X.SmartContractTransactionsOutcomeParser({abi:h}).parseExecute({transactionOnNetwork:t,function:a.func||void 0});for(let[I,y]of Object.entries(e.results)){if(y.startsWith(W.WarpConstants.Transform.Prefix))continue;if(y.startsWith("input.")){o[I]=y;continue}let k=(0,W.parseResultsOutIndex)(y);if(k!==null&&k!==s){o[I]=null;continue}let[B,S,D]=y.split(".");if(B==="event"){if(!S||isNaN(Number(D)))continue;let F=Number(D),T=(0,X.findEventsByFirstTopic)(t,S),Y=g.parseEvents({events:T})[0],ue=Object.values(Y)[F]||null;c.push(ue),o[I]=ue&&ue.valueOf()}else if(B==="out"||B.startsWith("out[")){if(!S)continue;let F=Number(S),T=E.values[F-1]||null;D&&(T=T[D]||null),T&&typeof T=="object"&&(T="toFixed"in T?T.toFixed():T.valueOf()),c.push(T),o[I]=T&&T.valueOf()}else o[I]=y}return{values:c,results:await(0,W.evaluateResultsCommon)(e,o,s,r)}}async extractQueryResults(e,t,r,a){let s=t.map(h=>this.serializer.typedToString(h)),c=t.map(h=>this.serializer.typedToNative(h)[1]),o={};if(!e.results)return{values:s,valuesRaw:c,results:o};let l=h=>{let g=h.split(".").slice(1).map(E=>parseInt(E)-1);if(g.length===0)return;let f=c[g[0]];for(let E=1;E<g.length;E++){if(f==null)return;f=f[g[E]]}return f};for(let[h,g]of Object.entries(e.results)){if(g.startsWith(W.WarpConstants.Transform.Prefix))continue;let f=(0,W.parseResultsOutIndex)(g);if(f!==null&&f!==r){o[h]=null;continue}g.startsWith("out.")||g==="out"||g.startsWith("out[")?o[h]=l(g)||null:o[h]=g}return{values:s,valuesRaw:c,results:await(0,W.evaluateResultsCommon)(e,o,r,a)}}async resolveWarpResultsRecursively(e){let t=e.warp,r=e.entryActionIndex,a=e.executor,s=e.inputs,c=e.meta,o=new Map,l=new Set,h=this;async function g(y,k=[]){if(o.has(y))return o.get(y);if(l.has(y))throw new Error(`Circular dependency detected at action ${y}`);l.add(y);let B=t.actions[y-1];if(!B)throw new Error(`Action ${y} not found`);let S;if(B.type==="query")S=await a.executeQuery(t,y,k);else if(B.type==="collect")S=await a.executeCollect(t,y,k,c);else throw new Error(`Unsupported or interactive action type: ${B.type}`);if(o.set(y,S),t.results)for(let D of Object.values(t.results)){let T=String(D).match(/^out\[(\d+)\]/);if(T){let Y=parseInt(T[1],10);Y!==y&&!o.has(Y)&&await g(Y)}}return l.delete(y),S}await g(r,s);let f={};for(let y of o.values())for(let[k,B]of Object.entries(y.results))B!==null?f[k]=B:k in f||(f[k]=null);let E=await(0,W.evaluateResultsCommon)(t,f,r,s,this.config.transform?.runner);return{...o.get(r),action:r,results:E}}};var Je="EGLD-000000",ae=class{constructor(e,t){this.config=e;this.chain=t;this.serializer=new O,this.abi=new M(this.config,this.chain),this.results=new q(this.config,this.chain)}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){let t=(0,N.getWarpWalletAddressFromConfig)(this.config,e.chain.name);if(!t)throw new Error("WarpMultiversxExecutor: createTransfer - user address not set");let r=w.Address.newFromBech32(t),a=new w.TransactionsFactoryConfig({chainID:e.chain.chainId}),s=e.data?Buffer.from(this.serializer.stringToTyped(e.data).valueOf()):null,c=e.transfers.length===1&&e.transfers[0].identifier===this.chain.nativeToken?.identifier,l=(c?e.transfers[0].amount:0n)+e.value;return await new w.TransferTransactionsFactory({config:a}).createTransactionForTransfer(r,{receiver:w.Address.newFromBech32(e.destination),nativeAmount:l,tokenTransfers:c?[]:this.toTokenTransfers(e.transfers),data:s?new Uint8Array(s):void 0})}async createContractCallTransaction(e){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),a=w.Address.newFromBech32(t),s=e.args.map(o=>this.serializer.stringToTyped(o)),c=new w.TransactionsFactoryConfig({chainID:e.chain.chainId});return new w.SmartContractTransactionsFactory({config:c}).createTransactionForExecute(a,{contract:w.Address.newFromBech32(e.destination),function:"func"in r&&r.func||"",gasLimit:"gasLimit"in r?BigInt(r.gasLimit||0):0n,arguments:s,tokenTransfers:this.toTokenTransfers(e.transfers),nativeTransferAmount:e.value})}async executeQuery(e){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),a=e.args.map(F=>this.serializer.stringToTyped(F)),s=v(e.chain,this.config.env,this.config),c=w.Address.newFromBech32(e.destination),o=s.createSmartContractController(r),l=o.createQuery({contract:c,function:t.func||"",arguments:a}),h=await o.runQuery(l),g=h.returnCode==="ok",f=new w.ArgSerializer,E=r.getEndpoint(h.function||t.func||""),I=(h.returnDataParts||[]).map(F=>Buffer.from(F)),y=f.buffersToValues(I,E.output),{values:k,valuesRaw:B,results:S}=await this.results.extractQueryResults(e.warp,y,e.action,e.resolvedInputs),D=(0,N.getNextInfo)(this.config,[],e.warp,e.action,S);return{success:g,warp:e.warp,action:e.action,user:(0,N.getWarpWalletAddressFromConfig)(this.config,e.chain.name),txHash:null,tx:null,next:D,values:k,valuesRaw:B,results:S,messages:(0,N.applyResultsToMessages)(e.warp,S)}}async signMessage(e,t){let r=w.UserSecretKey.fromString(t);return(await new w.UserSigner(r).sign(new Uint8Array(Buffer.from(e,"utf-8")))).toString()}toTokenTransfers(e){return e.map(t=>t.identifier===this.chain.nativeToken.identifier?{...t,identifier:Je}:t).map(t=>{let a=new w.TokenComputer().extractNonceFromExtendedIdentifier(t.identifier);return new w.TokenTransfer({token:new w.Token({identifier:t.identifier,nonce:BigInt(a||0)}),amount:t.amount})})}};var se=class{constructor(e,t){this.chain=e;this.config=t}getExplorers(){let e=We[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 s=H[t];if(s)return s}if(e){let s=H[e];if(s)return s}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(a=>{let s=H[a];s&&(r[a]=`${s}/accounts/${e}`)}),r}getTransactionUrls(e){let t=this.getAllExplorers(),r={};return t.forEach(a=>{let s=H[a];s&&(r[a]=`${s}/transactions/${e}`)}),r}};var u=require("@multiversx/sdk-core"),P=require("@vleap/warps");var ve={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 A=i=>{if(i==="devnet")return"erd1qqqqqqqqqqqqqpgqje2f99vr6r7sk54thg03c9suzcvwr4nfl3tsfkdl36";if(i==="testnet")throw new Error("Multiversx testnet is not supported");return"erd1qqqqqqqqqqqqqpgq3mrpj3u6q7tejv6d7eqhnyd27n9v5c5tl3ts08mffe"};var ie=i=>({hash:i.hash.toString("hex"),alias:i.alias?.toString()||null,trust:i.trust.toString(),owner:i.owner.toString(),createdAt:i.created_at.toNumber(),upgradedAt:i.upgraded_at?.toNumber(),brand:i.brand?.toString("hex")||null,upgrade:i.upgrade?.toString("hex")||null}),Ce=i=>({unitPrice:BigInt(i.unit_price.toString()),admins:i.admins.map(e=>e.toBech32())});var oe=class{constructor(e,t){this.config=e;this.chain=t;this.cache=new P.WarpCache(e.cache?.type),this.registryConfig={unitPrice:BigInt(0),admins:[]},this.userWallet=(0,P.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 a=u.Address.newFromBech32(this.userWallet),s=()=>this.isCurrentUserAdmin()?BigInt(0):t&&r?this.registryConfig.unitPrice*BigInt(3):t?this.registryConfig.unitPrice*BigInt(2):this.registryConfig.unitPrice,c=()=>t&&r?[u.BytesValue.fromHex(e),u.BytesValue.fromUTF8(t),u.BytesValue.fromHex(r)]:t?[u.BytesValue.fromHex(e),u.BytesValue.fromUTF8(t)]:[u.BytesValue.fromHex(e)];return await this.getFactory().createTransactionForExecute(a,{contract:u.Address.newFromBech32(A(this.config.env)),function:"registerWarp",gasLimit:BigInt(1e7),nativeTransferAmount:s(),arguments:c()})}async createWarpUnregisterTransaction(e){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let t=u.Address.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(t,{contract:u.Address.newFromBech32(A(this.config.env)),function:"unregisterWarp",gasLimit:BigInt(1e7),arguments:[u.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 a=u.Address.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(a,{contract:u.Address.newFromBech32(A(this.config.env)),function:"upgradeWarp",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:r?[u.BytesValue.fromUTF8(e),u.BytesValue.fromHex(t),u.BytesValue.fromHex(r)]:[u.BytesValue.fromUTF8(e),u.BytesValue.fromHex(t)]})}async createWarpAliasSetTransaction(e,t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let r=u.Address.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(r,{contract:u.Address.newFromBech32(A(this.config.env)),function:"setWarpAlias",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[u.BytesValue.fromHex(e),u.BytesValue.fromUTF8(t)]})}async createWarpVerifyTransaction(e){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let t=u.Address.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(t,{contract:u.Address.newFromBech32(A(this.config.env)),function:"verifyWarp",gasLimit:BigInt(1e7),arguments:[u.BytesValue.fromHex(e)]})}async createWarpTransferOwnershipTransaction(e,t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let r=u.Address.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(r,{contract:u.Address.newFromBech32(A(this.config.env)),function:"transferOwnership",gasLimit:BigInt(1e7),arguments:[u.BytesValue.fromHex(e),new u.AddressValue(new u.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=u.Address.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(t,{contract:u.Address.newFromBech32(A(this.config.env)),function:"registerBrand",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[u.BytesValue.fromHex(e)]})}async createWarpBrandingTransaction(e,t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let r=u.Address.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(r,{contract:u.Address.newFromBech32(A(this.config.env)),function:"brandWarp",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[u.BytesValue.fromHex(e),u.BytesValue.fromHex(t)]})}async getInfoByAlias(e,t){try{let r=P.WarpCacheKey.RegistryInfo(this.config.env,e),a=t?this.cache.get(r):null;if(a)return P.WarpLogger.info(`WarpRegistry (getInfoByAlias): RegistryInfo found in cache: ${e}`),a;let s=u.Address.newFromBech32(A(this.config.env)),c=this.getController(),o=c.createQuery({contract:s,function:"getInfoByAlias",arguments:[u.BytesValue.fromUTF8(e)]}),l=await c.runQuery(o),[h]=c.parseQueryResponse(l),g=h?ie(h):null,f=g?.brand?await this.fetchBrand(g.brand):null;return t&&t.ttl&&this.cache.set(r,{registryInfo:g,brand:f},t.ttl),{registryInfo:g,brand:f}}catch{return{registryInfo:null,brand:null}}}async getInfoByHash(e,t){try{let r=P.WarpCacheKey.RegistryInfo(this.config.env,e);if(t){let f=this.cache.get(r);if(f)return P.WarpLogger.info(`WarpRegistry (getInfoByHash): RegistryInfo found in cache: ${e}`),f}let a=u.Address.newFromBech32(A(this.config.env)),s=this.getController(),c=s.createQuery({contract:a,function:"getInfoByHash",arguments:[u.BytesValue.fromHex(e)]}),o=await s.runQuery(c),[l]=s.parseQueryResponse(o),h=l?ie(l):null,g=h?.brand?await this.fetchBrand(h.brand):null;return t&&t.ttl&&this.cache.set(r,{registryInfo:h,brand:g},t.ttl),{registryInfo:h,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=u.Address.newFromBech32(A(this.config.env)),a=this.getController(),s=a.createQuery({contract:r,function:"getUserWarps",arguments:[new u.AddressValue(new u.Address(t))]}),c=await a.runQuery(s),[o]=a.parseQueryResponse(c);return o.map(ie)}catch{return[]}}async getUserBrands(e){try{let t=e||this.userWallet;if(!t)throw new Error("WarpRegistry: user address not set");let r=u.Address.newFromBech32(A(this.config.env)),a=this.getController(),s=a.createQuery({contract:r,function:"getUserBrands",arguments:[new u.AddressValue(new u.Address(t))]}),c=await a.runQuery(s),[o]=a.parseQueryResponse(c),l=o.map(f=>f.toString("hex")),h={ttl:365*24*60*60};return(await Promise.all(l.map(f=>this.fetchBrand(f,h)))).filter(f=>f!==null)}catch{return[]}}async fetchBrand(e,t){let r=P.WarpCacheKey.Brand(this.config.env,e),a=t?this.cache.get(r):null;if(a)return P.WarpLogger.info(`WarpRegistry (fetchBrand): Brand found in cache: ${e}`),a;let c=v(this.chain,this.config.env,this.config).createNetworkProvider();try{let o=await c.getTransaction(e),l=JSON.parse(o.data.toString());return l.meta={chain:this.chain.name,hash:o.hash,creator:o.sender.toBech32(),createdAt:new Date(o.timestamp*1e3).toISOString()},t&&t.ttl&&this.cache.set(r,l,t.ttl),l}catch{return null}}async loadRegistryConfigs(){let e=u.Address.newFromBech32(A(this.config.env)),t=this.getController(),[r]=await t.query({contract:e,function:"getConfig",arguments:[]}),a=r?Ce(r):null;this.registryConfig=a||{unitPrice:BigInt(0),admins:[]}}getFactory(){let e=new u.TransactionsFactoryConfig({chainID:this.chain.chainId}),t=u.AbiRegistry.create(ve);return new u.SmartContractTransactionsFactory({config:e,abi:t})}getController(){let e=v(this.chain,this.config.env,this.config),t=u.AbiRegistry.create(ve);return e.createSmartContractController(t)}isCurrentUserAdmin(){return!!this.userWallet&&this.registryConfig.admins.includes(this.userWallet)}};var V=require("@multiversx/sdk-core"),L=require("@vleap/warps");var ce=class{constructor(e,t){this.config=e;this.chain=t;this.entry=v(t,e.env,e),this.provider=this.entry.createNetworkProvider(),this.cache=new L.WarpCache(e.cache?.type)}async signTransaction(e){if(!e||typeof e!="object")throw new Error("Invalid transaction object");let t=(0,L.getWarpWalletPrivateKeyFromConfig)(this.config,this.chain.name);if(!t)throw new Error("Wallet not initialized - no private key provided");let a=t.startsWith("-----")?V.UserSecretKey.fromPem(t):V.UserSecretKey.fromString(t),s=new V.Account(a);if(e.nonce===0n){let c=await this.entry.recallAccountNonce(s.address),o=this.cache.get(`nonce:${s.address.toBech32()}`)||0,l=BigInt(Math.max(o,Number(c)));e.nonce=l}return e.signature=await s.signTransaction(e),this.cache.set(`nonce:${s.address.toBech32()}`,Number(s.nonce),L.CacheTtl.OneHour),e}async signMessage(e){let t=(0,L.getWarpWalletPrivateKeyFromConfig)(this.config,this.chain.name);if(!t)throw new Error("Wallet not initialized - no private key provided");let a=t.startsWith("-----")?V.UserSecretKey.fromPem(t):V.UserSecretKey.fromString(t),s=new V.UserSigner(a),c=new TextEncoder().encode(e),o=await s.sign(c);return Buffer.from(o).toString("hex")}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)}create(e){let r=V.Mnemonic.fromString(e).deriveKey(0),a=r.hex();return{address:r.generatePublicKey().toAddress(this.chain.addressHrp).toBech32(),privateKey:a,mnemonic:e}}generate(){let e=V.Mnemonic.generate(),t=e.toString(),r=e.deriveKey(0),a=r.hex();return{address:r.generatePublicKey().toAddress(this.chain.addressHrp).toBech32(),privateKey:a,mnemonic:t}}getAddress(){return(0,L.getWarpWalletAddressFromConfig)(this.config,this.chain.name)}};var pe=(i,e,t)=>(r,a)=>{let s=t[r.env];return{chain:i,chainInfo:s,prefix:e,builder:()=>new re(r,s),executor:new ae(r,s),results:new q(r,s),serializer:new O,registry:new oe(r,s),explorer:new se(i,r),abiBuilder:()=>new M(r,s),brandBuilder:()=>new te(r,s),dataLoader:new ne(r,s),wallet:new ce(r,s),registerTypes:c=>{c.registerType("token",{stringToNative:o=>o,nativeToString:o=>`token:${o}`}),c.registerType("codemeta",{stringToNative:o=>o,nativeToString:o=>`codemeta:${o}`})}}};var de={chain:J.WarpChainName.Multiversx,identifier:"EGLD",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://vleap.ai/images/tokens/egld.svg"},Te=pe(J.WarpChainName.Multiversx,"multiversx",{mainnet:{name:J.WarpChainName.Multiversx,displayName:"MultiversX",chainId:"1",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://api.multiversx.com",logoUrl:"https://vleap.ai/images/chains/multiversx.svg",nativeToken:de},testnet:{name:J.WarpChainName.Multiversx,displayName:"MultiversX Testnet",chainId:"T",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://testnet-api.multiversx.com",logoUrl:"https://vleap.ai/images/chains/multiversx.svg",nativeToken:de},devnet:{name:J.WarpChainName.Multiversx,displayName:"MultiversX Devnet",chainId:"D",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://devnet-api.multiversx.com",logoUrl:"https://vleap.ai/images/chains/multiversx.svg",nativeToken:de}});var he=require("@vleap/warps");var He={chain:he.WarpChainName.Vibechain,identifier:"VIBE",name:"VIBE",symbol:"VIBE",decimals:18,logoUrl:"https://vleap.ai/images/tokens/vibe.svg"},xe={name:he.WarpChainName.Vibechain,displayName:"VibeChain",chainId:"V",blockTime:600,addressHrp:"vibe",defaultApiUrl:"https://vibeox-api.multiversx.com",logoUrl:"https://vleap.ai/images/chains/vibechain.svg",nativeToken:He},Ae=pe(he.WarpChainName.Vibechain,"vibe",{mainnet:xe,testnet:xe,devnet:xe});var Ze=(i,e)=>[Te(i,e),Ae(i,e)],et=()=>[Ee.WarpChainName.Multiversx,Ee.WarpChainName.Vibechain];var le=require("@vleap/warps");var tt=i=>new le.WarpSerializer().nativeToString(C.Token,i),rt=i=>new le.WarpSerializer().nativeToString(C.CodeMeta,i),nt=(i,e)=>new le.WarpSerializer().nativeToString(C.Optional,i),at=i=>new le.WarpSerializer().nativeToString(C.List,i);var p=require("@multiversx/sdk-core"),st=(i,e)=>i?p.OptionValue.newProvided(i):e?p.OptionValue.newMissingTyped(e):p.OptionValue.newMissing(),it=(i,e)=>i?new p.OptionalValue(i.getType(),i):e?new p.OptionalValue(e):p.OptionalValue.newMissing(),ot=i=>{if(i.length===0)throw new Error("Cannot create a list from an empty array");let e=i[0].getType();return new p.List(e,i)},ct=i=>p.VariadicValue.fromItems(...i),pt=i=>{let e=i.map(t=>t.getType());return new p.CompositeValue(new p.CompositeType(...e),i)},lt=i=>p.StringValue.fromUTF8(i),ut=i=>new p.U8Value(i),mt=i=>new p.U16Value(i),dt=i=>new p.U32Value(i),ht=i=>new p.U64Value(i),ft=i=>new p.BigUIntValue(BigInt(i)),gt=i=>new p.BooleanValue(i),yt=i=>new p.AddressValue(p.Address.newFromBech32(i)),wt=i=>new p.TokenIdentifierValue(i),Wt=i=>p.BytesValue.fromHex(i),vt=i=>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(i.token.identifier),"token_identifier"),new p.Field(new p.U64Value(BigInt(i.token.nonce)),"token_nonce"),new p.Field(new p.BigUIntValue(BigInt(i.amount)),"amount")]),Ct=i=>new p.CodeMetadataValue(p.CodeMetadata.newFromBytes(Uint8Array.from(Buffer.from(i,"hex")))),Tt=()=>new p.NothingValue;0&&(module.exports={ExplorerUrls,KnownTokens,MultiversxExplorers,MultiversxExplorersConfig,NativeTokenEgld,NativeTokenVibe,VibechainExplorers,WarpMultiversxAbiBuilder,WarpMultiversxBrandBuilder,WarpMultiversxBuilder,WarpMultiversxConstants,WarpMultiversxContractLoader,WarpMultiversxDataLoader,WarpMultiversxExecutor,WarpMultiversxExplorer,WarpMultiversxInputTypes,WarpMultiversxRegistry,WarpMultiversxResults,WarpMultiversxSerializer,WarpMultiversxWallet,address_value,asset_value,biguint_value,boolean_value,codemeta,codemeta_value,composite_value,createMultiversxAdapter,findKnownTokenById,getAllMultiversxAdapters,getAllMultiversxChainNames,getKnownTokensForChain,getMultiversxAdapter,getMultiversxEntrypoint,getMultiversxRegistryAddress,getNormalizedTokenIdentifier,getVibechainAdapter,hex_value,isNativeToken,list,list_value,nothing_value,option,option_value,optional_value,string_value,toTypedConfigInfo,toTypedRegistryInfo,token,token_value,u16_value,u32_value,u64_value,u8_value,variadic_value});
|
|
1
|
+
"use strict";var fe=Object.defineProperty;var Ge=Object.getOwnPropertyDescriptor;var $e=Object.getOwnPropertyNames;var Ke=Object.prototype.hasOwnProperty;var qe=(i,e)=>{for(var t in e)fe(i,t,{get:e[t],enumerable:!0})},ze=(i,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of $e(e))!Ke.call(i,a)&&a!==t&&fe(i,a,{get:()=>e[a],enumerable:!(r=Ge(e,a))||r.enumerable});return i};var Qe=i=>ze(fe({},"__esModule",{value:!0}),i);var xt={};qe(xt,{ExplorerUrls:()=>H,KnownTokens:()=>ye,MultiversxExplorers:()=>Oe,MultiversxExplorersConfig:()=>Ce,NativeTokenEgld:()=>de,NativeTokenVibe:()=>He,VibechainExplorers:()=>Le,WarpMultiversxAbiBuilder:()=>M,WarpMultiversxBrandBuilder:()=>te,WarpMultiversxBuilder:()=>re,WarpMultiversxConstants:()=>Xe,WarpMultiversxContractLoader:()=>ee,WarpMultiversxDataLoader:()=>ne,WarpMultiversxExecutor:()=>ae,WarpMultiversxExplorer:()=>se,WarpMultiversxInputTypes:()=>v,WarpMultiversxRegistry:()=>oe,WarpMultiversxResults:()=>q,WarpMultiversxSerializer:()=>O,WarpMultiversxWallet:()=>ce,address_value:()=>yt,asset_value:()=>Wt,biguint_value:()=>ft,boolean_value:()=>gt,codemeta:()=>rt,codemeta_value:()=>vt,composite_value:()=>pt,createMultiversxAdapter:()=>pe,findKnownTokenById:()=>we,getAllMultiversxAdapters:()=>Ze,getAllMultiversxChainNames:()=>et,getKnownTokensForChain:()=>je,getMultiversxAdapter:()=>Te,getMultiversxEntrypoint:()=>W,getMultiversxRegistryAddress:()=>b,getNormalizedTokenIdentifier:()=>Z,getVibechainAdapter:()=>Ae,hex_value:()=>Ct,isNativeToken:()=>G,list:()=>at,list_value:()=>ot,nothing_value:()=>Tt,option:()=>nt,option_value:()=>st,optional_value:()=>it,string_value:()=>lt,toTypedConfigInfo:()=>ve,toTypedRegistryInfo:()=>ie,token:()=>tt,token_value:()=>wt,u16_value:()=>mt,u32_value:()=>dt,u64_value:()=>ht,u8_value:()=>ut,variadic_value:()=>ct});module.exports=Qe(xt);var Ee=require("@vleap/warps");var J=require("@vleap/warps");var R=require("@multiversx/sdk-core"),S=require("@vleap/warps");var z=require("@multiversx/sdk-core"),be=require("@vleap/warps"),G=i=>!i.includes("-"),Z=i=>G(i)?`${i}-000000`:i,W=(i,e,t)=>{let r="warp-sdk",s=t?(0,be.getProviderUrl)(t,i.name,e,i.defaultApiUrl):i.defaultApiUrl;return e==="devnet"?new z.DevnetEntrypoint({url:s,kind:"api",clientName:r}):e==="testnet"?new z.TestnetEntrypoint({url:s,kind:"api",clientName:r}):new z.MainnetEntrypoint({url:s,kind:"api",clientName:r})};var ge=require("@vleap/warps");var ee=class{constructor(e){this.config=e}async getContract(e,t){try{let s=await W(t,this.config.env,this.config).createNetworkProvider().doGetGeneric(`accounts/${e}`);return{address:e,owner:s.ownerAddress,verified:s.isVerified||!1}}catch(r){return ge.WarpLogger.error("WarpContractLoader: getContract error",r),null}}async getVerificationInfo(e,t){try{let s=await W(t,this.config.env,this.config).createNetworkProvider().doGetGeneric(`accounts/${e}/verification`);return{codeHash:s.codeHash,abi:s.source.abi}}catch(r){return ge.WarpLogger.error("WarpContractLoader: getVerificationInfo error",r),null}}};var M=class{constructor(e,t){this.config=e;this.chain=t;this.contractLoader=new ee(this.config),this.cache=new S.WarpCache(this.config.cache?.type)}async createInscriptionTransaction(e){let t=(0,S.getWarpWalletAddressFromConfig)(this.config,this.chain.name);if(!t)throw new Error("WarpBuilder: user address not set");let r=new R.TransactionsFactoryConfig({chainID:this.chain.chainId}),a=new R.TransferTransactionsFactory({config:r}),s=R.Address.newFromBech32(t),c={protocol:(0,S.getLatestProtocolIdentifier)("abi"),content:e},o=JSON.stringify(c),p=await a.createTransactionForTransfer(s,{receiver:s,nativeAmount:BigInt(0),data:Uint8Array.from(Buffer.from(o))});return p.gasLimit=p.gasLimit+BigInt(2e6),p}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,hash:e.hash,creator:e.sender.toBech32(),createdAt:new Date(e.timestamp*1e3).toISOString()},t}async createFromTransactionHash(e,t){let r=S.WarpCacheKey.WarpAbi(this.config.env,e);if(t){let c=this.cache.get(r);if(c)return S.WarpLogger.info(`WarpAbiBuilder (createFromTransactionHash): Warp abi found in cache: ${e}`),c}let s=W(this.chain,this.config.env,this.config).createNetworkProvider();try{let c=await s.getTransaction(e),o=await this.createFromTransaction(c);return t&&t.ttl&&o&&this.cache.set(r,o,t.ttl),o}catch(c){return S.WarpLogger.error("WarpAbiBuilder: Error creating from transaction hash",c),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 R.AbiRegistry.create(t.abi)}async fetchAbi(e){if(!e.abi)throw new Error("WarpActionExecutor: ABI not found");if(e.abi.startsWith(S.WarpConstants.IdentifierType.Hash)){let t=e.abi.split(S.WarpConstants.ArgParamsSeparator)[1],r=await this.createFromTransactionHash(t);if(!r)throw new Error(`WarpActionExecutor: ABI not found for hash: ${e.abi}`);return R.AbiRegistry.create(r.content)}else{let r=await(await fetch(e.abi)).json();return R.AbiRegistry.create(r)}}};var $=require("@multiversx/sdk-core"),Q=require("@vleap/warps"),Se=require("buffer");var te=class{constructor(e,t){this.config=e;this.chain=t;this.core=new Q.WarpBrandBuilder(e)}async createInscriptionTransaction(e){let t=(0,Q.getWarpWalletAddressFromConfig)(this.config,this.chain.name);if(!t)throw new Error("BrandBuilder: user address not set");let r=new $.TransactionsFactoryConfig({chainID:this.chain.chainId}),a=new $.TransferTransactionsFactory({config:r}),s=$.Address.newFromBech32(t),c=JSON.stringify(e);return await a.createTransactionForNativeTokenTransfer(s,{receiver:$.Address.newFromBech32(t),nativeAmount:BigInt(0),data:Uint8Array.from(Se.Buffer.from(c))})}async createFromTransaction(e,t=!1){let r=await this.core.createFromRaw(e.data.toString(),t);return r.meta={chain:this.chain.name,hash:e.hash,creator:e.sender.toBech32(),createdAt:new Date(e.timestamp*1e3).toISOString()},r}async createFromTransactionHash(e){let r=W(this.chain,this.config.env,this.config).createNetworkProvider();try{let a=await r.getTransaction(e);return this.createFromTransaction(a)}catch(a){return Q.WarpLogger.error("BrandBuilder: Error creating from transaction hash",a),null}}};var K=require("@multiversx/sdk-core"),N=require("@vleap/warps");var re=class extends N.WarpBuilder{constructor(t,r){super(t);this.config=t;this.chain=r;this.cache=new N.WarpCache(t.cache?.type),this.core=new N.WarpBuilder(t)}async createInscriptionTransaction(t){let r=(0,N.getWarpWalletAddressFromConfig)(this.config,this.chain.name);if(!r)throw new Error("WarpBuilder: user address not set");let a=new K.TransactionsFactoryConfig({chainID:this.chain.chainId}),s=new K.TransferTransactionsFactory({config:a}),c=K.Address.newFromBech32(r),o=JSON.stringify(t),p=await s.createTransactionForTransfer(c,{receiver:K.Address.newFromBech32(r),nativeAmount:BigInt(0),data:Uint8Array.from(Buffer.from(o))});return p.gasLimit=p.gasLimit+BigInt(2e6),p}async createFromTransaction(t,r=!1){let a=await this.core.createFromRaw(t.data.toString(),r);return a.meta={chain:this.chain.name,hash:t.hash,creator:t.sender.toBech32(),createdAt:new Date(t.timestamp*1e3).toISOString()},a}async createFromTransactionHash(t,r){let a=N.WarpCacheKey.Warp(this.config.env,t);if(r){let o=this.cache.get(a);if(o)return N.WarpLogger.info(`WarpBuilder (createFromTransactionHash): Warp found in cache: ${t}`),o}let c=W(this.chain,this.config.env,this.config).createNetworkProvider();try{let o=await c.getTransaction(t),p=await this.createFromTransaction(o);return r&&r.ttl&&p&&this.cache.set(a,p,r.ttl),p}catch(o){return N.WarpLogger.error("WarpBuilder: Error creating from transaction hash",o),null}}};var _=require("@multiversx/sdk-core"),j=require("@vleap/warps");var Be=require("@vleap/warps"),Ie=Be.WarpChainName.Multiversx,Ne=[{chain:Ie,identifier:"EGLD",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"},{chain:Ie,identifier:"EGLD-000000",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"}];var Ue=require("@vleap/warps"),E=Ue.WarpChainName.Multiversx,Pe=[{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"},{chain:E,identifier:"SEGLD-3ad2d0",name:"StakedEGLD",symbol:"SEGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/SEGLD-3ad2d0/icon.png"},{chain:E,identifier:"HSEGLD-c13a4e",name:"HatomSEGLD",symbol:"HSEGLD",decimals:8,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/HSEGLD-c13a4e/icon.png"},{chain:E,identifier:"UTK-2f80e9",name:"xMoney UTK",symbol:"UTK",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/UTK-2f80e9/icon.png"},{chain:E,identifier:"USDC-c76f1f",name:"WrappedUSDC",symbol:"USDC",decimals:6,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/USDC-c76f1f/icon.png"},{chain:E,identifier:"WEGLD-bd4d79",name:"WrappedEGLD",symbol:"WEGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/WEGLD-bd4d79/icon.png"},{chain:E,identifier:"HTM-f51d55",name:"Hatom",symbol:"HTM",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/HTM-f51d55/icon.png"},{chain:E,identifier:"MEX-455c57",name:"MEX",symbol:"MEX",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/MEX-455c57/icon.png"},{chain:E,identifier:"WTAO-4f5363",name:"WrappedTAO",symbol:"WTAO",decimals:9,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/WTAO-4f5363/icon.png"},{chain:E,identifier:"HEGLD-d61095",name:"HatomEGLD",symbol:"HEGLD",decimals:8,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/HEGLD-d61095/icon.png"},{chain:E,identifier:"WBTC-5349b3",name:"WrappedBTC",symbol:"WBTC",decimals:8,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/WBTC-5349b3/icon.png"},{chain:E,identifier:"WETH-b4ca29",name:"WrappedETH",symbol:"WETH",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/WETH-b4ca29/icon.png"},{chain:E,identifier:"USH-111e09",name:"HatomUSD",symbol:"USH",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/USH-111e09/icon.png"},{chain:E,identifier:"USDT-f8c08c",name:"WrappedUSDT",symbol:"USDT",decimals:6,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/USDT-f8c08c/icon.png"}];var ke=require("@vleap/warps"),Ve=ke.WarpChainName.Multiversx,Fe=[{chain:Ve,identifier:"EGLD",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"},{chain:Ve,identifier:"EGLD-000000",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"}];var Me=require("@vleap/warps"),Re=Me.WarpChainName.Vibechain,me=[{chain:Re,identifier:"VIBE",name:"VIBE",symbol:"VIBE",decimals:18,logoUrl:"https://vleap.ai/images/tokens/vibe.svg"},{chain:Re,identifier:"VIBE-000000",name:"VIBE",symbol:"VIBE",decimals:18,logoUrl:"https://vleap.ai/images/tokens/vibe.svg"}];var ye={multiversx:{mainnet:Pe,testnet:Fe,devnet:Ne},vibechain:{mainnet:me,testnet:me,devnet:me}},we=(i,e,t)=>(ye[i]?.[e]||[]).find(a=>a.identifier===t)||null,je=(i,e)=>ye[i]?.[e]||[];var ne=class{constructor(e,t){this.config=e;this.chain=t;this.cache=new j.WarpCache(e.cache?.type)}async getAccount(e){let r=await W(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=W(this.chain,this.config.env,this.config).createNetworkProvider(),r=t.getAccount(_.Address.newFromBech32(e)),a=t.getFungibleTokensOfAccount(_.Address.newFromBech32(e)),[s,c]=await Promise.all([r,a]),o=s.balance>0?[{...this.chain.nativeToken,amount:s.balance}]:[];return o.push(...c.map(p=>({chain:this.chain.name,identifier:p.token.identifier,name:p.raw.name,symbol:p.raw.ticker,amount:p.amount,decimals:p.raw.decimals,logoUrl:p.raw.assets?.pngUrl||"",price:p.raw.price?Number(p.raw.price):void 0,supply:p.raw.supply?BigInt(p.raw.supply):void 0}))),o}async getAsset(e){let t=j.WarpCacheKey.Asset(this.config.env,this.chain.name,e),r=this.cache.get(t);if(r)return r;let a=we(this.chain.name,this.config.env,e);if(a)return{chain:this.chain.name,identifier:e,name:a.name,symbol:a.symbol,amount:0n,decimals:a.decimals,logoUrl:a.logoUrl};let s=new _.TokenComputer,c=G(e)?0n:s.extractNonceFromExtendedIdentifier(e),o=new _.Token({identifier:e,nonce:BigInt(c||0)}),p=s.isFungible(o),h=W(this.chain,this.config.env,this.config).createNetworkProvider(),g=Z(e),f=await h.doGetGeneric(`tokens/${g}`),T={chain:this.chain.name,identifier:o.identifier,name:f.name,symbol:f.ticker,amount:0n,decimals:f.decimals,logoUrl:f.assets?.pngUrl||"#",price:f.price?Number(f.price):void 0,supply:f.supply?BigInt(f.supply):void 0};return this.cache.set(t,T,j.CacheTtl.OneHour),T}async getAction(e,t=!1){let r=W(this.chain,this.config.env,this.config),a=t?await r.awaitCompletedTransaction(e):await r.getTransaction(e);return{chain:this.chain.name,id:a.hash,receiver:a.receiver.toBech32(),sender:a.sender.toBech32(),value:a.value,function:a.function,status:this.toActionStatus(a),createdAt:this.toActionCreatedAt(a),error:a?.smartContractResults.map(s=>s.raw.returnMessage)[0]||null,tx:a}}async getAccountActions(e,t){let r=W(this.chain,this.config.env,this.config).createNetworkProvider(),a=`accounts/${e}/transactions`,s=new URLSearchParams,c=t?.size||25,o=t?.page||0;if(o>0){let h=o*c;s.append("from",h.toString())}return c!==25&&s.append("size",c.toString()),s.toString()&&(a+=`?${s.toString()}`),(await r.doGetGeneric(a)).map(h=>({chain:this.chain.name,id:h.txHash,receiver:h.receiver,sender:h.sender,value:h.value,function:h.function,status:this.toActionStatus(h),createdAt:this.toActionCreatedAt(h)}))}toActionStatus(e){return e.status.isSuccessful()?"success":e.status.isFailed()?"failed":"pending"}toActionCreatedAt(e){return new Date(e.timestamp||e.timestamp*1e3).toISOString()}};var w=require("@multiversx/sdk-core"),U=require("@vleap/warps");var X=require("@multiversx/sdk-core"),C=require("@vleap/warps");var n=require("@multiversx/sdk-core"),_e=require("@vleap/warps");var d={HttpProtocolPrefix:"http",IdentifierParamName:"warp",IdentifierParamSeparator:":",IdentifierChainDefault:"multiversx",IdentifierType:{Alias:"alias",Hash:"hash"},Globals:{UserWallet:{Placeholder:"USER_WALLET",Accessor:i=>i.config.user?.wallets?.[i.chain]},ChainApiUrl:{Placeholder:"CHAIN_API",Accessor:i=>i.chainInfo.defaultApiUrl},ChainAddressHrp:{Placeholder:"CHAIN_ADDRESS_HRP",Accessor:i=>i.chainInfo.addressHrp}},Vars:{Query:"query",Env:"env"},ArgParamsSeparator:":",ArgCompositeSeparator:"|",ArgListSeparator:",",Transform:{Prefix:"transform:"},Source:{UserWallet:"user:wallet"},Position:{Payload:"payload:"}},m={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 Xe={Egld:{Identifier:"EGLD",EsdtIdentifier:"EGLD-000000",DisplayName:"eGold",Decimals:18}},v={Null:"null",Optional:"optional",List:"list",Token:"token",CodeMeta:"codemeta"},Oe=(r=>(r.MultiversxExplorer="multiversx_explorer",r.MultiversxExplorerDevnet="multiversx_explorer_devnet",r.MultiversxExplorerTestnet="multiversx_explorer_testnet",r))(Oe||{}),Le=(r=>(r.VibechainExplorer="vibechain_explorer",r.VibechainExplorerDevnet="vibechain_explorer_devnet",r.VibechainExplorerTestnet="vibechain_explorer_testnet",r))(Le||{}),Ce={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 De=new RegExp(`${d.ArgParamsSeparator}(.*)`),O=class{constructor(){this.coreSerializer=new _e.WarpSerializer}typedToString(e){let t=e.getType();if(t.hasExactClass(n.OptionType.ClassName)||e.hasClassOrSuperclass(n.OptionValue.ClassName)){if(!e.isSet())return m.Option+d.ArgParamsSeparator+"null";let r=this.typedToString(e.getTypedValue());return m.Option+d.ArgParamsSeparator+r}if(t.hasExactClass(n.VariadicType.ClassName)||e.hasClassOrSuperclass(n.VariadicValue.ClassName)){let r=e.getItems(),s=r.map(o=>this.typedToString(o).split(d.ArgParamsSeparator)[0])[0],c=r.map(o=>this.typedToString(o).split(d.ArgParamsSeparator)[1]);return m.Vector+d.ArgParamsSeparator+s+d.ArgParamsSeparator+c.join(d.ArgListSeparator)}if(t.hasExactClass(n.OptionalType.ClassName)||e.hasClassOrSuperclass(n.OptionalValue.ClassName)){if(!e.isSet())return v.Optional+d.ArgParamsSeparator+"null";let r=this.typedToString(e.getTypedValue());return v.Optional+d.ArgParamsSeparator+r}if(t.hasExactClass(n.ListType.ClassName)||e.hasClassOrSuperclass(n.List.ClassName)){let r=e.getItems(),s=r.map(o=>this.typedToString(o).split(d.ArgParamsSeparator)[0])[0],c=r.map(o=>this.typedToString(o).split(d.ArgParamsSeparator)[1]);return v.List+d.ArgParamsSeparator+s+d.ArgParamsSeparator+c.join(d.ArgListSeparator)}if(t.hasExactClass(n.CompositeType.ClassName)||e.hasClassOrSuperclass(n.CompositeValue.ClassName)){let r=e.getItems(),a=r.map(p=>this.typedToString(p).split(d.ArgParamsSeparator)[0]),s=r.map(p=>this.typedToString(p).split(d.ArgParamsSeparator)[1]),c=a.join(d.ArgCompositeSeparator),o=s.join(d.ArgCompositeSeparator);return`${m.Tuple}(${c})${d.ArgParamsSeparator}${o}`}if(t.hasExactClass(n.BigUIntType.ClassName)||e.hasClassOrSuperclass(n.BigUIntValue.ClassName)||t.getName()==="BigUint")return m.Biguint+d.ArgParamsSeparator+BigInt(e.valueOf().toFixed());if(t.hasExactClass(n.U8Type.ClassName)||e.hasClassOrSuperclass(n.U8Value.ClassName))return m.Uint8+d.ArgParamsSeparator+e.valueOf().toNumber();if(t.hasExactClass(n.U16Type.ClassName)||e.hasClassOrSuperclass(n.U16Value.ClassName))return m.Uint16+d.ArgParamsSeparator+e.valueOf().toNumber();if(t.hasExactClass(n.U32Type.ClassName)||e.hasClassOrSuperclass(n.U32Value.ClassName))return m.Uint32+d.ArgParamsSeparator+e.valueOf().toNumber();if(t.hasExactClass(n.U64Type.ClassName)||e.hasClassOrSuperclass(n.U64Value.ClassName))return m.Uint64+d.ArgParamsSeparator+BigInt(e.valueOf().toFixed());if(t.hasExactClass(n.StringType.ClassName)||e.hasClassOrSuperclass(n.StringValue.ClassName))return m.String+d.ArgParamsSeparator+e.valueOf();if(t.hasExactClass(n.BooleanType.ClassName)||e.hasClassOrSuperclass(n.BooleanValue.ClassName))return m.Bool+d.ArgParamsSeparator+e.valueOf();if(t.hasExactClass(n.AddressType.ClassName)||e.hasClassOrSuperclass(n.AddressValue.ClassName))return m.Address+d.ArgParamsSeparator+e.valueOf().toBech32();if(t.hasExactClass(n.BytesType.ClassName)||e.hasClassOrSuperclass(n.BytesValue.ClassName))return m.Hex+d.ArgParamsSeparator+e.valueOf().toString("hex");if(t.getName()==="EsdtTokenPayment"){let r=e.getFieldValue("token_identifier").valueOf(),a=e.getFieldValue("token_nonce").valueOf(),s=e.getFieldValue("amount").valueOf(),o=new n.TokenComputer().computeExtendedIdentifier(new n.Token({identifier:r,nonce:BigInt(a)}));return m.Asset+d.ArgParamsSeparator+o+d.ArgCompositeSeparator+s}if(t.hasExactClass(n.StructType.ClassName)||e.hasClassOrSuperclass(n.Struct.ClassName)){let r=e,s=r.getType().getName(),c=r.getFields();if(c.length===0)return`${m.Struct}(${s})${d.ArgParamsSeparator}`;let o=c.map(p=>{let h=p.name,g=p.value,f=g.getType(),T=this.typedToString(g).split(d.ArgParamsSeparator)[1];return`(${h}${d.ArgParamsSeparator}${this.typeToString(f)})${T}`});return`${m.Struct}(${s})${d.ArgParamsSeparator}${o.join(d.ArgListSeparator)}`}if(t.hasExactClass(n.TokenIdentifierType.ClassName)||e.hasClassOrSuperclass(n.TokenIdentifierValue.ClassName))return v.Token+d.ArgParamsSeparator+e.valueOf();if(t.hasExactClass(n.CodeMetadataType.ClassName)||e.hasClassOrSuperclass(n.CodeMetadataValue.ClassName))return v.CodeMeta+d.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){let r=this.coreSerializer.nativeToString(e,t);return this.stringToTyped(r)}nativeToType(e){if(e.startsWith(m.Tuple)){let t=e.match(/\(([^)]+)\)/)?.[1];return new n.CompositeType(...t.split(d.ArgCompositeSeparator).map(r=>this.nativeToType(r)))}if(e.startsWith(m.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 n.StructType(r,[])}if(e===m.String)return new n.StringType;if(e===m.Uint8)return new n.U8Type;if(e===m.Uint16)return new n.U16Type;if(e===m.Uint32)return new n.U32Type;if(e===m.Uint64)return new n.U64Type;if(e===m.Biguint)return new n.BigUIntType;if(e===m.Bool)return new n.BooleanType;if(e===m.Address)return new n.AddressType;if(e===m.Hex)return new n.BytesType;if(e===m.Asset)return new n.StructType("EsdtTokenPayment",[new n.FieldDefinition("token_identifier","",new n.TokenIdentifierType),new n.FieldDefinition("token_nonce","",new n.U64Type),new n.FieldDefinition("amount","",new n.BigUIntType)]);if(e===v.Token)return new n.TokenIdentifierType;if(e===v.CodeMeta)return new n.CodeMetadataType;throw new Error(`WarpArgSerializer (nativeToType): Unsupported input type: ${e}`)}stringToTyped(e){let[t,r]=e.split(/:(.*)/,2);if(t===m.Option){let a=this.stringToTyped(r);return a instanceof n.NothingValue?n.OptionValue.newMissingTyped(a.getType()):n.OptionValue.newProvided(a)}if(t===m.Vector){let[a,s]=r.split(De,2),o=s.split(d.ArgListSeparator).map(p=>this.stringToTyped(`${a}:${p}`));return new n.VariadicValue(new n.VariadicType(this.nativeToType(a)),o)}if(t.startsWith(m.Tuple)){let a=t.match(/\(([^)]+)\)/)?.[1],s=r.split(d.ArgCompositeSeparator),c=a.split(d.ArgCompositeSeparator),o=s.map((h,g)=>this.stringToTyped(c[g]+d.ArgParamsSeparator+h)),p=o.map(h=>h.getType());return new n.CompositeValue(new n.CompositeType(...p),o)}if(t.startsWith(m.Struct)){let a=t.match(/\(([^)]+)\)/),s=a?a[1]:"CustomStruct";if(!r)return new n.Struct(new n.StructType(s,[]),[]);let c=r.split(d.ArgListSeparator),o=[],p=[];return c.forEach(h=>{let g=h.match(new RegExp(`^\\(([^${d.ArgParamsSeparator}]+)${d.ArgParamsSeparator}([^)]+)\\)(.+)$`));if(g){let[,f,T,A]=g,y=this.stringToTyped(`${T}${d.ArgParamsSeparator}${A}`);o.push(new n.FieldDefinition(f,"",y.getType())),p.push(new n.Field(y,f))}}),new n.Struct(new n.StructType(s,o),p)}if(t===m.String)return r?n.StringValue.fromUTF8(r):new n.NothingValue;if(t===m.Uint8)return r?new n.U8Value(Number(r)):new n.NothingValue;if(t===m.Uint16)return r?new n.U16Value(Number(r)):new n.NothingValue;if(t===m.Uint32)return r?new n.U32Value(Number(r)):new n.NothingValue;if(t===m.Uint64)return r?new n.U64Value(BigInt(r)):new n.NothingValue;if(t===m.Biguint)return r?new n.BigUIntValue(BigInt(r)):new n.NothingValue;if(t===m.Bool)return r?new n.BooleanValue(typeof r=="boolean"?r:r==="true"):new n.NothingValue;if(t===m.Address)return r?new n.AddressValue(n.Address.newFromBech32(r)):new n.NothingValue;if(t===m.Hex)return r?n.BytesValue.fromHex(r):new n.NothingValue;if(t===m.Asset){let[a,s]=r.split(d.ArgCompositeSeparator),c=new n.TokenComputer,o=G(a)?Z(a):c.extractIdentifierFromExtendedIdentifier(a),p=G(a)?0n:c.extractNonceFromExtendedIdentifier(a);return new n.Struct(this.nativeToType("asset"),[new n.Field(new n.TokenIdentifierValue(o),"token_identifier"),new n.Field(new n.U64Value(BigInt(p)),"token_nonce"),new n.Field(new n.BigUIntValue(BigInt(s)),"amount")])}if(t===v.Null)return new n.NothingValue;if(t===v.Optional){let a=this.stringToTyped(r);return a instanceof n.NothingValue?n.OptionalValue.newMissing():new n.OptionalValue(a.getType(),a)}if(t===v.List){let[a,s]=r.split(De,2),o=s.split(d.ArgListSeparator).map(p=>this.stringToTyped(a+d.ArgParamsSeparator+p));return new n.List(this.nativeToType(a),o)}if(t===v.Token)return r?new n.TokenIdentifierValue(r):new n.NothingValue;if(t===v.CodeMeta)return new n.CodeMetadataValue(n.CodeMetadata.newFromBytes(Uint8Array.from(Buffer.from(r,"hex"))));throw new Error(`WarpArgSerializer (stringToTyped): Unsupported input type: ${t}`)}typeToString(e){if(e.hasExactClass(n.OptionType.ClassName))return m.Option+d.ArgParamsSeparator+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(n.VariadicType.ClassName))return m.Vector+d.ArgParamsSeparator+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(n.StringType.ClassName))return m.String;if(e.hasExactClass(n.U8Type.ClassName))return m.Uint8;if(e.hasExactClass(n.U16Type.ClassName))return m.Uint16;if(e.hasExactClass(n.U32Type.ClassName))return m.Uint32;if(e.hasExactClass(n.U64Type.ClassName))return m.Uint64;if(e.hasExactClass(n.BigUIntType.ClassName))return m.Biguint;if(e.hasExactClass(n.BooleanType.ClassName))return m.Bool;if(e.hasExactClass(n.AddressType.ClassName))return m.Address;if(e.hasExactClass(n.BytesType.ClassName))return m.Hex;if(e.hasExactClass(n.TokenIdentifierType.ClassName))return v.Token;if(e.hasExactClass(n.OptionalType.ClassName))return v.Optional+d.ArgParamsSeparator+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(n.ListType.ClassName))return v.List+d.ArgParamsSeparator+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(n.CodeMetadataType.ClassName))return v.CodeMeta;if(e.hasExactClass(n.StructType.ClassName)&&e.getClassName()==="EsdtTokenPayment")return m.Asset;if(e.hasExactClass(n.StructType.ClassName))return`${m.Struct}(${e.getName()})`;throw new Error(`WarpArgSerializer (typeToString): Unsupported input type: ${e.getClassName()}`)}};var q=class{constructor(e,t){this.config=e;this.chain=t;this.abi=new M(e,t),this.serializer=new O,this.cache=new C.WarpCache(e.cache?.type)}async getTransactionExecutionResults(e,t){let{actionIndex:r}=(0,C.findWarpExecutableAction)(e),a=this.cache.get(C.WarpCacheKey.WarpExecutable(this.config.env,e.meta?.hash||"",r))??[],s=await this.extractContractResults(e,t,a),c=(0,C.getNextInfo)(this.config,[],e,r,s),o=(0,C.applyResultsToMessages)(e,s.results);return{success:t.status.isSuccessful(),warp:e,action:r,user:(0,C.getWarpWalletAddressFromConfig)(this.config,this.chain.name),txHash:t.hash,tx:t,next:c,values:s.values,valuesRaw:[],results:s.results,messages:o}}async extractContractResults(e,t,r){let{action:a,actionIndex:s}=(0,C.findWarpExecutableAction)(e),c=[],o={};if(!e.results||a.type!=="contract")return{values:c,results:o};if(!Object.values(e.results).some(A=>A.includes("out")||A.includes("event"))){for(let[A,y]of Object.entries(e.results))o[A]=y;return{values:c,results:await(0,C.evaluateResultsCommon)(e,o,s,r,this.config.transform?.runner)}}let h=await this.abi.getAbiForAction(a),g=new X.TransactionEventsParser({abi:h}),T=new X.SmartContractTransactionsOutcomeParser({abi:h}).parseExecute({transactionOnNetwork:t,function:a.func||void 0});for(let[A,y]of Object.entries(e.results)){if(y.startsWith(C.WarpConstants.Transform.Prefix))continue;if(y.startsWith("input.")){o[A]=y;continue}let k=(0,C.parseResultsOutIndex)(y);if(k!==null&&k!==s){o[A]=null;continue}let[I,B,D]=y.split(".");if(I==="event"){if(!B||isNaN(Number(D)))continue;let F=Number(D),x=(0,X.findEventsByFirstTopic)(t,B),Y=g.parseEvents({events:x})[0],ue=Object.values(Y)[F]||null;c.push(ue),o[A]=ue&&ue.valueOf()}else if(I==="out"||I.startsWith("out[")){if(!B)continue;let F=Number(B),x=T.values[F-1]||null;D&&(x=x[D]||null),x&&typeof x=="object"&&(x="toFixed"in x?x.toFixed():x.valueOf()),c.push(x),o[A]=x&&x.valueOf()}else o[A]=y}return{values:c,results:await(0,C.evaluateResultsCommon)(e,o,s,r)}}async extractQueryResults(e,t,r,a){let s=t.map(h=>this.serializer.typedToString(h)),c=t.map(h=>this.serializer.typedToNative(h)[1]),o={};if(!e.results)return{values:s,valuesRaw:c,results:o};let p=h=>{let g=h.split(".").slice(1).map(T=>parseInt(T)-1);if(g.length===0)return;let f=c[g[0]];for(let T=1;T<g.length;T++){if(f==null)return;f=f[g[T]]}return f};for(let[h,g]of Object.entries(e.results)){if(g.startsWith(C.WarpConstants.Transform.Prefix))continue;let f=(0,C.parseResultsOutIndex)(g);if(f!==null&&f!==r){o[h]=null;continue}g.startsWith("out.")||g==="out"||g.startsWith("out[")?o[h]=p(g)||null:o[h]=g}return{values:s,valuesRaw:c,results:await(0,C.evaluateResultsCommon)(e,o,r,a)}}async resolveWarpResultsRecursively(e){let t=e.warp,r=e.entryActionIndex,a=e.executor,s=e.inputs,c=e.meta,o=new Map,p=new Set,h=this;async function g(y,k=[]){if(o.has(y))return o.get(y);if(p.has(y))throw new Error(`Circular dependency detected at action ${y}`);p.add(y);let I=t.actions[y-1];if(!I)throw new Error(`Action ${y} not found`);let B;if(I.type==="query")B=await a.executeQuery(t,y,k);else if(I.type==="collect")B=await a.executeCollect(t,y,k,c);else throw new Error(`Unsupported or interactive action type: ${I.type}`);if(o.set(y,B),t.results)for(let D of Object.values(t.results)){let x=String(D).match(/^out\[(\d+)\]/);if(x){let Y=parseInt(x[1],10);Y!==y&&!o.has(Y)&&await g(Y)}}return p.delete(y),B}await g(r,s);let f={};for(let y of o.values())for(let[k,I]of Object.entries(y.results))I!==null?f[k]=I:k in f||(f[k]=null);let T=await(0,C.evaluateResultsCommon)(t,f,r,s,this.config.transform?.runner);return{...o.get(r),action:r,results:T}}};var Je="EGLD-000000",ae=class{constructor(e,t){this.config=e;this.chain=t;this.serializer=new O,this.abi=new M(this.config,this.chain),this.results=new q(this.config,this.chain)}async createTransaction(e){let t=(0,U.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){let t=(0,U.getWarpWalletAddressFromConfig)(this.config,e.chain.name);if(!t)throw new Error("WarpMultiversxExecutor: createTransfer - user address not set");let r=w.Address.newFromBech32(t),a=new w.TransactionsFactoryConfig({chainID:e.chain.chainId}),s=e.data?Buffer.from(this.serializer.stringToTyped(e.data).valueOf()):null,c=e.transfers.length===1&&e.transfers[0].identifier===this.chain.nativeToken?.identifier,p=(c?e.transfers[0].amount:0n)+e.value;return await new w.TransferTransactionsFactory({config:a}).createTransactionForTransfer(r,{receiver:w.Address.newFromBech32(e.destination),nativeAmount:p,tokenTransfers:c?[]:this.toTokenTransfers(e.transfers),data:s?new Uint8Array(s):void 0})}async createContractCallTransaction(e){let t=(0,U.getWarpWalletAddressFromConfig)(this.config,e.chain.name);if(!t)throw new Error("WarpMultiversxExecutor: createContractCall - user address not set");let r=(0,U.getWarpActionByIndex)(e.warp,e.action),a=w.Address.newFromBech32(t),s=e.args.map(o=>this.serializer.stringToTyped(o)),c=new w.TransactionsFactoryConfig({chainID:e.chain.chainId});return new w.SmartContractTransactionsFactory({config:c}).createTransactionForExecute(a,{contract:w.Address.newFromBech32(e.destination),function:"func"in r&&r.func||"",gasLimit:"gasLimit"in r?BigInt(r.gasLimit||0):0n,arguments:s,tokenTransfers:this.toTokenTransfers(e.transfers),nativeTransferAmount:e.value})}async executeQuery(e){let t=(0,U.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),a=e.args.map(F=>this.serializer.stringToTyped(F)),s=W(e.chain,this.config.env,this.config),c=w.Address.newFromBech32(e.destination),o=s.createSmartContractController(r),p=o.createQuery({contract:c,function:t.func||"",arguments:a}),h=await o.runQuery(p),g=h.returnCode==="ok",f=new w.ArgSerializer,T=r.getEndpoint(h.function||t.func||""),A=(h.returnDataParts||[]).map(F=>Buffer.from(F)),y=f.buffersToValues(A,T.output),{values:k,valuesRaw:I,results:B}=await this.results.extractQueryResults(e.warp,y,e.action,e.resolvedInputs),D=(0,U.getNextInfo)(this.config,[],e.warp,e.action,B);return{success:g,warp:e.warp,action:e.action,user:(0,U.getWarpWalletAddressFromConfig)(this.config,e.chain.name),txHash:null,tx:null,next:D,values:k,valuesRaw:I,results:B,messages:(0,U.applyResultsToMessages)(e.warp,B)}}async signMessage(e,t){let r=w.UserSecretKey.fromString(t);return(await new w.UserSigner(r).sign(new Uint8Array(Buffer.from(e,"utf-8")))).toString()}toTokenTransfers(e){return e.map(t=>t.identifier===this.chain.nativeToken.identifier?{...t,identifier:Je}:t).map(t=>{let a=new w.TokenComputer().extractNonceFromExtendedIdentifier(t.identifier);return new w.TokenTransfer({token:new w.Token({identifier:t.identifier,nonce:BigInt(a||0)}),amount:t.amount})})}};var se=class{constructor(e,t){this.chain=e;this.config=t}getExplorers(){let e=Ce[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 s=H[t];if(s)return s}if(e){let s=H[e];if(s)return s}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(a=>{let s=H[a];s&&(r[a]=`${s}/accounts/${e}`)}),r}getTransactionUrls(e){let t=this.getAllExplorers(),r={};return t.forEach(a=>{let s=H[a];s&&(r[a]=`${s}/transactions/${e}`)}),r}};var u=require("@multiversx/sdk-core"),P=require("@vleap/warps");var We={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 b=i=>{if(i==="devnet")return"erd1qqqqqqqqqqqqqpgqje2f99vr6r7sk54thg03c9suzcvwr4nfl3tsfkdl36";if(i==="testnet")throw new Error("Multiversx testnet is not supported");return"erd1qqqqqqqqqqqqqpgq3mrpj3u6q7tejv6d7eqhnyd27n9v5c5tl3ts08mffe"};var ie=i=>({hash:i.hash.toString("hex"),alias:i.alias?.toString()||null,trust:i.trust.toString(),owner:i.owner.toString(),createdAt:i.created_at.toNumber(),upgradedAt:i.upgraded_at?.toNumber(),brand:i.brand?.toString("hex")||null,upgrade:i.upgrade?.toString("hex")||null}),ve=i=>({unitPrice:BigInt(i.unit_price.toString()),admins:i.admins.map(e=>e.toBech32())});var oe=class{constructor(e,t){this.config=e;this.chain=t;this.cache=new P.WarpCache(e.cache?.type),this.registryConfig={unitPrice:BigInt(0),admins:[]},this.userWallet=(0,P.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 a=u.Address.newFromBech32(this.userWallet),s=()=>this.isCurrentUserAdmin()?BigInt(0):t&&r?this.registryConfig.unitPrice*BigInt(3):t?this.registryConfig.unitPrice*BigInt(2):this.registryConfig.unitPrice,c=()=>t&&r?[u.BytesValue.fromHex(e),u.BytesValue.fromUTF8(t),u.BytesValue.fromHex(r)]:t?[u.BytesValue.fromHex(e),u.BytesValue.fromUTF8(t)]:[u.BytesValue.fromHex(e)];return await this.getFactory().createTransactionForExecute(a,{contract:u.Address.newFromBech32(b(this.config.env)),function:"registerWarp",gasLimit:BigInt(1e7),nativeTransferAmount:s(),arguments:c()})}async createWarpUnregisterTransaction(e){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let t=u.Address.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(t,{contract:u.Address.newFromBech32(b(this.config.env)),function:"unregisterWarp",gasLimit:BigInt(1e7),arguments:[u.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 a=u.Address.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(a,{contract:u.Address.newFromBech32(b(this.config.env)),function:"upgradeWarp",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:r?[u.BytesValue.fromUTF8(e),u.BytesValue.fromHex(t),u.BytesValue.fromHex(r)]:[u.BytesValue.fromUTF8(e),u.BytesValue.fromHex(t)]})}async createWarpAliasSetTransaction(e,t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let r=u.Address.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(r,{contract:u.Address.newFromBech32(b(this.config.env)),function:"setWarpAlias",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[u.BytesValue.fromHex(e),u.BytesValue.fromUTF8(t)]})}async createWarpVerifyTransaction(e){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let t=u.Address.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(t,{contract:u.Address.newFromBech32(b(this.config.env)),function:"verifyWarp",gasLimit:BigInt(1e7),arguments:[u.BytesValue.fromHex(e)]})}async createWarpTransferOwnershipTransaction(e,t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let r=u.Address.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(r,{contract:u.Address.newFromBech32(b(this.config.env)),function:"transferOwnership",gasLimit:BigInt(1e7),arguments:[u.BytesValue.fromHex(e),new u.AddressValue(new u.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=u.Address.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(t,{contract:u.Address.newFromBech32(b(this.config.env)),function:"registerBrand",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[u.BytesValue.fromHex(e)]})}async createWarpBrandingTransaction(e,t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let r=u.Address.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(r,{contract:u.Address.newFromBech32(b(this.config.env)),function:"brandWarp",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[u.BytesValue.fromHex(e),u.BytesValue.fromHex(t)]})}async getInfoByAlias(e,t){try{let r=P.WarpCacheKey.RegistryInfo(this.config.env,e),a=t?this.cache.get(r):null;if(a)return P.WarpLogger.info(`WarpRegistry (getInfoByAlias): RegistryInfo found in cache: ${e}`),a;let s=u.Address.newFromBech32(b(this.config.env)),c=this.getController(),o=c.createQuery({contract:s,function:"getInfoByAlias",arguments:[u.BytesValue.fromUTF8(e)]}),p=await c.runQuery(o),[h]=c.parseQueryResponse(p),g=h?ie(h):null,f=g?.brand?await this.fetchBrand(g.brand):null;return t&&t.ttl&&this.cache.set(r,{registryInfo:g,brand:f},t.ttl),{registryInfo:g,brand:f}}catch{return{registryInfo:null,brand:null}}}async getInfoByHash(e,t){try{let r=P.WarpCacheKey.RegistryInfo(this.config.env,e);if(t){let f=this.cache.get(r);if(f)return P.WarpLogger.info(`WarpRegistry (getInfoByHash): RegistryInfo found in cache: ${e}`),f}let a=u.Address.newFromBech32(b(this.config.env)),s=this.getController(),c=s.createQuery({contract:a,function:"getInfoByHash",arguments:[u.BytesValue.fromHex(e)]}),o=await s.runQuery(c),[p]=s.parseQueryResponse(o),h=p?ie(p):null,g=h?.brand?await this.fetchBrand(h.brand):null;return t&&t.ttl&&this.cache.set(r,{registryInfo:h,brand:g},t.ttl),{registryInfo:h,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=u.Address.newFromBech32(b(this.config.env)),a=this.getController(),s=a.createQuery({contract:r,function:"getUserWarps",arguments:[new u.AddressValue(new u.Address(t))]}),c=await a.runQuery(s),[o]=a.parseQueryResponse(c);return o.map(ie)}catch{return[]}}async getUserBrands(e){try{let t=e||this.userWallet;if(!t)throw new Error("WarpRegistry: user address not set");let r=u.Address.newFromBech32(b(this.config.env)),a=this.getController(),s=a.createQuery({contract:r,function:"getUserBrands",arguments:[new u.AddressValue(new u.Address(t))]}),c=await a.runQuery(s),[o]=a.parseQueryResponse(c),p=o.map(f=>f.toString("hex")),h={ttl:365*24*60*60};return(await Promise.all(p.map(f=>this.fetchBrand(f,h)))).filter(f=>f!==null)}catch{return[]}}async fetchBrand(e,t){let r=P.WarpCacheKey.Brand(this.config.env,e),a=t?this.cache.get(r):null;if(a)return P.WarpLogger.info(`WarpRegistry (fetchBrand): Brand found in cache: ${e}`),a;let c=W(this.chain,this.config.env,this.config).createNetworkProvider();try{let o=await c.getTransaction(e),p=JSON.parse(o.data.toString());return p.meta={chain:this.chain.name,hash:o.hash,creator:o.sender.toBech32(),createdAt:new Date(o.timestamp*1e3).toISOString()},t&&t.ttl&&this.cache.set(r,p,t.ttl),p}catch{return null}}async loadRegistryConfigs(){let e=u.Address.newFromBech32(b(this.config.env)),t=this.getController(),[r]=await t.query({contract:e,function:"getConfig",arguments:[]}),a=r?ve(r):null;this.registryConfig=a||{unitPrice:BigInt(0),admins:[]}}getFactory(){let e=new u.TransactionsFactoryConfig({chainID:this.chain.chainId}),t=u.AbiRegistry.create(We);return new u.SmartContractTransactionsFactory({config:e,abi:t})}getController(){let e=W(this.chain,this.config.env,this.config),t=u.AbiRegistry.create(We);return e.createSmartContractController(t)}isCurrentUserAdmin(){return!!this.userWallet&&this.registryConfig.admins.includes(this.userWallet)}};var V=require("@multiversx/sdk-core"),L=require("@vleap/warps");var ce=class{constructor(e,t){this.config=e;this.chain=t;this.entry=W(t,e.env,e),this.provider=this.entry.createNetworkProvider(),this.cache=new L.WarpCache(e.cache?.type)}async signTransaction(e){if(!e||typeof e!="object")throw new Error("Invalid transaction object");let t=(0,L.getWarpWalletPrivateKeyFromConfig)(this.config,this.chain.name);if(!t)throw new Error("Wallet not initialized - no private key provided");let a=t.startsWith("-----")?V.UserSecretKey.fromPem(t):V.UserSecretKey.fromString(t),s=new V.Account(a);if(e.nonce===0n){let c=await this.entry.recallAccountNonce(s.address),o=this.cache.get(`nonce:${s.address.toBech32()}`)||0,p=BigInt(Math.max(o,Number(c)));e.nonce=p}return e.signature=await s.signTransaction(e),this.cache.set(`nonce:${s.address.toBech32()}`,Number(s.nonce),L.CacheTtl.OneHour),e}async signMessage(e){let t=(0,L.getWarpWalletPrivateKeyFromConfig)(this.config,this.chain.name);if(!t)throw new Error("Wallet not initialized - no private key provided");let a=t.startsWith("-----")?V.UserSecretKey.fromPem(t):V.UserSecretKey.fromString(t),s=new V.UserSigner(a),c=new TextEncoder().encode(e),o=await s.sign(c);return Buffer.from(o).toString("hex")}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)}create(e){let r=V.Mnemonic.fromString(e).deriveKey(0),a=r.hex();return{address:r.generatePublicKey().toAddress(this.chain.addressHrp).toBech32(),privateKey:a,mnemonic:e}}generate(){let e=V.Mnemonic.generate(),t=e.toString(),r=e.deriveKey(0),a=r.hex();return{address:r.generatePublicKey().toAddress(this.chain.addressHrp).toBech32(),privateKey:a,mnemonic:t}}getAddress(){return(0,L.getWarpWalletAddressFromConfig)(this.config,this.chain.name)}};var pe=(i,e,t)=>(r,a)=>{let s=t[r.env];return{chain:i,chainInfo:s,prefix:e,builder:()=>new re(r,s),executor:new ae(r,s),results:new q(r,s),serializer:new O,registry:new oe(r,s),explorer:new se(i,r),abiBuilder:()=>new M(r,s),brandBuilder:()=>new te(r,s),dataLoader:new ne(r,s),wallet:new ce(r,s),registerTypes:c=>{c.registerType("token",{stringToNative:o=>o,nativeToString:o=>`token:${o}`}),c.registerType("codemeta",{stringToNative:o=>o,nativeToString:o=>`codemeta:${o}`})}}};var de={chain:J.WarpChainName.Multiversx,identifier:"EGLD",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://vleap.ai/images/tokens/egld.svg"},Te=pe(J.WarpChainName.Multiversx,"multiversx",{mainnet:{name:J.WarpChainName.Multiversx,displayName:"MultiversX",chainId:"1",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://api.multiversx.com",logoUrl:"https://vleap.ai/images/chains/multiversx.svg",nativeToken:de},testnet:{name:J.WarpChainName.Multiversx,displayName:"MultiversX Testnet",chainId:"T",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://testnet-api.multiversx.com",logoUrl:"https://vleap.ai/images/chains/multiversx.svg",nativeToken:de},devnet:{name:J.WarpChainName.Multiversx,displayName:"MultiversX Devnet",chainId:"D",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://devnet-api.multiversx.com",logoUrl:"https://vleap.ai/images/chains/multiversx.svg",nativeToken:de}});var he=require("@vleap/warps");var He={chain:he.WarpChainName.Vibechain,identifier:"VIBE",name:"VIBE",symbol:"VIBE",decimals:18,logoUrl:"https://vleap.ai/images/tokens/vibe.svg"},xe={name:he.WarpChainName.Vibechain,displayName:"VibeChain",chainId:"V",blockTime:600,addressHrp:"vibe",defaultApiUrl:"https://vibeox-api.multiversx.com",logoUrl:"https://vleap.ai/images/chains/vibechain.svg",nativeToken:He},Ae=pe(he.WarpChainName.Vibechain,"vibe",{mainnet:xe,testnet:xe,devnet:xe});var Ze=(i,e)=>[Te(i,e),Ae(i,e)],et=()=>[Ee.WarpChainName.Multiversx,Ee.WarpChainName.Vibechain];var le=require("@vleap/warps");var tt=i=>new le.WarpSerializer().nativeToString(v.Token,i),rt=i=>new le.WarpSerializer().nativeToString(v.CodeMeta,i),nt=(i,e)=>new le.WarpSerializer().nativeToString(v.Optional,i),at=i=>new le.WarpSerializer().nativeToString(v.List,i);var l=require("@multiversx/sdk-core"),st=(i,e)=>i?l.OptionValue.newProvided(i):e?l.OptionValue.newMissingTyped(e):l.OptionValue.newMissing(),it=(i,e)=>i?new l.OptionalValue(i.getType(),i):e?new l.OptionalValue(e):l.OptionalValue.newMissing(),ot=i=>{if(i.length===0)throw new Error("Cannot create a list from an empty array");let e=i[0].getType();return new l.List(e,i)},ct=i=>l.VariadicValue.fromItems(...i),pt=i=>{let e=i.map(t=>t.getType());return new l.CompositeValue(new l.CompositeType(...e),i)},lt=i=>l.StringValue.fromUTF8(i),ut=i=>new l.U8Value(i),mt=i=>new l.U16Value(i),dt=i=>new l.U32Value(i),ht=i=>new l.U64Value(i),ft=i=>new l.BigUIntValue(BigInt(i)),gt=i=>new l.BooleanValue(i),yt=i=>new l.AddressValue(l.Address.newFromBech32(i)),wt=i=>new l.TokenIdentifierValue(i),Ct=i=>l.BytesValue.fromHex(i),Wt=i=>new l.Struct(new l.StructType("EsdtTokenPayment",[new l.FieldDefinition("token_identifier","",new l.TokenIdentifierType),new l.FieldDefinition("token_nonce","",new l.U64Type),new l.FieldDefinition("amount","",new l.BigUIntType)]),[new l.Field(new l.TokenIdentifierValue(i.token.identifier),"token_identifier"),new l.Field(new l.U64Value(BigInt(i.token.nonce)),"token_nonce"),new l.Field(new l.BigUIntValue(BigInt(i.amount)),"amount")]),vt=i=>new l.CodeMetadataValue(l.CodeMetadata.newFromBytes(Uint8Array.from(Buffer.from(i,"hex")))),Tt=()=>new l.NothingValue;0&&(module.exports={ExplorerUrls,KnownTokens,MultiversxExplorers,MultiversxExplorersConfig,NativeTokenEgld,NativeTokenVibe,VibechainExplorers,WarpMultiversxAbiBuilder,WarpMultiversxBrandBuilder,WarpMultiversxBuilder,WarpMultiversxConstants,WarpMultiversxContractLoader,WarpMultiversxDataLoader,WarpMultiversxExecutor,WarpMultiversxExplorer,WarpMultiversxInputTypes,WarpMultiversxRegistry,WarpMultiversxResults,WarpMultiversxSerializer,WarpMultiversxWallet,address_value,asset_value,biguint_value,boolean_value,codemeta,codemeta_value,composite_value,createMultiversxAdapter,findKnownTokenById,getAllMultiversxAdapters,getAllMultiversxChainNames,getKnownTokensForChain,getMultiversxAdapter,getMultiversxEntrypoint,getMultiversxRegistryAddress,getNormalizedTokenIdentifier,getVibechainAdapter,hex_value,isNativeToken,list,list_value,nothing_value,option,option_value,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 At}from"@vleap/warps";import{WarpChainName as M}from"@vleap/warps";import{AbiRegistry as ne,Address as Pt,TransactionsFactoryConfig as Vt,TransferTransactionsFactory as kt}from"@multiversx/sdk-core";import{getLatestProtocolIdentifier as Ft,getWarpWalletAddressFromConfig as Rt,WarpCache as Mt,WarpCacheKey as Ot,WarpConstants as Re,WarpLogger as Me}from"@vleap/warps";import{DevnetEntrypoint as Bt,MainnetEntrypoint as St,TestnetEntrypoint as Ut}from"@multiversx/sdk-core";import{getProviderUrl as Nt}from"@vleap/warps";var V=s=>!s.includes("-"),L=s=>V(s)?`${s}-000000`:s,g=(s,e,t)=>{let r="warp-sdk",a=t?Nt(t,s.name,e,s.defaultApiUrl):s.defaultApiUrl;return e==="devnet"?new Bt({url:a,kind:"api",clientName:r}):e==="testnet"?new Ut({url:a,kind:"api",clientName:r}):new St({url:a,kind:"api",clientName:r})};import{WarpLogger as Fe}from"@vleap/warps";var D=class{constructor(e){this.config=e}async getContract(e,t){try{let a=await g(t,this.config.env,this.config).createNetworkProvider().doGetGeneric(`accounts/${e}`);return{address:e,owner:a.ownerAddress,verified:a.isVerified||!1}}catch(r){return Fe.error("WarpContractLoader: getContract error",r),null}}async getVerificationInfo(e,t){try{let a=await g(t,this.config.env,this.config).createNetworkProvider().doGetGeneric(`accounts/${e}/verification`);return{codeHash:a.codeHash,abi:a.source.abi}}catch(r){return Fe.error("WarpContractLoader: getVerificationInfo error",r),null}}};var U=class{constructor(e,t){this.config=e;this.chain=t;this.contractLoader=new D(this.config),this.cache=new Mt(this.config.cache?.type)}async createInscriptionTransaction(e){let t=Rt(this.config,this.chain.name);if(!t)throw new Error("WarpBuilder: user address not set");let r=new Vt({chainID:this.chain.chainId}),n=new kt({config:r}),a=Pt.newFromBech32(t),o={protocol:Ft("abi"),content:e},i=JSON.stringify(o),c=await n.createTransactionForTransfer(a,{receiver:a,nativeAmount:BigInt(0),data:Uint8Array.from(Buffer.from(i))});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,hash:e.hash,creator:e.sender.toBech32(),createdAt:new Date(e.timestamp*1e3).toISOString()},t}async createFromTransactionHash(e,t){let r=Ot.WarpAbi(this.config.env,e);if(t){let o=this.cache.get(r);if(o)return Me.info(`WarpAbiBuilder (createFromTransactionHash): Warp abi found in cache: ${e}`),o}let a=g(this.chain,this.config.env,this.config).createNetworkProvider();try{let o=await a.getTransaction(e),i=await this.createFromTransaction(o);return t&&t.ttl&&i&&this.cache.set(r,i,t.ttl),i}catch(o){return Me.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 ne.create(t.abi)}async fetchAbi(e){if(!e.abi)throw new Error("WarpActionExecutor: ABI not found");if(e.abi.startsWith(Re.IdentifierType.Hash)){let t=e.abi.split(Re.ArgParamsSeparator)[1],r=await this.createFromTransactionHash(t);if(!r)throw new Error(`WarpActionExecutor: ABI not found for hash: ${e.abi}`);return ne.create(r.content)}else{let r=await(await fetch(e.abi)).json();return ne.create(r)}}};import{Address as Oe,TransactionsFactoryConfig as Lt,TransferTransactionsFactory as Dt}from"@multiversx/sdk-core";import{getWarpWalletAddressFromConfig as _t,WarpBrandBuilder as Ht,WarpLogger as Gt}from"@vleap/warps";import{Buffer as Kt}from"buffer";var _=class{constructor(e,t){this.config=e;this.chain=t;this.core=new Ht(e)}async createInscriptionTransaction(e){let t=_t(this.config,this.chain.name);if(!t)throw new Error("BrandBuilder: user address not set");let r=new Lt({chainID:this.chain.chainId}),n=new Dt({config:r}),a=Oe.newFromBech32(t),o=JSON.stringify(e);return await n.createTransactionForNativeTokenTransfer(a,{receiver:Oe.newFromBech32(t),nativeAmount:BigInt(0),data:Uint8Array.from(Kt.from(o))})}async createFromTransaction(e,t=!1){let r=await this.core.createFromRaw(e.data.toString(),t);return r.meta={chain:this.chain.name,hash:e.hash,creator:e.sender.toBech32(),createdAt:new Date(e.timestamp*1e3).toISOString()},r}async createFromTransactionHash(e){let r=g(this.chain,this.config.env,this.config).createNetworkProvider();try{let n=await r.getTransaction(e);return this.createFromTransaction(n)}catch(n){return Gt.error("BrandBuilder: Error creating from transaction hash",n),null}}};import{Address as Le,TransactionsFactoryConfig as $t,TransferTransactionsFactory as qt}from"@multiversx/sdk-core";import{getWarpWalletAddressFromConfig as zt,WarpBuilder as De,WarpCache as Qt,WarpCacheKey as jt,WarpLogger as _e}from"@vleap/warps";var H=class extends De{constructor(t,r){super(t);this.config=t;this.chain=r;this.cache=new Qt(t.cache?.type),this.core=new De(t)}async createInscriptionTransaction(t){let r=zt(this.config,this.chain.name);if(!r)throw new Error("WarpBuilder: user address not set");let n=new $t({chainID:this.chain.chainId}),a=new qt({config:n}),o=Le.newFromBech32(r),i=JSON.stringify(t),c=await a.createTransactionForTransfer(o,{receiver:Le.newFromBech32(r),nativeAmount:BigInt(0),data:Uint8Array.from(Buffer.from(i))});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,hash:t.hash,creator:t.sender.toBech32(),createdAt:new Date(t.timestamp*1e3).toISOString()},n}async createFromTransactionHash(t,r){let n=jt.Warp(this.config.env,t);if(r){let i=this.cache.get(n);if(i)return _e.info(`WarpBuilder (createFromTransactionHash): Warp found in cache: ${t}`),i}let o=g(this.chain,this.config.env,this.config).createNetworkProvider();try{let i=await o.getTransaction(t),c=await this.createFromTransaction(i);return r&&r.ttl&&c&&this.cache.set(n,c,r.ttl),c}catch(i){return _e.error("WarpBuilder: Error creating from transaction hash",i),null}}};import{Address as ae,Token as er,TokenComputer as tr}from"@multiversx/sdk-core";import{CacheTtl as rr,WarpCache as nr,WarpCacheKey as ar}from"@vleap/warps";import{WarpChainName as Xt}from"@vleap/warps";var He=Xt.Multiversx,Ge=[{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"}];import{WarpChainName as Jt}from"@vleap/warps";var v=Jt.Multiversx,Ke=[{chain:v,identifier:"EGLD",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"},{chain:v,identifier:"EGLD-000000",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"},{chain:v,identifier:"SEGLD-3ad2d0",name:"StakedEGLD",symbol:"SEGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/SEGLD-3ad2d0/icon.png"},{chain:v,identifier:"HSEGLD-c13a4e",name:"HatomSEGLD",symbol:"HSEGLD",decimals:8,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/HSEGLD-c13a4e/icon.png"},{chain:v,identifier:"UTK-2f80e9",name:"xMoney UTK",symbol:"UTK",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/UTK-2f80e9/icon.png"},{chain:v,identifier:"USDC-c76f1f",name:"WrappedUSDC",symbol:"USDC",decimals:6,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/USDC-c76f1f/icon.png"},{chain:v,identifier:"WEGLD-bd4d79",name:"WrappedEGLD",symbol:"WEGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/WEGLD-bd4d79/icon.png"},{chain:v,identifier:"HTM-f51d55",name:"Hatom",symbol:"HTM",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/HTM-f51d55/icon.png"},{chain:v,identifier:"MEX-455c57",name:"MEX",symbol:"MEX",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/MEX-455c57/icon.png"},{chain:v,identifier:"WTAO-4f5363",name:"WrappedTAO",symbol:"WTAO",decimals:9,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/WTAO-4f5363/icon.png"},{chain:v,identifier:"HEGLD-d61095",name:"HatomEGLD",symbol:"HEGLD",decimals:8,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/HEGLD-d61095/icon.png"},{chain:v,identifier:"WBTC-5349b3",name:"WrappedBTC",symbol:"WBTC",decimals:8,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/WBTC-5349b3/icon.png"},{chain:v,identifier:"WETH-b4ca29",name:"WrappedETH",symbol:"WETH",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/WETH-b4ca29/icon.png"},{chain:v,identifier:"USH-111e09",name:"HatomUSD",symbol:"USH",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/USH-111e09/icon.png"},{chain:v,identifier:"USDT-f8c08c",name:"WrappedUSDT",symbol:"USDT",decimals:6,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/USDT-f8c08c/icon.png"}];import{WarpChainName as Yt}from"@vleap/warps";var $e=Yt.Multiversx,qe=[{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"}];import{WarpChainName as Zt}from"@vleap/warps";var ze=Zt.Vibechain,G=[{chain:ze,identifier:"VIBE",name:"VIBE",symbol:"VIBE",decimals:18,logoUrl:"https://vleap.ai/images/tokens/vibe.svg"},{chain:ze,identifier:"VIBE-000000",name:"VIBE",symbol:"VIBE",decimals:18,logoUrl:"https://vleap.ai/images/tokens/vibe.svg"}];var Qe={multiversx:{mainnet:Ke,testnet:qe,devnet:Ge},vibechain:{mainnet:G,testnet:G,devnet:G}},je=(s,e,t)=>(Qe[s]?.[e]||[]).find(n=>n.identifier===t)||null,Aa=(s,e)=>Qe[s]?.[e]||[];var K=class{constructor(e,t){this.config=e;this.chain=t;this.cache=new nr(e.cache?.type)}async getAccount(e){let r=await g(this.chain,this.config.env,this.config).createNetworkProvider().getAccount(ae.newFromBech32(e));return{chain:this.chain.name,address:r.address.toBech32(),balance:r.balance}}async getAccountAssets(e){let t=g(this.chain,this.config.env,this.config).createNetworkProvider(),r=t.getAccount(ae.newFromBech32(e)),n=t.getFungibleTokensOfAccount(ae.newFromBech32(e)),[a,o]=await Promise.all([r,n]),i=a.balance>0?[{...this.chain.nativeToken,amount:a.balance}]:[];return i.push(...o.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}))),i}async getAsset(e){let t=ar.Asset(this.config.env,this.chain.name,e),r=this.cache.get(t);if(r)return r;let n=je(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 tr,o=V(e)?0n:a.extractNonceFromExtendedIdentifier(e),i=new er({identifier:e,nonce:BigInt(o||0)}),c=a.isFungible(i),u=g(this.chain,this.config.env,this.config).createNetworkProvider(),d=L(e),m=await u.doGetGeneric(`tokens/${d}`),C={chain:this.chain.name,identifier:i.identifier,name:m.name,symbol:m.ticker,amount:0n,decimals:m.decimals,logoUrl:m.assets?.pngUrl||"#",price:m.price?Number(m.price):void 0,supply:m.supply?BigInt(m.supply):void 0};return this.cache.set(t,C,rr.OneHour),C}async getAction(e,t=!1){let r=g(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=g(this.chain,this.config.env,this.config).createNetworkProvider(),n=`accounts/${e}/transactions`,a=new URLSearchParams,o=t?.size||25,i=t?.page||0;if(i>0){let u=i*o;a.append("from",u.toString())}return o!==25&&a.append("size",o.toString()),a.toString()&&(n+=`?${a.toString()}`),(await r.doGetGeneric(n)).map(u=>({chain:this.chain.name,id:u.txHash,receiver:u.receiver,sender:u.sender,value:u.value,function:u.function,status:this.toActionStatus(u),createdAt:this.toActionCreatedAt(u)}))}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 R,ArgSerializer as vr,SmartContractTransactionsFactory as Cr,Token as Tr,TokenComputer as xr,TokenTransfer as Ar,TransactionsFactoryConfig as yt,TransferTransactionsFactory as Er,UserSecretKey as br,UserSigner as Ir}from"@multiversx/sdk-core";import{applyResultsToMessages as Br,getNextInfo as Sr,getWarpActionByIndex as Te,getWarpWalletAddressFromConfig as xe}from"@vleap/warps";import{findEventsByFirstTopic as mr,SmartContractTransactionsOutcomeParser as dr,TransactionEventsParser as hr}from"@multiversx/sdk-core";import{applyResultsToMessages as fr,evaluateResultsCommon as Q,findWarpExecutableAction as ht,getNextInfo as gr,getWarpWalletAddressFromConfig as yr,parseResultsOutIndex as ft,WarpCache as wr,WarpCacheKey as Wr,WarpConstants as gt}from"@vleap/warps";import{Address as or,AddressType as se,AddressValue as Je,BigUIntType as $,BigUIntValue as ie,BooleanType as oe,BooleanValue as Ye,BytesType as ce,BytesValue as Ze,CodeMetadata as cr,CodeMetadataType as pe,CodeMetadataValue as et,CompositeType as le,CompositeValue as tt,Field as ue,FieldDefinition as me,List as rt,ListType as nt,NothingValue as b,OptionalType as at,OptionalValue as de,OptionType as st,OptionValue as he,StringType as fe,StringValue as it,Struct as pr,StructType as ot,Token as lr,TokenComputer as ct,TokenIdentifierType as q,TokenIdentifierValue as ge,U16Type as ye,U16Value as pt,U32Type as we,U32Value as lt,U64Type as z,U64Value as We,U8Type as ve,U8Value as ut,VariadicType as Ce,VariadicValue as mt}from"@multiversx/sdk-core";import{WarpSerializer as ur}from"@vleap/warps";var l={HttpProtocolPrefix:"http",IdentifierParamName:"warp",IdentifierParamSeparator:":",IdentifierChainDefault:"multiversx",IdentifierType:{Alias:"alias",Hash:"hash"},Globals:{UserWallet:{Placeholder:"USER_WALLET",Accessor:s=>s.config.user?.wallets?.[s.chain]},ChainApiUrl:{Placeholder:"CHAIN_API",Accessor:s=>s.chainInfo.defaultApiUrl},ChainAddressHrp:{Placeholder:"CHAIN_ADDRESS_HRP",Accessor:s=>s.chainInfo.addressHrp}},Vars:{Query:"query",Env:"env"},ArgParamsSeparator:":",ArgCompositeSeparator:"|",ArgListSeparator:",",Transform:{Prefix:"transform:"},Source:{UserWallet:"user:wallet"},Position:{Payload:"payload:"}},p={Option:"option",Vector:"vector",Tuple:"tuple",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 _a={Egld:{Identifier:"EGLD",EsdtIdentifier:"EGLD-000000",DisplayName:"eGold",Decimals:18}},y={Null:"null",Optional:"optional",List:"list",Token:"token",CodeMeta:"codemeta"},sr=(r=>(r.MultiversxExplorer="multiversx_explorer",r.MultiversxExplorerDevnet="multiversx_explorer_devnet",r.MultiversxExplorerTestnet="multiversx_explorer_testnet",r))(sr||{}),ir=(r=>(r.VibechainExplorer="vibechain_explorer",r.VibechainExplorerDevnet="vibechain_explorer_devnet",r.VibechainExplorerTestnet="vibechain_explorer_testnet",r))(ir||{}),Xe={multiversx:{mainnet:["multiversx_explorer"],testnet:["multiversx_explorer_testnet"],devnet:["multiversx_explorer_devnet"]},vibechain:{mainnet:["vibechain_explorer"],testnet:["vibechain_explorer_testnet"],devnet:["vibechain_explorer_devnet"]}},P={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(`${l.ArgParamsSeparator}(.*)`),N=class{constructor(){this.coreSerializer=new ur}typedToString(e){let t=e.getType();if(t.hasExactClass(st.ClassName)||e.hasClassOrSuperclass(he.ClassName)){if(!e.isSet())return p.Option+l.ArgParamsSeparator+"null";let r=this.typedToString(e.getTypedValue());return p.Option+l.ArgParamsSeparator+r}if(t.hasExactClass(Ce.ClassName)||e.hasClassOrSuperclass(mt.ClassName)){let r=e.getItems(),a=r.map(i=>this.typedToString(i).split(l.ArgParamsSeparator)[0])[0],o=r.map(i=>this.typedToString(i).split(l.ArgParamsSeparator)[1]);return p.Vector+l.ArgParamsSeparator+a+l.ArgParamsSeparator+o.join(l.ArgListSeparator)}if(t.hasExactClass(at.ClassName)||e.hasClassOrSuperclass(de.ClassName)){if(!e.isSet())return y.Optional+l.ArgParamsSeparator+"null";let r=this.typedToString(e.getTypedValue());return y.Optional+l.ArgParamsSeparator+r}if(t.hasExactClass(nt.ClassName)||e.hasClassOrSuperclass(rt.ClassName)){let r=e.getItems(),a=r.map(i=>this.typedToString(i).split(l.ArgParamsSeparator)[0])[0],o=r.map(i=>this.typedToString(i).split(l.ArgParamsSeparator)[1]);return y.List+l.ArgParamsSeparator+a+l.ArgParamsSeparator+o.join(l.ArgListSeparator)}if(t.hasExactClass(le.ClassName)||e.hasClassOrSuperclass(tt.ClassName)){let r=e.getItems(),n=r.map(c=>this.typedToString(c).split(l.ArgParamsSeparator)[0]),a=r.map(c=>this.typedToString(c).split(l.ArgParamsSeparator)[1]),o=n.join(l.ArgCompositeSeparator),i=a.join(l.ArgCompositeSeparator);return`${p.Tuple}(${o})${l.ArgParamsSeparator}${i}`}if(t.hasExactClass($.ClassName)||e.hasClassOrSuperclass(ie.ClassName)||t.getName()==="BigUint")return p.Biguint+l.ArgParamsSeparator+BigInt(e.valueOf().toFixed());if(t.hasExactClass(ve.ClassName)||e.hasClassOrSuperclass(ut.ClassName))return p.Uint8+l.ArgParamsSeparator+e.valueOf().toNumber();if(t.hasExactClass(ye.ClassName)||e.hasClassOrSuperclass(pt.ClassName))return p.Uint16+l.ArgParamsSeparator+e.valueOf().toNumber();if(t.hasExactClass(we.ClassName)||e.hasClassOrSuperclass(lt.ClassName))return p.Uint32+l.ArgParamsSeparator+e.valueOf().toNumber();if(t.hasExactClass(z.ClassName)||e.hasClassOrSuperclass(We.ClassName))return p.Uint64+l.ArgParamsSeparator+BigInt(e.valueOf().toFixed());if(t.hasExactClass(fe.ClassName)||e.hasClassOrSuperclass(it.ClassName))return p.String+l.ArgParamsSeparator+e.valueOf();if(t.hasExactClass(oe.ClassName)||e.hasClassOrSuperclass(Ye.ClassName))return p.Bool+l.ArgParamsSeparator+e.valueOf();if(t.hasExactClass(se.ClassName)||e.hasClassOrSuperclass(Je.ClassName))return p.Address+l.ArgParamsSeparator+e.valueOf().toBech32();if(t.hasExactClass(ce.ClassName)||e.hasClassOrSuperclass(Ze.ClassName))return p.Hex+l.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(),i=new ct().computeExtendedIdentifier(new lr({identifier:r,nonce:BigInt(n)}));return p.Asset+l.ArgParamsSeparator+i+l.ArgCompositeSeparator+a}if(t.hasExactClass(q.ClassName)||e.hasClassOrSuperclass(ge.ClassName))return y.Token+l.ArgParamsSeparator+e.valueOf();if(t.hasExactClass(pe.ClassName)||e.hasClassOrSuperclass(et.ClassName))return y.CodeMeta+l.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){let r=this.coreSerializer.nativeToString(e,t);return this.stringToTyped(r)}nativeToType(e){if(e.startsWith(p.Tuple)){let t=e.match(/\(([^)]+)\)/)?.[1];return new le(...t.split(l.ArgCompositeSeparator).map(r=>this.nativeToType(r)))}if(e===p.String)return new fe;if(e===p.Uint8)return new ve;if(e===p.Uint16)return new ye;if(e===p.Uint32)return new we;if(e===p.Uint64)return new z;if(e===p.Biguint)return new $;if(e===p.Bool)return new oe;if(e===p.Address)return new se;if(e===p.Hex)return new ce;if(e===p.Asset)return new ot("EsdtTokenPayment",[new me("token_identifier","",new q),new me("token_nonce","",new z),new me("amount","",new $)]);if(e===y.Token)return new q;if(e===y.CodeMeta)return new pe;throw new Error(`WarpArgSerializer (nativeToType): Unsupported input type: ${e}`)}stringToTyped(e){let[t,r]=e.split(/:(.*)/,2);if(t===p.Option){let n=this.stringToTyped(r);return n instanceof b?he.newMissingTyped(n.getType()):he.newProvided(n)}if(t===p.Vector){let[n,a]=r.split(dt,2),i=a.split(l.ArgListSeparator).map(c=>this.stringToTyped(`${n}:${c}`));return new mt(new Ce(this.nativeToType(n)),i)}if(t.startsWith(p.Tuple)){let n=t.match(/\(([^)]+)\)/)?.[1],a=r.split(l.ArgCompositeSeparator),o=n.split(l.ArgCompositeSeparator),i=a.map((u,d)=>this.stringToTyped(o[d]+l.ArgParamsSeparator+u)),c=i.map(u=>u.getType());return new tt(new le(...c),i)}if(t===p.String)return r?it.fromUTF8(r):new b;if(t===p.Uint8)return r?new ut(Number(r)):new b;if(t===p.Uint16)return r?new pt(Number(r)):new b;if(t===p.Uint32)return r?new lt(Number(r)):new b;if(t===p.Uint64)return r?new We(BigInt(r)):new b;if(t===p.Biguint)return r?new ie(BigInt(r)):new b;if(t===p.Bool)return r?new Ye(typeof r=="boolean"?r:r==="true"):new b;if(t===p.Address)return r?new Je(or.newFromBech32(r)):new b;if(t===p.Hex)return r?Ze.fromHex(r):new b;if(t===p.Asset){let[n,a]=r.split(l.ArgCompositeSeparator),o=new ct,i=V(n)?L(n):o.extractIdentifierFromExtendedIdentifier(n),c=V(n)?0n:o.extractNonceFromExtendedIdentifier(n);return new pr(this.nativeToType("asset"),[new ue(new ge(i),"token_identifier"),new ue(new We(BigInt(c)),"token_nonce"),new ue(new ie(BigInt(a)),"amount")])}if(t===y.Null)return new b;if(t===y.Optional){let n=this.stringToTyped(r);return n instanceof b?de.newMissing():new de(n.getType(),n)}if(t===y.List){let[n,a]=r.split(dt,2),i=a.split(l.ArgListSeparator).map(c=>this.stringToTyped(n+l.ArgParamsSeparator+c));return new rt(this.nativeToType(n),i)}if(t===y.Token)return r?new ge(r):new b;if(t===y.CodeMeta)return new et(cr.newFromBytes(Uint8Array.from(Buffer.from(r,"hex"))));throw new Error(`WarpArgSerializer (stringToTyped): Unsupported input type: ${t}`)}typeToString(e){if(e.hasExactClass(st.ClassName))return p.Option+l.ArgParamsSeparator+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(Ce.ClassName))return p.Vector+l.ArgParamsSeparator+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(fe.ClassName))return p.String;if(e.hasExactClass(ve.ClassName))return p.Uint8;if(e.hasExactClass(ye.ClassName))return p.Uint16;if(e.hasExactClass(we.ClassName))return p.Uint32;if(e.hasExactClass(z.ClassName))return p.Uint64;if(e.hasExactClass($.ClassName))return p.Biguint;if(e.hasExactClass(oe.ClassName))return p.Bool;if(e.hasExactClass(se.ClassName))return p.Address;if(e.hasExactClass(ce.ClassName))return p.Hex;if(e.hasExactClass(q.ClassName))return y.Token;if(e.hasExactClass(at.ClassName))return y.Optional+l.ArgParamsSeparator+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(nt.ClassName))return y.List+l.ArgParamsSeparator+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(pe.ClassName))return y.CodeMeta;if(e.hasExactClass(ot.ClassName)&&e.getClassName()==="EsdtTokenPayment")return p.Asset;throw new Error(`WarpArgSerializer (typeToString): Unsupported input type: ${e.getClassName()}`)}};var k=class{constructor(e,t){this.config=e;this.chain=t;this.abi=new U(e,t),this.serializer=new N,this.cache=new wr(e.cache?.type)}async getTransactionExecutionResults(e,t){let{actionIndex:r}=ht(e),n=this.cache.get(Wr.WarpExecutable(this.config.env,e.meta?.hash||"",r))??[],a=await this.extractContractResults(e,t,n),o=gr(this.config,[],e,r,a),i=fr(e,a.results);return{success:t.status.isSuccessful(),warp:e,action:r,user:yr(this.config,this.chain.name),txHash:t.hash,tx:t,next:o,values:a.values,valuesRaw:[],results:a.results,messages:i}}async extractContractResults(e,t,r){let{action:n,actionIndex:a}=ht(e),o=[],i={};if(!e.results||n.type!=="contract")return{values:o,results:i};if(!Object.values(e.results).some(x=>x.includes("out")||x.includes("event"))){for(let[x,h]of Object.entries(e.results))i[x]=h;return{values:o,results:await Q(e,i,a,r,this.config.transform?.runner)}}let u=await this.abi.getAbiForAction(n),d=new hr({abi:u}),C=new dr({abi:u}).parseExecute({transactionOnNetwork:t,function:n.func||void 0});for(let[x,h]of Object.entries(e.results)){if(h.startsWith(gt.Transform.Prefix))continue;if(h.startsWith("input.")){i[x]=h;continue}let I=ft(h);if(I!==null&&I!==a){i[x]=null;continue}let[A,E,S]=h.split(".");if(A==="event"){if(!E||isNaN(Number(S)))continue;let B=Number(S),W=mr(t,E),F=d.parseEvents({events:W})[0],O=Object.values(F)[B]||null;o.push(O),i[x]=O&&O.valueOf()}else if(A==="out"||A.startsWith("out[")){if(!E)continue;let B=Number(E),W=C.values[B-1]||null;S&&(W=W[S]||null),W&&typeof W=="object"&&(W="toFixed"in W?W.toFixed():W.valueOf()),o.push(W),i[x]=W&&W.valueOf()}else i[x]=h}return{values:o,results:await Q(e,i,a,r)}}async extractQueryResults(e,t,r,n){let a=t.map(u=>this.serializer.typedToString(u)),o=t.map(u=>this.serializer.typedToNative(u)[1]),i={};if(!e.results)return{values:a,valuesRaw:o,results:i};let c=u=>{let d=u.split(".").slice(1).map(C=>parseInt(C)-1);if(d.length===0)return;let m=o[d[0]];for(let C=1;C<d.length;C++){if(m==null)return;m=m[d[C]]}return m};for(let[u,d]of Object.entries(e.results)){if(d.startsWith(gt.Transform.Prefix))continue;let m=ft(d);if(m!==null&&m!==r){i[u]=null;continue}d.startsWith("out.")||d==="out"||d.startsWith("out[")?i[u]=c(d)||null:i[u]=d}return{values:a,valuesRaw:o,results:await Q(e,i,r,n)}}async resolveWarpResultsRecursively(e){let t=e.warp,r=e.entryActionIndex,n=e.executor,a=e.inputs,o=e.meta,i=new Map,c=new Set,u=this;async function d(h,I=[]){if(i.has(h))return i.get(h);if(c.has(h))throw new Error(`Circular dependency detected at action ${h}`);c.add(h);let A=t.actions[h-1];if(!A)throw new Error(`Action ${h} not found`);let E;if(A.type==="query")E=await n.executeQuery(t,h,I);else if(A.type==="collect")E=await n.executeCollect(t,h,I,o);else throw new Error(`Unsupported or interactive action type: ${A.type}`);if(i.set(h,E),t.results)for(let S of Object.values(t.results)){let W=String(S).match(/^out\[(\d+)\]/);if(W){let F=parseInt(W[1],10);F!==h&&!i.has(F)&&await d(F)}}return c.delete(h),E}await d(r,a);let m={};for(let h of i.values())for(let[I,A]of Object.entries(h.results))A!==null?m[I]=A:I in m||(m[I]=null);let C=await Q(t,m,r,a,this.config.transform?.runner);return{...i.get(r),action:r,results:C}}};var Ur="EGLD-000000",j=class{constructor(e,t){this.config=e;this.chain=t;this.serializer=new N,this.abi=new U(this.config,this.chain),this.results=new k(this.config,this.chain)}async createTransaction(e){let t=Te(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){let t=xe(this.config,e.chain.name);if(!t)throw new Error("WarpMultiversxExecutor: createTransfer - user address not set");let r=R.newFromBech32(t),n=new yt({chainID:e.chain.chainId}),a=e.data?Buffer.from(this.serializer.stringToTyped(e.data).valueOf()):null,o=e.transfers.length===1&&e.transfers[0].identifier===this.chain.nativeToken?.identifier,c=(o?e.transfers[0].amount:0n)+e.value;return await new Er({config:n}).createTransactionForTransfer(r,{receiver:R.newFromBech32(e.destination),nativeAmount:c,tokenTransfers:o?[]:this.toTokenTransfers(e.transfers),data:a?new Uint8Array(a):void 0})}async createContractCallTransaction(e){let t=xe(this.config,e.chain.name);if(!t)throw new Error("WarpMultiversxExecutor: createContractCall - user address not set");let r=Te(e.warp,e.action),n=R.newFromBech32(t),a=e.args.map(i=>this.serializer.stringToTyped(i)),o=new yt({chainID:e.chain.chainId});return new Cr({config:o}).createTransactionForExecute(n,{contract:R.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){let t=Te(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(B=>this.serializer.stringToTyped(B)),a=g(e.chain,this.config.env,this.config),o=R.newFromBech32(e.destination),i=a.createSmartContractController(r),c=i.createQuery({contract:o,function:t.func||"",arguments:n}),u=await i.runQuery(c),d=u.returnCode==="ok",m=new vr,C=r.getEndpoint(u.function||t.func||""),x=(u.returnDataParts||[]).map(B=>Buffer.from(B)),h=m.buffersToValues(x,C.output),{values:I,valuesRaw:A,results:E}=await this.results.extractQueryResults(e.warp,h,e.action,e.resolvedInputs),S=Sr(this.config,[],e.warp,e.action,E);return{success:d,warp:e.warp,action:e.action,user:xe(this.config,e.chain.name),txHash:null,tx:null,next:S,values:I,valuesRaw:A,results:E,messages:Br(e.warp,E)}}async signMessage(e,t){let r=br.fromString(t);return(await new Ir(r).sign(new Uint8Array(Buffer.from(e,"utf-8")))).toString()}toTokenTransfers(e){return e.map(t=>t.identifier===this.chain.nativeToken.identifier?{...t,identifier:Ur}:t).map(t=>{let n=new xr().extractNonceFromExtendedIdentifier(t.identifier);return new Ar({token:new Tr({identifier:t.identifier,nonce:BigInt(n||0)}),amount:t.amount})})}};var X=class{constructor(e,t){this.chain=e;this.config=t}getExplorers(){let e=Xe[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=P[t];if(a)return a}if(e){let a=P[e];if(a)return a}let r=this.getPrimaryExplorer();return P[r]||P[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=P[n];a&&(r[n]=`${a}/accounts/${e}`)}),r}getTransactionUrls(e){let t=this.getAllExplorers(),r={};return t.forEach(n=>{let a=P[n];a&&(r[n]=`${a}/transactions/${e}`)}),r}};import{AbiRegistry as Wt,Address as f,AddressValue as Ee,BytesValue as w,SmartContractTransactionsFactory as Pr,TransactionsFactoryConfig as Vr}from"@multiversx/sdk-core";import{getWarpWalletAddressFromConfig as kr,WarpCache as Fr,WarpCacheKey as be,WarpLogger as Ie}from"@vleap/warps";var Ae={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 T=s=>{if(s==="devnet")return"erd1qqqqqqqqqqqqqpgqje2f99vr6r7sk54thg03c9suzcvwr4nfl3tsfkdl36";if(s==="testnet")throw new Error("Multiversx testnet is not supported");return"erd1qqqqqqqqqqqqqpgq3mrpj3u6q7tejv6d7eqhnyd27n9v5c5tl3ts08mffe"};var J=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}),wt=s=>({unitPrice:BigInt(s.unit_price.toString()),admins:s.admins.map(e=>e.toBech32())});var Y=class{constructor(e,t){this.config=e;this.chain=t;this.cache=new Fr(e.cache?.type),this.registryConfig={unitPrice:BigInt(0),admins:[]},this.userWallet=kr(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=f.newFromBech32(this.userWallet),a=()=>this.isCurrentUserAdmin()?BigInt(0):t&&r?this.registryConfig.unitPrice*BigInt(3):t?this.registryConfig.unitPrice*BigInt(2):this.registryConfig.unitPrice,o=()=>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:f.newFromBech32(T(this.config.env)),function:"registerWarp",gasLimit:BigInt(1e7),nativeTransferAmount:a(),arguments:o()})}async createWarpUnregisterTransaction(e){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let t=f.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(t,{contract:f.newFromBech32(T(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=f.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(n,{contract:f.newFromBech32(T(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=f.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(r,{contract:f.newFromBech32(T(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=f.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(t,{contract:f.newFromBech32(T(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=f.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(r,{contract:f.newFromBech32(T(this.config.env)),function:"transferOwnership",gasLimit:BigInt(1e7),arguments:[w.fromHex(e),new Ee(new f(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=f.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(t,{contract:f.newFromBech32(T(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=f.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(r,{contract:f.newFromBech32(T(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=be.RegistryInfo(this.config.env,e),n=t?this.cache.get(r):null;if(n)return Ie.info(`WarpRegistry (getInfoByAlias): RegistryInfo found in cache: ${e}`),n;let a=f.newFromBech32(T(this.config.env)),o=this.getController(),i=o.createQuery({contract:a,function:"getInfoByAlias",arguments:[w.fromUTF8(e)]}),c=await o.runQuery(i),[u]=o.parseQueryResponse(c),d=u?J(u):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 getInfoByHash(e,t){try{let r=be.RegistryInfo(this.config.env,e);if(t){let m=this.cache.get(r);if(m)return Ie.info(`WarpRegistry (getInfoByHash): RegistryInfo found in cache: ${e}`),m}let n=f.newFromBech32(T(this.config.env)),a=this.getController(),o=a.createQuery({contract:n,function:"getInfoByHash",arguments:[w.fromHex(e)]}),i=await a.runQuery(o),[c]=a.parseQueryResponse(i),u=c?J(c):null,d=u?.brand?await this.fetchBrand(u.brand):null;return t&&t.ttl&&this.cache.set(r,{registryInfo:u,brand:d},t.ttl),{registryInfo:u,brand:d}}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=f.newFromBech32(T(this.config.env)),n=this.getController(),a=n.createQuery({contract:r,function:"getUserWarps",arguments:[new Ee(new f(t))]}),o=await n.runQuery(a),[i]=n.parseQueryResponse(o);return i.map(J)}catch{return[]}}async getUserBrands(e){try{let t=e||this.userWallet;if(!t)throw new Error("WarpRegistry: user address not set");let r=f.newFromBech32(T(this.config.env)),n=this.getController(),a=n.createQuery({contract:r,function:"getUserBrands",arguments:[new Ee(new f(t))]}),o=await n.runQuery(a),[i]=n.parseQueryResponse(o),c=i.map(m=>m.toString("hex")),u={ttl:365*24*60*60};return(await Promise.all(c.map(m=>this.fetchBrand(m,u)))).filter(m=>m!==null)}catch{return[]}}async fetchBrand(e,t){let r=be.Brand(this.config.env,e),n=t?this.cache.get(r):null;if(n)return Ie.info(`WarpRegistry (fetchBrand): Brand found in cache: ${e}`),n;let o=g(this.chain,this.config.env,this.config).createNetworkProvider();try{let i=await o.getTransaction(e),c=JSON.parse(i.data.toString());return c.meta={chain:this.chain.name,hash:i.hash,creator:i.sender.toBech32(),createdAt:new Date(i.timestamp*1e3).toISOString()},t&&t.ttl&&this.cache.set(r,c,t.ttl),c}catch{return null}}async loadRegistryConfigs(){let e=f.newFromBech32(T(this.config.env)),t=this.getController(),[r]=await t.query({contract:e,function:"getConfig",arguments:[]}),n=r?wt(r):null;this.registryConfig=n||{unitPrice:BigInt(0),admins:[]}}getFactory(){let e=new Vr({chainID:this.chain.chainId}),t=Wt.create(Ae);return new Pr({config:e,abi:t})}getController(){let e=g(this.chain,this.config.env,this.config),t=Wt.create(Ae);return e.createSmartContractController(t)}isCurrentUserAdmin(){return!!this.userWallet&&this.registryConfig.admins.includes(this.userWallet)}};import{Account as Rr,Mnemonic as vt,UserSecretKey as Z,UserSigner as Mr}from"@multiversx/sdk-core";import{CacheTtl as Or,getWarpWalletAddressFromConfig as Lr,getWarpWalletPrivateKeyFromConfig as Ct,WarpCache as Dr}from"@vleap/warps";var ee=class{constructor(e,t){this.config=e;this.chain=t;this.entry=g(t,e.env,e),this.provider=this.entry.createNetworkProvider(),this.cache=new Dr(e.cache?.type)}async signTransaction(e){if(!e||typeof e!="object")throw new Error("Invalid transaction object");let t=Ct(this.config,this.chain.name);if(!t)throw new Error("Wallet not initialized - no private key provided");let n=t.startsWith("-----")?Z.fromPem(t):Z.fromString(t),a=new Rr(n);if(e.nonce===0n){let o=await this.entry.recallAccountNonce(a.address),i=this.cache.get(`nonce:${a.address.toBech32()}`)||0,c=BigInt(Math.max(i,Number(o)));e.nonce=c}return e.signature=await a.signTransaction(e),this.cache.set(`nonce:${a.address.toBech32()}`,Number(a.nonce),Or.OneHour),e}async signMessage(e){let t=Ct(this.config,this.chain.name);if(!t)throw new Error("Wallet not initialized - no private key provided");let n=t.startsWith("-----")?Z.fromPem(t):Z.fromString(t),a=new Mr(n),o=new TextEncoder().encode(e),i=await a.sign(o);return Buffer.from(i).toString("hex")}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)}create(e){let r=vt.fromString(e).deriveKey(0),n=r.hex();return{address:r.generatePublicKey().toAddress(this.chain.addressHrp).toBech32(),privateKey:n,mnemonic:e}}generate(){let e=vt.generate(),t=e.toString(),r=e.deriveKey(0),n=r.hex();return{address:r.generatePublicKey().toAddress(this.chain.addressHrp).toBech32(),privateKey:n,mnemonic:t}}getAddress(){return Lr(this.config,this.chain.name)}};var te=(s,e,t)=>(r,n)=>{let a=t[r.env];return{chain:s,chainInfo:a,prefix:e,builder:()=>new H(r,a),executor:new j(r,a),results:new k(r,a),serializer:new N,registry:new Y(r,a),explorer:new X(s,r),abiBuilder:()=>new U(r,a),brandBuilder:()=>new _(r,a),dataLoader:new K(r,a),wallet:new ee(r,a),registerTypes:o=>{o.registerType("token",{stringToNative:i=>i,nativeToString:i=>`token:${i}`}),o.registerType("codemeta",{stringToNative:i=>i,nativeToString:i=>`codemeta:${i}`})}}};var Be={chain:M.Multiversx,identifier:"EGLD",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://vleap.ai/images/tokens/egld.svg"},Tt=te(M.Multiversx,"multiversx",{mainnet:{name:M.Multiversx,displayName:"MultiversX",chainId:"1",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://api.multiversx.com",logoUrl:"https://vleap.ai/images/chains/multiversx.svg",nativeToken:Be},testnet:{name:M.Multiversx,displayName:"MultiversX Testnet",chainId:"T",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://testnet-api.multiversx.com",logoUrl:"https://vleap.ai/images/chains/multiversx.svg",nativeToken:Be},devnet:{name:M.Multiversx,displayName:"MultiversX Devnet",chainId:"D",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://devnet-api.multiversx.com",logoUrl:"https://vleap.ai/images/chains/multiversx.svg",nativeToken:Be}});import{WarpChainName as Ue}from"@vleap/warps";var _r={chain:Ue.Vibechain,identifier:"VIBE",name:"VIBE",symbol:"VIBE",decimals:18,logoUrl:"https://vleap.ai/images/tokens/vibe.svg"},Se={name:Ue.Vibechain,displayName:"VibeChain",chainId:"V",blockTime:600,addressHrp:"vibe",defaultApiUrl:"https://vibeox-api.multiversx.com",logoUrl:"https://vleap.ai/images/chains/vibechain.svg",nativeToken:_r},xt=te(Ue.Vibechain,"vibe",{mainnet:Se,testnet:Se,devnet:Se});var Mi=(s,e)=>[Tt(s,e),xt(s,e)],Oi=()=>[At.Multiversx,At.Vibechain];import{WarpSerializer as re}from"@vleap/warps";var Yi=s=>new re().nativeToString(y.Token,s),Zi=s=>new re().nativeToString(y.CodeMeta,s),eo=(s,e)=>new re().nativeToString(y.Optional,s),to=s=>new re().nativeToString(y.List,s);import{Address as Hr,AddressValue as Gr,BigUIntType as Kr,BigUIntValue as Et,BooleanValue as $r,BytesValue as qr,CodeMetadata as zr,CodeMetadataValue as Qr,CompositeType as jr,CompositeValue as Xr,Field as Ne,FieldDefinition as Pe,List as Jr,NothingValue as Yr,OptionalValue as Ve,OptionValue as ke,StringValue as Zr,Struct as en,StructType as tn,TokenIdentifierType as rn,TokenIdentifierValue as bt,U16Value as nn,U32Value as an,U64Type as sn,U64Value as It,U8Value as on,VariadicValue as cn}from"@multiversx/sdk-core";var oo=(s,e)=>s?ke.newProvided(s):e?ke.newMissingTyped(e):ke.newMissing(),co=(s,e)=>s?new Ve(s.getType(),s):e?new Ve(e):Ve.newMissing(),po=s=>{if(s.length===0)throw new Error("Cannot create a list from an empty array");let e=s[0].getType();return new Jr(e,s)},lo=s=>cn.fromItems(...s),uo=s=>{let e=s.map(t=>t.getType());return new Xr(new jr(...e),s)},mo=s=>Zr.fromUTF8(s),ho=s=>new on(s),fo=s=>new nn(s),go=s=>new an(s),yo=s=>new It(s),wo=s=>new Et(BigInt(s)),Wo=s=>new $r(s),vo=s=>new Gr(Hr.newFromBech32(s)),Co=s=>new bt(s),To=s=>qr.fromHex(s),xo=s=>new en(new tn("EsdtTokenPayment",[new Pe("token_identifier","",new rn),new Pe("token_nonce","",new sn),new Pe("amount","",new Kr)]),[new Ne(new bt(s.token.identifier),"token_identifier"),new Ne(new It(BigInt(s.token.nonce)),"token_nonce"),new Ne(new Et(BigInt(s.amount)),"amount")]),Ao=s=>new Qr(zr.newFromBytes(Uint8Array.from(Buffer.from(s,"hex")))),Eo=()=>new Yr;export{P as ExplorerUrls,Qe as KnownTokens,sr as MultiversxExplorers,Xe as MultiversxExplorersConfig,Be as NativeTokenEgld,_r as NativeTokenVibe,ir as VibechainExplorers,U as WarpMultiversxAbiBuilder,_ as WarpMultiversxBrandBuilder,H as WarpMultiversxBuilder,_a as WarpMultiversxConstants,D as WarpMultiversxContractLoader,K as WarpMultiversxDataLoader,j as WarpMultiversxExecutor,X as WarpMultiversxExplorer,y as WarpMultiversxInputTypes,Y as WarpMultiversxRegistry,k as WarpMultiversxResults,N as WarpMultiversxSerializer,ee as WarpMultiversxWallet,vo as address_value,xo as asset_value,wo as biguint_value,Wo as boolean_value,Zi as codemeta,Ao as codemeta_value,uo as composite_value,te as createMultiversxAdapter,je as findKnownTokenById,Mi as getAllMultiversxAdapters,Oi as getAllMultiversxChainNames,Aa as getKnownTokensForChain,Tt as getMultiversxAdapter,g as getMultiversxEntrypoint,T as getMultiversxRegistryAddress,L as getNormalizedTokenIdentifier,xt as getVibechainAdapter,To as hex_value,V as isNativeToken,to as list,po as list_value,Eo as nothing_value,eo as option,oo as option_value,co as optional_value,mo as string_value,wt as toTypedConfigInfo,J as toTypedRegistryInfo,Yi as token,Co as token_value,fo as u16_value,go as u32_value,yo as u64_value,ho as u8_value,lo as variadic_value};
|
|
1
|
+
import{WarpChainName as Et}from"@vleap/warps";import{WarpChainName as O}from"@vleap/warps";import{AbiRegistry as oe,Address as Vt,TransactionsFactoryConfig as kt,TransferTransactionsFactory as Ft}from"@multiversx/sdk-core";import{getLatestProtocolIdentifier as Rt,getWarpWalletAddressFromConfig as Mt,WarpCache as Ot,WarpCacheKey as Lt,WarpConstants as Oe,WarpLogger as Le}from"@vleap/warps";import{DevnetEntrypoint as Bt,MainnetEntrypoint as Nt,TestnetEntrypoint as Ut}from"@multiversx/sdk-core";import{getProviderUrl as Pt}from"@vleap/warps";var k=i=>!i.includes("-"),D=i=>k(i)?`${i}-000000`:i,g=(i,e,t)=>{let r="warp-sdk",a=t?Pt(t,i.name,e,i.defaultApiUrl):i.defaultApiUrl;return e==="devnet"?new Bt({url:a,kind:"api",clientName:r}):e==="testnet"?new Ut({url:a,kind:"api",clientName:r}):new Nt({url:a,kind:"api",clientName:r})};import{WarpLogger as Me}from"@vleap/warps";var _=class{constructor(e){this.config=e}async getContract(e,t){try{let a=await g(t,this.config.env,this.config).createNetworkProvider().doGetGeneric(`accounts/${e}`);return{address:e,owner:a.ownerAddress,verified:a.isVerified||!1}}catch(r){return Me.error("WarpContractLoader: getContract error",r),null}}async getVerificationInfo(e,t){try{let a=await g(t,this.config.env,this.config).createNetworkProvider().doGetGeneric(`accounts/${e}/verification`);return{codeHash:a.codeHash,abi:a.source.abi}}catch(r){return Me.error("WarpContractLoader: getVerificationInfo error",r),null}}};var N=class{constructor(e,t){this.config=e;this.chain=t;this.contractLoader=new _(this.config),this.cache=new Ot(this.config.cache?.type)}async createInscriptionTransaction(e){let t=Mt(this.config,this.chain.name);if(!t)throw new Error("WarpBuilder: user address not set");let r=new kt({chainID:this.chain.chainId}),n=new Ft({config:r}),a=Vt.newFromBech32(t),o={protocol:Rt("abi"),content:e},s=JSON.stringify(o),c=await n.createTransactionForTransfer(a,{receiver:a,nativeAmount:BigInt(0),data:Uint8Array.from(Buffer.from(s))});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,hash:e.hash,creator:e.sender.toBech32(),createdAt:new Date(e.timestamp*1e3).toISOString()},t}async createFromTransactionHash(e,t){let r=Lt.WarpAbi(this.config.env,e);if(t){let o=this.cache.get(r);if(o)return Le.info(`WarpAbiBuilder (createFromTransactionHash): Warp abi found in cache: ${e}`),o}let a=g(this.chain,this.config.env,this.config).createNetworkProvider();try{let o=await a.getTransaction(e),s=await this.createFromTransaction(o);return t&&t.ttl&&s&&this.cache.set(r,s,t.ttl),s}catch(o){return Le.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 oe.create(t.abi)}async fetchAbi(e){if(!e.abi)throw new Error("WarpActionExecutor: ABI not found");if(e.abi.startsWith(Oe.IdentifierType.Hash)){let t=e.abi.split(Oe.ArgParamsSeparator)[1],r=await this.createFromTransactionHash(t);if(!r)throw new Error(`WarpActionExecutor: ABI not found for hash: ${e.abi}`);return oe.create(r.content)}else{let r=await(await fetch(e.abi)).json();return oe.create(r)}}};import{Address as De,TransactionsFactoryConfig as Dt,TransferTransactionsFactory as _t}from"@multiversx/sdk-core";import{getWarpWalletAddressFromConfig as Ht,WarpBrandBuilder as Gt,WarpLogger as $t}from"@vleap/warps";import{Buffer as Kt}from"buffer";var H=class{constructor(e,t){this.config=e;this.chain=t;this.core=new Gt(e)}async createInscriptionTransaction(e){let t=Ht(this.config,this.chain.name);if(!t)throw new Error("BrandBuilder: user address not set");let r=new Dt({chainID:this.chain.chainId}),n=new _t({config:r}),a=De.newFromBech32(t),o=JSON.stringify(e);return await n.createTransactionForNativeTokenTransfer(a,{receiver:De.newFromBech32(t),nativeAmount:BigInt(0),data:Uint8Array.from(Kt.from(o))})}async createFromTransaction(e,t=!1){let r=await this.core.createFromRaw(e.data.toString(),t);return r.meta={chain:this.chain.name,hash:e.hash,creator:e.sender.toBech32(),createdAt:new Date(e.timestamp*1e3).toISOString()},r}async createFromTransactionHash(e){let r=g(this.chain,this.config.env,this.config).createNetworkProvider();try{let n=await r.getTransaction(e);return this.createFromTransaction(n)}catch(n){return $t.error("BrandBuilder: Error creating from transaction hash",n),null}}};import{Address as _e,TransactionsFactoryConfig as qt,TransferTransactionsFactory as zt}from"@multiversx/sdk-core";import{getWarpWalletAddressFromConfig as Qt,WarpBuilder as He,WarpCache as jt,WarpCacheKey as Xt,WarpLogger as Ge}from"@vleap/warps";var G=class extends He{constructor(t,r){super(t);this.config=t;this.chain=r;this.cache=new jt(t.cache?.type),this.core=new He(t)}async createInscriptionTransaction(t){let r=Qt(this.config,this.chain.name);if(!r)throw new Error("WarpBuilder: user address not set");let n=new qt({chainID:this.chain.chainId}),a=new zt({config:n}),o=_e.newFromBech32(r),s=JSON.stringify(t),c=await a.createTransactionForTransfer(o,{receiver:_e.newFromBech32(r),nativeAmount:BigInt(0),data:Uint8Array.from(Buffer.from(s))});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,hash:t.hash,creator:t.sender.toBech32(),createdAt:new Date(t.timestamp*1e3).toISOString()},n}async createFromTransactionHash(t,r){let n=Xt.Warp(this.config.env,t);if(r){let s=this.cache.get(n);if(s)return Ge.info(`WarpBuilder (createFromTransactionHash): Warp found in cache: ${t}`),s}let o=g(this.chain,this.config.env,this.config).createNetworkProvider();try{let s=await o.getTransaction(t),c=await this.createFromTransaction(s);return r&&r.ttl&&c&&this.cache.set(n,c,r.ttl),c}catch(s){return Ge.error("WarpBuilder: Error creating from transaction hash",s),null}}};import{Address as ce,Token as tr,TokenComputer as rr}from"@multiversx/sdk-core";import{CacheTtl as nr,WarpCache as ar,WarpCacheKey as sr}from"@vleap/warps";import{WarpChainName as Jt}from"@vleap/warps";var $e=Jt.Multiversx,Ke=[{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"}];import{WarpChainName as Yt}from"@vleap/warps";var T=Yt.Multiversx,qe=[{chain:T,identifier:"EGLD",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"},{chain:T,identifier:"EGLD-000000",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"},{chain:T,identifier:"SEGLD-3ad2d0",name:"StakedEGLD",symbol:"SEGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/SEGLD-3ad2d0/icon.png"},{chain:T,identifier:"HSEGLD-c13a4e",name:"HatomSEGLD",symbol:"HSEGLD",decimals:8,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/HSEGLD-c13a4e/icon.png"},{chain:T,identifier:"UTK-2f80e9",name:"xMoney UTK",symbol:"UTK",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/UTK-2f80e9/icon.png"},{chain:T,identifier:"USDC-c76f1f",name:"WrappedUSDC",symbol:"USDC",decimals:6,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/USDC-c76f1f/icon.png"},{chain:T,identifier:"WEGLD-bd4d79",name:"WrappedEGLD",symbol:"WEGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/WEGLD-bd4d79/icon.png"},{chain:T,identifier:"HTM-f51d55",name:"Hatom",symbol:"HTM",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/HTM-f51d55/icon.png"},{chain:T,identifier:"MEX-455c57",name:"MEX",symbol:"MEX",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/MEX-455c57/icon.png"},{chain:T,identifier:"WTAO-4f5363",name:"WrappedTAO",symbol:"WTAO",decimals:9,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/WTAO-4f5363/icon.png"},{chain:T,identifier:"HEGLD-d61095",name:"HatomEGLD",symbol:"HEGLD",decimals:8,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/HEGLD-d61095/icon.png"},{chain:T,identifier:"WBTC-5349b3",name:"WrappedBTC",symbol:"WBTC",decimals:8,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/WBTC-5349b3/icon.png"},{chain:T,identifier:"WETH-b4ca29",name:"WrappedETH",symbol:"WETH",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/WETH-b4ca29/icon.png"},{chain:T,identifier:"USH-111e09",name:"HatomUSD",symbol:"USH",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/USH-111e09/icon.png"},{chain:T,identifier:"USDT-f8c08c",name:"WrappedUSDT",symbol:"USDT",decimals:6,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/USDT-f8c08c/icon.png"}];import{WarpChainName as Zt}from"@vleap/warps";var ze=Zt.Multiversx,Qe=[{chain:ze,identifier:"EGLD",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"},{chain:ze,identifier:"EGLD-000000",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"}];import{WarpChainName as er}from"@vleap/warps";var je=er.Vibechain,$=[{chain:je,identifier:"VIBE",name:"VIBE",symbol:"VIBE",decimals:18,logoUrl:"https://vleap.ai/images/tokens/vibe.svg"},{chain:je,identifier:"VIBE-000000",name:"VIBE",symbol:"VIBE",decimals:18,logoUrl:"https://vleap.ai/images/tokens/vibe.svg"}];var Xe={multiversx:{mainnet:qe,testnet:Qe,devnet:Ke},vibechain:{mainnet:$,testnet:$,devnet:$}},Je=(i,e,t)=>(Xe[i]?.[e]||[]).find(n=>n.identifier===t)||null,Aa=(i,e)=>Xe[i]?.[e]||[];var K=class{constructor(e,t){this.config=e;this.chain=t;this.cache=new ar(e.cache?.type)}async getAccount(e){let r=await g(this.chain,this.config.env,this.config).createNetworkProvider().getAccount(ce.newFromBech32(e));return{chain:this.chain.name,address:r.address.toBech32(),balance:r.balance}}async getAccountAssets(e){let t=g(this.chain,this.config.env,this.config).createNetworkProvider(),r=t.getAccount(ce.newFromBech32(e)),n=t.getFungibleTokensOfAccount(ce.newFromBech32(e)),[a,o]=await Promise.all([r,n]),s=a.balance>0?[{...this.chain.nativeToken,amount:a.balance}]:[];return s.push(...o.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}))),s}async getAsset(e){let t=sr.Asset(this.config.env,this.chain.name,e),r=this.cache.get(t);if(r)return r;let n=Je(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 rr,o=k(e)?0n:a.extractNonceFromExtendedIdentifier(e),s=new tr({identifier:e,nonce:BigInt(o||0)}),c=a.isFungible(s),u=g(this.chain,this.config.env,this.config).createNetworkProvider(),d=D(e),m=await u.doGetGeneric(`tokens/${d}`),C={chain:this.chain.name,identifier:s.identifier,name:m.name,symbol:m.ticker,amount:0n,decimals:m.decimals,logoUrl:m.assets?.pngUrl||"#",price:m.price?Number(m.price):void 0,supply:m.supply?BigInt(m.supply):void 0};return this.cache.set(t,C,nr.OneHour),C}async getAction(e,t=!1){let r=g(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=g(this.chain,this.config.env,this.config).createNetworkProvider(),n=`accounts/${e}/transactions`,a=new URLSearchParams,o=t?.size||25,s=t?.page||0;if(s>0){let u=s*o;a.append("from",u.toString())}return o!==25&&a.append("size",o.toString()),a.toString()&&(n+=`?${a.toString()}`),(await r.doGetGeneric(n)).map(u=>({chain:this.chain.name,id:u.txHash,receiver:u.receiver,sender:u.sender,value:u.value,function:u.function,status:this.toActionStatus(u),createdAt:this.toActionCreatedAt(u)}))}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 M,ArgSerializer as Wr,SmartContractTransactionsFactory as vr,Token as Tr,TokenComputer as xr,TokenTransfer as Ar,TransactionsFactoryConfig as wt,TransferTransactionsFactory as Er,UserSecretKey as br,UserSigner as Sr}from"@multiversx/sdk-core";import{applyResultsToMessages as Ir,getNextInfo as Br,getWarpActionByIndex as Ae,getWarpWalletAddressFromConfig as Ee}from"@vleap/warps";import{findEventsByFirstTopic as mr,SmartContractTransactionsOutcomeParser as dr,TransactionEventsParser as hr}from"@multiversx/sdk-core";import{applyResultsToMessages as fr,evaluateResultsCommon as Y,findWarpExecutableAction as ft,getNextInfo as gr,getWarpWalletAddressFromConfig as yr,parseResultsOutIndex as gt,WarpCache as wr,WarpCacheKey as Cr,WarpConstants as yt}from"@vleap/warps";import{Address as cr,AddressType as pe,AddressValue as Ze,BigUIntType as q,BigUIntValue as le,BooleanType as ue,BooleanValue as et,BytesType as me,BytesValue as tt,CodeMetadata as pr,CodeMetadataType as de,CodeMetadataValue as rt,CompositeType as he,CompositeValue as nt,Field as z,FieldDefinition as Q,List as at,ListType as st,NothingValue as b,OptionalType as it,OptionalValue as fe,OptionType as ot,OptionValue as ge,StringType as ye,StringValue as ct,Struct as j,StructType as V,Token as lr,TokenComputer as pt,TokenIdentifierType as X,TokenIdentifierValue as we,U16Type as Ce,U16Value as lt,U32Type as We,U32Value as ut,U64Type as J,U64Value as ve,U8Type as Te,U8Value as mt,VariadicType as xe,VariadicValue as dt}from"@multiversx/sdk-core";import{WarpSerializer as ur}from"@vleap/warps";var l={HttpProtocolPrefix:"http",IdentifierParamName:"warp",IdentifierParamSeparator:":",IdentifierChainDefault:"multiversx",IdentifierType:{Alias:"alias",Hash:"hash"},Globals:{UserWallet:{Placeholder:"USER_WALLET",Accessor:i=>i.config.user?.wallets?.[i.chain]},ChainApiUrl:{Placeholder:"CHAIN_API",Accessor:i=>i.chainInfo.defaultApiUrl},ChainAddressHrp:{Placeholder:"CHAIN_ADDRESS_HRP",Accessor:i=>i.chainInfo.addressHrp}},Vars:{Query:"query",Env:"env"},ArgParamsSeparator:":",ArgCompositeSeparator:"|",ArgListSeparator:",",Transform:{Prefix:"transform:"},Source:{UserWallet:"user:wallet"},Position:{Payload:"payload:"}},p={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 _a={Egld:{Identifier:"EGLD",EsdtIdentifier:"EGLD-000000",DisplayName:"eGold",Decimals:18}},y={Null:"null",Optional:"optional",List:"list",Token:"token",CodeMeta:"codemeta"},ir=(r=>(r.MultiversxExplorer="multiversx_explorer",r.MultiversxExplorerDevnet="multiversx_explorer_devnet",r.MultiversxExplorerTestnet="multiversx_explorer_testnet",r))(ir||{}),or=(r=>(r.VibechainExplorer="vibechain_explorer",r.VibechainExplorerDevnet="vibechain_explorer_devnet",r.VibechainExplorerTestnet="vibechain_explorer_testnet",r))(or||{}),Ye={multiversx:{mainnet:["multiversx_explorer"],testnet:["multiversx_explorer_testnet"],devnet:["multiversx_explorer_devnet"]},vibechain:{mainnet:["vibechain_explorer"],testnet:["vibechain_explorer_testnet"],devnet:["vibechain_explorer_devnet"]}},P={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 ht=new RegExp(`${l.ArgParamsSeparator}(.*)`),U=class{constructor(){this.coreSerializer=new ur}typedToString(e){let t=e.getType();if(t.hasExactClass(ot.ClassName)||e.hasClassOrSuperclass(ge.ClassName)){if(!e.isSet())return p.Option+l.ArgParamsSeparator+"null";let r=this.typedToString(e.getTypedValue());return p.Option+l.ArgParamsSeparator+r}if(t.hasExactClass(xe.ClassName)||e.hasClassOrSuperclass(dt.ClassName)){let r=e.getItems(),a=r.map(s=>this.typedToString(s).split(l.ArgParamsSeparator)[0])[0],o=r.map(s=>this.typedToString(s).split(l.ArgParamsSeparator)[1]);return p.Vector+l.ArgParamsSeparator+a+l.ArgParamsSeparator+o.join(l.ArgListSeparator)}if(t.hasExactClass(it.ClassName)||e.hasClassOrSuperclass(fe.ClassName)){if(!e.isSet())return y.Optional+l.ArgParamsSeparator+"null";let r=this.typedToString(e.getTypedValue());return y.Optional+l.ArgParamsSeparator+r}if(t.hasExactClass(st.ClassName)||e.hasClassOrSuperclass(at.ClassName)){let r=e.getItems(),a=r.map(s=>this.typedToString(s).split(l.ArgParamsSeparator)[0])[0],o=r.map(s=>this.typedToString(s).split(l.ArgParamsSeparator)[1]);return y.List+l.ArgParamsSeparator+a+l.ArgParamsSeparator+o.join(l.ArgListSeparator)}if(t.hasExactClass(he.ClassName)||e.hasClassOrSuperclass(nt.ClassName)){let r=e.getItems(),n=r.map(c=>this.typedToString(c).split(l.ArgParamsSeparator)[0]),a=r.map(c=>this.typedToString(c).split(l.ArgParamsSeparator)[1]),o=n.join(l.ArgCompositeSeparator),s=a.join(l.ArgCompositeSeparator);return`${p.Tuple}(${o})${l.ArgParamsSeparator}${s}`}if(t.hasExactClass(q.ClassName)||e.hasClassOrSuperclass(le.ClassName)||t.getName()==="BigUint")return p.Biguint+l.ArgParamsSeparator+BigInt(e.valueOf().toFixed());if(t.hasExactClass(Te.ClassName)||e.hasClassOrSuperclass(mt.ClassName))return p.Uint8+l.ArgParamsSeparator+e.valueOf().toNumber();if(t.hasExactClass(Ce.ClassName)||e.hasClassOrSuperclass(lt.ClassName))return p.Uint16+l.ArgParamsSeparator+e.valueOf().toNumber();if(t.hasExactClass(We.ClassName)||e.hasClassOrSuperclass(ut.ClassName))return p.Uint32+l.ArgParamsSeparator+e.valueOf().toNumber();if(t.hasExactClass(J.ClassName)||e.hasClassOrSuperclass(ve.ClassName))return p.Uint64+l.ArgParamsSeparator+BigInt(e.valueOf().toFixed());if(t.hasExactClass(ye.ClassName)||e.hasClassOrSuperclass(ct.ClassName))return p.String+l.ArgParamsSeparator+e.valueOf();if(t.hasExactClass(ue.ClassName)||e.hasClassOrSuperclass(et.ClassName))return p.Bool+l.ArgParamsSeparator+e.valueOf();if(t.hasExactClass(pe.ClassName)||e.hasClassOrSuperclass(Ze.ClassName))return p.Address+l.ArgParamsSeparator+e.valueOf().toBech32();if(t.hasExactClass(me.ClassName)||e.hasClassOrSuperclass(tt.ClassName))return p.Hex+l.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(),s=new pt().computeExtendedIdentifier(new lr({identifier:r,nonce:BigInt(n)}));return p.Asset+l.ArgParamsSeparator+s+l.ArgCompositeSeparator+a}if(t.hasExactClass(V.ClassName)||e.hasClassOrSuperclass(j.ClassName)){let r=e,a=r.getType().getName(),o=r.getFields();if(o.length===0)return`${p.Struct}(${a})${l.ArgParamsSeparator}`;let s=o.map(c=>{let u=c.name,d=c.value,m=d.getType(),C=this.typedToString(d).split(l.ArgParamsSeparator)[1];return`(${u}${l.ArgParamsSeparator}${this.typeToString(m)})${C}`});return`${p.Struct}(${a})${l.ArgParamsSeparator}${s.join(l.ArgListSeparator)}`}if(t.hasExactClass(X.ClassName)||e.hasClassOrSuperclass(we.ClassName))return y.Token+l.ArgParamsSeparator+e.valueOf();if(t.hasExactClass(de.ClassName)||e.hasClassOrSuperclass(rt.ClassName))return y.CodeMeta+l.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){let r=this.coreSerializer.nativeToString(e,t);return this.stringToTyped(r)}nativeToType(e){if(e.startsWith(p.Tuple)){let t=e.match(/\(([^)]+)\)/)?.[1];return new he(...t.split(l.ArgCompositeSeparator).map(r=>this.nativeToType(r)))}if(e.startsWith(p.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 V(r,[])}if(e===p.String)return new ye;if(e===p.Uint8)return new Te;if(e===p.Uint16)return new Ce;if(e===p.Uint32)return new We;if(e===p.Uint64)return new J;if(e===p.Biguint)return new q;if(e===p.Bool)return new ue;if(e===p.Address)return new pe;if(e===p.Hex)return new me;if(e===p.Asset)return new V("EsdtTokenPayment",[new Q("token_identifier","",new X),new Q("token_nonce","",new J),new Q("amount","",new q)]);if(e===y.Token)return new X;if(e===y.CodeMeta)return new de;throw new Error(`WarpArgSerializer (nativeToType): Unsupported input type: ${e}`)}stringToTyped(e){let[t,r]=e.split(/:(.*)/,2);if(t===p.Option){let n=this.stringToTyped(r);return n instanceof b?ge.newMissingTyped(n.getType()):ge.newProvided(n)}if(t===p.Vector){let[n,a]=r.split(ht,2),s=a.split(l.ArgListSeparator).map(c=>this.stringToTyped(`${n}:${c}`));return new dt(new xe(this.nativeToType(n)),s)}if(t.startsWith(p.Tuple)){let n=t.match(/\(([^)]+)\)/)?.[1],a=r.split(l.ArgCompositeSeparator),o=n.split(l.ArgCompositeSeparator),s=a.map((u,d)=>this.stringToTyped(o[d]+l.ArgParamsSeparator+u)),c=s.map(u=>u.getType());return new nt(new he(...c),s)}if(t.startsWith(p.Struct)){let n=t.match(/\(([^)]+)\)/),a=n?n[1]:"CustomStruct";if(!r)return new j(new V(a,[]),[]);let o=r.split(l.ArgListSeparator),s=[],c=[];return o.forEach(u=>{let d=u.match(new RegExp(`^\\(([^${l.ArgParamsSeparator}]+)${l.ArgParamsSeparator}([^)]+)\\)(.+)$`));if(d){let[,m,C,v]=d,h=this.stringToTyped(`${C}${l.ArgParamsSeparator}${v}`);s.push(new Q(m,"",h.getType())),c.push(new z(h,m))}}),new j(new V(a,s),c)}if(t===p.String)return r?ct.fromUTF8(r):new b;if(t===p.Uint8)return r?new mt(Number(r)):new b;if(t===p.Uint16)return r?new lt(Number(r)):new b;if(t===p.Uint32)return r?new ut(Number(r)):new b;if(t===p.Uint64)return r?new ve(BigInt(r)):new b;if(t===p.Biguint)return r?new le(BigInt(r)):new b;if(t===p.Bool)return r?new et(typeof r=="boolean"?r:r==="true"):new b;if(t===p.Address)return r?new Ze(cr.newFromBech32(r)):new b;if(t===p.Hex)return r?tt.fromHex(r):new b;if(t===p.Asset){let[n,a]=r.split(l.ArgCompositeSeparator),o=new pt,s=k(n)?D(n):o.extractIdentifierFromExtendedIdentifier(n),c=k(n)?0n:o.extractNonceFromExtendedIdentifier(n);return new j(this.nativeToType("asset"),[new z(new we(s),"token_identifier"),new z(new ve(BigInt(c)),"token_nonce"),new z(new le(BigInt(a)),"amount")])}if(t===y.Null)return new b;if(t===y.Optional){let n=this.stringToTyped(r);return n instanceof b?fe.newMissing():new fe(n.getType(),n)}if(t===y.List){let[n,a]=r.split(ht,2),s=a.split(l.ArgListSeparator).map(c=>this.stringToTyped(n+l.ArgParamsSeparator+c));return new at(this.nativeToType(n),s)}if(t===y.Token)return r?new we(r):new b;if(t===y.CodeMeta)return new rt(pr.newFromBytes(Uint8Array.from(Buffer.from(r,"hex"))));throw new Error(`WarpArgSerializer (stringToTyped): Unsupported input type: ${t}`)}typeToString(e){if(e.hasExactClass(ot.ClassName))return p.Option+l.ArgParamsSeparator+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(xe.ClassName))return p.Vector+l.ArgParamsSeparator+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(ye.ClassName))return p.String;if(e.hasExactClass(Te.ClassName))return p.Uint8;if(e.hasExactClass(Ce.ClassName))return p.Uint16;if(e.hasExactClass(We.ClassName))return p.Uint32;if(e.hasExactClass(J.ClassName))return p.Uint64;if(e.hasExactClass(q.ClassName))return p.Biguint;if(e.hasExactClass(ue.ClassName))return p.Bool;if(e.hasExactClass(pe.ClassName))return p.Address;if(e.hasExactClass(me.ClassName))return p.Hex;if(e.hasExactClass(X.ClassName))return y.Token;if(e.hasExactClass(it.ClassName))return y.Optional+l.ArgParamsSeparator+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(st.ClassName))return y.List+l.ArgParamsSeparator+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(de.ClassName))return y.CodeMeta;if(e.hasExactClass(V.ClassName)&&e.getClassName()==="EsdtTokenPayment")return p.Asset;if(e.hasExactClass(V.ClassName))return`${p.Struct}(${e.getName()})`;throw new Error(`WarpArgSerializer (typeToString): Unsupported input type: ${e.getClassName()}`)}};var F=class{constructor(e,t){this.config=e;this.chain=t;this.abi=new N(e,t),this.serializer=new U,this.cache=new wr(e.cache?.type)}async getTransactionExecutionResults(e,t){let{actionIndex:r}=ft(e),n=this.cache.get(Cr.WarpExecutable(this.config.env,e.meta?.hash||"",r))??[],a=await this.extractContractResults(e,t,n),o=gr(this.config,[],e,r,a),s=fr(e,a.results);return{success:t.status.isSuccessful(),warp:e,action:r,user:yr(this.config,this.chain.name),txHash:t.hash,tx:t,next:o,values:a.values,valuesRaw:[],results:a.results,messages:s}}async extractContractResults(e,t,r){let{action:n,actionIndex:a}=ft(e),o=[],s={};if(!e.results||n.type!=="contract")return{values:o,results:s};if(!Object.values(e.results).some(v=>v.includes("out")||v.includes("event"))){for(let[v,h]of Object.entries(e.results))s[v]=h;return{values:o,results:await Y(e,s,a,r,this.config.transform?.runner)}}let u=await this.abi.getAbiForAction(n),d=new hr({abi:u}),C=new dr({abi:u}).parseExecute({transactionOnNetwork:t,function:n.func||void 0});for(let[v,h]of Object.entries(e.results)){if(h.startsWith(yt.Transform.Prefix))continue;if(h.startsWith("input.")){s[v]=h;continue}let S=gt(h);if(S!==null&&S!==a){s[v]=null;continue}let[A,E,B]=h.split(".");if(A==="event"){if(!E||isNaN(Number(B)))continue;let I=Number(B),W=mr(t,E),R=d.parseEvents({events:W})[0],L=Object.values(R)[I]||null;o.push(L),s[v]=L&&L.valueOf()}else if(A==="out"||A.startsWith("out[")){if(!E)continue;let I=Number(E),W=C.values[I-1]||null;B&&(W=W[B]||null),W&&typeof W=="object"&&(W="toFixed"in W?W.toFixed():W.valueOf()),o.push(W),s[v]=W&&W.valueOf()}else s[v]=h}return{values:o,results:await Y(e,s,a,r)}}async extractQueryResults(e,t,r,n){let a=t.map(u=>this.serializer.typedToString(u)),o=t.map(u=>this.serializer.typedToNative(u)[1]),s={};if(!e.results)return{values:a,valuesRaw:o,results:s};let c=u=>{let d=u.split(".").slice(1).map(C=>parseInt(C)-1);if(d.length===0)return;let m=o[d[0]];for(let C=1;C<d.length;C++){if(m==null)return;m=m[d[C]]}return m};for(let[u,d]of Object.entries(e.results)){if(d.startsWith(yt.Transform.Prefix))continue;let m=gt(d);if(m!==null&&m!==r){s[u]=null;continue}d.startsWith("out.")||d==="out"||d.startsWith("out[")?s[u]=c(d)||null:s[u]=d}return{values:a,valuesRaw:o,results:await Y(e,s,r,n)}}async resolveWarpResultsRecursively(e){let t=e.warp,r=e.entryActionIndex,n=e.executor,a=e.inputs,o=e.meta,s=new Map,c=new Set,u=this;async function d(h,S=[]){if(s.has(h))return s.get(h);if(c.has(h))throw new Error(`Circular dependency detected at action ${h}`);c.add(h);let A=t.actions[h-1];if(!A)throw new Error(`Action ${h} not found`);let E;if(A.type==="query")E=await n.executeQuery(t,h,S);else if(A.type==="collect")E=await n.executeCollect(t,h,S,o);else throw new Error(`Unsupported or interactive action type: ${A.type}`);if(s.set(h,E),t.results)for(let B of Object.values(t.results)){let W=String(B).match(/^out\[(\d+)\]/);if(W){let R=parseInt(W[1],10);R!==h&&!s.has(R)&&await d(R)}}return c.delete(h),E}await d(r,a);let m={};for(let h of s.values())for(let[S,A]of Object.entries(h.results))A!==null?m[S]=A:S in m||(m[S]=null);let C=await Y(t,m,r,a,this.config.transform?.runner);return{...s.get(r),action:r,results:C}}};var Nr="EGLD-000000",Z=class{constructor(e,t){this.config=e;this.chain=t;this.serializer=new U,this.abi=new N(this.config,this.chain),this.results=new F(this.config,this.chain)}async createTransaction(e){let t=Ae(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){let t=Ee(this.config,e.chain.name);if(!t)throw new Error("WarpMultiversxExecutor: createTransfer - user address not set");let r=M.newFromBech32(t),n=new wt({chainID:e.chain.chainId}),a=e.data?Buffer.from(this.serializer.stringToTyped(e.data).valueOf()):null,o=e.transfers.length===1&&e.transfers[0].identifier===this.chain.nativeToken?.identifier,c=(o?e.transfers[0].amount:0n)+e.value;return await new Er({config:n}).createTransactionForTransfer(r,{receiver:M.newFromBech32(e.destination),nativeAmount:c,tokenTransfers:o?[]:this.toTokenTransfers(e.transfers),data:a?new Uint8Array(a):void 0})}async createContractCallTransaction(e){let t=Ee(this.config,e.chain.name);if(!t)throw new Error("WarpMultiversxExecutor: createContractCall - user address not set");let r=Ae(e.warp,e.action),n=M.newFromBech32(t),a=e.args.map(s=>this.serializer.stringToTyped(s)),o=new wt({chainID:e.chain.chainId});return new vr({config:o}).createTransactionForExecute(n,{contract:M.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){let t=Ae(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(I=>this.serializer.stringToTyped(I)),a=g(e.chain,this.config.env,this.config),o=M.newFromBech32(e.destination),s=a.createSmartContractController(r),c=s.createQuery({contract:o,function:t.func||"",arguments:n}),u=await s.runQuery(c),d=u.returnCode==="ok",m=new Wr,C=r.getEndpoint(u.function||t.func||""),v=(u.returnDataParts||[]).map(I=>Buffer.from(I)),h=m.buffersToValues(v,C.output),{values:S,valuesRaw:A,results:E}=await this.results.extractQueryResults(e.warp,h,e.action,e.resolvedInputs),B=Br(this.config,[],e.warp,e.action,E);return{success:d,warp:e.warp,action:e.action,user:Ee(this.config,e.chain.name),txHash:null,tx:null,next:B,values:S,valuesRaw:A,results:E,messages:Ir(e.warp,E)}}async signMessage(e,t){let r=br.fromString(t);return(await new Sr(r).sign(new Uint8Array(Buffer.from(e,"utf-8")))).toString()}toTokenTransfers(e){return e.map(t=>t.identifier===this.chain.nativeToken.identifier?{...t,identifier:Nr}:t).map(t=>{let n=new xr().extractNonceFromExtendedIdentifier(t.identifier);return new Ar({token:new Tr({identifier:t.identifier,nonce:BigInt(n||0)}),amount:t.amount})})}};var ee=class{constructor(e,t){this.chain=e;this.config=t}getExplorers(){let e=Ye[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=P[t];if(a)return a}if(e){let a=P[e];if(a)return a}let r=this.getPrimaryExplorer();return P[r]||P[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=P[n];a&&(r[n]=`${a}/accounts/${e}`)}),r}getTransactionUrls(e){let t=this.getAllExplorers(),r={};return t.forEach(n=>{let a=P[n];a&&(r[n]=`${a}/transactions/${e}`)}),r}};import{AbiRegistry as Wt,Address as f,AddressValue as Se,BytesValue as w,SmartContractTransactionsFactory as Pr,TransactionsFactoryConfig as Vr}from"@multiversx/sdk-core";import{getWarpWalletAddressFromConfig as kr,WarpCache as Fr,WarpCacheKey as Ie,WarpLogger as Be}from"@vleap/warps";var be={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 x=i=>{if(i==="devnet")return"erd1qqqqqqqqqqqqqpgqje2f99vr6r7sk54thg03c9suzcvwr4nfl3tsfkdl36";if(i==="testnet")throw new Error("Multiversx testnet is not supported");return"erd1qqqqqqqqqqqqqpgq3mrpj3u6q7tejv6d7eqhnyd27n9v5c5tl3ts08mffe"};var te=i=>({hash:i.hash.toString("hex"),alias:i.alias?.toString()||null,trust:i.trust.toString(),owner:i.owner.toString(),createdAt:i.created_at.toNumber(),upgradedAt:i.upgraded_at?.toNumber(),brand:i.brand?.toString("hex")||null,upgrade:i.upgrade?.toString("hex")||null}),Ct=i=>({unitPrice:BigInt(i.unit_price.toString()),admins:i.admins.map(e=>e.toBech32())});var re=class{constructor(e,t){this.config=e;this.chain=t;this.cache=new Fr(e.cache?.type),this.registryConfig={unitPrice:BigInt(0),admins:[]},this.userWallet=kr(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=f.newFromBech32(this.userWallet),a=()=>this.isCurrentUserAdmin()?BigInt(0):t&&r?this.registryConfig.unitPrice*BigInt(3):t?this.registryConfig.unitPrice*BigInt(2):this.registryConfig.unitPrice,o=()=>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:f.newFromBech32(x(this.config.env)),function:"registerWarp",gasLimit:BigInt(1e7),nativeTransferAmount:a(),arguments:o()})}async createWarpUnregisterTransaction(e){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let t=f.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(t,{contract:f.newFromBech32(x(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=f.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(n,{contract:f.newFromBech32(x(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=f.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(r,{contract:f.newFromBech32(x(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=f.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(t,{contract:f.newFromBech32(x(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=f.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(r,{contract:f.newFromBech32(x(this.config.env)),function:"transferOwnership",gasLimit:BigInt(1e7),arguments:[w.fromHex(e),new Se(new f(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=f.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(t,{contract:f.newFromBech32(x(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=f.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(r,{contract:f.newFromBech32(x(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=Ie.RegistryInfo(this.config.env,e),n=t?this.cache.get(r):null;if(n)return Be.info(`WarpRegistry (getInfoByAlias): RegistryInfo found in cache: ${e}`),n;let a=f.newFromBech32(x(this.config.env)),o=this.getController(),s=o.createQuery({contract:a,function:"getInfoByAlias",arguments:[w.fromUTF8(e)]}),c=await o.runQuery(s),[u]=o.parseQueryResponse(c),d=u?te(u):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 getInfoByHash(e,t){try{let r=Ie.RegistryInfo(this.config.env,e);if(t){let m=this.cache.get(r);if(m)return Be.info(`WarpRegistry (getInfoByHash): RegistryInfo found in cache: ${e}`),m}let n=f.newFromBech32(x(this.config.env)),a=this.getController(),o=a.createQuery({contract:n,function:"getInfoByHash",arguments:[w.fromHex(e)]}),s=await a.runQuery(o),[c]=a.parseQueryResponse(s),u=c?te(c):null,d=u?.brand?await this.fetchBrand(u.brand):null;return t&&t.ttl&&this.cache.set(r,{registryInfo:u,brand:d},t.ttl),{registryInfo:u,brand:d}}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=f.newFromBech32(x(this.config.env)),n=this.getController(),a=n.createQuery({contract:r,function:"getUserWarps",arguments:[new Se(new f(t))]}),o=await n.runQuery(a),[s]=n.parseQueryResponse(o);return s.map(te)}catch{return[]}}async getUserBrands(e){try{let t=e||this.userWallet;if(!t)throw new Error("WarpRegistry: user address not set");let r=f.newFromBech32(x(this.config.env)),n=this.getController(),a=n.createQuery({contract:r,function:"getUserBrands",arguments:[new Se(new f(t))]}),o=await n.runQuery(a),[s]=n.parseQueryResponse(o),c=s.map(m=>m.toString("hex")),u={ttl:365*24*60*60};return(await Promise.all(c.map(m=>this.fetchBrand(m,u)))).filter(m=>m!==null)}catch{return[]}}async fetchBrand(e,t){let r=Ie.Brand(this.config.env,e),n=t?this.cache.get(r):null;if(n)return Be.info(`WarpRegistry (fetchBrand): Brand found in cache: ${e}`),n;let o=g(this.chain,this.config.env,this.config).createNetworkProvider();try{let s=await o.getTransaction(e),c=JSON.parse(s.data.toString());return c.meta={chain:this.chain.name,hash:s.hash,creator:s.sender.toBech32(),createdAt:new Date(s.timestamp*1e3).toISOString()},t&&t.ttl&&this.cache.set(r,c,t.ttl),c}catch{return null}}async loadRegistryConfigs(){let e=f.newFromBech32(x(this.config.env)),t=this.getController(),[r]=await t.query({contract:e,function:"getConfig",arguments:[]}),n=r?Ct(r):null;this.registryConfig=n||{unitPrice:BigInt(0),admins:[]}}getFactory(){let e=new Vr({chainID:this.chain.chainId}),t=Wt.create(be);return new Pr({config:e,abi:t})}getController(){let e=g(this.chain,this.config.env,this.config),t=Wt.create(be);return e.createSmartContractController(t)}isCurrentUserAdmin(){return!!this.userWallet&&this.registryConfig.admins.includes(this.userWallet)}};import{Account as Rr,Mnemonic as vt,UserSecretKey as ne,UserSigner as Mr}from"@multiversx/sdk-core";import{CacheTtl as Or,getWarpWalletAddressFromConfig as Lr,getWarpWalletPrivateKeyFromConfig as Tt,WarpCache as Dr}from"@vleap/warps";var ae=class{constructor(e,t){this.config=e;this.chain=t;this.entry=g(t,e.env,e),this.provider=this.entry.createNetworkProvider(),this.cache=new Dr(e.cache?.type)}async signTransaction(e){if(!e||typeof e!="object")throw new Error("Invalid transaction object");let t=Tt(this.config,this.chain.name);if(!t)throw new Error("Wallet not initialized - no private key provided");let n=t.startsWith("-----")?ne.fromPem(t):ne.fromString(t),a=new Rr(n);if(e.nonce===0n){let o=await this.entry.recallAccountNonce(a.address),s=this.cache.get(`nonce:${a.address.toBech32()}`)||0,c=BigInt(Math.max(s,Number(o)));e.nonce=c}return e.signature=await a.signTransaction(e),this.cache.set(`nonce:${a.address.toBech32()}`,Number(a.nonce),Or.OneHour),e}async signMessage(e){let t=Tt(this.config,this.chain.name);if(!t)throw new Error("Wallet not initialized - no private key provided");let n=t.startsWith("-----")?ne.fromPem(t):ne.fromString(t),a=new Mr(n),o=new TextEncoder().encode(e),s=await a.sign(o);return Buffer.from(s).toString("hex")}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)}create(e){let r=vt.fromString(e).deriveKey(0),n=r.hex();return{address:r.generatePublicKey().toAddress(this.chain.addressHrp).toBech32(),privateKey:n,mnemonic:e}}generate(){let e=vt.generate(),t=e.toString(),r=e.deriveKey(0),n=r.hex();return{address:r.generatePublicKey().toAddress(this.chain.addressHrp).toBech32(),privateKey:n,mnemonic:t}}getAddress(){return Lr(this.config,this.chain.name)}};var se=(i,e,t)=>(r,n)=>{let a=t[r.env];return{chain:i,chainInfo:a,prefix:e,builder:()=>new G(r,a),executor:new Z(r,a),results:new F(r,a),serializer:new U,registry:new re(r,a),explorer:new ee(i,r),abiBuilder:()=>new N(r,a),brandBuilder:()=>new H(r,a),dataLoader:new K(r,a),wallet:new ae(r,a),registerTypes:o=>{o.registerType("token",{stringToNative:s=>s,nativeToString:s=>`token:${s}`}),o.registerType("codemeta",{stringToNative:s=>s,nativeToString:s=>`codemeta:${s}`})}}};var Ne={chain:O.Multiversx,identifier:"EGLD",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://vleap.ai/images/tokens/egld.svg"},xt=se(O.Multiversx,"multiversx",{mainnet:{name:O.Multiversx,displayName:"MultiversX",chainId:"1",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://api.multiversx.com",logoUrl:"https://vleap.ai/images/chains/multiversx.svg",nativeToken:Ne},testnet:{name:O.Multiversx,displayName:"MultiversX Testnet",chainId:"T",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://testnet-api.multiversx.com",logoUrl:"https://vleap.ai/images/chains/multiversx.svg",nativeToken:Ne},devnet:{name:O.Multiversx,displayName:"MultiversX Devnet",chainId:"D",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://devnet-api.multiversx.com",logoUrl:"https://vleap.ai/images/chains/multiversx.svg",nativeToken:Ne}});import{WarpChainName as Pe}from"@vleap/warps";var _r={chain:Pe.Vibechain,identifier:"VIBE",name:"VIBE",symbol:"VIBE",decimals:18,logoUrl:"https://vleap.ai/images/tokens/vibe.svg"},Ue={name:Pe.Vibechain,displayName:"VibeChain",chainId:"V",blockTime:600,addressHrp:"vibe",defaultApiUrl:"https://vibeox-api.multiversx.com",logoUrl:"https://vleap.ai/images/chains/vibechain.svg",nativeToken:_r},At=se(Pe.Vibechain,"vibe",{mainnet:Ue,testnet:Ue,devnet:Ue});var Mi=(i,e)=>[xt(i,e),At(i,e)],Oi=()=>[Et.Multiversx,Et.Vibechain];import{WarpSerializer as ie}from"@vleap/warps";var Yi=i=>new ie().nativeToString(y.Token,i),Zi=i=>new ie().nativeToString(y.CodeMeta,i),eo=(i,e)=>new ie().nativeToString(y.Optional,i),to=i=>new ie().nativeToString(y.List,i);import{Address as Hr,AddressValue as Gr,BigUIntType as $r,BigUIntValue as bt,BooleanValue as Kr,BytesValue as qr,CodeMetadata as zr,CodeMetadataValue as Qr,CompositeType as jr,CompositeValue as Xr,Field as Ve,FieldDefinition as ke,List as Jr,NothingValue as Yr,OptionalValue as Fe,OptionValue as Re,StringValue as Zr,Struct as en,StructType as tn,TokenIdentifierType as rn,TokenIdentifierValue as St,U16Value as nn,U32Value as an,U64Type as sn,U64Value as It,U8Value as on,VariadicValue as cn}from"@multiversx/sdk-core";var oo=(i,e)=>i?Re.newProvided(i):e?Re.newMissingTyped(e):Re.newMissing(),co=(i,e)=>i?new Fe(i.getType(),i):e?new Fe(e):Fe.newMissing(),po=i=>{if(i.length===0)throw new Error("Cannot create a list from an empty array");let e=i[0].getType();return new Jr(e,i)},lo=i=>cn.fromItems(...i),uo=i=>{let e=i.map(t=>t.getType());return new Xr(new jr(...e),i)},mo=i=>Zr.fromUTF8(i),ho=i=>new on(i),fo=i=>new nn(i),go=i=>new an(i),yo=i=>new It(i),wo=i=>new bt(BigInt(i)),Co=i=>new Kr(i),Wo=i=>new Gr(Hr.newFromBech32(i)),vo=i=>new St(i),To=i=>qr.fromHex(i),xo=i=>new en(new tn("EsdtTokenPayment",[new ke("token_identifier","",new rn),new ke("token_nonce","",new sn),new ke("amount","",new $r)]),[new Ve(new St(i.token.identifier),"token_identifier"),new Ve(new It(BigInt(i.token.nonce)),"token_nonce"),new Ve(new bt(BigInt(i.amount)),"amount")]),Ao=i=>new Qr(zr.newFromBytes(Uint8Array.from(Buffer.from(i,"hex")))),Eo=()=>new Yr;export{P as ExplorerUrls,Xe as KnownTokens,ir as MultiversxExplorers,Ye as MultiversxExplorersConfig,Ne as NativeTokenEgld,_r as NativeTokenVibe,or as VibechainExplorers,N as WarpMultiversxAbiBuilder,H as WarpMultiversxBrandBuilder,G as WarpMultiversxBuilder,_a as WarpMultiversxConstants,_ as WarpMultiversxContractLoader,K as WarpMultiversxDataLoader,Z as WarpMultiversxExecutor,ee as WarpMultiversxExplorer,y as WarpMultiversxInputTypes,re as WarpMultiversxRegistry,F as WarpMultiversxResults,U as WarpMultiversxSerializer,ae as WarpMultiversxWallet,Wo as address_value,xo as asset_value,wo as biguint_value,Co as boolean_value,Zi as codemeta,Ao as codemeta_value,uo as composite_value,se as createMultiversxAdapter,Je as findKnownTokenById,Mi as getAllMultiversxAdapters,Oi as getAllMultiversxChainNames,Aa as getKnownTokensForChain,xt as getMultiversxAdapter,g as getMultiversxEntrypoint,x as getMultiversxRegistryAddress,D as getNormalizedTokenIdentifier,At as getVibechainAdapter,To as hex_value,k as isNativeToken,to as list,po as list_value,Eo as nothing_value,eo as option,oo as option_value,co as optional_value,mo as string_value,Ct as toTypedConfigInfo,te as toTypedRegistryInfo,Yi as token,vo as token_value,fo as u16_value,go as u32_value,yo as u64_value,ho as u8_value,lo 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-alpha.
|
|
3
|
+
"version": "0.2.0-alpha.58",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -38,6 +38,6 @@
|
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@multiversx/sdk-core": "^15.1.1",
|
|
41
|
-
"@vleap/warps": "^3.0.0-alpha.
|
|
41
|
+
"@vleap/warps": "^3.0.0-alpha.110"
|
|
42
42
|
}
|
|
43
43
|
}
|