Exemplo n.º 1
0
class _MintableTestToken(MintableForkToken):

    _rate_methods = (
        "exchangeRateStored",
        "exchangeRateCurrent",
        "getPricePerFullShare",
        "get_virtual_price",
    )

    def __init__(self, coin_data, is_wrapped):
        self._coin_data = coin_data

        wrapped_address = coin_data.get("wrapped_address")
        underlying_address = coin_data.get("underlying_address")
        if is_wrapped:
            address = wrapped_address or underlying_address
        else:
            address = underlying_address or wrapped_address
        super().__init__(address)

        if is_wrapped and wrapped_address:
            self._rate_fn = next(
                getattr(self, i) for i in self._rate_methods
                if hasattr(self, i))
        else:
            if "base_pool_token" in coin_data:
                base_pool = next(i for i in _pooldata.values()
                                 if i.get("lp_token_address") == self.address)
                self._rate_fn = Contract(
                    base_pool["swap_address"]).get_virtual_price
            else:
                self._rate_fn = None

    def _get_rate(self):
        if not self._rate_fn:
            return 10**18
        return self._rate_fn.call()
Exemplo n.º 2
0
class _MintableTestToken(Contract):

    _rate_methods = (
        "exchangeRateStored",
        "exchangeRateCurrent",
        "getPricePerFullShare",
        "get_virtual_price",
    )

    def __init__(self, coin_data, is_wrapped):
        self._coin_data = coin_data

        wrapped_address = coin_data.get("wrapped_address")
        underlying_address = coin_data.get("underlying_address")
        if is_wrapped:
            address = wrapped_address or underlying_address
        else:
            address = underlying_address or wrapped_address
        super().__init__(address)

        if is_wrapped and wrapped_address:
            self._rate_fn = next(
                getattr(self, i) for i in self._rate_methods
                if hasattr(self, i))
        else:
            if "base_pool_token" in coin_data:
                base_pool = next(i for i in _pooldata.values()
                                 if i.get("lp_token_address") == self.address)
                self._rate_fn = Contract(
                    base_pool["swap_address"]).get_virtual_price
            else:
                self._rate_fn = None

        # get top token holder addresses
        address = self.address
        if address not in _holders:
            holders = requests.get(
                f"https://api.ethplorer.io/getTopTokenHolders/{address}",
                params={
                    'apiKey': "freekey",
                    'limit': 50
                },
            ).json()
            _holders[address] = [
                to_address(i['address']) for i in holders['holders']
            ]

    def _get_rate(self):
        if not self._rate_fn:
            return 10**18
        return self._rate_fn.call()

    def _mint_for_testing(self, target, amount, tx=None):
        if self.address == "0x674C6Ad92Fd080e4004b2312b45f796a192D27a0":
            # USDN
            self.deposit(
                target, amount,
                {'from': "0x90f85042533F11b362769ea9beE20334584Dcd7D"})
            return
        if self.address == "0x0E2EC54fC0B509F445631Bf4b91AB8168230C752":
            # LinkUSD
            self.mint(target, amount,
                      {'from': "0x62F31E08e279f3091d9755a09914DF97554eAe0b"})
            return
        if self.address == "0x196f4727526eA7FB1e17b2071B3d8eAA38486988":
            self.changeMaxSupply(2**128, {'from': self.owner()})
            self.mint(target, amount, {'from': self.minter()})
            return

        for address in _holders[self.address].copy():
            if address == self.address:
                # don't claim from the treasury - that could cause wierdness
                continue

            balance = self.balanceOf(address)
            if amount > balance:
                self.transfer(target, balance, {'from': address})
                amount -= balance
            else:
                self.transfer(target, amount, {'from': address})
                return

        raise ValueError(
            f"Insufficient tokens available to mint {self.name()}")