Skip to content

Commit

Permalink
add temporary fixes to get the code to compile
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavogama-cll committed Jan 31, 2025
1 parent b33f02a commit f7cd53e
Show file tree
Hide file tree
Showing 9 changed files with 201 additions and 75 deletions.
2 changes: 2 additions & 0 deletions deployment/ccip/changeset/cs_deploy_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,8 @@ func initializeRouter(e deployment.Environment, chain deployment.SolChain, ccipR
true, // allow out of order execution
EnableExecutionAfter, // period to wait before allowing manual execution
solana.PublicKey{}, // fee aggregator
solana.PublicKey{}, // FIXME: linkTokenMint
solBinary.Uint128{}, // FIXME: maxFeeJuelsPerMsg
GetRouterConfigPDA(ccipRouterProgram),
GetRouterStatePDA(ccipRouterProgram),
chain.DeployerKey.PublicKey(),
Expand Down
8 changes: 6 additions & 2 deletions deployment/ccip/changeset/solana/cs_chain_contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (cfg AddRemoteChainToSolanaConfig) Validate(e deployment.Environment) error
if _, ok := supportedChains[remote]; !ok {
return fmt.Errorf("remote chain %d is not supported", remote)
}
if remote == routerConfigAccount.SolanaChainSelector {
if remote == routerConfigAccount.SvmChainSelector {
return fmt.Errorf("cannot add remote chain with same chain selector as current chain %d", remote)
}
}
Expand Down Expand Up @@ -110,7 +110,11 @@ func doAddRemoteChainToSolana(e deployment.Environment, s cs.CCIPOnChainState, c
// TODO: this should be GetSourceChainStatePDA
sourceChainStatePDA := cs.GetEvmSourceChainStatePDA(ccipRouterID, destination)
validSourceChainConfig := solRouter.SourceChainConfig{
OnRamp: []byte(update.RemoteChainOnRampAddress),
OnRamp: [2][64]byte{
// FIXME:
solana.MustSignatureFromBase58(update.RemoteChainOnRampAddress),
solana.MustSignatureFromBase58(update.RemoteChainOnRampAddress),
},
IsEnabled: update.EnabledAsSource,
}
// TODO: this should be GetDestChainStatePDA
Expand Down
5 changes: 3 additions & 2 deletions deployment/ccip/changeset/testhelpers/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset"
changeset_solana "github.com/smartcontractkit/chainlink/deployment/ccip/changeset/solana"
commoncs "github.com/smartcontractkit/chainlink/deployment/common/changeset"
commonstate "github.com/smartcontractkit/chainlink/deployment/common/changeset/state"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/fee_quoter"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/capabilities_registry"
"github.com/smartcontractkit/chainlink/v2/core/services/relay"
Expand Down Expand Up @@ -1359,7 +1360,7 @@ func SavePreloadedSolAddresses(t *testing.T, e deployment.Environment, solChainS
err := e.ExistingAddresses.Save(solChainSelector, solTestConfig.CcipRouterProgram.String(), tv)
require.NoError(t, err)
tv = deployment.NewTypeAndVersion(changeset.Receiver, deployment.Version1_0_0)
err = e.ExistingAddresses.Save(solChainSelector, solTestConfig.CcipReceiverProgram.String(), tv)
err = e.ExistingAddresses.Save(solChainSelector, solTestConfig.CcipLogicReceiver.String(), tv)
require.NoError(t, err)
}

Expand Down Expand Up @@ -1472,7 +1473,7 @@ func DeployLinkTokenTest(t *testing.T, solChains int) {
require.NoError(t, err)
addrs, err := e.ExistingAddresses.AddressesForChain(chain1)
require.NoError(t, err)
state, err := commoncs.MaybeLoadLinkTokenChainState(e.Chains[chain1], addrs)
state, err := commonstate.MaybeLoadLinkTokenChainState(e.Chains[chain1], addrs)
require.NoError(t, err)
// View itself already unit tested
_, err = state.GenerateLinkView()
Expand Down
44 changes: 22 additions & 22 deletions deployment/common/changeset/mcmsnew/solana/mcms.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ import (
"fmt"

"github.com/Masterminds/semver/v3"
binary "github.com/gagliardetto/binary"
"github.com/gagliardetto/solana-go"
"github.com/gagliardetto/solana-go/rpc"

mcmBindings "github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings/mcm"
"github.com/smartcontractkit/chainlink-common/pkg/logger"
mcmsTypes "github.com/smartcontractkit/mcms/types"

"github.com/smartcontractkit/chainlink/deployment"
mcmsNewTypes "github.com/smartcontractkit/chainlink/deployment/common/changeset/mcmsnew/types"
proposalUtilsSol "github.com/smartcontractkit/chainlink/deployment/common/proposalutils/solana"
"github.com/smartcontractkit/chainlink/deployment/common/types"
"github.com/smartcontractkit/chainlink/deployment/common/changeset/state"
)

const MCMSBinaryName = "mcms"
Expand Down Expand Up @@ -46,8 +47,8 @@ func deployMCMSWithConfigSolana(
}
// We purposefully don't check errors here to allow for the state to have Zero() values on
// programs that are not deployed.
state, _ := proposalUtilsSol.MaybeLoadMCMSSolanaWithTimelockContracts(chain, addresses)
mcmState := state.GetStateFromType(contractType)
chainState, _ := state.MaybeLoadMCMSWithTimelockChainStateSolana(chain, addresses)
mcmState := chainState.GetStateFromType(contractType)
if mcmState.IsZero() {
programID, err := chain.DeployProgram(lggr, MCMSBinaryName)
if err != nil {
Expand All @@ -73,10 +74,10 @@ func deployMCMSWithConfigSolana(
}

// TODO: modify helper to accept and Environment param
err := initializeMCM(e, chain, timelockProgram, config.TimelockMinDelay)
if err != nil {
return solana.PublicKey{}, PDASeed{}, fmt.Errorf("unable to initialize timelock: %w", err)
}
// err := initializeMCM(e, chain, timelockProgram, config.TimelockMinDelay)
// if err != nil {
// return solana.PublicKey{}, PDASeed{}, fmt.Errorf("unable to initialize timelock: %w", err)
// }
mcmBindings.SetProgramID(mcmProgram)

// FIXME: review if we need to setup an "AddressLookupTable".
Expand Down Expand Up @@ -142,23 +143,22 @@ func DeployMCMSWithTimelockProgramsSolana(
ab deployment.AddressBook,
config mcmsNewTypes.MCMSWithTimelockConfig,
) (*MCMSWithTimelockSolanaDeploy, error) {

bypasserProgramID, bypasserSeed, err := deployMCMSWithConfigSolana(types.BypasserManyChainMultisig, deployment.Version1_0_0, lggr, chain, ab, config.Bypasser)
if err != nil {
return nil, err
}
cancellerProgramID, cancellerSeed, err := deployMCMSWithConfigSolana(types.CancellerManyChainMultisig, deployment.Version1_0_0, lggr, chain, ab, config.Canceller)
if err != nil {
return nil, err
}
proposer, proposerSeed, err := deployMCMSWithConfigSolana(types.ProposerManyChainMultisig, deployment.Version1_0_0, lggr, chain, ab, config.Proposer)
if err != nil {
return nil, err
}
// bypasserProgramID, bypasserSeed, err := deployMCMSWithConfigSolana(types.BypasserManyChainMultisig, deployment.Version1_0_0, lggr, chain, ab, config.Bypasser)
// if err != nil {
// return nil, err
// }
// cancellerProgramID, cancellerSeed, err := deployMCMSWithConfigSolana(types.CancellerManyChainMultisig, deployment.Version1_0_0, lggr, chain, ab, config.Canceller)
// if err != nil {
// return nil, err
// }
// proposer, proposerSeed, err := deployMCMSWithConfigSolana(types.ProposerManyChainMultisig, deployment.Version1_0_0, lggr, chain, ab, config.Proposer)
// if err != nil {
// return nil, err
// }

// TODO: populate this, we need deployMCMSWithConfigSolana to generate a new seed or return the existing one by parsing it from the addressbook.
result := &MCMSWithTimelockSolanaDeploy{
McmProgram: bypasser,
// McmProgram: bypasser,
}

return result, nil
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package state

import (
"errors"
"fmt"
Expand Down
109 changes: 109 additions & 0 deletions deployment/common/changeset/state/solana.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package state

import (
"fmt"

"github.com/gagliardetto/solana-go"

"github.com/smartcontractkit/chainlink/deployment"
proposalutilssolana "github.com/smartcontractkit/chainlink/deployment/common/proposalutils/solana"
"github.com/smartcontractkit/chainlink/deployment/common/types"
)

// MCMSWithTimelockStateStateSolana holds the Go bindings
// for a MCMSWithTimelock contract deployment.
// It is public for use in product specific packages.
// Either all fields are nil or all fields are non-nil.
type MCMSWithTimelockStateSolana struct {
*proposalutilssolana.MCMSWithTimelockProgramsSolana
}

// MaybeLoadMCMSWithTimelockState loads the MCMSWithTimelockState state for each chain in the given environment.
func MaybeLoadMCMSWithTimelockStateSolana(env deployment.Environment, chainSelectors []uint64) (map[uint64]*MCMSWithTimelockStateSolana, error) {
result := map[uint64]*MCMSWithTimelockStateSolana{}
for _, chainSelector := range chainSelectors {
chain, ok := env.SolChains[chainSelector]
if !ok {
return nil, fmt.Errorf("chain %d not found", chainSelector)
}
addressesChain, err := env.ExistingAddresses.AddressesForChain(chainSelector)
if err != nil {
return nil, err
}
state, err := MaybeLoadMCMSWithTimelockChainStateSolana(chain, addressesChain)
if err != nil {
return nil, err
}
result[chainSelector] = state
}
return result, nil
}

// MaybeLoadMCMSWithTimelockChainState looks for the addresses corresponding to
// contracts deployed with DeployMCMSWithTimelock and loads them into a
// MCMSWithTimelockState struct. If none of the contracts are found, the state struct will be nil.
// An error indicates:
// - Found but was unable to load a contract
// - It only found part of the bundle of contracts
// - If found more than one instance of a contract (we expect one bundle in the given addresses)
func MaybeLoadMCMSWithTimelockChainStateSolana(chain deployment.SolChain, addresses map[string]deployment.TypeAndVersion) (*MCMSWithTimelockStateSolana, error) {
state := MCMSWithTimelockStateSolana{
MCMSWithTimelockProgramsSolana: &proposalutilssolana.MCMSWithTimelockProgramsSolana{},
}
// We expect one of each contract on the chain.
timelock := deployment.NewTypeAndVersion(types.RBACTimelock, deployment.Version1_0_0)
callProxy := deployment.NewTypeAndVersion(types.CallProxy, deployment.Version1_0_0)
proposer := deployment.NewTypeAndVersion(types.ProposerManyChainMultisig, deployment.Version1_0_0)
canceller := deployment.NewTypeAndVersion(types.CancellerManyChainMultisig, deployment.Version1_0_0)
bypasser := deployment.NewTypeAndVersion(types.BypasserManyChainMultisig, deployment.Version1_0_0)

// Convert map keys to a slice
wantTypes := []deployment.TypeAndVersion{timelock, proposer, canceller, bypasser, callProxy}

// Ensure we either have the bundle or not.
_, err := deployment.AddressesContainBundle(addresses, wantTypes)
if err != nil {
return nil, fmt.Errorf("unable to check MCMS contracts on chain %s error: %w", chain.Name(), err)
}

for address, tvStr := range addresses {
switch {
case tvStr.Type == timelock.Type && tvStr.Version.String() == timelock.Version.String():
pub, err := solana.PublicKeyFromBase58(address)
if err != nil {
return nil, fmt.Errorf("unable to create solana public key from timelock address (%s): %w", address, err)
}
state.Timelock = pub

case tvStr.Type == callProxy.Type && tvStr.Version.String() == callProxy.Version.String():
pub, err := solana.PublicKeyFromBase58(address)
if err != nil {
return nil, fmt.Errorf("unable to create solana public key from timelock address (%s): %w", address, err)
}
state.CallProxy = pub

case tvStr.Type == proposer.Type && tvStr.Version.String() == proposer.Version.String():
pub, err := solana.PublicKeyFromBase58(address)
if err != nil {
return nil, fmt.Errorf("unable to create solana public key from timelock address (%s): %w", address, err)
}
state.ProposerMcm = pub

case tvStr.Type == bypasser.Type && tvStr.Version.String() == bypasser.Version.String():
pub, err := solana.PublicKeyFromBase58(address)
if err != nil {
return nil, fmt.Errorf("unable to create solana public key from timelock address (%s): %w", address, err)
}
state.BypasserMcm = pub

case tvStr.Type == canceller.Type && tvStr.Version.String() == canceller.Version.String():
pub, err := solana.PublicKeyFromBase58(address)
if err != nil {
return nil, fmt.Errorf("unable to create solana public key from timelock address (%s): %w", address, err)
}
state.CancellerMcm = pub
}

}
return &state, nil
}
96 changes: 49 additions & 47 deletions deployment/common/proposalutils/solana/mcms_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package solana

import (
"errors"
"fmt"

"github.com/gagliardetto/solana-go"

Expand Down Expand Up @@ -60,49 +59,52 @@ func (state MCMSWithTimelockProgramsSolana) Validate() error {
return nil
}

// MaybeLoadMCMSSolanaWithTimelockContracts looks for the program IDs / seeds corresponding to
// contracts deployed with DeployMCMSWithTimelock and loads them into a
// MCMSWithTimelockState struct. If none of the contracts are found, the state struct will be nil.
// An error indicates:
// - Found but was unable to load a contract
// - It only found part of the bundle of contracts
// - If found more than one instance of a contract (we expect one bundle in the given addresses)
func MaybeLoadMCMSSolanaWithTimelockContracts(solChain deployment.SolChain, addresses map[string]deployment.TypeAndVersion) (*MCMSWithTimelockProgramsSolana, error) {
state := MCMSWithTimelockProgramsSolana{}
// We expect one of each contract on the chain.
timelock := deployment.NewTypeAndVersion(types.RBACTimelock, deployment.Version1_0_0)
callProxy := deployment.NewTypeAndVersion(types.CallProxy, deployment.Version1_0_0)
proposer := deployment.NewTypeAndVersion(types.ProposerManyChainMultisig, deployment.Version1_0_0)
canceller := deployment.NewTypeAndVersion(types.CancellerManyChainMultisig, deployment.Version1_0_0)
bypasser := deployment.NewTypeAndVersion(types.BypasserManyChainMultisig, deployment.Version1_0_0)

// Ensure we either have the bundle or not.
_, err := deployment.AddressesContainBundle(addresses,
map[deployment.TypeAndVersion]struct{}{
timelock: {}, proposer: {}, canceller: {}, bypasser: {}, callProxy: {},
})
if err != nil {
return nil, fmt.Errorf("unable to check MCMS contracts on chain %s error: %w", solChain.Name(), err)
}

for address, tvStr := range addresses {
switch tvStr {
case timelock:
pub := solana.MustPublicKeyFromBase58(address)
state.Timelock = pub
case callProxy:
pub := solana.MustPublicKeyFromBase58(address)
state.CallProxy = pub
case proposer:
pub := solana.MustPublicKeyFromBase58(address)
state.ProposerMcm = pub
case bypasser:
pub := solana.MustPublicKeyFromBase58(address)
state.BypasserMcm = pub
case canceller:
pub := solana.MustPublicKeyFromBase58(address)
state.CancellerMcm = pub
}
}
return &state, nil
}
// FIXME: the EVM version of MaybeLoadMCMSSolanaWithTimelockContracts is not used by anyone.
// Maybe we don't need to copy it?
//
// // MaybeLoadMCMSSolanaWithTimelockContracts looks for the program IDs / seeds corresponding to
// // contracts deployed with DeployMCMSWithTimelock and loads them into a
// // MCMSWithTimelockState struct. If none of the contracts are found, the state struct will be nil.
// // An error indicates:
// // - Found but was unable to load a contract
// // - It only found part of the bundle of contracts
// // - If found more than one instance of a contract (we expect one bundle in the given addresses)
// func MaybeLoadMCMSSolanaWithTimelockContracts(solChain deployment.SolChain, addresses map[string]deployment.TypeAndVersion) (*MCMSWithTimelockProgramsSolana, error) {
// state := MCMSWithTimelockProgramsSolana{}
// // We expect one of each contract on the chain.
// timelock := deployment.NewTypeAndVersion(types.RBACTimelock, deployment.Version1_0_0)
// callProxy := deployment.NewTypeAndVersion(types.CallProxy, deployment.Version1_0_0)
// proposer := deployment.NewTypeAndVersion(types.ProposerManyChainMultisig, deployment.Version1_0_0)
// canceller := deployment.NewTypeAndVersion(types.CancellerManyChainMultisig, deployment.Version1_0_0)
// bypasser := deployment.NewTypeAndVersion(types.BypasserManyChainMultisig, deployment.Version1_0_0)
//
// // Ensure we either have the bundle or not.
// _, err := deployment.AddressesContainBundle(addresses,
// map[deployment.TypeAndVersion]struct{}{
// timelock: {}, proposer: {}, canceller: {}, bypasser: {}, callProxy: {},
// })
// if err != nil {
// return nil, fmt.Errorf("unable to check MCMS contracts on chain %s error: %w", solChain.Name(), err)
// }
//
// for address, tvStr := range addresses {
// switch tvStr {
// case timelock:
// pub := solana.MustPublicKeyFromBase58(address)
// state.Timelock = pub
// case callProxy:
// pub := solana.MustPublicKeyFromBase58(address)
// state.CallProxy = pub
// case proposer:
// pub := solana.MustPublicKeyFromBase58(address)
// state.ProposerMcm = pub
// case bypasser:
// pub := solana.MustPublicKeyFromBase58(address)
// state.BypasserMcm = pub
// case canceller:
// pub := solana.MustPublicKeyFromBase58(address)
// state.CancellerMcm = pub
// }
// }
// return &state, nil
// }
9 changes: 9 additions & 0 deletions deployment/common/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/smartcontractkit/ccip-owner-contracts/pkg/config"
mcmstypes "github.com/smartcontractkit/mcms/types"

"github.com/smartcontractkit/chainlink/deployment"
)
Expand Down Expand Up @@ -36,6 +37,14 @@ type MCMSWithTimelockConfig struct {
Label *string
}

type MCMSWithTimelockConfigV2 struct {
Canceller mcmstypes.Config
Bypasser mcmstypes.Config
Proposer mcmstypes.Config
TimelockMinDelay *big.Int
Label *string
}

type OCRParameters struct {
DeltaProgress time.Duration
DeltaResend time.Duration
Expand Down
2 changes: 1 addition & 1 deletion deployment/environment/memory/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func solChain(t *testing.T, chainID uint64, adminKey *solana.PrivateKey) (string
programIds := map[string]string{
"ccip_router": solTestConfig.CcipRouterProgram.String(),
"token_pool": solTestConfig.CcipTokenPoolProgram.String(),
"ccip_receiver": solTestConfig.CcipReceiverProgram.String(),
"ccip_receiver": solTestConfig.CcipLogicReceiver.String(), // FIXME
}

bcInput := &blockchain.Input{
Expand Down

0 comments on commit f7cd53e

Please sign in to comment.