diff --git a/go.mod b/go.mod index 6a7444d9..81253ef4 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/gagliardetto/solana-go go 1.16 require ( - github.com/gagliardetto/binary v0.5.2 + github.com/gagliardetto/binary v0.6.0 github.com/gagliardetto/gofuzz v1.2.2 github.com/gagliardetto/treeout v0.1.4 ) @@ -35,7 +35,6 @@ require ( github.com/spf13/viper v1.7.1 github.com/stretchr/testify v1.6.1 github.com/teris-io/shortid v0.0.0-20201117134242-e59966efd125 // indirect - github.com/tidwall/gjson v1.9.3 // indirect go.opencensus.io v0.22.5 // indirect go.uber.org/multierr v1.6.0 // indirect go.uber.org/ratelimit v0.2.0 diff --git a/go.sum b/go.sum index a37395f2..2f56dea0 100644 --- a/go.sum +++ b/go.sum @@ -90,8 +90,8 @@ github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s= github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/gagliardetto/binary v0.5.2 h1:puURDkknQkF/e5bx2JtnYv9pEdBf5YCx5Qh99Mk9A00= -github.com/gagliardetto/binary v0.5.2/go.mod h1:peJR9PvwamL4YOh1nHWCPLry2VEfeeD1ADvewka7HnQ= +github.com/gagliardetto/binary v0.6.0 h1:ckbN1NNYvEZh/UzSRubZVgEK2kY2IL7bijSnANwj4z4= +github.com/gagliardetto/binary v0.6.0/go.mod h1:aOfYkc20U0deHaHn/LVZXiqlkDbFAX0FpTlDhsXa0S0= github.com/gagliardetto/gofuzz v1.2.2 h1:XL/8qDMzcgvR4+CyRQW9UGdwPRPMHVJfqQ/uMvSUuQw= github.com/gagliardetto/gofuzz v1.2.2/go.mod h1:bkH/3hYLZrMLbfYWA0pWzXmi5TTRZnu4pMGZBkqMKvY= github.com/gagliardetto/treeout v0.1.4 h1:ozeYerrLCmCubo1TcIjFiOWTTGteOOHND1twdFpgwaw= @@ -278,6 +278,8 @@ github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f h1:UFr9zpz4xgTnIE5yIMtWAMngCdZ9p/+q6lTbgelo80M= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= +github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= +github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= @@ -314,13 +316,10 @@ github.com/teris-io/shortid v0.0.0-20201117134242-e59966efd125 h1:3SNcvBmEPE1YlB github.com/teris-io/shortid v0.0.0-20201117134242-e59966efd125/go.mod h1:M8agBzgqHIhgj7wEn9/0hJUZcrvt9VY+Ln+S1I5Mha0= github.com/test-go/testify v1.1.4 h1:Tf9lntrKUMHiXQ07qBScBTSA0dhYQlu83hswqelv1iE= github.com/test-go/testify v1.1.4/go.mod h1:rH7cfJo/47vWGdi4GPj16x3/t1xGOj2YxzmNQzk2ghU= -github.com/tidwall/gjson v1.6.3/go.mod h1:BaHyNc5bjzYkPqgLq7mdVzeiRtULKULXLgZFKsxEHI0= github.com/tidwall/gjson v1.9.3 h1:hqzS9wAHMO+KVBBkLxYdkEeeFHuqr95GfClRLKlgK0E= github.com/tidwall/gjson v1.9.3/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= -github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E= github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= -github.com/tidwall/pretty v1.0.2/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= diff --git a/programs/serum/testdata/serum-open-orders-new.json b/programs/serum/testdata/serum-open-orders-new.json index 05ada472..6475e40c 100755 --- a/programs/serum/testdata/serum-open-orders-new.json +++ b/programs/serum/testdata/serum-open-orders-new.json @@ -6,8 +6,8 @@ "NativeBaseTokenTotal": "374817100000", "NativeQuoteTokenFree": "27061856249", "NativeQuoteTokenTotal": "398993915777", - "FreeSlotBits": "0xffffffffffffffffffffffffd0e00000", - "IsBidBits": "0x0000000000000000000000002f13a5d6", + "FreeSlotBits": "340282366920938463463374607430977585152", + "IsBidBits": "789816790", "Orders": [ { "Lo": 18446744073704103085, diff --git a/programs/serum/testdata/serum-open-orders-old.json b/programs/serum/testdata/serum-open-orders-old.json index 92eda1ad..264e346a 100755 --- a/programs/serum/testdata/serum-open-orders-old.json +++ b/programs/serum/testdata/serum-open-orders-old.json @@ -6,8 +6,8 @@ "NativeBaseTokenTotal": "374817100000", "NativeQuoteTokenFree": "27061856249", "NativeQuoteTokenTotal": "398993915777", - "FreeSlotBits": "0xffffffffffffffffffffffffd0f00000", - "IsBidBits": "0x0000000000000000000000002f03a5d7", + "FreeSlotBits": "340282366920938463463374607430978633728", + "IsBidBits": "788768215", "Orders": [ { "Lo": 18446744073704103085, diff --git a/programs/serum/types_test.go b/programs/serum/types_test.go index a03b8871..3ab2736b 100644 --- a/programs/serum/types_test.go +++ b/programs/serum/types_test.go @@ -23,11 +23,8 @@ import ( "encoding/hex" "fmt" "io/ioutil" - "strings" "testing" - "github.com/gagliardetto/solana-go/diff" - bin "github.com/gagliardetto/binary" "github.com/gagliardetto/solana-go" "github.com/stretchr/testify/assert" @@ -264,59 +261,6 @@ func TestOrderID(t *testing.T) { } -func Test_OpenOrderDiff(t *testing.T) { - oldDataFile := "testdata/serum-open-orders-old.hex" - newDataFile := "testdata/serum-open-orders-new.hex" - // is_free_slot diff => 0000f0d0ffffffffffffffffffffffff -> 0000e0d0ffffffffffffffffffffffff - // IsBidBits diff => d7a5032f000000000000000000000000 -> d6a5132f000000000000000000000000 - // added orders[20] => 00000000000000000000000000000000 -> fddeacffffffffff4008000000000000 (price = 2112, seqNum = 5447938) - - olDataJSONFile := strings.ReplaceAll(oldDataFile, ".hex", ".json") - newDataJSONFile := strings.ReplaceAll(newDataFile, ".hex", ".json") - - oldOpenOrders := &OpenOrders{} - require.NoError(t, oldOpenOrders.Decode(readHexFile(t, oldDataFile))) - - newOpenOrders := &OpenOrders{} - require.NoError(t, newOpenOrders.Decode(readHexFile(t, newDataFile))) - - oldCnt, err := json.MarshalIndent(oldOpenOrders, "", " ") - require.NoError(t, err) - writeFile(t, olDataJSONFile, oldCnt) - - newCnt, err := json.MarshalIndent(newOpenOrders, "", " ") - require.NoError(t, err) - writeFile(t, newDataJSONFile, newCnt) - - hasNewOrder := false - newOrderIndex := uint32(0) - diff.Diff(oldOpenOrders, newOpenOrders, diff.OnEvent(func(event diff.Event) { - if match, _ := event.Match("Orders[#]"); match { - switch event.Kind { - case diff.KindAdded: - if index, found := event.Path.SliceIndex(); found { - hasNewOrder = true - newOrderIndex = uint32(index) - } - } - } - })) - - assert.Equal(t, hasNewOrder, true) - assert.Equal(t, newOrderIndex, uint32(20)) - newOrder := newOpenOrders.GetOrder(newOrderIndex) - assert.Equal(t, &Order{ - ID: OrderID{ - Hi: 0x0000000000000840, - Lo: 0xffffffffffacdefd, - }, - Side: SideBid, - }, newOrder) - assert.Equal(t, newOrder.SeqNum(), uint64(5447938)) - assert.Equal(t, newOrder.Price(), uint64(2112)) - -} - func Test_OpenOrder_GetOrder(t *testing.T) { openOrderData := "testdata/serum-open-orders-new.hex" diff --git a/programs/tokenregistry/instruction.go b/programs/tokenregistry/instruction.go index a360f432..3314c303 100644 --- a/programs/tokenregistry/instruction.go +++ b/programs/tokenregistry/instruction.go @@ -59,7 +59,7 @@ func DecodeInstruction(accounts []*solana.AccountMeta, data []byte) (*Instructio func NewRegisterTokenInstruction(logo Logo, name Name, symbol Symbol, website Website, tokenMetaKey, ownerKey, tokenKey solana.PublicKey) *Instruction { return &Instruction{ BaseVariant: bin.BaseVariant{ - TypeID: bin.TypeIDFromUint32(0, bin.LE()), + TypeID: bin.TypeIDFromUint32(0, bin.LE), Impl: &RegisterToken{ Logo: logo, Name: name, @@ -83,7 +83,7 @@ var _ bin.EncoderDecoder = &Instruction{} func (i *Instruction) Accounts() (out []*solana.AccountMeta) { switch i.TypeID { - case bin.TypeIDFromUint32(0, bin.LE()): + case bin.TypeIDFromUint32(0, bin.LE): accounts := i.Impl.(*RegisterToken).Accounts out = []*solana.AccountMeta{accounts.TokenMeta, accounts.Owner, accounts.Token} }