-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Solana TODOs #15726
Draft
yashnevatia
wants to merge
22
commits into
develop
Choose a base branch
from
yn-solana
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,637
−131
Draft
Solana TODOs #15726
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
b606a3e
adding first solana todo
yashnevatia 24ffec9
adding todos
yashnevatia 7376e7d
job spec todo
yashnevatia b7429a9
test TODOs
yashnevatia 42ed1da
Adding stuff
yashnevatia bc536f0
Adding chainlink-ccip solana pkg
yashnevatia 79c2961
solana draft
yashnevatia 8a31399
solana link token skeleton
tt-cll e681a59
merging
yashnevatia 486c512
stuff
yashnevatia c1d11f7
fixing test
yashnevatia 56e7574
bump go mod; add ccip router
tt-cll 9bd60a8
solana prereq skeleton
tt-cll 80561c9
move deploy code
tt-cll cdbe726
go mod tidy
yashnevatia aa4d2e5
merging
yashnevatia c98c36f
Adding solana link token changeset
yashnevatia 9989bcf
adding test for DeployChainContractsSolana
yashnevatia b1a192f
adding add chain selector
yashnevatia 8dcd962
removing test file
yashnevatia b4dc5a6
Merge branch 'develop' of github.com:smartcontractkit/chainlink into …
yashnevatia 0a4e0cc
adding SetOCR3ConfigSolana
yashnevatia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,231 @@ | ||
package changeset | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/gagliardetto/solana-go" | ||
"github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings/ccip_router" | ||
"github.com/smartcontractkit/chainlink/deployment" | ||
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset/internal" | ||
) | ||
|
||
// TODO: | ||
// func (cfg UpdateOnRampDestsConfig) Validate(e deployment.Environment) error { | ||
// state, err := LoadOnchainState(e) | ||
// if err != nil { | ||
// return err | ||
// } | ||
// supportedChains := state.SupportedChains() | ||
// for chainSel, updates := range cfg.UpdatesByChain { | ||
// chainState, ok := state.Chains[chainSel] | ||
// if !ok { | ||
// return fmt.Errorf("chain %d not found in onchain state", chainSel) | ||
// } | ||
// if chainState.TestRouter == nil { | ||
// return fmt.Errorf("missing test router for chain %d", chainSel) | ||
// } | ||
// if chainState.Router == nil { | ||
// return fmt.Errorf("missing router for chain %d", chainSel) | ||
// } | ||
// if chainState.OnRamp == nil { | ||
// return fmt.Errorf("missing onramp onramp for chain %d", chainSel) | ||
// } | ||
// if err := commoncs.ValidateOwnership(e.GetContext(), cfg.MCMS != nil, e.Chains[chainSel].DeployerKey.From, chainState.Timelock.Address(), chainState.OnRamp); err != nil { | ||
// return err | ||
// } | ||
|
||
// for destination := range updates { | ||
// // Destination cannot be an unknown destination. | ||
// if _, ok := supportedChains[destination]; !ok { | ||
// return fmt.Errorf("destination chain %d is not a supported %s", destination, chainState.OnRamp.Address()) | ||
// } | ||
// sc, err := chainState.OnRamp.GetStaticConfig(&bind.CallOpts{Context: e.GetContext()}) | ||
// if err != nil { | ||
// return fmt.Errorf("failed to get onramp static config %s: %w", chainState.OnRamp.Address(), err) | ||
// } | ||
// if destination == sc.ChainSelector { | ||
// return fmt.Errorf("cannot update onramp destination to the same chain") | ||
// } | ||
// } | ||
// } | ||
// return nil | ||
// } | ||
|
||
// UpdateOnRampsDests updates the onramp destinations for each onramp | ||
// in the chains specified. Multichain support is important - consider when we add a new chain | ||
// and need to update the onramp destinations for all chains to support the new chain. | ||
func UpdateOnRampsDestsSolana(e deployment.Environment, cfg UpdateOnRampDestsConfig) (deployment.ChangesetOutput, error) { | ||
|
||
s, err := LoadOnchainStateSolana(e) | ||
if err != nil { | ||
return deployment.ChangesetOutput{}, err | ||
} | ||
for chainSel, updates := range cfg.UpdatesByChain { | ||
e.Logger.Infow("Updating onramp destinations", "chain", chainSel, "updates", updates) | ||
chain := e.SolChains[chainSel] | ||
|
||
validSourceChainConfig := ccip_router.SourceChainConfig{ | ||
OnRamp: []byte{1, 2, 3}, | ||
IsEnabled: true, | ||
} | ||
|
||
ccipRouterId := s.SolChains[chainSel].CcipRouter | ||
// ccip_router.SetProgramID(ccipRouterId) //cannot set this again | ||
|
||
for destination, update := range updates { | ||
EvmSourceChainStatePDA := GetEvmSourceChainStatePDA(ccipRouterId, destination) | ||
e.Logger.Infow("EvmSourceChainStatePDA", "EvmSourceChainStatePDA", EvmSourceChainStatePDA) | ||
EvmDestChainStatePDA := GetEvmDestChainStatePDA(ccipRouterId, destination) | ||
validDestChainConfig := ccip_router.DestChainConfig{ | ||
IsEnabled: update.IsEnabled, | ||
|
||
// minimal valid config | ||
DefaultTxGasLimit: 1, | ||
MaxPerMsgGasLimit: 100, | ||
MaxDataBytes: 32, | ||
MaxNumberOfTokensPerMsg: 1, | ||
// bytes4(keccak256("CCIP ChainFamilySelector EVM")) | ||
ChainFamilySelector: [4]uint8{40, 18, 213, 44}, | ||
} | ||
|
||
instruction, err := ccip_router.NewAddChainSelectorInstruction( | ||
destination, | ||
validSourceChainConfig, | ||
validDestChainConfig, | ||
EvmSourceChainStatePDA, | ||
EvmDestChainStatePDA, | ||
GetRouterConfigPDA(ccipRouterId), | ||
chain.DeployerKey.PublicKey(), | ||
solana.SystemProgramID, | ||
).ValidateAndBuild() | ||
|
||
if err != nil { | ||
return deployment.ChangesetOutput{}, fmt.Errorf("failed to generate instructions: %v", err) | ||
} | ||
|
||
err = chain.Confirm([]solana.Instruction{instruction}) | ||
|
||
if err != nil { | ||
return deployment.ChangesetOutput{}, fmt.Errorf("failed to confirm instructions: %v", err) | ||
} else { | ||
e.Logger.Infow("Confirmed instruction", "instruction", instruction) | ||
} | ||
} | ||
} | ||
|
||
return deployment.ChangesetOutput{}, nil | ||
} | ||
|
||
func btoi(b bool) uint8 { | ||
if b { | ||
return 1 | ||
} | ||
return 0 | ||
} | ||
|
||
// SetOCR3OffRamp will set the OCR3 offramp for the given chain. | ||
// to the active configuration on CCIPHome. This | ||
// is used to complete the candidate->active promotion cycle, it's | ||
// run after the candidate is confirmed to be working correctly. | ||
// Multichain is especially helpful for NOP rotations where we have | ||
// to touch all the chain to change signers. | ||
func SetOCR3ConfigSolana(e deployment.Environment, cfg SetOCR3OffRampConfig) (deployment.ChangesetOutput, error) { | ||
// if err := cfg.Validate(e); err != nil { | ||
// return deployment.ChangesetOutput{}, err | ||
// } | ||
|
||
solState, err := LoadOnchainStateSolana(e) | ||
if err != nil { | ||
return deployment.ChangesetOutput{}, err | ||
} | ||
state, err := LoadOnchainState(e) | ||
if err != nil { | ||
return deployment.ChangesetOutput{}, err | ||
} | ||
|
||
// cfg.RemoteChainSels will be a bunch of solana chains | ||
// can add this in validate | ||
for _, remote := range cfg.RemoteChainSels { | ||
donID, err := internal.DonIDForChain( | ||
state.Chains[cfg.HomeChainSel].CapabilityRegistry, | ||
state.Chains[cfg.HomeChainSel].CCIPHome, | ||
remote) | ||
if err != nil { | ||
return deployment.ChangesetOutput{}, err | ||
} | ||
args, err := internal.BuildSetOCR3ConfigArgsSolana(donID, state.Chains[cfg.HomeChainSel].CCIPHome, remote) | ||
if err != nil { | ||
return deployment.ChangesetOutput{}, err | ||
} | ||
// set, err := isOCR3ConfigSetSolana(e.Logger, e.Chains[remote], state.Chains[remote].OffRamp, args) | ||
// if err != nil { | ||
// return deployment.ChangesetOutput{}, err | ||
// } | ||
// if set { | ||
// e.Logger.Infof("OCR3 config already set on offramp for chain %d", remote) | ||
// continue | ||
// } | ||
var instructions []solana.Instruction | ||
ccipRouterId := solState.SolChains[remote].CcipRouter | ||
for _, arg := range args { | ||
instruction, err := ccip_router.NewSetOcrConfigInstruction( | ||
uint8(arg.OcrPluginType), | ||
ccip_router.Ocr3ConfigInfo{ | ||
ConfigDigest: arg.ConfigDigest, | ||
F: arg.F, | ||
IsSignatureVerificationEnabled: uint8(btoi(arg.IsSignatureVerificationEnabled)), | ||
}, | ||
arg.Signers, | ||
arg.Transmitters, | ||
GetRouterConfigPDA(ccipRouterId), | ||
GetRouterStatePDA(ccipRouterId), | ||
e.SolChains[remote].DeployerKey.PublicKey(), | ||
).ValidateAndBuild() | ||
if err != nil { | ||
return deployment.ChangesetOutput{}, err | ||
} | ||
instructions = append(instructions, instruction) | ||
} | ||
if cfg.MCMS == nil { | ||
err := e.SolChains[remote].Confirm(instructions) | ||
if err != nil { | ||
return deployment.ChangesetOutput{}, err | ||
} | ||
} | ||
} | ||
|
||
return deployment.ChangesetOutput{}, nil | ||
|
||
// var batches []timelock.BatchChainOperation | ||
// timelocks := make(map[uint64]common.Address) | ||
// proposers := make(map[uint64]*mcm.MCM) | ||
// else { | ||
// batches = append(batches, timelock.BatchChainOperation{ | ||
// ChainIdentifier: mcms.ChainIdentifier(remote), | ||
// Batch: []mcms.Operation{ | ||
// { | ||
// To: offRamp.Address(), | ||
// Data: tx.Data(), | ||
// Value: big.NewInt(0), | ||
// }, | ||
// }, | ||
// }) | ||
// timelocks[remote] = state.Chains[remote].Timelock.Address() | ||
// proposers[remote] = state.Chains[remote].ProposerMcm | ||
// } | ||
// p, err := proposalutils.BuildProposalFromBatches( | ||
// timelocks, | ||
// proposers, | ||
// batches, | ||
// "Update OCR3 config", | ||
// cfg.MCMS.MinDelay, | ||
// ) | ||
// if err != nil { | ||
// return deployment.ChangesetOutput{}, err | ||
// } | ||
// e.Logger.Infof("Proposing OCR3 config update for", cfg.RemoteChainSels) | ||
// return deployment.ChangesetOutput{Proposals: []timelock.MCMSWithTimelockProposal{ | ||
// *p, | ||
// }}, nil | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, this worked for me when I ran it outside of nix