Skip to content

Commit

Permalink
Adding on demand tpu support
Browse files Browse the repository at this point in the history
  • Loading branch information
tinystarinagalaxy committed May 9, 2024
1 parent 71e5f78 commit e3d41ea
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 69 deletions.
3 changes: 2 additions & 1 deletion examples/grpcclient/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,8 @@ func callPlaceOrderBundle(g *provider.GRPCClient, ownerAddr, payerAddr, _ string
}
log.Infof("created unsigned place order transaction: %v", response.Transaction)

resp, err := g.SignAndSubmit(ctx, &pb.TransactionMessage{Content: response.Transaction.Content}, true, true)
resp, err := g.SignAndSubmit(ctx, &pb.TransactionMessage{
Content: response.Transaction.Content}, true, true, 0)
if err != nil {
log.Errorf("failed to sign and submit order (%v)", err)
return true
Expand Down
2 changes: 1 addition & 1 deletion examples/httpclient/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ func callPlaceOrderBundle(ownerAddr string, bundleTip uint64) bool {

tx, err := h.SignAndSubmit(ctx, &pb.TransactionMessage{Content: resp.Transactions[0].Content, IsCleanup: false},
true,
true)
true, 0)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/wsclient/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ func callPlaceOrderBundle(w *provider.WSClient, ownerAddr string, tipAmount uint

signature, err := w.SignAndSubmit(ctx, &pb.TransactionMessage{Content: resp.Transactions[0].Content},
true,
true)
true, 0)
if err != nil {
log.Errorf("failed to sign and submit tx: %s", err)
return true
Expand Down
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
module github.com/bloXroute-Labs/solana-trader-client-go

go 1.18
go 1.21

toolchain go1.22.1

require (
github.com/bloXroute-Labs/solana-trader-proto v1.9.1-0.20240429232042-45327f4e1bbd
github.com/bloXroute-Labs/solana-trader-proto v1.9.1-0.20240501210629-90426218b803
github.com/gagliardetto/binary v0.7.7
github.com/gagliardetto/solana-go v1.8.4
github.com/gorilla/websocket v1.4.2
Expand Down
26 changes: 4 additions & 22 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,8 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB
github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84=
github.com/blendle/zapdriver v1.3.1 h1:C3dydBOWYRiOk+B8X9IVZ5IOe+7cl+tGOexN4QqHfpE=
github.com/blendle/zapdriver v1.3.1/go.mod h1:mdXfREi6u5MArG4j9fewC+FGnXaBR+T4Ox4J2u4eHCc=
github.com/bloXroute-Labs/solana-trader-proto v1.9.1-0.20240219185735-a8609a2fd7c7 h1:RR9FrOf9LWlf33MX9pPIoxl18Q8HBjlo2mygVv277Vs=
github.com/bloXroute-Labs/solana-trader-proto v1.9.1-0.20240219185735-a8609a2fd7c7/go.mod h1:OPAXgJCllC8aCvjRO1uOvpd1eHP0x5Rfr61oQAZEX8Y=
github.com/bloXroute-Labs/solana-trader-proto v1.9.1-0.20240220194656-6297e3dee036 h1:Wz7kbiDLE6x9wAGG4Z952vbB04KPfqYOU8q8WWKvvQg=
github.com/bloXroute-Labs/solana-trader-proto v1.9.1-0.20240220194656-6297e3dee036/go.mod h1:OPAXgJCllC8aCvjRO1uOvpd1eHP0x5Rfr61oQAZEX8Y=
github.com/bloXroute-Labs/solana-trader-proto v1.9.1-0.20240327203054-64ad5785ff21 h1:RuNYhxrCXuGR6xweB+QRXCDl3HQPyCwk2Qdo2R69Og4=
github.com/bloXroute-Labs/solana-trader-proto v1.9.1-0.20240327203054-64ad5785ff21/go.mod h1:OPAXgJCllC8aCvjRO1uOvpd1eHP0x5Rfr61oQAZEX8Y=
github.com/bloXroute-Labs/solana-trader-proto v1.9.1-0.20240402200942-6f2a1893a74a h1:hBoQzkeQzOPzORh76i2N7AdKVDl3+8QNZGGrTpm/6T0=
github.com/bloXroute-Labs/solana-trader-proto v1.9.1-0.20240402200942-6f2a1893a74a/go.mod h1:OPAXgJCllC8aCvjRO1uOvpd1eHP0x5Rfr61oQAZEX8Y=
github.com/bloXroute-Labs/solana-trader-proto v1.9.1-0.20240410002629-945bf58ca753 h1:s8u6kuSyjtnOJ3BGftefMkP6gym/5z+oVOxDPCmRujY=
github.com/bloXroute-Labs/solana-trader-proto v1.9.1-0.20240410002629-945bf58ca753/go.mod h1:OPAXgJCllC8aCvjRO1uOvpd1eHP0x5Rfr61oQAZEX8Y=
github.com/bloXroute-Labs/solana-trader-proto v1.9.1-0.20240412162724-ea0c96ba6732 h1:v2mR6vHlGcwtTNPQgSBoi19Vj2HgHNXuj+1NUqtBTjE=
github.com/bloXroute-Labs/solana-trader-proto v1.9.1-0.20240412162724-ea0c96ba6732/go.mod h1:OPAXgJCllC8aCvjRO1uOvpd1eHP0x5Rfr61oQAZEX8Y=
github.com/bloXroute-Labs/solana-trader-proto v1.9.1-0.20240417154647-c4d8338c2ca8 h1:GLEHaTmik0FObvicsAVhxAN35FKoclbxApi/cmaautI=
github.com/bloXroute-Labs/solana-trader-proto v1.9.1-0.20240417154647-c4d8338c2ca8/go.mod h1:OPAXgJCllC8aCvjRO1uOvpd1eHP0x5Rfr61oQAZEX8Y=
github.com/bloXroute-Labs/solana-trader-proto v1.9.1-0.20240417161811-fac45007d500 h1:7omIMIK0m8qanMsmxzKHESm4VVtOZt5VrnqclrwNGtM=
github.com/bloXroute-Labs/solana-trader-proto v1.9.1-0.20240417161811-fac45007d500/go.mod h1:OPAXgJCllC8aCvjRO1uOvpd1eHP0x5Rfr61oQAZEX8Y=
github.com/bloXroute-Labs/solana-trader-proto v1.9.1-0.20240423004058-8869a255d7f5 h1:HeD/erz+aVgglkqGOX4MUaQIJulT+dY7x8w/buj9Pm4=
github.com/bloXroute-Labs/solana-trader-proto v1.9.1-0.20240423004058-8869a255d7f5/go.mod h1:OPAXgJCllC8aCvjRO1uOvpd1eHP0x5Rfr61oQAZEX8Y=
github.com/bloXroute-Labs/solana-trader-proto v1.9.1-0.20240429221439-9851c4d5670a h1:VRW3P54ZsBA6b7PPzVgYNOKomsLxOjAm12Zzu275QtM=
github.com/bloXroute-Labs/solana-trader-proto v1.9.1-0.20240429221439-9851c4d5670a/go.mod h1:OPAXgJCllC8aCvjRO1uOvpd1eHP0x5Rfr61oQAZEX8Y=
github.com/bloXroute-Labs/solana-trader-proto v1.9.1-0.20240429232042-45327f4e1bbd h1:Ma0RfuzokMrNmywCGzQp6Ds9rGrq73Lm39DwWc8eyzc=
github.com/bloXroute-Labs/solana-trader-proto v1.9.1-0.20240429232042-45327f4e1bbd/go.mod h1:OPAXgJCllC8aCvjRO1uOvpd1eHP0x5Rfr61oQAZEX8Y=
github.com/bloXroute-Labs/solana-trader-proto v1.9.1-0.20240501210629-90426218b803 h1:eP59bftNJ5efdaZhDzFX/3HYX0hUiporyJmk5i9Xq7E=
github.com/bloXroute-Labs/solana-trader-proto v1.9.1-0.20240501210629-90426218b803/go.mod h1:OPAXgJCllC8aCvjRO1uOvpd1eHP0x5Rfr61oQAZEX8Y=
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
Expand Down Expand Up @@ -140,6 +120,7 @@ github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7a
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/glog v1.0.0 h1:nfP3RFugxnNRyKgeWd4oI1nYvXpxrx8ck8ZrcizshdQ=
github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4=
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
Expand Down Expand Up @@ -178,6 +159,7 @@ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
Expand Down
39 changes: 23 additions & 16 deletions provider/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ func (g *GRPCClient) GetQuotes(ctx context.Context, inToken, outToken string, in
}

// SignAndSubmit signs the given transaction and submits it.
func (g *GRPCClient) SignAndSubmit(ctx context.Context, tx *pb.TransactionMessage, skipPreFlight bool, frontRunningProtection bool) (string, error) {
func (g *GRPCClient) SignAndSubmit(ctx context.Context, tx *pb.TransactionMessage,
skipPreFlight bool, frontRunningProtection bool, tpu uint32) (string, error) {
if g.privateKey == nil {
return "", ErrPrivateKeyNotFound
}
Expand All @@ -269,7 +270,7 @@ func (g *GRPCClient) SignAndSubmit(ctx context.Context, tx *pb.TransactionMessag
response, err := g.PostSubmit(ctx, &pb.TransactionMessage{
Content: txBase64,
IsCleanup: tx.IsCleanup,
}, skipPreFlight, frontRunningProtection)
}, skipPreFlight, frontRunningProtection, tpu)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -324,10 +325,13 @@ func (g *GRPCClient) PostOrder(ctx context.Context, owner, payer, market string,
}

// PostSubmit posts the transaction string to the Solana network.
func (g *GRPCClient) PostSubmit(ctx context.Context, tx *pb.TransactionMessage, skipPreFlight bool, frontRunningProtection bool) (*pb.PostSubmitResponse, error) {
func (g *GRPCClient) PostSubmit(ctx context.Context, tx *pb.TransactionMessage, skipPreFlight bool,
frontRunningProtection bool, tpu uint32) (*pb.PostSubmitResponse, error) {
return g.apiClient.PostSubmit(ctx, &pb.PostSubmitRequest{Transaction: tx,
SkipPreFlight: skipPreFlight,
FrontRunningProtection: &frontRunningProtection})
FrontRunningProtection: &frontRunningProtection,
Tpu: &tpu,
})
}

// PostSubmitBatch posts a bundle of transactions string based on a specific SubmitStrategy to the Solana network.
Expand All @@ -336,10 +340,13 @@ func (g *GRPCClient) PostSubmitBatch(ctx context.Context, request *pb.PostSubmit
}

// PostSubmitV2 posts the transaction string to the Solana network.
func (g *GRPCClient) PostSubmitV2(ctx context.Context, tx *pb.TransactionMessage, skipPreFlight bool, frontRunningProtection bool) (*pb.PostSubmitResponse, error) {
func (g *GRPCClient) PostSubmitV2(ctx context.Context, tx *pb.TransactionMessage,
skipPreFlight bool, frontRunningProtection bool, tpu uint32) (*pb.PostSubmitResponse, error) {
return g.apiClient.PostSubmitV2(ctx, &pb.PostSubmitRequest{Transaction: tx,
SkipPreFlight: skipPreFlight,
FrontRunningProtection: &frontRunningProtection})
FrontRunningProtection: &frontRunningProtection,
Tpu: &tpu,
})
}

// PostSubmitBatchV2 posts a bundle of transactions string based on a specific SubmitStrategy to the Solana network.
Expand Down Expand Up @@ -481,7 +488,7 @@ func (g *GRPCClient) SubmitOrder(ctx context.Context, owner, payer, market strin
if opts.SkipPreFlight != nil {
skipPreFlight = *opts.SkipPreFlight
}
return g.SignAndSubmit(ctx, order.Transaction, skipPreFlight, false)
return g.SignAndSubmit(ctx, order.Transaction, skipPreFlight, false, 0)
}

// PostCancelOrder builds a Serum cancel order.
Expand Down Expand Up @@ -520,7 +527,7 @@ func (g *GRPCClient) SubmitCancelOrder(
return "", err
}

return g.SignAndSubmit(ctx, order.Transaction, skipPreFlight, false)
return g.SignAndSubmit(ctx, order.Transaction, skipPreFlight, false, 0)
}

// PostCancelByClientOrderID builds a Serum cancel order by client ID.
Expand Down Expand Up @@ -557,7 +564,7 @@ func (g *GRPCClient) SubmitCancelByClientOrderID(
return "", err
}

return g.SignAndSubmit(ctx, order.Transaction, skipPreFlight, false)
return g.SignAndSubmit(ctx, order.Transaction, skipPreFlight, false, 0)
}

