Skip to content

Commit

Permalink
zrc20 withdraw sol works!
Browse files Browse the repository at this point in the history
  • Loading branch information
brewmaster012 committed Jul 5, 2024
1 parent b9b2598 commit e3d8ca1
Show file tree
Hide file tree
Showing 9 changed files with 415 additions and 14 deletions.
6 changes: 4 additions & 2 deletions cmd/solana/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/gagliardetto/solana-go"
"github.com/gagliardetto/solana-go/rpc"
"github.com/near/borsh-go"
"github.com/zeta-chain/zetacore/pkg/chains"
)

const (
Expand Down Expand Up @@ -163,7 +164,7 @@ func main() {
}
fmt.Println("recent blockhash:", recent.Value.Blockhash)

programId := solana.MustPublicKeyFromBase58("4Nt8tsYWQj3qC1TbunmmmDbzRXE4UQuzcGcqqgwy9bvX")
programId := solana.MustPublicKeyFromBase58("8J5Kxan9DTZTcHq6W5zj2UFuoARiwyLmUx87qPL1L7eP")

Check failure on line 167 in cmd/solana/main.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: var programId should be programID (revive)
seed := []byte("meta")
pdaComputed, bump, err := solana.FindProgramAddress([][]byte{seed}, programId)
if err != nil {
Expand Down Expand Up @@ -255,7 +256,7 @@ func main() {
Nonce uint64
}
// fetch PDA account
programId := solana.MustPublicKeyFromBase58("4Nt8tsYWQj3qC1TbunmmmDbzRXE4UQuzcGcqqgwy9bvX")
programId := solana.MustPublicKeyFromBase58("8J5Kxan9DTZTcHq6W5zj2UFuoARiwyLmUx87qPL1L7eP")

Check failure on line 259 in cmd/solana/main.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: var programId should be programID (revive)
seed := []byte("meta")
pdaComputed, bump, err := solana.FindProgramAddress([][]byte{seed}, programId)
if err != nil {
Expand Down Expand Up @@ -295,6 +296,7 @@ func main() {
to := privkey.PublicKey()
bytes := make([]byte, 8)
nonce := pda.Nonce
binary.BigEndian.PutUint64(bytes, uint64(chains.SolanaLocalnet.ChainId))
binary.BigEndian.PutUint64(bytes, nonce)
message = append(message, bytes...)
binary.BigEndian.PutUint64(bytes, amount)
Expand Down
14 changes: 14 additions & 0 deletions cmd/zetaclientd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
evmsigner "github.com/zeta-chain/zetacore/zetaclient/chains/evm/signer"
"github.com/zeta-chain/zetacore/zetaclient/chains/interfaces"
solanaobserver "github.com/zeta-chain/zetacore/zetaclient/chains/solana/observer"
solanasigner "github.com/zeta-chain/zetacore/zetaclient/chains/solana/signer"

"github.com/zeta-chain/zetacore/zetaclient/config"
"github.com/zeta-chain/zetacore/zetaclient/context"
"github.com/zeta-chain/zetacore/zetaclient/keys"
Expand Down Expand Up @@ -110,6 +112,18 @@ func CreateSignerMap(
}
}

// FIXME: config this
solChain := chains.SolanaLocalnet
{
signer, err := solanasigner.NewSigner(solChain, appContext, tss, ts, logger)
if err != nil {
logger.Std.Error().Err(err).Msgf("NewSolanaSigner error for chain %s", solChain.String())
} else {
logger.Std.Info().Msgf("NewSolanaSigner for chain %s", solChain.String())
signerMap[solChain.ChainId] = signer
}
}

return signerMap, nil
}

Expand Down
11 changes: 8 additions & 3 deletions e2e/e2etests/test_solana_deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func TestSolanaInitializeGateway(r *runner.E2ERunner, args []string) {
Nonce uint64
TssAddress [20]byte
Authority [32]byte
ChainID uint64
}
pdaInfo, err := client.GetAccountInfo(context.TODO(), pdaComputed)
if err != nil {
Expand All @@ -128,7 +129,7 @@ func TestSolanaInitializeGateway(r *runner.E2ERunner, args []string) {
var pda PdaInfo
borsh.Deserialize(&pda, pdaInfo.Bytes())

Check failure on line 130 in e2e/e2etests/test_solana_deposit.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `borsh.Deserialize` is not checked (errcheck)

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

}

Expand Down Expand Up @@ -248,6 +249,7 @@ func TestSolanaDeposit(r *runner.E2ERunner, args []string) {

func TestSolanaWithdraw(r *runner.E2ERunner, args []string) {
r.Logger.Print("TestSolanaWithdraw...sol zrc20 %s", r.SOLZRC20Addr.String())
privkey := solana.MustPrivateKeyFromBase58("4yqSQxDeTBvn86BuxcN5jmZb2gaobFXrBqu8kiE9rZxNkVMe3LfXmFigRsU4sRp7vk4vVP1ZCFiejDKiXBNWvs2C")

solZRC20 := r.SOLZRC20
supply, err := solZRC20.BalanceOf(&bind.CallOpts{}, r.ZEVMAuth.From)
Expand All @@ -265,10 +267,13 @@ func TestSolanaWithdraw(r *runner.E2ERunner, args []string) {
receipt := utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout)
utils.RequireTxSuccessful(r, receipt)

tx, err = r.SOLZRC20.Withdraw(r.ZEVMAuth, r.EVMAddress().Bytes(), amount)
tx, err = r.SOLZRC20.Withdraw(r.ZEVMAuth, []byte(privkey.PublicKey().String()), amount)
require.NoError(r, err)
r.Logger.EVMTransaction(*tx, "withdraw")
receipt = utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout)
utils.RequireTxSuccessful(r, receipt)
r.Logger.Info("Receipt txhash %s status %d", receipt.TxHash, receipt.Status)
r.Logger.Print("Receipt txhash %s status %d", receipt.TxHash, receipt.Status)

cctx := utils.WaitCctxMinedByInboundHash(r.Ctx, tx.Hash().Hex(), r.CctxClient, r.Logger, r.CctxTimeout)
r.Logger.CCTX(*cctx, "withdraw")
}
4 changes: 2 additions & 2 deletions e2e/txserver/zeta_tx_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,11 @@ func (zts ZetaTxServer) DeploySystemContractsAndZRC20(
IsSupported: true,
GatewayAddress: "94U5AHQMKkV5txNJ17QPXWoh474PheGou6cNP2FEuL1d",
BallotThreshold: sdktypes.MustNewDecFromStr("0.66"),
ConfirmationCount: 32,
ConfirmationCount: 16,
GasPriceTicker: 100,
InboundTicker: 5,
OutboundTicker: 5,
OutboundScheduleInterval: 10,
OutboundScheduleInterval: 2,
OutboundScheduleLookahead: 10,
MinObserverDelegation: sdktypes.MustNewDecFromStr("1"),
}
Expand Down
17 changes: 10 additions & 7 deletions zetaclient/chains/solana/observer/observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,23 @@ func NewObserver(
return &ob, nil
}

// IsOutboundProcessed returns included, confirmed, error
func (o *Observer) IsOutboundProcessed(cctx *types.CrossChainTx, logger zerolog.Logger) (bool, bool, error) {
//TODO implement me
panic("implement me")
//panic("implement me")
return false, false, nil
}

func (o *Observer) SetChainParams(params observertypes.ChainParams) {
//TODO implement me
panic("implement me")
o.Mu.Lock()
defer o.Mu.Unlock()
o.chainParams = params
}

func (o *Observer) GetChainParams() observertypes.ChainParams {
//TODO implement me
return observertypes.ChainParams{
IsSupported: true,
}
o.Mu.Lock()
defer o.Mu.Unlock()
return o.chainParams
}

func (o *Observer) GetTxID(nonce uint64) string {
Expand Down Expand Up @@ -279,6 +281,7 @@ func (o *Observer) WatchGasPrice() {
o.logger.Err(err).Msg("GetSlot error")
continue
}
// FIXME: what's the fee rate of compute unit? How to query?
txhash, err := o.zetacoreClient.PostGasPrice(o.chain, 1, "", slot)
if err != nil {
o.logger.Err(err).Msg("PostGasPrice error")
Expand Down
Loading

0 comments on commit e3d8ca1

Please sign in to comment.