Added : Polygon Plugin #4635
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the ✨ Finishing Touches🧪 Generate Unit Tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. 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 (
|
Relates to
Issue:
This PR implements the core foundation and staking operations for the Polygon Plugin as part of the "Implement Polygon Plugin MVP" epic.
Risks
GasServiceprimarily uses L2 (PolygonScan) gas oracles. When used for L1 Ethereum transactions (staking, bridging), this can lead to inaccurate gas estimations, potentially causing transactions to be underpriced (fail) or overpriced.withdrawRewardsAction Stub: The LLM-enabledwithdrawRewardsaction is a non-functional stub. The core logic exists via the programmaticWITHDRAW_REWARDS_L1action and thePolygonRpcService.Background
What does this PR do?
Plugin Foundation (feat: replace
unruggable-corewithunruggable-sdk#450):Staking Read Operations (Package maintainers #453):
getValidatorInfo(validatorId)to fetch validator status, total stake, and commission rategetDelegatorInfo(validatorId, delegatorAddress)to get delegator stake and pending rewardsStaking Write Operations (fix: don't reply to tweets older than 5 days #454):
delegate(validatorId, amountWei)for staking MATIC/POL to validatorsundelegate(validatorId, sharesAmountWei)for initiating the unbonding processwithdrawRewards(validatorId)for claiming accumulated staking rewardsrestakeRewards(validatorId)as a convenience functionKey functionalities included:
package.json, TypeScript configuration, main plugin definition (src/index.ts) with lifecycle methods, and registration with ElizaOS.zod. Includes.env.example.PolygonRpcServiceimplements interactions with L1 staking contracts (StakeManager,ValidatorShare) for delegation, undelegation (partial viasellVoucher_newin service), reward withdrawal, and fetching validator/delegator information.PolygonRpcServiceimplements deposits to the L1RootChainManagercontract.PolygonRpcService.PolygonRpcServiceimplements checks against the L1RootChainManagerto verify L2 block checkpoint status.PROPOSE_GOVERNANCE_POLYGON,VOTE_GOVERNANCE_POLYGON) are implemented to interact with EVM-compatible governor smart contracts (e.g., OpenZeppelin Governor) usingviem.PolygonWalletProvider(usingviem) for EVM wallet interactions and exposing wallet details.PolygonRpcService(usingethers.js) for core L1/L2 EVM logic andGasServicefor L2 gas price fetching (PolygonScan).README.mdfor the plugin.What kind of change is this?
Features (non-breaking change which adds functionality)
Why are we doing this? Any context or related work?
This work establishes the dedicated
@elizaos/plugin-polygonas outlined in the "Implement Polygon Plugin MVP" epic. The goal is to create a focused plugin capable of handling Polygon-specific interactions (L1 staking, native bridge, Heimdall governance) that go beyond the scope of a generic EVM plugin. This PR lays the groundwork for these features, with many EVM-based L1/L2 interactions already functional.Documentation changes needed?
My changes do not require a change to the project documentation. (The plugin includes its own
README.mdwhich serves as initial documentation for its features and setup).Testing
Where should a reviewer start?
packages/plugin-polygon/README.md: For an overview of the plugin's intended features and setup.packages/plugin-polygon/src/index.ts: For the main plugin definition, configuration handling, and registration of components.packages/plugin-polygon/src/services/PolygonRpcService.ts: To understand the core logic for L1 staking, L1 bridging, and L2 interactions.packages/plugin-polygon/src/services/GasService.ts: To review the L2 gas oracle integration.packages/plugin-polygon/src/abi/: To verify the StakeManager and ValidatorShare ABIs are properly includedpackages/plugin-polygon/src/actions/delegate.ts: For L1 staking operationspackages/plugin-polygon/src/actions/getValidatorInfo.tsandgetDelegatorInfo.ts: For staking read operationsDetailed testing steps
Manual testing is recommended for this initial integration, focusing on the implemented P1 functionalities. Automated tests for configuration loading were considered in the ticket but not explicitly verified as present in this review.
Setup:
packages/plugin-polygondirectory..envfile based on.env.example..envfile with valid:POLYGON_RPC_URL(Polygon PoS RPC endpoint)ETHEREUM_RPC_URL(Ethereum Mainnet RPC endpoint for L1)PRIVATE_KEY(for a wallet with funds on both L1 and L2 for testing)POLYGONSCAN_KEY(API key for PolygonScan)HEIMDALL_RPC_URL(placeholder, as Heimdall features are not yet implemented)