Skip to content

Commit

Permalink
Move Uniswap Demo
Browse files Browse the repository at this point in the history
  • Loading branch information
igorsereda committed Jun 10, 2024
1 parent c7a0108 commit 2a4dbec
Show file tree
Hide file tree
Showing 82 changed files with 70 additions and 70 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from contextlib import suppress
from typing import cast

from demo_uniswap import models as models
from demo_uniswap.models.token import WHITELIST_TOKENS
from demo_uniswap.models.token import ERC20Token
from demo_uniswap.types.factory.evm_events.pool_created import PoolCreated
from demo_evm_uniswap import models as models
from demo_evm_uniswap.models.token import WHITELIST_TOKENS
from demo_evm_uniswap.models.token import ERC20Token
from demo_evm_uniswap.types.factory.evm_events.pool_created import PoolCreated
from dipdup.config.evm import EvmContractConfig
from dipdup.context import HandlerContext
from dipdup.models.evm_subsquid import SubsquidEvent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from demo_uniswap import models
from demo_uniswap.models.pool import PoolUpdateSign
from demo_uniswap.models.pool import pool_update
from demo_uniswap.types.pool.evm_events.burn import Burn
from demo_evm_uniswap import models
from demo_evm_uniswap.models.pool import PoolUpdateSign
from demo_evm_uniswap.models.pool import pool_update
from demo_evm_uniswap.types.pool.evm_events.burn import Burn
from dipdup.context import HandlerContext
from dipdup.models.evm_subsquid import SubsquidEvent

