From 2ea45cc8637b291deb85e899985df397646f900e Mon Sep 17 00:00:00 2001 From: Oliver Townsend Date: Tue, 10 Sep 2024 16:12:24 -0700 Subject: [PATCH] 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 +}