coinbase_agentkit.action_providers.compound package

Submodules

coinbase_agentkit.action_providers.compound.compound_action_provider module

Compound action provider for interacting with Compound protocol.

class coinbase_agentkit.action_providers.compound.compound_action_provider.CompoundActionProvider

Bases: ActionProvider[EvmWalletProvider]

Provides actions for interacting with Compound protocol.

borrow(wallet_provider, args)

Borrow base assets from Compound.

Parameters:
  • wallet_provider (EvmWalletProvider) – The wallet to use for the borrow operation.

  • args (dict[str, Any]) – The input arguments for the borrow operation.

Returns:

A message containing the result of the borrow operation.

Return type:

str

get_portfolio(wallet_provider, args)

Get portfolio details from Compound.

Parameters:
  • wallet_provider (EvmWalletProvider) – The wallet to use for getting details.

  • args (dict[str, Any]) – The input arguments containing comet_address and account.

Returns:

A markdown formatted string with portfolio details.

Return type:

str

repay(wallet_provider, args)

Repay borrowed assets to Compound.

Parameters:
  • wallet_provider (EvmWalletProvider) – The wallet to use for the repay operation.

  • args (dict[str, Any]) – The input arguments for the repay operation.

Returns:

A message containing the result of the repay operation.

Return type:

str

supply(wallet_provider, args)

Supply collateral assets to Compound.

Parameters:
  • wallet_provider (EvmWalletProvider) – The wallet to use for the supply operation.

  • args (dict[str, Any]) – The input arguments for the supply operation.

Returns:

A message containing the result of the supply operation.

Return type:

str

supports_network(network)

Check if network is supported by Compound.

Return type:

bool

withdraw(wallet_provider, args)

Withdraw collateral assets from Compound.

Parameters:
  • wallet_provider (EvmWalletProvider) – The wallet to use for the withdraw operation.

  • args (dict[str, Any]) – The input arguments for the withdraw operation.

Returns:

A message containing the result of the withdraw operation.

Return type:

str

coinbase_agentkit.action_providers.compound.compound_action_provider.compound_action_provider()

Create a new CompoundActionProvider instance.

Return type:

CompoundActionProvider

coinbase_agentkit.action_providers.compound.constants module

Constants for Compound action provider.

coinbase_agentkit.action_providers.compound.schemas module

Schemas for Compound action provider.

class coinbase_agentkit.action_providers.compound.schemas.CompoundBorrowSchema(**data)

Bases: BaseModel

Input schema for borrowing assets from Compound.

amount: str
asset_id: Literal['weth', 'usdc']
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class coinbase_agentkit.action_providers.compound.schemas.CompoundPortfolioSchema(**data)

Bases: BaseModel

Input schema for getting portfolio details from Compound.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class coinbase_agentkit.action_providers.compound.schemas.CompoundRepaySchema(**data)

Bases: BaseModel

Input schema for repaying borrowed assets to Compound.

amount: str
asset_id: Literal['weth', 'usdc']
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class coinbase_agentkit.action_providers.compound.schemas.CompoundSupplySchema(**data)

Bases: BaseModel

Input schema for supplying assets to Compound.

amount: str
asset_id: Literal['weth', 'cbeth', 'cbbtc', 'wsteth', 'usdc']
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class coinbase_agentkit.action_providers.compound.schemas.CompoundWithdrawSchema(**data)

Bases: BaseModel

Input schema for withdrawing assets from Compound.

amount: str
asset_id: Literal['weth', 'cbeth', 'cbbtc', 'wsteth', 'usdc']
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

coinbase_agentkit.action_providers.compound.utils module

Utility functions for Compound action provider.

coinbase_agentkit.action_providers.compound.utils.format_amount_from_decimals(amount, decimals)

Format an atomic amount to a human-readable string.

Parameters:
  • amount (int) – The amount in atomic units.

  • decimals (int) – The number of decimals for the token.

Returns:

The amount as a human-readable string.

Return type:

str

coinbase_agentkit.action_providers.compound.utils.format_amount_with_decimals(amount, decimals)

Format a human-readable amount with the correct number of decimals.

Parameters:
  • amount (str) – The amount as a string (e.g. “0.1”).

  • decimals (int) – The number of decimals for the token.

Returns:

The amount in atomic units.

Return type:

int

coinbase_agentkit.action_providers.compound.utils.get_base_token_address(wallet, comet_address)

Get the base token address from the Compound market.

Parameters:
  • wallet (EvmWalletProvider) – The wallet provider for reading from contracts.

  • comet_address (str) – The address of the Compound Comet contract.

Returns:

The address of the base token.

Return type:

str

coinbase_agentkit.action_providers.compound.utils.get_borrow_details(wallet, compound_address)

Get the borrow amount, token symbol, and price for a wallet’s position.

Parameters:
  • wallet (EvmWalletProvider) – The wallet to check the position for.

  • compound_address (str) – The address of the Compound market.

Returns:

Dictionary containing:

