-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement a scaffold for running arbitrage "strategies."
- Loading branch information
1 parent
00416a3
commit cba79ae
Showing
11 changed files
with
181 additions
and
31 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
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,57 @@ | ||
from src.contracts.auction import AuctionDirectory, AuctionProvider | ||
from src.contracts.pool.provider import PoolProvider | ||
from src.contracts.pool.astroport import AstroportPoolDirectory | ||
from src.contracts.pool.osmosis import OsmosisPoolDirectory | ||
from src.util import deployments | ||
from typing import Callable, List | ||
|
||
|
||
class Scheduler: | ||
""" | ||
A registry of pricing providers for different assets, | ||
which can be polled alongside a strategy function which | ||
may interact with registered providers. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
strategy: Callable[ | ||
[ | ||
dict[str, dict[str, List[PoolProvider]]], | ||
dict[str, dict[str, AuctionProvider]], | ||
], | ||
None, | ||
], | ||
): | ||
self.strategy = strategy | ||
self.providers: dict[str, dict[str, List[PoolProvider]]] = {} | ||
|
||
auction_manager = AuctionDirectory(deployments()) | ||
self.auctions = auction_manager.auctions() | ||
|
||
def register_provider(self, provider: PoolProvider): | ||
""" | ||
Registers a pool provider, enqueing it to future strategy function polls. | ||
""" | ||
|
||
if provider.asset_a() not in self.providers: | ||
self.providers[provider.asset_a()] = {} | ||
|
||
if provider.asset_b() not in self.providers: | ||
self.providers[provider.asset_b()] = {} | ||
|
||
if provider.asset_b() not in self.providers[provider.asset_a()]: | ||
self.providers[provider.asset_a()][provider.asset_b()] = [] | ||
|
||
if provider.asset_a() not in self.providers[provider.asset_b()]: | ||
self.providers[provider.asset_b()][provider.asset_a()] = [] | ||
|
||
self.providers[provider.asset_a()][provider.asset_b()].append(provider) | ||
self.providers[provider.asset_b()][provider.asset_a()].append(provider) | ||
|
||
def poll(self): | ||
""" | ||
Polls the strategy functionw with all registered providers. | ||
""" | ||
|
||
self.strategy(self.providers, self.auctions) |
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
Empty file.
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,77 @@ | ||
from src.scheduler import Scheduler | ||
from src.util import deployments | ||
from src.contracts.pool.osmosis import OsmosisPoolDirectory | ||
from src.contracts.pool.astroport import AstroportPoolDirectory | ||
from src.contracts.pool.provider import PoolProvider | ||
from src.contracts.auction import AuctionProvider | ||
import json | ||
import pytest | ||
from typing import List | ||
|
||
|
||
# Noop strategy | ||
def strategy( | ||
pools: dict[str, dict[str, List[PoolProvider]]], | ||
auctions: dict[str, dict[str, AuctionProvider]], | ||
): | ||
return None | ||
|
||
|
||
def test_init(): | ||
""" | ||
Test that a scheduler can be instantiated. | ||
""" | ||
|
||
sched = Scheduler(strategy) | ||
assert sched is not None | ||
|
||
|
||
def test_register_provider(): | ||
""" | ||
Test that a provider can be registered to a scheduler. | ||
""" | ||
|
||
osmosis = OsmosisPoolDirectory() | ||
pool = list(list(osmosis.pools().values())[0].values())[0] | ||
|
||
sched = Scheduler(strategy) | ||
|
||
directory = OsmosisPoolDirectory() | ||
pools = directory.pools() | ||
|
||
for base in pools.values(): | ||
for pool in base.values(): | ||
sched.register_provider(pool) | ||
|
||
assert len(sched.providers) > 0 | ||
|
||
|
||
def test_poll(): | ||
""" | ||
Test that a strategy function can be run. | ||
""" | ||
|
||
osmosis = OsmosisPoolDirectory() | ||
astroport = AstroportPoolDirectory(deployments()) | ||
|
||
def simple_strategy( | ||
pools: dict[str, dict[str, List[PoolProvider]]], | ||
auctions: dict[str, dict[str, AuctionProvider]], | ||
): | ||
assert len(pools) > 0 | ||
assert len(auctions) > 0 | ||
|
||
sched = Scheduler(simple_strategy) | ||
|
||
osmos_pools = osmosis.pools() | ||
astro_pools = astroport.pools() | ||
|
||
for base in osmos_pools.values(): | ||
for pool in base.values(): | ||
sched.register_provider(pool) | ||
|
||
for base in astro_pools.values(): | ||
for pool in base.values(): | ||
sched.register_provider(pool) | ||
|
||
sched.poll() |
This file was deleted.
Oops, something went wrong.