示例#1
0
def describe_vault(vault: Vault):
    info = {
        'vault balance': vault.vault.balance() / vault.scale,
        'share price': vault.vault.getPricePerFullShare() / 1e18,
        'vault total': vault.vault.totalSupply() / vault.scale,
        'strategy balance': vault.strategy.balanceOf() / vault.scale,
    }

    # some of the oldest vaults don't implement these methods
    if hasattr(vault.vault, 'available'):
        info['available'] = vault.vault.available() / vault.scale

    if hasattr(vault.vault, 'min') and hasattr(vault.vault, 'max'):
        info['strategy buffer'] = vault.vault.min() / vault.vault.max()

    # new curve voter proxy vaults
    if hasattr(vault.strategy, 'proxy'):
        strategy_proxy = interface.StrategyProxy(vault.strategy.proxy())
        vote_proxy = interface.CurveYCRVVoter(vault.strategy.voter())
        escrow = interface.CurveVotingEscrow(vote_proxy.escrow())
        swap = interface.CurveSwap(vault.strategy.curve())
        gauge = interface.CurveGauge(vault.strategy.gauge())
        info.update(curve.calculate_boost(gauge, vote_proxy))
        info.update(curve.calculate_apy(gauge, swap))

    if vault.strategy._name == 'StrategyYFIGovernance':
        ygov = interface.YearnGovernance(vault.strategy.gov())
        info['earned'] = ygov.earned(vault.strategy) / 1e18
        info['ygov balance'] = ygov.balanceOf(vault.strategy) / 1e18

    return info
示例#2
0
def token_price(token):
    if token in STABLECOINS:
        return 1
    # stETH Curve LP
    if token == "0x06325440D014e39736583c165C2963BA99fAf14E":
        virtual_price = interface.CurveSwap("0xDC24316b9AE028F1497c275EB9192a3Ea0f67022").get_virtual_price() / 1e18
        return price_router(weth) * virtual_price
    if is_uniswap_pool(token):
        return uniswap_lp_price(token)
    return price_router(token)
示例#3
0
    def describe(self):
        scale = 10**self.decimals
        info = {
            "vault balance": self.vault.balance() / scale,
            "share price": self.vault.getPricePerFullShare() / 1e18,
            "vault total": self.vault.totalSupply() / scale,
            "strategy balance": self.strategy.balanceOf() / scale,
        }

        # some of the oldest vaults don't implement these methods
        if hasattr(self.vault, "available"):
            info["available"] = self.vault.available() / scale

        if hasattr(self.vault, "min") and hasattr(self.vault, "max"):
            info["strategy buffer"] = self.vault.min() / self.vault.max()

        # new curve voter proxy vaults
        if hasattr(self.strategy, "proxy"):
            vote_proxy = interface.CurveYCRVVoter(self.strategy.voter())
            # curve swap is broken across several strategies
            swap = interface.CurveSwap(
                constants.CURVE_SWAP_OVERRIDES.get(self.strategy._name,
                                                   self.strategy.curve()))
            gauge = interface.CurveGauge(self.strategy.gauge())
            info.update(curve.calculate_boost(gauge, vote_proxy))
            info.update(curve.calculate_apy(gauge, swap))
            info["earned"] = gauge.claimable_tokens.call(vote_proxy).to(
                "ether")

        if hasattr(self.strategy, "earned"):
            info["lifetime earned"] = self.strategy.earned() / scale

        if self.strategy._name == "StrategyYFIGovernance":
            ygov = interface.YearnGovernance(self.strategy.gov())
            info["earned"] = ygov.earned(self.strategy) / 1e18
            info["reward rate"] = ygov.rewardRate() / 1e18
            info["ygov balance"] = ygov.balanceOf(self.strategy) / 1e18
            info["ygov total"] = ygov.totalSupply() / 1e18

        if "token price" not in info:
            if self.name in ["aLINK"]:
                info["token price"] = uniswap.token_price(
                    self.vault.underlying())
            elif self.name in ["USDC", "TUSD", "DAI", "USDT"]:
                info["token price"] = 1
            else:
                info["token price"] = uniswap.token_price(self.token)

        info["tvl"] = info["vault balance"] * info["token price"]
        return info
