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 router nitro plugin #2590

Merged
merged 6 commits into from
Jan 21, 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
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -708,3 +708,7 @@ PYTH_ENABLE_PRICE_STREAMING=true
PYTH_MAX_PRICE_STREAMS=2
PYTH_TEST_ID01=0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43
PYTH_TEST_ID02=0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace

# Router Nitro EVM Configuration
ROUTER_NITRO_EVM_ADDRESS=
ROUTER_NITRO_EVM_PRIVATE_KEY=
1 change: 1 addition & 0 deletions agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
"@elizaos/plugin-openai": "workspace:*",
"@elizaos/plugin-devin": "workspace:*",
"@elizaos/plugin-holdstation": "workspace:*",
"@elizaos/plugin-router-nitro": "workspace:*",
"readline": "1.3.0",
"ws": "8.18.0",
"yargs": "17.7.2"
Expand Down
63 changes: 32 additions & 31 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ import { dexScreenerPlugin } from "@elizaos/plugin-dexscreener";
import { pythDataPlugin } from "@elizaos/plugin-pyth-data";

import { openaiPlugin } from '@elizaos/plugin-openai';
import nitroPlugin from "@elizaos/plugin-router-nitro";
import { devinPlugin } from '@elizaos/plugin-devin';


Expand Down Expand Up @@ -585,10 +586,9 @@ export function getTokenForProvider(
settings.VENICE_API_KEY
);
case ModelProviderName.ATOMA:
return (
character.settings?.secrets?.ATOMASDK_BEARER_AUTH ||
settings.ATOMASDK_BEARER_AUTH
);
return (
character.settings?.secrets?.ATOMASDK_BEARER_AUTH ||
settings.ATOMASDK_BEARER_AUTH);
case ModelProviderName.NVIDIA:
return (
character.settings?.secrets?.NVIDIA_API_KEY ||
Expand Down Expand Up @@ -912,10 +912,11 @@ export async function createAgent(
? confluxPlugin
: null,
nodePlugin,
(getSecret(character, "ROUTER_NITRO_EVM_PRIVATE_KEY") && getSecret(character, "ROUTER_NITRO_EVM_ADDRESS")) ? nitroPlugin : null,
getSecret(character, "TAVILY_API_KEY") ? webSearchPlugin : null,
getSecret(character, "SOLANA_PUBLIC_KEY") ||
(getSecret(character, "WALLET_PUBLIC_KEY") &&
!getSecret(character, "WALLET_PUBLIC_KEY")?.startsWith("0x"))
(getSecret(character, "WALLET_PUBLIC_KEY") &&
!getSecret(character, "WALLET_PUBLIC_KEY")?.startsWith("0x"))
? solanaPlugin
: null,
getSecret(character, "SOLANA_PRIVATE_KEY")
Expand All @@ -924,12 +925,12 @@ export async function createAgent(
getSecret(character, "AUTONOME_JWT_TOKEN") ? autonomePlugin : null,
(getSecret(character, "NEAR_ADDRESS") ||
getSecret(character, "NEAR_WALLET_PUBLIC_KEY")) &&
getSecret(character, "NEAR_WALLET_SECRET_KEY")
getSecret(character, "NEAR_WALLET_SECRET_KEY")
? nearPlugin
: null,
getSecret(character, "EVM_PUBLIC_KEY") ||
(getSecret(character, "WALLET_PUBLIC_KEY") &&
getSecret(character, "WALLET_PUBLIC_KEY")?.startsWith("0x"))
(getSecret(character, "WALLET_PUBLIC_KEY") &&
getSecret(character, "WALLET_PUBLIC_KEY")?.startsWith("0x"))
? evmPlugin
: null,
(getSecret(character, "EVM_PUBLIC_KEY") ||
Expand All @@ -938,16 +939,16 @@ export async function createAgent(
? injectivePlugin
: null,
getSecret(character, "COSMOS_RECOVERY_PHRASE") &&
getSecret(character, "COSMOS_AVAILABLE_CHAINS") &&
createCosmosPlugin(),
getSecret(character, "COSMOS_AVAILABLE_CHAINS") &&
createCosmosPlugin(),
(getSecret(character, "SOLANA_PUBLIC_KEY") ||
(getSecret(character, "WALLET_PUBLIC_KEY") &&
!getSecret(character, "WALLET_PUBLIC_KEY")?.startsWith(
"0x"
))) &&
getSecret(character, "SOLANA_ADMIN_PUBLIC_KEY") &&
getSecret(character, "SOLANA_PRIVATE_KEY") &&
getSecret(character, "SOLANA_ADMIN_PRIVATE_KEY")
getSecret(character, "SOLANA_ADMIN_PUBLIC_KEY") &&
getSecret(character, "SOLANA_PRIVATE_KEY") &&
getSecret(character, "SOLANA_ADMIN_PRIVATE_KEY")
? nftGenerationPlugin
: null,
getSecret(character, "ZEROG_PRIVATE_KEY") ? zgPlugin : null,
Expand All @@ -968,13 +969,13 @@ export async function createAgent(
: null,
getSecret(character, "FAL_API_KEY") ? ThreeDGenerationPlugin : null,
...(getSecret(character, "COINBASE_API_KEY") &&
getSecret(character, "COINBASE_PRIVATE_KEY")
getSecret(character, "COINBASE_PRIVATE_KEY")
? [
coinbaseMassPaymentsPlugin,
tradePlugin,
tokenContractPlugin,
advancedTradePlugin,
]
coinbaseMassPaymentsPlugin,
tradePlugin,
tokenContractPlugin,
advancedTradePlugin,
]
: []),
...(teeMode !== TEEMode.OFF && walletSecretSalt ? [teePlugin] : []),
teeMode !== TEEMode.OFF &&
Expand All @@ -984,18 +985,18 @@ export async function createAgent(
: null,
getSecret(character, "SGX") ? sgxPlugin : null,
getSecret(character, "ENABLE_TEE_LOG") &&
((teeMode !== TEEMode.OFF && walletSecretSalt) ||
getSecret(character, "SGX"))
((teeMode !== TEEMode.OFF && walletSecretSalt) ||
getSecret(character, "SGX"))
? teeLogPlugin
: null,
getSecret(character, "COINBASE_API_KEY") &&
getSecret(character, "COINBASE_PRIVATE_KEY") &&
getSecret(character, "COINBASE_NOTIFICATION_URI")
getSecret(character, "COINBASE_PRIVATE_KEY") &&
getSecret(character, "COINBASE_NOTIFICATION_URI")
? webhookPlugin
: null,
goatPlugin,
getSecret(character, "COINGECKO_API_KEY") ||
getSecret(character, "COINGECKO_PRO_API_KEY")
getSecret(character, "COINGECKO_PRO_API_KEY")
? coingeckoPlugin
: null,
getSecret(character, "EVM_PROVIDER_URL") ? goatPlugin : null,
Expand All @@ -1004,15 +1005,15 @@ export async function createAgent(
: null,
getSecret(character, "B2_PRIVATE_KEY") ? b2Plugin : null,
getSecret(character, "BINANCE_API_KEY") &&
getSecret(character, "BINANCE_SECRET_KEY")
getSecret(character, "BINANCE_SECRET_KEY")
? binancePlugin
: null,
getSecret(character, "FLOW_ADDRESS") &&
getSecret(character, "FLOW_PRIVATE_KEY")
getSecret(character, "FLOW_PRIVATE_KEY")
? flowPlugin
: null,
getSecret(character, "LENS_ADDRESS") &&
getSecret(character, "LENS_PRIVATE_KEY")
getSecret(character, "LENS_PRIVATE_KEY")
? lensPlugin
: null,
getSecret(character, "APTOS_PRIVATE_KEY") ? aptosPlugin : null,
Expand All @@ -1039,7 +1040,7 @@ export async function createAgent(
: null,
getSecret(character, "BIRDEYE_API_KEY") ? birdeyePlugin : null,
getSecret(character, "ECHOCHAMBERS_API_URL") &&
getSecret(character, "ECHOCHAMBERS_API_KEY")
getSecret(character, "ECHOCHAMBERS_API_KEY")
? echoChambersPlugin
: null,
getSecret(character, "LETZAI_API_KEY") ? letzAIPlugin : null,
Expand All @@ -1052,7 +1053,7 @@ export async function createAgent(
? genLayerPlugin
: null,
getSecret(character, "AVAIL_SEED") &&
getSecret(character, "AVAIL_APP_ID")
getSecret(character, "AVAIL_APP_ID")
? availPlugin
: null,
getSecret(character, "OPEN_WEATHER_API_KEY")
Expand All @@ -1070,7 +1071,7 @@ export async function createAgent(
? hyperliquidPlugin
: null,
getSecret(character, "AKASH_MNEMONIC") &&
getSecret(character, "AKASH_WALLET_ADDRESS")
getSecret(character, "AKASH_WALLET_ADDRESS")
? akashPlugin
: null,
getSecret(character, "QUAI_PRIVATE_KEY") ? quaiPlugin : null,
Expand Down
41 changes: 41 additions & 0 deletions packages/plugin-router-nitro/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# @elizaos/plugin-router-nitro

A plugin for interacting with the Router Nitro bridge within the ElizaOS ecosystem.

## Description

The Router Nitro plugin enables seamless cross-chain token transfers and wallet management across blockchains. It supports efficient bridging of tokens and monitoring wallet balances, facilitating real-time transaction processing and price tracking.

## Installation

```bash
pnpm install @elizaos/plugin-router-nitro
```

## Configuration

The plugin requires the following environment variables to be set:

```typescript
ROUTER_NITRO_EVM_PRIVATE_KEY=<Your EVM-compatible private key>
ROUTER_NITRO_EVM_ADDRESS=<Router Nitro EVM bridge address>
```

## Usage

### Basic Integration

```typescript
import {
nitroPlugin
} from "@elizaos/plugin-router-nitro";
```

### Transfer Examples

```typescript
// The plugin responds to natural language commands like:

"Bridge 50 USDC from Ethereum to Polygon on address 0xCCa8009f5e09F8C5dB63cb0031052F9CB635Af62";
"Send 1 ETH from Arb to Base"
```
3 changes: 3 additions & 0 deletions packages/plugin-router-nitro/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];
35 changes: 35 additions & 0 deletions packages/plugin-router-nitro/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "@elizaos/plugin-router-nitro",
"version": "0.1.8+build.1",
"type": "module",
"main": "dist/index.js",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
"import": {
"@elizaos/source": "./src/index.ts",
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
}
},
"files": [
"dist"
],
"dependencies": {
"@elizaos/core": "workspace:*",
"axios": "^1.7.9",
"ethers": "^6.13.5",
"tsup": "8.3.5",
"viem": "2.21.58"
},
"scripts": {
"build": "tsup --format esm --dts",
"dev": "tsup --format esm --dts --watch",
"test": "vitest run",
"test:watch": "vitest",
"lint": "eslint --fix --cache ."
}
}
45 changes: 45 additions & 0 deletions packages/plugin-router-nitro/src/actions/chains.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import * as viemChains from "viem/chains";

// Create chains object from all available viem chains
const chains = Object.values(viemChains).reduce((acc, chain) => {
if (chain && typeof chain === 'object' && 'id' in chain) {
acc[chain.id] = chain;
}
return acc;
}, {});
wtfsayo marked this conversation as resolved.
Show resolved Hide resolved

export const getRpcUrlFromChainId = (chainId) => {
const chain = chains[chainId];
if (!chain) {
throw new Error(`Chain ID ${chainId} not found`);
}

return chain.rpcUrls.default.http[0];
}

// Helper to get chain object
export const getChainFromChainId = (chainId) => {
const chain = chains[chainId];
if (!chain) {
throw new Error(`Chain ID ${chainId} not found`);
}

return chain;
}

export const getBlockExplorerFromChainId = (chainId) => {
const chain = chains[chainId];
if (!chain) {
throw new Error(`Chain ID ${chainId} not found`);
}

if (!chain.blockExplorers || !chain.blockExplorers.default) {
throw new Error(`Block explorer not found for Chain ID ${chainId}`);
}

return {
url: chain.blockExplorers.default.url,
};
};

export { chains };
Loading
Loading