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