func (g *GRPCClient) PostCancelAll(ctx context.Context, market, owner string, openOrders []string, project pb.Project) (*pb.PostCancelAllResponse, error) {
Expand Down Expand Up @@ -596,7 +603,7 @@ func (g *GRPCClient) SubmitSettle(ctx context.Context, owner, market, baseTokenW
return "", err
}

return g.SignAndSubmit(ctx, order.Transaction, skipPreflight, false)
return g.SignAndSubmit(ctx, order.Transaction, skipPreflight, false, 0)
}

func (g *GRPCClient) PostReplaceByClientOrderID(ctx context.Context, owner, payer, market string, side pb.Side, types []common.OrderType, amount, price float64, project pb.Project, opts PostOrderOpts) (*pb.PostOrderResponse, error) {
Expand All @@ -623,7 +630,7 @@ func (g *GRPCClient) SubmitReplaceByClientOrderID(ctx context.Context, owner, pa
if opts.SkipPreFlight != nil {
skipPreFlight = *opts.SkipPreFlight
}
return g.SignAndSubmit(ctx, order.Transaction, skipPreFlight, false)
return g.SignAndSubmit(ctx, order.Transaction, skipPreFlight, false, 0)
}

func (g *GRPCClient) PostReplaceOrder(ctx context.Context, orderID, owner, payer, market string, side pb.Side, types []common.OrderType, amount, price float64, project pb.Project, opts PostOrderOpts) (*pb.PostOrderResponse, error) {
Expand Down Expand Up @@ -651,7 +658,7 @@ func (g *GRPCClient) SubmitReplaceOrder(ctx context.Context, orderID, owner, pay
if opts.SkipPreFlight != nil {
skipPreFlight = *opts.SkipPreFlight
}
return g.SignAndSubmit(ctx, order.Transaction, skipPreFlight, false)
return g.SignAndSubmit(ctx, order.Transaction, skipPreFlight, false, 0)
}

// GetOrderbookStream subscribes to a stream for changes to the requested market updates (e.g. asks and bids. Set limit to 0 for all bids/ asks).
Expand Down Expand Up @@ -897,7 +904,7 @@ func (g *GRPCClient) SubmitOrderV2(ctx context.Context, owner, payer, market str
if opts.SkipPreFlight != nil {
skipPreFlight = *opts.SkipPreFlight
}
return g.SignAndSubmit(ctx, order.Transaction, skipPreFlight, false)
return g.SignAndSubmit(ctx, order.Transaction, skipPreFlight, false, 0)
}

// SubmitOrderV2WithPriorityFee builds a Serum market order, signs it, and submits to the network with specified computeLimit and computePrice
Expand All @@ -912,7 +919,7 @@ func (g *GRPCClient) SubmitOrderV2WithPriorityFee(ctx context.Context, owner, pa
if opts.SkipPreFlight != nil {
skipPreFlight = *opts.SkipPreFlight
}
return g.SignAndSubmit(ctx, order.Transaction, skipPreFlight, false)
return g.SignAndSubmit(ctx, order.Transaction, skipPreFlight, false, 0)
}

// PostCancelOrderV2 builds a Serum cancel order.
Expand Down Expand Up @@ -972,7 +979,7 @@ func (g *GRPCClient) SubmitSettleV2(ctx context.Context, owner, market, baseToke
return "", err
}

return g.SignAndSubmit(ctx, order.Transaction, skipPreflight, false)
return g.SignAndSubmit(ctx, order.Transaction, skipPreflight, false, 0)
}

func (g *GRPCClient) PostReplaceOrderV2(ctx context.Context, orderID, owner, payer, market string, side string, orderType string, amount, price float64, opts PostOrderOpts) (*pb.PostOrderResponse, error) {
Expand All @@ -999,5 +1006,5 @@ func (g *GRPCClient) SubmitReplaceOrderV2(ctx context.Context, orderID, owner, p
if opts.SkipPreFlight != nil {
skipPreFlight = *opts.SkipPreFlight
}
return g.SignAndSubmit(ctx, order.Transaction, skipPreFlight, false)
return g.SignAndSubmit(ctx, order.Transaction, skipPreFlight, false, 0)
}
Loading

0 comments on commit e3d41ea

Please sign in to comment.