Token Symbol (str): The symbol of the base token. Borrow Amount (Decimal): The human-readable amount borrowed. Price (Decimal): The price of the base token in USD.

Return type:

dict

coinbase_agentkit.action_providers.compound.utils.get_collateral_balance(wallet, compound_address, asset_address)

Get the collateral balance of a specific asset for a wallet using wallet.read_contract.

Parameters:
  • wallet (EvmWalletProvider) – The wallet to check the balance for.

  • compound_address (str) – The address of the Compound market.

  • asset_address (str) – The address of the asset to check.

Returns:

The collateral balance in atomic units.

Return type:

int

coinbase_agentkit.action_providers.compound.utils.get_health_ratio(wallet, compound_address)

Calculate the current health ratio of a wallet’s Compound position.

Health ratio is calculated using human-readable values:
  • Borrow value = (human borrow amount) * (price)

  • Collateral value = Σ (human supply amount * price * collateral factor)

A ratio >= 1 indicates a healthy position. Returns infinity if there are no borrows.

Parameters:
  • wallet (EvmWalletProvider) – The wallet to check the position for.

  • compound_address (str) – The address of the Compound market.

Returns:

The current health ratio.

Return type:

Decimal

coinbase_agentkit.action_providers.compound.utils.get_health_ratio_after_borrow(wallet, compound_address, borrow_amount)

Calculate what the health ratio would be after a proposed borrow.

Parameters:
  • wallet (EvmWalletProvider) – The wallet to check the position for.

  • compound_address (str) – The address of the Compound market.

  • borrow_amount (str) – The additional amount to borrow in atomic units.

Returns:

The projected health ratio after the borrow.

Returns infinity if there would be no borrows.

Return type:

Decimal

coinbase_agentkit.action_providers.compound.utils.get_health_ratio_after_withdraw(wallet, compound_address, asset_address, withdraw_amount)

Calculate what the health ratio would be after a proposed withdrawal.

Parameters:
  • wallet (EvmWalletProvider) – The wallet to check the position for.

  • compound_address (str) – The address of the Compound market.

  • asset_address (str) – The address of the asset to withdraw.

  • withdraw_amount (str) – The amount to withdraw in atomic units.

Returns:

The projected health ratio after the withdrawal.

Returns infinity if there would be no borrows.

Return type:

Decimal

coinbase_agentkit.action_providers.compound.utils.get_portfolio_details_markdown(wallet, comet_address)

Get formatted portfolio details in markdown.

Parameters:
  • wallet (EvmWalletProvider) – The wallet to use for getting details

  • comet_address (str) – The address of the Compound Comet contract

Returns:

Markdown formatted portfolio details

Return type:

str

coinbase_agentkit.action_providers.compound.utils.get_price_feed_data(wallet, price_feed_address)

Get the latest price data from a Chainlink price feed using wallet.read_contract.

Parameters:
  • wallet (EvmWalletProvider) – The wallet provider for reading from contracts.

  • price_feed_address (str) – The address of the price feed contract.

Returns:

The price and timestamp.

Return type:

tuple[int, int]

coinbase_agentkit.action_providers.compound.utils.get_supply_details(wallet, compound_address)

Get supply details for all assets supplied by the wallet.

For each asset supplied the raw collateral balance (atomic units) is converted to a human-readable value using token decimals. Additionally, the price (in 8-decimals) is converted to USD and the collateral factor is converted from a raw 1e18 value to a fraction.

Parameters:
  • wallet (EvmWalletProvider) – The wallet to check the position for.

  • compound_address (str) – The address of the Compound market.

Returns:

List of dictionaries containing:

Token Symbol (str): Symbol of the supplied token. Supply Amount (Decimal): Human-readable supplied amount. Price (Decimal): Price in USD. Collateral Factor (Decimal): Borrow collateral factor as a fraction. Decimals (int): Number of decimals for the token.

Return type:

List[dict]

coinbase_agentkit.action_providers.compound.utils.get_token_balance(wallet, token_address)

Get the balance of a token for an account using wallet.read_contract.

Parameters:
  • wallet (EvmWalletProvider) – The wallet provider for reading from contracts.

  • token_address (str) – The address of the token.

  • account – The address of the account.

Returns:

The balance in atomic units.

Return type:

int

coinbase_agentkit.action_providers.compound.utils.get_token_decimals(wallet, token_address)

Get the number of decimals for a token using wallet.read_contract.

Parameters:
  • wallet (EvmWalletProvider) – The wallet provider for reading from contracts.

  • token_address (str) – The address of the token.

Returns:

The number of decimals for the token.

Return type:

int

coinbase_agentkit.action_providers.compound.utils.get_token_symbol(wallet, token_address)

Get a token’s symbol from its contract using wallet.read_contract.

Parameters:
  • wallet (EvmWalletProvider) – The wallet provider for reading from contracts.

  • token_address (str) – The address of the token contract.

Returns:

The token symbol.

Return type:

str

Module contents

Compound action provider for borrowing and lending.