Skip to content

Commit

Permalink
add onRamp reader
Browse files Browse the repository at this point in the history
  • Loading branch information
ogtownsend committed Sep 10, 2024
1 parent 54dbed8 commit 2ea45cc
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 0 deletions.
12 changes: 12 additions & 0 deletions integration-tests/deployment/ccip/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

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 @@ -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 {
Expand All @@ -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),
}
}
112 changes: 112 additions & 0 deletions integration-tests/deployment/ccip/view/onramp.go
Original file line number Diff line number Diff line change
@@ -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)

Check failure on line 48 in integration-tests/deployment/ccip/view/onramp.go

View workflow job for this annotation

GitHub Actions / Lint integration-tests

non-wrapping format verb for fmt.Errorf. Use `%w` to format errors (errorlint)
}

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

Check failure on line 53 in integration-tests/deployment/ccip/view/onramp.go

View workflow job for this annotation

GitHub Actions / Lint integration-tests

non-wrapping format verb for fmt.Errorf. Use `%w` to format errors (errorlint)
}

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

Check failure on line 58 in integration-tests/deployment/ccip/view/onramp.go

View workflow job for this annotation

GitHub Actions / Lint integration-tests

non-wrapping format verb for fmt.Errorf. Use `%w` to format errors (errorlint)
}

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
}

0 comments on commit 2ea45cc

Please sign in to comment.