-
Notifications
You must be signed in to change notification settings - Fork 289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get Balance for Other Wallets Fixes #291 #293
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,12 +1,13 @@ | ||||||
from collections.abc import Callable | ||||||
from typing import Optional | ||||||
|
||||||
from cdp import Wallet | ||||||
from cdp import Cdp, Wallet | ||||||
from pydantic import BaseModel, Field | ||||||
|
||||||
from cdp_agentkit_core.actions import CdpAction | ||||||
|
||||||
GET_BALANCE_PROMPT = """ | ||||||
This tool will get the balance of all the addresses in the wallet for a given asset. | ||||||
This tool will get the balance of address. | ||||||
It takes the asset ID as input. Always use 'eth' for the native asset ETH and 'usdc' for USDC. | ||||||
""" | ||||||
|
||||||
|
@@ -18,10 +19,14 @@ class GetBalanceInput(BaseModel): | |||||
..., | ||||||
description="The asset ID to get the balance for, e.g. `eth`, `0x036CbD53842c5426634e7929541eC2318f3dCF7e`", | ||||||
) | ||||||
address_to_fund: Optional[str] = Field( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: rename to just |
||||||
None, | ||||||
description="The address to fund. If not provided, the default address of the wallet will be used.", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please see suggestion
Suggested change
|
||||||
) | ||||||
|
||||||
|
||||||
def get_balance(wallet: Wallet, asset_id: str) -> str: | ||||||
"""Get balance for all addresses in the wallet for a given asset. | ||||||
def get_balance(wallet: Wallet, asset_id: str, address_to_fund: Optional[str]) -> str: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: rename to just |
||||||
"""Get balance for the address defined | ||||||
|
||||||
Args: | ||||||
wallet (Wallet): The wallet to get the balance for. | ||||||
|
@@ -33,11 +38,15 @@ def get_balance(wallet: Wallet, asset_id: str) -> str: | |||||
""" | ||||||
# for each address in the wallet, get the balance for the asset | ||||||
balances = {} | ||||||
|
||||||
try: | ||||||
for address in wallet.addresses: | ||||||
balance = address.balance(asset_id) | ||||||
balances[address.address_id] = balance | ||||||
if address_to_fund: | ||||||
balances[address_to_fund] = Cdp.api_clients.external_addresses.get_external_address_balance( | ||||||
network_id=wallet.network_id, address_id=address_to_fund, asset_id=asset_id | ||||||
) | ||||||
else: | ||||||
for address in wallet.addresses: | ||||||
balance = address.balance(asset_id) | ||||||
balances[address.address_id] = balance | ||||||
except Exception as e: | ||||||
return f"Error getting balance for all addresses in the wallet {e!s}" | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see suggestion