Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EXP-14-216] fix: oracle regression #216

Merged
merged 3 commits into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions yearn/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ class PriceError(Exception):

class ArchiveNodeRequired(Exception):
pass


class MulticallError(Exception):
pass
5 changes: 4 additions & 1 deletion yearn/multicall2.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from yearn.networks import Network
from yearn.utils import contract_creation_block, contract
from yearn.exceptions import MulticallError

MULTICALL2 = {
Network.Mainnet: '0x5BA1e12693Dc8F9c48aAD8770482f4739bEeD696',
Expand All @@ -17,7 +18,7 @@
multicall2 = contract(MULTICALL2[chain.id])


def fetch_multicall(*calls, block=None):
def fetch_multicall(*calls, block=None, require_success=False):
# https://github.com/makerdao/multicall
multicall_input = []
fn_list = []
Expand Down Expand Up @@ -52,6 +53,8 @@ def fetch_multicall(*calls, block=None):
assert ok, "call failed"
decoded.append(fn.decode_output(data))
except (AssertionError, InsufficientDataBytes):
if require_success:
raise MulticallError()
decoded.append(None)

return decoded
Expand Down
7 changes: 5 additions & 2 deletions yearn/outputs/describers/vault.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ def _get_price(token_address, block=None):
# https://github.com/yearn/yearn-security/blob/master/disclosures/2021-05-13.md
if token_address == '0x03403154afc09Ce8e44C3B185C82C6aD5f86b9ab' and 12430455 <= block <= 12430661:
return 1.091553
# GUSD vault state was broken due to an incident, return a post-fix price
# https://github.com/yearn/yearn-security/blob/master/disclosures/2021-01-17.md
elif token_address == '0x03403154afc09Ce8e44C3B185C82C6aD5f86b9ab' and 11603873 <= block <= 11645877:
return 0

logger.exception(e)

return 0
raise e
37 changes: 24 additions & 13 deletions yearn/prices/yearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from yearn.networks import Network
from yearn.utils import Singleton, contract
from brownie import chain
from yearn.exceptions import UnsupportedNetwork
from yearn.exceptions import MulticallError, UnsupportedNetwork
import logging
from cachetools.func import ttl_cache

Expand Down Expand Up @@ -60,23 +60,34 @@ def is_yearn_vault(self, token):
)

def get_price(self, token, block=None):
# v1 vaults use getPricePerFullShare scaled to 18 decimals
# v2 vaults use pricePerShare scaled to underlying token decimals
vault = contract(token)
if hasattr(vault, 'pricePerShare'):
share_price, underlying, decimals = fetch_multicall(
[vault, 'pricePerShare'],
[vault, 'token'],
[vault, 'decimals'],
block=block,
)
if share_price and underlying and decimals:
try:
share_price, underlying, decimals = fetch_multicall(
[vault, 'pricePerShare'],
[vault, 'token'],
[vault, 'decimals'],
block=block,
require_success=True,
)
except MulticallError:
return None
else:
return [share_price / 10 ** decimals, underlying]

# v1 vaults use getPricePerFullShare scaled to 18 decimals
if hasattr(vault, 'getPricePerFullShare'):
share_price, underlying = fetch_multicall(
[vault, 'getPricePerFullShare'], [vault, 'token'], block=block
)
if share_price and underlying:
try:
share_price, underlying = fetch_multicall(
[vault, 'getPricePerFullShare'],
[vault, 'token'],
block=block,
require_success=True,
)
except MulticallError:
return None
else:
return [share_price / 1e18, underlying]


Expand Down