-
Notifications
You must be signed in to change notification settings - Fork 0
/
instructions.go
285 lines (242 loc) · 8.5 KB
/
instructions.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
// Code generated by https://github.com/dcaf-mocha/anchor-go. DO NOT EDIT.
package whirlpool
import (
"bytes"
"fmt"
ag_spew "github.com/davecgh/go-spew/spew"
ag_binary "github.com/gagliardetto/binary"
ag_solanago "github.com/gagliardetto/solana-go"
ag_text "github.com/gagliardetto/solana-go/text"
ag_treeout "github.com/gagliardetto/treeout"
)
var ProgramID ag_solanago.PublicKey
func SetProgramID(pubkey ag_solanago.PublicKey) {
ProgramID = pubkey
ag_solanago.RegisterInstructionDecoder(ProgramID, registryDecodeInstruction)
}
const ProgramName = "Whirlpool"
func init() {
if !ProgramID.IsZero() {
ag_solanago.RegisterInstructionDecoder(ProgramID, registryDecodeInstruction)
}
}
var (
Instruction_InitializeConfig = ag_binary.TypeID([8]byte{208, 127, 21, 1, 194, 190, 196, 70})
Instruction_InitializePool = ag_binary.TypeID([8]byte{95, 180, 10, 172, 84, 174, 232, 40})
Instruction_InitializeTickArray = ag_binary.TypeID([8]byte{11, 188, 193, 214, 141, 91, 149, 184})
Instruction_InitializeFeeTier = ag_binary.TypeID([8]byte{183, 74, 156, 160, 112, 2, 42, 30})
Instruction_InitializeReward = ag_binary.TypeID([8]byte{95, 135, 192, 196, 242, 129, 230, 68})
Instruction_SetRewardEmissions = ag_binary.TypeID([8]byte{13, 197, 86, 168, 109, 176, 27, 244})
Instruction_OpenPosition = ag_binary.TypeID([8]byte{135, 128, 47, 77, 15, 152, 240, 49})
Instruction_OpenPositionWithMetadata = ag_binary.TypeID([8]byte{242, 29, 134, 48, 58, 110, 14, 60})
Instruction_IncreaseLiquidity = ag_binary.TypeID([8]byte{46, 156, 243, 118, 13, 205, 251, 178})
Instruction_DecreaseLiquidity = ag_binary.TypeID([8]byte{160, 38, 208, 111, 104, 91, 44, 1})
Instruction_UpdateFeesAndRewards = ag_binary.TypeID([8]byte{154, 230, 250, 13, 236, 209, 75, 223})
Instruction_CollectFees = ag_binary.TypeID([8]byte{164, 152, 207, 99, 30, 186, 19, 182})
Instruction_CollectReward = ag_binary.TypeID([8]byte{70, 5, 132, 87, 86, 235, 177, 34})
Instruction_CollectProtocolFees = ag_binary.TypeID([8]byte{22, 67, 23, 98, 150, 178, 70, 220})
Instruction_Swap = ag_binary.TypeID([8]byte{248, 198, 158, 145, 225, 117, 135, 200})
Instruction_ClosePosition = ag_binary.TypeID([8]byte{123, 134, 81, 0, 49, 68, 98, 98})
Instruction_SetDefaultFeeRate = ag_binary.TypeID([8]byte{118, 215, 214, 157, 182, 229, 208, 228})
Instruction_SetDefaultProtocolFeeRate = ag_binary.TypeID([8]byte{107, 205, 249, 226, 151, 35, 86, 0})
Instruction_SetFeeRate = ag_binary.TypeID([8]byte{53, 243, 137, 65, 8, 140, 158, 6})
Instruction_SetProtocolFeeRate = ag_binary.TypeID([8]byte{95, 7, 4, 50, 154, 79, 156, 131})
Instruction_SetFeeAuthority = ag_binary.TypeID([8]byte{31, 1, 50, 87, 237, 101, 97, 132})
Instruction_SetCollectProtocolFeesAuthority = ag_binary.TypeID([8]byte{34, 150, 93, 244, 139, 225, 233, 67})
Instruction_SetRewardAuthority = ag_binary.TypeID([8]byte{34, 39, 183, 252, 83, 28, 85, 127})
Instruction_SetRewardAuthorityBySuperAuthority = ag_binary.TypeID([8]byte{240, 154, 201, 198, 148, 93, 56, 25})
Instruction_SetRewardEmissionsSuperAuthority = ag_binary.TypeID([8]byte{207, 5, 200, 209, 122, 56, 82, 183})
)
// InstructionIDToName returns the name of the instruction given its ID.
func InstructionIDToName(id ag_binary.TypeID) string {
switch id {
case Instruction_InitializeConfig:
return "InitializeConfig"
case Instruction_InitializePool:
return "InitializePool"
case Instruction_InitializeTickArray:
return "InitializeTickArray"
case Instruction_InitializeFeeTier:
return "InitializeFeeTier"
case Instruction_InitializeReward:
return "InitializeReward"
case Instruction_SetRewardEmissions:
return "SetRewardEmissions"
case Instruction_OpenPosition:
return "OpenPosition"
case Instruction_OpenPositionWithMetadata:
return "OpenPositionWithMetadata"
case Instruction_IncreaseLiquidity:
return "IncreaseLiquidity"
case Instruction_DecreaseLiquidity:
return "DecreaseLiquidity"
case Instruction_UpdateFeesAndRewards:
return "UpdateFeesAndRewards"
case Instruction_CollectFees:
return "CollectFees"
case Instruction_CollectReward:
return "CollectReward"
case Instruction_CollectProtocolFees:
return "CollectProtocolFees"
case Instruction_Swap:
return "Swap"
case Instruction_ClosePosition:
return "ClosePosition"
case Instruction_SetDefaultFeeRate:
return "SetDefaultFeeRate"
case Instruction_SetDefaultProtocolFeeRate:
return "SetDefaultProtocolFeeRate"
case Instruction_SetFeeRate:
return "SetFeeRate"
case Instruction_SetProtocolFeeRate:
return "SetProtocolFeeRate"
case Instruction_SetFeeAuthority:
return "SetFeeAuthority"
case Instruction_SetCollectProtocolFeesAuthority:
return "SetCollectProtocolFeesAuthority"
case Instruction_SetRewardAuthority:
return "SetRewardAuthority"
case Instruction_SetRewardAuthorityBySuperAuthority:
return "SetRewardAuthorityBySuperAuthority"
case Instruction_SetRewardEmissionsSuperAuthority:
return "SetRewardEmissionsSuperAuthority"
default:
return ""
}
}
type Instruction struct {
ag_binary.BaseVariant
}
func (inst *Instruction) EncodeToTree(parent ag_treeout.Branches) {
if enToTree, ok := inst.Impl.(ag_text.EncodableToTree); ok {
enToTree.EncodeToTree(parent)
} else {
parent.Child(ag_spew.Sdump(inst))
}
}
var InstructionImplDef = ag_binary.NewVariantDefinition(
ag_binary.AnchorTypeIDEncoding,
[]ag_binary.VariantType{
{
"initialize_config", (*InitializeConfig)(nil),
},
{
"initialize_pool", (*InitializePool)(nil),
},
{
"initialize_tick_array", (*InitializeTickArray)(nil),
},
{
"initialize_fee_tier", (*InitializeFeeTier)(nil),
},
{
"initialize_reward", (*InitializeReward)(nil),
},
{
"set_reward_emissions", (*SetRewardEmissions)(nil),
},
{
"open_position", (*OpenPosition)(nil),
},
{
"open_position_with_metadata", (*OpenPositionWithMetadata)(nil),
},
{
"increase_liquidity", (*IncreaseLiquidity)(nil),
},
{
"decrease_liquidity", (*DecreaseLiquidity)(nil),
},
{
"update_fees_and_rewards", (*UpdateFeesAndRewards)(nil),
},
{
"collect_fees", (*CollectFees)(nil),
},
{
"collect_reward", (*CollectReward)(nil),
},
{
"collect_protocol_fees", (*CollectProtocolFees)(nil),
},
{
"swap", (*Swap)(nil),
},
{
"close_position", (*ClosePosition)(nil),
},
{
"set_default_fee_rate", (*SetDefaultFeeRate)(nil),
},
{
"set_default_protocol_fee_rate", (*SetDefaultProtocolFeeRate)(nil),
},
{
"set_fee_rate", (*SetFeeRate)(nil),
},
{
"set_protocol_fee_rate", (*SetProtocolFeeRate)(nil),
},
{
"set_fee_authority", (*SetFeeAuthority)(nil),
},
{
"set_collect_protocol_fees_authority", (*SetCollectProtocolFeesAuthority)(nil),
},
{
"set_reward_authority", (*SetRewardAuthority)(nil),
},
{
"set_reward_authority_by_super_authority", (*SetRewardAuthorityBySuperAuthority)(nil),
},
{
"set_reward_emissions_super_authority", (*SetRewardEmissionsSuperAuthority)(nil),
},
},
)
func (inst *Instruction) ProgramID() ag_solanago.PublicKey {
return ProgramID
}
func (inst *Instruction) Accounts() (out []*ag_solanago.AccountMeta) {
return inst.Impl.(ag_solanago.AccountsGettable).GetAccounts()
}
func (inst *Instruction) Data() ([]byte, error) {
buf := new(bytes.Buffer)
if err := ag_binary.NewBorshEncoder(buf).Encode(inst); err != nil {
return nil, fmt.Errorf("unable to encode instruction: %w", err)
}
return buf.Bytes(), nil
}
func (inst *Instruction) TextEncode(encoder *ag_text.Encoder, option *ag_text.Option) error {
return encoder.Encode(inst.Impl, option)
}
func (inst *Instruction) UnmarshalWithDecoder(decoder *ag_binary.Decoder) error {
return inst.BaseVariant.UnmarshalBinaryVariant(decoder, InstructionImplDef)
}
func (inst *Instruction) MarshalWithEncoder(encoder *ag_binary.Encoder) error {
err := encoder.WriteBytes(inst.TypeID.Bytes(), false)
if err != nil {
return fmt.Errorf("unable to write variant type: %w", err)
}
return encoder.Encode(inst.Impl)
}
func registryDecodeInstruction(accounts []*ag_solanago.AccountMeta, data []byte) (interface{}, error) {
inst, err := DecodeInstruction(accounts, data)
if err != nil {
return nil, err
}
return inst, nil
}
func DecodeInstruction(accounts []*ag_solanago.AccountMeta, data []byte) (*Instruction, error) {
inst := new(Instruction)
if err := ag_binary.NewBorshDecoder(data).Decode(inst); err != nil {
return nil, fmt.Errorf("unable to decode instruction: %w", err)
}
if v, ok := inst.Impl.(ag_solanago.AccountsSettable); ok {
err := v.SetAccounts(accounts)
if err != nil {
return nil, fmt.Errorf("unable to set accounts for instruction: %w", err)
}
}
return inst, nil
}