Skip to content

Commit

Permalink
Make fns private
Browse files Browse the repository at this point in the history
  • Loading branch information
kylesmartin committed Jan 10, 2025
1 parent b85e787 commit 9abacee
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 29 deletions.
36 changes: 18 additions & 18 deletions deployment/ccip/changeset/cs_deploy_token_pools.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ Others, not as urgent

var _ deployment.ChangeSet[DeployTokenPoolContractsConfig] = DeployTokenPoolContracts

// Zero returns a zero-value big.Int.
func Zero() *big.Int {
// zero returns a zero-value big.Int.
func zero() *big.Int {
return big.NewInt(0)
}

// ZeroAddress returns a zero-value Ethereum address.
func ZeroAddress() common.Address {
return common.BigToAddress(Zero())
// zeroAddress returns a zero-value Ethereum address.
func zeroAddress() common.Address {
return common.BigToAddress(zero())
}

// TokenChainConfig defines all information required to construct operations that fully configure the pool.
Expand All @@ -68,11 +68,11 @@ type RateLimiterConfig struct {
// see https://github.com/smartcontractkit/ccip/blob/ccip-develop/contracts/src/v0.8/ccip/libraries/RateLimiter.sol.
func validateRateLimiterConfig(rateLimiterConfig token_pool.RateLimiterConfig) error {
if rateLimiterConfig.IsEnabled {
if rateLimiterConfig.Rate.Cmp(rateLimiterConfig.Capacity) >= 0 || rateLimiterConfig.Rate.Cmp(Zero()) == 0 {
if rateLimiterConfig.Rate.Cmp(rateLimiterConfig.Capacity) >= 0 || rateLimiterConfig.Rate.Cmp(zero()) == 0 {
return errors.New("rate must be greater than 0 and less than capacity")
}
} else {
if rateLimiterConfig.Rate.Cmp(Zero()) != 0 || rateLimiterConfig.Capacity.Cmp(Zero()) != 0 {
if rateLimiterConfig.Rate.Cmp(zero()) != 0 || rateLimiterConfig.Capacity.Cmp(zero()) != 0 {
return errors.New("rate and capacity must be 0")
}
}
Expand Down Expand Up @@ -258,7 +258,7 @@ func fetchAndValidateTimelockOwnedTokenPool(
if err != nil {
return TokenChainConfig{}, fmt.Errorf("failed to get config on %s registry for token with address %s: %w", chainEnv.Name(), chainConfig.TokenAddress, err)
}
if tokenConfigOnRegistry.TokenPool.Cmp(ZeroAddress()) == 0 {
if tokenConfigOnRegistry.TokenPool.Cmp(zeroAddress()) == 0 {
return TokenChainConfig{}, fmt.Errorf("token with address %s is not set on %s registry: %w", chainConfig.TokenAddress, chainEnv.Name(), err)
}
tokenPool, err := token_pool.NewTokenPool(tokenConfigOnRegistry.TokenPool, chainEnv.Client)
Expand Down Expand Up @@ -423,7 +423,7 @@ func makeTokenPoolOperationsForChain(
batch = append(batch, mcms.Operation{
To: tokenChainConfig.TokenPool.Address(),
Data: acceptOwnershipTx.Data(),
Value: Zero(),
Value: zero(),
})
}

Expand All @@ -436,7 +436,7 @@ func makeTokenPoolOperationsForChain(
}
remotePoolAddresses := [][]byte{remoteTokenConfig.TokenPool.Address().Bytes()}
// If the token pool on the remote chain's registry is not the current pool nor the zero address, we should add it as a supported remote pool to avoid downtime
if remoteTokenConfig.RegistryState.TokenPool.Cmp(remoteTokenConfig.TokenPool.Address()) != 0 && remoteTokenConfig.RegistryState.TokenPool.Cmp(ZeroAddress()) != 0 {
if remoteTokenConfig.RegistryState.TokenPool.Cmp(remoteTokenConfig.TokenPool.Address()) != 0 && remoteTokenConfig.RegistryState.TokenPool.Cmp(zeroAddress()) != 0 {
remotePoolAddresses = append(remotePoolAddresses, remoteTokenConfig.RegistryState.TokenPool.Bytes())
}
chainUpdates = append(chainUpdates, token_pool.TokenPoolChainUpdate{
Expand All @@ -455,12 +455,12 @@ func makeTokenPoolOperationsForChain(
batch = append(batch, mcms.Operation{
To: tokenChainConfig.TokenPool.Address(),
Data: applyChainUpdatesTx.Data(),
Value: Zero(),
Value: zero(),
})
}

// Set the administrator of the token to the timelock (if it hasn't been set before)
noExistingAdmin := tokenChainConfig.RegistryState.Administrator.Cmp(ZeroAddress()) == 0
noExistingAdmin := tokenChainConfig.RegistryState.Administrator.Cmp(zeroAddress()) == 0
if noExistingAdmin {
proposeAdministratorTx, err := tokenChainConfig.TokenAdminRegistry.ProposeAdministrator(deployment.SimTransactOpts(), tokenChainConfig.TokenAddress, tokenChainConfig.TimelockAddress)
if err != nil {
Expand All @@ -469,7 +469,7 @@ func makeTokenPoolOperationsForChain(
batch = append(batch, mcms.Operation{
To: tokenChainConfig.TokenAdminRegistry.Address(),
Data: proposeAdministratorTx.Data(),
Value: Zero(),
Value: zero(),
})
acceptAdminRoleTx, err := tokenChainConfig.TokenAdminRegistry.AcceptAdminRole(deployment.SimTransactOpts(), tokenChainConfig.TokenAddress)
if err != nil {
Expand All @@ -478,7 +478,7 @@ func makeTokenPoolOperationsForChain(
batch = append(batch, mcms.Operation{
To: tokenChainConfig.TokenAdminRegistry.Address(),
Data: acceptAdminRoleTx.Data(),
Value: Zero(),
Value: zero(),
})
}
isTimelockAdmin := noExistingAdmin || tokenChainConfig.RegistryState.Administrator.Cmp(tokenChainConfig.TimelockAddress) == 0
Expand All @@ -492,21 +492,21 @@ func makeTokenPoolOperationsForChain(
batch = append(batch, mcms.Operation{
To: tokenChainConfig.TokenAdminRegistry.Address(),
Data: setPoolTx.Data(),
Value: Zero(),
Value: zero(),
})
}

// If an external admin is specified & timelock is currently the admin, transfer ownership of the pool and admin rights on the registry.
// The timelock would be the owner of the pool at this point, so we don't need to check ownership there.
if isTimelockAdmin && tokenChainConfig.ExternalAdmin.Cmp(ZeroAddress()) != 0 {
if isTimelockAdmin && tokenChainConfig.ExternalAdmin.Cmp(zeroAddress()) != 0 {
transferAdminRoleTx, err := tokenChainConfig.TokenAdminRegistry.TransferAdminRole(deployment.SimTransactOpts(), tokenChainConfig.TokenAddress, tokenChainConfig.ExternalAdmin)
if err != nil {
return []mcms.Operation{}, fmt.Errorf("failed to create transferAdminRole transaction: %w", err)
}
batch = append(batch, mcms.Operation{
To: tokenChainConfig.TokenAdminRegistry.Address(),
Data: transferAdminRoleTx.Data(),
Value: Zero(),
Value: zero(),
})
transferOwnershipTx, err := tokenChainConfig.TokenPool.TransferOwnership(deployment.SimTransactOpts(), tokenChainConfig.ExternalAdmin)
if err != nil {
Expand All @@ -515,7 +515,7 @@ func makeTokenPoolOperationsForChain(
batch = append(batch, mcms.Operation{
To: tokenChainConfig.TokenPool.Address(),
Data: transferOwnershipTx.Data(),
Value: Zero(),
Value: zero(),
})
}

Expand Down
24 changes: 13 additions & 11 deletions deployment/ccip/changeset/cs_deploy_token_pools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
)

const localTokenDecimals = 18
const testTokenSymbol = "TEST"

// createSymmetricRateLimits is a utility to quickly create a rate limiter config with equal inbound and outbound values
func createSymmetricRateLimits(rate int64, capacity int64) RateLimiterConfig {
Expand Down Expand Up @@ -52,11 +53,6 @@ func setup2ChainEnvironment(t *testing.T) (deployment.Environment, uint64, uint6
ChainSelector: selector,
})
}
// Deploys all pre-1.6 contracts, which are all we need for these particular tests
deployPrerequisiteChainContracts(e, addressBook, DeployPrerequisiteConfig{
Configs: prereqCfg,
})
e.ExistingAddresses = addressBook

mcmsCfg := make(map[uint64]commontypes.MCMSWithTimelockConfig)
for _, selector := range selectors {
Expand All @@ -71,8 +67,8 @@ func setup2ChainEnvironment(t *testing.T) (deployment.Environment, uint64, uint6
tokenAddress, tx, token, err := burn_mint_erc677.DeployBurnMintERC677(
e.Chains[selector].DeployerKey,
e.Chains[selector].Client,
"TEST",
"TEST",
testTokenSymbol,
testTokenSymbol,
localTokenDecimals,
big.NewInt(0).Mul(big.NewInt(1e9), big.NewInt(1e18)),
)
Expand All @@ -89,8 +85,14 @@ func setup2ChainEnvironment(t *testing.T) (deployment.Environment, uint64, uint6
tokens[selector] = token
}

// Deploy MCMS & Timelock setup
// Deploy MCMS setup & prerequisite contracts
e, err := commonchangeset.ApplyChangesets(t, e, nil, []commonchangeset.ChangesetApplication{
{
Changeset: commonchangeset.WrapChangeSet(DeployPrerequisites),
Config: DeployPrerequisiteConfig{
Configs: prereqCfg,
},
},
{
Changeset: commonchangeset.WrapChangeSet(commonchangeset.DeployMCMSWithTimelock),
Config: mcmsCfg,
Expand Down Expand Up @@ -139,7 +141,7 @@ func TestDeployTokenPoolContracts_DeployNew(t *testing.T) {
{
Changeset: commonchangeset.WrapChangeSet(DeployTokenPoolContracts),
Config: DeployTokenPoolContractsConfig{
Symbol: "TEST",
Symbol: testTokenSymbol,
TimelockDelay: 0 * time.Second,
NewPools: map[uint64]NewTokenPoolInput{
selectorA: {
Expand Down Expand Up @@ -173,7 +175,7 @@ func TestDeployTokenPoolContracts_DeployNew(t *testing.T) {

for _, selector := range []uint64{selectorA, selectorB} {
timelockAddress := state.Chains[selector].Timelock.Address()
burnMintTokenPool := state.Chains[selector].BurnMintTokenPools["TEST"]
burnMintTokenPool := state.Chains[selector].BurnMintTokenPools[testTokenSymbol]

// Verify that the timelock is the owner
owner, err := burnMintTokenPool.Owner(nil)
Expand Down Expand Up @@ -208,7 +210,7 @@ func TestDeployTokenPoolContracts_DeployNew(t *testing.T) {
require.NoError(t, err)
require.Equal(t, tokens[supportedChain].Address.Bytes(), remoteTokenAddress)

remoteBurnMintPool := state.Chains[supportedChain].BurnMintTokenPools["TEST"]
remoteBurnMintPool := state.Chains[supportedChain].BurnMintTokenPools[testTokenSymbol]
remotePoolAddresses, err := burnMintTokenPool.GetRemotePools(nil, supportedChain)
require.NoError(t, err)
require.Equal(t, [][]byte{remoteBurnMintPool.Address().Bytes()}, remotePoolAddresses)
Expand Down

0 comments on commit 9abacee

Please sign in to comment.