@vleap/warps-adapter-multiversx 0.2.0-alpha.12 → 0.2.0-alpha.13

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.d.mts CHANGED
@@ -98,6 +98,7 @@ declare class WarpMultiversxRegistry implements AdapterWarpRegistry {
98
98
  registryConfig: WarpRegistryConfigInfo;
99
99
  constructor(config: WarpClientConfig);
100
100
  init(): Promise<void>;
101
+ getRegistryConfig(): WarpRegistryConfigInfo;
101
102
  createWarpRegisterTransaction(txHash: string, alias?: string | null, brand?: string | null): Transaction;
102
103
  createWarpUnregisterTransaction(txHash: string): Transaction;
103
104
  createWarpUpgradeTransaction(alias: string, txHash: string): Transaction;
package/dist/index.d.ts CHANGED
@@ -98,6 +98,7 @@ declare class WarpMultiversxRegistry implements AdapterWarpRegistry {
98
98
  registryConfig: WarpRegistryConfigInfo;
99
99
  constructor(config: WarpClientConfig);
100
100
  init(): Promise<void>;
101
+ getRegistryConfig(): WarpRegistryConfigInfo;
101
102
  createWarpRegisterTransaction(txHash: string, alias?: string | null, brand?: string | null): Transaction;
102
103
  createWarpUnregisterTransaction(txHash: string): Transaction;
103
104
  createWarpUpgradeTransaction(alias: string, txHash: string): Transaction;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var J=Object.defineProperty;var it=Object.getOwnPropertyDescriptor;var st=Object.getOwnPropertyNames;var ot=Object.prototype.hasOwnProperty;var ct=(i,t)=>{for(var e in t)J(i,e,{get:t[e],enumerable:!0})},ut=(i,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of st(t))!ot.call(i,a)&&a!==e&&J(i,a,{get:()=>t[a],enumerable:!(r=it(t,a))||r.enumerable});return i};var pt=i=>ut(J({},"__esModule",{value:!0}),i);var Et={};ct(Et,{WarpMultiversxAbi:()=>O,WarpMultiversxBrandBuilder:()=>et,WarpMultiversxBuilder:()=>z,WarpMultiversxConstants:()=>_,WarpMultiversxContractLoader:()=>L,WarpMultiversxExecutor:()=>b,WarpMultiversxExplorer:()=>Q,WarpMultiversxRegistry:()=>H,WarpMultiversxResults:()=>k,WarpMultiversxSerializer:()=>P,address_value:()=>Ct,biguint_value:()=>Wt,boolean_value:()=>Tt,codemeta_value:()=>It,composite_value:()=>gt,esdt_value:()=>Z,getMultiversxAdapter:()=>Bt,hex_value:()=>vt,list_value:()=>mt,nothing_value:()=>At,option_value:()=>lt,optional_value:()=>ft,string_value:()=>R,token_value:()=>bt,u16_value:()=>ht,u32_value:()=>Y,u64_value:()=>wt,u8_value:()=>yt,variadic_value:()=>dt});module.exports=pt(Et);var _={ChainName:"multiversx",Egld:{Identifier:"EGLD",EsdtIdentifier:"EGLD-000000",DisplayName:"eGold",Decimals:18}};var N=require("@multiversx/sdk-core"),S=require("@vleap/warps");var g=require("@multiversx/sdk-core"),x=require("@vleap/warps");var G=require("@multiversx/sdk-core"),B=require("@vleap/warps");var X=require("@vleap/warps");var L=class{constructor(t){this.config=t}async getContract(t,e){try{let o=await b.getChainEntrypoint(e,this.config.env).createNetworkProvider().doGetGeneric(`accounts/${t}`);return{address:t,owner:o.ownerAddress,verified:o.isVerified||!1}}catch(r){return X.WarpLogger.error("WarpContractLoader: getContract error",r),null}}async getVerificationInfo(t,e){try{let o=await b.getChainEntrypoint(e,this.config.env).createNetworkProvider().doGetGeneric(`accounts/${t}/verification`);return{codeHash:o.codeHash,abi:o.source.abi}}catch(r){return X.WarpLogger.error("WarpContractLoader: getVerificationInfo error",r),null}}};var O=class{constructor(t){this.config=t;this.contractLoader=new L(this.config),this.cache=new B.WarpCache(this.config.cache?.type)}async createFromRaw(t){return JSON.parse(t)}async createFromTransaction(t){let e=await this.createFromRaw(t.data.toString());return e.meta={hash:t.hash,creator:t.sender.bech32(),createdAt:new Date(t.timestamp*1e3).toISOString()},e}async createFromTransactionHash(t,e){let r=B.WarpCacheKey.WarpAbi(this.config.env,t);if(e){let s=this.cache.get(r);if(s)return B.WarpLogger.info(`WarpAbiBuilder (createFromTransactionHash): Warp abi found in cache: ${t}`),s}let a=(0,B.getMainChainInfo)(this.config),p=b.getChainEntrypoint(a,this.config.env).createNetworkProvider();try{let s=await p.getTransaction(t),l=await this.createFromTransaction(s);return e&&e.ttl&&l&&this.cache.set(r,l,e.ttl),l}catch(s){return B.WarpLogger.error("WarpAbiBuilder: Error creating from transaction hash",s),null}}async getAbiForAction(t){if(t.abi)return await this.fetchAbi(t);if(!t.address)throw new Error("WarpActionExecutor: Address not found");let e=(0,B.getMainChainInfo)(this.config),r=await this.contractLoader.getVerificationInfo(t.address,e);if(!r)throw new Error("WarpActionExecutor: Verification info not found");return G.AbiRegistry.create(r.abi)}async fetchAbi(t){if(!t.abi)throw new Error("WarpActionExecutor: ABI not found");if(t.abi.startsWith(B.WarpConstants.IdentifierType.Hash)){let e=t.abi.split(B.WarpConstants.IdentifierParamSeparator)[1],r=await this.createFromTransactionHash(e);if(!r)throw new Error(`WarpActionExecutor: ABI not found for hash: ${t.abi}`);return G.AbiRegistry.create(r.content)}else{let r=await(await fetch(t.abi)).json();return G.AbiRegistry.create(r)}}};var M=require("@multiversx/sdk-core"),h=require("@vleap/warps");var n=require("@multiversx/sdk-core"),v=require("@vleap/warps"),rt=new RegExp(`${v.WarpConstants.ArgParamsSeparator}(.*)`),P=class{constructor(){this.coreSerializer=new v.WarpSerializer}typedToString(t){if(t.hasClassOrSuperclass(n.OptionValue.ClassName))return t.isSet()?`option:${this.typedToString(t.getTypedValue())}`:"option:null";if(t.hasClassOrSuperclass(n.OptionalValue.ClassName))return t.isSet()?`optional:${this.typedToString(t.getTypedValue())}`:"optional:null";if(t.hasClassOrSuperclass(n.List.ClassName)){let e=t.getItems(),a=e.map(p=>this.typedToString(p).split(v.WarpConstants.ArgParamsSeparator)[0])[0],o=e.map(p=>this.typedToString(p).split(v.WarpConstants.ArgParamsSeparator)[1]);return`list:${a}:${o.join(",")}`}if(t.hasClassOrSuperclass(n.VariadicValue.ClassName)){let e=t.getItems(),a=e.map(p=>this.typedToString(p).split(v.WarpConstants.ArgParamsSeparator)[0])[0],o=e.map(p=>this.typedToString(p).split(v.WarpConstants.ArgParamsSeparator)[1]);return`variadic:${a}:${o.join(",")}`}if(t.hasClassOrSuperclass(n.CompositeValue.ClassName)){let e=t.getItems(),r=e.map(s=>this.typedToString(s).split(v.WarpConstants.ArgParamsSeparator)[0]),a=e.map(s=>this.typedToString(s).split(v.WarpConstants.ArgParamsSeparator)[1]),o=r.join(v.WarpConstants.ArgCompositeSeparator),p=a.join(v.WarpConstants.ArgCompositeSeparator);return`composite(${o}):${p}`}if(t.hasClassOrSuperclass(n.BigUIntValue.ClassName)||t.getType().getName()==="BigUint")return`biguint:${BigInt(t.valueOf().toFixed())}`;if(t.hasClassOrSuperclass(n.U8Value.ClassName))return`uint8:${t.valueOf().toNumber()}`;if(t.hasClassOrSuperclass(n.U16Value.ClassName))return`uint16:${t.valueOf().toNumber()}`;if(t.hasClassOrSuperclass(n.U32Value.ClassName))return`uint32:${t.valueOf().toNumber()}`;if(t.hasClassOrSuperclass(n.U64Value.ClassName))return`uint64:${BigInt(t.valueOf().toFixed())}`;if(t.hasClassOrSuperclass(n.StringValue.ClassName))return`string:${t.valueOf()}`;if(t.hasClassOrSuperclass(n.BooleanValue.ClassName))return`bool:${t.valueOf()}`;if(t.hasClassOrSuperclass(n.AddressValue.ClassName))return`address:${t.valueOf().bech32()}`;if(t.hasClassOrSuperclass(n.TokenIdentifierValue.ClassName))return`token:${t.valueOf()}`;if(t.hasClassOrSuperclass(n.BytesValue.ClassName))return`hex:${t.valueOf().toString("hex")}`;if(t.hasClassOrSuperclass(n.CodeMetadataValue.ClassName))return`codemeta:${t.valueOf().toBuffer().toString("hex")}`;if(t.getType().getName()==="EsdtTokenPayment"){let e=t.getFieldValue("token_identifier").valueOf(),r=t.getFieldValue("token_nonce").valueOf(),a=t.getFieldValue("amount").valueOf();return`esdt:${e}|${r}|${a}`}throw new Error(`WarpArgSerializer (typedToString): Unsupported input type: ${t.getClassName()}`)}typedToNative(t){let e=this.typedToString(t);return this.coreSerializer.stringToNative(e)}nativeToTyped(t,e){let r=this.coreSerializer.nativeToString(t,e);return this.stringToTyped(r)}nativeToType(t){if(t.startsWith("composite")){let e=t.match(/\(([^)]+)\)/)?.[1];return new n.CompositeType(...e.split(v.WarpConstants.ArgCompositeSeparator).map(r=>this.nativeToType(r)))}if(t==="string")return new n.StringType;if(t==="uint8")return new n.U8Type;if(t==="uint16")return new n.U16Type;if(t==="uint32")return new n.U32Type;if(t==="uint64")return new n.U64Type;if(t==="biguint")return new n.BigUIntType;if(t==="bool")return new n.BooleanType;if(t==="address")return new n.AddressType;if(t==="token")return new n.TokenIdentifierType;if(t==="hex")return new n.BytesType;if(t==="codemeta")return new n.CodeMetadataType;if(t==="esdt"||t==="nft")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: ${t}`)}stringToTyped(t){let[e,r]=t.split(/:(.*)/,2);if(e==="null"||e===null)return new n.NothingValue;if(e==="option"){let a=this.stringToTyped(r);return a instanceof n.NothingValue?n.OptionValue.newMissingTyped(a.getType()):n.OptionValue.newProvided(a)}if(e==="optional"){let a=this.stringToTyped(r);return a instanceof n.NothingValue?n.OptionalValue.newMissing():new n.OptionalValue(a.getType(),a)}if(e==="list"){let[a,o]=r.split(rt,2),s=o.split(",").map(l=>this.stringToTyped(`${a}:${l}`));return new n.List(this.nativeToType(a),s)}if(e==="variadic"){let[a,o]=r.split(rt,2),s=o.split(",").map(l=>this.stringToTyped(`${a}:${l}`));return new n.VariadicValue(new n.VariadicType(this.nativeToType(a)),s)}if(e.startsWith("composite")){let a=e.match(/\(([^)]+)\)/)?.[1],o=r.split(v.WarpConstants.ArgCompositeSeparator),p=a.split(v.WarpConstants.ArgCompositeSeparator),s=o.map((f,m)=>this.stringToTyped(`${p[m]}:${f}`)),l=s.map(f=>f.getType());return new n.CompositeValue(new n.CompositeType(...l),s)}if(e==="string")return r?n.StringValue.fromUTF8(r):new n.NothingValue;if(e==="uint8")return r?new n.U8Value(Number(r)):new n.NothingValue;if(e==="uint16")return r?new n.U16Value(Number(r)):new n.NothingValue;if(e==="uint32")return r?new n.U32Value(Number(r)):new n.NothingValue;if(e==="uint64")return r?new n.U64Value(BigInt(r)):new n.NothingValue;if(e==="biguint")return r?new n.BigUIntValue(BigInt(r)):new n.NothingValue;if(e==="bool")return r?new n.BooleanValue(typeof r=="boolean"?r:r==="true"):new n.NothingValue;if(e==="address")return r?new n.AddressValue(n.Address.newFromBech32(r)):new n.NothingValue;if(e==="token")return r?new n.TokenIdentifierValue(r):new n.NothingValue;if(e==="hex")return r?n.BytesValue.fromHex(r):new n.NothingValue;if(e==="codemeta")return new n.CodeMetadataValue(n.CodeMetadata.newFromBytes(Uint8Array.from(Buffer.from(r,"hex"))));if(e==="esdt"){let a=r.split(v.WarpConstants.ArgCompositeSeparator);return new n.Struct(this.nativeToType("esdt"),[new n.Field(new n.TokenIdentifierValue(a[0]),"token_identifier"),new n.Field(new n.U64Value(BigInt(a[1])),"token_nonce"),new n.Field(new n.BigUIntValue(BigInt(a[2])),"amount")])}throw new Error(`WarpArgSerializer (stringToTyped): Unsupported input type: ${e}`)}typeToString(t){if(t instanceof n.OptionType)return"option:"+this.typeToString(t.getFirstTypeParameter());if(t instanceof n.OptionalType)return"optional:"+this.typeToString(t.getFirstTypeParameter());if(t instanceof n.ListType)return"list:"+this.typeToString(t.getFirstTypeParameter());if(t instanceof n.VariadicType)return"variadic:"+this.typeToString(t.getFirstTypeParameter());if(t instanceof n.StringType)return"string";if(t instanceof n.U8Type)return"uint8";if(t instanceof n.U16Type)return"uint16";if(t instanceof n.U32Type)return"uint32";if(t instanceof n.U64Type)return"uint64";if(t instanceof n.BigUIntType)return"biguint";if(t instanceof n.BooleanType)return"bool";if(t instanceof n.AddressType)return"address";if(t instanceof n.TokenIdentifierType)return"token";if(t instanceof n.BytesType)return"hex";if(t instanceof n.CodeMetadataType)return"codemeta";if(t instanceof n.StructType&&t.getClassName()==="EsdtTokenPayment")return"esdt";throw new Error(`WarpArgSerializer (typeToString): Unsupported input type: ${t.getClassName()}`)}};var k=class{constructor(t){this.config=t;this.abi=new O(t),this.serializer=new P,this.cache=new h.WarpCache(t.cache?.type)}async getTransactionExecutionResults(t,e){let[r,a]=(0,h.findWarpExecutableAction)(t),o=this.cache.get(h.WarpCacheKey.WarpExecutable(this.config.env,t.meta?.hash||"",a))??[],p=await this.extractContractResults(t,e,o),s=(0,h.getNextInfo)(this.config,t,a,p),l=(0,h.applyResultsToMessages)(t,p.results);return{success:e.status.isSuccessful(),warp:t,action:a,user:this.config.user?.wallets?.[_.ChainName]||null,txHash:e.hash,next:s,values:p.values,results:p.results,messages:l}}async extractContractResults(t,e,r){let[a,o]=(0,h.findWarpExecutableAction)(t),p=[],s={};if(!t.results||a.type!=="contract")return{values:p,results:s};if(!Object.values(t.results).some(I=>I.includes("out")||I.includes("event"))){for(let[I,y]of Object.entries(t.results))s[I]=y;return{values:p,results:await(0,h.evaluateResultsCommon)(t,s,o,r)}}let f=await this.abi.getAbiForAction(a),m=new M.TransactionEventsParser({abi:f}),T=new M.SmartContractTransactionsOutcomeParser({abi:f}).parseExecute({transactionOnNetwork:e,function:a.func||void 0});for(let[I,y]of Object.entries(t.results)){if(y.startsWith(h.WarpConstants.Transform.Prefix))continue;if(y.startsWith("input.")){s[I]=y;continue}let E=(0,h.parseResultsOutIndex)(y);if(E!==null&&E!==o){s[I]=null;continue}let[A,F,V]=y.split(".");if(A==="event"){if(!F||isNaN(Number(V)))continue;let D=Number(V),C=(0,M.findEventsByFirstTopic)(e,F),q=m.parseEvents({events:C})[0],j=Object.values(q)[D]||null;p.push(j),s[I]=j&&j.valueOf()}else if(A==="out"||A.startsWith("out[")){if(!F)continue;let D=Number(F),C=T.values[D-1]||null;V&&(C=C[V]||null),C&&typeof C=="object"&&(C="toFixed"in C?C.toFixed():C.valueOf()),p.push(C),s[I]=C&&C.valueOf()}else s[I]=y}return{values:p,results:await(0,h.evaluateResultsCommon)(t,s,o,r)}}async extractQueryResults(t,e,r,a){let o=e.map(f=>this.serializer.typedToString(f)),p=e.map(f=>this.serializer.typedToNative(f)[1]),s={};if(!t.results)return{values:o,results:s};let l=f=>{let m=f.split(".").slice(1).map(T=>parseInt(T)-1);if(m.length===0)return;let d=p[m[0]];for(let T=1;T<m.length;T++){if(d==null)return;d=d[m[T]]}return d};for(let[f,m]of Object.entries(t.results)){if(m.startsWith(h.WarpConstants.Transform.Prefix))continue;let d=(0,h.parseResultsOutIndex)(m);if(d!==null&&d!==r){s[f]=null;continue}m.startsWith("out.")||m==="out"||m.startsWith("out[")?s[f]=l(m)||null:s[f]=m}return{values:o,results:await(0,h.evaluateResultsCommon)(t,s,r,a)}}async resolveWarpResultsRecursively(t){let e=t.warp,r=t.entryActionIndex,a=t.executor,o=t.inputs,p=t.meta,s=new Map,l=new Set,f=this;async function m(y,E=[]){if(s.has(y))return s.get(y);if(l.has(y))throw new Error(`Circular dependency detected at action ${y}`);l.add(y);let A=e.actions[y-1];if(!A)throw new Error(`Action ${y} not found`);let F;if(A.type==="query")F=await a.executeQuery(e,y,E);else if(A.type==="collect")F=await a.executeCollect(e,y,E,p);else throw new Error(`Unsupported or interactive action type: ${A.type}`);if(s.set(y,F),e.results)for(let V of Object.values(e.results)){let C=String(V).match(/^out\[(\d+)\]/);if(C){let q=parseInt(C[1],10);q!==y&&!s.has(q)&&await m(q)}}return l.delete(y),F}await m(r,o);let d={};for(let y of s.values())for(let[E,A]of Object.entries(y.results))A!==null?d[E]=A:E in d||(d[E]=null);let T=await(0,h.evaluateResultsCommon)(e,d,r,o);return{...s.get(r),action:r,results:T}}};var c=require("@multiversx/sdk-core"),lt=(i,t)=>i?c.OptionValue.newProvided(i):t?c.OptionValue.newMissingTyped(t):c.OptionValue.newMissing(),ft=(i,t)=>i?new c.OptionalValue(i.getType(),i):t?new c.OptionalValue(t):c.OptionalValue.newMissing(),mt=i=>{if(i.length===0)throw new Error("Cannot create a list from an empty array");let t=i[0].getType();return new c.List(t,i)},dt=i=>c.VariadicValue.fromItems(...i),gt=i=>{let t=i.map(e=>e.getType());return new c.CompositeValue(new c.CompositeType(...t),i)},R=i=>c.StringValue.fromUTF8(i),yt=i=>new c.U8Value(i),ht=i=>new c.U16Value(i),Y=i=>new c.U32Value(i),wt=i=>new c.U64Value(i),Wt=i=>new c.BigUIntValue(BigInt(i)),Tt=i=>new c.BooleanValue(i),Ct=i=>new c.AddressValue(c.Address.newFromBech32(i)),bt=i=>new c.TokenIdentifierValue(i),vt=i=>c.BytesValue.fromHex(i),Z=i=>new c.Struct(new c.StructType("EsdtTokenPayment",[new c.FieldDefinition("token_identifier","",new c.TokenIdentifierType),new c.FieldDefinition("token_nonce","",new c.U64Type),new c.FieldDefinition("amount","",new c.BigUIntType)]),[new c.Field(new c.TokenIdentifierValue(i.token.identifier),"token_identifier"),new c.Field(new c.U64Value(BigInt(i.token.nonce)),"token_nonce"),new c.Field(new c.BigUIntValue(BigInt(i.amount)),"amount")]),It=i=>new c.CodeMetadataValue(c.CodeMetadata.newFromBytes(Uint8Array.from(Buffer.from(i,"hex")))),At=()=>new c.NothingValue;var b=class i{constructor(t){this.config=t;this.serializer=new P,this.abi=new O(this.config),this.results=new k(this.config)}async createTransaction(t){let e=(0,x.getWarpActionByIndex)(t.warp,t.action),r=null;if(e.type==="transfer")r=await this.createTransferTransaction(t);else if(e.type==="contract")r=await this.createContractCallTransaction(t);else{if(e.type==="query")throw new Error("WarpMultiversxExecutor: Invalid action type for createTransactionForExecute; Use executeQuery instead");if(e.type==="collect")throw new Error("WarpMultiversxExecutor: Invalid action type for createTransactionForExecute; Use executeCollect instead")}if(!r)throw new Error(`WarpMultiversxExecutor: Invalid action type (${e.type})`);return r}async createTransferTransaction(t){let e=this.config.user?.wallets?.[t.chain.name];if(!e)throw new Error("WarpMultiversxExecutor: createTransfer - user address not set");let r=g.Address.newFromBech32(e),a=new g.TransactionsFactoryConfig({chainID:t.chain.chainId}),o=t.data?Buffer.from(this.serializer.stringToTyped(t.data).valueOf()):null;return new g.TransferTransactionsFactory({config:a}).createTransactionForTransfer(r,{receiver:g.Address.newFromBech32(t.destination),nativeAmount:t.value,data:o?new Uint8Array(o):void 0})}async createContractCallTransaction(t){let e=this.config.user?.wallets?.[t.chain.name];if(!e)throw new Error("WarpMultiversxExecutor: createContractCall - user address not set");let r=(0,x.getWarpActionByIndex)(t.warp,t.action),a=g.Address.newFromBech32(e),o=t.args.map(s=>this.serializer.stringToTyped(s)),p=new g.TransactionsFactoryConfig({chainID:t.chain.chainId});return new g.SmartContractTransactionsFactory({config:p}).createTransactionForExecute(a,{contract:g.Address.newFromBech32(t.destination),function:"func"in r&&r.func||"",gasLimit:"gasLimit"in r?BigInt(r.gasLimit||0):0n,arguments:o,nativeTransferAmount:t.value})}async executeQuery(t){let e=(0,x.getWarpActionByIndex)(t.warp,t.action);if(e.type!=="query")throw new Error(`WarpMultiversxExecutor: Invalid action type for executeQuery: ${e.type}`);let r=await this.abi.getAbiForAction(e),a=t.args.map(V=>this.serializer.stringToTyped(V)),o=i.getChainEntrypoint(t.chain,this.config.env),p=g.Address.newFromBech32(t.destination),s=o.createSmartContractController(r),l=s.createQuery({contract:p,function:e.func||"",arguments:a}),f=await s.runQuery(l),m=f.returnCode==="ok",d=new g.ArgSerializer,T=r.getEndpoint(f.function||e.func||""),I=(f.returnDataParts||[]).map(V=>Buffer.from(V)),y=d.buffersToValues(I,T.output),{values:E,results:A}=await this.results.extractQueryResults(t.warp,y,t.action,t.resolvedInputs),F=(0,x.getNextInfo)(this.config,t.warp,t.action,A);return{success:m,warp:t.warp,action:t.action,user:this.config.user?.wallets?.[t.chain.name]||null,txHash:null,next:F,values:E,results:A,messages:(0,x.applyResultsToMessages)(t.warp,A)}}async preprocessInput(t,e,r,a){if(r==="esdt"){let[o,p,s,l]=a.split(x.WarpConstants.ArgCompositeSeparator);if(l)return e;let f=new g.Token({identifier:o,nonce:BigInt(p)});if(!new g.TokenComputer().isFungible(f))return e;let T=(0,x.findKnownTokenById)(o)?.decimals;if(T||(T=(await(await fetch(`${t.apiUrl}/tokens/${o}`)).json()).decimals),!T)throw new Error(`WarpActionExecutor: Decimals not found for token ${o}`);let I=Z(new g.TokenTransfer({token:f,amount:(0,x.shiftBigintBy)(s,T)}));return this.serializer.typedToString(I)+x.WarpConstants.ArgCompositeSeparator+T}return e}static getChainEntrypoint(t,e){let r="warp-sdk",a="api";return e==="devnet"?new g.DevnetEntrypoint(t.apiUrl,a,r):e==="testnet"?new g.TestnetEntrypoint(t.apiUrl,a,r):new g.MainnetEntrypoint(t.apiUrl,a,r)}};var z=class{constructor(t){this.config=t;this.cache=new S.WarpCache(t.cache?.type),this.core=new S.WarpBuilder(t)}createInscriptionTransaction(t){let e=(0,S.getMainChainInfo)(this.config),r=this.config.user?.wallets?.[e.name];if(!r)throw new Error("WarpBuilder: user address not set");let a=new N.TransactionsFactoryConfig({chainID:e.chainId}),o=new N.TransferTransactionsFactory({config:a}),p=N.Address.newFromBech32(r),s=JSON.stringify(t),l=o.createTransactionForTransfer(p,{receiver:N.Address.newFromBech32(r),nativeAmount:BigInt(0),data:Uint8Array.from(Buffer.from(s))});return l.gasLimit=l.gasLimit+BigInt(2e6),l}async createFromTransaction(t,e=!1){let r=await this.core.createFromRaw(t.data.toString(),e);return r.meta={hash:t.hash,creator:t.sender.toBech32(),createdAt:new Date(t.timestamp*1e3).toISOString()},r}async createFromTransactionHash(t,e){let r=S.WarpCacheKey.Warp(this.config.env,t);if(e){let s=this.cache.get(r);if(s)return S.WarpLogger.info(`WarpBuilder (createFromTransactionHash): Warp found in cache: ${t}`),s}let a=(0,S.getMainChainInfo)(this.config),p=b.getChainEntrypoint(a,this.config.env).createNetworkProvider();try{let s=await p.getTransaction(t),l=await this.createFromTransaction(s);return e&&e.ttl&&l&&this.cache.set(r,l,e.ttl),l}catch(s){return S.WarpLogger.error("WarpBuilder: Error creating from transaction hash",s),null}}};var Q=class{constructor(t){this.chainInfo=t}getAccountUrl(t){return`${this.chainInfo.explorerUrl}/accounts/${t}`}getTransactionUrl(t){return`${this.chainInfo.explorerUrl}/transactions/${t}`}};var u=require("@multiversx/sdk-core"),w=require("@vleap/warps");var tt={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 W=i=>i==="devnet"?"erd1qqqqqqqqqqqqqpgqje2f99vr6r7sk54thg03c9suzcvwr4nfl3tsfkdl36":i==="testnet"?"####":"erd1qqqqqqqqqqqqqpgq3mrpj3u6q7tejv6d7eqhnyd27n9v5c5tl3ts08mffe";var K=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}),nt=i=>({unitPrice:BigInt(i.unit_price.toString()),admins:i.admins.map(t=>t.toBech32())});var H=class{constructor(t){this.config=t;this.cache=new w.WarpCache(t.cache?.type),this.registryConfig={unitPrice:BigInt(0),admins:[]},this.userWallet=this.config.user?.wallets?.[_.ChainName]||null}async init(){await this.loadRegistryConfigs()}createWarpRegisterTransaction(t,e,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),o=()=>this.isCurrentUserAdmin()?BigInt(0):e&&r?this.registryConfig.unitPrice*BigInt(3):e?this.registryConfig.unitPrice*BigInt(2):this.registryConfig.unitPrice,p=()=>e&&r?[u.BytesValue.fromHex(t),u.BytesValue.fromUTF8(e),u.BytesValue.fromHex(r)]:e?[u.BytesValue.fromHex(t),u.BytesValue.fromUTF8(e)]:[u.BytesValue.fromHex(t)];return this.getFactory().createTransactionForExecute(a,{contract:u.Address.newFromBech32(W(this.config.env)),function:"registerWarp",gasLimit:BigInt(1e7),nativeTransferAmount:o(),arguments:p()})}createWarpUnregisterTransaction(t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let e=u.Address.newFromBech32(this.userWallet);return this.getFactory().createTransactionForExecute(e,{contract:u.Address.newFromBech32(W(this.config.env)),function:"unregisterWarp",gasLimit:BigInt(1e7),arguments:[u.BytesValue.fromHex(t)]})}createWarpUpgradeTransaction(t,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 r=u.Address.newFromBech32(this.userWallet);return this.getFactory().createTransactionForExecute(r,{contract:u.Address.newFromBech32(W(this.config.env)),function:"upgradeWarp",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[u.BytesValue.fromUTF8(t),u.BytesValue.fromHex(e)]})}createWarpAliasSetTransaction(t,e){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let r=u.Address.newFromBech32(this.userWallet);return this.getFactory().createTransactionForExecute(r,{contract:u.Address.newFromBech32(W(this.config.env)),function:"setWarpAlias",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[u.BytesValue.fromHex(t),u.BytesValue.fromUTF8(e)]})}createWarpVerifyTransaction(t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let e=u.Address.newFromBech32(this.userWallet);return this.getFactory().createTransactionForExecute(e,{contract:u.Address.newFromBech32(W(this.config.env)),function:"verifyWarp",gasLimit:BigInt(1e7),arguments:[u.BytesValue.fromHex(t)]})}createWarpTransferOwnershipTransaction(t,e){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let r=u.Address.newFromBech32(this.userWallet);return this.getFactory().createTransactionForExecute(r,{contract:u.Address.newFromBech32(W(this.config.env)),function:"transferOwnership",gasLimit:BigInt(1e7),arguments:[u.BytesValue.fromHex(t),new u.AddressValue(new u.Address(e))]})}createBrandRegisterTransaction(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 e=u.Address.newFromBech32(this.userWallet);return this.getFactory().createTransactionForExecute(e,{contract:u.Address.newFromBech32(W(this.config.env)),function:"registerBrand",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[u.BytesValue.fromHex(t)]})}createWarpBrandingTransaction(t,e){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let r=u.Address.newFromBech32(this.userWallet);return this.getFactory().createTransactionForExecute(r,{contract:u.Address.newFromBech32(W(this.config.env)),function:"brandWarp",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[u.BytesValue.fromHex(t),u.BytesValue.fromHex(e)]})}async getInfoByAlias(t,e){try{let r=w.WarpCacheKey.RegistryInfo(this.config.env,t),a=e?this.cache.get(r):null;if(a)return w.WarpLogger.info(`WarpRegistry (getInfoByAlias): RegistryInfo found in cache: ${t}`),a;let o=u.Address.newFromBech32(W(this.config.env)),p=this.getController(),s=p.createQuery({contract:o,function:"getInfoByAlias",arguments:[u.BytesValue.fromUTF8(t)]}),l=await p.runQuery(s),[f]=p.parseQueryResponse(l),m=f?K(f):null,d=m?.brand?await this.fetchBrand(m.brand):null;return e&&e.ttl&&this.cache.set(r,{registryInfo:m,brand:d},e.ttl),{registryInfo:m,brand:d}}catch{return{registryInfo:null,brand:null}}}async getInfoByHash(t,e){try{let r=w.WarpCacheKey.RegistryInfo(this.config.env,t);if(e){let d=this.cache.get(r);if(d)return w.WarpLogger.info(`WarpRegistry (getInfoByHash): RegistryInfo found in cache: ${t}`),d}let a=u.Address.newFromBech32(W(this.config.env)),o=this.getController(),p=o.createQuery({contract:a,function:"getInfoByHash",arguments:[u.BytesValue.fromHex(t)]}),s=await o.runQuery(p),[l]=o.parseQueryResponse(s),f=l?K(l):null,m=f?.brand?await this.fetchBrand(f.brand):null;return e&&e.ttl&&this.cache.set(r,{registryInfo:f,brand:m},e.ttl),{registryInfo:f,brand:m}}catch{return{registryInfo:null,brand:null}}}async getUserWarpRegistryInfos(t){try{let e=t||this.userWallet;if(!e)throw new Error("WarpRegistry: user address not set");let r=u.Address.newFromBech32(W(this.config.env)),a=this.getController(),o=a.createQuery({contract:r,function:"getUserWarps",arguments:[new u.AddressValue(new u.Address(e))]}),p=await a.runQuery(o),[s]=a.parseQueryResponse(p);return s.map(K)}catch{return[]}}async getUserBrands(t){try{let e=t||this.userWallet;if(!e)throw new Error("WarpRegistry: user address not set");let r=u.Address.newFromBech32(W(this.config.env)),a=this.getController(),o=a.createQuery({contract:r,function:"getUserBrands",arguments:[new u.AddressValue(new u.Address(e))]}),p=await a.runQuery(o),[s]=a.parseQueryResponse(p),l=s.map(d=>d.toString("hex")),f={ttl:365*24*60*60};return(await Promise.all(l.map(d=>this.fetchBrand(d,f)))).filter(d=>d!==null)}catch{return[]}}async getChainInfos(t){let e=w.WarpCacheKey.ChainInfos(this.config.env);if(t&&t.ttl){let f=this.cache.get(e);if(f)return w.WarpLogger.info("WarpRegistry (getChainInfos): ChainInfos found in cache"),f}let r=u.Address.newFromBech32(W(this.config.env)),a=this.getController(),o=a.createQuery({contract:r,function:"getChains",arguments:[]}),p=await a.runQuery(o),[s]=a.parseQueryResponse(p),l=s.map(w.toTypedChainInfo);if(t&&t.ttl){for(let f of l)this.cache.set(w.WarpCacheKey.ChainInfo(this.config.env,f.chain),f,t.ttl);this.cache.set(e,l,t.ttl)}return l}async getChainInfo(t,e){try{let r=w.WarpCacheKey.ChainInfo(this.config.env,t),a=e?this.cache.get(r):null;if(a)return w.WarpLogger.info(`WarpRegistry (getChainInfo): ChainInfo found in cache: ${t}`),a;let o=u.Address.newFromBech32(W(this.config.env)),p=this.getController(),s=p.createQuery({contract:o,function:"getChain",arguments:[u.BytesValue.fromUTF8(t)]}),l=await p.runQuery(s),[f]=p.parseQueryResponse(l),m=f?(0,w.toTypedChainInfo)(f):null;return e&&e.ttl&&m&&this.cache.set(r,m,e.ttl),m}catch{return null}}async setChain(t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let e=u.Address.newFromBech32(this.userWallet);return this.getFactory().createTransactionForExecute(e,{contract:u.Address.newFromBech32(W(this.config.env)),function:"setChain",gasLimit:BigInt(1e7),arguments:[R(t.name),R(t.displayName),R(t.chainId),Y(t.blockTime),R(t.addressHrp),R(t.apiUrl),R(t.explorerUrl),R(t.nativeToken)]})}async removeChain(t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let e=u.Address.newFromBech32(this.userWallet);return this.getFactory().createTransactionForExecute(e,{contract:u.Address.newFromBech32(W(this.config.env)),function:"removeChain",gasLimit:BigInt(1e7),arguments:[R(t)]})}async fetchBrand(t,e){let r=w.WarpCacheKey.Brand(this.config.env,t),a=e?this.cache.get(r):null;if(a)return w.WarpLogger.info(`WarpRegistry (fetchBrand): Brand found in cache: ${t}`),a;let o=(0,w.getMainChainInfo)(this.config),s=b.getChainEntrypoint(o,this.config.env).createNetworkProvider();try{let l=await s.getTransaction(t),f=JSON.parse(l.data.toString());return f.meta={hash:l.hash,creator:l.sender.bech32(),createdAt:new Date(l.timestamp*1e3).toISOString()},e&&e.ttl&&this.cache.set(r,f,e.ttl),f}catch{return null}}async loadRegistryConfigs(){let t=u.Address.newFromBech32(W(this.config.env)),e=this.getController(),[r]=await e.query({contract:t,function:"getConfig",arguments:[]}),a=r?nt(r):null;this.registryConfig=a||{unitPrice:BigInt(0),admins:[]}}getFactory(){let t=(0,w.getMainChainInfo)(this.config),e=new u.TransactionsFactoryConfig({chainID:t.chainId}),r=u.AbiRegistry.create(tt);return new u.SmartContractTransactionsFactory({config:e,abi:r})}getController(){let t=(0,w.getMainChainInfo)(this.config),e=b.getChainEntrypoint(t,this.config.env),r=u.AbiRegistry.create(tt);return e.createSmartContractController(r)}isCurrentUserAdmin(){return!!this.userWallet&&this.registryConfig.admins.includes(this.userWallet)}};var Bt=i=>({chain:_.ChainName,prefix:"mvx",builder:new z(i),executor:new b(i),results:new k(i),serializer:new P,registry:new H(i),explorer:t=>new Q(t)});var U=require("@multiversx/sdk-core"),$=require("@vleap/warps"),at=require("buffer");var et=class{constructor(t){this.config=t;this.core=new $.WarpBrandBuilder(t)}createInscriptionTransaction(t){let e=(0,$.getMainChainInfo)(this.config),r=this.config.user?.wallets?.[e.name];if(!r)throw new Error("BrandBuilder: user address not set");let a=new U.TransactionsFactoryConfig({chainID:e.chainId}),o=new U.TransferTransactionsFactory({config:a}),p=U.Address.newFromBech32(r),s=JSON.stringify(t);return o.createTransactionForNativeTokenTransfer(p,{receiver:U.Address.newFromBech32(r),nativeAmount:BigInt(0),data:Uint8Array.from(at.Buffer.from(s))})}async createFromTransaction(t,e=!1){return await this.core.createFromRaw(t.data.toString(),e)}async createFromTransactionHash(t){let e=(0,$.getMainChainInfo)(this.config),a=b.getChainEntrypoint(e,this.config.env).createNetworkProvider();try{let o=await a.getTransaction(t);return this.createFromTransaction(o)}catch(o){return $.WarpLogger.error("BrandBuilder: Error creating from transaction hash",o),null}}};0&&(module.exports={WarpMultiversxAbi,WarpMultiversxBrandBuilder,WarpMultiversxBuilder,WarpMultiversxConstants,WarpMultiversxContractLoader,WarpMultiversxExecutor,WarpMultiversxExplorer,WarpMultiversxRegistry,WarpMultiversxResults,WarpMultiversxSerializer,address_value,biguint_value,boolean_value,codemeta_value,composite_value,esdt_value,getMultiversxAdapter,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 J=Object.defineProperty;var it=Object.getOwnPropertyDescriptor;var st=Object.getOwnPropertyNames;var ot=Object.prototype.hasOwnProperty;var ct=(i,t)=>{for(var e in t)J(i,e,{get:t[e],enumerable:!0})},ut=(i,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of st(t))!ot.call(i,a)&&a!==e&&J(i,a,{get:()=>t[a],enumerable:!(r=it(t,a))||r.enumerable});return i};var pt=i=>ut(J({},"__esModule",{value:!0}),i);var Et={};ct(Et,{WarpMultiversxAbi:()=>O,WarpMultiversxBrandBuilder:()=>et,WarpMultiversxBuilder:()=>z,WarpMultiversxConstants:()=>_,WarpMultiversxContractLoader:()=>L,WarpMultiversxExecutor:()=>b,WarpMultiversxExplorer:()=>Q,WarpMultiversxRegistry:()=>H,WarpMultiversxResults:()=>k,WarpMultiversxSerializer:()=>P,address_value:()=>Ct,biguint_value:()=>Wt,boolean_value:()=>Tt,codemeta_value:()=>It,composite_value:()=>dt,esdt_value:()=>Z,getMultiversxAdapter:()=>Bt,hex_value:()=>vt,list_value:()=>mt,nothing_value:()=>At,option_value:()=>lt,optional_value:()=>ft,string_value:()=>R,token_value:()=>bt,u16_value:()=>ht,u32_value:()=>Y,u64_value:()=>wt,u8_value:()=>yt,variadic_value:()=>gt});module.exports=pt(Et);var _={ChainName:"multiversx",Egld:{Identifier:"EGLD",EsdtIdentifier:"EGLD-000000",DisplayName:"eGold",Decimals:18}};var N=require("@multiversx/sdk-core"),S=require("@vleap/warps");var d=require("@multiversx/sdk-core"),x=require("@vleap/warps");var G=require("@multiversx/sdk-core"),B=require("@vleap/warps");var X=require("@vleap/warps");var L=class{constructor(t){this.config=t}async getContract(t,e){try{let o=await b.getChainEntrypoint(e,this.config.env).createNetworkProvider().doGetGeneric(`accounts/${t}`);return{address:t,owner:o.ownerAddress,verified:o.isVerified||!1}}catch(r){return X.WarpLogger.error("WarpContractLoader: getContract error",r),null}}async getVerificationInfo(t,e){try{let o=await b.getChainEntrypoint(e,this.config.env).createNetworkProvider().doGetGeneric(`accounts/${t}/verification`);return{codeHash:o.codeHash,abi:o.source.abi}}catch(r){return X.WarpLogger.error("WarpContractLoader: getVerificationInfo error",r),null}}};var O=class{constructor(t){this.config=t;this.contractLoader=new L(this.config),this.cache=new B.WarpCache(this.config.cache?.type)}async createFromRaw(t){return JSON.parse(t)}async createFromTransaction(t){let e=await this.createFromRaw(t.data.toString());return e.meta={hash:t.hash,creator:t.sender.bech32(),createdAt:new Date(t.timestamp*1e3).toISOString()},e}async createFromTransactionHash(t,e){let r=B.WarpCacheKey.WarpAbi(this.config.env,t);if(e){let s=this.cache.get(r);if(s)return B.WarpLogger.info(`WarpAbiBuilder (createFromTransactionHash): Warp abi found in cache: ${t}`),s}let a=(0,B.getMainChainInfo)(this.config),p=b.getChainEntrypoint(a,this.config.env).createNetworkProvider();try{let s=await p.getTransaction(t),l=await this.createFromTransaction(s);return e&&e.ttl&&l&&this.cache.set(r,l,e.ttl),l}catch(s){return B.WarpLogger.error("WarpAbiBuilder: Error creating from transaction hash",s),null}}async getAbiForAction(t){if(t.abi)return await this.fetchAbi(t);if(!t.address)throw new Error("WarpActionExecutor: Address not found");let e=(0,B.getMainChainInfo)(this.config),r=await this.contractLoader.getVerificationInfo(t.address,e);if(!r)throw new Error("WarpActionExecutor: Verification info not found");return G.AbiRegistry.create(r.abi)}async fetchAbi(t){if(!t.abi)throw new Error("WarpActionExecutor: ABI not found");if(t.abi.startsWith(B.WarpConstants.IdentifierType.Hash)){let e=t.abi.split(B.WarpConstants.IdentifierParamSeparator)[1],r=await this.createFromTransactionHash(e);if(!r)throw new Error(`WarpActionExecutor: ABI not found for hash: ${t.abi}`);return G.AbiRegistry.create(r.content)}else{let r=await(await fetch(t.abi)).json();return G.AbiRegistry.create(r)}}};var M=require("@multiversx/sdk-core"),h=require("@vleap/warps");var n=require("@multiversx/sdk-core"),v=require("@vleap/warps"),rt=new RegExp(`${v.WarpConstants.ArgParamsSeparator}(.*)`),P=class{constructor(){this.coreSerializer=new v.WarpSerializer}typedToString(t){if(t.hasClassOrSuperclass(n.OptionValue.ClassName))return t.isSet()?`option:${this.typedToString(t.getTypedValue())}`:"option:null";if(t.hasClassOrSuperclass(n.OptionalValue.ClassName))return t.isSet()?`optional:${this.typedToString(t.getTypedValue())}`:"optional:null";if(t.hasClassOrSuperclass(n.List.ClassName)){let e=t.getItems(),a=e.map(p=>this.typedToString(p).split(v.WarpConstants.ArgParamsSeparator)[0])[0],o=e.map(p=>this.typedToString(p).split(v.WarpConstants.ArgParamsSeparator)[1]);return`list:${a}:${o.join(",")}`}if(t.hasClassOrSuperclass(n.VariadicValue.ClassName)){let e=t.getItems(),a=e.map(p=>this.typedToString(p).split(v.WarpConstants.ArgParamsSeparator)[0])[0],o=e.map(p=>this.typedToString(p).split(v.WarpConstants.ArgParamsSeparator)[1]);return`variadic:${a}:${o.join(",")}`}if(t.hasClassOrSuperclass(n.CompositeValue.ClassName)){let e=t.getItems(),r=e.map(s=>this.typedToString(s).split(v.WarpConstants.ArgParamsSeparator)[0]),a=e.map(s=>this.typedToString(s).split(v.WarpConstants.ArgParamsSeparator)[1]),o=r.join(v.WarpConstants.ArgCompositeSeparator),p=a.join(v.WarpConstants.ArgCompositeSeparator);return`composite(${o}):${p}`}if(t.hasClassOrSuperclass(n.BigUIntValue.ClassName)||t.getType().getName()==="BigUint")return`biguint:${BigInt(t.valueOf().toFixed())}`;if(t.hasClassOrSuperclass(n.U8Value.ClassName))return`uint8:${t.valueOf().toNumber()}`;if(t.hasClassOrSuperclass(n.U16Value.ClassName))return`uint16:${t.valueOf().toNumber()}`;if(t.hasClassOrSuperclass(n.U32Value.ClassName))return`uint32:${t.valueOf().toNumber()}`;if(t.hasClassOrSuperclass(n.U64Value.ClassName))return`uint64:${BigInt(t.valueOf().toFixed())}`;if(t.hasClassOrSuperclass(n.StringValue.ClassName))return`string:${t.valueOf()}`;if(t.hasClassOrSuperclass(n.BooleanValue.ClassName))return`bool:${t.valueOf()}`;if(t.hasClassOrSuperclass(n.AddressValue.ClassName))return`address:${t.valueOf().bech32()}`;if(t.hasClassOrSuperclass(n.TokenIdentifierValue.ClassName))return`token:${t.valueOf()}`;if(t.hasClassOrSuperclass(n.BytesValue.ClassName))return`hex:${t.valueOf().toString("hex")}`;if(t.hasClassOrSuperclass(n.CodeMetadataValue.ClassName))return`codemeta:${t.valueOf().toBuffer().toString("hex")}`;if(t.getType().getName()==="EsdtTokenPayment"){let e=t.getFieldValue("token_identifier").valueOf(),r=t.getFieldValue("token_nonce").valueOf(),a=t.getFieldValue("amount").valueOf();return`esdt:${e}|${r}|${a}`}throw new Error(`WarpArgSerializer (typedToString): Unsupported input type: ${t.getClassName()}`)}typedToNative(t){let e=this.typedToString(t);return this.coreSerializer.stringToNative(e)}nativeToTyped(t,e){let r=this.coreSerializer.nativeToString(t,e);return this.stringToTyped(r)}nativeToType(t){if(t.startsWith("composite")){let e=t.match(/\(([^)]+)\)/)?.[1];return new n.CompositeType(...e.split(v.WarpConstants.ArgCompositeSeparator).map(r=>this.nativeToType(r)))}if(t==="string")return new n.StringType;if(t==="uint8")return new n.U8Type;if(t==="uint16")return new n.U16Type;if(t==="uint32")return new n.U32Type;if(t==="uint64")return new n.U64Type;if(t==="biguint")return new n.BigUIntType;if(t==="bool")return new n.BooleanType;if(t==="address")return new n.AddressType;if(t==="token")return new n.TokenIdentifierType;if(t==="hex")return new n.BytesType;if(t==="codemeta")return new n.CodeMetadataType;if(t==="esdt"||t==="nft")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: ${t}`)}stringToTyped(t){let[e,r]=t.split(/:(.*)/,2);if(e==="null"||e===null)return new n.NothingValue;if(e==="option"){let a=this.stringToTyped(r);return a instanceof n.NothingValue?n.OptionValue.newMissingTyped(a.getType()):n.OptionValue.newProvided(a)}if(e==="optional"){let a=this.stringToTyped(r);return a instanceof n.NothingValue?n.OptionalValue.newMissing():new n.OptionalValue(a.getType(),a)}if(e==="list"){let[a,o]=r.split(rt,2),s=o.split(",").map(l=>this.stringToTyped(`${a}:${l}`));return new n.List(this.nativeToType(a),s)}if(e==="variadic"){let[a,o]=r.split(rt,2),s=o.split(",").map(l=>this.stringToTyped(`${a}:${l}`));return new n.VariadicValue(new n.VariadicType(this.nativeToType(a)),s)}if(e.startsWith("composite")){let a=e.match(/\(([^)]+)\)/)?.[1],o=r.split(v.WarpConstants.ArgCompositeSeparator),p=a.split(v.WarpConstants.ArgCompositeSeparator),s=o.map((f,m)=>this.stringToTyped(`${p[m]}:${f}`)),l=s.map(f=>f.getType());return new n.CompositeValue(new n.CompositeType(...l),s)}if(e==="string")return r?n.StringValue.fromUTF8(r):new n.NothingValue;if(e==="uint8")return r?new n.U8Value(Number(r)):new n.NothingValue;if(e==="uint16")return r?new n.U16Value(Number(r)):new n.NothingValue;if(e==="uint32")return r?new n.U32Value(Number(r)):new n.NothingValue;if(e==="uint64")return r?new n.U64Value(BigInt(r)):new n.NothingValue;if(e==="biguint")return r?new n.BigUIntValue(BigInt(r)):new n.NothingValue;if(e==="bool")return r?new n.BooleanValue(typeof r=="boolean"?r:r==="true"):new n.NothingValue;if(e==="address")return r?new n.AddressValue(n.Address.newFromBech32(r)):new n.NothingValue;if(e==="token")return r?new n.TokenIdentifierValue(r):new n.NothingValue;if(e==="hex")return r?n.BytesValue.fromHex(r):new n.NothingValue;if(e==="codemeta")return new n.CodeMetadataValue(n.CodeMetadata.newFromBytes(Uint8Array.from(Buffer.from(r,"hex"))));if(e==="esdt"){let a=r.split(v.WarpConstants.ArgCompositeSeparator);return new n.Struct(this.nativeToType("esdt"),[new n.Field(new n.TokenIdentifierValue(a[0]),"token_identifier"),new n.Field(new n.U64Value(BigInt(a[1])),"token_nonce"),new n.Field(new n.BigUIntValue(BigInt(a[2])),"amount")])}throw new Error(`WarpArgSerializer (stringToTyped): Unsupported input type: ${e}`)}typeToString(t){if(t instanceof n.OptionType)return"option:"+this.typeToString(t.getFirstTypeParameter());if(t instanceof n.OptionalType)return"optional:"+this.typeToString(t.getFirstTypeParameter());if(t instanceof n.ListType)return"list:"+this.typeToString(t.getFirstTypeParameter());if(t instanceof n.VariadicType)return"variadic:"+this.typeToString(t.getFirstTypeParameter());if(t instanceof n.StringType)return"string";if(t instanceof n.U8Type)return"uint8";if(t instanceof n.U16Type)return"uint16";if(t instanceof n.U32Type)return"uint32";if(t instanceof n.U64Type)return"uint64";if(t instanceof n.BigUIntType)return"biguint";if(t instanceof n.BooleanType)return"bool";if(t instanceof n.AddressType)return"address";if(t instanceof n.TokenIdentifierType)return"token";if(t instanceof n.BytesType)return"hex";if(t instanceof n.CodeMetadataType)return"codemeta";if(t instanceof n.StructType&&t.getClassName()==="EsdtTokenPayment")return"esdt";throw new Error(`WarpArgSerializer (typeToString): Unsupported input type: ${t.getClassName()}`)}};var k=class{constructor(t){this.config=t;this.abi=new O(t),this.serializer=new P,this.cache=new h.WarpCache(t.cache?.type)}async getTransactionExecutionResults(t,e){let[r,a]=(0,h.findWarpExecutableAction)(t),o=this.cache.get(h.WarpCacheKey.WarpExecutable(this.config.env,t.meta?.hash||"",a))??[],p=await this.extractContractResults(t,e,o),s=(0,h.getNextInfo)(this.config,t,a,p),l=(0,h.applyResultsToMessages)(t,p.results);return{success:e.status.isSuccessful(),warp:t,action:a,user:this.config.user?.wallets?.[_.ChainName]||null,txHash:e.hash,next:s,values:p.values,results:p.results,messages:l}}async extractContractResults(t,e,r){let[a,o]=(0,h.findWarpExecutableAction)(t),p=[],s={};if(!t.results||a.type!=="contract")return{values:p,results:s};if(!Object.values(t.results).some(I=>I.includes("out")||I.includes("event"))){for(let[I,y]of Object.entries(t.results))s[I]=y;return{values:p,results:await(0,h.evaluateResultsCommon)(t,s,o,r)}}let f=await this.abi.getAbiForAction(a),m=new M.TransactionEventsParser({abi:f}),T=new M.SmartContractTransactionsOutcomeParser({abi:f}).parseExecute({transactionOnNetwork:e,function:a.func||void 0});for(let[I,y]of Object.entries(t.results)){if(y.startsWith(h.WarpConstants.Transform.Prefix))continue;if(y.startsWith("input.")){s[I]=y;continue}let E=(0,h.parseResultsOutIndex)(y);if(E!==null&&E!==o){s[I]=null;continue}let[A,F,V]=y.split(".");if(A==="event"){if(!F||isNaN(Number(V)))continue;let D=Number(V),C=(0,M.findEventsByFirstTopic)(e,F),q=m.parseEvents({events:C})[0],j=Object.values(q)[D]||null;p.push(j),s[I]=j&&j.valueOf()}else if(A==="out"||A.startsWith("out[")){if(!F)continue;let D=Number(F),C=T.values[D-1]||null;V&&(C=C[V]||null),C&&typeof C=="object"&&(C="toFixed"in C?C.toFixed():C.valueOf()),p.push(C),s[I]=C&&C.valueOf()}else s[I]=y}return{values:p,results:await(0,h.evaluateResultsCommon)(t,s,o,r)}}async extractQueryResults(t,e,r,a){let o=e.map(f=>this.serializer.typedToString(f)),p=e.map(f=>this.serializer.typedToNative(f)[1]),s={};if(!t.results)return{values:o,results:s};let l=f=>{let m=f.split(".").slice(1).map(T=>parseInt(T)-1);if(m.length===0)return;let g=p[m[0]];for(let T=1;T<m.length;T++){if(g==null)return;g=g[m[T]]}return g};for(let[f,m]of Object.entries(t.results)){if(m.startsWith(h.WarpConstants.Transform.Prefix))continue;let g=(0,h.parseResultsOutIndex)(m);if(g!==null&&g!==r){s[f]=null;continue}m.startsWith("out.")||m==="out"||m.startsWith("out[")?s[f]=l(m)||null:s[f]=m}return{values:o,results:await(0,h.evaluateResultsCommon)(t,s,r,a)}}async resolveWarpResultsRecursively(t){let e=t.warp,r=t.entryActionIndex,a=t.executor,o=t.inputs,p=t.meta,s=new Map,l=new Set,f=this;async function m(y,E=[]){if(s.has(y))return s.get(y);if(l.has(y))throw new Error(`Circular dependency detected at action ${y}`);l.add(y);let A=e.actions[y-1];if(!A)throw new Error(`Action ${y} not found`);let F;if(A.type==="query")F=await a.executeQuery(e,y,E);else if(A.type==="collect")F=await a.executeCollect(e,y,E,p);else throw new Error(`Unsupported or interactive action type: ${A.type}`);if(s.set(y,F),e.results)for(let V of Object.values(e.results)){let C=String(V).match(/^out\[(\d+)\]/);if(C){let q=parseInt(C[1],10);q!==y&&!s.has(q)&&await m(q)}}return l.delete(y),F}await m(r,o);let g={};for(let y of s.values())for(let[E,A]of Object.entries(y.results))A!==null?g[E]=A:E in g||(g[E]=null);let T=await(0,h.evaluateResultsCommon)(e,g,r,o);return{...s.get(r),action:r,results:T}}};var c=require("@multiversx/sdk-core"),lt=(i,t)=>i?c.OptionValue.newProvided(i):t?c.OptionValue.newMissingTyped(t):c.OptionValue.newMissing(),ft=(i,t)=>i?new c.OptionalValue(i.getType(),i):t?new c.OptionalValue(t):c.OptionalValue.newMissing(),mt=i=>{if(i.length===0)throw new Error("Cannot create a list from an empty array");let t=i[0].getType();return new c.List(t,i)},gt=i=>c.VariadicValue.fromItems(...i),dt=i=>{let t=i.map(e=>e.getType());return new c.CompositeValue(new c.CompositeType(...t),i)},R=i=>c.StringValue.fromUTF8(i),yt=i=>new c.U8Value(i),ht=i=>new c.U16Value(i),Y=i=>new c.U32Value(i),wt=i=>new c.U64Value(i),Wt=i=>new c.BigUIntValue(BigInt(i)),Tt=i=>new c.BooleanValue(i),Ct=i=>new c.AddressValue(c.Address.newFromBech32(i)),bt=i=>new c.TokenIdentifierValue(i),vt=i=>c.BytesValue.fromHex(i),Z=i=>new c.Struct(new c.StructType("EsdtTokenPayment",[new c.FieldDefinition("token_identifier","",new c.TokenIdentifierType),new c.FieldDefinition("token_nonce","",new c.U64Type),new c.FieldDefinition("amount","",new c.BigUIntType)]),[new c.Field(new c.TokenIdentifierValue(i.token.identifier),"token_identifier"),new c.Field(new c.U64Value(BigInt(i.token.nonce)),"token_nonce"),new c.Field(new c.BigUIntValue(BigInt(i.amount)),"amount")]),It=i=>new c.CodeMetadataValue(c.CodeMetadata.newFromBytes(Uint8Array.from(Buffer.from(i,"hex")))),At=()=>new c.NothingValue;var b=class i{constructor(t){this.config=t;this.serializer=new P,this.abi=new O(this.config),this.results=new k(this.config)}async createTransaction(t){let e=(0,x.getWarpActionByIndex)(t.warp,t.action),r=null;if(e.type==="transfer")r=await this.createTransferTransaction(t);else if(e.type==="contract")r=await this.createContractCallTransaction(t);else{if(e.type==="query")throw new Error("WarpMultiversxExecutor: Invalid action type for createTransactionForExecute; Use executeQuery instead");if(e.type==="collect")throw new Error("WarpMultiversxExecutor: Invalid action type for createTransactionForExecute; Use executeCollect instead")}if(!r)throw new Error(`WarpMultiversxExecutor: Invalid action type (${e.type})`);return r}async createTransferTransaction(t){let e=this.config.user?.wallets?.[t.chain.name];if(!e)throw new Error("WarpMultiversxExecutor: createTransfer - user address not set");let r=d.Address.newFromBech32(e),a=new d.TransactionsFactoryConfig({chainID:t.chain.chainId}),o=t.data?Buffer.from(this.serializer.stringToTyped(t.data).valueOf()):null;return new d.TransferTransactionsFactory({config:a}).createTransactionForTransfer(r,{receiver:d.Address.newFromBech32(t.destination),nativeAmount:t.value,data:o?new Uint8Array(o):void 0})}async createContractCallTransaction(t){let e=this.config.user?.wallets?.[t.chain.name];if(!e)throw new Error("WarpMultiversxExecutor: createContractCall - user address not set");let r=(0,x.getWarpActionByIndex)(t.warp,t.action),a=d.Address.newFromBech32(e),o=t.args.map(s=>this.serializer.stringToTyped(s)),p=new d.TransactionsFactoryConfig({chainID:t.chain.chainId});return new d.SmartContractTransactionsFactory({config:p}).createTransactionForExecute(a,{contract:d.Address.newFromBech32(t.destination),function:"func"in r&&r.func||"",gasLimit:"gasLimit"in r?BigInt(r.gasLimit||0):0n,arguments:o,nativeTransferAmount:t.value})}async executeQuery(t){let e=(0,x.getWarpActionByIndex)(t.warp,t.action);if(e.type!=="query")throw new Error(`WarpMultiversxExecutor: Invalid action type for executeQuery: ${e.type}`);let r=await this.abi.getAbiForAction(e),a=t.args.map(V=>this.serializer.stringToTyped(V)),o=i.getChainEntrypoint(t.chain,this.config.env),p=d.Address.newFromBech32(t.destination),s=o.createSmartContractController(r),l=s.createQuery({contract:p,function:e.func||"",arguments:a}),f=await s.runQuery(l),m=f.returnCode==="ok",g=new d.ArgSerializer,T=r.getEndpoint(f.function||e.func||""),I=(f.returnDataParts||[]).map(V=>Buffer.from(V)),y=g.buffersToValues(I,T.output),{values:E,results:A}=await this.results.extractQueryResults(t.warp,y,t.action,t.resolvedInputs),F=(0,x.getNextInfo)(this.config,t.warp,t.action,A);return{success:m,warp:t.warp,action:t.action,user:this.config.user?.wallets?.[t.chain.name]||null,txHash:null,next:F,values:E,results:A,messages:(0,x.applyResultsToMessages)(t.warp,A)}}async preprocessInput(t,e,r,a){if(r==="esdt"){let[o,p,s,l]=a.split(x.WarpConstants.ArgCompositeSeparator);if(l)return e;let f=new d.Token({identifier:o,nonce:BigInt(p)});if(!new d.TokenComputer().isFungible(f))return e;let T=(0,x.findKnownTokenById)(o)?.decimals;if(T||(T=(await(await fetch(`${t.apiUrl}/tokens/${o}`)).json()).decimals),!T)throw new Error(`WarpActionExecutor: Decimals not found for token ${o}`);let I=Z(new d.TokenTransfer({token:f,amount:(0,x.shiftBigintBy)(s,T)}));return this.serializer.typedToString(I)+x.WarpConstants.ArgCompositeSeparator+T}return e}static getChainEntrypoint(t,e){let r="warp-sdk",a="api";return e==="devnet"?new d.DevnetEntrypoint(t.apiUrl,a,r):e==="testnet"?new d.TestnetEntrypoint(t.apiUrl,a,r):new d.MainnetEntrypoint(t.apiUrl,a,r)}};var z=class{constructor(t){this.config=t;this.cache=new S.WarpCache(t.cache?.type),this.core=new S.WarpBuilder(t)}createInscriptionTransaction(t){let e=(0,S.getMainChainInfo)(this.config),r=this.config.user?.wallets?.[e.name];if(!r)throw new Error("WarpBuilder: user address not set");let a=new N.TransactionsFactoryConfig({chainID:e.chainId}),o=new N.TransferTransactionsFactory({config:a}),p=N.Address.newFromBech32(r),s=JSON.stringify(t),l=o.createTransactionForTransfer(p,{receiver:N.Address.newFromBech32(r),nativeAmount:BigInt(0),data:Uint8Array.from(Buffer.from(s))});return l.gasLimit=l.gasLimit+BigInt(2e6),l}async createFromTransaction(t,e=!1){let r=await this.core.createFromRaw(t.data.toString(),e);return r.meta={hash:t.hash,creator:t.sender.toBech32(),createdAt:new Date(t.timestamp*1e3).toISOString()},r}async createFromTransactionHash(t,e){let r=S.WarpCacheKey.Warp(this.config.env,t);if(e){let s=this.cache.get(r);if(s)return S.WarpLogger.info(`WarpBuilder (createFromTransactionHash): Warp found in cache: ${t}`),s}let a=(0,S.getMainChainInfo)(this.config),p=b.getChainEntrypoint(a,this.config.env).createNetworkProvider();try{let s=await p.getTransaction(t),l=await this.createFromTransaction(s);return e&&e.ttl&&l&&this.cache.set(r,l,e.ttl),l}catch(s){return S.WarpLogger.error("WarpBuilder: Error creating from transaction hash",s),null}}};var Q=class{constructor(t){this.chainInfo=t}getAccountUrl(t){return`${this.chainInfo.explorerUrl}/accounts/${t}`}getTransactionUrl(t){return`${this.chainInfo.explorerUrl}/transactions/${t}`}};var u=require("@multiversx/sdk-core"),w=require("@vleap/warps");var tt={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 W=i=>i==="devnet"?"erd1qqqqqqqqqqqqqpgqje2f99vr6r7sk54thg03c9suzcvwr4nfl3tsfkdl36":i==="testnet"?"####":"erd1qqqqqqqqqqqqqpgq3mrpj3u6q7tejv6d7eqhnyd27n9v5c5tl3ts08mffe";var K=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}),nt=i=>({unitPrice:BigInt(i.unit_price.toString()),admins:i.admins.map(t=>t.toBech32())});var H=class{constructor(t){this.config=t;this.cache=new w.WarpCache(t.cache?.type),this.registryConfig={unitPrice:BigInt(0),admins:[]},this.userWallet=this.config.user?.wallets?.[_.ChainName]||null}async init(){await this.loadRegistryConfigs()}getRegistryConfig(){return this.registryConfig}createWarpRegisterTransaction(t,e,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),o=()=>this.isCurrentUserAdmin()?BigInt(0):e&&r?this.registryConfig.unitPrice*BigInt(3):e?this.registryConfig.unitPrice*BigInt(2):this.registryConfig.unitPrice,p=()=>e&&r?[u.BytesValue.fromHex(t),u.BytesValue.fromUTF8(e),u.BytesValue.fromHex(r)]:e?[u.BytesValue.fromHex(t),u.BytesValue.fromUTF8(e)]:[u.BytesValue.fromHex(t)];return this.getFactory().createTransactionForExecute(a,{contract:u.Address.newFromBech32(W(this.config.env)),function:"registerWarp",gasLimit:BigInt(1e7),nativeTransferAmount:o(),arguments:p()})}createWarpUnregisterTransaction(t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let e=u.Address.newFromBech32(this.userWallet);return this.getFactory().createTransactionForExecute(e,{contract:u.Address.newFromBech32(W(this.config.env)),function:"unregisterWarp",gasLimit:BigInt(1e7),arguments:[u.BytesValue.fromHex(t)]})}createWarpUpgradeTransaction(t,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 r=u.Address.newFromBech32(this.userWallet);return this.getFactory().createTransactionForExecute(r,{contract:u.Address.newFromBech32(W(this.config.env)),function:"upgradeWarp",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[u.BytesValue.fromUTF8(t),u.BytesValue.fromHex(e)]})}createWarpAliasSetTransaction(t,e){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let r=u.Address.newFromBech32(this.userWallet);return this.getFactory().createTransactionForExecute(r,{contract:u.Address.newFromBech32(W(this.config.env)),function:"setWarpAlias",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[u.BytesValue.fromHex(t),u.BytesValue.fromUTF8(e)]})}createWarpVerifyTransaction(t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let e=u.Address.newFromBech32(this.userWallet);return this.getFactory().createTransactionForExecute(e,{contract:u.Address.newFromBech32(W(this.config.env)),function:"verifyWarp",gasLimit:BigInt(1e7),arguments:[u.BytesValue.fromHex(t)]})}createWarpTransferOwnershipTransaction(t,e){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let r=u.Address.newFromBech32(this.userWallet);return this.getFactory().createTransactionForExecute(r,{contract:u.Address.newFromBech32(W(this.config.env)),function:"transferOwnership",gasLimit:BigInt(1e7),arguments:[u.BytesValue.fromHex(t),new u.AddressValue(new u.Address(e))]})}createBrandRegisterTransaction(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 e=u.Address.newFromBech32(this.userWallet);return this.getFactory().createTransactionForExecute(e,{contract:u.Address.newFromBech32(W(this.config.env)),function:"registerBrand",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[u.BytesValue.fromHex(t)]})}createWarpBrandingTransaction(t,e){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let r=u.Address.newFromBech32(this.userWallet);return this.getFactory().createTransactionForExecute(r,{contract:u.Address.newFromBech32(W(this.config.env)),function:"brandWarp",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[u.BytesValue.fromHex(t),u.BytesValue.fromHex(e)]})}async getInfoByAlias(t,e){try{let r=w.WarpCacheKey.RegistryInfo(this.config.env,t),a=e?this.cache.get(r):null;if(a)return w.WarpLogger.info(`WarpRegistry (getInfoByAlias): RegistryInfo found in cache: ${t}`),a;let o=u.Address.newFromBech32(W(this.config.env)),p=this.getController(),s=p.createQuery({contract:o,function:"getInfoByAlias",arguments:[u.BytesValue.fromUTF8(t)]}),l=await p.runQuery(s),[f]=p.parseQueryResponse(l),m=f?K(f):null,g=m?.brand?await this.fetchBrand(m.brand):null;return e&&e.ttl&&this.cache.set(r,{registryInfo:m,brand:g},e.ttl),{registryInfo:m,brand:g}}catch{return{registryInfo:null,brand:null}}}async getInfoByHash(t,e){try{let r=w.WarpCacheKey.RegistryInfo(this.config.env,t);if(e){let g=this.cache.get(r);if(g)return w.WarpLogger.info(`WarpRegistry (getInfoByHash): RegistryInfo found in cache: ${t}`),g}let a=u.Address.newFromBech32(W(this.config.env)),o=this.getController(),p=o.createQuery({contract:a,function:"getInfoByHash",arguments:[u.BytesValue.fromHex(t)]}),s=await o.runQuery(p),[l]=o.parseQueryResponse(s),f=l?K(l):null,m=f?.brand?await this.fetchBrand(f.brand):null;return e&&e.ttl&&this.cache.set(r,{registryInfo:f,brand:m},e.ttl),{registryInfo:f,brand:m}}catch{return{registryInfo:null,brand:null}}}async getUserWarpRegistryInfos(t){try{let e=t||this.userWallet;if(!e)throw new Error("WarpRegistry: user address not set");let r=u.Address.newFromBech32(W(this.config.env)),a=this.getController(),o=a.createQuery({contract:r,function:"getUserWarps",arguments:[new u.AddressValue(new u.Address(e))]}),p=await a.runQuery(o),[s]=a.parseQueryResponse(p);return s.map(K)}catch{return[]}}async getUserBrands(t){try{let e=t||this.userWallet;if(!e)throw new Error("WarpRegistry: user address not set");let r=u.Address.newFromBech32(W(this.config.env)),a=this.getController(),o=a.createQuery({contract:r,function:"getUserBrands",arguments:[new u.AddressValue(new u.Address(e))]}),p=await a.runQuery(o),[s]=a.parseQueryResponse(p),l=s.map(g=>g.toString("hex")),f={ttl:365*24*60*60};return(await Promise.all(l.map(g=>this.fetchBrand(g,f)))).filter(g=>g!==null)}catch{return[]}}async getChainInfos(t){let e=w.WarpCacheKey.ChainInfos(this.config.env);if(t&&t.ttl){let f=this.cache.get(e);if(f)return w.WarpLogger.info("WarpRegistry (getChainInfos): ChainInfos found in cache"),f}let r=u.Address.newFromBech32(W(this.config.env)),a=this.getController(),o=a.createQuery({contract:r,function:"getChains",arguments:[]}),p=await a.runQuery(o),[s]=a.parseQueryResponse(p),l=s.map(w.toTypedChainInfo);if(t&&t.ttl){for(let f of l)this.cache.set(w.WarpCacheKey.ChainInfo(this.config.env,f.chain),f,t.ttl);this.cache.set(e,l,t.ttl)}return l}async getChainInfo(t,e){try{let r=w.WarpCacheKey.ChainInfo(this.config.env,t),a=e?this.cache.get(r):null;if(a)return w.WarpLogger.info(`WarpRegistry (getChainInfo): ChainInfo found in cache: ${t}`),a;let o=u.Address.newFromBech32(W(this.config.env)),p=this.getController(),s=p.createQuery({contract:o,function:"getChain",arguments:[u.BytesValue.fromUTF8(t)]}),l=await p.runQuery(s),[f]=p.parseQueryResponse(l),m=f?(0,w.toTypedChainInfo)(f):null;return e&&e.ttl&&m&&this.cache.set(r,m,e.ttl),m}catch{return null}}async setChain(t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let e=u.Address.newFromBech32(this.userWallet);return this.getFactory().createTransactionForExecute(e,{contract:u.Address.newFromBech32(W(this.config.env)),function:"setChain",gasLimit:BigInt(1e7),arguments:[R(t.name),R(t.displayName),R(t.chainId),Y(t.blockTime),R(t.addressHrp),R(t.apiUrl),R(t.explorerUrl),R(t.nativeToken)]})}async removeChain(t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let e=u.Address.newFromBech32(this.userWallet);return this.getFactory().createTransactionForExecute(e,{contract:u.Address.newFromBech32(W(this.config.env)),function:"removeChain",gasLimit:BigInt(1e7),arguments:[R(t)]})}async fetchBrand(t,e){let r=w.WarpCacheKey.Brand(this.config.env,t),a=e?this.cache.get(r):null;if(a)return w.WarpLogger.info(`WarpRegistry (fetchBrand): Brand found in cache: ${t}`),a;let o=(0,w.getMainChainInfo)(this.config),s=b.getChainEntrypoint(o,this.config.env).createNetworkProvider();try{let l=await s.getTransaction(t),f=JSON.parse(l.data.toString());return f.meta={hash:l.hash,creator:l.sender.bech32(),createdAt:new Date(l.timestamp*1e3).toISOString()},e&&e.ttl&&this.cache.set(r,f,e.ttl),f}catch{return null}}async loadRegistryConfigs(){let t=u.Address.newFromBech32(W(this.config.env)),e=this.getController(),[r]=await e.query({contract:t,function:"getConfig",arguments:[]}),a=r?nt(r):null;this.registryConfig=a||{unitPrice:BigInt(0),admins:[]}}getFactory(){let t=(0,w.getMainChainInfo)(this.config),e=new u.TransactionsFactoryConfig({chainID:t.chainId}),r=u.AbiRegistry.create(tt);return new u.SmartContractTransactionsFactory({config:e,abi:r})}getController(){let t=(0,w.getMainChainInfo)(this.config),e=b.getChainEntrypoint(t,this.config.env),r=u.AbiRegistry.create(tt);return e.createSmartContractController(r)}isCurrentUserAdmin(){return!!this.userWallet&&this.registryConfig.admins.includes(this.userWallet)}};var Bt=i=>({chain:_.ChainName,prefix:"mvx",builder:new z(i),executor:new b(i),results:new k(i),serializer:new P,registry:new H(i),explorer:t=>new Q(t)});var U=require("@multiversx/sdk-core"),$=require("@vleap/warps"),at=require("buffer");var et=class{constructor(t){this.config=t;this.core=new $.WarpBrandBuilder(t)}createInscriptionTransaction(t){let e=(0,$.getMainChainInfo)(this.config),r=this.config.user?.wallets?.[e.name];if(!r)throw new Error("BrandBuilder: user address not set");let a=new U.TransactionsFactoryConfig({chainID:e.chainId}),o=new U.TransferTransactionsFactory({config:a}),p=U.Address.newFromBech32(r),s=JSON.stringify(t);return o.createTransactionForNativeTokenTransfer(p,{receiver:U.Address.newFromBech32(r),nativeAmount:BigInt(0),data:Uint8Array.from(at.Buffer.from(s))})}async createFromTransaction(t,e=!1){return await this.core.createFromRaw(t.data.toString(),e)}async createFromTransactionHash(t){let e=(0,$.getMainChainInfo)(this.config),a=b.getChainEntrypoint(e,this.config.env).createNetworkProvider();try{let o=await a.getTransaction(t);return this.createFromTransaction(o)}catch(o){return $.WarpLogger.error("BrandBuilder: Error creating from transaction hash",o),null}}};0&&(module.exports={WarpMultiversxAbi,WarpMultiversxBrandBuilder,WarpMultiversxBuilder,WarpMultiversxConstants,WarpMultiversxContractLoader,WarpMultiversxExecutor,WarpMultiversxExplorer,WarpMultiversxRegistry,WarpMultiversxResults,WarpMultiversxSerializer,address_value,biguint_value,boolean_value,codemeta_value,composite_value,esdt_value,getMultiversxAdapter,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
- var E={ChainName:"multiversx",Egld:{Identifier:"EGLD",EsdtIdentifier:"EGLD-000000",DisplayName:"eGold",Decimals:18}};import{Address as Ht,TransactionsFactoryConfig as Ke,TransferTransactionsFactory as Je}from"@multiversx/sdk-core";import{getMainChainInfo as Dt,WarpBuilder as Xe,WarpCache as Ye,WarpCacheKey as Ze,WarpLogger as jt}from"@vleap/warps";import{Address as P,ArgSerializer as ke,DevnetEntrypoint as Ne,MainnetEntrypoint as Ue,SmartContractTransactionsFactory as $e,TestnetEntrypoint as Me,Token as qe,TokenComputer as Le,TokenTransfer as ze,TransactionsFactoryConfig as zt,TransferTransactionsFactory as Qe}from"@multiversx/sdk-core";import{applyResultsToMessages as He,findKnownTokenById as De,getNextInfo as je,getWarpActionByIndex as at,shiftBigintBy as Ge,WarpConstants as Qt}from"@vleap/warps";import{AbiRegistry as z}from"@multiversx/sdk-core";import{getMainChainInfo as ut,WarpCache as te,WarpCacheKey as ee,WarpConstants as pt,WarpLogger as lt}from"@vleap/warps";import{WarpLogger as ct}from"@vleap/warps";var N=class{constructor(t){this.config=t}async getContract(t,e){try{let s=await w.getChainEntrypoint(e,this.config.env).createNetworkProvider().doGetGeneric(`accounts/${t}`);return{address:t,owner:s.ownerAddress,verified:s.isVerified||!1}}catch(r){return ct.error("WarpContractLoader: getContract error",r),null}}async getVerificationInfo(t,e){try{let s=await w.getChainEntrypoint(e,this.config.env).createNetworkProvider().doGetGeneric(`accounts/${t}/verification`);return{codeHash:s.codeHash,abi:s.source.abi}}catch(r){return ct.error("WarpContractLoader: getVerificationInfo error",r),null}}};var V=class{constructor(t){this.config=t;this.contractLoader=new N(this.config),this.cache=new te(this.config.cache?.type)}async createFromRaw(t){return JSON.parse(t)}async createFromTransaction(t){let e=await this.createFromRaw(t.data.toString());return e.meta={hash:t.hash,creator:t.sender.bech32(),createdAt:new Date(t.timestamp*1e3).toISOString()},e}async createFromTransactionHash(t,e){let r=ee.WarpAbi(this.config.env,t);if(e){let a=this.cache.get(r);if(a)return lt.info(`WarpAbiBuilder (createFromTransactionHash): Warp abi found in cache: ${t}`),a}let n=ut(this.config),o=w.getChainEntrypoint(n,this.config.env).createNetworkProvider();try{let a=await o.getTransaction(t),c=await this.createFromTransaction(a);return e&&e.ttl&&c&&this.cache.set(r,c,e.ttl),c}catch(a){return lt.error("WarpAbiBuilder: Error creating from transaction hash",a),null}}async getAbiForAction(t){if(t.abi)return await this.fetchAbi(t);if(!t.address)throw new Error("WarpActionExecutor: Address not found");let e=ut(this.config),r=await this.contractLoader.getVerificationInfo(t.address,e);if(!r)throw new Error("WarpActionExecutor: Verification info not found");return z.create(r.abi)}async fetchAbi(t){if(!t.abi)throw new Error("WarpActionExecutor: ABI not found");if(t.abi.startsWith(pt.IdentifierType.Hash)){let e=t.abi.split(pt.IdentifierParamSeparator)[1],r=await this.createFromTransactionHash(e);if(!r)throw new Error(`WarpActionExecutor: ABI not found for hash: ${t.abi}`);return z.create(r.content)}else{let r=await(await fetch(t.abi)).json();return z.create(r)}}};import{findEventsByFirstTopic as ue,SmartContractTransactionsOutcomeParser as pe,TransactionEventsParser as le}from"@multiversx/sdk-core";import{applyResultsToMessages as fe,evaluateResultsCommon as U,findWarpExecutableAction as Ot,getNextInfo as me,parseResultsOutIndex as kt,WarpCache as de,WarpCacheKey as ge,WarpConstants as Nt}from"@vleap/warps";import{Address as re,AddressType as ft,AddressValue as mt,BigUIntType as Q,BigUIntValue as H,BooleanType as dt,BooleanValue as gt,BytesType as yt,BytesValue as ht,CodeMetadata as ne,CodeMetadataType as wt,CodeMetadataValue as Wt,CompositeType as Tt,CompositeValue as Ct,Field as D,FieldDefinition as j,List as bt,ListType as ae,NothingValue as C,OptionalType as ie,OptionalValue as G,OptionType as se,OptionValue as K,StringType as vt,StringValue as It,Struct as oe,StructType as At,TokenIdentifierType as J,TokenIdentifierValue as X,U16Type as xt,U16Value as Bt,U32Type as Et,U32Value as Vt,U64Type as Y,U64Value as Z,U8Type as St,U8Value as Ft,VariadicType as Rt,VariadicValue as Pt}from"@multiversx/sdk-core";import{WarpConstants as b,WarpSerializer as ce}from"@vleap/warps";var _t=new RegExp(`${b.ArgParamsSeparator}(.*)`),B=class{constructor(){this.coreSerializer=new ce}typedToString(t){if(t.hasClassOrSuperclass(K.ClassName))return t.isSet()?`option:${this.typedToString(t.getTypedValue())}`:"option:null";if(t.hasClassOrSuperclass(G.ClassName))return t.isSet()?`optional:${this.typedToString(t.getTypedValue())}`:"optional:null";if(t.hasClassOrSuperclass(bt.ClassName)){let e=t.getItems(),n=e.map(o=>this.typedToString(o).split(b.ArgParamsSeparator)[0])[0],s=e.map(o=>this.typedToString(o).split(b.ArgParamsSeparator)[1]);return`list:${n}:${s.join(",")}`}if(t.hasClassOrSuperclass(Pt.ClassName)){let e=t.getItems(),n=e.map(o=>this.typedToString(o).split(b.ArgParamsSeparator)[0])[0],s=e.map(o=>this.typedToString(o).split(b.ArgParamsSeparator)[1]);return`variadic:${n}:${s.join(",")}`}if(t.hasClassOrSuperclass(Ct.ClassName)){let e=t.getItems(),r=e.map(a=>this.typedToString(a).split(b.ArgParamsSeparator)[0]),n=e.map(a=>this.typedToString(a).split(b.ArgParamsSeparator)[1]),s=r.join(b.ArgCompositeSeparator),o=n.join(b.ArgCompositeSeparator);return`composite(${s}):${o}`}if(t.hasClassOrSuperclass(H.ClassName)||t.getType().getName()==="BigUint")return`biguint:${BigInt(t.valueOf().toFixed())}`;if(t.hasClassOrSuperclass(Ft.ClassName))return`uint8:${t.valueOf().toNumber()}`;if(t.hasClassOrSuperclass(Bt.ClassName))return`uint16:${t.valueOf().toNumber()}`;if(t.hasClassOrSuperclass(Vt.ClassName))return`uint32:${t.valueOf().toNumber()}`;if(t.hasClassOrSuperclass(Z.ClassName))return`uint64:${BigInt(t.valueOf().toFixed())}`;if(t.hasClassOrSuperclass(It.ClassName))return`string:${t.valueOf()}`;if(t.hasClassOrSuperclass(gt.ClassName))return`bool:${t.valueOf()}`;if(t.hasClassOrSuperclass(mt.ClassName))return`address:${t.valueOf().bech32()}`;if(t.hasClassOrSuperclass(X.ClassName))return`token:${t.valueOf()}`;if(t.hasClassOrSuperclass(ht.ClassName))return`hex:${t.valueOf().toString("hex")}`;if(t.hasClassOrSuperclass(Wt.ClassName))return`codemeta:${t.valueOf().toBuffer().toString("hex")}`;if(t.getType().getName()==="EsdtTokenPayment"){let e=t.getFieldValue("token_identifier").valueOf(),r=t.getFieldValue("token_nonce").valueOf(),n=t.getFieldValue("amount").valueOf();return`esdt:${e}|${r}|${n}`}throw new Error(`WarpArgSerializer (typedToString): Unsupported input type: ${t.getClassName()}`)}typedToNative(t){let e=this.typedToString(t);return this.coreSerializer.stringToNative(e)}nativeToTyped(t,e){let r=this.coreSerializer.nativeToString(t,e);return this.stringToTyped(r)}nativeToType(t){if(t.startsWith("composite")){let e=t.match(/\(([^)]+)\)/)?.[1];return new Tt(...e.split(b.ArgCompositeSeparator).map(r=>this.nativeToType(r)))}if(t==="string")return new vt;if(t==="uint8")return new St;if(t==="uint16")return new xt;if(t==="uint32")return new Et;if(t==="uint64")return new Y;if(t==="biguint")return new Q;if(t==="bool")return new dt;if(t==="address")return new ft;if(t==="token")return new J;if(t==="hex")return new yt;if(t==="codemeta")return new wt;if(t==="esdt"||t==="nft")return new At("EsdtTokenPayment",[new j("token_identifier","",new J),new j("token_nonce","",new Y),new j("amount","",new Q)]);throw new Error(`WarpArgSerializer (nativeToType): Unsupported input type: ${t}`)}stringToTyped(t){let[e,r]=t.split(/:(.*)/,2);if(e==="null"||e===null)return new C;if(e==="option"){let n=this.stringToTyped(r);return n instanceof C?K.newMissingTyped(n.getType()):K.newProvided(n)}if(e==="optional"){let n=this.stringToTyped(r);return n instanceof C?G.newMissing():new G(n.getType(),n)}if(e==="list"){let[n,s]=r.split(_t,2),a=s.split(",").map(c=>this.stringToTyped(`${n}:${c}`));return new bt(this.nativeToType(n),a)}if(e==="variadic"){let[n,s]=r.split(_t,2),a=s.split(",").map(c=>this.stringToTyped(`${n}:${c}`));return new Pt(new Rt(this.nativeToType(n)),a)}if(e.startsWith("composite")){let n=e.match(/\(([^)]+)\)/)?.[1],s=r.split(b.ArgCompositeSeparator),o=n.split(b.ArgCompositeSeparator),a=s.map((u,p)=>this.stringToTyped(`${o[p]}:${u}`)),c=a.map(u=>u.getType());return new Ct(new Tt(...c),a)}if(e==="string")return r?It.fromUTF8(r):new C;if(e==="uint8")return r?new Ft(Number(r)):new C;if(e==="uint16")return r?new Bt(Number(r)):new C;if(e==="uint32")return r?new Vt(Number(r)):new C;if(e==="uint64")return r?new Z(BigInt(r)):new C;if(e==="biguint")return r?new H(BigInt(r)):new C;if(e==="bool")return r?new gt(typeof r=="boolean"?r:r==="true"):new C;if(e==="address")return r?new mt(re.newFromBech32(r)):new C;if(e==="token")return r?new X(r):new C;if(e==="hex")return r?ht.fromHex(r):new C;if(e==="codemeta")return new Wt(ne.newFromBytes(Uint8Array.from(Buffer.from(r,"hex"))));if(e==="esdt"){let n=r.split(b.ArgCompositeSeparator);return new oe(this.nativeToType("esdt"),[new D(new X(n[0]),"token_identifier"),new D(new Z(BigInt(n[1])),"token_nonce"),new D(new H(BigInt(n[2])),"amount")])}throw new Error(`WarpArgSerializer (stringToTyped): Unsupported input type: ${e}`)}typeToString(t){if(t instanceof se)return"option:"+this.typeToString(t.getFirstTypeParameter());if(t instanceof ie)return"optional:"+this.typeToString(t.getFirstTypeParameter());if(t instanceof ae)return"list:"+this.typeToString(t.getFirstTypeParameter());if(t instanceof Rt)return"variadic:"+this.typeToString(t.getFirstTypeParameter());if(t instanceof vt)return"string";if(t instanceof St)return"uint8";if(t instanceof xt)return"uint16";if(t instanceof Et)return"uint32";if(t instanceof Y)return"uint64";if(t instanceof Q)return"biguint";if(t instanceof dt)return"bool";if(t instanceof ft)return"address";if(t instanceof J)return"token";if(t instanceof yt)return"hex";if(t instanceof wt)return"codemeta";if(t instanceof At&&t.getClassName()==="EsdtTokenPayment")return"esdt";throw new Error(`WarpArgSerializer (typeToString): Unsupported input type: ${t.getClassName()}`)}};var S=class{constructor(t){this.config=t;this.abi=new V(t),this.serializer=new B,this.cache=new de(t.cache?.type)}async getTransactionExecutionResults(t,e){let[r,n]=Ot(t),s=this.cache.get(ge.WarpExecutable(this.config.env,t.meta?.hash||"",n))??[],o=await this.extractContractResults(t,e,s),a=me(this.config,t,n,o),c=fe(t,o.results);return{success:e.status.isSuccessful(),warp:t,action:n,user:this.config.user?.wallets?.[E.ChainName]||null,txHash:e.hash,next:a,values:o.values,results:o.results,messages:c}}async extractContractResults(t,e,r){let[n,s]=Ot(t),o=[],a={};if(!t.results||n.type!=="contract")return{values:o,results:a};if(!Object.values(t.results).some(W=>W.includes("out")||W.includes("event"))){for(let[W,m]of Object.entries(t.results))a[W]=m;return{values:o,results:await U(t,a,s,r)}}let u=await this.abi.getAbiForAction(n),p=new le({abi:u}),y=new pe({abi:u}).parseExecute({transactionOnNetwork:e,function:n.func||void 0});for(let[W,m]of Object.entries(t.results)){if(m.startsWith(Nt.Transform.Prefix))continue;if(m.startsWith("input.")){a[W]=m;continue}let v=kt(m);if(v!==null&&v!==s){a[W]=null;continue}let[T,A,I]=m.split(".");if(T==="event"){if(!A||isNaN(Number(I)))continue;let O=Number(I),h=ue(e,A),R=p.parseEvents({events:h})[0],k=Object.values(R)[O]||null;o.push(k),a[W]=k&&k.valueOf()}else if(T==="out"||T.startsWith("out[")){if(!A)continue;let O=Number(A),h=y.values[O-1]||null;I&&(h=h[I]||null),h&&typeof h=="object"&&(h="toFixed"in h?h.toFixed():h.valueOf()),o.push(h),a[W]=h&&h.valueOf()}else a[W]=m}return{values:o,results:await U(t,a,s,r)}}async extractQueryResults(t,e,r,n){let s=e.map(u=>this.serializer.typedToString(u)),o=e.map(u=>this.serializer.typedToNative(u)[1]),a={};if(!t.results)return{values:s,results:a};let c=u=>{let p=u.split(".").slice(1).map(y=>parseInt(y)-1);if(p.length===0)return;let f=o[p[0]];for(let y=1;y<p.length;y++){if(f==null)return;f=f[p[y]]}return f};for(let[u,p]of Object.entries(t.results)){if(p.startsWith(Nt.Transform.Prefix))continue;let f=kt(p);if(f!==null&&f!==r){a[u]=null;continue}p.startsWith("out.")||p==="out"||p.startsWith("out[")?a[u]=c(p)||null:a[u]=p}return{values:s,results:await U(t,a,r,n)}}async resolveWarpResultsRecursively(t){let e=t.warp,r=t.entryActionIndex,n=t.executor,s=t.inputs,o=t.meta,a=new Map,c=new Set,u=this;async function p(m,v=[]){if(a.has(m))return a.get(m);if(c.has(m))throw new Error(`Circular dependency detected at action ${m}`);c.add(m);let T=e.actions[m-1];if(!T)throw new Error(`Action ${m} not found`);let A;if(T.type==="query")A=await n.executeQuery(e,m,v);else if(T.type==="collect")A=await n.executeCollect(e,m,v,o);else throw new Error(`Unsupported or interactive action type: ${T.type}`);if(a.set(m,A),e.results)for(let I of Object.values(e.results)){let h=String(I).match(/^out\[(\d+)\]/);if(h){let R=parseInt(h[1],10);R!==m&&!a.has(R)&&await p(R)}}return c.delete(m),A}await p(r,s);let f={};for(let m of a.values())for(let[v,T]of Object.entries(m.results))T!==null?f[v]=T:v in f||(f[v]=null);let y=await U(e,f,r,s);return{...a.get(r),action:r,results:y}}};import{Address as ye,AddressValue as he,BigUIntType as we,BigUIntValue as Ut,BooleanValue as We,BytesValue as Te,CodeMetadata as Ce,CodeMetadataValue as be,CompositeType as ve,CompositeValue as Ie,Field as tt,FieldDefinition as et,List as Ae,NothingValue as xe,OptionalValue as rt,OptionValue as nt,StringValue as Be,Struct as Ee,StructType as Ve,TokenIdentifierType as Se,TokenIdentifierValue as $t,U16Value as Fe,U32Value as Re,U64Type as Pe,U64Value as Mt,U8Value as _e,VariadicValue as Oe}from"@multiversx/sdk-core";var an=(i,t)=>i?nt.newProvided(i):t?nt.newMissingTyped(t):nt.newMissing(),sn=(i,t)=>i?new rt(i.getType(),i):t?new rt(t):rt.newMissing(),on=i=>{if(i.length===0)throw new Error("Cannot create a list from an empty array");let t=i[0].getType();return new Ae(t,i)},cn=i=>Oe.fromItems(...i),un=i=>{let t=i.map(e=>e.getType());return new Ie(new ve(...t),i)},x=i=>Be.fromUTF8(i),pn=i=>new _e(i),ln=i=>new Fe(i),qt=i=>new Re(i),fn=i=>new Mt(i),mn=i=>new Ut(BigInt(i)),dn=i=>new We(i),gn=i=>new he(ye.newFromBech32(i)),yn=i=>new $t(i),hn=i=>Te.fromHex(i),Lt=i=>new Ee(new Ve("EsdtTokenPayment",[new et("token_identifier","",new Se),new et("token_nonce","",new Pe),new et("amount","",new we)]),[new tt(new $t(i.token.identifier),"token_identifier"),new tt(new Mt(BigInt(i.token.nonce)),"token_nonce"),new tt(new Ut(BigInt(i.amount)),"amount")]),wn=i=>new be(Ce.newFromBytes(Uint8Array.from(Buffer.from(i,"hex")))),Wn=()=>new xe;var w=class i{constructor(t){this.config=t;this.serializer=new B,this.abi=new V(this.config),this.results=new S(this.config)}async createTransaction(t){let e=at(t.warp,t.action),r=null;if(e.type==="transfer")r=await this.createTransferTransaction(t);else if(e.type==="contract")r=await this.createContractCallTransaction(t);else{if(e.type==="query")throw new Error("WarpMultiversxExecutor: Invalid action type for createTransactionForExecute; Use executeQuery instead");if(e.type==="collect")throw new Error("WarpMultiversxExecutor: Invalid action type for createTransactionForExecute; Use executeCollect instead")}if(!r)throw new Error(`WarpMultiversxExecutor: Invalid action type (${e.type})`);return r}async createTransferTransaction(t){let e=this.config.user?.wallets?.[t.chain.name];if(!e)throw new Error("WarpMultiversxExecutor: createTransfer - user address not set");let r=P.newFromBech32(e),n=new zt({chainID:t.chain.chainId}),s=t.data?Buffer.from(this.serializer.stringToTyped(t.data).valueOf()):null;return new Qe({config:n}).createTransactionForTransfer(r,{receiver:P.newFromBech32(t.destination),nativeAmount:t.value,data:s?new Uint8Array(s):void 0})}async createContractCallTransaction(t){let e=this.config.user?.wallets?.[t.chain.name];if(!e)throw new Error("WarpMultiversxExecutor: createContractCall - user address not set");let r=at(t.warp,t.action),n=P.newFromBech32(e),s=t.args.map(a=>this.serializer.stringToTyped(a)),o=new zt({chainID:t.chain.chainId});return new $e({config:o}).createTransactionForExecute(n,{contract:P.newFromBech32(t.destination),function:"func"in r&&r.func||"",gasLimit:"gasLimit"in r?BigInt(r.gasLimit||0):0n,arguments:s,nativeTransferAmount:t.value})}async executeQuery(t){let e=at(t.warp,t.action);if(e.type!=="query")throw new Error(`WarpMultiversxExecutor: Invalid action type for executeQuery: ${e.type}`);let r=await this.abi.getAbiForAction(e),n=t.args.map(I=>this.serializer.stringToTyped(I)),s=i.getChainEntrypoint(t.chain,this.config.env),o=P.newFromBech32(t.destination),a=s.createSmartContractController(r),c=a.createQuery({contract:o,function:e.func||"",arguments:n}),u=await a.runQuery(c),p=u.returnCode==="ok",f=new ke,y=r.getEndpoint(u.function||e.func||""),W=(u.returnDataParts||[]).map(I=>Buffer.from(I)),m=f.buffersToValues(W,y.output),{values:v,results:T}=await this.results.extractQueryResults(t.warp,m,t.action,t.resolvedInputs),A=je(this.config,t.warp,t.action,T);return{success:p,warp:t.warp,action:t.action,user:this.config.user?.wallets?.[t.chain.name]||null,txHash:null,next:A,values:v,results:T,messages:He(t.warp,T)}}async preprocessInput(t,e,r,n){if(r==="esdt"){let[s,o,a,c]=n.split(Qt.ArgCompositeSeparator);if(c)return e;let u=new qe({identifier:s,nonce:BigInt(o)});if(!new Le().isFungible(u))return e;let y=De(s)?.decimals;if(y||(y=(await(await fetch(`${t.apiUrl}/tokens/${s}`)).json()).decimals),!y)throw new Error(`WarpActionExecutor: Decimals not found for token ${s}`);let W=Lt(new ze({token:u,amount:Ge(a,y)}));return this.serializer.typedToString(W)+Qt.ArgCompositeSeparator+y}return e}static getChainEntrypoint(t,e){let r="warp-sdk",n="api";return e==="devnet"?new Ne(t.apiUrl,n,r):e==="testnet"?new Me(t.apiUrl,n,r):new Ue(t.apiUrl,n,r)}};var $=class{constructor(t){this.config=t;this.cache=new Ye(t.cache?.type),this.core=new Xe(t)}createInscriptionTransaction(t){let e=Dt(this.config),r=this.config.user?.wallets?.[e.name];if(!r)throw new Error("WarpBuilder: user address not set");let n=new Ke({chainID:e.chainId}),s=new Je({config:n}),o=Ht.newFromBech32(r),a=JSON.stringify(t),c=s.createTransactionForTransfer(o,{receiver:Ht.newFromBech32(r),nativeAmount:BigInt(0),data:Uint8Array.from(Buffer.from(a))});return c.gasLimit=c.gasLimit+BigInt(2e6),c}async createFromTransaction(t,e=!1){let r=await this.core.createFromRaw(t.data.toString(),e);return r.meta={hash:t.hash,creator:t.sender.toBech32(),createdAt:new Date(t.timestamp*1e3).toISOString()},r}async createFromTransactionHash(t,e){let r=Ze.Warp(this.config.env,t);if(e){let a=this.cache.get(r);if(a)return jt.info(`WarpBuilder (createFromTransactionHash): Warp found in cache: ${t}`),a}let n=Dt(this.config),o=w.getChainEntrypoint(n,this.config.env).createNetworkProvider();try{let a=await o.getTransaction(t),c=await this.createFromTransaction(a);return e&&e.ttl&&c&&this.cache.set(r,c,e.ttl),c}catch(a){return jt.error("WarpBuilder: Error creating from transaction hash",a),null}}};var M=class{constructor(t){this.chainInfo=t}getAccountUrl(t){return`${this.chainInfo.explorerUrl}/accounts/${t}`}getTransactionUrl(t){return`${this.chainInfo.explorerUrl}/transactions/${t}`}};import{AbiRegistry as Kt,Address as l,AddressValue as st,BytesValue as d,SmartContractTransactionsFactory as er,TransactionsFactoryConfig as rr}from"@multiversx/sdk-core";import{getMainChainInfo as ot,toTypedChainInfo as Jt,WarpCache as nr,WarpCacheKey as F,WarpLogger as _}from"@vleap/warps";var it={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 g=i=>i==="devnet"?"erd1qqqqqqqqqqqqqpgqje2f99vr6r7sk54thg03c9suzcvwr4nfl3tsfkdl36":i==="testnet"?"####":"erd1qqqqqqqqqqqqqpgq3mrpj3u6q7tejv6d7eqhnyd27n9v5c5tl3ts08mffe";var q=i=>({hash:i.hash.toString("hex"),alias:i.alias?.toString()||null,trust:i.trust.toString(),owner:i.owner.toString(),createdAt:i.created_at.toNumber(),upgradedAt:i.upgraded_at?.toNumber(),brand:i.brand?.toString("hex")||null,upgrade:i.upgrade?.toString("hex")||null}),Gt=i=>({unitPrice:BigInt(i.unit_price.toString()),admins:i.admins.map(t=>t.toBech32())});var L=class{constructor(t){this.config=t;this.cache=new nr(t.cache?.type),this.registryConfig={unitPrice:BigInt(0),admins:[]},this.userWallet=this.config.user?.wallets?.[E.ChainName]||null}async init(){await this.loadRegistryConfigs()}createWarpRegisterTransaction(t,e,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=l.newFromBech32(this.userWallet),s=()=>this.isCurrentUserAdmin()?BigInt(0):e&&r?this.registryConfig.unitPrice*BigInt(3):e?this.registryConfig.unitPrice*BigInt(2):this.registryConfig.unitPrice,o=()=>e&&r?[d.fromHex(t),d.fromUTF8(e),d.fromHex(r)]:e?[d.fromHex(t),d.fromUTF8(e)]:[d.fromHex(t)];return this.getFactory().createTransactionForExecute(n,{contract:l.newFromBech32(g(this.config.env)),function:"registerWarp",gasLimit:BigInt(1e7),nativeTransferAmount:s(),arguments:o()})}createWarpUnregisterTransaction(t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let e=l.newFromBech32(this.userWallet);return this.getFactory().createTransactionForExecute(e,{contract:l.newFromBech32(g(this.config.env)),function:"unregisterWarp",gasLimit:BigInt(1e7),arguments:[d.fromHex(t)]})}createWarpUpgradeTransaction(t,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 r=l.newFromBech32(this.userWallet);return this.getFactory().createTransactionForExecute(r,{contract:l.newFromBech32(g(this.config.env)),function:"upgradeWarp",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[d.fromUTF8(t),d.fromHex(e)]})}createWarpAliasSetTransaction(t,e){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let r=l.newFromBech32(this.userWallet);return this.getFactory().createTransactionForExecute(r,{contract:l.newFromBech32(g(this.config.env)),function:"setWarpAlias",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[d.fromHex(t),d.fromUTF8(e)]})}createWarpVerifyTransaction(t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let e=l.newFromBech32(this.userWallet);return this.getFactory().createTransactionForExecute(e,{contract:l.newFromBech32(g(this.config.env)),function:"verifyWarp",gasLimit:BigInt(1e7),arguments:[d.fromHex(t)]})}createWarpTransferOwnershipTransaction(t,e){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let r=l.newFromBech32(this.userWallet);return this.getFactory().createTransactionForExecute(r,{contract:l.newFromBech32(g(this.config.env)),function:"transferOwnership",gasLimit:BigInt(1e7),arguments:[d.fromHex(t),new st(new l(e))]})}createBrandRegisterTransaction(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 e=l.newFromBech32(this.userWallet);return this.getFactory().createTransactionForExecute(e,{contract:l.newFromBech32(g(this.config.env)),function:"registerBrand",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[d.fromHex(t)]})}createWarpBrandingTransaction(t,e){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let r=l.newFromBech32(this.userWallet);return this.getFactory().createTransactionForExecute(r,{contract:l.newFromBech32(g(this.config.env)),function:"brandWarp",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[d.fromHex(t),d.fromHex(e)]})}async getInfoByAlias(t,e){try{let r=F.RegistryInfo(this.config.env,t),n=e?this.cache.get(r):null;if(n)return _.info(`WarpRegistry (getInfoByAlias): RegistryInfo found in cache: ${t}`),n;let s=l.newFromBech32(g(this.config.env)),o=this.getController(),a=o.createQuery({contract:s,function:"getInfoByAlias",arguments:[d.fromUTF8(t)]}),c=await o.runQuery(a),[u]=o.parseQueryResponse(c),p=u?q(u):null,f=p?.brand?await this.fetchBrand(p.brand):null;return e&&e.ttl&&this.cache.set(r,{registryInfo:p,brand:f},e.ttl),{registryInfo:p,brand:f}}catch{return{registryInfo:null,brand:null}}}async getInfoByHash(t,e){try{let r=F.RegistryInfo(this.config.env,t);if(e){let f=this.cache.get(r);if(f)return _.info(`WarpRegistry (getInfoByHash): RegistryInfo found in cache: ${t}`),f}let n=l.newFromBech32(g(this.config.env)),s=this.getController(),o=s.createQuery({contract:n,function:"getInfoByHash",arguments:[d.fromHex(t)]}),a=await s.runQuery(o),[c]=s.parseQueryResponse(a),u=c?q(c):null,p=u?.brand?await this.fetchBrand(u.brand):null;return e&&e.ttl&&this.cache.set(r,{registryInfo:u,brand:p},e.ttl),{registryInfo:u,brand:p}}catch{return{registryInfo:null,brand:null}}}async getUserWarpRegistryInfos(t){try{let e=t||this.userWallet;if(!e)throw new Error("WarpRegistry: user address not set");let r=l.newFromBech32(g(this.config.env)),n=this.getController(),s=n.createQuery({contract:r,function:"getUserWarps",arguments:[new st(new l(e))]}),o=await n.runQuery(s),[a]=n.parseQueryResponse(o);return a.map(q)}catch{return[]}}async getUserBrands(t){try{let e=t||this.userWallet;if(!e)throw new Error("WarpRegistry: user address not set");let r=l.newFromBech32(g(this.config.env)),n=this.getController(),s=n.createQuery({contract:r,function:"getUserBrands",arguments:[new st(new l(e))]}),o=await n.runQuery(s),[a]=n.parseQueryResponse(o),c=a.map(f=>f.toString("hex")),u={ttl:365*24*60*60};return(await Promise.all(c.map(f=>this.fetchBrand(f,u)))).filter(f=>f!==null)}catch{return[]}}async getChainInfos(t){let e=F.ChainInfos(this.config.env);if(t&&t.ttl){let u=this.cache.get(e);if(u)return _.info("WarpRegistry (getChainInfos): ChainInfos found in cache"),u}let r=l.newFromBech32(g(this.config.env)),n=this.getController(),s=n.createQuery({contract:r,function:"getChains",arguments:[]}),o=await n.runQuery(s),[a]=n.parseQueryResponse(o),c=a.map(Jt);if(t&&t.ttl){for(let u of c)this.cache.set(F.ChainInfo(this.config.env,u.chain),u,t.ttl);this.cache.set(e,c,t.ttl)}return c}async getChainInfo(t,e){try{let r=F.ChainInfo(this.config.env,t),n=e?this.cache.get(r):null;if(n)return _.info(`WarpRegistry (getChainInfo): ChainInfo found in cache: ${t}`),n;let s=l.newFromBech32(g(this.config.env)),o=this.getController(),a=o.createQuery({contract:s,function:"getChain",arguments:[d.fromUTF8(t)]}),c=await o.runQuery(a),[u]=o.parseQueryResponse(c),p=u?Jt(u):null;return e&&e.ttl&&p&&this.cache.set(r,p,e.ttl),p}catch{return null}}async setChain(t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let e=l.newFromBech32(this.userWallet);return this.getFactory().createTransactionForExecute(e,{contract:l.newFromBech32(g(this.config.env)),function:"setChain",gasLimit:BigInt(1e7),arguments:[x(t.name),x(t.displayName),x(t.chainId),qt(t.blockTime),x(t.addressHrp),x(t.apiUrl),x(t.explorerUrl),x(t.nativeToken)]})}async removeChain(t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let e=l.newFromBech32(this.userWallet);return this.getFactory().createTransactionForExecute(e,{contract:l.newFromBech32(g(this.config.env)),function:"removeChain",gasLimit:BigInt(1e7),arguments:[x(t)]})}async fetchBrand(t,e){let r=F.Brand(this.config.env,t),n=e?this.cache.get(r):null;if(n)return _.info(`WarpRegistry (fetchBrand): Brand found in cache: ${t}`),n;let s=ot(this.config),a=w.getChainEntrypoint(s,this.config.env).createNetworkProvider();try{let c=await a.getTransaction(t),u=JSON.parse(c.data.toString());return u.meta={hash:c.hash,creator:c.sender.bech32(),createdAt:new Date(c.timestamp*1e3).toISOString()},e&&e.ttl&&this.cache.set(r,u,e.ttl),u}catch{return null}}async loadRegistryConfigs(){let t=l.newFromBech32(g(this.config.env)),e=this.getController(),[r]=await e.query({contract:t,function:"getConfig",arguments:[]}),n=r?Gt(r):null;this.registryConfig=n||{unitPrice:BigInt(0),admins:[]}}getFactory(){let t=ot(this.config),e=new rr({chainID:t.chainId}),r=Kt.create(it);return new er({config:e,abi:r})}getController(){let t=ot(this.config),e=w.getChainEntrypoint(t,this.config.env),r=Kt.create(it);return e.createSmartContractController(r)}isCurrentUserAdmin(){return!!this.userWallet&&this.registryConfig.admins.includes(this.userWallet)}};var Ia=i=>({chain:E.ChainName,prefix:"mvx",builder:new $(i),executor:new w(i),results:new S(i),serializer:new B,registry:new L(i),explorer:t=>new M(t)});import{Address as Xt,TransactionsFactoryConfig as ar,TransferTransactionsFactory as ir}from"@multiversx/sdk-core";import{getMainChainInfo as Yt,WarpBrandBuilder as sr,WarpLogger as or}from"@vleap/warps";import{Buffer as cr}from"buffer";var Zt=class{constructor(t){this.config=t;this.core=new sr(t)}createInscriptionTransaction(t){let e=Yt(this.config),r=this.config.user?.wallets?.[e.name];if(!r)throw new Error("BrandBuilder: user address not set");let n=new ar({chainID:e.chainId}),s=new ir({config:n}),o=Xt.newFromBech32(r),a=JSON.stringify(t);return s.createTransactionForNativeTokenTransfer(o,{receiver:Xt.newFromBech32(r),nativeAmount:BigInt(0),data:Uint8Array.from(cr.from(a))})}async createFromTransaction(t,e=!1){return await this.core.createFromRaw(t.data.toString(),e)}async createFromTransactionHash(t){let e=Yt(this.config),n=w.getChainEntrypoint(e,this.config.env).createNetworkProvider();try{let s=await n.getTransaction(t);return this.createFromTransaction(s)}catch(s){return or.error("BrandBuilder: Error creating from transaction hash",s),null}}};export{V as WarpMultiversxAbi,Zt as WarpMultiversxBrandBuilder,$ as WarpMultiversxBuilder,E as WarpMultiversxConstants,N as WarpMultiversxContractLoader,w as WarpMultiversxExecutor,M as WarpMultiversxExplorer,L as WarpMultiversxRegistry,S as WarpMultiversxResults,B as WarpMultiversxSerializer,gn as address_value,mn as biguint_value,dn as boolean_value,wn as codemeta_value,un as composite_value,Lt as esdt_value,Ia as getMultiversxAdapter,hn as hex_value,on as list_value,Wn as nothing_value,an as option_value,sn as optional_value,x as string_value,yn as token_value,ln as u16_value,qt as u32_value,fn as u64_value,pn as u8_value,cn as variadic_value};
1
+ var E={ChainName:"multiversx",Egld:{Identifier:"EGLD",EsdtIdentifier:"EGLD-000000",DisplayName:"eGold",Decimals:18}};import{Address as Ht,TransactionsFactoryConfig as Ke,TransferTransactionsFactory as Je}from"@multiversx/sdk-core";import{getMainChainInfo as Dt,WarpBuilder as Xe,WarpCache as Ye,WarpCacheKey as Ze,WarpLogger as jt}from"@vleap/warps";import{Address as P,ArgSerializer as ke,DevnetEntrypoint as Ne,MainnetEntrypoint as Ue,SmartContractTransactionsFactory as $e,TestnetEntrypoint as Me,Token as qe,TokenComputer as Le,TokenTransfer as ze,TransactionsFactoryConfig as zt,TransferTransactionsFactory as Qe}from"@multiversx/sdk-core";import{applyResultsToMessages as He,findKnownTokenById as De,getNextInfo as je,getWarpActionByIndex as at,shiftBigintBy as Ge,WarpConstants as Qt}from"@vleap/warps";import{AbiRegistry as z}from"@multiversx/sdk-core";import{getMainChainInfo as ut,WarpCache as te,WarpCacheKey as ee,WarpConstants as pt,WarpLogger as lt}from"@vleap/warps";import{WarpLogger as ct}from"@vleap/warps";var N=class{constructor(t){this.config=t}async getContract(t,e){try{let s=await w.getChainEntrypoint(e,this.config.env).createNetworkProvider().doGetGeneric(`accounts/${t}`);return{address:t,owner:s.ownerAddress,verified:s.isVerified||!1}}catch(r){return ct.error("WarpContractLoader: getContract error",r),null}}async getVerificationInfo(t,e){try{let s=await w.getChainEntrypoint(e,this.config.env).createNetworkProvider().doGetGeneric(`accounts/${t}/verification`);return{codeHash:s.codeHash,abi:s.source.abi}}catch(r){return ct.error("WarpContractLoader: getVerificationInfo error",r),null}}};var V=class{constructor(t){this.config=t;this.contractLoader=new N(this.config),this.cache=new te(this.config.cache?.type)}async createFromRaw(t){return JSON.parse(t)}async createFromTransaction(t){let e=await this.createFromRaw(t.data.toString());return e.meta={hash:t.hash,creator:t.sender.bech32(),createdAt:new Date(t.timestamp*1e3).toISOString()},e}async createFromTransactionHash(t,e){let r=ee.WarpAbi(this.config.env,t);if(e){let a=this.cache.get(r);if(a)return lt.info(`WarpAbiBuilder (createFromTransactionHash): Warp abi found in cache: ${t}`),a}let n=ut(this.config),o=w.getChainEntrypoint(n,this.config.env).createNetworkProvider();try{let a=await o.getTransaction(t),c=await this.createFromTransaction(a);return e&&e.ttl&&c&&this.cache.set(r,c,e.ttl),c}catch(a){return lt.error("WarpAbiBuilder: Error creating from transaction hash",a),null}}async getAbiForAction(t){if(t.abi)return await this.fetchAbi(t);if(!t.address)throw new Error("WarpActionExecutor: Address not found");let e=ut(this.config),r=await this.contractLoader.getVerificationInfo(t.address,e);if(!r)throw new Error("WarpActionExecutor: Verification info not found");return z.create(r.abi)}async fetchAbi(t){if(!t.abi)throw new Error("WarpActionExecutor: ABI not found");if(t.abi.startsWith(pt.IdentifierType.Hash)){let e=t.abi.split(pt.IdentifierParamSeparator)[1],r=await this.createFromTransactionHash(e);if(!r)throw new Error(`WarpActionExecutor: ABI not found for hash: ${t.abi}`);return z.create(r.content)}else{let r=await(await fetch(t.abi)).json();return z.create(r)}}};import{findEventsByFirstTopic as ue,SmartContractTransactionsOutcomeParser as pe,TransactionEventsParser as le}from"@multiversx/sdk-core";import{applyResultsToMessages as fe,evaluateResultsCommon as U,findWarpExecutableAction as Ot,getNextInfo as me,parseResultsOutIndex as kt,WarpCache as ge,WarpCacheKey as de,WarpConstants as Nt}from"@vleap/warps";import{Address as re,AddressType as ft,AddressValue as mt,BigUIntType as Q,BigUIntValue as H,BooleanType as gt,BooleanValue as dt,BytesType as yt,BytesValue as ht,CodeMetadata as ne,CodeMetadataType as wt,CodeMetadataValue as Wt,CompositeType as Tt,CompositeValue as Ct,Field as D,FieldDefinition as j,List as bt,ListType as ae,NothingValue as C,OptionalType as ie,OptionalValue as G,OptionType as se,OptionValue as K,StringType as vt,StringValue as It,Struct as oe,StructType as At,TokenIdentifierType as J,TokenIdentifierValue as X,U16Type as xt,U16Value as Bt,U32Type as Et,U32Value as Vt,U64Type as Y,U64Value as Z,U8Type as St,U8Value as Ft,VariadicType as Rt,VariadicValue as Pt}from"@multiversx/sdk-core";import{WarpConstants as b,WarpSerializer as ce}from"@vleap/warps";var _t=new RegExp(`${b.ArgParamsSeparator}(.*)`),B=class{constructor(){this.coreSerializer=new ce}typedToString(t){if(t.hasClassOrSuperclass(K.ClassName))return t.isSet()?`option:${this.typedToString(t.getTypedValue())}`:"option:null";if(t.hasClassOrSuperclass(G.ClassName))return t.isSet()?`optional:${this.typedToString(t.getTypedValue())}`:"optional:null";if(t.hasClassOrSuperclass(bt.ClassName)){let e=t.getItems(),n=e.map(o=>this.typedToString(o).split(b.ArgParamsSeparator)[0])[0],s=e.map(o=>this.typedToString(o).split(b.ArgParamsSeparator)[1]);return`list:${n}:${s.join(",")}`}if(t.hasClassOrSuperclass(Pt.ClassName)){let e=t.getItems(),n=e.map(o=>this.typedToString(o).split(b.ArgParamsSeparator)[0])[0],s=e.map(o=>this.typedToString(o).split(b.ArgParamsSeparator)[1]);return`variadic:${n}:${s.join(",")}`}if(t.hasClassOrSuperclass(Ct.ClassName)){let e=t.getItems(),r=e.map(a=>this.typedToString(a).split(b.ArgParamsSeparator)[0]),n=e.map(a=>this.typedToString(a).split(b.ArgParamsSeparator)[1]),s=r.join(b.ArgCompositeSeparator),o=n.join(b.ArgCompositeSeparator);return`composite(${s}):${o}`}if(t.hasClassOrSuperclass(H.ClassName)||t.getType().getName()==="BigUint")return`biguint:${BigInt(t.valueOf().toFixed())}`;if(t.hasClassOrSuperclass(Ft.ClassName))return`uint8:${t.valueOf().toNumber()}`;if(t.hasClassOrSuperclass(Bt.ClassName))return`uint16:${t.valueOf().toNumber()}`;if(t.hasClassOrSuperclass(Vt.ClassName))return`uint32:${t.valueOf().toNumber()}`;if(t.hasClassOrSuperclass(Z.ClassName))return`uint64:${BigInt(t.valueOf().toFixed())}`;if(t.hasClassOrSuperclass(It.ClassName))return`string:${t.valueOf()}`;if(t.hasClassOrSuperclass(dt.ClassName))return`bool:${t.valueOf()}`;if(t.hasClassOrSuperclass(mt.ClassName))return`address:${t.valueOf().bech32()}`;if(t.hasClassOrSuperclass(X.ClassName))return`token:${t.valueOf()}`;if(t.hasClassOrSuperclass(ht.ClassName))return`hex:${t.valueOf().toString("hex")}`;if(t.hasClassOrSuperclass(Wt.ClassName))return`codemeta:${t.valueOf().toBuffer().toString("hex")}`;if(t.getType().getName()==="EsdtTokenPayment"){let e=t.getFieldValue("token_identifier").valueOf(),r=t.getFieldValue("token_nonce").valueOf(),n=t.getFieldValue("amount").valueOf();return`esdt:${e}|${r}|${n}`}throw new Error(`WarpArgSerializer (typedToString): Unsupported input type: ${t.getClassName()}`)}typedToNative(t){let e=this.typedToString(t);return this.coreSerializer.stringToNative(e)}nativeToTyped(t,e){let r=this.coreSerializer.nativeToString(t,e);return this.stringToTyped(r)}nativeToType(t){if(t.startsWith("composite")){let e=t.match(/\(([^)]+)\)/)?.[1];return new Tt(...e.split(b.ArgCompositeSeparator).map(r=>this.nativeToType(r)))}if(t==="string")return new vt;if(t==="uint8")return new St;if(t==="uint16")return new xt;if(t==="uint32")return new Et;if(t==="uint64")return new Y;if(t==="biguint")return new Q;if(t==="bool")return new gt;if(t==="address")return new ft;if(t==="token")return new J;if(t==="hex")return new yt;if(t==="codemeta")return new wt;if(t==="esdt"||t==="nft")return new At("EsdtTokenPayment",[new j("token_identifier","",new J),new j("token_nonce","",new Y),new j("amount","",new Q)]);throw new Error(`WarpArgSerializer (nativeToType): Unsupported input type: ${t}`)}stringToTyped(t){let[e,r]=t.split(/:(.*)/,2);if(e==="null"||e===null)return new C;if(e==="option"){let n=this.stringToTyped(r);return n instanceof C?K.newMissingTyped(n.getType()):K.newProvided(n)}if(e==="optional"){let n=this.stringToTyped(r);return n instanceof C?G.newMissing():new G(n.getType(),n)}if(e==="list"){let[n,s]=r.split(_t,2),a=s.split(",").map(c=>this.stringToTyped(`${n}:${c}`));return new bt(this.nativeToType(n),a)}if(e==="variadic"){let[n,s]=r.split(_t,2),a=s.split(",").map(c=>this.stringToTyped(`${n}:${c}`));return new Pt(new Rt(this.nativeToType(n)),a)}if(e.startsWith("composite")){let n=e.match(/\(([^)]+)\)/)?.[1],s=r.split(b.ArgCompositeSeparator),o=n.split(b.ArgCompositeSeparator),a=s.map((u,p)=>this.stringToTyped(`${o[p]}:${u}`)),c=a.map(u=>u.getType());return new Ct(new Tt(...c),a)}if(e==="string")return r?It.fromUTF8(r):new C;if(e==="uint8")return r?new Ft(Number(r)):new C;if(e==="uint16")return r?new Bt(Number(r)):new C;if(e==="uint32")return r?new Vt(Number(r)):new C;if(e==="uint64")return r?new Z(BigInt(r)):new C;if(e==="biguint")return r?new H(BigInt(r)):new C;if(e==="bool")return r?new dt(typeof r=="boolean"?r:r==="true"):new C;if(e==="address")return r?new mt(re.newFromBech32(r)):new C;if(e==="token")return r?new X(r):new C;if(e==="hex")return r?ht.fromHex(r):new C;if(e==="codemeta")return new Wt(ne.newFromBytes(Uint8Array.from(Buffer.from(r,"hex"))));if(e==="esdt"){let n=r.split(b.ArgCompositeSeparator);return new oe(this.nativeToType("esdt"),[new D(new X(n[0]),"token_identifier"),new D(new Z(BigInt(n[1])),"token_nonce"),new D(new H(BigInt(n[2])),"amount")])}throw new Error(`WarpArgSerializer (stringToTyped): Unsupported input type: ${e}`)}typeToString(t){if(t instanceof se)return"option:"+this.typeToString(t.getFirstTypeParameter());if(t instanceof ie)return"optional:"+this.typeToString(t.getFirstTypeParameter());if(t instanceof ae)return"list:"+this.typeToString(t.getFirstTypeParameter());if(t instanceof Rt)return"variadic:"+this.typeToString(t.getFirstTypeParameter());if(t instanceof vt)return"string";if(t instanceof St)return"uint8";if(t instanceof xt)return"uint16";if(t instanceof Et)return"uint32";if(t instanceof Y)return"uint64";if(t instanceof Q)return"biguint";if(t instanceof gt)return"bool";if(t instanceof ft)return"address";if(t instanceof J)return"token";if(t instanceof yt)return"hex";if(t instanceof wt)return"codemeta";if(t instanceof At&&t.getClassName()==="EsdtTokenPayment")return"esdt";throw new Error(`WarpArgSerializer (typeToString): Unsupported input type: ${t.getClassName()}`)}};var S=class{constructor(t){this.config=t;this.abi=new V(t),this.serializer=new B,this.cache=new ge(t.cache?.type)}async getTransactionExecutionResults(t,e){let[r,n]=Ot(t),s=this.cache.get(de.WarpExecutable(this.config.env,t.meta?.hash||"",n))??[],o=await this.extractContractResults(t,e,s),a=me(this.config,t,n,o),c=fe(t,o.results);return{success:e.status.isSuccessful(),warp:t,action:n,user:this.config.user?.wallets?.[E.ChainName]||null,txHash:e.hash,next:a,values:o.values,results:o.results,messages:c}}async extractContractResults(t,e,r){let[n,s]=Ot(t),o=[],a={};if(!t.results||n.type!=="contract")return{values:o,results:a};if(!Object.values(t.results).some(W=>W.includes("out")||W.includes("event"))){for(let[W,m]of Object.entries(t.results))a[W]=m;return{values:o,results:await U(t,a,s,r)}}let u=await this.abi.getAbiForAction(n),p=new le({abi:u}),y=new pe({abi:u}).parseExecute({transactionOnNetwork:e,function:n.func||void 0});for(let[W,m]of Object.entries(t.results)){if(m.startsWith(Nt.Transform.Prefix))continue;if(m.startsWith("input.")){a[W]=m;continue}let v=kt(m);if(v!==null&&v!==s){a[W]=null;continue}let[T,A,I]=m.split(".");if(T==="event"){if(!A||isNaN(Number(I)))continue;let O=Number(I),h=ue(e,A),R=p.parseEvents({events:h})[0],k=Object.values(R)[O]||null;o.push(k),a[W]=k&&k.valueOf()}else if(T==="out"||T.startsWith("out[")){if(!A)continue;let O=Number(A),h=y.values[O-1]||null;I&&(h=h[I]||null),h&&typeof h=="object"&&(h="toFixed"in h?h.toFixed():h.valueOf()),o.push(h),a[W]=h&&h.valueOf()}else a[W]=m}return{values:o,results:await U(t,a,s,r)}}async extractQueryResults(t,e,r,n){let s=e.map(u=>this.serializer.typedToString(u)),o=e.map(u=>this.serializer.typedToNative(u)[1]),a={};if(!t.results)return{values:s,results:a};let c=u=>{let p=u.split(".").slice(1).map(y=>parseInt(y)-1);if(p.length===0)return;let f=o[p[0]];for(let y=1;y<p.length;y++){if(f==null)return;f=f[p[y]]}return f};for(let[u,p]of Object.entries(t.results)){if(p.startsWith(Nt.Transform.Prefix))continue;let f=kt(p);if(f!==null&&f!==r){a[u]=null;continue}p.startsWith("out.")||p==="out"||p.startsWith("out[")?a[u]=c(p)||null:a[u]=p}return{values:s,results:await U(t,a,r,n)}}async resolveWarpResultsRecursively(t){let e=t.warp,r=t.entryActionIndex,n=t.executor,s=t.inputs,o=t.meta,a=new Map,c=new Set,u=this;async function p(m,v=[]){if(a.has(m))return a.get(m);if(c.has(m))throw new Error(`Circular dependency detected at action ${m}`);c.add(m);let T=e.actions[m-1];if(!T)throw new Error(`Action ${m} not found`);let A;if(T.type==="query")A=await n.executeQuery(e,m,v);else if(T.type==="collect")A=await n.executeCollect(e,m,v,o);else throw new Error(`Unsupported or interactive action type: ${T.type}`);if(a.set(m,A),e.results)for(let I of Object.values(e.results)){let h=String(I).match(/^out\[(\d+)\]/);if(h){let R=parseInt(h[1],10);R!==m&&!a.has(R)&&await p(R)}}return c.delete(m),A}await p(r,s);let f={};for(let m of a.values())for(let[v,T]of Object.entries(m.results))T!==null?f[v]=T:v in f||(f[v]=null);let y=await U(e,f,r,s);return{...a.get(r),action:r,results:y}}};import{Address as ye,AddressValue as he,BigUIntType as we,BigUIntValue as Ut,BooleanValue as We,BytesValue as Te,CodeMetadata as Ce,CodeMetadataValue as be,CompositeType as ve,CompositeValue as Ie,Field as tt,FieldDefinition as et,List as Ae,NothingValue as xe,OptionalValue as rt,OptionValue as nt,StringValue as Be,Struct as Ee,StructType as Ve,TokenIdentifierType as Se,TokenIdentifierValue as $t,U16Value as Fe,U32Value as Re,U64Type as Pe,U64Value as Mt,U8Value as _e,VariadicValue as Oe}from"@multiversx/sdk-core";var an=(i,t)=>i?nt.newProvided(i):t?nt.newMissingTyped(t):nt.newMissing(),sn=(i,t)=>i?new rt(i.getType(),i):t?new rt(t):rt.newMissing(),on=i=>{if(i.length===0)throw new Error("Cannot create a list from an empty array");let t=i[0].getType();return new Ae(t,i)},cn=i=>Oe.fromItems(...i),un=i=>{let t=i.map(e=>e.getType());return new Ie(new ve(...t),i)},x=i=>Be.fromUTF8(i),pn=i=>new _e(i),ln=i=>new Fe(i),qt=i=>new Re(i),fn=i=>new Mt(i),mn=i=>new Ut(BigInt(i)),gn=i=>new We(i),dn=i=>new he(ye.newFromBech32(i)),yn=i=>new $t(i),hn=i=>Te.fromHex(i),Lt=i=>new Ee(new Ve("EsdtTokenPayment",[new et("token_identifier","",new Se),new et("token_nonce","",new Pe),new et("amount","",new we)]),[new tt(new $t(i.token.identifier),"token_identifier"),new tt(new Mt(BigInt(i.token.nonce)),"token_nonce"),new tt(new Ut(BigInt(i.amount)),"amount")]),wn=i=>new be(Ce.newFromBytes(Uint8Array.from(Buffer.from(i,"hex")))),Wn=()=>new xe;var w=class i{constructor(t){this.config=t;this.serializer=new B,this.abi=new V(this.config),this.results=new S(this.config)}async createTransaction(t){let e=at(t.warp,t.action),r=null;if(e.type==="transfer")r=await this.createTransferTransaction(t);else if(e.type==="contract")r=await this.createContractCallTransaction(t);else{if(e.type==="query")throw new Error("WarpMultiversxExecutor: Invalid action type for createTransactionForExecute; Use executeQuery instead");if(e.type==="collect")throw new Error("WarpMultiversxExecutor: Invalid action type for createTransactionForExecute; Use executeCollect instead")}if(!r)throw new Error(`WarpMultiversxExecutor: Invalid action type (${e.type})`);return r}async createTransferTransaction(t){let e=this.config.user?.wallets?.[t.chain.name];if(!e)throw new Error("WarpMultiversxExecutor: createTransfer - user address not set");let r=P.newFromBech32(e),n=new zt({chainID:t.chain.chainId}),s=t.data?Buffer.from(this.serializer.stringToTyped(t.data).valueOf()):null;return new Qe({config:n}).createTransactionForTransfer(r,{receiver:P.newFromBech32(t.destination),nativeAmount:t.value,data:s?new Uint8Array(s):void 0})}async createContractCallTransaction(t){let e=this.config.user?.wallets?.[t.chain.name];if(!e)throw new Error("WarpMultiversxExecutor: createContractCall - user address not set");let r=at(t.warp,t.action),n=P.newFromBech32(e),s=t.args.map(a=>this.serializer.stringToTyped(a)),o=new zt({chainID:t.chain.chainId});return new $e({config:o}).createTransactionForExecute(n,{contract:P.newFromBech32(t.destination),function:"func"in r&&r.func||"",gasLimit:"gasLimit"in r?BigInt(r.gasLimit||0):0n,arguments:s,nativeTransferAmount:t.value})}async executeQuery(t){let e=at(t.warp,t.action);if(e.type!=="query")throw new Error(`WarpMultiversxExecutor: Invalid action type for executeQuery: ${e.type}`);let r=await this.abi.getAbiForAction(e),n=t.args.map(I=>this.serializer.stringToTyped(I)),s=i.getChainEntrypoint(t.chain,this.config.env),o=P.newFromBech32(t.destination),a=s.createSmartContractController(r),c=a.createQuery({contract:o,function:e.func||"",arguments:n}),u=await a.runQuery(c),p=u.returnCode==="ok",f=new ke,y=r.getEndpoint(u.function||e.func||""),W=(u.returnDataParts||[]).map(I=>Buffer.from(I)),m=f.buffersToValues(W,y.output),{values:v,results:T}=await this.results.extractQueryResults(t.warp,m,t.action,t.resolvedInputs),A=je(this.config,t.warp,t.action,T);return{success:p,warp:t.warp,action:t.action,user:this.config.user?.wallets?.[t.chain.name]||null,txHash:null,next:A,values:v,results:T,messages:He(t.warp,T)}}async preprocessInput(t,e,r,n){if(r==="esdt"){let[s,o,a,c]=n.split(Qt.ArgCompositeSeparator);if(c)return e;let u=new qe({identifier:s,nonce:BigInt(o)});if(!new Le().isFungible(u))return e;let y=De(s)?.decimals;if(y||(y=(await(await fetch(`${t.apiUrl}/tokens/${s}`)).json()).decimals),!y)throw new Error(`WarpActionExecutor: Decimals not found for token ${s}`);let W=Lt(new ze({token:u,amount:Ge(a,y)}));return this.serializer.typedToString(W)+Qt.ArgCompositeSeparator+y}return e}static getChainEntrypoint(t,e){let r="warp-sdk",n="api";return e==="devnet"?new Ne(t.apiUrl,n,r):e==="testnet"?new Me(t.apiUrl,n,r):new Ue(t.apiUrl,n,r)}};var $=class{constructor(t){this.config=t;this.cache=new Ye(t.cache?.type),this.core=new Xe(t)}createInscriptionTransaction(t){let e=Dt(this.config),r=this.config.user?.wallets?.[e.name];if(!r)throw new Error("WarpBuilder: user address not set");let n=new Ke({chainID:e.chainId}),s=new Je({config:n}),o=Ht.newFromBech32(r),a=JSON.stringify(t),c=s.createTransactionForTransfer(o,{receiver:Ht.newFromBech32(r),nativeAmount:BigInt(0),data:Uint8Array.from(Buffer.from(a))});return c.gasLimit=c.gasLimit+BigInt(2e6),c}async createFromTransaction(t,e=!1){let r=await this.core.createFromRaw(t.data.toString(),e);return r.meta={hash:t.hash,creator:t.sender.toBech32(),createdAt:new Date(t.timestamp*1e3).toISOString()},r}async createFromTransactionHash(t,e){let r=Ze.Warp(this.config.env,t);if(e){let a=this.cache.get(r);if(a)return jt.info(`WarpBuilder (createFromTransactionHash): Warp found in cache: ${t}`),a}let n=Dt(this.config),o=w.getChainEntrypoint(n,this.config.env).createNetworkProvider();try{let a=await o.getTransaction(t),c=await this.createFromTransaction(a);return e&&e.ttl&&c&&this.cache.set(r,c,e.ttl),c}catch(a){return jt.error("WarpBuilder: Error creating from transaction hash",a),null}}};var M=class{constructor(t){this.chainInfo=t}getAccountUrl(t){return`${this.chainInfo.explorerUrl}/accounts/${t}`}getTransactionUrl(t){return`${this.chainInfo.explorerUrl}/transactions/${t}`}};import{AbiRegistry as Kt,Address as l,AddressValue as st,BytesValue as g,SmartContractTransactionsFactory as er,TransactionsFactoryConfig as rr}from"@multiversx/sdk-core";import{getMainChainInfo as ot,toTypedChainInfo as Jt,WarpCache as nr,WarpCacheKey as F,WarpLogger as _}from"@vleap/warps";var it={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 d=i=>i==="devnet"?"erd1qqqqqqqqqqqqqpgqje2f99vr6r7sk54thg03c9suzcvwr4nfl3tsfkdl36":i==="testnet"?"####":"erd1qqqqqqqqqqqqqpgq3mrpj3u6q7tejv6d7eqhnyd27n9v5c5tl3ts08mffe";var q=i=>({hash:i.hash.toString("hex"),alias:i.alias?.toString()||null,trust:i.trust.toString(),owner:i.owner.toString(),createdAt:i.created_at.toNumber(),upgradedAt:i.upgraded_at?.toNumber(),brand:i.brand?.toString("hex")||null,upgrade:i.upgrade?.toString("hex")||null}),Gt=i=>({unitPrice:BigInt(i.unit_price.toString()),admins:i.admins.map(t=>t.toBech32())});var L=class{constructor(t){this.config=t;this.cache=new nr(t.cache?.type),this.registryConfig={unitPrice:BigInt(0),admins:[]},this.userWallet=this.config.user?.wallets?.[E.ChainName]||null}async init(){await this.loadRegistryConfigs()}getRegistryConfig(){return this.registryConfig}createWarpRegisterTransaction(t,e,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=l.newFromBech32(this.userWallet),s=()=>this.isCurrentUserAdmin()?BigInt(0):e&&r?this.registryConfig.unitPrice*BigInt(3):e?this.registryConfig.unitPrice*BigInt(2):this.registryConfig.unitPrice,o=()=>e&&r?[g.fromHex(t),g.fromUTF8(e),g.fromHex(r)]:e?[g.fromHex(t),g.fromUTF8(e)]:[g.fromHex(t)];return this.getFactory().createTransactionForExecute(n,{contract:l.newFromBech32(d(this.config.env)),function:"registerWarp",gasLimit:BigInt(1e7),nativeTransferAmount:s(),arguments:o()})}createWarpUnregisterTransaction(t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let e=l.newFromBech32(this.userWallet);return this.getFactory().createTransactionForExecute(e,{contract:l.newFromBech32(d(this.config.env)),function:"unregisterWarp",gasLimit:BigInt(1e7),arguments:[g.fromHex(t)]})}createWarpUpgradeTransaction(t,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 r=l.newFromBech32(this.userWallet);return this.getFactory().createTransactionForExecute(r,{contract:l.newFromBech32(d(this.config.env)),function:"upgradeWarp",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[g.fromUTF8(t),g.fromHex(e)]})}createWarpAliasSetTransaction(t,e){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let r=l.newFromBech32(this.userWallet);return this.getFactory().createTransactionForExecute(r,{contract:l.newFromBech32(d(this.config.env)),function:"setWarpAlias",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[g.fromHex(t),g.fromUTF8(e)]})}createWarpVerifyTransaction(t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let e=l.newFromBech32(this.userWallet);return this.getFactory().createTransactionForExecute(e,{contract:l.newFromBech32(d(this.config.env)),function:"verifyWarp",gasLimit:BigInt(1e7),arguments:[g.fromHex(t)]})}createWarpTransferOwnershipTransaction(t,e){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let r=l.newFromBech32(this.userWallet);return this.getFactory().createTransactionForExecute(r,{contract:l.newFromBech32(d(this.config.env)),function:"transferOwnership",gasLimit:BigInt(1e7),arguments:[g.fromHex(t),new st(new l(e))]})}createBrandRegisterTransaction(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 e=l.newFromBech32(this.userWallet);return this.getFactory().createTransactionForExecute(e,{contract:l.newFromBech32(d(this.config.env)),function:"registerBrand",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[g.fromHex(t)]})}createWarpBrandingTransaction(t,e){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let r=l.newFromBech32(this.userWallet);return this.getFactory().createTransactionForExecute(r,{contract:l.newFromBech32(d(this.config.env)),function:"brandWarp",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[g.fromHex(t),g.fromHex(e)]})}async getInfoByAlias(t,e){try{let r=F.RegistryInfo(this.config.env,t),n=e?this.cache.get(r):null;if(n)return _.info(`WarpRegistry (getInfoByAlias): RegistryInfo found in cache: ${t}`),n;let s=l.newFromBech32(d(this.config.env)),o=this.getController(),a=o.createQuery({contract:s,function:"getInfoByAlias",arguments:[g.fromUTF8(t)]}),c=await o.runQuery(a),[u]=o.parseQueryResponse(c),p=u?q(u):null,f=p?.brand?await this.fetchBrand(p.brand):null;return e&&e.ttl&&this.cache.set(r,{registryInfo:p,brand:f},e.ttl),{registryInfo:p,brand:f}}catch{return{registryInfo:null,brand:null}}}async getInfoByHash(t,e){try{let r=F.RegistryInfo(this.config.env,t);if(e){let f=this.cache.get(r);if(f)return _.info(`WarpRegistry (getInfoByHash): RegistryInfo found in cache: ${t}`),f}let n=l.newFromBech32(d(this.config.env)),s=this.getController(),o=s.createQuery({contract:n,function:"getInfoByHash",arguments:[g.fromHex(t)]}),a=await s.runQuery(o),[c]=s.parseQueryResponse(a),u=c?q(c):null,p=u?.brand?await this.fetchBrand(u.brand):null;return e&&e.ttl&&this.cache.set(r,{registryInfo:u,brand:p},e.ttl),{registryInfo:u,brand:p}}catch{return{registryInfo:null,brand:null}}}async getUserWarpRegistryInfos(t){try{let e=t||this.userWallet;if(!e)throw new Error("WarpRegistry: user address not set");let r=l.newFromBech32(d(this.config.env)),n=this.getController(),s=n.createQuery({contract:r,function:"getUserWarps",arguments:[new st(new l(e))]}),o=await n.runQuery(s),[a]=n.parseQueryResponse(o);return a.map(q)}catch{return[]}}async getUserBrands(t){try{let e=t||this.userWallet;if(!e)throw new Error("WarpRegistry: user address not set");let r=l.newFromBech32(d(this.config.env)),n=this.getController(),s=n.createQuery({contract:r,function:"getUserBrands",arguments:[new st(new l(e))]}),o=await n.runQuery(s),[a]=n.parseQueryResponse(o),c=a.map(f=>f.toString("hex")),u={ttl:365*24*60*60};return(await Promise.all(c.map(f=>this.fetchBrand(f,u)))).filter(f=>f!==null)}catch{return[]}}async getChainInfos(t){let e=F.ChainInfos(this.config.env);if(t&&t.ttl){let u=this.cache.get(e);if(u)return _.info("WarpRegistry (getChainInfos): ChainInfos found in cache"),u}let r=l.newFromBech32(d(this.config.env)),n=this.getController(),s=n.createQuery({contract:r,function:"getChains",arguments:[]}),o=await n.runQuery(s),[a]=n.parseQueryResponse(o),c=a.map(Jt);if(t&&t.ttl){for(let u of c)this.cache.set(F.ChainInfo(this.config.env,u.chain),u,t.ttl);this.cache.set(e,c,t.ttl)}return c}async getChainInfo(t,e){try{let r=F.ChainInfo(this.config.env,t),n=e?this.cache.get(r):null;if(n)return _.info(`WarpRegistry (getChainInfo): ChainInfo found in cache: ${t}`),n;let s=l.newFromBech32(d(this.config.env)),o=this.getController(),a=o.createQuery({contract:s,function:"getChain",arguments:[g.fromUTF8(t)]}),c=await o.runQuery(a),[u]=o.parseQueryResponse(c),p=u?Jt(u):null;return e&&e.ttl&&p&&this.cache.set(r,p,e.ttl),p}catch{return null}}async setChain(t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let e=l.newFromBech32(this.userWallet);return this.getFactory().createTransactionForExecute(e,{contract:l.newFromBech32(d(this.config.env)),function:"setChain",gasLimit:BigInt(1e7),arguments:[x(t.name),x(t.displayName),x(t.chainId),qt(t.blockTime),x(t.addressHrp),x(t.apiUrl),x(t.explorerUrl),x(t.nativeToken)]})}async removeChain(t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let e=l.newFromBech32(this.userWallet);return this.getFactory().createTransactionForExecute(e,{contract:l.newFromBech32(d(this.config.env)),function:"removeChain",gasLimit:BigInt(1e7),arguments:[x(t)]})}async fetchBrand(t,e){let r=F.Brand(this.config.env,t),n=e?this.cache.get(r):null;if(n)return _.info(`WarpRegistry (fetchBrand): Brand found in cache: ${t}`),n;let s=ot(this.config),a=w.getChainEntrypoint(s,this.config.env).createNetworkProvider();try{let c=await a.getTransaction(t),u=JSON.parse(c.data.toString());return u.meta={hash:c.hash,creator:c.sender.bech32(),createdAt:new Date(c.timestamp*1e3).toISOString()},e&&e.ttl&&this.cache.set(r,u,e.ttl),u}catch{return null}}async loadRegistryConfigs(){let t=l.newFromBech32(d(this.config.env)),e=this.getController(),[r]=await e.query({contract:t,function:"getConfig",arguments:[]}),n=r?Gt(r):null;this.registryConfig=n||{unitPrice:BigInt(0),admins:[]}}getFactory(){let t=ot(this.config),e=new rr({chainID:t.chainId}),r=Kt.create(it);return new er({config:e,abi:r})}getController(){let t=ot(this.config),e=w.getChainEntrypoint(t,this.config.env),r=Kt.create(it);return e.createSmartContractController(r)}isCurrentUserAdmin(){return!!this.userWallet&&this.registryConfig.admins.includes(this.userWallet)}};var Ia=i=>({chain:E.ChainName,prefix:"mvx",builder:new $(i),executor:new w(i),results:new S(i),serializer:new B,registry:new L(i),explorer:t=>new M(t)});import{Address as Xt,TransactionsFactoryConfig as ar,TransferTransactionsFactory as ir}from"@multiversx/sdk-core";import{getMainChainInfo as Yt,WarpBrandBuilder as sr,WarpLogger as or}from"@vleap/warps";import{Buffer as cr}from"buffer";var Zt=class{constructor(t){this.config=t;this.core=new sr(t)}createInscriptionTransaction(t){let e=Yt(this.config),r=this.config.user?.wallets?.[e.name];if(!r)throw new Error("BrandBuilder: user address not set");let n=new ar({chainID:e.chainId}),s=new ir({config:n}),o=Xt.newFromBech32(r),a=JSON.stringify(t);return s.createTransactionForNativeTokenTransfer(o,{receiver:Xt.newFromBech32(r),nativeAmount:BigInt(0),data:Uint8Array.from(cr.from(a))})}async createFromTransaction(t,e=!1){return await this.core.createFromRaw(t.data.toString(),e)}async createFromTransactionHash(t){let e=Yt(this.config),n=w.getChainEntrypoint(e,this.config.env).createNetworkProvider();try{let s=await n.getTransaction(t);return this.createFromTransaction(s)}catch(s){return or.error("BrandBuilder: Error creating from transaction hash",s),null}}};export{V as WarpMultiversxAbi,Zt as WarpMultiversxBrandBuilder,$ as WarpMultiversxBuilder,E as WarpMultiversxConstants,N as WarpMultiversxContractLoader,w as WarpMultiversxExecutor,M as WarpMultiversxExplorer,L as WarpMultiversxRegistry,S as WarpMultiversxResults,B as WarpMultiversxSerializer,dn as address_value,mn as biguint_value,gn as boolean_value,wn as codemeta_value,un as composite_value,Lt as esdt_value,Ia as getMultiversxAdapter,hn as hex_value,on as list_value,Wn as nothing_value,an as option_value,sn as optional_value,x as string_value,yn as token_value,ln as u16_value,qt as u32_value,fn as u64_value,pn as u8_value,cn 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.12",
3
+ "version": "0.2.0-alpha.13",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -31,6 +31,6 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@multiversx/sdk-core": "^14.2.1",
34
- "@vleap/warps": "^3.0.0-alpha.48"
34
+ "@vleap/warps": "^3.0.0-alpha.53"
35
35
  }
36
36
  }