Skip to content

Commit 2960ced

Browse files
authored
chore: use new evm operation utils for link token changesets (#86)
This updates the link token changesets to use the new evm operation utils. This standardises the way we write EVM operations.
1 parent 68d4cda commit 2960ced

9 files changed

Lines changed: 87 additions & 66 deletions

File tree

legacy/mcms/internal/family/evm/operations/ops_ownership.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var OpTransferOwnership = operations.NewOperation(
3838
_, err = cldf.ConfirmIfNoError(deps.Chain, tx, err)
3939
if err != nil {
4040
return OpOwnershipOutput{Tx: tx}, fmt.Errorf(
41-
"failed to transfer ownership of contract %T: %w",
41+
"failed to transfer ownership of contract %s: %w",
4242
in.Address.Hex(),
4343
err,
4444
)
@@ -57,7 +57,7 @@ var OpAcceptOwnership = operations.NewOperation(
5757
tx, err := deps.OwnableC.AcceptOwnership(cldf.SimTransactOpts())
5858
if err != nil {
5959
return OpOwnershipOutput{Tx: tx}, fmt.Errorf(
60-
"failed to Accept ownership of contract %T: %w",
60+
"failed to Accept ownership of contract %s: %w",
6161
in.Address.Hex(),
6262
err,
6363
)

tokens/link/changesets/deploy_link_token.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ import (
77

88
"github.com/gagliardetto/solana-go"
99
chainsel "github.com/smartcontractkit/chain-selectors"
10+
"github.com/smartcontractkit/chainlink-deployments-framework/chain/evm"
11+
"github.com/smartcontractkit/chainlink-deployments-framework/chain/evm/operations2/contract"
1012
"github.com/smartcontractkit/chainlink-deployments-framework/datastore"
1113
cldf "github.com/smartcontractkit/chainlink-deployments-framework/deployment"
1214
cldfops "github.com/smartcontractkit/chainlink-deployments-framework/operations"
1315

14-
opsevm "github.com/smartcontractkit/cld-changesets/pkg/family/evm/operations"
1516
linkops "github.com/smartcontractkit/cld-changesets/tokens/link/operations"
17+
"github.com/smartcontractkit/cld-changesets/tokens/link/types"
1618
)
1719

1820
var _ cldf.ChangeSetV2[DeployLinkTokenInput] = DeployLinkTokenChangeset{}
@@ -69,9 +71,9 @@ func (DeployLinkTokenChangeset) VerifyPreconditions(e cldf.Environment, input De
6971
return fmt.Errorf("unknown EVM LINK variant %q for chain %d: must be %q or %q", cfg.Variant, sel, EVMLinkBurnMint, EVMLinkStatic)
7072
}
7173

72-
tv := linkTokenTypeAndVersion()
74+
tv := types.BurnMintLinkTokenTypeAndVersion
7375
if cfg.Variant == EVMLinkStatic {
74-
tv = staticLinkTokenTypeAndVersion()
76+
tv = types.StaticLinkTokenTypeAndVersion
7577
}
7678

7779
if err := validateNoExistingContract(e, []uint64{sel}, tv, cfg.Qualifier); err != nil {
@@ -92,7 +94,7 @@ func (DeployLinkTokenChangeset) VerifyPreconditions(e cldf.Environment, input De
9294
return fmt.Errorf("solana chain %d: TokenPrivKey must be set", sel)
9395
}
9496

95-
if err := validateNoExistingContract(e, []uint64{sel}, linkTokenTypeAndVersion(), cfg.Qualifier); err != nil {
97+
if err := validateNoExistingContract(e, []uint64{sel}, types.BurnMintLinkTokenTypeAndVersion, cfg.Qualifier); err != nil {
9698
return err
9799
}
98100
}
@@ -111,24 +113,31 @@ func (DeployLinkTokenChangeset) Apply(e cldf.Environment, input DeployLinkTokenI
111113
}
112114

113115
op := linkops.OpEVMDeployLinkToken
114-
tv := linkTokenTypeAndVersion()
116+
tv := types.BurnMintLinkTokenTypeAndVersion
115117
if cfg.Variant == EVMLinkStatic {
116118
op = linkops.OpEVMDeployStaticLinkToken
117-
tv = staticLinkTokenTypeAndVersion()
119+
tv = types.StaticLinkTokenTypeAndVersion
118120
}
119121

120122
qualifier := cfg.Qualifier
121123
report, err := cldfops.ExecuteOperation(
122124
e.OperationsBundle,
123125
op,
124126
chain,
125-
opsevm.EVMDeployInput[any]{ChainSelector: sel, Qualifier: &qualifier},
127+
contract.DeployInput[struct{}]{
128+
TypeAndVersion: tv,
129+
Qualifier: &qualifier,
130+
Args: struct{}{},
131+
},
132+
cldfops.WithIdempotencyKey[contract.DeployInput[struct{}], evm.Chain](
133+
fmt.Sprintf("link-token-deploy-%d-%s-%s", sel, tv.String(), qualifier),
134+
),
126135
)
127136
if err != nil {
128137
return cldf.ChangesetOutput{}, fmt.Errorf("failed to deploy link token for chain %d: %w", sel, err)
129138
}
130139

131-
addr := report.Output.Address.String()
140+
addr := report.Output.Address
132141
if err := saveAddressRef(ds, sel, addr, tv, cfg.Qualifier); err != nil {
133142
return cldf.ChangesetOutput{}, fmt.Errorf("failed to save link token address for chain %d: %w", sel, err)
134143
}
@@ -137,7 +146,7 @@ func (DeployLinkTokenChangeset) Apply(e cldf.Environment, input DeployLinkTokenI
137146
e.Logger.Infow("Deployed link token", "chain", sel, "addr", addr, "variant", tv.Type)
138147
}
139148

140-
tv := linkTokenTypeAndVersion()
149+
tv := types.BurnMintLinkTokenTypeAndVersion
141150
for sel, cfg := range input.Solana {
142151
chain, ok := e.BlockChains.SolanaChains()[sel]
143152
if !ok {

tokens/link/changesets/deploy_link_token_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import (
44
"testing"
55

66
"github.com/gagliardetto/solana-go"
7-
chain_selectors "github.com/smartcontractkit/chain-selectors"
87
"github.com/stretchr/testify/require"
98

9+
chain_selectors "github.com/smartcontractkit/chain-selectors"
1010
cldf_chain "github.com/smartcontractkit/chainlink-deployments-framework/chain"
1111
cldf_evm "github.com/smartcontractkit/chainlink-deployments-framework/chain/evm"
1212
cldf_solana "github.com/smartcontractkit/chainlink-deployments-framework/chain/solana"
@@ -17,6 +17,7 @@ import (
1717
"github.com/smartcontractkit/chainlink-deployments-framework/engine/test/runtime"
1818

1919
"github.com/smartcontractkit/cld-changesets/internal/semvers"
20+
"github.com/smartcontractkit/cld-changesets/tokens/link/types"
2021
)
2122

2223
func TestDeployLinkToken(t *testing.T) {
@@ -166,7 +167,7 @@ func TestDeployLinkTokenRejectsExistingStateBeforeDeploy(t *testing.T) {
166167
BlockChains: cldf_chain.NewBlockChainsFromSlice([]cldf_chain.BlockChain{
167168
cldf_evm.Chain{Selector: evmSelector},
168169
}),
169-
DataStore: datastoreWith(t, evmSelector, evmAddress, linkTokenTypeAndVersion(), ""),
170+
DataStore: datastoreWith(t, evmSelector, evmAddress, types.BurnMintLinkTokenTypeAndVersion, ""),
170171
},
171172
input: DeployLinkTokenInput{EVM: map[uint64]EVMLinkConfig{evmSelector: {}}},
172173
wantErr: "LinkToken contract already exists",
@@ -177,7 +178,7 @@ func TestDeployLinkTokenRejectsExistingStateBeforeDeploy(t *testing.T) {
177178
BlockChains: cldf_chain.NewBlockChainsFromSlice([]cldf_chain.BlockChain{
178179
cldf_evm.Chain{Selector: evmSelector},
179180
}),
180-
DataStore: datastoreWith(t, evmSelector, evmAddress, staticLinkTokenTypeAndVersion(), ""),
181+
DataStore: datastoreWith(t, evmSelector, evmAddress, types.StaticLinkTokenTypeAndVersion, ""),
181182
},
182183
input: DeployLinkTokenInput{EVM: map[uint64]EVMLinkConfig{evmSelector: {Variant: EVMLinkStatic}}},
183184
wantErr: "StaticLinkToken contract already exists",
@@ -188,7 +189,7 @@ func TestDeployLinkTokenRejectsExistingStateBeforeDeploy(t *testing.T) {
188189
BlockChains: cldf_chain.NewBlockChainsFromSlice([]cldf_chain.BlockChain{
189190
cldf_solana.Chain{Selector: solSelector},
190191
}),
191-
DataStore: datastoreWith(t, solSelector, solAddress, linkTokenTypeAndVersion(), ""),
192+
DataStore: datastoreWith(t, solSelector, solAddress, types.BurnMintLinkTokenTypeAndVersion, ""),
192193
},
193194
input: func() DeployLinkTokenInput {
194195
key, err := solana.NewRandomPrivateKey()
@@ -293,7 +294,7 @@ func TestDeployLinkTokenDifferentQualifierDoesNotBlock(t *testing.T) {
293294
BlockChains: cldf_chain.NewBlockChainsFromSlice([]cldf_chain.BlockChain{
294295
cldf_evm.Chain{Selector: evmSelector},
295296
}),
296-
DataStore: datastoreWith(t, evmSelector, evmAddress, linkTokenTypeAndVersion(), "migrated"),
297+
DataStore: datastoreWith(t, evmSelector, evmAddress, types.BurnMintLinkTokenTypeAndVersion, "migrated"),
297298
}
298299

299300
err := DeployLinkTokenChangeset{}.VerifyPreconditions(env, DeployLinkTokenInput{

tokens/link/changesets/transfer_link_token.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@ import (
1414
linkcontracts "github.com/smartcontractkit/chainlink-deployments-framework/engine/cld/contracts/link"
1515
mcmscontracts "github.com/smartcontractkit/chainlink-deployments-framework/engine/cld/contracts/mcms"
1616
"github.com/smartcontractkit/chainlink-evm/gethwrappers/shared/generated/initial/link_token"
17-
18-
"github.com/smartcontractkit/cld-changesets/internal/semvers"
19-
2017
"github.com/smartcontractkit/mcms"
2118
mcmstypes "github.com/smartcontractkit/mcms/types"
19+
20+
"github.com/smartcontractkit/cld-changesets/internal/semvers"
2221
)
2322

2423
const defaultProposalValidFor = 24 * time.Hour

tokens/link/changesets/transfer_link_token_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"time"
77

88
"github.com/ethereum/go-ethereum/common"
9+
"github.com/stretchr/testify/require"
10+
911
chain_selectors "github.com/smartcontractkit/chain-selectors"
1012
cldf_chain "github.com/smartcontractkit/chainlink-deployments-framework/chain"
1113
cldf_evm "github.com/smartcontractkit/chainlink-deployments-framework/chain/evm"
@@ -15,17 +17,17 @@ import (
1517
"github.com/smartcontractkit/chainlink-deployments-framework/engine/test/environment"
1618
"github.com/smartcontractkit/chainlink-evm/gethwrappers/shared/generated/initial/link_token"
1719
mcmstypes "github.com/smartcontractkit/mcms/types"
18-
"github.com/stretchr/testify/require"
1920

2021
"github.com/smartcontractkit/cld-changesets/internal/semvers"
22+
"github.com/smartcontractkit/cld-changesets/tokens/link/types"
2123
)
2224

2325
func TestTransferLinkTokenRejectsPreconditions(t *testing.T) {
2426
t.Parallel()
2527

2628
selector := chain_selectors.TEST_90000001.Selector
2729

28-
linkTV := linkTokenTypeAndVersion()
30+
linkTV := types.BurnMintLinkTokenTypeAndVersion
2931
proposerTV := cldf.NewTypeAndVersion(mcmscontracts.ProposerManyChainMultisig, semvers.V1_0_0)
3032
timelockTV := cldf.NewTypeAndVersion(mcmscontracts.RBACTimelock, semvers.V1_0_0)
3133

@@ -177,7 +179,7 @@ func TestTransferLinkTokenBuildsProposal(t *testing.T) {
177179
)
178180

179181
ds := datastore.NewMemoryDataStore()
180-
require.NoError(t, saveAddressRef(ds, selector, linkAddr.Hex(), linkTokenTypeAndVersion(), ""))
182+
require.NoError(t, saveAddressRef(ds, selector, linkAddr.Hex(), types.BurnMintLinkTokenTypeAndVersion, ""))
181183
require.NoError(t, saveAddressRef(ds, selector, proposerAddr, proposerTV, ""))
182184
require.NoError(t, saveAddressRef(ds, selector, timelockAddr, timelockTV, ""))
183185
env.DataStore = ds.Seal()
@@ -221,7 +223,7 @@ func TestTransferLinkTokenValidUntilIsRespected(t *testing.T) {
221223
)
222224

223225
ds := datastore.NewMemoryDataStore()
224-
require.NoError(t, saveAddressRef(ds, selector, linkAddr.Hex(), linkTokenTypeAndVersion(), ""))
226+
require.NoError(t, saveAddressRef(ds, selector, linkAddr.Hex(), types.BurnMintLinkTokenTypeAndVersion, ""))
225227
require.NoError(t, saveAddressRef(ds, selector, proposerAddr, proposerTV, ""))
226228
require.NoError(t, saveAddressRef(ds, selector, timelockAddr, timelockTV, ""))
227229
env.DataStore = ds.Seal()

tokens/link/changesets/validation.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,8 @@ import (
66
chainsel "github.com/smartcontractkit/chain-selectors"
77
"github.com/smartcontractkit/chainlink-deployments-framework/datastore"
88
cldf "github.com/smartcontractkit/chainlink-deployments-framework/deployment"
9-
linkcontracts "github.com/smartcontractkit/chainlink-deployments-framework/engine/cld/contracts/link"
10-
11-
"github.com/smartcontractkit/cld-changesets/internal/semvers"
129
)
1310

14-
func linkTokenTypeAndVersion() cldf.TypeAndVersion {
15-
return cldf.NewTypeAndVersion(linkcontracts.LinkToken, semvers.V1_0_0)
16-
}
17-
18-
func staticLinkTokenTypeAndVersion() cldf.TypeAndVersion {
19-
return cldf.NewTypeAndVersion(linkcontracts.StaticLinkToken, semvers.V1_0_0)
20-
}
21-
2211
func saveAddressRef(ds datastore.MutableDataStore, chainSelector uint64, address string, tv cldf.TypeAndVersion, qualifier string) error {
2312
return ds.Addresses().Add(datastore.AddressRef{
2413
ChainSelector: chainSelector,
Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
11
package operations
22

33
import (
4-
"github.com/Masterminds/semver/v3"
54
"github.com/ethereum/go-ethereum/common"
6-
linkcontracts "github.com/smartcontractkit/chainlink-deployments-framework/engine/cld/contracts/link"
5+
"github.com/smartcontractkit/chainlink-deployments-framework/chain/evm/operations2/contract"
76
"github.com/smartcontractkit/chainlink-evm/gethwrappers/shared/generated/initial/link_token"
87

9-
"github.com/smartcontractkit/cld-changesets/internal/semvers"
10-
opsevm "github.com/smartcontractkit/cld-changesets/pkg/family/evm/operations"
8+
"github.com/smartcontractkit/cld-changesets/tokens/link/types"
119
)
1210

13-
// OpEVMDeployLinkToken deploys a burn/mint ERC677 LINK token contract, with ZkSync support.
14-
var OpEVMDeployLinkToken = opsevm.NewEVMDeployOperation(
15-
"evm-link-token-deploy",
16-
semver.MustParse("1.0.0"),
17-
"Deploys LINK token (burn/mint ERC677) contract",
18-
linkcontracts.LinkToken,
19-
link_token.LinkTokenMetaData,
20-
&opsevm.ContractOpts{
21-
Version: &semvers.V1_0_0,
22-
EVMBytecode: common.FromHex(link_token.LinkTokenBin),
23-
ZkSyncVMBytecode: link_token.ZkBytecode,
11+
var OpEVMDeployLinkToken = contract.NewDeploy(contract.DeployParams[struct{}]{
12+
Name: "evm-link-token-deploy",
13+
Description: "Deploys LINK token (burn/mint ERC677) contract",
14+
Version: &types.BurnMintLinkTokenTypeAndVersion.Version,
15+
ContractMetadata: link_token.LinkTokenMetaData,
16+
BytecodeByTypeAndVersion: map[string]contract.Bytecode{
17+
types.BurnMintLinkTokenTypeAndVersion.String(): {
18+
EVM: common.FromHex(link_token.LinkTokenBin),
19+
ZkSyncVM: link_token.ZkBytecode,
20+
},
2421
},
25-
func(_ any) []any { return []any{} },
26-
)
22+
})
Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
package operations
22

33
import (
4-
"github.com/Masterminds/semver/v3"
54
"github.com/ethereum/go-ethereum/common"
6-
linkcontracts "github.com/smartcontractkit/chainlink-deployments-framework/engine/cld/contracts/link"
5+
6+
"github.com/smartcontractkit/chainlink-deployments-framework/chain/evm/operations2/contract"
77
"github.com/smartcontractkit/chainlink-evm/gethwrappers/generated/link_token_interface"
88

9-
"github.com/smartcontractkit/cld-changesets/internal/semvers"
10-
opsevm "github.com/smartcontractkit/cld-changesets/pkg/family/evm/operations"
9+
"github.com/smartcontractkit/cld-changesets/tokens/link/types"
1110
)
1211

1312
// OpEVMDeployStaticLinkToken deploys a non-burn/mint static LINK token contract.
14-
var OpEVMDeployStaticLinkToken = opsevm.NewEVMDeployOperation(
15-
"evm-static-link-token-deploy",
16-
semver.MustParse("1.0.0"),
17-
"Deploys static LINK token (non-burn/mint) contract",
18-
linkcontracts.StaticLinkToken,
19-
link_token_interface.LinkTokenMetaData,
20-
&opsevm.ContractOpts{
21-
Version: &semvers.V1_0_0,
22-
EVMBytecode: common.FromHex(link_token_interface.LinkTokenBin),
13+
var OpEVMDeployStaticLinkToken = contract.NewDeploy(contract.DeployParams[struct{}]{
14+
Name: "evm-static-link-token-deploy",
15+
Description: "Deploys static LINK token (non-burn/mint) contract",
16+
Version: &types.StaticLinkTokenTypeAndVersion.Version,
17+
ContractMetadata: link_token_interface.LinkTokenMetaData,
18+
BytecodeByTypeAndVersion: map[string]contract.Bytecode{
19+
types.StaticLinkTokenTypeAndVersion.String(): {
20+
EVM: common.FromHex(link_token_interface.LinkTokenBin),
21+
},
2322
},
24-
func(_ any) []any { return []any{} },
25-
)
23+
})

tokens/link/types/types.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package types
2+
3+
import (
4+
"github.com/smartcontractkit/chainlink-deployments-framework/deployment"
5+
6+
"github.com/smartcontractkit/cld-changesets/internal/semvers"
7+
)
8+
9+
const (
10+
// LinkToken is the burn/mint link token. It should be used everywhere for
11+
// new deployments. Corresponds to
12+
// https://github.com/smartcontractkit/chainlink/blob/develop/core/gethwrappers/shared/generated/link_token/link_token.go#L34
13+
ContractTypeLinkToken deployment.ContractType = "LinkToken"
14+
15+
// StaticLinkToken represents the (very old) non-burn/mint link token.
16+
// It is not used in new deployments, but still exists on some chains
17+
// and has a distinct ABI from the new LinkToken.
18+
// Corresponds to the ABI
19+
// https://github.com/smartcontractkit/chainlink/blob/develop/core/gethwrappers/generated/link_token_interface/link_token_interface.go#L34
20+
ContractTypeStaticLinkToken deployment.ContractType = "StaticLinkToken"
21+
)
22+
23+
// TypeAndVersion constants for the LINK token contracts.
24+
var (
25+
BurnMintLinkTokenTypeAndVersion = deployment.NewTypeAndVersion(ContractTypeLinkToken, semvers.V1_0_0)
26+
StaticLinkTokenTypeAndVersion = deployment.NewTypeAndVersion(ContractTypeStaticLinkToken, semvers.V1_0_0)
27+
)

0 commit comments

Comments
 (0)