Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rohan-agarwal-coinbase committed Nov 5, 2024
1 parent a6079cc commit 1e410f3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,34 @@
"type": "function",
},
]

UNISWAP_V3_FACTORY_CONTRACT_ADDRESSES = {
"base-sepolia": "0x4752ba5DBc23f44D87826276BF6Fd6b1C372aD24",
"base-mainnet": "0x33128a8fC17869897dcE68Ed026d694621f6FDfD",
"ethereum-mainnet": "0x1F98431c8aD98523631AE4a59f267346ea31F984",
"arbitrum-mainnet": "0x1F98431c8aD98523631AE4a59f267346ea31F984",
"polygon-mainnet": "0x1F98431c8aD98523631AE4a59f267346ea31F984",
}


def get_contract_address(network: str) -> str:
"""Get the Uniswap V3 Factory contract address for the specified network.
Args:
network (str): The network ID to get the contract address for.
Valid networks are: base-sepolia, base-mainnet, ethereum-mainnet,
arbitrum-mainnet, polygon-mainnet.
Returns:
str: The contract address for the specified network.
Raises:
ValueError: If the specified network is not supported.
"""
network = network.lower()
if network not in UNISWAP_V3_FACTORY_CONTRACT_ADDRESSES:
raise ValueError(
f"Invalid network: {network}. Valid networks are: {', '.join(UNISWAP_V3_FACTORY_CONTRACT_ADDRESSES.keys())}"
)
return UNISWAP_V3_FACTORY_CONTRACT_ADDRESSES[network]
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from cdp import Wallet
from pydantic import BaseModel, Field

from cdp_agentkit_core.actions.uniswap_v3.constants import UNISWAP_V3_FACTORY_ABI
from cdp_agentkit_core.actions.uniswap_v3.constants import (
UNISWAP_V3_FACTORY_ABI,
get_contract_address,
)

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."""
Expand Down Expand Up @@ -37,8 +40,10 @@ def uniswap_v3_create_pool(wallet: Wallet, token_a: str, token_b: str, fee: str)
str: A message containing the pool creation details.
"""
factory_address = get_contract_address(wallet.network_id)

pool = wallet.invoke_contract(
contract_address="0x4752ba5DBc23f44D87826276BF6Fd6b1C372aD24", # TODO - set this based on network id
contract_address=factory_address,
method="createPool",
abi=UNISWAP_V3_FACTORY_ABI,
args={
Expand Down

0 comments on commit 1e410f3

Please sign in to comment.