POC impl for token type adaptors to encapsulate token logic#2015
POC impl for token type adaptors to encapsulate token logic#2015
Conversation
|
👋 matYang, thanks for creating this pull request! To help reviewers, please consider creating future PRs as drafts first. This allows you to self-review and make any final changes before notifying the team. Once you're ready, you can mark it as "Ready for review" to request feedback. Thanks! |
There was a problem hiding this comment.
Pull request overview
Introduces a per-token-contract-type strategy registry to encapsulate EVM token deployment and pool-wiring logic, replacing scattered token-type switches across adapters/sequences and enabling reuse across pool versions.
Changes:
- Added
strategypackage (interface + singleton registry) andregistrationspackage to register known EVM token strategies at init. - Refactored v1.0.0 token deployment sequence and pool adapter role-grant logic to use the strategy registry.
- Refactored v2.0.0 token pool deployment role-grant logic to use the strategy registry and added a TIP-20 “v2.0 unsupported” guard.
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| chains/evm/deployment/v2_0_0/adapters/tokens.go | Uses strategy registry for pool role grants; adds TIP-20 guard prior to pool deployment. |
| chains/evm/deployment/v1_0_0/sequences/token.go | Replaces token-type switches/predicates with strategy registry dispatch (deploy, capabilities, admin grants). |
| chains/evm/deployment/v1_0_0/sequences/token_test.go | Updates tests to query strategy capabilities instead of removed predicate helpers. |
| chains/evm/deployment/v1_0_0/adapters/pool_adapter.go | Replaces token-type switch for pool role grants with strategy registry lookup. |
| chains/evm/deployment/v1_0_0/adapters/init.go | Adds blank import to ensure strategies are registered before adapter usage. |
| chains/evm/deployment/tokens/strategy/strategy.go | Defines the EVMTokenStrategy interface and capability flags. |
| chains/evm/deployment/tokens/strategy/registry.go | Implements singleton registry and lookup helpers for EVM strategies. |
| chains/evm/deployment/tokens/strategy/registrations/registrations.go | Registers concrete strategies for known token types (ERC20, BnM variants, TIP-20). |
| STRATEGY_REFACTOR.md | Documents motivation, design, and refactor plan/decisions. |
| .gitignore | Ignores new agent-related files. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 13 out of 13 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
chains/evm/deployment/v1_0_0/sequences/token_test.go:207
- The external-admin role assertions are currently nested under
if caps.SupportsCCIPAdmin { ... }. That means tokens which support admin roles but don’t support CCIP admin would skip the admin-role verification. Consider gating CCIP-admin checks onSupportsCCIPAdmin, but gating admin-role checks separately onSupportsAdminRole(and only checking DEFAULT_ADMIN_ROLE when the underlying contract type supports it).
caps := tokenimpl.Capabilities(tc.tokenType)
if caps.SupportsCCIPAdmin {
// Verify CCIP Admin was set correctly
t.Log(" Verifying CCIP Admin...")
onChainCCIPAdmin, err := tokenContract.GetCCIPAdmin(&bind.CallOpts{})
require.NoError(t, err, "Failed to get CCIP admin from chain")
require.Equal(t, ccipAdminAddr, onChainCCIPAdmin, "CCIP admin mismatch")
t.Logf(" On-chain CCIP admin: %s (expected: %s)", onChainCCIPAdmin.Hex(), ccipAdminAddr.Hex())
// TEST 2: Verify External Admins have the DEFAULT_ADMIN_ROLE
t.Log(" Verifying External Admin roles...")
defaultAdminRole, err := tokenContract.DEFAULTADMINROLE(&bind.CallOpts{})
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 17 out of 17 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
chains/evm/deployment/v1_0_0/sequences/token_test.go:223
- The admin-role assertions are currently gated on
caps.SupportsCCIPAdmin, but the checks inside this block verify DEFAULT_ADMIN_ROLE membership (admin-role support), not CCIP-admin support. This will skip admin-role verification for token types that support admin roles but not CCIP admin, and it also couples two independent capabilities. Split this into separate conditionals (e.g.,if caps.SupportsCCIPAdmin { ...GetCCIPAdmin... }andif caps.SupportsAdminRole { ...DEFAULT_ADMIN_ROLE/HasRole... }).
caps := tokenimpl.Capabilities(tc.tokenType)
if caps.SupportsCCIPAdmin {
// Verify CCIP Admin was set correctly
t.Log(" Verifying CCIP Admin...")
onChainCCIPAdmin, err := tokenContract.GetCCIPAdmin(&bind.CallOpts{})
require.NoError(t, err, "Failed to get CCIP admin from chain")
require.Equal(t, ccipAdminAddr, onChainCCIPAdmin, "CCIP admin mismatch")
t.Logf(" On-chain CCIP admin: %s (expected: %s)", onChainCCIPAdmin.Hex(), ccipAdminAddr.Hex())
// TEST 2: Verify External Admins have the DEFAULT_ADMIN_ROLE
t.Log(" Verifying External Admin roles...")
defaultAdminRole, err := tokenContract.DEFAULTADMINROLE(&bind.CallOpts{})
require.NoError(t, err, "Failed to get DEFAULT_ADMIN_ROLE")
t.Logf(" DEFAULT_ADMIN_ROLE: 0x%x", defaultAdminRole)
// Verify externalAdmin has the admin role
hasRole, err := tokenContract.HasRole(&bind.CallOpts{}, defaultAdminRole, common.HexToAddress(externalAdmin))
require.NoError(t, err, "Failed to check HasRole for externalAdmin")
require.True(t, hasRole, "External admin should have DEFAULT_ADMIN_ROLE")
t.Logf(" External admin (%s) has DEFAULT_ADMIN_ROLE: %v", externalAdmin, hasRole)
// Verify deployer still has the admin role (original deployer should retain role)
deployerHasRole, err := tokenContract.HasRole(&bind.CallOpts{}, defaultAdminRole, deployerAddr)
require.NoError(t, err, "Failed to check HasRole for deployer")
require.True(t, deployerHasRole, "Deployer should still have DEFAULT_ADMIN_ROLE")
t.Logf(" Deployer (%s) has DEFAULT_ADMIN_ROLE: %v", deployerAddr.Hex(), deployerHasRole)
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
core ref: 2a52a992df57d88d85e2d6d6aad393950af0944a