Skip to content

near-research/delegate-agent

Repository files navigation

NEAR AI Delegate

Warning

This technology has not yet undergone a formal audit. Please conduct your own due diligence and exercise caution before integrating or relying on it in production environments.

This agent detects House of Stake proposals, evaluates them using NEAR AI, and casts on-chain votes with veNEAR voting power delegated to it.

Built with the Shade Agent framework

Features

  • πŸ’­ LLM-Based Analysis: NEAR AI Cloud
  • πŸ” Secure Execution: Phala (TEEs)
  • πŸ“‘ Monitoring: Intear Events API

Prerequisites

Required Tools

near-cli-rs

curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/near-cli-rs/releases/latest/download/near-cli-rs-installer.sh | sh

shade-agent-cli

npm i -g @neardefi/shade-agent-cli

Docker

Install Docker for Mac or Linux and set up an account.

Log in to docker, docker login for Mac or sudo docker login for Linux.

Accounts & Keys

  1. Create NEAR testnet account:
near account create-account sponsor-by-faucet-service <example.testnet> autogenerate-new-keypair print-to-terminal network-config testnet create

Important

Be sure to record the account name and seed phrase!

  1. Get Phala Cloud API key:

Phala Cloud is a service that offers secure and private hosting in a TEE using Dstack.

  1. Get NEAR AI Cloud API key:

Setup

  1. Clone the repository:
git clone https://github.com/near-research/delegate-agent && cd delegate-agent
  1. Install dependencies:
npm i
  1. Configure environment:
cp .env.development.local.example .env.development.local

Getting Started

Edit .env.development.local with your credentials:

NEAR_AI_CLOUD_API_KEY=your_near_ai_api_key
NEAR_ACCOUNT_ID=your_near_account_id
NEAR_SEED_PHRASE="your seed phrase"
NEXT_PUBLIC_contractId=ac-proxy.example.testnet
VOTING_CONTRACT_ID=vote.ballotbox.testnet
VENEAR_CONTRACT_ID=v.hos03.testnet
NEAR_RPC_JSON=https://rpc.testnet.fastnear.com

Start Docker:

Mac

Simply open the Docker Desktop application or run:

open -a Docker

Linux

sudo systemctl start docker

Local Development

  1. Deploy proxy contract locally:
# Build contract
cd contract
docker run --rm -v "$(pwd)":/workspace pivortex/near-builder@sha256:cdffded38c6cff93a046171269268f99d517237fac800f58e5ad1bcd8d6e2418 cargo near build non-reproducible-wasm

# Deploy with Shade Agent CLI
cd ..
shade-agent-cli --wasm contract/target/near/contract.wasm --funding 5

The CLI on Linux may prompt you to enter your sudo password.

  1. Start agent in another terminal:
npm run dev

The app will be running here: https://localhost:3000

Contract Development

The proxy contract is in contract/:

  • src/lib.rs - Main contract logic
  • src/traits.rs - Type definitions and external contract interfaces

TEE Deployment

  1. Change the NEXT_PUBLIC_contractId prefix to ac-sandbox.example.testnet

  2. Run the Shade Agent CLI

shade-agent-cli --wasm contract/target/near/contract.wasm --funding 5

The CLI on Linux may prompt you to enter your sudo password.

The last URL the CLI outputs is where your app is hosted.

If your application is not working, head over to your App on Phala Dashboard and review the logs.

Interacting with the Agent

You can interact with your agent via the APIs directly or via a lightweight frontend contained in this repo.

Direct

For Phala deployments, swap localhost:3000 for your deployment URL.

Testing

To see the agent in action:

cd frontend
npm i
npm run dev

To run the frontend with your Phala deployment, change the API_URL to Phala URL in your config.js file.

API Endpoints

Vote on Proposal

POST /api/vote
Content-Type: application/json

{
  "proposalId": "0"
}

Manual Vote

POST /api/manual-vote
Content-Type: application/json

{
  "proposalId": "0",
  "vote": 0  # 0=For, 1=Against, 2=Abstain
}

Check Status

GET /api/vote/status
GET /api/vote/status/:proposalId
GET /api/agent-status

More Info

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 5