Skip to content

Commit

Permalink
Merge branch 'master' into rohan/zora-create-token
Browse files Browse the repository at this point in the history
  • Loading branch information
rohan-agarwal-coinbase committed Nov 7, 2024
2 parents dd25e1c + 097702d commit 4225b7d
Show file tree
Hide file tree
Showing 33 changed files with 98 additions and 1,231 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The Coinbase Developer Platform (CDP) Agentkit simplifies bringing your AI Agent
- Getting wallet details and balances
- Transferring and trading tokens
- Registering Basenames
- Deploying ERC20 tokens and creating uniswap_v3 pools for trading
- Deploying ERC20 tokens
- Deploying ERC721 tokens and minting NFTs

## Examples
Expand Down
2 changes: 0 additions & 2 deletions cdp-agentkit-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

### Added

- Added `uniswap_v3_create_pool` action.
- Added `uniswap_v3_get_pool`, `uniswap_v3_get_pool_observe`, `uniswap_v3_get_pool_slot0`, and `uniswap_v3_get_pool_liquidity` actions.
- Added `wow_create_token` action.

## [0.0.1] - 2024-11-04
Expand Down
10 changes: 0 additions & 10 deletions cdp-agentkit-core/cdp_agentkit_core/actions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@
from cdp_agentkit_core.actions.request_faucet_funds import RequestFaucetFundsAction
from cdp_agentkit_core.actions.trade import TradeAction
from cdp_agentkit_core.actions.transfer import TransferAction
from cdp_agentkit_core.actions.uniswap_v3.create_pool import UniswapV3CreatePoolAction
from cdp_agentkit_core.actions.uniswap_v3.get_pool import UniswapV3GetPoolAction
from cdp_agentkit_core.actions.uniswap_v3.get_pool_liquidity import UniswapV3GetPoolLiquidityAction
from cdp_agentkit_core.actions.uniswap_v3.get_pool_observe import UniswapV3GetPoolObserveAction
from cdp_agentkit_core.actions.uniswap_v3.get_pool_slot0 import UniswapV3GetPoolSlot0Action
from cdp_agentkit_core.actions.wow.create_token import WowCreateTokenAction


Expand All @@ -39,11 +34,6 @@ def get_all_cdp_actions() -> list[type[CdpAction]]:
"RequestFaucetFundsAction",
"TradeAction",
"TransferAction",
"UniswapV3CreatePoolAction",
"UniswapV3GetPoolAction",
"UniswapV3GetPoolSlot0Action",
"UniswapV3GetPoolObserveAction",
"UniswapV3GetPoolLiquidityAction",
"WowCreateTokenAction",
"CDP_ACTIONS",
]
5 changes: 4 additions & 1 deletion cdp-agentkit-core/cdp_agentkit_core/actions/deploy_nft.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ def deploy_nft(wallet: Wallet, name: str, symbol: str, base_uri: str) -> str:
str: A message containing the NFT token deployment details.
"""
nft_contract = wallet.deploy_nft(name=name, symbol=symbol, base_uri=base_uri).wait()
try:
nft_contract = wallet.deploy_nft(name=name, symbol=symbol, base_uri=base_uri).wait()
except Exception as e:
return f"Error deploying NFT {e!s}"

return f"Deployed NFT Collection {name} to address {nft_contract.contract_address} on network {wallet.network_id}.\nTransaction hash for the deployment: {nft_contract.transaction.transaction_hash}\nTransaction link for the deployment: {nft_contract.transaction.transaction_link}"

Expand Down
7 changes: 5 additions & 2 deletions cdp-agentkit-core/cdp_agentkit_core/actions/deploy_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ def deploy_token(wallet: Wallet, name: str, symbol: str, total_supply: str) -> s
str: A message containing the deployed token contract address and details
"""
token_contract = wallet.deploy_token(name=name, symbol=symbol, total_supply=total_supply)
try:
token_contract = wallet.deploy_token(name=name, symbol=symbol, total_supply=total_supply)

