Skip to content

Commit

Permalink
feat: add Superfluid flow management actions (create, update, delete)
Browse files Browse the repository at this point in the history
refactor: rename flow management classes and functions for consistency and add networks to prompts

refactor: rename Superfluid flow action classes for consistency

fix: lint issues
  • Loading branch information
Dayitva committed Jan 23, 2025
1 parent 4b60a25 commit e6b145b
Show file tree
Hide file tree
Showing 9 changed files with 587 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
from cdp_agentkit_core.actions.pyth.fetch_price_feed_id import PythFetchPriceFeedIDAction
from cdp_agentkit_core.actions.register_basename import RegisterBasenameAction
from cdp_agentkit_core.actions.request_faucet_funds import RequestFaucetFundsAction
from cdp_agentkit_core.actions.superfluid.create_flow import SuperfluidCreateFlowAction
from cdp_agentkit_core.actions.superfluid.delete_flow import SuperfluidDeleteFlowAction
from cdp_agentkit_core.actions.superfluid.update_flow import SuperfluidUpdateFlowAction
from cdp_agentkit_core.actions.trade import TradeAction
from cdp_agentkit_core.actions.transfer import TransferAction
from cdp_agentkit_core.actions.transfer_nft import TransferNftAction
Expand Down Expand Up @@ -50,4 +53,7 @@ def get_all_cdp_actions() -> list[type[CdpAction]]:
"WrapEthAction",
"PythFetchPriceFeedIDAction",
"PythFetchPriceAction",
"SuperfluidCreateFlowAction",
"SuperfluidUpdateFlowAction",
"SuperfluidDeleteFlowAction",
]
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
CREATE_ABI = [
{
"inputs": [
{
"internalType": "contract ISuperToken",
"name": "token",
"type": "address",
},
{"internalType": "address", "name": "sender", "type": "address"},
{"internalType": "address", "name": "receiver", "type": "address"},
{"internalType": "int96", "name": "flowrate", "type": "int96"},
{"internalType": "bytes", "name": "userData", "type": "bytes"},
],
"name": "createFlow",
"outputs": [{"internalType": "bool", "name": "", "type": "bool"}],
"stateMutability": "nonpayable",
"type": "function",
}
]

UPDATE_ABI = [
{
"inputs": [
{
"internalType": "contract ISuperToken",
"name": "token",
"type": "address",
},
{"internalType": "address", "name": "sender", "type": "address"},
{"internalType": "address", "name": "receiver", "type": "address"},
{"internalType": "int96", "name": "flowrate", "type": "int96"},
{"internalType": "bytes", "name": "userData", "type": "bytes"},
],
"name": "updateFlow",
"outputs": [{"internalType": "bool", "name": "", "type": "bool"}],
"stateMutability": "nonpayable",
"type": "function",
}
]

