-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @RaveenaBhasin! Welcome to the elizaOS community. Thanks for submitting your first pull request; your efforts are helping us accelerate towards AGI. We'll review it shortly. You are now an elizaOS contributor!
📝 WalkthroughWalkthroughThis pull request introduces the Changes
Possibly related issues
Possibly related PRs
Suggested labels
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 8
🧹 Nitpick comments (7)
packages/plugin-router-nitro/src/actions/utils.ts (2)
3-5
: Enhance type safety by defining interfaces instead of 'any'Consider defining TypeScript interfaces for the chain data structures to improve type safety and prevent potential runtime errors.
Also applies to: 43-44
75-117
: Avoid code duplication by extracting a common method for retrieving chain dataThe methods
getChainId
,getChainType
,isChainLive
, andgetGasToken
use similar logic to retrieve the chain object. Extract this logic into a private method to reduce duplication.Apply this diff to refactor the code:
+ private getChainByName(normalizedName: string): any | null { + return this.chainData.find( + c => c.name.toLowerCase() === normalizedName.toLowerCase() + ); + } getChainId(chainName: string): string | null { if (!chainName) return null; const normalizedName = this.normalizeChainName(chainName); - const chain = this.chainData.find( - c => c.name.toLowerCase() === normalizedName.toLowerCase() - ); + const chain = this.getChainByName(normalizedName); return chain ? chain.chainId : null; }Repeat similar changes for
getChainType
,isChainLive
, andgetGasToken
.packages/plugin-router-nitro/src/actions/executeSwap.ts (1)
196-202
: Correct the chain name in the exampleIn the second example, the agent mentions "Solana" instead of "Avalanche". Ensure the chain names are consistent.
Apply this diff:
- text: "Sure, I'll swap 1 ETH into USDC from Solana to Base on address 0xF43042865f4D3B32A19ECBD1C7d4d924613c41E8", + text: "Sure, I'll swap 1 ETH into USDC from Avalanche to Base on address 0xF43042865f4D3B32A19ECBD1C7d4d924613c41E8",packages/plugin-router-nitro/src/actions/swapTemplate.ts (1)
1-28
: Add validation hints and type constraints to the template.The template should include:
- Format requirements for token symbols
- Chain ID format expectations
- Amount format (decimal places, scientific notation)
Extract the following details for the cross-chain swap request: - - **From Token**: The symbol of the token to swap from. + - **From Token**: The token symbol (e.g., "ETH", "USDC"). Must be a valid token symbol. - - **Amount**: The amount to swap, in the "From Token." + - **Amount**: The amount to swap as a decimal number (e.g., "1.5", "0.01").packages/plugin-router-nitro/src/actions/chains.ts (1)
11-18
: Add caching for RPC URLs.Frequent RPC URL lookups could be optimized with a caching mechanism.
+ const rpcUrlCache = new Map<number, string>(); export const getRpcUrlFromChainId = (chainId) => { + const cached = rpcUrlCache.get(chainId); + if (cached) return cached; const chain = chains[chainId]; if (!chain) { throw new Error(`Chain ID ${chainId} not found`); } - return chain.rpcUrls.default.http[0]; + const url = chain.rpcUrls.default.http[0]; + rpcUrlCache.set(chainId, url); + return url; }agent/src/index.ts (2)
42-42
: Remove duplicate import.The
DirectClient
import is already present at line 14.-// import { DirectClient } from "@elizaos/client-direct";
734-735
: Use optional chaining for safer property access.Replace the nested condition with optional chaining to improve code safety.
- getSecret(character, "WALLET_PUBLIC_KEY") && - getSecret(character, "WALLET_PUBLIC_KEY")?.startsWith("0x") + getSecret(character, "WALLET_PUBLIC_KEY")?.startsWith("0x")🧰 Tools
🪛 Biome (1.9.4)
[error] 734-735: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yaml
is excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (13)
agent/package.json
(1 hunks)agent/src/index.ts
(10 hunks)packages/plugin-router-nitro/eslint.config.mjs
(1 hunks)packages/plugin-router-nitro/package.json
(1 hunks)packages/plugin-router-nitro/src/actions/chains.ts
(1 hunks)packages/plugin-router-nitro/src/actions/executeSwap.ts
(1 hunks)packages/plugin-router-nitro/src/actions/swapTemplate.ts
(1 hunks)packages/plugin-router-nitro/src/actions/txns.ts
(1 hunks)packages/plugin-router-nitro/src/actions/utils.ts
(1 hunks)packages/plugin-router-nitro/src/environment.ts
(1 hunks)packages/plugin-router-nitro/src/index.ts
(1 hunks)packages/plugin-router-nitro/tsconfig.json
(1 hunks)packages/plugin-router-nitro/tsup.config.ts
(1 hunks)
✅ Files skipped from review due to trivial changes (4)
- packages/plugin-router-nitro/eslint.config.mjs
- packages/plugin-router-nitro/tsconfig.json
- packages/plugin-router-nitro/package.json
- packages/plugin-router-nitro/tsup.config.ts
🧰 Additional context used
🪛 Biome (1.9.4)
agent/src/index.ts
[error] 185-185: Avoid the use of spread (...
) syntax on accumulators.
Spread syntax should be avoided on accumulators (like those in .reduce
) because it causes a time complexity of O(n^2)
.
Consider methods such as .splice or .push instead.
(lint/performance/noAccumulatingSpread)
[error] 734-735: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
🔇 Additional comments (4)
packages/plugin-router-nitro/src/index.ts (1)
1-13
: LGTM!The plugin setup is correct, and the implementation looks good.
agent/src/index.ts (2)
178-193
: LGTM! Well-structured environment variable handling.The code properly handles character-specific environment variables with a clear prefix structure.
🧰 Tools
🪛 Biome (1.9.4)
[error] 185-185: Avoid the use of spread (
...
) syntax on accumulators.Spread syntax should be avoided on accumulators (like those in
.reduce
) because it causes a time complexity ofO(n^2)
.
Consider methods such as .splice or .push instead.(lint/performance/noAccumulatingSpread)
717-717
: LGTM! Proper environment variable checks for nitroPlugin.The plugin initialization correctly checks for both required environment variables:
ROUTER_NITRO_EVM_PRIVATE_KEY
andROUTER_NITRO_EVM_ADDRESS
.agent/package.json (1)
95-95
: LGTM! Dependency added correctly.The router-nitro plugin dependency is properly added with workspace versioning.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would suggest to implement the feedback; in subsequent PR
Relates to
LINK TO ISSUE OR TICKET
#2561
Risks
No changes to core functionality or external APIs.
Background
What does this PR do?
Introducing new plugin for agent to cross chain swap/bridge tokens using Router Nitro Bridge.
![image](https://private-user-images.githubusercontent.com/73697080/405128519-9eb578a2-9f41-4e01-b0db-1e4e2d747728.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkzMTY1MjcsIm5iZiI6MTczOTMxNjIyNywicGF0aCI6Ii83MzY5NzA4MC80MDUxMjg1MTktOWViNTc4YTItOWY0MS00ZTAxLWIwZGItMWU0ZTJkNzQ3NzI4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjExVDIzMjM0N1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQ1ODg0ZjkyNjUzMTZkMDg2ZWMzOGFjZTk4NjMzZTk5NmIzZWQ2MDQ4Y2MyYTA0ZGUxYjY2ODI4M2M0ZjU4YjMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.TnGNKIetgWvKuzYuD-0cF6z1BN8982p8C8UV8QCPG84)
![image](https://private-user-images.githubusercontent.com/73697080/405128725-3cdef5d8-f6cf-45a9-a495-2c4c562200dd.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkzMTY1MjcsIm5iZiI6MTczOTMxNjIyNywicGF0aCI6Ii83MzY5NzA4MC80MDUxMjg3MjUtM2NkZWY1ZDgtZjZjZi00NWE5LWE0OTUtMmM0YzU2MjIwMGRkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjExVDIzMjM0N1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWY1YzA1YzM5YmZhMzIxNWU3YTY0YTI0MDc1YzYzM2NlNmQ2NTc3NjQ1NWFjNmIxYjlmYzA4M2Y3NTZiZThjY2ImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.-s8-vGjJJHNR7b6wg1ntx55_-F3Y9jlvOeweCiH2xJM)
Currently, only EVM chains are supported, but since the Router Nitro Bridge also facilitates swaps to and from various non-EVM chains, this plugin can be expanded to include those functionalities in the future.
The plugin supports both native and ERC20 cross-chain token swaps.
Transaction Link: https://arbiscan.io/tx/0x36a1f91c228b3a02ec26b877152ccd59c10139abce4b16466240bebfcc6613dd
What kind of change is this?
Features (non-breaking change which adds functionality)
Documentation changes needed?
Testing
Where should a reviewer start?
Spin up a agent and configure router-nitro-plugin. Go to the router-nitro-plugin directory for detailed understanding.
Detailed testing steps
Summary by CodeRabbit
New Features
Improvements
Technical Updates
@elizaos/plugin-router-nitro