Skip to content

Commit

Permalink
CCIP 3388 - add offramp generation (#14526)
Browse files Browse the repository at this point in the history
* add offramp getters

* Move GetRemoteChainSelectors to router

* run lint

* remove unnecessary owner calls
  • Loading branch information
ogtownsend committed Sep 23, 2024
1 parent c7a16eb commit f1b310b
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 16 deletions.
11 changes: 11 additions & 0 deletions integration-tests/deployment/ccip/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,17 @@ func (c CCIPChainState) GenerateView() (view.ChainView, error) {
}
chainView.OnRamp[c.OnRamp.Address().Hex()] = onRampView
}

if c.OffRamp != nil && c.Router != nil {
offRampView, err := v1_6.GenerateOffRampView(
c.OffRamp,
c.Router,
)
if err != nil {
return chainView, err
}
chainView.OffRamp[c.OffRamp.Address().Hex()] = offRampView
}
return chainView, nil
}

Expand Down
2 changes: 2 additions & 0 deletions integration-tests/deployment/ccip/view/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type ChainView struct {
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"`
OffRamp map[string]v1_6.OffRampView `json:"offRamp,omitempty"`
}

func NewChain() ChainView {
Expand All @@ -22,6 +23,7 @@ func NewChain() ChainView {
Router: make(map[string]v1_2.RouterView),
RMN: make(map[string]v1_6.RMNRemoteView),
OnRamp: make(map[string]v1_6.OnRampView),
OffRamp: make(map[string]v1_6.OffRampView),
FeeQuoter: make(map[string]v1_6.FeeQuoterView),
}
}
15 changes: 15 additions & 0 deletions integration-tests/deployment/ccip/view/v1_2/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,18 @@ func GenerateRouterView(r *router.Router) (RouterView, error) {
OffRamps: offRamps,
}, nil
}

// From the perspective of the OnRamp, the destination chains are the source chains for the OffRamp.
func GetRemoteChainSelectors(routerContract *router.Router) ([]uint64, error) {
remoteSelectors := make([]uint64, 0)
offRamps, err := routerContract.GetOffRamps(nil)
if err != nil {
return nil, fmt.Errorf("failed to get offRamps from router: %w", err)
}
// lanes are bidirectional, so we get the list of source chains to know which chains are supported as destinations as well
for _, offRamp := range offRamps {
remoteSelectors = append(remoteSelectors, offRamp.SourceChainSelector)
}

return remoteSelectors, nil
}
17 changes: 2 additions & 15 deletions integration-tests/deployment/ccip/view/v1_6/feequoter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"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/v1_2"
"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"
Expand Down Expand Up @@ -83,7 +84,7 @@ func GenerateFeeQuoterView(fqContract *fee_quoter.FeeQuoter, router *router1_2.R
}
// find router contract in dependencies
fq.DestinationChainConfig = make(map[uint64]FeeQuoterDestChainConfig)
destSelectors, err := GetDestinationSelectors(router)
destSelectors, err := v1_2.GetRemoteChainSelectors(router)
if err != nil {
return FeeQuoterView{}, fmt.Errorf("view error for FeeQuoter: %w", err)
}
Expand Down Expand Up @@ -137,17 +138,3 @@ func GetSupportedTokens(taContract *token_admin_registry.TokenAdminRegistry) ([]
}
return tokens, nil
}

func GetDestinationSelectors(routerContract *router1_2.Router) ([]uint64, error) {
destSelectors := make([]uint64, 0)
offRamps, err := routerContract.GetOffRamps(nil)
if err != nil {
return nil, fmt.Errorf("failed to get offRamps from router: %w", err)
}
// lanes are bidirectional, so we get the list of source chains to know which chains are supported as destinations as well
for _, offRamp := range offRamps {
destSelectors = append(destSelectors, offRamp.SourceChainSelector)
}

return destSelectors, nil
}
64 changes: 64 additions & 0 deletions integration-tests/deployment/ccip/view/v1_6/offramp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package v1_6

import (
"fmt"

"github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view/types"
"github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip/view/v1_2"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/offramp"
router1_2 "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router"
)

type OffRampView struct {
types.ContractMetaData
DynamicConfig offramp.OffRampDynamicConfig `json:"dynamicConfig"`
LatestPriceSequenceNumber uint64 `json:"latestPriceSequenceNumber"`
SourceChainConfigs map[uint64]offramp.OffRampSourceChainConfig `json:"sourceChainConfigs"`
StaticConfig offramp.OffRampStaticConfig `json:"staticConfig"`
}

func GenerateOffRampView(
offRampContract *offramp.OffRamp,
routerContract *router1_2.Router,
) (OffRampView, error) {
tv, err := types.NewContractMetaData(offRampContract, offRampContract.Address())
if err != nil {
return OffRampView{}, err
}

dynamicConfig, err := offRampContract.GetDynamicConfig(nil)
if err != nil {
return OffRampView{}, fmt.Errorf("failed to get dynamic config: %w", err)
}

latestPriceSequenceNumber, err := offRampContract.GetLatestPriceSequenceNumber(nil)
if err != nil {
return OffRampView{}, fmt.Errorf("failed to get latest price sequence number: %w", err)
}

sourceChainSelectors, err := v1_2.GetRemoteChainSelectors(routerContract)
if err != nil {
return OffRampView{}, fmt.Errorf("failed to get source chain selectors: %w", err)
}
sourceChainConfigs := make(map[uint64]offramp.OffRampSourceChainConfig)
for _, sourceChainSelector := range sourceChainSelectors {
sourceChainConfig, err := offRampContract.GetSourceChainConfig(nil, sourceChainSelector)
if err != nil {
return OffRampView{}, fmt.Errorf("failed to get source chain config: %w", err)
}
sourceChainConfigs[sourceChainSelector] = sourceChainConfig
}

staticConfig, err := offRampContract.GetStaticConfig(nil)
if err != nil {
return OffRampView{}, fmt.Errorf("failed to get static config: %w", err)
}

return OffRampView{
ContractMetaData: tv,
DynamicConfig: dynamicConfig,
LatestPriceSequenceNumber: latestPriceSequenceNumber,
SourceChainConfigs: sourceChainConfigs,
StaticConfig: staticConfig,
}, nil
}
3 changes: 2 additions & 1 deletion integration-tests/deployment/ccip/view/v1_6/onramp.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"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/v1_2"
"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"
Expand Down Expand Up @@ -51,7 +52,7 @@ func GenerateOnRampView(
return OnRampView{}, fmt.Errorf("failed to get owner: %w", err)
}
// populate destChainSelectors from router
destChainSelectors, err := GetDestinationSelectors(routerContract)
destChainSelectors, err := v1_2.GetRemoteChainSelectors(routerContract)
if err != nil {
return OnRampView{}, fmt.Errorf("failed to get destination selectors: %w", err)
}
Expand Down

0 comments on commit f1b310b

Please sign in to comment.