Skip to content
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 link deploy (B) #15845

Merged
merged 32 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
aaab52e
Adding solchains in NewEnv
yashnevatia Jan 3, 2025
f19598e
Revert "Adding solchains in NewEnv"
yashnevatia Jan 3, 2025
e4f1f05
adding sol chains to newenv
yashnevatia Jan 3, 2025
18d77d1
newEnv needs to send nil
yashnevatia Jan 3, 2025
8150d8d
adding test env setup
yashnevatia Jan 6, 2025
7a2afca
adding link token deployment and test
yashnevatia Jan 6, 2025
7da3b14
adding nil for crib sol chains
yashnevatia Jan 6, 2025
3b1e77a
Merge branch 'solana-updates' of github.com:smartcontractkit/chainlin…
yashnevatia Jan 6, 2025
1c41814
using switch case
yashnevatia Jan 7, 2025
01f39eb
Adding decimal const
yashnevatia Jan 7, 2025
3a4ae18
adding chain selectors commit
yashnevatia Jan 7, 2025
b76324d
go mod tidy
yashnevatia Jan 7, 2025
b8a9542
Merge branch 'solana-updates' of github.com:smartcontractkit/chainlin…
yashnevatia Jan 7, 2025
9d87560
linting
yashnevatia Jan 7, 2025
31cde63
merging
yashnevatia Jan 7, 2025
2f98015
chain sel update
yashnevatia Jan 7, 2025
cd73657
update core/scripts go files
yashnevatia Jan 7, 2025
a4ec585
again
yashnevatia Jan 7, 2025
0a2336b
Merge remote-tracking branch 'origin/develop' into solana-updates
tt-cll Jan 7, 2025
c0f35b9
add changeset
tt-cll Jan 7, 2025
720dccb
go imports
yashnevatia Jan 8, 2025
859dd64
Merge branch 'solana-updates' of github.com:smartcontractkit/chainlin…
yashnevatia Jan 8, 2025
c08d092
go mod
yashnevatia Jan 8, 2025
d0882cd
go mod
yashnevatia Jan 8, 2025
1e55e6f
go mod tidy
yashnevatia Jan 8, 2025
8b0f261
lint
yashnevatia Jan 8, 2025
87c289a
Merge branch 'develop' of github.com:smartcontractkit/chainlink into …
yashnevatia Jan 8, 2025
650a18a
merging
yashnevatia Jan 8, 2025
e846d6f
Merge branch 'develop' into solana-link-deploy
yashnevatia Jan 9, 2025
58480cf
merging
yashnevatia Jan 9, 2025
f4c69fd
Merge branch 'solana-link-deploy' of github.com:smartcontractkit/chai…
yashnevatia Jan 9, 2025
b4a7781
linting
yashnevatia Jan 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 58 additions & 8 deletions deployment/common/changeset/deploy_link_token.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package changeset

