Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Akash Network plugin with autonomous deployment capabilities #2111

Merged
merged 11 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,52 @@ TAVILY_API_KEY=
VERIFIABLE_INFERENCE_ENABLED=false # Set to false to disable verifiable inference
VERIFIABLE_INFERENCE_PROVIDER=opacity # Options: opacity


# Autonome Configuration
AUTONOME_JWT_TOKEN=
AUTONOME_RPC=https://wizard-bff-rpc.alt.technology/v1/bff/aaa/apps

####################################
#### Akash Network Configuration ####
####################################
AKASH_ENV=mainnet
AKASH_NET=https://raw.githubusercontent.com/ovrclk/net/master/mainnet
RPC_ENDPOINT=https://rpc.akashnet.net:443
AKASH_GAS_PRICES=0.025uakt
AKASH_GAS_ADJUSTMENT=1.5
AKASH_KEYRING_BACKEND=os
AKASH_FROM=default
AKASH_FEES=20000uakt
AKASH_DEPOSIT=500000uakt
AKASH_MNEMONIC=
AKASH_WALLET_ADDRESS=
# Akash Pricing API
AKASH_PRICING_API_URL=https://console-api.akash.network/v1/pricing
# Default values # 1 CPU = 1000 1GB = 1000000000 1GB = 1000000000
AKASH_DEFAULT_CPU=1000
AKASH_DEFAULT_MEMORY=1000000000
AKASH_DEFAULT_STORAGE=1000000000
AKASH_SDL=example.sdl.yml
# Close deployment
# Close all deployments = closeAll
# Close a single deployment = dseq and add the value in AKASH_CLOSE_DSEQ
AKASH_CLOSE_DEP=closeAll
AKASH_CLOSE_DSEQ=19729929
# Provider Info we added one to check you will have to pass this into the action
AKASH_PROVIDER_INFO=akash1ccktptfkvdc67msasmesuy5m7gpc76z75kukpz
# Deployment Status
# AKASH_DEP_STATUS = dseq or param_passed when you are building you wil pass the dseq dinamically to test you
# you can pass the dseq using AKASH_DEP_DSEQ 19729929 is an example of a dseq we test while build.
AKASH_DEP_STATUS=dseq
AKASH_DEP_DSEQ=19729929
# Gas Estimation Options: close, create, or update
# qseq is required when operation is "close" 19729929 is an example of a dseq we test while build.
AKASH_GAS_OPERATION=close
AKASH_GAS_DSEQ=19729929
# Manifest
# Values: "auto" | "manual" | "validate_only" Default: "auto"
AKASH_MANIFEST_MODE=auto
# Default: Will use the SDL directory
AKASH_MANIFEST_PATH=
# Values: "strict" | "lenient" | "none" - Default: "strict"
AKASH_MANIFEST_VALIDATION_LEVEL=strict
1 change: 1 addition & 0 deletions agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"@elizaos/plugin-arthera": "workspace:*",
"@elizaos/plugin-allora": "workspace:*",
"@elizaos/plugin-opacity": "workspace:*",
"@elizaos/plugin-akash": "workspace:*",
"readline": "1.3.0",
"ws": "8.18.0",
"yargs": "17.7.2"
Expand Down
5 changes: 5 additions & 0 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ import { zksyncEraPlugin } from "@elizaos/plugin-zksync-era";
import { OpacityAdapter } from "@elizaos/plugin-opacity";
import { openWeatherPlugin } from "@elizaos/plugin-open-weather";
import { stargazePlugin } from "@elizaos/plugin-stargaze";
import { akashPlugin } from "@elizaos/plugin-akash";
import Database from "better-sqlite3";
import fs from "fs";
import net from "net";
Expand Down Expand Up @@ -753,6 +754,10 @@ export async function createAgent(
? artheraPlugin
: null,
getSecret(character, "ALLORA_API_KEY") ? alloraPlugin : null,
getSecret(character, "AKASH_MNEMONIC") &&
getSecret(character, "AKASH_WALLET_ADDRESS")
? akashPlugin
: null,
].filter(Boolean),
providers: [],
actions: [],
Expand Down
29 changes: 29 additions & 0 deletions packages/plugin-akash/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
parserOptions: {
project: './tsconfig.json',
tsconfigRootDir: __dirname,
ecmaVersion: 2020,
sourceType: 'module',
},
plugins: ['@typescript-eslint'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
],
rules: {
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-unused-vars': ['error', {
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
ignoreRestSiblings: true,
}],
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-non-null-assertion': 'warn',
'no-console': ['error', { allow: ['warn', 'error'] }],
},
ignorePatterns: ['dist/', 'node_modules/', '*.js', '*.mjs', '*.cjs'],
};
6 changes: 6 additions & 0 deletions packages/plugin-akash/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*

