evm-amm-state 0.2.0

EVM-backed AMM state loading, cache synchronization, and pool simulation models
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
//! Runtime-bytecode seed artifacts for AMM pool contracts.
//!
//! `evm-fork-cache` calls this operation "seeding" when the bytecode is a
//! canonical on-chain claim to be verified: the plain functions here return
//! `seed_account_code` inputs, not local-divergence `etch_account_code` inputs.

use std::fmt;
use std::sync::LazyLock;

use alloy_primitives::{Address, B256, Bytes, U256};
use revm::state::Bytecode;

use super::types::V3Metadata;

const UNISWAP_V3_MIN_TICK: i32 = -887272;
const UNISWAP_V3_MAX_TICK: i32 = 887272;

const UNISWAP_V2_PAIR_RUNTIME_BYTES: &[u8] =
    include_bytes!("bytecodes/uniswap_v2_pair_runtime.bin");
const UNISWAP_V3_POOL_TEMPLATE_BYTES: &[u8] =
    include_bytes!("bytecodes/uniswap_v3_pool_template.bin");

static UNISWAP_V2_PAIR_RUNTIME: LazyLock<Bytes> =
    LazyLock::new(|| Bytes::from_static(UNISWAP_V2_PAIR_RUNTIME_BYTES));
static UNISWAP_V2_PAIR_RUNTIME_CODE_HASH: LazyLock<B256> =
    LazyLock::new(|| runtime_code_hash(&UNISWAP_V2_PAIR_RUNTIME));
static UNISWAP_V3_POOL_TEMPLATE: LazyLock<V3RuntimeBytecodeTemplate> = LazyLock::new(|| {
    V3RuntimeBytecodeTemplate::new(
        Bytes::from_static(UNISWAP_V3_POOL_TEMPLATE_BYTES),
        UNISWAP_V3_IMMUTABLE_PATCHES,
    )
});

// The byte offsets below are the immutable-word locations in the canonical
// mainnet Uniswap V3 pool runtime build (the `UNISWAP_V3_POOL_TEMPLATE_BYTES`
// artifact with those words zeroed). `tests/bytecode_golden.rs` pins them to
// chain-truth `EXTCODEHASH` values across three tickSpacings / two token pairs,
// so a wrong offset cannot pass by coincidence. If the compiler build ever
// changes, regenerate them by diffing two deployed pools' runtime bytecode.
const V3_POOL_ADDRESS_PATCHES: [BytecodePatch; 1] = [BytecodePatch::new(11259, 32)];
const V3_FACTORY_PATCHES: [BytecodePatch; 3] = [
    BytecodePatch::new(8315, 32),
    BytecodePatch::new(8829, 32),
    BytecodePatch::new(10457, 32),
];
const V3_TOKEN0_PATCHES: [BytecodePatch; 6] = [
    BytecodePatch::new(2258, 32),
    BytecodePatch::new(4853, 32),
    BytecodePatch::new(6740, 32),
    BytecodePatch::new(7822, 32),
    BytecodePatch::new(9150, 32),
    BytecodePatch::new(15650, 32),
];
const V3_TOKEN1_PATCHES: [BytecodePatch; 6] = [
    BytecodePatch::new(4551, 32),
    BytecodePatch::new(6789, 32),
    BytecodePatch::new(7924, 32),
    BytecodePatch::new(9284, 32),
    BytecodePatch::new(10529, 32),
    BytecodePatch::new(15979, 32),
];
const V3_FEE_PATCHES: [BytecodePatch; 4] = [
    BytecodePatch::new(3311, 32),
    BytecodePatch::new(6603, 32),
    BytecodePatch::new(6658, 32),
    BytecodePatch::new(10565, 32),
];
const V3_TICK_SPACING_PATCHES: [BytecodePatch; 4] = [
    BytecodePatch::new(3072, 32),
    BytecodePatch::new(10493, 32),
    BytecodePatch::new(19402, 32),
    BytecodePatch::new(19452, 32),
];
const V3_MAX_LIQUIDITY_PER_TICK_PATCHES: [BytecodePatch; 3] = [
    BytecodePatch::new(8174, 32),
    BytecodePatch::new(19295, 32),
    BytecodePatch::new(19350, 32),
];
const UNISWAP_V3_IMMUTABLE_PATCHES: V3ImmutablePatches = V3ImmutablePatches {
    pool_address: &V3_POOL_ADDRESS_PATCHES,
    factory: &V3_FACTORY_PATCHES,
    token0: &V3_TOKEN0_PATCHES,
    token1: &V3_TOKEN1_PATCHES,
    fee: &V3_FEE_PATCHES,
    tick_spacing: &V3_TICK_SPACING_PATCHES,
    max_liquidity_per_tick: &V3_MAX_LIQUIDITY_PER_TICK_PATCHES,
};

