@vleap/warps-adapter-multiversx 0.2.0-alpha.3 → 0.2.0-alpha.31

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.ts CHANGED
@@ -1,5 +1,19 @@
1
- import { Adapter, WarpInitConfig, WarpAbi, WarpCacheConfig, WarpContractAction, WarpQueryAction, AdapterWarpBuilder, Warp, WarpChainInfo, WarpContract, WarpContractVerification, AdapterWarpExecutor, WarpExecutable, WarpExecution, WarpChainEnv, AdapterWarpRegistry, WarpRegistryConfigInfo, WarpRegistryInfo, WarpBrand, WarpChain, AdapterWarpResults, WarpActionIndex, ResolvedInput, WarpExecutionResults, AdapterWarpSerializer, WarpSerializer, WarpActionInputType, WarpNativeValue, BaseWarpActionInputType, WarpAdapterGenericType } from '@vleap/warps-core';
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, Address } from '@multiversx/sdk-core';
1
+ import * as _vleap_warps from '@vleap/warps';
2
+ import { WarpClientConfig, Adapter, WarpChain, WarpChainEnv, WarpChainInfo, AdapterFactory, AdapterWarpAbiBuilder, WarpAbi, WarpCacheConfig, WarpContractAction, WarpQueryAction, WarpBrand, WarpBuilder, AdapterWarpBuilder, Warp, WarpContract, WarpContractVerification, AdapterWarpExecutor, WarpExecutable, WarpExecution, WarpActionInputType, AdapterWarpExplorer, AdapterWarpRegistry, WarpRegistryConfigInfo, WarpRegistryInfo, AdapterWarpResults, ResolvedInput, WarpExecutionResults, AdapterWarpSerializer, WarpSerializer, WarpNativeValue, BaseWarpActionInputType, WarpAdapterGenericType } from '@vleap/warps';
3
+ 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';
4
+
5
+ declare const getAllMultiversxAdapters: (config: WarpClientConfig, fallback?: Adapter) => Adapter[];
6
+ declare const getAllMultiversxChainNames: () => WarpChain[];
7
+
8
+ declare const createMultiversxAdapter: (chainName: string, chainPrefix: string, chainInfos: Record<WarpChainEnv, WarpChainInfo>) => AdapterFactory;
9
+
10
+ declare const ChainNameMultiversx: WarpChain;
11
+ declare const getMultiversxAdapter: _vleap_warps.AdapterFactory;
12
+
13
+ declare const ChainNameVibechain: WarpChain;
14
+ declare const getVibechainAdapter: _vleap_warps.AdapterFactory;
15
+
16
+ declare const getMultiversxRegistryAddress: (env: WarpChainEnv) => "erd1qqqqqqqqqqqqqpgqje2f99vr6r7sk54thg03c9suzcvwr4nfl3tsfkdl36" | "erd1qqqqqqqqqqqqqpgq3mrpj3u6q7tejv6d7eqhnyd27n9v5c5tl3ts08mffe";
3
17
 