token_contract.wait()
token_contract.wait()
except Exception as e:
return f"Error deploying token {e!s}"

return f"Deployed ERC20 token contract {name} ({symbol}) with total supply of {total_supply} tokens at address {token_contract.contract_address}. Transaction link: {token_contract.transaction.transaction_link}"

Expand Down
10 changes: 7 additions & 3 deletions cdp-agentkit-core/cdp_agentkit_core/actions/get_balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ def get_balance(wallet: Wallet, asset_id: str) -> str:
"""
# for each address in the wallet, get the balance for the asset
balances = {}
for address in wallet.addresses:
balance = address.balance(asset_id)
balances[address.address_id] = balance

try:
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}"

# Format each balance entry on a new line
balance_lines = [f" {addr}: {balance}" for addr, balance in balances.items()]
Expand Down
9 changes: 6 additions & 3 deletions cdp-agentkit-core/cdp_agentkit_core/actions/mint_nft.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ def mint_nft(wallet: Wallet, contract_address: str, destination: str) -> str:
"""
mint_args = {"to": destination, "quantity": "1"}

mint_invocation = wallet.invoke_contract(
contract_address=contract_address, method="mint", args=mint_args
).wait()
try:
mint_invocation = wallet.invoke_contract(
contract_address=contract_address, method="mint", args=mint_args
).wait()
except Exception as e:
return f"Error minting NFT {e!s}"

return f"Minted NFT from contract {contract_address} to address {destination} on network {wallet.network_id}.\nTransaction hash for the mint: {mint_invocation.transaction.transaction_hash}\nTransaction link for the mint: {mint_invocation.transaction.transaction_link}"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ def request_faucet_funds(wallet: Wallet, asset_id: str | None = None) -> str:
str: Confirmation message with transaction details
"""
# Request funds from the faucet.
faucet_tx = wallet.faucet(asset_id=asset_id if asset_id else None)

# Wait for the faucet transaction to be confirmed.
faucet_tx.wait()
try:
# Request funds from the faucet.
faucet_tx = wallet.faucet(asset_id=asset_id if asset_id else None)

# Wait for the faucet transaction to be confirmed.
faucet_tx.wait()
except Exception as e:
return f"Error requesting faucet funds {e!s}"

return f"Received {asset_id} from the faucet. Transaction: {faucet_tx.transaction_link}"

Expand Down
9 changes: 6 additions & 3 deletions cdp-agentkit-core/cdp_agentkit_core/actions/trade.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@ def trade(wallet: Wallet, amount: str, from_asset_id: str, to_asset_id: str) ->
str: A message containing the trade details.
"""
trade_result = wallet.trade(
amount=amount, from_asset_id=from_asset_id, to_asset_id=to_asset_id
).wait()
try:
trade_result = wallet.trade(
amount=amount, from_asset_id=from_asset_id, to_asset_id=to_asset_id
).wait()
except Exception as e:
return f"Error trading assets {e!s}"

return f"Traded {amount} of {from_asset_id} for {trade_result.to_amount} of {to_asset_id}.\nTransaction hash for the trade: {trade_result.transaction.transaction_hash}\nTransaction link for the trade: {trade_result.transaction.transaction_link}"

Expand Down
9 changes: 6 additions & 3 deletions cdp-agentkit-core/cdp_agentkit_core/actions/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ def transfer(
str: A message containing the transfer details.
"""
transfer_result = wallet.transfer(
amount=amount, asset_id=asset_id, destination=destination, gasless=gasless
).wait()
try:
transfer_result = wallet.transfer(
amount=amount, asset_id=asset_id, destination=destination, gasless=gasless
).wait()
except Exception as e:
return f"Error transferring the asset {e!s}"

return f"Transferred {amount} of {asset_id} to {destination}.\nTransaction hash for the transfer: {transfer_result.transaction_hash}\nTransaction link for the transfer: {transfer_result.transaction_link}"

Expand Down
Loading

0 comments on commit 4225b7d

Please sign in to comment.