Skip to content

Commit

Permalink
wip: trying to move pricePerShare logic into its own price class.
Browse files Browse the repository at this point in the history
  • Loading branch information
mariuspod committed Jan 31, 2022
1 parent b7daccb commit 3efcdba
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 29 deletions.
25 changes: 1 addition & 24 deletions yearn/outputs/describers/vault.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,9 @@ def describe_wallets(self, vault_address, block=None):
'wallet balances': {
wallet: {
"token balance": float(bal),
"usd balance": float(bal) * _get_price(vault_address, block=block)
"usd balance": float(bal) * magic.get_price(vault_address, block=block)
} for wallet, bal in balances.items()
}
}
info['active wallets'] = sum(1 if balances['usd balance'] > 50 else 0 for wallet, balances in info['wallet balances'].items())
return info

def _get_price(token_address, block=None):
try: return magic.get_price(token_address, block=block)
except TypeError as e:
if token_address == '0xec0d8D3ED5477106c6D4ea27D90a60e594693C90' and block <= 11645697:
return 0 # NOTE: yGUSD `share_price` returns `None` because balance() reverts due to hack
elif str(e) == "unsupported operand type(s) for /: 'NoneType' and 'float'" and token_address == '0x03403154afc09Ce8e44C3B185C82C6aD5f86b9ab':
# NOTE: There was an accounting error that had to be fixed manually
LAST_BLOCK_BEFORE_ACCOUNTING_ERR = 12429262
token = contract(token_address)
ppfs = token.getPricePerFullShare(block_identifier=LAST_BLOCK_BEFORE_ACCOUNTING_ERR) / 1e18
want_price = magic.get_price(token.token(),block=block)
return ppfs * want_price
else:
token = contract(token_address)
try:
token.getPricePerFullShare(block_identifier=block)
except ValueError as e:
if 'division by zero' in str(e) and token.totalSupply(block_identifier=block) == 0:
return magic.get_price(token.token(block_identifier=block),block=block) # NOTE: This runs when totalSupply() == 0 during early testing
logger.warn(f'address: {token_address}')
logger.warn(f'block: {block}')
raise
17 changes: 12 additions & 5 deletions yearn/prices/magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
from yearn.prices.uniswap.v3 import uniswap_v3
from yearn.prices.curve import curve
from yearn.prices.yearn import yearn_lens
from yearn.utils import contract

from yearn.prices.pps import pps
from yearn.prices import constants

from yearn.utils import contract
logger = logging.getLogger(__name__)

@ttl_cache(10000)
Expand Down Expand Up @@ -65,15 +65,22 @@ def find_price(token, block):
price = yearn_lens.get_price(token, block=block)
logger.debug("yearn -> %s", price)

elif pps and pps.token_wants_pps_price(token, block):
price = pps.get_price(token, block)
logger.debug("pps -> %s", price)

# xcredit
elif chain.id == Network.Fantom and token == '0xd9e28749e80D867d5d14217416BFf0e668C10645':
logger.debug('xcredit -> unwrap')
wrapper = contract(token)
price = get_price(wrapper.token(), block=block) * wrapper.getShareValue() / 1e18
# no liquid market for yveCRV-DAO -> return CRV token price
elif chain.id == Network.Mainnet and token == '0xc5bDdf9843308380375a611c18B50Fb9341f502A' and block and block < 11786563:
if curve and curve.crv:
return get_price(curve.crv, block=block)
elif chain.id == Network.Mainnet:
if token == '0xc5bDdf9843308380375a611c18B50Fb9341f502A' and block and block < 11786563:
if curve and curve.crv:
return get_price(curve.crv, block=block)
elif token == '0xec0d8D3ED5477106c6D4ea27D90a60e594693C90' and block <= 11645697:
return 0 # NOTE: yGUSD `share_price` returns `None` because balance() reverts due to hack

markets = [
chainlink,
Expand Down

0 comments on commit 3efcdba

Please sign in to comment.