eth_portfolio.protocols.lending package
Submodules
eth_portfolio.protocols.lending.compound module
- class eth_portfolio.protocols.lending.compound.Compound[source]
Bases:
LendingProtocol
- async _debt(address, block=None)[source]
Calculates the debt balance for a given address in the Compound protocol.
This method fetches the borrow balance for each market and calculates the debt in terms of the underlying token and its USD value.
- Parameters:
address (ChecksumAddress) – The Ethereum address to calculate the debt for.
block (int | BlockNumber | None) – The block number to query. Defaults to the latest block.
- Returns:
A
TokenBalances
object representing the debt balances.- Return type:
Examples
>>> compound = Compound() >>> debt_balances = await compound._debt("0x1234567890abcdef1234567890abcdef12345678") >>> for token, balance in debt_balances.items(): ... print(f"Token: {token}, Balance: {balance.balance}, USD Value: {balance.usd_value}")
See also
debt()
: Public method to get the debt balances.
- debt = <_ASyncFutureInstanceMethod for <function LendingProtocol.debt> bound to None>
- Parameters:
fn_args (~P)
fn_kwargs (~P)
- Return type:
T
- markets = <_ASyncFutureInstanceMethod for <cyfunction Compound.markets> bound to None>
- Parameters:
fn_args (~P)
fn_kwargs (~P)
- Return type:
T
- underlyings = <_ASyncFutureInstanceMethod for <async_lru._LRUCacheWrapper object> bound to None>
- Parameters:
fn_args (~P)
fn_kwargs (~P)
- Return type:
T
- async eth_portfolio.protocols.lending.compound._borrow_balance_stored(market, address, block=None)[source]
Fetches the stored borrow balance for a given market and address.
This function attempts to call the borrowBalanceStored method on the market contract. If the call reverts, it returns None.
- Parameters:
- Returns:
The stored borrow balance as an integer, or None if the call reverts.
- Return type:
int | None
Examples
>>> market = Contract.from_explorer("0x1234567890abcdef1234567890abcdef12345678") >>> balance = await _borrow_balance_stored(market, "0xabcdefabcdefabcdefabcdefabcdefabcdef") >>> print(balance)
See also
_debt()
: Uses this function to calculate debt balances.
eth_portfolio.protocols.lending.liquity module
- class eth_portfolio.protocols.lending.liquity.Liquity[source]
Bases:
LendingProtocolWithLockedCollateral
Represents the Liquity protocol, a decentralized borrowing protocol that allows users to draw loans against Ether collateral.
This class is a subclass of
LendingProtocolWithLockedCollateral
, which means it maintains a debt balance for a user and holds collateral internally.Examples
>>> liquity = Liquity() >>> balances = await liquity.balances("0xYourAddress", 12345678) >>> print(balances)
See also
LendingProtocolWithLockedCollateral
- async _balances(address, block=None)[source]
Retrieves the collateral balances for a given address at a specific block.
- Parameters:
address (str | HexBytes | AnyAddress | EthAddress) – The Ethereum address of the user.
block (int | BlockNumber | None) – The block number to query.
- Return type:
Examples
>>> balances = await liquity._balances("0xYourAddress", 12345678) >>> print(balances)
See also
- async _debt(address, block=None)[source]
Retrieves the debt balances for a given address at a specific block.
- Parameters:
address (str | HexBytes | AnyAddress | EthAddress) – The Ethereum address of the user.
block (int | BlockNumber | None) – The block number to query.
- Return type:
Examples
>>> debt_balances = await liquity._debt("0xYourAddress", 12345678) >>> print(debt_balances)
See also
- balances = <_ASyncFutureInstanceMethod for <function ProtocolABC.balances> bound to None>
- Parameters:
fn_args (~P)
fn_kwargs (~P)
- Return type:
T
- debt = <_ASyncFutureInstanceMethod for <function LendingProtocol.debt> bound to None>
- Parameters:
fn_args (~P)
fn_kwargs (~P)
- Return type:
T
- get_trove = <async_lru._LRUCacheWrapperInstanceMethod object>[source]
- Parameters:
address (str | HexBytes | AnyAddress | EthAddress)
block (int | BlockNumber)
- Return type:
- networks = [Network.<function Network.name at 0x7fdd2e7f32e0>]
The networks on which the protocol is available.
- start_block
The block number from which the protocol starts.
- troveManager
The contract instance for the Trove Manager.
eth_portfolio.protocols.lending.maker module
- class eth_portfolio.protocols.lending.maker.Maker[source]
Bases:
LendingProtocolWithLockedCollateral
- async _balances(address, block=None)[source]
- Parameters:
address (str | HexBytes | AnyAddress | EthAddress)
block (int | BlockNumber | None)
- Return type:
- async _debt(address, block=None)[source]
- Parameters:
address (str | HexBytes | AnyAddress | EthAddress)
block (int | None)
- Return type:
- _cdp = <async_lru._LRUCacheWrapperInstanceMethod object>[source]
- Parameters:
address (str | HexBytes | AnyAddress | EthAddress)
- Return type:
str | HexBytes | AnyAddress | EthAddress
- _proxy = <async_lru._LRUCacheWrapperInstanceMethod object>[source]
- Parameters:
address (str | HexBytes | AnyAddress | EthAddress)
- Return type:
str | HexBytes | AnyAddress | EthAddress
- _urn = <async_lru._LRUCacheWrapperInstanceMethod object>[source]
- Parameters:
address (str | HexBytes | AnyAddress | EthAddress)
- Return type:
str | HexBytes | AnyAddress | EthAddress
- balances = <_ASyncFutureInstanceMethod for <function ProtocolABC.balances> bound to None>
- Parameters:
fn_args (~P)
fn_kwargs (~P)
- Return type:
T
- debt = <_ASyncFutureInstanceMethod for <function LendingProtocol.debt> bound to None>
- Parameters:
fn_args (~P)
fn_kwargs (~P)
- Return type:
T
- networks = [Network.<function Network.name at 0x7fdd2e7f32e0>]
- eth_portfolio.protocols.lending.maker.encode_bytes(bytestring)
eth_portfolio.protocols.lending.unit module
- class eth_portfolio.protocols.lending.unit.UnitXyz[source]
Bases:
LendingProtocolWithLockedCollateral
- async _balances(address, block=None)[source]
- Parameters:
address (str | HexBytes | AnyAddress | EthAddress)
block (int | BlockNumber | None)
- Return type:
- async _debt(address, block=None)[source]
- Parameters:
address (str | HexBytes | AnyAddress | EthAddress)
block (int | BlockNumber | None)
- Return type:
- balances = <_ASyncFutureInstanceMethod for <function ProtocolABC.balances> bound to None>
- Parameters:
fn_args (~P)
fn_kwargs (~P)
- Return type:
T
- debt = <_ASyncFutureInstanceMethod for <function LendingProtocol.debt> bound to None>
- Parameters:
fn_args (~P)
fn_kwargs (~P)
- Return type:
T
- networks = [Network.<function Network.name at 0x7fdd2e7f32e0>]
Module contents
- eth_portfolio.protocols.lending.has_collateral(protocol)