/// Runtime bytecode to seed for one on-chain account before cold-start.
///
/// `#[non_exhaustive]`: Construct via [`AdapterCodeSeed::new`] or
/// [`AdapterCodeSeed::with_code_hash`].
#[non_exhaustive]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct AdapterCodeSeed {
    /// Account whose canonical runtime bytecode is being seeded.
    pub address: Address,
    /// Expected deployed runtime bytecode for [`address`](Self::address).
    pub runtime_bytecode: Bytes,
    /// Keccak256 hash of [`runtime_bytecode`](Self::runtime_bytecode).
    pub code_hash: B256,
}

impl AdapterCodeSeed {
    /// A seed for `address`, computing the code hash from `runtime_bytecode`.
    pub fn new(address: Address, runtime_bytecode: impl Into<Bytes>) -> Self {
        let runtime_bytecode = runtime_bytecode.into();
        let code_hash = runtime_code_hash(&runtime_bytecode);
        Self {
            address,
            runtime_bytecode,
            code_hash,
        }
    }

    /// A seed with a precomputed `code_hash` (skips re-hashing the bytecode).
    pub fn with_code_hash(
        address: Address,
        runtime_bytecode: impl Into<Bytes>,
        code_hash: B256,
    ) -> Self {
        Self {
            address,
            runtime_bytecode: runtime_bytecode.into(),
            code_hash,
        }
    }
}

/// Canonical runtime-bytecode seed for a Uniswap V2 pair at `address`.
///
/// All V2 pairs share one runtime (the immutables live in storage, not code),
/// so the seed is the embedded pair runtime plus its precomputed code hash —
/// no per-pool metadata is needed.
pub fn uniswap_v2_pair_code_seed(address: Address) -> AdapterCodeSeed {
    AdapterCodeSeed::with_code_hash(
        address,
        uniswap_v2_pair_runtime_bytecode(),
        uniswap_v2_pair_runtime_code_hash(),
    )
}

/// Render a canonical Uniswap V3 pool runtime-bytecode seed for `address` from
/// its [`V3Metadata`], if the metadata carries enough immutables to derive it.
///
/// Returns `Ok(None)` when `factory` / `token0` / `token1` / `fee` /
/// `tick_spacing` (falling back to the `storage_layout` tick spacing) are not
/// all known — such a pool is simply not seedable, not an error. Returns
/// `Err(BytecodeTemplateError)` only if rendering the template itself fails.
pub fn v3_code_seed_from_metadata(
    address: Address,
    metadata: &V3Metadata,
) -> Result<Option<AdapterCodeSeed>, BytecodeTemplateError> {
    let Some(factory) = metadata.factory else {
        return Ok(None);
    };
    let Some(token0) = metadata.token0 else {
        return Ok(None);
    };
    let Some(token1) = metadata.token1 else {
        return Ok(None);
    };
    let Some(fee) = metadata.fee else {
        return Ok(None);
    };
    let Some(tick_spacing) = metadata
        .tick_spacing
        .or_else(|| metadata.storage_layout.map(|layout| layout.tick_spacing))
    else {
        return Ok(None);
    };
    uniswap_v3_code_seed(
        address,
        &V3ImmutablePatchValues {
            pool_address: Some(address),
            factory: Some(factory),
            token0: Some(token0),
            token1: Some(token1),
            fee: Some(fee),
            tick_spacing: Some(tick_spacing),
            max_liquidity_per_tick: uniswap_v3_max_liquidity_per_tick(tick_spacing),
        },
    )
    .map(Some)
}

/// Render a Uniswap V3 runtime bytecode seed from explicit immutable values.
pub fn uniswap_v3_code_seed(
    address: Address,
    values: &V3ImmutablePatchValues,
) -> Result<AdapterCodeSeed, BytecodeTemplateError> {
    let runtime = uniswap_v3_pool_template().render(values)?;
    Ok(AdapterCodeSeed::new(address, runtime))
}

/// Embedded canonical Uniswap V2 pair runtime bytecode.
pub fn uniswap_v2_pair_runtime_bytecode() -> Bytes {
    UNISWAP_V2_PAIR_RUNTIME.clone()
}

/// Keccak256 hash of the embedded canonical Uniswap V2 pair runtime bytecode.
pub fn uniswap_v2_pair_runtime_code_hash() -> B256 {
    *UNISWAP_V2_PAIR_RUNTIME_CODE_HASH
}