示例#4
0
def lp():
    pool_info = {
        'compound': {
            'swap': '0xA2B47E3D5c44877cca798226B7B8118F9BFb7A56',
            'swap_token': '0x845838DF265Dcd2c412A1Dc9e959c7d08537f8a2',
            'gauge': '0x7ca5b0a2910B33e9759DC7dDB0413949071D7575',
        },
        'usdt': {
            'swap': '0x52EA46506B9CC5Ef470C5bf89f17Dc28bB35D85C',
            'swap_token': '0x9fC689CCaDa600B6DF723D9E47D84d76664a1F23',
            'gauge': '0xBC89cd85491d81C6AD2954E6d0362Ee29fCa8F53',
        },
        'y': {
            'swap': '0x45F783CCE6B7FF23B2ab2D70e416cdb7D6055f51',
            'swap_token': '0xdF5e0e81Dff6FAF3A7e52BA697820c5e32D806A8',
            'gauge': '0xFA712EE4788C042e2B7BB55E6cb8ec569C4530c1',
        },
        'busd': {
            'swap': '0x79a8C46DeA5aDa233ABaFFD40F3A0A2B1e5A4F27',
            'swap_token': '0x3B3Ac5386837Dc563660FB6a0937DFAa5924333B',
            'gauge': '0x69Fb7c45726cfE2baDeE8317005d3F94bE838840',
        },
        'susdv2': {
            'swap': '0xA5407eAE9Ba41422680e2e00537571bcC53efBfD',
            'swap_token': '0xC25a3A3b969415c80451098fa907EC722572917F',
            'gauge': '0xA90996896660DEcC6E997655E065b23788857849',
        },
        'pax': {
            'swap': '0x06364f10B501e868329afBc005b3492902d6C763',
            'swap_token': '0xD905e2eaeBe188fc92179b6350807D8bd91Db0D8',
            'gauge': '0x64E3C23bfc40722d3B649844055F1D51c1ac041d',
        },
        'ren': {
            'swap': '0x93054188d876f558f4a66B2EF1d97d16eDf0895B',
            'swap_token': '0x49849C98ae39Fff122806C06791Fa73784FB3675',
            'gauge': '0xB1F2cdeC61db658F091671F5f199635aEF202CAC',
        },
        'sbtc': {
            'swap': '0x7fC77b5c7614E1533320Ea6DDc2Eb61fa00A9714',
            'swap_token': '0x075b1bb99792c9E1041bA13afEf80C91a1e70fB3',
            'gauge': '0x705350c4BcD35c9441419DdD5d2f097d7a55410F',
        },
    }
    for name, item in pool_info.items():
        swap = interface.CurveSwap(item['swap'])
        gauge = interface.CurveGauge(item['gauge'])
        print(name, curve.calculate_apy(gauge, swap))
