@joai/warps-adapter-sui 1.0.0-beta.74
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/README.md +39 -0
- package/dist/index.d.cts +237 -0
- package/dist/index.d.ts +237 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/package.json +43 -0
package/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# @joai/warps-adapter-sui
|
|
2
|
+
|
|
3
|
+
Sui blockchain adapter for the Warps SDK. Enables Warp execution on the Sui network.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @joai/warps-adapter-sui
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { WarpClient, withAdapterFallback } from '@joai/warps'
|
|
15
|
+
import { SuiAdapter } from '@joai/warps-adapter-sui'
|
|
16
|
+
import { MultiversxAdapter } from '@joai/warps-adapter-multiversx'
|
|
17
|
+
|
|
18
|
+
// Sui adapter requires a fallback adapter
|
|
19
|
+
const client = new WarpClient(config, {
|
|
20
|
+
chains: [withAdapterFallback(SuiAdapter, MultiversxAdapter)],
|
|
21
|
+
})
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Features
|
|
25
|
+
|
|
26
|
+
- Transaction creation and execution
|
|
27
|
+
- Move package interaction
|
|
28
|
+
- Token transfers
|
|
29
|
+
- Query object state
|
|
30
|
+
- Transaction signing and execution
|
|
31
|
+
- Explorer integration
|
|
32
|
+
- ABI and brand builders
|
|
33
|
+
|
|
34
|
+
## Wallet Providers
|
|
35
|
+
|
|
36
|
+
Supports multiple wallet providers:
|
|
37
|
+
- Private key
|
|
38
|
+
- Mnemonic
|
|
39
|
+
- Read-only (for queries)
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { WarpChainEnv, WarpClientConfig, WarpChainInfo, WarpRegistryInfo, WarpChainAsset, ChainAdapterFactory, AdapterWarpAbiBuilder, WarpAbiContents, WarpAdapterGenericTransaction, WarpCacheConfig, AdapterWarpBrandBuilder, WarpBrand, WarpBuilder, AdapterWarpBuilder, Warp, AdapterWarpDataLoader, WarpChainAccount, WarpChainAction, WarpDataLoaderOptions, AdapterWarpExecutor, WarpExecutable, WarpActionExecutionResult, AdapterWarpExplorer, AdapterWarpRegistry, WarpRegistryConfigInfo, AdapterWarpOutput, WarpActionIndex, WarpAdapterGenericRemoteTransaction, ResolvedInput, WarpExecutionOutput, AdapterWarpSerializer, WarpSerializer, WarpActionInputType, WarpNativeValue, AdapterWarpWallet, WarpWalletDetails, WarpWalletProvider } from '@joai/warps';
|
|
2
|
+
import * as _mysten_sui_client from '@mysten/sui/client';
|
|
3
|
+
import { SuiClient } from '@mysten/sui/client';
|
|
4
|
+
import { Transaction } from '@mysten/sui/transactions';
|
|
5
|
+
import * as _mysten_sui_dist_cjs_client from '@mysten/sui/dist/cjs/client';
|
|
6
|
+
|
|
7
|
+
declare const getSuiRegistryPackageId: (env: WarpChainEnv) => string;
|
|
8
|
+
declare const getSuiRegistryObjectId: (env: WarpChainEnv) => string;
|
|
9
|
+
|
|
10
|
+
declare const WarpSuiConstants: {
|
|
11
|
+
Sui: {
|
|
12
|
+
Identifier: string;
|
|
13
|
+
DisplayName: string;
|
|
14
|
+
Decimals: number;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
declare enum SuiExplorers {
|
|
18
|
+
SuiVision = "suivision",
|
|
19
|
+
SuiVisionTestnet = "suivision_testnet",
|
|
20
|
+
SuiVisionDevnet = "suivision_devnet",
|
|
21
|
+
SuiScan = "suiscan",
|
|
22
|
+
SuiScanTestnet = "suiscan_testnet",
|
|
23
|
+
SuiScanDevnet = "suiscan_devnet"
|
|
24
|
+
}
|
|
25
|
+
type ExplorerName = SuiExplorers;
|
|
26
|
+
declare const SuiExplorersConfig: {
|
|
27
|
+
readonly sui: {
|
|
28
|
+
readonly mainnet: readonly [SuiExplorers.SuiVision, SuiExplorers.SuiScan];
|
|
29
|
+
readonly testnet: readonly [SuiExplorers.SuiVisionTestnet, SuiExplorers.SuiScanTestnet];
|
|
30
|
+
readonly devnet: readonly [SuiExplorers.SuiVisionDevnet, SuiExplorers.SuiScanDevnet];
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
declare const ExplorerUrls: Record<ExplorerName, string>;
|
|
34
|
+
|
|
35
|
+
declare const getConfiguredSuiClient: (config: WarpClientConfig, chain: WarpChainInfo) => SuiClient;
|
|
36
|
+
|
|
37
|
+
declare const toRegistryMoveTarget: (env: WarpChainEnv, module: string) => string;
|
|
38
|
+
declare const toTypedRegistryInfo: (infoView: any) => WarpRegistryInfo;
|
|
39
|
+
|
|
40
|
+
declare const NativeTokenSui: WarpChainAsset;
|
|
41
|
+
declare const SuiAdapter: ChainAdapterFactory;
|
|
42
|
+
|
|
43
|
+
declare const KnownTokens: WarpChainAsset[];
|
|
44
|
+
declare const findKnownTokenById: (id: string) => WarpChainAsset | null;
|
|
45
|
+
|
|
46
|
+
declare class WarpSuiAbiBuilder implements AdapterWarpAbiBuilder {
|
|
47
|
+
private readonly config;
|
|
48
|
+
private readonly chain;
|
|
49
|
+
private readonly client;
|
|
50
|
+
constructor(config: WarpClientConfig, chain: WarpChainInfo);
|
|
51
|
+
createInscriptionTransaction(abi: WarpAbiContents): Promise<WarpAdapterGenericTransaction>;
|
|
52
|
+
createFromRaw(encoded: string): Promise<any>;
|
|
53
|
+
createFromTransaction(tx: any): Promise<any>;
|
|
54
|
+
createFromTransactionHash(hash: string, cache?: WarpCacheConfig): Promise<any | null>;
|
|
55
|
+
getModuleAbi(packageId: string, moduleName: string): Promise<_mysten_sui_client.SuiMoveNormalizedModule>;
|
|
56
|
+
getFunctionAbi(packageId: string, moduleName: string, functionName: string): Promise<_mysten_sui_client.SuiMoveNormalizedFunction>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
declare class WarpSuiBrandBuilder implements AdapterWarpBrandBuilder {
|
|
60
|
+
private readonly config;
|
|
61
|
+
private readonly chain;
|
|
62
|
+
private readonly client;
|
|
63
|
+
constructor(config: WarpClientConfig, chain: WarpChainInfo);
|
|
64
|
+
createInscriptionTransaction(brand: WarpBrand): Transaction;
|
|
65
|
+
createFromRaw(encoded: string): Promise<WarpBrand>;
|
|
66
|
+
createFromTransaction(tx: any, validate?: boolean): Promise<WarpBrand>;
|
|
67
|
+
createFromTransactionHash(hash: string, cache?: WarpCacheConfig): Promise<WarpBrand | null>;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
declare class WarpSuiBuilder extends WarpBuilder implements AdapterWarpBuilder {
|
|
71
|
+
protected readonly config: WarpClientConfig;
|
|
72
|
+
private readonly chain;
|
|
73
|
+
private cache;
|
|
74
|
+
private client;
|
|
75
|
+
private userWallet;
|
|
76
|
+
constructor(config: WarpClientConfig, chain: WarpChainInfo);
|
|
77
|
+
createInscriptionTransaction(warp: Warp, registryObjectId?: string): Promise<WarpAdapterGenericTransaction>;
|
|
78
|
+
createFromNetwork(id: string, cache?: WarpCacheConfig): Promise<Warp | null>;
|
|
79
|
+
createFromTransaction(info: any): Promise<Warp>;
|
|
80
|
+
createFromTransactionHash(id: string, cache?: WarpCacheConfig): Promise<Warp | null>;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
declare class WarpSuiContractLoader {
|
|
84
|
+
private readonly abi;
|
|
85
|
+
constructor(config: WarpClientConfig, chain: WarpChainInfo);
|
|
86
|
+
loadModuleAbi(packageId: string, moduleName: string): Promise<_mysten_sui_dist_cjs_client.SuiMoveNormalizedModule>;
|
|
87
|
+
loadFunctionAbi(packageId: string, moduleName: string, functionName: string): Promise<_mysten_sui_dist_cjs_client.SuiMoveNormalizedFunction>;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
declare class WarpSuiDataLoader implements AdapterWarpDataLoader {
|
|
91
|
+
private readonly config;
|
|
92
|
+
private readonly chain;
|
|
93
|
+
client: SuiClient;
|
|
94
|
+
private cache;
|
|
95
|
+
constructor(config: WarpClientConfig, chain: WarpChainInfo);
|
|
96
|
+
getAccount(address: string): Promise<WarpChainAccount>;
|
|
97
|
+
getAccountAssets(address: string): Promise<WarpChainAsset[]>;
|
|
98
|
+
getAsset(identifier: string): Promise<WarpChainAsset | null>;
|
|
99
|
+
getAction(identifier: string, awaitCompleted?: boolean): Promise<WarpChainAction | null>;
|
|
100
|
+
getAccountActions(address: string, options?: WarpDataLoaderOptions): Promise<WarpChainAction[]>;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
declare class WarpSuiExecutor implements AdapterWarpExecutor {
|
|
104
|
+
private readonly config;
|
|
105
|
+
private readonly chain;
|
|
106
|
+
private readonly serializer;
|
|
107
|
+
private readonly output;
|
|
108
|
+
private readonly client;
|
|
109
|
+
private readonly userWallet;
|
|
110
|
+
constructor(config: WarpClientConfig, chain: WarpChainInfo);
|
|
111
|
+
createTransaction(executable: WarpExecutable): Promise<Transaction>;
|
|
112
|
+
createTransferTransaction(executable: WarpExecutable): Promise<Transaction>;
|
|
113
|
+
createContractCallTransaction(executable: WarpExecutable): Promise<Transaction>;
|
|
114
|
+
executeQuery(executable: WarpExecutable): Promise<WarpActionExecutionResult>;
|
|
115
|
+
signMessage(message: string, privateKey: string): Promise<string>;
|
|
116
|
+
private parseMoveCallTarget;
|
|
117
|
+
private buildPublicTransferArgs;
|
|
118
|
+
private extractObjectId;
|
|
119
|
+
private handleCoinTransfer;
|
|
120
|
+
private createCoinTransferFromObjects;
|
|
121
|
+
private getCoinObjectsForTransfer;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
declare class WarpSuiExplorer implements AdapterWarpExplorer {
|
|
125
|
+
private readonly config;
|
|
126
|
+
private readonly chain;
|
|
127
|
+
constructor(config: WarpClientConfig, chain: WarpChainInfo);
|
|
128
|
+
private getExplorers;
|
|
129
|
+
private getPrimaryExplorer;
|
|
130
|
+
private getExplorerUrlByName;
|
|
131
|
+
getAccountUrl(address: string, explorer?: ExplorerName): string;
|
|
132
|
+
getTransactionUrl(hash: string, explorer?: ExplorerName): string;
|
|
133
|
+
getBlockUrl(blockNumber: string | number, explorer?: ExplorerName): string;
|
|
134
|
+
getAssetUrl(identifier: string, explorer?: ExplorerName): string;
|
|
135
|
+
getContractUrl(address: string, explorer?: ExplorerName): string;
|
|
136
|
+
getAllExplorers(): readonly ExplorerName[];
|
|
137
|
+
getExplorerByName(name: string): ExplorerName | undefined;
|
|
138
|
+
getAccountUrls(address: string): Record<ExplorerName, string>;
|
|
139
|
+
getTransactionUrls(hash: string): Record<ExplorerName, string>;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
declare class WarpSuiRegistry implements AdapterWarpRegistry {
|
|
143
|
+
private config;
|
|
144
|
+
private readonly chain;
|
|
145
|
+
private client;
|
|
146
|
+
private cache;
|
|
147
|
+
private userWallet;
|
|
148
|
+
registryConfig: WarpRegistryConfigInfo;
|
|
149
|
+
constructor(config: WarpClientConfig, chain: WarpChainInfo);
|
|
150
|
+
init(): Promise<void>;
|
|
151
|
+
getRegistryConfig(): WarpRegistryConfigInfo;
|
|
152
|
+
private loadRegistryConfigs;
|
|
153
|
+
createWarpRegisterTransaction(txHash: string, alias?: string | null, brand?: string | null): Promise<Transaction>;
|
|
154
|
+
createWarpUnregisterTransaction(txHash: string): Promise<Transaction>;
|
|
155
|
+
createWarpUpgradeTransaction(alias: string, txHash: string): Promise<Transaction>;
|
|
156
|
+
createWarpAliasSetTransaction(txHash: string, alias: string): Promise<Transaction>;
|
|
157
|
+
createWarpVerifyTransaction(txHash: string): Promise<Transaction>;
|
|
158
|
+
createWarpTransferOwnershipTransaction(txHash: string, newOwner: string): Promise<Transaction>;
|
|
159
|
+
createBrandRegisterTransaction(brand: string): Promise<Transaction>;
|
|
160
|
+
createWarpBrandingTransaction(warpHash: string, brandHash: string): Promise<Transaction>;
|
|
161
|
+
getInfoByAlias(alias: string, cacheConfig?: WarpCacheConfig): Promise<{
|
|
162
|
+
registryInfo: WarpRegistryInfo | null;
|
|
163
|
+
brand: WarpBrand | null;
|
|
164
|
+
}>;
|
|
165
|
+
getInfoByHash(hash: string, cache?: WarpCacheConfig): Promise<{
|
|
166
|
+
registryInfo: WarpRegistryInfo | null;
|
|
167
|
+
brand: WarpBrand | null;
|
|
168
|
+
}>;
|
|
169
|
+
getUserWarpRegistryInfos(user?: string): Promise<WarpRegistryInfo[]>;
|
|
170
|
+
getUserBrands(user?: string): Promise<WarpBrand[]>;
|
|
171
|
+
fetchBrand(hash: string, cacheConfig?: WarpCacheConfig): Promise<WarpBrand | null>;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
declare class WarpSuiOutput implements AdapterWarpOutput {
|
|
175
|
+
private readonly config;
|
|
176
|
+
private readonly chain;
|
|
177
|
+
private readonly serializer;
|
|
178
|
+
private readonly client;
|
|
179
|
+
constructor(config: WarpClientConfig, chain: WarpChainInfo);
|
|
180
|
+
getActionExecution(warp: Warp, actionIndex: WarpActionIndex, tx: WarpAdapterGenericRemoteTransaction): Promise<WarpActionExecutionResult>;
|
|
181
|
+
extractContractOutput(warp: Warp, actionIndex: WarpActionIndex, tx: any, inputs: ResolvedInput[]): Promise<{
|
|
182
|
+
values: {
|
|
183
|
+
string: string[];
|
|
184
|
+
native: any[];
|
|
185
|
+
mapped: Record<string, any>;
|
|
186
|
+
};
|
|
187
|
+
output: WarpExecutionOutput;
|
|
188
|
+
}>;
|
|
189
|
+
extractQueryOutput(warp: Warp, typedValues: any[], actionIndex: number, inputs: ResolvedInput[]): Promise<{
|
|
190
|
+
values: {
|
|
191
|
+
string: string[];
|
|
192
|
+
native: any[];
|
|
193
|
+
mapped: Record<string, any>;
|
|
194
|
+
};
|
|
195
|
+
output: WarpExecutionOutput;
|
|
196
|
+
}>;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
declare class WarpSuiSerializer implements AdapterWarpSerializer {
|
|
200
|
+
readonly coreSerializer: WarpSerializer;
|
|
201
|
+
constructor();
|
|
202
|
+
typedToString(value: any): string;
|
|
203
|
+
typedToNative(value: any): [WarpActionInputType, WarpNativeValue];
|
|
204
|
+
nativeToTyped(type: WarpActionInputType, value: WarpNativeValue): any;
|
|
205
|
+
stringToTyped(value: string, tx?: Transaction): any;
|
|
206
|
+
typeToString(type: any): WarpActionInputType;
|
|
207
|
+
nativeToType(type: any): any;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
declare class WarpSuiWallet implements AdapterWarpWallet {
|
|
211
|
+
private config;
|
|
212
|
+
private chain;
|
|
213
|
+
private client;
|
|
214
|
+
private walletProvider;
|
|
215
|
+
private cachedAddress;
|
|
216
|
+
private cachedPublicKey;
|
|
217
|
+
private isInitializedPromise;
|
|
218
|
+
private isInitializedResolve;
|
|
219
|
+
constructor(config: WarpClientConfig, chain: WarpChainInfo);
|
|
220
|
+
waitUntilInitialized(): Promise<void>;
|
|
221
|
+
signTransaction(tx: WarpAdapterGenericTransaction): Promise<WarpAdapterGenericTransaction>;
|
|
222
|
+
signMessage(message: string): Promise<string>;
|
|
223
|
+
signTransactions(txs: WarpAdapterGenericTransaction[]): Promise<WarpAdapterGenericTransaction[]>;
|
|
224
|
+
sendTransaction(tx: WarpAdapterGenericTransaction): Promise<string>;
|
|
225
|
+
sendTransactions(txs: WarpAdapterGenericTransaction[]): Promise<string[]>;
|
|
226
|
+
importFromMnemonic(mnemonic: string): Promise<WarpWalletDetails>;
|
|
227
|
+
importFromPrivateKey(privateKey: string): Promise<WarpWalletDetails>;
|
|
228
|
+
export(provider: WarpWalletProvider): Promise<WarpWalletDetails>;
|
|
229
|
+
generate(provider: WarpWalletProvider): Promise<WarpWalletDetails>;
|
|
230
|
+
getAddress(): string | null;
|
|
231
|
+
getPublicKey(): string | null;
|
|
232
|
+
private createProvider;
|
|
233
|
+
private initializeCache;
|
|
234
|
+
private createProviderForOperation;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export { type ExplorerName, ExplorerUrls, KnownTokens, NativeTokenSui, SuiAdapter, SuiExplorers, SuiExplorersConfig, WarpSuiAbiBuilder, WarpSuiBrandBuilder, WarpSuiBuilder, WarpSuiConstants, WarpSuiContractLoader, WarpSuiDataLoader, WarpSuiExecutor, WarpSuiExplorer, WarpSuiOutput, WarpSuiRegistry, WarpSuiSerializer, WarpSuiWallet, findKnownTokenById, getConfiguredSuiClient, getSuiRegistryObjectId, getSuiRegistryPackageId, toRegistryMoveTarget, toTypedRegistryInfo };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { WarpChainEnv, WarpClientConfig, WarpChainInfo, WarpRegistryInfo, WarpChainAsset, ChainAdapterFactory, AdapterWarpAbiBuilder, WarpAbiContents, WarpAdapterGenericTransaction, WarpCacheConfig, AdapterWarpBrandBuilder, WarpBrand, WarpBuilder, AdapterWarpBuilder, Warp, AdapterWarpDataLoader, WarpChainAccount, WarpChainAction, WarpDataLoaderOptions, AdapterWarpExecutor, WarpExecutable, WarpActionExecutionResult, AdapterWarpExplorer, AdapterWarpRegistry, WarpRegistryConfigInfo, AdapterWarpOutput, WarpActionIndex, WarpAdapterGenericRemoteTransaction, ResolvedInput, WarpExecutionOutput, AdapterWarpSerializer, WarpSerializer, WarpActionInputType, WarpNativeValue, AdapterWarpWallet, WarpWalletDetails, WarpWalletProvider } from '@joai/warps';
|
|
2
|
+
import * as _mysten_sui_client from '@mysten/sui/client';
|
|
3
|
+
import { SuiClient } from '@mysten/sui/client';
|
|
4
|
+
import { Transaction } from '@mysten/sui/transactions';
|
|
5
|
+
import * as _mysten_sui_dist_cjs_client from '@mysten/sui/dist/cjs/client';
|
|
6
|
+
|
|
7
|
+
declare const getSuiRegistryPackageId: (env: WarpChainEnv) => string;
|
|
8
|
+
declare const getSuiRegistryObjectId: (env: WarpChainEnv) => string;
|
|
9
|
+
|
|
10
|
+
declare const WarpSuiConstants: {
|
|
11
|
+
Sui: {
|
|
12
|
+
Identifier: string;
|
|
13
|
+
DisplayName: string;
|
|
14
|
+
Decimals: number;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
declare enum SuiExplorers {
|
|
18
|
+
SuiVision = "suivision",
|
|
19
|
+
SuiVisionTestnet = "suivision_testnet",
|
|
20
|
+
SuiVisionDevnet = "suivision_devnet",
|
|
21
|
+
SuiScan = "suiscan",
|
|
22
|
+
SuiScanTestnet = "suiscan_testnet",
|
|
23
|
+
SuiScanDevnet = "suiscan_devnet"
|
|
24
|
+
}
|
|
25
|
+
type ExplorerName = SuiExplorers;
|
|
26
|
+
declare const SuiExplorersConfig: {
|
|
27
|
+
readonly sui: {
|
|
28
|
+
readonly mainnet: readonly [SuiExplorers.SuiVision, SuiExplorers.SuiScan];
|
|
29
|
+
readonly testnet: readonly [SuiExplorers.SuiVisionTestnet, SuiExplorers.SuiScanTestnet];
|
|
30
|
+
readonly devnet: readonly [SuiExplorers.SuiVisionDevnet, SuiExplorers.SuiScanDevnet];
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
declare const ExplorerUrls: Record<ExplorerName, string>;
|
|
34
|
+
|
|
35
|
+
declare const getConfiguredSuiClient: (config: WarpClientConfig, chain: WarpChainInfo) => SuiClient;
|
|
36
|
+
|
|
37
|
+
declare const toRegistryMoveTarget: (env: WarpChainEnv, module: string) => string;
|
|
38
|
+
declare const toTypedRegistryInfo: (infoView: any) => WarpRegistryInfo;
|
|
39
|
+
|
|
40
|
+
declare const NativeTokenSui: WarpChainAsset;
|
|
41
|
+
declare const SuiAdapter: ChainAdapterFactory;
|
|
42
|
+
|
|
43
|
+
declare const KnownTokens: WarpChainAsset[];
|
|
44
|
+
declare const findKnownTokenById: (id: string) => WarpChainAsset | null;
|
|
45
|
+
|
|
46
|
+
declare class WarpSuiAbiBuilder implements AdapterWarpAbiBuilder {
|
|
47
|
+
private readonly config;
|
|
48
|
+
private readonly chain;
|
|
49
|
+
private readonly client;
|
|
50
|
+
constructor(config: WarpClientConfig, chain: WarpChainInfo);
|
|
51
|
+
createInscriptionTransaction(abi: WarpAbiContents): Promise<WarpAdapterGenericTransaction>;
|
|
52
|
+
createFromRaw(encoded: string): Promise<any>;
|
|
53
|
+
createFromTransaction(tx: any): Promise<any>;
|
|
54
|
+
createFromTransactionHash(hash: string, cache?: WarpCacheConfig): Promise<any | null>;
|
|
55
|
+
getModuleAbi(packageId: string, moduleName: string): Promise<_mysten_sui_client.SuiMoveNormalizedModule>;
|
|
56
|
+
getFunctionAbi(packageId: string, moduleName: string, functionName: string): Promise<_mysten_sui_client.SuiMoveNormalizedFunction>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
declare class WarpSuiBrandBuilder implements AdapterWarpBrandBuilder {
|
|
60
|
+
private readonly config;
|
|
61
|
+
private readonly chain;
|
|
62
|
+
private readonly client;
|
|
63
|
+
constructor(config: WarpClientConfig, chain: WarpChainInfo);
|
|
64
|
+
createInscriptionTransaction(brand: WarpBrand): Transaction;
|
|
65
|
+
createFromRaw(encoded: string): Promise<WarpBrand>;
|
|
66
|
+
createFromTransaction(tx: any, validate?: boolean): Promise<WarpBrand>;
|
|
67
|
+
createFromTransactionHash(hash: string, cache?: WarpCacheConfig): Promise<WarpBrand | null>;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
declare class WarpSuiBuilder extends WarpBuilder implements AdapterWarpBuilder {
|
|
71
|
+
protected readonly config: WarpClientConfig;
|
|
72
|
+
private readonly chain;
|
|
73
|
+
private cache;
|
|
74
|
+
private client;
|
|
75
|
+
private userWallet;
|
|
76
|
+
constructor(config: WarpClientConfig, chain: WarpChainInfo);
|
|
77
|
+
createInscriptionTransaction(warp: Warp, registryObjectId?: string): Promise<WarpAdapterGenericTransaction>;
|
|
78
|
+
createFromNetwork(id: string, cache?: WarpCacheConfig): Promise<Warp | null>;
|
|
79
|
+
createFromTransaction(info: any): Promise<Warp>;
|
|
80
|
+
createFromTransactionHash(id: string, cache?: WarpCacheConfig): Promise<Warp | null>;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
declare class WarpSuiContractLoader {
|
|
84
|
+
private readonly abi;
|
|
85
|
+
constructor(config: WarpClientConfig, chain: WarpChainInfo);
|
|
86
|
+
loadModuleAbi(packageId: string, moduleName: string): Promise<_mysten_sui_dist_cjs_client.SuiMoveNormalizedModule>;
|
|
87
|
+
loadFunctionAbi(packageId: string, moduleName: string, functionName: string): Promise<_mysten_sui_dist_cjs_client.SuiMoveNormalizedFunction>;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
declare class WarpSuiDataLoader implements AdapterWarpDataLoader {
|
|
91
|
+
private readonly config;
|
|
92
|
+
private readonly chain;
|
|
93
|
+
client: SuiClient;
|
|
94
|
+
private cache;
|
|
95
|
+
constructor(config: WarpClientConfig, chain: WarpChainInfo);
|
|
96
|
+
getAccount(address: string): Promise<WarpChainAccount>;
|
|
97
|
+
getAccountAssets(address: string): Promise<WarpChainAsset[]>;
|
|
98
|
+
getAsset(identifier: string): Promise<WarpChainAsset | null>;
|
|
99
|
+
getAction(identifier: string, awaitCompleted?: boolean): Promise<WarpChainAction | null>;
|
|
100
|
+
getAccountActions(address: string, options?: WarpDataLoaderOptions): Promise<WarpChainAction[]>;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
declare class WarpSuiExecutor implements AdapterWarpExecutor {
|
|
104
|
+
private readonly config;
|
|
105
|
+
private readonly chain;
|
|
106
|
+
private readonly serializer;
|
|
107
|
+
private readonly output;
|
|
108
|
+
private readonly client;
|
|
109
|
+
private readonly userWallet;
|
|
110
|
+
constructor(config: WarpClientConfig, chain: WarpChainInfo);
|
|
111
|
+
createTransaction(executable: WarpExecutable): Promise<Transaction>;
|
|
112
|
+
createTransferTransaction(executable: WarpExecutable): Promise<Transaction>;
|
|
113
|
+
createContractCallTransaction(executable: WarpExecutable): Promise<Transaction>;
|
|
114
|
+
executeQuery(executable: WarpExecutable): Promise<WarpActionExecutionResult>;
|
|
115
|
+
signMessage(message: string, privateKey: string): Promise<string>;
|
|
116
|
+
private parseMoveCallTarget;
|
|
117
|
+
private buildPublicTransferArgs;
|
|
118
|
+
private extractObjectId;
|
|
119
|
+
private handleCoinTransfer;
|
|
120
|
+
private createCoinTransferFromObjects;
|
|
121
|
+
private getCoinObjectsForTransfer;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
declare class WarpSuiExplorer implements AdapterWarpExplorer {
|
|
125
|
+
private readonly config;
|
|
126
|
+
private readonly chain;
|
|
127
|
+
constructor(config: WarpClientConfig, chain: WarpChainInfo);
|
|
128
|
+
private getExplorers;
|
|
129
|
+
private getPrimaryExplorer;
|
|
130
|
+
private getExplorerUrlByName;
|
|
131
|
+
getAccountUrl(address: string, explorer?: ExplorerName): string;
|
|
132
|
+
getTransactionUrl(hash: string, explorer?: ExplorerName): string;
|
|
133
|
+
getBlockUrl(blockNumber: string | number, explorer?: ExplorerName): string;
|
|
134
|
+
getAssetUrl(identifier: string, explorer?: ExplorerName): string;
|
|
135
|
+
getContractUrl(address: string, explorer?: ExplorerName): string;
|
|
136
|
+
getAllExplorers(): readonly ExplorerName[];
|
|
137
|
+
getExplorerByName(name: string): ExplorerName | undefined;
|
|
138
|
+
getAccountUrls(address: string): Record<ExplorerName, string>;
|
|
139
|
+
getTransactionUrls(hash: string): Record<ExplorerName, string>;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
declare class WarpSuiRegistry implements AdapterWarpRegistry {
|
|
143
|
+
private config;
|
|
144
|
+
private readonly chain;
|
|
145
|
+
private client;
|
|
146
|
+
private cache;
|
|
147
|
+
private userWallet;
|
|
148
|
+
registryConfig: WarpRegistryConfigInfo;
|
|
149
|
+
constructor(config: WarpClientConfig, chain: WarpChainInfo);
|
|
150
|
+
init(): Promise<void>;
|
|
151
|
+
getRegistryConfig(): WarpRegistryConfigInfo;
|
|
152
|
+
private loadRegistryConfigs;
|
|
153
|
+
createWarpRegisterTransaction(txHash: string, alias?: string | null, brand?: string | null): Promise<Transaction>;
|
|
154
|
+
createWarpUnregisterTransaction(txHash: string): Promise<Transaction>;
|
|
155
|
+
createWarpUpgradeTransaction(alias: string, txHash: string): Promise<Transaction>;
|
|
156
|
+
createWarpAliasSetTransaction(txHash: string, alias: string): Promise<Transaction>;
|
|
157
|
+
createWarpVerifyTransaction(txHash: string): Promise<Transaction>;
|
|
158
|
+
createWarpTransferOwnershipTransaction(txHash: string, newOwner: string): Promise<Transaction>;
|
|
159
|
+
createBrandRegisterTransaction(brand: string): Promise<Transaction>;
|
|
160
|
+
createWarpBrandingTransaction(warpHash: string, brandHash: string): Promise<Transaction>;
|
|
161
|
+
getInfoByAlias(alias: string, cacheConfig?: WarpCacheConfig): Promise<{
|
|
162
|
+
registryInfo: WarpRegistryInfo | null;
|
|
163
|
+
brand: WarpBrand | null;
|
|
164
|
+
}>;
|
|
165
|
+
getInfoByHash(hash: string, cache?: WarpCacheConfig): Promise<{
|
|
166
|
+
registryInfo: WarpRegistryInfo | null;
|
|
167
|
+
brand: WarpBrand | null;
|
|
168
|
+
}>;
|
|
169
|
+
getUserWarpRegistryInfos(user?: string): Promise<WarpRegistryInfo[]>;
|
|
170
|
+
getUserBrands(user?: string): Promise<WarpBrand[]>;
|
|
171
|
+
fetchBrand(hash: string, cacheConfig?: WarpCacheConfig): Promise<WarpBrand | null>;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
declare class WarpSuiOutput implements AdapterWarpOutput {
|
|
175
|
+
private readonly config;
|
|
176
|
+
private readonly chain;
|
|
177
|
+
private readonly serializer;
|
|
178
|
+
private readonly client;
|
|
179
|
+
constructor(config: WarpClientConfig, chain: WarpChainInfo);
|
|
180
|
+
getActionExecution(warp: Warp, actionIndex: WarpActionIndex, tx: WarpAdapterGenericRemoteTransaction): Promise<WarpActionExecutionResult>;
|
|
181
|
+
extractContractOutput(warp: Warp, actionIndex: WarpActionIndex, tx: any, inputs: ResolvedInput[]): Promise<{
|
|
182
|
+
values: {
|
|
183
|
+
string: string[];
|
|
184
|
+
native: any[];
|
|
185
|
+
mapped: Record<string, any>;
|
|
186
|
+
};
|
|
187
|
+
output: WarpExecutionOutput;
|
|
188
|
+
}>;
|
|
189
|
+
extractQueryOutput(warp: Warp, typedValues: any[], actionIndex: number, inputs: ResolvedInput[]): Promise<{
|
|
190
|
+
values: {
|
|
191
|
+
string: string[];
|
|
192
|
+
native: any[];
|
|
193
|
+
mapped: Record<string, any>;
|
|
194
|
+
};
|
|
195
|
+
output: WarpExecutionOutput;
|
|
196
|
+
}>;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
declare class WarpSuiSerializer implements AdapterWarpSerializer {
|
|
200
|
+
readonly coreSerializer: WarpSerializer;
|
|
201
|
+
constructor();
|
|
202
|
+
typedToString(value: any): string;
|
|
203
|
+
typedToNative(value: any): [WarpActionInputType, WarpNativeValue];
|
|
204
|
+
nativeToTyped(type: WarpActionInputType, value: WarpNativeValue): any;
|
|
205
|
+
stringToTyped(value: string, tx?: Transaction): any;
|
|
206
|
+
typeToString(type: any): WarpActionInputType;
|
|
207
|
+
nativeToType(type: any): any;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
declare class WarpSuiWallet implements AdapterWarpWallet {
|
|
211
|
+
private config;
|
|
212
|
+
private chain;
|
|
213
|
+
private client;
|
|
214
|
+
private walletProvider;
|
|
215
|
+
private cachedAddress;
|
|
216
|
+
private cachedPublicKey;
|
|
217
|
+
private isInitializedPromise;
|
|
218
|
+
private isInitializedResolve;
|
|
219
|
+
constructor(config: WarpClientConfig, chain: WarpChainInfo);
|
|
220
|
+
waitUntilInitialized(): Promise<void>;
|
|
221
|
+
signTransaction(tx: WarpAdapterGenericTransaction): Promise<WarpAdapterGenericTransaction>;
|
|
222
|
+
signMessage(message: string): Promise<string>;
|
|
223
|
+
signTransactions(txs: WarpAdapterGenericTransaction[]): Promise<WarpAdapterGenericTransaction[]>;
|
|
224
|
+
sendTransaction(tx: WarpAdapterGenericTransaction): Promise<string>;
|
|
225
|
+
sendTransactions(txs: WarpAdapterGenericTransaction[]): Promise<string[]>;
|
|
226
|
+
importFromMnemonic(mnemonic: string): Promise<WarpWalletDetails>;
|
|
227
|
+
importFromPrivateKey(privateKey: string): Promise<WarpWalletDetails>;
|
|
228
|
+
export(provider: WarpWalletProvider): Promise<WarpWalletDetails>;
|
|
229
|
+
generate(provider: WarpWalletProvider): Promise<WarpWalletDetails>;
|
|
230
|
+
getAddress(): string | null;
|
|
231
|
+
getPublicKey(): string | null;
|
|
232
|
+
private createProvider;
|
|
233
|
+
private initializeCache;
|
|
234
|
+
private createProviderForOperation;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export { type ExplorerName, ExplorerUrls, KnownTokens, NativeTokenSui, SuiAdapter, SuiExplorers, SuiExplorersConfig, WarpSuiAbiBuilder, WarpSuiBrandBuilder, WarpSuiBuilder, WarpSuiConstants, WarpSuiContractLoader, WarpSuiDataLoader, WarpSuiExecutor, WarpSuiExplorer, WarpSuiOutput, WarpSuiRegistry, WarpSuiSerializer, WarpSuiWallet, findKnownTokenById, getConfiguredSuiClient, getSuiRegistryObjectId, getSuiRegistryPackageId, toRegistryMoveTarget, toTypedRegistryInfo };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var wr=Object.create;var V=Object.defineProperty;var Cr=Object.getOwnPropertyDescriptor;var br=Object.getOwnPropertyNames;var Ar=Object.getPrototypeOf,Sr=Object.prototype.hasOwnProperty;var Er=(o,r)=>{for(var e in r)V(o,e,{get:r[e],enumerable:!0})},X=(o,r,e,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of br(r))!Sr.call(o,n)&&n!==e&&V(o,n,{get:()=>r[n],enumerable:!(t=Cr(r,n))||t.enumerable});return o};var Pr=(o,r,e)=>(e=o!=null?wr(Ar(o)):{},X(r||!o||!o.__esModule?V(e,"default",{value:o,enumerable:!0}):e,o)),Ir=o=>X(V({},"__esModule",{value:!0}),o);var kr={};Er(kr,{ExplorerUrls:()=>C,KnownTokens:()=>lr,NativeTokenSui:()=>H,SuiAdapter:()=>Rr,SuiExplorers:()=>Y,SuiExplorersConfig:()=>G,WarpSuiAbiBuilder:()=>S,WarpSuiBrandBuilder:()=>K,WarpSuiBuilder:()=>N,WarpSuiConstants:()=>xr,WarpSuiContractLoader:()=>q,WarpSuiDataLoader:()=>D,WarpSuiExecutor:()=>$,WarpSuiExplorer:()=>O,WarpSuiOutput:()=>E,WarpSuiRegistry:()=>j,WarpSuiSerializer:()=>w,WarpSuiWallet:()=>_,findKnownTokenById:()=>L,getConfiguredSuiClient:()=>Q,getSuiRegistryObjectId:()=>Tr,getSuiRegistryPackageId:()=>R,toRegistryMoveTarget:()=>p,toTypedRegistryInfo:()=>k});module.exports=Ir(kr);var R=o=>{if(o==="devnet")throw new Error("Sui registry package id is not available for devnet");if(o==="testnet")return"0xc8824c98b09d36eec6c8b69ae7083e0b012b5e516e2f7a54c75bfa8a80105753";throw new Error("Sui registry package id is not available for mainnet")},Tr=o=>{if(o==="devnet")throw new Error("Sui registry object id is not available for devnet");if(o==="testnet")return"";throw new Error("Sui registry object id is not available for mainnet")};var xr={Sui:{Identifier:"SUI",DisplayName:"Sui",Decimals:9}},Y=(s=>(s.SuiVision="suivision",s.SuiVisionTestnet="suivision_testnet",s.SuiVisionDevnet="suivision_devnet",s.SuiScan="suiscan",s.SuiScanTestnet="suiscan_testnet",s.SuiScanDevnet="suiscan_devnet",s))(Y||{}),G={sui:{mainnet:["suivision","suiscan"],testnet:["suivision_testnet","suiscan_testnet"],devnet:["suivision_devnet","suiscan_devnet"]}},C={suivision:"https://suivision.xyz",suivision_testnet:"https://testnet.suivision.xyz",suivision_devnet:"https://devnet.suivision.xyz",suiscan:"https://suiscan.xyz",suiscan_testnet:"https://testnet.suiscan.xyz",suiscan_devnet:"https://devnet.suiscan.xyz"};var Z=require("@mysten/sui/client"),rr=require("@joai/warps"),Q=(o,r)=>{let e=(0,rr.getProviderConfig)(o,r.name,o.env,r.defaultApiUrl);return new Z.SuiClient({url:e.url})};var p=(o,r)=>`${R(o)}::${r}`,Br=o=>{let r=Buffer.from(o).toString();return r==="unverified"||r==="verified"||r==="blacklisted"?r:"unverified"},k=o=>({hash:Buffer.from(o.hash).toString("hex"),alias:o.alias?Buffer.from(o.alias).toString():null,trust:Br(o.trust),owner:o.owner,createdAt:Number(o.created_at),upgradedAt:Number(o.upgraded_at),brand:o.brand?Buffer.from(o.brand).toString("hex"):null,upgrade:o.upgrade?Buffer.from(o.upgrade).toString("hex"):null});var U=require("@joai/warps");var er=require("@mysten/sui/client"),tr=require("@joai/warps"),S=class{constructor(r,e){this.config=r;this.chain=e;let t=(0,tr.getProviderConfig)(this.config,this.chain.name,this.config.env,this.chain.defaultApiUrl);this.client=new er.SuiClient({url:t.url})}async createInscriptionTransaction(r){throw new Error("WarpSuiAbiBuilder: createInscriptionTransaction not implemented")}async createFromRaw(r){return JSON.parse(r)}async createFromTransaction(r){return this.createFromRaw(r.data||"{}")}async createFromTransactionHash(r,e){try{let t=await this.client.getTransactionBlock({digest:r});return t?this.createFromTransaction(t):null}catch{return null}}async getModuleAbi(r,e){return this.client.getNormalizedMoveModule({package:r,module:e})}async getFunctionAbi(r,e,t){return this.client.getNormalizedMoveFunction({package:r,module:e,function:t})}};var nr=require("@mysten/sui/client"),ir=require("@mysten/sui/transactions"),ar=require("@joai/warps"),K=class{constructor(r,e){this.config=r;this.chain=e;let t=(0,ar.getProviderConfig)(this.config,this.chain.name,this.config.env,this.chain.defaultApiUrl);this.client=new nr.SuiClient({url:t.url})}createInscriptionTransaction(r){return new ir.Transaction}async createFromRaw(r){return JSON.parse(r)}async createFromTransaction(r,e){return this.createFromRaw(r.data||"{}")}async createFromTransactionHash(r,e){try{let t=await this.client.getTransactionBlock({digest:r});return t?this.createFromTransaction(t,!1):null}catch{return null}}};var sr=require("@mysten/sui/client"),or=require("@mysten/sui/transactions"),b=require("@joai/warps");var N=class extends b.WarpBuilder{constructor(e,t){super(e);this.config=e;this.chain=t;this.cache=new b.WarpCache(e.env,e.cache);let n=(0,b.getProviderConfig)(this.config,this.chain.name,this.config.env,this.chain.defaultApiUrl);this.client=new sr.SuiClient({url:n.url}),this.userWallet=(0,b.getWarpWalletAddressFromConfig)(this.config,this.chain.name)}async createInscriptionTransaction(e,t){if(!t)throw new Error("WarpSuiBuilder: registryObjectId is required");if(!this.userWallet)throw new Error("WarpSuiBuilder: user address not set");if(!e.meta||!e.meta.hash)throw new Error("WarpSuiBuilder: warp.meta.hash is required");let n=Array.from(Buffer.from(e.meta.hash,"hex")),i=e.meta?.alias??void 0,s=e.meta?.brand?Array.from(Buffer.from(e.meta.brand,"hex")):void 0,a=new or.Transaction;return a.moveCall({target:p(this.config.env,"register_warp"),arguments:[a.object(t),a.pure.vector("u8",n),i?a.pure.option("string",i):a.pure.option("string",void 0),s?a.pure.option("vector<u8>",s):a.pure.option("vector<u8>",void 0),a.gas,a.pure.address(this.userWallet)]}),a}async createFromNetwork(e,t){let n=`sui:warp:${e}`;if(t){let i=this.cache.get(n);if(i)return i}try{let i=await this.client.call(`${p(this.config.env,"get_info_by_hash")}`,[e,Array.from(Buffer.from(e,"hex"))]);if(!i||!Object.prototype.hasOwnProperty.call(i,"hash")||!i.hash)return null;let s=this.createFromRaw(i);return t&&t.ttl&&s&&this.cache.set(n,s,t.ttl),s}catch{return null}}async createFromTransaction(e){return this.createFromRaw(e)}async createFromTransactionHash(e,t){return this.createFromNetwork(e,t)}};var pr=require("@mysten/sui/client"),A=require("@joai/warps");var cr=require("@joai/warps"),v=cr.WarpChainName.Sui,lr=[{chain:v,identifier:"0x2::sui::SUI",name:"Sui",symbol:"SUI",decimals:9,logoUrl:"https://assets.coingecko.com/coins/images/26375/small/sui-logo.png"},{chain:v,identifier:"0xa198f3be41cda8c07c3bf1c4e0bb88b8e9827b7c063f36b1e6c3d6da1c4e8753::usdc::USDC",name:"USD Coin",symbol:"USDC",decimals:6,logoUrl:"https://assets.coingecko.com/coins/images/6319/small/USD_Coin_icon.png"},{chain:v,identifier:"0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48ace0cdd97::usdt::USDT",name:"Tether USD",symbol:"USDT",decimals:6,logoUrl:"https://assets.coingecko.com/coins/images/325/small/Tether.png"},{chain:v,identifier:"0xaf8cd5edc19c4512f4259f0bee101a7c94d8a5c0e7c90c7a7c8c8c8c8c8c8c8c8::wbtc::WBTC",name:"Wrapped Bitcoin",symbol:"WBTC",decimals:8,logoUrl:"https://assets.coingecko.com/coins/images/7598/small/wrapped_bitcoin_wbtc.png"},{chain:v,identifier:"0xb8a6a9b7c7a6f4a3e2d1c0b9a8f7e6d5c4b3a2b1c0d9e8f7a6b5c4d3e2f1a0b::weth::WETH",name:"Wrapped Ether",symbol:"WETH",decimals:8,logoUrl:"https://assets.coingecko.com/coins/images/2518/small/weth.png"},{chain:v,identifier:"0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a15e0e9::ocean::OCEAN",name:"Ocean Protocol",symbol:"OCEAN",decimals:9,logoUrl:"https://assets.coingecko.com/coins/images/3687/small/ocean-protocol-logo.png"},{chain:v,identifier:"0x5d1f47ea69bb0de31c313d7acf89b890dbb8991ea8e03c6c35569693fd50fb8b7::deep::DEEP",name:"DeepBook",symbol:"DEEP",decimals:6,logoUrl:"https://assets.coingecko.com/coins/images/30169/small/deepbook.png"},{chain:v,identifier:"0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47ba3::hasui::HASUI",name:"Haedal Staked SUI",symbol:"HASUI",decimals:9,logoUrl:"https://assets.coingecko.com/coins/images/30027/small/haSUI.png"},{chain:v,identifier:"0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e935::usdc::USDC",name:"USD Coin (Wormhole)",symbol:"USDC",decimals:6,logoUrl:"https://assets.coingecko.com/coins/images/6319/small/USD_Coin_icon.png"}],L=o=>lr.find(r=>r.identifier===o)||null;var D=class{constructor(r,e){this.config=r;this.chain=e;let t=(0,A.getProviderConfig)(this.config,this.chain.name,this.config.env,this.chain.defaultApiUrl);this.client=new pr.SuiClient({url:t.url}),this.cache=new A.WarpCache(r.env,r.cache)}async getAccount(r){let e=await this.client.getBalance({owner:r,coinType:"0x2::sui::SUI"});return{chain:this.chain.name,address:r,balance:BigInt(e.totalBalance)}}async getAccountAssets(r){let e=await this.client.getAllBalances({owner:r});console.log("WarpSuiDataLoader.getAccountAssets",e);let t=e.find(s=>s.coinType==="0x2::sui::SUI"),n=e.filter(s=>s.coinType!=="0x2::sui::SUI"&&BigInt(s.totalBalance)>0n),i=[];if(t&&BigInt(t.totalBalance)>0n&&i.push({...this.chain.nativeToken,amount:BigInt(t.totalBalance)}),n.length>0){let s=await Promise.all(n.map(a=>this.getAsset(a.coinType)));i.push(...s.filter(a=>a!==null).map(a=>({...a,amount:BigInt(n.find(c=>c.coinType===a.identifier)?.totalBalance||0)})))}return i}async getAsset(r){let e=A.WarpCacheKey.Asset(this.config.env,this.chain.name,r),t=this.cache.get(e);if(t)return t;let n=L(r);if(n)return{chain:this.chain.name,identifier:r,name:n.name,symbol:n.symbol,amount:0n,decimals:n.decimals,logoUrl:n.logoUrl};try{let i=await this.client.getCoinMetadata({coinType:r}),s={chain:this.chain.name,identifier:r,name:i?.name||r.split("::").pop()||r,symbol:i?.symbol||r.split("::").pop()||r,amount:0n,decimals:i?.decimals||9,logoUrl:i?.iconUrl||""};return this.cache.set(e,s,A.CacheTtl.OneHour),s}catch{return null}}async getAction(r,e=!1){return null}async getAccountActions(r,e){return[]}};var fr=require("@mysten/sui/client"),J=require("@mysten/sui/transactions"),f=require("@joai/warps");var dr=require("@mysten/sui/client"),u=require("@joai/warps");var ur=require("@mysten/sui/transactions"),gr=require("@joai/warps"),w=class{constructor(){this.coreSerializer=new gr.WarpSerializer}typedToString(r){if(r==null)return"option:null";if(typeof r=="string")return`string:${r}`;if(typeof r=="boolean")return`bool:${r}`;if(typeof r=="number")return`uint64:${r.toString()}`;if(typeof r=="bigint")return`uint64:${r.toString()}`;if(r&&typeof r=="object"&&r.address)return`address:${r.address}`;if(Array.isArray(r)){if(r.length===0)return"vector:u8:";let e=this.typeToString(typeof r[0]),t=r.map(n=>this.typedToString(n).split(":")[1]);return`vector:${e}:${t.join(",")}`}if(r&&typeof r=="object"&&r.type&&r.value&&r.type==="option")return r.value===null||r.value===void 0?"option:null":`option:${this.typedToString(r.value)}`;throw new Error(`WarpSuiSerializer (typedToString): Unsupported input type: ${typeof r}`)}typedToNative(r){let e=this.typedToString(r);return this.coreSerializer.stringToNative(e)}nativeToTyped(r,e){let t=this.coreSerializer.nativeToString(r,e);return this.stringToTyped(t)}stringToTyped(r,e){let t=e||new ur.Transaction,[n,i]=r.split(/:(.*)/,2);if(n==="object")return t.object(i);if(n==="string")return t.pure.string(i);if(n==="bool")return t.pure.bool(i==="true");if(n==="u8")return t.pure.u8(Number(i));if(n==="u16")return t.pure.u16(Number(i));if(n==="u32")return t.pure.u32(Number(i));if(n==="u64"||n==="uint64")return t.pure.u64(BigInt(i));if(n==="u128")return t.pure.u128(BigInt(i));if(n==="u256")return t.pure.u256(BigInt(i));if(n==="address")return t.pure.address(i);throw new Error(`WarpSuiSerializer (stringToTyped): Unsupported type: ${n}`)}typeToString(r){if(r==="string")return"string";if(r==="bool")return"bool";if(r==="u8")return"u8";if(r==="u16")return"u16";if(r==="u32")return"u32";if(r==="u64"||r==="bigint"||r==="number")return"u64";if(r==="u128")return"u128";if(r==="u256")return"u256";if(r==="address")return"address";if(r==="vector")return"vector";if(r==="option")return"option";throw new Error(`WarpSuiSerializer (typeToString): Unsupported input type: ${r}`)}nativeToType(r){throw new Error("Not implemented")}};var E=class{constructor(r,e){this.config=r;this.chain=e;this.serializer=new w;let t=(0,u.getProviderConfig)(this.config,this.chain.name,this.config.env,this.chain.defaultApiUrl);this.client=new dr.SuiClient({url:t.url})}async getActionExecution(r,e,t){let n=await this.extractContractOutput(r,e,t,[]),i=(0,u.getNextInfo)(this.config,[],r,e,n.output),s=(0,u.applyOutputToMessages)(r,n.output,this.config);return{status:t.effects?.status?.status==="success"?"success":"error",warp:r,action:e,user:(0,u.getWarpWalletAddressFromConfig)(this.config,this.chain.name),txHash:t.digest,tx:t,next:i,values:n.values,output:n.output,messages:s,destination:null,resolvedInputs:[]}}async extractContractOutput(r,e,t,n){let i=[],s=[],a={};if(!r.output)return{values:{string:i,native:s,mapped:{}},output:a};for(let[c,d]of Object.entries(r.output)){if(d.startsWith(u.WarpConstants.Transform.Prefix))continue;if(d.startsWith("input.")){a[c]=d;continue}let h=(0,u.parseOutputOutIndex)(d);if(h!==null&&h!==e){a[c]=null;continue}if(d.startsWith("out.")){let W=t.returnValues?t.returnValues[c]:null;a[c]=W,i.push(String(W)),s.push(W)}else a[c]=d}return{values:{string:i,native:s,mapped:{}},output:await(0,u.evaluateOutputCommon)(r,a,e,n,this.serializer.coreSerializer,this.config)}}async extractQueryOutput(r,e,t,n){let a={string:e.map(d=>String(d)),native:e,mapped:{}},c={};if(!r.output)return{values:a,output:c};for(let[d,h]of Object.entries(r.output)){if(h.startsWith(u.WarpConstants.Transform.Prefix))continue;let W=(0,u.parseOutputOutIndex)(h);if(W!==null&&W!==t){c[d]=null;continue}if(h.startsWith("out.")||h==="out")if(Array.isArray(e)&&e.length>0&&typeof e[0]=="object"&&e[0]!==null){let vr=h.replace(/^out\./,"");c[d]=e[0][vr]}else c[d]=e[0];else c[d]=h}return{values:a,output:await(0,u.evaluateOutputCommon)(r,c,t,n,this.serializer.coreSerializer,this.config)}}};var $=class{constructor(r,e){this.config=r;this.chain=e;this.serializer=new w,this.output=new E(this.config,this.chain);let t=(0,f.getProviderConfig)(this.config,this.chain.name,this.config.env,this.chain.defaultApiUrl);this.client=new fr.SuiClient({url:t.url}),this.userWallet=(0,f.getWarpWalletAddressFromConfig)(this.config,this.chain.name)}async createTransaction(r){let e=(0,f.getWarpActionByIndex)(r.warp,r.action);if(e.type==="transfer")return this.createTransferTransaction(r);if(e.type==="contract")return this.createContractCallTransaction(r);throw e.type==="query"?new Error("WarpSuiExecutor: Invalid action type for createTransaction; Use executeQuery instead"):e.type==="collect"?new Error("WarpSuiExecutor: Invalid action type for createTransaction; Use executeCollect instead"):new Error(`WarpSuiExecutor: Invalid action type (${e.type})`)}async createTransferTransaction(r){if(!this.userWallet)throw new Error("WarpSuiExecutor: createTransfer - user address not set");if(!r.destination)throw new Error("WarpSuiExecutor: Invalid destination address");if(r.value<0)throw new Error(`WarpSuiExecutor: Transfer value cannot be negative: ${r.value}`);let e=new J.Transaction,t=[];if(r.value>0){let n=await this.handleCoinTransfer(e,"0x2::sui::SUI",r.value);t.push(n)}for(let n of r.transfers){let i=await this.handleCoinTransfer(e,n.identifier,n.amount);t.push(i)}return t.length>0&&e.transferObjects(t,e.pure.address(r.destination)),e}async createContractCallTransaction(r){if(!this.userWallet)throw new Error("WarpSuiExecutor: createContractCall - user address not set");if(!r.destination)throw new Error("WarpSuiExecutor: Invalid contract address");if(r.value<0)throw new Error(`WarpSuiExecutor: Contract call value cannot be negative: ${r.value}`);let e=(0,f.getWarpActionByIndex)(r.warp,r.action);if(!e.func)throw new Error("WarpSuiExecutor: createContractCall - function not set");let t=new J.Transaction;t.setSender(this.userWallet);let n=[];r.value>0&&n.push(await this.handleCoinTransfer(t,"0x2::sui::SUI",r.value));for(let c of r.transfers)n.push(await this.handleCoinTransfer(t,c.identifier,c.amount));let{target:i,typeArguments:s}=this.parseMoveCallTarget(e),a=r.args.map(c=>this.serializer.stringToTyped(c,t));return i==="0x2::transfer::public_transfer"?n.push(...await this.buildPublicTransferArgs(t,r,a)):n.push(...a),t.moveCall({target:i,arguments:n,typeArguments:s}),t.setGasBudget(1e8),t}async executeQuery(r){if(!r.destination)throw new Error("WarpSuiExecutor: executeQuery - destination not set");let e=(0,f.getWarpActionByIndex)(r.warp,r.action);if(e.type!=="query")throw new Error(`WarpSuiExecutor: Invalid action type for executeQuery: ${e.type}`);let t=await this.client.getObject({id:r.destination,options:{showContent:!0}}),n=[t],{values:i,output:s}=await this.output.extractQueryOutput(r.warp,n,r.action,r.resolvedInputs),a=(0,f.getNextInfo)(this.config,[],r.warp,r.action,s),d=r.resolvedInputs.find(W=>W.input.position==="receiver"||W.input.position==="destination")?.value||r.destination,h=(0,f.extractResolvedInputValues)(r.resolvedInputs);return{status:"success",warp:r.warp,action:r.action,user:this.userWallet,txHash:null,tx:null,next:a,values:i,output:{...s,_DATA:t},resolvedInputs:h,messages:(0,f.applyOutputToMessages)(r.warp,s,this.config),destination:d}}async signMessage(r,e){throw new Error("Not implemented")}parseMoveCallTarget(r){if(!r.func)throw new Error("WarpSuiExecutor: Function not set");let e=`${r.address}::${r.func}`,t=r.typeArguments;if(!t&&r.func.includes("<")&&r.func.includes(">")){let n=r.func.match(/<([^>]+)>/);n&&(t=[n[1]],e=`${r.address}::${r.func.replace(/<[^>]+>/,"")}`)}return{target:e,typeArguments:t}}async buildPublicTransferArgs(r,e,t){let n=e.resolvedInputs.find(a=>String(a.input.position)==="arg:0")?.value||e.args[0],i=e.resolvedInputs.find(a=>String(a.input.position)==="arg:1")?.value||e.resolvedInputs.find(a=>a.input.type==="address"&&String(a.input.position)!=="arg:0")?.value||e.args[1],s=this.extractObjectId(n);if(!s)return t;try{if(!(await this.client.getObject({id:s,options:{showType:!0,showContent:!0}})).data?.type?.startsWith("0x2::coin::Coin<"))return t;let c=i?this.serializer.stringToTyped(i.includes(":")?i:`address:${i}`,r):t[1]||r.pure.address(this.userWallet);return[r.object(s),c]}catch{return t}}extractObjectId(r){if(!r||typeof r!="string")return null;let e=r.startsWith("object:")?r.substring(7):r;return e.startsWith("0x")?e:null}async handleCoinTransfer(r,e,t){if(e==="0x2::sui::SUI")try{return r.splitCoins(r.gas,[t.toString()])[0]}catch{}return this.createCoinTransferFromObjects(r,e,t)}async createCoinTransferFromObjects(r,e,t){let n=await this.getCoinObjectsForTransfer(e,t);if(n.length===0)throw new Error(`No coin objects found for ${e}`);let i=r.object(n[0].coinObjectId);return n.length>1&&r.mergeCoins(i,n.slice(1).map(s=>r.object(s.coinObjectId))),r.splitCoins(i,[t.toString()])[0]}async getCoinObjectsForTransfer(r,e){if(!this.userWallet)throw new Error("User wallet not set");let{data:t}=await this.client.getCoins({owner:this.userWallet,coinType:r}),n=t.map(a=>({coinObjectId:a.coinObjectId,balance:a.balance})).sort((a,c)=>BigInt(c.balance)>BigInt(a.balance)?1:-1),i=BigInt(0),s=[];for(let a of n)if(s.push(a),i+=BigInt(a.balance),i>=e)return s;throw new Error(`Insufficient ${r} balance. Required: ${e}, Available: ${i}`)}};var O=class{constructor(r,e){this.config=r;this.chain=e}getExplorers(){let r=G[this.chain.name];if(!r)return["suivision"];let e=r[this.config.env];return e||["suivision"]}getPrimaryExplorer(){return this.getExplorers()[0]}getExplorerUrlByName(r){let e=this.config.preferences?.explorers?.[this.chain.name];if(e&&!r){let i=C[e];if(i)return i}if(r){let i=C[r];if(i)return i}let t=this.getPrimaryExplorer();return C[t]||C[t]}getAccountUrl(r,e){return`${this.getExplorerUrlByName(e)}/account/${r}`}getTransactionUrl(r,e){return`${this.getExplorerUrlByName(e)}/txblock/${r}`}getBlockUrl(r,e){return`${this.getExplorerUrlByName(e)}/block/${r}`}getAssetUrl(r,e){return`${this.getExplorerUrlByName(e)}/coin/${r}`}getContractUrl(r,e){return`${this.getExplorerUrlByName(e)}/object/${r}`}getAllExplorers(){return this.getExplorers()}getExplorerByName(r){return this.getExplorers().find(t=>t.toLowerCase()===r.toLowerCase())}getAccountUrls(r){let e=this.getAllExplorers(),t={};return e.forEach(n=>{let i=C[n];i&&(t[n]=`${i}/account/${r}`)}),t}getTransactionUrls(r){let e=this.getAllExplorers(),t={};return e.forEach(n=>{let i=C[n];i&&(t[n]=`${i}/txblock/${r}`)}),t}};var hr=require("@mysten/sui/client"),m=require("@mysten/sui/transactions"),l=require("@joai/warps");var j=class{constructor(r,e){this.config=r;this.chain=e;this.registryConfig={unitPrice:BigInt(0),admins:[]};let t=(0,l.getProviderConfig)(this.config,this.chain.name,this.config.env,this.chain.defaultApiUrl);this.client=new hr.SuiClient({url:t.url}),this.cache=new l.WarpCache(r.env,r.cache),this.userWallet=(0,l.getWarpWalletAddressFromConfig)(this.config,this.chain.name)}async init(){await this.loadRegistryConfigs()}getRegistryConfig(){return this.registryConfig}async loadRegistryConfigs(){try{let r=`${R(this.config.env)}::registry::get_config`;console.log("-- Loading registry configs",r);let e=new m.Transaction;e.moveCall({target:r,arguments:[]});let t=await this.client.devInspectTransactionBlock({transactionBlock:e,sender:"0x0000000000000000000000000000000000000000000000000000000000000000"});console.log("-- Registry configs loaded",t);let n=t.results?.[0]?.returnValues?.[0],i=n&&Array.isArray(n)&&n[0]?JSON.parse(String.fromCharCode(...n[0])):{};this.registryConfig={unitPrice:i.unit_price!==void 0?BigInt(i.unit_price):BigInt(0),admins:Array.isArray(i.admins)?i.admins:[]}}catch(r){l.WarpLogger.error("WarpSuiRegistry: Failed to load registry config",r),this.registryConfig={unitPrice:BigInt(0),admins:[]}}}async createWarpRegisterTransaction(r,e,t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let n=new m.Transaction;return n.moveCall({target:p(this.config.env,"register_warp"),arguments:[n.pure.vector("u8",Array.from(Buffer.from(r,"hex"))),e?n.pure.option("string",e):n.pure.option("string",void 0),t?n.pure.option("vector<u8>",Array.from(Buffer.from(t,"hex"))):n.pure.option("vector<u8>",void 0),n.gas,n.pure.address(this.userWallet)]}),n}async createWarpUnregisterTransaction(r){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let e=new m.Transaction;return e.moveCall({target:p(this.config.env,"unregister_warp"),arguments:[e.pure.vector("u8",Array.from(Buffer.from(r,"hex"))),e.gas,e.pure.address(this.userWallet)]}),e}async createWarpUpgradeTransaction(r,e){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let t=new m.Transaction;return t.moveCall({target:p(this.config.env,"upgrade_warp"),arguments:[t.pure.string(r),t.pure.vector("u8",Array.from(Buffer.from(e,"hex"))),t.gas,t.pure.address(this.userWallet)]}),t}async createWarpAliasSetTransaction(r,e){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let t=new m.Transaction;return t.moveCall({target:p(this.config.env,"set_warp_alias"),arguments:[t.pure.vector("u8",Array.from(Buffer.from(r,"hex"))),t.pure.string(e),t.gas,t.pure.address(this.userWallet)]}),t}async createWarpVerifyTransaction(r){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let e=new m.Transaction;return e.moveCall({target:p(this.config.env,"verify_warp"),arguments:[e.pure.vector("u8",Array.from(Buffer.from(r,"hex"))),e.gas,e.pure.address(this.userWallet)]}),e}async createWarpTransferOwnershipTransaction(r,e){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let t=new m.Transaction;return t.moveCall({target:p(this.config.env,"transfer_ownership"),arguments:[t.pure.vector("u8",Array.from(Buffer.from(r,"hex"))),t.pure.address(e),t.gas,t.pure.address(this.userWallet)]}),t}async createBrandRegisterTransaction(r){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let e=new m.Transaction;return e.moveCall({target:p(this.config.env,"register_brand"),arguments:[e.pure.vector("u8",Array.from(Buffer.from(r,"hex"))),e.gas,e.pure.address(this.userWallet)]}),e}async createWarpBrandingTransaction(r,e){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let t=new m.Transaction;return t.moveCall({target:p(this.config.env,"brand_warp"),arguments:[t.pure.vector("u8",Array.from(Buffer.from(r,"hex"))),t.pure.vector("u8",Array.from(Buffer.from(e,"hex"))),t.gas,t.pure.address(this.userWallet)]}),t}async getInfoByAlias(r,e){let t=l.WarpCacheKey.RegistryInfo(this.config.env,r),n=e?this.cache.get(t):null;if(n)return l.WarpLogger.info(`WarpSuiRegistry (getInfoByAlias): RegistryInfo found in cache: ${r}`),n;try{let i=await this.client.call(p(this.config.env,"get_info_by_alias"),[r]),s=i||null,a=s?k(s):null,c=a?.brand?await this.fetchBrand(a.brand,e):null;return e&&e.ttl&&this.cache.set(t,{registryInfo:a,brand:c},e.ttl),{registryInfo:a,brand:c}}catch(i){return l.WarpLogger.error("WarpSuiRegistry (getInfoByAlias):",i),{registryInfo:null,brand:null}}}async getInfoByHash(r,e){let t=l.WarpCacheKey.RegistryInfo(this.config.env,r),n=e?this.cache.get(t):null;if(n)return l.WarpLogger.info(`WarpSuiRegistry (getInfoByHash): RegistryInfo found in cache: ${r}`),n;try{let i=await this.client.call(p(this.config.env,"get_info_by_hash"),[Array.from(Buffer.from(r,"hex"))]),s=i||null,a=s?k(s):null,c=a?.brand?await this.fetchBrand(a.brand,e):null;return e&&e.ttl&&this.cache.set(t,{registryInfo:a,brand:c},e.ttl),{registryInfo:a,brand:c}}catch(i){return l.WarpLogger.error("WarpSuiRegistry (getInfoByHash):",i),{registryInfo:null,brand:null}}}async getUserWarpRegistryInfos(r){let e=`sui:registry:user:${r||this.userWallet}`,t=this.cache.get(e);if(t)return l.WarpLogger.info(`WarpSuiRegistry (getUserWarpRegistryInfos): RegistryInfos found in cache for user: ${r||this.userWallet}`),t;try{let n=r||this.userWallet;if(!n)throw new Error("WarpRegistry: user address not set");let i=await this.client.call(p(this.config.env,"get_user_warps"),[n]),s=Array.isArray(i)?i.map(k):[];return r&&this.cache.set(e,s,300),s}catch(n){return l.WarpLogger.error("WarpSuiRegistry (getUserWarpRegistryInfos):",n),[]}}async getUserBrands(r){let e=`sui:registry:user:brands:${r||this.userWallet}`,t=this.cache.get(e);if(t)return l.WarpLogger.info(`WarpSuiRegistry (getUserBrands): Brands found in cache for user: ${r||this.userWallet}`),t;try{let n=r||this.userWallet;if(!n)throw new Error("WarpRegistry: user address not set");let i=await this.client.call(p(this.config.env,"get_user_brands"),[n]);if(!Array.isArray(i))return[];let a=(await Promise.all(i.map(c=>this.fetchBrand(c)))).filter(c=>c!==null);return r&&this.cache.set(e,a,300),a}catch(n){return l.WarpLogger.error("WarpSuiRegistry (getUserBrands):",n),[]}}async fetchBrand(r,e){let t=l.WarpCacheKey.Brand(this.config.env,r),n=e?this.cache.get(t):null;if(n)return l.WarpLogger.info(`WarpSuiRegistry (fetchBrand): Brand found in cache: ${r}`),n;try{let i=await this.client.getTransactionBlock({digest:r});if(!i||!i.effects)return null;let s=null;if(i.events&&Array.isArray(i.events)){for(let a of i.events)if(a.type&&typeof a.type=="string"&&a.type.includes("BrandRegistered"))try{s=a.parsedJson;break}catch{}}if(!s&&i.objectChanges&&Array.isArray(i.objectChanges)){for(let a of i.objectChanges)if(a.type==="created"&&a.objectType&&a.objectType.includes("Brand"))try{break}catch{}}return s?(s.meta={hash:r,creator:i.transaction&&i.transaction.data&&i.transaction.data.sender?i.transaction.data.sender:void 0,createdAt:i.timestampMs?new Date(Number(i.timestampMs)).toISOString():void 0},e&&e.ttl&&this.cache.set(t,s,e.ttl),s):null}catch(i){return l.WarpLogger.error("WarpSuiRegistry (fetchBrand):",i),null}}};var Wr=require("@joai/warps");var F=require("@mysten/sui/keypairs/ed25519"),mr=Pr(require("@scure/bip39"),1),yr=require("@scure/bip39/wordlists/english.js"),g=require("@joai/warps"),P=class P{constructor(r,e){this.config=r;this.chain=e;this.keypair=null}async getAddress(){return(0,g.getWarpWalletAddressFromConfig)(this.config,this.chain.name)}async getPublicKey(){try{let e=this.getKeypair().getPublicKey();return Buffer.from(e.toRawBytes()).toString("hex")}catch{return null}}async signTransaction(r){if(r&&typeof r=="object"&&"sign"in r&&typeof r.sign=="function")return r;let e=this.getKeypair(),t=new TextEncoder().encode(JSON.stringify(r)),n=await e.signPersonalMessage(t);return{...r,signature:n.signature}}async signMessage(r){let e=this.getKeypair(),t=new TextEncoder().encode(r);return(await e.signPersonalMessage(t)).signature}getKeypairInstance(){return this.getKeypair()}async importFromMnemonic(r){let e=(0,g.normalizeAndValidateMnemonic)(r),n=F.Ed25519Keypair.deriveKeypair(e).getPublicKey().toSuiAddress(),i={provider:P.PROVIDER_NAME,address:n,privateKey:null,mnemonic:e};return(0,g.setWarpWalletInConfig)(this.config,this.chain.name,i),i}async importFromPrivateKey(r){let e=Buffer.from(r,"hex"),t;if(e.length===70)t=new Uint8Array(e.subarray(1,33));else if(e.length===32)t=new Uint8Array(e);else throw new Error(`Unsupported private key length: ${e.length} bytes`);let i=F.Ed25519Keypair.fromSecretKey(t).getPublicKey().toSuiAddress(),s={provider:P.PROVIDER_NAME,address:i,privateKey:r,mnemonic:null};return(0,g.setWarpWalletInConfig)(this.config,this.chain.name,s),s}async export(){let r=this.getKeypair(),e=(0,g.getWarpWalletMnemonicFromConfig)(this.config,this.chain.name),t=(0,g.getWarpWalletPrivateKeyFromConfig)(this.config,this.chain.name);return{provider:P.PROVIDER_NAME,address:r.getPublicKey().toSuiAddress(),privateKey:t||null,mnemonic:e||null}}async generate(){let r=mr.generateMnemonic(yr.wordlist,256),e=(0,g.normalizeMnemonic)(r);(0,g.validateMnemonicLength)(e);let n=F.Ed25519Keypair.deriveKeypair(e).getPublicKey().toSuiAddress();return{provider:P.PROVIDER_NAME,address:n,privateKey:null,mnemonic:e}}getKeypair(){if(this.keypair)return this.keypair;let r=(0,g.getWarpWalletMnemonicFromConfig)(this.config,this.chain.name);if(!r)throw new Error("No mnemonic provided");return this.keypair=F.Ed25519Keypair.deriveKeypair(r.trim()),this.keypair}};P.PROVIDER_NAME="mnemonic";var z=P;var T=require("@mysten/sui/keypairs/ed25519"),y=require("@joai/warps"),I=class I{constructor(r,e){this.config=r;this.chain=e;this.keypair=null}async getAddress(){return(0,y.getWarpWalletAddressFromConfig)(this.config,this.chain.name)}async getPublicKey(){try{let e=this.getKeypair().getPublicKey();return Buffer.from(e.toRawBytes()).toString("hex")}catch{return null}}async signTransaction(r){if(r&&typeof r=="object"&&"sign"in r&&typeof r.sign=="function")return r;let e=this.getKeypair(),t=new TextEncoder().encode(JSON.stringify(r)),n=await e.signPersonalMessage(t);return{...r,signature:n.signature}}async signMessage(r){let e=this.getKeypair(),t=new TextEncoder().encode(r);return(await e.signPersonalMessage(t)).signature}getKeypairInstance(){return this.getKeypair()}async importFromMnemonic(r){let e=T.Ed25519Keypair.deriveKeypair(r.trim()),t=e.getPublicKey().toSuiAddress(),n=Buffer.from(e.getSecretKey()).toString("hex"),i={provider:I.PROVIDER_NAME,address:t,privateKey:n,mnemonic:r};return(0,y.setWarpWalletInConfig)(this.config,this.chain.name,i),i}async importFromPrivateKey(r){let e=Buffer.from(r,"hex"),t;if(e.length===70)t=new Uint8Array(e.subarray(1,33));else if(e.length===32)t=new Uint8Array(e);else throw new Error(`Unsupported private key length: ${e.length} bytes`);let i=T.Ed25519Keypair.fromSecretKey(t).getPublicKey().toSuiAddress(),s={provider:I.PROVIDER_NAME,address:i,privateKey:r,mnemonic:null};return(0,y.setWarpWalletInConfig)(this.config,this.chain.name,s),s}async export(){let r=this.getKeypair(),e=(0,y.getWarpWalletPrivateKeyFromConfig)(this.config,this.chain.name),t=(0,y.getWarpWalletMnemonicFromConfig)(this.config,this.chain.name);return{provider:I.PROVIDER_NAME,address:r.getPublicKey().toSuiAddress(),privateKey:e||null,mnemonic:t||null}}async generate(){let r=T.Ed25519Keypair.generate(),e=r.getPublicKey().toSuiAddress(),t=Buffer.from(r.getSecretKey()).toString("hex");return{provider:I.PROVIDER_NAME,address:e,privateKey:t,mnemonic:null}}getKeypair(){if(this.keypair)return this.keypair;let r=(0,y.getWarpWalletPrivateKeyFromConfig)(this.config,this.chain.name);if(!r)throw new Error("Wallet not initialized - no private key provided");try{let e=Buffer.from(r,"hex");if(e.length===70){let t=new Uint8Array(e.subarray(1,33));return this.keypair=T.Ed25519Keypair.fromSecretKey(t),this.keypair}else{if(e.length===32)return this.keypair=T.Ed25519Keypair.fromSecretKey(new Uint8Array(e)),this.keypair;throw new Error(`Unsupported private key length: ${e.length} bytes`)}}catch(e){throw e}}};I.PROVIDER_NAME="privateKey";var M=I;var x=require("@joai/warps"),B=class{constructor(r,e){this.config=r;this.chain=e}async getAddress(){return(0,x.getWarpWalletAddressFromConfig)(this.config,this.chain.name)}async getPublicKey(){return null}async signTransaction(r){let e=await this.getAddress();throw new Error(`Wallet can not be used for signing: ${e}`)}async signMessage(r){let e=await this.getAddress();throw new Error(`Wallet can not be used for signing: ${e}`)}async importFromMnemonic(r){let e=(0,x.getWarpWalletAddressFromConfig)(this.config,this.chain.name);throw new Error(`Wallet can not be used for signing: ${e}`)}async importFromPrivateKey(r){let e=(0,x.getWarpWalletAddressFromConfig)(this.config,this.chain.name);throw new Error(`Wallet can not be used for signing: ${e}`)}async export(){let r=(0,x.getWarpWalletAddressFromConfig)(this.config,this.chain.name);throw new Error(`Wallet can not be used for signing: ${r}`)}async generate(){let r=(0,x.getWarpWalletAddressFromConfig)(this.config,this.chain.name);throw new Error(`Wallet can not be used for signing: ${r}`)}};var _=class{constructor(r,e){this.config=r;this.chain=e;this.cachedAddress=null;this.cachedPublicKey=null;this.client=Q(r,e),this.walletProvider=this.createProvider(),this.isInitializedPromise=new Promise(t=>{this.isInitializedResolve=t}),this.initializeCache()}async waitUntilInitialized(){await this.isInitializedPromise}async signTransaction(r){if(await this.waitUntilInitialized(),!r||typeof r!="object")throw new Error("Invalid transaction object");if(!this.walletProvider)throw new Error("No wallet provider available");if(this.walletProvider instanceof B)throw new Error(`Wallet (${this.chain.name}) is read-only`);return r&&typeof r=="object"&&"sign"in r&&typeof r.sign=="function"?r:await this.walletProvider.signTransaction(r)}async signMessage(r){if(await this.waitUntilInitialized(),!this.walletProvider)throw new Error("No wallet provider available");if(this.walletProvider instanceof B)throw new Error(`Wallet (${this.chain.name}) is read-only`);return await this.walletProvider.signMessage(r)}async signTransactions(r){return await this.waitUntilInitialized(),r}async sendTransaction(r){if(await this.waitUntilInitialized(),!r||typeof r!="object")throw new Error("Invalid transaction object");if(this.walletProvider instanceof M||this.walletProvider instanceof z){let e=this.walletProvider.getKeypairInstance();if(r&&typeof r=="object"&&"sign"in r&&typeof r.sign=="function")return(await this.client.signAndExecuteTransaction({transaction:r,signer:e,options:{showEffects:!0,showEvents:!0}})).digest;if(r&&typeof r=="object"&&"bytes"in r&&"signature"in r)try{return(await this.client.executeTransactionBlock({transactionBlock:r.bytes,signature:Array.isArray(r.signature)?r.signature:[r.signature],options:{showEffects:!0,showEvents:!0}})).digest}catch(t){throw t}throw new Error(`Transaction must be a Transaction object or have bytes and signature. Got: ${typeof r}, has sign: ${r&&typeof r=="object"&&"sign"in r}, has bytes: ${r&&typeof r=="object"&&"bytes"in r}, has signature: ${r&&typeof r=="object"&&"signature"in r}`)}throw new Error("Wallet provider does not support sending transactions")}async sendTransactions(r){return await this.waitUntilInitialized(),Promise.all(r.map(async e=>this.sendTransaction(e)))}async importFromMnemonic(r){return await this.waitUntilInitialized(),await this.createProviderForOperation("mnemonic").importFromMnemonic(r)}async importFromPrivateKey(r){return await this.waitUntilInitialized(),await this.createProviderForOperation("privateKey").importFromPrivateKey(r)}async export(r){return await this.waitUntilInitialized(),await this.createProviderForOperation(r).export()}async generate(r){return await this.waitUntilInitialized(),await this.createProviderForOperation(r).generate()}getAddress(){return this.cachedAddress}getPublicKey(){return this.cachedPublicKey}createProvider(){let r=this.config.user?.wallets?.[this.chain.name];return r?typeof r=="string"?new B(this.config,this.chain):this.createProviderForOperation(r.provider):null}async initializeCache(){let r=await(0,Wr.initializeWalletCache)(this.walletProvider);this.cachedAddress=r.address,this.cachedPublicKey=r.publicKey,this.isInitializedResolve()}createProviderForOperation(r){let t=this.config.walletProviders?.[this.chain.name]?.[r];if(t){let n=t(this.config,this.chain);if(!n)throw new Error(`Custom wallet provider factory returned null for ${r}`);return n}if(r==="privateKey")return new M(this.config,this.chain);if(r==="mnemonic")return new z(this.config,this.chain);throw new Error(`Unsupported wallet provider for ${this.chain.name}: ${r}`)}};var H={chain:U.WarpChainName.Sui,identifier:"0x2::sui::SUI",name:"SUI",symbol:"SUI",decimals:9,logoUrl:"https://assets.coingecko.com/coins/images/26375/standard/sui-ocean-square.png?1727791290"};function Ur(o,r){return(e,t)=>{let n=r[e.env];if(!n)throw new Error(`SuiAdapter: chain info not found for chain ${o}`);return{chainInfo:n,builder:()=>new N(e,n),executor:new $(e,n),output:new E(e,n),serializer:new w,registry:new j(e,n),explorer:new O(e,n),abiBuilder:()=>new S(e,n),brandBuilder:()=>new K(e,n),dataLoader:new D(e,n),wallet:new _(e,n)}}}var Rr=Ur(U.WarpChainName.Sui,{mainnet:{name:U.WarpChainName.Sui,displayName:"Sui",chainId:"1",blockTime:3e3,addressHrp:"sui",defaultApiUrl:"https://fullnode.mainnet.sui.io",logoUrl:"https://raw.githubusercontent.com/JoAiHQ/assets/refs/heads/main/chains/logos/sui.svg",nativeToken:H},testnet:{name:U.WarpChainName.Sui,displayName:"Sui Testnet",chainId:"testnet",blockTime:3e3,addressHrp:"sui",defaultApiUrl:"https://fullnode.testnet.sui.io",logoUrl:"https://raw.githubusercontent.com/JoAiHQ/assets/refs/heads/main/chains/logos/sui.svg",nativeToken:H},devnet:{name:U.WarpChainName.Sui,displayName:"Sui Devnet",chainId:"devnet",blockTime:3e3,addressHrp:"sui",defaultApiUrl:"https://fullnode.devnet.sui.io",logoUrl:"https://raw.githubusercontent.com/JoAiHQ/assets/refs/heads/main/chains/logos/sui.svg",nativeToken:H}});var q=class{constructor(r,e){this.abi=new S(r,e)}async loadModuleAbi(r,e){return this.abi.getModuleAbi(r,e)}async loadFunctionAbi(r,e,t){return this.abi.getFunctionAbi(r,e,t)}};0&&(module.exports={ExplorerUrls,KnownTokens,NativeTokenSui,SuiAdapter,SuiExplorers,SuiExplorersConfig,WarpSuiAbiBuilder,WarpSuiBrandBuilder,WarpSuiBuilder,WarpSuiConstants,WarpSuiContractLoader,WarpSuiDataLoader,WarpSuiExecutor,WarpSuiExplorer,WarpSuiOutput,WarpSuiRegistry,WarpSuiSerializer,WarpSuiWallet,findKnownTokenById,getConfiguredSuiClient,getSuiRegistryObjectId,getSuiRegistryPackageId,toRegistryMoveTarget,toTypedRegistryInfo});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var T=o=>{if(o==="devnet")throw new Error("Sui registry package id is not available for devnet");if(o==="testnet")return"0xc8824c98b09d36eec6c8b69ae7083e0b012b5e516e2f7a54c75bfa8a80105753";throw new Error("Sui registry package id is not available for mainnet")},qr=o=>{if(o==="devnet")throw new Error("Sui registry object id is not available for devnet");if(o==="testnet")return"";throw new Error("Sui registry object id is not available for mainnet")};var Yr={Sui:{Identifier:"SUI",DisplayName:"Sui",Decimals:9}},er=(s=>(s.SuiVision="suivision",s.SuiVisionTestnet="suivision_testnet",s.SuiVisionDevnet="suivision_devnet",s.SuiScan="suiscan",s.SuiScanTestnet="suiscan_testnet",s.SuiScanDevnet="suiscan_devnet",s))(er||{}),z={sui:{mainnet:["suivision","suiscan"],testnet:["suivision_testnet","suiscan_testnet"],devnet:["suivision_devnet","suiscan_devnet"]}},y={suivision:"https://suivision.xyz",suivision_testnet:"https://testnet.suivision.xyz",suivision_devnet:"https://devnet.suivision.xyz",suiscan:"https://suiscan.xyz",suiscan_testnet:"https://testnet.suiscan.xyz",suiscan_devnet:"https://devnet.suiscan.xyz"};import{SuiClient as tr}from"@mysten/sui/client";import{getProviderConfig as nr}from"@joai/warps";var M=(o,r)=>{let e=nr(o,r.name,o.env,r.defaultApiUrl);return new tr({url:e.url})};var l=(o,r)=>`${T(o)}::${r}`,ir=o=>{let r=Buffer.from(o).toString();return r==="unverified"||r==="verified"||r==="blacklisted"?r:"unverified"},x=o=>({hash:Buffer.from(o.hash).toString("hex"),alias:o.alias?Buffer.from(o.alias).toString():null,trust:ir(o.trust),owner:o.owner,createdAt:Number(o.created_at),upgradedAt:Number(o.upgraded_at),brand:o.brand?Buffer.from(o.brand).toString("hex"):null,upgrade:o.upgrade?Buffer.from(o.upgrade).toString("hex"):null});import{WarpChainName as I}from"@joai/warps";import{SuiClient as ar}from"@mysten/sui/client";import{getProviderConfig as sr}from"@joai/warps";var w=class{constructor(r,e){this.config=r;this.chain=e;let t=sr(this.config,this.chain.name,this.config.env,this.chain.defaultApiUrl);this.client=new ar({url:t.url})}async createInscriptionTransaction(r){throw new Error("WarpSuiAbiBuilder: createInscriptionTransaction not implemented")}async createFromRaw(r){return JSON.parse(r)}async createFromTransaction(r){return this.createFromRaw(r.data||"{}")}async createFromTransactionHash(r,e){try{let t=await this.client.getTransactionBlock({digest:r});return t?this.createFromTransaction(t):null}catch{return null}}async getModuleAbi(r,e){return this.client.getNormalizedMoveModule({package:r,module:e})}async getFunctionAbi(r,e,t){return this.client.getNormalizedMoveFunction({package:r,module:e,function:t})}};import{SuiClient as or}from"@mysten/sui/client";import{Transaction as cr}from"@mysten/sui/transactions";import{getProviderConfig as lr}from"@joai/warps";var B=class{constructor(r,e){this.config=r;this.chain=e;let t=lr(this.config,this.chain.name,this.config.env,this.chain.defaultApiUrl);this.client=new or({url:t.url})}createInscriptionTransaction(r){return new cr}async createFromRaw(r){return JSON.parse(r)}async createFromTransaction(r,e){return this.createFromRaw(r.data||"{}")}async createFromTransactionHash(r,e){try{let t=await this.client.getTransactionBlock({digest:r});return t?this.createFromTransaction(t,!1):null}catch{return null}}};import{SuiClient as pr}from"@mysten/sui/client";import{Transaction as ur}from"@mysten/sui/transactions";import{getProviderConfig as gr,getWarpWalletAddressFromConfig as dr,WarpBuilder as fr,WarpCache as hr}from"@joai/warps";var U=class extends fr{constructor(e,t){super(e);this.config=e;this.chain=t;this.cache=new hr(e.env,e.cache);let n=gr(this.config,this.chain.name,this.config.env,this.chain.defaultApiUrl);this.client=new pr({url:n.url}),this.userWallet=dr(this.config,this.chain.name)}async createInscriptionTransaction(e,t){if(!t)throw new Error("WarpSuiBuilder: registryObjectId is required");if(!this.userWallet)throw new Error("WarpSuiBuilder: user address not set");if(!e.meta||!e.meta.hash)throw new Error("WarpSuiBuilder: warp.meta.hash is required");let n=Array.from(Buffer.from(e.meta.hash,"hex")),i=e.meta?.alias??void 0,s=e.meta?.brand?Array.from(Buffer.from(e.meta.brand,"hex")):void 0,a=new ur;return a.moveCall({target:l(this.config.env,"register_warp"),arguments:[a.object(t),a.pure.vector("u8",n),i?a.pure.option("string",i):a.pure.option("string",void 0),s?a.pure.option("vector<u8>",s):a.pure.option("vector<u8>",void 0),a.gas,a.pure.address(this.userWallet)]}),a}async createFromNetwork(e,t){let n=`sui:warp:${e}`;if(t){let i=this.cache.get(n);if(i)return i}try{let i=await this.client.call(`${l(this.config.env,"get_info_by_hash")}`,[e,Array.from(Buffer.from(e,"hex"))]);if(!i||!Object.prototype.hasOwnProperty.call(i,"hash")||!i.hash)return null;let s=this.createFromRaw(i);return t&&t.ttl&&s&&this.cache.set(n,s,t.ttl),s}catch{return null}}async createFromTransaction(e){return this.createFromRaw(e)}async createFromTransactionHash(e,t){return this.createFromNetwork(e,t)}};import{SuiClient as Wr}from"@mysten/sui/client";import{CacheTtl as vr,getProviderConfig as wr,WarpCache as Cr,WarpCacheKey as br}from"@joai/warps";import{WarpChainName as mr}from"@joai/warps";var f=mr.Sui,yr=[{chain:f,identifier:"0x2::sui::SUI",name:"Sui",symbol:"SUI",decimals:9,logoUrl:"https://assets.coingecko.com/coins/images/26375/small/sui-logo.png"},{chain:f,identifier:"0xa198f3be41cda8c07c3bf1c4e0bb88b8e9827b7c063f36b1e6c3d6da1c4e8753::usdc::USDC",name:"USD Coin",symbol:"USDC",decimals:6,logoUrl:"https://assets.coingecko.com/coins/images/6319/small/USD_Coin_icon.png"},{chain:f,identifier:"0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48ace0cdd97::usdt::USDT",name:"Tether USD",symbol:"USDT",decimals:6,logoUrl:"https://assets.coingecko.com/coins/images/325/small/Tether.png"},{chain:f,identifier:"0xaf8cd5edc19c4512f4259f0bee101a7c94d8a5c0e7c90c7a7c8c8c8c8c8c8c8c8::wbtc::WBTC",name:"Wrapped Bitcoin",symbol:"WBTC",decimals:8,logoUrl:"https://assets.coingecko.com/coins/images/7598/small/wrapped_bitcoin_wbtc.png"},{chain:f,identifier:"0xb8a6a9b7c7a6f4a3e2d1c0b9a8f7e6d5c4b3a2b1c0d9e8f7a6b5c4d3e2f1a0b::weth::WETH",name:"Wrapped Ether",symbol:"WETH",decimals:8,logoUrl:"https://assets.coingecko.com/coins/images/2518/small/weth.png"},{chain:f,identifier:"0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a15e0e9::ocean::OCEAN",name:"Ocean Protocol",symbol:"OCEAN",decimals:9,logoUrl:"https://assets.coingecko.com/coins/images/3687/small/ocean-protocol-logo.png"},{chain:f,identifier:"0x5d1f47ea69bb0de31c313d7acf89b890dbb8991ea8e03c6c35569693fd50fb8b7::deep::DEEP",name:"DeepBook",symbol:"DEEP",decimals:6,logoUrl:"https://assets.coingecko.com/coins/images/30169/small/deepbook.png"},{chain:f,identifier:"0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47ba3::hasui::HASUI",name:"Haedal Staked SUI",symbol:"HASUI",decimals:9,logoUrl:"https://assets.coingecko.com/coins/images/30027/small/haSUI.png"},{chain:f,identifier:"0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e935::usdc::USDC",name:"USD Coin (Wormhole)",symbol:"USDC",decimals:6,logoUrl:"https://assets.coingecko.com/coins/images/6319/small/USD_Coin_icon.png"}],_=o=>yr.find(r=>r.identifier===o)||null;var R=class{constructor(r,e){this.config=r;this.chain=e;let t=wr(this.config,this.chain.name,this.config.env,this.chain.defaultApiUrl);this.client=new Wr({url:t.url}),this.cache=new Cr(r.env,r.cache)}async getAccount(r){let e=await this.client.getBalance({owner:r,coinType:"0x2::sui::SUI"});return{chain:this.chain.name,address:r,balance:BigInt(e.totalBalance)}}async getAccountAssets(r){let e=await this.client.getAllBalances({owner:r});console.log("WarpSuiDataLoader.getAccountAssets",e);let t=e.find(s=>s.coinType==="0x2::sui::SUI"),n=e.filter(s=>s.coinType!=="0x2::sui::SUI"&&BigInt(s.totalBalance)>0n),i=[];if(t&&BigInt(t.totalBalance)>0n&&i.push({...this.chain.nativeToken,amount:BigInt(t.totalBalance)}),n.length>0){let s=await Promise.all(n.map(a=>this.getAsset(a.coinType)));i.push(...s.filter(a=>a!==null).map(a=>({...a,amount:BigInt(n.find(c=>c.coinType===a.identifier)?.totalBalance||0)})))}return i}async getAsset(r){let e=br.Asset(this.config.env,this.chain.name,r),t=this.cache.get(e);if(t)return t;let n=_(r);if(n)return{chain:this.chain.name,identifier:r,name:n.name,symbol:n.symbol,amount:0n,decimals:n.decimals,logoUrl:n.logoUrl};try{let i=await this.client.getCoinMetadata({coinType:r}),s={chain:this.chain.name,identifier:r,name:i?.name||r.split("::").pop()||r,symbol:i?.symbol||r.split("::").pop()||r,amount:0n,decimals:i?.decimals||9,logoUrl:i?.iconUrl||""};return this.cache.set(e,s,vr.OneHour),s}catch{return null}}async getAction(r,e=!1){return null}async getAccountActions(r,e){return[]}};import{SuiClient as Br}from"@mysten/sui/client";import{Transaction as Q}from"@mysten/sui/transactions";import{applyOutputToMessages as Ur,extractResolvedInputValues as Rr,getNextInfo as kr,getProviderConfig as Kr,getWarpActionByIndex as O,getWarpWalletAddressFromConfig as Nr}from"@joai/warps";import{SuiClient as Er}from"@mysten/sui/client";import{applyOutputToMessages as Pr,evaluateOutputCommon as V,getNextInfo as Ir,getProviderConfig as Tr,getWarpWalletAddressFromConfig as xr,parseOutputOutIndex as H,WarpConstants as G}from"@joai/warps";import{Transaction as Ar}from"@mysten/sui/transactions";import{WarpSerializer as Sr}from"@joai/warps";var m=class{constructor(){this.coreSerializer=new Sr}typedToString(r){if(r==null)return"option:null";if(typeof r=="string")return`string:${r}`;if(typeof r=="boolean")return`bool:${r}`;if(typeof r=="number")return`uint64:${r.toString()}`;if(typeof r=="bigint")return`uint64:${r.toString()}`;if(r&&typeof r=="object"&&r.address)return`address:${r.address}`;if(Array.isArray(r)){if(r.length===0)return"vector:u8:";let e=this.typeToString(typeof r[0]),t=r.map(n=>this.typedToString(n).split(":")[1]);return`vector:${e}:${t.join(",")}`}if(r&&typeof r=="object"&&r.type&&r.value&&r.type==="option")return r.value===null||r.value===void 0?"option:null":`option:${this.typedToString(r.value)}`;throw new Error(`WarpSuiSerializer (typedToString): Unsupported input type: ${typeof r}`)}typedToNative(r){let e=this.typedToString(r);return this.coreSerializer.stringToNative(e)}nativeToTyped(r,e){let t=this.coreSerializer.nativeToString(r,e);return this.stringToTyped(t)}stringToTyped(r,e){let t=e||new Ar,[n,i]=r.split(/:(.*)/,2);if(n==="object")return t.object(i);if(n==="string")return t.pure.string(i);if(n==="bool")return t.pure.bool(i==="true");if(n==="u8")return t.pure.u8(Number(i));if(n==="u16")return t.pure.u16(Number(i));if(n==="u32")return t.pure.u32(Number(i));if(n==="u64"||n==="uint64")return t.pure.u64(BigInt(i));if(n==="u128")return t.pure.u128(BigInt(i));if(n==="u256")return t.pure.u256(BigInt(i));if(n==="address")return t.pure.address(i);throw new Error(`WarpSuiSerializer (stringToTyped): Unsupported type: ${n}`)}typeToString(r){if(r==="string")return"string";if(r==="bool")return"bool";if(r==="u8")return"u8";if(r==="u16")return"u16";if(r==="u32")return"u32";if(r==="u64"||r==="bigint"||r==="number")return"u64";if(r==="u128")return"u128";if(r==="u256")return"u256";if(r==="address")return"address";if(r==="vector")return"vector";if(r==="option")return"option";throw new Error(`WarpSuiSerializer (typeToString): Unsupported input type: ${r}`)}nativeToType(r){throw new Error("Not implemented")}};var C=class{constructor(r,e){this.config=r;this.chain=e;this.serializer=new m;let t=Tr(this.config,this.chain.name,this.config.env,this.chain.defaultApiUrl);this.client=new Er({url:t.url})}async getActionExecution(r,e,t){let n=await this.extractContractOutput(r,e,t,[]),i=Ir(this.config,[],r,e,n.output),s=Pr(r,n.output,this.config);return{status:t.effects?.status?.status==="success"?"success":"error",warp:r,action:e,user:xr(this.config,this.chain.name),txHash:t.digest,tx:t,next:i,values:n.values,output:n.output,messages:s,destination:null,resolvedInputs:[]}}async extractContractOutput(r,e,t,n){let i=[],s=[],a={};if(!r.output)return{values:{string:i,native:s,mapped:{}},output:a};for(let[c,p]of Object.entries(r.output)){if(p.startsWith(G.Transform.Prefix))continue;if(p.startsWith("input.")){a[c]=p;continue}let u=H(p);if(u!==null&&u!==e){a[c]=null;continue}if(p.startsWith("out.")){let d=t.returnValues?t.returnValues[c]:null;a[c]=d,i.push(String(d)),s.push(d)}else a[c]=p}return{values:{string:i,native:s,mapped:{}},output:await V(r,a,e,n,this.serializer.coreSerializer,this.config)}}async extractQueryOutput(r,e,t,n){let a={string:e.map(p=>String(p)),native:e,mapped:{}},c={};if(!r.output)return{values:a,output:c};for(let[p,u]of Object.entries(r.output)){if(u.startsWith(G.Transform.Prefix))continue;let d=H(u);if(d!==null&&d!==t){c[p]=null;continue}if(u.startsWith("out.")||u==="out")if(Array.isArray(e)&&e.length>0&&typeof e[0]=="object"&&e[0]!==null){let rr=u.replace(/^out\./,"");c[p]=e[0][rr]}else c[p]=e[0];else c[p]=u}return{values:a,output:await V(r,c,t,n,this.serializer.coreSerializer,this.config)}}};var k=class{constructor(r,e){this.config=r;this.chain=e;this.serializer=new m,this.output=new C(this.config,this.chain);let t=Kr(this.config,this.chain.name,this.config.env,this.chain.defaultApiUrl);this.client=new Br({url:t.url}),this.userWallet=Nr(this.config,this.chain.name)}async createTransaction(r){let e=O(r.warp,r.action);if(e.type==="transfer")return this.createTransferTransaction(r);if(e.type==="contract")return this.createContractCallTransaction(r);throw e.type==="query"?new Error("WarpSuiExecutor: Invalid action type for createTransaction; Use executeQuery instead"):e.type==="collect"?new Error("WarpSuiExecutor: Invalid action type for createTransaction; Use executeCollect instead"):new Error(`WarpSuiExecutor: Invalid action type (${e.type})`)}async createTransferTransaction(r){if(!this.userWallet)throw new Error("WarpSuiExecutor: createTransfer - user address not set");if(!r.destination)throw new Error("WarpSuiExecutor: Invalid destination address");if(r.value<0)throw new Error(`WarpSuiExecutor: Transfer value cannot be negative: ${r.value}`);let e=new Q,t=[];if(r.value>0){let n=await this.handleCoinTransfer(e,"0x2::sui::SUI",r.value);t.push(n)}for(let n of r.transfers){let i=await this.handleCoinTransfer(e,n.identifier,n.amount);t.push(i)}return t.length>0&&e.transferObjects(t,e.pure.address(r.destination)),e}async createContractCallTransaction(r){if(!this.userWallet)throw new Error("WarpSuiExecutor: createContractCall - user address not set");if(!r.destination)throw new Error("WarpSuiExecutor: Invalid contract address");if(r.value<0)throw new Error(`WarpSuiExecutor: Contract call value cannot be negative: ${r.value}`);let e=O(r.warp,r.action);if(!e.func)throw new Error("WarpSuiExecutor: createContractCall - function not set");let t=new Q;t.setSender(this.userWallet);let n=[];r.value>0&&n.push(await this.handleCoinTransfer(t,"0x2::sui::SUI",r.value));for(let c of r.transfers)n.push(await this.handleCoinTransfer(t,c.identifier,c.amount));let{target:i,typeArguments:s}=this.parseMoveCallTarget(e),a=r.args.map(c=>this.serializer.stringToTyped(c,t));return i==="0x2::transfer::public_transfer"?n.push(...await this.buildPublicTransferArgs(t,r,a)):n.push(...a),t.moveCall({target:i,arguments:n,typeArguments:s}),t.setGasBudget(1e8),t}async executeQuery(r){if(!r.destination)throw new Error("WarpSuiExecutor: executeQuery - destination not set");let e=O(r.warp,r.action);if(e.type!=="query")throw new Error(`WarpSuiExecutor: Invalid action type for executeQuery: ${e.type}`);let t=await this.client.getObject({id:r.destination,options:{showContent:!0}}),n=[t],{values:i,output:s}=await this.output.extractQueryOutput(r.warp,n,r.action,r.resolvedInputs),a=kr(this.config,[],r.warp,r.action,s),p=r.resolvedInputs.find(d=>d.input.position==="receiver"||d.input.position==="destination")?.value||r.destination,u=Rr(r.resolvedInputs);return{status:"success",warp:r.warp,action:r.action,user:this.userWallet,txHash:null,tx:null,next:a,values:i,output:{...s,_DATA:t},resolvedInputs:u,messages:Ur(r.warp,s,this.config),destination:p}}async signMessage(r,e){throw new Error("Not implemented")}parseMoveCallTarget(r){if(!r.func)throw new Error("WarpSuiExecutor: Function not set");let e=`${r.address}::${r.func}`,t=r.typeArguments;if(!t&&r.func.includes("<")&&r.func.includes(">")){let n=r.func.match(/<([^>]+)>/);n&&(t=[n[1]],e=`${r.address}::${r.func.replace(/<[^>]+>/,"")}`)}return{target:e,typeArguments:t}}async buildPublicTransferArgs(r,e,t){let n=e.resolvedInputs.find(a=>String(a.input.position)==="arg:0")?.value||e.args[0],i=e.resolvedInputs.find(a=>String(a.input.position)==="arg:1")?.value||e.resolvedInputs.find(a=>a.input.type==="address"&&String(a.input.position)!=="arg:0")?.value||e.args[1],s=this.extractObjectId(n);if(!s)return t;try{if(!(await this.client.getObject({id:s,options:{showType:!0,showContent:!0}})).data?.type?.startsWith("0x2::coin::Coin<"))return t;let c=i?this.serializer.stringToTyped(i.includes(":")?i:`address:${i}`,r):t[1]||r.pure.address(this.userWallet);return[r.object(s),c]}catch{return t}}extractObjectId(r){if(!r||typeof r!="string")return null;let e=r.startsWith("object:")?r.substring(7):r;return e.startsWith("0x")?e:null}async handleCoinTransfer(r,e,t){if(e==="0x2::sui::SUI")try{return r.splitCoins(r.gas,[t.toString()])[0]}catch{}return this.createCoinTransferFromObjects(r,e,t)}async createCoinTransferFromObjects(r,e,t){let n=await this.getCoinObjectsForTransfer(e,t);if(n.length===0)throw new Error(`No coin objects found for ${e}`);let i=r.object(n[0].coinObjectId);return n.length>1&&r.mergeCoins(i,n.slice(1).map(s=>r.object(s.coinObjectId))),r.splitCoins(i,[t.toString()])[0]}async getCoinObjectsForTransfer(r,e){if(!this.userWallet)throw new Error("User wallet not set");let{data:t}=await this.client.getCoins({owner:this.userWallet,coinType:r}),n=t.map(a=>({coinObjectId:a.coinObjectId,balance:a.balance})).sort((a,c)=>BigInt(c.balance)>BigInt(a.balance)?1:-1),i=BigInt(0),s=[];for(let a of n)if(s.push(a),i+=BigInt(a.balance),i>=e)return s;throw new Error(`Insufficient ${r} balance. Required: ${e}, Available: ${i}`)}};var K=class{constructor(r,e){this.config=r;this.chain=e}getExplorers(){let r=z[this.chain.name];if(!r)return["suivision"];let e=r[this.config.env];return e||["suivision"]}getPrimaryExplorer(){return this.getExplorers()[0]}getExplorerUrlByName(r){let e=this.config.preferences?.explorers?.[this.chain.name];if(e&&!r){let i=y[e];if(i)return i}if(r){let i=y[r];if(i)return i}let t=this.getPrimaryExplorer();return y[t]||y[t]}getAccountUrl(r,e){return`${this.getExplorerUrlByName(e)}/account/${r}`}getTransactionUrl(r,e){return`${this.getExplorerUrlByName(e)}/txblock/${r}`}getBlockUrl(r,e){return`${this.getExplorerUrlByName(e)}/block/${r}`}getAssetUrl(r,e){return`${this.getExplorerUrlByName(e)}/coin/${r}`}getContractUrl(r,e){return`${this.getExplorerUrlByName(e)}/object/${r}`}getAllExplorers(){return this.getExplorers()}getExplorerByName(r){return this.getExplorers().find(t=>t.toLowerCase()===r.toLowerCase())}getAccountUrls(r){let e=this.getAllExplorers(),t={};return e.forEach(n=>{let i=y[n];i&&(t[n]=`${i}/account/${r}`)}),t}getTransactionUrls(r){let e=this.getAllExplorers(),t={};return e.forEach(n=>{let i=y[n];i&&(t[n]=`${i}/txblock/${r}`)}),t}};import{SuiClient as Dr}from"@mysten/sui/client";import{Transaction as h}from"@mysten/sui/transactions";import{getProviderConfig as $r,getWarpWalletAddressFromConfig as Or,WarpCache as jr,WarpCacheKey as j,WarpLogger as g}from"@joai/warps";var N=class{constructor(r,e){this.config=r;this.chain=e;this.registryConfig={unitPrice:BigInt(0),admins:[]};let t=$r(this.config,this.chain.name,this.config.env,this.chain.defaultApiUrl);this.client=new Dr({url:t.url}),this.cache=new jr(r.env,r.cache),this.userWallet=Or(this.config,this.chain.name)}async init(){await this.loadRegistryConfigs()}getRegistryConfig(){return this.registryConfig}async loadRegistryConfigs(){try{let r=`${T(this.config.env)}::registry::get_config`;console.log("-- Loading registry configs",r);let e=new h;e.moveCall({target:r,arguments:[]});let t=await this.client.devInspectTransactionBlock({transactionBlock:e,sender:"0x0000000000000000000000000000000000000000000000000000000000000000"});console.log("-- Registry configs loaded",t);let n=t.results?.[0]?.returnValues?.[0],i=n&&Array.isArray(n)&&n[0]?JSON.parse(String.fromCharCode(...n[0])):{};this.registryConfig={unitPrice:i.unit_price!==void 0?BigInt(i.unit_price):BigInt(0),admins:Array.isArray(i.admins)?i.admins:[]}}catch(r){g.error("WarpSuiRegistry: Failed to load registry config",r),this.registryConfig={unitPrice:BigInt(0),admins:[]}}}async createWarpRegisterTransaction(r,e,t){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let n=new h;return n.moveCall({target:l(this.config.env,"register_warp"),arguments:[n.pure.vector("u8",Array.from(Buffer.from(r,"hex"))),e?n.pure.option("string",e):n.pure.option("string",void 0),t?n.pure.option("vector<u8>",Array.from(Buffer.from(t,"hex"))):n.pure.option("vector<u8>",void 0),n.gas,n.pure.address(this.userWallet)]}),n}async createWarpUnregisterTransaction(r){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let e=new h;return e.moveCall({target:l(this.config.env,"unregister_warp"),arguments:[e.pure.vector("u8",Array.from(Buffer.from(r,"hex"))),e.gas,e.pure.address(this.userWallet)]}),e}async createWarpUpgradeTransaction(r,e){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let t=new h;return t.moveCall({target:l(this.config.env,"upgrade_warp"),arguments:[t.pure.string(r),t.pure.vector("u8",Array.from(Buffer.from(e,"hex"))),t.gas,t.pure.address(this.userWallet)]}),t}async createWarpAliasSetTransaction(r,e){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let t=new h;return t.moveCall({target:l(this.config.env,"set_warp_alias"),arguments:[t.pure.vector("u8",Array.from(Buffer.from(r,"hex"))),t.pure.string(e),t.gas,t.pure.address(this.userWallet)]}),t}async createWarpVerifyTransaction(r){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let e=new h;return e.moveCall({target:l(this.config.env,"verify_warp"),arguments:[e.pure.vector("u8",Array.from(Buffer.from(r,"hex"))),e.gas,e.pure.address(this.userWallet)]}),e}async createWarpTransferOwnershipTransaction(r,e){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let t=new h;return t.moveCall({target:l(this.config.env,"transfer_ownership"),arguments:[t.pure.vector("u8",Array.from(Buffer.from(r,"hex"))),t.pure.address(e),t.gas,t.pure.address(this.userWallet)]}),t}async createBrandRegisterTransaction(r){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let e=new h;return e.moveCall({target:l(this.config.env,"register_brand"),arguments:[e.pure.vector("u8",Array.from(Buffer.from(r,"hex"))),e.gas,e.pure.address(this.userWallet)]}),e}async createWarpBrandingTransaction(r,e){if(!this.userWallet)throw new Error("WarpRegistry: user address not set");let t=new h;return t.moveCall({target:l(this.config.env,"brand_warp"),arguments:[t.pure.vector("u8",Array.from(Buffer.from(r,"hex"))),t.pure.vector("u8",Array.from(Buffer.from(e,"hex"))),t.gas,t.pure.address(this.userWallet)]}),t}async getInfoByAlias(r,e){let t=j.RegistryInfo(this.config.env,r),n=e?this.cache.get(t):null;if(n)return g.info(`WarpSuiRegistry (getInfoByAlias): RegistryInfo found in cache: ${r}`),n;try{let i=await this.client.call(l(this.config.env,"get_info_by_alias"),[r]),s=i||null,a=s?x(s):null,c=a?.brand?await this.fetchBrand(a.brand,e):null;return e&&e.ttl&&this.cache.set(t,{registryInfo:a,brand:c},e.ttl),{registryInfo:a,brand:c}}catch(i){return g.error("WarpSuiRegistry (getInfoByAlias):",i),{registryInfo:null,brand:null}}}async getInfoByHash(r,e){let t=j.RegistryInfo(this.config.env,r),n=e?this.cache.get(t):null;if(n)return g.info(`WarpSuiRegistry (getInfoByHash): RegistryInfo found in cache: ${r}`),n;try{let i=await this.client.call(l(this.config.env,"get_info_by_hash"),[Array.from(Buffer.from(r,"hex"))]),s=i||null,a=s?x(s):null,c=a?.brand?await this.fetchBrand(a.brand,e):null;return e&&e.ttl&&this.cache.set(t,{registryInfo:a,brand:c},e.ttl),{registryInfo:a,brand:c}}catch(i){return g.error("WarpSuiRegistry (getInfoByHash):",i),{registryInfo:null,brand:null}}}async getUserWarpRegistryInfos(r){let e=`sui:registry:user:${r||this.userWallet}`,t=this.cache.get(e);if(t)return g.info(`WarpSuiRegistry (getUserWarpRegistryInfos): RegistryInfos found in cache for user: ${r||this.userWallet}`),t;try{let n=r||this.userWallet;if(!n)throw new Error("WarpRegistry: user address not set");let i=await this.client.call(l(this.config.env,"get_user_warps"),[n]),s=Array.isArray(i)?i.map(x):[];return r&&this.cache.set(e,s,300),s}catch(n){return g.error("WarpSuiRegistry (getUserWarpRegistryInfos):",n),[]}}async getUserBrands(r){let e=`sui:registry:user:brands:${r||this.userWallet}`,t=this.cache.get(e);if(t)return g.info(`WarpSuiRegistry (getUserBrands): Brands found in cache for user: ${r||this.userWallet}`),t;try{let n=r||this.userWallet;if(!n)throw new Error("WarpRegistry: user address not set");let i=await this.client.call(l(this.config.env,"get_user_brands"),[n]);if(!Array.isArray(i))return[];let a=(await Promise.all(i.map(c=>this.fetchBrand(c)))).filter(c=>c!==null);return r&&this.cache.set(e,a,300),a}catch(n){return g.error("WarpSuiRegistry (getUserBrands):",n),[]}}async fetchBrand(r,e){let t=j.Brand(this.config.env,r),n=e?this.cache.get(t):null;if(n)return g.info(`WarpSuiRegistry (fetchBrand): Brand found in cache: ${r}`),n;try{let i=await this.client.getTransactionBlock({digest:r});if(!i||!i.effects)return null;let s=null;if(i.events&&Array.isArray(i.events)){for(let a of i.events)if(a.type&&typeof a.type=="string"&&a.type.includes("BrandRegistered"))try{s=a.parsedJson;break}catch{}}if(!s&&i.objectChanges&&Array.isArray(i.objectChanges)){for(let a of i.objectChanges)if(a.type==="created"&&a.objectType&&a.objectType.includes("Brand"))try{break}catch{}}return s?(s.meta={hash:r,creator:i.transaction&&i.transaction.data&&i.transaction.data.sender?i.transaction.data.sender:void 0,createdAt:i.timestampMs?new Date(Number(i.timestampMs)).toISOString():void 0},e&&e.ttl&&this.cache.set(t,s,e.ttl),s):null}catch(i){return g.error("WarpSuiRegistry (fetchBrand):",i),null}}};import{initializeWalletCache as Lr}from"@joai/warps";import{Ed25519Keypair as D}from"@mysten/sui/keypairs/ed25519";import*as q from"@scure/bip39";import{wordlist as Fr}from"@scure/bip39/wordlists/english.js";import{getWarpWalletAddressFromConfig as zr,getWarpWalletMnemonicFromConfig as L,getWarpWalletPrivateKeyFromConfig as Mr,normalizeAndValidateMnemonic as _r,normalizeMnemonic as Vr,setWarpWalletInConfig as J,validateMnemonicLength as Hr}from"@joai/warps";var W=class W{constructor(r,e){this.config=r;this.chain=e;this.keypair=null}async getAddress(){return zr(this.config,this.chain.name)}async getPublicKey(){try{let e=this.getKeypair().getPublicKey();return Buffer.from(e.toRawBytes()).toString("hex")}catch{return null}}async signTransaction(r){if(r&&typeof r=="object"&&"sign"in r&&typeof r.sign=="function")return r;let e=this.getKeypair(),t=new TextEncoder().encode(JSON.stringify(r)),n=await e.signPersonalMessage(t);return{...r,signature:n.signature}}async signMessage(r){let e=this.getKeypair(),t=new TextEncoder().encode(r);return(await e.signPersonalMessage(t)).signature}getKeypairInstance(){return this.getKeypair()}async importFromMnemonic(r){let e=_r(r),n=D.deriveKeypair(e).getPublicKey().toSuiAddress(),i={provider:W.PROVIDER_NAME,address:n,privateKey:null,mnemonic:e};return J(this.config,this.chain.name,i),i}async importFromPrivateKey(r){let e=Buffer.from(r,"hex"),t;if(e.length===70)t=new Uint8Array(e.subarray(1,33));else if(e.length===32)t=new Uint8Array(e);else throw new Error(`Unsupported private key length: ${e.length} bytes`);let i=D.fromSecretKey(t).getPublicKey().toSuiAddress(),s={provider:W.PROVIDER_NAME,address:i,privateKey:r,mnemonic:null};return J(this.config,this.chain.name,s),s}async export(){let r=this.getKeypair(),e=L(this.config,this.chain.name),t=Mr(this.config,this.chain.name);return{provider:W.PROVIDER_NAME,address:r.getPublicKey().toSuiAddress(),privateKey:t||null,mnemonic:e||null}}async generate(){let r=q.generateMnemonic(Fr,256),e=Vr(r);Hr(e);let n=D.deriveKeypair(e).getPublicKey().toSuiAddress();return{provider:W.PROVIDER_NAME,address:n,privateKey:null,mnemonic:e}}getKeypair(){if(this.keypair)return this.keypair;let r=L(this.config,this.chain.name);if(!r)throw new Error("No mnemonic provided");return this.keypair=D.deriveKeypair(r.trim()),this.keypair}};W.PROVIDER_NAME="mnemonic";var A=W;import{Ed25519Keypair as S}from"@mysten/sui/keypairs/ed25519";import{getWarpWalletAddressFromConfig as Gr,getWarpWalletMnemonicFromConfig as Qr,getWarpWalletPrivateKeyFromConfig as X,setWarpWalletInConfig as Y}from"@joai/warps";var v=class v{constructor(r,e){this.config=r;this.chain=e;this.keypair=null}async getAddress(){return Gr(this.config,this.chain.name)}async getPublicKey(){try{let e=this.getKeypair().getPublicKey();return Buffer.from(e.toRawBytes()).toString("hex")}catch{return null}}async signTransaction(r){if(r&&typeof r=="object"&&"sign"in r&&typeof r.sign=="function")return r;let e=this.getKeypair(),t=new TextEncoder().encode(JSON.stringify(r)),n=await e.signPersonalMessage(t);return{...r,signature:n.signature}}async signMessage(r){let e=this.getKeypair(),t=new TextEncoder().encode(r);return(await e.signPersonalMessage(t)).signature}getKeypairInstance(){return this.getKeypair()}async importFromMnemonic(r){let e=S.deriveKeypair(r.trim()),t=e.getPublicKey().toSuiAddress(),n=Buffer.from(e.getSecretKey()).toString("hex"),i={provider:v.PROVIDER_NAME,address:t,privateKey:n,mnemonic:r};return Y(this.config,this.chain.name,i),i}async importFromPrivateKey(r){let e=Buffer.from(r,"hex"),t;if(e.length===70)t=new Uint8Array(e.subarray(1,33));else if(e.length===32)t=new Uint8Array(e);else throw new Error(`Unsupported private key length: ${e.length} bytes`);let i=S.fromSecretKey(t).getPublicKey().toSuiAddress(),s={provider:v.PROVIDER_NAME,address:i,privateKey:r,mnemonic:null};return Y(this.config,this.chain.name,s),s}async export(){let r=this.getKeypair(),e=X(this.config,this.chain.name),t=Qr(this.config,this.chain.name);return{provider:v.PROVIDER_NAME,address:r.getPublicKey().toSuiAddress(),privateKey:e||null,mnemonic:t||null}}async generate(){let r=S.generate(),e=r.getPublicKey().toSuiAddress(),t=Buffer.from(r.getSecretKey()).toString("hex");return{provider:v.PROVIDER_NAME,address:e,privateKey:t,mnemonic:null}}getKeypair(){if(this.keypair)return this.keypair;let r=X(this.config,this.chain.name);if(!r)throw new Error("Wallet not initialized - no private key provided");try{let e=Buffer.from(r,"hex");if(e.length===70){let t=new Uint8Array(e.subarray(1,33));return this.keypair=S.fromSecretKey(t),this.keypair}else{if(e.length===32)return this.keypair=S.fromSecretKey(new Uint8Array(e)),this.keypair;throw new Error(`Unsupported private key length: ${e.length} bytes`)}}catch(e){throw e}}};v.PROVIDER_NAME="privateKey";var E=v;import{getWarpWalletAddressFromConfig as P}from"@joai/warps";var b=class{constructor(r,e){this.config=r;this.chain=e}async getAddress(){return P(this.config,this.chain.name)}async getPublicKey(){return null}async signTransaction(r){let e=await this.getAddress();throw new Error(`Wallet can not be used for signing: ${e}`)}async signMessage(r){let e=await this.getAddress();throw new Error(`Wallet can not be used for signing: ${e}`)}async importFromMnemonic(r){let e=P(this.config,this.chain.name);throw new Error(`Wallet can not be used for signing: ${e}`)}async importFromPrivateKey(r){let e=P(this.config,this.chain.name);throw new Error(`Wallet can not be used for signing: ${e}`)}async export(){let r=P(this.config,this.chain.name);throw new Error(`Wallet can not be used for signing: ${r}`)}async generate(){let r=P(this.config,this.chain.name);throw new Error(`Wallet can not be used for signing: ${r}`)}};var $=class{constructor(r,e){this.config=r;this.chain=e;this.cachedAddress=null;this.cachedPublicKey=null;this.client=M(r,e),this.walletProvider=this.createProvider(),this.isInitializedPromise=new Promise(t=>{this.isInitializedResolve=t}),this.initializeCache()}async waitUntilInitialized(){await this.isInitializedPromise}async signTransaction(r){if(await this.waitUntilInitialized(),!r||typeof r!="object")throw new Error("Invalid transaction object");if(!this.walletProvider)throw new Error("No wallet provider available");if(this.walletProvider instanceof b)throw new Error(`Wallet (${this.chain.name}) is read-only`);return r&&typeof r=="object"&&"sign"in r&&typeof r.sign=="function"?r:await this.walletProvider.signTransaction(r)}async signMessage(r){if(await this.waitUntilInitialized(),!this.walletProvider)throw new Error("No wallet provider available");if(this.walletProvider instanceof b)throw new Error(`Wallet (${this.chain.name}) is read-only`);return await this.walletProvider.signMessage(r)}async signTransactions(r){return await this.waitUntilInitialized(),r}async sendTransaction(r){if(await this.waitUntilInitialized(),!r||typeof r!="object")throw new Error("Invalid transaction object");if(this.walletProvider instanceof E||this.walletProvider instanceof A){let e=this.walletProvider.getKeypairInstance();if(r&&typeof r=="object"&&"sign"in r&&typeof r.sign=="function")return(await this.client.signAndExecuteTransaction({transaction:r,signer:e,options:{showEffects:!0,showEvents:!0}})).digest;if(r&&typeof r=="object"&&"bytes"in r&&"signature"in r)try{return(await this.client.executeTransactionBlock({transactionBlock:r.bytes,signature:Array.isArray(r.signature)?r.signature:[r.signature],options:{showEffects:!0,showEvents:!0}})).digest}catch(t){throw t}throw new Error(`Transaction must be a Transaction object or have bytes and signature. Got: ${typeof r}, has sign: ${r&&typeof r=="object"&&"sign"in r}, has bytes: ${r&&typeof r=="object"&&"bytes"in r}, has signature: ${r&&typeof r=="object"&&"signature"in r}`)}throw new Error("Wallet provider does not support sending transactions")}async sendTransactions(r){return await this.waitUntilInitialized(),Promise.all(r.map(async e=>this.sendTransaction(e)))}async importFromMnemonic(r){return await this.waitUntilInitialized(),await this.createProviderForOperation("mnemonic").importFromMnemonic(r)}async importFromPrivateKey(r){return await this.waitUntilInitialized(),await this.createProviderForOperation("privateKey").importFromPrivateKey(r)}async export(r){return await this.waitUntilInitialized(),await this.createProviderForOperation(r).export()}async generate(r){return await this.waitUntilInitialized(),await this.createProviderForOperation(r).generate()}getAddress(){return this.cachedAddress}getPublicKey(){return this.cachedPublicKey}createProvider(){let r=this.config.user?.wallets?.[this.chain.name];return r?typeof r=="string"?new b(this.config,this.chain):this.createProviderForOperation(r.provider):null}async initializeCache(){let r=await Lr(this.walletProvider);this.cachedAddress=r.address,this.cachedPublicKey=r.publicKey,this.isInitializedResolve()}createProviderForOperation(r){let t=this.config.walletProviders?.[this.chain.name]?.[r];if(t){let n=t(this.config,this.chain);if(!n)throw new Error(`Custom wallet provider factory returned null for ${r}`);return n}if(r==="privateKey")return new E(this.config,this.chain);if(r==="mnemonic")return new A(this.config,this.chain);throw new Error(`Unsupported wallet provider for ${this.chain.name}: ${r}`)}};var F={chain:I.Sui,identifier:"0x2::sui::SUI",name:"SUI",symbol:"SUI",decimals:9,logoUrl:"https://assets.coingecko.com/coins/images/26375/standard/sui-ocean-square.png?1727791290"};function Jr(o,r){return(e,t)=>{let n=r[e.env];if(!n)throw new Error(`SuiAdapter: chain info not found for chain ${o}`);return{chainInfo:n,builder:()=>new U(e,n),executor:new k(e,n),output:new C(e,n),serializer:new m,registry:new N(e,n),explorer:new K(e,n),abiBuilder:()=>new w(e,n),brandBuilder:()=>new B(e,n),dataLoader:new R(e,n),wallet:new $(e,n)}}}var Hn=Jr(I.Sui,{mainnet:{name:I.Sui,displayName:"Sui",chainId:"1",blockTime:3e3,addressHrp:"sui",defaultApiUrl:"https://fullnode.mainnet.sui.io",logoUrl:"https://raw.githubusercontent.com/JoAiHQ/assets/refs/heads/main/chains/logos/sui.svg",nativeToken:F},testnet:{name:I.Sui,displayName:"Sui Testnet",chainId:"testnet",blockTime:3e3,addressHrp:"sui",defaultApiUrl:"https://fullnode.testnet.sui.io",logoUrl:"https://raw.githubusercontent.com/JoAiHQ/assets/refs/heads/main/chains/logos/sui.svg",nativeToken:F},devnet:{name:I.Sui,displayName:"Sui Devnet",chainId:"devnet",blockTime:3e3,addressHrp:"sui",defaultApiUrl:"https://fullnode.devnet.sui.io",logoUrl:"https://raw.githubusercontent.com/JoAiHQ/assets/refs/heads/main/chains/logos/sui.svg",nativeToken:F}});var Z=class{constructor(r,e){this.abi=new w(r,e)}async loadModuleAbi(r,e){return this.abi.getModuleAbi(r,e)}async loadFunctionAbi(r,e,t){return this.abi.getFunctionAbi(r,e,t)}};export{y as ExplorerUrls,yr as KnownTokens,F as NativeTokenSui,Hn as SuiAdapter,er as SuiExplorers,z as SuiExplorersConfig,w as WarpSuiAbiBuilder,B as WarpSuiBrandBuilder,U as WarpSuiBuilder,Yr as WarpSuiConstants,Z as WarpSuiContractLoader,R as WarpSuiDataLoader,k as WarpSuiExecutor,K as WarpSuiExplorer,C as WarpSuiOutput,N as WarpSuiRegistry,m as WarpSuiSerializer,$ as WarpSuiWallet,_ as findKnownTokenById,M as getConfiguredSuiClient,qr as getSuiRegistryObjectId,T as getSuiRegistryPackageId,l as toRegistryMoveTarget,x as toTypedRegistryInfo};
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@joai/warps-adapter-sui",
|
|
3
|
+
"version": "1.0.0-beta.74",
|
|
4
|
+
"description": "",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.mjs",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.mjs"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsup",
|
|
17
|
+
"test": "jest --config jest.config.mjs",
|
|
18
|
+
"lint": "tsc --noEmit",
|
|
19
|
+
"preversion": "npm run lint && npm run build"
|
|
20
|
+
},
|
|
21
|
+
"author": "",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/jest": "^30.0.0",
|
|
28
|
+
"jest": "^30.2.0",
|
|
29
|
+
"jest-environment-jsdom": "^30.2.0",
|
|
30
|
+
"jest-fetch-mock": "^3.0.3",
|
|
31
|
+
"ts-jest": "^29.4.6",
|
|
32
|
+
"tsup": "^8.5.1",
|
|
33
|
+
"typescript": "^5.9.3"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@mysten/sui": "^1.45.2",
|
|
40
|
+
"@scure/bip39": "^2.0.1",
|
|
41
|
+
"@joai/warps": "^3.0.0-beta.198"
|
|
42
|
+
}
|
|
43
|
+
}
|