/// Embedded Uniswap V3 pool runtime template with immutable words zeroed.
pub fn uniswap_v3_pool_template() -> V3RuntimeBytecodeTemplate {
    UNISWAP_V3_POOL_TEMPLATE.clone()
}

/// The Uniswap V3 `Tick.tickSpacingToMaxLiquidityPerTick` formula.
pub fn uniswap_v3_max_liquidity_per_tick(tick_spacing: i32) -> Option<U256> {
    if tick_spacing <= 0 {
        return None;
    }
    let tick_spacing = tick_spacing as i128;
    let min_tick = (UNISWAP_V3_MIN_TICK as i128 / tick_spacing) * tick_spacing;
    let max_tick = (UNISWAP_V3_MAX_TICK as i128 / tick_spacing) * tick_spacing;
    let tick_count = ((max_tick - min_tick) / tick_spacing) + 1;
    if tick_count <= 0 {
        return None;
    }
    Some(U256::from(u128::MAX) / U256::from(tick_count as u128))
}

fn runtime_code_hash(runtime_bytecode: &Bytes) -> B256 {
    Bytecode::new_raw(runtime_bytecode.clone()).hash_slow()
}

/// A byte range in deployed runtime bytecode occupied by one immutable value.
///
/// `#[non_exhaustive]`: Construct via [`BytecodePatch::new`] (`const`, so `static` patch tables
/// keep working).
#[non_exhaustive]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct BytecodePatch {
    /// Byte offset into the runtime bytecode.
    pub offset: usize,
    /// Number of bytes occupied by the immutable value.
    pub length: usize,
}

impl BytecodePatch {
    /// A patch covering `length` bytes at `offset` in the runtime bytecode.
    pub const fn new(offset: usize, length: usize) -> Self {
        Self { offset, length }
    }
}

/// Immutable byte ranges for a V3-style pool runtime template.
///
/// Each field lists the byte ranges in the template occupied by that Solidity
/// immutable, patched per-pool at render time.
///
/// `#[non_exhaustive]`: Construct via `Default` plus the `with_*` builders.
#[non_exhaustive]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct V3ImmutablePatches {
    /// Ranges holding the pool's own address (`NoDelegateCall` self-address).
    pub pool_address: &'static [BytecodePatch],
    /// Ranges holding the factory/deployer address.
    pub factory: &'static [BytecodePatch],
    /// Ranges holding `token0`.
    pub token0: &'static [BytecodePatch],
    /// Ranges holding `token1`.
    pub token1: &'static [BytecodePatch],
    /// Ranges holding the fee.
    pub fee: &'static [BytecodePatch],
    /// Ranges holding the tick spacing.
    pub tick_spacing: &'static [BytecodePatch],
    /// Ranges holding `maxLiquidityPerTick`.
    pub max_liquidity_per_tick: &'static [BytecodePatch],
}

impl V3ImmutablePatches {
    /// Set the pool-address patch ranges.
    pub fn with_pool_address(mut self, patches: &'static [BytecodePatch]) -> Self {
        self.pool_address = patches;
        self
    }

    /// Set the factory patch ranges.
    pub fn with_factory(mut self, patches: &'static [BytecodePatch]) -> Self {
        self.factory = patches;
        self
    }

    /// Set the `token0` patch ranges.
    pub fn with_token0(mut self, patches: &'static [BytecodePatch]) -> Self {
        self.token0 = patches;
        self
    }

    /// Set the `token1` patch ranges.
    pub fn with_token1(mut self, patches: &'static [BytecodePatch]) -> Self {
        self.token1 = patches;
        self
    }

    /// Set the fee patch ranges.
    pub fn with_fee(mut self, patches: &'static [BytecodePatch]) -> Self {
        self.fee = patches;
        self
    }

    /// Set the tick-spacing patch ranges.
    pub fn with_tick_spacing(mut self, patches: &'static [BytecodePatch]) -> Self {
        self.tick_spacing = patches;
        self
    }

    /// Set the `maxLiquidityPerTick` patch ranges.
    pub fn with_max_liquidity_per_tick(mut self, patches: &'static [BytecodePatch]) -> Self {
        self.max_liquidity_per_tick = patches;
        self
    }
}

/// A V3-style pool runtime template plus immutable patch locations.
///
/// `#[non_exhaustive]`: Construct via [`V3RuntimeBytecodeTemplate::new`].
#[non_exhaustive]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct V3RuntimeBytecodeTemplate {
    /// Deployed runtime bytecode before per-pool immutable replacement.
    pub runtime_bytecode: Bytes,
    /// Byte ranges to replace with per-pool immutable values.
    pub immutables: V3ImmutablePatches,
}