DELETE_ABI = [
{
"inputs": [
{
"internalType": "contract ISuperToken",
"name": "token",
"type": "address",
},
{"internalType": "address", "name": "sender", "type": "address"},
{"internalType": "address", "name": "receiver", "type": "address"},
{"internalType": "bytes", "name": "userData", "type": "bytes"},
],
"name": "deleteFlow",
"outputs": [{"internalType": "bool", "name": "", "type": "bool"}],
"stateMutability": "nonpayable",
"type": "function",
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
from collections.abc import Callable

from cdp import Wallet
from pydantic import BaseModel, Field

from cdp_agentkit_core.actions import CdpAction
from cdp_agentkit_core.actions.superfluid.constants import (
CREATE_ABI,
)

SUPERFLUID_CREATE_FLOW_PROMPT = """
This tool will create a money flow to a specified token recipient using Superfluid. Do not use this tool for any other purpose, or trading other assets.
Inputs:
- Wallet address to send the tokens to
- Super token contract address
- The flowrate of flow in wei per second
Important notes:
- The flowrate cannot have any decimal points, since the unit of measurement is wei per second.
- Make sure to use the exact amount provided, and if there's any doubt, check by getting more information before continuing with the action.
- 1 wei = 0.000000000000000001 ETH
- This is supported on the following networks:
- Base Sepolia (ie, 'base-sepolia')
- Base Mainnet (ie, 'base', 'base-mainnet')
- Ethereum Mainnet (ie, 'ethereum', 'ethereum-mainnet')
- Polygon Mainnet (ie, 'polygon', 'polygon-mainnet')
- Arbitrum Mainnet (ie, 'arbitrum', 'arbitrum-mainnet')
- Optimism, Celo, Scroll, Avalanche, Gnosis, BNB Smart Chain, Degen Chain, Avalance Fuji, Optimism Sepolia and Scroll Sepolia
"""

class SuperfluidCreateFlowInput(BaseModel):
"""Input argument schema for creating a flow."""

recipient: str = Field(
...,
description="The wallet address of the recipient"
)

token_address: str = Field(
...,
description="The address of the token that will be streamed"
)

flow_rate: str = Field(
...,
description="The flow rate of tokens in wei per second"
)

def superfluid_create_flow(wallet: Wallet, recipient: str, token_address: str, flow_rate: str) -> str:
"""Create a money flow using Superfluid.
Args:
wallet (Wallet): The wallet initiating the flow.
recipient (str): Recipient's wallet address.
token_address (str): Address of the token that will be streamed.
flow_rate (str): Rate of token flow in wei per second.
Returns:
str: Confirmation of flow creation.
"""
try:
invocation = wallet.invoke_contract(
contract_address="0xcfA132E353cB4E398080B9700609bb008eceB125",
abi=CREATE_ABI,
method="createFlow",
args={
"token": token_address,
"sender": wallet.default_address.address_id,
"receiver": recipient,
"flowrate": flow_rate,
"userData": "0x"
})

invocation.wait()

return f"Flow created successfully. Result: {invocation}"

except Exception as e:
return f"Error creating flow: {e!s}"

class SuperfluidCreateFlowAction(CdpAction):
"""Create flow action."""

name: str = "superfluid_create_flow"
description: str = SUPERFLUID_CREATE_FLOW_PROMPT
args_schema: type[BaseModel] | None = SuperfluidCreateFlowInput
func: Callable[..., str] = superfluid_create_flow
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
from collections.abc import Callable

from cdp import Wallet
from pydantic import BaseModel, Field

from cdp_agentkit_core.actions import CdpAction
from cdp_agentkit_core.actions.superfluid.constants import (
DELETE_ABI,
)

SUPERFLUID_DELETE_FLOW_PROMPT = """
This tool will delete an existing money flow to a token recipient using Superfluid. Do not use this tool for any other purpose, or trading other assets.
Inputs:
- Wallet address that the tokens are being streamed to or being streamed from
- Super token contract address
Important Notes:
- This is supported on the following networks:
- Base Sepolia (ie, 'base-sepolia')
- Base Mainnet (ie, 'base', 'base-mainnet')
- Ethereum Mainnet (ie, 'ethereum', 'ethereum-mainnet')
- Polygon Mainnet (ie, 'polygon', 'polygon-mainnet')
- Arbitrum Mainnet (ie, 'arbitrum', 'arbitrum-mainnet')
- Optimism, Celo, Scroll, Avalanche, Gnosis, BNB Smart Chain, Degen Chain, Avalance Fuji, Optimism Sepolia and Scroll Sepolia
"""

class SuperfluidDeleteFlowInput(BaseModel):
"""Input argument schema for deleting a flow."""

recipient: str = Field(
...,
description="The wallet address of the recipient"
)

token_address: str = Field(
...,
description="The address of the token being flowed"
)

def superfluid_delete_flow(wallet: Wallet, recipient: str, token_address: str) -> str:
"""Delete an existing money flow using Superfluid.
Args:
wallet (Wallet): The wallet closing the flow.
recipient (str): Recipient's wallet address.
token_address (str): Address of the token being streamed.
Returns:
str: Confirmation of flow closure.
"""
try:
invocation = wallet.invoke_contract(
contract_address="0xcfA132E353cB4E398080B9700609bb008eceB125",
abi=DELETE_ABI,
method="deleteFlow",
args={
"token": token_address,
"sender": wallet.default_address.address_id,
"receiver": recipient,
"userData": "0x"
})

invocation.wait()

return f"Flow deleted successfully. Result: {invocation}"
except Exception as e:
return f"Error deleting flow: {e!s}"

class SuperfluidDeleteFlowAction(CdpAction):
"""Delete flow action."""

name: str = "superfluid_delete_flow"
description: str = SUPERFLUID_DELETE_FLOW_PROMPT
args_schema: type[BaseModel] | None = SuperfluidDeleteFlowInput
func: Callable[..., str] = superfluid_delete_flow
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
from collections.abc import Callable

from cdp import Wallet
from pydantic import BaseModel, Field

from cdp_agentkit_core.actions import CdpAction
from cdp_agentkit_core.actions.superfluid.constants import (
UPDATE_ABI,
)

SUPERFLUID_UPDATE_FLOW_PROMPT = """
This tool will update an existing money flow to a specified token recipient using Superfluid. Do not use this tool for any other purpose, or trading other assets.
Inputs:
- Wallet address that the tokens are being streamed to
- Super token contract address
- The new flowrate of flow in wei per second
Important notes:
- The flowrate cannot have any decimal points, since the unit of measurement is wei per second.
- Make sure to use the exact amount provided, and if there's any doubt, check by getting more information before continuing with the action.
- 1 wei = 0.000000000000000001 ETH
- This is supported on the following networks:
- Base Sepolia (ie, 'base-sepolia')
- Base Mainnet (ie, 'base', 'base-mainnet')
- Ethereum Mainnet (ie, 'ethereum', 'ethereum-mainnet')
- Polygon Mainnet (ie, 'polygon', 'polygon-mainnet')
- Arbitrum Mainnet (ie, 'arbitrum', 'arbitrum-mainnet')
- Optimism, Celo, Scroll, Avalanche, Gnosis, BNB Smart Chain, Degen Chain, Avalance Fuji, Optimism Sepolia and Scroll Sepolia
"""

class SuperfluidUpdateFlowInput(BaseModel):
"""Input argument schema for updating a flow."""

recipient: str = Field(
...,
description="The wallet address of the recipient"
)

token_address: str = Field(
...,
description="The address of the token that is being streamed"
)

new_flow_rate: str = Field(
...,
description="The new flow rate of tokens in wei per second"
)

def superfluid_update_flow(wallet: Wallet, recipient: str, token_address: str, new_flow_rate: str) -> str:
"""Update an existing money flow using Superfluid.
Args:
wallet (Wallet): The wallet initiating the update.
recipient (str): Recipient's wallet address.
token_address (str): Address of the token that is being streamed.
new_flow_rate (str): New rate of token flow in wei per second.
Returns:
str: Confirmation of flow update.
"""
try:
invocation = wallet.invoke_contract(
contract_address="0xcfA132E353cB4E398080B9700609bb008eceB125",
abi=UPDATE_ABI,
method="updateFlow",
args={
"token": token_address,
"sender": wallet.default_address.address_id,
"receiver": recipient,
"flowrate": new_flow_rate,
"userData": "0x"
})

invocation.wait()

return f"Flow updated successfully. Result: {invocation}"

except Exception as e:
return f"Error updating flow: {e!s}"

class SuperfluidUpdateFlowAction(CdpAction):
"""Update flow action."""

name: str = "superfluid_update_flow"
description: str = SUPERFLUID_UPDATE_FLOW_PROMPT
args_schema: type[BaseModel] | None = SuperfluidUpdateFlowInput
func: Callable[..., str] = superfluid_update_flow
Loading

0 comments on commit e6b145b

Please sign in to comment.