├── lend_borrow_agent ├── __init__.py ├── test │ ├── __init__.py │ ├── pytest.ini │ └── test_lend_borrow.py ├── .gitignore ├── hive_config.toml ├── 2_deploy_contracts.js ├── requirements.txt ├── .env.example ├── README.md ├── main.py └── aave_lending_pool_abi.json ├── dapp_builer_swarm ├── hive_swarm │ ├── __init__.py │ ├── tools │ │ ├── __init__.py │ │ └── files.py │ ├── agents │ │ ├── qa_engineer │ │ │ ├── hive_config.toml │ │ │ └── agent.py │ │ └── instructions.py │ ├── swarm.py │ └── hive_config.toml ├── requirements.txt ├── .gitignore ├── .env.example ├── main.py └── README.md ├── livepeer_youtube_swarm ├── hive_swarm │ ├── __init__.py │ ├── tools │ │ ├── __init__.py │ │ ├── files.py │ │ ├── video_editor.py │ │ ├── youtube_upload.py │ │ └── livepeer_api.py │ ├── swarm.py │ └── hive_config.toml ├── ai_youtuber_swarm_architecture.png ├── .gitignore ├── .env.example ├── requirements.txt ├── main.py └── README.md ├── dune_agent ├── .env.example ├── requirements.txt ├── requirements-dev.txt ├── hive_config.toml ├── structures.py ├── README.md └── hive_crypto_agent.py ├── uniswap-retrieval-agent ├── .env.example ├── hive_config.toml ├── requirements.txt ├── README.md └── uniswap-retrieval-agent.py ├── news_agent ├── .env.example ├── .gitignore ├── requirements.txt ├── hive_config.toml ├── README.md └── news_agent.py ├── .gitignore └── README.md /lend_borrow_agent/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /lend_borrow_agent/test/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /dapp_builer_swarm/hive_swarm/__init__.py: -------------------------------------------------------------------------------- 1 | from .swarm import dapp_swarm 2 | -------------------------------------------------------------------------------- /lend_borrow_agent/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | venv 3 | __pycache__ 4 | .env -------------------------------------------------------------------------------- /livepeer_youtube_swarm/hive_swarm/__init__.py: -------------------------------------------------------------------------------- 1 | from .swarm import livepeer_swarm -------------------------------------------------------------------------------- /dapp_builer_swarm/hive_swarm/tools/__init__.py: -------------------------------------------------------------------------------- 1 | from .files import save_to_file 2 | -------------------------------------------------------------------------------- /dune_agent/.env.example: -------------------------------------------------------------------------------- 1 | MODEL=gpt-4-turbo-preview 2 | OPENAI_API_KEY= 3 | DUNE_API_KEY= -------------------------------------------------------------------------------- /uniswap-retrieval-agent/.env.example: -------------------------------------------------------------------------------- 1 | MODEL=gpt-4-turbo-preview 2 | OPENAI_API_KEY= 3 | -------------------------------------------------------------------------------- /lend_borrow_agent/test/pytest.ini: -------------------------------------------------------------------------------- 1 | [pytest] 2 | asyncio_mode = auto 3 | log_cli = true 4 | -------------------------------------------------------------------------------- /news_agent/.env.example: -------------------------------------------------------------------------------- 1 | MODEL=gpt-4-turbo-preview 2 | OPENAI_API_KEY= 3 | NEWS_API_KEY= 4 | -------------------------------------------------------------------------------- /news_agent/.gitignore: -------------------------------------------------------------------------------- 1 | .env 2 | .venv 3 | ,idea 4 | .vscode 5 | .DS_Store 6 | **/__pycache__ 7 | hive-agent-data 8 | -------------------------------------------------------------------------------- /dune_agent/requirements.txt: -------------------------------------------------------------------------------- 1 | hive-agent @ git+https://github.com/hivenetwork-ai/hive-agent-py@main 2 | langtrace-python-sdk 3 | -------------------------------------------------------------------------------- /dune_agent/requirements-dev.txt: -------------------------------------------------------------------------------- 1 | pytest==8.1.1 2 | pytest-asyncio==0.23.6 3 | pytest-mock==3.14.0 4 | httpx==0.27.0 5 | black==24.4.2 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .venv 2 | venv 3 | .env 4 | .idea 5 | .vscode 6 | .DS_Store 7 | **/__pycache__/ 8 | hive_agent.db 9 | . 10 | .anima/ 11 | -------------------------------------------------------------------------------- /uniswap-retrieval-agent/hive_config.toml: -------------------------------------------------------------------------------- 1 | [model] 2 | model = "gpt-4o" 3 | 4 | [environment] 5 | type = "dev" 6 | 7 | [timeout] 8 | llm = 30 -------------------------------------------------------------------------------- /uniswap-retrieval-agent/requirements.txt: -------------------------------------------------------------------------------- 1 | hive-agent @ git+https://github.com/hivenetwork-ai/hive-agent-py@main 2 | langtrace-python-sdk 3 | -------------------------------------------------------------------------------- /lend_borrow_agent/hive_config.toml: -------------------------------------------------------------------------------- 1 | [model] 2 | model = "gpt-4-turbo-preview" 3 | 4 | [environment] 5 | type = "dev" 6 | 7 | [timeout] 8 | llm = 30 -------------------------------------------------------------------------------- /dapp_builer_swarm/hive_swarm/agents/qa_engineer/hive_config.toml: -------------------------------------------------------------------------------- 1 | [Quality_Assurance_Engineer_Agent] 2 | model = "mistral-large-latest" 3 | environment="dev" 4 | timeout = 60 -------------------------------------------------------------------------------- /dapp_builer_swarm/requirements.txt: -------------------------------------------------------------------------------- 1 | hive-agent @ git+https://github.com/hivenetwork-ai/hive-agent-py@main 2 | aiosqlite==0.20.0 3 | python-dotenv==1.0.1 4 | requests==2.31.0 5 | -------------------------------------------------------------------------------- /dapp_builer_swarm/.gitignore: -------------------------------------------------------------------------------- 1 | .venv 2 | venv 3 | .env 4 | .idea 5 | .vscode 6 | .DS_Store 7 | **/__pycache__/ 8 | hive-agent-data/ 9 | hive_agent.db 10 | . 11 | .anima/ 12 | -------------------------------------------------------------------------------- /livepeer_youtube_swarm/ai_youtuber_swarm_architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hivenetwork-ai/example-agents/HEAD/livepeer_youtube_swarm/ai_youtuber_swarm_architecture.png -------------------------------------------------------------------------------- /dapp_builer_swarm/.env.example: -------------------------------------------------------------------------------- 1 | #MODEL=gpt-4 2 | OPENAI_API_KEY= 3 | MISTRAL_API_KEY= 4 | ANTHROPIC_API_KEY= 5 | ENVIRONMENT=dev 6 | HIVE_AGENT_LOG_LEVEL=INFO 7 | HIVE_AGENT_DATABASE_URL= 8 | -------------------------------------------------------------------------------- /lend_borrow_agent/2_deploy_contracts.js: -------------------------------------------------------------------------------- 1 | const LendingContract = artifacts.require("LendingContract"); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(LendingContract); 5 | }; 6 | -------------------------------------------------------------------------------- /lend_borrow_agent/requirements.txt: -------------------------------------------------------------------------------- 1 | aiosqlite==0.20.0 2 | python-dotenv==1.0.1 3 | requests==2.31.0 4 | pydantic==2.7.1 5 | web3==6.15.1 6 | 7 | hive-agent @ git+https://github.com/hivenetwork-ai/hive-agent-py@main -------------------------------------------------------------------------------- /news_agent/requirements.txt: -------------------------------------------------------------------------------- 1 | hive-agent @ git+https://github.com/hivenetwork-ai/hive-agent-py@main 2 | aiosqlite==0.20.0 3 | python-dotenv==1.0.1 4 | requests==2.31.0 5 | newsapi-python==0.2.7 6 | langtrace-python-sdk 7 | -------------------------------------------------------------------------------- /livepeer_youtube_swarm/.gitignore: -------------------------------------------------------------------------------- 1 | .env 2 | .venv 3 | .venv 4 | 5 | client_secret.json 6 | token.pickle 7 | 8 | hive-agent-data 9 | 10 | .idea 11 | .vscode 12 | .anima 13 | 14 | **/*/__pycache__ 15 | .DS_Store 16 | -------------------------------------------------------------------------------- /livepeer_youtube_swarm/.env.example: -------------------------------------------------------------------------------- 1 | MODEL=gpt-4-turbo-preview 2 | OPENAI_API_KEY= 3 | MISTRAL_API_KEY= 4 | ANTHROPIC_API_KEY= 5 | ENVIRONMENT=dev 6 | HIVE_AGENT_LOG_LEVEL=INFO 7 | HIVE_AGENT_DATABASE_URL= 8 | PINECONE_API_KEY= 9 | LIVEPEER_API_KEY= 10 | -------------------------------------------------------------------------------- /livepeer_youtube_swarm/hive_swarm/tools/__init__.py: -------------------------------------------------------------------------------- 1 | from .files import save_to_file, read_from_file, list_files,download_from_url 2 | from .livepeer_api import text_to_image, image_to_video 3 | from .video_editor import video_editor 4 | from .youtube_upload import upload_video -------------------------------------------------------------------------------- /lend_borrow_agent/.env.example: -------------------------------------------------------------------------------- 1 | MODEL=gpt-4-turbo-preview 2 | OPENAI_API_KEY= 3 | ANTHROPIC_API_KEY= 4 | LLAMA_API_KEY= 5 | MISTRAL_API_KEY= 6 | ENVIRONMENT=dev 7 | 8 | 9 | RPC_URL= 10 | PRIVATE_KEY= 11 | AAVE_LENDING_POOL_ADDRESS=0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9 12 | 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # example-agents 2 | Examples of AI Agents that can be built on SwarmZero 3 | 4 | ## Learn More 5 | Join our Discord community for support and discussion. 6 | 7 | [![](https://dcbadge.limes.pink/api/server/vnJvW4wZp9)](https://discord.gg/vnJvW4wZp9) 8 | 9 | https://swarmzero.ai 10 | -------------------------------------------------------------------------------- /livepeer_youtube_swarm/requirements.txt: -------------------------------------------------------------------------------- 1 | hive-agent @ git+https://github.com/hivenetwork-ai/hive-agent-py.git@main 2 | aiosqlite==0.20.0 3 | python-dotenv==1.0.1 4 | requests==2.31.0 5 | google-api-python-client==2.145.0 6 | google-auth-oauthlib==1.2.1 7 | moviepy==1.0.3 8 | Pillow==9.5.0 9 | livepeer-ai==0.5.0 10 | 11 | -------------------------------------------------------------------------------- /news_agent/hive_config.toml: -------------------------------------------------------------------------------- 1 | [model] 2 | model = "gpt-4-turbo-preview" 3 | 4 | [environment] 5 | type = "dev" 6 | 7 | [timeout] 8 | llm = 30 9 | 10 | [sample_prompts] 11 | prompts = [ 12 | "What is the latest news about the stock market?", 13 | "Get me news on new tech gadgets.", 14 | "What's going on in the world of AI?", 15 | ] 16 | -------------------------------------------------------------------------------- /dune_agent/hive_config.toml: -------------------------------------------------------------------------------- 1 | [model] 2 | model = "gpt-4o" 3 | 4 | [environment] 5 | type = "dev" 6 | 7 | [timeout] 8 | llm = 30 9 | 10 | [sample_prompts] 11 | prompts = [ 12 | "Can I get the Alpha Index?", 13 | "Provide the Beta Index with explanations.", 14 | "Provide the Yearly Narrative Index.", 15 | "How did the Monthly Narrative Index perform?" 16 | ] -------------------------------------------------------------------------------- /dapp_builer_swarm/main.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | 3 | from dotenv import load_dotenv 4 | 5 | from hive_swarm import dapp_swarm 6 | 7 | 8 | 9 | load_dotenv() 10 | 11 | 12 | async def main(): 13 | print( 14 | "Welcome to the dApp Builder Swarm!\nVisit https://SwarmZero.ai to learn more.\n\nType 'exit' to quit.\n" 15 | ) 16 | 17 | while True: 18 | prompt = input("\n\nEnter your prompt: \n\n") 19 | if prompt.lower() == "exit": 20 | break 21 | response = await dapp_swarm.chat(prompt) 22 | print(response) 23 | 24 | 25 | if __name__ == "__main__": 26 | asyncio.run(main()) 27 | -------------------------------------------------------------------------------- /livepeer_youtube_swarm/main.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | 3 | from dotenv import load_dotenv 4 | 5 | from hive_swarm import livepeer_swarm 6 | 7 | 8 | load_dotenv() 9 | 10 | 11 | async def main(): 12 | print( 13 | "Welcome to the Livepeer Youtube Video Generator Swarm!\nVisit https://SwarmZero.ai to learn more.\n\nType " 14 | "'exit' to quit.\n" 15 | ) 16 | 17 | while True: 18 | prompt = input("\n\nEnter your prompt: \n\n") 19 | if prompt.lower() == "exit": 20 | break 21 | response = await livepeer_swarm.chat(prompt) 22 | print(response) 23 | 24 | 25 | if __name__ == "__main__": 26 | asyncio.run(main()) 27 | -------------------------------------------------------------------------------- /dapp_builer_swarm/hive_swarm/agents/qa_engineer/agent.py: -------------------------------------------------------------------------------- 1 | from hive_agent import HiveAgent 2 | from hive_swarm.agents.instructions import QA_ENGINEER_INSTRUCTION 3 | 4 | def get_qa_agent(sdk_context): 5 | 6 | sdk_context.add_agent_config("./hive_swarm/agents/qa_engineer/hive_config.toml") 7 | 8 | qa_agent = HiveAgent( 9 | name="Quality Assurance Engineer Agent", 10 | description="This agent acts like a QA Engineer on a team and can review code.", 11 | instruction=QA_ENGINEER_INSTRUCTION, 12 | role="QA engineer", 13 | functions=[], 14 | swarm_mode=True, 15 | sdk_context=sdk_context, 16 | ) 17 | 18 | return qa_agent 19 | -------------------------------------------------------------------------------- /lend_borrow_agent/test/test_lend_borrow.py: -------------------------------------------------------------------------------- 1 | import logging 2 | from lend_borrow_agent.main import lend_crypto, borrow_crypto 3 | 4 | 5 | def test_lend_crypto(): 6 | try: 7 | tx_hash = lend_crypto(0.00000001, '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE') # ETH special address 8 | except Exception as e: 9 | logging.error(f"Error during lend_crypto test: {e}") 10 | 11 | def test_borrow_crypto(): 12 | try: 13 | tx_hash = borrow_crypto(0.00000001, '0x6b175474e89094c44da98b954eedeac495271d0f', 2) # DAI address 14 | except Exception as e: 15 | logging.error(f"Error during borrow_crypto test: {e}") 16 | 17 | if __name__ == "__main__": 18 | test_lend_crypto() 19 | test_borrow_crypto() 20 | -------------------------------------------------------------------------------- /dapp_builer_swarm/hive_swarm/tools/files.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | 4 | def save_to_file(content: str, file_name: str, file_path: str) -> None: 5 | """ 6 | Saves the given content to a file at the specified path with the specified file name. 7 | 8 | :param content: The content to be written to the file. 9 | :param file_name: The name of the file to save the content in. 10 | :param file_path: The path where the file should be saved. 11 | """ 12 | 13 | # ensure the directory exists 14 | os.makedirs(file_path, exist_ok=True) 15 | 16 | # construct the full file path 17 | full_path = os.path.join(file_path, file_name) 18 | 19 | # write the content to the file 20 | with open(full_path, "w") as file: 21 | file.write(content) 22 | 23 | print(f"File saved to {full_path}") 24 | -------------------------------------------------------------------------------- /dapp_builer_swarm/hive_swarm/swarm.py: -------------------------------------------------------------------------------- 1 | from hive_agent import HiveSwarm 2 | from hive_swarm.tools import save_to_file 3 | 4 | from dotenv import load_dotenv 5 | load_dotenv() 6 | 7 | from hive_agent.sdk_context import SDKContext 8 | from hive_swarm.agents.qa_engineer.agent import get_qa_agent 9 | 10 | 11 | config_path = "./hive_swarm/hive_config.toml" 12 | sdk_context = SDKContext(config_path=config_path) 13 | 14 | dapp_swarm = HiveSwarm( 15 | name="DeFi Startup", 16 | description="A swarm of agents that collaborate as members of a DeFi (Decentralized Finance) startup.", 17 | instruction="You are a DeFi Startup whose goal is to create new DeFi products for your customers. You are to " 18 | "output working code that satisfies the user's needs. You must output all the code to the " 19 | "`./hive-agent-data/output//` folder using the provided tools.", 20 | functions=[save_to_file], 21 | sdk_context=sdk_context, #We created sdkcontext to pass context to another agent. 22 | #config_path=config_path, # If you dont want to add agent you can pass config_path and remove sdkcontext to swarm it will create sdkcontext for you. 23 | ) 24 | 25 | #add QA agent 26 | qa_agent = get_qa_agent(sdk_context) 27 | 28 | dapp_swarm.add_agent(qa_agent) 29 | 30 | # remove QA agent 31 | # dapp_swarm.remove_agent(qa_agent) 32 | 33 | -------------------------------------------------------------------------------- /dapp_builer_swarm/README.md: -------------------------------------------------------------------------------- 1 | # dApp Builder Swarm 2 | 3 | This is an example of a Swarm of AI Agents that are able to coordinate and build a web3 dApp (decentralized application) based on a users' prompt. 4 | 5 | > NOTE: this is only a demonstration and is not intended for production use. The simpler the dApp you ask the swarm to build, the more likely it is to be completed. 6 | 7 | 8 | ## Project Requirements 9 | - Python >= 3.11 10 | 11 | ## Setup 12 | - Create a new file called .env 13 | - Copy the contents of [.env.example](.env.example) into your new .env file 14 | - API keys for third party tools are not provided. 15 | - `OPENAI_API_KEY` from OpenAI 16 | 17 | You can use other LLMs, in which case you can add a corresponding API key 18 | - `ANTHROPIC_API_KEY` from Anthropic 19 | - `MISTRAL_API_KEY` from Mistral 20 | - Create a virtual Python environment 21 | ``` 22 | $ python -m venv ./venv 23 | ``` 24 | - Activate the Python virtual env. 25 | - Windows: 26 | - In cmd.exe: `venv\Scripts\activate.bat` 27 | - In PowerShell: `venv\Scripts\Activate.ps1` 28 | - Unix: `source venv/bin/activate` 29 | - Install dependencies. 30 | ``` 31 | $ pip install -r requirements.txt 32 | ``` 33 | 34 | 35 | ## Usage 36 | - Run it 37 | ``` 38 | (venv) $ python main.py 39 | ``` 40 | - You can now describe the dApp you want to build e.g. *"build a dApp to mint new NFTs of AI models"*. 41 | - The code will be stored in [hive-agent-data/output](./hive-agent-data/output). 42 | 43 | 44 | ## More 45 | - Powered by [SwarmZero](https://swarmzero.ai). 46 | -------------------------------------------------------------------------------- /dune_agent/structures.py: -------------------------------------------------------------------------------- 1 | from pydantic import BaseModel 2 | from typing import List 3 | from llama_index.core.program import FunctionCallingProgram 4 | 5 | class Metadata(BaseModel): 6 | """Data model for the metadata field.""" 7 | column_names: List[str] 8 | column_types: List[str] 9 | row_count: int 10 | 11 | class IndexRow(BaseModel): 12 | """Data model for each row in the result set.""" 13 | ranking: int 14 | coin: str 15 | price_today: float 16 | optimized_relative_strength: float 17 | narrative: str 18 | 19 | class IndexResult(BaseModel): 20 | """Data model for the result field.""" 21 | rows: List[IndexRow] 22 | metadata: Metadata 23 | role : str = 'Function' 24 | class NarrativeRow(BaseModel): 25 | """Data model for each row in the result set.""" 26 | optimized_relative_strength: float 27 | price_growth: float 28 | relative_strategy: float 29 | relative_strength: float 30 | signal: str 31 | 32 | class NarrativeResult(BaseModel): 33 | """Data model for the result field.""" 34 | rows: List[NarrativeRow] 35 | metadata: Metadata 36 | role : str = 'Function' 37 | 38 | def get_structured_response(response, output_cls): 39 | 40 | prompt_template_str = """ Generate structured output data using {response} """ 41 | 42 | program = FunctionCallingProgram.from_defaults( 43 | output_cls=output_cls, 44 | prompt_template_str=prompt_template_str, 45 | verbose=True, 46 | ) 47 | output = program(response=response) 48 | return output.dict() 49 | -------------------------------------------------------------------------------- /dapp_builer_swarm/hive_swarm/agents/instructions.py: -------------------------------------------------------------------------------- 1 | PROJECT_MANAGER_INSTRUCTION = ( 2 | "You are a project manager on a software development team and you should provide guidance, " 3 | "planning, clarity and instruction on how to build the project." 4 | ) 5 | 6 | FRONTEND_DEVELOPER_INSTRUCTION = ( 7 | "You are a frontend developer on a team that produces clean, working React code in Typescript. You must" 8 | "output all the code to the `./hive-agent-data/output//frontend` folder " 9 | "using the provided tools. Return only code, do not return anything else unless explicitly instructed " 10 | "otherwise." 11 | ) 12 | 13 | BACKEND_DEVELOPER_INSTRUCTION = ( 14 | "You are a backend developer on a team that produces clean, working server code in Express.js. " 15 | "You use Typescript as much as possible rather than Javascript. You must output all the code to " 16 | "the `./hive-agent-data/output//backend` folder using the provided " 17 | "tools. Return only code, do not return anything else unless explicitly instructed otherwise." 18 | ) 19 | 20 | SMART_CONTRACTS_DEVELOPER_INSTRUCTION = ( 21 | "You are a Solidity smart contract developer on a team that produces clean, working smart contracts " 22 | "in Solidity. You must output all the code to the " 23 | "`./hive-agent-data/output//contracts` folder using the provided tools. " 24 | "Return only code, do not return anything else unless explicitly instructed otherwise." 25 | ) 26 | 27 | QA_ENGINEER_INSTRUCTION = ( 28 | "You are a Quality Assurance Engineer on a software team, you need to find bugs in the code given to " 29 | "you so that the developers can fix them before saving/committing their code." 30 | ) 31 | -------------------------------------------------------------------------------- /dapp_builer_swarm/hive_swarm/hive_config.toml: -------------------------------------------------------------------------------- 1 | [model] 2 | model = "gpt-4o" 3 | 4 | [environment] 5 | type = "dev" 6 | 7 | [timeout] 8 | llm = 60 9 | 10 | [Project_Manager_Agent] 11 | model = "gpt-4o" 12 | environment="dev" 13 | timeout = 30 14 | instruction= """ 15 | You are a project manager on a software development team and you should provide guidance, \ 16 | planning, clarity and instruction on how to build the project. 17 | """ 18 | 19 | [Frontend_Developer_Agent] 20 | model = "claude-3-opus-20240229" 21 | environment="dev" 22 | timeout = 60 23 | instruction= """ 24 | You are a frontend developer on a team that produces clean, working React code in Typescript. You must \ 25 | output all the code to the `./hive-agent-data/output//frontend` folder \ 26 | using the provided tools. Return only code, do not return anything else unless explicitly instructed \ 27 | otherwise. 28 | """ 29 | tools=[ 30 | { module = "hive_swarm.tools", name = "save_to_file" } 31 | ] 32 | 33 | [Backend_Developer_Agent] 34 | model = "claude-3-opus-20240229" 35 | environment="dev" 36 | timeout = 60 37 | instruction= """ 38 | You are a backend developer on a team that produces clean, working server code in Express.js. \ 39 | You use Typescript as much as possible rather than Javascript. You must output all the code to \ 40 | the `./hive-agent-data/output//backend` folder using the provided \ 41 | tools. Return only code, do not return anything else unless explicitly instructed otherwise. 42 | """ 43 | tools=[ 44 | { module = "hive_swarm.tools", name = "save_to_file" } 45 | ] 46 | 47 | [Solidity_Developer_Agent] 48 | model = "claude-3-opus-20240229" 49 | environment = "dev" 50 | timeout = 60 51 | instruction= """ 52 | You are a Solidity smart contract developer on a team that produces clean, working smart contracts \ 53 | in Solidity. You must output all the code to the \ 54 | `./hive-agent-data/output//contracts` folder using the provided tools. \ 55 | Return only code, do not return anything else unless explicitly instructed otherwise. 56 | """ 57 | tools=[ 58 | { module = "hive_swarm.tools", name = "save_to_file" } 59 | ] 60 | -------------------------------------------------------------------------------- /livepeer_youtube_swarm/hive_swarm/tools/files.py: -------------------------------------------------------------------------------- 1 | import os 2 | import requests 3 | 4 | def save_to_file(content: str, file_name: str, file_path: str) -> None: 5 | """ 6 | Saves the given content to a file at the specified path with the specified file name. 7 | 8 | :param content: The content to be written to the file. 9 | :param file_name: The name of the file to save the content in. 10 | :param file_path: The path where the file should be saved. 11 | """ 12 | 13 | # ensure the directory exists 14 | os.makedirs(file_path, exist_ok=True) 15 | 16 | # construct the full file path 17 | full_path = os.path.join(file_path, file_name) 18 | 19 | # write the content to the file 20 | with open(full_path, "w") as file: 21 | file.write(content) 22 | 23 | print(f"File saved to {full_path}") 24 | 25 | 26 | def read_from_file(file_path: str) -> str: 27 | """ 28 | Reads the content from a file at the specified path. 29 | 30 | :param file_path: The path of the file to read. 31 | :return: The content of the file. 32 | """ 33 | with open(file_path, "r") as file: 34 | return file.read() 35 | 36 | def list_files(file_path: str) -> list[str]: 37 | """ 38 | Lists the files in the specified directory. 39 | 40 | :param file_path: The path of the directory to list. 41 | :return: A list of files in the directory. 42 | """ 43 | return os.listdir(file_path) 44 | 45 | 46 | 47 | def download_from_url(url: str, file_name: str,file_path: str) -> str: 48 | 49 | """ 50 | Saves the given content to a file at the specified path with the specified file name. 51 | 52 | :param url: Url to download the image from. 53 | :param file_name: Name of the file to save the image to. 54 | :param file_path: Path to save the image to. 55 | :return: Path to the saved image. 56 | """ 57 | response = requests.get(url) 58 | if response.status_code == 200: 59 | # Create the full directory path 60 | os.makedirs(file_path, exist_ok=True) 61 | 62 | full_path = os.path.join(file_path, file_name) 63 | 64 | # Write the image content to the file 65 | with open(full_path, "wb") as f: 66 | f.write(response.content) 67 | 68 | return full_path 69 | else: 70 | raise Exception(f"Failed to download image: HTTP {response.status_code}") -------------------------------------------------------------------------------- /news_agent/README.md: -------------------------------------------------------------------------------- 1 | # News Agent 2 | This News Agent leverages a news API to fetch and process news from a wide array of sources to deliver comprehensive, contextual, and well-researched responses tailored to user queries. 3 | Whether you're seeking the latest headlines, in-depth analyses, or specific topic updates, this agent ensures you receive accurate and timely information. 4 | 5 | Built with [Hive Agent Kit](https://github.com/hivenetwork-ai/hive-agent-py). 6 | 7 | 8 | ## Project Requirements 9 | - Python >= 3.11 10 | 11 | ## Setup 12 | - Create a new file called .env 13 | - Copy the contents of [.env.example](.env.example) into your new .env file 14 | - API keys for third party tools are not provided. 15 | - `OPENAI_API_KEY` from OpenAI 16 | 17 | You can use other LLMs, in which case you can add a corresponding API key 18 | - `ANTHROPIC_API_KEY` from Anthropic 19 | - `MISTRAL_API_KEY` from Mistral 20 | - [All models supplied by Ollama](https://ollama.com/library) 21 | - Create a virtual Python environment 22 | ``` 23 | $ python -m venv ./venv 24 | ``` 25 | - Activate the Python virtual env. 26 | - Windows: 27 | - In cmd.exe: `venv\Scripts\activate.bat` 28 | - In PowerShell: `venv\Scripts\Activate.ps1` 29 | - Unix: `source venv/bin/activate` 30 | - Install dependencies. 31 | ``` 32 | $ pip install -r requirements.txt 33 | ``` 34 | 35 | ## Usage 36 | - Run it 37 | ``` 38 | (venv) $ python main.py 39 | ``` 40 | - Test your agent by calling it Chat API endpoint, `/api/chat`, to see the result: 41 | 42 | ``` 43 | curl --location 'localhost:8000/api/v1/chat' \ 44 | --header 'Content-Type: application/json' \ 45 | --data '{ 46 | "user_id": "user123", 47 | "session_id": "session123", 48 | "chat_data": { 49 | "messages": [ 50 | { "role": "user", "content": "What's going on in Canada right now?" } 51 | ] 52 | } 53 | }' 54 | ``` 55 | 56 | ## Testing 57 | - Install the dev dependencies: 58 | ``` 59 | (venv) $ pip install -r requirements-dev.txt 60 | ``` 61 | - Run the test suite 62 | ``` 63 | $ pytest 64 | ``` 65 | - Run tests for a specific module 66 | ``` 67 | $ pytest tests/path/to/test_module.py 68 | ``` 69 | - Run with verbose output: 70 | ``` 71 | $ pytest -v 72 | ``` 73 | - Run with a detailed output of each test (including print statements): 74 | ``` 75 | $ pytest -s 76 | ``` 77 | 78 | ## More 79 | - Powered by [Hive Network](https://hivenetwork.ai). 80 | -------------------------------------------------------------------------------- /livepeer_youtube_swarm/hive_swarm/tools/video_editor.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from moviepy.editor import VideoFileClip, concatenate_videoclips, CompositeVideoClip, vfx 3 | 4 | def video_editor(video_files: list[str], output_filename: str): 5 | """ 6 | This function takes a list of video files, resizes and crops them to fit YouTube Shorts dimensions, and concatenates them into a single video file. 7 | 8 | :param video_files: A list of paths to video files. 9 | :param output_filename: The path to the output video file. 10 | :return: The path to the output video file. 11 | """ 12 | 13 | clips = [] 14 | for video in video_files: 15 | try: 16 | # Load the video file 17 | clip = VideoFileClip(video) 18 | 19 | # Set target dimensions for YouTube Shorts 20 | target_width = 1080 21 | target_height = 1920 22 | 23 | # Determine the scaling factor to cover the target dimensions 24 | clip_width, clip_height = clip.size 25 | width_ratio = target_width / clip_width 26 | height_ratio = target_height / clip_height 27 | scaling_factor = max(width_ratio, height_ratio) 28 | 29 | # Resize the clip to cover the target area 30 | clip_resized = clip.resize(height=int(clip.h * scaling_factor)) 31 | 32 | # Center crop the clip to target dimensions 33 | clip_cropped = clip_resized.crop( 34 | x_center=clip_resized.w / 2, 35 | y_center=clip_resized.h / 2, 36 | width=target_width, 37 | height=target_height 38 | ) 39 | 40 | # Optionally limit the clip duration to 60 seconds 41 | # clip_cropped = clip_cropped.subclip(0, min(clip_cropped.duration, 60)) 42 | 43 | clips.append(clip_cropped) 44 | except Exception as e: 45 | print(f"Error processing {video}: {e}") 46 | continue 47 | 48 | if not clips: 49 | print("No valid video clips were processed.") 50 | sys.exit(1) 51 | 52 | # Concatenate clips 53 | final_clip = concatenate_videoclips(clips, method='compose') 54 | 55 | # Write the final video file 56 | final_clip.write_videofile( 57 | output_filename, 58 | fps=30, 59 | codec='libx264', 60 | audio_codec='aac', 61 | preset='medium', 62 | threads=4 63 | ) 64 | 65 | return output_filename -------------------------------------------------------------------------------- /dune_agent/README.md: -------------------------------------------------------------------------------- 1 | # Dune Agent 2 | This Dune Agent enables you to search for indexes and crypto narratives using the DUNE API, providing updated market data. You can access detailed insights into the ALPHA, Beta, and Gamma Indexes, as well as Daily, Weekly, Monthly, and Quarterly Crypto Narratives. This offers comprehensive and timely information on the latest crypto trends. 3 | 4 | Source: https://dune.com/dyorcrypto/relative-strength-crypto-narrative 5 | 6 | Built with [Hive Agent Kit](https://github.com/hivenetwork-ai/hive-agent-py). 7 | 8 | 9 | ## Project Requirements 10 | - Python >= 3.11 11 | 12 | ## Setup 13 | - Create a new file called .env 14 | - Copy the contents of [.env.example](.env.example) into your new .env file 15 | - API keys for third party tools are not provided. 16 | - `OPENAI_API_KEY` from OpenAI 17 | 18 | You can use other LLMs, in which case you can add a corresponding API key 19 | - `ANTHROPIC_API_KEY` from Anthropic 20 | - `MISTRAL_API_KEY` from Mistral 21 | - [All models supplied by Ollama](https://ollama.com/library) 22 | - Create a virtual Python environment 23 | ``` 24 | $ python -m venv ./venv 25 | ``` 26 | - Activate the Python virtual env. 27 | - Windows: 28 | - In cmd.exe: `venv\Scripts\activate.bat` 29 | - In PowerShell: `venv\Scripts\Activate.ps1` 30 | - Unix: `source venv/bin/activate` 31 | - Install dependencies. 32 | ``` 33 | $ pip install -r requirements.txt 34 | ``` 35 | 36 | ## Usage 37 | - Run it 38 | ``` 39 | (venv) $ python main.py 40 | ``` 41 | - Test your agent by calling it Chat API endpoint, `/api/chat`, to see the result: 42 | 43 | ``` 44 | curl --location 'localhost:8000/api/v1/chat' \ 45 | --header 'Content-Type: application/json' \ 46 | --data '{ 47 | "user_id": "user123", 48 | "session_id": "session123", 49 | "chat_data": { 50 | "messages": [ 51 | { "role": "user", "content": "Can I get weekly crypto report?" } 52 | ] 53 | } 54 | }' 55 | ``` 56 | 57 | ## Testing 58 | - Install the dev dependencies: 59 | ``` 60 | (venv) $ pip install -r requirements-dev.txt 61 | ``` 62 | - Run the test suite 63 | ``` 64 | $ pytest 65 | ``` 66 | - Run tests for a specific module 67 | ``` 68 | $ pytest tests/path/to/test_module.py 69 | ``` 70 | - Run with verbose output: 71 | ``` 72 | $ pytest -v 73 | ``` 74 | - Run with a detailed output of each test (including print statements): 75 | ``` 76 | $ pytest -s 77 | ``` 78 | 79 | ## More 80 | - Powered by [Hive Network](https://hivenetwork.ai). 81 | -------------------------------------------------------------------------------- /livepeer_youtube_swarm/hive_swarm/swarm.py: -------------------------------------------------------------------------------- 1 | from hive_agent import HiveSwarm 2 | from hive_swarm.tools import save_to_file,list_files, read_from_file 3 | from hive_swarm.tools import download_from_url 4 | 5 | from dotenv import load_dotenv 6 | load_dotenv() 7 | 8 | from hive_agent.sdk_context import SDKContext 9 | 10 | 11 | config_path = "./hive_swarm/hive_config.toml" 12 | sdk_context = SDKContext(config_path=config_path) 13 | 14 | livepeer_swarm = HiveSwarm( 15 | name="Livepeer Youtube Video Generator", 16 | description="A swarm of agents that collaborate as members of a Livepeer Youtube Video Generator team.", 17 | instruction="""You are the manager of a video production team for Livepeer Youtube Video Generator. Your goal is to guide the team in creating an engaging and informative video. Follow these steps: 18 | 19 | 1. Coordinate with these agents in order: 20 | a. Script Writer Agent 21 | b. Scene Writer Agent 22 | c. Scene Prompt Generator Agent 23 | d. Scene Image Generator Agent (max 3 files at a time) 24 | e. Scene Image to Video Generator Agent (max 3 files at a time) 25 | f. Video Editor Agent 26 | g. Youtube Upload Agent 27 | 28 | 2. After each interaction with agents, save the output as a separate file in: 29 | `./hive-agent-data/output///` 30 | Use the save_to_file tool for this purpose. 31 | 32 | 3. Scene Image Generator Agent and Scene Image to Video Agent will return url or list of urls. You should use download_from_url tool to download images and videos. 33 | 34 | 4. Use list_files and read_from_file tools to access and review previous outputs. 35 | 36 | 5. Ensure each agent receives the relevant input from the previous step. 37 | 38 | 6. Maintain consistency and coherence throughout the video creation process. 39 | 40 | 7. Monitor the quality and relevance of each output, requesting revisions if necessary. 41 | 42 | 8. Provide clear, concise instructions to each agent, specifying their task and any relevant constraints. 43 | 44 | 9. After all steps are complete, review the entire project for cohesiveness and alignment with the original video concept. 45 | 46 | Remember to adapt your management style based on the specific video topic and requirements provided by the user. 47 | """, 48 | functions=[save_to_file, list_files, read_from_file, download_from_url], 49 | sdk_context=sdk_context, 50 | # max_iterations=30, 51 | ) 52 | -------------------------------------------------------------------------------- /uniswap-retrieval-agent/README.md: -------------------------------------------------------------------------------- 1 | # Uniswap Docs Retrieval Agent 2 | This Uniswap Documentation Retrieval Agent empowers you to create a specialized Q&A Retrieval-Augmented Generation (RAG) agent. This tool assists in sourcing detailed information directly from Uniswap’s extensive documentation, enabling effective and informed responses to queries about Uniswap. 3 | 4 | Source: https://github.com/Uniswap/docs/tree/main/docs 5 | 6 | Built with [Hive Agent Kit](https://github.com/hivenetwork-ai/hive-agent-py). 7 | 8 | 9 | ## Project Requirements 10 | - Python >= 3.11 11 | 12 | ## Setup 13 | - Create a new file called .env 14 | - Copy the contents of [.env.example](.env.example) into your new .env file 15 | - API keys for third party tools are not provided. 16 | - `OPENAI_API_KEY` from OpenAI 17 | 18 | You can use other LLMs, in which case you can add a corresponding API key 19 | - `ANTHROPIC_API_KEY` from Anthropic 20 | - `MISTRAL_API_KEY` from Mistral 21 | - [All models supplied by Ollama](https://ollama.com/library) 22 | - Create a virtual Python environment 23 | ``` 24 | $ python -m venv ./venv 25 | ``` 26 | - Activate the Python virtual env. 27 | - Windows: 28 | - In cmd.exe: `venv\Scripts\activate.bat` 29 | - In PowerShell: `venv\Scripts\Activate.ps1` 30 | - Unix: `source venv/bin/activate` 31 | - Install dependencies. 32 | ``` 33 | $ pip install -r requirements.txt 34 | ``` 35 | 36 | ## Usage 37 | - Run it 38 | ``` 39 | (venv) $ python main.py 40 | ``` 41 | - Test your agent by calling it Chat API endpoint, `/api/chat`, to see the result: 42 | 43 | ``` 44 | curl --location 'localhost:8000/api/v1/chat' \ 45 | --header 'Content-Type: application/json' \ 46 | --data '{ 47 | "user_id": "user123", 48 | "session_id": "session123", 49 | "chat_data": { 50 | "messages": [ 51 | { "role": "user", "content": "Explain the concept of immutability in the context of Uniswap’s smart contracts. Why is this feature significant?" } 52 | ] 53 | } 54 | }' 55 | ``` 56 | 57 | ## Testing 58 | - Install the dev dependencies: 59 | ``` 60 | (venv) $ pip install -r requirements-dev.txt 61 | ``` 62 | - Run the test suite 63 | ``` 64 | $ pytest 65 | ``` 66 | - Run tests for a specific module 67 | ``` 68 | $ pytest tests/path/to/test_module.py 69 | ``` 70 | - Run with verbose output: 71 | ``` 72 | $ pytest -v 73 | ``` 74 | - Run with a detailed output of each test (including print statements): 75 | ``` 76 | $ pytest -s 77 | ``` 78 | 79 | ## More 80 | - Powered by [Hive Network](https://hivenetwork.ai). 81 | -------------------------------------------------------------------------------- /lend_borrow_agent/README.md: -------------------------------------------------------------------------------- 1 | # AAVE agent 2 | 3 | This agent provides lending and borrowing of cryptocurrencies from the AAVE pool. AAVE is a Decentralized Finance (DeFi) protocol that allows users to lend and borrow cryptocurrencies without the need for intermediaries. It operates on a peer-to-peer network, providing liquidity and earning interest for lenders while offering collateralized loans for borrowers. 4 | 5 | ## Environment Setup 6 | You need to specify an `RPC_URL` and `PRIVATE_KEY` in a _.env_ file in this directory. 7 | 8 | Make a copy of the [.env.example](.env.example) file and rename it to _.env_. 9 | 10 | The `RPC_URL` can come from an Infura key. 11 | 12 | The `PRIVATE_KEY` is your digital wallet's private key. 13 | 14 | # Usage 15 | 16 | Call the API endpoint, `/api/v1/chat`, to see the result: 17 | ```sh 18 | curl --location 'localhost:8000/api/v1/chat' \ 19 | --header 'Content-Type: application/json' \ 20 | --data '{ 21 | "user_id": "user123", 22 | "session_id": "session123", 23 | "chat_data": { 24 | "messages": [ 25 | { "role": "user", "content": "Borrow 5 ETH from the AAVE lending pool, with a variable interest rate" } 26 | ] 27 | } 28 | }' 29 | ``` 30 | ## Setup 31 | 32 | Make sure the .env file file is created by doing the following: 33 | 34 | - Create a new file called .env 35 | - Copy the contents of [.env.example](.env.example) into your new .env file 36 | 37 | Then create a virtual Python environment: 38 | ``` 39 | $ python -m venv ./venv 40 | ``` 41 | - Activate the Python virtual env. 42 | - Windows: 43 | - In cmd.exe: `venv\Scripts\activate.bat` 44 | - In PowerShell: `venv\Scripts\Activate.ps1` 45 | - Unix: `source venv/bin/activate` 46 | - Install dependencies. 47 | ``` 48 | $ pip install -r requirements.txt 49 | ``` 50 | 51 | 52 | 53 | ### Testing 54 | 55 | - Make sure you're in the `lend_borrow_agent` directory: 56 | ```sh 57 | $ pytest test/test_lend_borrow.py 58 | ``` 59 | - Run the test suite: 60 | ```sh 61 | $ pytest 62 | ``` 63 | - Run tests for a specific module: 64 | ```sh 65 | $ pytest tests/path/to/test_module.py 66 | ``` 67 | - Run with verbose output: 68 | ```sh 69 | $ pytest -v 70 | ``` 71 | - Run with a detailed output of each test (including print statements): 72 | ```sh 73 | $ pytest -s 74 | ``` 75 | 76 | ## Learn More 77 | 78 | Hivenetwork 79 | - https://hivenetwork.ai 80 | 81 | AAVE: 82 | - Website: https://aave.com/ 83 | - AAVE documentation: https://docs.aave.com/hub 84 | - AAVE token: https://docs.aave.com/developers/v/1.0/developing-on-aave/the-protocol/aave-token 85 | - Smart contracts overview: https://docs.aave.com/developers/getting-started/contracts-overview 86 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /livepeer_youtube_swarm/README.md: -------------------------------------------------------------------------------- 1 | # Livepeer Youtube Video Generator Swarm 2 | 3 | ## Description 4 | 5 | The Livepeer Youtube Video Generator Swarm is an AI-powered tool that automates the process of creating and uploading YouTube videos. It utilizes a swarm of specialized agents to handle different aspects of video production, from script writing to YouTube uploading. 6 | 7 | ## Agent Swarm Architecture Diagram 8 | ![Diagram](./ai_youtuber_swarm_architecture.png) 9 | 10 | ## Features 11 | 12 | - Automated video creation pipeline 13 | - AI-powered script and scene writing 14 | - Image and video generation using Livepeer AI 15 | - Automatic video editing and compilation 16 | - YouTube upload integration 17 | 18 | ## Installation 19 | 20 | 1. Clone the repository: 21 | ``` 22 | git clone https://github.com/hivenetwork-ai/example-agents 23 | cd livepeer-youtube-video-generator 24 | ``` 25 | 26 | 2. Install the required dependencies: 27 | ``` 28 | pip install -r requirements.txt 29 | ``` 30 | 31 | 3. Set up environment variables: 32 | Create a `.env` file in the root directory and add necessary API keys and credentials. 33 | 34 | 4. Set up YouTube API credentials: 35 | Place your `client_secret.json` file in the root directory. 36 | You can get your OAuth 2.0 API key using Google API Console [here](https://developers.google.com/identity/protocols/oauth2). 37 | You should add `http://localhost:8088` as a valid redirect URI for your OAuth client ID. 38 | 39 | ## Usage 40 | 41 | Run the main script: 42 | 43 | Follow the prompts to enter your video topic. The swarm will then generate and upload a video based on your input. 44 | 45 | ## Configuration 46 | 47 | The swarm behavior can be configured in the `hive_config.toml` file. You can adjust agent models, timeouts, and instructions here. 48 | 49 | ## Project Structure 50 | 51 | - `main.py`: Entry point of the application 52 | - `swarm/`: Contains the core swarm logic and agent definitions 53 | - `swarm/tools/`: Utility functions for file handling, API interactions, and video processing 54 | - `hive_config.toml`: Configuration file for the swarm and its agents 55 | 56 | ## Dependencies 57 | 58 | This project relies on several key libraries and APIs: 59 | 60 | - hive-agent: For swarm intelligence and agent coordination 61 | - Livepeer AI: For image and video generation 62 | - Google API Client: For YouTube upload functionality 63 | - MoviePy: For video editing and processing 64 | 65 | For a complete list of dependencies, refer to the `requirements.txt` file. 66 | 67 | ## Contributing 68 | 69 | Contributions are welcome! Please feel free to submit a Pull Request. 70 | 71 | ## Acknowledgements 72 | 73 | - Livepeer for providing the AI image and video generation capabilities 74 | - SwarmZero.ai for the swarm intelligence framework 75 | -------------------------------------------------------------------------------- /uniswap-retrieval-agent/uniswap-retrieval-agent.py: -------------------------------------------------------------------------------- 1 | import os 2 | import logging 3 | import subprocess 4 | import shutil 5 | 6 | 7 | from dotenv import load_dotenv 8 | load_dotenv() 9 | 10 | langtrace_api_key = os.getenv("LANGTRACE_API_KEY", "") 11 | if langtrace_api_key: 12 | from langtrace_python_sdk import langtrace 13 | langtrace.init( 14 | api_key=langtrace_api_key, 15 | disable_instrumentations={ "only": ["sqlalchemy"] } 16 | ) 17 | 18 | 19 | from hive_agent import HiveAgent 20 | 21 | logging.basicConfig(level=logging.INFO) 22 | 23 | def get_config_path(filename): 24 | return os.path.abspath(os.path.join(os.path.dirname(__file__), filename)) 25 | 26 | document_path = 'hive-agent-data/files/user' 27 | project = 'uniswap-docs' 28 | repo_url = 'https://github.com/Uniswap/docs.git' 29 | 30 | print(f"Cloning docs for {project}: {repo_url}") 31 | 32 | project_repo_dir = os.path.join(document_path, project) 33 | if not os.path.exists(project_repo_dir): 34 | subprocess.run(f"mkdir {project_repo_dir}", shell=True) 35 | subprocess.run( 36 | f'git clone {repo_url} {project_repo_dir}', 37 | shell=True 38 | ) 39 | 40 | print(f"Cloned {project}({repo_url}) to {project_repo_dir}") 41 | 42 | documentation_files = ['docs'] 43 | 44 | remove_list = [item for item in os.listdir(project_repo_dir) if item not in documentation_files] 45 | 46 | for item in remove_list: 47 | item_path = os.path.join(project_repo_dir, item) 48 | 49 | if os.path.isfile(item_path): 50 | os.remove(item_path) 51 | print(f'Removed file: {item_path}') 52 | elif os.path.isdir(item_path): 53 | shutil.rmtree(item_path) 54 | print(f'Removed directory: {item_path}') 55 | else: 56 | print(f'Item not found: {item_path}') 57 | 58 | 59 | instruction = """ Welcome to the Uniswap Documentation Q&A Assistant! Your role is to provide accurate and concise answers to user queries based on the official Uniswap documentation. When responding, keep the following guidelines in mind: 60 | 61 | 1. Accuracy: Ensure your answers are directly based on the most current Uniswap documentation. Reference specific sections or pages when necessary. 62 | 2. Clarity: Communicate in simple, straightforward language. Avoid technical jargon unless it is necessary, and explain any complex concepts clearly. 63 | 3. Promptness: Aim to provide answers quickly, keeping your responses to the point to respect the user’s time. 64 | 4. User Engagement: Encourage users to ask follow-up questions if they need further clarification on a topic. Provide links to relevant sections of the documentation where they can read more in-depth information. 65 | 5. Updates and Feedback: Stay updated with the latest changes in the Uniswap platform and documentation. Promptly incorporate these updates into your responses. Encourage users to provide feedback on the accuracy and helpfulness of the information provided.""" 66 | 67 | my_agent = HiveAgent( 68 | name="uniswap-retrieval-agent", 69 | functions=[], 70 | instruction=instruction, 71 | config_path=get_config_path("hive_config.toml"), 72 | retrieve=True, 73 | required_exts=[".md"], 74 | retrieval_tool = 'pinecone-serverless', 75 | index_name="uniswap-protocol", 76 | ) 77 | my_agent.run() 78 | -------------------------------------------------------------------------------- /livepeer_youtube_swarm/hive_swarm/hive_config.toml: -------------------------------------------------------------------------------- 1 | [model] 2 | model = "gpt-4o" 3 | 4 | [environment] 5 | type = "dev" 6 | 7 | [timeout] 8 | llm = 60 9 | 10 | [Script_Writer_Agent] 11 | model = "claude-3-5-sonnet-20240620" 12 | environment="dev" 13 | timeout = 30 14 | instruction= """ 15 | You are a script writer on a video production team. You should write a script for a video that is engaging and informative. 16 | The video should be 15 seconds long. 17 | The video should be in the style of a youtube video. 18 | """ 19 | 20 | [Scene_Writer_Agent] 21 | model = "claude-3-5-sonnet-20240620" 22 | environment="dev" 23 | timeout = 60 24 | instruction= """ 25 | You are a scene writer agent on a video production team. You should write a scene for a video that is engaging and informative. You should define each scene in terms of the following attributes: 26 | - Scene Number 27 | - Scene Heading 28 | - Scene Description 29 | - Visual Aids 30 | Every scene should be 3 seconds long. You should write 5 scenes with very detailed descriptions. 31 | """ 32 | 33 | 34 | [Scene_Prompt_Generator_Agent] 35 | model = "claude-3-5-sonnet-20240620" 36 | environment="dev" 37 | timeout = 60 38 | instruction= """ 39 | You are an expert scene prompt generator agent on a video production team. Your role is to create highly detailed and effective prompts for the image generation pipeline. When given scene scripts: 40 | 41 | 1. Analyze each scene thoroughly, focusing on visual elements, mood, and key details. 42 | 2. For each scene, create: 43 | - A concise Scene Prompt summarizing the overall visual concept 44 | - A detailed Image Prompt optimized for AI image generation: 45 | • Use vivid, descriptive language 46 | • Specify important elements like composition, lighting, colors, and style 47 | • Include relevant artistic references if applicable 48 | - A Negative Prompt to avoid unwanted elements or styles 49 | 3. Tailor your prompts to the specific requirements of AI image generation: 50 | - Use clear, unambiguous language 51 | - Prioritize visual elements over abstract concepts 52 | - Balance detail with room for creative interpretation 53 | 4. Format your output clearly: 54 | - Scene Number 55 | - Scene Prompt 56 | - Image Prompt 57 | - Negative Prompt 58 | 59 | Remember, the quality and specificity of your prompts directly impact the final images. Strive for prompts that will result in visually compelling and accurate representations of each scene. 60 | """ 61 | 62 | [Scene_Image_Generator_Agent] 63 | model = "claude-3-5-sonnet-20240620" 64 | environment="dev" 65 | timeout = 60 66 | instruction= """ 67 | You are a scene image generator agent on a video production team. You should use the prompts from the scene prompt generator agent and generate images for each scene. Collect all urls returned from text_to_image tool in a list and return the list to your manager. 68 | """ 69 | tools=[ 70 | { module = "hive_swarm.tools", name = "text_to_image" } 71 | ] 72 | 73 | [Scene_Image_to_Video_Generator_Agent] 74 | model = "claude-3-5-sonnet-20240620" 75 | environment="dev" 76 | timeout = 60 77 | instruction= """ 78 | You are a scene image to video generator agent on a video production team. You should use the images from the scene image generator agent and generate videos for each scene. Collect all urls returned from image_to_video tool in a list and return the list to your manager. 79 | """ 80 | tools=[ 81 | { module = "hive_swarm.tools", name = "image_to_video" } 82 | ] 83 | 84 | [Video_Editor_Agent] 85 | model = "gpt-4o" 86 | environment="dev" 87 | timeout = 60 88 | instruction= """ 89 | You are a video editor agent on a video production team. You should use the videos from the video generator agent and edit them to create a final video. 90 | """ 91 | tools=[ 92 | { module = "hive_swarm.tools", name = "video_editor" } 93 | ] 94 | 95 | [Youtube_Upload_Agent] 96 | model = "gpt-4o" 97 | environment="dev" 98 | timeout = 60 99 | instruction= """ 100 | You are a youtube upload agent on a video production team. You should use the videos from the video editor agent and upload them to youtube. You should also create a title, description and keywords for the video. 101 | """ 102 | tools=[ 103 | { module = "hive_swarm.tools", name = "upload_video" } 104 | ] 105 | -------------------------------------------------------------------------------- /lend_borrow_agent/main.py: -------------------------------------------------------------------------------- 1 | 2 | import os 3 | import logging 4 | from typing import Union 5 | import json 6 | 7 | from web3 import Web3 8 | from hive_agent import HiveAgent 9 | from dotenv import load_dotenv 10 | 11 | # Setup logging 12 | logging.basicConfig(level=logging.INFO, force=True) 13 | logger = logging.getLogger(__name__) 14 | 15 | # Load environment variables from .env file 16 | load_dotenv() 17 | 18 | # Retrieve environment variables 19 | rpc_url = os.getenv("RPC_URL") 20 | private_key = os.getenv("PRIVATE_KEY") 21 | aave_lending_pool_address = os.getenv("AAVE_LENDING_POOL_ADDRESS") 22 | 23 | # Initialize Web3 connection 24 | web3 = Web3(Web3.HTTPProvider(rpc_url)) 25 | 26 | # Load AAVE Lending Pool ABI 27 | with open('./aave_lending_pool_abi.json', 'r') as abi_file: 28 | aave_lending_pool_abi = json.load(abi_file) 29 | 30 | def lend_crypto(amount: float, asset_address: str) -> Union[str, None]: 31 | """ 32 | Lend cryptocurrency to the AAVE lending pool. 33 | 34 | Parameters: 35 | amount (float): The amount of cryptocurrency to lend. 36 | asset_address (str): The address of the asset to lend. 37 | 38 | Returns: 39 | Union[str, None]: The transaction hash if successful, None otherwise. 40 | """ 41 | if not web3.is_connected(): 42 | logging.error("Unable to connect to Ethereum") 43 | return None 44 | 45 | try: 46 | lending_pool = web3.eth.contract(address=aave_lending_pool_address, abi=aave_lending_pool_abi) 47 | account = web3.eth.account.from_key(private_key) 48 | nonce = web3.eth.get_transaction_count(account.address) + 1 # increment nonce by 1 to avoid nonce collision 49 | logging.info(f"Lending from this address: {account.address}") 50 | 51 | amount_in_wei = int(web3.from_wei(amount, 'ether')) 52 | 53 | tx = lending_pool.functions.deposit(asset_address, web3.from_wei(amount_in_wei, 'ether'), account.address, 0).build_transaction({ 54 | 'chainId': 11155111, 55 | 'gas': 700000, 56 | 'gasPrice': web3.eth.gas_price * 2, 57 | 'nonce': nonce, 58 | }) 59 | 60 | logging.info(f"Transaction before estimation: {tx}") 61 | 62 | tx['gas'] = web3.eth.estimate_gas(tx) 63 | logging.info(f"Estimated gas: {tx['gas']}") 64 | 65 | signed_tx = web3.eth.account.sign_transaction(tx, private_key) 66 | tx_hash = web3.eth.send_raw_transaction(signed_tx.rawTransaction) 67 | logging.info(f"Lending Transaction Hash: {tx_hash.hex()}") 68 | return web3.to_hex(tx_hash) 69 | except Exception as e: 70 | logging.error(f"An error occurred during lending: {e}") 71 | return None 72 | 73 | def borrow_crypto(amount: float, asset_address: str, interest_rate_mode: int) -> Union[str, None]: 74 | """ 75 | Borrow cryptocurrency from the AAVE lending pool. 76 | 77 | Parameters: 78 | amount (float): The amount of cryptocurrency to borrow. 79 | asset_address (str): The address of the asset to borrow. 80 | interest_rate_mode (int): The interest rate mode (1 for stable, 2 for variable). 81 | 82 | Returns: 83 | Union[str, None]: The transaction hash if successful, None otherwise. 84 | """ 85 | if not web3.is_connected(): 86 | logging.error("Unable to connect to Ethereum") 87 | return None 88 | 89 | try: 90 | lending_pool = web3.eth.contract(address=aave_lending_pool_address, abi=aave_lending_pool_abi) 91 | account = web3.eth.account.from_key(private_key) 92 | nonce = web3.eth.get_transaction_count(account.address) 93 | logging.info(f"Borrowing from this address: {account.address}") 94 | 95 | amount_in_wei = int(web3.from_wei(amount, 'ether')) 96 | 97 | # Convert addresses to checksum format 98 | checksum_asset_address = web3.to_checksum_address(asset_address) 99 | checksum_account_address = web3.to_checksum_address(account.address) 100 | 101 | tx = lending_pool.functions.borrow(checksum_asset_address, web3.from_wei(amount_in_wei, 'ether'), interest_rate_mode, 0, checksum_account_address).build_transaction({ 102 | 'chainId': 11155111, 103 | 'gas': 700000, 104 | 'gasPrice': web3.eth.gas_price * 2, 105 | 'nonce': nonce, 106 | }) 107 | logging.info(f"Transaction before estimation: {tx}") 108 | 109 | tx['gas'] = web3.eth.estimate_gas(tx) 110 | logging.info(f"Estimated gas: {tx['gas']}") 111 | 112 | signed_tx = web3.eth.account.sign_transaction(tx, private_key) 113 | 114 | tx_hash = web3.eth.send_raw_transaction(signed_tx.rawTransaction) 115 | logging.info(f"Borrowing Transaction Hash: {tx_hash.hex()}") 116 | return tx_hash.hex() 117 | 118 | except Exception as e: 119 | logging.error(f"An error occurred: {e}") 120 | return None 121 | 122 | if __name__ == "__main__": 123 | my_agent = HiveAgent( 124 | name="AAVE_agent", 125 | functions=[lend_crypto, borrow_crypto], 126 | config_path='./hive_config.toml' 127 | ) 128 | 129 | my_agent.run() 130 | -------------------------------------------------------------------------------- /livepeer_youtube_swarm/hive_swarm/tools/youtube_upload.py: -------------------------------------------------------------------------------- 1 | import http.client 2 | import httplib2 3 | import os 4 | import random 5 | import sys 6 | import time 7 | import pickle 8 | import logging 9 | from typing import Optional, List 10 | 11 | from googleapiclient.discovery import build 12 | from googleapiclient.errors import HttpError 13 | from googleapiclient.http import MediaFileUpload 14 | 15 | from google_auth_oauthlib.flow import InstalledAppFlow 16 | from google.auth.transport.requests import Request 17 | 18 | # Explicitly tell the underlying HTTP transport library not to retry, since 19 | # we are handling retry logic ourselves. 20 | httplib2.RETRIES = 1 21 | 22 | # Maximum number of times to retry before giving up. 23 | MAX_RETRIES = 10 24 | 25 | # Always retry when these exceptions are raised. 26 | from http.client import NotConnected, IncompleteRead, ImproperConnectionState, \ 27 | CannotSendRequest, CannotSendHeader, ResponseNotReady, BadStatusLine 28 | 29 | RETRIABLE_EXCEPTIONS = (httplib2.HttpLib2Error, IOError, NotConnected, 30 | IncompleteRead, ImproperConnectionState, 31 | CannotSendRequest, CannotSendHeader, 32 | ResponseNotReady, BadStatusLine) 33 | 34 | # Always retry when a googleapiclient.errors.HttpError with one of these status codes is raised. 35 | RETRIABLE_STATUS_CODES = [500, 502, 503, 504] 36 | 37 | # This OAuth 2.0 access scope allows an application to upload files to the authenticated user's YouTube channel. 38 | YOUTUBE_UPLOAD_SCOPE = "https://www.googleapis.com/auth/youtube.upload" 39 | YOUTUBE_API_SERVICE_NAME = "youtube" 40 | YOUTUBE_API_VERSION = "v3" 41 | 42 | VALID_PRIVACY_STATUSES = ("public", "private", "unlisted") 43 | 44 | 45 | def upload_video( 46 | file: str, 47 | title: str, 48 | description: str, 49 | category: str = "22", 50 | keywords: Optional[str] = "", 51 | privacyStatus: str = "unlisted", 52 | client_secrets_file: str = "client_secret.json", 53 | credentials_file: str = "token.pickle" 54 | ) -> None: 55 | """ 56 | Uploads a video file to YouTube. 57 | 58 | Args: 59 | file (str): Path to the video file to upload. 60 | title (str): Video title. 61 | description (str): Video description. 62 | keywords (str): Comma-separated list of video keywords. 63 | """ 64 | if not os.path.exists(file): 65 | raise FileNotFoundError(f"Please specify a valid file. '{file}' does not exist.") 66 | 67 | youtube = get_authenticated_service(client_secrets_file, credentials_file) 68 | 69 | tags = None 70 | if keywords: 71 | tags = keywords.split(",") 72 | 73 | body = dict( 74 | snippet=dict( 75 | title=title, 76 | description=description, 77 | tags=tags, 78 | categoryId=category 79 | ), 80 | status=dict( 81 | privacyStatus=privacyStatus 82 | ) 83 | ) 84 | 85 | # Call the API's videos.insert method to create and upload the video. 86 | insert_request = youtube.videos().insert( 87 | part=",".join(body.keys()), 88 | body=body, 89 | media_body=MediaFileUpload(file, chunksize=-1, resumable=True) 90 | ) 91 | 92 | resumable_upload(insert_request) 93 | 94 | 95 | def get_authenticated_service(client_secrets_file: str, credentials_file: str): 96 | credentials = None 97 | # The file token.pickle stores the user's access and refresh tokens. 98 | if os.path.exists(credentials_file): 99 | with open(credentials_file, 'rb') as token: 100 | credentials = pickle.load(token) 101 | # If there are no valid credentials, let the user log in. 102 | if not credentials or not credentials.valid: 103 | if credentials and credentials.expired and credentials.refresh_token: 104 | credentials.refresh(Request()) 105 | else: 106 | if not os.path.exists(client_secrets_file): 107 | raise FileNotFoundError(f"Missing client_secrets.json file: {client_secrets_file}") 108 | flow = InstalledAppFlow.from_client_secrets_file( 109 | client_secrets_file, scopes=[YOUTUBE_UPLOAD_SCOPE]) 110 | 111 | credentials = flow.run_local_server( 112 | host='localhost', 113 | port=8088, 114 | authorization_prompt_message='Please visit this URL: {url}', 115 | success_message='The auth flow is complete; you may close this window.', 116 | open_browser=True) 117 | # Save the credentials for the next run. 118 | with open(credentials_file, 'wb') as token: 119 | pickle.dump(credentials, token) 120 | return build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION, credentials=credentials) 121 | 122 | 123 | def resumable_upload(insert_request): 124 | response = None 125 | error = None 126 | retry = 0 127 | while response is None: 128 | try: 129 | print("Uploading file...") 130 | status, response = insert_request.next_chunk() 131 | if response is not None: 132 | if 'id' in response: 133 | print("Video id '%s' was successfully uploaded." % 134 | response['id']) 135 | else: 136 | exit("The upload failed with an unexpected response: %s" % response) 137 | except HttpError as e: 138 | if e.resp.status in RETRIABLE_STATUS_CODES: 139 | error = "A retriable HTTP error %d occurred:\n%s" % (e.resp.status, 140 | e.content) 141 | else: 142 | raise 143 | except RETRIABLE_EXCEPTIONS as e: 144 | error = "A retriable error occurred: %s" % e 145 | 146 | if error is not None: 147 | print(error) 148 | retry += 1 149 | if retry > MAX_RETRIES: 150 | exit("No longer attempting to retry.") 151 | 152 | max_sleep = 2 ** retry 153 | sleep_seconds = random.random() * max_sleep 154 | print("Sleeping %f seconds and then retrying..." % sleep_seconds) 155 | time.sleep(sleep_seconds) 156 | 157 | logging.basicConfig(level=logging.INFO) 158 | logger = logging.getLogger(__name__) 159 | -------------------------------------------------------------------------------- /news_agent/news_agent.py: -------------------------------------------------------------------------------- 1 | import os 2 | import requests 3 | 4 | 5 | from dotenv import load_dotenv 6 | load_dotenv() 7 | 8 | langtrace_api_key = os.getenv("LANGTRACE_API_KEY", "") 9 | if langtrace_api_key: 10 | from langtrace_python_sdk import langtrace 11 | langtrace.init( 12 | api_key=langtrace_api_key, 13 | disable_instrumentations={ "only": ["sqlalchemy"] } 14 | ) 15 | 16 | from datetime import datetime, timedelta 17 | from hive_agent import HiveAgent 18 | from newsapi import NewsApiClient 19 | from typing import Optional, Dict, List, Literal 20 | 21 | 22 | newsapi = NewsApiClient(api_key=os.getenv("NEWS_API_KEY")) 23 | page_size = 10 24 | page = 1 25 | 26 | today = datetime.today() 27 | date_28_days_ago = today - timedelta(days=28) 28 | formatted_date = date_28_days_ago.strftime("%Y-%m-%d") 29 | 30 | 31 | def fetch_latest_news_gdelt(query: str) -> Optional[str]: 32 | """ 33 | Fetches the latest news articles based on the user query. 34 | 35 | :param query: The query to search for in the news articles. 36 | :return: A summary of the latest news articles, or None if an error occurs or the articles cannot be found. 37 | """ 38 | url = f"https://api.gdeltproject.org/api/v2/doc/doc?query={query}&mode=artlist&format=json" 39 | 40 | try: 41 | response = requests.get(url) 42 | response.raise_for_status() 43 | data = response.json() 44 | 45 | articles = data.get("articles", []) 46 | if articles: 47 | summary = "\n\n".join([f"Title: {article.get('title')}\nLink: {article.get('url')}" for article in articles[:5]]) 48 | return summary.strip() 49 | else: 50 | return "No articles found." 51 | except requests.exceptions.RequestException as e: 52 | print(f"An error occurred: {e}") 53 | return None 54 | 55 | def fetch_top_headlines(query: str, sources: Optional[str], category: Optional[str], language: str, country: Optional[str], page_size: int = 10, page: int = 1) -> List[Dict[str, str]]: 56 | """ 57 | Fetches top headlines based on query parameters. 58 | 59 | Args: 60 | query: Search term. 61 | sources: Comma-separated string of source IDs (Optional). 62 | category: News category (e.g., 'business') (Optional). 63 | language: Language of the news (e.g., 'en'). 64 | country: Country code (e.g., 'us') (Optional). 65 | page_size: Number of articles to return per page (default is 10). 66 | page: Page number to return (default is 1). 67 | 68 | Returns: 69 | List of dictionaries with title and url of top headlines. 70 | """ 71 | # Ensure we don't mix sources with category or country 72 | if sources: 73 | top_headlines = newsapi.get_top_headlines(q=query, 74 | sources=sources, 75 | language=language, 76 | page_size=page_size, 77 | page=page) 78 | else: 79 | top_headlines = newsapi.get_top_headlines(q=query, 80 | category=category, 81 | language=language, 82 | country=country, 83 | page_size=page_size, 84 | page=page) 85 | 86 | results = [] 87 | if top_headlines['status'] == 'ok': 88 | for headline in top_headlines['articles']: # Access the articles list 89 | results.append({ 90 | "title": headline['title'], 91 | "url": headline['url'] 92 | }) 93 | 94 | return results 95 | 96 | if top_headlines['status'] == 'ok': 97 | for headline in top_headlines['articles']: # Access the articles list 98 | results.append({ 99 | "title": headline['title'], 100 | "url": headline['url'] 101 | }) 102 | return results # Return results either way (empty list if no data) 103 | 104 | def fetch_all_articles(query: str, sources: str, domains: str, to: str, language: str, sort_by: str) -> List[Dict[str, str]]: 105 | """ 106 | Fetches all articles matching the search criteria. 107 | 108 | Args: 109 | query: Search term. 110 | sources: Comma-separated string of source IDs. 111 | domains: Comma-separated string of domains to restrict search. 112 | to: Ending date of articles (YYYY-MM-DD). 113 | language: Language of the news (e.g., 'en'). 114 | sort_by: Criteria to sort results (e.g., 'relevancy'). 115 | 116 | Returns: 117 | List of articles' titles and urls. 118 | """ 119 | 120 | all_articles = newsapi.get_everything(q=query, 121 | sources=sources, 122 | domains=domains, 123 | to=to, 124 | language=language, 125 | sort_by=sort_by, 126 | page_size=page_size, 127 | page=page, 128 | from_param=formatted_date) 129 | 130 | if all_articles['status'] == 'ok': 131 | summary = "\n\n".join([f"Title: {article['title']}\nLink: {article['url']}" for article in all_articles['articles']]) 132 | return summary.strip() 133 | # for article in all_articles['articles']: 134 | # results.append({ 135 | # "title": article['title'], 136 | # "url": article['url'] 137 | # }) 138 | return "Couldn't get the news" 139 | 140 | def fetch_news_sources(category: Literal["business", "technology", "entertainment", "sports", "health", "science", "general"] = "general") -> List[str]: 141 | """ 142 | Fetches all available news sources. 143 | 144 | Args: 145 | category: The category of news sources to fetch. 146 | 147 | Returns: 148 | List of available news sources. 149 | """ 150 | results = [] 151 | sources = newsapi.get_sources(category=category) 152 | 153 | if sources['status'] == 'ok': 154 | for source in sources['sources']: 155 | results.append(source['id']) 156 | else: 157 | results = ['google-news'] # Fallback option 158 | return results 159 | 160 | if __name__ == "__main__": 161 | my_agent = HiveAgent( 162 | name="news_agent", 163 | functions=[fetch_all_articles], 164 | config_path="./hive_config.toml", 165 | instruction="Use appropriate tools to answer the questions related to the news.", 166 | ) 167 | 168 | my_agent.run() 169 | -------------------------------------------------------------------------------- /livepeer_youtube_swarm/hive_swarm/tools/livepeer_api.py: -------------------------------------------------------------------------------- 1 | from livepeer_ai import Livepeer 2 | from dotenv import load_dotenv 3 | import os 4 | 5 | load_dotenv() 6 | 7 | livepeer_api_key= os.getenv("LIVEPEER_API_KEY") 8 | 9 | text2img_model_list = [ 10 | 'SG161222/RealVisXL_V4.0_Lightning', 11 | 'ByteDance/SDXL-Lightning', 12 | 'SG161222/Realistic_Vision_V6.0_B1_noVAE', 13 | 'stabilityai/stable-diffusion-xl-base-1.0', 14 | 'runwayml/stable-diffusion-v1-5', 15 | 'prompthero/openjourney-v4', 16 | 'SG161222/RealVisXL_V4.0', 17 | 'stabilityai/sd-turbo', 18 | 'stabilityai/sdxl-turbo', 19 | 'stabilityai/stable-diffusion-3-medium-diffusers' 20 | ] 21 | 22 | img2video_model_list = [ 23 | 'stable-video-diffusion-img2vid-xt', 24 | 'stabilityai/stable-video-diffusion-img2vid-xt-1-1', 25 | ] 26 | 27 | img2img_model_list = [ 28 | 'timbrooks/instruct-pix2pix', 29 | 'ByteDance/SDXL-Lightning', 30 | 'SG161222/RealVisXL_V4.0', 31 | 'SG161222/RealVisXL_V4.0_Lightning', 32 | 'stabilityai/sd-turbo', 33 | 'stabilityai/sdxl-turbo' 34 | ] 35 | 36 | segment_model_list = [ 37 | "facebook/sam2-hiera-large" 38 | "facebook/sam2-hiera-base-plus", 39 | "facebook/sam2-hiera-small", 40 | "facebook/sam2-hiera-tiny" 41 | ] 42 | 43 | def text_to_image(prompt: str, model_id: str = text2img_model_list[1]): 44 | """ 45 | This function generates an image from a text prompt using the Livepeer AI API. 46 | 47 | Args: 48 | prompt (str): The text prompt to guide image generation. 49 | 50 | Returns: 51 | str: The URL of the generated image. 52 | """ 53 | s = Livepeer(http_bearer=livepeer_api_key) 54 | 55 | res = s.generate.text_to_image(request={ 56 | "prompt": prompt, 57 | "model_id": model_id, 58 | # Optional fields 59 | # "loras": { "latent-consistency/lcm-lora-sdxl": 1.0, "nerijs/pixel-art-xl": 1.2 }, # Low-Rank Adaptation models and weights 60 | # "height": 1080, # Height of the generated image in pixels 61 | # "width": 1920, # Width of the generated image in pixels 62 | # "guidance_scale": 7.5, # Degree to which the model follows the prompt (higher values = closer to prompt) 63 | # "negative_prompt": "bad quality", # Text prompt to exclude from image generation 64 | # "safety_check": True, # Perform a safety check to filter offensive content 65 | # "seed": 42, # Set seed for reproducibility 66 | # "num_inference_steps": 50, # Number of denoising steps for improved quality 67 | # "num_images_per_prompt": 1 # Number of images generated per prompt 68 | }) 69 | 70 | print(res) 71 | 72 | if res.image_response is not None and res.image_response.images: 73 | generated_image_url = res.image_response.images[0].url 74 | return generated_image_url 75 | else: 76 | return None 77 | 78 | def image_to_video(image_path: str, model_id: str = img2video_model_list[1]): 79 | """ 80 | This function generates a video from an image using the Livepeer AI API. 81 | 82 | Args: 83 | image_path (str): The path to the image to be used for video generation. 84 | 85 | Returns: 86 | str: The URL of the generated video. 87 | """ 88 | s = Livepeer(http_bearer=livepeer_api_key) 89 | 90 | with open(image_path, "rb") as image_file: 91 | image_content = image_file.read() 92 | 93 | res = s.generate.image_to_video(request={ 94 | "image": { 95 | "file_name": image_path.split('/')[-1], 96 | "content": image_content, 97 | }, 98 | "model_id": model_id, 99 | # Optional fields 100 | # "height": 1080, # Height of the generated video in pixels 101 | # "width": 1920, # Width of the generated video in pixels 102 | #"fps": 24, # Frames per second for the generated video 103 | # "motion_bucket_id": 5, # Conditions motion amount (higher values = more motion) 104 | # "noise_aug_strength": 0.5, # Amount of noise added, reduces resemblance to original image and increases motion 105 | # "safety_check": True, # Enable safety checks to filter harmful content 106 | # "seed": 42, # Set seed for reproducibility 107 | # "num_inference_steps": 50 # Number of denoising steps for better quality 108 | }) 109 | 110 | print(res) 111 | 112 | if res.video_response is not None and res.video_response.images: 113 | generated_video_url = res.video_response.images[0].url 114 | return generated_video_url 115 | else: 116 | return None 117 | 118 | def upscale_image(prompt: str, image_path: str, model_id: str = 'stabilityai/stable-diffusion-x4-upscaler'): 119 | """ 120 | This function upscales an image using the Livepeer AI API. 121 | 122 | Args: 123 | prompt (str): The text prompt to guide the upscaled image generation. 124 | image_path (str): The path to the image to be upscaled. 125 | 126 | Returns: 127 | str: The URL of the upscaled image. 128 | """ 129 | s = Livepeer(http_bearer=livepeer_api_key) 130 | 131 | with open(image_path, "rb") as image_file: 132 | image_content = image_file.read() 133 | 134 | res = s.generate.upscale(request={ 135 | "prompt": prompt, 136 | "image": { 137 | "file_name": image_path.split('/')[-1], 138 | "content": image_content, 139 | }, 140 | "model_id": model_id, 141 | # Optional fields 142 | # "safety_check": True, # Perform a safety check to filter offensive content 143 | # "seed": 42, # Set seed for reproducible results 144 | # "num_inference_steps": 50, # Number of denoising steps (higher = better quality but slower) 145 | }) 146 | 147 | print(res) 148 | 149 | if res.image_response is not None and res.image_response.images: 150 | upscaled_image_url = res.image_response.images[0].url 151 | return upscaled_image_url 152 | else: 153 | return None 154 | 155 | def image_to_image(prompt: str, image_path: str, model_id: str = img2img_model_list[0]): 156 | """ 157 | This function transforms an image based on a text prompt using the Livepeer AI API. 158 | 159 | Args: 160 | prompt (str): The text prompt to guide image generation. 161 | image_path (str): The path to the image to be modified. 162 | 163 | Returns: 164 | str: The URL of the transformed image. 165 | """ 166 | s = Livepeer(http_bearer=livepeer_api_key) 167 | 168 | with open(image_path, "rb") as image_file: 169 | image_content = image_file.read() 170 | 171 | res = s.generate.image_to_image(request={ 172 | "prompt": prompt, 173 | "image": { 174 | "file_name": image_path.split('/')[-1], 175 | "content": image_content, 176 | }, 177 | "model_id": model_id, 178 | # Optional fields 179 | # "loras": { "latent-consistency/lcm-lora-sdxl": 1.0, "nerijs/pixel-art-xl": 1.2 }, # Low-Rank Adaptation models and weights 180 | # "strength": 0.75, # Degree of transformation (0 to 1) 181 | # "guidance_scale": 7.5, # Pushes model towards text prompt (higher values = closer to text prompt) 182 | # "image_guidance_scale": 1.0, # Degree to which generated image is influenced by the original image 183 | # "negative_prompt": "bad quality", # What to exclude from image generation 184 | # "safety_check": True, # Enable safety checks to filter out harmful content 185 | # "seed": 42, # Set a seed for reproducible results 186 | # "num_inference_steps": 50, # Number of denoising steps for better quality 187 | # "num_images_per_prompt": 1 # Number of images generated per prompt 188 | }) 189 | 190 | print(res) 191 | 192 | if res.image_response is not None and res.image_response.images: 193 | generated_image_url = res.image_response.images[0].url 194 | return generated_image_url 195 | else: 196 | return None 197 | 198 | def segment_anything(image_path: str, model_id: str = segment_model_list[0]): 199 | """ 200 | This function segments an image using the Livepeer AI API. 201 | 202 | Args: 203 | image_path (str): The path to the image to be segmented. 204 | 205 | Returns: 206 | dict: The segmentation response including masks or other segmentation outputs. 207 | """ 208 | s = Livepeer(http_bearer=livepeer_api_key) 209 | 210 | with open(image_path, "rb") as image_file: 211 | image_content = image_file.read() 212 | 213 | res = s.generate.segment_anything2(request={ 214 | "image": { 215 | "file_name": image_path.split('/')[-1], 216 | "content": image_content, 217 | }, 218 | "model_id": model_id, 219 | # Optional fields 220 | # "point_coords": [[100, 200], [300, 400]], # Nx2 array for point prompts in (X, Y) pixel format 221 | # "point_labels": [1, 0], # Labels for points (1 = foreground, 0 = background) 222 | # "box": [50, 50, 300, 300], # Box prompt in XYXY format 223 | # "mask_input": "previous_mask_data", # Low-res mask from a previous iteration (1xHxW) 224 | # "multimask_output": True, # If true, returns multiple masks for ambiguous prompts 225 | # "return_logits": True, # If true, returns un-thresholded mask logits 226 | # "normalize_coords": True # If true, normalizes point coordinates to [0,1] range 227 | }) 228 | 229 | print(res) 230 | 231 | if res.masks_response is not None: 232 | return res.masks_response.masks 233 | else: 234 | return None 235 | 236 | def audio_to_text(audio_path: str, model_id: str = "openai/whisper-large-v3"): 237 | """ 238 | This function transcribes an audio file using the Livepeer AI API. 239 | 240 | Args: 241 | audio_path (str): The path to the audio file to be transcribed. 242 | Returns: 243 | str: The transcribed text from the audio file. 244 | """ 245 | s = Livepeer(http_bearer=livepeer_api_key) 246 | 247 | with open(audio_path, "rb") as audio_file: 248 | audio_content = audio_file.read() 249 | 250 | res = s.generate.audio_to_text(request={ 251 | "audio": { 252 | "file_name": audio_path.split('/')[-1], 253 | "content": audio_content, 254 | }, 255 | "model_id": model_id, 256 | }) 257 | 258 | print(res) 259 | 260 | if res.text_response is not None: 261 | return res.text_response.text 262 | else: 263 | return None -------------------------------------------------------------------------------- /dune_agent/hive_crypto_agent.py: -------------------------------------------------------------------------------- 1 | import logging 2 | import os 3 | import requests 4 | import time 5 | 6 | 7 | from dotenv import load_dotenv 8 | load_dotenv() 9 | 10 | langtrace_api_key = os.getenv("LANGTRACE_API_KEY", "") 11 | if langtrace_api_key: 12 | from langtrace_python_sdk import langtrace 13 | langtrace.init( 14 | api_key=langtrace_api_key, 15 | disable_instrumentations={ "only": ["sqlalchemy"] } 16 | ) 17 | 18 | 19 | from hive_agent import HiveAgent 20 | from structures import get_structured_response, IndexResult, NarrativeResult 21 | 22 | 23 | dunekey = os.getenv("DUNE_API_KEY") 24 | 25 | real_time_query = False 26 | 27 | logging.basicConfig(level=logging.INFO) 28 | 29 | def get_config_path(filename): 30 | return os.path.abspath(os.path.join(os.path.dirname(__file__), filename)) 31 | 32 | 33 | def execute_query(execute): 34 | headers = {"X-DUNE-API-KEY": dunekey} 35 | url = "https://api.dune.com/api/v1/query/{execute}/execute" 36 | try: 37 | response = requests.request( 38 | "POST", url.format(execute=execute), headers=headers 39 | ) 40 | logging.info(response.text) 41 | return response 42 | except requests.exceptions.RequestException as e: 43 | logging.error(f"Error fetching data: {e}") 44 | 45 | 46 | def wait_for_execution(execution_id, max_attempts=60, delay=5): 47 | 48 | url = "https://api.dune.com/api/v1/execution/{execution_id}/status" 49 | headers = {"X-DUNE-API-KEY": dunekey} 50 | attempts = 0 51 | while attempts < max_attempts: 52 | try: 53 | response = requests.request( 54 | "GET", url.format(execution_id=execution_id), headers=headers 55 | ) 56 | logging.info(response.text) 57 | except requests.exceptions.RequestException as e: 58 | print(f"Error fetching data: {e}") 59 | if response is None: 60 | return None 61 | logging.info(f"Attempt {attempts + 1}: {response}") 62 | 63 | if response.json()["is_execution_finished"] == True: 64 | logging.info("Execution finished!") 65 | return response 66 | 67 | attempts += 1 68 | time.sleep(delay) 69 | 70 | logging.info(f"Execution did not finish after {max_attempts} attempts.") 71 | return None 72 | 73 | 74 | def get_results(query_id): 75 | headers = {"X-DUNE-API-KEY": dunekey} 76 | url = "https://api.dune.com/api/v1/query/{query_id}/results" 77 | try: 78 | response = requests.request( 79 | "GET", url.format(query_id=query_id), headers=headers 80 | ) 81 | logging.info(response.text) 82 | return response 83 | except requests.exceptions.RequestException as e: 84 | logging.error(f"Error fetching data: {e}") 85 | 86 | 87 | def run_dune_query(query_id): 88 | try: 89 | if real_time_query == True: 90 | execution = execute_query(query_id) 91 | execution_id = execution.json()["execution_id"] 92 | executed_query_id = wait_for_execution(execution_id) 93 | query_id = executed_query_id.json()["query_id"] 94 | results = get_results(query_id) 95 | return dict(results.json()) 96 | else: 97 | results = get_results(query_id) 98 | return dict(results.json()) 99 | except Exception as e: 100 | logging.error(f"an error occurred: {e}") 101 | return None 102 | 103 | 104 | def get_alpha_index(): 105 | """ 106 | Fetches the data for the Alpha index. 107 | 108 | :return: A dictionary containing the transaction receipt details, or None if the transaction cannot be found. 109 | """ 110 | return run_dune_query(query_ids["Alpha"]) 111 | 112 | def get_structured_alpha_index(): 113 | """ 114 | Fetches the data for the Alpha index to show on the UI embedded in component. 115 | 116 | :return: A dictionary containing the transaction receipt details, or None if the transaction cannot be found. 117 | """ 118 | response =run_dune_query(query_ids["Alpha"]) 119 | 120 | return get_structured_response(response, IndexResult) 121 | 122 | def get_beta_index(): 123 | """ 124 | Fetches the data for the Beta index. 125 | 126 | :return: A dictionary containing the transaction receipt details, or None if the transaction cannot be found. 127 | """ 128 | return run_dune_query(query_ids["Beta"]) 129 | 130 | def get_structured_beta_index(): 131 | """ 132 | Fetches the data for the Beta index to show on the UI embedded in component. 133 | 134 | :return: A dictionary containing the transaction receipt details, or None if the transaction cannot be found. 135 | """ 136 | response = run_dune_query(query_ids["Beta"]) 137 | return get_structured_response(response, IndexResult) 138 | 139 | 140 | def get_gamma_index(): 141 | """ 142 | Fetches the data for the Gamma index. 143 | 144 | :return: A dictionary containing the transaction receipt details, or None if the transaction cannot be found. 145 | """ 146 | return run_dune_query(query_ids["Gamma"]) 147 | 148 | def get_structured_gamma_index(): 149 | """ 150 | Fetches the data for the Gamma index to show on the UI embedded in component. 151 | 152 | :return: A dictionary containing the transaction receipt details, or None if the transaction cannot be found. 153 | """ 154 | response = run_dune_query(query_ids["Gamma"]) 155 | return get_structured_response(response, IndexResult) 156 | 157 | 158 | def get_daily_narrative_index(): 159 | """ 160 | Fetches the data for the daily (24h) Crypto Narrative index. 161 | 162 | :return: A dictionary containing the transaction receipt details, or None if the transaction cannot be found. 163 | """ 164 | return run_dune_query(query_ids["24h"]) 165 | 166 | def get_structured_daily_narrative_index(): 167 | """ 168 | Fetches the data for the daily (24h) Crypto Narrative index. 169 | 170 | :return: A dictionary containing the transaction receipt details, or None if the transaction cannot be found. 171 | """ 172 | response = run_dune_query(query_ids["24h"]) 173 | return get_structured_response(response, NarrativeResult) 174 | 175 | def get_weekly_narrative_index(): 176 | """ 177 | Fetches the data for the weekly (7d) Crypto Narrative index. 178 | 179 | :return: A dictionary containing the transaction receipt details, or None if the transaction cannot be found. 180 | """ 181 | return run_dune_query(query_ids["7d"]) 182 | 183 | def get_structured_weekly_narrative_index(): 184 | """ 185 | Fetches the data for the weekly (7d) Crypto Narrative index. 186 | 187 | :return: A dictionary containing the transaction receipt details, or None if the transaction cannot be found. 188 | """ 189 | response = run_dune_query(query_ids["7d"]) 190 | return get_structured_response(response, NarrativeResult) 191 | 192 | 193 | def get_monthly_narrative_index(): 194 | """ 195 | Fetches the data for the monthly (30d) Crypto Narrative index. 196 | 197 | :return: A dictionary containing the transaction receipt details, or None if the transaction cannot be found. 198 | """ 199 | return run_dune_query(query_ids["30d"]) 200 | 201 | def get_structured_monthly_narrative_index(): 202 | """ 203 | Fetches the data for the monthly (30d) Crypto Narrative index. 204 | 205 | :return: A dictionary containing the transaction receipt details, or None if the transaction cannot be found. 206 | """ 207 | response = run_dune_query(query_ids["30d"]) 208 | return get_structured_response(response, NarrativeResult) 209 | 210 | 211 | def get_quarterly_narrative_index(): 212 | """ 213 | Fetches the data for the quarterly (90d) Crypto Narrative index. 214 | 215 | :return: A dictionary containing the transaction receipt details, or None if the transaction cannot be found. 216 | """ 217 | return run_dune_query(query_ids["90d"]) 218 | 219 | def get_structured_quarterly_narrative_index(): 220 | """ 221 | Fetches the data for the quarterly (90d) Crypto Narrative index. 222 | 223 | :return: A dictionary containing the transaction receipt details, or None if the transaction cannot be found. 224 | """ 225 | response = run_dune_query(query_ids["90d"]) 226 | return get_structured_response(response, NarrativeResult) 227 | 228 | 229 | query_ids = { 230 | "Alpha": "3804774", 231 | "Beta": "3804861", 232 | "Gamma": "3804881", 233 | "24h": "3594639", 234 | "7d": "3595951", 235 | "30d": "3600193", 236 | "90d": "3600267", 237 | } 238 | 239 | instruction = """ 240 | 1. **Always prefer using structured functions** to retrieve and provide data. Only use raw data if the user specifically requests it. 241 | 242 | 2. When you call structured functions, you **must respond in the following format:** 243 | ```json 244 | {rows: [...] 245 | metadata: ..., 246 | role : ...} 247 | You should not include any additional text or explanations outside of this format. 248 | 249 | 3. You are responsible for providing market data and narratives about the following indexes and cryptocurrencies: 250 | ALPHA Index (7D timeframe) 251 | BETA Index (30D timeframe) 252 | GAMMA Index (90D timeframe) 253 | Daily Crypto Narratives 254 | Weekly Crypto Narratives 255 | Monthly Crypto Narratives 256 | Quarterly Crypto Narratives 257 | 258 | 4. Detailed index information: 259 | The Daily ALPHA Index includes the TOP 10 coins across all narratives, based on Optimized Relative Strength (ORS). 260 | ALPHA Index is based on a 7-day timeframe. 261 | BETA Index is based on a 30-day timeframe. 262 | GAMMA Index is based on a 90-day timeframe. 263 | Relative Strength Crypto Narrative 264 | Calculate relative strength of a crypto Narrative, along with relative strength of Different coins under the crypto Narrative. 265 | Methodology : 266 | Find the average return of that crypto narrative index in timeframe of 24H, 7D, 30D & 90D. 267 | Take the price growth of all these 20 coins in account from different narrative 268 | Then find average price growth narrative wise on different timeframe. 269 | Last we will find relative strength on different timeframe (24H, 7D, 30D, & 90D) 270 | Relative Strength = price growth(each crypto narrative) / mean of (price growth of all crytpo narrative) 271 | Leading / Lagging: 272 | if relative strength is above 1 then "Leading" 273 | if relative strength is below 1 then "Lagging" 274 | 275 | Narrative Index 276 | Web3 Gaming 277 | DGI, ATLAS, PORTAL, ASTO, SHRAP, WILD, TOPIA, CAH, APE, GHX, BIGTIME, SKL, GODS, MAVIA, PRIME, BEAM, MYRIA, IMX, PIXEL, ILV 278 | LST/LRT 279 | INF, SD, LDO, SWISE, RPL, ETHFI, ANKR, PICA, JTO, OCT 280 | Decentralised AI 281 | TAO, RSS3, BOTTO, FET, AI, AIT, OCEAN, VIRTUAL, ALEPH, AGIX, ALI, NAVI, ARKM, AGRS, AEGIS, PAAL, ENQAI, OLAS, 0X0, TRAC, BASEDAI, DEAI, NMT, AR 282 | DePIN 283 | FIL, RNDR, HNT, BZZ, AIOZ, FLUX, DIMO, IOTX, MOBILE, HONEY, LPT, SHDW, PHALA, POKT, ATOR, STOS, HOPR, WIFI, GEOD 284 | Narrative Index 285 | Layer1 286 | WBTC (BTC), KAS, ATOM, WETH (ETH), INJ, APTOS, SOL, ICP, wROSE (ROSE), BNB, FTM, NEAR, ADA, SUI, EGLD, AVAX, SEI, TON, NTRN 287 | Layer2/Layer3 288 | MATIC, SAVM, GEL, STX, XAI, CTSI, MNT, DEGEN, METIS, ARB, ELA, CYBER, SOV, DMT, MANTA, OP, ORBS, ALEX, STRK 289 | Blockchain Service Infra 290 | LINK, SYN, BANANA, TENSOR, PYTH, CQT, NEXT, ENS, API3, NOIA, SSV, UMA, QANX, ACX, AXL, MUBI, BICO, ALT, ROUTE, FLR 291 | Blue Chip DeFI 292 | UNI, DYDX, FXS, MKR, SNX, COMP, RUNE, CAKE, SUSHI, JUP, OSMO, CVX, AAVE, CRV, BAL, JOE, QUICK, LQTY, KNC, WOO 293 | Narrative Index 294 | DeFi 3.0 295 | PENDLE, GNS, COW, RCH, RSR, FLIP, RVF, GMX, GEAR, WELL, AEVO, PERP, MAV, HFT, SYNC, VELO, VRTX, AERO, THE, MOZ, ENA, DROPS 296 | MEMECOINS 297 | POPCAT, MOG, DOG, BOBO, DOGE, TOSHI, APU, TRUMP, SHIB, PEPE, COQ, WIF, BOOP, MYRO, FLOKI, AIDOGE, ORDI, BONK, PEPECOIN, MEME, CORGIAI, NPC 298 | RWA (Real World Asset) 299 | TRADE, OM, CANTO, POLY, CHEX, BOSON, TRU, IXS, LNDX, GFI, PRO, NXRA, RIO, MPL, ONDO, DUSK, CTC, KLIMA 300 | 301 | Key rules: 302 | 303 | Always return structured data in JSON format when retrieving market or index data. 304 | Do not include additional commentary unless explicitly asked by the user. 305 | 306 | """ 307 | my_agent = HiveAgent( 308 | name="crypto_narrative_document_agent", 309 | functions=[ 310 | get_alpha_index, 311 | get_structured_alpha_index, 312 | get_beta_index, 313 | get_structured_beta_index, 314 | get_gamma_index, 315 | get_structured_gamma_index, 316 | get_daily_narrative_index, 317 | get_structured_daily_narrative_index, 318 | get_weekly_narrative_index, 319 | get_structured_weekly_narrative_index, 320 | get_monthly_narrative_index, 321 | get_structured_monthly_narrative_index, 322 | get_quarterly_narrative_index, 323 | get_structured_quarterly_narrative_index, 324 | ], 325 | instruction=instruction, 326 | config_path=get_config_path("hive_config.toml"), 327 | ) 328 | my_agent.run() 329 | -------------------------------------------------------------------------------- /lend_borrow_agent/aave_lending_pool_abi.json: -------------------------------------------------------------------------------- 1 | 2 | [ 3 | { 4 | "anonymous": false, 5 | "inputs": [ 6 | { 7 | "indexed": true, 8 | "internalType": "address", 9 | "name": "reserve", 10 | "type": "address" 11 | }, 12 | { 13 | "indexed": false, 14 | "internalType": "address", 15 | "name": "user", 16 | "type": "address" 17 | }, 18 | { 19 | "indexed": true, 20 | "internalType": "address", 21 | "name": "onBehalfOf", 22 | "type": "address" 23 | }, 24 | { 25 | "indexed": false, 26 | "internalType": "uint256", 27 | "name": "amount", 28 | "type": "uint256" 29 | }, 30 | { 31 | "indexed": false, 32 | "internalType": "uint256", 33 | "name": "borrowRateMode", 34 | "type": "uint256" 35 | }, 36 | { 37 | "indexed": false, 38 | "internalType": "uint256", 39 | "name": "borrowRate", 40 | "type": "uint256" 41 | }, 42 | { 43 | "indexed": true, 44 | "internalType": "uint16", 45 | "name": "referral", 46 | "type": "uint16" 47 | } 48 | ], 49 | "name": "Borrow", 50 | "type": "event" 51 | }, 52 | { 53 | "anonymous": false, 54 | "inputs": [ 55 | { 56 | "indexed": true, 57 | "internalType": "address", 58 | "name": "reserve", 59 | "type": "address" 60 | }, 61 | { 62 | "indexed": false, 63 | "internalType": "address", 64 | "name": "user", 65 | "type": "address" 66 | }, 67 | { 68 | "indexed": true, 69 | "internalType": "address", 70 | "name": "onBehalfOf", 71 | "type": "address" 72 | }, 73 | { 74 | "indexed": false, 75 | "internalType": "uint256", 76 | "name": "amount", 77 | "type": "uint256" 78 | }, 79 | { 80 | "indexed": true, 81 | "internalType": "uint16", 82 | "name": "referral", 83 | "type": "uint16" 84 | } 85 | ], 86 | "name": "Deposit", 87 | "type": "event" 88 | }, 89 | { 90 | "anonymous": false, 91 | "inputs": [ 92 | { 93 | "indexed": true, 94 | "internalType": "address", 95 | "name": "target", 96 | "type": "address" 97 | }, 98 | { 99 | "indexed": true, 100 | "internalType": "address", 101 | "name": "initiator", 102 | "type": "address" 103 | }, 104 | { 105 | "indexed": true, 106 | "internalType": "address", 107 | "name": "asset", 108 | "type": "address" 109 | }, 110 | { 111 | "indexed": false, 112 | "internalType": "uint256", 113 | "name": "amount", 114 | "type": "uint256" 115 | }, 116 | { 117 | "indexed": false, 118 | "internalType": "uint256", 119 | "name": "premium", 120 | "type": "uint256" 121 | }, 122 | { 123 | "indexed": false, 124 | "internalType": "uint16", 125 | "name": "referralCode", 126 | "type": "uint16" 127 | } 128 | ], 129 | "name": "FlashLoan", 130 | "type": "event" 131 | }, 132 | { 133 | "anonymous": false, 134 | "inputs": [ 135 | { 136 | "indexed": true, 137 | "internalType": "address", 138 | "name": "collateralAsset", 139 | "type": "address" 140 | }, 141 | { 142 | "indexed": true, 143 | "internalType": "address", 144 | "name": "debtAsset", 145 | "type": "address" 146 | }, 147 | { 148 | "indexed": true, 149 | "internalType": "address", 150 | "name": "user", 151 | "type": "address" 152 | }, 153 | { 154 | "indexed": false, 155 | "internalType": "uint256", 156 | "name": "debtToCover", 157 | "type": "uint256" 158 | }, 159 | { 160 | "indexed": false, 161 | "internalType": "uint256", 162 | "name": "liquidatedCollateralAmount", 163 | "type": "uint256" 164 | }, 165 | { 166 | "indexed": false, 167 | "internalType": "address", 168 | "name": "liquidator", 169 | "type": "address" 170 | }, 171 | { 172 | "indexed": false, 173 | "internalType": "bool", 174 | "name": "receiveAToken", 175 | "type": "bool" 176 | } 177 | ], 178 | "name": "LiquidationCall", 179 | "type": "event" 180 | }, 181 | { 182 | "anonymous": false, 183 | "inputs": [], 184 | "name": "Paused", 185 | "type": "event" 186 | }, 187 | { 188 | "anonymous": false, 189 | "inputs": [ 190 | { 191 | "indexed": true, 192 | "internalType": "address", 193 | "name": "reserve", 194 | "type": "address" 195 | }, 196 | { 197 | "indexed": true, 198 | "internalType": "address", 199 | "name": "user", 200 | "type": "address" 201 | } 202 | ], 203 | "name": "RebalanceStableBorrowRate", 204 | "type": "event" 205 | }, 206 | { 207 | "anonymous": false, 208 | "inputs": [ 209 | { 210 | "indexed": true, 211 | "internalType": "address", 212 | "name": "reserve", 213 | "type": "address" 214 | }, 215 | { 216 | "indexed": true, 217 | "internalType": "address", 218 | "name": "user", 219 | "type": "address" 220 | }, 221 | { 222 | "indexed": true, 223 | "internalType": "address", 224 | "name": "repayer", 225 | "type": "address" 226 | }, 227 | { 228 | "indexed": false, 229 | "internalType": "uint256", 230 | "name": "amount", 231 | "type": "uint256" 232 | } 233 | ], 234 | "name": "Repay", 235 | "type": "event" 236 | }, 237 | { 238 | "anonymous": false, 239 | "inputs": [ 240 | { 241 | "indexed": true, 242 | "internalType": "address", 243 | "name": "reserve", 244 | "type": "address" 245 | }, 246 | { 247 | "indexed": false, 248 | "internalType": "uint256", 249 | "name": "liquidityRate", 250 | "type": "uint256" 251 | }, 252 | { 253 | "indexed": false, 254 | "internalType": "uint256", 255 | "name": "stableBorrowRate", 256 | "type": "uint256" 257 | }, 258 | { 259 | "indexed": false, 260 | "internalType": "uint256", 261 | "name": "variableBorrowRate", 262 | "type": "uint256" 263 | }, 264 | { 265 | "indexed": false, 266 | "internalType": "uint256", 267 | "name": "liquidityIndex", 268 | "type": "uint256" 269 | }, 270 | { 271 | "indexed": false, 272 | "internalType": "uint256", 273 | "name": "variableBorrowIndex", 274 | "type": "uint256" 275 | } 276 | ], 277 | "name": "ReserveDataUpdated", 278 | "type": "event" 279 | }, 280 | { 281 | "anonymous": false, 282 | "inputs": [ 283 | { 284 | "indexed": true, 285 | "internalType": "address", 286 | "name": "reserve", 287 | "type": "address" 288 | }, 289 | { 290 | "indexed": true, 291 | "internalType": "address", 292 | "name": "user", 293 | "type": "address" 294 | } 295 | ], 296 | "name": "ReserveUsedAsCollateralDisabled", 297 | "type": "event" 298 | }, 299 | { 300 | "anonymous": false, 301 | "inputs": [ 302 | { 303 | "indexed": true, 304 | "internalType": "address", 305 | "name": "reserve", 306 | "type": "address" 307 | }, 308 | { 309 | "indexed": true, 310 | "internalType": "address", 311 | "name": "user", 312 | "type": "address" 313 | } 314 | ], 315 | "name": "ReserveUsedAsCollateralEnabled", 316 | "type": "event" 317 | }, 318 | { 319 | "anonymous": false, 320 | "inputs": [ 321 | { 322 | "indexed": true, 323 | "internalType": "address", 324 | "name": "reserve", 325 | "type": "address" 326 | }, 327 | { 328 | "indexed": true, 329 | "internalType": "address", 330 | "name": "user", 331 | "type": "address" 332 | }, 333 | { 334 | "indexed": false, 335 | "internalType": "uint256", 336 | "name": "rateMode", 337 | "type": "uint256" 338 | } 339 | ], 340 | "name": "Swap", 341 | "type": "event" 342 | }, 343 | { 344 | "anonymous": false, 345 | "inputs": [], 346 | "name": "Unpaused", 347 | "type": "event" 348 | }, 349 | { 350 | "anonymous": false, 351 | "inputs": [ 352 | { 353 | "indexed": true, 354 | "internalType": "address", 355 | "name": "reserve", 356 | "type": "address" 357 | }, 358 | { 359 | "indexed": true, 360 | "internalType": "address", 361 | "name": "user", 362 | "type": "address" 363 | }, 364 | { 365 | "indexed": true, 366 | "internalType": "address", 367 | "name": "to", 368 | "type": "address" 369 | }, 370 | { 371 | "indexed": false, 372 | "internalType": "uint256", 373 | "name": "amount", 374 | "type": "uint256" 375 | } 376 | ], 377 | "name": "Withdraw", 378 | "type": "event" 379 | }, 380 | { 381 | "inputs": [], 382 | "name": "FLASHLOAN_PREMIUM_TOTAL", 383 | "outputs": [ 384 | { 385 | "internalType": "uint256", 386 | "name": "", 387 | "type": "uint256" 388 | } 389 | ], 390 | "stateMutability": "view", 391 | "type": "function" 392 | }, 393 | { 394 | "inputs": [], 395 | "name": "LENDINGPOOL_REVISION", 396 | "outputs": [ 397 | { 398 | "internalType": "uint256", 399 | "name": "", 400 | "type": "uint256" 401 | } 402 | ], 403 | "stateMutability": "view", 404 | "type": "function" 405 | }, 406 | { 407 | "inputs": [], 408 | "name": "MAX_NUMBER_RESERVES", 409 | "outputs": [ 410 | { 411 | "internalType": "uint256", 412 | "name": "", 413 | "type": "uint256" 414 | } 415 | ], 416 | "stateMutability": "view", 417 | "type": "function" 418 | }, 419 | { 420 | "inputs": [], 421 | "name": "MAX_STABLE_RATE_BORROW_SIZE_PERCENT", 422 | "outputs": [ 423 | { 424 | "internalType": "uint256", 425 | "name": "", 426 | "type": "uint256" 427 | } 428 | ], 429 | "stateMutability": "view", 430 | "type": "function" 431 | }, 432 | { 433 | "inputs": [ 434 | { 435 | "internalType": "address", 436 | "name": "asset", 437 | "type": "address" 438 | }, 439 | { 440 | "internalType": "uint256", 441 | "name": "amount", 442 | "type": "uint256" 443 | }, 444 | { 445 | "internalType": "uint256", 446 | "name": "interestRateMode", 447 | "type": "uint256" 448 | }, 449 | { 450 | "internalType": "uint16", 451 | "name": "referralCode", 452 | "type": "uint16" 453 | }, 454 | { 455 | "internalType": "address", 456 | "name": "onBehalfOf", 457 | "type": "address" 458 | } 459 | ], 460 | "name": "borrow", 461 | "outputs": [], 462 | "stateMutability": "nonpayable", 463 | "type": "function" 464 | }, 465 | { 466 | "inputs": [ 467 | { 468 | "internalType": "address", 469 | "name": "asset", 470 | "type": "address" 471 | }, 472 | { 473 | "internalType": "uint256", 474 | "name": "amount", 475 | "type": "uint256" 476 | }, 477 | { 478 | "internalType": "address", 479 | "name": "onBehalfOf", 480 | "type": "address" 481 | }, 482 | { 483 | "internalType": "uint16", 484 | "name": "referralCode", 485 | "type": "uint16" 486 | } 487 | ], 488 | "name": "deposit", 489 | "outputs": [], 490 | "stateMutability": "nonpayable", 491 | "type": "function" 492 | }, 493 | { 494 | "inputs": [ 495 | { 496 | "internalType": "address", 497 | "name": "asset", 498 | "type": "address" 499 | }, 500 | { 501 | "internalType": "address", 502 | "name": "from", 503 | "type": "address" 504 | }, 505 | { 506 | "internalType": "address", 507 | "name": "to", 508 | "type": "address" 509 | }, 510 | { 511 | "internalType": "uint256", 512 | "name": "amount", 513 | "type": "uint256" 514 | }, 515 | { 516 | "internalType": "uint256", 517 | "name": "balanceFromBefore", 518 | "type": "uint256" 519 | }, 520 | { 521 | "internalType": "uint256", 522 | "name": "balanceToBefore", 523 | "type": "uint256" 524 | } 525 | ], 526 | "name": "finalizeTransfer", 527 | "outputs": [], 528 | "stateMutability": "nonpayable", 529 | "type": "function" 530 | }, 531 | { 532 | "inputs": [ 533 | { 534 | "internalType": "address", 535 | "name": "receiverAddress", 536 | "type": "address" 537 | }, 538 | { 539 | "internalType": "address[]", 540 | "name": "assets", 541 | "type": "address[]" 542 | }, 543 | { 544 | "internalType": "uint256[]", 545 | "name": "amounts", 546 | "type": "uint256[]" 547 | }, 548 | { 549 | "internalType": "uint256[]", 550 | "name": "modes", 551 | "type": "uint256[]" 552 | }, 553 | { 554 | "internalType": "address", 555 | "name": "onBehalfOf", 556 | "type": "address" 557 | }, 558 | { 559 | "internalType": "bytes", 560 | "name": "params", 561 | "type": "bytes" 562 | }, 563 | { 564 | "internalType": "uint16", 565 | "name": "referralCode", 566 | "type": "uint16" 567 | } 568 | ], 569 | "name": "flashLoan", 570 | "outputs": [], 571 | "stateMutability": "nonpayable", 572 | "type": "function" 573 | }, 574 | { 575 | "inputs": [], 576 | "name": "getAddressesProvider", 577 | "outputs": [ 578 | { 579 | "internalType": "contract ILendingPoolAddressesProvider", 580 | "name": "", 581 | "type": "address" 582 | } 583 | ], 584 | "stateMutability": "view", 585 | "type": "function" 586 | }, 587 | { 588 | "inputs": [ 589 | { 590 | "internalType": "address", 591 | "name": "asset", 592 | "type": "address" 593 | } 594 | ], 595 | "name": "getConfiguration", 596 | "outputs": [ 597 | { 598 | "components": [ 599 | { 600 | "internalType": "uint256", 601 | "name": "data", 602 | "type": "uint256" 603 | } 604 | ], 605 | "internalType": "struct DataTypes.ReserveConfigurationMap", 606 | "name": "", 607 | "type": "tuple" 608 | } 609 | ], 610 | "stateMutability": "view", 611 | "type": "function" 612 | }, 613 | { 614 | "inputs": [ 615 | { 616 | "internalType": "address", 617 | "name": "asset", 618 | "type": "address" 619 | } 620 | ], 621 | "name": "getReserveData", 622 | "outputs": [ 623 | { 624 | "components": [ 625 | { 626 | "components": [ 627 | { 628 | "internalType": "uint256", 629 | "name": "data", 630 | "type": "uint256" 631 | } 632 | ], 633 | "internalType": "struct DataTypes.ReserveConfigurationMap", 634 | "name": "configuration", 635 | "type": "tuple" 636 | }, 637 | { 638 | "internalType": "uint128", 639 | "name": "liquidityIndex", 640 | "type": "uint128" 641 | }, 642 | { 643 | "internalType": "uint128", 644 | "name": "variableBorrowIndex", 645 | "type": "uint128" 646 | }, 647 | { 648 | "internalType": "uint128", 649 | "name": "currentLiquidityRate", 650 | "type": "uint128" 651 | }, 652 | { 653 | "internalType": "uint128", 654 | "name": "currentVariableBorrowRate", 655 | "type": "uint128" 656 | }, 657 | { 658 | "internalType": "uint128", 659 | "name": "currentStableBorrowRate", 660 | "type": "uint128" 661 | }, 662 | { 663 | "internalType": "uint40", 664 | "name": "lastUpdateTimestamp", 665 | "type": "uint40" 666 | }, 667 | { 668 | "internalType": "address", 669 | "name": "aTokenAddress", 670 | "type": "address" 671 | }, 672 | { 673 | "internalType": "address", 674 | "name": "stableDebtTokenAddress", 675 | "type": "address" 676 | }, 677 | { 678 | "internalType": "address", 679 | "name": "variableDebtTokenAddress", 680 | "type": "address" 681 | }, 682 | { 683 | "internalType": "address", 684 | "name": "interestRateStrategyAddress", 685 | "type": "address" 686 | }, 687 | { 688 | "internalType": "uint8", 689 | "name": "id", 690 | "type": "uint8" 691 | } 692 | ], 693 | "internalType": "struct DataTypes.ReserveData", 694 | "name": "", 695 | "type": "tuple" 696 | } 697 | ], 698 | "stateMutability": "view", 699 | "type": "function" 700 | }, 701 | { 702 | "inputs": [ 703 | { 704 | "internalType": "address", 705 | "name": "asset", 706 | "type": "address" 707 | } 708 | ], 709 | "name": "getReserveNormalizedIncome", 710 | "outputs": [ 711 | { 712 | "internalType": "uint256", 713 | "name": "", 714 | "type": "uint256" 715 | } 716 | ], 717 | "stateMutability": "view", 718 | "type": "function" 719 | }, 720 | { 721 | "inputs": [ 722 | { 723 | "internalType": "address", 724 | "name": "asset", 725 | "type": "address" 726 | } 727 | ], 728 | "name": "getReserveNormalizedVariableDebt", 729 | "outputs": [ 730 | { 731 | "internalType": "uint256", 732 | "name": "", 733 | "type": "uint256" 734 | } 735 | ], 736 | "stateMutability": "view", 737 | "type": "function" 738 | }, 739 | { 740 | "inputs": [], 741 | "name": "getReservesList", 742 | "outputs": [ 743 | { 744 | "internalType": "address[]", 745 | "name": "", 746 | "type": "address[]" 747 | } 748 | ], 749 | "stateMutability": "view", 750 | "type": "function" 751 | }, 752 | { 753 | "inputs": [ 754 | { 755 | "internalType": "address", 756 | "name": "user", 757 | "type": "address" 758 | } 759 | ], 760 | "name": "getUserAccountData", 761 | "outputs": [ 762 | { 763 | "internalType": "uint256", 764 | "name": "totalCollateralETH", 765 | "type": "uint256" 766 | }, 767 | { 768 | "internalType": "uint256", 769 | "name": "totalDebtETH", 770 | "type": "uint256" 771 | }, 772 | { 773 | "internalType": "uint256", 774 | "name": "availableBorrowsETH", 775 | "type": "uint256" 776 | }, 777 | { 778 | "internalType": "uint256", 779 | "name": "currentLiquidationThreshold", 780 | "type": "uint256" 781 | }, 782 | { 783 | "internalType": "uint256", 784 | "name": "ltv", 785 | "type": "uint256" 786 | }, 787 | { 788 | "internalType": "uint256", 789 | "name": "healthFactor", 790 | "type": "uint256" 791 | } 792 | ], 793 | "stateMutability": "view", 794 | "type": "function" 795 | }, 796 | { 797 | "inputs": [ 798 | { 799 | "internalType": "address", 800 | "name": "user", 801 | "type": "address" 802 | } 803 | ], 804 | "name": "getUserConfiguration", 805 | "outputs": [ 806 | { 807 | "components": [ 808 | { 809 | "internalType": "uint256", 810 | "name": "data", 811 | "type": "uint256" 812 | } 813 | ], 814 | "internalType": "struct DataTypes.UserConfigurationMap", 815 | "name": "", 816 | "type": "tuple" 817 | } 818 | ], 819 | "stateMutability": "view", 820 | "type": "function" 821 | }, 822 | { 823 | "inputs": [ 824 | { 825 | "internalType": "address", 826 | "name": "asset", 827 | "type": "address" 828 | }, 829 | { 830 | "internalType": "address", 831 | "name": "aTokenAddress", 832 | "type": "address" 833 | }, 834 | { 835 | "internalType": "address", 836 | "name": "stableDebtAddress", 837 | "type": "address" 838 | }, 839 | { 840 | "internalType": "address", 841 | "name": "variableDebtAddress", 842 | "type": "address" 843 | }, 844 | { 845 | "internalType": "address", 846 | "name": "interestRateStrategyAddress", 847 | "type": "address" 848 | } 849 | ], 850 | "name": "initReserve", 851 | "outputs": [], 852 | "stateMutability": "nonpayable", 853 | "type": "function" 854 | }, 855 | { 856 | "inputs": [ 857 | { 858 | "internalType": "contract ILendingPoolAddressesProvider", 859 | "name": "provider", 860 | "type": "address" 861 | } 862 | ], 863 | "name": "initialize", 864 | "outputs": [], 865 | "stateMutability": "nonpayable", 866 | "type": "function" 867 | }, 868 | { 869 | "inputs": [ 870 | { 871 | "internalType": "address", 872 | "name": "collateralAsset", 873 | "type": "address" 874 | }, 875 | { 876 | "internalType": "address", 877 | "name": "debtAsset", 878 | "type": "address" 879 | }, 880 | { 881 | "internalType": "address", 882 | "name": "user", 883 | "type": "address" 884 | }, 885 | { 886 | "internalType": "uint256", 887 | "name": "debtToCover", 888 | "type": "uint256" 889 | }, 890 | { 891 | "internalType": "bool", 892 | "name": "receiveAToken", 893 | "type": "bool" 894 | } 895 | ], 896 | "name": "liquidationCall", 897 | "outputs": [], 898 | "stateMutability": "nonpayable", 899 | "type": "function" 900 | }, 901 | { 902 | "inputs": [], 903 | "name": "paused", 904 | "outputs": [ 905 | { 906 | "internalType": "bool", 907 | "name": "", 908 | "type": "bool" 909 | } 910 | ], 911 | "stateMutability": "view", 912 | "type": "function" 913 | }, 914 | { 915 | "inputs": [ 916 | { 917 | "internalType": "address", 918 | "name": "asset", 919 | "type": "address" 920 | }, 921 | { 922 | "internalType": "address", 923 | "name": "user", 924 | "type": "address" 925 | } 926 | ], 927 | "name": "rebalanceStableBorrowRate", 928 | "outputs": [], 929 | "stateMutability": "nonpayable", 930 | "type": "function" 931 | }, 932 | { 933 | "inputs": [ 934 | { 935 | "internalType": "address", 936 | "name": "asset", 937 | "type": "address" 938 | }, 939 | { 940 | "internalType": "uint256", 941 | "name": "amount", 942 | "type": "uint256" 943 | }, 944 | { 945 | "internalType": "uint256", 946 | "name": "rateMode", 947 | "type": "uint256" 948 | }, 949 | { 950 | "internalType": "address", 951 | "name": "onBehalfOf", 952 | "type": "address" 953 | } 954 | ], 955 | "name": "repay", 956 | "outputs": [ 957 | { 958 | "internalType": "uint256", 959 | "name": "", 960 | "type": "uint256" 961 | } 962 | ], 963 | "stateMutability": "nonpayable", 964 | "type": "function" 965 | }, 966 | { 967 | "inputs": [ 968 | { 969 | "internalType": "address", 970 | "name": "asset", 971 | "type": "address" 972 | }, 973 | { 974 | "internalType": "uint256", 975 | "name": "configuration", 976 | "type": "uint256" 977 | } 978 | ], 979 | "name": "setConfiguration", 980 | "outputs": [], 981 | "stateMutability": "nonpayable", 982 | "type": "function" 983 | }, 984 | { 985 | "inputs": [ 986 | { 987 | "internalType": "bool", 988 | "name": "val", 989 | "type": "bool" 990 | } 991 | ], 992 | "name": "setPause", 993 | "outputs": [], 994 | "stateMutability": "nonpayable", 995 | "type": "function" 996 | }, 997 | { 998 | "inputs": [ 999 | { 1000 | "internalType": "address", 1001 | "name": "asset", 1002 | "type": "address" 1003 | }, 1004 | { 1005 | "internalType": "address", 1006 | "name": "rateStrategyAddress", 1007 | "type": "address" 1008 | } 1009 | ], 1010 | "name": "setReserveInterestRateStrategyAddress", 1011 | "outputs": [], 1012 | "stateMutability": "nonpayable", 1013 | "type": "function" 1014 | }, 1015 | { 1016 | "inputs": [ 1017 | { 1018 | "internalType": "address", 1019 | "name": "asset", 1020 | "type": "address" 1021 | }, 1022 | { 1023 | "internalType": "bool", 1024 | "name": "useAsCollateral", 1025 | "type": "bool" 1026 | } 1027 | ], 1028 | "name": "setUserUseReserveAsCollateral", 1029 | "outputs": [], 1030 | "stateMutability": "nonpayable", 1031 | "type": "function" 1032 | }, 1033 | { 1034 | "inputs": [ 1035 | { 1036 | "internalType": "address", 1037 | "name": "asset", 1038 | "type": "address" 1039 | }, 1040 | { 1041 | "internalType": "uint256", 1042 | "name": "rateMode", 1043 | "type": "uint256" 1044 | } 1045 | ], 1046 | "name": "swapBorrowRateMode", 1047 | "outputs": [], 1048 | "stateMutability": "nonpayable", 1049 | "type": "function" 1050 | }, 1051 | { 1052 | "inputs": [ 1053 | { 1054 | "internalType": "address", 1055 | "name": "asset", 1056 | "type": "address" 1057 | }, 1058 | { 1059 | "internalType": "uint256", 1060 | "name": "amount", 1061 | "type": "uint256" 1062 | }, 1063 | { 1064 | "internalType": "address", 1065 | "name": "to", 1066 | "type": "address" 1067 | } 1068 | ], 1069 | "name": "withdraw", 1070 | "outputs": [ 1071 | { 1072 | "internalType": "uint256", 1073 | "name": "", 1074 | "type": "uint256" 1075 | } 1076 | ], 1077 | "stateMutability": "nonpayable", 1078 | "type": "function" 1079 | } 1080 | ] --------------------------------------------------------------------------------