First draft of Serum structs.

This commit is contained in:
Alexandre Bourget 2020-11-05 17:54:08 -05:00
parent 435368f98f
commit 2949cab0aa
6 changed files with 144 additions and 6 deletions

View File

@ -1 +1,23 @@
# Solana library for Go
Go library to interface with Solana nodes's JSON-RPC interface, Solana's SPL tokens and the
[https://dex.projectserum.com](Serum DEX) instructions. More contracts to come.
# Usage
```go
solana.NewClient("https://mainnet.solana.dfuse.io")
```
# Examples
# Contributing
Any contributions are welcome, use your standard GitHub-fu to pitch in and improve.
License
-------
Apache-2

View File

@ -70,11 +70,11 @@ func (c *Client) GetConfirmedBlock(ctx context.Context, slot uint64, encoding st
return
}
func (c *Client) GetAccountInfo(ctx context.Context, publicKey string, commitment CommitmentType) (out *GetAccountInfoResult, err error) {
params := []interface{}{publicKey}
if commitment != "" {
params = append(params, string(commitment))
func (c *Client) GetAccountInfo(ctx context.Context, publicKey string) (out *GetAccountInfoResult, err error) {
obj := map[string]interface{}{
"encoding": "base64",
}
params := []interface{}{publicKey, obj}
err = c.rpcClient.CallFor(&out, "getAccountInfo", params...)
return

View File

@ -78,7 +78,7 @@ type GetAccountInfoResult struct {
type Account struct {
Lamports U64 `json:"lamports"`
Data Base58 `json:"data"`
Data []byte `json:"data"`
Owner PublicKey `json:"owner"`
Executable bool `json:"executable"`
RentEpoch U64 `json:"rentEpoch"`

92
serum/types.go Normal file
View File

@ -0,0 +1,92 @@
package serum
import "github.com/dfuse-io/solana-go"
type MarketV2 struct {
/*
blob(5),
accountFlagsLayout('accountFlags'),
publicKeyLayout('ownAddress'),
u64('vaultSignerNonce'),
publicKeyLayout('baseMint'),
publicKeyLayout('quoteMint'),
publicKeyLayout('baseVault'),
u64('baseDepositsTotal'),
u64('baseFeesAccrued'),
publicKeyLayout('quoteVault'),
u64('quoteDepositsTotal'),
u64('quoteFeesAccrued'),
u64('quoteDustThreshold'),
publicKeyLayout('requestQueue'),
publicKeyLayout('eventQueue'),
publicKeyLayout('bids'),
publicKeyLayout('asks'),
u64('baseLotSize'),
u64('quoteLotSize'),
u64('feeRateBps'),
u64('referrerRebatesAccrued'),
blob(7),
*/
SerumPadding [5]byte `json:"-",struc:"[5]pad"`
AccountFlags solana.U64 `struc:"uint64,little"`
OwnAddress solana.PublicKey `struc:"[32]byte"`
VaultSignerNonce solana.U64 `struc:"uint64,little"`
BaseMint solana.PublicKey `struc:"[32]byte"`
QuoteMint solana.PublicKey `struc:"[32]byte"`
BaseVault solana.PublicKey `struc:"[32]byte"`
BaseDepositsTotal solana.U64 `struc:"uint64,little"`
BaseFeesAccrued solana.U64 `struc:"uint64,little"`
QuoteVault solana.PublicKey `struc:"[32]byte"`
QuoteDepositsTotal solana.U64 `struc:"uint64,little"`
QuoteFeesAccrued solana.U64 `struc:"uint64,little"`
QuoteDustThreshold solana.U64 `struc:"uint64,little"`
RequestQueue solana.PublicKey `struc:"[32]byte"`
EventQueue solana.PublicKey `struc:"[32]byte"`
Bids solana.PublicKey `struc:"[32]byte"`
Asks solana.PublicKey `struc:"[32]byte"`
BaseLotSize solana.U64 `struc:"uint64,little"`
QuoteLotSize solana.U64 `struc:"uint64,little"`
FeeRateBPS solana.U64 `struc:"uint64,little"`
ReferrerRebatesAccrued solana.U64 `struc:"uint64,little"`
EndPadding [7]byte `json:"-",struc:"[5]pad"`
}
type Orderbook struct {
BumpIndex uint32 `struc:"uint32,sizeof=Nodes"`
Padding [4]byte
FreeListLen uint32
Padding [4]byte
FreeListHead uint32
Root uint32
LeafCount uint32
Nodes []SlabNode
}
type SlabNode struct {
}

24
serum/types_test.go Normal file
View File

@ -0,0 +1,24 @@
package serum
import (
"bytes"
"encoding/base64"
"encoding/json"
"fmt"
"testing"
"github.com/lunixbochs/struc"
"github.com/stretchr/testify/require"
)
func TestMarketDecode(t *testing.T) {
s := `c2VydW0DAAAAAAAAAGdTY0MQ+JzjRQitPPQw7a6jFaO3QEtNbJqFwHlHoaDdAAAAAAAAAAAGm4hX/quBhPtof2NGGMA12sQ53BrrO1WYoPAAAAAAAZqhgojuhD2D9j0JH/1UU78OyY17yIzxSctOkEdQqtVn3J9Uzkd6sWTIS0jwubpXWBCWAdTAPAO1WBTXCUKhAiUA8Vb/JRoAAAAAAAAAAAAAe3KroxoWcpqkx0i8u5vTEf6p3L/ywwDq7Ktzy9emFhswTe1qDgAAAMiPz0sAAAAAZAAAAAAAAADe8TmrC1DwGtEuKniQQk1igbzy3FWrl5XOfqClpgrXPn8QBfRYuHutaT3LATJRSLiB32YOH7aWMK3FLYuxLSTFXlqAgmTHudbh5oQuYmowZgURANtyvD/GmOSv6N1nBjDpvaPvZD875suiOGn2gX+hOv6zwukfAaxjJxOl1QIRVQDh9QUAAAAAZAAAAAAAAAAAAAAAAAAAAPdrAgAAAAAAcGFkZGluZw==`
cnt, err := base64.StdEncoding.DecodeString(s)
require.NoError(t, err)
var m MarketV2
require.NoError(t, struc.Unpack(bytes.NewReader(cnt), &m))
cnt, _ = json.MarshalIndent(m, "", " ")
fmt.Println("MAMA", string(cnt))
}

View File

@ -17,7 +17,7 @@ var getAccountCmd = &cobra.Command{
client := getClient()
ctx := context.Background()
resp, err := client.GetAccountInfo(ctx, args[0], "")
resp, err := client.GetAccountInfo(ctx, args[0])
if err != nil {
return err
}