From 0baf9588646c0921e92dfa7ca67b3bd8154ebf51 Mon Sep 17 00:00:00 2001 From: Graham Goh Date: Wed, 27 Nov 2024 11:52:25 +1100 Subject: [PATCH] feat(deployment): add link contract deployment (#15379) Added a new changeset in shared package which deploys the link token. JIRA: https://smartcontract-it.atlassian.net/browse/DPA-1313 --- .../common/changeset/deploy_link_token.go | 55 +++++++++++++++++++ .../changeset/deploy_link_token_test.go | 39 +++++++++++++ deployment/common/types/types.go | 1 + 3 files changed, 95 insertions(+) create mode 100644 deployment/common/changeset/deploy_link_token.go create mode 100644 deployment/common/changeset/deploy_link_token_test.go diff --git a/deployment/common/changeset/deploy_link_token.go b/deployment/common/changeset/deploy_link_token.go new file mode 100644 index 00000000000..5f88b410f67 --- /dev/null +++ b/deployment/common/changeset/deploy_link_token.go @@ -0,0 +1,55 @@ +package changeset + +import ( + "fmt" + + "github.com/smartcontractkit/chainlink-common/pkg/logger" + + "github.com/smartcontractkit/chainlink/deployment" + "github.com/smartcontractkit/chainlink/deployment/common/types" + "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/shared/generated/link_token" +) + +var _ deployment.ChangeSet[uint64] = DeployLinkToken + +// DeployLinkToken deploys a link token contract to the chain identified by the chainSelector. +func DeployLinkToken(e deployment.Environment, chainSelector uint64) (deployment.ChangesetOutput, error) { + c, ok := e.Chains[chainSelector] + if !ok { + return deployment.ChangesetOutput{}, fmt.Errorf("chain not found in environment") + } + newAddresses := deployment.NewMemoryAddressBook() + _, err := deployLinkTokenContract( + e.Logger, c, newAddresses, + ) + if err != nil { + return deployment.ChangesetOutput{AddressBook: newAddresses}, err + } + return deployment.ChangesetOutput{AddressBook: newAddresses}, nil +} + +func deployLinkTokenContract( + lggr logger.Logger, + chain deployment.Chain, + ab deployment.AddressBook, +) (*deployment.ContractDeploy[*link_token.LinkToken], error) { + linkToken, err := deployment.DeployContract[*link_token.LinkToken](lggr, chain, ab, + func(chain deployment.Chain) deployment.ContractDeploy[*link_token.LinkToken] { + linkTokenAddr, tx, linkToken, err2 := link_token.DeployLinkToken( + chain.DeployerKey, + chain.Client, + ) + return deployment.ContractDeploy[*link_token.LinkToken]{ + Address: linkTokenAddr, + Contract: linkToken, + Tx: tx, + Tv: deployment.NewTypeAndVersion(types.LinkToken, deployment.Version1_0_0), + Err: err2, + } + }) + if err != nil { + lggr.Errorw("Failed to deploy link token", "err", err) + return linkToken, err + } + return linkToken, nil +} diff --git a/deployment/common/changeset/deploy_link_token_test.go b/deployment/common/changeset/deploy_link_token_test.go new file mode 100644 index 00000000000..a18e0181623 --- /dev/null +++ b/deployment/common/changeset/deploy_link_token_test.go @@ -0,0 +1,39 @@ +package changeset_test + +import ( + "testing" + + "github.com/smartcontractkit/chainlink-common/pkg/logger" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "go.uber.org/zap/zapcore" + + "github.com/smartcontractkit/chainlink/deployment/common/changeset" + "github.com/smartcontractkit/chainlink/deployment/environment/memory" +) + +func TestDeployLinkToken(t *testing.T) { + t.Parallel() + + lggr := logger.Test(t) + cfg := memory.MemoryEnvironmentConfig{ + Nodes: 1, + Chains: 2, + } + env := memory.NewMemoryEnvironment(t, lggr, zapcore.DebugLevel, cfg) + chainSelector := env.AllChainSelectors()[0] + + resp, err := changeset.DeployLinkToken(env, chainSelector) + require.NoError(t, err) + require.NotNil(t, resp) + + // LinkToken should be deployed on chain 0 + addrs, err := resp.AddressBook.AddressesForChain(chainSelector) + require.NoError(t, err) + require.Len(t, addrs, 1) + + // nothing on chain 1 + require.NotEqual(t, chainSelector, env.AllChainSelectors()[1]) + oaddrs, _ := resp.AddressBook.AddressesForChain(env.AllChainSelectors()[1]) + assert.Len(t, oaddrs, 0) +} diff --git a/deployment/common/types/types.go b/deployment/common/types/types.go index 7fb602c3704..a6504d17a94 100644 --- a/deployment/common/types/types.go +++ b/deployment/common/types/types.go @@ -16,6 +16,7 @@ const ( CancellerManyChainMultisig deployment.ContractType = "CancellerManyChainMultiSig" ProposerManyChainMultisig deployment.ContractType = "ProposerManyChainMultiSig" RBACTimelock deployment.ContractType = "RBACTimelock" + LinkToken deployment.ContractType = "LinkToken" ) type MCMSWithTimelockConfig struct {