-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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: Pr/2275 plugin: bridge, swap and transfer on Tron blockchain #2292
Conversation
lgtm as long as it builds; waiting for develop to be fixed |
* refactor: rename tron-plugin to plugin-tron in package.json * feat: add tron plugin to package.json and update index.ts for plugin integration * test: add unit tests for WalletProvider functionality * feat: update bridge and swap actions example to include specific token addresses * refactor: update documentation to replace 'token symbol' with 'token address' in templates * refactor: update README to rename plugin and enhance action examples with specific token details
can you have a look @odilitime |
hi @wtfsayo, is there anything else I need to do on this PR to get it merged? |
Update .env.example
Warning There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure. 🔧 eslint
agent/src/index.tsOops! Something went wrong! :( ESLint: 9.18.0 ESLint couldn't find an eslint.config.(js|mjs|cjs) file. From ESLint v9.0.0, the default configuration file is now eslint.config.js. https://eslint.org/docs/latest/use/configure/migration-guide If you still have problems after following the migration guide, please stop by 📝 WalkthroughWalkthroughThis pull request introduces a comprehensive Tron blockchain plugin for the Eliza OS ecosystem. The changes span multiple files, adding support for token transfers, swaps, and cross-chain bridging. A new plugin is created with detailed configuration, actions, and provider implementations, enabling seamless interaction with the Tron blockchain through environment variables and a structured plugin architecture. Changes
Possibly related PRs
✨ 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 (
|
Warning There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure. 🔧 eslint
agent/src/index.tsOops! Something went wrong! :( ESLint: 9.18.0 ESLint couldn't find an eslint.config.(js|mjs|cjs) file. From ESLint v9.0.0, the default configuration file is now eslint.config.js. https://eslint.org/docs/latest/use/configure/migration-guide If you still have problems after following the migration guide, please stop by 📝 WalkthroughWalkthroughThe pull request introduces a comprehensive TRON blockchain plugin for the Eliza OS ecosystem. It adds support for token transfers, cross-chain bridging, and token swapping on the TRON network. The plugin includes a wallet provider, action handlers, and necessary configurations to interact with TRON-based services like SunSwap and Symbiosis. New environment variables, ABIs, and type definitions are established to facilitate seamless blockchain interactions. Changes
✨ 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: 12
🧹 Nitpick comments (16)
packages/plugin-tron/src/actions/bridge.ts (1)
40-43
: Unnecessary string conversion of decimalsIn lines 40-43,
fromTokenInfo.decimals
is converted to a string, butparseUnits
expects decimals as a number. The extra.toString()
calls are unnecessary.Apply this diff to simplify:
- fromTokenInfo.decimals = fromTokenInfo.decimals.toString(); - const fromAmount = parseUnits( - params.amount, - fromTokenInfo.decimals.toString() - ); + const fromAmount = parseUnits( + params.amount, + fromTokenInfo.decimals + );This removes redundant conversions and keeps
decimals
as a number.🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
packages/plugin-tron/src/providers/wallet.ts (2)
31-31
: Consider making 'tronWeb' property private.To enforce encapsulation, declare
tronWeb
as a private property.🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
146-148
: Improve error message with specific chain name.Include the invalid chain name in the error message for better debugging.
Apply this diff:
if (!chain?.id) { - throw new Error("Invalid chain name"); + throw new Error(`Invalid chain name: ${chainName}`); }🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
packages/plugin-tron/src/environment.ts (1)
20-28
: Enhance error message for validation failures.The error message could be more helpful by including the actual values that failed validation.
throw new Error( - `TRON configuration validation failed:\n${errorMessages}` + `TRON configuration validation failed:\n${errorMessages}\nReceived: ${JSON.stringify(config, null, 2)}` );🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
packages/plugin-tron/src/interfaces/symbiosis.ts (1)
20-37
: Add JSDoc comments for complex interfaces.The
SymbiosisSwapResponse
interface contains many properties that would benefit from documentation explaining their purpose.+/** + * Response from a Symbiosis swap operation + * @property fee - The fee charged for the swap + * @property route - The route taken for the swap + * @property inTradeType - The type of trade for the input token + * @property outTradeType - The type of trade for the output token + * ... + */ export interface SymbiosisSwapResponse {🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
packages/plugin-tron/src/test/wallet.test.ts (1)
36-36
: Move token address to a constants file.The USDT token address should be moved to a dedicated constants file to maintain consistency and reusability.
+// In src/constants.ts +export const TRON_TOKENS = { + USDT: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t" +} as const; // In this file - const tokenAddress = "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"; // USDT + const tokenAddress = TRON_TOKENS.USDT;🧰 Tools
🪛 Gitleaks (8.21.2)
36-36: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
packages/plugin-tron/src/types/index.ts (1)
88-116
: Simplify RPC URL configuration using Record type.The current approach lists each chain explicitly. Using a Record type would be more maintainable.
- rpcUrl?: { - ethereum?: string; - abstract?: string; - // ... many more chains - }; + rpcUrl?: Partial<Record<SupportedChain, string>>;🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
packages/plugin-tron/src/abis/wtrx.ts (1)
14-16
: Consider standardizing parameter names.The parameter name 'sad' is non-standard and could cause confusion. Consider using 'amount' or 'value' to align with common practices.
- { "name": "sad", "type": "uint256" } + { "name": "amount", "type": "uint256" }Also applies to: 35-38, 84-86
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
packages/plugin-tron/src/templates/index.ts (2)
33-34
: Enhance error handling in templates.Consider adding specific error messages for common validation failures (e.g., insufficient balance, invalid decimals).
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
87-99
: Add validation for minimum bridge amounts.Consider adding minimum amount validation to prevent dust transfers that might not be economically viable due to bridge fees.
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
packages/plugin-tron/src/abis/sunswap_v2_pair.ts (1)
1-658
: Add documentation for the contract interface.Consider adding JSDoc comments to describe the contract interface, its purpose, and usage examples.
+/** + * @title SunSwap V2 Pair Contract Interface + * @dev Interface for SunSwap V2 pair contracts, implementing AMM functionality + * @notice This interface is compatible with Uniswap V2 pair specification + */ export default [🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
packages/plugin-tron/src/abis/sunswap_v2_router.ts (1)
1-973
: Add documentation for the router interface.Consider adding JSDoc comments to describe the router interface, supported operations, and usage examples.
+/** + * @title SunSwap V2 Router Contract Interface + * @dev Interface for SunSwap V2 router contracts, handling swaps and liquidity + * @notice This interface is compatible with Uniswap V2 router specification + */ export default [🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
packages/plugin-tron/package.json (1)
2-4
: Consider starting with version 0.0.1.Since this is a new plugin, consider starting with version 0.0.1 to indicate its pre-release status.
"name": "@elizaos/plugin-tron", -"version": "0.1.0", +"version": "0.0.1",🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
packages/plugin-tron/README.md (2)
1-152
: Enhance documentation with additional sections.Consider adding the following sections to make the documentation more comprehensive:
- Version compatibility matrix
- Troubleshooting guide
- API response examples
- Error handling examples
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
63-77
: Add error handling example in the transfer code snippet.The transfer example should demonstrate proper error handling:
const message: Memory = { content: { text: "Send 100 TRX to TH9husb1dF7q8KSe7PVdmZYKqfnuYw5KWL", action: transferAction.name, }, agentId: runtime.agentId, userId: stringToUuid("test"), roomId: stringToUuid("test"), }; -const state = await runtime.composeState(message); -const result = await runtime.processActions(message, [message], state); +try { + const state = await runtime.composeState(message); + const result = await runtime.processActions(message, [message], state); +} catch (error) { + console.error('Transfer failed:', error); + // Handle specific error cases +}🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
.env.example (1)
710-712
: Add documentation and default values for TRON environment variables.Enhance the environment variables with documentation and defaults:
# Tron blockchain -TRON_PRIVATE_KEY= -TRON_PROVIDER_URL= +# Required: Private key for the TRON wallet (64 characters hexadecimal) +TRON_PRIVATE_KEY= +# Optional: Custom RPC URL for TRON network (defaults to https://api.trongrid.io) +TRON_PROVIDER_URL=
📜 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 (26)
.env.example
(1 hunks)agent/package.json
(1 hunks)agent/src/index.ts
(2 hunks)packages/plugin-tron/.gitignore
(1 hunks)packages/plugin-tron/README.md
(1 hunks)packages/plugin-tron/eslint.config.mjs
(1 hunks)packages/plugin-tron/package.json
(1 hunks)packages/plugin-tron/prettier.config.cjs
(1 hunks)packages/plugin-tron/src/abis/sunswap_v2_factory.ts
(1 hunks)packages/plugin-tron/src/abis/sunswap_v2_pair.ts
(1 hunks)packages/plugin-tron/src/abis/sunswap_v2_router.ts
(1 hunks)packages/plugin-tron/src/abis/trc10.ts
(1 hunks)packages/plugin-tron/src/abis/wtrx.ts
(1 hunks)packages/plugin-tron/src/actions/bridge.ts
(1 hunks)packages/plugin-tron/src/actions/swap.ts
(1 hunks)packages/plugin-tron/src/actions/transfer.ts
(1 hunks)packages/plugin-tron/src/constants.ts
(1 hunks)packages/plugin-tron/src/environment.ts
(1 hunks)packages/plugin-tron/src/index.ts
(1 hunks)packages/plugin-tron/src/interfaces/symbiosis.ts
(1 hunks)packages/plugin-tron/src/providers/wallet.ts
(1 hunks)packages/plugin-tron/src/templates/index.ts
(1 hunks)packages/plugin-tron/src/test/wallet.test.ts
(1 hunks)packages/plugin-tron/src/types/index.ts
(1 hunks)packages/plugin-tron/tsconfig.json
(1 hunks)packages/plugin-tron/tsup.config.ts
(1 hunks)
✅ Files skipped from review due to trivial changes (5)
- packages/plugin-tron/eslint.config.mjs
- packages/plugin-tron/prettier.config.cjs
- packages/plugin-tron/.gitignore
- packages/plugin-tron/tsconfig.json
- packages/plugin-tron/src/constants.ts
🧰 Additional context used
🪛 GitHub Actions: smoke-test
packages/plugin-tron/tsup.config.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
packages/plugin-tron/src/environment.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
packages/plugin-tron/src/test/wallet.test.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
packages/plugin-tron/package.json
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
packages/plugin-tron/src/abis/sunswap_v2_router.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
packages/plugin-tron/src/abis/wtrx.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
packages/plugin-tron/src/index.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
packages/plugin-tron/src/abis/trc10.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
packages/plugin-tron/src/abis/sunswap_v2_pair.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
packages/plugin-tron/src/templates/index.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
packages/plugin-tron/README.md
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
packages/plugin-tron/src/actions/transfer.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
packages/plugin-tron/src/abis/sunswap_v2_factory.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
packages/plugin-tron/src/interfaces/symbiosis.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
packages/plugin-tron/src/actions/bridge.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
packages/plugin-tron/src/types/index.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
packages/plugin-tron/src/providers/wallet.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
packages/plugin-tron/src/actions/swap.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
🪛 GitHub Actions: Integration Tests
agent/src/index.ts
[error] Wallet address not provided
[error] Failed to fetch DBPDA
[error] Cannot found onchain data in this wallet
🪛 Gitleaks (8.21.2)
packages/plugin-tron/src/test/wallet.test.ts
36-36: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
packages/plugin-tron/src/templates/index.ts
144-144: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
150-150: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
🔇 Additional comments (10)
packages/plugin-tron/src/providers/wallet.ts (2)
1-241
: Resolve missing peer dependency warning.The pipeline reports a missing peer dependency:
fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
. Verify and install this dependency as needed.🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
92-92
: 🛠️ Refactor suggestionAvoid precision loss when converting
BigNumber
tonumber
.Using
BigNumber.toNumber()
can lead to precision loss for large values. Consider usingamount.toString()
directly or handlingBigNumber
appropriately.Apply this diff:
callValue: BigNumber(amount.toString()).toNumber(), +callValue: amount.toString(),
Likely invalid or redundant comment.
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
packages/plugin-tron/src/index.ts (1)
1-21
: Ensure all dependencies are declared correctly.Verify that all required dependencies for the plugin are included in
package.json
.🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
packages/plugin-tron/src/test/wallet.test.ts (1)
66-71
: Add negative test cases.The test suite only covers happy paths. Add tests for error scenarios:
- Invalid token addresses
- Network failures
- Insufficient balances
Would you like me to generate the additional test cases?
Also applies to: 73-81, 83-94
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
packages/plugin-tron/src/abis/sunswap_v2_factory.ts (1)
1-189
: LGTM! Factory contract ABI matches SunSwap V2 specification.The contract interface correctly implements pair creation, fee management, and event emission with proper parameter indexing.
Run this script to verify the contract address usage:
✅ Verification successful
Factory contract integration verified - implementation is correct
The swap implementation properly uses the factory contract to find trading pairs, following standard DEX patterns.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify the factory contract address usage rg -l "createPair|getPair|allPairs"Length of output: 130
Script:
#!/bin/bash # Check how factory methods are used in swap.ts rg -A 5 -B 5 "createPair|getPair|allPairs" packages/plugin-tron/src/actions/swap.tsLength of output: 824
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
packages/plugin-tron/src/abis/trc10.ts (1)
1-410
: LGTM! Standard TRC10 implementation with proper mode controls.The contract interface correctly implements the TRC10 standard with additional transfer mode controls.
Please address the missing peer dependency:
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
packages/plugin-tron/src/abis/sunswap_v2_pair.ts (1)
1-658
: Verify contract compatibility with SunSwap V2.Ensure this ABI matches the deployed SunSwap V2 pair contracts on TRON mainnet.
✅ Verification successful
ABI matches SunSwap V2 specification
The contract interfaces are consistent with SunSwap V2's production deployment, verified against the official factory address
TKWJdrQkqHisa1X8HUdHEfREvTzw4pMAaY
.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify if the ABI matches deployed contracts # Get the contract bytecode from a known SunSwap V2 pair curl -X POST https://api.trongrid.io/wallet/getcontract -d '{ "value": "YOUR_KNOWN_SUNSWAP_V2_PAIR_ADDRESS", "visible": true }'Length of output: 530
Script:
#!/bin/bash # Search for files containing SunSwap references echo "=== Files containing SunSwap references ===" rg -i "sunswap" --type ts -l echo -e "\n=== Files in plugin-tron directory ===" fd . packages/plugin-tron/src -t f -e ts -e json echo -e "\n=== Content of test files ===" rg -i "sunswap.*address" --type ts -A 3 -B 3Length of output: 1163
Script:
#!/bin/bash # Check constants and factory implementation echo "=== Constants file content ===" cat packages/plugin-tron/src/constants.ts echo -e "\n=== Factory ABI and implementation ===" cat packages/plugin-tron/src/abis/sunswap_v2_factory.tsLength of output: 4088
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
packages/plugin-tron/src/abis/sunswap_v2_router.ts (1)
1-973
: Verify router compatibility with SunSwap V2.Ensure this ABI matches the deployed SunSwap V2 router contracts on TRON mainnet.
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
agent/src/index.ts (1)
60-60
: LGTM! TRON plugin integration follows established patterns.The plugin is properly imported and conditionally initialized based on the presence of
TRON_PRIVATE_KEY
, consistent with other blockchain plugin integrations.Also applies to: 1096-1096
🧰 Tools
🪛 GitHub Actions: Integration Tests
[error] Wallet address not provided
[error] Failed to fetch DBPDA
[error] Cannot found onchain data in this wallet
agent/package.json (1)
73-73
: LGTM!The TRON plugin dependency is correctly added as a workspace dependency.
TRON_PRIVATE_KEY: z.string().min(1, "TRON_PRIVATE_KEY is required"), | ||
}); | ||
|
||
export type DiscordConfig = z.infer<typeof discordEnvSchema>; |
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.
🛠️ Refactor suggestion
Update type name for consistency.
Update the type name to match the schema rename.
-export type DiscordConfig = z.infer<typeof discordEnvSchema>;
+export type TronConfig = z.infer<typeof tronEnvSchema>;
Committable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
export interface SwapParams { | ||
fromToken: string; | ||
toToken: string; | ||
amount: string; | ||
slippage?: number; | ||
} |
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.
🛠️ Refactor suggestion
Add validation for slippage parameter.
The slippage parameter should be constrained to reasonable values (e.g., 0-100%).
export interface SwapParams {
fromToken: string;
toToken: string;
amount: string;
- slippage?: number;
+ slippage?: number & { __type: 'Percentage' }; // Using branded type for validation
}
Consider adding a utility function:
function validateSlippage(value: number): number & { __type: 'Percentage' } {
if (value < 0 || value > 100) {
throw new Error('Slippage must be between 0 and 100');
}
return value as number & { __type: 'Percentage' };
}
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
"peerDependencies": { | ||
"whatwg-url": "7.1.0" | ||
}, |
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.
Add missing peer dependency.
Add fastestsmallesttextencoderdecoder
to peer dependencies to resolve the pipeline failure.
"peerDependencies": {
+ "fastestsmallesttextencoderdecoder": ">= 1.0.22 < 2.0.0-0",
"whatwg-url": "7.1.0"
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
"peerDependencies": { | |
"whatwg-url": "7.1.0" | |
}, | |
"peerDependencies": { | |
"fastestsmallesttextencoderdecoder": ">= 1.0.22 < 2.0.0-0", | |
"whatwg-url": "7.1.0" | |
}, |
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>= 1.0.22 < 2.0.0-0
Warning There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure. 🔧 eslint
agent/src/index.tsOops! Something went wrong! :( ESLint: 9.18.0 ESLint couldn't find an eslint.config.(js|mjs|cjs) file. From ESLint v9.0.0, the default configuration file is now eslint.config.js. https://eslint.org/docs/latest/use/configure/migration-guide If you still have problems after following the migration guide, please stop by 📝 WalkthroughWalkthroughThis pull request introduces a comprehensive TRON blockchain plugin for the Eliza OS ecosystem. The changes include adding configuration variables, creating a new plugin package with actions for token transfers, swaps, and cross-chain bridging, and implementing a wallet provider for TRON blockchain interactions. The plugin enables seamless integration of TRON blockchain functionalities into the existing agent framework. Changes
Possibly related PRs
✨ 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: 18
🧹 Nitpick comments (14)
packages/plugin-tron/src/providers/wallet.ts (2)
188-192
: Clarify TEE Mode SupportThe error message states that
TEE_MODE
is not supported for TRON. Provide additional context or consider implementing support if feasible.🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
231-240
: Improve Error Handling in Wallet ProviderReturning
null
on error may obscure issues. Enhance error handling by providing more informative messages or throwing exceptions where appropriate.🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/abis/sunswap_v2_router.ts (1)
1-973
: Externalize ABI to Improve MaintainabilityEmbedding the ABI directly in the code can reduce readability. Store the ABI in a separate JSON file and import it to enhance maintainability.
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/tsup.config.ts (1)
9-22
: Review External DependenciesDouble-check the list of external dependencies to ensure all required modules are included and unnecessary ones are excluded.
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/interfaces/symbiosis.ts (1)
86-92
: Extend SymbiosisToken interface.
Token
interface duplicates properties fromSymbiosisToken
. Consider extending it.-export interface Token { - symbol: string; - address: string; - chainId: number; - decimals: number; - icon?: string; -} +export interface Token extends SymbiosisToken { + icon?: string; +}🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/test/wallet.test.ts (2)
36-36
: Move hardcoded token address to constants.The USDT token address should be moved to a constants file for better maintainability.
🧰 Tools
🪛 Gitleaks (8.21.2)
36-36: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
73-81
: Add validation for token details.The token test only checks for property existence. Add validation for property values.
it("should validate token details", async () => { const tokenDetails = await walletProvider.fetchOnchainToken(tokenAddress); expect(typeof tokenDetails.name).toBe('string'); expect(typeof tokenDetails.symbol).toBe('string'); expect(typeof tokenDetails.decimals).toBe('number'); });🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/types/index.ts (2)
86-125
: Add validation for multicall parameters.Consider adding validation for
batchSize
andwait
to prevent performance issues.export interface TronPluginConfig { // ... other fields ... multicall?: { - batchSize?: number; - wait?: number; + batchSize?: number & { min: 1; max: 500 }; + wait?: number & { min: 0; max: 5000 }; }; }🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
141-163
: Enhance ProviderError interface.Consider adding more specific error codes and data types for better error handling.
export interface ProviderError extends Error { - code?: number; - data?: unknown; + code?: number & { min: 400; max: 599 }; + data?: { + reason?: string; + details?: Record<string, unknown>; + }; }🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/abis/wtrx.ts (1)
1-162
: Improve parameter naming in WTRX ABI.Consider using more descriptive parameter names:
guy
→spender
sad
→amount
src
→from
dst
→to
- { "name": "guy", "type": "address" }, - { "name": "sad", "type": "uint256" } + { "name": "spender", "type": "address" }, + { "name": "amount", "type": "uint256" }🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/templates/index.ts (1)
54-57
: Avoid hardcoding token addresses in examples.Consider using placeholder addresses or documenting that these are example addresses:
-"Transfer 100 USDT (TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t) to TXXXXXXXXX" +"Transfer 100 USDT (TXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX) to TXXXXXXXXX"Also applies to: 142-152
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
.env.example (1)
710-712
: Add documentation for configuration values.Consider adding:
- Expected format for the private key
- Default or example provider URL for development
- Any network-specific requirements or limitations
# Tron blockchain -TRON_PRIVATE_KEY= -TRON_PROVIDER_URL= +# Private key for the TRON wallet (hex format without '0x' prefix) +TRON_PRIVATE_KEY= +# TRON network provider URL (e.g., https://api.trongrid.io for mainnet) +TRON_PROVIDER_URL=packages/plugin-tron/src/abis/trc10.ts (1)
93-130
: Consider documenting transfer modes.The contract implements three transfer modes (NORMAL, CONTROLLED, RESTRICTED) but their specific behaviors and use cases are not documented.
Consider adding code comments explaining each mode's purpose and restrictions.
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/README.md (1)
63-77
: Document error handling and recovery procedures.The code examples should include error handling patterns and explain how to handle common failures (network issues, insufficient funds, etc.).
Add error handling examples and a troubleshooting section to the documentation.
Also applies to: 84-96, 103-116
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
📜 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 (26)
.env.example
(1 hunks)agent/package.json
(1 hunks)agent/src/index.ts
(2 hunks)packages/plugin-tron/.gitignore
(1 hunks)packages/plugin-tron/README.md
(1 hunks)packages/plugin-tron/eslint.config.mjs
(1 hunks)packages/plugin-tron/package.json
(1 hunks)packages/plugin-tron/prettier.config.cjs
(1 hunks)packages/plugin-tron/src/abis/sunswap_v2_factory.ts
(1 hunks)packages/plugin-tron/src/abis/sunswap_v2_pair.ts
(1 hunks)packages/plugin-tron/src/abis/sunswap_v2_router.ts
(1 hunks)packages/plugin-tron/src/abis/trc10.ts
(1 hunks)packages/plugin-tron/src/abis/wtrx.ts
(1 hunks)packages/plugin-tron/src/actions/bridge.ts
(1 hunks)packages/plugin-tron/src/actions/swap.ts
(1 hunks)packages/plugin-tron/src/actions/transfer.ts
(1 hunks)packages/plugin-tron/src/constants.ts
(1 hunks)packages/plugin-tron/src/environment.ts
(1 hunks)packages/plugin-tron/src/index.ts
(1 hunks)packages/plugin-tron/src/interfaces/symbiosis.ts
(1 hunks)packages/plugin-tron/src/providers/wallet.ts
(1 hunks)packages/plugin-tron/src/templates/index.ts
(1 hunks)packages/plugin-tron/src/test/wallet.test.ts
(1 hunks)packages/plugin-tron/src/types/index.ts
(1 hunks)packages/plugin-tron/tsconfig.json
(1 hunks)packages/plugin-tron/tsup.config.ts
(1 hunks)
✅ Files skipped from review due to trivial changes (6)
- packages/plugin-tron/eslint.config.mjs
- packages/plugin-tron/prettier.config.cjs
- packages/plugin-tron/tsconfig.json
- packages/plugin-tron/.gitignore
- packages/plugin-tron/package.json
- packages/plugin-tron/src/constants.ts
🧰 Additional context used
🪛 GitHub Actions: smoke-test
packages/plugin-tron/src/abis/wtrx.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/test/wallet.test.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/abis/sunswap_v2_pair.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/abis/trc10.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/tsup.config.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/README.md
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/abis/sunswap_v2_router.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/actions/bridge.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/environment.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/templates/index.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/abis/sunswap_v2_factory.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/index.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/actions/transfer.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/actions/swap.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/interfaces/symbiosis.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/types/index.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/providers/wallet.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
🪛 GitHub Actions: Integration Tests
agent/src/index.ts
[error] Wallet address not provided
[error] Failed to fetch DBPDA
[error] Cannot found onchain data in this wallet
🪛 Gitleaks (8.21.2)
packages/plugin-tron/src/test/wallet.test.ts
36-36: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
packages/plugin-tron/src/templates/index.ts
144-144: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
150-150: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
🔇 Additional comments (8)
packages/plugin-tron/src/providers/wallet.ts (1)
97-103
: Ensure Consistent BigNumber UsageIn the
approve
method, verify that numeric values are handled asBigNumber
to prevent precision issues.🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/types/index.ts (2)
1-62
: Well-structured type definitions!The type definitions are comprehensive and follow TypeScript best practices.
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
127-139
: LGTM! Comprehensive LiFi types.The LiFi types properly handle all necessary states and include error handling.
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/abis/sunswap_v2_factory.ts (1)
1-189
: LGTM! Well-structured SunSwap V2 factory ABI.The ABI includes all necessary functions and events for factory contract interaction.
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
agent/src/index.ts (1)
60-60
: LGTM! Verify integration with other blockchain plugins.The TRON plugin integration follows the established pattern for blockchain plugins. The plugin is correctly gated behind the TRON_PRIVATE_KEY environment variable.
Run this script to verify no conflicts with other blockchain plugins:
Also applies to: 1096-1096
✅ Verification successful
TRON plugin integration verified - follows established patterns ✅
The plugin is properly integrated with consistent environment variable handling and follows the same architecture as other blockchain plugins. No conflicts found.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Check for potential conflicts in blockchain plugin configurations rg -A 5 "TRON_PRIVATE_KEY|TRON_PROVIDER_URL" .env* rg "tronPlugin" "src/**/*.ts"Length of output: 178
Script:
#!/bin/bash # Find TypeScript files and analyze plugin patterns fd -e ts | xargs rg -A 5 "tronPlugin|Plugin.*from.*@elizaos" # Check plugin registration patterns fd -e ts | xargs rg -A 10 "registerPlugin.*Plugin" # Look for environment variable handling patterns fd -e ts | xargs rg -B 2 -A 2 "TRON_PRIVATE_KEY"Length of output: 48265
🧰 Tools
🪛 GitHub Actions: Integration Tests
[error] Wallet address not provided
[error] Failed to fetch DBPDA
[error] Cannot found onchain data in this wallet
agent/package.json (1)
73-73
: LGTM! Dependency added correctly.The TRON plugin dependency follows the workspace pattern and maintains alphabetical ordering.
packages/plugin-tron/src/abis/trc10.ts (1)
1-410
:⚠️ Potential issueAdd missing peer dependency.
The pipeline indicates a missing peer dependency. Add the following to your package.json:
+"fastestsmallesttextencoderdecoder": "^1.0.22"
Likely invalid or redundant comment.
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/abis/sunswap_v2_pair.ts (1)
611-637
: Verify swap function's flash loan protection.The
swap
function accepts arbitrary calldata which could be used for flash loan attacks. Ensure proper slippage checks and reentrancy guards are implemented in the contract.🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
callback({ | ||
text: `Successfully transferred ${paramOptions.amount} TRX to ${paramOptions.toAddress}\nTransaction Hash: ${transferResp.hash}`, | ||
content: { | ||
success: true, | ||
hash: transferResp.hash, | ||
amount: paramOptions.amount, | ||
recipient: transferResp.to, | ||
chain: "tron", | ||
}, | ||
}); | ||
} | ||
return true; |
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.
🛠️ Refactor suggestion
Adjust the success message to reflect the correct token
Currently, the success message always indicates the transfer of TRX, even when transferring TRC20 tokens. Update the message to display the appropriate token.
Apply this diff to fix the message:
- text: `Successfully transferred ${paramOptions.amount} TRX to ${paramOptions.toAddress}\nTransaction Hash: ${transferResp.hash}`,
+ const tokenName = paramOptions.token ? 'TRC20 token' : 'TRX';
+ text: `Successfully transferred ${paramOptions.amount} ${tokenName} to ${paramOptions.toAddress}\nTransaction Hash: ${transferResp.hash}`,
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
callback({ | |
text: `Successfully transferred ${paramOptions.amount} TRX to ${paramOptions.toAddress}\nTransaction Hash: ${transferResp.hash}`, | |
content: { | |
success: true, | |
hash: transferResp.hash, | |
amount: paramOptions.amount, | |
recipient: transferResp.to, | |
chain: "tron", | |
}, | |
}); | |
} | |
return true; | |
callback({ | |
text: `Successfully transferred ${paramOptions.amount} ${paramOptions.token ? 'TRC20 token' : 'TRX'} to ${paramOptions.toAddress}\nTransaction Hash: ${transferResp.hash}`, | |
content: { | |
success: true, | |
hash: transferResp.hash, | |
amount: paramOptions.amount, | |
recipient: transferResp.to, | |
chain: "tron", | |
}, | |
}); | |
} | |
return true; |
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
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.
@justinmoonai can you check this?
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.
Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!
const amount = BigNumber( | ||
tronWeb.toSun(+params.amount) | ||
).toNumber(); |
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.
Ensure correct token amount conversion
tronWeb.toSun
converts amounts assuming 6 decimals (for TRX). For TRC20 tokens, use the token's actual decimals to calculate the amount accurately.
Apply this diff to fix the issue:
+ const decimals = await tokenContract.methods.decimals().call();
+ const amount = BigNumber(
+ +params.amount * Math.pow(10, decimals)
+ ).toNumber();
- const amount = BigNumber(
- tronWeb.toSun(+params.amount)
- ).toNumber();
Committable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
const fromTokenInfo = await this.walletProvider.fetchOnchainToken( | ||
params.fromToken | ||
); |
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.
Assign default params.fromToken
before using it
params.fromToken
is used to fetch token info before it is checked for undefined and assigned a default value. This can cause errors if params.fromToken
is undefined. Move the default assignment before its first use.
Apply this diff to fix the issue:
+ if (!params.fromToken) {
+ params.fromToken = WRAPPED_TRX_ADDRESS;
+ }
const fromTokenInfo = await this.walletProvider.fetchOnchainToken(
params.fromToken
);
- if (!params.fromToken) {
- params.fromToken = WRAPPED_TRX_ADDRESS;
- }
Also applies to: 77-79
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
if (error instanceof AxiosError) { | ||
if (error.response) { | ||
console.error("error.response", error.response.data); | ||
|
||
throw new Error(error.response.data); |
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.
🛠️ Refactor suggestion
Improve error handling in getSwapTransaction
error.response.data
might be an object, resulting in [object Object]
in the error message. To provide meaningful error messages, extract or stringify error.response.data
appropriately.
Apply this diff to enhance error handling:
- throw new Error(error.response.data);
+ const errorMsg = typeof error.response.data === 'string' ? error.response.data : JSON.stringify(error.response.data);
+ throw new Error(errorMsg);
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
if (error instanceof AxiosError) { | |
if (error.response) { | |
console.error("error.response", error.response.data); | |
throw new Error(error.response.data); | |
if (error instanceof AxiosError) { | |
if (error.response) { | |
console.error("error.response", error.response.data); | |
const errorMsg = typeof error.response.data === 'string' ? error.response.data : JSON.stringify(error.response.data); | |
throw new Error(errorMsg); |
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
export interface TokenAmountOut { | ||
symbol: string; | ||
icon: string; | ||
address: string; | ||
amount: string; | ||
chainId: number; | ||
decimals: number; | ||
} | ||
|
||
export interface TokenAmountOutMin { | ||
symbol: string; | ||
icon: string; | ||
address: string; | ||
amount: string; | ||
chainId: number; | ||
decimals: number; | ||
} | ||
|
||
export interface AmountInUsd { | ||
symbol: string; | ||
icon: string; | ||
address: string; | ||
amount: string; | ||
chainId: number; | ||
decimals: number; | ||
} |
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.
🛠️ Refactor suggestion
Reduce code duplication in token-related interfaces.
TokenAmountOut
, TokenAmountOutMin
, and AmountInUsd
share identical properties. Consider creating a base interface.
+interface BaseTokenAmount {
+ symbol: string;
+ icon: string;
+ address: string;
+ amount: string;
+ chainId: number;
+ decimals: number;
+}
+
-export interface TokenAmountOut {
- symbol: string;
- icon: string;
- address: string;
- amount: string;
- chainId: number;
- decimals: number;
-}
+export interface TokenAmountOut extends BaseTokenAmount {}
-export interface TokenAmountOutMin {
- symbol: string;
- icon: string;
- address: string;
- amount: string;
- chainId: number;
- decimals: number;
-}
+export interface TokenAmountOutMin extends BaseTokenAmount {}
-export interface AmountInUsd {
- symbol: string;
- icon: string;
- address: string;
- amount: string;
- chainId: number;
- decimals: number;
-}
+export interface AmountInUsd extends BaseTokenAmount {}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
export interface TokenAmountOut { | |
symbol: string; | |
icon: string; | |
address: string; | |
amount: string; | |
chainId: number; | |
decimals: number; | |
} | |
export interface TokenAmountOutMin { | |
symbol: string; | |
icon: string; | |
address: string; | |
amount: string; | |
chainId: number; | |
decimals: number; | |
} | |
export interface AmountInUsd { | |
symbol: string; | |
icon: string; | |
address: string; | |
amount: string; | |
chainId: number; | |
decimals: number; | |
} | |
interface BaseTokenAmount { | |
symbol: string; | |
icon: string; | |
address: string; | |
amount: string; | |
chainId: number; | |
decimals: number; | |
} | |
export interface TokenAmountOut extends BaseTokenAmount {} | |
export interface TokenAmountOutMin extends BaseTokenAmount {} | |
export interface AmountInUsd extends BaseTokenAmount {} |
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
- If the user says "Transfer 100 TRX to TXXXXXXXXX", the JSON should reflect TRON chain details and set "token" to null. | ||
- If the user says "Transfer 100 USDT (TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t) to TXXXXXXXXX", the JSON should reflect TRON chain details and set "token" to "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t". | ||
Now, process the user's request and provide your response.`; | ||
|
||
export const bridgeTemplate = `Given the recent messages and wallet information below: | ||
|
||
<recent_messages> | ||
{{recentMessages}} | ||
</recent_messages> | ||
|
||
<wallet_info> | ||
{{walletInfo}} | ||
</wallet_info> | ||
|
||
Extract the following information about the requested token bridge: | ||
- Token address to bridge | ||
- Destination chain | ||
- Amount to bridge: Must be a string representing the amount in the chain's native units (only number without coin symbol, e.g., "0.1") | ||
- Destination address (if specified) | ||
|
||
Respond with a JSON markdown block containing only the extracted values: | ||
|
||
\`\`\`json | ||
{ | ||
"token": string | null, | ||
"toChain": "ethereum" | "abstract" | "base" | "sepolia" | "bsc" | "arbitrum" | "avalanche" | "polygon" | "optimism" | "cronos" | "gnosis" | "fantom" | "klaytn" | "celo" | "moonbeam" | "aurora" | "harmonyOne" | "moonriver" | "arbitrumNova" | "mantle" | "linea" | "scroll" | "filecoin" | "taiko" | "zksync" | "canto" | "alienx" | "tron" | "ton" | null, | ||
"amount": string | null, | ||
"toAddress": string | null | ||
} | ||
\`\`\` | ||
|
||
### Validation Steps: | ||
1. **Token**: Identify the token address mentioned by the user. Set to null if no specific token is mentioned. | ||
2. **Destination Chains**: | ||
- Must exactly match one of the supported chains listed above. | ||
- If the chain is not explicitly stated, infer it based on wallet information or previous context in the conversation. | ||
3. **Amount**: | ||
- Ensure it is a valid numeric string without any symbols or extra characters. | ||
- If not provided, set to null. | ||
4. **Destination Address**: | ||
- Validate based on the destination chain: | ||
- **TRON**: Must be a valid Base58 address starting with "T". | ||
- **EVM**: Must be a valid Ethereum-style address (starting with "0x"). | ||
- If no address is provided, set to null. | ||
|
||
### Additional Notes: | ||
- If any required information is missing or invalid, respond with an appropriate error message. | ||
- The JSON response must only include the fields outlined above and must strictly adhere to the schema. | ||
|
||
Now, process the user's request and provide your response. | ||
`; | ||
|
||
export const swapTemplate = `Given the recent messages and wallet information below: | ||
|
||
{{recentMessages}} | ||
|
||
{{walletInfo}} | ||
|
||
Extract the following information about the requested token swap: | ||
- Input token address (the token being sold) | ||
- Output token address (the token being bought) | ||
- Amount to swap: Must be a string representing the amount in the chain's native units (only number without coin symbol, e.g., "100") | ||
- Slippage tolerance (optional, default is 0.5% if not specified) | ||
|
||
Respond with a JSON markdown block containing only the extracted values. Use null for any values that cannot be determined: | ||
|
||
\`\`\`json | ||
{ | ||
"inputToken": string | null, | ||
"outputToken": string | null, | ||
"amount": string | null, | ||
"slippage": number | null | ||
} | ||
\`\`\` | ||
|
||
**Validation Details**: | ||
1. **Amount**: | ||
- Verify the amount is a valid numeric string. | ||
|
||
2. **Input and Output Tokens**: | ||
- Validate token TRON address: Base58. | ||
- Set to null if tokens are not specified. | ||
|
||
3. **Slippage**: | ||
- If the user does not specify, use the default value of 0.5%. | ||
|
||
**Example Scenarios**: | ||
1. User says, "Swap 50 TRX to USDT (TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t)": | ||
- Input token: null | ||
- Output token: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t" | ||
- Amount: "50" | ||
- Slippage: null (default will apply) | ||
|
||
2. User says, "Swap 2 TRX to USDT (TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t) with 1% slippage": | ||
- Input token: null | ||
- Output token: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t" | ||
- Amount: "2" | ||
- Slippage: 0.01 | ||
|
||
Now, process the user's request and provide the JSON response.`; |
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.
Address the missing peer dependency.
The pipeline failure indicates a missing peer dependency. Add the following to your package.json:
{
"peerDependencies": {
"fastestsmallesttextencoderdecoder": ">=1.0.22 <2.0.0-0"
}
}
🧰 Tools
🪛 Gitleaks (8.21.2)
144-144: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
150-150: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
```env | ||
# Required | ||
TRON_PRIVATE_KEY=your-private-key-here | ||
|
||
# Optional - Custom RPC URLs | ||
TRON_PROVIDER_URL=https://your-custom-tron-rpc-url | ||
``` |
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.
🛠️ Refactor suggestion
Add security best practices for private key management.
The README should include warnings about secure private key handling and recommend using environment variables through a secure secrets management system.
Add a security section with best practices for managing private keys in production environments.
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
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: 14
🧹 Nitpick comments (22)
packages/plugin-tron/src/actions/transfer.ts (2)
38-40
: Simplify Amount ConversionThe use of
BigNumber
and immediate conversion to a number in lines 38-40 is unnecessary and may introduce precision issues. Consider usingtronWeb.toSun(params.amount)
directly, as it returns a string representing the amount in SUN.Simplify the code:
- const amount = BigNumber( - tronWeb.toSun(+params.amount) - ).toNumber(); + const amount = tronWeb.toSun(params.amount);🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
73-74
: Robust Error Handling
error
may not always have amessage
property. To avoid undefined errors, useString(error)
or check iferror.message
exists.Improve error handling:
- throw new Error(`Transfer failed: ${error.message}`); + const errorMessage = error.message || String(error); + throw new Error(`Transfer failed: ${errorMessage}`);🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/actions/bridge.ts (1)
125-130
: Improved Axios Error HandlingIn lines 126-129, throwing
new Error(error.response.data)
may result in[object Object]
iferror.response.data
is an object. Consider stringifying the error data for clarity.Update the error handling:
- throw new Error(error.response.data); + throw new Error(JSON.stringify(error.response.data));🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/actions/swap.ts (1)
219-225
: Robust Error HandlingIn the catch block,
error
may not have amessage
property. UseString(error)
to ensure the error message is captured correctly.Modify the error handling:
- callback({ text: `Error: ${error.message}` }); + const errorMessage = error.message || String(error); + callback({ text: `Error: ${errorMessage}` });🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/providers/wallet.ts (2)
191-211
: Address the commented TEE mode code.Remove the commented code related to TEE mode if it's not planned for implementation, or add a TODO note if future support is intended.
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
231-239
: Enhance error handling intronWalletProvider.get
.Provide more informative error messages to assist in debugging when exceptions occur.
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/index.ts (1)
13-20
: Review empty evaluators and services arrays.If no evaluators or services are needed, consider removing or documenting why they're empty.
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/environment.ts (3)
4-8
: Rename schema to match its purpose.The schema name
discordEnvSchema
is misleading as it validates Tron configuration. Consider renaming totronEnvSchema
.-export const discordEnvSchema = z.object({ +export const tronEnvSchema = z.object({ TRON_PRIVATE_KEY: z.string().min(1, "TRON_PRIVATE_KEY is required"), });🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
8-8
: Update type name for consistency.The type name should also reflect Tron configuration.
-export type DiscordConfig = z.infer<typeof discordEnvSchema>; +export type TronConfig = z.infer<typeof tronEnvSchema>;🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
10-32
: Consider additional validation for TRON_PRIVATE_KEY format.The validation only checks for non-empty string. Consider adding format validation for the private key.
export const discordEnvSchema = z.object({ - TRON_PRIVATE_KEY: z.string().min(1, "TRON_PRIVATE_KEY is required"), + TRON_PRIVATE_KEY: z.string() + .min(1, "TRON_PRIVATE_KEY is required") + .regex(/^[0-9a-fA-F]{64}$/, "TRON_PRIVATE_KEY must be a 64-character hex string"), });🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/interfaces/symbiosis.ts (1)
1-18
: Add JSDoc comments for better documentation.Consider adding JSDoc comments to describe the purpose and usage of each interface.
+/** Represents a token in the Symbiosis protocol */ export interface SymbiosisToken { chainId: number; address: string; symbol: string; decimals: number; } +/** Extends SymbiosisToken with amount information for transactions */ export interface SymbiosisTokenIn extends SymbiosisToken { amount: string; } +/** Parameters for initiating a swap request */ export interface SymbiosisSwapRequest { tokenAmountIn: SymbiosisTokenIn; tokenOut: SymbiosisToken; from: string; to: string; slippage: number; }🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/test/wallet.test.ts (2)
36-36
: Move hardcoded token address to test constants.The USDT token address should be moved to a dedicated constants file to improve maintainability and avoid false positives in security scans.
+// In src/test/constants.ts +export const TEST_TOKENS = { + USDT: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t" +}; -const tokenAddress = "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"; // USDT +const tokenAddress = TEST_TOKENS.USDT;🧰 Tools
🪛 Gitleaks (8.21.2)
36-36: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
66-71
: Add test cases for edge scenarios.The balance tests should include cases for:
- Non-zero balances
- Error handling scenarios
- Rate limiting responses
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/types/index.ts (2)
88-116
: Simplify RPC URL configuration using dynamic keys.Instead of listing all chains explicitly, consider using a dynamic key type.
export interface TronPluginConfig { - rpcUrl?: { - ethereum?: string; - abstract?: string; - // ... many more chains - alienx?: string; - }; + rpcUrl?: Partial<Record<SupportedChain, string>>; secrets?: { TRON_PRIVATE_KEY: string; }; // ... rest of the config }🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
160-163
: Enhance error handling with specific error codes.Consider using an enum for error codes to make error handling more predictable.
+export enum ProviderErrorCode { + INVALID_INPUT = 1000, + NETWORK_ERROR = 2000, + INSUFFICIENT_FUNDS = 3000, + // Add more specific error codes +} + export interface ProviderError extends Error { - code?: number; + code?: ProviderErrorCode; data?: unknown; }🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/abis/wtrx.ts (1)
14-15
: Consider using more descriptive parameter names.The parameter name 'sad' is used for amount values. Consider using more conventional names like 'amount' or 'value' for better code readability.
Also applies to: 35-37, 84-85
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/templates/index.ts (1)
88-98
: Consider adding chain-specific address format validation.The bridge template could benefit from more detailed address format validation for each supported chain.
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/package.json (1)
27-40
: Consider using stricter version constraints.Some dependencies use
^
which might lead to unexpected updates. Consider using exact versions for critical dependencies liketronweb
."dependencies": { "@elizaos/core": "^0.1.7", "@elizaos/plugin-tee": "^0.1.7", - "tronweb": "^6.0.0", + "tronweb": "6.0.0", // ... other dependencies }🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/README.md (3)
7-7
: Fix grammar in description.Add "the" before "TRON blockchain".
-The TRON plugin provides comprehensive functionality for interacting with TRON blockchain, including token transfers, cross-chain bridging, and token swaps using Symbiosis integration. +The TRON plugin provides comprehensive functionality for interacting with the TRON blockchain, including token transfers, cross-chain bridging, and token swaps using Symbiosis integration.🧰 Tools
🪛 LanguageTool
[uncategorized] ~7-~7: You might be missing the article “the” here.
Context: ...sive functionality for interacting with TRON blockchain, including token transfers, ...(AI_EN_LECTOR_MISSING_DETERMINER_THE)
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
38-38
: Add missing comma in configuration section.Add a comma after "URL".
-By default, the RPC URL is inferred from the `viem/chains` config. To use a custom RPC URL add the following to your `.env` file: +By default, the RPC URL is inferred from the `viem/chains` config. To use a custom RPC URL, add the following to your `.env` file:🧰 Tools
🪛 LanguageTool
[uncategorized] ~38-~38: A comma might be missing here.
Context: ...iem/chainsconfig. To use a custom RPC URL add the following to your
.env` file: ...(AI_EN_LECTOR_MISSING_PUNCTUATION_COMMA)
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
63-77
: Enhance code examples with error handling and comments.The code examples should:
- Include error handling
- Document the hardcoded addresses
- Add comments explaining the expected responses
Would you like me to provide enhanced versions of these code examples with proper error handling and documentation?
Also applies to: 83-96, 102-116
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
.env.example (1)
710-712
: Enhance Tron configuration documentation.Add comments explaining:
- Required format for TRON_PRIVATE_KEY
- Supported TRON_PROVIDER_URL endpoints
- Optional vs required fields
# Tron blockchain -TRON_PRIVATE_KEY= -TRON_PROVIDER_URL= +# Required: Private key in hex format (64 characters) +TRON_PRIVATE_KEY= +# Optional: Custom RPC URL (defaults to Tron Mainnet) +# Examples: +# - Mainnet: https://api.trongrid.io +# - Testnet: https://api.shasta.trongrid.io +TRON_PROVIDER_URL=
📜 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 (26)
.env.example
(1 hunks)agent/package.json
(1 hunks)agent/src/index.ts
(2 hunks)packages/plugin-tron/.gitignore
(1 hunks)packages/plugin-tron/README.md
(1 hunks)packages/plugin-tron/eslint.config.mjs
(1 hunks)packages/plugin-tron/package.json
(1 hunks)packages/plugin-tron/prettier.config.cjs
(1 hunks)packages/plugin-tron/src/abis/sunswap_v2_factory.ts
(1 hunks)packages/plugin-tron/src/abis/sunswap_v2_pair.ts
(1 hunks)packages/plugin-tron/src/abis/sunswap_v2_router.ts
(1 hunks)packages/plugin-tron/src/abis/trc10.ts
(1 hunks)packages/plugin-tron/src/abis/wtrx.ts
(1 hunks)packages/plugin-tron/src/actions/bridge.ts
(1 hunks)packages/plugin-tron/src/actions/swap.ts
(1 hunks)packages/plugin-tron/src/actions/transfer.ts
(1 hunks)packages/plugin-tron/src/constants.ts
(1 hunks)packages/plugin-tron/src/environment.ts
(1 hunks)packages/plugin-tron/src/index.ts
(1 hunks)packages/plugin-tron/src/interfaces/symbiosis.ts
(1 hunks)packages/plugin-tron/src/providers/wallet.ts
(1 hunks)packages/plugin-tron/src/templates/index.ts
(1 hunks)packages/plugin-tron/src/test/wallet.test.ts
(1 hunks)packages/plugin-tron/src/types/index.ts
(1 hunks)packages/plugin-tron/tsconfig.json
(1 hunks)packages/plugin-tron/tsup.config.ts
(1 hunks)
✅ Files skipped from review due to trivial changes (5)
- packages/plugin-tron/eslint.config.mjs
- packages/plugin-tron/tsconfig.json
- packages/plugin-tron/tsup.config.ts
- packages/plugin-tron/prettier.config.cjs
- packages/plugin-tron/.gitignore
🧰 Additional context used
🪛 GitHub Actions: smoke-test
packages/plugin-tron/src/abis/wtrx.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/index.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/README.md
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/environment.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/test/wallet.test.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/abis/sunswap_v2_factory.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/abis/sunswap_v2_pair.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/templates/index.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/abis/trc10.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/actions/transfer.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/constants.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/abis/sunswap_v2_router.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/package.json
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/actions/bridge.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/interfaces/symbiosis.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/providers/wallet.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/actions/swap.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/types/index.ts
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
🪛 GitHub Actions: Integration Tests
agent/src/index.ts
[error] Wallet address not provided
[error] Failed to fetch DBPDA
[error] Cannot found onchain data in this wallet
🪛 LanguageTool
packages/plugin-tron/README.md
[uncategorized] ~7-~7: You might be missing the article “the” here.
Context: ...sive functionality for interacting with TRON blockchain, including token transfers, ...
(AI_EN_LECTOR_MISSING_DETERMINER_THE)
[uncategorized] ~38-~38: A comma might be missing here.
Context: ...iem/chainsconfig. To use a custom RPC URL add the following to your
.env` file: ...
(AI_EN_LECTOR_MISSING_PUNCTUATION_COMMA)
🪛 Gitleaks (8.21.2)
packages/plugin-tron/src/test/wallet.test.ts
36-36: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
packages/plugin-tron/src/templates/index.ts
144-144: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
150-150: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
🔇 Additional comments (11)
packages/plugin-tron/src/providers/wallet.ts (2)
97-103
:⚠️ Potential issueCorrect the
approve
method call syntax.Adjust the method invocation to:
- return await token.methods.approve(spender, allowance).send({ + return await token.approve(spender, allowance).send({This ensures the approve function is called correctly.
Likely invalid or redundant comment.
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
105-108
:⚠️ Potential issueFix the
allowance
method call.Update the method call to:
- return await token["allowance"](owner, spender).call(); + return await token.allowance(owner, spender).call();This aligns with the proper syntax.
Likely invalid or redundant comment.
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/constants.ts (1)
1-8
: Verify the accuracy of addresses and fee limits.Confirm that all contract addresses and fee limits are correct and up-to-date.
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/abis/sunswap_v2_factory.ts (1)
1-189
: LGTM! Well-structured factory contract ABI.The SunswapV2Factory ABI follows the standard DEX factory pattern, with proper event indexing and comprehensive pair management functions.
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/templates/index.ts (1)
27-32
: LGTM! Comprehensive validation steps.The validation steps cover all critical aspects: amount format, address validation, and token verification.
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/abis/trc10.ts (1)
1-410
: LGTM! Well-structured TRC10 token contract ABI.The ABI includes all necessary functions with proper access control and transfer modes. Events are correctly indexed for efficient querying.
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/abis/sunswap_v2_pair.ts (2)
610-637
: Verify swap function parameter types for Tron compatibility.The swap function signature looks correct but ensure the
bytes
type fordata
parameter is compatible with Tron's implementation.Run this script to verify the parameter types:
✅ Verification successful
The
bytes
parameter type is compatible with Tron's implementation🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for swap function implementations in Tron contracts ast-grep --pattern 'function swap(uint256 amount0Out, uint256 amount1Out, address to, bytes calldata data)'Length of output: 109
Script:
#!/bin/bash # Search for swap function definitions in ABI files rg -A 10 '"name": "swap",' --type ts # Search for bytes parameter usage in contract-related files rg -B 5 '"type": "bytes"' --type ts # Find all ABI files that might contain swap functions fd -e ts -e json . packages/plugin-tron/src/abis/ --exec grep -l "swap"Length of output: 1420
Script:
#!/bin/bash # Check swap function signature in router rg -A 15 '"name": "swap",' packages/plugin-tron/src/abis/sunswap_v2_router.tsLength of output: 79
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
8-31
: Verify event parameter indexing for the Approval event.The event parameter indexing looks correct for efficient filtering, with
owner
andspender
indexed butvalue
unindexed. This matches the ERC20 standard.Run this script to verify consistency with other DEX implementations:
✅ Verification successful
Approval event parameter indexing is correctly implemented
The implementation follows the ERC20 standard with
owner
andspender
indexed for efficient filtering, while keepingvalue
non-indexed for full data access. This pattern is consistent across all token implementations in the codebase.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for Approval event definitions in other DEX contracts ast-grep --pattern 'event Approval(address indexed owner, address indexed spender, uint256 value)'Length of output: 100
Script:
#!/bin/bash # Search for Approval events in ABI files rg -U --multiline '"name":\s*"Approval".*?"type":\s*"event"' -A 20Length of output: 68
Script:
#!/bin/bash # Find and examine ABI files fd -e ts -e json -e abi . packages/plugin-tron/src/abis/ --exec cat {}Length of output: 47471
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/abis/sunswap_v2_router.ts (1)
652-684
: Verify deadline parameter usage in swap functions.The deadline parameter is correctly included to prevent transaction staleness. This is crucial for DEX operations.
Run this script to verify consistent deadline usage:
✅ Verification successful
Deadline parameter implementation is correct and consistent
The deadline parameter is properly implemented as uint256 across all swap functions in the SunSwap V2 router and pair contracts.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for deadline parameter in swap functions ast-grep --pattern 'function $_($$, uint256 deadline)'Length of output: 56
Script:
#!/bin/bash # Search for function definitions with deadline parameter in their inputs rg '"name": "deadline"' -B 2 -A 2Length of output: 7387
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
agent/src/index.ts (2)
60-60
: LGTM: Clean import of the Tron plugin.The import is correctly placed among other blockchain plugin imports.
🧰 Tools
🪛 GitHub Actions: Integration Tests
[error] Wallet address not provided
[error] Failed to fetch DBPDA
[error] Cannot found onchain data in this wallet
1096-1096
: Verify secure handling of TRON_PRIVATE_KEY.The plugin initialization is correctly gated by the presence of TRON_PRIVATE_KEY.
Run this script to verify secure key handling:
✅ Verification successful
TRON_PRIVATE_KEY handling follows security best practices
- Access is properly controlled through getter methods
- Multiple validation layers are in place
- No sensitive data exposure in logs or errors
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for private key usage patterns rg -A 5 "TRON_PRIVATE_KEY" --type tsLength of output: 3719
🧰 Tools
🪛 GitHub Actions: Integration Tests
[error] Wallet address not provided
[error] Failed to fetch DBPDA
[error] Cannot found onchain data in this wallet
value: BigInt(params.amount), | ||
data: params.token, |
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.
Potential Issue with BigInt Conversion
In line 48, converting params.amount
to BigInt
may cause errors if params.amount
is a decimal or string representing a non-integer value. Ensure that amounts are correctly converted to integers before using BigInt
.
Adjust the conversion:
- value: BigInt(params.amount),
+ value: BigInt(tronWeb.toSun(params.amount)),
Committable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
const { abi } = await tronWeb.trx.getContract(params.token); | ||
const tokenContract = tronWeb.contract( | ||
abi.entrys, | ||
params.token | ||
); |
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.
Possible Typo in ABI Property Access
In line 35, you're accessing abi.entrys
when creating the contract instance. This property may not exist or could be misspelled. The correct property might be abi.entries
. Verify and correct the property name to ensure the contract is instantiated properly.
Apply this fix if it's a typo:
- abi.entrys,
+ abi.entries,
Committable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
slippage: params.slippage || 300, | ||
}); |
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.
Inconsistent Slippage Units
The slippage
parameter is set to params.slippage || 300
, suggesting it's in basis points (e.g., 300 for 3%). However, in other parts of the code, slippage might be treated as a decimal. This inconsistency could lead to incorrect calculations and unexpected behavior.
Ensure slippage is consistently represented throughout the code. If using basis points, adjust calculations accordingly.
- slippage: params.slippage || 300,
+ const slippage = (params.slippage || 300) / 10000; // Convert to decimal
Committable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
.getAmountOut(fromAmount, reserve0, reserve1) | ||
.call(); | ||
|
||
return new BigNumber(amountOut).multipliedBy(1 - slippage).toFixed(0); |
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.
Incorrect Slippage Calculation
The calculation 1 - slippage
in line 170 may not produce the expected result if slippage
is intended to be a percentage or basis points. Ensure that slippage is correctly converted to a decimal factor before applying it.
Adjust the calculation:
- return new BigNumber(amountOut).multipliedBy(1 - slippage).toFixed(0);
+ const slippageFactor = (10000 - slippage) / 10000; // For basis points
+ return new BigNumber(amountOut).multipliedBy(slippageFactor).toFixed(0);
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
return new BigNumber(amountOut).multipliedBy(1 - slippage).toFixed(0); | |
const slippageFactor = (10000 - slippage) / 10000; // For basis points | |
return new BigNumber(amountOut).multipliedBy(slippageFactor).toFixed(0); |
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
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: 15
🧹 Nitpick comments (12)
packages/plugin-tron/src/types/index.ts (1)
87-116
: Simplify the 'rpcUrl' configuration using a mappingThe current
rpcUrl
configuration lists each chain individually. This approach may become unwieldy as more chains are added. Consider using a mapping from chain names to RPC URLs to enhance scalability and maintainability.Apply this diff to simplify the configuration:
export interface TronPluginConfig { - rpcUrl?: { - ethereum?: string; - abstract?: string; - base?: string; - sepolia?: string; - bsc?: string; - arbitrum?: string; - avalanche?: string; - polygon?: string; - optimism?: string; - cronos?: string; - gnosis?: string; - fantom?: string; - klaytn?: string; - celo?: string; - moonbeam?: string; - aurora?: string; - harmonyOne?: string; - moonriver?: string; - arbitrumNova?: string; - mantle?: string; - linea?: string; - scroll?: string; - filecoin?: string; - taiko?: string; - zksync?: string; - canto?: string; - alienx?: string; - }; + rpcUrl?: { + [chainName: string]: string; + }; secrets?: { TRON_PRIVATE_KEY: string; }; testMode?: boolean; multicall?: { batchSize?: number; wait?: number; }; }🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/actions/transfer.ts (1)
73-74
: Ensure 'error.message' is accessible when throwingIn the catch block,
error
may not always have amessage
property, leading to undefined errors. Safely accesserror.message
or converterror
to a string.Apply this diff for safer error handling:
} catch (error) { - throw new Error(`Transfer failed: ${error.message}`); + const errorMessage = error instanceof Error ? error.message : String(error); + throw new Error(`Transfer failed: ${errorMessage}`); }🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/providers/wallet.ts (1)
193-210
: Remove unnecessary commented-out code.Deleting the commented-out code enhances readability and maintainability.
Apply this diff:
if (teeMode !== TEEMode.OFF) { throw new Error("TEE_MODE is not supported for TRON"); - // const walletSecretSalt = runtime.getSetting("WALLET_SECRET_SALT"); - // if (!walletSecretSalt) { - // throw new Error( - // "WALLET_SECRET_SALT required when TEE_MODE is enabled" - // ); - // } - // - // const deriveKeyProvider = new DeriveKeyProvider(teeMode); - // const deriveKeyResult = await deriveKeyProvider.deriveEcdsaKeypair( - // "/", - // walletSecretSalt, - // runtime.agentId - // ); - // return new WalletProvider( - // deriveKeyResult.keypair., - // runtime.cacheManager, - // customRpcUrl - // ); } else { const privateKey = runtime.getSetting("TRON_PRIVATE_KEY") as string;🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/tsup.config.ts (1)
8-8
: Remove misleading comment about CommonJS.The comment suggests CommonJS targeting, but the format is set to ESM only.
- format: ["esm"], // Ensure you're targeting CommonJS + format: ["esm"],🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/interfaces/symbiosis.ts (1)
86-119
: Consolidate duplicate token interfaces.
Token
,TokenAmountOut
,TokenAmountOutMin
, andAmountInUsd
share the same structure. Consider using a base interface with composition.+interface BaseToken { + symbol: string; + address: string; + chainId: number; + decimals: number; + icon?: string; +} +interface TokenWithAmount extends BaseToken { + amount: string; +} -export interface Token {...} +export interface Token extends BaseToken {} -export interface TokenAmountOut {...} +export interface TokenAmountOut extends TokenWithAmount {} -export interface TokenAmountOutMin {...} +export interface TokenAmountOutMin extends TokenWithAmount {} -export interface AmountInUsd {...} +export interface AmountInUsd extends TokenWithAmount {}🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/test/wallet.test.ts (1)
66-95
: Consider expanding test coverage.While the basic functionality is tested, consider adding test cases for:
- Error scenarios (invalid addresses, network failures)
- Edge cases (zero balance, zero allowance)
- Token operations with different decimals
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/abis/wtrx.ts (1)
1-162
: Consider standardizing parameter names.The ABI uses unconventional parameter names like
sad
andguy
. Consider using more standard names:
sad
→amount
guy
→spender
oraccount
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/templates/index.ts (2)
1-58
: Consider enhancing transfer validation.Add validation for:
- Maximum transfer limits
- Contract address blacklist
- Gas fee estimation
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
107-154
: Enhance swap-specific validations.Consider adding:
- Price impact check
- Liquidity validation
- MEV protection parameters
🧰 Tools
🪛 Gitleaks (8.21.2)
144-144: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
150-150: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/abis/sunswap_v2_pair.ts (1)
1-658
: Add protocol-specific documentation.The Sunswap V2 pair ABI would benefit from:
- Documentation about the AMM formula
- Links to the protocol documentation
- Examples of common interactions
/** * Sunswap V2 Pair Contract ABI * @see https://sun.io/docs/v2 * * Common interactions: * - swap: Execute token swaps * - addLiquidity: Provide liquidity * - removeLiquidity: Remove liquidity */ export interface ISunswapV2Pair { // ... interface definition } export default [ // ... existing ABI ] as ISunswapV2Pair;🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/README.md (1)
36-48
: Add RPC endpoint security considerations.Document:
- SSL/TLS requirements
- Rate limiting considerations
- Fallback strategies
### Custom RPC URLs By default, the RPC URL is inferred from the `viem/chains` config. To use a custom RPC URL add the following to your `.env` file: +> 🔒 **Security Note**: +- Use HTTPS endpoints only +- Consider rate limiting +- Implement fallback endpoints + ```env TRON_PROVIDER_URL=https://your-custom-tron-rpc-url<details> <summary>🧰 Tools</summary> <details> <summary>🪛 GitHub Actions: smoke-test</summary> [warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0 </details> </details> </blockquote></details> <details> <summary>packages/plugin-tron/src/abis/trc10.ts (1)</summary><blockquote> `92-143`: **Document transfer modes** The mode system (`MODE_NORMAL`, `MODE_TRANSFER_CONTROLLED`, `MODE_TRANSFER_RESTRICTED`) lacks documentation about the implications of each mode. Add JSDoc comments explaining each mode's purpose and impact on transfers. <details> <summary>🧰 Tools</summary> <details> <summary>🪛 GitHub Actions: smoke-test</summary> [warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0 </details> </details> </blockquote></details> </blockquote></details> <details> <summary>📜 Review details</summary> **Configuration used: CodeRabbit UI** **Review profile: CHILL** **Plan: Pro** <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between a00f7237542b734e239de539bb3ee99271542ab7 and f2923734a2e9b7f7c25e7a8b1fe7bb9cc16029cd. </details> <details> <summary>⛔ Files ignored due to path filters (1)</summary> * `pnpm-lock.yaml` is excluded by `!**/pnpm-lock.yaml` </details> <details> <summary>📒 Files selected for processing (26)</summary> * `.env.example` (1 hunks) * `agent/package.json` (1 hunks) * `agent/src/index.ts` (2 hunks) * `packages/plugin-tron/.gitignore` (1 hunks) * `packages/plugin-tron/README.md` (1 hunks) * `packages/plugin-tron/eslint.config.mjs` (1 hunks) * `packages/plugin-tron/package.json` (1 hunks) * `packages/plugin-tron/prettier.config.cjs` (1 hunks) * `packages/plugin-tron/src/abis/sunswap_v2_factory.ts` (1 hunks) * `packages/plugin-tron/src/abis/sunswap_v2_pair.ts` (1 hunks) * `packages/plugin-tron/src/abis/sunswap_v2_router.ts` (1 hunks) * `packages/plugin-tron/src/abis/trc10.ts` (1 hunks) * `packages/plugin-tron/src/abis/wtrx.ts` (1 hunks) * `packages/plugin-tron/src/actions/bridge.ts` (1 hunks) * `packages/plugin-tron/src/actions/swap.ts` (1 hunks) * `packages/plugin-tron/src/actions/transfer.ts` (1 hunks) * `packages/plugin-tron/src/constants.ts` (1 hunks) * `packages/plugin-tron/src/environment.ts` (1 hunks) * `packages/plugin-tron/src/index.ts` (1 hunks) * `packages/plugin-tron/src/interfaces/symbiosis.ts` (1 hunks) * `packages/plugin-tron/src/providers/wallet.ts` (1 hunks) * `packages/plugin-tron/src/templates/index.ts` (1 hunks) * `packages/plugin-tron/src/test/wallet.test.ts` (1 hunks) * `packages/plugin-tron/src/types/index.ts` (1 hunks) * `packages/plugin-tron/tsconfig.json` (1 hunks) * `packages/plugin-tron/tsup.config.ts` (1 hunks) </details> <details> <summary>✅ Files skipped from review due to trivial changes (6)</summary> * packages/plugin-tron/eslint.config.mjs * packages/plugin-tron/tsconfig.json * packages/plugin-tron/prettier.config.cjs * packages/plugin-tron/.gitignore * packages/plugin-tron/package.json * packages/plugin-tron/src/constants.ts </details> <details> <summary>🧰 Additional context used</summary> <details> <summary>🪛 GitHub Actions: smoke-test</summary> <details> <summary>packages/plugin-tron/src/index.ts</summary> [warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0 </details> <details> <summary>packages/plugin-tron/README.md</summary> [warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0 </details> <details> <summary>packages/plugin-tron/tsup.config.ts</summary> [warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0 </details> <details> <summary>packages/plugin-tron/src/abis/wtrx.ts</summary> [warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0 </details> <details> <summary>packages/plugin-tron/src/environment.ts</summary> [warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0 </details> <details> <summary>packages/plugin-tron/src/test/wallet.test.ts</summary> [warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0 </details> <details> <summary>packages/plugin-tron/src/abis/trc10.ts</summary> [warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0 </details> <details> <summary>packages/plugin-tron/src/actions/transfer.ts</summary> [warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0 </details> <details> <summary>packages/plugin-tron/src/abis/sunswap_v2_pair.ts</summary> [warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0 </details> <details> <summary>packages/plugin-tron/src/types/index.ts</summary> [warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0 </details> <details> <summary>packages/plugin-tron/src/abis/sunswap_v2_factory.ts</summary> [warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0 </details> <details> <summary>packages/plugin-tron/src/actions/bridge.ts</summary> [warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0 </details> <details> <summary>packages/plugin-tron/src/providers/wallet.ts</summary> [warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0 </details> <details> <summary>packages/plugin-tron/src/actions/swap.ts</summary> [warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0 </details> <details> <summary>packages/plugin-tron/src/templates/index.ts</summary> [warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0 </details> <details> <summary>packages/plugin-tron/src/abis/sunswap_v2_router.ts</summary> [warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0 </details> <details> <summary>packages/plugin-tron/src/interfaces/symbiosis.ts</summary> [warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0 </details> </details> <details> <summary>🪛 Gitleaks (8.21.2)</summary> <details> <summary>packages/plugin-tron/src/test/wallet.test.ts</summary> 36-36: Detected a Generic API Key, potentially exposing access to various services and sensitive operations. (generic-api-key) </details> <details> <summary>packages/plugin-tron/src/templates/index.ts</summary> 144-144: Detected a Generic API Key, potentially exposing access to various services and sensitive operations. (generic-api-key) --- 150-150: Detected a Generic API Key, potentially exposing access to various services and sensitive operations. (generic-api-key) </details> </details> </details> <details> <summary>🔇 Additional comments (14)</summary><blockquote> <details> <summary>packages/plugin-tron/src/types/index.ts (1)</summary> `1-10`: **Verify missing peer dependency** The pipeline reports a missing peer dependency: `fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0`. Ensure this dependency is correctly installed to prevent potential runtime issues. Run the following script to identify missing peer dependencies: <details> <summary>🧰 Tools</summary> <details> <summary>🪛 GitHub Actions: smoke-test</summary> [warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0 </details> </details> </details> <details> <summary>packages/plugin-tron/src/actions/swap.ts (2)</summary> `61-71`: **Verify method names match TRON's smart contract interface.** Methods like `swapExactETHForTokens` and `swapExactTokensForETH` may be Ethereum-specific. Ensure these method names are correct for TRON's SunSwap V2 Router. Also applies to: 86-98, 100-111 <details> <summary>🧰 Tools</summary> <details> <summary>🪛 GitHub Actions: smoke-test</summary> [warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0 </details> </details> --- `166-168`: _:warning: Potential issue_ **Correct assignment of 'getAmountOut' result.** The method `getAmountOut` returns a single value. Remove the destructuring to properly assign `amountOut`. Apply this diff: ```diff - const [amountOut] = await router.methods + const amountOut = await router.methods .getAmountOut(fromAmount, reserve0, reserve1) .call();
Likely invalid or redundant comment.
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/abis/sunswap_v2_router.ts (1)
1-973
: ABI appears correct and comprehensive.The SunSwap V2 Router ABI is accurately defined and includes all necessary methods for router interactions.
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/index.ts (1)
1-22
: LGTM! Well-structured plugin definition.The plugin exports are organized clearly, and the plugin metadata is well-defined.
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/test/wallet.test.ts (3)
1-30
: Well-structured test setup with comprehensive mocking!The test setup follows best practices by properly mocking external dependencies.
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
31-51
: LGTM: Proper test initialization with clean setup and teardown!The beforeEach and afterEach hooks ensure a clean test environment.
🧰 Tools
🪛 Gitleaks (8.21.2)
36-36: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
53-64
: Good coverage of constructor functionality!Tests verify both address initialization and default chain setting.
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
packages/plugin-tron/src/abis/sunswap_v2_factory.ts (1)
1-189
: Well-defined factory contract ABI!The ABI includes all essential DEX factory functions and events, following standard patterns.
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
agent/src/index.ts (1)
60-60
: Verify TRON_PROVIDER_URL when TRON_PRIVATE_KEY is present.The plugin initialization should verify both required environment variables.
-getSecret(character, "TRON_PRIVATE_KEY") ? tronPlugin : null, +getSecret(character, "TRON_PRIVATE_KEY") && getSecret(character, "TRON_PROVIDER_URL") ? tronPlugin : null,Also applies to: 1096-1096
agent/package.json (1)
73-73
: LGTM! Tron plugin dependency added correctly.The workspace dependency for @elizaos/plugin-tron is properly configured.
.env.example (1)
710-712
: Consider adding documentation comments for the Tron configuration.While the variables are self-explanatory, adding comments about:
- Expected format of the private key
- Recommended provider URLs for different networks (mainnet/testnet)
would improve developer experience.Let's check if there's any existing documentation about these variables:
packages/plugin-tron/src/abis/trc10.ts (2)
344-409
:⚠️ Potential issueInstall missing peer dependency
The pipeline warning indicates a missing dependency
fastestsmallesttextencoderdecoder
which is required for proper encoding/decoding of transfer data.Add the dependency to your package.json:
+"fastestsmallesttextencoderdecoder": "^1.0.22"
Likely invalid or redundant comment.
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
144-343
: Add Tron-specific error handlingWhile the implementation follows OpenZeppelin's ERC20 pattern, consider adding Tron-specific error handling for energy limits and bandwidth consumption.
Let's check if error handling is implemented in the actions:
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
export const discordEnvSchema = z.object({ | ||
TRON_PRIVATE_KEY: z.string().min(1, "TRON_PRIVATE_KEY is required"), | ||
}); | ||
|
||
export type DiscordConfig = z.infer<typeof discordEnvSchema>; |
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.
Fix schema naming: 'discord' → 'tron'.
The schema is named discordEnvSchema
but it's for TRON configuration.
-export const discordEnvSchema = z.object({
+export const tronEnvSchema = z.object({
TRON_PRIVATE_KEY: z.string().min(1, "TRON_PRIVATE_KEY is required"),
});
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
export const discordEnvSchema = z.object({ | |
TRON_PRIVATE_KEY: z.string().min(1, "TRON_PRIVATE_KEY is required"), | |
}); | |
export type DiscordConfig = z.infer<typeof discordEnvSchema>; | |
export const tronEnvSchema = z.object({ | |
TRON_PRIVATE_KEY: z.string().min(1, "TRON_PRIVATE_KEY is required"), | |
}); | |
export type TronConfig = z.infer<typeof tronEnvSchema>; |
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
amountInUsd: AmountInUsd; | ||
approveTo: string; | ||
type: string; | ||
rewards: unknown[]; |
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.
🛠️ Refactor suggestion
Define proper type for rewards array.
Using unknown[]
for rewards lacks type safety.
- rewards: unknown[];
+ rewards: {
+ amount: string;
+ token: Token;
+ }[];
Committable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
export default [ | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "string", | ||
"name": "name", | ||
"type": "string" | ||
}, | ||
{ | ||
"internalType": "string", | ||
"name": "symbol", | ||
"type": "string" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "totalSupply", | ||
"type": "uint256" | ||
} | ||
], | ||
"stateMutability": "nonpayable", | ||
"type": "constructor" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "owner", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "spender", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "uint256", | ||
"name": "value", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "Approval", | ||
"type": "event" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "previousOwner", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "newOwner", | ||
"type": "address" | ||
} | ||
], | ||
"name": "OwnershipTransferred", | ||
"type": "event" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "from", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "to", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "uint256", | ||
"name": "value", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "Transfer", | ||
"type": "event" | ||
}, |
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.
💡 Codebase verification
TRC10 implementation needs to be reworked using native TronWeb methods
The codebase incorrectly treats TRC10 tokens as smart contracts. TRC10 tokens are native to Tron and should use:
tronWeb.trx.getAccount()
for balancestronWeb.trx.transferAsset()
for transfers
🔗 Analysis chain
Incorrect token standard implementation
This appears to be a TRC20 ABI being used for TRC10 tokens. TRC10 is a native token standard on Tron that doesn't use smart contracts or ABI. Consider using @tronweb/tronweb
library's native methods for TRC10 operations instead.
Let's verify if there are any TRC10-specific implementations in the codebase:
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for TRC10-specific implementations
rg -i "trc10|freezeBalance|unfreezeBalance|transferAsset"
Length of output: 469
Script:
#!/bin/bash
# Check TronWeb usage and implementation details
rg -A 5 "tronWeb\." packages/plugin-tron/src/
Length of output: 9753
🧰 Tools
🪛 GitHub Actions: smoke-test
[warning] Missing peer dependency: fastestsmallesttextencoderdecoder@>=1.0.22 <2.0.0-0
@tcm390 can you check this |
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
can you check ai feedback; if you want you can push to original branch; some of the stuff from here! I would suggest opening a new PR so that all the comments are gone tho! |
Hello, We are changing our plugin development strategy to be more scalable. We have moved the plugins out into their own repos and we're looking for people to either maintain those or own them on their own Github. If you'd like to be a maintainer, file an issue in the plugin repo and join our Discord https://discord.gg/elizaos to coordinate. If you'd like to control the plugin on your own Github, please add an issue to the plugin repo pointing to your repo, and add a modification to the registry. Submit a PR to edit the registry here: https://github.com/elizaos-plugins/registry Closing this PR for now. Let us know if you have any questions. |
Fork
#2275
Relates to
No specific issue or ticket is linked to this PR.
Risks
Low: This PR is for create a plugin that is not effecting the core functionality of the application.
Background
What does this PR do?
This PR creates a plugin that allows users integrate with TRON blockchain. including the following features:
What kind of change is this?
Features (non-breaking change which adds functionality)
Documentation changes needed?
My changes do not require a change to the project documentation.
Testing
Where should a reviewer start?
Review the new plugin from src/index.ts, actions/_ providers/_
Detailed testing steps
Please refer to the README.md for detailed testing steps.
Summary by CodeRabbit
New Features
Configuration
Documentation