@vleap/warps-adapter-multiversx 0.2.0-alpha.1 → 0.2.0-alpha.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- 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';
2
- import { WarpInitConfig, WarpAbi, WarpCacheConfig, WarpContractAction, WarpQueryAction, WarpChainInfo, WarpContract, WarpContractVerification, WarpExecutable, WarpExecution, WarpChainEnv, WarpRegistryConfigInfo, WarpRegistryInfo, Brand, WarpChain, Warp, WarpActionIndex, ResolvedInput, WarpExecutionResults, WarpSerializer, WarpActionInputType, WarpNativeValue, BaseWarpActionInputType } from '@vleap/warps-core';
1
+ import { WarpClientConfig, Adapter, WarpAbi, WarpCacheConfig, WarpContractAction, WarpQueryAction, WarpBrand, AdapterWarpBuilder, Warp, WarpChainInfo, WarpContract, WarpContractVerification, AdapterWarpExecutor, WarpExecutable, WarpExecution, WarpActionInputType, WarpChainEnv, AdapterWarpExplorer, AdapterWarpRegistry, WarpRegistryConfigInfo, WarpRegistryInfo, WarpChain, AdapterWarpResults, ResolvedInput, WarpExecutionResults, AdapterWarpSerializer, WarpSerializer, WarpNativeValue, BaseWarpActionInputType, WarpAdapterGenericType } from '@vleap/warps';
2
+ import { TypedValue, Type, OptionValue, OptionalValue, List, VariadicValue, CompositeValue, StringValue, U8Value, U16Value, U32Value, U64Value, BigUIntValue, BooleanValue, AddressValue, TokenIdentifierValue, BytesValue, TokenTransfer, Struct, CodeMetadataValue, NothingValue, TransactionOnNetwork, AbiRegistry, Transaction, NetworkEntrypoint } from '@multiversx/sdk-core';
3
3
 
