Skip to content

Commit

Permalink
[EXP-26-226] add CL price feeds for fantom (yearn#226)
Browse files Browse the repository at this point in the history
* fix: correct YFI price on fantom by reading from the CL price feed directly until there's a deployed registry on fantom.

* fix: adding some CL price feed mappings for fantom from: https://data.chain.link/fantom/mainnet

* fix: clean comments for fantom chainlink feeds

* fix: xcredit price block identifier

Co-authored-by: banteg <[email protected]>
  • Loading branch information
mariuspod and banteg authored Feb 3, 2022
1 parent dbb07b2 commit 64a2aee
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 26 deletions.
56 changes: 40 additions & 16 deletions yearn/prices/chainlink.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import logging
from functools import cached_property

from brownie import chain, ZERO_ADDRESS
from cachetools.func import lru_cache, ttl_cache

from brownie import ZERO_ADDRESS, chain
from cachetools.func import ttl_cache
from yearn.events import decode_logs, get_logs_asap
from yearn.utils import Singleton, contract
from yearn.networks import Network
from yearn.exceptions import UnsupportedNetwork
from yearn.networks import Network
from yearn.utils import Singleton, contract

logger = logging.getLogger(__name__)

Expand All @@ -17,17 +15,40 @@
'USD': '0x0000000000000000000000000000000000000348',
}
ADDITIONAL_FEEDS = {
"0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599": "0xF4030086522a5bEEa4988F8cA5B36dbC97BeE88c", # wbtc -> btc
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2": "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419", # weth -> eth
"0x0100546F2cD4C9D97f798fFC9755E47865FF7Ee6": "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419", # aleth -> eth
"0xdB25f211AB05b1c97D595516F45794528a807ad8": "0xb49f677943BC038e9857d61E7d053CaA2C1734C1", # eurs -> eur
"0xC581b735A1688071A1746c968e0798D642EDE491": "0xb49f677943BC038e9857d61E7d053CaA2C1734C1", # eurt -> eur
"0xD71eCFF9342A5Ced620049e616c5035F1dB98620": "0xb49f677943BC038e9857d61E7d053CaA2C1734C1", # seur -> eur
"0x81d66D255D47662b6B16f3C5bbfBb15283B05BC2": "0x438F81D95761d7036cd2617295827D9d01Cf593f", # ibzar -> zar
# map similar tokens to existing feeds
Network.Mainnet: {
"0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599": "0xF4030086522a5bEEa4988F8cA5B36dbC97BeE88c", # wbtc -> btc
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2": "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419", # weth -> eth
"0x0100546F2cD4C9D97f798fFC9755E47865FF7Ee6": "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419", # aleth -> eth
"0xdB25f211AB05b1c97D595516F45794528a807ad8": "0xb49f677943BC038e9857d61E7d053CaA2C1734C1", # eurs -> eur
"0xC581b735A1688071A1746c968e0798D642EDE491": "0xb49f677943BC038e9857d61E7d053CaA2C1734C1", # eurt -> eur
"0xD71eCFF9342A5Ced620049e616c5035F1dB98620": "0xb49f677943BC038e9857d61E7d053CaA2C1734C1", # seur -> eur
"0x81d66D255D47662b6B16f3C5bbfBb15283B05BC2": "0x438F81D95761d7036cd2617295827D9d01Cf593f", # ibzar -> zar
},
# feeds are hardcoded since there is no feed registry on fantom yet
# https://data.chain.link/fantom/mainnet
Network.Fantom: {
"0x21be370D5312f44cB42ce377BC9b8a0cEF1A4C83": "0xf4766552D15AE4d256Ad41B6cf2933482B0680dc", # wftm
"0x321162Cd933E2Be498Cd2267a90534A804051b11": "0x321162Cd933E2Be498Cd2267a90534A804051b11", # wbtc
"0x74b23882a30290451A17c44f4F05243b6b58C76d": "0x11DdD3d147E5b83D01cee7070027092397d63658", # weth
"0xd6070ae98b8069de6B494332d1A1a81B6179D960": "0x4F5Cc6a2291c964dEc4C7d6a50c0D89492d4D91B", # bifi
"0x1E4F97b9f9F913c46F1632781732927B9019C68b": "0xa141D7E3B44594cc65142AE5F2C7844Abea66D2B", # crv
"0x6a07A792ab2965C72a5B8088d3a069A7aC3a993B": "0xE6ecF7d2361B6459cBb3b4fb065E0eF4B175Fe74", # aave
"0x657A1861c15A3deD9AF0B6799a195a249ebdCbc6": "0xD2fFcCfA0934caFdA647c5Ff8e7918A10103c01c", # cream
"0xb3654dc3D10Ea7645f8319668E8F54d2574FBdC8": "0x221C773d8647BC3034e91a0c47062e26D20d97B4", # link
"0x399fe752D39338d28C36F3370fbebd8292fb9E6e": "0xb26867105D25bD127862bEA9B952Fa2E89942837", # ohmv2
"0x56ee926bD8c72B2d5fa1aF4d9E4Cbb515a1E3Adc": "0x2Eb00cC9dB7A7E0a013A49b3F6Ac66008d1456F7", # snx
"0x468003B688943977e6130F4F68F23aad939a1040": "0x02E48946849e0BFDD7bEa5daa80AF77195C7E24c", # spell
"0xae75A438b2E0cB8Bb01Ec1E1e376De11D44477CC": "0xCcc059a1a17577676c8673952Dc02070D29e5a66", # sushi
"0x81740D647493a61329E1c574A11ee7577659fb14": "0x4be9c8fb4105380116c03fc2eeb9ea1e1a109d95", # fchf
"0xe105621721D1293c27be7718e041a4Ce0EbB227E": "0x3E68e68ea2c3698400465e3104843597690ae0f7", # feur
"0x29b0Da86e484E1C0029B56e817912d778aC0EC69": "0x9B25eC3d6acfF665DfbbFD68B3C1D896E067F0ae", # yfi
},
}
registries = {
# https://docs.chain.link/docs/feed-registry/#contract-addresses
Network.Mainnet: '0x47Fb2585D2C56Fe188D0E6ec628a38b74fCeeeDf',
Network.Fantom: None,
}


