Skip to content

Commit

Permalink
parameterize token info
Browse files Browse the repository at this point in the history
  • Loading branch information
AnieeG committed Nov 26, 2024
1 parent 9ca884d commit 365491b
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 25 deletions.
1 change: 0 additions & 1 deletion deployment/ccip/changeset/active_candidate.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func SetCandidatePluginChangeset(
ccipOCRParams := DefaultOCRParams(
feedChainSel,
tokenConfig.GetTokenInfo(e.Logger, state.Chains[newChainSel].LinkToken, state.Chains[newChainSel].Weth9),
nil,
)
newDONArgs, err := internal.BuildOCR3ConfigForCCIPHome(
ocrSecrets,
Expand Down
1 change: 0 additions & 1 deletion deployment/ccip/changeset/active_candidate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ func TestActiveCandidate(t *testing.T) {
ccipOCRParams := DefaultOCRParams(
tenv.FeedChainSel,
tokenConfig.GetTokenInfo(e.Logger, state.Chains[tenv.FeedChainSel].LinkToken, state.Chains[tenv.FeedChainSel].Weth9),
nil,
)
ocr3ConfigMap, err := internal.BuildOCR3ConfigForCCIPHome(
deployment.XXXGenerateTestOCRSecrets(),
Expand Down
1 change: 0 additions & 1 deletion deployment/ccip/changeset/add_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ func AddDonAndSetCandidateChangeset(
ccipOCRParams := DefaultOCRParams(
feedChainSel,
tokenConfig.GetTokenInfo(e.Logger, state.Chains[newChainSel].LinkToken, state.Chains[newChainSel].Weth9),
nil,
)
newDONArgs, err := internal.BuildOCR3ConfigForCCIPHome(
ocrSecrets,
Expand Down
6 changes: 1 addition & 5 deletions deployment/ccip/changeset/add_chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,13 @@ func TestAddChainInbound(t *testing.T) {
require.NoError(t, e.Env.ExistingAddresses.Merge(out.AddressBook))
newAddresses = deployment.NewMemoryAddressBook()
tokenConfig := NewTestTokenConfig(state.Chains[e.FeedChainSel].USDFeeds)
ocrParams := make(map[uint64]CCIPOCRParams)
for _, chain := range initialDeploy {
ocrParams[chain] = DefaultOCRParams(e.FeedChainSel, nil, nil)
}

err = deployCCIPContracts(e.Env, newAddresses, NewChainsConfig{
HomeChainSel: e.HomeChainSel,
FeedChainSel: e.FeedChainSel,
ChainsToDeploy: initialDeploy,
TokenConfig: tokenConfig,
OCRSecrets: deployment.XXXGenerateTestOCRSecrets(),
OCRParams: ocrParams,
})
require.NoError(t, err)

Expand Down
15 changes: 12 additions & 3 deletions deployment/ccip/changeset/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,6 @@ func configureChain(
if chainState.OffRamp == nil {
return fmt.Errorf("off ramp not found for chain %d", chain.Selector)
}
// TODO : better handling - need to scale this for more tokens
ocrParams.CommitOffChainConfig.TokenInfo = c.TokenConfig.GetTokenInfo(e.Logger, existingState.Chains[chainSel].LinkToken, existingState.Chains[chainSel].Weth9)
_, err = AddChainConfig(
e.Logger,
e.Chains[c.HomeChainSel],
Expand All @@ -396,7 +394,7 @@ func configureChain(
return err
}
if enabled, ok := c.USDCConfig.EnabledChainMap()[chainSel]; ok && enabled {
ocrParams.ExecuteOffChainConfig.TokenDataObservers = append(ocrParams.ExecuteOffChainConfig.TokenDataObservers, c.USDCConfig.ToTokenDataObserverConfig()...)
ocrParams.ExecuteOffChainConfig.TokenDataObservers = c.USDCConfig.ToTokenDataObserverConfig()
}
ocrParams.CommitOffChainConfig.PriceFeedChainSelector = cciptypes.ChainSelector(c.FeedChainSel)
// For each chain, we create a DON on the home chain (2 OCR instances)
Expand Down Expand Up @@ -443,6 +441,17 @@ func deployCCIPContracts(
e.Logger.Errorw("Failed to merge address book", "err", err)
return err
}
state, err := LoadOnchainState(e)
if err != nil {
e.Logger.Errorw("Failed to load existing onchain state", "err", err)
return err
}
tokenInfo := c.TokenConfig.GetTokenInfo(nil, state.Chains[c.FeedChainSel].LinkToken, state.Chains[c.FeedChainSel].Weth9)
ocrParams := make(map[uint64]CCIPOCRParams)
for _, chain := range c.ChainsToDeploy {
ocrParams[chain] = DefaultOCRParams(c.FeedChainSel, tokenInfo)
}
c.OCRParams = ocrParams
err = configureChain(e, c)
if err != nil {
e.Logger.Errorw("Failed to add chain", "err", err)
Expand Down
2 changes: 0 additions & 2 deletions deployment/ccip/changeset/initial_add_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ func (c NewChainsConfig) Validate() error {
func DefaultOCRParams(
feedChainSel uint64,
tokenInfo map[ccipocr3.UnknownEncodedAddress]pluginconfig.TokenInfo,
dataObserverConfig []pluginconfig.TokenDataObserverConfig,
) CCIPOCRParams {
return CCIPOCRParams{
OCRParameters: types.OCRParameters{
Expand All @@ -192,7 +191,6 @@ func DefaultOCRParams(
RootSnoozeTime: *config.MustNewDuration(internal.RootSnoozeTime),
MessageVisibilityInterval: *config.MustNewDuration(internal.FirstBlockAge),
BatchingStrategyID: internal.BatchingStrategyID,
TokenDataObservers: dataObserverConfig,
},
CommitOffChainConfig: pluginconfig.CommitOffchainConfig{
RemoteGasPriceBatchWriteFrequency: *config.MustNewDuration(internal.RemoteGasPriceBatchWriteFrequency),
Expand Down
25 changes: 14 additions & 11 deletions deployment/ccip/changeset/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,13 @@ func NewMemoryEnvironmentWithJobsAndContracts(t *testing.T, lggr logger.Logger,
Changeset: commonchangeset.WrapChangeSet(commonchangeset.DeployMCMSWithTimelock),
Config: mcmsCfg,
},
{
Changeset: commonchangeset.WrapChangeSet(DeployChainContracts),
Config: DeployChainContractsConfig{
ChainSelectors: allChains,
HomeChainSelector: e.HomeChainSel,
},
},
})
require.NoError(t, err)

Expand All @@ -307,10 +314,8 @@ func NewMemoryEnvironmentWithJobsAndContracts(t *testing.T, lggr logger.Logger,
SourceMessageTransmitterAddr: state.Chains[chain].MockUSDCTransmitter.Address().String(),
}
}
for _, chain := range allChains {
timelocksPerChain[chain] = state.Chains[chain].Timelock
ocrParams[chain] = DefaultOCRParams(e.FeedChainSel, nil, nil)
}
require.NotNil(t, state.Chains[e.FeedChainSel].LinkToken)
require.NotNil(t, state.Chains[e.FeedChainSel].Weth9)
var usdcCfg USDCAttestationConfig
if len(usdcChains) > 0 {
server := mockAttestationResponse()
Expand All @@ -325,15 +330,13 @@ func NewMemoryEnvironmentWithJobsAndContracts(t *testing.T, lggr logger.Logger,
})
}

tokenInfo := tokenConfig.GetTokenInfo(nil, state.Chains[e.FeedChainSel].LinkToken, state.Chains[e.FeedChainSel].Weth9)
for _, chain := range allChains {
timelocksPerChain[chain] = state.Chains[chain].Timelock
ocrParams[chain] = DefaultOCRParams(e.FeedChainSel, tokenInfo)
}
// Deploy second set of changesets to deploy and configure the CCIP contracts.
e.Env, err = commonchangeset.ApplyChangesets(t, e.Env, timelocksPerChain, []commonchangeset.ChangesetApplication{
{
Changeset: commonchangeset.WrapChangeSet(DeployChainContracts),
Config: DeployChainContractsConfig{
ChainSelectors: allChains,
HomeChainSelector: e.HomeChainSel,
},
},
{
Changeset: commonchangeset.WrapChangeSet(ConfigureNewChains),
Config: NewChainsConfig{
Expand Down
1 change: 1 addition & 0 deletions deployment/ccip/changeset/token_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package changeset
import (
"github.com/smartcontractkit/chainlink-ccip/pkg/types/ccipocr3"
"github.com/smartcontractkit/chainlink-ccip/pluginconfig"

"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/weth9"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/aggregator_v3_interface"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/shared/generated/burn_mint_erc677"
Expand Down
5 changes: 4 additions & 1 deletion integration-tests/testsetups/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,12 @@ func NewLocalDevEnvironment(
APIInterval: commonconfig.MustNewDuration(500 * time.Millisecond),
}
}
require.NotNil(t, state.Chains[feedSel].LinkToken)
require.NotNil(t, state.Chains[feedSel].Weth9)
tokenInfo := tokenConfig.GetTokenInfo(nil, state.Chains[feedSel].LinkToken, state.Chains[feedSel].Weth9)
for _, chain := range allChains {
timelocksPerChain[chain] = state.Chains[chain].Timelock
ocrParams[chain] = changeset.DefaultOCRParams(feedSel, nil, nil)
ocrParams[chain] = changeset.DefaultOCRParams(feedSel, tokenInfo)
}
// Deploy second set of changesets to deploy and configure the CCIP contracts.
env, err = commonchangeset.ApplyChangesets(t, env, timelocksPerChain, []commonchangeset.ChangesetApplication{
Expand Down

0 comments on commit 365491b

Please sign in to comment.