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 token skeleton #15801

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
36 changes: 35 additions & 1 deletion deployment/common/changeset/deploy_link_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package changeset
import (
"fmt"

"github.com/gagliardetto/solana-go"
chainsel "github.com/smartcontractkit/chain-selectors"
"github.com/smartcontractkit/chainlink-common/pkg/logger"

"github.com/smartcontractkit/chainlink/deployment"
Expand All @@ -22,7 +24,16 @@ func DeployLinkToken(e deployment.Environment, chains []uint64) (deployment.Chan
}
newAddresses := deployment.NewMemoryAddressBook()
for _, chain := range chains {
_, err := deployLinkTokenContract(
family, err := chainsel.GetSelectorFamily(chain)
if err != nil {
return deployment.ChangesetOutput{AddressBook: newAddresses}, err
}
if family == chainsel.FamilySolana {
_, err = deployLinkTokenContractSolana(
e.Logger, e.SolChains[chain], newAddresses,
)
}
_, err = deployLinkTokenContract(
e.Logger, e.Chains[chain], newAddresses,
)
if err != nil {
Expand Down Expand Up @@ -57,3 +68,26 @@ func deployLinkTokenContract(
}
return linkToken, nil
}

func deployLinkTokenContractSolana(
lggr logger.Logger,
chain deployment.SolChain,
ab deployment.AddressBook,
) (*deployment.ContractDeploySolana, error) {
linkToken, err := deployment.DeploySolContract(lggr, chain, ab,
func(chain deployment.SolChain) deployment.ContractDeploySolana {
// linkTokenAddr, tx, linkToken, err2 := link_token.DeployLinkToken(
// chain.DeployerKey,
// chain.Client,
// )
// copy deployment code from solana internal integrations repo
return deployment.ContractDeploySolana{
Tv: deployment.NewTypeAndVersion(types.LinkToken, deployment.Version1_0_0),
}
})
if err != nil {
lggr.Errorw("Failed to deploy link token", "chain", chain.String(), "err", err)
return linkToken, err
}
return linkToken, nil
}
66 changes: 66 additions & 0 deletions deployment/solana_chain.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,71 @@
package deployment

import (
"fmt"

"github.com/gagliardetto/solana-go"
"github.com/smartcontractkit/chainlink-common/pkg/logger"
)

// SolChain represents a Solana chain.
type SolChain struct {
// Selectors used as canonical chain identifier.
Selector uint64
Client SolClient
Confirm func() (uint64, error)
}

func (c SolChain) String() string {
chainInfo, err := ChainInfo(c.Selector)
if err != nil {
// we should never get here, if the selector is invalid it should not be in the environment
panic(err)
}
return fmt.Sprintf("%s (%d)", chainInfo.ChainName, chainInfo.ChainSelector)
}

func (c SolChain) Name() string {
chainInfo, err := ChainInfo(c.Selector)
if err != nil {
// we should never get here, if the selector is invalid it should not be in the environment
panic(err)
}
if chainInfo.ChainName == "" {
return fmt.Sprintf("%d", c.Selector)
}
return chainInfo.ChainName
}

type SolClient interface {
}

type ContractDeploySolana struct {
ProgramID *solana.PublicKey // We leave this incase a Go binding doesn't have Address()
Tv TypeAndVersion
Err error
}

func DeploySolContract(
lggr logger.Logger,
chain SolChain,
addressBook AddressBook,
deploy func(chain SolChain) ContractDeploySolana,
) (*ContractDeploySolana, error) {
contractDeploy := deploy(chain)
if contractDeploy.Err != nil {
lggr.Errorw("Failed to deploy contract", "chain", chain.String(), "err", contractDeploy.Err)
return nil, contractDeploy.Err
}
_, err := chain.Confirm()
if err != nil {
lggr.Errorw("Failed to confirm deployment", "chain", chain.String(), "Contract", contractDeploy.Tv.String(), "err", err)
return nil, err
}
lggr.Infow("Deployed contract", "Contract", contractDeploy.Tv.String(), "addr", contractDeploy.ProgramID, "chain", chain.String())
err = addressBook.Save(chain.Selector, "fill in address", contractDeploy.Tv)
if err != nil {
lggr.Errorw("Failed to save contract address", "Contract", contractDeploy.Tv.String(), "addr", contractDeploy.ProgramID, "chain", chain.String(), "err", err)
return nil, err
}
return &contractDeploy, nil
}
Loading