From 2d7dc6a161fd67f532eb71372027c7a63948a904 Mon Sep 17 00:00:00 2001 From: AnieeG Date: Tue, 10 Sep 2024 11:04:20 -0700 Subject: [PATCH 01/23] initial draft --- integration-tests/deployment/ccip/state.go | 50 ++++--------------- .../deployment/ccip/view/chain.go | 7 +++ .../deployment/ccip/view/contract_state.go | 26 ++++++++++ .../deployment/ccip/view/noncemanager.go | 10 ++++ .../deployment/ccip/view/router.go | 1 + .../deployment/ccip/view/state.go | 18 +++++++ .../ccip/view/tokenadminregistry.go | 10 ++++ 7 files changed, 81 insertions(+), 41 deletions(-) create mode 100644 integration-tests/deployment/ccip/view/chain.go create mode 100644 integration-tests/deployment/ccip/view/contract_state.go create mode 100644 integration-tests/deployment/ccip/view/noncemanager.go create mode 100644 integration-tests/deployment/ccip/view/router.go create mode 100644 integration-tests/deployment/ccip/view/state.go create mode 100644 integration-tests/deployment/ccip/view/tokenadminregistry.go diff --git a/integration-tests/deployment/ccip/state.go b/integration-tests/deployment/ccip/state.go index f129650b30b..dc60e52028a 100644 --- a/integration-tests/deployment/ccip/state.go +++ b/integration-tests/deployment/ccip/state.go @@ -10,6 +10,7 @@ import ( owner_wrappers "github.com/smartcontractkit/ccip-owner-contracts/gethwrappers" "github.com/smartcontractkit/chainlink/integration-tests/deployment" + "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/ccip_config" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/fee_quoter" @@ -60,34 +61,9 @@ type CCIPOnChainState struct { Chains map[uint64]CCIPChainState } -type CCIPSnapShot struct { - Chains map[string]Chain `json:"chains"` -} - -type Contract struct { - TypeAndVersion string `json:"typeAndVersion"` - Address common.Address `json:"address"` -} - -type TokenAdminRegistryView struct { - Contract - Tokens []common.Address `json:"tokens"` -} - -type NonceManagerView struct { - Contract - AuthorizedCallers []common.Address `json:"authorizedCallers"` -} - -type Chain struct { - // TODO: this will have to be versioned for getting state during upgrades. - TokenAdminRegistry TokenAdminRegistryView `json:"tokenAdminRegistry"` - NonceManager NonceManagerView `json:"nonceManager"` -} - -func (s CCIPOnChainState) Snapshot(chains []uint64) (CCIPSnapShot, error) { - snapshot := CCIPSnapShot{ - Chains: make(map[string]Chain), +func (s CCIPOnChainState) Snapshot(chains []uint64) (view.CCIPSnapShot, error) { + snapshot := view.CCIPSnapShot{ + Chains: make(map[string]view.Chain), } for _, chainSelector := range chains { // TODO: Need a utility for this @@ -102,7 +78,7 @@ func (s CCIPOnChainState) Snapshot(chains []uint64) (CCIPSnapShot, error) { if _, ok := s.Chains[chainSelector]; !ok { return snapshot, fmt.Errorf("chain not supported %d", chainSelector) } - var c Chain + var c view.Chain ta := s.Chains[chainSelector].TokenAdminRegistry if ta != nil { tokens, err := ta.GetAllConfiguredTokens(nil, 0, 10) @@ -113,8 +89,8 @@ func (s CCIPOnChainState) Snapshot(chains []uint64) (CCIPSnapShot, error) { if err != nil { return snapshot, err } - c.TokenAdminRegistry = TokenAdminRegistryView{ - Contract: Contract{ + c.TokenAdminRegistry = view.TokenAdminRegistry{ + Contract: view.Contract{ TypeAndVersion: tv, Address: ta.Address(), }, @@ -131,8 +107,8 @@ func (s CCIPOnChainState) Snapshot(chains []uint64) (CCIPSnapShot, error) { if err != nil { return snapshot, err } - c.NonceManager = NonceManagerView{ - Contract: Contract{ + c.NonceManager = view.NonceManager{ + Contract: view.Contract{ TypeAndVersion: tv, Address: nm.Address(), }, @@ -145,14 +121,6 @@ func (s CCIPOnChainState) Snapshot(chains []uint64) (CCIPSnapShot, error) { return snapshot, nil } -func SnapshotState(e deployment.Environment, ab deployment.AddressBook) (CCIPSnapShot, error) { - state, err := LoadOnchainState(e, ab) - if err != nil { - return CCIPSnapShot{}, err - } - return state.Snapshot(e.AllChainSelectors()) -} - func LoadOnchainState(e deployment.Environment, ab deployment.AddressBook) (CCIPOnChainState, error) { state := CCIPOnChainState{ Chains: make(map[uint64]CCIPChainState), diff --git a/integration-tests/deployment/ccip/view/chain.go b/integration-tests/deployment/ccip/view/chain.go new file mode 100644 index 00000000000..7e7ab8f0f82 --- /dev/null +++ b/integration-tests/deployment/ccip/view/chain.go @@ -0,0 +1,7 @@ +package view + +type Chain struct { + // TODO: this will have to be versioned for getting state during upgrades. + TokenAdminRegistry TokenAdminRegistry `json:"tokenAdminRegistry"` + NonceManager NonceManager `json:"nonceManager"` +} diff --git a/integration-tests/deployment/ccip/view/contract_state.go b/integration-tests/deployment/ccip/view/contract_state.go new file mode 100644 index 00000000000..7fa06481bf0 --- /dev/null +++ b/integration-tests/deployment/ccip/view/contract_state.go @@ -0,0 +1,26 @@ +package view + +import ( + "github.com/ethereum/go-ethereum/common" +) + +type ContractStatus string + +const ( + Active ContractStatus = "active" + Inactive ContractStatus = "inactive" + Decommissioning ContractStatus = "decommissioning" + Dead ContractStatus = "dead" +) + +var ContractStatusLookup = map[string]ContractStatus{ + "active": Active, + "inactive": Inactive, + "decommissioning": Decommissioning, + "dead": Dead, +} + +type Contract struct { + TypeAndVersion string `json:"typeAndVersion"` + Address common.Address `json:"address"` +} diff --git a/integration-tests/deployment/ccip/view/noncemanager.go b/integration-tests/deployment/ccip/view/noncemanager.go new file mode 100644 index 00000000000..43a678a8812 --- /dev/null +++ b/integration-tests/deployment/ccip/view/noncemanager.go @@ -0,0 +1,10 @@ +package view + +import ( + "github.com/ethereum/go-ethereum/common" +) + +type NonceManager struct { + Contract + AuthorizedCallers []common.Address `json:"authorizedCallers"` +} diff --git a/integration-tests/deployment/ccip/view/router.go b/integration-tests/deployment/ccip/view/router.go new file mode 100644 index 00000000000..ef1189a1033 --- /dev/null +++ b/integration-tests/deployment/ccip/view/router.go @@ -0,0 +1 @@ +package view diff --git a/integration-tests/deployment/ccip/view/state.go b/integration-tests/deployment/ccip/view/state.go new file mode 100644 index 00000000000..6cee7de68f7 --- /dev/null +++ b/integration-tests/deployment/ccip/view/state.go @@ -0,0 +1,18 @@ +package view + +import ( + "github.com/smartcontractkit/chainlink/integration-tests/deployment" + "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip" +) + +type CCIPSnapShot struct { + Chains map[string]Chain `json:"chains"` +} + +func SnapshotState(e deployment.Environment, ab deployment.AddressBook) (CCIPSnapShot, error) { + state, err := ccipdeployment.LoadOnchainState(e, ab) + if err != nil { + return CCIPSnapShot{}, err + } + return state.Snapshot(e.AllChainSelectors()) +} diff --git a/integration-tests/deployment/ccip/view/tokenadminregistry.go b/integration-tests/deployment/ccip/view/tokenadminregistry.go new file mode 100644 index 00000000000..1431f2dc694 --- /dev/null +++ b/integration-tests/deployment/ccip/view/tokenadminregistry.go @@ -0,0 +1,10 @@ +package view + +import ( + "github.com/ethereum/go-ethereum/common" +) + +type TokenAdminRegistry struct { + Contract + Tokens []common.Address `json:"tokens"` +} From e575c2255a6e84e92e1f0281f5dc7ee93c0c5fe0 Mon Sep 17 00:00:00 2001 From: AnieeG Date: Tue, 10 Sep 2024 11:53:22 -0700 Subject: [PATCH 02/23] individual snapshot --- integration-tests/deployment/ccip/state.go | 35 ++++--------------- .../deployment/ccip/view/chain.go | 11 ++++-- .../deployment/ccip/view/contract_state.go | 8 ++--- .../deployment/ccip/view/noncemanager.go | 30 ++++++++++++++++ .../deployment/ccip/view/state.go | 6 ++++ .../ccip/view/tokenadminregistry.go | 29 +++++++++++++++ 6 files changed, 82 insertions(+), 37 deletions(-) diff --git a/integration-tests/deployment/ccip/state.go b/integration-tests/deployment/ccip/state.go index dc60e52028a..fd8dd0e7646 100644 --- a/integration-tests/deployment/ccip/state.go +++ b/integration-tests/deployment/ccip/state.go @@ -62,9 +62,7 @@ type CCIPOnChainState struct { } func (s CCIPOnChainState) Snapshot(chains []uint64) (view.CCIPSnapShot, error) { - snapshot := view.CCIPSnapShot{ - Chains: make(map[string]view.Chain), - } + snapshot := view.NewCCIPSnapShot() for _, chainSelector := range chains { // TODO: Need a utility for this chainid, err := chainsel.ChainIdFromSelector(chainSelector) @@ -78,43 +76,22 @@ func (s CCIPOnChainState) Snapshot(chains []uint64) (view.CCIPSnapShot, error) { if _, ok := s.Chains[chainSelector]; !ok { return snapshot, fmt.Errorf("chain not supported %d", chainSelector) } - var c view.Chain + c := view.NewChain() ta := s.Chains[chainSelector].TokenAdminRegistry if ta != nil { - tokens, err := ta.GetAllConfiguredTokens(nil, 0, 10) + taSnapshot, err := view.TokenAdminRegistrySnapshot(ta) if err != nil { return snapshot, err } - tv, err := ta.TypeAndVersion(nil) - if err != nil { - return snapshot, err - } - c.TokenAdminRegistry = view.TokenAdminRegistry{ - Contract: view.Contract{ - TypeAndVersion: tv, - Address: ta.Address(), - }, - Tokens: tokens, - } + c.TokenAdminRegistry[ta.Address().Hex()] = taSnapshot } nm := s.Chains[chainSelector].NonceManager if nm != nil { - authorizedCallers, err := nm.GetAllAuthorizedCallers(nil) + nmSnapshot, err := view.NonceManagerSnapshot(nm) if err != nil { return snapshot, err } - tv, err := nm.TypeAndVersion(nil) - if err != nil { - return snapshot, err - } - c.NonceManager = view.NonceManager{ - Contract: view.Contract{ - TypeAndVersion: tv, - Address: nm.Address(), - }, - // TODO: these can be resolved using an address book - AuthorizedCallers: authorizedCallers, - } + c.NonceManager[nm.Address().Hex()] = nmSnapshot } snapshot.Chains[chainName] = c } diff --git a/integration-tests/deployment/ccip/view/chain.go b/integration-tests/deployment/ccip/view/chain.go index 7e7ab8f0f82..47f90aa873d 100644 --- a/integration-tests/deployment/ccip/view/chain.go +++ b/integration-tests/deployment/ccip/view/chain.go @@ -2,6 +2,13 @@ package view type Chain struct { // TODO: this will have to be versioned for getting state during upgrades. - TokenAdminRegistry TokenAdminRegistry `json:"tokenAdminRegistry"` - NonceManager NonceManager `json:"nonceManager"` + TokenAdminRegistry map[string]TokenAdminRegistry `json:"tokenAdminRegistry"` + NonceManager map[string]NonceManager `json:"nonceManager"` +} + +func NewChain() Chain { + return Chain{ + TokenAdminRegistry: make(map[string]TokenAdminRegistry), + NonceManager: make(map[string]NonceManager), + } } diff --git a/integration-tests/deployment/ccip/view/contract_state.go b/integration-tests/deployment/ccip/view/contract_state.go index 7fa06481bf0..32dcc00a28c 100644 --- a/integration-tests/deployment/ccip/view/contract_state.go +++ b/integration-tests/deployment/ccip/view/contract_state.go @@ -1,9 +1,5 @@ package view -import ( - "github.com/ethereum/go-ethereum/common" -) - type ContractStatus string const ( @@ -21,6 +17,6 @@ var ContractStatusLookup = map[string]ContractStatus{ } type Contract struct { - TypeAndVersion string `json:"typeAndVersion"` - Address common.Address `json:"address"` + TypeAndVersion string `json:"typeAndVersion"` + Address string `json:"address"` } diff --git a/integration-tests/deployment/ccip/view/noncemanager.go b/integration-tests/deployment/ccip/view/noncemanager.go index 43a678a8812..b8898ca84d1 100644 --- a/integration-tests/deployment/ccip/view/noncemanager.go +++ b/integration-tests/deployment/ccip/view/noncemanager.go @@ -1,6 +1,7 @@ package view import ( + "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" ) @@ -8,3 +9,32 @@ type NonceManager struct { Contract AuthorizedCallers []common.Address `json:"authorizedCallers"` } + +func (nm NonceManager) Address() common.Address { + return common.HexToAddress(nm.Contract.Address) +} + +func NonceManagerSnapshot(nm NonceManagerGetter) (NonceManager, error) { + authorizedCallers, err := nm.GetAllAuthorizedCallers(nil) + if err != nil { + return NonceManager{}, err + } + tv, err := nm.TypeAndVersion(nil) + if err != nil { + return NonceManager{}, err + } + return NonceManager{ + Contract: Contract{ + TypeAndVersion: tv, + Address: nm.Address().Hex(), + }, + // TODO: these can be resolved using an address book + AuthorizedCallers: authorizedCallers, + }, nil +} + +type NonceManagerGetter interface { + GetAllAuthorizedCallers(opts *bind.CallOpts) ([]common.Address, error) + TypeAndVersion(opts *bind.CallOpts) (string, error) + Address() common.Address +} diff --git a/integration-tests/deployment/ccip/view/state.go b/integration-tests/deployment/ccip/view/state.go index 6cee7de68f7..e027bcc5323 100644 --- a/integration-tests/deployment/ccip/view/state.go +++ b/integration-tests/deployment/ccip/view/state.go @@ -9,6 +9,12 @@ type CCIPSnapShot struct { Chains map[string]Chain `json:"chains"` } +func NewCCIPSnapShot() CCIPSnapShot { + return CCIPSnapShot{ + Chains: make(map[string]Chain), + } +} + func SnapshotState(e deployment.Environment, ab deployment.AddressBook) (CCIPSnapShot, error) { state, err := ccipdeployment.LoadOnchainState(e, ab) if err != nil { diff --git a/integration-tests/deployment/ccip/view/tokenadminregistry.go b/integration-tests/deployment/ccip/view/tokenadminregistry.go index 1431f2dc694..6f33da1e688 100644 --- a/integration-tests/deployment/ccip/view/tokenadminregistry.go +++ b/integration-tests/deployment/ccip/view/tokenadminregistry.go @@ -1,6 +1,7 @@ package view import ( + "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" ) @@ -8,3 +9,31 @@ type TokenAdminRegistry struct { Contract Tokens []common.Address `json:"tokens"` } + +func (ta TokenAdminRegistry) Address() common.Address { + return common.HexToAddress(ta.Contract.Address) +} + +func TokenAdminRegistrySnapshot(taContract TokenAdminRegistryGetter) (TokenAdminRegistry, error) { + tokens, err := taContract.GetAllConfiguredTokens(nil, 0, 10) + if err != nil { + return TokenAdminRegistry{}, err + } + tv, err := taContract.TypeAndVersion(nil) + if err != nil { + return TokenAdminRegistry{}, err + } + return TokenAdminRegistry{ + Contract: Contract{ + TypeAndVersion: tv, + Address: taContract.Address().Hex(), + }, + Tokens: tokens, + }, nil +} + +type TokenAdminRegistryGetter interface { + GetAllConfiguredTokens(opts *bind.CallOpts, startIndex uint64, maxCount uint64) ([]common.Address, error) + TypeAndVersion(opts *bind.CallOpts) (string, error) + Address() common.Address +} From 8fcec56d3a4c901b519654da83c3382a79b12c92 Mon Sep 17 00:00:00 2001 From: AnieeG Date: Tue, 10 Sep 2024 12:09:08 -0700 Subject: [PATCH 03/23] change interface name --- integration-tests/deployment/ccip/view/noncemanager.go | 4 ++-- integration-tests/deployment/ccip/view/tokenadminregistry.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/integration-tests/deployment/ccip/view/noncemanager.go b/integration-tests/deployment/ccip/view/noncemanager.go index b8898ca84d1..b7036b0e7b8 100644 --- a/integration-tests/deployment/ccip/view/noncemanager.go +++ b/integration-tests/deployment/ccip/view/noncemanager.go @@ -14,7 +14,7 @@ func (nm NonceManager) Address() common.Address { return common.HexToAddress(nm.Contract.Address) } -func NonceManagerSnapshot(nm NonceManagerGetter) (NonceManager, error) { +func NonceManagerSnapshot(nm NonceManagerReader) (NonceManager, error) { authorizedCallers, err := nm.GetAllAuthorizedCallers(nil) if err != nil { return NonceManager{}, err @@ -33,7 +33,7 @@ func NonceManagerSnapshot(nm NonceManagerGetter) (NonceManager, error) { }, nil } -type NonceManagerGetter interface { +type NonceManagerReader interface { GetAllAuthorizedCallers(opts *bind.CallOpts) ([]common.Address, error) TypeAndVersion(opts *bind.CallOpts) (string, error) Address() common.Address diff --git a/integration-tests/deployment/ccip/view/tokenadminregistry.go b/integration-tests/deployment/ccip/view/tokenadminregistry.go index 6f33da1e688..a0ae702d9f5 100644 --- a/integration-tests/deployment/ccip/view/tokenadminregistry.go +++ b/integration-tests/deployment/ccip/view/tokenadminregistry.go @@ -14,7 +14,7 @@ func (ta TokenAdminRegistry) Address() common.Address { return common.HexToAddress(ta.Contract.Address) } -func TokenAdminRegistrySnapshot(taContract TokenAdminRegistryGetter) (TokenAdminRegistry, error) { +func TokenAdminRegistrySnapshot(taContract TokenAdminRegistryReader) (TokenAdminRegistry, error) { tokens, err := taContract.GetAllConfiguredTokens(nil, 0, 10) if err != nil { return TokenAdminRegistry{}, err @@ -32,7 +32,7 @@ func TokenAdminRegistrySnapshot(taContract TokenAdminRegistryGetter) (TokenAdmin }, nil } -type TokenAdminRegistryGetter interface { +type TokenAdminRegistryReader interface { GetAllConfiguredTokens(opts *bind.CallOpts, startIndex uint64, maxCount uint64) ([]common.Address, error) TypeAndVersion(opts *bind.CallOpts) (string, error) Address() common.Address From 17460da3d2ca853f17375c0bc49762512f22ab77 Mon Sep 17 00:00:00 2001 From: AnieeG Date: Tue, 10 Sep 2024 13:24:42 -0700 Subject: [PATCH 04/23] changes --- .../ccip/contractwrappers/router1_2/router.go | 31 +++++++++++ integration-tests/deployment/ccip/state.go | 17 ++++++- .../deployment/ccip/view/contract_state.go | 1 + .../deployment/ccip/view/router.go | 51 +++++++++++++++++++ .../deployment/ccip/view/state.go | 13 ----- 5 files changed, 98 insertions(+), 15 deletions(-) create mode 100644 integration-tests/deployment/ccip/contractwrappers/router1_2/router.go diff --git a/integration-tests/deployment/ccip/contractwrappers/router1_2/router.go b/integration-tests/deployment/ccip/contractwrappers/router1_2/router.go new file mode 100644 index 00000000000..a395c816df1 --- /dev/null +++ b/integration-tests/deployment/ccip/contractwrappers/router1_2/router.go @@ -0,0 +1,31 @@ +package router1_2 + +import ( + "github.com/ethereum/go-ethereum/accounts/abi/bind" + + "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view" + "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router" +) + +type Router struct { + *router.Router +} + +func (r Router) GetOffRamps(opts *bind.CallOpts) ([]stirng, error) { + offRamps, err := r.Router.GetOffRamps(opts) + if err != nil { + return nil, err + } + converted := make([]view.RouterOffRamp, len(offRamps)) + for i, offRamp := range offRamps { + converted[i] = view.RouterOffRamp{ + SourceChainSelector: offRamp.SourceChainSelector, + OffRamp: offRamp.OffRamp, + } + } + return converted, nil +} + +func New(r *router.Router) *Router { + return &Router{r} +} diff --git a/integration-tests/deployment/ccip/state.go b/integration-tests/deployment/ccip/state.go index fd8dd0e7646..3b8eaf08177 100644 --- a/integration-tests/deployment/ccip/state.go +++ b/integration-tests/deployment/ccip/state.go @@ -10,6 +10,7 @@ import ( owner_wrappers "github.com/smartcontractkit/ccip-owner-contracts/gethwrappers" "github.com/smartcontractkit/chainlink/integration-tests/deployment" + "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/contractwrappers/router1_2" "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/ccip_config" @@ -34,7 +35,7 @@ type CCIPChainState struct { ArmProxy *rmn_proxy_contract.RMNProxyContract NonceManager *nonce_manager.NonceManager TokenAdminRegistry *token_admin_registry.TokenAdminRegistry - Router *router.Router + Router *router1_2.Router Weth9 *weth9.WETH9 RMNRemote *rmn_remote.RMNRemote // TODO: May need to support older link too @@ -77,6 +78,10 @@ func (s CCIPOnChainState) Snapshot(chains []uint64) (view.CCIPSnapShot, error) { return snapshot, fmt.Errorf("chain not supported %d", chainSelector) } c := view.NewChain() + r := s.Chains[chainSelector].Router + if r != nil { + + } ta := s.Chains[chainSelector].TokenAdminRegistry if ta != nil { taSnapshot, err := view.TokenAdminRegistrySnapshot(ta) @@ -188,7 +193,7 @@ func LoadChainState(chain deployment.Chain, addresses map[string]deployment.Type if err != nil { return state, err } - state.Router = r + state.Router = router1_2.New(r) case deployment.NewTypeAndVersion(PriceRegistry, deployment.Version1_6_0_dev).String(): pr, err := fee_quoter.NewFeeQuoter(common.HexToAddress(address), chain.Client) if err != nil { @@ -219,3 +224,11 @@ func LoadChainState(chain deployment.Chain, addresses map[string]deployment.Type } return state, nil } + +func SnapshotState(e deployment.Environment, ab deployment.AddressBook) (view.CCIPSnapShot, error) { + state, err := LoadOnchainState(e, ab) + if err != nil { + return view.CCIPSnapShot{}, err + } + return state.Snapshot(e.AllChainSelectors()) +} diff --git a/integration-tests/deployment/ccip/view/contract_state.go b/integration-tests/deployment/ccip/view/contract_state.go index 32dcc00a28c..2625da39106 100644 --- a/integration-tests/deployment/ccip/view/contract_state.go +++ b/integration-tests/deployment/ccip/view/contract_state.go @@ -9,6 +9,7 @@ const ( Dead ContractStatus = "dead" ) +// TODO : Should this denote blue-green state? var ContractStatusLookup = map[string]ContractStatus{ "active": Active, "inactive": Inactive, diff --git a/integration-tests/deployment/ccip/view/router.go b/integration-tests/deployment/ccip/view/router.go index ef1189a1033..f2158e3f921 100644 --- a/integration-tests/deployment/ccip/view/router.go +++ b/integration-tests/deployment/ccip/view/router.go @@ -1 +1,52 @@ package view + +import ( + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" +) + +type Router struct { + Contract + WrappedNative string `json:"wrappedNative"` + ARMProxy string `json:"armProxy"` + OnRamps map[uint64]string `json:"onRamps"` // Map of DestinationChainSelectors to OnRamp Addresses + OffRamps map[uint64][]string `json:"offRamps"` // Map of SourceChainSelectors to a list of OffRamp Addresses +} + +func (r Router) Address() common.Address { + return common.HexToAddress(r.Contract.Address) +} + +func RouterSnapshot(r RouterReader) (Router, error) { + wrappedNative, err := r.GetWrappedNative(nil) + if err != nil { + return Router{}, err + } + armProxy, err := r.GetArmProxy(nil) + if err != nil { + return Router{}, err + } + onRamps := make(map[uint64]string) + offRamps := make(map[uint64][]string) + offRampList, err := r.GetOffRamps(nil) + if err != nil { + return Router{}, err + } + for _, offRamp := range offRampList { + offRamps[offRamp.SourceChainSelector] = append(offRamps[offRamp.SourceChainSelector], offRamp.OffRamp.Hex()) + } + return Router{ + Contract: Contract{Address: r.Address().Hex()}, + WrappedNative: wrappedNative.Hex(), + ARMProxy: armProxy.Hex(), + OnRamps: onRamps, + OffRamps: offRamps, + }, nil +} + +type RouterReader interface { + GetOffRamps(opts *bind.CallOpts, SourceChainSelector uint64) (common.Address, error) + GetOnRamp(opts *bind.CallOpts, destChainSelector uint64) (common.Address, error) + GetWrappedNative(opts *bind.CallOpts) (common.Address, error) + GetArmProxy(opts *bind.CallOpts) (common.Address, error) +} diff --git a/integration-tests/deployment/ccip/view/state.go b/integration-tests/deployment/ccip/view/state.go index e027bcc5323..7753146c84a 100644 --- a/integration-tests/deployment/ccip/view/state.go +++ b/integration-tests/deployment/ccip/view/state.go @@ -1,10 +1,5 @@ package view -import ( - "github.com/smartcontractkit/chainlink/integration-tests/deployment" - "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip" -) - type CCIPSnapShot struct { Chains map[string]Chain `json:"chains"` } @@ -14,11 +9,3 @@ func NewCCIPSnapShot() CCIPSnapShot { Chains: make(map[string]Chain), } } - -func SnapshotState(e deployment.Environment, ab deployment.AddressBook) (CCIPSnapShot, error) { - state, err := ccipdeployment.LoadOnchainState(e, ab) - if err != nil { - return CCIPSnapShot{}, err - } - return state.Snapshot(e.AllChainSelectors()) -} From 5a8812c51c5c75220540724c95c264ab4abf54e0 Mon Sep 17 00:00:00 2001 From: AnieeG Date: Tue, 10 Sep 2024 14:23:09 -0700 Subject: [PATCH 05/23] add all destchainselectors --- .../ccip/contractwrappers/router1_2/router.go | 4 +- integration-tests/deployment/ccip/state.go | 7 ++- .../deployment/ccip/view/chain.go | 6 ++- .../deployment/ccip/view/contract_state.go | 10 +++++ .../deployment/ccip/view/noncemanager.go | 3 +- .../deployment/ccip/view/router.go | 44 +++++++++++++++---- .../ccip/view/tokenadminregistry.go | 3 +- 7 files changed, 60 insertions(+), 17 deletions(-) diff --git a/integration-tests/deployment/ccip/contractwrappers/router1_2/router.go b/integration-tests/deployment/ccip/contractwrappers/router1_2/router.go index a395c816df1..a170e1f882a 100644 --- a/integration-tests/deployment/ccip/contractwrappers/router1_2/router.go +++ b/integration-tests/deployment/ccip/contractwrappers/router1_2/router.go @@ -11,7 +11,7 @@ type Router struct { *router.Router } -func (r Router) GetOffRamps(opts *bind.CallOpts) ([]stirng, error) { +func (r Router) GetOffRamps(opts *bind.CallOpts) ([]view.RouterOffRamp, error) { offRamps, err := r.Router.GetOffRamps(opts) if err != nil { return nil, err @@ -20,7 +20,7 @@ func (r Router) GetOffRamps(opts *bind.CallOpts) ([]stirng, error) { for i, offRamp := range offRamps { converted[i] = view.RouterOffRamp{ SourceChainSelector: offRamp.SourceChainSelector, - OffRamp: offRamp.OffRamp, + OffRamp: offRamp.OffRamp.Hex(), } } return converted, nil diff --git a/integration-tests/deployment/ccip/state.go b/integration-tests/deployment/ccip/state.go index 3b8eaf08177..9b12d422b2b 100644 --- a/integration-tests/deployment/ccip/state.go +++ b/integration-tests/deployment/ccip/state.go @@ -80,7 +80,12 @@ func (s CCIPOnChainState) Snapshot(chains []uint64) (view.CCIPSnapShot, error) { c := view.NewChain() r := s.Chains[chainSelector].Router if r != nil { - + routerSnapshot, err := view.RouterSnapshot(r) + if err != nil { + return snapshot, err + } + c.Router[r.Address().Hex()] = routerSnapshot + c.DestinationChainSelectors = routerSnapshot.DestinationChainSelectors() } ta := s.Chains[chainSelector].TokenAdminRegistry if ta != nil { diff --git a/integration-tests/deployment/ccip/view/chain.go b/integration-tests/deployment/ccip/view/chain.go index 47f90aa873d..80c15cc5e91 100644 --- a/integration-tests/deployment/ccip/view/chain.go +++ b/integration-tests/deployment/ccip/view/chain.go @@ -2,8 +2,10 @@ package view type Chain struct { // TODO: this will have to be versioned for getting state during upgrades. - TokenAdminRegistry map[string]TokenAdminRegistry `json:"tokenAdminRegistry"` - NonceManager map[string]NonceManager `json:"nonceManager"` + DestinationChainSelectors []uint64 `json:"destinationChainSelectors"` + TokenAdminRegistry map[string]TokenAdminRegistry `json:"tokenAdminRegistry"` + NonceManager map[string]NonceManager `json:"nonceManager"` + Router map[string]Router `json:"router"` } func NewChain() Chain { diff --git a/integration-tests/deployment/ccip/view/contract_state.go b/integration-tests/deployment/ccip/view/contract_state.go index 2625da39106..4cda149fb1a 100644 --- a/integration-tests/deployment/ccip/view/contract_state.go +++ b/integration-tests/deployment/ccip/view/contract_state.go @@ -1,5 +1,10 @@ package view +import ( + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" +) + type ContractStatus string const ( @@ -21,3 +26,8 @@ type Contract struct { TypeAndVersion string `json:"typeAndVersion"` Address string `json:"address"` } + +type ContractState interface { + TypeAndVersion(opts *bind.CallOpts) (string, error) + Address() common.Address +} diff --git a/integration-tests/deployment/ccip/view/noncemanager.go b/integration-tests/deployment/ccip/view/noncemanager.go index b7036b0e7b8..133a3aaca45 100644 --- a/integration-tests/deployment/ccip/view/noncemanager.go +++ b/integration-tests/deployment/ccip/view/noncemanager.go @@ -35,6 +35,5 @@ func NonceManagerSnapshot(nm NonceManagerReader) (NonceManager, error) { type NonceManagerReader interface { GetAllAuthorizedCallers(opts *bind.CallOpts) ([]common.Address, error) - TypeAndVersion(opts *bind.CallOpts) (string, error) - Address() common.Address + ContractState } diff --git a/integration-tests/deployment/ccip/view/router.go b/integration-tests/deployment/ccip/view/router.go index f2158e3f921..0e5d5230e04 100644 --- a/integration-tests/deployment/ccip/view/router.go +++ b/integration-tests/deployment/ccip/view/router.go @@ -7,17 +7,29 @@ import ( type Router struct { Contract - WrappedNative string `json:"wrappedNative"` - ARMProxy string `json:"armProxy"` - OnRamps map[uint64]string `json:"onRamps"` // Map of DestinationChainSelectors to OnRamp Addresses - OffRamps map[uint64][]string `json:"offRamps"` // Map of SourceChainSelectors to a list of OffRamp Addresses + WrappedNative string `json:"wrappedNative"` + ARMProxy string `json:"armProxy"` + OnRamps map[uint64]string `json:"onRamps"` // Map of DestinationChainSelectors to OnRamp Addresses + OffRamps map[uint64]string `json:"offRamps"` // Map of SourceChainSelectors to a list of OffRamp Addresses } func (r Router) Address() common.Address { return common.HexToAddress(r.Contract.Address) } +func (r Router) DestinationChainSelectors() []uint64 { + selectors := make([]uint64, 0, len(r.OffRamps)) + for selector := range r.OffRamps { + selectors = append(selectors, selector) + } + return selectors +} + func RouterSnapshot(r RouterReader) (Router, error) { + tv, err := r.TypeAndVersion(nil) + if err != nil { + return Router{}, err + } wrappedNative, err := r.GetWrappedNative(nil) if err != nil { return Router{}, err @@ -27,16 +39,26 @@ func RouterSnapshot(r RouterReader) (Router, error) { return Router{}, err } onRamps := make(map[uint64]string) - offRamps := make(map[uint64][]string) + offRamps := make(map[uint64]string) offRampList, err := r.GetOffRamps(nil) if err != nil { return Router{}, err } for _, offRamp := range offRampList { - offRamps[offRamp.SourceChainSelector] = append(offRamps[offRamp.SourceChainSelector], offRamp.OffRamp.Hex()) + offRamps[offRamp.SourceChainSelector] = offRamp.OffRamp + } + for selector := range offRamps { + onRamp, err := r.GetOnRamp(nil, selector) + if err != nil { + return Router{}, err + } + onRamps[selector] = onRamp.Hex() } return Router{ - Contract: Contract{Address: r.Address().Hex()}, + Contract: Contract{ + Address: r.Address().Hex(), + TypeAndVersion: tv, + }, WrappedNative: wrappedNative.Hex(), ARMProxy: armProxy.Hex(), OnRamps: onRamps, @@ -44,8 +66,14 @@ func RouterSnapshot(r RouterReader) (Router, error) { }, nil } +type RouterOffRamp struct { + SourceChainSelector uint64 + OffRamp string +} + type RouterReader interface { - GetOffRamps(opts *bind.CallOpts, SourceChainSelector uint64) (common.Address, error) + ContractState + GetOffRamps(opts *bind.CallOpts) ([]RouterOffRamp, error) GetOnRamp(opts *bind.CallOpts, destChainSelector uint64) (common.Address, error) GetWrappedNative(opts *bind.CallOpts) (common.Address, error) GetArmProxy(opts *bind.CallOpts) (common.Address, error) diff --git a/integration-tests/deployment/ccip/view/tokenadminregistry.go b/integration-tests/deployment/ccip/view/tokenadminregistry.go index a0ae702d9f5..5f1472e8686 100644 --- a/integration-tests/deployment/ccip/view/tokenadminregistry.go +++ b/integration-tests/deployment/ccip/view/tokenadminregistry.go @@ -34,6 +34,5 @@ func TokenAdminRegistrySnapshot(taContract TokenAdminRegistryReader) (TokenAdmin type TokenAdminRegistryReader interface { GetAllConfiguredTokens(opts *bind.CallOpts, startIndex uint64, maxCount uint64) ([]common.Address, error) - TypeAndVersion(opts *bind.CallOpts) (string, error) - Address() common.Address + ContractState } From 85e01a8592900bfc4c47b52f05f2858383f9453f Mon Sep 17 00:00:00 2001 From: AnieeG Date: Tue, 10 Sep 2024 15:27:48 -0700 Subject: [PATCH 06/23] rmn details --- .../ccip/contractwrappers/rmn1_6/rmn.go | 36 +++++++++++++ integration-tests/deployment/ccip/state.go | 13 ++++- .../deployment/ccip/view/chain.go | 8 ++- integration-tests/deployment/ccip/view/rmn.go | 52 +++++++++++++++++++ .../deployment/ccip/view/router.go | 4 +- 5 files changed, 107 insertions(+), 6 deletions(-) create mode 100644 integration-tests/deployment/ccip/contractwrappers/rmn1_6/rmn.go create mode 100644 integration-tests/deployment/ccip/view/rmn.go diff --git a/integration-tests/deployment/ccip/contractwrappers/rmn1_6/rmn.go b/integration-tests/deployment/ccip/contractwrappers/rmn1_6/rmn.go new file mode 100644 index 00000000000..f7203eb4677 --- /dev/null +++ b/integration-tests/deployment/ccip/contractwrappers/rmn1_6/rmn.go @@ -0,0 +1,36 @@ +package rmn1_6 + +import ( + "github.com/ethereum/go-ethereum/accounts/abi/bind" + + "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view" + "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/rmn_remote" +) + +type RMN struct { + *rmn_remote.RMNRemote +} + +func (rmn *RMN) GetVersionedConfig(opts *bind.CallOpts) (view.RMNRemoteVersionedConfig, error) { + config, err := rmn.RMNRemote.GetVersionedConfig(opts) + if err != nil { + return view.RMNRemoteVersionedConfig{}, err + } + var signers []view.RMNRemoteSigner + for _, signer := range config.Config.Signers { + signers = append(signers, view.RMNRemoteSigner{ + OnchainPublicKey: signer.OnchainPublicKey.Hex(), + NodeIndex: signer.NodeIndex, + }) + } + return view.RMNRemoteVersionedConfig{ + Version: config.Version, + MinSigners: config.Config.MinSigners, + Signers: signers, + }, nil + +} + +func New(rmn *rmn_remote.RMNRemote) *RMN { + return &RMN{rmn} +} diff --git a/integration-tests/deployment/ccip/state.go b/integration-tests/deployment/ccip/state.go index 9b12d422b2b..3cc02cf0602 100644 --- a/integration-tests/deployment/ccip/state.go +++ b/integration-tests/deployment/ccip/state.go @@ -10,6 +10,7 @@ import ( owner_wrappers "github.com/smartcontractkit/ccip-owner-contracts/gethwrappers" "github.com/smartcontractkit/chainlink/integration-tests/deployment" + "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/contractwrappers/rmn1_6" "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/contractwrappers/router1_2" "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view" @@ -37,7 +38,7 @@ type CCIPChainState struct { TokenAdminRegistry *token_admin_registry.TokenAdminRegistry Router *router1_2.Router Weth9 *weth9.WETH9 - RMNRemote *rmn_remote.RMNRemote + RMNRemote *rmn1_6.RMN // TODO: May need to support older link too LinkToken *burn_mint_erc677.BurnMintERC677 // Note we only expect one of these (on the home chain) @@ -103,6 +104,14 @@ func (s CCIPOnChainState) Snapshot(chains []uint64) (view.CCIPSnapShot, error) { } c.NonceManager[nm.Address().Hex()] = nmSnapshot } + rmn := s.Chains[chainSelector].RMNRemote + if rmn != nil { + rmnSnapshot, err := view.RMNSnapshot(rmn) + if err != nil { + return snapshot, err + } + c.RMN[rmn.Address().Hex()] = rmnSnapshot + } snapshot.Chains[chainName] = c } return snapshot, nil @@ -174,7 +183,7 @@ func LoadChainState(chain deployment.Chain, addresses map[string]deployment.Type if err != nil { return state, err } - state.RMNRemote = rmnRemote + state.RMNRemote = rmn1_6.New(rmnRemote) case deployment.NewTypeAndVersion(WETH9, deployment.Version1_0_0).String(): weth9, err := weth9.NewWETH9(common.HexToAddress(address), chain.Client) if err != nil { diff --git a/integration-tests/deployment/ccip/view/chain.go b/integration-tests/deployment/ccip/view/chain.go index 80c15cc5e91..0e0a2d850e0 100644 --- a/integration-tests/deployment/ccip/view/chain.go +++ b/integration-tests/deployment/ccip/view/chain.go @@ -6,11 +6,15 @@ type Chain struct { TokenAdminRegistry map[string]TokenAdminRegistry `json:"tokenAdminRegistry"` NonceManager map[string]NonceManager `json:"nonceManager"` Router map[string]Router `json:"router"` + RMN map[string]RMN `json:"rmn"` } func NewChain() Chain { return Chain{ - TokenAdminRegistry: make(map[string]TokenAdminRegistry), - NonceManager: make(map[string]NonceManager), + DestinationChainSelectors: make([]uint64, 0), + TokenAdminRegistry: make(map[string]TokenAdminRegistry), + NonceManager: make(map[string]NonceManager), + Router: make(map[string]Router), + RMN: make(map[string]RMN), } } diff --git a/integration-tests/deployment/ccip/view/rmn.go b/integration-tests/deployment/ccip/view/rmn.go new file mode 100644 index 00000000000..4abe66509b8 --- /dev/null +++ b/integration-tests/deployment/ccip/view/rmn.go @@ -0,0 +1,52 @@ +package view + +import ( + "github.com/ethereum/go-ethereum/accounts/abi/bind" +) + +type RMN struct { + Contract + IsCursed bool `json:"isCursed"` + Config RMNRemoteVersionedConfig `json:"config"` +} + +type RMNRemoteVersionedConfig struct { + Version uint32 `json:"version"` + Signers []RMNRemoteSigner `json:"signers"` + MinSigners uint64 `json:"minSigners"` +} + +type RMNRemoteSigner struct { + OnchainPublicKey string `json:"onchain_public_key"` + NodeIndex uint64 `json:"node_index"` +} + +func RMNSnapshot(rmnReader RMNReader) (RMN, error) { + tv, err := rmnReader.TypeAndVersion(nil) + if err != nil { + return RMN{}, err + } + config, err := rmnReader.GetVersionedConfig(nil) + if err != nil { + return RMN{}, err + } + isCursed, err := rmnReader.IsCursed0(nil) + if err != nil { + return RMN{}, err + } + return RMN{ + Contract: Contract{ + Address: rmnReader.Address().Hex(), + TypeAndVersion: tv, + }, + IsCursed: isCursed, + Config: config, + }, nil +} + +type RMNReader interface { + ContractState + GetVersionedConfig(opts *bind.CallOpts) (RMNRemoteVersionedConfig, error) + IsCursed(opts *bind.CallOpts, subject [16]byte) (bool, error) + IsCursed0(opts *bind.CallOpts) (bool, error) +} diff --git a/integration-tests/deployment/ccip/view/router.go b/integration-tests/deployment/ccip/view/router.go index 0e5d5230e04..8344ce3ae99 100644 --- a/integration-tests/deployment/ccip/view/router.go +++ b/integration-tests/deployment/ccip/view/router.go @@ -67,8 +67,8 @@ func RouterSnapshot(r RouterReader) (Router, error) { } type RouterOffRamp struct { - SourceChainSelector uint64 - OffRamp string + SourceChainSelector uint64 `json:"source_chain_selector"` + OffRamp string `json:"off_ramp"` } type RouterReader interface { From f133c38c5a33acc8195229d7e4a8388a15f33723 Mon Sep 17 00:00:00 2001 From: AnieeG Date: Tue, 10 Sep 2024 15:33:30 -0700 Subject: [PATCH 07/23] more changes --- integration-tests/deployment/ccip/state.go | 77 ++++++++++++---------- 1 file changed, 43 insertions(+), 34 deletions(-) diff --git a/integration-tests/deployment/ccip/state.go b/integration-tests/deployment/ccip/state.go index 3cc02cf0602..41ad57a31f5 100644 --- a/integration-tests/deployment/ccip/state.go +++ b/integration-tests/deployment/ccip/state.go @@ -53,6 +53,44 @@ type CCIPChainState struct { Receiver *maybe_revert_message_receiver.MaybeRevertMessageReceiver } +func (c CCIPChainState) Snapshot() (view.Chain, error) { + chainView := view.NewChain() + r := c.Router + if r != nil { + routerSnapshot, err := view.RouterSnapshot(r) + if err != nil { + return chainView, err + } + chainView.Router[r.Address().Hex()] = routerSnapshot + chainView.DestinationChainSelectors = routerSnapshot.DestinationChainSelectors() + } + ta := c.TokenAdminRegistry + if ta != nil { + taSnapshot, err := view.TokenAdminRegistrySnapshot(ta) + if err != nil { + return chainView, err + } + chainView.TokenAdminRegistry[ta.Address().Hex()] = taSnapshot + } + nm := c.NonceManager + if nm != nil { + nmSnapshot, err := view.NonceManagerSnapshot(nm) + if err != nil { + return chainView, err + } + chainView.NonceManager[nm.Address().Hex()] = nmSnapshot + } + rmn := c.RMNRemote + if rmn != nil { + rmnSnapshot, err := view.RMNSnapshot(rmn) + if err != nil { + return chainView, err + } + chainView.RMN[rmn.Address().Hex()] = rmnSnapshot + } + return chainView, nil +} + // Onchain state always derivable from an address book. // Offchain state always derivable from a list of nodeIds. // Note can translate this into Go struct needed for MCMS/Docs/UI. @@ -78,41 +116,12 @@ func (s CCIPOnChainState) Snapshot(chains []uint64) (view.CCIPSnapShot, error) { if _, ok := s.Chains[chainSelector]; !ok { return snapshot, fmt.Errorf("chain not supported %d", chainSelector) } - c := view.NewChain() - r := s.Chains[chainSelector].Router - if r != nil { - routerSnapshot, err := view.RouterSnapshot(r) - if err != nil { - return snapshot, err - } - c.Router[r.Address().Hex()] = routerSnapshot - c.DestinationChainSelectors = routerSnapshot.DestinationChainSelectors() - } - ta := s.Chains[chainSelector].TokenAdminRegistry - if ta != nil { - taSnapshot, err := view.TokenAdminRegistrySnapshot(ta) - if err != nil { - return snapshot, err - } - c.TokenAdminRegistry[ta.Address().Hex()] = taSnapshot - } - nm := s.Chains[chainSelector].NonceManager - if nm != nil { - nmSnapshot, err := view.NonceManagerSnapshot(nm) - if err != nil { - return snapshot, err - } - c.NonceManager[nm.Address().Hex()] = nmSnapshot - } - rmn := s.Chains[chainSelector].RMNRemote - if rmn != nil { - rmnSnapshot, err := view.RMNSnapshot(rmn) - if err != nil { - return snapshot, err - } - c.RMN[rmn.Address().Hex()] = rmnSnapshot + chainState := s.Chains[chainSelector] + chainSnapshot, err := chainState.Snapshot() + if err != nil { + return snapshot, err } - snapshot.Chains[chainName] = c + snapshot.Chains[chainName] = chainSnapshot } return snapshot, nil } From 54dbed881ae654b6f31653c8199efbd550d3da40 Mon Sep 17 00:00:00 2001 From: AnieeG Date: Tue, 10 Sep 2024 16:05:16 -0700 Subject: [PATCH 08/23] omitempty --- .../deployment/ccip/view/chain.go | 10 ++-- .../deployment/ccip/view/contract_state.go | 4 +- .../deployment/ccip/view/feequoter.go | 53 +++++++++++++++++++ .../deployment/ccip/view/noncemanager.go | 2 +- integration-tests/deployment/ccip/view/rmn.go | 2 +- .../deployment/ccip/view/router.go | 12 ++--- .../deployment/ccip/view/state.go | 2 +- 7 files changed, 69 insertions(+), 16 deletions(-) create mode 100644 integration-tests/deployment/ccip/view/feequoter.go diff --git a/integration-tests/deployment/ccip/view/chain.go b/integration-tests/deployment/ccip/view/chain.go index 0e0a2d850e0..0e8766675f2 100644 --- a/integration-tests/deployment/ccip/view/chain.go +++ b/integration-tests/deployment/ccip/view/chain.go @@ -2,11 +2,11 @@ package view type Chain struct { // TODO: this will have to be versioned for getting state during upgrades. - DestinationChainSelectors []uint64 `json:"destinationChainSelectors"` - TokenAdminRegistry map[string]TokenAdminRegistry `json:"tokenAdminRegistry"` - NonceManager map[string]NonceManager `json:"nonceManager"` - Router map[string]Router `json:"router"` - RMN map[string]RMN `json:"rmn"` + DestinationChainSelectors []uint64 `json:"destinationChainSelectors,omitempty"` + TokenAdminRegistry map[string]TokenAdminRegistry `json:"tokenAdminRegistry,omitempty"` + NonceManager map[string]NonceManager `json:"nonceManager,omitempty"` + Router map[string]Router `json:"router,omitempty"` + RMN map[string]RMN `json:"rmn,omitempty"` } func NewChain() Chain { diff --git a/integration-tests/deployment/ccip/view/contract_state.go b/integration-tests/deployment/ccip/view/contract_state.go index 4cda149fb1a..0ff78e78d46 100644 --- a/integration-tests/deployment/ccip/view/contract_state.go +++ b/integration-tests/deployment/ccip/view/contract_state.go @@ -23,8 +23,8 @@ var ContractStatusLookup = map[string]ContractStatus{ } type Contract struct { - TypeAndVersion string `json:"typeAndVersion"` - Address string `json:"address"` + TypeAndVersion string `json:"typeAndVersion,omitempty"` + Address string `json:"address,omitempty"` } type ContractState interface { diff --git a/integration-tests/deployment/ccip/view/feequoter.go b/integration-tests/deployment/ccip/view/feequoter.go new file mode 100644 index 00000000000..7911b468c48 --- /dev/null +++ b/integration-tests/deployment/ccip/view/feequoter.go @@ -0,0 +1,53 @@ +package view + +import ( + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" +) + +type FeeQuoter struct { + Contract + AuthorizedCallers []string `json:"authorizedCallers,omitempty"` + FeeTokens []string `json:"feeTokens,omitempty"` + StaticConfig FeeQuoterStaticConfig `json:"staticConfig,omitempty"` + DestinationChainConfig map[uint64]FeeQuoterDestChainConfig `json:"destinationChainConfig,omitempty"` // Map of DestinationChainSelectors to FeeQuoterDestChainConfig +} + +type FeeQuoterStaticConfig struct { + MaxFeeJuelsPerMsg string `json:"maxFeeJuelsPerMsg,omitempty"` + LinkToken common.Address `json:"linkToken,omitempty"` + StalenessThreshold uint32 `json:"stalenessThreshold,omitempty"` +} + +type FeeQuoterDestChainConfig struct { + IsEnabled bool `json:"isEnabled,omitempty"` + MaxNumberOfTokensPerMsg uint16 `json:"maxNumberOfTokensPerMsg,omitempty"` + MaxDataBytes uint32 `json:"maxDataBytes,omitempty"` + MaxPerMsgGasLimit uint32 `json:"maxPerMsgGasLimit,omitempty"` + DestGasOverhead uint32 `json:"destGasOverhead,omitempty"` + DestGasPerPayloadByte uint16 `json:"destGasPerPayloadByte,omitempty"` + DestDataAvailabilityOverheadGas uint32 `json:"destDataAvailabilityOverheadGas,omitempty"` + DestGasPerDataAvailabilityByte uint16 `json:"destGasPerDataAvailabilityByte,omitempty"` + DestDataAvailabilityMultiplierBps uint16 `json:"destDataAvailabilityMultiplierBps,omitempty"` + DefaultTokenFeeUSDCents uint16 `json:"defaultTokenFeeUSDCents,omitempty"` + DefaultTokenDestGasOverhead uint32 `json:"defaultTokenDestGasOverhead,omitempty"` + DefaultTxGasLimit uint32 `json:"defaultTxGasLimit,omitempty"` + GasMultiplierWeiPerEth uint64 `json:"gasMultiplierWeiPerEth,omitempty"` + NetworkFeeUSDCents uint32 `json:"networkFeeUSDCents,omitempty"` + EnforceOutOfOrder bool `json:"enforceOutOfOrder,omitempty"` + ChainFamilySelector string `json:"chainFamilySelector,omitempty"` +} + +type FeeQuoterTokenPriceFeedConfig struct { + DataFeedAddress string + TokenDecimals uint8 +} + +type FeeQuoterReader interface { + ContractState + GetAllAuthorizedCallers(opts *bind.CallOpts) ([]common.Address, error) + GetFeeTokens(opts *bind.CallOpts) ([]common.Address, error) + GetStaticConfig(opts *bind.CallOpts) (FeeQuoterStaticConfig, error) + GetDestChainConfig(opts *bind.CallOpts, destChainSelector uint64) (FeeQuoterDestChainConfig, error) + GetTokenPriceFeedConfig(opts *bind.CallOpts, token common.Address) (FeeQuoterTokenPriceFeedConfig, error) +} diff --git a/integration-tests/deployment/ccip/view/noncemanager.go b/integration-tests/deployment/ccip/view/noncemanager.go index 133a3aaca45..cf2a82b1eb6 100644 --- a/integration-tests/deployment/ccip/view/noncemanager.go +++ b/integration-tests/deployment/ccip/view/noncemanager.go @@ -7,7 +7,7 @@ import ( type NonceManager struct { Contract - AuthorizedCallers []common.Address `json:"authorizedCallers"` + AuthorizedCallers []common.Address `json:"authorizedCallers,omitempty"` } func (nm NonceManager) Address() common.Address { diff --git a/integration-tests/deployment/ccip/view/rmn.go b/integration-tests/deployment/ccip/view/rmn.go index 4abe66509b8..595f8ba4585 100644 --- a/integration-tests/deployment/ccip/view/rmn.go +++ b/integration-tests/deployment/ccip/view/rmn.go @@ -7,7 +7,7 @@ import ( type RMN struct { Contract IsCursed bool `json:"isCursed"` - Config RMNRemoteVersionedConfig `json:"config"` + Config RMNRemoteVersionedConfig `json:"config,omitempty"` } type RMNRemoteVersionedConfig struct { diff --git a/integration-tests/deployment/ccip/view/router.go b/integration-tests/deployment/ccip/view/router.go index 8344ce3ae99..382df783a77 100644 --- a/integration-tests/deployment/ccip/view/router.go +++ b/integration-tests/deployment/ccip/view/router.go @@ -7,10 +7,10 @@ import ( type Router struct { Contract - WrappedNative string `json:"wrappedNative"` - ARMProxy string `json:"armProxy"` - OnRamps map[uint64]string `json:"onRamps"` // Map of DestinationChainSelectors to OnRamp Addresses - OffRamps map[uint64]string `json:"offRamps"` // Map of SourceChainSelectors to a list of OffRamp Addresses + WrappedNative string `json:"wrappedNative,omitempty"` + ARMProxy string `json:"armProxy,omitempty"` + OnRamps map[uint64]string `json:"onRamps,omitempty"` // Map of DestinationChainSelectors to OnRamp Addresses + OffRamps map[uint64]string `json:"offRamps,omitempty"` // Map of SourceChainSelectors to a list of OffRamp Addresses } func (r Router) Address() common.Address { @@ -67,8 +67,8 @@ func RouterSnapshot(r RouterReader) (Router, error) { } type RouterOffRamp struct { - SourceChainSelector uint64 `json:"source_chain_selector"` - OffRamp string `json:"off_ramp"` + SourceChainSelector uint64 `json:"sourceChainSelector"` + OffRamp string `json:"offRamp"` } type RouterReader interface { diff --git a/integration-tests/deployment/ccip/view/state.go b/integration-tests/deployment/ccip/view/state.go index 7753146c84a..f6c6ec62563 100644 --- a/integration-tests/deployment/ccip/view/state.go +++ b/integration-tests/deployment/ccip/view/state.go @@ -1,7 +1,7 @@ package view type CCIPSnapShot struct { - Chains map[string]Chain `json:"chains"` + Chains map[string]Chain `json:"chains,omitempty"` } func NewCCIPSnapShot() CCIPSnapShot { From 2ea45cc8637b291deb85e899985df397646f900e Mon Sep 17 00:00:00 2001 From: Oliver Townsend Date: Tue, 10 Sep 2024 16:12:24 -0700 Subject: [PATCH 09/23] add onRamp reader --- integration-tests/deployment/ccip/state.go | 12 ++ .../deployment/ccip/view/chain.go | 2 + .../deployment/ccip/view/onramp.go | 112 ++++++++++++++++++ 3 files changed, 126 insertions(+) create mode 100644 integration-tests/deployment/ccip/view/onramp.go diff --git a/integration-tests/deployment/ccip/state.go b/integration-tests/deployment/ccip/state.go index 41ad57a31f5..e3d09ba382b 100644 --- a/integration-tests/deployment/ccip/state.go +++ b/integration-tests/deployment/ccip/state.go @@ -88,6 +88,18 @@ func (c CCIPChainState) Snapshot() (view.Chain, error) { } chainView.RMN[rmn.Address().Hex()] = rmnSnapshot } + onRamp := c.EvmOnRampV160 + if onRamp != nil { + onRampSnapshot, err := view.OnRampSnapshot( + onRamp, + chainView.DestinationChainSelectors, + chainView.TokenAdminRegistry[ta.Address().Hex()].Tokens, + ) + if err != nil { + return chainView, err + } + chainView.OnRamp[onRamp.Address().Hex()] = onRampSnapshot + } return chainView, nil } diff --git a/integration-tests/deployment/ccip/view/chain.go b/integration-tests/deployment/ccip/view/chain.go index 0e8766675f2..cac4236e413 100644 --- a/integration-tests/deployment/ccip/view/chain.go +++ b/integration-tests/deployment/ccip/view/chain.go @@ -7,6 +7,7 @@ type Chain struct { NonceManager map[string]NonceManager `json:"nonceManager,omitempty"` Router map[string]Router `json:"router,omitempty"` RMN map[string]RMN `json:"rmn,omitempty"` + OnRamp map[string]OnRamp `json:"onRamp,omitempty"` } func NewChain() Chain { @@ -16,5 +17,6 @@ func NewChain() Chain { NonceManager: make(map[string]NonceManager), Router: make(map[string]Router), RMN: make(map[string]RMN), + OnRamp: make(map[string]OnRamp), } } diff --git a/integration-tests/deployment/ccip/view/onramp.go b/integration-tests/deployment/ccip/view/onramp.go new file mode 100644 index 00000000000..2a882c2db64 --- /dev/null +++ b/integration-tests/deployment/ccip/view/onramp.go @@ -0,0 +1,112 @@ +package view + +import ( + "fmt" + + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + + "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/onramp" +) + +type OnRamp struct { + Contract + DynamicConfig onramp.OnRampDynamicConfig `json:"dynamicConfig"` + StaticConfig onramp.OnRampStaticConfig `json:"staticConfig"` + Owner common.Address `json:"owner"` + SourceTokenToPool map[common.Address]common.Address `json:"sourceTokenToPool"` + DestChainSpecificData map[uint64]DestChainSpecificData `json:"destChainSpecificData"` +} + +type DestChainSpecificData struct { + AllowedSendersList []common.Address `json:"allowedSendersList"` + DestChainConfig onramp.GetDestChainConfig `json:"destChainConfig"` + ExpectedNextSeqNum uint64 `json:"expectedNextSeqNum"` + Router common.Address `json:"router"` +} + +type OnRampReader interface { + TypeAndVersion(opts *bind.CallOpts) (string, error) + Address() common.Address + GetAllowedSendersList(opts *bind.CallOpts, destChainSelector uint64) ([]common.Address, error) + GetDestChainConfig(opts *bind.CallOpts, destChainSelector uint64) (onramp.GetDestChainConfig, error) + GetDynamicConfig(opts *bind.CallOpts) (onramp.OnRampDynamicConfig, error) + GetExpectedNextSequenceNumber(opts *bind.CallOpts, destChainSelector uint64) (uint64, error) + GetPoolBySourceToken(opts *bind.CallOpts, arg0 uint64, sourceToken common.Address) (common.Address, error) + GetRouter(opts *bind.CallOpts, destChainSelector uint64) (common.Address, error) + GetStaticConfig(opts *bind.CallOpts) (onramp.OnRampStaticConfig, error) + Owner(opts *bind.CallOpts) (common.Address, error) +} + +func OnRampSnapshot( + onRampReader OnRampReader, + destChainSelectors []uint64, + sourceTokens []common.Address, +) (OnRamp, error) { + tv, err := onRampReader.TypeAndVersion(nil) + if err != nil { + return OnRamp{}, fmt.Errorf("failed to get type and version: %v", err) + } + + dynamicConfig, err := onRampReader.GetDynamicConfig(nil) + if err != nil { + return OnRamp{}, fmt.Errorf("failed to get dynamic config: %v", err) + } + + staticConfig, err := onRampReader.GetStaticConfig(nil) + if err != nil { + return OnRamp{}, fmt.Errorf("failed to get static config: %v", err) + } + + owner, err := onRampReader.Owner(nil) + if err != nil { + return OnRamp{}, fmt.Errorf("failed to get owner: %v", err) + } + + sourceTokenToPool := make(map[common.Address]common.Address) + for _, sourceToken := range sourceTokens { + pool, err := onRampReader.GetPoolBySourceToken(nil, 0, sourceToken) + if err != nil { + return OnRamp{}, fmt.Errorf("failed to get pool by source token: %v", err) + } + sourceTokenToPool[sourceToken] = pool + } + + destChainSpecificData := make(map[uint64]DestChainSpecificData) + for _, destChainSelector := range destChainSelectors { + allowedSendersList, err := onRampReader.GetAllowedSendersList(nil, destChainSelector) + if err != nil { + return OnRamp{}, fmt.Errorf("failed to get allowed senders list: %v", err) + } + destChainConfig, err := onRampReader.GetDestChainConfig(nil, destChainSelector) + if err != nil { + return OnRamp{}, fmt.Errorf("failed to get dest chain config: %v", err) + } + expectedNextSeqNum, err := onRampReader.GetExpectedNextSequenceNumber(nil, destChainSelector) + if err != nil { + return OnRamp{}, fmt.Errorf("failed to get expected next sequence number: %v", err) + } + router, err := onRampReader.GetRouter(nil, destChainSelector) + if err != nil { + return OnRamp{}, fmt.Errorf("failed to get router: %v", err) + } + destChainSpecificData[destChainSelector] = DestChainSpecificData{ + AllowedSendersList: allowedSendersList, + DestChainConfig: destChainConfig, + ExpectedNextSeqNum: expectedNextSeqNum, + Router: router, + } + } + + return OnRamp{ + Contract: Contract{ + TypeAndVersion: tv, + Address: onRampReader.Address().Hex(), + }, + DynamicConfig: dynamicConfig, + StaticConfig: staticConfig, + Owner: owner, + SourceTokenToPool: sourceTokenToPool, + DestChainSpecificData: destChainSpecificData, + }, nil +} From 6c5abd9fc7bbdf0b79500393b062295eb90503ff Mon Sep 17 00:00:00 2001 From: AnieeG Date: Tue, 10 Sep 2024 16:23:49 -0700 Subject: [PATCH 10/23] changes --- .../deployment/ccip/view/feequoter.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/integration-tests/deployment/ccip/view/feequoter.go b/integration-tests/deployment/ccip/view/feequoter.go index 7911b468c48..fc26c70abf6 100644 --- a/integration-tests/deployment/ccip/view/feequoter.go +++ b/integration-tests/deployment/ccip/view/feequoter.go @@ -39,8 +39,17 @@ type FeeQuoterDestChainConfig struct { } type FeeQuoterTokenPriceFeedConfig struct { - DataFeedAddress string - TokenDecimals uint8 + DataFeedAddress string `json:"dataFeedAddress,omitempty"` + TokenDecimals uint8 `json:"tokenDecimals,omitempty"` +} + +type TokenTransferFeeConfig struct { + MinFeeUSDCents uint32 `json:"minFeeUSDCents,omitempty"` + MaxFeeUSDCents uint32 `json:"maxFeeUSDCents,omitempty"` + DeciBps uint16 `json:"deciBps,omitempty"` + DestGasOverhead uint32 `json:"destGasOverhead,omitempty"` + DestBytesOverhead uint32 `json:"destBytesOverhead,omitempty"` + IsEnabled bool `json:"isEnabled,omitempty"` } type FeeQuoterReader interface { @@ -50,4 +59,5 @@ type FeeQuoterReader interface { GetStaticConfig(opts *bind.CallOpts) (FeeQuoterStaticConfig, error) GetDestChainConfig(opts *bind.CallOpts, destChainSelector uint64) (FeeQuoterDestChainConfig, error) GetTokenPriceFeedConfig(opts *bind.CallOpts, token common.Address) (FeeQuoterTokenPriceFeedConfig, error) + GetTokenTransferFeeConfig(opts *bind.CallOpts, destChainSelector uint64, token common.Address) (TokenTransferFeeConfig, error) } From 0fa1505e807bd1c9ba403bac9c5615cdd8345138 Mon Sep 17 00:00:00 2001 From: Oliver Townsend Date: Tue, 10 Sep 2024 17:20:26 -0700 Subject: [PATCH 11/23] format errors --- .../deployment/ccip/view/onramp.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/integration-tests/deployment/ccip/view/onramp.go b/integration-tests/deployment/ccip/view/onramp.go index 2a882c2db64..0deb425f72a 100644 --- a/integration-tests/deployment/ccip/view/onramp.go +++ b/integration-tests/deployment/ccip/view/onramp.go @@ -45,29 +45,29 @@ func OnRampSnapshot( ) (OnRamp, error) { tv, err := onRampReader.TypeAndVersion(nil) if err != nil { - return OnRamp{}, fmt.Errorf("failed to get type and version: %v", err) + return OnRamp{}, fmt.Errorf("failed to get type and version: %w", err) } dynamicConfig, err := onRampReader.GetDynamicConfig(nil) if err != nil { - return OnRamp{}, fmt.Errorf("failed to get dynamic config: %v", err) + return OnRamp{}, fmt.Errorf("failed to get dynamic config: %w", err) } staticConfig, err := onRampReader.GetStaticConfig(nil) if err != nil { - return OnRamp{}, fmt.Errorf("failed to get static config: %v", err) + return OnRamp{}, fmt.Errorf("failed to get static config: %w", err) } owner, err := onRampReader.Owner(nil) if err != nil { - return OnRamp{}, fmt.Errorf("failed to get owner: %v", err) + return OnRamp{}, fmt.Errorf("failed to get owner: %w", err) } sourceTokenToPool := make(map[common.Address]common.Address) for _, sourceToken := range sourceTokens { pool, err := onRampReader.GetPoolBySourceToken(nil, 0, sourceToken) if err != nil { - return OnRamp{}, fmt.Errorf("failed to get pool by source token: %v", err) + return OnRamp{}, fmt.Errorf("failed to get pool by source token: %w", err) } sourceTokenToPool[sourceToken] = pool } @@ -76,19 +76,19 @@ func OnRampSnapshot( for _, destChainSelector := range destChainSelectors { allowedSendersList, err := onRampReader.GetAllowedSendersList(nil, destChainSelector) if err != nil { - return OnRamp{}, fmt.Errorf("failed to get allowed senders list: %v", err) + return OnRamp{}, fmt.Errorf("failed to get allowed senders list: %w", err) } destChainConfig, err := onRampReader.GetDestChainConfig(nil, destChainSelector) if err != nil { - return OnRamp{}, fmt.Errorf("failed to get dest chain config: %v", err) + return OnRamp{}, fmt.Errorf("failed to get dest chain config: %w", err) } expectedNextSeqNum, err := onRampReader.GetExpectedNextSequenceNumber(nil, destChainSelector) if err != nil { - return OnRamp{}, fmt.Errorf("failed to get expected next sequence number: %v", err) + return OnRamp{}, fmt.Errorf("failed to get expected next sequence number: %w", err) } router, err := onRampReader.GetRouter(nil, destChainSelector) if err != nil { - return OnRamp{}, fmt.Errorf("failed to get router: %v", err) + return OnRamp{}, fmt.Errorf("failed to get router: %w", err) } destChainSpecificData[destChainSelector] = DestChainSpecificData{ AllowedSendersList: allowedSendersList, From 9e932ece995913c6f0ed99f5dbec8162751b96db Mon Sep 17 00:00:00 2001 From: AnieeG Date: Tue, 10 Sep 2024 17:54:31 -0700 Subject: [PATCH 12/23] add Feequoter --- .../feequoter1_6/feequoter.go | 86 +++++++++++++++++++ integration-tests/deployment/ccip/state.go | 13 ++- .../deployment/ccip/view/chain.go | 16 ++-- .../deployment/ccip/view/feequoter.go | 74 ++++++++++++++-- 4 files changed, 171 insertions(+), 18 deletions(-) create mode 100644 integration-tests/deployment/ccip/contractwrappers/feequoter1_6/feequoter.go diff --git a/integration-tests/deployment/ccip/contractwrappers/feequoter1_6/feequoter.go b/integration-tests/deployment/ccip/contractwrappers/feequoter1_6/feequoter.go new file mode 100644 index 00000000000..d3bdaa3883c --- /dev/null +++ b/integration-tests/deployment/ccip/contractwrappers/feequoter1_6/feequoter.go @@ -0,0 +1,86 @@ +package feequoter1_6 + +import ( + "fmt" + + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + + "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view" + "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/fee_quoter" +) + +type FeeQuoter struct { + *fee_quoter.FeeQuoter +} + +func New( + fq *fee_quoter.FeeQuoter, +) *FeeQuoter { + return &FeeQuoter{ + FeeQuoter: fq, + } +} + +func (fq *FeeQuoter) GetStaticConfig(opts *bind.CallOpts) (view.FeeQuoterStaticConfig, error) { + config, err := fq.FeeQuoter.GetStaticConfig(opts) + if err != nil { + return view.FeeQuoterStaticConfig{}, err + } + return view.FeeQuoterStaticConfig{ + MaxFeeJuelsPerMsg: config.MaxFeeJuelsPerMsg.String(), + LinkToken: config.LinkToken.Hex(), + StalenessThreshold: config.StalenessThreshold, + }, nil +} + +func (fq *FeeQuoter) GetDestChainConfig(opts *bind.CallOpts, destChainSelector uint64) (view.FeeQuoterDestChainConfig, error) { + config, err := fq.FeeQuoter.GetDestChainConfig(opts, destChainSelector) + if err != nil { + return view.FeeQuoterDestChainConfig{}, err + } + return view.FeeQuoterDestChainConfig{ + IsEnabled: config.IsEnabled, + MaxNumberOfTokensPerMsg: config.MaxNumberOfTokensPerMsg, + MaxDataBytes: config.MaxDataBytes, + MaxPerMsgGasLimit: config.MaxPerMsgGasLimit, + DestGasOverhead: config.DestGasOverhead, + DestGasPerPayloadByte: config.DestGasPerPayloadByte, + DestDataAvailabilityOverheadGas: config.DestDataAvailabilityOverheadGas, + DestGasPerDataAvailabilityByte: config.DestGasPerDataAvailabilityByte, + DestDataAvailabilityMultiplierBps: config.DestDataAvailabilityMultiplierBps, + DefaultTokenFeeUSDCents: config.DefaultTokenFeeUSDCents, + DefaultTokenDestGasOverhead: config.DefaultTokenDestGasOverhead, + DefaultTxGasLimit: config.DefaultTxGasLimit, + GasMultiplierWeiPerEth: config.GasMultiplierWeiPerEth, + NetworkFeeUSDCents: config.NetworkFeeUSDCents, + EnforceOutOfOrder: config.EnforceOutOfOrder, + ChainFamilySelector: fmt.Sprintf("%x", config.ChainFamilySelector), + }, nil +} + +func (fq *FeeQuoter) GetTokenPriceFeedConfig(opts *bind.CallOpts, token common.Address) (view.FeeQuoterTokenPriceFeedConfig, error) { + config, err := fq.FeeQuoter.GetTokenPriceFeedConfig(opts, token) + if err != nil { + return view.FeeQuoterTokenPriceFeedConfig{}, err + } + return view.FeeQuoterTokenPriceFeedConfig{ + DataFeedAddress: config.DataFeedAddress.Hex(), + TokenDecimals: config.TokenDecimals, + }, nil +} + +func (fq *FeeQuoter) GetTokenTransferFeeConfig(opts *bind.CallOpts, destChainSelector uint64, token common.Address) (view.FeeQuoterTokenTransferFeeConfig, error) { + config, err := fq.FeeQuoter.GetTokenTransferFeeConfig(opts, destChainSelector, token) + if err != nil { + return view.FeeQuoterTokenTransferFeeConfig{}, err + } + return view.FeeQuoterTokenTransferFeeConfig{ + MinFeeUSDCents: config.MinFeeUSDCents, + MaxFeeUSDCents: config.MaxFeeUSDCents, + DeciBps: config.DeciBps, + DestGasOverhead: config.DestGasOverhead, + DestBytesOverhead: config.DestBytesOverhead, + IsEnabled: config.IsEnabled, + }, nil +} diff --git a/integration-tests/deployment/ccip/state.go b/integration-tests/deployment/ccip/state.go index e3d09ba382b..7828725cef0 100644 --- a/integration-tests/deployment/ccip/state.go +++ b/integration-tests/deployment/ccip/state.go @@ -10,6 +10,7 @@ import ( owner_wrappers "github.com/smartcontractkit/ccip-owner-contracts/gethwrappers" "github.com/smartcontractkit/chainlink/integration-tests/deployment" + "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/contractwrappers/feequoter1_6" "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/contractwrappers/rmn1_6" "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/contractwrappers/router1_2" "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view" @@ -32,7 +33,7 @@ import ( type CCIPChainState struct { EvmOnRampV160 *onramp.OnRamp EvmOffRampV160 *offramp.OffRamp - PriceRegistry *fee_quoter.FeeQuoter + PriceRegistry *feequoter1_6.FeeQuoter ArmProxy *rmn_proxy_contract.RMNProxyContract NonceManager *nonce_manager.NonceManager TokenAdminRegistry *token_admin_registry.TokenAdminRegistry @@ -88,6 +89,14 @@ func (c CCIPChainState) Snapshot() (view.Chain, error) { } chainView.RMN[rmn.Address().Hex()] = rmnSnapshot } + fq := c.PriceRegistry + if fq != nil { + fqSnapshot, err := view.FeeQuoterSnapshot(fq, chainView.SupportedTokensByDestination) + if err != nil { + return chainView, err + } + chainView.FeeQuoter[fq.Address().Hex()] = fqSnapshot + } onRamp := c.EvmOnRampV160 if onRamp != nil { onRampSnapshot, err := view.OnRampSnapshot( @@ -234,7 +243,7 @@ func LoadChainState(chain deployment.Chain, addresses map[string]deployment.Type if err != nil { return state, err } - state.PriceRegistry = pr + state.PriceRegistry = feequoter1_6.New(pr) case deployment.NewTypeAndVersion(LinkToken, deployment.Version1_0_0).String(): lt, err := burn_mint_erc677.NewBurnMintERC677(common.HexToAddress(address), chain.Client) if err != nil { diff --git a/integration-tests/deployment/ccip/view/chain.go b/integration-tests/deployment/ccip/view/chain.go index cac4236e413..0f0be1891e2 100644 --- a/integration-tests/deployment/ccip/view/chain.go +++ b/integration-tests/deployment/ccip/view/chain.go @@ -1,13 +1,15 @@ package view type Chain struct { - // TODO: this will have to be versioned for getting state during upgrades. - DestinationChainSelectors []uint64 `json:"destinationChainSelectors,omitempty"` - TokenAdminRegistry map[string]TokenAdminRegistry `json:"tokenAdminRegistry,omitempty"` - NonceManager map[string]NonceManager `json:"nonceManager,omitempty"` - Router map[string]Router `json:"router,omitempty"` - RMN map[string]RMN `json:"rmn,omitempty"` - OnRamp map[string]OnRamp `json:"onRamp,omitempty"` + DestinationChainSelectors []uint64 `json:"destinationChainSelectors,omitempty"` + // TODO - populate supportedTokensByDestination + SupportedTokensByDestination map[uint64][]string `json:"supportedTokensByDestination,omitempty"` + TokenAdminRegistry map[string]TokenAdminRegistry `json:"tokenAdminRegistry,omitempty"` + FeeQuoter map[string]FeeQuoter `json:"feeQuoter,omitempty"` + NonceManager map[string]NonceManager `json:"nonceManager,omitempty"` + Router map[string]Router `json:"router,omitempty"` + RMN map[string]RMN `json:"rmn,omitempty"` + OnRamp map[string]OnRamp `json:"onRamp,omitempty"` } func NewChain() Chain { diff --git a/integration-tests/deployment/ccip/view/feequoter.go b/integration-tests/deployment/ccip/view/feequoter.go index fc26c70abf6..b47fd6d38fd 100644 --- a/integration-tests/deployment/ccip/view/feequoter.go +++ b/integration-tests/deployment/ccip/view/feequoter.go @@ -7,16 +7,21 @@ import ( type FeeQuoter struct { Contract - AuthorizedCallers []string `json:"authorizedCallers,omitempty"` - FeeTokens []string `json:"feeTokens,omitempty"` - StaticConfig FeeQuoterStaticConfig `json:"staticConfig,omitempty"` - DestinationChainConfig map[uint64]FeeQuoterDestChainConfig `json:"destinationChainConfig,omitempty"` // Map of DestinationChainSelectors to FeeQuoterDestChainConfig + AuthorizedCallers []string `json:"authorizedCallers,omitempty"` + FeeTokens []string `json:"feeTokens,omitempty"` + StaticConfig FeeQuoterStaticConfig `json:"staticConfig,omitempty"` + DestinationChainConfig map[uint64]DestinationConfigWithTokens `json:"DestinationConfigWithTokens,omitempty"` // Map of DestinationChainSelectors +} + +type DestinationConfigWithTokens struct { + DestChainConfig FeeQuoterDestChainConfig `json:"destChainConfig,omitempty"` + TokenPriceFeedConfig map[string]FeeQuoterTokenPriceFeedConfig `json:"tokenPriceFeedConfig,omitempty"` // Map of Token addresses to FeeQuoterTokenPriceFeedConfig } type FeeQuoterStaticConfig struct { - MaxFeeJuelsPerMsg string `json:"maxFeeJuelsPerMsg,omitempty"` - LinkToken common.Address `json:"linkToken,omitempty"` - StalenessThreshold uint32 `json:"stalenessThreshold,omitempty"` + MaxFeeJuelsPerMsg string `json:"maxFeeJuelsPerMsg,omitempty"` + LinkToken string `json:"linkToken,omitempty"` + StalenessThreshold uint32 `json:"stalenessThreshold,omitempty"` } type FeeQuoterDestChainConfig struct { @@ -43,7 +48,7 @@ type FeeQuoterTokenPriceFeedConfig struct { TokenDecimals uint8 `json:"tokenDecimals,omitempty"` } -type TokenTransferFeeConfig struct { +type FeeQuoterTokenTransferFeeConfig struct { MinFeeUSDCents uint32 `json:"minFeeUSDCents,omitempty"` MaxFeeUSDCents uint32 `json:"maxFeeUSDCents,omitempty"` DeciBps uint16 `json:"deciBps,omitempty"` @@ -52,6 +57,57 @@ type TokenTransferFeeConfig struct { IsEnabled bool `json:"isEnabled,omitempty"` } +func FeeQuoterSnapshot(reader FeeQuoterReader, tokensByDestination map[uint64][]string) (FeeQuoter, error) { + var fq FeeQuoter + tv, err := reader.TypeAndVersion(nil) + if err != nil { + return fq, err + } + fq.TypeAndVersion = tv + fq.Address = reader.Address().Hex() + authorizedCallers, err := reader.GetAllAuthorizedCallers(nil) + if err != nil { + return fq, err + } + fq.AuthorizedCallers = make([]string, 0, len(authorizedCallers)) + for _, ac := range authorizedCallers { + fq.AuthorizedCallers = append(fq.AuthorizedCallers, ac.Hex()) + } + feeTokens, err := reader.GetFeeTokens(nil) + if err != nil { + return fq, err + } + fq.FeeTokens = make([]string, 0, len(feeTokens)) + for _, ft := range feeTokens { + fq.FeeTokens = append(fq.FeeTokens, ft.Hex()) + } + staticConfig, err := reader.GetStaticConfig(nil) + if err != nil { + return fq, err + } + fq.StaticConfig = staticConfig + fq.DestinationChainConfig = make(map[uint64]DestinationConfigWithTokens) + for destChainSelector, tokens := range tokensByDestination { + destChainConfig, err := reader.GetDestChainConfig(nil, destChainSelector) + if err != nil { + return fq, err + } + tokenPriceFeedConfig := make(map[string]FeeQuoterTokenPriceFeedConfig) + for _, token := range tokens { + t, err := reader.GetTokenPriceFeedConfig(nil, common.HexToAddress(token)) + if err != nil { + return fq, err + } + tokenPriceFeedConfig[token] = t + } + fq.DestinationChainConfig[destChainSelector] = DestinationConfigWithTokens{ + DestChainConfig: destChainConfig, + TokenPriceFeedConfig: tokenPriceFeedConfig, + } + } + return fq, nil +} + type FeeQuoterReader interface { ContractState GetAllAuthorizedCallers(opts *bind.CallOpts) ([]common.Address, error) @@ -59,5 +115,5 @@ type FeeQuoterReader interface { GetStaticConfig(opts *bind.CallOpts) (FeeQuoterStaticConfig, error) GetDestChainConfig(opts *bind.CallOpts, destChainSelector uint64) (FeeQuoterDestChainConfig, error) GetTokenPriceFeedConfig(opts *bind.CallOpts, token common.Address) (FeeQuoterTokenPriceFeedConfig, error) - GetTokenTransferFeeConfig(opts *bind.CallOpts, destChainSelector uint64, token common.Address) (TokenTransferFeeConfig, error) + GetTokenTransferFeeConfig(opts *bind.CallOpts, destChainSelector uint64, token common.Address) (FeeQuoterTokenTransferFeeConfig, error) } From 5267bc6f18d5156c093feffb71fc2ce1e623cb6c Mon Sep 17 00:00:00 2001 From: AnieeG Date: Thu, 12 Sep 2024 10:28:47 -0700 Subject: [PATCH 13/23] change approach direct go-binding reference --- .../feequoter1_6/feequoter.go | 86 ------------------- .../ccip/contractwrappers/rmn1_6/rmn.go | 36 -------- .../ccip/contractwrappers/router1_2/router.go | 31 ------- integration-tests/deployment/ccip/state.go | 27 +++--- .../deployment/ccip/view/chain.go | 27 +++--- .../deployment/ccip/view/router.go | 20 +---- .../view/{ => v1_5}/tokenadminregistry.go | 17 ++-- .../ccip/view/{ => v1_6}/feequoter.go | 76 +++++++++------- .../ccip/view/{ => v1_6}/noncemanager.go | 17 ++-- .../deployment/ccip/view/{ => v1_6}/onramp.go | 23 ++--- .../ccip/view/{rmn.go => v1_6/rmnremote.go} | 31 ++++--- 11 files changed, 113 insertions(+), 278 deletions(-) delete mode 100644 integration-tests/deployment/ccip/contractwrappers/feequoter1_6/feequoter.go delete mode 100644 integration-tests/deployment/ccip/contractwrappers/rmn1_6/rmn.go delete mode 100644 integration-tests/deployment/ccip/contractwrappers/router1_2/router.go rename integration-tests/deployment/ccip/view/{ => v1_5}/tokenadminregistry.go (61%) rename integration-tests/deployment/ccip/view/{ => v1_6}/feequoter.go (59%) rename integration-tests/deployment/ccip/view/{ => v1_6}/noncemanager.go (67%) rename integration-tests/deployment/ccip/view/{ => v1_6}/onramp.go (77%) rename integration-tests/deployment/ccip/view/{rmn.go => v1_6/rmnremote.go} (54%) diff --git a/integration-tests/deployment/ccip/contractwrappers/feequoter1_6/feequoter.go b/integration-tests/deployment/ccip/contractwrappers/feequoter1_6/feequoter.go deleted file mode 100644 index d3bdaa3883c..00000000000 --- a/integration-tests/deployment/ccip/contractwrappers/feequoter1_6/feequoter.go +++ /dev/null @@ -1,86 +0,0 @@ -package feequoter1_6 - -import ( - "fmt" - - "github.com/ethereum/go-ethereum/accounts/abi/bind" - "github.com/ethereum/go-ethereum/common" - - "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view" - "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/fee_quoter" -) - -type FeeQuoter struct { - *fee_quoter.FeeQuoter -} - -func New( - fq *fee_quoter.FeeQuoter, -) *FeeQuoter { - return &FeeQuoter{ - FeeQuoter: fq, - } -} - -func (fq *FeeQuoter) GetStaticConfig(opts *bind.CallOpts) (view.FeeQuoterStaticConfig, error) { - config, err := fq.FeeQuoter.GetStaticConfig(opts) - if err != nil { - return view.FeeQuoterStaticConfig{}, err - } - return view.FeeQuoterStaticConfig{ - MaxFeeJuelsPerMsg: config.MaxFeeJuelsPerMsg.String(), - LinkToken: config.LinkToken.Hex(), - StalenessThreshold: config.StalenessThreshold, - }, nil -} - -func (fq *FeeQuoter) GetDestChainConfig(opts *bind.CallOpts, destChainSelector uint64) (view.FeeQuoterDestChainConfig, error) { - config, err := fq.FeeQuoter.GetDestChainConfig(opts, destChainSelector) - if err != nil { - return view.FeeQuoterDestChainConfig{}, err - } - return view.FeeQuoterDestChainConfig{ - IsEnabled: config.IsEnabled, - MaxNumberOfTokensPerMsg: config.MaxNumberOfTokensPerMsg, - MaxDataBytes: config.MaxDataBytes, - MaxPerMsgGasLimit: config.MaxPerMsgGasLimit, - DestGasOverhead: config.DestGasOverhead, - DestGasPerPayloadByte: config.DestGasPerPayloadByte, - DestDataAvailabilityOverheadGas: config.DestDataAvailabilityOverheadGas, - DestGasPerDataAvailabilityByte: config.DestGasPerDataAvailabilityByte, - DestDataAvailabilityMultiplierBps: config.DestDataAvailabilityMultiplierBps, - DefaultTokenFeeUSDCents: config.DefaultTokenFeeUSDCents, - DefaultTokenDestGasOverhead: config.DefaultTokenDestGasOverhead, - DefaultTxGasLimit: config.DefaultTxGasLimit, - GasMultiplierWeiPerEth: config.GasMultiplierWeiPerEth, - NetworkFeeUSDCents: config.NetworkFeeUSDCents, - EnforceOutOfOrder: config.EnforceOutOfOrder, - ChainFamilySelector: fmt.Sprintf("%x", config.ChainFamilySelector), - }, nil -} - -func (fq *FeeQuoter) GetTokenPriceFeedConfig(opts *bind.CallOpts, token common.Address) (view.FeeQuoterTokenPriceFeedConfig, error) { - config, err := fq.FeeQuoter.GetTokenPriceFeedConfig(opts, token) - if err != nil { - return view.FeeQuoterTokenPriceFeedConfig{}, err - } - return view.FeeQuoterTokenPriceFeedConfig{ - DataFeedAddress: config.DataFeedAddress.Hex(), - TokenDecimals: config.TokenDecimals, - }, nil -} - -func (fq *FeeQuoter) GetTokenTransferFeeConfig(opts *bind.CallOpts, destChainSelector uint64, token common.Address) (view.FeeQuoterTokenTransferFeeConfig, error) { - config, err := fq.FeeQuoter.GetTokenTransferFeeConfig(opts, destChainSelector, token) - if err != nil { - return view.FeeQuoterTokenTransferFeeConfig{}, err - } - return view.FeeQuoterTokenTransferFeeConfig{ - MinFeeUSDCents: config.MinFeeUSDCents, - MaxFeeUSDCents: config.MaxFeeUSDCents, - DeciBps: config.DeciBps, - DestGasOverhead: config.DestGasOverhead, - DestBytesOverhead: config.DestBytesOverhead, - IsEnabled: config.IsEnabled, - }, nil -} diff --git a/integration-tests/deployment/ccip/contractwrappers/rmn1_6/rmn.go b/integration-tests/deployment/ccip/contractwrappers/rmn1_6/rmn.go deleted file mode 100644 index f7203eb4677..00000000000 --- a/integration-tests/deployment/ccip/contractwrappers/rmn1_6/rmn.go +++ /dev/null @@ -1,36 +0,0 @@ -package rmn1_6 - -import ( - "github.com/ethereum/go-ethereum/accounts/abi/bind" - - "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view" - "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/rmn_remote" -) - -type RMN struct { - *rmn_remote.RMNRemote -} - -func (rmn *RMN) GetVersionedConfig(opts *bind.CallOpts) (view.RMNRemoteVersionedConfig, error) { - config, err := rmn.RMNRemote.GetVersionedConfig(opts) - if err != nil { - return view.RMNRemoteVersionedConfig{}, err - } - var signers []view.RMNRemoteSigner - for _, signer := range config.Config.Signers { - signers = append(signers, view.RMNRemoteSigner{ - OnchainPublicKey: signer.OnchainPublicKey.Hex(), - NodeIndex: signer.NodeIndex, - }) - } - return view.RMNRemoteVersionedConfig{ - Version: config.Version, - MinSigners: config.Config.MinSigners, - Signers: signers, - }, nil - -} - -func New(rmn *rmn_remote.RMNRemote) *RMN { - return &RMN{rmn} -} diff --git a/integration-tests/deployment/ccip/contractwrappers/router1_2/router.go b/integration-tests/deployment/ccip/contractwrappers/router1_2/router.go deleted file mode 100644 index a170e1f882a..00000000000 --- a/integration-tests/deployment/ccip/contractwrappers/router1_2/router.go +++ /dev/null @@ -1,31 +0,0 @@ -package router1_2 - -import ( - "github.com/ethereum/go-ethereum/accounts/abi/bind" - - "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view" - "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router" -) - -type Router struct { - *router.Router -} - -func (r Router) GetOffRamps(opts *bind.CallOpts) ([]view.RouterOffRamp, error) { - offRamps, err := r.Router.GetOffRamps(opts) - if err != nil { - return nil, err - } - converted := make([]view.RouterOffRamp, len(offRamps)) - for i, offRamp := range offRamps { - converted[i] = view.RouterOffRamp{ - SourceChainSelector: offRamp.SourceChainSelector, - OffRamp: offRamp.OffRamp.Hex(), - } - } - return converted, nil -} - -func New(r *router.Router) *Router { - return &Router{r} -} diff --git a/integration-tests/deployment/ccip/state.go b/integration-tests/deployment/ccip/state.go index 7828725cef0..b8f73adb736 100644 --- a/integration-tests/deployment/ccip/state.go +++ b/integration-tests/deployment/ccip/state.go @@ -10,10 +10,9 @@ import ( owner_wrappers "github.com/smartcontractkit/ccip-owner-contracts/gethwrappers" "github.com/smartcontractkit/chainlink/integration-tests/deployment" - "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/contractwrappers/feequoter1_6" - "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/contractwrappers/rmn1_6" - "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/contractwrappers/router1_2" "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view" + "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view/v1_5" + "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view/v1_6" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/ccip_config" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/fee_quoter" @@ -33,13 +32,13 @@ import ( type CCIPChainState struct { EvmOnRampV160 *onramp.OnRamp EvmOffRampV160 *offramp.OffRamp - PriceRegistry *feequoter1_6.FeeQuoter + PriceRegistry *fee_quoter.FeeQuoter ArmProxy *rmn_proxy_contract.RMNProxyContract NonceManager *nonce_manager.NonceManager TokenAdminRegistry *token_admin_registry.TokenAdminRegistry - Router *router1_2.Router + Router *router.Router Weth9 *weth9.WETH9 - RMNRemote *rmn1_6.RMN + RMNRemote *rmn_remote.RMNRemote // TODO: May need to support older link too LinkToken *burn_mint_erc677.BurnMintERC677 // Note we only expect one of these (on the home chain) @@ -67,7 +66,7 @@ func (c CCIPChainState) Snapshot() (view.Chain, error) { } ta := c.TokenAdminRegistry if ta != nil { - taSnapshot, err := view.TokenAdminRegistrySnapshot(ta) + taSnapshot, err := v1_5.TokenAdminRegistrySnapshot(ta) if err != nil { return chainView, err } @@ -75,7 +74,7 @@ func (c CCIPChainState) Snapshot() (view.Chain, error) { } nm := c.NonceManager if nm != nil { - nmSnapshot, err := view.NonceManagerSnapshot(nm) + nmSnapshot, err := v1_6.NonceManagerSnapshot(nm) if err != nil { return chainView, err } @@ -83,7 +82,7 @@ func (c CCIPChainState) Snapshot() (view.Chain, error) { } rmn := c.RMNRemote if rmn != nil { - rmnSnapshot, err := view.RMNSnapshot(rmn) + rmnSnapshot, err := v1_6.RMNSnapshot(rmn) if err != nil { return chainView, err } @@ -91,7 +90,7 @@ func (c CCIPChainState) Snapshot() (view.Chain, error) { } fq := c.PriceRegistry if fq != nil { - fqSnapshot, err := view.FeeQuoterSnapshot(fq, chainView.SupportedTokensByDestination) + fqSnapshot, err := v1_6.FeeQuoterSnapshot(fq, chainView.SupportedTokensByDestination) if err != nil { return chainView, err } @@ -99,7 +98,7 @@ func (c CCIPChainState) Snapshot() (view.Chain, error) { } onRamp := c.EvmOnRampV160 if onRamp != nil { - onRampSnapshot, err := view.OnRampSnapshot( + onRampSnapshot, err := v1_6.OnRampSnapshot( onRamp, chainView.DestinationChainSelectors, chainView.TokenAdminRegistry[ta.Address().Hex()].Tokens, @@ -213,7 +212,7 @@ func LoadChainState(chain deployment.Chain, addresses map[string]deployment.Type if err != nil { return state, err } - state.RMNRemote = rmn1_6.New(rmnRemote) + state.RMNRemote = rmnRemote case deployment.NewTypeAndVersion(WETH9, deployment.Version1_0_0).String(): weth9, err := weth9.NewWETH9(common.HexToAddress(address), chain.Client) if err != nil { @@ -237,13 +236,13 @@ func LoadChainState(chain deployment.Chain, addresses map[string]deployment.Type if err != nil { return state, err } - state.Router = router1_2.New(r) + state.Router = r case deployment.NewTypeAndVersion(PriceRegistry, deployment.Version1_6_0_dev).String(): pr, err := fee_quoter.NewFeeQuoter(common.HexToAddress(address), chain.Client) if err != nil { return state, err } - state.PriceRegistry = feequoter1_6.New(pr) + state.PriceRegistry = pr case deployment.NewTypeAndVersion(LinkToken, deployment.Version1_0_0).String(): lt, err := burn_mint_erc677.NewBurnMintERC677(common.HexToAddress(address), chain.Client) if err != nil { diff --git a/integration-tests/deployment/ccip/view/chain.go b/integration-tests/deployment/ccip/view/chain.go index 0f0be1891e2..c1e9778b37e 100644 --- a/integration-tests/deployment/ccip/view/chain.go +++ b/integration-tests/deployment/ccip/view/chain.go @@ -1,24 +1,29 @@ package view +import ( + "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view/v1_5" + "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view/v1_6" +) + type Chain struct { DestinationChainSelectors []uint64 `json:"destinationChainSelectors,omitempty"` // TODO - populate supportedTokensByDestination - SupportedTokensByDestination map[uint64][]string `json:"supportedTokensByDestination,omitempty"` - TokenAdminRegistry map[string]TokenAdminRegistry `json:"tokenAdminRegistry,omitempty"` - FeeQuoter map[string]FeeQuoter `json:"feeQuoter,omitempty"` - NonceManager map[string]NonceManager `json:"nonceManager,omitempty"` - Router map[string]Router `json:"router,omitempty"` - RMN map[string]RMN `json:"rmn,omitempty"` - OnRamp map[string]OnRamp `json:"onRamp,omitempty"` + SupportedTokensByDestination map[uint64][]string `json:"supportedTokensByDestination,omitempty"` + TokenAdminRegistry map[string]v1_5.TokenAdminRegistry `json:"tokenAdminRegistry,omitempty"` + FeeQuoter map[string]v1_6.FeeQuoter `json:"feeQuoter,omitempty"` + NonceManager map[string]v1_6.NonceManager `json:"nonceManager,omitempty"` + Router map[string]Router `json:"router,omitempty"` + RMN map[string]v1_6.RMN `json:"rmn,omitempty"` + OnRamp map[string]v1_6.OnRamp `json:"onRamp,omitempty"` } func NewChain() Chain { return Chain{ DestinationChainSelectors: make([]uint64, 0), - TokenAdminRegistry: make(map[string]TokenAdminRegistry), - NonceManager: make(map[string]NonceManager), + TokenAdminRegistry: make(map[string]v1_5.TokenAdminRegistry), + NonceManager: make(map[string]v1_6.NonceManager), Router: make(map[string]Router), - RMN: make(map[string]RMN), - OnRamp: make(map[string]OnRamp), + RMN: make(map[string]v1_6.RMN), + OnRamp: make(map[string]v1_6.OnRamp), } } diff --git a/integration-tests/deployment/ccip/view/router.go b/integration-tests/deployment/ccip/view/router.go index 382df783a77..54946fdd3e2 100644 --- a/integration-tests/deployment/ccip/view/router.go +++ b/integration-tests/deployment/ccip/view/router.go @@ -1,8 +1,9 @@ package view import ( - "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" + + "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router" ) type Router struct { @@ -25,7 +26,7 @@ func (r Router) DestinationChainSelectors() []uint64 { return selectors } -func RouterSnapshot(r RouterReader) (Router, error) { +func RouterSnapshot(r *router.Router) (Router, error) { tv, err := r.TypeAndVersion(nil) if err != nil { return Router{}, err @@ -45,7 +46,7 @@ func RouterSnapshot(r RouterReader) (Router, error) { return Router{}, err } for _, offRamp := range offRampList { - offRamps[offRamp.SourceChainSelector] = offRamp.OffRamp + offRamps[offRamp.SourceChainSelector] = offRamp.OffRamp.Hex() } for selector := range offRamps { onRamp, err := r.GetOnRamp(nil, selector) @@ -65,16 +66,3 @@ func RouterSnapshot(r RouterReader) (Router, error) { OffRamps: offRamps, }, nil } - -type RouterOffRamp struct { - SourceChainSelector uint64 `json:"sourceChainSelector"` - OffRamp string `json:"offRamp"` -} - -type RouterReader interface { - ContractState - GetOffRamps(opts *bind.CallOpts) ([]RouterOffRamp, error) - GetOnRamp(opts *bind.CallOpts, destChainSelector uint64) (common.Address, error) - GetWrappedNative(opts *bind.CallOpts) (common.Address, error) - GetArmProxy(opts *bind.CallOpts) (common.Address, error) -} diff --git a/integration-tests/deployment/ccip/view/tokenadminregistry.go b/integration-tests/deployment/ccip/view/v1_5/tokenadminregistry.go similarity index 61% rename from integration-tests/deployment/ccip/view/tokenadminregistry.go rename to integration-tests/deployment/ccip/view/v1_5/tokenadminregistry.go index 5f1472e8686..24892aab8f5 100644 --- a/integration-tests/deployment/ccip/view/tokenadminregistry.go +++ b/integration-tests/deployment/ccip/view/v1_5/tokenadminregistry.go @@ -1,12 +1,14 @@ -package view +package v1_5 import ( - "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" + + "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view" + "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/token_admin_registry" ) type TokenAdminRegistry struct { - Contract + view.Contract Tokens []common.Address `json:"tokens"` } @@ -14,7 +16,7 @@ func (ta TokenAdminRegistry) Address() common.Address { return common.HexToAddress(ta.Contract.Address) } -func TokenAdminRegistrySnapshot(taContract TokenAdminRegistryReader) (TokenAdminRegistry, error) { +func TokenAdminRegistrySnapshot(taContract *token_admin_registry.TokenAdminRegistry) (TokenAdminRegistry, error) { tokens, err := taContract.GetAllConfiguredTokens(nil, 0, 10) if err != nil { return TokenAdminRegistry{}, err @@ -24,15 +26,10 @@ func TokenAdminRegistrySnapshot(taContract TokenAdminRegistryReader) (TokenAdmin return TokenAdminRegistry{}, err } return TokenAdminRegistry{ - Contract: Contract{ + Contract: view.Contract{ TypeAndVersion: tv, Address: taContract.Address().Hex(), }, Tokens: tokens, }, nil } - -type TokenAdminRegistryReader interface { - GetAllConfiguredTokens(opts *bind.CallOpts, startIndex uint64, maxCount uint64) ([]common.Address, error) - ContractState -} diff --git a/integration-tests/deployment/ccip/view/feequoter.go b/integration-tests/deployment/ccip/view/v1_6/feequoter.go similarity index 59% rename from integration-tests/deployment/ccip/view/feequoter.go rename to integration-tests/deployment/ccip/view/v1_6/feequoter.go index b47fd6d38fd..f243f43db48 100644 --- a/integration-tests/deployment/ccip/view/feequoter.go +++ b/integration-tests/deployment/ccip/view/v1_6/feequoter.go @@ -1,12 +1,16 @@ -package view +package v1_6 import ( - "github.com/ethereum/go-ethereum/accounts/abi/bind" + "fmt" + "github.com/ethereum/go-ethereum/common" + + "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view" + "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/fee_quoter" ) type FeeQuoter struct { - Contract + view.Contract AuthorizedCallers []string `json:"authorizedCallers,omitempty"` FeeTokens []string `json:"feeTokens,omitempty"` StaticConfig FeeQuoterStaticConfig `json:"staticConfig,omitempty"` @@ -48,24 +52,15 @@ type FeeQuoterTokenPriceFeedConfig struct { TokenDecimals uint8 `json:"tokenDecimals,omitempty"` } -type FeeQuoterTokenTransferFeeConfig struct { - MinFeeUSDCents uint32 `json:"minFeeUSDCents,omitempty"` - MaxFeeUSDCents uint32 `json:"maxFeeUSDCents,omitempty"` - DeciBps uint16 `json:"deciBps,omitempty"` - DestGasOverhead uint32 `json:"destGasOverhead,omitempty"` - DestBytesOverhead uint32 `json:"destBytesOverhead,omitempty"` - IsEnabled bool `json:"isEnabled,omitempty"` -} - -func FeeQuoterSnapshot(reader FeeQuoterReader, tokensByDestination map[uint64][]string) (FeeQuoter, error) { +func FeeQuoterSnapshot(fqContract *fee_quoter.FeeQuoter, tokensByDestination map[uint64][]string) (FeeQuoter, error) { var fq FeeQuoter - tv, err := reader.TypeAndVersion(nil) + tv, err := fqContract.TypeAndVersion(nil) if err != nil { return fq, err } fq.TypeAndVersion = tv - fq.Address = reader.Address().Hex() - authorizedCallers, err := reader.GetAllAuthorizedCallers(nil) + fq.Address = fqContract.Address().Hex() + authorizedCallers, err := fqContract.GetAllAuthorizedCallers(nil) if err != nil { return fq, err } @@ -73,7 +68,7 @@ func FeeQuoterSnapshot(reader FeeQuoterReader, tokensByDestination map[uint64][] for _, ac := range authorizedCallers { fq.AuthorizedCallers = append(fq.AuthorizedCallers, ac.Hex()) } - feeTokens, err := reader.GetFeeTokens(nil) + feeTokens, err := fqContract.GetFeeTokens(nil) if err != nil { return fq, err } @@ -81,39 +76,54 @@ func FeeQuoterSnapshot(reader FeeQuoterReader, tokensByDestination map[uint64][] for _, ft := range feeTokens { fq.FeeTokens = append(fq.FeeTokens, ft.Hex()) } - staticConfig, err := reader.GetStaticConfig(nil) + staticConfig, err := fqContract.GetStaticConfig(nil) if err != nil { return fq, err } - fq.StaticConfig = staticConfig + fq.StaticConfig = FeeQuoterStaticConfig{ + MaxFeeJuelsPerMsg: staticConfig.MaxFeeJuelsPerMsg.String(), + LinkToken: staticConfig.LinkToken.Hex(), + StalenessThreshold: staticConfig.StalenessThreshold, + } fq.DestinationChainConfig = make(map[uint64]DestinationConfigWithTokens) for destChainSelector, tokens := range tokensByDestination { - destChainConfig, err := reader.GetDestChainConfig(nil, destChainSelector) + destChainConfig, err := fqContract.GetDestChainConfig(nil, destChainSelector) if err != nil { return fq, err } + d := FeeQuoterDestChainConfig{ + IsEnabled: destChainConfig.IsEnabled, + MaxNumberOfTokensPerMsg: destChainConfig.MaxNumberOfTokensPerMsg, + MaxDataBytes: destChainConfig.MaxDataBytes, + MaxPerMsgGasLimit: destChainConfig.MaxPerMsgGasLimit, + DestGasOverhead: destChainConfig.DestGasOverhead, + DestGasPerPayloadByte: destChainConfig.DestGasPerPayloadByte, + DestDataAvailabilityOverheadGas: destChainConfig.DestDataAvailabilityOverheadGas, + DestGasPerDataAvailabilityByte: destChainConfig.DestGasPerDataAvailabilityByte, + DestDataAvailabilityMultiplierBps: destChainConfig.DestDataAvailabilityMultiplierBps, + DefaultTokenFeeUSDCents: destChainConfig.DefaultTokenFeeUSDCents, + DefaultTokenDestGasOverhead: destChainConfig.DefaultTokenDestGasOverhead, + DefaultTxGasLimit: destChainConfig.DefaultTxGasLimit, + GasMultiplierWeiPerEth: destChainConfig.GasMultiplierWeiPerEth, + NetworkFeeUSDCents: destChainConfig.NetworkFeeUSDCents, + EnforceOutOfOrder: destChainConfig.EnforceOutOfOrder, + ChainFamilySelector: fmt.Sprintf("%x", destChainConfig.ChainFamilySelector), + } tokenPriceFeedConfig := make(map[string]FeeQuoterTokenPriceFeedConfig) for _, token := range tokens { - t, err := reader.GetTokenPriceFeedConfig(nil, common.HexToAddress(token)) + t, err := fqContract.GetTokenPriceFeedConfig(nil, common.HexToAddress(token)) if err != nil { return fq, err } - tokenPriceFeedConfig[token] = t + tokenPriceFeedConfig[token] = FeeQuoterTokenPriceFeedConfig{ + DataFeedAddress: t.DataFeedAddress.Hex(), + TokenDecimals: t.TokenDecimals, + } } fq.DestinationChainConfig[destChainSelector] = DestinationConfigWithTokens{ - DestChainConfig: destChainConfig, + DestChainConfig: d, TokenPriceFeedConfig: tokenPriceFeedConfig, } } return fq, nil } - -type FeeQuoterReader interface { - ContractState - GetAllAuthorizedCallers(opts *bind.CallOpts) ([]common.Address, error) - GetFeeTokens(opts *bind.CallOpts) ([]common.Address, error) - GetStaticConfig(opts *bind.CallOpts) (FeeQuoterStaticConfig, error) - GetDestChainConfig(opts *bind.CallOpts, destChainSelector uint64) (FeeQuoterDestChainConfig, error) - GetTokenPriceFeedConfig(opts *bind.CallOpts, token common.Address) (FeeQuoterTokenPriceFeedConfig, error) - GetTokenTransferFeeConfig(opts *bind.CallOpts, destChainSelector uint64, token common.Address) (FeeQuoterTokenTransferFeeConfig, error) -} diff --git a/integration-tests/deployment/ccip/view/noncemanager.go b/integration-tests/deployment/ccip/view/v1_6/noncemanager.go similarity index 67% rename from integration-tests/deployment/ccip/view/noncemanager.go rename to integration-tests/deployment/ccip/view/v1_6/noncemanager.go index cf2a82b1eb6..5b3ac2da9ab 100644 --- a/integration-tests/deployment/ccip/view/noncemanager.go +++ b/integration-tests/deployment/ccip/view/v1_6/noncemanager.go @@ -1,12 +1,14 @@ -package view +package v1_6 import ( - "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" + + "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view" + "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/nonce_manager" ) type NonceManager struct { - Contract + view.Contract AuthorizedCallers []common.Address `json:"authorizedCallers,omitempty"` } @@ -14,7 +16,7 @@ func (nm NonceManager) Address() common.Address { return common.HexToAddress(nm.Contract.Address) } -func NonceManagerSnapshot(nm NonceManagerReader) (NonceManager, error) { +func NonceManagerSnapshot(nm *nonce_manager.NonceManager) (NonceManager, error) { authorizedCallers, err := nm.GetAllAuthorizedCallers(nil) if err != nil { return NonceManager{}, err @@ -24,7 +26,7 @@ func NonceManagerSnapshot(nm NonceManagerReader) (NonceManager, error) { return NonceManager{}, err } return NonceManager{ - Contract: Contract{ + Contract: view.Contract{ TypeAndVersion: tv, Address: nm.Address().Hex(), }, @@ -32,8 +34,3 @@ func NonceManagerSnapshot(nm NonceManagerReader) (NonceManager, error) { AuthorizedCallers: authorizedCallers, }, nil } - -type NonceManagerReader interface { - GetAllAuthorizedCallers(opts *bind.CallOpts) ([]common.Address, error) - ContractState -} diff --git a/integration-tests/deployment/ccip/view/onramp.go b/integration-tests/deployment/ccip/view/v1_6/onramp.go similarity index 77% rename from integration-tests/deployment/ccip/view/onramp.go rename to integration-tests/deployment/ccip/view/v1_6/onramp.go index 0deb425f72a..4d1282bbbaa 100644 --- a/integration-tests/deployment/ccip/view/onramp.go +++ b/integration-tests/deployment/ccip/view/v1_6/onramp.go @@ -1,16 +1,16 @@ -package view +package v1_6 import ( "fmt" - "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" + "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/onramp" ) type OnRamp struct { - Contract + view.Contract DynamicConfig onramp.OnRampDynamicConfig `json:"dynamicConfig"` StaticConfig onramp.OnRampStaticConfig `json:"staticConfig"` Owner common.Address `json:"owner"` @@ -25,21 +25,8 @@ type DestChainSpecificData struct { Router common.Address `json:"router"` } -type OnRampReader interface { - TypeAndVersion(opts *bind.CallOpts) (string, error) - Address() common.Address - GetAllowedSendersList(opts *bind.CallOpts, destChainSelector uint64) ([]common.Address, error) - GetDestChainConfig(opts *bind.CallOpts, destChainSelector uint64) (onramp.GetDestChainConfig, error) - GetDynamicConfig(opts *bind.CallOpts) (onramp.OnRampDynamicConfig, error) - GetExpectedNextSequenceNumber(opts *bind.CallOpts, destChainSelector uint64) (uint64, error) - GetPoolBySourceToken(opts *bind.CallOpts, arg0 uint64, sourceToken common.Address) (common.Address, error) - GetRouter(opts *bind.CallOpts, destChainSelector uint64) (common.Address, error) - GetStaticConfig(opts *bind.CallOpts) (onramp.OnRampStaticConfig, error) - Owner(opts *bind.CallOpts) (common.Address, error) -} - func OnRampSnapshot( - onRampReader OnRampReader, + onRampReader *onramp.OnRamp, destChainSelectors []uint64, sourceTokens []common.Address, ) (OnRamp, error) { @@ -99,7 +86,7 @@ func OnRampSnapshot( } return OnRamp{ - Contract: Contract{ + Contract: view.Contract{ TypeAndVersion: tv, Address: onRampReader.Address().Hex(), }, diff --git a/integration-tests/deployment/ccip/view/rmn.go b/integration-tests/deployment/ccip/view/v1_6/rmnremote.go similarity index 54% rename from integration-tests/deployment/ccip/view/rmn.go rename to integration-tests/deployment/ccip/view/v1_6/rmnremote.go index 595f8ba4585..49469d4602e 100644 --- a/integration-tests/deployment/ccip/view/rmn.go +++ b/integration-tests/deployment/ccip/view/v1_6/rmnremote.go @@ -1,11 +1,12 @@ -package view +package v1_6 import ( - "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view" + "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/rmn_remote" ) type RMN struct { - Contract + view.Contract IsCursed bool `json:"isCursed"` Config RMNRemoteVersionedConfig `json:"config,omitempty"` } @@ -21,7 +22,7 @@ type RMNRemoteSigner struct { NodeIndex uint64 `json:"node_index"` } -func RMNSnapshot(rmnReader RMNReader) (RMN, error) { +func RMNSnapshot(rmnReader *rmn_remote.RMNRemote) (RMN, error) { tv, err := rmnReader.TypeAndVersion(nil) if err != nil { return RMN{}, err @@ -30,23 +31,27 @@ func RMNSnapshot(rmnReader RMNReader) (RMN, error) { if err != nil { return RMN{}, err } + rmnConfig := RMNRemoteVersionedConfig{ + Version: config.Version, + Signers: make([]RMNRemoteSigner, 0, len(config.Config.Signers)), + MinSigners: config.Config.MinSigners, + } + for _, signer := range config.Config.Signers { + rmnConfig.Signers = append(rmnConfig.Signers, RMNRemoteSigner{ + OnchainPublicKey: signer.OnchainPublicKey.Hex(), + NodeIndex: signer.NodeIndex, + }) + } isCursed, err := rmnReader.IsCursed0(nil) if err != nil { return RMN{}, err } return RMN{ - Contract: Contract{ + Contract: view.Contract{ Address: rmnReader.Address().Hex(), TypeAndVersion: tv, }, IsCursed: isCursed, - Config: config, + Config: rmnConfig, }, nil } - -type RMNReader interface { - ContractState - GetVersionedConfig(opts *bind.CallOpts) (RMNRemoteVersionedConfig, error) - IsCursed(opts *bind.CallOpts, subject [16]byte) (bool, error) - IsCursed0(opts *bind.CallOpts) (bool, error) -} From c2dddc43e02f2a5bda411298806e98cccb1396f8 Mon Sep 17 00:00:00 2001 From: AnieeG Date: Thu, 12 Sep 2024 10:41:54 -0700 Subject: [PATCH 14/23] fix import cycle --- integration-tests/deployment/ccip/view/router.go | 5 +++-- .../deployment/ccip/view/{ => types}/contract_state.go | 2 +- .../deployment/ccip/view/v1_5/tokenadminregistry.go | 6 +++--- integration-tests/deployment/ccip/view/v1_6/feequoter.go | 4 ++-- integration-tests/deployment/ccip/view/v1_6/noncemanager.go | 6 +++--- integration-tests/deployment/ccip/view/v1_6/onramp.go | 6 +++--- integration-tests/deployment/ccip/view/v1_6/rmnremote.go | 6 +++--- 7 files changed, 18 insertions(+), 17 deletions(-) rename integration-tests/deployment/ccip/view/{ => types}/contract_state.go (98%) diff --git a/integration-tests/deployment/ccip/view/router.go b/integration-tests/deployment/ccip/view/router.go index 54946fdd3e2..01e6fcddb39 100644 --- a/integration-tests/deployment/ccip/view/router.go +++ b/integration-tests/deployment/ccip/view/router.go @@ -3,11 +3,12 @@ package view import ( "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 Router struct { - Contract + types.Contract WrappedNative string `json:"wrappedNative,omitempty"` ARMProxy string `json:"armProxy,omitempty"` OnRamps map[uint64]string `json:"onRamps,omitempty"` // Map of DestinationChainSelectors to OnRamp Addresses @@ -56,7 +57,7 @@ func RouterSnapshot(r *router.Router) (Router, error) { onRamps[selector] = onRamp.Hex() } return Router{ - Contract: Contract{ + Contract: types.Contract{ Address: r.Address().Hex(), TypeAndVersion: tv, }, diff --git a/integration-tests/deployment/ccip/view/contract_state.go b/integration-tests/deployment/ccip/view/types/contract_state.go similarity index 98% rename from integration-tests/deployment/ccip/view/contract_state.go rename to integration-tests/deployment/ccip/view/types/contract_state.go index 0ff78e78d46..ee59d5de4ac 100644 --- a/integration-tests/deployment/ccip/view/contract_state.go +++ b/integration-tests/deployment/ccip/view/types/contract_state.go @@ -1,4 +1,4 @@ -package view +package types import ( "github.com/ethereum/go-ethereum/accounts/abi/bind" diff --git a/integration-tests/deployment/ccip/view/v1_5/tokenadminregistry.go b/integration-tests/deployment/ccip/view/v1_5/tokenadminregistry.go index 24892aab8f5..1b3f7d0b2a0 100644 --- a/integration-tests/deployment/ccip/view/v1_5/tokenadminregistry.go +++ b/integration-tests/deployment/ccip/view/v1_5/tokenadminregistry.go @@ -3,12 +3,12 @@ package v1_5 import ( "github.com/ethereum/go-ethereum/common" - "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view" + "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view/types" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/token_admin_registry" ) type TokenAdminRegistry struct { - view.Contract + types.Contract Tokens []common.Address `json:"tokens"` } @@ -26,7 +26,7 @@ func TokenAdminRegistrySnapshot(taContract *token_admin_registry.TokenAdminRegis return TokenAdminRegistry{}, err } return TokenAdminRegistry{ - Contract: view.Contract{ + Contract: types.Contract{ TypeAndVersion: tv, Address: taContract.Address().Hex(), }, diff --git a/integration-tests/deployment/ccip/view/v1_6/feequoter.go b/integration-tests/deployment/ccip/view/v1_6/feequoter.go index f243f43db48..9524436f372 100644 --- a/integration-tests/deployment/ccip/view/v1_6/feequoter.go +++ b/integration-tests/deployment/ccip/view/v1_6/feequoter.go @@ -5,12 +5,12 @@ import ( "github.com/ethereum/go-ethereum/common" - "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view" + "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view/types" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/fee_quoter" ) type FeeQuoter struct { - view.Contract + types.Contract AuthorizedCallers []string `json:"authorizedCallers,omitempty"` FeeTokens []string `json:"feeTokens,omitempty"` StaticConfig FeeQuoterStaticConfig `json:"staticConfig,omitempty"` diff --git a/integration-tests/deployment/ccip/view/v1_6/noncemanager.go b/integration-tests/deployment/ccip/view/v1_6/noncemanager.go index 5b3ac2da9ab..febf8650fd3 100644 --- a/integration-tests/deployment/ccip/view/v1_6/noncemanager.go +++ b/integration-tests/deployment/ccip/view/v1_6/noncemanager.go @@ -3,12 +3,12 @@ package v1_6 import ( "github.com/ethereum/go-ethereum/common" - "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view" + "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view/types" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/nonce_manager" ) type NonceManager struct { - view.Contract + types.Contract AuthorizedCallers []common.Address `json:"authorizedCallers,omitempty"` } @@ -26,7 +26,7 @@ func NonceManagerSnapshot(nm *nonce_manager.NonceManager) (NonceManager, error) return NonceManager{}, err } return NonceManager{ - Contract: view.Contract{ + Contract: types.Contract{ TypeAndVersion: tv, Address: nm.Address().Hex(), }, diff --git a/integration-tests/deployment/ccip/view/v1_6/onramp.go b/integration-tests/deployment/ccip/view/v1_6/onramp.go index 4d1282bbbaa..09b917cbfbd 100644 --- a/integration-tests/deployment/ccip/view/v1_6/onramp.go +++ b/integration-tests/deployment/ccip/view/v1_6/onramp.go @@ -5,12 +5,12 @@ import ( "github.com/ethereum/go-ethereum/common" - "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view" + "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view/types" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/onramp" ) type OnRamp struct { - view.Contract + types.Contract DynamicConfig onramp.OnRampDynamicConfig `json:"dynamicConfig"` StaticConfig onramp.OnRampStaticConfig `json:"staticConfig"` Owner common.Address `json:"owner"` @@ -86,7 +86,7 @@ func OnRampSnapshot( } return OnRamp{ - Contract: view.Contract{ + Contract: types.Contract{ TypeAndVersion: tv, Address: onRampReader.Address().Hex(), }, diff --git a/integration-tests/deployment/ccip/view/v1_6/rmnremote.go b/integration-tests/deployment/ccip/view/v1_6/rmnremote.go index 49469d4602e..813181aed3e 100644 --- a/integration-tests/deployment/ccip/view/v1_6/rmnremote.go +++ b/integration-tests/deployment/ccip/view/v1_6/rmnremote.go @@ -1,12 +1,12 @@ package v1_6 import ( - "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view" + "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view/types" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/rmn_remote" ) type RMN struct { - view.Contract + types.Contract IsCursed bool `json:"isCursed"` Config RMNRemoteVersionedConfig `json:"config,omitempty"` } @@ -47,7 +47,7 @@ func RMNSnapshot(rmnReader *rmn_remote.RMNRemote) (RMN, error) { return RMN{}, err } return RMN{ - Contract: view.Contract{ + Contract: types.Contract{ Address: rmnReader.Address().Hex(), TypeAndVersion: tv, }, From 55424e8e06dd1b491d25d9c4e2112cb64c1a8bf6 Mon Sep 17 00:00:00 2001 From: AnieeG Date: Thu, 12 Sep 2024 10:48:07 -0700 Subject: [PATCH 15/23] moduler --- integration-tests/deployment/ccip/state.go | 7 ++++--- integration-tests/deployment/ccip/view/chain.go | 9 +++++---- .../deployment/ccip/view/{ => types/v1_2}/router.go | 2 +- .../ccip/view/{ => types}/v1_5/tokenadminregistry.go | 0 .../deployment/ccip/view/{ => types}/v1_6/feequoter.go | 0 .../ccip/view/{ => types}/v1_6/noncemanager.go | 0 .../deployment/ccip/view/{ => types}/v1_6/onramp.go | 0 .../deployment/ccip/view/{ => types}/v1_6/rmnremote.go | 0 8 files changed, 10 insertions(+), 8 deletions(-) rename integration-tests/deployment/ccip/view/{ => types/v1_2}/router.go (99%) rename integration-tests/deployment/ccip/view/{ => types}/v1_5/tokenadminregistry.go (100%) rename integration-tests/deployment/ccip/view/{ => types}/v1_6/feequoter.go (100%) rename integration-tests/deployment/ccip/view/{ => types}/v1_6/noncemanager.go (100%) rename integration-tests/deployment/ccip/view/{ => types}/v1_6/onramp.go (100%) rename integration-tests/deployment/ccip/view/{ => types}/v1_6/rmnremote.go (100%) diff --git a/integration-tests/deployment/ccip/state.go b/integration-tests/deployment/ccip/state.go index b8f73adb736..ff0e644cdfa 100644 --- a/integration-tests/deployment/ccip/state.go +++ b/integration-tests/deployment/ccip/state.go @@ -11,8 +11,9 @@ import ( "github.com/smartcontractkit/chainlink/integration-tests/deployment" "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view" - "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view/v1_5" - "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view/v1_6" + "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" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/ccip_config" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/fee_quoter" @@ -57,7 +58,7 @@ func (c CCIPChainState) Snapshot() (view.Chain, error) { chainView := view.NewChain() r := c.Router if r != nil { - routerSnapshot, err := view.RouterSnapshot(r) + routerSnapshot, err := v1_2.RouterSnapshot(r) if err != nil { return chainView, err } diff --git a/integration-tests/deployment/ccip/view/chain.go b/integration-tests/deployment/ccip/view/chain.go index c1e9778b37e..b6d91f6efd4 100644 --- a/integration-tests/deployment/ccip/view/chain.go +++ b/integration-tests/deployment/ccip/view/chain.go @@ -1,8 +1,9 @@ package view import ( - "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view/v1_5" - "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view/v1_6" + "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 Chain struct { @@ -12,7 +13,7 @@ type Chain struct { TokenAdminRegistry map[string]v1_5.TokenAdminRegistry `json:"tokenAdminRegistry,omitempty"` FeeQuoter map[string]v1_6.FeeQuoter `json:"feeQuoter,omitempty"` NonceManager map[string]v1_6.NonceManager `json:"nonceManager,omitempty"` - Router map[string]Router `json:"router,omitempty"` + Router map[string]v1_2.Router `json:"router,omitempty"` RMN map[string]v1_6.RMN `json:"rmn,omitempty"` OnRamp map[string]v1_6.OnRamp `json:"onRamp,omitempty"` } @@ -22,7 +23,7 @@ func NewChain() Chain { DestinationChainSelectors: make([]uint64, 0), TokenAdminRegistry: make(map[string]v1_5.TokenAdminRegistry), NonceManager: make(map[string]v1_6.NonceManager), - Router: make(map[string]Router), + Router: make(map[string]v1_2.Router), RMN: make(map[string]v1_6.RMN), OnRamp: make(map[string]v1_6.OnRamp), } diff --git a/integration-tests/deployment/ccip/view/router.go b/integration-tests/deployment/ccip/view/types/v1_2/router.go similarity index 99% rename from integration-tests/deployment/ccip/view/router.go rename to integration-tests/deployment/ccip/view/types/v1_2/router.go index 01e6fcddb39..f6126bd8f50 100644 --- a/integration-tests/deployment/ccip/view/router.go +++ b/integration-tests/deployment/ccip/view/types/v1_2/router.go @@ -1,4 +1,4 @@ -package view +package v1_2 import ( "github.com/ethereum/go-ethereum/common" diff --git a/integration-tests/deployment/ccip/view/v1_5/tokenadminregistry.go b/integration-tests/deployment/ccip/view/types/v1_5/tokenadminregistry.go similarity index 100% rename from integration-tests/deployment/ccip/view/v1_5/tokenadminregistry.go rename to integration-tests/deployment/ccip/view/types/v1_5/tokenadminregistry.go diff --git a/integration-tests/deployment/ccip/view/v1_6/feequoter.go b/integration-tests/deployment/ccip/view/types/v1_6/feequoter.go similarity index 100% rename from integration-tests/deployment/ccip/view/v1_6/feequoter.go rename to integration-tests/deployment/ccip/view/types/v1_6/feequoter.go diff --git a/integration-tests/deployment/ccip/view/v1_6/noncemanager.go b/integration-tests/deployment/ccip/view/types/v1_6/noncemanager.go similarity index 100% rename from integration-tests/deployment/ccip/view/v1_6/noncemanager.go rename to integration-tests/deployment/ccip/view/types/v1_6/noncemanager.go diff --git a/integration-tests/deployment/ccip/view/v1_6/onramp.go b/integration-tests/deployment/ccip/view/types/v1_6/onramp.go similarity index 100% rename from integration-tests/deployment/ccip/view/v1_6/onramp.go rename to integration-tests/deployment/ccip/view/types/v1_6/onramp.go diff --git a/integration-tests/deployment/ccip/view/v1_6/rmnremote.go b/integration-tests/deployment/ccip/view/types/v1_6/rmnremote.go similarity index 100% rename from integration-tests/deployment/ccip/view/v1_6/rmnremote.go rename to integration-tests/deployment/ccip/view/types/v1_6/rmnremote.go From 25c21ac2e8981874dc38cee2af182a75c258d213 Mon Sep 17 00:00:00 2001 From: AnieeG Date: Thu, 12 Sep 2024 15:35:01 -0700 Subject: [PATCH 16/23] fix panic --- integration-tests/deployment/ccip/view/chain.go | 1 + 1 file changed, 1 insertion(+) diff --git a/integration-tests/deployment/ccip/view/chain.go b/integration-tests/deployment/ccip/view/chain.go index b6d91f6efd4..e3006d59cef 100644 --- a/integration-tests/deployment/ccip/view/chain.go +++ b/integration-tests/deployment/ccip/view/chain.go @@ -23,6 +23,7 @@ func NewChain() Chain { DestinationChainSelectors: make([]uint64, 0), TokenAdminRegistry: make(map[string]v1_5.TokenAdminRegistry), NonceManager: make(map[string]v1_6.NonceManager), + FeeQuoter: make(map[string]v1_6.FeeQuoter), Router: make(map[string]v1_2.Router), RMN: make(map[string]v1_6.RMN), OnRamp: make(map[string]v1_6.OnRamp), From 1684ad45d05f03f55b7f0fcecfea8ac90bfb35ea Mon Sep 17 00:00:00 2001 From: AnieeG Date: Fri, 13 Sep 2024 13:33:08 -0700 Subject: [PATCH 17/23] add interface for snapshot --- .../deployment/ccip/deploy_test.go | 2 +- integration-tests/deployment/ccip/state.go | 63 ++----- .../deployment/ccip/view/chain.go | 156 +++++++++++++++--- .../ccip/view/types/contract_state.go | 51 +++++- .../deployment/ccip/view/types/v1_2/router.go | 74 ++++----- .../view/types/v1_5/tokenadminregistry.go | 33 ++-- .../ccip/view/types/v1_6/feequoter.go | 116 +++++++++---- .../ccip/view/types/v1_6/noncemanager.go | 10 +- .../deployment/ccip/view/types/v1_6/onramp.go | 70 ++++++-- .../ccip/view/types/v1_6/rmnremote.go | 6 +- 10 files changed, 387 insertions(+), 194 deletions(-) diff --git a/integration-tests/deployment/ccip/deploy_test.go b/integration-tests/deployment/ccip/deploy_test.go index 7bc56f82f76..abcab392c45 100644 --- a/integration-tests/deployment/ccip/deploy_test.go +++ b/integration-tests/deployment/ccip/deploy_test.go @@ -33,7 +33,7 @@ func TestDeployCCIPContracts(t *testing.T) { require.NoError(t, err) state, err := LoadOnchainState(e, ab) require.NoError(t, err) - snap, err := state.Snapshot(e.AllChainSelectors()) + snap, err := state.Snapshot(e.Chains) require.NoError(t, err) // Assert expect every deployed address to be in the address book. diff --git a/integration-tests/deployment/ccip/state.go b/integration-tests/deployment/ccip/state.go index ff0e644cdfa..1be10b4ab81 100644 --- a/integration-tests/deployment/ccip/state.go +++ b/integration-tests/deployment/ccip/state.go @@ -3,6 +3,7 @@ package ccipdeployment import ( "fmt" + "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/pkg/errors" chainsel "github.com/smartcontractkit/chain-selectors" @@ -11,10 +12,6 @@ import ( "github.com/smartcontractkit/chainlink/integration-tests/deployment" "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view" - "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" - "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/ccip_config" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/fee_quoter" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/maybe_revert_message_receiver" @@ -54,62 +51,30 @@ type CCIPChainState struct { Receiver *maybe_revert_message_receiver.MaybeRevertMessageReceiver } -func (c CCIPChainState) Snapshot() (view.Chain, error) { - chainView := view.NewChain() +func (c CCIPChainState) Snapshot(chain bind.ContractBackend) (view.Chain, error) { + chainViewMeta := view.NewChainContractsMetaData() r := c.Router if r != nil { - routerSnapshot, err := v1_2.RouterSnapshot(r) + err := chainViewMeta.SetRouter(r.Address(), chain) if err != nil { - return chainView, err + return view.Chain{}, err } - chainView.Router[r.Address().Hex()] = routerSnapshot - chainView.DestinationChainSelectors = routerSnapshot.DestinationChainSelectors() } ta := c.TokenAdminRegistry if ta != nil { - taSnapshot, err := v1_5.TokenAdminRegistrySnapshot(ta) - if err != nil { - return chainView, err - } - chainView.TokenAdminRegistry[ta.Address().Hex()] = taSnapshot - } - nm := c.NonceManager - if nm != nil { - nmSnapshot, err := v1_6.NonceManagerSnapshot(nm) - if err != nil { - return chainView, err - } - chainView.NonceManager[nm.Address().Hex()] = nmSnapshot - } - rmn := c.RMNRemote - if rmn != nil { - rmnSnapshot, err := v1_6.RMNSnapshot(rmn) + err := chainViewMeta.SetTokenAdminRegistry(ta.Address(), chain) if err != nil { - return chainView, err + return view.Chain{}, err } - chainView.RMN[rmn.Address().Hex()] = rmnSnapshot } fq := c.PriceRegistry if fq != nil { - fqSnapshot, err := v1_6.FeeQuoterSnapshot(fq, chainView.SupportedTokensByDestination) - if err != nil { - return chainView, err - } - chainView.FeeQuoter[fq.Address().Hex()] = fqSnapshot - } - onRamp := c.EvmOnRampV160 - if onRamp != nil { - onRampSnapshot, err := v1_6.OnRampSnapshot( - onRamp, - chainView.DestinationChainSelectors, - chainView.TokenAdminRegistry[ta.Address().Hex()].Tokens, - ) + err := chainViewMeta.SetFeeQuoter(fq.Address(), chain) if err != nil { - return chainView, err + return view.Chain{}, err } - chainView.OnRamp[onRamp.Address().Hex()] = onRampSnapshot } - return chainView, nil + return view.NewChain(chainViewMeta, chain) } // Onchain state always derivable from an address book. @@ -122,9 +87,9 @@ type CCIPOnChainState struct { Chains map[uint64]CCIPChainState } -func (s CCIPOnChainState) Snapshot(chains []uint64) (view.CCIPSnapShot, error) { +func (s CCIPOnChainState) Snapshot(chains map[uint64]deployment.Chain) (view.CCIPSnapShot, error) { snapshot := view.NewCCIPSnapShot() - for _, chainSelector := range chains { + for chainSelector, chain := range chains { // TODO: Need a utility for this chainid, err := chainsel.ChainIdFromSelector(chainSelector) if err != nil { @@ -138,7 +103,7 @@ func (s CCIPOnChainState) Snapshot(chains []uint64) (view.CCIPSnapShot, error) { return snapshot, fmt.Errorf("chain not supported %d", chainSelector) } chainState := s.Chains[chainSelector] - chainSnapshot, err := chainState.Snapshot() + chainSnapshot, err := chainState.Snapshot(chain.Client) if err != nil { return snapshot, err } @@ -274,5 +239,5 @@ func SnapshotState(e deployment.Environment, ab deployment.AddressBook) (view.CC if err != nil { return view.CCIPSnapShot{}, err } - return state.Snapshot(e.AllChainSelectors()) + return state.Snapshot(e.Chains) } diff --git a/integration-tests/deployment/ccip/view/chain.go b/integration-tests/deployment/ccip/view/chain.go index e3006d59cef..81be58fa769 100644 --- a/integration-tests/deployment/ccip/view/chain.go +++ b/integration-tests/deployment/ccip/view/chain.go @@ -1,31 +1,147 @@ package view import ( + "fmt" + + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + + "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view/types" "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 Chain struct { - DestinationChainSelectors []uint64 `json:"destinationChainSelectors,omitempty"` - // TODO - populate supportedTokensByDestination - SupportedTokensByDestination map[uint64][]string `json:"supportedTokensByDestination,omitempty"` - TokenAdminRegistry map[string]v1_5.TokenAdminRegistry `json:"tokenAdminRegistry,omitempty"` - FeeQuoter map[string]v1_6.FeeQuoter `json:"feeQuoter,omitempty"` - NonceManager map[string]v1_6.NonceManager `json:"nonceManager,omitempty"` - Router map[string]v1_2.Router `json:"router,omitempty"` - RMN map[string]v1_6.RMN `json:"rmn,omitempty"` - OnRamp map[string]v1_6.OnRamp `json:"onRamp,omitempty"` -} - -func NewChain() Chain { - return Chain{ - DestinationChainSelectors: make([]uint64, 0), - TokenAdminRegistry: make(map[string]v1_5.TokenAdminRegistry), - NonceManager: make(map[string]v1_6.NonceManager), - FeeQuoter: make(map[string]v1_6.FeeQuoter), - Router: make(map[string]v1_2.Router), - RMN: make(map[string]v1_6.RMN), - OnRamp: make(map[string]v1_6.OnRamp), + TokenAdminRegistry map[string]types.Snapshotter `json:"tokenAdminRegistry,omitempty"` + FeeQuoter map[string]types.Snapshotter `json:"feeQuoter,omitempty"` + NonceManager map[string]types.Snapshotter `json:"nonceManager,omitempty"` + Router map[string]types.Snapshotter `json:"router,omitempty"` + RMN map[string]types.Snapshotter `json:"rmn,omitempty"` + OnRamp map[string]types.Snapshotter `json:"onRamp,omitempty"` +} + +type ChainContractsMetaData struct { + TokenAdminRegistry map[string]types.ContractMetaData `json:"tokenAdminRegistry,omitempty"` + FeeQuoter map[string]types.ContractMetaData `json:"feeQuoter,omitempty"` + NonceManager map[string]types.ContractMetaData `json:"nonceManager,omitempty"` + Router map[string]types.ContractMetaData `json:"router,omitempty"` + RMN map[string]types.ContractMetaData `json:"rmn,omitempty"` + OnRamp map[string]types.ContractMetaData `json:"onRamp,omitempty"` +} + +func (ccm *ChainContractsMetaData) SetTokenAdminRegistry(addr common.Address, client bind.ContractBackend) error { + if ccm.TokenAdminRegistry == nil { + ccm.TokenAdminRegistry = make(map[string]types.ContractMetaData) + } + ta, err := types.NewContractMetaData(addr, client) + if err != nil { + return fmt.Errorf("tokenAdminRegistry %s: %w", addr, err) + } + ccm.TokenAdminRegistry[addr.String()] = ta + return nil +} + +func (ccm *ChainContractsMetaData) SetFeeQuoter(addr common.Address, client bind.ContractBackend) error { + if ccm.FeeQuoter == nil { + ccm.FeeQuoter = make(map[string]types.ContractMetaData) + } + fq, err := types.NewContractMetaData(addr, client) + if err != nil { + return fmt.Errorf("feeQuoter %s: %w", addr, err) + } + ccm.FeeQuoter[addr.String()] = fq + return nil +} + +func (ccm *ChainContractsMetaData) SetRouter(addr common.Address, client bind.ContractBackend) error { + if ccm.Router == nil { + ccm.Router = make(map[string]types.ContractMetaData) + } + r, err := types.NewContractMetaData(addr, client) + if err != nil { + return fmt.Errorf("router %s: %w", addr, err) } + ccm.Router[addr.String()] = r + return nil + +} +func (ccm *ChainContractsMetaData) GetRouterMetas() []types.ContractMetaData { + routerMetas := make([]types.ContractMetaData, 0) + for _, meta := range ccm.Router { + routerMetas = append(routerMetas, meta) + } + return routerMetas +} + +func (ccm *ChainContractsMetaData) GetTokenAdminRegistryMetas() []types.ContractMetaData { + tokenAdminRegistryMetas := make([]types.ContractMetaData, 0) + for _, meta := range ccm.TokenAdminRegistry { + tokenAdminRegistryMetas = append(tokenAdminRegistryMetas, meta) + } + return tokenAdminRegistryMetas +} + +func NewChainContractsMetaData() *ChainContractsMetaData { + return &ChainContractsMetaData{ + TokenAdminRegistry: make(map[string]types.ContractMetaData), + FeeQuoter: make(map[string]types.ContractMetaData), + NonceManager: make(map[string]types.ContractMetaData), + Router: make(map[string]types.ContractMetaData), + RMN: make(map[string]types.ContractMetaData), + OnRamp: make(map[string]types.ContractMetaData), + } +} + +func NewChain(chainContractsMeta *ChainContractsMetaData, client bind.ContractBackend) (Chain, error) { + var chain Chain + for addr, tv := range chainContractsMeta.Router { + switch tv.TypeAndVersion { + case types.RouterTypeAndVersionV1_2: + if chain.Router == nil { + chain.Router = make(map[string]types.Snapshotter) + } + r := &v1_2.Router{} + err := r.Snapshot(tv, nil, client) + if err != nil { + return Chain{}, err + } + chain.Router[addr] = r + } + } + for addr, tv := range chainContractsMeta.TokenAdminRegistry { + switch tv.TypeAndVersion { + case types.TokenAdminRegistryTypeAndVersionV1_5: + if chain.TokenAdminRegistry == nil { + chain.TokenAdminRegistry = make(map[string]types.Snapshotter) + } + ta := &v1_5.TokenAdminRegistry{} + err := ta.Snapshot(tv, nil, client) + if err != nil { + return Chain{}, err + } + chain.TokenAdminRegistry[addr] = ta + } + } + for addr, tv := range chainContractsMeta.FeeQuoter { + chainContractsMeta.FeeQuoter[addr] = types.ContractMetaData{ + TypeAndVersion: tv.TypeAndVersion, + Address: tv.Address, + } + switch tv.TypeAndVersion { + case types.FEEQuoterTypeAndVersionV1_6: + if chain.FeeQuoter == nil { + chain.FeeQuoter = make(map[string]types.Snapshotter) + } + fq := &v1_6.FeeQuoter{} + dependencies := append(chainContractsMeta.GetRouterMetas(), chainContractsMeta.GetTokenAdminRegistryMetas()...) + err := fq.Snapshot(tv, dependencies, client) + if err != nil { + return Chain{}, err + } + chain.FeeQuoter[addr] = fq + } + } + + return chain, nil } diff --git a/integration-tests/deployment/ccip/view/types/contract_state.go b/integration-tests/deployment/ccip/view/types/contract_state.go index ee59d5de4ac..725ea9ff9f5 100644 --- a/integration-tests/deployment/ccip/view/types/contract_state.go +++ b/integration-tests/deployment/ccip/view/types/contract_state.go @@ -1,8 +1,12 @@ package types import ( + "fmt" + "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" + + type_and_version "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/type_and_version_interface_wrapper" ) type ContractStatus string @@ -22,12 +26,47 @@ var ContractStatusLookup = map[string]ContractStatus{ "dead": Dead, } -type Contract struct { - TypeAndVersion string `json:"typeAndVersion,omitempty"` - Address string `json:"address,omitempty"` +const ( + RouterTypeAndVersionV1_2 = "Router 1.2.0" + TokenAdminRegistryTypeAndVersionV1_5 = "TokenAdminRegistry 1.5.0" + FEEQuoterTypeAndVersionV1_6 = "FeeQuoter 1.6.0-dev" +) + +type ContractMetaData struct { + TypeAndVersion string `json:"typeAndVersion,omitempty"` + Address common.Address `json:"address,omitempty"` + Owner common.Address `json:"owner,omitempty"` +} + +func (c *ContractMetaData) SetOwner(owner common.Address) { + c.Owner = owner +} + +func (c *ContractMetaData) Validate() error { + if c.TypeAndVersion == "" { + return fmt.Errorf("type and version is required") + } + if c.Address == (common.Address{}) { + return fmt.Errorf("address is required") + } + return nil +} + +func NewContractMetaData(address common.Address, client bind.ContractBackend) (ContractMetaData, error) { + tv, err := type_and_version.NewTypeAndVersionInterface(address, client) + if err != nil { + return ContractMetaData{}, fmt.Errorf("failed to get type and version for contract %s: %w", address, err) + } + tvStr, err := tv.TypeAndVersion(nil) + if err != nil { + return ContractMetaData{}, err + } + return ContractMetaData{ + TypeAndVersion: tvStr, + Address: address, + }, nil } -type ContractState interface { - TypeAndVersion(opts *bind.CallOpts) (string, error) - Address() common.Address +type Snapshotter interface { + Snapshot(contractMeta ContractMetaData, dependenciesMeta []ContractMetaData, client bind.ContractBackend) error } diff --git a/integration-tests/deployment/ccip/view/types/v1_2/router.go b/integration-tests/deployment/ccip/view/types/v1_2/router.go index f6126bd8f50..ee30b05a6b2 100644 --- a/integration-tests/deployment/ccip/view/types/v1_2/router.go +++ b/integration-tests/deployment/ccip/view/types/v1_2/router.go @@ -1,69 +1,59 @@ package v1_2 import ( + "fmt" + + "github.com/ethereum/go-ethereum/accounts/abi/bind" "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" + router1_2 "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router" ) type Router struct { - types.Contract - WrappedNative string `json:"wrappedNative,omitempty"` - ARMProxy string `json:"armProxy,omitempty"` - OnRamps map[uint64]string `json:"onRamps,omitempty"` // Map of DestinationChainSelectors to OnRamp Addresses - OffRamps map[uint64]string `json:"offRamps,omitempty"` // Map of SourceChainSelectors to a list of OffRamp Addresses -} - -func (r Router) Address() common.Address { - return common.HexToAddress(r.Contract.Address) + 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 (r Router) DestinationChainSelectors() []uint64 { - selectors := make([]uint64, 0, len(r.OffRamps)) - for selector := range r.OffRamps { - selectors = append(selectors, selector) +func (r *Router) Snapshot(routerContractMeta types.ContractMetaData, _ []types.ContractMetaData, client bind.ContractBackend) error { + r.ContractMetaData = routerContractMeta + if err := r.ContractMetaData.Validate(); err != nil { + return fmt.Errorf("snapshot error for Router: %w", err) } - return selectors -} - -func RouterSnapshot(r *router.Router) (Router, error) { - tv, err := r.TypeAndVersion(nil) + rContract, err := router1_2.NewRouter(routerContractMeta.Address, client) if err != nil { - return Router{}, err + return fmt.Errorf("snapshot error for Router: failed to get router contract: %w", err) } - wrappedNative, err := r.GetWrappedNative(nil) + wrappedNative, err := rContract.GetWrappedNative(nil) if err != nil { - return Router{}, err + return err } - armProxy, err := r.GetArmProxy(nil) + armProxy, err := rContract.GetArmProxy(nil) if err != nil { - return Router{}, err + return err } - onRamps := make(map[uint64]string) - offRamps := make(map[uint64]string) - offRampList, err := r.GetOffRamps(nil) + onRamps := make(map[uint64]common.Address) + offRamps := make(map[uint64]common.Address) + offRampList, err := rContract.GetOffRamps(nil) if err != nil { - return Router{}, err + return err } for _, offRamp := range offRampList { - offRamps[offRamp.SourceChainSelector] = offRamp.OffRamp.Hex() + offRamps[offRamp.SourceChainSelector] = offRamp.OffRamp } for selector := range offRamps { - onRamp, err := r.GetOnRamp(nil, selector) + onRamp, err := rContract.GetOnRamp(nil, selector) if err != nil { - return Router{}, err + return err } - onRamps[selector] = onRamp.Hex() + onRamps[selector] = onRamp } - return Router{ - Contract: types.Contract{ - Address: r.Address().Hex(), - TypeAndVersion: tv, - }, - WrappedNative: wrappedNative.Hex(), - ARMProxy: armProxy.Hex(), - OnRamps: onRamps, - OffRamps: offRamps, - }, nil + r.WrappedNative = wrappedNative + r.ARMProxy = armProxy + r.OnRamps = onRamps + r.OffRamps = offRamps + return nil } diff --git a/integration-tests/deployment/ccip/view/types/v1_5/tokenadminregistry.go b/integration-tests/deployment/ccip/view/types/v1_5/tokenadminregistry.go index 1b3f7d0b2a0..65572d5ba8f 100644 --- a/integration-tests/deployment/ccip/view/types/v1_5/tokenadminregistry.go +++ b/integration-tests/deployment/ccip/view/types/v1_5/tokenadminregistry.go @@ -1,6 +1,9 @@ package v1_5 import ( + "fmt" + + "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view/types" @@ -8,28 +11,24 @@ import ( ) type TokenAdminRegistry struct { - types.Contract + types.ContractMetaData Tokens []common.Address `json:"tokens"` } -func (ta TokenAdminRegistry) Address() common.Address { - return common.HexToAddress(ta.Contract.Address) -} - -func TokenAdminRegistrySnapshot(taContract *token_admin_registry.TokenAdminRegistry) (TokenAdminRegistry, error) { - tokens, err := taContract.GetAllConfiguredTokens(nil, 0, 10) +func (ta *TokenAdminRegistry) Snapshot(contractMeta types.ContractMetaData, _ []types.ContractMetaData, client bind.ContractBackend) error { + ta.ContractMetaData = contractMeta + if err := ta.ContractMetaData.Validate(); err != nil { + return fmt.Errorf("snapshot error for TokenAdminRegistry: %w", err) + } + taContract, err := token_admin_registry.NewTokenAdminRegistry(ta.Address, client) if err != nil { - return TokenAdminRegistry{}, err + return fmt.Errorf("failed to get token admin registry contract: %w", err) } - tv, err := taContract.TypeAndVersion(nil) + // TODO : CCIP-3416 : get all tokens here instead of just 10 + tokens, err := taContract.GetAllConfiguredTokens(nil, 0, 10) if err != nil { - return TokenAdminRegistry{}, err + return err } - return TokenAdminRegistry{ - Contract: types.Contract{ - TypeAndVersion: tv, - Address: taContract.Address().Hex(), - }, - Tokens: tokens, - }, nil + ta.Tokens = tokens + return nil } diff --git a/integration-tests/deployment/ccip/view/types/v1_6/feequoter.go b/integration-tests/deployment/ccip/view/types/v1_6/feequoter.go index 9524436f372..73797e4d65f 100644 --- a/integration-tests/deployment/ccip/view/types/v1_6/feequoter.go +++ b/integration-tests/deployment/ccip/view/types/v1_6/feequoter.go @@ -3,23 +3,22 @@ package v1_6 import ( "fmt" + "github.com/ethereum/go-ethereum/accounts/abi/bind" "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/fee_quoter" + router1_2 "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router" + "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/token_admin_registry" ) type FeeQuoter struct { - types.Contract - AuthorizedCallers []string `json:"authorizedCallers,omitempty"` - FeeTokens []string `json:"feeTokens,omitempty"` - StaticConfig FeeQuoterStaticConfig `json:"staticConfig,omitempty"` - DestinationChainConfig map[uint64]DestinationConfigWithTokens `json:"DestinationConfigWithTokens,omitempty"` // Map of DestinationChainSelectors -} - -type DestinationConfigWithTokens struct { - DestChainConfig FeeQuoterDestChainConfig `json:"destChainConfig,omitempty"` - TokenPriceFeedConfig map[string]FeeQuoterTokenPriceFeedConfig `json:"tokenPriceFeedConfig,omitempty"` // Map of Token addresses to FeeQuoterTokenPriceFeedConfig + types.ContractMetaData + AuthorizedCallers []string `json:"authorizedCallers,omitempty"` + FeeTokens []string `json:"feeTokens,omitempty"` + StaticConfig FeeQuoterStaticConfig `json:"staticConfig,omitempty"` + DestinationChainConfig map[uint64]FeeQuoterDestChainConfig `json:"destinationChainConfig,omitempty"` + TokenPriceFeedConfig map[string]FeeQuoterTokenPriceFeedConfig `json:"tokenPriceFeedConfig,omitempty"` } type FeeQuoterStaticConfig struct { @@ -52,17 +51,18 @@ type FeeQuoterTokenPriceFeedConfig struct { TokenDecimals uint8 `json:"tokenDecimals,omitempty"` } -func FeeQuoterSnapshot(fqContract *fee_quoter.FeeQuoter, tokensByDestination map[uint64][]string) (FeeQuoter, error) { - var fq FeeQuoter - tv, err := fqContract.TypeAndVersion(nil) +func (fq *FeeQuoter) Snapshot(fqContractMeta types.ContractMetaData, dependenciesMeta []types.ContractMetaData, client bind.ContractBackend) error { + if err := fqContractMeta.Validate(); err != nil { + return fmt.Errorf("snapshot error for FeeQuoter: %w", err) + } + fq.ContractMetaData = fqContractMeta + fqContract, err := fee_quoter.NewFeeQuoter(fqContractMeta.Address, client) if err != nil { - return fq, err + return fmt.Errorf("failed to get fee quoter contract: %w", err) } - fq.TypeAndVersion = tv - fq.Address = fqContract.Address().Hex() authorizedCallers, err := fqContract.GetAllAuthorizedCallers(nil) if err != nil { - return fq, err + return err } fq.AuthorizedCallers = make([]string, 0, len(authorizedCallers)) for _, ac := range authorizedCallers { @@ -70,7 +70,7 @@ func FeeQuoterSnapshot(fqContract *fee_quoter.FeeQuoter, tokensByDestination map } feeTokens, err := fqContract.GetFeeTokens(nil) if err != nil { - return fq, err + return err } fq.FeeTokens = make([]string, 0, len(feeTokens)) for _, ft := range feeTokens { @@ -78,20 +78,25 @@ func FeeQuoterSnapshot(fqContract *fee_quoter.FeeQuoter, tokensByDestination map } staticConfig, err := fqContract.GetStaticConfig(nil) if err != nil { - return fq, err + return err } fq.StaticConfig = FeeQuoterStaticConfig{ MaxFeeJuelsPerMsg: staticConfig.MaxFeeJuelsPerMsg.String(), LinkToken: staticConfig.LinkToken.Hex(), StalenessThreshold: staticConfig.StalenessThreshold, } - fq.DestinationChainConfig = make(map[uint64]DestinationConfigWithTokens) - for destChainSelector, tokens := range tokensByDestination { + // find router contract in dependencies + fq.DestinationChainConfig = make(map[uint64]FeeQuoterDestChainConfig) + destSelectors, err := GetDestinationSelectors(dependenciesMeta, client) + if err != nil { + return fmt.Errorf("snapshot error for FeeQuoter: %w", err) + } + for _, destChainSelector := range destSelectors { destChainConfig, err := fqContract.GetDestChainConfig(nil, destChainSelector) if err != nil { - return fq, err + return err } - d := FeeQuoterDestChainConfig{ + fq.DestinationChainConfig[destChainSelector] = FeeQuoterDestChainConfig{ IsEnabled: destChainConfig.IsEnabled, MaxNumberOfTokensPerMsg: destChainConfig.MaxNumberOfTokensPerMsg, MaxDataBytes: destChainConfig.MaxDataBytes, @@ -109,21 +114,64 @@ func FeeQuoterSnapshot(fqContract *fee_quoter.FeeQuoter, tokensByDestination map EnforceOutOfOrder: destChainConfig.EnforceOutOfOrder, ChainFamilySelector: fmt.Sprintf("%x", destChainConfig.ChainFamilySelector), } - tokenPriceFeedConfig := make(map[string]FeeQuoterTokenPriceFeedConfig) - for _, token := range tokens { - t, err := fqContract.GetTokenPriceFeedConfig(nil, common.HexToAddress(token)) + } + fq.TokenPriceFeedConfig = make(map[string]FeeQuoterTokenPriceFeedConfig) + tokens, err := GetSupportedTokens(dependenciesMeta, client) + if err != nil { + return fmt.Errorf("snapshot error for FeeQuoter: %w", err) + } + for _, token := range tokens { + t, err := fqContract.GetTokenPriceFeedConfig(nil, token) + if err != nil { + return err + } + fq.TokenPriceFeedConfig[token.String()] = FeeQuoterTokenPriceFeedConfig{ + DataFeedAddress: t.DataFeedAddress.Hex(), + TokenDecimals: t.TokenDecimals, + } + } + return nil +} + +func GetSupportedTokens(dependenciesMeta []types.ContractMetaData, client bind.ContractBackend) ([]common.Address, error) { + for _, dep := range dependenciesMeta { + if dep.TypeAndVersion == types.TokenAdminRegistryTypeAndVersionV1_5 { + taContract, err := token_admin_registry.NewTokenAdminRegistry(dep.Address, client) if err != nil { - return fq, err + return nil, fmt.Errorf("failed to get router contract: %w", err) } - tokenPriceFeedConfig[token] = FeeQuoterTokenPriceFeedConfig{ - DataFeedAddress: t.DataFeedAddress.Hex(), - TokenDecimals: t.TokenDecimals, + // TODO : include pagination CCIP-3416 + tokens, err := taContract.GetAllConfiguredTokens(nil, 0, 10) + if err != nil { + return nil, fmt.Errorf("failed to get tokens from router: %w", err) } + return tokens, nil } - fq.DestinationChainConfig[destChainSelector] = DestinationConfigWithTokens{ - DestChainConfig: d, - TokenPriceFeedConfig: tokenPriceFeedConfig, + } + return nil, fmt.Errorf("token admin registry not found in dependencies") +} + +func GetDestinationSelectors(dependenciesMeta []types.ContractMetaData, client bind.ContractBackend) ([]uint64, error) { + destSelectors := make([]uint64, 0) + foundRouter := false + for _, dep := range dependenciesMeta { + if dep.TypeAndVersion == types.RouterTypeAndVersionV1_2 { + foundRouter = true + routerContract, err := router1_2.NewRouter(dep.Address, client) + if err != nil { + return nil, fmt.Errorf("failed to get router contract: %w", err) + } + offRamps, err := routerContract.GetOffRamps(nil) + if err != nil { + return nil, fmt.Errorf("failed to get offRamps from router: %w", err) + } + for _, offRamp := range offRamps { + destSelectors = append(destSelectors, offRamp.SourceChainSelector) + } } } - return fq, nil + if !foundRouter { + return nil, fmt.Errorf("router not found in dependencies") + } + return destSelectors, nil } diff --git a/integration-tests/deployment/ccip/view/types/v1_6/noncemanager.go b/integration-tests/deployment/ccip/view/types/v1_6/noncemanager.go index febf8650fd3..67f51814769 100644 --- a/integration-tests/deployment/ccip/view/types/v1_6/noncemanager.go +++ b/integration-tests/deployment/ccip/view/types/v1_6/noncemanager.go @@ -8,14 +8,10 @@ import ( ) type NonceManager struct { - types.Contract + types.ContractMetaData AuthorizedCallers []common.Address `json:"authorizedCallers,omitempty"` } -func (nm NonceManager) Address() common.Address { - return common.HexToAddress(nm.Contract.Address) -} - func NonceManagerSnapshot(nm *nonce_manager.NonceManager) (NonceManager, error) { authorizedCallers, err := nm.GetAllAuthorizedCallers(nil) if err != nil { @@ -26,9 +22,9 @@ func NonceManagerSnapshot(nm *nonce_manager.NonceManager) (NonceManager, error) return NonceManager{}, err } return NonceManager{ - Contract: types.Contract{ + ContractMetaData: types.ContractMetaData{ TypeAndVersion: tv, - Address: nm.Address().Hex(), + Address: nm.Address(), }, // TODO: these can be resolved using an address book AuthorizedCallers: authorizedCallers, diff --git a/integration-tests/deployment/ccip/view/types/v1_6/onramp.go b/integration-tests/deployment/ccip/view/types/v1_6/onramp.go index 09b917cbfbd..96528f04b8b 100644 --- a/integration-tests/deployment/ccip/view/types/v1_6/onramp.go +++ b/integration-tests/deployment/ccip/view/types/v1_6/onramp.go @@ -3,14 +3,17 @@ package v1_6 import ( "fmt" + "github.com/ethereum/go-ethereum/accounts/abi/bind" "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/onramp" + router1_2 "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router" + "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/token_admin_registry" ) type OnRamp struct { - types.Contract + types.ContractMetaData DynamicConfig onramp.OnRampDynamicConfig `json:"dynamicConfig"` StaticConfig onramp.OnRampStaticConfig `json:"staticConfig"` Owner common.Address `json:"owner"` @@ -26,33 +29,70 @@ type DestChainSpecificData struct { } func OnRampSnapshot( - onRampReader *onramp.OnRamp, - destChainSelectors []uint64, - sourceTokens []common.Address, + onRampContract *onramp.OnRamp, + routerContract types.ContractMetaData, + taContract types.ContractMetaData, + client bind.ContractBackend, ) (OnRamp, error) { - tv, err := onRampReader.TypeAndVersion(nil) + tv, err := onRampContract.TypeAndVersion(nil) if err != nil { return OnRamp{}, fmt.Errorf("failed to get type and version: %w", err) } - dynamicConfig, err := onRampReader.GetDynamicConfig(nil) + dynamicConfig, err := onRampContract.GetDynamicConfig(nil) if err != nil { return OnRamp{}, fmt.Errorf("failed to get dynamic config: %w", err) } - staticConfig, err := onRampReader.GetStaticConfig(nil) + staticConfig, err := onRampContract.GetStaticConfig(nil) if err != nil { return OnRamp{}, fmt.Errorf("failed to get static config: %w", err) } - owner, err := onRampReader.Owner(nil) + owner, err := onRampContract.Owner(nil) if err != nil { return OnRamp{}, fmt.Errorf("failed to get owner: %w", err) } + // populate destChainSelectors from router + destChainSelectors := make([]uint64, 0) + switch routerContract.TypeAndVersion { + case types.RouterTypeAndVersionV1_2: + router, err := router1_2.NewRouter(routerContract.Address, client) + if err != nil { + return OnRamp{}, fmt.Errorf("failed to get router: %w", err) + } + offRampList, err := router.GetOffRamps(nil) + if err != nil { + return OnRamp{}, fmt.Errorf("failed to get offRamps from router %w", err) + } + for _, offRamp := range offRampList { + // the lanes are bidirectional, so we get the list of source chains to know which chains are supported as destinations as well + destChainSelectors = append(destChainSelectors, offRamp.SourceChainSelector) + } + default: + return OnRamp{}, fmt.Errorf("unsupported router type and version: %s", routerContract.TypeAndVersion) + } + + // populate sourceTokens from token admin registry contract + var sourceTokens []common.Address + switch taContract.TypeAndVersion { + case types.TokenAdminRegistryTypeAndVersionV1_5: + ta, err := token_admin_registry.NewTokenAdminRegistry(taContract.Address, client) + if err != nil { + return OnRamp{}, fmt.Errorf("failed to get token admin registry: %w", err) + } + // TODO : CCIP-3416 : get all tokens here instead of just 10 + sourceTokens, err = ta.GetAllConfiguredTokens(nil, 0, 10) + if err != nil { + return OnRamp{}, fmt.Errorf("failed to get all configured tokens: %w", err) + } + default: + return OnRamp{}, fmt.Errorf("unsupported token admin registry type and version: %s", taContract.TypeAndVersion) + } sourceTokenToPool := make(map[common.Address]common.Address) for _, sourceToken := range sourceTokens { - pool, err := onRampReader.GetPoolBySourceToken(nil, 0, sourceToken) + pool, err := onRampContract.GetPoolBySourceToken(nil, 0, sourceToken) if err != nil { return OnRamp{}, fmt.Errorf("failed to get pool by source token: %w", err) } @@ -61,19 +101,19 @@ func OnRampSnapshot( destChainSpecificData := make(map[uint64]DestChainSpecificData) for _, destChainSelector := range destChainSelectors { - allowedSendersList, err := onRampReader.GetAllowedSendersList(nil, destChainSelector) + allowedSendersList, err := onRampContract.GetAllowedSendersList(nil, destChainSelector) if err != nil { return OnRamp{}, fmt.Errorf("failed to get allowed senders list: %w", err) } - destChainConfig, err := onRampReader.GetDestChainConfig(nil, destChainSelector) + destChainConfig, err := onRampContract.GetDestChainConfig(nil, destChainSelector) if err != nil { return OnRamp{}, fmt.Errorf("failed to get dest chain config: %w", err) } - expectedNextSeqNum, err := onRampReader.GetExpectedNextSequenceNumber(nil, destChainSelector) + expectedNextSeqNum, err := onRampContract.GetExpectedNextSequenceNumber(nil, destChainSelector) if err != nil { return OnRamp{}, fmt.Errorf("failed to get expected next sequence number: %w", err) } - router, err := onRampReader.GetRouter(nil, destChainSelector) + router, err := onRampContract.GetRouter(nil, destChainSelector) if err != nil { return OnRamp{}, fmt.Errorf("failed to get router: %w", err) } @@ -86,9 +126,9 @@ func OnRampSnapshot( } return OnRamp{ - Contract: types.Contract{ + ContractMetaData: types.ContractMetaData{ TypeAndVersion: tv, - Address: onRampReader.Address().Hex(), + Address: onRampContract.Address(), }, DynamicConfig: dynamicConfig, StaticConfig: staticConfig, diff --git a/integration-tests/deployment/ccip/view/types/v1_6/rmnremote.go b/integration-tests/deployment/ccip/view/types/v1_6/rmnremote.go index 813181aed3e..5c112362505 100644 --- a/integration-tests/deployment/ccip/view/types/v1_6/rmnremote.go +++ b/integration-tests/deployment/ccip/view/types/v1_6/rmnremote.go @@ -6,7 +6,7 @@ import ( ) type RMN struct { - types.Contract + types.ContractMetaData IsCursed bool `json:"isCursed"` Config RMNRemoteVersionedConfig `json:"config,omitempty"` } @@ -47,8 +47,8 @@ func RMNSnapshot(rmnReader *rmn_remote.RMNRemote) (RMN, error) { return RMN{}, err } return RMN{ - Contract: types.Contract{ - Address: rmnReader.Address().Hex(), + ContractMetaData: types.ContractMetaData{ + Address: rmnReader.Address(), TypeAndVersion: tv, }, IsCursed: isCursed, From c7d602319d65390684bbf2f05a0e655754e41701 Mon Sep 17 00:00:00 2001 From: AnieeG Date: Wed, 18 Sep 2024 16:02:34 -0700 Subject: [PATCH 18/23] more changes --- .../deployment/ccip/deploy_test.go | 2 +- integration-tests/deployment/ccip/state.go | 50 +++++++++---------- .../deployment/ccip/view/chain.go | 33 ++++++------ .../deployment/ccip/view/state.go | 10 ++-- 4 files changed, 46 insertions(+), 49 deletions(-) diff --git a/integration-tests/deployment/ccip/deploy_test.go b/integration-tests/deployment/ccip/deploy_test.go index e2963b84a3b..11e71c7e3f2 100644 --- a/integration-tests/deployment/ccip/deploy_test.go +++ b/integration-tests/deployment/ccip/deploy_test.go @@ -34,7 +34,7 @@ func TestDeployCCIPContracts(t *testing.T) { require.NoError(t, err) state, err := LoadOnchainState(e, ab) require.NoError(t, err) - snap, err := state.Snapshot(e.AllChainSelectors()) + snap, err := state.View(e.AllChainSelectors()) require.NoError(t, err) // Assert expect every deployed address to be in the address book. diff --git a/integration-tests/deployment/ccip/state.go b/integration-tests/deployment/ccip/state.go index ae13e22abe5..03f1a45e2a8 100644 --- a/integration-tests/deployment/ccip/state.go +++ b/integration-tests/deployment/ccip/state.go @@ -54,51 +54,51 @@ type CCIPChainState struct { TestRouter *router.Router } -func (c CCIPChainState) GenerateView() (view.Chain, error) { +func (c CCIPChainState) GenerateView() (view.ChainView, error) { chainView := view.NewChain() r := c.Router if r != nil { - routerSnapshot, err := v1_2.GenerateRouterView(r) + routerView, err := v1_2.GenerateRouterView(r) if err != nil { return chainView, err } - chainView.Router[r.Address().Hex()] = routerSnapshot + chainView.Router[r.Address().Hex()] = routerView } ta := c.TokenAdminRegistry if ta != nil { - taSnapshot, err := v1_5.GenerateTokenAdminRegistryView(ta) + taView, err := v1_5.GenerateTokenAdminRegistryView(ta) if err != nil { return chainView, err } - chainView.TokenAdminRegistry[ta.Address().Hex()] = taSnapshot + chainView.TokenAdminRegistry[ta.Address().Hex()] = taView } nm := c.NonceManager if nm != nil { - nmSnapshot, err := v1_6.GenerateNonceManagerView(nm) + nmView, err := v1_6.GenerateNonceManagerView(nm) if err != nil { return chainView, err } - chainView.NonceManager[nm.Address().Hex()] = nmSnapshot + chainView.NonceManager[nm.Address().Hex()] = nmView } rmn := c.RMNRemote if rmn != nil { - rmnSnapshot, err := v1_6.GenerateRMNRemoteView(rmn) + rmnView, err := v1_6.GenerateRMNRemoteView(rmn) if err != nil { return chainView, err } - chainView.RMN[rmn.Address().Hex()] = rmnSnapshot + chainView.RMN[rmn.Address().Hex()] = rmnView } fq := c.FeeQuoter if fq != nil && c.Router != nil && c.TokenAdminRegistry != nil { - fqSnapshot, err := v1_6.GenerateFeeQuoterView(fq, c.Router, c.TokenAdminRegistry) + fqView, err := v1_6.GenerateFeeQuoterView(fq, c.Router, c.TokenAdminRegistry) if err != nil { return chainView, err } - chainView.FeeQuoter[fq.Address().Hex()] = fqSnapshot + chainView.FeeQuoter[fq.Address().Hex()] = fqView } onRamp := c.OnRamp if onRamp != nil && c.Router != nil && c.TokenAdminRegistry != nil { - onRampSnapshot, err := v1_6.GenerateOnRampView( + onRampView, err := v1_6.GenerateOnRampView( onRamp, c.Router, c.TokenAdminRegistry, @@ -106,7 +106,7 @@ func (c CCIPChainState) GenerateView() (view.Chain, error) { if err != nil { return chainView, err } - chainView.OnRamp[onRamp.Address().Hex()] = onRampSnapshot + chainView.OnRamp[onRamp.Address().Hex()] = onRampView } return chainView, nil } @@ -121,37 +121,37 @@ type CCIPOnChainState struct { Chains map[uint64]CCIPChainState } -func (s CCIPOnChainState) Snapshot(chains []uint64) (view.CCIPSnapShot, error) { - snapshot := view.NewCCIPSnapShot() +func (s CCIPOnChainState) View(chains []uint64) (view.CCIPView, error) { + View := view.NewCCIPView() for _, chainSelector := range chains { // TODO: Need a utility for this chainid, err := chainsel.ChainIdFromSelector(chainSelector) if err != nil { - return snapshot, err + return View, err } chainName, err := chainsel.NameFromChainId(chainid) if err != nil { - return snapshot, err + return View, err } if _, ok := s.Chains[chainSelector]; !ok { - return snapshot, fmt.Errorf("chain not supported %d", chainSelector) + return View, fmt.Errorf("chain not supported %d", chainSelector) } chainState := s.Chains[chainSelector] - chainSnapshot, err := chainState.GenerateView() + chainView, err := chainState.GenerateView() if err != nil { - return snapshot, err + return View, err } - snapshot.Chains[chainName] = chainSnapshot + View.Chains[chainName] = chainView } - return snapshot, nil + return View, nil } -func SnapshotState(e deployment.Environment, ab deployment.AddressBook) (view.CCIPSnapShot, error) { +func StateView(e deployment.Environment, ab deployment.AddressBook) (view.CCIPView, error) { state, err := LoadOnchainState(e, ab) if err != nil { - return view.CCIPSnapShot{}, err + return view.CCIPView{}, err } - return state.Snapshot(e.AllChainSelectors()) + return state.View(e.AllChainSelectors()) } func LoadOnchainState(e deployment.Environment, ab deployment.AddressBook) (CCIPOnChainState, error) { diff --git a/integration-tests/deployment/ccip/view/chain.go b/integration-tests/deployment/ccip/view/chain.go index c5df4eec720..1185c33d7b7 100644 --- a/integration-tests/deployment/ccip/view/chain.go +++ b/integration-tests/deployment/ccip/view/chain.go @@ -6,25 +6,22 @@ import ( "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view/types/v1_6" ) -type Chain struct { - DestinationChainSelectors []uint64 `json:"destinationChainSelectors,omitempty"` - // TODO - populate supportedTokensByDestination - SupportedTokensByDestination map[uint64][]string `json:"supportedTokensByDestination,omitempty"` - TokenAdminRegistry map[string]v1_5.TokenAdminRegistry `json:"tokenAdminRegistry,omitempty"` - FeeQuoter map[string]v1_6.FeeQuoterView `json:"feeQuoter,omitempty"` - NonceManager map[string]v1_6.NonceManager `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"` +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() Chain { - return Chain{ - DestinationChainSelectors: make([]uint64, 0), - TokenAdminRegistry: make(map[string]v1_5.TokenAdminRegistry), - NonceManager: make(map[string]v1_6.NonceManager), - Router: make(map[string]v1_2.RouterView), - RMN: make(map[string]v1_6.RMNRemoteView), - OnRamp: make(map[string]v1_6.OnRampView), +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), } } diff --git a/integration-tests/deployment/ccip/view/state.go b/integration-tests/deployment/ccip/view/state.go index f6c6ec62563..5c86f8e27a5 100644 --- a/integration-tests/deployment/ccip/view/state.go +++ b/integration-tests/deployment/ccip/view/state.go @@ -1,11 +1,11 @@ package view -type CCIPSnapShot struct { - Chains map[string]Chain `json:"chains,omitempty"` +type CCIPView struct { + Chains map[string]ChainView `json:"chains,omitempty"` } -func NewCCIPSnapShot() CCIPSnapShot { - return CCIPSnapShot{ - Chains: make(map[string]Chain), +func NewCCIPView() CCIPView { + return CCIPView{ + Chains: make(map[string]ChainView), } } From 53b4c40ddf05ac01e902f6d962dc87ae0c38db32 Mon Sep 17 00:00:00 2001 From: AnieeG Date: Wed, 18 Sep 2024 16:05:11 -0700 Subject: [PATCH 19/23] rename --- integration-tests/deployment/ccip/state.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/integration-tests/deployment/ccip/state.go b/integration-tests/deployment/ccip/state.go index 03f1a45e2a8..0d263c5b8f5 100644 --- a/integration-tests/deployment/ccip/state.go +++ b/integration-tests/deployment/ccip/state.go @@ -122,28 +122,28 @@ type CCIPOnChainState struct { } func (s CCIPOnChainState) View(chains []uint64) (view.CCIPView, error) { - View := view.NewCCIPView() + ccipView := view.NewCCIPView() for _, chainSelector := range chains { // TODO: Need a utility for this chainid, err := chainsel.ChainIdFromSelector(chainSelector) if err != nil { - return View, err + return ccipView, err } chainName, err := chainsel.NameFromChainId(chainid) if err != nil { - return View, err + return ccipView, err } if _, ok := s.Chains[chainSelector]; !ok { - return View, fmt.Errorf("chain not supported %d", chainSelector) + return ccipView, fmt.Errorf("chain not supported %d", chainSelector) } chainState := s.Chains[chainSelector] chainView, err := chainState.GenerateView() if err != nil { - return View, err + return ccipView, err } - View.Chains[chainName] = chainView + ccipView.Chains[chainName] = chainView } - return View, nil + return ccipView, nil } func StateView(e deployment.Environment, ab deployment.AddressBook) (view.CCIPView, error) { From fe85444e24d092c53ededdf0e7919cca3e169c18 Mon Sep 17 00:00:00 2001 From: AnieeG Date: Wed, 18 Sep 2024 18:35:23 -0700 Subject: [PATCH 20/23] fix lint --- integration-tests/deployment/ccip/view/types/v1_2/router.go | 3 +++ integration-tests/deployment/ccip/view/types/v1_6/onramp.go | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/integration-tests/deployment/ccip/view/types/v1_2/router.go b/integration-tests/deployment/ccip/view/types/v1_2/router.go index c1df1be4ca7..9d3711d0c28 100644 --- a/integration-tests/deployment/ccip/view/types/v1_2/router.go +++ b/integration-tests/deployment/ccip/view/types/v1_2/router.go @@ -19,6 +19,9 @@ type RouterView struct { 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) diff --git a/integration-tests/deployment/ccip/view/types/v1_6/onramp.go b/integration-tests/deployment/ccip/view/types/v1_6/onramp.go index 5967c787722..a5fe13bfb5c 100644 --- a/integration-tests/deployment/ccip/view/types/v1_6/onramp.go +++ b/integration-tests/deployment/ccip/view/types/v1_6/onramp.go @@ -57,7 +57,9 @@ func GenerateOnRampView( } // populate sourceTokens from token admin registry contract sourceTokens, err := taContract.GetAllConfiguredTokens(nil, 0, 10) - + if err != nil { + return OnRampView{}, fmt.Errorf("failed to get all configured tokens: %w", err) + } sourceTokenToPool := make(map[common.Address]common.Address) for _, sourceToken := range sourceTokens { pool, err := onRampContract.GetPoolBySourceToken(nil, 0, sourceToken) From dc695c9dc530d83d903fce7fa9e91eb4576d3f4a Mon Sep 17 00:00:00 2001 From: AnieeG Date: Fri, 20 Sep 2024 12:39:06 -0700 Subject: [PATCH 21/23] more review comments --- integration-tests/deployment/ccip/state.go | 43 ++++++++++------------ 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/integration-tests/deployment/ccip/state.go b/integration-tests/deployment/ccip/state.go index 6f32d91ecdd..5eff1815720 100644 --- a/integration-tests/deployment/ccip/state.go +++ b/integration-tests/deployment/ccip/state.go @@ -69,57 +69,52 @@ type CCIPChainState struct { func (c CCIPChainState) GenerateView() (view.ChainView, error) { chainView := view.NewChain() - r := c.Router - if r != nil { - routerView, err := v1_2.GenerateRouterView(r) + if c.Router != nil { + routerView, err := v1_2.GenerateRouterView(c.Router) if err != nil { return chainView, err } - chainView.Router[r.Address().Hex()] = routerView + chainView.Router[c.Router.Address().Hex()] = routerView } - ta := c.TokenAdminRegistry - if ta != nil { - taView, err := v1_5.GenerateTokenAdminRegistryView(ta) + if c.TokenAdminRegistry != nil { + taView, err := v1_5.GenerateTokenAdminRegistryView(c.TokenAdminRegistry) if err != nil { return chainView, err } - chainView.TokenAdminRegistry[ta.Address().Hex()] = taView + chainView.TokenAdminRegistry[c.TokenAdminRegistry.Address().Hex()] = taView } - nm := c.NonceManager - if nm != nil { - nmView, err := v1_6.GenerateNonceManagerView(nm) + if c.NonceManager != nil { + nmView, err := v1_6.GenerateNonceManagerView(c.NonceManager) if err != nil { return chainView, err } - chainView.NonceManager[nm.Address().Hex()] = nmView + chainView.NonceManager[c.NonceManager.Address().Hex()] = nmView } - rmn := c.RMNRemote - if rmn != nil { - rmnView, err := v1_6.GenerateRMNRemoteView(rmn) + if c.RMNRemote != nil { + rmnView, err := v1_6.GenerateRMNRemoteView(c.RMNRemote) if err != nil { return chainView, err } - chainView.RMN[rmn.Address().Hex()] = rmnView + chainView.RMN[c.RMNRemote.Address().Hex()] = rmnView } - fq := c.FeeQuoter - if fq != nil && c.Router != nil && c.TokenAdminRegistry != nil { - fqView, err := v1_6.GenerateFeeQuoterView(fq, c.Router, c.TokenAdminRegistry) + if c.FeeQuoter != nil && c.Router != nil && c.TokenAdminRegistry != nil { + fqView, err := v1_6.GenerateFeeQuoterView(c.FeeQuoter, c.Router, c.TokenAdminRegistry) if err != nil { return chainView, err } - chainView.FeeQuoter[fq.Address().Hex()] = fqView + chainView.FeeQuoter[c.FeeQuoter.Address().Hex()] = fqView } - onRamp := c.OnRamp - if onRamp != nil && c.Router != nil && c.TokenAdminRegistry != nil { + + if c.OnRamp != nil && c.Router != nil && c.TokenAdminRegistry != nil { onRampView, err := v1_6.GenerateOnRampView( - onRamp, + c.OnRamp, c.Router, c.TokenAdminRegistry, ) if err != nil { return chainView, err } - chainView.OnRamp[onRamp.Address().Hex()] = onRampView + chainView.OnRamp[c.OnRamp.Address().Hex()] = onRampView } return chainView, nil } From 9fda18bfc909ce911fc2564534b2e8f983e28bfa Mon Sep 17 00:00:00 2001 From: AnieeG Date: Fri, 20 Sep 2024 12:48:42 -0700 Subject: [PATCH 22/23] fix rmnremote version --- integration-tests/deployment/ccip/state.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration-tests/deployment/ccip/state.go b/integration-tests/deployment/ccip/state.go index 5eff1815720..d6bd8894396 100644 --- a/integration-tests/deployment/ccip/state.go +++ b/integration-tests/deployment/ccip/state.go @@ -222,7 +222,7 @@ func LoadChainState(chain deployment.Chain, addresses map[string]deployment.Type return state, err } state.ArmProxy = armProxy - case deployment.NewTypeAndVersion(RMNRemote, deployment.Version1_0_0).String(): + case deployment.NewTypeAndVersion(RMNRemote, deployment.Version1_6_0_dev).String(): rmnRemote, err := rmn_remote.NewRMNRemote(common.HexToAddress(address), chain.Client) if err != nil { return state, err From 145bf8f55982b3c721f3fc57957f243faa02cc34 Mon Sep 17 00:00:00 2001 From: AnieeG Date: Fri, 20 Sep 2024 13:01:32 -0700 Subject: [PATCH 23/23] one more fix --- integration-tests/deployment/ccip/deploy.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration-tests/deployment/ccip/deploy.go b/integration-tests/deployment/ccip/deploy.go index f0641b65165..358a72bad11 100644 --- a/integration-tests/deployment/ccip/deploy.go +++ b/integration-tests/deployment/ccip/deploy.go @@ -248,7 +248,7 @@ func DeployChainContracts( chain.Selector, ) return ContractDeploy[*rmn_remote.RMNRemote]{ - rmnRemoteAddr, rmnRemote, tx, deployment.NewTypeAndVersion(RMNRemote, deployment.Version1_0_0), err2, + rmnRemoteAddr, rmnRemote, tx, deployment.NewTypeAndVersion(RMNRemote, deployment.Version1_6_0_dev), err2, } }) if err != nil {