Skip to content

Commit

Permalink
Rename
Browse files Browse the repository at this point in the history
  • Loading branch information
rohan-agarwal-coinbase committed Nov 13, 2024
1 parent eeaa577 commit 0651f59
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
10 changes: 5 additions & 5 deletions cdp-agentkit-core/cdp_agentkit_core/actions/wow/buy_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@ class WowBuyTokenInput(BaseModel):
description="The WOW token contract address, such as `0x036CbD53842c5426634e7929541eC2318f3dCF7e`",
)

amount_eth: str = Field(
amount_eth_in_wei: str = Field(
...,
description="Amount of ETH to spend (in wei), meaning 1 is 1 wei or 0.000000000000000001 of ETH",
)


def wow_buy_token(wallet: Wallet, contract_address: str, amount_eth: str) -> str:
def wow_buy_token(wallet: Wallet, contract_address: str, amount_eth_in_wei: str) -> str:
"""Buy a Zora Wow ERC20 memecoin with ETH.
Args:
wallet (Wallet): The wallet to create the token from.
contract_address (str): The WOW token contract address, such as `0x036CbD53842c5426634e7929541eC2318f3dCF7e`
amount_eth (str): Amount of ETH to spend (in wei), meaning 1 is 1 wei or 0.000000000000000001 of ETH
amount_eth_in_wei (str): Amount of ETH to spend (in wei), meaning 1 is 1 wei or 0.000000000000000001 of ETH
Returns:
str: A message containing the token purchase details.
"""
token_quote = get_buy_quote(wallet.network_id, contract_address, amount_eth)
token_quote = get_buy_quote(wallet.network_id, contract_address, amount_eth_in_wei)

# Multiply by 99/100 and floor to get 99% of quote as minimum
min_tokens = str(int((token_quote * 99) // 100)) # Using integer division to floor the result
Expand All @@ -60,7 +60,7 @@ def wow_buy_token(wallet: Wallet, contract_address: str, amount_eth: str) -> str
"sqrtPriceLimitX96": "0", # TODO
"comment": "",
},
amount=amount_eth,
amount=amount_eth_in_wei,
asset_id="wei",
).wait()

Expand Down
16 changes: 8 additions & 8 deletions cdp-agentkit-core/cdp_agentkit_core/actions/wow/quotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,49 +21,49 @@ def get_current_supply(token_address):
return test


def get_buy_quote(network_id: str, token_address: str, amount_eth: str):
def get_buy_quote(network_id: str, token_address: str, amount_eth_in_wei: str):
"""Get quote for buying tokens.
Args:
network_id: Network ID, which is either `base-sepolia` or `base-mainnet`
token_address: Address of the token contract, such as `0x036CbD53842c5426634e7929541eC2318f3dCF7e`
amount_eth: Amount of ETH to buy (in wei), meaning 1 is 1 wei or 0.000000000000000001 of ETH
amount_eth_in_wei: Amount of ETH to buy (in wei), meaning 1 is 1 wei or 0.000000000000000001 of ETH
"""
has_graduated = get_has_graduated(network_id, token_address)
token_quote = (
has_graduated
and (get_uniswap_quote(network_id, token_address, amount_eth, "buy")).amount_out
and (get_uniswap_quote(network_id, token_address, amount_eth_in_wei, "buy")).amount_out
or SmartContract.read(
network_id,
token_address,
"getEthBuyQuote",
abi=WOW_ABI,
args={"ethOrderSize": str(amount_eth)},
args={"ethOrderSize": str(amount_eth_in_wei)},
)
)
return token_quote


def get_sell_quote(network_id: str, token_address: str, amount_tokens: str):
def get_sell_quote(network_id: str, token_address: str, amount_tokens_in_wei: str):
"""Get quote for selling tokens.
Args:
network_id: Network ID, which is either `base-sepolia` or `base-mainnet`
token_address: Address of the token contract, such as `0x036CbD53842c5426634e7929541eC2318f3dCF7e`
amount_tokens (str): Amount of tokens to sell (in wei), meaning 1 is 1 wei or 0.000000000000000001 of the token
amount_tokens_in_wei (str): Amount of tokens to sell (in wei), meaning 1 is 1 wei or 0.000000000000000001 of the token
"""
has_graduated = get_has_graduated(network_id, token_address)
token_quote = (
has_graduated
and (get_uniswap_quote(network_id, token_address, amount_tokens, "sell")).amount_out
and (get_uniswap_quote(network_id, token_address, amount_tokens_in_wei, "sell")).amount_out
or SmartContract.read(
network_id,
token_address,
"getTokenSellQuote",
WOW_ABI,
args={"tokenOrderSize": str(amount_tokens)},
args={"tokenOrderSize": str(amount_tokens_in_wei)},
)
)
return token_quote
10 changes: 5 additions & 5 deletions cdp-agentkit-core/cdp_agentkit_core/actions/wow/sell_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@ class WowSellTokenInput(BaseModel):
description="The WOW token contract address, such as `0x036CbD53842c5426634e7929541eC2318f3dCF7e`",
)

amount_tokens: str = Field(
amount_tokens_in_wei: str = Field(
...,
description="Amount of tokens to sell (in wei), meaning 1 is 1 wei or 0.000000000000000001 of the token",
)


def wow_sell_token(wallet: Wallet, contract_address: str, amount_tokens: str):
def wow_sell_token(wallet: Wallet, contract_address: str, amount_tokens_in_wei: str):
"""Sell WOW tokens for ETH.
Args:
wallet (Wallet): The wallet to sell the tokens from.
contract_address (str): The WOW token contract address, such as `0x036CbD53842c5426634e7929541eC2318f3dCF7e`
amount_tokens (str): Amount of tokens to sell (in wei), meaning 1 is 1 wei or 0.000000000000000001 of the token
amount_tokens_in_wei (str): Amount of tokens to sell (in wei), meaning 1 is 1 wei or 0.000000000000000001 of the token
Returns:
str: A message confirming the sale with the transaction hash
"""
eth_quote = get_sell_quote(wallet.network_id, contract_address, amount_tokens)
eth_quote = get_sell_quote(wallet.network_id, contract_address, amount_tokens_in_wei)
has_graduated = get_has_graduated(wallet.network_id, contract_address)

# Multiply by 98/100 and floor to get 98% of quote as minimum (slippage protection)
Expand All @@ -52,7 +52,7 @@ def wow_sell_token(wallet: Wallet, contract_address: str, amount_tokens: str):
method="sell",
abi=WOW_ABI,
args={
"tokensToSell": str(amount_tokens),
"tokensToSell": str(amount_tokens_in_wei),
"recipient": wallet.default_address.address_id,
"orderReferrer": "0x0000000000000000000000000000000000000000",
"comment": "",
Expand Down

0 comments on commit 0651f59

Please sign in to comment.