示例#5
0
def describe_vault(vault: Vault):
    info = {
        "vault balance": vault.vault.balance() / vault.scale,
        "share price": vault.vault.getPricePerFullShare() / 1e18,
        "vault total": vault.vault.totalSupply() / vault.scale,
        "strategy balance": vault.strategy.balanceOf() / vault.scale,
    }

    # some of the oldest vaults don't implement these methods
    if hasattr(vault.vault, "available"):
        info["available"] = vault.vault.available() / vault.scale

    if hasattr(vault.vault, "min") and hasattr(vault.vault, "max"):
        info["strategy buffer"] = vault.vault.min() / vault.vault.max()

    # new curve voter proxy vaults
    if hasattr(vault.strategy, "proxy"):
        vote_proxy = interface.CurveYCRVVoter(vault.strategy.voter())
        swap_func = {
            "StrategyCurveGUSDProxy": "SWAP"
        }.get(vault.strategy._name, "curve")
        swap = interface.CurveSwap(getattr(vault.strategy, swap_func)())
        gauge = interface.CurveGauge(vault.strategy.gauge())
        info.update(curve.calculate_boost(gauge, vote_proxy))
        info.update(curve.calculate_apy(gauge, swap))
        info["earned"] = gauge.claimable_tokens.call(vote_proxy).to("ether")

    if hasattr(vault.strategy, "earned"):
        info["lifetime earned"] = vault.strategy.earned() / vault.scale

    if vault.strategy._name == "StrategyYFIGovernance":
        ygov = interface.YearnGovernance(vault.strategy.gov())
        info["earned"] = ygov.earned(vault.strategy) / 1e18
        info["reward rate"] = ygov.rewardRate() / 1e18
        info["ygov balance"] = ygov.balanceOf(vault.strategy) / 1e18
        info["ygov total"] = ygov.totalSupply() / 1e18
        info["token price"] = uniswap.price_router(vault.token, uniswap.usdc)

    return info
示例#6
0
def get_virtual_price(lp):
    return interface.CurveSwap(lp_to_pool(lp)).get_virtual_price() / 1e18
示例#7
0
    def describe(self):
        scale = 10**self.decimals
        info = {}
        try:
            info['share price'] = self.vault.getPricePerFullShare() / 1e18
        except ValueError:
            # no money in vault, exit early
            return {'tvl': 0}

        attrs = {
            'vault balance': [self.vault, 'balance'],
            'vault total': [self.vault, 'totalSupply'],
            'strategy balance': [self.strategy, 'balanceOf'],
        }

        # some of the oldest vaults don't implement these methods
        if hasattr(self.vault, "available"):
            attrs['available'] = [self.vault, 'available']

        if hasattr(self.vault, "min") and hasattr(self.vault, "max"):
            attrs['min'] = [self.vault, 'min']
            attrs['max'] = [self.vault, 'max']

        # new curve voter proxy vaults
        if hasattr(self.strategy, "proxy"):
            results = fetch_multicall(
                [self.strategy, 'voter'],
                [curve.registry, 'get_pool_from_lp_token', self.token],
                [self.strategy, 'gauge'],
            )
            vote_proxy = interface.CurveYCRVVoter(results[0])
            swap = interface.CurveSwap(results[1])
            gauge = interface.CurveGauge(results[2])
            info.update(curve.calculate_boost(gauge, vote_proxy))
            info.update(curve.calculate_apy(gauge, swap))
            info["earned"] = gauge.claimable_tokens.call(vote_proxy).to(
                "ether")

        if hasattr(self.strategy, "earned"):
            info["lifetime earned"] = self.strategy.earned() / scale

        if self.strategy._name == "StrategyYFIGovernance":
            ygov = interface.YearnGovernance(self.strategy.gov())
            attrs["earned"] = [ygov, 'earned', self.strategy]
            attrs["reward rate"] = [ygov, 'rewardRate']
            attrs["ygov balance"] = [ygov, 'balanceOf', self.strategy]
            attrs["ygov total"] = [ygov, 'totalSupply']

        # fetch attrs as multicall
        try:
            results = fetch_multicall(*attrs.values())
        except ValueError:
            pass
        else:
            for name, attr in zip(attrs, results):
                info[name] = attr / scale

        # some additional post-processing
        if 'min' in info:
            info["strategy buffer"] = info.pop('min') / info.pop('max')

        if "token price" not in info:
            if self.name in ["aLINK"]:
                info["token price"] = uniswap.token_price(
                    self.vault.underlying())
            elif self.name in ["USDC", "TUSD", "DAI", "USDT"]:
                info["token price"] = 1
            else:
                info["token price"] = uniswap.token_price(self.token)

        info["tvl"] = info["vault balance"] * info["token price"]
        return info