4
18
  declare const WarpMultiversxConstants: {
5
19
  Egld: {
@@ -9,8 +23,30 @@ declare const WarpMultiversxConstants: {
9
23
  Decimals: number;
10
24
  };
11
25
  };
12
-
13
- declare const getMultiversxAdapter: () => Adapter;
26
+ declare enum MultiversxExplorers {
27
+ MultiversxExplorer = "multiversx_explorer",
28
+ MultiversxExplorerDevnet = "multiversx_explorer_devnet",
29
+ MultiversxExplorerTestnet = "multiversx_explorer_testnet"
30
+ }
31
+ declare enum VibechainExplorers {
32
+ VibechainExplorer = "vibechain_explorer",
33
+ VibechainExplorerDevnet = "vibechain_explorer_devnet",
34
+ VibechainExplorerTestnet = "vibechain_explorer_testnet"
35
+ }
36
+ type ExplorerName = MultiversxExplorers | VibechainExplorers;
37
+ declare const MultiversxExplorersConfig: {
38
+ readonly multiversx: {
39
+ readonly mainnet: readonly [MultiversxExplorers.MultiversxExplorer];
40
+ readonly testnet: readonly [MultiversxExplorers.MultiversxExplorerTestnet];
41
+ readonly devnet: readonly [MultiversxExplorers.MultiversxExplorerDevnet];
42
+ };
43
+ readonly vibechain: {
44
+ readonly mainnet: readonly [VibechainExplorers.VibechainExplorer];
45
+ readonly testnet: readonly [VibechainExplorers.VibechainExplorerTestnet];
46
+ readonly devnet: readonly [VibechainExplorers.VibechainExplorerDevnet];
47
+ };
48
+ };
49
+ declare const ExplorerUrls: Record<ExplorerName, string>;
14
50
 
15
51
  declare const option_value: (value: TypedValue | null, type?: Type) => OptionValue;
16
52
  declare const optional_value: (value: TypedValue | null, type?: Type) => OptionalValue;
@@ -31,11 +67,12 @@ declare const esdt_value: (value: TokenTransfer) => Struct;
31
67
  declare const codemeta_value: (hexString: string) => CodeMetadataValue;
32
68
  declare const nothing_value: () => NothingValue;
33
69
 
34
- declare class WarpMultiversxAbi {
70
+ declare class WarpMultiversxAbiBuilder implements AdapterWarpAbiBuilder {
35
71
  private readonly config;
72
+ private readonly chain;
36
73
  private readonly contractLoader;
37
74
  private readonly cache;
38
- constructor(config: WarpInitConfig);
75
+ constructor(config: WarpClientConfig, chain: WarpChainInfo);
39
76
  createFromRaw(encoded: string): Promise<WarpAbi>;
40
77
  createFromTransaction(tx: TransactionOnNetwork): Promise<WarpAbi>;
41
78
  createFromTransactionHash(hash: string, cache?: WarpCacheConfig): Promise<WarpAbi | null>;
@@ -43,50 +80,85 @@ declare class WarpMultiversxAbi {
43
80
  fetchAbi(action: WarpContractAction | WarpQueryAction): Promise<AbiRegistry>;
44
81
  }
45
82
 
46
- declare class WarpMultiversxBuilder implements AdapterWarpBuilder {
47
- private config;
48
- private cache;
49
- private core;
50
- constructor(config: WarpInitConfig);
51
- createInscriptionTransaction(warp: Warp): Transaction;
83
+ declare class WarpMultiversxBrandBuilder {
84
+ private readonly config;
85
+ private readonly chain;
86
+ private readonly core;
87
+ constructor(config: WarpClientConfig, chain: WarpChainInfo);
88
+ createInscriptionTransaction(brand: WarpBrand): Promise<Transaction>;
89
+ createFromTransaction(tx: TransactionOnNetwork, validateSchema?: boolean): Promise<WarpBrand>;
90
+ createFromTransactionHash(hash: string): Promise<WarpBrand | null>;
91
+ }
92
+
93
+ declare class WarpMultiversxBuilder extends WarpBuilder implements AdapterWarpBuilder {
94
+ protected readonly config: WarpClientConfig;
95
+ private readonly chain;
96
+ private readonly cache;
97
+ private readonly core;
98
+ constructor(config: WarpClientConfig, chain: WarpChainInfo);
99
+ createInscriptionTransaction(warp: Warp): Promise<Transaction>;
52
100
  createFromTransaction(tx: TransactionOnNetwork, validate?: boolean): Promise<Warp>;
53
101
  createFromTransactionHash(hash: string, cache?: WarpCacheConfig): Promise<Warp | null>;
54
102
  }
55
103
 
56
104
  declare class WarpMultiversxContractLoader {
57
105
  private readonly config;
58
- constructor(config: WarpInitConfig);
106
+ constructor(config: WarpClientConfig);
59
107
  getContract(address: string, chain: WarpChainInfo): Promise<WarpContract | null>;
60
108
  getVerificationInfo(address: string, chain: WarpChainInfo): Promise<WarpContractVerification | null>;
61
109
  }
62
110
 
63
111
  declare class WarpMultiversxExecutor implements AdapterWarpExecutor {
64
112
  private readonly config;
113
+ private readonly chain;
65
114
  private readonly serializer;
66
115
  private readonly abi;
67
116
  private readonly results;
68
- constructor(config: WarpInitConfig);
117
+ constructor(config: WarpClientConfig, chain: WarpChainInfo);
69
118
  createTransaction(executable: WarpExecutable): Promise<Transaction>;
70
119
  createTransferTransaction(executable: WarpExecutable): Promise<Transaction>;
71
120
  createContractCallTransaction(executable: WarpExecutable): Promise<Transaction>;
72
121
  executeQuery(executable: WarpExecutable): Promise<WarpExecution>;
73
- static getChainEntrypoint(chainInfo: WarpChainInfo, env: WarpChainEnv): NetworkEntrypoint;
122
+ preprocessInput(chain: WarpChainInfo, input: string, type: WarpActionInputType, value: string): Promise<string>;
123
+ static getChainEntrypoint(chainInfo: WarpChainInfo, env: WarpChainEnv, config?: WarpClientConfig): NetworkEntrypoint;
124
+ signMessage(message: string, privateKey: string): Promise<string>;
125
+ }
126
+
127
+ declare class WarpMultiversxExplorer implements AdapterWarpExplorer {
128
+ private readonly chain;
129
+ private readonly config;
130
+ constructor(chain: WarpChain, config: WarpClientConfig);
131
+ private getExplorers;
132
+ private getPrimaryExplorer;
133
+ private getExplorerUrlByName;
134
+ getAccountUrl(address: string, explorer?: ExplorerName): string;
135
+ getTransactionUrl(hash: string, explorer?: ExplorerName): string;
136
+ getBlockUrl(blockNumber: string | number, explorer?: ExplorerName): string;
137
+ getAssetUrl(identifier: string, explorer?: ExplorerName): string;
138
+ getContractUrl(address: string, explorer?: ExplorerName): string;
139
+ getAllExplorers(): readonly ExplorerName[];
140
+ getExplorerByName(name: string): ExplorerName | undefined;
141
+ getAccountUrls(address: string): Record<ExplorerName, string>;
142
+ getTransactionUrls(hash: string): Record<ExplorerName, string>;
74
143
  }
75
144
 
76
145
  declare class WarpMultiversxRegistry implements AdapterWarpRegistry {
77
146
  private config;
147
+ private chain;
78
148
  private cache;
149
+ private userWallet;
79
150
  registryConfig: WarpRegistryConfigInfo;
80
- constructor(config: WarpInitConfig);
151
+ constructor(config: WarpClientConfig, chain: WarpChainInfo);
81
152
  init(): Promise<void>;
82
- createWarpRegisterTransaction(txHash: string, alias?: string | null, brand?: string | null): Transaction;
83
- createWarpUnregisterTransaction(txHash: string): Transaction;
84
- createWarpUpgradeTransaction(alias: string, txHash: string): Transaction;
85
- createWarpAliasSetTransaction(txHash: string, alias: string): Transaction;
86
- createWarpVerifyTransaction(txHash: string): Transaction;
87
- createWarpTransferOwnershipTransaction(txHash: string, newOwner: string): Transaction;
88
- createBrandRegisterTransaction(txHash: string): Transaction;
89
- createWarpBrandingTransaction(warpHash: string, brandHash: string): Transaction;
153
+ getRegistryConfig(): WarpRegistryConfigInfo;
154
+ createWarpRegisterTransaction(txHash: string, alias?: string | null, brand?: string | null): Promise<Transaction>;
155
+ createWarpUnregisterTransaction(txHash: string): Promise<Transaction>;
156
+ createWarpUpgradeTransaction(alias: string, txHash: string): Promise<Transaction>;
157
+ createWarpAliasSetTransaction(txHash: string, alias: string): Promise<Transaction>;
158
+ createWarpVerifyTransaction(txHash: string): Promise<Transaction>;
159
+ createWarpTransferOwnershipTransaction(txHash: string, newOwner: string): Promise<Transaction>;
160
+ createBrandRegisterTransaction(txHash: string): Promise<Transaction>;
161
+ createWarpBrandingTransaction(warpHash: string, brandHash: string): Promise<Transaction>;
90
162
  getInfoByAlias(alias: string, cache?: WarpCacheConfig): Promise<{
91
163
  registryInfo: WarpRegistryInfo | null;
92
164
  brand: WarpBrand | null;
@@ -97,12 +169,7 @@ declare class WarpMultiversxRegistry implements AdapterWarpRegistry {
97
169
  }>;
98
170
  getUserWarpRegistryInfos(user?: string): Promise<WarpRegistryInfo[]>;
99
171
  getUserBrands(user?: string): Promise<WarpBrand[]>;
100
- getChainInfos(cache?: WarpCacheConfig): Promise<WarpChainInfo[]>;
101
- getChainInfo(chain: WarpChain, cache?: WarpCacheConfig): Promise<WarpChainInfo | null>;
102
- setChain(info: WarpChainInfo): Promise<Transaction>;
103
- removeChain(chain: WarpChain): Promise<Transaction>;
104
172
  fetchBrand(hash: string, cache?: WarpCacheConfig): Promise<WarpBrand | null>;
105
- getRegistryContractAddress(): Address;
106
173
  private loadRegistryConfigs;
107
174
  private getFactory;
108
175
  private getController;
@@ -111,12 +178,13 @@ declare class WarpMultiversxRegistry implements AdapterWarpRegistry {
111
178
 
112
179
  declare class WarpMultiversxResults implements AdapterWarpResults {
113
180
  private readonly config;
181
+ private readonly chain;
114
182
  private readonly abi;
115
183
  private readonly serializer;
116
184
  private readonly cache;
117
- constructor(config: WarpInitConfig);
118
- getTransactionExecutionResults(warp: Warp, actionIndex: WarpActionIndex, tx: TransactionOnNetwork): Promise<WarpExecution>;
119
- extractContractResults(warp: Warp, actionIndex: WarpActionIndex, tx: TransactionOnNetwork, inputs: ResolvedInput[]): Promise<{
185
+ constructor(config: WarpClientConfig, chain: WarpChainInfo);
186
+ getTransactionExecutionResults(warp: Warp, tx: TransactionOnNetwork): Promise<WarpExecution>;
187
+ extractContractResults(warp: Warp, tx: TransactionOnNetwork, inputs: ResolvedInput[]): Promise<{
120
188
  values: any[];
121
189
  results: WarpExecutionResults;
122
190
  }>;
@@ -147,4 +215,4 @@ declare class WarpMultiversxSerializer implements AdapterWarpSerializer {
147
215
  typeToString(type: Type): WarpActionInputType;
148
216
  }
149
217
 
150
- export { WarpMultiversxAbi, WarpMultiversxBuilder, WarpMultiversxConstants, WarpMultiversxContractLoader, WarpMultiversxExecutor, WarpMultiversxRegistry, WarpMultiversxResults, WarpMultiversxSerializer, address_value, biguint_value, boolean_value, codemeta_value, composite_value, esdt_value, getMultiversxAdapter, hex_value, list_value, nothing_value, option_value, optional_value, string_value, token_value, u16_value, u32_value, u64_value, u8_value, variadic_value };
218
+ export { ChainNameMultiversx, ChainNameVibechain, type ExplorerName, ExplorerUrls, MultiversxExplorers, MultiversxExplorersConfig, VibechainExplorers, WarpMultiversxAbiBuilder, WarpMultiversxBrandBuilder, WarpMultiversxBuilder, WarpMultiversxConstants, WarpMultiversxContractLoader, WarpMultiversxExecutor, WarpMultiversxExplorer, WarpMultiversxRegistry, WarpMultiversxResults, WarpMultiversxSerializer, address_value, biguint_value, boolean_value, codemeta_value, composite_value, createMultiversxAdapter, esdt_value, getAllMultiversxAdapters, getAllMultiversxChainNames, getMultiversxAdapter, getMultiversxRegistryAddress, getVibechainAdapter, hex_value, list_value, nothing_value, option_value, optional_value, string_value, token_value, u16_value, u32_value, u64_value, u8_value, variadic_value };
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- var je={Egld:{Identifier:"EGLD",EsdtIdentifier:"EGLD-000000",DisplayName:"eGold",Decimals:18}};import{Address as Ot,TransactionsFactoryConfig as me,TransferTransactionsFactory as he}from"@multiversx/sdk-core";import{getMainChainInfo as Ut,WarpBuilder as we,WarpCache as Te,WarpCacheKey as Ce,WarpLogger as Nt}from"@vleap/warps-core";import{Address as S,ArgSerializer as ce,DevnetEntrypoint as ue,MainnetEntrypoint as pe,SmartContractTransactionsFactory as le,TestnetEntrypoint as fe,TransactionsFactoryConfig as _t,TransferTransactionsFactory as ge}from"@multiversx/sdk-core";import{applyResultsToMessages as ye,getNextInfo as de,getWarpActionByIndex as X}from"@vleap/warps-core";import{AbiRegistry as M}from"@multiversx/sdk-core";import{getMainChainInfo as st,WarpCache as Dt,WarpCacheKey as jt,WarpConstants as ot,WarpLogger as ct}from"@vleap/warps-core";import{WarpLogger as it}from"@vleap/warps-core";var O=class{constructor(t){this.config=t}async getContract(t,e){try{let s=await m.getChainEntrypoint(e,this.config.env).createNetworkProvider().doGetGeneric(`accounts/${t}`);return{address:t,owner:s.ownerAddress,verified:s.isVerified||!1}}catch(r){return it.error("WarpContractLoader: getContract error",r),null}}async getVerificationInfo(t,e){try{let s=await m.getChainEntrypoint(e,this.config.env).createNetworkProvider().doGetGeneric(`accounts/${t}/verification`);return{codeHash:s.codeHash,abi:s.source.abi}}catch(r){return it.error("WarpContractLoader: getVerificationInfo error",r),null}}};var B=class{constructor(t){this.config=t;this.contractLoader=new O(this.config),this.cache=new Dt(this.config.cache?.type)}async createFromRaw(t){return JSON.parse(t)}async createFromTransaction(t){let e=await this.createFromRaw(t.data.toString());return e.meta={hash:t.hash,creator:t.sender.bech32(),createdAt:new Date(t.timestamp*1e3).toISOString()},e}async createFromTransactionHash(t,e){let r=jt.WarpAbi(this.config.env,t);if(e){let a=this.cache.get(r);if(a)return ct.info(`WarpAbiBuilder (createFromTransactionHash): Warp abi found in cache: ${t}`),a}let n=st(this.config),o=m.getChainEntrypoint(n,this.config.env).createNetworkProvider();try{let a=await o.getTransaction(t),u=await this.createFromTransaction(a);return e&&e.ttl&&u&&this.cache.set(r,u,e.ttl),u}catch(a){return ct.error("WarpAbiBuilder: Error creating from transaction hash",a),null}}async getAbiForAction(t){if(t.abi)return await this.fetchAbi(t);if(!t.address)throw new Error("WarpActionExecutor: Address not found");let e=st(this.config),r=await this.contractLoader.getVerificationInfo(t.address,e);if(!r)throw new Error("WarpActionExecutor: Verification info not found");return M.create(r.abi)}async fetchAbi(t){if(!t.abi)throw new Error("WarpActionExecutor: ABI not found");if(t.abi.startsWith(ot.IdentifierType.Hash)){let e=t.abi.split(ot.IdentifierParamSeparator)[1],r=await this.createFromTransactionHash(e);if(!r)throw new Error(`WarpActionExecutor: ABI not found for hash: ${t.abi}`);return M.create(r.content)}else{let r=await(await fetch(t.abi)).json();return M.create(r)}}};import{findEventsByFirstTopic as te,SmartContractTransactionsOutcomeParser as ee,TransactionEventsParser as re}from"@multiversx/sdk-core";import{applyResultsToMessages as ne,evaluateResultsCommon as U,getNextInfo as ae,getWarpActionByIndex as ie,parseResultsOutIndex as Ft,WarpCache as se,WarpCacheKey as oe,WarpConstants as Pt}from"@vleap/warps-core";import{Address as Gt,AddressType as ut,AddressValue as pt,BigUIntType as L,BigUIntValue as Q,BooleanType as lt,BooleanValue as ft,BytesType as gt,BytesValue as yt,CodeMetadata as qt,CodeMetadataType as dt,CodeMetadataValue as mt,CompositeType as ht,CompositeValue as wt,Field as H,FieldDefinition as z,List as Tt,ListType as Kt,NothingValue as T,OptionalType as Jt,OptionalValue as D,OptionType as Xt,OptionValue as j,StringType as Ct,StringValue as Wt,Struct as Yt,StructType as bt,TokenIdentifierType as G,TokenIdentifierValue as q,U16Type as At,U16Value as It,U32Type as vt,U32Value as xt,U64Type as K,U64Value as J,U8Type as Bt,U8Value as Vt,VariadicType as Et,VariadicValue as Rt}from"@multiversx/sdk-core";import{WarpConstants as C,WarpSerializer as Zt}from"@vleap/warps-core";var St=new RegExp(`${C.ArgParamsSeparator}(.*)`),x=class{constructor(){this.coreSerializer=new Zt}typedToString(t){if(t.hasClassOrSuperclass(j.ClassName))return t.isSet()?`option:${this.typedToString(t.getTypedValue())}`:"option:null";if(t.hasClassOrSuperclass(D.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(C.ArgParamsSeparator)[0])[0],s=e.map(o=>this.typedToString(o).split(C.ArgParamsSeparator)[1]);return`list:${n}:${s.join(",")}`}if(t.hasClassOrSuperclass(Rt.ClassName)){let e=t.getItems(),n=e.map(o=>this.typedToString(o).split(C.ArgParamsSeparator)[0])[0],s=e.map(o=>this.typedToString(o).split(C.ArgParamsSeparator)[1]);return`variadic:${n}:${s.join(",")}`}if(t.hasClassOrSuperclass(wt.ClassName)){let e=t.getItems(),r=e.map(a=>this.typedToString(a).split(C.ArgParamsSeparator)[0]),n=e.map(a=>this.typedToString(a).split(C.ArgParamsSeparator)[1]),s=r.join(C.ArgCompositeSeparator),o=n.join(C.ArgCompositeSeparator);return`composite(${s}):${o}`}if(t.hasClassOrSuperclass(Q.ClassName)||t.getType().getName()==="BigUint")return`biguint:${BigInt(t.valueOf().toFixed())}`;if(t.hasClassOrSuperclass(Vt.ClassName))return`uint8:${t.valueOf().toNumber()}`;if(t.hasClassOrSuperclass(It.ClassName))return`uint16:${t.valueOf().toNumber()}`;if(t.hasClassOrSuperclass(xt.ClassName))return`uint32:${t.valueOf().toNumber()}`;if(t.hasClassOrSuperclass(J.ClassName))return`uint64:${BigInt(t.valueOf().toFixed())}`;if(t.hasClassOrSuperclass(Wt.ClassName))return`string:${t.valueOf()}`;if(t.hasClassOrSuperclass(ft.ClassName))return`bool:${t.valueOf()}`;if(t.hasClassOrSuperclass(pt.ClassName))return`address:${t.valueOf().bech32()}`;if(t.hasClassOrSuperclass(q.ClassName))return`token:${t.valueOf()}`;if(t.hasClassOrSuperclass(yt.ClassName))return`hex:${t.valueOf().toString("hex")}`;if(t.hasClassOrSuperclass(mt.ClassName))return`codemeta:${t.valueOf().toBuffer().toString("hex")}`;if(t.getType().getName()==="EsdtTokenPayment"){let e=t.getFieldValue("token_identifier").valueOf(),r=t.getFieldValue("token_nonce").valueOf(),n=t.getFieldValue("amount").valueOf();return`esdt:${e}|${r}|${n}`}throw new Error(`WarpArgSerializer (typedToString): Unsupported input type: ${t.getClassName()}`)}typedToNative(t){let e=this.typedToString(t);return this.coreSerializer.stringToNative(e)}nativeToTyped(t,e){let r=this.coreSerializer.nativeToString(t,e);return this.stringToTyped(r)}nativeToType(t){if(t.startsWith("composite")){let e=t.match(/\(([^)]+)\)/)?.[1];return new ht(...e.split(C.ArgCompositeSeparator).map(r=>this.nativeToType(r)))}if(t==="string")return new Ct;if(t==="uint8")return new Bt;if(t==="uint16")return new At;if(t==="uint32")return new vt;if(t==="uint64")return new K;if(t==="biguint")return new L;if(t==="bool")return new lt;if(t==="address")return new ut;if(t==="token")return new G;if(t==="hex")return new gt;if(t==="codemeta")return new dt;if(t==="esdt"||t==="nft")return new bt("EsdtTokenPayment",[new z("token_identifier","",new G),new z("token_nonce","",new K),new z("amount","",new L)]);throw new Error(`WarpArgSerializer (nativeToType): Unsupported input type: ${t}`)}stringToTyped(t){let[e,r]=t.split(/:(.*)/,2);if(e==="null"||e===null)return new T;if(e==="option"){let n=this.stringToTyped(r);return n instanceof T?j.newMissingTyped(n.getType()):j.newProvided(n)}if(e==="optional"){let n=this.stringToTyped(r);return n instanceof T?D.newMissing():new D(n.getType(),n)}if(e==="list"){let[n,s]=r.split(St,2),a=s.split(",").map(u=>this.stringToTyped(`${n}:${u}`));return new Tt(this.nativeToType(n),a)}if(e==="variadic"){let[n,s]=r.split(St,2),a=s.split(",").map(u=>this.stringToTyped(`${n}:${u}`));return new Rt(new Et(this.nativeToType(n)),a)}if(e.startsWith("composite")){let n=e.match(/\(([^)]+)\)/)?.[1],s=r.split(C.ArgCompositeSeparator),o=n.split(C.ArgCompositeSeparator),a=s.map((c,p)=>this.stringToTyped(`${o[p]}:${c}`)),u=a.map(c=>c.getType());return new wt(new ht(...u),a)}if(e==="string")return r?Wt.fromUTF8(r):new T;if(e==="uint8")return r?new Vt(Number(r)):new T;if(e==="uint16")return r?new It(Number(r)):new T;if(e==="uint32")return r?new xt(Number(r)):new T;if(e==="uint64")return r?new J(BigInt(r)):new T;if(e==="biguint")return r?new Q(BigInt(r)):new T;if(e==="bool")return r?new ft(typeof r=="boolean"?r:r==="true"):new T;if(e==="address")return r?new pt(Gt.newFromBech32(r)):new T;if(e==="token")return r?new q(r):new T;if(e==="hex")return r?yt.fromHex(r):new T;if(e==="codemeta")return new mt(qt.newFromBytes(Uint8Array.from(Buffer.from(r,"hex"))));if(e==="esdt"){let n=r.split(C.ArgCompositeSeparator);return new Yt(this.nativeToType("esdt"),[new H(new q(n[0]),"token_identifier"),new H(new J(BigInt(n[1])),"token_nonce"),new H(new Q(BigInt(n[2])),"amount")])}throw new Error(`WarpArgSerializer (stringToTyped): Unsupported input type: ${e}`)}typeToString(t){if(t instanceof Xt)return"option:"+this.typeToString(t.getFirstTypeParameter());if(t instanceof Jt)return"optional:"+this.typeToString(t.getFirstTypeParameter());if(t instanceof Kt)return"list:"+this.typeToString(t.getFirstTypeParameter());if(t instanceof Et)return"variadic:"+this.typeToString(t.getFirstTypeParameter());if(t instanceof Ct)return"string";if(t instanceof Bt)return"uint8";if(t instanceof At)return"uint16";if(t instanceof vt)return"uint32";if(t instanceof K)return"uint64";if(t instanceof L)return"biguint";if(t instanceof lt)return"bool";if(t instanceof ut)return"address";if(t instanceof G)return"token";if(t instanceof gt)return"hex";if(t instanceof dt)return"codemeta";if(t instanceof bt&&t.getClassName()==="EsdtTokenPayment")return"esdt";throw new Error(`WarpArgSerializer (typeToString): Unsupported input type: ${t.getClassName()}`)}};var V=class{constructor(t){this.config=t;this.abi=new B(t),this.serializer=new x,this.cache=new se(t.cache?.type)}async getTransactionExecutionResults(t,e,r){let n=this.cache.get(oe.WarpExecutable(this.config.env,t.meta?.hash||"",e))??[],s=await this.extractContractResults(t,e,r,n),o=ae(this.config,t,e,s),a=ne(t,s.results);return{success:r.status.isSuccessful(),warp:t,action:e,user:this.config.user?.wallet||null,txHash:r.hash,next:o,values:s.values,results:s.results,messages:a}}async extractContractResults(t,e,r,n){let s=ie(t,e),o=[],a={};if(!t.results||s.type!=="contract")return{values:o,results:a};if(!Object.values(t.results).some(w=>w.includes("out")||w.includes("event"))){for(let[w,f]of Object.entries(t.results))a[w]=f;return{values:o,results:await U(t,a,e,n)}}let c=await this.abi.getAbiForAction(s),p=new re({abi:c}),b=new ee({abi:c}).parseExecute({transactionOnNetwork:r,function:s.func||void 0});for(let[w,f]of Object.entries(t.results)){if(f.startsWith(Pt.Transform.Prefix))continue;if(f.startsWith("input.")){a[w]=f;continue}let A=Ft(f);if(A!==null&&A!==e){a[w]=null;continue}let[d,I,W]=f.split(".");if(d==="event"){if(!I||isNaN(Number(W)))continue;let P=Number(W),y=te(r,I),R=p.parseEvents({events:y})[0],_=Object.values(R)[P]||null;o.push(_),a[w]=_&&_.valueOf()}else if(d==="out"||d.startsWith("out[")){if(!I)continue;let P=Number(I),y=b.values[P-1]||null;W&&(y=y[W]||null),y&&typeof y=="object"&&(y="toFixed"in y?y.toFixed():y.valueOf()),o.push(y),a[w]=y&&y.valueOf()}else a[w]=f}return{values:o,results:await U(t,a,e,n)}}async extractQueryResults(t,e,r,n){let s=e.map(c=>this.serializer.typedToString(c)),o=e.map(c=>this.serializer.typedToNative(c)[1]),a={};if(!t.results)return{values:s,results:a};let u=c=>{let p=c.split(".").slice(1).map(b=>parseInt(b)-1);if(p.length===0)return;let l=o[p[0]];for(let b=1;b<p.length;b++){if(l==null)return;l=l[p[b]]}return l};for(let[c,p]of Object.entries(t.results)){if(p.startsWith(Pt.Transform.Prefix))continue;let l=Ft(p);if(l!==null&&l!==r){a[c]=null;continue}p.startsWith("out.")||p==="out"||p.startsWith("out[")?a[c]=u(p)||null:a[c]=p}return{values:s,results:await U(t,a,r,n)}}async resolveWarpResultsRecursively(t){let e=t.warp,r=t.entryActionIndex,n=t.executor,s=t.inputs,o=t.meta,a=new Map,u=new Set,c=this;async function p(f,A=[]){if(a.has(f))return a.get(f);if(u.has(f))throw new Error(`Circular dependency detected at action ${f}`);u.add(f);let d=e.actions[f-1];if(!d)throw new Error(`Action ${f} not found`);let I;if(d.type==="query")I=await n.executeQuery(e,f,A);else if(d.type==="collect")I=await n.executeCollect(e,f,A,o);else throw new Error(`Unsupported or interactive action type: ${d.type}`);if(a.set(f,I),e.results)for(let W of Object.values(e.results)){let y=String(W).match(/^out\[(\d+)\]/);if(y){let R=parseInt(y[1],10);R!==f&&!a.has(R)&&await p(R)}}return u.delete(f),I}await p(r,s);let l={};for(let f of a.values())for(let[A,d]of Object.entries(f.results))d!==null?l[A]=d:A in l||(l[A]=null);let b=await U(e,l,r,s);return{...a.get(r),action:r,results:b}}};var m=class i{constructor(t){this.config=t;this.serializer=new x,this.abi=new B(this.config),this.results=new V(this.config)}async createTransaction(t){let e=X(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){if(!this.config.user?.wallet)throw new Error("WarpMultiversxExecutor: createTransfer - user address not set");let e=S.newFromBech32(this.config.user.wallet),r=new _t({chainID:t.chain.chainId}),n=t.data?Buffer.from(this.serializer.stringToTyped(t.data).valueOf()):null;return new ge({config:r}).createTransactionForTransfer(e,{receiver:S.newFromBech32(t.destination),nativeAmount:t.value,data:n?new Uint8Array(n):void 0})}async createContractCallTransaction(t){if(!this.config.user?.wallet)throw new Error("WarpMultiversxExecutor: createContractCall - user address not set");let e=X(t.warp,t.action),r=S.newFromBech32(this.config.user.wallet),n=t.args.map(o=>this.serializer.stringToTyped(o)),s=new _t({chainID:t.chain.chainId});return new le({config:s}).createTransactionForExecute(r,{contract:S.newFromBech32(t.destination),function:"func"in e&&e.func||"",gasLimit:"gasLimit"in e?BigInt(e.gasLimit||0):0n,arguments:n,nativeTransferAmount:t.value})}async executeQuery(t){let e=X(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(W=>this.serializer.stringToTyped(W)),s=i.getChainEntrypoint(t.chain,this.config.env),o=S.newFromBech32(t.destination),a=s.createSmartContractController(r),u=a.createQuery({contract:o,function:e.func||"",arguments:n}),c=await a.runQuery(u),p=c.returnCode==="ok",l=new ce,b=r.getEndpoint(c.function||e.func||""),w=(c.returnDataParts||[]).map(W=>Buffer.from(W)),f=l.buffersToValues(w,b.output),{values:A,results:d}=await this.results.extractQueryResults(t.warp,f,t.action,t.resolvedInputs),I=de(this.config,t.warp,t.action,d);return{success:p,warp:t.warp,action:t.action,user:this.config.user?.wallet||null,txHash:null,next:I,values:A,results:d,messages:ye(t.warp,d)}}static getChainEntrypoint(t,e){let r="warp-sdk",n="api";return e==="devnet"?new ue(t.apiUrl,n,r):e==="testnet"?new fe(t.apiUrl,n,r):new pe(t.apiUrl,n,r)}};var N=class{constructor(t){this.config=t,this.cache=new Te(t.cache?.type),this.core=new we(t)}createInscriptionTransaction(t){if(!this.config.user?.wallet)throw new Error("WarpBuilder: user address not set");let e=Ut(this.config),r=new me({chainID:e.chainId}),n=new he({config:r}),s=Ot.newFromBech32(this.config.user.wallet),o=JSON.stringify(t),a=n.createTransactionForTransfer(s,{receiver:Ot.newFromBech32(this.config.user.wallet),nativeAmount:BigInt(0),data:Uint8Array.from(Buffer.from(o))});return a.gasLimit=a.gasLimit+BigInt(2e6),a}async createFromTransaction(t,e=!1){let r=await this.core.createFromRaw(t.data.toString(),e);return r.meta={hash:t.hash,creator:t.sender.toBech32(),createdAt:new Date(t.timestamp*1e3).toISOString()},r}async createFromTransactionHash(t,e){let r=Ce.Warp(this.config.env,t);if(e){let a=this.cache.get(r);if(a)return Nt.info(`WarpBuilder (createFromTransactionHash): Warp found in cache: ${t}`),a}let n=Ut(this.config),o=m.getChainEntrypoint(n,this.config.env).createNetworkProvider();try{let a=await o.getTransaction(t),u=await this.createFromTransaction(a);return e&&e.ttl&&u&&this.cache.set(r,u,e.ttl),u}catch(a){return Nt.error("WarpBuilder: Error creating from transaction hash",a),null}}};import{AbiRegistry as Ht,Address as h,AddressValue as nt,BytesValue as g,SmartContractTransactionsFactory as Qe,TransactionsFactoryConfig as He}from"@multiversx/sdk-core";import{getMainChainInfo as at,toTypedChainInfo as zt,WarpCache as ze,WarpCacheKey as E,WarpConfig as De,WarpLogger as F}from"@vleap/warps-core";var Y={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 k=i=>({hash:i.hash.toString("hex"),alias:i.alias?.toString()||null,trust:i.trust.toString(),owner:i.owner.toString(),createdAt:i.created_at.toNumber(),upgradedAt:i.upgraded_at?.toNumber(),brand:i.brand?.toString("hex")||null,upgrade:i.upgrade?.toString("hex")||null}),kt=i=>({unitPrice:BigInt(i.unit_price.toString()),admins:i.admins.map(t=>t.toBech32())});import{Address as be,AddressValue as Ae,BigUIntType as Ie,BigUIntValue as $t,BooleanValue as ve,BytesValue as xe,CodeMetadata as Be,CodeMetadataValue as Ve,CompositeType as Ee,CompositeValue as Re,Field as Z,FieldDefinition as tt,List as Se,NothingValue as Fe,OptionalValue as et,OptionValue as rt,StringValue as Pe,Struct as _e,StructType as Oe,TokenIdentifierType as Ue,TokenIdentifierValue as Mt,U16Value as Ne,U32Value as ke,U64Type as $e,U64Value as Lt,U8Value as Me,VariadicValue as Le}from"@multiversx/sdk-core";var dn=(i,t)=>i?rt.newProvided(i):t?rt.newMissingTyped(t):rt.newMissing(),mn=(i,t)=>i?new et(i.getType(),i):t?new et(t):et.newMissing(),hn=i=>{if(i.length===0)throw new Error("Cannot create a list from an empty array");let t=i[0].getType();return new Se(t,i)},wn=i=>Le.fromItems(...i),Tn=i=>{let t=i.map(e=>e.getType());return new Re(new Ee(...t),i)},v=i=>Pe.fromUTF8(i),Cn=i=>new Me(i),Wn=i=>new Ne(i),Qt=i=>new ke(i),bn=i=>new Lt(i),An=i=>new $t(BigInt(i)),In=i=>new ve(i),vn=i=>new Ae(be.newFromBech32(i)),xn=i=>new Mt(i),Bn=i=>xe.fromHex(i),Vn=i=>new _e(new Oe("EsdtTokenPayment",[new tt("token_identifier","",new Ue),new tt("token_nonce","",new $e),new tt("amount","",new Ie)]),[new Z(new Mt(i.token.identifier),"token_identifier"),new Z(new Lt(BigInt(i.token.nonce)),"token_nonce"),new Z(new $t(BigInt(i.amount)),"amount")]),En=i=>new Ve(Be.newFromBytes(Uint8Array.from(Buffer.from(i,"hex")))),Rn=()=>new Fe;var $=class{constructor(t){this.config=t,this.cache=new ze(t.cache?.type),this.registryConfig={unitPrice:BigInt(0),admins:[]}}async init(){await this.loadRegistryConfigs()}createWarpRegisterTransaction(t,e,r){if(this.registryConfig.unitPrice===BigInt(0))throw new Error("WarpRegistry: config not loaded. forgot to call init()?");if(!this.config.user?.wallet)throw new Error("WarpRegistry: user address not set");let n=h.newFromBech32(this.config.user.wallet),s=()=>this.isCurrentUserAdmin()?BigInt(0):e&&r?this.registryConfig.unitPrice*BigInt(3):e?this.registryConfig.unitPrice*BigInt(2):this.registryConfig.unitPrice,o=()=>e&&r?[g.fromHex(t),g.fromUTF8(e),g.fromHex(r)]:e?[g.fromHex(t),g.fromUTF8(e)]:[g.fromHex(t)];return this.getFactory().createTransactionForExecute(n,{contract:this.getRegistryContractAddress(),function:"registerWarp",gasLimit:BigInt(1e7),nativeTransferAmount:s(),arguments:o()})}createWarpUnregisterTransaction(t){if(!this.config.user?.wallet)throw new Error("WarpRegistry: user address not set");let e=h.newFromBech32(this.config.user.wallet);return this.getFactory().createTransactionForExecute(e,{contract:this.getRegistryContractAddress(),function:"unregisterWarp",gasLimit:BigInt(1e7),arguments:[g.fromHex(t)]})}createWarpUpgradeTransaction(t,e){if(this.registryConfig.unitPrice===BigInt(0))throw new Error("WarpRegistry: config not loaded. forgot to call init()?");if(!this.config.user?.wallet)throw new Error("WarpRegistry: user address not set");let r=h.newFromBech32(this.config.user.wallet);return this.getFactory().createTransactionForExecute(r,{contract:this.getRegistryContractAddress(),function:"upgradeWarp",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[g.fromUTF8(t),g.fromHex(e)]})}createWarpAliasSetTransaction(t,e){if(!this.config.user?.wallet)throw new Error("WarpRegistry: user address not set");let r=h.newFromBech32(this.config.user.wallet);return this.getFactory().createTransactionForExecute(r,{contract:this.getRegistryContractAddress(),function:"setWarpAlias",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[g.fromHex(t),g.fromUTF8(e)]})}createWarpVerifyTransaction(t){if(!this.config.user?.wallet)throw new Error("WarpRegistry: user address not set");let e=h.newFromBech32(this.config.user.wallet);return this.getFactory().createTransactionForExecute(e,{contract:this.getRegistryContractAddress(),function:"verifyWarp",gasLimit:BigInt(1e7),arguments:[g.fromHex(t)]})}createWarpTransferOwnershipTransaction(t,e){if(!this.config.user?.wallet)throw new Error("WarpRegistry: user address not set");let r=h.newFromBech32(this.config.user.wallet);return this.getFactory().createTransactionForExecute(r,{contract:this.getRegistryContractAddress(),function:"transferOwnership",gasLimit:BigInt(1e7),arguments:[g.fromHex(t),new nt(new h(e))]})}createBrandRegisterTransaction(t){if(this.registryConfig.unitPrice===BigInt(0))throw new Error("WarpRegistry: config not loaded. forgot to call init()?");if(!this.config.user?.wallet)throw new Error("WarpRegistry: user address not set");let e=h.newFromBech32(this.config.user.wallet);return this.getFactory().createTransactionForExecute(e,{contract:this.getRegistryContractAddress(),function:"registerBrand",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[g.fromHex(t)]})}createWarpBrandingTransaction(t,e){if(!this.config.user?.wallet)throw new Error("WarpRegistry: user address not set");let r=h.newFromBech32(this.config.user.wallet);return this.getFactory().createTransactionForExecute(r,{contract:this.getRegistryContractAddress(),function:"brandWarp",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[g.fromHex(t),g.fromHex(e)]})}async getInfoByAlias(t,e){try{let r=E.RegistryInfo(this.config.env,t),n=e?this.cache.get(r):null;if(n)return F.info(`WarpRegistry (getInfoByAlias): RegistryInfo found in cache: ${t}`),n;let s=this.getRegistryContractAddress(),o=this.getController(),a=o.createQuery({contract:s,function:"getInfoByAlias",arguments:[g.fromUTF8(t)]}),u=await o.runQuery(a),[c]=o.parseQueryResponse(u),p=c?k(c):null,l=p?.brand?await this.fetchBrand(p.brand):null;return e&&e.ttl&&this.cache.set(r,{registryInfo:p,brand:l},e.ttl),{registryInfo:p,brand:l}}catch{return{registryInfo:null,brand:null}}}async getInfoByHash(t,e){try{let r=E.RegistryInfo(this.config.env,t);if(e){let l=this.cache.get(r);if(l)return F.info(`WarpRegistry (getInfoByHash): RegistryInfo found in cache: ${t}`),l}let n=this.getRegistryContractAddress(),s=this.getController(),o=s.createQuery({contract:n,function:"getInfoByHash",arguments:[g.fromHex(t)]}),a=await s.runQuery(o),[u]=s.parseQueryResponse(a),c=u?k(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.config.user?.wallet;if(!e)throw new Error("WarpRegistry: user address not set");let r=this.getRegistryContractAddress(),n=this.getController(),s=n.createQuery({contract:r,function:"getUserWarps",arguments:[new nt(new h(e))]}),o=await n.runQuery(s),[a]=n.parseQueryResponse(o);return a.map(k)}catch{return[]}}async getUserBrands(t){try{let e=t||this.config.user?.wallet;if(!e)throw new Error("WarpRegistry: user address not set");let r=this.getRegistryContractAddress(),n=this.getController(),s=n.createQuery({contract:r,function:"getUserBrands",arguments:[new nt(new h(e))]}),o=await n.runQuery(s),[a]=n.parseQueryResponse(o),u=a.map(l=>l.toString("hex")),c={ttl:365*24*60*60};return(await Promise.all(u.map(l=>this.fetchBrand(l,c)))).filter(l=>l!==null)}catch{return[]}}async getChainInfos(t){let e=E.ChainInfos(this.config.env);if(t&&t.ttl){let c=this.cache.get(e);if(c)return F.info("WarpRegistry (getChainInfos): ChainInfos found in cache"),c}let r=this.getRegistryContractAddress(),n=this.getController(),s=n.createQuery({contract:r,function:"getChains",arguments:[]}),o=await n.runQuery(s),[a]=n.parseQueryResponse(o),u=a.map(zt);if(t&&t.ttl){for(let c of u)this.cache.set(E.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=E.ChainInfo(this.config.env,t),n=e?this.cache.get(r):null;if(n)return F.info(`WarpRegistry (getChainInfo): ChainInfo found in cache: ${t}`),n;let s=this.getRegistryContractAddress(),o=this.getController(),a=o.createQuery({contract:s,function:"getChain",arguments:[g.fromUTF8(t)]}),u=await o.runQuery(a),[c]=o.parseQueryResponse(u),p=c?zt(c):null;return e&&e.ttl&&p&&this.cache.set(r,p,e.ttl),p}catch{return null}}async setChain(t){if(!this.config.user?.wallet)throw new Error("WarpRegistry: user address not set");let e=h.newFromBech32(this.config.user.wallet);return this.getFactory().createTransactionForExecute(e,{contract:this.getRegistryContractAddress(),function:"setChain",gasLimit:BigInt(1e7),arguments:[v(t.name),v(t.displayName),v(t.chainId),Qt(t.blockTime),v(t.addressHrp),v(t.apiUrl),v(t.explorerUrl),v(t.nativeToken)]})}async removeChain(t){if(!this.config.user?.wallet)throw new Error("WarpRegistry: user address not set");let e=h.newFromBech32(this.config.user.wallet);return this.getFactory().createTransactionForExecute(e,{contract:this.getRegistryContractAddress(),function:"removeChain",gasLimit:BigInt(1e7),arguments:[v(t)]})}async fetchBrand(t,e){let r=E.Brand(this.config.env,t),n=e?this.cache.get(r):null;if(n)return F.info(`WarpRegistry (fetchBrand): Brand found in cache: ${t}`),n;let s=at(this.config),a=m.getChainEntrypoint(s,this.config.env).createNetworkProvider();try{let u=await a.getTransaction(t),c=JSON.parse(u.data.toString());return c.meta={hash:u.hash,creator:u.sender.bech32(),createdAt:new Date(u.timestamp*1e3).toISOString()},e&&e.ttl&&this.cache.set(r,c,e.ttl),c}catch{return null}}getRegistryContractAddress(){return h.newFromBech32(this.config.registry?.contract||De.Registry.Contract(this.config.env))}async loadRegistryConfigs(){let t=this.getRegistryContractAddress(),e=this.getController(),[r]=await e.query({contract:t,function:"getConfig",arguments:[]}),n=r?kt(r):null;this.registryConfig=n||{unitPrice:BigInt(0),admins:[]}}getFactory(){let t=at(this.config),e=new He({chainID:t.chainId}),r=Ht.create(Y);return new Qe({config:e,abi:r})}getController(){let t=at(this.config),e=m.getChainEntrypoint(t,this.config.env),r=Ht.create(Y);return e.createSmartContractController(r)}isCurrentUserAdmin(){return!!this.config.user?.wallet&&this.registryConfig.admins.includes(this.config.user.wallet)}};var ta=()=>({chain:"multiversx",builder:N,executor:m,results:V,serializer:x,registry:$});export{B as WarpMultiversxAbi,N as WarpMultiversxBuilder,je as WarpMultiversxConstants,O as WarpMultiversxContractLoader,m as WarpMultiversxExecutor,$ as WarpMultiversxRegistry,V as WarpMultiversxResults,x as WarpMultiversxSerializer,vn as address_value,An as biguint_value,In as boolean_value,En as codemeta_value,Tn as composite_value,Vn as esdt_value,ta as getMultiversxAdapter,Bn as hex_value,hn as list_value,Rn as nothing_value,dn as option_value,mn as optional_value,v as string_value,xn as token_value,Wn as u16_value,Qt as u32_value,bn as u64_value,Cn as u8_value,wn as variadic_value};
1
+ import{AbiRegistry as se}from"@multiversx/sdk-core";import{WarpCache as Zt,WarpCacheKey as er,WarpConstants as ze,WarpLogger as Qe}from"@vleap/warps";import{WarpLogger as He}from"@vleap/warps";import{Address as N,ArgSerializer as _t,DevnetEntrypoint as Ot,MainnetEntrypoint as Mt,SmartContractTransactionsFactory as $t,TestnetEntrypoint as Lt,Token as qt,TokenComputer as Dt,TokenTransfer as Ht,TransactionsFactoryConfig as qe,TransferTransactionsFactory as zt,UserSecretKey as Qt,UserSigner as jt}from"@multiversx/sdk-core";import{applyResultsToMessages as Gt,findKnownTokenById as Kt,getNextInfo as Jt,getProviderUrl as Xt,getWarpActionByIndex as ie,shiftBigintBy as Yt,WarpConstants as De}from"@vleap/warps";import{findEventsByFirstTopic as ut,SmartContractTransactionsOutcomeParser as lt,TransactionEventsParser as mt}from"@multiversx/sdk-core";import{applyResultsToMessages as ft,evaluateResultsCommon as U,findWarpExecutableAction as Ue,getNextInfo as dt,parseResultsOutIndex as ke,WarpCache as gt,WarpCacheKey as yt,WarpConstants as _e}from"@vleap/warps";import{Address as nt,AddressType as me,AddressValue as fe,BigUIntType as z,BigUIntValue as Q,BooleanType as de,BooleanValue as ge,BytesType as ye,BytesValue as he,CodeMetadata as at,CodeMetadataType as we,CodeMetadataValue as We,CompositeType as xe,CompositeValue as Te,Field as j,FieldDefinition as G,List as Ce,ListType as it,NothingValue as T,OptionalType as st,OptionalValue as K,OptionType as ot,OptionValue as J,StringType as ve,StringValue as be,Struct as ct,StructType as Ae,TokenIdentifierType as X,TokenIdentifierValue as Y,U16Type as Ee,U16Value as Be,U32Type as Ie,U32Value as Ve,U64Type as Z,U64Value as ee,U8Type as Se,U8Value as Fe,VariadicType as Ne,VariadicValue as Re}from"@multiversx/sdk-core";import{WarpConstants as C,WarpSerializer as pt}from"@vleap/warps";var Pe=new RegExp(`${C.ArgParamsSeparator}(.*)`),E=class{constructor(){this.coreSerializer=new pt}typedToString(e){if(e.hasClassOrSuperclass(J.ClassName))return e.isSet()?`option:${this.typedToString(e.getTypedValue())}`:"option:null";if(e.hasClassOrSuperclass(K.ClassName))return e.isSet()?`optional:${this.typedToString(e.getTypedValue())}`:"optional:null";if(e.hasClassOrSuperclass(Ce.ClassName)){let t=e.getItems(),n=t.map(o=>this.typedToString(o).split(C.ArgParamsSeparator)[0])[0],a=t.map(o=>this.typedToString(o).split(C.ArgParamsSeparator)[1]);return`list:${n}:${a.join(",")}`}if(e.hasClassOrSuperclass(Re.ClassName)){let t=e.getItems(),n=t.map(o=>this.typedToString(o).split(C.ArgParamsSeparator)[0])[0],a=t.map(o=>this.typedToString(o).split(C.ArgParamsSeparator)[1]);return`variadic:${n}:${a.join(",")}`}if(e.hasClassOrSuperclass(Te.ClassName)){let t=e.getItems(),r=t.map(i=>this.typedToString(i).split(C.ArgParamsSeparator)[0]),n=t.map(i=>this.typedToString(i).split(C.ArgParamsSeparator)[1]),a=r.join(C.ArgCompositeSeparator),o=n.join(C.ArgCompositeSeparator);return`composite(${a}):${o}`}if(e.hasClassOrSuperclass(Q.ClassName)||e.getType().getName()==="BigUint")return`biguint:${BigInt(e.valueOf().toFixed())}`;if(e.hasClassOrSuperclass(Fe.ClassName))return`uint8:${e.valueOf().toNumber()}`;if(e.hasClassOrSuperclass(Be.ClassName))return`uint16:${e.valueOf().toNumber()}`;if(e.hasClassOrSuperclass(Ve.ClassName))return`uint32:${e.valueOf().toNumber()}`;if(e.hasClassOrSuperclass(ee.ClassName))return`uint64:${BigInt(e.valueOf().toFixed())}`;if(e.hasClassOrSuperclass(be.ClassName))return`string:${e.valueOf()}`;if(e.hasClassOrSuperclass(ge.ClassName))return`bool:${e.valueOf()}`;if(e.hasClassOrSuperclass(fe.ClassName))return`address:${e.valueOf().toBech32()}`;if(e.hasClassOrSuperclass(Y.ClassName))return`token:${e.valueOf()}`;if(e.hasClassOrSuperclass(he.ClassName))return`hex:${e.valueOf().toString("hex")}`;if(e.hasClassOrSuperclass(We.ClassName))return`codemeta:${e.valueOf().toString()}`;if(e.getType().getName()==="EsdtTokenPayment"){let t=e.getFieldValue("token_identifier").valueOf(),r=e.getFieldValue("token_nonce").valueOf(),n=e.getFieldValue("amount").valueOf();return`asset:${t}|${r}|${n}`}throw new Error(`WarpArgSerializer (typedToString): Unsupported input type: ${e.getClassName()}`)}typedToNative(e){let t=this.typedToString(e);return this.coreSerializer.stringToNative(t)}nativeToTyped(e,t){let r=this.coreSerializer.nativeToString(e,t);return this.stringToTyped(r)}nativeToType(e){if(e.startsWith("composite")){let t=e.match(/\(([^)]+)\)/)?.[1];return new xe(...t.split(C.ArgCompositeSeparator).map(r=>this.nativeToType(r)))}if(e==="string")return new ve;if(e==="uint8")return new Se;if(e==="uint16")return new Ee;if(e==="uint32")return new Ie;if(e==="uint64")return new Z;if(e==="biguint")return new z;if(e==="bool")return new de;if(e==="address")return new me;if(e==="token")return new X;if(e==="hex")return new ye;if(e==="codemeta")return new we;if(e==="asset")return new Ae("EsdtTokenPayment",[new G("token_identifier","",new X),new G("token_nonce","",new Z),new G("amount","",new z)]);throw new Error(`WarpArgSerializer (nativeToType): Unsupported input type: ${e}`)}stringToTyped(e){let[t,r]=e.split(/:(.*)/,2);if(t==="null"||t===null)return new T;if(t==="option"){let n=this.stringToTyped(r);return n instanceof T?J.newMissingTyped(n.getType()):J.newProvided(n)}if(t==="optional"){let n=this.stringToTyped(r);return n instanceof T?K.newMissing():new K(n.getType(),n)}if(t==="list"){let[n,a]=r.split(Pe,2),i=a.split(",").map(c=>this.stringToTyped(`${n}:${c}`));return new Ce(this.nativeToType(n),i)}if(t==="variadic"){let[n,a]=r.split(Pe,2),i=a.split(",").map(c=>this.stringToTyped(`${n}:${c}`));return new Re(new Ne(this.nativeToType(n)),i)}if(t.startsWith("composite")){let n=t.match(/\(([^)]+)\)/)?.[1],a=r.split(C.ArgCompositeSeparator),o=n.split(C.ArgCompositeSeparator),i=a.map((p,u)=>this.stringToTyped(`${o[u]}:${p}`)),c=i.map(p=>p.getType());return new Te(new xe(...c),i)}if(t==="string")return r?be.fromUTF8(r):new T;if(t==="uint8")return r?new Fe(Number(r)):new T;if(t==="uint16")return r?new Be(Number(r)):new T;if(t==="uint32")return r?new Ve(Number(r)):new T;if(t==="uint64")return r?new ee(BigInt(r)):new T;if(t==="biguint")return r?new Q(BigInt(r)):new T;if(t==="bool")return r?new ge(typeof r=="boolean"?r:r==="true"):new T;if(t==="address")return r?new fe(nt.newFromBech32(r)):new T;if(t==="token")return r?new Y(r):new T;if(t==="hex")return r?he.fromHex(r):new T;if(t==="codemeta")return new We(at.newFromBytes(Uint8Array.from(Buffer.from(r,"hex"))));if(t==="asset"){let n=r.split(C.ArgCompositeSeparator);return new ct(this.nativeToType("asset"),[new j(new Y(n[0]),"token_identifier"),new j(new ee(BigInt(n[1])),"token_nonce"),new j(new Q(BigInt(n[2])),"amount")])}throw new Error(`WarpArgSerializer (stringToTyped): Unsupported input type: ${t}`)}typeToString(e){if(e instanceof ot)return"option:"+this.typeToString(e.getFirstTypeParameter());if(e instanceof st)return"optional:"+this.typeToString(e.getFirstTypeParameter());if(e instanceof it)return"list:"+this.typeToString(e.getFirstTypeParameter());if(e instanceof Ne)return"variadic:"+this.typeToString(e.getFirstTypeParameter());if(e instanceof ve)return"string";if(e instanceof Se)return"uint8";if(e instanceof Ee)return"uint16";if(e instanceof Ie)return"uint32";if(e instanceof Z)return"uint64";if(e instanceof z)return"biguint";if(e instanceof de)return"bool";if(e instanceof me)return"address";if(e instanceof X)return"token";if(e instanceof ye)return"hex";if(e instanceof we)return"codemeta";if(e instanceof Ae&&e.getClassName()==="EsdtTokenPayment")return"asset";throw new Error(`WarpArgSerializer (typeToString): Unsupported input type: ${e.getClassName()}`)}};var V=class{constructor(e,t){this.config=e;this.chain=t;this.abi=new B(e,t),this.serializer=new E,this.cache=new gt(e.cache?.type)}async getTransactionExecutionResults(e,t){let{actionIndex:r}=Ue(e),n=this.cache.get(yt.WarpExecutable(this.config.env,e.meta?.hash||"",r))??[],a=await this.extractContractResults(e,t,n),o=dt(this.config,[],e,r,a),i=ft(e,a.results);return{success:t.status.isSuccessful(),warp:e,action:r,user:this.config.user?.wallets?.[this.chain.name]||null,txHash:t.hash,next:o,values:a.values,results:a.results,messages:i}}async extractContractResults(e,t,r){let{action:n,actionIndex:a}=Ue(e),o=[],i={};if(!e.results||n.type!=="contract")return{values:o,results:i};if(!Object.values(e.results).some(w=>w.includes("out")||w.includes("event"))){for(let[w,m]of Object.entries(e.results))i[w]=m;return{values:o,results:await U(e,i,a,r,this.config.transform?.runner)}}let p=await this.abi.getAbiForAction(n),u=new mt({abi:p}),y=new lt({abi:p}).parseExecute({transactionOnNetwork:t,function:n.func||void 0});for(let[w,m]of Object.entries(e.results)){if(m.startsWith(_e.Transform.Prefix))continue;if(m.startsWith("input.")){i[w]=m;continue}let v=ke(m);if(v!==null&&v!==a){i[w]=null;continue}let[W,A,b]=m.split(".");if(W==="event"){if(!A||isNaN(Number(b)))continue;let R=Number(b),h=ut(t,A),F=u.parseEvents({events:h})[0],P=Object.values(F)[R]||null;o.push(P),i[w]=P&&P.valueOf()}else if(W==="out"||W.startsWith("out[")){if(!A)continue;let R=Number(A),h=y.values[R-1]||null;b&&(h=h[b]||null),h&&typeof h=="object"&&(h="toFixed"in h?h.toFixed():h.valueOf()),o.push(h),i[w]=h&&h.valueOf()}else i[w]=m}return{values:o,results:await U(e,i,a,r)}}async extractQueryResults(e,t,r,n){let a=t.map(p=>this.serializer.typedToString(p)),o=t.map(p=>this.serializer.typedToNative(p)[1]),i={};if(!e.results)return{values:a,results:i};let c=p=>{let u=p.split(".").slice(1).map(y=>parseInt(y)-1);if(u.length===0)return;let l=o[u[0]];for(let y=1;y<u.length;y++){if(l==null)return;l=l[u[y]]}return l};for(let[p,u]of Object.entries(e.results)){if(u.startsWith(_e.Transform.Prefix))continue;let l=ke(u);if(l!==null&&l!==r){i[p]=null;continue}u.startsWith("out.")||u==="out"||u.startsWith("out[")?i[p]=c(u)||null:i[p]=u}return{values:a,results:await U(e,i,r,n)}}async resolveWarpResultsRecursively(e){let t=e.warp,r=e.entryActionIndex,n=e.executor,a=e.inputs,o=e.meta,i=new Map,c=new Set,p=this;async function u(m,v=[]){if(i.has(m))return i.get(m);if(c.has(m))throw new Error(`Circular dependency detected at action ${m}`);c.add(m);let W=t.actions[m-1];if(!W)throw new Error(`Action ${m} not found`);let A;if(W.type==="query")A=await n.executeQuery(t,m,v);else if(W.type==="collect")A=await n.executeCollect(t,m,v,o);else throw new Error(`Unsupported or interactive action type: ${W.type}`);if(i.set(m,A),t.results)for(let b of Object.values(t.results)){let h=String(b).match(/^out\[(\d+)\]/);if(h){let F=parseInt(h[1],10);F!==m&&!i.has(F)&&await u(F)}}return c.delete(m),A}await u(r,a);let l={};for(let m of i.values())for(let[v,W]of Object.entries(m.results))W!==null?l[v]=W:v in l||(l[v]=null);let y=await U(t,l,r,a,this.config.transform?.runner);return{...i.get(r),action:r,results:y}}};import{Address as ht,AddressValue as wt,BigUIntType as Wt,BigUIntValue as Oe,BooleanValue as xt,BytesValue as Tt,CodeMetadata as Ct,CodeMetadataValue as vt,CompositeType as bt,CompositeValue as At,Field as te,FieldDefinition as re,List as Et,NothingValue as Bt,OptionalValue as ne,OptionValue as ae,StringValue as It,Struct as Vt,StructType as St,TokenIdentifierType as Ft,TokenIdentifierValue as Me,U16Value as Nt,U32Value as Rt,U64Type as Pt,U64Value as $e,U8Value as Ut,VariadicValue as kt}from"@multiversx/sdk-core";var Qr=(s,e)=>s?ae.newProvided(s):e?ae.newMissingTyped(e):ae.newMissing(),jr=(s,e)=>s?new ne(s.getType(),s):e?new ne(e):ne.newMissing(),Gr=s=>{if(s.length===0)throw new Error("Cannot create a list from an empty array");let e=s[0].getType();return new Et(e,s)},Kr=s=>kt.fromItems(...s),Jr=s=>{let e=s.map(t=>t.getType());return new At(new bt(...e),s)},Xr=s=>It.fromUTF8(s),Yr=s=>new Ut(s),Zr=s=>new Nt(s),en=s=>new Rt(s),tn=s=>new $e(s),rn=s=>new Oe(BigInt(s)),nn=s=>new xt(s),an=s=>new wt(ht.newFromBech32(s)),sn=s=>new Me(s),on=s=>Tt.fromHex(s),Le=s=>new Vt(new St("EsdtTokenPayment",[new re("token_identifier","",new Ft),new re("token_nonce","",new Pt),new re("amount","",new Wt)]),[new te(new Me(s.token.identifier),"token_identifier"),new te(new $e(BigInt(s.token.nonce)),"token_nonce"),new te(new Oe(BigInt(s.amount)),"amount")]),cn=s=>new vt(Ct.newFromBytes(Uint8Array.from(Buffer.from(s,"hex")))),pn=()=>new Bt;var d=class s{constructor(e,t){this.config=e;this.chain=t;this.serializer=new E,this.abi=new B(this.config,this.chain),this.results=new V(this.config,this.chain)}async createTransaction(e){let t=ie(e.warp,e.action),r=null;if(t.type==="transfer")r=await this.createTransferTransaction(e);else if(t.type==="contract")r=await this.createContractCallTransaction(e);else{if(t.type==="query")throw new Error("WarpMultiversxExecutor: Invalid action type for createTransactionForExecute; Use executeQuery instead");if(t.type==="collect")throw new Error("WarpMultiversxExecutor: Invalid action type for createTransactionForExecute; Use executeCollect instead")}if(!r)throw new Error(`WarpMultiversxExecutor: Invalid action type (${t.type})`);return r}async createTransferTransaction(e){let t=this.config.user?.wallets?.[e.chain.name];if(!t)throw new Error("WarpMultiversxExecutor: createTransfer - user address not set");let r=N.newFromBech32(t),n=new qe({chainID:e.chain.chainId}),a=e.data?Buffer.from(this.serializer.stringToTyped(e.data).valueOf()):null;return new zt({config:n}).createTransactionForTransfer(r,{receiver:N.newFromBech32(e.destination),nativeAmount:e.value,data:a?new Uint8Array(a):void 0})}async createContractCallTransaction(e){let t=this.config.user?.wallets?.[e.chain.name];if(!t)throw new Error("WarpMultiversxExecutor: createContractCall - user address not set");let r=ie(e.warp,e.action),n=N.newFromBech32(t),a=e.args.map(i=>this.serializer.stringToTyped(i)),o=new qe({chainID:e.chain.chainId});return new $t({config:o}).createTransactionForExecute(n,{contract:N.newFromBech32(e.destination),function:"func"in r&&r.func||"",gasLimit:"gasLimit"in r?BigInt(r.gasLimit||0):0n,arguments:a,nativeTransferAmount:e.value})}async executeQuery(e){let t=ie(e.warp,e.action);if(t.type!=="query")throw new Error(`WarpMultiversxExecutor: Invalid action type for executeQuery: ${t.type}`);let r=await this.abi.getAbiForAction(t),n=e.args.map(b=>this.serializer.stringToTyped(b)),a=s.getChainEntrypoint(e.chain,this.config.env,this.config),o=N.newFromBech32(e.destination),i=a.createSmartContractController(r),c=i.createQuery({contract:o,function:t.func||"",arguments:n}),p=await i.runQuery(c),u=p.returnCode==="ok",l=new _t,y=r.getEndpoint(p.function||t.func||""),w=(p.returnDataParts||[]).map(b=>Buffer.from(b)),m=l.buffersToValues(w,y.output),{values:v,results:W}=await this.results.extractQueryResults(e.warp,m,e.action,e.resolvedInputs),A=Jt(this.config,[],e.warp,e.action,W);return{success:u,warp:e.warp,action:e.action,user:this.config.user?.wallets?.[e.chain.name]||null,txHash:null,next:A,values:v,results:W,messages:Gt(e.warp,W)}}async preprocessInput(e,t,r,n){if(r==="asset"){let[a,o,i,c]=n.split(De.ArgCompositeSeparator);if(c)return t;let p=new qt({identifier:a,nonce:BigInt(o)});if(!new Dt().isFungible(p))return t;let y=Kt(a)?.decimals;if(y||(y=(await(await fetch(`${e.defaultApiUrl}/tokens/${a}`)).json()).decimals),!y)throw new Error(`WarpActionExecutor: Decimals not found for token ${a}`);let w=Le(new Ht({token:p,amount:Yt(i,y)}));return this.serializer.typedToString(w)+De.ArgCompositeSeparator+y}return t}static getChainEntrypoint(e,t,r){let n="warp-sdk",o=r?Xt(r,e.name,t,e.defaultApiUrl):e.defaultApiUrl;return t==="devnet"?new Ot({url:o,kind:"api",clientName:n}):t==="testnet"?new Lt({url:o,kind:"api",clientName:n}):new Mt({url:o,kind:"api",clientName:n})}async signMessage(e,t){let r=Qt.fromString(t);return(await new jt(r).sign(new Uint8Array(Buffer.from(e,"utf-8")))).toString()}};var k=class{constructor(e){this.config=e}async getContract(e,t){try{let a=await d.getChainEntrypoint(t,this.config.env).createNetworkProvider().doGetGeneric(`accounts/${e}`);return{address:e,owner:a.ownerAddress,verified:a.isVerified||!1}}catch(r){return He.error("WarpContractLoader: getContract error",r),null}}async getVerificationInfo(e,t){try{let a=await d.getChainEntrypoint(t,this.config.env).createNetworkProvider().doGetGeneric(`accounts/${e}/verification`);return{codeHash:a.codeHash,abi:a.source.abi}}catch(r){return He.error("WarpContractLoader: getVerificationInfo error",r),null}}};var B=class{constructor(e,t){this.config=e;this.chain=t;this.contractLoader=new k(this.config),this.cache=new Zt(this.config.cache?.type)}async createFromRaw(e){return JSON.parse(e)}async createFromTransaction(e){let t=await this.createFromRaw(e.data.toString());return t.meta={chain:this.chain.name,hash:e.hash,creator:e.sender.toBech32(),createdAt:new Date(e.timestamp*1e3).toISOString()},t}async createFromTransactionHash(e,t){let r=er.WarpAbi(this.config.env,e);if(t){let o=this.cache.get(r);if(o)return Qe.info(`WarpAbiBuilder (createFromTransactionHash): Warp abi found in cache: ${e}`),o}let a=d.getChainEntrypoint(this.chain,this.config.env).createNetworkProvider();try{let o=await a.getTransaction(e),i=await this.createFromTransaction(o);return t&&t.ttl&&i&&this.cache.set(r,i,t.ttl),i}catch(o){return Qe.error("WarpAbiBuilder: Error creating from transaction hash",o),null}}async getAbiForAction(e){if(e.abi)return await this.fetchAbi(e);if(!e.address)throw new Error("WarpActionExecutor: Address not found");let t=await this.contractLoader.getVerificationInfo(e.address,this.chain);if(!t)throw new Error("WarpActionExecutor: Verification info not found");return se.create(t.abi)}async fetchAbi(e){if(!e.abi)throw new Error("WarpActionExecutor: ABI not found");if(e.abi.startsWith(ze.IdentifierType.Hash)){let t=e.abi.split(ze.IdentifierParamSeparatorDefault)[1],r=await this.createFromTransactionHash(t);if(!r)throw new Error(`WarpActionExecutor: ABI not found for hash: ${e.abi}`);return se.create(r.content)}else{let r=await(await fetch(e.abi)).json();return se.create(r)}}};import{Address as je,TransactionsFactoryConfig as tr,TransferTransactionsFactory as rr}from"@multiversx/sdk-core";import{WarpBrandBuilder as nr,WarpLogger as ar}from"@vleap/warps";import{Buffer as ir}from"buffer";var _=class{constructor(e,t){this.config=e;this.chain=t;this.core=new nr(e)}async createInscriptionTransaction(e){let t=this.config.user?.wallets?.[this.chain.name];if(!t)throw new Error("BrandBuilder: user address not set");let r=new tr({chainID:this.chain.chainId}),n=new rr({config:r}),a=je.newFromBech32(t),o=JSON.stringify(e);return await n.createTransactionForNativeTokenTransfer(a,{receiver:je.newFromBech32(t),nativeAmount:BigInt(0),data:Uint8Array.from(ir.from(o))})}async createFromTransaction(e,t=!1){return await this.core.createFromRaw(e.data.toString(),t)}async createFromTransactionHash(e){let r=d.getChainEntrypoint(this.chain,this.config.env).createNetworkProvider();try{let n=await r.getTransaction(e);return this.createFromTransaction(n)}catch(n){return ar.error("BrandBuilder: Error creating from transaction hash",n),null}}};import{Address as Ge,TransactionsFactoryConfig as sr,TransferTransactionsFactory as or}from"@multiversx/sdk-core";import{WarpBuilder as Ke,WarpCache as cr,WarpCacheKey as pr,WarpLogger as Je}from"@vleap/warps";var O=class extends Ke{constructor(t,r){super(t);this.config=t;this.chain=r;this.cache=new cr(t.cache?.type),this.core=new Ke(t)}async createInscriptionTransaction(t){let r=this.config.user?.wallets?.[this.chain.name];if(!r)throw new Error("WarpBuilder: user address not set");let n=new sr({chainID:this.chain.chainId}),a=new or({config:n}),o=Ge.newFromBech32(r),i=JSON.stringify(t),c=await a.createTransactionForTransfer(o,{receiver:Ge.newFromBech32(r),nativeAmount:BigInt(0),data:Uint8Array.from(Buffer.from(i))});return c.gasLimit=c.gasLimit+BigInt(2e6),c}async createFromTransaction(t,r=!1){let n=await this.core.createFromRaw(t.data.toString(),r);return n.meta={chain:this.chain.name,hash:t.hash,creator:t.sender.toBech32(),createdAt:new Date(t.timestamp*1e3).toISOString()},n}async createFromTransactionHash(t,r){let n=pr.Warp(this.config.env,t);if(r){let i=this.cache.get(n);if(i)return Je.info(`WarpBuilder (createFromTransactionHash): Warp found in cache: ${t}`),i}let o=d.getChainEntrypoint(this.chain,this.config.env).createNetworkProvider();try{let i=await o.getTransaction(t),c=await this.createFromTransaction(i);return r&&r.ttl&&c&&this.cache.set(n,c,r.ttl),c}catch(i){return Je.error("WarpBuilder: Error creating from transaction hash",i),null}}};import{Address as Xe}from"@multiversx/sdk-core";var M=class{constructor(e,t){this.config=e;this.chain=t}async getAccount(e){let r=await d.getChainEntrypoint(this.chain,this.config.env,this.config).createNetworkProvider().getAccount(Xe.newFromBech32(e));return{address:r.address.toBech32(),balance:r.balance}}async getAccountAssets(e){return(await d.getChainEntrypoint(this.chain,this.config.env,this.config).createNetworkProvider().getFungibleTokensOfAccount(Xe.newFromBech32(e))).map(n=>({identifier:n.token.identifier,name:n.raw.name,amount:n.amount,decimals:n.raw.decimals,logoUrl:n.raw.assets?.pngUrl||""}))}};var wa={Egld:{Identifier:"EGLD",EsdtIdentifier:"EGLD-000000",DisplayName:"eGold",Decimals:18}},ur=(r=>(r.MultiversxExplorer="multiversx_explorer",r.MultiversxExplorerDevnet="multiversx_explorer_devnet",r.MultiversxExplorerTestnet="multiversx_explorer_testnet",r))(ur||{}),lr=(r=>(r.VibechainExplorer="vibechain_explorer",r.VibechainExplorerDevnet="vibechain_explorer_devnet",r.VibechainExplorerTestnet="vibechain_explorer_testnet",r))(lr||{}),Ye={multiversx:{mainnet:["multiversx_explorer"],testnet:["multiversx_explorer_testnet"],devnet:["multiversx_explorer_devnet"]},vibechain:{mainnet:["vibechain_explorer"],testnet:["vibechain_explorer_testnet"],devnet:["vibechain_explorer_devnet"]}},I={multiversx_explorer:"https://explorer.multiversx.com",multiversx_explorer_devnet:"https://devnet-explorer.multiversx.com",multiversx_explorer_testnet:"https://testnet-explorer.multiversx.com",vibechain_explorer:"https://vibeox-explorer.multiversx.com",vibechain_explorer_devnet:"https://vibeox-explorer.multiversx.com",vibechain_explorer_testnet:"https://vibeox-explorer.multiversx.com"};var $=class{constructor(e,t){this.chain=e;this.config=t}getExplorers(){let e=Ye[this.chain];if(!e)return["multiversx_explorer"];let t=e[this.config.env];return t||["multiversx_explorer"]}getPrimaryExplorer(){return this.getExplorers()[0]}getExplorerUrlByName(e){let t=this.config.preferences?.explorers?.[this.chain];if(t&&!e){let a=I[t];if(a)return a}if(e){let a=I[e];if(a)return a}let r=this.getPrimaryExplorer();return I[r]||I[r]}getAccountUrl(e,t){return`${this.getExplorerUrlByName(t)}/accounts/${e}`}getTransactionUrl(e,t){return`${this.getExplorerUrlByName(t)}/transactions/${e}`}getBlockUrl(e,t){return`${this.getExplorerUrlByName(t)}/blocks/${e}`}getAssetUrl(e,t){return`${this.getExplorerUrlByName(t)}/tokens/${e}`}getContractUrl(e,t){return`${this.getExplorerUrlByName(t)}/accounts/${e}`}getAllExplorers(){return this.getExplorers()}getExplorerByName(e){return this.getExplorers().find(r=>r.toLowerCase()===e.toLowerCase())}getAccountUrls(e){let t=this.getAllExplorers(),r={};return t.forEach(n=>{let a=I[n];a&&(r[n]=`${a}/accounts/${e}`)}),r}getTransactionUrls(e){let t=this.getAllExplorers(),r={};return t.forEach(n=>{let a=I[n];a&&(r[n]=`${a}/transactions/${e}`)}),r}};import{AbiRegistry as et,Address as f,AddressValue as ce,BytesValue as g,SmartContractTransactionsFactory as fr,TransactionsFactoryConfig as dr}from"@multiversx/sdk-core";import{WarpCache as gr,WarpCacheKey as pe,WarpLogger as ue}from"@vleap/warps";var oe={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=s=>{if(s==="devnet")return"erd1qqqqqqqqqqqqqpgqje2f99vr6r7sk54thg03c9suzcvwr4nfl3tsfkdl36";if(s==="testnet")throw new Error("Multiversx testnet is not supported");return"erd1qqqqqqqqqqqqqpgq3mrpj3u6q7tejv6d7eqhnyd27n9v5c5tl3ts08mffe"};var L=s=>({hash:s.hash.toString("hex"),alias:s.alias?.toString()||null,trust:s.trust.toString(),owner:s.owner.toString(),createdAt:s.created_at.toNumber(),upgradedAt:s.upgraded_at?.toNumber(),brand:s.brand?.toString("hex")||null,upgrade:s.upgrade?.toString("hex")||null}),Ze=s=>({unitPrice:BigInt(s.unit_price.toString()),admins:s.admins.map(e=>e.toBech32())});var q=class{constructor(e,t){this.config=e;this.chain=t;this.cache=new gr(e.cache?.type),this.registryConfig={unitPrice:BigInt(0),admins:[]},this.userWallet=this.config.user?.wallets?.[this.chain.name]||null}async init(){await this.loadRegistryConfigs()}getRegistryConfig(){return this.registryConfig}async createWarpRegisterTransaction(e,t,r){if(this.registryConfig.unitPrice===BigInt(0))throw new Error("WarpRegistry: config not loaded. forgot to call init()?");if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let n=f.newFromBech32(this.userWallet),a=()=>this.isCurrentUserAdmin()?BigInt(0):t&&r?this.registryConfig.unitPrice*BigInt(3):t?this.registryConfig.unitPrice*BigInt(2):this.registryConfig.unitPrice,o=()=>t&&r?[g.fromHex(e),g.fromUTF8(t),g.fromHex(r)]:t?[g.fromHex(e),g.fromUTF8(t)]:[g.fromHex(e)];return await this.getFactory().createTransactionForExecute(n,{contract:f.newFromBech32(x(this.config.env)),function:"registerWarp",gasLimit:BigInt(1e7),nativeTransferAmount:a(),arguments:o()})}async createWarpUnregisterTransaction(e){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let t=f.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(t,{contract:f.newFromBech32(x(this.config.env)),function:"unregisterWarp",gasLimit:BigInt(1e7),arguments:[g.fromHex(e)]})}async createWarpUpgradeTransaction(e,t){if(this.registryConfig.unitPrice===BigInt(0))throw new Error("WarpRegistry: config not loaded. forgot to call init()?");if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let r=f.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(r,{contract:f.newFromBech32(x(this.config.env)),function:"upgradeWarp",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[g.fromUTF8(e),g.fromHex(t)]})}async createWarpAliasSetTransaction(e,t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let r=f.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(r,{contract:f.newFromBech32(x(this.config.env)),function:"setWarpAlias",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[g.fromHex(e),g.fromUTF8(t)]})}async createWarpVerifyTransaction(e){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let t=f.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(t,{contract:f.newFromBech32(x(this.config.env)),function:"verifyWarp",gasLimit:BigInt(1e7),arguments:[g.fromHex(e)]})}async createWarpTransferOwnershipTransaction(e,t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let r=f.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(r,{contract:f.newFromBech32(x(this.config.env)),function:"transferOwnership",gasLimit:BigInt(1e7),arguments:[g.fromHex(e),new ce(new f(t))]})}async createBrandRegisterTransaction(e){if(this.registryConfig.unitPrice===BigInt(0))throw new Error("WarpRegistry: config not loaded. forgot to call init()?");if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let t=f.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(t,{contract:f.newFromBech32(x(this.config.env)),function:"registerBrand",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[g.fromHex(e)]})}async createWarpBrandingTransaction(e,t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let r=f.newFromBech32(this.userWallet);return await this.getFactory().createTransactionForExecute(r,{contract:f.newFromBech32(x(this.config.env)),function:"brandWarp",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[g.fromHex(e),g.fromHex(t)]})}async getInfoByAlias(e,t){try{let r=pe.RegistryInfo(this.config.env,e),n=t?this.cache.get(r):null;if(n)return ue.info(`WarpRegistry (getInfoByAlias): RegistryInfo found in cache: ${e}`),n;let a=f.newFromBech32(x(this.config.env)),o=this.getController(),i=o.createQuery({contract:a,function:"getInfoByAlias",arguments:[g.fromUTF8(e)]}),c=await o.runQuery(i),[p]=o.parseQueryResponse(c),u=p?L(p):null,l=u?.brand?await this.fetchBrand(u.brand):null;return t&&t.ttl&&this.cache.set(r,{registryInfo:u,brand:l},t.ttl),{registryInfo:u,brand:l}}catch{return{registryInfo:null,brand:null}}}async getInfoByHash(e,t){try{let r=pe.RegistryInfo(this.config.env,e);if(t){let l=this.cache.get(r);if(l)return ue.info(`WarpRegistry (getInfoByHash): RegistryInfo found in cache: ${e}`),l}let n=f.newFromBech32(x(this.config.env)),a=this.getController(),o=a.createQuery({contract:n,function:"getInfoByHash",arguments:[g.fromHex(e)]}),i=await a.runQuery(o),[c]=a.parseQueryResponse(i),p=c?L(c):null,u=p?.brand?await this.fetchBrand(p.brand):null;return t&&t.ttl&&this.cache.set(r,{registryInfo:p,brand:u},t.ttl),{registryInfo:p,brand:u}}catch{return{registryInfo:null,brand:null}}}async getUserWarpRegistryInfos(e){try{let t=e||this.userWallet;if(!t)throw new Error("WarpRegistry: user address not set");let r=f.newFromBech32(x(this.config.env)),n=this.getController(),a=n.createQuery({contract:r,function:"getUserWarps",arguments:[new ce(new f(t))]}),o=await n.runQuery(a),[i]=n.parseQueryResponse(o);return i.map(L)}catch{return[]}}async getUserBrands(e){try{let t=e||this.userWallet;if(!t)throw new Error("WarpRegistry: user address not set");let r=f.newFromBech32(x(this.config.env)),n=this.getController(),a=n.createQuery({contract:r,function:"getUserBrands",arguments:[new ce(new f(t))]}),o=await n.runQuery(a),[i]=n.parseQueryResponse(o),c=i.map(l=>l.toString("hex")),p={ttl:365*24*60*60};return(await Promise.all(c.map(l=>this.fetchBrand(l,p)))).filter(l=>l!==null)}catch{return[]}}async fetchBrand(e,t){let r=pe.Brand(this.config.env,e),n=t?this.cache.get(r):null;if(n)return ue.info(`WarpRegistry (fetchBrand): Brand found in cache: ${e}`),n;let o=d.getChainEntrypoint(this.chain,this.config.env).createNetworkProvider();try{let i=await o.getTransaction(e),c=JSON.parse(i.data.toString());return c.meta={hash:i.hash,creator:i.sender.toBech32(),createdAt:new Date(i.timestamp*1e3).toISOString()},t&&t.ttl&&this.cache.set(r,c,t.ttl),c}catch{return null}}async loadRegistryConfigs(){let e=f.newFromBech32(x(this.config.env)),t=this.getController(),[r]=await t.query({contract:e,function:"getConfig",arguments:[]}),n=r?Ze(r):null;this.registryConfig=n||{unitPrice:BigInt(0),admins:[]}}getFactory(){let e=new dr({chainID:this.chain.chainId}),t=et.create(oe);return new fr({config:e,abi:t})}getController(){let e=d.getChainEntrypoint(this.chain,this.config.env),t=et.create(oe);return e.createSmartContractController(t)}isCurrentUserAdmin(){return!!this.userWallet&&this.registryConfig.admins.includes(this.userWallet)}};var D=(s,e,t)=>(r,n)=>{let a=t[r.env];return{chain:s,chainInfo:a,prefix:e,builder:()=>new O(r,a),executor:new d(r,a),results:new V(r,a),serializer:new E,registry:new q(r,a),explorer:new $(s,r),abiBuilder:()=>new B(r,a),brandBuilder:()=>new _(r,a),dataLoader:new M(r,a),registerTypes:o=>{o.registerType("token",{stringToNative:i=>i,nativeToString:i=>`token:${i}`}),o.registerType("codemeta",{stringToNative:i=>i,nativeToString:i=>`codemeta:${i}`})}}};var S="multiversx",tt=D(S,"mvx",{mainnet:{name:S,displayName:"MultiversX",chainId:"1",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://api.multiversx.com",nativeToken:"EGLD"},testnet:{name:S,displayName:"MultiversX Testnet",chainId:"T",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://testnet-api.multiversx.com",nativeToken:"EGLD"},devnet:{name:S,displayName:"MultiversX Devnet",chainId:"D",blockTime:6e3,addressHrp:"erd",defaultApiUrl:"https://devnet-api.multiversx.com",nativeToken:"EGLD"}});var H="vibechain",le={name:H,displayName:"VibeChain",chainId:"V",blockTime:600,addressHrp:"vibe",defaultApiUrl:"https://vibeox-api.multiversx.com",nativeToken:"VIBE"},rt=D(H,"vibe",{mainnet:le,testnet:le,devnet:le});var ai=(s,e)=>[tt(s,e),rt(s,e)],ii=()=>[S,H];export{S as ChainNameMultiversx,H as ChainNameVibechain,I as ExplorerUrls,ur as MultiversxExplorers,Ye as MultiversxExplorersConfig,lr as VibechainExplorers,B as WarpMultiversxAbiBuilder,_ as WarpMultiversxBrandBuilder,O as WarpMultiversxBuilder,wa as WarpMultiversxConstants,k as WarpMultiversxContractLoader,d as WarpMultiversxExecutor,$ as WarpMultiversxExplorer,q as WarpMultiversxRegistry,V as WarpMultiversxResults,E as WarpMultiversxSerializer,an as address_value,rn as biguint_value,nn as boolean_value,cn as codemeta_value,Jr as composite_value,D as createMultiversxAdapter,Le as esdt_value,ai as getAllMultiversxAdapters,ii as getAllMultiversxChainNames,tt as getMultiversxAdapter,x as getMultiversxRegistryAddress,rt as getVibechainAdapter,on as hex_value,Gr as list_value,pn as nothing_value,Qr as option_value,jr as optional_value,Xr as string_value,sn as token_value,Zr as u16_value,en as u32_value,tn as u64_value,Yr as u8_value,Kr as variadic_value};
package/package.json CHANGED
@@ -1,13 +1,19 @@
1
1
  {
2
2
  "name": "@vleap/warps-adapter-multiversx",
3
- "version": "0.2.0-alpha.3",
3
+ "version": "0.2.0-alpha.31",
4
4
  "description": "",
5
- "main": "./dist/index.js",
5
+ "type": "module",
6
6
  "types": "./dist/index.d.ts",
7
- "module": "./dist/index.js",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.mjs",
11
+ "default": "./dist/index.mjs"
12
+ }
13
+ },
8
14
  "scripts": {
9
15
  "build": "tsup",
10
- "test": "jest --config jest.config.js",
16
+ "test": "jest --config jest.config.mjs",
11
17
  "lint": "tsc --noEmit",
12
18
  "prepare": "npm run build",
13
19
  "preversion": "npm run lint && npm run build"
@@ -18,19 +24,19 @@
18
24
  "dist"
19
25
  ],
20
26
  "devDependencies": {
21
- "@types/jest": "^29.5.14",
22
- "jest": "^30.0.0",
23
- "jest-environment-jsdom": "^30.0.0",
27
+ "@types/jest": "^30.0.0",
28
+ "jest": "^30.0.5",
29
+ "jest-environment-jsdom": "^30.0.5",
24
30
  "jest-fetch-mock": "^3.0.3",
25
- "ts-jest": "^29.4.0",
31
+ "ts-jest": "^29.4.1",
26
32
  "tsup": "^8.5.0",
27
- "typescript": "^5.8.3"
33
+ "typescript": "^5.9.2"
28
34
  },
29
35
  "publishConfig": {
30
36
  "access": "public"
31
37
  },
32
38
  "dependencies": {
33
- "@multiversx/sdk-core": "^14.2.1",
34
- "@vleap/warps-core": "^0.2.0-alpha.4"
39
+ "@multiversx/sdk-core": "^15.0.1",
40
+ "@vleap/warps": "^3.0.0-alpha.77"
35
41
  }
36
42
  }
package/dist/index.d.mts DELETED
@@ -1,150 +0,0 @@
1
- import { Adapter, WarpInitConfig, WarpAbi, WarpCacheConfig, WarpContractAction, WarpQueryAction, AdapterWarpBuilder, Warp, WarpChainInfo, WarpContract, WarpContractVerification, AdapterWarpExecutor, WarpExecutable, WarpExecution, WarpChainEnv, AdapterWarpRegistry, WarpRegistryConfigInfo, WarpRegistryInfo, WarpBrand, WarpChain, AdapterWarpResults, WarpActionIndex, ResolvedInput, WarpExecutionResults, AdapterWarpSerializer, WarpSerializer, WarpActionInputType, WarpNativeValue, BaseWarpActionInputType, WarpAdapterGenericType } from '@vleap/warps-core';
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, Address } from '@multiversx/sdk-core';
3
-
4
- declare const WarpMultiversxConstants: {
5
- Egld: {
6
- Identifier: string;
7
- EsdtIdentifier: string;
8
- DisplayName: string;
9
- Decimals: number;
10
- };
11
- };
12
-
13
- declare const getMultiversxAdapter: () => Adapter;
14
-
15
- declare const option_value: (value: TypedValue | null, type?: Type) => OptionValue;
16
- declare const optional_value: (value: TypedValue | null, type?: Type) => OptionalValue;
17
- declare const list_value: (values: TypedValue[]) => List;
18
- declare const variadic_value: (values: TypedValue[]) => VariadicValue;
19
- declare const composite_value: (values: TypedValue[]) => CompositeValue;
20
- declare const string_value: (value: string) => StringValue;
21
- declare const u8_value: (value: number) => U8Value;
22
- declare const u16_value: (value: number) => U16Value;
23
- declare const u32_value: (value: number) => U32Value;
24
- declare const u64_value: (value: bigint) => U64Value;
25
- declare const biguint_value: (value: bigint | string | number) => BigUIntValue;
26
- declare const boolean_value: (value: boolean) => BooleanValue;
27
- declare const address_value: (value: string) => AddressValue;
28
- declare const token_value: (value: string) => TokenIdentifierValue;
29
- declare const hex_value: (value: string) => BytesValue;
30
- declare const esdt_value: (value: TokenTransfer) => Struct;
31
- declare const codemeta_value: (hexString: string) => CodeMetadataValue;
32
- declare const nothing_value: () => NothingValue;
33
-
34
- declare class WarpMultiversxAbi {
35
- private readonly config;
36
- private readonly contractLoader;
37
- private readonly cache;
38
- constructor(config: WarpInitConfig);
39
- createFromRaw(encoded: string): Promise<WarpAbi>;
40
- createFromTransaction(tx: TransactionOnNetwork): Promise<WarpAbi>;
41
- createFromTransactionHash(hash: string, cache?: WarpCacheConfig): Promise<WarpAbi | null>;
42
- getAbiForAction(action: WarpContractAction | WarpQueryAction): Promise<AbiRegistry>;
43
- fetchAbi(action: WarpContractAction | WarpQueryAction): Promise<AbiRegistry>;
44
- }
45
-
46
- declare class WarpMultiversxBuilder implements AdapterWarpBuilder {
47
- private config;
48
- private cache;
49
- private core;
50
- constructor(config: WarpInitConfig);
51
- createInscriptionTransaction(warp: Warp): Transaction;
52
- createFromTransaction(tx: TransactionOnNetwork, validate?: boolean): Promise<Warp>;
53
- createFromTransactionHash(hash: string, cache?: WarpCacheConfig): Promise<Warp | null>;
54
- }
55
-
56
- declare class WarpMultiversxContractLoader {
57
- private readonly config;
58
- constructor(config: WarpInitConfig);
59
- getContract(address: string, chain: WarpChainInfo): Promise<WarpContract | null>;
60
- getVerificationInfo(address: string, chain: WarpChainInfo): Promise<WarpContractVerification | null>;
61
- }
62
-
63
- declare class WarpMultiversxExecutor implements AdapterWarpExecutor {
64
- private readonly config;
65
- private readonly serializer;
66
- private readonly abi;
67
- private readonly results;
68
- constructor(config: WarpInitConfig);
69
- createTransaction(executable: WarpExecutable): Promise<Transaction>;
70
- createTransferTransaction(executable: WarpExecutable): Promise<Transaction>;
71
- createContractCallTransaction(executable: WarpExecutable): Promise<Transaction>;
72
- executeQuery(executable: WarpExecutable): Promise<WarpExecution>;
73
- static getChainEntrypoint(chainInfo: WarpChainInfo, env: WarpChainEnv): NetworkEntrypoint;
74
- }
75
-
76
- declare class WarpMultiversxRegistry implements AdapterWarpRegistry {
77
- private config;
78
- private cache;
79
- registryConfig: WarpRegistryConfigInfo;
80
- constructor(config: WarpInitConfig);
81
- init(): Promise<void>;
82
- createWarpRegisterTransaction(txHash: string, alias?: string | null, brand?: string | null): Transaction;
83
- createWarpUnregisterTransaction(txHash: string): Transaction;
84
- createWarpUpgradeTransaction(alias: string, txHash: string): Transaction;
85
- createWarpAliasSetTransaction(txHash: string, alias: string): Transaction;
86
- createWarpVerifyTransaction(txHash: string): Transaction;
87
- createWarpTransferOwnershipTransaction(txHash: string, newOwner: string): Transaction;
88
- createBrandRegisterTransaction(txHash: string): Transaction;
89
- createWarpBrandingTransaction(warpHash: string, brandHash: string): Transaction;
90
- getInfoByAlias(alias: string, cache?: WarpCacheConfig): Promise<{
91
- registryInfo: WarpRegistryInfo | null;
92
- brand: WarpBrand | null;
93
- }>;
94
- getInfoByHash(hash: string, cache?: WarpCacheConfig): Promise<{
95
- registryInfo: WarpRegistryInfo | null;
96
- brand: WarpBrand | null;
97
- }>;
98
- getUserWarpRegistryInfos(user?: string): Promise<WarpRegistryInfo[]>;
99
- getUserBrands(user?: string): Promise<WarpBrand[]>;
100
- getChainInfos(cache?: WarpCacheConfig): Promise<WarpChainInfo[]>;
101
- getChainInfo(chain: WarpChain, cache?: WarpCacheConfig): Promise<WarpChainInfo | null>;
102
- setChain(info: WarpChainInfo): Promise<Transaction>;
103
- removeChain(chain: WarpChain): Promise<Transaction>;
104
- fetchBrand(hash: string, cache?: WarpCacheConfig): Promise<WarpBrand | null>;
105
- getRegistryContractAddress(): Address;
106
- private loadRegistryConfigs;
107
- private getFactory;
108
- private getController;
109
- private isCurrentUserAdmin;
110
- }
111
-
112
- declare class WarpMultiversxResults implements AdapterWarpResults {
113
- private readonly config;
114
- private readonly abi;
115
- private readonly serializer;
116
- private readonly cache;
117
- constructor(config: WarpInitConfig);
118
- getTransactionExecutionResults(warp: Warp, actionIndex: WarpActionIndex, tx: TransactionOnNetwork): Promise<WarpExecution>;
119
- extractContractResults(warp: Warp, actionIndex: WarpActionIndex, tx: TransactionOnNetwork, inputs: ResolvedInput[]): Promise<{
120
- values: any[];
121
- results: WarpExecutionResults;
122
- }>;
123
- extractQueryResults(warp: Warp, typedValues: TypedValue[], actionIndex: number, inputs: ResolvedInput[]): Promise<{
124
- values: any[];
125
- results: WarpExecutionResults;
126
- }>;
127
- resolveWarpResultsRecursively(props: {
128
- warp: Warp;
129
- entryActionIndex: number;
130
- executor: {
131
- executeQuery: Function;
132
- executeCollect: Function;
133
- };
134
- inputs: ResolvedInput[];
135
- meta?: Record<string, any>;
136
- }): Promise<any>;
137
- }
138
-
139
- declare class WarpMultiversxSerializer implements AdapterWarpSerializer {
140
- readonly coreSerializer: WarpSerializer;
141
- constructor();
142
- typedToString(value: TypedValue): string;
143
- typedToNative(value: TypedValue): [WarpActionInputType, WarpNativeValue];
144
- nativeToTyped(type: WarpActionInputType, value: WarpNativeValue): TypedValue;
145
- nativeToType(type: BaseWarpActionInputType): WarpAdapterGenericType;
146
- stringToTyped(value: string): TypedValue;
147
- typeToString(type: Type): WarpActionInputType;
148
- }
149
-
150
- export { WarpMultiversxAbi, WarpMultiversxBuilder, WarpMultiversxConstants, WarpMultiversxContractLoader, WarpMultiversxExecutor, WarpMultiversxRegistry, WarpMultiversxResults, WarpMultiversxSerializer, address_value, biguint_value, boolean_value, codemeta_value, composite_value, esdt_value, getMultiversxAdapter, hex_value, list_value, nothing_value, option_value, optional_value, string_value, token_value, u16_value, u32_value, u64_value, u8_value, variadic_value };
package/dist/index.js DELETED
@@ -1 +0,0 @@
1
- "use strict";var D=Object.defineProperty;var X=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var Z=Object.prototype.hasOwnProperty;var tt=(s,t)=>{for(var e in t)D(s,e,{get:t[e],enumerable:!0})},et=(s,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of Y(t))!Z.call(s,a)&&a!==e&&D(s,a,{get:()=>t[a],enumerable:!(r=X(t,a))||r.enumerable});return s};var rt=s=>et(D({},"__esModule",{value:!0}),s);var bt={};tt(bt,{WarpMultiversxAbi:()=>P,WarpMultiversxBuilder:()=>$,WarpMultiversxConstants:()=>nt,WarpMultiversxContractLoader:()=>k,WarpMultiversxExecutor:()=>b,WarpMultiversxRegistry:()=>M,WarpMultiversxResults:()=>_,WarpMultiversxSerializer:()=>S,address_value:()=>dt,biguint_value:()=>gt,boolean_value:()=>yt,codemeta_value:()=>Tt,composite_value:()=>ut,esdt_value:()=>wt,getMultiversxAdapter:()=>Wt,hex_value:()=>ht,list_value:()=>ot,nothing_value:()=>Ct,option_value:()=>it,optional_value:()=>st,string_value:()=>R,token_value:()=>mt,u16_value:()=>lt,u32_value:()=>q,u64_value:()=>ft,u8_value:()=>pt,variadic_value:()=>ct});module.exports=rt(bt);var nt={Egld:{Identifier:"EGLD",EsdtIdentifier:"EGLD-000000",DisplayName:"eGold",Decimals:18}};var O=require("@multiversx/sdk-core"),x=require("@vleap/warps-core");var w=require("@multiversx/sdk-core"),F=require("@vleap/warps-core");var H=require("@multiversx/sdk-core"),I=require("@vleap/warps-core");var j=require("@vleap/warps-core");var k=class{constructor(t){this.config=t}async getContract(t,e){try{let c=await b.getChainEntrypoint(e,this.config.env).createNetworkProvider().doGetGeneric(`accounts/${t}`);return{address:t,owner:c.ownerAddress,verified:c.isVerified||!1}}catch(r){return j.WarpLogger.error("WarpContractLoader: getContract error",r),null}}async getVerificationInfo(t,e){try{let c=await b.getChainEntrypoint(e,this.config.env).createNetworkProvider().doGetGeneric(`accounts/${t}/verification`);return{codeHash:c.codeHash,abi:c.source.abi}}catch(r){return j.WarpLogger.error("WarpContractLoader: getVerificationInfo error",r),null}}};var P=class{constructor(t){this.config=t;this.contractLoader=new k(this.config),this.cache=new I.WarpCache(this.config.cache?.type)}async createFromRaw(t){return JSON.parse(t)}async createFromTransaction(t){let e=await this.createFromRaw(t.data.toString());return e.meta={hash:t.hash,creator:t.sender.bech32(),createdAt:new Date(t.timestamp*1e3).toISOString()},e}async createFromTransactionHash(t,e){let r=I.WarpCacheKey.WarpAbi(this.config.env,t);if(e){let i=this.cache.get(r);if(i)return I.WarpLogger.info(`WarpAbiBuilder (createFromTransactionHash): Warp abi found in cache: ${t}`),i}let a=(0,I.getMainChainInfo)(this.config),u=b.getChainEntrypoint(a,this.config.env).createNetworkProvider();try{let i=await u.getTransaction(t),f=await this.createFromTransaction(i);return e&&e.ttl&&f&&this.cache.set(r,f,e.ttl),f}catch(i){return I.WarpLogger.error("WarpAbiBuilder: Error creating from transaction hash",i),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,I.getMainChainInfo)(this.config),r=await this.contractLoader.getVerificationInfo(t.address,e);if(!r)throw new Error("WarpActionExecutor: Verification info not found");return H.AbiRegistry.create(r.abi)}async fetchAbi(t){if(!t.abi)throw new Error("WarpActionExecutor: ABI not found");if(t.abi.startsWith(I.WarpConstants.IdentifierType.Hash)){let e=t.abi.split(I.WarpConstants.IdentifierParamSeparator)[1],r=await this.createFromTransactionHash(e);if(!r)throw new Error(`WarpActionExecutor: ABI not found for hash: ${t.abi}`);return H.AbiRegistry.create(r.content)}else{let r=await(await fetch(t.abi)).json();return H.AbiRegistry.create(r)}}};var U=require("@multiversx/sdk-core"),h=require("@vleap/warps-core");var n=require("@multiversx/sdk-core"),C=require("@vleap/warps-core"),K=new RegExp(`${C.WarpConstants.ArgParamsSeparator}(.*)`),S=class{constructor(){this.coreSerializer=new C.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(u=>this.typedToString(u).split(C.WarpConstants.ArgParamsSeparator)[0])[0],c=e.map(u=>this.typedToString(u).split(C.WarpConstants.ArgParamsSeparator)[1]);return`list:${a}:${c.join(",")}`}if(t.hasClassOrSuperclass(n.VariadicValue.ClassName)){let e=t.getItems(),a=e.map(u=>this.typedToString(u).split(C.WarpConstants.ArgParamsSeparator)[0])[0],c=e.map(u=>this.typedToString(u).split(C.WarpConstants.ArgParamsSeparator)[1]);return`variadic:${a}:${c.join(",")}`}if(t.hasClassOrSuperclass(n.CompositeValue.ClassName)){let e=t.getItems(),r=e.map(i=>this.typedToString(i).split(C.WarpConstants.ArgParamsSeparator)[0]),a=e.map(i=>this.typedToString(i).split(C.WarpConstants.ArgParamsSeparator)[1]),c=r.join(C.WarpConstants.ArgCompositeSeparator),u=a.join(C.WarpConstants.ArgCompositeSeparator);return`composite(${c}):${u}`}if(t.hasClassOrSuperclass(n.BigUIntValue.ClassName)||t.getType().getName()==="BigUint")return`biguint:${BigInt(t.valueOf().toFixed())}`;if(t.hasClassOrSuperclass(n.U8Value.ClassName))return`uint8:${t.valueOf().toNumber()}`;if(t.hasClassOrSuperclass(n.U16Value.ClassName))return`uint16:${t.valueOf().toNumber()}`;if(t.hasClassOrSuperclass(n.U32Value.ClassName))return`uint32:${t.valueOf().toNumber()}`;if(t.hasClassOrSuperclass(n.U64Value.ClassName))return`uint64:${BigInt(t.valueOf().toFixed())}`;if(t.hasClassOrSuperclass(n.StringValue.ClassName))return`string:${t.valueOf()}`;if(t.hasClassOrSuperclass(n.BooleanValue.ClassName))return`bool:${t.valueOf()}`;if(t.hasClassOrSuperclass(n.AddressValue.ClassName))return`address:${t.valueOf().bech32()}`;if(t.hasClassOrSuperclass(n.TokenIdentifierValue.ClassName))return`token:${t.valueOf()}`;if(t.hasClassOrSuperclass(n.BytesValue.ClassName))return`hex:${t.valueOf().toString("hex")}`;if(t.hasClassOrSuperclass(n.CodeMetadataValue.ClassName))return`codemeta:${t.valueOf().toBuffer().toString("hex")}`;if(t.getType().getName()==="EsdtTokenPayment"){let e=t.getFieldValue("token_identifier").valueOf(),r=t.getFieldValue("token_nonce").valueOf(),a=t.getFieldValue("amount").valueOf();return`esdt:${e}|${r}|${a}`}throw new Error(`WarpArgSerializer (typedToString): Unsupported input type: ${t.getClassName()}`)}typedToNative(t){let e=this.typedToString(t);return this.coreSerializer.stringToNative(e)}nativeToTyped(t,e){let r=this.coreSerializer.nativeToString(t,e);return this.stringToTyped(r)}nativeToType(t){if(t.startsWith("composite")){let e=t.match(/\(([^)]+)\)/)?.[1];return new n.CompositeType(...e.split(C.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,c]=r.split(K,2),i=c.split(",").map(f=>this.stringToTyped(`${a}:${f}`));return new n.List(this.nativeToType(a),i)}if(e==="variadic"){let[a,c]=r.split(K,2),i=c.split(",").map(f=>this.stringToTyped(`${a}:${f}`));return new n.VariadicValue(new n.VariadicType(this.nativeToType(a)),i)}if(e.startsWith("composite")){let a=e.match(/\(([^)]+)\)/)?.[1],c=r.split(C.WarpConstants.ArgCompositeSeparator),u=a.split(C.WarpConstants.ArgCompositeSeparator),i=c.map((l,g)=>this.stringToTyped(`${u[g]}:${l}`)),f=i.map(l=>l.getType());return new n.CompositeValue(new n.CompositeType(...f),i)}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(C.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 _=class{constructor(t){this.config=t;this.abi=new P(t),this.serializer=new S,this.cache=new h.WarpCache(t.cache?.type)}async getTransactionExecutionResults(t,e,r){let a=this.cache.get(h.WarpCacheKey.WarpExecutable(this.config.env,t.meta?.hash||"",e))??[],c=await this.extractContractResults(t,e,r,a),u=(0,h.getNextInfo)(this.config,t,e,c),i=(0,h.applyResultsToMessages)(t,c.results);return{success:r.status.isSuccessful(),warp:t,action:e,user:this.config.user?.wallet||null,txHash:r.hash,next:u,values:c.values,results:c.results,messages:i}}async extractContractResults(t,e,r,a){let c=(0,h.getWarpActionByIndex)(t,e),u=[],i={};if(!t.results||c.type!=="contract")return{values:u,results:i};if(!Object.values(t.results).some(A=>A.includes("out")||A.includes("event"))){for(let[A,d]of Object.entries(t.results))i[A]=d;return{values:u,results:await(0,h.evaluateResultsCommon)(t,i,e,a)}}let l=await this.abi.getAbiForAction(c),g=new U.TransactionEventsParser({abi:l}),B=new U.SmartContractTransactionsOutcomeParser({abi:l}).parseExecute({transactionOnNetwork:r,function:c.func||void 0});for(let[A,d]of Object.entries(t.results)){if(d.startsWith(h.WarpConstants.Transform.Prefix))continue;if(d.startsWith("input.")){i[A]=d;continue}let V=(0,h.parseResultsOutIndex)(d);if(V!==null&&V!==e){i[A]=null;continue}let[W,E,v]=d.split(".");if(W==="event"){if(!E||isNaN(Number(v)))continue;let L=Number(v),T=(0,U.findEventsByFirstTopic)(r,E),N=g.parseEvents({events:T})[0],Q=Object.values(N)[L]||null;u.push(Q),i[A]=Q&&Q.valueOf()}else if(W==="out"||W.startsWith("out[")){if(!E)continue;let L=Number(E),T=B.values[L-1]||null;v&&(T=T[v]||null),T&&typeof T=="object"&&(T="toFixed"in T?T.toFixed():T.valueOf()),u.push(T),i[A]=T&&T.valueOf()}else i[A]=d}return{values:u,results:await(0,h.evaluateResultsCommon)(t,i,e,a)}}async extractQueryResults(t,e,r,a){let c=e.map(l=>this.serializer.typedToString(l)),u=e.map(l=>this.serializer.typedToNative(l)[1]),i={};if(!t.results)return{values:c,results:i};let f=l=>{let g=l.split(".").slice(1).map(B=>parseInt(B)-1);if(g.length===0)return;let y=u[g[0]];for(let B=1;B<g.length;B++){if(y==null)return;y=y[g[B]]}return y};for(let[l,g]of Object.entries(t.results)){if(g.startsWith(h.WarpConstants.Transform.Prefix))continue;let y=(0,h.parseResultsOutIndex)(g);if(y!==null&&y!==r){i[l]=null;continue}g.startsWith("out.")||g==="out"||g.startsWith("out[")?i[l]=f(g)||null:i[l]=g}return{values:c,results:await(0,h.evaluateResultsCommon)(t,i,r,a)}}async resolveWarpResultsRecursively(t){let e=t.warp,r=t.entryActionIndex,a=t.executor,c=t.inputs,u=t.meta,i=new Map,f=new Set,l=this;async function g(d,V=[]){if(i.has(d))return i.get(d);if(f.has(d))throw new Error(`Circular dependency detected at action ${d}`);f.add(d);let W=e.actions[d-1];if(!W)throw new Error(`Action ${d} not found`);let E;if(W.type==="query")E=await a.executeQuery(e,d,V);else if(W.type==="collect")E=await a.executeCollect(e,d,V,u);else throw new Error(`Unsupported or interactive action type: ${W.type}`);if(i.set(d,E),e.results)for(let v of Object.values(e.results)){let T=String(v).match(/^out\[(\d+)\]/);if(T){let N=parseInt(T[1],10);N!==d&&!i.has(N)&&await g(N)}}return f.delete(d),E}await g(r,c);let y={};for(let d of i.values())for(let[V,W]of Object.entries(d.results))W!==null?y[V]=W:V in y||(y[V]=null);let B=await(0,h.evaluateResultsCommon)(e,y,r,c);return{...i.get(r),action:r,results:B}}};var b=class s{constructor(t){this.config=t;this.serializer=new S,this.abi=new P(this.config),this.results=new _(this.config)}async createTransaction(t){let e=(0,F.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){if(!this.config.user?.wallet)throw new Error("WarpMultiversxExecutor: createTransfer - user address not set");let e=w.Address.newFromBech32(this.config.user.wallet),r=new w.TransactionsFactoryConfig({chainID:t.chain.chainId}),a=t.data?Buffer.from(this.serializer.stringToTyped(t.data).valueOf()):null;return new w.TransferTransactionsFactory({config:r}).createTransactionForTransfer(e,{receiver:w.Address.newFromBech32(t.destination),nativeAmount:t.value,data:a?new Uint8Array(a):void 0})}async createContractCallTransaction(t){if(!this.config.user?.wallet)throw new Error("WarpMultiversxExecutor: createContractCall - user address not set");let e=(0,F.getWarpActionByIndex)(t.warp,t.action),r=w.Address.newFromBech32(this.config.user.wallet),a=t.args.map(u=>this.serializer.stringToTyped(u)),c=new w.TransactionsFactoryConfig({chainID:t.chain.chainId});return new w.SmartContractTransactionsFactory({config:c}).createTransactionForExecute(r,{contract:w.Address.newFromBech32(t.destination),function:"func"in e&&e.func||"",gasLimit:"gasLimit"in e?BigInt(e.gasLimit||0):0n,arguments:a,nativeTransferAmount:t.value})}async executeQuery(t){let e=(0,F.getWarpActionByIndex)(t.warp,t.action);if(e.type!=="query")throw new Error(`WarpMultiversxExecutor: Invalid action type for executeQuery: ${e.type}`);let r=await this.abi.getAbiForAction(e),a=t.args.map(v=>this.serializer.stringToTyped(v)),c=s.getChainEntrypoint(t.chain,this.config.env),u=w.Address.newFromBech32(t.destination),i=c.createSmartContractController(r),f=i.createQuery({contract:u,function:e.func||"",arguments:a}),l=await i.runQuery(f),g=l.returnCode==="ok",y=new w.ArgSerializer,B=r.getEndpoint(l.function||e.func||""),A=(l.returnDataParts||[]).map(v=>Buffer.from(v)),d=y.buffersToValues(A,B.output),{values:V,results:W}=await this.results.extractQueryResults(t.warp,d,t.action,t.resolvedInputs),E=(0,F.getNextInfo)(this.config,t.warp,t.action,W);return{success:g,warp:t.warp,action:t.action,user:this.config.user?.wallet||null,txHash:null,next:E,values:V,results:W,messages:(0,F.applyResultsToMessages)(t.warp,W)}}static getChainEntrypoint(t,e){let r="warp-sdk",a="api";return e==="devnet"?new w.DevnetEntrypoint(t.apiUrl,a,r):e==="testnet"?new w.TestnetEntrypoint(t.apiUrl,a,r):new w.MainnetEntrypoint(t.apiUrl,a,r)}};var $=class{constructor(t){this.config=t,this.cache=new x.WarpCache(t.cache?.type),this.core=new x.WarpBuilder(t)}createInscriptionTransaction(t){if(!this.config.user?.wallet)throw new Error("WarpBuilder: user address not set");let e=(0,x.getMainChainInfo)(this.config),r=new O.TransactionsFactoryConfig({chainID:e.chainId}),a=new O.TransferTransactionsFactory({config:r}),c=O.Address.newFromBech32(this.config.user.wallet),u=JSON.stringify(t),i=a.createTransactionForTransfer(c,{receiver:O.Address.newFromBech32(this.config.user.wallet),nativeAmount:BigInt(0),data:Uint8Array.from(Buffer.from(u))});return i.gasLimit=i.gasLimit+BigInt(2e6),i}async createFromTransaction(t,e=!1){let r=await this.core.createFromRaw(t.data.toString(),e);return r.meta={hash:t.hash,creator:t.sender.toBech32(),createdAt:new Date(t.timestamp*1e3).toISOString()},r}async createFromTransactionHash(t,e){let r=x.WarpCacheKey.Warp(this.config.env,t);if(e){let i=this.cache.get(r);if(i)return x.WarpLogger.info(`WarpBuilder (createFromTransactionHash): Warp found in cache: ${t}`),i}let a=(0,x.getMainChainInfo)(this.config),u=b.getChainEntrypoint(a,this.config.env).createNetworkProvider();try{let i=await u.getTransaction(t),f=await this.createFromTransaction(i);return e&&e.ttl&&f&&this.cache.set(r,f,e.ttl),f}catch(i){return x.WarpLogger.error("WarpBuilder: Error creating from transaction hash",i),null}}};var p=require("@multiversx/sdk-core"),m=require("@vleap/warps-core");var G={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=s=>({hash:s.hash.toString("hex"),alias:s.alias?.toString()||null,trust:s.trust.toString(),owner:s.owner.toString(),createdAt:s.created_at.toNumber(),upgradedAt:s.upgraded_at?.toNumber(),brand:s.brand?.toString("hex")||null,upgrade:s.upgrade?.toString("hex")||null}),J=s=>({unitPrice:BigInt(s.unit_price.toString()),admins:s.admins.map(t=>t.toBech32())});var o=require("@multiversx/sdk-core"),it=(s,t)=>s?o.OptionValue.newProvided(s):t?o.OptionValue.newMissingTyped(t):o.OptionValue.newMissing(),st=(s,t)=>s?new o.OptionalValue(s.getType(),s):t?new o.OptionalValue(t):o.OptionalValue.newMissing(),ot=s=>{if(s.length===0)throw new Error("Cannot create a list from an empty array");let t=s[0].getType();return new o.List(t,s)},ct=s=>o.VariadicValue.fromItems(...s),ut=s=>{let t=s.map(e=>e.getType());return new o.CompositeValue(new o.CompositeType(...t),s)},R=s=>o.StringValue.fromUTF8(s),pt=s=>new o.U8Value(s),lt=s=>new o.U16Value(s),q=s=>new o.U32Value(s),ft=s=>new o.U64Value(s),gt=s=>new o.BigUIntValue(BigInt(s)),yt=s=>new o.BooleanValue(s),dt=s=>new o.AddressValue(o.Address.newFromBech32(s)),mt=s=>new o.TokenIdentifierValue(s),ht=s=>o.BytesValue.fromHex(s),wt=s=>new o.Struct(new o.StructType("EsdtTokenPayment",[new o.FieldDefinition("token_identifier","",new o.TokenIdentifierType),new o.FieldDefinition("token_nonce","",new o.U64Type),new o.FieldDefinition("amount","",new o.BigUIntType)]),[new o.Field(new o.TokenIdentifierValue(s.token.identifier),"token_identifier"),new o.Field(new o.U64Value(BigInt(s.token.nonce)),"token_nonce"),new o.Field(new o.BigUIntValue(BigInt(s.amount)),"amount")]),Tt=s=>new o.CodeMetadataValue(o.CodeMetadata.newFromBytes(Uint8Array.from(Buffer.from(s,"hex")))),Ct=()=>new o.NothingValue;var M=class{constructor(t){this.config=t,this.cache=new m.WarpCache(t.cache?.type),this.registryConfig={unitPrice:BigInt(0),admins:[]}}async init(){await this.loadRegistryConfigs()}createWarpRegisterTransaction(t,e,r){if(this.registryConfig.unitPrice===BigInt(0))throw new Error("WarpRegistry: config not loaded. forgot to call init()?");if(!this.config.user?.wallet)throw new Error("WarpRegistry: user address not set");let a=p.Address.newFromBech32(this.config.user.wallet),c=()=>this.isCurrentUserAdmin()?BigInt(0):e&&r?this.registryConfig.unitPrice*BigInt(3):e?this.registryConfig.unitPrice*BigInt(2):this.registryConfig.unitPrice,u=()=>e&&r?[p.BytesValue.fromHex(t),p.BytesValue.fromUTF8(e),p.BytesValue.fromHex(r)]:e?[p.BytesValue.fromHex(t),p.BytesValue.fromUTF8(e)]:[p.BytesValue.fromHex(t)];return this.getFactory().createTransactionForExecute(a,{contract:this.getRegistryContractAddress(),function:"registerWarp",gasLimit:BigInt(1e7),nativeTransferAmount:c(),arguments:u()})}createWarpUnregisterTransaction(t){if(!this.config.user?.wallet)throw new Error("WarpRegistry: user address not set");let e=p.Address.newFromBech32(this.config.user.wallet);return this.getFactory().createTransactionForExecute(e,{contract:this.getRegistryContractAddress(),function:"unregisterWarp",gasLimit:BigInt(1e7),arguments:[p.BytesValue.fromHex(t)]})}createWarpUpgradeTransaction(t,e){if(this.registryConfig.unitPrice===BigInt(0))throw new Error("WarpRegistry: config not loaded. forgot to call init()?");if(!this.config.user?.wallet)throw new Error("WarpRegistry: user address not set");let r=p.Address.newFromBech32(this.config.user.wallet);return this.getFactory().createTransactionForExecute(r,{contract:this.getRegistryContractAddress(),function:"upgradeWarp",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[p.BytesValue.fromUTF8(t),p.BytesValue.fromHex(e)]})}createWarpAliasSetTransaction(t,e){if(!this.config.user?.wallet)throw new Error("WarpRegistry: user address not set");let r=p.Address.newFromBech32(this.config.user.wallet);return this.getFactory().createTransactionForExecute(r,{contract:this.getRegistryContractAddress(),function:"setWarpAlias",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[p.BytesValue.fromHex(t),p.BytesValue.fromUTF8(e)]})}createWarpVerifyTransaction(t){if(!this.config.user?.wallet)throw new Error("WarpRegistry: user address not set");let e=p.Address.newFromBech32(this.config.user.wallet);return this.getFactory().createTransactionForExecute(e,{contract:this.getRegistryContractAddress(),function:"verifyWarp",gasLimit:BigInt(1e7),arguments:[p.BytesValue.fromHex(t)]})}createWarpTransferOwnershipTransaction(t,e){if(!this.config.user?.wallet)throw new Error("WarpRegistry: user address not set");let r=p.Address.newFromBech32(this.config.user.wallet);return this.getFactory().createTransactionForExecute(r,{contract:this.getRegistryContractAddress(),function:"transferOwnership",gasLimit:BigInt(1e7),arguments:[p.BytesValue.fromHex(t),new p.AddressValue(new p.Address(e))]})}createBrandRegisterTransaction(t){if(this.registryConfig.unitPrice===BigInt(0))throw new Error("WarpRegistry: config not loaded. forgot to call init()?");if(!this.config.user?.wallet)throw new Error("WarpRegistry: user address not set");let e=p.Address.newFromBech32(this.config.user.wallet);return this.getFactory().createTransactionForExecute(e,{contract:this.getRegistryContractAddress(),function:"registerBrand",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[p.BytesValue.fromHex(t)]})}createWarpBrandingTransaction(t,e){if(!this.config.user?.wallet)throw new Error("WarpRegistry: user address not set");let r=p.Address.newFromBech32(this.config.user.wallet);return this.getFactory().createTransactionForExecute(r,{contract:this.getRegistryContractAddress(),function:"brandWarp",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[p.BytesValue.fromHex(t),p.BytesValue.fromHex(e)]})}async getInfoByAlias(t,e){try{let r=m.WarpCacheKey.RegistryInfo(this.config.env,t),a=e?this.cache.get(r):null;if(a)return m.WarpLogger.info(`WarpRegistry (getInfoByAlias): RegistryInfo found in cache: ${t}`),a;let c=this.getRegistryContractAddress(),u=this.getController(),i=u.createQuery({contract:c,function:"getInfoByAlias",arguments:[p.BytesValue.fromUTF8(t)]}),f=await u.runQuery(i),[l]=u.parseQueryResponse(f),g=l?z(l):null,y=g?.brand?await this.fetchBrand(g.brand):null;return e&&e.ttl&&this.cache.set(r,{registryInfo:g,brand:y},e.ttl),{registryInfo:g,brand:y}}catch{return{registryInfo:null,brand:null}}}async getInfoByHash(t,e){try{let r=m.WarpCacheKey.RegistryInfo(this.config.env,t);if(e){let y=this.cache.get(r);if(y)return m.WarpLogger.info(`WarpRegistry (getInfoByHash): RegistryInfo found in cache: ${t}`),y}let a=this.getRegistryContractAddress(),c=this.getController(),u=c.createQuery({contract:a,function:"getInfoByHash",arguments:[p.BytesValue.fromHex(t)]}),i=await c.runQuery(u),[f]=c.parseQueryResponse(i),l=f?z(f):null,g=l?.brand?await this.fetchBrand(l.brand):null;return e&&e.ttl&&this.cache.set(r,{registryInfo:l,brand:g},e.ttl),{registryInfo:l,brand:g}}catch{return{registryInfo:null,brand:null}}}async getUserWarpRegistryInfos(t){try{let e=t||this.config.user?.wallet;if(!e)throw new Error("WarpRegistry: user address not set");let r=this.getRegistryContractAddress(),a=this.getController(),c=a.createQuery({contract:r,function:"getUserWarps",arguments:[new p.AddressValue(new p.Address(e))]}),u=await a.runQuery(c),[i]=a.parseQueryResponse(u);return i.map(z)}catch{return[]}}async getUserBrands(t){try{let e=t||this.config.user?.wallet;if(!e)throw new Error("WarpRegistry: user address not set");let r=this.getRegistryContractAddress(),a=this.getController(),c=a.createQuery({contract:r,function:"getUserBrands",arguments:[new p.AddressValue(new p.Address(e))]}),u=await a.runQuery(c),[i]=a.parseQueryResponse(u),f=i.map(y=>y.toString("hex")),l={ttl:365*24*60*60};return(await Promise.all(f.map(y=>this.fetchBrand(y,l)))).filter(y=>y!==null)}catch{return[]}}async getChainInfos(t){let e=m.WarpCacheKey.ChainInfos(this.config.env);if(t&&t.ttl){let l=this.cache.get(e);if(l)return m.WarpLogger.info("WarpRegistry (getChainInfos): ChainInfos found in cache"),l}let r=this.getRegistryContractAddress(),a=this.getController(),c=a.createQuery({contract:r,function:"getChains",arguments:[]}),u=await a.runQuery(c),[i]=a.parseQueryResponse(u),f=i.map(m.toTypedChainInfo);if(t&&t.ttl){for(let l of f)this.cache.set(m.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=m.WarpCacheKey.ChainInfo(this.config.env,t),a=e?this.cache.get(r):null;if(a)return m.WarpLogger.info(`WarpRegistry (getChainInfo): ChainInfo found in cache: ${t}`),a;let c=this.getRegistryContractAddress(),u=this.getController(),i=u.createQuery({contract:c,function:"getChain",arguments:[p.BytesValue.fromUTF8(t)]}),f=await u.runQuery(i),[l]=u.parseQueryResponse(f),g=l?(0,m.toTypedChainInfo)(l):null;return e&&e.ttl&&g&&this.cache.set(r,g,e.ttl),g}catch{return null}}async setChain(t){if(!this.config.user?.wallet)throw new Error("WarpRegistry: user address not set");let e=p.Address.newFromBech32(this.config.user.wallet);return this.getFactory().createTransactionForExecute(e,{contract:this.getRegistryContractAddress(),function:"setChain",gasLimit:BigInt(1e7),arguments:[R(t.name),R(t.displayName),R(t.chainId),q(t.blockTime),R(t.addressHrp),R(t.apiUrl),R(t.explorerUrl),R(t.nativeToken)]})}async removeChain(t){if(!this.config.user?.wallet)throw new Error("WarpRegistry: user address not set");let e=p.Address.newFromBech32(this.config.user.wallet);return this.getFactory().createTransactionForExecute(e,{contract:this.getRegistryContractAddress(),function:"removeChain",gasLimit:BigInt(1e7),arguments:[R(t)]})}async fetchBrand(t,e){let r=m.WarpCacheKey.Brand(this.config.env,t),a=e?this.cache.get(r):null;if(a)return m.WarpLogger.info(`WarpRegistry (fetchBrand): Brand found in cache: ${t}`),a;let c=(0,m.getMainChainInfo)(this.config),i=b.getChainEntrypoint(c,this.config.env).createNetworkProvider();try{let f=await i.getTransaction(t),l=JSON.parse(f.data.toString());return l.meta={hash:f.hash,creator:f.sender.bech32(),createdAt:new Date(f.timestamp*1e3).toISOString()},e&&e.ttl&&this.cache.set(r,l,e.ttl),l}catch{return null}}getRegistryContractAddress(){return p.Address.newFromBech32(this.config.registry?.contract||m.WarpConfig.Registry.Contract(this.config.env))}async loadRegistryConfigs(){let t=this.getRegistryContractAddress(),e=this.getController(),[r]=await e.query({contract:t,function:"getConfig",arguments:[]}),a=r?J(r):null;this.registryConfig=a||{unitPrice:BigInt(0),admins:[]}}getFactory(){let t=(0,m.getMainChainInfo)(this.config),e=new p.TransactionsFactoryConfig({chainID:t.chainId}),r=p.AbiRegistry.create(G);return new p.SmartContractTransactionsFactory({config:e,abi:r})}getController(){let t=(0,m.getMainChainInfo)(this.config),e=b.getChainEntrypoint(t,this.config.env),r=p.AbiRegistry.create(G);return e.createSmartContractController(r)}isCurrentUserAdmin(){return!!this.config.user?.wallet&&this.registryConfig.admins.includes(this.config.user.wallet)}};var Wt=()=>({chain:"multiversx",builder:$,executor:b,results:_,serializer:S,registry:M});0&&(module.exports={WarpMultiversxAbi,WarpMultiversxBuilder,WarpMultiversxConstants,WarpMultiversxContractLoader,WarpMultiversxExecutor,WarpMultiversxRegistry,WarpMultiversxResults,WarpMultiversxSerializer,address_value,biguint_value,boolean_value,codemeta_value,composite_value,esdt_value,getMultiversxAdapter,hex_value,list_value,nothing_value,option_value,optional_value,string_value,token_value,u16_value,u32_value,u64_value,u8_value,variadic_value});