!dist/**
!package.json
!readme.md
!tsup.config.ts
Binary file added packages/plugin-akash/assets/akash.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions packages/plugin-akash/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import eslintGlobalConfig from "../../eslint.config.mjs";

export default [...eslintGlobalConfig];
31 changes: 31 additions & 0 deletions packages/plugin-akash/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
roots: ['<rootDir>/test'],
testMatch: [
"**/__tests__/**/*.+(ts|tsx|js)",
"**/?(*.)+(spec|test).+(ts|tsx|js)"
],
transform: {
"^.+\\.(ts|tsx)$": "ts-jest"
},
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1'
},
setupFilesAfterEnv: ['<rootDir>/test/setup/jest.setup.ts'],
globals: {
'ts-jest': {
tsconfig: 'tsconfig.json'
}
},
testTimeout: 30000,
verbose: true,
collectCoverage: true,
coverageDirectory: "coverage",
coverageReporters: ["text", "lcov"],
coveragePathIgnorePatterns: [
"/node_modules/",
"/test/fixtures/",
"/test/setup/"
]
};
51 changes: 51 additions & 0 deletions packages/plugin-akash/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "@elizaos/plugin-akash",
"version": "0.1.0",
"description": "Akash Network Plugin for Eliza",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"type": "module",
"scripts": {
"build": "tsup",
"dev": "tsup --watch",
"clean": "rm -rf dist",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"test": "vitest",
"test:watch": "vitest watch",
"test:coverage": "vitest run --coverage",
"test:ui": "vitest --ui"
},
"dependencies": {
"@akashnetwork/akash-api": "^1.4.0",
"@akashnetwork/akashjs": "0.10.1",
"@cosmjs/proto-signing": "^0.31.3",
"@cosmjs/stargate": "0.31.3",
"@elizaos/core": "workspace:*",
"axios": "^1.7.9",
"dotenv": "^16.4.1",
"jsrsasign": "^11.1.0",
"node-fetch": "^2.7.0",
"zod": "^3.22.4",
"@types/js-yaml": "^4.0.9"
},
"devDependencies": {
"@types/dotenv": "^8.2.0",
"@types/jest": "^29.5.11",
"@types/js-yaml": "^4.0.9",
"@types/node": "^20.10.5",
"@typescript-eslint/eslint-plugin": "^6.15.0",
"@typescript-eslint/parser": "^6.15.0",
"@vitest/coverage-v8": "^0.34.6",
"@vitest/ui": "^0.34.6",
"eslint": "^8.56.0",
"tsup": "^8.0.1",
"typescript": "^5.3.3",
"vite": "^5.0.10",
"vite-tsconfig-paths": "^4.2.2",
"vitest": "^0.34.6"
},
"peerDependencies": {
"@elizaos/core": "workspace:*"
}
}
133 changes: 133 additions & 0 deletions packages/plugin-akash/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# Akash Network Plugin for Eliza

A powerful plugin for interacting with the Akash Network, enabling deployment management and cloud compute operations through Eliza.

