forked from gagliardetto/solana-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
instruction.go
616 lines (523 loc) · 20.7 KB
/
instruction.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
// Copyright 2021 github.com/gagliardetto
// This file has been modified by github.com/gagliardetto
//
// Copyright 2020 dfuse Platform Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package serum
import (
"encoding/binary"
"fmt"
bin "github.com/gagliardetto/binary"
"github.com/stonecoldik/go-solana"
"github.com/stonecoldik/go-solana/text"
)
func init() {
solana.RegisterInstructionDecoder(DEXProgramIDV2, registryDecodeInstruction)
}
func registryDecodeInstruction(accounts []*solana.AccountMeta, data []byte) (interface{}, error) {
inst, err := DecodeInstruction(accounts, data)
if err != nil {
return nil, err
}
return inst, nil
}
func DecodeInstruction(accounts []*solana.AccountMeta, data []byte) (*Instruction, error) {
// FIXME: can't we dedupe this in some ways? It's copied in all of the programs' folders.
var inst Instruction
if err := bin.NewBinDecoder(data).Decode(&inst); err != nil {
return nil, fmt.Errorf("unable to decode instruction for serum program: %w", err)
}
if v, ok := inst.Impl.(solana.AccountsSettable); ok {
err := v.SetAccounts(accounts)
if err != nil {
return nil, fmt.Errorf("unable to set accounts for instruction: %w", err)
}
}
return &inst, nil
}
var InstructionDefVariant = bin.NewVariantDefinition(bin.Uint32TypeIDEncoding, []bin.VariantType{
{Name: "initialize_market", Type: (*InstructionInitializeMarket)(nil)},
{Name: "new_order", Type: (*InstructionNewOrder)(nil)},
{Name: "match_orders", Type: (*InstructionMatchOrder)(nil)},
{Name: "consume_events", Type: (*InstructionConsumeEvents)(nil)},
{Name: "cancel_order", Type: (*InstructionCancelOrder)(nil)},
{Name: "settle_funds", Type: (*InstructionSettleFunds)(nil)},
{Name: "cancel_order_by_client_id", Type: (*InstructionCancelOrderByClientId)(nil)},
{Name: "disable_market", Type: (*InstructionDisableMarketAccounts)(nil)},
{Name: "sweep_fees", Type: (*InstructionSweepFees)(nil)},
{Name: "new_order_v2", Type: (*InstructionNewOrderV2)(nil)},
// Added in DEX V3
{Name: "new_order_v3", Type: (*InstructionNewOrderV3)(nil)},
{Name: "cancel_order_v2", Type: (*InstructionCancelOrderV2)(nil)},
{Name: "cancel_order_by_client_id_v2", Type: (*InstructionCancelOrderByClientIdV2)(nil)},
{Name: "send_take", Type: (*InstructionSendTake)(nil)},
})
type Instruction struct {
bin.BaseVariant
Version uint8
}
var _ bin.EncoderDecoder = &Instruction{}
func (i *Instruction) TextEncode(encoder *text.Encoder, option *text.Option) error {
return encoder.Encode(i.Impl, option)
}
func (i *Instruction) UnmarshalWithDecoder(decoder *bin.Decoder) (err error) {
i.Version, err = decoder.ReadUint8()
if err != nil {
return fmt.Errorf("unable to read version: %w", err)
}
return i.BaseVariant.UnmarshalBinaryVariant(decoder, InstructionDefVariant)
}
func (i Instruction) MarshalWithEncoder(encoder *bin.Encoder) error {
err := encoder.WriteUint8(i.Version)
if err != nil {
return fmt.Errorf("unable to write instruction version: %w", err)
}
err = encoder.WriteUint32(i.TypeID.Uint32(), binary.LittleEndian)
if err != nil {
return fmt.Errorf("unable to write variant type: %w", err)
}
return encoder.Encode(i.Impl)
}
type InitializeMarketAccounts struct {
Market *solana.AccountMeta `text:"linear,notype"`
SPLCoinToken *solana.AccountMeta `text:"linear,notype"`
SPLPriceToken *solana.AccountMeta `text:"linear,notype"`
CoinMint *solana.AccountMeta `text:"linear,notype"`
PriceMint *solana.AccountMeta `text:"linear,notype"`
}
type InstructionInitializeMarket struct {
BaseLotSize uint64
QuoteLotSize uint64
FeeRateBps uint16
VaultSignerNonce uint64
QuoteDustThreshold uint64
Accounts *InitializeMarketAccounts `bin:"-"`
}
func (i *InstructionInitializeMarket) SetAccounts(accounts []*solana.AccountMeta) error {
if len(accounts) < 9 {
return fmt.Errorf("insufficient account, Initialize Market requires at-least 8 accounts not %d", len(accounts))
}
i.Accounts = &InitializeMarketAccounts{
Market: accounts[0],
SPLCoinToken: accounts[5],
SPLPriceToken: accounts[6],
CoinMint: accounts[7],
PriceMint: accounts[8],
}
return nil
}
type NewOrderAccounts struct {
Market *solana.AccountMeta `text:"linear,notype"`
OpenOrders *solana.AccountMeta `text:"linear,notype"`
RequestQueue *solana.AccountMeta `text:"linear,notype"`
Payer *solana.AccountMeta `text:"linear,notype"`
Owner *solana.AccountMeta `text:"linear,notype"` // The owner of the open orders, i.e. the trader
CoinVault *solana.AccountMeta `text:"linear,notype"`
PCVault *solana.AccountMeta `text:"linear,notype"`
SPLTokenProgram *solana.AccountMeta `text:"linear,notype"`
Rent *solana.AccountMeta `text:"linear,notype"`
SRMDiscountAccount *solana.AccountMeta `text:"linear,notype"`
}
// InstructionNewOrder seems to be unused after DEX v3 (unconfirmed claim)
type InstructionNewOrder struct {
Side Side
LimitPrice uint64
MaxQuantity uint64
OrderType OrderType
ClientID uint64
Accounts *NewOrderAccounts `bin:"-"`
}
func (i *InstructionNewOrder) SetAccounts(accounts []*solana.AccountMeta) error {
if len(accounts) < 9 {
return fmt.Errorf("insufficient account, New Order requires at-least 10 accounts not %d", len(accounts))
}
i.Accounts = &NewOrderAccounts{
Market: accounts[0],
OpenOrders: accounts[1],
RequestQueue: accounts[2],
Payer: accounts[3],
Owner: accounts[4],
CoinVault: accounts[5],
PCVault: accounts[6],
SPLTokenProgram: accounts[7],
Rent: accounts[8],
}
if len(accounts) >= 10 {
i.Accounts.SRMDiscountAccount = accounts[9]
}
return nil
}
type MatchOrderAccounts struct {
Market *solana.AccountMeta `text:"linear,notype"`
RequestQueue *solana.AccountMeta `text:"linear,notype"`
EventQueue *solana.AccountMeta `text:"linear,notype"`
Bids *solana.AccountMeta `text:"linear,notype"`
Asks *solana.AccountMeta `text:"linear,notype"`
CoinFeeReceivable *solana.AccountMeta `text:"linear,notype"`
PCFeeReceivable *solana.AccountMeta `text:"linear,notype"`
}
// InstructionMatchOrder seems to be unused after DEX v3 (unconfirmed claim)
type InstructionMatchOrder struct {
Limit uint16
Accounts *MatchOrderAccounts `bin:"-"`
}
func (i *InstructionMatchOrder) SetAccounts(accounts []*solana.AccountMeta) error {
if len(accounts) < 7 {
return fmt.Errorf("insufficient account, Match Order requires at-least 7 accounts not %d\n", len(accounts))
}
i.Accounts = &MatchOrderAccounts{
Market: accounts[0],
RequestQueue: accounts[1],
EventQueue: accounts[2],
Bids: accounts[3],
Asks: accounts[4],
CoinFeeReceivable: accounts[5],
PCFeeReceivable: accounts[6],
}
return nil
}
type ConsumeEventsAccounts struct {
OpenOrders []*solana.AccountMeta `text:"linear,notype"`
Market *solana.AccountMeta `text:"linear,notype"`
EventQueue *solana.AccountMeta `text:"linear,notype"`
CoinFeeReceivable *solana.AccountMeta `text:"linear,notype"`
PCFeeReceivable *solana.AccountMeta `text:"linear,notype"`
}
type InstructionConsumeEvents struct {
Limit uint16
Accounts *ConsumeEventsAccounts `bin:"-"`
}
func (i *InstructionConsumeEvents) SetAccounts(accounts []*solana.AccountMeta) error {
l := len(accounts)
if l < 4 {
return fmt.Errorf("insufficient account, Consume Events requires at-least 4 accounts not %d", len(accounts))
}
i.Accounts = &ConsumeEventsAccounts{
Market: accounts[l-4],
EventQueue: accounts[l-3],
CoinFeeReceivable: accounts[l-2],
PCFeeReceivable: accounts[l-1],
}
for idx := 0; idx < l-4; idx++ {
i.Accounts.OpenOrders = append(i.Accounts.OpenOrders, accounts[idx])
}
return nil
}
type CancelOrderAccounts struct {
Market *solana.AccountMeta `text:"linear,notype"`
OpenOrders *solana.AccountMeta `text:"linear,notype"`
RequestQueue *solana.AccountMeta `text:"linear,notype"`
Owner *solana.AccountMeta `text:"linear,notype"`
}
// InstructionCancelOrder seems to be unused after DEX v3 (unconfirmed claim)
type InstructionCancelOrder struct {
Side Side
OrderID bin.Uint128
OpenOrders solana.PublicKey
OpenOrderSlot uint8
Accounts *CancelOrderAccounts `bin:"-"`
}
func (i *InstructionCancelOrder) SetAccounts(accounts []*solana.AccountMeta) error {
if len(accounts) < 4 {
return fmt.Errorf("insufficient account, Cancel Order requires at-least 4 accounts not %d\n", len(accounts))
}
i.Accounts = &CancelOrderAccounts{
Market: accounts[0],
OpenOrders: accounts[1],
RequestQueue: accounts[2],
Owner: accounts[3],
}
return nil
}
type SettleFundsAccounts struct {
Market *solana.AccountMeta `text:"linear,notype"`
OpenOrders *solana.AccountMeta `text:"linear,notype"`
Owner *solana.AccountMeta `text:"linear,notype"`
CoinVault *solana.AccountMeta `text:"linear,notype"`
PCVault *solana.AccountMeta `text:"linear,notype"`
CoinWallet *solana.AccountMeta `text:"linear,notype"`
PCWallet *solana.AccountMeta `text:"linear,notype"`
Signer *solana.AccountMeta `text:"linear,notype"`
SPLTokenProgram *solana.AccountMeta `text:"linear,notype"`
ReferrerPCWallet *solana.AccountMeta `text:"linear,notype"`
}
type InstructionSettleFunds struct {
Accounts *SettleFundsAccounts `bin:"-"`
}
func (i *InstructionSettleFunds) SetAccounts(accounts []*solana.AccountMeta) error {
if len(accounts) < 9 {
return fmt.Errorf("insufficient account, Settle Funds requires at-least 10 accounts not %d", len(accounts))
}
i.Accounts = &SettleFundsAccounts{
Market: accounts[0],
OpenOrders: accounts[1],
Owner: accounts[2],
CoinVault: accounts[3],
PCVault: accounts[4],
CoinWallet: accounts[5],
PCWallet: accounts[6],
Signer: accounts[7],
SPLTokenProgram: accounts[8],
}
if len(accounts) >= 10 {
i.Accounts.ReferrerPCWallet = accounts[9]
}
return nil
}
type CancelOrderByClientIdAccounts struct {
Market *solana.AccountMeta `text:"linear,notype"`
OpenOrders *solana.AccountMeta `text:"linear,notype"`
RequestQueue *solana.AccountMeta `text:"linear,notype"`
Owner *solana.AccountMeta `text:"linear,notype"`
}
// InstructionCancelOrderByClientId seems to be unused after DEX v3 (unconfirmed claim)
type InstructionCancelOrderByClientId struct {
ClientID uint64
Accounts *CancelOrderByClientIdAccounts `bin:"-"`
}
func (i *InstructionCancelOrderByClientId) SetAccounts(accounts []*solana.AccountMeta) error {
if len(accounts) < 4 {
return fmt.Errorf("insufficient account, Cancel Order By Client Id requires at-least 4 accounts not %d", len(accounts))
}
i.Accounts = &CancelOrderByClientIdAccounts{
Market: accounts[0],
OpenOrders: accounts[1],
RequestQueue: accounts[2],
Owner: accounts[3],
}
return nil
}
type DisableMarketAccounts struct {
Market *solana.AccountMeta `text:"linear,notype"`
DisableAuthority *solana.AccountMeta `text:"linear,notype"`
}
type InstructionDisableMarketAccounts struct {
Accounts *DisableMarketAccounts `bin:"-"`
}
func (i *InstructionDisableMarketAccounts) SetAccounts(accounts []*solana.AccountMeta) error {
if len(accounts) < 2 {
return fmt.Errorf("insufficient account, Disable Market requires at-least 2 accounts not %d", len(accounts))
}
i.Accounts = &DisableMarketAccounts{
Market: accounts[0],
DisableAuthority: accounts[1],
}
return nil
}
type SweepFeesAccounts struct {
Market *solana.AccountMeta `text:"linear,notype"`
PCVault *solana.AccountMeta `text:"linear,notype"`
FeeSweepingAuthority *solana.AccountMeta `text:"linear,notype"`
FeeReceivableAccount *solana.AccountMeta `text:"linear,notype"`
VaultSigner *solana.AccountMeta `text:"linear,notype"`
SPLTokenProgram *solana.AccountMeta `text:"linear,notype"`
}
type InstructionSweepFees struct {
Accounts *SweepFeesAccounts `bin:"-"`
}
func (i *InstructionSweepFees) SetAccounts(accounts []*solana.AccountMeta) error {
if len(accounts) < 6 {
return fmt.Errorf("insufficient account, Sweep Fees requires at-least 6 accounts not %d", len(accounts))
}
i.Accounts = &SweepFeesAccounts{
Market: accounts[0],
PCVault: accounts[1],
FeeSweepingAuthority: accounts[2],
FeeReceivableAccount: accounts[3],
VaultSigner: accounts[4],
SPLTokenProgram: accounts[5],
}
return nil
}
type NewOrderV2Accounts struct {
Market *solana.AccountMeta `text:"linear,notype"` // the market
OpenOrders *solana.AccountMeta `text:"linear,notype"` // the OpenOrders account to use
RequestQueue *solana.AccountMeta `text:"linear,notype"` // the request queue
Payer *solana.AccountMeta `text:"linear,notype"` // the (coin or price currency) account paying for the order
Owner *solana.AccountMeta `text:"linear,notype"` // owner of the OpenOrders account
CoinVault *solana.AccountMeta `text:"linear,notype"` // coin vault
PCVault *solana.AccountMeta `text:"linear,notype"` // pc vault
SPLTokenProgram *solana.AccountMeta `text:"linear,notype"` // spl token program
RentSysvar *solana.AccountMeta `text:"linear,notype"` // the rent sysvar
FeeDiscount *solana.AccountMeta `text:"linear,notype"` // (optional) the (M)SRM account used for fee discounts
}
type SelfTradeBehavior uint32
const (
SelfTradeBehaviorDecrementTake = iota
SelfTradeBehaviorCancelProvide
// Added in DEX V3
SelfTradeBehaviorAbortTransaction
)
// InstructionNewOrderV2 seems to be unused after DEX v3 (unconfirmed claim)
type InstructionNewOrderV2 struct {
Side Side
LimitPrice uint64
MaxQuantity uint64
OrderType OrderType
ClientID uint64
SelfTradeBehavior SelfTradeBehavior
Accounts *NewOrderV2Accounts `bin:"-"`
}
func (i *InstructionNewOrderV2) SetAccounts(accounts []*solana.AccountMeta) error {
if len(accounts) < 9 {
return fmt.Errorf("insufficient account, New Order V2 requires at-least 9 accounts + 1 optional not %d", len(accounts))
}
i.Accounts = &NewOrderV2Accounts{
Market: accounts[0],
OpenOrders: accounts[1],
RequestQueue: accounts[2],
Payer: accounts[3],
Owner: accounts[4],
CoinVault: accounts[5],
PCVault: accounts[6],
SPLTokenProgram: accounts[7],
RentSysvar: accounts[8],
}
if len(accounts) == 10 {
i.Accounts.FeeDiscount = accounts[9]
}
return nil
}
// DEX V3 Support
type NewOrderV3Accounts struct {
Market *solana.AccountMeta `text:"linear,notype"` // the market
OpenOrders *solana.AccountMeta `text:"linear,notype"` // the OpenOrders account to use
RequestQueue *solana.AccountMeta `text:"linear,notype"` // the request queue
EventQueue *solana.AccountMeta `text:"linear,notype"` // the event queue
Bidder *solana.AccountMeta `text:"linear,notype"` // bids
Asker *solana.AccountMeta `text:"linear,notype"` // asks
Payer *solana.AccountMeta `text:"linear,notype"` // the (coin or price currency) account paying for the order
Owner *solana.AccountMeta `text:"linear,notype"` // owner of the OpenOrders account
CoinVault *solana.AccountMeta `text:"linear,notype"` // coin vault
PCVault *solana.AccountMeta `text:"linear,notype"` // pc vault
SPLTokenProgram *solana.AccountMeta `text:"linear,notype"` // spl token program
RentSysvar *solana.AccountMeta `text:"linear,notype"` // the rent sysvar
FeeDiscount *solana.AccountMeta `text:"linear,notype"` // (optional) the (M)SRM account used for fee discounts
}
type InstructionNewOrderV3 struct {
Side Side
LimitPrice uint64
MaxCoinQuantity uint64
MaxNativePCQuantityIncludingFees uint64
SelfTradeBehavior SelfTradeBehavior
OrderType OrderType
ClientOrderID uint64
Limit uint16
Accounts *NewOrderV3Accounts `bin:"-"`
}
func (i *InstructionNewOrderV3) SetAccounts(accounts []*solana.AccountMeta) error {
if len(accounts) < 13 {
return fmt.Errorf("insufficient account, New Order V3 requires at-least 13 accounts not %d", len(accounts))
}
i.Accounts = &NewOrderV3Accounts{
Market: accounts[0],
OpenOrders: accounts[1],
RequestQueue: accounts[2],
EventQueue: accounts[3],
Bidder: accounts[4],
Asker: accounts[5],
Payer: accounts[6],
Owner: accounts[7],
CoinVault: accounts[8],
PCVault: accounts[9],
SPLTokenProgram: accounts[10],
RentSysvar: accounts[11],
FeeDiscount: accounts[12],
}
return nil
}
type CancelOrderV2Accounts struct {
Market *solana.AccountMeta `text:"linear,notype"` // 0. `[writable]` market
Bids *solana.AccountMeta `text:"linear,notype"` // 1. `[writable]` bids
Asks *solana.AccountMeta `text:"linear,notype"` // 2. `[writable]` asks
OpenOrders *solana.AccountMeta `text:"linear,notype"` // 3. `[writable]` OpenOrders
Owner *solana.AccountMeta `text:"linear,notype"` // 4. `[signer]` the OpenOrders owner
EventQueue *solana.AccountMeta `text:"linear,notype"` // 5. `[writable]` event_q
}
type InstructionCancelOrderV2 struct {
Side Side
OrderID bin.Uint128
Accounts *CancelOrderV2Accounts `bin:"-"`
}
func (i *InstructionCancelOrderV2) SetAccounts(accounts []*solana.AccountMeta) error {
if len(accounts) < 6 {
return fmt.Errorf("insufficient account, Cancel Order V2 requires at-least 6 accounts not %d", len(accounts))
}
i.Accounts = &CancelOrderV2Accounts{
Market: accounts[0],
Bids: accounts[1],
Asks: accounts[2],
OpenOrders: accounts[3],
Owner: accounts[4],
EventQueue: accounts[5],
}
return nil
}
type CancelOrderByClientIdV2Accounts struct {
Market *solana.AccountMeta `text:"linear,notype"` // 0. `[writable]` market
Bids *solana.AccountMeta `text:"linear,notype"` // 1. `[writable]` bids
Asks *solana.AccountMeta `text:"linear,notype"` // 2. `[writable]` asks
OpenOrders *solana.AccountMeta `text:"linear,notype"` // 3. `[writable]` OpenOrders
Owner *solana.AccountMeta `text:"linear,notype"` // 4. `[signer]` the OpenOrders owner
EventQueue *solana.AccountMeta `text:"linear,notype"` // 5. `[writable]` event_q
}
type InstructionCancelOrderByClientIdV2 struct {
ClientID uint64
Accounts *CancelOrderByClientIdV2Accounts `bin:"-"`
}
func (i *InstructionCancelOrderByClientIdV2) SetAccounts(accounts []*solana.AccountMeta) error {
if len(accounts) < 6 {
return fmt.Errorf("insufficient account, Cancel Order By Client Id V2 requires at-least 6 accounts not %d", len(accounts))
}
i.Accounts = &CancelOrderByClientIdV2Accounts{
Market: accounts[0],
Bids: accounts[1],
Asks: accounts[2],
OpenOrders: accounts[3],
Owner: accounts[4],
EventQueue: accounts[5],
}
return nil
}
// InstructionSendTakeAccounts defined from comment in serum-dex contract code, was never able to validate it's correct
type InstructionSendTakeAccounts struct {
Market *solana.AccountMeta `text:"linear,notype"` // 0. `[writable]` market
Bids *solana.AccountMeta `text:"linear,notype"` // 1. `[writable]` bids
Asks *solana.AccountMeta `text:"linear,notype"` // 2. `[writable]` asks
OpenOrders *solana.AccountMeta `text:"linear,notype"` // 3. `[writable]` OpenOrders
Owner *solana.AccountMeta `text:"linear,notype"` // 4. `[]`
}
type InstructionSendTake struct {
Side Side
LimitPrice uint64
MaxCoinQuantity uint64
MaxNativePCQuantityIncludingFees uint64
MinCoinQuantity uint64
MinNativePCQuantity uint64
Limit uint16
Accounts *InstructionSendTakeAccounts `bin:"-"`
}
func (i *InstructionSendTake) SetAccounts(accounts []*solana.AccountMeta) error {
if len(accounts) < 5 {
return fmt.Errorf("insufficient account, Send Take requires at-least 5 accounts not %d", len(accounts))
}
i.Accounts = &InstructionSendTakeAccounts{
Market: accounts[0],
Bids: accounts[1],
Asks: accounts[2],
OpenOrders: accounts[3],
Owner: accounts[4],
}
return nil
}