github.com/diadata-org/diadata@v1.4.593/pkg/dia/scraper/exchange-scrapers/orca/whirlpool/DecreaseLiquidity.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 // DecreaseLiquidity is the `decreaseLiquidity` instruction. 14 type DecreaseLiquidity struct { 15 LiquidityAmount *ag_binary.Uint128 16 TokenMinA *uint64 17 TokenMinB *uint64 18 19 // [0] = [WRITE] whirlpool 20 // 21 // [1] = [] tokenProgram 22 // 23 // [2] = [SIGNER] positionAuthority 24 // 25 // [3] = [WRITE] position 26 // 27 // [4] = [] positionTokenAccount 28 // 29 // [5] = [WRITE] tokenOwnerAccountA 30 // 31 // [6] = [WRITE] tokenOwnerAccountB 32 // 33 // [7] = [WRITE] tokenVaultA 34 // 35 // [8] = [WRITE] tokenVaultB 36 // 37 // [9] = [WRITE] tickArrayLower 38 // 39 // [10] = [WRITE] tickArrayUpper 40 ag_solanago.AccountMetaSlice `bin:"-"` 41 } 42 43 // NewDecreaseLiquidityInstructionBuilder creates a new `DecreaseLiquidity` instruction builder. 44 func NewDecreaseLiquidityInstructionBuilder() *DecreaseLiquidity { 45 nd := &DecreaseLiquidity{ 46 AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 11), 47 } 48 return nd 49 } 50 51 // SetLiquidityAmount sets the "liquidityAmount" parameter. 52 func (inst *DecreaseLiquidity) SetLiquidityAmount(liquidityAmount ag_binary.Uint128) *DecreaseLiquidity { 53 inst.LiquidityAmount = &liquidityAmount 54 return inst 55 } 56 57 // SetTokenMinA sets the "tokenMinA" parameter. 58 func (inst *DecreaseLiquidity) SetTokenMinA(tokenMinA uint64) *DecreaseLiquidity { 59 inst.TokenMinA = &tokenMinA 60 return inst 61 } 62 63 // SetTokenMinB sets the "tokenMinB" parameter. 64 func (inst *DecreaseLiquidity) SetTokenMinB(tokenMinB uint64) *DecreaseLiquidity { 65 inst.TokenMinB = &tokenMinB 66 return inst 67 } 68 69 // SetWhirlpoolAccount sets the "whirlpool" account. 70 func (inst *DecreaseLiquidity) SetWhirlpoolAccount(whirlpool ag_solanago.PublicKey) *DecreaseLiquidity { 71 inst.AccountMetaSlice[0] = ag_solanago.Meta(whirlpool).WRITE() 72 return inst 73 } 74 75 // GetWhirlpoolAccount gets the "whirlpool" account. 76 func (inst *DecreaseLiquidity) GetWhirlpoolAccount() *ag_solanago.AccountMeta { 77 return inst.AccountMetaSlice.Get(0) 78 } 79 80 // SetTokenProgramAccount sets the "tokenProgram" account. 81 func (inst *DecreaseLiquidity) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *DecreaseLiquidity { 82 inst.AccountMetaSlice[1] = ag_solanago.Meta(tokenProgram) 83 return inst 84 } 85 86 // GetTokenProgramAccount gets the "tokenProgram" account. 87 func (inst *DecreaseLiquidity) GetTokenProgramAccount() *ag_solanago.AccountMeta { 88 return inst.AccountMetaSlice.Get(1) 89 } 90 91 // SetPositionAuthorityAccount sets the "positionAuthority" account. 92 func (inst *DecreaseLiquidity) SetPositionAuthorityAccount(positionAuthority ag_solanago.PublicKey) *DecreaseLiquidity { 93 inst.AccountMetaSlice[2] = ag_solanago.Meta(positionAuthority).SIGNER() 94 return inst 95 } 96 97 // GetPositionAuthorityAccount gets the "positionAuthority" account. 98 func (inst *DecreaseLiquidity) GetPositionAuthorityAccount() *ag_solanago.AccountMeta { 99 return inst.AccountMetaSlice.Get(2) 100 } 101 102 // SetPositionAccount sets the "position" account. 103 func (inst *DecreaseLiquidity) SetPositionAccount(position ag_solanago.PublicKey) *DecreaseLiquidity { 104 inst.AccountMetaSlice[3] = ag_solanago.Meta(position).WRITE() 105 return inst 106 } 107 108 // GetPositionAccount gets the "position" account. 109 func (inst *DecreaseLiquidity) GetPositionAccount() *ag_solanago.AccountMeta { 110 return inst.AccountMetaSlice.Get(3) 111 } 112 113 // SetPositionTokenAccountAccount sets the "positionTokenAccount" account. 114 func (inst *DecreaseLiquidity) SetPositionTokenAccountAccount(positionTokenAccount ag_solanago.PublicKey) *DecreaseLiquidity { 115 inst.AccountMetaSlice[4] = ag_solanago.Meta(positionTokenAccount) 116 return inst 117 } 118 119 // GetPositionTokenAccountAccount gets the "positionTokenAccount" account. 120 func (inst *DecreaseLiquidity) GetPositionTokenAccountAccount() *ag_solanago.AccountMeta { 121 return inst.AccountMetaSlice.Get(4) 122 } 123 124 // SetTokenOwnerAccountAAccount sets the "tokenOwnerAccountA" account. 125 func (inst *DecreaseLiquidity) SetTokenOwnerAccountAAccount(tokenOwnerAccountA ag_solanago.PublicKey) *DecreaseLiquidity { 126 inst.AccountMetaSlice[5] = ag_solanago.Meta(tokenOwnerAccountA).WRITE() 127 return inst 128 } 129 130 // GetTokenOwnerAccountAAccount gets the "tokenOwnerAccountA" account. 131 func (inst *DecreaseLiquidity) GetTokenOwnerAccountAAccount() *ag_solanago.AccountMeta { 132 return inst.AccountMetaSlice.Get(5) 133 } 134 135 // SetTokenOwnerAccountBAccount sets the "tokenOwnerAccountB" account. 136 func (inst *DecreaseLiquidity) SetTokenOwnerAccountBAccount(tokenOwnerAccountB ag_solanago.PublicKey) *DecreaseLiquidity { 137 inst.AccountMetaSlice[6] = ag_solanago.Meta(tokenOwnerAccountB).WRITE() 138 return inst 139 } 140 141 // GetTokenOwnerAccountBAccount gets the "tokenOwnerAccountB" account. 142 func (inst *DecreaseLiquidity) GetTokenOwnerAccountBAccount() *ag_solanago.AccountMeta { 143 return inst.AccountMetaSlice.Get(6) 144 } 145 146 // SetTokenVaultAAccount sets the "tokenVaultA" account. 147 func (inst *DecreaseLiquidity) SetTokenVaultAAccount(tokenVaultA ag_solanago.PublicKey) *DecreaseLiquidity { 148 inst.AccountMetaSlice[7] = ag_solanago.Meta(tokenVaultA).WRITE() 149 return inst 150 } 151 152 // GetTokenVaultAAccount gets the "tokenVaultA" account. 153 func (inst *DecreaseLiquidity) GetTokenVaultAAccount() *ag_solanago.AccountMeta { 154 return inst.AccountMetaSlice.Get(7) 155 } 156 157 // SetTokenVaultBAccount sets the "tokenVaultB" account. 158 func (inst *DecreaseLiquidity) SetTokenVaultBAccount(tokenVaultB ag_solanago.PublicKey) *DecreaseLiquidity { 159 inst.AccountMetaSlice[8] = ag_solanago.Meta(tokenVaultB).WRITE() 160 return inst 161 } 162 163 // GetTokenVaultBAccount gets the "tokenVaultB" account. 164 func (inst *DecreaseLiquidity) GetTokenVaultBAccount() *ag_solanago.AccountMeta { 165 return inst.AccountMetaSlice.Get(8) 166 } 167 168 // SetTickArrayLowerAccount sets the "tickArrayLower" account. 169 func (inst *DecreaseLiquidity) SetTickArrayLowerAccount(tickArrayLower ag_solanago.PublicKey) *DecreaseLiquidity { 170 inst.AccountMetaSlice[9] = ag_solanago.Meta(tickArrayLower).WRITE() 171 return inst 172 } 173 174 // GetTickArrayLowerAccount gets the "tickArrayLower" account. 175 func (inst *DecreaseLiquidity) GetTickArrayLowerAccount() *ag_solanago.AccountMeta { 176 return inst.AccountMetaSlice.Get(9) 177 } 178 179 // SetTickArrayUpperAccount sets the "tickArrayUpper" account. 180 func (inst *DecreaseLiquidity) SetTickArrayUpperAccount(tickArrayUpper ag_solanago.PublicKey) *DecreaseLiquidity { 181 inst.AccountMetaSlice[10] = ag_solanago.Meta(tickArrayUpper).WRITE() 182 return inst 183 } 184 185 // GetTickArrayUpperAccount gets the "tickArrayUpper" account. 186 func (inst *DecreaseLiquidity) GetTickArrayUpperAccount() *ag_solanago.AccountMeta { 187 return inst.AccountMetaSlice.Get(10) 188 } 189 190 func (inst DecreaseLiquidity) Build() *Instruction { 191 return &Instruction{BaseVariant: ag_binary.BaseVariant{ 192 Impl: inst, 193 TypeID: Instruction_DecreaseLiquidity, 194 }} 195 } 196 197 // ValidateAndBuild validates the instruction parameters and accounts; 198 // if there is a validation error, it returns the error. 199 // Otherwise, it builds and returns the instruction. 200 func (inst DecreaseLiquidity) ValidateAndBuild() (*Instruction, error) { 201 if err := inst.Validate(); err != nil { 202 return nil, err 203 } 204 return inst.Build(), nil 205 } 206 207 func (inst *DecreaseLiquidity) Validate() error { 208 // Check whether all (required) parameters are set: 209 { 210 if inst.LiquidityAmount == nil { 211 return errors.New("LiquidityAmount parameter is not set") 212 } 213 if inst.TokenMinA == nil { 214 return errors.New("TokenMinA parameter is not set") 215 } 216 if inst.TokenMinB == nil { 217 return errors.New("TokenMinB parameter is not set") 218 } 219 } 220 221 // Check whether all (required) accounts are set: 222 { 223 if inst.AccountMetaSlice[0] == nil { 224 return errors.New("accounts.Whirlpool is not set") 225 } 226 if inst.AccountMetaSlice[1] == nil { 227 return errors.New("accounts.TokenProgram is not set") 228 } 229 if inst.AccountMetaSlice[2] == nil { 230 return errors.New("accounts.PositionAuthority is not set") 231 } 232 if inst.AccountMetaSlice[3] == nil { 233 return errors.New("accounts.Position is not set") 234 } 235 if inst.AccountMetaSlice[4] == nil { 236 return errors.New("accounts.PositionTokenAccount is not set") 237 } 238 if inst.AccountMetaSlice[5] == nil { 239 return errors.New("accounts.TokenOwnerAccountA is not set") 240 } 241 if inst.AccountMetaSlice[6] == nil { 242 return errors.New("accounts.TokenOwnerAccountB is not set") 243 } 244 if inst.AccountMetaSlice[7] == nil { 245 return errors.New("accounts.TokenVaultA is not set") 246 } 247 if inst.AccountMetaSlice[8] == nil { 248 return errors.New("accounts.TokenVaultB is not set") 249 } 250 if inst.AccountMetaSlice[9] == nil { 251 return errors.New("accounts.TickArrayLower is not set") 252 } 253 if inst.AccountMetaSlice[10] == nil { 254 return errors.New("accounts.TickArrayUpper is not set") 255 } 256 } 257 return nil 258 } 259 260 func (inst *DecreaseLiquidity) EncodeToTree(parent ag_treeout.Branches) { 261 parent.Child(ag_format.Program(ProgramName, ProgramID)). 262 // 263 ParentFunc(func(programBranch ag_treeout.Branches) { 264 programBranch.Child(ag_format.Instruction("DecreaseLiquidity")). 265 // 266 ParentFunc(func(instructionBranch ag_treeout.Branches) { 267 268 // Parameters of the instruction: 269 instructionBranch.Child("Params[len=3]").ParentFunc(func(paramsBranch ag_treeout.Branches) { 270 paramsBranch.Child(ag_format.Param("LiquidityAmount", *inst.LiquidityAmount)) 271 paramsBranch.Child(ag_format.Param(" TokenMinA", *inst.TokenMinA)) 272 paramsBranch.Child(ag_format.Param(" TokenMinB", *inst.TokenMinB)) 273 }) 274 275 // Accounts of the instruction: 276 instructionBranch.Child("Accounts[len=11]").ParentFunc(func(accountsBranch ag_treeout.Branches) { 277 accountsBranch.Child(ag_format.Meta(" whirlpool", inst.AccountMetaSlice.Get(0))) 278 accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(1))) 279 accountsBranch.Child(ag_format.Meta(" positionAuthority", inst.AccountMetaSlice.Get(2))) 280 accountsBranch.Child(ag_format.Meta(" position", inst.AccountMetaSlice.Get(3))) 281 accountsBranch.Child(ag_format.Meta(" positionToken", inst.AccountMetaSlice.Get(4))) 282 accountsBranch.Child(ag_format.Meta("tokenOwnerAccountA", inst.AccountMetaSlice.Get(5))) 283 accountsBranch.Child(ag_format.Meta("tokenOwnerAccountB", inst.AccountMetaSlice.Get(6))) 284 accountsBranch.Child(ag_format.Meta(" tokenVaultA", inst.AccountMetaSlice.Get(7))) 285 accountsBranch.Child(ag_format.Meta(" tokenVaultB", inst.AccountMetaSlice.Get(8))) 286 accountsBranch.Child(ag_format.Meta(" tickArrayLower", inst.AccountMetaSlice.Get(9))) 287 accountsBranch.Child(ag_format.Meta(" tickArrayUpper", inst.AccountMetaSlice.Get(10))) 288 }) 289 }) 290 }) 291 } 292 293 func (obj DecreaseLiquidity) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { 294 // Serialize `LiquidityAmount` param: 295 err = encoder.Encode(obj.LiquidityAmount) 296 if err != nil { 297 return err 298 } 299 // Serialize `TokenMinA` param: 300 err = encoder.Encode(obj.TokenMinA) 301 if err != nil { 302 return err 303 } 304 // Serialize `TokenMinB` param: 305 err = encoder.Encode(obj.TokenMinB) 306 if err != nil { 307 return err 308 } 309 return nil 310 } 311 func (obj *DecreaseLiquidity) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { 312 // Deserialize `LiquidityAmount`: 313 err = decoder.Decode(&obj.LiquidityAmount) 314 if err != nil { 315 return err 316 } 317 // Deserialize `TokenMinA`: 318 err = decoder.Decode(&obj.TokenMinA) 319 if err != nil { 320 return err 321 } 322 // Deserialize `TokenMinB`: 323 err = decoder.Decode(&obj.TokenMinB) 324 if err != nil { 325 return err 326 } 327 return nil 328 } 329 330 // NewDecreaseLiquidityInstruction declares a new DecreaseLiquidity instruction with the provided parameters and accounts. 331 func NewDecreaseLiquidityInstruction( 332 // Parameters: 333 liquidityAmount ag_binary.Uint128, 334 tokenMinA uint64, 335 tokenMinB uint64, 336 // Accounts: 337 whirlpool ag_solanago.PublicKey, 338 tokenProgram ag_solanago.PublicKey, 339 positionAuthority ag_solanago.PublicKey, 340 position ag_solanago.PublicKey, 341 positionTokenAccount ag_solanago.PublicKey, 342 tokenOwnerAccountA ag_solanago.PublicKey, 343 tokenOwnerAccountB ag_solanago.PublicKey, 344 tokenVaultA ag_solanago.PublicKey, 345 tokenVaultB ag_solanago.PublicKey, 346 tickArrayLower ag_solanago.PublicKey, 347 tickArrayUpper ag_solanago.PublicKey) *DecreaseLiquidity { 348 return NewDecreaseLiquidityInstructionBuilder(). 349 SetLiquidityAmount(liquidityAmount). 350 SetTokenMinA(tokenMinA). 351 SetTokenMinB(tokenMinB). 352 SetWhirlpoolAccount(whirlpool). 353 SetTokenProgramAccount(tokenProgram). 354 SetPositionAuthorityAccount(positionAuthority). 355 SetPositionAccount(position). 356 SetPositionTokenAccountAccount(positionTokenAccount). 357 SetTokenOwnerAccountAAccount(tokenOwnerAccountA). 358 SetTokenOwnerAccountBAccount(tokenOwnerAccountB). 359 SetTokenVaultAAccount(tokenVaultA). 360 SetTokenVaultBAccount(tokenVaultB). 361 SetTickArrayLowerAccount(tickArrayLower). 362 SetTickArrayUpperAccount(tickArrayUpper) 363 }