@vleap/warps-adapter-evm 0.2.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,1110 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ ArbitrumExplorers: () => ArbitrumExplorers,
24
+ BaseExplorers: () => BaseExplorers,
25
+ ChainNameArbitrum: () => ChainNameArbitrum,
26
+ ChainNameBase: () => ChainNameBase,
27
+ ChainNameEthereum: () => ChainNameEthereum,
28
+ EVM_CHAIN_CONFIGS: () => EVM_CHAIN_CONFIGS,
29
+ EthereumExplorers: () => EthereumExplorers,
30
+ EvmExplorers: () => EvmExplorers,
31
+ ExplorerUrls: () => ExplorerUrls,
32
+ WarpEvmConstants: () => WarpEvmConstants,
33
+ WarpEvmExecutor: () => WarpEvmExecutor,
34
+ WarpEvmExplorer: () => WarpEvmExplorer,
35
+ WarpEvmResults: () => WarpEvmResults,
36
+ WarpEvmSerializer: () => WarpEvmSerializer,
37
+ getAllEvmAdapters: () => getAllEvmAdapters,
38
+ getAllEvmChainNames: () => getAllEvmChainNames,
39
+ getArbitrumAdapter: () => getArbitrumAdapter,
40
+ getBaseAdapter: () => getBaseAdapter,
41
+ getEthereumAdapter: () => getEthereumAdapter,
42
+ getEvmApiUrl: () => getEvmApiUrl,
43
+ getEvmChainConfig: () => getEvmChainConfig,
44
+ getEvmExplorerUrl: () => getEvmExplorerUrl
45
+ });
46
+ module.exports = __toCommonJS(index_exports);
47
+
48
+ // src/WarpEvmDataLoader.ts
49
+ var import_ethers = require("ethers");
50
+
51
+ // src/config.ts
52
+ var EVM_CHAIN_CONFIGS = {
53
+ ethereum: {
54
+ mainnet: {
55
+ apiUrl: "https://eth-mainnet.g.alchemy.com/v2/demo",
56
+ explorerUrl: "https://etherscan.io",
57
+ chainId: "1",
58
+ registryAddress: "0x0000000000000000000000000000000000000000",
59
+ nativeToken: "ETH",
60
+ blockTime: 12e3
61
+ },
62
+ testnet: {
63
+ apiUrl: "https://eth-sepolia.g.alchemy.com/v2/demo",
64
+ explorerUrl: "https://sepolia.etherscan.io",
65
+ chainId: "11155111",
66
+ registryAddress: "0x0000000000000000000000000000000000000000",
67
+ nativeToken: "ETH",
68
+ blockTime: 12e3
69
+ },
70
+ devnet: {
71
+ apiUrl: "http://localhost:8545",
72
+ explorerUrl: "http://localhost:4000",
73
+ chainId: "1337",
74
+ registryAddress: "0x0000000000000000000000000000000000000000",
75
+ nativeToken: "ETH",
76
+ blockTime: 12e3
77
+ }
78
+ },
79
+ arbitrum: {
80
+ mainnet: {
81
+ apiUrl: "https://arb-mainnet.g.alchemy.com/v2/demo",
82
+ explorerUrl: "https://arbiscan.io",
83
+ chainId: "42161",
84
+ registryAddress: "0x0000000000000000000000000000000000000000",
85
+ nativeToken: "ETH",
86
+ blockTime: 1e3
87
+ },
88
+ testnet: {
89
+ apiUrl: "https://arb-sepolia.g.alchemy.com/v2/demo",
90
+ explorerUrl: "https://sepolia.arbiscan.io",
91
+ chainId: "421614",
92
+ registryAddress: "0x0000000000000000000000000000000000000000",
93
+ nativeToken: "ETH",
94
+ blockTime: 1e3
95
+ },
96
+ devnet: {
97
+ apiUrl: "http://localhost:8545",
98
+ explorerUrl: "http://localhost:4000",
99
+ chainId: "1337",
100
+ registryAddress: "0x0000000000000000000000000000000000000000",
101
+ nativeToken: "ETH",
102
+ blockTime: 1e3
103
+ }
104
+ },
105
+ base: {
106
+ mainnet: {
107
+ apiUrl: "https://mainnet.base.org",
108
+ explorerUrl: "https://basescan.org",
109
+ chainId: "8453",
110
+ registryAddress: "0x0000000000000000000000000000000000000000",
111
+ nativeToken: "ETH",
112
+ blockTime: 2e3
113
+ },
114
+ testnet: {
115
+ apiUrl: "https://sepolia.base.org",
116
+ explorerUrl: "https://sepolia.basescan.org",
117
+ chainId: "84532",
118
+ registryAddress: "0x0000000000000000000000000000000000000000",
119
+ nativeToken: "ETH",
120
+ blockTime: 2e3
121
+ },
122
+ devnet: {
123
+ apiUrl: "http://localhost:8545",
124
+ explorerUrl: "http://localhost:4000",
125
+ chainId: "1337",
126
+ registryAddress: "0x0000000000000000000000000000000000000000",
127
+ nativeToken: "ETH",
128
+ blockTime: 2e3
129
+ }
130
+ }
131
+ };
132
+ var DEFAULT_CHAIN = "ethereum";
133
+ var getEvmChainConfig = (chain = DEFAULT_CHAIN, env) => {
134
+ const chainConfigs = EVM_CHAIN_CONFIGS[chain];
135
+ if (!chainConfigs) {
136
+ throw new Error(`Unsupported EVM chain: ${chain}`);
137
+ }
138
+ const config = chainConfigs[env];
139
+ if (!config) {
140
+ throw new Error(`Unsupported environment ${env} for chain ${chain}`);
141
+ }
142
+ return config;
143
+ };
144
+ var getEvmApiUrl = (env, chain = DEFAULT_CHAIN) => {
145
+ return getEvmChainConfig(chain, env).apiUrl;
146
+ };
147
+ var getEvmExplorerUrl = (env, chain = DEFAULT_CHAIN) => {
148
+ return getEvmChainConfig(chain, env).explorerUrl;
149
+ };
150
+
151
+ // src/WarpEvmDataLoader.ts
152
+ var ERC20_ABI = [
153
+ "function balanceOf(address owner) view returns (uint256)",
154
+ "function decimals() view returns (uint8)",
155
+ "function name() view returns (string)",
156
+ "function symbol() view returns (string)",
157
+ "function totalSupply() view returns (uint256)"
158
+ ];
159
+ var KNOWN_TOKENS = {
160
+ ethereum: {
161
+ "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48": {
162
+ name: "USD Coin",
163
+ symbol: "USDC",
164
+ decimals: 6,
165
+ logoUrl: "https://assets.coingecko.com/coins/images/6319/small/USD_Coin_icon.png"
166
+ },
167
+ "0xdAC17F958D2ee523a2206206994597C13D831ec7": {
168
+ name: "Tether USD",
169
+ symbol: "USDT",
170
+ decimals: 6,
171
+ logoUrl: "https://assets.coingecko.com/coins/images/325/small/Tether.png"
172
+ },
173
+ "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599": {
174
+ name: "Wrapped Bitcoin",
175
+ symbol: "WBTC",
176
+ decimals: 8,
177
+ logoUrl: "https://assets.coingecko.com/coins/images/7598/small/wrapped_bitcoin_wbtc.png"
178
+ },
179
+ "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2": {
180
+ name: "Wrapped Ether",
181
+ symbol: "WETH",
182
+ decimals: 18,
183
+ logoUrl: "https://assets.coingecko.com/coins/images/2518/small/weth.png"
184
+ },
185
+ "0x6B175474E89094C44Da98b954EedeAC495271d0F": {
186
+ name: "Dai Stablecoin",
187
+ symbol: "DAI",
188
+ decimals: 18,
189
+ logoUrl: "https://assets.coingecko.com/coins/images/9956/small/4943.png"
190
+ }
191
+ },
192
+ arbitrum: {
193
+ "0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8": {
194
+ name: "USD Coin",
195
+ symbol: "USDC",
196
+ decimals: 6,
197
+ logoUrl: "https://assets.coingecko.com/coins/images/6319/small/USD_Coin_icon.png"
198
+ },
199
+ "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9": {
200
+ name: "Tether USD",
201
+ symbol: "USDT",
202
+ decimals: 6,
203
+ logoUrl: "https://assets.coingecko.com/coins/images/325/small/Tether.png"
204
+ },
205
+ "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1": {
206
+ name: "Wrapped Ether",
207
+ symbol: "WETH",
208
+ decimals: 18,
209
+ logoUrl: "https://assets.coingecko.com/coins/images/2518/small/weth.png"
210
+ }
211
+ },
212
+ base: {
213
+ "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913": {
214
+ name: "USD Coin",
215
+ symbol: "USDC",
216
+ decimals: 6,
217
+ logoUrl: "https://assets.coingecko.com/coins/images/6319/small/USD_Coin_icon.png"
218
+ },
219
+ "0x4200000000000000000000000000000000000006": {
220
+ name: "Wrapped Ether",
221
+ symbol: "WETH",
222
+ decimals: 18,
223
+ logoUrl: "https://assets.coingecko.com/coins/images/2518/small/weth.png"
224
+ }
225
+ }
226
+ };
227
+ var WarpEvmDataLoader = class {
228
+ constructor(config, chain) {
229
+ this.config = config;
230
+ this.chain = chain;
231
+ this.provider = new import_ethers.ethers.JsonRpcProvider(getEvmApiUrl(this.config.env, this.chain.name));
232
+ this.chainConfig = getEvmChainConfig(this.chain.name, this.config.env);
233
+ }
234
+ async getAccount(address) {
235
+ try {
236
+ const balance = await this.provider.getBalance(address);
237
+ return {
238
+ address,
239
+ balance
240
+ };
241
+ } catch (error) {
242
+ throw new Error(`Failed to get account balance for ${address}: ${error}`);
243
+ }
244
+ }
245
+ async getAccountAssets(address) {
246
+ try {
247
+ const assets = [];
248
+ const tokenBalances = await this.getERC20TokenBalances(address);
249
+ for (const tokenBalance of tokenBalances) {
250
+ if (tokenBalance.balance > 0n) {
251
+ assets.push({
252
+ identifier: tokenBalance.tokenAddress,
253
+ name: tokenBalance.metadata.name,
254
+ amount: tokenBalance.balance,
255
+ decimals: tokenBalance.metadata.decimals,
256
+ logoUrl: tokenBalance.metadata.logoUrl || ""
257
+ });
258
+ }
259
+ }
260
+ return assets;
261
+ } catch (error) {
262
+ throw new Error(`Failed to get account assets for ${address}: ${error}`);
263
+ }
264
+ }
265
+ async getERC20TokenBalances(address) {
266
+ const tokenBalances = [];
267
+ const knownTokens = KNOWN_TOKENS[this.chain.name] || {};
268
+ for (const [tokenAddress, metadata] of Object.entries(knownTokens)) {
269
+ try {
270
+ const balance = await this.getTokenBalance(address, tokenAddress);
271
+ if (balance > 0n) {
272
+ tokenBalances.push({
273
+ tokenAddress,
274
+ balance,
275
+ metadata
276
+ });
277
+ }
278
+ } catch (error) {
279
+ console.warn(`Failed to get balance for token ${tokenAddress}: ${error}`);
280
+ }
281
+ }
282
+ const additionalTokens = await this.detectTokensFromEvents(address);
283
+ for (const tokenAddress of additionalTokens) {
284
+ if (!knownTokens[tokenAddress]) {
285
+ try {
286
+ const metadata = await this.getTokenMetadata(tokenAddress);
287
+ const balance = await this.getTokenBalance(address, tokenAddress);
288
+ if (balance > 0n) {
289
+ tokenBalances.push({
290
+ tokenAddress,
291
+ balance,
292
+ metadata
293
+ });
294
+ }
295
+ } catch (error) {
296
+ console.warn(`Failed to get metadata/balance for detected token ${tokenAddress}: ${error}`);
297
+ }
298
+ }
299
+ }
300
+ return tokenBalances;
301
+ }
302
+ async getTokenBalance(address, tokenAddress) {
303
+ try {
304
+ const contract = new import_ethers.ethers.Contract(tokenAddress, ERC20_ABI, this.provider);
305
+ const balance = await contract.balanceOf(address);
306
+ return balance;
307
+ } catch (error) {
308
+ throw new Error(`Failed to get token balance: ${error}`);
309
+ }
310
+ }
311
+ async getTokenMetadata(tokenAddress) {
312
+ try {
313
+ const contract = new import_ethers.ethers.Contract(tokenAddress, ERC20_ABI, this.provider);
314
+ const [name, symbol, decimals] = await Promise.all([contract.name(), contract.symbol(), contract.decimals()]);
315
+ return {
316
+ name: name || "Unknown Token",
317
+ symbol: symbol || "UNKNOWN",
318
+ decimals: decimals || 18
319
+ };
320
+ } catch (error) {
321
+ throw new Error(`Failed to get token metadata: ${error}`);
322
+ }
323
+ }
324
+ async detectTokensFromEvents(address) {
325
+ try {
326
+ const currentBlock = await this.provider.getBlockNumber();
327
+ const fromBlock = Math.max(0, currentBlock - 1e4);
328
+ const filter = {
329
+ fromBlock,
330
+ toBlock: currentBlock,
331
+ topics: [
332
+ import_ethers.ethers.id("Transfer(address,address,uint256)"),
333
+ null,
334
+ // from address (any)
335
+ import_ethers.ethers.zeroPadValue(address, 32)
336
+ // to address (our target)
337
+ ]
338
+ };
339
+ const logs = await this.provider.getLogs(filter);
340
+ const tokenAddresses = /* @__PURE__ */ new Set();
341
+ for (const log of logs) {
342
+ tokenAddresses.add(log.address);
343
+ }
344
+ return Array.from(tokenAddresses);
345
+ } catch (error) {
346
+ console.warn(`Failed to detect tokens from events: ${error}`);
347
+ return [];
348
+ }
349
+ }
350
+ // Additional utility methods for enhanced token support
351
+ async getTokenInfo(tokenAddress) {
352
+ try {
353
+ return await this.getTokenMetadata(tokenAddress);
354
+ } catch (error) {
355
+ console.warn(`Failed to get token info for ${tokenAddress}: ${error}`);
356
+ return null;
357
+ }
358
+ }
359
+ async getTokenBalanceForAddress(address, tokenAddress) {
360
+ try {
361
+ return await this.getTokenBalance(address, tokenAddress);
362
+ } catch (error) {
363
+ throw new Error(`Failed to get token balance for ${tokenAddress}: ${error}`);
364
+ }
365
+ }
366
+ async getMultipleTokenBalances(address, tokenAddresses) {
367
+ const balances = /* @__PURE__ */ new Map();
368
+ await Promise.all(
369
+ tokenAddresses.map(async (tokenAddress) => {
370
+ try {
371
+ const balance = await this.getTokenBalance(address, tokenAddress);
372
+ balances.set(tokenAddress, balance);
373
+ } catch (error) {
374
+ console.warn(`Failed to get balance for token ${tokenAddress}: ${error}`);
375
+ balances.set(tokenAddress, 0n);
376
+ }
377
+ })
378
+ );
379
+ return balances;
380
+ }
381
+ };
382
+
383
+ // src/WarpEvmExecutor.ts
384
+ var import_warps3 = require("@vleap/warps");
385
+ var import_ethers3 = require("ethers");
386
+
387
+ // src/constants.ts
388
+ var WarpEvmConstants = {
389
+ GasLimit: {
390
+ Default: 21e3,
391
+ ContractCall: 1e5,
392
+ ContractDeploy: 5e5,
393
+ Transfer: 21e3,
394
+ Approve: 46e3,
395
+ Swap: 2e5
396
+ },
397
+ GasPrice: {
398
+ Default: "20000000000"
399
+ },
400
+ Validation: {
401
+ MinGasLimit: 21e3,
402
+ MaxGasLimit: 3e7
403
+ }
404
+ };
405
+ var EthereumExplorers = /* @__PURE__ */ ((EthereumExplorers2) => {
406
+ EthereumExplorers2["Etherscan"] = "etherscan";
407
+ EthereumExplorers2["EtherscanSepolia"] = "etherscan_sepolia";
408
+ EthereumExplorers2["Ethplorer"] = "ethplorer";
409
+ EthereumExplorers2["Blockscout"] = "blockscout";
410
+ EthereumExplorers2["BlockscoutSepolia"] = "blockscout_sepolia";
411
+ return EthereumExplorers2;
412
+ })(EthereumExplorers || {});
413
+ var ArbitrumExplorers = /* @__PURE__ */ ((ArbitrumExplorers2) => {
414
+ ArbitrumExplorers2["Arbiscan"] = "arbiscan";
415
+ ArbitrumExplorers2["ArbiscanSepolia"] = "arbiscan_sepolia";
416
+ ArbitrumExplorers2["BlockscoutArbitrum"] = "blockscout_arbitrum";
417
+ ArbitrumExplorers2["BlockscoutArbitrumSepolia"] = "blockscout_arbitrum_sepolia";
418
+ return ArbitrumExplorers2;
419
+ })(ArbitrumExplorers || {});
420
+ var BaseExplorers = /* @__PURE__ */ ((BaseExplorers2) => {
421
+ BaseExplorers2["Basescan"] = "basescan";
422
+ BaseExplorers2["BasescanSepolia"] = "basescan_sepolia";
423
+ BaseExplorers2["BlockscoutBase"] = "blockscout_base";
424
+ BaseExplorers2["BlockscoutBaseSepolia"] = "blockscout_base_sepolia";
425
+ return BaseExplorers2;
426
+ })(BaseExplorers || {});
427
+ var EvmExplorers = {
428
+ ethereum: {
429
+ mainnet: ["etherscan" /* Etherscan */, "ethplorer" /* Ethplorer */, "blockscout" /* Blockscout */],
430
+ testnet: ["etherscan_sepolia" /* EtherscanSepolia */, "blockscout_sepolia" /* BlockscoutSepolia */],
431
+ devnet: ["etherscan_sepolia" /* EtherscanSepolia */, "blockscout_sepolia" /* BlockscoutSepolia */]
432
+ },
433
+ arbitrum: {
434
+ mainnet: ["arbiscan" /* Arbiscan */, "blockscout_arbitrum" /* BlockscoutArbitrum */],
435
+ testnet: ["arbiscan_sepolia" /* ArbiscanSepolia */, "blockscout_arbitrum_sepolia" /* BlockscoutArbitrumSepolia */],
436
+ devnet: ["arbiscan_sepolia" /* ArbiscanSepolia */, "blockscout_arbitrum_sepolia" /* BlockscoutArbitrumSepolia */]
437
+ },
438
+ base: {
439
+ mainnet: ["basescan" /* Basescan */, "blockscout_base" /* BlockscoutBase */],
440
+ testnet: ["basescan_sepolia" /* BasescanSepolia */, "blockscout_base_sepolia" /* BlockscoutBaseSepolia */],
441
+ devnet: ["basescan_sepolia" /* BasescanSepolia */, "blockscout_base_sepolia" /* BlockscoutBaseSepolia */]
442
+ }
443
+ };
444
+ var ExplorerUrls = {
445
+ ["etherscan" /* Etherscan */]: "https://etherscan.io",
446
+ ["etherscan_sepolia" /* EtherscanSepolia */]: "https://sepolia.etherscan.io",
447
+ ["ethplorer" /* Ethplorer */]: "https://ethplorer.io",
448
+ ["blockscout" /* Blockscout */]: "https://eth.blockscout.com",
449
+ ["blockscout_sepolia" /* BlockscoutSepolia */]: "https://sepolia.blockscout.com",
450
+ ["arbiscan" /* Arbiscan */]: "https://arbiscan.io",
451
+ ["arbiscan_sepolia" /* ArbiscanSepolia */]: "https://sepolia.arbiscan.io",
452
+ ["blockscout_arbitrum" /* BlockscoutArbitrum */]: "https://arbitrum.blockscout.com",
453
+ ["blockscout_arbitrum_sepolia" /* BlockscoutArbitrumSepolia */]: "https://sepolia.blockscout.com",
454
+ ["basescan" /* Basescan */]: "https://basescan.org",
455
+ ["basescan_sepolia" /* BasescanSepolia */]: "https://sepolia.basescan.org",
456
+ ["blockscout_base" /* BlockscoutBase */]: "https://base.blockscout.com",
457
+ ["blockscout_base_sepolia" /* BlockscoutBaseSepolia */]: "https://sepolia.blockscout.com"
458
+ };
459
+
460
+ // src/WarpEvmResults.ts
461
+ var import_warps2 = require("@vleap/warps");
462
+
463
+ // src/WarpEvmSerializer.ts
464
+ var import_warps = require("@vleap/warps");
465
+ var import_ethers2 = require("ethers");
466
+ var SplitParamsRegex = new RegExp(`${import_warps.WarpConstants.ArgParamsSeparator}(.*)`);
467
+ var WarpEvmSerializer = class {
468
+ constructor() {
469
+ this.coreSerializer = new import_warps.WarpSerializer();
470
+ }
471
+ typedToString(value) {
472
+ if (typeof value === "string") {
473
+ if (import_ethers2.ethers.isAddress(value)) {
474
+ return `address:${value}`;
475
+ }
476
+ if (import_ethers2.ethers.isHexString(value) && !import_ethers2.ethers.isAddress(value)) {
477
+ return `hex:${value}`;
478
+ }
479
+ return `string:${value}`;
480
+ }
481
+ if (typeof value === "number") {
482
+ if (Number.isInteger(value)) {
483
+ if (value >= 0 && value <= 255) return `uint8:${value}`;
484
+ if (value >= 0 && value <= 65535) return `uint16:${value}`;
485
+ if (value >= 0 && value <= 4294967295) return `uint32:${value}`;
486
+ return `uint64:${value}`;
487
+ }
488
+ return `string:${value}`;
489
+ }
490
+ if (typeof value === "bigint") {
491
+ return `biguint:${value.toString()}`;
492
+ }
493
+ if (typeof value === "boolean") {
494
+ return `boolean:${value}`;
495
+ }
496
+ if (Array.isArray(value)) {
497
+ if (value.length === 0) return `list:string:`;
498
+ const types = value.map((item) => this.typedToString(item).split(import_warps.WarpConstants.ArgParamsSeparator)[0]);
499
+ const type = types[0];
500
+ const values = value.map((item) => this.typedToString(item).split(import_warps.WarpConstants.ArgParamsSeparator)[1]);
501
+ return `list:${type}:${values.join(",")}`;
502
+ }
503
+ if (value === null || value === void 0) {
504
+ return `string:null`;
505
+ }
506
+ return `string:${String(value)}`;
507
+ }
508
+ typedToNative(value) {
509
+ const stringValue = this.typedToString(value);
510
+ const [type, ...valueParts] = stringValue.split(import_warps.WarpConstants.ArgParamsSeparator);
511
+ const nativeValue = valueParts.join(import_warps.WarpConstants.ArgParamsSeparator);
512
+ return [type, this.parseNativeValue(type, nativeValue)];
513
+ }
514
+ nativeToTyped(type, value) {
515
+ switch (type) {
516
+ case "string":
517
+ return String(value);
518
+ case "uint8":
519
+ case "uint16":
520
+ case "uint32":
521
+ case "uint64":
522
+ return BigInt(value);
523
+ case "biguint":
524
+ return BigInt(value);
525
+ case "boolean":
526
+ return Boolean(value);
527
+ case "address":
528
+ return String(value);
529
+ case "hex":
530
+ return String(value);
531
+ default:
532
+ if (type.startsWith("list:")) {
533
+ const [, itemType, itemsStr] = type.split(":");
534
+ if (!itemsStr) return [];
535
+ const items = itemsStr.split(",");
536
+ return items.map((item) => this.nativeToTyped(itemType, item));
537
+ }
538
+ return String(value);
539
+ }
540
+ }
541
+ nativeToType(type) {
542
+ switch (type) {
543
+ case "string":
544
+ return "string";
545
+ case "uint8":
546
+ case "uint16":
547
+ case "uint32":
548
+ case "uint64":
549
+ case "biguint":
550
+ return "bigint";
551
+ case "boolean":
552
+ return "boolean";
553
+ case "address":
554
+ return "string";
555
+ case "hex":
556
+ return "string";
557
+ default:
558
+ return "string";
559
+ }
560
+ }
561
+ stringToTyped(value) {
562
+ const parts = value.split(import_warps.WarpConstants.ArgParamsSeparator, 2);
563
+ if (parts.length < 2) {
564
+ return value;
565
+ }
566
+ const [type, stringValue] = parts;
567
+ switch (type) {
568
+ case "string":
569
+ return stringValue;
570
+ case "uint8":
571
+ case "uint16":
572
+ case "uint32":
573
+ case "uint64":
574
+ return BigInt(stringValue);
575
+ case "biguint":
576
+ return BigInt(stringValue);
577
+ case "boolean":
578
+ return stringValue === "true";
579
+ case "address":
580
+ return stringValue;
581
+ case "hex":
582
+ return stringValue;
583
+ default:
584
+ if (type.startsWith("list:")) {
585
+ const [, itemType, itemsStr] = type.split(":");
586
+ if (!itemsStr) return [];
587
+ const items = itemsStr.split(",");
588
+ return items.map((item) => this.stringToTyped(`${itemType}:${item}`));
589
+ }
590
+ return stringValue;
591
+ }
592
+ }
593
+ parseNativeValue(type, value) {
594
+ switch (type) {
595
+ case "string":
596
+ return value;
597
+ case "uint8":
598
+ case "uint16":
599
+ case "uint32":
600
+ case "uint64":
601
+ case "biguint":
602
+ return BigInt(value);
603
+ case "boolean":
604
+ return value === "true";
605
+ case "address":
606
+ return value;
607
+ case "hex":
608
+ return value;
609
+ default:
610
+ return value;
611
+ }
612
+ }
613
+ };
614
+
615
+ // src/WarpEvmResults.ts
616
+ var WarpEvmResults = class {
617
+ constructor(config) {
618
+ this.config = config;
619
+ this.serializer = new WarpEvmSerializer();
620
+ }
621
+ async getTransactionExecutionResults(warp, tx) {
622
+ const success = tx.status === 1;
623
+ const gasUsed = tx.gasUsed?.toString() || "0";
624
+ const gasPrice = tx.gasPrice?.toString() || "0";
625
+ const blockNumber = tx.blockNumber?.toString() || "0";
626
+ const transactionHash = tx.hash;
627
+ const logs = tx.logs.map((log) => ({
628
+ address: log.address,
629
+ topics: log.topics,
630
+ data: log.data,
631
+ blockNumber: log.blockNumber?.toString() || "0",
632
+ transactionHash: log.transactionHash,
633
+ index: log.index?.toString() || "0"
634
+ }));
635
+ return {
636
+ success,
637
+ warp,
638
+ action: 0,
639
+ user: this.config.user?.wallets?.evm || null,
640
+ txHash: transactionHash,
641
+ next: null,
642
+ values: [transactionHash, blockNumber, gasUsed, gasPrice, ...logs.length > 0 ? logs : []],
643
+ results: {},
644
+ messages: {}
645
+ };
646
+ }
647
+ async extractQueryResults(warp, typedValues, actionIndex, inputs) {
648
+ const values = typedValues.map((t) => this.serializer.typedToString(t));
649
+ const valuesRaw = typedValues.map((t) => this.serializer.typedToNative(t)[1]);
650
+ let results = {};
651
+ if (!warp.results) return { values, results };
652
+ const getNestedValue = (path) => {
653
+ const indices = path.split(".").slice(1).map((i) => parseInt(i) - 1);
654
+ if (indices.length === 0) return void 0;
655
+ let value = valuesRaw[indices[0]];
656
+ for (let i = 1; i < indices.length; i++) {
657
+ if (value === void 0 || value === null) return void 0;
658
+ value = value[indices[i]];
659
+ }
660
+ return value;
661
+ };
662
+ for (const [key, path] of Object.entries(warp.results)) {
663
+ if (path.startsWith(import_warps2.WarpConstants.Transform.Prefix)) continue;
664
+ const currentActionIndex = (0, import_warps2.parseResultsOutIndex)(path);
665
+ if (currentActionIndex !== null && currentActionIndex !== actionIndex) {
666
+ results[key] = null;
667
+ continue;
668
+ }
669
+ if (path.startsWith("out.") || path === "out" || path.startsWith("out[")) {
670
+ results[key] = getNestedValue(path) || null;
671
+ } else {
672
+ results[key] = path;
673
+ }
674
+ }
675
+ return { values, results: await (0, import_warps2.evaluateResultsCommon)(warp, results, actionIndex, inputs) };
676
+ }
677
+ };
678
+
679
+ // src/WarpEvmExecutor.ts
680
+ var WarpEvmExecutor = class {
681
+ constructor(config) {
682
+ this.config = config;
683
+ this.serializer = new WarpEvmSerializer();
684
+ this.provider = new import_ethers3.ethers.JsonRpcProvider(getEvmApiUrl(config.env));
685
+ this.results = new WarpEvmResults(config);
686
+ }
687
+ async createTransaction(executable) {
688
+ const action = (0, import_warps3.getWarpActionByIndex)(executable.warp, executable.action);
689
+ let tx = null;
690
+ if (action.type === "transfer") {
691
+ tx = await this.createTransferTransaction(executable);
692
+ } else if (action.type === "contract") {
693
+ tx = await this.createContractCallTransaction(executable);
694
+ } else if (action.type === "query") {
695
+ throw new Error("WarpEvmExecutor: Invalid action type for createTransaction; Use executeQuery instead");
696
+ } else if (action.type === "collect") {
697
+ throw new Error("WarpEvmExecutor: Invalid action type for createTransaction; Use executeCollect instead");
698
+ }
699
+ if (!tx) throw new Error(`WarpEvmExecutor: Invalid action type (${action.type})`);
700
+ return tx;
701
+ }
702
+ async createTransferTransaction(executable) {
703
+ const userWallet = this.config.user?.wallets?.[executable.chain.name];
704
+ if (!userWallet) throw new Error("WarpEvmExecutor: createTransfer - user address not set");
705
+ if (!import_ethers3.ethers.isAddress(executable.destination)) {
706
+ throw new Error(`WarpEvmExecutor: Invalid destination address: ${executable.destination}`);
707
+ }
708
+ if (executable.value < 0) {
709
+ throw new Error(`WarpEvmExecutor: Transfer value cannot be negative: ${executable.value}`);
710
+ }
711
+ const tx = {
712
+ to: executable.destination,
713
+ value: executable.value,
714
+ data: executable.data ? this.serializer.stringToTyped(executable.data) : "0x"
715
+ };
716
+ return this.estimateGasAndSetDefaults(tx, userWallet);
717
+ }
718
+ async createContractCallTransaction(executable) {
719
+ const userWallet = this.config.user?.wallets?.[executable.chain.name];
720
+ if (!userWallet) throw new Error("WarpEvmExecutor: createContractCall - user address not set");
721
+ const action = (0, import_warps3.getWarpActionByIndex)(executable.warp, executable.action);
722
+ if (!action || !("func" in action) || !action.func) {
723
+ throw new Error("WarpEvmExecutor: Contract action must have a function name");
724
+ }
725
+ if (!import_ethers3.ethers.isAddress(executable.destination)) {
726
+ throw new Error(`WarpEvmExecutor: Invalid contract address: ${executable.destination}`);
727
+ }
728
+ if (executable.value < 0) {
729
+ throw new Error(`WarpEvmExecutor: Contract call value cannot be negative: ${executable.value}`);
730
+ }
731
+ try {
732
+ const iface = new import_ethers3.ethers.Interface([`function ${action.func}`]);
733
+ const encodedData = iface.encodeFunctionData(action.func, executable.args);
734
+ const tx = {
735
+ to: executable.destination,
736
+ value: executable.value,
737
+ data: encodedData
738
+ };
739
+ return this.estimateGasAndSetDefaults(tx, userWallet);
740
+ } catch (error) {
741
+ throw new Error(`WarpEvmExecutor: Failed to encode function data for ${action.func}: ${error}`);
742
+ }
743
+ }
744
+ async executeQuery(executable) {
745
+ const action = (0, import_warps3.getWarpActionByIndex)(executable.warp, executable.action);
746
+ if (action.type !== "query") {
747
+ throw new Error(`WarpEvmExecutor: Invalid action type for executeQuery: ${action.type}`);
748
+ }
749
+ if (!action.func) {
750
+ throw new Error("WarpEvmExecutor: Query action must have a function name");
751
+ }
752
+ if (!import_ethers3.ethers.isAddress(executable.destination)) {
753
+ throw new Error(`WarpEvmExecutor: Invalid contract address for query: ${executable.destination}`);
754
+ }
755
+ try {
756
+ const iface = new import_ethers3.ethers.Interface([`function ${action.func}`]);
757
+ const encodedData = iface.encodeFunctionData(action.func, executable.args);
758
+ const result = await this.provider.call({
759
+ to: executable.destination,
760
+ data: encodedData
761
+ });
762
+ const decodedResult = iface.decodeFunctionResult(action.func, result);
763
+ const isSuccess = true;
764
+ const { values, results } = await this.results.extractQueryResults(
765
+ executable.warp,
766
+ decodedResult,
767
+ executable.action,
768
+ executable.resolvedInputs
769
+ );
770
+ const next = (0, import_warps3.getNextInfo)(this.config, [], executable.warp, executable.action, results);
771
+ return {
772
+ success: isSuccess,
773
+ warp: executable.warp,
774
+ action: executable.action,
775
+ user: this.config.user?.wallets?.[executable.chain.name] || null,
776
+ txHash: null,
777
+ next,
778
+ values,
779
+ results,
780
+ messages: (0, import_warps3.applyResultsToMessages)(executable.warp, results)
781
+ };
782
+ } catch (error) {
783
+ return {
784
+ success: false,
785
+ warp: executable.warp,
786
+ action: executable.action,
787
+ user: this.config.user?.wallets?.[executable.chain.name] || null,
788
+ txHash: null,
789
+ next: null,
790
+ values: [],
791
+ results: {},
792
+ messages: {}
793
+ };
794
+ }
795
+ }
796
+ async preprocessInput(chain, input, type, value) {
797
+ const typedValue = this.serializer.stringToTyped(value);
798
+ switch (type) {
799
+ case "address":
800
+ if (!import_ethers3.ethers.isAddress(typedValue)) {
801
+ throw new Error(`Invalid address format: ${typedValue}`);
802
+ }
803
+ return import_ethers3.ethers.getAddress(typedValue);
804
+ case "hex":
805
+ if (!import_ethers3.ethers.isHexString(typedValue)) {
806
+ throw new Error(`Invalid hex format: ${typedValue}`);
807
+ }
808
+ return typedValue;
809
+ case "uint8":
810
+ case "uint16":
811
+ case "uint32":
812
+ case "uint64":
813
+ case "biguint":
814
+ const bigIntValue = BigInt(typedValue);
815
+ if (bigIntValue < 0) {
816
+ throw new Error(`Negative value not allowed for type ${type}: ${typedValue}`);
817
+ }
818
+ return bigIntValue.toString();
819
+ default:
820
+ return String(typedValue);
821
+ }
822
+ }
823
+ async estimateGasAndSetDefaults(tx, from) {
824
+ try {
825
+ const gasEstimate = await this.provider.estimateGas({
826
+ ...tx,
827
+ from
828
+ });
829
+ if (gasEstimate < BigInt(WarpEvmConstants.Validation.MinGasLimit)) {
830
+ throw new Error(`Gas estimate too low: ${gasEstimate}`);
831
+ }
832
+ if (gasEstimate > BigInt(WarpEvmConstants.Validation.MaxGasLimit)) {
833
+ throw new Error(`Gas estimate too high: ${gasEstimate}`);
834
+ }
835
+ const feeData = await this.provider.getFeeData();
836
+ if (feeData.maxFeePerGas && feeData.maxPriorityFeePerGas) {
837
+ return {
838
+ ...tx,
839
+ gasLimit: gasEstimate,
840
+ maxFeePerGas: feeData.maxFeePerGas,
841
+ maxPriorityFeePerGas: feeData.maxPriorityFeePerGas
842
+ };
843
+ } else if (feeData.gasPrice) {
844
+ return {
845
+ ...tx,
846
+ gasLimit: gasEstimate,
847
+ gasPrice: feeData.gasPrice
848
+ };
849
+ } else {
850
+ return {
851
+ ...tx,
852
+ gasLimit: gasEstimate,
853
+ gasPrice: import_ethers3.ethers.parseUnits(WarpEvmConstants.GasPrice.Default, "wei")
854
+ };
855
+ }
856
+ } catch (error) {
857
+ let defaultGasLimit = BigInt(WarpEvmConstants.GasLimit.Default);
858
+ if (tx.data && tx.data !== "0x") {
859
+ defaultGasLimit = BigInt(WarpEvmConstants.GasLimit.ContractCall);
860
+ } else {
861
+ defaultGasLimit = BigInt(WarpEvmConstants.GasLimit.Transfer);
862
+ }
863
+ return {
864
+ ...tx,
865
+ gasLimit: defaultGasLimit,
866
+ gasPrice: import_ethers3.ethers.parseUnits(WarpEvmConstants.GasPrice.Default, "wei")
867
+ };
868
+ }
869
+ }
870
+ async signMessage(message, privateKey) {
871
+ throw new Error("Not implemented");
872
+ }
873
+ };
874
+
875
+ // src/WarpEvmExplorer.ts
876
+ var WarpEvmExplorer = class {
877
+ constructor(chain, config) {
878
+ this.chain = chain;
879
+ this.config = config;
880
+ }
881
+ getExplorers() {
882
+ const chainExplorers = EvmExplorers[this.chain.name];
883
+ if (!chainExplorers) {
884
+ return ["Default"];
885
+ }
886
+ const explorers = chainExplorers[this.config.env];
887
+ if (!explorers) {
888
+ return ["Default"];
889
+ }
890
+ return explorers;
891
+ }
892
+ getPrimaryExplorer() {
893
+ const explorers = this.getExplorers();
894
+ return explorers[0];
895
+ }
896
+ getExplorerUrlByName(explorer) {
897
+ const userPreference = this.config.preferences?.explorers?.[this.chain.name];
898
+ if (userPreference && !explorer) {
899
+ const url2 = ExplorerUrls[userPreference];
900
+ if (url2) return url2;
901
+ }
902
+ if (explorer) {
903
+ const url2 = ExplorerUrls[explorer];
904
+ if (url2) return url2;
905
+ }
906
+ const primaryExplorer = this.getPrimaryExplorer();
907
+ const url = ExplorerUrls[primaryExplorer];
908
+ return url || ExplorerUrls[primaryExplorer];
909
+ }
910
+ getAccountUrl(address, explorer) {
911
+ const baseUrl = this.getExplorerUrlByName(explorer);
912
+ return `${baseUrl}/address/${address}`;
913
+ }
914
+ getTransactionUrl(hash, explorer) {
915
+ const baseUrl = this.getExplorerUrlByName(explorer);
916
+ return `${baseUrl}/tx/${hash}`;
917
+ }
918
+ getBlockUrl(blockNumber, explorer) {
919
+ const baseUrl = this.getExplorerUrlByName(explorer);
920
+ return `${baseUrl}/block/${blockNumber}`;
921
+ }
922
+ getAssetUrl(identifier, explorer) {
923
+ const baseUrl = this.getExplorerUrlByName(explorer);
924
+ return `${baseUrl}/token/${identifier}`;
925
+ }
926
+ getContractUrl(address, explorer) {
927
+ const baseUrl = this.getExplorerUrlByName(explorer);
928
+ return `${baseUrl}/address/${address}`;
929
+ }
930
+ getAllExplorers() {
931
+ return this.getExplorers();
932
+ }
933
+ getExplorerByName(name) {
934
+ const explorers = this.getExplorers();
935
+ return explorers.find((explorer) => explorer.toLowerCase() === name.toLowerCase());
936
+ }
937
+ getAccountUrls(address) {
938
+ const explorers = this.getAllExplorers();
939
+ const urls = {};
940
+ explorers.forEach((explorer) => {
941
+ const url = ExplorerUrls[explorer];
942
+ if (url) {
943
+ urls[explorer] = `${url}/address/${address}`;
944
+ }
945
+ });
946
+ return urls;
947
+ }
948
+ getTransactionUrls(hash) {
949
+ const explorers = this.getAllExplorers();
950
+ const urls = {};
951
+ explorers.forEach((explorer) => {
952
+ const url = ExplorerUrls[explorer];
953
+ if (url) {
954
+ urls[explorer] = `${url}/tx/${hash}`;
955
+ }
956
+ });
957
+ return urls;
958
+ }
959
+ };
960
+
961
+ // src/chains/common.ts
962
+ var createEvmAdapter = (chainName, chainPrefix, chainInfos) => {
963
+ return (config, fallback) => {
964
+ if (!fallback) throw new Error(`${chainName} adapter requires a fallback adapter`);
965
+ return {
966
+ chain: chainName,
967
+ chainInfo: chainInfos[config.env],
968
+ prefix: chainPrefix,
969
+ builder: () => fallback.builder(),
970
+ executor: new WarpEvmExecutor(config),
971
+ results: new WarpEvmResults(config),
972
+ serializer: new WarpEvmSerializer(),
973
+ registry: fallback.registry,
974
+ explorer: new WarpEvmExplorer(chainInfos[config.env], config),
975
+ abiBuilder: () => fallback.abiBuilder(),
976
+ brandBuilder: () => fallback.brandBuilder(),
977
+ dataLoader: new WarpEvmDataLoader(config, chainInfos[config.env])
978
+ };
979
+ };
980
+ };
981
+
982
+ // src/chains/arbitrum.ts
983
+ var ChainNameArbitrum = "arbitrum";
984
+ var getArbitrumAdapter = createEvmAdapter(ChainNameArbitrum, "arb", {
985
+ devnet: {
986
+ name: ChainNameArbitrum,
987
+ displayName: "Arbitrum Devnet",
988
+ chainId: "421614",
989
+ blockTime: 1e3,
990
+ addressHrp: "0x",
991
+ apiUrl: "https://sepolia-rollup.arbitrum.io/rpc",
992
+ nativeToken: "ETH"
993
+ },
994
+ testnet: {
995
+ name: ChainNameArbitrum,
996
+ displayName: "Arbitrum Testnet",
997
+ chainId: "421613",
998
+ blockTime: 1e3,
999
+ addressHrp: "0x",
1000
+ apiUrl: "https://goerli-rollup.arbitrum.io/rpc",
1001
+ nativeToken: "ETH"
1002
+ },
1003
+ mainnet: {
1004
+ name: ChainNameArbitrum,
1005
+ displayName: "Arbitrum",
1006
+ chainId: "42161",
1007
+ blockTime: 1e3,
1008
+ addressHrp: "0x",
1009
+ apiUrl: "https://arb1.arbitrum.io/rpc",
1010
+ nativeToken: "ETH"
1011
+ }
1012
+ });
1013
+
1014
+ // src/chains/base.ts
1015
+ var ChainNameBase = "base";
1016
+ var getBaseAdapter = createEvmAdapter(ChainNameBase, "base", {
1017
+ mainnet: {
1018
+ name: ChainNameBase,
1019
+ displayName: "Base",
1020
+ chainId: "8453",
1021
+ blockTime: 2e3,
1022
+ addressHrp: "0x",
1023
+ apiUrl: "https://mainnet.base.org",
1024
+ nativeToken: "ETH"
1025
+ },
1026
+ testnet: {
1027
+ name: ChainNameBase,
1028
+ displayName: "Base Testnet",
1029
+ chainId: "84531",
1030
+ blockTime: 2e3,
1031
+ addressHrp: "0x",
1032
+ apiUrl: "https://goerli.base.org",
1033
+ nativeToken: "ETH"
1034
+ },
1035
+ devnet: {
1036
+ name: ChainNameBase,
1037
+ displayName: "Base Devnet",
1038
+ chainId: "84532",
1039
+ blockTime: 2e3,
1040
+ addressHrp: "0x",
1041
+ apiUrl: "https://sepolia.base.org",
1042
+ nativeToken: "ETH"
1043
+ }
1044
+ });
1045
+
1046
+ // src/chains/ethereum.ts
1047
+ var ChainNameEthereum = "ethereum";
1048
+ var getEthereumAdapter = createEvmAdapter(ChainNameEthereum, "eth", {
1049
+ devnet: {
1050
+ name: ChainNameEthereum,
1051
+ displayName: "Ethereum Devnet",
1052
+ chainId: "11155111",
1053
+ blockTime: 12e3,
1054
+ addressHrp: "0x",
1055
+ apiUrl: "https://eth-sepolia.g.alchemy.com/v2/YOUR_API_KEY",
1056
+ nativeToken: "ETH"
1057
+ },
1058
+ testnet: {
1059
+ name: ChainNameEthereum,
1060
+ displayName: "Ethereum Testnet",
1061
+ chainId: "5",
1062
+ blockTime: 12e3,
1063
+ addressHrp: "0x",
1064
+ apiUrl: "https://eth-goerli.g.alchemy.com/v2/YOUR_API_KEY",
1065
+ nativeToken: "ETH"
1066
+ },
1067
+ mainnet: {
1068
+ name: ChainNameEthereum,
1069
+ displayName: "Ethereum Mainnet",
1070
+ chainId: "1",
1071
+ blockTime: 12e3,
1072
+ addressHrp: "0x",
1073
+ apiUrl: "https://eth-mainnet.g.alchemy.com/v2/YOUR_API_KEY",
1074
+ nativeToken: "ETH"
1075
+ }
1076
+ });
1077
+
1078
+ // src/chains/combined.ts
1079
+ var getAllEvmAdapters = (config, fallback) => [
1080
+ getEthereumAdapter(config, fallback),
1081
+ getArbitrumAdapter(config, fallback),
1082
+ getBaseAdapter(config, fallback)
1083
+ ];
1084
+ var getAllEvmChainNames = () => [ChainNameArbitrum, ChainNameBase, ChainNameEthereum];
1085
+ // Annotate the CommonJS export names for ESM import in node:
1086
+ 0 && (module.exports = {
1087
+ ArbitrumExplorers,
1088
+ BaseExplorers,
1089
+ ChainNameArbitrum,
1090
+ ChainNameBase,
1091
+ ChainNameEthereum,
1092
+ EVM_CHAIN_CONFIGS,
1093
+ EthereumExplorers,
1094
+ EvmExplorers,
1095
+ ExplorerUrls,
1096
+ WarpEvmConstants,
1097
+ WarpEvmExecutor,
1098
+ WarpEvmExplorer,
1099
+ WarpEvmResults,
1100
+ WarpEvmSerializer,
1101
+ getAllEvmAdapters,
1102
+ getAllEvmChainNames,
1103
+ getArbitrumAdapter,
1104
+ getBaseAdapter,
1105
+ getEthereumAdapter,
1106
+ getEvmApiUrl,
1107
+ getEvmChainConfig,
1108
+ getEvmExplorerUrl
1109
+ });
1110
+ //# sourceMappingURL=index.js.map