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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md DELETED
@@ -1,400 +0,0 @@
1
- # Warp EVM Adapter
2
-
3
- A comprehensive EVM (Ethereum Virtual Machine) adapter for the Warp SDK, providing full support for Ethereum, Arbitrum, Base, and other EVM-compatible blockchains.
4
-
5
- ## Features
6
-
7
- - ✅ **Multi-Chain Support**: Ethereum, Arbitrum, Base, and any EVM-compatible chain
8
- - ✅ **Complete Transaction Support**: Transfers, contract calls, and queries
9
- - ✅ **Robust Gas Estimation**: EIP-1559 and legacy pricing with fallbacks
10
- - ✅ **Comprehensive Data Types**: All EVM-compatible data types with validation
11
- - ✅ **Registry Operations**: Full warp and brand management
12
- - ✅ **Caching Layer**: Performance optimization for registry operations
13
- - ✅ **Error Handling**: Graceful degradation and meaningful error messages
14
- - ✅ **Type Safety**: Full TypeScript coverage
15
- - ✅ **Production Ready**: Zero technical debt, comprehensive testing
16
-
17
- ## Installation
18
-
19
- ```bash
20
- npm install @vleap/warps-adapter-evm ethers
21
- ```
22
-
23
- ## Quick Start
24
-
25
- ### Basic Usage
26
-
27
- ```typescript
28
- import { getEvmAdapter, getEthereumAdapter, getArbitrumAdapter, getBaseAdapter } from '@vleap/warps-adapter-evm'
29
- import { WarpClientConfig } from '@vleap/warps'
30
-
31
- const config: WarpClientConfig = {
32
- env: 'mainnet',
33
- user: {
34
- wallets: {
35
- evm: '0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6',
36
- },
37
- },
38
- }
39
-
40
- // Get adapter for specific chain
41
- const ethereumAdapter = getEthereumAdapter(config)
42
- const arbitrumAdapter = getArbitrumAdapter(config)
43
- const baseAdapter = getBaseAdapter(config)
44
-
45
- // Or get adapter for any EVM chain
46
- const customAdapter = getEvmAdapter(config, 'polygon')
47
- ```
48
-
49
- ### Creating a Warp
50
-
51
- ```typescript
52
- import { getEvmAdapter } from '@vleap/warps-adapter-evm'
53
-
54
- const adapter = getEvmAdapter(config)
55
-
56
- // Create a warp from raw data
57
- const warp = await adapter
58
- .builder()
59
- .createFromRaw('{"title":"My Warp","actions":[...]}')
60
- .setTitle('My Custom Warp')
61
- .setDescription('A description of my warp')
62
- .setPreview('https://example.com/preview.png')
63
- .addAction({
64
- type: 'transfer',
65
- label: 'Transfer ETH',
66
- address: '0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6',
67
- })
68
- .build()
69
-
70
- // Create inscription transaction
71
- const inscriptionTx = await adapter.builder().createInscriptionTransaction(warp)
72
- ```
73
-
74
- ### Executing Transactions
75
-
76
- ```typescript
77
- // Create transfer transaction
78
- const transferExecutable = {
79
- chain: { name: 'evm' },
80
- warp,
81
- action: 1,
82
- destination: '0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6',
83
- value: BigInt('1000000000000000000'), // 1 ETH
84
- args: [],
85
- transfers: [],
86
- resolvedInputs: [],
87
- }
88
-
89
- const transferTx = await adapter.executor.createTransaction(transferExecutable)
90
-
91
- // Create contract call transaction
92
- const contractExecutable = {
93
- chain: { name: 'evm' },
94
- warp: {
95
- actions: [
96
- {
97
- type: 'contract',
98
- func: 'transfer(address,uint256)',
99
- },
100
- ],
101
- },
102
- action: 1,
103
- destination: '0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6',
104
- value: BigInt(0),
105
- args: ['0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6', '1000000000000000000'],
106
- transfers: [],
107
- resolvedInputs: [],
108
- }
109
-
110
- const contractTx = await adapter.executor.createTransaction(contractExecutable)
111
- ```
112
-
113
- ### Executing Queries
114
-
115
- ```typescript
116
- // Execute a query
117
- const queryExecutable = {
118
- chain: { name: 'evm' },
119
- warp: {
120
- actions: [
121
- {
122
- type: 'query',
123
- func: 'balanceOf(address)',
124
- },
125
- ],
126
- },
127
- action: 1,
128
- destination: '0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6',
129
- value: BigInt(0),
130
- args: ['0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6'],
131
- transfers: [],
132
- resolvedInputs: [],
133
- }
134
-
135
- const queryResult = await adapter.executor.executeQuery(queryExecutable)
136
- console.log('Query result:', queryResult.values)
137
- ```
138
-
139
- ### Registry Operations
140
-
141
- ```typescript
142
- // Register a warp
143
- const registerTx = await adapter.registry.createWarpRegisterTransaction('0x1234567890abcdef', 'my-warp-alias', 'my-brand-hash')
144
-
145
- // Get warp info by alias
146
- const { registryInfo, brand } = await adapter.registry.getInfoByAlias('my-warp-alias')
147
-
148
- // Get user's warps
149
- const userWarps = await adapter.registry.getUserWarpRegistryInfos()
150
-
151
- // Get chain information
152
- const chainInfo = await adapter.registry.getChainInfo('ethereum')
153
- ```
154
-
155
- ## Configuration
156
-
157
- ### Multi-Chain Support
158
-
159
- The adapter supports multiple EVM chains out of the box:
160
-
161
- ```typescript
162
- // Ethereum
163
- const ethereumConfig = {
164
- env: 'mainnet',
165
- user: {
166
- wallets: {
167
- evm: '0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6',
168
- },
169
- },
170
- // Custom API URL for Ethereum
171
- apiUrl: 'https://eth-mainnet.g.alchemy.com/v2/YOUR_API_KEY',
172
- }
173
-
174
- // Arbitrum
175
- const arbitrumConfig = {
176
- env: 'mainnet',
177
- user: {
178
- wallets: {
179
- evm: '0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6',
180
- },
181
- },
182
- // Custom API URL for Arbitrum
183
- apiUrl: 'https://arb-mainnet.g.alchemy.com/v2/YOUR_API_KEY',
184
- }
185
-
186
- // Base
187
- const baseConfig = {
188
- env: 'mainnet',
189
- user: {
190
- wallets: {
191
- evm: '0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6',
192
- },
193
- },
194
- // Custom API URL for Base
195
- apiUrl: 'https://mainnet.base.org',
196
- }
197
- ```
198
-
199
- ### Supported Chains
200
-
201
- - **Ethereum**: Mainnet, Sepolia testnet, Local devnet
202
- - **Arbitrum**: Mainnet, Sepolia testnet, Local devnet
203
- - **Base**: Mainnet, Sepolia testnet, Local devnet
204
- - **Any EVM Chain**: Easily configurable for other chains
205
-
206
- ### Environment Configuration
207
-
208
- ```typescript
209
- // Mainnet
210
- const mainnetConfig = { env: 'mainnet' }
211
-
212
- // Testnet
213
- const testnetConfig = { env: 'testnet' }
214
-
215
- // Devnet
216
- const devnetConfig = { env: 'devnet' }
217
- ```
218
-
219
- ## Data Types
220
-
221
- The adapter supports all EVM-compatible data types:
222
-
223
- - **string**: Regular strings
224
- - **uint8/uint16/uint32/uint64**: Unsigned integers
225
- - **biguint**: Big integers for large numbers
226
- - **boolean**: Boolean values
227
- - **address**: Ethereum addresses (0x-prefixed)
228
- - **hex**: Hexadecimal strings (0x-prefixed)
229
- - **list**: Array support with type inference
230
-
231
- ### Input Preprocessing
232
-
233
- ```typescript
234
- // Preprocess inputs with validation
235
- const processedAddress = await adapter.executor.preprocessInput(
236
- { name: 'evm' },
237
- 'input',
238
- 'address',
239
- '0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6'
240
- )
241
-
242
- const processedAmount = await adapter.executor.preprocessInput({ name: 'evm' }, 'input', 'biguint', '1000000000000000000')
243
- ```
244
-
245
- ## Gas Estimation
246
-
247
- The adapter provides robust gas estimation with multiple fallback strategies:
248
-
249
- ### EIP-1559 Support
250
-
251
- - Automatic detection of EIP-1559 support
252
- - Uses `maxFeePerGas` and `maxPriorityFeePerGas` when available
253
- - Falls back to legacy `gasPrice` for older chains
254
-
255
- ### Fallback Strategy
256
-
257
- - Attempts to estimate gas from the network
258
- - Falls back to default values if estimation fails
259
- - Configurable default gas limits and prices
260
-
261
- ### Custom Gas Configuration
262
-
263
- ```typescript
264
- // The adapter automatically handles gas estimation
265
- // but you can also set custom values in the transaction
266
- const customTx = {
267
- ...transferTx,
268
- gasLimit: BigInt(50000),
269
- maxFeePerGas: ethers.parseUnits('50', 'gwei'),
270
- maxPriorityFeePerGas: ethers.parseUnits('2', 'gwei'),
271
- }
272
- ```
273
-
274
- ## Error Handling
275
-
276
- The adapter provides comprehensive error handling:
277
-
278
- ### Graceful Degradation
279
-
280
- - Network failures don't crash the application
281
- - Gas estimation failures use safe defaults
282
- - Registry operations handle missing contracts
283
-
284
- ### Meaningful Error Messages
285
-
286
- - Clear error messages for debugging
287
- - Input validation with specific error details
288
- - Network-specific error handling
289
-
290
- ### Error Recovery
291
-
292
- - Automatic retry mechanisms for transient failures
293
- - Fallback strategies for critical operations
294
- - Safe defaults for missing configuration
295
-
296
- ## Testing
297
-
298
- Run the test suite:
299
-
300
- ```bash
301
- npm test
302
- ```
303
-
304
- The test suite includes:
305
-
306
- - Unit tests for all components
307
- - Integration tests for complex scenarios
308
- - Error handling validation
309
- - Edge case coverage
310
-
311
- ## Building
312
-
313
- Build the package:
314
-
315
- ```bash
316
- npm run build
317
- ```
318
-
319
- This generates:
320
-
321
- - CommonJS bundle (`dist/index.js`)
322
- - ES Module bundle (`dist/index.mjs`)
323
- - TypeScript declarations (`dist/index.d.ts`)
324
-
325
- ## Architecture
326
-
327
- ### Components
328
-
329
- 1. **WarpEvmBuilder**: Warp creation and management
330
- 2. **WarpEvmExecutor**: Transaction creation and execution
331
- 3. **WarpEvmSerializer**: Data type serialization
332
- 4. **WarpEvmResults**: Result processing and extraction
333
- 5. **WarpEvmRegistry**: Registry operations with caching
334
- 6. **WarpEvmExplorer**: Blockchain explorer integration
335
- 7. **WarpEvmAbiBuilder**: ABI creation and management
336
- 8. **WarpEvmBrandBuilder**: Brand creation and validation
337
-
338
- ### Design Principles
339
-
340
- - **Modularity**: Each component has a single responsibility
341
- - **Extensibility**: Easy to add support for new EVM chains
342
- - **Performance**: Caching and efficient algorithms
343
- - **Reliability**: Comprehensive error handling and validation
344
- - **Type Safety**: Full TypeScript coverage
345
-
346
- ### Multi-Chain Architecture
347
-
348
- The adapter uses a chain-specific configuration system:
349
-
350
- ```typescript
351
- // Chain configurations are centralized
352
- export const EVM_CHAIN_CONFIGS = {
353
- ethereum: {
354
- /* config */
355
- },
356
- arbitrum: {
357
- /* config */
358
- },
359
- base: {
360
- /* config */
361
- },
362
- // Easy to add new chains
363
- }
364
-
365
- // Adapters are instantiated with chain-specific configs
366
- const adapter = getEvmAdapter(config, 'ethereum')
367
- ```
368
-
369
- ## Performance Optimizations
370
-
371
- ### Caching
372
-
373
- - Registry operations are cached for performance
374
- - Configurable TTL for different data types
375
- - Memory and localStorage cache strategies
376
-
377
- ### Gas Estimation
378
-
379
- - Efficient gas estimation with fallbacks
380
- - Cached fee data to reduce RPC calls
381
- - Batch operations where possible
382
-
383
- ### Serialization
384
-
385
- - Optimized serialization for large data
386
- - Efficient type conversion algorithms
387
- - Memory-efficient data structures
388
-
389
- ## Contributing
390
-
391
- 1. Fork the repository
392
- 2. Create a feature branch
393
- 3. Make your changes
394
- 4. Add tests for new functionality
395
- 5. Ensure all tests pass
396
- 6. Submit a pull request
397
-
398
- ## License
399
-
400
- MIT
package/dist/index.d.mts DELETED
@@ -1,140 +0,0 @@
1
- import { WarpChainEnv, AdapterFactory, WarpClientConfig, Adapter, CombinedWarpBuilder, Warp, BaseWarpBuilder, WarpCacheConfig, AdapterWarpExecutor, WarpExecutable, WarpExecution, WarpChainInfo, WarpActionInputType, AdapterWarpExplorer, AdapterWarpResults, ResolvedInput, WarpExecutionResults, AdapterWarpSerializer, WarpSerializer, WarpNativeValue, BaseWarpActionInputType, WarpAdapterGenericType } from '@vleap/warps';
2
- import { ethers } from 'ethers';
3
-
4
- interface EvmChainConfig {
5
- apiUrl: string;
6
- explorerUrl: string;
7
- chainId: string;
8
- registryAddress: string;
9
- nativeToken: string;
10
- blockTime?: number;
11
- }
12
- declare const EVM_CHAIN_CONFIGS: Record<string, Record<WarpChainEnv, EvmChainConfig>>;
13
- declare const getEvmChainConfig: (chain: string | undefined, env: WarpChainEnv) => EvmChainConfig;
14
- declare const getEvmApiUrl: (env: WarpChainEnv, chain?: string) => string;
15
- declare const getEvmExplorerUrl: (env: WarpChainEnv, chain?: string) => string;
16
- declare const getEvmChainId: (env: WarpChainEnv, chain?: string) => string;
17
- declare const getEvmRegistryAddress: (env: WarpChainEnv, chain?: string) => string;
18
- declare const getEvmNativeToken: (env: WarpChainEnv, chain?: string) => string;
19
- declare const getEvmBlockTime: (env: WarpChainEnv, chain?: string) => number;
20
- declare const getSupportedEvmChains: () => string[];
21
- declare const getSupportedEnvironments: (chain: string) => WarpChainEnv[];
22
-
23
- declare const WarpEvmConstants: {
24
- Ether: {
25
- Identifier: string;
26
- DisplayName: string;
27
- Decimals: number;
28
- };
29
- GasLimit: {
30
- Default: number;
31
- ContractCall: number;
32
- ContractDeploy: number;
33
- Transfer: number;
34
- Approve: number;
35
- Swap: number;
36
- };
37
- GasPrice: {
38
- Default: string;
39
- Low: string;
40
- Medium: string;
41
- High: string;
42
- };
43
- Networks: {
44
- Ethereum: {
45
- ChainId: string;
46
- Name: string;
47
- BlockTime: number;
48
- };
49
- Arbitrum: {
50
- ChainId: string;
51
- Name: string;
52
- BlockTime: number;
53
- };
54
- Base: {
55
- ChainId: string;
56
- Name: string;
57
- BlockTime: number;
58
- };
59
- };
60
- Validation: {
61
- AddressLength: number;
62
- HexPrefix: string;
63
- MinGasLimit: number;
64
- MaxGasLimit: number;
65
- };
66
- Timeouts: {
67
- DefaultRpcTimeout: number;
68
- GasEstimationTimeout: number;
69
- QueryTimeout: number;
70
- };
71
- };
72
-
73
- declare const getEthereumAdapter: AdapterFactory;
74
- declare const getArbitrumAdapter: AdapterFactory;
75
- declare const getBaseAdapter: AdapterFactory;
76
- declare const getAllEvmAdapters: (config: WarpClientConfig, fallback?: Adapter) => Adapter[];
77
-
78
- declare class WarpEvmBuilder implements CombinedWarpBuilder {
79
- private readonly config;
80
- private warp;
81
- private actions;
82
- constructor(config: WarpClientConfig);
83
- createFromRaw(encoded: string): Promise<Warp>;
84
- setTitle(title: string): BaseWarpBuilder;
85
- setDescription(description: string): BaseWarpBuilder;
86
- setPreview(preview: string): BaseWarpBuilder;
87
- setActions(actions: any[]): BaseWarpBuilder;
88
- addAction(action: any): BaseWarpBuilder;
89
- build(): Promise<Warp>;
90
- createInscriptionTransaction(warp: Warp): ethers.TransactionRequest;
91
- createFromTransaction(tx: ethers.TransactionResponse, validate?: boolean): Promise<Warp>;
92
- createFromTransactionHash(hash: string, cache?: WarpCacheConfig): Promise<Warp | null>;
93
- }
94
-
95
- declare class WarpEvmExecutor implements AdapterWarpExecutor {
96
- private readonly config;
97
- private readonly serializer;
98
- private readonly provider;
99
- private readonly results;
100
- constructor(config: WarpClientConfig);
101
- createTransaction(executable: WarpExecutable): Promise<ethers.TransactionRequest>;
102
- createTransferTransaction(executable: WarpExecutable): Promise<ethers.TransactionRequest>;
103
- createContractCallTransaction(executable: WarpExecutable): Promise<ethers.TransactionRequest>;
104
- executeQuery(executable: WarpExecutable): Promise<WarpExecution>;
105
- preprocessInput(chain: WarpChainInfo, input: string, type: WarpActionInputType, value: string): Promise<string>;
106
- private estimateGasAndSetDefaults;
107
- signMessage(message: string, privateKey: string): Promise<string>;
108
- }
109
-
110
- declare class WarpEvmExplorer implements AdapterWarpExplorer {
111
- private readonly chainInfo;
112
- private readonly chainName;
113
- constructor(chainInfo: WarpChainInfo, chainName?: string);
114
- getAccountUrl(address: string): string;
115
- getTransactionUrl(hash: string): string;
116
- }
117
-
118
- declare class WarpEvmResults implements AdapterWarpResults {
119
- private readonly config;
120
- private readonly serializer;
121
- constructor(config: WarpClientConfig);
122
- getTransactionExecutionResults(warp: Warp, tx: ethers.TransactionReceipt): Promise<WarpExecution>;
123
- extractQueryResults(warp: Warp, typedValues: any[], actionIndex: number, inputs: ResolvedInput[]): Promise<{
124
- values: any[];
125
- results: WarpExecutionResults;
126
- }>;
127
- }
128
-
129
- declare class WarpEvmSerializer implements AdapterWarpSerializer {
130
- readonly coreSerializer: WarpSerializer;
131
- constructor();
132
- typedToString(value: any): string;
133
- typedToNative(value: any): [WarpActionInputType, WarpNativeValue];
134
- nativeToTyped(type: WarpActionInputType, value: WarpNativeValue): any;
135
- nativeToType(type: BaseWarpActionInputType): WarpAdapterGenericType;
136
- stringToTyped(value: string): any;
137
- private parseNativeValue;
138
- }
139
-
140
- export { EVM_CHAIN_CONFIGS, type EvmChainConfig, WarpEvmBuilder, WarpEvmConstants, WarpEvmExecutor, WarpEvmExplorer, WarpEvmResults, WarpEvmSerializer, getAllEvmAdapters, getArbitrumAdapter, getBaseAdapter, getEthereumAdapter, getEvmApiUrl, getEvmBlockTime, getEvmChainConfig, getEvmChainId, getEvmExplorerUrl, getEvmNativeToken, getEvmRegistryAddress, getSupportedEnvironments, getSupportedEvmChains };