Expand All @@ -13,4 +13,4 @@ async def burn(
pool = await models.Pool.cached_get_or_none(event.data.address)
if not pool:
return
await pool_update(ctx, pool, event, PoolUpdateSign.BURN)
await pool_update(ctx, pool, event, PoolUpdateSign.BURN)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from demo_uniswap import models as models
from demo_uniswap.types.pool.evm_events.flash import Flash
from demo_evm_uniswap import models as models
from demo_evm_uniswap.types.pool.evm_events.flash import Flash
from dipdup.context import HandlerContext
from dipdup.models.evm_subsquid import SubsquidEvent

Expand All @@ -8,4 +8,4 @@ async def flash(
ctx: HandlerContext,
event: SubsquidEvent[Flash],
) -> None:
...
...
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from decimal import Decimal

from demo_uniswap import models
from demo_uniswap.models.token import token_derive_eth
from demo_uniswap.types.pool.evm_events.initialize import Initialize
from demo_evm_uniswap import models
from demo_evm_uniswap.models.token import token_derive_eth
from demo_evm_uniswap.types.pool.evm_events.initialize import Initialize
from dipdup.context import HandlerContext
from dipdup.models.evm_subsquid import SubsquidEvent

Expand All @@ -23,4 +23,4 @@ async def initialize(
token0.derived_eth = await token_derive_eth(token0)
token1.derived_eth = await token_derive_eth(token1)
await token0.save()
await token1.save()
await token1.save()
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from demo_uniswap import models
from demo_uniswap.models.pool import PoolUpdateSign
from demo_uniswap.models.pool import pool_update
from demo_uniswap.models.repo import models_repo
from demo_uniswap.types.pool.evm_events.mint import Mint
from demo_evm_uniswap import models
from demo_evm_uniswap.models.pool import PoolUpdateSign
from demo_evm_uniswap.models.pool import pool_update
from demo_evm_uniswap.models.repo import models_repo
from demo_evm_uniswap.types.pool.evm_events.mint import Mint
from dipdup.context import HandlerContext
from dipdup.models.evm_subsquid import SubsquidEvent
from eth_utils.address import to_normalized_address
Expand Down Expand Up @@ -30,4 +30,4 @@ async def mint(
'tick_upper_id': f'{pool.id}#{event.payload.tickUpper}',
}
position_idx = f'{event.data.level}.{event.data.transaction_index}.{int(event.data.log_index) + 1}'
models_repo.save_pending_position(position_idx, pending_position)
models_repo.save_pending_position(position_idx, pending_position)
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from decimal import Decimal

from demo_uniswap import models as models
from demo_uniswap.models.repo import USDC_WETH_03_POOL
from demo_uniswap.models.repo import get_ctx_factory
from demo_uniswap.models.repo import models_repo
from demo_uniswap.models.token import WHITELIST_TOKENS
from demo_uniswap.models.token import convert_token_amount
from demo_uniswap.models.token import token_derive_eth
from demo_uniswap.types.pool.evm_events.swap import Swap
from demo_evm_uniswap import models as models
from demo_evm_uniswap.models.repo import USDC_WETH_03_POOL
from demo_evm_uniswap.models.repo import get_ctx_factory
from demo_evm_uniswap.models.repo import models_repo
from demo_evm_uniswap.models.token import WHITELIST_TOKENS
from demo_evm_uniswap.models.token import convert_token_amount
from demo_evm_uniswap.models.token import token_derive_eth
from demo_evm_uniswap.types.pool.evm_events.swap import Swap
from dipdup.context import HandlerContext
from dipdup.models.evm_subsquid import SubsquidEvent

Expand Down Expand Up @@ -167,4 +167,4 @@ async def swap(
await factory.save()
await pool.save()
await token0.save()
await token1.save()
await token1.save()
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from demo_uniswap import models
from demo_uniswap.models.position import save_position_snapshot
from demo_uniswap.models.token import convert_token_amount
from demo_uniswap.types.position_manager.evm_events.collect import Collect
from demo_evm_uniswap import models
from demo_evm_uniswap.models.position import save_position_snapshot
from demo_evm_uniswap.models.token import convert_token_amount
from demo_evm_uniswap.types.position_manager.evm_events.collect import Collect
from dipdup.context import HandlerContext
from dipdup.models.evm_subsquid import SubsquidEvent

Expand Down Expand Up @@ -30,4 +30,4 @@ async def collect(

await position.save()
# position.cache()
await save_position_snapshot(position, event.data.level, event.data.timestamp)
await save_position_snapshot(position, event.data.level, event.data.timestamp)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from demo_uniswap import models
from demo_uniswap.models.position import save_position_snapshot
from demo_uniswap.models.token import convert_token_amount
from demo_uniswap.types.position_manager.evm_events.decrease_liquidity import DecreaseLiquidity
from demo_evm_uniswap import models
from demo_evm_uniswap.models.position import save_position_snapshot
from demo_evm_uniswap.models.token import convert_token_amount
from demo_evm_uniswap.types.position_manager.evm_events.decrease_liquidity import DecreaseLiquidity
from dipdup.context import HandlerContext
from dipdup.models.evm_subsquid import SubsquidEvent

Expand Down Expand Up @@ -33,4 +33,4 @@ async def decrease_liquidity(

await position.save()
# position.cache()
await save_position_snapshot(position, event.data.level, event.data.timestamp)
await save_position_snapshot(position, event.data.level, event.data.timestamp)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from demo_uniswap import models
from demo_uniswap.models.position import save_position_snapshot
from demo_uniswap.models.token import convert_token_amount
from demo_uniswap.types.position_manager.evm_events.increase_liquidity import IncreaseLiquidity
from demo_evm_uniswap import models
from demo_evm_uniswap.models.position import save_position_snapshot
from demo_evm_uniswap.models.token import convert_token_amount
from demo_evm_uniswap.types.position_manager.evm_events.increase_liquidity import IncreaseLiquidity
from dipdup.context import HandlerContext
from dipdup.models.evm_subsquid import SubsquidEvent

Expand Down Expand Up @@ -35,4 +35,4 @@ async def increase_liquidity(
position.deposited_token1 += amount1

await position.save()
await save_position_snapshot(position, event.data.level, event.data.timestamp)
await save_position_snapshot(position, event.data.level, event.data.timestamp)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import demo_uniswap.models as models
from demo_uniswap.models.position import save_position_snapshot
from demo_uniswap.models.repo import models_repo
from demo_uniswap.types.position_manager.evm_events.transfer import Transfer
import demo_evm_uniswap.models as models
from demo_evm_uniswap.models.position import save_position_snapshot
from demo_evm_uniswap.models.repo import models_repo
from demo_evm_uniswap.types.position_manager.evm_events.transfer import Transfer
from dipdup.context import HandlerContext
from dipdup.models.evm_subsquid import SubsquidEvent
from eth_utils.address import to_normalized_address
Expand All @@ -28,4 +28,4 @@ async def transfer(

position.owner = to_normalized_address(event.payload.to)
await position.save()
await save_position_snapshot(position, event.data.level, event.data.timestamp)
await save_position_snapshot(position, event.data.level, event.data.timestamp)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from dipdup.context import HandlerContext
from dipdup.models.evm_subsquid import SubsquidEvent

from demo_uniswap import models
from demo_uniswap.models.repo import get_ctx_factory
from demo_uniswap.models.repo import models_repo
from demo_uniswap.models.tick import tick_get_or_create
from demo_uniswap.models.token import convert_token_amount
from demo_uniswap.types.pool.evm_events.burn import Burn
from demo_uniswap.types.pool.evm_events.mint import Mint
from demo_evm_uniswap import models
from demo_evm_uniswap.models.repo import get_ctx_factory
from demo_evm_uniswap.models.repo import models_repo
from demo_evm_uniswap.models.tick import tick_get_or_create
from demo_evm_uniswap.models.token import convert_token_amount
from demo_evm_uniswap.types.pool.evm_events.burn import Burn
from demo_evm_uniswap.types.pool.evm_events.mint import Mint


class PoolUpdateSign:
Expand Down Expand Up @@ -99,4 +99,4 @@ async def pool_update(
upper_tick = await tick_get_or_create(event.payload.tickUpper, pool, event.data.level, event.data.timestamp)
upper_tick.liquidity_gross = upper_tick.liquidity_gross + sign * event.payload.amount
upper_tick.liquidity_net = upper_tick.liquidity_net - sign * event.payload.amount
await upper_tick.save()
await upper_tick.save()
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from eth_utils.address import to_checksum_address
from eth_utils.address import to_normalized_address

import demo_uniswap.models as models
from demo_uniswap.models.abi import get_abi
import demo_evm_uniswap.models as models
from demo_evm_uniswap.models.abi import get_abi


async def position_validate(
Expand Down Expand Up @@ -68,4 +68,4 @@ async def save_position_snapshot(position: models.Position, level: int, timestam
snapshot.withdrawn_token1 = position.withdrawn_token1
snapshot.collected_fees_token0 = position.collected_fees_token0
snapshot.collected_fees_token1 = position.collected_fees_token1
await snapshot.save()
await snapshot.save()
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from dipdup.context import HandlerContext
from lru import LRU

import demo_uniswap.models as models
import demo_evm_uniswap.models as models

USDC_WETH_03_POOL = '0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8'

Expand Down Expand Up @@ -42,4 +42,4 @@ async def get_ctx_factory(ctx: HandlerContext) -> models.Factory:
return await models.Factory.cached_get(factory_address)


models_repo = ModelsRepo()
models_repo = ModelsRepo()
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from decimal import Decimal

from demo_uniswap import models as models
from demo_evm_uniswap import models as models


async def tick_get_or_create(tick_idx: int, pool: models.Pool, level: int, timestamp: int) -> models.Tick:
Expand All @@ -15,4 +15,4 @@ async def tick_get_or_create(tick_idx: int, pool: models.Pool, level: int, times
'price1': 1 / Decimal('1.0001') ** tick_idx,
},
)
return tick
return tick
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from eth_utils.address import to_checksum_address
from web3 import AsyncWeb3

from demo_uniswap import models as models
from demo_uniswap.models.abi import get_abi
from demo_uniswap.models.repo import models_repo
from demo_evm_uniswap import models as models
from demo_evm_uniswap.models.abi import get_abi
from demo_evm_uniswap.models.repo import models_repo

MINIMUM_ETH_LOCKED = Decimal('60')
STABLE_COINS = {
Expand Down Expand Up @@ -178,4 +178,4 @@ async def token_derive_eth(token: models.Token) -> Decimal:
largest_liquidity_eth = eth_locked
price_so_far = pool.token0_price * other_token.derived_eth

return price_so_far
return price_so_far
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 2a4dbec

Please sign in to comment.