Skip to content

Commit

Permalink
CCIP-3605 Registering CCTP/USDC events in ChainReader (#14624)
Browse files Browse the repository at this point in the history
* Using shared config for USDCReader

* Merging USDC chain reader config

* Changelog

* Bumping to the main version

* Bumping to the main version
  • Loading branch information
mateusz-sekara authored Oct 2, 2024
1 parent e724e5f commit be774f0
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 31 deletions.
5 changes: 5 additions & 0 deletions .changeset/metal-pots-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

Registering USDC/CCTP events in the ChainReader during oracle creation #internal
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import (
sel "github.com/smartcontractkit/chain-selectors"

"github.com/smartcontractkit/chainlink-ccip/execute/exectypes"
"github.com/smartcontractkit/chainlink-ccip/pkg/consts"
"github.com/smartcontractkit/chainlink-ccip/pkg/contractreader"
"github.com/smartcontractkit/chainlink-ccip/pkg/reader"
"github.com/smartcontractkit/chainlink-ccip/pluginconfig"
"github.com/smartcontractkit/chainlink-common/pkg/types"
cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3"

evmconfig "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/configs/evm"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/client"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/headtracker"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller"
Expand All @@ -48,24 +48,7 @@ func Test_USDCReader_MessageHashes(t *testing.T) {
polygonChain := cciptypes.ChainSelector(sel.POLYGON_MAINNET.Selector)
polygonDomainCCTP := reader.CCTPDestDomains[uint64(polygonChain)]

cfg := evmtypes.ChainReaderConfig{
Contracts: map[string]evmtypes.ChainContractReader{
consts.ContractNameCCTPMessageTransmitter: {
ContractPollingFilter: evmtypes.ContractPollingFilter{
GenericEventNames: []string{consts.EventNameCCTPMessageSent},
},
ContractABI: usdc_reader_tester.USDCReaderTesterABI,
Configs: map[string]*evmtypes.ChainReaderDefinition{
consts.EventNameCCTPMessageSent: {
ChainSpecificName: consts.EventNameCCTPMessageSent,
ReadType: evmtypes.Event,
},
},
},
},
}

ts := testSetup(ctx, t, ethereumChain, cfg)
ts := testSetup(ctx, t, ethereumChain, evmconfig.USDCReaderConfig)

usdcReader, err := reader.NewUSDCMessageReader(
map[cciptypes.ChainSelector]pluginconfig.USDCCCTPTokenConfig{
Expand Down
17 changes: 17 additions & 0 deletions core/capabilities/ccip/configs/evm/contract_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,23 @@ var FeedReaderConfig = evmrelaytypes.ChainReaderConfig{
},
}

var USDCReaderConfig = evmrelaytypes.ChainReaderConfig{
Contracts: map[string]evmrelaytypes.ChainContractReader{
consts.ContractNameCCTPMessageTransmitter: {
ContractABI: MessageTransmitterABI,
ContractPollingFilter: evmrelaytypes.ContractPollingFilter{
GenericEventNames: []string{consts.EventNameCCTPMessageSent},
},
Configs: map[string]*evmrelaytypes.ChainReaderDefinition{
consts.EventNameCCTPMessageSent: {
ChainSpecificName: consts.EventNameCCTPMessageSent,
ReadType: evmrelaytypes.Event,
},
},
},
},
}

// HomeChainReaderConfigRaw returns a ChainReaderConfig that can be used to read from the home chain.
var HomeChainReaderConfigRaw = evmrelaytypes.ChainReaderConfig{
Contracts: map[string]evmrelaytypes.ChainContractReader{
Expand Down
26 changes: 26 additions & 0 deletions core/capabilities/ccip/configs/evm/usdc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package evm

import (
evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
)

var (
// We need only ABI part of the contract that describes the event structure
// https://github.com/circlefin/evm-cctp-contracts/blob/377c9bd813fb86a42d900ae4003599d82aef635a/src/MessageTransmitter.sol#L41
MessageTransmitterABI = `[
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "bytes",
"name": "",
"type": "bytes"
}
],
"name": "MessageSent",
"type": "event"
}
]`
_ = evmtypes.MustGetABI(MessageTransmitterABI)
)
16 changes: 16 additions & 0 deletions core/capabilities/ccip/oraclecreator/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,12 +383,28 @@ func getChainReaderConfig(
chainReaderConfig = evmconfig.MergeReaderConfigs(chainReaderConfig, evmconfig.FeedReaderConfig)
}

if isUSDCEnabled(chainID, destChainID, ofc) {
chainReaderConfig = evmconfig.MergeReaderConfigs(chainReaderConfig, evmconfig.USDCReaderConfig)
}

if chainID == homeChainID {
chainReaderConfig = evmconfig.MergeReaderConfigs(chainReaderConfig, evmconfig.HomeChainReaderConfigRaw)
}
return chainReaderConfig
}

func isUSDCEnabled(chainID uint64, destChainID uint64, ofc offChainConfig) bool {
if chainID == destChainID {
return false
}

if ofc.execEmpty() {
return false
}

return ofc.exec().IsUSDCEnabled()
}

func createChainReader(
lggr logger.Logger,
chain legacyevm.Chain,
Expand Down
2 changes: 1 addition & 1 deletion core/scripts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ require (
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/shirou/gopsutil/v3 v3.24.3 // indirect
github.com/smartcontractkit/chain-selectors v1.0.23 // indirect
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240930203817-424892240cd1 // indirect
github.com/smartcontractkit/chainlink-ccip v0.0.0-20241002064705-34d7f9b7e26a // indirect
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240911175228-daf2600bb7b7 // indirect
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240916152957-433914114bd2 // indirect
github.com/smartcontractkit/chainlink-feeds v0.0.0-20240910155501-42f20443189f // indirect
Expand Down
4 changes: 2 additions & 2 deletions core/scripts/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1081,8 +1081,8 @@ github.com/smartcontractkit/chain-selectors v1.0.23 h1:D2Eaex4Cw/O7Lg3tX6WklOqnj
github.com/smartcontractkit/chain-selectors v1.0.23/go.mod h1:d4Hi+E1zqjy9HqMkjBE5q1vcG9VGgxf5VxiRHfzi2kE=
github.com/smartcontractkit/chainlink-automation v1.0.4 h1:iyW181JjKHLNMnDleI8umfIfVVlwC7+n5izbLSFgjw8=
github.com/smartcontractkit/chainlink-automation v1.0.4/go.mod h1:u4NbPZKJ5XiayfKHD/v3z3iflQWqvtdhj13jVZXj/cM=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240930203817-424892240cd1 h1:X07jKFIakpR7UyG/BnQ8wKZz395LsEcowqyQgDKHcT8=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240930203817-424892240cd1/go.mod h1:/nGkIe25kgtr+l6y30VH+aTVaxu0NjIEEEhtV1TDlaE=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20241002064705-34d7f9b7e26a h1:zHMknn5+VAOMzMk3LXT+GfCD17h252jTKreFyQwRaB0=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20241002064705-34d7f9b7e26a/go.mod h1:/nGkIe25kgtr+l6y30VH+aTVaxu0NjIEEEhtV1TDlaE=
github.com/smartcontractkit/chainlink-common v0.2.3-0.20241001140426-35be2fad06ec h1:zmLmKLCpoV73AaGU8YBc86YPLJBzoZFv9lPC677Eqcs=
github.com/smartcontractkit/chainlink-common v0.2.3-0.20241001140426-35be2fad06ec/go.mod h1:F6WUS6N4mP5ScwpwyTyAJc9/vjR+GXbMCRUOVekQi1g=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240911175228-daf2600bb7b7 h1:lTGIOQYLk1Ufn++X/AvZnt6VOcuhste5yp+C157No/Q=
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ require (
github.com/shopspring/decimal v1.4.0
github.com/smartcontractkit/chain-selectors v1.0.23
github.com/smartcontractkit/chainlink-automation v1.0.4
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240930203817-424892240cd1
github.com/smartcontractkit/chainlink-ccip v0.0.0-20241002064705-34d7f9b7e26a
github.com/smartcontractkit/chainlink-common v0.2.3-0.20241001140426-35be2fad06ec
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240911175228-daf2600bb7b7
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240916152957-433914114bd2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1054,8 +1054,8 @@ github.com/smartcontractkit/chain-selectors v1.0.23 h1:D2Eaex4Cw/O7Lg3tX6WklOqnj
github.com/smartcontractkit/chain-selectors v1.0.23/go.mod h1:d4Hi+E1zqjy9HqMkjBE5q1vcG9VGgxf5VxiRHfzi2kE=
github.com/smartcontractkit/chainlink-automation v1.0.4 h1:iyW181JjKHLNMnDleI8umfIfVVlwC7+n5izbLSFgjw8=
github.com/smartcontractkit/chainlink-automation v1.0.4/go.mod h1:u4NbPZKJ5XiayfKHD/v3z3iflQWqvtdhj13jVZXj/cM=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240930203817-424892240cd1 h1:X07jKFIakpR7UyG/BnQ8wKZz395LsEcowqyQgDKHcT8=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240930203817-424892240cd1/go.mod h1:/nGkIe25kgtr+l6y30VH+aTVaxu0NjIEEEhtV1TDlaE=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20241002064705-34d7f9b7e26a h1:zHMknn5+VAOMzMk3LXT+GfCD17h252jTKreFyQwRaB0=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20241002064705-34d7f9b7e26a/go.mod h1:/nGkIe25kgtr+l6y30VH+aTVaxu0NjIEEEhtV1TDlaE=
github.com/smartcontractkit/chainlink-common v0.2.3-0.20241001140426-35be2fad06ec h1:zmLmKLCpoV73AaGU8YBc86YPLJBzoZFv9lPC677Eqcs=
github.com/smartcontractkit/chainlink-common v0.2.3-0.20241001140426-35be2fad06ec/go.mod h1:F6WUS6N4mP5ScwpwyTyAJc9/vjR+GXbMCRUOVekQi1g=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240911175228-daf2600bb7b7 h1:lTGIOQYLk1Ufn++X/AvZnt6VOcuhste5yp+C157No/Q=
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ require (
github.com/smartcontractkit/ccip-owner-contracts v0.0.0-20240926212305-a6deabdfce86
github.com/smartcontractkit/chain-selectors v1.0.23
github.com/smartcontractkit/chainlink-automation v1.0.4
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240930203817-424892240cd1
github.com/smartcontractkit/chainlink-ccip v0.0.0-20241002064705-34d7f9b7e26a
github.com/smartcontractkit/chainlink-common v0.2.3-0.20241001140426-35be2fad06ec
github.com/smartcontractkit/chainlink-testing-framework/havoc v1.50.0
github.com/smartcontractkit/chainlink-testing-framework/lib v1.50.9
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1423,8 +1423,8 @@ github.com/smartcontractkit/chain-selectors v1.0.23 h1:D2Eaex4Cw/O7Lg3tX6WklOqnj
github.com/smartcontractkit/chain-selectors v1.0.23/go.mod h1:d4Hi+E1zqjy9HqMkjBE5q1vcG9VGgxf5VxiRHfzi2kE=
github.com/smartcontractkit/chainlink-automation v1.0.4 h1:iyW181JjKHLNMnDleI8umfIfVVlwC7+n5izbLSFgjw8=
github.com/smartcontractkit/chainlink-automation v1.0.4/go.mod h1:u4NbPZKJ5XiayfKHD/v3z3iflQWqvtdhj13jVZXj/cM=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240930203817-424892240cd1 h1:X07jKFIakpR7UyG/BnQ8wKZz395LsEcowqyQgDKHcT8=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240930203817-424892240cd1/go.mod h1:/nGkIe25kgtr+l6y30VH+aTVaxu0NjIEEEhtV1TDlaE=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20241002064705-34d7f9b7e26a h1:zHMknn5+VAOMzMk3LXT+GfCD17h252jTKreFyQwRaB0=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20241002064705-34d7f9b7e26a/go.mod h1:/nGkIe25kgtr+l6y30VH+aTVaxu0NjIEEEhtV1TDlaE=
github.com/smartcontractkit/chainlink-common v0.2.3-0.20241001140426-35be2fad06ec h1:zmLmKLCpoV73AaGU8YBc86YPLJBzoZFv9lPC677Eqcs=
github.com/smartcontractkit/chainlink-common v0.2.3-0.20241001140426-35be2fad06ec/go.mod h1:F6WUS6N4mP5ScwpwyTyAJc9/vjR+GXbMCRUOVekQi1g=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240911175228-daf2600bb7b7 h1:lTGIOQYLk1Ufn++X/AvZnt6VOcuhste5yp+C157No/Q=
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/load/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ require (
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/smartcontractkit/chain-selectors v1.0.23 // indirect
github.com/smartcontractkit/chainlink-automation v1.0.4 // indirect
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240930203817-424892240cd1 // indirect
github.com/smartcontractkit/chainlink-ccip v0.0.0-20241002064705-34d7f9b7e26a // indirect
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240911175228-daf2600bb7b7 // indirect
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240916152957-433914114bd2 // indirect
github.com/smartcontractkit/chainlink-feeds v0.0.0-20240910155501-42f20443189f // indirect
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/load/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1397,8 +1397,8 @@ github.com/smartcontractkit/chain-selectors v1.0.23 h1:D2Eaex4Cw/O7Lg3tX6WklOqnj
github.com/smartcontractkit/chain-selectors v1.0.23/go.mod h1:d4Hi+E1zqjy9HqMkjBE5q1vcG9VGgxf5VxiRHfzi2kE=
github.com/smartcontractkit/chainlink-automation v1.0.4 h1:iyW181JjKHLNMnDleI8umfIfVVlwC7+n5izbLSFgjw8=
github.com/smartcontractkit/chainlink-automation v1.0.4/go.mod h1:u4NbPZKJ5XiayfKHD/v3z3iflQWqvtdhj13jVZXj/cM=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240930203817-424892240cd1 h1:X07jKFIakpR7UyG/BnQ8wKZz395LsEcowqyQgDKHcT8=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240930203817-424892240cd1/go.mod h1:/nGkIe25kgtr+l6y30VH+aTVaxu0NjIEEEhtV1TDlaE=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20241002064705-34d7f9b7e26a h1:zHMknn5+VAOMzMk3LXT+GfCD17h252jTKreFyQwRaB0=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20241002064705-34d7f9b7e26a/go.mod h1:/nGkIe25kgtr+l6y30VH+aTVaxu0NjIEEEhtV1TDlaE=
github.com/smartcontractkit/chainlink-common v0.2.3-0.20241001140426-35be2fad06ec h1:zmLmKLCpoV73AaGU8YBc86YPLJBzoZFv9lPC677Eqcs=
github.com/smartcontractkit/chainlink-common v0.2.3-0.20241001140426-35be2fad06ec/go.mod h1:F6WUS6N4mP5ScwpwyTyAJc9/vjR+GXbMCRUOVekQi1g=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240911175228-daf2600bb7b7 h1:lTGIOQYLk1Ufn++X/AvZnt6VOcuhste5yp+C157No/Q=
Expand Down

0 comments on commit be774f0

Please sign in to comment.