Skip to content

Commit

Permalink
refactor: remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
johnson2427 committed Jul 30, 2024
1 parent e1d0172 commit 2ba4b9b
Showing 1 changed file with 3 additions and 47 deletions.
50 changes: 3 additions & 47 deletions uniswap_sdk/v2.py
Original file line number Diff line number Diff line change
@@ -1,61 +1,20 @@
import pkgutil
from typing import Iterator

from ape import Contract
from ape.contracts import ContractInstance
from ape.types import AddressType
from ape.utils import ManagerAccessMixin
from ethpm_types import PackageManifest

from .packages import UNI_ROUTER, get_contract_instance

# TODO: Figure out better way to load this using `Project`
_manifest = pkgutil.get_data(__package__, "v2.json")
CONTRACT_TYPES = PackageManifest.parse_raw(_manifest).contract_types # type: ignore

ADDRESSES = {
"ethereum": {
"mainnet": "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",
"rospten": "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",
"rinkeby": "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",
"kovan": "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",
"goerli": "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",
},
"bsc": {
"mainnet": "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",
},
"polygon": {
"mainnet": "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",
"mumbai": "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",
},
"fantom": {
"opera": "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",
"testnet": "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",
},
}


class Factory(ManagerAccessMixin):
@property
def address(self) -> AddressType:
ecosystem_name = self.provider.network.ecosystem.name
network_name = self.provider.network.name.replace("-fork", "")

if ecosystem_name not in ADDRESSES or network_name not in ADDRESSES[ecosystem_name]:
raise ValueError(f"No Uniswap deployment on '{ecosystem_name}:{network_name}'")

return AddressType(ADDRESSES[ecosystem_name][network_name]) # type: ignore

@property
def contract(self) -> ContractInstance:
# return get_contract_instance(UNI_ROUTER.UniversalRouter, self.provider.chain_id)
return Contract(
self.address,
contract_type=CONTRACT_TYPES["UniswapV2Factory"], # type: ignore
)
return get_contract_instance(UNI_ROUTER.UniversalRouter, self.provider.chain_id)

def get_pools(self, token: AddressType) -> Iterator["Pool"]:
# TODO: Use query manager to search once topic filtering is available
breakpoint()
df = self.contract.PairCreated.query("*", start_block=-1000)
pairs = df[df["event_arguments"].apply(
lambda x: x.get("token0") == token or x.get("token1") == token
Expand All @@ -75,7 +34,4 @@ def __init__(self, address: AddressType):

@property
def contract(self) -> ContractInstance:
return Contract(
self.address,
contract_type=CONTRACT_TYPES["UniswapV2Pair"], # type: ignore
)
return get_contract_instance(UNI_ROUTER.UniversalRouter, self.provider.chain_id)

0 comments on commit 2ba4b9b

Please sign in to comment.