impl V3RuntimeBytecodeTemplate {
    /// A template from `runtime_bytecode` and its immutable patch locations.
    pub fn new(runtime_bytecode: impl Into<Bytes>, immutables: V3ImmutablePatches) -> Self {
        Self {
            runtime_bytecode: runtime_bytecode.into(),
            immutables,
        }
    }

    /// Render the expected deployed bytecode for one pool by patching immutable
    /// values into the template.
    pub fn render(&self, values: &V3ImmutablePatchValues) -> Result<Bytes, BytecodeTemplateError> {
        let mut bytecode = self.runtime_bytecode.to_vec();

        patch_optional_address(
            &mut bytecode,
            "pool_address",
            self.immutables.pool_address,
            values.pool_address,
        )?;
        patch_optional_address(
            &mut bytecode,
            "factory",
            self.immutables.factory,
            values.factory,
        )?;
        patch_optional_address(
            &mut bytecode,
            "token0",
            self.immutables.token0,
            values.token0,
        )?;
        patch_optional_address(
            &mut bytecode,
            "token1",
            self.immutables.token1,
            values.token1,
        )?;
        patch_optional_u32(&mut bytecode, "fee", self.immutables.fee, values.fee)?;
        patch_optional_i32(
            &mut bytecode,
            "tick_spacing",
            self.immutables.tick_spacing,
            values.tick_spacing,
        )?;
        patch_optional_u256(
            &mut bytecode,
            "max_liquidity_per_tick",
            self.immutables.max_liquidity_per_tick,
            values.max_liquidity_per_tick,
        )?;

        Ok(Bytes::from(bytecode))
    }
}

/// Per-pool immutable values used to render a V3 runtime bytecode template.
///
/// `#[non_exhaustive]`: Construct via `Default` plus the `with_*` builders (fields stay `pub`
/// for direct assignment).
#[non_exhaustive]
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct V3ImmutablePatchValues {
    /// The pool's own address.
    pub pool_address: Option<Address>,
    /// The factory/deployer address.
    pub factory: Option<Address>,
    /// The pool's `token0`.
    pub token0: Option<Address>,
    /// The pool's `token1`.
    pub token1: Option<Address>,
    /// The pool fee.
    pub fee: Option<u32>,
    /// The pool's tick spacing.
    pub tick_spacing: Option<i32>,
    /// The pool's `maxLiquidityPerTick`.
    pub max_liquidity_per_tick: Option<U256>,
}

impl V3ImmutablePatchValues {
    /// Set the pool's own address.
    pub fn with_pool_address(mut self, pool_address: Address) -> Self {
        self.pool_address = Some(pool_address);
        self
    }

    /// Set the factory/deployer address.
    pub fn with_factory(mut self, factory: Address) -> Self {
        self.factory = Some(factory);
        self
    }

    /// Set `token0`.
    pub fn with_token0(mut self, token0: Address) -> Self {
        self.token0 = Some(token0);
        self
    }

    /// Set `token1`.
    pub fn with_token1(mut self, token1: Address) -> Self {
        self.token1 = Some(token1);
        self
    }

    /// Set the pool fee.
    pub fn with_fee(mut self, fee: u32) -> Self {
        self.fee = Some(fee);
        self
    }

    /// Set the tick spacing.
    pub fn with_tick_spacing(mut self, tick_spacing: i32) -> Self {
        self.tick_spacing = Some(tick_spacing);
        self
    }

    /// Set `maxLiquidityPerTick`.
    pub fn with_max_liquidity_per_tick(mut self, max_liquidity_per_tick: U256) -> Self {
        self.max_liquidity_per_tick = Some(max_liquidity_per_tick);
        self
    }
}

/// Why rendering a V3 runtime bytecode template failed.
///
/// `#[non_exhaustive]` — an open error vocabulary.
#[non_exhaustive]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum BytecodeTemplateError {
    /// A patch range was declared for `field` but no value was supplied.
    MissingImmutable {
        /// The immutable whose value was missing.
        field: &'static str,
    },
    /// A patch range's `length` cannot hold the immutable's encoded value.
    InvalidPatchLength {
        /// The immutable being patched.
        field: &'static str,
        /// The declared patch length that is too small.
        length: usize,
    },
    /// A patch range falls outside the template bytecode.
    PatchOutOfBounds {
        /// The immutable being patched.
        field: &'static str,
        /// The patch's byte offset.
        offset: usize,
        /// The patch's byte length.
        length: usize,
        /// The template bytecode's length.
        bytecode_len: usize,
    },
}

