@vleap/warps-adapter-multiversx 0.2.0-alpha.43 → 0.2.0-alpha.44

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 re=Object.defineProperty;var xe=Object.getOwnPropertyDescriptor;var We=Object.getOwnPropertyNames;var Te=Object.prototype.hasOwnProperty;var ve=(o,e)=>{for(var t in e)re(o,t,{get:e[t],enumerable:!0})},be=(o,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of We(e))!Te.call(o,a)&&a!==t&&re(o,a,{get:()=>e[a],enumerable:!(r=xe(e,a))||r.enumerable});return o};var Ee=o=>be(re({},"__esModule",{value:!0}),o);var Ge={};ve(Ge,{ExplorerUrls:()=>P,KnownTokens:()=>ge,MultiversxExplorers:()=>fe,MultiversxExplorersConfig:()=>ae,NativeTokenEgld:()=>ee,NativeTokenVibe:()=>Ce,VibechainExplorers:()=>he,WarpMultiversxAbiBuilder:()=>F,WarpMultiversxBrandBuilder:()=>D,WarpMultiversxBuilder:()=>z,WarpMultiversxConstants:()=>ne,WarpMultiversxContractLoader:()=>q,WarpMultiversxDataLoader:()=>H,WarpMultiversxExecutor:()=>w,WarpMultiversxExplorer:()=>Q,WarpMultiversxRegistry:()=>G,WarpMultiversxResults:()=>U,WarpMultiversxSerializer:()=>k,address_value:()=>Oe,biguint_value:()=>Ue,boolean_value:()=>_e,codemeta_value:()=>Le,composite_value:()=>Ne,createMultiversxAdapter:()=>j,esdt_value:()=>ie,findKnownTokenById:()=>se,getAllMultiversxAdapters:()=>He,getAllMultiversxChainNames:()=>Qe,getMultiversxAdapter:()=>pe,getMultiversxRegistryAddress:()=>v,getVibechainAdapter:()=>le,hex_value:()=>$e,list_value:()=>Be,nothing_value:()=>qe,option_value:()=>Ae,optional_value:()=>Ie,string_value:()=>Se,token_value:()=>Me,u16_value:()=>Fe,u32_value:()=>Re,u64_value:()=>Pe,u8_value:()=>ke,variadic_value:()=>Ve});module.exports=Ee(Ge);var me=require("@vleap/warps");var $=require("@vleap/warps");var J=require("@multiversx/sdk-core"),V=require("@vleap/warps");var oe=require("@vleap/warps");var d=require("@multiversx/sdk-core"),T=require("@vleap/warps");var M=require("@multiversx/sdk-core"),y=require("@vleap/warps");var n=require("@multiversx/sdk-core"),W=require("@vleap/warps"),de=new RegExp(`${W.WarpConstants.ArgParamsSeparator}(.*)`),k=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(de,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(de,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=r.split(W.WarpConstants.ArgCompositeSeparator),s=new n.TokenComputer,c=s.extractIdentifierFromExtendedIdentifier(a[0]),i=s.extractNonceFromExtendedIdentifier(a[0]);return new n.Struct(this.nativeToType("asset"),[new n.Field(new n.TokenIdentifierValue(c),"token_identifier"),new n.Field(new n.U64Value(BigInt(i)),"token_nonce"),new n.Field(new n.BigUIntValue(BigInt(a[1])),"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 U=class{constructor(e,t){this.config=e;this.chain=t;this.abi=new F(e,t),this.serializer=new k,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:this.config.user?.wallets?.[this.chain.name]||null,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(C=>C.includes("out")||C.includes("event"))){for(let[C,g]of Object.entries(e.results))i[C]=g;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 M.TransactionEventsParser({abi:m}),A=new M.SmartContractTransactionsOutcomeParser({abi:m}).parseExecute({transactionOnNetwork:t,function:a.func||void 0});for(let[C,g]of Object.entries(e.results)){if(g.startsWith(y.WarpConstants.Transform.Prefix))continue;if(g.startsWith("input.")){i[C]=g;continue}let I=(0,y.parseResultsOutIndex)(g);if(I!==null&&I!==s){i[C]=null;continue}let[b,E,R]=g.split(".");if(b==="event"){if(!E||isNaN(Number(R)))continue;let B=Number(R),x=(0,M.findEventsByFirstTopic)(t,E),L=f.parseEvents({events:x})[0],K=Object.values(L)[B]||null;c.push(K),i[C]=K&&K.valueOf()}else if(b==="out"||b.startsWith("out[")){if(!E)continue;let B=Number(E),x=A.values[B-1]||null;R&&(x=x[R]||null),x&&typeof x=="object"&&(x="toFixed"in x?x.toFixed():x.valueOf()),c.push(x),i[C]=x&&x.valueOf()}else i[C]=g}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(A=>parseInt(A)-1);if(f.length===0)return;let h=c[f[0]];for(let A=1;A<f.length;A++){if(h==null)return;h=h[f[A]]}return h};for(let[m,f]of Object.entries(e.results)){if(f.startsWith(y.WarpConstants.Transform.Prefix))continue;let h=(0,y.parseResultsOutIndex)(f);if(h!==null&&h!==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(g,I=[]){if(i.has(g))return i.get(g);if(l.has(g))throw new Error(`Circular dependency detected at action ${g}`);l.add(g);let b=t.actions[g-1];if(!b)throw new Error(`Action ${g} not found`);let E;if(b.type==="query")E=await a.executeQuery(t,g,I);else if(b.type==="collect")E=await a.executeCollect(t,g,I,c);else throw new Error(`Unsupported or interactive action type: ${b.type}`);if(i.set(g,E),t.results)for(let R of Object.values(t.results)){let x=String(R).match(/^out\[(\d+)\]/);if(x){let L=parseInt(x[1],10);L!==g&&!i.has(L)&&await f(L)}}return l.delete(g),E}await f(r,s);let h={};for(let g of i.values())for(let[I,b]of Object.entries(g.results))b!==null?h[I]=b:I in h||(h[I]=null);let A=await(0,y.evaluateResultsCommon)(t,h,r,s,this.config.transform?.runner);return{...i.get(r),action:r,results:A}}};var ne={Egld:{Identifier:"EGLD",EsdtIdentifier:"EGLD-000000",DisplayName:"eGold",Decimals:18}},fe=(r=>(r.MultiversxExplorer="multiversx_explorer",r.MultiversxExplorerDevnet="multiversx_explorer_devnet",r.MultiversxExplorerTestnet="multiversx_explorer_testnet",r))(fe||{}),he=(r=>(r.VibechainExplorer="vibechain_explorer",r.VibechainExplorerDevnet="vibechain_explorer_devnet",r.VibechainExplorerTestnet="vibechain_explorer_testnet",r))(he||{}),ae={multiversx:{mainnet:["multiversx_explorer"],testnet:["multiversx_explorer_testnet"],devnet:["multiversx_explorer_devnet"]},vibechain:{mainnet:["vibechain_explorer"],testnet:["vibechain_explorer_testnet"],devnet:["vibechain_explorer_devnet"]}},P={multiversx_explorer:"https://explorer.multiversx.com",multiversx_explorer_devnet:"https://devnet-explorer.multiversx.com",multiversx_explorer_testnet:"https://testnet-explorer.multiversx.com",vibechain_explorer:"https://vibeox-explorer.multiversx.com",vibechain_explorer_devnet:"https://vibeox-explorer.multiversx.com",vibechain_explorer_testnet:"https://vibeox-explorer.multiversx.com"};var ge=[{id:"EGLD",name:"eGold",decimals:18},{id:"EGLD-000000",name:"eGold",decimals:18},{id:"VIBE-000000",name:"VIBE",decimals:18}],se=o=>ge.find(e=>e.id===o)||null;var p=require("@multiversx/sdk-core"),Ae=(o,e)=>o?p.OptionValue.newProvided(o):e?p.OptionValue.newMissingTyped(e):p.OptionValue.newMissing(),Ie=(o,e)=>o?new p.OptionalValue(o.getType(),o):e?new p.OptionalValue(e):p.OptionalValue.newMissing(),Be=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)},Ve=o=>p.VariadicValue.fromItems(...o),Ne=o=>{let e=o.map(t=>t.getType());return new p.CompositeValue(new p.CompositeType(...e),o)},Se=o=>p.StringValue.fromUTF8(o),ke=o=>new p.U8Value(o),Fe=o=>new p.U16Value(o),Re=o=>new p.U32Value(o),Pe=o=>new p.U64Value(o),Ue=o=>new p.BigUIntValue(BigInt(o)),_e=o=>new p.BooleanValue(o),Oe=o=>new p.AddressValue(p.Address.newFromBech32(o)),Me=o=>new p.TokenIdentifierValue(o),$e=o=>p.BytesValue.fromHex(o),ie=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")]),Le=o=>new p.CodeMetadataValue(p.CodeMetadata.newFromBytes(Uint8Array.from(Buffer.from(o,"hex")))),qe=()=>new p.NothingValue;var De="EGLD-000000",w=class o{constructor(e,t){this.config=e;this.chain=t;this.serializer=new k,this.abi=new F(this.config,this.chain),this.results=new U(this.config,this.chain)}async createTransaction(e){let t=(0,T.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){console.log("createTransferTransaction user wallets",this.config.user?.wallets);let t=this.config.user?.wallets?.[e.chain.name];if(!t)throw new Error("WarpMultiversxExecutor: createTransfer - user address not set");let r=d.Address.newFromBech32(t),a=new d.TransactionsFactoryConfig({chainID:e.chain.chainId}),s=e.data?Buffer.from(this.serializer.stringToTyped(e.data).valueOf()):null;return new d.TransferTransactionsFactory({config:a}).createTransactionForTransfer(r,{receiver:d.Address.newFromBech32(e.destination),nativeAmount:e.value,tokenTransfers:this.toTokenTransfers(e.transfers),data:s?new Uint8Array(s):void 0})}async createContractCallTransaction(e){let t=this.config.user?.wallets?.[e.chain.name];if(!t)throw new Error("WarpMultiversxExecutor: createContractCall - user address not set");let r=(0,T.getWarpActionByIndex)(e.warp,e.action),a=d.Address.newFromBech32(t),s=e.args.map(i=>this.serializer.stringToTyped(i)),c=new d.TransactionsFactoryConfig({chainID:e.chain.chainId});return new d.SmartContractTransactionsFactory({config:c}).createTransactionForExecute(a,{contract:d.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,T.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(B=>this.serializer.stringToTyped(B)),s=o.getChainEntrypoint(e.chain,this.config.env,this.config),c=d.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",h=new d.ArgSerializer,A=r.getEndpoint(m.function||t.func||""),C=(m.returnDataParts||[]).map(B=>Buffer.from(B)),g=h.buffersToValues(C,A.output),{values:I,valuesRaw:b,results:E}=await this.results.extractQueryResults(e.warp,g,e.action,e.resolvedInputs),R=(0,T.getNextInfo)(this.config,[],e.warp,e.action,E);return{success:f,warp:e.warp,action:e.action,user:this.config.user?.wallets?.[e.chain.name]||null,txHash:null,tx:null,next:R,values:I,valuesRaw:b,results:E,messages:(0,T.applyResultsToMessages)(e.warp,E)}}async preprocessInput(e,t,r,a){if(r==="asset"){let[s,c,i]=a.split(T.WarpConstants.ArgCompositeSeparator);if(i)return t;let l=new d.TokenComputer,m=s===ne.Egld.Identifier?0:l.extractNonceFromExtendedIdentifier(s),f=new d.Token({identifier:s,nonce:BigInt(m||0)});if(!l.isFungible(f))return t;let C=se(s)?.decimals;if(C||(C=(await(await fetch(`${e.defaultApiUrl}/tokens/${s}`)).json()).decimals),!C)throw new Error(`WarpMultiversxExecutor: Decimals not found for token ${s}`);let g=ie(new d.TokenTransfer({token:f,amount:(0,T.shiftBigintBy)(c,C)}));return this.serializer.typedToString(g)+T.WarpConstants.ArgCompositeSeparator+C}return t}static getChainEntrypoint(e,t,r){let a="warp-sdk",c=r?(0,T.getProviderUrl)(r,e.name,t,e.defaultApiUrl):e.defaultApiUrl;return t==="devnet"?new d.DevnetEntrypoint({url:c,kind:"api",clientName:a}):t==="testnet"?new d.TestnetEntrypoint({url:c,kind:"api",clientName:a}):new d.MainnetEntrypoint({url:c,kind:"api",clientName:a})}async signMessage(e,t){let r=d.UserSecretKey.fromString(t);return(await new d.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:De}:t).map(t=>{let a=new d.TokenComputer().extractNonceFromExtendedIdentifier(t.identifier);return new d.TokenTransfer({token:new d.Token({identifier:t.identifier,nonce:BigInt(a||0)}),amount:t.amount})})}};var q=class{constructor(e){this.config=e}async getContract(e,t){try{let s=await w.getChainEntrypoint(t,this.config.env).createNetworkProvider().doGetGeneric(`accounts/${e}`);return{address:e,owner:s.ownerAddress,verified:s.isVerified||!1}}catch(r){return oe.WarpLogger.error("WarpContractLoader: getContract error",r),null}}async getVerificationInfo(e,t){try{let s=await w.getChainEntrypoint(t,this.config.env).createNetworkProvider().doGetGeneric(`accounts/${e}/verification`);return{codeHash:s.codeHash,abi:s.source.abi}}catch(r){return oe.WarpLogger.error("WarpContractLoader: getVerificationInfo error",r),null}}};var F=class{constructor(e,t){this.config=e;this.chain=t;this.contractLoader=new q(this.config),this.cache=new V.WarpCache(this.config.cache?.type)}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=V.WarpCacheKey.WarpAbi(this.config.env,e);if(t){let c=this.cache.get(r);if(c)return V.WarpLogger.info(`WarpAbiBuilder (createFromTransactionHash): Warp abi found in cache: ${e}`),c}let s=w.getChainEntrypoint(this.chain,this.config.env).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 V.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 J.AbiRegistry.create(t.abi)}async fetchAbi(e){if(!e.abi)throw new Error("WarpActionExecutor: ABI not found");if(e.abi.startsWith(V.WarpConstants.IdentifierType.Hash)){let t=e.abi.split(V.WarpConstants.IdentifierParamSeparatorDefault)[1],r=await this.createFromTransactionHash(t);if(!r)throw new Error(`WarpActionExecutor: ABI not found for hash: ${e.abi}`);return J.AbiRegistry.create(r.content)}else{let r=await(await fetch(e.abi)).json();return J.AbiRegistry.create(r)}}};var _=require("@multiversx/sdk-core"),X=require("@vleap/warps"),ye=require("buffer");var D=class{constructor(e,t){this.config=e;this.chain=t;this.core=new X.WarpBrandBuilder(e)}async createInscriptionTransaction(e){let t=this.config.user?.wallets?.[this.chain.name];if(!t)throw new Error("BrandBuilder: user address not set");let r=new _.TransactionsFactoryConfig({chainID:this.chain.chainId}),a=new _.TransferTransactionsFactory({config:r}),s=_.Address.newFromBech32(t),c=JSON.stringify(e);return await a.createTransactionForNativeTokenTransfer(s,{receiver:_.Address.newFromBech32(t),nativeAmount:BigInt(0),data:Uint8Array.from(ye.Buffer.from(c))})}async createFromTransaction(e,t=!1){return await this.core.createFromRaw(e.data.toString(),t)}async createFromTransactionHash(e){let r=w.getChainEntrypoint(this.chain,this.config.env).createNetworkProvider();try{let a=await r.getTransaction(e);return this.createFromTransaction(a)}catch(a){return X.WarpLogger.error("BrandBuilder: Error creating from transaction hash",a),null}}};var O=require("@multiversx/sdk-core"),N=require("@vleap/warps");var z=class extends N.WarpBuilder{constructor(t,r){super(t);this.config=t;this.chain=r;this.cache=new N.WarpCache(t.cache?.type),this.core=new N.WarpBuilder(t)}async createInscriptionTransaction(t){let r=this.config.user?.wallets?.[this.chain.name];if(!r)throw new Error("WarpBuilder: user address not set");let a=new O.TransactionsFactoryConfig({chainID:this.chain.chainId}),s=new O.TransferTransactionsFactory({config:a}),c=O.Address.newFromBech32(r),i=JSON.stringify(t),l=await s.createTransactionForTransfer(c,{receiver:O.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=N.WarpCacheKey.Warp(this.config.env,t);if(r){let i=this.cache.get(a);if(i)return N.WarpLogger.info(`WarpBuilder (createFromTransactionHash): Warp found in cache: ${t}`),i}let c=w.getChainEntrypoint(this.chain,this.config.env).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 N.WarpLogger.error("WarpBuilder: Error creating from transaction hash",i),null}}};var Y=require("@multiversx/sdk-core");var H=class{constructor(e,t){this.config=e;this.chain=t}async getAccount(e){let r=await w.getChainEntrypoint(this.chain,this.config.env,this.config).createNetworkProvider().getAccount(Y.Address.newFromBech32(e));return{chain:this.chain.name,address:r.address.toBech32(),balance:r.balance}}async getAccountAssets(e){let t=w.getChainEntrypoint(this.chain,this.config.env,this.config).createNetworkProvider(),r=t.getAccount(Y.Address.newFromBech32(e)),a=t.getFungibleTokensOfAccount(Y.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,amount:l.amount,decimals:l.raw.decimals,logoUrl:l.raw.assets?.pngUrl||""}))),i}async getAccountActions(e,t){let r=w.getChainEntrypoint(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:m.status,createdAt:new Date(m.timestampMs||m.timestamp*1e3).toISOString()}))}};var Q=class{constructor(e,t){this.chain=e;this.config=t}getExplorers(){let e=ae[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=P[t];if(s)return s}if(e){let s=P[e];if(s)return s}let r=this.getPrimaryExplorer();return P[r]||P[r]}getAccountUrl(e,t){return`${this.getExplorerUrlByName(t)}/accounts/${e}`}getTransactionUrl(e,t){return`${this.getExplorerUrlByName(t)}/transactions/${e}`}getBlockUrl(e,t){return`${this.getExplorerUrlByName(t)}/blocks/${e}`}getAssetUrl(e,t){return`${this.getExplorerUrlByName(t)}/tokens/${e}`}getContractUrl(e,t){return`${this.getExplorerUrlByName(t)}/accounts/${e}`}getAllExplorers(){return this.getExplorers()}getExplorerByName(e){return this.getExplorers().find(r=>r.toLowerCase()===e.toLowerCase())}getAccountUrls(e){let t=this.getAllExplorers(),r={};return t.forEach(a=>{let s=P[a];s&&(r[a]=`${s}/accounts/${e}`)}),r}getTransactionUrls(e){let t=this.getAllExplorers(),r={};return t.forEach(a=>{let s=P[a];s&&(r[a]=`${s}/transactions/${e}`)}),r}};var u=require("@multiversx/sdk-core"),S=require("@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"}],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}]},{name:"setChain",onlyOwner:!0,mutability:"mutable",inputs:[{name:"name",type:"bytes"},{name:"display_name",type:"bytes"},{name:"chain_id",type:"bytes"},{name:"block_time",type:"u32"},{name:"address_hrp",type:"bytes"},{name:"api_url",type:"bytes"},{name:"explorer_url",type:"bytes"},{name:"native_token",type:"bytes"}],outputs:[]},{name:"removeChain",onlyOwner:!0,mutability:"mutable",inputs:[{name:"name",type:"bytes"}],outputs:[]},{name:"getChain",mutability:"readonly",inputs:[{name:"name",type:"bytes"}],outputs:[{type:"ChainView"}]},{name:"getChains",mutability:"readonly",inputs:[],outputs:[{type:"variadic<ChainView>",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:{ChainView:{type:"struct",fields:[{name:"name",type:"bytes"},{name:"display_name",type:"bytes"},{name:"chain_id",type:"bytes"},{name:"block_time",type:"u32"},{name:"address_hrp",type:"bytes"},{name:"api_url",type:"bytes"},{name:"explorer_url",type:"bytes"},{name:"native_token",type:"bytes"}]},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 Z=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}),we=o=>({unitPrice:BigInt(o.unit_price.toString()),admins:o.admins.map(e=>e.toBech32())});var G=class{constructor(e,t){this.config=e;this.chain=t;this.cache=new S.WarpCache(e.cache?.type),this.registryConfig={unitPrice:BigInt(0),admins:[]},this.userWallet=this.config.user?.wallets?.[this.chain.name]||null}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){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 r=u.Address.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(r,{contract:u.Address.newFromBech32(v(this.config.env)),function:"upgradeWarp",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[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=S.WarpCacheKey.RegistryInfo(this.config.env,e),a=t?this.cache.get(r):null;if(a)return S.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?Z(m):null,h=f?.brand?await this.fetchBrand(f.brand):null;return t&&t.ttl&&this.cache.set(r,{registryInfo:f,brand:h},t.ttl),{registryInfo:f,brand:h}}catch{return{registryInfo:null,brand:null}}}async getInfoByHash(e,t){try{let r=S.WarpCacheKey.RegistryInfo(this.config.env,e);if(t){let h=this.cache.get(r);if(h)return S.WarpLogger.info(`WarpRegistry (getInfoByHash): RegistryInfo found in cache: ${e}`),h}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?Z(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(Z)}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(h=>h.toString("hex")),m={ttl:365*24*60*60};return(await Promise.all(l.map(h=>this.fetchBrand(h,m)))).filter(h=>h!==null)}catch{return[]}}async fetchBrand(e,t){let r=S.WarpCacheKey.Brand(this.config.env,e),a=t?this.cache.get(r):null;if(a)return S.WarpLogger.info(`WarpRegistry (fetchBrand): Brand found in cache: ${e}`),a;let c=w.getChainEntrypoint(this.chain,this.config.env).createNetworkProvider();try{let i=await c.getTransaction(e),l=JSON.parse(i.data.toString());return l.meta={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?we(r):null;this.registryConfig=a||{unitPrice:BigInt(0),admins:[]}}getFactory(){let e=new u.TransactionsFactoryConfig({chainID:this.chain.chainId}),t=u.AbiRegistry.create(ce);return new u.SmartContractTransactionsFactory({config:e,abi:t})}getController(){let e=w.getChainEntrypoint(this.chain,this.config.env),t=u.AbiRegistry.create(ce);return e.createSmartContractController(t)}isCurrentUserAdmin(){return!!this.userWallet&&this.registryConfig.admins.includes(this.userWallet)}};var j=(o,e,t)=>(r,a)=>{let s=t[r.env];return{chain:o,chainInfo:s,prefix:e,builder:()=>new z(r,s),executor:new w(r,s),results:new U(r,s),serializer:new k,registry:new G(r,s),explorer:new Q(o,r),abiBuilder:()=>new F(r,s),brandBuilder:()=>new D(r,s),dataLoader:new H(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 ee={chain:$.WarpChainName.Multiversx,identifier:"EGLD",name:"eGold",decimals:18,logoUrl:"https://vleap.ai/images/tokens/egld.svg"},pe=j($.WarpChainName.Multiversx,"mvx",{mainnet:{name:$.WarpChainName.Multiversx,displayName:"MultiversX",chainId:"1",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://api.multiversx.com",nativeToken:ee},testnet:{name:$.WarpChainName.Multiversx,displayName:"MultiversX Testnet",chainId:"T",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://testnet-api.multiversx.com",nativeToken:ee},devnet:{name:$.WarpChainName.Multiversx,displayName:"MultiversX Devnet",chainId:"D",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://devnet-api.multiversx.com",nativeToken:ee}});var te=require("@vleap/warps");var Ce={chain:te.WarpChainName.Vibechain,identifier:"VIBE",name:"VIBE",decimals:18,logoUrl:"https://vleap.ai/images/tokens/vibe.svg"},ue={name:te.WarpChainName.Vibechain,displayName:"VibeChain",chainId:"V",blockTime:600,addressHrp:"vibe",defaultApiUrl:"https://vibeox-api.multiversx.com",nativeToken:Ce},le=j(te.WarpChainName.Vibechain,"vibe",{mainnet:ue,testnet:ue,devnet:ue});var He=(o,e)=>[pe(o,e),le(o,e)],Qe=()=>[me.WarpChainName.Multiversx,me.WarpChainName.Vibechain];0&&(module.exports={ExplorerUrls,KnownTokens,MultiversxExplorers,MultiversxExplorersConfig,NativeTokenEgld,NativeTokenVibe,VibechainExplorers,WarpMultiversxAbiBuilder,WarpMultiversxBrandBuilder,WarpMultiversxBuilder,WarpMultiversxConstants,WarpMultiversxContractLoader,WarpMultiversxDataLoader,WarpMultiversxExecutor,WarpMultiversxExplorer,WarpMultiversxRegistry,WarpMultiversxResults,WarpMultiversxSerializer,address_value,biguint_value,boolean_value,codemeta_value,composite_value,createMultiversxAdapter,esdt_value,findKnownTokenById,getAllMultiversxAdapters,getAllMultiversxChainNames,getMultiversxAdapter,getMultiversxRegistryAddress,getVibechainAdapter,hex_value,list_value,nothing_value,option_value,optional_value,string_value,token_value,u16_value,u32_value,u64_value,u8_value,variadic_value});
1
+ "use strict";var ne=Object.defineProperty;var xe=Object.getOwnPropertyDescriptor;var We=Object.getOwnPropertyNames;var Te=Object.prototype.hasOwnProperty;var ve=(o,e)=>{for(var t in e)ne(o,t,{get:e[t],enumerable:!0})},be=(o,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of We(e))!Te.call(o,a)&&a!==t&&ne(o,a,{get:()=>e[a],enumerable:!(r=xe(e,a))||r.enumerable});return o};var Ee=o=>be(ne({},"__esModule",{value:!0}),o);var Ge={};ve(Ge,{ExplorerUrls:()=>P,KnownTokens:()=>ge,MultiversxExplorers:()=>de,MultiversxExplorersConfig:()=>ae,NativeTokenEgld:()=>te,NativeTokenVibe:()=>Ce,VibechainExplorers:()=>fe,WarpMultiversxAbiBuilder:()=>F,WarpMultiversxBrandBuilder:()=>z,WarpMultiversxBuilder:()=>H,WarpMultiversxConstants:()=>U,WarpMultiversxContractLoader:()=>D,WarpMultiversxDataLoader:()=>Q,WarpMultiversxExecutor:()=>w,WarpMultiversxExplorer:()=>G,WarpMultiversxRegistry:()=>j,WarpMultiversxResults:()=>_,WarpMultiversxSerializer:()=>k,address_value:()=>Oe,biguint_value:()=>Ue,boolean_value:()=>_e,codemeta_value:()=>Le,composite_value:()=>Ne,createMultiversxAdapter:()=>K,esdt_value:()=>ie,findKnownTokenById:()=>se,getAllMultiversxAdapters:()=>He,getAllMultiversxChainNames:()=>Qe,getMultiversxAdapter:()=>pe,getMultiversxRegistryAddress:()=>v,getVibechainAdapter:()=>le,hex_value:()=>$e,list_value:()=>Be,nothing_value:()=>qe,option_value:()=>Ae,optional_value:()=>Ie,string_value:()=>Se,token_value:()=>Me,u16_value:()=>Fe,u32_value:()=>Re,u64_value:()=>Pe,u8_value:()=>ke,variadic_value:()=>Ve});module.exports=Ee(Ge);var me=require("@vleap/warps");var L=require("@vleap/warps");var X=require("@multiversx/sdk-core"),V=require("@vleap/warps");var oe=require("@vleap/warps");var d=require("@multiversx/sdk-core"),T=require("@vleap/warps");var $=require("@multiversx/sdk-core"),y=require("@vleap/warps");var n=require("@multiversx/sdk-core"),W=require("@vleap/warps");var U={Egld:{Identifier:"EGLD",EsdtIdentifier:"EGLD-000000",DisplayName:"eGold",Decimals:18}},de=(r=>(r.MultiversxExplorer="multiversx_explorer",r.MultiversxExplorerDevnet="multiversx_explorer_devnet",r.MultiversxExplorerTestnet="multiversx_explorer_testnet",r))(de||{}),fe=(r=>(r.VibechainExplorer="vibechain_explorer",r.VibechainExplorerDevnet="vibechain_explorer_devnet",r.VibechainExplorerTestnet="vibechain_explorer_testnet",r))(fe||{}),ae={multiversx:{mainnet:["multiversx_explorer"],testnet:["multiversx_explorer_testnet"],devnet:["multiversx_explorer_devnet"]},vibechain:{mainnet:["vibechain_explorer"],testnet:["vibechain_explorer_testnet"],devnet:["vibechain_explorer_devnet"]}},P={multiversx_explorer:"https://explorer.multiversx.com",multiversx_explorer_devnet:"https://devnet-explorer.multiversx.com",multiversx_explorer_testnet:"https://testnet-explorer.multiversx.com",vibechain_explorer:"https://vibeox-explorer.multiversx.com",vibechain_explorer_devnet:"https://vibeox-explorer.multiversx.com",vibechain_explorer_testnet:"https://vibeox-explorer.multiversx.com"};var he=new RegExp(`${W.WarpConstants.ArgParamsSeparator}(.*)`),k=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(he,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(he,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=r.split(W.WarpConstants.ArgCompositeSeparator),s=new n.TokenComputer,c=a[0]===U.Egld.Identifier?U.Egld.EsdtIdentifier:s.extractIdentifierFromExtendedIdentifier(a[0]),i=a[0]===U.Egld.Identifier?0:s.extractNonceFromExtendedIdentifier(a[0]);return new n.Struct(this.nativeToType("asset"),[new n.Field(new n.TokenIdentifierValue(c),"token_identifier"),new n.Field(new n.U64Value(BigInt(i)),"token_nonce"),new n.Field(new n.BigUIntValue(BigInt(a[1])),"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 _=class{constructor(e,t){this.config=e;this.chain=t;this.abi=new F(e,t),this.serializer=new k,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:this.config.user?.wallets?.[this.chain.name]||null,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(C=>C.includes("out")||C.includes("event"))){for(let[C,g]of Object.entries(e.results))i[C]=g;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 $.TransactionEventsParser({abi:m}),A=new $.SmartContractTransactionsOutcomeParser({abi:m}).parseExecute({transactionOnNetwork:t,function:a.func||void 0});for(let[C,g]of Object.entries(e.results)){if(g.startsWith(y.WarpConstants.Transform.Prefix))continue;if(g.startsWith("input.")){i[C]=g;continue}let I=(0,y.parseResultsOutIndex)(g);if(I!==null&&I!==s){i[C]=null;continue}let[b,E,R]=g.split(".");if(b==="event"){if(!E||isNaN(Number(R)))continue;let B=Number(R),x=(0,$.findEventsByFirstTopic)(t,E),q=f.parseEvents({events:x})[0],J=Object.values(q)[B]||null;c.push(J),i[C]=J&&J.valueOf()}else if(b==="out"||b.startsWith("out[")){if(!E)continue;let B=Number(E),x=A.values[B-1]||null;R&&(x=x[R]||null),x&&typeof x=="object"&&(x="toFixed"in x?x.toFixed():x.valueOf()),c.push(x),i[C]=x&&x.valueOf()}else i[C]=g}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(A=>parseInt(A)-1);if(f.length===0)return;let h=c[f[0]];for(let A=1;A<f.length;A++){if(h==null)return;h=h[f[A]]}return h};for(let[m,f]of Object.entries(e.results)){if(f.startsWith(y.WarpConstants.Transform.Prefix))continue;let h=(0,y.parseResultsOutIndex)(f);if(h!==null&&h!==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(g,I=[]){if(i.has(g))return i.get(g);if(l.has(g))throw new Error(`Circular dependency detected at action ${g}`);l.add(g);let b=t.actions[g-1];if(!b)throw new Error(`Action ${g} not found`);let E;if(b.type==="query")E=await a.executeQuery(t,g,I);else if(b.type==="collect")E=await a.executeCollect(t,g,I,c);else throw new Error(`Unsupported or interactive action type: ${b.type}`);if(i.set(g,E),t.results)for(let R of Object.values(t.results)){let x=String(R).match(/^out\[(\d+)\]/);if(x){let q=parseInt(x[1],10);q!==g&&!i.has(q)&&await f(q)}}return l.delete(g),E}await f(r,s);let h={};for(let g of i.values())for(let[I,b]of Object.entries(g.results))b!==null?h[I]=b:I in h||(h[I]=null);let A=await(0,y.evaluateResultsCommon)(t,h,r,s,this.config.transform?.runner);return{...i.get(r),action:r,results:A}}};var ge=[{id:"EGLD",name:"eGold",decimals:18},{id:"EGLD-000000",name:"eGold",decimals:18},{id:"VIBE-000000",name:"VIBE",decimals:18}],se=o=>ge.find(e=>e.id===o)||null;var p=require("@multiversx/sdk-core"),Ae=(o,e)=>o?p.OptionValue.newProvided(o):e?p.OptionValue.newMissingTyped(e):p.OptionValue.newMissing(),Ie=(o,e)=>o?new p.OptionalValue(o.getType(),o):e?new p.OptionalValue(e):p.OptionalValue.newMissing(),Be=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)},Ve=o=>p.VariadicValue.fromItems(...o),Ne=o=>{let e=o.map(t=>t.getType());return new p.CompositeValue(new p.CompositeType(...e),o)},Se=o=>p.StringValue.fromUTF8(o),ke=o=>new p.U8Value(o),Fe=o=>new p.U16Value(o),Re=o=>new p.U32Value(o),Pe=o=>new p.U64Value(o),Ue=o=>new p.BigUIntValue(BigInt(o)),_e=o=>new p.BooleanValue(o),Oe=o=>new p.AddressValue(p.Address.newFromBech32(o)),Me=o=>new p.TokenIdentifierValue(o),$e=o=>p.BytesValue.fromHex(o),ie=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")]),Le=o=>new p.CodeMetadataValue(p.CodeMetadata.newFromBytes(Uint8Array.from(Buffer.from(o,"hex")))),qe=()=>new p.NothingValue;var De="EGLD-000000",w=class o{constructor(e,t){this.config=e;this.chain=t;this.serializer=new k,this.abi=new F(this.config,this.chain),this.results=new _(this.config,this.chain)}async createTransaction(e){let t=(0,T.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){console.log("createTransferTransaction user wallets",this.config.user?.wallets);let t=this.config.user?.wallets?.[e.chain.name];if(!t)throw new Error("WarpMultiversxExecutor: createTransfer - user address not set");let r=d.Address.newFromBech32(t),a=new d.TransactionsFactoryConfig({chainID:e.chain.chainId}),s=e.data?Buffer.from(this.serializer.stringToTyped(e.data).valueOf()):null;return new d.TransferTransactionsFactory({config:a}).createTransactionForTransfer(r,{receiver:d.Address.newFromBech32(e.destination),nativeAmount:e.value,tokenTransfers:this.toTokenTransfers(e.transfers),data:s?new Uint8Array(s):void 0})}async createContractCallTransaction(e){let t=this.config.user?.wallets?.[e.chain.name];if(!t)throw new Error("WarpMultiversxExecutor: createContractCall - user address not set");let r=(0,T.getWarpActionByIndex)(e.warp,e.action),a=d.Address.newFromBech32(t),s=e.args.map(i=>this.serializer.stringToTyped(i)),c=new d.TransactionsFactoryConfig({chainID:e.chain.chainId});return new d.SmartContractTransactionsFactory({config:c}).createTransactionForExecute(a,{contract:d.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,T.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(B=>this.serializer.stringToTyped(B)),s=o.getChainEntrypoint(e.chain,this.config.env,this.config),c=d.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",h=new d.ArgSerializer,A=r.getEndpoint(m.function||t.func||""),C=(m.returnDataParts||[]).map(B=>Buffer.from(B)),g=h.buffersToValues(C,A.output),{values:I,valuesRaw:b,results:E}=await this.results.extractQueryResults(e.warp,g,e.action,e.resolvedInputs),R=(0,T.getNextInfo)(this.config,[],e.warp,e.action,E);return{success:f,warp:e.warp,action:e.action,user:this.config.user?.wallets?.[e.chain.name]||null,txHash:null,tx:null,next:R,values:I,valuesRaw:b,results:E,messages:(0,T.applyResultsToMessages)(e.warp,E)}}async preprocessInput(e,t,r,a){if(r==="asset"){let[s,c,i]=a.split(T.WarpConstants.ArgCompositeSeparator);if(i)return t;let l=new d.TokenComputer,m=s===U.Egld.Identifier?0:l.extractNonceFromExtendedIdentifier(s),f=new d.Token({identifier:s,nonce:BigInt(m||0)});if(!l.isFungible(f))return t;let C=se(s)?.decimals;if(C||(C=(await(await fetch(`${e.defaultApiUrl}/tokens/${s}`)).json()).decimals),!C)throw new Error(`WarpMultiversxExecutor: Decimals not found for token ${s}`);let g=ie(new d.TokenTransfer({token:f,amount:(0,T.shiftBigintBy)(c,C)}));return this.serializer.typedToString(g)+T.WarpConstants.ArgCompositeSeparator+C}return t}static getChainEntrypoint(e,t,r){let a="warp-sdk",c=r?(0,T.getProviderUrl)(r,e.name,t,e.defaultApiUrl):e.defaultApiUrl;return t==="devnet"?new d.DevnetEntrypoint({url:c,kind:"api",clientName:a}):t==="testnet"?new d.TestnetEntrypoint({url:c,kind:"api",clientName:a}):new d.MainnetEntrypoint({url:c,kind:"api",clientName:a})}async signMessage(e,t){let r=d.UserSecretKey.fromString(t);return(await new d.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:De}:t).map(t=>{let a=new d.TokenComputer().extractNonceFromExtendedIdentifier(t.identifier);return new d.TokenTransfer({token:new d.Token({identifier:t.identifier,nonce:BigInt(a||0)}),amount:t.amount})})}};var D=class{constructor(e){this.config=e}async getContract(e,t){try{let s=await w.getChainEntrypoint(t,this.config.env).createNetworkProvider().doGetGeneric(`accounts/${e}`);return{address:e,owner:s.ownerAddress,verified:s.isVerified||!1}}catch(r){return oe.WarpLogger.error("WarpContractLoader: getContract error",r),null}}async getVerificationInfo(e,t){try{let s=await w.getChainEntrypoint(t,this.config.env).createNetworkProvider().doGetGeneric(`accounts/${e}/verification`);return{codeHash:s.codeHash,abi:s.source.abi}}catch(r){return oe.WarpLogger.error("WarpContractLoader: getVerificationInfo error",r),null}}};var F=class{constructor(e,t){this.config=e;this.chain=t;this.contractLoader=new D(this.config),this.cache=new V.WarpCache(this.config.cache?.type)}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=V.WarpCacheKey.WarpAbi(this.config.env,e);if(t){let c=this.cache.get(r);if(c)return V.WarpLogger.info(`WarpAbiBuilder (createFromTransactionHash): Warp abi found in cache: ${e}`),c}let s=w.getChainEntrypoint(this.chain,this.config.env).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 V.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 X.AbiRegistry.create(t.abi)}async fetchAbi(e){if(!e.abi)throw new Error("WarpActionExecutor: ABI not found");if(e.abi.startsWith(V.WarpConstants.IdentifierType.Hash)){let t=e.abi.split(V.WarpConstants.IdentifierParamSeparatorDefault)[1],r=await this.createFromTransactionHash(t);if(!r)throw new Error(`WarpActionExecutor: ABI not found for hash: ${e.abi}`);return X.AbiRegistry.create(r.content)}else{let r=await(await fetch(e.abi)).json();return X.AbiRegistry.create(r)}}};var O=require("@multiversx/sdk-core"),Y=require("@vleap/warps"),ye=require("buffer");var z=class{constructor(e,t){this.config=e;this.chain=t;this.core=new Y.WarpBrandBuilder(e)}async createInscriptionTransaction(e){let t=this.config.user?.wallets?.[this.chain.name];if(!t)throw new Error("BrandBuilder: user address not set");let r=new O.TransactionsFactoryConfig({chainID:this.chain.chainId}),a=new O.TransferTransactionsFactory({config:r}),s=O.Address.newFromBech32(t),c=JSON.stringify(e);return await a.createTransactionForNativeTokenTransfer(s,{receiver:O.Address.newFromBech32(t),nativeAmount:BigInt(0),data:Uint8Array.from(ye.Buffer.from(c))})}async createFromTransaction(e,t=!1){return await this.core.createFromRaw(e.data.toString(),t)}async createFromTransactionHash(e){let r=w.getChainEntrypoint(this.chain,this.config.env).createNetworkProvider();try{let a=await r.getTransaction(e);return this.createFromTransaction(a)}catch(a){return Y.WarpLogger.error("BrandBuilder: Error creating from transaction hash",a),null}}};var M=require("@multiversx/sdk-core"),N=require("@vleap/warps");var H=class extends N.WarpBuilder{constructor(t,r){super(t);this.config=t;this.chain=r;this.cache=new N.WarpCache(t.cache?.type),this.core=new N.WarpBuilder(t)}async createInscriptionTransaction(t){let r=this.config.user?.wallets?.[this.chain.name];if(!r)throw new Error("WarpBuilder: user address not set");let a=new M.TransactionsFactoryConfig({chainID:this.chain.chainId}),s=new M.TransferTransactionsFactory({config:a}),c=M.Address.newFromBech32(r),i=JSON.stringify(t),l=await s.createTransactionForTransfer(c,{receiver:M.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=N.WarpCacheKey.Warp(this.config.env,t);if(r){let i=this.cache.get(a);if(i)return N.WarpLogger.info(`WarpBuilder (createFromTransactionHash): Warp found in cache: ${t}`),i}let c=w.getChainEntrypoint(this.chain,this.config.env).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 N.WarpLogger.error("WarpBuilder: Error creating from transaction hash",i),null}}};var Z=require("@multiversx/sdk-core");var Q=class{constructor(e,t){this.config=e;this.chain=t}async getAccount(e){let r=await w.getChainEntrypoint(this.chain,this.config.env,this.config).createNetworkProvider().getAccount(Z.Address.newFromBech32(e));return{chain:this.chain.name,address:r.address.toBech32(),balance:r.balance}}async getAccountAssets(e){let t=w.getChainEntrypoint(this.chain,this.config.env,this.config).createNetworkProvider(),r=t.getAccount(Z.Address.newFromBech32(e)),a=t.getFungibleTokensOfAccount(Z.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,amount:l.amount,decimals:l.raw.decimals,logoUrl:l.raw.assets?.pngUrl||""}))),i}async getAccountActions(e,t){let r=w.getChainEntrypoint(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:m.status,createdAt:new Date(m.timestampMs||m.timestamp*1e3).toISOString()}))}};var G=class{constructor(e,t){this.chain=e;this.config=t}getExplorers(){let e=ae[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=P[t];if(s)return s}if(e){let s=P[e];if(s)return s}let r=this.getPrimaryExplorer();return P[r]||P[r]}getAccountUrl(e,t){return`${this.getExplorerUrlByName(t)}/accounts/${e}`}getTransactionUrl(e,t){return`${this.getExplorerUrlByName(t)}/transactions/${e}`}getBlockUrl(e,t){return`${this.getExplorerUrlByName(t)}/blocks/${e}`}getAssetUrl(e,t){return`${this.getExplorerUrlByName(t)}/tokens/${e}`}getContractUrl(e,t){return`${this.getExplorerUrlByName(t)}/accounts/${e}`}getAllExplorers(){return this.getExplorers()}getExplorerByName(e){return this.getExplorers().find(r=>r.toLowerCase()===e.toLowerCase())}getAccountUrls(e){let t=this.getAllExplorers(),r={};return t.forEach(a=>{let s=P[a];s&&(r[a]=`${s}/accounts/${e}`)}),r}getTransactionUrls(e){let t=this.getAllExplorers(),r={};return t.forEach(a=>{let s=P[a];s&&(r[a]=`${s}/transactions/${e}`)}),r}};var u=require("@multiversx/sdk-core"),S=require("@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"}],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}]},{name:"setChain",onlyOwner:!0,mutability:"mutable",inputs:[{name:"name",type:"bytes"},{name:"display_name",type:"bytes"},{name:"chain_id",type:"bytes"},{name:"block_time",type:"u32"},{name:"address_hrp",type:"bytes"},{name:"api_url",type:"bytes"},{name:"explorer_url",type:"bytes"},{name:"native_token",type:"bytes"}],outputs:[]},{name:"removeChain",onlyOwner:!0,mutability:"mutable",inputs:[{name:"name",type:"bytes"}],outputs:[]},{name:"getChain",mutability:"readonly",inputs:[{name:"name",type:"bytes"}],outputs:[{type:"ChainView"}]},{name:"getChains",mutability:"readonly",inputs:[],outputs:[{type:"variadic<ChainView>",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:{ChainView:{type:"struct",fields:[{name:"name",type:"bytes"},{name:"display_name",type:"bytes"},{name:"chain_id",type:"bytes"},{name:"block_time",type:"u32"},{name:"address_hrp",type:"bytes"},{name:"api_url",type:"bytes"},{name:"explorer_url",type:"bytes"},{name:"native_token",type:"bytes"}]},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 ee=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}),we=o=>({unitPrice:BigInt(o.unit_price.toString()),admins:o.admins.map(e=>e.toBech32())});var j=class{constructor(e,t){this.config=e;this.chain=t;this.cache=new S.WarpCache(e.cache?.type),this.registryConfig={unitPrice:BigInt(0),admins:[]},this.userWallet=this.config.user?.wallets?.[this.chain.name]||null}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){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 r=u.Address.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(r,{contract:u.Address.newFromBech32(v(this.config.env)),function:"upgradeWarp",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[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=S.WarpCacheKey.RegistryInfo(this.config.env,e),a=t?this.cache.get(r):null;if(a)return S.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?ee(m):null,h=f?.brand?await this.fetchBrand(f.brand):null;return t&&t.ttl&&this.cache.set(r,{registryInfo:f,brand:h},t.ttl),{registryInfo:f,brand:h}}catch{return{registryInfo:null,brand:null}}}async getInfoByHash(e,t){try{let r=S.WarpCacheKey.RegistryInfo(this.config.env,e);if(t){let h=this.cache.get(r);if(h)return S.WarpLogger.info(`WarpRegistry (getInfoByHash): RegistryInfo found in cache: ${e}`),h}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?ee(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(ee)}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(h=>h.toString("hex")),m={ttl:365*24*60*60};return(await Promise.all(l.map(h=>this.fetchBrand(h,m)))).filter(h=>h!==null)}catch{return[]}}async fetchBrand(e,t){let r=S.WarpCacheKey.Brand(this.config.env,e),a=t?this.cache.get(r):null;if(a)return S.WarpLogger.info(`WarpRegistry (fetchBrand): Brand found in cache: ${e}`),a;let c=w.getChainEntrypoint(this.chain,this.config.env).createNetworkProvider();try{let i=await c.getTransaction(e),l=JSON.parse(i.data.toString());return l.meta={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?we(r):null;this.registryConfig=a||{unitPrice:BigInt(0),admins:[]}}getFactory(){let e=new u.TransactionsFactoryConfig({chainID:this.chain.chainId}),t=u.AbiRegistry.create(ce);return new u.SmartContractTransactionsFactory({config:e,abi:t})}getController(){let e=w.getChainEntrypoint(this.chain,this.config.env),t=u.AbiRegistry.create(ce);return e.createSmartContractController(t)}isCurrentUserAdmin(){return!!this.userWallet&&this.registryConfig.admins.includes(this.userWallet)}};var K=(o,e,t)=>(r,a)=>{let s=t[r.env];return{chain:o,chainInfo:s,prefix:e,builder:()=>new H(r,s),executor:new w(r,s),results:new _(r,s),serializer:new k,registry:new j(r,s),explorer:new G(o,r),abiBuilder:()=>new F(r,s),brandBuilder:()=>new z(r,s),dataLoader:new Q(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 te={chain:L.WarpChainName.Multiversx,identifier:"EGLD",name:"eGold",decimals:18,logoUrl:"https://vleap.ai/images/tokens/egld.svg"},pe=K(L.WarpChainName.Multiversx,"mvx",{mainnet:{name:L.WarpChainName.Multiversx,displayName:"MultiversX",chainId:"1",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://api.multiversx.com",nativeToken:te},testnet:{name:L.WarpChainName.Multiversx,displayName:"MultiversX Testnet",chainId:"T",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://testnet-api.multiversx.com",nativeToken:te},devnet:{name:L.WarpChainName.Multiversx,displayName:"MultiversX Devnet",chainId:"D",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://devnet-api.multiversx.com",nativeToken:te}});var re=require("@vleap/warps");var Ce={chain:re.WarpChainName.Vibechain,identifier:"VIBE",name:"VIBE",decimals:18,logoUrl:"https://vleap.ai/images/tokens/vibe.svg"},ue={name:re.WarpChainName.Vibechain,displayName:"VibeChain",chainId:"V",blockTime:600,addressHrp:"vibe",defaultApiUrl:"https://vibeox-api.multiversx.com",nativeToken:Ce},le=K(re.WarpChainName.Vibechain,"vibe",{mainnet:ue,testnet:ue,devnet:ue});var He=(o,e)=>[pe(o,e),le(o,e)],Qe=()=>[me.WarpChainName.Multiversx,me.WarpChainName.Vibechain];0&&(module.exports={ExplorerUrls,KnownTokens,MultiversxExplorers,MultiversxExplorersConfig,NativeTokenEgld,NativeTokenVibe,VibechainExplorers,WarpMultiversxAbiBuilder,WarpMultiversxBrandBuilder,WarpMultiversxBuilder,WarpMultiversxConstants,WarpMultiversxContractLoader,WarpMultiversxDataLoader,WarpMultiversxExecutor,WarpMultiversxExplorer,WarpMultiversxRegistry,WarpMultiversxResults,WarpMultiversxSerializer,address_value,biguint_value,boolean_value,codemeta_value,composite_value,createMultiversxAdapter,esdt_value,findKnownTokenById,getAllMultiversxAdapters,getAllMultiversxChainNames,getMultiversxAdapter,getMultiversxRegistryAddress,getVibechainAdapter,hex_value,list_value,nothing_value,option_value,optional_value,string_value,token_value,u16_value,u32_value,u64_value,u8_value,variadic_value});
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{WarpChainName as dt}from"@vleap/warps";import{WarpChainName as F}from"@vleap/warps";import{AbiRegistry as he}from"@multiversx/sdk-core";import{WarpCache as cr,WarpCacheKey as pr,WarpConstants as nt,WarpLogger as at}from"@vleap/warps";import{WarpLogger as rt}from"@vleap/warps";import{Address as k,ArgSerializer as Kt,DevnetEntrypoint as Jt,MainnetEntrypoint as Xt,SmartContractTransactionsFactory as Yt,TestnetEntrypoint as Zt,Token as Xe,TokenComputer as Ye,TokenTransfer as Ze,TransactionsFactoryConfig as et,TransferTransactionsFactory as er,UserSecretKey as tr,UserSigner as rr}from"@multiversx/sdk-core";import{applyResultsToMessages as nr,getNextInfo as ar,getProviderUrl as sr,getWarpActionByIndex as fe,shiftBigintBy as ir,WarpConstants as tt}from"@vleap/warps";import{findEventsByFirstTopic as Ct,SmartContractTransactionsOutcomeParser as xt,TransactionEventsParser as Wt}from"@multiversx/sdk-core";import{applyResultsToMessages as Tt,evaluateResultsCommon as O,findWarpExecutableAction as Le,getNextInfo as vt,parseResultsOutIndex as qe,WarpCache as bt,WarpCacheKey as Et,WarpConstants as De}from"@vleap/warps";import{Address as ft,AddressType as G,AddressValue as be,BigUIntType as P,BigUIntValue as j,BooleanType as K,BooleanValue as Ee,BytesType as J,BytesValue as Ae,CodeMetadata as ht,CodeMetadataType as X,CodeMetadataValue as Ie,CompositeType as Y,CompositeValue as Be,Field as Z,FieldDefinition as ee,List as Ve,ListType as Ne,NothingValue as W,OptionalType as Se,OptionalValue as te,OptionType as ke,OptionValue as re,StringType as ne,StringValue as Fe,Struct as gt,StructType as Re,Token as yt,TokenComputer as Pe,TokenIdentifierType as U,TokenIdentifierValue as ae,U16Type as se,U16Value as Ue,U32Type as ie,U32Value as _e,U64Type as _,U64Value as oe,U8Type as ce,U8Value as Oe,VariadicType as pe,VariadicValue as Me}from"@multiversx/sdk-core";import{WarpConstants as T,WarpSerializer as wt}from"@vleap/warps";var $e=new RegExp(`${T.ArgParamsSeparator}(.*)`),I=class{constructor(){this.coreSerializer=new wt}typedToString(e){let t=e.getType();if(t.hasExactClass(ke.ClassName)||e.hasClassOrSuperclass(re.ClassName))return e.isSet()?`option:${this.typedToString(e.getTypedValue())}`:"option:null";if(t.hasExactClass(Se.ClassName)||e.hasClassOrSuperclass(te.ClassName))return e.isSet()?`optional:${this.typedToString(e.getTypedValue())}`:"optional:null";if(t.hasExactClass(Ne.ClassName)||e.hasClassOrSuperclass(Ve.ClassName)){let r=e.getItems(),n=r.map(s=>this.typedToString(s).split(T.ArgParamsSeparator)[0])[0],o=r.map(s=>this.typedToString(s).split(T.ArgParamsSeparator)[1]);return`list:${n}:${o.join(",")}`}if(t.hasExactClass(pe.ClassName)||e.hasClassOrSuperclass(Me.ClassName)){let r=e.getItems(),n=r.map(s=>this.typedToString(s).split(T.ArgParamsSeparator)[0])[0],o=r.map(s=>this.typedToString(s).split(T.ArgParamsSeparator)[1]);return`variadic:${n}:${o.join(",")}`}if(t.hasExactClass(Y.ClassName)||e.hasClassOrSuperclass(Be.ClassName)){let r=e.getItems(),a=r.map(c=>this.typedToString(c).split(T.ArgParamsSeparator)[0]),n=r.map(c=>this.typedToString(c).split(T.ArgParamsSeparator)[1]),o=a.join(T.ArgCompositeSeparator),s=n.join(T.ArgCompositeSeparator);return`composite(${o}):${s}`}if(t.hasExactClass(P.ClassName)||e.hasClassOrSuperclass(j.ClassName)||t.getName()==="BigUint")return`biguint:${BigInt(e.valueOf().toFixed())}`;if(t.hasExactClass(ce.ClassName)||e.hasClassOrSuperclass(Oe.ClassName))return`uint8:${e.valueOf().toNumber()}`;if(t.hasExactClass(se.ClassName)||e.hasClassOrSuperclass(Ue.ClassName))return`uint16:${e.valueOf().toNumber()}`;if(t.hasExactClass(ie.ClassName)||e.hasClassOrSuperclass(_e.ClassName))return`uint32:${e.valueOf().toNumber()}`;if(t.hasExactClass(_.ClassName)||e.hasClassOrSuperclass(oe.ClassName))return`uint64:${BigInt(e.valueOf().toFixed())}`;if(t.hasExactClass(ne.ClassName)||e.hasClassOrSuperclass(Fe.ClassName))return`string:${e.valueOf()}`;if(t.hasExactClass(K.ClassName)||e.hasClassOrSuperclass(Ee.ClassName))return`bool:${e.valueOf()}`;if(t.hasExactClass(G.ClassName)||e.hasClassOrSuperclass(be.ClassName))return`address:${e.valueOf().toBech32()}`;if(t.hasExactClass(U.ClassName)||e.hasClassOrSuperclass(ae.ClassName))return`token:${e.valueOf()}`;if(t.hasExactClass(J.ClassName)||e.hasClassOrSuperclass(Ae.ClassName))return`hex:${e.valueOf().toString("hex")}`;if(t.hasExactClass(X.ClassName)||e.hasClassOrSuperclass(Ie.ClassName))return`codemeta:${e.valueOf().toString()}`;if(t.getName()==="EsdtTokenPayment"){let r=e.getFieldValue("token_identifier").valueOf(),a=e.getFieldValue("token_nonce").valueOf(),n=e.getFieldValue("amount").valueOf();return`asset:${new Pe().computeExtendedIdentifier(new yt({identifier:r,nonce:BigInt(a)}))}|${n}`}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 Y(...t.split(T.ArgCompositeSeparator).map(r=>this.nativeToType(r)))}if(e==="string")return new ne;if(e==="uint8")return new ce;if(e==="uint16")return new se;if(e==="uint32")return new ie;if(e==="uint64")return new _;if(e==="biguint")return new P;if(e==="bool")return new K;if(e==="address")return new G;if(e==="token")return new U;if(e==="hex")return new J;if(e==="codemeta")return new X;if(e==="asset")return new Re("EsdtTokenPayment",[new ee("token_identifier","",new U),new ee("token_nonce","",new _),new ee("amount","",new P)]);throw new Error(`WarpArgSerializer (nativeToType): Unsupported input type: ${e}`)}stringToTyped(e){let[t,r]=e.split(/:(.*)/,2);if(t==="null"||t===null)return new W;if(t==="option"){let a=this.stringToTyped(r);return a instanceof W?re.newMissingTyped(a.getType()):re.newProvided(a)}if(t==="optional"){let a=this.stringToTyped(r);return a instanceof W?te.newMissing():new te(a.getType(),a)}if(t==="list"){let[a,n]=r.split($e,2),s=n.split(",").map(c=>this.stringToTyped(`${a}:${c}`));return new Ve(this.nativeToType(a),s)}if(t==="variadic"){let[a,n]=r.split($e,2),s=n.split(",").map(c=>this.stringToTyped(`${a}:${c}`));return new Me(new pe(this.nativeToType(a)),s)}if(t.startsWith("composite")){let a=t.match(/\(([^)]+)\)/)?.[1],n=r.split(T.ArgCompositeSeparator),o=a.split(T.ArgCompositeSeparator),s=n.map((p,u)=>this.stringToTyped(`${o[u]}:${p}`)),c=s.map(p=>p.getType());return new Be(new Y(...c),s)}if(t==="string")return r?Fe.fromUTF8(r):new W;if(t==="uint8")return r?new Oe(Number(r)):new W;if(t==="uint16")return r?new Ue(Number(r)):new W;if(t==="uint32")return r?new _e(Number(r)):new W;if(t==="uint64")return r?new oe(BigInt(r)):new W;if(t==="biguint")return r?new j(BigInt(r)):new W;if(t==="bool")return r?new Ee(typeof r=="boolean"?r:r==="true"):new W;if(t==="address")return r?new be(ft.newFromBech32(r)):new W;if(t==="token")return r?new ae(r):new W;if(t==="hex")return r?Ae.fromHex(r):new W;if(t==="codemeta")return new Ie(ht.newFromBytes(Uint8Array.from(Buffer.from(r,"hex"))));if(t==="asset"){let a=r.split(T.ArgCompositeSeparator),n=new Pe,o=n.extractIdentifierFromExtendedIdentifier(a[0]),s=n.extractNonceFromExtendedIdentifier(a[0]);return new gt(this.nativeToType("asset"),[new Z(new ae(o),"token_identifier"),new Z(new oe(BigInt(s)),"token_nonce"),new Z(new j(BigInt(a[1])),"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(Se.ClassName))return"optional:"+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(Ne.ClassName))return"list:"+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(pe.ClassName))return"variadic:"+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(ne.ClassName))return"string";if(e.hasExactClass(ce.ClassName))return"uint8";if(e.hasExactClass(se.ClassName))return"uint16";if(e.hasExactClass(ie.ClassName))return"uint32";if(e.hasExactClass(_.ClassName))return"uint64";if(e.hasExactClass(P.ClassName))return"biguint";if(e.hasExactClass(K.ClassName))return"bool";if(e.hasExactClass(G.ClassName))return"address";if(e.hasExactClass(U.ClassName))return"token";if(e.hasExactClass(J.ClassName))return"hex";if(e.hasExactClass(X.ClassName))return"codemeta";if(e.hasExactClass(Re.ClassName)&&e.getClassName()==="EsdtTokenPayment")return"asset";throw new Error(`WarpArgSerializer (typeToString): Unsupported input type: ${e.getClassName()}`)}};var N=class{constructor(e,t){this.config=e;this.chain=t;this.abi=new B(e,t),this.serializer=new I,this.cache=new bt(e.cache?.type)}async getTransactionExecutionResults(e,t){let{actionIndex:r}=Le(e),a=this.cache.get(Et.WarpExecutable(this.config.env,e.meta?.hash||"",r))??[],n=await this.extractContractResults(e,t,a),o=vt(this.config,[],e,r,n),s=Tt(e,n.results);return{success:t.status.isSuccessful(),warp:e,action:r,user:this.config.user?.wallets?.[this.chain.name]||null,txHash:t.hash,tx:t,next:o,values:n.values,valuesRaw:[],results:n.results,messages:s}}async extractContractResults(e,t,r){let{action:a,actionIndex:n}=Le(e),o=[],s={};if(!e.results||a.type!=="contract")return{values:o,results:s};if(!Object.values(e.results).some(h=>h.includes("out")||h.includes("event"))){for(let[h,m]of Object.entries(e.results))s[h]=m;return{values:o,results:await O(e,s,n,r,this.config.transform?.runner)}}let p=await this.abi.getAbiForAction(a),u=new Wt({abi:p}),v=new xt({abi:p}).parseExecute({transactionOnNetwork:t,function:a.func||void 0});for(let[h,m]of Object.entries(e.results)){if(m.startsWith(De.Transform.Prefix))continue;if(m.startsWith("input.")){s[h]=m;continue}let b=qe(m);if(b!==null&&b!==n){s[h]=null;continue}let[w,x,A]=m.split(".");if(w==="event"){if(!x||isNaN(Number(A)))continue;let E=Number(A),y=Ct(t,x),S=u.parseEvents({events:y})[0],R=Object.values(S)[E]||null;o.push(R),s[h]=R&&R.valueOf()}else if(w==="out"||w.startsWith("out[")){if(!x)continue;let E=Number(x),y=v.values[E-1]||null;A&&(y=y[A]||null),y&&typeof y=="object"&&(y="toFixed"in y?y.toFixed():y.valueOf()),o.push(y),s[h]=y&&y.valueOf()}else s[h]=m}return{values:o,results:await O(e,s,n,r)}}async extractQueryResults(e,t,r,a){let n=t.map(p=>this.serializer.typedToString(p)),o=t.map(p=>this.serializer.typedToNative(p)[1]),s={};if(!e.results)return{values:n,valuesRaw:o,results:s};let c=p=>{let u=p.split(".").slice(1).map(v=>parseInt(v)-1);if(u.length===0)return;let l=o[u[0]];for(let v=1;v<u.length;v++){if(l==null)return;l=l[u[v]]}return l};for(let[p,u]of Object.entries(e.results)){if(u.startsWith(De.Transform.Prefix))continue;let l=qe(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:n,valuesRaw:o,results:await O(e,s,r,a)}}async resolveWarpResultsRecursively(e){let t=e.warp,r=e.entryActionIndex,a=e.executor,n=e.inputs,o=e.meta,s=new Map,c=new Set,p=this;async function u(m,b=[]){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 x;if(w.type==="query")x=await a.executeQuery(t,m,b);else if(w.type==="collect")x=await a.executeCollect(t,m,b,o);else throw new Error(`Unsupported or interactive action type: ${w.type}`);if(s.set(m,x),t.results)for(let A of Object.values(t.results)){let y=String(A).match(/^out\[(\d+)\]/);if(y){let S=parseInt(y[1],10);S!==m&&!s.has(S)&&await u(S)}}return c.delete(m),x}await u(r,n);let l={};for(let m of s.values())for(let[b,w]of Object.entries(m.results))w!==null?l[b]=w:b in l||(l[b]=null);let v=await O(t,l,r,n,this.config.transform?.runner);return{...s.get(r),action:r,results:v}}};var ze={Egld:{Identifier:"EGLD",EsdtIdentifier:"EGLD-000000",DisplayName:"eGold",Decimals:18}},At=(r=>(r.MultiversxExplorer="multiversx_explorer",r.MultiversxExplorerDevnet="multiversx_explorer_devnet",r.MultiversxExplorerTestnet="multiversx_explorer_testnet",r))(At||{}),It=(r=>(r.VibechainExplorer="vibechain_explorer",r.VibechainExplorerDevnet="vibechain_explorer_devnet",r.VibechainExplorerTestnet="vibechain_explorer_testnet",r))(It||{}),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"]}},V={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 Bt=[{id:"EGLD",name:"eGold",decimals:18},{id:"EGLD-000000",name:"eGold",decimals:18},{id:"VIBE-000000",name:"VIBE",decimals:18}],Qe=i=>Bt.find(e=>e.id===i)||null;import{Address as Vt,AddressValue as Nt,BigUIntType as St,BigUIntValue as Ge,BooleanValue as kt,BytesValue as Ft,CodeMetadata as Rt,CodeMetadataValue as Pt,CompositeType as Ut,CompositeValue as _t,Field as ue,FieldDefinition as le,List as Ot,NothingValue as Mt,OptionalValue as me,OptionValue as de,StringValue as $t,Struct as Lt,StructType as qt,TokenIdentifierType as Dt,TokenIdentifierValue as je,U16Value as zt,U32Value as Ht,U64Type as Qt,U64Value as Ke,U8Value as Gt,VariadicValue as jt}from"@multiversx/sdk-core";var rn=(i,e)=>i?de.newProvided(i):e?de.newMissingTyped(e):de.newMissing(),nn=(i,e)=>i?new me(i.getType(),i):e?new me(e):me.newMissing(),an=i=>{if(i.length===0)throw new Error("Cannot create a list from an empty array");let e=i[0].getType();return new Ot(e,i)},sn=i=>jt.fromItems(...i),on=i=>{let e=i.map(t=>t.getType());return new _t(new Ut(...e),i)},cn=i=>$t.fromUTF8(i),pn=i=>new Gt(i),un=i=>new zt(i),ln=i=>new Ht(i),mn=i=>new Ke(i),dn=i=>new Ge(BigInt(i)),fn=i=>new kt(i),hn=i=>new Nt(Vt.newFromBech32(i)),gn=i=>new je(i),yn=i=>Ft.fromHex(i),Je=i=>new Lt(new qt("EsdtTokenPayment",[new le("token_identifier","",new Dt),new le("token_nonce","",new Qt),new le("amount","",new St)]),[new ue(new je(i.token.identifier),"token_identifier"),new ue(new Ke(BigInt(i.token.nonce)),"token_nonce"),new ue(new Ge(BigInt(i.amount)),"amount")]),wn=i=>new Pt(Rt.newFromBytes(Uint8Array.from(Buffer.from(i,"hex")))),Cn=()=>new Mt;var or="EGLD-000000",f=class i{constructor(e,t){this.config=e;this.chain=t;this.serializer=new I,this.abi=new B(this.config,this.chain),this.results=new N(this.config,this.chain)}async createTransaction(e){let t=fe(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){console.log("createTransferTransaction user wallets",this.config.user?.wallets);let t=this.config.user?.wallets?.[e.chain.name];if(!t)throw new Error("WarpMultiversxExecutor: createTransfer - user address not set");let r=k.newFromBech32(t),a=new et({chainID:e.chain.chainId}),n=e.data?Buffer.from(this.serializer.stringToTyped(e.data).valueOf()):null;return new er({config:a}).createTransactionForTransfer(r,{receiver:k.newFromBech32(e.destination),nativeAmount:e.value,tokenTransfers:this.toTokenTransfers(e.transfers),data:n?new Uint8Array(n):void 0})}async createContractCallTransaction(e){let t=this.config.user?.wallets?.[e.chain.name];if(!t)throw new Error("WarpMultiversxExecutor: createContractCall - user address not set");let r=fe(e.warp,e.action),a=k.newFromBech32(t),n=e.args.map(s=>this.serializer.stringToTyped(s)),o=new et({chainID:e.chain.chainId});return new Yt({config:o}).createTransactionForExecute(a,{contract:k.newFromBech32(e.destination),function:"func"in r&&r.func||"",gasLimit:"gasLimit"in r?BigInt(r.gasLimit||0):0n,arguments:n,tokenTransfers:this.toTokenTransfers(e.transfers),nativeTransferAmount:e.value})}async executeQuery(e){let t=fe(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(E=>this.serializer.stringToTyped(E)),n=i.getChainEntrypoint(e.chain,this.config.env,this.config),o=k.newFromBech32(e.destination),s=n.createSmartContractController(r),c=s.createQuery({contract:o,function:t.func||"",arguments:a}),p=await s.runQuery(c),u=p.returnCode==="ok",l=new Kt,v=r.getEndpoint(p.function||t.func||""),h=(p.returnDataParts||[]).map(E=>Buffer.from(E)),m=l.buffersToValues(h,v.output),{values:b,valuesRaw:w,results:x}=await this.results.extractQueryResults(e.warp,m,e.action,e.resolvedInputs),A=ar(this.config,[],e.warp,e.action,x);return{success:u,warp:e.warp,action:e.action,user:this.config.user?.wallets?.[e.chain.name]||null,txHash:null,tx:null,next:A,values:b,valuesRaw:w,results:x,messages:nr(e.warp,x)}}async preprocessInput(e,t,r,a){if(r==="asset"){let[n,o,s]=a.split(tt.ArgCompositeSeparator);if(s)return t;let c=new Ye,p=n===ze.Egld.Identifier?0:c.extractNonceFromExtendedIdentifier(n),u=new Xe({identifier:n,nonce:BigInt(p||0)});if(!c.isFungible(u))return t;let h=Qe(n)?.decimals;if(h||(h=(await(await fetch(`${e.defaultApiUrl}/tokens/${n}`)).json()).decimals),!h)throw new Error(`WarpMultiversxExecutor: Decimals not found for token ${n}`);let m=Je(new Ze({token:u,amount:ir(o,h)}));return this.serializer.typedToString(m)+tt.ArgCompositeSeparator+h}return t}static getChainEntrypoint(e,t,r){let a="warp-sdk",o=r?sr(r,e.name,t,e.defaultApiUrl):e.defaultApiUrl;return t==="devnet"?new Jt({url:o,kind:"api",clientName:a}):t==="testnet"?new Zt({url:o,kind:"api",clientName:a}):new Xt({url:o,kind:"api",clientName:a})}async signMessage(e,t){let r=tr.fromString(t);return(await new rr(r).sign(new Uint8Array(Buffer.from(e,"utf-8")))).toString()}toTokenTransfers(e){return e.map(t=>t.identifier===this.chain.nativeToken.identifier?{...t,identifier:or}:t).map(t=>{let a=new Ye().extractNonceFromExtendedIdentifier(t.identifier);return new Ze({token:new Xe({identifier:t.identifier,nonce:BigInt(a||0)}),amount:t.amount})})}};var M=class{constructor(e){this.config=e}async getContract(e,t){try{let n=await f.getChainEntrypoint(t,this.config.env).createNetworkProvider().doGetGeneric(`accounts/${e}`);return{address:e,owner:n.ownerAddress,verified:n.isVerified||!1}}catch(r){return rt.error("WarpContractLoader: getContract error",r),null}}async getVerificationInfo(e,t){try{let n=await f.getChainEntrypoint(t,this.config.env).createNetworkProvider().doGetGeneric(`accounts/${e}/verification`);return{codeHash:n.codeHash,abi:n.source.abi}}catch(r){return rt.error("WarpContractLoader: getVerificationInfo error",r),null}}};var B=class{constructor(e,t){this.config=e;this.chain=t;this.contractLoader=new M(this.config),this.cache=new cr(this.config.cache?.type)}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=pr.WarpAbi(this.config.env,e);if(t){let o=this.cache.get(r);if(o)return at.info(`WarpAbiBuilder (createFromTransactionHash): Warp abi found in cache: ${e}`),o}let n=f.getChainEntrypoint(this.chain,this.config.env).createNetworkProvider();try{let o=await n.getTransaction(e),s=await this.createFromTransaction(o);return t&&t.ttl&&s&&this.cache.set(r,s,t.ttl),s}catch(o){return at.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 he.create(t.abi)}async fetchAbi(e){if(!e.abi)throw new Error("WarpActionExecutor: ABI not found");if(e.abi.startsWith(nt.IdentifierType.Hash)){let t=e.abi.split(nt.IdentifierParamSeparatorDefault)[1],r=await this.createFromTransactionHash(t);if(!r)throw new Error(`WarpActionExecutor: ABI not found for hash: ${e.abi}`);return he.create(r.content)}else{let r=await(await fetch(e.abi)).json();return he.create(r)}}};import{Address as st,TransactionsFactoryConfig as ur,TransferTransactionsFactory as lr}from"@multiversx/sdk-core";import{WarpBrandBuilder as mr,WarpLogger as dr}from"@vleap/warps";import{Buffer as fr}from"buffer";var $=class{constructor(e,t){this.config=e;this.chain=t;this.core=new mr(e)}async createInscriptionTransaction(e){let t=this.config.user?.wallets?.[this.chain.name];if(!t)throw new Error("BrandBuilder: user address not set");let r=new ur({chainID:this.chain.chainId}),a=new lr({config:r}),n=st.newFromBech32(t),o=JSON.stringify(e);return await a.createTransactionForNativeTokenTransfer(n,{receiver:st.newFromBech32(t),nativeAmount:BigInt(0),data:Uint8Array.from(fr.from(o))})}async createFromTransaction(e,t=!1){return await this.core.createFromRaw(e.data.toString(),t)}async createFromTransactionHash(e){let r=f.getChainEntrypoint(this.chain,this.config.env).createNetworkProvider();try{let a=await r.getTransaction(e);return this.createFromTransaction(a)}catch(a){return dr.error("BrandBuilder: Error creating from transaction hash",a),null}}};import{Address as it,TransactionsFactoryConfig as hr,TransferTransactionsFactory as gr}from"@multiversx/sdk-core";import{WarpBuilder as ot,WarpCache as yr,WarpCacheKey as wr,WarpLogger as ct}from"@vleap/warps";var L=class extends ot{constructor(t,r){super(t);this.config=t;this.chain=r;this.cache=new yr(t.cache?.type),this.core=new ot(t)}async createInscriptionTransaction(t){let r=this.config.user?.wallets?.[this.chain.name];if(!r)throw new Error("WarpBuilder: user address not set");let a=new hr({chainID:this.chain.chainId}),n=new gr({config:a}),o=it.newFromBech32(r),s=JSON.stringify(t),c=await n.createTransactionForTransfer(o,{receiver:it.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 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=wr.Warp(this.config.env,t);if(r){let s=this.cache.get(a);if(s)return ct.info(`WarpBuilder (createFromTransactionHash): Warp found in cache: ${t}`),s}let o=f.getChainEntrypoint(this.chain,this.config.env).createNetworkProvider();try{let s=await o.getTransaction(t),c=await this.createFromTransaction(s);return r&&r.ttl&&c&&this.cache.set(a,c,r.ttl),c}catch(s){return ct.error("WarpBuilder: Error creating from transaction hash",s),null}}};import{Address as ge}from"@multiversx/sdk-core";var q=class{constructor(e,t){this.config=e;this.chain=t}async getAccount(e){let r=await f.getChainEntrypoint(this.chain,this.config.env,this.config).createNetworkProvider().getAccount(ge.newFromBech32(e));return{chain:this.chain.name,address:r.address.toBech32(),balance:r.balance}}async getAccountAssets(e){let t=f.getChainEntrypoint(this.chain,this.config.env,this.config).createNetworkProvider(),r=t.getAccount(ge.newFromBech32(e)),a=t.getFungibleTokensOfAccount(ge.newFromBech32(e)),[n,o]=await Promise.all([r,a]),s=n.balance>0?[{...this.chain.nativeToken,amount:n.balance}]:[];return s.push(...o.map(c=>({chain:this.chain.name,identifier:c.token.identifier,name:c.raw.name,amount:c.amount,decimals:c.raw.decimals,logoUrl:c.raw.assets?.pngUrl||""}))),s}async getAccountActions(e,t){let r=f.getChainEntrypoint(this.chain,this.config.env,this.config).createNetworkProvider(),a=`accounts/${e}/transactions`,n=new URLSearchParams,o=t?.size||25,s=t?.page||0;if(s>0){let p=s*o;n.append("from",p.toString())}return o!==25&&n.append("size",o.toString()),n.toString()&&(a+=`?${n.toString()}`),(await r.doGetGeneric(a)).map(p=>({chain:this.chain.name,id:p.txHash,receiver:p.receiver,sender:p.sender,value:p.value,function:p.function,status:p.status,createdAt:new Date(p.timestampMs||p.timestamp*1e3).toISOString()}))}};var D=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 n=V[t];if(n)return n}if(e){let n=V[e];if(n)return n}let r=this.getPrimaryExplorer();return V[r]||V[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 n=V[a];n&&(r[a]=`${n}/accounts/${e}`)}),r}getTransactionUrls(e){let t=this.getAllExplorers(),r={};return t.forEach(a=>{let n=V[a];n&&(r[a]=`${n}/transactions/${e}`)}),r}};import{AbiRegistry as ut,Address as d,AddressValue as we,BytesValue as g,SmartContractTransactionsFactory as xr,TransactionsFactoryConfig as Wr}from"@multiversx/sdk-core";import{WarpCache as Tr,WarpCacheKey as Ce,WarpLogger as xe}from"@vleap/warps";var ye={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"}],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}]},{name:"setChain",onlyOwner:!0,mutability:"mutable",inputs:[{name:"name",type:"bytes"},{name:"display_name",type:"bytes"},{name:"chain_id",type:"bytes"},{name:"block_time",type:"u32"},{name:"address_hrp",type:"bytes"},{name:"api_url",type:"bytes"},{name:"explorer_url",type:"bytes"},{name:"native_token",type:"bytes"}],outputs:[]},{name:"removeChain",onlyOwner:!0,mutability:"mutable",inputs:[{name:"name",type:"bytes"}],outputs:[]},{name:"getChain",mutability:"readonly",inputs:[{name:"name",type:"bytes"}],outputs:[{type:"ChainView"}]},{name:"getChains",mutability:"readonly",inputs:[],outputs:[{type:"variadic<ChainView>",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:{ChainView:{type:"struct",fields:[{name:"name",type:"bytes"},{name:"display_name",type:"bytes"},{name:"chain_id",type:"bytes"},{name:"block_time",type:"u32"},{name:"address_hrp",type:"bytes"},{name:"api_url",type:"bytes"},{name:"explorer_url",type:"bytes"},{name:"native_token",type:"bytes"}]},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 C=i=>{if(i==="devnet")return"erd1qqqqqqqqqqqqqpgqje2f99vr6r7sk54thg03c9suzcvwr4nfl3tsfkdl36";if(i==="testnet")throw new Error("Multiversx testnet is not supported");return"erd1qqqqqqqqqqqqqpgq3mrpj3u6q7tejv6d7eqhnyd27n9v5c5tl3ts08mffe"};var z=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}),pt=i=>({unitPrice:BigInt(i.unit_price.toString()),admins:i.admins.map(e=>e.toBech32())});var H=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=this.config.user?.wallets?.[this.chain.name]||null}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=d.newFromBech32(this.userWallet),n=()=>this.isCurrentUserAdmin()?BigInt(0):t&&r?this.registryConfig.unitPrice*BigInt(3):t?this.registryConfig.unitPrice*BigInt(2):this.registryConfig.unitPrice,o=()=>t&&r?[g.fromHex(e),g.fromUTF8(t),g.fromHex(r)]:t?[g.fromHex(e),g.fromUTF8(t)]:[g.fromHex(e)];return await this.getFactory().createTransactionForExecute(a,{contract:d.newFromBech32(C(this.config.env)),function:"registerWarp",gasLimit:BigInt(1e7),nativeTransferAmount:n(),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(C(this.config.env)),function:"unregisterWarp",gasLimit:BigInt(1e7),arguments:[g.fromHex(e)]})}async createWarpUpgradeTransaction(e,t){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 r=d.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(r,{contract:d.newFromBech32(C(this.config.env)),function:"upgradeWarp",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[g.fromUTF8(e),g.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(C(this.config.env)),function:"setWarpAlias",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[g.fromHex(e),g.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(C(this.config.env)),function:"verifyWarp",gasLimit:BigInt(1e7),arguments:[g.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(C(this.config.env)),function:"transferOwnership",gasLimit:BigInt(1e7),arguments:[g.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(C(this.config.env)),function:"registerBrand",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[g.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(C(this.config.env)),function:"brandWarp",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[g.fromHex(e),g.fromHex(t)]})}async getInfoByAlias(e,t){try{let r=Ce.RegistryInfo(this.config.env,e),a=t?this.cache.get(r):null;if(a)return xe.info(`WarpRegistry (getInfoByAlias): RegistryInfo found in cache: ${e}`),a;let n=d.newFromBech32(C(this.config.env)),o=this.getController(),s=o.createQuery({contract:n,function:"getInfoByAlias",arguments:[g.fromUTF8(e)]}),c=await o.runQuery(s),[p]=o.parseQueryResponse(c),u=p?z(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=Ce.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 a=d.newFromBech32(C(this.config.env)),n=this.getController(),o=n.createQuery({contract:a,function:"getInfoByHash",arguments:[g.fromHex(e)]}),s=await n.runQuery(o),[c]=n.parseQueryResponse(s),p=c?z(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(C(this.config.env)),a=this.getController(),n=a.createQuery({contract:r,function:"getUserWarps",arguments:[new we(new d(t))]}),o=await a.runQuery(n),[s]=a.parseQueryResponse(o);return s.map(z)}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(C(this.config.env)),a=this.getController(),n=a.createQuery({contract:r,function:"getUserBrands",arguments:[new we(new d(t))]}),o=await a.runQuery(n),[s]=a.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=Ce.Brand(this.config.env,e),a=t?this.cache.get(r):null;if(a)return xe.info(`WarpRegistry (fetchBrand): Brand found in cache: ${e}`),a;let o=f.getChainEntrypoint(this.chain,this.config.env).createNetworkProvider();try{let s=await o.getTransaction(e),c=JSON.parse(s.data.toString());return c.meta={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(C(this.config.env)),t=this.getController(),[r]=await t.query({contract:e,function:"getConfig",arguments:[]}),a=r?pt(r):null;this.registryConfig=a||{unitPrice:BigInt(0),admins:[]}}getFactory(){let e=new Wr({chainID:this.chain.chainId}),t=ut.create(ye);return new xr({config:e,abi:t})}getController(){let e=f.getChainEntrypoint(this.chain,this.config.env),t=ut.create(ye);return e.createSmartContractController(t)}isCurrentUserAdmin(){return!!this.userWallet&&this.registryConfig.admins.includes(this.userWallet)}};var Q=(i,e,t)=>(r,a)=>{let n=t[r.env];return{chain:i,chainInfo:n,prefix:e,builder:()=>new L(r,n),executor:new f(r,n),results:new N(r,n),serializer:new I,registry:new H(r,n),explorer:new D(i,r),abiBuilder:()=>new B(r,n),brandBuilder:()=>new $(r,n),dataLoader:new q(r,n),registerTypes:o=>{o.registerType("token",{stringToNative:s=>s,nativeToString:s=>`token:${s}`}),o.registerType("codemeta",{stringToNative:s=>s,nativeToString:s=>`codemeta:${s}`})}}};var We={chain:F.Multiversx,identifier:"EGLD",name:"eGold",decimals:18,logoUrl:"https://vleap.ai/images/tokens/egld.svg"},lt=Q(F.Multiversx,"mvx",{mainnet:{name:F.Multiversx,displayName:"MultiversX",chainId:"1",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://api.multiversx.com",nativeToken:We},testnet:{name:F.Multiversx,displayName:"MultiversX Testnet",chainId:"T",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://testnet-api.multiversx.com",nativeToken:We},devnet:{name:F.Multiversx,displayName:"MultiversX Devnet",chainId:"D",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://devnet-api.multiversx.com",nativeToken:We}});import{WarpChainName as ve}from"@vleap/warps";var vr={chain:ve.Vibechain,identifier:"VIBE",name:"VIBE",decimals:18,logoUrl:"https://vleap.ai/images/tokens/vibe.svg"},Te={name:ve.Vibechain,displayName:"VibeChain",chainId:"V",blockTime:600,addressHrp:"vibe",defaultApiUrl:"https://vibeox-api.multiversx.com",nativeToken:vr},mt=Q(ve.Vibechain,"vibe",{mainnet:Te,testnet:Te,devnet:Te});var bs=(i,e)=>[lt(i,e),mt(i,e)],Es=()=>[dt.Multiversx,dt.Vibechain];export{V as ExplorerUrls,Bt as KnownTokens,At as MultiversxExplorers,He as MultiversxExplorersConfig,We as NativeTokenEgld,vr as NativeTokenVibe,It as VibechainExplorers,B as WarpMultiversxAbiBuilder,$ as WarpMultiversxBrandBuilder,L as WarpMultiversxBuilder,ze as WarpMultiversxConstants,M as WarpMultiversxContractLoader,q as WarpMultiversxDataLoader,f as WarpMultiversxExecutor,D as WarpMultiversxExplorer,H as WarpMultiversxRegistry,N as WarpMultiversxResults,I as WarpMultiversxSerializer,hn as address_value,dn as biguint_value,fn as boolean_value,wn as codemeta_value,on as composite_value,Q as createMultiversxAdapter,Je as esdt_value,Qe as findKnownTokenById,bs as getAllMultiversxAdapters,Es as getAllMultiversxChainNames,lt as getMultiversxAdapter,C as getMultiversxRegistryAddress,mt as getVibechainAdapter,yn as hex_value,an as list_value,Cn as nothing_value,rn as option_value,nn as optional_value,cn as string_value,gn as token_value,un as u16_value,ln as u32_value,mn as u64_value,pn as u8_value,sn as variadic_value};
1
+ import{WarpChainName as dt}from"@vleap/warps";import{WarpChainName as R}from"@vleap/warps";import{AbiRegistry as ge}from"@multiversx/sdk-core";import{WarpCache as cr,WarpCacheKey as pr,WarpConstants as nt,WarpLogger as at}from"@vleap/warps";import{WarpLogger as rt}from"@vleap/warps";import{Address as F,ArgSerializer as Kt,DevnetEntrypoint as Jt,MainnetEntrypoint as Xt,SmartContractTransactionsFactory as Yt,TestnetEntrypoint as Zt,Token as Xe,TokenComputer as Ye,TokenTransfer as Ze,TransactionsFactoryConfig as et,TransferTransactionsFactory as er,UserSecretKey as tr,UserSigner as rr}from"@multiversx/sdk-core";import{applyResultsToMessages as nr,getNextInfo as ar,getProviderUrl as sr,getWarpActionByIndex as he,shiftBigintBy as ir,WarpConstants as tt}from"@vleap/warps";import{findEventsByFirstTopic as Wt,SmartContractTransactionsOutcomeParser as Tt,TransactionEventsParser as vt}from"@multiversx/sdk-core";import{applyResultsToMessages as bt,evaluateResultsCommon as M,findWarpExecutableAction as De,getNextInfo as Et,parseResultsOutIndex as ze,WarpCache as At,WarpCacheKey as It,WarpConstants as He}from"@vleap/warps";import{Address as gt,AddressType as j,AddressValue as Ae,BigUIntType as U,BigUIntValue as K,BooleanType as J,BooleanValue as Ie,BytesType as X,BytesValue as Be,CodeMetadata as yt,CodeMetadataType as Y,CodeMetadataValue as Ve,CompositeType as Z,CompositeValue as Ne,Field as ee,FieldDefinition as te,List as Se,ListType as ke,NothingValue as W,OptionalType as Fe,OptionalValue as re,OptionType as Re,OptionValue as ne,StringType as ae,StringValue as Pe,Struct as wt,StructType as Ue,Token as Ct,TokenComputer as _e,TokenIdentifierType as _,TokenIdentifierValue as se,U16Type as ie,U16Value as Oe,U32Type as oe,U32Value as Me,U64Type as O,U64Value as ce,U8Type as pe,U8Value as $e,VariadicType as ue,VariadicValue as Le}from"@multiversx/sdk-core";import{WarpConstants as T,WarpSerializer as xt}from"@vleap/warps";var N={Egld:{Identifier:"EGLD",EsdtIdentifier:"EGLD-000000",DisplayName:"eGold",Decimals:18}},ft=(r=>(r.MultiversxExplorer="multiversx_explorer",r.MultiversxExplorerDevnet="multiversx_explorer_devnet",r.MultiversxExplorerTestnet="multiversx_explorer_testnet",r))(ft||{}),ht=(r=>(r.VibechainExplorer="vibechain_explorer",r.VibechainExplorerDevnet="vibechain_explorer_devnet",r.VibechainExplorerTestnet="vibechain_explorer_testnet",r))(ht||{}),Ee={multiversx:{mainnet:["multiversx_explorer"],testnet:["multiversx_explorer_testnet"],devnet:["multiversx_explorer_devnet"]},vibechain:{mainnet:["vibechain_explorer"],testnet:["vibechain_explorer_testnet"],devnet:["vibechain_explorer_devnet"]}},V={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 qe=new RegExp(`${T.ArgParamsSeparator}(.*)`),I=class{constructor(){this.coreSerializer=new xt}typedToString(e){let t=e.getType();if(t.hasExactClass(Re.ClassName)||e.hasClassOrSuperclass(ne.ClassName))return e.isSet()?`option:${this.typedToString(e.getTypedValue())}`:"option:null";if(t.hasExactClass(Fe.ClassName)||e.hasClassOrSuperclass(re.ClassName))return e.isSet()?`optional:${this.typedToString(e.getTypedValue())}`:"optional:null";if(t.hasExactClass(ke.ClassName)||e.hasClassOrSuperclass(Se.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(ue.ClassName)||e.hasClassOrSuperclass(Le.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(Z.ClassName)||e.hasClassOrSuperclass(Ne.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(U.ClassName)||e.hasClassOrSuperclass(K.ClassName)||t.getName()==="BigUint")return`biguint:${BigInt(e.valueOf().toFixed())}`;if(t.hasExactClass(pe.ClassName)||e.hasClassOrSuperclass($e.ClassName))return`uint8:${e.valueOf().toNumber()}`;if(t.hasExactClass(ie.ClassName)||e.hasClassOrSuperclass(Oe.ClassName))return`uint16:${e.valueOf().toNumber()}`;if(t.hasExactClass(oe.ClassName)||e.hasClassOrSuperclass(Me.ClassName))return`uint32:${e.valueOf().toNumber()}`;if(t.hasExactClass(O.ClassName)||e.hasClassOrSuperclass(ce.ClassName))return`uint64:${BigInt(e.valueOf().toFixed())}`;if(t.hasExactClass(ae.ClassName)||e.hasClassOrSuperclass(Pe.ClassName))return`string:${e.valueOf()}`;if(t.hasExactClass(J.ClassName)||e.hasClassOrSuperclass(Ie.ClassName))return`bool:${e.valueOf()}`;if(t.hasExactClass(j.ClassName)||e.hasClassOrSuperclass(Ae.ClassName))return`address:${e.valueOf().toBech32()}`;if(t.hasExactClass(_.ClassName)||e.hasClassOrSuperclass(se.ClassName))return`token:${e.valueOf()}`;if(t.hasExactClass(X.ClassName)||e.hasClassOrSuperclass(Be.ClassName))return`hex:${e.valueOf().toString("hex")}`;if(t.hasExactClass(Y.ClassName)||e.hasClassOrSuperclass(Ve.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 _e().computeExtendedIdentifier(new Ct({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 Z(...t.split(T.ArgCompositeSeparator).map(r=>this.nativeToType(r)))}if(e==="string")return new ae;if(e==="uint8")return new pe;if(e==="uint16")return new ie;if(e==="uint32")return new oe;if(e==="uint64")return new O;if(e==="biguint")return new U;if(e==="bool")return new J;if(e==="address")return new j;if(e==="token")return new _;if(e==="hex")return new X;if(e==="codemeta")return new Y;if(e==="asset")return new Ue("EsdtTokenPayment",[new te("token_identifier","",new _),new te("token_nonce","",new O),new te("amount","",new U)]);throw new Error(`WarpArgSerializer (nativeToType): Unsupported input type: ${e}`)}stringToTyped(e){let[t,r]=e.split(/:(.*)/,2);if(t==="null"||t===null)return new W;if(t==="option"){let n=this.stringToTyped(r);return n instanceof W?ne.newMissingTyped(n.getType()):ne.newProvided(n)}if(t==="optional"){let n=this.stringToTyped(r);return n instanceof W?re.newMissing():new re(n.getType(),n)}if(t==="list"){let[n,a]=r.split(qe,2),s=a.split(",").map(c=>this.stringToTyped(`${n}:${c}`));return new Se(this.nativeToType(n),s)}if(t==="variadic"){let[n,a]=r.split(qe,2),s=a.split(",").map(c=>this.stringToTyped(`${n}:${c}`));return new Le(new ue(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 Ne(new Z(...c),s)}if(t==="string")return r?Pe.fromUTF8(r):new W;if(t==="uint8")return r?new $e(Number(r)):new W;if(t==="uint16")return r?new Oe(Number(r)):new W;if(t==="uint32")return r?new Me(Number(r)):new W;if(t==="uint64")return r?new ce(BigInt(r)):new W;if(t==="biguint")return r?new K(BigInt(r)):new W;if(t==="bool")return r?new Ie(typeof r=="boolean"?r:r==="true"):new W;if(t==="address")return r?new Ae(gt.newFromBech32(r)):new W;if(t==="token")return r?new se(r):new W;if(t==="hex")return r?Be.fromHex(r):new W;if(t==="codemeta")return new Ve(yt.newFromBytes(Uint8Array.from(Buffer.from(r,"hex"))));if(t==="asset"){let n=r.split(T.ArgCompositeSeparator),a=new _e,o=n[0]===N.Egld.Identifier?N.Egld.EsdtIdentifier:a.extractIdentifierFromExtendedIdentifier(n[0]),s=n[0]===N.Egld.Identifier?0:a.extractNonceFromExtendedIdentifier(n[0]);return new wt(this.nativeToType("asset"),[new ee(new se(o),"token_identifier"),new ee(new ce(BigInt(s)),"token_nonce"),new ee(new K(BigInt(n[1])),"amount")])}throw new Error(`WarpArgSerializer (stringToTyped): Unsupported input type: ${t}`)}typeToString(e){if(e.hasExactClass(Re.ClassName))return"option:"+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(Fe.ClassName))return"optional:"+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(ke.ClassName))return"list:"+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(ue.ClassName))return"variadic:"+this.typeToString(e.getFirstTypeParameter());if(e.hasExactClass(ae.ClassName))return"string";if(e.hasExactClass(pe.ClassName))return"uint8";if(e.hasExactClass(ie.ClassName))return"uint16";if(e.hasExactClass(oe.ClassName))return"uint32";if(e.hasExactClass(O.ClassName))return"uint64";if(e.hasExactClass(U.ClassName))return"biguint";if(e.hasExactClass(J.ClassName))return"bool";if(e.hasExactClass(j.ClassName))return"address";if(e.hasExactClass(_.ClassName))return"token";if(e.hasExactClass(X.ClassName))return"hex";if(e.hasExactClass(Y.ClassName))return"codemeta";if(e.hasExactClass(Ue.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 B(e,t),this.serializer=new I,this.cache=new At(e.cache?.type)}async getTransactionExecutionResults(e,t){let{actionIndex:r}=De(e),n=this.cache.get(It.WarpExecutable(this.config.env,e.meta?.hash||"",r))??[],a=await this.extractContractResults(e,t,n),o=Et(this.config,[],e,r,a),s=bt(e,a.results);return{success:t.status.isSuccessful(),warp:e,action:r,user:this.config.user?.wallets?.[this.chain.name]||null,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}=De(e),o=[],s={};if(!e.results||n.type!=="contract")return{values:o,results:s};if(!Object.values(e.results).some(h=>h.includes("out")||h.includes("event"))){for(let[h,m]of Object.entries(e.results))s[h]=m;return{values:o,results:await M(e,s,a,r,this.config.transform?.runner)}}let p=await this.abi.getAbiForAction(n),u=new vt({abi:p}),v=new Tt({abi:p}).parseExecute({transactionOnNetwork:t,function:n.func||void 0});for(let[h,m]of Object.entries(e.results)){if(m.startsWith(He.Transform.Prefix))continue;if(m.startsWith("input.")){s[h]=m;continue}let b=ze(m);if(b!==null&&b!==a){s[h]=null;continue}let[w,x,A]=m.split(".");if(w==="event"){if(!x||isNaN(Number(A)))continue;let E=Number(A),y=Wt(t,x),k=u.parseEvents({events:y})[0],P=Object.values(k)[E]||null;o.push(P),s[h]=P&&P.valueOf()}else if(w==="out"||w.startsWith("out[")){if(!x)continue;let E=Number(x),y=v.values[E-1]||null;A&&(y=y[A]||null),y&&typeof y=="object"&&(y="toFixed"in y?y.toFixed():y.valueOf()),o.push(y),s[h]=y&&y.valueOf()}else s[h]=m}return{values:o,results:await M(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(v=>parseInt(v)-1);if(u.length===0)return;let l=o[u[0]];for(let v=1;v<u.length;v++){if(l==null)return;l=l[u[v]]}return l};for(let[p,u]of Object.entries(e.results)){if(u.startsWith(He.Transform.Prefix))continue;let l=ze(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 M(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,b=[]){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 x;if(w.type==="query")x=await n.executeQuery(t,m,b);else if(w.type==="collect")x=await n.executeCollect(t,m,b,o);else throw new Error(`Unsupported or interactive action type: ${w.type}`);if(s.set(m,x),t.results)for(let A of Object.values(t.results)){let y=String(A).match(/^out\[(\d+)\]/);if(y){let k=parseInt(y[1],10);k!==m&&!s.has(k)&&await u(k)}}return c.delete(m),x}await u(r,a);let l={};for(let m of s.values())for(let[b,w]of Object.entries(m.results))w!==null?l[b]=w:b in l||(l[b]=null);let v=await M(t,l,r,a,this.config.transform?.runner);return{...s.get(r),action:r,results:v}}};var Bt=[{id:"EGLD",name:"eGold",decimals:18},{id:"EGLD-000000",name:"eGold",decimals:18},{id:"VIBE-000000",name:"VIBE",decimals:18}],Qe=i=>Bt.find(e=>e.id===i)||null;import{Address as Vt,AddressValue as Nt,BigUIntType as St,BigUIntValue as Ge,BooleanValue as kt,BytesValue as Ft,CodeMetadata as Rt,CodeMetadataValue as Pt,CompositeType as Ut,CompositeValue as _t,Field as le,FieldDefinition as me,List as Ot,NothingValue as Mt,OptionalValue as de,OptionValue as fe,StringValue as $t,Struct as Lt,StructType as qt,TokenIdentifierType as Dt,TokenIdentifierValue as je,U16Value as zt,U32Value as Ht,U64Type as Qt,U64Value as Ke,U8Value as Gt,VariadicValue as jt}from"@multiversx/sdk-core";var nn=(i,e)=>i?fe.newProvided(i):e?fe.newMissingTyped(e):fe.newMissing(),an=(i,e)=>i?new de(i.getType(),i):e?new de(e):de.newMissing(),sn=i=>{if(i.length===0)throw new Error("Cannot create a list from an empty array");let e=i[0].getType();return new Ot(e,i)},on=i=>jt.fromItems(...i),cn=i=>{let e=i.map(t=>t.getType());return new _t(new Ut(...e),i)},pn=i=>$t.fromUTF8(i),un=i=>new Gt(i),ln=i=>new zt(i),mn=i=>new Ht(i),dn=i=>new Ke(i),fn=i=>new Ge(BigInt(i)),hn=i=>new kt(i),gn=i=>new Nt(Vt.newFromBech32(i)),yn=i=>new je(i),wn=i=>Ft.fromHex(i),Je=i=>new Lt(new qt("EsdtTokenPayment",[new me("token_identifier","",new Dt),new me("token_nonce","",new Qt),new me("amount","",new St)]),[new le(new je(i.token.identifier),"token_identifier"),new le(new Ke(BigInt(i.token.nonce)),"token_nonce"),new le(new Ge(BigInt(i.amount)),"amount")]),Cn=i=>new Pt(Rt.newFromBytes(Uint8Array.from(Buffer.from(i,"hex")))),xn=()=>new Mt;var or="EGLD-000000",f=class i{constructor(e,t){this.config=e;this.chain=t;this.serializer=new I,this.abi=new B(this.config,this.chain),this.results=new S(this.config,this.chain)}async createTransaction(e){let t=he(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){console.log("createTransferTransaction user wallets",this.config.user?.wallets);let t=this.config.user?.wallets?.[e.chain.name];if(!t)throw new Error("WarpMultiversxExecutor: createTransfer - user address not set");let r=F.newFromBech32(t),n=new et({chainID:e.chain.chainId}),a=e.data?Buffer.from(this.serializer.stringToTyped(e.data).valueOf()):null;return new er({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=this.config.user?.wallets?.[e.chain.name];if(!t)throw new Error("WarpMultiversxExecutor: createContractCall - user address not set");let r=he(e.warp,e.action),n=F.newFromBech32(t),a=e.args.map(s=>this.serializer.stringToTyped(s)),o=new et({chainID:e.chain.chainId});return new Yt({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=he(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(E=>this.serializer.stringToTyped(E)),a=i.getChainEntrypoint(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 Kt,v=r.getEndpoint(p.function||t.func||""),h=(p.returnDataParts||[]).map(E=>Buffer.from(E)),m=l.buffersToValues(h,v.output),{values:b,valuesRaw:w,results:x}=await this.results.extractQueryResults(e.warp,m,e.action,e.resolvedInputs),A=ar(this.config,[],e.warp,e.action,x);return{success:u,warp:e.warp,action:e.action,user:this.config.user?.wallets?.[e.chain.name]||null,txHash:null,tx:null,next:A,values:b,valuesRaw:w,results:x,messages:nr(e.warp,x)}}async preprocessInput(e,t,r,n){if(r==="asset"){let[a,o,s]=n.split(tt.ArgCompositeSeparator);if(s)return t;let c=new Ye,p=a===N.Egld.Identifier?0:c.extractNonceFromExtendedIdentifier(a),u=new Xe({identifier:a,nonce:BigInt(p||0)});if(!c.isFungible(u))return t;let h=Qe(a)?.decimals;if(h||(h=(await(await fetch(`${e.defaultApiUrl}/tokens/${a}`)).json()).decimals),!h)throw new Error(`WarpMultiversxExecutor: Decimals not found for token ${a}`);let m=Je(new Ze({token:u,amount:ir(o,h)}));return this.serializer.typedToString(m)+tt.ArgCompositeSeparator+h}return t}static getChainEntrypoint(e,t,r){let n="warp-sdk",o=r?sr(r,e.name,t,e.defaultApiUrl):e.defaultApiUrl;return t==="devnet"?new Jt({url:o,kind:"api",clientName:n}):t==="testnet"?new Zt({url:o,kind:"api",clientName:n}):new Xt({url:o,kind:"api",clientName:n})}async signMessage(e,t){let r=tr.fromString(t);return(await new rr(r).sign(new Uint8Array(Buffer.from(e,"utf-8")))).toString()}toTokenTransfers(e){return e.map(t=>t.identifier===this.chain.nativeToken.identifier?{...t,identifier:or}:t).map(t=>{let n=new Ye().extractNonceFromExtendedIdentifier(t.identifier);return new Ze({token:new Xe({identifier:t.identifier,nonce:BigInt(n||0)}),amount:t.amount})})}};var $=class{constructor(e){this.config=e}async getContract(e,t){try{let a=await f.getChainEntrypoint(t,this.config.env).createNetworkProvider().doGetGeneric(`accounts/${e}`);return{address:e,owner:a.ownerAddress,verified:a.isVerified||!1}}catch(r){return rt.error("WarpContractLoader: getContract error",r),null}}async getVerificationInfo(e,t){try{let a=await f.getChainEntrypoint(t,this.config.env).createNetworkProvider().doGetGeneric(`accounts/${e}/verification`);return{codeHash:a.codeHash,abi:a.source.abi}}catch(r){return rt.error("WarpContractLoader: getVerificationInfo error",r),null}}};var B=class{constructor(e,t){this.config=e;this.chain=t;this.contractLoader=new $(this.config),this.cache=new cr(this.config.cache?.type)}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=pr.WarpAbi(this.config.env,e);if(t){let o=this.cache.get(r);if(o)return at.info(`WarpAbiBuilder (createFromTransactionHash): Warp abi found in cache: ${e}`),o}let a=f.getChainEntrypoint(this.chain,this.config.env).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 at.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 ge.create(t.abi)}async fetchAbi(e){if(!e.abi)throw new Error("WarpActionExecutor: ABI not found");if(e.abi.startsWith(nt.IdentifierType.Hash)){let t=e.abi.split(nt.IdentifierParamSeparatorDefault)[1],r=await this.createFromTransactionHash(t);if(!r)throw new Error(`WarpActionExecutor: ABI not found for hash: ${e.abi}`);return ge.create(r.content)}else{let r=await(await fetch(e.abi)).json();return ge.create(r)}}};import{Address as st,TransactionsFactoryConfig as ur,TransferTransactionsFactory as lr}from"@multiversx/sdk-core";import{WarpBrandBuilder as mr,WarpLogger as dr}from"@vleap/warps";import{Buffer as fr}from"buffer";var L=class{constructor(e,t){this.config=e;this.chain=t;this.core=new mr(e)}async createInscriptionTransaction(e){let t=this.config.user?.wallets?.[this.chain.name];if(!t)throw new Error("BrandBuilder: user address not set");let r=new ur({chainID:this.chain.chainId}),n=new lr({config:r}),a=st.newFromBech32(t),o=JSON.stringify(e);return await n.createTransactionForNativeTokenTransfer(a,{receiver:st.newFromBech32(t),nativeAmount:BigInt(0),data:Uint8Array.from(fr.from(o))})}async createFromTransaction(e,t=!1){return await this.core.createFromRaw(e.data.toString(),t)}async createFromTransactionHash(e){let r=f.getChainEntrypoint(this.chain,this.config.env).createNetworkProvider();try{let n=await r.getTransaction(e);return this.createFromTransaction(n)}catch(n){return dr.error("BrandBuilder: Error creating from transaction hash",n),null}}};import{Address as it,TransactionsFactoryConfig as hr,TransferTransactionsFactory as gr}from"@multiversx/sdk-core";import{WarpBuilder as ot,WarpCache as yr,WarpCacheKey as wr,WarpLogger as ct}from"@vleap/warps";var q=class extends ot{constructor(t,r){super(t);this.config=t;this.chain=r;this.cache=new yr(t.cache?.type),this.core=new ot(t)}async createInscriptionTransaction(t){let r=this.config.user?.wallets?.[this.chain.name];if(!r)throw new Error("WarpBuilder: user address not set");let n=new hr({chainID:this.chain.chainId}),a=new gr({config:n}),o=it.newFromBech32(r),s=JSON.stringify(t),c=await a.createTransactionForTransfer(o,{receiver:it.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=wr.Warp(this.config.env,t);if(r){let s=this.cache.get(n);if(s)return ct.info(`WarpBuilder (createFromTransactionHash): Warp found in cache: ${t}`),s}let o=f.getChainEntrypoint(this.chain,this.config.env).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 ct.error("WarpBuilder: Error creating from transaction hash",s),null}}};import{Address as ye}from"@multiversx/sdk-core";var D=class{constructor(e,t){this.config=e;this.chain=t}async getAccount(e){let r=await f.getChainEntrypoint(this.chain,this.config.env,this.config).createNetworkProvider().getAccount(ye.newFromBech32(e));return{chain:this.chain.name,address:r.address.toBech32(),balance:r.balance}}async getAccountAssets(e){let t=f.getChainEntrypoint(this.chain,this.config.env,this.config).createNetworkProvider(),r=t.getAccount(ye.newFromBech32(e)),n=t.getFungibleTokensOfAccount(ye.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,amount:c.amount,decimals:c.raw.decimals,logoUrl:c.raw.assets?.pngUrl||""}))),s}async getAccountActions(e,t){let r=f.getChainEntrypoint(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:p.status,createdAt:new Date(p.timestampMs||p.timestamp*1e3).toISOString()}))}};var z=class{constructor(e,t){this.chain=e;this.config=t}getExplorers(){let e=Ee[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=V[t];if(a)return a}if(e){let a=V[e];if(a)return a}let r=this.getPrimaryExplorer();return V[r]||V[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=V[n];a&&(r[n]=`${a}/accounts/${e}`)}),r}getTransactionUrls(e){let t=this.getAllExplorers(),r={};return t.forEach(n=>{let a=V[n];a&&(r[n]=`${a}/transactions/${e}`)}),r}};import{AbiRegistry as ut,Address as d,AddressValue as Ce,BytesValue as g,SmartContractTransactionsFactory as xr,TransactionsFactoryConfig as Wr}from"@multiversx/sdk-core";import{WarpCache as Tr,WarpCacheKey as xe,WarpLogger as We}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"}],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}]},{name:"setChain",onlyOwner:!0,mutability:"mutable",inputs:[{name:"name",type:"bytes"},{name:"display_name",type:"bytes"},{name:"chain_id",type:"bytes"},{name:"block_time",type:"u32"},{name:"address_hrp",type:"bytes"},{name:"api_url",type:"bytes"},{name:"explorer_url",type:"bytes"},{name:"native_token",type:"bytes"}],outputs:[]},{name:"removeChain",onlyOwner:!0,mutability:"mutable",inputs:[{name:"name",type:"bytes"}],outputs:[]},{name:"getChain",mutability:"readonly",inputs:[{name:"name",type:"bytes"}],outputs:[{type:"ChainView"}]},{name:"getChains",mutability:"readonly",inputs:[],outputs:[{type:"variadic<ChainView>",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:{ChainView:{type:"struct",fields:[{name:"name",type:"bytes"},{name:"display_name",type:"bytes"},{name:"chain_id",type:"bytes"},{name:"block_time",type:"u32"},{name:"address_hrp",type:"bytes"},{name:"api_url",type:"bytes"},{name:"explorer_url",type:"bytes"},{name:"native_token",type:"bytes"}]},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 C=i=>{if(i==="devnet")return"erd1qqqqqqqqqqqqqpgqje2f99vr6r7sk54thg03c9suzcvwr4nfl3tsfkdl36";if(i==="testnet")throw new Error("Multiversx testnet is not supported");return"erd1qqqqqqqqqqqqqpgq3mrpj3u6q7tejv6d7eqhnyd27n9v5c5tl3ts08mffe"};var H=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}),pt=i=>({unitPrice:BigInt(i.unit_price.toString()),admins:i.admins.map(e=>e.toBech32())});var Q=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=this.config.user?.wallets?.[this.chain.name]||null}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?[g.fromHex(e),g.fromUTF8(t),g.fromHex(r)]:t?[g.fromHex(e),g.fromUTF8(t)]:[g.fromHex(e)];return await this.getFactory().createTransactionForExecute(n,{contract:d.newFromBech32(C(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(C(this.config.env)),function:"unregisterWarp",gasLimit:BigInt(1e7),arguments:[g.fromHex(e)]})}async createWarpUpgradeTransaction(e,t){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 r=d.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(r,{contract:d.newFromBech32(C(this.config.env)),function:"upgradeWarp",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[g.fromUTF8(e),g.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(C(this.config.env)),function:"setWarpAlias",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[g.fromHex(e),g.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(C(this.config.env)),function:"verifyWarp",gasLimit:BigInt(1e7),arguments:[g.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(C(this.config.env)),function:"transferOwnership",gasLimit:BigInt(1e7),arguments:[g.fromHex(e),new Ce(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(C(this.config.env)),function:"registerBrand",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[g.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(C(this.config.env)),function:"brandWarp",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[g.fromHex(e),g.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 We.info(`WarpRegistry (getInfoByAlias): RegistryInfo found in cache: ${e}`),n;let a=d.newFromBech32(C(this.config.env)),o=this.getController(),s=o.createQuery({contract:a,function:"getInfoByAlias",arguments:[g.fromUTF8(e)]}),c=await o.runQuery(s),[p]=o.parseQueryResponse(c),u=p?H(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 We.info(`WarpRegistry (getInfoByHash): RegistryInfo found in cache: ${e}`),l}let n=d.newFromBech32(C(this.config.env)),a=this.getController(),o=a.createQuery({contract:n,function:"getInfoByHash",arguments:[g.fromHex(e)]}),s=await a.runQuery(o),[c]=a.parseQueryResponse(s),p=c?H(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(C(this.config.env)),n=this.getController(),a=n.createQuery({contract:r,function:"getUserWarps",arguments:[new Ce(new d(t))]}),o=await n.runQuery(a),[s]=n.parseQueryResponse(o);return s.map(H)}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(C(this.config.env)),n=this.getController(),a=n.createQuery({contract:r,function:"getUserBrands",arguments:[new Ce(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 We.info(`WarpRegistry (fetchBrand): Brand found in cache: ${e}`),n;let o=f.getChainEntrypoint(this.chain,this.config.env).createNetworkProvider();try{let s=await o.getTransaction(e),c=JSON.parse(s.data.toString());return c.meta={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(C(this.config.env)),t=this.getController(),[r]=await t.query({contract:e,function:"getConfig",arguments:[]}),n=r?pt(r):null;this.registryConfig=n||{unitPrice:BigInt(0),admins:[]}}getFactory(){let e=new Wr({chainID:this.chain.chainId}),t=ut.create(we);return new xr({config:e,abi:t})}getController(){let e=f.getChainEntrypoint(this.chain,this.config.env),t=ut.create(we);return e.createSmartContractController(t)}isCurrentUserAdmin(){return!!this.userWallet&&this.registryConfig.admins.includes(this.userWallet)}};var G=(i,e,t)=>(r,n)=>{let a=t[r.env];return{chain:i,chainInfo:a,prefix:e,builder:()=>new q(r,a),executor:new f(r,a),results:new S(r,a),serializer:new I,registry:new Q(r,a),explorer:new z(i,r),abiBuilder:()=>new B(r,a),brandBuilder:()=>new L(r,a),dataLoader:new D(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:R.Multiversx,identifier:"EGLD",name:"eGold",decimals:18,logoUrl:"https://vleap.ai/images/tokens/egld.svg"},lt=G(R.Multiversx,"mvx",{mainnet:{name:R.Multiversx,displayName:"MultiversX",chainId:"1",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://api.multiversx.com",nativeToken:Te},testnet:{name:R.Multiversx,displayName:"MultiversX Testnet",chainId:"T",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://testnet-api.multiversx.com",nativeToken:Te},devnet:{name:R.Multiversx,displayName:"MultiversX Devnet",chainId:"D",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://devnet-api.multiversx.com",nativeToken:Te}});import{WarpChainName as be}from"@vleap/warps";var vr={chain:be.Vibechain,identifier:"VIBE",name:"VIBE",decimals:18,logoUrl:"https://vleap.ai/images/tokens/vibe.svg"},ve={name:be.Vibechain,displayName:"VibeChain",chainId:"V",blockTime:600,addressHrp:"vibe",defaultApiUrl:"https://vibeox-api.multiversx.com",nativeToken:vr},mt=G(be.Vibechain,"vibe",{mainnet:ve,testnet:ve,devnet:ve});var Es=(i,e)=>[lt(i,e),mt(i,e)],As=()=>[dt.Multiversx,dt.Vibechain];export{V as ExplorerUrls,Bt as KnownTokens,ft as MultiversxExplorers,Ee as MultiversxExplorersConfig,Te as NativeTokenEgld,vr as NativeTokenVibe,ht as VibechainExplorers,B as WarpMultiversxAbiBuilder,L as WarpMultiversxBrandBuilder,q as WarpMultiversxBuilder,N as WarpMultiversxConstants,$ as WarpMultiversxContractLoader,D as WarpMultiversxDataLoader,f as WarpMultiversxExecutor,z as WarpMultiversxExplorer,Q as WarpMultiversxRegistry,S as WarpMultiversxResults,I as WarpMultiversxSerializer,gn as address_value,fn as biguint_value,hn as boolean_value,Cn as codemeta_value,cn as composite_value,G as createMultiversxAdapter,Je as esdt_value,Qe as findKnownTokenById,Es as getAllMultiversxAdapters,As as getAllMultiversxChainNames,lt as getMultiversxAdapter,C as getMultiversxRegistryAddress,mt as getVibechainAdapter,wn as hex_value,sn as list_value,xn as nothing_value,nn as option_value,an as optional_value,pn as string_value,yn as token_value,ln as u16_value,mn as u32_value,dn as u64_value,un as u8_value,on 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.43",
3
+ "version": "0.2.0-alpha.44",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",