Ejemplo n.º 1
0
async def create_reserve(result: Tuple[float, GenericToken]):
    (value, token) = result
    try:
        exp = await token.decimals()
    except Exception:
        raise IERC20TokenError("Token doesn't contain decimals.")
    return BigNumber.from_value(value, exp)
Ejemplo n.º 2
0
 async def get_balances(self) -> List[BigNumber]:
     tokens = await self.get_tokens()
     balances = []
     for token in tokens:
         b = self.contract.functions.getBalance(token.get_address()).call()
         try:
             decimals = await token.decimals()
         except Exception:
             raise IERC20TokenError("Bad token in balancer pool")
         balances.append(BigNumber.from_value(b, decimals))
     return balances
Ejemplo n.º 3
0
def dummy_account(w3, empty_account) -> Account:
    balance = w3.eth.getBalance(empty_account.address)
    required = 11 - BigNumber.from_value(balance).to_number()
    required = max(0, required)

    tx_recip = w3.eth.sendTransaction({
        "from": w3.eth.accounts[2],
        "to": empty_account.address,
        "value": BigNumber(required).value,
    })
    w3.eth.waitForTransactionReceipt(tx_recip)
    return empty_account
Ejemplo n.º 4
0
    def _transact_info(self,
                       transaction,
                       value=None,
                       gas=None,
                       dry_run=False) -> Tuple[bool, float]:
        if gas is None:
            gas = self._estimate_gas(transaction)
        gas_amount = self.w3.eth.generateGasPrice()

        if gas_amount:
            gas_cost = BigNumber.from_value(gas * gas_amount).to_number()
        else:
            # No gas strategy specified
            gas_cost = None

        if dry_run:
            return False, gas_cost
        return self._transact(transaction, value, gas).status, gas_cost
Ejemplo n.º 5
0
 def check_out_given_in(self, trade: Trade):
     path_address = list(map(lambda t: t.address, trade.path))
     amount_out = self.contract.functions.getAmountsOut(
         BigNumber(trade.amount_in).value, path_address
     ).call()
     return BigNumber.from_value(amount_out[-1]).to_number()
Ejemplo n.º 6
0
 async def check(self, address):
     amount_weth = await self.weth.balance_of(address)
     amount_eth = BigNumber.from_value(self.web3.eth.getBalance(address))
     return amount_eth.to_number(), amount_weth.to_number()
Ejemplo n.º 7
0
 async def balance_of(self, owner: str) -> BigNumber:
     result = await asyncio.gather(
         self._call_async(self.contract.functions.balanceOf(owner)),
         self.decimals())
     return BigNumber.from_value(result[0], result[1])
Ejemplo n.º 8
0
 async def get_fee(self) -> float:
     fee = await self._call_async(self.contract.functions.getSwapFee())
     return BigNumber.from_value(fee).to_number()