Skip to content

Commit 7093ed0

Browse files
committed
break up registration files
1 parent ff28580 commit 7093ed0

8 files changed

Lines changed: 406 additions & 330 deletions

File tree

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package registrations
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/ethereum/go-ethereum/common"
7+
8+
"github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/tokens/strategy"
9+
"github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v1_0_0/operations/burn_mint_erc20"
10+
tokensapi "github.com/smartcontractkit/chainlink-ccip/deployment/tokens"
11+
common_utils "github.com/smartcontractkit/chainlink-ccip/deployment/utils"
12+
"github.com/smartcontractkit/chainlink-deployments-framework/chain/evm"
13+
"github.com/smartcontractkit/chainlink-deployments-framework/chain/evm/operations/contract"
14+
"github.com/smartcontractkit/chainlink-deployments-framework/datastore"
15+
"github.com/smartcontractkit/chainlink-deployments-framework/deployment"
16+
cldf_ops "github.com/smartcontractkit/chainlink-deployments-framework/operations"
17+
)
18+
19+
func init() {
20+
strategy.GetRegistry().RegisterEVM(burnMintERC20Strategy{})
21+
}
22+
23+
type burnMintERC20Strategy struct{}
24+
25+
func (burnMintERC20Strategy) ContractType() deployment.ContractType {
26+
return burn_mint_erc20.ContractType
27+
}
28+
29+
func (burnMintERC20Strategy) Capabilities() strategy.Capabilities {
30+
return strategy.Capabilities{
31+
SupportsAdminRole: true,
32+
SupportsCCIPAdmin: true,
33+
SupportsPreMint: true,
34+
ParticipatesInPoolRoleGrant: true,
35+
}
36+
}
37+
38+
func (burnMintERC20Strategy) Deploy(b cldf_ops.Bundle, chain evm.Chain, in tokensapi.DeployTokenInput) (datastore.AddressRef, []contract.WriteOutput, error) {
39+
qualifier := in.Symbol
40+
maxSupply, preMint := scaledSupplyAndPreMint(in)
41+
ref, err := contract.MaybeDeployContract(b, burn_mint_erc20.Deploy, chain, contract.DeployInput[burn_mint_erc20.ConstructorArgs]{
42+
TypeAndVersion: deployment.NewTypeAndVersion(burn_mint_erc20.ContractType, *common_utils.Version_1_0_0),
43+
ChainSelector: chain.Selector,
44+
Args: burn_mint_erc20.ConstructorArgs{
45+
Name: in.Name,
46+
Symbol: in.Symbol,
47+
Decimals: in.Decimals,
48+
MaxSupply: maxSupply,
49+
PreMint: preMint,
50+
},
51+
Qualifier: &qualifier,
52+
}, nil)
53+
if err != nil {
54+
return datastore.AddressRef{}, nil, fmt.Errorf("failed to deploy BurnMintERC20 token: %w", err)
55+
}
56+
return ref, nil, nil
57+
}
58+
59+
func (burnMintERC20Strategy) GrantPoolRoles(b cldf_ops.Bundle, chain evm.Chain, token, pool common.Address, chainSelector uint64) ([]contract.WriteOutput, error) {
60+
return grantBnMMintAndBurnRoles(b, chain, token, pool, chainSelector)
61+
}
62+
63+
func (burnMintERC20Strategy) GrantExternalAdmin(b cldf_ops.Bundle, chain evm.Chain, token, externalAdmin common.Address, chainSelector uint64) ([]contract.WriteOutput, error) {
64+
return grantBnMDefaultAdminRole(b, chain, token, externalAdmin, chainSelector)
65+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package registrations
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/ethereum/go-ethereum/common"
7+
8+
"github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/tokens/strategy"
9+
"github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v1_0_0/operations/burn_mint_erc20_with_drip"
10+
tokensapi "github.com/smartcontractkit/chainlink-ccip/deployment/tokens"
11+
common_utils "github.com/smartcontractkit/chainlink-ccip/deployment/utils"
12+
"github.com/smartcontractkit/chainlink-deployments-framework/chain/evm"
13+
"github.com/smartcontractkit/chainlink-deployments-framework/chain/evm/operations/contract"
14+
"github.com/smartcontractkit/chainlink-deployments-framework/datastore"
15+
"github.com/smartcontractkit/chainlink-deployments-framework/deployment"
16+
cldf_ops "github.com/smartcontractkit/chainlink-deployments-framework/operations"
17+
)
18+
19+
func init() {
20+
strategy.GetRegistry().RegisterEVM(burnMintERC20WithDripStrategy{})
21+
}
22+
23+
type burnMintERC20WithDripStrategy struct{}
24+
25+
func (burnMintERC20WithDripStrategy) ContractType() deployment.ContractType {
26+
return burn_mint_erc20_with_drip.ContractType
27+
}
28+
29+
func (burnMintERC20WithDripStrategy) Capabilities() strategy.Capabilities {
30+
return strategy.Capabilities{
31+
SupportsAdminRole: true,
32+
SupportsCCIPAdmin: true,
33+
SupportsPreMint: true,
34+
ParticipatesInPoolRoleGrant: true,
35+
}
36+
}
37+
38+
func (burnMintERC20WithDripStrategy) Deploy(b cldf_ops.Bundle, chain evm.Chain, in tokensapi.DeployTokenInput) (datastore.AddressRef, []contract.WriteOutput, error) {
39+
qualifier := in.Symbol
40+
maxSupply, preMint := scaledSupplyAndPreMint(in)
41+
ref, err := contract.MaybeDeployContract(b, burn_mint_erc20_with_drip.Deploy, chain, contract.DeployInput[burn_mint_erc20_with_drip.ConstructorArgs]{
42+
TypeAndVersion: deployment.NewTypeAndVersion(burn_mint_erc20_with_drip.ContractType, *common_utils.Version_1_0_0),
43+
ChainSelector: chain.Selector,
44+
Args: burn_mint_erc20_with_drip.ConstructorArgs{
45+
Name: in.Name,
46+
Symbol: in.Symbol,
47+
Decimals: in.Decimals,
48+
MaxSupply: maxSupply,
49+
PreMint: preMint,
50+
},
51+
Qualifier: &qualifier,
52+
}, nil)
53+
if err != nil {
54+
return datastore.AddressRef{}, nil, fmt.Errorf("failed to deploy BurnMintERC20WithDrip token: %w", err)
55+
}
56+
return ref, nil, nil
57+
}
58+
59+
func (burnMintERC20WithDripStrategy) GrantPoolRoles(b cldf_ops.Bundle, chain evm.Chain, token, pool common.Address, chainSelector uint64) ([]contract.WriteOutput, error) {
60+
return grantBnMMintAndBurnRoles(b, chain, token, pool, chainSelector)
61+
}
62+
63+
func (burnMintERC20WithDripStrategy) GrantExternalAdmin(b cldf_ops.Bundle, chain evm.Chain, token, externalAdmin common.Address, chainSelector uint64) ([]contract.WriteOutput, error) {
64+
return grantBnMDefaultAdminRole(b, chain, token, externalAdmin, chainSelector)
65+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package registrations
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/ethereum/go-ethereum/common"
7+
8+
"github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/tokens/strategy"
9+
drip_v150 "github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v1_5_0/operations/burn_mint_erc20_with_drip"
10+
tokensapi "github.com/smartcontractkit/chainlink-ccip/deployment/tokens"
11+
"github.com/smartcontractkit/chainlink-deployments-framework/chain/evm"
12+
"github.com/smartcontractkit/chainlink-deployments-framework/chain/evm/operations/contract"
13+
"github.com/smartcontractkit/chainlink-deployments-framework/datastore"
14+
"github.com/smartcontractkit/chainlink-deployments-framework/deployment"
15+
cldf_ops "github.com/smartcontractkit/chainlink-deployments-framework/operations"
16+
)
17+
18+
func init() {
19+
strategy.GetRegistry().RegisterEVM(burnMintERC20WithDripV150Strategy{})
20+
}
21+
22+
// burnMintERC20WithDripV150Strategy is the v1.5.0 variant of BurnMintERC20WithDrip.
23+
// Pre-mint is unsupported because the v1.5.0 constructor takes neither
24+
// supply nor decimals; matches the historical tokenSupportsPreMint table.
25+
type burnMintERC20WithDripV150Strategy struct{}
26+
27+
func (burnMintERC20WithDripV150Strategy) ContractType() deployment.ContractType {
28+
return drip_v150.ContractType
29+
}
30+
31+
func (burnMintERC20WithDripV150Strategy) Capabilities() strategy.Capabilities {
32+
return strategy.Capabilities{
33+
SupportsAdminRole: true,
34+
SupportsCCIPAdmin: true,
35+
SupportsPreMint: false,
36+
ParticipatesInPoolRoleGrant: true,
37+
}
38+
}
39+
40+
func (burnMintERC20WithDripV150Strategy) Deploy(b cldf_ops.Bundle, chain evm.Chain, in tokensapi.DeployTokenInput) (datastore.AddressRef, []contract.WriteOutput, error) {
41+
qualifier := in.Symbol
42+
ref, err := contract.MaybeDeployContract(b, drip_v150.Deploy, chain, contract.DeployInput[drip_v150.ConstructorArgs]{
43+
TypeAndVersion: deployment.NewTypeAndVersion(drip_v150.ContractType, *drip_v150.Version),
44+
ChainSelector: chain.Selector,
45+
Args: drip_v150.ConstructorArgs{
46+
Name: in.Name,
47+
Symbol: in.Symbol,
48+
},
49+
Qualifier: &qualifier,
50+
}, nil)
51+
if err != nil {
52+
return datastore.AddressRef{}, nil, fmt.Errorf("failed to deploy BurnMintERC20WithDrip (v1.5.0) token: %w", err)
53+
}
54+
return ref, nil, nil
55+
}
56+
57+
func (burnMintERC20WithDripV150Strategy) GrantPoolRoles(b cldf_ops.Bundle, chain evm.Chain, token, pool common.Address, chainSelector uint64) ([]contract.WriteOutput, error) {
58+
return grantBnMMintAndBurnRoles(b, chain, token, pool, chainSelector)
59+
}
60+
61+
func (burnMintERC20WithDripV150Strategy) GrantExternalAdmin(b cldf_ops.Bundle, chain evm.Chain, token, externalAdmin common.Address, chainSelector uint64) ([]contract.WriteOutput, error) {
62+
return grantBnMDefaultAdminRole(b, chain, token, externalAdmin, chainSelector)
63+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Package registrations registers all known EVM token contract strategies
2+
// with the singleton strategy.Registry at init time. Adapters that need
3+
// per-token-type behavior pull in this package via a blank import; all
4+
// known token types become available in one line.
5+
//
6+
// Convention: each strategy lives in its own file with its own init() that
7+
// registers itself. Adding a new EVM token contract type means dropping in
8+
// one new file (strategy struct + init); no central registry list to amend.
9+
package registrations
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package registrations
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/ethereum/go-ethereum/common"
7+
8+
"github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/tokens/strategy"
9+
"github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v1_0_0/operations/erc20"
10+
tokensapi "github.com/smartcontractkit/chainlink-ccip/deployment/tokens"
11+
common_utils "github.com/smartcontractkit/chainlink-ccip/deployment/utils"
12+
"github.com/smartcontractkit/chainlink-deployments-framework/chain/evm"
13+
"github.com/smartcontractkit/chainlink-deployments-framework/chain/evm/operations/contract"
14+
"github.com/smartcontractkit/chainlink-deployments-framework/datastore"
15+
"github.com/smartcontractkit/chainlink-deployments-framework/deployment"
16+
cldf_ops "github.com/smartcontractkit/chainlink-deployments-framework/operations"
17+
)
18+
19+
func init() {
20+
strategy.GetRegistry().RegisterEVM(erc20Strategy{})
21+
}
22+
23+
// erc20Strategy is the plain (non-CCIP-aware) ERC20 strategy.
24+
type erc20Strategy struct{}
25+
26+
func (erc20Strategy) ContractType() deployment.ContractType { return erc20.ContractType }
27+
28+
func (erc20Strategy) Capabilities() strategy.Capabilities {
29+
return strategy.Capabilities{}
30+
}
31+
32+
func (erc20Strategy) Deploy(b cldf_ops.Bundle, chain evm.Chain, in tokensapi.DeployTokenInput) (datastore.AddressRef, []contract.WriteOutput, error) {
33+
qualifier := in.Symbol
34+
ref, err := contract.MaybeDeployContract(b, erc20.Deploy, chain, contract.DeployInput[erc20.ConstructorArgs]{
35+
TypeAndVersion: deployment.NewTypeAndVersion(erc20.ContractType, *common_utils.Version_1_0_0),
36+
ChainSelector: chain.Selector,
37+
Args: erc20.ConstructorArgs{
38+
Name: in.Name,
39+
Symbol: in.Symbol,
40+
},
41+
Qualifier: &qualifier,
42+
}, nil)
43+
if err != nil {
44+
return datastore.AddressRef{}, nil, fmt.Errorf("failed to deploy ERC20 token: %w", err)
45+
}
46+
return ref, nil, nil
47+
}
48+
49+
func (erc20Strategy) GrantPoolRoles(_ cldf_ops.Bundle, _ evm.Chain, _, _ common.Address, _ uint64) ([]contract.WriteOutput, error) {
50+
return nil, nil
51+
}
52+
53+
func (erc20Strategy) GrantExternalAdmin(_ cldf_ops.Bundle, _ evm.Chain, _, _ common.Address, _ uint64) ([]contract.WriteOutput, error) {
54+
return nil, nil
55+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package registrations
2+
3+
import (
4+
"fmt"
5+
"math/big"
6+
7+
"github.com/ethereum/go-ethereum/accounts/abi/bind"
8+
"github.com/ethereum/go-ethereum/common"
9+
10+
"github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v1_0_0/operations/burn_mint_erc20"
11+
tokensapi "github.com/smartcontractkit/chainlink-ccip/deployment/tokens"
12+
"github.com/smartcontractkit/chainlink-deployments-framework/chain/evm"
13+
"github.com/smartcontractkit/chainlink-deployments-framework/chain/evm/operations/contract"
14+
cldf_ops "github.com/smartcontractkit/chainlink-deployments-framework/operations"
15+
bnm_erc20_bindings "github.com/smartcontractkit/chainlink-evm/gethwrappers/shared/generated/initial/burn_mint_erc20"
16+
)
17+
18+
func scaledSupplyAndPreMint(in tokensapi.DeployTokenInput) (*big.Int, *big.Int) {
19+
maxSupply := big.NewInt(0)
20+
if in.Supply != nil {
21+
maxSupply = tokensapi.ScaleTokenAmount(new(big.Int).SetUint64(*in.Supply), in.Decimals)
22+
}
23+
preMint := big.NewInt(0)
24+
if in.PreMint != nil {
25+
preMint = tokensapi.ScaleTokenAmount(new(big.Int).SetUint64(*in.PreMint), in.Decimals)
26+
}
27+
return maxSupply, preMint
28+
}
29+
30+
// grantBnMMintAndBurnRoles is shared by all BnM-family strategies.
31+
// Historically the BnM, BnM+Drip (v1.0.0), and BnM+Drip (v1.5.0) types
32+
// all dispatch to burn_mint_erc20.GrantMintAndBurnRoles (the v1.0.0 op);
33+
// preserved here verbatim.
34+
func grantBnMMintAndBurnRoles(b cldf_ops.Bundle, chain evm.Chain, token, pool common.Address, chainSelector uint64) ([]contract.WriteOutput, error) {
35+
report, err := cldf_ops.ExecuteOperation(b, burn_mint_erc20.GrantMintAndBurnRoles, chain, contract.FunctionInput[common.Address]{
36+
ChainSelector: chainSelector,
37+
Address: token,
38+
Args: pool,
39+
})
40+
if err != nil {
41+
return nil, fmt.Errorf("failed to grant mint and burn roles: %w", err)
42+
}
43+
return []contract.WriteOutput{report.Output}, nil
44+
}
45+
46+
func grantBnMDefaultAdminRole(b cldf_ops.Bundle, chain evm.Chain, token, externalAdmin common.Address, chainSelector uint64) ([]contract.WriteOutput, error) {
47+
tokenContract, err := bnm_erc20_bindings.NewBurnMintERC20(token, chain.Client)
48+
if err != nil {
49+
return nil, fmt.Errorf("failed to instantiate BurnMintERC20 contract: %w", err)
50+
}
51+
role, err := tokenContract.DEFAULTADMINROLE(&bind.CallOpts{Context: b.GetContext()})
52+
if err != nil {
53+
return nil, fmt.Errorf("failed to get default admin role constant: %w", err)
54+
}
55+
report, err := cldf_ops.ExecuteOperation(b, burn_mint_erc20.GrantAdminRole, chain, contract.FunctionInput[burn_mint_erc20.RoleAssignment]{
56+
ChainSelector: chainSelector,
57+
Address: token,
58+
Args: burn_mint_erc20.RoleAssignment{
59+
Role: role,
60+
To: externalAdmin,
61+
},
62+
})
63+
if err != nil {
64+
return nil, fmt.Errorf("failed to grant default admin role: %w", err)
65+
}
66+
return []contract.WriteOutput{report.Output}, nil
67+
}

0 commit comments

Comments
 (0)