## Table of Contents
- [Installation](#installation)
- [Configuration](#configuration)
- [Directory Structure](#directory-structure)
- [Available Actions](#available-actions)

## Installation

```bash
pnpm add @elizaos/plugin-akash
```

## Configuration

### Environment Variables
Create a `.env` file in your project root with the following configuration:

```env
# Network Configuration
AKASH_ENV=mainnet
AKASH_NET=https://raw.githubusercontent.com/ovrclk/net/master/mainnet
RPC_ENDPOINT=https://rpc.akashnet.net:443

# Transaction Settings
AKASH_GAS_PRICES=0.025uakt
AKASH_GAS_ADJUSTMENT=1.5
AKASH_KEYRING_BACKEND=os
AKASH_FROM=default
AKASH_FEES=20000uakt

# Authentication
AKASH_MNEMONIC=your_12_word_mnemonic_here

# Manifest Settings
AKASH_MANIFEST_MODE=auto # Options: auto, validate_only
AKASH_MANIFEST_VALIDATION_LEVEL=strict # Options: strict, basic, none
AKASH_MANIFEST_PATH=/path/to/manifests # Optional: Path to save generated manifests

# Deployment Settings
AKASH_DEPOSIT=5000000uakt # Default deployment deposit
AKASH_SDL=deployment.yml # Default SDL file name
```

**Important Notes:**
- `AKASH_MNEMONIC`: Your 12-word wallet mnemonic phrase (required)
- `AKASH_MANIFEST_MODE`: Controls manifest generation behavior
- `AKASH_MANIFEST_VALIDATION_LEVEL`: Sets SDL validation strictness
- `AKASH_DEPOSIT`: Default deposit amount for deployments

⚠️ Never commit your `.env` file with real credentials to version control!


#### SDL (Stack Definition Language)
```
src/sdl/example.sdl.yml
```
Place your SDL configuration files here. The plugin looks for SDL files in this directory by default.

#### Certificates
```
src/.certificates/
```
SSL certificates for secure provider communication are stored here.

## Available Actions

| Action | Description | Parameters |
|---------------------|------------------------------------------------|---------------------------------------------|
| CREATE_DEPLOYMENT | Create a new deployment | `sdl`, `sdlFile`, `deposit` |
| CLOSE_DEPLOYMENT | Close an existing deployment | `dseq`, `owner` |
| GET_PROVIDER_INFO | Get provider information | `provider` |
| GET_DEPLOYMENT_STATUS| Check deployment status | `dseq`, `owner` |
| GET_GPU_PRICING | Get GPU pricing comparison | `cpu`, `memory`, `storage` |
| GET_MANIFEST | Generate deployment manifest | `sdl`, `sdlFile` |
| GET_PROVIDERS_LIST | List available providers | `filter: { active, hasGPU, region }` |


Each action returns a structured response with:
```typescript
{
text: string; // Human-readable response
content: {
success: boolean; // Operation success status
data?: any; // Action-specific data
error?: { // Present only on failure
code: string;
message: string;
};
metadata: { // Operation metadata
timestamp: string;
source: string;
action: string;
version: string;
actionId: string;
}
}
}
```

## Error Handling

The plugin includes comprehensive error handling with specific error codes:

- `VALIDATION_SDL_FAILED`: SDL validation errors
- `WALLET_NOT_INITIALIZED`: Wallet setup issues
- `DEPLOYMENT_CREATION_FAILED`: Deployment failures
- `API_REQUEST_FAILED`: Network/API issues
- `MANIFEST_PARSING_FAILED`: Manifest generation errors
- `PROVIDER_FILTER_ERROR`: Provider filtering issues

## Development

### Running Tests
```bash
pnpm test
```

### Building
```bash
pnpm run build
```

## License

This project is licensed under the MIT License - see the LICENSE file for details.

## Support

For support and questions, please open an issue in the repository or contact the maintainers.
Loading
Loading