コード例 #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
ファイル: vaults_v1.py プロジェクト: w1r2p1/yearn-exporter
    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
コード例 #3
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
コード例 #4
0
    def describe(self, block=None):
        info = {}
        strategy = self.strategy
        if block is not None:
            strategy = self.get_strategy(block=block)

        # attrs are fetches as multicall and populate info
        attrs = {
            "vault balance": [self.vault, "balance"],
            "vault total": [self.vault, "totalSupply"],
            "strategy balance": [strategy, "balanceOf"],
            "share price": [self.vault, "getPricePerFullShare"],
        }

        # 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 self.is_curve_vault and hasattr(strategy, "proxy"):
            vote_proxy, gauge = fetch_multicall(
                [strategy, "voter"],  # voter is static, can pin
                [strategy, "gauge"],  # gauge is static per strategy, can cache
                block=block,
            )
            # guard historical queries where there are no vote_proxy and gauge
            # for block <= 10635293 (2020-08-11)
            if vote_proxy and gauge:
                vote_proxy = interface.CurveYCRVVoter(vote_proxy)
                gauge = contract(gauge)
                info.update(
                    curve.calculate_boost(gauge, vote_proxy, block=block))
                info.update(curve.calculate_apy(gauge, self.token,
                                                block=block))
                attrs["earned"] = [gauge, "claimable_tokens",
                                   vote_proxy]  # / scale

        if hasattr(strategy, "earned"):
            attrs["lifetime earned"] = [strategy, "earned"]  # /scale

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

        # fetch attrs as multicall
        results = fetch_multicall(*attrs.values(), block=block)
        scale_overrides = {"share price": 1e18}
        for name, attr in zip(attrs, results):
            if attr is not None:
                info[name] = attr / scale_overrides.get(name, self.scale)
            else:
                logger.warning("attr %s rekt %s", name, attr)

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

        if "token price" not in info:
            info["token price"] = self.get_price(block=block)

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

        return info
コード例 #5
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