4
4
  declare const WarpMultiversxConstants: {
5
5
  Egld: {
@@ -10,6 +10,8 @@ declare const WarpMultiversxConstants: {
10
10
  };
11
11
  };
12
12
 
13
+ declare const getMultiversxAdapter: (config: WarpClientConfig) => Adapter;
14
+
13
15
  declare const option_value: (value: TypedValue | null, type?: Type) => OptionValue;
14
16
  declare const optional_value: (value: TypedValue | null, type?: Type) => OptionalValue;
15
17
  declare const list_value: (values: TypedValue[]) => List;
@@ -33,7 +35,7 @@ declare class WarpMultiversxAbi {
33
35
  private readonly config;
34
36
  private readonly contractLoader;
35
37
  private readonly cache;
36
- constructor(config: WarpInitConfig);
38
+ constructor(config: WarpClientConfig);
37
39
  createFromRaw(encoded: string): Promise<WarpAbi>;
38
40
  createFromTransaction(tx: TransactionOnNetwork): Promise<WarpAbi>;
39
41
  createFromTransactionHash(hash: string, cache?: WarpCacheConfig): Promise<WarpAbi | null>;
@@ -41,31 +43,58 @@ declare class WarpMultiversxAbi {
41
43
  fetchAbi(action: WarpContractAction | WarpQueryAction): Promise<AbiRegistry>;
42
44
  }
43
45
 
46
+ declare class WarpMultiversxBrandBuilder {
47
+ private config;
48
+ private core;
49
+ constructor(config: WarpClientConfig);
50
+ createInscriptionTransaction(brand: WarpBrand): Transaction;
51
+ createFromTransaction(tx: TransactionOnNetwork, validateSchema?: boolean): Promise<WarpBrand>;
52
+ createFromTransactionHash(hash: string): Promise<WarpBrand | null>;
53
+ }
54
+
55
+ declare class WarpMultiversxBuilder implements AdapterWarpBuilder {
56
+ private config;
57
+ private cache;
58
+ private core;
59
+ constructor(config: WarpClientConfig);
60
+ createInscriptionTransaction(warp: Warp): Transaction;
61
+ createFromTransaction(tx: TransactionOnNetwork, validate?: boolean): Promise<Warp>;
62
+ createFromTransactionHash(hash: string, cache?: WarpCacheConfig): Promise<Warp | null>;
63
+ }
64
+
44
65
  declare class WarpMultiversxContractLoader {
45
66
  private readonly config;
46
- constructor(config: WarpInitConfig);
67
+ constructor(config: WarpClientConfig);
47
68
  getContract(address: string, chain: WarpChainInfo): Promise<WarpContract | null>;
48
69
  getVerificationInfo(address: string, chain: WarpChainInfo): Promise<WarpContractVerification | null>;
49
70
  }
50
71
 
51
- declare class WarpMultiversxExecutor {
72
+ declare class WarpMultiversxExecutor implements AdapterWarpExecutor {
52
73
  private readonly config;
53
74
  private readonly serializer;
54
75
  private readonly abi;
55
76
  private readonly results;
56
- constructor(config: WarpInitConfig);
77
+ constructor(config: WarpClientConfig);
57
78
  createTransaction(executable: WarpExecutable): Promise<Transaction>;
58
79
  createTransferTransaction(executable: WarpExecutable): Promise<Transaction>;
59
80
  createContractCallTransaction(executable: WarpExecutable): Promise<Transaction>;
60
81
  executeQuery(executable: WarpExecutable): Promise<WarpExecution>;
82
+ preprocessInput(chain: WarpChainInfo, input: string, type: WarpActionInputType, value: string): Promise<string>;
61
83
  static getChainEntrypoint(chainInfo: WarpChainInfo, env: WarpChainEnv): NetworkEntrypoint;
62
84
  }
63
85
 
64
- declare class WarpMultiversxRegistry {
86
+ declare class WarpMultiversxExplorer implements AdapterWarpExplorer {
87
+ private readonly chainInfo;
88
+ constructor(chainInfo: WarpChainInfo);
89
+ getAccountUrl(address: string): string;
90
+ getTransactionUrl(hash: string): string;
91
+ }
92
+
93
+ declare class WarpMultiversxRegistry implements AdapterWarpRegistry {
65
94
  private config;
66
95
  private cache;
67
96
  registryConfig: WarpRegistryConfigInfo;
68
- constructor(config: WarpInitConfig);
97
+ constructor(config: WarpClientConfig);
69
98
  init(): Promise<void>;
70
99
  createWarpRegisterTransaction(txHash: string, alias?: string | null, brand?: string | null): Transaction;
71
100
  createWarpUnregisterTransaction(txHash: string): Transaction;
@@ -77,35 +106,33 @@ declare class WarpMultiversxRegistry {
77
106
  createWarpBrandingTransaction(warpHash: string, brandHash: string): Transaction;
78
107
  getInfoByAlias(alias: string, cache?: WarpCacheConfig): Promise<{
79
108
  registryInfo: WarpRegistryInfo | null;
80
- brand: Brand | null;
109
+ brand: WarpBrand | null;
81
110
  }>;
82
111
  getInfoByHash(hash: string, cache?: WarpCacheConfig): Promise<{
83
112
  registryInfo: WarpRegistryInfo | null;
84
- brand: Brand | null;
113
+ brand: WarpBrand | null;
85
114
  }>;
86
115
  getUserWarpRegistryInfos(user?: string): Promise<WarpRegistryInfo[]>;
87
- getUserBrands(user?: string): Promise<Brand[]>;
116
+ getUserBrands(user?: string): Promise<WarpBrand[]>;
88
117
  getChainInfos(cache?: WarpCacheConfig): Promise<WarpChainInfo[]>;
89
118
  getChainInfo(chain: WarpChain, cache?: WarpCacheConfig): Promise<WarpChainInfo | null>;
90
119
  setChain(info: WarpChainInfo): Promise<Transaction>;
91
120
  removeChain(chain: WarpChain): Promise<Transaction>;
92
- fetchBrand(hash: string, cache?: WarpCacheConfig): Promise<Brand | null>;
93
- getRegistryContractAddress(): Address;
121
+ fetchBrand(hash: string, cache?: WarpCacheConfig): Promise<WarpBrand | null>;
94
122
  private loadRegistryConfigs;
95
123
  private getFactory;
96
124
  private getController;
97
125
  private isCurrentUserAdmin;
98
126
  }
99
127
 
100
- declare class WarpMultiversxResults {
128
+ declare class WarpMultiversxResults implements AdapterWarpResults {
101
129
  private readonly config;
102
130
  private readonly abi;
103
131
  private readonly serializer;
104
132
  private readonly cache;
105
- constructor(config: WarpInitConfig);
106
- getTransactionExecutionResults(warp: Warp, actionIndex: WarpActionIndex, tx: TransactionOnNetwork): Promise<WarpExecution>;
107
- static parseResultsOutIndex(resultPath: string): number | null;
108
- extractContractResults(warp: Warp, actionIndex: WarpActionIndex, tx: TransactionOnNetwork, inputs: ResolvedInput[]): Promise<{
133
+ constructor(config: WarpClientConfig);
134
+ getTransactionExecutionResults(warp: Warp, tx: TransactionOnNetwork): Promise<WarpExecution>;
135
+ extractContractResults(warp: Warp, tx: TransactionOnNetwork, inputs: ResolvedInput[]): Promise<{
109
136
  values: any[];
110
137
  results: WarpExecutionResults;
111
138
  }>;
@@ -125,15 +152,15 @@ declare class WarpMultiversxResults {
125
152
  }): Promise<any>;
126
153
  }
127
154
 
128
- declare class WarpMultiversxSerializer {
155
+ declare class WarpMultiversxSerializer implements AdapterWarpSerializer {
129
156
  readonly coreSerializer: WarpSerializer;
130
157
  constructor();
131
158
  typedToString(value: TypedValue): string;
132
159
  typedToNative(value: TypedValue): [WarpActionInputType, WarpNativeValue];
133
160
  nativeToTyped(type: WarpActionInputType, value: WarpNativeValue): TypedValue;
134
- nativeToType(type: BaseWarpActionInputType): Type;
161
+ nativeToType(type: BaseWarpActionInputType): WarpAdapterGenericType;
135
162
  stringToTyped(value: string): TypedValue;
136
163
  typeToString(type: Type): WarpActionInputType;
137
164
  }
138
165
 
139
- export { WarpMultiversxAbi, WarpMultiversxConstants, WarpMultiversxContractLoader, WarpMultiversxExecutor, WarpMultiversxRegistry, WarpMultiversxResults, WarpMultiversxSerializer, address_value, biguint_value, boolean_value, codemeta_value, composite_value, esdt_value, hex_value, list_value, nothing_value, option_value, optional_value, string_value, token_value, u16_value, u32_value, u64_value, u8_value, variadic_value };
166
+ export { WarpMultiversxAbi, WarpMultiversxBrandBuilder, WarpMultiversxBuilder, WarpMultiversxConstants, WarpMultiversxContractLoader, WarpMultiversxExecutor, WarpMultiversxExplorer, WarpMultiversxRegistry, WarpMultiversxResults, WarpMultiversxSerializer, address_value, biguint_value, boolean_value, codemeta_value, composite_value, esdt_value, getMultiversxAdapter, hex_value, list_value, nothing_value, option_value, optional_value, string_value, token_value, u16_value, u32_value, u64_value, u8_value, variadic_value };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- 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';
2
- import { WarpInitConfig, WarpAbi, WarpCacheConfig, WarpContractAction, WarpQueryAction, WarpChainInfo, WarpContract, WarpContractVerification, WarpExecutable, WarpExecution, WarpChainEnv, WarpRegistryConfigInfo, WarpRegistryInfo, Brand, WarpChain, Warp, WarpActionIndex, ResolvedInput, WarpExecutionResults, WarpSerializer, WarpActionInputType, WarpNativeValue, BaseWarpActionInputType } from '@vleap/warps-core';
1
+ import { WarpClientConfig, Adapter, WarpAbi, WarpCacheConfig, WarpContractAction, WarpQueryAction, WarpBrand, AdapterWarpBuilder, Warp, WarpChainInfo, WarpContract, WarpContractVerification, AdapterWarpExecutor, WarpExecutable, WarpExecution, WarpActionInputType, WarpChainEnv, AdapterWarpExplorer, AdapterWarpRegistry, WarpRegistryConfigInfo, WarpRegistryInfo, WarpChain, AdapterWarpResults, ResolvedInput, WarpExecutionResults, AdapterWarpSerializer, WarpSerializer, WarpNativeValue, BaseWarpActionInputType, WarpAdapterGenericType } from '@vleap/warps';
2
+ import { TypedValue, Type, OptionValue, OptionalValue, List, VariadicValue, CompositeValue, StringValue, U8Value, U16Value, U32Value, U64Value, BigUIntValue, BooleanValue, AddressValue, TokenIdentifierValue, BytesValue, TokenTransfer, Struct, CodeMetadataValue, NothingValue, TransactionOnNetwork, AbiRegistry, Transaction, NetworkEntrypoint } from '@multiversx/sdk-core';
3
3
 
4
4
  declare const WarpMultiversxConstants: {
5
5
  Egld: {
@@ -10,6 +10,8 @@ declare const WarpMultiversxConstants: {
10
10
  };
11
11
  };
12
12
 
13
+ declare const getMultiversxAdapter: (config: WarpClientConfig) => Adapter;
14
+
13
15
  declare const option_value: (value: TypedValue | null, type?: Type) => OptionValue;
14
16
  declare const optional_value: (value: TypedValue | null, type?: Type) => OptionalValue;
15
17
  declare const list_value: (values: TypedValue[]) => List;
@@ -33,7 +35,7 @@ declare class WarpMultiversxAbi {
33
35
  private readonly config;
34
36
  private readonly contractLoader;
35
37
  private readonly cache;
36
- constructor(config: WarpInitConfig);
38
+ constructor(config: WarpClientConfig);
37
39
  createFromRaw(encoded: string): Promise<WarpAbi>;
38
40
  createFromTransaction(tx: TransactionOnNetwork): Promise<WarpAbi>;
39
41
  createFromTransactionHash(hash: string, cache?: WarpCacheConfig): Promise<WarpAbi | null>;
@@ -41,31 +43,58 @@ declare class WarpMultiversxAbi {
41
43
  fetchAbi(action: WarpContractAction | WarpQueryAction): Promise<AbiRegistry>;
42
44
  }
43
45
 
46
+ declare class WarpMultiversxBrandBuilder {
47
+ private config;
48
+ private core;
49
+ constructor(config: WarpClientConfig);
50
+ createInscriptionTransaction(brand: WarpBrand): Transaction;
51
+ createFromTransaction(tx: TransactionOnNetwork, validateSchema?: boolean): Promise<WarpBrand>;
52
+ createFromTransactionHash(hash: string): Promise<WarpBrand | null>;
53
+ }
54
+
55
+ declare class WarpMultiversxBuilder implements AdapterWarpBuilder {
56
+ private config;
57
+ private cache;
58
+ private core;
59
+ constructor(config: WarpClientConfig);
60
+ createInscriptionTransaction(warp: Warp): Transaction;
61
+ createFromTransaction(tx: TransactionOnNetwork, validate?: boolean): Promise<Warp>;
62
+ createFromTransactionHash(hash: string, cache?: WarpCacheConfig): Promise<Warp | null>;
63
+ }
64
+
44
65
  declare class WarpMultiversxContractLoader {
45
66
  private readonly config;
46
- constructor(config: WarpInitConfig);
67
+ constructor(config: WarpClientConfig);
47
68
  getContract(address: string, chain: WarpChainInfo): Promise<WarpContract | null>;
48
69
  getVerificationInfo(address: string, chain: WarpChainInfo): Promise<WarpContractVerification | null>;
49
70
  }
50
71
 
51
- declare class WarpMultiversxExecutor {
72
+ declare class WarpMultiversxExecutor implements AdapterWarpExecutor {
52
73
  private readonly config;
53
74
  private readonly serializer;
54
75
  private readonly abi;
55
76
  private readonly results;
56
- constructor(config: WarpInitConfig);
77
+ constructor(config: WarpClientConfig);
57
78
  createTransaction(executable: WarpExecutable): Promise<Transaction>;
58
79
  createTransferTransaction(executable: WarpExecutable): Promise<Transaction>;
59
80
  createContractCallTransaction(executable: WarpExecutable): Promise<Transaction>;
60
81
  executeQuery(executable: WarpExecutable): Promise<WarpExecution>;
82
+ preprocessInput(chain: WarpChainInfo, input: string, type: WarpActionInputType, value: string): Promise<string>;
61
83
  static getChainEntrypoint(chainInfo: WarpChainInfo, env: WarpChainEnv): NetworkEntrypoint;
62
84
  }
63
85
 
64
- declare class WarpMultiversxRegistry {
86
+ declare class WarpMultiversxExplorer implements AdapterWarpExplorer {
87
+ private readonly chainInfo;
88
+ constructor(chainInfo: WarpChainInfo);
89
+ getAccountUrl(address: string): string;
90
+ getTransactionUrl(hash: string): string;
91
+ }
92
+
93
+ declare class WarpMultiversxRegistry implements AdapterWarpRegistry {
65
94
  private config;
66
95
  private cache;
67
96
  registryConfig: WarpRegistryConfigInfo;
68
- constructor(config: WarpInitConfig);
97
+ constructor(config: WarpClientConfig);
69
98
  init(): Promise<void>;
70
99
  createWarpRegisterTransaction(txHash: string, alias?: string | null, brand?: string | null): Transaction;
71
100
  createWarpUnregisterTransaction(txHash: string): Transaction;
@@ -77,35 +106,33 @@ declare class WarpMultiversxRegistry {
77
106
  createWarpBrandingTransaction(warpHash: string, brandHash: string): Transaction;
78
107
  getInfoByAlias(alias: string, cache?: WarpCacheConfig): Promise<{
79
108
  registryInfo: WarpRegistryInfo | null;
80
- brand: Brand | null;
109
+ brand: WarpBrand | null;
81
110
  }>;
82
111
  getInfoByHash(hash: string, cache?: WarpCacheConfig): Promise<{
83
112
  registryInfo: WarpRegistryInfo | null;
84
- brand: Brand | null;
113
+ brand: WarpBrand | null;
85
114
  }>;
86
115
  getUserWarpRegistryInfos(user?: string): Promise<WarpRegistryInfo[]>;
87
- getUserBrands(user?: string): Promise<Brand[]>;
116
+ getUserBrands(user?: string): Promise<WarpBrand[]>;
88
117
  getChainInfos(cache?: WarpCacheConfig): Promise<WarpChainInfo[]>;
89
118
  getChainInfo(chain: WarpChain, cache?: WarpCacheConfig): Promise<WarpChainInfo | null>;
90
119
  setChain(info: WarpChainInfo): Promise<Transaction>;
91
120
  removeChain(chain: WarpChain): Promise<Transaction>;
92
- fetchBrand(hash: string, cache?: WarpCacheConfig): Promise<Brand | null>;
93
- getRegistryContractAddress(): Address;
121
+ fetchBrand(hash: string, cache?: WarpCacheConfig): Promise<WarpBrand | null>;
94
122
  private loadRegistryConfigs;
95
123
  private getFactory;
96
124
  private getController;
97
125
  private isCurrentUserAdmin;
98
126
  }
99
127
 
100
- declare class WarpMultiversxResults {
128
+ declare class WarpMultiversxResults implements AdapterWarpResults {
101
129
  private readonly config;
102
130
  private readonly abi;
103
131
  private readonly serializer;
104
132
  private readonly cache;
105
- constructor(config: WarpInitConfig);
106
- getTransactionExecutionResults(warp: Warp, actionIndex: WarpActionIndex, tx: TransactionOnNetwork): Promise<WarpExecution>;
107
- static parseResultsOutIndex(resultPath: string): number | null;
108
- extractContractResults(warp: Warp, actionIndex: WarpActionIndex, tx: TransactionOnNetwork, inputs: ResolvedInput[]): Promise<{
133
+ constructor(config: WarpClientConfig);
134
+ getTransactionExecutionResults(warp: Warp, tx: TransactionOnNetwork): Promise<WarpExecution>;
135
+ extractContractResults(warp: Warp, tx: TransactionOnNetwork, inputs: ResolvedInput[]): Promise<{
109
136
  values: any[];
110
137
  results: WarpExecutionResults;
111
138
  }>;
@@ -125,15 +152,15 @@ declare class WarpMultiversxResults {
125
152
  }): Promise<any>;
126
153
  }
127
154
 
128
- declare class WarpMultiversxSerializer {
155
+ declare class WarpMultiversxSerializer implements AdapterWarpSerializer {
129
156
  readonly coreSerializer: WarpSerializer;
130
157
  constructor();
131
158
  typedToString(value: TypedValue): string;
132
159
  typedToNative(value: TypedValue): [WarpActionInputType, WarpNativeValue];
133
160
  nativeToTyped(type: WarpActionInputType, value: WarpNativeValue): TypedValue;
134
- nativeToType(type: BaseWarpActionInputType): Type;
161
+ nativeToType(type: BaseWarpActionInputType): WarpAdapterGenericType;
135
162
  stringToTyped(value: string): TypedValue;
136
163
  typeToString(type: Type): WarpActionInputType;
137
164
  }
138
165
 
139
- export { WarpMultiversxAbi, WarpMultiversxConstants, WarpMultiversxContractLoader, WarpMultiversxExecutor, WarpMultiversxRegistry, WarpMultiversxResults, WarpMultiversxSerializer, address_value, biguint_value, boolean_value, codemeta_value, composite_value, esdt_value, hex_value, list_value, nothing_value, option_value, optional_value, string_value, token_value, u16_value, u32_value, u64_value, u8_value, variadic_value };
166
+ export { WarpMultiversxAbi, WarpMultiversxBrandBuilder, WarpMultiversxBuilder, WarpMultiversxConstants, WarpMultiversxContractLoader, WarpMultiversxExecutor, WarpMultiversxExplorer, WarpMultiversxRegistry, WarpMultiversxResults, WarpMultiversxSerializer, address_value, biguint_value, boolean_value, codemeta_value, composite_value, esdt_value, getMultiversxAdapter, hex_value, list_value, nothing_value, option_value, optional_value, string_value, token_value, u16_value, u32_value, u64_value, u8_value, variadic_value };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var M=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var J=Object.prototype.hasOwnProperty;var X=(s,t)=>{for(var e in t)M(s,e,{get:t[e],enumerable:!0})},Y=(s,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of K(t))!J.call(s,a)&&a!==e&&M(s,a,{get:()=>t[a],enumerable:!(n=q(t,a))||n.enumerable});return s};var Z=s=>Y(M({},"__esModule",{value:!0}),s);var wt={};X(wt,{WarpMultiversxAbi:()=>F,WarpMultiversxConstants:()=>tt,WarpMultiversxContractLoader:()=>U,WarpMultiversxExecutor:()=>V,WarpMultiversxRegistry:()=>D,WarpMultiversxResults:()=>O,WarpMultiversxSerializer:()=>S,address_value:()=>lt,biguint_value:()=>ut,boolean_value:()=>pt,codemeta_value:()=>dt,composite_value:()=>st,esdt_value:()=>yt,hex_value:()=>gt,list_value:()=>nt,nothing_value:()=>mt,option_value:()=>et,optional_value:()=>rt,string_value:()=>E,token_value:()=>ft,u16_value:()=>ot,u32_value:()=>Q,u64_value:()=>ct,u8_value:()=>it,variadic_value:()=>at});module.exports=Z(wt);var tt={Egld:{Identifier:"EGLD",EsdtIdentifier:"EGLD-000000",DisplayName:"eGold",Decimals:18}};var i=require("@multiversx/sdk-core"),et=(s,t)=>s?i.OptionValue.newProvided(s):t?i.OptionValue.newMissingTyped(t):i.OptionValue.newMissing(),rt=(s,t)=>s?new i.OptionalValue(s.getType(),s):t?new i.OptionalValue(t):i.OptionalValue.newMissing(),nt=s=>{if(s.length===0)throw new Error("Cannot create a list from an empty array");let t=s[0].getType();return new i.List(t,s)},at=s=>i.VariadicValue.fromItems(...s),st=s=>{let t=s.map(e=>e.getType());return new i.CompositeValue(new i.CompositeType(...t),s)},E=s=>i.StringValue.fromUTF8(s),it=s=>new i.U8Value(s),ot=s=>new i.U16Value(s),Q=s=>new i.U32Value(s),ct=s=>new i.U64Value(s),ut=s=>new i.BigUIntValue(BigInt(s)),pt=s=>new i.BooleanValue(s),lt=s=>new i.AddressValue(i.Address.newFromBech32(s)),ft=s=>new i.TokenIdentifierValue(s),gt=s=>i.BytesValue.fromHex(s),yt=s=>new i.Struct(new i.StructType("EsdtTokenPayment",[new i.FieldDefinition("token_identifier","",new i.TokenIdentifierType),new i.FieldDefinition("token_nonce","",new i.U64Type),new i.FieldDefinition("amount","",new i.BigUIntType)]),[new i.Field(new i.TokenIdentifierValue(s.token.identifier),"token_identifier"),new i.Field(new i.U64Value(BigInt(s.token.nonce)),"token_nonce"),new i.Field(new i.BigUIntValue(BigInt(s.amount)),"amount")]),dt=s=>new i.CodeMetadataValue(i.CodeMetadata.newFromBytes(Uint8Array.from(Buffer.from(s,"hex")))),mt=()=>new i.NothingValue;var $=require("@multiversx/sdk-core"),I=require("@vleap/warps-core");var H=require("@vleap/warps-core");var w=require("@multiversx/sdk-core"),R=require("@vleap/warps-core");var _=require("@multiversx/sdk-core"),h=require("@vleap/warps-core");var r=require("@multiversx/sdk-core"),C=require("@vleap/warps-core"),j=new RegExp(`${C.WarpConstants.ArgParamsSeparator}(.*)`),S=class{constructor(){this.coreSerializer=new C.WarpSerializer}typedToString(t){if(t.hasClassOrSuperclass(r.OptionValue.ClassName))return t.isSet()?`option:${this.typedToString(t.getTypedValue())}`:"option:null";if(t.hasClassOrSuperclass(r.OptionalValue.ClassName))return t.isSet()?`optional:${this.typedToString(t.getTypedValue())}`:"optional:null";if(t.hasClassOrSuperclass(r.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(r.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(r.CompositeValue.ClassName)){let e=t.getItems(),n=e.map(o=>this.typedToString(o).split(C.WarpConstants.ArgParamsSeparator)[0]),a=e.map(o=>this.typedToString(o).split(C.WarpConstants.ArgParamsSeparator)[1]),c=n.join(C.WarpConstants.ArgCompositeSeparator),u=a.join(C.WarpConstants.ArgCompositeSeparator);return`composite(${c}):${u}`}if(t.hasClassOrSuperclass(r.BigUIntValue.ClassName)||t.getType().getName()==="BigUint")return`biguint:${BigInt(t.valueOf().toFixed())}`;if(t.hasClassOrSuperclass(r.U8Value.ClassName))return`uint8:${t.valueOf().toNumber()}`;if(t.hasClassOrSuperclass(r.U16Value.ClassName))return`uint16:${t.valueOf().toNumber()}`;if(t.hasClassOrSuperclass(r.U32Value.ClassName))return`uint32:${t.valueOf().toNumber()}`;if(t.hasClassOrSuperclass(r.U64Value.ClassName))return`uint64:${BigInt(t.valueOf().toFixed())}`;if(t.hasClassOrSuperclass(r.StringValue.ClassName))return`string:${t.valueOf()}`;if(t.hasClassOrSuperclass(r.BooleanValue.ClassName))return`bool:${t.valueOf()}`;if(t.hasClassOrSuperclass(r.AddressValue.ClassName))return`address:${t.valueOf().bech32()}`;if(t.hasClassOrSuperclass(r.TokenIdentifierValue.ClassName))return`token:${t.valueOf()}`;if(t.hasClassOrSuperclass(r.BytesValue.ClassName))return`hex:${t.valueOf().toString("hex")}`;if(t.hasClassOrSuperclass(r.CodeMetadataValue.ClassName))return`codemeta:${t.valueOf().toBuffer().toString("hex")}`;if(t.getType().getName()==="EsdtTokenPayment"){let e=t.getFieldValue("token_identifier").valueOf(),n=t.getFieldValue("token_nonce").valueOf(),a=t.getFieldValue("amount").valueOf();return`esdt:${e}|${n}|${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 n=this.coreSerializer.nativeToString(t,e);return this.stringToTyped(n)}nativeToType(t){if(t.startsWith("composite")){let e=t.match(/\(([^)]+)\)/)?.[1];return new r.CompositeType(...e.split(C.WarpConstants.ArgCompositeSeparator).map(n=>this.nativeToType(n)))}if(t==="string")return new r.StringType;if(t==="uint8")return new r.U8Type;if(t==="uint16")return new r.U16Type;if(t==="uint32")return new r.U32Type;if(t==="uint64")return new r.U64Type;if(t==="biguint")return new r.BigUIntType;if(t==="bool")return new r.BooleanType;if(t==="address")return new r.AddressType;if(t==="token")return new r.TokenIdentifierType;if(t==="hex")return new r.BytesType;if(t==="codemeta")return new r.CodeMetadataType;if(t==="esdt"||t==="nft")return new r.StructType("EsdtTokenPayment",[new r.FieldDefinition("token_identifier","",new r.TokenIdentifierType),new r.FieldDefinition("token_nonce","",new r.U64Type),new r.FieldDefinition("amount","",new r.BigUIntType)]);throw new Error(`WarpArgSerializer (nativeToType): Unsupported input type: ${t}`)}stringToTyped(t){let[e,n]=t.split(/:(.*)/,2);if(e==="null"||e===null)return new r.NothingValue;if(e==="option"){let a=this.stringToTyped(n);return a instanceof r.NothingValue?r.OptionValue.newMissingTyped(a.getType()):r.OptionValue.newProvided(a)}if(e==="optional"){let a=this.stringToTyped(n);return a instanceof r.NothingValue?r.OptionalValue.newMissing():new r.OptionalValue(a.getType(),a)}if(e==="list"){let[a,c]=n.split(j,2),o=c.split(",").map(f=>this.stringToTyped(`${a}:${f}`));return new r.List(this.nativeToType(a),o)}if(e==="variadic"){let[a,c]=n.split(j,2),o=c.split(",").map(f=>this.stringToTyped(`${a}:${f}`));return new r.VariadicValue(new r.VariadicType(this.nativeToType(a)),o)}if(e.startsWith("composite")){let a=e.match(/\(([^)]+)\)/)?.[1],c=n.split(C.WarpConstants.ArgCompositeSeparator),u=a.split(C.WarpConstants.ArgCompositeSeparator),o=c.map((l,g)=>this.stringToTyped(`${u[g]}:${l}`)),f=o.map(l=>l.getType());return new r.CompositeValue(new r.CompositeType(...f),o)}if(e==="string")return n?r.StringValue.fromUTF8(n):new r.NothingValue;if(e==="uint8")return n?new r.U8Value(Number(n)):new r.NothingValue;if(e==="uint16")return n?new r.U16Value(Number(n)):new r.NothingValue;if(e==="uint32")return n?new r.U32Value(Number(n)):new r.NothingValue;if(e==="uint64")return n?new r.U64Value(BigInt(n)):new r.NothingValue;if(e==="biguint")return n?new r.BigUIntValue(BigInt(n)):new r.NothingValue;if(e==="bool")return n?new r.BooleanValue(typeof n=="boolean"?n:n==="true"):new r.NothingValue;if(e==="address")return n?new r.AddressValue(r.Address.newFromBech32(n)):new r.NothingValue;if(e==="token")return n?new r.TokenIdentifierValue(n):new r.NothingValue;if(e==="hex")return n?r.BytesValue.fromHex(n):new r.NothingValue;if(e==="codemeta")return new r.CodeMetadataValue(r.CodeMetadata.newFromBytes(Uint8Array.from(Buffer.from(n,"hex"))));if(e==="esdt"){let a=n.split(C.WarpConstants.ArgCompositeSeparator);return new r.Struct(this.nativeToType("esdt"),[new r.Field(new r.TokenIdentifierValue(a[0]),"token_identifier"),new r.Field(new r.U64Value(BigInt(a[1])),"token_nonce"),new r.Field(new r.BigUIntValue(BigInt(a[2])),"amount")])}throw new Error(`WarpArgSerializer (stringToTyped): Unsupported input type: ${e}`)}typeToString(t){if(t instanceof r.OptionType)return"option:"+this.typeToString(t.getFirstTypeParameter());if(t instanceof r.OptionalType)return"optional:"+this.typeToString(t.getFirstTypeParameter());if(t instanceof r.ListType)return"list:"+this.typeToString(t.getFirstTypeParameter());if(t instanceof r.VariadicType)return"variadic:"+this.typeToString(t.getFirstTypeParameter());if(t instanceof r.StringType)return"string";if(t instanceof r.U8Type)return"uint8";if(t instanceof r.U16Type)return"uint16";if(t instanceof r.U32Type)return"uint32";if(t instanceof r.U64Type)return"uint64";if(t instanceof r.BigUIntType)return"biguint";if(t instanceof r.BooleanType)return"bool";if(t instanceof r.AddressType)return"address";if(t instanceof r.TokenIdentifierType)return"token";if(t instanceof r.BytesType)return"hex";if(t instanceof r.CodeMetadataType)return"codemeta";if(t instanceof r.StructType&&t.getClassName()==="EsdtTokenPayment")return"esdt";throw new Error(`WarpArgSerializer (typeToString): Unsupported input type: ${t.getClassName()}`)}};var O=class{constructor(t){this.config=t;this.abi=new F(t),this.serializer=new S,this.cache=new h.WarpCache(t.cache?.type)}async getTransactionExecutionResults(t,e,n){let a=this.cache.get(h.WarpCacheKey.WarpExecutable(this.config.env,t.meta?.hash||"",e))??[],c=await this.extractContractResults(t,e,n,a),u=(0,h.getNextInfo)(this.config,t,e,c),o=(0,h.applyResultsToMessages)(t,c.results);return{success:n.status.isSuccessful(),warp:t,action:e,user:this.config.user?.wallet||null,txHash:n.hash,next:u,values:c.values,results:c.results,messages:o}}static parseResultsOutIndex(t){if(t==="out")return 1;let e=t.match(/^out\[(\d+)\]/);return e?parseInt(e[1],10):(t.startsWith("out.")||t.startsWith("event."),null)}async extractContractResults(t,e,n,a){let c=(0,h.getWarpActionByIndex)(t,e),u=[],o={};if(!t.results||c.type!=="contract")return{values:u,results:o};if(!Object.values(t.results).some(b=>b.includes("out")||b.includes("event"))){for(let[b,d]of Object.entries(t.results))o[b]=d;return{values:u,results:await(0,h.evaluateResultsCommon)(t,o,e,a)}}let l=await this.abi.getAbiForAction(c),g=new _.TransactionEventsParser({abi:l}),v=new _.SmartContractTransactionsOutcomeParser({abi:l}).parseExecute({transactionOnNetwork:n,function:c.func||void 0});for(let[b,d]of Object.entries(t.results)){if(d.startsWith(h.WarpConstants.Transform.Prefix))continue;if(d.startsWith("input.")){o[b]=d;continue}let x=(0,h.parseResultsOutIndex)(d);if(x!==null&&x!==e){o[b]=null;continue}let[W,B,A]=d.split(".");if(W==="event"){if(!B||isNaN(Number(A)))continue;let N=Number(A),T=(0,_.findEventsByFirstTopic)(n,B),P=g.parseEvents({events:T})[0],k=Object.values(P)[N]||null;u.push(k),o[b]=k&&k.valueOf()}else if(W==="out"||W.startsWith("out[")){if(!B)continue;let N=Number(B),T=v.values[N-1]||null;A&&(T=T[A]||null),T&&typeof T=="object"&&(T="toFixed"in T?T.toFixed():T.valueOf()),u.push(T),o[b]=T&&T.valueOf()}else o[b]=d}return{values:u,results:await(0,h.evaluateResultsCommon)(t,o,e,a)}}async extractQueryResults(t,e,n,a){let c=e.map(l=>this.serializer.typedToString(l)),u=e.map(l=>this.serializer.typedToNative(l)[1]),o={};if(!t.results)return{values:c,results:o};let f=l=>{let g=l.split(".").slice(1).map(v=>parseInt(v)-1);if(g.length===0)return;let y=u[g[0]];for(let v=1;v<g.length;v++){if(y==null)return;y=y[g[v]]}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!==n){o[l]=null;continue}g.startsWith("out.")||g==="out"||g.startsWith("out[")?o[l]=f(g)||null:o[l]=g}return{values:c,results:await(0,h.evaluateResultsCommon)(t,o,n,a)}}async resolveWarpResultsRecursively(t){let e=t.warp,n=t.entryActionIndex,a=t.executor,c=t.inputs,u=t.meta,o=new Map,f=new Set,l=this;async function g(d,x=[]){if(o.has(d))return o.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 B;if(W.type==="query")B=await a.executeQuery(e,d,x);else if(W.type==="collect")B=await a.executeCollect(e,d,x,u);else throw new Error(`Unsupported or interactive action type: ${W.type}`);if(o.set(d,B),e.results)for(let A of Object.values(e.results)){let T=String(A).match(/^out\[(\d+)\]/);if(T){let P=parseInt(T[1],10);P!==d&&!o.has(P)&&await g(P)}}return f.delete(d),B}await g(n,c);let y={};for(let d of o.values())for(let[x,W]of Object.entries(d.results))W!==null?y[x]=W:x in y||(y[x]=null);let v=await(0,h.evaluateResultsCommon)(e,y,n,c);return{...o.get(n),action:n,results:v}}};var V=class s{constructor(t){this.config=t;this.serializer=new S,this.abi=new F(this.config),this.results=new O(this.config)}async createTransaction(t){let e=(0,R.getWarpActionByIndex)(t.warp,t.action),n=null;if(e.type==="transfer")n=await this.createTransferTransaction(t);else if(e.type==="contract")n=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(!n)throw new Error(`WarpMultiversxExecutor: Invalid action type (${e.type})`);return n}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),n=new w.TransactionsFactoryConfig({chainID:t.chain.chainId}),a=t.data?Buffer.from(this.serializer.stringToTyped(t.data).valueOf()):null;return new w.TransferTransactionsFactory({config:n}).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,R.getWarpActionByIndex)(t.warp,t.action),n=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(n,{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,R.getWarpActionByIndex)(t.warp,t.action);if(e.type!=="query")throw new Error(`WarpMultiversxExecutor: Invalid action type for executeQuery: ${e.type}`);let n=await this.abi.getAbiForAction(e),a=t.args.map(A=>this.serializer.stringToTyped(A)),c=s.getChainEntrypoint(t.chain,this.config.env),u=w.Address.newFromBech32(t.destination),o=c.createSmartContractController(n),f=o.createQuery({contract:u,function:e.func||"",arguments:a}),l=await o.runQuery(f),g=l.returnCode==="ok",y=new w.ArgSerializer,v=n.getEndpoint(l.function||e.func||""),b=(l.returnDataParts||[]).map(A=>Buffer.from(A)),d=y.buffersToValues(b,v.output),{values:x,results:W}=await this.results.extractQueryResults(t.warp,d,t.action,t.resolvedInputs),B=(0,R.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:B,values:x,results:W,messages:(0,R.applyResultsToMessages)(t.warp,W)}}static getChainEntrypoint(t,e){let n="warp-sdk",a="api";return e==="devnet"?new w.DevnetEntrypoint(t.apiUrl,a,n):e==="testnet"?new w.TestnetEntrypoint(t.apiUrl,a,n):new w.MainnetEntrypoint(t.apiUrl,a,n)}};var U=class{constructor(t){this.config=t}async getContract(t,e){try{let c=await V.getChainEntrypoint(e,this.config.env).createNetworkProvider().doGetGeneric(`accounts/${t}`);return{address:t,owner:c.ownerAddress,verified:c.isVerified||!1}}catch(n){return H.WarpLogger.error("WarpContractLoader: getContract error",n),null}}async getVerificationInfo(t,e){try{let c=await V.getChainEntrypoint(e,this.config.env).createNetworkProvider().doGetGeneric(`accounts/${t}/verification`);return{codeHash:c.codeHash,abi:c.source.abi}}catch(n){return H.WarpLogger.error("WarpContractLoader: getVerificationInfo error",n),null}}};var F=class{constructor(t){this.config=t;this.contractLoader=new U(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 n=I.WarpCacheKey.WarpAbi(this.config.env,t);if(e){let o=this.cache.get(n);if(o)return I.WarpLogger.info(`WarpAbiBuilder (createFromTransactionHash): Warp abi found in cache: ${t}`),o}let a=(0,I.getMainChainInfo)(this.config),u=V.getChainEntrypoint(a,this.config.env).createNetworkProvider();try{let o=await u.getTransaction(t),f=await this.createFromTransaction(o);return e&&e.ttl&&f&&this.cache.set(n,f,e.ttl),f}catch(o){return I.WarpLogger.error("WarpAbiBuilder: Error creating from transaction hash",o),null}}async getAbiForAction(t){if(t.abi)return await this.fetchAbi(t);if(!t.address)throw new Error("WarpActionExecutor: Address not found");let e=(0,I.getMainChainInfo)(this.config),n=await this.contractLoader.getVerificationInfo(t.address,e);if(!n)throw new Error("WarpActionExecutor: Verification info not found");return $.AbiRegistry.create(n.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],n=await this.createFromTransactionHash(e);if(!n)throw new Error(`WarpActionExecutor: ABI not found for hash: ${t.abi}`);return $.AbiRegistry.create(n.content)}else{let n=await(await fetch(t.abi)).json();return $.AbiRegistry.create(n)}}};var p=require("@multiversx/sdk-core"),m=require("@vleap/warps-core");var z={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 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}),G=s=>({unitPrice:BigInt(s.unit_price.toString()),admins:s.admins.map(t=>t.toBech32())});var D=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,n){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&&n?this.registryConfig.unitPrice*BigInt(3):e?this.registryConfig.unitPrice*BigInt(2):this.registryConfig.unitPrice,u=()=>e&&n?[p.BytesValue.fromHex(t),p.BytesValue.fromUTF8(e),p.BytesValue.fromHex(n)]: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 n=p.Address.newFromBech32(this.config.user.wallet);return this.getFactory().createTransactionForExecute(n,{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 n=p.Address.newFromBech32(this.config.user.wallet);return this.getFactory().createTransactionForExecute(n,{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 n=p.Address.newFromBech32(this.config.user.wallet);return this.getFactory().createTransactionForExecute(n,{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 n=p.Address.newFromBech32(this.config.user.wallet);return this.getFactory().createTransactionForExecute(n,{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 n=m.WarpCacheKey.RegistryInfo(this.config.env,t),a=e?this.cache.get(n):null;if(a)return m.WarpLogger.info(`WarpRegistry (getInfoByAlias): RegistryInfo found in cache: ${t}`),a;let c=this.getRegistryContractAddress(),u=this.getController(),o=u.createQuery({contract:c,function:"getInfoByAlias",arguments:[p.BytesValue.fromUTF8(t)]}),f=await u.runQuery(o),[l]=u.parseQueryResponse(f),g=l?L(l):null,y=g?.brand?await this.fetchBrand(g.brand):null;return e&&e.ttl&&this.cache.set(n,{registryInfo:g,brand:y},e.ttl),{registryInfo:g,brand:y}}catch{return{registryInfo:null,brand:null}}}async getInfoByHash(t,e){try{let n=m.WarpCacheKey.RegistryInfo(this.config.env,t);if(e){let y=this.cache.get(n);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)]}),o=await c.runQuery(u),[f]=c.parseQueryResponse(o),l=f?L(f):null,g=l?.brand?await this.fetchBrand(l.brand):null;return e&&e.ttl&&this.cache.set(n,{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 n=this.getRegistryContractAddress(),a=this.getController(),c=a.createQuery({contract:n,function:"getUserWarps",arguments:[new p.AddressValue(new p.Address(e))]}),u=await a.runQuery(c),[o]=a.parseQueryResponse(u);return o.map(L)}catch{return[]}}async getUserBrands(t){try{let e=t||this.config.user?.wallet;if(!e)throw new Error("WarpRegistry: user address not set");let n=this.getRegistryContractAddress(),a=this.getController(),c=a.createQuery({contract:n,function:"getUserBrands",arguments:[new p.AddressValue(new p.Address(e))]}),u=await a.runQuery(c),[o]=a.parseQueryResponse(u),f=o.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 n=this.getRegistryContractAddress(),a=this.getController(),c=a.createQuery({contract:n,function:"getChains",arguments:[]}),u=await a.runQuery(c),[o]=a.parseQueryResponse(u),f=o.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 n=m.WarpCacheKey.ChainInfo(this.config.env,t),a=e?this.cache.get(n):null;if(a)return m.WarpLogger.info(`WarpRegistry (getChainInfo): ChainInfo found in cache: ${t}`),a;let c=this.getRegistryContractAddress(),u=this.getController(),o=u.createQuery({contract:c,function:"getChain",arguments:[p.BytesValue.fromUTF8(t)]}),f=await u.runQuery(o),[l]=u.parseQueryResponse(f),g=l?(0,m.toTypedChainInfo)(l):null;return e&&e.ttl&&g&&this.cache.set(n,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:[E(t.name),E(t.displayName),E(t.chainId),Q(t.blockTime),E(t.addressHrp),E(t.apiUrl),E(t.explorerUrl),E(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:[E(t)]})}async fetchBrand(t,e){let n=m.WarpCacheKey.Brand(this.config.env,t),a=e?this.cache.get(n):null;if(a)return m.WarpLogger.info(`WarpRegistry (fetchBrand): Brand found in cache: ${t}`),a;let c=(0,m.getMainChainInfo)(this.config),o=V.getChainEntrypoint(c,this.config.env).createNetworkProvider();try{let f=await o.getTransaction(t),l=JSON.parse(f.data.toString());return l.meta={hash:f.hash,creator:f.sender.bech32(),createdAt:new Date(f.timestamp*1e3).toISOString()},e&&e.ttl&&this.cache.set(n,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(),[n]=await e.query({contract:t,function:"getConfig",arguments:[]}),a=n?G(n):null;this.registryConfig=a||{unitPrice:BigInt(0),admins:[]}}getFactory(){let t=(0,m.getMainChainInfo)(this.config),e=new p.TransactionsFactoryConfig({chainID:t.chainId}),n=p.AbiRegistry.create(z);return new p.SmartContractTransactionsFactory({config:e,abi:n})}getController(){let t=(0,m.getMainChainInfo)(this.config),e=V.getChainEntrypoint(t,this.config.env),n=p.AbiRegistry.create(z);return e.createSmartContractController(n)}isCurrentUserAdmin(){return!!this.config.user?.wallet&&this.registryConfig.admins.includes(this.config.user.wallet)}};0&&(module.exports={WarpMultiversxAbi,WarpMultiversxConstants,WarpMultiversxContractLoader,WarpMultiversxExecutor,WarpMultiversxRegistry,WarpMultiversxResults,WarpMultiversxSerializer,address_value,biguint_value,boolean_value,codemeta_value,composite_value,esdt_value,hex_value,list_value,nothing_value,option_value,optional_value,string_value,token_value,u16_value,u32_value,u64_value,u8_value,variadic_value});
1
+ "use strict";var K=Object.defineProperty;var at=Object.getOwnPropertyDescriptor;var it=Object.getOwnPropertyNames;var st=Object.prototype.hasOwnProperty;var ot=(i,t)=>{for(var e in t)K(i,e,{get:t[e],enumerable:!0})},ct=(i,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of it(t))!st.call(i,a)&&a!==e&&K(i,a,{get:()=>t[a],enumerable:!(r=at(t,a))||r.enumerable});return i};var ut=i=>ct(K({},"__esModule",{value:!0}),i);var Et={};ot(Et,{WarpMultiversxAbi:()=>_,WarpMultiversxBrandBuilder:()=>tt,WarpMultiversxBuilder:()=>L,WarpMultiversxConstants:()=>pt,WarpMultiversxContractLoader:()=>q,WarpMultiversxExecutor:()=>b,WarpMultiversxExplorer:()=>z,WarpMultiversxRegistry:()=>Q,WarpMultiversxResults:()=>O,WarpMultiversxSerializer:()=>P,address_value:()=>Ct,biguint_value:()=>Tt,boolean_value:()=>Wt,codemeta_value:()=>It,composite_value:()=>dt,esdt_value:()=>Y,getMultiversxAdapter:()=>Bt,hex_value:()=>vt,list_value:()=>gt,nothing_value:()=>At,option_value:()=>lt,optional_value:()=>ft,string_value:()=>R,token_value:()=>bt,u16_value:()=>ht,u32_value:()=>X,u64_value:()=>wt,u8_value:()=>yt,variadic_value:()=>mt});module.exports=ut(Et);var pt={Egld:{Identifier:"EGLD",EsdtIdentifier:"EGLD-000000",DisplayName:"eGold",Decimals:18}};var k=require("@multiversx/sdk-core"),S=require("@vleap/warps");var d=require("@multiversx/sdk-core"),x=require("@vleap/warps");var j=require("@multiversx/sdk-core"),B=require("@vleap/warps");var J=require("@vleap/warps");var q=class{constructor(t){this.config=t}async getContract(t,e){try{let o=await b.getChainEntrypoint(e,this.config.env).createNetworkProvider().doGetGeneric(`accounts/${t}`);return{address:t,owner:o.ownerAddress,verified:o.isVerified||!1}}catch(r){return J.WarpLogger.error("WarpContractLoader: getContract error",r),null}}async getVerificationInfo(t,e){try{let o=await b.getChainEntrypoint(e,this.config.env).createNetworkProvider().doGetGeneric(`accounts/${t}/verification`);return{codeHash:o.codeHash,abi:o.source.abi}}catch(r){return J.WarpLogger.error("WarpContractLoader: getVerificationInfo error",r),null}}};var _=class{constructor(t){this.config=t;this.contractLoader=new q(this.config),this.cache=new B.WarpCache(this.config.cache?.type)}async createFromRaw(t){return JSON.parse(t)}async createFromTransaction(t){let e=await this.createFromRaw(t.data.toString());return e.meta={hash:t.hash,creator:t.sender.bech32(),createdAt:new Date(t.timestamp*1e3).toISOString()},e}async createFromTransactionHash(t,e){let r=B.WarpCacheKey.WarpAbi(this.config.env,t);if(e){let s=this.cache.get(r);if(s)return B.WarpLogger.info(`WarpAbiBuilder (createFromTransactionHash): Warp abi found in cache: ${t}`),s}let a=(0,B.getMainChainInfo)(this.config),p=b.getChainEntrypoint(a,this.config.env).createNetworkProvider();try{let s=await p.getTransaction(t),f=await this.createFromTransaction(s);return e&&e.ttl&&f&&this.cache.set(r,f,e.ttl),f}catch(s){return B.WarpLogger.error("WarpAbiBuilder: Error creating from transaction hash",s),null}}async getAbiForAction(t){if(t.abi)return await this.fetchAbi(t);if(!t.address)throw new Error("WarpActionExecutor: Address not found");let e=(0,B.getMainChainInfo)(this.config),r=await this.contractLoader.getVerificationInfo(t.address,e);if(!r)throw new Error("WarpActionExecutor: Verification info not found");return j.AbiRegistry.create(r.abi)}async fetchAbi(t){if(!t.abi)throw new Error("WarpActionExecutor: ABI not found");if(t.abi.startsWith(B.WarpConstants.IdentifierType.Hash)){let e=t.abi.split(B.WarpConstants.IdentifierParamSeparator)[1],r=await this.createFromTransactionHash(e);if(!r)throw new Error(`WarpActionExecutor: ABI not found for hash: ${t.abi}`);return j.AbiRegistry.create(r.content)}else{let r=await(await fetch(t.abi)).json();return j.AbiRegistry.create(r)}}};var $=require("@multiversx/sdk-core"),h=require("@vleap/warps");var n=require("@multiversx/sdk-core"),v=require("@vleap/warps"),et=new RegExp(`${v.WarpConstants.ArgParamsSeparator}(.*)`),P=class{constructor(){this.coreSerializer=new v.WarpSerializer}typedToString(t){if(t.hasClassOrSuperclass(n.OptionValue.ClassName))return t.isSet()?`option:${this.typedToString(t.getTypedValue())}`:"option:null";if(t.hasClassOrSuperclass(n.OptionalValue.ClassName))return t.isSet()?`optional:${this.typedToString(t.getTypedValue())}`:"optional:null";if(t.hasClassOrSuperclass(n.List.ClassName)){let e=t.getItems(),a=e.map(p=>this.typedToString(p).split(v.WarpConstants.ArgParamsSeparator)[0])[0],o=e.map(p=>this.typedToString(p).split(v.WarpConstants.ArgParamsSeparator)[1]);return`list:${a}:${o.join(",")}`}if(t.hasClassOrSuperclass(n.VariadicValue.ClassName)){let e=t.getItems(),a=e.map(p=>this.typedToString(p).split(v.WarpConstants.ArgParamsSeparator)[0])[0],o=e.map(p=>this.typedToString(p).split(v.WarpConstants.ArgParamsSeparator)[1]);return`variadic:${a}:${o.join(",")}`}if(t.hasClassOrSuperclass(n.CompositeValue.ClassName)){let e=t.getItems(),r=e.map(s=>this.typedToString(s).split(v.WarpConstants.ArgParamsSeparator)[0]),a=e.map(s=>this.typedToString(s).split(v.WarpConstants.ArgParamsSeparator)[1]),o=r.join(v.WarpConstants.ArgCompositeSeparator),p=a.join(v.WarpConstants.ArgCompositeSeparator);return`composite(${o}):${p}`}if(t.hasClassOrSuperclass(n.BigUIntValue.ClassName)||t.getType().getName()==="BigUint")return`biguint:${BigInt(t.valueOf().toFixed())}`;if(t.hasClassOrSuperclass(n.U8Value.ClassName))return`uint8:${t.valueOf().toNumber()}`;if(t.hasClassOrSuperclass(n.U16Value.ClassName))return`uint16:${t.valueOf().toNumber()}`;if(t.hasClassOrSuperclass(n.U32Value.ClassName))return`uint32:${t.valueOf().toNumber()}`;if(t.hasClassOrSuperclass(n.U64Value.ClassName))return`uint64:${BigInt(t.valueOf().toFixed())}`;if(t.hasClassOrSuperclass(n.StringValue.ClassName))return`string:${t.valueOf()}`;if(t.hasClassOrSuperclass(n.BooleanValue.ClassName))return`bool:${t.valueOf()}`;if(t.hasClassOrSuperclass(n.AddressValue.ClassName))return`address:${t.valueOf().bech32()}`;if(t.hasClassOrSuperclass(n.TokenIdentifierValue.ClassName))return`token:${t.valueOf()}`;if(t.hasClassOrSuperclass(n.BytesValue.ClassName))return`hex:${t.valueOf().toString("hex")}`;if(t.hasClassOrSuperclass(n.CodeMetadataValue.ClassName))return`codemeta:${t.valueOf().toBuffer().toString("hex")}`;if(t.getType().getName()==="EsdtTokenPayment"){let e=t.getFieldValue("token_identifier").valueOf(),r=t.getFieldValue("token_nonce").valueOf(),a=t.getFieldValue("amount").valueOf();return`esdt:${e}|${r}|${a}`}throw new Error(`WarpArgSerializer (typedToString): Unsupported input type: ${t.getClassName()}`)}typedToNative(t){let e=this.typedToString(t);return this.coreSerializer.stringToNative(e)}nativeToTyped(t,e){let r=this.coreSerializer.nativeToString(t,e);return this.stringToTyped(r)}nativeToType(t){if(t.startsWith("composite")){let e=t.match(/\(([^)]+)\)/)?.[1];return new n.CompositeType(...e.split(v.WarpConstants.ArgCompositeSeparator).map(r=>this.nativeToType(r)))}if(t==="string")return new n.StringType;if(t==="uint8")return new n.U8Type;if(t==="uint16")return new n.U16Type;if(t==="uint32")return new n.U32Type;if(t==="uint64")return new n.U64Type;if(t==="biguint")return new n.BigUIntType;if(t==="bool")return new n.BooleanType;if(t==="address")return new n.AddressType;if(t==="token")return new n.TokenIdentifierType;if(t==="hex")return new n.BytesType;if(t==="codemeta")return new n.CodeMetadataType;if(t==="esdt"||t==="nft")return new n.StructType("EsdtTokenPayment",[new n.FieldDefinition("token_identifier","",new n.TokenIdentifierType),new n.FieldDefinition("token_nonce","",new n.U64Type),new n.FieldDefinition("amount","",new n.BigUIntType)]);throw new Error(`WarpArgSerializer (nativeToType): Unsupported input type: ${t}`)}stringToTyped(t){let[e,r]=t.split(/:(.*)/,2);if(e==="null"||e===null)return new n.NothingValue;if(e==="option"){let a=this.stringToTyped(r);return a instanceof n.NothingValue?n.OptionValue.newMissingTyped(a.getType()):n.OptionValue.newProvided(a)}if(e==="optional"){let a=this.stringToTyped(r);return a instanceof n.NothingValue?n.OptionalValue.newMissing():new n.OptionalValue(a.getType(),a)}if(e==="list"){let[a,o]=r.split(et,2),s=o.split(",").map(f=>this.stringToTyped(`${a}:${f}`));return new n.List(this.nativeToType(a),s)}if(e==="variadic"){let[a,o]=r.split(et,2),s=o.split(",").map(f=>this.stringToTyped(`${a}:${f}`));return new n.VariadicValue(new n.VariadicType(this.nativeToType(a)),s)}if(e.startsWith("composite")){let a=e.match(/\(([^)]+)\)/)?.[1],o=r.split(v.WarpConstants.ArgCompositeSeparator),p=a.split(v.WarpConstants.ArgCompositeSeparator),s=o.map((l,g)=>this.stringToTyped(`${p[g]}:${l}`)),f=s.map(l=>l.getType());return new n.CompositeValue(new n.CompositeType(...f),s)}if(e==="string")return r?n.StringValue.fromUTF8(r):new n.NothingValue;if(e==="uint8")return r?new n.U8Value(Number(r)):new n.NothingValue;if(e==="uint16")return r?new n.U16Value(Number(r)):new n.NothingValue;if(e==="uint32")return r?new n.U32Value(Number(r)):new n.NothingValue;if(e==="uint64")return r?new n.U64Value(BigInt(r)):new n.NothingValue;if(e==="biguint")return r?new n.BigUIntValue(BigInt(r)):new n.NothingValue;if(e==="bool")return r?new n.BooleanValue(typeof r=="boolean"?r:r==="true"):new n.NothingValue;if(e==="address")return r?new n.AddressValue(n.Address.newFromBech32(r)):new n.NothingValue;if(e==="token")return r?new n.TokenIdentifierValue(r):new n.NothingValue;if(e==="hex")return r?n.BytesValue.fromHex(r):new n.NothingValue;if(e==="codemeta")return new n.CodeMetadataValue(n.CodeMetadata.newFromBytes(Uint8Array.from(Buffer.from(r,"hex"))));if(e==="esdt"){let a=r.split(v.WarpConstants.ArgCompositeSeparator);return new n.Struct(this.nativeToType("esdt"),[new n.Field(new n.TokenIdentifierValue(a[0]),"token_identifier"),new n.Field(new n.U64Value(BigInt(a[1])),"token_nonce"),new n.Field(new n.BigUIntValue(BigInt(a[2])),"amount")])}throw new Error(`WarpArgSerializer (stringToTyped): Unsupported input type: ${e}`)}typeToString(t){if(t instanceof n.OptionType)return"option:"+this.typeToString(t.getFirstTypeParameter());if(t instanceof n.OptionalType)return"optional:"+this.typeToString(t.getFirstTypeParameter());if(t instanceof n.ListType)return"list:"+this.typeToString(t.getFirstTypeParameter());if(t instanceof n.VariadicType)return"variadic:"+this.typeToString(t.getFirstTypeParameter());if(t instanceof n.StringType)return"string";if(t instanceof n.U8Type)return"uint8";if(t instanceof n.U16Type)return"uint16";if(t instanceof n.U32Type)return"uint32";if(t instanceof n.U64Type)return"uint64";if(t instanceof n.BigUIntType)return"biguint";if(t instanceof n.BooleanType)return"bool";if(t instanceof n.AddressType)return"address";if(t instanceof n.TokenIdentifierType)return"token";if(t instanceof n.BytesType)return"hex";if(t instanceof n.CodeMetadataType)return"codemeta";if(t instanceof n.StructType&&t.getClassName()==="EsdtTokenPayment")return"esdt";throw new Error(`WarpArgSerializer (typeToString): Unsupported input type: ${t.getClassName()}`)}};var O=class{constructor(t){this.config=t;this.abi=new _(t),this.serializer=new P,this.cache=new h.WarpCache(t.cache?.type)}async getTransactionExecutionResults(t,e){let[r,a]=(0,h.findWarpExecutableAction)(t),o=this.cache.get(h.WarpCacheKey.WarpExecutable(this.config.env,t.meta?.hash||"",a))??[],p=await this.extractContractResults(t,e,o),s=(0,h.getNextInfo)(this.config,t,a,p),f=(0,h.applyResultsToMessages)(t,p.results);return{success:e.status.isSuccessful(),warp:t,action:a,user:this.config.user?.wallet||null,txHash:e.hash,next:s,values:p.values,results:p.results,messages:f}}async extractContractResults(t,e,r){let[a,o]=(0,h.findWarpExecutableAction)(t),p=[],s={};if(!t.results||a.type!=="contract")return{values:p,results:s};if(!Object.values(t.results).some(I=>I.includes("out")||I.includes("event"))){for(let[I,y]of Object.entries(t.results))s[I]=y;return{values:p,results:await(0,h.evaluateResultsCommon)(t,s,o,r)}}let l=await this.abi.getAbiForAction(a),g=new $.TransactionEventsParser({abi:l}),W=new $.SmartContractTransactionsOutcomeParser({abi:l}).parseExecute({transactionOnNetwork:e,function:a.func||void 0});for(let[I,y]of Object.entries(t.results)){if(y.startsWith(h.WarpConstants.Transform.Prefix))continue;if(y.startsWith("input.")){s[I]=y;continue}let E=(0,h.parseResultsOutIndex)(y);if(E!==null&&E!==o){s[I]=null;continue}let[A,F,V]=y.split(".");if(A==="event"){if(!F||isNaN(Number(V)))continue;let H=Number(V),C=(0,$.findEventsByFirstTopic)(e,F),M=g.parseEvents({events:C})[0],D=Object.values(M)[H]||null;p.push(D),s[I]=D&&D.valueOf()}else if(A==="out"||A.startsWith("out[")){if(!F)continue;let H=Number(F),C=W.values[H-1]||null;V&&(C=C[V]||null),C&&typeof C=="object"&&(C="toFixed"in C?C.toFixed():C.valueOf()),p.push(C),s[I]=C&&C.valueOf()}else s[I]=y}return{values:p,results:await(0,h.evaluateResultsCommon)(t,s,o,r)}}async extractQueryResults(t,e,r,a){let o=e.map(l=>this.serializer.typedToString(l)),p=e.map(l=>this.serializer.typedToNative(l)[1]),s={};if(!t.results)return{values:o,results:s};let f=l=>{let g=l.split(".").slice(1).map(W=>parseInt(W)-1);if(g.length===0)return;let m=p[g[0]];for(let W=1;W<g.length;W++){if(m==null)return;m=m[g[W]]}return m};for(let[l,g]of Object.entries(t.results)){if(g.startsWith(h.WarpConstants.Transform.Prefix))continue;let m=(0,h.parseResultsOutIndex)(g);if(m!==null&&m!==r){s[l]=null;continue}g.startsWith("out.")||g==="out"||g.startsWith("out[")?s[l]=f(g)||null:s[l]=g}return{values:o,results:await(0,h.evaluateResultsCommon)(t,s,r,a)}}async resolveWarpResultsRecursively(t){let e=t.warp,r=t.entryActionIndex,a=t.executor,o=t.inputs,p=t.meta,s=new Map,f=new Set,l=this;async function g(y,E=[]){if(s.has(y))return s.get(y);if(f.has(y))throw new Error(`Circular dependency detected at action ${y}`);f.add(y);let A=e.actions[y-1];if(!A)throw new Error(`Action ${y} not found`);let F;if(A.type==="query")F=await a.executeQuery(e,y,E);else if(A.type==="collect")F=await a.executeCollect(e,y,E,p);else throw new Error(`Unsupported or interactive action type: ${A.type}`);if(s.set(y,F),e.results)for(let V of Object.values(e.results)){let C=String(V).match(/^out\[(\d+)\]/);if(C){let M=parseInt(C[1],10);M!==y&&!s.has(M)&&await g(M)}}return f.delete(y),F}await g(r,o);let m={};for(let y of s.values())for(let[E,A]of Object.entries(y.results))A!==null?m[E]=A:E in m||(m[E]=null);let W=await(0,h.evaluateResultsCommon)(e,m,r,o);return{...s.get(r),action:r,results:W}}};var c=require("@multiversx/sdk-core"),lt=(i,t)=>i?c.OptionValue.newProvided(i):t?c.OptionValue.newMissingTyped(t):c.OptionValue.newMissing(),ft=(i,t)=>i?new c.OptionalValue(i.getType(),i):t?new c.OptionalValue(t):c.OptionalValue.newMissing(),gt=i=>{if(i.length===0)throw new Error("Cannot create a list from an empty array");let t=i[0].getType();return new c.List(t,i)},mt=i=>c.VariadicValue.fromItems(...i),dt=i=>{let t=i.map(e=>e.getType());return new c.CompositeValue(new c.CompositeType(...t),i)},R=i=>c.StringValue.fromUTF8(i),yt=i=>new c.U8Value(i),ht=i=>new c.U16Value(i),X=i=>new c.U32Value(i),wt=i=>new c.U64Value(i),Tt=i=>new c.BigUIntValue(BigInt(i)),Wt=i=>new c.BooleanValue(i),Ct=i=>new c.AddressValue(c.Address.newFromBech32(i)),bt=i=>new c.TokenIdentifierValue(i),vt=i=>c.BytesValue.fromHex(i),Y=i=>new c.Struct(new c.StructType("EsdtTokenPayment",[new c.FieldDefinition("token_identifier","",new c.TokenIdentifierType),new c.FieldDefinition("token_nonce","",new c.U64Type),new c.FieldDefinition("amount","",new c.BigUIntType)]),[new c.Field(new c.TokenIdentifierValue(i.token.identifier),"token_identifier"),new c.Field(new c.U64Value(BigInt(i.token.nonce)),"token_nonce"),new c.Field(new c.BigUIntValue(BigInt(i.amount)),"amount")]),It=i=>new c.CodeMetadataValue(c.CodeMetadata.newFromBytes(Uint8Array.from(Buffer.from(i,"hex")))),At=()=>new c.NothingValue;var b=class i{constructor(t){this.config=t;this.serializer=new P,this.abi=new _(this.config),this.results=new O(this.config)}async createTransaction(t){let e=(0,x.getWarpActionByIndex)(t.warp,t.action),r=null;if(e.type==="transfer")r=await this.createTransferTransaction(t);else if(e.type==="contract")r=await this.createContractCallTransaction(t);else{if(e.type==="query")throw new Error("WarpMultiversxExecutor: Invalid action type for createTransactionForExecute; Use executeQuery instead");if(e.type==="collect")throw new Error("WarpMultiversxExecutor: Invalid action type for createTransactionForExecute; Use executeCollect instead")}if(!r)throw new Error(`WarpMultiversxExecutor: Invalid action type (${e.type})`);return r}async createTransferTransaction(t){if(!this.config.user?.wallet)throw new Error("WarpMultiversxExecutor: createTransfer - user address not set");let e=d.Address.newFromBech32(this.config.user.wallet),r=new d.TransactionsFactoryConfig({chainID:t.chain.chainId}),a=t.data?Buffer.from(this.serializer.stringToTyped(t.data).valueOf()):null;return new d.TransferTransactionsFactory({config:r}).createTransactionForTransfer(e,{receiver:d.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,x.getWarpActionByIndex)(t.warp,t.action),r=d.Address.newFromBech32(this.config.user.wallet),a=t.args.map(p=>this.serializer.stringToTyped(p)),o=new d.TransactionsFactoryConfig({chainID:t.chain.chainId});return new d.SmartContractTransactionsFactory({config:o}).createTransactionForExecute(r,{contract:d.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,x.getWarpActionByIndex)(t.warp,t.action);if(e.type!=="query")throw new Error(`WarpMultiversxExecutor: Invalid action type for executeQuery: ${e.type}`);let r=await this.abi.getAbiForAction(e),a=t.args.map(V=>this.serializer.stringToTyped(V)),o=i.getChainEntrypoint(t.chain,this.config.env),p=d.Address.newFromBech32(t.destination),s=o.createSmartContractController(r),f=s.createQuery({contract:p,function:e.func||"",arguments:a}),l=await s.runQuery(f),g=l.returnCode==="ok",m=new d.ArgSerializer,W=r.getEndpoint(l.function||e.func||""),I=(l.returnDataParts||[]).map(V=>Buffer.from(V)),y=m.buffersToValues(I,W.output),{values:E,results:A}=await this.results.extractQueryResults(t.warp,y,t.action,t.resolvedInputs),F=(0,x.getNextInfo)(this.config,t.warp,t.action,A);return{success:g,warp:t.warp,action:t.action,user:this.config.user?.wallet||null,txHash:null,next:F,values:E,results:A,messages:(0,x.applyResultsToMessages)(t.warp,A)}}async preprocessInput(t,e,r,a){if(r==="esdt"){let[o,p,s,f]=a.split(x.WarpConstants.ArgCompositeSeparator);if(f)return e;let l=new d.Token({identifier:o,nonce:BigInt(p)});if(!new d.TokenComputer().isFungible(l))return e;let W=(0,x.findKnownTokenById)(o)?.decimals;if(W||(W=(await(await fetch(`${t.apiUrl}/tokens/${o}`)).json()).decimals),!W)throw new Error(`WarpActionExecutor: Decimals not found for token ${o}`);let I=Y(new d.TokenTransfer({token:l,amount:(0,x.shiftBigintBy)(s,W)}));return this.serializer.typedToString(I)+x.WarpConstants.ArgCompositeSeparator+W}return e}static getChainEntrypoint(t,e){let r="warp-sdk",a="api";return e==="devnet"?new d.DevnetEntrypoint(t.apiUrl,a,r):e==="testnet"?new d.TestnetEntrypoint(t.apiUrl,a,r):new d.MainnetEntrypoint(t.apiUrl,a,r)}};var L=class{constructor(t){this.config=t;this.cache=new S.WarpCache(t.cache?.type),this.core=new S.WarpBuilder(t)}createInscriptionTransaction(t){if(!this.config.user?.wallet)throw new Error("WarpBuilder: user address not set");let e=(0,S.getMainChainInfo)(this.config),r=new k.TransactionsFactoryConfig({chainID:e.chainId}),a=new k.TransferTransactionsFactory({config:r}),o=k.Address.newFromBech32(this.config.user.wallet),p=JSON.stringify(t),s=a.createTransactionForTransfer(o,{receiver:k.Address.newFromBech32(this.config.user.wallet),nativeAmount:BigInt(0),data:Uint8Array.from(Buffer.from(p))});return s.gasLimit=s.gasLimit+BigInt(2e6),s}async createFromTransaction(t,e=!1){let r=await this.core.createFromRaw(t.data.toString(),e);return r.meta={hash:t.hash,creator:t.sender.toBech32(),createdAt:new Date(t.timestamp*1e3).toISOString()},r}async createFromTransactionHash(t,e){let r=S.WarpCacheKey.Warp(this.config.env,t);if(e){let s=this.cache.get(r);if(s)return S.WarpLogger.info(`WarpBuilder (createFromTransactionHash): Warp found in cache: ${t}`),s}let a=(0,S.getMainChainInfo)(this.config),p=b.getChainEntrypoint(a,this.config.env).createNetworkProvider();try{let s=await p.getTransaction(t),f=await this.createFromTransaction(s);return e&&e.ttl&&f&&this.cache.set(r,f,e.ttl),f}catch(s){return S.WarpLogger.error("WarpBuilder: Error creating from transaction hash",s),null}}};var z=class{constructor(t){this.chainInfo=t}getAccountUrl(t){return`${this.chainInfo.explorerUrl}/accounts/${t}`}getTransactionUrl(t){return`${this.chainInfo.explorerUrl}/transactions/${t}`}};var u=require("@multiversx/sdk-core"),w=require("@vleap/warps");var Z={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 T=i=>i==="devnet"?"erd1qqqqqqqqqqqqqpgqje2f99vr6r7sk54thg03c9suzcvwr4nfl3tsfkdl36":i==="testnet"?"####":"erd1qqqqqqqqqqqqqpgq3mrpj3u6q7tejv6d7eqhnyd27n9v5c5tl3ts08mffe";var G=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}),rt=i=>({unitPrice:BigInt(i.unit_price.toString()),admins:i.admins.map(t=>t.toBech32())});var Q=class{constructor(t){this.config=t;this.cache=new w.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=u.Address.newFromBech32(this.config.user.wallet),o=()=>this.isCurrentUserAdmin()?BigInt(0):e&&r?this.registryConfig.unitPrice*BigInt(3):e?this.registryConfig.unitPrice*BigInt(2):this.registryConfig.unitPrice,p=()=>e&&r?[u.BytesValue.fromHex(t),u.BytesValue.fromUTF8(e),u.BytesValue.fromHex(r)]:e?[u.BytesValue.fromHex(t),u.BytesValue.fromUTF8(e)]:[u.BytesValue.fromHex(t)];return this.getFactory().createTransactionForExecute(a,{contract:u.Address.newFromBech32(T(this.config.env)),function:"registerWarp",gasLimit:BigInt(1e7),nativeTransferAmount:o(),arguments:p()})}createWarpUnregisterTransaction(t){if(!this.config.user?.wallet)throw new Error("WarpRegistry: user address not set");let e=u.Address.newFromBech32(this.config.user.wallet);return this.getFactory().createTransactionForExecute(e,{contract:u.Address.newFromBech32(T(this.config.env)),function:"unregisterWarp",gasLimit:BigInt(1e7),arguments:[u.BytesValue.fromHex(t)]})}createWarpUpgradeTransaction(t,e){if(this.registryConfig.unitPrice===BigInt(0))throw new Error("WarpRegistry: config not loaded. forgot to call init()?");if(!this.config.user?.wallet)throw new Error("WarpRegistry: user address not set");let r=u.Address.newFromBech32(this.config.user.wallet);return this.getFactory().createTransactionForExecute(r,{contract:u.Address.newFromBech32(T(this.config.env)),function:"upgradeWarp",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[u.BytesValue.fromUTF8(t),u.BytesValue.fromHex(e)]})}createWarpAliasSetTransaction(t,e){if(!this.config.user?.wallet)throw new Error("WarpRegistry: user address not set");let r=u.Address.newFromBech32(this.config.user.wallet);return this.getFactory().createTransactionForExecute(r,{contract:u.Address.newFromBech32(T(this.config.env)),function:"setWarpAlias",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[u.BytesValue.fromHex(t),u.BytesValue.fromUTF8(e)]})}createWarpVerifyTransaction(t){if(!this.config.user?.wallet)throw new Error("WarpRegistry: user address not set");let e=u.Address.newFromBech32(this.config.user.wallet);return this.getFactory().createTransactionForExecute(e,{contract:u.Address.newFromBech32(T(this.config.env)),function:"verifyWarp",gasLimit:BigInt(1e7),arguments:[u.BytesValue.fromHex(t)]})}createWarpTransferOwnershipTransaction(t,e){if(!this.config.user?.wallet)throw new Error("WarpRegistry: user address not set");let r=u.Address.newFromBech32(this.config.user.wallet);return this.getFactory().createTransactionForExecute(r,{contract:u.Address.newFromBech32(T(this.config.env)),function:"transferOwnership",gasLimit:BigInt(1e7),arguments:[u.BytesValue.fromHex(t),new u.AddressValue(new u.Address(e))]})}createBrandRegisterTransaction(t){if(this.registryConfig.unitPrice===BigInt(0))throw new Error("WarpRegistry: config not loaded. forgot to call init()?");if(!this.config.user?.wallet)throw new Error("WarpRegistry: user address not set");let e=u.Address.newFromBech32(this.config.user.wallet);return this.getFactory().createTransactionForExecute(e,{contract:u.Address.newFromBech32(T(this.config.env)),function:"registerBrand",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[u.BytesValue.fromHex(t)]})}createWarpBrandingTransaction(t,e){if(!this.config.user?.wallet)throw new Error("WarpRegistry: user address not set");let r=u.Address.newFromBech32(this.config.user.wallet);return this.getFactory().createTransactionForExecute(r,{contract:u.Address.newFromBech32(T(this.config.env)),function:"brandWarp",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[u.BytesValue.fromHex(t),u.BytesValue.fromHex(e)]})}async getInfoByAlias(t,e){try{let r=w.WarpCacheKey.RegistryInfo(this.config.env,t),a=e?this.cache.get(r):null;if(a)return w.WarpLogger.info(`WarpRegistry (getInfoByAlias): RegistryInfo found in cache: ${t}`),a;let o=u.Address.newFromBech32(T(this.config.env)),p=this.getController(),s=p.createQuery({contract:o,function:"getInfoByAlias",arguments:[u.BytesValue.fromUTF8(t)]}),f=await p.runQuery(s),[l]=p.parseQueryResponse(f),g=l?G(l):null,m=g?.brand?await this.fetchBrand(g.brand):null;return e&&e.ttl&&this.cache.set(r,{registryInfo:g,brand:m},e.ttl),{registryInfo:g,brand:m}}catch{return{registryInfo:null,brand:null}}}async getInfoByHash(t,e){try{let r=w.WarpCacheKey.RegistryInfo(this.config.env,t);if(e){let m=this.cache.get(r);if(m)return w.WarpLogger.info(`WarpRegistry (getInfoByHash): RegistryInfo found in cache: ${t}`),m}let a=u.Address.newFromBech32(T(this.config.env)),o=this.getController(),p=o.createQuery({contract:a,function:"getInfoByHash",arguments:[u.BytesValue.fromHex(t)]}),s=await o.runQuery(p),[f]=o.parseQueryResponse(s),l=f?G(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=u.Address.newFromBech32(T(this.config.env)),a=this.getController(),o=a.createQuery({contract:r,function:"getUserWarps",arguments:[new u.AddressValue(new u.Address(e))]}),p=await a.runQuery(o),[s]=a.parseQueryResponse(p);return s.map(G)}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=u.Address.newFromBech32(T(this.config.env)),a=this.getController(),o=a.createQuery({contract:r,function:"getUserBrands",arguments:[new u.AddressValue(new u.Address(e))]}),p=await a.runQuery(o),[s]=a.parseQueryResponse(p),f=s.map(m=>m.toString("hex")),l={ttl:365*24*60*60};return(await Promise.all(f.map(m=>this.fetchBrand(m,l)))).filter(m=>m!==null)}catch{return[]}}async getChainInfos(t){let e=w.WarpCacheKey.ChainInfos(this.config.env);if(t&&t.ttl){let l=this.cache.get(e);if(l)return w.WarpLogger.info("WarpRegistry (getChainInfos): ChainInfos found in cache"),l}let r=u.Address.newFromBech32(T(this.config.env)),a=this.getController(),o=a.createQuery({contract:r,function:"getChains",arguments:[]}),p=await a.runQuery(o),[s]=a.parseQueryResponse(p),f=s.map(w.toTypedChainInfo);if(t&&t.ttl){for(let l of f)this.cache.set(w.WarpCacheKey.ChainInfo(this.config.env,l.chain),l,t.ttl);this.cache.set(e,f,t.ttl)}return f}async getChainInfo(t,e){try{let r=w.WarpCacheKey.ChainInfo(this.config.env,t),a=e?this.cache.get(r):null;if(a)return w.WarpLogger.info(`WarpRegistry (getChainInfo): ChainInfo found in cache: ${t}`),a;let o=u.Address.newFromBech32(T(this.config.env)),p=this.getController(),s=p.createQuery({contract:o,function:"getChain",arguments:[u.BytesValue.fromUTF8(t)]}),f=await p.runQuery(s),[l]=p.parseQueryResponse(f),g=l?(0,w.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=u.Address.newFromBech32(this.config.user.wallet);return this.getFactory().createTransactionForExecute(e,{contract:u.Address.newFromBech32(T(this.config.env)),function:"setChain",gasLimit:BigInt(1e7),arguments:[R(t.name),R(t.displayName),R(t.chainId),X(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=u.Address.newFromBech32(this.config.user.wallet);return this.getFactory().createTransactionForExecute(e,{contract:u.Address.newFromBech32(T(this.config.env)),function:"removeChain",gasLimit:BigInt(1e7),arguments:[R(t)]})}async fetchBrand(t,e){let r=w.WarpCacheKey.Brand(this.config.env,t),a=e?this.cache.get(r):null;if(a)return w.WarpLogger.info(`WarpRegistry (fetchBrand): Brand found in cache: ${t}`),a;let o=(0,w.getMainChainInfo)(this.config),s=b.getChainEntrypoint(o,this.config.env).createNetworkProvider();try{let f=await s.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}}async loadRegistryConfigs(){let t=u.Address.newFromBech32(T(this.config.env)),e=this.getController(),[r]=await e.query({contract:t,function:"getConfig",arguments:[]}),a=r?rt(r):null;this.registryConfig=a||{unitPrice:BigInt(0),admins:[]}}getFactory(){let t=(0,w.getMainChainInfo)(this.config),e=new u.TransactionsFactoryConfig({chainID:t.chainId}),r=u.AbiRegistry.create(Z);return new u.SmartContractTransactionsFactory({config:e,abi:r})}getController(){let t=(0,w.getMainChainInfo)(this.config),e=b.getChainEntrypoint(t,this.config.env),r=u.AbiRegistry.create(Z);return e.createSmartContractController(r)}isCurrentUserAdmin(){return!!this.config.user?.wallet&&this.registryConfig.admins.includes(this.config.user.wallet)}};var Bt=i=>({chain:"multiversx",prefix:"mvx",builder:new L(i),executor:new b(i),results:new O(i),serializer:new P,registry:new Q(i),explorer:t=>new z(t)});var U=require("@multiversx/sdk-core"),N=require("@vleap/warps"),nt=require("buffer");var tt=class{constructor(t){this.config=t;this.core=new N.WarpBrandBuilder(t)}createInscriptionTransaction(t){if(!this.config.user?.wallet)throw new Error("BrandBuilder: user address not set");let e=(0,N.getMainChainInfo)(this.config),r=new U.TransactionsFactoryConfig({chainID:e.chainId}),a=new U.TransferTransactionsFactory({config:r}),o=U.Address.newFromBech32(this.config.user.wallet),p=JSON.stringify(t);return a.createTransactionForNativeTokenTransfer(o,{receiver:U.Address.newFromBech32(this.config.user.wallet),nativeAmount:BigInt(0),data:Uint8Array.from(nt.Buffer.from(p))})}async createFromTransaction(t,e=!1){return await this.core.createFromRaw(t.data.toString(),e)}async createFromTransactionHash(t){let e=(0,N.getMainChainInfo)(this.config),a=b.getChainEntrypoint(e,this.config.env).createNetworkProvider();try{let o=await a.getTransaction(t);return this.createFromTransaction(o)}catch(o){return N.WarpLogger.error("BrandBuilder: Error creating from transaction hash",o),null}}};0&&(module.exports={WarpMultiversxAbi,WarpMultiversxBrandBuilder,WarpMultiversxBuilder,WarpMultiversxConstants,WarpMultiversxContractLoader,WarpMultiversxExecutor,WarpMultiversxExplorer,WarpMultiversxRegistry,WarpMultiversxResults,WarpMultiversxSerializer,address_value,biguint_value,boolean_value,codemeta_value,composite_value,esdt_value,getMultiversxAdapter,hex_value,list_value,nothing_value,option_value,optional_value,string_value,token_value,u16_value,u32_value,u64_value,u8_value,variadic_value});
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- var Ne={Egld:{Identifier:"EGLD",EsdtIdentifier:"EGLD-000000",DisplayName:"eGold",Decimals:18}};import{Address as Mt,AddressValue as Qt,BigUIntType as Ht,BigUIntValue as nt,BooleanValue as zt,BytesValue as Dt,CodeMetadata as jt,CodeMetadataValue as Gt,CompositeType as qt,CompositeValue as Kt,Field as k,FieldDefinition as $,List as Jt,NothingValue as Xt,OptionalValue as L,OptionValue as M,StringValue as Yt,Struct as Zt,StructType as te,TokenIdentifierType as ee,TokenIdentifierValue as at,U16Value as re,U32Value as ne,U64Type as ae,U64Value as st,U8Value as se,VariadicValue as ie}from"@multiversx/sdk-core";var He=(a,t)=>a?M.newProvided(a):t?M.newMissingTyped(t):M.newMissing(),ze=(a,t)=>a?new L(a.getType(),a):t?new L(t):L.newMissing(),De=a=>{if(a.length===0)throw new Error("Cannot create a list from an empty array");let t=a[0].getType();return new Jt(t,a)},je=a=>ie.fromItems(...a),Ge=a=>{let t=a.map(e=>e.getType());return new Kt(new qt(...t),a)},v=a=>Yt.fromUTF8(a),qe=a=>new se(a),Ke=a=>new re(a),it=a=>new ne(a),Je=a=>new st(a),Xe=a=>new nt(BigInt(a)),Ye=a=>new zt(a),Ze=a=>new Qt(Mt.newFromBech32(a)),tr=a=>new at(a),er=a=>Dt.fromHex(a),rr=a=>new Zt(new te("EsdtTokenPayment",[new $("token_identifier","",new ee),new $("token_nonce","",new ae),new $("amount","",new Ht)]),[new k(new at(a.token.identifier),"token_identifier"),new k(new st(BigInt(a.token.nonce)),"token_nonce"),new k(new nt(BigInt(a.amount)),"amount")]),nr=a=>new Gt(jt.newFromBytes(Uint8Array.from(Buffer.from(a,"hex")))),ar=()=>new Xt;import{AbiRegistry as Z}from"@multiversx/sdk-core";import{getMainChainInfo as Pt,WarpCache as Re,WarpCacheKey as Se,WarpConstants as Ot,WarpLogger as Ut}from"@vleap/warps-core";import{WarpLogger as _t}from"@vleap/warps-core";import{Address as R,ArgSerializer as be,DevnetEntrypoint as Ie,MainnetEntrypoint as Ae,SmartContractTransactionsFactory as ve,TestnetEntrypoint as xe,TransactionsFactoryConfig as Ft,TransferTransactionsFactory as Be}from"@multiversx/sdk-core";import{applyResultsToMessages as Ve,getNextInfo as Ee,getWarpActionByIndex as Y}from"@vleap/warps-core";import{findEventsByFirstTopic as ye,SmartContractTransactionsOutcomeParser as de,TransactionEventsParser as me}from"@multiversx/sdk-core";import{applyResultsToMessages as he,evaluateResultsCommon as P,getNextInfo as we,getWarpActionByIndex as Te,parseResultsOutIndex as Rt,WarpCache as Ce,WarpCacheKey as We,WarpConstants as St}from"@vleap/warps-core";import{Address as oe,AddressType as ot,AddressValue as ct,BigUIntType as Q,BigUIntValue as H,BooleanType as ut,BooleanValue as pt,BytesType as lt,BytesValue as ft,CodeMetadata as ce,CodeMetadataType as gt,CodeMetadataValue as yt,CompositeType as dt,CompositeValue as mt,Field as z,FieldDefinition as D,List as ht,ListType as ue,NothingValue as w,OptionalType as pe,OptionalValue as j,OptionType as le,OptionValue as G,StringType as wt,StringValue as Tt,Struct as fe,StructType as Ct,TokenIdentifierType as q,TokenIdentifierValue as K,U16Type as Wt,U16Value as bt,U32Type as It,U32Value as At,U64Type as J,U64Value as X,U8Type as vt,U8Value as xt,VariadicType as Bt,VariadicValue as Vt}from"@multiversx/sdk-core";import{WarpConstants as T,WarpSerializer as ge}from"@vleap/warps-core";var Et=new RegExp(`${T.ArgParamsSeparator}(.*)`),x=class{constructor(){this.coreSerializer=new ge}typedToString(t){if(t.hasClassOrSuperclass(G.ClassName))return t.isSet()?`option:${this.typedToString(t.getTypedValue())}`:"option:null";if(t.hasClassOrSuperclass(j.ClassName))return t.isSet()?`optional:${this.typedToString(t.getTypedValue())}`:"optional:null";if(t.hasClassOrSuperclass(ht.ClassName)){let e=t.getItems(),n=e.map(o=>this.typedToString(o).split(T.ArgParamsSeparator)[0])[0],i=e.map(o=>this.typedToString(o).split(T.ArgParamsSeparator)[1]);return`list:${n}:${i.join(",")}`}if(t.hasClassOrSuperclass(Vt.ClassName)){let e=t.getItems(),n=e.map(o=>this.typedToString(o).split(T.ArgParamsSeparator)[0])[0],i=e.map(o=>this.typedToString(o).split(T.ArgParamsSeparator)[1]);return`variadic:${n}:${i.join(",")}`}if(t.hasClassOrSuperclass(mt.ClassName)){let e=t.getItems(),r=e.map(s=>this.typedToString(s).split(T.ArgParamsSeparator)[0]),n=e.map(s=>this.typedToString(s).split(T.ArgParamsSeparator)[1]),i=r.join(T.ArgCompositeSeparator),o=n.join(T.ArgCompositeSeparator);return`composite(${i}):${o}`}if(t.hasClassOrSuperclass(H.ClassName)||t.getType().getName()==="BigUint")return`biguint:${BigInt(t.valueOf().toFixed())}`;if(t.hasClassOrSuperclass(xt.ClassName))return`uint8:${t.valueOf().toNumber()}`;if(t.hasClassOrSuperclass(bt.ClassName))return`uint16:${t.valueOf().toNumber()}`;if(t.hasClassOrSuperclass(At.ClassName))return`uint32:${t.valueOf().toNumber()}`;if(t.hasClassOrSuperclass(X.ClassName))return`uint64:${BigInt(t.valueOf().toFixed())}`;if(t.hasClassOrSuperclass(Tt.ClassName))return`string:${t.valueOf()}`;if(t.hasClassOrSuperclass(pt.ClassName))return`bool:${t.valueOf()}`;if(t.hasClassOrSuperclass(ct.ClassName))return`address:${t.valueOf().bech32()}`;if(t.hasClassOrSuperclass(K.ClassName))return`token:${t.valueOf()}`;if(t.hasClassOrSuperclass(ft.ClassName))return`hex:${t.valueOf().toString("hex")}`;if(t.hasClassOrSuperclass(yt.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 dt(...e.split(T.ArgCompositeSeparator).map(r=>this.nativeToType(r)))}if(t==="string")return new wt;if(t==="uint8")return new vt;if(t==="uint16")return new Wt;if(t==="uint32")return new It;if(t==="uint64")return new J;if(t==="biguint")return new Q;if(t==="bool")return new ut;if(t==="address")return new ot;if(t==="token")return new q;if(t==="hex")return new lt;if(t==="codemeta")return new gt;if(t==="esdt"||t==="nft")return new Ct("EsdtTokenPayment",[new D("token_identifier","",new q),new D("token_nonce","",new J),new D("amount","",new Q)]);throw new Error(`WarpArgSerializer (nativeToType): Unsupported input type: ${t}`)}stringToTyped(t){let[e,r]=t.split(/:(.*)/,2);if(e==="null"||e===null)return new w;if(e==="option"){let n=this.stringToTyped(r);return n instanceof w?G.newMissingTyped(n.getType()):G.newProvided(n)}if(e==="optional"){let n=this.stringToTyped(r);return n instanceof w?j.newMissing():new j(n.getType(),n)}if(e==="list"){let[n,i]=r.split(Et,2),s=i.split(",").map(u=>this.stringToTyped(`${n}:${u}`));return new ht(this.nativeToType(n),s)}if(e==="variadic"){let[n,i]=r.split(Et,2),s=i.split(",").map(u=>this.stringToTyped(`${n}:${u}`));return new Vt(new Bt(this.nativeToType(n)),s)}if(e.startsWith("composite")){let n=e.match(/\(([^)]+)\)/)?.[1],i=r.split(T.ArgCompositeSeparator),o=n.split(T.ArgCompositeSeparator),s=i.map((c,p)=>this.stringToTyped(`${o[p]}:${c}`)),u=s.map(c=>c.getType());return new mt(new dt(...u),s)}if(e==="string")return r?Tt.fromUTF8(r):new w;if(e==="uint8")return r?new xt(Number(r)):new w;if(e==="uint16")return r?new bt(Number(r)):new w;if(e==="uint32")return r?new At(Number(r)):new w;if(e==="uint64")return r?new X(BigInt(r)):new w;if(e==="biguint")return r?new H(BigInt(r)):new w;if(e==="bool")return r?new pt(typeof r=="boolean"?r:r==="true"):new w;if(e==="address")return r?new ct(oe.newFromBech32(r)):new w;if(e==="token")return r?new K(r):new w;if(e==="hex")return r?ft.fromHex(r):new w;if(e==="codemeta")return new yt(ce.newFromBytes(Uint8Array.from(Buffer.from(r,"hex"))));if(e==="esdt"){let n=r.split(T.ArgCompositeSeparator);return new fe(this.nativeToType("esdt"),[new z(new K(n[0]),"token_identifier"),new z(new X(BigInt(n[1])),"token_nonce"),new z(new H(BigInt(n[2])),"amount")])}throw new Error(`WarpArgSerializer (stringToTyped): Unsupported input type: ${e}`)}typeToString(t){if(t instanceof le)return"option:"+this.typeToString(t.getFirstTypeParameter());if(t instanceof pe)return"optional:"+this.typeToString(t.getFirstTypeParameter());if(t instanceof ue)return"list:"+this.typeToString(t.getFirstTypeParameter());if(t instanceof Bt)return"variadic:"+this.typeToString(t.getFirstTypeParameter());if(t instanceof wt)return"string";if(t instanceof vt)return"uint8";if(t instanceof Wt)return"uint16";if(t instanceof It)return"uint32";if(t instanceof J)return"uint64";if(t instanceof Q)return"biguint";if(t instanceof ut)return"bool";if(t instanceof ot)return"address";if(t instanceof q)return"token";if(t instanceof lt)return"hex";if(t instanceof gt)return"codemeta";if(t instanceof Ct&&t.getClassName()==="EsdtTokenPayment")return"esdt";throw new Error(`WarpArgSerializer (typeToString): Unsupported input type: ${t.getClassName()}`)}};var O=class{constructor(t){this.config=t;this.abi=new B(t),this.serializer=new x,this.cache=new Ce(t.cache?.type)}async getTransactionExecutionResults(t,e,r){let n=this.cache.get(We.WarpExecutable(this.config.env,t.meta?.hash||"",e))??[],i=await this.extractContractResults(t,e,r,n),o=we(this.config,t,e,i),s=he(t,i.results);return{success:r.status.isSuccessful(),warp:t,action:e,user:this.config.user?.wallet||null,txHash:r.hash,next:o,values:i.values,results:i.results,messages:s}}static parseResultsOutIndex(t){if(t==="out")return 1;let e=t.match(/^out\[(\d+)\]/);return e?parseInt(e[1],10):(t.startsWith("out.")||t.startsWith("event."),null)}async extractContractResults(t,e,r,n){let i=Te(t,e),o=[],s={};if(!t.results||i.type!=="contract")return{values:o,results:s};if(!Object.values(t.results).some(h=>h.includes("out")||h.includes("event"))){for(let[h,f]of Object.entries(t.results))s[h]=f;return{values:o,results:await P(t,s,e,n)}}let c=await this.abi.getAbiForAction(i),p=new me({abi:c}),W=new de({abi:c}).parseExecute({transactionOnNetwork:r,function:i.func||void 0});for(let[h,f]of Object.entries(t.results)){if(f.startsWith(St.Transform.Prefix))continue;if(f.startsWith("input.")){s[h]=f;continue}let b=Rt(f);if(b!==null&&b!==e){s[h]=null;continue}let[d,I,C]=f.split(".");if(d==="event"){if(!I||isNaN(Number(C)))continue;let F=Number(C),y=ye(r,I),E=p.parseEvents({events:y})[0],_=Object.values(E)[F]||null;o.push(_),s[h]=_&&_.valueOf()}else if(d==="out"||d.startsWith("out[")){if(!I)continue;let F=Number(I),y=W.values[F-1]||null;C&&(y=y[C]||null),y&&typeof y=="object"&&(y="toFixed"in y?y.toFixed():y.valueOf()),o.push(y),s[h]=y&&y.valueOf()}else s[h]=f}return{values:o,results:await P(t,s,e,n)}}async extractQueryResults(t,e,r,n){let i=e.map(c=>this.serializer.typedToString(c)),o=e.map(c=>this.serializer.typedToNative(c)[1]),s={};if(!t.results)return{values:i,results:s};let u=c=>{let p=c.split(".").slice(1).map(W=>parseInt(W)-1);if(p.length===0)return;let l=o[p[0]];for(let W=1;W<p.length;W++){if(l==null)return;l=l[p[W]]}return l};for(let[c,p]of Object.entries(t.results)){if(p.startsWith(St.Transform.Prefix))continue;let l=Rt(p);if(l!==null&&l!==r){s[c]=null;continue}p.startsWith("out.")||p==="out"||p.startsWith("out[")?s[c]=u(p)||null:s[c]=p}return{values:i,results:await P(t,s,r,n)}}async resolveWarpResultsRecursively(t){let e=t.warp,r=t.entryActionIndex,n=t.executor,i=t.inputs,o=t.meta,s=new Map,u=new Set,c=this;async function p(f,b=[]){if(s.has(f))return s.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,b);else if(d.type==="collect")I=await n.executeCollect(e,f,b,o);else throw new Error(`Unsupported or interactive action type: ${d.type}`);if(s.set(f,I),e.results)for(let C of Object.values(e.results)){let y=String(C).match(/^out\[(\d+)\]/);if(y){let E=parseInt(y[1],10);E!==f&&!s.has(E)&&await p(E)}}return u.delete(f),I}await p(r,i);let l={};for(let f of s.values())for(let[b,d]of Object.entries(f.results))d!==null?l[b]=d:b in l||(l[b]=null);let W=await P(e,l,r,i);return{...s.get(r),action:r,results:W}}};var A=class a{constructor(t){this.config=t;this.serializer=new x,this.abi=new B(this.config),this.results=new O(this.config)}async createTransaction(t){let e=Y(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=R.newFromBech32(this.config.user.wallet),r=new Ft({chainID:t.chain.chainId}),n=t.data?Buffer.from(this.serializer.stringToTyped(t.data).valueOf()):null;return new Be({config:r}).createTransactionForTransfer(e,{receiver:R.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=Y(t.warp,t.action),r=R.newFromBech32(this.config.user.wallet),n=t.args.map(o=>this.serializer.stringToTyped(o)),i=new Ft({chainID:t.chain.chainId});return new ve({config:i}).createTransactionForExecute(r,{contract:R.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=Y(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(C=>this.serializer.stringToTyped(C)),i=a.getChainEntrypoint(t.chain,this.config.env),o=R.newFromBech32(t.destination),s=i.createSmartContractController(r),u=s.createQuery({contract:o,function:e.func||"",arguments:n}),c=await s.runQuery(u),p=c.returnCode==="ok",l=new be,W=r.getEndpoint(c.function||e.func||""),h=(c.returnDataParts||[]).map(C=>Buffer.from(C)),f=l.buffersToValues(h,W.output),{values:b,results:d}=await this.results.extractQueryResults(t.warp,f,t.action,t.resolvedInputs),I=Ee(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:b,results:d,messages:Ve(t.warp,d)}}static getChainEntrypoint(t,e){let r="warp-sdk",n="api";return e==="devnet"?new Ie(t.apiUrl,n,r):e==="testnet"?new xe(t.apiUrl,n,r):new Ae(t.apiUrl,n,r)}};var U=class{constructor(t){this.config=t}async getContract(t,e){try{let i=await A.getChainEntrypoint(e,this.config.env).createNetworkProvider().doGetGeneric(`accounts/${t}`);return{address:t,owner:i.ownerAddress,verified:i.isVerified||!1}}catch(r){return _t.error("WarpContractLoader: getContract error",r),null}}async getVerificationInfo(t,e){try{let i=await A.getChainEntrypoint(e,this.config.env).createNetworkProvider().doGetGeneric(`accounts/${t}/verification`);return{codeHash:i.codeHash,abi:i.source.abi}}catch(r){return _t.error("WarpContractLoader: getVerificationInfo error",r),null}}};var B=class{constructor(t){this.config=t;this.contractLoader=new U(this.config),this.cache=new Re(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=Se.WarpAbi(this.config.env,t);if(e){let s=this.cache.get(r);if(s)return Ut.info(`WarpAbiBuilder (createFromTransactionHash): Warp abi found in cache: ${t}`),s}let n=Pt(this.config),o=A.getChainEntrypoint(n,this.config.env).createNetworkProvider();try{let s=await o.getTransaction(t),u=await this.createFromTransaction(s);return e&&e.ttl&&u&&this.cache.set(r,u,e.ttl),u}catch(s){return Ut.error("WarpAbiBuilder: Error creating from transaction hash",s),null}}async getAbiForAction(t){if(t.abi)return await this.fetchAbi(t);if(!t.address)throw new Error("WarpActionExecutor: Address not found");let e=Pt(this.config),r=await this.contractLoader.getVerificationInfo(t.address,e);if(!r)throw new Error("WarpActionExecutor: Verification info not found");return Z.create(r.abi)}async fetchAbi(t){if(!t.abi)throw new Error("WarpActionExecutor: ABI not found");if(t.abi.startsWith(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 Z.create(r.content)}else{let r=await(await fetch(t.abi)).json();return Z.create(r)}}};import{AbiRegistry as kt,Address as m,AddressValue as et,BytesValue as g,SmartContractTransactionsFactory as _e,TransactionsFactoryConfig as Pe}from"@multiversx/sdk-core";import{getMainChainInfo as rt,toTypedChainInfo as $t,WarpCache as Oe,WarpCacheKey as V,WarpConfig as Ue,WarpLogger as S}from"@vleap/warps-core";var tt={buildInfo:{rustc:{version:"1.86.0",commitHash:"05f9846f893b09a1be1fc8560e33fc3c815cfecb",commitDate:"2025-03-31",channel:"Stable",short:"rustc 1.86.0 (05f9846f8 2025-03-31)"},contractCrate:{name:"registry",version:"0.0.1"},framework:{name:"multiversx-sc",version:"0.51.1"}},name:"RegistryContract",constructor:{inputs:[{name:"unit_price",type:"BigUint"},{name:"vault",type:"Address"}],outputs:[]},upgradeConstructor:{inputs:[],outputs:[]},endpoints:[{name:"registerWarp",mutability:"mutable",payableInTokens:["EGLD"],inputs:[{name:"hash",type:"bytes"},{name:"alias_opt",type:"optional<bytes>",multi_arg:!0},{name:"brand_opt",type:"optional<bytes>",multi_arg:!0}],outputs:[],allow_multiple_var_args:!0},{name:"unregisterWarp",mutability:"mutable",inputs:[{name:"warp",type:"bytes"}],outputs:[]},{name:"upgradeWarp",mutability:"mutable",payableInTokens:["EGLD"],inputs:[{name:"alias",type:"bytes"},{name:"new_warp",type:"bytes"}],outputs:[]},{name:"setWarpAlias",mutability:"mutable",payableInTokens:["EGLD"],inputs:[{name:"hash",type:"bytes"},{name:"alias",type:"bytes"}],outputs:[]},{name:"forceRemoveAlias",mutability:"mutable",inputs:[{name:"hash",type:"bytes"}],outputs:[]},{name:"verifyWarp",mutability:"mutable",inputs:[{name:"warp",type:"bytes"}],outputs:[]},{name:"transferOwnership",mutability:"mutable",inputs:[{name:"warp",type:"bytes"},{name:"new_owner",type:"Address"}],outputs:[]},{name:"getUserWarps",mutability:"readonly",inputs:[{name:"address",type:"Address"}],outputs:[{type:"variadic<InfoView>",multi_result:!0}]},{name:"getInfoByAlias",mutability:"readonly",inputs:[{name:"alias",type:"bytes"}],outputs:[{type:"InfoView"}]},{name:"getInfoByHash",mutability:"readonly",inputs:[{name:"hash",type:"bytes"}],outputs:[{type:"InfoView"}]},{name:"setVault",onlyOwner:!0,mutability:"mutable",inputs:[{name:"vault",type:"Address"}],outputs:[]},{name:"setUnitPrice",onlyOwner:!0,mutability:"mutable",inputs:[{name:"amount",type:"BigUint"}],outputs:[]},{name:"addAdmin",onlyOwner:!0,mutability:"mutable",inputs:[{name:"address",type:"Address"}],outputs:[]},{name:"removeAdmin",onlyOwner:!0,mutability:"mutable",inputs:[{name:"address",type:"Address"}],outputs:[]},{name:"getConfig",mutability:"readonly",inputs:[],outputs:[{type:"ConfigView"}]},{name:"registerBrand",mutability:"mutable",payableInTokens:["EGLD"],inputs:[{name:"hash",type:"bytes"}],outputs:[]},{name:"brandWarp",mutability:"mutable",payableInTokens:["EGLD"],inputs:[{name:"warp",type:"bytes"},{name:"brand",type:"bytes"}],outputs:[]},{name:"getUserBrands",mutability:"readonly",inputs:[{name:"user",type:"Address"}],outputs:[{type:"variadic<bytes>",multi_result:!0}]},{name:"setChain",onlyOwner:!0,mutability:"mutable",inputs:[{name:"name",type:"bytes"},{name:"display_name",type:"bytes"},{name:"chain_id",type:"bytes"},{name:"block_time",type:"u32"},{name:"address_hrp",type:"bytes"},{name:"api_url",type:"bytes"},{name:"explorer_url",type:"bytes"},{name:"native_token",type:"bytes"}],outputs:[]},{name:"removeChain",onlyOwner:!0,mutability:"mutable",inputs:[{name:"name",type:"bytes"}],outputs:[]},{name:"getChain",mutability:"readonly",inputs:[{name:"name",type:"bytes"}],outputs:[{type:"ChainView"}]},{name:"getChains",mutability:"readonly",inputs:[],outputs:[{type:"variadic<ChainView>",multi_result:!0}]}],events:[{identifier:"warpRegistered",inputs:[{name:"hash",type:"bytes",indexed:!0},{name:"alias",type:"bytes",indexed:!0},{name:"trust",type:"bytes",indexed:!0}]},{identifier:"warpUnregistered",inputs:[{name:"hash",type:"bytes",indexed:!0}]},{identifier:"warpUpgraded",inputs:[{name:"alias",type:"bytes",indexed:!0},{name:"new_warp",type:"bytes",indexed:!0},{name:"trust",type:"bytes",indexed:!0}]},{identifier:"warpVerified",inputs:[{name:"hash",type:"bytes",indexed:!0}]},{identifier:"aliasUpdated",inputs:[{name:"hash",type:"bytes",indexed:!0},{name:"alias",type:"bytes",indexed:!0}]},{identifier:"ownershipTransferred",inputs:[{name:"warp",type:"bytes",indexed:!0},{name:"old_owner",type:"Address",indexed:!0},{name:"new_owner",type:"Address",indexed:!0}]}],esdtAttributes:[],hasCallback:!1,types:{ChainView:{type:"struct",fields:[{name:"name",type:"bytes"},{name:"display_name",type:"bytes"},{name:"chain_id",type:"bytes"},{name:"block_time",type:"u32"},{name:"address_hrp",type:"bytes"},{name:"api_url",type:"bytes"},{name:"explorer_url",type:"bytes"},{name:"native_token",type:"bytes"}]},ConfigView:{type:"struct",fields:[{name:"unit_price",type:"BigUint"},{name:"admins",type:"List<Address>"}]},InfoView:{type:"struct",fields:[{name:"hash",type:"bytes"},{name:"alias",type:"Option<bytes>"},{name:"trust",type:"bytes"},{name:"owner",type:"Address"},{name:"created_at",type:"u64"},{name:"upgraded_at",type:"u64"},{name:"brand",type:"Option<bytes>"},{name:"upgrade",type:"Option<bytes>"}]}}};var N=a=>({hash:a.hash.toString("hex"),alias:a.alias?.toString()||null,trust:a.trust.toString(),owner:a.owner.toString(),createdAt:a.created_at.toNumber(),upgradedAt:a.upgraded_at?.toNumber(),brand:a.brand?.toString("hex")||null,upgrade:a.upgrade?.toString("hex")||null}),Nt=a=>({unitPrice:BigInt(a.unit_price.toString()),admins:a.admins.map(t=>t.toBech32())});var Lt=class{constructor(t){this.config=t,this.cache=new Oe(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=m.newFromBech32(this.config.user.wallet),i=()=>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:i(),arguments:o()})}createWarpUnregisterTransaction(t){if(!this.config.user?.wallet)throw new Error("WarpRegistry: user address not set");let e=m.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=m.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=m.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=m.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=m.newFromBech32(this.config.user.wallet);return this.getFactory().createTransactionForExecute(r,{contract:this.getRegistryContractAddress(),function:"transferOwnership",gasLimit:BigInt(1e7),arguments:[g.fromHex(t),new et(new m(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=m.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=m.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=V.RegistryInfo(this.config.env,t),n=e?this.cache.get(r):null;if(n)return S.info(`WarpRegistry (getInfoByAlias): RegistryInfo found in cache: ${t}`),n;let i=this.getRegistryContractAddress(),o=this.getController(),s=o.createQuery({contract:i,function:"getInfoByAlias",arguments:[g.fromUTF8(t)]}),u=await o.runQuery(s),[c]=o.parseQueryResponse(u),p=c?N(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=V.RegistryInfo(this.config.env,t);if(e){let l=this.cache.get(r);if(l)return S.info(`WarpRegistry (getInfoByHash): RegistryInfo found in cache: ${t}`),l}let n=this.getRegistryContractAddress(),i=this.getController(),o=i.createQuery({contract:n,function:"getInfoByHash",arguments:[g.fromHex(t)]}),s=await i.runQuery(o),[u]=i.parseQueryResponse(s),c=u?N(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(),i=n.createQuery({contract:r,function:"getUserWarps",arguments:[new et(new m(e))]}),o=await n.runQuery(i),[s]=n.parseQueryResponse(o);return s.map(N)}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(),i=n.createQuery({contract:r,function:"getUserBrands",arguments:[new et(new m(e))]}),o=await n.runQuery(i),[s]=n.parseQueryResponse(o),u=s.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=V.ChainInfos(this.config.env);if(t&&t.ttl){let c=this.cache.get(e);if(c)return S.info("WarpRegistry (getChainInfos): ChainInfos found in cache"),c}let r=this.getRegistryContractAddress(),n=this.getController(),i=n.createQuery({contract:r,function:"getChains",arguments:[]}),o=await n.runQuery(i),[s]=n.parseQueryResponse(o),u=s.map($t);if(t&&t.ttl){for(let c of u)this.cache.set(V.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=V.ChainInfo(this.config.env,t),n=e?this.cache.get(r):null;if(n)return S.info(`WarpRegistry (getChainInfo): ChainInfo found in cache: ${t}`),n;let i=this.getRegistryContractAddress(),o=this.getController(),s=o.createQuery({contract:i,function:"getChain",arguments:[g.fromUTF8(t)]}),u=await o.runQuery(s),[c]=o.parseQueryResponse(u),p=c?$t(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=m.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),it(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=m.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=V.Brand(this.config.env,t),n=e?this.cache.get(r):null;if(n)return S.info(`WarpRegistry (fetchBrand): Brand found in cache: ${t}`),n;let i=rt(this.config),s=A.getChainEntrypoint(i,this.config.env).createNetworkProvider();try{let u=await s.getTransaction(t),c=JSON.parse(u.data.toString());return c.meta={hash:u.hash,creator:u.sender.bech32(),createdAt:new Date(u.timestamp*1e3).toISOString()},e&&e.ttl&&this.cache.set(r,c,e.ttl),c}catch{return null}}getRegistryContractAddress(){return m.newFromBech32(this.config.registry?.contract||Ue.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?Nt(r):null;this.registryConfig=n||{unitPrice:BigInt(0),admins:[]}}getFactory(){let t=rt(this.config),e=new Pe({chainID:t.chainId}),r=kt.create(tt);return new _e({config:e,abi:r})}getController(){let t=rt(this.config),e=A.getChainEntrypoint(t,this.config.env),r=kt.create(tt);return e.createSmartContractController(r)}isCurrentUserAdmin(){return!!this.config.user?.wallet&&this.registryConfig.admins.includes(this.config.user.wallet)}};export{B as WarpMultiversxAbi,Ne as WarpMultiversxConstants,U as WarpMultiversxContractLoader,A as WarpMultiversxExecutor,Lt as WarpMultiversxRegistry,O as WarpMultiversxResults,x as WarpMultiversxSerializer,Ze as address_value,Xe as biguint_value,Ye as boolean_value,nr as codemeta_value,Ge as composite_value,rr as esdt_value,er as hex_value,De as list_value,ar as nothing_value,He as option_value,ze as optional_value,v as string_value,tr as token_value,Ke as u16_value,it as u32_value,Je as u64_value,qe as u8_value,je as variadic_value};
1
+ var cr={Egld:{Identifier:"EGLD",EsdtIdentifier:"EGLD-000000",DisplayName:"eGold",Decimals:18}};import{Address as Qt,TransactionsFactoryConfig as Ge,TransferTransactionsFactory as Ke}from"@multiversx/sdk-core";import{getMainChainInfo as Ht,WarpBuilder as Je,WarpCache as Xe,WarpCacheKey as Ye,WarpLogger as Dt}from"@vleap/warps";import{Address as R,ArgSerializer as Oe,DevnetEntrypoint as ke,MainnetEntrypoint as Ue,SmartContractTransactionsFactory as Ne,TestnetEntrypoint as $e,Token as Me,TokenComputer as qe,TokenTransfer as Le,TransactionsFactoryConfig as Lt,TransferTransactionsFactory as ze}from"@multiversx/sdk-core";import{applyResultsToMessages as Qe,findKnownTokenById as He,getNextInfo as De,getWarpActionByIndex as nt,shiftBigintBy as je,WarpConstants as zt}from"@vleap/warps";import{AbiRegistry as L}from"@multiversx/sdk-core";import{getMainChainInfo as ct,WarpCache as Zt,WarpCacheKey as te,WarpConstants as ut,WarpLogger as pt}from"@vleap/warps";import{WarpLogger as ot}from"@vleap/warps";var k=class{constructor(t){this.config=t}async getContract(t,e){try{let s=await w.getChainEntrypoint(e,this.config.env).createNetworkProvider().doGetGeneric(`accounts/${t}`);return{address:t,owner:s.ownerAddress,verified:s.isVerified||!1}}catch(r){return ot.error("WarpContractLoader: getContract error",r),null}}async getVerificationInfo(t,e){try{let s=await w.getChainEntrypoint(e,this.config.env).createNetworkProvider().doGetGeneric(`accounts/${t}/verification`);return{codeHash:s.codeHash,abi:s.source.abi}}catch(r){return ot.error("WarpContractLoader: getVerificationInfo error",r),null}}};var E=class{constructor(t){this.config=t;this.contractLoader=new k(this.config),this.cache=new Zt(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=te.WarpAbi(this.config.env,t);if(e){let a=this.cache.get(r);if(a)return pt.info(`WarpAbiBuilder (createFromTransactionHash): Warp abi found in cache: ${t}`),a}let n=ct(this.config),o=w.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 pt.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=ct(this.config),r=await this.contractLoader.getVerificationInfo(t.address,e);if(!r)throw new Error("WarpActionExecutor: Verification info not found");return L.create(r.abi)}async fetchAbi(t){if(!t.abi)throw new Error("WarpActionExecutor: ABI not found");if(t.abi.startsWith(ut.IdentifierType.Hash)){let e=t.abi.split(ut.IdentifierParamSeparator)[1],r=await this.createFromTransactionHash(e);if(!r)throw new Error(`WarpActionExecutor: ABI not found for hash: ${t.abi}`);return L.create(r.content)}else{let r=await(await fetch(t.abi)).json();return L.create(r)}}};import{findEventsByFirstTopic as ce,SmartContractTransactionsOutcomeParser as ue,TransactionEventsParser as pe}from"@multiversx/sdk-core";import{applyResultsToMessages as le,evaluateResultsCommon as U,findWarpExecutableAction as _t,getNextInfo as fe,parseResultsOutIndex as Ot,WarpCache as ge,WarpCacheKey as me,WarpConstants as kt}from"@vleap/warps";import{Address as ee,AddressType as lt,AddressValue as ft,BigUIntType as z,BigUIntValue as Q,BooleanType as gt,BooleanValue as mt,BytesType as dt,BytesValue as yt,CodeMetadata as re,CodeMetadataType as ht,CodeMetadataValue as wt,CompositeType as Tt,CompositeValue as Wt,Field as H,FieldDefinition as D,List as Ct,ListType as ne,NothingValue as C,OptionalType as ae,OptionalValue as j,OptionType as ie,OptionValue as G,StringType as bt,StringValue as vt,Struct as se,StructType as It,TokenIdentifierType as K,TokenIdentifierValue as J,U16Type as At,U16Value as xt,U32Type as Bt,U32Value as Et,U64Type as X,U64Value as Y,U8Type as Vt,U8Value as St,VariadicType as Ft,VariadicValue as Rt}from"@multiversx/sdk-core";import{WarpConstants as b,WarpSerializer as oe}from"@vleap/warps";var Pt=new RegExp(`${b.ArgParamsSeparator}(.*)`),B=class{constructor(){this.coreSerializer=new oe}typedToString(t){if(t.hasClassOrSuperclass(G.ClassName))return t.isSet()?`option:${this.typedToString(t.getTypedValue())}`:"option:null";if(t.hasClassOrSuperclass(j.ClassName))return t.isSet()?`optional:${this.typedToString(t.getTypedValue())}`:"optional:null";if(t.hasClassOrSuperclass(Ct.ClassName)){let e=t.getItems(),n=e.map(o=>this.typedToString(o).split(b.ArgParamsSeparator)[0])[0],s=e.map(o=>this.typedToString(o).split(b.ArgParamsSeparator)[1]);return`list:${n}:${s.join(",")}`}if(t.hasClassOrSuperclass(Rt.ClassName)){let e=t.getItems(),n=e.map(o=>this.typedToString(o).split(b.ArgParamsSeparator)[0])[0],s=e.map(o=>this.typedToString(o).split(b.ArgParamsSeparator)[1]);return`variadic:${n}:${s.join(",")}`}if(t.hasClassOrSuperclass(Wt.ClassName)){let e=t.getItems(),r=e.map(a=>this.typedToString(a).split(b.ArgParamsSeparator)[0]),n=e.map(a=>this.typedToString(a).split(b.ArgParamsSeparator)[1]),s=r.join(b.ArgCompositeSeparator),o=n.join(b.ArgCompositeSeparator);return`composite(${s}):${o}`}if(t.hasClassOrSuperclass(Q.ClassName)||t.getType().getName()==="BigUint")return`biguint:${BigInt(t.valueOf().toFixed())}`;if(t.hasClassOrSuperclass(St.ClassName))return`uint8:${t.valueOf().toNumber()}`;if(t.hasClassOrSuperclass(xt.ClassName))return`uint16:${t.valueOf().toNumber()}`;if(t.hasClassOrSuperclass(Et.ClassName))return`uint32:${t.valueOf().toNumber()}`;if(t.hasClassOrSuperclass(Y.ClassName))return`uint64:${BigInt(t.valueOf().toFixed())}`;if(t.hasClassOrSuperclass(vt.ClassName))return`string:${t.valueOf()}`;if(t.hasClassOrSuperclass(mt.ClassName))return`bool:${t.valueOf()}`;if(t.hasClassOrSuperclass(ft.ClassName))return`address:${t.valueOf().bech32()}`;if(t.hasClassOrSuperclass(J.ClassName))return`token:${t.valueOf()}`;if(t.hasClassOrSuperclass(yt.ClassName))return`hex:${t.valueOf().toString("hex")}`;if(t.hasClassOrSuperclass(wt.ClassName))return`codemeta:${t.valueOf().toBuffer().toString("hex")}`;if(t.getType().getName()==="EsdtTokenPayment"){let e=t.getFieldValue("token_identifier").valueOf(),r=t.getFieldValue("token_nonce").valueOf(),n=t.getFieldValue("amount").valueOf();return`esdt:${e}|${r}|${n}`}throw new Error(`WarpArgSerializer (typedToString): Unsupported input type: ${t.getClassName()}`)}typedToNative(t){let e=this.typedToString(t);return this.coreSerializer.stringToNative(e)}nativeToTyped(t,e){let r=this.coreSerializer.nativeToString(t,e);return this.stringToTyped(r)}nativeToType(t){if(t.startsWith("composite")){let e=t.match(/\(([^)]+)\)/)?.[1];return new Tt(...e.split(b.ArgCompositeSeparator).map(r=>this.nativeToType(r)))}if(t==="string")return new bt;if(t==="uint8")return new Vt;if(t==="uint16")return new At;if(t==="uint32")return new Bt;if(t==="uint64")return new X;if(t==="biguint")return new z;if(t==="bool")return new gt;if(t==="address")return new lt;if(t==="token")return new K;if(t==="hex")return new dt;if(t==="codemeta")return new ht;if(t==="esdt"||t==="nft")return new It("EsdtTokenPayment",[new D("token_identifier","",new K),new D("token_nonce","",new X),new D("amount","",new z)]);throw new Error(`WarpArgSerializer (nativeToType): Unsupported input type: ${t}`)}stringToTyped(t){let[e,r]=t.split(/:(.*)/,2);if(e==="null"||e===null)return new C;if(e==="option"){let n=this.stringToTyped(r);return n instanceof C?G.newMissingTyped(n.getType()):G.newProvided(n)}if(e==="optional"){let n=this.stringToTyped(r);return n instanceof C?j.newMissing():new j(n.getType(),n)}if(e==="list"){let[n,s]=r.split(Pt,2),a=s.split(",").map(u=>this.stringToTyped(`${n}:${u}`));return new Ct(this.nativeToType(n),a)}if(e==="variadic"){let[n,s]=r.split(Pt,2),a=s.split(",").map(u=>this.stringToTyped(`${n}:${u}`));return new Rt(new Ft(this.nativeToType(n)),a)}if(e.startsWith("composite")){let n=e.match(/\(([^)]+)\)/)?.[1],s=r.split(b.ArgCompositeSeparator),o=n.split(b.ArgCompositeSeparator),a=s.map((c,p)=>this.stringToTyped(`${o[p]}:${c}`)),u=a.map(c=>c.getType());return new Wt(new Tt(...u),a)}if(e==="string")return r?vt.fromUTF8(r):new C;if(e==="uint8")return r?new St(Number(r)):new C;if(e==="uint16")return r?new xt(Number(r)):new C;if(e==="uint32")return r?new Et(Number(r)):new C;if(e==="uint64")return r?new Y(BigInt(r)):new C;if(e==="biguint")return r?new Q(BigInt(r)):new C;if(e==="bool")return r?new mt(typeof r=="boolean"?r:r==="true"):new C;if(e==="address")return r?new ft(ee.newFromBech32(r)):new C;if(e==="token")return r?new J(r):new C;if(e==="hex")return r?yt.fromHex(r):new C;if(e==="codemeta")return new wt(re.newFromBytes(Uint8Array.from(Buffer.from(r,"hex"))));if(e==="esdt"){let n=r.split(b.ArgCompositeSeparator);return new se(this.nativeToType("esdt"),[new H(new J(n[0]),"token_identifier"),new H(new Y(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 ie)return"option:"+this.typeToString(t.getFirstTypeParameter());if(t instanceof ae)return"optional:"+this.typeToString(t.getFirstTypeParameter());if(t instanceof ne)return"list:"+this.typeToString(t.getFirstTypeParameter());if(t instanceof Ft)return"variadic:"+this.typeToString(t.getFirstTypeParameter());if(t instanceof bt)return"string";if(t instanceof Vt)return"uint8";if(t instanceof At)return"uint16";if(t instanceof Bt)return"uint32";if(t instanceof X)return"uint64";if(t instanceof z)return"biguint";if(t instanceof gt)return"bool";if(t instanceof lt)return"address";if(t instanceof K)return"token";if(t instanceof dt)return"hex";if(t instanceof ht)return"codemeta";if(t instanceof It&&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 E(t),this.serializer=new B,this.cache=new ge(t.cache?.type)}async getTransactionExecutionResults(t,e){let[r,n]=_t(t),s=this.cache.get(me.WarpExecutable(this.config.env,t.meta?.hash||"",n))??[],o=await this.extractContractResults(t,e,s),a=fe(this.config,t,n,o),u=le(t,o.results);return{success:e.status.isSuccessful(),warp:t,action:n,user:this.config.user?.wallet||null,txHash:e.hash,next:a,values:o.values,results:o.results,messages:u}}async extractContractResults(t,e,r){let[n,s]=_t(t),o=[],a={};if(!t.results||n.type!=="contract")return{values:o,results:a};if(!Object.values(t.results).some(T=>T.includes("out")||T.includes("event"))){for(let[T,g]of Object.entries(t.results))a[T]=g;return{values:o,results:await U(t,a,s,r)}}let c=await this.abi.getAbiForAction(n),p=new pe({abi:c}),y=new ue({abi:c}).parseExecute({transactionOnNetwork:e,function:n.func||void 0});for(let[T,g]of Object.entries(t.results)){if(g.startsWith(kt.Transform.Prefix))continue;if(g.startsWith("input.")){a[T]=g;continue}let v=Ot(g);if(v!==null&&v!==s){a[T]=null;continue}let[W,A,I]=g.split(".");if(W==="event"){if(!A||isNaN(Number(I)))continue;let _=Number(I),h=ce(e,A),F=p.parseEvents({events:h})[0],O=Object.values(F)[_]||null;o.push(O),a[T]=O&&O.valueOf()}else if(W==="out"||W.startsWith("out[")){if(!A)continue;let _=Number(A),h=y.values[_-1]||null;I&&(h=h[I]||null),h&&typeof h=="object"&&(h="toFixed"in h?h.toFixed():h.valueOf()),o.push(h),a[T]=h&&h.valueOf()}else a[T]=g}return{values:o,results:await U(t,a,s,r)}}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(y=>parseInt(y)-1);if(p.length===0)return;let f=o[p[0]];for(let y=1;y<p.length;y++){if(f==null)return;f=f[p[y]]}return f};for(let[c,p]of Object.entries(t.results)){if(p.startsWith(kt.Transform.Prefix))continue;let f=Ot(p);if(f!==null&&f!==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(g,v=[]){if(a.has(g))return a.get(g);if(u.has(g))throw new Error(`Circular dependency detected at action ${g}`);u.add(g);let W=e.actions[g-1];if(!W)throw new Error(`Action ${g} not found`);let A;if(W.type==="query")A=await n.executeQuery(e,g,v);else if(W.type==="collect")A=await n.executeCollect(e,g,v,o);else throw new Error(`Unsupported or interactive action type: ${W.type}`);if(a.set(g,A),e.results)for(let I of Object.values(e.results)){let h=String(I).match(/^out\[(\d+)\]/);if(h){let F=parseInt(h[1],10);F!==g&&!a.has(F)&&await p(F)}}return u.delete(g),A}await p(r,s);let f={};for(let g of a.values())for(let[v,W]of Object.entries(g.results))W!==null?f[v]=W:v in f||(f[v]=null);let y=await U(e,f,r,s);return{...a.get(r),action:r,results:y}}};import{Address as de,AddressValue as ye,BigUIntType as he,BigUIntValue as Ut,BooleanValue as we,BytesValue as Te,CodeMetadata as We,CodeMetadataValue as Ce,CompositeType as be,CompositeValue as ve,Field as Z,FieldDefinition as tt,List as Ie,NothingValue as Ae,OptionalValue as et,OptionValue as rt,StringValue as xe,Struct as Be,StructType as Ee,TokenIdentifierType as Ve,TokenIdentifierValue as Nt,U16Value as Se,U32Value as Fe,U64Type as Re,U64Value as $t,U8Value as Pe,VariadicValue as _e}from"@multiversx/sdk-core";var nn=(i,t)=>i?rt.newProvided(i):t?rt.newMissingTyped(t):rt.newMissing(),an=(i,t)=>i?new et(i.getType(),i):t?new et(t):et.newMissing(),sn=i=>{if(i.length===0)throw new Error("Cannot create a list from an empty array");let t=i[0].getType();return new Ie(t,i)},on=i=>_e.fromItems(...i),cn=i=>{let t=i.map(e=>e.getType());return new ve(new be(...t),i)},x=i=>xe.fromUTF8(i),un=i=>new Pe(i),pn=i=>new Se(i),Mt=i=>new Fe(i),ln=i=>new $t(i),fn=i=>new Ut(BigInt(i)),gn=i=>new we(i),mn=i=>new ye(de.newFromBech32(i)),dn=i=>new Nt(i),yn=i=>Te.fromHex(i),qt=i=>new Be(new Ee("EsdtTokenPayment",[new tt("token_identifier","",new Ve),new tt("token_nonce","",new Re),new tt("amount","",new he)]),[new Z(new Nt(i.token.identifier),"token_identifier"),new Z(new $t(BigInt(i.token.nonce)),"token_nonce"),new Z(new Ut(BigInt(i.amount)),"amount")]),hn=i=>new Ce(We.newFromBytes(Uint8Array.from(Buffer.from(i,"hex")))),wn=()=>new Ae;var w=class i{constructor(t){this.config=t;this.serializer=new B,this.abi=new E(this.config),this.results=new V(this.config)}async createTransaction(t){let e=nt(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=R.newFromBech32(this.config.user.wallet),r=new Lt({chainID:t.chain.chainId}),n=t.data?Buffer.from(this.serializer.stringToTyped(t.data).valueOf()):null;return new ze({config:r}).createTransactionForTransfer(e,{receiver:R.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=nt(t.warp,t.action),r=R.newFromBech32(this.config.user.wallet),n=t.args.map(o=>this.serializer.stringToTyped(o)),s=new Lt({chainID:t.chain.chainId});return new Ne({config:s}).createTransactionForExecute(r,{contract:R.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=nt(t.warp,t.action);if(e.type!=="query")throw new Error(`WarpMultiversxExecutor: Invalid action type for executeQuery: ${e.type}`);let r=await this.abi.getAbiForAction(e),n=t.args.map(I=>this.serializer.stringToTyped(I)),s=i.getChainEntrypoint(t.chain,this.config.env),o=R.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",f=new Oe,y=r.getEndpoint(c.function||e.func||""),T=(c.returnDataParts||[]).map(I=>Buffer.from(I)),g=f.buffersToValues(T,y.output),{values:v,results:W}=await this.results.extractQueryResults(t.warp,g,t.action,t.resolvedInputs),A=De(this.config,t.warp,t.action,W);return{success:p,warp:t.warp,action:t.action,user:this.config.user?.wallet||null,txHash:null,next:A,values:v,results:W,messages:Qe(t.warp,W)}}async preprocessInput(t,e,r,n){if(r==="esdt"){let[s,o,a,u]=n.split(zt.ArgCompositeSeparator);if(u)return e;let c=new Me({identifier:s,nonce:BigInt(o)});if(!new qe().isFungible(c))return e;let y=He(s)?.decimals;if(y||(y=(await(await fetch(`${t.apiUrl}/tokens/${s}`)).json()).decimals),!y)throw new Error(`WarpActionExecutor: Decimals not found for token ${s}`);let T=qt(new Le({token:c,amount:je(a,y)}));return this.serializer.typedToString(T)+zt.ArgCompositeSeparator+y}return e}static getChainEntrypoint(t,e){let r="warp-sdk",n="api";return e==="devnet"?new ke(t.apiUrl,n,r):e==="testnet"?new $e(t.apiUrl,n,r):new Ue(t.apiUrl,n,r)}};var N=class{constructor(t){this.config=t;this.cache=new Xe(t.cache?.type),this.core=new Je(t)}createInscriptionTransaction(t){if(!this.config.user?.wallet)throw new Error("WarpBuilder: user address not set");let e=Ht(this.config),r=new Ge({chainID:e.chainId}),n=new Ke({config:r}),s=Qt.newFromBech32(this.config.user.wallet),o=JSON.stringify(t),a=n.createTransactionForTransfer(s,{receiver:Qt.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=Ye.Warp(this.config.env,t);if(e){let a=this.cache.get(r);if(a)return Dt.info(`WarpBuilder (createFromTransactionHash): Warp found in cache: ${t}`),a}let n=Ht(this.config),o=w.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 Dt.error("WarpBuilder: Error creating from transaction hash",a),null}}};var $=class{constructor(t){this.chainInfo=t}getAccountUrl(t){return`${this.chainInfo.explorerUrl}/accounts/${t}`}getTransactionUrl(t){return`${this.chainInfo.explorerUrl}/transactions/${t}`}};import{AbiRegistry as Gt,Address as l,AddressValue as it,BytesValue as m,SmartContractTransactionsFactory as tr,TransactionsFactoryConfig as er}from"@multiversx/sdk-core";import{getMainChainInfo as st,toTypedChainInfo as Kt,WarpCache as rr,WarpCacheKey as S,WarpLogger as P}from"@vleap/warps";var at={buildInfo:{rustc:{version:"1.86.0",commitHash:"05f9846f893b09a1be1fc8560e33fc3c815cfecb",commitDate:"2025-03-31",channel:"Stable",short:"rustc 1.86.0 (05f9846f8 2025-03-31)"},contractCrate:{name:"registry",version:"0.0.1"},framework:{name:"multiversx-sc",version:"0.51.1"}},name:"RegistryContract",constructor:{inputs:[{name:"unit_price",type:"BigUint"},{name:"vault",type:"Address"}],outputs:[]},upgradeConstructor:{inputs:[],outputs:[]},endpoints:[{name:"registerWarp",mutability:"mutable",payableInTokens:["EGLD"],inputs:[{name:"hash",type:"bytes"},{name:"alias_opt",type:"optional<bytes>",multi_arg:!0},{name:"brand_opt",type:"optional<bytes>",multi_arg:!0}],outputs:[],allow_multiple_var_args:!0},{name:"unregisterWarp",mutability:"mutable",inputs:[{name:"warp",type:"bytes"}],outputs:[]},{name:"upgradeWarp",mutability:"mutable",payableInTokens:["EGLD"],inputs:[{name:"alias",type:"bytes"},{name:"new_warp",type:"bytes"}],outputs:[]},{name:"setWarpAlias",mutability:"mutable",payableInTokens:["EGLD"],inputs:[{name:"hash",type:"bytes"},{name:"alias",type:"bytes"}],outputs:[]},{name:"forceRemoveAlias",mutability:"mutable",inputs:[{name:"hash",type:"bytes"}],outputs:[]},{name:"verifyWarp",mutability:"mutable",inputs:[{name:"warp",type:"bytes"}],outputs:[]},{name:"transferOwnership",mutability:"mutable",inputs:[{name:"warp",type:"bytes"},{name:"new_owner",type:"Address"}],outputs:[]},{name:"getUserWarps",mutability:"readonly",inputs:[{name:"address",type:"Address"}],outputs:[{type:"variadic<InfoView>",multi_result:!0}]},{name:"getInfoByAlias",mutability:"readonly",inputs:[{name:"alias",type:"bytes"}],outputs:[{type:"InfoView"}]},{name:"getInfoByHash",mutability:"readonly",inputs:[{name:"hash",type:"bytes"}],outputs:[{type:"InfoView"}]},{name:"setVault",onlyOwner:!0,mutability:"mutable",inputs:[{name:"vault",type:"Address"}],outputs:[]},{name:"setUnitPrice",onlyOwner:!0,mutability:"mutable",inputs:[{name:"amount",type:"BigUint"}],outputs:[]},{name:"addAdmin",onlyOwner:!0,mutability:"mutable",inputs:[{name:"address",type:"Address"}],outputs:[]},{name:"removeAdmin",onlyOwner:!0,mutability:"mutable",inputs:[{name:"address",type:"Address"}],outputs:[]},{name:"getConfig",mutability:"readonly",inputs:[],outputs:[{type:"ConfigView"}]},{name:"registerBrand",mutability:"mutable",payableInTokens:["EGLD"],inputs:[{name:"hash",type:"bytes"}],outputs:[]},{name:"brandWarp",mutability:"mutable",payableInTokens:["EGLD"],inputs:[{name:"warp",type:"bytes"},{name:"brand",type:"bytes"}],outputs:[]},{name:"getUserBrands",mutability:"readonly",inputs:[{name:"user",type:"Address"}],outputs:[{type:"variadic<bytes>",multi_result:!0}]},{name:"setChain",onlyOwner:!0,mutability:"mutable",inputs:[{name:"name",type:"bytes"},{name:"display_name",type:"bytes"},{name:"chain_id",type:"bytes"},{name:"block_time",type:"u32"},{name:"address_hrp",type:"bytes"},{name:"api_url",type:"bytes"},{name:"explorer_url",type:"bytes"},{name:"native_token",type:"bytes"}],outputs:[]},{name:"removeChain",onlyOwner:!0,mutability:"mutable",inputs:[{name:"name",type:"bytes"}],outputs:[]},{name:"getChain",mutability:"readonly",inputs:[{name:"name",type:"bytes"}],outputs:[{type:"ChainView"}]},{name:"getChains",mutability:"readonly",inputs:[],outputs:[{type:"variadic<ChainView>",multi_result:!0}]}],events:[{identifier:"warpRegistered",inputs:[{name:"hash",type:"bytes",indexed:!0},{name:"alias",type:"bytes",indexed:!0},{name:"trust",type:"bytes",indexed:!0}]},{identifier:"warpUnregistered",inputs:[{name:"hash",type:"bytes",indexed:!0}]},{identifier:"warpUpgraded",inputs:[{name:"alias",type:"bytes",indexed:!0},{name:"new_warp",type:"bytes",indexed:!0},{name:"trust",type:"bytes",indexed:!0}]},{identifier:"warpVerified",inputs:[{name:"hash",type:"bytes",indexed:!0}]},{identifier:"aliasUpdated",inputs:[{name:"hash",type:"bytes",indexed:!0},{name:"alias",type:"bytes",indexed:!0}]},{identifier:"ownershipTransferred",inputs:[{name:"warp",type:"bytes",indexed:!0},{name:"old_owner",type:"Address",indexed:!0},{name:"new_owner",type:"Address",indexed:!0}]}],esdtAttributes:[],hasCallback:!1,types:{ChainView:{type:"struct",fields:[{name:"name",type:"bytes"},{name:"display_name",type:"bytes"},{name:"chain_id",type:"bytes"},{name:"block_time",type:"u32"},{name:"address_hrp",type:"bytes"},{name:"api_url",type:"bytes"},{name:"explorer_url",type:"bytes"},{name:"native_token",type:"bytes"}]},ConfigView:{type:"struct",fields:[{name:"unit_price",type:"BigUint"},{name:"admins",type:"List<Address>"}]},InfoView:{type:"struct",fields:[{name:"hash",type:"bytes"},{name:"alias",type:"Option<bytes>"},{name:"trust",type:"bytes"},{name:"owner",type:"Address"},{name:"created_at",type:"u64"},{name:"upgraded_at",type:"u64"},{name:"brand",type:"Option<bytes>"},{name:"upgrade",type:"Option<bytes>"}]}}};var d=i=>i==="devnet"?"erd1qqqqqqqqqqqqqpgqje2f99vr6r7sk54thg03c9suzcvwr4nfl3tsfkdl36":i==="testnet"?"####":"erd1qqqqqqqqqqqqqpgq3mrpj3u6q7tejv6d7eqhnyd27n9v5c5tl3ts08mffe";var M=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}),jt=i=>({unitPrice:BigInt(i.unit_price.toString()),admins:i.admins.map(t=>t.toBech32())});var q=class{constructor(t){this.config=t;this.cache=new rr(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=l.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?[m.fromHex(t),m.fromUTF8(e),m.fromHex(r)]:e?[m.fromHex(t),m.fromUTF8(e)]:[m.fromHex(t)];return this.getFactory().createTransactionForExecute(n,{contract:l.newFromBech32(d(this.config.env)),function:"registerWarp",gasLimit:BigInt(1e7),nativeTransferAmount:s(),arguments:o()})}createWarpUnregisterTransaction(t){if(!this.config.user?.wallet)throw new Error("WarpRegistry: user address not set");let e=l.newFromBech32(this.config.user.wallet);return this.getFactory().createTransactionForExecute(e,{contract:l.newFromBech32(d(this.config.env)),function:"unregisterWarp",gasLimit:BigInt(1e7),arguments:[m.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=l.newFromBech32(this.config.user.wallet);return this.getFactory().createTransactionForExecute(r,{contract:l.newFromBech32(d(this.config.env)),function:"upgradeWarp",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[m.fromUTF8(t),m.fromHex(e)]})}createWarpAliasSetTransaction(t,e){if(!this.config.user?.wallet)throw new Error("WarpRegistry: user address not set");let r=l.newFromBech32(this.config.user.wallet);return this.getFactory().createTransactionForExecute(r,{contract:l.newFromBech32(d(this.config.env)),function:"setWarpAlias",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[m.fromHex(t),m.fromUTF8(e)]})}createWarpVerifyTransaction(t){if(!this.config.user?.wallet)throw new Error("WarpRegistry: user address not set");let e=l.newFromBech32(this.config.user.wallet);return this.getFactory().createTransactionForExecute(e,{contract:l.newFromBech32(d(this.config.env)),function:"verifyWarp",gasLimit:BigInt(1e7),arguments:[m.fromHex(t)]})}createWarpTransferOwnershipTransaction(t,e){if(!this.config.user?.wallet)throw new Error("WarpRegistry: user address not set");let r=l.newFromBech32(this.config.user.wallet);return this.getFactory().createTransactionForExecute(r,{contract:l.newFromBech32(d(this.config.env)),function:"transferOwnership",gasLimit:BigInt(1e7),arguments:[m.fromHex(t),new it(new l(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=l.newFromBech32(this.config.user.wallet);return this.getFactory().createTransactionForExecute(e,{contract:l.newFromBech32(d(this.config.env)),function:"registerBrand",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[m.fromHex(t)]})}createWarpBrandingTransaction(t,e){if(!this.config.user?.wallet)throw new Error("WarpRegistry: user address not set");let r=l.newFromBech32(this.config.user.wallet);return this.getFactory().createTransactionForExecute(r,{contract:l.newFromBech32(d(this.config.env)),function:"brandWarp",gasLimit:BigInt(1e7),nativeTransferAmount:this.isCurrentUserAdmin()?void 0:this.registryConfig.unitPrice,arguments:[m.fromHex(t),m.fromHex(e)]})}async getInfoByAlias(t,e){try{let r=S.RegistryInfo(this.config.env,t),n=e?this.cache.get(r):null;if(n)return P.info(`WarpRegistry (getInfoByAlias): RegistryInfo found in cache: ${t}`),n;let s=l.newFromBech32(d(this.config.env)),o=this.getController(),a=o.createQuery({contract:s,function:"getInfoByAlias",arguments:[m.fromUTF8(t)]}),u=await o.runQuery(a),[c]=o.parseQueryResponse(u),p=c?M(c):null,f=p?.brand?await this.fetchBrand(p.brand):null;return e&&e.ttl&&this.cache.set(r,{registryInfo:p,brand:f},e.ttl),{registryInfo:p,brand:f}}catch{return{registryInfo:null,brand:null}}}async getInfoByHash(t,e){try{let r=S.RegistryInfo(this.config.env,t);if(e){let f=this.cache.get(r);if(f)return P.info(`WarpRegistry (getInfoByHash): RegistryInfo found in cache: ${t}`),f}let n=l.newFromBech32(d(this.config.env)),s=this.getController(),o=s.createQuery({contract:n,function:"getInfoByHash",arguments:[m.fromHex(t)]}),a=await s.runQuery(o),[u]=s.parseQueryResponse(a),c=u?M(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=l.newFromBech32(d(this.config.env)),n=this.getController(),s=n.createQuery({contract:r,function:"getUserWarps",arguments:[new it(new l(e))]}),o=await n.runQuery(s),[a]=n.parseQueryResponse(o);return a.map(M)}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=l.newFromBech32(d(this.config.env)),n=this.getController(),s=n.createQuery({contract:r,function:"getUserBrands",arguments:[new it(new l(e))]}),o=await n.runQuery(s),[a]=n.parseQueryResponse(o),u=a.map(f=>f.toString("hex")),c={ttl:365*24*60*60};return(await Promise.all(u.map(f=>this.fetchBrand(f,c)))).filter(f=>f!==null)}catch{return[]}}async getChainInfos(t){let e=S.ChainInfos(this.config.env);if(t&&t.ttl){let c=this.cache.get(e);if(c)return P.info("WarpRegistry (getChainInfos): ChainInfos found in cache"),c}let r=l.newFromBech32(d(this.config.env)),n=this.getController(),s=n.createQuery({contract:r,function:"getChains",arguments:[]}),o=await n.runQuery(s),[a]=n.parseQueryResponse(o),u=a.map(Kt);if(t&&t.ttl){for(let c of u)this.cache.set(S.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=S.ChainInfo(this.config.env,t),n=e?this.cache.get(r):null;if(n)return P.info(`WarpRegistry (getChainInfo): ChainInfo found in cache: ${t}`),n;let s=l.newFromBech32(d(this.config.env)),o=this.getController(),a=o.createQuery({contract:s,function:"getChain",arguments:[m.fromUTF8(t)]}),u=await o.runQuery(a),[c]=o.parseQueryResponse(u),p=c?Kt(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=l.newFromBech32(this.config.user.wallet);return this.getFactory().createTransactionForExecute(e,{contract:l.newFromBech32(d(this.config.env)),function:"setChain",gasLimit:BigInt(1e7),arguments:[x(t.name),x(t.displayName),x(t.chainId),Mt(t.blockTime),x(t.addressHrp),x(t.apiUrl),x(t.explorerUrl),x(t.nativeToken)]})}async removeChain(t){if(!this.config.user?.wallet)throw new Error("WarpRegistry: user address not set");let e=l.newFromBech32(this.config.user.wallet);return this.getFactory().createTransactionForExecute(e,{contract:l.newFromBech32(d(this.config.env)),function:"removeChain",gasLimit:BigInt(1e7),arguments:[x(t)]})}async fetchBrand(t,e){let r=S.Brand(this.config.env,t),n=e?this.cache.get(r):null;if(n)return P.info(`WarpRegistry (fetchBrand): Brand found in cache: ${t}`),n;let s=st(this.config),a=w.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}}async loadRegistryConfigs(){let t=l.newFromBech32(d(this.config.env)),e=this.getController(),[r]=await e.query({contract:t,function:"getConfig",arguments:[]}),n=r?jt(r):null;this.registryConfig=n||{unitPrice:BigInt(0),admins:[]}}getFactory(){let t=st(this.config),e=new er({chainID:t.chainId}),r=Gt.create(at);return new tr({config:e,abi:r})}getController(){let t=st(this.config),e=w.getChainEntrypoint(t,this.config.env),r=Gt.create(at);return e.createSmartContractController(r)}isCurrentUserAdmin(){return!!this.config.user?.wallet&&this.registryConfig.admins.includes(this.config.user.wallet)}};var Ca=i=>({chain:"multiversx",prefix:"mvx",builder:new N(i),executor:new w(i),results:new V(i),serializer:new B,registry:new q(i),explorer:t=>new $(t)});import{Address as Jt,TransactionsFactoryConfig as nr,TransferTransactionsFactory as ar}from"@multiversx/sdk-core";import{getMainChainInfo as Xt,WarpBrandBuilder as ir,WarpLogger as sr}from"@vleap/warps";import{Buffer as or}from"buffer";var Yt=class{constructor(t){this.config=t;this.core=new ir(t)}createInscriptionTransaction(t){if(!this.config.user?.wallet)throw new Error("BrandBuilder: user address not set");let e=Xt(this.config),r=new nr({chainID:e.chainId}),n=new ar({config:r}),s=Jt.newFromBech32(this.config.user.wallet),o=JSON.stringify(t);return n.createTransactionForNativeTokenTransfer(s,{receiver:Jt.newFromBech32(this.config.user.wallet),nativeAmount:BigInt(0),data:Uint8Array.from(or.from(o))})}async createFromTransaction(t,e=!1){return await this.core.createFromRaw(t.data.toString(),e)}async createFromTransactionHash(t){let e=Xt(this.config),n=w.getChainEntrypoint(e,this.config.env).createNetworkProvider();try{let s=await n.getTransaction(t);return this.createFromTransaction(s)}catch(s){return sr.error("BrandBuilder: Error creating from transaction hash",s),null}}};export{E as WarpMultiversxAbi,Yt as WarpMultiversxBrandBuilder,N as WarpMultiversxBuilder,cr as WarpMultiversxConstants,k as WarpMultiversxContractLoader,w as WarpMultiversxExecutor,$ as WarpMultiversxExplorer,q as WarpMultiversxRegistry,V as WarpMultiversxResults,B as WarpMultiversxSerializer,mn as address_value,fn as biguint_value,gn as boolean_value,hn as codemeta_value,cn as composite_value,qt as esdt_value,Ca as getMultiversxAdapter,yn as hex_value,sn as list_value,wn as nothing_value,nn as option_value,an as optional_value,x as string_value,dn as token_value,pn as u16_value,Mt as u32_value,ln as u64_value,un as u8_value,on as variadic_value};
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@vleap/warps-adapter-multiversx",
3
- "version": "0.2.0-alpha.1",
3
+ "version": "0.2.0-alpha.11",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "module": "./dist/index.js",
8
8
  "scripts": {
9
- "build": "tsup src/index.ts --dts --format cjs,esm --minify --clean",
9
+ "build": "tsup",
10
10
  "test": "jest --config jest.config.js",
11
11
  "lint": "tsc --noEmit",
12
12
  "prepare": "npm run build",
@@ -18,21 +18,19 @@
18
18
  "dist"
19
19
  ],
20
20
  "devDependencies": {
21
- "@multiversx/sdk-core": "^14.2.1",
22
21
  "@types/jest": "^29.5.14",
23
22
  "jest": "^30.0.0",
24
23
  "jest-environment-jsdom": "^30.0.0",
25
24
  "jest-fetch-mock": "^3.0.3",
26
25
  "ts-jest": "^29.4.0",
27
26
  "tsup": "^8.5.0",
28
- "typescript": "^5.8.3",
29
- "vm2": "^3.9.19"
27
+ "typescript": "^5.8.3"
30
28
  },
31
29
  "publishConfig": {
32
30
  "access": "public"
33
31
  },
34
32
  "dependencies": {
35
- "@vleap/warps-core": "^0.2.0-alpha.0",
36
- "@multiversx/sdk-core": "^14.2.1"
33
+ "@multiversx/sdk-core": "^14.2.1",
34
+ "@vleap/warps": "^3.0.0-alpha.47"
37
35
  }
38
36
  }