impl fmt::Display for BytecodeTemplateError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::MissingImmutable { field } => {
                write!(f, "missing V3 bytecode immutable `{field}`")
            }
            Self::InvalidPatchLength { field, length } => {
                write!(
                    f,
                    "invalid V3 bytecode patch length for `{field}`: {length}"
                )
            }
            Self::PatchOutOfBounds {
                field,
                offset,
                length,
                bytecode_len,
            } => write!(
                f,
                "V3 bytecode patch for `{field}` is out of bounds: offset {offset}, length {length}, bytecode length {bytecode_len}"
            ),
        }
    }
}

impl std::error::Error for BytecodeTemplateError {}

fn patch_optional_address(
    bytecode: &mut [u8],
    field: &'static str,
    patches: &[BytecodePatch],
    value: Option<Address>,
) -> Result<(), BytecodeTemplateError> {
    if patches.is_empty() {
        return Ok(());
    }
    let value = value.ok_or(BytecodeTemplateError::MissingImmutable { field })?;
    let mut word = [0u8; 32];
    word[12..].copy_from_slice(value.as_slice());
    patch_word(bytecode, field, patches, word)
}

fn patch_optional_u32(
    bytecode: &mut [u8],
    field: &'static str,
    patches: &[BytecodePatch],
    value: Option<u32>,
) -> Result<(), BytecodeTemplateError> {
    if patches.is_empty() {
        return Ok(());
    }
    let value = value.ok_or(BytecodeTemplateError::MissingImmutable { field })?;
    patch_word(
        bytecode,
        field,
        patches,
        U256::from(value).to_be_bytes::<32>(),
    )
}

fn patch_optional_i32(
    bytecode: &mut [u8],
    field: &'static str,
    patches: &[BytecodePatch],
    value: Option<i32>,
) -> Result<(), BytecodeTemplateError> {
    if patches.is_empty() {
        return Ok(());
    }
    let value = value.ok_or(BytecodeTemplateError::MissingImmutable { field })?;
    let mut word = if value < 0 { [0xFF; 32] } else { [0u8; 32] };
    word[28..].copy_from_slice(&value.to_be_bytes());
    patch_word(bytecode, field, patches, word)
}

fn patch_optional_u256(
    bytecode: &mut [u8],
    field: &'static str,
    patches: &[BytecodePatch],
    value: Option<U256>,
) -> Result<(), BytecodeTemplateError> {
    if patches.is_empty() {
        return Ok(());
    }
    let value = value.ok_or(BytecodeTemplateError::MissingImmutable { field })?;
    patch_word(bytecode, field, patches, value.to_be_bytes::<32>())
}

fn patch_word(
    bytecode: &mut [u8],
    field: &'static str,
    patches: &[BytecodePatch],
    word: [u8; 32],
) -> Result<(), BytecodeTemplateError> {
    for patch in patches {
        if patch.length == 0 || patch.length > 32 {
            return Err(BytecodeTemplateError::InvalidPatchLength {
                field,
                length: patch.length,
            });
        }
        let end = patch.offset.checked_add(patch.length).ok_or(
            BytecodeTemplateError::PatchOutOfBounds {
                field,
                offset: patch.offset,
                length: patch.length,
                bytecode_len: bytecode.len(),
            },
        )?;
        if end > bytecode.len() {
            return Err(BytecodeTemplateError::PatchOutOfBounds {
                field,
                offset: patch.offset,
                length: patch.length,
                bytecode_len: bytecode.len(),
            });
        }

        let src = 32 - patch.length;
        bytecode[patch.offset..end].copy_from_slice(&word[src..]);
    }
    Ok(())
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn computes_uniswap_v3_max_liquidity_per_tick() {
        assert_eq!(
            uniswap_v3_max_liquidity_per_tick(10),
            Some(U256::from(1917569901783203986719870431555990_u128))
        );
        assert_eq!(
            uniswap_v3_max_liquidity_per_tick(60),
            Some(U256::from(11505743598341114571880798222544994_u128))
        );
        assert_eq!(uniswap_v3_max_liquidity_per_tick(0), None);
    }

    #[test]
    fn embedded_artifacts_decode() {
        assert_eq!(uniswap_v2_pair_runtime_bytecode().len(), 11293);
        assert_eq!(uniswap_v3_pool_template().runtime_bytecode.len(), 22142);
    }
}