Skip to content

Commit

Permalink
add sol chains to serialized output
Browse files Browse the repository at this point in the history
  • Loading branch information
tt-cll committed Dec 16, 2024
1 parent beb82ec commit bd79507
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 14 deletions.
2 changes: 1 addition & 1 deletion deployment/ccip/changeset/cs_deploy_chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestDeployCCIPContracts(t *testing.T) {
// Deploy all the CCIP contracts.
state, err := LoadOnchainState(e.Env)
require.NoError(t, err)
snap, err := state.View(e.Env.AllChainSelectors())
snap, _, err := state.View(e.Env.AllChainSelectors())
require.NoError(t, err)

// Assert expect every deployed address to be in the address book.
Expand Down
2 changes: 1 addition & 1 deletion deployment/ccip/changeset/cs_home_chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestDeployHomeChain(t *testing.T) {
require.NotNil(t, state.Chains[homeChainSel].CapabilityRegistry)
require.NotNil(t, state.Chains[homeChainSel].CCIPHome)
require.NotNil(t, state.Chains[homeChainSel].RMNHome)
snap, err := state.View([]uint64{homeChainSel})
snap, _, err := state.View([]uint64{homeChainSel})
require.NoError(t, err)
chainName := e.Chains[homeChainSel].Name()
_, ok := snap[chainName]
Expand Down
3 changes: 3 additions & 0 deletions deployment/ccip/changeset/solana_state.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package changeset

// TODO: create similar struct as CCIPChainState, but with Sol specific primitives
// SolChainState holds a Go binding for all the currently deployed CCIP programs
// on a chain. If a binding is nil, it means here is no such contract on the chain.
type SolCCIPChainState struct {
}

// TODO: create GenerateSolanaView function similar to GenerateView
17 changes: 11 additions & 6 deletions deployment/ccip/changeset/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,29 +289,32 @@ func (s CCIPOnChainState) GetAllTimeLocksForChains(chains []uint64) (map[uint64]
return timelocks, nil
}

func (s CCIPOnChainState) View(chains []uint64) (map[string]view.ChainView, error) {
func (s CCIPOnChainState) View(chains []uint64) (map[string]view.ChainView, map[string]view.SolChainView, error) {
m := make(map[string]view.ChainView)
sm := make(map[string]view.SolChainView)
for _, chainSelector := range chains {
chainInfo, err := deployment.ChainInfo(chainSelector)
if err != nil {
return m, err
return m, sm, err
}
if _, ok := s.Chains[chainSelector]; !ok {
return m, fmt.Errorf("chain not supported %d", chainSelector)
return m, sm, fmt.Errorf("chain not supported %d", chainSelector)
}
chainState := s.Chains[chainSelector]
// TODO: call Solana view generation here (switch case on chainSelector)
chainView, err := chainState.GenerateView()
if err != nil {
return m, err
return m, sm, err
}
m[chainInfo.ChainName] = chainView
}
return m, nil
return m, sm, nil
}

func LoadOnchainState(e deployment.Environment) (CCIPOnChainState, error) {
state := CCIPOnChainState{
Chains: make(map[uint64]CCIPChainState),
Chains: make(map[uint64]CCIPChainState),
SolChains: make(map[uint64]SolCCIPChainState),
}
for chainSelector, chain := range e.Chains {
addresses, err := e.ExistingAddresses.AddressesForChain(chainSelector)
Expand All @@ -323,6 +326,7 @@ func LoadOnchainState(e deployment.Environment) (CCIPOnChainState, error) {
return state, err
}
}
// TODO: Load Solana state here based on chainSelector
chainState, err := LoadChainState(chain, addresses)
if err != nil {
return state, err
Expand All @@ -333,6 +337,7 @@ func LoadOnchainState(e deployment.Environment) (CCIPOnChainState, error) {
}

// LoadChainState Loads all state for a chain into state
// TODO: Add function LoadSolanaChainState
func LoadChainState(chain deployment.Chain, addresses map[string]deployment.TypeAndVersion) (CCIPChainState, error) {
var state CCIPChainState
mcmsWithTimelock, err := commoncs.MaybeLoadMCMSWithTimelockChainState(chain, addresses)
Expand Down
2 changes: 1 addition & 1 deletion deployment/ccip/changeset/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ func TestSmokeState(t *testing.T) {
tenv := NewMemoryEnvironment(t, WithChains(3))
state, err := LoadOnchainState(tenv.Env)
require.NoError(t, err)
_, err = state.View(tenv.Env.AllChainSelectors())
_, _, err = state.View(tenv.Env.AllChainSelectors())
require.NoError(t, err)
}
7 changes: 4 additions & 3 deletions deployment/ccip/changeset/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func ViewCCIP(e deployment.Environment) (json.Marshaler, error) {
if err != nil {
return nil, err
}
chainView, err := state.View(e.AllChainSelectors())
chainView, solChainView, err := state.View(e.AllChainSelectors())
if err != nil {
return nil, err
}
Expand All @@ -24,7 +24,8 @@ func ViewCCIP(e deployment.Environment) (json.Marshaler, error) {
return nil, err
}
return ccipview.CCIPView{
Chains: chainView,
Nops: nopsView,
Chains: chainView,
SolChains: solChainView,
Nops: nopsView,
}, nil
}
12 changes: 10 additions & 2 deletions deployment/ccip/view/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,17 @@ func NewChain() ChainView {
}
}

type SolChainView struct {
}

func NewSolChain() SolChainView {
return SolChainView{}
}

type CCIPView struct {
Chains map[string]ChainView `json:"chains,omitempty"`
Nops map[string]view.NopView `json:"nops,omitempty"`
Chains map[string]ChainView `json:"chains,omitempty"`
SolChains map[string]SolChainView `json:"solChains,omitempty"`
Nops map[string]view.NopView `json:"nops,omitempty"`
}

func (v CCIPView) MarshalJSON() ([]byte, error) {
Expand Down

0 comments on commit bd79507

Please sign in to comment.