Skip to content

Commit

Permalink
use current bdv for withdrawal
Browse files Browse the repository at this point in the history
  • Loading branch information
soilking committed Aug 20, 2024
1 parent 925eb41 commit 5fa6691
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 3 additions & 5 deletions bots/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1186,15 +1186,13 @@ def single_event_str(self, event_log):
# Pull args from the event log.
token_address = event_log.args.get("token")
token_amount_long = event_log.args.get("amount") # AddDeposit, AddWithdrawal
bdv = None
if event_log.args.get("bdvs") is not None:
bdv = bean_to_float(sum(event_log.args.get("bdvs")))
else:
bdv = bean_to_float(event_log.args.get("bdv"))

_, _, token_symbol, decimals = get_erc20_info(token_address, web3=self._web3).parse()
amount = token_to_float(token_amount_long, decimals)

# Use current bdv rather than the deposited bdv reported in the event
bdv = amount * self.beanstalk_client.get_bdv(get_erc20_info(token_address))

value = None
if bdv > 0:
value = bdv * bean_price
Expand Down
7 changes: 7 additions & 0 deletions data_access/eth_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,12 @@ def get_seeds(self, token, block_number='latest'):
token_settings = call_contract_function_with_retry(self.contract.functions.tokenSettings(token), block_number=block_number)
return (token_settings[1] * 10000) / 10 ** STALK_DECIMALS

def get_bdv(self, erc20_info, block_number='latest'):
"""Returns the current bdv `token`."""
token = Web3.to_checksum_address(erc20_info.addr)
bdv = call_contract_function_with_retry(self.contract.functions.bdv(token, 10 ** erc20_info.decimals), block_number=block_number)
return bean_to_float(bdv)


class BeanClient(ChainClient):
"""Common functionality related to the Bean token."""
Expand Down Expand Up @@ -2763,6 +2769,7 @@ def monitor_beanstalk_events():
client = EthEventsClient(EventClientType.SEASON)
events = client.get_log_range(20566115, 20566115)
logging.info(f"found txn: {events[0].txn_hash.hex()}")
logging.info(f"lp bdv {bs.get_bdv(get_erc20_info(BEAN_WSTETH_WELL_ADDR), 20566115)}")

# monitor_beanstalk_events()
# monitor_curve_pool_events()
Expand Down

0 comments on commit 5fa6691

Please sign in to comment.