-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Superfluid flow management actions (create, update, delete)
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
Showing
9 changed files
with
587 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
58 changes: 58 additions & 0 deletions
58
cdp-agentkit-core/python/cdp_agentkit_core/actions/superfluid/constants.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
} | ||
] |
89 changes: 89 additions & 0 deletions
89
cdp-agentkit-core/python/cdp_agentkit_core/actions/superfluid/create_flow.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
77 changes: 77 additions & 0 deletions
77
cdp-agentkit-core/python/cdp_agentkit_core/actions/superfluid/delete_flow.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
89 changes: 89 additions & 0 deletions
89
cdp-agentkit-core/python/cdp_agentkit_core/actions/superfluid/update_flow.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.