Skip to content

Commit

Permalink
Merge pull request #148 from bancorprotocol/147-pol-merge-bug-on-mainnet
Browse files Browse the repository at this point in the history
bugfix for POL on mainnet
  • Loading branch information
mikewcasale authored Sep 21, 2023
2 parents b655c52 + 5e4a293 commit 151a05d
Show file tree
Hide file tree
Showing 13 changed files with 185 additions and 167 deletions.
9 changes: 8 additions & 1 deletion fastlane_bot/events/managers/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from web3 import Web3
from web3.contract import Contract

from fastlane_bot.data.abi import BANCOR_V3_NETWORK_INFO_ABI, ERC20_ABI
from fastlane_bot.data.abi import BANCOR_V3_NETWORK_INFO_ABI, ERC20_ABI, BANCOR_POL_ABI
from fastlane_bot.events.managers.base import BaseManager


Expand Down Expand Up @@ -53,6 +53,13 @@ def init_exchange_contracts(self):
abi=BANCOR_V3_NETWORK_INFO_ABI,
name="BancorNetwork",
)
elif exchange_name == "bancor_pol":
self.pool_contracts[exchange_name][
self.cfg.BANCOR_POL_ADDRESS
] = self.web3.eth.contract(
address=self.cfg.BANCOR_POL_ADDRESS,
abi=BANCOR_POL_ABI,
)

