Beispiel #1
0
 def calcInGivenOut(self, pool_address: str, token_in_address: str,
                    token_out_address: str, token_out_amount: float):
     pool = BPool(pool_address)
     in_amount = pool.calcInGivenOut(
         pool.getBalance(token_in_address),
         pool.getDenormalizedWeight(token_in_address),
         pool.getBalance(token_out_address),
         pool.getDenormalizedWeight(token_out_address),
         to_base_18(token_out_amount), pool.getSwapFee())
     return from_base_18(in_amount)
Beispiel #2
0
 def calcInGivenOut(
     self,
     pool_address: str,
     token_in_address: str,
     token_out_address: str,
     token_out_amount: int,
 ) -> int:
     pool = BPool(self.web3, pool_address)
     return pool.calcInGivenOut(
         pool.getBalance(token_in_address),
         pool.getDenormalizedWeight(token_in_address),
         pool.getBalance(token_out_address),
         pool.getDenormalizedWeight(token_out_address),
         token_out_amount,
         pool.getSwapFee(),
     )
Beispiel #3
0
    def get_pool_reserves_and_price(self, _pool, dt_address):
        pool = BPool(_pool)
        dt_reserve = pool.getBalance(dt_address)
        ocn_reserve = pool.getBalance(self._checksum_ocean)
        price_base = pool.calcInGivenOut(
            ocn_reserve,
            pool.getDenormalizedWeight(self._checksum_ocean), dt_reserve,
            pool.getDenormalizedWeight(dt_address), to_base_18(1.0),
            pool.getSwapFee())
        price = from_base_18(price_base)
        ocn_reserve = from_base_18(ocn_reserve)
        dt_reserve = from_base_18(dt_reserve)
        if dt_reserve <= 1.0:
            price = 0.0
        if price > self.PRICE_TOO_LARGE:
            price = 0.0

        return dt_reserve, ocn_reserve, price, _pool