-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
47f18ed
commit 7f7e812
Showing
18 changed files
with
230 additions
and
272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 0 additions & 45 deletions
45
dex_screener/handlers/hydradx/stableswap/on_buy_executed.py
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
dex_screener/handlers/hydradx/stableswap/on_pool_created.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from dipdup.context import HandlerContext | ||
from dipdup.models.substrate import SubstrateEvent | ||
|
||
from dex_screener.service.dex.stableswap.stableswap_service import StableSwapService | ||
from dex_screener.types.hydradx.substrate_events.stableswap_pool_created import StableswapPoolCreatedPayload | ||
|
||
|
||
async def on_pool_created( | ||
ctx: HandlerContext, | ||
event: SubstrateEvent[StableswapPoolCreatedPayload], | ||
) -> None: | ||
pool = await StableSwapService.register_pool(event) | ||
await StableSwapService.register_pair(pool, event) |
45 changes: 0 additions & 45 deletions
45
dex_screener/handlers/hydradx/stableswap/on_sell_executed.py
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
DEX_PULL_ACCOUNT_MAPPING: dict[int, str] = { | ||
100: '0x22bb00df7706a5965728b60f96406ee59ce675fd5fd10652a4ed6f618856ccfe', | ||
101: '0xaffeef2e0ccac1986d8ac3b557e1e0d682d649bf61aee81e1a7faaab7eae35e0', | ||
102: '0x7fe7d370617e793b178de6efc9bc5813382f2e2866ee298ea1917d8b8dce436b', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from __future__ import annotations | ||
|
||
import logging | ||
from itertools import combinations | ||
from typing import TYPE_CHECKING | ||
|
||
from dex_screener.models import Asset | ||
from dex_screener.models import DexKey | ||
from dex_screener.models import Pair | ||
from dex_screener.models import Pool | ||
from dex_screener.models.dto import DexScreenerEventInfoDTO | ||
from dex_screener.service.dex.stableswap.const import DEX_PULL_ACCOUNT_MAPPING | ||
|
||
if TYPE_CHECKING: | ||
from dipdup.models.substrate import SubstrateEvent | ||
|
||
from dex_screener.types.hydradx.substrate_events.stableswap_pool_created import StableswapPoolCreatedPayload | ||
|
||
|
||
class StableSwapService: | ||
logger = logging.getLogger('stableswap_service') | ||
|
||
@classmethod | ||
def get_pair_id(cls, pool_account: str, asset_a_id: int, asset_b_id: int) -> str: | ||
asset_id_list = [str(asset_id) for asset_id in sorted([int(asset_a_id), int(asset_b_id)])] | ||
|
||
return '-'.join([pool_account, *asset_id_list]) | ||
|
||
@classmethod | ||
async def register_pool(cls, event: SubstrateEvent[StableswapPoolCreatedPayload]): | ||
dex_pool_id = event.payload['pool_id'] | ||
account = DEX_PULL_ACCOUNT_MAPPING[int(dex_pool_id)] | ||
pool = await Pool.create( | ||
dex_key=DexKey.StableSwap, | ||
dex_pool_id=dex_pool_id, | ||
account=account, | ||
) | ||
cls.logger.info('StableSwap Pool registered: %r.', pool) | ||
|
||
return pool | ||
|
||
@classmethod | ||
async def register_pair(cls, pool: Pool, event: SubstrateEvent[StableswapPoolCreatedPayload]): | ||
|
||
for asset_a_id, asset_b_id in combinations(event.payload['assets'], 2): | ||
pair_id = cls.get_pair_id(pool.account, asset_a_id, asset_b_id) | ||
|
||
event_info = DexScreenerEventInfoDTO.from_event(event) | ||
|
||
pair = await Pair.create( | ||
id=pair_id, | ||
dex_key=DexKey.StableSwap, | ||
asset_0_id=min(asset_a_id, asset_b_id), | ||
asset_1_id=max(asset_a_id, asset_b_id), | ||
pool=pool, | ||
created_at_block_id=event_info.block_id, | ||
created_at_txn_id=event_info.tx_id, | ||
fee_bps=event.payload['fee'], | ||
) | ||
cls.logger.info('Pair registered in pool %r: %r.', pool, pair) | ||
pool_assets: list[Asset] = await Asset.filter(id__in=event.payload['assets']) | ||
await pool.assets.add(*pool_assets) | ||
cls.logger.info('Assets added to pool %r: %s.', pool, pool_assets) |
Oops, something went wrong.