Skip to content

Commit

Permalink
Adding
Browse files Browse the repository at this point in the history
  • Loading branch information
yashnevatia committed Jan 8, 2025
1 parent a4b2bc6 commit 074dacf
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
1 change: 1 addition & 0 deletions deployment/ccip/changeset/cs_deploy_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ func deployChainContractsSolana(
if err != nil {
return fmt.Errorf("failed to save address: %v", err)
}
//TODO: deploy token pool contract
}
return nil
}
28 changes: 18 additions & 10 deletions deployment/environment/memory/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/ethereum/go-ethereum/ethclient/simulated"
"github.com/gagliardetto/solana-go"
solRpc "github.com/gagliardetto/solana-go/rpc"
"github.com/mr-tron/base58"

"github.com/stretchr/testify/require"

Expand All @@ -35,6 +36,7 @@ type SolanaChain struct {
Client *solRpc.Client
DeployerKey *solana.PrivateKey
URL string
WSURL string
KeypairPath string
}

Expand Down Expand Up @@ -84,15 +86,20 @@ func generateAndStoreKeypair() (solana.PrivateKey, string, error) {
return solana.PrivateKey{}, "", fmt.Errorf("failed to generate private key: %w", err)
}

// Convert the private key to a byte slice
keypairBytes := privateKey
privateKeyBytes, err := base58.Decode(privateKey.String())
if err != nil {
return solana.PrivateKey{}, "", fmt.Errorf("failed to decode Base58 private key: %w", err)
}

// solana.NewWallet().
intArray := make([]int, len(privateKeyBytes))
for i, b := range privateKeyBytes {
intArray[i] = int(b)
}

// Serialize the keypair as JSON
jsonData, err := json.Marshal(keypairBytes)
// Marshal the integer array to JSON
keypairJSON, err := json.Marshal(intArray)
if err != nil {
return solana.PrivateKey{}, "", fmt.Errorf("failed to serialize keypair: %w", err)
return solana.PrivateKey{}, "", fmt.Errorf("failed to marshal keypair to JSON: %w", err)
}

// Create a temporary file
Expand All @@ -103,8 +110,8 @@ func generateAndStoreKeypair() (solana.PrivateKey, string, error) {
defer tempFile.Close()

// Write the keypair data to the file
if _, err := tempFile.Write(jsonData); err != nil {
return solana.PrivateKey{}, "", fmt.Errorf("failed to write keypair to temporary file: %w", err)
if err := os.WriteFile(tempFile.Name(), keypairJSON, 0600); err != nil {
return solana.PrivateKey{}, "", fmt.Errorf("failed to write keypair to file: %w", err)
}

// Return the path to the temporary file
Expand All @@ -119,10 +126,10 @@ func GenerateChainsSol(t *testing.T, numChains int) map[uint64]SolanaChain {
chains := make(map[uint64]SolanaChain)
for i := 0; i < numChains; i++ {
chainID := testSolanaChainSelectors[i]
url, _ := solTestUtil.SetupLocalSolNodeWithFlags(t)
url, wsurl := solTestUtil.SetupLocalSolNodeWithFlags(t)
admin, keypairPath, gerr := generateAndStoreKeypair()
// byteSlice, err := base58.Decode(admin)
t.Log("keypairPath", keypairPath)
t.Log("admin", admin.PublicKey())
t.Log("admin private key", admin)
key, err := solana.PrivateKeyFromSolanaKeygenFile(keypairPath)
require.NoError(t, err)
Expand All @@ -134,6 +141,7 @@ func GenerateChainsSol(t *testing.T, numChains int) map[uint64]SolanaChain {
Client: solRpc.New(url),
DeployerKey: &admin,
URL: url,
WSURL: wsurl,
KeypairPath: keypairPath,
}
}
Expand Down
1 change: 1 addition & 0 deletions deployment/environment/memory/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func generateMemoryChainSol(t *testing.T, inputs map[uint64]SolanaChain) map[uin
Client: chain.Client,
DeployerKey: chain.DeployerKey,
URL: chain.URL,
WSURL: chain.WSURL,
KeypairPath: chain.KeypairPath,
Confirm: func(instructions []solana.Instruction, opts ...solCommomUtil.TxModifier) error {
_, err := solCommomUtil.SendAndConfirm(
Expand Down
2 changes: 2 additions & 0 deletions deployment/solana_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type SolChain struct {
DeployerKey *solana.PrivateKey
Confirm func(instructions []solana.Instruction, opts ...solCommomUtil.TxModifier) error
URL string
WSURL string
KeypairPath string
}

Expand Down Expand Up @@ -65,6 +66,7 @@ func (c SolChain) DeployProgram(logger logger.Logger, programName string) (strin
}
logger.Infow("program key pair", "key", key)
cmd := exec.Command("solana", "program", "deploy", programFile, "--keypair", c.KeypairPath, "--program-id", programKeyPair, "--url", c.URL)
// cmd := exec.Command("solana", "program", "deploy", programFile, "--upgrade-authority", c.DeployerKey.PublicKey().String(), "--program-id", programKeyPair, "--url", c.URL)

// Capture the command output
var stdout, stderr bytes.Buffer
Expand Down

0 comments on commit 074dacf

Please sign in to comment.