@staticmethod
def get_or_create_token_contracts(
Expand Down
4 changes: 3 additions & 1 deletion fastlane_bot/events/managers/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def update_from_pool_info(
)
pool = self.get_or_init_pool(pool_info)
params = pool.update_from_contract(
contract, self.tenderly_fork_id, self.w3_tenderly
contract, self.tenderly_fork_id, self.w3_tenderly, self.web3
)
for key, value in params.items():
pool_info[key] = value
Expand Down Expand Up @@ -182,6 +182,7 @@ def update_from_contract(
contract,
tenderly_fork_id=self.tenderly_fork_id,
w3_tenderly=self.w3_tenderly,
w3=self.web3,
)
for key, value in params.items():
pool_info[key] = value
Expand Down Expand Up @@ -216,6 +217,7 @@ def update_from_erc20_balance(
contract=pool_contract,
tenderly_fork_id=self.tenderly_fork_id,
w3_tenderly=self.w3_tenderly,
w3=self.web3,
)
params["last_updated_block"] = current_block

Expand Down
2 changes: 1 addition & 1 deletion fastlane_bot/events/managers/pools.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def add_pool_info(
if contract:
pool_info.update(
pool.update_from_contract(
contract, self.tenderly_fork_id, self.w3_tenderly
contract, self.tenderly_fork_id, self.w3_tenderly, self.web3
)
)

Expand Down
16 changes: 11 additions & 5 deletions fastlane_bot/events/pools/bancor_pol.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class BancorPolPool(Pool):

exchange_name: str = "bancor_pol"
ONE = 2**48
contract: Contract = None

@staticmethod
def unique_key() -> str:
Expand Down Expand Up @@ -83,7 +84,7 @@ def update_from_event(
return data

def update_from_contract(
self, contract: Contract, tenderly_fork_id: str = None, w3_tenderly: Web3 = None
self, contract: Contract, tenderly_fork_id: str = None, w3_tenderly: Web3 = None, w3: Web3 = None
) -> Dict[str, Any]:
"""
See base class.
Expand All @@ -96,13 +97,13 @@ def update_from_contract(
p0 = 0
p1 = 0

tkn_balance = self.get_erc20_tkn_balance(contract, tkn0, w3_tenderly)
tkn_balance = self.get_erc20_tkn_balance(contract, tkn0, w3_tenderly, w3)

if tenderly_fork_id:
contract = w3_tenderly.eth.contract(
abi=BANCOR_POL_ABI, address=contract.address
)

try:
p0, p1 = contract.functions.tokenPrice(tkn0).call()
except web3.exceptions.BadFunctionCallOutput:
Expand All @@ -128,7 +129,7 @@ def update_from_contract(

@staticmethod
def get_erc20_tkn_balance(
contract: Contract, tkn0: str, w3_tenderly: Web3 = None
contract: Contract, tkn0: str, w3_tenderly: Web3 = None, w3: Web3 = None
) -> int:
"""
Get the ERC20 token balance of the POL contract
Expand All @@ -141,14 +142,19 @@ def get_erc20_tkn_balance(
The token address
w3_tenderly: Web3
The tenderly web3 object
w3: Web3
The web3 object
Returns
-------
int
The token balance
"""
erc20_contract = w3_tenderly.eth.contract(abi=ERC20_ABI, address=tkn0)
if w3_tenderly:
erc20_contract = w3_tenderly.eth.contract(abi=ERC20_ABI, address=tkn0)
else:
erc20_contract = w3.eth.contract(abi=ERC20_ABI, address=tkn0)
return erc20_contract.functions.balanceOf(contract.address).call()

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion fastlane_bot/events/pools/bancor_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def update_from_event(
return data

def update_from_contract(
self, contract: Contract, tenderly_fork_id: str = None, w3_tenderly: Web3 = None
self, contract: Contract, tenderly_fork_id: str = None, w3_tenderly: Web3 = None, w3: Web3 = None
) -> Dict[str, Any]:
"""
See base class.
Expand Down
2 changes: 1 addition & 1 deletion fastlane_bot/events/pools/bancor_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def update_from_event(
return data

def update_from_contract(
self, contract: Contract, tenderly_fork_id: str = None, w3_tenderly: Web3 = None
self, contract: Contract, tenderly_fork_id: str = None, w3_tenderly: Web3 = None, w3: Web3 = None
) -> Dict[str, Any]:
"""
See base class.
Expand Down
4 changes: 3 additions & 1 deletion fastlane_bot/events/pools/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def update_from_event(

@abstractmethod
def update_from_contract(
self, contract: Contract, tenderly_fork_id: str = None, w3_tenderly: Web3 = None
self, contract: Contract, tenderly_fork_id: str = None, w3_tenderly: Web3 = None, w3: Web3 = None
) -> Dict[str, Any]:
"""
Update the pool state from a contract.
Expand All @@ -89,6 +89,8 @@ def update_from_contract(
The tenderly fork id, by default None
w3_tenderly : Web3, optional
The tenderly web3 instance, by default None
w3 : Web3, optional
The web3 instance, by default None
Returns
-------
Expand Down
2 changes: 1 addition & 1 deletion fastlane_bot/events/pools/carbon_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def parse_orders(
return order0, order1

def update_from_contract(
self, contract: Contract, tenderly_fork_id: str = None, w3_tenderly: Web3 = None
self, contract: Contract, tenderly_fork_id: str = None, w3_tenderly: Web3 = None, w3: Web3 = None
) -> Dict[str, Any]:
"""
See base class.
Expand Down
2 changes: 1 addition & 1 deletion fastlane_bot/events/pools/sushiswap_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def update_from_event(
return data

def update_from_contract(
self, contract: Contract, tenderly_fork_id: str = None, w3_tenderly: Web3 = None
self, contract: Contract, tenderly_fork_id: str = None, w3_tenderly: Web3 = None, w3: Web3 = None
) -> Dict[str, Any]:
"""
See base class.
Expand Down
2 changes: 1 addition & 1 deletion fastlane_bot/events/pools/uniswap_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def update_from_event(
return data

def update_from_contract(
self, contract: Contract, tenderly_fork_id: str = None, w3_tenderly: Web3 = None
self, contract: Contract, tenderly_fork_id: str = None, w3_tenderly: Web3 = None, w3: Web3 = None
) -> Dict[str, Any]:
"""
See base class.
Expand Down
2 changes: 1 addition & 1 deletion fastlane_bot/events/pools/uniswap_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def update_from_event(
return data

def update_from_contract(
self, contract: Contract, tenderly_fork_id: str = None, w3_tenderly: Any = None
self, contract: Contract, tenderly_fork_id: str = None, w3_tenderly: Any = None, w3: Any = None
) -> Dict[str, Any]:
"""
See base class.
Expand Down
3 changes: 2 additions & 1 deletion fastlane_bot/events/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -967,13 +967,14 @@ def multicall_every_iteration(
The number of jobs to run in parallel.
"""
multicallable_exchanges = [exchange for exchange in mgr.cfg.MULTICALLABLE_EXCHANGES if exchange in mgr.exchanges]
multicallable_pool_rows = [
list(set(get_pools_for_exchange(mgr=mgr, exchange=ex_name)))
for ex_name in mgr.cfg.MULTICALLABLE_EXCHANGES
if ex_name in mgr.exchanges
]

for idx, exchange in enumerate(mgr.cfg.MULTICALLABLE_EXCHANGES):
for idx, exchange in enumerate(multicallable_exchanges):
update_pools_from_contracts(
n_jobs=n_jobs,
current_block=current_block,
Expand Down
Loading

0 comments on commit 151a05d

Please sign in to comment.