-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Ccip-3398 populate state initial PR #14391
Changes from 27 commits
df3df9d
9106334
65efde9
99ab4c1
2d7dc6a
e575c22
8fcec56
17460da
5a8812c
85e01a8
f133c38
54dbed8
2ea45cc
6c5abd9
a7846c4
0fa1505
9e932ec
460bccb
5267bc6
c2dddc4
55424e8
25c21ac
1684ad4
939b246
c7d6023
53b4c40
fe85444
fa3760d
dc695c9
9fda18b
145bf8f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package view | ||
|
||
import ( | ||
"github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view/types/v1_2" | ||
"github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view/types/v1_5" | ||
"github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view/types/v1_6" | ||
) | ||
|
||
type ChainView struct { | ||
TokenAdminRegistry map[string]v1_5.TokenAdminRegistryView `json:"tokenAdminRegistry,omitempty"` | ||
FeeQuoter map[string]v1_6.FeeQuoterView `json:"feeQuoter,omitempty"` | ||
NonceManager map[string]v1_6.NonceManagerView `json:"nonceManager,omitempty"` | ||
Router map[string]v1_2.RouterView `json:"router,omitempty"` | ||
RMN map[string]v1_6.RMNRemoteView `json:"rmn,omitempty"` | ||
OnRamp map[string]v1_6.OnRampView `json:"onRamp,omitempty"` | ||
} | ||
|
||
func NewChain() ChainView { | ||
return ChainView{ | ||
TokenAdminRegistry: make(map[string]v1_5.TokenAdminRegistryView), | ||
NonceManager: make(map[string]v1_6.NonceManagerView), | ||
Router: make(map[string]v1_2.RouterView), | ||
RMN: make(map[string]v1_6.RMNRemoteView), | ||
OnRamp: make(map[string]v1_6.OnRampView), | ||
FeeQuoter: make(map[string]v1_6.FeeQuoterView), | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package view | ||
|
||
type CCIPView struct { | ||
Chains map[string]ChainView `json:"chains,omitempty"` | ||
} | ||
|
||
func NewCCIPView() CCIPView { | ||
return CCIPView{ | ||
Chains: make(map[string]ChainView), | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package types | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. idk if the types directory is helping much - think we could just have
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The type directory is to avoid import cycle, We have the Contract struct getting imported into v1_2 ,v1_5 etc from parent view and then Chain struct has elements from v1_2, v1_5 in the parent view package There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see - I think it could be on the same hierarchical level though just to avoid the nesting |
||
|
||
import ( | ||
"github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
"github.com/ethereum/go-ethereum/common" | ||
) | ||
|
||
type ContractMetaData struct { | ||
TypeAndVersion string `json:"typeAndVersion,omitempty"` | ||
Address common.Address `json:"address,omitempty"` | ||
Owner common.Address `json:"owner,omitempty"` | ||
} | ||
|
||
func NewContractMetaData(tv Meta, addr common.Address) (ContractMetaData, error) { | ||
tvStr, err := tv.TypeAndVersion(nil) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these might not always exist (e.g. WETH) but we can come back to that later, can just be empty in that case |
||
if err != nil { | ||
return ContractMetaData{}, err | ||
} | ||
owner, err := tv.Owner(nil) | ||
if err != nil { | ||
return ContractMetaData{}, err | ||
} | ||
return ContractMetaData{ | ||
TypeAndVersion: tvStr, | ||
Address: addr, | ||
Owner: owner, | ||
}, nil | ||
} | ||
|
||
type Meta interface { | ||
TypeAndVersion(opts *bind.CallOpts) (string, error) | ||
Owner(opts *bind.CallOpts) (common.Address, error) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package v1_2 | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
|
||
"github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view/types" | ||
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router" | ||
) | ||
|
||
type RouterView struct { | ||
types.ContractMetaData | ||
WrappedNative common.Address `json:"wrappedNative,omitempty"` | ||
ARMProxy common.Address `json:"armProxy,omitempty"` | ||
OnRamps map[uint64]common.Address `json:"onRamps,omitempty"` // Map of DestinationChainSelectors to OnRamp Addresses | ||
OffRamps map[uint64]common.Address `json:"offRamps,omitempty"` // Map of SourceChainSelectors to a list of OffRamp Addresses | ||
} | ||
|
||
func GenerateRouterView(r *router.Router) (RouterView, error) { | ||
meta, err := types.NewContractMetaData(r, r.Address()) | ||
if err != nil { | ||
return RouterView{}, fmt.Errorf("view error to get router metadata: %w", err) | ||
} | ||
wrappedNative, err := r.GetWrappedNative(nil) | ||
if err != nil { | ||
return RouterView{}, fmt.Errorf("view error to get router wrapped native: %w", err) | ||
} | ||
armProxy, err := r.GetArmProxy(nil) | ||
if err != nil { | ||
return RouterView{}, fmt.Errorf("view error to get router arm proxy: %w", err) | ||
} | ||
onRamps := make(map[uint64]common.Address) | ||
offRamps := make(map[uint64]common.Address) | ||
offRampList, err := r.GetOffRamps(nil) | ||
if err != nil { | ||
return RouterView{}, fmt.Errorf("view error to get router offRamps: %w", err) | ||
} | ||
for _, offRamp := range offRampList { | ||
offRamps[offRamp.SourceChainSelector] = offRamp.OffRamp | ||
} | ||
for selector := range offRamps { | ||
onRamp, err := r.GetOnRamp(nil, selector) | ||
if err != nil { | ||
return RouterView{}, fmt.Errorf("view error to get router onRamp: %w", err) | ||
} | ||
onRamps[selector] = onRamp | ||
} | ||
return RouterView{ | ||
ContractMetaData: meta, | ||
WrappedNative: wrappedNative, | ||
ARMProxy: armProxy, | ||
OnRamps: onRamps, | ||
OffRamps: offRamps, | ||
}, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package v1_5 | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
|
||
"github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view/types" | ||
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/token_admin_registry" | ||
) | ||
|
||
type TokenAdminRegistryView struct { | ||
types.ContractMetaData | ||
Tokens []common.Address `json:"tokens"` | ||
} | ||
|
||
func GenerateTokenAdminRegistryView(taContract *token_admin_registry.TokenAdminRegistry) (TokenAdminRegistryView, error) { | ||
tokens, err := taContract.GetAllConfiguredTokens(nil, 0, 10) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will be an interesting problem here, there could be an unbounded number of tokens since its permissionless. We can start by just listing them all but lets add a TODO here for smarter pruning/DoS protection later. |
||
if err != nil { | ||
return TokenAdminRegistryView{}, fmt.Errorf("view error for token admin registry: %w", err) | ||
} | ||
tvMeta, err := types.NewContractMetaData(taContract, taContract.Address()) | ||
if err != nil { | ||
return TokenAdminRegistryView{}, fmt.Errorf("metadata error for token admin registry: %w", err) | ||
} | ||
return TokenAdminRegistryView{ | ||
ContractMetaData: tvMeta, | ||
Tokens: tokens, | ||
}, nil | ||
} |
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.
ultranit - we can avoid these variables and just use c.Router then if c.Router != nil {c.Router.Address()}