Exemple #1
0
    def get_staking_balances(self, address: str) -> List[BalanceItem]:
        response = self.get('get_staking_data', address=address)

        balances = []
        if int(response['delegationTotal']) > 0:
            balances.append(
                BalanceItem.from_api(
                    balance_raw=response['delegationTotal'],
                    coin=self.coin,
                    asset_type=AssetType.STAKED,
                    raw=response,
                ))

        if float(response['rewards']['total']) > 0:
            balances.append(
                BalanceItem.from_api(
                    balance_raw=response['rewards']['total'],
                    coin=self.coin,
                    asset_type=AssetType.CLAIMABLE,
                    raw=response,
                ))

        # process undelegations

        return balances
Exemple #2
0
    def _parse_token_balances(self, response: Dict) -> Iterable[BalanceItem]:
        for _token_raw in response.get('tokens', []):
            if _token_raw.get('rawBalance') is None or _token_raw['rawBalance'] == 0:
                continue

            info = _token_raw['tokenInfo']
            coin = Coin.from_api(
                blockchain=self.api_options.blockchain,
                decimals=info.get('decimals', 0),
                symbol=info.get('symbol'),
                name=info.get('name'),
                address=to_checksum_address(info['address']),
                standards=None,  # parse from tags?
                info=CoinInfo.from_api(
                    tags=info.get('publicTags'),
                    total_supply=info.get('totalSupply'),
                    logo_url=(
                        self._format_logo_url(info.get('image'))
                        if info.get('image')
                        else None
                    ),
                    coingecko_id=info.get('coingecko'),
                    website=info.get('website'),
                ),
            )

            yield BalanceItem.from_api(
                balance_raw=_token_raw['rawBalance'],
                coin=coin,
                last_updated=info.get('lastUpdated'),
                raw=_token_raw,
            )
Exemple #3
0
    def _parse_eth_balance(self, response: Dict) -> Optional[BalanceItem]:
        _eth_raw = response['ETH']
        if int(_eth_raw['rawBalance']) == 0:
            return

        return BalanceItem.from_api(
            balance_raw=_eth_raw['rawBalance'],
            coin=self.coin,
            last_updated=None,
            raw=_eth_raw,
        )
Exemple #4
0
    def _get_sol_balance(
        self,
        address: str,
    ) -> Optional[BalanceItem]:
        response = self._request(method='getBalance', params=[address])
        if int(response['result']['value']) == 0:
            return

        return BalanceItem.from_api(
            balance_raw=response['result']['value'],
            coin=self.coin,
            last_updated=None,
            raw=response,
        )
Exemple #5
0
    def get_native_balances(self, address: str) -> List[BalanceItem]:
        response = self.get('get_native_balances', address=address)

        balances = []
        for b in response['balance']:
            if int(b['available']) == 0:
                continue

            coin = (self._get_terra_token_by_denom(b['denom'])
                    if b['denom'].startswith('u') else
                    self._get_ibc_token_by_denom(b['denom']))

            balances.append(
                BalanceItem.from_api(balance_raw=b['available'],
                                     coin=coin,
                                     raw=b))

        return balances
Exemple #6
0
    def get_cw20_balances(self, address: str):
        raw_balances = self._get_raw_balances(address)

        balances = []
        for contract, result_raw in raw_balances['data'].items():
            data_raw = json.loads(result_raw['Result'])
            balance_raw = data_raw['balance']
            if int(balance_raw) == 0:
                continue

            balances.append(
                BalanceItem.from_api(
                    balance_raw=balance_raw,
                    coin=self._get_token_data(contract),
                    raw=result_raw,
                ))

        return balances
Exemple #7
0
    def _parse_items(self, response: Dict) -> [BalanceItem]:
        try:
            raw_balances = response['data']['items']
        except KeyError as e:
            logger.exception(e)
            return []

        balances = []
        for raw_balance in raw_balances:
            if raw_balance.get(
                    'balance') is None or raw_balance['balance'] == 0:
                logger.debug(
                    "Skipping coin: '%s' - balance is zero.",
                    raw_balance.get("contract_name"),
                )
                continue

            coin_symbol = raw_balance.get('contract_ticker_symbol')
            if coin_symbol == self.coin.symbol:
                # Native coin for given blockchain.
                coin = self.coin
            else:
                coin = Coin.from_api(
                    symbol=raw_balance.get('contract_ticker_symbol'),
                    name=raw_balance.get('contract_name'),
                    decimals=raw_balance.get('contract_decimals', 0),
                    blockchain=self.api_options.blockchain,
                    address=self.to_checksum_address(
                        raw_balance.get('contract_address')),
                    standards=raw_balance.get("supports_erc", []),
                    info=CoinInfo(logo_url=raw_balance.get("logo_url")),
                )

            balances.append(
                BalanceItem.from_api(
                    balance_raw=raw_balance.get('balance'),
                    coin=coin,
                    last_updated=raw_balance.get('last_transferred_at'),
                    raw=raw_balance,
                ))

        return balances
Exemple #8
0
    def _parse_token_balance(self, raw: Dict) -> Optional[BalanceItem]:
        info = raw['account']['data']['parsed']['info']
        if int(info['tokenAmount']['amount']) == 0:
            return

        address = info['mint']

        if address in self.tokens_map:
            token = self._get_token_data(address)
        else:
            token = Coin.from_api(
                blockchain=Blockchain.SOLANA,
                decimals=info['tokenAmount']['decimals'],
                address=address,
            )

        return BalanceItem.from_api(
            balance_raw=info['tokenAmount']['amount'],
            coin=token,
            raw=raw,
        )
 def _parse_eth_balance(self, response: Dict) -> BalanceItem:
     return BalanceItem.from_api(
         balance_raw=response.get('result', 0),
         coin=self.coin,
         raw=response,
     )