-
Notifications
You must be signed in to change notification settings - Fork 4
/
InitializeMarket.go
394 lines (348 loc) · 14.2 KB
/
InitializeMarket.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
// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT.
package serumgo
import (
"encoding/binary"
"errors"
ag_binary "github.com/gagliardetto/binary"
ag_solanago "github.com/gagliardetto/solana-go"
ag_format "github.com/gagliardetto/solana-go/text/format"
ag_treeout "github.com/gagliardetto/treeout"
)
// InitializeMarket is the `InitializeMarket` instruction.
type InitializeMarket struct {
Args *InitializeMarketInstruction
// [0] = [WRITE] marketToInitialize
// ··········· the market to initialize
//
// [1] = [WRITE] requestQueue
// ··········· zeroed out request queue
//
// [2] = [WRITE] eventQueue
// ··········· zeroed out event queue
//
// [3] = [WRITE] bids
// ··········· zeroed out bids
//
// [4] = [WRITE] asks
// ··········· zeroed out asks
//
// [5] = [WRITE] splTokenAccountCoin
// ··········· spl-token account for the coin currency
//
// [6] = [WRITE] splTokenAccountPrice
// ··········· spl-token account for the price currency
//
// [7] = [] coinCurrencyMint
// ··········· coin currency Mint
//
// [8] = [] priceCurrencyMint
// ··········· price currency Mint
//
// [9] = [] rentSysvar
// ··········· the rent sysvar
//
// [10] = [] openOrdersMarketAuthority
// ··········· open orders market authority (optional)
//
// [11] = [] pruneAuthority
// ··········· prune authority (optional, requires open orders market authority)
//
// [12] = [] crankAuthority
// ··········· crank authority (optional, requires prune authority)
ag_solanago.AccountMetaSlice `bin:"-"`
}
// NewInitializeMarketInstructionBuilder creates a new `InitializeMarket` instruction builder.
func NewInitializeMarketInstructionBuilder() *InitializeMarket {
nd := &InitializeMarket{
AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 13),
}
return nd
}
// SetArgs sets the "args" parameter.
func (inst *InitializeMarket) SetArgs(args InitializeMarketInstruction) *InitializeMarket {
inst.Args = &args
return inst
}
// SetMarketToInitializeAccount sets the "marketToInitialize" account.
// the market to initialize
func (inst *InitializeMarket) SetMarketToInitializeAccount(marketToInitialize ag_solanago.PublicKey) *InitializeMarket {
inst.AccountMetaSlice[0] = ag_solanago.Meta(marketToInitialize).WRITE()
return inst
}
// GetMarketToInitializeAccount gets the "marketToInitialize" account.
// the market to initialize
func (inst *InitializeMarket) GetMarketToInitializeAccount() *ag_solanago.AccountMeta {
return inst.AccountMetaSlice.Get(0)
}
// SetRequestQueueAccount sets the "requestQueue" account.
// zeroed out request queue
func (inst *InitializeMarket) SetRequestQueueAccount(requestQueue ag_solanago.PublicKey) *InitializeMarket {
inst.AccountMetaSlice[1] = ag_solanago.Meta(requestQueue).WRITE()
return inst
}
// GetRequestQueueAccount gets the "requestQueue" account.
// zeroed out request queue
func (inst *InitializeMarket) GetRequestQueueAccount() *ag_solanago.AccountMeta {
return inst.AccountMetaSlice.Get(1)
}
// SetEventQueueAccount sets the "eventQueue" account.
// zeroed out event queue
func (inst *InitializeMarket) SetEventQueueAccount(eventQueue ag_solanago.PublicKey) *InitializeMarket {
inst.AccountMetaSlice[2] = ag_solanago.Meta(eventQueue).WRITE()
return inst
}
// GetEventQueueAccount gets the "eventQueue" account.
// zeroed out event queue
func (inst *InitializeMarket) GetEventQueueAccount() *ag_solanago.AccountMeta {
return inst.AccountMetaSlice.Get(2)
}
// SetBidsAccount sets the "bids" account.
// zeroed out bids
func (inst *InitializeMarket) SetBidsAccount(bids ag_solanago.PublicKey) *InitializeMarket {
inst.AccountMetaSlice[3] = ag_solanago.Meta(bids).WRITE()
return inst
}
// GetBidsAccount gets the "bids" account.
// zeroed out bids
func (inst *InitializeMarket) GetBidsAccount() *ag_solanago.AccountMeta {
return inst.AccountMetaSlice.Get(3)
}
// SetAsksAccount sets the "asks" account.
// zeroed out asks
func (inst *InitializeMarket) SetAsksAccount(asks ag_solanago.PublicKey) *InitializeMarket {
inst.AccountMetaSlice[4] = ag_solanago.Meta(asks).WRITE()
return inst
}
// GetAsksAccount gets the "asks" account.
// zeroed out asks
func (inst *InitializeMarket) GetAsksAccount() *ag_solanago.AccountMeta {
return inst.AccountMetaSlice.Get(4)
}
// SetSplTokenAccountCoinAccount sets the "splTokenAccountCoin" account.
// spl-token account for the coin currency
func (inst *InitializeMarket) SetSplTokenAccountCoinAccount(splTokenAccountCoin ag_solanago.PublicKey) *InitializeMarket {
inst.AccountMetaSlice[5] = ag_solanago.Meta(splTokenAccountCoin).WRITE()
return inst
}
// GetSplTokenAccountCoinAccount gets the "splTokenAccountCoin" account.
// spl-token account for the coin currency
func (inst *InitializeMarket) GetSplTokenAccountCoinAccount() *ag_solanago.AccountMeta {
return inst.AccountMetaSlice.Get(5)
}
// SetSplTokenAccountPriceAccount sets the "splTokenAccountPrice" account.
// spl-token account for the price currency
func (inst *InitializeMarket) SetSplTokenAccountPriceAccount(splTokenAccountPrice ag_solanago.PublicKey) *InitializeMarket {
inst.AccountMetaSlice[6] = ag_solanago.Meta(splTokenAccountPrice).WRITE()
return inst
}
// GetSplTokenAccountPriceAccount gets the "splTokenAccountPrice" account.
// spl-token account for the price currency
func (inst *InitializeMarket) GetSplTokenAccountPriceAccount() *ag_solanago.AccountMeta {
return inst.AccountMetaSlice.Get(6)
}
// SetCoinCurrencyMintAccount sets the "coinCurrencyMint" account.
// coin currency Mint
func (inst *InitializeMarket) SetCoinCurrencyMintAccount(coinCurrencyMint ag_solanago.PublicKey) *InitializeMarket {
inst.AccountMetaSlice[7] = ag_solanago.Meta(coinCurrencyMint)
return inst
}
// GetCoinCurrencyMintAccount gets the "coinCurrencyMint" account.
// coin currency Mint
func (inst *InitializeMarket) GetCoinCurrencyMintAccount() *ag_solanago.AccountMeta {
return inst.AccountMetaSlice.Get(7)
}
// SetPriceCurrencyMintAccount sets the "priceCurrencyMint" account.
// price currency Mint
func (inst *InitializeMarket) SetPriceCurrencyMintAccount(priceCurrencyMint ag_solanago.PublicKey) *InitializeMarket {
inst.AccountMetaSlice[8] = ag_solanago.Meta(priceCurrencyMint)
return inst
}
// GetPriceCurrencyMintAccount gets the "priceCurrencyMint" account.
// price currency Mint
func (inst *InitializeMarket) GetPriceCurrencyMintAccount() *ag_solanago.AccountMeta {
return inst.AccountMetaSlice.Get(8)
}
// SetRentSysvarAccount sets the "rentSysvar" account.
// the rent sysvar
func (inst *InitializeMarket) SetRentSysvarAccount(rentSysvar ag_solanago.PublicKey) *InitializeMarket {
inst.AccountMetaSlice[9] = ag_solanago.Meta(rentSysvar)
return inst
}
// GetRentSysvarAccount gets the "rentSysvar" account.
// the rent sysvar
func (inst *InitializeMarket) GetRentSysvarAccount() *ag_solanago.AccountMeta {
return inst.AccountMetaSlice.Get(9)
}
// SetOpenOrdersMarketAuthorityAccount sets the "openOrdersMarketAuthority" account.
// open orders market authority (optional)
func (inst *InitializeMarket) SetOpenOrdersMarketAuthorityAccount(openOrdersMarketAuthority ag_solanago.PublicKey) *InitializeMarket {
inst.AccountMetaSlice[10] = ag_solanago.Meta(openOrdersMarketAuthority)
return inst
}
// GetOpenOrdersMarketAuthorityAccount gets the "openOrdersMarketAuthority" account.
// open orders market authority (optional)
func (inst *InitializeMarket) GetOpenOrdersMarketAuthorityAccount() *ag_solanago.AccountMeta {
return inst.AccountMetaSlice.Get(10)
}
// SetPruneAuthorityAccount sets the "pruneAuthority" account.
// prune authority (optional, requires open orders market authority)
func (inst *InitializeMarket) SetPruneAuthorityAccount(pruneAuthority ag_solanago.PublicKey) *InitializeMarket {
inst.AccountMetaSlice[11] = ag_solanago.Meta(pruneAuthority)
return inst
}
// GetPruneAuthorityAccount gets the "pruneAuthority" account.
// prune authority (optional, requires open orders market authority)
func (inst *InitializeMarket) GetPruneAuthorityAccount() *ag_solanago.AccountMeta {
return inst.AccountMetaSlice.Get(11)
}
// SetCrankAuthorityAccount sets the "crankAuthority" account.
// crank authority (optional, requires prune authority)
func (inst *InitializeMarket) SetCrankAuthorityAccount(crankAuthority ag_solanago.PublicKey) *InitializeMarket {
inst.AccountMetaSlice[12] = ag_solanago.Meta(crankAuthority)
return inst
}
// GetCrankAuthorityAccount gets the "crankAuthority" account.
// crank authority (optional, requires prune authority)
func (inst *InitializeMarket) GetCrankAuthorityAccount() *ag_solanago.AccountMeta {
return inst.AccountMetaSlice.Get(12)
}
func (inst InitializeMarket) Build() *Instruction {
return &Instruction{BaseVariant: ag_binary.BaseVariant{
Impl: inst,
TypeID: ag_binary.TypeIDFromUint32(Instruction_InitializeMarket, binary.LittleEndian),
}}
}
// ValidateAndBuild validates the instruction parameters and accounts;
// if there is a validation error, it returns the error.
// Otherwise, it builds and returns the instruction.
func (inst InitializeMarket) ValidateAndBuild() (*Instruction, error) {
if err := inst.Validate(); err != nil {
return nil, err
}
return inst.Build(), nil
}
func (inst *InitializeMarket) Validate() error {
// Check whether all (required) parameters are set:
{
if inst.Args == nil {
return errors.New("Args parameter is not set")
}
}
// Check whether all (required) accounts are set:
{
if inst.AccountMetaSlice[0] == nil {
return errors.New("accounts.MarketToInitialize is not set")
}
if inst.AccountMetaSlice[1] == nil {
return errors.New("accounts.RequestQueue is not set")
}
if inst.AccountMetaSlice[2] == nil {
return errors.New("accounts.EventQueue is not set")
}
if inst.AccountMetaSlice[3] == nil {
return errors.New("accounts.Bids is not set")
}
if inst.AccountMetaSlice[4] == nil {
return errors.New("accounts.Asks is not set")
}
if inst.AccountMetaSlice[5] == nil {
return errors.New("accounts.SplTokenAccountCoin is not set")
}
if inst.AccountMetaSlice[6] == nil {
return errors.New("accounts.SplTokenAccountPrice is not set")
}
if inst.AccountMetaSlice[7] == nil {
return errors.New("accounts.CoinCurrencyMint is not set")
}
if inst.AccountMetaSlice[8] == nil {
return errors.New("accounts.PriceCurrencyMint is not set")
}
if inst.AccountMetaSlice[9] == nil {
return errors.New("accounts.RentSysvar is not set")
}
// [10] = OpenOrdersMarketAuthority is optional
// [11] = PruneAuthority is optional
// [12] = CrankAuthority is optional
}
return nil
}
func (inst *InitializeMarket) EncodeToTree(parent ag_treeout.Branches) {
parent.Child(ag_format.Program(ProgramName, ProgramID)).
//
ParentFunc(func(programBranch ag_treeout.Branches) {
programBranch.Child(ag_format.Instruction("InitializeMarket")).
//
ParentFunc(func(instructionBranch ag_treeout.Branches) {
// Parameters of the instruction:
instructionBranch.Child("Params[len=1]").ParentFunc(func(paramsBranch ag_treeout.Branches) {
paramsBranch.Child(ag_format.Param("Args", *inst.Args))
})
// Accounts of the instruction:
instructionBranch.Child("Accounts[len=13]").ParentFunc(func(accountsBranch ag_treeout.Branches) {
accountsBranch.Child(ag_format.Meta(" marketToInitialize", inst.AccountMetaSlice.Get(0)))
accountsBranch.Child(ag_format.Meta(" requestQueue", inst.AccountMetaSlice.Get(1)))
accountsBranch.Child(ag_format.Meta(" eventQueue", inst.AccountMetaSlice.Get(2)))
accountsBranch.Child(ag_format.Meta(" bids", inst.AccountMetaSlice.Get(3)))
accountsBranch.Child(ag_format.Meta(" asks", inst.AccountMetaSlice.Get(4)))
accountsBranch.Child(ag_format.Meta(" splTokenAccountCoin", inst.AccountMetaSlice.Get(5)))
accountsBranch.Child(ag_format.Meta(" splTokenAccountPrice", inst.AccountMetaSlice.Get(6)))
accountsBranch.Child(ag_format.Meta(" coinCurrencyMint", inst.AccountMetaSlice.Get(7)))
accountsBranch.Child(ag_format.Meta(" priceCurrencyMint", inst.AccountMetaSlice.Get(8)))
accountsBranch.Child(ag_format.Meta(" rentSysvar", inst.AccountMetaSlice.Get(9)))
accountsBranch.Child(ag_format.Meta("openOrdersMarketAuthority", inst.AccountMetaSlice.Get(10)))
accountsBranch.Child(ag_format.Meta(" pruneAuthority", inst.AccountMetaSlice.Get(11)))
accountsBranch.Child(ag_format.Meta(" crankAuthority", inst.AccountMetaSlice.Get(12)))
})
})
})
}
func (obj InitializeMarket) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) {
// Serialize `Args` param:
err = encoder.Encode(obj.Args)
if err != nil {
return err
}
return nil
}
func (obj *InitializeMarket) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) {
// Deserialize `Args`:
err = decoder.Decode(&obj.Args)
if err != nil {
return err
}
return nil
}
// NewInitializeMarketInstruction declares a new InitializeMarket instruction with the provided parameters and accounts.
func NewInitializeMarketInstruction(
// Parameters:
args InitializeMarketInstruction,
// Accounts:
marketToInitialize ag_solanago.PublicKey,
requestQueue ag_solanago.PublicKey,
eventQueue ag_solanago.PublicKey,
bids ag_solanago.PublicKey,
asks ag_solanago.PublicKey,
splTokenAccountCoin ag_solanago.PublicKey,
splTokenAccountPrice ag_solanago.PublicKey,
coinCurrencyMint ag_solanago.PublicKey,
priceCurrencyMint ag_solanago.PublicKey,
rentSysvar ag_solanago.PublicKey,
openOrdersMarketAuthority ag_solanago.PublicKey,
pruneAuthority ag_solanago.PublicKey,
crankAuthority ag_solanago.PublicKey) *InitializeMarket {
return NewInitializeMarketInstructionBuilder().
SetArgs(args).
SetMarketToInitializeAccount(marketToInitialize).
SetRequestQueueAccount(requestQueue).
SetEventQueueAccount(eventQueue).
SetBidsAccount(bids).
SetAsksAccount(asks).
SetSplTokenAccountCoinAccount(splTokenAccountCoin).
SetSplTokenAccountPriceAccount(splTokenAccountPrice).
SetCoinCurrencyMintAccount(coinCurrencyMint).
SetPriceCurrencyMintAccount(priceCurrencyMint).
SetRentSysvarAccount(rentSysvar).
SetOpenOrdersMarketAuthorityAccount(openOrdersMarketAuthority).
SetPruneAuthorityAccount(pruneAuthority).
SetCrankAuthorityAccount(crankAuthority)
}