Skip to content

Commit

Permalink
Add remaining CCIP views (#15590)
Browse files Browse the repository at this point in the history
* Remove cap reg and add pr

* RMN

* CCIP home basics

* Fix test name

* Add to state

* Fix name

* Basic sanity tests

* Fix state

* Comments
  • Loading branch information
connorwstein authored Dec 11, 2024
1 parent e48ca56 commit 266c147
Show file tree
Hide file tree
Showing 14 changed files with 533 additions and 1,194 deletions.
1,126 changes: 0 additions & 1,126 deletions core/gethwrappers/ccip/generated/ccip_config/ccip_config.go

This file was deleted.

38 changes: 20 additions & 18 deletions deployment/ccip/changeset/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
commoncs "github.com/smartcontractkit/chainlink/deployment/common/changeset"
commontypes "github.com/smartcontractkit/chainlink/deployment/common/types"
common_v1_0 "github.com/smartcontractkit/chainlink/deployment/common/view/v1_0"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/ccip_config"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/commit_store"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/mock_rmn_contract"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/registry_module_owner_custom"
Expand All @@ -48,33 +47,38 @@ import (
)

var (
// Legacy
CommitStore deployment.ContractType = "CommitStore"

// Not legacy
MockRMN deployment.ContractType = "MockRMN"
RMNRemote deployment.ContractType = "RMNRemote"
ARMProxy deployment.ContractType = "ARMProxy"
WETH9 deployment.ContractType = "WETH9"
Router deployment.ContractType = "Router"
CommitStore deployment.ContractType = "CommitStore"
TokenAdminRegistry deployment.ContractType = "TokenAdminRegistry"
RegistryModule deployment.ContractType = "RegistryModuleOwnerCustom"
NonceManager deployment.ContractType = "NonceManager"
FeeQuoter deployment.ContractType = "FeeQuoter"
CCIPHome deployment.ContractType = "CCIPHome"
CCIPConfig deployment.ContractType = "CCIPConfig"
RMNHome deployment.ContractType = "RMNHome"
OnRamp deployment.ContractType = "OnRamp"
OffRamp deployment.ContractType = "OffRamp"
CapabilitiesRegistry deployment.ContractType = "CapabilitiesRegistry"
PriceFeed deployment.ContractType = "PriceFeed"
// Note test router maps to a regular router contract.

// Test contracts. Note test router maps to a regular router contract.
TestRouter deployment.ContractType = "TestRouter"
Multicall3 deployment.ContractType = "Multicall3"
CCIPReceiver deployment.ContractType = "CCIPReceiver"
BurnMintToken deployment.ContractType = "BurnMintToken"
BurnMintTokenPool deployment.ContractType = "BurnMintTokenPool"
USDCToken deployment.ContractType = "USDCToken"
USDCMockTransmitter deployment.ContractType = "USDCMockTransmitter"
USDCTokenMessenger deployment.ContractType = "USDCTokenMessenger"
USDCTokenPool deployment.ContractType = "USDCTokenPool"

// Pools
BurnMintToken deployment.ContractType = "BurnMintToken"
BurnMintTokenPool deployment.ContractType = "BurnMintTokenPool"
USDCToken deployment.ContractType = "USDCToken"
USDCTokenMessenger deployment.ContractType = "USDCTokenMessenger"
USDCTokenPool deployment.ContractType = "USDCTokenPool"
)

// CCIPChainState holds a Go binding for all the currently deployed CCIP contracts
Expand Down Expand Up @@ -117,8 +121,6 @@ type CCIPChainState struct {
CapabilityRegistry *capabilities_registry.CapabilitiesRegistry
CCIPHome *ccip_home.CCIPHome
RMNHome *rmn_home.RMNHome
// TODO remove once staging upgraded.
CCIPConfig *ccip_config.CCIPConfig

// Test contracts
Receiver *maybe_revert_message_receiver.MaybeRevertMessageReceiver
Expand Down Expand Up @@ -205,6 +207,13 @@ func (c CCIPChainState) GenerateView() (view.ChainView, error) {
}
chainView.RMNProxy[c.RMNProxyNew.Address().Hex()] = rmnProxyView
}
if c.CCIPHome != nil && c.CapabilityRegistry != nil {
chView, err := v1_6.GenerateCCIPHomeView(c.CapabilityRegistry, c.CCIPHome)
if err != nil {
return chainView, errors.Wrapf(err, "failed to generate CCIP home view for CCIP home %s", c.CCIPHome.Address())
}
chainView.CCIPHome[c.CCIPHome.Address().Hex()] = chView
}
if c.CapabilityRegistry != nil {
capRegView, err := common_v1_0.GenerateCapabilityRegistryView(c.CapabilityRegistry)
if err != nil {
Expand Down Expand Up @@ -453,13 +462,6 @@ func LoadChainState(chain deployment.Chain, addresses map[string]deployment.Type
return state, err
}
state.CCIPHome = ccipHome
case deployment.NewTypeAndVersion(CCIPConfig, deployment.Version1_0_0).String():
// TODO: Remove once staging upgraded.
ccipConfig, err := ccip_config.NewCCIPConfig(common.HexToAddress(address), chain.Client)
if err != nil {
return state, err
}
state.CCIPConfig = ccipConfig
case deployment.NewTypeAndVersion(CCIPReceiver, deployment.Version1_0_0).String():
mr, err := maybe_revert_message_receiver.NewMaybeRevertMessageReceiver(common.HexToAddress(address), chain.Client)
if err != nil {
Expand Down
45 changes: 45 additions & 0 deletions deployment/ccip/view/v1_2/price_registry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package v1_2

import (
"fmt"

"github.com/ethereum/go-ethereum/common"

"github.com/smartcontractkit/chainlink/deployment/common/view/types"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/price_registry_1_2_0"
)

type PriceRegistryView struct {
types.ContractMetaData
FeeTokens []common.Address `json:"feeTokens"`
StalenessThreshold string `json:"stalenessThreshold"`
Updaters []common.Address `json:"updaters"`
}

func GeneratePriceRegistryView(pr *price_registry_1_2_0.PriceRegistry) (PriceRegistryView, error) {
if pr == nil {
return PriceRegistryView{}, fmt.Errorf("cannot generate view for nil PriceRegistry")
}
meta, err := types.NewContractMetaData(pr, pr.Address())
if err != nil {
return PriceRegistryView{}, fmt.Errorf("failed to generate contract metadata for PriceRegistry %s: %w", pr.Address(), err)
}
ft, err := pr.GetFeeTokens(nil)
if err != nil {
return PriceRegistryView{}, fmt.Errorf("failed to get fee tokens %s: %w", pr.Address(), err)
}
st, err := pr.GetStalenessThreshold(nil)
if err != nil {
return PriceRegistryView{}, fmt.Errorf("failed to get staleness threshold %s: %w", pr.Address(), err)
}
updaters, err := pr.GetPriceUpdaters(nil)
if err != nil {
return PriceRegistryView{}, fmt.Errorf("failed to get price updaters %s: %w", pr.Address(), err)
}
return PriceRegistryView{
ContractMetaData: meta,
FeeTokens: ft,
StalenessThreshold: st.String(),
Updaters: updaters,
}, nil
}
38 changes: 38 additions & 0 deletions deployment/ccip/view/v1_2/price_registry_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package v1_2

import (
"encoding/json"
"testing"

"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zapcore"

"github.com/smartcontractkit/chainlink/deployment"
"github.com/smartcontractkit/chainlink/deployment/environment/memory"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/price_registry_1_2_0"
"github.com/smartcontractkit/chainlink/v2/core/logger"
)

func TestGeneratePriceRegistryView(t *testing.T) {
e := memory.NewMemoryEnvironment(t, logger.TestLogger(t), zapcore.InfoLevel, memory.MemoryEnvironmentConfig{
Chains: 1,
})
chain := e.Chains[e.AllChainSelectors()[0]]
f1, f2 := common.HexToAddress("0x1"), common.HexToAddress("0x2")
_, tx, c, err := price_registry_1_2_0.DeployPriceRegistry(
chain.DeployerKey, chain.Client, []common.Address{chain.DeployerKey.From}, []common.Address{f1, f2}, uint32(10))
_, err = deployment.ConfirmIfNoError(chain, tx, err)
require.NoError(t, err)

v, err := GeneratePriceRegistryView(c)
require.NoError(t, err)
assert.Equal(t, v.Owner, chain.DeployerKey.From)
assert.Equal(t, v.TypeAndVersion, "PriceRegistry 1.2.0")
assert.Equal(t, v.FeeTokens, []common.Address{f1, f2})
assert.Equal(t, v.StalenessThreshold, "10")
assert.Equal(t, v.Updaters, []common.Address{chain.DeployerKey.From})
_, err = json.MarshalIndent(v, "", " ")
require.NoError(t, err)
}
40 changes: 40 additions & 0 deletions deployment/ccip/view/v1_5/offramp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package v1_5

import (
"fmt"

"github.com/smartcontractkit/chainlink/deployment/common/view/types"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/evm_2_evm_offramp"
)

type OffRampView struct {
types.ContractMetaData
StaticConfig evm_2_evm_offramp.EVM2EVMOffRampStaticConfig `json:"staticConfig"`
DynamicConfig evm_2_evm_offramp.EVM2EVMOffRampDynamicConfig `json:"dynamicConfig"`
}

func GenerateOffRampView(r *evm_2_evm_offramp.EVM2EVMOffRamp) (OffRampView, error) {
if r == nil {
return OffRampView{}, fmt.Errorf("cannot generate view for nil OffRamp")
}
meta, err := types.NewContractMetaData(r, r.Address())
if err != nil {
return OffRampView{}, fmt.Errorf("failed to generate contract metadata for OffRamp %s: %w", r.Address(), err)
}
staticConfig, err := r.GetStaticConfig(nil)
if err != nil {
return OffRampView{}, fmt.Errorf("failed to get static config for OffRamp %s: %w", r.Address(), err)
}
dynamicConfig, err := r.GetDynamicConfig(nil)
if err != nil {
return OffRampView{}, fmt.Errorf("failed to get dynamic config for OffRamp %s: %w", r.Address(), err)
}

// TODO: If needed, we can filter logs to get the OCR config.
// May not be required for the legacy contracts.
return OffRampView{
ContractMetaData: meta,
StaticConfig: staticConfig,
DynamicConfig: dynamicConfig,
}, nil
}
60 changes: 60 additions & 0 deletions deployment/ccip/view/v1_5/offramp_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package v1_5

import (
"encoding/json"
"testing"

"github.com/ethereum/go-ethereum/common"
chainsel "github.com/smartcontractkit/chain-selectors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zapcore"

"math/big"

"github.com/smartcontractkit/chainlink/deployment"
"github.com/smartcontractkit/chainlink/deployment/environment/memory"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/commit_store"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/evm_2_evm_offramp"
"github.com/smartcontractkit/chainlink/v2/core/logger"
)

func TestOffRampView(t *testing.T) {
e := memory.NewMemoryEnvironment(t, logger.TestLogger(t), zapcore.InfoLevel, memory.MemoryEnvironmentConfig{
Chains: 1,
})
chain := e.Chains[e.AllChainSelectors()[0]]
_, tx, c, err := commit_store.DeployCommitStore(
chain.DeployerKey, chain.Client, commit_store.CommitStoreStaticConfig{
ChainSelector: chainsel.TEST_90000002.Selector,
SourceChainSelector: chainsel.TEST_90000001.Selector,
OnRamp: common.HexToAddress("0x4"),
RmnProxy: common.HexToAddress("0x1"),
})
_, err = deployment.ConfirmIfNoError(chain, tx, err)
require.NoError(t, err)
sc := evm_2_evm_offramp.EVM2EVMOffRampStaticConfig{
ChainSelector: chainsel.TEST_90000002.Selector,
SourceChainSelector: chainsel.TEST_90000001.Selector,
RmnProxy: common.HexToAddress("0x1"),
CommitStore: c.Address(),
TokenAdminRegistry: common.HexToAddress("0x3"),
OnRamp: common.HexToAddress("0x4"),
}
rl := evm_2_evm_offramp.RateLimiterConfig{
IsEnabled: true,
Capacity: big.NewInt(100),
Rate: big.NewInt(10),
}
_, tx, c2, err := evm_2_evm_offramp.DeployEVM2EVMOffRamp(
chain.DeployerKey, chain.Client, sc, rl)
_, err = deployment.ConfirmIfNoError(chain, tx, err)
require.NoError(t, err)

v, err := GenerateOffRampView(c2)
require.NoError(t, err)
assert.Equal(t, v.StaticConfig, sc)
assert.Equal(t, v.TypeAndVersion, "EVM2EVMOffRamp 1.5.0")
_, err = json.MarshalIndent(v, "", " ")
require.NoError(t, err)
}
39 changes: 39 additions & 0 deletions deployment/ccip/view/v1_5/onramp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package v1_5

import (
"fmt"

"github.com/smartcontractkit/chainlink/deployment/common/view/types"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/evm_2_evm_onramp"
)

type OnRampView struct {
types.ContractMetaData
StaticConfig evm_2_evm_onramp.EVM2EVMOnRampStaticConfig `json:"staticConfig"`
DynamicConfig evm_2_evm_onramp.EVM2EVMOnRampDynamicConfig `json:"dynamicConfig"`
}

func GenerateOnRampView(r *evm_2_evm_onramp.EVM2EVMOnRamp) (OnRampView, error) {
if r == nil {
return OnRampView{}, fmt.Errorf("cannot generate view for nil OnRamp")
}
meta, err := types.NewContractMetaData(r, r.Address())
if err != nil {
return OnRampView{}, fmt.Errorf("failed to generate contract metadata for OnRamp %s: %w", r.Address(), err)
}
staticConfig, err := r.GetStaticConfig(nil)
if err != nil {
return OnRampView{}, fmt.Errorf("failed to get static config for OnRamp %s: %w", r.Address(), err)
}
dynamicConfig, err := r.GetDynamicConfig(nil)
if err != nil {
return OnRampView{}, fmt.Errorf("failed to get dynamic config for OnRamp %s: %w", r.Address(), err)
}

// Add billing if needed, maybe not required for legacy contract?
return OnRampView{
ContractMetaData: meta,
StaticConfig: staticConfig,
DynamicConfig: dynamicConfig,
}, nil
}
71 changes: 71 additions & 0 deletions deployment/ccip/view/v1_5/onramp_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package v1_5

import (
"encoding/json"
"math/big"
"testing"

"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zapcore"

"github.com/smartcontractkit/chainlink/deployment"
"github.com/smartcontractkit/chainlink/deployment/environment/memory"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/evm_2_evm_onramp"
"github.com/smartcontractkit/chainlink/v2/core/logger"
)

func TestOnRampView(t *testing.T) {
e := memory.NewMemoryEnvironment(t, logger.TestLogger(t), zapcore.InfoLevel, memory.MemoryEnvironmentConfig{
Chains: 1,
})
chain := e.Chains[e.AllChainSelectors()[0]]
_, tx, c, err := evm_2_evm_onramp.DeployEVM2EVMOnRamp(
chain.DeployerKey, chain.Client,
evm_2_evm_onramp.EVM2EVMOnRampStaticConfig{
LinkToken: common.HexToAddress("0x1"),
ChainSelector: chain.Selector,
DestChainSelector: 100,
DefaultTxGasLimit: 10,
MaxNopFeesJuels: big.NewInt(10),
PrevOnRamp: common.Address{},
RmnProxy: common.HexToAddress("0x2"),
TokenAdminRegistry: common.HexToAddress("0x3"),
},
evm_2_evm_onramp.EVM2EVMOnRampDynamicConfig{
Router: common.HexToAddress("0x4"),
MaxNumberOfTokensPerMsg: 0,
DestGasOverhead: 0,
DestGasPerPayloadByte: 0,
DestDataAvailabilityOverheadGas: 0,
DestGasPerDataAvailabilityByte: 0,
DestDataAvailabilityMultiplierBps: 0,
PriceRegistry: common.HexToAddress("0x5"),
MaxDataBytes: 0,
MaxPerMsgGasLimit: 0,
DefaultTokenFeeUSDCents: 0,
DefaultTokenDestGasOverhead: 0,
EnforceOutOfOrder: false,
},
evm_2_evm_onramp.RateLimiterConfig{
IsEnabled: true,
Capacity: big.NewInt(100),
Rate: big.NewInt(10),
},
[]evm_2_evm_onramp.EVM2EVMOnRampFeeTokenConfigArgs{},
[]evm_2_evm_onramp.EVM2EVMOnRampTokenTransferFeeConfigArgs{},
[]evm_2_evm_onramp.EVM2EVMOnRampNopAndWeight{},
)
_, err = deployment.ConfirmIfNoError(chain, tx, err)
require.NoError(t, err)
v, err := GenerateOnRampView(c)
require.NoError(t, err)
// Check a few fields.
assert.Equal(t, v.StaticConfig.ChainSelector, chain.Selector)
assert.Equal(t, v.DynamicConfig.Router, common.HexToAddress("0x4"))
assert.Equal(t, v.TypeAndVersion, "EVM2EVMOnRamp 1.5.0")
_, err = json.MarshalIndent(v, "", " ")
require.NoError(t, err)

}
Loading

0 comments on commit 266c147

Please sign in to comment.