github.com/diadata-org/diadata@v1.4.593/pkg/dia/scraper/exchange-scrapers/orca/whirlpool/Swap.go (about) 1 // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. 2 3 package whirlpool 4 5 import ( 6 "errors" 7 ag_binary "github.com/gagliardetto/binary" 8 ag_solanago "github.com/gagliardetto/solana-go" 9 ag_format "github.com/gagliardetto/solana-go/text/format" 10 ag_treeout "github.com/gagliardetto/treeout" 11 ) 12 13 // Swap is the `swap` instruction. 14 type Swap struct { 15 Amount *uint64 16 OtherAmountThreshold *uint64 17 SqrtPriceLimit *ag_binary.Uint128 18 AmountSpecifiedIsInput *bool 19 AToB *bool 20 21 // [0] = [] tokenProgram 22 // 23 // [1] = [SIGNER] tokenAuthority 24 // 25 // [2] = [WRITE] whirlpool 26 // 27 // [3] = [WRITE] tokenOwnerAccountA 28 // 29 // [4] = [WRITE] tokenVaultA 30 // 31 // [5] = [WRITE] tokenOwnerAccountB 32 // 33 // [6] = [WRITE] tokenVaultB 34 // 35 // [7] = [WRITE] tickArray0 36 // 37 // [8] = [WRITE] tickArray1 38 // 39 // [9] = [WRITE] tickArray2 40 // 41 // [10] = [] oracle 42 ag_solanago.AccountMetaSlice `bin:"-"` 43 } 44 45 // NewSwapInstructionBuilder creates a new `Swap` instruction builder. 46 func NewSwapInstructionBuilder() *Swap { 47 nd := &Swap{ 48 AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 11), 49 } 50 return nd 51 } 52 53 // SetAmount sets the "amount" parameter. 54 func (inst *Swap) SetAmount(amount uint64) *Swap { 55 inst.Amount = &amount 56 return inst 57 } 58 59 // SetOtherAmountThreshold sets the "otherAmountThreshold" parameter. 60 func (inst *Swap) SetOtherAmountThreshold(otherAmountThreshold uint64) *Swap { 61 inst.OtherAmountThreshold = &otherAmountThreshold 62 return inst 63 } 64 65 // SetSqrtPriceLimit sets the "sqrtPriceLimit" parameter. 66 func (inst *Swap) SetSqrtPriceLimit(sqrtPriceLimit ag_binary.Uint128) *Swap { 67 inst.SqrtPriceLimit = &sqrtPriceLimit 68 return inst 69 } 70 71 // SetAmountSpecifiedIsInput sets the "amountSpecifiedIsInput" parameter. 72 func (inst *Swap) SetAmountSpecifiedIsInput(amountSpecifiedIsInput bool) *Swap { 73 inst.AmountSpecifiedIsInput = &amountSpecifiedIsInput 74 return inst 75 } 76 77 // SetAToB sets the "aToB" parameter. 78 func (inst *Swap) SetAToB(aToB bool) *Swap { 79 inst.AToB = &aToB 80 return inst 81 } 82 83 // SetTokenProgramAccount sets the "tokenProgram" account. 84 func (inst *Swap) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *Swap { 85 inst.AccountMetaSlice[0] = ag_solanago.Meta(tokenProgram) 86 return inst 87 } 88 89 // GetTokenProgramAccount gets the "tokenProgram" account. 90 func (inst *Swap) GetTokenProgramAccount() *ag_solanago.AccountMeta { 91 return inst.AccountMetaSlice.Get(0) 92 } 93 94 // SetTokenAuthorityAccount sets the "tokenAuthority" account. 95 func (inst *Swap) SetTokenAuthorityAccount(tokenAuthority ag_solanago.PublicKey) *Swap { 96 inst.AccountMetaSlice[1] = ag_solanago.Meta(tokenAuthority).SIGNER() 97 return inst 98 } 99 100 // GetTokenAuthorityAccount gets the "tokenAuthority" account. 101 func (inst *Swap) GetTokenAuthorityAccount() *ag_solanago.AccountMeta { 102 return inst.AccountMetaSlice.Get(1) 103 } 104 105 // SetWhirlpoolAccount sets the "whirlpool" account. 106 func (inst *Swap) SetWhirlpoolAccount(whirlpool ag_solanago.PublicKey) *Swap { 107 inst.AccountMetaSlice[2] = ag_solanago.Meta(whirlpool).WRITE() 108 return inst 109 } 110 111 // GetWhirlpoolAccount gets the "whirlpool" account. 112 func (inst *Swap) GetWhirlpoolAccount() *ag_solanago.AccountMeta { 113 return inst.AccountMetaSlice.Get(2) 114 } 115 116 // SetTokenOwnerAccountAAccount sets the "tokenOwnerAccountA" account. 117 func (inst *Swap) SetTokenOwnerAccountAAccount(tokenOwnerAccountA ag_solanago.PublicKey) *Swap { 118 inst.AccountMetaSlice[3] = ag_solanago.Meta(tokenOwnerAccountA).WRITE() 119 return inst 120 } 121 122 // GetTokenOwnerAccountAAccount gets the "tokenOwnerAccountA" account. 123 func (inst *Swap) GetTokenOwnerAccountAAccount() *ag_solanago.AccountMeta { 124 return inst.AccountMetaSlice.Get(3) 125 } 126 127 // SetTokenVaultAAccount sets the "tokenVaultA" account. 128 func (inst *Swap) SetTokenVaultAAccount(tokenVaultA ag_solanago.PublicKey) *Swap { 129 inst.AccountMetaSlice[4] = ag_solanago.Meta(tokenVaultA).WRITE() 130 return inst 131 } 132 133 // GetTokenVaultAAccount gets the "tokenVaultA" account. 134 func (inst *Swap) GetTokenVaultAAccount() *ag_solanago.AccountMeta { 135 return inst.AccountMetaSlice.Get(4) 136 } 137 138 // SetTokenOwnerAccountBAccount sets the "tokenOwnerAccountB" account. 139 func (inst *Swap) SetTokenOwnerAccountBAccount(tokenOwnerAccountB ag_solanago.PublicKey) *Swap { 140 inst.AccountMetaSlice[5] = ag_solanago.Meta(tokenOwnerAccountB).WRITE() 141 return inst 142 } 143 144 // GetTokenOwnerAccountBAccount gets the "tokenOwnerAccountB" account. 145 func (inst *Swap) GetTokenOwnerAccountBAccount() *ag_solanago.AccountMeta { 146 return inst.AccountMetaSlice.Get(5) 147 } 148 149 // SetTokenVaultBAccount sets the "tokenVaultB" account. 150 func (inst *Swap) SetTokenVaultBAccount(tokenVaultB ag_solanago.PublicKey) *Swap { 151 inst.AccountMetaSlice[6] = ag_solanago.Meta(tokenVaultB).WRITE() 152 return inst 153 } 154 155 // GetTokenVaultBAccount gets the "tokenVaultB" account. 156 func (inst *Swap) GetTokenVaultBAccount() *ag_solanago.AccountMeta { 157 return inst.AccountMetaSlice.Get(6) 158 } 159 160 // SetTickArray0Account sets the "tickArray0" account. 161 func (inst *Swap) SetTickArray0Account(tickArray0 ag_solanago.PublicKey) *Swap { 162 inst.AccountMetaSlice[7] = ag_solanago.Meta(tickArray0).WRITE() 163 return inst 164 } 165 166 // GetTickArray0Account gets the "tickArray0" account. 167 func (inst *Swap) GetTickArray0Account() *ag_solanago.AccountMeta { 168 return inst.AccountMetaSlice.Get(7) 169 } 170 171 // SetTickArray1Account sets the "tickArray1" account. 172 func (inst *Swap) SetTickArray1Account(tickArray1 ag_solanago.PublicKey) *Swap { 173 inst.AccountMetaSlice[8] = ag_solanago.Meta(tickArray1).WRITE() 174 return inst 175 } 176 177 // GetTickArray1Account gets the "tickArray1" account. 178 func (inst *Swap) GetTickArray1Account() *ag_solanago.AccountMeta { 179 return inst.AccountMetaSlice.Get(8) 180 } 181 182 // SetTickArray2Account sets the "tickArray2" account. 183 func (inst *Swap) SetTickArray2Account(tickArray2 ag_solanago.PublicKey) *Swap { 184 inst.AccountMetaSlice[9] = ag_solanago.Meta(tickArray2).WRITE() 185 return inst 186 } 187 188 // GetTickArray2Account gets the "tickArray2" account. 189 func (inst *Swap) GetTickArray2Account() *ag_solanago.AccountMeta { 190 return inst.AccountMetaSlice.Get(9) 191 } 192 193 // SetOracleAccount sets the "oracle" account. 194 func (inst *Swap) SetOracleAccount(oracle ag_solanago.PublicKey) *Swap { 195 inst.AccountMetaSlice[10] = ag_solanago.Meta(oracle) 196 return inst 197 } 198 199 // GetOracleAccount gets the "oracle" account. 200 func (inst *Swap) GetOracleAccount() *ag_solanago.AccountMeta { 201 return inst.AccountMetaSlice.Get(10) 202 } 203 204 func (inst Swap) Build() *Instruction { 205 return &Instruction{BaseVariant: ag_binary.BaseVariant{ 206 Impl: inst, 207 TypeID: Instruction_Swap, 208 }} 209 } 210 211 // ValidateAndBuild validates the instruction parameters and accounts; 212 // if there is a validation error, it returns the error. 213 // Otherwise, it builds and returns the instruction. 214 func (inst Swap) ValidateAndBuild() (*Instruction, error) { 215 if err := inst.Validate(); err != nil { 216 return nil, err 217 } 218 return inst.Build(), nil 219 } 220 221 func (inst *Swap) Validate() error { 222 // Check whether all (required) parameters are set: 223 { 224 if inst.Amount == nil { 225 return errors.New("Amount parameter is not set") 226 } 227 if inst.OtherAmountThreshold == nil { 228 return errors.New("OtherAmountThreshold parameter is not set") 229 } 230 if inst.SqrtPriceLimit == nil { 231 return errors.New("SqrtPriceLimit parameter is not set") 232 } 233 if inst.AmountSpecifiedIsInput == nil { 234 return errors.New("AmountSpecifiedIsInput parameter is not set") 235 } 236 if inst.AToB == nil { 237 return errors.New("AToB parameter is not set") 238 } 239 } 240 241 // Check whether all (required) accounts are set: 242 { 243 if inst.AccountMetaSlice[0] == nil { 244 return errors.New("accounts.TokenProgram is not set") 245 } 246 if inst.AccountMetaSlice[1] == nil { 247 return errors.New("accounts.TokenAuthority is not set") 248 } 249 if inst.AccountMetaSlice[2] == nil { 250 return errors.New("accounts.Whirlpool is not set") 251 } 252 if inst.AccountMetaSlice[3] == nil { 253 return errors.New("accounts.TokenOwnerAccountA is not set") 254 } 255 if inst.AccountMetaSlice[4] == nil { 256 return errors.New("accounts.TokenVaultA is not set") 257 } 258 if inst.AccountMetaSlice[5] == nil { 259 return errors.New("accounts.TokenOwnerAccountB is not set") 260 } 261 if inst.AccountMetaSlice[6] == nil { 262 return errors.New("accounts.TokenVaultB is not set") 263 } 264 if inst.AccountMetaSlice[7] == nil { 265 return errors.New("accounts.TickArray0 is not set") 266 } 267 if inst.AccountMetaSlice[8] == nil { 268 return errors.New("accounts.TickArray1 is not set") 269 } 270 if inst.AccountMetaSlice[9] == nil { 271 return errors.New("accounts.TickArray2 is not set") 272 } 273 if inst.AccountMetaSlice[10] == nil { 274 return errors.New("accounts.Oracle is not set") 275 } 276 } 277 return nil 278 } 279 280 func (inst *Swap) EncodeToTree(parent ag_treeout.Branches) { 281 parent.Child(ag_format.Program(ProgramName, ProgramID)). 282 // 283 ParentFunc(func(programBranch ag_treeout.Branches) { 284 programBranch.Child(ag_format.Instruction("Swap")). 285 // 286 ParentFunc(func(instructionBranch ag_treeout.Branches) { 287 288 // Parameters of the instruction: 289 instructionBranch.Child("Params[len=5]").ParentFunc(func(paramsBranch ag_treeout.Branches) { 290 paramsBranch.Child(ag_format.Param(" Amount", *inst.Amount)) 291 paramsBranch.Child(ag_format.Param(" OtherAmountThreshold", *inst.OtherAmountThreshold)) 292 paramsBranch.Child(ag_format.Param(" SqrtPriceLimit", *inst.SqrtPriceLimit)) 293 paramsBranch.Child(ag_format.Param("AmountSpecifiedIsInput", *inst.AmountSpecifiedIsInput)) 294 paramsBranch.Child(ag_format.Param(" AToB", *inst.AToB)) 295 }) 296 297 // Accounts of the instruction: 298 instructionBranch.Child("Accounts[len=11]").ParentFunc(func(accountsBranch ag_treeout.Branches) { 299 accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(0))) 300 accountsBranch.Child(ag_format.Meta(" tokenAuthority", inst.AccountMetaSlice.Get(1))) 301 accountsBranch.Child(ag_format.Meta(" whirlpool", inst.AccountMetaSlice.Get(2))) 302 accountsBranch.Child(ag_format.Meta("tokenOwnerAccountA", inst.AccountMetaSlice.Get(3))) 303 accountsBranch.Child(ag_format.Meta(" tokenVaultA", inst.AccountMetaSlice.Get(4))) 304 accountsBranch.Child(ag_format.Meta("tokenOwnerAccountB", inst.AccountMetaSlice.Get(5))) 305 accountsBranch.Child(ag_format.Meta(" tokenVaultB", inst.AccountMetaSlice.Get(6))) 306 accountsBranch.Child(ag_format.Meta(" tickArray0", inst.AccountMetaSlice.Get(7))) 307 accountsBranch.Child(ag_format.Meta(" tickArray1", inst.AccountMetaSlice.Get(8))) 308 accountsBranch.Child(ag_format.Meta(" tickArray2", inst.AccountMetaSlice.Get(9))) 309 accountsBranch.Child(ag_format.Meta(" oracle", inst.AccountMetaSlice.Get(10))) 310 }) 311 }) 312 }) 313 } 314 315 func (obj Swap) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { 316 // Serialize `Amount` param: 317 err = encoder.Encode(obj.Amount) 318 if err != nil { 319 return err 320 } 321 // Serialize `OtherAmountThreshold` param: 322 err = encoder.Encode(obj.OtherAmountThreshold) 323 if err != nil { 324 return err 325 } 326 // Serialize `SqrtPriceLimit` param: 327 err = encoder.Encode(obj.SqrtPriceLimit) 328 if err != nil { 329 return err 330 } 331 // Serialize `AmountSpecifiedIsInput` param: 332 err = encoder.Encode(obj.AmountSpecifiedIsInput) 333 if err != nil { 334 return err 335 } 336 // Serialize `AToB` param: 337 err = encoder.Encode(obj.AToB) 338 if err != nil { 339 return err 340 } 341 return nil 342 } 343 func (obj *Swap) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { 344 // Deserialize `Amount`: 345 err = decoder.Decode(&obj.Amount) 346 if err != nil { 347 return err 348 } 349 // Deserialize `OtherAmountThreshold`: 350 err = decoder.Decode(&obj.OtherAmountThreshold) 351 if err != nil { 352 return err 353 } 354 // Deserialize `SqrtPriceLimit`: 355 err = decoder.Decode(&obj.SqrtPriceLimit) 356 if err != nil { 357 return err 358 } 359 // Deserialize `AmountSpecifiedIsInput`: 360 err = decoder.Decode(&obj.AmountSpecifiedIsInput) 361 if err != nil { 362 return err 363 } 364 // Deserialize `AToB`: 365 err = decoder.Decode(&obj.AToB) 366 if err != nil { 367 return err 368 } 369 return nil 370 } 371 372 // NewSwapInstruction declares a new Swap instruction with the provided parameters and accounts. 373 func NewSwapInstruction( 374 // Parameters: 375 amount uint64, 376 otherAmountThreshold uint64, 377 sqrtPriceLimit ag_binary.Uint128, 378 amountSpecifiedIsInput bool, 379 aToB bool, 380 // Accounts: 381 tokenProgram ag_solanago.PublicKey, 382 tokenAuthority ag_solanago.PublicKey, 383 whirlpool ag_solanago.PublicKey, 384 tokenOwnerAccountA ag_solanago.PublicKey, 385 tokenVaultA ag_solanago.PublicKey, 386 tokenOwnerAccountB ag_solanago.PublicKey, 387 tokenVaultB ag_solanago.PublicKey, 388 tickArray0 ag_solanago.PublicKey, 389 tickArray1 ag_solanago.PublicKey, 390 tickArray2 ag_solanago.PublicKey, 391 oracle ag_solanago.PublicKey) *Swap { 392 return NewSwapInstructionBuilder(). 393 SetAmount(amount). 394 SetOtherAmountThreshold(otherAmountThreshold). 395 SetSqrtPriceLimit(sqrtPriceLimit). 396 SetAmountSpecifiedIsInput(amountSpecifiedIsInput). 397 SetAToB(aToB). 398 SetTokenProgramAccount(tokenProgram). 399 SetTokenAuthorityAccount(tokenAuthority). 400 SetWhirlpoolAccount(whirlpool). 401 SetTokenOwnerAccountAAccount(tokenOwnerAccountA). 402 SetTokenVaultAAccount(tokenVaultA). 403 SetTokenOwnerAccountBAccount(tokenOwnerAccountB). 404 SetTokenVaultBAccount(tokenVaultB). 405 SetTickArray0Account(tickArray0). 406 SetTickArray1Account(tickArray1). 407 SetTickArray2Account(tickArray2). 408 SetOracleAccount(oracle) 409 }