Expand All @@ -36,8 +57,11 @@ def __init__(self):
if chain.id not in registries:
raise UnsupportedNetwork('chainlink is not supported on this network')

self.registry = contract(registries[chain.id])
self.load_feeds()
if registries[chain.id]:
self.registry = contract(registries[chain.id])
self.load_feeds()
else:
self.feeds = ADDITIONAL_FEEDS[chain.id]

def load_feeds(self):
logs = decode_logs(
Expand All @@ -48,7 +72,7 @@ def load_feeds(self):
for log in logs
if log['denomination'] == DENOMINATIONS['USD']
}
self.feeds.update(ADDITIONAL_FEEDS)
self.feeds.update(ADDITIONAL_FEEDS[chain.id])
logger.info(f'loaded {len(self.feeds)} feeds')

def get_feed(self, asset):
Expand Down
5 changes: 4 additions & 1 deletion yearn/prices/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@
Network.Fantom: {
"0x04068DA6C83AFCFA0e13ba15A6696662335D5B75": "usdc",
"0x8D11eC38a3EB5E956B052f67Da8Bdc9bef8Abf3E": "dai",
"0x1B27A9dE6a775F98aaA5B90B62a4e2A0B84DbDd9": "usdt",
"0xC931f61B1534EB21D8c11B24f3f5Ab2471d4aB50": "busd",
"0xe2D27f06F63d98b8e11b38b5b08A75D0c8dD62B9": "ust",
"0x82f0B8B456c1A451378467398982d4834b6829c1": "mim",
"0x049d68029688eAbF473097a2fC38ef61633A3C7A": "fusdt"
"0x049d68029688eAbF473097a2fC38ef61633A3C7A": "fusdt",
"0xdc301622e621166BD8E82f2cA0A26c13Ad0BE355": "frax",
},
Network.Arbitrum: {
'0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8': 'usdc',
Expand Down
21 changes: 12 additions & 9 deletions yearn/prices/magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,18 @@ def find_price(token, block):
price = yearn_lens.get_price(token, block=block)
logger.debug("yearn -> %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.Fantom:
# xcredit
if token == '0xd9e28749e80D867d5d14217416BFf0e668C10645':
logger.debug('xcredit -> unwrap')
wrapper = contract(token)
price = get_price(wrapper.token(), block=block) * wrapper.getShareValue(block_identifier=block) / 1e18

elif chain.id == Network.Mainnet:
# no liquid market for yveCRV-DAO -> return CRV token price
if token == '0xc5bDdf9843308380375a611c18B50Fb9341f502A' and block and block < 11786563:
if curve and curve.crv:
return get_price(curve.crv, block=block)

markets = [
chainlink,
Expand Down

0 comments on commit 64a2aee

Please sign in to comment.