Skip to content
23 changes: 12 additions & 11 deletions chains/evm/deployment/v2_0_0/adapters/chain_family.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"k8s.io/utils/ptr"

cldf_chain "github.com/smartcontractkit/chainlink-deployments-framework/chain"
"github.com/smartcontractkit/chainlink-deployments-framework/datastore"
Expand Down Expand Up @@ -184,18 +185,18 @@ func (a *ChainFamilyAdapter) GetChainFamilySelector() [4]byte {
return evmFamilySelector
}

func (a *ChainFamilyAdapter) GetDefaultFeeQuoterDestChainConfig() ccvadapters.FeeQuoterDestChainConfig {
return ccvadapters.FeeQuoterDestChainConfig{
IsEnabled: true,
MaxDataBytes: 32_000,
MaxPerMsgGasLimit: 8_000_000,
DestGasPerPayloadByteBase: 20,
func (a *ChainFamilyAdapter) GetDefaultFeeQuoterDestChainConfig() ccvadapters.FeeQuoterDestChainConfigOverrides {
return ccvadapters.FeeQuoterDestChainConfigOverrides{
IsEnabled: ptr.To(true),
MaxDataBytes: ptr.To(uint32(32_000)),
MaxPerMsgGasLimit: ptr.To(uint32(8_000_000)),
DestGasPerPayloadByteBase: ptr.To(uint8(20)),
ChainFamilySelector: evmFamilySelector,
DefaultTokenFeeUSDCents: 25,
DefaultTokenDestGasOverhead: 90_000,
DefaultTxGasLimit: 200_000,
NetworkFeeUSDCents: 10,
LinkFeeMultiplierPercent: 90,
DefaultTokenFeeUSDCents: ptr.To(uint16(25)),
DefaultTokenDestGasOverhead: ptr.To(uint32(90_000)),
DefaultTxGasLimit: ptr.To(uint32(200_000)),
NetworkFeeUSDCents: ptr.To(uint16(10)),
LinkFeeMultiplierPercent: ptr.To(uint8(90)),
// USDPerUnitGas is not set here to avoid doing a gas price update by default
}
}
Expand Down
133 changes: 71 additions & 62 deletions chains/evm/deployment/v2_0_0/sequences/configure_chain_for_lanes.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/Masterminds/semver/v3"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"k8s.io/utils/ptr"

mcms_types "github.com/smartcontractkit/mcms/types"

Expand All @@ -20,13 +21,14 @@ import (
seqtypes "github.com/smartcontractkit/chainlink-ccip/deployment/utils/sequences"
changesetadapters "github.com/smartcontractkit/chainlink-ccip/deployment/v2_0_0/adapters"

fqc "github.com/smartcontractkit/chainlink-ccip/chains/evm/gobindings/generated/v2_0_0/fee_quoter"

"github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v2_0_0/operations/committee_verifier"
"github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v2_0_0/operations/fee_quoter"
"github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v2_0_0/operations/offramp"
"github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v2_0_0/operations/onramp"
"github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v2_0_0/operations/proxy"
"github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v2_0_0/versioned_verifier_resolver"
fqc "github.com/smartcontractkit/chainlink-ccip/chains/evm/gobindings/generated/v2_0_0/fee_quoter"
)

// ConfigureChainForLanes is the canonical sequence for configuring an EVM chain to participate
Expand Down Expand Up @@ -126,7 +128,7 @@ var ConfigureChainForLanes = cldf_ops.NewSequence(
return seqtypes.OnChainOutput{}, fmt.Errorf("remote chain %d: %w", remoteSelector, err)
}

if remoteConfig.FeeQuoterDestChainConfig.USDPerUnitGas != nil {
if remoteConfig.FeeQuoterDestChainConfigOverrides.USDPerUnitGas != nil {
gasPriceReport, err := cldf_ops.ExecuteOperation(b, fee_quoter.GetDestinationChainGasPrice, chain, contract.FunctionInput[uint64]{
ChainSelector: chain.Selector,
Address: feeQuoterAddr,
Expand All @@ -135,10 +137,10 @@ var ConfigureChainForLanes = cldf_ops.NewSequence(
if err != nil {
return seqtypes.OnChainOutput{}, fmt.Errorf("failed to get gas prices on FeeQuoter(%s) on chain %s: %w", feeQuoterAddr, chain, err)
}
if remoteConfig.FeeQuoterDestChainConfig.USDPerUnitGas.Cmp(gasPriceReport.Output.Value) != 0 {
if remoteConfig.FeeQuoterDestChainConfigOverrides.USDPerUnitGas.Cmp(gasPriceReport.Output.Value) != 0 {
gasPriceUpdates = append(gasPriceUpdates, fee_quoter.GasPriceUpdate{
DestChainSelector: remoteSelector,
UsdPerUnitGas: remoteConfig.FeeQuoterDestChainConfig.USDPerUnitGas,
UsdPerUnitGas: remoteConfig.FeeQuoterDestChainConfigOverrides.USDPerUnitGas,
})
}
}
Expand Down Expand Up @@ -185,8 +187,8 @@ var ConfigureChainForLanes = cldf_ops.NewSequence(

// FeeQuoter dest chain config: when OverrideExistingConfig is false, we skip
// chains that already have an enabled config to avoid accidentally overwriting
// production parameters. When true, we always diff and update.
if !remoteConfig.FeeQuoterDestChainConfig.OverrideExistingConfig {
// production parameters. When true, we always update.
if !remoteConfig.FeeQuoterDestChainConfigOverrides.OverrideExistingConfig {
destChainCfg, err := feeQContract.GetDestChainConfig(&bind.CallOpts{Context: b.GetContext()}, remoteSelector)
if err != nil {
return seqtypes.OnChainOutput{}, fmt.Errorf("failed to get dest chain config for remote chain selector %d from fee quoter at address %s on chain %s: %w", remoteSelector, feeQuoterAddr, chain.String(), err)
Expand Down Expand Up @@ -492,18 +494,58 @@ func maybeAddOnRampDestChainConfigArgOnLocalChain(

// USDPerUnitGas is intentionally excluded because it is updated via a separate
// FeeQuoter.UpdatePrices call (gas prices live in a different on-chain mapping).
func feeQuoterDestChainConfigEqualTo(cur fqc.FeeQuoterDestChainConfig, desired changesetadapters.FeeQuoterDestChainConfig) bool {
return cur.IsEnabled == desired.IsEnabled &&
cur.MaxDataBytes == desired.MaxDataBytes &&
cur.MaxPerMsgGasLimit == desired.MaxPerMsgGasLimit &&
cur.DestGasOverhead == desired.DestGasOverhead &&
cur.DestGasPerPayloadByteBase == desired.DestGasPerPayloadByteBase &&
func feeQuoterDestChainConfigEqualTo(cur fqc.FeeQuoterDestChainConfig, desired changesetadapters.FeeQuoterDestChainConfigOverrides) bool {
return cur.IsEnabled == *desired.IsEnabled &&
cur.MaxDataBytes == *desired.MaxDataBytes &&
cur.MaxPerMsgGasLimit == *desired.MaxPerMsgGasLimit &&
cur.DestGasOverhead == *desired.DestGasOverhead &&
cur.DestGasPerPayloadByteBase == *desired.DestGasPerPayloadByteBase &&
cur.ChainFamilySelector == desired.ChainFamilySelector &&
cur.DefaultTokenFeeUSDCents == desired.DefaultTokenFeeUSDCents &&
cur.DefaultTokenDestGasOverhead == desired.DefaultTokenDestGasOverhead &&
cur.DefaultTxGasLimit == desired.DefaultTxGasLimit &&
cur.NetworkFeeUSDCents == desired.NetworkFeeUSDCents &&
cur.LinkFeeMultiplierPercent == desired.LinkFeeMultiplierPercent
cur.DefaultTokenFeeUSDCents == *desired.DefaultTokenFeeUSDCents &&
cur.DefaultTokenDestGasOverhead == *desired.DefaultTokenDestGasOverhead &&
cur.DefaultTxGasLimit == *desired.DefaultTxGasLimit &&
cur.NetworkFeeUSDCents == *desired.NetworkFeeUSDCents &&
cur.LinkFeeMultiplierPercent == *desired.LinkFeeMultiplierPercent
}

func fillFeeQuoterDestChainConfigOverridesFromOnChain(
desired changesetadapters.FeeQuoterDestChainConfigOverrides,
cur fqc.FeeQuoterDestChainConfig,
) changesetadapters.FeeQuoterDestChainConfigOverrides {
if desired.IsEnabled == nil {
desired.IsEnabled = ptr.To(cur.IsEnabled)
}
if desired.MaxDataBytes == nil {
desired.MaxDataBytes = ptr.To(cur.MaxDataBytes)
}
if desired.MaxPerMsgGasLimit == nil {
desired.MaxPerMsgGasLimit = ptr.To(cur.MaxPerMsgGasLimit)
}
if desired.DestGasOverhead == nil {
desired.DestGasOverhead = ptr.To(cur.DestGasOverhead)
}
if desired.DestGasPerPayloadByteBase == nil {
desired.DestGasPerPayloadByteBase = ptr.To(cur.DestGasPerPayloadByteBase)
}
if desired.ChainFamilySelector == [4]byte{} {
desired.ChainFamilySelector = cur.ChainFamilySelector
}
if desired.DefaultTokenFeeUSDCents == nil {
desired.DefaultTokenFeeUSDCents = ptr.To(cur.DefaultTokenFeeUSDCents)
}
if desired.DefaultTokenDestGasOverhead == nil {
desired.DefaultTokenDestGasOverhead = ptr.To(cur.DefaultTokenDestGasOverhead)
}
if desired.DefaultTxGasLimit == nil {
desired.DefaultTxGasLimit = ptr.To(cur.DefaultTxGasLimit)
}
if desired.NetworkFeeUSDCents == nil {
desired.NetworkFeeUSDCents = ptr.To(cur.NetworkFeeUSDCents)
}
if desired.LinkFeeMultiplierPercent == nil {
desired.LinkFeeMultiplierPercent = ptr.To(cur.LinkFeeMultiplierPercent)
}
return desired
}

// maybeAddFeeQuoterDestChainConfigArgOnLocalChain compares the desired FeeQuoter dest chain
Expand Down Expand Up @@ -531,40 +573,7 @@ func maybeAddFeeQuoterDestChainConfigArgOnLocalChain(
cur = fetched
}

desired := remoteConfig.FeeQuoterDestChainConfig
if !desired.IsEnabled {
desired.IsEnabled = cur.IsEnabled
}
if desired.MaxDataBytes == 0 {
desired.MaxDataBytes = cur.MaxDataBytes
}
if desired.MaxPerMsgGasLimit == 0 {
desired.MaxPerMsgGasLimit = cur.MaxPerMsgGasLimit
}
if desired.DestGasOverhead == 0 {
desired.DestGasOverhead = cur.DestGasOverhead
}
if desired.DestGasPerPayloadByteBase == 0 {
desired.DestGasPerPayloadByteBase = cur.DestGasPerPayloadByteBase
}
if desired.ChainFamilySelector == [4]byte{} {
desired.ChainFamilySelector = cur.ChainFamilySelector
}
if desired.DefaultTokenFeeUSDCents == 0 {
desired.DefaultTokenFeeUSDCents = cur.DefaultTokenFeeUSDCents
}
if desired.DefaultTokenDestGasOverhead == 0 {
desired.DefaultTokenDestGasOverhead = cur.DefaultTokenDestGasOverhead
}
if desired.DefaultTxGasLimit == 0 {
desired.DefaultTxGasLimit = cur.DefaultTxGasLimit
}
if desired.NetworkFeeUSDCents == 0 {
desired.NetworkFeeUSDCents = cur.NetworkFeeUSDCents
}
if desired.LinkFeeMultiplierPercent == 0 {
desired.LinkFeeMultiplierPercent = cur.LinkFeeMultiplierPercent
}
desired := fillFeeQuoterDestChainConfigOverridesFromOnChain(remoteConfig.FeeQuoterDestChainConfigOverrides, cur)
if feeQuoterDestChainConfigEqualTo(cur, desired) {
return feeQuoterArgs, nil
}
Expand Down Expand Up @@ -835,19 +844,19 @@ func configureCommitteeVerifierAsDest(
return writes, nil
}

func adapterDestChainConfigToFeeQuoterV2(cfg changesetadapters.FeeQuoterDestChainConfig) fee_quoter.DestChainConfig {
func adapterDestChainConfigToFeeQuoterV2(cfg changesetadapters.FeeQuoterDestChainConfigOverrides) fee_quoter.DestChainConfig {
return fee_quoter.DestChainConfig{
IsEnabled: cfg.IsEnabled,
MaxDataBytes: cfg.MaxDataBytes,
MaxPerMsgGasLimit: cfg.MaxPerMsgGasLimit,
DestGasOverhead: cfg.DestGasOverhead,
DestGasPerPayloadByteBase: cfg.DestGasPerPayloadByteBase,
IsEnabled: *cfg.IsEnabled,
MaxDataBytes: *cfg.MaxDataBytes,
MaxPerMsgGasLimit: *cfg.MaxPerMsgGasLimit,
DestGasOverhead: *cfg.DestGasOverhead,
DestGasPerPayloadByteBase: *cfg.DestGasPerPayloadByteBase,
ChainFamilySelector: cfg.ChainFamilySelector,
DefaultTokenFeeUSDCents: cfg.DefaultTokenFeeUSDCents,
DefaultTokenDestGasOverhead: cfg.DefaultTokenDestGasOverhead,
DefaultTxGasLimit: cfg.DefaultTxGasLimit,
NetworkFeeUSDCents: cfg.NetworkFeeUSDCents,
LinkFeeMultiplierPercent: cfg.LinkFeeMultiplierPercent,
DefaultTokenFeeUSDCents: *cfg.DefaultTokenFeeUSDCents,
DefaultTokenDestGasOverhead: *cfg.DefaultTokenDestGasOverhead,
DefaultTxGasLimit: *cfg.DefaultTxGasLimit,
NetworkFeeUSDCents: *cfg.NetworkFeeUSDCents,
LinkFeeMultiplierPercent: *cfg.LinkFeeMultiplierPercent,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"github.com/smartcontractkit/chainlink-deployments-framework/operations"

chainsel "github.com/smartcontractkit/chain-selectors"
"github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/utils/operations/contract"
"github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v1_2_0/operations/router"
"github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v2_0_0/create2_factory"
"github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v2_0_0/operations/committee_verifier"
"github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v2_0_0/operations/executor"
Expand All @@ -24,15 +26,15 @@ import (
"github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v2_0_0/operations/onramp"
"github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v2_0_0/sequences"
"github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v2_0_0/testsetup"
"github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/utils/operations/contract"
"github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v1_2_0/operations/router"
changesetadapters "github.com/smartcontractkit/chainlink-ccip/deployment/v2_0_0/adapters"
)

var evmFamilySelector = [4]byte{0x28, 0x12, 0xd5, 0x2c}

func boolPtr(v bool) *bool { return &v }

func uint32Ptr(v uint32) *uint32 { return &v }

type deployedContracts struct {
router string
onRamp string
Expand Down Expand Up @@ -131,19 +133,7 @@ func buildConfigureChainForLanesInput(
DefaultExecutor: local.executor,
DefaultInboundCCVs: []string{local.committeeVerifier},
DefaultOutboundCCVs: []string{local.committeeVerifier},
FeeQuoterDestChainConfig: changesetadapters.FeeQuoterDestChainConfig{
IsEnabled: true,
MaxDataBytes: 30_000,
MaxPerMsgGasLimit: 3_000_000,
DestGasOverhead: 300_000,
DefaultTokenFeeUSDCents: 25,
DestGasPerPayloadByteBase: 16,
DefaultTokenDestGasOverhead: 90_000,
DefaultTxGasLimit: 200_000,
NetworkFeeUSDCents: 10,
ChainFamilySelector: evmFamilySelector,
LinkFeeMultiplierPercent: 90,
},
FeeQuoterDestChainConfigOverrides: testsetup.CreateBasicFeeQuoterDestChainConfigOverrides(),
ExecutorDestChainConfig: changesetadapters.ExecutorDestChainConfig{
USDCentsFee: 50,
Enabled: true,
Expand Down Expand Up @@ -552,19 +542,17 @@ func TestConfigureChainForLanes_ConfiguresMultipleRemoteChainsInSingleCall(t *te
DefaultExecutor: local.executor,
DefaultInboundCCVs: []string{local.committeeVerifier},
DefaultOutboundCCVs: []string{local.committeeVerifier},
FeeQuoterDestChainConfig: changesetadapters.FeeQuoterDestChainConfig{
IsEnabled: true,
MaxDataBytes: 50_000,
MaxPerMsgGasLimit: 5_000_000,
DestGasOverhead: 400_000,
DefaultTokenFeeUSDCents: 30,
DestGasPerPayloadByteBase: 16,
DefaultTokenDestGasOverhead: 100_000,
DefaultTxGasLimit: 250_000,
NetworkFeeUSDCents: 20,
ChainFamilySelector: evmFamilySelector,
LinkFeeMultiplierPercent: 90,
},
FeeQuoterDestChainConfigOverrides: func() changesetadapters.FeeQuoterDestChainConfigOverrides {
cfg := testsetup.CreateBasicFeeQuoterDestChainConfigOverrides()
cfg.MaxDataBytes = uint32Ptr(50_000)
cfg.MaxPerMsgGasLimit = uint32Ptr(5_000_000)
cfg.DestGasOverhead = uint32Ptr(400_000)
cfg.DefaultTokenFeeUSDCents = func() *uint16 { v := uint16(30); return &v }()
cfg.DefaultTokenDestGasOverhead = uint32Ptr(100_000)
cfg.DefaultTxGasLimit = uint32Ptr(250_000)
cfg.NetworkFeeUSDCents = func() *uint16 { v := uint16(20); return &v }()
return cfg
}(),
ExecutorDestChainConfig: changesetadapters.ExecutorDestChainConfig{
USDCentsFee: 100,
Enabled: true,
Expand Down Expand Up @@ -765,9 +753,9 @@ func TestConfigureChainForLanes_PartialUpdatePreservesExistingFields(t *testing.
DefaultInboundCCVs: []string{local.committeeVerifier},
DefaultOutboundCCVs: []string{local.committeeVerifier},
BaseExecutionGasCost: 120_000,
FeeQuoterDestChainConfig: changesetadapters.FeeQuoterDestChainConfig{
FeeQuoterDestChainConfigOverrides: changesetadapters.FeeQuoterDestChainConfigOverrides{
OverrideExistingConfig: true,
DestGasOverhead: 500_000,
DestGasOverhead: uint32Ptr(500_000),
},
DefaultExecutor: local.executor,
ExecutorDestChainConfig: changesetadapters.ExecutorDestChainConfig{
Expand Down Expand Up @@ -835,8 +823,8 @@ func TestConfigureChainForLanes_OverrideExistingFeeQuoterConfig(t *testing.T) {

noOverrideInput := buildConfigureChainForLanesInput(local, chainSelector, remote, remoteSelector)
rc := noOverrideInput.RemoteChains[remoteSelector]
rc.FeeQuoterDestChainConfig.OverrideExistingConfig = false
rc.FeeQuoterDestChainConfig.MaxDataBytes = 99_000
rc.FeeQuoterDestChainConfigOverrides.OverrideExistingConfig = false
rc.FeeQuoterDestChainConfigOverrides.MaxDataBytes = uint32Ptr(99_000)
noOverrideInput.RemoteChains[remoteSelector] = rc

_, err = operations.ExecuteSequence(
Expand All @@ -855,8 +843,8 @@ func TestConfigureChainForLanes_OverrideExistingFeeQuoterConfig(t *testing.T) {

overrideInput := buildConfigureChainForLanesInput(local, chainSelector, remote, remoteSelector)
rc = overrideInput.RemoteChains[remoteSelector]
rc.FeeQuoterDestChainConfig.OverrideExistingConfig = true
rc.FeeQuoterDestChainConfig.MaxDataBytes = 99_000
rc.FeeQuoterDestChainConfigOverrides.OverrideExistingConfig = true
rc.FeeQuoterDestChainConfigOverrides.MaxDataBytes = uint32Ptr(99_000)
overrideInput.RemoteChains[remoteSelector] = rc

_, err = operations.ExecuteSequence(
Expand Down Expand Up @@ -1188,7 +1176,7 @@ func TestConfigureChainForLanes_GasPriceUpdateSkippedWhenAlreadySet(t *testing.T

input := buildConfigureChainForLanesInput(local, chainSelector, remote, remoteChainSelector)
rc := input.RemoteChains[remoteChainSelector]
rc.FeeQuoterDestChainConfig.USDPerUnitGas = big.NewInt(42_000)
rc.FeeQuoterDestChainConfigOverrides.USDPerUnitGas = big.NewInt(42_000)
input.RemoteChains[remoteChainSelector] = rc

report1, err := operations.ExecuteSequence(
Expand Down
22 changes: 5 additions & 17 deletions chains/evm/deployment/v2_0_0/testadapter/test_adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@ type laneContracts struct {
addresses []datastore.AddressRef
}

// evmFamilySelector is bytes4(keccak256("CCIP ChainFamilySelector EVM")) = 0x2812d52c.
var evmFamilySelector = [4]byte{0x28, 0x12, 0xd5, 0x2c}

func boolPtr(v bool) *bool { return &v }

func deployLaneContracts(t *testing.T, env *deployment.Environment, chain cldf_evm.Chain, chainSelector uint64) laneContracts {
Expand Down Expand Up @@ -206,20 +203,11 @@ func buildConfigureChainForLanesInput(
DefaultExecutor: local.executor,
DefaultInboundCCVs: []string{local.committeeVerifier},
DefaultOutboundCCVs: []string{local.committeeVerifier},
FeeQuoterDestChainConfig: changesetadapters.FeeQuoterDestChainConfig{
IsEnabled: true,
MaxDataBytes: 30_000,
MaxPerMsgGasLimit: 3_000_000,
DestGasOverhead: 300_000,
DefaultTokenFeeUSDCents: 25,
DestGasPerPayloadByteBase: 16,
DefaultTokenDestGasOverhead: 90_000,
DefaultTxGasLimit: 200_000,
NetworkFeeUSDCents: 10,
ChainFamilySelector: evmFamilySelector,
LinkFeeMultiplierPercent: 90,
USDPerUnitGas: big.NewInt(20_000_000_000_000),
},
FeeQuoterDestChainConfigOverrides: func() changesetadapters.FeeQuoterDestChainConfigOverrides {
cfg := testsetup.CreateBasicFeeQuoterDestChainConfigOverrides()
cfg.USDPerUnitGas = big.NewInt(20_000_000_000_000)
return cfg
}(),
ExecutorDestChainConfig: changesetadapters.ExecutorDestChainConfig{
USDCentsFee: 50,
Enabled: true,
Expand Down
Loading
Loading