Skip to content

Commit

Permalink
Merge pull request #654 from bancorprotocol/bancor-pol-events
Browse files Browse the repository at this point in the history
feat: collect bancor_pol events from block 0
  • Loading branch information
platonfloria authored May 18, 2024
2 parents adeece8 + 59c43a2 commit f1e0e06
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
9 changes: 8 additions & 1 deletion fastlane_bot/events/event_gatherer.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ def __init__(
self._subscriptions.append(sub)

def get_all_events(self, from_block: int, to_block: int):
results = asyncio.get_event_loop().run_until_complete(asyncio.gather(*[self._get_events_for_topic(from_block, to_block, sub) for sub in self._subscriptions]))
coroutines = []
for sub in self._subscriptions:
if sub.collect_all:
from_block_ = 0
else:
from_block_ = from_block
coroutines.append(self._get_events_for_topic(from_block_, to_block, sub))
results = asyncio.get_event_loop().run_until_complete(asyncio.gather(*coroutines))
return list(chain.from_iterable(results))

async def _get_events_for_topic(self, from_block: int, to_block: int, subscription: Subscription):
Expand Down
4 changes: 2 additions & 2 deletions fastlane_bot/events/exchanges/bancor_pol.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ def get_events(self, contract: Contract) -> List[Type[Contract]]:

def get_subscriptions(self, contract: Contract) -> List[Subscription]:
return [
Subscription(contract.events.TokenTraded),
Subscription(contract.events.TradingEnabled, "0xae3f48c001771f8e9868e24d47b9e4295b06b1d78072acf96f167074aa3fab64"),
Subscription(contract.events.TokenTraded, collect_all=True),
Subscription(contract.events.TradingEnabled, "0xae3f48c001771f8e9868e24d47b9e4295b06b1d78072acf96f167074aa3fab64", collect_all=True),
]

async def get_fee(self, address: str, contract: Contract) -> Tuple[str, float]:
Expand Down
7 changes: 6 additions & 1 deletion fastlane_bot/events/interfaces/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ def _get_event_topic(event):


class Subscription:
def __init__(self, event: ContractEvent, topic: Optional[str] = None):
def __init__(self, event: ContractEvent, topic: Optional[str] = None, collect_all: bool = False):
self._event = event
self._topic = _get_event_topic(event) if topic is None else topic
self._collect_all = collect_all
self._subscription_id = None
self._latest_event_index = (-1, -1) # (block_number, block_index)

Expand All @@ -30,6 +31,10 @@ def subscription_id(self):
@property
def topic(self):
return self._topic

@property
def collect_all(self):
return self._collect_all

def parse_log(self, log) -> Event:
try:
Expand Down

0 comments on commit f1e0e06

Please sign in to comment.