Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
rohan-agarwal-coinbase committed Nov 5, 2024
1 parent bd3f47e commit b8c06e5
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 25 deletions.
16 changes: 8 additions & 8 deletions cdp-agentkit-core/cdp_agentkit_core/actions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
from cdp_agentkit_core.actions.create_pool import (
CREATE_POOL_PROMPT,
CreatePoolInput,
create_pool,
)
from cdp_agentkit_core.actions.deploy_nft import (
DEPLOY_NFT_PROMPT,
DeployNftInput,
Expand Down Expand Up @@ -48,11 +43,16 @@
TransferInput,
transfer,
)
from cdp_agentkit_core.actions.uniswap_v3.create_pool import (
UNISWAP_V3_CREATE_POOL_PROMPT,
UniswapV3CreatePoolInput,
uniswap_v3_create_pool,
)

__all__ = [
"CREATE_POOL_PROMPT",
"CreatePoolInput",
"create_pool",
"UNISWAP_V3_CREATE_POOL_PROMPT",
"UniswapV3CreatePoolInput",
"uniswap_v3_create_pool",
"DEPLOY_NFT_PROMPT",
"DeployNftInput",
"deploy_nft",
Expand Down
2 changes: 1 addition & 1 deletion cdp-agentkit-core/cdp_agentkit_core/actions/create_pool.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from cdp import Wallet
from pydantic import BaseModel, Field

from cdp_agentkit_core.constants import UNISWAP_V3_FACTORY_ABI
from cdp_agentkit_core.actions.uniswap_v3.constants import UNISWAP_V3_FACTORY_ABI

CREATE_POOL_PROMPT = """
This tool will create a Uniswap v3 pool for trading 2 tokens, one of which can be the native gas token. For native gas token, use the address 0x4200000000000000000000000000000000000006. This tool takes the address of the first token, address of the second token, and the fee to charge for trades as inputs. The fee is denominated in hundredths of a bip (i.e. 1e-6) and must be passed a string. Acceptable fee values are 100, 500, 3000, and 10000."""
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from cdp import Wallet
from pydantic import BaseModel, Field

from cdp_agentkit_core.actions.uniswap_v3.constants import UNISWAP_V3_FACTORY_ABI

UNISWAP_V3_CREATE_POOL_PROMPT = """
This tool will create a Uniswap v3 pool for trading 2 tokens, one of which can be the native gas token. For native gas token, use the address 0x4200000000000000000000000000000000000006, and for ERC20 token, use its contract address. This tool takes the address of the first token, address of the second token, and the fee to charge for trades as inputs. The fee is denominated in hundredths of a bip (i.e. 1e-6) and must be passed a string. Acceptable fee values are 100, 500, 3000, and 10000. Supported networks are Base Sepolia, Base Mainnet, Ethereum Mainnet, Polygon Mainnet, and Arbitrum Mainnet."""


class UniswapV3CreatePoolInput(BaseModel):
"""Input argument schema for create pool action."""

token_a: str = Field(
...,
description="The address of the first token to trade, e.g. 0x4200000000000000000000000000000000000006 for native gas token",
)
token_b: str = Field(
...,
description="The address of the second token to trade, e.g. 0x1234567890123456789012345678901234567890 for ERC20 token",
)
fee: str = Field(
...,
description="The fee to charge for trades, denominated in hundredths of a bip (i.e. 1e-6). Acceptable fee values are 100, 500, 3000, and 10000.",
)


def uniswap_v3_create_pool(wallet: Wallet, token_a: str, token_b: str, fee: str) -> str:
"""Create a Uniswap v3 pool for trading 2 tokens, one of which can be the native gas token.
Args:
wallet (Wallet): The wallet to create the pool from.
token_a (str): The address of the first token to trade.
token_b (str): The address of the second token to trade.
fee (str): The fee to charge for trades, denominated in hundredths of a bip (i.e. 1e-6).
Returns:
str: A message containing the pool creation details.
"""
pool = wallet.invoke_contract(
contract_address="0x4752ba5DBc23f44D87826276BF6Fd6b1C372aD24", # TODO - set this based on network id
method="createPool",
abi=UNISWAP_V3_FACTORY_ABI,
args={
"tokenA": token_a,
"tokenB": token_b,
"fee": fee,
},
).wait()
return f"Created pool for {token_a} and {token_b} with fee {fee} on network {wallet.network_id}.\nTransaction hash for the pool creation: {pool.transaction.transaction_hash}\nTransaction link for the pool creation: {pool.transaction.transaction_link}"
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import pytest

from cdp_agentkit_core.actions.create_pool import (
CreatePoolInput,
create_pool,
from cdp_agentkit_core.actions.uniswap_v3.constants import UNISWAP_V3_FACTORY_ABI
from cdp_agentkit_core.actions.uniswap_v3.create_pool import (
UniswapV3CreatePoolInput,
uniswap_v3_create_pool,
)
from cdp_agentkit_core.constants import UNISWAP_V3_FACTORY_ABI

MOCK_TOKEN_A = "0x4200000000000000000000000000000000000006"
MOCK_TOKEN_B = "0x1234567890123456789012345678901234567890"
Expand All @@ -15,7 +15,7 @@

def test_create_pool_input_model_valid():
"""Test that CreatePoolInput accepts valid parameters."""
input_model = CreatePoolInput(
input_model = UniswapV3CreatePoolInput(
token_a=MOCK_TOKEN_A,
token_b=MOCK_TOKEN_B,
fee=MOCK_FEE,
Expand All @@ -29,7 +29,7 @@ def test_create_pool_input_model_valid():
def test_create_pool_input_model_missing_params():
"""Test that CreatePoolInput raises error when params are missing."""
with pytest.raises(ValueError):
CreatePoolInput()
UniswapV3CreatePoolInput()


def test_create_pool_success(wallet_factory, contract_invocation_factory):
Expand All @@ -45,7 +45,7 @@ def test_create_pool_success(wallet_factory, contract_invocation_factory):
mock_contract_instance, "wait", return_value=mock_contract_instance
) as mock_contract_wait,
):
action_response = create_pool(mock_wallet, MOCK_TOKEN_A, MOCK_TOKEN_B, MOCK_FEE)
action_response = uniswap_v3_create_pool(mock_wallet, MOCK_TOKEN_A, MOCK_TOKEN_B, MOCK_FEE)

expected_response = f"Created pool for {MOCK_TOKEN_A} and {MOCK_TOKEN_B} with fee {MOCK_FEE} on network {mock_wallet.network_id}.\nTransaction hash for the pool creation: {mock_contract_instance.transaction.transaction_hash}\nTransaction link for the pool creation: {mock_contract_instance.transaction.transaction_link}"
assert action_response == expected_response
Expand All @@ -71,7 +71,7 @@ def test_create_pool_api_error(wallet_factory):
mock_wallet, "invoke_contract", side_effect=Exception("API error")
) as mock_invoke:
with pytest.raises(Exception, match="API error"):
create_pool(mock_wallet, MOCK_TOKEN_A, MOCK_TOKEN_B, MOCK_FEE)
uniswap_v3_create_pool(mock_wallet, MOCK_TOKEN_A, MOCK_TOKEN_B, MOCK_FEE)

mock_invoke.assert_called_once_with(
contract_address="0x4752ba5DBc23f44D87826276BF6Fd6b1C372aD24",
Expand Down
13 changes: 7 additions & 6 deletions cdp-langchain/cdp_langchain/agent_toolkits/cdp_toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from langchain_core.tools.base import BaseToolkit

from cdp_agentkit_core.actions import (
CREATE_POOL_PROMPT,
DEPLOY_NFT_PROMPT,
DEPLOY_TOKEN_PROMPT,
GET_BALANCE_PROMPT,
Expand All @@ -14,7 +13,7 @@
REQUEST_FAUCET_FUNDS_PROMPT,
TRADE_PROMPT,
TRANSFER_PROMPT,
CreatePoolInput,
UNISWAP_V3_CREATE_POOL_PROMPT,
DeployNftInput,
DeployTokenInput,
GetBalanceInput,
Expand All @@ -24,6 +23,7 @@
RequestFaucetFundsInput,
TradeInput,
TransferInput,
UniswapV3CreatePoolInput,
)
from cdp_langchain.tools import CdpAction
from cdp_langchain.utils import CdpAgentkitWrapper
Expand Down Expand Up @@ -81,6 +81,7 @@ class CdpToolkit(BaseToolkit):
mint_nft
deploy_nft
register_basename
uniswap_v3_create_pool
Use within an agent:
.. code-block:: python
Expand Down Expand Up @@ -144,10 +145,10 @@ def from_cdp_agentkit_wrapper(cls, cdp_agentkit_wrapper: CdpAgentkitWrapper) ->
"""
actions: list[dict] = [
{
"mode": "create_pool",
"name": "create_pool",
"description": CREATE_POOL_PROMPT,
"args_schema": CreatePoolInput,
"mode": "uniswap_v3_create_pool",
"name": "uniswap_v3_create_pool",
"description": UNISWAP_V3_CREATE_POOL_PROMPT,
"args_schema": UniswapV3CreatePoolInput,
},
{
"mode": "get_wallet_details",
Expand Down
4 changes: 2 additions & 2 deletions cdp-langchain/cdp_langchain/utils/cdp_agentkit_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from pydantic import BaseModel, model_validator

from cdp_agentkit_core.actions import (
create_pool,
deploy_nft,
deploy_token,
get_balance,
Expand All @@ -17,6 +16,7 @@
request_faucet_funds,
trade,
transfer,
uniswap_v3_create_pool,
)


Expand Down Expand Up @@ -83,7 +83,7 @@ def create_pool_wrapper(self, token_a: str, token_b: str, fee: str) -> str:
str: A message containing the pool details.
"""
return create_pool(wallet=self.wallet, token_a=token_a, token_b=token_b, fee=fee)
return uniswap_v3_create_pool(wallet=self.wallet, token_a=token_a, token_b=token_b, fee=fee)

def get_wallet_details_wrapper(self) -> str:
"""Get details about the MPC Wallet by wrapping call to CDP Agentkit Core."""
Expand Down

0 comments on commit b8c06e5

Please sign in to comment.