Skip to content

Commit

Permalink
initialted inbound observation on SOL deposit
Browse files Browse the repository at this point in the history
  • Loading branch information
ws4charlie committed Jul 11, 2024
1 parent 0db1123 commit 8f1648a
Show file tree
Hide file tree
Showing 38 changed files with 1,671 additions and 368 deletions.
52 changes: 32 additions & 20 deletions cmd/solana/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
)

const (
PYTH_PROGRAM_DEVNET = "gSbePebfvPy7tRqimPoVecS2UsBvYv46ynrzWocc92s" // this program has many many txs
pythProgramDevnet = "gSbePebfvPy7tRqimPoVecS2UsBvYv46ynrzWocc92s" // this program has many many txs
)

//go:embed gateway.json
Expand All @@ -31,11 +31,15 @@ func main() {
limit := 10
out, err := client.GetSignaturesForAddressWithOpts(
context.TODO(),
solana.MustPublicKeyFromBase58(PYTH_PROGRAM_DEVNET),
solana.MustPublicKeyFromBase58(pythProgramDevnet),
&rpc.GetSignaturesForAddressOpts{
Limit: &limit,
Before: solana.MustSignatureFromBase58("5pLBywq74Nc6jYrWUqn9KjnYXHbQEY2UPkhWefZF5u4NYaUvEwz1Cirqaym9wDeHNAjiQwuLBfrdhXo8uFQA45jL"),
Until: solana.MustSignatureFromBase58("2coX9CckSmJWeHVqJNANeD7m4J7pctpSomxMon3h36droxCVB3JDbLyWQKMjnf85ntuFGxMLySykEMaRd5MDw35e"),
Limit: &limit,
Before: solana.MustSignatureFromBase58(
"5pLBywq74Nc6jYrWUqn9KjnYXHbQEY2UPkhWefZF5u4NYaUvEwz1Cirqaym9wDeHNAjiQwuLBfrdhXo8uFQA45jL",
),
Until: solana.MustSignatureFromBase58(
"2coX9CckSmJWeHVqJNANeD7m4J7pctpSomxMon3h36droxCVB3JDbLyWQKMjnf85ntuFGxMLySykEMaRd5MDw35e",
),
},
)

Expand Down Expand Up @@ -65,11 +69,11 @@ func main() {
// Parsing a Deposit Instruction
// devnet tx: deposit with memo
// https://solana.fm/tx/51746triQeve21zP1bcVEPvvsoXt94B57TU5exBvoy938bhGCfzBtsvKJbLpS1zRc2dmb3S3HBHnhTfbtKCBpmqg
const DEPOSIT_TX = "51746triQeve21zP1bcVEPvvsoXt94B57TU5exBvoy938bhGCfzBtsvKJbLpS1zRc2dmb3S3HBHnhTfbtKCBpmqg"
const depositTx = "51746triQeve21zP1bcVEPvvsoXt94B57TU5exBvoy938bhGCfzBtsvKJbLpS1zRc2dmb3S3HBHnhTfbtKCBpmqg"

tx, err := client.GetTransaction(
context.TODO(),
solana.MustSignatureFromBase58(DEPOSIT_TX),
solana.MustSignatureFromBase58(depositTx),
&rpc.GetTransactionOpts{})
if err != nil {
log.Fatalf("Error getting transaction: %v", err)
Expand Down Expand Up @@ -111,11 +115,13 @@ func main() {
{
// explore failed transaction
//https://explorer.solana.com/tx/2LbBdmCkuVyQhHAvsZhZ1HLdH12jQbHY7brwH6xUBsZKKPuV8fomyz1Qh9CaCZSqo8FNefaR8ir7ngo7H3H2VfWv
tx_sig := solana.MustSignatureFromBase58("2LbBdmCkuVyQhHAvsZhZ1HLdH12jQbHY7brwH6xUBsZKKPuV8fomyz1Qh9CaCZSqo8FNefaR8ir7ngo7H3H2VfWv")
txSig := solana.MustSignatureFromBase58(
"2LbBdmCkuVyQhHAvsZhZ1HLdH12jQbHY7brwH6xUBsZKKPuV8fomyz1Qh9CaCZSqo8FNefaR8ir7ngo7H3H2VfWv",
)
client2 := rpc.New("https://solana-mainnet.g.allthatnode.com/archive/json_rpc/842c667c947e42e2a9995ac2ec75026d")
tx, err := client2.GetTransaction(
context.TODO(),
tx_sig,
txSig,
&rpc.GetTransactionOpts{})
if err != nil {
log.Fatalf("Error getting transaction: %v", err)
Expand Down Expand Up @@ -163,9 +169,9 @@ func main() {
}
fmt.Println("recent blockhash:", recent.Value.Blockhash)

programId := solana.MustPublicKeyFromBase58("4Nt8tsYWQj3qC1TbunmmmDbzRXE4UQuzcGcqqgwy9bvX")
programID := solana.MustPublicKeyFromBase58("4Nt8tsYWQj3qC1TbunmmmDbzRXE4UQuzcGcqqgwy9bvX")
seed := []byte("meta")
pdaComputed, bump, err := solana.FindProgramAddress([][]byte{seed}, programId)
pdaComputed, bump, err := solana.FindProgramAddress([][]byte{seed}, programID)
if err != nil {
panic(err)
}
Expand All @@ -177,8 +183,8 @@ func main() {
accountSlice = append(accountSlice, solana.Meta(privkey.PublicKey()).WRITE().SIGNER())
accountSlice = append(accountSlice, solana.Meta(pdaComputed).WRITE())
accountSlice = append(accountSlice, solana.Meta(solana.SystemProgramID))
accountSlice = append(accountSlice, solana.Meta(programId))
inst.ProgID = programId
accountSlice = append(accountSlice, solana.Meta(programID))
inst.ProgID = programID
inst.AccountValues = accountSlice

type DepositInstructionParams struct {
Expand Down Expand Up @@ -255,9 +261,9 @@ func main() {
Nonce uint64
}
// fetch PDA account
programId := solana.MustPublicKeyFromBase58("4Nt8tsYWQj3qC1TbunmmmDbzRXE4UQuzcGcqqgwy9bvX")
programID := solana.MustPublicKeyFromBase58("4Nt8tsYWQj3qC1TbunmmmDbzRXE4UQuzcGcqqgwy9bvX")
seed := []byte("meta")
pdaComputed, bump, err := solana.FindProgramAddress([][]byte{seed}, programId)
pdaComputed, bump, err := solana.FindProgramAddress([][]byte{seed}, programID)
if err != nil {
panic(err)
}
Expand All @@ -272,8 +278,13 @@ func main() {
if err != nil {
panic(err)
}

// deserialize PDA account
var pda PdaInfo
borsh.Deserialize(&pda, pdaInfo.Bytes())
err = borsh.Deserialize(&pda, pdaInfo.Bytes())
if err != nil {
panic(err)
}

//spew.Dump(pda)
// building the transaction
Expand Down Expand Up @@ -316,13 +327,16 @@ func main() {
MessageHash: messageHash,
Nonce: nonce,
})
if err != nil {
panic(err)
}

var accountSlice []*solana.AccountMeta
accountSlice = append(accountSlice, solana.Meta(privkey.PublicKey()).WRITE().SIGNER())
accountSlice = append(accountSlice, solana.Meta(pdaComputed).WRITE())
accountSlice = append(accountSlice, solana.Meta(to).WRITE())
accountSlice = append(accountSlice, solana.Meta(programId))
inst.ProgID = programId
accountSlice = append(accountSlice, solana.Meta(programID))
inst.ProgID = programID
inst.AccountValues = accountSlice
tx, err := solana.NewTransaction(
[]solana.Instruction{&inst},
Expand Down Expand Up @@ -355,7 +369,5 @@ func main() {
panic(err)
}
spew.Dump(txsig)

}

}
41 changes: 31 additions & 10 deletions cmd/zetaclientd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/zeta-chain/zetacore/pkg/chains"
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
solrpc "github.com/gagliardetto/solana-go/rpc"

observertypes "github.com/zeta-chain/zetacore/x/observer/types"
"github.com/zeta-chain/zetacore/zetaclient/authz"
"github.com/zeta-chain/zetacore/zetaclient/chains/base"
btcobserver "github.com/zeta-chain/zetacore/zetaclient/chains/bitcoin/observer"
Expand Down Expand Up @@ -193,18 +193,39 @@ func CreateChainObserverMap(
}
}

// FIXME: config this
// FIXME_SOLANA: config chain params
solChain, solConfig, enabled := appContext.GetSolanaChainAndConfig()
solChainParams := observertypes.ChainParams{
GatewayAddress: "94U5AHQMKkV5txNJ17QPXWoh474PheGou6cNP2FEuL1d",
IsSupported: true,
ChainId: chains.SolanaLocalnet.ChainId,
ChainId: solChain.ChainId,
InboundTicker: 10,
}
co, err := solanaobserver.NewObserver(appContext, zetacoreClient, solChainParams, tss, dbpath, ts)
if err != nil {
logger.Std.Error().Err(err).Msg("NewObserver error for solana chain")
} else {
// TODO: config this
observerMap[solChainParams.ChainId] = co

// create Solana chain observer if enabled
if enabled {
rpcClient := solrpc.New(solConfig.Endpoint)
if rpcClient == nil {
// should never happen
return nil, fmt.Errorf("solana create Solana client error")
}

// create Solana chain observer
co, err := solanaobserver.NewObserver(
solChain,
rpcClient,
solChainParams,
appContext,
zetacoreClient,
tss,
logger,
ts,
)
if err != nil {
logger.Std.Error().Err(err).Msg("NewObserver error for solana chain")
} else {
observerMap[solChainParams.ChainId] = co
}
}

return observerMap, nil
Expand Down
20 changes: 16 additions & 4 deletions cmd/zetae2e/config/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,33 @@ func getClientsFromConfig(ctx context.Context, conf config.Config, account confi
}
btcRPCClient, err := getBtcClient(conf.RPCs.Bitcoin)
if err != nil {
return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, fmt.Errorf("failed to get btc client: %w", err)
return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, fmt.Errorf(
"failed to get btc client: %w",
err,
)
}
evmClient, evmAuth, err := getEVMClient(ctx, conf.RPCs.EVM, account)
if err != nil {
return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, fmt.Errorf("failed to get evm client: %w", err)
return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, fmt.Errorf(
"failed to get evm client: %w",
err,
)
}
cctxClient, fungibleClient, authClient, bankClient, observerClient, lightclientClient, err := getZetaClients(
conf.RPCs.ZetaCoreGRPC,
)
if err != nil {
return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, fmt.Errorf("failed to get zeta clients: %w", err)
return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, fmt.Errorf(
"failed to get zeta clients: %w",
err,
)
}
zevmClient, zevmAuth, err := getEVMClient(ctx, conf.RPCs.Zevm, account)
if err != nil {
return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, fmt.Errorf("failed to get zevm client: %w", err)
return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, fmt.Errorf(
"failed to get zevm client: %w",
err,
)
}
return btcRPCClient,
solanaClient,
Expand Down
3 changes: 2 additions & 1 deletion cmd/zetae2e/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ func NewInitCmd() *cobra.Command {
InitCmd.Flags().
StringVar(&initConf.RPCs.Zevm, "zevmURL", "http://zetacore0:8545", "--zevmURL http://zetacore0:8545")
InitCmd.Flags().StringVar(&initConf.RPCs.Bitcoin.Host, "btcURL", "bitcoin:18443", "--grpcURL bitcoin:18443")
InitCmd.Flags().StringVar(&initConf.RPCs.SolanaRPC, "solanaURL", "http://solana:8899", "--solanaURL http://solana:8899")
InitCmd.Flags().
StringVar(&initConf.RPCs.SolanaRPC, "solanaURL", "http://solana:8899", "--solanaURL http://solana:8899")

InitCmd.Flags().StringVar(&initConf.ZetaChainID, "chainID", "athens_101-1", "--chainID athens_101-1")
InitCmd.Flags().StringVar(&configFile, local.FlagConfigFile, "e2e.config", "--cfg ./e2e.config")
Expand Down
2 changes: 1 addition & 1 deletion cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
eg.Go(zetaTestRoutine(conf, deployerRunner, verbose, zetaTests...))
eg.Go(zevmMPTestRoutine(conf, deployerRunner, verbose, zevmMPTests...))
eg.Go(bitcoinTestRoutine(conf, deployerRunner, verbose, !skipBitcoinSetup, testHeader, bitcoinTests...))
eg.Go(solanaTestRoutine(conf, deployerRunner, verbose, !skipBitcoinSetup, testHeader, solanaTests...))
eg.Go(solanaTestRoutine(conf, deployerRunner, verbose, testHeader, solanaTests...))
eg.Go(ethereumTestRoutine(conf, deployerRunner, verbose, testHeader, ethereumTests...))
}
if testAdmin {
Expand Down
3 changes: 1 addition & 2 deletions cmd/zetae2e/local/solana.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ func solanaTestRoutine(
conf config.Config,
deployerRunner *runner.E2ERunner,
verbose bool,
initBitcoinNetwork bool,
testHeader bool,
_ bool,
testNames ...string,
) func() error {
return func() (err error) {
Expand Down
43 changes: 26 additions & 17 deletions e2e/e2etests/test_solana_deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/gagliardetto/solana-go"
"github.com/gagliardetto/solana-go/rpc"
"github.com/near/borsh-go"

"github.com/zeta-chain/zetacore/e2e/runner"
"github.com/zeta-chain/zetacore/pkg/chains"
)
Expand Down Expand Up @@ -39,15 +40,17 @@ func TestSolanaInitializeGateway(r *runner.E2ERunner, args []string) {
}
r.Logger.Print("recent blockhash: %s", recent.Value.Blockhash)

programId := solana.MustPublicKeyFromBase58("94U5AHQMKkV5txNJ17QPXWoh474PheGou6cNP2FEuL1d")
programID := solana.MustPublicKeyFromBase58("94U5AHQMKkV5txNJ17QPXWoh474PheGou6cNP2FEuL1d")
seed := []byte("meta")
pdaComputed, bump, err := solana.FindProgramAddress([][]byte{seed}, programId)
pdaComputed, bump, err := solana.FindProgramAddress([][]byte{seed}, programID)
if err != nil {
panic(err)
}
r.Logger.Print("computed pda: %s, bump %d\n", pdaComputed, bump)

privkey := solana.MustPrivateKeyFromBase58("4yqSQxDeTBvn86BuxcN5jmZb2gaobFXrBqu8kiE9rZxNkVMe3LfXmFigRsU4sRp7vk4vVP1ZCFiejDKiXBNWvs2C")
privkey := solana.MustPrivateKeyFromBase58(
"4yqSQxDeTBvn86BuxcN5jmZb2gaobFXrBqu8kiE9rZxNkVMe3LfXmFigRsU4sRp7vk4vVP1ZCFiejDKiXBNWvs2C",
)
r.Logger.Print("user pubkey: %s", privkey.PublicKey().String())
bal, err := client.GetBalance(context.TODO(), privkey.PublicKey(), rpc.CommitmentFinalized)
if err != nil {
Expand All @@ -60,21 +63,21 @@ func TestSolanaInitializeGateway(r *runner.E2ERunner, args []string) {
accountSlice = append(accountSlice, solana.Meta(privkey.PublicKey()).WRITE().SIGNER())
accountSlice = append(accountSlice, solana.Meta(pdaComputed).WRITE())
accountSlice = append(accountSlice, solana.Meta(solana.SystemProgramID))
accountSlice = append(accountSlice, solana.Meta(programId))
inst.ProgID = programId
accountSlice = append(accountSlice, solana.Meta(programID))
inst.ProgID = programID
inst.AccountValues = accountSlice

type InitializeParams struct {
Discriminator [8]byte
TssAddress [20]byte
ChainId uint64
ChainID uint64
}
r.Logger.Print("TSS EthAddress: %s", r.TSSAddress)

inst.DataBytes, err = borsh.Serialize(InitializeParams{
Discriminator: [8]byte{175, 175, 109, 31, 13, 152, 155, 237},
TssAddress: r.TSSAddress,
ChainId: uint64(chains.SolanaLocalnet.ChainId),
ChainID: uint64(chains.SolanaLocalnet.ChainId),
})
if err != nil {
panic(err)
Expand Down Expand Up @@ -120,17 +123,24 @@ func TestSolanaInitializeGateway(r *runner.E2ERunner, args []string) {
r.Logger.Print("error getting PDA info: %v", err)
panic(err)
}

// deserialize the PDA info
var pda PdaInfo
borsh.Deserialize(&pda, pdaInfo.Bytes())
err = borsh.Deserialize(&pda, pdaInfo.Bytes())
if err != nil {
r.Logger.Print("error deserializing PDA info: %v", err)
panic(err)
}

r.Logger.Print("PDA info Tss: %v", pda.TssAddress)

}

func TestSolanaDeposit(r *runner.E2ERunner, args []string) {
func TestSolanaDeposit(r *runner.E2ERunner, _ []string) {
client := r.SolanaClient

privkey := solana.MustPrivateKeyFromBase58("4yqSQxDeTBvn86BuxcN5jmZb2gaobFXrBqu8kiE9rZxNkVMe3LfXmFigRsU4sRp7vk4vVP1ZCFiejDKiXBNWvs2C")
privkey := solana.MustPrivateKeyFromBase58(
"4yqSQxDeTBvn86BuxcN5jmZb2gaobFXrBqu8kiE9rZxNkVMe3LfXmFigRsU4sRp7vk4vVP1ZCFiejDKiXBNWvs2C",
)

// build & bcast a Depsosit tx
bal, err := client.GetBalance(context.TODO(), privkey.PublicKey(), rpc.CommitmentFinalized)
Expand All @@ -146,11 +156,11 @@ func TestSolanaDeposit(r *runner.E2ERunner, args []string) {
r.Logger.Error("Error getting recent blockhash: %v", err)
panic(err)
}
r.Logger.Print("recent blockhash:", recent.Value.Blockhash)
r.Logger.Print("recent blockhash: %s", recent.Value.Blockhash)

programId := solana.MustPublicKeyFromBase58("94U5AHQMKkV5txNJ17QPXWoh474PheGou6cNP2FEuL1d")
programID := solana.MustPublicKeyFromBase58("94U5AHQMKkV5txNJ17QPXWoh474PheGou6cNP2FEuL1d")
seed := []byte("meta")
pdaComputed, bump, err := solana.FindProgramAddress([][]byte{seed}, programId)
pdaComputed, bump, err := solana.FindProgramAddress([][]byte{seed}, programID)
if err != nil {
r.Logger.Error("Error finding program address: %v", err)
panic(err)
Expand All @@ -163,8 +173,8 @@ func TestSolanaDeposit(r *runner.E2ERunner, args []string) {
accountSlice = append(accountSlice, solana.Meta(privkey.PublicKey()).WRITE().SIGNER())
accountSlice = append(accountSlice, solana.Meta(pdaComputed).WRITE())
accountSlice = append(accountSlice, solana.Meta(solana.SystemProgramID))
accountSlice = append(accountSlice, solana.Meta(programId))
inst.ProgID = programId
accountSlice = append(accountSlice, solana.Meta(programID))
inst.ProgID = programID
inst.AccountValues = accountSlice

type DepositInstructionParams struct {
Expand Down Expand Up @@ -238,5 +248,4 @@ func TestSolanaDeposit(r *runner.E2ERunner, args []string) {
// cctx.CctxStatus.StatusMessage),
// )
//}

}
6 changes: 3 additions & 3 deletions e2e/runner/setup_zeta.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ func (r *E2ERunner) SetTSSAddresses() error {
}

// SetSolanaContracts set Solana contracts
func (runner *E2ERunner) SetSolanaContracts() {
runner.Logger.Print("⚙️ setting up Solana contracts")
func (r *E2ERunner) SetSolanaContracts() {
r.Logger.Print("⚙️ setting up Solana contracts")

// set Solana contracts
// TODO: remove this hardcoded stuff for localnet
runner.GatewayProgram = solana.MustPublicKeyFromBase58("94U5AHQMKkV5txNJ17QPXWoh474PheGou6cNP2FEuL1d")
r.GatewayProgram = solana.MustPublicKeyFromBase58("94U5AHQMKkV5txNJ17QPXWoh474PheGou6cNP2FEuL1d")
}

// SetZEVMContracts set contracts for the ZEVM
Expand Down
Loading

0 comments on commit 8f1648a

Please sign in to comment.