@vleap/warps-adapter-multiversx 0.2.0-alpha.53 → 0.2.0-alpha.54

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var ue=Object.defineProperty;var Ne=Object.getOwnPropertyDescriptor;var Ve=Object.getOwnPropertyNames;var Se=Object.prototype.hasOwnProperty;var Fe=(o,e)=>{for(var t in e)ue(o,t,{get:e[t],enumerable:!0})},ke=(o,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of Ve(e))!Se.call(o,a)&&a!==t&&ue(o,a,{get:()=>e[a],enumerable:!(r=Ne(e,a))||r.enumerable});return o};var Pe=o=>ke(ue({},"__esModule",{value:!0}),o);var at={};Fe(at,{ExplorerUrls:()=>M,KnownTokens:()=>Ae,MultiversxExplorers:()=>Ee,MultiversxExplorersConfig:()=>he,NativeTokenEgld:()=>pe,NativeTokenVibe:()=>Be,VibechainExplorers:()=>Ie,WarpMultiversxAbiBuilder:()=>P,WarpMultiversxBrandBuilder:()=>Y,WarpMultiversxBuilder:()=>Z,WarpMultiversxConstants:()=>Re,WarpMultiversxContractLoader:()=>X,WarpMultiversxDataLoader:()=>ee,WarpMultiversxExecutor:()=>te,WarpMultiversxExplorer:()=>re,WarpMultiversxRegistry:()=>ae,WarpMultiversxResults:()=>q,WarpMultiversxSerializer:()=>U,WarpMultiversxWallet:()=>se,address_value:()=>Ye,asset_value:()=>tt,biguint_value:()=>Je,boolean_value:()=>Xe,codemeta_value:()=>rt,composite_value:()=>He,createMultiversxAdapter:()=>ie,findKnownTokenById:()=>de,getAllMultiversxAdapters:()=>Me,getAllMultiversxChainNames:()=>_e,getMultiversxAdapter:()=>ye,getMultiversxEntrypoint:()=>w,getMultiversxRegistryAddress:()=>v,getNormalizedTokenIdentifier:()=>J,getVibechainAdapter:()=>Ce,hex_value:()=>et,isNativeToken:()=>$,list_value:()=>De,nothing_value:()=>nt,option_value:()=>$e,optional_value:()=>Le,string_value:()=>ze,toTypedConfigInfo:()=>ge,toTypedRegistryInfo:()=>ne,token_value:()=>Ze,u16_value:()=>Ge,u32_value:()=>Qe,u64_value:()=>je,u8_value:()=>Ke,variadic_value:()=>qe});module.exports=Pe(at);var We=require("@vleap/warps");var Q=require("@vleap/warps");var k=require("@multiversx/sdk-core"),T=require("@vleap/warps");var H=require("@multiversx/sdk-core"),ve=require("@vleap/warps"),$=o=>!o.includes("-"),J=o=>$(o)?`${o}-000000`:o,w=(o,e,t)=>{let r="warp-sdk",s=t?(0,ve.getProviderUrl)(t,o.name,e,o.defaultApiUrl):o.defaultApiUrl;return e==="devnet"?new H.DevnetEntrypoint({url:s,kind:"api",clientName:r}):e==="testnet"?new H.TestnetEntrypoint({url:s,kind:"api",clientName:r}):new H.MainnetEntrypoint({url:s,kind:"api",clientName:r})};var me=require("@vleap/warps");var X=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 me.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 me.WarpLogger.error("WarpContractLoader: getVerificationInfo error",r),null}}};var P=class{constructor(e,t){this.config=e;this.chain=t;this.contractLoader=new X(this.config),this.cache=new T.WarpCache(this.config.cache?.type)}async createInscriptionTransaction(e){let t=(0,T.getWarpWalletAddressFromConfig)(this.config,this.chain.name);if(!t)throw new Error("WarpBuilder: 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={protocol:(0,T.getLatestProtocolIdentifier)("abi"),content:e},i=JSON.stringify(c),l=await a.createTransactionForTransfer(s,{receiver:s,nativeAmount:BigInt(0),data:Uint8Array.from(Buffer.from(i))});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=T.WarpCacheKey.WarpAbi(this.config.env,e);if(t){let c=this.cache.get(r);if(c)return T.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),i=await this.createFromTransaction(c);return t&&t.ttl&&i&&this.cache.set(r,i,t.ttl),i}catch(c){return T.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 k.AbiRegistry.create(t.abi)}async fetchAbi(e){if(!e.abi)throw new Error("WarpActionExecutor: ABI not found");if(e.abi.startsWith(T.WarpConstants.IdentifierType.Hash)){let t=e.abi.split(T.WarpConstants.ArgParamsSeparator)[1],r=await this.createFromTransactionHash(t);if(!r)throw new Error(`WarpActionExecutor: ABI not found for hash: ${e.abi}`);return k.AbiRegistry.create(r.content)}else{let r=await(await fetch(e.abi)).json();return k.AbiRegistry.create(r)}}};var L=require("@multiversx/sdk-core"),z=require("@vleap/warps"),xe=require("buffer");var Y=class{constructor(e,t){this.config=e;this.chain=t;this.core=new z.WarpBrandBuilder(e)}async createInscriptionTransaction(e){let t=(0,z.getWarpWalletAddressFromConfig)(this.config,this.chain.name);if(!t)throw new Error("BrandBuilder: user address not set");let r=new L.TransactionsFactoryConfig({chainID:this.chain.chainId}),a=new L.TransferTransactionsFactory({config:r}),s=L.Address.newFromBech32(t),c=JSON.stringify(e);return await a.createTransactionForNativeTokenTransfer(s,{receiver:L.Address.newFromBech32(t),nativeAmount:BigInt(0),data:Uint8Array.from(xe.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 z.WarpLogger.error("BrandBuilder: Error creating from transaction hash",a),null}}};var D=require("@multiversx/sdk-core"),I=require("@vleap/warps");var Z=class extends I.WarpBuilder{constructor(t,r){super(t);this.config=t;this.chain=r;this.cache=new I.WarpCache(t.cache?.type),this.core=new I.WarpBuilder(t)}async createInscriptionTransaction(t){let r=(0,I.getWarpWalletAddressFromConfig)(this.config,this.chain.name);if(!r)throw new Error("WarpBuilder: user address not set");let a=new D.TransactionsFactoryConfig({chainID:this.chain.chainId}),s=new D.TransferTransactionsFactory({config:a}),c=D.Address.newFromBech32(r),i=JSON.stringify(t),l=await s.createTransactionForTransfer(c,{receiver:D.Address.newFromBech32(r),nativeAmount:BigInt(0),data:Uint8Array.from(Buffer.from(i))});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=I.WarpCacheKey.Warp(this.config.env,t);if(r){let i=this.cache.get(a);if(i)return I.WarpLogger.info(`WarpBuilder (createFromTransactionHash): Warp found in cache: ${t}`),i}let c=w(this.chain,this.config.env,this.config).createNetworkProvider();try{let i=await c.getTransaction(t),l=await this.createFromTransaction(i);return r&&r.ttl&&l&&this.cache.set(a,l,r.ttl),l}catch(i){return I.WarpLogger.error("WarpBuilder: Error creating from transaction hash",i),null}}};var O=require("@multiversx/sdk-core"),K=require("@vleap/warps");var Te=require("@vleap/warps"),ce=Te.WarpChainName.Multiversx,Ae=[{chain:ce,identifier:"EGLD",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.pngsvg"},{chain:ce,identifier:"EGLD-000000",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"},{chain:ce,identifier:"VIBE",name:"VIBE",symbol:"VIBE",decimals:18,logoUrl:"https://vleap.ai/images/tokens/vibe.svg"},{chain:ce,identifier:"VIBE-000000",name:"VIBE",symbol:"VIBE",decimals:18,logoUrl:"https://vleap.ai/images/tokens/vibe.svg"}],de=o=>Ae.find(e=>e.identifier===o)||null;var ee=class{constructor(e,t){this.config=e;this.chain=t;this.cache=new K.WarpCache(e.cache?.type)}async getAccount(e){let r=await w(this.chain,this.config.env,this.config).createNetworkProvider().getAccount(O.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(O.Address.newFromBech32(e)),a=t.getFungibleTokensOfAccount(O.Address.newFromBech32(e)),[s,c]=await Promise.all([r,a]),i=s.balance>0?[{...this.chain.nativeToken,amount:s.balance}]:[];return i.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}))),i}async getAsset(e){let t=K.WarpCacheKey.Asset(this.config.env,this.chain.name,e),r=this.cache.get(t);if(r)return r;let a=de(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 O.TokenComputer,c=$(e)?0n:s.extractNonceFromExtendedIdentifier(e),i=new O.Token({identifier:e,nonce:BigInt(c||0)}),l=s.isFungible(i),m=w(this.chain,this.config.env,this.config).createNetworkProvider(),h=J(e),d=await m.doGetGeneric(`tokens/${h}`),x={chain:this.chain.name,identifier:i.identifier,name:d.name,symbol:d.ticker,amount:0n,decimals:d.decimals,logoUrl:d.assets?.pngUrl||"#",price:d.price?Number(d.price):void 0,supply:d.supply?BigInt(d.supply):void 0};return this.cache.set(t,x,K.CacheTtl.OneHour),x}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,i=t?.page||0;if(i>0){let m=i*c;s.append("from",m.toString())}return c!==25&&s.append("size",c.toString()),s.toString()&&(a+=`?${s.toString()}`),(await r.doGetGeneric(a)).map(m=>({chain:this.chain.name,id:m.txHash,receiver:m.receiver,sender:m.sender,value:m.value,function:m.function,status:this.toActionStatus(m),createdAt:this.toActionCreatedAt(m)}))}toActionStatus(e){return e.status.isSuccessful()?"success":e.status.isFailed()?"failed":"pending"}toActionCreatedAt(e){return new Date(e.timestamp||e.timestamp*1e3).toISOString()}};var g=require("@multiversx/sdk-core"),B=require("@vleap/warps");var G=require("@multiversx/sdk-core"),y=require("@vleap/warps");var n=require("@multiversx/sdk-core"),W=require("@vleap/warps");var be=new RegExp(`${W.WarpConstants.ArgParamsSeparator}(.*)`),U=class{constructor(){this.coreSerializer=new W.WarpSerializer}typedToString(e){let t=e.getType();if(t.hasExactClass(n.OptionType.ClassName)||e.hasClassOrSuperclass(n.OptionValue.ClassName))return e.isSet()?`option:${this.typedToString(e.getTypedValue())}`:"option:null";if(t.hasExactClass(n.OptionalType.ClassName)||e.hasClassOrSuperclass(n.OptionalValue.ClassName))return e.isSet()?`optional:${this.typedToString(e.getTypedValue())}`:"optional:null";if(t.hasExactClass(n.ListType.ClassName)||e.hasClassOrSuperclass(n.List.ClassName)){let r=e.getItems(),s=r.map(i=>this.typedToString(i).split(W.WarpConstants.ArgParamsSeparator)[0])[0],c=r.map(i=>this.typedToString(i).split(W.WarpConstants.ArgParamsSeparator)[1]);return`list:${s}:${c.join(",")}`}if(t.hasExactClass(n.VariadicType.ClassName)||e.hasClassOrSuperclass(n.VariadicValue.ClassName)){let r=e.getItems(),s=r.map(i=>this.typedToString(i).split(W.WarpConstants.ArgParamsSeparator)[0])[0],c=r.map(i=>this.typedToString(i).split(W.WarpConstants.ArgParamsSeparator)[1]);return`variadic:${s}:${c.join(",")}`}if(t.hasExactClass(n.CompositeType.ClassName)||e.hasClassOrSuperclass(n.CompositeValue.ClassName)){let r=e.getItems(),a=r.map(l=>this.typedToString(l).split(W.WarpConstants.ArgParamsSeparator)[0]),s=r.map(l=>this.typedToString(l).split(W.WarpConstants.ArgParamsSeparator)[1]),c=a.join(W.WarpConstants.ArgCompositeSeparator),i=s.join(W.WarpConstants.ArgCompositeSeparator);return`composite(${c}):${i}`}if(t.hasExactClass(n.BigUIntType.ClassName)||e.hasClassOrSuperclass(n.BigUIntValue.ClassName)||t.getName()==="BigUint")return`biguint:${BigInt(e.valueOf().toFixed())}`;if(t.hasExactClass(n.U8Type.ClassName)||e.hasClassOrSuperclass(n.U8Value.ClassName))return`uint8:${e.valueOf().toNumber()}`;if(t.hasExactClass(n.U16Type.ClassName)||e.hasClassOrSuperclass(n.U16Value.ClassName))return`uint16:${e.valueOf().toNumber()}`;if(t.hasExactClass(n.U32Type.ClassName)||e.hasClassOrSuperclass(n.U32Value.ClassName))return`uint32:${e.valueOf().toNumber()}`;if(t.hasExactClass(n.U64Type.ClassName)||e.hasClassOrSuperclass(n.U64Value.ClassName))return`uint64:${BigInt(e.valueOf().toFixed())}`;if(t.hasExactClass(n.StringType.ClassName)||e.hasClassOrSuperclass(n.StringValue.ClassName))return`string:${e.valueOf()}`;if(t.hasExactClass(n.BooleanType.ClassName)||e.hasClassOrSuperclass(n.BooleanValue.ClassName))return`bool:${e.valueOf()}`;if(t.hasExactClass(n.AddressType.ClassName)||e.hasClassOrSuperclass(n.AddressValue.ClassName))return`address:${e.valueOf().toBech32()}`;if(t.hasExactClass(n.TokenIdentifierType.ClassName)||e.hasClassOrSuperclass(n.TokenIdentifierValue.ClassName))return`token:${e.valueOf()}`;if(t.hasExactClass(n.BytesType.ClassName)||e.hasClassOrSuperclass(n.BytesValue.ClassName))return`hex:${e.valueOf().toString("hex")}`;if(t.hasExactClass(n.CodeMetadataType.ClassName)||e.hasClassOrSuperclass(n.CodeMetadataValue.ClassName))return`codemeta:${e.valueOf().toString()}`;if(t.getName()==="EsdtTokenPayment"){let r=e.getFieldValue("token_identifier").valueOf(),a=e.getFieldValue("token_nonce").valueOf(),s=e.getFieldValue("amount").valueOf();return`asset:${new n.TokenComputer().computeExtendedIdentifier(new n.Token({identifier:r,nonce:BigInt(a)}))}|${s}`}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("composite")){let t=e.match(/\(([^)]+)\)/)?.[1];return new n.CompositeType(...t.split(W.WarpConstants.ArgCompositeSeparator).map(r=>this.nativeToType(r)))}if(e==="string")return new n.StringType;if(e==="uint8")return new n.U8Type;if(e==="uint16")return new n.U16Type;if(e==="uint32")return new n.U32Type;if(e==="uint64")return new n.U64Type;if(e==="biguint")return new n.BigUIntType;if(e==="bool")return new n.BooleanType;if(e==="address")return new n.AddressType;if(e==="token")return new n.TokenIdentifierType;if(e==="hex")return new n.BytesType;if(e==="codemeta")return new n.CodeMetadataType;if(e==="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)]);throw new Error(`WarpArgSerializer (nativeToType): Unsupported input type: ${e}`)}stringToTyped(e){let[t,r]=e.split(/:(.*)/,2);if(t==="null"||t===null)return new n.NothingValue;if(t==="option"){let a=this.stringToTyped(r);return a instanceof n.NothingValue?n.OptionValue.newMissingTyped(a.getType()):n.OptionValue.newProvided(a)}if(t==="optional"){let a=this.stringToTyped(r);return a instanceof n.NothingValue?n.OptionalValue.newMissing():new n.OptionalValue(a.getType(),a)}if(t==="list"){let[a,s]=r.split(be,2),i=s.split(",").map(l=>this.stringToTyped(`${a}:${l}`));return new n.List(this.nativeToType(a),i)}if(t==="variadic"){let[a,s]=r.split(be,2),i=s.split(",").map(l=>this.stringToTyped(`${a}:${l}`));return new n.VariadicValue(new n.VariadicType(this.nativeToType(a)),i)}if(t.startsWith("composite")){let a=t.match(/\(([^)]+)\)/)?.[1],s=r.split(W.WarpConstants.ArgCompositeSeparator),c=a.split(W.WarpConstants.ArgCompositeSeparator),i=s.map((m,h)=>this.stringToTyped(`${c[h]}:${m}`)),l=i.map(m=>m.getType());return new n.CompositeValue(new n.CompositeType(...l),i)}if(t==="string")return r?n.StringValue.fromUTF8(r):new n.NothingValue;if(t==="uint8")return r?new n.U8Value(Number(r)):new n.NothingValue;if(t==="uint16")return r?new n.U16Value(Number(r)):new n.NothingValue;if(t==="uint32")return r?new n.U32Value(Number(r)):new n.NothingValue;if(t==="uint64")return r?new n.U64Value(BigInt(r)):new n.NothingValue;if(t==="biguint")return r?new n.BigUIntValue(BigInt(r)):new n.NothingValue;if(t==="bool")return r?new n.BooleanValue(typeof r=="boolean"?r:r==="true"):new n.NothingValue;if(t==="address")return r?new n.AddressValue(n.Address.newFromBech32(r)):new n.NothingValue;if(t==="token")return r?new n.TokenIdentifierValue(r):new n.NothingValue;if(t==="hex")return r?n.BytesValue.fromHex(r):new n.NothingValue;if(t==="codemeta")return new n.CodeMetadataValue(n.CodeMetadata.newFromBytes(Uint8Array.from(Buffer.from(r,"hex"))));if(t==="asset"){let[a,s]=r.split(W.WarpConstants.ArgCompositeSeparator),c=new n.TokenComputer,i=$(a)?J(a):c.extractIdentifierFromExtendedIdentifier(a),l=$(a)?0n:c.extractNonceFromExtendedIdentifier(a);return new n.Struct(this.nativeToType("asset"),[new n.Field(new n.TokenIdentifierValue(i),"token_identifier"),new n.Field(new n.U64Value(BigInt(l)),"token_nonce"),new n.Field(new n.BigUIntValue(BigInt(s)),"amount")])}throw new Error(`WarpArgSerializer (stringToTyped): Unsupported input type: ${t}`)}typeToString(e){if(e.hasExactClass(n.OptionType.ClassName))return"option:"+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(n.OptionalType.ClassName))return"optional:"+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(n.ListType.ClassName))return"list:"+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(n.VariadicType.ClassName))return"variadic:"+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(n.StringType.ClassName))return"string";if(e.hasExactClass(n.U8Type.ClassName))return"uint8";if(e.hasExactClass(n.U16Type.ClassName))return"uint16";if(e.hasExactClass(n.U32Type.ClassName))return"uint32";if(e.hasExactClass(n.U64Type.ClassName))return"uint64";if(e.hasExactClass(n.BigUIntType.ClassName))return"biguint";if(e.hasExactClass(n.BooleanType.ClassName))return"bool";if(e.hasExactClass(n.AddressType.ClassName))return"address";if(e.hasExactClass(n.TokenIdentifierType.ClassName))return"token";if(e.hasExactClass(n.BytesType.ClassName))return"hex";if(e.hasExactClass(n.CodeMetadataType.ClassName))return"codemeta";if(e.hasExactClass(n.StructType.ClassName)&&e.getClassName()==="EsdtTokenPayment")return"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 P(e,t),this.serializer=new U,this.cache=new y.WarpCache(e.cache?.type)}async getTransactionExecutionResults(e,t){let{actionIndex:r}=(0,y.findWarpExecutableAction)(e),a=this.cache.get(y.WarpCacheKey.WarpExecutable(this.config.env,e.meta?.hash||"",r))??[],s=await this.extractContractResults(e,t,a),c=(0,y.getNextInfo)(this.config,[],e,r,s),i=(0,y.applyResultsToMessages)(e,s.results);return{success:t.status.isSuccessful(),warp:e,action:r,user:(0,y.getWarpWalletAddressFromConfig)(this.config,this.chain.name),txHash:t.hash,tx:t,next:c,values:s.values,valuesRaw:[],results:s.results,messages:i}}async extractContractResults(e,t,r){let{action:a,actionIndex:s}=(0,y.findWarpExecutableAction)(e),c=[],i={};if(!e.results||a.type!=="contract")return{values:c,results:i};if(!Object.values(e.results).some(A=>A.includes("out")||A.includes("event"))){for(let[A,f]of Object.entries(e.results))i[A]=f;return{values:c,results:await(0,y.evaluateResultsCommon)(e,i,s,r,this.config.transform?.runner)}}let m=await this.abi.getAbiForAction(a),h=new G.TransactionEventsParser({abi:m}),x=new G.SmartContractTransactionsOutcomeParser({abi:m}).parseExecute({transactionOnNetwork:t,function:a.func||void 0});for(let[A,f]of Object.entries(e.results)){if(f.startsWith(y.WarpConstants.Transform.Prefix))continue;if(f.startsWith("input.")){i[A]=f;continue}let S=(0,y.parseResultsOutIndex)(f);if(S!==null&&S!==s){i[A]=null;continue}let[b,E,R]=f.split(".");if(b==="event"){if(!E||isNaN(Number(R)))continue;let F=Number(R),C=(0,G.findEventsByFirstTopic)(t,E),j=h.parseEvents({events:C})[0],oe=Object.values(j)[F]||null;c.push(oe),i[A]=oe&&oe.valueOf()}else if(b==="out"||b.startsWith("out[")){if(!E)continue;let F=Number(E),C=x.values[F-1]||null;R&&(C=C[R]||null),C&&typeof C=="object"&&(C="toFixed"in C?C.toFixed():C.valueOf()),c.push(C),i[A]=C&&C.valueOf()}else i[A]=f}return{values:c,results:await(0,y.evaluateResultsCommon)(e,i,s,r)}}async extractQueryResults(e,t,r,a){let s=t.map(m=>this.serializer.typedToString(m)),c=t.map(m=>this.serializer.typedToNative(m)[1]),i={};if(!e.results)return{values:s,valuesRaw:c,results:i};let l=m=>{let h=m.split(".").slice(1).map(x=>parseInt(x)-1);if(h.length===0)return;let d=c[h[0]];for(let x=1;x<h.length;x++){if(d==null)return;d=d[h[x]]}return d};for(let[m,h]of Object.entries(e.results)){if(h.startsWith(y.WarpConstants.Transform.Prefix))continue;let d=(0,y.parseResultsOutIndex)(h);if(d!==null&&d!==r){i[m]=null;continue}h.startsWith("out.")||h==="out"||h.startsWith("out[")?i[m]=l(h)||null:i[m]=h}return{values:s,valuesRaw:c,results:await(0,y.evaluateResultsCommon)(e,i,r,a)}}async resolveWarpResultsRecursively(e){let t=e.warp,r=e.entryActionIndex,a=e.executor,s=e.inputs,c=e.meta,i=new Map,l=new Set,m=this;async function h(f,S=[]){if(i.has(f))return i.get(f);if(l.has(f))throw new Error(`Circular dependency detected at action ${f}`);l.add(f);let b=t.actions[f-1];if(!b)throw new Error(`Action ${f} not found`);let E;if(b.type==="query")E=await a.executeQuery(t,f,S);else if(b.type==="collect")E=await a.executeCollect(t,f,S,c);else throw new Error(`Unsupported or interactive action type: ${b.type}`);if(i.set(f,E),t.results)for(let R of Object.values(t.results)){let C=String(R).match(/^out\[(\d+)\]/);if(C){let j=parseInt(C[1],10);j!==f&&!i.has(j)&&await h(j)}}return l.delete(f),E}await h(r,s);let d={};for(let f of i.values())for(let[S,b]of Object.entries(f.results))b!==null?d[S]=b:S in d||(d[S]=null);let x=await(0,y.evaluateResultsCommon)(t,d,r,s,this.config.transform?.runner);return{...i.get(r),action:r,results:x}}};var Ue="EGLD-000000",te=class{constructor(e,t){this.config=e;this.chain=t;this.serializer=new U,this.abi=new P(this.config,this.chain),this.results=new q(this.config,this.chain)}async createTransaction(e){let t=(0,B.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,B.getWarpWalletAddressFromConfig)(this.config,e.chain.name);if(!t)throw new Error("WarpMultiversxExecutor: createTransfer - user address not set");let r=g.Address.newFromBech32(t),a=new g.TransactionsFactoryConfig({chainID:e.chain.chainId}),s=e.data?Buffer.from(this.serializer.stringToTyped(e.data).valueOf()):null;return new g.TransferTransactionsFactory({config:a}).createTransactionForTransfer(r,{receiver:g.Address.newFromBech32(e.destination),nativeAmount:e.value,tokenTransfers:this.toTokenTransfers(e.transfers),data:s?new Uint8Array(s):void 0})}async createContractCallTransaction(e){let t=(0,B.getWarpWalletAddressFromConfig)(this.config,e.chain.name);if(!t)throw new Error("WarpMultiversxExecutor: createContractCall - user address not set");let r=(0,B.getWarpActionByIndex)(e.warp,e.action),a=g.Address.newFromBech32(t),s=e.args.map(i=>this.serializer.stringToTyped(i)),c=new g.TransactionsFactoryConfig({chainID:e.chain.chainId});return new g.SmartContractTransactionsFactory({config:c}).createTransactionForExecute(a,{contract:g.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,B.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=g.Address.newFromBech32(e.destination),i=s.createSmartContractController(r),l=i.createQuery({contract:c,function:t.func||"",arguments:a}),m=await i.runQuery(l),h=m.returnCode==="ok",d=new g.ArgSerializer,x=r.getEndpoint(m.function||t.func||""),A=(m.returnDataParts||[]).map(F=>Buffer.from(F)),f=d.buffersToValues(A,x.output),{values:S,valuesRaw:b,results:E}=await this.results.extractQueryResults(e.warp,f,e.action,e.resolvedInputs),R=(0,B.getNextInfo)(this.config,[],e.warp,e.action,E);return{success:h,warp:e.warp,action:e.action,user:(0,B.getWarpWalletAddressFromConfig)(this.config,e.chain.name),txHash:null,tx:null,next:R,values:S,valuesRaw:b,results:E,messages:(0,B.applyResultsToMessages)(e.warp,E)}}async signMessage(e,t){let r=g.UserSecretKey.fromString(t);return(await new g.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:Ue}:t).map(t=>{let a=new g.TokenComputer().extractNonceFromExtendedIdentifier(t.identifier);return new g.TokenTransfer({token:new g.Token({identifier:t.identifier,nonce:BigInt(a||0)}),amount:t.amount})})}};var Re={Egld:{Identifier:"EGLD",EsdtIdentifier:"EGLD-000000",DisplayName:"eGold",Decimals:18}},Ee=(r=>(r.MultiversxExplorer="multiversx_explorer",r.MultiversxExplorerDevnet="multiversx_explorer_devnet",r.MultiversxExplorerTestnet="multiversx_explorer_testnet",r))(Ee||{}),Ie=(r=>(r.VibechainExplorer="vibechain_explorer",r.VibechainExplorerDevnet="vibechain_explorer_devnet",r.VibechainExplorerTestnet="vibechain_explorer_testnet",r))(Ie||{}),he={multiversx:{mainnet:["multiversx_explorer"],testnet:["multiversx_explorer_testnet"],devnet:["multiversx_explorer_devnet"]},vibechain:{mainnet:["vibechain_explorer"],testnet:["vibechain_explorer_testnet"],devnet:["vibechain_explorer_devnet"]}},M={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 re=class{constructor(e,t){this.chain=e;this.config=t}getExplorers(){let e=he[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=M[t];if(s)return s}if(e){let s=M[e];if(s)return s}let r=this.getPrimaryExplorer();return M[r]||M[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=M[a];s&&(r[a]=`${s}/accounts/${e}`)}),r}getTransactionUrls(e){let t=this.getAllExplorers(),r={};return t.forEach(a=>{let s=M[a];s&&(r[a]=`${s}/transactions/${e}`)}),r}};var u=require("@multiversx/sdk-core"),N=require("@vleap/warps");var fe={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 v=o=>{if(o==="devnet")return"erd1qqqqqqqqqqqqqpgqje2f99vr6r7sk54thg03c9suzcvwr4nfl3tsfkdl36";if(o==="testnet")throw new Error("Multiversx testnet is not supported");return"erd1qqqqqqqqqqqqqpgq3mrpj3u6q7tejv6d7eqhnyd27n9v5c5tl3ts08mffe"};var ne=o=>({hash:o.hash.toString("hex"),alias:o.alias?.toString()||null,trust:o.trust.toString(),owner:o.owner.toString(),createdAt:o.created_at.toNumber(),upgradedAt:o.upgraded_at?.toNumber(),brand:o.brand?.toString("hex")||null,upgrade:o.upgrade?.toString("hex")||null}),ge=o=>({unitPrice:BigInt(o.unit_price.toString()),admins:o.admins.map(e=>e.toBech32())});var ae=class{constructor(e,t){this.config=e;this.chain=t;this.cache=new N.WarpCache(e.cache?.type),this.registryConfig={unitPrice:BigInt(0),admins:[]},this.userWallet=(0,N.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(v(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(v(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(v(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(v(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(v(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(v(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(v(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(v(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=N.WarpCacheKey.RegistryInfo(this.config.env,e),a=t?this.cache.get(r):null;if(a)return N.WarpLogger.info(`WarpRegistry (getInfoByAlias): RegistryInfo found in cache: ${e}`),a;let s=u.Address.newFromBech32(v(this.config.env)),c=this.getController(),i=c.createQuery({contract:s,function:"getInfoByAlias",arguments:[u.BytesValue.fromUTF8(e)]}),l=await c.runQuery(i),[m]=c.parseQueryResponse(l),h=m?ne(m):null,d=h?.brand?await this.fetchBrand(h.brand):null;return t&&t.ttl&&this.cache.set(r,{registryInfo:h,brand:d},t.ttl),{registryInfo:h,brand:d}}catch{return{registryInfo:null,brand:null}}}async getInfoByHash(e,t){try{let r=N.WarpCacheKey.RegistryInfo(this.config.env,e);if(t){let d=this.cache.get(r);if(d)return N.WarpLogger.info(`WarpRegistry (getInfoByHash): RegistryInfo found in cache: ${e}`),d}let a=u.Address.newFromBech32(v(this.config.env)),s=this.getController(),c=s.createQuery({contract:a,function:"getInfoByHash",arguments:[u.BytesValue.fromHex(e)]}),i=await s.runQuery(c),[l]=s.parseQueryResponse(i),m=l?ne(l):null,h=m?.brand?await this.fetchBrand(m.brand):null;return t&&t.ttl&&this.cache.set(r,{registryInfo:m,brand:h},t.ttl),{registryInfo:m,brand:h}}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(v(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),[i]=a.parseQueryResponse(c);return i.map(ne)}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(v(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),[i]=a.parseQueryResponse(c),l=i.map(d=>d.toString("hex")),m={ttl:365*24*60*60};return(await Promise.all(l.map(d=>this.fetchBrand(d,m)))).filter(d=>d!==null)}catch{return[]}}async fetchBrand(e,t){let r=N.WarpCacheKey.Brand(this.config.env,e),a=t?this.cache.get(r):null;if(a)return N.WarpLogger.info(`WarpRegistry (fetchBrand): Brand found in cache: ${e}`),a;let c=w(this.chain,this.config.env,this.config).createNetworkProvider();try{let i=await c.getTransaction(e),l=JSON.parse(i.data.toString());return l.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,l,t.ttl),l}catch{return null}}async loadRegistryConfigs(){let e=u.Address.newFromBech32(v(this.config.env)),t=this.getController(),[r]=await t.query({contract:e,function:"getConfig",arguments:[]}),a=r?ge(r):null;this.registryConfig=a||{unitPrice:BigInt(0),admins:[]}}getFactory(){let e=new u.TransactionsFactoryConfig({chainID:this.chain.chainId}),t=u.AbiRegistry.create(fe);return new u.SmartContractTransactionsFactory({config:e,abi:t})}getController(){let e=w(this.chain,this.config.env,this.config),t=u.AbiRegistry.create(fe);return e.createSmartContractController(t)}isCurrentUserAdmin(){return!!this.userWallet&&this.registryConfig.admins.includes(this.userWallet)}};var V=require("@multiversx/sdk-core"),_=require("@vleap/warps");var se=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 _.WarpCache(e.cache?.type)}async signTransaction(e){if(!e||typeof e!="object")throw new Error("Invalid transaction object");let t=(0,_.getWarpWalletPrivateKeyFromConfig)(this.config,this.chain.name);if(!t)throw new Error("Wallet not initialized - no private key provided");console.log("privateKey",t);let r=t.startsWith("-----");console.log("isPrivateKeyPem",r);let a=r?V.UserSecretKey.fromPem(t):V.UserSecretKey.fromString(t),s=new V.UserSigner(a),c=new V.Account(a),i=(await this.provider.getAccount(c.address)).nonce,l=this.cache.get(`nonce:${c.address.toBech32()}`)||0;c.nonce=BigInt(Math.max(l,Number(i))),e.nonce=c.getNonceThenIncrement();let h=new V.TransactionComputer().computeBytesForSigning(e);return e.signature=await s.sign(h),this.cache.set(`nonce:${c.address.toBech32()}`,Number(c.nonce),_.CacheTtl.OneHour),e}async signMessage(e){throw new Error("Not implemented")}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,_.getWarpWalletAddressFromConfig)(this.config,this.chain.name)}};var ie=(o,e,t)=>(r,a)=>{let s=t[r.env];return{chain:o,chainInfo:s,prefix:e,builder:()=>new Z(r,s),executor:new te(r,s),results:new q(r,s),serializer:new U,registry:new ae(r,s),explorer:new re(o,r),abiBuilder:()=>new P(r,s),brandBuilder:()=>new Y(r,s),dataLoader:new ee(r,s),wallet:new se(r,s),registerTypes:c=>{c.registerType("token",{stringToNative:i=>i,nativeToString:i=>`token:${i}`}),c.registerType("codemeta",{stringToNative:i=>i,nativeToString:i=>`codemeta:${i}`})}}};var pe={chain:Q.WarpChainName.Multiversx,identifier:"EGLD",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://vleap.ai/images/tokens/egld.svg"},ye=ie(Q.WarpChainName.Multiversx,"mvx",{mainnet:{name:Q.WarpChainName.Multiversx,displayName:"MultiversX",chainId:"1",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://api.multiversx.com",logoUrl:"https://vleap.ai/images/chains/multiversx.svg",nativeToken:pe},testnet:{name:Q.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:pe},devnet:{name:Q.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:pe}});var le=require("@vleap/warps");var Be={chain:le.WarpChainName.Vibechain,identifier:"VIBE",name:"VIBE",symbol:"VIBE",decimals:18,logoUrl:"https://vleap.ai/images/tokens/vibe.svg"},we={name:le.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:Be},Ce=ie(le.WarpChainName.Vibechain,"vibe",{mainnet:we,testnet:we,devnet:we});var Me=(o,e)=>[ye(o,e),Ce(o,e)],_e=()=>[We.WarpChainName.Multiversx,We.WarpChainName.Vibechain];var p=require("@multiversx/sdk-core"),$e=(o,e)=>o?p.OptionValue.newProvided(o):e?p.OptionValue.newMissingTyped(e):p.OptionValue.newMissing(),Le=(o,e)=>o?new p.OptionalValue(o.getType(),o):e?new p.OptionalValue(e):p.OptionalValue.newMissing(),De=o=>{if(o.length===0)throw new Error("Cannot create a list from an empty array");let e=o[0].getType();return new p.List(e,o)},qe=o=>p.VariadicValue.fromItems(...o),He=o=>{let e=o.map(t=>t.getType());return new p.CompositeValue(new p.CompositeType(...e),o)},ze=o=>p.StringValue.fromUTF8(o),Ke=o=>new p.U8Value(o),Ge=o=>new p.U16Value(o),Qe=o=>new p.U32Value(o),je=o=>new p.U64Value(o),Je=o=>new p.BigUIntValue(BigInt(o)),Xe=o=>new p.BooleanValue(o),Ye=o=>new p.AddressValue(p.Address.newFromBech32(o)),Ze=o=>new p.TokenIdentifierValue(o),et=o=>p.BytesValue.fromHex(o),tt=o=>new p.Struct(new p.StructType("EsdtTokenPayment",[new p.FieldDefinition("token_identifier","",new p.TokenIdentifierType),new p.FieldDefinition("token_nonce","",new p.U64Type),new p.FieldDefinition("amount","",new p.BigUIntType)]),[new p.Field(new p.TokenIdentifierValue(o.token.identifier),"token_identifier"),new p.Field(new p.U64Value(BigInt(o.token.nonce)),"token_nonce"),new p.Field(new p.BigUIntValue(BigInt(o.amount)),"amount")]),rt=o=>new p.CodeMetadataValue(p.CodeMetadata.newFromBytes(Uint8Array.from(Buffer.from(o,"hex")))),nt=()=>new p.NothingValue;0&&(module.exports={ExplorerUrls,KnownTokens,MultiversxExplorers,MultiversxExplorersConfig,NativeTokenEgld,NativeTokenVibe,VibechainExplorers,WarpMultiversxAbiBuilder,WarpMultiversxBrandBuilder,WarpMultiversxBuilder,WarpMultiversxConstants,WarpMultiversxContractLoader,WarpMultiversxDataLoader,WarpMultiversxExecutor,WarpMultiversxExplorer,WarpMultiversxRegistry,WarpMultiversxResults,WarpMultiversxSerializer,WarpMultiversxWallet,address_value,asset_value,biguint_value,boolean_value,codemeta_value,composite_value,createMultiversxAdapter,findKnownTokenById,getAllMultiversxAdapters,getAllMultiversxChainNames,getMultiversxAdapter,getMultiversxEntrypoint,getMultiversxRegistryAddress,getNormalizedTokenIdentifier,getVibechainAdapter,hex_value,isNativeToken,list_value,nothing_value,option_value,optional_value,string_value,toTypedConfigInfo,toTypedRegistryInfo,token_value,u16_value,u32_value,u64_value,u8_value,variadic_value});
1
+ "use strict";var ue=Object.defineProperty;var Ne=Object.getOwnPropertyDescriptor;var Ve=Object.getOwnPropertyNames;var Se=Object.prototype.hasOwnProperty;var ke=(o,e)=>{for(var t in e)ue(o,t,{get:e[t],enumerable:!0})},Fe=(o,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of Ve(e))!Se.call(o,a)&&a!==t&&ue(o,a,{get:()=>e[a],enumerable:!(r=Ne(e,a))||r.enumerable});return o};var Pe=o=>Fe(ue({},"__esModule",{value:!0}),o);var at={};ke(at,{ExplorerUrls:()=>_,KnownTokens:()=>Ae,MultiversxExplorers:()=>Ee,MultiversxExplorersConfig:()=>fe,NativeTokenEgld:()=>pe,NativeTokenVibe:()=>Be,VibechainExplorers:()=>Ie,WarpMultiversxAbiBuilder:()=>P,WarpMultiversxBrandBuilder:()=>Y,WarpMultiversxBuilder:()=>Z,WarpMultiversxConstants:()=>Re,WarpMultiversxContractLoader:()=>X,WarpMultiversxDataLoader:()=>ee,WarpMultiversxExecutor:()=>te,WarpMultiversxExplorer:()=>re,WarpMultiversxRegistry:()=>ae,WarpMultiversxResults:()=>K,WarpMultiversxSerializer:()=>U,WarpMultiversxWallet:()=>se,address_value:()=>Ye,asset_value:()=>tt,biguint_value:()=>Je,boolean_value:()=>Xe,codemeta_value:()=>rt,composite_value:()=>qe,createMultiversxAdapter:()=>ie,findKnownTokenById:()=>de,getAllMultiversxAdapters:()=>Me,getAllMultiversxChainNames:()=>_e,getMultiversxAdapter:()=>ye,getMultiversxEntrypoint:()=>w,getMultiversxRegistryAddress:()=>v,getNormalizedTokenIdentifier:()=>J,getVibechainAdapter:()=>Ce,hex_value:()=>et,isNativeToken:()=>$,list_value:()=>De,nothing_value:()=>nt,option_value:()=>$e,optional_value:()=>Le,string_value:()=>ze,toTypedConfigInfo:()=>ge,toTypedRegistryInfo:()=>ne,token_value:()=>Ze,u16_value:()=>Ge,u32_value:()=>Qe,u64_value:()=>je,u8_value:()=>He,variadic_value:()=>Ke});module.exports=Pe(at);var We=require("@vleap/warps");var Q=require("@vleap/warps");var F=require("@multiversx/sdk-core"),A=require("@vleap/warps");var q=require("@multiversx/sdk-core"),ve=require("@vleap/warps"),$=o=>!o.includes("-"),J=o=>$(o)?`${o}-000000`:o,w=(o,e,t)=>{let r="warp-sdk",s=t?(0,ve.getProviderUrl)(t,o.name,e,o.defaultApiUrl):o.defaultApiUrl;return e==="devnet"?new q.DevnetEntrypoint({url:s,kind:"api",clientName:r}):e==="testnet"?new q.TestnetEntrypoint({url:s,kind:"api",clientName:r}):new q.MainnetEntrypoint({url:s,kind:"api",clientName:r})};var me=require("@vleap/warps");var X=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 me.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 me.WarpLogger.error("WarpContractLoader: getVerificationInfo error",r),null}}};var P=class{constructor(e,t){this.config=e;this.chain=t;this.contractLoader=new X(this.config),this.cache=new A.WarpCache(this.config.cache?.type)}async createInscriptionTransaction(e){let t=(0,A.getWarpWalletAddressFromConfig)(this.config,this.chain.name);if(!t)throw new Error("WarpBuilder: user address not set");let r=new F.TransactionsFactoryConfig({chainID:this.chain.chainId}),a=new F.TransferTransactionsFactory({config:r}),s=F.Address.newFromBech32(t),c={protocol:(0,A.getLatestProtocolIdentifier)("abi"),content:e},i=JSON.stringify(c),l=await a.createTransactionForTransfer(s,{receiver:s,nativeAmount:BigInt(0),data:Uint8Array.from(Buffer.from(i))});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=A.WarpCacheKey.WarpAbi(this.config.env,e);if(t){let c=this.cache.get(r);if(c)return A.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),i=await this.createFromTransaction(c);return t&&t.ttl&&i&&this.cache.set(r,i,t.ttl),i}catch(c){return A.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 F.AbiRegistry.create(t.abi)}async fetchAbi(e){if(!e.abi)throw new Error("WarpActionExecutor: ABI not found");if(e.abi.startsWith(A.WarpConstants.IdentifierType.Hash)){let t=e.abi.split(A.WarpConstants.ArgParamsSeparator)[1],r=await this.createFromTransactionHash(t);if(!r)throw new Error(`WarpActionExecutor: ABI not found for hash: ${e.abi}`);return F.AbiRegistry.create(r.content)}else{let r=await(await fetch(e.abi)).json();return F.AbiRegistry.create(r)}}};var L=require("@multiversx/sdk-core"),z=require("@vleap/warps"),xe=require("buffer");var Y=class{constructor(e,t){this.config=e;this.chain=t;this.core=new z.WarpBrandBuilder(e)}async createInscriptionTransaction(e){let t=(0,z.getWarpWalletAddressFromConfig)(this.config,this.chain.name);if(!t)throw new Error("BrandBuilder: user address not set");let r=new L.TransactionsFactoryConfig({chainID:this.chain.chainId}),a=new L.TransferTransactionsFactory({config:r}),s=L.Address.newFromBech32(t),c=JSON.stringify(e);return await a.createTransactionForNativeTokenTransfer(s,{receiver:L.Address.newFromBech32(t),nativeAmount:BigInt(0),data:Uint8Array.from(xe.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 z.WarpLogger.error("BrandBuilder: Error creating from transaction hash",a),null}}};var D=require("@multiversx/sdk-core"),B=require("@vleap/warps");var Z=class extends B.WarpBuilder{constructor(t,r){super(t);this.config=t;this.chain=r;this.cache=new B.WarpCache(t.cache?.type),this.core=new B.WarpBuilder(t)}async createInscriptionTransaction(t){let r=(0,B.getWarpWalletAddressFromConfig)(this.config,this.chain.name);if(!r)throw new Error("WarpBuilder: user address not set");let a=new D.TransactionsFactoryConfig({chainID:this.chain.chainId}),s=new D.TransferTransactionsFactory({config:a}),c=D.Address.newFromBech32(r),i=JSON.stringify(t),l=await s.createTransactionForTransfer(c,{receiver:D.Address.newFromBech32(r),nativeAmount:BigInt(0),data:Uint8Array.from(Buffer.from(i))});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=B.WarpCacheKey.Warp(this.config.env,t);if(r){let i=this.cache.get(a);if(i)return B.WarpLogger.info(`WarpBuilder (createFromTransactionHash): Warp found in cache: ${t}`),i}let c=w(this.chain,this.config.env,this.config).createNetworkProvider();try{let i=await c.getTransaction(t),l=await this.createFromTransaction(i);return r&&r.ttl&&l&&this.cache.set(a,l,r.ttl),l}catch(i){return B.WarpLogger.error("WarpBuilder: Error creating from transaction hash",i),null}}};var M=require("@multiversx/sdk-core"),H=require("@vleap/warps");var Te=require("@vleap/warps"),ce=Te.WarpChainName.Multiversx,Ae=[{chain:ce,identifier:"EGLD",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.pngsvg"},{chain:ce,identifier:"EGLD-000000",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"},{chain:ce,identifier:"VIBE",name:"VIBE",symbol:"VIBE",decimals:18,logoUrl:"https://vleap.ai/images/tokens/vibe.svg"},{chain:ce,identifier:"VIBE-000000",name:"VIBE",symbol:"VIBE",decimals:18,logoUrl:"https://vleap.ai/images/tokens/vibe.svg"}],de=o=>Ae.find(e=>e.identifier===o)||null;var ee=class{constructor(e,t){this.config=e;this.chain=t;this.cache=new H.WarpCache(e.cache?.type)}async getAccount(e){let r=await w(this.chain,this.config.env,this.config).createNetworkProvider().getAccount(M.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(M.Address.newFromBech32(e)),a=t.getFungibleTokensOfAccount(M.Address.newFromBech32(e)),[s,c]=await Promise.all([r,a]),i=s.balance>0?[{...this.chain.nativeToken,amount:s.balance}]:[];return i.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}))),i}async getAsset(e){let t=H.WarpCacheKey.Asset(this.config.env,this.chain.name,e),r=this.cache.get(t);if(r)return r;let a=de(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 M.TokenComputer,c=$(e)?0n:s.extractNonceFromExtendedIdentifier(e),i=new M.Token({identifier:e,nonce:BigInt(c||0)}),l=s.isFungible(i),m=w(this.chain,this.config.env,this.config).createNetworkProvider(),f=J(e),d=await m.doGetGeneric(`tokens/${f}`),T={chain:this.chain.name,identifier:i.identifier,name:d.name,symbol:d.ticker,amount:0n,decimals:d.decimals,logoUrl:d.assets?.pngUrl||"#",price:d.price?Number(d.price):void 0,supply:d.supply?BigInt(d.supply):void 0};return this.cache.set(t,T,H.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,i=t?.page||0;if(i>0){let m=i*c;s.append("from",m.toString())}return c!==25&&s.append("size",c.toString()),s.toString()&&(a+=`?${s.toString()}`),(await r.doGetGeneric(a)).map(m=>({chain:this.chain.name,id:m.txHash,receiver:m.receiver,sender:m.sender,value:m.value,function:m.function,status:this.toActionStatus(m),createdAt:this.toActionCreatedAt(m)}))}toActionStatus(e){return e.status.isSuccessful()?"success":e.status.isFailed()?"failed":"pending"}toActionCreatedAt(e){return new Date(e.timestamp||e.timestamp*1e3).toISOString()}};var g=require("@multiversx/sdk-core"),N=require("@vleap/warps");var G=require("@multiversx/sdk-core"),y=require("@vleap/warps");var n=require("@multiversx/sdk-core"),W=require("@vleap/warps");var be=new RegExp(`${W.WarpConstants.ArgParamsSeparator}(.*)`),U=class{constructor(){this.coreSerializer=new W.WarpSerializer}typedToString(e){let t=e.getType();if(t.hasExactClass(n.OptionType.ClassName)||e.hasClassOrSuperclass(n.OptionValue.ClassName))return e.isSet()?`option:${this.typedToString(e.getTypedValue())}`:"option:null";if(t.hasExactClass(n.OptionalType.ClassName)||e.hasClassOrSuperclass(n.OptionalValue.ClassName))return e.isSet()?`optional:${this.typedToString(e.getTypedValue())}`:"optional:null";if(t.hasExactClass(n.ListType.ClassName)||e.hasClassOrSuperclass(n.List.ClassName)){let r=e.getItems(),s=r.map(i=>this.typedToString(i).split(W.WarpConstants.ArgParamsSeparator)[0])[0],c=r.map(i=>this.typedToString(i).split(W.WarpConstants.ArgParamsSeparator)[1]);return`list:${s}:${c.join(",")}`}if(t.hasExactClass(n.VariadicType.ClassName)||e.hasClassOrSuperclass(n.VariadicValue.ClassName)){let r=e.getItems(),s=r.map(i=>this.typedToString(i).split(W.WarpConstants.ArgParamsSeparator)[0])[0],c=r.map(i=>this.typedToString(i).split(W.WarpConstants.ArgParamsSeparator)[1]);return`variadic:${s}:${c.join(",")}`}if(t.hasExactClass(n.CompositeType.ClassName)||e.hasClassOrSuperclass(n.CompositeValue.ClassName)){let r=e.getItems(),a=r.map(l=>this.typedToString(l).split(W.WarpConstants.ArgParamsSeparator)[0]),s=r.map(l=>this.typedToString(l).split(W.WarpConstants.ArgParamsSeparator)[1]),c=a.join(W.WarpConstants.ArgCompositeSeparator),i=s.join(W.WarpConstants.ArgCompositeSeparator);return`composite(${c}):${i}`}if(t.hasExactClass(n.BigUIntType.ClassName)||e.hasClassOrSuperclass(n.BigUIntValue.ClassName)||t.getName()==="BigUint")return`biguint:${BigInt(e.valueOf().toFixed())}`;if(t.hasExactClass(n.U8Type.ClassName)||e.hasClassOrSuperclass(n.U8Value.ClassName))return`uint8:${e.valueOf().toNumber()}`;if(t.hasExactClass(n.U16Type.ClassName)||e.hasClassOrSuperclass(n.U16Value.ClassName))return`uint16:${e.valueOf().toNumber()}`;if(t.hasExactClass(n.U32Type.ClassName)||e.hasClassOrSuperclass(n.U32Value.ClassName))return`uint32:${e.valueOf().toNumber()}`;if(t.hasExactClass(n.U64Type.ClassName)||e.hasClassOrSuperclass(n.U64Value.ClassName))return`uint64:${BigInt(e.valueOf().toFixed())}`;if(t.hasExactClass(n.StringType.ClassName)||e.hasClassOrSuperclass(n.StringValue.ClassName))return`string:${e.valueOf()}`;if(t.hasExactClass(n.BooleanType.ClassName)||e.hasClassOrSuperclass(n.BooleanValue.ClassName))return`bool:${e.valueOf()}`;if(t.hasExactClass(n.AddressType.ClassName)||e.hasClassOrSuperclass(n.AddressValue.ClassName))return`address:${e.valueOf().toBech32()}`;if(t.hasExactClass(n.TokenIdentifierType.ClassName)||e.hasClassOrSuperclass(n.TokenIdentifierValue.ClassName))return`token:${e.valueOf()}`;if(t.hasExactClass(n.BytesType.ClassName)||e.hasClassOrSuperclass(n.BytesValue.ClassName))return`hex:${e.valueOf().toString("hex")}`;if(t.hasExactClass(n.CodeMetadataType.ClassName)||e.hasClassOrSuperclass(n.CodeMetadataValue.ClassName))return`codemeta:${e.valueOf().toString()}`;if(t.getName()==="EsdtTokenPayment"){let r=e.getFieldValue("token_identifier").valueOf(),a=e.getFieldValue("token_nonce").valueOf(),s=e.getFieldValue("amount").valueOf();return`asset:${new n.TokenComputer().computeExtendedIdentifier(new n.Token({identifier:r,nonce:BigInt(a)}))}|${s}`}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("composite")){let t=e.match(/\(([^)]+)\)/)?.[1];return new n.CompositeType(...t.split(W.WarpConstants.ArgCompositeSeparator).map(r=>this.nativeToType(r)))}if(e==="string")return new n.StringType;if(e==="uint8")return new n.U8Type;if(e==="uint16")return new n.U16Type;if(e==="uint32")return new n.U32Type;if(e==="uint64")return new n.U64Type;if(e==="biguint")return new n.BigUIntType;if(e==="bool")return new n.BooleanType;if(e==="address")return new n.AddressType;if(e==="token")return new n.TokenIdentifierType;if(e==="hex")return new n.BytesType;if(e==="codemeta")return new n.CodeMetadataType;if(e==="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)]);throw new Error(`WarpArgSerializer (nativeToType): Unsupported input type: ${e}`)}stringToTyped(e){let[t,r]=e.split(/:(.*)/,2);if(t==="null"||t===null)return new n.NothingValue;if(t==="option"){let a=this.stringToTyped(r);return a instanceof n.NothingValue?n.OptionValue.newMissingTyped(a.getType()):n.OptionValue.newProvided(a)}if(t==="optional"){let a=this.stringToTyped(r);return a instanceof n.NothingValue?n.OptionalValue.newMissing():new n.OptionalValue(a.getType(),a)}if(t==="list"){let[a,s]=r.split(be,2),i=s.split(",").map(l=>this.stringToTyped(`${a}:${l}`));return new n.List(this.nativeToType(a),i)}if(t==="variadic"){let[a,s]=r.split(be,2),i=s.split(",").map(l=>this.stringToTyped(`${a}:${l}`));return new n.VariadicValue(new n.VariadicType(this.nativeToType(a)),i)}if(t.startsWith("composite")){let a=t.match(/\(([^)]+)\)/)?.[1],s=r.split(W.WarpConstants.ArgCompositeSeparator),c=a.split(W.WarpConstants.ArgCompositeSeparator),i=s.map((m,f)=>this.stringToTyped(`${c[f]}:${m}`)),l=i.map(m=>m.getType());return new n.CompositeValue(new n.CompositeType(...l),i)}if(t==="string")return r?n.StringValue.fromUTF8(r):new n.NothingValue;if(t==="uint8")return r?new n.U8Value(Number(r)):new n.NothingValue;if(t==="uint16")return r?new n.U16Value(Number(r)):new n.NothingValue;if(t==="uint32")return r?new n.U32Value(Number(r)):new n.NothingValue;if(t==="uint64")return r?new n.U64Value(BigInt(r)):new n.NothingValue;if(t==="biguint")return r?new n.BigUIntValue(BigInt(r)):new n.NothingValue;if(t==="bool")return r?new n.BooleanValue(typeof r=="boolean"?r:r==="true"):new n.NothingValue;if(t==="address")return r?new n.AddressValue(n.Address.newFromBech32(r)):new n.NothingValue;if(t==="token")return r?new n.TokenIdentifierValue(r):new n.NothingValue;if(t==="hex")return r?n.BytesValue.fromHex(r):new n.NothingValue;if(t==="codemeta")return new n.CodeMetadataValue(n.CodeMetadata.newFromBytes(Uint8Array.from(Buffer.from(r,"hex"))));if(t==="asset"){let[a,s]=r.split(W.WarpConstants.ArgCompositeSeparator),c=new n.TokenComputer,i=$(a)?J(a):c.extractIdentifierFromExtendedIdentifier(a),l=$(a)?0n:c.extractNonceFromExtendedIdentifier(a);return new n.Struct(this.nativeToType("asset"),[new n.Field(new n.TokenIdentifierValue(i),"token_identifier"),new n.Field(new n.U64Value(BigInt(l)),"token_nonce"),new n.Field(new n.BigUIntValue(BigInt(s)),"amount")])}throw new Error(`WarpArgSerializer (stringToTyped): Unsupported input type: ${t}`)}typeToString(e){if(e.hasExactClass(n.OptionType.ClassName))return"option:"+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(n.OptionalType.ClassName))return"optional:"+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(n.ListType.ClassName))return"list:"+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(n.VariadicType.ClassName))return"variadic:"+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(n.StringType.ClassName))return"string";if(e.hasExactClass(n.U8Type.ClassName))return"uint8";if(e.hasExactClass(n.U16Type.ClassName))return"uint16";if(e.hasExactClass(n.U32Type.ClassName))return"uint32";if(e.hasExactClass(n.U64Type.ClassName))return"uint64";if(e.hasExactClass(n.BigUIntType.ClassName))return"biguint";if(e.hasExactClass(n.BooleanType.ClassName))return"bool";if(e.hasExactClass(n.AddressType.ClassName))return"address";if(e.hasExactClass(n.TokenIdentifierType.ClassName))return"token";if(e.hasExactClass(n.BytesType.ClassName))return"hex";if(e.hasExactClass(n.CodeMetadataType.ClassName))return"codemeta";if(e.hasExactClass(n.StructType.ClassName)&&e.getClassName()==="EsdtTokenPayment")return"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 P(e,t),this.serializer=new U,this.cache=new y.WarpCache(e.cache?.type)}async getTransactionExecutionResults(e,t){let{actionIndex:r}=(0,y.findWarpExecutableAction)(e),a=this.cache.get(y.WarpCacheKey.WarpExecutable(this.config.env,e.meta?.hash||"",r))??[],s=await this.extractContractResults(e,t,a),c=(0,y.getNextInfo)(this.config,[],e,r,s),i=(0,y.applyResultsToMessages)(e,s.results);return{success:t.status.isSuccessful(),warp:e,action:r,user:(0,y.getWarpWalletAddressFromConfig)(this.config,this.chain.name),txHash:t.hash,tx:t,next:c,values:s.values,valuesRaw:[],results:s.results,messages:i}}async extractContractResults(e,t,r){let{action:a,actionIndex:s}=(0,y.findWarpExecutableAction)(e),c=[],i={};if(!e.results||a.type!=="contract")return{values:c,results:i};if(!Object.values(e.results).some(b=>b.includes("out")||b.includes("event"))){for(let[b,h]of Object.entries(e.results))i[b]=h;return{values:c,results:await(0,y.evaluateResultsCommon)(e,i,s,r,this.config.transform?.runner)}}let m=await this.abi.getAbiForAction(a),f=new G.TransactionEventsParser({abi:m}),T=new G.SmartContractTransactionsOutcomeParser({abi:m}).parseExecute({transactionOnNetwork:t,function:a.func||void 0});for(let[b,h]of Object.entries(e.results)){if(h.startsWith(y.WarpConstants.Transform.Prefix))continue;if(h.startsWith("input.")){i[b]=h;continue}let S=(0,y.parseResultsOutIndex)(h);if(S!==null&&S!==s){i[b]=null;continue}let[E,I,O]=h.split(".");if(E==="event"){if(!I||isNaN(Number(O)))continue;let k=Number(O),C=(0,G.findEventsByFirstTopic)(t,I),j=f.parseEvents({events:C})[0],oe=Object.values(j)[k]||null;c.push(oe),i[b]=oe&&oe.valueOf()}else if(E==="out"||E.startsWith("out[")){if(!I)continue;let k=Number(I),C=T.values[k-1]||null;O&&(C=C[O]||null),C&&typeof C=="object"&&(C="toFixed"in C?C.toFixed():C.valueOf()),c.push(C),i[b]=C&&C.valueOf()}else i[b]=h}return{values:c,results:await(0,y.evaluateResultsCommon)(e,i,s,r)}}async extractQueryResults(e,t,r,a){let s=t.map(m=>this.serializer.typedToString(m)),c=t.map(m=>this.serializer.typedToNative(m)[1]),i={};if(!e.results)return{values:s,valuesRaw:c,results:i};let l=m=>{let f=m.split(".").slice(1).map(T=>parseInt(T)-1);if(f.length===0)return;let d=c[f[0]];for(let T=1;T<f.length;T++){if(d==null)return;d=d[f[T]]}return d};for(let[m,f]of Object.entries(e.results)){if(f.startsWith(y.WarpConstants.Transform.Prefix))continue;let d=(0,y.parseResultsOutIndex)(f);if(d!==null&&d!==r){i[m]=null;continue}f.startsWith("out.")||f==="out"||f.startsWith("out[")?i[m]=l(f)||null:i[m]=f}return{values:s,valuesRaw:c,results:await(0,y.evaluateResultsCommon)(e,i,r,a)}}async resolveWarpResultsRecursively(e){let t=e.warp,r=e.entryActionIndex,a=e.executor,s=e.inputs,c=e.meta,i=new Map,l=new Set,m=this;async function f(h,S=[]){if(i.has(h))return i.get(h);if(l.has(h))throw new Error(`Circular dependency detected at action ${h}`);l.add(h);let E=t.actions[h-1];if(!E)throw new Error(`Action ${h} not found`);let I;if(E.type==="query")I=await a.executeQuery(t,h,S);else if(E.type==="collect")I=await a.executeCollect(t,h,S,c);else throw new Error(`Unsupported or interactive action type: ${E.type}`);if(i.set(h,I),t.results)for(let O of Object.values(t.results)){let C=String(O).match(/^out\[(\d+)\]/);if(C){let j=parseInt(C[1],10);j!==h&&!i.has(j)&&await f(j)}}return l.delete(h),I}await f(r,s);let d={};for(let h of i.values())for(let[S,E]of Object.entries(h.results))E!==null?d[S]=E:S in d||(d[S]=null);let T=await(0,y.evaluateResultsCommon)(t,d,r,s,this.config.transform?.runner);return{...i.get(r),action:r,results:T}}};var Ue="EGLD-000000",te=class{constructor(e,t){this.config=e;this.chain=t;this.serializer=new U,this.abi=new P(this.config,this.chain),this.results=new K(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=g.Address.newFromBech32(t),a=new g.TransactionsFactoryConfig({chainID:e.chain.chainId}),s=e.data?Buffer.from(this.serializer.stringToTyped(e.data).valueOf()):null;return new g.TransferTransactionsFactory({config:a}).createTransactionForTransfer(r,{receiver:g.Address.newFromBech32(e.destination),nativeAmount:e.value,tokenTransfers: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=g.Address.newFromBech32(t),s=e.args.map(i=>this.serializer.stringToTyped(i)),c=new g.TransactionsFactoryConfig({chainID:e.chain.chainId});return new g.SmartContractTransactionsFactory({config:c}).createTransactionForExecute(a,{contract:g.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(k=>this.serializer.stringToTyped(k)),s=w(e.chain,this.config.env,this.config),c=g.Address.newFromBech32(e.destination),i=s.createSmartContractController(r),l=i.createQuery({contract:c,function:t.func||"",arguments:a}),m=await i.runQuery(l),f=m.returnCode==="ok",d=new g.ArgSerializer,T=r.getEndpoint(m.function||t.func||""),b=(m.returnDataParts||[]).map(k=>Buffer.from(k)),h=d.buffersToValues(b,T.output),{values:S,valuesRaw:E,results:I}=await this.results.extractQueryResults(e.warp,h,e.action,e.resolvedInputs),O=(0,N.getNextInfo)(this.config,[],e.warp,e.action,I);return{success:f,warp:e.warp,action:e.action,user:(0,N.getWarpWalletAddressFromConfig)(this.config,e.chain.name),txHash:null,tx:null,next:O,values:S,valuesRaw:E,results:I,messages:(0,N.applyResultsToMessages)(e.warp,I)}}async signMessage(e,t){let r=g.UserSecretKey.fromString(t);return(await new g.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:Ue}:t).map(t=>{let a=new g.TokenComputer().extractNonceFromExtendedIdentifier(t.identifier);return new g.TokenTransfer({token:new g.Token({identifier:t.identifier,nonce:BigInt(a||0)}),amount:t.amount})})}};var Re={Egld:{Identifier:"EGLD",EsdtIdentifier:"EGLD-000000",DisplayName:"eGold",Decimals:18}},Ee=(r=>(r.MultiversxExplorer="multiversx_explorer",r.MultiversxExplorerDevnet="multiversx_explorer_devnet",r.MultiversxExplorerTestnet="multiversx_explorer_testnet",r))(Ee||{}),Ie=(r=>(r.VibechainExplorer="vibechain_explorer",r.VibechainExplorerDevnet="vibechain_explorer_devnet",r.VibechainExplorerTestnet="vibechain_explorer_testnet",r))(Ie||{}),fe={multiversx:{mainnet:["multiversx_explorer"],testnet:["multiversx_explorer_testnet"],devnet:["multiversx_explorer_devnet"]},vibechain:{mainnet:["vibechain_explorer"],testnet:["vibechain_explorer_testnet"],devnet:["vibechain_explorer_devnet"]}},_={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 re=class{constructor(e,t){this.chain=e;this.config=t}getExplorers(){let e=fe[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=_[t];if(s)return s}if(e){let s=_[e];if(s)return s}let r=this.getPrimaryExplorer();return _[r]||_[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=_[a];s&&(r[a]=`${s}/accounts/${e}`)}),r}getTransactionUrls(e){let t=this.getAllExplorers(),r={};return t.forEach(a=>{let s=_[a];s&&(r[a]=`${s}/transactions/${e}`)}),r}};var u=require("@multiversx/sdk-core"),V=require("@vleap/warps");var he={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 v=o=>{if(o==="devnet")return"erd1qqqqqqqqqqqqqpgqje2f99vr6r7sk54thg03c9suzcvwr4nfl3tsfkdl36";if(o==="testnet")throw new Error("Multiversx testnet is not supported");return"erd1qqqqqqqqqqqqqpgq3mrpj3u6q7tejv6d7eqhnyd27n9v5c5tl3ts08mffe"};var ne=o=>({hash:o.hash.toString("hex"),alias:o.alias?.toString()||null,trust:o.trust.toString(),owner:o.owner.toString(),createdAt:o.created_at.toNumber(),upgradedAt:o.upgraded_at?.toNumber(),brand:o.brand?.toString("hex")||null,upgrade:o.upgrade?.toString("hex")||null}),ge=o=>({unitPrice:BigInt(o.unit_price.toString()),admins:o.admins.map(e=>e.toBech32())});var ae=class{constructor(e,t){this.config=e;this.chain=t;this.cache=new V.WarpCache(e.cache?.type),this.registryConfig={unitPrice:BigInt(0),admins:[]},this.userWallet=(0,V.getWarpWalletAddressFromConfig)(this.config,this.chain.name)}async init(){await this.loadRegistryConfigs()}getRegistryConfig(){return this.registryConfig}async createWarpRegisterTransaction(e,t,r){if(this.registryConfig.unitPrice===BigInt(0))throw new Error("WarpRegistry: config not loaded. forgot to call init()?");if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let 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(v(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(v(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(v(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(v(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(v(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(v(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(v(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(v(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=V.WarpCacheKey.RegistryInfo(this.config.env,e),a=t?this.cache.get(r):null;if(a)return V.WarpLogger.info(`WarpRegistry (getInfoByAlias): RegistryInfo found in cache: ${e}`),a;let s=u.Address.newFromBech32(v(this.config.env)),c=this.getController(),i=c.createQuery({contract:s,function:"getInfoByAlias",arguments:[u.BytesValue.fromUTF8(e)]}),l=await c.runQuery(i),[m]=c.parseQueryResponse(l),f=m?ne(m):null,d=f?.brand?await this.fetchBrand(f.brand):null;return t&&t.ttl&&this.cache.set(r,{registryInfo:f,brand:d},t.ttl),{registryInfo:f,brand:d}}catch{return{registryInfo:null,brand:null}}}async getInfoByHash(e,t){try{let r=V.WarpCacheKey.RegistryInfo(this.config.env,e);if(t){let d=this.cache.get(r);if(d)return V.WarpLogger.info(`WarpRegistry (getInfoByHash): RegistryInfo found in cache: ${e}`),d}let a=u.Address.newFromBech32(v(this.config.env)),s=this.getController(),c=s.createQuery({contract:a,function:"getInfoByHash",arguments:[u.BytesValue.fromHex(e)]}),i=await s.runQuery(c),[l]=s.parseQueryResponse(i),m=l?ne(l):null,f=m?.brand?await this.fetchBrand(m.brand):null;return t&&t.ttl&&this.cache.set(r,{registryInfo:m,brand:f},t.ttl),{registryInfo:m,brand:f}}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(v(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),[i]=a.parseQueryResponse(c);return i.map(ne)}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(v(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),[i]=a.parseQueryResponse(c),l=i.map(d=>d.toString("hex")),m={ttl:365*24*60*60};return(await Promise.all(l.map(d=>this.fetchBrand(d,m)))).filter(d=>d!==null)}catch{return[]}}async fetchBrand(e,t){let r=V.WarpCacheKey.Brand(this.config.env,e),a=t?this.cache.get(r):null;if(a)return V.WarpLogger.info(`WarpRegistry (fetchBrand): Brand found in cache: ${e}`),a;let c=w(this.chain,this.config.env,this.config).createNetworkProvider();try{let i=await c.getTransaction(e),l=JSON.parse(i.data.toString());return l.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,l,t.ttl),l}catch{return null}}async loadRegistryConfigs(){let e=u.Address.newFromBech32(v(this.config.env)),t=this.getController(),[r]=await t.query({contract:e,function:"getConfig",arguments:[]}),a=r?ge(r):null;this.registryConfig=a||{unitPrice:BigInt(0),admins:[]}}getFactory(){let e=new u.TransactionsFactoryConfig({chainID:this.chain.chainId}),t=u.AbiRegistry.create(he);return new u.SmartContractTransactionsFactory({config:e,abi:t})}getController(){let e=w(this.chain,this.config.env,this.config),t=u.AbiRegistry.create(he);return e.createSmartContractController(t)}isCurrentUserAdmin(){return!!this.userWallet&&this.registryConfig.admins.includes(this.userWallet)}};var x=require("@multiversx/sdk-core"),R=require("@vleap/warps");var se=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 R.WarpCache(e.cache?.type)}async signTransaction(e){if(!e||typeof e!="object")throw new Error("Invalid transaction object");let t=(0,R.getWarpWalletPrivateKeyFromConfig)(this.config,this.chain.name);if(!t)throw new Error("Wallet not initialized - no private key provided");console.log("privateKey",t);let r=t.startsWith("-----");console.log("isPrivateKeyPem",r);let a=r?x.UserSecretKey.fromPem(t):x.UserSecretKey.fromString(t),s=new x.UserSigner(a),c=new x.Account(a),i=(await this.provider.getAccount(c.address)).nonce,l=this.cache.get(`nonce:${c.address.toBech32()}`)||0;c.nonce=BigInt(Math.max(l,Number(i))),e.nonce=c.getNonceThenIncrement();let f=new x.TransactionComputer().computeBytesForSigning(e);return e.signature=await s.sign(f),this.cache.set(`nonce:${c.address.toBech32()}`,Number(c.nonce),R.CacheTtl.OneHour),e}async signMessage(e){let t=(0,R.getWarpWalletPrivateKeyFromConfig)(this.config,this.chain.name);if(!t)throw new Error("Wallet not initialized - no private key provided");let a=t.startsWith("-----")?x.UserSecretKey.fromPem(t):x.UserSecretKey.fromString(t),s=new x.UserSigner(a),c=new TextEncoder().encode(e),i=await s.sign(c);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=x.Mnemonic.fromString(e).deriveKey(0),a=r.hex();return{address:r.generatePublicKey().toAddress(this.chain.addressHrp).toBech32(),privateKey:a,mnemonic:e}}generate(){let e=x.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,R.getWarpWalletAddressFromConfig)(this.config,this.chain.name)}};var ie=(o,e,t)=>(r,a)=>{let s=t[r.env];return{chain:o,chainInfo:s,prefix:e,builder:()=>new Z(r,s),executor:new te(r,s),results:new K(r,s),serializer:new U,registry:new ae(r,s),explorer:new re(o,r),abiBuilder:()=>new P(r,s),brandBuilder:()=>new Y(r,s),dataLoader:new ee(r,s),wallet:new se(r,s),registerTypes:c=>{c.registerType("token",{stringToNative:i=>i,nativeToString:i=>`token:${i}`}),c.registerType("codemeta",{stringToNative:i=>i,nativeToString:i=>`codemeta:${i}`})}}};var pe={chain:Q.WarpChainName.Multiversx,identifier:"EGLD",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://vleap.ai/images/tokens/egld.svg"},ye=ie(Q.WarpChainName.Multiversx,"multiversx",{mainnet:{name:Q.WarpChainName.Multiversx,displayName:"MultiversX",chainId:"1",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://api.multiversx.com",logoUrl:"https://vleap.ai/images/chains/multiversx.svg",nativeToken:pe},testnet:{name:Q.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:pe},devnet:{name:Q.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:pe}});var le=require("@vleap/warps");var Be={chain:le.WarpChainName.Vibechain,identifier:"VIBE",name:"VIBE",symbol:"VIBE",decimals:18,logoUrl:"https://vleap.ai/images/tokens/vibe.svg"},we={name:le.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:Be},Ce=ie(le.WarpChainName.Vibechain,"vibe",{mainnet:we,testnet:we,devnet:we});var Me=(o,e)=>[ye(o,e),Ce(o,e)],_e=()=>[We.WarpChainName.Multiversx,We.WarpChainName.Vibechain];var p=require("@multiversx/sdk-core"),$e=(o,e)=>o?p.OptionValue.newProvided(o):e?p.OptionValue.newMissingTyped(e):p.OptionValue.newMissing(),Le=(o,e)=>o?new p.OptionalValue(o.getType(),o):e?new p.OptionalValue(e):p.OptionalValue.newMissing(),De=o=>{if(o.length===0)throw new Error("Cannot create a list from an empty array");let e=o[0].getType();return new p.List(e,o)},Ke=o=>p.VariadicValue.fromItems(...o),qe=o=>{let e=o.map(t=>t.getType());return new p.CompositeValue(new p.CompositeType(...e),o)},ze=o=>p.StringValue.fromUTF8(o),He=o=>new p.U8Value(o),Ge=o=>new p.U16Value(o),Qe=o=>new p.U32Value(o),je=o=>new p.U64Value(o),Je=o=>new p.BigUIntValue(BigInt(o)),Xe=o=>new p.BooleanValue(o),Ye=o=>new p.AddressValue(p.Address.newFromBech32(o)),Ze=o=>new p.TokenIdentifierValue(o),et=o=>p.BytesValue.fromHex(o),tt=o=>new p.Struct(new p.StructType("EsdtTokenPayment",[new p.FieldDefinition("token_identifier","",new p.TokenIdentifierType),new p.FieldDefinition("token_nonce","",new p.U64Type),new p.FieldDefinition("amount","",new p.BigUIntType)]),[new p.Field(new p.TokenIdentifierValue(o.token.identifier),"token_identifier"),new p.Field(new p.U64Value(BigInt(o.token.nonce)),"token_nonce"),new p.Field(new p.BigUIntValue(BigInt(o.amount)),"amount")]),rt=o=>new p.CodeMetadataValue(p.CodeMetadata.newFromBytes(Uint8Array.from(Buffer.from(o,"hex")))),nt=()=>new p.NothingValue;0&&(module.exports={ExplorerUrls,KnownTokens,MultiversxExplorers,MultiversxExplorersConfig,NativeTokenEgld,NativeTokenVibe,VibechainExplorers,WarpMultiversxAbiBuilder,WarpMultiversxBrandBuilder,WarpMultiversxBuilder,WarpMultiversxConstants,WarpMultiversxContractLoader,WarpMultiversxDataLoader,WarpMultiversxExecutor,WarpMultiversxExplorer,WarpMultiversxRegistry,WarpMultiversxResults,WarpMultiversxSerializer,WarpMultiversxWallet,address_value,asset_value,biguint_value,boolean_value,codemeta_value,composite_value,createMultiversxAdapter,findKnownTokenById,getAllMultiversxAdapters,getAllMultiversxChainNames,getMultiversxAdapter,getMultiversxEntrypoint,getMultiversxRegistryAddress,getNormalizedTokenIdentifier,getVibechainAdapter,hex_value,isNativeToken,list_value,nothing_value,option_value,optional_value,string_value,toTypedConfigInfo,toTypedRegistryInfo,token_value,u16_value,u32_value,u64_value,u8_value,variadic_value});
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{WarpChainName as mt}from"@vleap/warps";import{WarpChainName as P}from"@vleap/warps";import{AbiRegistry as Y,Address as Wt,TransactionsFactoryConfig as vt,TransferTransactionsFactory as xt}from"@multiversx/sdk-core";import{getLatestProtocolIdentifier as Tt,getWarpWalletAddressFromConfig as At,WarpCache as bt,WarpCacheKey as Et,WarpConstants as Se,WarpLogger as Fe}from"@vleap/warps";import{DevnetEntrypoint as gt,MainnetEntrypoint as yt,TestnetEntrypoint as wt}from"@multiversx/sdk-core";import{getProviderUrl as Ct}from"@vleap/warps";var V=i=>!i.includes("-"),R=i=>V(i)?`${i}-000000`:i,h=(i,e,t)=>{let r="warp-sdk",a=t?Ct(t,i.name,e,i.defaultApiUrl):i.defaultApiUrl;return e==="devnet"?new gt({url:a,kind:"api",clientName:r}):e==="testnet"?new wt({url:a,kind:"api",clientName:r}):new yt({url:a,kind:"api",clientName:r})};import{WarpLogger as Ve}from"@vleap/warps";var O=class{constructor(e){this.config=e}async getContract(e,t){try{let a=await h(t,this.config.env,this.config).createNetworkProvider().doGetGeneric(`accounts/${e}`);return{address:e,owner:a.ownerAddress,verified:a.isVerified||!1}}catch(r){return Ve.error("WarpContractLoader: getContract error",r),null}}async getVerificationInfo(e,t){try{let a=await h(t,this.config.env,this.config).createNetworkProvider().doGetGeneric(`accounts/${e}/verification`);return{codeHash:a.codeHash,abi:a.source.abi}}catch(r){return Ve.error("WarpContractLoader: getVerificationInfo error",r),null}}};var I=class{constructor(e,t){this.config=e;this.chain=t;this.contractLoader=new O(this.config),this.cache=new bt(this.config.cache?.type)}async createInscriptionTransaction(e){let t=At(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 xt({config:r}),a=Wt.newFromBech32(t),o={protocol:Tt("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=Et.WarpAbi(this.config.env,e);if(t){let o=this.cache.get(r);if(o)return Fe.info(`WarpAbiBuilder (createFromTransactionHash): Warp abi found in cache: ${e}`),o}let a=h(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 Fe.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 Y.create(t.abi)}async fetchAbi(e){if(!e.abi)throw new Error("WarpActionExecutor: ABI not found");if(e.abi.startsWith(Se.IdentifierType.Hash)){let t=e.abi.split(Se.ArgParamsSeparator)[1],r=await this.createFromTransactionHash(t);if(!r)throw new Error(`WarpActionExecutor: ABI not found for hash: ${e.abi}`);return Y.create(r.content)}else{let r=await(await fetch(e.abi)).json();return Y.create(r)}}};import{Address as ke,TransactionsFactoryConfig as It,TransferTransactionsFactory as Bt}from"@multiversx/sdk-core";import{getWarpWalletAddressFromConfig as Nt,WarpBrandBuilder as Vt,WarpLogger as St}from"@vleap/warps";import{Buffer as Ft}from"buffer";var M=class{constructor(e,t){this.config=e;this.chain=t;this.core=new Vt(e)}async createInscriptionTransaction(e){let t=Nt(this.config,this.chain.name);if(!t)throw new Error("BrandBuilder: user address not set");let r=new It({chainID:this.chain.chainId}),n=new Bt({config:r}),a=ke.newFromBech32(t),o=JSON.stringify(e);return await n.createTransactionForNativeTokenTransfer(a,{receiver:ke.newFromBech32(t),nativeAmount:BigInt(0),data:Uint8Array.from(Ft.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=h(this.chain,this.config.env,this.config).createNetworkProvider();try{let n=await r.getTransaction(e);return this.createFromTransaction(n)}catch(n){return St.error("BrandBuilder: Error creating from transaction hash",n),null}}};import{Address as Pe,TransactionsFactoryConfig as kt,TransferTransactionsFactory as Pt}from"@multiversx/sdk-core";import{getWarpWalletAddressFromConfig as Ut,WarpBuilder as Ue,WarpCache as Rt,WarpCacheKey as Ot,WarpLogger as Re}from"@vleap/warps";var _=class extends Ue{constructor(t,r){super(t);this.config=t;this.chain=r;this.cache=new Rt(t.cache?.type),this.core=new Ue(t)}async createInscriptionTransaction(t){let r=Ut(this.config,this.chain.name);if(!r)throw new Error("WarpBuilder: user address not set");let n=new kt({chainID:this.chain.chainId}),a=new Pt({config:n}),o=Pe.newFromBech32(r),s=JSON.stringify(t),c=await a.createTransactionForTransfer(o,{receiver:Pe.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=Ot.Warp(this.config.env,t);if(r){let s=this.cache.get(n);if(s)return Re.info(`WarpBuilder (createFromTransactionHash): Warp found in cache: ${t}`),s}let o=h(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 Re.error("WarpBuilder: Error creating from transaction hash",s),null}}};import{Address as Z,Token as $t,TokenComputer as Lt}from"@multiversx/sdk-core";import{CacheTtl as Dt,WarpCache as qt,WarpCacheKey as Ht}from"@vleap/warps";import{WarpChainName as Mt}from"@vleap/warps";var $=Mt.Multiversx,_t=[{chain:$,identifier:"EGLD",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.pngsvg"},{chain:$,identifier:"EGLD-000000",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"},{chain:$,identifier:"VIBE",name:"VIBE",symbol:"VIBE",decimals:18,logoUrl:"https://vleap.ai/images/tokens/vibe.svg"},{chain:$,identifier:"VIBE-000000",name:"VIBE",symbol:"VIBE",decimals:18,logoUrl:"https://vleap.ai/images/tokens/vibe.svg"}],Oe=i=>_t.find(e=>e.identifier===i)||null;var L=class{constructor(e,t){this.config=e;this.chain=t;this.cache=new qt(e.cache?.type)}async getAccount(e){let r=await h(this.chain,this.config.env,this.config).createNetworkProvider().getAccount(Z.newFromBech32(e));return{chain:this.chain.name,address:r.address.toBech32(),balance:r.balance}}async getAccountAssets(e){let t=h(this.chain,this.config.env,this.config).createNetworkProvider(),r=t.getAccount(Z.newFromBech32(e)),n=t.getFungibleTokensOfAccount(Z.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=Ht.Asset(this.config.env,this.chain.name,e),r=this.cache.get(t);if(r)return r;let n=Oe(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 Lt,o=V(e)?0n:a.extractNonceFromExtendedIdentifier(e),s=new $t({identifier:e,nonce:BigInt(o||0)}),c=a.isFungible(s),p=h(this.chain,this.config.env,this.config).createNetworkProvider(),u=R(e),l=await p.doGetGeneric(`tokens/${u}`),y={chain:this.chain.name,identifier:s.identifier,name:l.name,symbol:l.ticker,amount:0n,decimals:l.decimals,logoUrl:l.assets?.pngUrl||"#",price:l.price?Number(l.price):void 0,supply:l.supply?BigInt(l.supply):void 0};return this.cache.set(t,y,Dt.OneHour),y}async getAction(e,t=!1){let r=h(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=h(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 p=s*o;a.append("from",p.toString())}return o!==25&&a.append("size",o.toString()),a.toString()&&(n+=`?${a.toString()}`),(await r.doGetGeneric(n)).map(p=>({chain:this.chain.name,id:p.txHash,receiver:p.receiver,sender:p.sender,value:p.value,function:p.function,status:this.toActionStatus(p),createdAt:this.toActionCreatedAt(p)}))}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 k,ArgSerializer as ar,SmartContractTransactionsFactory as sr,Token as ir,TokenComputer as or,TokenTransfer as cr,TransactionsFactoryConfig as at,TransferTransactionsFactory as pr,UserSecretKey as lr,UserSigner as ur}from"@multiversx/sdk-core";import{applyResultsToMessages as mr,getNextInfo as dr,getWarpActionByIndex as ye,getWarpWalletAddressFromConfig as we}from"@vleap/warps";import{findEventsByFirstTopic as Jt,SmartContractTransactionsOutcomeParser as Xt,TransactionEventsParser as Yt}from"@multiversx/sdk-core";import{applyResultsToMessages as Zt,evaluateResultsCommon as z,findWarpExecutableAction as tt,getNextInfo as er,getWarpWalletAddressFromConfig as tr,parseResultsOutIndex as rt,WarpCache as rr,WarpCacheKey as nr,WarpConstants as nt}from"@vleap/warps";import{Address as zt,AddressType as ee,AddressValue as Me,BigUIntType as D,BigUIntValue as te,BooleanType as re,BooleanValue as _e,BytesType as ne,BytesValue as $e,CodeMetadata as Kt,CodeMetadataType as ae,CodeMetadataValue as Le,CompositeType as se,CompositeValue as De,Field as ie,FieldDefinition as oe,List as qe,ListType as He,NothingValue as x,OptionalType as ze,OptionalValue as ce,OptionType as Ke,OptionValue as pe,StringType as le,StringValue as Ge,Struct as Gt,StructType as Qe,Token as Qt,TokenComputer as je,TokenIdentifierType as q,TokenIdentifierValue as ue,U16Type as me,U16Value as Je,U32Type as de,U32Value as Xe,U64Type as H,U64Value as he,U8Type as fe,U8Value as Ye,VariadicType as ge,VariadicValue as Ze}from"@multiversx/sdk-core";import{WarpConstants as T,WarpSerializer as jt}from"@vleap/warps";var et=new RegExp(`${T.ArgParamsSeparator}(.*)`),B=class{constructor(){this.coreSerializer=new jt}typedToString(e){let t=e.getType();if(t.hasExactClass(Ke.ClassName)||e.hasClassOrSuperclass(pe.ClassName))return e.isSet()?`option:${this.typedToString(e.getTypedValue())}`:"option:null";if(t.hasExactClass(ze.ClassName)||e.hasClassOrSuperclass(ce.ClassName))return e.isSet()?`optional:${this.typedToString(e.getTypedValue())}`:"optional:null";if(t.hasExactClass(He.ClassName)||e.hasClassOrSuperclass(qe.ClassName)){let r=e.getItems(),a=r.map(s=>this.typedToString(s).split(T.ArgParamsSeparator)[0])[0],o=r.map(s=>this.typedToString(s).split(T.ArgParamsSeparator)[1]);return`list:${a}:${o.join(",")}`}if(t.hasExactClass(ge.ClassName)||e.hasClassOrSuperclass(Ze.ClassName)){let r=e.getItems(),a=r.map(s=>this.typedToString(s).split(T.ArgParamsSeparator)[0])[0],o=r.map(s=>this.typedToString(s).split(T.ArgParamsSeparator)[1]);return`variadic:${a}:${o.join(",")}`}if(t.hasExactClass(se.ClassName)||e.hasClassOrSuperclass(De.ClassName)){let r=e.getItems(),n=r.map(c=>this.typedToString(c).split(T.ArgParamsSeparator)[0]),a=r.map(c=>this.typedToString(c).split(T.ArgParamsSeparator)[1]),o=n.join(T.ArgCompositeSeparator),s=a.join(T.ArgCompositeSeparator);return`composite(${o}):${s}`}if(t.hasExactClass(D.ClassName)||e.hasClassOrSuperclass(te.ClassName)||t.getName()==="BigUint")return`biguint:${BigInt(e.valueOf().toFixed())}`;if(t.hasExactClass(fe.ClassName)||e.hasClassOrSuperclass(Ye.ClassName))return`uint8:${e.valueOf().toNumber()}`;if(t.hasExactClass(me.ClassName)||e.hasClassOrSuperclass(Je.ClassName))return`uint16:${e.valueOf().toNumber()}`;if(t.hasExactClass(de.ClassName)||e.hasClassOrSuperclass(Xe.ClassName))return`uint32:${e.valueOf().toNumber()}`;if(t.hasExactClass(H.ClassName)||e.hasClassOrSuperclass(he.ClassName))return`uint64:${BigInt(e.valueOf().toFixed())}`;if(t.hasExactClass(le.ClassName)||e.hasClassOrSuperclass(Ge.ClassName))return`string:${e.valueOf()}`;if(t.hasExactClass(re.ClassName)||e.hasClassOrSuperclass(_e.ClassName))return`bool:${e.valueOf()}`;if(t.hasExactClass(ee.ClassName)||e.hasClassOrSuperclass(Me.ClassName))return`address:${e.valueOf().toBech32()}`;if(t.hasExactClass(q.ClassName)||e.hasClassOrSuperclass(ue.ClassName))return`token:${e.valueOf()}`;if(t.hasExactClass(ne.ClassName)||e.hasClassOrSuperclass($e.ClassName))return`hex:${e.valueOf().toString("hex")}`;if(t.hasExactClass(ae.ClassName)||e.hasClassOrSuperclass(Le.ClassName))return`codemeta:${e.valueOf().toString()}`;if(t.getName()==="EsdtTokenPayment"){let r=e.getFieldValue("token_identifier").valueOf(),n=e.getFieldValue("token_nonce").valueOf(),a=e.getFieldValue("amount").valueOf();return`asset:${new je().computeExtendedIdentifier(new Qt({identifier:r,nonce:BigInt(n)}))}|${a}`}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("composite")){let t=e.match(/\(([^)]+)\)/)?.[1];return new se(...t.split(T.ArgCompositeSeparator).map(r=>this.nativeToType(r)))}if(e==="string")return new le;if(e==="uint8")return new fe;if(e==="uint16")return new me;if(e==="uint32")return new de;if(e==="uint64")return new H;if(e==="biguint")return new D;if(e==="bool")return new re;if(e==="address")return new ee;if(e==="token")return new q;if(e==="hex")return new ne;if(e==="codemeta")return new ae;if(e==="asset")return new Qe("EsdtTokenPayment",[new oe("token_identifier","",new q),new oe("token_nonce","",new H),new oe("amount","",new D)]);throw new Error(`WarpArgSerializer (nativeToType): Unsupported input type: ${e}`)}stringToTyped(e){let[t,r]=e.split(/:(.*)/,2);if(t==="null"||t===null)return new x;if(t==="option"){let n=this.stringToTyped(r);return n instanceof x?pe.newMissingTyped(n.getType()):pe.newProvided(n)}if(t==="optional"){let n=this.stringToTyped(r);return n instanceof x?ce.newMissing():new ce(n.getType(),n)}if(t==="list"){let[n,a]=r.split(et,2),s=a.split(",").map(c=>this.stringToTyped(`${n}:${c}`));return new qe(this.nativeToType(n),s)}if(t==="variadic"){let[n,a]=r.split(et,2),s=a.split(",").map(c=>this.stringToTyped(`${n}:${c}`));return new Ze(new ge(this.nativeToType(n)),s)}if(t.startsWith("composite")){let n=t.match(/\(([^)]+)\)/)?.[1],a=r.split(T.ArgCompositeSeparator),o=n.split(T.ArgCompositeSeparator),s=a.map((p,u)=>this.stringToTyped(`${o[u]}:${p}`)),c=s.map(p=>p.getType());return new De(new se(...c),s)}if(t==="string")return r?Ge.fromUTF8(r):new x;if(t==="uint8")return r?new Ye(Number(r)):new x;if(t==="uint16")return r?new Je(Number(r)):new x;if(t==="uint32")return r?new Xe(Number(r)):new x;if(t==="uint64")return r?new he(BigInt(r)):new x;if(t==="biguint")return r?new te(BigInt(r)):new x;if(t==="bool")return r?new _e(typeof r=="boolean"?r:r==="true"):new x;if(t==="address")return r?new Me(zt.newFromBech32(r)):new x;if(t==="token")return r?new ue(r):new x;if(t==="hex")return r?$e.fromHex(r):new x;if(t==="codemeta")return new Le(Kt.newFromBytes(Uint8Array.from(Buffer.from(r,"hex"))));if(t==="asset"){let[n,a]=r.split(T.ArgCompositeSeparator),o=new je,s=V(n)?R(n):o.extractIdentifierFromExtendedIdentifier(n),c=V(n)?0n:o.extractNonceFromExtendedIdentifier(n);return new Gt(this.nativeToType("asset"),[new ie(new ue(s),"token_identifier"),new ie(new he(BigInt(c)),"token_nonce"),new ie(new te(BigInt(a)),"amount")])}throw new Error(`WarpArgSerializer (stringToTyped): Unsupported input type: ${t}`)}typeToString(e){if(e.hasExactClass(Ke.ClassName))return"option:"+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(ze.ClassName))return"optional:"+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(He.ClassName))return"list:"+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(ge.ClassName))return"variadic:"+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(le.ClassName))return"string";if(e.hasExactClass(fe.ClassName))return"uint8";if(e.hasExactClass(me.ClassName))return"uint16";if(e.hasExactClass(de.ClassName))return"uint32";if(e.hasExactClass(H.ClassName))return"uint64";if(e.hasExactClass(D.ClassName))return"biguint";if(e.hasExactClass(re.ClassName))return"bool";if(e.hasExactClass(ee.ClassName))return"address";if(e.hasExactClass(q.ClassName))return"token";if(e.hasExactClass(ne.ClassName))return"hex";if(e.hasExactClass(ae.ClassName))return"codemeta";if(e.hasExactClass(Qe.ClassName)&&e.getClassName()==="EsdtTokenPayment")return"asset";throw new Error(`WarpArgSerializer (typeToString): Unsupported input type: ${e.getClassName()}`)}};var S=class{constructor(e,t){this.config=e;this.chain=t;this.abi=new I(e,t),this.serializer=new B,this.cache=new rr(e.cache?.type)}async getTransactionExecutionResults(e,t){let{actionIndex:r}=tt(e),n=this.cache.get(nr.WarpExecutable(this.config.env,e.meta?.hash||"",r))??[],a=await this.extractContractResults(e,t,n),o=er(this.config,[],e,r,a),s=Zt(e,a.results);return{success:t.status.isSuccessful(),warp:e,action:r,user:tr(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}=tt(e),o=[],s={};if(!e.results||n.type!=="contract")return{values:o,results:s};if(!Object.values(e.results).some(C=>C.includes("out")||C.includes("event"))){for(let[C,m]of Object.entries(e.results))s[C]=m;return{values:o,results:await z(e,s,a,r,this.config.transform?.runner)}}let p=await this.abi.getAbiForAction(n),u=new Yt({abi:p}),y=new Xt({abi:p}).parseExecute({transactionOnNetwork:t,function:n.func||void 0});for(let[C,m]of Object.entries(e.results)){if(m.startsWith(nt.Transform.Prefix))continue;if(m.startsWith("input.")){s[C]=m;continue}let A=rt(m);if(A!==null&&A!==a){s[C]=null;continue}let[W,v,E]=m.split(".");if(W==="event"){if(!v||isNaN(Number(E)))continue;let b=Number(E),g=Jt(t,v),F=u.parseEvents({events:g})[0],U=Object.values(F)[b]||null;o.push(U),s[C]=U&&U.valueOf()}else if(W==="out"||W.startsWith("out[")){if(!v)continue;let b=Number(v),g=y.values[b-1]||null;E&&(g=g[E]||null),g&&typeof g=="object"&&(g="toFixed"in g?g.toFixed():g.valueOf()),o.push(g),s[C]=g&&g.valueOf()}else s[C]=m}return{values:o,results:await z(e,s,a,r)}}async extractQueryResults(e,t,r,n){let a=t.map(p=>this.serializer.typedToString(p)),o=t.map(p=>this.serializer.typedToNative(p)[1]),s={};if(!e.results)return{values:a,valuesRaw:o,results:s};let c=p=>{let u=p.split(".").slice(1).map(y=>parseInt(y)-1);if(u.length===0)return;let l=o[u[0]];for(let y=1;y<u.length;y++){if(l==null)return;l=l[u[y]]}return l};for(let[p,u]of Object.entries(e.results)){if(u.startsWith(nt.Transform.Prefix))continue;let l=rt(u);if(l!==null&&l!==r){s[p]=null;continue}u.startsWith("out.")||u==="out"||u.startsWith("out[")?s[p]=c(u)||null:s[p]=u}return{values:a,valuesRaw:o,results:await z(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,p=this;async function u(m,A=[]){if(s.has(m))return s.get(m);if(c.has(m))throw new Error(`Circular dependency detected at action ${m}`);c.add(m);let W=t.actions[m-1];if(!W)throw new Error(`Action ${m} not found`);let v;if(W.type==="query")v=await n.executeQuery(t,m,A);else if(W.type==="collect")v=await n.executeCollect(t,m,A,o);else throw new Error(`Unsupported or interactive action type: ${W.type}`);if(s.set(m,v),t.results)for(let E of Object.values(t.results)){let g=String(E).match(/^out\[(\d+)\]/);if(g){let F=parseInt(g[1],10);F!==m&&!s.has(F)&&await u(F)}}return c.delete(m),v}await u(r,a);let l={};for(let m of s.values())for(let[A,W]of Object.entries(m.results))W!==null?l[A]=W:A in l||(l[A]=null);let y=await z(t,l,r,a,this.config.transform?.runner);return{...s.get(r),action:r,results:y}}};var hr="EGLD-000000",K=class{constructor(e,t){this.config=e;this.chain=t;this.serializer=new B,this.abi=new I(this.config,this.chain),this.results=new S(this.config,this.chain)}async createTransaction(e){let t=ye(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=we(this.config,e.chain.name);if(!t)throw new Error("WarpMultiversxExecutor: createTransfer - user address not set");let r=k.newFromBech32(t),n=new at({chainID:e.chain.chainId}),a=e.data?Buffer.from(this.serializer.stringToTyped(e.data).valueOf()):null;return new pr({config:n}).createTransactionForTransfer(r,{receiver:k.newFromBech32(e.destination),nativeAmount:e.value,tokenTransfers:this.toTokenTransfers(e.transfers),data:a?new Uint8Array(a):void 0})}async createContractCallTransaction(e){let t=we(this.config,e.chain.name);if(!t)throw new Error("WarpMultiversxExecutor: createContractCall - user address not set");let r=ye(e.warp,e.action),n=k.newFromBech32(t),a=e.args.map(s=>this.serializer.stringToTyped(s)),o=new at({chainID:e.chain.chainId});return new sr({config:o}).createTransactionForExecute(n,{contract:k.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=ye(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=h(e.chain,this.config.env,this.config),o=k.newFromBech32(e.destination),s=a.createSmartContractController(r),c=s.createQuery({contract:o,function:t.func||"",arguments:n}),p=await s.runQuery(c),u=p.returnCode==="ok",l=new ar,y=r.getEndpoint(p.function||t.func||""),C=(p.returnDataParts||[]).map(b=>Buffer.from(b)),m=l.buffersToValues(C,y.output),{values:A,valuesRaw:W,results:v}=await this.results.extractQueryResults(e.warp,m,e.action,e.resolvedInputs),E=dr(this.config,[],e.warp,e.action,v);return{success:u,warp:e.warp,action:e.action,user:we(this.config,e.chain.name),txHash:null,tx:null,next:E,values:A,valuesRaw:W,results:v,messages:mr(e.warp,v)}}async signMessage(e,t){let r=lr.fromString(t);return(await new ur(r).sign(new Uint8Array(Buffer.from(e,"utf-8")))).toString()}toTokenTransfers(e){return e.map(t=>t.identifier===this.chain.nativeToken.identifier?{...t,identifier:hr}:t).map(t=>{let n=new or().extractNonceFromExtendedIdentifier(t.identifier);return new cr({token:new ir({identifier:t.identifier,nonce:BigInt(n||0)}),amount:t.amount})})}};var Ya={Egld:{Identifier:"EGLD",EsdtIdentifier:"EGLD-000000",DisplayName:"eGold",Decimals:18}},fr=(r=>(r.MultiversxExplorer="multiversx_explorer",r.MultiversxExplorerDevnet="multiversx_explorer_devnet",r.MultiversxExplorerTestnet="multiversx_explorer_testnet",r))(fr||{}),gr=(r=>(r.VibechainExplorer="vibechain_explorer",r.VibechainExplorerDevnet="vibechain_explorer_devnet",r.VibechainExplorerTestnet="vibechain_explorer_testnet",r))(gr||{}),st={multiversx:{mainnet:["multiversx_explorer"],testnet:["multiversx_explorer_testnet"],devnet:["multiversx_explorer_devnet"]},vibechain:{mainnet:["vibechain_explorer"],testnet:["vibechain_explorer_testnet"],devnet:["vibechain_explorer_devnet"]}},N={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 G=class{constructor(e,t){this.chain=e;this.config=t}getExplorers(){let e=st[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=N[t];if(a)return a}if(e){let a=N[e];if(a)return a}let r=this.getPrimaryExplorer();return N[r]||N[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=N[n];a&&(r[n]=`${a}/accounts/${e}`)}),r}getTransactionUrls(e){let t=this.getAllExplorers(),r={};return t.forEach(n=>{let a=N[n];a&&(r[n]=`${a}/transactions/${e}`)}),r}};import{AbiRegistry as ot,Address as d,AddressValue as We,BytesValue as f,SmartContractTransactionsFactory as wr,TransactionsFactoryConfig as Cr}from"@multiversx/sdk-core";import{getWarpWalletAddressFromConfig as Wr,WarpCache as vr,WarpCacheKey as ve,WarpLogger as xe}from"@vleap/warps";var Ce={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 w=i=>{if(i==="devnet")return"erd1qqqqqqqqqqqqqpgqje2f99vr6r7sk54thg03c9suzcvwr4nfl3tsfkdl36";if(i==="testnet")throw new Error("Multiversx testnet is not supported");return"erd1qqqqqqqqqqqqqpgq3mrpj3u6q7tejv6d7eqhnyd27n9v5c5tl3ts08mffe"};var Q=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}),it=i=>({unitPrice:BigInt(i.unit_price.toString()),admins:i.admins.map(e=>e.toBech32())});var j=class{constructor(e,t){this.config=e;this.chain=t;this.cache=new vr(e.cache?.type),this.registryConfig={unitPrice:BigInt(0),admins:[]},this.userWallet=Wr(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=d.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?[f.fromHex(e),f.fromUTF8(t),f.fromHex(r)]:t?[f.fromHex(e),f.fromUTF8(t)]:[f.fromHex(e)];return await this.getFactory().createTransactionForExecute(n,{contract:d.newFromBech32(w(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=d.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(t,{contract:d.newFromBech32(w(this.config.env)),function:"unregisterWarp",gasLimit:BigInt(1e7),arguments:[f.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=d.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(n,{contract:d.newFromBech32(w(this.config.env)),function:"upgradeWarp",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:r?[f.fromUTF8(e),f.fromHex(t),f.fromHex(r)]:[f.fromUTF8(e),f.fromHex(t)]})}async createWarpAliasSetTransaction(e,t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let r=d.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(r,{contract:d.newFromBech32(w(this.config.env)),function:"setWarpAlias",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[f.fromHex(e),f.fromUTF8(t)]})}async createWarpVerifyTransaction(e){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let t=d.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(t,{contract:d.newFromBech32(w(this.config.env)),function:"verifyWarp",gasLimit:BigInt(1e7),arguments:[f.fromHex(e)]})}async createWarpTransferOwnershipTransaction(e,t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let r=d.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(r,{contract:d.newFromBech32(w(this.config.env)),function:"transferOwnership",gasLimit:BigInt(1e7),arguments:[f.fromHex(e),new We(new d(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=d.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(t,{contract:d.newFromBech32(w(this.config.env)),function:"registerBrand",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[f.fromHex(e)]})}async createWarpBrandingTransaction(e,t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let r=d.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(r,{contract:d.newFromBech32(w(this.config.env)),function:"brandWarp",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[f.fromHex(e),f.fromHex(t)]})}async getInfoByAlias(e,t){try{let r=ve.RegistryInfo(this.config.env,e),n=t?this.cache.get(r):null;if(n)return xe.info(`WarpRegistry (getInfoByAlias): RegistryInfo found in cache: ${e}`),n;let a=d.newFromBech32(w(this.config.env)),o=this.getController(),s=o.createQuery({contract:a,function:"getInfoByAlias",arguments:[f.fromUTF8(e)]}),c=await o.runQuery(s),[p]=o.parseQueryResponse(c),u=p?Q(p):null,l=u?.brand?await this.fetchBrand(u.brand):null;return t&&t.ttl&&this.cache.set(r,{registryInfo:u,brand:l},t.ttl),{registryInfo:u,brand:l}}catch{return{registryInfo:null,brand:null}}}async getInfoByHash(e,t){try{let r=ve.RegistryInfo(this.config.env,e);if(t){let l=this.cache.get(r);if(l)return xe.info(`WarpRegistry (getInfoByHash): RegistryInfo found in cache: ${e}`),l}let n=d.newFromBech32(w(this.config.env)),a=this.getController(),o=a.createQuery({contract:n,function:"getInfoByHash",arguments:[f.fromHex(e)]}),s=await a.runQuery(o),[c]=a.parseQueryResponse(s),p=c?Q(c):null,u=p?.brand?await this.fetchBrand(p.brand):null;return t&&t.ttl&&this.cache.set(r,{registryInfo:p,brand:u},t.ttl),{registryInfo:p,brand:u}}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=d.newFromBech32(w(this.config.env)),n=this.getController(),a=n.createQuery({contract:r,function:"getUserWarps",arguments:[new We(new d(t))]}),o=await n.runQuery(a),[s]=n.parseQueryResponse(o);return s.map(Q)}catch{return[]}}async getUserBrands(e){try{let t=e||this.userWallet;if(!t)throw new Error("WarpRegistry: user address not set");let r=d.newFromBech32(w(this.config.env)),n=this.getController(),a=n.createQuery({contract:r,function:"getUserBrands",arguments:[new We(new d(t))]}),o=await n.runQuery(a),[s]=n.parseQueryResponse(o),c=s.map(l=>l.toString("hex")),p={ttl:365*24*60*60};return(await Promise.all(c.map(l=>this.fetchBrand(l,p)))).filter(l=>l!==null)}catch{return[]}}async fetchBrand(e,t){let r=ve.Brand(this.config.env,e),n=t?this.cache.get(r):null;if(n)return xe.info(`WarpRegistry (fetchBrand): Brand found in cache: ${e}`),n;let o=h(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=d.newFromBech32(w(this.config.env)),t=this.getController(),[r]=await t.query({contract:e,function:"getConfig",arguments:[]}),n=r?it(r):null;this.registryConfig=n||{unitPrice:BigInt(0),admins:[]}}getFactory(){let e=new Cr({chainID:this.chain.chainId}),t=ot.create(Ce);return new wr({config:e,abi:t})}getController(){let e=h(this.chain,this.config.env,this.config),t=ot.create(Ce);return e.createSmartContractController(t)}isCurrentUserAdmin(){return!!this.userWallet&&this.registryConfig.admins.includes(this.userWallet)}};import{Account as xr,Mnemonic as ct,TransactionComputer as Tr,UserSecretKey as pt,UserSigner as Ar}from"@multiversx/sdk-core";import{CacheTtl as br,getWarpWalletAddressFromConfig as Er,getWarpWalletPrivateKeyFromConfig as Ir,WarpCache as Br}from"@vleap/warps";var J=class{constructor(e,t){this.config=e;this.chain=t;this.entry=h(t,e.env,e),this.provider=this.entry.createNetworkProvider(),this.cache=new Br(e.cache?.type)}async signTransaction(e){if(!e||typeof e!="object")throw new Error("Invalid transaction object");let t=Ir(this.config,this.chain.name);if(!t)throw new Error("Wallet not initialized - no private key provided");console.log("privateKey",t);let r=t.startsWith("-----");console.log("isPrivateKeyPem",r);let n=r?pt.fromPem(t):pt.fromString(t),a=new Ar(n),o=new xr(n),s=(await this.provider.getAccount(o.address)).nonce,c=this.cache.get(`nonce:${o.address.toBech32()}`)||0;o.nonce=BigInt(Math.max(c,Number(s))),e.nonce=o.getNonceThenIncrement();let u=new Tr().computeBytesForSigning(e);return e.signature=await a.sign(u),this.cache.set(`nonce:${o.address.toBech32()}`,Number(o.nonce),br.OneHour),e}async signMessage(e){throw new Error("Not implemented")}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=ct.fromString(e).deriveKey(0),n=r.hex();return{address:r.generatePublicKey().toAddress(this.chain.addressHrp).toBech32(),privateKey:n,mnemonic:e}}generate(){let e=ct.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 Er(this.config,this.chain.name)}};var X=(i,e,t)=>(r,n)=>{let a=t[r.env];return{chain:i,chainInfo:a,prefix:e,builder:()=>new _(r,a),executor:new K(r,a),results:new S(r,a),serializer:new B,registry:new j(r,a),explorer:new G(i,r),abiBuilder:()=>new I(r,a),brandBuilder:()=>new M(r,a),dataLoader:new L(r,a),wallet:new J(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 Te={chain:P.Multiversx,identifier:"EGLD",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://vleap.ai/images/tokens/egld.svg"},lt=X(P.Multiversx,"mvx",{mainnet:{name:P.Multiversx,displayName:"MultiversX",chainId:"1",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://api.multiversx.com",logoUrl:"https://vleap.ai/images/chains/multiversx.svg",nativeToken:Te},testnet:{name:P.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:Te},devnet:{name:P.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:Te}});import{WarpChainName as be}from"@vleap/warps";var Nr={chain:be.Vibechain,identifier:"VIBE",name:"VIBE",symbol:"VIBE",decimals:18,logoUrl:"https://vleap.ai/images/tokens/vibe.svg"},Ae={name:be.Vibechain,displayName:"VibeChain",chainId:"V",blockTime:600,addressHrp:"vibe",defaultApiUrl:"https://vibeox-api.multiversx.com",logoUrl:"https://vleap.ai/images/chains/vibechain.svg",nativeToken:Nr},ut=X(be.Vibechain,"vibe",{mainnet:Ae,testnet:Ae,devnet:Ae});var ai=(i,e)=>[lt(i,e),ut(i,e)],si=()=>[mt.Multiversx,mt.Vibechain];import{Address as Vr,AddressValue as Sr,BigUIntType as Fr,BigUIntValue as dt,BooleanValue as kr,BytesValue as Pr,CodeMetadata as Ur,CodeMetadataValue as Rr,CompositeType as Or,CompositeValue as Mr,Field as Ee,FieldDefinition as Ie,List as _r,NothingValue as $r,OptionalValue as Be,OptionValue as Ne,StringValue as Lr,Struct as Dr,StructType as qr,TokenIdentifierType as Hr,TokenIdentifierValue as ht,U16Value as zr,U32Value as Kr,U64Type as Gr,U64Value as ft,U8Value as Qr,VariadicValue as jr}from"@multiversx/sdk-core";var Ci=(i,e)=>i?Ne.newProvided(i):e?Ne.newMissingTyped(e):Ne.newMissing(),Wi=(i,e)=>i?new Be(i.getType(),i):e?new Be(e):Be.newMissing(),vi=i=>{if(i.length===0)throw new Error("Cannot create a list from an empty array");let e=i[0].getType();return new _r(e,i)},xi=i=>jr.fromItems(...i),Ti=i=>{let e=i.map(t=>t.getType());return new Mr(new Or(...e),i)},Ai=i=>Lr.fromUTF8(i),bi=i=>new Qr(i),Ei=i=>new zr(i),Ii=i=>new Kr(i),Bi=i=>new ft(i),Ni=i=>new dt(BigInt(i)),Vi=i=>new kr(i),Si=i=>new Sr(Vr.newFromBech32(i)),Fi=i=>new ht(i),ki=i=>Pr.fromHex(i),Pi=i=>new Dr(new qr("EsdtTokenPayment",[new Ie("token_identifier","",new Hr),new Ie("token_nonce","",new Gr),new Ie("amount","",new Fr)]),[new Ee(new ht(i.token.identifier),"token_identifier"),new Ee(new ft(BigInt(i.token.nonce)),"token_nonce"),new Ee(new dt(BigInt(i.amount)),"amount")]),Ui=i=>new Rr(Ur.newFromBytes(Uint8Array.from(Buffer.from(i,"hex")))),Ri=()=>new $r;export{N as ExplorerUrls,_t as KnownTokens,fr as MultiversxExplorers,st as MultiversxExplorersConfig,Te as NativeTokenEgld,Nr as NativeTokenVibe,gr as VibechainExplorers,I as WarpMultiversxAbiBuilder,M as WarpMultiversxBrandBuilder,_ as WarpMultiversxBuilder,Ya as WarpMultiversxConstants,O as WarpMultiversxContractLoader,L as WarpMultiversxDataLoader,K as WarpMultiversxExecutor,G as WarpMultiversxExplorer,j as WarpMultiversxRegistry,S as WarpMultiversxResults,B as WarpMultiversxSerializer,J as WarpMultiversxWallet,Si as address_value,Pi as asset_value,Ni as biguint_value,Vi as boolean_value,Ui as codemeta_value,Ti as composite_value,X as createMultiversxAdapter,Oe as findKnownTokenById,ai as getAllMultiversxAdapters,si as getAllMultiversxChainNames,lt as getMultiversxAdapter,h as getMultiversxEntrypoint,w as getMultiversxRegistryAddress,R as getNormalizedTokenIdentifier,ut as getVibechainAdapter,ki as hex_value,V as isNativeToken,vi as list_value,Ri as nothing_value,Ci as option_value,Wi as optional_value,Ai as string_value,it as toTypedConfigInfo,Q as toTypedRegistryInfo,Fi as token_value,Ei as u16_value,Ii as u32_value,Bi as u64_value,bi as u8_value,xi as variadic_value};
1
+ import{WarpChainName as ft}from"@vleap/warps";import{WarpChainName as P}from"@vleap/warps";import{AbiRegistry as Z,Address as xt,TransactionsFactoryConfig as Tt,TransferTransactionsFactory as At}from"@multiversx/sdk-core";import{getLatestProtocolIdentifier as bt,getWarpWalletAddressFromConfig as Et,WarpCache as It,WarpCacheKey as Bt,WarpConstants as ke,WarpLogger as Fe}from"@vleap/warps";import{DevnetEntrypoint as wt,MainnetEntrypoint as Ct,TestnetEntrypoint as Wt}from"@multiversx/sdk-core";import{getProviderUrl as vt}from"@vleap/warps";var V=i=>!i.includes("-"),R=i=>V(i)?`${i}-000000`:i,f=(i,e,t)=>{let r="warp-sdk",a=t?vt(t,i.name,e,i.defaultApiUrl):i.defaultApiUrl;return e==="devnet"?new wt({url:a,kind:"api",clientName:r}):e==="testnet"?new Wt({url:a,kind:"api",clientName:r}):new Ct({url:a,kind:"api",clientName:r})};import{WarpLogger as Se}from"@vleap/warps";var O=class{constructor(e){this.config=e}async getContract(e,t){try{let a=await f(t,this.config.env,this.config).createNetworkProvider().doGetGeneric(`accounts/${e}`);return{address:e,owner:a.ownerAddress,verified:a.isVerified||!1}}catch(r){return Se.error("WarpContractLoader: getContract error",r),null}}async getVerificationInfo(e,t){try{let a=await f(t,this.config.env,this.config).createNetworkProvider().doGetGeneric(`accounts/${e}/verification`);return{codeHash:a.codeHash,abi:a.source.abi}}catch(r){return Se.error("WarpContractLoader: getVerificationInfo error",r),null}}};var I=class{constructor(e,t){this.config=e;this.chain=t;this.contractLoader=new O(this.config),this.cache=new It(this.config.cache?.type)}async createInscriptionTransaction(e){let t=Et(this.config,this.chain.name);if(!t)throw new Error("WarpBuilder: user address not set");let r=new Tt({chainID:this.chain.chainId}),n=new At({config:r}),a=xt.newFromBech32(t),o={protocol:bt("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=Bt.WarpAbi(this.config.env,e);if(t){let o=this.cache.get(r);if(o)return Fe.info(`WarpAbiBuilder (createFromTransactionHash): Warp abi found in cache: ${e}`),o}let a=f(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 Fe.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 Z.create(t.abi)}async fetchAbi(e){if(!e.abi)throw new Error("WarpActionExecutor: ABI not found");if(e.abi.startsWith(ke.IdentifierType.Hash)){let t=e.abi.split(ke.ArgParamsSeparator)[1],r=await this.createFromTransactionHash(t);if(!r)throw new Error(`WarpActionExecutor: ABI not found for hash: ${e.abi}`);return Z.create(r.content)}else{let r=await(await fetch(e.abi)).json();return Z.create(r)}}};import{Address as Pe,TransactionsFactoryConfig as Nt,TransferTransactionsFactory as Vt}from"@multiversx/sdk-core";import{getWarpWalletAddressFromConfig as St,WarpBrandBuilder as kt,WarpLogger as Ft}from"@vleap/warps";import{Buffer as Pt}from"buffer";var M=class{constructor(e,t){this.config=e;this.chain=t;this.core=new kt(e)}async createInscriptionTransaction(e){let t=St(this.config,this.chain.name);if(!t)throw new Error("BrandBuilder: user address not set");let r=new Nt({chainID:this.chain.chainId}),n=new Vt({config:r}),a=Pe.newFromBech32(t),o=JSON.stringify(e);return await n.createTransactionForNativeTokenTransfer(a,{receiver:Pe.newFromBech32(t),nativeAmount:BigInt(0),data:Uint8Array.from(Pt.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=f(this.chain,this.config.env,this.config).createNetworkProvider();try{let n=await r.getTransaction(e);return this.createFromTransaction(n)}catch(n){return Ft.error("BrandBuilder: Error creating from transaction hash",n),null}}};import{Address as Ue,TransactionsFactoryConfig as Ut,TransferTransactionsFactory as Rt}from"@multiversx/sdk-core";import{getWarpWalletAddressFromConfig as Ot,WarpBuilder as Re,WarpCache as Mt,WarpCacheKey as _t,WarpLogger as Oe}from"@vleap/warps";var _=class extends Re{constructor(t,r){super(t);this.config=t;this.chain=r;this.cache=new Mt(t.cache?.type),this.core=new Re(t)}async createInscriptionTransaction(t){let r=Ot(this.config,this.chain.name);if(!r)throw new Error("WarpBuilder: user address not set");let n=new Ut({chainID:this.chain.chainId}),a=new Rt({config:n}),o=Ue.newFromBech32(r),s=JSON.stringify(t),c=await a.createTransactionForTransfer(o,{receiver:Ue.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=_t.Warp(this.config.env,t);if(r){let s=this.cache.get(n);if(s)return Oe.info(`WarpBuilder (createFromTransactionHash): Warp found in cache: ${t}`),s}let o=f(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 Oe.error("WarpBuilder: Error creating from transaction hash",s),null}}};import{Address as ee,Token as Dt,TokenComputer as Kt}from"@multiversx/sdk-core";import{CacheTtl as qt,WarpCache as zt,WarpCacheKey as Ht}from"@vleap/warps";import{WarpChainName as $t}from"@vleap/warps";var $=$t.Multiversx,Lt=[{chain:$,identifier:"EGLD",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.pngsvg"},{chain:$,identifier:"EGLD-000000",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://tools.multiversx.com/assets-cdn/tokens/EGLD-000000/icon.png"},{chain:$,identifier:"VIBE",name:"VIBE",symbol:"VIBE",decimals:18,logoUrl:"https://vleap.ai/images/tokens/vibe.svg"},{chain:$,identifier:"VIBE-000000",name:"VIBE",symbol:"VIBE",decimals:18,logoUrl:"https://vleap.ai/images/tokens/vibe.svg"}],Me=i=>Lt.find(e=>e.identifier===i)||null;var L=class{constructor(e,t){this.config=e;this.chain=t;this.cache=new zt(e.cache?.type)}async getAccount(e){let r=await f(this.chain,this.config.env,this.config).createNetworkProvider().getAccount(ee.newFromBech32(e));return{chain:this.chain.name,address:r.address.toBech32(),balance:r.balance}}async getAccountAssets(e){let t=f(this.chain,this.config.env,this.config).createNetworkProvider(),r=t.getAccount(ee.newFromBech32(e)),n=t.getFungibleTokensOfAccount(ee.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=Ht.Asset(this.config.env,this.chain.name,e),r=this.cache.get(t);if(r)return r;let n=Me(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 Kt,o=V(e)?0n:a.extractNonceFromExtendedIdentifier(e),s=new Dt({identifier:e,nonce:BigInt(o||0)}),c=a.isFungible(s),p=f(this.chain,this.config.env,this.config).createNetworkProvider(),u=R(e),l=await p.doGetGeneric(`tokens/${u}`),y={chain:this.chain.name,identifier:s.identifier,name:l.name,symbol:l.ticker,amount:0n,decimals:l.decimals,logoUrl:l.assets?.pngUrl||"#",price:l.price?Number(l.price):void 0,supply:l.supply?BigInt(l.supply):void 0};return this.cache.set(t,y,qt.OneHour),y}async getAction(e,t=!1){let r=f(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=f(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 p=s*o;a.append("from",p.toString())}return o!==25&&a.append("size",o.toString()),a.toString()&&(n+=`?${a.toString()}`),(await r.doGetGeneric(n)).map(p=>({chain:this.chain.name,id:p.txHash,receiver:p.receiver,sender:p.sender,value:p.value,function:p.function,status:this.toActionStatus(p),createdAt:this.toActionCreatedAt(p)}))}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 F,ArgSerializer as ir,SmartContractTransactionsFactory as or,Token as cr,TokenComputer as pr,TokenTransfer as lr,TransactionsFactoryConfig as st,TransferTransactionsFactory as ur,UserSecretKey as mr,UserSigner as dr}from"@multiversx/sdk-core";import{applyResultsToMessages as fr,getNextInfo as hr,getWarpActionByIndex as we,getWarpWalletAddressFromConfig as Ce}from"@vleap/warps";import{findEventsByFirstTopic as Yt,SmartContractTransactionsOutcomeParser as Zt,TransactionEventsParser as er}from"@multiversx/sdk-core";import{applyResultsToMessages as tr,evaluateResultsCommon as z,findWarpExecutableAction as rt,getNextInfo as rr,getWarpWalletAddressFromConfig as nr,parseResultsOutIndex as nt,WarpCache as ar,WarpCacheKey as sr,WarpConstants as at}from"@vleap/warps";import{Address as Gt,AddressType as te,AddressValue as _e,BigUIntType as D,BigUIntValue as re,BooleanType as ne,BooleanValue as $e,BytesType as ae,BytesValue as Le,CodeMetadata as Qt,CodeMetadataType as se,CodeMetadataValue as De,CompositeType as ie,CompositeValue as Ke,Field as oe,FieldDefinition as ce,List as qe,ListType as ze,NothingValue as x,OptionalType as He,OptionalValue as pe,OptionType as Ge,OptionValue as le,StringType as ue,StringValue as Qe,Struct as jt,StructType as je,Token as Jt,TokenComputer as Je,TokenIdentifierType as K,TokenIdentifierValue as me,U16Type as de,U16Value as Xe,U32Type as fe,U32Value as Ye,U64Type as q,U64Value as he,U8Type as ge,U8Value as Ze,VariadicType as ye,VariadicValue as et}from"@multiversx/sdk-core";import{WarpConstants as T,WarpSerializer as Xt}from"@vleap/warps";var tt=new RegExp(`${T.ArgParamsSeparator}(.*)`),B=class{constructor(){this.coreSerializer=new Xt}typedToString(e){let t=e.getType();if(t.hasExactClass(Ge.ClassName)||e.hasClassOrSuperclass(le.ClassName))return e.isSet()?`option:${this.typedToString(e.getTypedValue())}`:"option:null";if(t.hasExactClass(He.ClassName)||e.hasClassOrSuperclass(pe.ClassName))return e.isSet()?`optional:${this.typedToString(e.getTypedValue())}`:"optional:null";if(t.hasExactClass(ze.ClassName)||e.hasClassOrSuperclass(qe.ClassName)){let r=e.getItems(),a=r.map(s=>this.typedToString(s).split(T.ArgParamsSeparator)[0])[0],o=r.map(s=>this.typedToString(s).split(T.ArgParamsSeparator)[1]);return`list:${a}:${o.join(",")}`}if(t.hasExactClass(ye.ClassName)||e.hasClassOrSuperclass(et.ClassName)){let r=e.getItems(),a=r.map(s=>this.typedToString(s).split(T.ArgParamsSeparator)[0])[0],o=r.map(s=>this.typedToString(s).split(T.ArgParamsSeparator)[1]);return`variadic:${a}:${o.join(",")}`}if(t.hasExactClass(ie.ClassName)||e.hasClassOrSuperclass(Ke.ClassName)){let r=e.getItems(),n=r.map(c=>this.typedToString(c).split(T.ArgParamsSeparator)[0]),a=r.map(c=>this.typedToString(c).split(T.ArgParamsSeparator)[1]),o=n.join(T.ArgCompositeSeparator),s=a.join(T.ArgCompositeSeparator);return`composite(${o}):${s}`}if(t.hasExactClass(D.ClassName)||e.hasClassOrSuperclass(re.ClassName)||t.getName()==="BigUint")return`biguint:${BigInt(e.valueOf().toFixed())}`;if(t.hasExactClass(ge.ClassName)||e.hasClassOrSuperclass(Ze.ClassName))return`uint8:${e.valueOf().toNumber()}`;if(t.hasExactClass(de.ClassName)||e.hasClassOrSuperclass(Xe.ClassName))return`uint16:${e.valueOf().toNumber()}`;if(t.hasExactClass(fe.ClassName)||e.hasClassOrSuperclass(Ye.ClassName))return`uint32:${e.valueOf().toNumber()}`;if(t.hasExactClass(q.ClassName)||e.hasClassOrSuperclass(he.ClassName))return`uint64:${BigInt(e.valueOf().toFixed())}`;if(t.hasExactClass(ue.ClassName)||e.hasClassOrSuperclass(Qe.ClassName))return`string:${e.valueOf()}`;if(t.hasExactClass(ne.ClassName)||e.hasClassOrSuperclass($e.ClassName))return`bool:${e.valueOf()}`;if(t.hasExactClass(te.ClassName)||e.hasClassOrSuperclass(_e.ClassName))return`address:${e.valueOf().toBech32()}`;if(t.hasExactClass(K.ClassName)||e.hasClassOrSuperclass(me.ClassName))return`token:${e.valueOf()}`;if(t.hasExactClass(ae.ClassName)||e.hasClassOrSuperclass(Le.ClassName))return`hex:${e.valueOf().toString("hex")}`;if(t.hasExactClass(se.ClassName)||e.hasClassOrSuperclass(De.ClassName))return`codemeta:${e.valueOf().toString()}`;if(t.getName()==="EsdtTokenPayment"){let r=e.getFieldValue("token_identifier").valueOf(),n=e.getFieldValue("token_nonce").valueOf(),a=e.getFieldValue("amount").valueOf();return`asset:${new Je().computeExtendedIdentifier(new Jt({identifier:r,nonce:BigInt(n)}))}|${a}`}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("composite")){let t=e.match(/\(([^)]+)\)/)?.[1];return new ie(...t.split(T.ArgCompositeSeparator).map(r=>this.nativeToType(r)))}if(e==="string")return new ue;if(e==="uint8")return new ge;if(e==="uint16")return new de;if(e==="uint32")return new fe;if(e==="uint64")return new q;if(e==="biguint")return new D;if(e==="bool")return new ne;if(e==="address")return new te;if(e==="token")return new K;if(e==="hex")return new ae;if(e==="codemeta")return new se;if(e==="asset")return new je("EsdtTokenPayment",[new ce("token_identifier","",new K),new ce("token_nonce","",new q),new ce("amount","",new D)]);throw new Error(`WarpArgSerializer (nativeToType): Unsupported input type: ${e}`)}stringToTyped(e){let[t,r]=e.split(/:(.*)/,2);if(t==="null"||t===null)return new x;if(t==="option"){let n=this.stringToTyped(r);return n instanceof x?le.newMissingTyped(n.getType()):le.newProvided(n)}if(t==="optional"){let n=this.stringToTyped(r);return n instanceof x?pe.newMissing():new pe(n.getType(),n)}if(t==="list"){let[n,a]=r.split(tt,2),s=a.split(",").map(c=>this.stringToTyped(`${n}:${c}`));return new qe(this.nativeToType(n),s)}if(t==="variadic"){let[n,a]=r.split(tt,2),s=a.split(",").map(c=>this.stringToTyped(`${n}:${c}`));return new et(new ye(this.nativeToType(n)),s)}if(t.startsWith("composite")){let n=t.match(/\(([^)]+)\)/)?.[1],a=r.split(T.ArgCompositeSeparator),o=n.split(T.ArgCompositeSeparator),s=a.map((p,u)=>this.stringToTyped(`${o[u]}:${p}`)),c=s.map(p=>p.getType());return new Ke(new ie(...c),s)}if(t==="string")return r?Qe.fromUTF8(r):new x;if(t==="uint8")return r?new Ze(Number(r)):new x;if(t==="uint16")return r?new Xe(Number(r)):new x;if(t==="uint32")return r?new Ye(Number(r)):new x;if(t==="uint64")return r?new he(BigInt(r)):new x;if(t==="biguint")return r?new re(BigInt(r)):new x;if(t==="bool")return r?new $e(typeof r=="boolean"?r:r==="true"):new x;if(t==="address")return r?new _e(Gt.newFromBech32(r)):new x;if(t==="token")return r?new me(r):new x;if(t==="hex")return r?Le.fromHex(r):new x;if(t==="codemeta")return new De(Qt.newFromBytes(Uint8Array.from(Buffer.from(r,"hex"))));if(t==="asset"){let[n,a]=r.split(T.ArgCompositeSeparator),o=new Je,s=V(n)?R(n):o.extractIdentifierFromExtendedIdentifier(n),c=V(n)?0n:o.extractNonceFromExtendedIdentifier(n);return new jt(this.nativeToType("asset"),[new oe(new me(s),"token_identifier"),new oe(new he(BigInt(c)),"token_nonce"),new oe(new re(BigInt(a)),"amount")])}throw new Error(`WarpArgSerializer (stringToTyped): Unsupported input type: ${t}`)}typeToString(e){if(e.hasExactClass(Ge.ClassName))return"option:"+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(He.ClassName))return"optional:"+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(ze.ClassName))return"list:"+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(ye.ClassName))return"variadic:"+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(ue.ClassName))return"string";if(e.hasExactClass(ge.ClassName))return"uint8";if(e.hasExactClass(de.ClassName))return"uint16";if(e.hasExactClass(fe.ClassName))return"uint32";if(e.hasExactClass(q.ClassName))return"uint64";if(e.hasExactClass(D.ClassName))return"biguint";if(e.hasExactClass(ne.ClassName))return"bool";if(e.hasExactClass(te.ClassName))return"address";if(e.hasExactClass(K.ClassName))return"token";if(e.hasExactClass(ae.ClassName))return"hex";if(e.hasExactClass(se.ClassName))return"codemeta";if(e.hasExactClass(je.ClassName)&&e.getClassName()==="EsdtTokenPayment")return"asset";throw new Error(`WarpArgSerializer (typeToString): Unsupported input type: ${e.getClassName()}`)}};var S=class{constructor(e,t){this.config=e;this.chain=t;this.abi=new I(e,t),this.serializer=new B,this.cache=new ar(e.cache?.type)}async getTransactionExecutionResults(e,t){let{actionIndex:r}=rt(e),n=this.cache.get(sr.WarpExecutable(this.config.env,e.meta?.hash||"",r))??[],a=await this.extractContractResults(e,t,n),o=rr(this.config,[],e,r,a),s=tr(e,a.results);return{success:t.status.isSuccessful(),warp:e,action:r,user:nr(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}=rt(e),o=[],s={};if(!e.results||n.type!=="contract")return{values:o,results:s};if(!Object.values(e.results).some(C=>C.includes("out")||C.includes("event"))){for(let[C,m]of Object.entries(e.results))s[C]=m;return{values:o,results:await z(e,s,a,r,this.config.transform?.runner)}}let p=await this.abi.getAbiForAction(n),u=new er({abi:p}),y=new Zt({abi:p}).parseExecute({transactionOnNetwork:t,function:n.func||void 0});for(let[C,m]of Object.entries(e.results)){if(m.startsWith(at.Transform.Prefix))continue;if(m.startsWith("input.")){s[C]=m;continue}let A=nt(m);if(A!==null&&A!==a){s[C]=null;continue}let[W,v,E]=m.split(".");if(W==="event"){if(!v||isNaN(Number(E)))continue;let b=Number(E),g=Yt(t,v),k=u.parseEvents({events:g})[0],U=Object.values(k)[b]||null;o.push(U),s[C]=U&&U.valueOf()}else if(W==="out"||W.startsWith("out[")){if(!v)continue;let b=Number(v),g=y.values[b-1]||null;E&&(g=g[E]||null),g&&typeof g=="object"&&(g="toFixed"in g?g.toFixed():g.valueOf()),o.push(g),s[C]=g&&g.valueOf()}else s[C]=m}return{values:o,results:await z(e,s,a,r)}}async extractQueryResults(e,t,r,n){let a=t.map(p=>this.serializer.typedToString(p)),o=t.map(p=>this.serializer.typedToNative(p)[1]),s={};if(!e.results)return{values:a,valuesRaw:o,results:s};let c=p=>{let u=p.split(".").slice(1).map(y=>parseInt(y)-1);if(u.length===0)return;let l=o[u[0]];for(let y=1;y<u.length;y++){if(l==null)return;l=l[u[y]]}return l};for(let[p,u]of Object.entries(e.results)){if(u.startsWith(at.Transform.Prefix))continue;let l=nt(u);if(l!==null&&l!==r){s[p]=null;continue}u.startsWith("out.")||u==="out"||u.startsWith("out[")?s[p]=c(u)||null:s[p]=u}return{values:a,valuesRaw:o,results:await z(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,p=this;async function u(m,A=[]){if(s.has(m))return s.get(m);if(c.has(m))throw new Error(`Circular dependency detected at action ${m}`);c.add(m);let W=t.actions[m-1];if(!W)throw new Error(`Action ${m} not found`);let v;if(W.type==="query")v=await n.executeQuery(t,m,A);else if(W.type==="collect")v=await n.executeCollect(t,m,A,o);else throw new Error(`Unsupported or interactive action type: ${W.type}`);if(s.set(m,v),t.results)for(let E of Object.values(t.results)){let g=String(E).match(/^out\[(\d+)\]/);if(g){let k=parseInt(g[1],10);k!==m&&!s.has(k)&&await u(k)}}return c.delete(m),v}await u(r,a);let l={};for(let m of s.values())for(let[A,W]of Object.entries(m.results))W!==null?l[A]=W:A in l||(l[A]=null);let y=await z(t,l,r,a,this.config.transform?.runner);return{...s.get(r),action:r,results:y}}};var gr="EGLD-000000",H=class{constructor(e,t){this.config=e;this.chain=t;this.serializer=new B,this.abi=new I(this.config,this.chain),this.results=new S(this.config,this.chain)}async createTransaction(e){let t=we(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=Ce(this.config,e.chain.name);if(!t)throw new Error("WarpMultiversxExecutor: createTransfer - user address not set");let r=F.newFromBech32(t),n=new st({chainID:e.chain.chainId}),a=e.data?Buffer.from(this.serializer.stringToTyped(e.data).valueOf()):null;return new ur({config:n}).createTransactionForTransfer(r,{receiver:F.newFromBech32(e.destination),nativeAmount:e.value,tokenTransfers:this.toTokenTransfers(e.transfers),data:a?new Uint8Array(a):void 0})}async createContractCallTransaction(e){let t=Ce(this.config,e.chain.name);if(!t)throw new Error("WarpMultiversxExecutor: createContractCall - user address not set");let r=we(e.warp,e.action),n=F.newFromBech32(t),a=e.args.map(s=>this.serializer.stringToTyped(s)),o=new st({chainID:e.chain.chainId});return new or({config:o}).createTransactionForExecute(n,{contract:F.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=we(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=f(e.chain,this.config.env,this.config),o=F.newFromBech32(e.destination),s=a.createSmartContractController(r),c=s.createQuery({contract:o,function:t.func||"",arguments:n}),p=await s.runQuery(c),u=p.returnCode==="ok",l=new ir,y=r.getEndpoint(p.function||t.func||""),C=(p.returnDataParts||[]).map(b=>Buffer.from(b)),m=l.buffersToValues(C,y.output),{values:A,valuesRaw:W,results:v}=await this.results.extractQueryResults(e.warp,m,e.action,e.resolvedInputs),E=hr(this.config,[],e.warp,e.action,v);return{success:u,warp:e.warp,action:e.action,user:Ce(this.config,e.chain.name),txHash:null,tx:null,next:E,values:A,valuesRaw:W,results:v,messages:fr(e.warp,v)}}async signMessage(e,t){let r=mr.fromString(t);return(await new dr(r).sign(new Uint8Array(Buffer.from(e,"utf-8")))).toString()}toTokenTransfers(e){return e.map(t=>t.identifier===this.chain.nativeToken.identifier?{...t,identifier:gr}:t).map(t=>{let n=new pr().extractNonceFromExtendedIdentifier(t.identifier);return new lr({token:new cr({identifier:t.identifier,nonce:BigInt(n||0)}),amount:t.amount})})}};var Ya={Egld:{Identifier:"EGLD",EsdtIdentifier:"EGLD-000000",DisplayName:"eGold",Decimals:18}},yr=(r=>(r.MultiversxExplorer="multiversx_explorer",r.MultiversxExplorerDevnet="multiversx_explorer_devnet",r.MultiversxExplorerTestnet="multiversx_explorer_testnet",r))(yr||{}),wr=(r=>(r.VibechainExplorer="vibechain_explorer",r.VibechainExplorerDevnet="vibechain_explorer_devnet",r.VibechainExplorerTestnet="vibechain_explorer_testnet",r))(wr||{}),it={multiversx:{mainnet:["multiversx_explorer"],testnet:["multiversx_explorer_testnet"],devnet:["multiversx_explorer_devnet"]},vibechain:{mainnet:["vibechain_explorer"],testnet:["vibechain_explorer_testnet"],devnet:["vibechain_explorer_devnet"]}},N={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 G=class{constructor(e,t){this.chain=e;this.config=t}getExplorers(){let e=it[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=N[t];if(a)return a}if(e){let a=N[e];if(a)return a}let r=this.getPrimaryExplorer();return N[r]||N[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=N[n];a&&(r[n]=`${a}/accounts/${e}`)}),r}getTransactionUrls(e){let t=this.getAllExplorers(),r={};return t.forEach(n=>{let a=N[n];a&&(r[n]=`${a}/transactions/${e}`)}),r}};import{AbiRegistry as ct,Address as d,AddressValue as ve,BytesValue as h,SmartContractTransactionsFactory as Wr,TransactionsFactoryConfig as vr}from"@multiversx/sdk-core";import{getWarpWalletAddressFromConfig as xr,WarpCache as Tr,WarpCacheKey as xe,WarpLogger as Te}from"@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 w=i=>{if(i==="devnet")return"erd1qqqqqqqqqqqqqpgqje2f99vr6r7sk54thg03c9suzcvwr4nfl3tsfkdl36";if(i==="testnet")throw new Error("Multiversx testnet is not supported");return"erd1qqqqqqqqqqqqqpgq3mrpj3u6q7tejv6d7eqhnyd27n9v5c5tl3ts08mffe"};var Q=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}),ot=i=>({unitPrice:BigInt(i.unit_price.toString()),admins:i.admins.map(e=>e.toBech32())});var j=class{constructor(e,t){this.config=e;this.chain=t;this.cache=new Tr(e.cache?.type),this.registryConfig={unitPrice:BigInt(0),admins:[]},this.userWallet=xr(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=d.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?[h.fromHex(e),h.fromUTF8(t),h.fromHex(r)]:t?[h.fromHex(e),h.fromUTF8(t)]:[h.fromHex(e)];return await this.getFactory().createTransactionForExecute(n,{contract:d.newFromBech32(w(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=d.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(t,{contract:d.newFromBech32(w(this.config.env)),function:"unregisterWarp",gasLimit:BigInt(1e7),arguments:[h.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=d.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(n,{contract:d.newFromBech32(w(this.config.env)),function:"upgradeWarp",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:r?[h.fromUTF8(e),h.fromHex(t),h.fromHex(r)]:[h.fromUTF8(e),h.fromHex(t)]})}async createWarpAliasSetTransaction(e,t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let r=d.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(r,{contract:d.newFromBech32(w(this.config.env)),function:"setWarpAlias",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[h.fromHex(e),h.fromUTF8(t)]})}async createWarpVerifyTransaction(e){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let t=d.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(t,{contract:d.newFromBech32(w(this.config.env)),function:"verifyWarp",gasLimit:BigInt(1e7),arguments:[h.fromHex(e)]})}async createWarpTransferOwnershipTransaction(e,t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let r=d.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(r,{contract:d.newFromBech32(w(this.config.env)),function:"transferOwnership",gasLimit:BigInt(1e7),arguments:[h.fromHex(e),new ve(new d(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=d.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(t,{contract:d.newFromBech32(w(this.config.env)),function:"registerBrand",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[h.fromHex(e)]})}async createWarpBrandingTransaction(e,t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let r=d.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(r,{contract:d.newFromBech32(w(this.config.env)),function:"brandWarp",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[h.fromHex(e),h.fromHex(t)]})}async getInfoByAlias(e,t){try{let r=xe.RegistryInfo(this.config.env,e),n=t?this.cache.get(r):null;if(n)return Te.info(`WarpRegistry (getInfoByAlias): RegistryInfo found in cache: ${e}`),n;let a=d.newFromBech32(w(this.config.env)),o=this.getController(),s=o.createQuery({contract:a,function:"getInfoByAlias",arguments:[h.fromUTF8(e)]}),c=await o.runQuery(s),[p]=o.parseQueryResponse(c),u=p?Q(p):null,l=u?.brand?await this.fetchBrand(u.brand):null;return t&&t.ttl&&this.cache.set(r,{registryInfo:u,brand:l},t.ttl),{registryInfo:u,brand:l}}catch{return{registryInfo:null,brand:null}}}async getInfoByHash(e,t){try{let r=xe.RegistryInfo(this.config.env,e);if(t){let l=this.cache.get(r);if(l)return Te.info(`WarpRegistry (getInfoByHash): RegistryInfo found in cache: ${e}`),l}let n=d.newFromBech32(w(this.config.env)),a=this.getController(),o=a.createQuery({contract:n,function:"getInfoByHash",arguments:[h.fromHex(e)]}),s=await a.runQuery(o),[c]=a.parseQueryResponse(s),p=c?Q(c):null,u=p?.brand?await this.fetchBrand(p.brand):null;return t&&t.ttl&&this.cache.set(r,{registryInfo:p,brand:u},t.ttl),{registryInfo:p,brand:u}}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=d.newFromBech32(w(this.config.env)),n=this.getController(),a=n.createQuery({contract:r,function:"getUserWarps",arguments:[new ve(new d(t))]}),o=await n.runQuery(a),[s]=n.parseQueryResponse(o);return s.map(Q)}catch{return[]}}async getUserBrands(e){try{let t=e||this.userWallet;if(!t)throw new Error("WarpRegistry: user address not set");let r=d.newFromBech32(w(this.config.env)),n=this.getController(),a=n.createQuery({contract:r,function:"getUserBrands",arguments:[new ve(new d(t))]}),o=await n.runQuery(a),[s]=n.parseQueryResponse(o),c=s.map(l=>l.toString("hex")),p={ttl:365*24*60*60};return(await Promise.all(c.map(l=>this.fetchBrand(l,p)))).filter(l=>l!==null)}catch{return[]}}async fetchBrand(e,t){let r=xe.Brand(this.config.env,e),n=t?this.cache.get(r):null;if(n)return Te.info(`WarpRegistry (fetchBrand): Brand found in cache: ${e}`),n;let o=f(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=d.newFromBech32(w(this.config.env)),t=this.getController(),[r]=await t.query({contract:e,function:"getConfig",arguments:[]}),n=r?ot(r):null;this.registryConfig=n||{unitPrice:BigInt(0),admins:[]}}getFactory(){let e=new vr({chainID:this.chain.chainId}),t=ct.create(We);return new Wr({config:e,abi:t})}getController(){let e=f(this.chain,this.config.env,this.config),t=ct.create(We);return e.createSmartContractController(t)}isCurrentUserAdmin(){return!!this.userWallet&&this.registryConfig.admins.includes(this.userWallet)}};import{Account as Ar,Mnemonic as pt,TransactionComputer as br,UserSecretKey as J,UserSigner as lt}from"@multiversx/sdk-core";import{CacheTtl as Er,getWarpWalletAddressFromConfig as Ir,getWarpWalletPrivateKeyFromConfig as ut,WarpCache as Br}from"@vleap/warps";var X=class{constructor(e,t){this.config=e;this.chain=t;this.entry=f(t,e.env,e),this.provider=this.entry.createNetworkProvider(),this.cache=new Br(e.cache?.type)}async signTransaction(e){if(!e||typeof e!="object")throw new Error("Invalid transaction object");let t=ut(this.config,this.chain.name);if(!t)throw new Error("Wallet not initialized - no private key provided");console.log("privateKey",t);let r=t.startsWith("-----");console.log("isPrivateKeyPem",r);let n=r?J.fromPem(t):J.fromString(t),a=new lt(n),o=new Ar(n),s=(await this.provider.getAccount(o.address)).nonce,c=this.cache.get(`nonce:${o.address.toBech32()}`)||0;o.nonce=BigInt(Math.max(c,Number(s))),e.nonce=o.getNonceThenIncrement();let u=new br().computeBytesForSigning(e);return e.signature=await a.sign(u),this.cache.set(`nonce:${o.address.toBech32()}`,Number(o.nonce),Er.OneHour),e}async signMessage(e){let t=ut(this.config,this.chain.name);if(!t)throw new Error("Wallet not initialized - no private key provided");let n=t.startsWith("-----")?J.fromPem(t):J.fromString(t),a=new lt(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=pt.fromString(e).deriveKey(0),n=r.hex();return{address:r.generatePublicKey().toAddress(this.chain.addressHrp).toBech32(),privateKey:n,mnemonic:e}}generate(){let e=pt.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 Ir(this.config,this.chain.name)}};var Y=(i,e,t)=>(r,n)=>{let a=t[r.env];return{chain:i,chainInfo:a,prefix:e,builder:()=>new _(r,a),executor:new H(r,a),results:new S(r,a),serializer:new B,registry:new j(r,a),explorer:new G(i,r),abiBuilder:()=>new I(r,a),brandBuilder:()=>new M(r,a),dataLoader:new L(r,a),wallet:new X(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 Ae={chain:P.Multiversx,identifier:"EGLD",name:"eGold",symbol:"EGLD",decimals:18,logoUrl:"https://vleap.ai/images/tokens/egld.svg"},mt=Y(P.Multiversx,"multiversx",{mainnet:{name:P.Multiversx,displayName:"MultiversX",chainId:"1",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://api.multiversx.com",logoUrl:"https://vleap.ai/images/chains/multiversx.svg",nativeToken:Ae},testnet:{name:P.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:Ae},devnet:{name:P.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:Ae}});import{WarpChainName as Ee}from"@vleap/warps";var Nr={chain:Ee.Vibechain,identifier:"VIBE",name:"VIBE",symbol:"VIBE",decimals:18,logoUrl:"https://vleap.ai/images/tokens/vibe.svg"},be={name:Ee.Vibechain,displayName:"VibeChain",chainId:"V",blockTime:600,addressHrp:"vibe",defaultApiUrl:"https://vibeox-api.multiversx.com",logoUrl:"https://vleap.ai/images/chains/vibechain.svg",nativeToken:Nr},dt=Y(Ee.Vibechain,"vibe",{mainnet:be,testnet:be,devnet:be});var ai=(i,e)=>[mt(i,e),dt(i,e)],si=()=>[ft.Multiversx,ft.Vibechain];import{Address as Vr,AddressValue as Sr,BigUIntType as kr,BigUIntValue as ht,BooleanValue as Fr,BytesValue as Pr,CodeMetadata as Ur,CodeMetadataValue as Rr,CompositeType as Or,CompositeValue as Mr,Field as Ie,FieldDefinition as Be,List as _r,NothingValue as $r,OptionalValue as Ne,OptionValue as Ve,StringValue as Lr,Struct as Dr,StructType as Kr,TokenIdentifierType as qr,TokenIdentifierValue as gt,U16Value as zr,U32Value as Hr,U64Type as Gr,U64Value as yt,U8Value as Qr,VariadicValue as jr}from"@multiversx/sdk-core";var Ci=(i,e)=>i?Ve.newProvided(i):e?Ve.newMissingTyped(e):Ve.newMissing(),Wi=(i,e)=>i?new Ne(i.getType(),i):e?new Ne(e):Ne.newMissing(),vi=i=>{if(i.length===0)throw new Error("Cannot create a list from an empty array");let e=i[0].getType();return new _r(e,i)},xi=i=>jr.fromItems(...i),Ti=i=>{let e=i.map(t=>t.getType());return new Mr(new Or(...e),i)},Ai=i=>Lr.fromUTF8(i),bi=i=>new Qr(i),Ei=i=>new zr(i),Ii=i=>new Hr(i),Bi=i=>new yt(i),Ni=i=>new ht(BigInt(i)),Vi=i=>new Fr(i),Si=i=>new Sr(Vr.newFromBech32(i)),ki=i=>new gt(i),Fi=i=>Pr.fromHex(i),Pi=i=>new Dr(new Kr("EsdtTokenPayment",[new Be("token_identifier","",new qr),new Be("token_nonce","",new Gr),new Be("amount","",new kr)]),[new Ie(new gt(i.token.identifier),"token_identifier"),new Ie(new yt(BigInt(i.token.nonce)),"token_nonce"),new Ie(new ht(BigInt(i.amount)),"amount")]),Ui=i=>new Rr(Ur.newFromBytes(Uint8Array.from(Buffer.from(i,"hex")))),Ri=()=>new $r;export{N as ExplorerUrls,Lt as KnownTokens,yr as MultiversxExplorers,it as MultiversxExplorersConfig,Ae as NativeTokenEgld,Nr as NativeTokenVibe,wr as VibechainExplorers,I as WarpMultiversxAbiBuilder,M as WarpMultiversxBrandBuilder,_ as WarpMultiversxBuilder,Ya as WarpMultiversxConstants,O as WarpMultiversxContractLoader,L as WarpMultiversxDataLoader,H as WarpMultiversxExecutor,G as WarpMultiversxExplorer,j as WarpMultiversxRegistry,S as WarpMultiversxResults,B as WarpMultiversxSerializer,X as WarpMultiversxWallet,Si as address_value,Pi as asset_value,Ni as biguint_value,Vi as boolean_value,Ui as codemeta_value,Ti as composite_value,Y as createMultiversxAdapter,Me as findKnownTokenById,ai as getAllMultiversxAdapters,si as getAllMultiversxChainNames,mt as getMultiversxAdapter,f as getMultiversxEntrypoint,w as getMultiversxRegistryAddress,R as getNormalizedTokenIdentifier,dt as getVibechainAdapter,Fi as hex_value,V as isNativeToken,vi as list_value,Ri as nothing_value,Ci as option_value,Wi as optional_value,Ai as string_value,ot as toTypedConfigInfo,Q as toTypedRegistryInfo,ki as token_value,Ei as u16_value,Ii as u32_value,Bi as u64_value,bi as u8_value,xi 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.53",
3
+ "version": "0.2.0-alpha.54",
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.104"
41
+ "@vleap/warps": "^3.0.0-alpha.105"
42
42
  }
43
43
  }