def fetch_data_for_fulcrum_pool(token):
    shift_by = web3_service.findDecimals(token)
    pool_info = next(
        (m for m in constants.fulcrumContractInfo if m['token'] == token))
    itoken_contract = web3_service.initializeContract(
        pool_info['contractAddress'], constants.fulcrum_itoken_abi)
    base_token_contract = web3_service.initializeContract(
        pool_info['baseTokenAddress'], abi=constants.erc20_abi_string)
    total_supply = itoken_contract.functions.totalAssetSupply().call(
    ) / 10**shift_by
    total_borrow = itoken_contract.functions.totalAssetBorrow().call(
    ) / 10**shift_by
    result = create_pool_data_object(token, total_supply, total_borrow)
    return result
Example #2
0
def fetch_data_for_ddex_pool(token):
  shift_by = web3_service.findDecimals(token)
  pool_info = next((m for m in constants.ddexContractInfo if m['token'] == token))
  ddex_contract_address = web3_service.w3.toChecksumAddress(constants.ddex_address)
  ddex_contract = web3_service.initializeContract(constants.ddex_address, constants.ddex_abi)
  checksummed_base_token_address = web3_service.w3.toChecksumAddress(pool_info['baseTokenAddress'])
  base_token_contract = web3_service.initializeContract(pool_info['baseTokenAddress'], constants.erc20_abi_string)
  if (token == 'eth'):
    collateral = web3_service.w3.eth.getBalance(ddex_contract_address) / 10 ** shift_by
  else:
    collateral = base_token_contract.functions.balanceOf(ddex_contract_address).call() / 10 ** shift_by
  total_supply = ddex_contract.functions.getTotalSupply(checksummed_base_token_address).call() / 10 ** shift_by
  total_borrow = ddex_contract.functions.getTotalBorrow(checksummed_base_token_address).call() / 10 ** shift_by
  result = create_pool_data_object(token, total_supply, total_borrow, collateral)
  return result
Example #3
0
def fetch_data_for_dydx_pool(token):
    shift_by = 6 if token == 'usdc'  else 18
    pool_info = constants.dydxContractInfo['markets'].index(token)
    initializedContract = web3_service.initializeContract(constants.dydxContractInfo['contractAddress'], abi=constants.dydx_abi_string)
    pool_data = initializedContract.functions.getMarketWithInfo(pool_info).call()
    # Grab + calculate data from dydx market info structure
    total_supply = pool_data[0][1][1] / 10 ** shift_by
    total_borrow = pool_data[0][1][0] / 10 ** shift_by
    result = create_pool_data_object(token, total_supply, total_borrow)
    return result
Example #4
0
def fetch_data_for_compound_pool(token):
  pool_info = next((m for m in constants.compoundContractInfo if m['token'] == token))
  shift_by = web3_service.findDecimals(pool_info['token'])
  abi = json.loads(constants.compound_ceth_abi_string) if (pool_info['token'] == 'eth') else json.loads(constants.erc20_abi_string)
  initialized_contract = web3_service.initializeContract(address=pool_info['contract'], abi=abi)
  # Grabs liquidity from contract which needs to be transformed according to decimals
  liquidity = initialized_contract.functions.getCash().call() / 10 ** shift_by
  total_borrow = initialized_contract.functions.totalBorrows().call() / 10 ** shift_by
  total_supply = liquidity + total_borrow
  result = create_pool_data_object(token, total_supply, total_borrow)
  return result