@vleap/warps-adapter-evm 0.2.0-alpha.6 → 0.2.0-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +7 -3
- package/dist/index.d.ts +7 -3
- package/dist/index.js +282 -39
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +278 -39
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/README.md +0 -400
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
|