import (
"context"
"fmt"

"github.com/smartcontractkit/chainlink-common/pkg/logger"

"github.com/gagliardetto/solana-go"
solRpc "github.com/gagliardetto/solana-go/rpc"
solCommomUtil "github.com/smartcontractkit/chainlink-ccip/chains/solana/utils/common"
solTokenUtil "github.com/smartcontractkit/chainlink-ccip/chains/solana/utils/tokens"
"github.com/smartcontractkit/chainlink/deployment"
"github.com/smartcontractkit/chainlink/deployment/common/types"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/shared/generated/link_token"
Expand All @@ -15,18 +20,30 @@ var _ deployment.ChangeSet[[]uint64] = DeployLinkToken
// DeployLinkToken deploys a link token contract to the chain identified by the ChainSelector.
func DeployLinkToken(e deployment.Environment, chains []uint64) (deployment.ChangesetOutput, error) {
for _, chain := range chains {
_, ok := e.Chains[chain]
if !ok {
return deployment.ChangesetOutput{}, fmt.Errorf("chain not found in environment")
_, evmOk := e.Chains[chain]
_, solOk := e.SolChains[chain]
if !evmOk && !solOk {
return deployment.ChangesetOutput{}, fmt.Errorf("chain %d not found in environment", chain)
}
}
newAddresses := deployment.NewMemoryAddressBook()
for _, chain := range chains {
_, err := deployLinkTokenContract(
e.Logger, e.Chains[chain], newAddresses,
)
if err != nil {
return deployment.ChangesetOutput{AddressBook: newAddresses}, err
if _, ok := e.Chains[chain]; ok {
yashnevatia marked this conversation as resolved.
Show resolved Hide resolved
// Deploy EVM LINK token
_, err := deployLinkTokenContract(
e.Logger, e.Chains[chain], newAddresses,
)
if err != nil {
return deployment.ChangesetOutput{AddressBook: newAddresses}, err
}
} else if _, ok := e.SolChains[chain]; ok {
// Deploy Solana LINK token
err := deployLinkTokenContractSolana(
e.Logger, e.SolChains[chain], newAddresses,
)
if err != nil {
return deployment.ChangesetOutput{AddressBook: newAddresses}, err
}
yashnevatia marked this conversation as resolved.
Show resolved Hide resolved
}
}
return deployment.ChangesetOutput{AddressBook: newAddresses}, nil
Expand Down Expand Up @@ -57,3 +74,36 @@ func deployLinkTokenContract(
}
return linkToken, nil
}

func deployLinkTokenContractSolana(
lggr logger.Logger,
chain deployment.SolChain,
ab deployment.AddressBook,
) error {
decimals := uint8(0)
adminPublicKey := chain.DeployerKey.PublicKey()
mint, _ := solana.NewRandomPrivateKey()
// this is the token address
mintPublicKey := mint.PublicKey()
instructions, err := solTokenUtil.CreateToken(
context.Background(), solana.Token2022ProgramID, mintPublicKey, adminPublicKey, decimals, chain.Client, solRpc.CommitmentConfirmed,
)
if err != nil {
lggr.Errorw("Failed to generate instructions for link token deployment", "chain", chain.String(), "err", err)
return err
}
err = chain.Confirm(instructions, solCommomUtil.AddSigners(mint))
if err != nil {
lggr.Errorw("Failed to confirm instructions for link token deployment", "chain", chain.String(), "err", err)
return err
}
tv := deployment.NewTypeAndVersion(types.LinkToken, deployment.Version1_0_0)
lggr.Infow("Deployed contract", "Contract", tv.String(), "addr", mintPublicKey.String(), "chain", chain.String())
err = ab.Save(chain.Selector, mintPublicKey.String(), tv)
if err != nil {
lggr.Errorw("Failed to save link token", "chain", chain.String(), "err", err)
return err
}

return nil
}
12 changes: 10 additions & 2 deletions deployment/common/changeset/deploy_link_token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ func TestDeployLinkToken(t *testing.T) {
t.Parallel()
lggr := logger.TestLogger(t)
e := memory.NewMemoryEnvironment(t, lggr, zapcore.InfoLevel, memory.MemoryEnvironmentConfig{
Chains: 1,
Chains: 1,
SolChains: 1,
})
chain1 := e.AllChainSelectors()[0]
solChain1 := e.AllChainSelectorsSolana()[0]
e, err := changeset.ApplyChangesets(t, e, nil, []changeset.ChangesetApplication{
{
Changeset: changeset.WrapChangeSet(changeset.DeployLinkToken),
Config: []uint64{chain1},
Config: []uint64{chain1, solChain1},
},
})
require.NoError(t, err)
Expand All @@ -32,4 +34,10 @@ func TestDeployLinkToken(t *testing.T) {
// View itself already unit tested
_, err = state.GenerateLinkView()
require.NoError(t, err)

// solana test
addrs, err = e.ExistingAddresses.AddressesForChain(solChain1)
require.NoError(t, err)
require.NotEmpty(t, addrs)

}
1 change: 1 addition & 0 deletions deployment/common/changeset/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func ApplyChangesets(t *testing.T, e deployment.Environment, timelockContractsPe
Logger: e.Logger,
ExistingAddresses: addresses,
Chains: e.Chains,
SolChains: e.SolChains,
NodeIDs: e.NodeIDs,
Offchain: e.Offchain,
OCRSecrets: e.OCRSecrets,
Expand Down
13 changes: 13 additions & 0 deletions deployment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
logger logger.Logger,
existingAddrs AddressBook,
chains map[uint64]Chain,
solChains map[uint64]SolChain,
nodeIDs []string,
offchain OffchainClient,
ctx func() context.Context,
Expand All @@ -120,6 +121,7 @@
Logger: logger,
ExistingAddresses: existingAddrs,
Chains: chains,
SolChains: solChains,
NodeIDs: nodeIDs,
Offchain: offchain,
GetContext: ctx,
Expand Down Expand Up @@ -158,6 +160,17 @@
return selectors
}

func (e Environment) AllChainSelectorsSolana() []uint64 {
var selectors []uint64

Check failure on line 164 in deployment/environment.go

View workflow job for this annotation

GitHub Actions / GolangCI Lint (deployment)

Consider pre-allocating `selectors` (prealloc)
for sel := range e.SolChains {
selectors = append(selectors, sel)
}
sort.Slice(selectors, func(i, j int) bool {
return selectors[i] < selectors[j]
})
return selectors
}

func (e Environment) AllDeployerKeys() []common.Address {
var deployerKeys []common.Address
for sel := range e.Chains {
Expand Down
2 changes: 2 additions & 0 deletions deployment/environment/crib/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package crib

import (
"context"

"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink/deployment"
"github.com/smartcontractkit/chainlink/deployment/environment/devenv"
Expand Down Expand Up @@ -32,6 +33,7 @@ func NewDeployEnvironmentFromCribOutput(lggr logger.Logger, output DeployOutput)
lggr,
output.AddressBook,
chains,
nil, // nil for solana chains, can use memory solana chain example when required
output.NodeIDs,
nil, // todo: populate the offchain client using output.DON
func() context.Context { return context.Background() }, deployment.XXXGenerateTestOCRSecrets(),
Expand Down
1 change: 1 addition & 0 deletions deployment/environment/devenv/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func NewEnvironment(ctx func() context.Context, lggr logger.Logger, config Envir
lggr,
deployment.NewMemoryAddressBook(),
chains,
nil, // sending nil for solana chains right now, we can build this when we need it
nodeIDs,
offChain,
ctx,
Expand Down
38 changes: 38 additions & 0 deletions deployment/environment/memory/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import (

"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"

"github.com/gagliardetto/solana-go"
solRpc "github.com/gagliardetto/solana-go/rpc"
solTestUtil "github.com/smartcontractkit/chainlink-ccip/chains/solana/contracts/tests/testutils"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
)

Expand All @@ -24,6 +27,11 @@ type EVMChain struct {
Users []*bind.TransactOpts
}

type SolanaChain struct {
Client *solRpc.Client
DeployerKey *solana.PrivateKey
}

func fundAddress(t *testing.T, from *bind.TransactOpts, to common.Address, amount *big.Int, backend *simulated.Backend) {
ctx := tests.Context(t)
nonce, err := backend.Client().PendingNonceAt(ctx, from.From)
Expand Down Expand Up @@ -53,6 +61,36 @@ func GenerateChains(t *testing.T, numChains int, numUsers int) map[uint64]EVMCha
return chains
}

func getTestSolanaChainSelectors() []uint64 {
result := []uint64{}
for _, x := range chainsel.SolanaALL {
if x.Name == x.ChainID {
result = append(result, x.Selector)
}
}
return result
}

func GenerateChainsSol(t *testing.T, numChains int) map[uint64]SolanaChain {
testSolanaChainSelectors := getTestSolanaChainSelectors()
if len(testSolanaChainSelectors) < numChains {
t.Fatalf("not enough test solana chain selectors available")
}
chains := make(map[uint64]SolanaChain)
for i := 0; i < numChains; i++ {
chainID := testSolanaChainSelectors[i]
url, _ := solTestUtil.SetupLocalSolNodeWithFlags(t)
admin, gerr := solana.NewRandomPrivateKey()
solTestUtil.FundTestAccounts(t, []solana.PublicKey{admin.PublicKey()}, url)
require.NoError(t, gerr)
chains[chainID] = SolanaChain{
Client: solRpc.New(url),
DeployerKey: &admin,
}
}
return chains
}

func GenerateChainsWithIds(t *testing.T, chainIDs []uint64, numUsers int) map[uint64]EVMChain {
chains := make(map[uint64]EVMChain)
for _, chainID := range chainIDs {
Expand Down
34 changes: 34 additions & 0 deletions deployment/environment/memory/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/core/types"
"github.com/gagliardetto/solana-go"
"github.com/hashicorp/consul/sdk/freeport"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zapcore"
Expand All @@ -19,6 +20,8 @@ import (

"github.com/smartcontractkit/chainlink/deployment"

solRpc "github.com/gagliardetto/solana-go/rpc"
solCommomUtil "github.com/smartcontractkit/chainlink-ccip/chains/solana/utils/common"
"github.com/smartcontractkit/chainlink-common/pkg/logger"
)

Expand All @@ -28,6 +31,7 @@ const (

type MemoryEnvironmentConfig struct {
Chains int
SolChains int
NumOfUsersPerChain int
Nodes int
Bootstraps int
Expand Down Expand Up @@ -59,6 +63,11 @@ func NewMemoryChains(t *testing.T, numChains int, numUsers int) (map[uint64]depl
return generateMemoryChain(t, mchains), users
}

func NewMemoryChainsSol(t *testing.T, numChains int) map[uint64]deployment.SolChain {
mchains := GenerateChainsSol(t, numChains)
return generateMemoryChainSol(t, mchains)
}

func NewMemoryChainsWithChainIDs(t *testing.T, chainIDs []uint64, numUsers int) (map[uint64]deployment.Chain, map[uint64][]*bind.TransactOpts) {
mchains := GenerateChainsWithIds(t, chainIDs, numUsers)
users := make(map[uint64][]*bind.TransactOpts)
Expand Down Expand Up @@ -111,6 +120,28 @@ func generateMemoryChain(t *testing.T, inputs map[uint64]EVMChain) map[uint64]de
return chains
}

func generateMemoryChainSol(t *testing.T, inputs map[uint64]SolanaChain) map[uint64]deployment.SolChain {
chains := make(map[uint64]deployment.SolChain)
for cid, chain := range inputs {
chain := chain
chains[cid] = deployment.SolChain{
Selector: cid,
Client: chain.Client,
DeployerKey: chain.DeployerKey,
Confirm: func(instructions []solana.Instruction, opts ...solCommomUtil.TxModifier) error {
_, err := solCommomUtil.SendAndConfirm(
context.Background(), chain.Client, instructions, *chain.DeployerKey, solRpc.CommitmentConfirmed, opts...,
)
if err != nil {
return err
}
return nil
},
}
}
return chains
}

func NewNodes(t *testing.T, logLevel zapcore.Level, chains map[uint64]deployment.Chain, numNodes, numBootstraps int, registryConfig deployment.CapabilityRegistryConfig) map[string]Node {
nodesByPeerID := make(map[string]Node)
if numNodes+numBootstraps == 0 {
Expand Down Expand Up @@ -149,6 +180,7 @@ func NewMemoryEnvironmentFromChainsNodes(
lggr,
deployment.NewMemoryAddressBook(),
chains,
nil,
nodeIDs, // Note these have the p2p_ prefix.
NewMemoryJobClient(nodes),
ctx,
Expand All @@ -159,6 +191,7 @@ func NewMemoryEnvironmentFromChainsNodes(
// To be used by tests and any kind of deployment logic.
func NewMemoryEnvironment(t *testing.T, lggr logger.Logger, logLevel zapcore.Level, config MemoryEnvironmentConfig) deployment.Environment {
chains, _ := NewMemoryChains(t, config.Chains, config.NumOfUsersPerChain)
solChains := NewMemoryChainsSol(t, config.SolChains)
nodes := NewNodes(t, logLevel, chains, config.Nodes, config.Bootstraps, config.RegistryConfig)
var nodeIDs []string
for id := range nodes {
Expand All @@ -169,6 +202,7 @@ func NewMemoryEnvironment(t *testing.T, lggr logger.Logger, logLevel zapcore.Lev
lggr,
deployment.NewMemoryAddressBook(),
chains,
solChains,
nodeIDs,
NewMemoryJobClient(nodes),
func() context.Context { return tests.Context(t) },
Expand Down
Loading
Loading