-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DRAFT: Add websocket usage #582
Draft
platonfloria
wants to merge
16
commits into
add_sei
Choose a base branch
from
add-websocket-usage
base: add_sei
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
b316ecf
Add event handler
Lesigh-3100 5b3035f
wip: improved subscription logic
platonfloria ae312fd
Update docstrings & typing
Lesigh-3100 b700611
feat: EventListener implementation
platonfloria 6137d12
feat: generate topics from abi
platonfloria 8c6de4e
feat: yield events in batches
platonfloria 778b609
Update network.py
Lesigh-3100 0d1c40c
chore: refactor to use Event dataclass
platonfloria 7244fd7
Update bancor_v3.py
Lesigh-3100 9b8c99b
chore: update gitignore
platonfloria acd9af7
Move async_handle_initial_iteration outside main loop
Lesigh-3100 7cfd444
feat: move event listener outside of the main loop
platonfloria 2e74f1e
feat: reconnect websocket
platonfloria 1881024
fix: exchange subscription filter
platonfloria dbdf2ab
fix: websocket reconnect
platonfloria 377fecf
chore: add debug logging
platonfloria File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,3 +73,5 @@ logs/* | |
missing_tokens_df.csv | ||
tokens_and_fee_df.csv | ||
fastlane_bot/tests/nbtest/* | ||
|
||
.python-version |
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
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 |
---|---|---|
|
@@ -14,11 +14,14 @@ | |
from dataclasses import dataclass | ||
from typing import List, Type, Tuple, Any | ||
|
||
from web3 import AsyncWeb3 | ||
from web3.contract import Contract, AsyncContract | ||
|
||
from fastlane_bot.data.abi import BANCOR_V2_CONVERTER_ABI | ||
from fastlane_bot.events.exchanges.base import Exchange | ||
from fastlane_bot.events.pools.base import Pool | ||
from ..exchanges.base import Exchange | ||
from ..pools.base import Pool | ||
from ..interfaces.event import Event | ||
from ..interfaces.subscription import Subscription | ||
|
||
|
||
@dataclass | ||
|
@@ -44,6 +47,9 @@ def get_factory_abi(self): | |
def get_events(self, contract: Contract) -> List[Type[Contract]]: | ||
return [contract.events.TokenRateUpdate] | ||
|
||
def get_subscriptions(self, contract: Contract) -> List[Subscription]: | ||
return [Subscription(contract.events.TokenRateUpdate)] | ||
|
||
# def async convert_address(self, address: str, contract: Contract) -> str: | ||
# return | ||
|
||
|
@@ -59,15 +65,15 @@ async def get_fee(self, address: str, contract: AsyncContract) -> Tuple[str, flo | |
fee_float = float(fee) / 1e6 | ||
return fee, fee_float | ||
|
||
async def get_tkn0(self, address: str, contract: Contract, event: Any) -> str: | ||
async def get_tkn0(self, address: str, contract: Contract, event: Event) -> str: | ||
if event: | ||
return event["args"]["_token1"] | ||
return await contract.caller.reserveTokens()[0] | ||
return event.args["_token1"] | ||
return await contract.functions.reserveTokens()[0] | ||
|
||
async def get_tkn1(self, address: str, contract: Contract, event: Any) -> str: | ||
async def get_tkn1(self, address: str, contract: Contract, event: Event) -> str: | ||
if event: | ||
return event["args"]["_token2"] | ||
return await contract.caller.reserveTokens()[1] | ||
return event.args["_token2"] | ||
return await contract.functions.reserveTokens()[1] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be |
||
|
||
async def get_anchor(self, contract: Contract) -> str: | ||
return await contract.caller.anchor() |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be
caller
, notfunctions
.