From c145eb8bde211d0f6f6800f174046cd30677272e Mon Sep 17 00:00:00 2001 From: egaotan Date: Sun, 5 Jan 2025 15:42:34 +0800 Subject: [PATCH 1/6] add some programs --- keys.go | 5 +- .../address-lookup-table/closelookuptable.go | 136 ++ .../closelookuptable_test.go | 32 + .../address-lookup-table/createlookuptable.go | 207 +++ .../createlookuptable_test.go | 32 + .../deactivatelookuptable.go | 117 ++ .../deactivatelookuptable_test.go | 32 + .../address-lookup-table/extendlookuptable.go | 184 +++ .../extendlookuptable_test.go | 32 + .../address-lookup-table/freezelookuptable.go | 117 ++ .../freezelookuptable_test.go | 32 + programs/address-lookup-table/instructions.go | 167 +++ .../address-lookup-table/testing_utils.go | 20 + programs/associated-token-account/Create.go | 302 ++-- .../associated-token-account/create_test.go | 32 + .../createidempotent.go | 234 +++ .../createidempotent_test.go | 32 + .../associated-token-account/instructions.go | 131 +- .../associated-token-account/testing_utils.go | 20 + programs/raydiumamm/AdminCancelOrders.go | 431 ++++++ programs/raydiumamm/AdminCancelOrders_test.go | 32 + programs/raydiumamm/CreateConfigAccount.go | 174 +++ .../raydiumamm/CreateConfigAccount_test.go | 32 + programs/raydiumamm/Deposit.go | 420 ++++++ programs/raydiumamm/Deposit_test.go | 32 + programs/raydiumamm/Initialize.go | 473 ++++++ programs/raydiumamm/Initialize2.go | 576 ++++++++ programs/raydiumamm/Initialize2_test.go | 32 + programs/raydiumamm/Initialize_test.go | 32 + programs/raydiumamm/MigrateToOpenBook.go | 478 ++++++ programs/raydiumamm/MigrateToOpenBook_test.go | 32 + programs/raydiumamm/MonitorStep.go | 515 +++++++ programs/raydiumamm/MonitorStep_test.go | 32 + programs/raydiumamm/PreInitialize.go | 374 +++++ programs/raydiumamm/PreInitialize_test.go | 32 + programs/raydiumamm/SetParams.go | 617 ++++++++ programs/raydiumamm/SetParams_test.go | 32 + programs/raydiumamm/SimulateInfo.go | 342 +++++ programs/raydiumamm/SimulateInfo_test.go | 32 + programs/raydiumamm/SwapBaseIn.go | 473 ++++++ programs/raydiumamm/SwapBaseIn_test.go | 32 + programs/raydiumamm/SwapBaseOut.go | 473 ++++++ programs/raydiumamm/SwapBaseOut_test.go | 32 + programs/raydiumamm/UpdateConfigAccount.go | 169 +++ .../raydiumamm/UpdateConfigAccount_test.go | 32 + programs/raydiumamm/Withdraw.go | 526 +++++++ programs/raydiumamm/WithdrawPnl.go | 402 +++++ programs/raydiumamm/WithdrawPnl_test.go | 32 + programs/raydiumamm/WithdrawSrm.go | 222 +++ programs/raydiumamm/WithdrawSrm_test.go | 32 + programs/raydiumamm/Withdraw_test.go | 32 + programs/raydiumamm/accounts.go | 767 ++++++++++ programs/raydiumamm/instructions.go | 222 +++ programs/raydiumamm/testing_utils.go | 20 + programs/raydiumamm/types.go | 514 +++++++ programs/raydiumclmm/ClosePosition.go | 219 +++ programs/raydiumclmm/ClosePosition_test.go | 32 + programs/raydiumclmm/CollectFundFee.go | 380 +++++ programs/raydiumclmm/CollectFundFee_test.go | 32 + programs/raydiumclmm/CollectProtocolFee.go | 380 +++++ .../raydiumclmm/CollectProtocolFee_test.go | 32 + .../raydiumclmm/CollectRemainingRewards.go | 287 ++++ .../CollectRemainingRewards_test.go | 32 + programs/raydiumclmm/CreateAmmConfig.go | 271 ++++ programs/raydiumclmm/CreateAmmConfig_test.go | 32 + .../raydiumclmm/CreateOperationAccount.go | 147 ++ .../CreateOperationAccount_test.go | 32 + programs/raydiumclmm/CreatePool.go | 420 ++++++ programs/raydiumclmm/CreatePool_test.go | 32 + programs/raydiumclmm/DecreaseLiquidity.go | 420 ++++++ programs/raydiumclmm/DecreaseLiquidityV2.go | 508 +++++++ .../raydiumclmm/DecreaseLiquidityV2_test.go | 32 + .../raydiumclmm/DecreaseLiquidity_test.go | 32 + programs/raydiumclmm/IncreaseLiquidity.go | 420 ++++++ programs/raydiumclmm/IncreaseLiquidityV2.go | 528 +++++++ .../raydiumclmm/IncreaseLiquidityV2_test.go | 32 + .../raydiumclmm/IncreaseLiquidity_test.go | 32 + programs/raydiumclmm/InitializeReward.go | 325 +++++ programs/raydiumclmm/InitializeReward_test.go | 32 + programs/raydiumclmm/OpenPosition.go | 667 +++++++++ programs/raydiumclmm/OpenPositionV2.go | 798 ++++++++++ programs/raydiumclmm/OpenPositionV2_test.go | 32 + programs/raydiumclmm/OpenPosition_test.go | 32 + programs/raydiumclmm/SetRewardParams.go | 313 ++++ programs/raydiumclmm/SetRewardParams_test.go | 32 + programs/raydiumclmm/Swap.go | 403 +++++ programs/raydiumclmm/SwapRouterBaseIn.go | 267 ++++ programs/raydiumclmm/SwapRouterBaseIn_test.go | 32 + programs/raydiumclmm/SwapV2.go | 469 ++++++ programs/raydiumclmm/SwapV2_test.go | 32 + programs/raydiumclmm/Swap_test.go | 32 + programs/raydiumclmm/TransferRewardOwner.go | 155 ++ .../raydiumclmm/TransferRewardOwner_test.go | 32 + programs/raydiumclmm/UpdateAmmConfig.go | 187 +++ programs/raydiumclmm/UpdateAmmConfig_test.go | 32 + .../raydiumclmm/UpdateOperationAccount.go | 204 +++ .../UpdateOperationAccount_test.go | 32 + programs/raydiumclmm/UpdatePoolStatus.go | 152 ++ programs/raydiumclmm/UpdatePoolStatus_test.go | 32 + programs/raydiumclmm/UpdateRewardInfos.go | 106 ++ .../raydiumclmm/UpdateRewardInfos_test.go | 32 + programs/raydiumclmm/accounts.go | 1296 +++++++++++++++++ programs/raydiumclmm/instructions.go | 479 ++++++ programs/raydiumclmm/testing_utils.go | 20 + programs/raydiumclmm/types.go | 470 ++++++ programs/whirlpool/CloseBundledPosition.go | 203 +++ .../whirlpool/CloseBundledPosition_test.go | 32 + programs/whirlpool/ClosePosition.go | 193 +++ programs/whirlpool/ClosePosition_test.go | 32 + programs/whirlpool/CollectFees.go | 250 ++++ programs/whirlpool/CollectFees_test.go | 32 + programs/whirlpool/CollectProtocolFees.go | 231 +++ .../whirlpool/CollectProtocolFees_test.go | 32 + programs/whirlpool/CollectReward.go | 241 +++ programs/whirlpool/CollectReward_test.go | 32 + programs/whirlpool/DecreaseLiquidity.go | 363 +++++ programs/whirlpool/DecreaseLiquidity_test.go | 32 + programs/whirlpool/DeletePositionBundle.go | 193 +++ .../whirlpool/DeletePositionBundle_test.go | 32 + programs/whirlpool/IncreaseLiquidity.go | 363 +++++ programs/whirlpool/IncreaseLiquidity_test.go | 32 + programs/whirlpool/InitializeConfig.go | 234 +++ programs/whirlpool/InitializeConfig_test.go | 32 + programs/whirlpool/InitializeFeeTier.go | 226 +++ programs/whirlpool/InitializeFeeTier_test.go | 32 + programs/whirlpool/InitializePool.go | 363 +++++ programs/whirlpool/InitializePool_test.go | 32 + .../whirlpool/InitializePositionBundle.go | 250 ++++ .../InitializePositionBundleWithMetadata.go | 307 ++++ ...itializePositionBundleWithMetadata_test.go | 32 + .../InitializePositionBundle_test.go | 32 + programs/whirlpool/InitializeReward.go | 260 ++++ programs/whirlpool/InitializeReward_test.go | 32 + programs/whirlpool/InitializeTickArray.go | 184 +++ .../whirlpool/InitializeTickArray_test.go | 32 + programs/whirlpool/OpenBundledPosition.go | 306 ++++ .../whirlpool/OpenBundledPosition_test.go | 32 + programs/whirlpool/OpenPosition.go | 344 +++++ .../whirlpool/OpenPositionWithMetadata.go | 401 +++++ .../OpenPositionWithMetadata_test.go | 32 + programs/whirlpool/OpenPosition_test.go | 32 + .../SetCollectProtocolFeesAuthority.go | 136 ++ .../SetCollectProtocolFeesAuthority_test.go | 32 + programs/whirlpool/SetDefaultFeeRate.go | 165 +++ programs/whirlpool/SetDefaultFeeRate_test.go | 32 + .../whirlpool/SetDefaultProtocolFeeRate.go | 146 ++ .../SetDefaultProtocolFeeRate_test.go | 32 + programs/whirlpool/SetFeeAuthority.go | 136 ++ programs/whirlpool/SetFeeAuthority_test.go | 32 + programs/whirlpool/SetFeeRate.go | 165 +++ programs/whirlpool/SetFeeRate_test.go | 32 + programs/whirlpool/SetProtocolFeeRate.go | 165 +++ programs/whirlpool/SetProtocolFeeRate_test.go | 32 + programs/whirlpool/SetRewardAuthority.go | 165 +++ .../SetRewardAuthorityBySuperAuthority.go | 184 +++ ...SetRewardAuthorityBySuperAuthority_test.go | 32 + programs/whirlpool/SetRewardAuthority_test.go | 32 + programs/whirlpool/SetRewardEmissions.go | 188 +++ .../SetRewardEmissionsSuperAuthority.go | 136 ++ .../SetRewardEmissionsSuperAuthority_test.go | 32 + programs/whirlpool/SetRewardEmissions_test.go | 32 + programs/whirlpool/Swap.go | 409 ++++++ programs/whirlpool/Swap_test.go | 32 + programs/whirlpool/TwoHopSwap.go | 626 ++++++++ programs/whirlpool/TwoHopSwap_test.go | 32 + programs/whirlpool/UpdateFeesAndRewards.go | 155 ++ .../whirlpool/UpdateFeesAndRewards_test.go | 32 + programs/whirlpool/accounts.go | 646 ++++++++ programs/whirlpool/instructions.go | 327 +++++ programs/whirlpool/testing_utils.go | 20 + programs/whirlpool/types.go | 318 ++++ 171 files changed, 31401 insertions(+), 181 deletions(-) create mode 100644 programs/address-lookup-table/closelookuptable.go create mode 100644 programs/address-lookup-table/closelookuptable_test.go create mode 100644 programs/address-lookup-table/createlookuptable.go create mode 100644 programs/address-lookup-table/createlookuptable_test.go create mode 100644 programs/address-lookup-table/deactivatelookuptable.go create mode 100644 programs/address-lookup-table/deactivatelookuptable_test.go create mode 100644 programs/address-lookup-table/extendlookuptable.go create mode 100644 programs/address-lookup-table/extendlookuptable_test.go create mode 100644 programs/address-lookup-table/freezelookuptable.go create mode 100644 programs/address-lookup-table/freezelookuptable_test.go create mode 100644 programs/address-lookup-table/instructions.go create mode 100644 programs/address-lookup-table/testing_utils.go create mode 100644 programs/associated-token-account/create_test.go create mode 100644 programs/associated-token-account/createidempotent.go create mode 100644 programs/associated-token-account/createidempotent_test.go create mode 100644 programs/associated-token-account/testing_utils.go create mode 100644 programs/raydiumamm/AdminCancelOrders.go create mode 100644 programs/raydiumamm/AdminCancelOrders_test.go create mode 100644 programs/raydiumamm/CreateConfigAccount.go create mode 100644 programs/raydiumamm/CreateConfigAccount_test.go create mode 100644 programs/raydiumamm/Deposit.go create mode 100644 programs/raydiumamm/Deposit_test.go create mode 100644 programs/raydiumamm/Initialize.go create mode 100644 programs/raydiumamm/Initialize2.go create mode 100644 programs/raydiumamm/Initialize2_test.go create mode 100644 programs/raydiumamm/Initialize_test.go create mode 100644 programs/raydiumamm/MigrateToOpenBook.go create mode 100644 programs/raydiumamm/MigrateToOpenBook_test.go create mode 100644 programs/raydiumamm/MonitorStep.go create mode 100644 programs/raydiumamm/MonitorStep_test.go create mode 100644 programs/raydiumamm/PreInitialize.go create mode 100644 programs/raydiumamm/PreInitialize_test.go create mode 100644 programs/raydiumamm/SetParams.go create mode 100644 programs/raydiumamm/SetParams_test.go create mode 100644 programs/raydiumamm/SimulateInfo.go create mode 100644 programs/raydiumamm/SimulateInfo_test.go create mode 100644 programs/raydiumamm/SwapBaseIn.go create mode 100644 programs/raydiumamm/SwapBaseIn_test.go create mode 100644 programs/raydiumamm/SwapBaseOut.go create mode 100644 programs/raydiumamm/SwapBaseOut_test.go create mode 100644 programs/raydiumamm/UpdateConfigAccount.go create mode 100644 programs/raydiumamm/UpdateConfigAccount_test.go create mode 100644 programs/raydiumamm/Withdraw.go create mode 100644 programs/raydiumamm/WithdrawPnl.go create mode 100644 programs/raydiumamm/WithdrawPnl_test.go create mode 100644 programs/raydiumamm/WithdrawSrm.go create mode 100644 programs/raydiumamm/WithdrawSrm_test.go create mode 100644 programs/raydiumamm/Withdraw_test.go create mode 100644 programs/raydiumamm/accounts.go create mode 100644 programs/raydiumamm/instructions.go create mode 100644 programs/raydiumamm/testing_utils.go create mode 100644 programs/raydiumamm/types.go create mode 100644 programs/raydiumclmm/ClosePosition.go create mode 100644 programs/raydiumclmm/ClosePosition_test.go create mode 100644 programs/raydiumclmm/CollectFundFee.go create mode 100644 programs/raydiumclmm/CollectFundFee_test.go create mode 100644 programs/raydiumclmm/CollectProtocolFee.go create mode 100644 programs/raydiumclmm/CollectProtocolFee_test.go create mode 100644 programs/raydiumclmm/CollectRemainingRewards.go create mode 100644 programs/raydiumclmm/CollectRemainingRewards_test.go create mode 100644 programs/raydiumclmm/CreateAmmConfig.go create mode 100644 programs/raydiumclmm/CreateAmmConfig_test.go create mode 100644 programs/raydiumclmm/CreateOperationAccount.go create mode 100644 programs/raydiumclmm/CreateOperationAccount_test.go create mode 100644 programs/raydiumclmm/CreatePool.go create mode 100644 programs/raydiumclmm/CreatePool_test.go create mode 100644 programs/raydiumclmm/DecreaseLiquidity.go create mode 100644 programs/raydiumclmm/DecreaseLiquidityV2.go create mode 100644 programs/raydiumclmm/DecreaseLiquidityV2_test.go create mode 100644 programs/raydiumclmm/DecreaseLiquidity_test.go create mode 100644 programs/raydiumclmm/IncreaseLiquidity.go create mode 100644 programs/raydiumclmm/IncreaseLiquidityV2.go create mode 100644 programs/raydiumclmm/IncreaseLiquidityV2_test.go create mode 100644 programs/raydiumclmm/IncreaseLiquidity_test.go create mode 100644 programs/raydiumclmm/InitializeReward.go create mode 100644 programs/raydiumclmm/InitializeReward_test.go create mode 100644 programs/raydiumclmm/OpenPosition.go create mode 100644 programs/raydiumclmm/OpenPositionV2.go create mode 100644 programs/raydiumclmm/OpenPositionV2_test.go create mode 100644 programs/raydiumclmm/OpenPosition_test.go create mode 100644 programs/raydiumclmm/SetRewardParams.go create mode 100644 programs/raydiumclmm/SetRewardParams_test.go create mode 100644 programs/raydiumclmm/Swap.go create mode 100644 programs/raydiumclmm/SwapRouterBaseIn.go create mode 100644 programs/raydiumclmm/SwapRouterBaseIn_test.go create mode 100644 programs/raydiumclmm/SwapV2.go create mode 100644 programs/raydiumclmm/SwapV2_test.go create mode 100644 programs/raydiumclmm/Swap_test.go create mode 100644 programs/raydiumclmm/TransferRewardOwner.go create mode 100644 programs/raydiumclmm/TransferRewardOwner_test.go create mode 100644 programs/raydiumclmm/UpdateAmmConfig.go create mode 100644 programs/raydiumclmm/UpdateAmmConfig_test.go create mode 100644 programs/raydiumclmm/UpdateOperationAccount.go create mode 100644 programs/raydiumclmm/UpdateOperationAccount_test.go create mode 100644 programs/raydiumclmm/UpdatePoolStatus.go create mode 100644 programs/raydiumclmm/UpdatePoolStatus_test.go create mode 100644 programs/raydiumclmm/UpdateRewardInfos.go create mode 100644 programs/raydiumclmm/UpdateRewardInfos_test.go create mode 100644 programs/raydiumclmm/accounts.go create mode 100644 programs/raydiumclmm/instructions.go create mode 100644 programs/raydiumclmm/testing_utils.go create mode 100644 programs/raydiumclmm/types.go create mode 100644 programs/whirlpool/CloseBundledPosition.go create mode 100644 programs/whirlpool/CloseBundledPosition_test.go create mode 100644 programs/whirlpool/ClosePosition.go create mode 100644 programs/whirlpool/ClosePosition_test.go create mode 100644 programs/whirlpool/CollectFees.go create mode 100644 programs/whirlpool/CollectFees_test.go create mode 100644 programs/whirlpool/CollectProtocolFees.go create mode 100644 programs/whirlpool/CollectProtocolFees_test.go create mode 100644 programs/whirlpool/CollectReward.go create mode 100644 programs/whirlpool/CollectReward_test.go create mode 100644 programs/whirlpool/DecreaseLiquidity.go create mode 100644 programs/whirlpool/DecreaseLiquidity_test.go create mode 100644 programs/whirlpool/DeletePositionBundle.go create mode 100644 programs/whirlpool/DeletePositionBundle_test.go create mode 100644 programs/whirlpool/IncreaseLiquidity.go create mode 100644 programs/whirlpool/IncreaseLiquidity_test.go create mode 100644 programs/whirlpool/InitializeConfig.go create mode 100644 programs/whirlpool/InitializeConfig_test.go create mode 100644 programs/whirlpool/InitializeFeeTier.go create mode 100644 programs/whirlpool/InitializeFeeTier_test.go create mode 100644 programs/whirlpool/InitializePool.go create mode 100644 programs/whirlpool/InitializePool_test.go create mode 100644 programs/whirlpool/InitializePositionBundle.go create mode 100644 programs/whirlpool/InitializePositionBundleWithMetadata.go create mode 100644 programs/whirlpool/InitializePositionBundleWithMetadata_test.go create mode 100644 programs/whirlpool/InitializePositionBundle_test.go create mode 100644 programs/whirlpool/InitializeReward.go create mode 100644 programs/whirlpool/InitializeReward_test.go create mode 100644 programs/whirlpool/InitializeTickArray.go create mode 100644 programs/whirlpool/InitializeTickArray_test.go create mode 100644 programs/whirlpool/OpenBundledPosition.go create mode 100644 programs/whirlpool/OpenBundledPosition_test.go create mode 100644 programs/whirlpool/OpenPosition.go create mode 100644 programs/whirlpool/OpenPositionWithMetadata.go create mode 100644 programs/whirlpool/OpenPositionWithMetadata_test.go create mode 100644 programs/whirlpool/OpenPosition_test.go create mode 100644 programs/whirlpool/SetCollectProtocolFeesAuthority.go create mode 100644 programs/whirlpool/SetCollectProtocolFeesAuthority_test.go create mode 100644 programs/whirlpool/SetDefaultFeeRate.go create mode 100644 programs/whirlpool/SetDefaultFeeRate_test.go create mode 100644 programs/whirlpool/SetDefaultProtocolFeeRate.go create mode 100644 programs/whirlpool/SetDefaultProtocolFeeRate_test.go create mode 100644 programs/whirlpool/SetFeeAuthority.go create mode 100644 programs/whirlpool/SetFeeAuthority_test.go create mode 100644 programs/whirlpool/SetFeeRate.go create mode 100644 programs/whirlpool/SetFeeRate_test.go create mode 100644 programs/whirlpool/SetProtocolFeeRate.go create mode 100644 programs/whirlpool/SetProtocolFeeRate_test.go create mode 100644 programs/whirlpool/SetRewardAuthority.go create mode 100644 programs/whirlpool/SetRewardAuthorityBySuperAuthority.go create mode 100644 programs/whirlpool/SetRewardAuthorityBySuperAuthority_test.go create mode 100644 programs/whirlpool/SetRewardAuthority_test.go create mode 100644 programs/whirlpool/SetRewardEmissions.go create mode 100644 programs/whirlpool/SetRewardEmissionsSuperAuthority.go create mode 100644 programs/whirlpool/SetRewardEmissionsSuperAuthority_test.go create mode 100644 programs/whirlpool/SetRewardEmissions_test.go create mode 100644 programs/whirlpool/Swap.go create mode 100644 programs/whirlpool/Swap_test.go create mode 100644 programs/whirlpool/TwoHopSwap.go create mode 100644 programs/whirlpool/TwoHopSwap_test.go create mode 100644 programs/whirlpool/UpdateFeesAndRewards.go create mode 100644 programs/whirlpool/UpdateFeesAndRewards_test.go create mode 100644 programs/whirlpool/accounts.go create mode 100644 programs/whirlpool/instructions.go create mode 100644 programs/whirlpool/testing_utils.go create mode 100644 programs/whirlpool/types.go diff --git a/keys.go b/keys.go index 306c4c98..a39d0d1b 100644 --- a/keys.go +++ b/keys.go @@ -694,10 +694,12 @@ func FindProgramAddress(seed [][]byte, programID PublicKey) (PublicKey, uint8, e func FindAssociatedTokenAddress( wallet PublicKey, mint PublicKey, + tokenProgram PublicKey, ) (PublicKey, uint8, error) { return findAssociatedTokenAddressAndBumpSeed( wallet, mint, + tokenProgram, SPLAssociatedTokenAccountProgramID, ) } @@ -705,11 +707,12 @@ func FindAssociatedTokenAddress( func findAssociatedTokenAddressAndBumpSeed( walletAddress PublicKey, splTokenMintAddress PublicKey, + tokenProgram PublicKey, programID PublicKey, ) (PublicKey, uint8, error) { return FindProgramAddress([][]byte{ walletAddress[:], - TokenProgramID[:], + tokenProgram[:], splTokenMintAddress[:], }, programID, diff --git a/programs/address-lookup-table/closelookuptable.go b/programs/address-lookup-table/closelookuptable.go new file mode 100644 index 00000000..1beab598 --- /dev/null +++ b/programs/address-lookup-table/closelookuptable.go @@ -0,0 +1,136 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package addresslookuptable + +import ( + "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" +) + +// CloseLookupTable is the `close_lookup_table` instruction. +type CloseLookupTable struct { + + // [0] = [WRITE] address_lookup_table + // + // [1] = [SIGNER] owner + // + // [2] = [WRITE] recipient + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewCloseLookupTableInstructionBuilder creates a new `CloseLookupTable` instruction builder. +func NewCloseLookupTableInstructionBuilder() *CloseLookupTable { + nd := &CloseLookupTable{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 3), + } + return nd +} + +// SetAddressLookupTableAccount sets the "address_lookup_table" account. +func (inst *CloseLookupTable) SetAddressLookupTableAccount(addressLookupTable ag_solanago.PublicKey) *CloseLookupTable { + inst.AccountMetaSlice[0] = ag_solanago.Meta(addressLookupTable).WRITE() + return inst +} + +// GetAddressLookupTableAccount gets the "address_lookup_table" account. +func (inst *CloseLookupTable) GetAddressLookupTableAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetOwnerAccount sets the "owner" account. +func (inst *CloseLookupTable) SetOwnerAccount(owner ag_solanago.PublicKey) *CloseLookupTable { + inst.AccountMetaSlice[1] = ag_solanago.Meta(owner).SIGNER() + return inst +} + +// GetOwnerAccount gets the "owner" account. +func (inst *CloseLookupTable) GetOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetRecipientAccount sets the "recipient" account. +func (inst *CloseLookupTable) SetRecipientAccount(recipient ag_solanago.PublicKey) *CloseLookupTable { + inst.AccountMetaSlice[2] = ag_solanago.Meta(recipient).WRITE() + return inst +} + +// GetRecipientAccount gets the "recipient" account. +func (inst *CloseLookupTable) GetRecipientAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +func (inst CloseLookupTable) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: ag_binary.TypeIDFromUint8(Instruction_CloseLookupTable), + }} +} + +// 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 CloseLookupTable) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *CloseLookupTable) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.AddressLookupTable is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Owner is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.Recipient is not set") + } + } + return nil +} + +func (inst *CloseLookupTable) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("CloseLookupTable")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=3]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta("address_lookup_table", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" owner", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" recipient", inst.AccountMetaSlice.Get(2))) + }) + }) + }) +} + +func (obj CloseLookupTable) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *CloseLookupTable) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewCloseLookupTableInstruction declares a new CloseLookupTable instruction with the provided parameters and accounts. +func NewCloseLookupTableInstruction( + // Accounts: + addressLookupTable ag_solanago.PublicKey, + owner ag_solanago.PublicKey, + recipient ag_solanago.PublicKey) *CloseLookupTable { + return NewCloseLookupTableInstructionBuilder(). + SetAddressLookupTableAccount(addressLookupTable). + SetOwnerAccount(owner). + SetRecipientAccount(recipient) +} diff --git a/programs/address-lookup-table/closelookuptable_test.go b/programs/address-lookup-table/closelookuptable_test.go new file mode 100644 index 00000000..2c70f0b7 --- /dev/null +++ b/programs/address-lookup-table/closelookuptable_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package addresslookuptable + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_CloseLookupTable(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("CloseLookupTable"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(CloseLookupTable) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(CloseLookupTable) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/address-lookup-table/createlookuptable.go b/programs/address-lookup-table/createlookuptable.go new file mode 100644 index 00000000..85b172ae --- /dev/null +++ b/programs/address-lookup-table/createlookuptable.go @@ -0,0 +1,207 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package addresslookuptable + +import ( + "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" +) + +// CreateLookupTable is the `create_lookup_table` instruction. +type CreateLookupTable struct { + Slot *uint64 + BumpSeed *uint8 + + // [0] = [WRITE] address_lookup_table + // + // [1] = [SIGNER] owner + // + // [2] = [WRITE, SIGNER] payer + // + // [3] = [] system_program + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewCreateLookupTableInstructionBuilder creates a new `CreateLookupTable` instruction builder. +func NewCreateLookupTableInstructionBuilder() *CreateLookupTable { + nd := &CreateLookupTable{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 4), + } + return nd +} + +// SetSlot sets the "slot" parameter. +func (inst *CreateLookupTable) SetSlot(slot uint64) *CreateLookupTable { + inst.Slot = &slot + return inst +} + +// SetBumpSeed sets the "bump_seed" parameter. +func (inst *CreateLookupTable) SetBumpSeed(bump_seed uint8) *CreateLookupTable { + inst.BumpSeed = &bump_seed + return inst +} + +// SetAddressLookupTableAccount sets the "address_lookup_table" account. +func (inst *CreateLookupTable) SetAddressLookupTableAccount(addressLookupTable ag_solanago.PublicKey) *CreateLookupTable { + inst.AccountMetaSlice[0] = ag_solanago.Meta(addressLookupTable).WRITE() + return inst +} + +// GetAddressLookupTableAccount gets the "address_lookup_table" account. +func (inst *CreateLookupTable) GetAddressLookupTableAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetOwnerAccount sets the "owner" account. +func (inst *CreateLookupTable) SetOwnerAccount(owner ag_solanago.PublicKey) *CreateLookupTable { + inst.AccountMetaSlice[1] = ag_solanago.Meta(owner).SIGNER() + return inst +} + +// GetOwnerAccount gets the "owner" account. +func (inst *CreateLookupTable) GetOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetPayerAccount sets the "payer" account. +func (inst *CreateLookupTable) SetPayerAccount(payer ag_solanago.PublicKey) *CreateLookupTable { + inst.AccountMetaSlice[2] = ag_solanago.Meta(payer).WRITE().SIGNER() + return inst +} + +// GetPayerAccount gets the "payer" account. +func (inst *CreateLookupTable) GetPayerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetSystemProgramAccount sets the "system_program" account. +func (inst *CreateLookupTable) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *CreateLookupTable { + inst.AccountMetaSlice[3] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "system_program" account. +func (inst *CreateLookupTable) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +func (inst CreateLookupTable) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: ag_binary.TypeIDFromUint8(Instruction_CreateLookupTable), + }} +} + +// 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 CreateLookupTable) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *CreateLookupTable) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.Slot == nil { + return errors.New("Slot parameter is not set") + } + if inst.BumpSeed == nil { + return errors.New("BumpSeed parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.AddressLookupTable is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Owner is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.Payer is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.SystemProgram is not set") + } + } + return nil +} + +func (inst *CreateLookupTable) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("CreateLookupTable")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=2]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" Slot", *inst.Slot)) + paramsBranch.Child(ag_format.Param(" BumpSeed", *inst.BumpSeed)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=4]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta("address_lookup_table", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" owner", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" payer", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" system_program", inst.AccountMetaSlice.Get(3))) + }) + }) + }) +} + +func (obj CreateLookupTable) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Slot` param: + err = encoder.Encode(obj.Slot) + if err != nil { + return err + } + // Serialize `BumpSeed` param: + err = encoder.Encode(obj.BumpSeed) + if err != nil { + return err + } + return nil +} +func (obj *CreateLookupTable) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Slot`: + err = decoder.Decode(&obj.Slot) + if err != nil { + return err + } + // Deserialize `BumpSeed`: + err = decoder.Decode(&obj.BumpSeed) + if err != nil { + return err + } + return nil +} + +// NewCreateLookupTableInstruction declares a new CreateLookupTable instruction with the provided parameters and accounts. +func NewCreateLookupTableInstruction( + // Parameters: + slot uint64, + bump_seed uint8, + // Accounts: + addressLookupTable ag_solanago.PublicKey, + owner ag_solanago.PublicKey, + payer ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey) *CreateLookupTable { + return NewCreateLookupTableInstructionBuilder(). + SetSlot(slot). + SetBumpSeed(bump_seed). + SetAddressLookupTableAccount(addressLookupTable). + SetOwnerAccount(owner). + SetPayerAccount(payer). + SetSystemProgramAccount(systemProgram) +} diff --git a/programs/address-lookup-table/createlookuptable_test.go b/programs/address-lookup-table/createlookuptable_test.go new file mode 100644 index 00000000..446dd2f1 --- /dev/null +++ b/programs/address-lookup-table/createlookuptable_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package addresslookuptable + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_CreateLookupTable(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("CreateLookupTable"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(CreateLookupTable) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(CreateLookupTable) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/address-lookup-table/deactivatelookuptable.go b/programs/address-lookup-table/deactivatelookuptable.go new file mode 100644 index 00000000..690c1245 --- /dev/null +++ b/programs/address-lookup-table/deactivatelookuptable.go @@ -0,0 +1,117 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package addresslookuptable + +import ( + "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" +) + +// DeactivateLookupTable is the `deactivate_lookup_table` instruction. +type DeactivateLookupTable struct { + + // [0] = [WRITE] address_lookup_table + // + // [1] = [SIGNER] owner + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewDeactivateLookupTableInstructionBuilder creates a new `DeactivateLookupTable` instruction builder. +func NewDeactivateLookupTableInstructionBuilder() *DeactivateLookupTable { + nd := &DeactivateLookupTable{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 2), + } + return nd +} + +// SetAddressLookupTableAccount sets the "address_lookup_table" account. +func (inst *DeactivateLookupTable) SetAddressLookupTableAccount(addressLookupTable ag_solanago.PublicKey) *DeactivateLookupTable { + inst.AccountMetaSlice[0] = ag_solanago.Meta(addressLookupTable).WRITE() + return inst +} + +// GetAddressLookupTableAccount gets the "address_lookup_table" account. +func (inst *DeactivateLookupTable) GetAddressLookupTableAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetOwnerAccount sets the "owner" account. +func (inst *DeactivateLookupTable) SetOwnerAccount(owner ag_solanago.PublicKey) *DeactivateLookupTable { + inst.AccountMetaSlice[1] = ag_solanago.Meta(owner).SIGNER() + return inst +} + +// GetOwnerAccount gets the "owner" account. +func (inst *DeactivateLookupTable) GetOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +func (inst DeactivateLookupTable) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: ag_binary.TypeIDFromUint8(Instruction_DeactivateLookupTable), + }} +} + +// 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 DeactivateLookupTable) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *DeactivateLookupTable) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.AddressLookupTable is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Owner is not set") + } + } + return nil +} + +func (inst *DeactivateLookupTable) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("DeactivateLookupTable")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=2]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta("address_lookup_table", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" owner", inst.AccountMetaSlice.Get(1))) + }) + }) + }) +} + +func (obj DeactivateLookupTable) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *DeactivateLookupTable) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewDeactivateLookupTableInstruction declares a new DeactivateLookupTable instruction with the provided parameters and accounts. +func NewDeactivateLookupTableInstruction( + // Accounts: + addressLookupTable ag_solanago.PublicKey, + owner ag_solanago.PublicKey) *DeactivateLookupTable { + return NewDeactivateLookupTableInstructionBuilder(). + SetAddressLookupTableAccount(addressLookupTable). + SetOwnerAccount(owner) +} diff --git a/programs/address-lookup-table/deactivatelookuptable_test.go b/programs/address-lookup-table/deactivatelookuptable_test.go new file mode 100644 index 00000000..dbd92464 --- /dev/null +++ b/programs/address-lookup-table/deactivatelookuptable_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package addresslookuptable + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_DeactivateLookupTable(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("DeactivateLookupTable"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(DeactivateLookupTable) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(DeactivateLookupTable) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/address-lookup-table/extendlookuptable.go b/programs/address-lookup-table/extendlookuptable.go new file mode 100644 index 00000000..a990da77 --- /dev/null +++ b/programs/address-lookup-table/extendlookuptable.go @@ -0,0 +1,184 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package addresslookuptable + +import ( + "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" +) + +// ExtendLookupTable is the `extend_lookup_table` instruction. +type ExtendLookupTable struct { + NewAddresses *[]ag_solanago.PublicKey + + // [0] = [WRITE] address_lookup_table + // + // [1] = [SIGNER] owner + // + // [2] = [WRITE, SIGNER] payer + // + // [3] = [] system_program + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewExtendLookupTableInstructionBuilder creates a new `ExtendLookupTable` instruction builder. +func NewExtendLookupTableInstructionBuilder() *ExtendLookupTable { + nd := &ExtendLookupTable{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 4), + } + return nd +} + +// SetNewAddresses sets the "new_addresses" parameter. +func (inst *ExtendLookupTable) SetNewAddresses(new_addresses []ag_solanago.PublicKey) *ExtendLookupTable { + inst.NewAddresses = &new_addresses + return inst +} + +// SetAddressLookupTableAccount sets the "address_lookup_table" account. +func (inst *ExtendLookupTable) SetAddressLookupTableAccount(addressLookupTable ag_solanago.PublicKey) *ExtendLookupTable { + inst.AccountMetaSlice[0] = ag_solanago.Meta(addressLookupTable).WRITE() + return inst +} + +// GetAddressLookupTableAccount gets the "address_lookup_table" account. +func (inst *ExtendLookupTable) GetAddressLookupTableAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetOwnerAccount sets the "owner" account. +func (inst *ExtendLookupTable) SetOwnerAccount(owner ag_solanago.PublicKey) *ExtendLookupTable { + inst.AccountMetaSlice[1] = ag_solanago.Meta(owner).SIGNER() + return inst +} + +// GetOwnerAccount gets the "owner" account. +func (inst *ExtendLookupTable) GetOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetPayerAccount sets the "payer" account. +func (inst *ExtendLookupTable) SetPayerAccount(payer ag_solanago.PublicKey) *ExtendLookupTable { + inst.AccountMetaSlice[2] = ag_solanago.Meta(payer).WRITE().SIGNER() + return inst +} + +// GetPayerAccount gets the "payer" account. +func (inst *ExtendLookupTable) GetPayerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetSystemProgramAccount sets the "system_program" account. +func (inst *ExtendLookupTable) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *ExtendLookupTable { + inst.AccountMetaSlice[3] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "system_program" account. +func (inst *ExtendLookupTable) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +func (inst ExtendLookupTable) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: ag_binary.TypeIDFromUint8(Instruction_ExtendLookupTable), + }} +} + +// 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 ExtendLookupTable) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *ExtendLookupTable) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.NewAddresses == nil { + return errors.New("NewAddresses parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.AddressLookupTable is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Owner is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.Payer is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.SystemProgram is not set") + } + } + return nil +} + +func (inst *ExtendLookupTable) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("ExtendLookupTable")). + // + 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(" NewAddresses", *inst.NewAddresses)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=4]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta("address_lookup_table", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" owner", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" payer", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" system_program", inst.AccountMetaSlice.Get(3))) + }) + }) + }) +} + +func (obj ExtendLookupTable) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `NewAddresses` param: + err = encoder.Encode(obj.NewAddresses) + if err != nil { + return err + } + return nil +} +func (obj *ExtendLookupTable) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `NewAddresses`: + err = decoder.Decode(&obj.NewAddresses) + if err != nil { + return err + } + return nil +} + +// NewExtendLookupTableInstruction declares a new ExtendLookupTable instruction with the provided parameters and accounts. +func NewExtendLookupTableInstruction( + // Parameters: + new_addresses []ag_solanago.PublicKey, + // Accounts: + addressLookupTable ag_solanago.PublicKey, + owner ag_solanago.PublicKey, + payer ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey) *ExtendLookupTable { + return NewExtendLookupTableInstructionBuilder(). + SetNewAddresses(new_addresses). + SetAddressLookupTableAccount(addressLookupTable). + SetOwnerAccount(owner). + SetPayerAccount(payer). + SetSystemProgramAccount(systemProgram) +} diff --git a/programs/address-lookup-table/extendlookuptable_test.go b/programs/address-lookup-table/extendlookuptable_test.go new file mode 100644 index 00000000..c177819a --- /dev/null +++ b/programs/address-lookup-table/extendlookuptable_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package addresslookuptable + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_ExtendLookupTable(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("ExtendLookupTable"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(ExtendLookupTable) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(ExtendLookupTable) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/address-lookup-table/freezelookuptable.go b/programs/address-lookup-table/freezelookuptable.go new file mode 100644 index 00000000..184dd6e9 --- /dev/null +++ b/programs/address-lookup-table/freezelookuptable.go @@ -0,0 +1,117 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package addresslookuptable + +import ( + "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" +) + +// FreezeLookupTable is the `freeze_lookup_table` instruction. +type FreezeLookupTable struct { + + // [0] = [WRITE] address_lookup_table + // + // [1] = [SIGNER] owner + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewFreezeLookupTableInstructionBuilder creates a new `FreezeLookupTable` instruction builder. +func NewFreezeLookupTableInstructionBuilder() *FreezeLookupTable { + nd := &FreezeLookupTable{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 2), + } + return nd +} + +// SetAddressLookupTableAccount sets the "address_lookup_table" account. +func (inst *FreezeLookupTable) SetAddressLookupTableAccount(addressLookupTable ag_solanago.PublicKey) *FreezeLookupTable { + inst.AccountMetaSlice[0] = ag_solanago.Meta(addressLookupTable).WRITE() + return inst +} + +// GetAddressLookupTableAccount gets the "address_lookup_table" account. +func (inst *FreezeLookupTable) GetAddressLookupTableAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetOwnerAccount sets the "owner" account. +func (inst *FreezeLookupTable) SetOwnerAccount(owner ag_solanago.PublicKey) *FreezeLookupTable { + inst.AccountMetaSlice[1] = ag_solanago.Meta(owner).SIGNER() + return inst +} + +// GetOwnerAccount gets the "owner" account. +func (inst *FreezeLookupTable) GetOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +func (inst FreezeLookupTable) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: ag_binary.TypeIDFromUint8(Instruction_FreezeLookupTable), + }} +} + +// 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 FreezeLookupTable) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *FreezeLookupTable) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.AddressLookupTable is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Owner is not set") + } + } + return nil +} + +func (inst *FreezeLookupTable) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("FreezeLookupTable")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=2]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta("address_lookup_table", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" owner", inst.AccountMetaSlice.Get(1))) + }) + }) + }) +} + +func (obj FreezeLookupTable) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *FreezeLookupTable) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewFreezeLookupTableInstruction declares a new FreezeLookupTable instruction with the provided parameters and accounts. +func NewFreezeLookupTableInstruction( + // Accounts: + addressLookupTable ag_solanago.PublicKey, + owner ag_solanago.PublicKey) *FreezeLookupTable { + return NewFreezeLookupTableInstructionBuilder(). + SetAddressLookupTableAccount(addressLookupTable). + SetOwnerAccount(owner) +} diff --git a/programs/address-lookup-table/freezelookuptable_test.go b/programs/address-lookup-table/freezelookuptable_test.go new file mode 100644 index 00000000..426df9a6 --- /dev/null +++ b/programs/address-lookup-table/freezelookuptable_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package addresslookuptable + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_FreezeLookupTable(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("FreezeLookupTable"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(FreezeLookupTable) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(FreezeLookupTable) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/address-lookup-table/instructions.go b/programs/address-lookup-table/instructions.go new file mode 100644 index 00000000..9b75a631 --- /dev/null +++ b/programs/address-lookup-table/instructions.go @@ -0,0 +1,167 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package addresslookuptable + +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(PublicKey ag_solanago.PublicKey) { + ProgramID = PublicKey + ag_solanago.RegisterInstructionDecoder(ProgramID, registryDecodeInstruction) +} + +const ProgramName = "AddressLookupTable" + +func init() { + if !ProgramID.IsZero() { + ag_solanago.RegisterInstructionDecoder(ProgramID, registryDecodeInstruction) + } +} + +const ( + Instruction_CloseLookupTable uint8 = iota + + Instruction_CreateLookupTable + + Instruction_DeactivateLookupTable + + Instruction_ExtendLookupTable + + Instruction_FreezeLookupTable +) + +// InstructionIDToName returns the name of the instruction given its ID. +func InstructionIDToName(id uint8) string { + switch id { + case Instruction_CloseLookupTable: + return "CloseLookupTable" + case Instruction_CreateLookupTable: + return "CreateLookupTable" + case Instruction_DeactivateLookupTable: + return "DeactivateLookupTable" + case Instruction_ExtendLookupTable: + return "ExtendLookupTable" + case Instruction_FreezeLookupTable: + return "FreezeLookupTable" + 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.Uint8TypeIDEncoding, + []ag_binary.VariantType{ + { + "CloseLookupTable", (*CloseLookupTable)(nil), + }, + { + "CreateLookupTable", (*CreateLookupTable)(nil), + }, + { + "DeactivateLookupTable", (*DeactivateLookupTable)(nil), + }, + { + "ExtendLookupTable", (*ExtendLookupTable)(nil), + }, + { + "FreezeLookupTable", (*FreezeLookupTable)(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.WriteUint8(inst.TypeID.Uint8()) + 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 +} + +func DecodeInstructions(message *ag_solanago.Message) (instructions []*Instruction, err error) { + for _, ins := range message.Instructions { + var programID ag_solanago.PublicKey + if programID, err = message.Program(ins.ProgramIDIndex); err != nil { + return + } + if !programID.Equals(ProgramID) { + continue + } + var accounts []*ag_solanago.AccountMeta + if accounts, err = ins.ResolveInstructionAccounts(message); err != nil { + return + } + var insDecoded *Instruction + if insDecoded, err = decodeInstruction(accounts, ins.Data); err != nil { + return + } + instructions = append(instructions, insDecoded) + } + return +} diff --git a/programs/address-lookup-table/testing_utils.go b/programs/address-lookup-table/testing_utils.go new file mode 100644 index 00000000..e5bed038 --- /dev/null +++ b/programs/address-lookup-table/testing_utils.go @@ -0,0 +1,20 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package addresslookuptable + +import ( + "bytes" + "fmt" + ag_binary "github.com/gagliardetto/binary" +) + +func encodeT(data interface{}, buf *bytes.Buffer) error { + if err := ag_binary.NewBorshEncoder(buf).Encode(data); err != nil { + return fmt.Errorf("unable to encode instruction: %w", err) + } + return nil +} + +func decodeT(dst interface{}, data []byte) error { + return ag_binary.NewBorshDecoder(data).Decode(dst) +} diff --git a/programs/associated-token-account/Create.go b/programs/associated-token-account/Create.go index 4456f747..396f6239 100644 --- a/programs/associated-token-account/Create.go +++ b/programs/associated-token-account/Create.go @@ -1,135 +1,129 @@ -// Copyright 2021 github.com/gagliardetto -// -// 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 associatedtokenaccount +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package associated_token_account import ( "errors" - "fmt" - - bin "github.com/gagliardetto/binary" - solana "github.com/gagliardetto/solana-go" - format "github.com/gagliardetto/solana-go/text/format" - treeout "github.com/gagliardetto/treeout" + 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" ) +// Create is the `create` instruction. type Create struct { - Payer solana.PublicKey `bin:"-" borsh_skip:"true"` - Wallet solana.PublicKey `bin:"-" borsh_skip:"true"` - Mint solana.PublicKey `bin:"-" borsh_skip:"true"` - // [0] = [WRITE, SIGNER] Payer - // ··········· Funding account + // [0] = [WRITE, SIGNER] payer // - // [1] = [WRITE] AssociatedTokenAccount - // ··········· Associated token account address to be created + // [1] = [WRITE] associated_token_account // - // [2] = [] Wallet - // ··········· Wallet address for the new associated token account + // [2] = [] wallet // - // [3] = [] TokenMint - // ··········· The token mint for the new associated token account + // [3] = [] mint // - // [4] = [] SystemProgram - // ··········· System program ID + // [4] = [] system_program // - // [5] = [] TokenProgram - // ··········· SPL token program ID + // [5] = [] token_program // - // [6] = [] SysVarRent - // ··········· SysVarRentPubkey - solana.AccountMetaSlice `bin:"-" borsh_skip:"true"` + // [6] = [] sysvar_rent + ag_solanago.AccountMetaSlice `bin:"-"` } // NewCreateInstructionBuilder creates a new `Create` instruction builder. func NewCreateInstructionBuilder() *Create { - nd := &Create{} + nd := &Create{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 7), + } return nd } -func (inst *Create) SetPayer(payer solana.PublicKey) *Create { - inst.Payer = payer +// SetPayerAccount sets the "payer" account. +func (inst *Create) SetPayerAccount(payer ag_solanago.PublicKey) *Create { + inst.AccountMetaSlice[0] = ag_solanago.Meta(payer).WRITE().SIGNER() return inst } -func (inst *Create) SetWallet(wallet solana.PublicKey) *Create { - inst.Wallet = wallet +// GetPayerAccount gets the "payer" account. +func (inst *Create) GetPayerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetAssociatedTokenAccount sets the "associated_token_account" account. +func (inst *Create) SetAssociatedTokenAccount(associatedTokenAccount ag_solanago.PublicKey) *Create { + inst.AccountMetaSlice[1] = ag_solanago.Meta(associatedTokenAccount).WRITE() return inst } -func (inst *Create) SetMint(mint solana.PublicKey) *Create { - inst.Mint = mint +// GetAssociatedTokenAccount gets the "associated_token_account" account. +func (inst *Create) GetAssociatedTokenAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetWalletAccount sets the "wallet" account. +func (inst *Create) SetWalletAccount(wallet ag_solanago.PublicKey) *Create { + inst.AccountMetaSlice[2] = ag_solanago.Meta(wallet) return inst } -func (inst Create) Build() *Instruction { +// GetWalletAccount gets the "wallet" account. +func (inst *Create) GetWalletAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} - // Find the associatedTokenAddress; - associatedTokenAddress, _, _ := solana.FindAssociatedTokenAddress( - inst.Wallet, - inst.Mint, - ) +// SetMintAccount sets the "mint" account. +func (inst *Create) SetMintAccount(mint ag_solanago.PublicKey) *Create { + inst.AccountMetaSlice[3] = ag_solanago.Meta(mint) + return inst +} - keys := []*solana.AccountMeta{ - { - PublicKey: inst.Payer, - IsSigner: true, - IsWritable: true, - }, - { - PublicKey: associatedTokenAddress, - IsSigner: false, - IsWritable: true, - }, - { - PublicKey: inst.Wallet, - IsSigner: false, - IsWritable: false, - }, - { - PublicKey: inst.Mint, - IsSigner: false, - IsWritable: false, - }, - { - PublicKey: solana.SystemProgramID, - IsSigner: false, - IsWritable: false, - }, - { - PublicKey: solana.TokenProgramID, - IsSigner: false, - IsWritable: false, - }, - { - PublicKey: solana.SysVarRentPubkey, - IsSigner: false, - IsWritable: false, - }, - } +// GetMintAccount gets the "mint" account. +func (inst *Create) GetMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetSystemProgramAccount sets the "system_program" account. +func (inst *Create) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *Create { + inst.AccountMetaSlice[4] = ag_solanago.Meta(systemProgram) + return inst +} - inst.AccountMetaSlice = keys +// GetSystemProgramAccount gets the "system_program" account. +func (inst *Create) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} - return &Instruction{BaseVariant: bin.BaseVariant{ +// SetTokenProgramAccount sets the "token_program" account. +func (inst *Create) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *Create { + inst.AccountMetaSlice[5] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "token_program" account. +func (inst *Create) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetSysvarRentAccount sets the "sysvar_rent" account. +func (inst *Create) SetSysvarRentAccount(sysvarRent ag_solanago.PublicKey) *Create { + inst.AccountMetaSlice[6] = ag_solanago.Meta(sysvarRent) + return inst +} + +// GetSysvarRentAccount gets the "sysvar_rent" account. +func (inst *Create) GetSysvarRentAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +func (inst Create) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ Impl: inst, - TypeID: bin.NoTypeIDDefaultID, + TypeID: ag_binary.TypeIDFromUint8(Instruction_Create), }} } -// ValidateAndBuild validates the instruction accounts. -// If there is a validation error, return the error. -// Otherwise, build and return the instruction. +// 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 Create) ValidateAndBuild() (*Instruction, error) { if err := inst.Validate(); err != nil { return nil, err @@ -138,65 +132,103 @@ func (inst Create) ValidateAndBuild() (*Instruction, error) { } func (inst *Create) Validate() error { - if inst.Payer.IsZero() { - return errors.New("Payer not set") - } - if inst.Wallet.IsZero() { - return errors.New("Wallet not set") - } - if inst.Mint.IsZero() { - return errors.New("Mint not set") - } - _, _, err := solana.FindAssociatedTokenAddress( - inst.Wallet, - inst.Mint, - ) - if err != nil { - return fmt.Errorf("error while FindAssociatedTokenAddress: %w", err) + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Payer is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.AssociatedTokenAccount is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.Wallet is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.Mint is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.SystemProgram is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.SysvarRent is not set") + } } return nil } -func (inst *Create) EncodeToTree(parent treeout.Branches) { - parent.Child(format.Program(ProgramName, ProgramID)). +func (inst *Create) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). // - ParentFunc(func(programBranch treeout.Branches) { - programBranch.Child(format.Instruction("Create")). + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("Create")). // - ParentFunc(func(instructionBranch treeout.Branches) { + ParentFunc(func(instructionBranch ag_treeout.Branches) { // Parameters of the instruction: - instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch treeout.Branches) {}) + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) // Accounts of the instruction: - instructionBranch.Child("Accounts[len=7").ParentFunc(func(accountsBranch treeout.Branches) { - accountsBranch.Child(format.Meta(" payer", inst.AccountMetaSlice.Get(0))) - accountsBranch.Child(format.Meta("associatedTokenAddress", inst.AccountMetaSlice.Get(1))) - accountsBranch.Child(format.Meta(" wallet", inst.AccountMetaSlice.Get(2))) - accountsBranch.Child(format.Meta(" tokenMint", inst.AccountMetaSlice.Get(3))) - accountsBranch.Child(format.Meta(" systemProgram", inst.AccountMetaSlice.Get(4))) - accountsBranch.Child(format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(5))) - accountsBranch.Child(format.Meta(" sysVarRent", inst.AccountMetaSlice.Get(6))) + instructionBranch.Child("Accounts[len=7]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" payer", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta("associated_token_", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" wallet", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" mint", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" system_program", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" token_program", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" sysvar_rent", inst.AccountMetaSlice.Get(6))) }) }) }) } -func (inst Create) MarshalWithEncoder(encoder *bin.Encoder) error { - return encoder.WriteBytes([]byte{}, false) +func (obj Create) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil } - -func (inst *Create) UnmarshalWithDecoder(decoder *bin.Decoder) error { +func (obj *Create) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { return nil } +// NewCreateInstruction declares a new Create instruction with the provided parameters and accounts. func NewCreateInstruction( - payer solana.PublicKey, - walletAddress solana.PublicKey, - splTokenMintAddress solana.PublicKey, -) *Create { + // Accounts: + payer ag_solanago.PublicKey, + associatedTokenAccount ag_solanago.PublicKey, + wallet ag_solanago.PublicKey, + mint ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + sysvarRent ag_solanago.PublicKey) *Create { + return NewCreateInstructionBuilder(). + SetPayerAccount(payer). + SetAssociatedTokenAccount(associatedTokenAccount). + SetWalletAccount(wallet). + SetMintAccount(mint). + SetSystemProgramAccount(systemProgram). + SetTokenProgramAccount(tokenProgram). + SetSysvarRentAccount(sysvarRent) +} + +// NewCreateInstruction declares a new Create instruction with the provided parameters and accounts. +func NewCreateInstructionWithDerivation( +// Accounts: + payer ag_solanago.PublicKey, + wallet ag_solanago.PublicKey, + mint ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey) *Create { + associatedTokenAccount, _, _ := ag_solanago.FindAssociatedTokenAddress( + wallet, + mint, + tokenProgram, + ) return NewCreateInstructionBuilder(). - SetPayer(payer). - SetWallet(walletAddress). - SetMint(splTokenMintAddress) + SetPayerAccount(payer). + SetAssociatedTokenAccount(associatedTokenAccount). + SetWalletAccount(wallet). + SetMintAccount(mint). + SetSystemProgramAccount(ag_solanago.SystemProgramID). + SetTokenProgramAccount(tokenProgram). + SetSysvarRentAccount(ag_solanago.SysVarRentPubkey) } diff --git a/programs/associated-token-account/create_test.go b/programs/associated-token-account/create_test.go new file mode 100644 index 00000000..4db0bb0f --- /dev/null +++ b/programs/associated-token-account/create_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package associated_token_account + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_Create(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("Create"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(Create) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(Create) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/associated-token-account/createidempotent.go b/programs/associated-token-account/createidempotent.go new file mode 100644 index 00000000..17908f29 --- /dev/null +++ b/programs/associated-token-account/createidempotent.go @@ -0,0 +1,234 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package associated_token_account + +import ( + "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" +) + +// CreateIdempotent is the `create_idempotent` instruction. +type CreateIdempotent struct { + + // [0] = [WRITE, SIGNER] payer + // + // [1] = [WRITE] associated_token_account + // + // [2] = [] wallet + // + // [3] = [] mint + // + // [4] = [] system_program + // + // [5] = [] token_program + // + // [6] = [] sysvar_rent + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewCreateIdempotentInstructionBuilder creates a new `CreateIdempotent` instruction builder. +func NewCreateIdempotentInstructionBuilder() *CreateIdempotent { + nd := &CreateIdempotent{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 7), + } + return nd +} + +// SetPayerAccount sets the "payer" account. +func (inst *CreateIdempotent) SetPayerAccount(payer ag_solanago.PublicKey) *CreateIdempotent { + inst.AccountMetaSlice[0] = ag_solanago.Meta(payer).WRITE().SIGNER() + return inst +} + +// GetPayerAccount gets the "payer" account. +func (inst *CreateIdempotent) GetPayerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetAssociatedTokenAccount sets the "associated_token_account" account. +func (inst *CreateIdempotent) SetAssociatedTokenAccount(associatedTokenAccount ag_solanago.PublicKey) *CreateIdempotent { + inst.AccountMetaSlice[1] = ag_solanago.Meta(associatedTokenAccount).WRITE() + return inst +} + +// GetAssociatedTokenAccount gets the "associated_token_account" account. +func (inst *CreateIdempotent) GetAssociatedTokenAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetWalletAccount sets the "wallet" account. +func (inst *CreateIdempotent) SetWalletAccount(wallet ag_solanago.PublicKey) *CreateIdempotent { + inst.AccountMetaSlice[2] = ag_solanago.Meta(wallet) + return inst +} + +// GetWalletAccount gets the "wallet" account. +func (inst *CreateIdempotent) GetWalletAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetMintAccount sets the "mint" account. +func (inst *CreateIdempotent) SetMintAccount(mint ag_solanago.PublicKey) *CreateIdempotent { + inst.AccountMetaSlice[3] = ag_solanago.Meta(mint) + return inst +} + +// GetMintAccount gets the "mint" account. +func (inst *CreateIdempotent) GetMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetSystemProgramAccount sets the "system_program" account. +func (inst *CreateIdempotent) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *CreateIdempotent { + inst.AccountMetaSlice[4] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "system_program" account. +func (inst *CreateIdempotent) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetTokenProgramAccount sets the "token_program" account. +func (inst *CreateIdempotent) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *CreateIdempotent { + inst.AccountMetaSlice[5] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "token_program" account. +func (inst *CreateIdempotent) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetSysvarRentAccount sets the "sysvar_rent" account. +func (inst *CreateIdempotent) SetSysvarRentAccount(sysvarRent ag_solanago.PublicKey) *CreateIdempotent { + inst.AccountMetaSlice[6] = ag_solanago.Meta(sysvarRent) + return inst +} + +// GetSysvarRentAccount gets the "sysvar_rent" account. +func (inst *CreateIdempotent) GetSysvarRentAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +func (inst CreateIdempotent) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: ag_binary.TypeIDFromUint8(Instruction_CreateIdempotent), + }} +} + +// 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 CreateIdempotent) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *CreateIdempotent) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Payer is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.AssociatedTokenAccount is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.Wallet is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.Mint is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.SystemProgram is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.SysvarRent is not set") + } + } + return nil +} + +func (inst *CreateIdempotent) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("CreateIdempotent")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=7]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" payer", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta("associated_token_", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" wallet", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" mint", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" system_program", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" token_program", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" sysvar_rent", inst.AccountMetaSlice.Get(6))) + }) + }) + }) +} + +func (obj CreateIdempotent) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *CreateIdempotent) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewCreateIdempotentInstruction declares a new CreateIdempotent instruction with the provided parameters and accounts. +func NewCreateIdempotentInstruction( + // Accounts: + payer ag_solanago.PublicKey, + associatedTokenAccount ag_solanago.PublicKey, + wallet ag_solanago.PublicKey, + mint ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + sysvarRent ag_solanago.PublicKey) *CreateIdempotent { + return NewCreateIdempotentInstructionBuilder(). + SetPayerAccount(payer). + SetAssociatedTokenAccount(associatedTokenAccount). + SetWalletAccount(wallet). + SetMintAccount(mint). + SetSystemProgramAccount(systemProgram). + SetTokenProgramAccount(tokenProgram). + SetSysvarRentAccount(sysvarRent) +} + + +func NewCreateIdempotentInstructionWithDerivation( +// Accounts: + payer ag_solanago.PublicKey, + wallet ag_solanago.PublicKey, + mint ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey) *CreateIdempotent { + associatedTokenAccount, _, _ := ag_solanago.FindAssociatedTokenAddress( + wallet, + mint, + tokenProgram, + ) + return NewCreateIdempotentInstructionBuilder(). + SetPayerAccount(payer). + SetAssociatedTokenAccount(associatedTokenAccount). + SetWalletAccount(wallet). + SetMintAccount(mint). + SetSystemProgramAccount(ag_solanago.SystemProgramID). + SetTokenProgramAccount(tokenProgram). + SetSysvarRentAccount(ag_solanago.SysVarRentPubkey) +} diff --git a/programs/associated-token-account/createidempotent_test.go b/programs/associated-token-account/createidempotent_test.go new file mode 100644 index 00000000..8077705e --- /dev/null +++ b/programs/associated-token-account/createidempotent_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package associated_token_account + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_CreateIdempotent(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("CreateIdempotent"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(CreateIdempotent) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(CreateIdempotent) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/associated-token-account/instructions.go b/programs/associated-token-account/instructions.go index b0ac3140..710c3f8e 100644 --- a/programs/associated-token-account/instructions.go +++ b/programs/associated-token-account/instructions.go @@ -1,101 +1,120 @@ -// Copyright 2021 github.com/gagliardetto -// -// 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 associatedtokenaccount +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package associated_token_account import ( + "bytes" "fmt" - - spew "github.com/davecgh/go-spew/spew" - bin "github.com/gagliardetto/binary" - solana "github.com/gagliardetto/solana-go" - text "github.com/gagliardetto/solana-go/text" - treeout "github.com/gagliardetto/treeout" + 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 solana.PublicKey = solana.SPLAssociatedTokenAccountProgramID +var ProgramID ag_solanago.PublicKey -func SetProgramID(pubkey solana.PublicKey) { - ProgramID = pubkey - solana.RegisterInstructionDecoder(ProgramID, registryDecodeInstruction) +func SetProgramID(PublicKey ag_solanago.PublicKey) { + ProgramID = PublicKey + ag_solanago.RegisterInstructionDecoder(ProgramID, registryDecodeInstruction) } const ProgramName = "AssociatedTokenAccount" func init() { - solana.RegisterInstructionDecoder(ProgramID, registryDecodeInstruction) + if !ProgramID.IsZero() { + ag_solanago.RegisterInstructionDecoder(ProgramID, registryDecodeInstruction) + } +} + +const ( + Instruction_Create uint8 = iota + + Instruction_CreateIdempotent +) + +// InstructionIDToName returns the name of the instruction given its ID. +func InstructionIDToName(id uint8) string { + switch id { + case Instruction_Create: + return "Create" + case Instruction_CreateIdempotent: + return "CreateIdempotent" + default: + return "" + } } type Instruction struct { - bin.BaseVariant + ag_binary.BaseVariant } -func (inst *Instruction) EncodeToTree(parent treeout.Branches) { - if enToTree, ok := inst.Impl.(text.EncodableToTree); ok { +func (inst *Instruction) EncodeToTree(parent ag_treeout.Branches) { + if enToTree, ok := inst.Impl.(ag_text.EncodableToTree); ok { enToTree.EncodeToTree(parent) } else { - parent.Child(spew.Sdump(inst)) + parent.Child(ag_spew.Sdump(inst)) } } -var InstructionImplDef = bin.NewVariantDefinition( - bin.NoTypeIDEncoding, // NOTE: the associated-token-account program has no ID encoding. - []bin.VariantType{ +var InstructionImplDef = ag_binary.NewVariantDefinition( + ag_binary.Uint8TypeIDEncoding, + []ag_binary.VariantType{ { "Create", (*Create)(nil), }, + { + "CreateIdempotent", (*CreateIdempotent)(nil), + }, }, ) -func (inst *Instruction) ProgramID() solana.PublicKey { +func (inst *Instruction) ProgramID() ag_solanago.PublicKey { return ProgramID } -func (inst *Instruction) Accounts() (out []*solana.AccountMeta) { - return inst.Impl.(solana.AccountsGettable).GetAccounts() +func (inst *Instruction) Accounts() (out []*ag_solanago.AccountMeta) { + return inst.Impl.(ag_solanago.AccountsGettable).GetAccounts() } func (inst *Instruction) Data() ([]byte, error) { - return []byte{}, nil + 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 *text.Encoder, option *text.Option) error { +func (inst *Instruction) TextEncode(encoder *ag_text.Encoder, option *ag_text.Option) error { return encoder.Encode(inst.Impl, option) } -func (inst *Instruction) UnmarshalWithDecoder(decoder *bin.Decoder) error { +func (inst *Instruction) UnmarshalWithDecoder(decoder *ag_binary.Decoder) error { return inst.BaseVariant.UnmarshalBinaryVariant(decoder, InstructionImplDef) } -func (inst Instruction) MarshalWithEncoder(encoder *bin.Encoder) error { +func (inst *Instruction) MarshalWithEncoder(encoder *ag_binary.Encoder) error { + err := encoder.WriteUint8(inst.TypeID.Uint8()) + if err != nil { + return fmt.Errorf("unable to write variant type: %w", err) + } return encoder.Encode(inst.Impl) } -func registryDecodeInstruction(accounts []*solana.AccountMeta, data []byte) (interface{}, error) { - inst, err := DecodeInstruction(accounts, data) +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 []*solana.AccountMeta, data []byte) (*Instruction, error) { +func decodeInstruction(accounts []*ag_solanago.AccountMeta, data []byte) (*Instruction, error) { inst := new(Instruction) - if err := bin.NewBinDecoder(data).Decode(inst); err != nil { + 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.(solana.AccountsSettable); ok { + 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) @@ -103,3 +122,25 @@ func DecodeInstruction(accounts []*solana.AccountMeta, data []byte) (*Instructio } return inst, nil } + +func DecodeInstructions(message *ag_solanago.Message) (instructions []*Instruction, err error) { + for _, ins := range message.Instructions { + var programID ag_solanago.PublicKey + if programID, err = message.Program(ins.ProgramIDIndex); err != nil { + return + } + if !programID.Equals(ProgramID) { + continue + } + var accounts []*ag_solanago.AccountMeta + if accounts, err = ins.ResolveInstructionAccounts(message); err != nil { + return + } + var insDecoded *Instruction + if insDecoded, err = decodeInstruction(accounts, ins.Data); err != nil { + return + } + instructions = append(instructions, insDecoded) + } + return +} diff --git a/programs/associated-token-account/testing_utils.go b/programs/associated-token-account/testing_utils.go new file mode 100644 index 00000000..c6a215b7 --- /dev/null +++ b/programs/associated-token-account/testing_utils.go @@ -0,0 +1,20 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package associated_token_account + +import ( + "bytes" + "fmt" + ag_binary "github.com/gagliardetto/binary" +) + +func encodeT(data interface{}, buf *bytes.Buffer) error { + if err := ag_binary.NewBorshEncoder(buf).Encode(data); err != nil { + return fmt.Errorf("unable to encode instruction: %w", err) + } + return nil +} + +func decodeT(dst interface{}, data []byte) error { + return ag_binary.NewBorshDecoder(data).Decode(dst) +} diff --git a/programs/raydiumamm/AdminCancelOrders.go b/programs/raydiumamm/AdminCancelOrders.go new file mode 100644 index 00000000..6cc58d13 --- /dev/null +++ b/programs/raydiumamm/AdminCancelOrders.go @@ -0,0 +1,431 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package raydium_amm + +import ( + "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" +) + +// AdminCancelOrders is the `adminCancelOrders` instruction. +type AdminCancelOrders struct { + Limit *uint16 + + // [0] = [] tokenProgram + // + // [1] = [] amm + // + // [2] = [] ammAuthority + // + // [3] = [WRITE] ammOpenOrders + // + // [4] = [WRITE] ammTargetOrders + // + // [5] = [WRITE] poolCoinTokenAccount + // + // [6] = [WRITE] poolPcTokenAccount + // + // [7] = [SIGNER] ammOwnerAccount + // + // [8] = [WRITE] ammConfig + // + // [9] = [] serumProgram + // + // [10] = [WRITE] serumMarket + // + // [11] = [WRITE] serumCoinVaultAccount + // + // [12] = [WRITE] serumPcVaultAccount + // + // [13] = [] serumVaultSigner + // + // [14] = [WRITE] serumEventQ + // + // [15] = [WRITE] serumBids + // + // [16] = [WRITE] serumAsks + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewAdminCancelOrdersInstructionBuilder creates a new `AdminCancelOrders` instruction builder. +func NewAdminCancelOrdersInstructionBuilder() *AdminCancelOrders { + nd := &AdminCancelOrders{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 17), + } + return nd +} + +// SetLimit sets the "limit" parameter. +func (inst *AdminCancelOrders) SetLimit(limit uint16) *AdminCancelOrders { + inst.Limit = &limit + return inst +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *AdminCancelOrders) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *AdminCancelOrders { + inst.AccountMetaSlice[0] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *AdminCancelOrders) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetAmmAccount sets the "amm" account. +func (inst *AdminCancelOrders) SetAmmAccount(amm ag_solanago.PublicKey) *AdminCancelOrders { + inst.AccountMetaSlice[1] = ag_solanago.Meta(amm) + return inst +} + +// GetAmmAccount gets the "amm" account. +func (inst *AdminCancelOrders) GetAmmAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetAmmAuthorityAccount sets the "ammAuthority" account. +func (inst *AdminCancelOrders) SetAmmAuthorityAccount(ammAuthority ag_solanago.PublicKey) *AdminCancelOrders { + inst.AccountMetaSlice[2] = ag_solanago.Meta(ammAuthority) + return inst +} + +// GetAmmAuthorityAccount gets the "ammAuthority" account. +func (inst *AdminCancelOrders) GetAmmAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetAmmOpenOrdersAccount sets the "ammOpenOrders" account. +func (inst *AdminCancelOrders) SetAmmOpenOrdersAccount(ammOpenOrders ag_solanago.PublicKey) *AdminCancelOrders { + inst.AccountMetaSlice[3] = ag_solanago.Meta(ammOpenOrders).WRITE() + return inst +} + +// GetAmmOpenOrdersAccount gets the "ammOpenOrders" account. +func (inst *AdminCancelOrders) GetAmmOpenOrdersAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetAmmTargetOrdersAccount sets the "ammTargetOrders" account. +func (inst *AdminCancelOrders) SetAmmTargetOrdersAccount(ammTargetOrders ag_solanago.PublicKey) *AdminCancelOrders { + inst.AccountMetaSlice[4] = ag_solanago.Meta(ammTargetOrders).WRITE() + return inst +} + +// GetAmmTargetOrdersAccount gets the "ammTargetOrders" account. +func (inst *AdminCancelOrders) GetAmmTargetOrdersAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetPoolCoinTokenAccountAccount sets the "poolCoinTokenAccount" account. +func (inst *AdminCancelOrders) SetPoolCoinTokenAccountAccount(poolCoinTokenAccount ag_solanago.PublicKey) *AdminCancelOrders { + inst.AccountMetaSlice[5] = ag_solanago.Meta(poolCoinTokenAccount).WRITE() + return inst +} + +// GetPoolCoinTokenAccountAccount gets the "poolCoinTokenAccount" account. +func (inst *AdminCancelOrders) GetPoolCoinTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetPoolPcTokenAccountAccount sets the "poolPcTokenAccount" account. +func (inst *AdminCancelOrders) SetPoolPcTokenAccountAccount(poolPcTokenAccount ag_solanago.PublicKey) *AdminCancelOrders { + inst.AccountMetaSlice[6] = ag_solanago.Meta(poolPcTokenAccount).WRITE() + return inst +} + +// GetPoolPcTokenAccountAccount gets the "poolPcTokenAccount" account. +func (inst *AdminCancelOrders) GetPoolPcTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetAmmOwnerAccountAccount sets the "ammOwnerAccount" account. +func (inst *AdminCancelOrders) SetAmmOwnerAccountAccount(ammOwnerAccount ag_solanago.PublicKey) *AdminCancelOrders { + inst.AccountMetaSlice[7] = ag_solanago.Meta(ammOwnerAccount).SIGNER() + return inst +} + +// GetAmmOwnerAccountAccount gets the "ammOwnerAccount" account. +func (inst *AdminCancelOrders) GetAmmOwnerAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetAmmConfigAccount sets the "ammConfig" account. +func (inst *AdminCancelOrders) SetAmmConfigAccount(ammConfig ag_solanago.PublicKey) *AdminCancelOrders { + inst.AccountMetaSlice[8] = ag_solanago.Meta(ammConfig).WRITE() + return inst +} + +// GetAmmConfigAccount gets the "ammConfig" account. +func (inst *AdminCancelOrders) GetAmmConfigAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetSerumProgramAccount sets the "serumProgram" account. +func (inst *AdminCancelOrders) SetSerumProgramAccount(serumProgram ag_solanago.PublicKey) *AdminCancelOrders { + inst.AccountMetaSlice[9] = ag_solanago.Meta(serumProgram) + return inst +} + +// GetSerumProgramAccount gets the "serumProgram" account. +func (inst *AdminCancelOrders) GetSerumProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetSerumMarketAccount sets the "serumMarket" account. +func (inst *AdminCancelOrders) SetSerumMarketAccount(serumMarket ag_solanago.PublicKey) *AdminCancelOrders { + inst.AccountMetaSlice[10] = ag_solanago.Meta(serumMarket).WRITE() + return inst +} + +// GetSerumMarketAccount gets the "serumMarket" account. +func (inst *AdminCancelOrders) GetSerumMarketAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetSerumCoinVaultAccountAccount sets the "serumCoinVaultAccount" account. +func (inst *AdminCancelOrders) SetSerumCoinVaultAccountAccount(serumCoinVaultAccount ag_solanago.PublicKey) *AdminCancelOrders { + inst.AccountMetaSlice[11] = ag_solanago.Meta(serumCoinVaultAccount).WRITE() + return inst +} + +// GetSerumCoinVaultAccountAccount gets the "serumCoinVaultAccount" account. +func (inst *AdminCancelOrders) GetSerumCoinVaultAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetSerumPcVaultAccountAccount sets the "serumPcVaultAccount" account. +func (inst *AdminCancelOrders) SetSerumPcVaultAccountAccount(serumPcVaultAccount ag_solanago.PublicKey) *AdminCancelOrders { + inst.AccountMetaSlice[12] = ag_solanago.Meta(serumPcVaultAccount).WRITE() + return inst +} + +// GetSerumPcVaultAccountAccount gets the "serumPcVaultAccount" account. +func (inst *AdminCancelOrders) GetSerumPcVaultAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetSerumVaultSignerAccount sets the "serumVaultSigner" account. +func (inst *AdminCancelOrders) SetSerumVaultSignerAccount(serumVaultSigner ag_solanago.PublicKey) *AdminCancelOrders { + inst.AccountMetaSlice[13] = ag_solanago.Meta(serumVaultSigner) + return inst +} + +// GetSerumVaultSignerAccount gets the "serumVaultSigner" account. +func (inst *AdminCancelOrders) GetSerumVaultSignerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetSerumEventQAccount sets the "serumEventQ" account. +func (inst *AdminCancelOrders) SetSerumEventQAccount(serumEventQ ag_solanago.PublicKey) *AdminCancelOrders { + inst.AccountMetaSlice[14] = ag_solanago.Meta(serumEventQ).WRITE() + return inst +} + +// GetSerumEventQAccount gets the "serumEventQ" account. +func (inst *AdminCancelOrders) GetSerumEventQAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +// SetSerumBidsAccount sets the "serumBids" account. +func (inst *AdminCancelOrders) SetSerumBidsAccount(serumBids ag_solanago.PublicKey) *AdminCancelOrders { + inst.AccountMetaSlice[15] = ag_solanago.Meta(serumBids).WRITE() + return inst +} + +// GetSerumBidsAccount gets the "serumBids" account. +func (inst *AdminCancelOrders) GetSerumBidsAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(15) +} + +// SetSerumAsksAccount sets the "serumAsks" account. +func (inst *AdminCancelOrders) SetSerumAsksAccount(serumAsks ag_solanago.PublicKey) *AdminCancelOrders { + inst.AccountMetaSlice[16] = ag_solanago.Meta(serumAsks).WRITE() + return inst +} + +// GetSerumAsksAccount gets the "serumAsks" account. +func (inst *AdminCancelOrders) GetSerumAsksAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(16) +} + +func (inst AdminCancelOrders) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: ag_binary.TypeIDFromUint8(Instruction_AdminCancelOrders), + }} +} + +// 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 AdminCancelOrders) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *AdminCancelOrders) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.Limit == nil { + return errors.New("Limit parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Amm is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.AmmAuthority is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.AmmOpenOrders is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.AmmTargetOrders is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.PoolCoinTokenAccount is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.PoolPcTokenAccount is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.AmmOwnerAccount is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.AmmConfig is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.SerumProgram is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.SerumMarket is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.SerumCoinVaultAccount is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.SerumPcVaultAccount is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.SerumVaultSigner is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.SerumEventQ is not set") + } + if inst.AccountMetaSlice[15] == nil { + return errors.New("accounts.SerumBids is not set") + } + if inst.AccountMetaSlice[16] == nil { + return errors.New("accounts.SerumAsks is not set") + } + } + return nil +} + +func (inst *AdminCancelOrders) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("AdminCancelOrders")). + // + 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("Limit", *inst.Limit)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=17]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" amm", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" ammAuthority", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" ammOpenOrders", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" ammTargetOrders", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" poolCoinToken", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" poolPcToken", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" ammOwner", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" ammConfig", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" serumProgram", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" serumMarket", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" serumCoinVault", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" serumPcVault", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta("serumVaultSigner", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta(" serumEventQ", inst.AccountMetaSlice.Get(14))) + accountsBranch.Child(ag_format.Meta(" serumBids", inst.AccountMetaSlice.Get(15))) + accountsBranch.Child(ag_format.Meta(" serumAsks", inst.AccountMetaSlice.Get(16))) + }) + }) + }) +} + +func (obj AdminCancelOrders) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Limit` param: + err = encoder.Encode(obj.Limit) + if err != nil { + return err + } + return nil +} +func (obj *AdminCancelOrders) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Limit`: + err = decoder.Decode(&obj.Limit) + if err != nil { + return err + } + return nil +} + +// NewAdminCancelOrdersInstruction declares a new AdminCancelOrders instruction with the provided parameters and accounts. +func NewAdminCancelOrdersInstruction( + // Parameters: + limit uint16, + // Accounts: + tokenProgram ag_solanago.PublicKey, + amm ag_solanago.PublicKey, + ammAuthority ag_solanago.PublicKey, + ammOpenOrders ag_solanago.PublicKey, + ammTargetOrders ag_solanago.PublicKey, + poolCoinTokenAccount ag_solanago.PublicKey, + poolPcTokenAccount ag_solanago.PublicKey, + ammOwnerAccount ag_solanago.PublicKey, + ammConfig ag_solanago.PublicKey, + serumProgram ag_solanago.PublicKey, + serumMarket ag_solanago.PublicKey, + serumCoinVaultAccount ag_solanago.PublicKey, + serumPcVaultAccount ag_solanago.PublicKey, + serumVaultSigner ag_solanago.PublicKey, + serumEventQ ag_solanago.PublicKey, + serumBids ag_solanago.PublicKey, + serumAsks ag_solanago.PublicKey) *AdminCancelOrders { + return NewAdminCancelOrdersInstructionBuilder(). + SetLimit(limit). + SetTokenProgramAccount(tokenProgram). + SetAmmAccount(amm). + SetAmmAuthorityAccount(ammAuthority). + SetAmmOpenOrdersAccount(ammOpenOrders). + SetAmmTargetOrdersAccount(ammTargetOrders). + SetPoolCoinTokenAccountAccount(poolCoinTokenAccount). + SetPoolPcTokenAccountAccount(poolPcTokenAccount). + SetAmmOwnerAccountAccount(ammOwnerAccount). + SetAmmConfigAccount(ammConfig). + SetSerumProgramAccount(serumProgram). + SetSerumMarketAccount(serumMarket). + SetSerumCoinVaultAccountAccount(serumCoinVaultAccount). + SetSerumPcVaultAccountAccount(serumPcVaultAccount). + SetSerumVaultSignerAccount(serumVaultSigner). + SetSerumEventQAccount(serumEventQ). + SetSerumBidsAccount(serumBids). + SetSerumAsksAccount(serumAsks) +} diff --git a/programs/raydiumamm/AdminCancelOrders_test.go b/programs/raydiumamm/AdminCancelOrders_test.go new file mode 100644 index 00000000..05f9adad --- /dev/null +++ b/programs/raydiumamm/AdminCancelOrders_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package raydium_amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_AdminCancelOrders(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("AdminCancelOrders"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(AdminCancelOrders) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(AdminCancelOrders) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/raydiumamm/CreateConfigAccount.go b/programs/raydiumamm/CreateConfigAccount.go new file mode 100644 index 00000000..0309aa92 --- /dev/null +++ b/programs/raydiumamm/CreateConfigAccount.go @@ -0,0 +1,174 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package raydium_amm + +import ( + "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" +) + +// CreateConfigAccount is the `createConfigAccount` instruction. +type CreateConfigAccount struct { + + // [0] = [WRITE, SIGNER] admin + // + // [1] = [WRITE] ammConfig + // + // [2] = [] owner + // + // [3] = [] systemProgram + // + // [4] = [] rent + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewCreateConfigAccountInstructionBuilder creates a new `CreateConfigAccount` instruction builder. +func NewCreateConfigAccountInstructionBuilder() *CreateConfigAccount { + nd := &CreateConfigAccount{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 5), + } + return nd +} + +// SetAdminAccount sets the "admin" account. +func (inst *CreateConfigAccount) SetAdminAccount(admin ag_solanago.PublicKey) *CreateConfigAccount { + inst.AccountMetaSlice[0] = ag_solanago.Meta(admin).WRITE().SIGNER() + return inst +} + +// GetAdminAccount gets the "admin" account. +func (inst *CreateConfigAccount) GetAdminAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetAmmConfigAccount sets the "ammConfig" account. +func (inst *CreateConfigAccount) SetAmmConfigAccount(ammConfig ag_solanago.PublicKey) *CreateConfigAccount { + inst.AccountMetaSlice[1] = ag_solanago.Meta(ammConfig).WRITE() + return inst +} + +// GetAmmConfigAccount gets the "ammConfig" account. +func (inst *CreateConfigAccount) GetAmmConfigAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetOwnerAccount sets the "owner" account. +func (inst *CreateConfigAccount) SetOwnerAccount(owner ag_solanago.PublicKey) *CreateConfigAccount { + inst.AccountMetaSlice[2] = ag_solanago.Meta(owner) + return inst +} + +// GetOwnerAccount gets the "owner" account. +func (inst *CreateConfigAccount) GetOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +func (inst *CreateConfigAccount) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *CreateConfigAccount { + inst.AccountMetaSlice[3] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +func (inst *CreateConfigAccount) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetRentAccount sets the "rent" account. +func (inst *CreateConfigAccount) SetRentAccount(rent ag_solanago.PublicKey) *CreateConfigAccount { + inst.AccountMetaSlice[4] = ag_solanago.Meta(rent) + return inst +} + +// GetRentAccount gets the "rent" account. +func (inst *CreateConfigAccount) GetRentAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +func (inst CreateConfigAccount) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: ag_binary.TypeIDFromUint8(Instruction_CreateConfigAccount), + }} +} + +// 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 CreateConfigAccount) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *CreateConfigAccount) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Admin is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.AmmConfig is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.Owner is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.SystemProgram is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.Rent is not set") + } + } + return nil +} + +func (inst *CreateConfigAccount) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("CreateConfigAccount")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=5]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" admin", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" ammConfig", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" owner", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta("systemProgram", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" rent", inst.AccountMetaSlice.Get(4))) + }) + }) + }) +} + +func (obj CreateConfigAccount) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *CreateConfigAccount) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewCreateConfigAccountInstruction declares a new CreateConfigAccount instruction with the provided parameters and accounts. +func NewCreateConfigAccountInstruction( + // Accounts: + admin ag_solanago.PublicKey, + ammConfig ag_solanago.PublicKey, + owner ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey, + rent ag_solanago.PublicKey) *CreateConfigAccount { + return NewCreateConfigAccountInstructionBuilder(). + SetAdminAccount(admin). + SetAmmConfigAccount(ammConfig). + SetOwnerAccount(owner). + SetSystemProgramAccount(systemProgram). + SetRentAccount(rent) +} diff --git a/programs/raydiumamm/CreateConfigAccount_test.go b/programs/raydiumamm/CreateConfigAccount_test.go new file mode 100644 index 00000000..124c115a --- /dev/null +++ b/programs/raydiumamm/CreateConfigAccount_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package raydium_amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_CreateConfigAccount(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("CreateConfigAccount"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(CreateConfigAccount) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(CreateConfigAccount) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/raydiumamm/Deposit.go b/programs/raydiumamm/Deposit.go new file mode 100644 index 00000000..b5dedb76 --- /dev/null +++ b/programs/raydiumamm/Deposit.go @@ -0,0 +1,420 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package raydium_amm + +import ( + "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" +) + +// Deposit is the `deposit` instruction. +type Deposit struct { + MaxCoinAmount *uint64 + MaxPcAmount *uint64 + BaseSide *uint64 + + // [0] = [] tokenProgram + // + // [1] = [WRITE] amm + // + // [2] = [] ammAuthority + // + // [3] = [] ammOpenOrders + // + // [4] = [WRITE] ammTargetOrders + // + // [5] = [WRITE] lpMintAddress + // + // [6] = [WRITE] poolCoinTokenAccount + // + // [7] = [WRITE] poolPcTokenAccount + // + // [8] = [] serumMarket + // + // [9] = [WRITE] userCoinTokenAccount + // + // [10] = [WRITE] userPcTokenAccount + // + // [11] = [WRITE] userLpTokenAccount + // + // [12] = [SIGNER] userOwner + // + // [13] = [] serumEventQueue + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewDepositInstructionBuilder creates a new `Deposit` instruction builder. +func NewDepositInstructionBuilder() *Deposit { + nd := &Deposit{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 14), + } + return nd +} + +// SetMaxCoinAmount sets the "maxCoinAmount" parameter. +func (inst *Deposit) SetMaxCoinAmount(maxCoinAmount uint64) *Deposit { + inst.MaxCoinAmount = &maxCoinAmount + return inst +} + +// SetMaxPcAmount sets the "maxPcAmount" parameter. +func (inst *Deposit) SetMaxPcAmount(maxPcAmount uint64) *Deposit { + inst.MaxPcAmount = &maxPcAmount + return inst +} + +// SetBaseSide sets the "baseSide" parameter. +func (inst *Deposit) SetBaseSide(baseSide uint64) *Deposit { + inst.BaseSide = &baseSide + return inst +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *Deposit) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *Deposit { + inst.AccountMetaSlice[0] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *Deposit) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetAmmAccount sets the "amm" account. +func (inst *Deposit) SetAmmAccount(amm ag_solanago.PublicKey) *Deposit { + inst.AccountMetaSlice[1] = ag_solanago.Meta(amm).WRITE() + return inst +} + +// GetAmmAccount gets the "amm" account. +func (inst *Deposit) GetAmmAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetAmmAuthorityAccount sets the "ammAuthority" account. +func (inst *Deposit) SetAmmAuthorityAccount(ammAuthority ag_solanago.PublicKey) *Deposit { + inst.AccountMetaSlice[2] = ag_solanago.Meta(ammAuthority) + return inst +} + +// GetAmmAuthorityAccount gets the "ammAuthority" account. +func (inst *Deposit) GetAmmAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetAmmOpenOrdersAccount sets the "ammOpenOrders" account. +func (inst *Deposit) SetAmmOpenOrdersAccount(ammOpenOrders ag_solanago.PublicKey) *Deposit { + inst.AccountMetaSlice[3] = ag_solanago.Meta(ammOpenOrders) + return inst +} + +// GetAmmOpenOrdersAccount gets the "ammOpenOrders" account. +func (inst *Deposit) GetAmmOpenOrdersAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetAmmTargetOrdersAccount sets the "ammTargetOrders" account. +func (inst *Deposit) SetAmmTargetOrdersAccount(ammTargetOrders ag_solanago.PublicKey) *Deposit { + inst.AccountMetaSlice[4] = ag_solanago.Meta(ammTargetOrders).WRITE() + return inst +} + +// GetAmmTargetOrdersAccount gets the "ammTargetOrders" account. +func (inst *Deposit) GetAmmTargetOrdersAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetLpMintAddressAccount sets the "lpMintAddress" account. +func (inst *Deposit) SetLpMintAddressAccount(lpMintAddress ag_solanago.PublicKey) *Deposit { + inst.AccountMetaSlice[5] = ag_solanago.Meta(lpMintAddress).WRITE() + return inst +} + +// GetLpMintAddressAccount gets the "lpMintAddress" account. +func (inst *Deposit) GetLpMintAddressAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetPoolCoinTokenAccountAccount sets the "poolCoinTokenAccount" account. +func (inst *Deposit) SetPoolCoinTokenAccountAccount(poolCoinTokenAccount ag_solanago.PublicKey) *Deposit { + inst.AccountMetaSlice[6] = ag_solanago.Meta(poolCoinTokenAccount).WRITE() + return inst +} + +// GetPoolCoinTokenAccountAccount gets the "poolCoinTokenAccount" account. +func (inst *Deposit) GetPoolCoinTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetPoolPcTokenAccountAccount sets the "poolPcTokenAccount" account. +func (inst *Deposit) SetPoolPcTokenAccountAccount(poolPcTokenAccount ag_solanago.PublicKey) *Deposit { + inst.AccountMetaSlice[7] = ag_solanago.Meta(poolPcTokenAccount).WRITE() + return inst +} + +// GetPoolPcTokenAccountAccount gets the "poolPcTokenAccount" account. +func (inst *Deposit) GetPoolPcTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetSerumMarketAccount sets the "serumMarket" account. +func (inst *Deposit) SetSerumMarketAccount(serumMarket ag_solanago.PublicKey) *Deposit { + inst.AccountMetaSlice[8] = ag_solanago.Meta(serumMarket) + return inst +} + +// GetSerumMarketAccount gets the "serumMarket" account. +func (inst *Deposit) GetSerumMarketAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetUserCoinTokenAccountAccount sets the "userCoinTokenAccount" account. +func (inst *Deposit) SetUserCoinTokenAccountAccount(userCoinTokenAccount ag_solanago.PublicKey) *Deposit { + inst.AccountMetaSlice[9] = ag_solanago.Meta(userCoinTokenAccount).WRITE() + return inst +} + +// GetUserCoinTokenAccountAccount gets the "userCoinTokenAccount" account. +func (inst *Deposit) GetUserCoinTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetUserPcTokenAccountAccount sets the "userPcTokenAccount" account. +func (inst *Deposit) SetUserPcTokenAccountAccount(userPcTokenAccount ag_solanago.PublicKey) *Deposit { + inst.AccountMetaSlice[10] = ag_solanago.Meta(userPcTokenAccount).WRITE() + return inst +} + +// GetUserPcTokenAccountAccount gets the "userPcTokenAccount" account. +func (inst *Deposit) GetUserPcTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetUserLpTokenAccountAccount sets the "userLpTokenAccount" account. +func (inst *Deposit) SetUserLpTokenAccountAccount(userLpTokenAccount ag_solanago.PublicKey) *Deposit { + inst.AccountMetaSlice[11] = ag_solanago.Meta(userLpTokenAccount).WRITE() + return inst +} + +// GetUserLpTokenAccountAccount gets the "userLpTokenAccount" account. +func (inst *Deposit) GetUserLpTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetUserOwnerAccount sets the "userOwner" account. +func (inst *Deposit) SetUserOwnerAccount(userOwner ag_solanago.PublicKey) *Deposit { + inst.AccountMetaSlice[12] = ag_solanago.Meta(userOwner).SIGNER() + return inst +} + +// GetUserOwnerAccount gets the "userOwner" account. +func (inst *Deposit) GetUserOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetSerumEventQueueAccount sets the "serumEventQueue" account. +func (inst *Deposit) SetSerumEventQueueAccount(serumEventQueue ag_solanago.PublicKey) *Deposit { + inst.AccountMetaSlice[13] = ag_solanago.Meta(serumEventQueue) + return inst +} + +// GetSerumEventQueueAccount gets the "serumEventQueue" account. +func (inst *Deposit) GetSerumEventQueueAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +func (inst Deposit) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: ag_binary.TypeIDFromUint8(Instruction_Deposit), + }} +} + +// 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 Deposit) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *Deposit) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.MaxCoinAmount == nil { + return errors.New("MaxCoinAmount parameter is not set") + } + if inst.MaxPcAmount == nil { + return errors.New("MaxPcAmount parameter is not set") + } + if inst.BaseSide == nil { + return errors.New("BaseSide parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Amm is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.AmmAuthority is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.AmmOpenOrders is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.AmmTargetOrders is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.LpMintAddress is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.PoolCoinTokenAccount is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.PoolPcTokenAccount is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.SerumMarket is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.UserCoinTokenAccount is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.UserPcTokenAccount is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.UserLpTokenAccount is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.UserOwner is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.SerumEventQueue is not set") + } + } + return nil +} + +func (inst *Deposit) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("Deposit")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=3]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param("MaxCoinAmount", *inst.MaxCoinAmount)) + paramsBranch.Child(ag_format.Param(" MaxPcAmount", *inst.MaxPcAmount)) + paramsBranch.Child(ag_format.Param(" BaseSide", *inst.BaseSide)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=14]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" amm", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" ammAuthority", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" ammOpenOrders", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta("ammTargetOrders", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" lpMintAddress", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" poolCoinToken", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" poolPcToken", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" serumMarket", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" userCoinToken", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" userPcToken", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" userLpToken", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" userOwner", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta("serumEventQueue", inst.AccountMetaSlice.Get(13))) + }) + }) + }) +} + +func (obj Deposit) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `MaxCoinAmount` param: + err = encoder.Encode(obj.MaxCoinAmount) + if err != nil { + return err + } + // Serialize `MaxPcAmount` param: + err = encoder.Encode(obj.MaxPcAmount) + if err != nil { + return err + } + // Serialize `BaseSide` param: + err = encoder.Encode(obj.BaseSide) + if err != nil { + return err + } + return nil +} +func (obj *Deposit) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `MaxCoinAmount`: + err = decoder.Decode(&obj.MaxCoinAmount) + if err != nil { + return err + } + // Deserialize `MaxPcAmount`: + err = decoder.Decode(&obj.MaxPcAmount) + if err != nil { + return err + } + // Deserialize `BaseSide`: + err = decoder.Decode(&obj.BaseSide) + if err != nil { + return err + } + return nil +} + +// NewDepositInstruction declares a new Deposit instruction with the provided parameters and accounts. +func NewDepositInstruction( + // Parameters: + maxCoinAmount uint64, + maxPcAmount uint64, + baseSide uint64, + // Accounts: + tokenProgram ag_solanago.PublicKey, + amm ag_solanago.PublicKey, + ammAuthority ag_solanago.PublicKey, + ammOpenOrders ag_solanago.PublicKey, + ammTargetOrders ag_solanago.PublicKey, + lpMintAddress ag_solanago.PublicKey, + poolCoinTokenAccount ag_solanago.PublicKey, + poolPcTokenAccount ag_solanago.PublicKey, + serumMarket ag_solanago.PublicKey, + userCoinTokenAccount ag_solanago.PublicKey, + userPcTokenAccount ag_solanago.PublicKey, + userLpTokenAccount ag_solanago.PublicKey, + userOwner ag_solanago.PublicKey, + serumEventQueue ag_solanago.PublicKey) *Deposit { + return NewDepositInstructionBuilder(). + SetMaxCoinAmount(maxCoinAmount). + SetMaxPcAmount(maxPcAmount). + SetBaseSide(baseSide). + SetTokenProgramAccount(tokenProgram). + SetAmmAccount(amm). + SetAmmAuthorityAccount(ammAuthority). + SetAmmOpenOrdersAccount(ammOpenOrders). + SetAmmTargetOrdersAccount(ammTargetOrders). + SetLpMintAddressAccount(lpMintAddress). + SetPoolCoinTokenAccountAccount(poolCoinTokenAccount). + SetPoolPcTokenAccountAccount(poolPcTokenAccount). + SetSerumMarketAccount(serumMarket). + SetUserCoinTokenAccountAccount(userCoinTokenAccount). + SetUserPcTokenAccountAccount(userPcTokenAccount). + SetUserLpTokenAccountAccount(userLpTokenAccount). + SetUserOwnerAccount(userOwner). + SetSerumEventQueueAccount(serumEventQueue) +} diff --git a/programs/raydiumamm/Deposit_test.go b/programs/raydiumamm/Deposit_test.go new file mode 100644 index 00000000..111f3881 --- /dev/null +++ b/programs/raydiumamm/Deposit_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package raydium_amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_Deposit(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("Deposit"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(Deposit) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(Deposit) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/raydiumamm/Initialize.go b/programs/raydiumamm/Initialize.go new file mode 100644 index 00000000..b36b84f2 --- /dev/null +++ b/programs/raydiumamm/Initialize.go @@ -0,0 +1,473 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package raydium_amm + +import ( + "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" +) + +// Initialize is the `initialize` instruction. +type Initialize struct { + Nonce *uint8 + OpenTime *uint64 + + // [0] = [] tokenProgram + // + // [1] = [] systemProgram + // + // [2] = [] rent + // + // [3] = [WRITE] amm + // + // [4] = [] ammAuthority + // + // [5] = [WRITE] ammOpenOrders + // + // [6] = [WRITE] lpMintAddress + // + // [7] = [] coinMintAddress + // + // [8] = [] pcMintAddress + // + // [9] = [] poolCoinTokenAccount + // + // [10] = [] poolPcTokenAccount + // + // [11] = [WRITE] poolWithdrawQueue + // + // [12] = [WRITE] poolTargetOrdersAccount + // + // [13] = [WRITE] userLpTokenAccount + // + // [14] = [] poolTempLpTokenAccount + // + // [15] = [] serumProgram + // + // [16] = [] serumMarket + // + // [17] = [WRITE, SIGNER] userWallet + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewInitializeInstructionBuilder creates a new `Initialize` instruction builder. +func NewInitializeInstructionBuilder() *Initialize { + nd := &Initialize{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 18), + } + return nd +} + +// SetNonce sets the "nonce" parameter. +func (inst *Initialize) SetNonce(nonce uint8) *Initialize { + inst.Nonce = &nonce + return inst +} + +// SetOpenTime sets the "openTime" parameter. +func (inst *Initialize) SetOpenTime(openTime uint64) *Initialize { + inst.OpenTime = &openTime + return inst +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *Initialize) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *Initialize { + inst.AccountMetaSlice[0] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *Initialize) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +func (inst *Initialize) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *Initialize { + inst.AccountMetaSlice[1] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +func (inst *Initialize) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetRentAccount sets the "rent" account. +func (inst *Initialize) SetRentAccount(rent ag_solanago.PublicKey) *Initialize { + inst.AccountMetaSlice[2] = ag_solanago.Meta(rent) + return inst +} + +// GetRentAccount gets the "rent" account. +func (inst *Initialize) GetRentAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetAmmAccount sets the "amm" account. +func (inst *Initialize) SetAmmAccount(amm ag_solanago.PublicKey) *Initialize { + inst.AccountMetaSlice[3] = ag_solanago.Meta(amm).WRITE() + return inst +} + +// GetAmmAccount gets the "amm" account. +func (inst *Initialize) GetAmmAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetAmmAuthorityAccount sets the "ammAuthority" account. +func (inst *Initialize) SetAmmAuthorityAccount(ammAuthority ag_solanago.PublicKey) *Initialize { + inst.AccountMetaSlice[4] = ag_solanago.Meta(ammAuthority) + return inst +} + +// GetAmmAuthorityAccount gets the "ammAuthority" account. +func (inst *Initialize) GetAmmAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetAmmOpenOrdersAccount sets the "ammOpenOrders" account. +func (inst *Initialize) SetAmmOpenOrdersAccount(ammOpenOrders ag_solanago.PublicKey) *Initialize { + inst.AccountMetaSlice[5] = ag_solanago.Meta(ammOpenOrders).WRITE() + return inst +} + +// GetAmmOpenOrdersAccount gets the "ammOpenOrders" account. +func (inst *Initialize) GetAmmOpenOrdersAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetLpMintAddressAccount sets the "lpMintAddress" account. +func (inst *Initialize) SetLpMintAddressAccount(lpMintAddress ag_solanago.PublicKey) *Initialize { + inst.AccountMetaSlice[6] = ag_solanago.Meta(lpMintAddress).WRITE() + return inst +} + +// GetLpMintAddressAccount gets the "lpMintAddress" account. +func (inst *Initialize) GetLpMintAddressAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetCoinMintAddressAccount sets the "coinMintAddress" account. +func (inst *Initialize) SetCoinMintAddressAccount(coinMintAddress ag_solanago.PublicKey) *Initialize { + inst.AccountMetaSlice[7] = ag_solanago.Meta(coinMintAddress) + return inst +} + +// GetCoinMintAddressAccount gets the "coinMintAddress" account. +func (inst *Initialize) GetCoinMintAddressAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetPcMintAddressAccount sets the "pcMintAddress" account. +func (inst *Initialize) SetPcMintAddressAccount(pcMintAddress ag_solanago.PublicKey) *Initialize { + inst.AccountMetaSlice[8] = ag_solanago.Meta(pcMintAddress) + return inst +} + +// GetPcMintAddressAccount gets the "pcMintAddress" account. +func (inst *Initialize) GetPcMintAddressAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetPoolCoinTokenAccountAccount sets the "poolCoinTokenAccount" account. +func (inst *Initialize) SetPoolCoinTokenAccountAccount(poolCoinTokenAccount ag_solanago.PublicKey) *Initialize { + inst.AccountMetaSlice[9] = ag_solanago.Meta(poolCoinTokenAccount) + return inst +} + +// GetPoolCoinTokenAccountAccount gets the "poolCoinTokenAccount" account. +func (inst *Initialize) GetPoolCoinTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetPoolPcTokenAccountAccount sets the "poolPcTokenAccount" account. +func (inst *Initialize) SetPoolPcTokenAccountAccount(poolPcTokenAccount ag_solanago.PublicKey) *Initialize { + inst.AccountMetaSlice[10] = ag_solanago.Meta(poolPcTokenAccount) + return inst +} + +// GetPoolPcTokenAccountAccount gets the "poolPcTokenAccount" account. +func (inst *Initialize) GetPoolPcTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetPoolWithdrawQueueAccount sets the "poolWithdrawQueue" account. +func (inst *Initialize) SetPoolWithdrawQueueAccount(poolWithdrawQueue ag_solanago.PublicKey) *Initialize { + inst.AccountMetaSlice[11] = ag_solanago.Meta(poolWithdrawQueue).WRITE() + return inst +} + +// GetPoolWithdrawQueueAccount gets the "poolWithdrawQueue" account. +func (inst *Initialize) GetPoolWithdrawQueueAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetPoolTargetOrdersAccountAccount sets the "poolTargetOrdersAccount" account. +func (inst *Initialize) SetPoolTargetOrdersAccountAccount(poolTargetOrdersAccount ag_solanago.PublicKey) *Initialize { + inst.AccountMetaSlice[12] = ag_solanago.Meta(poolTargetOrdersAccount).WRITE() + return inst +} + +// GetPoolTargetOrdersAccountAccount gets the "poolTargetOrdersAccount" account. +func (inst *Initialize) GetPoolTargetOrdersAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetUserLpTokenAccountAccount sets the "userLpTokenAccount" account. +func (inst *Initialize) SetUserLpTokenAccountAccount(userLpTokenAccount ag_solanago.PublicKey) *Initialize { + inst.AccountMetaSlice[13] = ag_solanago.Meta(userLpTokenAccount).WRITE() + return inst +} + +// GetUserLpTokenAccountAccount gets the "userLpTokenAccount" account. +func (inst *Initialize) GetUserLpTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetPoolTempLpTokenAccountAccount sets the "poolTempLpTokenAccount" account. +func (inst *Initialize) SetPoolTempLpTokenAccountAccount(poolTempLpTokenAccount ag_solanago.PublicKey) *Initialize { + inst.AccountMetaSlice[14] = ag_solanago.Meta(poolTempLpTokenAccount) + return inst +} + +// GetPoolTempLpTokenAccountAccount gets the "poolTempLpTokenAccount" account. +func (inst *Initialize) GetPoolTempLpTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +// SetSerumProgramAccount sets the "serumProgram" account. +func (inst *Initialize) SetSerumProgramAccount(serumProgram ag_solanago.PublicKey) *Initialize { + inst.AccountMetaSlice[15] = ag_solanago.Meta(serumProgram) + return inst +} + +// GetSerumProgramAccount gets the "serumProgram" account. +func (inst *Initialize) GetSerumProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(15) +} + +// SetSerumMarketAccount sets the "serumMarket" account. +func (inst *Initialize) SetSerumMarketAccount(serumMarket ag_solanago.PublicKey) *Initialize { + inst.AccountMetaSlice[16] = ag_solanago.Meta(serumMarket) + return inst +} + +// GetSerumMarketAccount gets the "serumMarket" account. +func (inst *Initialize) GetSerumMarketAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(16) +} + +// SetUserWalletAccount sets the "userWallet" account. +func (inst *Initialize) SetUserWalletAccount(userWallet ag_solanago.PublicKey) *Initialize { + inst.AccountMetaSlice[17] = ag_solanago.Meta(userWallet).WRITE().SIGNER() + return inst +} + +// GetUserWalletAccount gets the "userWallet" account. +func (inst *Initialize) GetUserWalletAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(17) +} + +func (inst Initialize) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: ag_binary.TypeIDFromUint8(Instruction_Initialize), + }} +} + +// 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 Initialize) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *Initialize) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.Nonce == nil { + return errors.New("Nonce parameter is not set") + } + if inst.OpenTime == nil { + return errors.New("OpenTime parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.SystemProgram is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.Rent is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.Amm is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.AmmAuthority is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.AmmOpenOrders is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.LpMintAddress is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.CoinMintAddress is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.PcMintAddress is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.PoolCoinTokenAccount is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.PoolPcTokenAccount is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.PoolWithdrawQueue is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.PoolTargetOrdersAccount is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.UserLpTokenAccount is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.PoolTempLpTokenAccount is not set") + } + if inst.AccountMetaSlice[15] == nil { + return errors.New("accounts.SerumProgram is not set") + } + if inst.AccountMetaSlice[16] == nil { + return errors.New("accounts.SerumMarket is not set") + } + if inst.AccountMetaSlice[17] == nil { + return errors.New("accounts.UserWallet is not set") + } + } + return nil +} + +func (inst *Initialize) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("Initialize")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=2]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" Nonce", *inst.Nonce)) + paramsBranch.Child(ag_format.Param("OpenTime", *inst.OpenTime)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=18]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" systemProgram", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" rent", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" amm", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" ammAuthority", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" ammOpenOrders", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" lpMintAddress", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" coinMintAddress", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" pcMintAddress", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" poolCoinToken", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" poolPcToken", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta("poolWithdrawQueue", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" poolTargetOrders", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" userLpToken", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta(" poolTempLpToken", inst.AccountMetaSlice.Get(14))) + accountsBranch.Child(ag_format.Meta(" serumProgram", inst.AccountMetaSlice.Get(15))) + accountsBranch.Child(ag_format.Meta(" serumMarket", inst.AccountMetaSlice.Get(16))) + accountsBranch.Child(ag_format.Meta(" userWallet", inst.AccountMetaSlice.Get(17))) + }) + }) + }) +} + +func (obj Initialize) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Nonce` param: + err = encoder.Encode(obj.Nonce) + if err != nil { + return err + } + // Serialize `OpenTime` param: + err = encoder.Encode(obj.OpenTime) + if err != nil { + return err + } + return nil +} +func (obj *Initialize) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Nonce`: + err = decoder.Decode(&obj.Nonce) + if err != nil { + return err + } + // Deserialize `OpenTime`: + err = decoder.Decode(&obj.OpenTime) + if err != nil { + return err + } + return nil +} + +// NewInitializeInstruction declares a new Initialize instruction with the provided parameters and accounts. +func NewInitializeInstruction( + // Parameters: + nonce uint8, + openTime uint64, + // Accounts: + tokenProgram ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey, + rent ag_solanago.PublicKey, + amm ag_solanago.PublicKey, + ammAuthority ag_solanago.PublicKey, + ammOpenOrders ag_solanago.PublicKey, + lpMintAddress ag_solanago.PublicKey, + coinMintAddress ag_solanago.PublicKey, + pcMintAddress ag_solanago.PublicKey, + poolCoinTokenAccount ag_solanago.PublicKey, + poolPcTokenAccount ag_solanago.PublicKey, + poolWithdrawQueue ag_solanago.PublicKey, + poolTargetOrdersAccount ag_solanago.PublicKey, + userLpTokenAccount ag_solanago.PublicKey, + poolTempLpTokenAccount ag_solanago.PublicKey, + serumProgram ag_solanago.PublicKey, + serumMarket ag_solanago.PublicKey, + userWallet ag_solanago.PublicKey) *Initialize { + return NewInitializeInstructionBuilder(). + SetNonce(nonce). + SetOpenTime(openTime). + SetTokenProgramAccount(tokenProgram). + SetSystemProgramAccount(systemProgram). + SetRentAccount(rent). + SetAmmAccount(amm). + SetAmmAuthorityAccount(ammAuthority). + SetAmmOpenOrdersAccount(ammOpenOrders). + SetLpMintAddressAccount(lpMintAddress). + SetCoinMintAddressAccount(coinMintAddress). + SetPcMintAddressAccount(pcMintAddress). + SetPoolCoinTokenAccountAccount(poolCoinTokenAccount). + SetPoolPcTokenAccountAccount(poolPcTokenAccount). + SetPoolWithdrawQueueAccount(poolWithdrawQueue). + SetPoolTargetOrdersAccountAccount(poolTargetOrdersAccount). + SetUserLpTokenAccountAccount(userLpTokenAccount). + SetPoolTempLpTokenAccountAccount(poolTempLpTokenAccount). + SetSerumProgramAccount(serumProgram). + SetSerumMarketAccount(serumMarket). + SetUserWalletAccount(userWallet) +} diff --git a/programs/raydiumamm/Initialize2.go b/programs/raydiumamm/Initialize2.go new file mode 100644 index 00000000..79af1907 --- /dev/null +++ b/programs/raydiumamm/Initialize2.go @@ -0,0 +1,576 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package raydium_amm + +import ( + "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" +) + +// Initialize2 is the `initialize2` instruction. +type Initialize2 struct { + Nonce *uint8 + OpenTime *uint64 + InitPcAmount *uint64 + InitCoinAmount *uint64 + + // [0] = [] tokenProgram + // + // [1] = [] splAssociatedTokenAccount + // + // [2] = [] systemProgram + // + // [3] = [] rent + // + // [4] = [WRITE] amm + // + // [5] = [] ammAuthority + // + // [6] = [WRITE] ammOpenOrders + // + // [7] = [WRITE] lpMint + // + // [8] = [] coinMint + // + // [9] = [] pcMint + // + // [10] = [WRITE] poolCoinTokenAccount + // + // [11] = [WRITE] poolPcTokenAccount + // + // [12] = [WRITE] poolWithdrawQueue + // + // [13] = [WRITE] ammTargetOrders + // + // [14] = [WRITE] poolTempLp + // + // [15] = [] serumProgram + // + // [16] = [] serumMarket + // + // [17] = [WRITE, SIGNER] userWallet + // + // [18] = [WRITE] userTokenCoin + // + // [19] = [WRITE] userTokenPc + // + // [20] = [WRITE] userLpTokenAccount + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewInitialize2InstructionBuilder creates a new `Initialize2` instruction builder. +func NewInitialize2InstructionBuilder() *Initialize2 { + nd := &Initialize2{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 21), + } + return nd +} + +// SetNonce sets the "nonce" parameter. +func (inst *Initialize2) SetNonce(nonce uint8) *Initialize2 { + inst.Nonce = &nonce + return inst +} + +// SetOpenTime sets the "openTime" parameter. +func (inst *Initialize2) SetOpenTime(openTime uint64) *Initialize2 { + inst.OpenTime = &openTime + return inst +} + +// SetInitPcAmount sets the "initPcAmount" parameter. +func (inst *Initialize2) SetInitPcAmount(initPcAmount uint64) *Initialize2 { + inst.InitPcAmount = &initPcAmount + return inst +} + +// SetInitCoinAmount sets the "initCoinAmount" parameter. +func (inst *Initialize2) SetInitCoinAmount(initCoinAmount uint64) *Initialize2 { + inst.InitCoinAmount = &initCoinAmount + return inst +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *Initialize2) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *Initialize2 { + inst.AccountMetaSlice[0] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *Initialize2) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetSplAssociatedTokenAccountAccount sets the "splAssociatedTokenAccount" account. +func (inst *Initialize2) SetSplAssociatedTokenAccountAccount(splAssociatedTokenAccount ag_solanago.PublicKey) *Initialize2 { + inst.AccountMetaSlice[1] = ag_solanago.Meta(splAssociatedTokenAccount) + return inst +} + +// GetSplAssociatedTokenAccountAccount gets the "splAssociatedTokenAccount" account. +func (inst *Initialize2) GetSplAssociatedTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +func (inst *Initialize2) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *Initialize2 { + inst.AccountMetaSlice[2] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +func (inst *Initialize2) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetRentAccount sets the "rent" account. +func (inst *Initialize2) SetRentAccount(rent ag_solanago.PublicKey) *Initialize2 { + inst.AccountMetaSlice[3] = ag_solanago.Meta(rent) + return inst +} + +// GetRentAccount gets the "rent" account. +func (inst *Initialize2) GetRentAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetAmmAccount sets the "amm" account. +func (inst *Initialize2) SetAmmAccount(amm ag_solanago.PublicKey) *Initialize2 { + inst.AccountMetaSlice[4] = ag_solanago.Meta(amm).WRITE() + return inst +} + +// GetAmmAccount gets the "amm" account. +func (inst *Initialize2) GetAmmAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetAmmAuthorityAccount sets the "ammAuthority" account. +func (inst *Initialize2) SetAmmAuthorityAccount(ammAuthority ag_solanago.PublicKey) *Initialize2 { + inst.AccountMetaSlice[5] = ag_solanago.Meta(ammAuthority) + return inst +} + +// GetAmmAuthorityAccount gets the "ammAuthority" account. +func (inst *Initialize2) GetAmmAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetAmmOpenOrdersAccount sets the "ammOpenOrders" account. +func (inst *Initialize2) SetAmmOpenOrdersAccount(ammOpenOrders ag_solanago.PublicKey) *Initialize2 { + inst.AccountMetaSlice[6] = ag_solanago.Meta(ammOpenOrders).WRITE() + return inst +} + +// GetAmmOpenOrdersAccount gets the "ammOpenOrders" account. +func (inst *Initialize2) GetAmmOpenOrdersAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetLpMintAccount sets the "lpMint" account. +func (inst *Initialize2) SetLpMintAccount(lpMint ag_solanago.PublicKey) *Initialize2 { + inst.AccountMetaSlice[7] = ag_solanago.Meta(lpMint).WRITE() + return inst +} + +// GetLpMintAccount gets the "lpMint" account. +func (inst *Initialize2) GetLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetCoinMintAccount sets the "coinMint" account. +func (inst *Initialize2) SetCoinMintAccount(coinMint ag_solanago.PublicKey) *Initialize2 { + inst.AccountMetaSlice[8] = ag_solanago.Meta(coinMint) + return inst +} + +// GetCoinMintAccount gets the "coinMint" account. +func (inst *Initialize2) GetCoinMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetPcMintAccount sets the "pcMint" account. +func (inst *Initialize2) SetPcMintAccount(pcMint ag_solanago.PublicKey) *Initialize2 { + inst.AccountMetaSlice[9] = ag_solanago.Meta(pcMint) + return inst +} + +// GetPcMintAccount gets the "pcMint" account. +func (inst *Initialize2) GetPcMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetPoolCoinTokenAccountAccount sets the "poolCoinTokenAccount" account. +func (inst *Initialize2) SetPoolCoinTokenAccountAccount(poolCoinTokenAccount ag_solanago.PublicKey) *Initialize2 { + inst.AccountMetaSlice[10] = ag_solanago.Meta(poolCoinTokenAccount).WRITE() + return inst +} + +// GetPoolCoinTokenAccountAccount gets the "poolCoinTokenAccount" account. +func (inst *Initialize2) GetPoolCoinTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetPoolPcTokenAccountAccount sets the "poolPcTokenAccount" account. +func (inst *Initialize2) SetPoolPcTokenAccountAccount(poolPcTokenAccount ag_solanago.PublicKey) *Initialize2 { + inst.AccountMetaSlice[11] = ag_solanago.Meta(poolPcTokenAccount).WRITE() + return inst +} + +// GetPoolPcTokenAccountAccount gets the "poolPcTokenAccount" account. +func (inst *Initialize2) GetPoolPcTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetPoolWithdrawQueueAccount sets the "poolWithdrawQueue" account. +func (inst *Initialize2) SetPoolWithdrawQueueAccount(poolWithdrawQueue ag_solanago.PublicKey) *Initialize2 { + inst.AccountMetaSlice[12] = ag_solanago.Meta(poolWithdrawQueue).WRITE() + return inst +} + +// GetPoolWithdrawQueueAccount gets the "poolWithdrawQueue" account. +func (inst *Initialize2) GetPoolWithdrawQueueAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetAmmTargetOrdersAccount sets the "ammTargetOrders" account. +func (inst *Initialize2) SetAmmTargetOrdersAccount(ammTargetOrders ag_solanago.PublicKey) *Initialize2 { + inst.AccountMetaSlice[13] = ag_solanago.Meta(ammTargetOrders).WRITE() + return inst +} + +// GetAmmTargetOrdersAccount gets the "ammTargetOrders" account. +func (inst *Initialize2) GetAmmTargetOrdersAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetPoolTempLpAccount sets the "poolTempLp" account. +func (inst *Initialize2) SetPoolTempLpAccount(poolTempLp ag_solanago.PublicKey) *Initialize2 { + inst.AccountMetaSlice[14] = ag_solanago.Meta(poolTempLp).WRITE() + return inst +} + +// GetPoolTempLpAccount gets the "poolTempLp" account. +func (inst *Initialize2) GetPoolTempLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +// SetSerumProgramAccount sets the "serumProgram" account. +func (inst *Initialize2) SetSerumProgramAccount(serumProgram ag_solanago.PublicKey) *Initialize2 { + inst.AccountMetaSlice[15] = ag_solanago.Meta(serumProgram) + return inst +} + +// GetSerumProgramAccount gets the "serumProgram" account. +func (inst *Initialize2) GetSerumProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(15) +} + +// SetSerumMarketAccount sets the "serumMarket" account. +func (inst *Initialize2) SetSerumMarketAccount(serumMarket ag_solanago.PublicKey) *Initialize2 { + inst.AccountMetaSlice[16] = ag_solanago.Meta(serumMarket) + return inst +} + +// GetSerumMarketAccount gets the "serumMarket" account. +func (inst *Initialize2) GetSerumMarketAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(16) +} + +// SetUserWalletAccount sets the "userWallet" account. +func (inst *Initialize2) SetUserWalletAccount(userWallet ag_solanago.PublicKey) *Initialize2 { + inst.AccountMetaSlice[17] = ag_solanago.Meta(userWallet).WRITE().SIGNER() + return inst +} + +// GetUserWalletAccount gets the "userWallet" account. +func (inst *Initialize2) GetUserWalletAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(17) +} + +// SetUserTokenCoinAccount sets the "userTokenCoin" account. +func (inst *Initialize2) SetUserTokenCoinAccount(userTokenCoin ag_solanago.PublicKey) *Initialize2 { + inst.AccountMetaSlice[18] = ag_solanago.Meta(userTokenCoin).WRITE() + return inst +} + +// GetUserTokenCoinAccount gets the "userTokenCoin" account. +func (inst *Initialize2) GetUserTokenCoinAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(18) +} + +// SetUserTokenPcAccount sets the "userTokenPc" account. +func (inst *Initialize2) SetUserTokenPcAccount(userTokenPc ag_solanago.PublicKey) *Initialize2 { + inst.AccountMetaSlice[19] = ag_solanago.Meta(userTokenPc).WRITE() + return inst +} + +// GetUserTokenPcAccount gets the "userTokenPc" account. +func (inst *Initialize2) GetUserTokenPcAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(19) +} + +// SetUserLpTokenAccountAccount sets the "userLpTokenAccount" account. +func (inst *Initialize2) SetUserLpTokenAccountAccount(userLpTokenAccount ag_solanago.PublicKey) *Initialize2 { + inst.AccountMetaSlice[20] = ag_solanago.Meta(userLpTokenAccount).WRITE() + return inst +} + +// GetUserLpTokenAccountAccount gets the "userLpTokenAccount" account. +func (inst *Initialize2) GetUserLpTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(20) +} + +func (inst Initialize2) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: ag_binary.TypeIDFromUint8(Instruction_Initialize2), + }} +} + +// 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 Initialize2) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *Initialize2) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.Nonce == nil { + return errors.New("Nonce parameter is not set") + } + if inst.OpenTime == nil { + return errors.New("OpenTime parameter is not set") + } + if inst.InitPcAmount == nil { + return errors.New("InitPcAmount parameter is not set") + } + if inst.InitCoinAmount == nil { + return errors.New("InitCoinAmount parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.SplAssociatedTokenAccount is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.SystemProgram is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.Rent is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.Amm is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.AmmAuthority is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.AmmOpenOrders is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.LpMint is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.CoinMint is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.PcMint is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.PoolCoinTokenAccount is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.PoolPcTokenAccount is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.PoolWithdrawQueue is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.AmmTargetOrders is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.PoolTempLp is not set") + } + if inst.AccountMetaSlice[15] == nil { + return errors.New("accounts.SerumProgram is not set") + } + if inst.AccountMetaSlice[16] == nil { + return errors.New("accounts.SerumMarket is not set") + } + if inst.AccountMetaSlice[17] == nil { + return errors.New("accounts.UserWallet is not set") + } + if inst.AccountMetaSlice[18] == nil { + return errors.New("accounts.UserTokenCoin is not set") + } + if inst.AccountMetaSlice[19] == nil { + return errors.New("accounts.UserTokenPc is not set") + } + if inst.AccountMetaSlice[20] == nil { + return errors.New("accounts.UserLpTokenAccount is not set") + } + } + return nil +} + +func (inst *Initialize2) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("Initialize2")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=4]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" Nonce", *inst.Nonce)) + paramsBranch.Child(ag_format.Param(" OpenTime", *inst.OpenTime)) + paramsBranch.Child(ag_format.Param(" InitPcAmount", *inst.InitPcAmount)) + paramsBranch.Child(ag_format.Param("InitCoinAmount", *inst.InitCoinAmount)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=21]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta("splAssociatedToken", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" systemProgram", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" rent", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" amm", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" ammAuthority", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" ammOpenOrders", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" lpMint", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" coinMint", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" pcMint", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" poolCoinToken", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" poolPcToken", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" poolWithdrawQueue", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" ammTargetOrders", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta(" poolTempLp", inst.AccountMetaSlice.Get(14))) + accountsBranch.Child(ag_format.Meta(" serumProgram", inst.AccountMetaSlice.Get(15))) + accountsBranch.Child(ag_format.Meta(" serumMarket", inst.AccountMetaSlice.Get(16))) + accountsBranch.Child(ag_format.Meta(" userWallet", inst.AccountMetaSlice.Get(17))) + accountsBranch.Child(ag_format.Meta(" userTokenCoin", inst.AccountMetaSlice.Get(18))) + accountsBranch.Child(ag_format.Meta(" userTokenPc", inst.AccountMetaSlice.Get(19))) + accountsBranch.Child(ag_format.Meta(" userLpToken", inst.AccountMetaSlice.Get(20))) + }) + }) + }) +} + +func (obj Initialize2) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Nonce` param: + err = encoder.Encode(obj.Nonce) + if err != nil { + return err + } + // Serialize `OpenTime` param: + err = encoder.Encode(obj.OpenTime) + if err != nil { + return err + } + // Serialize `InitPcAmount` param: + err = encoder.Encode(obj.InitPcAmount) + if err != nil { + return err + } + // Serialize `InitCoinAmount` param: + err = encoder.Encode(obj.InitCoinAmount) + if err != nil { + return err + } + return nil +} +func (obj *Initialize2) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Nonce`: + err = decoder.Decode(&obj.Nonce) + if err != nil { + return err + } + // Deserialize `OpenTime`: + err = decoder.Decode(&obj.OpenTime) + if err != nil { + return err + } + // Deserialize `InitPcAmount`: + err = decoder.Decode(&obj.InitPcAmount) + if err != nil { + return err + } + // Deserialize `InitCoinAmount`: + err = decoder.Decode(&obj.InitCoinAmount) + if err != nil { + return err + } + return nil +} + +// NewInitialize2Instruction declares a new Initialize2 instruction with the provided parameters and accounts. +func NewInitialize2Instruction( + // Parameters: + nonce uint8, + openTime uint64, + initPcAmount uint64, + initCoinAmount uint64, + // Accounts: + tokenProgram ag_solanago.PublicKey, + splAssociatedTokenAccount ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey, + rent ag_solanago.PublicKey, + amm ag_solanago.PublicKey, + ammAuthority ag_solanago.PublicKey, + ammOpenOrders ag_solanago.PublicKey, + lpMint ag_solanago.PublicKey, + coinMint ag_solanago.PublicKey, + pcMint ag_solanago.PublicKey, + poolCoinTokenAccount ag_solanago.PublicKey, + poolPcTokenAccount ag_solanago.PublicKey, + poolWithdrawQueue ag_solanago.PublicKey, + ammTargetOrders ag_solanago.PublicKey, + poolTempLp ag_solanago.PublicKey, + serumProgram ag_solanago.PublicKey, + serumMarket ag_solanago.PublicKey, + userWallet ag_solanago.PublicKey, + userTokenCoin ag_solanago.PublicKey, + userTokenPc ag_solanago.PublicKey, + userLpTokenAccount ag_solanago.PublicKey) *Initialize2 { + return NewInitialize2InstructionBuilder(). + SetNonce(nonce). + SetOpenTime(openTime). + SetInitPcAmount(initPcAmount). + SetInitCoinAmount(initCoinAmount). + SetTokenProgramAccount(tokenProgram). + SetSplAssociatedTokenAccountAccount(splAssociatedTokenAccount). + SetSystemProgramAccount(systemProgram). + SetRentAccount(rent). + SetAmmAccount(amm). + SetAmmAuthorityAccount(ammAuthority). + SetAmmOpenOrdersAccount(ammOpenOrders). + SetLpMintAccount(lpMint). + SetCoinMintAccount(coinMint). + SetPcMintAccount(pcMint). + SetPoolCoinTokenAccountAccount(poolCoinTokenAccount). + SetPoolPcTokenAccountAccount(poolPcTokenAccount). + SetPoolWithdrawQueueAccount(poolWithdrawQueue). + SetAmmTargetOrdersAccount(ammTargetOrders). + SetPoolTempLpAccount(poolTempLp). + SetSerumProgramAccount(serumProgram). + SetSerumMarketAccount(serumMarket). + SetUserWalletAccount(userWallet). + SetUserTokenCoinAccount(userTokenCoin). + SetUserTokenPcAccount(userTokenPc). + SetUserLpTokenAccountAccount(userLpTokenAccount) +} diff --git a/programs/raydiumamm/Initialize2_test.go b/programs/raydiumamm/Initialize2_test.go new file mode 100644 index 00000000..736c19e2 --- /dev/null +++ b/programs/raydiumamm/Initialize2_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package raydium_amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_Initialize2(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("Initialize2"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(Initialize2) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(Initialize2) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/raydiumamm/Initialize_test.go b/programs/raydiumamm/Initialize_test.go new file mode 100644 index 00000000..4ce2a987 --- /dev/null +++ b/programs/raydiumamm/Initialize_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package raydium_amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_Initialize(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("Initialize"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(Initialize) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(Initialize) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/raydiumamm/MigrateToOpenBook.go b/programs/raydiumamm/MigrateToOpenBook.go new file mode 100644 index 00000000..0887017c --- /dev/null +++ b/programs/raydiumamm/MigrateToOpenBook.go @@ -0,0 +1,478 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package raydium_amm + +import ( + "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" +) + +// MigrateToOpenBook is the `migrateToOpenBook` instruction. +type MigrateToOpenBook struct { + + // [0] = [] tokenProgram + // + // [1] = [] systemProgram + // + // [2] = [] rent + // + // [3] = [WRITE] amm + // + // [4] = [] ammAuthority + // + // [5] = [WRITE] ammOpenOrders + // + // [6] = [WRITE] ammTokenCoin + // + // [7] = [WRITE] ammTokenPc + // + // [8] = [WRITE] ammTargetOrders + // + // [9] = [] serumProgram + // + // [10] = [WRITE] serumMarket + // + // [11] = [WRITE] serumBids + // + // [12] = [WRITE] serumAsks + // + // [13] = [WRITE] serumEventQueue + // + // [14] = [WRITE] serumCoinVault + // + // [15] = [WRITE] serumPcVault + // + // [16] = [] serumVaultSigner + // + // [17] = [WRITE] newAmmOpenOrders + // + // [18] = [] newSerumProgram + // + // [19] = [] newSerumMarket + // + // [20] = [WRITE, SIGNER] admin + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewMigrateToOpenBookInstructionBuilder creates a new `MigrateToOpenBook` instruction builder. +func NewMigrateToOpenBookInstructionBuilder() *MigrateToOpenBook { + nd := &MigrateToOpenBook{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 21), + } + return nd +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *MigrateToOpenBook) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *MigrateToOpenBook { + inst.AccountMetaSlice[0] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *MigrateToOpenBook) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +func (inst *MigrateToOpenBook) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *MigrateToOpenBook { + inst.AccountMetaSlice[1] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +func (inst *MigrateToOpenBook) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetRentAccount sets the "rent" account. +func (inst *MigrateToOpenBook) SetRentAccount(rent ag_solanago.PublicKey) *MigrateToOpenBook { + inst.AccountMetaSlice[2] = ag_solanago.Meta(rent) + return inst +} + +// GetRentAccount gets the "rent" account. +func (inst *MigrateToOpenBook) GetRentAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetAmmAccount sets the "amm" account. +func (inst *MigrateToOpenBook) SetAmmAccount(amm ag_solanago.PublicKey) *MigrateToOpenBook { + inst.AccountMetaSlice[3] = ag_solanago.Meta(amm).WRITE() + return inst +} + +// GetAmmAccount gets the "amm" account. +func (inst *MigrateToOpenBook) GetAmmAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetAmmAuthorityAccount sets the "ammAuthority" account. +func (inst *MigrateToOpenBook) SetAmmAuthorityAccount(ammAuthority ag_solanago.PublicKey) *MigrateToOpenBook { + inst.AccountMetaSlice[4] = ag_solanago.Meta(ammAuthority) + return inst +} + +// GetAmmAuthorityAccount gets the "ammAuthority" account. +func (inst *MigrateToOpenBook) GetAmmAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetAmmOpenOrdersAccount sets the "ammOpenOrders" account. +func (inst *MigrateToOpenBook) SetAmmOpenOrdersAccount(ammOpenOrders ag_solanago.PublicKey) *MigrateToOpenBook { + inst.AccountMetaSlice[5] = ag_solanago.Meta(ammOpenOrders).WRITE() + return inst +} + +// GetAmmOpenOrdersAccount gets the "ammOpenOrders" account. +func (inst *MigrateToOpenBook) GetAmmOpenOrdersAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetAmmTokenCoinAccount sets the "ammTokenCoin" account. +func (inst *MigrateToOpenBook) SetAmmTokenCoinAccount(ammTokenCoin ag_solanago.PublicKey) *MigrateToOpenBook { + inst.AccountMetaSlice[6] = ag_solanago.Meta(ammTokenCoin).WRITE() + return inst +} + +// GetAmmTokenCoinAccount gets the "ammTokenCoin" account. +func (inst *MigrateToOpenBook) GetAmmTokenCoinAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetAmmTokenPcAccount sets the "ammTokenPc" account. +func (inst *MigrateToOpenBook) SetAmmTokenPcAccount(ammTokenPc ag_solanago.PublicKey) *MigrateToOpenBook { + inst.AccountMetaSlice[7] = ag_solanago.Meta(ammTokenPc).WRITE() + return inst +} + +// GetAmmTokenPcAccount gets the "ammTokenPc" account. +func (inst *MigrateToOpenBook) GetAmmTokenPcAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetAmmTargetOrdersAccount sets the "ammTargetOrders" account. +func (inst *MigrateToOpenBook) SetAmmTargetOrdersAccount(ammTargetOrders ag_solanago.PublicKey) *MigrateToOpenBook { + inst.AccountMetaSlice[8] = ag_solanago.Meta(ammTargetOrders).WRITE() + return inst +} + +// GetAmmTargetOrdersAccount gets the "ammTargetOrders" account. +func (inst *MigrateToOpenBook) GetAmmTargetOrdersAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetSerumProgramAccount sets the "serumProgram" account. +func (inst *MigrateToOpenBook) SetSerumProgramAccount(serumProgram ag_solanago.PublicKey) *MigrateToOpenBook { + inst.AccountMetaSlice[9] = ag_solanago.Meta(serumProgram) + return inst +} + +// GetSerumProgramAccount gets the "serumProgram" account. +func (inst *MigrateToOpenBook) GetSerumProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetSerumMarketAccount sets the "serumMarket" account. +func (inst *MigrateToOpenBook) SetSerumMarketAccount(serumMarket ag_solanago.PublicKey) *MigrateToOpenBook { + inst.AccountMetaSlice[10] = ag_solanago.Meta(serumMarket).WRITE() + return inst +} + +// GetSerumMarketAccount gets the "serumMarket" account. +func (inst *MigrateToOpenBook) GetSerumMarketAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetSerumBidsAccount sets the "serumBids" account. +func (inst *MigrateToOpenBook) SetSerumBidsAccount(serumBids ag_solanago.PublicKey) *MigrateToOpenBook { + inst.AccountMetaSlice[11] = ag_solanago.Meta(serumBids).WRITE() + return inst +} + +// GetSerumBidsAccount gets the "serumBids" account. +func (inst *MigrateToOpenBook) GetSerumBidsAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetSerumAsksAccount sets the "serumAsks" account. +func (inst *MigrateToOpenBook) SetSerumAsksAccount(serumAsks ag_solanago.PublicKey) *MigrateToOpenBook { + inst.AccountMetaSlice[12] = ag_solanago.Meta(serumAsks).WRITE() + return inst +} + +// GetSerumAsksAccount gets the "serumAsks" account. +func (inst *MigrateToOpenBook) GetSerumAsksAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetSerumEventQueueAccount sets the "serumEventQueue" account. +func (inst *MigrateToOpenBook) SetSerumEventQueueAccount(serumEventQueue ag_solanago.PublicKey) *MigrateToOpenBook { + inst.AccountMetaSlice[13] = ag_solanago.Meta(serumEventQueue).WRITE() + return inst +} + +// GetSerumEventQueueAccount gets the "serumEventQueue" account. +func (inst *MigrateToOpenBook) GetSerumEventQueueAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetSerumCoinVaultAccount sets the "serumCoinVault" account. +func (inst *MigrateToOpenBook) SetSerumCoinVaultAccount(serumCoinVault ag_solanago.PublicKey) *MigrateToOpenBook { + inst.AccountMetaSlice[14] = ag_solanago.Meta(serumCoinVault).WRITE() + return inst +} + +// GetSerumCoinVaultAccount gets the "serumCoinVault" account. +func (inst *MigrateToOpenBook) GetSerumCoinVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +// SetSerumPcVaultAccount sets the "serumPcVault" account. +func (inst *MigrateToOpenBook) SetSerumPcVaultAccount(serumPcVault ag_solanago.PublicKey) *MigrateToOpenBook { + inst.AccountMetaSlice[15] = ag_solanago.Meta(serumPcVault).WRITE() + return inst +} + +// GetSerumPcVaultAccount gets the "serumPcVault" account. +func (inst *MigrateToOpenBook) GetSerumPcVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(15) +} + +// SetSerumVaultSignerAccount sets the "serumVaultSigner" account. +func (inst *MigrateToOpenBook) SetSerumVaultSignerAccount(serumVaultSigner ag_solanago.PublicKey) *MigrateToOpenBook { + inst.AccountMetaSlice[16] = ag_solanago.Meta(serumVaultSigner) + return inst +} + +// GetSerumVaultSignerAccount gets the "serumVaultSigner" account. +func (inst *MigrateToOpenBook) GetSerumVaultSignerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(16) +} + +// SetNewAmmOpenOrdersAccount sets the "newAmmOpenOrders" account. +func (inst *MigrateToOpenBook) SetNewAmmOpenOrdersAccount(newAmmOpenOrders ag_solanago.PublicKey) *MigrateToOpenBook { + inst.AccountMetaSlice[17] = ag_solanago.Meta(newAmmOpenOrders).WRITE() + return inst +} + +// GetNewAmmOpenOrdersAccount gets the "newAmmOpenOrders" account. +func (inst *MigrateToOpenBook) GetNewAmmOpenOrdersAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(17) +} + +// SetNewSerumProgramAccount sets the "newSerumProgram" account. +func (inst *MigrateToOpenBook) SetNewSerumProgramAccount(newSerumProgram ag_solanago.PublicKey) *MigrateToOpenBook { + inst.AccountMetaSlice[18] = ag_solanago.Meta(newSerumProgram) + return inst +} + +// GetNewSerumProgramAccount gets the "newSerumProgram" account. +func (inst *MigrateToOpenBook) GetNewSerumProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(18) +} + +// SetNewSerumMarketAccount sets the "newSerumMarket" account. +func (inst *MigrateToOpenBook) SetNewSerumMarketAccount(newSerumMarket ag_solanago.PublicKey) *MigrateToOpenBook { + inst.AccountMetaSlice[19] = ag_solanago.Meta(newSerumMarket) + return inst +} + +// GetNewSerumMarketAccount gets the "newSerumMarket" account. +func (inst *MigrateToOpenBook) GetNewSerumMarketAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(19) +} + +// SetAdminAccount sets the "admin" account. +func (inst *MigrateToOpenBook) SetAdminAccount(admin ag_solanago.PublicKey) *MigrateToOpenBook { + inst.AccountMetaSlice[20] = ag_solanago.Meta(admin).WRITE().SIGNER() + return inst +} + +// GetAdminAccount gets the "admin" account. +func (inst *MigrateToOpenBook) GetAdminAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(20) +} + +func (inst MigrateToOpenBook) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: ag_binary.TypeIDFromUint8(Instruction_MigrateToOpenBook), + }} +} + +// 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 MigrateToOpenBook) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *MigrateToOpenBook) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.SystemProgram is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.Rent is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.Amm is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.AmmAuthority is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.AmmOpenOrders is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.AmmTokenCoin is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.AmmTokenPc is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.AmmTargetOrders is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.SerumProgram is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.SerumMarket is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.SerumBids is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.SerumAsks is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.SerumEventQueue is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.SerumCoinVault is not set") + } + if inst.AccountMetaSlice[15] == nil { + return errors.New("accounts.SerumPcVault is not set") + } + if inst.AccountMetaSlice[16] == nil { + return errors.New("accounts.SerumVaultSigner is not set") + } + if inst.AccountMetaSlice[17] == nil { + return errors.New("accounts.NewAmmOpenOrders is not set") + } + if inst.AccountMetaSlice[18] == nil { + return errors.New("accounts.NewSerumProgram is not set") + } + if inst.AccountMetaSlice[19] == nil { + return errors.New("accounts.NewSerumMarket is not set") + } + if inst.AccountMetaSlice[20] == nil { + return errors.New("accounts.Admin is not set") + } + } + return nil +} + +func (inst *MigrateToOpenBook) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("MigrateToOpenBook")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=21]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" systemProgram", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" rent", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" amm", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" ammAuthority", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" ammOpenOrders", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" ammTokenCoin", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" ammTokenPc", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" ammTargetOrders", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" serumProgram", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" serumMarket", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" serumBids", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" serumAsks", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" serumEventQueue", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta(" serumCoinVault", inst.AccountMetaSlice.Get(14))) + accountsBranch.Child(ag_format.Meta(" serumPcVault", inst.AccountMetaSlice.Get(15))) + accountsBranch.Child(ag_format.Meta("serumVaultSigner", inst.AccountMetaSlice.Get(16))) + accountsBranch.Child(ag_format.Meta("newAmmOpenOrders", inst.AccountMetaSlice.Get(17))) + accountsBranch.Child(ag_format.Meta(" newSerumProgram", inst.AccountMetaSlice.Get(18))) + accountsBranch.Child(ag_format.Meta(" newSerumMarket", inst.AccountMetaSlice.Get(19))) + accountsBranch.Child(ag_format.Meta(" admin", inst.AccountMetaSlice.Get(20))) + }) + }) + }) +} + +func (obj MigrateToOpenBook) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *MigrateToOpenBook) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewMigrateToOpenBookInstruction declares a new MigrateToOpenBook instruction with the provided parameters and accounts. +func NewMigrateToOpenBookInstruction( + // Accounts: + tokenProgram ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey, + rent ag_solanago.PublicKey, + amm ag_solanago.PublicKey, + ammAuthority ag_solanago.PublicKey, + ammOpenOrders ag_solanago.PublicKey, + ammTokenCoin ag_solanago.PublicKey, + ammTokenPc ag_solanago.PublicKey, + ammTargetOrders ag_solanago.PublicKey, + serumProgram ag_solanago.PublicKey, + serumMarket ag_solanago.PublicKey, + serumBids ag_solanago.PublicKey, + serumAsks ag_solanago.PublicKey, + serumEventQueue ag_solanago.PublicKey, + serumCoinVault ag_solanago.PublicKey, + serumPcVault ag_solanago.PublicKey, + serumVaultSigner ag_solanago.PublicKey, + newAmmOpenOrders ag_solanago.PublicKey, + newSerumProgram ag_solanago.PublicKey, + newSerumMarket ag_solanago.PublicKey, + admin ag_solanago.PublicKey) *MigrateToOpenBook { + return NewMigrateToOpenBookInstructionBuilder(). + SetTokenProgramAccount(tokenProgram). + SetSystemProgramAccount(systemProgram). + SetRentAccount(rent). + SetAmmAccount(amm). + SetAmmAuthorityAccount(ammAuthority). + SetAmmOpenOrdersAccount(ammOpenOrders). + SetAmmTokenCoinAccount(ammTokenCoin). + SetAmmTokenPcAccount(ammTokenPc). + SetAmmTargetOrdersAccount(ammTargetOrders). + SetSerumProgramAccount(serumProgram). + SetSerumMarketAccount(serumMarket). + SetSerumBidsAccount(serumBids). + SetSerumAsksAccount(serumAsks). + SetSerumEventQueueAccount(serumEventQueue). + SetSerumCoinVaultAccount(serumCoinVault). + SetSerumPcVaultAccount(serumPcVault). + SetSerumVaultSignerAccount(serumVaultSigner). + SetNewAmmOpenOrdersAccount(newAmmOpenOrders). + SetNewSerumProgramAccount(newSerumProgram). + SetNewSerumMarketAccount(newSerumMarket). + SetAdminAccount(admin) +} diff --git a/programs/raydiumamm/MigrateToOpenBook_test.go b/programs/raydiumamm/MigrateToOpenBook_test.go new file mode 100644 index 00000000..d778ada1 --- /dev/null +++ b/programs/raydiumamm/MigrateToOpenBook_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package raydium_amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_MigrateToOpenBook(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("MigrateToOpenBook"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(MigrateToOpenBook) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(MigrateToOpenBook) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/raydiumamm/MonitorStep.go b/programs/raydiumamm/MonitorStep.go new file mode 100644 index 00000000..6bacce85 --- /dev/null +++ b/programs/raydiumamm/MonitorStep.go @@ -0,0 +1,515 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package raydium_amm + +import ( + "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" +) + +// MonitorStep is the `monitorStep` instruction. +type MonitorStep struct { + PlanOrderLimit *uint16 + PlaceOrderLimit *uint16 + CancelOrderLimit *uint16 + + // [0] = [] tokenProgram + // + // [1] = [] rent + // + // [2] = [] clock + // + // [3] = [WRITE] amm + // + // [4] = [] ammAuthority + // + // [5] = [WRITE] ammOpenOrders + // + // [6] = [WRITE] ammTargetOrders + // + // [7] = [WRITE] poolCoinTokenAccount + // + // [8] = [WRITE] poolPcTokenAccount + // + // [9] = [WRITE] poolWithdrawQueue + // + // [10] = [] serumProgram + // + // [11] = [WRITE] serumMarket + // + // [12] = [WRITE] serumCoinVaultAccount + // + // [13] = [WRITE] serumPcVaultAccount + // + // [14] = [] serumVaultSigner + // + // [15] = [WRITE] serumReqQ + // + // [16] = [WRITE] serumEventQ + // + // [17] = [WRITE] serumBids + // + // [18] = [WRITE] serumAsks + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewMonitorStepInstructionBuilder creates a new `MonitorStep` instruction builder. +func NewMonitorStepInstructionBuilder() *MonitorStep { + nd := &MonitorStep{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 19), + } + return nd +} + +// SetPlanOrderLimit sets the "planOrderLimit" parameter. +func (inst *MonitorStep) SetPlanOrderLimit(planOrderLimit uint16) *MonitorStep { + inst.PlanOrderLimit = &planOrderLimit + return inst +} + +// SetPlaceOrderLimit sets the "placeOrderLimit" parameter. +func (inst *MonitorStep) SetPlaceOrderLimit(placeOrderLimit uint16) *MonitorStep { + inst.PlaceOrderLimit = &placeOrderLimit + return inst +} + +// SetCancelOrderLimit sets the "cancelOrderLimit" parameter. +func (inst *MonitorStep) SetCancelOrderLimit(cancelOrderLimit uint16) *MonitorStep { + inst.CancelOrderLimit = &cancelOrderLimit + return inst +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *MonitorStep) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *MonitorStep { + inst.AccountMetaSlice[0] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *MonitorStep) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetRentAccount sets the "rent" account. +func (inst *MonitorStep) SetRentAccount(rent ag_solanago.PublicKey) *MonitorStep { + inst.AccountMetaSlice[1] = ag_solanago.Meta(rent) + return inst +} + +// GetRentAccount gets the "rent" account. +func (inst *MonitorStep) GetRentAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetClockAccount sets the "clock" account. +func (inst *MonitorStep) SetClockAccount(clock ag_solanago.PublicKey) *MonitorStep { + inst.AccountMetaSlice[2] = ag_solanago.Meta(clock) + return inst +} + +// GetClockAccount gets the "clock" account. +func (inst *MonitorStep) GetClockAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetAmmAccount sets the "amm" account. +func (inst *MonitorStep) SetAmmAccount(amm ag_solanago.PublicKey) *MonitorStep { + inst.AccountMetaSlice[3] = ag_solanago.Meta(amm).WRITE() + return inst +} + +// GetAmmAccount gets the "amm" account. +func (inst *MonitorStep) GetAmmAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetAmmAuthorityAccount sets the "ammAuthority" account. +func (inst *MonitorStep) SetAmmAuthorityAccount(ammAuthority ag_solanago.PublicKey) *MonitorStep { + inst.AccountMetaSlice[4] = ag_solanago.Meta(ammAuthority) + return inst +} + +// GetAmmAuthorityAccount gets the "ammAuthority" account. +func (inst *MonitorStep) GetAmmAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetAmmOpenOrdersAccount sets the "ammOpenOrders" account. +func (inst *MonitorStep) SetAmmOpenOrdersAccount(ammOpenOrders ag_solanago.PublicKey) *MonitorStep { + inst.AccountMetaSlice[5] = ag_solanago.Meta(ammOpenOrders).WRITE() + return inst +} + +// GetAmmOpenOrdersAccount gets the "ammOpenOrders" account. +func (inst *MonitorStep) GetAmmOpenOrdersAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetAmmTargetOrdersAccount sets the "ammTargetOrders" account. +func (inst *MonitorStep) SetAmmTargetOrdersAccount(ammTargetOrders ag_solanago.PublicKey) *MonitorStep { + inst.AccountMetaSlice[6] = ag_solanago.Meta(ammTargetOrders).WRITE() + return inst +} + +// GetAmmTargetOrdersAccount gets the "ammTargetOrders" account. +func (inst *MonitorStep) GetAmmTargetOrdersAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetPoolCoinTokenAccountAccount sets the "poolCoinTokenAccount" account. +func (inst *MonitorStep) SetPoolCoinTokenAccountAccount(poolCoinTokenAccount ag_solanago.PublicKey) *MonitorStep { + inst.AccountMetaSlice[7] = ag_solanago.Meta(poolCoinTokenAccount).WRITE() + return inst +} + +// GetPoolCoinTokenAccountAccount gets the "poolCoinTokenAccount" account. +func (inst *MonitorStep) GetPoolCoinTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetPoolPcTokenAccountAccount sets the "poolPcTokenAccount" account. +func (inst *MonitorStep) SetPoolPcTokenAccountAccount(poolPcTokenAccount ag_solanago.PublicKey) *MonitorStep { + inst.AccountMetaSlice[8] = ag_solanago.Meta(poolPcTokenAccount).WRITE() + return inst +} + +// GetPoolPcTokenAccountAccount gets the "poolPcTokenAccount" account. +func (inst *MonitorStep) GetPoolPcTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetPoolWithdrawQueueAccount sets the "poolWithdrawQueue" account. +func (inst *MonitorStep) SetPoolWithdrawQueueAccount(poolWithdrawQueue ag_solanago.PublicKey) *MonitorStep { + inst.AccountMetaSlice[9] = ag_solanago.Meta(poolWithdrawQueue).WRITE() + return inst +} + +// GetPoolWithdrawQueueAccount gets the "poolWithdrawQueue" account. +func (inst *MonitorStep) GetPoolWithdrawQueueAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetSerumProgramAccount sets the "serumProgram" account. +func (inst *MonitorStep) SetSerumProgramAccount(serumProgram ag_solanago.PublicKey) *MonitorStep { + inst.AccountMetaSlice[10] = ag_solanago.Meta(serumProgram) + return inst +} + +// GetSerumProgramAccount gets the "serumProgram" account. +func (inst *MonitorStep) GetSerumProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetSerumMarketAccount sets the "serumMarket" account. +func (inst *MonitorStep) SetSerumMarketAccount(serumMarket ag_solanago.PublicKey) *MonitorStep { + inst.AccountMetaSlice[11] = ag_solanago.Meta(serumMarket).WRITE() + return inst +} + +// GetSerumMarketAccount gets the "serumMarket" account. +func (inst *MonitorStep) GetSerumMarketAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetSerumCoinVaultAccountAccount sets the "serumCoinVaultAccount" account. +func (inst *MonitorStep) SetSerumCoinVaultAccountAccount(serumCoinVaultAccount ag_solanago.PublicKey) *MonitorStep { + inst.AccountMetaSlice[12] = ag_solanago.Meta(serumCoinVaultAccount).WRITE() + return inst +} + +// GetSerumCoinVaultAccountAccount gets the "serumCoinVaultAccount" account. +func (inst *MonitorStep) GetSerumCoinVaultAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetSerumPcVaultAccountAccount sets the "serumPcVaultAccount" account. +func (inst *MonitorStep) SetSerumPcVaultAccountAccount(serumPcVaultAccount ag_solanago.PublicKey) *MonitorStep { + inst.AccountMetaSlice[13] = ag_solanago.Meta(serumPcVaultAccount).WRITE() + return inst +} + +// GetSerumPcVaultAccountAccount gets the "serumPcVaultAccount" account. +func (inst *MonitorStep) GetSerumPcVaultAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetSerumVaultSignerAccount sets the "serumVaultSigner" account. +func (inst *MonitorStep) SetSerumVaultSignerAccount(serumVaultSigner ag_solanago.PublicKey) *MonitorStep { + inst.AccountMetaSlice[14] = ag_solanago.Meta(serumVaultSigner) + return inst +} + +// GetSerumVaultSignerAccount gets the "serumVaultSigner" account. +func (inst *MonitorStep) GetSerumVaultSignerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +// SetSerumReqQAccount sets the "serumReqQ" account. +func (inst *MonitorStep) SetSerumReqQAccount(serumReqQ ag_solanago.PublicKey) *MonitorStep { + inst.AccountMetaSlice[15] = ag_solanago.Meta(serumReqQ).WRITE() + return inst +} + +// GetSerumReqQAccount gets the "serumReqQ" account. +func (inst *MonitorStep) GetSerumReqQAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(15) +} + +// SetSerumEventQAccount sets the "serumEventQ" account. +func (inst *MonitorStep) SetSerumEventQAccount(serumEventQ ag_solanago.PublicKey) *MonitorStep { + inst.AccountMetaSlice[16] = ag_solanago.Meta(serumEventQ).WRITE() + return inst +} + +// GetSerumEventQAccount gets the "serumEventQ" account. +func (inst *MonitorStep) GetSerumEventQAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(16) +} + +// SetSerumBidsAccount sets the "serumBids" account. +func (inst *MonitorStep) SetSerumBidsAccount(serumBids ag_solanago.PublicKey) *MonitorStep { + inst.AccountMetaSlice[17] = ag_solanago.Meta(serumBids).WRITE() + return inst +} + +// GetSerumBidsAccount gets the "serumBids" account. +func (inst *MonitorStep) GetSerumBidsAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(17) +} + +// SetSerumAsksAccount sets the "serumAsks" account. +func (inst *MonitorStep) SetSerumAsksAccount(serumAsks ag_solanago.PublicKey) *MonitorStep { + inst.AccountMetaSlice[18] = ag_solanago.Meta(serumAsks).WRITE() + return inst +} + +// GetSerumAsksAccount gets the "serumAsks" account. +func (inst *MonitorStep) GetSerumAsksAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(18) +} + +func (inst MonitorStep) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: ag_binary.TypeIDFromUint8(Instruction_MonitorStep), + }} +} + +// 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 MonitorStep) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *MonitorStep) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.PlanOrderLimit == nil { + return errors.New("PlanOrderLimit parameter is not set") + } + if inst.PlaceOrderLimit == nil { + return errors.New("PlaceOrderLimit parameter is not set") + } + if inst.CancelOrderLimit == nil { + return errors.New("CancelOrderLimit parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Rent is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.Clock is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.Amm is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.AmmAuthority is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.AmmOpenOrders is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.AmmTargetOrders is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.PoolCoinTokenAccount is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.PoolPcTokenAccount is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.PoolWithdrawQueue is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.SerumProgram is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.SerumMarket is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.SerumCoinVaultAccount is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.SerumPcVaultAccount is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.SerumVaultSigner is not set") + } + if inst.AccountMetaSlice[15] == nil { + return errors.New("accounts.SerumReqQ is not set") + } + if inst.AccountMetaSlice[16] == nil { + return errors.New("accounts.SerumEventQ is not set") + } + if inst.AccountMetaSlice[17] == nil { + return errors.New("accounts.SerumBids is not set") + } + if inst.AccountMetaSlice[18] == nil { + return errors.New("accounts.SerumAsks is not set") + } + } + return nil +} + +func (inst *MonitorStep) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("MonitorStep")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=3]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" PlanOrderLimit", *inst.PlanOrderLimit)) + paramsBranch.Child(ag_format.Param(" PlaceOrderLimit", *inst.PlaceOrderLimit)) + paramsBranch.Child(ag_format.Param("CancelOrderLimit", *inst.CancelOrderLimit)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=19]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" rent", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" clock", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" amm", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" ammAuthority", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" ammOpenOrders", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" ammTargetOrders", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" poolCoinToken", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" poolPcToken", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta("poolWithdrawQueue", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" serumProgram", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" serumMarket", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" serumCoinVault", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" serumPcVault", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta(" serumVaultSigner", inst.AccountMetaSlice.Get(14))) + accountsBranch.Child(ag_format.Meta(" serumReqQ", inst.AccountMetaSlice.Get(15))) + accountsBranch.Child(ag_format.Meta(" serumEventQ", inst.AccountMetaSlice.Get(16))) + accountsBranch.Child(ag_format.Meta(" serumBids", inst.AccountMetaSlice.Get(17))) + accountsBranch.Child(ag_format.Meta(" serumAsks", inst.AccountMetaSlice.Get(18))) + }) + }) + }) +} + +func (obj MonitorStep) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `PlanOrderLimit` param: + err = encoder.Encode(obj.PlanOrderLimit) + if err != nil { + return err + } + // Serialize `PlaceOrderLimit` param: + err = encoder.Encode(obj.PlaceOrderLimit) + if err != nil { + return err + } + // Serialize `CancelOrderLimit` param: + err = encoder.Encode(obj.CancelOrderLimit) + if err != nil { + return err + } + return nil +} +func (obj *MonitorStep) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `PlanOrderLimit`: + err = decoder.Decode(&obj.PlanOrderLimit) + if err != nil { + return err + } + // Deserialize `PlaceOrderLimit`: + err = decoder.Decode(&obj.PlaceOrderLimit) + if err != nil { + return err + } + // Deserialize `CancelOrderLimit`: + err = decoder.Decode(&obj.CancelOrderLimit) + if err != nil { + return err + } + return nil +} + +// NewMonitorStepInstruction declares a new MonitorStep instruction with the provided parameters and accounts. +func NewMonitorStepInstruction( + // Parameters: + planOrderLimit uint16, + placeOrderLimit uint16, + cancelOrderLimit uint16, + // Accounts: + tokenProgram ag_solanago.PublicKey, + rent ag_solanago.PublicKey, + clock ag_solanago.PublicKey, + amm ag_solanago.PublicKey, + ammAuthority ag_solanago.PublicKey, + ammOpenOrders ag_solanago.PublicKey, + ammTargetOrders ag_solanago.PublicKey, + poolCoinTokenAccount ag_solanago.PublicKey, + poolPcTokenAccount ag_solanago.PublicKey, + poolWithdrawQueue ag_solanago.PublicKey, + serumProgram ag_solanago.PublicKey, + serumMarket ag_solanago.PublicKey, + serumCoinVaultAccount ag_solanago.PublicKey, + serumPcVaultAccount ag_solanago.PublicKey, + serumVaultSigner ag_solanago.PublicKey, + serumReqQ ag_solanago.PublicKey, + serumEventQ ag_solanago.PublicKey, + serumBids ag_solanago.PublicKey, + serumAsks ag_solanago.PublicKey) *MonitorStep { + return NewMonitorStepInstructionBuilder(). + SetPlanOrderLimit(planOrderLimit). + SetPlaceOrderLimit(placeOrderLimit). + SetCancelOrderLimit(cancelOrderLimit). + SetTokenProgramAccount(tokenProgram). + SetRentAccount(rent). + SetClockAccount(clock). + SetAmmAccount(amm). + SetAmmAuthorityAccount(ammAuthority). + SetAmmOpenOrdersAccount(ammOpenOrders). + SetAmmTargetOrdersAccount(ammTargetOrders). + SetPoolCoinTokenAccountAccount(poolCoinTokenAccount). + SetPoolPcTokenAccountAccount(poolPcTokenAccount). + SetPoolWithdrawQueueAccount(poolWithdrawQueue). + SetSerumProgramAccount(serumProgram). + SetSerumMarketAccount(serumMarket). + SetSerumCoinVaultAccountAccount(serumCoinVaultAccount). + SetSerumPcVaultAccountAccount(serumPcVaultAccount). + SetSerumVaultSignerAccount(serumVaultSigner). + SetSerumReqQAccount(serumReqQ). + SetSerumEventQAccount(serumEventQ). + SetSerumBidsAccount(serumBids). + SetSerumAsksAccount(serumAsks) +} diff --git a/programs/raydiumamm/MonitorStep_test.go b/programs/raydiumamm/MonitorStep_test.go new file mode 100644 index 00000000..595c422d --- /dev/null +++ b/programs/raydiumamm/MonitorStep_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package raydium_amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_MonitorStep(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("MonitorStep"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(MonitorStep) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(MonitorStep) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/raydiumamm/PreInitialize.go b/programs/raydiumamm/PreInitialize.go new file mode 100644 index 00000000..889a0575 --- /dev/null +++ b/programs/raydiumamm/PreInitialize.go @@ -0,0 +1,374 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package raydium_amm + +import ( + "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" +) + +// PreInitialize is the `preInitialize` instruction. +type PreInitialize struct { + Nonce *uint8 + + // [0] = [] tokenProgram + // + // [1] = [] systemProgram + // + // [2] = [] rent + // + // [3] = [WRITE] ammTargetOrders + // + // [4] = [WRITE] poolWithdrawQueue + // + // [5] = [] ammAuthority + // + // [6] = [WRITE] lpMintAddress + // + // [7] = [] coinMintAddress + // + // [8] = [] pcMintAddress + // + // [9] = [WRITE] poolCoinTokenAccount + // + // [10] = [WRITE] poolPcTokenAccount + // + // [11] = [WRITE] poolTempLpTokenAccount + // + // [12] = [] serumMarket + // + // [13] = [WRITE, SIGNER] userWallet + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewPreInitializeInstructionBuilder creates a new `PreInitialize` instruction builder. +func NewPreInitializeInstructionBuilder() *PreInitialize { + nd := &PreInitialize{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 14), + } + return nd +} + +// SetNonce sets the "nonce" parameter. +func (inst *PreInitialize) SetNonce(nonce uint8) *PreInitialize { + inst.Nonce = &nonce + return inst +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *PreInitialize) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *PreInitialize { + inst.AccountMetaSlice[0] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *PreInitialize) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +func (inst *PreInitialize) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *PreInitialize { + inst.AccountMetaSlice[1] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +func (inst *PreInitialize) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetRentAccount sets the "rent" account. +func (inst *PreInitialize) SetRentAccount(rent ag_solanago.PublicKey) *PreInitialize { + inst.AccountMetaSlice[2] = ag_solanago.Meta(rent) + return inst +} + +// GetRentAccount gets the "rent" account. +func (inst *PreInitialize) GetRentAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetAmmTargetOrdersAccount sets the "ammTargetOrders" account. +func (inst *PreInitialize) SetAmmTargetOrdersAccount(ammTargetOrders ag_solanago.PublicKey) *PreInitialize { + inst.AccountMetaSlice[3] = ag_solanago.Meta(ammTargetOrders).WRITE() + return inst +} + +// GetAmmTargetOrdersAccount gets the "ammTargetOrders" account. +func (inst *PreInitialize) GetAmmTargetOrdersAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetPoolWithdrawQueueAccount sets the "poolWithdrawQueue" account. +func (inst *PreInitialize) SetPoolWithdrawQueueAccount(poolWithdrawQueue ag_solanago.PublicKey) *PreInitialize { + inst.AccountMetaSlice[4] = ag_solanago.Meta(poolWithdrawQueue).WRITE() + return inst +} + +// GetPoolWithdrawQueueAccount gets the "poolWithdrawQueue" account. +func (inst *PreInitialize) GetPoolWithdrawQueueAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetAmmAuthorityAccount sets the "ammAuthority" account. +func (inst *PreInitialize) SetAmmAuthorityAccount(ammAuthority ag_solanago.PublicKey) *PreInitialize { + inst.AccountMetaSlice[5] = ag_solanago.Meta(ammAuthority) + return inst +} + +// GetAmmAuthorityAccount gets the "ammAuthority" account. +func (inst *PreInitialize) GetAmmAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetLpMintAddressAccount sets the "lpMintAddress" account. +func (inst *PreInitialize) SetLpMintAddressAccount(lpMintAddress ag_solanago.PublicKey) *PreInitialize { + inst.AccountMetaSlice[6] = ag_solanago.Meta(lpMintAddress).WRITE() + return inst +} + +// GetLpMintAddressAccount gets the "lpMintAddress" account. +func (inst *PreInitialize) GetLpMintAddressAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetCoinMintAddressAccount sets the "coinMintAddress" account. +func (inst *PreInitialize) SetCoinMintAddressAccount(coinMintAddress ag_solanago.PublicKey) *PreInitialize { + inst.AccountMetaSlice[7] = ag_solanago.Meta(coinMintAddress) + return inst +} + +// GetCoinMintAddressAccount gets the "coinMintAddress" account. +func (inst *PreInitialize) GetCoinMintAddressAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetPcMintAddressAccount sets the "pcMintAddress" account. +func (inst *PreInitialize) SetPcMintAddressAccount(pcMintAddress ag_solanago.PublicKey) *PreInitialize { + inst.AccountMetaSlice[8] = ag_solanago.Meta(pcMintAddress) + return inst +} + +// GetPcMintAddressAccount gets the "pcMintAddress" account. +func (inst *PreInitialize) GetPcMintAddressAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetPoolCoinTokenAccountAccount sets the "poolCoinTokenAccount" account. +func (inst *PreInitialize) SetPoolCoinTokenAccountAccount(poolCoinTokenAccount ag_solanago.PublicKey) *PreInitialize { + inst.AccountMetaSlice[9] = ag_solanago.Meta(poolCoinTokenAccount).WRITE() + return inst +} + +// GetPoolCoinTokenAccountAccount gets the "poolCoinTokenAccount" account. +func (inst *PreInitialize) GetPoolCoinTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetPoolPcTokenAccountAccount sets the "poolPcTokenAccount" account. +func (inst *PreInitialize) SetPoolPcTokenAccountAccount(poolPcTokenAccount ag_solanago.PublicKey) *PreInitialize { + inst.AccountMetaSlice[10] = ag_solanago.Meta(poolPcTokenAccount).WRITE() + return inst +} + +// GetPoolPcTokenAccountAccount gets the "poolPcTokenAccount" account. +func (inst *PreInitialize) GetPoolPcTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetPoolTempLpTokenAccountAccount sets the "poolTempLpTokenAccount" account. +func (inst *PreInitialize) SetPoolTempLpTokenAccountAccount(poolTempLpTokenAccount ag_solanago.PublicKey) *PreInitialize { + inst.AccountMetaSlice[11] = ag_solanago.Meta(poolTempLpTokenAccount).WRITE() + return inst +} + +// GetPoolTempLpTokenAccountAccount gets the "poolTempLpTokenAccount" account. +func (inst *PreInitialize) GetPoolTempLpTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetSerumMarketAccount sets the "serumMarket" account. +func (inst *PreInitialize) SetSerumMarketAccount(serumMarket ag_solanago.PublicKey) *PreInitialize { + inst.AccountMetaSlice[12] = ag_solanago.Meta(serumMarket) + return inst +} + +// GetSerumMarketAccount gets the "serumMarket" account. +func (inst *PreInitialize) GetSerumMarketAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetUserWalletAccount sets the "userWallet" account. +func (inst *PreInitialize) SetUserWalletAccount(userWallet ag_solanago.PublicKey) *PreInitialize { + inst.AccountMetaSlice[13] = ag_solanago.Meta(userWallet).WRITE().SIGNER() + return inst +} + +// GetUserWalletAccount gets the "userWallet" account. +func (inst *PreInitialize) GetUserWalletAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +func (inst PreInitialize) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: ag_binary.TypeIDFromUint8(Instruction_PreInitialize), + }} +} + +// 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 PreInitialize) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *PreInitialize) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.Nonce == nil { + return errors.New("Nonce parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.SystemProgram is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.Rent is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.AmmTargetOrders is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.PoolWithdrawQueue is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.AmmAuthority is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.LpMintAddress is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.CoinMintAddress is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.PcMintAddress is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.PoolCoinTokenAccount is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.PoolPcTokenAccount is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.PoolTempLpTokenAccount is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.SerumMarket is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.UserWallet is not set") + } + } + return nil +} + +func (inst *PreInitialize) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("PreInitialize")). + // + 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("Nonce", *inst.Nonce)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=14]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" systemProgram", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" rent", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" ammTargetOrders", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta("poolWithdrawQueue", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" ammAuthority", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" lpMintAddress", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" coinMintAddress", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" pcMintAddress", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" poolCoinToken", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" poolPcToken", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" poolTempLpToken", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" serumMarket", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" userWallet", inst.AccountMetaSlice.Get(13))) + }) + }) + }) +} + +func (obj PreInitialize) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Nonce` param: + err = encoder.Encode(obj.Nonce) + if err != nil { + return err + } + return nil +} +func (obj *PreInitialize) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Nonce`: + err = decoder.Decode(&obj.Nonce) + if err != nil { + return err + } + return nil +} + +// NewPreInitializeInstruction declares a new PreInitialize instruction with the provided parameters and accounts. +func NewPreInitializeInstruction( + // Parameters: + nonce uint8, + // Accounts: + tokenProgram ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey, + rent ag_solanago.PublicKey, + ammTargetOrders ag_solanago.PublicKey, + poolWithdrawQueue ag_solanago.PublicKey, + ammAuthority ag_solanago.PublicKey, + lpMintAddress ag_solanago.PublicKey, + coinMintAddress ag_solanago.PublicKey, + pcMintAddress ag_solanago.PublicKey, + poolCoinTokenAccount ag_solanago.PublicKey, + poolPcTokenAccount ag_solanago.PublicKey, + poolTempLpTokenAccount ag_solanago.PublicKey, + serumMarket ag_solanago.PublicKey, + userWallet ag_solanago.PublicKey) *PreInitialize { + return NewPreInitializeInstructionBuilder(). + SetNonce(nonce). + SetTokenProgramAccount(tokenProgram). + SetSystemProgramAccount(systemProgram). + SetRentAccount(rent). + SetAmmTargetOrdersAccount(ammTargetOrders). + SetPoolWithdrawQueueAccount(poolWithdrawQueue). + SetAmmAuthorityAccount(ammAuthority). + SetLpMintAddressAccount(lpMintAddress). + SetCoinMintAddressAccount(coinMintAddress). + SetPcMintAddressAccount(pcMintAddress). + SetPoolCoinTokenAccountAccount(poolCoinTokenAccount). + SetPoolPcTokenAccountAccount(poolPcTokenAccount). + SetPoolTempLpTokenAccountAccount(poolTempLpTokenAccount). + SetSerumMarketAccount(serumMarket). + SetUserWalletAccount(userWallet) +} diff --git a/programs/raydiumamm/PreInitialize_test.go b/programs/raydiumamm/PreInitialize_test.go new file mode 100644 index 00000000..eed33ecf --- /dev/null +++ b/programs/raydiumamm/PreInitialize_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package raydium_amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_PreInitialize(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("PreInitialize"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(PreInitialize) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(PreInitialize) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/raydiumamm/SetParams.go b/programs/raydiumamm/SetParams.go new file mode 100644 index 00000000..127c5494 --- /dev/null +++ b/programs/raydiumamm/SetParams.go @@ -0,0 +1,617 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package raydium_amm + +import ( + "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" +) + +// SetParams is the `setParams` instruction. +type SetParams struct { + Param *uint8 + Value *uint64 `bin:"optional"` + NewPubkey *ag_solanago.PublicKey `bin:"optional"` + Fees *Fees `bin:"optional"` + LastOrderDistance *LastOrderDistance `bin:"optional"` + NeedTakeAmounts *NeedTake `bin:"optional"` + + // [0] = [] tokenProgram + // + // [1] = [WRITE] amm + // + // [2] = [] ammAuthority + // + // [3] = [WRITE] ammOpenOrders + // + // [4] = [WRITE] ammTargetOrders + // + // [5] = [WRITE] ammCoinVault + // + // [6] = [WRITE] ammPcVault + // + // [7] = [] serumProgram + // + // [8] = [WRITE] serumMarket + // + // [9] = [WRITE] serumCoinVault + // + // [10] = [WRITE] serumPcVault + // + // [11] = [] serumVaultSigner + // + // [12] = [WRITE] serumEventQueue + // + // [13] = [WRITE] serumBids + // + // [14] = [WRITE] serumAsks + // + // [15] = [SIGNER] ammAdminAccount + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewSetParamsInstructionBuilder creates a new `SetParams` instruction builder. +func NewSetParamsInstructionBuilder() *SetParams { + nd := &SetParams{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 16), + } + return nd +} + +// SetParam sets the "param" parameter. +func (inst *SetParams) SetParam(param uint8) *SetParams { + inst.Param = ¶m + return inst +} + +// SetValue sets the "value" parameter. +func (inst *SetParams) SetValue(value uint64) *SetParams { + inst.Value = &value + return inst +} + +// SetNewPubkey sets the "newPubkey" parameter. +func (inst *SetParams) SetNewPubkey(newPubkey ag_solanago.PublicKey) *SetParams { + inst.NewPubkey = &newPubkey + return inst +} + +// SetFees sets the "fees" parameter. +func (inst *SetParams) SetFees(fees Fees) *SetParams { + inst.Fees = &fees + return inst +} + +// SetLastOrderDistance sets the "lastOrderDistance" parameter. +func (inst *SetParams) SetLastOrderDistance(lastOrderDistance LastOrderDistance) *SetParams { + inst.LastOrderDistance = &lastOrderDistance + return inst +} + +// SetNeedTakeAmounts sets the "needTakeAmounts" parameter. +func (inst *SetParams) SetNeedTakeAmounts(needTakeAmounts NeedTake) *SetParams { + inst.NeedTakeAmounts = &needTakeAmounts + return inst +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *SetParams) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *SetParams { + inst.AccountMetaSlice[0] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *SetParams) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetAmmAccount sets the "amm" account. +func (inst *SetParams) SetAmmAccount(amm ag_solanago.PublicKey) *SetParams { + inst.AccountMetaSlice[1] = ag_solanago.Meta(amm).WRITE() + return inst +} + +// GetAmmAccount gets the "amm" account. +func (inst *SetParams) GetAmmAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetAmmAuthorityAccount sets the "ammAuthority" account. +func (inst *SetParams) SetAmmAuthorityAccount(ammAuthority ag_solanago.PublicKey) *SetParams { + inst.AccountMetaSlice[2] = ag_solanago.Meta(ammAuthority) + return inst +} + +// GetAmmAuthorityAccount gets the "ammAuthority" account. +func (inst *SetParams) GetAmmAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetAmmOpenOrdersAccount sets the "ammOpenOrders" account. +func (inst *SetParams) SetAmmOpenOrdersAccount(ammOpenOrders ag_solanago.PublicKey) *SetParams { + inst.AccountMetaSlice[3] = ag_solanago.Meta(ammOpenOrders).WRITE() + return inst +} + +// GetAmmOpenOrdersAccount gets the "ammOpenOrders" account. +func (inst *SetParams) GetAmmOpenOrdersAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetAmmTargetOrdersAccount sets the "ammTargetOrders" account. +func (inst *SetParams) SetAmmTargetOrdersAccount(ammTargetOrders ag_solanago.PublicKey) *SetParams { + inst.AccountMetaSlice[4] = ag_solanago.Meta(ammTargetOrders).WRITE() + return inst +} + +// GetAmmTargetOrdersAccount gets the "ammTargetOrders" account. +func (inst *SetParams) GetAmmTargetOrdersAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetAmmCoinVaultAccount sets the "ammCoinVault" account. +func (inst *SetParams) SetAmmCoinVaultAccount(ammCoinVault ag_solanago.PublicKey) *SetParams { + inst.AccountMetaSlice[5] = ag_solanago.Meta(ammCoinVault).WRITE() + return inst +} + +// GetAmmCoinVaultAccount gets the "ammCoinVault" account. +func (inst *SetParams) GetAmmCoinVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetAmmPcVaultAccount sets the "ammPcVault" account. +func (inst *SetParams) SetAmmPcVaultAccount(ammPcVault ag_solanago.PublicKey) *SetParams { + inst.AccountMetaSlice[6] = ag_solanago.Meta(ammPcVault).WRITE() + return inst +} + +// GetAmmPcVaultAccount gets the "ammPcVault" account. +func (inst *SetParams) GetAmmPcVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetSerumProgramAccount sets the "serumProgram" account. +func (inst *SetParams) SetSerumProgramAccount(serumProgram ag_solanago.PublicKey) *SetParams { + inst.AccountMetaSlice[7] = ag_solanago.Meta(serumProgram) + return inst +} + +// GetSerumProgramAccount gets the "serumProgram" account. +func (inst *SetParams) GetSerumProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetSerumMarketAccount sets the "serumMarket" account. +func (inst *SetParams) SetSerumMarketAccount(serumMarket ag_solanago.PublicKey) *SetParams { + inst.AccountMetaSlice[8] = ag_solanago.Meta(serumMarket).WRITE() + return inst +} + +// GetSerumMarketAccount gets the "serumMarket" account. +func (inst *SetParams) GetSerumMarketAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetSerumCoinVaultAccount sets the "serumCoinVault" account. +func (inst *SetParams) SetSerumCoinVaultAccount(serumCoinVault ag_solanago.PublicKey) *SetParams { + inst.AccountMetaSlice[9] = ag_solanago.Meta(serumCoinVault).WRITE() + return inst +} + +// GetSerumCoinVaultAccount gets the "serumCoinVault" account. +func (inst *SetParams) GetSerumCoinVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetSerumPcVaultAccount sets the "serumPcVault" account. +func (inst *SetParams) SetSerumPcVaultAccount(serumPcVault ag_solanago.PublicKey) *SetParams { + inst.AccountMetaSlice[10] = ag_solanago.Meta(serumPcVault).WRITE() + return inst +} + +// GetSerumPcVaultAccount gets the "serumPcVault" account. +func (inst *SetParams) GetSerumPcVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetSerumVaultSignerAccount sets the "serumVaultSigner" account. +func (inst *SetParams) SetSerumVaultSignerAccount(serumVaultSigner ag_solanago.PublicKey) *SetParams { + inst.AccountMetaSlice[11] = ag_solanago.Meta(serumVaultSigner) + return inst +} + +// GetSerumVaultSignerAccount gets the "serumVaultSigner" account. +func (inst *SetParams) GetSerumVaultSignerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetSerumEventQueueAccount sets the "serumEventQueue" account. +func (inst *SetParams) SetSerumEventQueueAccount(serumEventQueue ag_solanago.PublicKey) *SetParams { + inst.AccountMetaSlice[12] = ag_solanago.Meta(serumEventQueue).WRITE() + return inst +} + +// GetSerumEventQueueAccount gets the "serumEventQueue" account. +func (inst *SetParams) GetSerumEventQueueAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetSerumBidsAccount sets the "serumBids" account. +func (inst *SetParams) SetSerumBidsAccount(serumBids ag_solanago.PublicKey) *SetParams { + inst.AccountMetaSlice[13] = ag_solanago.Meta(serumBids).WRITE() + return inst +} + +// GetSerumBidsAccount gets the "serumBids" account. +func (inst *SetParams) GetSerumBidsAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetSerumAsksAccount sets the "serumAsks" account. +func (inst *SetParams) SetSerumAsksAccount(serumAsks ag_solanago.PublicKey) *SetParams { + inst.AccountMetaSlice[14] = ag_solanago.Meta(serumAsks).WRITE() + return inst +} + +// GetSerumAsksAccount gets the "serumAsks" account. +func (inst *SetParams) GetSerumAsksAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +// SetAmmAdminAccountAccount sets the "ammAdminAccount" account. +func (inst *SetParams) SetAmmAdminAccountAccount(ammAdminAccount ag_solanago.PublicKey) *SetParams { + inst.AccountMetaSlice[15] = ag_solanago.Meta(ammAdminAccount).SIGNER() + return inst +} + +// GetAmmAdminAccountAccount gets the "ammAdminAccount" account. +func (inst *SetParams) GetAmmAdminAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(15) +} + +func (inst SetParams) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: ag_binary.TypeIDFromUint8(Instruction_SetParams), + }} +} + +// 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 SetParams) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *SetParams) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.Param == nil { + return errors.New("Param parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Amm is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.AmmAuthority is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.AmmOpenOrders is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.AmmTargetOrders is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.AmmCoinVault is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.AmmPcVault is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.SerumProgram is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.SerumMarket is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.SerumCoinVault is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.SerumPcVault is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.SerumVaultSigner is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.SerumEventQueue is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.SerumBids is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.SerumAsks is not set") + } + if inst.AccountMetaSlice[15] == nil { + return errors.New("accounts.AmmAdminAccount is not set") + } + } + return nil +} + +func (inst *SetParams) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("SetParams")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=6]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" Param", *inst.Param)) + paramsBranch.Child(ag_format.Param(" Value (OPT)", inst.Value)) + paramsBranch.Child(ag_format.Param(" NewPubkey (OPT)", inst.NewPubkey)) + paramsBranch.Child(ag_format.Param(" Fees (OPT)", inst.Fees)) + paramsBranch.Child(ag_format.Param("LastOrderDistance (OPT)", inst.LastOrderDistance)) + paramsBranch.Child(ag_format.Param(" NeedTakeAmounts (OPT)", inst.NeedTakeAmounts)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=16]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" amm", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" ammAuthority", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" ammOpenOrders", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" ammTargetOrders", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" ammCoinVault", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" ammPcVault", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" serumProgram", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" serumMarket", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" serumCoinVault", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" serumPcVault", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta("serumVaultSigner", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" serumEventQueue", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" serumBids", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta(" serumAsks", inst.AccountMetaSlice.Get(14))) + accountsBranch.Child(ag_format.Meta(" ammAdmin", inst.AccountMetaSlice.Get(15))) + }) + }) + }) +} + +func (obj SetParams) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Param` param: + err = encoder.Encode(obj.Param) + if err != nil { + return err + } + // Serialize `Value` param (optional): + { + if obj.Value == nil { + err = encoder.WriteBool(false) + if err != nil { + return err + } + } else { + err = encoder.WriteBool(true) + if err != nil { + return err + } + err = encoder.Encode(obj.Value) + if err != nil { + return err + } + } + } + // Serialize `NewPubkey` param (optional): + { + if obj.NewPubkey == nil { + err = encoder.WriteBool(false) + if err != nil { + return err + } + } else { + err = encoder.WriteBool(true) + if err != nil { + return err + } + err = encoder.Encode(obj.NewPubkey) + if err != nil { + return err + } + } + } + // Serialize `Fees` param (optional): + { + if obj.Fees == nil { + err = encoder.WriteBool(false) + if err != nil { + return err + } + } else { + err = encoder.WriteBool(true) + if err != nil { + return err + } + err = encoder.Encode(obj.Fees) + if err != nil { + return err + } + } + } + // Serialize `LastOrderDistance` param (optional): + { + if obj.LastOrderDistance == nil { + err = encoder.WriteBool(false) + if err != nil { + return err + } + } else { + err = encoder.WriteBool(true) + if err != nil { + return err + } + err = encoder.Encode(obj.LastOrderDistance) + if err != nil { + return err + } + } + } + // Serialize `NeedTakeAmounts` param (optional): + { + if obj.NeedTakeAmounts == nil { + err = encoder.WriteBool(false) + if err != nil { + return err + } + } else { + err = encoder.WriteBool(true) + if err != nil { + return err + } + err = encoder.Encode(obj.NeedTakeAmounts) + if err != nil { + return err + } + } + } + return nil +} +func (obj *SetParams) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Param`: + err = decoder.Decode(&obj.Param) + if err != nil { + return err + } + // Deserialize `Value` (optional): + { + ok, err := decoder.ReadBool() + if err != nil { + return err + } + if ok { + err = decoder.Decode(&obj.Value) + if err != nil { + return err + } + } + } + // Deserialize `NewPubkey` (optional): + { + ok, err := decoder.ReadBool() + if err != nil { + return err + } + if ok { + err = decoder.Decode(&obj.NewPubkey) + if err != nil { + return err + } + } + } + // Deserialize `Fees` (optional): + { + ok, err := decoder.ReadBool() + if err != nil { + return err + } + if ok { + err = decoder.Decode(&obj.Fees) + if err != nil { + return err + } + } + } + // Deserialize `LastOrderDistance` (optional): + { + ok, err := decoder.ReadBool() + if err != nil { + return err + } + if ok { + err = decoder.Decode(&obj.LastOrderDistance) + if err != nil { + return err + } + } + } + // Deserialize `NeedTakeAmounts` (optional): + { + ok, err := decoder.ReadBool() + if err != nil { + return err + } + if ok { + err = decoder.Decode(&obj.NeedTakeAmounts) + if err != nil { + return err + } + } + } + return nil +} + +// NewSetParamsInstruction declares a new SetParams instruction with the provided parameters and accounts. +func NewSetParamsInstruction( + // Parameters: + param uint8, + value uint64, + newPubkey ag_solanago.PublicKey, + fees Fees, + lastOrderDistance LastOrderDistance, + needTakeAmounts NeedTake, + // Accounts: + tokenProgram ag_solanago.PublicKey, + amm ag_solanago.PublicKey, + ammAuthority ag_solanago.PublicKey, + ammOpenOrders ag_solanago.PublicKey, + ammTargetOrders ag_solanago.PublicKey, + ammCoinVault ag_solanago.PublicKey, + ammPcVault ag_solanago.PublicKey, + serumProgram ag_solanago.PublicKey, + serumMarket ag_solanago.PublicKey, + serumCoinVault ag_solanago.PublicKey, + serumPcVault ag_solanago.PublicKey, + serumVaultSigner ag_solanago.PublicKey, + serumEventQueue ag_solanago.PublicKey, + serumBids ag_solanago.PublicKey, + serumAsks ag_solanago.PublicKey, + ammAdminAccount ag_solanago.PublicKey) *SetParams { + return NewSetParamsInstructionBuilder(). + SetParam(param). + SetValue(value). + SetNewPubkey(newPubkey). + SetFees(fees). + SetLastOrderDistance(lastOrderDistance). + SetNeedTakeAmounts(needTakeAmounts). + SetTokenProgramAccount(tokenProgram). + SetAmmAccount(amm). + SetAmmAuthorityAccount(ammAuthority). + SetAmmOpenOrdersAccount(ammOpenOrders). + SetAmmTargetOrdersAccount(ammTargetOrders). + SetAmmCoinVaultAccount(ammCoinVault). + SetAmmPcVaultAccount(ammPcVault). + SetSerumProgramAccount(serumProgram). + SetSerumMarketAccount(serumMarket). + SetSerumCoinVaultAccount(serumCoinVault). + SetSerumPcVaultAccount(serumPcVault). + SetSerumVaultSignerAccount(serumVaultSigner). + SetSerumEventQueueAccount(serumEventQueue). + SetSerumBidsAccount(serumBids). + SetSerumAsksAccount(serumAsks). + SetAmmAdminAccountAccount(ammAdminAccount) +} diff --git a/programs/raydiumamm/SetParams_test.go b/programs/raydiumamm/SetParams_test.go new file mode 100644 index 00000000..0bead896 --- /dev/null +++ b/programs/raydiumamm/SetParams_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package raydium_amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_SetParams(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("SetParams"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(SetParams) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(SetParams) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/raydiumamm/SimulateInfo.go b/programs/raydiumamm/SimulateInfo.go new file mode 100644 index 00000000..8e8fbebe --- /dev/null +++ b/programs/raydiumamm/SimulateInfo.go @@ -0,0 +1,342 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package raydium_amm + +import ( + "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" +) + +// SimulateInfo is the `simulateInfo` instruction. +type SimulateInfo struct { + Param *uint8 + SwapBaseInValue *SwapInstructionBaseIn `bin:"optional"` + SwapBaseOutValue *SwapInstructionBaseOut `bin:"optional"` + + // [0] = [] amm + // + // [1] = [] ammAuthority + // + // [2] = [] ammOpenOrders + // + // [3] = [] poolCoinTokenAccount + // + // [4] = [] poolPcTokenAccount + // + // [5] = [] lpMintAddress + // + // [6] = [] serumMarket + // + // [7] = [] serumEventQueue + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewSimulateInfoInstructionBuilder creates a new `SimulateInfo` instruction builder. +func NewSimulateInfoInstructionBuilder() *SimulateInfo { + nd := &SimulateInfo{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 8), + } + return nd +} + +// SetParam sets the "param" parameter. +func (inst *SimulateInfo) SetParam(param uint8) *SimulateInfo { + inst.Param = ¶m + return inst +} + +// SetSwapBaseInValue sets the "swapBaseInValue" parameter. +func (inst *SimulateInfo) SetSwapBaseInValue(swapBaseInValue SwapInstructionBaseIn) *SimulateInfo { + inst.SwapBaseInValue = &swapBaseInValue + return inst +} + +// SetSwapBaseOutValue sets the "swapBaseOutValue" parameter. +func (inst *SimulateInfo) SetSwapBaseOutValue(swapBaseOutValue SwapInstructionBaseOut) *SimulateInfo { + inst.SwapBaseOutValue = &swapBaseOutValue + return inst +} + +// SetAmmAccount sets the "amm" account. +func (inst *SimulateInfo) SetAmmAccount(amm ag_solanago.PublicKey) *SimulateInfo { + inst.AccountMetaSlice[0] = ag_solanago.Meta(amm) + return inst +} + +// GetAmmAccount gets the "amm" account. +func (inst *SimulateInfo) GetAmmAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetAmmAuthorityAccount sets the "ammAuthority" account. +func (inst *SimulateInfo) SetAmmAuthorityAccount(ammAuthority ag_solanago.PublicKey) *SimulateInfo { + inst.AccountMetaSlice[1] = ag_solanago.Meta(ammAuthority) + return inst +} + +// GetAmmAuthorityAccount gets the "ammAuthority" account. +func (inst *SimulateInfo) GetAmmAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetAmmOpenOrdersAccount sets the "ammOpenOrders" account. +func (inst *SimulateInfo) SetAmmOpenOrdersAccount(ammOpenOrders ag_solanago.PublicKey) *SimulateInfo { + inst.AccountMetaSlice[2] = ag_solanago.Meta(ammOpenOrders) + return inst +} + +// GetAmmOpenOrdersAccount gets the "ammOpenOrders" account. +func (inst *SimulateInfo) GetAmmOpenOrdersAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetPoolCoinTokenAccountAccount sets the "poolCoinTokenAccount" account. +func (inst *SimulateInfo) SetPoolCoinTokenAccountAccount(poolCoinTokenAccount ag_solanago.PublicKey) *SimulateInfo { + inst.AccountMetaSlice[3] = ag_solanago.Meta(poolCoinTokenAccount) + return inst +} + +// GetPoolCoinTokenAccountAccount gets the "poolCoinTokenAccount" account. +func (inst *SimulateInfo) GetPoolCoinTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetPoolPcTokenAccountAccount sets the "poolPcTokenAccount" account. +func (inst *SimulateInfo) SetPoolPcTokenAccountAccount(poolPcTokenAccount ag_solanago.PublicKey) *SimulateInfo { + inst.AccountMetaSlice[4] = ag_solanago.Meta(poolPcTokenAccount) + return inst +} + +// GetPoolPcTokenAccountAccount gets the "poolPcTokenAccount" account. +func (inst *SimulateInfo) GetPoolPcTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetLpMintAddressAccount sets the "lpMintAddress" account. +func (inst *SimulateInfo) SetLpMintAddressAccount(lpMintAddress ag_solanago.PublicKey) *SimulateInfo { + inst.AccountMetaSlice[5] = ag_solanago.Meta(lpMintAddress) + return inst +} + +// GetLpMintAddressAccount gets the "lpMintAddress" account. +func (inst *SimulateInfo) GetLpMintAddressAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetSerumMarketAccount sets the "serumMarket" account. +func (inst *SimulateInfo) SetSerumMarketAccount(serumMarket ag_solanago.PublicKey) *SimulateInfo { + inst.AccountMetaSlice[6] = ag_solanago.Meta(serumMarket) + return inst +} + +// GetSerumMarketAccount gets the "serumMarket" account. +func (inst *SimulateInfo) GetSerumMarketAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetSerumEventQueueAccount sets the "serumEventQueue" account. +func (inst *SimulateInfo) SetSerumEventQueueAccount(serumEventQueue ag_solanago.PublicKey) *SimulateInfo { + inst.AccountMetaSlice[7] = ag_solanago.Meta(serumEventQueue) + return inst +} + +// GetSerumEventQueueAccount gets the "serumEventQueue" account. +func (inst *SimulateInfo) GetSerumEventQueueAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +func (inst SimulateInfo) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: ag_binary.TypeIDFromUint8(Instruction_SimulateInfo), + }} +} + +// 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 SimulateInfo) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *SimulateInfo) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.Param == nil { + return errors.New("Param parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Amm is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.AmmAuthority is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.AmmOpenOrders is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.PoolCoinTokenAccount is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.PoolPcTokenAccount is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.LpMintAddress is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.SerumMarket is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.SerumEventQueue is not set") + } + } + return nil +} + +func (inst *SimulateInfo) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("SimulateInfo")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=3]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" Param", *inst.Param)) + paramsBranch.Child(ag_format.Param(" SwapBaseInValue (OPT)", inst.SwapBaseInValue)) + paramsBranch.Child(ag_format.Param("SwapBaseOutValue (OPT)", inst.SwapBaseOutValue)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=8]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" amm", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" ammAuthority", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" ammOpenOrders", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" poolCoinToken", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" poolPcToken", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" lpMintAddress", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" serumMarket", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta("serumEventQueue", inst.AccountMetaSlice.Get(7))) + }) + }) + }) +} + +func (obj SimulateInfo) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Param` param: + err = encoder.Encode(obj.Param) + if err != nil { + return err + } + // Serialize `SwapBaseInValue` param (optional): + { + if obj.SwapBaseInValue == nil { + err = encoder.WriteBool(false) + if err != nil { + return err + } + } else { + err = encoder.WriteBool(true) + if err != nil { + return err + } + err = encoder.Encode(obj.SwapBaseInValue) + if err != nil { + return err + } + } + } + // Serialize `SwapBaseOutValue` param (optional): + { + if obj.SwapBaseOutValue == nil { + err = encoder.WriteBool(false) + if err != nil { + return err + } + } else { + err = encoder.WriteBool(true) + if err != nil { + return err + } + err = encoder.Encode(obj.SwapBaseOutValue) + if err != nil { + return err + } + } + } + return nil +} +func (obj *SimulateInfo) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Param`: + err = decoder.Decode(&obj.Param) + if err != nil { + return err + } + // Deserialize `SwapBaseInValue` (optional): + { + ok, err := decoder.ReadBool() + if err != nil { + return err + } + if ok { + err = decoder.Decode(&obj.SwapBaseInValue) + if err != nil { + return err + } + } + } + // Deserialize `SwapBaseOutValue` (optional): + { + ok, err := decoder.ReadBool() + if err != nil { + return err + } + if ok { + err = decoder.Decode(&obj.SwapBaseOutValue) + if err != nil { + return err + } + } + } + return nil +} + +// NewSimulateInfoInstruction declares a new SimulateInfo instruction with the provided parameters and accounts. +func NewSimulateInfoInstruction( + // Parameters: + param uint8, + swapBaseInValue SwapInstructionBaseIn, + swapBaseOutValue SwapInstructionBaseOut, + // Accounts: + amm ag_solanago.PublicKey, + ammAuthority ag_solanago.PublicKey, + ammOpenOrders ag_solanago.PublicKey, + poolCoinTokenAccount ag_solanago.PublicKey, + poolPcTokenAccount ag_solanago.PublicKey, + lpMintAddress ag_solanago.PublicKey, + serumMarket ag_solanago.PublicKey, + serumEventQueue ag_solanago.PublicKey) *SimulateInfo { + return NewSimulateInfoInstructionBuilder(). + SetParam(param). + SetSwapBaseInValue(swapBaseInValue). + SetSwapBaseOutValue(swapBaseOutValue). + SetAmmAccount(amm). + SetAmmAuthorityAccount(ammAuthority). + SetAmmOpenOrdersAccount(ammOpenOrders). + SetPoolCoinTokenAccountAccount(poolCoinTokenAccount). + SetPoolPcTokenAccountAccount(poolPcTokenAccount). + SetLpMintAddressAccount(lpMintAddress). + SetSerumMarketAccount(serumMarket). + SetSerumEventQueueAccount(serumEventQueue) +} diff --git a/programs/raydiumamm/SimulateInfo_test.go b/programs/raydiumamm/SimulateInfo_test.go new file mode 100644 index 00000000..5b13d463 --- /dev/null +++ b/programs/raydiumamm/SimulateInfo_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package raydium_amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_SimulateInfo(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("SimulateInfo"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(SimulateInfo) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(SimulateInfo) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/raydiumamm/SwapBaseIn.go b/programs/raydiumamm/SwapBaseIn.go new file mode 100644 index 00000000..1548baee --- /dev/null +++ b/programs/raydiumamm/SwapBaseIn.go @@ -0,0 +1,473 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package raydium_amm + +import ( + "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" +) + +// SwapBaseIn is the `swapBaseIn` instruction. +type SwapBaseIn struct { + AmountIn *uint64 + MinimumAmountOut *uint64 + + // [0] = [] tokenProgram + // + // [1] = [WRITE] amm + // + // [2] = [] ammAuthority + // + // [3] = [WRITE] ammOpenOrders + // + // [4] = [WRITE] ammTargetOrders + // + // [5] = [WRITE] poolCoinTokenAccount + // + // [6] = [WRITE] poolPcTokenAccount + // + // [7] = [] serumProgram + // + // [8] = [WRITE] serumMarket + // + // [9] = [WRITE] serumBids + // + // [10] = [WRITE] serumAsks + // + // [11] = [WRITE] serumEventQueue + // + // [12] = [WRITE] serumCoinVaultAccount + // + // [13] = [WRITE] serumPcVaultAccount + // + // [14] = [] serumVaultSigner + // + // [15] = [WRITE] uerSourceTokenAccount + // + // [16] = [WRITE] uerDestinationTokenAccount + // + // [17] = [SIGNER] userSourceOwner + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewSwapBaseInInstructionBuilder creates a new `SwapBaseIn` instruction builder. +func NewSwapBaseInInstructionBuilder() *SwapBaseIn { + nd := &SwapBaseIn{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 18), + } + return nd +} + +// SetAmountIn sets the "amountIn" parameter. +func (inst *SwapBaseIn) SetAmountIn(amountIn uint64) *SwapBaseIn { + inst.AmountIn = &amountIn + return inst +} + +// SetMinimumAmountOut sets the "minimumAmountOut" parameter. +func (inst *SwapBaseIn) SetMinimumAmountOut(minimumAmountOut uint64) *SwapBaseIn { + inst.MinimumAmountOut = &minimumAmountOut + return inst +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *SwapBaseIn) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *SwapBaseIn { + inst.AccountMetaSlice[0] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *SwapBaseIn) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetAmmAccount sets the "amm" account. +func (inst *SwapBaseIn) SetAmmAccount(amm ag_solanago.PublicKey) *SwapBaseIn { + inst.AccountMetaSlice[1] = ag_solanago.Meta(amm).WRITE() + return inst +} + +// GetAmmAccount gets the "amm" account. +func (inst *SwapBaseIn) GetAmmAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetAmmAuthorityAccount sets the "ammAuthority" account. +func (inst *SwapBaseIn) SetAmmAuthorityAccount(ammAuthority ag_solanago.PublicKey) *SwapBaseIn { + inst.AccountMetaSlice[2] = ag_solanago.Meta(ammAuthority) + return inst +} + +// GetAmmAuthorityAccount gets the "ammAuthority" account. +func (inst *SwapBaseIn) GetAmmAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetAmmOpenOrdersAccount sets the "ammOpenOrders" account. +func (inst *SwapBaseIn) SetAmmOpenOrdersAccount(ammOpenOrders ag_solanago.PublicKey) *SwapBaseIn { + inst.AccountMetaSlice[3] = ag_solanago.Meta(ammOpenOrders).WRITE() + return inst +} + +// GetAmmOpenOrdersAccount gets the "ammOpenOrders" account. +func (inst *SwapBaseIn) GetAmmOpenOrdersAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetAmmTargetOrdersAccount sets the "ammTargetOrders" account. +func (inst *SwapBaseIn) SetAmmTargetOrdersAccount(ammTargetOrders ag_solanago.PublicKey) *SwapBaseIn { + inst.AccountMetaSlice[4] = ag_solanago.Meta(ammTargetOrders).WRITE() + return inst +} + +// GetAmmTargetOrdersAccount gets the "ammTargetOrders" account. +func (inst *SwapBaseIn) GetAmmTargetOrdersAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetPoolCoinTokenAccountAccount sets the "poolCoinTokenAccount" account. +func (inst *SwapBaseIn) SetPoolCoinTokenAccountAccount(poolCoinTokenAccount ag_solanago.PublicKey) *SwapBaseIn { + inst.AccountMetaSlice[5] = ag_solanago.Meta(poolCoinTokenAccount).WRITE() + return inst +} + +// GetPoolCoinTokenAccountAccount gets the "poolCoinTokenAccount" account. +func (inst *SwapBaseIn) GetPoolCoinTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetPoolPcTokenAccountAccount sets the "poolPcTokenAccount" account. +func (inst *SwapBaseIn) SetPoolPcTokenAccountAccount(poolPcTokenAccount ag_solanago.PublicKey) *SwapBaseIn { + inst.AccountMetaSlice[6] = ag_solanago.Meta(poolPcTokenAccount).WRITE() + return inst +} + +// GetPoolPcTokenAccountAccount gets the "poolPcTokenAccount" account. +func (inst *SwapBaseIn) GetPoolPcTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetSerumProgramAccount sets the "serumProgram" account. +func (inst *SwapBaseIn) SetSerumProgramAccount(serumProgram ag_solanago.PublicKey) *SwapBaseIn { + inst.AccountMetaSlice[7] = ag_solanago.Meta(serumProgram) + return inst +} + +// GetSerumProgramAccount gets the "serumProgram" account. +func (inst *SwapBaseIn) GetSerumProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetSerumMarketAccount sets the "serumMarket" account. +func (inst *SwapBaseIn) SetSerumMarketAccount(serumMarket ag_solanago.PublicKey) *SwapBaseIn { + inst.AccountMetaSlice[8] = ag_solanago.Meta(serumMarket).WRITE() + return inst +} + +// GetSerumMarketAccount gets the "serumMarket" account. +func (inst *SwapBaseIn) GetSerumMarketAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetSerumBidsAccount sets the "serumBids" account. +func (inst *SwapBaseIn) SetSerumBidsAccount(serumBids ag_solanago.PublicKey) *SwapBaseIn { + inst.AccountMetaSlice[9] = ag_solanago.Meta(serumBids).WRITE() + return inst +} + +// GetSerumBidsAccount gets the "serumBids" account. +func (inst *SwapBaseIn) GetSerumBidsAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetSerumAsksAccount sets the "serumAsks" account. +func (inst *SwapBaseIn) SetSerumAsksAccount(serumAsks ag_solanago.PublicKey) *SwapBaseIn { + inst.AccountMetaSlice[10] = ag_solanago.Meta(serumAsks).WRITE() + return inst +} + +// GetSerumAsksAccount gets the "serumAsks" account. +func (inst *SwapBaseIn) GetSerumAsksAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetSerumEventQueueAccount sets the "serumEventQueue" account. +func (inst *SwapBaseIn) SetSerumEventQueueAccount(serumEventQueue ag_solanago.PublicKey) *SwapBaseIn { + inst.AccountMetaSlice[11] = ag_solanago.Meta(serumEventQueue).WRITE() + return inst +} + +// GetSerumEventQueueAccount gets the "serumEventQueue" account. +func (inst *SwapBaseIn) GetSerumEventQueueAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetSerumCoinVaultAccountAccount sets the "serumCoinVaultAccount" account. +func (inst *SwapBaseIn) SetSerumCoinVaultAccountAccount(serumCoinVaultAccount ag_solanago.PublicKey) *SwapBaseIn { + inst.AccountMetaSlice[12] = ag_solanago.Meta(serumCoinVaultAccount).WRITE() + return inst +} + +// GetSerumCoinVaultAccountAccount gets the "serumCoinVaultAccount" account. +func (inst *SwapBaseIn) GetSerumCoinVaultAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetSerumPcVaultAccountAccount sets the "serumPcVaultAccount" account. +func (inst *SwapBaseIn) SetSerumPcVaultAccountAccount(serumPcVaultAccount ag_solanago.PublicKey) *SwapBaseIn { + inst.AccountMetaSlice[13] = ag_solanago.Meta(serumPcVaultAccount).WRITE() + return inst +} + +// GetSerumPcVaultAccountAccount gets the "serumPcVaultAccount" account. +func (inst *SwapBaseIn) GetSerumPcVaultAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetSerumVaultSignerAccount sets the "serumVaultSigner" account. +func (inst *SwapBaseIn) SetSerumVaultSignerAccount(serumVaultSigner ag_solanago.PublicKey) *SwapBaseIn { + inst.AccountMetaSlice[14] = ag_solanago.Meta(serumVaultSigner) + return inst +} + +// GetSerumVaultSignerAccount gets the "serumVaultSigner" account. +func (inst *SwapBaseIn) GetSerumVaultSignerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +// SetUerSourceTokenAccountAccount sets the "uerSourceTokenAccount" account. +func (inst *SwapBaseIn) SetUerSourceTokenAccountAccount(uerSourceTokenAccount ag_solanago.PublicKey) *SwapBaseIn { + inst.AccountMetaSlice[15] = ag_solanago.Meta(uerSourceTokenAccount).WRITE() + return inst +} + +// GetUerSourceTokenAccountAccount gets the "uerSourceTokenAccount" account. +func (inst *SwapBaseIn) GetUerSourceTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(15) +} + +// SetUerDestinationTokenAccountAccount sets the "uerDestinationTokenAccount" account. +func (inst *SwapBaseIn) SetUerDestinationTokenAccountAccount(uerDestinationTokenAccount ag_solanago.PublicKey) *SwapBaseIn { + inst.AccountMetaSlice[16] = ag_solanago.Meta(uerDestinationTokenAccount).WRITE() + return inst +} + +// GetUerDestinationTokenAccountAccount gets the "uerDestinationTokenAccount" account. +func (inst *SwapBaseIn) GetUerDestinationTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(16) +} + +// SetUserSourceOwnerAccount sets the "userSourceOwner" account. +func (inst *SwapBaseIn) SetUserSourceOwnerAccount(userSourceOwner ag_solanago.PublicKey) *SwapBaseIn { + inst.AccountMetaSlice[17] = ag_solanago.Meta(userSourceOwner).SIGNER() + return inst +} + +// GetUserSourceOwnerAccount gets the "userSourceOwner" account. +func (inst *SwapBaseIn) GetUserSourceOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(17) +} + +func (inst SwapBaseIn) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: ag_binary.TypeIDFromUint8(Instruction_SwapBaseIn), + }} +} + +// 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 SwapBaseIn) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *SwapBaseIn) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.AmountIn == nil { + return errors.New("AmountIn parameter is not set") + } + if inst.MinimumAmountOut == nil { + return errors.New("MinimumAmountOut parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Amm is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.AmmAuthority is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.AmmOpenOrders is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.AmmTargetOrders is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.PoolCoinTokenAccount is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.PoolPcTokenAccount is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.SerumProgram is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.SerumMarket is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.SerumBids is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.SerumAsks is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.SerumEventQueue is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.SerumCoinVaultAccount is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.SerumPcVaultAccount is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.SerumVaultSigner is not set") + } + if inst.AccountMetaSlice[15] == nil { + return errors.New("accounts.UerSourceTokenAccount is not set") + } + if inst.AccountMetaSlice[16] == nil { + return errors.New("accounts.UerDestinationTokenAccount is not set") + } + if inst.AccountMetaSlice[17] == nil { + return errors.New("accounts.UserSourceOwner is not set") + } + } + return nil +} + +func (inst *SwapBaseIn) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("SwapBaseIn")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=2]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" AmountIn", *inst.AmountIn)) + paramsBranch.Child(ag_format.Param("MinimumAmountOut", *inst.MinimumAmountOut)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=18]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" amm", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" ammAuthority", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" ammOpenOrders", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" ammTargetOrders", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" poolCoinToken", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" poolPcToken", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" serumProgram", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" serumMarket", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" serumBids", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" serumAsks", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" serumEventQueue", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" serumCoinVault", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" serumPcVault", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta(" serumVaultSigner", inst.AccountMetaSlice.Get(14))) + accountsBranch.Child(ag_format.Meta(" uerSourceToken", inst.AccountMetaSlice.Get(15))) + accountsBranch.Child(ag_format.Meta("uerDestinationToken", inst.AccountMetaSlice.Get(16))) + accountsBranch.Child(ag_format.Meta(" userSourceOwner", inst.AccountMetaSlice.Get(17))) + }) + }) + }) +} + +func (obj SwapBaseIn) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `AmountIn` param: + err = encoder.Encode(obj.AmountIn) + if err != nil { + return err + } + // Serialize `MinimumAmountOut` param: + err = encoder.Encode(obj.MinimumAmountOut) + if err != nil { + return err + } + return nil +} +func (obj *SwapBaseIn) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `AmountIn`: + err = decoder.Decode(&obj.AmountIn) + if err != nil { + return err + } + // Deserialize `MinimumAmountOut`: + err = decoder.Decode(&obj.MinimumAmountOut) + if err != nil { + return err + } + return nil +} + +// NewSwapBaseInInstruction declares a new SwapBaseIn instruction with the provided parameters and accounts. +func NewSwapBaseInInstruction( + // Parameters: + amountIn uint64, + minimumAmountOut uint64, + // Accounts: + tokenProgram ag_solanago.PublicKey, + amm ag_solanago.PublicKey, + ammAuthority ag_solanago.PublicKey, + ammOpenOrders ag_solanago.PublicKey, + ammTargetOrders ag_solanago.PublicKey, + poolCoinTokenAccount ag_solanago.PublicKey, + poolPcTokenAccount ag_solanago.PublicKey, + serumProgram ag_solanago.PublicKey, + serumMarket ag_solanago.PublicKey, + serumBids ag_solanago.PublicKey, + serumAsks ag_solanago.PublicKey, + serumEventQueue ag_solanago.PublicKey, + serumCoinVaultAccount ag_solanago.PublicKey, + serumPcVaultAccount ag_solanago.PublicKey, + serumVaultSigner ag_solanago.PublicKey, + uerSourceTokenAccount ag_solanago.PublicKey, + uerDestinationTokenAccount ag_solanago.PublicKey, + userSourceOwner ag_solanago.PublicKey) *SwapBaseIn { + return NewSwapBaseInInstructionBuilder(). + SetAmountIn(amountIn). + SetMinimumAmountOut(minimumAmountOut). + SetTokenProgramAccount(tokenProgram). + SetAmmAccount(amm). + SetAmmAuthorityAccount(ammAuthority). + SetAmmOpenOrdersAccount(ammOpenOrders). + SetAmmTargetOrdersAccount(ammTargetOrders). + SetPoolCoinTokenAccountAccount(poolCoinTokenAccount). + SetPoolPcTokenAccountAccount(poolPcTokenAccount). + SetSerumProgramAccount(serumProgram). + SetSerumMarketAccount(serumMarket). + SetSerumBidsAccount(serumBids). + SetSerumAsksAccount(serumAsks). + SetSerumEventQueueAccount(serumEventQueue). + SetSerumCoinVaultAccountAccount(serumCoinVaultAccount). + SetSerumPcVaultAccountAccount(serumPcVaultAccount). + SetSerumVaultSignerAccount(serumVaultSigner). + SetUerSourceTokenAccountAccount(uerSourceTokenAccount). + SetUerDestinationTokenAccountAccount(uerDestinationTokenAccount). + SetUserSourceOwnerAccount(userSourceOwner) +} diff --git a/programs/raydiumamm/SwapBaseIn_test.go b/programs/raydiumamm/SwapBaseIn_test.go new file mode 100644 index 00000000..ab218a93 --- /dev/null +++ b/programs/raydiumamm/SwapBaseIn_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package raydium_amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_SwapBaseIn(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("SwapBaseIn"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(SwapBaseIn) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(SwapBaseIn) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/raydiumamm/SwapBaseOut.go b/programs/raydiumamm/SwapBaseOut.go new file mode 100644 index 00000000..4f0d8329 --- /dev/null +++ b/programs/raydiumamm/SwapBaseOut.go @@ -0,0 +1,473 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package raydium_amm + +import ( + "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" +) + +// SwapBaseOut is the `swapBaseOut` instruction. +type SwapBaseOut struct { + MaxAmountIn *uint64 + AmountOut *uint64 + + // [0] = [] tokenProgram + // + // [1] = [WRITE] amm + // + // [2] = [] ammAuthority + // + // [3] = [WRITE] ammOpenOrders + // + // [4] = [WRITE] ammTargetOrders + // + // [5] = [WRITE] poolCoinTokenAccount + // + // [6] = [WRITE] poolPcTokenAccount + // + // [7] = [] serumProgram + // + // [8] = [WRITE] serumMarket + // + // [9] = [WRITE] serumBids + // + // [10] = [WRITE] serumAsks + // + // [11] = [WRITE] serumEventQueue + // + // [12] = [WRITE] serumCoinVaultAccount + // + // [13] = [WRITE] serumPcVaultAccount + // + // [14] = [] serumVaultSigner + // + // [15] = [WRITE] uerSourceTokenAccount + // + // [16] = [WRITE] uerDestinationTokenAccount + // + // [17] = [SIGNER] userSourceOwner + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewSwapBaseOutInstructionBuilder creates a new `SwapBaseOut` instruction builder. +func NewSwapBaseOutInstructionBuilder() *SwapBaseOut { + nd := &SwapBaseOut{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 18), + } + return nd +} + +// SetMaxAmountIn sets the "maxAmountIn" parameter. +func (inst *SwapBaseOut) SetMaxAmountIn(maxAmountIn uint64) *SwapBaseOut { + inst.MaxAmountIn = &maxAmountIn + return inst +} + +// SetAmountOut sets the "amountOut" parameter. +func (inst *SwapBaseOut) SetAmountOut(amountOut uint64) *SwapBaseOut { + inst.AmountOut = &amountOut + return inst +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *SwapBaseOut) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *SwapBaseOut { + inst.AccountMetaSlice[0] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *SwapBaseOut) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetAmmAccount sets the "amm" account. +func (inst *SwapBaseOut) SetAmmAccount(amm ag_solanago.PublicKey) *SwapBaseOut { + inst.AccountMetaSlice[1] = ag_solanago.Meta(amm).WRITE() + return inst +} + +// GetAmmAccount gets the "amm" account. +func (inst *SwapBaseOut) GetAmmAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetAmmAuthorityAccount sets the "ammAuthority" account. +func (inst *SwapBaseOut) SetAmmAuthorityAccount(ammAuthority ag_solanago.PublicKey) *SwapBaseOut { + inst.AccountMetaSlice[2] = ag_solanago.Meta(ammAuthority) + return inst +} + +// GetAmmAuthorityAccount gets the "ammAuthority" account. +func (inst *SwapBaseOut) GetAmmAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetAmmOpenOrdersAccount sets the "ammOpenOrders" account. +func (inst *SwapBaseOut) SetAmmOpenOrdersAccount(ammOpenOrders ag_solanago.PublicKey) *SwapBaseOut { + inst.AccountMetaSlice[3] = ag_solanago.Meta(ammOpenOrders).WRITE() + return inst +} + +// GetAmmOpenOrdersAccount gets the "ammOpenOrders" account. +func (inst *SwapBaseOut) GetAmmOpenOrdersAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetAmmTargetOrdersAccount sets the "ammTargetOrders" account. +func (inst *SwapBaseOut) SetAmmTargetOrdersAccount(ammTargetOrders ag_solanago.PublicKey) *SwapBaseOut { + inst.AccountMetaSlice[4] = ag_solanago.Meta(ammTargetOrders).WRITE() + return inst +} + +// GetAmmTargetOrdersAccount gets the "ammTargetOrders" account. +func (inst *SwapBaseOut) GetAmmTargetOrdersAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetPoolCoinTokenAccountAccount sets the "poolCoinTokenAccount" account. +func (inst *SwapBaseOut) SetPoolCoinTokenAccountAccount(poolCoinTokenAccount ag_solanago.PublicKey) *SwapBaseOut { + inst.AccountMetaSlice[5] = ag_solanago.Meta(poolCoinTokenAccount).WRITE() + return inst +} + +// GetPoolCoinTokenAccountAccount gets the "poolCoinTokenAccount" account. +func (inst *SwapBaseOut) GetPoolCoinTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetPoolPcTokenAccountAccount sets the "poolPcTokenAccount" account. +func (inst *SwapBaseOut) SetPoolPcTokenAccountAccount(poolPcTokenAccount ag_solanago.PublicKey) *SwapBaseOut { + inst.AccountMetaSlice[6] = ag_solanago.Meta(poolPcTokenAccount).WRITE() + return inst +} + +// GetPoolPcTokenAccountAccount gets the "poolPcTokenAccount" account. +func (inst *SwapBaseOut) GetPoolPcTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetSerumProgramAccount sets the "serumProgram" account. +func (inst *SwapBaseOut) SetSerumProgramAccount(serumProgram ag_solanago.PublicKey) *SwapBaseOut { + inst.AccountMetaSlice[7] = ag_solanago.Meta(serumProgram) + return inst +} + +// GetSerumProgramAccount gets the "serumProgram" account. +func (inst *SwapBaseOut) GetSerumProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetSerumMarketAccount sets the "serumMarket" account. +func (inst *SwapBaseOut) SetSerumMarketAccount(serumMarket ag_solanago.PublicKey) *SwapBaseOut { + inst.AccountMetaSlice[8] = ag_solanago.Meta(serumMarket).WRITE() + return inst +} + +// GetSerumMarketAccount gets the "serumMarket" account. +func (inst *SwapBaseOut) GetSerumMarketAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetSerumBidsAccount sets the "serumBids" account. +func (inst *SwapBaseOut) SetSerumBidsAccount(serumBids ag_solanago.PublicKey) *SwapBaseOut { + inst.AccountMetaSlice[9] = ag_solanago.Meta(serumBids).WRITE() + return inst +} + +// GetSerumBidsAccount gets the "serumBids" account. +func (inst *SwapBaseOut) GetSerumBidsAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetSerumAsksAccount sets the "serumAsks" account. +func (inst *SwapBaseOut) SetSerumAsksAccount(serumAsks ag_solanago.PublicKey) *SwapBaseOut { + inst.AccountMetaSlice[10] = ag_solanago.Meta(serumAsks).WRITE() + return inst +} + +// GetSerumAsksAccount gets the "serumAsks" account. +func (inst *SwapBaseOut) GetSerumAsksAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetSerumEventQueueAccount sets the "serumEventQueue" account. +func (inst *SwapBaseOut) SetSerumEventQueueAccount(serumEventQueue ag_solanago.PublicKey) *SwapBaseOut { + inst.AccountMetaSlice[11] = ag_solanago.Meta(serumEventQueue).WRITE() + return inst +} + +// GetSerumEventQueueAccount gets the "serumEventQueue" account. +func (inst *SwapBaseOut) GetSerumEventQueueAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetSerumCoinVaultAccountAccount sets the "serumCoinVaultAccount" account. +func (inst *SwapBaseOut) SetSerumCoinVaultAccountAccount(serumCoinVaultAccount ag_solanago.PublicKey) *SwapBaseOut { + inst.AccountMetaSlice[12] = ag_solanago.Meta(serumCoinVaultAccount).WRITE() + return inst +} + +// GetSerumCoinVaultAccountAccount gets the "serumCoinVaultAccount" account. +func (inst *SwapBaseOut) GetSerumCoinVaultAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetSerumPcVaultAccountAccount sets the "serumPcVaultAccount" account. +func (inst *SwapBaseOut) SetSerumPcVaultAccountAccount(serumPcVaultAccount ag_solanago.PublicKey) *SwapBaseOut { + inst.AccountMetaSlice[13] = ag_solanago.Meta(serumPcVaultAccount).WRITE() + return inst +} + +// GetSerumPcVaultAccountAccount gets the "serumPcVaultAccount" account. +func (inst *SwapBaseOut) GetSerumPcVaultAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetSerumVaultSignerAccount sets the "serumVaultSigner" account. +func (inst *SwapBaseOut) SetSerumVaultSignerAccount(serumVaultSigner ag_solanago.PublicKey) *SwapBaseOut { + inst.AccountMetaSlice[14] = ag_solanago.Meta(serumVaultSigner) + return inst +} + +// GetSerumVaultSignerAccount gets the "serumVaultSigner" account. +func (inst *SwapBaseOut) GetSerumVaultSignerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +// SetUerSourceTokenAccountAccount sets the "uerSourceTokenAccount" account. +func (inst *SwapBaseOut) SetUerSourceTokenAccountAccount(uerSourceTokenAccount ag_solanago.PublicKey) *SwapBaseOut { + inst.AccountMetaSlice[15] = ag_solanago.Meta(uerSourceTokenAccount).WRITE() + return inst +} + +// GetUerSourceTokenAccountAccount gets the "uerSourceTokenAccount" account. +func (inst *SwapBaseOut) GetUerSourceTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(15) +} + +// SetUerDestinationTokenAccountAccount sets the "uerDestinationTokenAccount" account. +func (inst *SwapBaseOut) SetUerDestinationTokenAccountAccount(uerDestinationTokenAccount ag_solanago.PublicKey) *SwapBaseOut { + inst.AccountMetaSlice[16] = ag_solanago.Meta(uerDestinationTokenAccount).WRITE() + return inst +} + +// GetUerDestinationTokenAccountAccount gets the "uerDestinationTokenAccount" account. +func (inst *SwapBaseOut) GetUerDestinationTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(16) +} + +// SetUserSourceOwnerAccount sets the "userSourceOwner" account. +func (inst *SwapBaseOut) SetUserSourceOwnerAccount(userSourceOwner ag_solanago.PublicKey) *SwapBaseOut { + inst.AccountMetaSlice[17] = ag_solanago.Meta(userSourceOwner).SIGNER() + return inst +} + +// GetUserSourceOwnerAccount gets the "userSourceOwner" account. +func (inst *SwapBaseOut) GetUserSourceOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(17) +} + +func (inst SwapBaseOut) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: ag_binary.TypeIDFromUint8(Instruction_SwapBaseOut), + }} +} + +// 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 SwapBaseOut) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *SwapBaseOut) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.MaxAmountIn == nil { + return errors.New("MaxAmountIn parameter is not set") + } + if inst.AmountOut == nil { + return errors.New("AmountOut parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Amm is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.AmmAuthority is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.AmmOpenOrders is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.AmmTargetOrders is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.PoolCoinTokenAccount is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.PoolPcTokenAccount is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.SerumProgram is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.SerumMarket is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.SerumBids is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.SerumAsks is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.SerumEventQueue is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.SerumCoinVaultAccount is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.SerumPcVaultAccount is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.SerumVaultSigner is not set") + } + if inst.AccountMetaSlice[15] == nil { + return errors.New("accounts.UerSourceTokenAccount is not set") + } + if inst.AccountMetaSlice[16] == nil { + return errors.New("accounts.UerDestinationTokenAccount is not set") + } + if inst.AccountMetaSlice[17] == nil { + return errors.New("accounts.UserSourceOwner is not set") + } + } + return nil +} + +func (inst *SwapBaseOut) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("SwapBaseOut")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=2]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param("MaxAmountIn", *inst.MaxAmountIn)) + paramsBranch.Child(ag_format.Param(" AmountOut", *inst.AmountOut)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=18]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" amm", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" ammAuthority", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" ammOpenOrders", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" ammTargetOrders", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" poolCoinToken", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" poolPcToken", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" serumProgram", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" serumMarket", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" serumBids", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" serumAsks", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" serumEventQueue", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" serumCoinVault", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" serumPcVault", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta(" serumVaultSigner", inst.AccountMetaSlice.Get(14))) + accountsBranch.Child(ag_format.Meta(" uerSourceToken", inst.AccountMetaSlice.Get(15))) + accountsBranch.Child(ag_format.Meta("uerDestinationToken", inst.AccountMetaSlice.Get(16))) + accountsBranch.Child(ag_format.Meta(" userSourceOwner", inst.AccountMetaSlice.Get(17))) + }) + }) + }) +} + +func (obj SwapBaseOut) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `MaxAmountIn` param: + err = encoder.Encode(obj.MaxAmountIn) + if err != nil { + return err + } + // Serialize `AmountOut` param: + err = encoder.Encode(obj.AmountOut) + if err != nil { + return err + } + return nil +} +func (obj *SwapBaseOut) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `MaxAmountIn`: + err = decoder.Decode(&obj.MaxAmountIn) + if err != nil { + return err + } + // Deserialize `AmountOut`: + err = decoder.Decode(&obj.AmountOut) + if err != nil { + return err + } + return nil +} + +// NewSwapBaseOutInstruction declares a new SwapBaseOut instruction with the provided parameters and accounts. +func NewSwapBaseOutInstruction( + // Parameters: + maxAmountIn uint64, + amountOut uint64, + // Accounts: + tokenProgram ag_solanago.PublicKey, + amm ag_solanago.PublicKey, + ammAuthority ag_solanago.PublicKey, + ammOpenOrders ag_solanago.PublicKey, + ammTargetOrders ag_solanago.PublicKey, + poolCoinTokenAccount ag_solanago.PublicKey, + poolPcTokenAccount ag_solanago.PublicKey, + serumProgram ag_solanago.PublicKey, + serumMarket ag_solanago.PublicKey, + serumBids ag_solanago.PublicKey, + serumAsks ag_solanago.PublicKey, + serumEventQueue ag_solanago.PublicKey, + serumCoinVaultAccount ag_solanago.PublicKey, + serumPcVaultAccount ag_solanago.PublicKey, + serumVaultSigner ag_solanago.PublicKey, + uerSourceTokenAccount ag_solanago.PublicKey, + uerDestinationTokenAccount ag_solanago.PublicKey, + userSourceOwner ag_solanago.PublicKey) *SwapBaseOut { + return NewSwapBaseOutInstructionBuilder(). + SetMaxAmountIn(maxAmountIn). + SetAmountOut(amountOut). + SetTokenProgramAccount(tokenProgram). + SetAmmAccount(amm). + SetAmmAuthorityAccount(ammAuthority). + SetAmmOpenOrdersAccount(ammOpenOrders). + SetAmmTargetOrdersAccount(ammTargetOrders). + SetPoolCoinTokenAccountAccount(poolCoinTokenAccount). + SetPoolPcTokenAccountAccount(poolPcTokenAccount). + SetSerumProgramAccount(serumProgram). + SetSerumMarketAccount(serumMarket). + SetSerumBidsAccount(serumBids). + SetSerumAsksAccount(serumAsks). + SetSerumEventQueueAccount(serumEventQueue). + SetSerumCoinVaultAccountAccount(serumCoinVaultAccount). + SetSerumPcVaultAccountAccount(serumPcVaultAccount). + SetSerumVaultSignerAccount(serumVaultSigner). + SetUerSourceTokenAccountAccount(uerSourceTokenAccount). + SetUerDestinationTokenAccountAccount(uerDestinationTokenAccount). + SetUserSourceOwnerAccount(userSourceOwner) +} diff --git a/programs/raydiumamm/SwapBaseOut_test.go b/programs/raydiumamm/SwapBaseOut_test.go new file mode 100644 index 00000000..3504a298 --- /dev/null +++ b/programs/raydiumamm/SwapBaseOut_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package raydium_amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_SwapBaseOut(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("SwapBaseOut"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(SwapBaseOut) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(SwapBaseOut) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/raydiumamm/UpdateConfigAccount.go b/programs/raydiumamm/UpdateConfigAccount.go new file mode 100644 index 00000000..a5a02f64 --- /dev/null +++ b/programs/raydiumamm/UpdateConfigAccount.go @@ -0,0 +1,169 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package raydium_amm + +import ( + "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" +) + +// UpdateConfigAccount is the `updateConfigAccount` instruction. +type UpdateConfigAccount struct { + Param *uint8 + Owner *ag_solanago.PublicKey + + // [0] = [SIGNER] admin + // + // [1] = [WRITE] ammConfig + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewUpdateConfigAccountInstructionBuilder creates a new `UpdateConfigAccount` instruction builder. +func NewUpdateConfigAccountInstructionBuilder() *UpdateConfigAccount { + nd := &UpdateConfigAccount{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 2), + } + return nd +} + +// SetParam sets the "param" parameter. +func (inst *UpdateConfigAccount) SetParam(param uint8) *UpdateConfigAccount { + inst.Param = ¶m + return inst +} + +// SetOwner sets the "owner" parameter. +func (inst *UpdateConfigAccount) SetOwner(owner ag_solanago.PublicKey) *UpdateConfigAccount { + inst.Owner = &owner + return inst +} + +// SetAdminAccount sets the "admin" account. +func (inst *UpdateConfigAccount) SetAdminAccount(admin ag_solanago.PublicKey) *UpdateConfigAccount { + inst.AccountMetaSlice[0] = ag_solanago.Meta(admin).SIGNER() + return inst +} + +// GetAdminAccount gets the "admin" account. +func (inst *UpdateConfigAccount) GetAdminAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetAmmConfigAccount sets the "ammConfig" account. +func (inst *UpdateConfigAccount) SetAmmConfigAccount(ammConfig ag_solanago.PublicKey) *UpdateConfigAccount { + inst.AccountMetaSlice[1] = ag_solanago.Meta(ammConfig).WRITE() + return inst +} + +// GetAmmConfigAccount gets the "ammConfig" account. +func (inst *UpdateConfigAccount) GetAmmConfigAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +func (inst UpdateConfigAccount) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: ag_binary.TypeIDFromUint8(Instruction_UpdateConfigAccount), + }} +} + +// 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 UpdateConfigAccount) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *UpdateConfigAccount) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.Param == nil { + return errors.New("Param parameter is not set") + } + if inst.Owner == nil { + return errors.New("Owner parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Admin is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.AmmConfig is not set") + } + } + return nil +} + +func (inst *UpdateConfigAccount) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("UpdateConfigAccount")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=2]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param("Param", *inst.Param)) + paramsBranch.Child(ag_format.Param("Owner", *inst.Owner)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=2]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" admin", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta("ammConfig", inst.AccountMetaSlice.Get(1))) + }) + }) + }) +} + +func (obj UpdateConfigAccount) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Param` param: + err = encoder.Encode(obj.Param) + if err != nil { + return err + } + // Serialize `Owner` param: + err = encoder.Encode(obj.Owner) + if err != nil { + return err + } + return nil +} +func (obj *UpdateConfigAccount) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Param`: + err = decoder.Decode(&obj.Param) + if err != nil { + return err + } + // Deserialize `Owner`: + err = decoder.Decode(&obj.Owner) + if err != nil { + return err + } + return nil +} + +// NewUpdateConfigAccountInstruction declares a new UpdateConfigAccount instruction with the provided parameters and accounts. +func NewUpdateConfigAccountInstruction( + // Parameters: + param uint8, + owner ag_solanago.PublicKey, + // Accounts: + admin ag_solanago.PublicKey, + ammConfig ag_solanago.PublicKey) *UpdateConfigAccount { + return NewUpdateConfigAccountInstructionBuilder(). + SetParam(param). + SetOwner(owner). + SetAdminAccount(admin). + SetAmmConfigAccount(ammConfig) +} diff --git a/programs/raydiumamm/UpdateConfigAccount_test.go b/programs/raydiumamm/UpdateConfigAccount_test.go new file mode 100644 index 00000000..60678d45 --- /dev/null +++ b/programs/raydiumamm/UpdateConfigAccount_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package raydium_amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_UpdateConfigAccount(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("UpdateConfigAccount"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(UpdateConfigAccount) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(UpdateConfigAccount) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/raydiumamm/Withdraw.go b/programs/raydiumamm/Withdraw.go new file mode 100644 index 00000000..6213d72a --- /dev/null +++ b/programs/raydiumamm/Withdraw.go @@ -0,0 +1,526 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package raydium_amm + +import ( + "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" +) + +// Withdraw is the `withdraw` instruction. +type Withdraw struct { + Amount *uint64 + + // [0] = [] tokenProgram + // + // [1] = [WRITE] amm + // + // [2] = [] ammAuthority + // + // [3] = [WRITE] ammOpenOrders + // + // [4] = [WRITE] ammTargetOrders + // + // [5] = [WRITE] lpMintAddress + // + // [6] = [WRITE] poolCoinTokenAccount + // + // [7] = [WRITE] poolPcTokenAccount + // + // [8] = [WRITE] poolWithdrawQueue + // + // [9] = [WRITE] poolTempLpTokenAccount + // + // [10] = [] serumProgram + // + // [11] = [WRITE] serumMarket + // + // [12] = [WRITE] serumCoinVaultAccount + // + // [13] = [WRITE] serumPcVaultAccount + // + // [14] = [] serumVaultSigner + // + // [15] = [WRITE] userLpTokenAccount + // + // [16] = [WRITE] uerCoinTokenAccount + // + // [17] = [WRITE] uerPcTokenAccount + // + // [18] = [SIGNER] userOwner + // + // [19] = [WRITE] serumEventQ + // + // [20] = [WRITE] serumBids + // + // [21] = [WRITE] serumAsks + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewWithdrawInstructionBuilder creates a new `Withdraw` instruction builder. +func NewWithdrawInstructionBuilder() *Withdraw { + nd := &Withdraw{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 22), + } + return nd +} + +// SetAmount sets the "amount" parameter. +func (inst *Withdraw) SetAmount(amount uint64) *Withdraw { + inst.Amount = &amount + return inst +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *Withdraw) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *Withdraw { + inst.AccountMetaSlice[0] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *Withdraw) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetAmmAccount sets the "amm" account. +func (inst *Withdraw) SetAmmAccount(amm ag_solanago.PublicKey) *Withdraw { + inst.AccountMetaSlice[1] = ag_solanago.Meta(amm).WRITE() + return inst +} + +// GetAmmAccount gets the "amm" account. +func (inst *Withdraw) GetAmmAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetAmmAuthorityAccount sets the "ammAuthority" account. +func (inst *Withdraw) SetAmmAuthorityAccount(ammAuthority ag_solanago.PublicKey) *Withdraw { + inst.AccountMetaSlice[2] = ag_solanago.Meta(ammAuthority) + return inst +} + +// GetAmmAuthorityAccount gets the "ammAuthority" account. +func (inst *Withdraw) GetAmmAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetAmmOpenOrdersAccount sets the "ammOpenOrders" account. +func (inst *Withdraw) SetAmmOpenOrdersAccount(ammOpenOrders ag_solanago.PublicKey) *Withdraw { + inst.AccountMetaSlice[3] = ag_solanago.Meta(ammOpenOrders).WRITE() + return inst +} + +// GetAmmOpenOrdersAccount gets the "ammOpenOrders" account. +func (inst *Withdraw) GetAmmOpenOrdersAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetAmmTargetOrdersAccount sets the "ammTargetOrders" account. +func (inst *Withdraw) SetAmmTargetOrdersAccount(ammTargetOrders ag_solanago.PublicKey) *Withdraw { + inst.AccountMetaSlice[4] = ag_solanago.Meta(ammTargetOrders).WRITE() + return inst +} + +// GetAmmTargetOrdersAccount gets the "ammTargetOrders" account. +func (inst *Withdraw) GetAmmTargetOrdersAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetLpMintAddressAccount sets the "lpMintAddress" account. +func (inst *Withdraw) SetLpMintAddressAccount(lpMintAddress ag_solanago.PublicKey) *Withdraw { + inst.AccountMetaSlice[5] = ag_solanago.Meta(lpMintAddress).WRITE() + return inst +} + +// GetLpMintAddressAccount gets the "lpMintAddress" account. +func (inst *Withdraw) GetLpMintAddressAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetPoolCoinTokenAccountAccount sets the "poolCoinTokenAccount" account. +func (inst *Withdraw) SetPoolCoinTokenAccountAccount(poolCoinTokenAccount ag_solanago.PublicKey) *Withdraw { + inst.AccountMetaSlice[6] = ag_solanago.Meta(poolCoinTokenAccount).WRITE() + return inst +} + +// GetPoolCoinTokenAccountAccount gets the "poolCoinTokenAccount" account. +func (inst *Withdraw) GetPoolCoinTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetPoolPcTokenAccountAccount sets the "poolPcTokenAccount" account. +func (inst *Withdraw) SetPoolPcTokenAccountAccount(poolPcTokenAccount ag_solanago.PublicKey) *Withdraw { + inst.AccountMetaSlice[7] = ag_solanago.Meta(poolPcTokenAccount).WRITE() + return inst +} + +// GetPoolPcTokenAccountAccount gets the "poolPcTokenAccount" account. +func (inst *Withdraw) GetPoolPcTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetPoolWithdrawQueueAccount sets the "poolWithdrawQueue" account. +func (inst *Withdraw) SetPoolWithdrawQueueAccount(poolWithdrawQueue ag_solanago.PublicKey) *Withdraw { + inst.AccountMetaSlice[8] = ag_solanago.Meta(poolWithdrawQueue).WRITE() + return inst +} + +// GetPoolWithdrawQueueAccount gets the "poolWithdrawQueue" account. +func (inst *Withdraw) GetPoolWithdrawQueueAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetPoolTempLpTokenAccountAccount sets the "poolTempLpTokenAccount" account. +func (inst *Withdraw) SetPoolTempLpTokenAccountAccount(poolTempLpTokenAccount ag_solanago.PublicKey) *Withdraw { + inst.AccountMetaSlice[9] = ag_solanago.Meta(poolTempLpTokenAccount).WRITE() + return inst +} + +// GetPoolTempLpTokenAccountAccount gets the "poolTempLpTokenAccount" account. +func (inst *Withdraw) GetPoolTempLpTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetSerumProgramAccount sets the "serumProgram" account. +func (inst *Withdraw) SetSerumProgramAccount(serumProgram ag_solanago.PublicKey) *Withdraw { + inst.AccountMetaSlice[10] = ag_solanago.Meta(serumProgram) + return inst +} + +// GetSerumProgramAccount gets the "serumProgram" account. +func (inst *Withdraw) GetSerumProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetSerumMarketAccount sets the "serumMarket" account. +func (inst *Withdraw) SetSerumMarketAccount(serumMarket ag_solanago.PublicKey) *Withdraw { + inst.AccountMetaSlice[11] = ag_solanago.Meta(serumMarket).WRITE() + return inst +} + +// GetSerumMarketAccount gets the "serumMarket" account. +func (inst *Withdraw) GetSerumMarketAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetSerumCoinVaultAccountAccount sets the "serumCoinVaultAccount" account. +func (inst *Withdraw) SetSerumCoinVaultAccountAccount(serumCoinVaultAccount ag_solanago.PublicKey) *Withdraw { + inst.AccountMetaSlice[12] = ag_solanago.Meta(serumCoinVaultAccount).WRITE() + return inst +} + +// GetSerumCoinVaultAccountAccount gets the "serumCoinVaultAccount" account. +func (inst *Withdraw) GetSerumCoinVaultAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetSerumPcVaultAccountAccount sets the "serumPcVaultAccount" account. +func (inst *Withdraw) SetSerumPcVaultAccountAccount(serumPcVaultAccount ag_solanago.PublicKey) *Withdraw { + inst.AccountMetaSlice[13] = ag_solanago.Meta(serumPcVaultAccount).WRITE() + return inst +} + +// GetSerumPcVaultAccountAccount gets the "serumPcVaultAccount" account. +func (inst *Withdraw) GetSerumPcVaultAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetSerumVaultSignerAccount sets the "serumVaultSigner" account. +func (inst *Withdraw) SetSerumVaultSignerAccount(serumVaultSigner ag_solanago.PublicKey) *Withdraw { + inst.AccountMetaSlice[14] = ag_solanago.Meta(serumVaultSigner) + return inst +} + +// GetSerumVaultSignerAccount gets the "serumVaultSigner" account. +func (inst *Withdraw) GetSerumVaultSignerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +// SetUserLpTokenAccountAccount sets the "userLpTokenAccount" account. +func (inst *Withdraw) SetUserLpTokenAccountAccount(userLpTokenAccount ag_solanago.PublicKey) *Withdraw { + inst.AccountMetaSlice[15] = ag_solanago.Meta(userLpTokenAccount).WRITE() + return inst +} + +// GetUserLpTokenAccountAccount gets the "userLpTokenAccount" account. +func (inst *Withdraw) GetUserLpTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(15) +} + +// SetUerCoinTokenAccountAccount sets the "uerCoinTokenAccount" account. +func (inst *Withdraw) SetUerCoinTokenAccountAccount(uerCoinTokenAccount ag_solanago.PublicKey) *Withdraw { + inst.AccountMetaSlice[16] = ag_solanago.Meta(uerCoinTokenAccount).WRITE() + return inst +} + +// GetUerCoinTokenAccountAccount gets the "uerCoinTokenAccount" account. +func (inst *Withdraw) GetUerCoinTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(16) +} + +// SetUerPcTokenAccountAccount sets the "uerPcTokenAccount" account. +func (inst *Withdraw) SetUerPcTokenAccountAccount(uerPcTokenAccount ag_solanago.PublicKey) *Withdraw { + inst.AccountMetaSlice[17] = ag_solanago.Meta(uerPcTokenAccount).WRITE() + return inst +} + +// GetUerPcTokenAccountAccount gets the "uerPcTokenAccount" account. +func (inst *Withdraw) GetUerPcTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(17) +} + +// SetUserOwnerAccount sets the "userOwner" account. +func (inst *Withdraw) SetUserOwnerAccount(userOwner ag_solanago.PublicKey) *Withdraw { + inst.AccountMetaSlice[18] = ag_solanago.Meta(userOwner).SIGNER() + return inst +} + +// GetUserOwnerAccount gets the "userOwner" account. +func (inst *Withdraw) GetUserOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(18) +} + +// SetSerumEventQAccount sets the "serumEventQ" account. +func (inst *Withdraw) SetSerumEventQAccount(serumEventQ ag_solanago.PublicKey) *Withdraw { + inst.AccountMetaSlice[19] = ag_solanago.Meta(serumEventQ).WRITE() + return inst +} + +// GetSerumEventQAccount gets the "serumEventQ" account. +func (inst *Withdraw) GetSerumEventQAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(19) +} + +// SetSerumBidsAccount sets the "serumBids" account. +func (inst *Withdraw) SetSerumBidsAccount(serumBids ag_solanago.PublicKey) *Withdraw { + inst.AccountMetaSlice[20] = ag_solanago.Meta(serumBids).WRITE() + return inst +} + +// GetSerumBidsAccount gets the "serumBids" account. +func (inst *Withdraw) GetSerumBidsAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(20) +} + +// SetSerumAsksAccount sets the "serumAsks" account. +func (inst *Withdraw) SetSerumAsksAccount(serumAsks ag_solanago.PublicKey) *Withdraw { + inst.AccountMetaSlice[21] = ag_solanago.Meta(serumAsks).WRITE() + return inst +} + +// GetSerumAsksAccount gets the "serumAsks" account. +func (inst *Withdraw) GetSerumAsksAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(21) +} + +func (inst Withdraw) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: ag_binary.TypeIDFromUint8(Instruction_Withdraw), + }} +} + +// 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 Withdraw) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *Withdraw) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.Amount == nil { + return errors.New("Amount parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Amm is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.AmmAuthority is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.AmmOpenOrders is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.AmmTargetOrders is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.LpMintAddress is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.PoolCoinTokenAccount is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.PoolPcTokenAccount is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.PoolWithdrawQueue is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.PoolTempLpTokenAccount is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.SerumProgram is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.SerumMarket is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.SerumCoinVaultAccount is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.SerumPcVaultAccount is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.SerumVaultSigner is not set") + } + if inst.AccountMetaSlice[15] == nil { + return errors.New("accounts.UserLpTokenAccount is not set") + } + if inst.AccountMetaSlice[16] == nil { + return errors.New("accounts.UerCoinTokenAccount is not set") + } + if inst.AccountMetaSlice[17] == nil { + return errors.New("accounts.UerPcTokenAccount is not set") + } + if inst.AccountMetaSlice[18] == nil { + return errors.New("accounts.UserOwner is not set") + } + if inst.AccountMetaSlice[19] == nil { + return errors.New("accounts.SerumEventQ is not set") + } + if inst.AccountMetaSlice[20] == nil { + return errors.New("accounts.SerumBids is not set") + } + if inst.AccountMetaSlice[21] == nil { + return errors.New("accounts.SerumAsks is not set") + } + } + return nil +} + +func (inst *Withdraw) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("Withdraw")). + // + 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("Amount", *inst.Amount)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=22]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" amm", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" ammAuthority", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" ammOpenOrders", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" ammTargetOrders", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" lpMintAddress", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" poolCoinToken", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" poolPcToken", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta("poolWithdrawQueue", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" poolTempLpToken", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" serumProgram", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" serumMarket", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" serumCoinVault", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" serumPcVault", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta(" serumVaultSigner", inst.AccountMetaSlice.Get(14))) + accountsBranch.Child(ag_format.Meta(" userLpToken", inst.AccountMetaSlice.Get(15))) + accountsBranch.Child(ag_format.Meta(" uerCoinToken", inst.AccountMetaSlice.Get(16))) + accountsBranch.Child(ag_format.Meta(" uerPcToken", inst.AccountMetaSlice.Get(17))) + accountsBranch.Child(ag_format.Meta(" userOwner", inst.AccountMetaSlice.Get(18))) + accountsBranch.Child(ag_format.Meta(" serumEventQ", inst.AccountMetaSlice.Get(19))) + accountsBranch.Child(ag_format.Meta(" serumBids", inst.AccountMetaSlice.Get(20))) + accountsBranch.Child(ag_format.Meta(" serumAsks", inst.AccountMetaSlice.Get(21))) + }) + }) + }) +} + +func (obj Withdraw) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Amount` param: + err = encoder.Encode(obj.Amount) + if err != nil { + return err + } + return nil +} +func (obj *Withdraw) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Amount`: + err = decoder.Decode(&obj.Amount) + if err != nil { + return err + } + return nil +} + +// NewWithdrawInstruction declares a new Withdraw instruction with the provided parameters and accounts. +func NewWithdrawInstruction( + // Parameters: + amount uint64, + // Accounts: + tokenProgram ag_solanago.PublicKey, + amm ag_solanago.PublicKey, + ammAuthority ag_solanago.PublicKey, + ammOpenOrders ag_solanago.PublicKey, + ammTargetOrders ag_solanago.PublicKey, + lpMintAddress ag_solanago.PublicKey, + poolCoinTokenAccount ag_solanago.PublicKey, + poolPcTokenAccount ag_solanago.PublicKey, + poolWithdrawQueue ag_solanago.PublicKey, + poolTempLpTokenAccount ag_solanago.PublicKey, + serumProgram ag_solanago.PublicKey, + serumMarket ag_solanago.PublicKey, + serumCoinVaultAccount ag_solanago.PublicKey, + serumPcVaultAccount ag_solanago.PublicKey, + serumVaultSigner ag_solanago.PublicKey, + userLpTokenAccount ag_solanago.PublicKey, + uerCoinTokenAccount ag_solanago.PublicKey, + uerPcTokenAccount ag_solanago.PublicKey, + userOwner ag_solanago.PublicKey, + serumEventQ ag_solanago.PublicKey, + serumBids ag_solanago.PublicKey, + serumAsks ag_solanago.PublicKey) *Withdraw { + return NewWithdrawInstructionBuilder(). + SetAmount(amount). + SetTokenProgramAccount(tokenProgram). + SetAmmAccount(amm). + SetAmmAuthorityAccount(ammAuthority). + SetAmmOpenOrdersAccount(ammOpenOrders). + SetAmmTargetOrdersAccount(ammTargetOrders). + SetLpMintAddressAccount(lpMintAddress). + SetPoolCoinTokenAccountAccount(poolCoinTokenAccount). + SetPoolPcTokenAccountAccount(poolPcTokenAccount). + SetPoolWithdrawQueueAccount(poolWithdrawQueue). + SetPoolTempLpTokenAccountAccount(poolTempLpTokenAccount). + SetSerumProgramAccount(serumProgram). + SetSerumMarketAccount(serumMarket). + SetSerumCoinVaultAccountAccount(serumCoinVaultAccount). + SetSerumPcVaultAccountAccount(serumPcVaultAccount). + SetSerumVaultSignerAccount(serumVaultSigner). + SetUserLpTokenAccountAccount(userLpTokenAccount). + SetUerCoinTokenAccountAccount(uerCoinTokenAccount). + SetUerPcTokenAccountAccount(uerPcTokenAccount). + SetUserOwnerAccount(userOwner). + SetSerumEventQAccount(serumEventQ). + SetSerumBidsAccount(serumBids). + SetSerumAsksAccount(serumAsks) +} diff --git a/programs/raydiumamm/WithdrawPnl.go b/programs/raydiumamm/WithdrawPnl.go new file mode 100644 index 00000000..2a4399d6 --- /dev/null +++ b/programs/raydiumamm/WithdrawPnl.go @@ -0,0 +1,402 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package raydium_amm + +import ( + "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" +) + +// WithdrawPnl is the `withdrawPnl` instruction. +type WithdrawPnl struct { + + // [0] = [] tokenProgram + // + // [1] = [WRITE] amm + // + // [2] = [] ammConfig + // + // [3] = [] ammAuthority + // + // [4] = [WRITE] ammOpenOrders + // + // [5] = [WRITE] poolCoinTokenAccount + // + // [6] = [WRITE] poolPcTokenAccount + // + // [7] = [WRITE] coinPnlTokenAccount + // + // [8] = [WRITE] pcPnlTokenAccount + // + // [9] = [SIGNER] pnlOwnerAccount + // + // [10] = [WRITE] ammTargetOrders + // + // [11] = [] serumProgram + // + // [12] = [WRITE] serumMarket + // + // [13] = [] serumEventQueue + // + // [14] = [WRITE] serumCoinVaultAccount + // + // [15] = [WRITE] serumPcVaultAccount + // + // [16] = [] serumVaultSigner + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewWithdrawPnlInstructionBuilder creates a new `WithdrawPnl` instruction builder. +func NewWithdrawPnlInstructionBuilder() *WithdrawPnl { + nd := &WithdrawPnl{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 17), + } + return nd +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *WithdrawPnl) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *WithdrawPnl { + inst.AccountMetaSlice[0] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *WithdrawPnl) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetAmmAccount sets the "amm" account. +func (inst *WithdrawPnl) SetAmmAccount(amm ag_solanago.PublicKey) *WithdrawPnl { + inst.AccountMetaSlice[1] = ag_solanago.Meta(amm).WRITE() + return inst +} + +// GetAmmAccount gets the "amm" account. +func (inst *WithdrawPnl) GetAmmAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetAmmConfigAccount sets the "ammConfig" account. +func (inst *WithdrawPnl) SetAmmConfigAccount(ammConfig ag_solanago.PublicKey) *WithdrawPnl { + inst.AccountMetaSlice[2] = ag_solanago.Meta(ammConfig) + return inst +} + +// GetAmmConfigAccount gets the "ammConfig" account. +func (inst *WithdrawPnl) GetAmmConfigAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetAmmAuthorityAccount sets the "ammAuthority" account. +func (inst *WithdrawPnl) SetAmmAuthorityAccount(ammAuthority ag_solanago.PublicKey) *WithdrawPnl { + inst.AccountMetaSlice[3] = ag_solanago.Meta(ammAuthority) + return inst +} + +// GetAmmAuthorityAccount gets the "ammAuthority" account. +func (inst *WithdrawPnl) GetAmmAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetAmmOpenOrdersAccount sets the "ammOpenOrders" account. +func (inst *WithdrawPnl) SetAmmOpenOrdersAccount(ammOpenOrders ag_solanago.PublicKey) *WithdrawPnl { + inst.AccountMetaSlice[4] = ag_solanago.Meta(ammOpenOrders).WRITE() + return inst +} + +// GetAmmOpenOrdersAccount gets the "ammOpenOrders" account. +func (inst *WithdrawPnl) GetAmmOpenOrdersAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetPoolCoinTokenAccountAccount sets the "poolCoinTokenAccount" account. +func (inst *WithdrawPnl) SetPoolCoinTokenAccountAccount(poolCoinTokenAccount ag_solanago.PublicKey) *WithdrawPnl { + inst.AccountMetaSlice[5] = ag_solanago.Meta(poolCoinTokenAccount).WRITE() + return inst +} + +// GetPoolCoinTokenAccountAccount gets the "poolCoinTokenAccount" account. +func (inst *WithdrawPnl) GetPoolCoinTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetPoolPcTokenAccountAccount sets the "poolPcTokenAccount" account. +func (inst *WithdrawPnl) SetPoolPcTokenAccountAccount(poolPcTokenAccount ag_solanago.PublicKey) *WithdrawPnl { + inst.AccountMetaSlice[6] = ag_solanago.Meta(poolPcTokenAccount).WRITE() + return inst +} + +// GetPoolPcTokenAccountAccount gets the "poolPcTokenAccount" account. +func (inst *WithdrawPnl) GetPoolPcTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetCoinPnlTokenAccountAccount sets the "coinPnlTokenAccount" account. +func (inst *WithdrawPnl) SetCoinPnlTokenAccountAccount(coinPnlTokenAccount ag_solanago.PublicKey) *WithdrawPnl { + inst.AccountMetaSlice[7] = ag_solanago.Meta(coinPnlTokenAccount).WRITE() + return inst +} + +// GetCoinPnlTokenAccountAccount gets the "coinPnlTokenAccount" account. +func (inst *WithdrawPnl) GetCoinPnlTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetPcPnlTokenAccountAccount sets the "pcPnlTokenAccount" account. +func (inst *WithdrawPnl) SetPcPnlTokenAccountAccount(pcPnlTokenAccount ag_solanago.PublicKey) *WithdrawPnl { + inst.AccountMetaSlice[8] = ag_solanago.Meta(pcPnlTokenAccount).WRITE() + return inst +} + +// GetPcPnlTokenAccountAccount gets the "pcPnlTokenAccount" account. +func (inst *WithdrawPnl) GetPcPnlTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetPnlOwnerAccountAccount sets the "pnlOwnerAccount" account. +func (inst *WithdrawPnl) SetPnlOwnerAccountAccount(pnlOwnerAccount ag_solanago.PublicKey) *WithdrawPnl { + inst.AccountMetaSlice[9] = ag_solanago.Meta(pnlOwnerAccount).SIGNER() + return inst +} + +// GetPnlOwnerAccountAccount gets the "pnlOwnerAccount" account. +func (inst *WithdrawPnl) GetPnlOwnerAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetAmmTargetOrdersAccount sets the "ammTargetOrders" account. +func (inst *WithdrawPnl) SetAmmTargetOrdersAccount(ammTargetOrders ag_solanago.PublicKey) *WithdrawPnl { + inst.AccountMetaSlice[10] = ag_solanago.Meta(ammTargetOrders).WRITE() + return inst +} + +// GetAmmTargetOrdersAccount gets the "ammTargetOrders" account. +func (inst *WithdrawPnl) GetAmmTargetOrdersAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetSerumProgramAccount sets the "serumProgram" account. +func (inst *WithdrawPnl) SetSerumProgramAccount(serumProgram ag_solanago.PublicKey) *WithdrawPnl { + inst.AccountMetaSlice[11] = ag_solanago.Meta(serumProgram) + return inst +} + +// GetSerumProgramAccount gets the "serumProgram" account. +func (inst *WithdrawPnl) GetSerumProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetSerumMarketAccount sets the "serumMarket" account. +func (inst *WithdrawPnl) SetSerumMarketAccount(serumMarket ag_solanago.PublicKey) *WithdrawPnl { + inst.AccountMetaSlice[12] = ag_solanago.Meta(serumMarket).WRITE() + return inst +} + +// GetSerumMarketAccount gets the "serumMarket" account. +func (inst *WithdrawPnl) GetSerumMarketAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetSerumEventQueueAccount sets the "serumEventQueue" account. +func (inst *WithdrawPnl) SetSerumEventQueueAccount(serumEventQueue ag_solanago.PublicKey) *WithdrawPnl { + inst.AccountMetaSlice[13] = ag_solanago.Meta(serumEventQueue) + return inst +} + +// GetSerumEventQueueAccount gets the "serumEventQueue" account. +func (inst *WithdrawPnl) GetSerumEventQueueAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetSerumCoinVaultAccountAccount sets the "serumCoinVaultAccount" account. +func (inst *WithdrawPnl) SetSerumCoinVaultAccountAccount(serumCoinVaultAccount ag_solanago.PublicKey) *WithdrawPnl { + inst.AccountMetaSlice[14] = ag_solanago.Meta(serumCoinVaultAccount).WRITE() + return inst +} + +// GetSerumCoinVaultAccountAccount gets the "serumCoinVaultAccount" account. +func (inst *WithdrawPnl) GetSerumCoinVaultAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +// SetSerumPcVaultAccountAccount sets the "serumPcVaultAccount" account. +func (inst *WithdrawPnl) SetSerumPcVaultAccountAccount(serumPcVaultAccount ag_solanago.PublicKey) *WithdrawPnl { + inst.AccountMetaSlice[15] = ag_solanago.Meta(serumPcVaultAccount).WRITE() + return inst +} + +// GetSerumPcVaultAccountAccount gets the "serumPcVaultAccount" account. +func (inst *WithdrawPnl) GetSerumPcVaultAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(15) +} + +// SetSerumVaultSignerAccount sets the "serumVaultSigner" account. +func (inst *WithdrawPnl) SetSerumVaultSignerAccount(serumVaultSigner ag_solanago.PublicKey) *WithdrawPnl { + inst.AccountMetaSlice[16] = ag_solanago.Meta(serumVaultSigner) + return inst +} + +// GetSerumVaultSignerAccount gets the "serumVaultSigner" account. +func (inst *WithdrawPnl) GetSerumVaultSignerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(16) +} + +func (inst WithdrawPnl) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: ag_binary.TypeIDFromUint8(Instruction_WithdrawPnl), + }} +} + +// 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 WithdrawPnl) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *WithdrawPnl) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Amm is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.AmmConfig is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.AmmAuthority is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.AmmOpenOrders is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.PoolCoinTokenAccount is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.PoolPcTokenAccount is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.CoinPnlTokenAccount is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.PcPnlTokenAccount is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.PnlOwnerAccount is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.AmmTargetOrders is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.SerumProgram is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.SerumMarket is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.SerumEventQueue is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.SerumCoinVaultAccount is not set") + } + if inst.AccountMetaSlice[15] == nil { + return errors.New("accounts.SerumPcVaultAccount is not set") + } + if inst.AccountMetaSlice[16] == nil { + return errors.New("accounts.SerumVaultSigner is not set") + } + } + return nil +} + +func (inst *WithdrawPnl) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("WithdrawPnl")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=17]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" amm", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" ammConfig", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" ammAuthority", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" ammOpenOrders", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" poolCoinToken", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" poolPcToken", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" coinPnlToken", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" pcPnlToken", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" pnlOwner", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" ammTargetOrders", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" serumProgram", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" serumMarket", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" serumEventQueue", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta(" serumCoinVault", inst.AccountMetaSlice.Get(14))) + accountsBranch.Child(ag_format.Meta(" serumPcVault", inst.AccountMetaSlice.Get(15))) + accountsBranch.Child(ag_format.Meta("serumVaultSigner", inst.AccountMetaSlice.Get(16))) + }) + }) + }) +} + +func (obj WithdrawPnl) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *WithdrawPnl) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewWithdrawPnlInstruction declares a new WithdrawPnl instruction with the provided parameters and accounts. +func NewWithdrawPnlInstruction( + // Accounts: + tokenProgram ag_solanago.PublicKey, + amm ag_solanago.PublicKey, + ammConfig ag_solanago.PublicKey, + ammAuthority ag_solanago.PublicKey, + ammOpenOrders ag_solanago.PublicKey, + poolCoinTokenAccount ag_solanago.PublicKey, + poolPcTokenAccount ag_solanago.PublicKey, + coinPnlTokenAccount ag_solanago.PublicKey, + pcPnlTokenAccount ag_solanago.PublicKey, + pnlOwnerAccount ag_solanago.PublicKey, + ammTargetOrders ag_solanago.PublicKey, + serumProgram ag_solanago.PublicKey, + serumMarket ag_solanago.PublicKey, + serumEventQueue ag_solanago.PublicKey, + serumCoinVaultAccount ag_solanago.PublicKey, + serumPcVaultAccount ag_solanago.PublicKey, + serumVaultSigner ag_solanago.PublicKey) *WithdrawPnl { + return NewWithdrawPnlInstructionBuilder(). + SetTokenProgramAccount(tokenProgram). + SetAmmAccount(amm). + SetAmmConfigAccount(ammConfig). + SetAmmAuthorityAccount(ammAuthority). + SetAmmOpenOrdersAccount(ammOpenOrders). + SetPoolCoinTokenAccountAccount(poolCoinTokenAccount). + SetPoolPcTokenAccountAccount(poolPcTokenAccount). + SetCoinPnlTokenAccountAccount(coinPnlTokenAccount). + SetPcPnlTokenAccountAccount(pcPnlTokenAccount). + SetPnlOwnerAccountAccount(pnlOwnerAccount). + SetAmmTargetOrdersAccount(ammTargetOrders). + SetSerumProgramAccount(serumProgram). + SetSerumMarketAccount(serumMarket). + SetSerumEventQueueAccount(serumEventQueue). + SetSerumCoinVaultAccountAccount(serumCoinVaultAccount). + SetSerumPcVaultAccountAccount(serumPcVaultAccount). + SetSerumVaultSignerAccount(serumVaultSigner) +} diff --git a/programs/raydiumamm/WithdrawPnl_test.go b/programs/raydiumamm/WithdrawPnl_test.go new file mode 100644 index 00000000..34708a87 --- /dev/null +++ b/programs/raydiumamm/WithdrawPnl_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package raydium_amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_WithdrawPnl(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("WithdrawPnl"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(WithdrawPnl) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(WithdrawPnl) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/raydiumamm/WithdrawSrm.go b/programs/raydiumamm/WithdrawSrm.go new file mode 100644 index 00000000..c09ed52c --- /dev/null +++ b/programs/raydiumamm/WithdrawSrm.go @@ -0,0 +1,222 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package raydium_amm + +import ( + "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" +) + +// WithdrawSrm is the `withdrawSrm` instruction. +type WithdrawSrm struct { + Amount *uint64 + + // [0] = [] tokenProgram + // + // [1] = [] amm + // + // [2] = [SIGNER] ammOwnerAccount + // + // [3] = [] ammAuthority + // + // [4] = [WRITE] srmToken + // + // [5] = [WRITE] destSrmToken + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewWithdrawSrmInstructionBuilder creates a new `WithdrawSrm` instruction builder. +func NewWithdrawSrmInstructionBuilder() *WithdrawSrm { + nd := &WithdrawSrm{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 6), + } + return nd +} + +// SetAmount sets the "amount" parameter. +func (inst *WithdrawSrm) SetAmount(amount uint64) *WithdrawSrm { + inst.Amount = &amount + return inst +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *WithdrawSrm) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *WithdrawSrm { + inst.AccountMetaSlice[0] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *WithdrawSrm) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetAmmAccount sets the "amm" account. +func (inst *WithdrawSrm) SetAmmAccount(amm ag_solanago.PublicKey) *WithdrawSrm { + inst.AccountMetaSlice[1] = ag_solanago.Meta(amm) + return inst +} + +// GetAmmAccount gets the "amm" account. +func (inst *WithdrawSrm) GetAmmAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetAmmOwnerAccountAccount sets the "ammOwnerAccount" account. +func (inst *WithdrawSrm) SetAmmOwnerAccountAccount(ammOwnerAccount ag_solanago.PublicKey) *WithdrawSrm { + inst.AccountMetaSlice[2] = ag_solanago.Meta(ammOwnerAccount).SIGNER() + return inst +} + +// GetAmmOwnerAccountAccount gets the "ammOwnerAccount" account. +func (inst *WithdrawSrm) GetAmmOwnerAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetAmmAuthorityAccount sets the "ammAuthority" account. +func (inst *WithdrawSrm) SetAmmAuthorityAccount(ammAuthority ag_solanago.PublicKey) *WithdrawSrm { + inst.AccountMetaSlice[3] = ag_solanago.Meta(ammAuthority) + return inst +} + +// GetAmmAuthorityAccount gets the "ammAuthority" account. +func (inst *WithdrawSrm) GetAmmAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetSrmTokenAccount sets the "srmToken" account. +func (inst *WithdrawSrm) SetSrmTokenAccount(srmToken ag_solanago.PublicKey) *WithdrawSrm { + inst.AccountMetaSlice[4] = ag_solanago.Meta(srmToken).WRITE() + return inst +} + +// GetSrmTokenAccount gets the "srmToken" account. +func (inst *WithdrawSrm) GetSrmTokenAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetDestSrmTokenAccount sets the "destSrmToken" account. +func (inst *WithdrawSrm) SetDestSrmTokenAccount(destSrmToken ag_solanago.PublicKey) *WithdrawSrm { + inst.AccountMetaSlice[5] = ag_solanago.Meta(destSrmToken).WRITE() + return inst +} + +// GetDestSrmTokenAccount gets the "destSrmToken" account. +func (inst *WithdrawSrm) GetDestSrmTokenAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +func (inst WithdrawSrm) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: ag_binary.TypeIDFromUint8(Instruction_WithdrawSrm), + }} +} + +// 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 WithdrawSrm) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *WithdrawSrm) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.Amount == nil { + return errors.New("Amount parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Amm is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.AmmOwnerAccount is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.AmmAuthority is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.SrmToken is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.DestSrmToken is not set") + } + } + return nil +} + +func (inst *WithdrawSrm) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("WithdrawSrm")). + // + 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("Amount", *inst.Amount)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=6]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta("tokenProgram", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" amm", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" ammOwner", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta("ammAuthority", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" srmToken", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta("destSrmToken", inst.AccountMetaSlice.Get(5))) + }) + }) + }) +} + +func (obj WithdrawSrm) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Amount` param: + err = encoder.Encode(obj.Amount) + if err != nil { + return err + } + return nil +} +func (obj *WithdrawSrm) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Amount`: + err = decoder.Decode(&obj.Amount) + if err != nil { + return err + } + return nil +} + +// NewWithdrawSrmInstruction declares a new WithdrawSrm instruction with the provided parameters and accounts. +func NewWithdrawSrmInstruction( + // Parameters: + amount uint64, + // Accounts: + tokenProgram ag_solanago.PublicKey, + amm ag_solanago.PublicKey, + ammOwnerAccount ag_solanago.PublicKey, + ammAuthority ag_solanago.PublicKey, + srmToken ag_solanago.PublicKey, + destSrmToken ag_solanago.PublicKey) *WithdrawSrm { + return NewWithdrawSrmInstructionBuilder(). + SetAmount(amount). + SetTokenProgramAccount(tokenProgram). + SetAmmAccount(amm). + SetAmmOwnerAccountAccount(ammOwnerAccount). + SetAmmAuthorityAccount(ammAuthority). + SetSrmTokenAccount(srmToken). + SetDestSrmTokenAccount(destSrmToken) +} diff --git a/programs/raydiumamm/WithdrawSrm_test.go b/programs/raydiumamm/WithdrawSrm_test.go new file mode 100644 index 00000000..92ce7d23 --- /dev/null +++ b/programs/raydiumamm/WithdrawSrm_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package raydium_amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_WithdrawSrm(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("WithdrawSrm"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(WithdrawSrm) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(WithdrawSrm) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/raydiumamm/Withdraw_test.go b/programs/raydiumamm/Withdraw_test.go new file mode 100644 index 00000000..d3c5377a --- /dev/null +++ b/programs/raydiumamm/Withdraw_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package raydium_amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_Withdraw(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("Withdraw"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(Withdraw) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(Withdraw) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/raydiumamm/accounts.go b/programs/raydiumamm/accounts.go new file mode 100644 index 00000000..720c388a --- /dev/null +++ b/programs/raydiumamm/accounts.go @@ -0,0 +1,767 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package raydium_amm + +import ( + ag_binary "github.com/gagliardetto/binary" + ag_solanago "github.com/gagliardetto/solana-go" +) + +type TargetOrders struct { + Owner [4]uint64 + BuyOrders [50]TargetOrder + Padding1 [8]uint64 + TargetX ag_binary.Uint128 + TargetY ag_binary.Uint128 + PlanXBuy ag_binary.Uint128 + PlanYBuy ag_binary.Uint128 + PlanXSell ag_binary.Uint128 + PlanYSell ag_binary.Uint128 + PlacedX ag_binary.Uint128 + PlacedY ag_binary.Uint128 + CalcPnlX ag_binary.Uint128 + CalcPnlY ag_binary.Uint128 + SellOrders [50]TargetOrder + Padding2 [6]uint64 + ReplaceBuyClientId [10]uint64 + ReplaceSellClientId [10]uint64 + LastOrderNumerator uint64 + LastOrderDenominator uint64 + PlanOrdersCur uint64 + PlaceOrdersCur uint64 + ValidBuyOrderNum uint64 + ValidSellOrderNum uint64 + Padding3 [10]uint64 + FreeSlotBits ag_binary.Uint128 +} + +func (obj TargetOrders) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Owner` param: + err = encoder.Encode(obj.Owner) + if err != nil { + return err + } + // Serialize `BuyOrders` param: + err = encoder.Encode(obj.BuyOrders) + if err != nil { + return err + } + // Serialize `Padding1` param: + err = encoder.Encode(obj.Padding1) + if err != nil { + return err + } + // Serialize `TargetX` param: + err = encoder.Encode(obj.TargetX) + if err != nil { + return err + } + // Serialize `TargetY` param: + err = encoder.Encode(obj.TargetY) + if err != nil { + return err + } + // Serialize `PlanXBuy` param: + err = encoder.Encode(obj.PlanXBuy) + if err != nil { + return err + } + // Serialize `PlanYBuy` param: + err = encoder.Encode(obj.PlanYBuy) + if err != nil { + return err + } + // Serialize `PlanXSell` param: + err = encoder.Encode(obj.PlanXSell) + if err != nil { + return err + } + // Serialize `PlanYSell` param: + err = encoder.Encode(obj.PlanYSell) + if err != nil { + return err + } + // Serialize `PlacedX` param: + err = encoder.Encode(obj.PlacedX) + if err != nil { + return err + } + // Serialize `PlacedY` param: + err = encoder.Encode(obj.PlacedY) + if err != nil { + return err + } + // Serialize `CalcPnlX` param: + err = encoder.Encode(obj.CalcPnlX) + if err != nil { + return err + } + // Serialize `CalcPnlY` param: + err = encoder.Encode(obj.CalcPnlY) + if err != nil { + return err + } + // Serialize `SellOrders` param: + err = encoder.Encode(obj.SellOrders) + if err != nil { + return err + } + // Serialize `Padding2` param: + err = encoder.Encode(obj.Padding2) + if err != nil { + return err + } + // Serialize `ReplaceBuyClientId` param: + err = encoder.Encode(obj.ReplaceBuyClientId) + if err != nil { + return err + } + // Serialize `ReplaceSellClientId` param: + err = encoder.Encode(obj.ReplaceSellClientId) + if err != nil { + return err + } + // Serialize `LastOrderNumerator` param: + err = encoder.Encode(obj.LastOrderNumerator) + if err != nil { + return err + } + // Serialize `LastOrderDenominator` param: + err = encoder.Encode(obj.LastOrderDenominator) + if err != nil { + return err + } + // Serialize `PlanOrdersCur` param: + err = encoder.Encode(obj.PlanOrdersCur) + if err != nil { + return err + } + // Serialize `PlaceOrdersCur` param: + err = encoder.Encode(obj.PlaceOrdersCur) + if err != nil { + return err + } + // Serialize `ValidBuyOrderNum` param: + err = encoder.Encode(obj.ValidBuyOrderNum) + if err != nil { + return err + } + // Serialize `ValidSellOrderNum` param: + err = encoder.Encode(obj.ValidSellOrderNum) + if err != nil { + return err + } + // Serialize `Padding3` param: + err = encoder.Encode(obj.Padding3) + if err != nil { + return err + } + // Serialize `FreeSlotBits` param: + err = encoder.Encode(obj.FreeSlotBits) + if err != nil { + return err + } + return nil +} + +func (obj *TargetOrders) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Owner`: + err = decoder.Decode(&obj.Owner) + if err != nil { + return err + } + // Deserialize `BuyOrders`: + err = decoder.Decode(&obj.BuyOrders) + if err != nil { + return err + } + // Deserialize `Padding1`: + err = decoder.Decode(&obj.Padding1) + if err != nil { + return err + } + // Deserialize `TargetX`: + err = decoder.Decode(&obj.TargetX) + if err != nil { + return err + } + // Deserialize `TargetY`: + err = decoder.Decode(&obj.TargetY) + if err != nil { + return err + } + // Deserialize `PlanXBuy`: + err = decoder.Decode(&obj.PlanXBuy) + if err != nil { + return err + } + // Deserialize `PlanYBuy`: + err = decoder.Decode(&obj.PlanYBuy) + if err != nil { + return err + } + // Deserialize `PlanXSell`: + err = decoder.Decode(&obj.PlanXSell) + if err != nil { + return err + } + // Deserialize `PlanYSell`: + err = decoder.Decode(&obj.PlanYSell) + if err != nil { + return err + } + // Deserialize `PlacedX`: + err = decoder.Decode(&obj.PlacedX) + if err != nil { + return err + } + // Deserialize `PlacedY`: + err = decoder.Decode(&obj.PlacedY) + if err != nil { + return err + } + // Deserialize `CalcPnlX`: + err = decoder.Decode(&obj.CalcPnlX) + if err != nil { + return err + } + // Deserialize `CalcPnlY`: + err = decoder.Decode(&obj.CalcPnlY) + if err != nil { + return err + } + // Deserialize `SellOrders`: + err = decoder.Decode(&obj.SellOrders) + if err != nil { + return err + } + // Deserialize `Padding2`: + err = decoder.Decode(&obj.Padding2) + if err != nil { + return err + } + // Deserialize `ReplaceBuyClientId`: + err = decoder.Decode(&obj.ReplaceBuyClientId) + if err != nil { + return err + } + // Deserialize `ReplaceSellClientId`: + err = decoder.Decode(&obj.ReplaceSellClientId) + if err != nil { + return err + } + // Deserialize `LastOrderNumerator`: + err = decoder.Decode(&obj.LastOrderNumerator) + if err != nil { + return err + } + // Deserialize `LastOrderDenominator`: + err = decoder.Decode(&obj.LastOrderDenominator) + if err != nil { + return err + } + // Deserialize `PlanOrdersCur`: + err = decoder.Decode(&obj.PlanOrdersCur) + if err != nil { + return err + } + // Deserialize `PlaceOrdersCur`: + err = decoder.Decode(&obj.PlaceOrdersCur) + if err != nil { + return err + } + // Deserialize `ValidBuyOrderNum`: + err = decoder.Decode(&obj.ValidBuyOrderNum) + if err != nil { + return err + } + // Deserialize `ValidSellOrderNum`: + err = decoder.Decode(&obj.ValidSellOrderNum) + if err != nil { + return err + } + // Deserialize `Padding3`: + err = decoder.Decode(&obj.Padding3) + if err != nil { + return err + } + // Deserialize `FreeSlotBits`: + err = decoder.Decode(&obj.FreeSlotBits) + if err != nil { + return err + } + return nil +} + +type Fees struct { + MinSeparateNumerator uint64 + MinSeparateDenominator uint64 + TradeFeeNumerator uint64 + TradeFeeDenominator uint64 + PnlNumerator uint64 + PnlDenominator uint64 + SwapFeeNumerator uint64 + SwapFeeDenominator uint64 +} + +func (obj Fees) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `MinSeparateNumerator` param: + err = encoder.Encode(obj.MinSeparateNumerator) + if err != nil { + return err + } + // Serialize `MinSeparateDenominator` param: + err = encoder.Encode(obj.MinSeparateDenominator) + if err != nil { + return err + } + // Serialize `TradeFeeNumerator` param: + err = encoder.Encode(obj.TradeFeeNumerator) + if err != nil { + return err + } + // Serialize `TradeFeeDenominator` param: + err = encoder.Encode(obj.TradeFeeDenominator) + if err != nil { + return err + } + // Serialize `PnlNumerator` param: + err = encoder.Encode(obj.PnlNumerator) + if err != nil { + return err + } + // Serialize `PnlDenominator` param: + err = encoder.Encode(obj.PnlDenominator) + if err != nil { + return err + } + // Serialize `SwapFeeNumerator` param: + err = encoder.Encode(obj.SwapFeeNumerator) + if err != nil { + return err + } + // Serialize `SwapFeeDenominator` param: + err = encoder.Encode(obj.SwapFeeDenominator) + if err != nil { + return err + } + return nil +} + +func (obj *Fees) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `MinSeparateNumerator`: + err = decoder.Decode(&obj.MinSeparateNumerator) + if err != nil { + return err + } + // Deserialize `MinSeparateDenominator`: + err = decoder.Decode(&obj.MinSeparateDenominator) + if err != nil { + return err + } + // Deserialize `TradeFeeNumerator`: + err = decoder.Decode(&obj.TradeFeeNumerator) + if err != nil { + return err + } + // Deserialize `TradeFeeDenominator`: + err = decoder.Decode(&obj.TradeFeeDenominator) + if err != nil { + return err + } + // Deserialize `PnlNumerator`: + err = decoder.Decode(&obj.PnlNumerator) + if err != nil { + return err + } + // Deserialize `PnlDenominator`: + err = decoder.Decode(&obj.PnlDenominator) + if err != nil { + return err + } + // Deserialize `SwapFeeNumerator`: + err = decoder.Decode(&obj.SwapFeeNumerator) + if err != nil { + return err + } + // Deserialize `SwapFeeDenominator`: + err = decoder.Decode(&obj.SwapFeeDenominator) + if err != nil { + return err + } + return nil +} + +type AmmInfo struct { + Status uint64 + Nonce uint64 + OrderNum uint64 + Depth uint64 + CoinDecimals uint64 + PcDecimals uint64 + State uint64 + ResetFlag uint64 + MinSize uint64 + VolMaxCutRatio uint64 + AmountWave uint64 + CoinLotSize uint64 + PcLotSize uint64 + MinPriceMultiplier uint64 + MaxPriceMultiplier uint64 + SysDecimalValue uint64 + Fees Fees + OutPut OutPutData + TokenCoin ag_solanago.PublicKey + TokenPc ag_solanago.PublicKey + CoinMint ag_solanago.PublicKey + PcMint ag_solanago.PublicKey + LpMint ag_solanago.PublicKey + OpenOrders ag_solanago.PublicKey + Market ag_solanago.PublicKey + SerumDex ag_solanago.PublicKey + TargetOrders ag_solanago.PublicKey + WithdrawQueue ag_solanago.PublicKey + TokenTempLp ag_solanago.PublicKey + AmmOwner ag_solanago.PublicKey + LpAmount uint64 + ClientOrderId uint64 + Padding [2]uint64 +} + +func (obj AmmInfo) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Status` param: + err = encoder.Encode(obj.Status) + if err != nil { + return err + } + // Serialize `Nonce` param: + err = encoder.Encode(obj.Nonce) + if err != nil { + return err + } + // Serialize `OrderNum` param: + err = encoder.Encode(obj.OrderNum) + if err != nil { + return err + } + // Serialize `Depth` param: + err = encoder.Encode(obj.Depth) + if err != nil { + return err + } + // Serialize `CoinDecimals` param: + err = encoder.Encode(obj.CoinDecimals) + if err != nil { + return err + } + // Serialize `PcDecimals` param: + err = encoder.Encode(obj.PcDecimals) + if err != nil { + return err + } + // Serialize `State` param: + err = encoder.Encode(obj.State) + if err != nil { + return err + } + // Serialize `ResetFlag` param: + err = encoder.Encode(obj.ResetFlag) + if err != nil { + return err + } + // Serialize `MinSize` param: + err = encoder.Encode(obj.MinSize) + if err != nil { + return err + } + // Serialize `VolMaxCutRatio` param: + err = encoder.Encode(obj.VolMaxCutRatio) + if err != nil { + return err + } + // Serialize `AmountWave` param: + err = encoder.Encode(obj.AmountWave) + if err != nil { + return err + } + // Serialize `CoinLotSize` param: + err = encoder.Encode(obj.CoinLotSize) + if err != nil { + return err + } + // Serialize `PcLotSize` param: + err = encoder.Encode(obj.PcLotSize) + if err != nil { + return err + } + // Serialize `MinPriceMultiplier` param: + err = encoder.Encode(obj.MinPriceMultiplier) + if err != nil { + return err + } + // Serialize `MaxPriceMultiplier` param: + err = encoder.Encode(obj.MaxPriceMultiplier) + if err != nil { + return err + } + // Serialize `SysDecimalValue` param: + err = encoder.Encode(obj.SysDecimalValue) + if err != nil { + return err + } + // Serialize `Fees` param: + err = encoder.Encode(obj.Fees) + if err != nil { + return err + } + // Serialize `OutPut` param: + err = encoder.Encode(obj.OutPut) + if err != nil { + return err + } + // Serialize `TokenCoin` param: + err = encoder.Encode(obj.TokenCoin) + if err != nil { + return err + } + // Serialize `TokenPc` param: + err = encoder.Encode(obj.TokenPc) + if err != nil { + return err + } + // Serialize `CoinMint` param: + err = encoder.Encode(obj.CoinMint) + if err != nil { + return err + } + // Serialize `PcMint` param: + err = encoder.Encode(obj.PcMint) + if err != nil { + return err + } + // Serialize `LpMint` param: + err = encoder.Encode(obj.LpMint) + if err != nil { + return err + } + // Serialize `OpenOrders` param: + err = encoder.Encode(obj.OpenOrders) + if err != nil { + return err + } + // Serialize `Pool` param: + err = encoder.Encode(obj.Market) + if err != nil { + return err + } + // Serialize `SerumDex` param: + err = encoder.Encode(obj.SerumDex) + if err != nil { + return err + } + // Serialize `TargetOrders` param: + err = encoder.Encode(obj.TargetOrders) + if err != nil { + return err + } + // Serialize `WithdrawQueue` param: + err = encoder.Encode(obj.WithdrawQueue) + if err != nil { + return err + } + // Serialize `TokenTempLp` param: + err = encoder.Encode(obj.TokenTempLp) + if err != nil { + return err + } + // Serialize `AmmOwner` param: + err = encoder.Encode(obj.AmmOwner) + if err != nil { + return err + } + // Serialize `LpAmount` param: + err = encoder.Encode(obj.LpAmount) + if err != nil { + return err + } + // Serialize `ClientOrderId` param: + err = encoder.Encode(obj.ClientOrderId) + if err != nil { + return err + } + // Serialize `Padding` param: + err = encoder.Encode(obj.Padding) + if err != nil { + return err + } + return nil +} + +func (obj *AmmInfo) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Status`: + err = decoder.Decode(&obj.Status) + if err != nil { + return err + } + // Deserialize `Nonce`: + err = decoder.Decode(&obj.Nonce) + if err != nil { + return err + } + // Deserialize `OrderNum`: + err = decoder.Decode(&obj.OrderNum) + if err != nil { + return err + } + // Deserialize `Depth`: + err = decoder.Decode(&obj.Depth) + if err != nil { + return err + } + // Deserialize `CoinDecimals`: + err = decoder.Decode(&obj.CoinDecimals) + if err != nil { + return err + } + // Deserialize `PcDecimals`: + err = decoder.Decode(&obj.PcDecimals) + if err != nil { + return err + } + // Deserialize `State`: + err = decoder.Decode(&obj.State) + if err != nil { + return err + } + // Deserialize `ResetFlag`: + err = decoder.Decode(&obj.ResetFlag) + if err != nil { + return err + } + // Deserialize `MinSize`: + err = decoder.Decode(&obj.MinSize) + if err != nil { + return err + } + // Deserialize `VolMaxCutRatio`: + err = decoder.Decode(&obj.VolMaxCutRatio) + if err != nil { + return err + } + // Deserialize `AmountWave`: + err = decoder.Decode(&obj.AmountWave) + if err != nil { + return err + } + // Deserialize `CoinLotSize`: + err = decoder.Decode(&obj.CoinLotSize) + if err != nil { + return err + } + // Deserialize `PcLotSize`: + err = decoder.Decode(&obj.PcLotSize) + if err != nil { + return err + } + // Deserialize `MinPriceMultiplier`: + err = decoder.Decode(&obj.MinPriceMultiplier) + if err != nil { + return err + } + // Deserialize `MaxPriceMultiplier`: + err = decoder.Decode(&obj.MaxPriceMultiplier) + if err != nil { + return err + } + // Deserialize `SysDecimalValue`: + err = decoder.Decode(&obj.SysDecimalValue) + if err != nil { + return err + } + // Deserialize `Fees`: + err = decoder.Decode(&obj.Fees) + if err != nil { + return err + } + // Deserialize `OutPut`: + err = decoder.Decode(&obj.OutPut) + if err != nil { + return err + } + // Deserialize `TokenCoin`: + err = decoder.Decode(&obj.TokenCoin) + if err != nil { + return err + } + // Deserialize `TokenPc`: + err = decoder.Decode(&obj.TokenPc) + if err != nil { + return err + } + // Deserialize `CoinMint`: + err = decoder.Decode(&obj.CoinMint) + if err != nil { + return err + } + // Deserialize `PcMint`: + err = decoder.Decode(&obj.PcMint) + if err != nil { + return err + } + // Deserialize `LpMint`: + err = decoder.Decode(&obj.LpMint) + if err != nil { + return err + } + // Deserialize `OpenOrders`: + err = decoder.Decode(&obj.OpenOrders) + if err != nil { + return err + } + // Deserialize `Pool`: + err = decoder.Decode(&obj.Market) + if err != nil { + return err + } + // Deserialize `SerumDex`: + err = decoder.Decode(&obj.SerumDex) + if err != nil { + return err + } + // Deserialize `TargetOrders`: + err = decoder.Decode(&obj.TargetOrders) + if err != nil { + return err + } + // Deserialize `WithdrawQueue`: + err = decoder.Decode(&obj.WithdrawQueue) + if err != nil { + return err + } + // Deserialize `TokenTempLp`: + err = decoder.Decode(&obj.TokenTempLp) + if err != nil { + return err + } + // Deserialize `AmmOwner`: + err = decoder.Decode(&obj.AmmOwner) + if err != nil { + return err + } + // Deserialize `LpAmount`: + err = decoder.Decode(&obj.LpAmount) + if err != nil { + return err + } + // Deserialize `ClientOrderId`: + err = decoder.Decode(&obj.ClientOrderId) + if err != nil { + return err + } + // Deserialize `Padding`: + err = decoder.Decode(&obj.Padding) + if err != nil { + return err + } + return nil +} diff --git a/programs/raydiumamm/instructions.go b/programs/raydiumamm/instructions.go new file mode 100644 index 00000000..1a3fa007 --- /dev/null +++ b/programs/raydiumamm/instructions.go @@ -0,0 +1,222 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package raydium_amm + +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 = "RaydiumAmm" + +func init() { + if !ProgramID.IsZero() { + ag_solanago.RegisterInstructionDecoder(ProgramID, registryDecodeInstruction) + } +} + +const ( + Instruction_Initialize uint8 = iota + + Instruction_Initialize2 + + Instruction_MonitorStep + + Instruction_Deposit + + Instruction_Withdraw + + Instruction_MigrateToOpenBook + + Instruction_SetParams + + Instruction_WithdrawPnl + + Instruction_WithdrawSrm + + Instruction_SwapBaseIn + + Instruction_PreInitialize + + Instruction_SwapBaseOut + + Instruction_SimulateInfo + + Instruction_AdminCancelOrders + + Instruction_CreateConfigAccount + + Instruction_UpdateConfigAccount +) + +// InstructionIDToName returns the name of the instruction given its ID. +func InstructionIDToName(id uint8) string { + switch id { + case Instruction_Initialize: + return "Initialize" + case Instruction_Initialize2: + return "Initialize2" + case Instruction_MonitorStep: + return "MonitorStep" + case Instruction_Deposit: + return "Deposit" + case Instruction_Withdraw: + return "Withdraw" + case Instruction_MigrateToOpenBook: + return "MigrateToOpenBook" + case Instruction_SetParams: + return "SetParams" + case Instruction_WithdrawPnl: + return "WithdrawPnl" + case Instruction_WithdrawSrm: + return "WithdrawSrm" + case Instruction_SwapBaseIn: + return "SwapBaseIn" + case Instruction_PreInitialize: + return "PreInitialize" + case Instruction_SwapBaseOut: + return "SwapBaseOut" + case Instruction_SimulateInfo: + return "SimulateInfo" + case Instruction_AdminCancelOrders: + return "AdminCancelOrders" + case Instruction_CreateConfigAccount: + return "CreateConfigAccount" + case Instruction_UpdateConfigAccount: + return "UpdateConfigAccount" + 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.Uint8TypeIDEncoding, + []ag_binary.VariantType{ + { + "Initialize", (*Initialize)(nil), + }, + { + "Initialize2", (*Initialize2)(nil), + }, + { + "MonitorStep", (*MonitorStep)(nil), + }, + { + "Deposit", (*Deposit)(nil), + }, + { + "Withdraw", (*Withdraw)(nil), + }, + { + "MigrateToOpenBook", (*MigrateToOpenBook)(nil), + }, + { + "SetParams", (*SetParams)(nil), + }, + { + "WithdrawPnl", (*WithdrawPnl)(nil), + }, + { + "WithdrawSrm", (*WithdrawSrm)(nil), + }, + { + "SwapBaseIn", (*SwapBaseIn)(nil), + }, + { + "PreInitialize", (*PreInitialize)(nil), + }, + { + "SwapBaseOut", (*SwapBaseOut)(nil), + }, + { + "SimulateInfo", (*SimulateInfo)(nil), + }, + { + "AdminCancelOrders", (*AdminCancelOrders)(nil), + }, + { + "CreateConfigAccount", (*CreateConfigAccount)(nil), + }, + { + "UpdateConfigAccount", (*UpdateConfigAccount)(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.WriteUint8(inst.TypeID.Uint8()) + 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 +} diff --git a/programs/raydiumamm/testing_utils.go b/programs/raydiumamm/testing_utils.go new file mode 100644 index 00000000..b6bf2dcb --- /dev/null +++ b/programs/raydiumamm/testing_utils.go @@ -0,0 +1,20 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package raydium_amm + +import ( + "bytes" + "fmt" + ag_binary "github.com/gagliardetto/binary" +) + +func encodeT(data interface{}, buf *bytes.Buffer) error { + if err := ag_binary.NewBorshEncoder(buf).Encode(data); err != nil { + return fmt.Errorf("unable to encode instruction: %w", err) + } + return nil +} + +func decodeT(dst interface{}, data []byte) error { + return ag_binary.NewBorshDecoder(data).Decode(dst) +} diff --git a/programs/raydiumamm/types.go b/programs/raydiumamm/types.go new file mode 100644 index 00000000..e31f3c2a --- /dev/null +++ b/programs/raydiumamm/types.go @@ -0,0 +1,514 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package raydium_amm + +import ( + ag_binary "github.com/gagliardetto/binary" + ag_solanago "github.com/gagliardetto/solana-go" +) + +type WithdrawDestToken struct { + WithdrawAmount uint64 + CoinAmount uint64 + PcAmount uint64 + DestTokenCoin ag_solanago.PublicKey + DestTokenPc ag_solanago.PublicKey +} + +func (obj WithdrawDestToken) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `WithdrawAmount` param: + err = encoder.Encode(obj.WithdrawAmount) + if err != nil { + return err + } + // Serialize `CoinAmount` param: + err = encoder.Encode(obj.CoinAmount) + if err != nil { + return err + } + // Serialize `PcAmount` param: + err = encoder.Encode(obj.PcAmount) + if err != nil { + return err + } + // Serialize `DestTokenCoin` param: + err = encoder.Encode(obj.DestTokenCoin) + if err != nil { + return err + } + // Serialize `DestTokenPc` param: + err = encoder.Encode(obj.DestTokenPc) + if err != nil { + return err + } + return nil +} + +func (obj *WithdrawDestToken) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `WithdrawAmount`: + err = decoder.Decode(&obj.WithdrawAmount) + if err != nil { + return err + } + // Deserialize `CoinAmount`: + err = decoder.Decode(&obj.CoinAmount) + if err != nil { + return err + } + // Deserialize `PcAmount`: + err = decoder.Decode(&obj.PcAmount) + if err != nil { + return err + } + // Deserialize `DestTokenCoin`: + err = decoder.Decode(&obj.DestTokenCoin) + if err != nil { + return err + } + // Deserialize `DestTokenPc`: + err = decoder.Decode(&obj.DestTokenPc) + if err != nil { + return err + } + return nil +} + +type WithdrawQueue struct { + Owner [4]uint64 + Head uint64 + Count uint64 + Buf [64]WithdrawDestToken +} + +func (obj WithdrawQueue) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Owner` param: + err = encoder.Encode(obj.Owner) + if err != nil { + return err + } + // Serialize `Head` param: + err = encoder.Encode(obj.Head) + if err != nil { + return err + } + // Serialize `Count` param: + err = encoder.Encode(obj.Count) + if err != nil { + return err + } + // Serialize `Buf` param: + err = encoder.Encode(obj.Buf) + if err != nil { + return err + } + return nil +} + +func (obj *WithdrawQueue) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Owner`: + err = decoder.Decode(&obj.Owner) + if err != nil { + return err + } + // Deserialize `Head`: + err = decoder.Decode(&obj.Head) + if err != nil { + return err + } + // Deserialize `Count`: + err = decoder.Decode(&obj.Count) + if err != nil { + return err + } + // Deserialize `Buf`: + err = decoder.Decode(&obj.Buf) + if err != nil { + return err + } + return nil +} + +type TargetOrder struct { + Price uint64 + Vol uint64 +} + +func (obj TargetOrder) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Price` param: + err = encoder.Encode(obj.Price) + if err != nil { + return err + } + // Serialize `Vol` param: + err = encoder.Encode(obj.Vol) + if err != nil { + return err + } + return nil +} + +func (obj *TargetOrder) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Price`: + err = decoder.Decode(&obj.Price) + if err != nil { + return err + } + // Deserialize `Vol`: + err = decoder.Decode(&obj.Vol) + if err != nil { + return err + } + return nil +} + +type OutPutData struct { + NeedTakePnlCoin uint64 + NeedTakePnlPc uint64 + TotalPnlPc uint64 + TotalPnlCoin uint64 + PoolOpenTime uint64 + PunishPcAmount uint64 + PunishCoinAmount uint64 + OrderbookToInitTime uint64 + SwapCoinInAmount ag_binary.Uint128 + SwapPcOutAmount ag_binary.Uint128 + SwapTakePcFee uint64 + SwapPcInAmount ag_binary.Uint128 + SwapCoinOutAmount ag_binary.Uint128 + SwapTakeCoinFee uint64 +} + +func (obj OutPutData) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `NeedTakePnlCoin` param: + err = encoder.Encode(obj.NeedTakePnlCoin) + if err != nil { + return err + } + // Serialize `NeedTakePnlPc` param: + err = encoder.Encode(obj.NeedTakePnlPc) + if err != nil { + return err + } + // Serialize `TotalPnlPc` param: + err = encoder.Encode(obj.TotalPnlPc) + if err != nil { + return err + } + // Serialize `TotalPnlCoin` param: + err = encoder.Encode(obj.TotalPnlCoin) + if err != nil { + return err + } + // Serialize `PoolOpenTime` param: + err = encoder.Encode(obj.PoolOpenTime) + if err != nil { + return err + } + // Serialize `PunishPcAmount` param: + err = encoder.Encode(obj.PunishPcAmount) + if err != nil { + return err + } + // Serialize `PunishCoinAmount` param: + err = encoder.Encode(obj.PunishCoinAmount) + if err != nil { + return err + } + // Serialize `OrderbookToInitTime` param: + err = encoder.Encode(obj.OrderbookToInitTime) + if err != nil { + return err + } + // Serialize `SwapCoinInAmount` param: + err = encoder.Encode(obj.SwapCoinInAmount) + if err != nil { + return err + } + // Serialize `SwapPcOutAmount` param: + err = encoder.Encode(obj.SwapPcOutAmount) + if err != nil { + return err + } + // Serialize `SwapTakePcFee` param: + err = encoder.Encode(obj.SwapTakePcFee) + if err != nil { + return err + } + // Serialize `SwapPcInAmount` param: + err = encoder.Encode(obj.SwapPcInAmount) + if err != nil { + return err + } + // Serialize `SwapCoinOutAmount` param: + err = encoder.Encode(obj.SwapCoinOutAmount) + if err != nil { + return err + } + // Serialize `SwapTakeCoinFee` param: + err = encoder.Encode(obj.SwapTakeCoinFee) + if err != nil { + return err + } + return nil +} + +func (obj *OutPutData) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `NeedTakePnlCoin`: + err = decoder.Decode(&obj.NeedTakePnlCoin) + if err != nil { + return err + } + // Deserialize `NeedTakePnlPc`: + err = decoder.Decode(&obj.NeedTakePnlPc) + if err != nil { + return err + } + // Deserialize `TotalPnlPc`: + err = decoder.Decode(&obj.TotalPnlPc) + if err != nil { + return err + } + // Deserialize `TotalPnlCoin`: + err = decoder.Decode(&obj.TotalPnlCoin) + if err != nil { + return err + } + // Deserialize `PoolOpenTime`: + err = decoder.Decode(&obj.PoolOpenTime) + if err != nil { + return err + } + // Deserialize `PunishPcAmount`: + err = decoder.Decode(&obj.PunishPcAmount) + if err != nil { + return err + } + // Deserialize `PunishCoinAmount`: + err = decoder.Decode(&obj.PunishCoinAmount) + if err != nil { + return err + } + // Deserialize `OrderbookToInitTime`: + err = decoder.Decode(&obj.OrderbookToInitTime) + if err != nil { + return err + } + // Deserialize `SwapCoinInAmount`: + err = decoder.Decode(&obj.SwapCoinInAmount) + if err != nil { + return err + } + // Deserialize `SwapPcOutAmount`: + err = decoder.Decode(&obj.SwapPcOutAmount) + if err != nil { + return err + } + // Deserialize `SwapTakePcFee`: + err = decoder.Decode(&obj.SwapTakePcFee) + if err != nil { + return err + } + // Deserialize `SwapPcInAmount`: + err = decoder.Decode(&obj.SwapPcInAmount) + if err != nil { + return err + } + // Deserialize `SwapCoinOutAmount`: + err = decoder.Decode(&obj.SwapCoinOutAmount) + if err != nil { + return err + } + // Deserialize `SwapTakeCoinFee`: + err = decoder.Decode(&obj.SwapTakeCoinFee) + if err != nil { + return err + } + return nil +} + +type AmmConfig struct { + PnlOwner ag_solanago.PublicKey + CancelOwner ag_solanago.PublicKey + Pending1 [28]uint64 + Pending2 [32]uint64 +} + +func (obj AmmConfig) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `PnlOwner` param: + err = encoder.Encode(obj.PnlOwner) + if err != nil { + return err + } + // Serialize `CancelOwner` param: + err = encoder.Encode(obj.CancelOwner) + if err != nil { + return err + } + // Serialize `Pending1` param: + err = encoder.Encode(obj.Pending1) + if err != nil { + return err + } + // Serialize `Pending2` param: + err = encoder.Encode(obj.Pending2) + if err != nil { + return err + } + return nil +} + +func (obj *AmmConfig) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `PnlOwner`: + err = decoder.Decode(&obj.PnlOwner) + if err != nil { + return err + } + // Deserialize `CancelOwner`: + err = decoder.Decode(&obj.CancelOwner) + if err != nil { + return err + } + // Deserialize `Pending1`: + err = decoder.Decode(&obj.Pending1) + if err != nil { + return err + } + // Deserialize `Pending2`: + err = decoder.Decode(&obj.Pending2) + if err != nil { + return err + } + return nil +} + +type LastOrderDistance struct { + LastOrderNumerator uint64 + LastOrderDenominator uint64 +} + +func (obj LastOrderDistance) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `LastOrderNumerator` param: + err = encoder.Encode(obj.LastOrderNumerator) + if err != nil { + return err + } + // Serialize `LastOrderDenominator` param: + err = encoder.Encode(obj.LastOrderDenominator) + if err != nil { + return err + } + return nil +} + +func (obj *LastOrderDistance) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `LastOrderNumerator`: + err = decoder.Decode(&obj.LastOrderNumerator) + if err != nil { + return err + } + // Deserialize `LastOrderDenominator`: + err = decoder.Decode(&obj.LastOrderDenominator) + if err != nil { + return err + } + return nil +} + +type NeedTake struct { + NeedTakePc uint64 + NeedTakeCoin uint64 +} + +func (obj NeedTake) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `NeedTakePc` param: + err = encoder.Encode(obj.NeedTakePc) + if err != nil { + return err + } + // Serialize `NeedTakeCoin` param: + err = encoder.Encode(obj.NeedTakeCoin) + if err != nil { + return err + } + return nil +} + +func (obj *NeedTake) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `NeedTakePc`: + err = decoder.Decode(&obj.NeedTakePc) + if err != nil { + return err + } + // Deserialize `NeedTakeCoin`: + err = decoder.Decode(&obj.NeedTakeCoin) + if err != nil { + return err + } + return nil +} + +type SwapInstructionBaseIn struct { + AmountIn uint64 + MinimumAmountOut uint64 +} + +func (obj SwapInstructionBaseIn) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `AmountIn` param: + err = encoder.Encode(obj.AmountIn) + if err != nil { + return err + } + // Serialize `MinimumAmountOut` param: + err = encoder.Encode(obj.MinimumAmountOut) + if err != nil { + return err + } + return nil +} + +func (obj *SwapInstructionBaseIn) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `AmountIn`: + err = decoder.Decode(&obj.AmountIn) + if err != nil { + return err + } + // Deserialize `MinimumAmountOut`: + err = decoder.Decode(&obj.MinimumAmountOut) + if err != nil { + return err + } + return nil +} + +type SwapInstructionBaseOut struct { + MaxAmountIn uint64 + AmountOut uint64 +} + +func (obj SwapInstructionBaseOut) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `MaxAmountIn` param: + err = encoder.Encode(obj.MaxAmountIn) + if err != nil { + return err + } + // Serialize `AmountOut` param: + err = encoder.Encode(obj.AmountOut) + if err != nil { + return err + } + return nil +} + +func (obj *SwapInstructionBaseOut) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `MaxAmountIn`: + err = decoder.Decode(&obj.MaxAmountIn) + if err != nil { + return err + } + // Deserialize `AmountOut`: + err = decoder.Decode(&obj.AmountOut) + if err != nil { + return err + } + return nil +} diff --git a/programs/raydiumclmm/ClosePosition.go b/programs/raydiumclmm/ClosePosition.go new file mode 100644 index 00000000..13c18f5b --- /dev/null +++ b/programs/raydiumclmm/ClosePosition.go @@ -0,0 +1,219 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "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" +) + +// Close a position, the nft mint and nft account +// +// # Arguments +// +// * `ctx` - The context of accounts +// +type ClosePosition struct { + + // [0] = [WRITE, SIGNER] nftOwner + // ··········· The position nft owner + // + // [1] = [WRITE] positionNftMint + // ··········· Unique token mint address + // + // [2] = [WRITE] positionNftAccount + // ··········· Token account where position NFT will be minted + // + // [3] = [WRITE] personalPosition + // ··········· To store metaplex metadata + // ··········· Metadata for the tokenized position + // + // [4] = [] systemProgram + // ··········· Program to create the position manager state account + // + // [5] = [] tokenProgram + // ··········· Program to create mint account and mint tokens + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewClosePositionInstructionBuilder creates a new `ClosePosition` instruction builder. +func NewClosePositionInstructionBuilder() *ClosePosition { + nd := &ClosePosition{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 6), + } + return nd +} + +// SetNftOwnerAccount sets the "nftOwner" account. +// The position nft owner +func (inst *ClosePosition) SetNftOwnerAccount(nftOwner ag_solanago.PublicKey) *ClosePosition { + inst.AccountMetaSlice[0] = ag_solanago.Meta(nftOwner).WRITE().SIGNER() + return inst +} + +// GetNftOwnerAccount gets the "nftOwner" account. +// The position nft owner +func (inst *ClosePosition) GetNftOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetPositionNftMintAccount sets the "positionNftMint" account. +// Unique token mint address +func (inst *ClosePosition) SetPositionNftMintAccount(positionNftMint ag_solanago.PublicKey) *ClosePosition { + inst.AccountMetaSlice[1] = ag_solanago.Meta(positionNftMint).WRITE() + return inst +} + +// GetPositionNftMintAccount gets the "positionNftMint" account. +// Unique token mint address +func (inst *ClosePosition) GetPositionNftMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetPositionNftAccountAccount sets the "positionNftAccount" account. +// Token account where position NFT will be minted +func (inst *ClosePosition) SetPositionNftAccountAccount(positionNftAccount ag_solanago.PublicKey) *ClosePosition { + inst.AccountMetaSlice[2] = ag_solanago.Meta(positionNftAccount).WRITE() + return inst +} + +// GetPositionNftAccountAccount gets the "positionNftAccount" account. +// Token account where position NFT will be minted +func (inst *ClosePosition) GetPositionNftAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetPersonalPositionAccount sets the "personalPosition" account. +// To store metaplex metadata +// Metadata for the tokenized position +func (inst *ClosePosition) SetPersonalPositionAccount(personalPosition ag_solanago.PublicKey) *ClosePosition { + inst.AccountMetaSlice[3] = ag_solanago.Meta(personalPosition).WRITE() + return inst +} + +// GetPersonalPositionAccount gets the "personalPosition" account. +// To store metaplex metadata +// Metadata for the tokenized position +func (inst *ClosePosition) GetPersonalPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +// Program to create the position manager state account +func (inst *ClosePosition) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *ClosePosition { + inst.AccountMetaSlice[4] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +// Program to create the position manager state account +func (inst *ClosePosition) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +// Program to create mint account and mint tokens +func (inst *ClosePosition) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *ClosePosition { + inst.AccountMetaSlice[5] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +// Program to create mint account and mint tokens +func (inst *ClosePosition) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +func (inst ClosePosition) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_ClosePosition, + }} +} + +// 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 ClosePosition) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *ClosePosition) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.NftOwner is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.PositionNftMint is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.PositionNftAccount is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.PersonalPosition is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.SystemProgram is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.TokenProgram is not set") + } + } + return nil +} + +func (inst *ClosePosition) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("ClosePosition")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=6]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" nftOwner", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" positionNftMint", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" positionNft", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta("personalPosition", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" systemProgram", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(5))) + }) + }) + }) +} + +func (obj ClosePosition) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *ClosePosition) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewClosePositionInstruction declares a new ClosePosition instruction with the provided parameters and accounts. +func NewClosePositionInstruction( + // Accounts: + nftOwner ag_solanago.PublicKey, + positionNftMint ag_solanago.PublicKey, + positionNftAccount ag_solanago.PublicKey, + personalPosition ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey) *ClosePosition { + return NewClosePositionInstructionBuilder(). + SetNftOwnerAccount(nftOwner). + SetPositionNftMintAccount(positionNftMint). + SetPositionNftAccountAccount(positionNftAccount). + SetPersonalPositionAccount(personalPosition). + SetSystemProgramAccount(systemProgram). + SetTokenProgramAccount(tokenProgram) +} diff --git a/programs/raydiumclmm/ClosePosition_test.go b/programs/raydiumclmm/ClosePosition_test.go new file mode 100644 index 00000000..02ac7962 --- /dev/null +++ b/programs/raydiumclmm/ClosePosition_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_ClosePosition(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("ClosePosition"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(ClosePosition) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(ClosePosition) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/raydiumclmm/CollectFundFee.go b/programs/raydiumclmm/CollectFundFee.go new file mode 100644 index 00000000..9c62963a --- /dev/null +++ b/programs/raydiumclmm/CollectFundFee.go @@ -0,0 +1,380 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "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" +) + +// Collect the fund fee accrued to the pool +// +// # Arguments +// +// * `ctx` - The context of accounts +// * `amount_0_requested` - The maximum amount of token_0 to send, can be 0 to collect fees in only token_1 +// * `amount_1_requested` - The maximum amount of token_1 to send, can be 0 to collect fees in only token_0 +// +type CollectFundFee struct { + Amount0Requested *uint64 + Amount1Requested *uint64 + + // [0] = [SIGNER] owner + // ··········· Only admin or fund_owner can collect fee now + // + // [1] = [WRITE] poolState + // ··········· Pool state stores accumulated protocol fee amount + // + // [2] = [] ammConfig + // ··········· Amm config account stores fund_owner + // + // [3] = [WRITE] tokenVault0 + // ··········· The address that holds pool tokens for token_0 + // + // [4] = [WRITE] tokenVault1 + // ··········· The address that holds pool tokens for token_1 + // + // [5] = [] vault0Mint + // ··········· The mint of token vault 0 + // + // [6] = [] vault1Mint + // ··········· The mint of token vault 1 + // + // [7] = [WRITE] recipientTokenAccount0 + // ··········· The address that receives the collected token_0 protocol fees + // + // [8] = [WRITE] recipientTokenAccount1 + // ··········· The address that receives the collected token_1 protocol fees + // + // [9] = [] tokenProgram + // ··········· The SPL program to perform token transfers + // + // [10] = [] tokenProgram2022 + // ··········· The SPL program 2022 to perform token transfers + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewCollectFundFeeInstructionBuilder creates a new `CollectFundFee` instruction builder. +func NewCollectFundFeeInstructionBuilder() *CollectFundFee { + nd := &CollectFundFee{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 11), + } + return nd +} + +// SetAmount0Requested sets the "amount0Requested" parameter. +func (inst *CollectFundFee) SetAmount0Requested(amount0Requested uint64) *CollectFundFee { + inst.Amount0Requested = &amount0Requested + return inst +} + +// SetAmount1Requested sets the "amount1Requested" parameter. +func (inst *CollectFundFee) SetAmount1Requested(amount1Requested uint64) *CollectFundFee { + inst.Amount1Requested = &amount1Requested + return inst +} + +// SetOwnerAccount sets the "owner" account. +// Only admin or fund_owner can collect fee now +func (inst *CollectFundFee) SetOwnerAccount(owner ag_solanago.PublicKey) *CollectFundFee { + inst.AccountMetaSlice[0] = ag_solanago.Meta(owner).SIGNER() + return inst +} + +// GetOwnerAccount gets the "owner" account. +// Only admin or fund_owner can collect fee now +func (inst *CollectFundFee) GetOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetPoolStateAccount sets the "poolState" account. +// Pool state stores accumulated protocol fee amount +func (inst *CollectFundFee) SetPoolStateAccount(poolState ag_solanago.PublicKey) *CollectFundFee { + inst.AccountMetaSlice[1] = ag_solanago.Meta(poolState).WRITE() + return inst +} + +// GetPoolStateAccount gets the "poolState" account. +// Pool state stores accumulated protocol fee amount +func (inst *CollectFundFee) GetPoolStateAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetAmmConfigAccount sets the "ammConfig" account. +// Amm config account stores fund_owner +func (inst *CollectFundFee) SetAmmConfigAccount(ammConfig ag_solanago.PublicKey) *CollectFundFee { + inst.AccountMetaSlice[2] = ag_solanago.Meta(ammConfig) + return inst +} + +// GetAmmConfigAccount gets the "ammConfig" account. +// Amm config account stores fund_owner +func (inst *CollectFundFee) GetAmmConfigAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetTokenVault0Account sets the "tokenVault0" account. +// The address that holds pool tokens for token_0 +func (inst *CollectFundFee) SetTokenVault0Account(tokenVault0 ag_solanago.PublicKey) *CollectFundFee { + inst.AccountMetaSlice[3] = ag_solanago.Meta(tokenVault0).WRITE() + return inst +} + +// GetTokenVault0Account gets the "tokenVault0" account. +// The address that holds pool tokens for token_0 +func (inst *CollectFundFee) GetTokenVault0Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetTokenVault1Account sets the "tokenVault1" account. +// The address that holds pool tokens for token_1 +func (inst *CollectFundFee) SetTokenVault1Account(tokenVault1 ag_solanago.PublicKey) *CollectFundFee { + inst.AccountMetaSlice[4] = ag_solanago.Meta(tokenVault1).WRITE() + return inst +} + +// GetTokenVault1Account gets the "tokenVault1" account. +// The address that holds pool tokens for token_1 +func (inst *CollectFundFee) GetTokenVault1Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetVault0MintAccount sets the "vault0Mint" account. +// The mint of token vault 0 +func (inst *CollectFundFee) SetVault0MintAccount(vault0Mint ag_solanago.PublicKey) *CollectFundFee { + inst.AccountMetaSlice[5] = ag_solanago.Meta(vault0Mint) + return inst +} + +// GetVault0MintAccount gets the "vault0Mint" account. +// The mint of token vault 0 +func (inst *CollectFundFee) GetVault0MintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetVault1MintAccount sets the "vault1Mint" account. +// The mint of token vault 1 +func (inst *CollectFundFee) SetVault1MintAccount(vault1Mint ag_solanago.PublicKey) *CollectFundFee { + inst.AccountMetaSlice[6] = ag_solanago.Meta(vault1Mint) + return inst +} + +// GetVault1MintAccount gets the "vault1Mint" account. +// The mint of token vault 1 +func (inst *CollectFundFee) GetVault1MintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetRecipientTokenAccount0Account sets the "recipientTokenAccount0" account. +// The address that receives the collected token_0 protocol fees +func (inst *CollectFundFee) SetRecipientTokenAccount0Account(recipientTokenAccount0 ag_solanago.PublicKey) *CollectFundFee { + inst.AccountMetaSlice[7] = ag_solanago.Meta(recipientTokenAccount0).WRITE() + return inst +} + +// GetRecipientTokenAccount0Account gets the "recipientTokenAccount0" account. +// The address that receives the collected token_0 protocol fees +func (inst *CollectFundFee) GetRecipientTokenAccount0Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetRecipientTokenAccount1Account sets the "recipientTokenAccount1" account. +// The address that receives the collected token_1 protocol fees +func (inst *CollectFundFee) SetRecipientTokenAccount1Account(recipientTokenAccount1 ag_solanago.PublicKey) *CollectFundFee { + inst.AccountMetaSlice[8] = ag_solanago.Meta(recipientTokenAccount1).WRITE() + return inst +} + +// GetRecipientTokenAccount1Account gets the "recipientTokenAccount1" account. +// The address that receives the collected token_1 protocol fees +func (inst *CollectFundFee) GetRecipientTokenAccount1Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +// The SPL program to perform token transfers +func (inst *CollectFundFee) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *CollectFundFee { + inst.AccountMetaSlice[9] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +// The SPL program to perform token transfers +func (inst *CollectFundFee) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetTokenProgram2022Account sets the "tokenProgram2022" account. +// The SPL program 2022 to perform token transfers +func (inst *CollectFundFee) SetTokenProgram2022Account(tokenProgram2022 ag_solanago.PublicKey) *CollectFundFee { + inst.AccountMetaSlice[10] = ag_solanago.Meta(tokenProgram2022) + return inst +} + +// GetTokenProgram2022Account gets the "tokenProgram2022" account. +// The SPL program 2022 to perform token transfers +func (inst *CollectFundFee) GetTokenProgram2022Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +func (inst CollectFundFee) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_CollectFundFee, + }} +} + +// 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 CollectFundFee) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *CollectFundFee) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.Amount0Requested == nil { + return errors.New("Amount0Requested parameter is not set") + } + if inst.Amount1Requested == nil { + return errors.New("Amount1Requested parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Owner is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.PoolState is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.AmmConfig is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.TokenVault0 is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.TokenVault1 is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.Vault0Mint is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.Vault1Mint is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.RecipientTokenAccount0 is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.RecipientTokenAccount1 is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.TokenProgram2022 is not set") + } + } + return nil +} + +func (inst *CollectFundFee) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("CollectFundFee")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=2]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param("Amount0Requested", *inst.Amount0Requested)) + paramsBranch.Child(ag_format.Param("Amount1Requested", *inst.Amount1Requested)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=11]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" owner", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" poolState", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" ammConfig", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" tokenVault0", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" tokenVault1", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" vault0Mint", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" vault1Mint", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta("recipientTokenAccount0", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta("recipientTokenAccount1", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" tokenProgram2022", inst.AccountMetaSlice.Get(10))) + }) + }) + }) +} + +func (obj CollectFundFee) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Amount0Requested` param: + err = encoder.Encode(obj.Amount0Requested) + if err != nil { + return err + } + // Serialize `Amount1Requested` param: + err = encoder.Encode(obj.Amount1Requested) + if err != nil { + return err + } + return nil +} +func (obj *CollectFundFee) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Amount0Requested`: + err = decoder.Decode(&obj.Amount0Requested) + if err != nil { + return err + } + // Deserialize `Amount1Requested`: + err = decoder.Decode(&obj.Amount1Requested) + if err != nil { + return err + } + return nil +} + +// NewCollectFundFeeInstruction declares a new CollectFundFee instruction with the provided parameters and accounts. +func NewCollectFundFeeInstruction( + // Parameters: + amount0Requested uint64, + amount1Requested uint64, + // Accounts: + owner ag_solanago.PublicKey, + poolState ag_solanago.PublicKey, + ammConfig ag_solanago.PublicKey, + tokenVault0 ag_solanago.PublicKey, + tokenVault1 ag_solanago.PublicKey, + vault0Mint ag_solanago.PublicKey, + vault1Mint ag_solanago.PublicKey, + recipientTokenAccount0 ag_solanago.PublicKey, + recipientTokenAccount1 ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + tokenProgram2022 ag_solanago.PublicKey) *CollectFundFee { + return NewCollectFundFeeInstructionBuilder(). + SetAmount0Requested(amount0Requested). + SetAmount1Requested(amount1Requested). + SetOwnerAccount(owner). + SetPoolStateAccount(poolState). + SetAmmConfigAccount(ammConfig). + SetTokenVault0Account(tokenVault0). + SetTokenVault1Account(tokenVault1). + SetVault0MintAccount(vault0Mint). + SetVault1MintAccount(vault1Mint). + SetRecipientTokenAccount0Account(recipientTokenAccount0). + SetRecipientTokenAccount1Account(recipientTokenAccount1). + SetTokenProgramAccount(tokenProgram). + SetTokenProgram2022Account(tokenProgram2022) +} diff --git a/programs/raydiumclmm/CollectFundFee_test.go b/programs/raydiumclmm/CollectFundFee_test.go new file mode 100644 index 00000000..2cd05545 --- /dev/null +++ b/programs/raydiumclmm/CollectFundFee_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_CollectFundFee(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("CollectFundFee"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(CollectFundFee) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(CollectFundFee) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/raydiumclmm/CollectProtocolFee.go b/programs/raydiumclmm/CollectProtocolFee.go new file mode 100644 index 00000000..2a6e29ef --- /dev/null +++ b/programs/raydiumclmm/CollectProtocolFee.go @@ -0,0 +1,380 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "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" +) + +// Collect the protocol fee accrued to the pool +// +// # Arguments +// +// * `ctx` - The context of accounts +// * `amount_0_requested` - The maximum amount of token_0 to send, can be 0 to collect fees in only token_1 +// * `amount_1_requested` - The maximum amount of token_1 to send, can be 0 to collect fees in only token_0 +// +type CollectProtocolFee struct { + Amount0Requested *uint64 + Amount1Requested *uint64 + + // [0] = [SIGNER] owner + // ··········· Only admin or config owner can collect fee now + // + // [1] = [WRITE] poolState + // ··········· Pool state stores accumulated protocol fee amount + // + // [2] = [] ammConfig + // ··········· Amm config account stores owner + // + // [3] = [WRITE] tokenVault0 + // ··········· The address that holds pool tokens for token_0 + // + // [4] = [WRITE] tokenVault1 + // ··········· The address that holds pool tokens for token_1 + // + // [5] = [] vault0Mint + // ··········· The mint of token vault 0 + // + // [6] = [] vault1Mint + // ··········· The mint of token vault 1 + // + // [7] = [WRITE] recipientTokenAccount0 + // ··········· The address that receives the collected token_0 protocol fees + // + // [8] = [WRITE] recipientTokenAccount1 + // ··········· The address that receives the collected token_1 protocol fees + // + // [9] = [] tokenProgram + // ··········· The SPL program to perform token transfers + // + // [10] = [] tokenProgram2022 + // ··········· The SPL program 2022 to perform token transfers + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewCollectProtocolFeeInstructionBuilder creates a new `CollectProtocolFee` instruction builder. +func NewCollectProtocolFeeInstructionBuilder() *CollectProtocolFee { + nd := &CollectProtocolFee{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 11), + } + return nd +} + +// SetAmount0Requested sets the "amount0Requested" parameter. +func (inst *CollectProtocolFee) SetAmount0Requested(amount0Requested uint64) *CollectProtocolFee { + inst.Amount0Requested = &amount0Requested + return inst +} + +// SetAmount1Requested sets the "amount1Requested" parameter. +func (inst *CollectProtocolFee) SetAmount1Requested(amount1Requested uint64) *CollectProtocolFee { + inst.Amount1Requested = &amount1Requested + return inst +} + +// SetOwnerAccount sets the "owner" account. +// Only admin or config owner can collect fee now +func (inst *CollectProtocolFee) SetOwnerAccount(owner ag_solanago.PublicKey) *CollectProtocolFee { + inst.AccountMetaSlice[0] = ag_solanago.Meta(owner).SIGNER() + return inst +} + +// GetOwnerAccount gets the "owner" account. +// Only admin or config owner can collect fee now +func (inst *CollectProtocolFee) GetOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetPoolStateAccount sets the "poolState" account. +// Pool state stores accumulated protocol fee amount +func (inst *CollectProtocolFee) SetPoolStateAccount(poolState ag_solanago.PublicKey) *CollectProtocolFee { + inst.AccountMetaSlice[1] = ag_solanago.Meta(poolState).WRITE() + return inst +} + +// GetPoolStateAccount gets the "poolState" account. +// Pool state stores accumulated protocol fee amount +func (inst *CollectProtocolFee) GetPoolStateAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetAmmConfigAccount sets the "ammConfig" account. +// Amm config account stores owner +func (inst *CollectProtocolFee) SetAmmConfigAccount(ammConfig ag_solanago.PublicKey) *CollectProtocolFee { + inst.AccountMetaSlice[2] = ag_solanago.Meta(ammConfig) + return inst +} + +// GetAmmConfigAccount gets the "ammConfig" account. +// Amm config account stores owner +func (inst *CollectProtocolFee) GetAmmConfigAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetTokenVault0Account sets the "tokenVault0" account. +// The address that holds pool tokens for token_0 +func (inst *CollectProtocolFee) SetTokenVault0Account(tokenVault0 ag_solanago.PublicKey) *CollectProtocolFee { + inst.AccountMetaSlice[3] = ag_solanago.Meta(tokenVault0).WRITE() + return inst +} + +// GetTokenVault0Account gets the "tokenVault0" account. +// The address that holds pool tokens for token_0 +func (inst *CollectProtocolFee) GetTokenVault0Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetTokenVault1Account sets the "tokenVault1" account. +// The address that holds pool tokens for token_1 +func (inst *CollectProtocolFee) SetTokenVault1Account(tokenVault1 ag_solanago.PublicKey) *CollectProtocolFee { + inst.AccountMetaSlice[4] = ag_solanago.Meta(tokenVault1).WRITE() + return inst +} + +// GetTokenVault1Account gets the "tokenVault1" account. +// The address that holds pool tokens for token_1 +func (inst *CollectProtocolFee) GetTokenVault1Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetVault0MintAccount sets the "vault0Mint" account. +// The mint of token vault 0 +func (inst *CollectProtocolFee) SetVault0MintAccount(vault0Mint ag_solanago.PublicKey) *CollectProtocolFee { + inst.AccountMetaSlice[5] = ag_solanago.Meta(vault0Mint) + return inst +} + +// GetVault0MintAccount gets the "vault0Mint" account. +// The mint of token vault 0 +func (inst *CollectProtocolFee) GetVault0MintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetVault1MintAccount sets the "vault1Mint" account. +// The mint of token vault 1 +func (inst *CollectProtocolFee) SetVault1MintAccount(vault1Mint ag_solanago.PublicKey) *CollectProtocolFee { + inst.AccountMetaSlice[6] = ag_solanago.Meta(vault1Mint) + return inst +} + +// GetVault1MintAccount gets the "vault1Mint" account. +// The mint of token vault 1 +func (inst *CollectProtocolFee) GetVault1MintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetRecipientTokenAccount0Account sets the "recipientTokenAccount0" account. +// The address that receives the collected token_0 protocol fees +func (inst *CollectProtocolFee) SetRecipientTokenAccount0Account(recipientTokenAccount0 ag_solanago.PublicKey) *CollectProtocolFee { + inst.AccountMetaSlice[7] = ag_solanago.Meta(recipientTokenAccount0).WRITE() + return inst +} + +// GetRecipientTokenAccount0Account gets the "recipientTokenAccount0" account. +// The address that receives the collected token_0 protocol fees +func (inst *CollectProtocolFee) GetRecipientTokenAccount0Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetRecipientTokenAccount1Account sets the "recipientTokenAccount1" account. +// The address that receives the collected token_1 protocol fees +func (inst *CollectProtocolFee) SetRecipientTokenAccount1Account(recipientTokenAccount1 ag_solanago.PublicKey) *CollectProtocolFee { + inst.AccountMetaSlice[8] = ag_solanago.Meta(recipientTokenAccount1).WRITE() + return inst +} + +// GetRecipientTokenAccount1Account gets the "recipientTokenAccount1" account. +// The address that receives the collected token_1 protocol fees +func (inst *CollectProtocolFee) GetRecipientTokenAccount1Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +// The SPL program to perform token transfers +func (inst *CollectProtocolFee) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *CollectProtocolFee { + inst.AccountMetaSlice[9] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +// The SPL program to perform token transfers +func (inst *CollectProtocolFee) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetTokenProgram2022Account sets the "tokenProgram2022" account. +// The SPL program 2022 to perform token transfers +func (inst *CollectProtocolFee) SetTokenProgram2022Account(tokenProgram2022 ag_solanago.PublicKey) *CollectProtocolFee { + inst.AccountMetaSlice[10] = ag_solanago.Meta(tokenProgram2022) + return inst +} + +// GetTokenProgram2022Account gets the "tokenProgram2022" account. +// The SPL program 2022 to perform token transfers +func (inst *CollectProtocolFee) GetTokenProgram2022Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +func (inst CollectProtocolFee) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_CollectProtocolFee, + }} +} + +// 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 CollectProtocolFee) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *CollectProtocolFee) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.Amount0Requested == nil { + return errors.New("Amount0Requested parameter is not set") + } + if inst.Amount1Requested == nil { + return errors.New("Amount1Requested parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Owner is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.PoolState is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.AmmConfig is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.TokenVault0 is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.TokenVault1 is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.Vault0Mint is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.Vault1Mint is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.RecipientTokenAccount0 is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.RecipientTokenAccount1 is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.TokenProgram2022 is not set") + } + } + return nil +} + +func (inst *CollectProtocolFee) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("CollectProtocolFee")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=2]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param("Amount0Requested", *inst.Amount0Requested)) + paramsBranch.Child(ag_format.Param("Amount1Requested", *inst.Amount1Requested)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=11]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" owner", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" poolState", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" ammConfig", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" tokenVault0", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" tokenVault1", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" vault0Mint", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" vault1Mint", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta("recipientTokenAccount0", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta("recipientTokenAccount1", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" tokenProgram2022", inst.AccountMetaSlice.Get(10))) + }) + }) + }) +} + +func (obj CollectProtocolFee) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Amount0Requested` param: + err = encoder.Encode(obj.Amount0Requested) + if err != nil { + return err + } + // Serialize `Amount1Requested` param: + err = encoder.Encode(obj.Amount1Requested) + if err != nil { + return err + } + return nil +} +func (obj *CollectProtocolFee) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Amount0Requested`: + err = decoder.Decode(&obj.Amount0Requested) + if err != nil { + return err + } + // Deserialize `Amount1Requested`: + err = decoder.Decode(&obj.Amount1Requested) + if err != nil { + return err + } + return nil +} + +// NewCollectProtocolFeeInstruction declares a new CollectProtocolFee instruction with the provided parameters and accounts. +func NewCollectProtocolFeeInstruction( + // Parameters: + amount0Requested uint64, + amount1Requested uint64, + // Accounts: + owner ag_solanago.PublicKey, + poolState ag_solanago.PublicKey, + ammConfig ag_solanago.PublicKey, + tokenVault0 ag_solanago.PublicKey, + tokenVault1 ag_solanago.PublicKey, + vault0Mint ag_solanago.PublicKey, + vault1Mint ag_solanago.PublicKey, + recipientTokenAccount0 ag_solanago.PublicKey, + recipientTokenAccount1 ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + tokenProgram2022 ag_solanago.PublicKey) *CollectProtocolFee { + return NewCollectProtocolFeeInstructionBuilder(). + SetAmount0Requested(amount0Requested). + SetAmount1Requested(amount1Requested). + SetOwnerAccount(owner). + SetPoolStateAccount(poolState). + SetAmmConfigAccount(ammConfig). + SetTokenVault0Account(tokenVault0). + SetTokenVault1Account(tokenVault1). + SetVault0MintAccount(vault0Mint). + SetVault1MintAccount(vault1Mint). + SetRecipientTokenAccount0Account(recipientTokenAccount0). + SetRecipientTokenAccount1Account(recipientTokenAccount1). + SetTokenProgramAccount(tokenProgram). + SetTokenProgram2022Account(tokenProgram2022) +} diff --git a/programs/raydiumclmm/CollectProtocolFee_test.go b/programs/raydiumclmm/CollectProtocolFee_test.go new file mode 100644 index 00000000..d6f81231 --- /dev/null +++ b/programs/raydiumclmm/CollectProtocolFee_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_CollectProtocolFee(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("CollectProtocolFee"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(CollectProtocolFee) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(CollectProtocolFee) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/raydiumclmm/CollectRemainingRewards.go b/programs/raydiumclmm/CollectRemainingRewards.go new file mode 100644 index 00000000..5efc81f3 --- /dev/null +++ b/programs/raydiumclmm/CollectRemainingRewards.go @@ -0,0 +1,287 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "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" +) + +// Collect remaining reward token for reward founder +// +// # Arguments +// +// * `ctx`- The context of accounts +// * `reward_index` - the index to reward info +// +type CollectRemainingRewards struct { + RewardIndex *uint8 + + // [0] = [SIGNER] rewardFunder + // ··········· The founder who init reward info in berfore + // + // [1] = [WRITE] funderTokenAccount + // ··········· The funder's reward token account + // + // [2] = [WRITE] poolState + // ··········· Set reward for this pool + // + // [3] = [] rewardTokenVault + // ··········· Reward vault transfer remaining token to founder token account + // + // [4] = [] rewardVaultMint + // ··········· The mint of reward token vault + // + // [5] = [] tokenProgram + // + // [6] = [] tokenProgram2022 + // ··········· Token program 2022 + // + // [7] = [] memoProgram + // ··········· memo program + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewCollectRemainingRewardsInstructionBuilder creates a new `CollectRemainingRewards` instruction builder. +func NewCollectRemainingRewardsInstructionBuilder() *CollectRemainingRewards { + nd := &CollectRemainingRewards{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 8), + } + return nd +} + +// SetRewardIndex sets the "rewardIndex" parameter. +func (inst *CollectRemainingRewards) SetRewardIndex(rewardIndex uint8) *CollectRemainingRewards { + inst.RewardIndex = &rewardIndex + return inst +} + +// SetRewardFunderAccount sets the "rewardFunder" account. +// The founder who init reward info in berfore +func (inst *CollectRemainingRewards) SetRewardFunderAccount(rewardFunder ag_solanago.PublicKey) *CollectRemainingRewards { + inst.AccountMetaSlice[0] = ag_solanago.Meta(rewardFunder).SIGNER() + return inst +} + +// GetRewardFunderAccount gets the "rewardFunder" account. +// The founder who init reward info in berfore +func (inst *CollectRemainingRewards) GetRewardFunderAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetFunderTokenAccountAccount sets the "funderTokenAccount" account. +// The funder's reward token account +func (inst *CollectRemainingRewards) SetFunderTokenAccountAccount(funderTokenAccount ag_solanago.PublicKey) *CollectRemainingRewards { + inst.AccountMetaSlice[1] = ag_solanago.Meta(funderTokenAccount).WRITE() + return inst +} + +// GetFunderTokenAccountAccount gets the "funderTokenAccount" account. +// The funder's reward token account +func (inst *CollectRemainingRewards) GetFunderTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetPoolStateAccount sets the "poolState" account. +// Set reward for this pool +func (inst *CollectRemainingRewards) SetPoolStateAccount(poolState ag_solanago.PublicKey) *CollectRemainingRewards { + inst.AccountMetaSlice[2] = ag_solanago.Meta(poolState).WRITE() + return inst +} + +// GetPoolStateAccount gets the "poolState" account. +// Set reward for this pool +func (inst *CollectRemainingRewards) GetPoolStateAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetRewardTokenVaultAccount sets the "rewardTokenVault" account. +// Reward vault transfer remaining token to founder token account +func (inst *CollectRemainingRewards) SetRewardTokenVaultAccount(rewardTokenVault ag_solanago.PublicKey) *CollectRemainingRewards { + inst.AccountMetaSlice[3] = ag_solanago.Meta(rewardTokenVault) + return inst +} + +// GetRewardTokenVaultAccount gets the "rewardTokenVault" account. +// Reward vault transfer remaining token to founder token account +func (inst *CollectRemainingRewards) GetRewardTokenVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetRewardVaultMintAccount sets the "rewardVaultMint" account. +// The mint of reward token vault +func (inst *CollectRemainingRewards) SetRewardVaultMintAccount(rewardVaultMint ag_solanago.PublicKey) *CollectRemainingRewards { + inst.AccountMetaSlice[4] = ag_solanago.Meta(rewardVaultMint) + return inst +} + +// GetRewardVaultMintAccount gets the "rewardVaultMint" account. +// The mint of reward token vault +func (inst *CollectRemainingRewards) GetRewardVaultMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *CollectRemainingRewards) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *CollectRemainingRewards { + inst.AccountMetaSlice[5] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *CollectRemainingRewards) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetTokenProgram2022Account sets the "tokenProgram2022" account. +// Token program 2022 +func (inst *CollectRemainingRewards) SetTokenProgram2022Account(tokenProgram2022 ag_solanago.PublicKey) *CollectRemainingRewards { + inst.AccountMetaSlice[6] = ag_solanago.Meta(tokenProgram2022) + return inst +} + +// GetTokenProgram2022Account gets the "tokenProgram2022" account. +// Token program 2022 +func (inst *CollectRemainingRewards) GetTokenProgram2022Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetMemoProgramAccount sets the "memoProgram" account. +// memo program +func (inst *CollectRemainingRewards) SetMemoProgramAccount(memoProgram ag_solanago.PublicKey) *CollectRemainingRewards { + inst.AccountMetaSlice[7] = ag_solanago.Meta(memoProgram) + return inst +} + +// GetMemoProgramAccount gets the "memoProgram" account. +// memo program +func (inst *CollectRemainingRewards) GetMemoProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +func (inst CollectRemainingRewards) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_CollectRemainingRewards, + }} +} + +// 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 CollectRemainingRewards) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *CollectRemainingRewards) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.RewardIndex == nil { + return errors.New("RewardIndex parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.RewardFunder is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.FunderTokenAccount is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.PoolState is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.RewardTokenVault is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.RewardVaultMint is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.TokenProgram2022 is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.MemoProgram is not set") + } + } + return nil +} + +func (inst *CollectRemainingRewards) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("CollectRemainingRewards")). + // + 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("RewardIndex", *inst.RewardIndex)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=8]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" rewardFunder", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" funderToken", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" poolState", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta("rewardTokenVault", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" rewardVaultMint", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta("tokenProgram2022", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" memoProgram", inst.AccountMetaSlice.Get(7))) + }) + }) + }) +} + +func (obj CollectRemainingRewards) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `RewardIndex` param: + err = encoder.Encode(obj.RewardIndex) + if err != nil { + return err + } + return nil +} +func (obj *CollectRemainingRewards) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `RewardIndex`: + err = decoder.Decode(&obj.RewardIndex) + if err != nil { + return err + } + return nil +} + +// NewCollectRemainingRewardsInstruction declares a new CollectRemainingRewards instruction with the provided parameters and accounts. +func NewCollectRemainingRewardsInstruction( + // Parameters: + rewardIndex uint8, + // Accounts: + rewardFunder ag_solanago.PublicKey, + funderTokenAccount ag_solanago.PublicKey, + poolState ag_solanago.PublicKey, + rewardTokenVault ag_solanago.PublicKey, + rewardVaultMint ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + tokenProgram2022 ag_solanago.PublicKey, + memoProgram ag_solanago.PublicKey) *CollectRemainingRewards { + return NewCollectRemainingRewardsInstructionBuilder(). + SetRewardIndex(rewardIndex). + SetRewardFunderAccount(rewardFunder). + SetFunderTokenAccountAccount(funderTokenAccount). + SetPoolStateAccount(poolState). + SetRewardTokenVaultAccount(rewardTokenVault). + SetRewardVaultMintAccount(rewardVaultMint). + SetTokenProgramAccount(tokenProgram). + SetTokenProgram2022Account(tokenProgram2022). + SetMemoProgramAccount(memoProgram) +} diff --git a/programs/raydiumclmm/CollectRemainingRewards_test.go b/programs/raydiumclmm/CollectRemainingRewards_test.go new file mode 100644 index 00000000..090e7097 --- /dev/null +++ b/programs/raydiumclmm/CollectRemainingRewards_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_CollectRemainingRewards(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("CollectRemainingRewards"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(CollectRemainingRewards) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(CollectRemainingRewards) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/raydiumclmm/CreateAmmConfig.go b/programs/raydiumclmm/CreateAmmConfig.go new file mode 100644 index 00000000..cd174be9 --- /dev/null +++ b/programs/raydiumclmm/CreateAmmConfig.go @@ -0,0 +1,271 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "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" +) + +// # Arguments +// +// * `ctx`- The accounts needed by instruction. +// * `index` - The index of amm config, there may be multiple config. +// * `tick_spacing` - The tickspacing binding with config, cannot be changed. +// * `trade_fee_rate` - Trade fee rate, can be changed. +// * `protocol_fee_rate` - The rate of protocol fee within tarde fee. +// * `fund_fee_rate` - The rate of fund fee within tarde fee. +// +type CreateAmmConfig struct { + Index *uint16 + TickSpacing *uint16 + TradeFeeRate *uint32 + ProtocolFeeRate *uint32 + FundFeeRate *uint32 + + // [0] = [WRITE, SIGNER] owner + // ··········· Address to be set as protocol owner. + // + // [1] = [WRITE] ammConfig + // ··········· Initialize config state account to store protocol owner address and fee rates. + // + // [2] = [] systemProgram + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewCreateAmmConfigInstructionBuilder creates a new `CreateAmmConfig` instruction builder. +func NewCreateAmmConfigInstructionBuilder() *CreateAmmConfig { + nd := &CreateAmmConfig{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 3), + } + return nd +} + +// SetIndex sets the "index" parameter. +func (inst *CreateAmmConfig) SetIndex(index uint16) *CreateAmmConfig { + inst.Index = &index + return inst +} + +// SetTickSpacing sets the "tickSpacing" parameter. +func (inst *CreateAmmConfig) SetTickSpacing(tickSpacing uint16) *CreateAmmConfig { + inst.TickSpacing = &tickSpacing + return inst +} + +// SetTradeFeeRate sets the "tradeFeeRate" parameter. +func (inst *CreateAmmConfig) SetTradeFeeRate(tradeFeeRate uint32) *CreateAmmConfig { + inst.TradeFeeRate = &tradeFeeRate + return inst +} + +// SetProtocolFeeRate sets the "protocolFeeRate" parameter. +func (inst *CreateAmmConfig) SetProtocolFeeRate(protocolFeeRate uint32) *CreateAmmConfig { + inst.ProtocolFeeRate = &protocolFeeRate + return inst +} + +// SetFundFeeRate sets the "fundFeeRate" parameter. +func (inst *CreateAmmConfig) SetFundFeeRate(fundFeeRate uint32) *CreateAmmConfig { + inst.FundFeeRate = &fundFeeRate + return inst +} + +// SetOwnerAccount sets the "owner" account. +// Address to be set as protocol owner. +func (inst *CreateAmmConfig) SetOwnerAccount(owner ag_solanago.PublicKey) *CreateAmmConfig { + inst.AccountMetaSlice[0] = ag_solanago.Meta(owner).WRITE().SIGNER() + return inst +} + +// GetOwnerAccount gets the "owner" account. +// Address to be set as protocol owner. +func (inst *CreateAmmConfig) GetOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetAmmConfigAccount sets the "ammConfig" account. +// Initialize config state account to store protocol owner address and fee rates. +func (inst *CreateAmmConfig) SetAmmConfigAccount(ammConfig ag_solanago.PublicKey) *CreateAmmConfig { + inst.AccountMetaSlice[1] = ag_solanago.Meta(ammConfig).WRITE() + return inst +} + +// GetAmmConfigAccount gets the "ammConfig" account. +// Initialize config state account to store protocol owner address and fee rates. +func (inst *CreateAmmConfig) GetAmmConfigAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +func (inst *CreateAmmConfig) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *CreateAmmConfig { + inst.AccountMetaSlice[2] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +func (inst *CreateAmmConfig) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +func (inst CreateAmmConfig) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_CreateAmmConfig, + }} +} + +// 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 CreateAmmConfig) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *CreateAmmConfig) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.Index == nil { + return errors.New("Index parameter is not set") + } + if inst.TickSpacing == nil { + return errors.New("TickSpacing parameter is not set") + } + if inst.TradeFeeRate == nil { + return errors.New("TradeFeeRate parameter is not set") + } + if inst.ProtocolFeeRate == nil { + return errors.New("ProtocolFeeRate parameter is not set") + } + if inst.FundFeeRate == nil { + return errors.New("FundFeeRate parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Owner is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.AmmConfig is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.SystemProgram is not set") + } + } + return nil +} + +func (inst *CreateAmmConfig) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("CreateAmmConfig")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=5]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" Index", *inst.Index)) + paramsBranch.Child(ag_format.Param(" TickSpacing", *inst.TickSpacing)) + paramsBranch.Child(ag_format.Param(" TradeFeeRate", *inst.TradeFeeRate)) + paramsBranch.Child(ag_format.Param("ProtocolFeeRate", *inst.ProtocolFeeRate)) + paramsBranch.Child(ag_format.Param(" FundFeeRate", *inst.FundFeeRate)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=3]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" owner", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" ammConfig", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta("systemProgram", inst.AccountMetaSlice.Get(2))) + }) + }) + }) +} + +func (obj CreateAmmConfig) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Index` param: + err = encoder.Encode(obj.Index) + if err != nil { + return err + } + // Serialize `TickSpacing` param: + err = encoder.Encode(obj.TickSpacing) + if err != nil { + return err + } + // Serialize `TradeFeeRate` param: + err = encoder.Encode(obj.TradeFeeRate) + if err != nil { + return err + } + // Serialize `ProtocolFeeRate` param: + err = encoder.Encode(obj.ProtocolFeeRate) + if err != nil { + return err + } + // Serialize `FundFeeRate` param: + err = encoder.Encode(obj.FundFeeRate) + if err != nil { + return err + } + return nil +} +func (obj *CreateAmmConfig) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Index`: + err = decoder.Decode(&obj.Index) + if err != nil { + return err + } + // Deserialize `TickSpacing`: + err = decoder.Decode(&obj.TickSpacing) + if err != nil { + return err + } + // Deserialize `TradeFeeRate`: + err = decoder.Decode(&obj.TradeFeeRate) + if err != nil { + return err + } + // Deserialize `ProtocolFeeRate`: + err = decoder.Decode(&obj.ProtocolFeeRate) + if err != nil { + return err + } + // Deserialize `FundFeeRate`: + err = decoder.Decode(&obj.FundFeeRate) + if err != nil { + return err + } + return nil +} + +// NewCreateAmmConfigInstruction declares a new CreateAmmConfig instruction with the provided parameters and accounts. +func NewCreateAmmConfigInstruction( + // Parameters: + index uint16, + tickSpacing uint16, + tradeFeeRate uint32, + protocolFeeRate uint32, + fundFeeRate uint32, + // Accounts: + owner ag_solanago.PublicKey, + ammConfig ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey) *CreateAmmConfig { + return NewCreateAmmConfigInstructionBuilder(). + SetIndex(index). + SetTickSpacing(tickSpacing). + SetTradeFeeRate(tradeFeeRate). + SetProtocolFeeRate(protocolFeeRate). + SetFundFeeRate(fundFeeRate). + SetOwnerAccount(owner). + SetAmmConfigAccount(ammConfig). + SetSystemProgramAccount(systemProgram) +} diff --git a/programs/raydiumclmm/CreateAmmConfig_test.go b/programs/raydiumclmm/CreateAmmConfig_test.go new file mode 100644 index 00000000..4d42f02a --- /dev/null +++ b/programs/raydiumclmm/CreateAmmConfig_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_CreateAmmConfig(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("CreateAmmConfig"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(CreateAmmConfig) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(CreateAmmConfig) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/raydiumclmm/CreateOperationAccount.go b/programs/raydiumclmm/CreateOperationAccount.go new file mode 100644 index 00000000..5d4f46fb --- /dev/null +++ b/programs/raydiumclmm/CreateOperationAccount.go @@ -0,0 +1,147 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "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" +) + +// Creates an operation account for the program +// +// # Arguments +// +// * `ctx`- The context of accounts +// +type CreateOperationAccount struct { + + // [0] = [WRITE, SIGNER] owner + // ··········· Address to be set as operation account owner. + // + // [1] = [WRITE] operationState + // ··········· Initialize operation state account to store operation owner address and white list mint. + // + // [2] = [] systemProgram + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewCreateOperationAccountInstructionBuilder creates a new `CreateOperationAccount` instruction builder. +func NewCreateOperationAccountInstructionBuilder() *CreateOperationAccount { + nd := &CreateOperationAccount{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 3), + } + return nd +} + +// SetOwnerAccount sets the "owner" account. +// Address to be set as operation account owner. +func (inst *CreateOperationAccount) SetOwnerAccount(owner ag_solanago.PublicKey) *CreateOperationAccount { + inst.AccountMetaSlice[0] = ag_solanago.Meta(owner).WRITE().SIGNER() + return inst +} + +// GetOwnerAccount gets the "owner" account. +// Address to be set as operation account owner. +func (inst *CreateOperationAccount) GetOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetOperationStateAccount sets the "operationState" account. +// Initialize operation state account to store operation owner address and white list mint. +func (inst *CreateOperationAccount) SetOperationStateAccount(operationState ag_solanago.PublicKey) *CreateOperationAccount { + inst.AccountMetaSlice[1] = ag_solanago.Meta(operationState).WRITE() + return inst +} + +// GetOperationStateAccount gets the "operationState" account. +// Initialize operation state account to store operation owner address and white list mint. +func (inst *CreateOperationAccount) GetOperationStateAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +func (inst *CreateOperationAccount) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *CreateOperationAccount { + inst.AccountMetaSlice[2] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +func (inst *CreateOperationAccount) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +func (inst CreateOperationAccount) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_CreateOperationAccount, + }} +} + +// 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 CreateOperationAccount) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *CreateOperationAccount) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Owner is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.OperationState is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.SystemProgram is not set") + } + } + return nil +} + +func (inst *CreateOperationAccount) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("CreateOperationAccount")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=3]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" owner", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta("operationState", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" systemProgram", inst.AccountMetaSlice.Get(2))) + }) + }) + }) +} + +func (obj CreateOperationAccount) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *CreateOperationAccount) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewCreateOperationAccountInstruction declares a new CreateOperationAccount instruction with the provided parameters and accounts. +func NewCreateOperationAccountInstruction( + // Accounts: + owner ag_solanago.PublicKey, + operationState ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey) *CreateOperationAccount { + return NewCreateOperationAccountInstructionBuilder(). + SetOwnerAccount(owner). + SetOperationStateAccount(operationState). + SetSystemProgramAccount(systemProgram) +} diff --git a/programs/raydiumclmm/CreateOperationAccount_test.go b/programs/raydiumclmm/CreateOperationAccount_test.go new file mode 100644 index 00000000..78f642de --- /dev/null +++ b/programs/raydiumclmm/CreateOperationAccount_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_CreateOperationAccount(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("CreateOperationAccount"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(CreateOperationAccount) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(CreateOperationAccount) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/raydiumclmm/CreatePool.go b/programs/raydiumclmm/CreatePool.go new file mode 100644 index 00000000..cee0b8c5 --- /dev/null +++ b/programs/raydiumclmm/CreatePool.go @@ -0,0 +1,420 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "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" +) + +// Creates a pool for the given token pair and the initial price +// +// # Arguments +// +// * `ctx`- The context of accounts +// * `sqrt_price_x64` - the initial sqrt price (amount_token_1 / amount_token_0) of the pool as a Q64.64 +// +type CreatePool struct { + SqrtPriceX64 *ag_binary.Uint128 + OpenTime *uint64 + + // [0] = [WRITE, SIGNER] poolCreator + // ··········· Address paying to create the pool. Can be anyone + // + // [1] = [] ammConfig + // ··········· Which config the pool belongs to. + // + // [2] = [WRITE] poolState + // ··········· Initialize an account to store the pool state + // + // [3] = [] tokenMint0 + // ··········· Token_0 mint, the key must grater then token_1 mint. + // + // [4] = [] tokenMint1 + // ··········· Token_1 mint + // + // [5] = [WRITE] tokenVault0 + // ··········· Token_0 vault for the pool + // + // [6] = [WRITE] tokenVault1 + // ··········· Token_1 vault for the pool + // + // [7] = [] observationState + // + // [8] = [WRITE] tickArrayBitmap + // ··········· Initialize an account to store if a tick array is initialized. + // + // [9] = [] tokenProgram0 + // ··········· Spl token program or token program 2022 + // + // [10] = [] tokenProgram1 + // ··········· Spl token program or token program 2022 + // + // [11] = [] systemProgram + // ··········· To create a new program account + // + // [12] = [] rent + // ··········· Sysvar for program account + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewCreatePoolInstructionBuilder creates a new `CreatePool` instruction builder. +func NewCreatePoolInstructionBuilder() *CreatePool { + nd := &CreatePool{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 13), + } + return nd +} + +// SetSqrtPriceX64 sets the "sqrtPriceX64" parameter. +func (inst *CreatePool) SetSqrtPriceX64(sqrtPriceX64 ag_binary.Uint128) *CreatePool { + inst.SqrtPriceX64 = &sqrtPriceX64 + return inst +} + +// SetOpenTime sets the "openTime" parameter. +func (inst *CreatePool) SetOpenTime(openTime uint64) *CreatePool { + inst.OpenTime = &openTime + return inst +} + +// SetPoolCreatorAccount sets the "poolCreator" account. +// Address paying to create the pool. Can be anyone +func (inst *CreatePool) SetPoolCreatorAccount(poolCreator ag_solanago.PublicKey) *CreatePool { + inst.AccountMetaSlice[0] = ag_solanago.Meta(poolCreator).WRITE().SIGNER() + return inst +} + +// GetPoolCreatorAccount gets the "poolCreator" account. +// Address paying to create the pool. Can be anyone +func (inst *CreatePool) GetPoolCreatorAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetAmmConfigAccount sets the "ammConfig" account. +// Which config the pool belongs to. +func (inst *CreatePool) SetAmmConfigAccount(ammConfig ag_solanago.PublicKey) *CreatePool { + inst.AccountMetaSlice[1] = ag_solanago.Meta(ammConfig) + return inst +} + +// GetAmmConfigAccount gets the "ammConfig" account. +// Which config the pool belongs to. +func (inst *CreatePool) GetAmmConfigAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetPoolStateAccount sets the "poolState" account. +// Initialize an account to store the pool state +func (inst *CreatePool) SetPoolStateAccount(poolState ag_solanago.PublicKey) *CreatePool { + inst.AccountMetaSlice[2] = ag_solanago.Meta(poolState).WRITE() + return inst +} + +// GetPoolStateAccount gets the "poolState" account. +// Initialize an account to store the pool state +func (inst *CreatePool) GetPoolStateAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetTokenMint0Account sets the "tokenMint0" account. +// Token_0 mint, the key must grater then token_1 mint. +func (inst *CreatePool) SetTokenMint0Account(tokenMint0 ag_solanago.PublicKey) *CreatePool { + inst.AccountMetaSlice[3] = ag_solanago.Meta(tokenMint0) + return inst +} + +// GetTokenMint0Account gets the "tokenMint0" account. +// Token_0 mint, the key must grater then token_1 mint. +func (inst *CreatePool) GetTokenMint0Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetTokenMint1Account sets the "tokenMint1" account. +// Token_1 mint +func (inst *CreatePool) SetTokenMint1Account(tokenMint1 ag_solanago.PublicKey) *CreatePool { + inst.AccountMetaSlice[4] = ag_solanago.Meta(tokenMint1) + return inst +} + +// GetTokenMint1Account gets the "tokenMint1" account. +// Token_1 mint +func (inst *CreatePool) GetTokenMint1Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetTokenVault0Account sets the "tokenVault0" account. +// Token_0 vault for the pool +func (inst *CreatePool) SetTokenVault0Account(tokenVault0 ag_solanago.PublicKey) *CreatePool { + inst.AccountMetaSlice[5] = ag_solanago.Meta(tokenVault0).WRITE() + return inst +} + +// GetTokenVault0Account gets the "tokenVault0" account. +// Token_0 vault for the pool +func (inst *CreatePool) GetTokenVault0Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetTokenVault1Account sets the "tokenVault1" account. +// Token_1 vault for the pool +func (inst *CreatePool) SetTokenVault1Account(tokenVault1 ag_solanago.PublicKey) *CreatePool { + inst.AccountMetaSlice[6] = ag_solanago.Meta(tokenVault1).WRITE() + return inst +} + +// GetTokenVault1Account gets the "tokenVault1" account. +// Token_1 vault for the pool +func (inst *CreatePool) GetTokenVault1Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetObservationStateAccount sets the "observationState" account. +func (inst *CreatePool) SetObservationStateAccount(observationState ag_solanago.PublicKey) *CreatePool { + inst.AccountMetaSlice[7] = ag_solanago.Meta(observationState) + return inst +} + +// GetObservationStateAccount gets the "observationState" account. +func (inst *CreatePool) GetObservationStateAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetTickArrayBitmapAccount sets the "tickArrayBitmap" account. +// Initialize an account to store if a tick array is initialized. +func (inst *CreatePool) SetTickArrayBitmapAccount(tickArrayBitmap ag_solanago.PublicKey) *CreatePool { + inst.AccountMetaSlice[8] = ag_solanago.Meta(tickArrayBitmap).WRITE() + return inst +} + +// GetTickArrayBitmapAccount gets the "tickArrayBitmap" account. +// Initialize an account to store if a tick array is initialized. +func (inst *CreatePool) GetTickArrayBitmapAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetTokenProgram0Account sets the "tokenProgram0" account. +// Spl token program or token program 2022 +func (inst *CreatePool) SetTokenProgram0Account(tokenProgram0 ag_solanago.PublicKey) *CreatePool { + inst.AccountMetaSlice[9] = ag_solanago.Meta(tokenProgram0) + return inst +} + +// GetTokenProgram0Account gets the "tokenProgram0" account. +// Spl token program or token program 2022 +func (inst *CreatePool) GetTokenProgram0Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetTokenProgram1Account sets the "tokenProgram1" account. +// Spl token program or token program 2022 +func (inst *CreatePool) SetTokenProgram1Account(tokenProgram1 ag_solanago.PublicKey) *CreatePool { + inst.AccountMetaSlice[10] = ag_solanago.Meta(tokenProgram1) + return inst +} + +// GetTokenProgram1Account gets the "tokenProgram1" account. +// Spl token program or token program 2022 +func (inst *CreatePool) GetTokenProgram1Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +// To create a new program account +func (inst *CreatePool) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *CreatePool { + inst.AccountMetaSlice[11] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +// To create a new program account +func (inst *CreatePool) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetRentAccount sets the "rent" account. +// Sysvar for program account +func (inst *CreatePool) SetRentAccount(rent ag_solanago.PublicKey) *CreatePool { + inst.AccountMetaSlice[12] = ag_solanago.Meta(rent) + return inst +} + +// GetRentAccount gets the "rent" account. +// Sysvar for program account +func (inst *CreatePool) GetRentAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +func (inst CreatePool) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_CreatePool, + }} +} + +// 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 CreatePool) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *CreatePool) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.SqrtPriceX64 == nil { + return errors.New("SqrtPriceX64 parameter is not set") + } + if inst.OpenTime == nil { + return errors.New("OpenTime parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.PoolCreator is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.AmmConfig is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.PoolState is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.TokenMint0 is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.TokenMint1 is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.TokenVault0 is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.TokenVault1 is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.ObservationState is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.TickArrayBitmap is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.TokenProgram0 is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.TokenProgram1 is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.SystemProgram is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.Rent is not set") + } + } + return nil +} + +func (inst *CreatePool) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("CreatePool")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=2]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param("SqrtPriceX64", *inst.SqrtPriceX64)) + paramsBranch.Child(ag_format.Param(" OpenTime", *inst.OpenTime)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=13]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" poolCreator", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" ammConfig", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" poolState", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" tokenMint0", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" tokenMint1", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" tokenVault0", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" tokenVault1", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta("observationState", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" tickArrayBitmap", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" tokenProgram0", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" tokenProgram1", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" systemProgram", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" rent", inst.AccountMetaSlice.Get(12))) + }) + }) + }) +} + +func (obj CreatePool) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `SqrtPriceX64` param: + err = encoder.Encode(obj.SqrtPriceX64) + if err != nil { + return err + } + // Serialize `OpenTime` param: + err = encoder.Encode(obj.OpenTime) + if err != nil { + return err + } + return nil +} +func (obj *CreatePool) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `SqrtPriceX64`: + err = decoder.Decode(&obj.SqrtPriceX64) + if err != nil { + return err + } + // Deserialize `OpenTime`: + err = decoder.Decode(&obj.OpenTime) + if err != nil { + return err + } + return nil +} + +// NewCreatePoolInstruction declares a new CreatePool instruction with the provided parameters and accounts. +func NewCreatePoolInstruction( + // Parameters: + sqrtPriceX64 ag_binary.Uint128, + openTime uint64, + // Accounts: + poolCreator ag_solanago.PublicKey, + ammConfig ag_solanago.PublicKey, + poolState ag_solanago.PublicKey, + tokenMint0 ag_solanago.PublicKey, + tokenMint1 ag_solanago.PublicKey, + tokenVault0 ag_solanago.PublicKey, + tokenVault1 ag_solanago.PublicKey, + observationState ag_solanago.PublicKey, + tickArrayBitmap ag_solanago.PublicKey, + tokenProgram0 ag_solanago.PublicKey, + tokenProgram1 ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey, + rent ag_solanago.PublicKey) *CreatePool { + return NewCreatePoolInstructionBuilder(). + SetSqrtPriceX64(sqrtPriceX64). + SetOpenTime(openTime). + SetPoolCreatorAccount(poolCreator). + SetAmmConfigAccount(ammConfig). + SetPoolStateAccount(poolState). + SetTokenMint0Account(tokenMint0). + SetTokenMint1Account(tokenMint1). + SetTokenVault0Account(tokenVault0). + SetTokenVault1Account(tokenVault1). + SetObservationStateAccount(observationState). + SetTickArrayBitmapAccount(tickArrayBitmap). + SetTokenProgram0Account(tokenProgram0). + SetTokenProgram1Account(tokenProgram1). + SetSystemProgramAccount(systemProgram). + SetRentAccount(rent) +} diff --git a/programs/raydiumclmm/CreatePool_test.go b/programs/raydiumclmm/CreatePool_test.go new file mode 100644 index 00000000..4c29e6ef --- /dev/null +++ b/programs/raydiumclmm/CreatePool_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_CreatePool(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("CreatePool"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(CreatePool) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(CreatePool) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/raydiumclmm/DecreaseLiquidity.go b/programs/raydiumclmm/DecreaseLiquidity.go new file mode 100644 index 00000000..c789310b --- /dev/null +++ b/programs/raydiumclmm/DecreaseLiquidity.go @@ -0,0 +1,420 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "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" +) + +// Decreases liquidity with a exist position +// +// # Arguments +// +// * `ctx` - The context of accounts +// * `liquidity` - The amount by which liquidity will be decreased +// * `amount_0_min` - The minimum amount of token_0 that should be accounted for the burned liquidity +// * `amount_1_min` - The minimum amount of token_1 that should be accounted for the burned liquidity +// +type DecreaseLiquidity struct { + Liquidity *ag_binary.Uint128 + Amount0Min *uint64 + Amount1Min *uint64 + + // [0] = [SIGNER] nftOwner + // ··········· The position owner or delegated authority + // + // [1] = [] nftAccount + // ··········· The token account for the tokenized position + // + // [2] = [WRITE] personalPosition + // ··········· Decrease liquidity for this position + // + // [3] = [WRITE] poolState + // + // [4] = [WRITE] protocolPosition + // + // [5] = [WRITE] tokenVault0 + // ··········· Token_0 vault + // + // [6] = [WRITE] tokenVault1 + // ··········· Token_1 vault + // + // [7] = [WRITE] tickArrayLower + // ··········· Stores init state for the lower tick + // + // [8] = [WRITE] tickArrayUpper + // ··········· Stores init state for the upper tick + // + // [9] = [WRITE] recipientTokenAccount0 + // ··········· The destination token account for receive amount_0 + // + // [10] = [WRITE] recipientTokenAccount1 + // ··········· The destination token account for receive amount_1 + // + // [11] = [] tokenProgram + // ··········· SPL program to transfer out tokens + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewDecreaseLiquidityInstructionBuilder creates a new `DecreaseLiquidity` instruction builder. +func NewDecreaseLiquidityInstructionBuilder() *DecreaseLiquidity { + nd := &DecreaseLiquidity{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 12), + } + return nd +} + +// SetLiquidity sets the "liquidity" parameter. +func (inst *DecreaseLiquidity) SetLiquidity(liquidity ag_binary.Uint128) *DecreaseLiquidity { + inst.Liquidity = &liquidity + return inst +} + +// SetAmount0Min sets the "amount0Min" parameter. +func (inst *DecreaseLiquidity) SetAmount0Min(amount0Min uint64) *DecreaseLiquidity { + inst.Amount0Min = &amount0Min + return inst +} + +// SetAmount1Min sets the "amount1Min" parameter. +func (inst *DecreaseLiquidity) SetAmount1Min(amount1Min uint64) *DecreaseLiquidity { + inst.Amount1Min = &amount1Min + return inst +} + +// SetNftOwnerAccount sets the "nftOwner" account. +// The position owner or delegated authority +func (inst *DecreaseLiquidity) SetNftOwnerAccount(nftOwner ag_solanago.PublicKey) *DecreaseLiquidity { + inst.AccountMetaSlice[0] = ag_solanago.Meta(nftOwner).SIGNER() + return inst +} + +// GetNftOwnerAccount gets the "nftOwner" account. +// The position owner or delegated authority +func (inst *DecreaseLiquidity) GetNftOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetNftAccountAccount sets the "nftAccount" account. +// The token account for the tokenized position +func (inst *DecreaseLiquidity) SetNftAccountAccount(nftAccount ag_solanago.PublicKey) *DecreaseLiquidity { + inst.AccountMetaSlice[1] = ag_solanago.Meta(nftAccount) + return inst +} + +// GetNftAccountAccount gets the "nftAccount" account. +// The token account for the tokenized position +func (inst *DecreaseLiquidity) GetNftAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetPersonalPositionAccount sets the "personalPosition" account. +// Decrease liquidity for this position +func (inst *DecreaseLiquidity) SetPersonalPositionAccount(personalPosition ag_solanago.PublicKey) *DecreaseLiquidity { + inst.AccountMetaSlice[2] = ag_solanago.Meta(personalPosition).WRITE() + return inst +} + +// GetPersonalPositionAccount gets the "personalPosition" account. +// Decrease liquidity for this position +func (inst *DecreaseLiquidity) GetPersonalPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetPoolStateAccount sets the "poolState" account. +func (inst *DecreaseLiquidity) SetPoolStateAccount(poolState ag_solanago.PublicKey) *DecreaseLiquidity { + inst.AccountMetaSlice[3] = ag_solanago.Meta(poolState).WRITE() + return inst +} + +// GetPoolStateAccount gets the "poolState" account. +func (inst *DecreaseLiquidity) GetPoolStateAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetProtocolPositionAccount sets the "protocolPosition" account. +func (inst *DecreaseLiquidity) SetProtocolPositionAccount(protocolPosition ag_solanago.PublicKey) *DecreaseLiquidity { + inst.AccountMetaSlice[4] = ag_solanago.Meta(protocolPosition).WRITE() + return inst +} + +// GetProtocolPositionAccount gets the "protocolPosition" account. +func (inst *DecreaseLiquidity) GetProtocolPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetTokenVault0Account sets the "tokenVault0" account. +// Token_0 vault +func (inst *DecreaseLiquidity) SetTokenVault0Account(tokenVault0 ag_solanago.PublicKey) *DecreaseLiquidity { + inst.AccountMetaSlice[5] = ag_solanago.Meta(tokenVault0).WRITE() + return inst +} + +// GetTokenVault0Account gets the "tokenVault0" account. +// Token_0 vault +func (inst *DecreaseLiquidity) GetTokenVault0Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetTokenVault1Account sets the "tokenVault1" account. +// Token_1 vault +func (inst *DecreaseLiquidity) SetTokenVault1Account(tokenVault1 ag_solanago.PublicKey) *DecreaseLiquidity { + inst.AccountMetaSlice[6] = ag_solanago.Meta(tokenVault1).WRITE() + return inst +} + +// GetTokenVault1Account gets the "tokenVault1" account. +// Token_1 vault +func (inst *DecreaseLiquidity) GetTokenVault1Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetTickArrayLowerAccount sets the "tickArrayLower" account. +// Stores init state for the lower tick +func (inst *DecreaseLiquidity) SetTickArrayLowerAccount(tickArrayLower ag_solanago.PublicKey) *DecreaseLiquidity { + inst.AccountMetaSlice[7] = ag_solanago.Meta(tickArrayLower).WRITE() + return inst +} + +// GetTickArrayLowerAccount gets the "tickArrayLower" account. +// Stores init state for the lower tick +func (inst *DecreaseLiquidity) GetTickArrayLowerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetTickArrayUpperAccount sets the "tickArrayUpper" account. +// Stores init state for the upper tick +func (inst *DecreaseLiquidity) SetTickArrayUpperAccount(tickArrayUpper ag_solanago.PublicKey) *DecreaseLiquidity { + inst.AccountMetaSlice[8] = ag_solanago.Meta(tickArrayUpper).WRITE() + return inst +} + +// GetTickArrayUpperAccount gets the "tickArrayUpper" account. +// Stores init state for the upper tick +func (inst *DecreaseLiquidity) GetTickArrayUpperAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetRecipientTokenAccount0Account sets the "recipientTokenAccount0" account. +// The destination token account for receive amount_0 +func (inst *DecreaseLiquidity) SetRecipientTokenAccount0Account(recipientTokenAccount0 ag_solanago.PublicKey) *DecreaseLiquidity { + inst.AccountMetaSlice[9] = ag_solanago.Meta(recipientTokenAccount0).WRITE() + return inst +} + +// GetRecipientTokenAccount0Account gets the "recipientTokenAccount0" account. +// The destination token account for receive amount_0 +func (inst *DecreaseLiquidity) GetRecipientTokenAccount0Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetRecipientTokenAccount1Account sets the "recipientTokenAccount1" account. +// The destination token account for receive amount_1 +func (inst *DecreaseLiquidity) SetRecipientTokenAccount1Account(recipientTokenAccount1 ag_solanago.PublicKey) *DecreaseLiquidity { + inst.AccountMetaSlice[10] = ag_solanago.Meta(recipientTokenAccount1).WRITE() + return inst +} + +// GetRecipientTokenAccount1Account gets the "recipientTokenAccount1" account. +// The destination token account for receive amount_1 +func (inst *DecreaseLiquidity) GetRecipientTokenAccount1Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +// SPL program to transfer out tokens +func (inst *DecreaseLiquidity) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *DecreaseLiquidity { + inst.AccountMetaSlice[11] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +// SPL program to transfer out tokens +func (inst *DecreaseLiquidity) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +func (inst DecreaseLiquidity) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_DecreaseLiquidity, + }} +} + +// 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 DecreaseLiquidity) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *DecreaseLiquidity) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.Liquidity == nil { + return errors.New("Liquidity parameter is not set") + } + if inst.Amount0Min == nil { + return errors.New("Amount0Min parameter is not set") + } + if inst.Amount1Min == nil { + return errors.New("Amount1Min parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.NftOwner is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.NftAccount is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.PersonalPosition is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.PoolState is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.ProtocolPosition is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.TokenVault0 is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.TokenVault1 is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.TickArrayLower is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.TickArrayUpper is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.RecipientTokenAccount0 is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.RecipientTokenAccount1 is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.TokenProgram is not set") + } + } + return nil +} + +func (inst *DecreaseLiquidity) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("DecreaseLiquidity")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=3]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" Liquidity", *inst.Liquidity)) + paramsBranch.Child(ag_format.Param("Amount0Min", *inst.Amount0Min)) + paramsBranch.Child(ag_format.Param("Amount1Min", *inst.Amount1Min)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=12]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" nftOwner", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" nft", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" personalPosition", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" poolState", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" protocolPosition", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" tokenVault0", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" tokenVault1", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" tickArrayLower", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" tickArrayUpper", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta("recipientTokenAccount0", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta("recipientTokenAccount1", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(11))) + }) + }) + }) +} + +func (obj DecreaseLiquidity) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Liquidity` param: + err = encoder.Encode(obj.Liquidity) + if err != nil { + return err + } + // Serialize `Amount0Min` param: + err = encoder.Encode(obj.Amount0Min) + if err != nil { + return err + } + // Serialize `Amount1Min` param: + err = encoder.Encode(obj.Amount1Min) + if err != nil { + return err + } + return nil +} +func (obj *DecreaseLiquidity) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Liquidity`: + err = decoder.Decode(&obj.Liquidity) + if err != nil { + return err + } + // Deserialize `Amount0Min`: + err = decoder.Decode(&obj.Amount0Min) + if err != nil { + return err + } + // Deserialize `Amount1Min`: + err = decoder.Decode(&obj.Amount1Min) + if err != nil { + return err + } + return nil +} + +// NewDecreaseLiquidityInstruction declares a new DecreaseLiquidity instruction with the provided parameters and accounts. +func NewDecreaseLiquidityInstruction( + // Parameters: + liquidity ag_binary.Uint128, + amount0Min uint64, + amount1Min uint64, + // Accounts: + nftOwner ag_solanago.PublicKey, + nftAccount ag_solanago.PublicKey, + personalPosition ag_solanago.PublicKey, + poolState ag_solanago.PublicKey, + protocolPosition ag_solanago.PublicKey, + tokenVault0 ag_solanago.PublicKey, + tokenVault1 ag_solanago.PublicKey, + tickArrayLower ag_solanago.PublicKey, + tickArrayUpper ag_solanago.PublicKey, + recipientTokenAccount0 ag_solanago.PublicKey, + recipientTokenAccount1 ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey) *DecreaseLiquidity { + return NewDecreaseLiquidityInstructionBuilder(). + SetLiquidity(liquidity). + SetAmount0Min(amount0Min). + SetAmount1Min(amount1Min). + SetNftOwnerAccount(nftOwner). + SetNftAccountAccount(nftAccount). + SetPersonalPositionAccount(personalPosition). + SetPoolStateAccount(poolState). + SetProtocolPositionAccount(protocolPosition). + SetTokenVault0Account(tokenVault0). + SetTokenVault1Account(tokenVault1). + SetTickArrayLowerAccount(tickArrayLower). + SetTickArrayUpperAccount(tickArrayUpper). + SetRecipientTokenAccount0Account(recipientTokenAccount0). + SetRecipientTokenAccount1Account(recipientTokenAccount1). + SetTokenProgramAccount(tokenProgram) +} diff --git a/programs/raydiumclmm/DecreaseLiquidityV2.go b/programs/raydiumclmm/DecreaseLiquidityV2.go new file mode 100644 index 00000000..814a1d8f --- /dev/null +++ b/programs/raydiumclmm/DecreaseLiquidityV2.go @@ -0,0 +1,508 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "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" +) + +// Decreases liquidity with a exist position, support Token2022 +// +// # Arguments +// +// * `ctx` - The context of accounts +// * `liquidity` - The amount by which liquidity will be decreased +// * `amount_0_min` - The minimum amount of token_0 that should be accounted for the burned liquidity +// * `amount_1_min` - The minimum amount of token_1 that should be accounted for the burned liquidity +// +type DecreaseLiquidityV2 struct { + Liquidity *ag_binary.Uint128 + Amount0Min *uint64 + Amount1Min *uint64 + + // [0] = [SIGNER] nftOwner + // ··········· The position owner or delegated authority + // + // [1] = [] nftAccount + // ··········· The token account for the tokenized position + // + // [2] = [WRITE] personalPosition + // ··········· Decrease liquidity for this position + // + // [3] = [WRITE] poolState + // + // [4] = [WRITE] protocolPosition + // + // [5] = [WRITE] tokenVault0 + // ··········· Token_0 vault + // + // [6] = [WRITE] tokenVault1 + // ··········· Token_1 vault + // + // [7] = [WRITE] tickArrayLower + // ··········· Stores init state for the lower tick + // + // [8] = [WRITE] tickArrayUpper + // ··········· Stores init state for the upper tick + // + // [9] = [WRITE] recipientTokenAccount0 + // ··········· The destination token account for receive amount_0 + // + // [10] = [WRITE] recipientTokenAccount1 + // ··········· The destination token account for receive amount_1 + // + // [11] = [] tokenProgram + // ··········· SPL program to transfer out tokens + // + // [12] = [] tokenProgram2022 + // ··········· Token program 2022 + // + // [13] = [] memoProgram + // ··········· memo program + // + // [14] = [] vault0Mint + // ··········· The mint of token vault 0 + // + // [15] = [] vault1Mint + // ··········· The mint of token vault 1 + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewDecreaseLiquidityV2InstructionBuilder creates a new `DecreaseLiquidityV2` instruction builder. +func NewDecreaseLiquidityV2InstructionBuilder() *DecreaseLiquidityV2 { + nd := &DecreaseLiquidityV2{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 16), + } + return nd +} + +// SetLiquidity sets the "liquidity" parameter. +func (inst *DecreaseLiquidityV2) SetLiquidity(liquidity ag_binary.Uint128) *DecreaseLiquidityV2 { + inst.Liquidity = &liquidity + return inst +} + +// SetAmount0Min sets the "amount0Min" parameter. +func (inst *DecreaseLiquidityV2) SetAmount0Min(amount0Min uint64) *DecreaseLiquidityV2 { + inst.Amount0Min = &amount0Min + return inst +} + +// SetAmount1Min sets the "amount1Min" parameter. +func (inst *DecreaseLiquidityV2) SetAmount1Min(amount1Min uint64) *DecreaseLiquidityV2 { + inst.Amount1Min = &amount1Min + return inst +} + +// SetNftOwnerAccount sets the "nftOwner" account. +// The position owner or delegated authority +func (inst *DecreaseLiquidityV2) SetNftOwnerAccount(nftOwner ag_solanago.PublicKey) *DecreaseLiquidityV2 { + inst.AccountMetaSlice[0] = ag_solanago.Meta(nftOwner).SIGNER() + return inst +} + +// GetNftOwnerAccount gets the "nftOwner" account. +// The position owner or delegated authority +func (inst *DecreaseLiquidityV2) GetNftOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetNftAccountAccount sets the "nftAccount" account. +// The token account for the tokenized position +func (inst *DecreaseLiquidityV2) SetNftAccountAccount(nftAccount ag_solanago.PublicKey) *DecreaseLiquidityV2 { + inst.AccountMetaSlice[1] = ag_solanago.Meta(nftAccount) + return inst +} + +// GetNftAccountAccount gets the "nftAccount" account. +// The token account for the tokenized position +func (inst *DecreaseLiquidityV2) GetNftAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetPersonalPositionAccount sets the "personalPosition" account. +// Decrease liquidity for this position +func (inst *DecreaseLiquidityV2) SetPersonalPositionAccount(personalPosition ag_solanago.PublicKey) *DecreaseLiquidityV2 { + inst.AccountMetaSlice[2] = ag_solanago.Meta(personalPosition).WRITE() + return inst +} + +// GetPersonalPositionAccount gets the "personalPosition" account. +// Decrease liquidity for this position +func (inst *DecreaseLiquidityV2) GetPersonalPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetPoolStateAccount sets the "poolState" account. +func (inst *DecreaseLiquidityV2) SetPoolStateAccount(poolState ag_solanago.PublicKey) *DecreaseLiquidityV2 { + inst.AccountMetaSlice[3] = ag_solanago.Meta(poolState).WRITE() + return inst +} + +// GetPoolStateAccount gets the "poolState" account. +func (inst *DecreaseLiquidityV2) GetPoolStateAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetProtocolPositionAccount sets the "protocolPosition" account. +func (inst *DecreaseLiquidityV2) SetProtocolPositionAccount(protocolPosition ag_solanago.PublicKey) *DecreaseLiquidityV2 { + inst.AccountMetaSlice[4] = ag_solanago.Meta(protocolPosition).WRITE() + return inst +} + +// GetProtocolPositionAccount gets the "protocolPosition" account. +func (inst *DecreaseLiquidityV2) GetProtocolPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetTokenVault0Account sets the "tokenVault0" account. +// Token_0 vault +func (inst *DecreaseLiquidityV2) SetTokenVault0Account(tokenVault0 ag_solanago.PublicKey) *DecreaseLiquidityV2 { + inst.AccountMetaSlice[5] = ag_solanago.Meta(tokenVault0).WRITE() + return inst +} + +// GetTokenVault0Account gets the "tokenVault0" account. +// Token_0 vault +func (inst *DecreaseLiquidityV2) GetTokenVault0Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetTokenVault1Account sets the "tokenVault1" account. +// Token_1 vault +func (inst *DecreaseLiquidityV2) SetTokenVault1Account(tokenVault1 ag_solanago.PublicKey) *DecreaseLiquidityV2 { + inst.AccountMetaSlice[6] = ag_solanago.Meta(tokenVault1).WRITE() + return inst +} + +// GetTokenVault1Account gets the "tokenVault1" account. +// Token_1 vault +func (inst *DecreaseLiquidityV2) GetTokenVault1Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetTickArrayLowerAccount sets the "tickArrayLower" account. +// Stores init state for the lower tick +func (inst *DecreaseLiquidityV2) SetTickArrayLowerAccount(tickArrayLower ag_solanago.PublicKey) *DecreaseLiquidityV2 { + inst.AccountMetaSlice[7] = ag_solanago.Meta(tickArrayLower).WRITE() + return inst +} + +// GetTickArrayLowerAccount gets the "tickArrayLower" account. +// Stores init state for the lower tick +func (inst *DecreaseLiquidityV2) GetTickArrayLowerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetTickArrayUpperAccount sets the "tickArrayUpper" account. +// Stores init state for the upper tick +func (inst *DecreaseLiquidityV2) SetTickArrayUpperAccount(tickArrayUpper ag_solanago.PublicKey) *DecreaseLiquidityV2 { + inst.AccountMetaSlice[8] = ag_solanago.Meta(tickArrayUpper).WRITE() + return inst +} + +// GetTickArrayUpperAccount gets the "tickArrayUpper" account. +// Stores init state for the upper tick +func (inst *DecreaseLiquidityV2) GetTickArrayUpperAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetRecipientTokenAccount0Account sets the "recipientTokenAccount0" account. +// The destination token account for receive amount_0 +func (inst *DecreaseLiquidityV2) SetRecipientTokenAccount0Account(recipientTokenAccount0 ag_solanago.PublicKey) *DecreaseLiquidityV2 { + inst.AccountMetaSlice[9] = ag_solanago.Meta(recipientTokenAccount0).WRITE() + return inst +} + +// GetRecipientTokenAccount0Account gets the "recipientTokenAccount0" account. +// The destination token account for receive amount_0 +func (inst *DecreaseLiquidityV2) GetRecipientTokenAccount0Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetRecipientTokenAccount1Account sets the "recipientTokenAccount1" account. +// The destination token account for receive amount_1 +func (inst *DecreaseLiquidityV2) SetRecipientTokenAccount1Account(recipientTokenAccount1 ag_solanago.PublicKey) *DecreaseLiquidityV2 { + inst.AccountMetaSlice[10] = ag_solanago.Meta(recipientTokenAccount1).WRITE() + return inst +} + +// GetRecipientTokenAccount1Account gets the "recipientTokenAccount1" account. +// The destination token account for receive amount_1 +func (inst *DecreaseLiquidityV2) GetRecipientTokenAccount1Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +// SPL program to transfer out tokens +func (inst *DecreaseLiquidityV2) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *DecreaseLiquidityV2 { + inst.AccountMetaSlice[11] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +// SPL program to transfer out tokens +func (inst *DecreaseLiquidityV2) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetTokenProgram2022Account sets the "tokenProgram2022" account. +// Token program 2022 +func (inst *DecreaseLiquidityV2) SetTokenProgram2022Account(tokenProgram2022 ag_solanago.PublicKey) *DecreaseLiquidityV2 { + inst.AccountMetaSlice[12] = ag_solanago.Meta(tokenProgram2022) + return inst +} + +// GetTokenProgram2022Account gets the "tokenProgram2022" account. +// Token program 2022 +func (inst *DecreaseLiquidityV2) GetTokenProgram2022Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetMemoProgramAccount sets the "memoProgram" account. +// memo program +func (inst *DecreaseLiquidityV2) SetMemoProgramAccount(memoProgram ag_solanago.PublicKey) *DecreaseLiquidityV2 { + inst.AccountMetaSlice[13] = ag_solanago.Meta(memoProgram) + return inst +} + +// GetMemoProgramAccount gets the "memoProgram" account. +// memo program +func (inst *DecreaseLiquidityV2) GetMemoProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetVault0MintAccount sets the "vault0Mint" account. +// The mint of token vault 0 +func (inst *DecreaseLiquidityV2) SetVault0MintAccount(vault0Mint ag_solanago.PublicKey) *DecreaseLiquidityV2 { + inst.AccountMetaSlice[14] = ag_solanago.Meta(vault0Mint) + return inst +} + +// GetVault0MintAccount gets the "vault0Mint" account. +// The mint of token vault 0 +func (inst *DecreaseLiquidityV2) GetVault0MintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +// SetVault1MintAccount sets the "vault1Mint" account. +// The mint of token vault 1 +func (inst *DecreaseLiquidityV2) SetVault1MintAccount(vault1Mint ag_solanago.PublicKey) *DecreaseLiquidityV2 { + inst.AccountMetaSlice[15] = ag_solanago.Meta(vault1Mint) + return inst +} + +// GetVault1MintAccount gets the "vault1Mint" account. +// The mint of token vault 1 +func (inst *DecreaseLiquidityV2) GetVault1MintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(15) +} + +func (inst DecreaseLiquidityV2) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_DecreaseLiquidityV2, + }} +} + +// 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 DecreaseLiquidityV2) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *DecreaseLiquidityV2) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.Liquidity == nil { + return errors.New("Liquidity parameter is not set") + } + if inst.Amount0Min == nil { + return errors.New("Amount0Min parameter is not set") + } + if inst.Amount1Min == nil { + return errors.New("Amount1Min parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.NftOwner is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.NftAccount is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.PersonalPosition is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.PoolState is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.ProtocolPosition is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.TokenVault0 is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.TokenVault1 is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.TickArrayLower is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.TickArrayUpper is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.RecipientTokenAccount0 is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.RecipientTokenAccount1 is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.TokenProgram2022 is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.MemoProgram is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.Vault0Mint is not set") + } + if inst.AccountMetaSlice[15] == nil { + return errors.New("accounts.Vault1Mint is not set") + } + } + return nil +} + +func (inst *DecreaseLiquidityV2) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("DecreaseLiquidityV2")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=3]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" Liquidity", *inst.Liquidity)) + paramsBranch.Child(ag_format.Param("Amount0Min", *inst.Amount0Min)) + paramsBranch.Child(ag_format.Param("Amount1Min", *inst.Amount1Min)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=16]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" nftOwner", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" nft", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" personalPosition", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" poolState", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" protocolPosition", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" tokenVault0", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" tokenVault1", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" tickArrayLower", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" tickArrayUpper", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta("recipientTokenAccount0", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta("recipientTokenAccount1", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" tokenProgram2022", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" memoProgram", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta(" vault0Mint", inst.AccountMetaSlice.Get(14))) + accountsBranch.Child(ag_format.Meta(" vault1Mint", inst.AccountMetaSlice.Get(15))) + }) + }) + }) +} + +func (obj DecreaseLiquidityV2) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Liquidity` param: + err = encoder.Encode(obj.Liquidity) + if err != nil { + return err + } + // Serialize `Amount0Min` param: + err = encoder.Encode(obj.Amount0Min) + if err != nil { + return err + } + // Serialize `Amount1Min` param: + err = encoder.Encode(obj.Amount1Min) + if err != nil { + return err + } + return nil +} +func (obj *DecreaseLiquidityV2) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Liquidity`: + err = decoder.Decode(&obj.Liquidity) + if err != nil { + return err + } + // Deserialize `Amount0Min`: + err = decoder.Decode(&obj.Amount0Min) + if err != nil { + return err + } + // Deserialize `Amount1Min`: + err = decoder.Decode(&obj.Amount1Min) + if err != nil { + return err + } + return nil +} + +// NewDecreaseLiquidityV2Instruction declares a new DecreaseLiquidityV2 instruction with the provided parameters and accounts. +func NewDecreaseLiquidityV2Instruction( + // Parameters: + liquidity ag_binary.Uint128, + amount0Min uint64, + amount1Min uint64, + // Accounts: + nftOwner ag_solanago.PublicKey, + nftAccount ag_solanago.PublicKey, + personalPosition ag_solanago.PublicKey, + poolState ag_solanago.PublicKey, + protocolPosition ag_solanago.PublicKey, + tokenVault0 ag_solanago.PublicKey, + tokenVault1 ag_solanago.PublicKey, + tickArrayLower ag_solanago.PublicKey, + tickArrayUpper ag_solanago.PublicKey, + recipientTokenAccount0 ag_solanago.PublicKey, + recipientTokenAccount1 ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + tokenProgram2022 ag_solanago.PublicKey, + memoProgram ag_solanago.PublicKey, + vault0Mint ag_solanago.PublicKey, + vault1Mint ag_solanago.PublicKey) *DecreaseLiquidityV2 { + return NewDecreaseLiquidityV2InstructionBuilder(). + SetLiquidity(liquidity). + SetAmount0Min(amount0Min). + SetAmount1Min(amount1Min). + SetNftOwnerAccount(nftOwner). + SetNftAccountAccount(nftAccount). + SetPersonalPositionAccount(personalPosition). + SetPoolStateAccount(poolState). + SetProtocolPositionAccount(protocolPosition). + SetTokenVault0Account(tokenVault0). + SetTokenVault1Account(tokenVault1). + SetTickArrayLowerAccount(tickArrayLower). + SetTickArrayUpperAccount(tickArrayUpper). + SetRecipientTokenAccount0Account(recipientTokenAccount0). + SetRecipientTokenAccount1Account(recipientTokenAccount1). + SetTokenProgramAccount(tokenProgram). + SetTokenProgram2022Account(tokenProgram2022). + SetMemoProgramAccount(memoProgram). + SetVault0MintAccount(vault0Mint). + SetVault1MintAccount(vault1Mint) +} diff --git a/programs/raydiumclmm/DecreaseLiquidityV2_test.go b/programs/raydiumclmm/DecreaseLiquidityV2_test.go new file mode 100644 index 00000000..8588c44b --- /dev/null +++ b/programs/raydiumclmm/DecreaseLiquidityV2_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_DecreaseLiquidityV2(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("DecreaseLiquidityV2"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(DecreaseLiquidityV2) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(DecreaseLiquidityV2) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/raydiumclmm/DecreaseLiquidity_test.go b/programs/raydiumclmm/DecreaseLiquidity_test.go new file mode 100644 index 00000000..299b7c0b --- /dev/null +++ b/programs/raydiumclmm/DecreaseLiquidity_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_DecreaseLiquidity(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("DecreaseLiquidity"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(DecreaseLiquidity) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(DecreaseLiquidity) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/raydiumclmm/IncreaseLiquidity.go b/programs/raydiumclmm/IncreaseLiquidity.go new file mode 100644 index 00000000..7408c541 --- /dev/null +++ b/programs/raydiumclmm/IncreaseLiquidity.go @@ -0,0 +1,420 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "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" +) + +// Increases liquidity with a exist position, with amount paid by `payer` +// +// # Arguments +// +// * `ctx` - The context of accounts +// * `liquidity` - The desired liquidity to be added, can't be zero +// * `amount_0_max` - The max amount of token_0 to spend, which serves as a slippage check +// * `amount_1_max` - The max amount of token_1 to spend, which serves as a slippage check +// +type IncreaseLiquidity struct { + Liquidity *ag_binary.Uint128 + Amount0Max *uint64 + Amount1Max *uint64 + + // [0] = [SIGNER] nftOwner + // ··········· Pays to mint the position + // + // [1] = [] nftAccount + // ··········· The token account for nft + // + // [2] = [WRITE] poolState + // + // [3] = [WRITE] protocolPosition + // + // [4] = [WRITE] personalPosition + // ··········· Increase liquidity for this position + // + // [5] = [WRITE] tickArrayLower + // ··········· Stores init state for the lower tick + // + // [6] = [WRITE] tickArrayUpper + // ··········· Stores init state for the upper tick + // + // [7] = [WRITE] tokenAccount0 + // ··········· The payer's token account for token_0 + // + // [8] = [WRITE] tokenAccount1 + // ··········· The token account spending token_1 to mint the position + // + // [9] = [WRITE] tokenVault0 + // ··········· The address that holds pool tokens for token_0 + // + // [10] = [WRITE] tokenVault1 + // ··········· The address that holds pool tokens for token_1 + // + // [11] = [] tokenProgram + // ··········· Program to create mint account and mint tokens + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewIncreaseLiquidityInstructionBuilder creates a new `IncreaseLiquidity` instruction builder. +func NewIncreaseLiquidityInstructionBuilder() *IncreaseLiquidity { + nd := &IncreaseLiquidity{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 12), + } + return nd +} + +// SetLiquidity sets the "liquidity" parameter. +func (inst *IncreaseLiquidity) SetLiquidity(liquidity ag_binary.Uint128) *IncreaseLiquidity { + inst.Liquidity = &liquidity + return inst +} + +// SetAmount0Max sets the "amount0Max" parameter. +func (inst *IncreaseLiquidity) SetAmount0Max(amount0Max uint64) *IncreaseLiquidity { + inst.Amount0Max = &amount0Max + return inst +} + +// SetAmount1Max sets the "amount1Max" parameter. +func (inst *IncreaseLiquidity) SetAmount1Max(amount1Max uint64) *IncreaseLiquidity { + inst.Amount1Max = &amount1Max + return inst +} + +// SetNftOwnerAccount sets the "nftOwner" account. +// Pays to mint the position +func (inst *IncreaseLiquidity) SetNftOwnerAccount(nftOwner ag_solanago.PublicKey) *IncreaseLiquidity { + inst.AccountMetaSlice[0] = ag_solanago.Meta(nftOwner).SIGNER() + return inst +} + +// GetNftOwnerAccount gets the "nftOwner" account. +// Pays to mint the position +func (inst *IncreaseLiquidity) GetNftOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetNftAccountAccount sets the "nftAccount" account. +// The token account for nft +func (inst *IncreaseLiquidity) SetNftAccountAccount(nftAccount ag_solanago.PublicKey) *IncreaseLiquidity { + inst.AccountMetaSlice[1] = ag_solanago.Meta(nftAccount) + return inst +} + +// GetNftAccountAccount gets the "nftAccount" account. +// The token account for nft +func (inst *IncreaseLiquidity) GetNftAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetPoolStateAccount sets the "poolState" account. +func (inst *IncreaseLiquidity) SetPoolStateAccount(poolState ag_solanago.PublicKey) *IncreaseLiquidity { + inst.AccountMetaSlice[2] = ag_solanago.Meta(poolState).WRITE() + return inst +} + +// GetPoolStateAccount gets the "poolState" account. +func (inst *IncreaseLiquidity) GetPoolStateAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetProtocolPositionAccount sets the "protocolPosition" account. +func (inst *IncreaseLiquidity) SetProtocolPositionAccount(protocolPosition ag_solanago.PublicKey) *IncreaseLiquidity { + inst.AccountMetaSlice[3] = ag_solanago.Meta(protocolPosition).WRITE() + return inst +} + +// GetProtocolPositionAccount gets the "protocolPosition" account. +func (inst *IncreaseLiquidity) GetProtocolPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetPersonalPositionAccount sets the "personalPosition" account. +// Increase liquidity for this position +func (inst *IncreaseLiquidity) SetPersonalPositionAccount(personalPosition ag_solanago.PublicKey) *IncreaseLiquidity { + inst.AccountMetaSlice[4] = ag_solanago.Meta(personalPosition).WRITE() + return inst +} + +// GetPersonalPositionAccount gets the "personalPosition" account. +// Increase liquidity for this position +func (inst *IncreaseLiquidity) GetPersonalPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetTickArrayLowerAccount sets the "tickArrayLower" account. +// Stores init state for the lower tick +func (inst *IncreaseLiquidity) SetTickArrayLowerAccount(tickArrayLower ag_solanago.PublicKey) *IncreaseLiquidity { + inst.AccountMetaSlice[5] = ag_solanago.Meta(tickArrayLower).WRITE() + return inst +} + +// GetTickArrayLowerAccount gets the "tickArrayLower" account. +// Stores init state for the lower tick +func (inst *IncreaseLiquidity) GetTickArrayLowerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetTickArrayUpperAccount sets the "tickArrayUpper" account. +// Stores init state for the upper tick +func (inst *IncreaseLiquidity) SetTickArrayUpperAccount(tickArrayUpper ag_solanago.PublicKey) *IncreaseLiquidity { + inst.AccountMetaSlice[6] = ag_solanago.Meta(tickArrayUpper).WRITE() + return inst +} + +// GetTickArrayUpperAccount gets the "tickArrayUpper" account. +// Stores init state for the upper tick +func (inst *IncreaseLiquidity) GetTickArrayUpperAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetTokenAccount0Account sets the "tokenAccount0" account. +// The payer's token account for token_0 +func (inst *IncreaseLiquidity) SetTokenAccount0Account(tokenAccount0 ag_solanago.PublicKey) *IncreaseLiquidity { + inst.AccountMetaSlice[7] = ag_solanago.Meta(tokenAccount0).WRITE() + return inst +} + +// GetTokenAccount0Account gets the "tokenAccount0" account. +// The payer's token account for token_0 +func (inst *IncreaseLiquidity) GetTokenAccount0Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetTokenAccount1Account sets the "tokenAccount1" account. +// The token account spending token_1 to mint the position +func (inst *IncreaseLiquidity) SetTokenAccount1Account(tokenAccount1 ag_solanago.PublicKey) *IncreaseLiquidity { + inst.AccountMetaSlice[8] = ag_solanago.Meta(tokenAccount1).WRITE() + return inst +} + +// GetTokenAccount1Account gets the "tokenAccount1" account. +// The token account spending token_1 to mint the position +func (inst *IncreaseLiquidity) GetTokenAccount1Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetTokenVault0Account sets the "tokenVault0" account. +// The address that holds pool tokens for token_0 +func (inst *IncreaseLiquidity) SetTokenVault0Account(tokenVault0 ag_solanago.PublicKey) *IncreaseLiquidity { + inst.AccountMetaSlice[9] = ag_solanago.Meta(tokenVault0).WRITE() + return inst +} + +// GetTokenVault0Account gets the "tokenVault0" account. +// The address that holds pool tokens for token_0 +func (inst *IncreaseLiquidity) GetTokenVault0Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetTokenVault1Account sets the "tokenVault1" account. +// The address that holds pool tokens for token_1 +func (inst *IncreaseLiquidity) SetTokenVault1Account(tokenVault1 ag_solanago.PublicKey) *IncreaseLiquidity { + inst.AccountMetaSlice[10] = ag_solanago.Meta(tokenVault1).WRITE() + return inst +} + +// GetTokenVault1Account gets the "tokenVault1" account. +// The address that holds pool tokens for token_1 +func (inst *IncreaseLiquidity) GetTokenVault1Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +// Program to create mint account and mint tokens +func (inst *IncreaseLiquidity) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *IncreaseLiquidity { + inst.AccountMetaSlice[11] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +// Program to create mint account and mint tokens +func (inst *IncreaseLiquidity) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +func (inst IncreaseLiquidity) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_IncreaseLiquidity, + }} +} + +// 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 IncreaseLiquidity) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *IncreaseLiquidity) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.Liquidity == nil { + return errors.New("Liquidity parameter is not set") + } + if inst.Amount0Max == nil { + return errors.New("Amount0Max parameter is not set") + } + if inst.Amount1Max == nil { + return errors.New("Amount1Max parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.NftOwner is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.NftAccount is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.PoolState is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.ProtocolPosition is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.PersonalPosition is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.TickArrayLower is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.TickArrayUpper is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.TokenAccount0 is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.TokenAccount1 is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.TokenVault0 is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.TokenVault1 is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.TokenProgram is not set") + } + } + return nil +} + +func (inst *IncreaseLiquidity) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("IncreaseLiquidity")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=3]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" Liquidity", *inst.Liquidity)) + paramsBranch.Child(ag_format.Param("Amount0Max", *inst.Amount0Max)) + paramsBranch.Child(ag_format.Param("Amount1Max", *inst.Amount1Max)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=12]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" nftOwner", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" nft", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" poolState", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta("protocolPosition", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta("personalPosition", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" tickArrayLower", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" tickArrayUpper", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" tokenAccount0", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" tokenAccount1", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" tokenVault0", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" tokenVault1", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(11))) + }) + }) + }) +} + +func (obj IncreaseLiquidity) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Liquidity` param: + err = encoder.Encode(obj.Liquidity) + if err != nil { + return err + } + // Serialize `Amount0Max` param: + err = encoder.Encode(obj.Amount0Max) + if err != nil { + return err + } + // Serialize `Amount1Max` param: + err = encoder.Encode(obj.Amount1Max) + if err != nil { + return err + } + return nil +} +func (obj *IncreaseLiquidity) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Liquidity`: + err = decoder.Decode(&obj.Liquidity) + if err != nil { + return err + } + // Deserialize `Amount0Max`: + err = decoder.Decode(&obj.Amount0Max) + if err != nil { + return err + } + // Deserialize `Amount1Max`: + err = decoder.Decode(&obj.Amount1Max) + if err != nil { + return err + } + return nil +} + +// NewIncreaseLiquidityInstruction declares a new IncreaseLiquidity instruction with the provided parameters and accounts. +func NewIncreaseLiquidityInstruction( + // Parameters: + liquidity ag_binary.Uint128, + amount0Max uint64, + amount1Max uint64, + // Accounts: + nftOwner ag_solanago.PublicKey, + nftAccount ag_solanago.PublicKey, + poolState ag_solanago.PublicKey, + protocolPosition ag_solanago.PublicKey, + personalPosition ag_solanago.PublicKey, + tickArrayLower ag_solanago.PublicKey, + tickArrayUpper ag_solanago.PublicKey, + tokenAccount0 ag_solanago.PublicKey, + tokenAccount1 ag_solanago.PublicKey, + tokenVault0 ag_solanago.PublicKey, + tokenVault1 ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey) *IncreaseLiquidity { + return NewIncreaseLiquidityInstructionBuilder(). + SetLiquidity(liquidity). + SetAmount0Max(amount0Max). + SetAmount1Max(amount1Max). + SetNftOwnerAccount(nftOwner). + SetNftAccountAccount(nftAccount). + SetPoolStateAccount(poolState). + SetProtocolPositionAccount(protocolPosition). + SetPersonalPositionAccount(personalPosition). + SetTickArrayLowerAccount(tickArrayLower). + SetTickArrayUpperAccount(tickArrayUpper). + SetTokenAccount0Account(tokenAccount0). + SetTokenAccount1Account(tokenAccount1). + SetTokenVault0Account(tokenVault0). + SetTokenVault1Account(tokenVault1). + SetTokenProgramAccount(tokenProgram) +} diff --git a/programs/raydiumclmm/IncreaseLiquidityV2.go b/programs/raydiumclmm/IncreaseLiquidityV2.go new file mode 100644 index 00000000..1ffd0f99 --- /dev/null +++ b/programs/raydiumclmm/IncreaseLiquidityV2.go @@ -0,0 +1,528 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "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" +) + +// Increases liquidity with a exist position, with amount paid by `payer`, support Token2022 +// +// # Arguments +// +// * `ctx` - The context of accounts +// * `liquidity` - The desired liquidity to be added, if zero, calculate liquidity base amount_0 or amount_1 according base_flag +// * `amount_0_max` - The max amount of token_0 to spend, which serves as a slippage check +// * `amount_1_max` - The max amount of token_1 to spend, which serves as a slippage check +// * `base_flag` - active if liquidity is zero, 0: calculate liquidity base amount_0_max otherwise base amount_1_max +// +type IncreaseLiquidityV2 struct { + Liquidity *ag_binary.Uint128 + Amount0Max *uint64 + Amount1Max *uint64 + BaseFlag *bool `bin:"optional"` + + // [0] = [SIGNER] nftOwner + // ··········· Pays to mint the position + // + // [1] = [] nftAccount + // ··········· The token account for nft + // + // [2] = [WRITE] poolState + // + // [3] = [WRITE] protocolPosition + // + // [4] = [WRITE] personalPosition + // ··········· Increase liquidity for this position + // + // [5] = [WRITE] tickArrayLower + // ··········· Stores init state for the lower tick + // + // [6] = [WRITE] tickArrayUpper + // ··········· Stores init state for the upper tick + // + // [7] = [WRITE] tokenAccount0 + // ··········· The payer's token account for token_0 + // + // [8] = [WRITE] tokenAccount1 + // ··········· The token account spending token_1 to mint the position + // + // [9] = [WRITE] tokenVault0 + // ··········· The address that holds pool tokens for token_0 + // + // [10] = [WRITE] tokenVault1 + // ··········· The address that holds pool tokens for token_1 + // + // [11] = [] tokenProgram + // ··········· Program to create mint account and mint tokens + // + // [12] = [] tokenProgram2022 + // ··········· Token program 2022 + // + // [13] = [] vault0Mint + // ··········· The mint of token vault 0 + // + // [14] = [] vault1Mint + // ··········· The mint of token vault 1 + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewIncreaseLiquidityV2InstructionBuilder creates a new `IncreaseLiquidityV2` instruction builder. +func NewIncreaseLiquidityV2InstructionBuilder() *IncreaseLiquidityV2 { + nd := &IncreaseLiquidityV2{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 15), + } + return nd +} + +// SetLiquidity sets the "liquidity" parameter. +func (inst *IncreaseLiquidityV2) SetLiquidity(liquidity ag_binary.Uint128) *IncreaseLiquidityV2 { + inst.Liquidity = &liquidity + return inst +} + +// SetAmount0Max sets the "amount0Max" parameter. +func (inst *IncreaseLiquidityV2) SetAmount0Max(amount0Max uint64) *IncreaseLiquidityV2 { + inst.Amount0Max = &amount0Max + return inst +} + +// SetAmount1Max sets the "amount1Max" parameter. +func (inst *IncreaseLiquidityV2) SetAmount1Max(amount1Max uint64) *IncreaseLiquidityV2 { + inst.Amount1Max = &amount1Max + return inst +} + +// SetBaseFlag sets the "baseFlag" parameter. +func (inst *IncreaseLiquidityV2) SetBaseFlag(baseFlag bool) *IncreaseLiquidityV2 { + inst.BaseFlag = &baseFlag + return inst +} + +// SetNftOwnerAccount sets the "nftOwner" account. +// Pays to mint the position +func (inst *IncreaseLiquidityV2) SetNftOwnerAccount(nftOwner ag_solanago.PublicKey) *IncreaseLiquidityV2 { + inst.AccountMetaSlice[0] = ag_solanago.Meta(nftOwner).SIGNER() + return inst +} + +// GetNftOwnerAccount gets the "nftOwner" account. +// Pays to mint the position +func (inst *IncreaseLiquidityV2) GetNftOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetNftAccountAccount sets the "nftAccount" account. +// The token account for nft +func (inst *IncreaseLiquidityV2) SetNftAccountAccount(nftAccount ag_solanago.PublicKey) *IncreaseLiquidityV2 { + inst.AccountMetaSlice[1] = ag_solanago.Meta(nftAccount) + return inst +} + +// GetNftAccountAccount gets the "nftAccount" account. +// The token account for nft +func (inst *IncreaseLiquidityV2) GetNftAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetPoolStateAccount sets the "poolState" account. +func (inst *IncreaseLiquidityV2) SetPoolStateAccount(poolState ag_solanago.PublicKey) *IncreaseLiquidityV2 { + inst.AccountMetaSlice[2] = ag_solanago.Meta(poolState).WRITE() + return inst +} + +// GetPoolStateAccount gets the "poolState" account. +func (inst *IncreaseLiquidityV2) GetPoolStateAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetProtocolPositionAccount sets the "protocolPosition" account. +func (inst *IncreaseLiquidityV2) SetProtocolPositionAccount(protocolPosition ag_solanago.PublicKey) *IncreaseLiquidityV2 { + inst.AccountMetaSlice[3] = ag_solanago.Meta(protocolPosition).WRITE() + return inst +} + +// GetProtocolPositionAccount gets the "protocolPosition" account. +func (inst *IncreaseLiquidityV2) GetProtocolPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetPersonalPositionAccount sets the "personalPosition" account. +// Increase liquidity for this position +func (inst *IncreaseLiquidityV2) SetPersonalPositionAccount(personalPosition ag_solanago.PublicKey) *IncreaseLiquidityV2 { + inst.AccountMetaSlice[4] = ag_solanago.Meta(personalPosition).WRITE() + return inst +} + +// GetPersonalPositionAccount gets the "personalPosition" account. +// Increase liquidity for this position +func (inst *IncreaseLiquidityV2) GetPersonalPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetTickArrayLowerAccount sets the "tickArrayLower" account. +// Stores init state for the lower tick +func (inst *IncreaseLiquidityV2) SetTickArrayLowerAccount(tickArrayLower ag_solanago.PublicKey) *IncreaseLiquidityV2 { + inst.AccountMetaSlice[5] = ag_solanago.Meta(tickArrayLower).WRITE() + return inst +} + +// GetTickArrayLowerAccount gets the "tickArrayLower" account. +// Stores init state for the lower tick +func (inst *IncreaseLiquidityV2) GetTickArrayLowerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetTickArrayUpperAccount sets the "tickArrayUpper" account. +// Stores init state for the upper tick +func (inst *IncreaseLiquidityV2) SetTickArrayUpperAccount(tickArrayUpper ag_solanago.PublicKey) *IncreaseLiquidityV2 { + inst.AccountMetaSlice[6] = ag_solanago.Meta(tickArrayUpper).WRITE() + return inst +} + +// GetTickArrayUpperAccount gets the "tickArrayUpper" account. +// Stores init state for the upper tick +func (inst *IncreaseLiquidityV2) GetTickArrayUpperAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetTokenAccount0Account sets the "tokenAccount0" account. +// The payer's token account for token_0 +func (inst *IncreaseLiquidityV2) SetTokenAccount0Account(tokenAccount0 ag_solanago.PublicKey) *IncreaseLiquidityV2 { + inst.AccountMetaSlice[7] = ag_solanago.Meta(tokenAccount0).WRITE() + return inst +} + +// GetTokenAccount0Account gets the "tokenAccount0" account. +// The payer's token account for token_0 +func (inst *IncreaseLiquidityV2) GetTokenAccount0Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetTokenAccount1Account sets the "tokenAccount1" account. +// The token account spending token_1 to mint the position +func (inst *IncreaseLiquidityV2) SetTokenAccount1Account(tokenAccount1 ag_solanago.PublicKey) *IncreaseLiquidityV2 { + inst.AccountMetaSlice[8] = ag_solanago.Meta(tokenAccount1).WRITE() + return inst +} + +// GetTokenAccount1Account gets the "tokenAccount1" account. +// The token account spending token_1 to mint the position +func (inst *IncreaseLiquidityV2) GetTokenAccount1Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetTokenVault0Account sets the "tokenVault0" account. +// The address that holds pool tokens for token_0 +func (inst *IncreaseLiquidityV2) SetTokenVault0Account(tokenVault0 ag_solanago.PublicKey) *IncreaseLiquidityV2 { + inst.AccountMetaSlice[9] = ag_solanago.Meta(tokenVault0).WRITE() + return inst +} + +// GetTokenVault0Account gets the "tokenVault0" account. +// The address that holds pool tokens for token_0 +func (inst *IncreaseLiquidityV2) GetTokenVault0Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetTokenVault1Account sets the "tokenVault1" account. +// The address that holds pool tokens for token_1 +func (inst *IncreaseLiquidityV2) SetTokenVault1Account(tokenVault1 ag_solanago.PublicKey) *IncreaseLiquidityV2 { + inst.AccountMetaSlice[10] = ag_solanago.Meta(tokenVault1).WRITE() + return inst +} + +// GetTokenVault1Account gets the "tokenVault1" account. +// The address that holds pool tokens for token_1 +func (inst *IncreaseLiquidityV2) GetTokenVault1Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +// Program to create mint account and mint tokens +func (inst *IncreaseLiquidityV2) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *IncreaseLiquidityV2 { + inst.AccountMetaSlice[11] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +// Program to create mint account and mint tokens +func (inst *IncreaseLiquidityV2) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetTokenProgram2022Account sets the "tokenProgram2022" account. +// Token program 2022 +func (inst *IncreaseLiquidityV2) SetTokenProgram2022Account(tokenProgram2022 ag_solanago.PublicKey) *IncreaseLiquidityV2 { + inst.AccountMetaSlice[12] = ag_solanago.Meta(tokenProgram2022) + return inst +} + +// GetTokenProgram2022Account gets the "tokenProgram2022" account. +// Token program 2022 +func (inst *IncreaseLiquidityV2) GetTokenProgram2022Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetVault0MintAccount sets the "vault0Mint" account. +// The mint of token vault 0 +func (inst *IncreaseLiquidityV2) SetVault0MintAccount(vault0Mint ag_solanago.PublicKey) *IncreaseLiquidityV2 { + inst.AccountMetaSlice[13] = ag_solanago.Meta(vault0Mint) + return inst +} + +// GetVault0MintAccount gets the "vault0Mint" account. +// The mint of token vault 0 +func (inst *IncreaseLiquidityV2) GetVault0MintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetVault1MintAccount sets the "vault1Mint" account. +// The mint of token vault 1 +func (inst *IncreaseLiquidityV2) SetVault1MintAccount(vault1Mint ag_solanago.PublicKey) *IncreaseLiquidityV2 { + inst.AccountMetaSlice[14] = ag_solanago.Meta(vault1Mint) + return inst +} + +// GetVault1MintAccount gets the "vault1Mint" account. +// The mint of token vault 1 +func (inst *IncreaseLiquidityV2) GetVault1MintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +func (inst IncreaseLiquidityV2) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_IncreaseLiquidityV2, + }} +} + +// 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 IncreaseLiquidityV2) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *IncreaseLiquidityV2) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.Liquidity == nil { + return errors.New("Liquidity parameter is not set") + } + if inst.Amount0Max == nil { + return errors.New("Amount0Max parameter is not set") + } + if inst.Amount1Max == nil { + return errors.New("Amount1Max parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.NftOwner is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.NftAccount is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.PoolState is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.ProtocolPosition is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.PersonalPosition is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.TickArrayLower is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.TickArrayUpper is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.TokenAccount0 is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.TokenAccount1 is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.TokenVault0 is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.TokenVault1 is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.TokenProgram2022 is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.Vault0Mint is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.Vault1Mint is not set") + } + } + return nil +} + +func (inst *IncreaseLiquidityV2) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("IncreaseLiquidityV2")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=4]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" Liquidity", *inst.Liquidity)) + paramsBranch.Child(ag_format.Param("Amount0Max", *inst.Amount0Max)) + paramsBranch.Child(ag_format.Param("Amount1Max", *inst.Amount1Max)) + paramsBranch.Child(ag_format.Param(" BaseFlag (OPT)", inst.BaseFlag)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=15]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" nftOwner", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" nft", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" poolState", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta("protocolPosition", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta("personalPosition", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" tickArrayLower", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" tickArrayUpper", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" tokenAccount0", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" tokenAccount1", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" tokenVault0", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" tokenVault1", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta("tokenProgram2022", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" vault0Mint", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta(" vault1Mint", inst.AccountMetaSlice.Get(14))) + }) + }) + }) +} + +func (obj IncreaseLiquidityV2) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Liquidity` param: + err = encoder.Encode(obj.Liquidity) + if err != nil { + return err + } + // Serialize `Amount0Max` param: + err = encoder.Encode(obj.Amount0Max) + if err != nil { + return err + } + // Serialize `Amount1Max` param: + err = encoder.Encode(obj.Amount1Max) + if err != nil { + return err + } + // Serialize `BaseFlag` param (optional): + { + if obj.BaseFlag == nil { + err = encoder.WriteBool(false) + if err != nil { + return err + } + } else { + err = encoder.WriteBool(true) + if err != nil { + return err + } + err = encoder.Encode(obj.BaseFlag) + if err != nil { + return err + } + } + } + return nil +} +func (obj *IncreaseLiquidityV2) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Liquidity`: + err = decoder.Decode(&obj.Liquidity) + if err != nil { + return err + } + // Deserialize `Amount0Max`: + err = decoder.Decode(&obj.Amount0Max) + if err != nil { + return err + } + // Deserialize `Amount1Max`: + err = decoder.Decode(&obj.Amount1Max) + if err != nil { + return err + } + // Deserialize `BaseFlag` (optional): + { + ok, err := decoder.ReadBool() + if err != nil { + return err + } + if ok { + err = decoder.Decode(&obj.BaseFlag) + if err != nil { + return err + } + } + } + return nil +} + +// NewIncreaseLiquidityV2Instruction declares a new IncreaseLiquidityV2 instruction with the provided parameters and accounts. +func NewIncreaseLiquidityV2Instruction( + // Parameters: + liquidity ag_binary.Uint128, + amount0Max uint64, + amount1Max uint64, + baseFlag bool, + // Accounts: + nftOwner ag_solanago.PublicKey, + nftAccount ag_solanago.PublicKey, + poolState ag_solanago.PublicKey, + protocolPosition ag_solanago.PublicKey, + personalPosition ag_solanago.PublicKey, + tickArrayLower ag_solanago.PublicKey, + tickArrayUpper ag_solanago.PublicKey, + tokenAccount0 ag_solanago.PublicKey, + tokenAccount1 ag_solanago.PublicKey, + tokenVault0 ag_solanago.PublicKey, + tokenVault1 ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + tokenProgram2022 ag_solanago.PublicKey, + vault0Mint ag_solanago.PublicKey, + vault1Mint ag_solanago.PublicKey) *IncreaseLiquidityV2 { + return NewIncreaseLiquidityV2InstructionBuilder(). + SetLiquidity(liquidity). + SetAmount0Max(amount0Max). + SetAmount1Max(amount1Max). + SetBaseFlag(baseFlag). + SetNftOwnerAccount(nftOwner). + SetNftAccountAccount(nftAccount). + SetPoolStateAccount(poolState). + SetProtocolPositionAccount(protocolPosition). + SetPersonalPositionAccount(personalPosition). + SetTickArrayLowerAccount(tickArrayLower). + SetTickArrayUpperAccount(tickArrayUpper). + SetTokenAccount0Account(tokenAccount0). + SetTokenAccount1Account(tokenAccount1). + SetTokenVault0Account(tokenVault0). + SetTokenVault1Account(tokenVault1). + SetTokenProgramAccount(tokenProgram). + SetTokenProgram2022Account(tokenProgram2022). + SetVault0MintAccount(vault0Mint). + SetVault1MintAccount(vault1Mint) +} diff --git a/programs/raydiumclmm/IncreaseLiquidityV2_test.go b/programs/raydiumclmm/IncreaseLiquidityV2_test.go new file mode 100644 index 00000000..ebfa8cda --- /dev/null +++ b/programs/raydiumclmm/IncreaseLiquidityV2_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_IncreaseLiquidityV2(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("IncreaseLiquidityV2"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(IncreaseLiquidityV2) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(IncreaseLiquidityV2) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/raydiumclmm/IncreaseLiquidity_test.go b/programs/raydiumclmm/IncreaseLiquidity_test.go new file mode 100644 index 00000000..117bcb9e --- /dev/null +++ b/programs/raydiumclmm/IncreaseLiquidity_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_IncreaseLiquidity(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("IncreaseLiquidity"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(IncreaseLiquidity) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(IncreaseLiquidity) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/raydiumclmm/InitializeReward.go b/programs/raydiumclmm/InitializeReward.go new file mode 100644 index 00000000..bf563c51 --- /dev/null +++ b/programs/raydiumclmm/InitializeReward.go @@ -0,0 +1,325 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "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" +) + +// Initialize a reward info for a given pool and reward index +// +// # Arguments +// +// * `ctx`- The context of accounts +// * `reward_index` - the index to reward info +// * `open_time` - reward open timestamp +// * `end_time` - reward end timestamp +// * `emissions_per_second_x64` - Token reward per second are earned per unit of liquidity. +// +type InitializeReward struct { + Param *InitializeRewardParam + + // [0] = [WRITE, SIGNER] rewardFunder + // ··········· The founder deposit reward token to vault + // + // [1] = [WRITE] funderTokenAccount + // + // [2] = [] ammConfig + // ··········· For check the reward_funder authority + // + // [3] = [WRITE] poolState + // ··········· Set reward for this pool + // + // [4] = [] operationState + // ··········· load info from the account to judge reward permission + // + // [5] = [] rewardTokenMint + // ··········· Reward mint + // + // [6] = [WRITE] rewardTokenVault + // ··········· A pda, reward vault + // + // [7] = [] rewardTokenProgram + // + // [8] = [] systemProgram + // + // [9] = [] rent + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewInitializeRewardInstructionBuilder creates a new `InitializeReward` instruction builder. +func NewInitializeRewardInstructionBuilder() *InitializeReward { + nd := &InitializeReward{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 10), + } + return nd +} + +// SetParam sets the "param" parameter. +func (inst *InitializeReward) SetParam(param InitializeRewardParam) *InitializeReward { + inst.Param = ¶m + return inst +} + +// SetRewardFunderAccount sets the "rewardFunder" account. +// The founder deposit reward token to vault +func (inst *InitializeReward) SetRewardFunderAccount(rewardFunder ag_solanago.PublicKey) *InitializeReward { + inst.AccountMetaSlice[0] = ag_solanago.Meta(rewardFunder).WRITE().SIGNER() + return inst +} + +// GetRewardFunderAccount gets the "rewardFunder" account. +// The founder deposit reward token to vault +func (inst *InitializeReward) GetRewardFunderAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetFunderTokenAccountAccount sets the "funderTokenAccount" account. +func (inst *InitializeReward) SetFunderTokenAccountAccount(funderTokenAccount ag_solanago.PublicKey) *InitializeReward { + inst.AccountMetaSlice[1] = ag_solanago.Meta(funderTokenAccount).WRITE() + return inst +} + +// GetFunderTokenAccountAccount gets the "funderTokenAccount" account. +func (inst *InitializeReward) GetFunderTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetAmmConfigAccount sets the "ammConfig" account. +// For check the reward_funder authority +func (inst *InitializeReward) SetAmmConfigAccount(ammConfig ag_solanago.PublicKey) *InitializeReward { + inst.AccountMetaSlice[2] = ag_solanago.Meta(ammConfig) + return inst +} + +// GetAmmConfigAccount gets the "ammConfig" account. +// For check the reward_funder authority +func (inst *InitializeReward) GetAmmConfigAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetPoolStateAccount sets the "poolState" account. +// Set reward for this pool +func (inst *InitializeReward) SetPoolStateAccount(poolState ag_solanago.PublicKey) *InitializeReward { + inst.AccountMetaSlice[3] = ag_solanago.Meta(poolState).WRITE() + return inst +} + +// GetPoolStateAccount gets the "poolState" account. +// Set reward for this pool +func (inst *InitializeReward) GetPoolStateAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetOperationStateAccount sets the "operationState" account. +// load info from the account to judge reward permission +func (inst *InitializeReward) SetOperationStateAccount(operationState ag_solanago.PublicKey) *InitializeReward { + inst.AccountMetaSlice[4] = ag_solanago.Meta(operationState) + return inst +} + +// GetOperationStateAccount gets the "operationState" account. +// load info from the account to judge reward permission +func (inst *InitializeReward) GetOperationStateAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetRewardTokenMintAccount sets the "rewardTokenMint" account. +// Reward mint +func (inst *InitializeReward) SetRewardTokenMintAccount(rewardTokenMint ag_solanago.PublicKey) *InitializeReward { + inst.AccountMetaSlice[5] = ag_solanago.Meta(rewardTokenMint) + return inst +} + +// GetRewardTokenMintAccount gets the "rewardTokenMint" account. +// Reward mint +func (inst *InitializeReward) GetRewardTokenMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetRewardTokenVaultAccount sets the "rewardTokenVault" account. +// A pda, reward vault +func (inst *InitializeReward) SetRewardTokenVaultAccount(rewardTokenVault ag_solanago.PublicKey) *InitializeReward { + inst.AccountMetaSlice[6] = ag_solanago.Meta(rewardTokenVault).WRITE() + return inst +} + +// GetRewardTokenVaultAccount gets the "rewardTokenVault" account. +// A pda, reward vault +func (inst *InitializeReward) GetRewardTokenVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetRewardTokenProgramAccount sets the "rewardTokenProgram" account. +func (inst *InitializeReward) SetRewardTokenProgramAccount(rewardTokenProgram ag_solanago.PublicKey) *InitializeReward { + inst.AccountMetaSlice[7] = ag_solanago.Meta(rewardTokenProgram) + return inst +} + +// GetRewardTokenProgramAccount gets the "rewardTokenProgram" account. +func (inst *InitializeReward) GetRewardTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +func (inst *InitializeReward) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *InitializeReward { + inst.AccountMetaSlice[8] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +func (inst *InitializeReward) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetRentAccount sets the "rent" account. +func (inst *InitializeReward) SetRentAccount(rent ag_solanago.PublicKey) *InitializeReward { + inst.AccountMetaSlice[9] = ag_solanago.Meta(rent) + return inst +} + +// GetRentAccount gets the "rent" account. +func (inst *InitializeReward) GetRentAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +func (inst InitializeReward) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_InitializeReward, + }} +} + +// 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 InitializeReward) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *InitializeReward) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.Param == nil { + return errors.New("Param parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.RewardFunder is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.FunderTokenAccount is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.AmmConfig is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.PoolState is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.OperationState is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.RewardTokenMint is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.RewardTokenVault is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.RewardTokenProgram is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.SystemProgram is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.Rent is not set") + } + } + return nil +} + +func (inst *InitializeReward) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("InitializeReward")). + // + 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("Param", *inst.Param)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=10]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" rewardFunder", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" funderToken", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" ammConfig", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" poolState", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" operationState", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" rewardTokenMint", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" rewardTokenVault", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta("rewardTokenProgram", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" systemProgram", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" rent", inst.AccountMetaSlice.Get(9))) + }) + }) + }) +} + +func (obj InitializeReward) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Param` param: + err = encoder.Encode(obj.Param) + if err != nil { + return err + } + return nil +} +func (obj *InitializeReward) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Param`: + err = decoder.Decode(&obj.Param) + if err != nil { + return err + } + return nil +} + +// NewInitializeRewardInstruction declares a new InitializeReward instruction with the provided parameters and accounts. +func NewInitializeRewardInstruction( + // Parameters: + param InitializeRewardParam, + // Accounts: + rewardFunder ag_solanago.PublicKey, + funderTokenAccount ag_solanago.PublicKey, + ammConfig ag_solanago.PublicKey, + poolState ag_solanago.PublicKey, + operationState ag_solanago.PublicKey, + rewardTokenMint ag_solanago.PublicKey, + rewardTokenVault ag_solanago.PublicKey, + rewardTokenProgram ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey, + rent ag_solanago.PublicKey) *InitializeReward { + return NewInitializeRewardInstructionBuilder(). + SetParam(param). + SetRewardFunderAccount(rewardFunder). + SetFunderTokenAccountAccount(funderTokenAccount). + SetAmmConfigAccount(ammConfig). + SetPoolStateAccount(poolState). + SetOperationStateAccount(operationState). + SetRewardTokenMintAccount(rewardTokenMint). + SetRewardTokenVaultAccount(rewardTokenVault). + SetRewardTokenProgramAccount(rewardTokenProgram). + SetSystemProgramAccount(systemProgram). + SetRentAccount(rent) +} diff --git a/programs/raydiumclmm/InitializeReward_test.go b/programs/raydiumclmm/InitializeReward_test.go new file mode 100644 index 00000000..5bbb9ca9 --- /dev/null +++ b/programs/raydiumclmm/InitializeReward_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_InitializeReward(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("InitializeReward"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(InitializeReward) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(InitializeReward) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/raydiumclmm/OpenPosition.go b/programs/raydiumclmm/OpenPosition.go new file mode 100644 index 00000000..542e34c7 --- /dev/null +++ b/programs/raydiumclmm/OpenPosition.go @@ -0,0 +1,667 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "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" +) + +// Creates a new position wrapped in a NFT +// +// # Arguments +// +// * `ctx` - The context of accounts +// * `tick_lower_index` - The low boundary of market +// * `tick_upper_index` - The upper boundary of market +// * `tick_array_lower_start_index` - The start index of tick array which include tick low +// * `tick_array_upper_start_index` - The start index of tick array which include tick upper +// * `liquidity` - The liquidity to be added +// * `amount_0_max` - The max amount of token_0 to spend, which serves as a slippage check +// * `amount_1_max` - The max amount of token_1 to spend, which serves as a slippage check +// +type OpenPosition struct { + TickLowerIndex *int32 + TickUpperIndex *int32 + TickArrayLowerStartIndex *int32 + TickArrayUpperStartIndex *int32 + Liquidity *ag_binary.Uint128 + Amount0Max *uint64 + Amount1Max *uint64 + + // [0] = [WRITE, SIGNER] payer + // ··········· Pays to mint the position + // + // [1] = [] positionNftOwner + // + // [2] = [WRITE, SIGNER] positionNftMint + // ··········· Unique token mint address + // + // [3] = [WRITE] positionNftAccount + // ··········· Token account where position NFT will be minted + // + // [4] = [WRITE] metadataAccount + // ··········· To store metaplex metadata + // + // [5] = [WRITE] poolState + // ··········· Add liquidity for this pool + // + // [6] = [WRITE] protocolPosition + // ··········· Store the information of market marking in range + // + // [7] = [WRITE] tickArrayLower + // + // [8] = [WRITE] tickArrayUpper + // + // [9] = [WRITE] personalPosition + // ··········· personal position state + // + // [10] = [WRITE] tokenAccount0 + // ··········· The token_0 account deposit token to the pool + // + // [11] = [WRITE] tokenAccount1 + // ··········· The token_1 account deposit token to the pool + // + // [12] = [WRITE] tokenVault0 + // ··········· The address that holds pool tokens for token_0 + // + // [13] = [WRITE] tokenVault1 + // ··········· The address that holds pool tokens for token_1 + // + // [14] = [] rent + // ··········· Sysvar for token mint and ATA creation + // + // [15] = [] systemProgram + // ··········· Program to create the position manager state account + // + // [16] = [] tokenProgram + // ··········· Program to create mint account and mint tokens + // + // [17] = [] associatedTokenProgram + // ··········· Program to create an ATA for receiving position NFT + // + // [18] = [] metadataProgram + // ··········· Program to create NFT metadata + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewOpenPositionInstructionBuilder creates a new `OpenPosition` instruction builder. +func NewOpenPositionInstructionBuilder() *OpenPosition { + nd := &OpenPosition{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 19), + } + return nd +} + +// SetTickLowerIndex sets the "tickLowerIndex" parameter. +func (inst *OpenPosition) SetTickLowerIndex(tickLowerIndex int32) *OpenPosition { + inst.TickLowerIndex = &tickLowerIndex + return inst +} + +// SetTickUpperIndex sets the "tickUpperIndex" parameter. +func (inst *OpenPosition) SetTickUpperIndex(tickUpperIndex int32) *OpenPosition { + inst.TickUpperIndex = &tickUpperIndex + return inst +} + +// SetTickArrayLowerStartIndex sets the "tickArrayLowerStartIndex" parameter. +func (inst *OpenPosition) SetTickArrayLowerStartIndex(tickArrayLowerStartIndex int32) *OpenPosition { + inst.TickArrayLowerStartIndex = &tickArrayLowerStartIndex + return inst +} + +// SetTickArrayUpperStartIndex sets the "tickArrayUpperStartIndex" parameter. +func (inst *OpenPosition) SetTickArrayUpperStartIndex(tickArrayUpperStartIndex int32) *OpenPosition { + inst.TickArrayUpperStartIndex = &tickArrayUpperStartIndex + return inst +} + +// SetLiquidity sets the "liquidity" parameter. +func (inst *OpenPosition) SetLiquidity(liquidity ag_binary.Uint128) *OpenPosition { + inst.Liquidity = &liquidity + return inst +} + +// SetAmount0Max sets the "amount0Max" parameter. +func (inst *OpenPosition) SetAmount0Max(amount0Max uint64) *OpenPosition { + inst.Amount0Max = &amount0Max + return inst +} + +// SetAmount1Max sets the "amount1Max" parameter. +func (inst *OpenPosition) SetAmount1Max(amount1Max uint64) *OpenPosition { + inst.Amount1Max = &amount1Max + return inst +} + +// SetPayerAccount sets the "payer" account. +// Pays to mint the position +func (inst *OpenPosition) SetPayerAccount(payer ag_solanago.PublicKey) *OpenPosition { + inst.AccountMetaSlice[0] = ag_solanago.Meta(payer).WRITE().SIGNER() + return inst +} + +// GetPayerAccount gets the "payer" account. +// Pays to mint the position +func (inst *OpenPosition) GetPayerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetPositionNftOwnerAccount sets the "positionNftOwner" account. +func (inst *OpenPosition) SetPositionNftOwnerAccount(positionNftOwner ag_solanago.PublicKey) *OpenPosition { + inst.AccountMetaSlice[1] = ag_solanago.Meta(positionNftOwner) + return inst +} + +// GetPositionNftOwnerAccount gets the "positionNftOwner" account. +func (inst *OpenPosition) GetPositionNftOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetPositionNftMintAccount sets the "positionNftMint" account. +// Unique token mint address +func (inst *OpenPosition) SetPositionNftMintAccount(positionNftMint ag_solanago.PublicKey) *OpenPosition { + inst.AccountMetaSlice[2] = ag_solanago.Meta(positionNftMint).WRITE().SIGNER() + return inst +} + +// GetPositionNftMintAccount gets the "positionNftMint" account. +// Unique token mint address +func (inst *OpenPosition) GetPositionNftMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetPositionNftAccountAccount sets the "positionNftAccount" account. +// Token account where position NFT will be minted +func (inst *OpenPosition) SetPositionNftAccountAccount(positionNftAccount ag_solanago.PublicKey) *OpenPosition { + inst.AccountMetaSlice[3] = ag_solanago.Meta(positionNftAccount).WRITE() + return inst +} + +// GetPositionNftAccountAccount gets the "positionNftAccount" account. +// Token account where position NFT will be minted +func (inst *OpenPosition) GetPositionNftAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetMetadataAccountAccount sets the "metadataAccount" account. +// To store metaplex metadata +func (inst *OpenPosition) SetMetadataAccountAccount(metadataAccount ag_solanago.PublicKey) *OpenPosition { + inst.AccountMetaSlice[4] = ag_solanago.Meta(metadataAccount).WRITE() + return inst +} + +// GetMetadataAccountAccount gets the "metadataAccount" account. +// To store metaplex metadata +func (inst *OpenPosition) GetMetadataAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetPoolStateAccount sets the "poolState" account. +// Add liquidity for this pool +func (inst *OpenPosition) SetPoolStateAccount(poolState ag_solanago.PublicKey) *OpenPosition { + inst.AccountMetaSlice[5] = ag_solanago.Meta(poolState).WRITE() + return inst +} + +// GetPoolStateAccount gets the "poolState" account. +// Add liquidity for this pool +func (inst *OpenPosition) GetPoolStateAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetProtocolPositionAccount sets the "protocolPosition" account. +// Store the information of market marking in range +func (inst *OpenPosition) SetProtocolPositionAccount(protocolPosition ag_solanago.PublicKey) *OpenPosition { + inst.AccountMetaSlice[6] = ag_solanago.Meta(protocolPosition).WRITE() + return inst +} + +// GetProtocolPositionAccount gets the "protocolPosition" account. +// Store the information of market marking in range +func (inst *OpenPosition) GetProtocolPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetTickArrayLowerAccount sets the "tickArrayLower" account. +func (inst *OpenPosition) SetTickArrayLowerAccount(tickArrayLower ag_solanago.PublicKey) *OpenPosition { + inst.AccountMetaSlice[7] = ag_solanago.Meta(tickArrayLower).WRITE() + return inst +} + +// GetTickArrayLowerAccount gets the "tickArrayLower" account. +func (inst *OpenPosition) GetTickArrayLowerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetTickArrayUpperAccount sets the "tickArrayUpper" account. +func (inst *OpenPosition) SetTickArrayUpperAccount(tickArrayUpper ag_solanago.PublicKey) *OpenPosition { + inst.AccountMetaSlice[8] = ag_solanago.Meta(tickArrayUpper).WRITE() + return inst +} + +// GetTickArrayUpperAccount gets the "tickArrayUpper" account. +func (inst *OpenPosition) GetTickArrayUpperAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetPersonalPositionAccount sets the "personalPosition" account. +// personal position state +func (inst *OpenPosition) SetPersonalPositionAccount(personalPosition ag_solanago.PublicKey) *OpenPosition { + inst.AccountMetaSlice[9] = ag_solanago.Meta(personalPosition).WRITE() + return inst +} + +// GetPersonalPositionAccount gets the "personalPosition" account. +// personal position state +func (inst *OpenPosition) GetPersonalPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetTokenAccount0Account sets the "tokenAccount0" account. +// The token_0 account deposit token to the pool +func (inst *OpenPosition) SetTokenAccount0Account(tokenAccount0 ag_solanago.PublicKey) *OpenPosition { + inst.AccountMetaSlice[10] = ag_solanago.Meta(tokenAccount0).WRITE() + return inst +} + +// GetTokenAccount0Account gets the "tokenAccount0" account. +// The token_0 account deposit token to the pool +func (inst *OpenPosition) GetTokenAccount0Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetTokenAccount1Account sets the "tokenAccount1" account. +// The token_1 account deposit token to the pool +func (inst *OpenPosition) SetTokenAccount1Account(tokenAccount1 ag_solanago.PublicKey) *OpenPosition { + inst.AccountMetaSlice[11] = ag_solanago.Meta(tokenAccount1).WRITE() + return inst +} + +// GetTokenAccount1Account gets the "tokenAccount1" account. +// The token_1 account deposit token to the pool +func (inst *OpenPosition) GetTokenAccount1Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetTokenVault0Account sets the "tokenVault0" account. +// The address that holds pool tokens for token_0 +func (inst *OpenPosition) SetTokenVault0Account(tokenVault0 ag_solanago.PublicKey) *OpenPosition { + inst.AccountMetaSlice[12] = ag_solanago.Meta(tokenVault0).WRITE() + return inst +} + +// GetTokenVault0Account gets the "tokenVault0" account. +// The address that holds pool tokens for token_0 +func (inst *OpenPosition) GetTokenVault0Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetTokenVault1Account sets the "tokenVault1" account. +// The address that holds pool tokens for token_1 +func (inst *OpenPosition) SetTokenVault1Account(tokenVault1 ag_solanago.PublicKey) *OpenPosition { + inst.AccountMetaSlice[13] = ag_solanago.Meta(tokenVault1).WRITE() + return inst +} + +// GetTokenVault1Account gets the "tokenVault1" account. +// The address that holds pool tokens for token_1 +func (inst *OpenPosition) GetTokenVault1Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetRentAccount sets the "rent" account. +// Sysvar for token mint and ATA creation +func (inst *OpenPosition) SetRentAccount(rent ag_solanago.PublicKey) *OpenPosition { + inst.AccountMetaSlice[14] = ag_solanago.Meta(rent) + return inst +} + +// GetRentAccount gets the "rent" account. +// Sysvar for token mint and ATA creation +func (inst *OpenPosition) GetRentAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +// Program to create the position manager state account +func (inst *OpenPosition) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *OpenPosition { + inst.AccountMetaSlice[15] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +// Program to create the position manager state account +func (inst *OpenPosition) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(15) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +// Program to create mint account and mint tokens +func (inst *OpenPosition) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *OpenPosition { + inst.AccountMetaSlice[16] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +// Program to create mint account and mint tokens +func (inst *OpenPosition) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(16) +} + +// SetAssociatedTokenProgramAccount sets the "associatedTokenProgram" account. +// Program to create an ATA for receiving position NFT +func (inst *OpenPosition) SetAssociatedTokenProgramAccount(associatedTokenProgram ag_solanago.PublicKey) *OpenPosition { + inst.AccountMetaSlice[17] = ag_solanago.Meta(associatedTokenProgram) + return inst +} + +// GetAssociatedTokenProgramAccount gets the "associatedTokenProgram" account. +// Program to create an ATA for receiving position NFT +func (inst *OpenPosition) GetAssociatedTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(17) +} + +// SetMetadataProgramAccount sets the "metadataProgram" account. +// Program to create NFT metadata +func (inst *OpenPosition) SetMetadataProgramAccount(metadataProgram ag_solanago.PublicKey) *OpenPosition { + inst.AccountMetaSlice[18] = ag_solanago.Meta(metadataProgram) + return inst +} + +// GetMetadataProgramAccount gets the "metadataProgram" account. +// Program to create NFT metadata +func (inst *OpenPosition) GetMetadataProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(18) +} + +func (inst OpenPosition) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_OpenPosition, + }} +} + +// 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 OpenPosition) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *OpenPosition) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.TickLowerIndex == nil { + return errors.New("TickLowerIndex parameter is not set") + } + if inst.TickUpperIndex == nil { + return errors.New("TickUpperIndex parameter is not set") + } + if inst.TickArrayLowerStartIndex == nil { + return errors.New("TickArrayLowerStartIndex parameter is not set") + } + if inst.TickArrayUpperStartIndex == nil { + return errors.New("TickArrayUpperStartIndex parameter is not set") + } + if inst.Liquidity == nil { + return errors.New("Liquidity parameter is not set") + } + if inst.Amount0Max == nil { + return errors.New("Amount0Max parameter is not set") + } + if inst.Amount1Max == nil { + return errors.New("Amount1Max parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Payer is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.PositionNftOwner is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.PositionNftMint is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.PositionNftAccount is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.MetadataAccount is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.PoolState is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.ProtocolPosition is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.TickArrayLower is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.TickArrayUpper is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.PersonalPosition is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.TokenAccount0 is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.TokenAccount1 is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.TokenVault0 is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.TokenVault1 is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.Rent is not set") + } + if inst.AccountMetaSlice[15] == nil { + return errors.New("accounts.SystemProgram is not set") + } + if inst.AccountMetaSlice[16] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[17] == nil { + return errors.New("accounts.AssociatedTokenProgram is not set") + } + if inst.AccountMetaSlice[18] == nil { + return errors.New("accounts.MetadataProgram is not set") + } + } + return nil +} + +func (inst *OpenPosition) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("OpenPosition")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=7]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" TickLowerIndex", *inst.TickLowerIndex)) + paramsBranch.Child(ag_format.Param(" TickUpperIndex", *inst.TickUpperIndex)) + paramsBranch.Child(ag_format.Param("TickArrayLowerStartIndex", *inst.TickArrayLowerStartIndex)) + paramsBranch.Child(ag_format.Param("TickArrayUpperStartIndex", *inst.TickArrayUpperStartIndex)) + paramsBranch.Child(ag_format.Param(" Liquidity", *inst.Liquidity)) + paramsBranch.Child(ag_format.Param(" Amount0Max", *inst.Amount0Max)) + paramsBranch.Child(ag_format.Param(" Amount1Max", *inst.Amount1Max)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=19]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" payer", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" positionNftOwner", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" positionNftMint", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" positionNft", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" metadata", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" poolState", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" protocolPosition", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" tickArrayLower", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" tickArrayUpper", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" personalPosition", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" tokenAccount0", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" tokenAccount1", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" tokenVault0", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" tokenVault1", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta(" rent", inst.AccountMetaSlice.Get(14))) + accountsBranch.Child(ag_format.Meta(" systemProgram", inst.AccountMetaSlice.Get(15))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(16))) + accountsBranch.Child(ag_format.Meta("associatedTokenProgram", inst.AccountMetaSlice.Get(17))) + accountsBranch.Child(ag_format.Meta(" metadataProgram", inst.AccountMetaSlice.Get(18))) + }) + }) + }) +} + +func (obj OpenPosition) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `TickLowerIndex` param: + err = encoder.Encode(obj.TickLowerIndex) + if err != nil { + return err + } + // Serialize `TickUpperIndex` param: + err = encoder.Encode(obj.TickUpperIndex) + if err != nil { + return err + } + // Serialize `TickArrayLowerStartIndex` param: + err = encoder.Encode(obj.TickArrayLowerStartIndex) + if err != nil { + return err + } + // Serialize `TickArrayUpperStartIndex` param: + err = encoder.Encode(obj.TickArrayUpperStartIndex) + if err != nil { + return err + } + // Serialize `Liquidity` param: + err = encoder.Encode(obj.Liquidity) + if err != nil { + return err + } + // Serialize `Amount0Max` param: + err = encoder.Encode(obj.Amount0Max) + if err != nil { + return err + } + // Serialize `Amount1Max` param: + err = encoder.Encode(obj.Amount1Max) + if err != nil { + return err + } + return nil +} +func (obj *OpenPosition) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `TickLowerIndex`: + err = decoder.Decode(&obj.TickLowerIndex) + if err != nil { + return err + } + // Deserialize `TickUpperIndex`: + err = decoder.Decode(&obj.TickUpperIndex) + if err != nil { + return err + } + // Deserialize `TickArrayLowerStartIndex`: + err = decoder.Decode(&obj.TickArrayLowerStartIndex) + if err != nil { + return err + } + // Deserialize `TickArrayUpperStartIndex`: + err = decoder.Decode(&obj.TickArrayUpperStartIndex) + if err != nil { + return err + } + // Deserialize `Liquidity`: + err = decoder.Decode(&obj.Liquidity) + if err != nil { + return err + } + // Deserialize `Amount0Max`: + err = decoder.Decode(&obj.Amount0Max) + if err != nil { + return err + } + // Deserialize `Amount1Max`: + err = decoder.Decode(&obj.Amount1Max) + if err != nil { + return err + } + return nil +} + +// NewOpenPositionInstruction declares a new OpenPosition instruction with the provided parameters and accounts. +func NewOpenPositionInstruction( + // Parameters: + tickLowerIndex int32, + tickUpperIndex int32, + tickArrayLowerStartIndex int32, + tickArrayUpperStartIndex int32, + liquidity ag_binary.Uint128, + amount0Max uint64, + amount1Max uint64, + // Accounts: + payer ag_solanago.PublicKey, + positionNftOwner ag_solanago.PublicKey, + positionNftMint ag_solanago.PublicKey, + positionNftAccount ag_solanago.PublicKey, + metadataAccount ag_solanago.PublicKey, + poolState ag_solanago.PublicKey, + protocolPosition ag_solanago.PublicKey, + tickArrayLower ag_solanago.PublicKey, + tickArrayUpper ag_solanago.PublicKey, + personalPosition ag_solanago.PublicKey, + tokenAccount0 ag_solanago.PublicKey, + tokenAccount1 ag_solanago.PublicKey, + tokenVault0 ag_solanago.PublicKey, + tokenVault1 ag_solanago.PublicKey, + rent ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + associatedTokenProgram ag_solanago.PublicKey, + metadataProgram ag_solanago.PublicKey) *OpenPosition { + return NewOpenPositionInstructionBuilder(). + SetTickLowerIndex(tickLowerIndex). + SetTickUpperIndex(tickUpperIndex). + SetTickArrayLowerStartIndex(tickArrayLowerStartIndex). + SetTickArrayUpperStartIndex(tickArrayUpperStartIndex). + SetLiquidity(liquidity). + SetAmount0Max(amount0Max). + SetAmount1Max(amount1Max). + SetPayerAccount(payer). + SetPositionNftOwnerAccount(positionNftOwner). + SetPositionNftMintAccount(positionNftMint). + SetPositionNftAccountAccount(positionNftAccount). + SetMetadataAccountAccount(metadataAccount). + SetPoolStateAccount(poolState). + SetProtocolPositionAccount(protocolPosition). + SetTickArrayLowerAccount(tickArrayLower). + SetTickArrayUpperAccount(tickArrayUpper). + SetPersonalPositionAccount(personalPosition). + SetTokenAccount0Account(tokenAccount0). + SetTokenAccount1Account(tokenAccount1). + SetTokenVault0Account(tokenVault0). + SetTokenVault1Account(tokenVault1). + SetRentAccount(rent). + SetSystemProgramAccount(systemProgram). + SetTokenProgramAccount(tokenProgram). + SetAssociatedTokenProgramAccount(associatedTokenProgram). + SetMetadataProgramAccount(metadataProgram) +} diff --git a/programs/raydiumclmm/OpenPositionV2.go b/programs/raydiumclmm/OpenPositionV2.go new file mode 100644 index 00000000..d8d92904 --- /dev/null +++ b/programs/raydiumclmm/OpenPositionV2.go @@ -0,0 +1,798 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "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" +) + +// Creates a new position wrapped in a NFT, support Token2022 +// +// # Arguments +// +// * `ctx` - The context of accounts +// * `tick_lower_index` - The low boundary of market +// * `tick_upper_index` - The upper boundary of market +// * `tick_array_lower_start_index` - The start index of tick array which include tick low +// * `tick_array_upper_start_index` - The start index of tick array which include tick upper +// * `liquidity` - The liquidity to be added, if zero, calculate liquidity base amount_0_max or amount_1_max according base_flag +// * `amount_0_max` - The max amount of token_0 to spend, which serves as a slippage check +// * `amount_1_max` - The max amount of token_1 to spend, which serves as a slippage check +// * `base_flag` - must be special if liquidity is zero, false: calculate liquidity base amount_0_max otherwise base amount_1_max +// +type OpenPositionV2 struct { + TickLowerIndex *int32 + TickUpperIndex *int32 + TickArrayLowerStartIndex *int32 + TickArrayUpperStartIndex *int32 + Liquidity *ag_binary.Uint128 + Amount0Max *uint64 + Amount1Max *uint64 + WithMatedata *bool + BaseFlag *bool `bin:"optional"` + + // [0] = [WRITE, SIGNER] payer + // ··········· Pays to mint the position + // + // [1] = [] positionNftOwner + // + // [2] = [WRITE, SIGNER] positionNftMint + // ··········· Unique token mint address + // + // [3] = [WRITE] positionNftAccount + // ··········· Token account where position NFT will be minted + // + // [4] = [WRITE] metadataAccount + // ··········· To store metaplex metadata + // + // [5] = [WRITE] poolState + // ··········· Add liquidity for this pool + // + // [6] = [WRITE] protocolPosition + // ··········· Store the information of market marking in range + // + // [7] = [WRITE] tickArrayLower + // + // [8] = [WRITE] tickArrayUpper + // + // [9] = [WRITE] personalPosition + // ··········· personal position state + // + // [10] = [WRITE] tokenAccount0 + // ··········· The token_0 account deposit token to the pool + // + // [11] = [WRITE] tokenAccount1 + // ··········· The token_1 account deposit token to the pool + // + // [12] = [WRITE] tokenVault0 + // ··········· The address that holds pool tokens for token_0 + // + // [13] = [WRITE] tokenVault1 + // ··········· The address that holds pool tokens for token_1 + // + // [14] = [] rent + // ··········· Sysvar for token mint and ATA creation + // + // [15] = [] systemProgram + // ··········· Program to create the position manager state account + // + // [16] = [] tokenProgram + // ··········· Program to create mint account and mint tokens + // + // [17] = [] associatedTokenProgram + // ··········· Program to create an ATA for receiving position NFT + // + // [18] = [] metadataProgram + // ··········· Program to create NFT metadata + // + // [19] = [] tokenProgram2022 + // ··········· Program to create mint account and mint tokens + // + // [20] = [] vault0Mint + // ··········· The mint of token vault 0 + // + // [21] = [] vault1Mint + // ··········· The mint of token vault 1 + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewOpenPositionV2InstructionBuilder creates a new `OpenPositionV2` instruction builder. +func NewOpenPositionV2InstructionBuilder() *OpenPositionV2 { + nd := &OpenPositionV2{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 22), + } + return nd +} + +// SetTickLowerIndex sets the "tickLowerIndex" parameter. +func (inst *OpenPositionV2) SetTickLowerIndex(tickLowerIndex int32) *OpenPositionV2 { + inst.TickLowerIndex = &tickLowerIndex + return inst +} + +// SetTickUpperIndex sets the "tickUpperIndex" parameter. +func (inst *OpenPositionV2) SetTickUpperIndex(tickUpperIndex int32) *OpenPositionV2 { + inst.TickUpperIndex = &tickUpperIndex + return inst +} + +// SetTickArrayLowerStartIndex sets the "tickArrayLowerStartIndex" parameter. +func (inst *OpenPositionV2) SetTickArrayLowerStartIndex(tickArrayLowerStartIndex int32) *OpenPositionV2 { + inst.TickArrayLowerStartIndex = &tickArrayLowerStartIndex + return inst +} + +// SetTickArrayUpperStartIndex sets the "tickArrayUpperStartIndex" parameter. +func (inst *OpenPositionV2) SetTickArrayUpperStartIndex(tickArrayUpperStartIndex int32) *OpenPositionV2 { + inst.TickArrayUpperStartIndex = &tickArrayUpperStartIndex + return inst +} + +// SetLiquidity sets the "liquidity" parameter. +func (inst *OpenPositionV2) SetLiquidity(liquidity ag_binary.Uint128) *OpenPositionV2 { + inst.Liquidity = &liquidity + return inst +} + +// SetAmount0Max sets the "amount0Max" parameter. +func (inst *OpenPositionV2) SetAmount0Max(amount0Max uint64) *OpenPositionV2 { + inst.Amount0Max = &amount0Max + return inst +} + +// SetAmount1Max sets the "amount1Max" parameter. +func (inst *OpenPositionV2) SetAmount1Max(amount1Max uint64) *OpenPositionV2 { + inst.Amount1Max = &amount1Max + return inst +} + +// SetWithMatedata sets the "withMatedata" parameter. +func (inst *OpenPositionV2) SetWithMatedata(withMatedata bool) *OpenPositionV2 { + inst.WithMatedata = &withMatedata + return inst +} + +// SetBaseFlag sets the "baseFlag" parameter. +func (inst *OpenPositionV2) SetBaseFlag(baseFlag bool) *OpenPositionV2 { + inst.BaseFlag = &baseFlag + return inst +} + +// SetPayerAccount sets the "payer" account. +// Pays to mint the position +func (inst *OpenPositionV2) SetPayerAccount(payer ag_solanago.PublicKey) *OpenPositionV2 { + inst.AccountMetaSlice[0] = ag_solanago.Meta(payer).WRITE().SIGNER() + return inst +} + +// GetPayerAccount gets the "payer" account. +// Pays to mint the position +func (inst *OpenPositionV2) GetPayerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetPositionNftOwnerAccount sets the "positionNftOwner" account. +func (inst *OpenPositionV2) SetPositionNftOwnerAccount(positionNftOwner ag_solanago.PublicKey) *OpenPositionV2 { + inst.AccountMetaSlice[1] = ag_solanago.Meta(positionNftOwner) + return inst +} + +// GetPositionNftOwnerAccount gets the "positionNftOwner" account. +func (inst *OpenPositionV2) GetPositionNftOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetPositionNftMintAccount sets the "positionNftMint" account. +// Unique token mint address +func (inst *OpenPositionV2) SetPositionNftMintAccount(positionNftMint ag_solanago.PublicKey) *OpenPositionV2 { + inst.AccountMetaSlice[2] = ag_solanago.Meta(positionNftMint).WRITE().SIGNER() + return inst +} + +// GetPositionNftMintAccount gets the "positionNftMint" account. +// Unique token mint address +func (inst *OpenPositionV2) GetPositionNftMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetPositionNftAccountAccount sets the "positionNftAccount" account. +// Token account where position NFT will be minted +func (inst *OpenPositionV2) SetPositionNftAccountAccount(positionNftAccount ag_solanago.PublicKey) *OpenPositionV2 { + inst.AccountMetaSlice[3] = ag_solanago.Meta(positionNftAccount).WRITE() + return inst +} + +// GetPositionNftAccountAccount gets the "positionNftAccount" account. +// Token account where position NFT will be minted +func (inst *OpenPositionV2) GetPositionNftAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetMetadataAccountAccount sets the "metadataAccount" account. +// To store metaplex metadata +func (inst *OpenPositionV2) SetMetadataAccountAccount(metadataAccount ag_solanago.PublicKey) *OpenPositionV2 { + inst.AccountMetaSlice[4] = ag_solanago.Meta(metadataAccount).WRITE() + return inst +} + +// GetMetadataAccountAccount gets the "metadataAccount" account. +// To store metaplex metadata +func (inst *OpenPositionV2) GetMetadataAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetPoolStateAccount sets the "poolState" account. +// Add liquidity for this pool +func (inst *OpenPositionV2) SetPoolStateAccount(poolState ag_solanago.PublicKey) *OpenPositionV2 { + inst.AccountMetaSlice[5] = ag_solanago.Meta(poolState).WRITE() + return inst +} + +// GetPoolStateAccount gets the "poolState" account. +// Add liquidity for this pool +func (inst *OpenPositionV2) GetPoolStateAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetProtocolPositionAccount sets the "protocolPosition" account. +// Store the information of market marking in range +func (inst *OpenPositionV2) SetProtocolPositionAccount(protocolPosition ag_solanago.PublicKey) *OpenPositionV2 { + inst.AccountMetaSlice[6] = ag_solanago.Meta(protocolPosition).WRITE() + return inst +} + +// GetProtocolPositionAccount gets the "protocolPosition" account. +// Store the information of market marking in range +func (inst *OpenPositionV2) GetProtocolPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetTickArrayLowerAccount sets the "tickArrayLower" account. +func (inst *OpenPositionV2) SetTickArrayLowerAccount(tickArrayLower ag_solanago.PublicKey) *OpenPositionV2 { + inst.AccountMetaSlice[7] = ag_solanago.Meta(tickArrayLower).WRITE() + return inst +} + +// GetTickArrayLowerAccount gets the "tickArrayLower" account. +func (inst *OpenPositionV2) GetTickArrayLowerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetTickArrayUpperAccount sets the "tickArrayUpper" account. +func (inst *OpenPositionV2) SetTickArrayUpperAccount(tickArrayUpper ag_solanago.PublicKey) *OpenPositionV2 { + inst.AccountMetaSlice[8] = ag_solanago.Meta(tickArrayUpper).WRITE() + return inst +} + +// GetTickArrayUpperAccount gets the "tickArrayUpper" account. +func (inst *OpenPositionV2) GetTickArrayUpperAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetPersonalPositionAccount sets the "personalPosition" account. +// personal position state +func (inst *OpenPositionV2) SetPersonalPositionAccount(personalPosition ag_solanago.PublicKey) *OpenPositionV2 { + inst.AccountMetaSlice[9] = ag_solanago.Meta(personalPosition).WRITE() + return inst +} + +// GetPersonalPositionAccount gets the "personalPosition" account. +// personal position state +func (inst *OpenPositionV2) GetPersonalPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetTokenAccount0Account sets the "tokenAccount0" account. +// The token_0 account deposit token to the pool +func (inst *OpenPositionV2) SetTokenAccount0Account(tokenAccount0 ag_solanago.PublicKey) *OpenPositionV2 { + inst.AccountMetaSlice[10] = ag_solanago.Meta(tokenAccount0).WRITE() + return inst +} + +// GetTokenAccount0Account gets the "tokenAccount0" account. +// The token_0 account deposit token to the pool +func (inst *OpenPositionV2) GetTokenAccount0Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetTokenAccount1Account sets the "tokenAccount1" account. +// The token_1 account deposit token to the pool +func (inst *OpenPositionV2) SetTokenAccount1Account(tokenAccount1 ag_solanago.PublicKey) *OpenPositionV2 { + inst.AccountMetaSlice[11] = ag_solanago.Meta(tokenAccount1).WRITE() + return inst +} + +// GetTokenAccount1Account gets the "tokenAccount1" account. +// The token_1 account deposit token to the pool +func (inst *OpenPositionV2) GetTokenAccount1Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetTokenVault0Account sets the "tokenVault0" account. +// The address that holds pool tokens for token_0 +func (inst *OpenPositionV2) SetTokenVault0Account(tokenVault0 ag_solanago.PublicKey) *OpenPositionV2 { + inst.AccountMetaSlice[12] = ag_solanago.Meta(tokenVault0).WRITE() + return inst +} + +// GetTokenVault0Account gets the "tokenVault0" account. +// The address that holds pool tokens for token_0 +func (inst *OpenPositionV2) GetTokenVault0Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetTokenVault1Account sets the "tokenVault1" account. +// The address that holds pool tokens for token_1 +func (inst *OpenPositionV2) SetTokenVault1Account(tokenVault1 ag_solanago.PublicKey) *OpenPositionV2 { + inst.AccountMetaSlice[13] = ag_solanago.Meta(tokenVault1).WRITE() + return inst +} + +// GetTokenVault1Account gets the "tokenVault1" account. +// The address that holds pool tokens for token_1 +func (inst *OpenPositionV2) GetTokenVault1Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetRentAccount sets the "rent" account. +// Sysvar for token mint and ATA creation +func (inst *OpenPositionV2) SetRentAccount(rent ag_solanago.PublicKey) *OpenPositionV2 { + inst.AccountMetaSlice[14] = ag_solanago.Meta(rent) + return inst +} + +// GetRentAccount gets the "rent" account. +// Sysvar for token mint and ATA creation +func (inst *OpenPositionV2) GetRentAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +// Program to create the position manager state account +func (inst *OpenPositionV2) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *OpenPositionV2 { + inst.AccountMetaSlice[15] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +// Program to create the position manager state account +func (inst *OpenPositionV2) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(15) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +// Program to create mint account and mint tokens +func (inst *OpenPositionV2) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *OpenPositionV2 { + inst.AccountMetaSlice[16] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +// Program to create mint account and mint tokens +func (inst *OpenPositionV2) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(16) +} + +// SetAssociatedTokenProgramAccount sets the "associatedTokenProgram" account. +// Program to create an ATA for receiving position NFT +func (inst *OpenPositionV2) SetAssociatedTokenProgramAccount(associatedTokenProgram ag_solanago.PublicKey) *OpenPositionV2 { + inst.AccountMetaSlice[17] = ag_solanago.Meta(associatedTokenProgram) + return inst +} + +// GetAssociatedTokenProgramAccount gets the "associatedTokenProgram" account. +// Program to create an ATA for receiving position NFT +func (inst *OpenPositionV2) GetAssociatedTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(17) +} + +// SetMetadataProgramAccount sets the "metadataProgram" account. +// Program to create NFT metadata +func (inst *OpenPositionV2) SetMetadataProgramAccount(metadataProgram ag_solanago.PublicKey) *OpenPositionV2 { + inst.AccountMetaSlice[18] = ag_solanago.Meta(metadataProgram) + return inst +} + +// GetMetadataProgramAccount gets the "metadataProgram" account. +// Program to create NFT metadata +func (inst *OpenPositionV2) GetMetadataProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(18) +} + +// SetTokenProgram2022Account sets the "tokenProgram2022" account. +// Program to create mint account and mint tokens +func (inst *OpenPositionV2) SetTokenProgram2022Account(tokenProgram2022 ag_solanago.PublicKey) *OpenPositionV2 { + inst.AccountMetaSlice[19] = ag_solanago.Meta(tokenProgram2022) + return inst +} + +// GetTokenProgram2022Account gets the "tokenProgram2022" account. +// Program to create mint account and mint tokens +func (inst *OpenPositionV2) GetTokenProgram2022Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(19) +} + +// SetVault0MintAccount sets the "vault0Mint" account. +// The mint of token vault 0 +func (inst *OpenPositionV2) SetVault0MintAccount(vault0Mint ag_solanago.PublicKey) *OpenPositionV2 { + inst.AccountMetaSlice[20] = ag_solanago.Meta(vault0Mint) + return inst +} + +// GetVault0MintAccount gets the "vault0Mint" account. +// The mint of token vault 0 +func (inst *OpenPositionV2) GetVault0MintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(20) +} + +// SetVault1MintAccount sets the "vault1Mint" account. +// The mint of token vault 1 +func (inst *OpenPositionV2) SetVault1MintAccount(vault1Mint ag_solanago.PublicKey) *OpenPositionV2 { + inst.AccountMetaSlice[21] = ag_solanago.Meta(vault1Mint) + return inst +} + +// GetVault1MintAccount gets the "vault1Mint" account. +// The mint of token vault 1 +func (inst *OpenPositionV2) GetVault1MintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(21) +} + +func (inst OpenPositionV2) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_OpenPositionV2, + }} +} + +// 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 OpenPositionV2) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *OpenPositionV2) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.TickLowerIndex == nil { + return errors.New("TickLowerIndex parameter is not set") + } + if inst.TickUpperIndex == nil { + return errors.New("TickUpperIndex parameter is not set") + } + if inst.TickArrayLowerStartIndex == nil { + return errors.New("TickArrayLowerStartIndex parameter is not set") + } + if inst.TickArrayUpperStartIndex == nil { + return errors.New("TickArrayUpperStartIndex parameter is not set") + } + if inst.Liquidity == nil { + return errors.New("Liquidity parameter is not set") + } + if inst.Amount0Max == nil { + return errors.New("Amount0Max parameter is not set") + } + if inst.Amount1Max == nil { + return errors.New("Amount1Max parameter is not set") + } + if inst.WithMatedata == nil { + return errors.New("WithMatedata parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Payer is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.PositionNftOwner is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.PositionNftMint is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.PositionNftAccount is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.MetadataAccount is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.PoolState is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.ProtocolPosition is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.TickArrayLower is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.TickArrayUpper is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.PersonalPosition is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.TokenAccount0 is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.TokenAccount1 is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.TokenVault0 is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.TokenVault1 is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.Rent is not set") + } + if inst.AccountMetaSlice[15] == nil { + return errors.New("accounts.SystemProgram is not set") + } + if inst.AccountMetaSlice[16] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[17] == nil { + return errors.New("accounts.AssociatedTokenProgram is not set") + } + if inst.AccountMetaSlice[18] == nil { + return errors.New("accounts.MetadataProgram is not set") + } + if inst.AccountMetaSlice[19] == nil { + return errors.New("accounts.TokenProgram2022 is not set") + } + if inst.AccountMetaSlice[20] == nil { + return errors.New("accounts.Vault0Mint is not set") + } + if inst.AccountMetaSlice[21] == nil { + return errors.New("accounts.Vault1Mint is not set") + } + } + return nil +} + +func (inst *OpenPositionV2) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("OpenPositionV2")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=9]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" TickLowerIndex", *inst.TickLowerIndex)) + paramsBranch.Child(ag_format.Param(" TickUpperIndex", *inst.TickUpperIndex)) + paramsBranch.Child(ag_format.Param("TickArrayLowerStartIndex", *inst.TickArrayLowerStartIndex)) + paramsBranch.Child(ag_format.Param("TickArrayUpperStartIndex", *inst.TickArrayUpperStartIndex)) + paramsBranch.Child(ag_format.Param(" Liquidity", *inst.Liquidity)) + paramsBranch.Child(ag_format.Param(" Amount0Max", *inst.Amount0Max)) + paramsBranch.Child(ag_format.Param(" Amount1Max", *inst.Amount1Max)) + paramsBranch.Child(ag_format.Param(" WithMatedata", *inst.WithMatedata)) + paramsBranch.Child(ag_format.Param(" BaseFlag (OPT)", inst.BaseFlag)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=22]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" payer", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" positionNftOwner", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" positionNftMint", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" positionNft", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" metadata", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" poolState", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" protocolPosition", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" tickArrayLower", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" tickArrayUpper", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" personalPosition", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" tokenAccount0", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" tokenAccount1", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" tokenVault0", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" tokenVault1", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta(" rent", inst.AccountMetaSlice.Get(14))) + accountsBranch.Child(ag_format.Meta(" systemProgram", inst.AccountMetaSlice.Get(15))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(16))) + accountsBranch.Child(ag_format.Meta("associatedTokenProgram", inst.AccountMetaSlice.Get(17))) + accountsBranch.Child(ag_format.Meta(" metadataProgram", inst.AccountMetaSlice.Get(18))) + accountsBranch.Child(ag_format.Meta(" tokenProgram2022", inst.AccountMetaSlice.Get(19))) + accountsBranch.Child(ag_format.Meta(" vault0Mint", inst.AccountMetaSlice.Get(20))) + accountsBranch.Child(ag_format.Meta(" vault1Mint", inst.AccountMetaSlice.Get(21))) + }) + }) + }) +} + +func (obj OpenPositionV2) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `TickLowerIndex` param: + err = encoder.Encode(obj.TickLowerIndex) + if err != nil { + return err + } + // Serialize `TickUpperIndex` param: + err = encoder.Encode(obj.TickUpperIndex) + if err != nil { + return err + } + // Serialize `TickArrayLowerStartIndex` param: + err = encoder.Encode(obj.TickArrayLowerStartIndex) + if err != nil { + return err + } + // Serialize `TickArrayUpperStartIndex` param: + err = encoder.Encode(obj.TickArrayUpperStartIndex) + if err != nil { + return err + } + // Serialize `Liquidity` param: + err = encoder.Encode(obj.Liquidity) + if err != nil { + return err + } + // Serialize `Amount0Max` param: + err = encoder.Encode(obj.Amount0Max) + if err != nil { + return err + } + // Serialize `Amount1Max` param: + err = encoder.Encode(obj.Amount1Max) + if err != nil { + return err + } + // Serialize `WithMatedata` param: + err = encoder.Encode(obj.WithMatedata) + if err != nil { + return err + } + // Serialize `BaseFlag` param (optional): + { + if obj.BaseFlag == nil { + err = encoder.WriteBool(false) + if err != nil { + return err + } + } else { + err = encoder.WriteBool(true) + if err != nil { + return err + } + err = encoder.Encode(obj.BaseFlag) + if err != nil { + return err + } + } + } + return nil +} +func (obj *OpenPositionV2) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `TickLowerIndex`: + err = decoder.Decode(&obj.TickLowerIndex) + if err != nil { + return err + } + // Deserialize `TickUpperIndex`: + err = decoder.Decode(&obj.TickUpperIndex) + if err != nil { + return err + } + // Deserialize `TickArrayLowerStartIndex`: + err = decoder.Decode(&obj.TickArrayLowerStartIndex) + if err != nil { + return err + } + // Deserialize `TickArrayUpperStartIndex`: + err = decoder.Decode(&obj.TickArrayUpperStartIndex) + if err != nil { + return err + } + // Deserialize `Liquidity`: + err = decoder.Decode(&obj.Liquidity) + if err != nil { + return err + } + // Deserialize `Amount0Max`: + err = decoder.Decode(&obj.Amount0Max) + if err != nil { + return err + } + // Deserialize `Amount1Max`: + err = decoder.Decode(&obj.Amount1Max) + if err != nil { + return err + } + // Deserialize `WithMatedata`: + err = decoder.Decode(&obj.WithMatedata) + if err != nil { + return err + } + // Deserialize `BaseFlag` (optional): + { + ok, err := decoder.ReadBool() + if err != nil { + return err + } + if ok { + err = decoder.Decode(&obj.BaseFlag) + if err != nil { + return err + } + } + } + return nil +} + +// NewOpenPositionV2Instruction declares a new OpenPositionV2 instruction with the provided parameters and accounts. +func NewOpenPositionV2Instruction( + // Parameters: + tickLowerIndex int32, + tickUpperIndex int32, + tickArrayLowerStartIndex int32, + tickArrayUpperStartIndex int32, + liquidity ag_binary.Uint128, + amount0Max uint64, + amount1Max uint64, + withMatedata bool, + baseFlag bool, + // Accounts: + payer ag_solanago.PublicKey, + positionNftOwner ag_solanago.PublicKey, + positionNftMint ag_solanago.PublicKey, + positionNftAccount ag_solanago.PublicKey, + metadataAccount ag_solanago.PublicKey, + poolState ag_solanago.PublicKey, + protocolPosition ag_solanago.PublicKey, + tickArrayLower ag_solanago.PublicKey, + tickArrayUpper ag_solanago.PublicKey, + personalPosition ag_solanago.PublicKey, + tokenAccount0 ag_solanago.PublicKey, + tokenAccount1 ag_solanago.PublicKey, + tokenVault0 ag_solanago.PublicKey, + tokenVault1 ag_solanago.PublicKey, + rent ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + associatedTokenProgram ag_solanago.PublicKey, + metadataProgram ag_solanago.PublicKey, + tokenProgram2022 ag_solanago.PublicKey, + vault0Mint ag_solanago.PublicKey, + vault1Mint ag_solanago.PublicKey) *OpenPositionV2 { + return NewOpenPositionV2InstructionBuilder(). + SetTickLowerIndex(tickLowerIndex). + SetTickUpperIndex(tickUpperIndex). + SetTickArrayLowerStartIndex(tickArrayLowerStartIndex). + SetTickArrayUpperStartIndex(tickArrayUpperStartIndex). + SetLiquidity(liquidity). + SetAmount0Max(amount0Max). + SetAmount1Max(amount1Max). + SetWithMatedata(withMatedata). + SetBaseFlag(baseFlag). + SetPayerAccount(payer). + SetPositionNftOwnerAccount(positionNftOwner). + SetPositionNftMintAccount(positionNftMint). + SetPositionNftAccountAccount(positionNftAccount). + SetMetadataAccountAccount(metadataAccount). + SetPoolStateAccount(poolState). + SetProtocolPositionAccount(protocolPosition). + SetTickArrayLowerAccount(tickArrayLower). + SetTickArrayUpperAccount(tickArrayUpper). + SetPersonalPositionAccount(personalPosition). + SetTokenAccount0Account(tokenAccount0). + SetTokenAccount1Account(tokenAccount1). + SetTokenVault0Account(tokenVault0). + SetTokenVault1Account(tokenVault1). + SetRentAccount(rent). + SetSystemProgramAccount(systemProgram). + SetTokenProgramAccount(tokenProgram). + SetAssociatedTokenProgramAccount(associatedTokenProgram). + SetMetadataProgramAccount(metadataProgram). + SetTokenProgram2022Account(tokenProgram2022). + SetVault0MintAccount(vault0Mint). + SetVault1MintAccount(vault1Mint) +} diff --git a/programs/raydiumclmm/OpenPositionV2_test.go b/programs/raydiumclmm/OpenPositionV2_test.go new file mode 100644 index 00000000..71514de2 --- /dev/null +++ b/programs/raydiumclmm/OpenPositionV2_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_OpenPositionV2(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("OpenPositionV2"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(OpenPositionV2) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(OpenPositionV2) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/raydiumclmm/OpenPosition_test.go b/programs/raydiumclmm/OpenPosition_test.go new file mode 100644 index 00000000..8f6eecbb --- /dev/null +++ b/programs/raydiumclmm/OpenPosition_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_OpenPosition(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("OpenPosition"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(OpenPosition) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(OpenPosition) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/raydiumclmm/SetRewardParams.go b/programs/raydiumclmm/SetRewardParams.go new file mode 100644 index 00000000..cffcbc6f --- /dev/null +++ b/programs/raydiumclmm/SetRewardParams.go @@ -0,0 +1,313 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "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" +) + +// Restset reward param, start a new reward cycle or extend the current cycle. +// +// # Arguments +// +// * `ctx` - The context of accounts +// * `reward_index` - The index of reward token in the pool. +// * `emissions_per_second_x64` - The per second emission reward, when extend the current cycle, +// new value can't be less than old value +// * `open_time` - reward open timestamp, must be set when state a new cycle +// * `end_time` - reward end timestamp +// +type SetRewardParams struct { + RewardIndex *uint8 + EmissionsPerSecondX64 *ag_binary.Uint128 + OpenTime *uint64 + EndTime *uint64 + + // [0] = [SIGNER] authority + // ··········· Address to be set as protocol owner. It pays to create factory state account. + // + // [1] = [] ammConfig + // + // [2] = [WRITE] poolState + // + // [3] = [] operationState + // ··········· load info from the account to judge reward permission + // + // [4] = [] tokenProgram + // ··········· Token program + // + // [5] = [] tokenProgram2022 + // ··········· Token program 2022 + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewSetRewardParamsInstructionBuilder creates a new `SetRewardParams` instruction builder. +func NewSetRewardParamsInstructionBuilder() *SetRewardParams { + nd := &SetRewardParams{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 6), + } + return nd +} + +// SetRewardIndex sets the "rewardIndex" parameter. +func (inst *SetRewardParams) SetRewardIndex(rewardIndex uint8) *SetRewardParams { + inst.RewardIndex = &rewardIndex + return inst +} + +// SetEmissionsPerSecondX64 sets the "emissionsPerSecondX64" parameter. +func (inst *SetRewardParams) SetEmissionsPerSecondX64(emissionsPerSecondX64 ag_binary.Uint128) *SetRewardParams { + inst.EmissionsPerSecondX64 = &emissionsPerSecondX64 + return inst +} + +// SetOpenTime sets the "openTime" parameter. +func (inst *SetRewardParams) SetOpenTime(openTime uint64) *SetRewardParams { + inst.OpenTime = &openTime + return inst +} + +// SetEndTime sets the "endTime" parameter. +func (inst *SetRewardParams) SetEndTime(endTime uint64) *SetRewardParams { + inst.EndTime = &endTime + return inst +} + +// SetAuthorityAccount sets the "authority" account. +// Address to be set as protocol owner. It pays to create factory state account. +func (inst *SetRewardParams) SetAuthorityAccount(authority ag_solanago.PublicKey) *SetRewardParams { + inst.AccountMetaSlice[0] = ag_solanago.Meta(authority).SIGNER() + return inst +} + +// GetAuthorityAccount gets the "authority" account. +// Address to be set as protocol owner. It pays to create factory state account. +func (inst *SetRewardParams) GetAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetAmmConfigAccount sets the "ammConfig" account. +func (inst *SetRewardParams) SetAmmConfigAccount(ammConfig ag_solanago.PublicKey) *SetRewardParams { + inst.AccountMetaSlice[1] = ag_solanago.Meta(ammConfig) + return inst +} + +// GetAmmConfigAccount gets the "ammConfig" account. +func (inst *SetRewardParams) GetAmmConfigAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetPoolStateAccount sets the "poolState" account. +func (inst *SetRewardParams) SetPoolStateAccount(poolState ag_solanago.PublicKey) *SetRewardParams { + inst.AccountMetaSlice[2] = ag_solanago.Meta(poolState).WRITE() + return inst +} + +// GetPoolStateAccount gets the "poolState" account. +func (inst *SetRewardParams) GetPoolStateAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetOperationStateAccount sets the "operationState" account. +// load info from the account to judge reward permission +func (inst *SetRewardParams) SetOperationStateAccount(operationState ag_solanago.PublicKey) *SetRewardParams { + inst.AccountMetaSlice[3] = ag_solanago.Meta(operationState) + return inst +} + +// GetOperationStateAccount gets the "operationState" account. +// load info from the account to judge reward permission +func (inst *SetRewardParams) GetOperationStateAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +// Token program +func (inst *SetRewardParams) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *SetRewardParams { + inst.AccountMetaSlice[4] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +// Token program +func (inst *SetRewardParams) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetTokenProgram2022Account sets the "tokenProgram2022" account. +// Token program 2022 +func (inst *SetRewardParams) SetTokenProgram2022Account(tokenProgram2022 ag_solanago.PublicKey) *SetRewardParams { + inst.AccountMetaSlice[5] = ag_solanago.Meta(tokenProgram2022) + return inst +} + +// GetTokenProgram2022Account gets the "tokenProgram2022" account. +// Token program 2022 +func (inst *SetRewardParams) GetTokenProgram2022Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +func (inst SetRewardParams) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_SetRewardParams, + }} +} + +// 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 SetRewardParams) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *SetRewardParams) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.RewardIndex == nil { + return errors.New("RewardIndex parameter is not set") + } + if inst.EmissionsPerSecondX64 == nil { + return errors.New("EmissionsPerSecondX64 parameter is not set") + } + if inst.OpenTime == nil { + return errors.New("OpenTime parameter is not set") + } + if inst.EndTime == nil { + return errors.New("EndTime parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Authority is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.AmmConfig is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.PoolState is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.OperationState is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.TokenProgram2022 is not set") + } + } + return nil +} + +func (inst *SetRewardParams) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("SetRewardParams")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=4]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" RewardIndex", *inst.RewardIndex)) + paramsBranch.Child(ag_format.Param("EmissionsPerSecondX64", *inst.EmissionsPerSecondX64)) + paramsBranch.Child(ag_format.Param(" OpenTime", *inst.OpenTime)) + paramsBranch.Child(ag_format.Param(" EndTime", *inst.EndTime)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=6]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" authority", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" ammConfig", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" poolState", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" operationState", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta("tokenProgram2022", inst.AccountMetaSlice.Get(5))) + }) + }) + }) +} + +func (obj SetRewardParams) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `RewardIndex` param: + err = encoder.Encode(obj.RewardIndex) + if err != nil { + return err + } + // Serialize `EmissionsPerSecondX64` param: + err = encoder.Encode(obj.EmissionsPerSecondX64) + if err != nil { + return err + } + // Serialize `OpenTime` param: + err = encoder.Encode(obj.OpenTime) + if err != nil { + return err + } + // Serialize `EndTime` param: + err = encoder.Encode(obj.EndTime) + if err != nil { + return err + } + return nil +} +func (obj *SetRewardParams) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `RewardIndex`: + err = decoder.Decode(&obj.RewardIndex) + if err != nil { + return err + } + // Deserialize `EmissionsPerSecondX64`: + err = decoder.Decode(&obj.EmissionsPerSecondX64) + if err != nil { + return err + } + // Deserialize `OpenTime`: + err = decoder.Decode(&obj.OpenTime) + if err != nil { + return err + } + // Deserialize `EndTime`: + err = decoder.Decode(&obj.EndTime) + if err != nil { + return err + } + return nil +} + +// NewSetRewardParamsInstruction declares a new SetRewardParams instruction with the provided parameters and accounts. +func NewSetRewardParamsInstruction( + // Parameters: + rewardIndex uint8, + emissionsPerSecondX64 ag_binary.Uint128, + openTime uint64, + endTime uint64, + // Accounts: + authority ag_solanago.PublicKey, + ammConfig ag_solanago.PublicKey, + poolState ag_solanago.PublicKey, + operationState ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + tokenProgram2022 ag_solanago.PublicKey) *SetRewardParams { + return NewSetRewardParamsInstructionBuilder(). + SetRewardIndex(rewardIndex). + SetEmissionsPerSecondX64(emissionsPerSecondX64). + SetOpenTime(openTime). + SetEndTime(endTime). + SetAuthorityAccount(authority). + SetAmmConfigAccount(ammConfig). + SetPoolStateAccount(poolState). + SetOperationStateAccount(operationState). + SetTokenProgramAccount(tokenProgram). + SetTokenProgram2022Account(tokenProgram2022) +} diff --git a/programs/raydiumclmm/SetRewardParams_test.go b/programs/raydiumclmm/SetRewardParams_test.go new file mode 100644 index 00000000..f64caaa9 --- /dev/null +++ b/programs/raydiumclmm/SetRewardParams_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_SetRewardParams(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("SetRewardParams"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(SetRewardParams) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(SetRewardParams) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/raydiumclmm/Swap.go b/programs/raydiumclmm/Swap.go new file mode 100644 index 00000000..604526d9 --- /dev/null +++ b/programs/raydiumclmm/Swap.go @@ -0,0 +1,403 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "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" +) + +// Swaps one token for as much as possible of another token across a single pool +// +// # Arguments +// +// * `ctx` - The context of accounts +// * `amount` - Arranged in pairs with other_amount_threshold. (amount_in, amount_out_minimum) or (amount_out, amount_in_maximum) +// * `other_amount_threshold` - For slippage check +// * `sqrt_price_limit` - The Q64.64 sqrt price √P limit. If zero for one, the price cannot +// * `is_base_input` - swap base input or swap base output +// +type Swap struct { + Amount *uint64 + OtherAmountThreshold *uint64 + SqrtPriceLimitX64 *ag_binary.Uint128 + IsBaseInput *bool + + // [0] = [SIGNER] payer + // ··········· The user performing the swap + // + // [1] = [] ammConfig + // ··········· The factory state to read protocol fees + // + // [2] = [WRITE] poolState + // ··········· The program account of the pool in which the swap will be performed + // + // [3] = [WRITE] inputTokenAccount + // ··········· The user token account for input token + // + // [4] = [WRITE] outputTokenAccount + // ··········· The user token account for output token + // + // [5] = [WRITE] inputVault + // ··········· The vault token account for input token + // + // [6] = [WRITE] outputVault + // ··········· The vault token account for output token + // + // [7] = [WRITE] observationState + // ··········· The program account for the most recent oracle observation + // + // [8] = [] tokenProgram + // ··········· SPL program for token transfers + // + // [9] = [WRITE] tickArray + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewSwapInstructionBuilder creates a new `Swap` instruction builder. +func NewSwapInstructionBuilder() *Swap { + nd := &Swap{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 10), + } + return nd +} + +// SetAmount sets the "amount" parameter. +func (inst *Swap) SetAmount(amount uint64) *Swap { + inst.Amount = &amount + return inst +} + +// SetOtherAmountThreshold sets the "otherAmountThreshold" parameter. +func (inst *Swap) SetOtherAmountThreshold(otherAmountThreshold uint64) *Swap { + inst.OtherAmountThreshold = &otherAmountThreshold + return inst +} + +// SetSqrtPriceLimitX64 sets the "sqrtPriceLimitX64" parameter. +func (inst *Swap) SetSqrtPriceLimitX64(sqrtPriceLimitX64 ag_binary.Uint128) *Swap { + inst.SqrtPriceLimitX64 = &sqrtPriceLimitX64 + return inst +} + +// SetIsBaseInput sets the "isBaseInput" parameter. +func (inst *Swap) SetIsBaseInput(isBaseInput bool) *Swap { + inst.IsBaseInput = &isBaseInput + return inst +} + +// SetPayerAccount sets the "payer" account. +// The user performing the swap +func (inst *Swap) SetPayerAccount(payer ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[0] = ag_solanago.Meta(payer).SIGNER() + return inst +} + +// GetPayerAccount gets the "payer" account. +// The user performing the swap +func (inst *Swap) GetPayerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetAmmConfigAccount sets the "ammConfig" account. +// The factory state to read protocol fees +func (inst *Swap) SetAmmConfigAccount(ammConfig ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[1] = ag_solanago.Meta(ammConfig) + return inst +} + +// GetAmmConfigAccount gets the "ammConfig" account. +// The factory state to read protocol fees +func (inst *Swap) GetAmmConfigAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetPoolStateAccount sets the "poolState" account. +// The program account of the pool in which the swap will be performed +func (inst *Swap) SetPoolStateAccount(poolState ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[2] = ag_solanago.Meta(poolState).WRITE() + return inst +} + +// GetPoolStateAccount gets the "poolState" account. +// The program account of the pool in which the swap will be performed +func (inst *Swap) GetPoolStateAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetInputTokenAccountAccount sets the "inputTokenAccount" account. +// The user token account for input token +func (inst *Swap) SetInputTokenAccountAccount(inputTokenAccount ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[3] = ag_solanago.Meta(inputTokenAccount).WRITE() + return inst +} + +// GetInputTokenAccountAccount gets the "inputTokenAccount" account. +// The user token account for input token +func (inst *Swap) GetInputTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetOutputTokenAccountAccount sets the "outputTokenAccount" account. +// The user token account for output token +func (inst *Swap) SetOutputTokenAccountAccount(outputTokenAccount ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[4] = ag_solanago.Meta(outputTokenAccount).WRITE() + return inst +} + +// GetOutputTokenAccountAccount gets the "outputTokenAccount" account. +// The user token account for output token +func (inst *Swap) GetOutputTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetInputVaultAccount sets the "inputVault" account. +// The vault token account for input token +func (inst *Swap) SetInputVaultAccount(inputVault ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[5] = ag_solanago.Meta(inputVault).WRITE() + return inst +} + +// GetInputVaultAccount gets the "inputVault" account. +// The vault token account for input token +func (inst *Swap) GetInputVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetOutputVaultAccount sets the "outputVault" account. +// The vault token account for output token +func (inst *Swap) SetOutputVaultAccount(outputVault ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[6] = ag_solanago.Meta(outputVault).WRITE() + return inst +} + +// GetOutputVaultAccount gets the "outputVault" account. +// The vault token account for output token +func (inst *Swap) GetOutputVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetObservationStateAccount sets the "observationState" account. +// The program account for the most recent oracle observation +func (inst *Swap) SetObservationStateAccount(observationState ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[7] = ag_solanago.Meta(observationState).WRITE() + return inst +} + +// GetObservationStateAccount gets the "observationState" account. +// The program account for the most recent oracle observation +func (inst *Swap) GetObservationStateAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +// SPL program for token transfers +func (inst *Swap) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[8] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +// SPL program for token transfers +func (inst *Swap) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetTickArrayAccount sets the "tickArray" account. +func (inst *Swap) SetTickArrayAccount(tickArray ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[9] = ag_solanago.Meta(tickArray).WRITE() + return inst +} + +// GetTickArrayAccount gets the "tickArray" account. +func (inst *Swap) GetTickArrayAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +func (inst Swap) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_Swap, + }} +} + +// 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 Swap) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *Swap) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.Amount == nil { + return errors.New("Amount parameter is not set") + } + if inst.OtherAmountThreshold == nil { + return errors.New("OtherAmountThreshold parameter is not set") + } + if inst.SqrtPriceLimitX64 == nil { + return errors.New("SqrtPriceLimitX64 parameter is not set") + } + if inst.IsBaseInput == nil { + return errors.New("IsBaseInput parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Payer is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.AmmConfig is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.PoolState is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.InputTokenAccount is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.OutputTokenAccount is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.InputVault is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.OutputVault is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.ObservationState is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.TickArray is not set") + } + } + return nil +} + +func (inst *Swap) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("Swap")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=4]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" Amount", *inst.Amount)) + paramsBranch.Child(ag_format.Param("OtherAmountThreshold", *inst.OtherAmountThreshold)) + paramsBranch.Child(ag_format.Param(" SqrtPriceLimitX64", *inst.SqrtPriceLimitX64)) + paramsBranch.Child(ag_format.Param(" IsBaseInput", *inst.IsBaseInput)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=10]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" payer", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" ammConfig", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" poolState", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" inputToken", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" outputToken", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" inputVault", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" outputVault", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta("observationState", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" tickArray", inst.AccountMetaSlice.Get(9))) + }) + }) + }) +} + +func (obj Swap) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Amount` param: + err = encoder.Encode(obj.Amount) + if err != nil { + return err + } + // Serialize `OtherAmountThreshold` param: + err = encoder.Encode(obj.OtherAmountThreshold) + if err != nil { + return err + } + // Serialize `SqrtPriceLimitX64` param: + err = encoder.Encode(obj.SqrtPriceLimitX64) + if err != nil { + return err + } + // Serialize `IsBaseInput` param: + err = encoder.Encode(obj.IsBaseInput) + if err != nil { + return err + } + return nil +} +func (obj *Swap) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Amount`: + err = decoder.Decode(&obj.Amount) + if err != nil { + return err + } + // Deserialize `OtherAmountThreshold`: + err = decoder.Decode(&obj.OtherAmountThreshold) + if err != nil { + return err + } + // Deserialize `SqrtPriceLimitX64`: + err = decoder.Decode(&obj.SqrtPriceLimitX64) + if err != nil { + return err + } + // Deserialize `IsBaseInput`: + err = decoder.Decode(&obj.IsBaseInput) + if err != nil { + return err + } + return nil +} + +// NewSwapInstruction declares a new Swap instruction with the provided parameters and accounts. +func NewSwapInstruction( + // Parameters: + amount uint64, + otherAmountThreshold uint64, + sqrtPriceLimitX64 ag_binary.Uint128, + isBaseInput bool, + // Accounts: + payer ag_solanago.PublicKey, + ammConfig ag_solanago.PublicKey, + poolState ag_solanago.PublicKey, + inputTokenAccount ag_solanago.PublicKey, + outputTokenAccount ag_solanago.PublicKey, + inputVault ag_solanago.PublicKey, + outputVault ag_solanago.PublicKey, + observationState ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + tickArray ag_solanago.PublicKey) *Swap { + return NewSwapInstructionBuilder(). + SetAmount(amount). + SetOtherAmountThreshold(otherAmountThreshold). + SetSqrtPriceLimitX64(sqrtPriceLimitX64). + SetIsBaseInput(isBaseInput). + SetPayerAccount(payer). + SetAmmConfigAccount(ammConfig). + SetPoolStateAccount(poolState). + SetInputTokenAccountAccount(inputTokenAccount). + SetOutputTokenAccountAccount(outputTokenAccount). + SetInputVaultAccount(inputVault). + SetOutputVaultAccount(outputVault). + SetObservationStateAccount(observationState). + SetTokenProgramAccount(tokenProgram). + SetTickArrayAccount(tickArray) +} diff --git a/programs/raydiumclmm/SwapRouterBaseIn.go b/programs/raydiumclmm/SwapRouterBaseIn.go new file mode 100644 index 00000000..15adcff3 --- /dev/null +++ b/programs/raydiumclmm/SwapRouterBaseIn.go @@ -0,0 +1,267 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "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" +) + +// Swap token for as much as possible of another token across the path provided, base input +// +// # Arguments +// +// * `ctx` - The context of accounts +// * `amount_in` - Token amount to be swapped in +// * `amount_out_minimum` - Panic if output amount is below minimum amount. For slippage. +// +type SwapRouterBaseIn struct { + AmountIn *uint64 + AmountOutMinimum *uint64 + + // [0] = [SIGNER] payer + // ··········· The user performing the swap + // + // [1] = [WRITE] inputTokenAccount + // ··········· The token account that pays input tokens for the swap + // + // [2] = [WRITE] inputTokenMint + // ··········· The mint of input token + // + // [3] = [] tokenProgram + // ··········· SPL program for token transfers + // + // [4] = [] tokenProgram2022 + // ··········· SPL program 2022 for token transfers + // + // [5] = [] memoProgram + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewSwapRouterBaseInInstructionBuilder creates a new `SwapRouterBaseIn` instruction builder. +func NewSwapRouterBaseInInstructionBuilder() *SwapRouterBaseIn { + nd := &SwapRouterBaseIn{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 6), + } + return nd +} + +// SetAmountIn sets the "amountIn" parameter. +func (inst *SwapRouterBaseIn) SetAmountIn(amountIn uint64) *SwapRouterBaseIn { + inst.AmountIn = &amountIn + return inst +} + +// SetAmountOutMinimum sets the "amountOutMinimum" parameter. +func (inst *SwapRouterBaseIn) SetAmountOutMinimum(amountOutMinimum uint64) *SwapRouterBaseIn { + inst.AmountOutMinimum = &amountOutMinimum + return inst +} + +// SetPayerAccount sets the "payer" account. +// The user performing the swap +func (inst *SwapRouterBaseIn) SetPayerAccount(payer ag_solanago.PublicKey) *SwapRouterBaseIn { + inst.AccountMetaSlice[0] = ag_solanago.Meta(payer).SIGNER() + return inst +} + +// GetPayerAccount gets the "payer" account. +// The user performing the swap +func (inst *SwapRouterBaseIn) GetPayerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetInputTokenAccountAccount sets the "inputTokenAccount" account. +// The token account that pays input tokens for the swap +func (inst *SwapRouterBaseIn) SetInputTokenAccountAccount(inputTokenAccount ag_solanago.PublicKey) *SwapRouterBaseIn { + inst.AccountMetaSlice[1] = ag_solanago.Meta(inputTokenAccount).WRITE() + return inst +} + +// GetInputTokenAccountAccount gets the "inputTokenAccount" account. +// The token account that pays input tokens for the swap +func (inst *SwapRouterBaseIn) GetInputTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetInputTokenMintAccount sets the "inputTokenMint" account. +// The mint of input token +func (inst *SwapRouterBaseIn) SetInputTokenMintAccount(inputTokenMint ag_solanago.PublicKey) *SwapRouterBaseIn { + inst.AccountMetaSlice[2] = ag_solanago.Meta(inputTokenMint).WRITE() + return inst +} + +// GetInputTokenMintAccount gets the "inputTokenMint" account. +// The mint of input token +func (inst *SwapRouterBaseIn) GetInputTokenMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +// SPL program for token transfers +func (inst *SwapRouterBaseIn) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *SwapRouterBaseIn { + inst.AccountMetaSlice[3] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +// SPL program for token transfers +func (inst *SwapRouterBaseIn) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetTokenProgram2022Account sets the "tokenProgram2022" account. +// SPL program 2022 for token transfers +func (inst *SwapRouterBaseIn) SetTokenProgram2022Account(tokenProgram2022 ag_solanago.PublicKey) *SwapRouterBaseIn { + inst.AccountMetaSlice[4] = ag_solanago.Meta(tokenProgram2022) + return inst +} + +// GetTokenProgram2022Account gets the "tokenProgram2022" account. +// SPL program 2022 for token transfers +func (inst *SwapRouterBaseIn) GetTokenProgram2022Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetMemoProgramAccount sets the "memoProgram" account. +func (inst *SwapRouterBaseIn) SetMemoProgramAccount(memoProgram ag_solanago.PublicKey) *SwapRouterBaseIn { + inst.AccountMetaSlice[5] = ag_solanago.Meta(memoProgram) + return inst +} + +// GetMemoProgramAccount gets the "memoProgram" account. +func (inst *SwapRouterBaseIn) GetMemoProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +func (inst SwapRouterBaseIn) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_SwapRouterBaseIn, + }} +} + +// 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 SwapRouterBaseIn) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *SwapRouterBaseIn) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.AmountIn == nil { + return errors.New("AmountIn parameter is not set") + } + if inst.AmountOutMinimum == nil { + return errors.New("AmountOutMinimum parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Payer is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.InputTokenAccount is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.InputTokenMint is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.TokenProgram2022 is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.MemoProgram is not set") + } + } + return nil +} + +func (inst *SwapRouterBaseIn) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("SwapRouterBaseIn")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=2]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" AmountIn", *inst.AmountIn)) + paramsBranch.Child(ag_format.Param("AmountOutMinimum", *inst.AmountOutMinimum)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=6]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" payer", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" inputToken", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" inputTokenMint", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta("tokenProgram2022", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" memoProgram", inst.AccountMetaSlice.Get(5))) + }) + }) + }) +} + +func (obj SwapRouterBaseIn) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `AmountIn` param: + err = encoder.Encode(obj.AmountIn) + if err != nil { + return err + } + // Serialize `AmountOutMinimum` param: + err = encoder.Encode(obj.AmountOutMinimum) + if err != nil { + return err + } + return nil +} +func (obj *SwapRouterBaseIn) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `AmountIn`: + err = decoder.Decode(&obj.AmountIn) + if err != nil { + return err + } + // Deserialize `AmountOutMinimum`: + err = decoder.Decode(&obj.AmountOutMinimum) + if err != nil { + return err + } + return nil +} + +// NewSwapRouterBaseInInstruction declares a new SwapRouterBaseIn instruction with the provided parameters and accounts. +func NewSwapRouterBaseInInstruction( + // Parameters: + amountIn uint64, + amountOutMinimum uint64, + // Accounts: + payer ag_solanago.PublicKey, + inputTokenAccount ag_solanago.PublicKey, + inputTokenMint ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + tokenProgram2022 ag_solanago.PublicKey, + memoProgram ag_solanago.PublicKey) *SwapRouterBaseIn { + return NewSwapRouterBaseInInstructionBuilder(). + SetAmountIn(amountIn). + SetAmountOutMinimum(amountOutMinimum). + SetPayerAccount(payer). + SetInputTokenAccountAccount(inputTokenAccount). + SetInputTokenMintAccount(inputTokenMint). + SetTokenProgramAccount(tokenProgram). + SetTokenProgram2022Account(tokenProgram2022). + SetMemoProgramAccount(memoProgram) +} diff --git a/programs/raydiumclmm/SwapRouterBaseIn_test.go b/programs/raydiumclmm/SwapRouterBaseIn_test.go new file mode 100644 index 00000000..7571baaf --- /dev/null +++ b/programs/raydiumclmm/SwapRouterBaseIn_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_SwapRouterBaseIn(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("SwapRouterBaseIn"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(SwapRouterBaseIn) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(SwapRouterBaseIn) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/raydiumclmm/SwapV2.go b/programs/raydiumclmm/SwapV2.go new file mode 100644 index 00000000..aa6d7aab --- /dev/null +++ b/programs/raydiumclmm/SwapV2.go @@ -0,0 +1,469 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "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" +) + +// Swaps one token for as much as possible of another token across a single pool, support token program 2022 +// +// # Arguments +// +// * `ctx` - The context of accounts +// * `amount` - Arranged in pairs with other_amount_threshold. (amount_in, amount_out_minimum) or (amount_out, amount_in_maximum) +// * `other_amount_threshold` - For slippage check +// * `sqrt_price_limit` - The Q64.64 sqrt price √P limit. If zero for one, the price cannot +// * `is_base_input` - swap base input or swap base output +// +type SwapV2 struct { + Amount *uint64 + OtherAmountThreshold *uint64 + SqrtPriceLimitX64 *ag_binary.Uint128 + IsBaseInput *bool + + // [0] = [SIGNER] payer + // ··········· The user performing the swap + // + // [1] = [] ammConfig + // ··········· The factory state to read protocol fees + // + // [2] = [WRITE] poolState + // ··········· The program account of the pool in which the swap will be performed + // + // [3] = [WRITE] inputTokenAccount + // ··········· The user token account for input token + // + // [4] = [WRITE] outputTokenAccount + // ··········· The user token account for output token + // + // [5] = [WRITE] inputVault + // ··········· The vault token account for input token + // + // [6] = [WRITE] outputVault + // ··········· The vault token account for output token + // + // [7] = [WRITE] observationState + // ··········· The program account for the most recent oracle observation + // + // [8] = [] tokenProgram + // ··········· SPL program for token transfers + // + // [9] = [] tokenProgram2022 + // ··········· SPL program 2022 for token transfers + // + // [10] = [] memoProgram + // + // [11] = [] inputVaultMint + // ··········· The mint of token vault 0 + // + // [12] = [] outputVaultMint + // ··········· The mint of token vault 1 + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewSwapV2InstructionBuilder creates a new `SwapV2` instruction builder. +func NewSwapV2InstructionBuilder() *SwapV2 { + nd := &SwapV2{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 13), + } + return nd +} + +// SetAmount sets the "amount" parameter. +func (inst *SwapV2) SetAmount(amount uint64) *SwapV2 { + inst.Amount = &amount + return inst +} + +// SetOtherAmountThreshold sets the "otherAmountThreshold" parameter. +func (inst *SwapV2) SetOtherAmountThreshold(otherAmountThreshold uint64) *SwapV2 { + inst.OtherAmountThreshold = &otherAmountThreshold + return inst +} + +// SetSqrtPriceLimitX64 sets the "sqrtPriceLimitX64" parameter. +func (inst *SwapV2) SetSqrtPriceLimitX64(sqrtPriceLimitX64 ag_binary.Uint128) *SwapV2 { + inst.SqrtPriceLimitX64 = &sqrtPriceLimitX64 + return inst +} + +// SetIsBaseInput sets the "isBaseInput" parameter. +func (inst *SwapV2) SetIsBaseInput(isBaseInput bool) *SwapV2 { + inst.IsBaseInput = &isBaseInput + return inst +} + +// SetPayerAccount sets the "payer" account. +// The user performing the swap +func (inst *SwapV2) SetPayerAccount(payer ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[0] = ag_solanago.Meta(payer).SIGNER() + return inst +} + +// GetPayerAccount gets the "payer" account. +// The user performing the swap +func (inst *SwapV2) GetPayerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetAmmConfigAccount sets the "ammConfig" account. +// The factory state to read protocol fees +func (inst *SwapV2) SetAmmConfigAccount(ammConfig ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[1] = ag_solanago.Meta(ammConfig) + return inst +} + +// GetAmmConfigAccount gets the "ammConfig" account. +// The factory state to read protocol fees +func (inst *SwapV2) GetAmmConfigAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetPoolStateAccount sets the "poolState" account. +// The program account of the pool in which the swap will be performed +func (inst *SwapV2) SetPoolStateAccount(poolState ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[2] = ag_solanago.Meta(poolState).WRITE() + return inst +} + +// GetPoolStateAccount gets the "poolState" account. +// The program account of the pool in which the swap will be performed +func (inst *SwapV2) GetPoolStateAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetInputTokenAccountAccount sets the "inputTokenAccount" account. +// The user token account for input token +func (inst *SwapV2) SetInputTokenAccountAccount(inputTokenAccount ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[3] = ag_solanago.Meta(inputTokenAccount).WRITE() + return inst +} + +// GetInputTokenAccountAccount gets the "inputTokenAccount" account. +// The user token account for input token +func (inst *SwapV2) GetInputTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetOutputTokenAccountAccount sets the "outputTokenAccount" account. +// The user token account for output token +func (inst *SwapV2) SetOutputTokenAccountAccount(outputTokenAccount ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[4] = ag_solanago.Meta(outputTokenAccount).WRITE() + return inst +} + +// GetOutputTokenAccountAccount gets the "outputTokenAccount" account. +// The user token account for output token +func (inst *SwapV2) GetOutputTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetInputVaultAccount sets the "inputVault" account. +// The vault token account for input token +func (inst *SwapV2) SetInputVaultAccount(inputVault ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[5] = ag_solanago.Meta(inputVault).WRITE() + return inst +} + +// GetInputVaultAccount gets the "inputVault" account. +// The vault token account for input token +func (inst *SwapV2) GetInputVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetOutputVaultAccount sets the "outputVault" account. +// The vault token account for output token +func (inst *SwapV2) SetOutputVaultAccount(outputVault ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[6] = ag_solanago.Meta(outputVault).WRITE() + return inst +} + +// GetOutputVaultAccount gets the "outputVault" account. +// The vault token account for output token +func (inst *SwapV2) GetOutputVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetObservationStateAccount sets the "observationState" account. +// The program account for the most recent oracle observation +func (inst *SwapV2) SetObservationStateAccount(observationState ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[7] = ag_solanago.Meta(observationState).WRITE() + return inst +} + +// GetObservationStateAccount gets the "observationState" account. +// The program account for the most recent oracle observation +func (inst *SwapV2) GetObservationStateAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +// SPL program for token transfers +func (inst *SwapV2) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[8] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +// SPL program for token transfers +func (inst *SwapV2) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetTokenProgram2022Account sets the "tokenProgram2022" account. +// SPL program 2022 for token transfers +func (inst *SwapV2) SetTokenProgram2022Account(tokenProgram2022 ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[9] = ag_solanago.Meta(tokenProgram2022) + return inst +} + +// GetTokenProgram2022Account gets the "tokenProgram2022" account. +// SPL program 2022 for token transfers +func (inst *SwapV2) GetTokenProgram2022Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetMemoProgramAccount sets the "memoProgram" account. +func (inst *SwapV2) SetMemoProgramAccount(memoProgram ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[10] = ag_solanago.Meta(memoProgram) + return inst +} + +// GetMemoProgramAccount gets the "memoProgram" account. +func (inst *SwapV2) GetMemoProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetInputVaultMintAccount sets the "inputVaultMint" account. +// The mint of token vault 0 +func (inst *SwapV2) SetInputVaultMintAccount(inputVaultMint ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[11] = ag_solanago.Meta(inputVaultMint) + return inst +} + +// GetInputVaultMintAccount gets the "inputVaultMint" account. +// The mint of token vault 0 +func (inst *SwapV2) GetInputVaultMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetOutputVaultMintAccount sets the "outputVaultMint" account. +// The mint of token vault 1 +func (inst *SwapV2) SetOutputVaultMintAccount(outputVaultMint ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[12] = ag_solanago.Meta(outputVaultMint) + return inst +} + +// GetOutputVaultMintAccount gets the "outputVaultMint" account. +// The mint of token vault 1 +func (inst *SwapV2) GetOutputVaultMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +func (inst SwapV2) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_SwapV2, + }} +} + +// 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 SwapV2) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *SwapV2) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.Amount == nil { + return errors.New("Amount parameter is not set") + } + if inst.OtherAmountThreshold == nil { + return errors.New("OtherAmountThreshold parameter is not set") + } + if inst.SqrtPriceLimitX64 == nil { + return errors.New("SqrtPriceLimitX64 parameter is not set") + } + if inst.IsBaseInput == nil { + return errors.New("IsBaseInput parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Payer is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.AmmConfig is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.PoolState is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.InputTokenAccount is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.OutputTokenAccount is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.InputVault is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.OutputVault is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.ObservationState is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.TokenProgram2022 is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.MemoProgram is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.InputVaultMint is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.OutputVaultMint is not set") + } + } + return nil +} + +func (inst *SwapV2) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("SwapV2")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=4]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" Amount", *inst.Amount)) + paramsBranch.Child(ag_format.Param("OtherAmountThreshold", *inst.OtherAmountThreshold)) + paramsBranch.Child(ag_format.Param(" SqrtPriceLimitX64", *inst.SqrtPriceLimitX64)) + paramsBranch.Child(ag_format.Param(" IsBaseInput", *inst.IsBaseInput)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=13]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" payer", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" ammConfig", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" poolState", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" inputToken", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" outputToken", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" inputVault", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" outputVault", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta("observationState", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta("tokenProgram2022", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" memoProgram", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" inputVaultMint", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" outputVaultMint", inst.AccountMetaSlice.Get(12))) + }) + }) + }) +} + +func (obj SwapV2) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Amount` param: + err = encoder.Encode(obj.Amount) + if err != nil { + return err + } + // Serialize `OtherAmountThreshold` param: + err = encoder.Encode(obj.OtherAmountThreshold) + if err != nil { + return err + } + // Serialize `SqrtPriceLimitX64` param: + err = encoder.Encode(obj.SqrtPriceLimitX64) + if err != nil { + return err + } + // Serialize `IsBaseInput` param: + err = encoder.Encode(obj.IsBaseInput) + if err != nil { + return err + } + return nil +} +func (obj *SwapV2) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Amount`: + err = decoder.Decode(&obj.Amount) + if err != nil { + return err + } + // Deserialize `OtherAmountThreshold`: + err = decoder.Decode(&obj.OtherAmountThreshold) + if err != nil { + return err + } + // Deserialize `SqrtPriceLimitX64`: + err = decoder.Decode(&obj.SqrtPriceLimitX64) + if err != nil { + return err + } + // Deserialize `IsBaseInput`: + err = decoder.Decode(&obj.IsBaseInput) + if err != nil { + return err + } + return nil +} + +// NewSwapV2Instruction declares a new SwapV2 instruction with the provided parameters and accounts. +func NewSwapV2Instruction( + // Parameters: + amount uint64, + otherAmountThreshold uint64, + sqrtPriceLimitX64 ag_binary.Uint128, + isBaseInput bool, + // Accounts: + payer ag_solanago.PublicKey, + ammConfig ag_solanago.PublicKey, + poolState ag_solanago.PublicKey, + inputTokenAccount ag_solanago.PublicKey, + outputTokenAccount ag_solanago.PublicKey, + inputVault ag_solanago.PublicKey, + outputVault ag_solanago.PublicKey, + observationState ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + tokenProgram2022 ag_solanago.PublicKey, + memoProgram ag_solanago.PublicKey, + inputVaultMint ag_solanago.PublicKey, + outputVaultMint ag_solanago.PublicKey) *SwapV2 { + return NewSwapV2InstructionBuilder(). + SetAmount(amount). + SetOtherAmountThreshold(otherAmountThreshold). + SetSqrtPriceLimitX64(sqrtPriceLimitX64). + SetIsBaseInput(isBaseInput). + SetPayerAccount(payer). + SetAmmConfigAccount(ammConfig). + SetPoolStateAccount(poolState). + SetInputTokenAccountAccount(inputTokenAccount). + SetOutputTokenAccountAccount(outputTokenAccount). + SetInputVaultAccount(inputVault). + SetOutputVaultAccount(outputVault). + SetObservationStateAccount(observationState). + SetTokenProgramAccount(tokenProgram). + SetTokenProgram2022Account(tokenProgram2022). + SetMemoProgramAccount(memoProgram). + SetInputVaultMintAccount(inputVaultMint). + SetOutputVaultMintAccount(outputVaultMint) +} diff --git a/programs/raydiumclmm/SwapV2_test.go b/programs/raydiumclmm/SwapV2_test.go new file mode 100644 index 00000000..6f8de634 --- /dev/null +++ b/programs/raydiumclmm/SwapV2_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_SwapV2(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("SwapV2"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(SwapV2) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(SwapV2) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/raydiumclmm/Swap_test.go b/programs/raydiumclmm/Swap_test.go new file mode 100644 index 00000000..3272fdc0 --- /dev/null +++ b/programs/raydiumclmm/Swap_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_Swap(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("Swap"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(Swap) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(Swap) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/raydiumclmm/TransferRewardOwner.go b/programs/raydiumclmm/TransferRewardOwner.go new file mode 100644 index 00000000..768364ee --- /dev/null +++ b/programs/raydiumclmm/TransferRewardOwner.go @@ -0,0 +1,155 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "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" +) + +// Transfer reward owner +// +// # Arguments +// +// * `ctx`- The context of accounts +// * `new_owner`- new owner pubkey +// +type TransferRewardOwner struct { + NewOwner *ag_solanago.PublicKey + + // [0] = [SIGNER] authority + // ··········· Address to be set as operation account owner. + // + // [1] = [WRITE] poolState + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewTransferRewardOwnerInstructionBuilder creates a new `TransferRewardOwner` instruction builder. +func NewTransferRewardOwnerInstructionBuilder() *TransferRewardOwner { + nd := &TransferRewardOwner{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 2), + } + return nd +} + +// SetNewOwner sets the "newOwner" parameter. +func (inst *TransferRewardOwner) SetNewOwner(newOwner ag_solanago.PublicKey) *TransferRewardOwner { + inst.NewOwner = &newOwner + return inst +} + +// SetAuthorityAccount sets the "authority" account. +// Address to be set as operation account owner. +func (inst *TransferRewardOwner) SetAuthorityAccount(authority ag_solanago.PublicKey) *TransferRewardOwner { + inst.AccountMetaSlice[0] = ag_solanago.Meta(authority).SIGNER() + return inst +} + +// GetAuthorityAccount gets the "authority" account. +// Address to be set as operation account owner. +func (inst *TransferRewardOwner) GetAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetPoolStateAccount sets the "poolState" account. +func (inst *TransferRewardOwner) SetPoolStateAccount(poolState ag_solanago.PublicKey) *TransferRewardOwner { + inst.AccountMetaSlice[1] = ag_solanago.Meta(poolState).WRITE() + return inst +} + +// GetPoolStateAccount gets the "poolState" account. +func (inst *TransferRewardOwner) GetPoolStateAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +func (inst TransferRewardOwner) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_TransferRewardOwner, + }} +} + +// 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 TransferRewardOwner) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *TransferRewardOwner) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.NewOwner == nil { + return errors.New("NewOwner parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Authority is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.PoolState is not set") + } + } + return nil +} + +func (inst *TransferRewardOwner) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("TransferRewardOwner")). + // + 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("NewOwner", *inst.NewOwner)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=2]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta("authority", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta("poolState", inst.AccountMetaSlice.Get(1))) + }) + }) + }) +} + +func (obj TransferRewardOwner) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `NewOwner` param: + err = encoder.Encode(obj.NewOwner) + if err != nil { + return err + } + return nil +} +func (obj *TransferRewardOwner) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `NewOwner`: + err = decoder.Decode(&obj.NewOwner) + if err != nil { + return err + } + return nil +} + +// NewTransferRewardOwnerInstruction declares a new TransferRewardOwner instruction with the provided parameters and accounts. +func NewTransferRewardOwnerInstruction( + // Parameters: + newOwner ag_solanago.PublicKey, + // Accounts: + authority ag_solanago.PublicKey, + poolState ag_solanago.PublicKey) *TransferRewardOwner { + return NewTransferRewardOwnerInstructionBuilder(). + SetNewOwner(newOwner). + SetAuthorityAccount(authority). + SetPoolStateAccount(poolState) +} diff --git a/programs/raydiumclmm/TransferRewardOwner_test.go b/programs/raydiumclmm/TransferRewardOwner_test.go new file mode 100644 index 00000000..a972f483 --- /dev/null +++ b/programs/raydiumclmm/TransferRewardOwner_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_TransferRewardOwner(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("TransferRewardOwner"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(TransferRewardOwner) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(TransferRewardOwner) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/raydiumclmm/UpdateAmmConfig.go b/programs/raydiumclmm/UpdateAmmConfig.go new file mode 100644 index 00000000..89b91a3b --- /dev/null +++ b/programs/raydiumclmm/UpdateAmmConfig.go @@ -0,0 +1,187 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "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" +) + +// Updates the owner of the amm config +// Must be called by the current owner or admin +// +// # Arguments +// +// * `ctx`- The context of accounts +// * `trade_fee_rate`- The new trade fee rate of amm config, be set when `param` is 0 +// * `protocol_fee_rate`- The new protocol fee rate of amm config, be set when `param` is 1 +// * `fund_fee_rate`- The new fund fee rate of amm config, be set when `param` is 2 +// * `new_owner`- The config's new owner, be set when `param` is 3 +// * `new_fund_owner`- The config's new fund owner, be set when `param` is 4 +// * `param`- The vaule can be 0 | 1 | 2 | 3 | 4, otherwise will report a error +// +type UpdateAmmConfig struct { + Param *uint8 + Value *uint32 + + // [0] = [SIGNER] owner + // ··········· The amm config owner or admin + // + // [1] = [WRITE] ammConfig + // ··········· Amm config account to be changed + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewUpdateAmmConfigInstructionBuilder creates a new `UpdateAmmConfig` instruction builder. +func NewUpdateAmmConfigInstructionBuilder() *UpdateAmmConfig { + nd := &UpdateAmmConfig{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 2), + } + return nd +} + +// SetParam sets the "param" parameter. +func (inst *UpdateAmmConfig) SetParam(param uint8) *UpdateAmmConfig { + inst.Param = ¶m + return inst +} + +// SetValue sets the "value" parameter. +func (inst *UpdateAmmConfig) SetValue(value uint32) *UpdateAmmConfig { + inst.Value = &value + return inst +} + +// SetOwnerAccount sets the "owner" account. +// The amm config owner or admin +func (inst *UpdateAmmConfig) SetOwnerAccount(owner ag_solanago.PublicKey) *UpdateAmmConfig { + inst.AccountMetaSlice[0] = ag_solanago.Meta(owner).SIGNER() + return inst +} + +// GetOwnerAccount gets the "owner" account. +// The amm config owner or admin +func (inst *UpdateAmmConfig) GetOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetAmmConfigAccount sets the "ammConfig" account. +// Amm config account to be changed +func (inst *UpdateAmmConfig) SetAmmConfigAccount(ammConfig ag_solanago.PublicKey) *UpdateAmmConfig { + inst.AccountMetaSlice[1] = ag_solanago.Meta(ammConfig).WRITE() + return inst +} + +// GetAmmConfigAccount gets the "ammConfig" account. +// Amm config account to be changed +func (inst *UpdateAmmConfig) GetAmmConfigAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +func (inst UpdateAmmConfig) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_UpdateAmmConfig, + }} +} + +// 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 UpdateAmmConfig) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *UpdateAmmConfig) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.Param == nil { + return errors.New("Param parameter is not set") + } + if inst.Value == nil { + return errors.New("Value parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Owner is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.AmmConfig is not set") + } + } + return nil +} + +func (inst *UpdateAmmConfig) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("UpdateAmmConfig")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=2]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param("Param", *inst.Param)) + paramsBranch.Child(ag_format.Param("Value", *inst.Value)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=2]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" owner", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta("ammConfig", inst.AccountMetaSlice.Get(1))) + }) + }) + }) +} + +func (obj UpdateAmmConfig) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Param` param: + err = encoder.Encode(obj.Param) + if err != nil { + return err + } + // Serialize `Value` param: + err = encoder.Encode(obj.Value) + if err != nil { + return err + } + return nil +} +func (obj *UpdateAmmConfig) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Param`: + err = decoder.Decode(&obj.Param) + if err != nil { + return err + } + // Deserialize `Value`: + err = decoder.Decode(&obj.Value) + if err != nil { + return err + } + return nil +} + +// NewUpdateAmmConfigInstruction declares a new UpdateAmmConfig instruction with the provided parameters and accounts. +func NewUpdateAmmConfigInstruction( + // Parameters: + param uint8, + value uint32, + // Accounts: + owner ag_solanago.PublicKey, + ammConfig ag_solanago.PublicKey) *UpdateAmmConfig { + return NewUpdateAmmConfigInstructionBuilder(). + SetParam(param). + SetValue(value). + SetOwnerAccount(owner). + SetAmmConfigAccount(ammConfig) +} diff --git a/programs/raydiumclmm/UpdateAmmConfig_test.go b/programs/raydiumclmm/UpdateAmmConfig_test.go new file mode 100644 index 00000000..b0fbbc0e --- /dev/null +++ b/programs/raydiumclmm/UpdateAmmConfig_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_UpdateAmmConfig(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("UpdateAmmConfig"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(UpdateAmmConfig) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(UpdateAmmConfig) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/raydiumclmm/UpdateOperationAccount.go b/programs/raydiumclmm/UpdateOperationAccount.go new file mode 100644 index 00000000..cc641e35 --- /dev/null +++ b/programs/raydiumclmm/UpdateOperationAccount.go @@ -0,0 +1,204 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "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" +) + +// Update the operation account +// +// # Arguments +// +// * `ctx`- The context of accounts +// * `param`- The vaule can be 0 | 1 | 2 | 3, otherwise will report a error +// * `keys`- update operation owner when the `param` is 0 +// remove operation owner when the `param` is 1 +// update whitelist mint when the `param` is 2 +// remove whitelist mint when the `param` is 3 +// +type UpdateOperationAccount struct { + Param *uint8 + Keys *[]ag_solanago.PublicKey + + // [0] = [SIGNER] owner + // ··········· Address to be set as operation account owner. + // + // [1] = [WRITE] operationState + // ··········· Initialize operation state account to store operation owner address and white list mint. + // + // [2] = [] systemProgram + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewUpdateOperationAccountInstructionBuilder creates a new `UpdateOperationAccount` instruction builder. +func NewUpdateOperationAccountInstructionBuilder() *UpdateOperationAccount { + nd := &UpdateOperationAccount{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 3), + } + return nd +} + +// SetParam sets the "param" parameter. +func (inst *UpdateOperationAccount) SetParam(param uint8) *UpdateOperationAccount { + inst.Param = ¶m + return inst +} + +// SetKeys sets the "keys" parameter. +func (inst *UpdateOperationAccount) SetKeys(keys []ag_solanago.PublicKey) *UpdateOperationAccount { + inst.Keys = &keys + return inst +} + +// SetOwnerAccount sets the "owner" account. +// Address to be set as operation account owner. +func (inst *UpdateOperationAccount) SetOwnerAccount(owner ag_solanago.PublicKey) *UpdateOperationAccount { + inst.AccountMetaSlice[0] = ag_solanago.Meta(owner).SIGNER() + return inst +} + +// GetOwnerAccount gets the "owner" account. +// Address to be set as operation account owner. +func (inst *UpdateOperationAccount) GetOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetOperationStateAccount sets the "operationState" account. +// Initialize operation state account to store operation owner address and white list mint. +func (inst *UpdateOperationAccount) SetOperationStateAccount(operationState ag_solanago.PublicKey) *UpdateOperationAccount { + inst.AccountMetaSlice[1] = ag_solanago.Meta(operationState).WRITE() + return inst +} + +// GetOperationStateAccount gets the "operationState" account. +// Initialize operation state account to store operation owner address and white list mint. +func (inst *UpdateOperationAccount) GetOperationStateAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +func (inst *UpdateOperationAccount) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *UpdateOperationAccount { + inst.AccountMetaSlice[2] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +func (inst *UpdateOperationAccount) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +func (inst UpdateOperationAccount) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_UpdateOperationAccount, + }} +} + +// 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 UpdateOperationAccount) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *UpdateOperationAccount) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.Param == nil { + return errors.New("Param parameter is not set") + } + if inst.Keys == nil { + return errors.New("Keys parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Owner is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.OperationState is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.SystemProgram is not set") + } + } + return nil +} + +func (inst *UpdateOperationAccount) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("UpdateOperationAccount")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=2]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param("Param", *inst.Param)) + paramsBranch.Child(ag_format.Param(" Keys", *inst.Keys)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=3]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" owner", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta("operationState", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" systemProgram", inst.AccountMetaSlice.Get(2))) + }) + }) + }) +} + +func (obj UpdateOperationAccount) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Param` param: + err = encoder.Encode(obj.Param) + if err != nil { + return err + } + // Serialize `Keys` param: + err = encoder.Encode(obj.Keys) + if err != nil { + return err + } + return nil +} +func (obj *UpdateOperationAccount) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Param`: + err = decoder.Decode(&obj.Param) + if err != nil { + return err + } + // Deserialize `Keys`: + err = decoder.Decode(&obj.Keys) + if err != nil { + return err + } + return nil +} + +// NewUpdateOperationAccountInstruction declares a new UpdateOperationAccount instruction with the provided parameters and accounts. +func NewUpdateOperationAccountInstruction( + // Parameters: + param uint8, + keys []ag_solanago.PublicKey, + // Accounts: + owner ag_solanago.PublicKey, + operationState ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey) *UpdateOperationAccount { + return NewUpdateOperationAccountInstructionBuilder(). + SetParam(param). + SetKeys(keys). + SetOwnerAccount(owner). + SetOperationStateAccount(operationState). + SetSystemProgramAccount(systemProgram) +} diff --git a/programs/raydiumclmm/UpdateOperationAccount_test.go b/programs/raydiumclmm/UpdateOperationAccount_test.go new file mode 100644 index 00000000..bd286c12 --- /dev/null +++ b/programs/raydiumclmm/UpdateOperationAccount_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_UpdateOperationAccount(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("UpdateOperationAccount"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(UpdateOperationAccount) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(UpdateOperationAccount) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/raydiumclmm/UpdatePoolStatus.go b/programs/raydiumclmm/UpdatePoolStatus.go new file mode 100644 index 00000000..4bdd7cc2 --- /dev/null +++ b/programs/raydiumclmm/UpdatePoolStatus.go @@ -0,0 +1,152 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "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" +) + +// Update pool status for given vaule +// +// # Arguments +// +// * `ctx`- The context of accounts +// * `status` - The vaule of status +// +type UpdatePoolStatus struct { + Status *uint8 + + // [0] = [SIGNER] authority + // + // [1] = [WRITE] poolState + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewUpdatePoolStatusInstructionBuilder creates a new `UpdatePoolStatus` instruction builder. +func NewUpdatePoolStatusInstructionBuilder() *UpdatePoolStatus { + nd := &UpdatePoolStatus{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 2), + } + return nd +} + +// SetStatus sets the "status" parameter. +func (inst *UpdatePoolStatus) SetStatus(status uint8) *UpdatePoolStatus { + inst.Status = &status + return inst +} + +// SetAuthorityAccount sets the "authority" account. +func (inst *UpdatePoolStatus) SetAuthorityAccount(authority ag_solanago.PublicKey) *UpdatePoolStatus { + inst.AccountMetaSlice[0] = ag_solanago.Meta(authority).SIGNER() + return inst +} + +// GetAuthorityAccount gets the "authority" account. +func (inst *UpdatePoolStatus) GetAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetPoolStateAccount sets the "poolState" account. +func (inst *UpdatePoolStatus) SetPoolStateAccount(poolState ag_solanago.PublicKey) *UpdatePoolStatus { + inst.AccountMetaSlice[1] = ag_solanago.Meta(poolState).WRITE() + return inst +} + +// GetPoolStateAccount gets the "poolState" account. +func (inst *UpdatePoolStatus) GetPoolStateAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +func (inst UpdatePoolStatus) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_UpdatePoolStatus, + }} +} + +// 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 UpdatePoolStatus) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *UpdatePoolStatus) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.Status == nil { + return errors.New("Status parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Authority is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.PoolState is not set") + } + } + return nil +} + +func (inst *UpdatePoolStatus) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("UpdatePoolStatus")). + // + 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("Status", *inst.Status)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=2]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta("authority", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta("poolState", inst.AccountMetaSlice.Get(1))) + }) + }) + }) +} + +func (obj UpdatePoolStatus) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Status` param: + err = encoder.Encode(obj.Status) + if err != nil { + return err + } + return nil +} +func (obj *UpdatePoolStatus) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Status`: + err = decoder.Decode(&obj.Status) + if err != nil { + return err + } + return nil +} + +// NewUpdatePoolStatusInstruction declares a new UpdatePoolStatus instruction with the provided parameters and accounts. +func NewUpdatePoolStatusInstruction( + // Parameters: + status uint8, + // Accounts: + authority ag_solanago.PublicKey, + poolState ag_solanago.PublicKey) *UpdatePoolStatus { + return NewUpdatePoolStatusInstructionBuilder(). + SetStatus(status). + SetAuthorityAccount(authority). + SetPoolStateAccount(poolState) +} diff --git a/programs/raydiumclmm/UpdatePoolStatus_test.go b/programs/raydiumclmm/UpdatePoolStatus_test.go new file mode 100644 index 00000000..94f10d19 --- /dev/null +++ b/programs/raydiumclmm/UpdatePoolStatus_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_UpdatePoolStatus(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("UpdatePoolStatus"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(UpdatePoolStatus) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(UpdatePoolStatus) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/raydiumclmm/UpdateRewardInfos.go b/programs/raydiumclmm/UpdateRewardInfos.go new file mode 100644 index 00000000..91fec3ba --- /dev/null +++ b/programs/raydiumclmm/UpdateRewardInfos.go @@ -0,0 +1,106 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "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" +) + +// Update rewards info of the given pool, can be called for everyone +// +// # Arguments +// +// * `ctx`- The context of accounts +// +type UpdateRewardInfos struct { + + // [0] = [WRITE] poolState + // ··········· The liquidity pool for which reward info to update + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewUpdateRewardInfosInstructionBuilder creates a new `UpdateRewardInfos` instruction builder. +func NewUpdateRewardInfosInstructionBuilder() *UpdateRewardInfos { + nd := &UpdateRewardInfos{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 1), + } + return nd +} + +// SetPoolStateAccount sets the "poolState" account. +// The liquidity pool for which reward info to update +func (inst *UpdateRewardInfos) SetPoolStateAccount(poolState ag_solanago.PublicKey) *UpdateRewardInfos { + inst.AccountMetaSlice[0] = ag_solanago.Meta(poolState).WRITE() + return inst +} + +// GetPoolStateAccount gets the "poolState" account. +// The liquidity pool for which reward info to update +func (inst *UpdateRewardInfos) GetPoolStateAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +func (inst UpdateRewardInfos) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_UpdateRewardInfos, + }} +} + +// 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 UpdateRewardInfos) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *UpdateRewardInfos) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.PoolState is not set") + } + } + return nil +} + +func (inst *UpdateRewardInfos) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("UpdateRewardInfos")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=1]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta("poolState", inst.AccountMetaSlice.Get(0))) + }) + }) + }) +} + +func (obj UpdateRewardInfos) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *UpdateRewardInfos) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewUpdateRewardInfosInstruction declares a new UpdateRewardInfos instruction with the provided parameters and accounts. +func NewUpdateRewardInfosInstruction( + // Accounts: + poolState ag_solanago.PublicKey) *UpdateRewardInfos { + return NewUpdateRewardInfosInstructionBuilder(). + SetPoolStateAccount(poolState) +} diff --git a/programs/raydiumclmm/UpdateRewardInfos_test.go b/programs/raydiumclmm/UpdateRewardInfos_test.go new file mode 100644 index 00000000..c3f978da --- /dev/null +++ b/programs/raydiumclmm/UpdateRewardInfos_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_UpdateRewardInfos(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("UpdateRewardInfos"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(UpdateRewardInfos) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(UpdateRewardInfos) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/raydiumclmm/accounts.go b/programs/raydiumclmm/accounts.go new file mode 100644 index 00000000..fe3c62a0 --- /dev/null +++ b/programs/raydiumclmm/accounts.go @@ -0,0 +1,1296 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "fmt" + ag_binary "github.com/gagliardetto/binary" + ag_solanago "github.com/gagliardetto/solana-go" +) + +type AmmConfig struct { + // Bump to identify PDA + Bump uint8 + Index uint16 + + // Address of the protocol owner + Owner ag_solanago.PublicKey + + // The protocol fee + ProtocolFeeRate uint32 + + // The trade fee, denominated in hundredths of a bip (10^-6) + TradeFeeRate uint32 + + // The tick spacing + TickSpacing uint16 + + // The fund fee, denominated in hundredths of a bip (10^-6) + FundFeeRate uint32 + PaddingU32 uint32 + FundOwner ag_solanago.PublicKey + Padding [3]uint64 +} + +var AmmConfigDiscriminator = [8]byte{218, 244, 33, 104, 203, 203, 43, 111} + +func (obj AmmConfig) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Write account discriminator: + err = encoder.WriteBytes(AmmConfigDiscriminator[:], false) + if err != nil { + return err + } + // Serialize `Bump` param: + err = encoder.Encode(obj.Bump) + if err != nil { + return err + } + // Serialize `Index` param: + err = encoder.Encode(obj.Index) + if err != nil { + return err + } + // Serialize `Owner` param: + err = encoder.Encode(obj.Owner) + if err != nil { + return err + } + // Serialize `ProtocolFeeRate` param: + err = encoder.Encode(obj.ProtocolFeeRate) + if err != nil { + return err + } + // Serialize `TradeFeeRate` param: + err = encoder.Encode(obj.TradeFeeRate) + if err != nil { + return err + } + // Serialize `TickSpacing` param: + err = encoder.Encode(obj.TickSpacing) + if err != nil { + return err + } + // Serialize `FundFeeRate` param: + err = encoder.Encode(obj.FundFeeRate) + if err != nil { + return err + } + // Serialize `PaddingU32` param: + err = encoder.Encode(obj.PaddingU32) + if err != nil { + return err + } + // Serialize `FundOwner` param: + err = encoder.Encode(obj.FundOwner) + if err != nil { + return err + } + // Serialize `Padding` param: + err = encoder.Encode(obj.Padding) + if err != nil { + return err + } + return nil +} + +func (obj *AmmConfig) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Read and check account discriminator: + { + discriminator, err := decoder.ReadTypeID() + if err != nil { + return err + } + if !discriminator.Equal(AmmConfigDiscriminator[:]) { + return fmt.Errorf( + "wrong discriminator: wanted %s, got %s", + "[218 244 33 104 203 203 43 111]", + fmt.Sprint(discriminator[:])) + } + } + // Deserialize `Bump`: + err = decoder.Decode(&obj.Bump) + if err != nil { + return err + } + // Deserialize `Index`: + err = decoder.Decode(&obj.Index) + if err != nil { + return err + } + // Deserialize `Owner`: + err = decoder.Decode(&obj.Owner) + if err != nil { + return err + } + // Deserialize `ProtocolFeeRate`: + err = decoder.Decode(&obj.ProtocolFeeRate) + if err != nil { + return err + } + // Deserialize `TradeFeeRate`: + err = decoder.Decode(&obj.TradeFeeRate) + if err != nil { + return err + } + // Deserialize `TickSpacing`: + err = decoder.Decode(&obj.TickSpacing) + if err != nil { + return err + } + // Deserialize `FundFeeRate`: + err = decoder.Decode(&obj.FundFeeRate) + if err != nil { + return err + } + // Deserialize `PaddingU32`: + err = decoder.Decode(&obj.PaddingU32) + if err != nil { + return err + } + // Deserialize `FundOwner`: + err = decoder.Decode(&obj.FundOwner) + if err != nil { + return err + } + // Deserialize `Padding`: + err = decoder.Decode(&obj.Padding) + if err != nil { + return err + } + return nil +} + +type OperationState struct { + // Bump to identify PDA + Bump uint8 + + // Address of the operation owner + OperationOwners [10]ag_solanago.PublicKey + + // The mint address of whitelist to emmit reward + WhitelistMints [100]ag_solanago.PublicKey +} + +var OperationStateDiscriminator = [8]byte{19, 236, 58, 237, 81, 222, 183, 252} + +func (obj OperationState) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Write account discriminator: + err = encoder.WriteBytes(OperationStateDiscriminator[:], false) + if err != nil { + return err + } + // Serialize `Bump` param: + err = encoder.Encode(obj.Bump) + if err != nil { + return err + } + // Serialize `OperationOwners` param: + err = encoder.Encode(obj.OperationOwners) + if err != nil { + return err + } + // Serialize `WhitelistMints` param: + err = encoder.Encode(obj.WhitelistMints) + if err != nil { + return err + } + return nil +} + +func (obj *OperationState) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Read and check account discriminator: + { + discriminator, err := decoder.ReadTypeID() + if err != nil { + return err + } + if !discriminator.Equal(OperationStateDiscriminator[:]) { + return fmt.Errorf( + "wrong discriminator: wanted %s, got %s", + "[19 236 58 237 81 222 183 252]", + fmt.Sprint(discriminator[:])) + } + } + // Deserialize `Bump`: + err = decoder.Decode(&obj.Bump) + if err != nil { + return err + } + // Deserialize `OperationOwners`: + err = decoder.Decode(&obj.OperationOwners) + if err != nil { + return err + } + // Deserialize `WhitelistMints`: + err = decoder.Decode(&obj.WhitelistMints) + if err != nil { + return err + } + return nil +} + +type ObservationState struct { + // Whether the ObservationState is initialized + Initialized bool + PoolId ag_solanago.PublicKey + + // observation array + Observations [1000]Observation + + // padding for feature update + Padding [5]ag_binary.Uint128 +} + +var ObservationStateDiscriminator = [8]byte{122, 174, 197, 53, 129, 9, 165, 132} + +func (obj ObservationState) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Write account discriminator: + err = encoder.WriteBytes(ObservationStateDiscriminator[:], false) + if err != nil { + return err + } + // Serialize `Initialized` param: + err = encoder.Encode(obj.Initialized) + if err != nil { + return err + } + // Serialize `PoolId` param: + err = encoder.Encode(obj.PoolId) + if err != nil { + return err + } + // Serialize `Observations` param: + err = encoder.Encode(obj.Observations) + if err != nil { + return err + } + // Serialize `Padding` param: + err = encoder.Encode(obj.Padding) + if err != nil { + return err + } + return nil +} + +func (obj *ObservationState) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Read and check account discriminator: + { + discriminator, err := decoder.ReadTypeID() + if err != nil { + return err + } + if !discriminator.Equal(ObservationStateDiscriminator[:]) { + return fmt.Errorf( + "wrong discriminator: wanted %s, got %s", + "[122 174 197 53 129 9 165 132]", + fmt.Sprint(discriminator[:])) + } + } + // Deserialize `Initialized`: + err = decoder.Decode(&obj.Initialized) + if err != nil { + return err + } + // Deserialize `PoolId`: + err = decoder.Decode(&obj.PoolId) + if err != nil { + return err + } + // Deserialize `Observations`: + err = decoder.Decode(&obj.Observations) + if err != nil { + return err + } + // Deserialize `Padding`: + err = decoder.Decode(&obj.Padding) + if err != nil { + return err + } + return nil +} + +type PersonalPositionState struct { + // Bump to identify PDA + Bump uint8 + + // Mint address of the tokenized position + NftMint ag_solanago.PublicKey + + // The ID of the pool with which this token is connected + PoolId ag_solanago.PublicKey + + // The lower bound tick of the position + TickLowerIndex int32 + + // The upper bound tick of the position + TickUpperIndex int32 + + // The amount of liquidity owned by this position + Liquidity ag_binary.Uint128 + + // The token_0 fee growth of the aggregate position as of the last action on the individual position + FeeGrowthInside0LastX64 ag_binary.Uint128 + + // The token_1 fee growth of the aggregate position as of the last action on the individual position + FeeGrowthInside1LastX64 ag_binary.Uint128 + + // The fees owed to the position owner in token_0, as of the last computation + TokenFeesOwed0 uint64 + + // The fees owed to the position owner in token_1, as of the last computation + TokenFeesOwed1 uint64 + RewardInfos [3]PositionRewardInfo + Padding [8]uint64 +} + +var PersonalPositionStateDiscriminator = [8]byte{70, 111, 150, 126, 230, 15, 25, 117} + +func (obj PersonalPositionState) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Write account discriminator: + err = encoder.WriteBytes(PersonalPositionStateDiscriminator[:], false) + if err != nil { + return err + } + // Serialize `Bump` param: + err = encoder.Encode(obj.Bump) + if err != nil { + return err + } + // Serialize `NftMint` param: + err = encoder.Encode(obj.NftMint) + if err != nil { + return err + } + // Serialize `PoolId` param: + err = encoder.Encode(obj.PoolId) + if err != nil { + return err + } + // Serialize `TickLowerIndex` param: + err = encoder.Encode(obj.TickLowerIndex) + if err != nil { + return err + } + // Serialize `TickUpperIndex` param: + err = encoder.Encode(obj.TickUpperIndex) + if err != nil { + return err + } + // Serialize `Liquidity` param: + err = encoder.Encode(obj.Liquidity) + if err != nil { + return err + } + // Serialize `FeeGrowthInside0LastX64` param: + err = encoder.Encode(obj.FeeGrowthInside0LastX64) + if err != nil { + return err + } + // Serialize `FeeGrowthInside1LastX64` param: + err = encoder.Encode(obj.FeeGrowthInside1LastX64) + if err != nil { + return err + } + // Serialize `TokenFeesOwed0` param: + err = encoder.Encode(obj.TokenFeesOwed0) + if err != nil { + return err + } + // Serialize `TokenFeesOwed1` param: + err = encoder.Encode(obj.TokenFeesOwed1) + if err != nil { + return err + } + // Serialize `RewardInfos` param: + err = encoder.Encode(obj.RewardInfos) + if err != nil { + return err + } + // Serialize `Padding` param: + err = encoder.Encode(obj.Padding) + if err != nil { + return err + } + return nil +} + +func (obj *PersonalPositionState) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Read and check account discriminator: + { + discriminator, err := decoder.ReadTypeID() + if err != nil { + return err + } + if !discriminator.Equal(PersonalPositionStateDiscriminator[:]) { + return fmt.Errorf( + "wrong discriminator: wanted %s, got %s", + "[70 111 150 126 230 15 25 117]", + fmt.Sprint(discriminator[:])) + } + } + // Deserialize `Bump`: + err = decoder.Decode(&obj.Bump) + if err != nil { + return err + } + // Deserialize `NftMint`: + err = decoder.Decode(&obj.NftMint) + if err != nil { + return err + } + // Deserialize `PoolId`: + err = decoder.Decode(&obj.PoolId) + if err != nil { + return err + } + // Deserialize `TickLowerIndex`: + err = decoder.Decode(&obj.TickLowerIndex) + if err != nil { + return err + } + // Deserialize `TickUpperIndex`: + err = decoder.Decode(&obj.TickUpperIndex) + if err != nil { + return err + } + // Deserialize `Liquidity`: + err = decoder.Decode(&obj.Liquidity) + if err != nil { + return err + } + // Deserialize `FeeGrowthInside0LastX64`: + err = decoder.Decode(&obj.FeeGrowthInside0LastX64) + if err != nil { + return err + } + // Deserialize `FeeGrowthInside1LastX64`: + err = decoder.Decode(&obj.FeeGrowthInside1LastX64) + if err != nil { + return err + } + // Deserialize `TokenFeesOwed0`: + err = decoder.Decode(&obj.TokenFeesOwed0) + if err != nil { + return err + } + // Deserialize `TokenFeesOwed1`: + err = decoder.Decode(&obj.TokenFeesOwed1) + if err != nil { + return err + } + // Deserialize `RewardInfos`: + err = decoder.Decode(&obj.RewardInfos) + if err != nil { + return err + } + // Deserialize `Padding`: + err = decoder.Decode(&obj.Padding) + if err != nil { + return err + } + return nil +} + +type PoolState struct { + // Bump to identify PDA + Bump [1]uint8 + AmmConfig ag_solanago.PublicKey + Owner ag_solanago.PublicKey + + // Token pair of the pool, where token_mint_0 address < token_mint_1 address + TokenMint0 ag_solanago.PublicKey + TokenMint1 ag_solanago.PublicKey + + // Token pair vault + TokenVault0 ag_solanago.PublicKey + TokenVault1 ag_solanago.PublicKey + + // observation account key + ObservationKey ag_solanago.PublicKey + + // mint0 and mint1 decimals + MintDecimals0 uint8 + MintDecimals1 uint8 + + // The minimum number of ticks between initialized ticks + TickSpacing uint16 + + // The currently in range liquidity available to the pool. + Liquidity ag_binary.Uint128 + + // The current price of the pool as a sqrt(token_1/token_0) Q64.64 value + SqrtPriceX64 ag_binary.Uint128 + + // The current tick of the pool, i.e. according to the last tick transition that was run. + TickCurrent int32 + + // the most-recently updated index of the observations array + ObservationIndex uint16 + ObservationUpdateDuration uint16 + + // The fee growth as a Q64.64 number, i.e. fees of token_0 and token_1 collected per + // unit of liquidity for the entire life of the pool. + FeeGrowthGlobal0X64 ag_binary.Uint128 + FeeGrowthGlobal1X64 ag_binary.Uint128 + + // The amounts of token_0 and token_1 that are owed to the protocol. + ProtocolFeesToken0 uint64 + ProtocolFeesToken1 uint64 + + // The amounts in and out of swap token_0 and token_1 + SwapInAmountToken0 ag_binary.Uint128 + SwapOutAmountToken1 ag_binary.Uint128 + SwapInAmountToken1 ag_binary.Uint128 + SwapOutAmountToken0 ag_binary.Uint128 + + // Bitwise representation of the state of the pool + // bit0, 1: disable open position and increase liquidity, 0: normal + // bit1, 1: disable decrease liquidity, 0: normal + // bit2, 1: disable collect fee, 0: normal + // bit3, 1: disable collect reward, 0: normal + // bit4, 1: disable swap, 0: normal + Status uint8 + + // Leave blank for future use + Padding [7]uint8 + RewardInfos [3]RewardInfo + + // Packed initialized tick array state + TickArrayBitmap [16]uint64 + + // except protocol_fee and fund_fee + TotalFeesToken0 uint64 + + // except protocol_fee and fund_fee + TotalFeesClaimedToken0 uint64 + TotalFeesToken1 uint64 + TotalFeesClaimedToken1 uint64 + FundFeesToken0 uint64 + FundFeesToken1 uint64 + OpenTime uint64 + Padding1 [25]uint64 + Padding2 [32]uint64 +} + +var PoolStateDiscriminator = [8]byte{247, 237, 227, 245, 215, 195, 222, 70} + +func (obj PoolState) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Write account discriminator: + err = encoder.WriteBytes(PoolStateDiscriminator[:], false) + if err != nil { + return err + } + // Serialize `Bump` param: + err = encoder.Encode(obj.Bump) + if err != nil { + return err + } + // Serialize `AmmConfig` param: + err = encoder.Encode(obj.AmmConfig) + if err != nil { + return err + } + // Serialize `Owner` param: + err = encoder.Encode(obj.Owner) + if err != nil { + return err + } + // Serialize `TokenMint0` param: + err = encoder.Encode(obj.TokenMint0) + if err != nil { + return err + } + // Serialize `TokenMint1` param: + err = encoder.Encode(obj.TokenMint1) + if err != nil { + return err + } + // Serialize `TokenVault0` param: + err = encoder.Encode(obj.TokenVault0) + if err != nil { + return err + } + // Serialize `TokenVault1` param: + err = encoder.Encode(obj.TokenVault1) + if err != nil { + return err + } + // Serialize `ObservationKey` param: + err = encoder.Encode(obj.ObservationKey) + if err != nil { + return err + } + // Serialize `MintDecimals0` param: + err = encoder.Encode(obj.MintDecimals0) + if err != nil { + return err + } + // Serialize `MintDecimals1` param: + err = encoder.Encode(obj.MintDecimals1) + if err != nil { + return err + } + // Serialize `TickSpacing` param: + err = encoder.Encode(obj.TickSpacing) + if err != nil { + return err + } + // Serialize `Liquidity` param: + err = encoder.Encode(obj.Liquidity) + if err != nil { + return err + } + // Serialize `SqrtPriceX64` param: + err = encoder.Encode(obj.SqrtPriceX64) + if err != nil { + return err + } + // Serialize `TickCurrent` param: + err = encoder.Encode(obj.TickCurrent) + if err != nil { + return err + } + // Serialize `ObservationIndex` param: + err = encoder.Encode(obj.ObservationIndex) + if err != nil { + return err + } + // Serialize `ObservationUpdateDuration` param: + err = encoder.Encode(obj.ObservationUpdateDuration) + if err != nil { + return err + } + // Serialize `FeeGrowthGlobal0X64` param: + err = encoder.Encode(obj.FeeGrowthGlobal0X64) + if err != nil { + return err + } + // Serialize `FeeGrowthGlobal1X64` param: + err = encoder.Encode(obj.FeeGrowthGlobal1X64) + if err != nil { + return err + } + // Serialize `ProtocolFeesToken0` param: + err = encoder.Encode(obj.ProtocolFeesToken0) + if err != nil { + return err + } + // Serialize `ProtocolFeesToken1` param: + err = encoder.Encode(obj.ProtocolFeesToken1) + if err != nil { + return err + } + // Serialize `SwapInAmountToken0` param: + err = encoder.Encode(obj.SwapInAmountToken0) + if err != nil { + return err + } + // Serialize `SwapOutAmountToken1` param: + err = encoder.Encode(obj.SwapOutAmountToken1) + if err != nil { + return err + } + // Serialize `SwapInAmountToken1` param: + err = encoder.Encode(obj.SwapInAmountToken1) + if err != nil { + return err + } + // Serialize `SwapOutAmountToken0` param: + err = encoder.Encode(obj.SwapOutAmountToken0) + if err != nil { + return err + } + // Serialize `Status` param: + err = encoder.Encode(obj.Status) + if err != nil { + return err + } + // Serialize `Padding` param: + err = encoder.Encode(obj.Padding) + if err != nil { + return err + } + // Serialize `RewardInfos` param: + err = encoder.Encode(obj.RewardInfos) + if err != nil { + return err + } + // Serialize `TickArrayBitmap` param: + err = encoder.Encode(obj.TickArrayBitmap) + if err != nil { + return err + } + // Serialize `TotalFeesToken0` param: + err = encoder.Encode(obj.TotalFeesToken0) + if err != nil { + return err + } + // Serialize `TotalFeesClaimedToken0` param: + err = encoder.Encode(obj.TotalFeesClaimedToken0) + if err != nil { + return err + } + // Serialize `TotalFeesToken1` param: + err = encoder.Encode(obj.TotalFeesToken1) + if err != nil { + return err + } + // Serialize `TotalFeesClaimedToken1` param: + err = encoder.Encode(obj.TotalFeesClaimedToken1) + if err != nil { + return err + } + // Serialize `FundFeesToken0` param: + err = encoder.Encode(obj.FundFeesToken0) + if err != nil { + return err + } + // Serialize `FundFeesToken1` param: + err = encoder.Encode(obj.FundFeesToken1) + if err != nil { + return err + } + // Serialize `OpenTime` param: + err = encoder.Encode(obj.OpenTime) + if err != nil { + return err + } + // Serialize `Padding1` param: + err = encoder.Encode(obj.Padding1) + if err != nil { + return err + } + // Serialize `Padding2` param: + err = encoder.Encode(obj.Padding2) + if err != nil { + return err + } + return nil +} + +func (obj *PoolState) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Read and check account discriminator: + { + discriminator, err := decoder.ReadTypeID() + if err != nil { + return err + } + if !discriminator.Equal(PoolStateDiscriminator[:]) { + return fmt.Errorf( + "wrong discriminator: wanted %s, got %s", + "[247 237 227 245 215 195 222 70]", + fmt.Sprint(discriminator[:])) + } + } + // Deserialize `Bump`: + err = decoder.Decode(&obj.Bump) + if err != nil { + return err + } + // Deserialize `AmmConfig`: + err = decoder.Decode(&obj.AmmConfig) + if err != nil { + return err + } + // Deserialize `Owner`: + err = decoder.Decode(&obj.Owner) + if err != nil { + return err + } + // Deserialize `TokenMint0`: + err = decoder.Decode(&obj.TokenMint0) + if err != nil { + return err + } + // Deserialize `TokenMint1`: + err = decoder.Decode(&obj.TokenMint1) + if err != nil { + return err + } + // Deserialize `TokenVault0`: + err = decoder.Decode(&obj.TokenVault0) + if err != nil { + return err + } + // Deserialize `TokenVault1`: + err = decoder.Decode(&obj.TokenVault1) + if err != nil { + return err + } + // Deserialize `ObservationKey`: + err = decoder.Decode(&obj.ObservationKey) + if err != nil { + return err + } + // Deserialize `MintDecimals0`: + err = decoder.Decode(&obj.MintDecimals0) + if err != nil { + return err + } + // Deserialize `MintDecimals1`: + err = decoder.Decode(&obj.MintDecimals1) + if err != nil { + return err + } + // Deserialize `TickSpacing`: + err = decoder.Decode(&obj.TickSpacing) + if err != nil { + return err + } + // Deserialize `Liquidity`: + err = decoder.Decode(&obj.Liquidity) + if err != nil { + return err + } + // Deserialize `SqrtPriceX64`: + err = decoder.Decode(&obj.SqrtPriceX64) + if err != nil { + return err + } + // Deserialize `TickCurrent`: + err = decoder.Decode(&obj.TickCurrent) + if err != nil { + return err + } + // Deserialize `ObservationIndex`: + err = decoder.Decode(&obj.ObservationIndex) + if err != nil { + return err + } + // Deserialize `ObservationUpdateDuration`: + err = decoder.Decode(&obj.ObservationUpdateDuration) + if err != nil { + return err + } + // Deserialize `FeeGrowthGlobal0X64`: + err = decoder.Decode(&obj.FeeGrowthGlobal0X64) + if err != nil { + return err + } + // Deserialize `FeeGrowthGlobal1X64`: + err = decoder.Decode(&obj.FeeGrowthGlobal1X64) + if err != nil { + return err + } + // Deserialize `ProtocolFeesToken0`: + err = decoder.Decode(&obj.ProtocolFeesToken0) + if err != nil { + return err + } + // Deserialize `ProtocolFeesToken1`: + err = decoder.Decode(&obj.ProtocolFeesToken1) + if err != nil { + return err + } + // Deserialize `SwapInAmountToken0`: + err = decoder.Decode(&obj.SwapInAmountToken0) + if err != nil { + return err + } + // Deserialize `SwapOutAmountToken1`: + err = decoder.Decode(&obj.SwapOutAmountToken1) + if err != nil { + return err + } + // Deserialize `SwapInAmountToken1`: + err = decoder.Decode(&obj.SwapInAmountToken1) + if err != nil { + return err + } + // Deserialize `SwapOutAmountToken0`: + err = decoder.Decode(&obj.SwapOutAmountToken0) + if err != nil { + return err + } + // Deserialize `Status`: + err = decoder.Decode(&obj.Status) + if err != nil { + return err + } + // Deserialize `Padding`: + err = decoder.Decode(&obj.Padding) + if err != nil { + return err + } + // Deserialize `RewardInfos`: + err = decoder.Decode(&obj.RewardInfos) + if err != nil { + return err + } + // Deserialize `TickArrayBitmap`: + err = decoder.Decode(&obj.TickArrayBitmap) + if err != nil { + return err + } + // Deserialize `TotalFeesToken0`: + err = decoder.Decode(&obj.TotalFeesToken0) + if err != nil { + return err + } + // Deserialize `TotalFeesClaimedToken0`: + err = decoder.Decode(&obj.TotalFeesClaimedToken0) + if err != nil { + return err + } + // Deserialize `TotalFeesToken1`: + err = decoder.Decode(&obj.TotalFeesToken1) + if err != nil { + return err + } + // Deserialize `TotalFeesClaimedToken1`: + err = decoder.Decode(&obj.TotalFeesClaimedToken1) + if err != nil { + return err + } + // Deserialize `FundFeesToken0`: + err = decoder.Decode(&obj.FundFeesToken0) + if err != nil { + return err + } + // Deserialize `FundFeesToken1`: + err = decoder.Decode(&obj.FundFeesToken1) + if err != nil { + return err + } + // Deserialize `OpenTime`: + err = decoder.Decode(&obj.OpenTime) + if err != nil { + return err + } + // Deserialize `Padding1`: + err = decoder.Decode(&obj.Padding1) + if err != nil { + return err + } + // Deserialize `Padding2`: + err = decoder.Decode(&obj.Padding2) + if err != nil { + return err + } + return nil +} + +type ProtocolPositionState struct { + // Bump to identify PDA + Bump uint8 + + // The ID of the pool with which this token is connected + PoolId ag_solanago.PublicKey + + // The lower bound tick of the position + TickLowerIndex int32 + + // The upper bound tick of the position + TickUpperIndex int32 + + // The amount of liquidity owned by this position + Liquidity ag_binary.Uint128 + + // The token_0 fee growth per unit of liquidity as of the last update to liquidity or fees owed + FeeGrowthInside0LastX64 ag_binary.Uint128 + + // The token_1 fee growth per unit of liquidity as of the last update to liquidity or fees owed + FeeGrowthInside1LastX64 ag_binary.Uint128 + + // The fees owed to the position owner in token_0 + TokenFeesOwed0 uint64 + + // The fees owed to the position owner in token_1 + TokenFeesOwed1 uint64 + + // The reward growth per unit of liquidity as of the last update to liquidity + RewardGrowthInside [3]ag_binary.Uint128 + Padding [8]uint64 +} + +var ProtocolPositionStateDiscriminator = [8]byte{100, 226, 145, 99, 146, 218, 160, 106} + +func (obj ProtocolPositionState) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Write account discriminator: + err = encoder.WriteBytes(ProtocolPositionStateDiscriminator[:], false) + if err != nil { + return err + } + // Serialize `Bump` param: + err = encoder.Encode(obj.Bump) + if err != nil { + return err + } + // Serialize `PoolId` param: + err = encoder.Encode(obj.PoolId) + if err != nil { + return err + } + // Serialize `TickLowerIndex` param: + err = encoder.Encode(obj.TickLowerIndex) + if err != nil { + return err + } + // Serialize `TickUpperIndex` param: + err = encoder.Encode(obj.TickUpperIndex) + if err != nil { + return err + } + // Serialize `Liquidity` param: + err = encoder.Encode(obj.Liquidity) + if err != nil { + return err + } + // Serialize `FeeGrowthInside0LastX64` param: + err = encoder.Encode(obj.FeeGrowthInside0LastX64) + if err != nil { + return err + } + // Serialize `FeeGrowthInside1LastX64` param: + err = encoder.Encode(obj.FeeGrowthInside1LastX64) + if err != nil { + return err + } + // Serialize `TokenFeesOwed0` param: + err = encoder.Encode(obj.TokenFeesOwed0) + if err != nil { + return err + } + // Serialize `TokenFeesOwed1` param: + err = encoder.Encode(obj.TokenFeesOwed1) + if err != nil { + return err + } + // Serialize `RewardGrowthInside` param: + err = encoder.Encode(obj.RewardGrowthInside) + if err != nil { + return err + } + // Serialize `Padding` param: + err = encoder.Encode(obj.Padding) + if err != nil { + return err + } + return nil +} + +func (obj *ProtocolPositionState) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Read and check account discriminator: + { + discriminator, err := decoder.ReadTypeID() + if err != nil { + return err + } + if !discriminator.Equal(ProtocolPositionStateDiscriminator[:]) { + return fmt.Errorf( + "wrong discriminator: wanted %s, got %s", + "[100 226 145 99 146 218 160 106]", + fmt.Sprint(discriminator[:])) + } + } + // Deserialize `Bump`: + err = decoder.Decode(&obj.Bump) + if err != nil { + return err + } + // Deserialize `PoolId`: + err = decoder.Decode(&obj.PoolId) + if err != nil { + return err + } + // Deserialize `TickLowerIndex`: + err = decoder.Decode(&obj.TickLowerIndex) + if err != nil { + return err + } + // Deserialize `TickUpperIndex`: + err = decoder.Decode(&obj.TickUpperIndex) + if err != nil { + return err + } + // Deserialize `Liquidity`: + err = decoder.Decode(&obj.Liquidity) + if err != nil { + return err + } + // Deserialize `FeeGrowthInside0LastX64`: + err = decoder.Decode(&obj.FeeGrowthInside0LastX64) + if err != nil { + return err + } + // Deserialize `FeeGrowthInside1LastX64`: + err = decoder.Decode(&obj.FeeGrowthInside1LastX64) + if err != nil { + return err + } + // Deserialize `TokenFeesOwed0`: + err = decoder.Decode(&obj.TokenFeesOwed0) + if err != nil { + return err + } + // Deserialize `TokenFeesOwed1`: + err = decoder.Decode(&obj.TokenFeesOwed1) + if err != nil { + return err + } + // Deserialize `RewardGrowthInside`: + err = decoder.Decode(&obj.RewardGrowthInside) + if err != nil { + return err + } + // Deserialize `Padding`: + err = decoder.Decode(&obj.Padding) + if err != nil { + return err + } + return nil +} + +type TickArrayState struct { + PoolId ag_solanago.PublicKey + StartTickIndex int32 + Ticks [60]TickState + InitializedTickCount uint8 + Padding [115]uint8 +} + +var TickArrayStateDiscriminator = [8]byte{192, 155, 85, 205, 49, 249, 129, 42} + +func (obj TickArrayState) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Write account discriminator: + err = encoder.WriteBytes(TickArrayStateDiscriminator[:], false) + if err != nil { + return err + } + // Serialize `PoolId` param: + err = encoder.Encode(obj.PoolId) + if err != nil { + return err + } + // Serialize `StartTickIndex` param: + err = encoder.Encode(obj.StartTickIndex) + if err != nil { + return err + } + // Serialize `Ticks` param: + err = encoder.Encode(obj.Ticks) + if err != nil { + return err + } + // Serialize `InitializedTickCount` param: + err = encoder.Encode(obj.InitializedTickCount) + if err != nil { + return err + } + // Serialize `Padding` param: + err = encoder.Encode(obj.Padding) + if err != nil { + return err + } + return nil +} + +func (obj *TickArrayState) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Read and check account discriminator: + { + discriminator, err := decoder.ReadTypeID() + if err != nil { + return err + } + if !discriminator.Equal(TickArrayStateDiscriminator[:]) { + return fmt.Errorf( + "wrong discriminator: wanted %s, got %s", + "[192 155 85 205 49 249 129 42]", + fmt.Sprint(discriminator[:])) + } + } + // Deserialize `PoolId`: + err = decoder.Decode(&obj.PoolId) + if err != nil { + return err + } + // Deserialize `StartTickIndex`: + err = decoder.Decode(&obj.StartTickIndex) + if err != nil { + return err + } + // Deserialize `Ticks`: + err = decoder.Decode(&obj.Ticks) + if err != nil { + return err + } + // Deserialize `InitializedTickCount`: + err = decoder.Decode(&obj.InitializedTickCount) + if err != nil { + return err + } + // Deserialize `Padding`: + err = decoder.Decode(&obj.Padding) + if err != nil { + return err + } + return nil +} + +type TickArrayBitmapExtension struct { + PoolId ag_solanago.PublicKey + + // Packed initialized tick array state for start_tick_index is positive + PositiveTickArrayBitmap [14][8]uint64 + + // Packed initialized tick array state for start_tick_index is negitive + NegativeTickArrayBitmap [14][8]uint64 +} + +var TickArrayBitmapExtensionDiscriminator = [8]byte{60, 150, 36, 219, 97, 128, 139, 153} + +func (obj TickArrayBitmapExtension) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Write account discriminator: + err = encoder.WriteBytes(TickArrayBitmapExtensionDiscriminator[:], false) + if err != nil { + return err + } + // Serialize `PoolId` param: + err = encoder.Encode(obj.PoolId) + if err != nil { + return err + } + // Serialize `PositiveTickArrayBitmap` param: + err = encoder.Encode(obj.PositiveTickArrayBitmap) + if err != nil { + return err + } + // Serialize `NegativeTickArrayBitmap` param: + err = encoder.Encode(obj.NegativeTickArrayBitmap) + if err != nil { + return err + } + return nil +} + +func (obj *TickArrayBitmapExtension) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Read and check account discriminator: + { + discriminator, err := decoder.ReadTypeID() + if err != nil { + return err + } + if !discriminator.Equal(TickArrayBitmapExtensionDiscriminator[:]) { + return fmt.Errorf( + "wrong discriminator: wanted %s, got %s", + "[60 150 36 219 97 128 139 153]", + fmt.Sprint(discriminator[:])) + } + } + // Deserialize `PoolId`: + err = decoder.Decode(&obj.PoolId) + if err != nil { + return err + } + // Deserialize `PositiveTickArrayBitmap`: + err = decoder.Decode(&obj.PositiveTickArrayBitmap) + if err != nil { + return err + } + // Deserialize `NegativeTickArrayBitmap`: + err = decoder.Decode(&obj.NegativeTickArrayBitmap) + if err != nil { + return err + } + return nil +} diff --git a/programs/raydiumclmm/instructions.go b/programs/raydiumclmm/instructions.go new file mode 100644 index 00000000..5caea28c --- /dev/null +++ b/programs/raydiumclmm/instructions.go @@ -0,0 +1,479 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +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 = "AmmV3" + +func init() { + if !ProgramID.IsZero() { + ag_solanago.RegisterInstructionDecoder(ProgramID, registryDecodeInstruction) + } +} + +var ( + // # Arguments + // + // * `ctx`- The accounts needed by instruction. + // * `index` - The index of amm config, there may be multiple config. + // * `tick_spacing` - The tickspacing binding with config, cannot be changed. + // * `trade_fee_rate` - Trade fee rate, can be changed. + // * `protocol_fee_rate` - The rate of protocol fee within tarde fee. + // * `fund_fee_rate` - The rate of fund fee within tarde fee. + // + Instruction_CreateAmmConfig = ag_binary.TypeID([8]byte{137, 52, 237, 212, 215, 117, 108, 104}) + + // Updates the owner of the amm config + // Must be called by the current owner or admin + // + // # Arguments + // + // * `ctx`- The context of accounts + // * `trade_fee_rate`- The new trade fee rate of amm config, be set when `param` is 0 + // * `protocol_fee_rate`- The new protocol fee rate of amm config, be set when `param` is 1 + // * `fund_fee_rate`- The new fund fee rate of amm config, be set when `param` is 2 + // * `new_owner`- The config's new owner, be set when `param` is 3 + // * `new_fund_owner`- The config's new fund owner, be set when `param` is 4 + // * `param`- The vaule can be 0 | 1 | 2 | 3 | 4, otherwise will report a error + // + Instruction_UpdateAmmConfig = ag_binary.TypeID([8]byte{49, 60, 174, 136, 154, 28, 116, 200}) + + // Creates a pool for the given token pair and the initial price + // + // # Arguments + // + // * `ctx`- The context of accounts + // * `sqrt_price_x64` - the initial sqrt price (amount_token_1 / amount_token_0) of the pool as a Q64.64 + // + Instruction_CreatePool = ag_binary.TypeID([8]byte{233, 146, 209, 142, 207, 104, 64, 188}) + + // Update pool status for given vaule + // + // # Arguments + // + // * `ctx`- The context of accounts + // * `status` - The vaule of status + // + Instruction_UpdatePoolStatus = ag_binary.TypeID([8]byte{130, 87, 108, 6, 46, 224, 117, 123}) + + // Creates an operation account for the program + // + // # Arguments + // + // * `ctx`- The context of accounts + // + Instruction_CreateOperationAccount = ag_binary.TypeID([8]byte{63, 87, 148, 33, 109, 35, 8, 104}) + + // Update the operation account + // + // # Arguments + // + // * `ctx`- The context of accounts + // * `param`- The vaule can be 0 | 1 | 2 | 3, otherwise will report a error + // * `keys`- update operation owner when the `param` is 0 + // remove operation owner when the `param` is 1 + // update whitelist mint when the `param` is 2 + // remove whitelist mint when the `param` is 3 + // + Instruction_UpdateOperationAccount = ag_binary.TypeID([8]byte{127, 70, 119, 40, 188, 227, 61, 7}) + + // Transfer reward owner + // + // # Arguments + // + // * `ctx`- The context of accounts + // * `new_owner`- new owner pubkey + // + Instruction_TransferRewardOwner = ag_binary.TypeID([8]byte{7, 22, 12, 83, 242, 43, 48, 121}) + + // Initialize a reward info for a given pool and reward index + // + // # Arguments + // + // * `ctx`- The context of accounts + // * `reward_index` - the index to reward info + // * `open_time` - reward open timestamp + // * `end_time` - reward end timestamp + // * `emissions_per_second_x64` - Token reward per second are earned per unit of liquidity. + // + Instruction_InitializeReward = ag_binary.TypeID([8]byte{95, 135, 192, 196, 242, 129, 230, 68}) + + // Collect remaining reward token for reward founder + // + // # Arguments + // + // * `ctx`- The context of accounts + // * `reward_index` - the index to reward info + // + Instruction_CollectRemainingRewards = ag_binary.TypeID([8]byte{18, 237, 166, 197, 34, 16, 213, 144}) + + // Update rewards info of the given pool, can be called for everyone + // + // # Arguments + // + // * `ctx`- The context of accounts + // + Instruction_UpdateRewardInfos = ag_binary.TypeID([8]byte{163, 172, 224, 52, 11, 154, 106, 223}) + + // Restset reward param, start a new reward cycle or extend the current cycle. + // + // # Arguments + // + // * `ctx` - The context of accounts + // * `reward_index` - The index of reward token in the pool. + // * `emissions_per_second_x64` - The per second emission reward, when extend the current cycle, + // new value can't be less than old value + // * `open_time` - reward open timestamp, must be set when state a new cycle + // * `end_time` - reward end timestamp + // + Instruction_SetRewardParams = ag_binary.TypeID([8]byte{112, 52, 167, 75, 32, 201, 211, 137}) + + // Collect the protocol fee accrued to the pool + // + // # Arguments + // + // * `ctx` - The context of accounts + // * `amount_0_requested` - The maximum amount of token_0 to send, can be 0 to collect fees in only token_1 + // * `amount_1_requested` - The maximum amount of token_1 to send, can be 0 to collect fees in only token_0 + // + Instruction_CollectProtocolFee = ag_binary.TypeID([8]byte{136, 136, 252, 221, 194, 66, 126, 89}) + + // Collect the fund fee accrued to the pool + // + // # Arguments + // + // * `ctx` - The context of accounts + // * `amount_0_requested` - The maximum amount of token_0 to send, can be 0 to collect fees in only token_1 + // * `amount_1_requested` - The maximum amount of token_1 to send, can be 0 to collect fees in only token_0 + // + Instruction_CollectFundFee = ag_binary.TypeID([8]byte{167, 138, 78, 149, 223, 194, 6, 126}) + + // Creates a new position wrapped in a NFT + // + // # Arguments + // + // * `ctx` - The context of accounts + // * `tick_lower_index` - The low boundary of market + // * `tick_upper_index` - The upper boundary of market + // * `tick_array_lower_start_index` - The start index of tick array which include tick low + // * `tick_array_upper_start_index` - The start index of tick array which include tick upper + // * `liquidity` - The liquidity to be added + // * `amount_0_max` - The max amount of token_0 to spend, which serves as a slippage check + // * `amount_1_max` - The max amount of token_1 to spend, which serves as a slippage check + // + Instruction_OpenPosition = ag_binary.TypeID([8]byte{135, 128, 47, 77, 15, 152, 240, 49}) + + // Creates a new position wrapped in a NFT, support Token2022 + // + // # Arguments + // + // * `ctx` - The context of accounts + // * `tick_lower_index` - The low boundary of market + // * `tick_upper_index` - The upper boundary of market + // * `tick_array_lower_start_index` - The start index of tick array which include tick low + // * `tick_array_upper_start_index` - The start index of tick array which include tick upper + // * `liquidity` - The liquidity to be added, if zero, calculate liquidity base amount_0_max or amount_1_max according base_flag + // * `amount_0_max` - The max amount of token_0 to spend, which serves as a slippage check + // * `amount_1_max` - The max amount of token_1 to spend, which serves as a slippage check + // * `base_flag` - must be special if liquidity is zero, false: calculate liquidity base amount_0_max otherwise base amount_1_max + // + Instruction_OpenPositionV2 = ag_binary.TypeID([8]byte{77, 184, 74, 214, 112, 86, 241, 199}) + + // Close a position, the nft mint and nft account + // + // # Arguments + // + // * `ctx` - The context of accounts + // + Instruction_ClosePosition = ag_binary.TypeID([8]byte{123, 134, 81, 0, 49, 68, 98, 98}) + + // Increases liquidity with a exist position, with amount paid by `payer` + // + // # Arguments + // + // * `ctx` - The context of accounts + // * `liquidity` - The desired liquidity to be added, can't be zero + // * `amount_0_max` - The max amount of token_0 to spend, which serves as a slippage check + // * `amount_1_max` - The max amount of token_1 to spend, which serves as a slippage check + // + Instruction_IncreaseLiquidity = ag_binary.TypeID([8]byte{46, 156, 243, 118, 13, 205, 251, 178}) + + // Increases liquidity with a exist position, with amount paid by `payer`, support Token2022 + // + // # Arguments + // + // * `ctx` - The context of accounts + // * `liquidity` - The desired liquidity to be added, if zero, calculate liquidity base amount_0 or amount_1 according base_flag + // * `amount_0_max` - The max amount of token_0 to spend, which serves as a slippage check + // * `amount_1_max` - The max amount of token_1 to spend, which serves as a slippage check + // * `base_flag` - active if liquidity is zero, 0: calculate liquidity base amount_0_max otherwise base amount_1_max + // + Instruction_IncreaseLiquidityV2 = ag_binary.TypeID([8]byte{133, 29, 89, 223, 69, 238, 176, 10}) + + // Decreases liquidity with a exist position + // + // # Arguments + // + // * `ctx` - The context of accounts + // * `liquidity` - The amount by which liquidity will be decreased + // * `amount_0_min` - The minimum amount of token_0 that should be accounted for the burned liquidity + // * `amount_1_min` - The minimum amount of token_1 that should be accounted for the burned liquidity + // + Instruction_DecreaseLiquidity = ag_binary.TypeID([8]byte{160, 38, 208, 111, 104, 91, 44, 1}) + + // Decreases liquidity with a exist position, support Token2022 + // + // # Arguments + // + // * `ctx` - The context of accounts + // * `liquidity` - The amount by which liquidity will be decreased + // * `amount_0_min` - The minimum amount of token_0 that should be accounted for the burned liquidity + // * `amount_1_min` - The minimum amount of token_1 that should be accounted for the burned liquidity + // + Instruction_DecreaseLiquidityV2 = ag_binary.TypeID([8]byte{58, 127, 188, 62, 79, 82, 196, 96}) + + // Swaps one token for as much as possible of another token across a single pool + // + // # Arguments + // + // * `ctx` - The context of accounts + // * `amount` - Arranged in pairs with other_amount_threshold. (amount_in, amount_out_minimum) or (amount_out, amount_in_maximum) + // * `other_amount_threshold` - For slippage check + // * `sqrt_price_limit` - The Q64.64 sqrt price √P limit. If zero for one, the price cannot + // * `is_base_input` - swap base input or swap base output + // + Instruction_Swap = ag_binary.TypeID([8]byte{248, 198, 158, 145, 225, 117, 135, 200}) + + // Swaps one token for as much as possible of another token across a single pool, support token program 2022 + // + // # Arguments + // + // * `ctx` - The context of accounts + // * `amount` - Arranged in pairs with other_amount_threshold. (amount_in, amount_out_minimum) or (amount_out, amount_in_maximum) + // * `other_amount_threshold` - For slippage check + // * `sqrt_price_limit` - The Q64.64 sqrt price √P limit. If zero for one, the price cannot + // * `is_base_input` - swap base input or swap base output + // + Instruction_SwapV2 = ag_binary.TypeID([8]byte{43, 4, 237, 11, 26, 201, 30, 98}) + + // Swap token for as much as possible of another token across the path provided, base input + // + // # Arguments + // + // * `ctx` - The context of accounts + // * `amount_in` - Token amount to be swapped in + // * `amount_out_minimum` - Panic if output amount is below minimum amount. For slippage. + // + Instruction_SwapRouterBaseIn = ag_binary.TypeID([8]byte{69, 125, 115, 218, 245, 186, 242, 196}) +) + +// InstructionIDToName returns the name of the instruction given its ID. +func InstructionIDToName(id ag_binary.TypeID) string { + switch id { + case Instruction_CreateAmmConfig: + return "CreateAmmConfig" + case Instruction_UpdateAmmConfig: + return "UpdateAmmConfig" + case Instruction_CreatePool: + return "CreatePool" + case Instruction_UpdatePoolStatus: + return "UpdatePoolStatus" + case Instruction_CreateOperationAccount: + return "CreateOperationAccount" + case Instruction_UpdateOperationAccount: + return "UpdateOperationAccount" + case Instruction_TransferRewardOwner: + return "TransferRewardOwner" + case Instruction_InitializeReward: + return "InitializeReward" + case Instruction_CollectRemainingRewards: + return "CollectRemainingRewards" + case Instruction_UpdateRewardInfos: + return "UpdateRewardInfos" + case Instruction_SetRewardParams: + return "SetRewardParams" + case Instruction_CollectProtocolFee: + return "CollectProtocolFee" + case Instruction_CollectFundFee: + return "CollectFundFee" + case Instruction_OpenPosition: + return "OpenPosition" + case Instruction_OpenPositionV2: + return "OpenPositionV2" + case Instruction_ClosePosition: + return "ClosePosition" + case Instruction_IncreaseLiquidity: + return "IncreaseLiquidity" + case Instruction_IncreaseLiquidityV2: + return "IncreaseLiquidityV2" + case Instruction_DecreaseLiquidity: + return "DecreaseLiquidity" + case Instruction_DecreaseLiquidityV2: + return "DecreaseLiquidityV2" + case Instruction_Swap: + return "Swap" + case Instruction_SwapV2: + return "SwapV2" + case Instruction_SwapRouterBaseIn: + return "SwapRouterBaseIn" + 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{ + { + "create_amm_config", (*CreateAmmConfig)(nil), + }, + { + "update_amm_config", (*UpdateAmmConfig)(nil), + }, + { + "create_pool", (*CreatePool)(nil), + }, + { + "update_pool_status", (*UpdatePoolStatus)(nil), + }, + { + "create_operation_account", (*CreateOperationAccount)(nil), + }, + { + "update_operation_account", (*UpdateOperationAccount)(nil), + }, + { + "transfer_reward_owner", (*TransferRewardOwner)(nil), + }, + { + "initialize_reward", (*InitializeReward)(nil), + }, + { + "collect_remaining_rewards", (*CollectRemainingRewards)(nil), + }, + { + "update_reward_infos", (*UpdateRewardInfos)(nil), + }, + { + "set_reward_params", (*SetRewardParams)(nil), + }, + { + "collect_protocol_fee", (*CollectProtocolFee)(nil), + }, + { + "collect_fund_fee", (*CollectFundFee)(nil), + }, + { + "open_position", (*OpenPosition)(nil), + }, + { + "open_position_v2", (*OpenPositionV2)(nil), + }, + { + "close_position", (*ClosePosition)(nil), + }, + { + "increase_liquidity", (*IncreaseLiquidity)(nil), + }, + { + "increase_liquidity_v2", (*IncreaseLiquidityV2)(nil), + }, + { + "decrease_liquidity", (*DecreaseLiquidity)(nil), + }, + { + "decrease_liquidity_v2", (*DecreaseLiquidityV2)(nil), + }, + { + "swap", (*Swap)(nil), + }, + { + "swap_v2", (*SwapV2)(nil), + }, + { + "swap_router_base_in", (*SwapRouterBaseIn)(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 +} diff --git a/programs/raydiumclmm/testing_utils.go b/programs/raydiumclmm/testing_utils.go new file mode 100644 index 00000000..cb09721d --- /dev/null +++ b/programs/raydiumclmm/testing_utils.go @@ -0,0 +1,20 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + "bytes" + "fmt" + ag_binary "github.com/gagliardetto/binary" +) + +func encodeT(data interface{}, buf *bytes.Buffer) error { + if err := ag_binary.NewBorshEncoder(buf).Encode(data); err != nil { + return fmt.Errorf("unable to encode instruction: %w", err) + } + return nil +} + +func decodeT(dst interface{}, data []byte) error { + return ag_binary.NewBorshDecoder(data).Decode(dst) +} diff --git a/programs/raydiumclmm/types.go b/programs/raydiumclmm/types.go new file mode 100644 index 00000000..01938cbf --- /dev/null +++ b/programs/raydiumclmm/types.go @@ -0,0 +1,470 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm_v3 + +import ( + ag_binary "github.com/gagliardetto/binary" + ag_solanago "github.com/gagliardetto/solana-go" +) + +type InitializeRewardParam struct { + // Reward open time + OpenTime uint64 + + // Reward end time + EndTime uint64 + + // Token reward per second are earned per unit of liquidity + EmissionsPerSecondX64 ag_binary.Uint128 +} + +func (obj InitializeRewardParam) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `OpenTime` param: + err = encoder.Encode(obj.OpenTime) + if err != nil { + return err + } + // Serialize `EndTime` param: + err = encoder.Encode(obj.EndTime) + if err != nil { + return err + } + // Serialize `EmissionsPerSecondX64` param: + err = encoder.Encode(obj.EmissionsPerSecondX64) + if err != nil { + return err + } + return nil +} + +func (obj *InitializeRewardParam) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `OpenTime`: + err = decoder.Decode(&obj.OpenTime) + if err != nil { + return err + } + // Deserialize `EndTime`: + err = decoder.Decode(&obj.EndTime) + if err != nil { + return err + } + // Deserialize `EmissionsPerSecondX64`: + err = decoder.Decode(&obj.EmissionsPerSecondX64) + if err != nil { + return err + } + return nil +} + +type Observation struct { + // The block timestamp of the observation + BlockTimestamp uint32 + + // the price of the observation timestamp, Q64.64 + SqrtPriceX64 ag_binary.Uint128 + + // the cumulative of price during the duration time, Q64.64 + CumulativeTimePriceX64 ag_binary.Uint128 + + // padding for feature update + Padding ag_binary.Uint128 +} + +func (obj Observation) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `BlockTimestamp` param: + err = encoder.Encode(obj.BlockTimestamp) + if err != nil { + return err + } + // Serialize `SqrtPriceX64` param: + err = encoder.Encode(obj.SqrtPriceX64) + if err != nil { + return err + } + // Serialize `CumulativeTimePriceX64` param: + err = encoder.Encode(obj.CumulativeTimePriceX64) + if err != nil { + return err + } + // Serialize `Padding` param: + err = encoder.Encode(obj.Padding) + if err != nil { + return err + } + return nil +} + +func (obj *Observation) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `BlockTimestamp`: + err = decoder.Decode(&obj.BlockTimestamp) + if err != nil { + return err + } + // Deserialize `SqrtPriceX64`: + err = decoder.Decode(&obj.SqrtPriceX64) + if err != nil { + return err + } + // Deserialize `CumulativeTimePriceX64`: + err = decoder.Decode(&obj.CumulativeTimePriceX64) + if err != nil { + return err + } + // Deserialize `Padding`: + err = decoder.Decode(&obj.Padding) + if err != nil { + return err + } + return nil +} + +type PositionRewardInfo struct { + GrowthInsideLastX64 ag_binary.Uint128 + RewardAmountOwed uint64 +} + +func (obj PositionRewardInfo) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `GrowthInsideLastX64` param: + err = encoder.Encode(obj.GrowthInsideLastX64) + if err != nil { + return err + } + // Serialize `RewardAmountOwed` param: + err = encoder.Encode(obj.RewardAmountOwed) + if err != nil { + return err + } + return nil +} + +func (obj *PositionRewardInfo) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `GrowthInsideLastX64`: + err = decoder.Decode(&obj.GrowthInsideLastX64) + if err != nil { + return err + } + // Deserialize `RewardAmountOwed`: + err = decoder.Decode(&obj.RewardAmountOwed) + if err != nil { + return err + } + return nil +} + +type RewardInfo struct { + // Reward state + RewardState uint8 + + // Reward open time + OpenTime uint64 + + // Reward end time + EndTime uint64 + + // Reward last update time + LastUpdateTime uint64 + + // Q64.64 number indicates how many tokens per second are earned per unit of liquidity. + EmissionsPerSecondX64 ag_binary.Uint128 + + // The total amount of reward emissioned + RewardTotalEmissioned uint64 + + // The total amount of claimed reward + RewardClaimed uint64 + + // Reward token mint. + TokenMint ag_solanago.PublicKey + + // Reward vault token account. + TokenVault ag_solanago.PublicKey + + // The owner that has permission to set reward param + Authority ag_solanago.PublicKey + + // Q64.64 number that tracks the total tokens earned per unit of liquidity since the reward + // emissions were turned on. + RewardGrowthGlobalX64 ag_binary.Uint128 +} + +func (obj RewardInfo) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `RewardState` param: + err = encoder.Encode(obj.RewardState) + if err != nil { + return err + } + // Serialize `OpenTime` param: + err = encoder.Encode(obj.OpenTime) + if err != nil { + return err + } + // Serialize `EndTime` param: + err = encoder.Encode(obj.EndTime) + if err != nil { + return err + } + // Serialize `LastUpdateTime` param: + err = encoder.Encode(obj.LastUpdateTime) + if err != nil { + return err + } + // Serialize `EmissionsPerSecondX64` param: + err = encoder.Encode(obj.EmissionsPerSecondX64) + if err != nil { + return err + } + // Serialize `RewardTotalEmissioned` param: + err = encoder.Encode(obj.RewardTotalEmissioned) + if err != nil { + return err + } + // Serialize `RewardClaimed` param: + err = encoder.Encode(obj.RewardClaimed) + if err != nil { + return err + } + // Serialize `TokenMint` param: + err = encoder.Encode(obj.TokenMint) + if err != nil { + return err + } + // Serialize `TokenVault` param: + err = encoder.Encode(obj.TokenVault) + if err != nil { + return err + } + // Serialize `Authority` param: + err = encoder.Encode(obj.Authority) + if err != nil { + return err + } + // Serialize `RewardGrowthGlobalX64` param: + err = encoder.Encode(obj.RewardGrowthGlobalX64) + if err != nil { + return err + } + return nil +} + +func (obj *RewardInfo) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `RewardState`: + err = decoder.Decode(&obj.RewardState) + if err != nil { + return err + } + // Deserialize `OpenTime`: + err = decoder.Decode(&obj.OpenTime) + if err != nil { + return err + } + // Deserialize `EndTime`: + err = decoder.Decode(&obj.EndTime) + if err != nil { + return err + } + // Deserialize `LastUpdateTime`: + err = decoder.Decode(&obj.LastUpdateTime) + if err != nil { + return err + } + // Deserialize `EmissionsPerSecondX64`: + err = decoder.Decode(&obj.EmissionsPerSecondX64) + if err != nil { + return err + } + // Deserialize `RewardTotalEmissioned`: + err = decoder.Decode(&obj.RewardTotalEmissioned) + if err != nil { + return err + } + // Deserialize `RewardClaimed`: + err = decoder.Decode(&obj.RewardClaimed) + if err != nil { + return err + } + // Deserialize `TokenMint`: + err = decoder.Decode(&obj.TokenMint) + if err != nil { + return err + } + // Deserialize `TokenVault`: + err = decoder.Decode(&obj.TokenVault) + if err != nil { + return err + } + // Deserialize `Authority`: + err = decoder.Decode(&obj.Authority) + if err != nil { + return err + } + // Deserialize `RewardGrowthGlobalX64`: + err = decoder.Decode(&obj.RewardGrowthGlobalX64) + if err != nil { + return err + } + return nil +} + +type TickState struct { + Tick int32 + + // Amount of net liquidity added (subtracted) when tick is crossed from left to right (right to left) + LiquidityNet ag_binary.Int128 + + // The total position liquidity that references this tick + LiquidityGross ag_binary.Uint128 + + // Fee growth per unit of liquidity on the _other_ side of this tick (relative to the current tick) + // only has relative meaning, not absolute — the value depends on when the tick is initialized + FeeGrowthOutside0X64 ag_binary.Uint128 + FeeGrowthOutside1X64 ag_binary.Uint128 + RewardGrowthsOutsideX64 [3]ag_binary.Uint128 + Padding [13]uint32 +} + +func (obj TickState) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Tick` param: + err = encoder.Encode(obj.Tick) + if err != nil { + return err + } + // Serialize `LiquidityNet` param: + err = encoder.Encode(obj.LiquidityNet) + if err != nil { + return err + } + // Serialize `LiquidityGross` param: + err = encoder.Encode(obj.LiquidityGross) + if err != nil { + return err + } + // Serialize `FeeGrowthOutside0X64` param: + err = encoder.Encode(obj.FeeGrowthOutside0X64) + if err != nil { + return err + } + // Serialize `FeeGrowthOutside1X64` param: + err = encoder.Encode(obj.FeeGrowthOutside1X64) + if err != nil { + return err + } + // Serialize `RewardGrowthsOutsideX64` param: + err = encoder.Encode(obj.RewardGrowthsOutsideX64) + if err != nil { + return err + } + // Serialize `Padding` param: + err = encoder.Encode(obj.Padding) + if err != nil { + return err + } + return nil +} + +func (obj *TickState) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Tick`: + err = decoder.Decode(&obj.Tick) + if err != nil { + return err + } + // Deserialize `LiquidityNet`: + err = decoder.Decode(&obj.LiquidityNet) + if err != nil { + return err + } + // Deserialize `LiquidityGross`: + err = decoder.Decode(&obj.LiquidityGross) + if err != nil { + return err + } + // Deserialize `FeeGrowthOutside0X64`: + err = decoder.Decode(&obj.FeeGrowthOutside0X64) + if err != nil { + return err + } + // Deserialize `FeeGrowthOutside1X64`: + err = decoder.Decode(&obj.FeeGrowthOutside1X64) + if err != nil { + return err + } + // Deserialize `RewardGrowthsOutsideX64`: + err = decoder.Decode(&obj.RewardGrowthsOutsideX64) + if err != nil { + return err + } + // Deserialize `Padding`: + err = decoder.Decode(&obj.Padding) + if err != nil { + return err + } + return nil +} + +type PoolStatusBitIndex ag_binary.BorshEnum + +const ( + PoolStatusBitIndexOpenPositionOrIncreaseLiquidity PoolStatusBitIndex = iota + PoolStatusBitIndexDecreaseLiquidity + PoolStatusBitIndexCollectFee + PoolStatusBitIndexCollectReward + PoolStatusBitIndexSwap +) + +func (value PoolStatusBitIndex) String() string { + switch value { + case PoolStatusBitIndexOpenPositionOrIncreaseLiquidity: + return "OpenPositionOrIncreaseLiquidity" + case PoolStatusBitIndexDecreaseLiquidity: + return "DecreaseLiquidity" + case PoolStatusBitIndexCollectFee: + return "CollectFee" + case PoolStatusBitIndexCollectReward: + return "CollectReward" + case PoolStatusBitIndexSwap: + return "Swap" + default: + return "" + } +} + +type PoolStatusBitFlag ag_binary.BorshEnum + +const ( + PoolStatusBitFlagEnable PoolStatusBitFlag = iota + PoolStatusBitFlagDisable +) + +func (value PoolStatusBitFlag) String() string { + switch value { + case PoolStatusBitFlagEnable: + return "Enable" + case PoolStatusBitFlagDisable: + return "Disable" + default: + return "" + } +} + +type RewardState ag_binary.BorshEnum + +const ( + RewardStateUninitialized RewardState = iota + RewardStateInitialized + RewardStateOpening + RewardStateEnded +) + +func (value RewardState) String() string { + switch value { + case RewardStateUninitialized: + return "Uninitialized" + case RewardStateInitialized: + return "Initialized" + case RewardStateOpening: + return "Opening" + case RewardStateEnded: + return "Ended" + default: + return "" + } +} diff --git a/programs/whirlpool/CloseBundledPosition.go b/programs/whirlpool/CloseBundledPosition.go new file mode 100644 index 00000000..3fdf723a --- /dev/null +++ b/programs/whirlpool/CloseBundledPosition.go @@ -0,0 +1,203 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "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" +) + +// CloseBundledPosition is the `closeBundledPosition` instruction. +type CloseBundledPosition struct { + BundleIndex *uint16 + + // [0] = [WRITE] bundledPosition + // + // [1] = [WRITE] positionBundle + // + // [2] = [] positionBundleTokenAccount + // + // [3] = [SIGNER] positionBundleAuthority + // + // [4] = [WRITE] receiver + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewCloseBundledPositionInstructionBuilder creates a new `CloseBundledPosition` instruction builder. +func NewCloseBundledPositionInstructionBuilder() *CloseBundledPosition { + nd := &CloseBundledPosition{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 5), + } + return nd +} + +// SetBundleIndex sets the "bundleIndex" parameter. +func (inst *CloseBundledPosition) SetBundleIndex(bundleIndex uint16) *CloseBundledPosition { + inst.BundleIndex = &bundleIndex + return inst +} + +// SetBundledPositionAccount sets the "bundledPosition" account. +func (inst *CloseBundledPosition) SetBundledPositionAccount(bundledPosition ag_solanago.PublicKey) *CloseBundledPosition { + inst.AccountMetaSlice[0] = ag_solanago.Meta(bundledPosition).WRITE() + return inst +} + +// GetBundledPositionAccount gets the "bundledPosition" account. +func (inst *CloseBundledPosition) GetBundledPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetPositionBundleAccount sets the "positionBundle" account. +func (inst *CloseBundledPosition) SetPositionBundleAccount(positionBundle ag_solanago.PublicKey) *CloseBundledPosition { + inst.AccountMetaSlice[1] = ag_solanago.Meta(positionBundle).WRITE() + return inst +} + +// GetPositionBundleAccount gets the "positionBundle" account. +func (inst *CloseBundledPosition) GetPositionBundleAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetPositionBundleTokenAccountAccount sets the "positionBundleTokenAccount" account. +func (inst *CloseBundledPosition) SetPositionBundleTokenAccountAccount(positionBundleTokenAccount ag_solanago.PublicKey) *CloseBundledPosition { + inst.AccountMetaSlice[2] = ag_solanago.Meta(positionBundleTokenAccount) + return inst +} + +// GetPositionBundleTokenAccountAccount gets the "positionBundleTokenAccount" account. +func (inst *CloseBundledPosition) GetPositionBundleTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetPositionBundleAuthorityAccount sets the "positionBundleAuthority" account. +func (inst *CloseBundledPosition) SetPositionBundleAuthorityAccount(positionBundleAuthority ag_solanago.PublicKey) *CloseBundledPosition { + inst.AccountMetaSlice[3] = ag_solanago.Meta(positionBundleAuthority).SIGNER() + return inst +} + +// GetPositionBundleAuthorityAccount gets the "positionBundleAuthority" account. +func (inst *CloseBundledPosition) GetPositionBundleAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetReceiverAccount sets the "receiver" account. +func (inst *CloseBundledPosition) SetReceiverAccount(receiver ag_solanago.PublicKey) *CloseBundledPosition { + inst.AccountMetaSlice[4] = ag_solanago.Meta(receiver).WRITE() + return inst +} + +// GetReceiverAccount gets the "receiver" account. +func (inst *CloseBundledPosition) GetReceiverAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +func (inst CloseBundledPosition) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_CloseBundledPosition, + }} +} + +// 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 CloseBundledPosition) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *CloseBundledPosition) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.BundleIndex == nil { + return errors.New("BundleIndex parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.BundledPosition is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.PositionBundle is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.PositionBundleTokenAccount is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.PositionBundleAuthority is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.Receiver is not set") + } + } + return nil +} + +func (inst *CloseBundledPosition) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("CloseBundledPosition")). + // + 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("BundleIndex", *inst.BundleIndex)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=5]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" bundledPosition", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" positionBundle", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" positionBundleToken", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta("positionBundleAuthority", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" receiver", inst.AccountMetaSlice.Get(4))) + }) + }) + }) +} + +func (obj CloseBundledPosition) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `BundleIndex` param: + err = encoder.Encode(obj.BundleIndex) + if err != nil { + return err + } + return nil +} +func (obj *CloseBundledPosition) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `BundleIndex`: + err = decoder.Decode(&obj.BundleIndex) + if err != nil { + return err + } + return nil +} + +// NewCloseBundledPositionInstruction declares a new CloseBundledPosition instruction with the provided parameters and accounts. +func NewCloseBundledPositionInstruction( + // Parameters: + bundleIndex uint16, + // Accounts: + bundledPosition ag_solanago.PublicKey, + positionBundle ag_solanago.PublicKey, + positionBundleTokenAccount ag_solanago.PublicKey, + positionBundleAuthority ag_solanago.PublicKey, + receiver ag_solanago.PublicKey) *CloseBundledPosition { + return NewCloseBundledPositionInstructionBuilder(). + SetBundleIndex(bundleIndex). + SetBundledPositionAccount(bundledPosition). + SetPositionBundleAccount(positionBundle). + SetPositionBundleTokenAccountAccount(positionBundleTokenAccount). + SetPositionBundleAuthorityAccount(positionBundleAuthority). + SetReceiverAccount(receiver) +} diff --git a/programs/whirlpool/CloseBundledPosition_test.go b/programs/whirlpool/CloseBundledPosition_test.go new file mode 100644 index 00000000..b4ac2ecb --- /dev/null +++ b/programs/whirlpool/CloseBundledPosition_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_CloseBundledPosition(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("CloseBundledPosition"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(CloseBundledPosition) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(CloseBundledPosition) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/ClosePosition.go b/programs/whirlpool/ClosePosition.go new file mode 100644 index 00000000..afc3e51e --- /dev/null +++ b/programs/whirlpool/ClosePosition.go @@ -0,0 +1,193 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "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" +) + +// ClosePosition is the `closePosition` instruction. +type ClosePosition struct { + + // [0] = [SIGNER] positionAuthority + // + // [1] = [WRITE] receiver + // + // [2] = [WRITE] position + // + // [3] = [WRITE] positionMint + // + // [4] = [WRITE] positionTokenAccount + // + // [5] = [] tokenProgram + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewClosePositionInstructionBuilder creates a new `ClosePosition` instruction builder. +func NewClosePositionInstructionBuilder() *ClosePosition { + nd := &ClosePosition{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 6), + } + return nd +} + +// SetPositionAuthorityAccount sets the "positionAuthority" account. +func (inst *ClosePosition) SetPositionAuthorityAccount(positionAuthority ag_solanago.PublicKey) *ClosePosition { + inst.AccountMetaSlice[0] = ag_solanago.Meta(positionAuthority).SIGNER() + return inst +} + +// GetPositionAuthorityAccount gets the "positionAuthority" account. +func (inst *ClosePosition) GetPositionAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetReceiverAccount sets the "receiver" account. +func (inst *ClosePosition) SetReceiverAccount(receiver ag_solanago.PublicKey) *ClosePosition { + inst.AccountMetaSlice[1] = ag_solanago.Meta(receiver).WRITE() + return inst +} + +// GetReceiverAccount gets the "receiver" account. +func (inst *ClosePosition) GetReceiverAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetPositionAccount sets the "position" account. +func (inst *ClosePosition) SetPositionAccount(position ag_solanago.PublicKey) *ClosePosition { + inst.AccountMetaSlice[2] = ag_solanago.Meta(position).WRITE() + return inst +} + +// GetPositionAccount gets the "position" account. +func (inst *ClosePosition) GetPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetPositionMintAccount sets the "positionMint" account. +func (inst *ClosePosition) SetPositionMintAccount(positionMint ag_solanago.PublicKey) *ClosePosition { + inst.AccountMetaSlice[3] = ag_solanago.Meta(positionMint).WRITE() + return inst +} + +// GetPositionMintAccount gets the "positionMint" account. +func (inst *ClosePosition) GetPositionMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetPositionTokenAccountAccount sets the "positionTokenAccount" account. +func (inst *ClosePosition) SetPositionTokenAccountAccount(positionTokenAccount ag_solanago.PublicKey) *ClosePosition { + inst.AccountMetaSlice[4] = ag_solanago.Meta(positionTokenAccount).WRITE() + return inst +} + +// GetPositionTokenAccountAccount gets the "positionTokenAccount" account. +func (inst *ClosePosition) GetPositionTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *ClosePosition) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *ClosePosition { + inst.AccountMetaSlice[5] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *ClosePosition) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +func (inst ClosePosition) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_ClosePosition, + }} +} + +// 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 ClosePosition) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *ClosePosition) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.PositionAuthority is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Receiver is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.Position is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.PositionMint is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.PositionTokenAccount is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.TokenProgram is not set") + } + } + return nil +} + +func (inst *ClosePosition) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("ClosePosition")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=6]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta("positionAuthority", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" receiver", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" position", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" positionMint", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" positionToken", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(5))) + }) + }) + }) +} + +func (obj ClosePosition) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *ClosePosition) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewClosePositionInstruction declares a new ClosePosition instruction with the provided parameters and accounts. +func NewClosePositionInstruction( + // Accounts: + positionAuthority ag_solanago.PublicKey, + receiver ag_solanago.PublicKey, + position ag_solanago.PublicKey, + positionMint ag_solanago.PublicKey, + positionTokenAccount ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey) *ClosePosition { + return NewClosePositionInstructionBuilder(). + SetPositionAuthorityAccount(positionAuthority). + SetReceiverAccount(receiver). + SetPositionAccount(position). + SetPositionMintAccount(positionMint). + SetPositionTokenAccountAccount(positionTokenAccount). + SetTokenProgramAccount(tokenProgram) +} diff --git a/programs/whirlpool/ClosePosition_test.go b/programs/whirlpool/ClosePosition_test.go new file mode 100644 index 00000000..56173093 --- /dev/null +++ b/programs/whirlpool/ClosePosition_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_ClosePosition(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("ClosePosition"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(ClosePosition) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(ClosePosition) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/CollectFees.go b/programs/whirlpool/CollectFees.go new file mode 100644 index 00000000..9343b7b4 --- /dev/null +++ b/programs/whirlpool/CollectFees.go @@ -0,0 +1,250 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "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" +) + +// CollectFees is the `collectFees` instruction. +type CollectFees struct { + + // [0] = [] whirlpool + // + // [1] = [SIGNER] positionAuthority + // + // [2] = [WRITE] position + // + // [3] = [] positionTokenAccount + // + // [4] = [WRITE] tokenOwnerAccountA + // + // [5] = [WRITE] tokenVaultA + // + // [6] = [WRITE] tokenOwnerAccountB + // + // [7] = [WRITE] tokenVaultB + // + // [8] = [] tokenProgram + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewCollectFeesInstructionBuilder creates a new `CollectFees` instruction builder. +func NewCollectFeesInstructionBuilder() *CollectFees { + nd := &CollectFees{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 9), + } + return nd +} + +// SetWhirlpoolAccount sets the "whirlpool" account. +func (inst *CollectFees) SetWhirlpoolAccount(whirlpool ag_solanago.PublicKey) *CollectFees { + inst.AccountMetaSlice[0] = ag_solanago.Meta(whirlpool) + return inst +} + +// GetWhirlpoolAccount gets the "whirlpool" account. +func (inst *CollectFees) GetWhirlpoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetPositionAuthorityAccount sets the "positionAuthority" account. +func (inst *CollectFees) SetPositionAuthorityAccount(positionAuthority ag_solanago.PublicKey) *CollectFees { + inst.AccountMetaSlice[1] = ag_solanago.Meta(positionAuthority).SIGNER() + return inst +} + +// GetPositionAuthorityAccount gets the "positionAuthority" account. +func (inst *CollectFees) GetPositionAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetPositionAccount sets the "position" account. +func (inst *CollectFees) SetPositionAccount(position ag_solanago.PublicKey) *CollectFees { + inst.AccountMetaSlice[2] = ag_solanago.Meta(position).WRITE() + return inst +} + +// GetPositionAccount gets the "position" account. +func (inst *CollectFees) GetPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetPositionTokenAccountAccount sets the "positionTokenAccount" account. +func (inst *CollectFees) SetPositionTokenAccountAccount(positionTokenAccount ag_solanago.PublicKey) *CollectFees { + inst.AccountMetaSlice[3] = ag_solanago.Meta(positionTokenAccount) + return inst +} + +// GetPositionTokenAccountAccount gets the "positionTokenAccount" account. +func (inst *CollectFees) GetPositionTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetTokenOwnerAccountAAccount sets the "tokenOwnerAccountA" account. +func (inst *CollectFees) SetTokenOwnerAccountAAccount(tokenOwnerAccountA ag_solanago.PublicKey) *CollectFees { + inst.AccountMetaSlice[4] = ag_solanago.Meta(tokenOwnerAccountA).WRITE() + return inst +} + +// GetTokenOwnerAccountAAccount gets the "tokenOwnerAccountA" account. +func (inst *CollectFees) GetTokenOwnerAccountAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetTokenVaultAAccount sets the "tokenVaultA" account. +func (inst *CollectFees) SetTokenVaultAAccount(tokenVaultA ag_solanago.PublicKey) *CollectFees { + inst.AccountMetaSlice[5] = ag_solanago.Meta(tokenVaultA).WRITE() + return inst +} + +// GetTokenVaultAAccount gets the "tokenVaultA" account. +func (inst *CollectFees) GetTokenVaultAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetTokenOwnerAccountBAccount sets the "tokenOwnerAccountB" account. +func (inst *CollectFees) SetTokenOwnerAccountBAccount(tokenOwnerAccountB ag_solanago.PublicKey) *CollectFees { + inst.AccountMetaSlice[6] = ag_solanago.Meta(tokenOwnerAccountB).WRITE() + return inst +} + +// GetTokenOwnerAccountBAccount gets the "tokenOwnerAccountB" account. +func (inst *CollectFees) GetTokenOwnerAccountBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetTokenVaultBAccount sets the "tokenVaultB" account. +func (inst *CollectFees) SetTokenVaultBAccount(tokenVaultB ag_solanago.PublicKey) *CollectFees { + inst.AccountMetaSlice[7] = ag_solanago.Meta(tokenVaultB).WRITE() + return inst +} + +// GetTokenVaultBAccount gets the "tokenVaultB" account. +func (inst *CollectFees) GetTokenVaultBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *CollectFees) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *CollectFees { + inst.AccountMetaSlice[8] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *CollectFees) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +func (inst CollectFees) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_CollectFees, + }} +} + +// 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 CollectFees) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *CollectFees) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Whirlpool is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.PositionAuthority is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.Position is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.PositionTokenAccount is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.TokenOwnerAccountA is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.TokenVaultA is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.TokenOwnerAccountB is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.TokenVaultB is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.TokenProgram is not set") + } + } + return nil +} + +func (inst *CollectFees) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("CollectFees")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=9]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" whirlpool", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" positionAuthority", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" position", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" positionToken", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta("tokenOwnerAccountA", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" tokenVaultA", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta("tokenOwnerAccountB", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" tokenVaultB", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(8))) + }) + }) + }) +} + +func (obj CollectFees) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *CollectFees) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewCollectFeesInstruction declares a new CollectFees instruction with the provided parameters and accounts. +func NewCollectFeesInstruction( + // Accounts: + whirlpool ag_solanago.PublicKey, + positionAuthority ag_solanago.PublicKey, + position ag_solanago.PublicKey, + positionTokenAccount ag_solanago.PublicKey, + tokenOwnerAccountA ag_solanago.PublicKey, + tokenVaultA ag_solanago.PublicKey, + tokenOwnerAccountB ag_solanago.PublicKey, + tokenVaultB ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey) *CollectFees { + return NewCollectFeesInstructionBuilder(). + SetWhirlpoolAccount(whirlpool). + SetPositionAuthorityAccount(positionAuthority). + SetPositionAccount(position). + SetPositionTokenAccountAccount(positionTokenAccount). + SetTokenOwnerAccountAAccount(tokenOwnerAccountA). + SetTokenVaultAAccount(tokenVaultA). + SetTokenOwnerAccountBAccount(tokenOwnerAccountB). + SetTokenVaultBAccount(tokenVaultB). + SetTokenProgramAccount(tokenProgram) +} diff --git a/programs/whirlpool/CollectFees_test.go b/programs/whirlpool/CollectFees_test.go new file mode 100644 index 00000000..fe7ab3d9 --- /dev/null +++ b/programs/whirlpool/CollectFees_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_CollectFees(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("CollectFees"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(CollectFees) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(CollectFees) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/CollectProtocolFees.go b/programs/whirlpool/CollectProtocolFees.go new file mode 100644 index 00000000..90e9d0a9 --- /dev/null +++ b/programs/whirlpool/CollectProtocolFees.go @@ -0,0 +1,231 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "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" +) + +// CollectProtocolFees is the `collectProtocolFees` instruction. +type CollectProtocolFees struct { + + // [0] = [] whirlpoolsConfig + // + // [1] = [WRITE] whirlpool + // + // [2] = [SIGNER] collectProtocolFeesAuthority + // + // [3] = [WRITE] tokenVaultA + // + // [4] = [WRITE] tokenVaultB + // + // [5] = [WRITE] tokenDestinationA + // + // [6] = [WRITE] tokenDestinationB + // + // [7] = [] tokenProgram + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewCollectProtocolFeesInstructionBuilder creates a new `CollectProtocolFees` instruction builder. +func NewCollectProtocolFeesInstructionBuilder() *CollectProtocolFees { + nd := &CollectProtocolFees{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 8), + } + return nd +} + +// SetWhirlpoolsConfigAccount sets the "whirlpoolsConfig" account. +func (inst *CollectProtocolFees) SetWhirlpoolsConfigAccount(whirlpoolsConfig ag_solanago.PublicKey) *CollectProtocolFees { + inst.AccountMetaSlice[0] = ag_solanago.Meta(whirlpoolsConfig) + return inst +} + +// GetWhirlpoolsConfigAccount gets the "whirlpoolsConfig" account. +func (inst *CollectProtocolFees) GetWhirlpoolsConfigAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetWhirlpoolAccount sets the "whirlpool" account. +func (inst *CollectProtocolFees) SetWhirlpoolAccount(whirlpool ag_solanago.PublicKey) *CollectProtocolFees { + inst.AccountMetaSlice[1] = ag_solanago.Meta(whirlpool).WRITE() + return inst +} + +// GetWhirlpoolAccount gets the "whirlpool" account. +func (inst *CollectProtocolFees) GetWhirlpoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetCollectProtocolFeesAuthorityAccount sets the "collectProtocolFeesAuthority" account. +func (inst *CollectProtocolFees) SetCollectProtocolFeesAuthorityAccount(collectProtocolFeesAuthority ag_solanago.PublicKey) *CollectProtocolFees { + inst.AccountMetaSlice[2] = ag_solanago.Meta(collectProtocolFeesAuthority).SIGNER() + return inst +} + +// GetCollectProtocolFeesAuthorityAccount gets the "collectProtocolFeesAuthority" account. +func (inst *CollectProtocolFees) GetCollectProtocolFeesAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetTokenVaultAAccount sets the "tokenVaultA" account. +func (inst *CollectProtocolFees) SetTokenVaultAAccount(tokenVaultA ag_solanago.PublicKey) *CollectProtocolFees { + inst.AccountMetaSlice[3] = ag_solanago.Meta(tokenVaultA).WRITE() + return inst +} + +// GetTokenVaultAAccount gets the "tokenVaultA" account. +func (inst *CollectProtocolFees) GetTokenVaultAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetTokenVaultBAccount sets the "tokenVaultB" account. +func (inst *CollectProtocolFees) SetTokenVaultBAccount(tokenVaultB ag_solanago.PublicKey) *CollectProtocolFees { + inst.AccountMetaSlice[4] = ag_solanago.Meta(tokenVaultB).WRITE() + return inst +} + +// GetTokenVaultBAccount gets the "tokenVaultB" account. +func (inst *CollectProtocolFees) GetTokenVaultBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetTokenDestinationAAccount sets the "tokenDestinationA" account. +func (inst *CollectProtocolFees) SetTokenDestinationAAccount(tokenDestinationA ag_solanago.PublicKey) *CollectProtocolFees { + inst.AccountMetaSlice[5] = ag_solanago.Meta(tokenDestinationA).WRITE() + return inst +} + +// GetTokenDestinationAAccount gets the "tokenDestinationA" account. +func (inst *CollectProtocolFees) GetTokenDestinationAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetTokenDestinationBAccount sets the "tokenDestinationB" account. +func (inst *CollectProtocolFees) SetTokenDestinationBAccount(tokenDestinationB ag_solanago.PublicKey) *CollectProtocolFees { + inst.AccountMetaSlice[6] = ag_solanago.Meta(tokenDestinationB).WRITE() + return inst +} + +// GetTokenDestinationBAccount gets the "tokenDestinationB" account. +func (inst *CollectProtocolFees) GetTokenDestinationBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *CollectProtocolFees) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *CollectProtocolFees { + inst.AccountMetaSlice[7] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *CollectProtocolFees) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +func (inst CollectProtocolFees) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_CollectProtocolFees, + }} +} + +// 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 CollectProtocolFees) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *CollectProtocolFees) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.WhirlpoolsConfig is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Whirlpool is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.CollectProtocolFeesAuthority is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.TokenVaultA is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.TokenVaultB is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.TokenDestinationA is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.TokenDestinationB is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.TokenProgram is not set") + } + } + return nil +} + +func (inst *CollectProtocolFees) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("CollectProtocolFees")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=8]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" whirlpoolsConfig", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" whirlpool", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta("collectProtocolFeesAuthority", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" tokenVaultA", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" tokenVaultB", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" tokenDestinationA", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" tokenDestinationB", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(7))) + }) + }) + }) +} + +func (obj CollectProtocolFees) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *CollectProtocolFees) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewCollectProtocolFeesInstruction declares a new CollectProtocolFees instruction with the provided parameters and accounts. +func NewCollectProtocolFeesInstruction( + // Accounts: + whirlpoolsConfig ag_solanago.PublicKey, + whirlpool ag_solanago.PublicKey, + collectProtocolFeesAuthority ag_solanago.PublicKey, + tokenVaultA ag_solanago.PublicKey, + tokenVaultB ag_solanago.PublicKey, + tokenDestinationA ag_solanago.PublicKey, + tokenDestinationB ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey) *CollectProtocolFees { + return NewCollectProtocolFeesInstructionBuilder(). + SetWhirlpoolsConfigAccount(whirlpoolsConfig). + SetWhirlpoolAccount(whirlpool). + SetCollectProtocolFeesAuthorityAccount(collectProtocolFeesAuthority). + SetTokenVaultAAccount(tokenVaultA). + SetTokenVaultBAccount(tokenVaultB). + SetTokenDestinationAAccount(tokenDestinationA). + SetTokenDestinationBAccount(tokenDestinationB). + SetTokenProgramAccount(tokenProgram) +} diff --git a/programs/whirlpool/CollectProtocolFees_test.go b/programs/whirlpool/CollectProtocolFees_test.go new file mode 100644 index 00000000..55160e51 --- /dev/null +++ b/programs/whirlpool/CollectProtocolFees_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_CollectProtocolFees(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("CollectProtocolFees"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(CollectProtocolFees) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(CollectProtocolFees) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/CollectReward.go b/programs/whirlpool/CollectReward.go new file mode 100644 index 00000000..983106df --- /dev/null +++ b/programs/whirlpool/CollectReward.go @@ -0,0 +1,241 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "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" +) + +// CollectReward is the `collectReward` instruction. +type CollectReward struct { + RewardIndex *uint8 + + // [0] = [] whirlpool + // + // [1] = [SIGNER] positionAuthority + // + // [2] = [WRITE] position + // + // [3] = [] positionTokenAccount + // + // [4] = [WRITE] rewardOwnerAccount + // + // [5] = [WRITE] rewardVault + // + // [6] = [] tokenProgram + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewCollectRewardInstructionBuilder creates a new `CollectReward` instruction builder. +func NewCollectRewardInstructionBuilder() *CollectReward { + nd := &CollectReward{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 7), + } + return nd +} + +// SetRewardIndex sets the "rewardIndex" parameter. +func (inst *CollectReward) SetRewardIndex(rewardIndex uint8) *CollectReward { + inst.RewardIndex = &rewardIndex + return inst +} + +// SetWhirlpoolAccount sets the "whirlpool" account. +func (inst *CollectReward) SetWhirlpoolAccount(whirlpool ag_solanago.PublicKey) *CollectReward { + inst.AccountMetaSlice[0] = ag_solanago.Meta(whirlpool) + return inst +} + +// GetWhirlpoolAccount gets the "whirlpool" account. +func (inst *CollectReward) GetWhirlpoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetPositionAuthorityAccount sets the "positionAuthority" account. +func (inst *CollectReward) SetPositionAuthorityAccount(positionAuthority ag_solanago.PublicKey) *CollectReward { + inst.AccountMetaSlice[1] = ag_solanago.Meta(positionAuthority).SIGNER() + return inst +} + +// GetPositionAuthorityAccount gets the "positionAuthority" account. +func (inst *CollectReward) GetPositionAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetPositionAccount sets the "position" account. +func (inst *CollectReward) SetPositionAccount(position ag_solanago.PublicKey) *CollectReward { + inst.AccountMetaSlice[2] = ag_solanago.Meta(position).WRITE() + return inst +} + +// GetPositionAccount gets the "position" account. +func (inst *CollectReward) GetPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetPositionTokenAccountAccount sets the "positionTokenAccount" account. +func (inst *CollectReward) SetPositionTokenAccountAccount(positionTokenAccount ag_solanago.PublicKey) *CollectReward { + inst.AccountMetaSlice[3] = ag_solanago.Meta(positionTokenAccount) + return inst +} + +// GetPositionTokenAccountAccount gets the "positionTokenAccount" account. +func (inst *CollectReward) GetPositionTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetRewardOwnerAccountAccount sets the "rewardOwnerAccount" account. +func (inst *CollectReward) SetRewardOwnerAccountAccount(rewardOwnerAccount ag_solanago.PublicKey) *CollectReward { + inst.AccountMetaSlice[4] = ag_solanago.Meta(rewardOwnerAccount).WRITE() + return inst +} + +// GetRewardOwnerAccountAccount gets the "rewardOwnerAccount" account. +func (inst *CollectReward) GetRewardOwnerAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetRewardVaultAccount sets the "rewardVault" account. +func (inst *CollectReward) SetRewardVaultAccount(rewardVault ag_solanago.PublicKey) *CollectReward { + inst.AccountMetaSlice[5] = ag_solanago.Meta(rewardVault).WRITE() + return inst +} + +// GetRewardVaultAccount gets the "rewardVault" account. +func (inst *CollectReward) GetRewardVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *CollectReward) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *CollectReward { + inst.AccountMetaSlice[6] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *CollectReward) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +func (inst CollectReward) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_CollectReward, + }} +} + +// 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 CollectReward) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *CollectReward) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.RewardIndex == nil { + return errors.New("RewardIndex parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Whirlpool is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.PositionAuthority is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.Position is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.PositionTokenAccount is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.RewardOwnerAccount is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.RewardVault is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.TokenProgram is not set") + } + } + return nil +} + +func (inst *CollectReward) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("CollectReward")). + // + 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("RewardIndex", *inst.RewardIndex)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=7]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" whirlpool", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta("positionAuthority", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" position", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" positionToken", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" rewardOwner", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" rewardVault", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(6))) + }) + }) + }) +} + +func (obj CollectReward) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `RewardIndex` param: + err = encoder.Encode(obj.RewardIndex) + if err != nil { + return err + } + return nil +} +func (obj *CollectReward) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `RewardIndex`: + err = decoder.Decode(&obj.RewardIndex) + if err != nil { + return err + } + return nil +} + +// NewCollectRewardInstruction declares a new CollectReward instruction with the provided parameters and accounts. +func NewCollectRewardInstruction( + // Parameters: + rewardIndex uint8, + // Accounts: + whirlpool ag_solanago.PublicKey, + positionAuthority ag_solanago.PublicKey, + position ag_solanago.PublicKey, + positionTokenAccount ag_solanago.PublicKey, + rewardOwnerAccount ag_solanago.PublicKey, + rewardVault ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey) *CollectReward { + return NewCollectRewardInstructionBuilder(). + SetRewardIndex(rewardIndex). + SetWhirlpoolAccount(whirlpool). + SetPositionAuthorityAccount(positionAuthority). + SetPositionAccount(position). + SetPositionTokenAccountAccount(positionTokenAccount). + SetRewardOwnerAccountAccount(rewardOwnerAccount). + SetRewardVaultAccount(rewardVault). + SetTokenProgramAccount(tokenProgram) +} diff --git a/programs/whirlpool/CollectReward_test.go b/programs/whirlpool/CollectReward_test.go new file mode 100644 index 00000000..76d9fc5e --- /dev/null +++ b/programs/whirlpool/CollectReward_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_CollectReward(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("CollectReward"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(CollectReward) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(CollectReward) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/DecreaseLiquidity.go b/programs/whirlpool/DecreaseLiquidity.go new file mode 100644 index 00000000..44acf0b8 --- /dev/null +++ b/programs/whirlpool/DecreaseLiquidity.go @@ -0,0 +1,363 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "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" +) + +// DecreaseLiquidity is the `decreaseLiquidity` instruction. +type DecreaseLiquidity struct { + LiquidityAmount *ag_binary.Uint128 + TokenMinA *uint64 + TokenMinB *uint64 + + // [0] = [WRITE] whirlpool + // + // [1] = [] tokenProgram + // + // [2] = [SIGNER] positionAuthority + // + // [3] = [WRITE] position + // + // [4] = [] positionTokenAccount + // + // [5] = [WRITE] tokenOwnerAccountA + // + // [6] = [WRITE] tokenOwnerAccountB + // + // [7] = [WRITE] tokenVaultA + // + // [8] = [WRITE] tokenVaultB + // + // [9] = [WRITE] tickArrayLower + // + // [10] = [WRITE] tickArrayUpper + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewDecreaseLiquidityInstructionBuilder creates a new `DecreaseLiquidity` instruction builder. +func NewDecreaseLiquidityInstructionBuilder() *DecreaseLiquidity { + nd := &DecreaseLiquidity{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 11), + } + return nd +} + +// SetLiquidityAmount sets the "liquidityAmount" parameter. +func (inst *DecreaseLiquidity) SetLiquidityAmount(liquidityAmount ag_binary.Uint128) *DecreaseLiquidity { + inst.LiquidityAmount = &liquidityAmount + return inst +} + +// SetTokenMinA sets the "tokenMinA" parameter. +func (inst *DecreaseLiquidity) SetTokenMinA(tokenMinA uint64) *DecreaseLiquidity { + inst.TokenMinA = &tokenMinA + return inst +} + +// SetTokenMinB sets the "tokenMinB" parameter. +func (inst *DecreaseLiquidity) SetTokenMinB(tokenMinB uint64) *DecreaseLiquidity { + inst.TokenMinB = &tokenMinB + return inst +} + +// SetWhirlpoolAccount sets the "whirlpool" account. +func (inst *DecreaseLiquidity) SetWhirlpoolAccount(whirlpool ag_solanago.PublicKey) *DecreaseLiquidity { + inst.AccountMetaSlice[0] = ag_solanago.Meta(whirlpool).WRITE() + return inst +} + +// GetWhirlpoolAccount gets the "whirlpool" account. +func (inst *DecreaseLiquidity) GetWhirlpoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *DecreaseLiquidity) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *DecreaseLiquidity { + inst.AccountMetaSlice[1] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *DecreaseLiquidity) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetPositionAuthorityAccount sets the "positionAuthority" account. +func (inst *DecreaseLiquidity) SetPositionAuthorityAccount(positionAuthority ag_solanago.PublicKey) *DecreaseLiquidity { + inst.AccountMetaSlice[2] = ag_solanago.Meta(positionAuthority).SIGNER() + return inst +} + +// GetPositionAuthorityAccount gets the "positionAuthority" account. +func (inst *DecreaseLiquidity) GetPositionAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetPositionAccount sets the "position" account. +func (inst *DecreaseLiquidity) SetPositionAccount(position ag_solanago.PublicKey) *DecreaseLiquidity { + inst.AccountMetaSlice[3] = ag_solanago.Meta(position).WRITE() + return inst +} + +// GetPositionAccount gets the "position" account. +func (inst *DecreaseLiquidity) GetPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetPositionTokenAccountAccount sets the "positionTokenAccount" account. +func (inst *DecreaseLiquidity) SetPositionTokenAccountAccount(positionTokenAccount ag_solanago.PublicKey) *DecreaseLiquidity { + inst.AccountMetaSlice[4] = ag_solanago.Meta(positionTokenAccount) + return inst +} + +// GetPositionTokenAccountAccount gets the "positionTokenAccount" account. +func (inst *DecreaseLiquidity) GetPositionTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetTokenOwnerAccountAAccount sets the "tokenOwnerAccountA" account. +func (inst *DecreaseLiquidity) SetTokenOwnerAccountAAccount(tokenOwnerAccountA ag_solanago.PublicKey) *DecreaseLiquidity { + inst.AccountMetaSlice[5] = ag_solanago.Meta(tokenOwnerAccountA).WRITE() + return inst +} + +// GetTokenOwnerAccountAAccount gets the "tokenOwnerAccountA" account. +func (inst *DecreaseLiquidity) GetTokenOwnerAccountAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetTokenOwnerAccountBAccount sets the "tokenOwnerAccountB" account. +func (inst *DecreaseLiquidity) SetTokenOwnerAccountBAccount(tokenOwnerAccountB ag_solanago.PublicKey) *DecreaseLiquidity { + inst.AccountMetaSlice[6] = ag_solanago.Meta(tokenOwnerAccountB).WRITE() + return inst +} + +// GetTokenOwnerAccountBAccount gets the "tokenOwnerAccountB" account. +func (inst *DecreaseLiquidity) GetTokenOwnerAccountBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetTokenVaultAAccount sets the "tokenVaultA" account. +func (inst *DecreaseLiquidity) SetTokenVaultAAccount(tokenVaultA ag_solanago.PublicKey) *DecreaseLiquidity { + inst.AccountMetaSlice[7] = ag_solanago.Meta(tokenVaultA).WRITE() + return inst +} + +// GetTokenVaultAAccount gets the "tokenVaultA" account. +func (inst *DecreaseLiquidity) GetTokenVaultAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetTokenVaultBAccount sets the "tokenVaultB" account. +func (inst *DecreaseLiquidity) SetTokenVaultBAccount(tokenVaultB ag_solanago.PublicKey) *DecreaseLiquidity { + inst.AccountMetaSlice[8] = ag_solanago.Meta(tokenVaultB).WRITE() + return inst +} + +// GetTokenVaultBAccount gets the "tokenVaultB" account. +func (inst *DecreaseLiquidity) GetTokenVaultBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetTickArrayLowerAccount sets the "tickArrayLower" account. +func (inst *DecreaseLiquidity) SetTickArrayLowerAccount(tickArrayLower ag_solanago.PublicKey) *DecreaseLiquidity { + inst.AccountMetaSlice[9] = ag_solanago.Meta(tickArrayLower).WRITE() + return inst +} + +// GetTickArrayLowerAccount gets the "tickArrayLower" account. +func (inst *DecreaseLiquidity) GetTickArrayLowerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetTickArrayUpperAccount sets the "tickArrayUpper" account. +func (inst *DecreaseLiquidity) SetTickArrayUpperAccount(tickArrayUpper ag_solanago.PublicKey) *DecreaseLiquidity { + inst.AccountMetaSlice[10] = ag_solanago.Meta(tickArrayUpper).WRITE() + return inst +} + +// GetTickArrayUpperAccount gets the "tickArrayUpper" account. +func (inst *DecreaseLiquidity) GetTickArrayUpperAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +func (inst DecreaseLiquidity) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_DecreaseLiquidity, + }} +} + +// 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 DecreaseLiquidity) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *DecreaseLiquidity) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.LiquidityAmount == nil { + return errors.New("LiquidityAmount parameter is not set") + } + if inst.TokenMinA == nil { + return errors.New("TokenMinA parameter is not set") + } + if inst.TokenMinB == nil { + return errors.New("TokenMinB parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Whirlpool is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.PositionAuthority is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.Position is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.PositionTokenAccount is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.TokenOwnerAccountA is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.TokenOwnerAccountB is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.TokenVaultA is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.TokenVaultB is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.TickArrayLower is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.TickArrayUpper is not set") + } + } + return nil +} + +func (inst *DecreaseLiquidity) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("DecreaseLiquidity")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=3]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param("LiquidityAmount", *inst.LiquidityAmount)) + paramsBranch.Child(ag_format.Param(" TokenMinA", *inst.TokenMinA)) + paramsBranch.Child(ag_format.Param(" TokenMinB", *inst.TokenMinB)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=11]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" whirlpool", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" positionAuthority", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" position", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" positionToken", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta("tokenOwnerAccountA", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta("tokenOwnerAccountB", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" tokenVaultA", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" tokenVaultB", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" tickArrayLower", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" tickArrayUpper", inst.AccountMetaSlice.Get(10))) + }) + }) + }) +} + +func (obj DecreaseLiquidity) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `LiquidityAmount` param: + err = encoder.Encode(obj.LiquidityAmount) + if err != nil { + return err + } + // Serialize `TokenMinA` param: + err = encoder.Encode(obj.TokenMinA) + if err != nil { + return err + } + // Serialize `TokenMinB` param: + err = encoder.Encode(obj.TokenMinB) + if err != nil { + return err + } + return nil +} +func (obj *DecreaseLiquidity) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `LiquidityAmount`: + err = decoder.Decode(&obj.LiquidityAmount) + if err != nil { + return err + } + // Deserialize `TokenMinA`: + err = decoder.Decode(&obj.TokenMinA) + if err != nil { + return err + } + // Deserialize `TokenMinB`: + err = decoder.Decode(&obj.TokenMinB) + if err != nil { + return err + } + return nil +} + +// NewDecreaseLiquidityInstruction declares a new DecreaseLiquidity instruction with the provided parameters and accounts. +func NewDecreaseLiquidityInstruction( + // Parameters: + liquidityAmount ag_binary.Uint128, + tokenMinA uint64, + tokenMinB uint64, + // Accounts: + whirlpool ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + positionAuthority ag_solanago.PublicKey, + position ag_solanago.PublicKey, + positionTokenAccount ag_solanago.PublicKey, + tokenOwnerAccountA ag_solanago.PublicKey, + tokenOwnerAccountB ag_solanago.PublicKey, + tokenVaultA ag_solanago.PublicKey, + tokenVaultB ag_solanago.PublicKey, + tickArrayLower ag_solanago.PublicKey, + tickArrayUpper ag_solanago.PublicKey) *DecreaseLiquidity { + return NewDecreaseLiquidityInstructionBuilder(). + SetLiquidityAmount(liquidityAmount). + SetTokenMinA(tokenMinA). + SetTokenMinB(tokenMinB). + SetWhirlpoolAccount(whirlpool). + SetTokenProgramAccount(tokenProgram). + SetPositionAuthorityAccount(positionAuthority). + SetPositionAccount(position). + SetPositionTokenAccountAccount(positionTokenAccount). + SetTokenOwnerAccountAAccount(tokenOwnerAccountA). + SetTokenOwnerAccountBAccount(tokenOwnerAccountB). + SetTokenVaultAAccount(tokenVaultA). + SetTokenVaultBAccount(tokenVaultB). + SetTickArrayLowerAccount(tickArrayLower). + SetTickArrayUpperAccount(tickArrayUpper) +} diff --git a/programs/whirlpool/DecreaseLiquidity_test.go b/programs/whirlpool/DecreaseLiquidity_test.go new file mode 100644 index 00000000..2fd8b21d --- /dev/null +++ b/programs/whirlpool/DecreaseLiquidity_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_DecreaseLiquidity(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("DecreaseLiquidity"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(DecreaseLiquidity) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(DecreaseLiquidity) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/DeletePositionBundle.go b/programs/whirlpool/DeletePositionBundle.go new file mode 100644 index 00000000..a8a9507b --- /dev/null +++ b/programs/whirlpool/DeletePositionBundle.go @@ -0,0 +1,193 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "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" +) + +// DeletePositionBundle is the `deletePositionBundle` instruction. +type DeletePositionBundle struct { + + // [0] = [WRITE] positionBundle + // + // [1] = [WRITE] positionBundleMint + // + // [2] = [WRITE] positionBundleTokenAccount + // + // [3] = [SIGNER] positionBundleOwner + // + // [4] = [WRITE] receiver + // + // [5] = [] tokenProgram + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewDeletePositionBundleInstructionBuilder creates a new `DeletePositionBundle` instruction builder. +func NewDeletePositionBundleInstructionBuilder() *DeletePositionBundle { + nd := &DeletePositionBundle{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 6), + } + return nd +} + +// SetPositionBundleAccount sets the "positionBundle" account. +func (inst *DeletePositionBundle) SetPositionBundleAccount(positionBundle ag_solanago.PublicKey) *DeletePositionBundle { + inst.AccountMetaSlice[0] = ag_solanago.Meta(positionBundle).WRITE() + return inst +} + +// GetPositionBundleAccount gets the "positionBundle" account. +func (inst *DeletePositionBundle) GetPositionBundleAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetPositionBundleMintAccount sets the "positionBundleMint" account. +func (inst *DeletePositionBundle) SetPositionBundleMintAccount(positionBundleMint ag_solanago.PublicKey) *DeletePositionBundle { + inst.AccountMetaSlice[1] = ag_solanago.Meta(positionBundleMint).WRITE() + return inst +} + +// GetPositionBundleMintAccount gets the "positionBundleMint" account. +func (inst *DeletePositionBundle) GetPositionBundleMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetPositionBundleTokenAccountAccount sets the "positionBundleTokenAccount" account. +func (inst *DeletePositionBundle) SetPositionBundleTokenAccountAccount(positionBundleTokenAccount ag_solanago.PublicKey) *DeletePositionBundle { + inst.AccountMetaSlice[2] = ag_solanago.Meta(positionBundleTokenAccount).WRITE() + return inst +} + +// GetPositionBundleTokenAccountAccount gets the "positionBundleTokenAccount" account. +func (inst *DeletePositionBundle) GetPositionBundleTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetPositionBundleOwnerAccount sets the "positionBundleOwner" account. +func (inst *DeletePositionBundle) SetPositionBundleOwnerAccount(positionBundleOwner ag_solanago.PublicKey) *DeletePositionBundle { + inst.AccountMetaSlice[3] = ag_solanago.Meta(positionBundleOwner).SIGNER() + return inst +} + +// GetPositionBundleOwnerAccount gets the "positionBundleOwner" account. +func (inst *DeletePositionBundle) GetPositionBundleOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetReceiverAccount sets the "receiver" account. +func (inst *DeletePositionBundle) SetReceiverAccount(receiver ag_solanago.PublicKey) *DeletePositionBundle { + inst.AccountMetaSlice[4] = ag_solanago.Meta(receiver).WRITE() + return inst +} + +// GetReceiverAccount gets the "receiver" account. +func (inst *DeletePositionBundle) GetReceiverAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *DeletePositionBundle) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *DeletePositionBundle { + inst.AccountMetaSlice[5] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *DeletePositionBundle) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +func (inst DeletePositionBundle) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_DeletePositionBundle, + }} +} + +// 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 DeletePositionBundle) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *DeletePositionBundle) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.PositionBundle is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.PositionBundleMint is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.PositionBundleTokenAccount is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.PositionBundleOwner is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.Receiver is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.TokenProgram is not set") + } + } + return nil +} + +func (inst *DeletePositionBundle) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("DeletePositionBundle")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=6]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" positionBundle", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" positionBundleMint", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta("positionBundleToken", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta("positionBundleOwner", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" receiver", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(5))) + }) + }) + }) +} + +func (obj DeletePositionBundle) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *DeletePositionBundle) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewDeletePositionBundleInstruction declares a new DeletePositionBundle instruction with the provided parameters and accounts. +func NewDeletePositionBundleInstruction( + // Accounts: + positionBundle ag_solanago.PublicKey, + positionBundleMint ag_solanago.PublicKey, + positionBundleTokenAccount ag_solanago.PublicKey, + positionBundleOwner ag_solanago.PublicKey, + receiver ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey) *DeletePositionBundle { + return NewDeletePositionBundleInstructionBuilder(). + SetPositionBundleAccount(positionBundle). + SetPositionBundleMintAccount(positionBundleMint). + SetPositionBundleTokenAccountAccount(positionBundleTokenAccount). + SetPositionBundleOwnerAccount(positionBundleOwner). + SetReceiverAccount(receiver). + SetTokenProgramAccount(tokenProgram) +} diff --git a/programs/whirlpool/DeletePositionBundle_test.go b/programs/whirlpool/DeletePositionBundle_test.go new file mode 100644 index 00000000..5b1c77be --- /dev/null +++ b/programs/whirlpool/DeletePositionBundle_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_DeletePositionBundle(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("DeletePositionBundle"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(DeletePositionBundle) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(DeletePositionBundle) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/IncreaseLiquidity.go b/programs/whirlpool/IncreaseLiquidity.go new file mode 100644 index 00000000..3ed65900 --- /dev/null +++ b/programs/whirlpool/IncreaseLiquidity.go @@ -0,0 +1,363 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "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" +) + +// IncreaseLiquidity is the `increaseLiquidity` instruction. +type IncreaseLiquidity struct { + LiquidityAmount *ag_binary.Uint128 + TokenMaxA *uint64 + TokenMaxB *uint64 + + // [0] = [WRITE] whirlpool + // + // [1] = [] tokenProgram + // + // [2] = [SIGNER] positionAuthority + // + // [3] = [WRITE] position + // + // [4] = [] positionTokenAccount + // + // [5] = [WRITE] tokenOwnerAccountA + // + // [6] = [WRITE] tokenOwnerAccountB + // + // [7] = [WRITE] tokenVaultA + // + // [8] = [WRITE] tokenVaultB + // + // [9] = [WRITE] tickArrayLower + // + // [10] = [WRITE] tickArrayUpper + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewIncreaseLiquidityInstructionBuilder creates a new `IncreaseLiquidity` instruction builder. +func NewIncreaseLiquidityInstructionBuilder() *IncreaseLiquidity { + nd := &IncreaseLiquidity{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 11), + } + return nd +} + +// SetLiquidityAmount sets the "liquidityAmount" parameter. +func (inst *IncreaseLiquidity) SetLiquidityAmount(liquidityAmount ag_binary.Uint128) *IncreaseLiquidity { + inst.LiquidityAmount = &liquidityAmount + return inst +} + +// SetTokenMaxA sets the "tokenMaxA" parameter. +func (inst *IncreaseLiquidity) SetTokenMaxA(tokenMaxA uint64) *IncreaseLiquidity { + inst.TokenMaxA = &tokenMaxA + return inst +} + +// SetTokenMaxB sets the "tokenMaxB" parameter. +func (inst *IncreaseLiquidity) SetTokenMaxB(tokenMaxB uint64) *IncreaseLiquidity { + inst.TokenMaxB = &tokenMaxB + return inst +} + +// SetWhirlpoolAccount sets the "whirlpool" account. +func (inst *IncreaseLiquidity) SetWhirlpoolAccount(whirlpool ag_solanago.PublicKey) *IncreaseLiquidity { + inst.AccountMetaSlice[0] = ag_solanago.Meta(whirlpool).WRITE() + return inst +} + +// GetWhirlpoolAccount gets the "whirlpool" account. +func (inst *IncreaseLiquidity) GetWhirlpoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *IncreaseLiquidity) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *IncreaseLiquidity { + inst.AccountMetaSlice[1] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *IncreaseLiquidity) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetPositionAuthorityAccount sets the "positionAuthority" account. +func (inst *IncreaseLiquidity) SetPositionAuthorityAccount(positionAuthority ag_solanago.PublicKey) *IncreaseLiquidity { + inst.AccountMetaSlice[2] = ag_solanago.Meta(positionAuthority).SIGNER() + return inst +} + +// GetPositionAuthorityAccount gets the "positionAuthority" account. +func (inst *IncreaseLiquidity) GetPositionAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetPositionAccount sets the "position" account. +func (inst *IncreaseLiquidity) SetPositionAccount(position ag_solanago.PublicKey) *IncreaseLiquidity { + inst.AccountMetaSlice[3] = ag_solanago.Meta(position).WRITE() + return inst +} + +// GetPositionAccount gets the "position" account. +func (inst *IncreaseLiquidity) GetPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetPositionTokenAccountAccount sets the "positionTokenAccount" account. +func (inst *IncreaseLiquidity) SetPositionTokenAccountAccount(positionTokenAccount ag_solanago.PublicKey) *IncreaseLiquidity { + inst.AccountMetaSlice[4] = ag_solanago.Meta(positionTokenAccount) + return inst +} + +// GetPositionTokenAccountAccount gets the "positionTokenAccount" account. +func (inst *IncreaseLiquidity) GetPositionTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetTokenOwnerAccountAAccount sets the "tokenOwnerAccountA" account. +func (inst *IncreaseLiquidity) SetTokenOwnerAccountAAccount(tokenOwnerAccountA ag_solanago.PublicKey) *IncreaseLiquidity { + inst.AccountMetaSlice[5] = ag_solanago.Meta(tokenOwnerAccountA).WRITE() + return inst +} + +// GetTokenOwnerAccountAAccount gets the "tokenOwnerAccountA" account. +func (inst *IncreaseLiquidity) GetTokenOwnerAccountAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetTokenOwnerAccountBAccount sets the "tokenOwnerAccountB" account. +func (inst *IncreaseLiquidity) SetTokenOwnerAccountBAccount(tokenOwnerAccountB ag_solanago.PublicKey) *IncreaseLiquidity { + inst.AccountMetaSlice[6] = ag_solanago.Meta(tokenOwnerAccountB).WRITE() + return inst +} + +// GetTokenOwnerAccountBAccount gets the "tokenOwnerAccountB" account. +func (inst *IncreaseLiquidity) GetTokenOwnerAccountBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetTokenVaultAAccount sets the "tokenVaultA" account. +func (inst *IncreaseLiquidity) SetTokenVaultAAccount(tokenVaultA ag_solanago.PublicKey) *IncreaseLiquidity { + inst.AccountMetaSlice[7] = ag_solanago.Meta(tokenVaultA).WRITE() + return inst +} + +// GetTokenVaultAAccount gets the "tokenVaultA" account. +func (inst *IncreaseLiquidity) GetTokenVaultAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetTokenVaultBAccount sets the "tokenVaultB" account. +func (inst *IncreaseLiquidity) SetTokenVaultBAccount(tokenVaultB ag_solanago.PublicKey) *IncreaseLiquidity { + inst.AccountMetaSlice[8] = ag_solanago.Meta(tokenVaultB).WRITE() + return inst +} + +// GetTokenVaultBAccount gets the "tokenVaultB" account. +func (inst *IncreaseLiquidity) GetTokenVaultBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetTickArrayLowerAccount sets the "tickArrayLower" account. +func (inst *IncreaseLiquidity) SetTickArrayLowerAccount(tickArrayLower ag_solanago.PublicKey) *IncreaseLiquidity { + inst.AccountMetaSlice[9] = ag_solanago.Meta(tickArrayLower).WRITE() + return inst +} + +// GetTickArrayLowerAccount gets the "tickArrayLower" account. +func (inst *IncreaseLiquidity) GetTickArrayLowerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetTickArrayUpperAccount sets the "tickArrayUpper" account. +func (inst *IncreaseLiquidity) SetTickArrayUpperAccount(tickArrayUpper ag_solanago.PublicKey) *IncreaseLiquidity { + inst.AccountMetaSlice[10] = ag_solanago.Meta(tickArrayUpper).WRITE() + return inst +} + +// GetTickArrayUpperAccount gets the "tickArrayUpper" account. +func (inst *IncreaseLiquidity) GetTickArrayUpperAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +func (inst IncreaseLiquidity) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_IncreaseLiquidity, + }} +} + +// 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 IncreaseLiquidity) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *IncreaseLiquidity) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.LiquidityAmount == nil { + return errors.New("LiquidityAmount parameter is not set") + } + if inst.TokenMaxA == nil { + return errors.New("TokenMaxA parameter is not set") + } + if inst.TokenMaxB == nil { + return errors.New("TokenMaxB parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Whirlpool is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.PositionAuthority is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.Position is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.PositionTokenAccount is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.TokenOwnerAccountA is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.TokenOwnerAccountB is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.TokenVaultA is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.TokenVaultB is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.TickArrayLower is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.TickArrayUpper is not set") + } + } + return nil +} + +func (inst *IncreaseLiquidity) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("IncreaseLiquidity")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=3]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param("LiquidityAmount", *inst.LiquidityAmount)) + paramsBranch.Child(ag_format.Param(" TokenMaxA", *inst.TokenMaxA)) + paramsBranch.Child(ag_format.Param(" TokenMaxB", *inst.TokenMaxB)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=11]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" whirlpool", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" positionAuthority", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" position", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" positionToken", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta("tokenOwnerAccountA", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta("tokenOwnerAccountB", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" tokenVaultA", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" tokenVaultB", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" tickArrayLower", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" tickArrayUpper", inst.AccountMetaSlice.Get(10))) + }) + }) + }) +} + +func (obj IncreaseLiquidity) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `LiquidityAmount` param: + err = encoder.Encode(obj.LiquidityAmount) + if err != nil { + return err + } + // Serialize `TokenMaxA` param: + err = encoder.Encode(obj.TokenMaxA) + if err != nil { + return err + } + // Serialize `TokenMaxB` param: + err = encoder.Encode(obj.TokenMaxB) + if err != nil { + return err + } + return nil +} +func (obj *IncreaseLiquidity) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `LiquidityAmount`: + err = decoder.Decode(&obj.LiquidityAmount) + if err != nil { + return err + } + // Deserialize `TokenMaxA`: + err = decoder.Decode(&obj.TokenMaxA) + if err != nil { + return err + } + // Deserialize `TokenMaxB`: + err = decoder.Decode(&obj.TokenMaxB) + if err != nil { + return err + } + return nil +} + +// NewIncreaseLiquidityInstruction declares a new IncreaseLiquidity instruction with the provided parameters and accounts. +func NewIncreaseLiquidityInstruction( + // Parameters: + liquidityAmount ag_binary.Uint128, + tokenMaxA uint64, + tokenMaxB uint64, + // Accounts: + whirlpool ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + positionAuthority ag_solanago.PublicKey, + position ag_solanago.PublicKey, + positionTokenAccount ag_solanago.PublicKey, + tokenOwnerAccountA ag_solanago.PublicKey, + tokenOwnerAccountB ag_solanago.PublicKey, + tokenVaultA ag_solanago.PublicKey, + tokenVaultB ag_solanago.PublicKey, + tickArrayLower ag_solanago.PublicKey, + tickArrayUpper ag_solanago.PublicKey) *IncreaseLiquidity { + return NewIncreaseLiquidityInstructionBuilder(). + SetLiquidityAmount(liquidityAmount). + SetTokenMaxA(tokenMaxA). + SetTokenMaxB(tokenMaxB). + SetWhirlpoolAccount(whirlpool). + SetTokenProgramAccount(tokenProgram). + SetPositionAuthorityAccount(positionAuthority). + SetPositionAccount(position). + SetPositionTokenAccountAccount(positionTokenAccount). + SetTokenOwnerAccountAAccount(tokenOwnerAccountA). + SetTokenOwnerAccountBAccount(tokenOwnerAccountB). + SetTokenVaultAAccount(tokenVaultA). + SetTokenVaultBAccount(tokenVaultB). + SetTickArrayLowerAccount(tickArrayLower). + SetTickArrayUpperAccount(tickArrayUpper) +} diff --git a/programs/whirlpool/IncreaseLiquidity_test.go b/programs/whirlpool/IncreaseLiquidity_test.go new file mode 100644 index 00000000..a0277725 --- /dev/null +++ b/programs/whirlpool/IncreaseLiquidity_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_IncreaseLiquidity(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("IncreaseLiquidity"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(IncreaseLiquidity) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(IncreaseLiquidity) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/InitializeConfig.go b/programs/whirlpool/InitializeConfig.go new file mode 100644 index 00000000..914da5e7 --- /dev/null +++ b/programs/whirlpool/InitializeConfig.go @@ -0,0 +1,234 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "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" +) + +// InitializeConfig is the `initializeConfig` instruction. +type InitializeConfig struct { + FeeAuthority *ag_solanago.PublicKey + CollectProtocolFeesAuthority *ag_solanago.PublicKey + RewardEmissionsSuperAuthority *ag_solanago.PublicKey + DefaultProtocolFeeRate *uint16 + + // [0] = [WRITE, SIGNER] config + // + // [1] = [WRITE, SIGNER] funder + // + // [2] = [] systemProgram + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewInitializeConfigInstructionBuilder creates a new `InitializeConfig` instruction builder. +func NewInitializeConfigInstructionBuilder() *InitializeConfig { + nd := &InitializeConfig{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 3), + } + return nd +} + +// SetFeeAuthority sets the "feeAuthority" parameter. +func (inst *InitializeConfig) SetFeeAuthority(feeAuthority ag_solanago.PublicKey) *InitializeConfig { + inst.FeeAuthority = &feeAuthority + return inst +} + +// SetCollectProtocolFeesAuthority sets the "collectProtocolFeesAuthority" parameter. +func (inst *InitializeConfig) SetCollectProtocolFeesAuthority(collectProtocolFeesAuthority ag_solanago.PublicKey) *InitializeConfig { + inst.CollectProtocolFeesAuthority = &collectProtocolFeesAuthority + return inst +} + +// SetRewardEmissionsSuperAuthority sets the "rewardEmissionsSuperAuthority" parameter. +func (inst *InitializeConfig) SetRewardEmissionsSuperAuthority(rewardEmissionsSuperAuthority ag_solanago.PublicKey) *InitializeConfig { + inst.RewardEmissionsSuperAuthority = &rewardEmissionsSuperAuthority + return inst +} + +// SetDefaultProtocolFeeRate sets the "defaultProtocolFeeRate" parameter. +func (inst *InitializeConfig) SetDefaultProtocolFeeRate(defaultProtocolFeeRate uint16) *InitializeConfig { + inst.DefaultProtocolFeeRate = &defaultProtocolFeeRate + return inst +} + +// SetConfigAccount sets the "config" account. +func (inst *InitializeConfig) SetConfigAccount(config ag_solanago.PublicKey) *InitializeConfig { + inst.AccountMetaSlice[0] = ag_solanago.Meta(config).WRITE().SIGNER() + return inst +} + +// GetConfigAccount gets the "config" account. +func (inst *InitializeConfig) GetConfigAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetFunderAccount sets the "funder" account. +func (inst *InitializeConfig) SetFunderAccount(funder ag_solanago.PublicKey) *InitializeConfig { + inst.AccountMetaSlice[1] = ag_solanago.Meta(funder).WRITE().SIGNER() + return inst +} + +// GetFunderAccount gets the "funder" account. +func (inst *InitializeConfig) GetFunderAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +func (inst *InitializeConfig) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *InitializeConfig { + inst.AccountMetaSlice[2] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +func (inst *InitializeConfig) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +func (inst InitializeConfig) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_InitializeConfig, + }} +} + +// 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 InitializeConfig) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *InitializeConfig) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.FeeAuthority == nil { + return errors.New("FeeAuthority parameter is not set") + } + if inst.CollectProtocolFeesAuthority == nil { + return errors.New("CollectProtocolFeesAuthority parameter is not set") + } + if inst.RewardEmissionsSuperAuthority == nil { + return errors.New("RewardEmissionsSuperAuthority parameter is not set") + } + if inst.DefaultProtocolFeeRate == nil { + return errors.New("DefaultProtocolFeeRate parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Config is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Funder is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.SystemProgram is not set") + } + } + return nil +} + +func (inst *InitializeConfig) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("InitializeConfig")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=4]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" FeeAuthority", *inst.FeeAuthority)) + paramsBranch.Child(ag_format.Param(" CollectProtocolFeesAuthority", *inst.CollectProtocolFeesAuthority)) + paramsBranch.Child(ag_format.Param("RewardEmissionsSuperAuthority", *inst.RewardEmissionsSuperAuthority)) + paramsBranch.Child(ag_format.Param(" DefaultProtocolFeeRate", *inst.DefaultProtocolFeeRate)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=3]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" config", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" funder", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta("systemProgram", inst.AccountMetaSlice.Get(2))) + }) + }) + }) +} + +func (obj InitializeConfig) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `FeeAuthority` param: + err = encoder.Encode(obj.FeeAuthority) + if err != nil { + return err + } + // Serialize `CollectProtocolFeesAuthority` param: + err = encoder.Encode(obj.CollectProtocolFeesAuthority) + if err != nil { + return err + } + // Serialize `RewardEmissionsSuperAuthority` param: + err = encoder.Encode(obj.RewardEmissionsSuperAuthority) + if err != nil { + return err + } + // Serialize `DefaultProtocolFeeRate` param: + err = encoder.Encode(obj.DefaultProtocolFeeRate) + if err != nil { + return err + } + return nil +} +func (obj *InitializeConfig) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `FeeAuthority`: + err = decoder.Decode(&obj.FeeAuthority) + if err != nil { + return err + } + // Deserialize `CollectProtocolFeesAuthority`: + err = decoder.Decode(&obj.CollectProtocolFeesAuthority) + if err != nil { + return err + } + // Deserialize `RewardEmissionsSuperAuthority`: + err = decoder.Decode(&obj.RewardEmissionsSuperAuthority) + if err != nil { + return err + } + // Deserialize `DefaultProtocolFeeRate`: + err = decoder.Decode(&obj.DefaultProtocolFeeRate) + if err != nil { + return err + } + return nil +} + +// NewInitializeConfigInstruction declares a new InitializeConfig instruction with the provided parameters and accounts. +func NewInitializeConfigInstruction( + // Parameters: + feeAuthority ag_solanago.PublicKey, + collectProtocolFeesAuthority ag_solanago.PublicKey, + rewardEmissionsSuperAuthority ag_solanago.PublicKey, + defaultProtocolFeeRate uint16, + // Accounts: + config ag_solanago.PublicKey, + funder ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey) *InitializeConfig { + return NewInitializeConfigInstructionBuilder(). + SetFeeAuthority(feeAuthority). + SetCollectProtocolFeesAuthority(collectProtocolFeesAuthority). + SetRewardEmissionsSuperAuthority(rewardEmissionsSuperAuthority). + SetDefaultProtocolFeeRate(defaultProtocolFeeRate). + SetConfigAccount(config). + SetFunderAccount(funder). + SetSystemProgramAccount(systemProgram) +} diff --git a/programs/whirlpool/InitializeConfig_test.go b/programs/whirlpool/InitializeConfig_test.go new file mode 100644 index 00000000..266f96d8 --- /dev/null +++ b/programs/whirlpool/InitializeConfig_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_InitializeConfig(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("InitializeConfig"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(InitializeConfig) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(InitializeConfig) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/InitializeFeeTier.go b/programs/whirlpool/InitializeFeeTier.go new file mode 100644 index 00000000..9077e187 --- /dev/null +++ b/programs/whirlpool/InitializeFeeTier.go @@ -0,0 +1,226 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "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" +) + +// InitializeFeeTier is the `initializeFeeTier` instruction. +type InitializeFeeTier struct { + TickSpacing *uint16 + DefaultFeeRate *uint16 + + // [0] = [] config + // + // [1] = [WRITE] feeTier + // + // [2] = [WRITE, SIGNER] funder + // + // [3] = [SIGNER] feeAuthority + // + // [4] = [] systemProgram + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewInitializeFeeTierInstructionBuilder creates a new `InitializeFeeTier` instruction builder. +func NewInitializeFeeTierInstructionBuilder() *InitializeFeeTier { + nd := &InitializeFeeTier{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 5), + } + return nd +} + +// SetTickSpacing sets the "tickSpacing" parameter. +func (inst *InitializeFeeTier) SetTickSpacing(tickSpacing uint16) *InitializeFeeTier { + inst.TickSpacing = &tickSpacing + return inst +} + +// SetDefaultFeeRate sets the "defaultFeeRate" parameter. +func (inst *InitializeFeeTier) SetDefaultFeeRate(defaultFeeRate uint16) *InitializeFeeTier { + inst.DefaultFeeRate = &defaultFeeRate + return inst +} + +// SetConfigAccount sets the "config" account. +func (inst *InitializeFeeTier) SetConfigAccount(config ag_solanago.PublicKey) *InitializeFeeTier { + inst.AccountMetaSlice[0] = ag_solanago.Meta(config) + return inst +} + +// GetConfigAccount gets the "config" account. +func (inst *InitializeFeeTier) GetConfigAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetFeeTierAccount sets the "feeTier" account. +func (inst *InitializeFeeTier) SetFeeTierAccount(feeTier ag_solanago.PublicKey) *InitializeFeeTier { + inst.AccountMetaSlice[1] = ag_solanago.Meta(feeTier).WRITE() + return inst +} + +// GetFeeTierAccount gets the "feeTier" account. +func (inst *InitializeFeeTier) GetFeeTierAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetFunderAccount sets the "funder" account. +func (inst *InitializeFeeTier) SetFunderAccount(funder ag_solanago.PublicKey) *InitializeFeeTier { + inst.AccountMetaSlice[2] = ag_solanago.Meta(funder).WRITE().SIGNER() + return inst +} + +// GetFunderAccount gets the "funder" account. +func (inst *InitializeFeeTier) GetFunderAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetFeeAuthorityAccount sets the "feeAuthority" account. +func (inst *InitializeFeeTier) SetFeeAuthorityAccount(feeAuthority ag_solanago.PublicKey) *InitializeFeeTier { + inst.AccountMetaSlice[3] = ag_solanago.Meta(feeAuthority).SIGNER() + return inst +} + +// GetFeeAuthorityAccount gets the "feeAuthority" account. +func (inst *InitializeFeeTier) GetFeeAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +func (inst *InitializeFeeTier) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *InitializeFeeTier { + inst.AccountMetaSlice[4] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +func (inst *InitializeFeeTier) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +func (inst InitializeFeeTier) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_InitializeFeeTier, + }} +} + +// 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 InitializeFeeTier) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *InitializeFeeTier) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.TickSpacing == nil { + return errors.New("TickSpacing parameter is not set") + } + if inst.DefaultFeeRate == nil { + return errors.New("DefaultFeeRate parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Config is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.FeeTier is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.Funder is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.FeeAuthority is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.SystemProgram is not set") + } + } + return nil +} + +func (inst *InitializeFeeTier) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("InitializeFeeTier")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=2]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" TickSpacing", *inst.TickSpacing)) + paramsBranch.Child(ag_format.Param("DefaultFeeRate", *inst.DefaultFeeRate)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=5]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" config", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" feeTier", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" funder", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" feeAuthority", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta("systemProgram", inst.AccountMetaSlice.Get(4))) + }) + }) + }) +} + +func (obj InitializeFeeTier) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `TickSpacing` param: + err = encoder.Encode(obj.TickSpacing) + if err != nil { + return err + } + // Serialize `DefaultFeeRate` param: + err = encoder.Encode(obj.DefaultFeeRate) + if err != nil { + return err + } + return nil +} +func (obj *InitializeFeeTier) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `TickSpacing`: + err = decoder.Decode(&obj.TickSpacing) + if err != nil { + return err + } + // Deserialize `DefaultFeeRate`: + err = decoder.Decode(&obj.DefaultFeeRate) + if err != nil { + return err + } + return nil +} + +// NewInitializeFeeTierInstruction declares a new InitializeFeeTier instruction with the provided parameters and accounts. +func NewInitializeFeeTierInstruction( + // Parameters: + tickSpacing uint16, + defaultFeeRate uint16, + // Accounts: + config ag_solanago.PublicKey, + feeTier ag_solanago.PublicKey, + funder ag_solanago.PublicKey, + feeAuthority ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey) *InitializeFeeTier { + return NewInitializeFeeTierInstructionBuilder(). + SetTickSpacing(tickSpacing). + SetDefaultFeeRate(defaultFeeRate). + SetConfigAccount(config). + SetFeeTierAccount(feeTier). + SetFunderAccount(funder). + SetFeeAuthorityAccount(feeAuthority). + SetSystemProgramAccount(systemProgram) +} diff --git a/programs/whirlpool/InitializeFeeTier_test.go b/programs/whirlpool/InitializeFeeTier_test.go new file mode 100644 index 00000000..04df6d61 --- /dev/null +++ b/programs/whirlpool/InitializeFeeTier_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_InitializeFeeTier(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("InitializeFeeTier"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(InitializeFeeTier) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(InitializeFeeTier) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/InitializePool.go b/programs/whirlpool/InitializePool.go new file mode 100644 index 00000000..9985cc45 --- /dev/null +++ b/programs/whirlpool/InitializePool.go @@ -0,0 +1,363 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "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" +) + +// InitializePool is the `initializePool` instruction. +type InitializePool struct { + Bumps *WhirlpoolBumps + TickSpacing *uint16 + InitialSqrtPrice *ag_binary.Uint128 + + // [0] = [] whirlpoolsConfig + // + // [1] = [] tokenMintA + // + // [2] = [] tokenMintB + // + // [3] = [WRITE, SIGNER] funder + // + // [4] = [WRITE] whirlpool + // + // [5] = [WRITE, SIGNER] tokenVaultA + // + // [6] = [WRITE, SIGNER] tokenVaultB + // + // [7] = [] feeTier + // + // [8] = [] tokenProgram + // + // [9] = [] systemProgram + // + // [10] = [] rent + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewInitializePoolInstructionBuilder creates a new `InitializePool` instruction builder. +func NewInitializePoolInstructionBuilder() *InitializePool { + nd := &InitializePool{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 11), + } + return nd +} + +// SetBumps sets the "bumps" parameter. +func (inst *InitializePool) SetBumps(bumps WhirlpoolBumps) *InitializePool { + inst.Bumps = &bumps + return inst +} + +// SetTickSpacing sets the "tickSpacing" parameter. +func (inst *InitializePool) SetTickSpacing(tickSpacing uint16) *InitializePool { + inst.TickSpacing = &tickSpacing + return inst +} + +// SetInitialSqrtPrice sets the "initialSqrtPrice" parameter. +func (inst *InitializePool) SetInitialSqrtPrice(initialSqrtPrice ag_binary.Uint128) *InitializePool { + inst.InitialSqrtPrice = &initialSqrtPrice + return inst +} + +// SetWhirlpoolsConfigAccount sets the "whirlpoolsConfig" account. +func (inst *InitializePool) SetWhirlpoolsConfigAccount(whirlpoolsConfig ag_solanago.PublicKey) *InitializePool { + inst.AccountMetaSlice[0] = ag_solanago.Meta(whirlpoolsConfig) + return inst +} + +// GetWhirlpoolsConfigAccount gets the "whirlpoolsConfig" account. +func (inst *InitializePool) GetWhirlpoolsConfigAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetTokenMintAAccount sets the "tokenMintA" account. +func (inst *InitializePool) SetTokenMintAAccount(tokenMintA ag_solanago.PublicKey) *InitializePool { + inst.AccountMetaSlice[1] = ag_solanago.Meta(tokenMintA) + return inst +} + +// GetTokenMintAAccount gets the "tokenMintA" account. +func (inst *InitializePool) GetTokenMintAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetTokenMintBAccount sets the "tokenMintB" account. +func (inst *InitializePool) SetTokenMintBAccount(tokenMintB ag_solanago.PublicKey) *InitializePool { + inst.AccountMetaSlice[2] = ag_solanago.Meta(tokenMintB) + return inst +} + +// GetTokenMintBAccount gets the "tokenMintB" account. +func (inst *InitializePool) GetTokenMintBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetFunderAccount sets the "funder" account. +func (inst *InitializePool) SetFunderAccount(funder ag_solanago.PublicKey) *InitializePool { + inst.AccountMetaSlice[3] = ag_solanago.Meta(funder).WRITE().SIGNER() + return inst +} + +// GetFunderAccount gets the "funder" account. +func (inst *InitializePool) GetFunderAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetWhirlpoolAccount sets the "whirlpool" account. +func (inst *InitializePool) SetWhirlpoolAccount(whirlpool ag_solanago.PublicKey) *InitializePool { + inst.AccountMetaSlice[4] = ag_solanago.Meta(whirlpool).WRITE() + return inst +} + +// GetWhirlpoolAccount gets the "whirlpool" account. +func (inst *InitializePool) GetWhirlpoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetTokenVaultAAccount sets the "tokenVaultA" account. +func (inst *InitializePool) SetTokenVaultAAccount(tokenVaultA ag_solanago.PublicKey) *InitializePool { + inst.AccountMetaSlice[5] = ag_solanago.Meta(tokenVaultA).WRITE().SIGNER() + return inst +} + +// GetTokenVaultAAccount gets the "tokenVaultA" account. +func (inst *InitializePool) GetTokenVaultAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetTokenVaultBAccount sets the "tokenVaultB" account. +func (inst *InitializePool) SetTokenVaultBAccount(tokenVaultB ag_solanago.PublicKey) *InitializePool { + inst.AccountMetaSlice[6] = ag_solanago.Meta(tokenVaultB).WRITE().SIGNER() + return inst +} + +// GetTokenVaultBAccount gets the "tokenVaultB" account. +func (inst *InitializePool) GetTokenVaultBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetFeeTierAccount sets the "feeTier" account. +func (inst *InitializePool) SetFeeTierAccount(feeTier ag_solanago.PublicKey) *InitializePool { + inst.AccountMetaSlice[7] = ag_solanago.Meta(feeTier) + return inst +} + +// GetFeeTierAccount gets the "feeTier" account. +func (inst *InitializePool) GetFeeTierAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *InitializePool) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *InitializePool { + inst.AccountMetaSlice[8] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *InitializePool) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +func (inst *InitializePool) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *InitializePool { + inst.AccountMetaSlice[9] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +func (inst *InitializePool) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetRentAccount sets the "rent" account. +func (inst *InitializePool) SetRentAccount(rent ag_solanago.PublicKey) *InitializePool { + inst.AccountMetaSlice[10] = ag_solanago.Meta(rent) + return inst +} + +// GetRentAccount gets the "rent" account. +func (inst *InitializePool) GetRentAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +func (inst InitializePool) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_InitializePool, + }} +} + +// 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 InitializePool) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *InitializePool) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.Bumps == nil { + return errors.New("Bumps parameter is not set") + } + if inst.TickSpacing == nil { + return errors.New("TickSpacing parameter is not set") + } + if inst.InitialSqrtPrice == nil { + return errors.New("InitialSqrtPrice parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.WhirlpoolsConfig is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.TokenMintA is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.TokenMintB is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.Funder is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.Whirlpool is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.TokenVaultA is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.TokenVaultB is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.FeeTier is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.SystemProgram is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.Rent is not set") + } + } + return nil +} + +func (inst *InitializePool) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("InitializePool")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=3]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" Bumps", *inst.Bumps)) + paramsBranch.Child(ag_format.Param(" TickSpacing", *inst.TickSpacing)) + paramsBranch.Child(ag_format.Param("InitialSqrtPrice", *inst.InitialSqrtPrice)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=11]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta("whirlpoolsConfig", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" tokenMintA", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" tokenMintB", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" funder", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" whirlpool", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" tokenVaultA", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" tokenVaultB", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" feeTier", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" systemProgram", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" rent", inst.AccountMetaSlice.Get(10))) + }) + }) + }) +} + +func (obj InitializePool) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Bumps` param: + err = encoder.Encode(obj.Bumps) + if err != nil { + return err + } + // Serialize `TickSpacing` param: + err = encoder.Encode(obj.TickSpacing) + if err != nil { + return err + } + // Serialize `InitialSqrtPrice` param: + err = encoder.Encode(obj.InitialSqrtPrice) + if err != nil { + return err + } + return nil +} +func (obj *InitializePool) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Bumps`: + err = decoder.Decode(&obj.Bumps) + if err != nil { + return err + } + // Deserialize `TickSpacing`: + err = decoder.Decode(&obj.TickSpacing) + if err != nil { + return err + } + // Deserialize `InitialSqrtPrice`: + err = decoder.Decode(&obj.InitialSqrtPrice) + if err != nil { + return err + } + return nil +} + +// NewInitializePoolInstruction declares a new InitializePool instruction with the provided parameters and accounts. +func NewInitializePoolInstruction( + // Parameters: + bumps WhirlpoolBumps, + tickSpacing uint16, + initialSqrtPrice ag_binary.Uint128, + // Accounts: + whirlpoolsConfig ag_solanago.PublicKey, + tokenMintA ag_solanago.PublicKey, + tokenMintB ag_solanago.PublicKey, + funder ag_solanago.PublicKey, + whirlpool ag_solanago.PublicKey, + tokenVaultA ag_solanago.PublicKey, + tokenVaultB ag_solanago.PublicKey, + feeTier ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey, + rent ag_solanago.PublicKey) *InitializePool { + return NewInitializePoolInstructionBuilder(). + SetBumps(bumps). + SetTickSpacing(tickSpacing). + SetInitialSqrtPrice(initialSqrtPrice). + SetWhirlpoolsConfigAccount(whirlpoolsConfig). + SetTokenMintAAccount(tokenMintA). + SetTokenMintBAccount(tokenMintB). + SetFunderAccount(funder). + SetWhirlpoolAccount(whirlpool). + SetTokenVaultAAccount(tokenVaultA). + SetTokenVaultBAccount(tokenVaultB). + SetFeeTierAccount(feeTier). + SetTokenProgramAccount(tokenProgram). + SetSystemProgramAccount(systemProgram). + SetRentAccount(rent) +} diff --git a/programs/whirlpool/InitializePool_test.go b/programs/whirlpool/InitializePool_test.go new file mode 100644 index 00000000..339132d0 --- /dev/null +++ b/programs/whirlpool/InitializePool_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_InitializePool(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("InitializePool"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(InitializePool) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(InitializePool) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/InitializePositionBundle.go b/programs/whirlpool/InitializePositionBundle.go new file mode 100644 index 00000000..964f20b2 --- /dev/null +++ b/programs/whirlpool/InitializePositionBundle.go @@ -0,0 +1,250 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "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" +) + +// InitializePositionBundle is the `initializePositionBundle` instruction. +type InitializePositionBundle struct { + + // [0] = [WRITE] positionBundle + // + // [1] = [WRITE, SIGNER] positionBundleMint + // + // [2] = [WRITE] positionBundleTokenAccount + // + // [3] = [] positionBundleOwner + // + // [4] = [WRITE, SIGNER] funder + // + // [5] = [] tokenProgram + // + // [6] = [] systemProgram + // + // [7] = [] rent + // + // [8] = [] associatedTokenProgram + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewInitializePositionBundleInstructionBuilder creates a new `InitializePositionBundle` instruction builder. +func NewInitializePositionBundleInstructionBuilder() *InitializePositionBundle { + nd := &InitializePositionBundle{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 9), + } + return nd +} + +// SetPositionBundleAccount sets the "positionBundle" account. +func (inst *InitializePositionBundle) SetPositionBundleAccount(positionBundle ag_solanago.PublicKey) *InitializePositionBundle { + inst.AccountMetaSlice[0] = ag_solanago.Meta(positionBundle).WRITE() + return inst +} + +// GetPositionBundleAccount gets the "positionBundle" account. +func (inst *InitializePositionBundle) GetPositionBundleAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetPositionBundleMintAccount sets the "positionBundleMint" account. +func (inst *InitializePositionBundle) SetPositionBundleMintAccount(positionBundleMint ag_solanago.PublicKey) *InitializePositionBundle { + inst.AccountMetaSlice[1] = ag_solanago.Meta(positionBundleMint).WRITE().SIGNER() + return inst +} + +// GetPositionBundleMintAccount gets the "positionBundleMint" account. +func (inst *InitializePositionBundle) GetPositionBundleMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetPositionBundleTokenAccountAccount sets the "positionBundleTokenAccount" account. +func (inst *InitializePositionBundle) SetPositionBundleTokenAccountAccount(positionBundleTokenAccount ag_solanago.PublicKey) *InitializePositionBundle { + inst.AccountMetaSlice[2] = ag_solanago.Meta(positionBundleTokenAccount).WRITE() + return inst +} + +// GetPositionBundleTokenAccountAccount gets the "positionBundleTokenAccount" account. +func (inst *InitializePositionBundle) GetPositionBundleTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetPositionBundleOwnerAccount sets the "positionBundleOwner" account. +func (inst *InitializePositionBundle) SetPositionBundleOwnerAccount(positionBundleOwner ag_solanago.PublicKey) *InitializePositionBundle { + inst.AccountMetaSlice[3] = ag_solanago.Meta(positionBundleOwner) + return inst +} + +// GetPositionBundleOwnerAccount gets the "positionBundleOwner" account. +func (inst *InitializePositionBundle) GetPositionBundleOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetFunderAccount sets the "funder" account. +func (inst *InitializePositionBundle) SetFunderAccount(funder ag_solanago.PublicKey) *InitializePositionBundle { + inst.AccountMetaSlice[4] = ag_solanago.Meta(funder).WRITE().SIGNER() + return inst +} + +// GetFunderAccount gets the "funder" account. +func (inst *InitializePositionBundle) GetFunderAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *InitializePositionBundle) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *InitializePositionBundle { + inst.AccountMetaSlice[5] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *InitializePositionBundle) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +func (inst *InitializePositionBundle) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *InitializePositionBundle { + inst.AccountMetaSlice[6] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +func (inst *InitializePositionBundle) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetRentAccount sets the "rent" account. +func (inst *InitializePositionBundle) SetRentAccount(rent ag_solanago.PublicKey) *InitializePositionBundle { + inst.AccountMetaSlice[7] = ag_solanago.Meta(rent) + return inst +} + +// GetRentAccount gets the "rent" account. +func (inst *InitializePositionBundle) GetRentAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetAssociatedTokenProgramAccount sets the "associatedTokenProgram" account. +func (inst *InitializePositionBundle) SetAssociatedTokenProgramAccount(associatedTokenProgram ag_solanago.PublicKey) *InitializePositionBundle { + inst.AccountMetaSlice[8] = ag_solanago.Meta(associatedTokenProgram) + return inst +} + +// GetAssociatedTokenProgramAccount gets the "associatedTokenProgram" account. +func (inst *InitializePositionBundle) GetAssociatedTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +func (inst InitializePositionBundle) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_InitializePositionBundle, + }} +} + +// 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 InitializePositionBundle) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *InitializePositionBundle) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.PositionBundle is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.PositionBundleMint is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.PositionBundleTokenAccount is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.PositionBundleOwner is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.Funder is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.SystemProgram is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.Rent is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.AssociatedTokenProgram is not set") + } + } + return nil +} + +func (inst *InitializePositionBundle) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("InitializePositionBundle")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=9]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" positionBundle", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" positionBundleMint", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" positionBundleToken", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" positionBundleOwner", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" funder", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" systemProgram", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" rent", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta("associatedTokenProgram", inst.AccountMetaSlice.Get(8))) + }) + }) + }) +} + +func (obj InitializePositionBundle) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *InitializePositionBundle) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewInitializePositionBundleInstruction declares a new InitializePositionBundle instruction with the provided parameters and accounts. +func NewInitializePositionBundleInstruction( + // Accounts: + positionBundle ag_solanago.PublicKey, + positionBundleMint ag_solanago.PublicKey, + positionBundleTokenAccount ag_solanago.PublicKey, + positionBundleOwner ag_solanago.PublicKey, + funder ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey, + rent ag_solanago.PublicKey, + associatedTokenProgram ag_solanago.PublicKey) *InitializePositionBundle { + return NewInitializePositionBundleInstructionBuilder(). + SetPositionBundleAccount(positionBundle). + SetPositionBundleMintAccount(positionBundleMint). + SetPositionBundleTokenAccountAccount(positionBundleTokenAccount). + SetPositionBundleOwnerAccount(positionBundleOwner). + SetFunderAccount(funder). + SetTokenProgramAccount(tokenProgram). + SetSystemProgramAccount(systemProgram). + SetRentAccount(rent). + SetAssociatedTokenProgramAccount(associatedTokenProgram) +} diff --git a/programs/whirlpool/InitializePositionBundleWithMetadata.go b/programs/whirlpool/InitializePositionBundleWithMetadata.go new file mode 100644 index 00000000..35b33c8e --- /dev/null +++ b/programs/whirlpool/InitializePositionBundleWithMetadata.go @@ -0,0 +1,307 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "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" +) + +// InitializePositionBundleWithMetadata is the `initializePositionBundleWithMetadata` instruction. +type InitializePositionBundleWithMetadata struct { + + // [0] = [WRITE] positionBundle + // + // [1] = [WRITE, SIGNER] positionBundleMint + // + // [2] = [WRITE] positionBundleMetadata + // + // [3] = [WRITE] positionBundleTokenAccount + // + // [4] = [] positionBundleOwner + // + // [5] = [WRITE, SIGNER] funder + // + // [6] = [] metadataUpdateAuth + // + // [7] = [] tokenProgram + // + // [8] = [] systemProgram + // + // [9] = [] rent + // + // [10] = [] associatedTokenProgram + // + // [11] = [] metadataProgram + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewInitializePositionBundleWithMetadataInstructionBuilder creates a new `InitializePositionBundleWithMetadata` instruction builder. +func NewInitializePositionBundleWithMetadataInstructionBuilder() *InitializePositionBundleWithMetadata { + nd := &InitializePositionBundleWithMetadata{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 12), + } + return nd +} + +// SetPositionBundleAccount sets the "positionBundle" account. +func (inst *InitializePositionBundleWithMetadata) SetPositionBundleAccount(positionBundle ag_solanago.PublicKey) *InitializePositionBundleWithMetadata { + inst.AccountMetaSlice[0] = ag_solanago.Meta(positionBundle).WRITE() + return inst +} + +// GetPositionBundleAccount gets the "positionBundle" account. +func (inst *InitializePositionBundleWithMetadata) GetPositionBundleAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetPositionBundleMintAccount sets the "positionBundleMint" account. +func (inst *InitializePositionBundleWithMetadata) SetPositionBundleMintAccount(positionBundleMint ag_solanago.PublicKey) *InitializePositionBundleWithMetadata { + inst.AccountMetaSlice[1] = ag_solanago.Meta(positionBundleMint).WRITE().SIGNER() + return inst +} + +// GetPositionBundleMintAccount gets the "positionBundleMint" account. +func (inst *InitializePositionBundleWithMetadata) GetPositionBundleMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetPositionBundleMetadataAccount sets the "positionBundleMetadata" account. +func (inst *InitializePositionBundleWithMetadata) SetPositionBundleMetadataAccount(positionBundleMetadata ag_solanago.PublicKey) *InitializePositionBundleWithMetadata { + inst.AccountMetaSlice[2] = ag_solanago.Meta(positionBundleMetadata).WRITE() + return inst +} + +// GetPositionBundleMetadataAccount gets the "positionBundleMetadata" account. +func (inst *InitializePositionBundleWithMetadata) GetPositionBundleMetadataAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetPositionBundleTokenAccountAccount sets the "positionBundleTokenAccount" account. +func (inst *InitializePositionBundleWithMetadata) SetPositionBundleTokenAccountAccount(positionBundleTokenAccount ag_solanago.PublicKey) *InitializePositionBundleWithMetadata { + inst.AccountMetaSlice[3] = ag_solanago.Meta(positionBundleTokenAccount).WRITE() + return inst +} + +// GetPositionBundleTokenAccountAccount gets the "positionBundleTokenAccount" account. +func (inst *InitializePositionBundleWithMetadata) GetPositionBundleTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetPositionBundleOwnerAccount sets the "positionBundleOwner" account. +func (inst *InitializePositionBundleWithMetadata) SetPositionBundleOwnerAccount(positionBundleOwner ag_solanago.PublicKey) *InitializePositionBundleWithMetadata { + inst.AccountMetaSlice[4] = ag_solanago.Meta(positionBundleOwner) + return inst +} + +// GetPositionBundleOwnerAccount gets the "positionBundleOwner" account. +func (inst *InitializePositionBundleWithMetadata) GetPositionBundleOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetFunderAccount sets the "funder" account. +func (inst *InitializePositionBundleWithMetadata) SetFunderAccount(funder ag_solanago.PublicKey) *InitializePositionBundleWithMetadata { + inst.AccountMetaSlice[5] = ag_solanago.Meta(funder).WRITE().SIGNER() + return inst +} + +// GetFunderAccount gets the "funder" account. +func (inst *InitializePositionBundleWithMetadata) GetFunderAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetMetadataUpdateAuthAccount sets the "metadataUpdateAuth" account. +func (inst *InitializePositionBundleWithMetadata) SetMetadataUpdateAuthAccount(metadataUpdateAuth ag_solanago.PublicKey) *InitializePositionBundleWithMetadata { + inst.AccountMetaSlice[6] = ag_solanago.Meta(metadataUpdateAuth) + return inst +} + +// GetMetadataUpdateAuthAccount gets the "metadataUpdateAuth" account. +func (inst *InitializePositionBundleWithMetadata) GetMetadataUpdateAuthAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *InitializePositionBundleWithMetadata) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *InitializePositionBundleWithMetadata { + inst.AccountMetaSlice[7] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *InitializePositionBundleWithMetadata) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +func (inst *InitializePositionBundleWithMetadata) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *InitializePositionBundleWithMetadata { + inst.AccountMetaSlice[8] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +func (inst *InitializePositionBundleWithMetadata) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetRentAccount sets the "rent" account. +func (inst *InitializePositionBundleWithMetadata) SetRentAccount(rent ag_solanago.PublicKey) *InitializePositionBundleWithMetadata { + inst.AccountMetaSlice[9] = ag_solanago.Meta(rent) + return inst +} + +// GetRentAccount gets the "rent" account. +func (inst *InitializePositionBundleWithMetadata) GetRentAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetAssociatedTokenProgramAccount sets the "associatedTokenProgram" account. +func (inst *InitializePositionBundleWithMetadata) SetAssociatedTokenProgramAccount(associatedTokenProgram ag_solanago.PublicKey) *InitializePositionBundleWithMetadata { + inst.AccountMetaSlice[10] = ag_solanago.Meta(associatedTokenProgram) + return inst +} + +// GetAssociatedTokenProgramAccount gets the "associatedTokenProgram" account. +func (inst *InitializePositionBundleWithMetadata) GetAssociatedTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetMetadataProgramAccount sets the "metadataProgram" account. +func (inst *InitializePositionBundleWithMetadata) SetMetadataProgramAccount(metadataProgram ag_solanago.PublicKey) *InitializePositionBundleWithMetadata { + inst.AccountMetaSlice[11] = ag_solanago.Meta(metadataProgram) + return inst +} + +// GetMetadataProgramAccount gets the "metadataProgram" account. +func (inst *InitializePositionBundleWithMetadata) GetMetadataProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +func (inst InitializePositionBundleWithMetadata) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_InitializePositionBundleWithMetadata, + }} +} + +// 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 InitializePositionBundleWithMetadata) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *InitializePositionBundleWithMetadata) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.PositionBundle is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.PositionBundleMint is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.PositionBundleMetadata is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.PositionBundleTokenAccount is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.PositionBundleOwner is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.Funder is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.MetadataUpdateAuth is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.SystemProgram is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.Rent is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.AssociatedTokenProgram is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.MetadataProgram is not set") + } + } + return nil +} + +func (inst *InitializePositionBundleWithMetadata) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("InitializePositionBundleWithMetadata")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=12]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" positionBundle", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" positionBundleMint", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta("positionBundleMetadata", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" positionBundleToken", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" positionBundleOwner", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" funder", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" metadataUpdateAuth", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" systemProgram", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" rent", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta("associatedTokenProgram", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" metadataProgram", inst.AccountMetaSlice.Get(11))) + }) + }) + }) +} + +func (obj InitializePositionBundleWithMetadata) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *InitializePositionBundleWithMetadata) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewInitializePositionBundleWithMetadataInstruction declares a new InitializePositionBundleWithMetadata instruction with the provided parameters and accounts. +func NewInitializePositionBundleWithMetadataInstruction( + // Accounts: + positionBundle ag_solanago.PublicKey, + positionBundleMint ag_solanago.PublicKey, + positionBundleMetadata ag_solanago.PublicKey, + positionBundleTokenAccount ag_solanago.PublicKey, + positionBundleOwner ag_solanago.PublicKey, + funder ag_solanago.PublicKey, + metadataUpdateAuth ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey, + rent ag_solanago.PublicKey, + associatedTokenProgram ag_solanago.PublicKey, + metadataProgram ag_solanago.PublicKey) *InitializePositionBundleWithMetadata { + return NewInitializePositionBundleWithMetadataInstructionBuilder(). + SetPositionBundleAccount(positionBundle). + SetPositionBundleMintAccount(positionBundleMint). + SetPositionBundleMetadataAccount(positionBundleMetadata). + SetPositionBundleTokenAccountAccount(positionBundleTokenAccount). + SetPositionBundleOwnerAccount(positionBundleOwner). + SetFunderAccount(funder). + SetMetadataUpdateAuthAccount(metadataUpdateAuth). + SetTokenProgramAccount(tokenProgram). + SetSystemProgramAccount(systemProgram). + SetRentAccount(rent). + SetAssociatedTokenProgramAccount(associatedTokenProgram). + SetMetadataProgramAccount(metadataProgram) +} diff --git a/programs/whirlpool/InitializePositionBundleWithMetadata_test.go b/programs/whirlpool/InitializePositionBundleWithMetadata_test.go new file mode 100644 index 00000000..4e7bbfae --- /dev/null +++ b/programs/whirlpool/InitializePositionBundleWithMetadata_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_InitializePositionBundleWithMetadata(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("InitializePositionBundleWithMetadata"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(InitializePositionBundleWithMetadata) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(InitializePositionBundleWithMetadata) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/InitializePositionBundle_test.go b/programs/whirlpool/InitializePositionBundle_test.go new file mode 100644 index 00000000..548ab8a2 --- /dev/null +++ b/programs/whirlpool/InitializePositionBundle_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_InitializePositionBundle(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("InitializePositionBundle"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(InitializePositionBundle) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(InitializePositionBundle) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/InitializeReward.go b/programs/whirlpool/InitializeReward.go new file mode 100644 index 00000000..2131cb04 --- /dev/null +++ b/programs/whirlpool/InitializeReward.go @@ -0,0 +1,260 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "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" +) + +// InitializeReward is the `initializeReward` instruction. +type InitializeReward struct { + RewardIndex *uint8 + + // [0] = [SIGNER] rewardAuthority + // + // [1] = [WRITE, SIGNER] funder + // + // [2] = [WRITE] whirlpool + // + // [3] = [] rewardMint + // + // [4] = [WRITE, SIGNER] rewardVault + // + // [5] = [] tokenProgram + // + // [6] = [] systemProgram + // + // [7] = [] rent + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewInitializeRewardInstructionBuilder creates a new `InitializeReward` instruction builder. +func NewInitializeRewardInstructionBuilder() *InitializeReward { + nd := &InitializeReward{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 8), + } + return nd +} + +// SetRewardIndex sets the "rewardIndex" parameter. +func (inst *InitializeReward) SetRewardIndex(rewardIndex uint8) *InitializeReward { + inst.RewardIndex = &rewardIndex + return inst +} + +// SetRewardAuthorityAccount sets the "rewardAuthority" account. +func (inst *InitializeReward) SetRewardAuthorityAccount(rewardAuthority ag_solanago.PublicKey) *InitializeReward { + inst.AccountMetaSlice[0] = ag_solanago.Meta(rewardAuthority).SIGNER() + return inst +} + +// GetRewardAuthorityAccount gets the "rewardAuthority" account. +func (inst *InitializeReward) GetRewardAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetFunderAccount sets the "funder" account. +func (inst *InitializeReward) SetFunderAccount(funder ag_solanago.PublicKey) *InitializeReward { + inst.AccountMetaSlice[1] = ag_solanago.Meta(funder).WRITE().SIGNER() + return inst +} + +// GetFunderAccount gets the "funder" account. +func (inst *InitializeReward) GetFunderAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetWhirlpoolAccount sets the "whirlpool" account. +func (inst *InitializeReward) SetWhirlpoolAccount(whirlpool ag_solanago.PublicKey) *InitializeReward { + inst.AccountMetaSlice[2] = ag_solanago.Meta(whirlpool).WRITE() + return inst +} + +// GetWhirlpoolAccount gets the "whirlpool" account. +func (inst *InitializeReward) GetWhirlpoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetRewardMintAccount sets the "rewardMint" account. +func (inst *InitializeReward) SetRewardMintAccount(rewardMint ag_solanago.PublicKey) *InitializeReward { + inst.AccountMetaSlice[3] = ag_solanago.Meta(rewardMint) + return inst +} + +// GetRewardMintAccount gets the "rewardMint" account. +func (inst *InitializeReward) GetRewardMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetRewardVaultAccount sets the "rewardVault" account. +func (inst *InitializeReward) SetRewardVaultAccount(rewardVault ag_solanago.PublicKey) *InitializeReward { + inst.AccountMetaSlice[4] = ag_solanago.Meta(rewardVault).WRITE().SIGNER() + return inst +} + +// GetRewardVaultAccount gets the "rewardVault" account. +func (inst *InitializeReward) GetRewardVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *InitializeReward) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *InitializeReward { + inst.AccountMetaSlice[5] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *InitializeReward) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +func (inst *InitializeReward) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *InitializeReward { + inst.AccountMetaSlice[6] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +func (inst *InitializeReward) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetRentAccount sets the "rent" account. +func (inst *InitializeReward) SetRentAccount(rent ag_solanago.PublicKey) *InitializeReward { + inst.AccountMetaSlice[7] = ag_solanago.Meta(rent) + return inst +} + +// GetRentAccount gets the "rent" account. +func (inst *InitializeReward) GetRentAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +func (inst InitializeReward) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_InitializeReward, + }} +} + +// 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 InitializeReward) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *InitializeReward) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.RewardIndex == nil { + return errors.New("RewardIndex parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.RewardAuthority is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Funder is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.Whirlpool is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.RewardMint is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.RewardVault is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.SystemProgram is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.Rent is not set") + } + } + return nil +} + +func (inst *InitializeReward) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("InitializeReward")). + // + 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("RewardIndex", *inst.RewardIndex)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=8]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta("rewardAuthority", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" funder", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" whirlpool", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" rewardMint", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" rewardVault", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" systemProgram", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" rent", inst.AccountMetaSlice.Get(7))) + }) + }) + }) +} + +func (obj InitializeReward) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `RewardIndex` param: + err = encoder.Encode(obj.RewardIndex) + if err != nil { + return err + } + return nil +} +func (obj *InitializeReward) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `RewardIndex`: + err = decoder.Decode(&obj.RewardIndex) + if err != nil { + return err + } + return nil +} + +// NewInitializeRewardInstruction declares a new InitializeReward instruction with the provided parameters and accounts. +func NewInitializeRewardInstruction( + // Parameters: + rewardIndex uint8, + // Accounts: + rewardAuthority ag_solanago.PublicKey, + funder ag_solanago.PublicKey, + whirlpool ag_solanago.PublicKey, + rewardMint ag_solanago.PublicKey, + rewardVault ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey, + rent ag_solanago.PublicKey) *InitializeReward { + return NewInitializeRewardInstructionBuilder(). + SetRewardIndex(rewardIndex). + SetRewardAuthorityAccount(rewardAuthority). + SetFunderAccount(funder). + SetWhirlpoolAccount(whirlpool). + SetRewardMintAccount(rewardMint). + SetRewardVaultAccount(rewardVault). + SetTokenProgramAccount(tokenProgram). + SetSystemProgramAccount(systemProgram). + SetRentAccount(rent) +} diff --git a/programs/whirlpool/InitializeReward_test.go b/programs/whirlpool/InitializeReward_test.go new file mode 100644 index 00000000..701e12f5 --- /dev/null +++ b/programs/whirlpool/InitializeReward_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_InitializeReward(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("InitializeReward"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(InitializeReward) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(InitializeReward) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/InitializeTickArray.go b/programs/whirlpool/InitializeTickArray.go new file mode 100644 index 00000000..faa83b78 --- /dev/null +++ b/programs/whirlpool/InitializeTickArray.go @@ -0,0 +1,184 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "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" +) + +// InitializeTickArray is the `initializeTickArray` instruction. +type InitializeTickArray struct { + StartTickIndex *int32 + + // [0] = [] whirlpool + // + // [1] = [WRITE, SIGNER] funder + // + // [2] = [WRITE] tickArray + // + // [3] = [] systemProgram + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewInitializeTickArrayInstructionBuilder creates a new `InitializeTickArray` instruction builder. +func NewInitializeTickArrayInstructionBuilder() *InitializeTickArray { + nd := &InitializeTickArray{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 4), + } + return nd +} + +// SetStartTickIndex sets the "startTickIndex" parameter. +func (inst *InitializeTickArray) SetStartTickIndex(startTickIndex int32) *InitializeTickArray { + inst.StartTickIndex = &startTickIndex + return inst +} + +// SetWhirlpoolAccount sets the "whirlpool" account. +func (inst *InitializeTickArray) SetWhirlpoolAccount(whirlpool ag_solanago.PublicKey) *InitializeTickArray { + inst.AccountMetaSlice[0] = ag_solanago.Meta(whirlpool) + return inst +} + +// GetWhirlpoolAccount gets the "whirlpool" account. +func (inst *InitializeTickArray) GetWhirlpoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetFunderAccount sets the "funder" account. +func (inst *InitializeTickArray) SetFunderAccount(funder ag_solanago.PublicKey) *InitializeTickArray { + inst.AccountMetaSlice[1] = ag_solanago.Meta(funder).WRITE().SIGNER() + return inst +} + +// GetFunderAccount gets the "funder" account. +func (inst *InitializeTickArray) GetFunderAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetTickArrayAccount sets the "tickArray" account. +func (inst *InitializeTickArray) SetTickArrayAccount(tickArray ag_solanago.PublicKey) *InitializeTickArray { + inst.AccountMetaSlice[2] = ag_solanago.Meta(tickArray).WRITE() + return inst +} + +// GetTickArrayAccount gets the "tickArray" account. +func (inst *InitializeTickArray) GetTickArrayAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +func (inst *InitializeTickArray) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *InitializeTickArray { + inst.AccountMetaSlice[3] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +func (inst *InitializeTickArray) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +func (inst InitializeTickArray) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_InitializeTickArray, + }} +} + +// 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 InitializeTickArray) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *InitializeTickArray) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.StartTickIndex == nil { + return errors.New("StartTickIndex parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Whirlpool is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Funder is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.TickArray is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.SystemProgram is not set") + } + } + return nil +} + +func (inst *InitializeTickArray) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("InitializeTickArray")). + // + 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("StartTickIndex", *inst.StartTickIndex)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=4]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" whirlpool", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" funder", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" tickArray", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta("systemProgram", inst.AccountMetaSlice.Get(3))) + }) + }) + }) +} + +func (obj InitializeTickArray) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `StartTickIndex` param: + err = encoder.Encode(obj.StartTickIndex) + if err != nil { + return err + } + return nil +} +func (obj *InitializeTickArray) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `StartTickIndex`: + err = decoder.Decode(&obj.StartTickIndex) + if err != nil { + return err + } + return nil +} + +// NewInitializeTickArrayInstruction declares a new InitializeTickArray instruction with the provided parameters and accounts. +func NewInitializeTickArrayInstruction( + // Parameters: + startTickIndex int32, + // Accounts: + whirlpool ag_solanago.PublicKey, + funder ag_solanago.PublicKey, + tickArray ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey) *InitializeTickArray { + return NewInitializeTickArrayInstructionBuilder(). + SetStartTickIndex(startTickIndex). + SetWhirlpoolAccount(whirlpool). + SetFunderAccount(funder). + SetTickArrayAccount(tickArray). + SetSystemProgramAccount(systemProgram) +} diff --git a/programs/whirlpool/InitializeTickArray_test.go b/programs/whirlpool/InitializeTickArray_test.go new file mode 100644 index 00000000..008b3b4e --- /dev/null +++ b/programs/whirlpool/InitializeTickArray_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_InitializeTickArray(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("InitializeTickArray"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(InitializeTickArray) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(InitializeTickArray) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/OpenBundledPosition.go b/programs/whirlpool/OpenBundledPosition.go new file mode 100644 index 00000000..65b47136 --- /dev/null +++ b/programs/whirlpool/OpenBundledPosition.go @@ -0,0 +1,306 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "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" +) + +// OpenBundledPosition is the `openBundledPosition` instruction. +type OpenBundledPosition struct { + BundleIndex *uint16 + TickLowerIndex *int32 + TickUpperIndex *int32 + + // [0] = [WRITE] bundledPosition + // + // [1] = [WRITE] positionBundle + // + // [2] = [] positionBundleTokenAccount + // + // [3] = [SIGNER] positionBundleAuthority + // + // [4] = [] whirlpool + // + // [5] = [WRITE, SIGNER] funder + // + // [6] = [] systemProgram + // + // [7] = [] rent + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewOpenBundledPositionInstructionBuilder creates a new `OpenBundledPosition` instruction builder. +func NewOpenBundledPositionInstructionBuilder() *OpenBundledPosition { + nd := &OpenBundledPosition{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 8), + } + return nd +} + +// SetBundleIndex sets the "bundleIndex" parameter. +func (inst *OpenBundledPosition) SetBundleIndex(bundleIndex uint16) *OpenBundledPosition { + inst.BundleIndex = &bundleIndex + return inst +} + +// SetTickLowerIndex sets the "tickLowerIndex" parameter. +func (inst *OpenBundledPosition) SetTickLowerIndex(tickLowerIndex int32) *OpenBundledPosition { + inst.TickLowerIndex = &tickLowerIndex + return inst +} + +// SetTickUpperIndex sets the "tickUpperIndex" parameter. +func (inst *OpenBundledPosition) SetTickUpperIndex(tickUpperIndex int32) *OpenBundledPosition { + inst.TickUpperIndex = &tickUpperIndex + return inst +} + +// SetBundledPositionAccount sets the "bundledPosition" account. +func (inst *OpenBundledPosition) SetBundledPositionAccount(bundledPosition ag_solanago.PublicKey) *OpenBundledPosition { + inst.AccountMetaSlice[0] = ag_solanago.Meta(bundledPosition).WRITE() + return inst +} + +// GetBundledPositionAccount gets the "bundledPosition" account. +func (inst *OpenBundledPosition) GetBundledPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetPositionBundleAccount sets the "positionBundle" account. +func (inst *OpenBundledPosition) SetPositionBundleAccount(positionBundle ag_solanago.PublicKey) *OpenBundledPosition { + inst.AccountMetaSlice[1] = ag_solanago.Meta(positionBundle).WRITE() + return inst +} + +// GetPositionBundleAccount gets the "positionBundle" account. +func (inst *OpenBundledPosition) GetPositionBundleAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetPositionBundleTokenAccountAccount sets the "positionBundleTokenAccount" account. +func (inst *OpenBundledPosition) SetPositionBundleTokenAccountAccount(positionBundleTokenAccount ag_solanago.PublicKey) *OpenBundledPosition { + inst.AccountMetaSlice[2] = ag_solanago.Meta(positionBundleTokenAccount) + return inst +} + +// GetPositionBundleTokenAccountAccount gets the "positionBundleTokenAccount" account. +func (inst *OpenBundledPosition) GetPositionBundleTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetPositionBundleAuthorityAccount sets the "positionBundleAuthority" account. +func (inst *OpenBundledPosition) SetPositionBundleAuthorityAccount(positionBundleAuthority ag_solanago.PublicKey) *OpenBundledPosition { + inst.AccountMetaSlice[3] = ag_solanago.Meta(positionBundleAuthority).SIGNER() + return inst +} + +// GetPositionBundleAuthorityAccount gets the "positionBundleAuthority" account. +func (inst *OpenBundledPosition) GetPositionBundleAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetWhirlpoolAccount sets the "whirlpool" account. +func (inst *OpenBundledPosition) SetWhirlpoolAccount(whirlpool ag_solanago.PublicKey) *OpenBundledPosition { + inst.AccountMetaSlice[4] = ag_solanago.Meta(whirlpool) + return inst +} + +// GetWhirlpoolAccount gets the "whirlpool" account. +func (inst *OpenBundledPosition) GetWhirlpoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetFunderAccount sets the "funder" account. +func (inst *OpenBundledPosition) SetFunderAccount(funder ag_solanago.PublicKey) *OpenBundledPosition { + inst.AccountMetaSlice[5] = ag_solanago.Meta(funder).WRITE().SIGNER() + return inst +} + +// GetFunderAccount gets the "funder" account. +func (inst *OpenBundledPosition) GetFunderAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +func (inst *OpenBundledPosition) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *OpenBundledPosition { + inst.AccountMetaSlice[6] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +func (inst *OpenBundledPosition) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetRentAccount sets the "rent" account. +func (inst *OpenBundledPosition) SetRentAccount(rent ag_solanago.PublicKey) *OpenBundledPosition { + inst.AccountMetaSlice[7] = ag_solanago.Meta(rent) + return inst +} + +// GetRentAccount gets the "rent" account. +func (inst *OpenBundledPosition) GetRentAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +func (inst OpenBundledPosition) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_OpenBundledPosition, + }} +} + +// 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 OpenBundledPosition) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *OpenBundledPosition) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.BundleIndex == nil { + return errors.New("BundleIndex parameter is not set") + } + if inst.TickLowerIndex == nil { + return errors.New("TickLowerIndex parameter is not set") + } + if inst.TickUpperIndex == nil { + return errors.New("TickUpperIndex parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.BundledPosition is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.PositionBundle is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.PositionBundleTokenAccount is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.PositionBundleAuthority is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.Whirlpool is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.Funder is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.SystemProgram is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.Rent is not set") + } + } + return nil +} + +func (inst *OpenBundledPosition) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("OpenBundledPosition")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=3]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" BundleIndex", *inst.BundleIndex)) + paramsBranch.Child(ag_format.Param("TickLowerIndex", *inst.TickLowerIndex)) + paramsBranch.Child(ag_format.Param("TickUpperIndex", *inst.TickUpperIndex)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=8]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" bundledPosition", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" positionBundle", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" positionBundleToken", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta("positionBundleAuthority", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" whirlpool", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" funder", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" systemProgram", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" rent", inst.AccountMetaSlice.Get(7))) + }) + }) + }) +} + +func (obj OpenBundledPosition) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `BundleIndex` param: + err = encoder.Encode(obj.BundleIndex) + if err != nil { + return err + } + // Serialize `TickLowerIndex` param: + err = encoder.Encode(obj.TickLowerIndex) + if err != nil { + return err + } + // Serialize `TickUpperIndex` param: + err = encoder.Encode(obj.TickUpperIndex) + if err != nil { + return err + } + return nil +} +func (obj *OpenBundledPosition) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `BundleIndex`: + err = decoder.Decode(&obj.BundleIndex) + if err != nil { + return err + } + // Deserialize `TickLowerIndex`: + err = decoder.Decode(&obj.TickLowerIndex) + if err != nil { + return err + } + // Deserialize `TickUpperIndex`: + err = decoder.Decode(&obj.TickUpperIndex) + if err != nil { + return err + } + return nil +} + +// NewOpenBundledPositionInstruction declares a new OpenBundledPosition instruction with the provided parameters and accounts. +func NewOpenBundledPositionInstruction( + // Parameters: + bundleIndex uint16, + tickLowerIndex int32, + tickUpperIndex int32, + // Accounts: + bundledPosition ag_solanago.PublicKey, + positionBundle ag_solanago.PublicKey, + positionBundleTokenAccount ag_solanago.PublicKey, + positionBundleAuthority ag_solanago.PublicKey, + whirlpool ag_solanago.PublicKey, + funder ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey, + rent ag_solanago.PublicKey) *OpenBundledPosition { + return NewOpenBundledPositionInstructionBuilder(). + SetBundleIndex(bundleIndex). + SetTickLowerIndex(tickLowerIndex). + SetTickUpperIndex(tickUpperIndex). + SetBundledPositionAccount(bundledPosition). + SetPositionBundleAccount(positionBundle). + SetPositionBundleTokenAccountAccount(positionBundleTokenAccount). + SetPositionBundleAuthorityAccount(positionBundleAuthority). + SetWhirlpoolAccount(whirlpool). + SetFunderAccount(funder). + SetSystemProgramAccount(systemProgram). + SetRentAccount(rent) +} diff --git a/programs/whirlpool/OpenBundledPosition_test.go b/programs/whirlpool/OpenBundledPosition_test.go new file mode 100644 index 00000000..2494800b --- /dev/null +++ b/programs/whirlpool/OpenBundledPosition_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_OpenBundledPosition(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("OpenBundledPosition"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(OpenBundledPosition) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(OpenBundledPosition) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/OpenPosition.go b/programs/whirlpool/OpenPosition.go new file mode 100644 index 00000000..114e77a5 --- /dev/null +++ b/programs/whirlpool/OpenPosition.go @@ -0,0 +1,344 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "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" +) + +// OpenPosition is the `openPosition` instruction. +type OpenPosition struct { + Bumps *OpenPositionBumps + TickLowerIndex *int32 + TickUpperIndex *int32 + + // [0] = [WRITE, SIGNER] funder + // + // [1] = [] owner + // + // [2] = [WRITE] position + // + // [3] = [WRITE, SIGNER] positionMint + // + // [4] = [WRITE] positionTokenAccount + // + // [5] = [] whirlpool + // + // [6] = [] tokenProgram + // + // [7] = [] systemProgram + // + // [8] = [] rent + // + // [9] = [] associatedTokenProgram + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewOpenPositionInstructionBuilder creates a new `OpenPosition` instruction builder. +func NewOpenPositionInstructionBuilder() *OpenPosition { + nd := &OpenPosition{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 10), + } + return nd +} + +// SetBumps sets the "bumps" parameter. +func (inst *OpenPosition) SetBumps(bumps OpenPositionBumps) *OpenPosition { + inst.Bumps = &bumps + return inst +} + +// SetTickLowerIndex sets the "tickLowerIndex" parameter. +func (inst *OpenPosition) SetTickLowerIndex(tickLowerIndex int32) *OpenPosition { + inst.TickLowerIndex = &tickLowerIndex + return inst +} + +// SetTickUpperIndex sets the "tickUpperIndex" parameter. +func (inst *OpenPosition) SetTickUpperIndex(tickUpperIndex int32) *OpenPosition { + inst.TickUpperIndex = &tickUpperIndex + return inst +} + +// SetFunderAccount sets the "funder" account. +func (inst *OpenPosition) SetFunderAccount(funder ag_solanago.PublicKey) *OpenPosition { + inst.AccountMetaSlice[0] = ag_solanago.Meta(funder).WRITE().SIGNER() + return inst +} + +// GetFunderAccount gets the "funder" account. +func (inst *OpenPosition) GetFunderAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetOwnerAccount sets the "owner" account. +func (inst *OpenPosition) SetOwnerAccount(owner ag_solanago.PublicKey) *OpenPosition { + inst.AccountMetaSlice[1] = ag_solanago.Meta(owner) + return inst +} + +// GetOwnerAccount gets the "owner" account. +func (inst *OpenPosition) GetOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetPositionAccount sets the "position" account. +func (inst *OpenPosition) SetPositionAccount(position ag_solanago.PublicKey) *OpenPosition { + inst.AccountMetaSlice[2] = ag_solanago.Meta(position).WRITE() + return inst +} + +// GetPositionAccount gets the "position" account. +func (inst *OpenPosition) GetPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetPositionMintAccount sets the "positionMint" account. +func (inst *OpenPosition) SetPositionMintAccount(positionMint ag_solanago.PublicKey) *OpenPosition { + inst.AccountMetaSlice[3] = ag_solanago.Meta(positionMint).WRITE().SIGNER() + return inst +} + +// GetPositionMintAccount gets the "positionMint" account. +func (inst *OpenPosition) GetPositionMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetPositionTokenAccountAccount sets the "positionTokenAccount" account. +func (inst *OpenPosition) SetPositionTokenAccountAccount(positionTokenAccount ag_solanago.PublicKey) *OpenPosition { + inst.AccountMetaSlice[4] = ag_solanago.Meta(positionTokenAccount).WRITE() + return inst +} + +// GetPositionTokenAccountAccount gets the "positionTokenAccount" account. +func (inst *OpenPosition) GetPositionTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetWhirlpoolAccount sets the "whirlpool" account. +func (inst *OpenPosition) SetWhirlpoolAccount(whirlpool ag_solanago.PublicKey) *OpenPosition { + inst.AccountMetaSlice[5] = ag_solanago.Meta(whirlpool) + return inst +} + +// GetWhirlpoolAccount gets the "whirlpool" account. +func (inst *OpenPosition) GetWhirlpoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *OpenPosition) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *OpenPosition { + inst.AccountMetaSlice[6] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *OpenPosition) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +func (inst *OpenPosition) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *OpenPosition { + inst.AccountMetaSlice[7] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +func (inst *OpenPosition) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetRentAccount sets the "rent" account. +func (inst *OpenPosition) SetRentAccount(rent ag_solanago.PublicKey) *OpenPosition { + inst.AccountMetaSlice[8] = ag_solanago.Meta(rent) + return inst +} + +// GetRentAccount gets the "rent" account. +func (inst *OpenPosition) GetRentAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetAssociatedTokenProgramAccount sets the "associatedTokenProgram" account. +func (inst *OpenPosition) SetAssociatedTokenProgramAccount(associatedTokenProgram ag_solanago.PublicKey) *OpenPosition { + inst.AccountMetaSlice[9] = ag_solanago.Meta(associatedTokenProgram) + return inst +} + +// GetAssociatedTokenProgramAccount gets the "associatedTokenProgram" account. +func (inst *OpenPosition) GetAssociatedTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +func (inst OpenPosition) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_OpenPosition, + }} +} + +// 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 OpenPosition) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *OpenPosition) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.Bumps == nil { + return errors.New("Bumps parameter is not set") + } + if inst.TickLowerIndex == nil { + return errors.New("TickLowerIndex parameter is not set") + } + if inst.TickUpperIndex == nil { + return errors.New("TickUpperIndex parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Funder is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Owner is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.Position is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.PositionMint is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.PositionTokenAccount is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.Whirlpool is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.SystemProgram is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.Rent is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.AssociatedTokenProgram is not set") + } + } + return nil +} + +func (inst *OpenPosition) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("OpenPosition")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=3]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" Bumps", *inst.Bumps)) + paramsBranch.Child(ag_format.Param("TickLowerIndex", *inst.TickLowerIndex)) + paramsBranch.Child(ag_format.Param("TickUpperIndex", *inst.TickUpperIndex)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=10]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" funder", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" owner", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" position", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" positionMint", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" positionToken", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" whirlpool", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" systemProgram", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" rent", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta("associatedTokenProgram", inst.AccountMetaSlice.Get(9))) + }) + }) + }) +} + +func (obj OpenPosition) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Bumps` param: + err = encoder.Encode(obj.Bumps) + if err != nil { + return err + } + // Serialize `TickLowerIndex` param: + err = encoder.Encode(obj.TickLowerIndex) + if err != nil { + return err + } + // Serialize `TickUpperIndex` param: + err = encoder.Encode(obj.TickUpperIndex) + if err != nil { + return err + } + return nil +} +func (obj *OpenPosition) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Bumps`: + err = decoder.Decode(&obj.Bumps) + if err != nil { + return err + } + // Deserialize `TickLowerIndex`: + err = decoder.Decode(&obj.TickLowerIndex) + if err != nil { + return err + } + // Deserialize `TickUpperIndex`: + err = decoder.Decode(&obj.TickUpperIndex) + if err != nil { + return err + } + return nil +} + +// NewOpenPositionInstruction declares a new OpenPosition instruction with the provided parameters and accounts. +func NewOpenPositionInstruction( + // Parameters: + bumps OpenPositionBumps, + tickLowerIndex int32, + tickUpperIndex int32, + // Accounts: + funder ag_solanago.PublicKey, + owner ag_solanago.PublicKey, + position ag_solanago.PublicKey, + positionMint ag_solanago.PublicKey, + positionTokenAccount ag_solanago.PublicKey, + whirlpool ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey, + rent ag_solanago.PublicKey, + associatedTokenProgram ag_solanago.PublicKey) *OpenPosition { + return NewOpenPositionInstructionBuilder(). + SetBumps(bumps). + SetTickLowerIndex(tickLowerIndex). + SetTickUpperIndex(tickUpperIndex). + SetFunderAccount(funder). + SetOwnerAccount(owner). + SetPositionAccount(position). + SetPositionMintAccount(positionMint). + SetPositionTokenAccountAccount(positionTokenAccount). + SetWhirlpoolAccount(whirlpool). + SetTokenProgramAccount(tokenProgram). + SetSystemProgramAccount(systemProgram). + SetRentAccount(rent). + SetAssociatedTokenProgramAccount(associatedTokenProgram) +} diff --git a/programs/whirlpool/OpenPositionWithMetadata.go b/programs/whirlpool/OpenPositionWithMetadata.go new file mode 100644 index 00000000..aa744130 --- /dev/null +++ b/programs/whirlpool/OpenPositionWithMetadata.go @@ -0,0 +1,401 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "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" +) + +// OpenPositionWithMetadata is the `openPositionWithMetadata` instruction. +type OpenPositionWithMetadata struct { + Bumps *OpenPositionWithMetadataBumps + TickLowerIndex *int32 + TickUpperIndex *int32 + + // [0] = [WRITE, SIGNER] funder + // + // [1] = [] owner + // + // [2] = [WRITE] position + // + // [3] = [WRITE, SIGNER] positionMint + // + // [4] = [WRITE] positionMetadataAccount + // + // [5] = [WRITE] positionTokenAccount + // + // [6] = [] whirlpool + // + // [7] = [] tokenProgram + // + // [8] = [] systemProgram + // + // [9] = [] rent + // + // [10] = [] associatedTokenProgram + // + // [11] = [] metadataProgram + // + // [12] = [] metadataUpdateAuth + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewOpenPositionWithMetadataInstructionBuilder creates a new `OpenPositionWithMetadata` instruction builder. +func NewOpenPositionWithMetadataInstructionBuilder() *OpenPositionWithMetadata { + nd := &OpenPositionWithMetadata{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 13), + } + return nd +} + +// SetBumps sets the "bumps" parameter. +func (inst *OpenPositionWithMetadata) SetBumps(bumps OpenPositionWithMetadataBumps) *OpenPositionWithMetadata { + inst.Bumps = &bumps + return inst +} + +// SetTickLowerIndex sets the "tickLowerIndex" parameter. +func (inst *OpenPositionWithMetadata) SetTickLowerIndex(tickLowerIndex int32) *OpenPositionWithMetadata { + inst.TickLowerIndex = &tickLowerIndex + return inst +} + +// SetTickUpperIndex sets the "tickUpperIndex" parameter. +func (inst *OpenPositionWithMetadata) SetTickUpperIndex(tickUpperIndex int32) *OpenPositionWithMetadata { + inst.TickUpperIndex = &tickUpperIndex + return inst +} + +// SetFunderAccount sets the "funder" account. +func (inst *OpenPositionWithMetadata) SetFunderAccount(funder ag_solanago.PublicKey) *OpenPositionWithMetadata { + inst.AccountMetaSlice[0] = ag_solanago.Meta(funder).WRITE().SIGNER() + return inst +} + +// GetFunderAccount gets the "funder" account. +func (inst *OpenPositionWithMetadata) GetFunderAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetOwnerAccount sets the "owner" account. +func (inst *OpenPositionWithMetadata) SetOwnerAccount(owner ag_solanago.PublicKey) *OpenPositionWithMetadata { + inst.AccountMetaSlice[1] = ag_solanago.Meta(owner) + return inst +} + +// GetOwnerAccount gets the "owner" account. +func (inst *OpenPositionWithMetadata) GetOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetPositionAccount sets the "position" account. +func (inst *OpenPositionWithMetadata) SetPositionAccount(position ag_solanago.PublicKey) *OpenPositionWithMetadata { + inst.AccountMetaSlice[2] = ag_solanago.Meta(position).WRITE() + return inst +} + +// GetPositionAccount gets the "position" account. +func (inst *OpenPositionWithMetadata) GetPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetPositionMintAccount sets the "positionMint" account. +func (inst *OpenPositionWithMetadata) SetPositionMintAccount(positionMint ag_solanago.PublicKey) *OpenPositionWithMetadata { + inst.AccountMetaSlice[3] = ag_solanago.Meta(positionMint).WRITE().SIGNER() + return inst +} + +// GetPositionMintAccount gets the "positionMint" account. +func (inst *OpenPositionWithMetadata) GetPositionMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetPositionMetadataAccountAccount sets the "positionMetadataAccount" account. +func (inst *OpenPositionWithMetadata) SetPositionMetadataAccountAccount(positionMetadataAccount ag_solanago.PublicKey) *OpenPositionWithMetadata { + inst.AccountMetaSlice[4] = ag_solanago.Meta(positionMetadataAccount).WRITE() + return inst +} + +// GetPositionMetadataAccountAccount gets the "positionMetadataAccount" account. +func (inst *OpenPositionWithMetadata) GetPositionMetadataAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetPositionTokenAccountAccount sets the "positionTokenAccount" account. +func (inst *OpenPositionWithMetadata) SetPositionTokenAccountAccount(positionTokenAccount ag_solanago.PublicKey) *OpenPositionWithMetadata { + inst.AccountMetaSlice[5] = ag_solanago.Meta(positionTokenAccount).WRITE() + return inst +} + +// GetPositionTokenAccountAccount gets the "positionTokenAccount" account. +func (inst *OpenPositionWithMetadata) GetPositionTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetWhirlpoolAccount sets the "whirlpool" account. +func (inst *OpenPositionWithMetadata) SetWhirlpoolAccount(whirlpool ag_solanago.PublicKey) *OpenPositionWithMetadata { + inst.AccountMetaSlice[6] = ag_solanago.Meta(whirlpool) + return inst +} + +// GetWhirlpoolAccount gets the "whirlpool" account. +func (inst *OpenPositionWithMetadata) GetWhirlpoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *OpenPositionWithMetadata) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *OpenPositionWithMetadata { + inst.AccountMetaSlice[7] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *OpenPositionWithMetadata) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +func (inst *OpenPositionWithMetadata) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *OpenPositionWithMetadata { + inst.AccountMetaSlice[8] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +func (inst *OpenPositionWithMetadata) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetRentAccount sets the "rent" account. +func (inst *OpenPositionWithMetadata) SetRentAccount(rent ag_solanago.PublicKey) *OpenPositionWithMetadata { + inst.AccountMetaSlice[9] = ag_solanago.Meta(rent) + return inst +} + +// GetRentAccount gets the "rent" account. +func (inst *OpenPositionWithMetadata) GetRentAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetAssociatedTokenProgramAccount sets the "associatedTokenProgram" account. +func (inst *OpenPositionWithMetadata) SetAssociatedTokenProgramAccount(associatedTokenProgram ag_solanago.PublicKey) *OpenPositionWithMetadata { + inst.AccountMetaSlice[10] = ag_solanago.Meta(associatedTokenProgram) + return inst +} + +// GetAssociatedTokenProgramAccount gets the "associatedTokenProgram" account. +func (inst *OpenPositionWithMetadata) GetAssociatedTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetMetadataProgramAccount sets the "metadataProgram" account. +func (inst *OpenPositionWithMetadata) SetMetadataProgramAccount(metadataProgram ag_solanago.PublicKey) *OpenPositionWithMetadata { + inst.AccountMetaSlice[11] = ag_solanago.Meta(metadataProgram) + return inst +} + +// GetMetadataProgramAccount gets the "metadataProgram" account. +func (inst *OpenPositionWithMetadata) GetMetadataProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetMetadataUpdateAuthAccount sets the "metadataUpdateAuth" account. +func (inst *OpenPositionWithMetadata) SetMetadataUpdateAuthAccount(metadataUpdateAuth ag_solanago.PublicKey) *OpenPositionWithMetadata { + inst.AccountMetaSlice[12] = ag_solanago.Meta(metadataUpdateAuth) + return inst +} + +// GetMetadataUpdateAuthAccount gets the "metadataUpdateAuth" account. +func (inst *OpenPositionWithMetadata) GetMetadataUpdateAuthAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +func (inst OpenPositionWithMetadata) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_OpenPositionWithMetadata, + }} +} + +// 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 OpenPositionWithMetadata) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *OpenPositionWithMetadata) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.Bumps == nil { + return errors.New("Bumps parameter is not set") + } + if inst.TickLowerIndex == nil { + return errors.New("TickLowerIndex parameter is not set") + } + if inst.TickUpperIndex == nil { + return errors.New("TickUpperIndex parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Funder is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Owner is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.Position is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.PositionMint is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.PositionMetadataAccount is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.PositionTokenAccount is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.Whirlpool is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.SystemProgram is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.Rent is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.AssociatedTokenProgram is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.MetadataProgram is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.MetadataUpdateAuth is not set") + } + } + return nil +} + +func (inst *OpenPositionWithMetadata) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("OpenPositionWithMetadata")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=3]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" Bumps", *inst.Bumps)) + paramsBranch.Child(ag_format.Param("TickLowerIndex", *inst.TickLowerIndex)) + paramsBranch.Child(ag_format.Param("TickUpperIndex", *inst.TickUpperIndex)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=13]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" funder", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" owner", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" position", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" positionMint", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" positionMetadata", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" positionToken", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" whirlpool", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" systemProgram", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" rent", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta("associatedTokenProgram", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" metadataProgram", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" metadataUpdateAuth", inst.AccountMetaSlice.Get(12))) + }) + }) + }) +} + +func (obj OpenPositionWithMetadata) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Bumps` param: + err = encoder.Encode(obj.Bumps) + if err != nil { + return err + } + // Serialize `TickLowerIndex` param: + err = encoder.Encode(obj.TickLowerIndex) + if err != nil { + return err + } + // Serialize `TickUpperIndex` param: + err = encoder.Encode(obj.TickUpperIndex) + if err != nil { + return err + } + return nil +} +func (obj *OpenPositionWithMetadata) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Bumps`: + err = decoder.Decode(&obj.Bumps) + if err != nil { + return err + } + // Deserialize `TickLowerIndex`: + err = decoder.Decode(&obj.TickLowerIndex) + if err != nil { + return err + } + // Deserialize `TickUpperIndex`: + err = decoder.Decode(&obj.TickUpperIndex) + if err != nil { + return err + } + return nil +} + +// NewOpenPositionWithMetadataInstruction declares a new OpenPositionWithMetadata instruction with the provided parameters and accounts. +func NewOpenPositionWithMetadataInstruction( + // Parameters: + bumps OpenPositionWithMetadataBumps, + tickLowerIndex int32, + tickUpperIndex int32, + // Accounts: + funder ag_solanago.PublicKey, + owner ag_solanago.PublicKey, + position ag_solanago.PublicKey, + positionMint ag_solanago.PublicKey, + positionMetadataAccount ag_solanago.PublicKey, + positionTokenAccount ag_solanago.PublicKey, + whirlpool ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey, + rent ag_solanago.PublicKey, + associatedTokenProgram ag_solanago.PublicKey, + metadataProgram ag_solanago.PublicKey, + metadataUpdateAuth ag_solanago.PublicKey) *OpenPositionWithMetadata { + return NewOpenPositionWithMetadataInstructionBuilder(). + SetBumps(bumps). + SetTickLowerIndex(tickLowerIndex). + SetTickUpperIndex(tickUpperIndex). + SetFunderAccount(funder). + SetOwnerAccount(owner). + SetPositionAccount(position). + SetPositionMintAccount(positionMint). + SetPositionMetadataAccountAccount(positionMetadataAccount). + SetPositionTokenAccountAccount(positionTokenAccount). + SetWhirlpoolAccount(whirlpool). + SetTokenProgramAccount(tokenProgram). + SetSystemProgramAccount(systemProgram). + SetRentAccount(rent). + SetAssociatedTokenProgramAccount(associatedTokenProgram). + SetMetadataProgramAccount(metadataProgram). + SetMetadataUpdateAuthAccount(metadataUpdateAuth) +} diff --git a/programs/whirlpool/OpenPositionWithMetadata_test.go b/programs/whirlpool/OpenPositionWithMetadata_test.go new file mode 100644 index 00000000..cd638155 --- /dev/null +++ b/programs/whirlpool/OpenPositionWithMetadata_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_OpenPositionWithMetadata(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("OpenPositionWithMetadata"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(OpenPositionWithMetadata) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(OpenPositionWithMetadata) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/OpenPosition_test.go b/programs/whirlpool/OpenPosition_test.go new file mode 100644 index 00000000..f89e9c97 --- /dev/null +++ b/programs/whirlpool/OpenPosition_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_OpenPosition(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("OpenPosition"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(OpenPosition) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(OpenPosition) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/SetCollectProtocolFeesAuthority.go b/programs/whirlpool/SetCollectProtocolFeesAuthority.go new file mode 100644 index 00000000..7f12da6f --- /dev/null +++ b/programs/whirlpool/SetCollectProtocolFeesAuthority.go @@ -0,0 +1,136 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "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" +) + +// SetCollectProtocolFeesAuthority is the `setCollectProtocolFeesAuthority` instruction. +type SetCollectProtocolFeesAuthority struct { + + // [0] = [WRITE] whirlpoolsConfig + // + // [1] = [SIGNER] collectProtocolFeesAuthority + // + // [2] = [] newCollectProtocolFeesAuthority + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewSetCollectProtocolFeesAuthorityInstructionBuilder creates a new `SetCollectProtocolFeesAuthority` instruction builder. +func NewSetCollectProtocolFeesAuthorityInstructionBuilder() *SetCollectProtocolFeesAuthority { + nd := &SetCollectProtocolFeesAuthority{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 3), + } + return nd +} + +// SetWhirlpoolsConfigAccount sets the "whirlpoolsConfig" account. +func (inst *SetCollectProtocolFeesAuthority) SetWhirlpoolsConfigAccount(whirlpoolsConfig ag_solanago.PublicKey) *SetCollectProtocolFeesAuthority { + inst.AccountMetaSlice[0] = ag_solanago.Meta(whirlpoolsConfig).WRITE() + return inst +} + +// GetWhirlpoolsConfigAccount gets the "whirlpoolsConfig" account. +func (inst *SetCollectProtocolFeesAuthority) GetWhirlpoolsConfigAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetCollectProtocolFeesAuthorityAccount sets the "collectProtocolFeesAuthority" account. +func (inst *SetCollectProtocolFeesAuthority) SetCollectProtocolFeesAuthorityAccount(collectProtocolFeesAuthority ag_solanago.PublicKey) *SetCollectProtocolFeesAuthority { + inst.AccountMetaSlice[1] = ag_solanago.Meta(collectProtocolFeesAuthority).SIGNER() + return inst +} + +// GetCollectProtocolFeesAuthorityAccount gets the "collectProtocolFeesAuthority" account. +func (inst *SetCollectProtocolFeesAuthority) GetCollectProtocolFeesAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetNewCollectProtocolFeesAuthorityAccount sets the "newCollectProtocolFeesAuthority" account. +func (inst *SetCollectProtocolFeesAuthority) SetNewCollectProtocolFeesAuthorityAccount(newCollectProtocolFeesAuthority ag_solanago.PublicKey) *SetCollectProtocolFeesAuthority { + inst.AccountMetaSlice[2] = ag_solanago.Meta(newCollectProtocolFeesAuthority) + return inst +} + +// GetNewCollectProtocolFeesAuthorityAccount gets the "newCollectProtocolFeesAuthority" account. +func (inst *SetCollectProtocolFeesAuthority) GetNewCollectProtocolFeesAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +func (inst SetCollectProtocolFeesAuthority) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_SetCollectProtocolFeesAuthority, + }} +} + +// 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 SetCollectProtocolFeesAuthority) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *SetCollectProtocolFeesAuthority) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.WhirlpoolsConfig is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.CollectProtocolFeesAuthority is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.NewCollectProtocolFeesAuthority is not set") + } + } + return nil +} + +func (inst *SetCollectProtocolFeesAuthority) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("SetCollectProtocolFeesAuthority")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=3]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" whirlpoolsConfig", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" collectProtocolFeesAuthority", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta("newCollectProtocolFeesAuthority", inst.AccountMetaSlice.Get(2))) + }) + }) + }) +} + +func (obj SetCollectProtocolFeesAuthority) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *SetCollectProtocolFeesAuthority) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewSetCollectProtocolFeesAuthorityInstruction declares a new SetCollectProtocolFeesAuthority instruction with the provided parameters and accounts. +func NewSetCollectProtocolFeesAuthorityInstruction( + // Accounts: + whirlpoolsConfig ag_solanago.PublicKey, + collectProtocolFeesAuthority ag_solanago.PublicKey, + newCollectProtocolFeesAuthority ag_solanago.PublicKey) *SetCollectProtocolFeesAuthority { + return NewSetCollectProtocolFeesAuthorityInstructionBuilder(). + SetWhirlpoolsConfigAccount(whirlpoolsConfig). + SetCollectProtocolFeesAuthorityAccount(collectProtocolFeesAuthority). + SetNewCollectProtocolFeesAuthorityAccount(newCollectProtocolFeesAuthority) +} diff --git a/programs/whirlpool/SetCollectProtocolFeesAuthority_test.go b/programs/whirlpool/SetCollectProtocolFeesAuthority_test.go new file mode 100644 index 00000000..5c03e519 --- /dev/null +++ b/programs/whirlpool/SetCollectProtocolFeesAuthority_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_SetCollectProtocolFeesAuthority(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("SetCollectProtocolFeesAuthority"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(SetCollectProtocolFeesAuthority) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(SetCollectProtocolFeesAuthority) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/SetDefaultFeeRate.go b/programs/whirlpool/SetDefaultFeeRate.go new file mode 100644 index 00000000..a9790aaf --- /dev/null +++ b/programs/whirlpool/SetDefaultFeeRate.go @@ -0,0 +1,165 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "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" +) + +// SetDefaultFeeRate is the `setDefaultFeeRate` instruction. +type SetDefaultFeeRate struct { + DefaultFeeRate *uint16 + + // [0] = [] whirlpoolsConfig + // + // [1] = [WRITE] feeTier + // + // [2] = [SIGNER] feeAuthority + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewSetDefaultFeeRateInstructionBuilder creates a new `SetDefaultFeeRate` instruction builder. +func NewSetDefaultFeeRateInstructionBuilder() *SetDefaultFeeRate { + nd := &SetDefaultFeeRate{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 3), + } + return nd +} + +// SetDefaultFeeRate sets the "defaultFeeRate" parameter. +func (inst *SetDefaultFeeRate) SetDefaultFeeRate(defaultFeeRate uint16) *SetDefaultFeeRate { + inst.DefaultFeeRate = &defaultFeeRate + return inst +} + +// SetWhirlpoolsConfigAccount sets the "whirlpoolsConfig" account. +func (inst *SetDefaultFeeRate) SetWhirlpoolsConfigAccount(whirlpoolsConfig ag_solanago.PublicKey) *SetDefaultFeeRate { + inst.AccountMetaSlice[0] = ag_solanago.Meta(whirlpoolsConfig) + return inst +} + +// GetWhirlpoolsConfigAccount gets the "whirlpoolsConfig" account. +func (inst *SetDefaultFeeRate) GetWhirlpoolsConfigAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetFeeTierAccount sets the "feeTier" account. +func (inst *SetDefaultFeeRate) SetFeeTierAccount(feeTier ag_solanago.PublicKey) *SetDefaultFeeRate { + inst.AccountMetaSlice[1] = ag_solanago.Meta(feeTier).WRITE() + return inst +} + +// GetFeeTierAccount gets the "feeTier" account. +func (inst *SetDefaultFeeRate) GetFeeTierAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetFeeAuthorityAccount sets the "feeAuthority" account. +func (inst *SetDefaultFeeRate) SetFeeAuthorityAccount(feeAuthority ag_solanago.PublicKey) *SetDefaultFeeRate { + inst.AccountMetaSlice[2] = ag_solanago.Meta(feeAuthority).SIGNER() + return inst +} + +// GetFeeAuthorityAccount gets the "feeAuthority" account. +func (inst *SetDefaultFeeRate) GetFeeAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +func (inst SetDefaultFeeRate) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_SetDefaultFeeRate, + }} +} + +// 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 SetDefaultFeeRate) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *SetDefaultFeeRate) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.DefaultFeeRate == nil { + return errors.New("DefaultFeeRate parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.WhirlpoolsConfig is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.FeeTier is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.FeeAuthority is not set") + } + } + return nil +} + +func (inst *SetDefaultFeeRate) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("SetDefaultFeeRate")). + // + 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("DefaultFeeRate", *inst.DefaultFeeRate)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=3]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta("whirlpoolsConfig", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" feeTier", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" feeAuthority", inst.AccountMetaSlice.Get(2))) + }) + }) + }) +} + +func (obj SetDefaultFeeRate) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `DefaultFeeRate` param: + err = encoder.Encode(obj.DefaultFeeRate) + if err != nil { + return err + } + return nil +} +func (obj *SetDefaultFeeRate) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `DefaultFeeRate`: + err = decoder.Decode(&obj.DefaultFeeRate) + if err != nil { + return err + } + return nil +} + +// NewSetDefaultFeeRateInstruction declares a new SetDefaultFeeRate instruction with the provided parameters and accounts. +func NewSetDefaultFeeRateInstruction( + // Parameters: + defaultFeeRate uint16, + // Accounts: + whirlpoolsConfig ag_solanago.PublicKey, + feeTier ag_solanago.PublicKey, + feeAuthority ag_solanago.PublicKey) *SetDefaultFeeRate { + return NewSetDefaultFeeRateInstructionBuilder(). + SetDefaultFeeRate(defaultFeeRate). + SetWhirlpoolsConfigAccount(whirlpoolsConfig). + SetFeeTierAccount(feeTier). + SetFeeAuthorityAccount(feeAuthority) +} diff --git a/programs/whirlpool/SetDefaultFeeRate_test.go b/programs/whirlpool/SetDefaultFeeRate_test.go new file mode 100644 index 00000000..b636bdc4 --- /dev/null +++ b/programs/whirlpool/SetDefaultFeeRate_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_SetDefaultFeeRate(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("SetDefaultFeeRate"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(SetDefaultFeeRate) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(SetDefaultFeeRate) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/SetDefaultProtocolFeeRate.go b/programs/whirlpool/SetDefaultProtocolFeeRate.go new file mode 100644 index 00000000..8af69b67 --- /dev/null +++ b/programs/whirlpool/SetDefaultProtocolFeeRate.go @@ -0,0 +1,146 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "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" +) + +// SetDefaultProtocolFeeRate is the `setDefaultProtocolFeeRate` instruction. +type SetDefaultProtocolFeeRate struct { + DefaultProtocolFeeRate *uint16 + + // [0] = [WRITE] whirlpoolsConfig + // + // [1] = [SIGNER] feeAuthority + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewSetDefaultProtocolFeeRateInstructionBuilder creates a new `SetDefaultProtocolFeeRate` instruction builder. +func NewSetDefaultProtocolFeeRateInstructionBuilder() *SetDefaultProtocolFeeRate { + nd := &SetDefaultProtocolFeeRate{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 2), + } + return nd +} + +// SetDefaultProtocolFeeRate sets the "defaultProtocolFeeRate" parameter. +func (inst *SetDefaultProtocolFeeRate) SetDefaultProtocolFeeRate(defaultProtocolFeeRate uint16) *SetDefaultProtocolFeeRate { + inst.DefaultProtocolFeeRate = &defaultProtocolFeeRate + return inst +} + +// SetWhirlpoolsConfigAccount sets the "whirlpoolsConfig" account. +func (inst *SetDefaultProtocolFeeRate) SetWhirlpoolsConfigAccount(whirlpoolsConfig ag_solanago.PublicKey) *SetDefaultProtocolFeeRate { + inst.AccountMetaSlice[0] = ag_solanago.Meta(whirlpoolsConfig).WRITE() + return inst +} + +// GetWhirlpoolsConfigAccount gets the "whirlpoolsConfig" account. +func (inst *SetDefaultProtocolFeeRate) GetWhirlpoolsConfigAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetFeeAuthorityAccount sets the "feeAuthority" account. +func (inst *SetDefaultProtocolFeeRate) SetFeeAuthorityAccount(feeAuthority ag_solanago.PublicKey) *SetDefaultProtocolFeeRate { + inst.AccountMetaSlice[1] = ag_solanago.Meta(feeAuthority).SIGNER() + return inst +} + +// GetFeeAuthorityAccount gets the "feeAuthority" account. +func (inst *SetDefaultProtocolFeeRate) GetFeeAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +func (inst SetDefaultProtocolFeeRate) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_SetDefaultProtocolFeeRate, + }} +} + +// 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 SetDefaultProtocolFeeRate) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *SetDefaultProtocolFeeRate) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.DefaultProtocolFeeRate == nil { + return errors.New("DefaultProtocolFeeRate parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.WhirlpoolsConfig is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.FeeAuthority is not set") + } + } + return nil +} + +func (inst *SetDefaultProtocolFeeRate) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("SetDefaultProtocolFeeRate")). + // + 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("DefaultProtocolFeeRate", *inst.DefaultProtocolFeeRate)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=2]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta("whirlpoolsConfig", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" feeAuthority", inst.AccountMetaSlice.Get(1))) + }) + }) + }) +} + +func (obj SetDefaultProtocolFeeRate) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `DefaultProtocolFeeRate` param: + err = encoder.Encode(obj.DefaultProtocolFeeRate) + if err != nil { + return err + } + return nil +} +func (obj *SetDefaultProtocolFeeRate) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `DefaultProtocolFeeRate`: + err = decoder.Decode(&obj.DefaultProtocolFeeRate) + if err != nil { + return err + } + return nil +} + +// NewSetDefaultProtocolFeeRateInstruction declares a new SetDefaultProtocolFeeRate instruction with the provided parameters and accounts. +func NewSetDefaultProtocolFeeRateInstruction( + // Parameters: + defaultProtocolFeeRate uint16, + // Accounts: + whirlpoolsConfig ag_solanago.PublicKey, + feeAuthority ag_solanago.PublicKey) *SetDefaultProtocolFeeRate { + return NewSetDefaultProtocolFeeRateInstructionBuilder(). + SetDefaultProtocolFeeRate(defaultProtocolFeeRate). + SetWhirlpoolsConfigAccount(whirlpoolsConfig). + SetFeeAuthorityAccount(feeAuthority) +} diff --git a/programs/whirlpool/SetDefaultProtocolFeeRate_test.go b/programs/whirlpool/SetDefaultProtocolFeeRate_test.go new file mode 100644 index 00000000..37a028a3 --- /dev/null +++ b/programs/whirlpool/SetDefaultProtocolFeeRate_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_SetDefaultProtocolFeeRate(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("SetDefaultProtocolFeeRate"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(SetDefaultProtocolFeeRate) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(SetDefaultProtocolFeeRate) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/SetFeeAuthority.go b/programs/whirlpool/SetFeeAuthority.go new file mode 100644 index 00000000..23020f11 --- /dev/null +++ b/programs/whirlpool/SetFeeAuthority.go @@ -0,0 +1,136 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "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" +) + +// SetFeeAuthority is the `setFeeAuthority` instruction. +type SetFeeAuthority struct { + + // [0] = [WRITE] whirlpoolsConfig + // + // [1] = [SIGNER] feeAuthority + // + // [2] = [] newFeeAuthority + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewSetFeeAuthorityInstructionBuilder creates a new `SetFeeAuthority` instruction builder. +func NewSetFeeAuthorityInstructionBuilder() *SetFeeAuthority { + nd := &SetFeeAuthority{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 3), + } + return nd +} + +// SetWhirlpoolsConfigAccount sets the "whirlpoolsConfig" account. +func (inst *SetFeeAuthority) SetWhirlpoolsConfigAccount(whirlpoolsConfig ag_solanago.PublicKey) *SetFeeAuthority { + inst.AccountMetaSlice[0] = ag_solanago.Meta(whirlpoolsConfig).WRITE() + return inst +} + +// GetWhirlpoolsConfigAccount gets the "whirlpoolsConfig" account. +func (inst *SetFeeAuthority) GetWhirlpoolsConfigAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetFeeAuthorityAccount sets the "feeAuthority" account. +func (inst *SetFeeAuthority) SetFeeAuthorityAccount(feeAuthority ag_solanago.PublicKey) *SetFeeAuthority { + inst.AccountMetaSlice[1] = ag_solanago.Meta(feeAuthority).SIGNER() + return inst +} + +// GetFeeAuthorityAccount gets the "feeAuthority" account. +func (inst *SetFeeAuthority) GetFeeAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetNewFeeAuthorityAccount sets the "newFeeAuthority" account. +func (inst *SetFeeAuthority) SetNewFeeAuthorityAccount(newFeeAuthority ag_solanago.PublicKey) *SetFeeAuthority { + inst.AccountMetaSlice[2] = ag_solanago.Meta(newFeeAuthority) + return inst +} + +// GetNewFeeAuthorityAccount gets the "newFeeAuthority" account. +func (inst *SetFeeAuthority) GetNewFeeAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +func (inst SetFeeAuthority) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_SetFeeAuthority, + }} +} + +// 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 SetFeeAuthority) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *SetFeeAuthority) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.WhirlpoolsConfig is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.FeeAuthority is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.NewFeeAuthority is not set") + } + } + return nil +} + +func (inst *SetFeeAuthority) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("SetFeeAuthority")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=3]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta("whirlpoolsConfig", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" feeAuthority", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" newFeeAuthority", inst.AccountMetaSlice.Get(2))) + }) + }) + }) +} + +func (obj SetFeeAuthority) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *SetFeeAuthority) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewSetFeeAuthorityInstruction declares a new SetFeeAuthority instruction with the provided parameters and accounts. +func NewSetFeeAuthorityInstruction( + // Accounts: + whirlpoolsConfig ag_solanago.PublicKey, + feeAuthority ag_solanago.PublicKey, + newFeeAuthority ag_solanago.PublicKey) *SetFeeAuthority { + return NewSetFeeAuthorityInstructionBuilder(). + SetWhirlpoolsConfigAccount(whirlpoolsConfig). + SetFeeAuthorityAccount(feeAuthority). + SetNewFeeAuthorityAccount(newFeeAuthority) +} diff --git a/programs/whirlpool/SetFeeAuthority_test.go b/programs/whirlpool/SetFeeAuthority_test.go new file mode 100644 index 00000000..c3382a2a --- /dev/null +++ b/programs/whirlpool/SetFeeAuthority_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_SetFeeAuthority(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("SetFeeAuthority"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(SetFeeAuthority) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(SetFeeAuthority) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/SetFeeRate.go b/programs/whirlpool/SetFeeRate.go new file mode 100644 index 00000000..222f49fe --- /dev/null +++ b/programs/whirlpool/SetFeeRate.go @@ -0,0 +1,165 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "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" +) + +// SetFeeRate is the `setFeeRate` instruction. +type SetFeeRate struct { + FeeRate *uint16 + + // [0] = [] whirlpoolsConfig + // + // [1] = [WRITE] whirlpool + // + // [2] = [SIGNER] feeAuthority + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewSetFeeRateInstructionBuilder creates a new `SetFeeRate` instruction builder. +func NewSetFeeRateInstructionBuilder() *SetFeeRate { + nd := &SetFeeRate{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 3), + } + return nd +} + +// SetFeeRate sets the "feeRate" parameter. +func (inst *SetFeeRate) SetFeeRate(feeRate uint16) *SetFeeRate { + inst.FeeRate = &feeRate + return inst +} + +// SetWhirlpoolsConfigAccount sets the "whirlpoolsConfig" account. +func (inst *SetFeeRate) SetWhirlpoolsConfigAccount(whirlpoolsConfig ag_solanago.PublicKey) *SetFeeRate { + inst.AccountMetaSlice[0] = ag_solanago.Meta(whirlpoolsConfig) + return inst +} + +// GetWhirlpoolsConfigAccount gets the "whirlpoolsConfig" account. +func (inst *SetFeeRate) GetWhirlpoolsConfigAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetWhirlpoolAccount sets the "whirlpool" account. +func (inst *SetFeeRate) SetWhirlpoolAccount(whirlpool ag_solanago.PublicKey) *SetFeeRate { + inst.AccountMetaSlice[1] = ag_solanago.Meta(whirlpool).WRITE() + return inst +} + +// GetWhirlpoolAccount gets the "whirlpool" account. +func (inst *SetFeeRate) GetWhirlpoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetFeeAuthorityAccount sets the "feeAuthority" account. +func (inst *SetFeeRate) SetFeeAuthorityAccount(feeAuthority ag_solanago.PublicKey) *SetFeeRate { + inst.AccountMetaSlice[2] = ag_solanago.Meta(feeAuthority).SIGNER() + return inst +} + +// GetFeeAuthorityAccount gets the "feeAuthority" account. +func (inst *SetFeeRate) GetFeeAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +func (inst SetFeeRate) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_SetFeeRate, + }} +} + +// 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 SetFeeRate) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *SetFeeRate) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.FeeRate == nil { + return errors.New("FeeRate parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.WhirlpoolsConfig is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Whirlpool is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.FeeAuthority is not set") + } + } + return nil +} + +func (inst *SetFeeRate) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("SetFeeRate")). + // + 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("FeeRate", *inst.FeeRate)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=3]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta("whirlpoolsConfig", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" whirlpool", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" feeAuthority", inst.AccountMetaSlice.Get(2))) + }) + }) + }) +} + +func (obj SetFeeRate) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `FeeRate` param: + err = encoder.Encode(obj.FeeRate) + if err != nil { + return err + } + return nil +} +func (obj *SetFeeRate) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `FeeRate`: + err = decoder.Decode(&obj.FeeRate) + if err != nil { + return err + } + return nil +} + +// NewSetFeeRateInstruction declares a new SetFeeRate instruction with the provided parameters and accounts. +func NewSetFeeRateInstruction( + // Parameters: + feeRate uint16, + // Accounts: + whirlpoolsConfig ag_solanago.PublicKey, + whirlpool ag_solanago.PublicKey, + feeAuthority ag_solanago.PublicKey) *SetFeeRate { + return NewSetFeeRateInstructionBuilder(). + SetFeeRate(feeRate). + SetWhirlpoolsConfigAccount(whirlpoolsConfig). + SetWhirlpoolAccount(whirlpool). + SetFeeAuthorityAccount(feeAuthority) +} diff --git a/programs/whirlpool/SetFeeRate_test.go b/programs/whirlpool/SetFeeRate_test.go new file mode 100644 index 00000000..ffb722d1 --- /dev/null +++ b/programs/whirlpool/SetFeeRate_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_SetFeeRate(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("SetFeeRate"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(SetFeeRate) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(SetFeeRate) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/SetProtocolFeeRate.go b/programs/whirlpool/SetProtocolFeeRate.go new file mode 100644 index 00000000..ec97bf0d --- /dev/null +++ b/programs/whirlpool/SetProtocolFeeRate.go @@ -0,0 +1,165 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "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" +) + +// SetProtocolFeeRate is the `setProtocolFeeRate` instruction. +type SetProtocolFeeRate struct { + ProtocolFeeRate *uint16 + + // [0] = [] whirlpoolsConfig + // + // [1] = [WRITE] whirlpool + // + // [2] = [SIGNER] feeAuthority + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewSetProtocolFeeRateInstructionBuilder creates a new `SetProtocolFeeRate` instruction builder. +func NewSetProtocolFeeRateInstructionBuilder() *SetProtocolFeeRate { + nd := &SetProtocolFeeRate{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 3), + } + return nd +} + +// SetProtocolFeeRate sets the "protocolFeeRate" parameter. +func (inst *SetProtocolFeeRate) SetProtocolFeeRate(protocolFeeRate uint16) *SetProtocolFeeRate { + inst.ProtocolFeeRate = &protocolFeeRate + return inst +} + +// SetWhirlpoolsConfigAccount sets the "whirlpoolsConfig" account. +func (inst *SetProtocolFeeRate) SetWhirlpoolsConfigAccount(whirlpoolsConfig ag_solanago.PublicKey) *SetProtocolFeeRate { + inst.AccountMetaSlice[0] = ag_solanago.Meta(whirlpoolsConfig) + return inst +} + +// GetWhirlpoolsConfigAccount gets the "whirlpoolsConfig" account. +func (inst *SetProtocolFeeRate) GetWhirlpoolsConfigAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetWhirlpoolAccount sets the "whirlpool" account. +func (inst *SetProtocolFeeRate) SetWhirlpoolAccount(whirlpool ag_solanago.PublicKey) *SetProtocolFeeRate { + inst.AccountMetaSlice[1] = ag_solanago.Meta(whirlpool).WRITE() + return inst +} + +// GetWhirlpoolAccount gets the "whirlpool" account. +func (inst *SetProtocolFeeRate) GetWhirlpoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetFeeAuthorityAccount sets the "feeAuthority" account. +func (inst *SetProtocolFeeRate) SetFeeAuthorityAccount(feeAuthority ag_solanago.PublicKey) *SetProtocolFeeRate { + inst.AccountMetaSlice[2] = ag_solanago.Meta(feeAuthority).SIGNER() + return inst +} + +// GetFeeAuthorityAccount gets the "feeAuthority" account. +func (inst *SetProtocolFeeRate) GetFeeAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +func (inst SetProtocolFeeRate) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_SetProtocolFeeRate, + }} +} + +// 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 SetProtocolFeeRate) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *SetProtocolFeeRate) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.ProtocolFeeRate == nil { + return errors.New("ProtocolFeeRate parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.WhirlpoolsConfig is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Whirlpool is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.FeeAuthority is not set") + } + } + return nil +} + +func (inst *SetProtocolFeeRate) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("SetProtocolFeeRate")). + // + 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("ProtocolFeeRate", *inst.ProtocolFeeRate)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=3]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta("whirlpoolsConfig", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" whirlpool", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" feeAuthority", inst.AccountMetaSlice.Get(2))) + }) + }) + }) +} + +func (obj SetProtocolFeeRate) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `ProtocolFeeRate` param: + err = encoder.Encode(obj.ProtocolFeeRate) + if err != nil { + return err + } + return nil +} +func (obj *SetProtocolFeeRate) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `ProtocolFeeRate`: + err = decoder.Decode(&obj.ProtocolFeeRate) + if err != nil { + return err + } + return nil +} + +// NewSetProtocolFeeRateInstruction declares a new SetProtocolFeeRate instruction with the provided parameters and accounts. +func NewSetProtocolFeeRateInstruction( + // Parameters: + protocolFeeRate uint16, + // Accounts: + whirlpoolsConfig ag_solanago.PublicKey, + whirlpool ag_solanago.PublicKey, + feeAuthority ag_solanago.PublicKey) *SetProtocolFeeRate { + return NewSetProtocolFeeRateInstructionBuilder(). + SetProtocolFeeRate(protocolFeeRate). + SetWhirlpoolsConfigAccount(whirlpoolsConfig). + SetWhirlpoolAccount(whirlpool). + SetFeeAuthorityAccount(feeAuthority) +} diff --git a/programs/whirlpool/SetProtocolFeeRate_test.go b/programs/whirlpool/SetProtocolFeeRate_test.go new file mode 100644 index 00000000..9023c3ae --- /dev/null +++ b/programs/whirlpool/SetProtocolFeeRate_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_SetProtocolFeeRate(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("SetProtocolFeeRate"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(SetProtocolFeeRate) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(SetProtocolFeeRate) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/SetRewardAuthority.go b/programs/whirlpool/SetRewardAuthority.go new file mode 100644 index 00000000..f39b4271 --- /dev/null +++ b/programs/whirlpool/SetRewardAuthority.go @@ -0,0 +1,165 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "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" +) + +// SetRewardAuthority is the `setRewardAuthority` instruction. +type SetRewardAuthority struct { + RewardIndex *uint8 + + // [0] = [WRITE] whirlpool + // + // [1] = [SIGNER] rewardAuthority + // + // [2] = [] newRewardAuthority + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewSetRewardAuthorityInstructionBuilder creates a new `SetRewardAuthority` instruction builder. +func NewSetRewardAuthorityInstructionBuilder() *SetRewardAuthority { + nd := &SetRewardAuthority{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 3), + } + return nd +} + +// SetRewardIndex sets the "rewardIndex" parameter. +func (inst *SetRewardAuthority) SetRewardIndex(rewardIndex uint8) *SetRewardAuthority { + inst.RewardIndex = &rewardIndex + return inst +} + +// SetWhirlpoolAccount sets the "whirlpool" account. +func (inst *SetRewardAuthority) SetWhirlpoolAccount(whirlpool ag_solanago.PublicKey) *SetRewardAuthority { + inst.AccountMetaSlice[0] = ag_solanago.Meta(whirlpool).WRITE() + return inst +} + +// GetWhirlpoolAccount gets the "whirlpool" account. +func (inst *SetRewardAuthority) GetWhirlpoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetRewardAuthorityAccount sets the "rewardAuthority" account. +func (inst *SetRewardAuthority) SetRewardAuthorityAccount(rewardAuthority ag_solanago.PublicKey) *SetRewardAuthority { + inst.AccountMetaSlice[1] = ag_solanago.Meta(rewardAuthority).SIGNER() + return inst +} + +// GetRewardAuthorityAccount gets the "rewardAuthority" account. +func (inst *SetRewardAuthority) GetRewardAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetNewRewardAuthorityAccount sets the "newRewardAuthority" account. +func (inst *SetRewardAuthority) SetNewRewardAuthorityAccount(newRewardAuthority ag_solanago.PublicKey) *SetRewardAuthority { + inst.AccountMetaSlice[2] = ag_solanago.Meta(newRewardAuthority) + return inst +} + +// GetNewRewardAuthorityAccount gets the "newRewardAuthority" account. +func (inst *SetRewardAuthority) GetNewRewardAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +func (inst SetRewardAuthority) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_SetRewardAuthority, + }} +} + +// 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 SetRewardAuthority) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *SetRewardAuthority) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.RewardIndex == nil { + return errors.New("RewardIndex parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Whirlpool is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.RewardAuthority is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.NewRewardAuthority is not set") + } + } + return nil +} + +func (inst *SetRewardAuthority) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("SetRewardAuthority")). + // + 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("RewardIndex", *inst.RewardIndex)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=3]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" whirlpool", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" rewardAuthority", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta("newRewardAuthority", inst.AccountMetaSlice.Get(2))) + }) + }) + }) +} + +func (obj SetRewardAuthority) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `RewardIndex` param: + err = encoder.Encode(obj.RewardIndex) + if err != nil { + return err + } + return nil +} +func (obj *SetRewardAuthority) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `RewardIndex`: + err = decoder.Decode(&obj.RewardIndex) + if err != nil { + return err + } + return nil +} + +// NewSetRewardAuthorityInstruction declares a new SetRewardAuthority instruction with the provided parameters and accounts. +func NewSetRewardAuthorityInstruction( + // Parameters: + rewardIndex uint8, + // Accounts: + whirlpool ag_solanago.PublicKey, + rewardAuthority ag_solanago.PublicKey, + newRewardAuthority ag_solanago.PublicKey) *SetRewardAuthority { + return NewSetRewardAuthorityInstructionBuilder(). + SetRewardIndex(rewardIndex). + SetWhirlpoolAccount(whirlpool). + SetRewardAuthorityAccount(rewardAuthority). + SetNewRewardAuthorityAccount(newRewardAuthority) +} diff --git a/programs/whirlpool/SetRewardAuthorityBySuperAuthority.go b/programs/whirlpool/SetRewardAuthorityBySuperAuthority.go new file mode 100644 index 00000000..c321efd7 --- /dev/null +++ b/programs/whirlpool/SetRewardAuthorityBySuperAuthority.go @@ -0,0 +1,184 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "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" +) + +// SetRewardAuthorityBySuperAuthority is the `setRewardAuthorityBySuperAuthority` instruction. +type SetRewardAuthorityBySuperAuthority struct { + RewardIndex *uint8 + + // [0] = [] whirlpoolsConfig + // + // [1] = [WRITE] whirlpool + // + // [2] = [SIGNER] rewardEmissionsSuperAuthority + // + // [3] = [] newRewardAuthority + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewSetRewardAuthorityBySuperAuthorityInstructionBuilder creates a new `SetRewardAuthorityBySuperAuthority` instruction builder. +func NewSetRewardAuthorityBySuperAuthorityInstructionBuilder() *SetRewardAuthorityBySuperAuthority { + nd := &SetRewardAuthorityBySuperAuthority{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 4), + } + return nd +} + +// SetRewardIndex sets the "rewardIndex" parameter. +func (inst *SetRewardAuthorityBySuperAuthority) SetRewardIndex(rewardIndex uint8) *SetRewardAuthorityBySuperAuthority { + inst.RewardIndex = &rewardIndex + return inst +} + +// SetWhirlpoolsConfigAccount sets the "whirlpoolsConfig" account. +func (inst *SetRewardAuthorityBySuperAuthority) SetWhirlpoolsConfigAccount(whirlpoolsConfig ag_solanago.PublicKey) *SetRewardAuthorityBySuperAuthority { + inst.AccountMetaSlice[0] = ag_solanago.Meta(whirlpoolsConfig) + return inst +} + +// GetWhirlpoolsConfigAccount gets the "whirlpoolsConfig" account. +func (inst *SetRewardAuthorityBySuperAuthority) GetWhirlpoolsConfigAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetWhirlpoolAccount sets the "whirlpool" account. +func (inst *SetRewardAuthorityBySuperAuthority) SetWhirlpoolAccount(whirlpool ag_solanago.PublicKey) *SetRewardAuthorityBySuperAuthority { + inst.AccountMetaSlice[1] = ag_solanago.Meta(whirlpool).WRITE() + return inst +} + +// GetWhirlpoolAccount gets the "whirlpool" account. +func (inst *SetRewardAuthorityBySuperAuthority) GetWhirlpoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetRewardEmissionsSuperAuthorityAccount sets the "rewardEmissionsSuperAuthority" account. +func (inst *SetRewardAuthorityBySuperAuthority) SetRewardEmissionsSuperAuthorityAccount(rewardEmissionsSuperAuthority ag_solanago.PublicKey) *SetRewardAuthorityBySuperAuthority { + inst.AccountMetaSlice[2] = ag_solanago.Meta(rewardEmissionsSuperAuthority).SIGNER() + return inst +} + +// GetRewardEmissionsSuperAuthorityAccount gets the "rewardEmissionsSuperAuthority" account. +func (inst *SetRewardAuthorityBySuperAuthority) GetRewardEmissionsSuperAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetNewRewardAuthorityAccount sets the "newRewardAuthority" account. +func (inst *SetRewardAuthorityBySuperAuthority) SetNewRewardAuthorityAccount(newRewardAuthority ag_solanago.PublicKey) *SetRewardAuthorityBySuperAuthority { + inst.AccountMetaSlice[3] = ag_solanago.Meta(newRewardAuthority) + return inst +} + +// GetNewRewardAuthorityAccount gets the "newRewardAuthority" account. +func (inst *SetRewardAuthorityBySuperAuthority) GetNewRewardAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +func (inst SetRewardAuthorityBySuperAuthority) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_SetRewardAuthorityBySuperAuthority, + }} +} + +// 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 SetRewardAuthorityBySuperAuthority) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *SetRewardAuthorityBySuperAuthority) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.RewardIndex == nil { + return errors.New("RewardIndex parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.WhirlpoolsConfig is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Whirlpool is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.RewardEmissionsSuperAuthority is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.NewRewardAuthority is not set") + } + } + return nil +} + +func (inst *SetRewardAuthorityBySuperAuthority) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("SetRewardAuthorityBySuperAuthority")). + // + 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("RewardIndex", *inst.RewardIndex)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=4]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" whirlpoolsConfig", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" whirlpool", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta("rewardEmissionsSuperAuthority", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" newRewardAuthority", inst.AccountMetaSlice.Get(3))) + }) + }) + }) +} + +func (obj SetRewardAuthorityBySuperAuthority) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `RewardIndex` param: + err = encoder.Encode(obj.RewardIndex) + if err != nil { + return err + } + return nil +} +func (obj *SetRewardAuthorityBySuperAuthority) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `RewardIndex`: + err = decoder.Decode(&obj.RewardIndex) + if err != nil { + return err + } + return nil +} + +// NewSetRewardAuthorityBySuperAuthorityInstruction declares a new SetRewardAuthorityBySuperAuthority instruction with the provided parameters and accounts. +func NewSetRewardAuthorityBySuperAuthorityInstruction( + // Parameters: + rewardIndex uint8, + // Accounts: + whirlpoolsConfig ag_solanago.PublicKey, + whirlpool ag_solanago.PublicKey, + rewardEmissionsSuperAuthority ag_solanago.PublicKey, + newRewardAuthority ag_solanago.PublicKey) *SetRewardAuthorityBySuperAuthority { + return NewSetRewardAuthorityBySuperAuthorityInstructionBuilder(). + SetRewardIndex(rewardIndex). + SetWhirlpoolsConfigAccount(whirlpoolsConfig). + SetWhirlpoolAccount(whirlpool). + SetRewardEmissionsSuperAuthorityAccount(rewardEmissionsSuperAuthority). + SetNewRewardAuthorityAccount(newRewardAuthority) +} diff --git a/programs/whirlpool/SetRewardAuthorityBySuperAuthority_test.go b/programs/whirlpool/SetRewardAuthorityBySuperAuthority_test.go new file mode 100644 index 00000000..29360b4d --- /dev/null +++ b/programs/whirlpool/SetRewardAuthorityBySuperAuthority_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_SetRewardAuthorityBySuperAuthority(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("SetRewardAuthorityBySuperAuthority"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(SetRewardAuthorityBySuperAuthority) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(SetRewardAuthorityBySuperAuthority) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/SetRewardAuthority_test.go b/programs/whirlpool/SetRewardAuthority_test.go new file mode 100644 index 00000000..ab81692f --- /dev/null +++ b/programs/whirlpool/SetRewardAuthority_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_SetRewardAuthority(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("SetRewardAuthority"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(SetRewardAuthority) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(SetRewardAuthority) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/SetRewardEmissions.go b/programs/whirlpool/SetRewardEmissions.go new file mode 100644 index 00000000..93c405e8 --- /dev/null +++ b/programs/whirlpool/SetRewardEmissions.go @@ -0,0 +1,188 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "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" +) + +// SetRewardEmissions is the `setRewardEmissions` instruction. +type SetRewardEmissions struct { + RewardIndex *uint8 + EmissionsPerSecondX64 *ag_binary.Uint128 + + // [0] = [WRITE] whirlpool + // + // [1] = [SIGNER] rewardAuthority + // + // [2] = [] rewardVault + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewSetRewardEmissionsInstructionBuilder creates a new `SetRewardEmissions` instruction builder. +func NewSetRewardEmissionsInstructionBuilder() *SetRewardEmissions { + nd := &SetRewardEmissions{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 3), + } + return nd +} + +// SetRewardIndex sets the "rewardIndex" parameter. +func (inst *SetRewardEmissions) SetRewardIndex(rewardIndex uint8) *SetRewardEmissions { + inst.RewardIndex = &rewardIndex + return inst +} + +// SetEmissionsPerSecondX64 sets the "emissionsPerSecondX64" parameter. +func (inst *SetRewardEmissions) SetEmissionsPerSecondX64(emissionsPerSecondX64 ag_binary.Uint128) *SetRewardEmissions { + inst.EmissionsPerSecondX64 = &emissionsPerSecondX64 + return inst +} + +// SetWhirlpoolAccount sets the "whirlpool" account. +func (inst *SetRewardEmissions) SetWhirlpoolAccount(whirlpool ag_solanago.PublicKey) *SetRewardEmissions { + inst.AccountMetaSlice[0] = ag_solanago.Meta(whirlpool).WRITE() + return inst +} + +// GetWhirlpoolAccount gets the "whirlpool" account. +func (inst *SetRewardEmissions) GetWhirlpoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetRewardAuthorityAccount sets the "rewardAuthority" account. +func (inst *SetRewardEmissions) SetRewardAuthorityAccount(rewardAuthority ag_solanago.PublicKey) *SetRewardEmissions { + inst.AccountMetaSlice[1] = ag_solanago.Meta(rewardAuthority).SIGNER() + return inst +} + +// GetRewardAuthorityAccount gets the "rewardAuthority" account. +func (inst *SetRewardEmissions) GetRewardAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetRewardVaultAccount sets the "rewardVault" account. +func (inst *SetRewardEmissions) SetRewardVaultAccount(rewardVault ag_solanago.PublicKey) *SetRewardEmissions { + inst.AccountMetaSlice[2] = ag_solanago.Meta(rewardVault) + return inst +} + +// GetRewardVaultAccount gets the "rewardVault" account. +func (inst *SetRewardEmissions) GetRewardVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +func (inst SetRewardEmissions) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_SetRewardEmissions, + }} +} + +// 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 SetRewardEmissions) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *SetRewardEmissions) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.RewardIndex == nil { + return errors.New("RewardIndex parameter is not set") + } + if inst.EmissionsPerSecondX64 == nil { + return errors.New("EmissionsPerSecondX64 parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Whirlpool is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.RewardAuthority is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.RewardVault is not set") + } + } + return nil +} + +func (inst *SetRewardEmissions) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("SetRewardEmissions")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=2]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" RewardIndex", *inst.RewardIndex)) + paramsBranch.Child(ag_format.Param("EmissionsPerSecondX64", *inst.EmissionsPerSecondX64)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=3]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" whirlpool", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta("rewardAuthority", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" rewardVault", inst.AccountMetaSlice.Get(2))) + }) + }) + }) +} + +func (obj SetRewardEmissions) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `RewardIndex` param: + err = encoder.Encode(obj.RewardIndex) + if err != nil { + return err + } + // Serialize `EmissionsPerSecondX64` param: + err = encoder.Encode(obj.EmissionsPerSecondX64) + if err != nil { + return err + } + return nil +} +func (obj *SetRewardEmissions) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `RewardIndex`: + err = decoder.Decode(&obj.RewardIndex) + if err != nil { + return err + } + // Deserialize `EmissionsPerSecondX64`: + err = decoder.Decode(&obj.EmissionsPerSecondX64) + if err != nil { + return err + } + return nil +} + +// NewSetRewardEmissionsInstruction declares a new SetRewardEmissions instruction with the provided parameters and accounts. +func NewSetRewardEmissionsInstruction( + // Parameters: + rewardIndex uint8, + emissionsPerSecondX64 ag_binary.Uint128, + // Accounts: + whirlpool ag_solanago.PublicKey, + rewardAuthority ag_solanago.PublicKey, + rewardVault ag_solanago.PublicKey) *SetRewardEmissions { + return NewSetRewardEmissionsInstructionBuilder(). + SetRewardIndex(rewardIndex). + SetEmissionsPerSecondX64(emissionsPerSecondX64). + SetWhirlpoolAccount(whirlpool). + SetRewardAuthorityAccount(rewardAuthority). + SetRewardVaultAccount(rewardVault) +} diff --git a/programs/whirlpool/SetRewardEmissionsSuperAuthority.go b/programs/whirlpool/SetRewardEmissionsSuperAuthority.go new file mode 100644 index 00000000..a2ede32b --- /dev/null +++ b/programs/whirlpool/SetRewardEmissionsSuperAuthority.go @@ -0,0 +1,136 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "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" +) + +// SetRewardEmissionsSuperAuthority is the `setRewardEmissionsSuperAuthority` instruction. +type SetRewardEmissionsSuperAuthority struct { + + // [0] = [WRITE] whirlpoolsConfig + // + // [1] = [SIGNER] rewardEmissionsSuperAuthority + // + // [2] = [] newRewardEmissionsSuperAuthority + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewSetRewardEmissionsSuperAuthorityInstructionBuilder creates a new `SetRewardEmissionsSuperAuthority` instruction builder. +func NewSetRewardEmissionsSuperAuthorityInstructionBuilder() *SetRewardEmissionsSuperAuthority { + nd := &SetRewardEmissionsSuperAuthority{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 3), + } + return nd +} + +// SetWhirlpoolsConfigAccount sets the "whirlpoolsConfig" account. +func (inst *SetRewardEmissionsSuperAuthority) SetWhirlpoolsConfigAccount(whirlpoolsConfig ag_solanago.PublicKey) *SetRewardEmissionsSuperAuthority { + inst.AccountMetaSlice[0] = ag_solanago.Meta(whirlpoolsConfig).WRITE() + return inst +} + +// GetWhirlpoolsConfigAccount gets the "whirlpoolsConfig" account. +func (inst *SetRewardEmissionsSuperAuthority) GetWhirlpoolsConfigAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetRewardEmissionsSuperAuthorityAccount sets the "rewardEmissionsSuperAuthority" account. +func (inst *SetRewardEmissionsSuperAuthority) SetRewardEmissionsSuperAuthorityAccount(rewardEmissionsSuperAuthority ag_solanago.PublicKey) *SetRewardEmissionsSuperAuthority { + inst.AccountMetaSlice[1] = ag_solanago.Meta(rewardEmissionsSuperAuthority).SIGNER() + return inst +} + +// GetRewardEmissionsSuperAuthorityAccount gets the "rewardEmissionsSuperAuthority" account. +func (inst *SetRewardEmissionsSuperAuthority) GetRewardEmissionsSuperAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetNewRewardEmissionsSuperAuthorityAccount sets the "newRewardEmissionsSuperAuthority" account. +func (inst *SetRewardEmissionsSuperAuthority) SetNewRewardEmissionsSuperAuthorityAccount(newRewardEmissionsSuperAuthority ag_solanago.PublicKey) *SetRewardEmissionsSuperAuthority { + inst.AccountMetaSlice[2] = ag_solanago.Meta(newRewardEmissionsSuperAuthority) + return inst +} + +// GetNewRewardEmissionsSuperAuthorityAccount gets the "newRewardEmissionsSuperAuthority" account. +func (inst *SetRewardEmissionsSuperAuthority) GetNewRewardEmissionsSuperAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +func (inst SetRewardEmissionsSuperAuthority) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_SetRewardEmissionsSuperAuthority, + }} +} + +// 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 SetRewardEmissionsSuperAuthority) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *SetRewardEmissionsSuperAuthority) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.WhirlpoolsConfig is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.RewardEmissionsSuperAuthority is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.NewRewardEmissionsSuperAuthority is not set") + } + } + return nil +} + +func (inst *SetRewardEmissionsSuperAuthority) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("SetRewardEmissionsSuperAuthority")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=3]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" whirlpoolsConfig", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" rewardEmissionsSuperAuthority", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta("newRewardEmissionsSuperAuthority", inst.AccountMetaSlice.Get(2))) + }) + }) + }) +} + +func (obj SetRewardEmissionsSuperAuthority) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *SetRewardEmissionsSuperAuthority) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewSetRewardEmissionsSuperAuthorityInstruction declares a new SetRewardEmissionsSuperAuthority instruction with the provided parameters and accounts. +func NewSetRewardEmissionsSuperAuthorityInstruction( + // Accounts: + whirlpoolsConfig ag_solanago.PublicKey, + rewardEmissionsSuperAuthority ag_solanago.PublicKey, + newRewardEmissionsSuperAuthority ag_solanago.PublicKey) *SetRewardEmissionsSuperAuthority { + return NewSetRewardEmissionsSuperAuthorityInstructionBuilder(). + SetWhirlpoolsConfigAccount(whirlpoolsConfig). + SetRewardEmissionsSuperAuthorityAccount(rewardEmissionsSuperAuthority). + SetNewRewardEmissionsSuperAuthorityAccount(newRewardEmissionsSuperAuthority) +} diff --git a/programs/whirlpool/SetRewardEmissionsSuperAuthority_test.go b/programs/whirlpool/SetRewardEmissionsSuperAuthority_test.go new file mode 100644 index 00000000..9501fd79 --- /dev/null +++ b/programs/whirlpool/SetRewardEmissionsSuperAuthority_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_SetRewardEmissionsSuperAuthority(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("SetRewardEmissionsSuperAuthority"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(SetRewardEmissionsSuperAuthority) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(SetRewardEmissionsSuperAuthority) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/SetRewardEmissions_test.go b/programs/whirlpool/SetRewardEmissions_test.go new file mode 100644 index 00000000..67c1dde9 --- /dev/null +++ b/programs/whirlpool/SetRewardEmissions_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_SetRewardEmissions(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("SetRewardEmissions"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(SetRewardEmissions) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(SetRewardEmissions) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/Swap.go b/programs/whirlpool/Swap.go new file mode 100644 index 00000000..bb28478d --- /dev/null +++ b/programs/whirlpool/Swap.go @@ -0,0 +1,409 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "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" +) + +// Swap is the `swap` instruction. +type Swap struct { + Amount *uint64 + OtherAmountThreshold *uint64 + SqrtPriceLimit *ag_binary.Uint128 + AmountSpecifiedIsInput *bool + AToB *bool + + // [0] = [] tokenProgram + // + // [1] = [SIGNER] tokenAuthority + // + // [2] = [WRITE] whirlpool + // + // [3] = [WRITE] tokenOwnerAccountA + // + // [4] = [WRITE] tokenVaultA + // + // [5] = [WRITE] tokenOwnerAccountB + // + // [6] = [WRITE] tokenVaultB + // + // [7] = [WRITE] tickArray0 + // + // [8] = [WRITE] tickArray1 + // + // [9] = [WRITE] tickArray2 + // + // [10] = [] oracle + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewSwapInstructionBuilder creates a new `Swap` instruction builder. +func NewSwapInstructionBuilder() *Swap { + nd := &Swap{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 11), + } + return nd +} + +// SetAmount sets the "amount" parameter. +func (inst *Swap) SetAmount(amount uint64) *Swap { + inst.Amount = &amount + return inst +} + +// SetOtherAmountThreshold sets the "otherAmountThreshold" parameter. +func (inst *Swap) SetOtherAmountThreshold(otherAmountThreshold uint64) *Swap { + inst.OtherAmountThreshold = &otherAmountThreshold + return inst +} + +// SetSqrtPriceLimit sets the "sqrtPriceLimit" parameter. +func (inst *Swap) SetSqrtPriceLimit(sqrtPriceLimit ag_binary.Uint128) *Swap { + inst.SqrtPriceLimit = &sqrtPriceLimit + return inst +} + +// SetAmountSpecifiedIsInput sets the "amountSpecifiedIsInput" parameter. +func (inst *Swap) SetAmountSpecifiedIsInput(amountSpecifiedIsInput bool) *Swap { + inst.AmountSpecifiedIsInput = &amountSpecifiedIsInput + return inst +} + +// SetAToB sets the "aToB" parameter. +func (inst *Swap) SetAToB(aToB bool) *Swap { + inst.AToB = &aToB + return inst +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *Swap) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[0] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *Swap) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetTokenAuthorityAccount sets the "tokenAuthority" account. +func (inst *Swap) SetTokenAuthorityAccount(tokenAuthority ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[1] = ag_solanago.Meta(tokenAuthority).SIGNER() + return inst +} + +// GetTokenAuthorityAccount gets the "tokenAuthority" account. +func (inst *Swap) GetTokenAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetWhirlpoolAccount sets the "whirlpool" account. +func (inst *Swap) SetWhirlpoolAccount(whirlpool ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[2] = ag_solanago.Meta(whirlpool).WRITE() + return inst +} + +// GetWhirlpoolAccount gets the "whirlpool" account. +func (inst *Swap) GetWhirlpoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetTokenOwnerAccountAAccount sets the "tokenOwnerAccountA" account. +func (inst *Swap) SetTokenOwnerAccountAAccount(tokenOwnerAccountA ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[3] = ag_solanago.Meta(tokenOwnerAccountA).WRITE() + return inst +} + +// GetTokenOwnerAccountAAccount gets the "tokenOwnerAccountA" account. +func (inst *Swap) GetTokenOwnerAccountAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetTokenVaultAAccount sets the "tokenVaultA" account. +func (inst *Swap) SetTokenVaultAAccount(tokenVaultA ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[4] = ag_solanago.Meta(tokenVaultA).WRITE() + return inst +} + +// GetTokenVaultAAccount gets the "tokenVaultA" account. +func (inst *Swap) GetTokenVaultAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetTokenOwnerAccountBAccount sets the "tokenOwnerAccountB" account. +func (inst *Swap) SetTokenOwnerAccountBAccount(tokenOwnerAccountB ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[5] = ag_solanago.Meta(tokenOwnerAccountB).WRITE() + return inst +} + +// GetTokenOwnerAccountBAccount gets the "tokenOwnerAccountB" account. +func (inst *Swap) GetTokenOwnerAccountBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetTokenVaultBAccount sets the "tokenVaultB" account. +func (inst *Swap) SetTokenVaultBAccount(tokenVaultB ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[6] = ag_solanago.Meta(tokenVaultB).WRITE() + return inst +} + +// GetTokenVaultBAccount gets the "tokenVaultB" account. +func (inst *Swap) GetTokenVaultBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetTickArray0Account sets the "tickArray0" account. +func (inst *Swap) SetTickArray0Account(tickArray0 ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[7] = ag_solanago.Meta(tickArray0).WRITE() + return inst +} + +// GetTickArray0Account gets the "tickArray0" account. +func (inst *Swap) GetTickArray0Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetTickArray1Account sets the "tickArray1" account. +func (inst *Swap) SetTickArray1Account(tickArray1 ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[8] = ag_solanago.Meta(tickArray1).WRITE() + return inst +} + +// GetTickArray1Account gets the "tickArray1" account. +func (inst *Swap) GetTickArray1Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetTickArray2Account sets the "tickArray2" account. +func (inst *Swap) SetTickArray2Account(tickArray2 ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[9] = ag_solanago.Meta(tickArray2).WRITE() + return inst +} + +// GetTickArray2Account gets the "tickArray2" account. +func (inst *Swap) GetTickArray2Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetOracleAccount sets the "oracle" account. +func (inst *Swap) SetOracleAccount(oracle ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[10] = ag_solanago.Meta(oracle) + return inst +} + +// GetOracleAccount gets the "oracle" account. +func (inst *Swap) GetOracleAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +func (inst Swap) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_Swap, + }} +} + +// 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 Swap) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *Swap) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.Amount == nil { + return errors.New("Amount parameter is not set") + } + if inst.OtherAmountThreshold == nil { + return errors.New("OtherAmountThreshold parameter is not set") + } + if inst.SqrtPriceLimit == nil { + return errors.New("SqrtPriceLimit parameter is not set") + } + if inst.AmountSpecifiedIsInput == nil { + return errors.New("AmountSpecifiedIsInput parameter is not set") + } + if inst.AToB == nil { + return errors.New("AToB parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.TokenAuthority is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.Whirlpool is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.TokenOwnerAccountA is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.TokenVaultA is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.TokenOwnerAccountB is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.TokenVaultB is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.TickArray0 is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.TickArray1 is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.TickArray2 is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.Oracle is not set") + } + } + return nil +} + +func (inst *Swap) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("Swap")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=5]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" Amount", *inst.Amount)) + paramsBranch.Child(ag_format.Param(" OtherAmountThreshold", *inst.OtherAmountThreshold)) + paramsBranch.Child(ag_format.Param(" SqrtPriceLimit", *inst.SqrtPriceLimit)) + paramsBranch.Child(ag_format.Param("AmountSpecifiedIsInput", *inst.AmountSpecifiedIsInput)) + paramsBranch.Child(ag_format.Param(" AToB", *inst.AToB)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=11]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" tokenAuthority", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" whirlpool", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta("tokenOwnerAccountA", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" tokenVaultA", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta("tokenOwnerAccountB", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" tokenVaultB", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" tickArray0", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" tickArray1", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" tickArray2", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" oracle", inst.AccountMetaSlice.Get(10))) + }) + }) + }) +} + +func (obj Swap) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Amount` param: + err = encoder.Encode(obj.Amount) + if err != nil { + return err + } + // Serialize `OtherAmountThreshold` param: + err = encoder.Encode(obj.OtherAmountThreshold) + if err != nil { + return err + } + // Serialize `SqrtPriceLimit` param: + err = encoder.Encode(obj.SqrtPriceLimit) + if err != nil { + return err + } + // Serialize `AmountSpecifiedIsInput` param: + err = encoder.Encode(obj.AmountSpecifiedIsInput) + if err != nil { + return err + } + // Serialize `AToB` param: + err = encoder.Encode(obj.AToB) + if err != nil { + return err + } + return nil +} +func (obj *Swap) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Amount`: + err = decoder.Decode(&obj.Amount) + if err != nil { + return err + } + // Deserialize `OtherAmountThreshold`: + err = decoder.Decode(&obj.OtherAmountThreshold) + if err != nil { + return err + } + // Deserialize `SqrtPriceLimit`: + err = decoder.Decode(&obj.SqrtPriceLimit) + if err != nil { + return err + } + // Deserialize `AmountSpecifiedIsInput`: + err = decoder.Decode(&obj.AmountSpecifiedIsInput) + if err != nil { + return err + } + // Deserialize `AToB`: + err = decoder.Decode(&obj.AToB) + if err != nil { + return err + } + return nil +} + +// NewSwapInstruction declares a new Swap instruction with the provided parameters and accounts. +func NewSwapInstruction( + // Parameters: + amount uint64, + otherAmountThreshold uint64, + sqrtPriceLimit ag_binary.Uint128, + amountSpecifiedIsInput bool, + aToB bool, + // Accounts: + tokenProgram ag_solanago.PublicKey, + tokenAuthority ag_solanago.PublicKey, + whirlpool ag_solanago.PublicKey, + tokenOwnerAccountA ag_solanago.PublicKey, + tokenVaultA ag_solanago.PublicKey, + tokenOwnerAccountB ag_solanago.PublicKey, + tokenVaultB ag_solanago.PublicKey, + tickArray0 ag_solanago.PublicKey, + tickArray1 ag_solanago.PublicKey, + tickArray2 ag_solanago.PublicKey, + oracle ag_solanago.PublicKey) *Swap { + return NewSwapInstructionBuilder(). + SetAmount(amount). + SetOtherAmountThreshold(otherAmountThreshold). + SetSqrtPriceLimit(sqrtPriceLimit). + SetAmountSpecifiedIsInput(amountSpecifiedIsInput). + SetAToB(aToB). + SetTokenProgramAccount(tokenProgram). + SetTokenAuthorityAccount(tokenAuthority). + SetWhirlpoolAccount(whirlpool). + SetTokenOwnerAccountAAccount(tokenOwnerAccountA). + SetTokenVaultAAccount(tokenVaultA). + SetTokenOwnerAccountBAccount(tokenOwnerAccountB). + SetTokenVaultBAccount(tokenVaultB). + SetTickArray0Account(tickArray0). + SetTickArray1Account(tickArray1). + SetTickArray2Account(tickArray2). + SetOracleAccount(oracle) +} diff --git a/programs/whirlpool/Swap_test.go b/programs/whirlpool/Swap_test.go new file mode 100644 index 00000000..ecb46b16 --- /dev/null +++ b/programs/whirlpool/Swap_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_Swap(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("Swap"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(Swap) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(Swap) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/TwoHopSwap.go b/programs/whirlpool/TwoHopSwap.go new file mode 100644 index 00000000..8a6a0e3a --- /dev/null +++ b/programs/whirlpool/TwoHopSwap.go @@ -0,0 +1,626 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "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" +) + +// TwoHopSwap is the `twoHopSwap` instruction. +type TwoHopSwap struct { + Amount *uint64 + OtherAmountThreshold *uint64 + AmountSpecifiedIsInput *bool + AToBOne *bool + AToBTwo *bool + SqrtPriceLimitOne *ag_binary.Uint128 + SqrtPriceLimitTwo *ag_binary.Uint128 + + // [0] = [] tokenProgram + // + // [1] = [SIGNER] tokenAuthority + // + // [2] = [WRITE] whirlpoolOne + // + // [3] = [WRITE] whirlpoolTwo + // + // [4] = [WRITE] tokenOwnerAccountOneA + // + // [5] = [WRITE] tokenVaultOneA + // + // [6] = [WRITE] tokenOwnerAccountOneB + // + // [7] = [WRITE] tokenVaultOneB + // + // [8] = [WRITE] tokenOwnerAccountTwoA + // + // [9] = [WRITE] tokenVaultTwoA + // + // [10] = [WRITE] tokenOwnerAccountTwoB + // + // [11] = [WRITE] tokenVaultTwoB + // + // [12] = [WRITE] tickArrayOne0 + // + // [13] = [WRITE] tickArrayOne1 + // + // [14] = [WRITE] tickArrayOne2 + // + // [15] = [WRITE] tickArrayTwo0 + // + // [16] = [WRITE] tickArrayTwo1 + // + // [17] = [WRITE] tickArrayTwo2 + // + // [18] = [] oracleOne + // + // [19] = [] oracleTwo + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewTwoHopSwapInstructionBuilder creates a new `TwoHopSwap` instruction builder. +func NewTwoHopSwapInstructionBuilder() *TwoHopSwap { + nd := &TwoHopSwap{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 20), + } + return nd +} + +// SetAmount sets the "amount" parameter. +func (inst *TwoHopSwap) SetAmount(amount uint64) *TwoHopSwap { + inst.Amount = &amount + return inst +} + +// SetOtherAmountThreshold sets the "otherAmountThreshold" parameter. +func (inst *TwoHopSwap) SetOtherAmountThreshold(otherAmountThreshold uint64) *TwoHopSwap { + inst.OtherAmountThreshold = &otherAmountThreshold + return inst +} + +// SetAmountSpecifiedIsInput sets the "amountSpecifiedIsInput" parameter. +func (inst *TwoHopSwap) SetAmountSpecifiedIsInput(amountSpecifiedIsInput bool) *TwoHopSwap { + inst.AmountSpecifiedIsInput = &amountSpecifiedIsInput + return inst +} + +// SetAToBOne sets the "aToBOne" parameter. +func (inst *TwoHopSwap) SetAToBOne(aToBOne bool) *TwoHopSwap { + inst.AToBOne = &aToBOne + return inst +} + +// SetAToBTwo sets the "aToBTwo" parameter. +func (inst *TwoHopSwap) SetAToBTwo(aToBTwo bool) *TwoHopSwap { + inst.AToBTwo = &aToBTwo + return inst +} + +// SetSqrtPriceLimitOne sets the "sqrtPriceLimitOne" parameter. +func (inst *TwoHopSwap) SetSqrtPriceLimitOne(sqrtPriceLimitOne ag_binary.Uint128) *TwoHopSwap { + inst.SqrtPriceLimitOne = &sqrtPriceLimitOne + return inst +} + +// SetSqrtPriceLimitTwo sets the "sqrtPriceLimitTwo" parameter. +func (inst *TwoHopSwap) SetSqrtPriceLimitTwo(sqrtPriceLimitTwo ag_binary.Uint128) *TwoHopSwap { + inst.SqrtPriceLimitTwo = &sqrtPriceLimitTwo + return inst +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *TwoHopSwap) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *TwoHopSwap { + inst.AccountMetaSlice[0] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *TwoHopSwap) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetTokenAuthorityAccount sets the "tokenAuthority" account. +func (inst *TwoHopSwap) SetTokenAuthorityAccount(tokenAuthority ag_solanago.PublicKey) *TwoHopSwap { + inst.AccountMetaSlice[1] = ag_solanago.Meta(tokenAuthority).SIGNER() + return inst +} + +// GetTokenAuthorityAccount gets the "tokenAuthority" account. +func (inst *TwoHopSwap) GetTokenAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetWhirlpoolOneAccount sets the "whirlpoolOne" account. +func (inst *TwoHopSwap) SetWhirlpoolOneAccount(whirlpoolOne ag_solanago.PublicKey) *TwoHopSwap { + inst.AccountMetaSlice[2] = ag_solanago.Meta(whirlpoolOne).WRITE() + return inst +} + +// GetWhirlpoolOneAccount gets the "whirlpoolOne" account. +func (inst *TwoHopSwap) GetWhirlpoolOneAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetWhirlpoolTwoAccount sets the "whirlpoolTwo" account. +func (inst *TwoHopSwap) SetWhirlpoolTwoAccount(whirlpoolTwo ag_solanago.PublicKey) *TwoHopSwap { + inst.AccountMetaSlice[3] = ag_solanago.Meta(whirlpoolTwo).WRITE() + return inst +} + +// GetWhirlpoolTwoAccount gets the "whirlpoolTwo" account. +func (inst *TwoHopSwap) GetWhirlpoolTwoAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetTokenOwnerAccountOneAAccount sets the "tokenOwnerAccountOneA" account. +func (inst *TwoHopSwap) SetTokenOwnerAccountOneAAccount(tokenOwnerAccountOneA ag_solanago.PublicKey) *TwoHopSwap { + inst.AccountMetaSlice[4] = ag_solanago.Meta(tokenOwnerAccountOneA).WRITE() + return inst +} + +// GetTokenOwnerAccountOneAAccount gets the "tokenOwnerAccountOneA" account. +func (inst *TwoHopSwap) GetTokenOwnerAccountOneAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetTokenVaultOneAAccount sets the "tokenVaultOneA" account. +func (inst *TwoHopSwap) SetTokenVaultOneAAccount(tokenVaultOneA ag_solanago.PublicKey) *TwoHopSwap { + inst.AccountMetaSlice[5] = ag_solanago.Meta(tokenVaultOneA).WRITE() + return inst +} + +// GetTokenVaultOneAAccount gets the "tokenVaultOneA" account. +func (inst *TwoHopSwap) GetTokenVaultOneAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetTokenOwnerAccountOneBAccount sets the "tokenOwnerAccountOneB" account. +func (inst *TwoHopSwap) SetTokenOwnerAccountOneBAccount(tokenOwnerAccountOneB ag_solanago.PublicKey) *TwoHopSwap { + inst.AccountMetaSlice[6] = ag_solanago.Meta(tokenOwnerAccountOneB).WRITE() + return inst +} + +// GetTokenOwnerAccountOneBAccount gets the "tokenOwnerAccountOneB" account. +func (inst *TwoHopSwap) GetTokenOwnerAccountOneBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetTokenVaultOneBAccount sets the "tokenVaultOneB" account. +func (inst *TwoHopSwap) SetTokenVaultOneBAccount(tokenVaultOneB ag_solanago.PublicKey) *TwoHopSwap { + inst.AccountMetaSlice[7] = ag_solanago.Meta(tokenVaultOneB).WRITE() + return inst +} + +// GetTokenVaultOneBAccount gets the "tokenVaultOneB" account. +func (inst *TwoHopSwap) GetTokenVaultOneBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetTokenOwnerAccountTwoAAccount sets the "tokenOwnerAccountTwoA" account. +func (inst *TwoHopSwap) SetTokenOwnerAccountTwoAAccount(tokenOwnerAccountTwoA ag_solanago.PublicKey) *TwoHopSwap { + inst.AccountMetaSlice[8] = ag_solanago.Meta(tokenOwnerAccountTwoA).WRITE() + return inst +} + +// GetTokenOwnerAccountTwoAAccount gets the "tokenOwnerAccountTwoA" account. +func (inst *TwoHopSwap) GetTokenOwnerAccountTwoAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetTokenVaultTwoAAccount sets the "tokenVaultTwoA" account. +func (inst *TwoHopSwap) SetTokenVaultTwoAAccount(tokenVaultTwoA ag_solanago.PublicKey) *TwoHopSwap { + inst.AccountMetaSlice[9] = ag_solanago.Meta(tokenVaultTwoA).WRITE() + return inst +} + +// GetTokenVaultTwoAAccount gets the "tokenVaultTwoA" account. +func (inst *TwoHopSwap) GetTokenVaultTwoAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetTokenOwnerAccountTwoBAccount sets the "tokenOwnerAccountTwoB" account. +func (inst *TwoHopSwap) SetTokenOwnerAccountTwoBAccount(tokenOwnerAccountTwoB ag_solanago.PublicKey) *TwoHopSwap { + inst.AccountMetaSlice[10] = ag_solanago.Meta(tokenOwnerAccountTwoB).WRITE() + return inst +} + +// GetTokenOwnerAccountTwoBAccount gets the "tokenOwnerAccountTwoB" account. +func (inst *TwoHopSwap) GetTokenOwnerAccountTwoBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetTokenVaultTwoBAccount sets the "tokenVaultTwoB" account. +func (inst *TwoHopSwap) SetTokenVaultTwoBAccount(tokenVaultTwoB ag_solanago.PublicKey) *TwoHopSwap { + inst.AccountMetaSlice[11] = ag_solanago.Meta(tokenVaultTwoB).WRITE() + return inst +} + +// GetTokenVaultTwoBAccount gets the "tokenVaultTwoB" account. +func (inst *TwoHopSwap) GetTokenVaultTwoBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetTickArrayOne0Account sets the "tickArrayOne0" account. +func (inst *TwoHopSwap) SetTickArrayOne0Account(tickArrayOne0 ag_solanago.PublicKey) *TwoHopSwap { + inst.AccountMetaSlice[12] = ag_solanago.Meta(tickArrayOne0).WRITE() + return inst +} + +// GetTickArrayOne0Account gets the "tickArrayOne0" account. +func (inst *TwoHopSwap) GetTickArrayOne0Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetTickArrayOne1Account sets the "tickArrayOne1" account. +func (inst *TwoHopSwap) SetTickArrayOne1Account(tickArrayOne1 ag_solanago.PublicKey) *TwoHopSwap { + inst.AccountMetaSlice[13] = ag_solanago.Meta(tickArrayOne1).WRITE() + return inst +} + +// GetTickArrayOne1Account gets the "tickArrayOne1" account. +func (inst *TwoHopSwap) GetTickArrayOne1Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetTickArrayOne2Account sets the "tickArrayOne2" account. +func (inst *TwoHopSwap) SetTickArrayOne2Account(tickArrayOne2 ag_solanago.PublicKey) *TwoHopSwap { + inst.AccountMetaSlice[14] = ag_solanago.Meta(tickArrayOne2).WRITE() + return inst +} + +// GetTickArrayOne2Account gets the "tickArrayOne2" account. +func (inst *TwoHopSwap) GetTickArrayOne2Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +// SetTickArrayTwo0Account sets the "tickArrayTwo0" account. +func (inst *TwoHopSwap) SetTickArrayTwo0Account(tickArrayTwo0 ag_solanago.PublicKey) *TwoHopSwap { + inst.AccountMetaSlice[15] = ag_solanago.Meta(tickArrayTwo0).WRITE() + return inst +} + +// GetTickArrayTwo0Account gets the "tickArrayTwo0" account. +func (inst *TwoHopSwap) GetTickArrayTwo0Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(15) +} + +// SetTickArrayTwo1Account sets the "tickArrayTwo1" account. +func (inst *TwoHopSwap) SetTickArrayTwo1Account(tickArrayTwo1 ag_solanago.PublicKey) *TwoHopSwap { + inst.AccountMetaSlice[16] = ag_solanago.Meta(tickArrayTwo1).WRITE() + return inst +} + +// GetTickArrayTwo1Account gets the "tickArrayTwo1" account. +func (inst *TwoHopSwap) GetTickArrayTwo1Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(16) +} + +// SetTickArrayTwo2Account sets the "tickArrayTwo2" account. +func (inst *TwoHopSwap) SetTickArrayTwo2Account(tickArrayTwo2 ag_solanago.PublicKey) *TwoHopSwap { + inst.AccountMetaSlice[17] = ag_solanago.Meta(tickArrayTwo2).WRITE() + return inst +} + +// GetTickArrayTwo2Account gets the "tickArrayTwo2" account. +func (inst *TwoHopSwap) GetTickArrayTwo2Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(17) +} + +// SetOracleOneAccount sets the "oracleOne" account. +func (inst *TwoHopSwap) SetOracleOneAccount(oracleOne ag_solanago.PublicKey) *TwoHopSwap { + inst.AccountMetaSlice[18] = ag_solanago.Meta(oracleOne) + return inst +} + +// GetOracleOneAccount gets the "oracleOne" account. +func (inst *TwoHopSwap) GetOracleOneAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(18) +} + +// SetOracleTwoAccount sets the "oracleTwo" account. +func (inst *TwoHopSwap) SetOracleTwoAccount(oracleTwo ag_solanago.PublicKey) *TwoHopSwap { + inst.AccountMetaSlice[19] = ag_solanago.Meta(oracleTwo) + return inst +} + +// GetOracleTwoAccount gets the "oracleTwo" account. +func (inst *TwoHopSwap) GetOracleTwoAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(19) +} + +func (inst TwoHopSwap) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_TwoHopSwap, + }} +} + +// 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 TwoHopSwap) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *TwoHopSwap) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.Amount == nil { + return errors.New("Amount parameter is not set") + } + if inst.OtherAmountThreshold == nil { + return errors.New("OtherAmountThreshold parameter is not set") + } + if inst.AmountSpecifiedIsInput == nil { + return errors.New("AmountSpecifiedIsInput parameter is not set") + } + if inst.AToBOne == nil { + return errors.New("AToBOne parameter is not set") + } + if inst.AToBTwo == nil { + return errors.New("AToBTwo parameter is not set") + } + if inst.SqrtPriceLimitOne == nil { + return errors.New("SqrtPriceLimitOne parameter is not set") + } + if inst.SqrtPriceLimitTwo == nil { + return errors.New("SqrtPriceLimitTwo parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.TokenAuthority is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.WhirlpoolOne is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.WhirlpoolTwo is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.TokenOwnerAccountOneA is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.TokenVaultOneA is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.TokenOwnerAccountOneB is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.TokenVaultOneB is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.TokenOwnerAccountTwoA is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.TokenVaultTwoA is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.TokenOwnerAccountTwoB is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.TokenVaultTwoB is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.TickArrayOne0 is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.TickArrayOne1 is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.TickArrayOne2 is not set") + } + if inst.AccountMetaSlice[15] == nil { + return errors.New("accounts.TickArrayTwo0 is not set") + } + if inst.AccountMetaSlice[16] == nil { + return errors.New("accounts.TickArrayTwo1 is not set") + } + if inst.AccountMetaSlice[17] == nil { + return errors.New("accounts.TickArrayTwo2 is not set") + } + if inst.AccountMetaSlice[18] == nil { + return errors.New("accounts.OracleOne is not set") + } + if inst.AccountMetaSlice[19] == nil { + return errors.New("accounts.OracleTwo is not set") + } + } + return nil +} + +func (inst *TwoHopSwap) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("TwoHopSwap")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=7]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" Amount", *inst.Amount)) + paramsBranch.Child(ag_format.Param(" OtherAmountThreshold", *inst.OtherAmountThreshold)) + paramsBranch.Child(ag_format.Param("AmountSpecifiedIsInput", *inst.AmountSpecifiedIsInput)) + paramsBranch.Child(ag_format.Param(" AToBOne", *inst.AToBOne)) + paramsBranch.Child(ag_format.Param(" AToBTwo", *inst.AToBTwo)) + paramsBranch.Child(ag_format.Param(" SqrtPriceLimitOne", *inst.SqrtPriceLimitOne)) + paramsBranch.Child(ag_format.Param(" SqrtPriceLimitTwo", *inst.SqrtPriceLimitTwo)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=20]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" tokenAuthority", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" whirlpoolOne", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" whirlpoolTwo", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta("tokenOwnerAccountOneA", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" tokenVaultOneA", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta("tokenOwnerAccountOneB", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" tokenVaultOneB", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta("tokenOwnerAccountTwoA", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" tokenVaultTwoA", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta("tokenOwnerAccountTwoB", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" tokenVaultTwoB", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" tickArrayOne0", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" tickArrayOne1", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta(" tickArrayOne2", inst.AccountMetaSlice.Get(14))) + accountsBranch.Child(ag_format.Meta(" tickArrayTwo0", inst.AccountMetaSlice.Get(15))) + accountsBranch.Child(ag_format.Meta(" tickArrayTwo1", inst.AccountMetaSlice.Get(16))) + accountsBranch.Child(ag_format.Meta(" tickArrayTwo2", inst.AccountMetaSlice.Get(17))) + accountsBranch.Child(ag_format.Meta(" oracleOne", inst.AccountMetaSlice.Get(18))) + accountsBranch.Child(ag_format.Meta(" oracleTwo", inst.AccountMetaSlice.Get(19))) + }) + }) + }) +} + +func (obj TwoHopSwap) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Amount` param: + err = encoder.Encode(obj.Amount) + if err != nil { + return err + } + // Serialize `OtherAmountThreshold` param: + err = encoder.Encode(obj.OtherAmountThreshold) + if err != nil { + return err + } + // Serialize `AmountSpecifiedIsInput` param: + err = encoder.Encode(obj.AmountSpecifiedIsInput) + if err != nil { + return err + } + // Serialize `AToBOne` param: + err = encoder.Encode(obj.AToBOne) + if err != nil { + return err + } + // Serialize `AToBTwo` param: + err = encoder.Encode(obj.AToBTwo) + if err != nil { + return err + } + // Serialize `SqrtPriceLimitOne` param: + err = encoder.Encode(obj.SqrtPriceLimitOne) + if err != nil { + return err + } + // Serialize `SqrtPriceLimitTwo` param: + err = encoder.Encode(obj.SqrtPriceLimitTwo) + if err != nil { + return err + } + return nil +} +func (obj *TwoHopSwap) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Amount`: + err = decoder.Decode(&obj.Amount) + if err != nil { + return err + } + // Deserialize `OtherAmountThreshold`: + err = decoder.Decode(&obj.OtherAmountThreshold) + if err != nil { + return err + } + // Deserialize `AmountSpecifiedIsInput`: + err = decoder.Decode(&obj.AmountSpecifiedIsInput) + if err != nil { + return err + } + // Deserialize `AToBOne`: + err = decoder.Decode(&obj.AToBOne) + if err != nil { + return err + } + // Deserialize `AToBTwo`: + err = decoder.Decode(&obj.AToBTwo) + if err != nil { + return err + } + // Deserialize `SqrtPriceLimitOne`: + err = decoder.Decode(&obj.SqrtPriceLimitOne) + if err != nil { + return err + } + // Deserialize `SqrtPriceLimitTwo`: + err = decoder.Decode(&obj.SqrtPriceLimitTwo) + if err != nil { + return err + } + return nil +} + +// NewTwoHopSwapInstruction declares a new TwoHopSwap instruction with the provided parameters and accounts. +func NewTwoHopSwapInstruction( + // Parameters: + amount uint64, + otherAmountThreshold uint64, + amountSpecifiedIsInput bool, + aToBOne bool, + aToBTwo bool, + sqrtPriceLimitOne ag_binary.Uint128, + sqrtPriceLimitTwo ag_binary.Uint128, + // Accounts: + tokenProgram ag_solanago.PublicKey, + tokenAuthority ag_solanago.PublicKey, + whirlpoolOne ag_solanago.PublicKey, + whirlpoolTwo ag_solanago.PublicKey, + tokenOwnerAccountOneA ag_solanago.PublicKey, + tokenVaultOneA ag_solanago.PublicKey, + tokenOwnerAccountOneB ag_solanago.PublicKey, + tokenVaultOneB ag_solanago.PublicKey, + tokenOwnerAccountTwoA ag_solanago.PublicKey, + tokenVaultTwoA ag_solanago.PublicKey, + tokenOwnerAccountTwoB ag_solanago.PublicKey, + tokenVaultTwoB ag_solanago.PublicKey, + tickArrayOne0 ag_solanago.PublicKey, + tickArrayOne1 ag_solanago.PublicKey, + tickArrayOne2 ag_solanago.PublicKey, + tickArrayTwo0 ag_solanago.PublicKey, + tickArrayTwo1 ag_solanago.PublicKey, + tickArrayTwo2 ag_solanago.PublicKey, + oracleOne ag_solanago.PublicKey, + oracleTwo ag_solanago.PublicKey) *TwoHopSwap { + return NewTwoHopSwapInstructionBuilder(). + SetAmount(amount). + SetOtherAmountThreshold(otherAmountThreshold). + SetAmountSpecifiedIsInput(amountSpecifiedIsInput). + SetAToBOne(aToBOne). + SetAToBTwo(aToBTwo). + SetSqrtPriceLimitOne(sqrtPriceLimitOne). + SetSqrtPriceLimitTwo(sqrtPriceLimitTwo). + SetTokenProgramAccount(tokenProgram). + SetTokenAuthorityAccount(tokenAuthority). + SetWhirlpoolOneAccount(whirlpoolOne). + SetWhirlpoolTwoAccount(whirlpoolTwo). + SetTokenOwnerAccountOneAAccount(tokenOwnerAccountOneA). + SetTokenVaultOneAAccount(tokenVaultOneA). + SetTokenOwnerAccountOneBAccount(tokenOwnerAccountOneB). + SetTokenVaultOneBAccount(tokenVaultOneB). + SetTokenOwnerAccountTwoAAccount(tokenOwnerAccountTwoA). + SetTokenVaultTwoAAccount(tokenVaultTwoA). + SetTokenOwnerAccountTwoBAccount(tokenOwnerAccountTwoB). + SetTokenVaultTwoBAccount(tokenVaultTwoB). + SetTickArrayOne0Account(tickArrayOne0). + SetTickArrayOne1Account(tickArrayOne1). + SetTickArrayOne2Account(tickArrayOne2). + SetTickArrayTwo0Account(tickArrayTwo0). + SetTickArrayTwo1Account(tickArrayTwo1). + SetTickArrayTwo2Account(tickArrayTwo2). + SetOracleOneAccount(oracleOne). + SetOracleTwoAccount(oracleTwo) +} diff --git a/programs/whirlpool/TwoHopSwap_test.go b/programs/whirlpool/TwoHopSwap_test.go new file mode 100644 index 00000000..de710c3d --- /dev/null +++ b/programs/whirlpool/TwoHopSwap_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_TwoHopSwap(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("TwoHopSwap"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(TwoHopSwap) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(TwoHopSwap) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/UpdateFeesAndRewards.go b/programs/whirlpool/UpdateFeesAndRewards.go new file mode 100644 index 00000000..baf101c5 --- /dev/null +++ b/programs/whirlpool/UpdateFeesAndRewards.go @@ -0,0 +1,155 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "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" +) + +// UpdateFeesAndRewards is the `updateFeesAndRewards` instruction. +type UpdateFeesAndRewards struct { + + // [0] = [WRITE] whirlpool + // + // [1] = [WRITE] position + // + // [2] = [] tickArrayLower + // + // [3] = [] tickArrayUpper + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewUpdateFeesAndRewardsInstructionBuilder creates a new `UpdateFeesAndRewards` instruction builder. +func NewUpdateFeesAndRewardsInstructionBuilder() *UpdateFeesAndRewards { + nd := &UpdateFeesAndRewards{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 4), + } + return nd +} + +// SetWhirlpoolAccount sets the "whirlpool" account. +func (inst *UpdateFeesAndRewards) SetWhirlpoolAccount(whirlpool ag_solanago.PublicKey) *UpdateFeesAndRewards { + inst.AccountMetaSlice[0] = ag_solanago.Meta(whirlpool).WRITE() + return inst +} + +// GetWhirlpoolAccount gets the "whirlpool" account. +func (inst *UpdateFeesAndRewards) GetWhirlpoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetPositionAccount sets the "position" account. +func (inst *UpdateFeesAndRewards) SetPositionAccount(position ag_solanago.PublicKey) *UpdateFeesAndRewards { + inst.AccountMetaSlice[1] = ag_solanago.Meta(position).WRITE() + return inst +} + +// GetPositionAccount gets the "position" account. +func (inst *UpdateFeesAndRewards) GetPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetTickArrayLowerAccount sets the "tickArrayLower" account. +func (inst *UpdateFeesAndRewards) SetTickArrayLowerAccount(tickArrayLower ag_solanago.PublicKey) *UpdateFeesAndRewards { + inst.AccountMetaSlice[2] = ag_solanago.Meta(tickArrayLower) + return inst +} + +// GetTickArrayLowerAccount gets the "tickArrayLower" account. +func (inst *UpdateFeesAndRewards) GetTickArrayLowerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetTickArrayUpperAccount sets the "tickArrayUpper" account. +func (inst *UpdateFeesAndRewards) SetTickArrayUpperAccount(tickArrayUpper ag_solanago.PublicKey) *UpdateFeesAndRewards { + inst.AccountMetaSlice[3] = ag_solanago.Meta(tickArrayUpper) + return inst +} + +// GetTickArrayUpperAccount gets the "tickArrayUpper" account. +func (inst *UpdateFeesAndRewards) GetTickArrayUpperAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +func (inst UpdateFeesAndRewards) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_UpdateFeesAndRewards, + }} +} + +// 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 UpdateFeesAndRewards) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *UpdateFeesAndRewards) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Whirlpool is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Position is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.TickArrayLower is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.TickArrayUpper is not set") + } + } + return nil +} + +func (inst *UpdateFeesAndRewards) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("UpdateFeesAndRewards")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=4]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" whirlpool", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" position", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta("tickArrayLower", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta("tickArrayUpper", inst.AccountMetaSlice.Get(3))) + }) + }) + }) +} + +func (obj UpdateFeesAndRewards) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *UpdateFeesAndRewards) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewUpdateFeesAndRewardsInstruction declares a new UpdateFeesAndRewards instruction with the provided parameters and accounts. +func NewUpdateFeesAndRewardsInstruction( + // Accounts: + whirlpool ag_solanago.PublicKey, + position ag_solanago.PublicKey, + tickArrayLower ag_solanago.PublicKey, + tickArrayUpper ag_solanago.PublicKey) *UpdateFeesAndRewards { + return NewUpdateFeesAndRewardsInstructionBuilder(). + SetWhirlpoolAccount(whirlpool). + SetPositionAccount(position). + SetTickArrayLowerAccount(tickArrayLower). + SetTickArrayUpperAccount(tickArrayUpper) +} diff --git a/programs/whirlpool/UpdateFeesAndRewards_test.go b/programs/whirlpool/UpdateFeesAndRewards_test.go new file mode 100644 index 00000000..97dae8e9 --- /dev/null +++ b/programs/whirlpool/UpdateFeesAndRewards_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_UpdateFeesAndRewards(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("UpdateFeesAndRewards"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(UpdateFeesAndRewards) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(UpdateFeesAndRewards) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/accounts.go b/programs/whirlpool/accounts.go new file mode 100644 index 00000000..240678c7 --- /dev/null +++ b/programs/whirlpool/accounts.go @@ -0,0 +1,646 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "fmt" + ag_binary "github.com/gagliardetto/binary" + ag_solanago "github.com/gagliardetto/solana-go" +) + +type WhirlpoolsConfig struct { + FeeAuthority ag_solanago.PublicKey + CollectProtocolFeesAuthority ag_solanago.PublicKey + RewardEmissionsSuperAuthority ag_solanago.PublicKey + DefaultProtocolFeeRate uint16 +} + +var WhirlpoolsConfigDiscriminator = [8]byte{157, 20, 49, 224, 217, 87, 193, 254} + +func (obj WhirlpoolsConfig) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Write account discriminator: + err = encoder.WriteBytes(WhirlpoolsConfigDiscriminator[:], false) + if err != nil { + return err + } + // Serialize `FeeAuthority` param: + err = encoder.Encode(obj.FeeAuthority) + if err != nil { + return err + } + // Serialize `CollectProtocolFeesAuthority` param: + err = encoder.Encode(obj.CollectProtocolFeesAuthority) + if err != nil { + return err + } + // Serialize `RewardEmissionsSuperAuthority` param: + err = encoder.Encode(obj.RewardEmissionsSuperAuthority) + if err != nil { + return err + } + // Serialize `DefaultProtocolFeeRate` param: + err = encoder.Encode(obj.DefaultProtocolFeeRate) + if err != nil { + return err + } + return nil +} + +func (obj *WhirlpoolsConfig) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Read and check account discriminator: + { + discriminator, err := decoder.ReadTypeID() + if err != nil { + return err + } + if !discriminator.Equal(WhirlpoolsConfigDiscriminator[:]) { + return fmt.Errorf( + "wrong discriminator: wanted %s, got %s", + "[157 20 49 224 217 87 193 254]", + fmt.Sprint(discriminator[:])) + } + } + // Deserialize `FeeAuthority`: + err = decoder.Decode(&obj.FeeAuthority) + if err != nil { + return err + } + // Deserialize `CollectProtocolFeesAuthority`: + err = decoder.Decode(&obj.CollectProtocolFeesAuthority) + if err != nil { + return err + } + // Deserialize `RewardEmissionsSuperAuthority`: + err = decoder.Decode(&obj.RewardEmissionsSuperAuthority) + if err != nil { + return err + } + // Deserialize `DefaultProtocolFeeRate`: + err = decoder.Decode(&obj.DefaultProtocolFeeRate) + if err != nil { + return err + } + return nil +} + +type FeeTier struct { + WhirlpoolsConfig ag_solanago.PublicKey + TickSpacing uint16 + DefaultFeeRate uint16 +} + +var FeeTierDiscriminator = [8]byte{56, 75, 159, 76, 142, 68, 190, 105} + +func (obj FeeTier) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Write account discriminator: + err = encoder.WriteBytes(FeeTierDiscriminator[:], false) + if err != nil { + return err + } + // Serialize `WhirlpoolsConfig` param: + err = encoder.Encode(obj.WhirlpoolsConfig) + if err != nil { + return err + } + // Serialize `TickSpacing` param: + err = encoder.Encode(obj.TickSpacing) + if err != nil { + return err + } + // Serialize `DefaultFeeRate` param: + err = encoder.Encode(obj.DefaultFeeRate) + if err != nil { + return err + } + return nil +} + +func (obj *FeeTier) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Read and check account discriminator: + { + discriminator, err := decoder.ReadTypeID() + if err != nil { + return err + } + if !discriminator.Equal(FeeTierDiscriminator[:]) { + return fmt.Errorf( + "wrong discriminator: wanted %s, got %s", + "[56 75 159 76 142 68 190 105]", + fmt.Sprint(discriminator[:])) + } + } + // Deserialize `WhirlpoolsConfig`: + err = decoder.Decode(&obj.WhirlpoolsConfig) + if err != nil { + return err + } + // Deserialize `TickSpacing`: + err = decoder.Decode(&obj.TickSpacing) + if err != nil { + return err + } + // Deserialize `DefaultFeeRate`: + err = decoder.Decode(&obj.DefaultFeeRate) + if err != nil { + return err + } + return nil +} + +type PositionBundle struct { + PositionBundleMint ag_solanago.PublicKey + PositionBitmap [32]uint8 +} + +var PositionBundleDiscriminator = [8]byte{129, 169, 175, 65, 185, 95, 32, 100} + +func (obj PositionBundle) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Write account discriminator: + err = encoder.WriteBytes(PositionBundleDiscriminator[:], false) + if err != nil { + return err + } + // Serialize `PositionBundleMint` param: + err = encoder.Encode(obj.PositionBundleMint) + if err != nil { + return err + } + // Serialize `PositionBitmap` param: + err = encoder.Encode(obj.PositionBitmap) + if err != nil { + return err + } + return nil +} + +func (obj *PositionBundle) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Read and check account discriminator: + { + discriminator, err := decoder.ReadTypeID() + if err != nil { + return err + } + if !discriminator.Equal(PositionBundleDiscriminator[:]) { + return fmt.Errorf( + "wrong discriminator: wanted %s, got %s", + "[129 169 175 65 185 95 32 100]", + fmt.Sprint(discriminator[:])) + } + } + // Deserialize `PositionBundleMint`: + err = decoder.Decode(&obj.PositionBundleMint) + if err != nil { + return err + } + // Deserialize `PositionBitmap`: + err = decoder.Decode(&obj.PositionBitmap) + if err != nil { + return err + } + return nil +} + +type Position struct { + Whirlpool ag_solanago.PublicKey + PositionMint ag_solanago.PublicKey + Liquidity ag_binary.Uint128 + TickLowerIndex int32 + TickUpperIndex int32 + FeeGrowthCheckpointA ag_binary.Uint128 + FeeOwedA uint64 + FeeGrowthCheckpointB ag_binary.Uint128 + FeeOwedB uint64 + RewardInfos [3]PositionRewardInfo +} + +var PositionDiscriminator = [8]byte{170, 188, 143, 228, 122, 64, 247, 208} + +func (obj Position) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Write account discriminator: + err = encoder.WriteBytes(PositionDiscriminator[:], false) + if err != nil { + return err + } + // Serialize `Whirlpool` param: + err = encoder.Encode(obj.Whirlpool) + if err != nil { + return err + } + // Serialize `PositionMint` param: + err = encoder.Encode(obj.PositionMint) + if err != nil { + return err + } + // Serialize `Liquidity` param: + err = encoder.Encode(obj.Liquidity) + if err != nil { + return err + } + // Serialize `TickLowerIndex` param: + err = encoder.Encode(obj.TickLowerIndex) + if err != nil { + return err + } + // Serialize `TickUpperIndex` param: + err = encoder.Encode(obj.TickUpperIndex) + if err != nil { + return err + } + // Serialize `FeeGrowthCheckpointA` param: + err = encoder.Encode(obj.FeeGrowthCheckpointA) + if err != nil { + return err + } + // Serialize `FeeOwedA` param: + err = encoder.Encode(obj.FeeOwedA) + if err != nil { + return err + } + // Serialize `FeeGrowthCheckpointB` param: + err = encoder.Encode(obj.FeeGrowthCheckpointB) + if err != nil { + return err + } + // Serialize `FeeOwedB` param: + err = encoder.Encode(obj.FeeOwedB) + if err != nil { + return err + } + // Serialize `RewardInfos` param: + err = encoder.Encode(obj.RewardInfos) + if err != nil { + return err + } + return nil +} + +func (obj *Position) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Read and check account discriminator: + { + discriminator, err := decoder.ReadTypeID() + if err != nil { + return err + } + if !discriminator.Equal(PositionDiscriminator[:]) { + return fmt.Errorf( + "wrong discriminator: wanted %s, got %s", + "[170 188 143 228 122 64 247 208]", + fmt.Sprint(discriminator[:])) + } + } + // Deserialize `Whirlpool`: + err = decoder.Decode(&obj.Whirlpool) + if err != nil { + return err + } + // Deserialize `PositionMint`: + err = decoder.Decode(&obj.PositionMint) + if err != nil { + return err + } + // Deserialize `Liquidity`: + err = decoder.Decode(&obj.Liquidity) + if err != nil { + return err + } + // Deserialize `TickLowerIndex`: + err = decoder.Decode(&obj.TickLowerIndex) + if err != nil { + return err + } + // Deserialize `TickUpperIndex`: + err = decoder.Decode(&obj.TickUpperIndex) + if err != nil { + return err + } + // Deserialize `FeeGrowthCheckpointA`: + err = decoder.Decode(&obj.FeeGrowthCheckpointA) + if err != nil { + return err + } + // Deserialize `FeeOwedA`: + err = decoder.Decode(&obj.FeeOwedA) + if err != nil { + return err + } + // Deserialize `FeeGrowthCheckpointB`: + err = decoder.Decode(&obj.FeeGrowthCheckpointB) + if err != nil { + return err + } + // Deserialize `FeeOwedB`: + err = decoder.Decode(&obj.FeeOwedB) + if err != nil { + return err + } + // Deserialize `RewardInfos`: + err = decoder.Decode(&obj.RewardInfos) + if err != nil { + return err + } + return nil +} + +type TickArray struct { + StartTickIndex int32 + Ticks [88]Tick + Whirlpool ag_solanago.PublicKey +} + +var TickArrayDiscriminator = [8]byte{69, 97, 189, 190, 110, 7, 66, 187} + +func (obj TickArray) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Write account discriminator: + err = encoder.WriteBytes(TickArrayDiscriminator[:], false) + if err != nil { + return err + } + // Serialize `StartTickIndex` param: + err = encoder.Encode(obj.StartTickIndex) + if err != nil { + return err + } + // Serialize `Ticks` param: + err = encoder.Encode(obj.Ticks) + if err != nil { + return err + } + // Serialize `Whirlpool` param: + err = encoder.Encode(obj.Whirlpool) + if err != nil { + return err + } + return nil +} + +func (obj *TickArray) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Read and check account discriminator: + { + discriminator, err := decoder.ReadTypeID() + if err != nil { + return err + } + if !discriminator.Equal(TickArrayDiscriminator[:]) { + return fmt.Errorf( + "wrong discriminator: wanted %s, got %s", + "[69 97 189 190 110 7 66 187]", + fmt.Sprint(discriminator[:])) + } + } + // Deserialize `StartTickIndex`: + err = decoder.Decode(&obj.StartTickIndex) + if err != nil { + return err + } + // Deserialize `Ticks`: + err = decoder.Decode(&obj.Ticks) + if err != nil { + return err + } + // Deserialize `Whirlpool`: + err = decoder.Decode(&obj.Whirlpool) + if err != nil { + return err + } + return nil +} + +type Whirlpool struct { + WhirlpoolsConfig ag_solanago.PublicKey + WhirlpoolBump [1]uint8 + TickSpacing uint16 + TickSpacingSeed [2]uint8 + FeeRate uint16 + ProtocolFeeRate uint16 + Liquidity ag_binary.Uint128 + SqrtPrice ag_binary.Uint128 + TickCurrentIndex int32 + ProtocolFeeOwedA uint64 + ProtocolFeeOwedB uint64 + TokenMintA ag_solanago.PublicKey + TokenVaultA ag_solanago.PublicKey + FeeGrowthGlobalA ag_binary.Uint128 + TokenMintB ag_solanago.PublicKey + TokenVaultB ag_solanago.PublicKey + FeeGrowthGlobalB ag_binary.Uint128 + RewardLastUpdatedTimestamp uint64 + RewardInfos [3]WhirlpoolRewardInfo +} + +var WhirlpoolDiscriminator = [8]byte{63, 149, 209, 12, 225, 128, 99, 9} + +func (obj Whirlpool) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Write account discriminator: + err = encoder.WriteBytes(WhirlpoolDiscriminator[:], false) + if err != nil { + return err + } + // Serialize `WhirlpoolsConfig` param: + err = encoder.Encode(obj.WhirlpoolsConfig) + if err != nil { + return err + } + // Serialize `WhirlpoolBump` param: + err = encoder.Encode(obj.WhirlpoolBump) + if err != nil { + return err + } + // Serialize `TickSpacing` param: + err = encoder.Encode(obj.TickSpacing) + if err != nil { + return err + } + // Serialize `TickSpacingSeed` param: + err = encoder.Encode(obj.TickSpacingSeed) + if err != nil { + return err + } + // Serialize `FeeRate` param: + err = encoder.Encode(obj.FeeRate) + if err != nil { + return err + } + // Serialize `ProtocolFeeRate` param: + err = encoder.Encode(obj.ProtocolFeeRate) + if err != nil { + return err + } + // Serialize `Liquidity` param: + err = encoder.Encode(obj.Liquidity) + if err != nil { + return err + } + // Serialize `SqrtPrice` param: + err = encoder.Encode(obj.SqrtPrice) + if err != nil { + return err + } + // Serialize `TickCurrentIndex` param: + err = encoder.Encode(obj.TickCurrentIndex) + if err != nil { + return err + } + // Serialize `ProtocolFeeOwedA` param: + err = encoder.Encode(obj.ProtocolFeeOwedA) + if err != nil { + return err + } + // Serialize `ProtocolFeeOwedB` param: + err = encoder.Encode(obj.ProtocolFeeOwedB) + if err != nil { + return err + } + // Serialize `TokenMintA` param: + err = encoder.Encode(obj.TokenMintA) + if err != nil { + return err + } + // Serialize `TokenVaultA` param: + err = encoder.Encode(obj.TokenVaultA) + if err != nil { + return err + } + // Serialize `FeeGrowthGlobalA` param: + err = encoder.Encode(obj.FeeGrowthGlobalA) + if err != nil { + return err + } + // Serialize `TokenMintB` param: + err = encoder.Encode(obj.TokenMintB) + if err != nil { + return err + } + // Serialize `TokenVaultB` param: + err = encoder.Encode(obj.TokenVaultB) + if err != nil { + return err + } + // Serialize `FeeGrowthGlobalB` param: + err = encoder.Encode(obj.FeeGrowthGlobalB) + if err != nil { + return err + } + // Serialize `RewardLastUpdatedTimestamp` param: + err = encoder.Encode(obj.RewardLastUpdatedTimestamp) + if err != nil { + return err + } + // Serialize `RewardInfos` param: + err = encoder.Encode(obj.RewardInfos) + if err != nil { + return err + } + return nil +} + +func (obj *Whirlpool) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Read and check account discriminator: + { + discriminator, err := decoder.ReadTypeID() + if err != nil { + return err + } + if !discriminator.Equal(WhirlpoolDiscriminator[:]) { + return fmt.Errorf( + "wrong discriminator: wanted %s, got %s", + "[63 149 209 12 225 128 99 9]", + fmt.Sprint(discriminator[:])) + } + } + // Deserialize `WhirlpoolsConfig`: + err = decoder.Decode(&obj.WhirlpoolsConfig) + if err != nil { + return err + } + // Deserialize `WhirlpoolBump`: + err = decoder.Decode(&obj.WhirlpoolBump) + if err != nil { + return err + } + // Deserialize `TickSpacing`: + err = decoder.Decode(&obj.TickSpacing) + if err != nil { + return err + } + // Deserialize `TickSpacingSeed`: + err = decoder.Decode(&obj.TickSpacingSeed) + if err != nil { + return err + } + // Deserialize `FeeRate`: + err = decoder.Decode(&obj.FeeRate) + if err != nil { + return err + } + // Deserialize `ProtocolFeeRate`: + err = decoder.Decode(&obj.ProtocolFeeRate) + if err != nil { + return err + } + // Deserialize `Liquidity`: + err = decoder.Decode(&obj.Liquidity) + if err != nil { + return err + } + // Deserialize `SqrtPrice`: + err = decoder.Decode(&obj.SqrtPrice) + if err != nil { + return err + } + // Deserialize `TickCurrentIndex`: + err = decoder.Decode(&obj.TickCurrentIndex) + if err != nil { + return err + } + // Deserialize `ProtocolFeeOwedA`: + err = decoder.Decode(&obj.ProtocolFeeOwedA) + if err != nil { + return err + } + // Deserialize `ProtocolFeeOwedB`: + err = decoder.Decode(&obj.ProtocolFeeOwedB) + if err != nil { + return err + } + // Deserialize `TokenMintA`: + err = decoder.Decode(&obj.TokenMintA) + if err != nil { + return err + } + // Deserialize `TokenVaultA`: + err = decoder.Decode(&obj.TokenVaultA) + if err != nil { + return err + } + // Deserialize `FeeGrowthGlobalA`: + err = decoder.Decode(&obj.FeeGrowthGlobalA) + if err != nil { + return err + } + // Deserialize `TokenMintB`: + err = decoder.Decode(&obj.TokenMintB) + if err != nil { + return err + } + // Deserialize `TokenVaultB`: + err = decoder.Decode(&obj.TokenVaultB) + if err != nil { + return err + } + // Deserialize `FeeGrowthGlobalB`: + err = decoder.Decode(&obj.FeeGrowthGlobalB) + if err != nil { + return err + } + // Deserialize `RewardLastUpdatedTimestamp`: + err = decoder.Decode(&obj.RewardLastUpdatedTimestamp) + if err != nil { + return err + } + // Deserialize `RewardInfos`: + err = decoder.Decode(&obj.RewardInfos) + if err != nil { + return err + } + return nil +} diff --git a/programs/whirlpool/instructions.go b/programs/whirlpool/instructions.go new file mode 100644 index 00000000..531831c1 --- /dev/null +++ b/programs/whirlpool/instructions.go @@ -0,0 +1,327 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +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}) + + Instruction_TwoHopSwap = ag_binary.TypeID([8]byte{195, 96, 237, 108, 68, 162, 219, 230}) + + Instruction_InitializePositionBundle = ag_binary.TypeID([8]byte{117, 45, 241, 149, 24, 18, 194, 65}) + + Instruction_InitializePositionBundleWithMetadata = ag_binary.TypeID([8]byte{93, 124, 16, 179, 249, 131, 115, 245}) + + Instruction_DeletePositionBundle = ag_binary.TypeID([8]byte{100, 25, 99, 2, 217, 239, 124, 173}) + + Instruction_OpenBundledPosition = ag_binary.TypeID([8]byte{169, 113, 126, 171, 213, 172, 212, 49}) + + Instruction_CloseBundledPosition = ag_binary.TypeID([8]byte{41, 36, 216, 245, 27, 85, 103, 67}) +) + +// 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" + case Instruction_TwoHopSwap: + return "TwoHopSwap" + case Instruction_InitializePositionBundle: + return "InitializePositionBundle" + case Instruction_InitializePositionBundleWithMetadata: + return "InitializePositionBundleWithMetadata" + case Instruction_DeletePositionBundle: + return "DeletePositionBundle" + case Instruction_OpenBundledPosition: + return "OpenBundledPosition" + case Instruction_CloseBundledPosition: + return "CloseBundledPosition" + 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), + }, + { + "two_hop_swap", (*TwoHopSwap)(nil), + }, + { + "initialize_position_bundle", (*InitializePositionBundle)(nil), + }, + { + "initialize_position_bundle_with_metadata", (*InitializePositionBundleWithMetadata)(nil), + }, + { + "delete_position_bundle", (*DeletePositionBundle)(nil), + }, + { + "open_bundled_position", (*OpenBundledPosition)(nil), + }, + { + "close_bundled_position", (*CloseBundledPosition)(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 +} diff --git a/programs/whirlpool/testing_utils.go b/programs/whirlpool/testing_utils.go new file mode 100644 index 00000000..b19f0534 --- /dev/null +++ b/programs/whirlpool/testing_utils.go @@ -0,0 +1,20 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + "bytes" + "fmt" + ag_binary "github.com/gagliardetto/binary" +) + +func encodeT(data interface{}, buf *bytes.Buffer) error { + if err := ag_binary.NewBorshEncoder(buf).Encode(data); err != nil { + return fmt.Errorf("unable to encode instruction: %w", err) + } + return nil +} + +func decodeT(dst interface{}, data []byte) error { + return ag_binary.NewBorshDecoder(data).Decode(dst) +} diff --git a/programs/whirlpool/types.go b/programs/whirlpool/types.go new file mode 100644 index 00000000..6eaf0e82 --- /dev/null +++ b/programs/whirlpool/types.go @@ -0,0 +1,318 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package generated + +import ( + ag_binary "github.com/gagliardetto/binary" + ag_solanago "github.com/gagliardetto/solana-go" +) + +type OpenPositionBumps struct { + PositionBump uint8 +} + +func (obj OpenPositionBumps) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `PositionBump` param: + err = encoder.Encode(obj.PositionBump) + if err != nil { + return err + } + return nil +} + +func (obj *OpenPositionBumps) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `PositionBump`: + err = decoder.Decode(&obj.PositionBump) + if err != nil { + return err + } + return nil +} + +type OpenPositionWithMetadataBumps struct { + PositionBump uint8 + MetadataBump uint8 +} + +func (obj OpenPositionWithMetadataBumps) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `PositionBump` param: + err = encoder.Encode(obj.PositionBump) + if err != nil { + return err + } + // Serialize `MetadataBump` param: + err = encoder.Encode(obj.MetadataBump) + if err != nil { + return err + } + return nil +} + +func (obj *OpenPositionWithMetadataBumps) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `PositionBump`: + err = decoder.Decode(&obj.PositionBump) + if err != nil { + return err + } + // Deserialize `MetadataBump`: + err = decoder.Decode(&obj.MetadataBump) + if err != nil { + return err + } + return nil +} + +type PositionRewardInfo struct { + GrowthInsideCheckpoint ag_binary.Uint128 + AmountOwed uint64 +} + +func (obj PositionRewardInfo) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `GrowthInsideCheckpoint` param: + err = encoder.Encode(obj.GrowthInsideCheckpoint) + if err != nil { + return err + } + // Serialize `AmountOwed` param: + err = encoder.Encode(obj.AmountOwed) + if err != nil { + return err + } + return nil +} + +func (obj *PositionRewardInfo) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `GrowthInsideCheckpoint`: + err = decoder.Decode(&obj.GrowthInsideCheckpoint) + if err != nil { + return err + } + // Deserialize `AmountOwed`: + err = decoder.Decode(&obj.AmountOwed) + if err != nil { + return err + } + return nil +} + +type Tick struct { + Initialized bool + LiquidityNet ag_binary.Int128 + LiquidityGross ag_binary.Uint128 + FeeGrowthOutsideA ag_binary.Uint128 + FeeGrowthOutsideB ag_binary.Uint128 + RewardGrowthsOutside [3]ag_binary.Uint128 +} + +func (obj Tick) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Initialized` param: + err = encoder.Encode(obj.Initialized) + if err != nil { + return err + } + // Serialize `LiquidityNet` param: + err = encoder.Encode(obj.LiquidityNet) + if err != nil { + return err + } + // Serialize `LiquidityGross` param: + err = encoder.Encode(obj.LiquidityGross) + if err != nil { + return err + } + // Serialize `FeeGrowthOutsideA` param: + err = encoder.Encode(obj.FeeGrowthOutsideA) + if err != nil { + return err + } + // Serialize `FeeGrowthOutsideB` param: + err = encoder.Encode(obj.FeeGrowthOutsideB) + if err != nil { + return err + } + // Serialize `RewardGrowthsOutside` param: + err = encoder.Encode(obj.RewardGrowthsOutside) + if err != nil { + return err + } + return nil +} + +func (obj *Tick) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Initialized`: + err = decoder.Decode(&obj.Initialized) + if err != nil { + return err + } + // Deserialize `LiquidityNet`: + err = decoder.Decode(&obj.LiquidityNet) + if err != nil { + return err + } + // Deserialize `LiquidityGross`: + err = decoder.Decode(&obj.LiquidityGross) + if err != nil { + return err + } + // Deserialize `FeeGrowthOutsideA`: + err = decoder.Decode(&obj.FeeGrowthOutsideA) + if err != nil { + return err + } + // Deserialize `FeeGrowthOutsideB`: + err = decoder.Decode(&obj.FeeGrowthOutsideB) + if err != nil { + return err + } + // Deserialize `RewardGrowthsOutside`: + err = decoder.Decode(&obj.RewardGrowthsOutside) + if err != nil { + return err + } + return nil +} + +type WhirlpoolRewardInfo struct { + Mint ag_solanago.PublicKey + Vault ag_solanago.PublicKey + Authority ag_solanago.PublicKey + EmissionsPerSecondX64 ag_binary.Uint128 + GrowthGlobalX64 ag_binary.Uint128 +} + +func (obj WhirlpoolRewardInfo) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Mint` param: + err = encoder.Encode(obj.Mint) + if err != nil { + return err + } + // Serialize `Vault` param: + err = encoder.Encode(obj.Vault) + if err != nil { + return err + } + // Serialize `Authority` param: + err = encoder.Encode(obj.Authority) + if err != nil { + return err + } + // Serialize `EmissionsPerSecondX64` param: + err = encoder.Encode(obj.EmissionsPerSecondX64) + if err != nil { + return err + } + // Serialize `GrowthGlobalX64` param: + err = encoder.Encode(obj.GrowthGlobalX64) + if err != nil { + return err + } + return nil +} + +func (obj *WhirlpoolRewardInfo) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Mint`: + err = decoder.Decode(&obj.Mint) + if err != nil { + return err + } + // Deserialize `Vault`: + err = decoder.Decode(&obj.Vault) + if err != nil { + return err + } + // Deserialize `Authority`: + err = decoder.Decode(&obj.Authority) + if err != nil { + return err + } + // Deserialize `EmissionsPerSecondX64`: + err = decoder.Decode(&obj.EmissionsPerSecondX64) + if err != nil { + return err + } + // Deserialize `GrowthGlobalX64`: + err = decoder.Decode(&obj.GrowthGlobalX64) + if err != nil { + return err + } + return nil +} + +type WhirlpoolBumps struct { + WhirlpoolBump uint8 +} + +func (obj WhirlpoolBumps) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `WhirlpoolBump` param: + err = encoder.Encode(obj.WhirlpoolBump) + if err != nil { + return err + } + return nil +} + +func (obj *WhirlpoolBumps) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `WhirlpoolBump`: + err = decoder.Decode(&obj.WhirlpoolBump) + if err != nil { + return err + } + return nil +} + +type CurrIndex ag_binary.BorshEnum + +const ( + CurrIndexBelow CurrIndex = iota + CurrIndexInside + CurrIndexAbove +) + +func (value CurrIndex) String() string { + switch value { + case CurrIndexBelow: + return "Below" + case CurrIndexInside: + return "Inside" + case CurrIndexAbove: + return "Above" + default: + return "" + } +} + +type TickLabel ag_binary.BorshEnum + +const ( + TickLabelUpper TickLabel = iota + TickLabelLower +) + +func (value TickLabel) String() string { + switch value { + case TickLabelUpper: + return "Upper" + case TickLabelLower: + return "Lower" + default: + return "" + } +} + +type Direction ag_binary.BorshEnum + +const ( + DirectionLeft Direction = iota + DirectionRight +) + +func (value Direction) String() string { + switch value { + case DirectionLeft: + return "Left" + case DirectionRight: + return "Right" + default: + return "" + } +} From f5910a6050768b02dadb788a78688c84b8cedea1 Mon Sep 17 00:00:00 2001 From: egaotan Date: Thu, 23 Jan 2025 17:33:10 +0800 Subject: [PATCH 2/6] update --- programs/whirlpool/CloseBundledPosition.go | 2 +- .../whirlpool/CloseBundledPosition_test.go | 2 +- programs/whirlpool/ClosePosition.go | 2 +- programs/whirlpool/ClosePosition_test.go | 2 +- programs/whirlpool/CollectFees.go | 2 +- programs/whirlpool/CollectFeesV2.go | 373 +++++++++ programs/whirlpool/CollectFeesV2_test.go | 32 + programs/whirlpool/CollectFees_test.go | 2 +- programs/whirlpool/CollectProtocolFees.go | 2 +- programs/whirlpool/CollectProtocolFeesV2.go | 354 +++++++++ .../whirlpool/CollectProtocolFeesV2_test.go | 32 + .../whirlpool/CollectProtocolFees_test.go | 2 +- programs/whirlpool/CollectReward.go | 2 +- programs/whirlpool/CollectRewardV2.go | 320 ++++++++ programs/whirlpool/CollectRewardV2_test.go | 32 + programs/whirlpool/CollectReward_test.go | 2 +- programs/whirlpool/DecreaseLiquidity.go | 2 +- programs/whirlpool/DecreaseLiquidityV2.go | 480 +++++++++++ .../whirlpool/DecreaseLiquidityV2_test.go | 32 + programs/whirlpool/DecreaseLiquidity_test.go | 2 +- programs/whirlpool/DeletePositionBundle.go | 2 +- .../whirlpool/DeletePositionBundle_test.go | 2 +- programs/whirlpool/DeleteTokenBadge.go | 193 +++++ programs/whirlpool/DeleteTokenBadge_test.go | 32 + programs/whirlpool/IncreaseLiquidity.go | 2 +- programs/whirlpool/IncreaseLiquidityV2.go | 480 +++++++++++ .../whirlpool/IncreaseLiquidityV2_test.go | 32 + programs/whirlpool/IncreaseLiquidity_test.go | 2 +- programs/whirlpool/InitializeConfig.go | 2 +- .../whirlpool/InitializeConfigExtension.go | 174 ++++ .../InitializeConfigExtension_test.go | 32 + programs/whirlpool/InitializeConfig_test.go | 2 +- programs/whirlpool/InitializeFeeTier.go | 2 +- programs/whirlpool/InitializeFeeTier_test.go | 2 +- programs/whirlpool/InitializePool.go | 2 +- programs/whirlpool/InitializePoolV2.go | 397 ++++++++++ programs/whirlpool/InitializePoolV2_test.go | 32 + programs/whirlpool/InitializePool_test.go | 2 +- .../whirlpool/InitializePositionBundle.go | 2 +- .../InitializePositionBundleWithMetadata.go | 2 +- ...itializePositionBundleWithMetadata_test.go | 2 +- .../InitializePositionBundle_test.go | 2 +- programs/whirlpool/InitializeReward.go | 2 +- programs/whirlpool/InitializeRewardV2.go | 279 +++++++ programs/whirlpool/InitializeRewardV2_test.go | 32 + programs/whirlpool/InitializeReward_test.go | 2 +- programs/whirlpool/InitializeTickArray.go | 2 +- .../whirlpool/InitializeTickArray_test.go | 2 +- programs/whirlpool/InitializeTokenBadge.go | 212 +++++ .../whirlpool/InitializeTokenBadge_test.go | 32 + programs/whirlpool/OpenBundledPosition.go | 2 +- .../whirlpool/OpenBundledPosition_test.go | 2 +- programs/whirlpool/OpenPosition.go | 2 +- .../whirlpool/OpenPositionWithMetadata.go | 2 +- .../OpenPositionWithMetadata_test.go | 2 +- programs/whirlpool/OpenPosition_test.go | 2 +- .../SetCollectProtocolFeesAuthority.go | 2 +- .../SetCollectProtocolFeesAuthority_test.go | 2 +- .../whirlpool/SetConfigExtensionAuthority.go | 155 ++++ .../SetConfigExtensionAuthority_test.go | 32 + programs/whirlpool/SetDefaultFeeRate.go | 2 +- programs/whirlpool/SetDefaultFeeRate_test.go | 2 +- .../whirlpool/SetDefaultProtocolFeeRate.go | 2 +- .../SetDefaultProtocolFeeRate_test.go | 2 +- programs/whirlpool/SetFeeAuthority.go | 2 +- programs/whirlpool/SetFeeAuthority_test.go | 2 +- programs/whirlpool/SetFeeRate.go | 2 +- programs/whirlpool/SetFeeRate_test.go | 2 +- programs/whirlpool/SetProtocolFeeRate.go | 2 +- programs/whirlpool/SetProtocolFeeRate_test.go | 2 +- programs/whirlpool/SetRewardAuthority.go | 2 +- .../SetRewardAuthorityBySuperAuthority.go | 2 +- ...SetRewardAuthorityBySuperAuthority_test.go | 2 +- programs/whirlpool/SetRewardAuthority_test.go | 2 +- programs/whirlpool/SetRewardEmissions.go | 2 +- .../SetRewardEmissionsSuperAuthority.go | 2 +- .../SetRewardEmissionsSuperAuthority_test.go | 2 +- programs/whirlpool/SetRewardEmissionsV2.go | 188 +++++ .../whirlpool/SetRewardEmissionsV2_test.go | 32 + programs/whirlpool/SetRewardEmissions_test.go | 2 +- programs/whirlpool/SetTokenBadgeAuthority.go | 155 ++++ .../whirlpool/SetTokenBadgeAuthority_test.go | 32 + programs/whirlpool/Swap.go | 2 +- programs/whirlpool/SwapV2.go | 526 +++++++++++++ programs/whirlpool/SwapV2_test.go | 32 + programs/whirlpool/Swap_test.go | 2 +- programs/whirlpool/TwoHopSwap.go | 2 +- programs/whirlpool/TwoHopSwapV2.go | 743 ++++++++++++++++++ programs/whirlpool/TwoHopSwapV2_test.go | 32 + programs/whirlpool/TwoHopSwap_test.go | 2 +- programs/whirlpool/UpdateFeesAndRewards.go | 2 +- .../whirlpool/UpdateFeesAndRewards_test.go | 2 +- programs/whirlpool/accounts.go | 119 ++- programs/whirlpool/instructions.go | 107 ++- programs/whirlpool/testing_utils.go | 2 +- programs/whirlpool/types.go | 96 ++- programs/whirlpool/utils.go | 1 + 97 files changed, 5892 insertions(+), 66 deletions(-) create mode 100644 programs/whirlpool/CollectFeesV2.go create mode 100644 programs/whirlpool/CollectFeesV2_test.go create mode 100644 programs/whirlpool/CollectProtocolFeesV2.go create mode 100644 programs/whirlpool/CollectProtocolFeesV2_test.go create mode 100644 programs/whirlpool/CollectRewardV2.go create mode 100644 programs/whirlpool/CollectRewardV2_test.go create mode 100644 programs/whirlpool/DecreaseLiquidityV2.go create mode 100644 programs/whirlpool/DecreaseLiquidityV2_test.go create mode 100644 programs/whirlpool/DeleteTokenBadge.go create mode 100644 programs/whirlpool/DeleteTokenBadge_test.go create mode 100644 programs/whirlpool/IncreaseLiquidityV2.go create mode 100644 programs/whirlpool/IncreaseLiquidityV2_test.go create mode 100644 programs/whirlpool/InitializeConfigExtension.go create mode 100644 programs/whirlpool/InitializeConfigExtension_test.go create mode 100644 programs/whirlpool/InitializePoolV2.go create mode 100644 programs/whirlpool/InitializePoolV2_test.go create mode 100644 programs/whirlpool/InitializeRewardV2.go create mode 100644 programs/whirlpool/InitializeRewardV2_test.go create mode 100644 programs/whirlpool/InitializeTokenBadge.go create mode 100644 programs/whirlpool/InitializeTokenBadge_test.go create mode 100644 programs/whirlpool/SetConfigExtensionAuthority.go create mode 100644 programs/whirlpool/SetConfigExtensionAuthority_test.go create mode 100644 programs/whirlpool/SetRewardEmissionsV2.go create mode 100644 programs/whirlpool/SetRewardEmissionsV2_test.go create mode 100644 programs/whirlpool/SetTokenBadgeAuthority.go create mode 100644 programs/whirlpool/SetTokenBadgeAuthority_test.go create mode 100644 programs/whirlpool/SwapV2.go create mode 100644 programs/whirlpool/SwapV2_test.go create mode 100644 programs/whirlpool/TwoHopSwapV2.go create mode 100644 programs/whirlpool/TwoHopSwapV2_test.go create mode 100644 programs/whirlpool/utils.go diff --git a/programs/whirlpool/CloseBundledPosition.go b/programs/whirlpool/CloseBundledPosition.go index 3fdf723a..a714d5c3 100644 --- a/programs/whirlpool/CloseBundledPosition.go +++ b/programs/whirlpool/CloseBundledPosition.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "errors" diff --git a/programs/whirlpool/CloseBundledPosition_test.go b/programs/whirlpool/CloseBundledPosition_test.go index b4ac2ecb..1d7a39f6 100644 --- a/programs/whirlpool/CloseBundledPosition_test.go +++ b/programs/whirlpool/CloseBundledPosition_test.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "bytes" diff --git a/programs/whirlpool/ClosePosition.go b/programs/whirlpool/ClosePosition.go index afc3e51e..c9fae537 100644 --- a/programs/whirlpool/ClosePosition.go +++ b/programs/whirlpool/ClosePosition.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "errors" diff --git a/programs/whirlpool/ClosePosition_test.go b/programs/whirlpool/ClosePosition_test.go index 56173093..ffe44eb5 100644 --- a/programs/whirlpool/ClosePosition_test.go +++ b/programs/whirlpool/ClosePosition_test.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "bytes" diff --git a/programs/whirlpool/CollectFees.go b/programs/whirlpool/CollectFees.go index 9343b7b4..3d650b27 100644 --- a/programs/whirlpool/CollectFees.go +++ b/programs/whirlpool/CollectFees.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "errors" diff --git a/programs/whirlpool/CollectFeesV2.go b/programs/whirlpool/CollectFeesV2.go new file mode 100644 index 00000000..0fc7844c --- /dev/null +++ b/programs/whirlpool/CollectFeesV2.go @@ -0,0 +1,373 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package whirlpool + +import ( + "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" +) + +// CollectFeesV2 is the `collectFeesV2` instruction. +type CollectFeesV2 struct { + RemainingAccountsInfo *RemainingAccountsInfo `bin:"optional"` + + // [0] = [] whirlpool + // + // [1] = [SIGNER] positionAuthority + // + // [2] = [WRITE] position + // + // [3] = [] positionTokenAccount + // + // [4] = [] tokenMintA + // + // [5] = [] tokenMintB + // + // [6] = [WRITE] tokenOwnerAccountA + // + // [7] = [WRITE] tokenVaultA + // + // [8] = [WRITE] tokenOwnerAccountB + // + // [9] = [WRITE] tokenVaultB + // + // [10] = [] tokenProgramA + // + // [11] = [] tokenProgramB + // + // [12] = [] memoProgram + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewCollectFeesV2InstructionBuilder creates a new `CollectFeesV2` instruction builder. +func NewCollectFeesV2InstructionBuilder() *CollectFeesV2 { + nd := &CollectFeesV2{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 13), + } + return nd +} + +// SetRemainingAccountsInfo sets the "remainingAccountsInfo" parameter. +func (inst *CollectFeesV2) SetRemainingAccountsInfo(remainingAccountsInfo RemainingAccountsInfo) *CollectFeesV2 { + inst.RemainingAccountsInfo = &remainingAccountsInfo + return inst +} + +// SetWhirlpoolAccount sets the "whirlpool" account. +func (inst *CollectFeesV2) SetWhirlpoolAccount(whirlpool ag_solanago.PublicKey) *CollectFeesV2 { + inst.AccountMetaSlice[0] = ag_solanago.Meta(whirlpool) + return inst +} + +// GetWhirlpoolAccount gets the "whirlpool" account. +func (inst *CollectFeesV2) GetWhirlpoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetPositionAuthorityAccount sets the "positionAuthority" account. +func (inst *CollectFeesV2) SetPositionAuthorityAccount(positionAuthority ag_solanago.PublicKey) *CollectFeesV2 { + inst.AccountMetaSlice[1] = ag_solanago.Meta(positionAuthority).SIGNER() + return inst +} + +// GetPositionAuthorityAccount gets the "positionAuthority" account. +func (inst *CollectFeesV2) GetPositionAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetPositionAccount sets the "position" account. +func (inst *CollectFeesV2) SetPositionAccount(position ag_solanago.PublicKey) *CollectFeesV2 { + inst.AccountMetaSlice[2] = ag_solanago.Meta(position).WRITE() + return inst +} + +// GetPositionAccount gets the "position" account. +func (inst *CollectFeesV2) GetPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetPositionTokenAccountAccount sets the "positionTokenAccount" account. +func (inst *CollectFeesV2) SetPositionTokenAccountAccount(positionTokenAccount ag_solanago.PublicKey) *CollectFeesV2 { + inst.AccountMetaSlice[3] = ag_solanago.Meta(positionTokenAccount) + return inst +} + +// GetPositionTokenAccountAccount gets the "positionTokenAccount" account. +func (inst *CollectFeesV2) GetPositionTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetTokenMintAAccount sets the "tokenMintA" account. +func (inst *CollectFeesV2) SetTokenMintAAccount(tokenMintA ag_solanago.PublicKey) *CollectFeesV2 { + inst.AccountMetaSlice[4] = ag_solanago.Meta(tokenMintA) + return inst +} + +// GetTokenMintAAccount gets the "tokenMintA" account. +func (inst *CollectFeesV2) GetTokenMintAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetTokenMintBAccount sets the "tokenMintB" account. +func (inst *CollectFeesV2) SetTokenMintBAccount(tokenMintB ag_solanago.PublicKey) *CollectFeesV2 { + inst.AccountMetaSlice[5] = ag_solanago.Meta(tokenMintB) + return inst +} + +// GetTokenMintBAccount gets the "tokenMintB" account. +func (inst *CollectFeesV2) GetTokenMintBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetTokenOwnerAccountAAccount sets the "tokenOwnerAccountA" account. +func (inst *CollectFeesV2) SetTokenOwnerAccountAAccount(tokenOwnerAccountA ag_solanago.PublicKey) *CollectFeesV2 { + inst.AccountMetaSlice[6] = ag_solanago.Meta(tokenOwnerAccountA).WRITE() + return inst +} + +// GetTokenOwnerAccountAAccount gets the "tokenOwnerAccountA" account. +func (inst *CollectFeesV2) GetTokenOwnerAccountAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetTokenVaultAAccount sets the "tokenVaultA" account. +func (inst *CollectFeesV2) SetTokenVaultAAccount(tokenVaultA ag_solanago.PublicKey) *CollectFeesV2 { + inst.AccountMetaSlice[7] = ag_solanago.Meta(tokenVaultA).WRITE() + return inst +} + +// GetTokenVaultAAccount gets the "tokenVaultA" account. +func (inst *CollectFeesV2) GetTokenVaultAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetTokenOwnerAccountBAccount sets the "tokenOwnerAccountB" account. +func (inst *CollectFeesV2) SetTokenOwnerAccountBAccount(tokenOwnerAccountB ag_solanago.PublicKey) *CollectFeesV2 { + inst.AccountMetaSlice[8] = ag_solanago.Meta(tokenOwnerAccountB).WRITE() + return inst +} + +// GetTokenOwnerAccountBAccount gets the "tokenOwnerAccountB" account. +func (inst *CollectFeesV2) GetTokenOwnerAccountBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetTokenVaultBAccount sets the "tokenVaultB" account. +func (inst *CollectFeesV2) SetTokenVaultBAccount(tokenVaultB ag_solanago.PublicKey) *CollectFeesV2 { + inst.AccountMetaSlice[9] = ag_solanago.Meta(tokenVaultB).WRITE() + return inst +} + +// GetTokenVaultBAccount gets the "tokenVaultB" account. +func (inst *CollectFeesV2) GetTokenVaultBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetTokenProgramAAccount sets the "tokenProgramA" account. +func (inst *CollectFeesV2) SetTokenProgramAAccount(tokenProgramA ag_solanago.PublicKey) *CollectFeesV2 { + inst.AccountMetaSlice[10] = ag_solanago.Meta(tokenProgramA) + return inst +} + +// GetTokenProgramAAccount gets the "tokenProgramA" account. +func (inst *CollectFeesV2) GetTokenProgramAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetTokenProgramBAccount sets the "tokenProgramB" account. +func (inst *CollectFeesV2) SetTokenProgramBAccount(tokenProgramB ag_solanago.PublicKey) *CollectFeesV2 { + inst.AccountMetaSlice[11] = ag_solanago.Meta(tokenProgramB) + return inst +} + +// GetTokenProgramBAccount gets the "tokenProgramB" account. +func (inst *CollectFeesV2) GetTokenProgramBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetMemoProgramAccount sets the "memoProgram" account. +func (inst *CollectFeesV2) SetMemoProgramAccount(memoProgram ag_solanago.PublicKey) *CollectFeesV2 { + inst.AccountMetaSlice[12] = ag_solanago.Meta(memoProgram) + return inst +} + +// GetMemoProgramAccount gets the "memoProgram" account. +func (inst *CollectFeesV2) GetMemoProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +func (inst CollectFeesV2) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_CollectFeesV2, + }} +} + +// 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 CollectFeesV2) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *CollectFeesV2) Validate() error { + // Check whether all (required) parameters are set: + { + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Whirlpool is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.PositionAuthority is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.Position is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.PositionTokenAccount is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.TokenMintA is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.TokenMintB is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.TokenOwnerAccountA is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.TokenVaultA is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.TokenOwnerAccountB is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.TokenVaultB is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.TokenProgramA is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.TokenProgramB is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.MemoProgram is not set") + } + } + return nil +} + +func (inst *CollectFeesV2) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("CollectFeesV2")). + // + 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("RemainingAccountsInfo (OPT)", inst.RemainingAccountsInfo)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=13]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" whirlpool", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" positionAuthority", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" position", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" positionToken", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" tokenMintA", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" tokenMintB", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta("tokenOwnerAccountA", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" tokenVaultA", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta("tokenOwnerAccountB", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" tokenVaultB", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" tokenProgramA", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" tokenProgramB", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" memoProgram", inst.AccountMetaSlice.Get(12))) + }) + }) + }) +} + +func (obj CollectFeesV2) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `RemainingAccountsInfo` param (optional): + { + if obj.RemainingAccountsInfo == nil { + err = encoder.WriteBool(false) + if err != nil { + return err + } + } else { + err = encoder.WriteBool(true) + if err != nil { + return err + } + err = encoder.Encode(obj.RemainingAccountsInfo) + if err != nil { + return err + } + } + } + return nil +} +func (obj *CollectFeesV2) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `RemainingAccountsInfo` (optional): + { + ok, err := decoder.ReadBool() + if err != nil { + return err + } + if ok { + err = decoder.Decode(&obj.RemainingAccountsInfo) + if err != nil { + return err + } + } + } + return nil +} + +// NewCollectFeesV2Instruction declares a new CollectFeesV2 instruction with the provided parameters and accounts. +func NewCollectFeesV2Instruction( + // Parameters: + remainingAccountsInfo RemainingAccountsInfo, + // Accounts: + whirlpool ag_solanago.PublicKey, + positionAuthority ag_solanago.PublicKey, + position ag_solanago.PublicKey, + positionTokenAccount ag_solanago.PublicKey, + tokenMintA ag_solanago.PublicKey, + tokenMintB ag_solanago.PublicKey, + tokenOwnerAccountA ag_solanago.PublicKey, + tokenVaultA ag_solanago.PublicKey, + tokenOwnerAccountB ag_solanago.PublicKey, + tokenVaultB ag_solanago.PublicKey, + tokenProgramA ag_solanago.PublicKey, + tokenProgramB ag_solanago.PublicKey, + memoProgram ag_solanago.PublicKey) *CollectFeesV2 { + return NewCollectFeesV2InstructionBuilder(). + SetRemainingAccountsInfo(remainingAccountsInfo). + SetWhirlpoolAccount(whirlpool). + SetPositionAuthorityAccount(positionAuthority). + SetPositionAccount(position). + SetPositionTokenAccountAccount(positionTokenAccount). + SetTokenMintAAccount(tokenMintA). + SetTokenMintBAccount(tokenMintB). + SetTokenOwnerAccountAAccount(tokenOwnerAccountA). + SetTokenVaultAAccount(tokenVaultA). + SetTokenOwnerAccountBAccount(tokenOwnerAccountB). + SetTokenVaultBAccount(tokenVaultB). + SetTokenProgramAAccount(tokenProgramA). + SetTokenProgramBAccount(tokenProgramB). + SetMemoProgramAccount(memoProgram) +} diff --git a/programs/whirlpool/CollectFeesV2_test.go b/programs/whirlpool/CollectFeesV2_test.go new file mode 100644 index 00000000..27ce2766 --- /dev/null +++ b/programs/whirlpool/CollectFeesV2_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package whirlpool + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_CollectFeesV2(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("CollectFeesV2"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(CollectFeesV2) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(CollectFeesV2) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/CollectFees_test.go b/programs/whirlpool/CollectFees_test.go index fe7ab3d9..1909fa1f 100644 --- a/programs/whirlpool/CollectFees_test.go +++ b/programs/whirlpool/CollectFees_test.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "bytes" diff --git a/programs/whirlpool/CollectProtocolFees.go b/programs/whirlpool/CollectProtocolFees.go index 90e9d0a9..6074dee3 100644 --- a/programs/whirlpool/CollectProtocolFees.go +++ b/programs/whirlpool/CollectProtocolFees.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "errors" diff --git a/programs/whirlpool/CollectProtocolFeesV2.go b/programs/whirlpool/CollectProtocolFeesV2.go new file mode 100644 index 00000000..59c580ce --- /dev/null +++ b/programs/whirlpool/CollectProtocolFeesV2.go @@ -0,0 +1,354 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package whirlpool + +import ( + "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" +) + +// CollectProtocolFeesV2 is the `collectProtocolFeesV2` instruction. +type CollectProtocolFeesV2 struct { + RemainingAccountsInfo *RemainingAccountsInfo `bin:"optional"` + + // [0] = [] whirlpoolsConfig + // + // [1] = [WRITE] whirlpool + // + // [2] = [SIGNER] collectProtocolFeesAuthority + // + // [3] = [] tokenMintA + // + // [4] = [] tokenMintB + // + // [5] = [WRITE] tokenVaultA + // + // [6] = [WRITE] tokenVaultB + // + // [7] = [WRITE] tokenDestinationA + // + // [8] = [WRITE] tokenDestinationB + // + // [9] = [] tokenProgramA + // + // [10] = [] tokenProgramB + // + // [11] = [] memoProgram + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewCollectProtocolFeesV2InstructionBuilder creates a new `CollectProtocolFeesV2` instruction builder. +func NewCollectProtocolFeesV2InstructionBuilder() *CollectProtocolFeesV2 { + nd := &CollectProtocolFeesV2{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 12), + } + return nd +} + +// SetRemainingAccountsInfo sets the "remainingAccountsInfo" parameter. +func (inst *CollectProtocolFeesV2) SetRemainingAccountsInfo(remainingAccountsInfo RemainingAccountsInfo) *CollectProtocolFeesV2 { + inst.RemainingAccountsInfo = &remainingAccountsInfo + return inst +} + +// SetWhirlpoolsConfigAccount sets the "whirlpoolsConfig" account. +func (inst *CollectProtocolFeesV2) SetWhirlpoolsConfigAccount(whirlpoolsConfig ag_solanago.PublicKey) *CollectProtocolFeesV2 { + inst.AccountMetaSlice[0] = ag_solanago.Meta(whirlpoolsConfig) + return inst +} + +// GetWhirlpoolsConfigAccount gets the "whirlpoolsConfig" account. +func (inst *CollectProtocolFeesV2) GetWhirlpoolsConfigAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetWhirlpoolAccount sets the "whirlpool" account. +func (inst *CollectProtocolFeesV2) SetWhirlpoolAccount(whirlpool ag_solanago.PublicKey) *CollectProtocolFeesV2 { + inst.AccountMetaSlice[1] = ag_solanago.Meta(whirlpool).WRITE() + return inst +} + +// GetWhirlpoolAccount gets the "whirlpool" account. +func (inst *CollectProtocolFeesV2) GetWhirlpoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetCollectProtocolFeesAuthorityAccount sets the "collectProtocolFeesAuthority" account. +func (inst *CollectProtocolFeesV2) SetCollectProtocolFeesAuthorityAccount(collectProtocolFeesAuthority ag_solanago.PublicKey) *CollectProtocolFeesV2 { + inst.AccountMetaSlice[2] = ag_solanago.Meta(collectProtocolFeesAuthority).SIGNER() + return inst +} + +// GetCollectProtocolFeesAuthorityAccount gets the "collectProtocolFeesAuthority" account. +func (inst *CollectProtocolFeesV2) GetCollectProtocolFeesAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetTokenMintAAccount sets the "tokenMintA" account. +func (inst *CollectProtocolFeesV2) SetTokenMintAAccount(tokenMintA ag_solanago.PublicKey) *CollectProtocolFeesV2 { + inst.AccountMetaSlice[3] = ag_solanago.Meta(tokenMintA) + return inst +} + +// GetTokenMintAAccount gets the "tokenMintA" account. +func (inst *CollectProtocolFeesV2) GetTokenMintAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetTokenMintBAccount sets the "tokenMintB" account. +func (inst *CollectProtocolFeesV2) SetTokenMintBAccount(tokenMintB ag_solanago.PublicKey) *CollectProtocolFeesV2 { + inst.AccountMetaSlice[4] = ag_solanago.Meta(tokenMintB) + return inst +} + +// GetTokenMintBAccount gets the "tokenMintB" account. +func (inst *CollectProtocolFeesV2) GetTokenMintBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetTokenVaultAAccount sets the "tokenVaultA" account. +func (inst *CollectProtocolFeesV2) SetTokenVaultAAccount(tokenVaultA ag_solanago.PublicKey) *CollectProtocolFeesV2 { + inst.AccountMetaSlice[5] = ag_solanago.Meta(tokenVaultA).WRITE() + return inst +} + +// GetTokenVaultAAccount gets the "tokenVaultA" account. +func (inst *CollectProtocolFeesV2) GetTokenVaultAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetTokenVaultBAccount sets the "tokenVaultB" account. +func (inst *CollectProtocolFeesV2) SetTokenVaultBAccount(tokenVaultB ag_solanago.PublicKey) *CollectProtocolFeesV2 { + inst.AccountMetaSlice[6] = ag_solanago.Meta(tokenVaultB).WRITE() + return inst +} + +// GetTokenVaultBAccount gets the "tokenVaultB" account. +func (inst *CollectProtocolFeesV2) GetTokenVaultBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetTokenDestinationAAccount sets the "tokenDestinationA" account. +func (inst *CollectProtocolFeesV2) SetTokenDestinationAAccount(tokenDestinationA ag_solanago.PublicKey) *CollectProtocolFeesV2 { + inst.AccountMetaSlice[7] = ag_solanago.Meta(tokenDestinationA).WRITE() + return inst +} + +// GetTokenDestinationAAccount gets the "tokenDestinationA" account. +func (inst *CollectProtocolFeesV2) GetTokenDestinationAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetTokenDestinationBAccount sets the "tokenDestinationB" account. +func (inst *CollectProtocolFeesV2) SetTokenDestinationBAccount(tokenDestinationB ag_solanago.PublicKey) *CollectProtocolFeesV2 { + inst.AccountMetaSlice[8] = ag_solanago.Meta(tokenDestinationB).WRITE() + return inst +} + +// GetTokenDestinationBAccount gets the "tokenDestinationB" account. +func (inst *CollectProtocolFeesV2) GetTokenDestinationBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetTokenProgramAAccount sets the "tokenProgramA" account. +func (inst *CollectProtocolFeesV2) SetTokenProgramAAccount(tokenProgramA ag_solanago.PublicKey) *CollectProtocolFeesV2 { + inst.AccountMetaSlice[9] = ag_solanago.Meta(tokenProgramA) + return inst +} + +// GetTokenProgramAAccount gets the "tokenProgramA" account. +func (inst *CollectProtocolFeesV2) GetTokenProgramAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetTokenProgramBAccount sets the "tokenProgramB" account. +func (inst *CollectProtocolFeesV2) SetTokenProgramBAccount(tokenProgramB ag_solanago.PublicKey) *CollectProtocolFeesV2 { + inst.AccountMetaSlice[10] = ag_solanago.Meta(tokenProgramB) + return inst +} + +// GetTokenProgramBAccount gets the "tokenProgramB" account. +func (inst *CollectProtocolFeesV2) GetTokenProgramBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetMemoProgramAccount sets the "memoProgram" account. +func (inst *CollectProtocolFeesV2) SetMemoProgramAccount(memoProgram ag_solanago.PublicKey) *CollectProtocolFeesV2 { + inst.AccountMetaSlice[11] = ag_solanago.Meta(memoProgram) + return inst +} + +// GetMemoProgramAccount gets the "memoProgram" account. +func (inst *CollectProtocolFeesV2) GetMemoProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +func (inst CollectProtocolFeesV2) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_CollectProtocolFeesV2, + }} +} + +// 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 CollectProtocolFeesV2) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *CollectProtocolFeesV2) Validate() error { + // Check whether all (required) parameters are set: + { + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.WhirlpoolsConfig is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Whirlpool is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.CollectProtocolFeesAuthority is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.TokenMintA is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.TokenMintB is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.TokenVaultA is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.TokenVaultB is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.TokenDestinationA is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.TokenDestinationB is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.TokenProgramA is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.TokenProgramB is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.MemoProgram is not set") + } + } + return nil +} + +func (inst *CollectProtocolFeesV2) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("CollectProtocolFeesV2")). + // + 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("RemainingAccountsInfo (OPT)", inst.RemainingAccountsInfo)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=12]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" whirlpoolsConfig", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" whirlpool", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta("collectProtocolFeesAuthority", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" tokenMintA", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" tokenMintB", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" tokenVaultA", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" tokenVaultB", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" tokenDestinationA", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" tokenDestinationB", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" tokenProgramA", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" tokenProgramB", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" memoProgram", inst.AccountMetaSlice.Get(11))) + }) + }) + }) +} + +func (obj CollectProtocolFeesV2) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `RemainingAccountsInfo` param (optional): + { + if obj.RemainingAccountsInfo == nil { + err = encoder.WriteBool(false) + if err != nil { + return err + } + } else { + err = encoder.WriteBool(true) + if err != nil { + return err + } + err = encoder.Encode(obj.RemainingAccountsInfo) + if err != nil { + return err + } + } + } + return nil +} +func (obj *CollectProtocolFeesV2) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `RemainingAccountsInfo` (optional): + { + ok, err := decoder.ReadBool() + if err != nil { + return err + } + if ok { + err = decoder.Decode(&obj.RemainingAccountsInfo) + if err != nil { + return err + } + } + } + return nil +} + +// NewCollectProtocolFeesV2Instruction declares a new CollectProtocolFeesV2 instruction with the provided parameters and accounts. +func NewCollectProtocolFeesV2Instruction( + // Parameters: + remainingAccountsInfo RemainingAccountsInfo, + // Accounts: + whirlpoolsConfig ag_solanago.PublicKey, + whirlpool ag_solanago.PublicKey, + collectProtocolFeesAuthority ag_solanago.PublicKey, + tokenMintA ag_solanago.PublicKey, + tokenMintB ag_solanago.PublicKey, + tokenVaultA ag_solanago.PublicKey, + tokenVaultB ag_solanago.PublicKey, + tokenDestinationA ag_solanago.PublicKey, + tokenDestinationB ag_solanago.PublicKey, + tokenProgramA ag_solanago.PublicKey, + tokenProgramB ag_solanago.PublicKey, + memoProgram ag_solanago.PublicKey) *CollectProtocolFeesV2 { + return NewCollectProtocolFeesV2InstructionBuilder(). + SetRemainingAccountsInfo(remainingAccountsInfo). + SetWhirlpoolsConfigAccount(whirlpoolsConfig). + SetWhirlpoolAccount(whirlpool). + SetCollectProtocolFeesAuthorityAccount(collectProtocolFeesAuthority). + SetTokenMintAAccount(tokenMintA). + SetTokenMintBAccount(tokenMintB). + SetTokenVaultAAccount(tokenVaultA). + SetTokenVaultBAccount(tokenVaultB). + SetTokenDestinationAAccount(tokenDestinationA). + SetTokenDestinationBAccount(tokenDestinationB). + SetTokenProgramAAccount(tokenProgramA). + SetTokenProgramBAccount(tokenProgramB). + SetMemoProgramAccount(memoProgram) +} diff --git a/programs/whirlpool/CollectProtocolFeesV2_test.go b/programs/whirlpool/CollectProtocolFeesV2_test.go new file mode 100644 index 00000000..a314fc30 --- /dev/null +++ b/programs/whirlpool/CollectProtocolFeesV2_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package whirlpool + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_CollectProtocolFeesV2(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("CollectProtocolFeesV2"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(CollectProtocolFeesV2) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(CollectProtocolFeesV2) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/CollectProtocolFees_test.go b/programs/whirlpool/CollectProtocolFees_test.go index 55160e51..cf7df59d 100644 --- a/programs/whirlpool/CollectProtocolFees_test.go +++ b/programs/whirlpool/CollectProtocolFees_test.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "bytes" diff --git a/programs/whirlpool/CollectReward.go b/programs/whirlpool/CollectReward.go index 983106df..df9bb594 100644 --- a/programs/whirlpool/CollectReward.go +++ b/programs/whirlpool/CollectReward.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "errors" diff --git a/programs/whirlpool/CollectRewardV2.go b/programs/whirlpool/CollectRewardV2.go new file mode 100644 index 00000000..354f05f7 --- /dev/null +++ b/programs/whirlpool/CollectRewardV2.go @@ -0,0 +1,320 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package whirlpool + +import ( + "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" +) + +// CollectRewardV2 is the `collectRewardV2` instruction. +type CollectRewardV2 struct { + RewardIndex *uint8 + RemainingAccountsInfo *RemainingAccountsInfo `bin:"optional"` + + // [0] = [] whirlpool + // + // [1] = [SIGNER] positionAuthority + // + // [2] = [WRITE] position + // + // [3] = [] positionTokenAccount + // + // [4] = [WRITE] rewardOwnerAccount + // + // [5] = [] rewardMint + // + // [6] = [WRITE] rewardVault + // + // [7] = [] rewardTokenProgram + // + // [8] = [] memoProgram + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewCollectRewardV2InstructionBuilder creates a new `CollectRewardV2` instruction builder. +func NewCollectRewardV2InstructionBuilder() *CollectRewardV2 { + nd := &CollectRewardV2{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 9), + } + return nd +} + +// SetRewardIndex sets the "rewardIndex" parameter. +func (inst *CollectRewardV2) SetRewardIndex(rewardIndex uint8) *CollectRewardV2 { + inst.RewardIndex = &rewardIndex + return inst +} + +// SetRemainingAccountsInfo sets the "remainingAccountsInfo" parameter. +func (inst *CollectRewardV2) SetRemainingAccountsInfo(remainingAccountsInfo RemainingAccountsInfo) *CollectRewardV2 { + inst.RemainingAccountsInfo = &remainingAccountsInfo + return inst +} + +// SetWhirlpoolAccount sets the "whirlpool" account. +func (inst *CollectRewardV2) SetWhirlpoolAccount(whirlpool ag_solanago.PublicKey) *CollectRewardV2 { + inst.AccountMetaSlice[0] = ag_solanago.Meta(whirlpool) + return inst +} + +// GetWhirlpoolAccount gets the "whirlpool" account. +func (inst *CollectRewardV2) GetWhirlpoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetPositionAuthorityAccount sets the "positionAuthority" account. +func (inst *CollectRewardV2) SetPositionAuthorityAccount(positionAuthority ag_solanago.PublicKey) *CollectRewardV2 { + inst.AccountMetaSlice[1] = ag_solanago.Meta(positionAuthority).SIGNER() + return inst +} + +// GetPositionAuthorityAccount gets the "positionAuthority" account. +func (inst *CollectRewardV2) GetPositionAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetPositionAccount sets the "position" account. +func (inst *CollectRewardV2) SetPositionAccount(position ag_solanago.PublicKey) *CollectRewardV2 { + inst.AccountMetaSlice[2] = ag_solanago.Meta(position).WRITE() + return inst +} + +// GetPositionAccount gets the "position" account. +func (inst *CollectRewardV2) GetPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetPositionTokenAccountAccount sets the "positionTokenAccount" account. +func (inst *CollectRewardV2) SetPositionTokenAccountAccount(positionTokenAccount ag_solanago.PublicKey) *CollectRewardV2 { + inst.AccountMetaSlice[3] = ag_solanago.Meta(positionTokenAccount) + return inst +} + +// GetPositionTokenAccountAccount gets the "positionTokenAccount" account. +func (inst *CollectRewardV2) GetPositionTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetRewardOwnerAccountAccount sets the "rewardOwnerAccount" account. +func (inst *CollectRewardV2) SetRewardOwnerAccountAccount(rewardOwnerAccount ag_solanago.PublicKey) *CollectRewardV2 { + inst.AccountMetaSlice[4] = ag_solanago.Meta(rewardOwnerAccount).WRITE() + return inst +} + +// GetRewardOwnerAccountAccount gets the "rewardOwnerAccount" account. +func (inst *CollectRewardV2) GetRewardOwnerAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetRewardMintAccount sets the "rewardMint" account. +func (inst *CollectRewardV2) SetRewardMintAccount(rewardMint ag_solanago.PublicKey) *CollectRewardV2 { + inst.AccountMetaSlice[5] = ag_solanago.Meta(rewardMint) + return inst +} + +// GetRewardMintAccount gets the "rewardMint" account. +func (inst *CollectRewardV2) GetRewardMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetRewardVaultAccount sets the "rewardVault" account. +func (inst *CollectRewardV2) SetRewardVaultAccount(rewardVault ag_solanago.PublicKey) *CollectRewardV2 { + inst.AccountMetaSlice[6] = ag_solanago.Meta(rewardVault).WRITE() + return inst +} + +// GetRewardVaultAccount gets the "rewardVault" account. +func (inst *CollectRewardV2) GetRewardVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetRewardTokenProgramAccount sets the "rewardTokenProgram" account. +func (inst *CollectRewardV2) SetRewardTokenProgramAccount(rewardTokenProgram ag_solanago.PublicKey) *CollectRewardV2 { + inst.AccountMetaSlice[7] = ag_solanago.Meta(rewardTokenProgram) + return inst +} + +// GetRewardTokenProgramAccount gets the "rewardTokenProgram" account. +func (inst *CollectRewardV2) GetRewardTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetMemoProgramAccount sets the "memoProgram" account. +func (inst *CollectRewardV2) SetMemoProgramAccount(memoProgram ag_solanago.PublicKey) *CollectRewardV2 { + inst.AccountMetaSlice[8] = ag_solanago.Meta(memoProgram) + return inst +} + +// GetMemoProgramAccount gets the "memoProgram" account. +func (inst *CollectRewardV2) GetMemoProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +func (inst CollectRewardV2) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_CollectRewardV2, + }} +} + +// 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 CollectRewardV2) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *CollectRewardV2) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.RewardIndex == nil { + return errors.New("RewardIndex parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Whirlpool is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.PositionAuthority is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.Position is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.PositionTokenAccount is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.RewardOwnerAccount is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.RewardMint is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.RewardVault is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.RewardTokenProgram is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.MemoProgram is not set") + } + } + return nil +} + +func (inst *CollectRewardV2) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("CollectRewardV2")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=2]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" RewardIndex", *inst.RewardIndex)) + paramsBranch.Child(ag_format.Param("RemainingAccountsInfo (OPT)", inst.RemainingAccountsInfo)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=9]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" whirlpool", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" positionAuthority", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" position", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" positionToken", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" rewardOwner", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" rewardMint", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" rewardVault", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta("rewardTokenProgram", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" memoProgram", inst.AccountMetaSlice.Get(8))) + }) + }) + }) +} + +func (obj CollectRewardV2) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `RewardIndex` param: + err = encoder.Encode(obj.RewardIndex) + if err != nil { + return err + } + // Serialize `RemainingAccountsInfo` param (optional): + { + if obj.RemainingAccountsInfo == nil { + err = encoder.WriteBool(false) + if err != nil { + return err + } + } else { + err = encoder.WriteBool(true) + if err != nil { + return err + } + err = encoder.Encode(obj.RemainingAccountsInfo) + if err != nil { + return err + } + } + } + return nil +} +func (obj *CollectRewardV2) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `RewardIndex`: + err = decoder.Decode(&obj.RewardIndex) + if err != nil { + return err + } + // Deserialize `RemainingAccountsInfo` (optional): + { + ok, err := decoder.ReadBool() + if err != nil { + return err + } + if ok { + err = decoder.Decode(&obj.RemainingAccountsInfo) + if err != nil { + return err + } + } + } + return nil +} + +// NewCollectRewardV2Instruction declares a new CollectRewardV2 instruction with the provided parameters and accounts. +func NewCollectRewardV2Instruction( + // Parameters: + rewardIndex uint8, + remainingAccountsInfo RemainingAccountsInfo, + // Accounts: + whirlpool ag_solanago.PublicKey, + positionAuthority ag_solanago.PublicKey, + position ag_solanago.PublicKey, + positionTokenAccount ag_solanago.PublicKey, + rewardOwnerAccount ag_solanago.PublicKey, + rewardMint ag_solanago.PublicKey, + rewardVault ag_solanago.PublicKey, + rewardTokenProgram ag_solanago.PublicKey, + memoProgram ag_solanago.PublicKey) *CollectRewardV2 { + return NewCollectRewardV2InstructionBuilder(). + SetRewardIndex(rewardIndex). + SetRemainingAccountsInfo(remainingAccountsInfo). + SetWhirlpoolAccount(whirlpool). + SetPositionAuthorityAccount(positionAuthority). + SetPositionAccount(position). + SetPositionTokenAccountAccount(positionTokenAccount). + SetRewardOwnerAccountAccount(rewardOwnerAccount). + SetRewardMintAccount(rewardMint). + SetRewardVaultAccount(rewardVault). + SetRewardTokenProgramAccount(rewardTokenProgram). + SetMemoProgramAccount(memoProgram) +} diff --git a/programs/whirlpool/CollectRewardV2_test.go b/programs/whirlpool/CollectRewardV2_test.go new file mode 100644 index 00000000..705b1171 --- /dev/null +++ b/programs/whirlpool/CollectRewardV2_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package whirlpool + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_CollectRewardV2(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("CollectRewardV2"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(CollectRewardV2) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(CollectRewardV2) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/CollectReward_test.go b/programs/whirlpool/CollectReward_test.go index 76d9fc5e..4e4b1c87 100644 --- a/programs/whirlpool/CollectReward_test.go +++ b/programs/whirlpool/CollectReward_test.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "bytes" diff --git a/programs/whirlpool/DecreaseLiquidity.go b/programs/whirlpool/DecreaseLiquidity.go index 44acf0b8..4fe6b10d 100644 --- a/programs/whirlpool/DecreaseLiquidity.go +++ b/programs/whirlpool/DecreaseLiquidity.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "errors" diff --git a/programs/whirlpool/DecreaseLiquidityV2.go b/programs/whirlpool/DecreaseLiquidityV2.go new file mode 100644 index 00000000..f7e93952 --- /dev/null +++ b/programs/whirlpool/DecreaseLiquidityV2.go @@ -0,0 +1,480 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package whirlpool + +import ( + "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" +) + +// DecreaseLiquidityV2 is the `decreaseLiquidityV2` instruction. +type DecreaseLiquidityV2 struct { + LiquidityAmount *ag_binary.Uint128 + TokenMinA *uint64 + TokenMinB *uint64 + RemainingAccountsInfo *RemainingAccountsInfo `bin:"optional"` + + // [0] = [WRITE] whirlpool + // + // [1] = [] tokenProgramA + // + // [2] = [] tokenProgramB + // + // [3] = [] memoProgram + // + // [4] = [SIGNER] positionAuthority + // + // [5] = [WRITE] position + // + // [6] = [] positionTokenAccount + // + // [7] = [] tokenMintA + // + // [8] = [] tokenMintB + // + // [9] = [WRITE] tokenOwnerAccountA + // + // [10] = [WRITE] tokenOwnerAccountB + // + // [11] = [WRITE] tokenVaultA + // + // [12] = [WRITE] tokenVaultB + // + // [13] = [WRITE] tickArrayLower + // + // [14] = [WRITE] tickArrayUpper + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewDecreaseLiquidityV2InstructionBuilder creates a new `DecreaseLiquidityV2` instruction builder. +func NewDecreaseLiquidityV2InstructionBuilder() *DecreaseLiquidityV2 { + nd := &DecreaseLiquidityV2{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 15), + } + return nd +} + +// SetLiquidityAmount sets the "liquidityAmount" parameter. +func (inst *DecreaseLiquidityV2) SetLiquidityAmount(liquidityAmount ag_binary.Uint128) *DecreaseLiquidityV2 { + inst.LiquidityAmount = &liquidityAmount + return inst +} + +// SetTokenMinA sets the "tokenMinA" parameter. +func (inst *DecreaseLiquidityV2) SetTokenMinA(tokenMinA uint64) *DecreaseLiquidityV2 { + inst.TokenMinA = &tokenMinA + return inst +} + +// SetTokenMinB sets the "tokenMinB" parameter. +func (inst *DecreaseLiquidityV2) SetTokenMinB(tokenMinB uint64) *DecreaseLiquidityV2 { + inst.TokenMinB = &tokenMinB + return inst +} + +// SetRemainingAccountsInfo sets the "remainingAccountsInfo" parameter. +func (inst *DecreaseLiquidityV2) SetRemainingAccountsInfo(remainingAccountsInfo RemainingAccountsInfo) *DecreaseLiquidityV2 { + inst.RemainingAccountsInfo = &remainingAccountsInfo + return inst +} + +// SetWhirlpoolAccount sets the "whirlpool" account. +func (inst *DecreaseLiquidityV2) SetWhirlpoolAccount(whirlpool ag_solanago.PublicKey) *DecreaseLiquidityV2 { + inst.AccountMetaSlice[0] = ag_solanago.Meta(whirlpool).WRITE() + return inst +} + +// GetWhirlpoolAccount gets the "whirlpool" account. +func (inst *DecreaseLiquidityV2) GetWhirlpoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetTokenProgramAAccount sets the "tokenProgramA" account. +func (inst *DecreaseLiquidityV2) SetTokenProgramAAccount(tokenProgramA ag_solanago.PublicKey) *DecreaseLiquidityV2 { + inst.AccountMetaSlice[1] = ag_solanago.Meta(tokenProgramA) + return inst +} + +// GetTokenProgramAAccount gets the "tokenProgramA" account. +func (inst *DecreaseLiquidityV2) GetTokenProgramAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetTokenProgramBAccount sets the "tokenProgramB" account. +func (inst *DecreaseLiquidityV2) SetTokenProgramBAccount(tokenProgramB ag_solanago.PublicKey) *DecreaseLiquidityV2 { + inst.AccountMetaSlice[2] = ag_solanago.Meta(tokenProgramB) + return inst +} + +// GetTokenProgramBAccount gets the "tokenProgramB" account. +func (inst *DecreaseLiquidityV2) GetTokenProgramBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetMemoProgramAccount sets the "memoProgram" account. +func (inst *DecreaseLiquidityV2) SetMemoProgramAccount(memoProgram ag_solanago.PublicKey) *DecreaseLiquidityV2 { + inst.AccountMetaSlice[3] = ag_solanago.Meta(memoProgram) + return inst +} + +// GetMemoProgramAccount gets the "memoProgram" account. +func (inst *DecreaseLiquidityV2) GetMemoProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetPositionAuthorityAccount sets the "positionAuthority" account. +func (inst *DecreaseLiquidityV2) SetPositionAuthorityAccount(positionAuthority ag_solanago.PublicKey) *DecreaseLiquidityV2 { + inst.AccountMetaSlice[4] = ag_solanago.Meta(positionAuthority).SIGNER() + return inst +} + +// GetPositionAuthorityAccount gets the "positionAuthority" account. +func (inst *DecreaseLiquidityV2) GetPositionAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetPositionAccount sets the "position" account. +func (inst *DecreaseLiquidityV2) SetPositionAccount(position ag_solanago.PublicKey) *DecreaseLiquidityV2 { + inst.AccountMetaSlice[5] = ag_solanago.Meta(position).WRITE() + return inst +} + +// GetPositionAccount gets the "position" account. +func (inst *DecreaseLiquidityV2) GetPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetPositionTokenAccountAccount sets the "positionTokenAccount" account. +func (inst *DecreaseLiquidityV2) SetPositionTokenAccountAccount(positionTokenAccount ag_solanago.PublicKey) *DecreaseLiquidityV2 { + inst.AccountMetaSlice[6] = ag_solanago.Meta(positionTokenAccount) + return inst +} + +// GetPositionTokenAccountAccount gets the "positionTokenAccount" account. +func (inst *DecreaseLiquidityV2) GetPositionTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetTokenMintAAccount sets the "tokenMintA" account. +func (inst *DecreaseLiquidityV2) SetTokenMintAAccount(tokenMintA ag_solanago.PublicKey) *DecreaseLiquidityV2 { + inst.AccountMetaSlice[7] = ag_solanago.Meta(tokenMintA) + return inst +} + +// GetTokenMintAAccount gets the "tokenMintA" account. +func (inst *DecreaseLiquidityV2) GetTokenMintAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetTokenMintBAccount sets the "tokenMintB" account. +func (inst *DecreaseLiquidityV2) SetTokenMintBAccount(tokenMintB ag_solanago.PublicKey) *DecreaseLiquidityV2 { + inst.AccountMetaSlice[8] = ag_solanago.Meta(tokenMintB) + return inst +} + +// GetTokenMintBAccount gets the "tokenMintB" account. +func (inst *DecreaseLiquidityV2) GetTokenMintBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetTokenOwnerAccountAAccount sets the "tokenOwnerAccountA" account. +func (inst *DecreaseLiquidityV2) SetTokenOwnerAccountAAccount(tokenOwnerAccountA ag_solanago.PublicKey) *DecreaseLiquidityV2 { + inst.AccountMetaSlice[9] = ag_solanago.Meta(tokenOwnerAccountA).WRITE() + return inst +} + +// GetTokenOwnerAccountAAccount gets the "tokenOwnerAccountA" account. +func (inst *DecreaseLiquidityV2) GetTokenOwnerAccountAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetTokenOwnerAccountBAccount sets the "tokenOwnerAccountB" account. +func (inst *DecreaseLiquidityV2) SetTokenOwnerAccountBAccount(tokenOwnerAccountB ag_solanago.PublicKey) *DecreaseLiquidityV2 { + inst.AccountMetaSlice[10] = ag_solanago.Meta(tokenOwnerAccountB).WRITE() + return inst +} + +// GetTokenOwnerAccountBAccount gets the "tokenOwnerAccountB" account. +func (inst *DecreaseLiquidityV2) GetTokenOwnerAccountBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetTokenVaultAAccount sets the "tokenVaultA" account. +func (inst *DecreaseLiquidityV2) SetTokenVaultAAccount(tokenVaultA ag_solanago.PublicKey) *DecreaseLiquidityV2 { + inst.AccountMetaSlice[11] = ag_solanago.Meta(tokenVaultA).WRITE() + return inst +} + +// GetTokenVaultAAccount gets the "tokenVaultA" account. +func (inst *DecreaseLiquidityV2) GetTokenVaultAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetTokenVaultBAccount sets the "tokenVaultB" account. +func (inst *DecreaseLiquidityV2) SetTokenVaultBAccount(tokenVaultB ag_solanago.PublicKey) *DecreaseLiquidityV2 { + inst.AccountMetaSlice[12] = ag_solanago.Meta(tokenVaultB).WRITE() + return inst +} + +// GetTokenVaultBAccount gets the "tokenVaultB" account. +func (inst *DecreaseLiquidityV2) GetTokenVaultBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetTickArrayLowerAccount sets the "tickArrayLower" account. +func (inst *DecreaseLiquidityV2) SetTickArrayLowerAccount(tickArrayLower ag_solanago.PublicKey) *DecreaseLiquidityV2 { + inst.AccountMetaSlice[13] = ag_solanago.Meta(tickArrayLower).WRITE() + return inst +} + +// GetTickArrayLowerAccount gets the "tickArrayLower" account. +func (inst *DecreaseLiquidityV2) GetTickArrayLowerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetTickArrayUpperAccount sets the "tickArrayUpper" account. +func (inst *DecreaseLiquidityV2) SetTickArrayUpperAccount(tickArrayUpper ag_solanago.PublicKey) *DecreaseLiquidityV2 { + inst.AccountMetaSlice[14] = ag_solanago.Meta(tickArrayUpper).WRITE() + return inst +} + +// GetTickArrayUpperAccount gets the "tickArrayUpper" account. +func (inst *DecreaseLiquidityV2) GetTickArrayUpperAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +func (inst DecreaseLiquidityV2) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_DecreaseLiquidityV2, + }} +} + +// 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 DecreaseLiquidityV2) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *DecreaseLiquidityV2) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.LiquidityAmount == nil { + return errors.New("LiquidityAmount parameter is not set") + } + if inst.TokenMinA == nil { + return errors.New("TokenMinA parameter is not set") + } + if inst.TokenMinB == nil { + return errors.New("TokenMinB parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Whirlpool is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.TokenProgramA is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.TokenProgramB is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.MemoProgram is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.PositionAuthority is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.Position is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.PositionTokenAccount is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.TokenMintA is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.TokenMintB is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.TokenOwnerAccountA is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.TokenOwnerAccountB is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.TokenVaultA is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.TokenVaultB is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.TickArrayLower is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.TickArrayUpper is not set") + } + } + return nil +} + +func (inst *DecreaseLiquidityV2) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("DecreaseLiquidityV2")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=4]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" LiquidityAmount", *inst.LiquidityAmount)) + paramsBranch.Child(ag_format.Param(" TokenMinA", *inst.TokenMinA)) + paramsBranch.Child(ag_format.Param(" TokenMinB", *inst.TokenMinB)) + paramsBranch.Child(ag_format.Param("RemainingAccountsInfo (OPT)", inst.RemainingAccountsInfo)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=15]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" whirlpool", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" tokenProgramA", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" tokenProgramB", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" memoProgram", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" positionAuthority", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" position", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" positionToken", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" tokenMintA", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" tokenMintB", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta("tokenOwnerAccountA", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta("tokenOwnerAccountB", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" tokenVaultA", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" tokenVaultB", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" tickArrayLower", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta(" tickArrayUpper", inst.AccountMetaSlice.Get(14))) + }) + }) + }) +} + +func (obj DecreaseLiquidityV2) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `LiquidityAmount` param: + err = encoder.Encode(obj.LiquidityAmount) + if err != nil { + return err + } + // Serialize `TokenMinA` param: + err = encoder.Encode(obj.TokenMinA) + if err != nil { + return err + } + // Serialize `TokenMinB` param: + err = encoder.Encode(obj.TokenMinB) + if err != nil { + return err + } + // Serialize `RemainingAccountsInfo` param (optional): + { + if obj.RemainingAccountsInfo == nil { + err = encoder.WriteBool(false) + if err != nil { + return err + } + } else { + err = encoder.WriteBool(true) + if err != nil { + return err + } + err = encoder.Encode(obj.RemainingAccountsInfo) + if err != nil { + return err + } + } + } + return nil +} +func (obj *DecreaseLiquidityV2) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `LiquidityAmount`: + err = decoder.Decode(&obj.LiquidityAmount) + if err != nil { + return err + } + // Deserialize `TokenMinA`: + err = decoder.Decode(&obj.TokenMinA) + if err != nil { + return err + } + // Deserialize `TokenMinB`: + err = decoder.Decode(&obj.TokenMinB) + if err != nil { + return err + } + // Deserialize `RemainingAccountsInfo` (optional): + { + ok, err := decoder.ReadBool() + if err != nil { + return err + } + if ok { + err = decoder.Decode(&obj.RemainingAccountsInfo) + if err != nil { + return err + } + } + } + return nil +} + +// NewDecreaseLiquidityV2Instruction declares a new DecreaseLiquidityV2 instruction with the provided parameters and accounts. +func NewDecreaseLiquidityV2Instruction( + // Parameters: + liquidityAmount ag_binary.Uint128, + tokenMinA uint64, + tokenMinB uint64, + remainingAccountsInfo RemainingAccountsInfo, + // Accounts: + whirlpool ag_solanago.PublicKey, + tokenProgramA ag_solanago.PublicKey, + tokenProgramB ag_solanago.PublicKey, + memoProgram ag_solanago.PublicKey, + positionAuthority ag_solanago.PublicKey, + position ag_solanago.PublicKey, + positionTokenAccount ag_solanago.PublicKey, + tokenMintA ag_solanago.PublicKey, + tokenMintB ag_solanago.PublicKey, + tokenOwnerAccountA ag_solanago.PublicKey, + tokenOwnerAccountB ag_solanago.PublicKey, + tokenVaultA ag_solanago.PublicKey, + tokenVaultB ag_solanago.PublicKey, + tickArrayLower ag_solanago.PublicKey, + tickArrayUpper ag_solanago.PublicKey) *DecreaseLiquidityV2 { + return NewDecreaseLiquidityV2InstructionBuilder(). + SetLiquidityAmount(liquidityAmount). + SetTokenMinA(tokenMinA). + SetTokenMinB(tokenMinB). + SetRemainingAccountsInfo(remainingAccountsInfo). + SetWhirlpoolAccount(whirlpool). + SetTokenProgramAAccount(tokenProgramA). + SetTokenProgramBAccount(tokenProgramB). + SetMemoProgramAccount(memoProgram). + SetPositionAuthorityAccount(positionAuthority). + SetPositionAccount(position). + SetPositionTokenAccountAccount(positionTokenAccount). + SetTokenMintAAccount(tokenMintA). + SetTokenMintBAccount(tokenMintB). + SetTokenOwnerAccountAAccount(tokenOwnerAccountA). + SetTokenOwnerAccountBAccount(tokenOwnerAccountB). + SetTokenVaultAAccount(tokenVaultA). + SetTokenVaultBAccount(tokenVaultB). + SetTickArrayLowerAccount(tickArrayLower). + SetTickArrayUpperAccount(tickArrayUpper) +} diff --git a/programs/whirlpool/DecreaseLiquidityV2_test.go b/programs/whirlpool/DecreaseLiquidityV2_test.go new file mode 100644 index 00000000..92b0442b --- /dev/null +++ b/programs/whirlpool/DecreaseLiquidityV2_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package whirlpool + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_DecreaseLiquidityV2(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("DecreaseLiquidityV2"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(DecreaseLiquidityV2) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(DecreaseLiquidityV2) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/DecreaseLiquidity_test.go b/programs/whirlpool/DecreaseLiquidity_test.go index 2fd8b21d..9f857c6f 100644 --- a/programs/whirlpool/DecreaseLiquidity_test.go +++ b/programs/whirlpool/DecreaseLiquidity_test.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "bytes" diff --git a/programs/whirlpool/DeletePositionBundle.go b/programs/whirlpool/DeletePositionBundle.go index a8a9507b..eba09413 100644 --- a/programs/whirlpool/DeletePositionBundle.go +++ b/programs/whirlpool/DeletePositionBundle.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "errors" diff --git a/programs/whirlpool/DeletePositionBundle_test.go b/programs/whirlpool/DeletePositionBundle_test.go index 5b1c77be..db51d69d 100644 --- a/programs/whirlpool/DeletePositionBundle_test.go +++ b/programs/whirlpool/DeletePositionBundle_test.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "bytes" diff --git a/programs/whirlpool/DeleteTokenBadge.go b/programs/whirlpool/DeleteTokenBadge.go new file mode 100644 index 00000000..826ed1ec --- /dev/null +++ b/programs/whirlpool/DeleteTokenBadge.go @@ -0,0 +1,193 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package whirlpool + +import ( + "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" +) + +// DeleteTokenBadge is the `deleteTokenBadge` instruction. +type DeleteTokenBadge struct { + + // [0] = [] whirlpoolsConfig + // + // [1] = [] whirlpoolsConfigExtension + // + // [2] = [SIGNER] tokenBadgeAuthority + // + // [3] = [] tokenMint + // + // [4] = [WRITE] tokenBadge + // + // [5] = [WRITE] receiver + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewDeleteTokenBadgeInstructionBuilder creates a new `DeleteTokenBadge` instruction builder. +func NewDeleteTokenBadgeInstructionBuilder() *DeleteTokenBadge { + nd := &DeleteTokenBadge{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 6), + } + return nd +} + +// SetWhirlpoolsConfigAccount sets the "whirlpoolsConfig" account. +func (inst *DeleteTokenBadge) SetWhirlpoolsConfigAccount(whirlpoolsConfig ag_solanago.PublicKey) *DeleteTokenBadge { + inst.AccountMetaSlice[0] = ag_solanago.Meta(whirlpoolsConfig) + return inst +} + +// GetWhirlpoolsConfigAccount gets the "whirlpoolsConfig" account. +func (inst *DeleteTokenBadge) GetWhirlpoolsConfigAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetWhirlpoolsConfigExtensionAccount sets the "whirlpoolsConfigExtension" account. +func (inst *DeleteTokenBadge) SetWhirlpoolsConfigExtensionAccount(whirlpoolsConfigExtension ag_solanago.PublicKey) *DeleteTokenBadge { + inst.AccountMetaSlice[1] = ag_solanago.Meta(whirlpoolsConfigExtension) + return inst +} + +// GetWhirlpoolsConfigExtensionAccount gets the "whirlpoolsConfigExtension" account. +func (inst *DeleteTokenBadge) GetWhirlpoolsConfigExtensionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetTokenBadgeAuthorityAccount sets the "tokenBadgeAuthority" account. +func (inst *DeleteTokenBadge) SetTokenBadgeAuthorityAccount(tokenBadgeAuthority ag_solanago.PublicKey) *DeleteTokenBadge { + inst.AccountMetaSlice[2] = ag_solanago.Meta(tokenBadgeAuthority).SIGNER() + return inst +} + +// GetTokenBadgeAuthorityAccount gets the "tokenBadgeAuthority" account. +func (inst *DeleteTokenBadge) GetTokenBadgeAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetTokenMintAccount sets the "tokenMint" account. +func (inst *DeleteTokenBadge) SetTokenMintAccount(tokenMint ag_solanago.PublicKey) *DeleteTokenBadge { + inst.AccountMetaSlice[3] = ag_solanago.Meta(tokenMint) + return inst +} + +// GetTokenMintAccount gets the "tokenMint" account. +func (inst *DeleteTokenBadge) GetTokenMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetTokenBadgeAccount sets the "tokenBadge" account. +func (inst *DeleteTokenBadge) SetTokenBadgeAccount(tokenBadge ag_solanago.PublicKey) *DeleteTokenBadge { + inst.AccountMetaSlice[4] = ag_solanago.Meta(tokenBadge).WRITE() + return inst +} + +// GetTokenBadgeAccount gets the "tokenBadge" account. +func (inst *DeleteTokenBadge) GetTokenBadgeAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetReceiverAccount sets the "receiver" account. +func (inst *DeleteTokenBadge) SetReceiverAccount(receiver ag_solanago.PublicKey) *DeleteTokenBadge { + inst.AccountMetaSlice[5] = ag_solanago.Meta(receiver).WRITE() + return inst +} + +// GetReceiverAccount gets the "receiver" account. +func (inst *DeleteTokenBadge) GetReceiverAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +func (inst DeleteTokenBadge) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_DeleteTokenBadge, + }} +} + +// 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 DeleteTokenBadge) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *DeleteTokenBadge) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.WhirlpoolsConfig is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.WhirlpoolsConfigExtension is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.TokenBadgeAuthority is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.TokenMint is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.TokenBadge is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.Receiver is not set") + } + } + return nil +} + +func (inst *DeleteTokenBadge) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("DeleteTokenBadge")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=6]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" whirlpoolsConfig", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta("whirlpoolsConfigExtension", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" tokenBadgeAuthority", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" tokenMint", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" tokenBadge", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" receiver", inst.AccountMetaSlice.Get(5))) + }) + }) + }) +} + +func (obj DeleteTokenBadge) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *DeleteTokenBadge) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewDeleteTokenBadgeInstruction declares a new DeleteTokenBadge instruction with the provided parameters and accounts. +func NewDeleteTokenBadgeInstruction( + // Accounts: + whirlpoolsConfig ag_solanago.PublicKey, + whirlpoolsConfigExtension ag_solanago.PublicKey, + tokenBadgeAuthority ag_solanago.PublicKey, + tokenMint ag_solanago.PublicKey, + tokenBadge ag_solanago.PublicKey, + receiver ag_solanago.PublicKey) *DeleteTokenBadge { + return NewDeleteTokenBadgeInstructionBuilder(). + SetWhirlpoolsConfigAccount(whirlpoolsConfig). + SetWhirlpoolsConfigExtensionAccount(whirlpoolsConfigExtension). + SetTokenBadgeAuthorityAccount(tokenBadgeAuthority). + SetTokenMintAccount(tokenMint). + SetTokenBadgeAccount(tokenBadge). + SetReceiverAccount(receiver) +} diff --git a/programs/whirlpool/DeleteTokenBadge_test.go b/programs/whirlpool/DeleteTokenBadge_test.go new file mode 100644 index 00000000..7e3c89e8 --- /dev/null +++ b/programs/whirlpool/DeleteTokenBadge_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package whirlpool + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_DeleteTokenBadge(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("DeleteTokenBadge"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(DeleteTokenBadge) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(DeleteTokenBadge) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/IncreaseLiquidity.go b/programs/whirlpool/IncreaseLiquidity.go index 3ed65900..37e721cd 100644 --- a/programs/whirlpool/IncreaseLiquidity.go +++ b/programs/whirlpool/IncreaseLiquidity.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "errors" diff --git a/programs/whirlpool/IncreaseLiquidityV2.go b/programs/whirlpool/IncreaseLiquidityV2.go new file mode 100644 index 00000000..a15364df --- /dev/null +++ b/programs/whirlpool/IncreaseLiquidityV2.go @@ -0,0 +1,480 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package whirlpool + +import ( + "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" +) + +// IncreaseLiquidityV2 is the `increaseLiquidityV2` instruction. +type IncreaseLiquidityV2 struct { + LiquidityAmount *ag_binary.Uint128 + TokenMaxA *uint64 + TokenMaxB *uint64 + RemainingAccountsInfo *RemainingAccountsInfo `bin:"optional"` + + // [0] = [WRITE] whirlpool + // + // [1] = [] tokenProgramA + // + // [2] = [] tokenProgramB + // + // [3] = [] memoProgram + // + // [4] = [SIGNER] positionAuthority + // + // [5] = [WRITE] position + // + // [6] = [] positionTokenAccount + // + // [7] = [] tokenMintA + // + // [8] = [] tokenMintB + // + // [9] = [WRITE] tokenOwnerAccountA + // + // [10] = [WRITE] tokenOwnerAccountB + // + // [11] = [WRITE] tokenVaultA + // + // [12] = [WRITE] tokenVaultB + // + // [13] = [WRITE] tickArrayLower + // + // [14] = [WRITE] tickArrayUpper + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewIncreaseLiquidityV2InstructionBuilder creates a new `IncreaseLiquidityV2` instruction builder. +func NewIncreaseLiquidityV2InstructionBuilder() *IncreaseLiquidityV2 { + nd := &IncreaseLiquidityV2{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 15), + } + return nd +} + +// SetLiquidityAmount sets the "liquidityAmount" parameter. +func (inst *IncreaseLiquidityV2) SetLiquidityAmount(liquidityAmount ag_binary.Uint128) *IncreaseLiquidityV2 { + inst.LiquidityAmount = &liquidityAmount + return inst +} + +// SetTokenMaxA sets the "tokenMaxA" parameter. +func (inst *IncreaseLiquidityV2) SetTokenMaxA(tokenMaxA uint64) *IncreaseLiquidityV2 { + inst.TokenMaxA = &tokenMaxA + return inst +} + +// SetTokenMaxB sets the "tokenMaxB" parameter. +func (inst *IncreaseLiquidityV2) SetTokenMaxB(tokenMaxB uint64) *IncreaseLiquidityV2 { + inst.TokenMaxB = &tokenMaxB + return inst +} + +// SetRemainingAccountsInfo sets the "remainingAccountsInfo" parameter. +func (inst *IncreaseLiquidityV2) SetRemainingAccountsInfo(remainingAccountsInfo RemainingAccountsInfo) *IncreaseLiquidityV2 { + inst.RemainingAccountsInfo = &remainingAccountsInfo + return inst +} + +// SetWhirlpoolAccount sets the "whirlpool" account. +func (inst *IncreaseLiquidityV2) SetWhirlpoolAccount(whirlpool ag_solanago.PublicKey) *IncreaseLiquidityV2 { + inst.AccountMetaSlice[0] = ag_solanago.Meta(whirlpool).WRITE() + return inst +} + +// GetWhirlpoolAccount gets the "whirlpool" account. +func (inst *IncreaseLiquidityV2) GetWhirlpoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetTokenProgramAAccount sets the "tokenProgramA" account. +func (inst *IncreaseLiquidityV2) SetTokenProgramAAccount(tokenProgramA ag_solanago.PublicKey) *IncreaseLiquidityV2 { + inst.AccountMetaSlice[1] = ag_solanago.Meta(tokenProgramA) + return inst +} + +// GetTokenProgramAAccount gets the "tokenProgramA" account. +func (inst *IncreaseLiquidityV2) GetTokenProgramAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetTokenProgramBAccount sets the "tokenProgramB" account. +func (inst *IncreaseLiquidityV2) SetTokenProgramBAccount(tokenProgramB ag_solanago.PublicKey) *IncreaseLiquidityV2 { + inst.AccountMetaSlice[2] = ag_solanago.Meta(tokenProgramB) + return inst +} + +// GetTokenProgramBAccount gets the "tokenProgramB" account. +func (inst *IncreaseLiquidityV2) GetTokenProgramBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetMemoProgramAccount sets the "memoProgram" account. +func (inst *IncreaseLiquidityV2) SetMemoProgramAccount(memoProgram ag_solanago.PublicKey) *IncreaseLiquidityV2 { + inst.AccountMetaSlice[3] = ag_solanago.Meta(memoProgram) + return inst +} + +// GetMemoProgramAccount gets the "memoProgram" account. +func (inst *IncreaseLiquidityV2) GetMemoProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetPositionAuthorityAccount sets the "positionAuthority" account. +func (inst *IncreaseLiquidityV2) SetPositionAuthorityAccount(positionAuthority ag_solanago.PublicKey) *IncreaseLiquidityV2 { + inst.AccountMetaSlice[4] = ag_solanago.Meta(positionAuthority).SIGNER() + return inst +} + +// GetPositionAuthorityAccount gets the "positionAuthority" account. +func (inst *IncreaseLiquidityV2) GetPositionAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetPositionAccount sets the "position" account. +func (inst *IncreaseLiquidityV2) SetPositionAccount(position ag_solanago.PublicKey) *IncreaseLiquidityV2 { + inst.AccountMetaSlice[5] = ag_solanago.Meta(position).WRITE() + return inst +} + +// GetPositionAccount gets the "position" account. +func (inst *IncreaseLiquidityV2) GetPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetPositionTokenAccountAccount sets the "positionTokenAccount" account. +func (inst *IncreaseLiquidityV2) SetPositionTokenAccountAccount(positionTokenAccount ag_solanago.PublicKey) *IncreaseLiquidityV2 { + inst.AccountMetaSlice[6] = ag_solanago.Meta(positionTokenAccount) + return inst +} + +// GetPositionTokenAccountAccount gets the "positionTokenAccount" account. +func (inst *IncreaseLiquidityV2) GetPositionTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetTokenMintAAccount sets the "tokenMintA" account. +func (inst *IncreaseLiquidityV2) SetTokenMintAAccount(tokenMintA ag_solanago.PublicKey) *IncreaseLiquidityV2 { + inst.AccountMetaSlice[7] = ag_solanago.Meta(tokenMintA) + return inst +} + +// GetTokenMintAAccount gets the "tokenMintA" account. +func (inst *IncreaseLiquidityV2) GetTokenMintAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetTokenMintBAccount sets the "tokenMintB" account. +func (inst *IncreaseLiquidityV2) SetTokenMintBAccount(tokenMintB ag_solanago.PublicKey) *IncreaseLiquidityV2 { + inst.AccountMetaSlice[8] = ag_solanago.Meta(tokenMintB) + return inst +} + +// GetTokenMintBAccount gets the "tokenMintB" account. +func (inst *IncreaseLiquidityV2) GetTokenMintBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetTokenOwnerAccountAAccount sets the "tokenOwnerAccountA" account. +func (inst *IncreaseLiquidityV2) SetTokenOwnerAccountAAccount(tokenOwnerAccountA ag_solanago.PublicKey) *IncreaseLiquidityV2 { + inst.AccountMetaSlice[9] = ag_solanago.Meta(tokenOwnerAccountA).WRITE() + return inst +} + +// GetTokenOwnerAccountAAccount gets the "tokenOwnerAccountA" account. +func (inst *IncreaseLiquidityV2) GetTokenOwnerAccountAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetTokenOwnerAccountBAccount sets the "tokenOwnerAccountB" account. +func (inst *IncreaseLiquidityV2) SetTokenOwnerAccountBAccount(tokenOwnerAccountB ag_solanago.PublicKey) *IncreaseLiquidityV2 { + inst.AccountMetaSlice[10] = ag_solanago.Meta(tokenOwnerAccountB).WRITE() + return inst +} + +// GetTokenOwnerAccountBAccount gets the "tokenOwnerAccountB" account. +func (inst *IncreaseLiquidityV2) GetTokenOwnerAccountBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetTokenVaultAAccount sets the "tokenVaultA" account. +func (inst *IncreaseLiquidityV2) SetTokenVaultAAccount(tokenVaultA ag_solanago.PublicKey) *IncreaseLiquidityV2 { + inst.AccountMetaSlice[11] = ag_solanago.Meta(tokenVaultA).WRITE() + return inst +} + +// GetTokenVaultAAccount gets the "tokenVaultA" account. +func (inst *IncreaseLiquidityV2) GetTokenVaultAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetTokenVaultBAccount sets the "tokenVaultB" account. +func (inst *IncreaseLiquidityV2) SetTokenVaultBAccount(tokenVaultB ag_solanago.PublicKey) *IncreaseLiquidityV2 { + inst.AccountMetaSlice[12] = ag_solanago.Meta(tokenVaultB).WRITE() + return inst +} + +// GetTokenVaultBAccount gets the "tokenVaultB" account. +func (inst *IncreaseLiquidityV2) GetTokenVaultBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetTickArrayLowerAccount sets the "tickArrayLower" account. +func (inst *IncreaseLiquidityV2) SetTickArrayLowerAccount(tickArrayLower ag_solanago.PublicKey) *IncreaseLiquidityV2 { + inst.AccountMetaSlice[13] = ag_solanago.Meta(tickArrayLower).WRITE() + return inst +} + +// GetTickArrayLowerAccount gets the "tickArrayLower" account. +func (inst *IncreaseLiquidityV2) GetTickArrayLowerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetTickArrayUpperAccount sets the "tickArrayUpper" account. +func (inst *IncreaseLiquidityV2) SetTickArrayUpperAccount(tickArrayUpper ag_solanago.PublicKey) *IncreaseLiquidityV2 { + inst.AccountMetaSlice[14] = ag_solanago.Meta(tickArrayUpper).WRITE() + return inst +} + +// GetTickArrayUpperAccount gets the "tickArrayUpper" account. +func (inst *IncreaseLiquidityV2) GetTickArrayUpperAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +func (inst IncreaseLiquidityV2) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_IncreaseLiquidityV2, + }} +} + +// 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 IncreaseLiquidityV2) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *IncreaseLiquidityV2) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.LiquidityAmount == nil { + return errors.New("LiquidityAmount parameter is not set") + } + if inst.TokenMaxA == nil { + return errors.New("TokenMaxA parameter is not set") + } + if inst.TokenMaxB == nil { + return errors.New("TokenMaxB parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Whirlpool is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.TokenProgramA is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.TokenProgramB is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.MemoProgram is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.PositionAuthority is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.Position is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.PositionTokenAccount is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.TokenMintA is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.TokenMintB is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.TokenOwnerAccountA is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.TokenOwnerAccountB is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.TokenVaultA is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.TokenVaultB is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.TickArrayLower is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.TickArrayUpper is not set") + } + } + return nil +} + +func (inst *IncreaseLiquidityV2) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("IncreaseLiquidityV2")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=4]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" LiquidityAmount", *inst.LiquidityAmount)) + paramsBranch.Child(ag_format.Param(" TokenMaxA", *inst.TokenMaxA)) + paramsBranch.Child(ag_format.Param(" TokenMaxB", *inst.TokenMaxB)) + paramsBranch.Child(ag_format.Param("RemainingAccountsInfo (OPT)", inst.RemainingAccountsInfo)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=15]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" whirlpool", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" tokenProgramA", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" tokenProgramB", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" memoProgram", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" positionAuthority", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" position", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" positionToken", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" tokenMintA", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" tokenMintB", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta("tokenOwnerAccountA", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta("tokenOwnerAccountB", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" tokenVaultA", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" tokenVaultB", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" tickArrayLower", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta(" tickArrayUpper", inst.AccountMetaSlice.Get(14))) + }) + }) + }) +} + +func (obj IncreaseLiquidityV2) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `LiquidityAmount` param: + err = encoder.Encode(obj.LiquidityAmount) + if err != nil { + return err + } + // Serialize `TokenMaxA` param: + err = encoder.Encode(obj.TokenMaxA) + if err != nil { + return err + } + // Serialize `TokenMaxB` param: + err = encoder.Encode(obj.TokenMaxB) + if err != nil { + return err + } + // Serialize `RemainingAccountsInfo` param (optional): + { + if obj.RemainingAccountsInfo == nil { + err = encoder.WriteBool(false) + if err != nil { + return err + } + } else { + err = encoder.WriteBool(true) + if err != nil { + return err + } + err = encoder.Encode(obj.RemainingAccountsInfo) + if err != nil { + return err + } + } + } + return nil +} +func (obj *IncreaseLiquidityV2) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `LiquidityAmount`: + err = decoder.Decode(&obj.LiquidityAmount) + if err != nil { + return err + } + // Deserialize `TokenMaxA`: + err = decoder.Decode(&obj.TokenMaxA) + if err != nil { + return err + } + // Deserialize `TokenMaxB`: + err = decoder.Decode(&obj.TokenMaxB) + if err != nil { + return err + } + // Deserialize `RemainingAccountsInfo` (optional): + { + ok, err := decoder.ReadBool() + if err != nil { + return err + } + if ok { + err = decoder.Decode(&obj.RemainingAccountsInfo) + if err != nil { + return err + } + } + } + return nil +} + +// NewIncreaseLiquidityV2Instruction declares a new IncreaseLiquidityV2 instruction with the provided parameters and accounts. +func NewIncreaseLiquidityV2Instruction( + // Parameters: + liquidityAmount ag_binary.Uint128, + tokenMaxA uint64, + tokenMaxB uint64, + remainingAccountsInfo RemainingAccountsInfo, + // Accounts: + whirlpool ag_solanago.PublicKey, + tokenProgramA ag_solanago.PublicKey, + tokenProgramB ag_solanago.PublicKey, + memoProgram ag_solanago.PublicKey, + positionAuthority ag_solanago.PublicKey, + position ag_solanago.PublicKey, + positionTokenAccount ag_solanago.PublicKey, + tokenMintA ag_solanago.PublicKey, + tokenMintB ag_solanago.PublicKey, + tokenOwnerAccountA ag_solanago.PublicKey, + tokenOwnerAccountB ag_solanago.PublicKey, + tokenVaultA ag_solanago.PublicKey, + tokenVaultB ag_solanago.PublicKey, + tickArrayLower ag_solanago.PublicKey, + tickArrayUpper ag_solanago.PublicKey) *IncreaseLiquidityV2 { + return NewIncreaseLiquidityV2InstructionBuilder(). + SetLiquidityAmount(liquidityAmount). + SetTokenMaxA(tokenMaxA). + SetTokenMaxB(tokenMaxB). + SetRemainingAccountsInfo(remainingAccountsInfo). + SetWhirlpoolAccount(whirlpool). + SetTokenProgramAAccount(tokenProgramA). + SetTokenProgramBAccount(tokenProgramB). + SetMemoProgramAccount(memoProgram). + SetPositionAuthorityAccount(positionAuthority). + SetPositionAccount(position). + SetPositionTokenAccountAccount(positionTokenAccount). + SetTokenMintAAccount(tokenMintA). + SetTokenMintBAccount(tokenMintB). + SetTokenOwnerAccountAAccount(tokenOwnerAccountA). + SetTokenOwnerAccountBAccount(tokenOwnerAccountB). + SetTokenVaultAAccount(tokenVaultA). + SetTokenVaultBAccount(tokenVaultB). + SetTickArrayLowerAccount(tickArrayLower). + SetTickArrayUpperAccount(tickArrayUpper) +} diff --git a/programs/whirlpool/IncreaseLiquidityV2_test.go b/programs/whirlpool/IncreaseLiquidityV2_test.go new file mode 100644 index 00000000..bfddb86b --- /dev/null +++ b/programs/whirlpool/IncreaseLiquidityV2_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package whirlpool + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_IncreaseLiquidityV2(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("IncreaseLiquidityV2"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(IncreaseLiquidityV2) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(IncreaseLiquidityV2) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/IncreaseLiquidity_test.go b/programs/whirlpool/IncreaseLiquidity_test.go index a0277725..1c4feabd 100644 --- a/programs/whirlpool/IncreaseLiquidity_test.go +++ b/programs/whirlpool/IncreaseLiquidity_test.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "bytes" diff --git a/programs/whirlpool/InitializeConfig.go b/programs/whirlpool/InitializeConfig.go index 914da5e7..c10dfbc9 100644 --- a/programs/whirlpool/InitializeConfig.go +++ b/programs/whirlpool/InitializeConfig.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "errors" diff --git a/programs/whirlpool/InitializeConfigExtension.go b/programs/whirlpool/InitializeConfigExtension.go new file mode 100644 index 00000000..0f0737aa --- /dev/null +++ b/programs/whirlpool/InitializeConfigExtension.go @@ -0,0 +1,174 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package whirlpool + +import ( + "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" +) + +// InitializeConfigExtension is the `initializeConfigExtension` instruction. +type InitializeConfigExtension struct { + + // [0] = [] config + // + // [1] = [WRITE] configExtension + // + // [2] = [WRITE, SIGNER] funder + // + // [3] = [SIGNER] feeAuthority + // + // [4] = [] systemProgram + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewInitializeConfigExtensionInstructionBuilder creates a new `InitializeConfigExtension` instruction builder. +func NewInitializeConfigExtensionInstructionBuilder() *InitializeConfigExtension { + nd := &InitializeConfigExtension{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 5), + } + return nd +} + +// SetConfigAccount sets the "config" account. +func (inst *InitializeConfigExtension) SetConfigAccount(config ag_solanago.PublicKey) *InitializeConfigExtension { + inst.AccountMetaSlice[0] = ag_solanago.Meta(config) + return inst +} + +// GetConfigAccount gets the "config" account. +func (inst *InitializeConfigExtension) GetConfigAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetConfigExtensionAccount sets the "configExtension" account. +func (inst *InitializeConfigExtension) SetConfigExtensionAccount(configExtension ag_solanago.PublicKey) *InitializeConfigExtension { + inst.AccountMetaSlice[1] = ag_solanago.Meta(configExtension).WRITE() + return inst +} + +// GetConfigExtensionAccount gets the "configExtension" account. +func (inst *InitializeConfigExtension) GetConfigExtensionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetFunderAccount sets the "funder" account. +func (inst *InitializeConfigExtension) SetFunderAccount(funder ag_solanago.PublicKey) *InitializeConfigExtension { + inst.AccountMetaSlice[2] = ag_solanago.Meta(funder).WRITE().SIGNER() + return inst +} + +// GetFunderAccount gets the "funder" account. +func (inst *InitializeConfigExtension) GetFunderAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetFeeAuthorityAccount sets the "feeAuthority" account. +func (inst *InitializeConfigExtension) SetFeeAuthorityAccount(feeAuthority ag_solanago.PublicKey) *InitializeConfigExtension { + inst.AccountMetaSlice[3] = ag_solanago.Meta(feeAuthority).SIGNER() + return inst +} + +// GetFeeAuthorityAccount gets the "feeAuthority" account. +func (inst *InitializeConfigExtension) GetFeeAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +func (inst *InitializeConfigExtension) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *InitializeConfigExtension { + inst.AccountMetaSlice[4] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +func (inst *InitializeConfigExtension) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +func (inst InitializeConfigExtension) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_InitializeConfigExtension, + }} +} + +// 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 InitializeConfigExtension) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *InitializeConfigExtension) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Config is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.ConfigExtension is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.Funder is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.FeeAuthority is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.SystemProgram is not set") + } + } + return nil +} + +func (inst *InitializeConfigExtension) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("InitializeConfigExtension")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=5]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" config", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta("configExtension", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" funder", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" feeAuthority", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" systemProgram", inst.AccountMetaSlice.Get(4))) + }) + }) + }) +} + +func (obj InitializeConfigExtension) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *InitializeConfigExtension) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewInitializeConfigExtensionInstruction declares a new InitializeConfigExtension instruction with the provided parameters and accounts. +func NewInitializeConfigExtensionInstruction( + // Accounts: + config ag_solanago.PublicKey, + configExtension ag_solanago.PublicKey, + funder ag_solanago.PublicKey, + feeAuthority ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey) *InitializeConfigExtension { + return NewInitializeConfigExtensionInstructionBuilder(). + SetConfigAccount(config). + SetConfigExtensionAccount(configExtension). + SetFunderAccount(funder). + SetFeeAuthorityAccount(feeAuthority). + SetSystemProgramAccount(systemProgram) +} diff --git a/programs/whirlpool/InitializeConfigExtension_test.go b/programs/whirlpool/InitializeConfigExtension_test.go new file mode 100644 index 00000000..08f7533b --- /dev/null +++ b/programs/whirlpool/InitializeConfigExtension_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package whirlpool + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_InitializeConfigExtension(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("InitializeConfigExtension"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(InitializeConfigExtension) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(InitializeConfigExtension) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/InitializeConfig_test.go b/programs/whirlpool/InitializeConfig_test.go index 266f96d8..4cb1c997 100644 --- a/programs/whirlpool/InitializeConfig_test.go +++ b/programs/whirlpool/InitializeConfig_test.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "bytes" diff --git a/programs/whirlpool/InitializeFeeTier.go b/programs/whirlpool/InitializeFeeTier.go index 9077e187..6a3bc659 100644 --- a/programs/whirlpool/InitializeFeeTier.go +++ b/programs/whirlpool/InitializeFeeTier.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "errors" diff --git a/programs/whirlpool/InitializeFeeTier_test.go b/programs/whirlpool/InitializeFeeTier_test.go index 04df6d61..c0c367f5 100644 --- a/programs/whirlpool/InitializeFeeTier_test.go +++ b/programs/whirlpool/InitializeFeeTier_test.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "bytes" diff --git a/programs/whirlpool/InitializePool.go b/programs/whirlpool/InitializePool.go index 9985cc45..6c952d72 100644 --- a/programs/whirlpool/InitializePool.go +++ b/programs/whirlpool/InitializePool.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "errors" diff --git a/programs/whirlpool/InitializePoolV2.go b/programs/whirlpool/InitializePoolV2.go new file mode 100644 index 00000000..07e5f2d6 --- /dev/null +++ b/programs/whirlpool/InitializePoolV2.go @@ -0,0 +1,397 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package whirlpool + +import ( + "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" +) + +// InitializePoolV2 is the `initializePoolV2` instruction. +type InitializePoolV2 struct { + TickSpacing *uint16 + InitialSqrtPrice *ag_binary.Uint128 + + // [0] = [] whirlpoolsConfig + // + // [1] = [] tokenMintA + // + // [2] = [] tokenMintB + // + // [3] = [] tokenBadgeA + // + // [4] = [] tokenBadgeB + // + // [5] = [WRITE, SIGNER] funder + // + // [6] = [WRITE] whirlpool + // + // [7] = [WRITE, SIGNER] tokenVaultA + // + // [8] = [WRITE, SIGNER] tokenVaultB + // + // [9] = [] feeTier + // + // [10] = [] tokenProgramA + // + // [11] = [] tokenProgramB + // + // [12] = [] systemProgram + // + // [13] = [] rent + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewInitializePoolV2InstructionBuilder creates a new `InitializePoolV2` instruction builder. +func NewInitializePoolV2InstructionBuilder() *InitializePoolV2 { + nd := &InitializePoolV2{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 14), + } + return nd +} + +// SetTickSpacing sets the "tickSpacing" parameter. +func (inst *InitializePoolV2) SetTickSpacing(tickSpacing uint16) *InitializePoolV2 { + inst.TickSpacing = &tickSpacing + return inst +} + +// SetInitialSqrtPrice sets the "initialSqrtPrice" parameter. +func (inst *InitializePoolV2) SetInitialSqrtPrice(initialSqrtPrice ag_binary.Uint128) *InitializePoolV2 { + inst.InitialSqrtPrice = &initialSqrtPrice + return inst +} + +// SetWhirlpoolsConfigAccount sets the "whirlpoolsConfig" account. +func (inst *InitializePoolV2) SetWhirlpoolsConfigAccount(whirlpoolsConfig ag_solanago.PublicKey) *InitializePoolV2 { + inst.AccountMetaSlice[0] = ag_solanago.Meta(whirlpoolsConfig) + return inst +} + +// GetWhirlpoolsConfigAccount gets the "whirlpoolsConfig" account. +func (inst *InitializePoolV2) GetWhirlpoolsConfigAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetTokenMintAAccount sets the "tokenMintA" account. +func (inst *InitializePoolV2) SetTokenMintAAccount(tokenMintA ag_solanago.PublicKey) *InitializePoolV2 { + inst.AccountMetaSlice[1] = ag_solanago.Meta(tokenMintA) + return inst +} + +// GetTokenMintAAccount gets the "tokenMintA" account. +func (inst *InitializePoolV2) GetTokenMintAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetTokenMintBAccount sets the "tokenMintB" account. +func (inst *InitializePoolV2) SetTokenMintBAccount(tokenMintB ag_solanago.PublicKey) *InitializePoolV2 { + inst.AccountMetaSlice[2] = ag_solanago.Meta(tokenMintB) + return inst +} + +// GetTokenMintBAccount gets the "tokenMintB" account. +func (inst *InitializePoolV2) GetTokenMintBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetTokenBadgeAAccount sets the "tokenBadgeA" account. +func (inst *InitializePoolV2) SetTokenBadgeAAccount(tokenBadgeA ag_solanago.PublicKey) *InitializePoolV2 { + inst.AccountMetaSlice[3] = ag_solanago.Meta(tokenBadgeA) + return inst +} + +// GetTokenBadgeAAccount gets the "tokenBadgeA" account. +func (inst *InitializePoolV2) GetTokenBadgeAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetTokenBadgeBAccount sets the "tokenBadgeB" account. +func (inst *InitializePoolV2) SetTokenBadgeBAccount(tokenBadgeB ag_solanago.PublicKey) *InitializePoolV2 { + inst.AccountMetaSlice[4] = ag_solanago.Meta(tokenBadgeB) + return inst +} + +// GetTokenBadgeBAccount gets the "tokenBadgeB" account. +func (inst *InitializePoolV2) GetTokenBadgeBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetFunderAccount sets the "funder" account. +func (inst *InitializePoolV2) SetFunderAccount(funder ag_solanago.PublicKey) *InitializePoolV2 { + inst.AccountMetaSlice[5] = ag_solanago.Meta(funder).WRITE().SIGNER() + return inst +} + +// GetFunderAccount gets the "funder" account. +func (inst *InitializePoolV2) GetFunderAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetWhirlpoolAccount sets the "whirlpool" account. +func (inst *InitializePoolV2) SetWhirlpoolAccount(whirlpool ag_solanago.PublicKey) *InitializePoolV2 { + inst.AccountMetaSlice[6] = ag_solanago.Meta(whirlpool).WRITE() + return inst +} + +// GetWhirlpoolAccount gets the "whirlpool" account. +func (inst *InitializePoolV2) GetWhirlpoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetTokenVaultAAccount sets the "tokenVaultA" account. +func (inst *InitializePoolV2) SetTokenVaultAAccount(tokenVaultA ag_solanago.PublicKey) *InitializePoolV2 { + inst.AccountMetaSlice[7] = ag_solanago.Meta(tokenVaultA).WRITE().SIGNER() + return inst +} + +// GetTokenVaultAAccount gets the "tokenVaultA" account. +func (inst *InitializePoolV2) GetTokenVaultAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetTokenVaultBAccount sets the "tokenVaultB" account. +func (inst *InitializePoolV2) SetTokenVaultBAccount(tokenVaultB ag_solanago.PublicKey) *InitializePoolV2 { + inst.AccountMetaSlice[8] = ag_solanago.Meta(tokenVaultB).WRITE().SIGNER() + return inst +} + +// GetTokenVaultBAccount gets the "tokenVaultB" account. +func (inst *InitializePoolV2) GetTokenVaultBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetFeeTierAccount sets the "feeTier" account. +func (inst *InitializePoolV2) SetFeeTierAccount(feeTier ag_solanago.PublicKey) *InitializePoolV2 { + inst.AccountMetaSlice[9] = ag_solanago.Meta(feeTier) + return inst +} + +// GetFeeTierAccount gets the "feeTier" account. +func (inst *InitializePoolV2) GetFeeTierAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetTokenProgramAAccount sets the "tokenProgramA" account. +func (inst *InitializePoolV2) SetTokenProgramAAccount(tokenProgramA ag_solanago.PublicKey) *InitializePoolV2 { + inst.AccountMetaSlice[10] = ag_solanago.Meta(tokenProgramA) + return inst +} + +// GetTokenProgramAAccount gets the "tokenProgramA" account. +func (inst *InitializePoolV2) GetTokenProgramAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetTokenProgramBAccount sets the "tokenProgramB" account. +func (inst *InitializePoolV2) SetTokenProgramBAccount(tokenProgramB ag_solanago.PublicKey) *InitializePoolV2 { + inst.AccountMetaSlice[11] = ag_solanago.Meta(tokenProgramB) + return inst +} + +// GetTokenProgramBAccount gets the "tokenProgramB" account. +func (inst *InitializePoolV2) GetTokenProgramBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +func (inst *InitializePoolV2) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *InitializePoolV2 { + inst.AccountMetaSlice[12] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +func (inst *InitializePoolV2) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetRentAccount sets the "rent" account. +func (inst *InitializePoolV2) SetRentAccount(rent ag_solanago.PublicKey) *InitializePoolV2 { + inst.AccountMetaSlice[13] = ag_solanago.Meta(rent) + return inst +} + +// GetRentAccount gets the "rent" account. +func (inst *InitializePoolV2) GetRentAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +func (inst InitializePoolV2) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_InitializePoolV2, + }} +} + +// 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 InitializePoolV2) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *InitializePoolV2) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.TickSpacing == nil { + return errors.New("TickSpacing parameter is not set") + } + if inst.InitialSqrtPrice == nil { + return errors.New("InitialSqrtPrice parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.WhirlpoolsConfig is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.TokenMintA is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.TokenMintB is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.TokenBadgeA is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.TokenBadgeB is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.Funder is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.Whirlpool is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.TokenVaultA is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.TokenVaultB is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.FeeTier is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.TokenProgramA is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.TokenProgramB is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.SystemProgram is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.Rent is not set") + } + } + return nil +} + +func (inst *InitializePoolV2) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("InitializePoolV2")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=2]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" TickSpacing", *inst.TickSpacing)) + paramsBranch.Child(ag_format.Param("InitialSqrtPrice", *inst.InitialSqrtPrice)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=14]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta("whirlpoolsConfig", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" tokenMintA", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" tokenMintB", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" tokenBadgeA", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" tokenBadgeB", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" funder", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" whirlpool", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" tokenVaultA", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" tokenVaultB", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" feeTier", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" tokenProgramA", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" tokenProgramB", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" systemProgram", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" rent", inst.AccountMetaSlice.Get(13))) + }) + }) + }) +} + +func (obj InitializePoolV2) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `TickSpacing` param: + err = encoder.Encode(obj.TickSpacing) + if err != nil { + return err + } + // Serialize `InitialSqrtPrice` param: + err = encoder.Encode(obj.InitialSqrtPrice) + if err != nil { + return err + } + return nil +} +func (obj *InitializePoolV2) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `TickSpacing`: + err = decoder.Decode(&obj.TickSpacing) + if err != nil { + return err + } + // Deserialize `InitialSqrtPrice`: + err = decoder.Decode(&obj.InitialSqrtPrice) + if err != nil { + return err + } + return nil +} + +// NewInitializePoolV2Instruction declares a new InitializePoolV2 instruction with the provided parameters and accounts. +func NewInitializePoolV2Instruction( + // Parameters: + tickSpacing uint16, + initialSqrtPrice ag_binary.Uint128, + // Accounts: + whirlpoolsConfig ag_solanago.PublicKey, + tokenMintA ag_solanago.PublicKey, + tokenMintB ag_solanago.PublicKey, + tokenBadgeA ag_solanago.PublicKey, + tokenBadgeB ag_solanago.PublicKey, + funder ag_solanago.PublicKey, + whirlpool ag_solanago.PublicKey, + tokenVaultA ag_solanago.PublicKey, + tokenVaultB ag_solanago.PublicKey, + feeTier ag_solanago.PublicKey, + tokenProgramA ag_solanago.PublicKey, + tokenProgramB ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey, + rent ag_solanago.PublicKey) *InitializePoolV2 { + return NewInitializePoolV2InstructionBuilder(). + SetTickSpacing(tickSpacing). + SetInitialSqrtPrice(initialSqrtPrice). + SetWhirlpoolsConfigAccount(whirlpoolsConfig). + SetTokenMintAAccount(tokenMintA). + SetTokenMintBAccount(tokenMintB). + SetTokenBadgeAAccount(tokenBadgeA). + SetTokenBadgeBAccount(tokenBadgeB). + SetFunderAccount(funder). + SetWhirlpoolAccount(whirlpool). + SetTokenVaultAAccount(tokenVaultA). + SetTokenVaultBAccount(tokenVaultB). + SetFeeTierAccount(feeTier). + SetTokenProgramAAccount(tokenProgramA). + SetTokenProgramBAccount(tokenProgramB). + SetSystemProgramAccount(systemProgram). + SetRentAccount(rent) +} diff --git a/programs/whirlpool/InitializePoolV2_test.go b/programs/whirlpool/InitializePoolV2_test.go new file mode 100644 index 00000000..f0433f61 --- /dev/null +++ b/programs/whirlpool/InitializePoolV2_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package whirlpool + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_InitializePoolV2(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("InitializePoolV2"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(InitializePoolV2) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(InitializePoolV2) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/InitializePool_test.go b/programs/whirlpool/InitializePool_test.go index 339132d0..57c5a911 100644 --- a/programs/whirlpool/InitializePool_test.go +++ b/programs/whirlpool/InitializePool_test.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "bytes" diff --git a/programs/whirlpool/InitializePositionBundle.go b/programs/whirlpool/InitializePositionBundle.go index 964f20b2..e616488b 100644 --- a/programs/whirlpool/InitializePositionBundle.go +++ b/programs/whirlpool/InitializePositionBundle.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "errors" diff --git a/programs/whirlpool/InitializePositionBundleWithMetadata.go b/programs/whirlpool/InitializePositionBundleWithMetadata.go index 35b33c8e..f6ca51e4 100644 --- a/programs/whirlpool/InitializePositionBundleWithMetadata.go +++ b/programs/whirlpool/InitializePositionBundleWithMetadata.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "errors" diff --git a/programs/whirlpool/InitializePositionBundleWithMetadata_test.go b/programs/whirlpool/InitializePositionBundleWithMetadata_test.go index 4e7bbfae..65a8fbb7 100644 --- a/programs/whirlpool/InitializePositionBundleWithMetadata_test.go +++ b/programs/whirlpool/InitializePositionBundleWithMetadata_test.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "bytes" diff --git a/programs/whirlpool/InitializePositionBundle_test.go b/programs/whirlpool/InitializePositionBundle_test.go index 548ab8a2..00775a86 100644 --- a/programs/whirlpool/InitializePositionBundle_test.go +++ b/programs/whirlpool/InitializePositionBundle_test.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "bytes" diff --git a/programs/whirlpool/InitializeReward.go b/programs/whirlpool/InitializeReward.go index 2131cb04..3f54ca69 100644 --- a/programs/whirlpool/InitializeReward.go +++ b/programs/whirlpool/InitializeReward.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "errors" diff --git a/programs/whirlpool/InitializeRewardV2.go b/programs/whirlpool/InitializeRewardV2.go new file mode 100644 index 00000000..bc66124b --- /dev/null +++ b/programs/whirlpool/InitializeRewardV2.go @@ -0,0 +1,279 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package whirlpool + +import ( + "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" +) + +// InitializeRewardV2 is the `initializeRewardV2` instruction. +type InitializeRewardV2 struct { + RewardIndex *uint8 + + // [0] = [SIGNER] rewardAuthority + // + // [1] = [WRITE, SIGNER] funder + // + // [2] = [WRITE] whirlpool + // + // [3] = [] rewardMint + // + // [4] = [] rewardTokenBadge + // + // [5] = [WRITE, SIGNER] rewardVault + // + // [6] = [] rewardTokenProgram + // + // [7] = [] systemProgram + // + // [8] = [] rent + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewInitializeRewardV2InstructionBuilder creates a new `InitializeRewardV2` instruction builder. +func NewInitializeRewardV2InstructionBuilder() *InitializeRewardV2 { + nd := &InitializeRewardV2{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 9), + } + return nd +} + +// SetRewardIndex sets the "rewardIndex" parameter. +func (inst *InitializeRewardV2) SetRewardIndex(rewardIndex uint8) *InitializeRewardV2 { + inst.RewardIndex = &rewardIndex + return inst +} + +// SetRewardAuthorityAccount sets the "rewardAuthority" account. +func (inst *InitializeRewardV2) SetRewardAuthorityAccount(rewardAuthority ag_solanago.PublicKey) *InitializeRewardV2 { + inst.AccountMetaSlice[0] = ag_solanago.Meta(rewardAuthority).SIGNER() + return inst +} + +// GetRewardAuthorityAccount gets the "rewardAuthority" account. +func (inst *InitializeRewardV2) GetRewardAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetFunderAccount sets the "funder" account. +func (inst *InitializeRewardV2) SetFunderAccount(funder ag_solanago.PublicKey) *InitializeRewardV2 { + inst.AccountMetaSlice[1] = ag_solanago.Meta(funder).WRITE().SIGNER() + return inst +} + +// GetFunderAccount gets the "funder" account. +func (inst *InitializeRewardV2) GetFunderAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetWhirlpoolAccount sets the "whirlpool" account. +func (inst *InitializeRewardV2) SetWhirlpoolAccount(whirlpool ag_solanago.PublicKey) *InitializeRewardV2 { + inst.AccountMetaSlice[2] = ag_solanago.Meta(whirlpool).WRITE() + return inst +} + +// GetWhirlpoolAccount gets the "whirlpool" account. +func (inst *InitializeRewardV2) GetWhirlpoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetRewardMintAccount sets the "rewardMint" account. +func (inst *InitializeRewardV2) SetRewardMintAccount(rewardMint ag_solanago.PublicKey) *InitializeRewardV2 { + inst.AccountMetaSlice[3] = ag_solanago.Meta(rewardMint) + return inst +} + +// GetRewardMintAccount gets the "rewardMint" account. +func (inst *InitializeRewardV2) GetRewardMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetRewardTokenBadgeAccount sets the "rewardTokenBadge" account. +func (inst *InitializeRewardV2) SetRewardTokenBadgeAccount(rewardTokenBadge ag_solanago.PublicKey) *InitializeRewardV2 { + inst.AccountMetaSlice[4] = ag_solanago.Meta(rewardTokenBadge) + return inst +} + +// GetRewardTokenBadgeAccount gets the "rewardTokenBadge" account. +func (inst *InitializeRewardV2) GetRewardTokenBadgeAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetRewardVaultAccount sets the "rewardVault" account. +func (inst *InitializeRewardV2) SetRewardVaultAccount(rewardVault ag_solanago.PublicKey) *InitializeRewardV2 { + inst.AccountMetaSlice[5] = ag_solanago.Meta(rewardVault).WRITE().SIGNER() + return inst +} + +// GetRewardVaultAccount gets the "rewardVault" account. +func (inst *InitializeRewardV2) GetRewardVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetRewardTokenProgramAccount sets the "rewardTokenProgram" account. +func (inst *InitializeRewardV2) SetRewardTokenProgramAccount(rewardTokenProgram ag_solanago.PublicKey) *InitializeRewardV2 { + inst.AccountMetaSlice[6] = ag_solanago.Meta(rewardTokenProgram) + return inst +} + +// GetRewardTokenProgramAccount gets the "rewardTokenProgram" account. +func (inst *InitializeRewardV2) GetRewardTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +func (inst *InitializeRewardV2) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *InitializeRewardV2 { + inst.AccountMetaSlice[7] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +func (inst *InitializeRewardV2) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetRentAccount sets the "rent" account. +func (inst *InitializeRewardV2) SetRentAccount(rent ag_solanago.PublicKey) *InitializeRewardV2 { + inst.AccountMetaSlice[8] = ag_solanago.Meta(rent) + return inst +} + +// GetRentAccount gets the "rent" account. +func (inst *InitializeRewardV2) GetRentAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +func (inst InitializeRewardV2) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_InitializeRewardV2, + }} +} + +// 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 InitializeRewardV2) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *InitializeRewardV2) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.RewardIndex == nil { + return errors.New("RewardIndex parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.RewardAuthority is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Funder is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.Whirlpool is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.RewardMint is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.RewardTokenBadge is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.RewardVault is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.RewardTokenProgram is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.SystemProgram is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.Rent is not set") + } + } + return nil +} + +func (inst *InitializeRewardV2) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("InitializeRewardV2")). + // + 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("RewardIndex", *inst.RewardIndex)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=9]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" rewardAuthority", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" funder", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" whirlpool", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" rewardMint", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" rewardTokenBadge", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" rewardVault", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta("rewardTokenProgram", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" systemProgram", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" rent", inst.AccountMetaSlice.Get(8))) + }) + }) + }) +} + +func (obj InitializeRewardV2) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `RewardIndex` param: + err = encoder.Encode(obj.RewardIndex) + if err != nil { + return err + } + return nil +} +func (obj *InitializeRewardV2) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `RewardIndex`: + err = decoder.Decode(&obj.RewardIndex) + if err != nil { + return err + } + return nil +} + +// NewInitializeRewardV2Instruction declares a new InitializeRewardV2 instruction with the provided parameters and accounts. +func NewInitializeRewardV2Instruction( + // Parameters: + rewardIndex uint8, + // Accounts: + rewardAuthority ag_solanago.PublicKey, + funder ag_solanago.PublicKey, + whirlpool ag_solanago.PublicKey, + rewardMint ag_solanago.PublicKey, + rewardTokenBadge ag_solanago.PublicKey, + rewardVault ag_solanago.PublicKey, + rewardTokenProgram ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey, + rent ag_solanago.PublicKey) *InitializeRewardV2 { + return NewInitializeRewardV2InstructionBuilder(). + SetRewardIndex(rewardIndex). + SetRewardAuthorityAccount(rewardAuthority). + SetFunderAccount(funder). + SetWhirlpoolAccount(whirlpool). + SetRewardMintAccount(rewardMint). + SetRewardTokenBadgeAccount(rewardTokenBadge). + SetRewardVaultAccount(rewardVault). + SetRewardTokenProgramAccount(rewardTokenProgram). + SetSystemProgramAccount(systemProgram). + SetRentAccount(rent) +} diff --git a/programs/whirlpool/InitializeRewardV2_test.go b/programs/whirlpool/InitializeRewardV2_test.go new file mode 100644 index 00000000..27d4faca --- /dev/null +++ b/programs/whirlpool/InitializeRewardV2_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package whirlpool + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_InitializeRewardV2(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("InitializeRewardV2"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(InitializeRewardV2) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(InitializeRewardV2) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/InitializeReward_test.go b/programs/whirlpool/InitializeReward_test.go index 701e12f5..3bb2cf5b 100644 --- a/programs/whirlpool/InitializeReward_test.go +++ b/programs/whirlpool/InitializeReward_test.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "bytes" diff --git a/programs/whirlpool/InitializeTickArray.go b/programs/whirlpool/InitializeTickArray.go index faa83b78..3d6f8afd 100644 --- a/programs/whirlpool/InitializeTickArray.go +++ b/programs/whirlpool/InitializeTickArray.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "errors" diff --git a/programs/whirlpool/InitializeTickArray_test.go b/programs/whirlpool/InitializeTickArray_test.go index 008b3b4e..b38cd116 100644 --- a/programs/whirlpool/InitializeTickArray_test.go +++ b/programs/whirlpool/InitializeTickArray_test.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "bytes" diff --git a/programs/whirlpool/InitializeTokenBadge.go b/programs/whirlpool/InitializeTokenBadge.go new file mode 100644 index 00000000..b426f5eb --- /dev/null +++ b/programs/whirlpool/InitializeTokenBadge.go @@ -0,0 +1,212 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package whirlpool + +import ( + "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" +) + +// InitializeTokenBadge is the `initializeTokenBadge` instruction. +type InitializeTokenBadge struct { + + // [0] = [] whirlpoolsConfig + // + // [1] = [] whirlpoolsConfigExtension + // + // [2] = [SIGNER] tokenBadgeAuthority + // + // [3] = [] tokenMint + // + // [4] = [WRITE] tokenBadge + // + // [5] = [WRITE, SIGNER] funder + // + // [6] = [] systemProgram + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewInitializeTokenBadgeInstructionBuilder creates a new `InitializeTokenBadge` instruction builder. +func NewInitializeTokenBadgeInstructionBuilder() *InitializeTokenBadge { + nd := &InitializeTokenBadge{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 7), + } + return nd +} + +// SetWhirlpoolsConfigAccount sets the "whirlpoolsConfig" account. +func (inst *InitializeTokenBadge) SetWhirlpoolsConfigAccount(whirlpoolsConfig ag_solanago.PublicKey) *InitializeTokenBadge { + inst.AccountMetaSlice[0] = ag_solanago.Meta(whirlpoolsConfig) + return inst +} + +// GetWhirlpoolsConfigAccount gets the "whirlpoolsConfig" account. +func (inst *InitializeTokenBadge) GetWhirlpoolsConfigAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetWhirlpoolsConfigExtensionAccount sets the "whirlpoolsConfigExtension" account. +func (inst *InitializeTokenBadge) SetWhirlpoolsConfigExtensionAccount(whirlpoolsConfigExtension ag_solanago.PublicKey) *InitializeTokenBadge { + inst.AccountMetaSlice[1] = ag_solanago.Meta(whirlpoolsConfigExtension) + return inst +} + +// GetWhirlpoolsConfigExtensionAccount gets the "whirlpoolsConfigExtension" account. +func (inst *InitializeTokenBadge) GetWhirlpoolsConfigExtensionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetTokenBadgeAuthorityAccount sets the "tokenBadgeAuthority" account. +func (inst *InitializeTokenBadge) SetTokenBadgeAuthorityAccount(tokenBadgeAuthority ag_solanago.PublicKey) *InitializeTokenBadge { + inst.AccountMetaSlice[2] = ag_solanago.Meta(tokenBadgeAuthority).SIGNER() + return inst +} + +// GetTokenBadgeAuthorityAccount gets the "tokenBadgeAuthority" account. +func (inst *InitializeTokenBadge) GetTokenBadgeAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetTokenMintAccount sets the "tokenMint" account. +func (inst *InitializeTokenBadge) SetTokenMintAccount(tokenMint ag_solanago.PublicKey) *InitializeTokenBadge { + inst.AccountMetaSlice[3] = ag_solanago.Meta(tokenMint) + return inst +} + +// GetTokenMintAccount gets the "tokenMint" account. +func (inst *InitializeTokenBadge) GetTokenMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetTokenBadgeAccount sets the "tokenBadge" account. +func (inst *InitializeTokenBadge) SetTokenBadgeAccount(tokenBadge ag_solanago.PublicKey) *InitializeTokenBadge { + inst.AccountMetaSlice[4] = ag_solanago.Meta(tokenBadge).WRITE() + return inst +} + +// GetTokenBadgeAccount gets the "tokenBadge" account. +func (inst *InitializeTokenBadge) GetTokenBadgeAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetFunderAccount sets the "funder" account. +func (inst *InitializeTokenBadge) SetFunderAccount(funder ag_solanago.PublicKey) *InitializeTokenBadge { + inst.AccountMetaSlice[5] = ag_solanago.Meta(funder).WRITE().SIGNER() + return inst +} + +// GetFunderAccount gets the "funder" account. +func (inst *InitializeTokenBadge) GetFunderAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +func (inst *InitializeTokenBadge) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *InitializeTokenBadge { + inst.AccountMetaSlice[6] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +func (inst *InitializeTokenBadge) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +func (inst InitializeTokenBadge) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_InitializeTokenBadge, + }} +} + +// 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 InitializeTokenBadge) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *InitializeTokenBadge) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.WhirlpoolsConfig is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.WhirlpoolsConfigExtension is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.TokenBadgeAuthority is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.TokenMint is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.TokenBadge is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.Funder is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.SystemProgram is not set") + } + } + return nil +} + +func (inst *InitializeTokenBadge) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("InitializeTokenBadge")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=7]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" whirlpoolsConfig", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta("whirlpoolsConfigExtension", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" tokenBadgeAuthority", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" tokenMint", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" tokenBadge", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" funder", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" systemProgram", inst.AccountMetaSlice.Get(6))) + }) + }) + }) +} + +func (obj InitializeTokenBadge) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *InitializeTokenBadge) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewInitializeTokenBadgeInstruction declares a new InitializeTokenBadge instruction with the provided parameters and accounts. +func NewInitializeTokenBadgeInstruction( + // Accounts: + whirlpoolsConfig ag_solanago.PublicKey, + whirlpoolsConfigExtension ag_solanago.PublicKey, + tokenBadgeAuthority ag_solanago.PublicKey, + tokenMint ag_solanago.PublicKey, + tokenBadge ag_solanago.PublicKey, + funder ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey) *InitializeTokenBadge { + return NewInitializeTokenBadgeInstructionBuilder(). + SetWhirlpoolsConfigAccount(whirlpoolsConfig). + SetWhirlpoolsConfigExtensionAccount(whirlpoolsConfigExtension). + SetTokenBadgeAuthorityAccount(tokenBadgeAuthority). + SetTokenMintAccount(tokenMint). + SetTokenBadgeAccount(tokenBadge). + SetFunderAccount(funder). + SetSystemProgramAccount(systemProgram) +} diff --git a/programs/whirlpool/InitializeTokenBadge_test.go b/programs/whirlpool/InitializeTokenBadge_test.go new file mode 100644 index 00000000..e8a30377 --- /dev/null +++ b/programs/whirlpool/InitializeTokenBadge_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package whirlpool + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_InitializeTokenBadge(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("InitializeTokenBadge"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(InitializeTokenBadge) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(InitializeTokenBadge) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/OpenBundledPosition.go b/programs/whirlpool/OpenBundledPosition.go index 65b47136..2f53bbc2 100644 --- a/programs/whirlpool/OpenBundledPosition.go +++ b/programs/whirlpool/OpenBundledPosition.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "errors" diff --git a/programs/whirlpool/OpenBundledPosition_test.go b/programs/whirlpool/OpenBundledPosition_test.go index 2494800b..0479c997 100644 --- a/programs/whirlpool/OpenBundledPosition_test.go +++ b/programs/whirlpool/OpenBundledPosition_test.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "bytes" diff --git a/programs/whirlpool/OpenPosition.go b/programs/whirlpool/OpenPosition.go index 114e77a5..cb11a51b 100644 --- a/programs/whirlpool/OpenPosition.go +++ b/programs/whirlpool/OpenPosition.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "errors" diff --git a/programs/whirlpool/OpenPositionWithMetadata.go b/programs/whirlpool/OpenPositionWithMetadata.go index aa744130..3ab25d71 100644 --- a/programs/whirlpool/OpenPositionWithMetadata.go +++ b/programs/whirlpool/OpenPositionWithMetadata.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "errors" diff --git a/programs/whirlpool/OpenPositionWithMetadata_test.go b/programs/whirlpool/OpenPositionWithMetadata_test.go index cd638155..e4f52c46 100644 --- a/programs/whirlpool/OpenPositionWithMetadata_test.go +++ b/programs/whirlpool/OpenPositionWithMetadata_test.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "bytes" diff --git a/programs/whirlpool/OpenPosition_test.go b/programs/whirlpool/OpenPosition_test.go index f89e9c97..c326791c 100644 --- a/programs/whirlpool/OpenPosition_test.go +++ b/programs/whirlpool/OpenPosition_test.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "bytes" diff --git a/programs/whirlpool/SetCollectProtocolFeesAuthority.go b/programs/whirlpool/SetCollectProtocolFeesAuthority.go index 7f12da6f..876bcdfc 100644 --- a/programs/whirlpool/SetCollectProtocolFeesAuthority.go +++ b/programs/whirlpool/SetCollectProtocolFeesAuthority.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "errors" diff --git a/programs/whirlpool/SetCollectProtocolFeesAuthority_test.go b/programs/whirlpool/SetCollectProtocolFeesAuthority_test.go index 5c03e519..520a7814 100644 --- a/programs/whirlpool/SetCollectProtocolFeesAuthority_test.go +++ b/programs/whirlpool/SetCollectProtocolFeesAuthority_test.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "bytes" diff --git a/programs/whirlpool/SetConfigExtensionAuthority.go b/programs/whirlpool/SetConfigExtensionAuthority.go new file mode 100644 index 00000000..911f5aab --- /dev/null +++ b/programs/whirlpool/SetConfigExtensionAuthority.go @@ -0,0 +1,155 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package whirlpool + +import ( + "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" +) + +// SetConfigExtensionAuthority is the `setConfigExtensionAuthority` instruction. +type SetConfigExtensionAuthority struct { + + // [0] = [] whirlpoolsConfig + // + // [1] = [WRITE] whirlpoolsConfigExtension + // + // [2] = [SIGNER] configExtensionAuthority + // + // [3] = [] newConfigExtensionAuthority + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewSetConfigExtensionAuthorityInstructionBuilder creates a new `SetConfigExtensionAuthority` instruction builder. +func NewSetConfigExtensionAuthorityInstructionBuilder() *SetConfigExtensionAuthority { + nd := &SetConfigExtensionAuthority{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 4), + } + return nd +} + +// SetWhirlpoolsConfigAccount sets the "whirlpoolsConfig" account. +func (inst *SetConfigExtensionAuthority) SetWhirlpoolsConfigAccount(whirlpoolsConfig ag_solanago.PublicKey) *SetConfigExtensionAuthority { + inst.AccountMetaSlice[0] = ag_solanago.Meta(whirlpoolsConfig) + return inst +} + +// GetWhirlpoolsConfigAccount gets the "whirlpoolsConfig" account. +func (inst *SetConfigExtensionAuthority) GetWhirlpoolsConfigAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetWhirlpoolsConfigExtensionAccount sets the "whirlpoolsConfigExtension" account. +func (inst *SetConfigExtensionAuthority) SetWhirlpoolsConfigExtensionAccount(whirlpoolsConfigExtension ag_solanago.PublicKey) *SetConfigExtensionAuthority { + inst.AccountMetaSlice[1] = ag_solanago.Meta(whirlpoolsConfigExtension).WRITE() + return inst +} + +// GetWhirlpoolsConfigExtensionAccount gets the "whirlpoolsConfigExtension" account. +func (inst *SetConfigExtensionAuthority) GetWhirlpoolsConfigExtensionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetConfigExtensionAuthorityAccount sets the "configExtensionAuthority" account. +func (inst *SetConfigExtensionAuthority) SetConfigExtensionAuthorityAccount(configExtensionAuthority ag_solanago.PublicKey) *SetConfigExtensionAuthority { + inst.AccountMetaSlice[2] = ag_solanago.Meta(configExtensionAuthority).SIGNER() + return inst +} + +// GetConfigExtensionAuthorityAccount gets the "configExtensionAuthority" account. +func (inst *SetConfigExtensionAuthority) GetConfigExtensionAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetNewConfigExtensionAuthorityAccount sets the "newConfigExtensionAuthority" account. +func (inst *SetConfigExtensionAuthority) SetNewConfigExtensionAuthorityAccount(newConfigExtensionAuthority ag_solanago.PublicKey) *SetConfigExtensionAuthority { + inst.AccountMetaSlice[3] = ag_solanago.Meta(newConfigExtensionAuthority) + return inst +} + +// GetNewConfigExtensionAuthorityAccount gets the "newConfigExtensionAuthority" account. +func (inst *SetConfigExtensionAuthority) GetNewConfigExtensionAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +func (inst SetConfigExtensionAuthority) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_SetConfigExtensionAuthority, + }} +} + +// 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 SetConfigExtensionAuthority) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *SetConfigExtensionAuthority) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.WhirlpoolsConfig is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.WhirlpoolsConfigExtension is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.ConfigExtensionAuthority is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.NewConfigExtensionAuthority is not set") + } + } + return nil +} + +func (inst *SetConfigExtensionAuthority) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("SetConfigExtensionAuthority")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=4]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" whirlpoolsConfig", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" whirlpoolsConfigExtension", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" configExtensionAuthority", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta("newConfigExtensionAuthority", inst.AccountMetaSlice.Get(3))) + }) + }) + }) +} + +func (obj SetConfigExtensionAuthority) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *SetConfigExtensionAuthority) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewSetConfigExtensionAuthorityInstruction declares a new SetConfigExtensionAuthority instruction with the provided parameters and accounts. +func NewSetConfigExtensionAuthorityInstruction( + // Accounts: + whirlpoolsConfig ag_solanago.PublicKey, + whirlpoolsConfigExtension ag_solanago.PublicKey, + configExtensionAuthority ag_solanago.PublicKey, + newConfigExtensionAuthority ag_solanago.PublicKey) *SetConfigExtensionAuthority { + return NewSetConfigExtensionAuthorityInstructionBuilder(). + SetWhirlpoolsConfigAccount(whirlpoolsConfig). + SetWhirlpoolsConfigExtensionAccount(whirlpoolsConfigExtension). + SetConfigExtensionAuthorityAccount(configExtensionAuthority). + SetNewConfigExtensionAuthorityAccount(newConfigExtensionAuthority) +} diff --git a/programs/whirlpool/SetConfigExtensionAuthority_test.go b/programs/whirlpool/SetConfigExtensionAuthority_test.go new file mode 100644 index 00000000..2abc7acf --- /dev/null +++ b/programs/whirlpool/SetConfigExtensionAuthority_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package whirlpool + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_SetConfigExtensionAuthority(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("SetConfigExtensionAuthority"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(SetConfigExtensionAuthority) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(SetConfigExtensionAuthority) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/SetDefaultFeeRate.go b/programs/whirlpool/SetDefaultFeeRate.go index a9790aaf..26084ae7 100644 --- a/programs/whirlpool/SetDefaultFeeRate.go +++ b/programs/whirlpool/SetDefaultFeeRate.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "errors" diff --git a/programs/whirlpool/SetDefaultFeeRate_test.go b/programs/whirlpool/SetDefaultFeeRate_test.go index b636bdc4..45d9338a 100644 --- a/programs/whirlpool/SetDefaultFeeRate_test.go +++ b/programs/whirlpool/SetDefaultFeeRate_test.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "bytes" diff --git a/programs/whirlpool/SetDefaultProtocolFeeRate.go b/programs/whirlpool/SetDefaultProtocolFeeRate.go index 8af69b67..972044e3 100644 --- a/programs/whirlpool/SetDefaultProtocolFeeRate.go +++ b/programs/whirlpool/SetDefaultProtocolFeeRate.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "errors" diff --git a/programs/whirlpool/SetDefaultProtocolFeeRate_test.go b/programs/whirlpool/SetDefaultProtocolFeeRate_test.go index 37a028a3..e31efba4 100644 --- a/programs/whirlpool/SetDefaultProtocolFeeRate_test.go +++ b/programs/whirlpool/SetDefaultProtocolFeeRate_test.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "bytes" diff --git a/programs/whirlpool/SetFeeAuthority.go b/programs/whirlpool/SetFeeAuthority.go index 23020f11..13533b2f 100644 --- a/programs/whirlpool/SetFeeAuthority.go +++ b/programs/whirlpool/SetFeeAuthority.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "errors" diff --git a/programs/whirlpool/SetFeeAuthority_test.go b/programs/whirlpool/SetFeeAuthority_test.go index c3382a2a..9520a0fb 100644 --- a/programs/whirlpool/SetFeeAuthority_test.go +++ b/programs/whirlpool/SetFeeAuthority_test.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "bytes" diff --git a/programs/whirlpool/SetFeeRate.go b/programs/whirlpool/SetFeeRate.go index 222f49fe..6fbfb6c7 100644 --- a/programs/whirlpool/SetFeeRate.go +++ b/programs/whirlpool/SetFeeRate.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "errors" diff --git a/programs/whirlpool/SetFeeRate_test.go b/programs/whirlpool/SetFeeRate_test.go index ffb722d1..f4b5264a 100644 --- a/programs/whirlpool/SetFeeRate_test.go +++ b/programs/whirlpool/SetFeeRate_test.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "bytes" diff --git a/programs/whirlpool/SetProtocolFeeRate.go b/programs/whirlpool/SetProtocolFeeRate.go index ec97bf0d..31ec6b8c 100644 --- a/programs/whirlpool/SetProtocolFeeRate.go +++ b/programs/whirlpool/SetProtocolFeeRate.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "errors" diff --git a/programs/whirlpool/SetProtocolFeeRate_test.go b/programs/whirlpool/SetProtocolFeeRate_test.go index 9023c3ae..b9c86074 100644 --- a/programs/whirlpool/SetProtocolFeeRate_test.go +++ b/programs/whirlpool/SetProtocolFeeRate_test.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "bytes" diff --git a/programs/whirlpool/SetRewardAuthority.go b/programs/whirlpool/SetRewardAuthority.go index f39b4271..2fd4088a 100644 --- a/programs/whirlpool/SetRewardAuthority.go +++ b/programs/whirlpool/SetRewardAuthority.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "errors" diff --git a/programs/whirlpool/SetRewardAuthorityBySuperAuthority.go b/programs/whirlpool/SetRewardAuthorityBySuperAuthority.go index c321efd7..772a87ce 100644 --- a/programs/whirlpool/SetRewardAuthorityBySuperAuthority.go +++ b/programs/whirlpool/SetRewardAuthorityBySuperAuthority.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "errors" diff --git a/programs/whirlpool/SetRewardAuthorityBySuperAuthority_test.go b/programs/whirlpool/SetRewardAuthorityBySuperAuthority_test.go index 29360b4d..b1753a3c 100644 --- a/programs/whirlpool/SetRewardAuthorityBySuperAuthority_test.go +++ b/programs/whirlpool/SetRewardAuthorityBySuperAuthority_test.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "bytes" diff --git a/programs/whirlpool/SetRewardAuthority_test.go b/programs/whirlpool/SetRewardAuthority_test.go index ab81692f..629a5692 100644 --- a/programs/whirlpool/SetRewardAuthority_test.go +++ b/programs/whirlpool/SetRewardAuthority_test.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "bytes" diff --git a/programs/whirlpool/SetRewardEmissions.go b/programs/whirlpool/SetRewardEmissions.go index 93c405e8..5d7b9a5a 100644 --- a/programs/whirlpool/SetRewardEmissions.go +++ b/programs/whirlpool/SetRewardEmissions.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "errors" diff --git a/programs/whirlpool/SetRewardEmissionsSuperAuthority.go b/programs/whirlpool/SetRewardEmissionsSuperAuthority.go index a2ede32b..58e35357 100644 --- a/programs/whirlpool/SetRewardEmissionsSuperAuthority.go +++ b/programs/whirlpool/SetRewardEmissionsSuperAuthority.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "errors" diff --git a/programs/whirlpool/SetRewardEmissionsSuperAuthority_test.go b/programs/whirlpool/SetRewardEmissionsSuperAuthority_test.go index 9501fd79..8ba14f28 100644 --- a/programs/whirlpool/SetRewardEmissionsSuperAuthority_test.go +++ b/programs/whirlpool/SetRewardEmissionsSuperAuthority_test.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "bytes" diff --git a/programs/whirlpool/SetRewardEmissionsV2.go b/programs/whirlpool/SetRewardEmissionsV2.go new file mode 100644 index 00000000..c373cac1 --- /dev/null +++ b/programs/whirlpool/SetRewardEmissionsV2.go @@ -0,0 +1,188 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package whirlpool + +import ( + "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" +) + +// SetRewardEmissionsV2 is the `setRewardEmissionsV2` instruction. +type SetRewardEmissionsV2 struct { + RewardIndex *uint8 + EmissionsPerSecondX64 *ag_binary.Uint128 + + // [0] = [WRITE] whirlpool + // + // [1] = [SIGNER] rewardAuthority + // + // [2] = [] rewardVault + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewSetRewardEmissionsV2InstructionBuilder creates a new `SetRewardEmissionsV2` instruction builder. +func NewSetRewardEmissionsV2InstructionBuilder() *SetRewardEmissionsV2 { + nd := &SetRewardEmissionsV2{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 3), + } + return nd +} + +// SetRewardIndex sets the "rewardIndex" parameter. +func (inst *SetRewardEmissionsV2) SetRewardIndex(rewardIndex uint8) *SetRewardEmissionsV2 { + inst.RewardIndex = &rewardIndex + return inst +} + +// SetEmissionsPerSecondX64 sets the "emissionsPerSecondX64" parameter. +func (inst *SetRewardEmissionsV2) SetEmissionsPerSecondX64(emissionsPerSecondX64 ag_binary.Uint128) *SetRewardEmissionsV2 { + inst.EmissionsPerSecondX64 = &emissionsPerSecondX64 + return inst +} + +// SetWhirlpoolAccount sets the "whirlpool" account. +func (inst *SetRewardEmissionsV2) SetWhirlpoolAccount(whirlpool ag_solanago.PublicKey) *SetRewardEmissionsV2 { + inst.AccountMetaSlice[0] = ag_solanago.Meta(whirlpool).WRITE() + return inst +} + +// GetWhirlpoolAccount gets the "whirlpool" account. +func (inst *SetRewardEmissionsV2) GetWhirlpoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetRewardAuthorityAccount sets the "rewardAuthority" account. +func (inst *SetRewardEmissionsV2) SetRewardAuthorityAccount(rewardAuthority ag_solanago.PublicKey) *SetRewardEmissionsV2 { + inst.AccountMetaSlice[1] = ag_solanago.Meta(rewardAuthority).SIGNER() + return inst +} + +// GetRewardAuthorityAccount gets the "rewardAuthority" account. +func (inst *SetRewardEmissionsV2) GetRewardAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetRewardVaultAccount sets the "rewardVault" account. +func (inst *SetRewardEmissionsV2) SetRewardVaultAccount(rewardVault ag_solanago.PublicKey) *SetRewardEmissionsV2 { + inst.AccountMetaSlice[2] = ag_solanago.Meta(rewardVault) + return inst +} + +// GetRewardVaultAccount gets the "rewardVault" account. +func (inst *SetRewardEmissionsV2) GetRewardVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +func (inst SetRewardEmissionsV2) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_SetRewardEmissionsV2, + }} +} + +// 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 SetRewardEmissionsV2) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *SetRewardEmissionsV2) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.RewardIndex == nil { + return errors.New("RewardIndex parameter is not set") + } + if inst.EmissionsPerSecondX64 == nil { + return errors.New("EmissionsPerSecondX64 parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Whirlpool is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.RewardAuthority is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.RewardVault is not set") + } + } + return nil +} + +func (inst *SetRewardEmissionsV2) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("SetRewardEmissionsV2")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=2]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" RewardIndex", *inst.RewardIndex)) + paramsBranch.Child(ag_format.Param("EmissionsPerSecondX64", *inst.EmissionsPerSecondX64)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=3]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" whirlpool", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta("rewardAuthority", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" rewardVault", inst.AccountMetaSlice.Get(2))) + }) + }) + }) +} + +func (obj SetRewardEmissionsV2) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `RewardIndex` param: + err = encoder.Encode(obj.RewardIndex) + if err != nil { + return err + } + // Serialize `EmissionsPerSecondX64` param: + err = encoder.Encode(obj.EmissionsPerSecondX64) + if err != nil { + return err + } + return nil +} +func (obj *SetRewardEmissionsV2) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `RewardIndex`: + err = decoder.Decode(&obj.RewardIndex) + if err != nil { + return err + } + // Deserialize `EmissionsPerSecondX64`: + err = decoder.Decode(&obj.EmissionsPerSecondX64) + if err != nil { + return err + } + return nil +} + +// NewSetRewardEmissionsV2Instruction declares a new SetRewardEmissionsV2 instruction with the provided parameters and accounts. +func NewSetRewardEmissionsV2Instruction( + // Parameters: + rewardIndex uint8, + emissionsPerSecondX64 ag_binary.Uint128, + // Accounts: + whirlpool ag_solanago.PublicKey, + rewardAuthority ag_solanago.PublicKey, + rewardVault ag_solanago.PublicKey) *SetRewardEmissionsV2 { + return NewSetRewardEmissionsV2InstructionBuilder(). + SetRewardIndex(rewardIndex). + SetEmissionsPerSecondX64(emissionsPerSecondX64). + SetWhirlpoolAccount(whirlpool). + SetRewardAuthorityAccount(rewardAuthority). + SetRewardVaultAccount(rewardVault) +} diff --git a/programs/whirlpool/SetRewardEmissionsV2_test.go b/programs/whirlpool/SetRewardEmissionsV2_test.go new file mode 100644 index 00000000..4dd3aa1c --- /dev/null +++ b/programs/whirlpool/SetRewardEmissionsV2_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package whirlpool + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_SetRewardEmissionsV2(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("SetRewardEmissionsV2"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(SetRewardEmissionsV2) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(SetRewardEmissionsV2) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/SetRewardEmissions_test.go b/programs/whirlpool/SetRewardEmissions_test.go index 67c1dde9..abf4205d 100644 --- a/programs/whirlpool/SetRewardEmissions_test.go +++ b/programs/whirlpool/SetRewardEmissions_test.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "bytes" diff --git a/programs/whirlpool/SetTokenBadgeAuthority.go b/programs/whirlpool/SetTokenBadgeAuthority.go new file mode 100644 index 00000000..3d0da1b7 --- /dev/null +++ b/programs/whirlpool/SetTokenBadgeAuthority.go @@ -0,0 +1,155 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package whirlpool + +import ( + "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" +) + +// SetTokenBadgeAuthority is the `setTokenBadgeAuthority` instruction. +type SetTokenBadgeAuthority struct { + + // [0] = [] whirlpoolsConfig + // + // [1] = [WRITE] whirlpoolsConfigExtension + // + // [2] = [SIGNER] configExtensionAuthority + // + // [3] = [] newTokenBadgeAuthority + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewSetTokenBadgeAuthorityInstructionBuilder creates a new `SetTokenBadgeAuthority` instruction builder. +func NewSetTokenBadgeAuthorityInstructionBuilder() *SetTokenBadgeAuthority { + nd := &SetTokenBadgeAuthority{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 4), + } + return nd +} + +// SetWhirlpoolsConfigAccount sets the "whirlpoolsConfig" account. +func (inst *SetTokenBadgeAuthority) SetWhirlpoolsConfigAccount(whirlpoolsConfig ag_solanago.PublicKey) *SetTokenBadgeAuthority { + inst.AccountMetaSlice[0] = ag_solanago.Meta(whirlpoolsConfig) + return inst +} + +// GetWhirlpoolsConfigAccount gets the "whirlpoolsConfig" account. +func (inst *SetTokenBadgeAuthority) GetWhirlpoolsConfigAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetWhirlpoolsConfigExtensionAccount sets the "whirlpoolsConfigExtension" account. +func (inst *SetTokenBadgeAuthority) SetWhirlpoolsConfigExtensionAccount(whirlpoolsConfigExtension ag_solanago.PublicKey) *SetTokenBadgeAuthority { + inst.AccountMetaSlice[1] = ag_solanago.Meta(whirlpoolsConfigExtension).WRITE() + return inst +} + +// GetWhirlpoolsConfigExtensionAccount gets the "whirlpoolsConfigExtension" account. +func (inst *SetTokenBadgeAuthority) GetWhirlpoolsConfigExtensionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetConfigExtensionAuthorityAccount sets the "configExtensionAuthority" account. +func (inst *SetTokenBadgeAuthority) SetConfigExtensionAuthorityAccount(configExtensionAuthority ag_solanago.PublicKey) *SetTokenBadgeAuthority { + inst.AccountMetaSlice[2] = ag_solanago.Meta(configExtensionAuthority).SIGNER() + return inst +} + +// GetConfigExtensionAuthorityAccount gets the "configExtensionAuthority" account. +func (inst *SetTokenBadgeAuthority) GetConfigExtensionAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetNewTokenBadgeAuthorityAccount sets the "newTokenBadgeAuthority" account. +func (inst *SetTokenBadgeAuthority) SetNewTokenBadgeAuthorityAccount(newTokenBadgeAuthority ag_solanago.PublicKey) *SetTokenBadgeAuthority { + inst.AccountMetaSlice[3] = ag_solanago.Meta(newTokenBadgeAuthority) + return inst +} + +// GetNewTokenBadgeAuthorityAccount gets the "newTokenBadgeAuthority" account. +func (inst *SetTokenBadgeAuthority) GetNewTokenBadgeAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +func (inst SetTokenBadgeAuthority) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_SetTokenBadgeAuthority, + }} +} + +// 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 SetTokenBadgeAuthority) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *SetTokenBadgeAuthority) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.WhirlpoolsConfig is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.WhirlpoolsConfigExtension is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.ConfigExtensionAuthority is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.NewTokenBadgeAuthority is not set") + } + } + return nil +} + +func (inst *SetTokenBadgeAuthority) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("SetTokenBadgeAuthority")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=4]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" whirlpoolsConfig", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta("whirlpoolsConfigExtension", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" configExtensionAuthority", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" newTokenBadgeAuthority", inst.AccountMetaSlice.Get(3))) + }) + }) + }) +} + +func (obj SetTokenBadgeAuthority) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *SetTokenBadgeAuthority) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewSetTokenBadgeAuthorityInstruction declares a new SetTokenBadgeAuthority instruction with the provided parameters and accounts. +func NewSetTokenBadgeAuthorityInstruction( + // Accounts: + whirlpoolsConfig ag_solanago.PublicKey, + whirlpoolsConfigExtension ag_solanago.PublicKey, + configExtensionAuthority ag_solanago.PublicKey, + newTokenBadgeAuthority ag_solanago.PublicKey) *SetTokenBadgeAuthority { + return NewSetTokenBadgeAuthorityInstructionBuilder(). + SetWhirlpoolsConfigAccount(whirlpoolsConfig). + SetWhirlpoolsConfigExtensionAccount(whirlpoolsConfigExtension). + SetConfigExtensionAuthorityAccount(configExtensionAuthority). + SetNewTokenBadgeAuthorityAccount(newTokenBadgeAuthority) +} diff --git a/programs/whirlpool/SetTokenBadgeAuthority_test.go b/programs/whirlpool/SetTokenBadgeAuthority_test.go new file mode 100644 index 00000000..660c611a --- /dev/null +++ b/programs/whirlpool/SetTokenBadgeAuthority_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package whirlpool + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_SetTokenBadgeAuthority(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("SetTokenBadgeAuthority"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(SetTokenBadgeAuthority) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(SetTokenBadgeAuthority) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/Swap.go b/programs/whirlpool/Swap.go index bb28478d..6fc3ac81 100644 --- a/programs/whirlpool/Swap.go +++ b/programs/whirlpool/Swap.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "errors" diff --git a/programs/whirlpool/SwapV2.go b/programs/whirlpool/SwapV2.go new file mode 100644 index 00000000..a4022cb1 --- /dev/null +++ b/programs/whirlpool/SwapV2.go @@ -0,0 +1,526 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package whirlpool + +import ( + "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" +) + +// SwapV2 is the `swapV2` instruction. +type SwapV2 struct { + Amount *uint64 + OtherAmountThreshold *uint64 + SqrtPriceLimit *ag_binary.Uint128 + AmountSpecifiedIsInput *bool + AToB *bool + RemainingAccountsInfo *RemainingAccountsInfo `bin:"optional"` + + // [0] = [] tokenProgramA + // + // [1] = [] tokenProgramB + // + // [2] = [] memoProgram + // + // [3] = [SIGNER] tokenAuthority + // + // [4] = [WRITE] whirlpool + // + // [5] = [] tokenMintA + // + // [6] = [] tokenMintB + // + // [7] = [WRITE] tokenOwnerAccountA + // + // [8] = [WRITE] tokenVaultA + // + // [9] = [WRITE] tokenOwnerAccountB + // + // [10] = [WRITE] tokenVaultB + // + // [11] = [WRITE] tickArray0 + // + // [12] = [WRITE] tickArray1 + // + // [13] = [WRITE] tickArray2 + // + // [14] = [WRITE] oracle + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewSwapV2InstructionBuilder creates a new `SwapV2` instruction builder. +func NewSwapV2InstructionBuilder() *SwapV2 { + nd := &SwapV2{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 15), + } + return nd +} + +// SetAmount sets the "amount" parameter. +func (inst *SwapV2) SetAmount(amount uint64) *SwapV2 { + inst.Amount = &amount + return inst +} + +// SetOtherAmountThreshold sets the "otherAmountThreshold" parameter. +func (inst *SwapV2) SetOtherAmountThreshold(otherAmountThreshold uint64) *SwapV2 { + inst.OtherAmountThreshold = &otherAmountThreshold + return inst +} + +// SetSqrtPriceLimit sets the "sqrtPriceLimit" parameter. +func (inst *SwapV2) SetSqrtPriceLimit(sqrtPriceLimit ag_binary.Uint128) *SwapV2 { + inst.SqrtPriceLimit = &sqrtPriceLimit + return inst +} + +// SetAmountSpecifiedIsInput sets the "amountSpecifiedIsInput" parameter. +func (inst *SwapV2) SetAmountSpecifiedIsInput(amountSpecifiedIsInput bool) *SwapV2 { + inst.AmountSpecifiedIsInput = &amountSpecifiedIsInput + return inst +} + +// SetAToB sets the "aToB" parameter. +func (inst *SwapV2) SetAToB(aToB bool) *SwapV2 { + inst.AToB = &aToB + return inst +} + +// SetRemainingAccountsInfo sets the "remainingAccountsInfo" parameter. +func (inst *SwapV2) SetRemainingAccountsInfo(remainingAccountsInfo RemainingAccountsInfo) *SwapV2 { + inst.RemainingAccountsInfo = &remainingAccountsInfo + return inst +} + +// SetTokenProgramAAccount sets the "tokenProgramA" account. +func (inst *SwapV2) SetTokenProgramAAccount(tokenProgramA ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[0] = ag_solanago.Meta(tokenProgramA) + return inst +} + +// GetTokenProgramAAccount gets the "tokenProgramA" account. +func (inst *SwapV2) GetTokenProgramAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetTokenProgramBAccount sets the "tokenProgramB" account. +func (inst *SwapV2) SetTokenProgramBAccount(tokenProgramB ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[1] = ag_solanago.Meta(tokenProgramB) + return inst +} + +// GetTokenProgramBAccount gets the "tokenProgramB" account. +func (inst *SwapV2) GetTokenProgramBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetMemoProgramAccount sets the "memoProgram" account. +func (inst *SwapV2) SetMemoProgramAccount(memoProgram ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[2] = ag_solanago.Meta(memoProgram) + return inst +} + +// GetMemoProgramAccount gets the "memoProgram" account. +func (inst *SwapV2) GetMemoProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetTokenAuthorityAccount sets the "tokenAuthority" account. +func (inst *SwapV2) SetTokenAuthorityAccount(tokenAuthority ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[3] = ag_solanago.Meta(tokenAuthority).SIGNER() + return inst +} + +// GetTokenAuthorityAccount gets the "tokenAuthority" account. +func (inst *SwapV2) GetTokenAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetWhirlpoolAccount sets the "whirlpool" account. +func (inst *SwapV2) SetWhirlpoolAccount(whirlpool ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[4] = ag_solanago.Meta(whirlpool).WRITE() + return inst +} + +// GetWhirlpoolAccount gets the "whirlpool" account. +func (inst *SwapV2) GetWhirlpoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetTokenMintAAccount sets the "tokenMintA" account. +func (inst *SwapV2) SetTokenMintAAccount(tokenMintA ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[5] = ag_solanago.Meta(tokenMintA) + return inst +} + +// GetTokenMintAAccount gets the "tokenMintA" account. +func (inst *SwapV2) GetTokenMintAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetTokenMintBAccount sets the "tokenMintB" account. +func (inst *SwapV2) SetTokenMintBAccount(tokenMintB ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[6] = ag_solanago.Meta(tokenMintB) + return inst +} + +// GetTokenMintBAccount gets the "tokenMintB" account. +func (inst *SwapV2) GetTokenMintBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetTokenOwnerAccountAAccount sets the "tokenOwnerAccountA" account. +func (inst *SwapV2) SetTokenOwnerAccountAAccount(tokenOwnerAccountA ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[7] = ag_solanago.Meta(tokenOwnerAccountA).WRITE() + return inst +} + +// GetTokenOwnerAccountAAccount gets the "tokenOwnerAccountA" account. +func (inst *SwapV2) GetTokenOwnerAccountAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetTokenVaultAAccount sets the "tokenVaultA" account. +func (inst *SwapV2) SetTokenVaultAAccount(tokenVaultA ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[8] = ag_solanago.Meta(tokenVaultA).WRITE() + return inst +} + +// GetTokenVaultAAccount gets the "tokenVaultA" account. +func (inst *SwapV2) GetTokenVaultAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetTokenOwnerAccountBAccount sets the "tokenOwnerAccountB" account. +func (inst *SwapV2) SetTokenOwnerAccountBAccount(tokenOwnerAccountB ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[9] = ag_solanago.Meta(tokenOwnerAccountB).WRITE() + return inst +} + +// GetTokenOwnerAccountBAccount gets the "tokenOwnerAccountB" account. +func (inst *SwapV2) GetTokenOwnerAccountBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetTokenVaultBAccount sets the "tokenVaultB" account. +func (inst *SwapV2) SetTokenVaultBAccount(tokenVaultB ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[10] = ag_solanago.Meta(tokenVaultB).WRITE() + return inst +} + +// GetTokenVaultBAccount gets the "tokenVaultB" account. +func (inst *SwapV2) GetTokenVaultBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetTickArray0Account sets the "tickArray0" account. +func (inst *SwapV2) SetTickArray0Account(tickArray0 ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[11] = ag_solanago.Meta(tickArray0).WRITE() + return inst +} + +// GetTickArray0Account gets the "tickArray0" account. +func (inst *SwapV2) GetTickArray0Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetTickArray1Account sets the "tickArray1" account. +func (inst *SwapV2) SetTickArray1Account(tickArray1 ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[12] = ag_solanago.Meta(tickArray1).WRITE() + return inst +} + +// GetTickArray1Account gets the "tickArray1" account. +func (inst *SwapV2) GetTickArray1Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetTickArray2Account sets the "tickArray2" account. +func (inst *SwapV2) SetTickArray2Account(tickArray2 ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[13] = ag_solanago.Meta(tickArray2).WRITE() + return inst +} + +// GetTickArray2Account gets the "tickArray2" account. +func (inst *SwapV2) GetTickArray2Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetOracleAccount sets the "oracle" account. +func (inst *SwapV2) SetOracleAccount(oracle ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[14] = ag_solanago.Meta(oracle).WRITE() + return inst +} + +// GetOracleAccount gets the "oracle" account. +func (inst *SwapV2) GetOracleAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +func (inst SwapV2) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_SwapV2, + }} +} + +// 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 SwapV2) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *SwapV2) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.Amount == nil { + return errors.New("Amount parameter is not set") + } + if inst.OtherAmountThreshold == nil { + return errors.New("OtherAmountThreshold parameter is not set") + } + if inst.SqrtPriceLimit == nil { + return errors.New("SqrtPriceLimit parameter is not set") + } + if inst.AmountSpecifiedIsInput == nil { + return errors.New("AmountSpecifiedIsInput parameter is not set") + } + if inst.AToB == nil { + return errors.New("AToB parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.TokenProgramA is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.TokenProgramB is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.MemoProgram is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.TokenAuthority is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.Whirlpool is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.TokenMintA is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.TokenMintB is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.TokenOwnerAccountA is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.TokenVaultA is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.TokenOwnerAccountB is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.TokenVaultB is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.TickArray0 is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.TickArray1 is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.TickArray2 is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.Oracle is not set") + } + } + return nil +} + +func (inst *SwapV2) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("SwapV2")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=6]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" Amount", *inst.Amount)) + paramsBranch.Child(ag_format.Param(" OtherAmountThreshold", *inst.OtherAmountThreshold)) + paramsBranch.Child(ag_format.Param(" SqrtPriceLimit", *inst.SqrtPriceLimit)) + paramsBranch.Child(ag_format.Param("AmountSpecifiedIsInput", *inst.AmountSpecifiedIsInput)) + paramsBranch.Child(ag_format.Param(" AToB", *inst.AToB)) + paramsBranch.Child(ag_format.Param(" RemainingAccountsInfo (OPT)", inst.RemainingAccountsInfo)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=15]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" tokenProgramA", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" tokenProgramB", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" memoProgram", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" tokenAuthority", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" whirlpool", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" tokenMintA", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" tokenMintB", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta("tokenOwnerAccountA", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" tokenVaultA", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta("tokenOwnerAccountB", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" tokenVaultB", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" tickArray0", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" tickArray1", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" tickArray2", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta(" oracle", inst.AccountMetaSlice.Get(14))) + }) + }) + }) +} + +func (obj SwapV2) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Amount` param: + err = encoder.Encode(obj.Amount) + if err != nil { + return err + } + // Serialize `OtherAmountThreshold` param: + err = encoder.Encode(obj.OtherAmountThreshold) + if err != nil { + return err + } + // Serialize `SqrtPriceLimit` param: + err = encoder.Encode(obj.SqrtPriceLimit) + if err != nil { + return err + } + // Serialize `AmountSpecifiedIsInput` param: + err = encoder.Encode(obj.AmountSpecifiedIsInput) + if err != nil { + return err + } + // Serialize `AToB` param: + err = encoder.Encode(obj.AToB) + if err != nil { + return err + } + // Serialize `RemainingAccountsInfo` param (optional): + { + if obj.RemainingAccountsInfo == nil { + err = encoder.WriteBool(false) + if err != nil { + return err + } + } else { + err = encoder.WriteBool(true) + if err != nil { + return err + } + err = encoder.Encode(obj.RemainingAccountsInfo) + if err != nil { + return err + } + } + } + return nil +} +func (obj *SwapV2) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Amount`: + err = decoder.Decode(&obj.Amount) + if err != nil { + return err + } + // Deserialize `OtherAmountThreshold`: + err = decoder.Decode(&obj.OtherAmountThreshold) + if err != nil { + return err + } + // Deserialize `SqrtPriceLimit`: + err = decoder.Decode(&obj.SqrtPriceLimit) + if err != nil { + return err + } + // Deserialize `AmountSpecifiedIsInput`: + err = decoder.Decode(&obj.AmountSpecifiedIsInput) + if err != nil { + return err + } + // Deserialize `AToB`: + err = decoder.Decode(&obj.AToB) + if err != nil { + return err + } + // Deserialize `RemainingAccountsInfo` (optional): + { + ok, err := decoder.ReadBool() + if err != nil { + return err + } + if ok { + err = decoder.Decode(&obj.RemainingAccountsInfo) + if err != nil { + return err + } + } + } + return nil +} + +// NewSwapV2Instruction declares a new SwapV2 instruction with the provided parameters and accounts. +func NewSwapV2Instruction( + // Parameters: + amount uint64, + otherAmountThreshold uint64, + sqrtPriceLimit ag_binary.Uint128, + amountSpecifiedIsInput bool, + aToB bool, + remainingAccountsInfo RemainingAccountsInfo, + // Accounts: + tokenProgramA ag_solanago.PublicKey, + tokenProgramB ag_solanago.PublicKey, + memoProgram ag_solanago.PublicKey, + tokenAuthority ag_solanago.PublicKey, + whirlpool ag_solanago.PublicKey, + tokenMintA ag_solanago.PublicKey, + tokenMintB ag_solanago.PublicKey, + tokenOwnerAccountA ag_solanago.PublicKey, + tokenVaultA ag_solanago.PublicKey, + tokenOwnerAccountB ag_solanago.PublicKey, + tokenVaultB ag_solanago.PublicKey, + tickArray0 ag_solanago.PublicKey, + tickArray1 ag_solanago.PublicKey, + tickArray2 ag_solanago.PublicKey, + oracle ag_solanago.PublicKey) *SwapV2 { + return NewSwapV2InstructionBuilder(). + SetAmount(amount). + SetOtherAmountThreshold(otherAmountThreshold). + SetSqrtPriceLimit(sqrtPriceLimit). + SetAmountSpecifiedIsInput(amountSpecifiedIsInput). + SetAToB(aToB). + SetRemainingAccountsInfo(remainingAccountsInfo). + SetTokenProgramAAccount(tokenProgramA). + SetTokenProgramBAccount(tokenProgramB). + SetMemoProgramAccount(memoProgram). + SetTokenAuthorityAccount(tokenAuthority). + SetWhirlpoolAccount(whirlpool). + SetTokenMintAAccount(tokenMintA). + SetTokenMintBAccount(tokenMintB). + SetTokenOwnerAccountAAccount(tokenOwnerAccountA). + SetTokenVaultAAccount(tokenVaultA). + SetTokenOwnerAccountBAccount(tokenOwnerAccountB). + SetTokenVaultBAccount(tokenVaultB). + SetTickArray0Account(tickArray0). + SetTickArray1Account(tickArray1). + SetTickArray2Account(tickArray2). + SetOracleAccount(oracle) +} diff --git a/programs/whirlpool/SwapV2_test.go b/programs/whirlpool/SwapV2_test.go new file mode 100644 index 00000000..dfa9a5e1 --- /dev/null +++ b/programs/whirlpool/SwapV2_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package whirlpool + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_SwapV2(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("SwapV2"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(SwapV2) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(SwapV2) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/Swap_test.go b/programs/whirlpool/Swap_test.go index ecb46b16..9da23c9d 100644 --- a/programs/whirlpool/Swap_test.go +++ b/programs/whirlpool/Swap_test.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "bytes" diff --git a/programs/whirlpool/TwoHopSwap.go b/programs/whirlpool/TwoHopSwap.go index 8a6a0e3a..9ffe2b6a 100644 --- a/programs/whirlpool/TwoHopSwap.go +++ b/programs/whirlpool/TwoHopSwap.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "errors" diff --git a/programs/whirlpool/TwoHopSwapV2.go b/programs/whirlpool/TwoHopSwapV2.go new file mode 100644 index 00000000..86fffb16 --- /dev/null +++ b/programs/whirlpool/TwoHopSwapV2.go @@ -0,0 +1,743 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package whirlpool + +import ( + "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" +) + +// TwoHopSwapV2 is the `twoHopSwapV2` instruction. +type TwoHopSwapV2 struct { + Amount *uint64 + OtherAmountThreshold *uint64 + AmountSpecifiedIsInput *bool + AToBOne *bool + AToBTwo *bool + SqrtPriceLimitOne *ag_binary.Uint128 + SqrtPriceLimitTwo *ag_binary.Uint128 + RemainingAccountsInfo *RemainingAccountsInfo `bin:"optional"` + + // [0] = [WRITE] whirlpoolOne + // + // [1] = [WRITE] whirlpoolTwo + // + // [2] = [] tokenMintInput + // + // [3] = [] tokenMintIntermediate + // + // [4] = [] tokenMintOutput + // + // [5] = [] tokenProgramInput + // + // [6] = [] tokenProgramIntermediate + // + // [7] = [] tokenProgramOutput + // + // [8] = [WRITE] tokenOwnerAccountInput + // + // [9] = [WRITE] tokenVaultOneInput + // + // [10] = [WRITE] tokenVaultOneIntermediate + // + // [11] = [WRITE] tokenVaultTwoIntermediate + // + // [12] = [WRITE] tokenVaultTwoOutput + // + // [13] = [WRITE] tokenOwnerAccountOutput + // + // [14] = [SIGNER] tokenAuthority + // + // [15] = [WRITE] tickArrayOne0 + // + // [16] = [WRITE] tickArrayOne1 + // + // [17] = [WRITE] tickArrayOne2 + // + // [18] = [WRITE] tickArrayTwo0 + // + // [19] = [WRITE] tickArrayTwo1 + // + // [20] = [WRITE] tickArrayTwo2 + // + // [21] = [WRITE] oracleOne + // + // [22] = [WRITE] oracleTwo + // + // [23] = [] memoProgram + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewTwoHopSwapV2InstructionBuilder creates a new `TwoHopSwapV2` instruction builder. +func NewTwoHopSwapV2InstructionBuilder() *TwoHopSwapV2 { + nd := &TwoHopSwapV2{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 24), + } + return nd +} + +// SetAmount sets the "amount" parameter. +func (inst *TwoHopSwapV2) SetAmount(amount uint64) *TwoHopSwapV2 { + inst.Amount = &amount + return inst +} + +// SetOtherAmountThreshold sets the "otherAmountThreshold" parameter. +func (inst *TwoHopSwapV2) SetOtherAmountThreshold(otherAmountThreshold uint64) *TwoHopSwapV2 { + inst.OtherAmountThreshold = &otherAmountThreshold + return inst +} + +// SetAmountSpecifiedIsInput sets the "amountSpecifiedIsInput" parameter. +func (inst *TwoHopSwapV2) SetAmountSpecifiedIsInput(amountSpecifiedIsInput bool) *TwoHopSwapV2 { + inst.AmountSpecifiedIsInput = &amountSpecifiedIsInput + return inst +} + +// SetAToBOne sets the "aToBOne" parameter. +func (inst *TwoHopSwapV2) SetAToBOne(aToBOne bool) *TwoHopSwapV2 { + inst.AToBOne = &aToBOne + return inst +} + +// SetAToBTwo sets the "aToBTwo" parameter. +func (inst *TwoHopSwapV2) SetAToBTwo(aToBTwo bool) *TwoHopSwapV2 { + inst.AToBTwo = &aToBTwo + return inst +} + +// SetSqrtPriceLimitOne sets the "sqrtPriceLimitOne" parameter. +func (inst *TwoHopSwapV2) SetSqrtPriceLimitOne(sqrtPriceLimitOne ag_binary.Uint128) *TwoHopSwapV2 { + inst.SqrtPriceLimitOne = &sqrtPriceLimitOne + return inst +} + +// SetSqrtPriceLimitTwo sets the "sqrtPriceLimitTwo" parameter. +func (inst *TwoHopSwapV2) SetSqrtPriceLimitTwo(sqrtPriceLimitTwo ag_binary.Uint128) *TwoHopSwapV2 { + inst.SqrtPriceLimitTwo = &sqrtPriceLimitTwo + return inst +} + +// SetRemainingAccountsInfo sets the "remainingAccountsInfo" parameter. +func (inst *TwoHopSwapV2) SetRemainingAccountsInfo(remainingAccountsInfo RemainingAccountsInfo) *TwoHopSwapV2 { + inst.RemainingAccountsInfo = &remainingAccountsInfo + return inst +} + +// SetWhirlpoolOneAccount sets the "whirlpoolOne" account. +func (inst *TwoHopSwapV2) SetWhirlpoolOneAccount(whirlpoolOne ag_solanago.PublicKey) *TwoHopSwapV2 { + inst.AccountMetaSlice[0] = ag_solanago.Meta(whirlpoolOne).WRITE() + return inst +} + +// GetWhirlpoolOneAccount gets the "whirlpoolOne" account. +func (inst *TwoHopSwapV2) GetWhirlpoolOneAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetWhirlpoolTwoAccount sets the "whirlpoolTwo" account. +func (inst *TwoHopSwapV2) SetWhirlpoolTwoAccount(whirlpoolTwo ag_solanago.PublicKey) *TwoHopSwapV2 { + inst.AccountMetaSlice[1] = ag_solanago.Meta(whirlpoolTwo).WRITE() + return inst +} + +// GetWhirlpoolTwoAccount gets the "whirlpoolTwo" account. +func (inst *TwoHopSwapV2) GetWhirlpoolTwoAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetTokenMintInputAccount sets the "tokenMintInput" account. +func (inst *TwoHopSwapV2) SetTokenMintInputAccount(tokenMintInput ag_solanago.PublicKey) *TwoHopSwapV2 { + inst.AccountMetaSlice[2] = ag_solanago.Meta(tokenMintInput) + return inst +} + +// GetTokenMintInputAccount gets the "tokenMintInput" account. +func (inst *TwoHopSwapV2) GetTokenMintInputAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetTokenMintIntermediateAccount sets the "tokenMintIntermediate" account. +func (inst *TwoHopSwapV2) SetTokenMintIntermediateAccount(tokenMintIntermediate ag_solanago.PublicKey) *TwoHopSwapV2 { + inst.AccountMetaSlice[3] = ag_solanago.Meta(tokenMintIntermediate) + return inst +} + +// GetTokenMintIntermediateAccount gets the "tokenMintIntermediate" account. +func (inst *TwoHopSwapV2) GetTokenMintIntermediateAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetTokenMintOutputAccount sets the "tokenMintOutput" account. +func (inst *TwoHopSwapV2) SetTokenMintOutputAccount(tokenMintOutput ag_solanago.PublicKey) *TwoHopSwapV2 { + inst.AccountMetaSlice[4] = ag_solanago.Meta(tokenMintOutput) + return inst +} + +// GetTokenMintOutputAccount gets the "tokenMintOutput" account. +func (inst *TwoHopSwapV2) GetTokenMintOutputAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetTokenProgramInputAccount sets the "tokenProgramInput" account. +func (inst *TwoHopSwapV2) SetTokenProgramInputAccount(tokenProgramInput ag_solanago.PublicKey) *TwoHopSwapV2 { + inst.AccountMetaSlice[5] = ag_solanago.Meta(tokenProgramInput) + return inst +} + +// GetTokenProgramInputAccount gets the "tokenProgramInput" account. +func (inst *TwoHopSwapV2) GetTokenProgramInputAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetTokenProgramIntermediateAccount sets the "tokenProgramIntermediate" account. +func (inst *TwoHopSwapV2) SetTokenProgramIntermediateAccount(tokenProgramIntermediate ag_solanago.PublicKey) *TwoHopSwapV2 { + inst.AccountMetaSlice[6] = ag_solanago.Meta(tokenProgramIntermediate) + return inst +} + +// GetTokenProgramIntermediateAccount gets the "tokenProgramIntermediate" account. +func (inst *TwoHopSwapV2) GetTokenProgramIntermediateAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetTokenProgramOutputAccount sets the "tokenProgramOutput" account. +func (inst *TwoHopSwapV2) SetTokenProgramOutputAccount(tokenProgramOutput ag_solanago.PublicKey) *TwoHopSwapV2 { + inst.AccountMetaSlice[7] = ag_solanago.Meta(tokenProgramOutput) + return inst +} + +// GetTokenProgramOutputAccount gets the "tokenProgramOutput" account. +func (inst *TwoHopSwapV2) GetTokenProgramOutputAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetTokenOwnerAccountInputAccount sets the "tokenOwnerAccountInput" account. +func (inst *TwoHopSwapV2) SetTokenOwnerAccountInputAccount(tokenOwnerAccountInput ag_solanago.PublicKey) *TwoHopSwapV2 { + inst.AccountMetaSlice[8] = ag_solanago.Meta(tokenOwnerAccountInput).WRITE() + return inst +} + +// GetTokenOwnerAccountInputAccount gets the "tokenOwnerAccountInput" account. +func (inst *TwoHopSwapV2) GetTokenOwnerAccountInputAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetTokenVaultOneInputAccount sets the "tokenVaultOneInput" account. +func (inst *TwoHopSwapV2) SetTokenVaultOneInputAccount(tokenVaultOneInput ag_solanago.PublicKey) *TwoHopSwapV2 { + inst.AccountMetaSlice[9] = ag_solanago.Meta(tokenVaultOneInput).WRITE() + return inst +} + +// GetTokenVaultOneInputAccount gets the "tokenVaultOneInput" account. +func (inst *TwoHopSwapV2) GetTokenVaultOneInputAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetTokenVaultOneIntermediateAccount sets the "tokenVaultOneIntermediate" account. +func (inst *TwoHopSwapV2) SetTokenVaultOneIntermediateAccount(tokenVaultOneIntermediate ag_solanago.PublicKey) *TwoHopSwapV2 { + inst.AccountMetaSlice[10] = ag_solanago.Meta(tokenVaultOneIntermediate).WRITE() + return inst +} + +// GetTokenVaultOneIntermediateAccount gets the "tokenVaultOneIntermediate" account. +func (inst *TwoHopSwapV2) GetTokenVaultOneIntermediateAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetTokenVaultTwoIntermediateAccount sets the "tokenVaultTwoIntermediate" account. +func (inst *TwoHopSwapV2) SetTokenVaultTwoIntermediateAccount(tokenVaultTwoIntermediate ag_solanago.PublicKey) *TwoHopSwapV2 { + inst.AccountMetaSlice[11] = ag_solanago.Meta(tokenVaultTwoIntermediate).WRITE() + return inst +} + +// GetTokenVaultTwoIntermediateAccount gets the "tokenVaultTwoIntermediate" account. +func (inst *TwoHopSwapV2) GetTokenVaultTwoIntermediateAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetTokenVaultTwoOutputAccount sets the "tokenVaultTwoOutput" account. +func (inst *TwoHopSwapV2) SetTokenVaultTwoOutputAccount(tokenVaultTwoOutput ag_solanago.PublicKey) *TwoHopSwapV2 { + inst.AccountMetaSlice[12] = ag_solanago.Meta(tokenVaultTwoOutput).WRITE() + return inst +} + +// GetTokenVaultTwoOutputAccount gets the "tokenVaultTwoOutput" account. +func (inst *TwoHopSwapV2) GetTokenVaultTwoOutputAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetTokenOwnerAccountOutputAccount sets the "tokenOwnerAccountOutput" account. +func (inst *TwoHopSwapV2) SetTokenOwnerAccountOutputAccount(tokenOwnerAccountOutput ag_solanago.PublicKey) *TwoHopSwapV2 { + inst.AccountMetaSlice[13] = ag_solanago.Meta(tokenOwnerAccountOutput).WRITE() + return inst +} + +// GetTokenOwnerAccountOutputAccount gets the "tokenOwnerAccountOutput" account. +func (inst *TwoHopSwapV2) GetTokenOwnerAccountOutputAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetTokenAuthorityAccount sets the "tokenAuthority" account. +func (inst *TwoHopSwapV2) SetTokenAuthorityAccount(tokenAuthority ag_solanago.PublicKey) *TwoHopSwapV2 { + inst.AccountMetaSlice[14] = ag_solanago.Meta(tokenAuthority).SIGNER() + return inst +} + +// GetTokenAuthorityAccount gets the "tokenAuthority" account. +func (inst *TwoHopSwapV2) GetTokenAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +// SetTickArrayOne0Account sets the "tickArrayOne0" account. +func (inst *TwoHopSwapV2) SetTickArrayOne0Account(tickArrayOne0 ag_solanago.PublicKey) *TwoHopSwapV2 { + inst.AccountMetaSlice[15] = ag_solanago.Meta(tickArrayOne0).WRITE() + return inst +} + +// GetTickArrayOne0Account gets the "tickArrayOne0" account. +func (inst *TwoHopSwapV2) GetTickArrayOne0Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(15) +} + +// SetTickArrayOne1Account sets the "tickArrayOne1" account. +func (inst *TwoHopSwapV2) SetTickArrayOne1Account(tickArrayOne1 ag_solanago.PublicKey) *TwoHopSwapV2 { + inst.AccountMetaSlice[16] = ag_solanago.Meta(tickArrayOne1).WRITE() + return inst +} + +// GetTickArrayOne1Account gets the "tickArrayOne1" account. +func (inst *TwoHopSwapV2) GetTickArrayOne1Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(16) +} + +// SetTickArrayOne2Account sets the "tickArrayOne2" account. +func (inst *TwoHopSwapV2) SetTickArrayOne2Account(tickArrayOne2 ag_solanago.PublicKey) *TwoHopSwapV2 { + inst.AccountMetaSlice[17] = ag_solanago.Meta(tickArrayOne2).WRITE() + return inst +} + +// GetTickArrayOne2Account gets the "tickArrayOne2" account. +func (inst *TwoHopSwapV2) GetTickArrayOne2Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(17) +} + +// SetTickArrayTwo0Account sets the "tickArrayTwo0" account. +func (inst *TwoHopSwapV2) SetTickArrayTwo0Account(tickArrayTwo0 ag_solanago.PublicKey) *TwoHopSwapV2 { + inst.AccountMetaSlice[18] = ag_solanago.Meta(tickArrayTwo0).WRITE() + return inst +} + +// GetTickArrayTwo0Account gets the "tickArrayTwo0" account. +func (inst *TwoHopSwapV2) GetTickArrayTwo0Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(18) +} + +// SetTickArrayTwo1Account sets the "tickArrayTwo1" account. +func (inst *TwoHopSwapV2) SetTickArrayTwo1Account(tickArrayTwo1 ag_solanago.PublicKey) *TwoHopSwapV2 { + inst.AccountMetaSlice[19] = ag_solanago.Meta(tickArrayTwo1).WRITE() + return inst +} + +// GetTickArrayTwo1Account gets the "tickArrayTwo1" account. +func (inst *TwoHopSwapV2) GetTickArrayTwo1Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(19) +} + +// SetTickArrayTwo2Account sets the "tickArrayTwo2" account. +func (inst *TwoHopSwapV2) SetTickArrayTwo2Account(tickArrayTwo2 ag_solanago.PublicKey) *TwoHopSwapV2 { + inst.AccountMetaSlice[20] = ag_solanago.Meta(tickArrayTwo2).WRITE() + return inst +} + +// GetTickArrayTwo2Account gets the "tickArrayTwo2" account. +func (inst *TwoHopSwapV2) GetTickArrayTwo2Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(20) +} + +// SetOracleOneAccount sets the "oracleOne" account. +func (inst *TwoHopSwapV2) SetOracleOneAccount(oracleOne ag_solanago.PublicKey) *TwoHopSwapV2 { + inst.AccountMetaSlice[21] = ag_solanago.Meta(oracleOne).WRITE() + return inst +} + +// GetOracleOneAccount gets the "oracleOne" account. +func (inst *TwoHopSwapV2) GetOracleOneAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(21) +} + +// SetOracleTwoAccount sets the "oracleTwo" account. +func (inst *TwoHopSwapV2) SetOracleTwoAccount(oracleTwo ag_solanago.PublicKey) *TwoHopSwapV2 { + inst.AccountMetaSlice[22] = ag_solanago.Meta(oracleTwo).WRITE() + return inst +} + +// GetOracleTwoAccount gets the "oracleTwo" account. +func (inst *TwoHopSwapV2) GetOracleTwoAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(22) +} + +// SetMemoProgramAccount sets the "memoProgram" account. +func (inst *TwoHopSwapV2) SetMemoProgramAccount(memoProgram ag_solanago.PublicKey) *TwoHopSwapV2 { + inst.AccountMetaSlice[23] = ag_solanago.Meta(memoProgram) + return inst +} + +// GetMemoProgramAccount gets the "memoProgram" account. +func (inst *TwoHopSwapV2) GetMemoProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(23) +} + +func (inst TwoHopSwapV2) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_TwoHopSwapV2, + }} +} + +// 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 TwoHopSwapV2) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *TwoHopSwapV2) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.Amount == nil { + return errors.New("Amount parameter is not set") + } + if inst.OtherAmountThreshold == nil { + return errors.New("OtherAmountThreshold parameter is not set") + } + if inst.AmountSpecifiedIsInput == nil { + return errors.New("AmountSpecifiedIsInput parameter is not set") + } + if inst.AToBOne == nil { + return errors.New("AToBOne parameter is not set") + } + if inst.AToBTwo == nil { + return errors.New("AToBTwo parameter is not set") + } + if inst.SqrtPriceLimitOne == nil { + return errors.New("SqrtPriceLimitOne parameter is not set") + } + if inst.SqrtPriceLimitTwo == nil { + return errors.New("SqrtPriceLimitTwo parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.WhirlpoolOne is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.WhirlpoolTwo is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.TokenMintInput is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.TokenMintIntermediate is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.TokenMintOutput is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.TokenProgramInput is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.TokenProgramIntermediate is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.TokenProgramOutput is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.TokenOwnerAccountInput is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.TokenVaultOneInput is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.TokenVaultOneIntermediate is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.TokenVaultTwoIntermediate is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.TokenVaultTwoOutput is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.TokenOwnerAccountOutput is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.TokenAuthority is not set") + } + if inst.AccountMetaSlice[15] == nil { + return errors.New("accounts.TickArrayOne0 is not set") + } + if inst.AccountMetaSlice[16] == nil { + return errors.New("accounts.TickArrayOne1 is not set") + } + if inst.AccountMetaSlice[17] == nil { + return errors.New("accounts.TickArrayOne2 is not set") + } + if inst.AccountMetaSlice[18] == nil { + return errors.New("accounts.TickArrayTwo0 is not set") + } + if inst.AccountMetaSlice[19] == nil { + return errors.New("accounts.TickArrayTwo1 is not set") + } + if inst.AccountMetaSlice[20] == nil { + return errors.New("accounts.TickArrayTwo2 is not set") + } + if inst.AccountMetaSlice[21] == nil { + return errors.New("accounts.OracleOne is not set") + } + if inst.AccountMetaSlice[22] == nil { + return errors.New("accounts.OracleTwo is not set") + } + if inst.AccountMetaSlice[23] == nil { + return errors.New("accounts.MemoProgram is not set") + } + } + return nil +} + +func (inst *TwoHopSwapV2) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("TwoHopSwapV2")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=8]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" Amount", *inst.Amount)) + paramsBranch.Child(ag_format.Param(" OtherAmountThreshold", *inst.OtherAmountThreshold)) + paramsBranch.Child(ag_format.Param("AmountSpecifiedIsInput", *inst.AmountSpecifiedIsInput)) + paramsBranch.Child(ag_format.Param(" AToBOne", *inst.AToBOne)) + paramsBranch.Child(ag_format.Param(" AToBTwo", *inst.AToBTwo)) + paramsBranch.Child(ag_format.Param(" SqrtPriceLimitOne", *inst.SqrtPriceLimitOne)) + paramsBranch.Child(ag_format.Param(" SqrtPriceLimitTwo", *inst.SqrtPriceLimitTwo)) + paramsBranch.Child(ag_format.Param(" RemainingAccountsInfo (OPT)", inst.RemainingAccountsInfo)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=24]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" whirlpoolOne", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" whirlpoolTwo", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" tokenMintInput", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" tokenMintIntermediate", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" tokenMintOutput", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" tokenProgramInput", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" tokenProgramIntermediate", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" tokenProgramOutput", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" tokenOwnerAccountInput", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" tokenVaultOneInput", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta("tokenVaultOneIntermediate", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta("tokenVaultTwoIntermediate", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" tokenVaultTwoOutput", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" tokenOwnerAccountOutput", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta(" tokenAuthority", inst.AccountMetaSlice.Get(14))) + accountsBranch.Child(ag_format.Meta(" tickArrayOne0", inst.AccountMetaSlice.Get(15))) + accountsBranch.Child(ag_format.Meta(" tickArrayOne1", inst.AccountMetaSlice.Get(16))) + accountsBranch.Child(ag_format.Meta(" tickArrayOne2", inst.AccountMetaSlice.Get(17))) + accountsBranch.Child(ag_format.Meta(" tickArrayTwo0", inst.AccountMetaSlice.Get(18))) + accountsBranch.Child(ag_format.Meta(" tickArrayTwo1", inst.AccountMetaSlice.Get(19))) + accountsBranch.Child(ag_format.Meta(" tickArrayTwo2", inst.AccountMetaSlice.Get(20))) + accountsBranch.Child(ag_format.Meta(" oracleOne", inst.AccountMetaSlice.Get(21))) + accountsBranch.Child(ag_format.Meta(" oracleTwo", inst.AccountMetaSlice.Get(22))) + accountsBranch.Child(ag_format.Meta(" memoProgram", inst.AccountMetaSlice.Get(23))) + }) + }) + }) +} + +func (obj TwoHopSwapV2) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Amount` param: + err = encoder.Encode(obj.Amount) + if err != nil { + return err + } + // Serialize `OtherAmountThreshold` param: + err = encoder.Encode(obj.OtherAmountThreshold) + if err != nil { + return err + } + // Serialize `AmountSpecifiedIsInput` param: + err = encoder.Encode(obj.AmountSpecifiedIsInput) + if err != nil { + return err + } + // Serialize `AToBOne` param: + err = encoder.Encode(obj.AToBOne) + if err != nil { + return err + } + // Serialize `AToBTwo` param: + err = encoder.Encode(obj.AToBTwo) + if err != nil { + return err + } + // Serialize `SqrtPriceLimitOne` param: + err = encoder.Encode(obj.SqrtPriceLimitOne) + if err != nil { + return err + } + // Serialize `SqrtPriceLimitTwo` param: + err = encoder.Encode(obj.SqrtPriceLimitTwo) + if err != nil { + return err + } + // Serialize `RemainingAccountsInfo` param (optional): + { + if obj.RemainingAccountsInfo == nil { + err = encoder.WriteBool(false) + if err != nil { + return err + } + } else { + err = encoder.WriteBool(true) + if err != nil { + return err + } + err = encoder.Encode(obj.RemainingAccountsInfo) + if err != nil { + return err + } + } + } + return nil +} +func (obj *TwoHopSwapV2) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Amount`: + err = decoder.Decode(&obj.Amount) + if err != nil { + return err + } + // Deserialize `OtherAmountThreshold`: + err = decoder.Decode(&obj.OtherAmountThreshold) + if err != nil { + return err + } + // Deserialize `AmountSpecifiedIsInput`: + err = decoder.Decode(&obj.AmountSpecifiedIsInput) + if err != nil { + return err + } + // Deserialize `AToBOne`: + err = decoder.Decode(&obj.AToBOne) + if err != nil { + return err + } + // Deserialize `AToBTwo`: + err = decoder.Decode(&obj.AToBTwo) + if err != nil { + return err + } + // Deserialize `SqrtPriceLimitOne`: + err = decoder.Decode(&obj.SqrtPriceLimitOne) + if err != nil { + return err + } + // Deserialize `SqrtPriceLimitTwo`: + err = decoder.Decode(&obj.SqrtPriceLimitTwo) + if err != nil { + return err + } + // Deserialize `RemainingAccountsInfo` (optional): + { + ok, err := decoder.ReadBool() + if err != nil { + return err + } + if ok { + err = decoder.Decode(&obj.RemainingAccountsInfo) + if err != nil { + return err + } + } + } + return nil +} + +// NewTwoHopSwapV2Instruction declares a new TwoHopSwapV2 instruction with the provided parameters and accounts. +func NewTwoHopSwapV2Instruction( + // Parameters: + amount uint64, + otherAmountThreshold uint64, + amountSpecifiedIsInput bool, + aToBOne bool, + aToBTwo bool, + sqrtPriceLimitOne ag_binary.Uint128, + sqrtPriceLimitTwo ag_binary.Uint128, + remainingAccountsInfo RemainingAccountsInfo, + // Accounts: + whirlpoolOne ag_solanago.PublicKey, + whirlpoolTwo ag_solanago.PublicKey, + tokenMintInput ag_solanago.PublicKey, + tokenMintIntermediate ag_solanago.PublicKey, + tokenMintOutput ag_solanago.PublicKey, + tokenProgramInput ag_solanago.PublicKey, + tokenProgramIntermediate ag_solanago.PublicKey, + tokenProgramOutput ag_solanago.PublicKey, + tokenOwnerAccountInput ag_solanago.PublicKey, + tokenVaultOneInput ag_solanago.PublicKey, + tokenVaultOneIntermediate ag_solanago.PublicKey, + tokenVaultTwoIntermediate ag_solanago.PublicKey, + tokenVaultTwoOutput ag_solanago.PublicKey, + tokenOwnerAccountOutput ag_solanago.PublicKey, + tokenAuthority ag_solanago.PublicKey, + tickArrayOne0 ag_solanago.PublicKey, + tickArrayOne1 ag_solanago.PublicKey, + tickArrayOne2 ag_solanago.PublicKey, + tickArrayTwo0 ag_solanago.PublicKey, + tickArrayTwo1 ag_solanago.PublicKey, + tickArrayTwo2 ag_solanago.PublicKey, + oracleOne ag_solanago.PublicKey, + oracleTwo ag_solanago.PublicKey, + memoProgram ag_solanago.PublicKey) *TwoHopSwapV2 { + return NewTwoHopSwapV2InstructionBuilder(). + SetAmount(amount). + SetOtherAmountThreshold(otherAmountThreshold). + SetAmountSpecifiedIsInput(amountSpecifiedIsInput). + SetAToBOne(aToBOne). + SetAToBTwo(aToBTwo). + SetSqrtPriceLimitOne(sqrtPriceLimitOne). + SetSqrtPriceLimitTwo(sqrtPriceLimitTwo). + SetRemainingAccountsInfo(remainingAccountsInfo). + SetWhirlpoolOneAccount(whirlpoolOne). + SetWhirlpoolTwoAccount(whirlpoolTwo). + SetTokenMintInputAccount(tokenMintInput). + SetTokenMintIntermediateAccount(tokenMintIntermediate). + SetTokenMintOutputAccount(tokenMintOutput). + SetTokenProgramInputAccount(tokenProgramInput). + SetTokenProgramIntermediateAccount(tokenProgramIntermediate). + SetTokenProgramOutputAccount(tokenProgramOutput). + SetTokenOwnerAccountInputAccount(tokenOwnerAccountInput). + SetTokenVaultOneInputAccount(tokenVaultOneInput). + SetTokenVaultOneIntermediateAccount(tokenVaultOneIntermediate). + SetTokenVaultTwoIntermediateAccount(tokenVaultTwoIntermediate). + SetTokenVaultTwoOutputAccount(tokenVaultTwoOutput). + SetTokenOwnerAccountOutputAccount(tokenOwnerAccountOutput). + SetTokenAuthorityAccount(tokenAuthority). + SetTickArrayOne0Account(tickArrayOne0). + SetTickArrayOne1Account(tickArrayOne1). + SetTickArrayOne2Account(tickArrayOne2). + SetTickArrayTwo0Account(tickArrayTwo0). + SetTickArrayTwo1Account(tickArrayTwo1). + SetTickArrayTwo2Account(tickArrayTwo2). + SetOracleOneAccount(oracleOne). + SetOracleTwoAccount(oracleTwo). + SetMemoProgramAccount(memoProgram) +} diff --git a/programs/whirlpool/TwoHopSwapV2_test.go b/programs/whirlpool/TwoHopSwapV2_test.go new file mode 100644 index 00000000..33f7590d --- /dev/null +++ b/programs/whirlpool/TwoHopSwapV2_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package whirlpool + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_TwoHopSwapV2(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("TwoHopSwapV2"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(TwoHopSwapV2) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(TwoHopSwapV2) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/whirlpool/TwoHopSwap_test.go b/programs/whirlpool/TwoHopSwap_test.go index de710c3d..3bad9b1a 100644 --- a/programs/whirlpool/TwoHopSwap_test.go +++ b/programs/whirlpool/TwoHopSwap_test.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "bytes" diff --git a/programs/whirlpool/UpdateFeesAndRewards.go b/programs/whirlpool/UpdateFeesAndRewards.go index baf101c5..6e47c327 100644 --- a/programs/whirlpool/UpdateFeesAndRewards.go +++ b/programs/whirlpool/UpdateFeesAndRewards.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "errors" diff --git a/programs/whirlpool/UpdateFeesAndRewards_test.go b/programs/whirlpool/UpdateFeesAndRewards_test.go index 97dae8e9..00f43c07 100644 --- a/programs/whirlpool/UpdateFeesAndRewards_test.go +++ b/programs/whirlpool/UpdateFeesAndRewards_test.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "bytes" diff --git a/programs/whirlpool/accounts.go b/programs/whirlpool/accounts.go index 240678c7..930a1c6a 100644 --- a/programs/whirlpool/accounts.go +++ b/programs/whirlpool/accounts.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "fmt" @@ -8,6 +8,70 @@ import ( ag_solanago "github.com/gagliardetto/solana-go" ) +type WhirlpoolsConfigExtension struct { + WhirlpoolsConfig ag_solanago.PublicKey + ConfigExtensionAuthority ag_solanago.PublicKey + TokenBadgeAuthority ag_solanago.PublicKey +} + +var WhirlpoolsConfigExtensionDiscriminator = [8]byte{2, 99, 215, 163, 240, 26, 153, 58} + +func (obj WhirlpoolsConfigExtension) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Write account discriminator: + err = encoder.WriteBytes(WhirlpoolsConfigExtensionDiscriminator[:], false) + if err != nil { + return err + } + // Serialize `WhirlpoolsConfig` param: + err = encoder.Encode(obj.WhirlpoolsConfig) + if err != nil { + return err + } + // Serialize `ConfigExtensionAuthority` param: + err = encoder.Encode(obj.ConfigExtensionAuthority) + if err != nil { + return err + } + // Serialize `TokenBadgeAuthority` param: + err = encoder.Encode(obj.TokenBadgeAuthority) + if err != nil { + return err + } + return nil +} + +func (obj *WhirlpoolsConfigExtension) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Read and check account discriminator: + { + discriminator, err := decoder.ReadTypeID() + if err != nil { + return err + } + if !discriminator.Equal(WhirlpoolsConfigExtensionDiscriminator[:]) { + return fmt.Errorf( + "wrong discriminator: wanted %s, got %s", + "[2 99 215 163 240 26 153 58]", + fmt.Sprint(discriminator[:])) + } + } + // Deserialize `WhirlpoolsConfig`: + err = decoder.Decode(&obj.WhirlpoolsConfig) + if err != nil { + return err + } + // Deserialize `ConfigExtensionAuthority`: + err = decoder.Decode(&obj.ConfigExtensionAuthority) + if err != nil { + return err + } + // Deserialize `TokenBadgeAuthority`: + err = decoder.Decode(&obj.TokenBadgeAuthority) + if err != nil { + return err + } + return nil +} + type WhirlpoolsConfig struct { FeeAuthority ag_solanago.PublicKey CollectProtocolFeesAuthority ag_solanago.PublicKey @@ -405,6 +469,59 @@ func (obj *TickArray) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err erro return nil } +type TokenBadge struct { + WhirlpoolsConfig ag_solanago.PublicKey + TokenMint ag_solanago.PublicKey +} + +var TokenBadgeDiscriminator = [8]byte{116, 219, 204, 229, 249, 116, 255, 150} + +func (obj TokenBadge) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Write account discriminator: + err = encoder.WriteBytes(TokenBadgeDiscriminator[:], false) + if err != nil { + return err + } + // Serialize `WhirlpoolsConfig` param: + err = encoder.Encode(obj.WhirlpoolsConfig) + if err != nil { + return err + } + // Serialize `TokenMint` param: + err = encoder.Encode(obj.TokenMint) + if err != nil { + return err + } + return nil +} + +func (obj *TokenBadge) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Read and check account discriminator: + { + discriminator, err := decoder.ReadTypeID() + if err != nil { + return err + } + if !discriminator.Equal(TokenBadgeDiscriminator[:]) { + return fmt.Errorf( + "wrong discriminator: wanted %s, got %s", + "[116 219 204 229 249 116 255 150]", + fmt.Sprint(discriminator[:])) + } + } + // Deserialize `WhirlpoolsConfig`: + err = decoder.Decode(&obj.WhirlpoolsConfig) + if err != nil { + return err + } + // Deserialize `TokenMint`: + err = decoder.Decode(&obj.TokenMint) + if err != nil { + return err + } + return nil +} + type Whirlpool struct { WhirlpoolsConfig ag_solanago.PublicKey WhirlpoolBump [1]uint8 diff --git a/programs/whirlpool/instructions.go b/programs/whirlpool/instructions.go index 531831c1..abcde973 100644 --- a/programs/whirlpool/instructions.go +++ b/programs/whirlpool/instructions.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "bytes" @@ -89,6 +89,36 @@ var ( Instruction_OpenBundledPosition = ag_binary.TypeID([8]byte{169, 113, 126, 171, 213, 172, 212, 49}) Instruction_CloseBundledPosition = ag_binary.TypeID([8]byte{41, 36, 216, 245, 27, 85, 103, 67}) + + Instruction_CollectFeesV2 = ag_binary.TypeID([8]byte{207, 117, 95, 191, 229, 180, 226, 15}) + + Instruction_CollectProtocolFeesV2 = ag_binary.TypeID([8]byte{103, 128, 222, 134, 114, 200, 22, 200}) + + Instruction_CollectRewardV2 = ag_binary.TypeID([8]byte{177, 107, 37, 180, 160, 19, 49, 209}) + + Instruction_DecreaseLiquidityV2 = ag_binary.TypeID([8]byte{58, 127, 188, 62, 79, 82, 196, 96}) + + Instruction_IncreaseLiquidityV2 = ag_binary.TypeID([8]byte{133, 29, 89, 223, 69, 238, 176, 10}) + + Instruction_InitializePoolV2 = ag_binary.TypeID([8]byte{207, 45, 87, 242, 27, 63, 204, 67}) + + Instruction_InitializeRewardV2 = ag_binary.TypeID([8]byte{91, 1, 77, 50, 235, 229, 133, 49}) + + Instruction_SetRewardEmissionsV2 = ag_binary.TypeID([8]byte{114, 228, 72, 32, 193, 48, 160, 102}) + + Instruction_SwapV2 = ag_binary.TypeID([8]byte{43, 4, 237, 11, 26, 201, 30, 98}) + + Instruction_TwoHopSwapV2 = ag_binary.TypeID([8]byte{186, 143, 209, 29, 254, 2, 194, 117}) + + Instruction_InitializeConfigExtension = ag_binary.TypeID([8]byte{55, 9, 53, 9, 114, 57, 209, 52}) + + Instruction_SetConfigExtensionAuthority = ag_binary.TypeID([8]byte{44, 94, 241, 116, 24, 188, 60, 143}) + + Instruction_SetTokenBadgeAuthority = ag_binary.TypeID([8]byte{207, 202, 4, 32, 205, 79, 13, 178}) + + Instruction_InitializeTokenBadge = ag_binary.TypeID([8]byte{253, 77, 205, 95, 27, 224, 89, 223}) + + Instruction_DeleteTokenBadge = ag_binary.TypeID([8]byte{53, 146, 68, 8, 18, 117, 17, 185}) ) // InstructionIDToName returns the name of the instruction given its ID. @@ -156,6 +186,36 @@ func InstructionIDToName(id ag_binary.TypeID) string { return "OpenBundledPosition" case Instruction_CloseBundledPosition: return "CloseBundledPosition" + case Instruction_CollectFeesV2: + return "CollectFeesV2" + case Instruction_CollectProtocolFeesV2: + return "CollectProtocolFeesV2" + case Instruction_CollectRewardV2: + return "CollectRewardV2" + case Instruction_DecreaseLiquidityV2: + return "DecreaseLiquidityV2" + case Instruction_IncreaseLiquidityV2: + return "IncreaseLiquidityV2" + case Instruction_InitializePoolV2: + return "InitializePoolV2" + case Instruction_InitializeRewardV2: + return "InitializeRewardV2" + case Instruction_SetRewardEmissionsV2: + return "SetRewardEmissionsV2" + case Instruction_SwapV2: + return "SwapV2" + case Instruction_TwoHopSwapV2: + return "TwoHopSwapV2" + case Instruction_InitializeConfigExtension: + return "InitializeConfigExtension" + case Instruction_SetConfigExtensionAuthority: + return "SetConfigExtensionAuthority" + case Instruction_SetTokenBadgeAuthority: + return "SetTokenBadgeAuthority" + case Instruction_InitializeTokenBadge: + return "InitializeTokenBadge" + case Instruction_DeleteTokenBadge: + return "DeleteTokenBadge" default: return "" } @@ -269,6 +329,51 @@ var InstructionImplDef = ag_binary.NewVariantDefinition( { "close_bundled_position", (*CloseBundledPosition)(nil), }, + { + "collect_fees_v2", (*CollectFeesV2)(nil), + }, + { + "collect_protocol_fees_v2", (*CollectProtocolFeesV2)(nil), + }, + { + "collect_reward_v2", (*CollectRewardV2)(nil), + }, + { + "decrease_liquidity_v2", (*DecreaseLiquidityV2)(nil), + }, + { + "increase_liquidity_v2", (*IncreaseLiquidityV2)(nil), + }, + { + "initialize_pool_v2", (*InitializePoolV2)(nil), + }, + { + "initialize_reward_v2", (*InitializeRewardV2)(nil), + }, + { + "set_reward_emissions_v2", (*SetRewardEmissionsV2)(nil), + }, + { + "swap_v2", (*SwapV2)(nil), + }, + { + "two_hop_swap_v2", (*TwoHopSwapV2)(nil), + }, + { + "initialize_config_extension", (*InitializeConfigExtension)(nil), + }, + { + "set_config_extension_authority", (*SetConfigExtensionAuthority)(nil), + }, + { + "set_token_badge_authority", (*SetTokenBadgeAuthority)(nil), + }, + { + "initialize_token_badge", (*InitializeTokenBadge)(nil), + }, + { + "delete_token_badge", (*DeleteTokenBadge)(nil), + }, }, ) diff --git a/programs/whirlpool/testing_utils.go b/programs/whirlpool/testing_utils.go index b19f0534..0596a980 100644 --- a/programs/whirlpool/testing_utils.go +++ b/programs/whirlpool/testing_utils.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( "bytes" diff --git a/programs/whirlpool/types.go b/programs/whirlpool/types.go index 6eaf0e82..832c503f 100644 --- a/programs/whirlpool/types.go +++ b/programs/whirlpool/types.go @@ -1,6 +1,6 @@ // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -package generated +package whirlpool import ( ag_binary "github.com/gagliardetto/binary" @@ -260,6 +260,61 @@ func (obj *WhirlpoolBumps) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err return nil } +type RemainingAccountsSlice struct { + AccountsType AccountsType + Length uint8 +} + +func (obj RemainingAccountsSlice) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `AccountsType` param: + err = encoder.Encode(obj.AccountsType) + if err != nil { + return err + } + // Serialize `Length` param: + err = encoder.Encode(obj.Length) + if err != nil { + return err + } + return nil +} + +func (obj *RemainingAccountsSlice) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `AccountsType`: + err = decoder.Decode(&obj.AccountsType) + if err != nil { + return err + } + // Deserialize `Length`: + err = decoder.Decode(&obj.Length) + if err != nil { + return err + } + return nil +} + +type RemainingAccountsInfo struct { + Slices []RemainingAccountsSlice +} + +func (obj RemainingAccountsInfo) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Slices` param: + err = encoder.Encode(obj.Slices) + if err != nil { + return err + } + return nil +} + +func (obj *RemainingAccountsInfo) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Slices`: + err = decoder.Decode(&obj.Slices) + if err != nil { + return err + } + return nil +} + type CurrIndex ag_binary.BorshEnum const ( @@ -316,3 +371,42 @@ func (value Direction) String() string { return "" } } + +type AccountsType ag_binary.BorshEnum + +const ( + AccountsTypeTransferHookA AccountsType = iota + AccountsTypeTransferHookB + AccountsTypeTransferHookReward + AccountsTypeTransferHookInput + AccountsTypeTransferHookIntermediate + AccountsTypeTransferHookOutput + AccountsTypeSupplementalTickArrays + AccountsTypeSupplementalTickArraysOne + AccountsTypeSupplementalTickArraysTwo +) + +func (value AccountsType) String() string { + switch value { + case AccountsTypeTransferHookA: + return "TransferHookA" + case AccountsTypeTransferHookB: + return "TransferHookB" + case AccountsTypeTransferHookReward: + return "TransferHookReward" + case AccountsTypeTransferHookInput: + return "TransferHookInput" + case AccountsTypeTransferHookIntermediate: + return "TransferHookIntermediate" + case AccountsTypeTransferHookOutput: + return "TransferHookOutput" + case AccountsTypeSupplementalTickArrays: + return "SupplementalTickArrays" + case AccountsTypeSupplementalTickArraysOne: + return "SupplementalTickArraysOne" + case AccountsTypeSupplementalTickArraysTwo: + return "SupplementalTickArraysTwo" + default: + return "" + } +} diff --git a/programs/whirlpool/utils.go b/programs/whirlpool/utils.go new file mode 100644 index 00000000..951c8800 --- /dev/null +++ b/programs/whirlpool/utils.go @@ -0,0 +1 @@ +package generated From c56bc812bf250bc636b79972212f39c103dbbc7f Mon Sep 17 00:00:00 2001 From: egaotan Date: Thu, 23 Jan 2025 17:34:12 +0800 Subject: [PATCH 3/6] udpate --- programs/whirlpool/utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/whirlpool/utils.go b/programs/whirlpool/utils.go index 951c8800..4d17441e 100644 --- a/programs/whirlpool/utils.go +++ b/programs/whirlpool/utils.go @@ -1 +1 @@ -package generated +package whirlpool From f42bca197fd496a34cbc7a0fdb6458ee3088241c Mon Sep 17 00:00:00 2001 From: egaotan Date: Thu, 23 Jan 2025 18:02:06 +0800 Subject: [PATCH 4/6] update --- programs/stabblestableswap/acceptowner.go | 117 ++++ .../stabblestableswap/acceptowner_test.go | 32 + programs/stabblestableswap/accounts.go | 458 +++++++++++++ programs/stabblestableswap/addresses.go | 7 + programs/stabblestableswap/approvestrategy.go | 194 ++++++ .../stabblestableswap/approvestrategy_test.go | 32 + programs/stabblestableswap/changeampfactor.go | 188 ++++++ .../stabblestableswap/changeampfactor_test.go | 32 + programs/stabblestableswap/changeswapfee.go | 146 ++++ .../stabblestableswap/changeswapfee_test.go | 32 + programs/stabblestableswap/constants.go | 3 + programs/stabblestableswap/createstrategy.go | 318 +++++++++ .../stabblestableswap/createstrategy_test.go | 32 + programs/stabblestableswap/deposit.go | 302 +++++++++ programs/stabblestableswap/deposit_test.go | 32 + programs/stabblestableswap/errors.go | 83 +++ programs/stabblestableswap/events.go | 243 +++++++ programs/stabblestableswap/execstrategy.go | 169 +++++ .../stabblestableswap/execstrategy_test.go | 32 + programs/stabblestableswap/initialize.go | 268 ++++++++ programs/stabblestableswap/initialize_test.go | 32 + programs/stabblestableswap/instructions.go | 249 +++++++ programs/stabblestableswap/pause.go | 117 ++++ programs/stabblestableswap/pause_test.go | 32 + programs/stabblestableswap/rejectowner.go | 117 ++++ .../stabblestableswap/rejectowner_test.go | 32 + programs/stabblestableswap/shutdown.go | 117 ++++ programs/stabblestableswap/shutdown_test.go | 32 + programs/stabblestableswap/swap.go | 377 +++++++++++ programs/stabblestableswap/swap_test.go | 32 + programs/stabblestableswap/swapv2.go | 434 ++++++++++++ programs/stabblestableswap/swapv2_test.go | 32 + programs/stabblestableswap/testing_utils.go | 20 + programs/stabblestableswap/transferowner.go | 146 ++++ .../stabblestableswap/transferowner_test.go | 32 + programs/stabblestableswap/types.go | 628 ++++++++++++++++++ programs/stabblestableswap/unpause.go | 117 ++++ programs/stabblestableswap/unpause_test.go | 32 + programs/stabblestableswap/withdraw.go | 321 +++++++++ programs/stabblestableswap/withdraw_test.go | 32 + 40 files changed, 5651 insertions(+) create mode 100644 programs/stabblestableswap/acceptowner.go create mode 100644 programs/stabblestableswap/acceptowner_test.go create mode 100644 programs/stabblestableswap/accounts.go create mode 100644 programs/stabblestableswap/addresses.go create mode 100644 programs/stabblestableswap/approvestrategy.go create mode 100644 programs/stabblestableswap/approvestrategy_test.go create mode 100644 programs/stabblestableswap/changeampfactor.go create mode 100644 programs/stabblestableswap/changeampfactor_test.go create mode 100644 programs/stabblestableswap/changeswapfee.go create mode 100644 programs/stabblestableswap/changeswapfee_test.go create mode 100644 programs/stabblestableswap/constants.go create mode 100644 programs/stabblestableswap/createstrategy.go create mode 100644 programs/stabblestableswap/createstrategy_test.go create mode 100644 programs/stabblestableswap/deposit.go create mode 100644 programs/stabblestableswap/deposit_test.go create mode 100644 programs/stabblestableswap/errors.go create mode 100644 programs/stabblestableswap/events.go create mode 100644 programs/stabblestableswap/execstrategy.go create mode 100644 programs/stabblestableswap/execstrategy_test.go create mode 100644 programs/stabblestableswap/initialize.go create mode 100644 programs/stabblestableswap/initialize_test.go create mode 100644 programs/stabblestableswap/instructions.go create mode 100644 programs/stabblestableswap/pause.go create mode 100644 programs/stabblestableswap/pause_test.go create mode 100644 programs/stabblestableswap/rejectowner.go create mode 100644 programs/stabblestableswap/rejectowner_test.go create mode 100644 programs/stabblestableswap/shutdown.go create mode 100644 programs/stabblestableswap/shutdown_test.go create mode 100644 programs/stabblestableswap/swap.go create mode 100644 programs/stabblestableswap/swap_test.go create mode 100644 programs/stabblestableswap/swapv2.go create mode 100644 programs/stabblestableswap/swapv2_test.go create mode 100644 programs/stabblestableswap/testing_utils.go create mode 100644 programs/stabblestableswap/transferowner.go create mode 100644 programs/stabblestableswap/transferowner_test.go create mode 100644 programs/stabblestableswap/types.go create mode 100644 programs/stabblestableswap/unpause.go create mode 100644 programs/stabblestableswap/unpause_test.go create mode 100644 programs/stabblestableswap/withdraw.go create mode 100644 programs/stabblestableswap/withdraw_test.go diff --git a/programs/stabblestableswap/acceptowner.go b/programs/stabblestableswap/acceptowner.go new file mode 100644 index 00000000..2314bb2c --- /dev/null +++ b/programs/stabblestableswap/acceptowner.go @@ -0,0 +1,117 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package stable_swap + +import ( + "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" +) + +// AcceptOwner is the `accept_owner` instruction. +type AcceptOwner struct { + + // [0] = [SIGNER] pending_owner + // + // [1] = [WRITE] pool + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewAcceptOwnerInstructionBuilder creates a new `AcceptOwner` instruction builder. +func NewAcceptOwnerInstructionBuilder() *AcceptOwner { + nd := &AcceptOwner{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 2), + } + return nd +} + +// SetPendingOwnerAccount sets the "pending_owner" account. +func (inst *AcceptOwner) SetPendingOwnerAccount(pendingOwner ag_solanago.PublicKey) *AcceptOwner { + inst.AccountMetaSlice[0] = ag_solanago.Meta(pendingOwner).SIGNER() + return inst +} + +// GetPendingOwnerAccount gets the "pending_owner" account. +func (inst *AcceptOwner) GetPendingOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetPoolAccount sets the "pool" account. +func (inst *AcceptOwner) SetPoolAccount(pool ag_solanago.PublicKey) *AcceptOwner { + inst.AccountMetaSlice[1] = ag_solanago.Meta(pool).WRITE() + return inst +} + +// GetPoolAccount gets the "pool" account. +func (inst *AcceptOwner) GetPoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +func (inst AcceptOwner) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_AcceptOwner, + }} +} + +// 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 AcceptOwner) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *AcceptOwner) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.PendingOwner is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Pool is not set") + } + } + return nil +} + +func (inst *AcceptOwner) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("AcceptOwner")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=2]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta("pending_owner", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" pool", inst.AccountMetaSlice.Get(1))) + }) + }) + }) +} + +func (obj AcceptOwner) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *AcceptOwner) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewAcceptOwnerInstruction declares a new AcceptOwner instruction with the provided parameters and accounts. +func NewAcceptOwnerInstruction( + // Accounts: + pendingOwner ag_solanago.PublicKey, + pool ag_solanago.PublicKey) *AcceptOwner { + return NewAcceptOwnerInstructionBuilder(). + SetPendingOwnerAccount(pendingOwner). + SetPoolAccount(pool) +} diff --git a/programs/stabblestableswap/acceptowner_test.go b/programs/stabblestableswap/acceptowner_test.go new file mode 100644 index 00000000..ccf68747 --- /dev/null +++ b/programs/stabblestableswap/acceptowner_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package stable_swap + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_AcceptOwner(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("AcceptOwner"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(AcceptOwner) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(AcceptOwner) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/stabblestableswap/accounts.go b/programs/stabblestableswap/accounts.go new file mode 100644 index 00000000..0194db5a --- /dev/null +++ b/programs/stabblestableswap/accounts.go @@ -0,0 +1,458 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package stable_swap + +import ( + "fmt" + ag_binary "github.com/gagliardetto/binary" + ag_solanago "github.com/gagliardetto/solana-go" +) + +type PoolAccount struct { + Owner ag_solanago.PublicKey + Vault ag_solanago.PublicKey + Mint ag_solanago.PublicKey + AuthorityBump uint8 + IsActive bool + AmpInitialFactor uint16 + AmpTargetFactor uint16 + RampStartTs int64 + RampStopTs int64 + SwapFee uint64 + Tokens []PoolToken + PendingOwner *ag_solanago.PublicKey `bin:"optional"` +} + +var PoolAccountDiscriminator = [8]byte{241, 154, 109, 4, 17, 177, 109, 188} + +func (obj PoolAccount) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Write account discriminator: + err = encoder.WriteBytes(PoolAccountDiscriminator[:], false) + if err != nil { + return err + } + // Serialize `Owner` param: + err = encoder.Encode(obj.Owner) + if err != nil { + return err + } + // Serialize `Vault` param: + err = encoder.Encode(obj.Vault) + if err != nil { + return err + } + // Serialize `Mint` param: + err = encoder.Encode(obj.Mint) + if err != nil { + return err + } + // Serialize `AuthorityBump` param: + err = encoder.Encode(obj.AuthorityBump) + if err != nil { + return err + } + // Serialize `IsActive` param: + err = encoder.Encode(obj.IsActive) + if err != nil { + return err + } + // Serialize `AmpInitialFactor` param: + err = encoder.Encode(obj.AmpInitialFactor) + if err != nil { + return err + } + // Serialize `AmpTargetFactor` param: + err = encoder.Encode(obj.AmpTargetFactor) + if err != nil { + return err + } + // Serialize `RampStartTs` param: + err = encoder.Encode(obj.RampStartTs) + if err != nil { + return err + } + // Serialize `RampStopTs` param: + err = encoder.Encode(obj.RampStopTs) + if err != nil { + return err + } + // Serialize `SwapFee` param: + err = encoder.Encode(obj.SwapFee) + if err != nil { + return err + } + // Serialize `Tokens` param: + err = encoder.Encode(obj.Tokens) + if err != nil { + return err + } + // Serialize `PendingOwner` param (optional): + { + if obj.PendingOwner == nil { + err = encoder.WriteBool(false) + if err != nil { + return err + } + } else { + err = encoder.WriteBool(true) + if err != nil { + return err + } + err = encoder.Encode(obj.PendingOwner) + if err != nil { + return err + } + } + } + return nil +} + +func (obj *PoolAccount) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Read and check account discriminator: + { + discriminator, err := decoder.ReadTypeID() + if err != nil { + return err + } + if !discriminator.Equal(PoolAccountDiscriminator[:]) { + return fmt.Errorf( + "wrong discriminator: wanted %s, got %s", + "[241 154 109 4 17 177 109 188]", + fmt.Sprint(discriminator[:])) + } + } + // Deserialize `Owner`: + err = decoder.Decode(&obj.Owner) + if err != nil { + return err + } + // Deserialize `Vault`: + err = decoder.Decode(&obj.Vault) + if err != nil { + return err + } + // Deserialize `Mint`: + err = decoder.Decode(&obj.Mint) + if err != nil { + return err + } + // Deserialize `AuthorityBump`: + err = decoder.Decode(&obj.AuthorityBump) + if err != nil { + return err + } + // Deserialize `IsActive`: + err = decoder.Decode(&obj.IsActive) + if err != nil { + return err + } + // Deserialize `AmpInitialFactor`: + err = decoder.Decode(&obj.AmpInitialFactor) + if err != nil { + return err + } + // Deserialize `AmpTargetFactor`: + err = decoder.Decode(&obj.AmpTargetFactor) + if err != nil { + return err + } + // Deserialize `RampStartTs`: + err = decoder.Decode(&obj.RampStartTs) + if err != nil { + return err + } + // Deserialize `RampStopTs`: + err = decoder.Decode(&obj.RampStopTs) + if err != nil { + return err + } + // Deserialize `SwapFee`: + err = decoder.Decode(&obj.SwapFee) + if err != nil { + return err + } + // Deserialize `Tokens`: + err = decoder.Decode(&obj.Tokens) + if err != nil { + return err + } + // Deserialize `PendingOwner` (optional): + { + ok, err := decoder.ReadBool() + if err != nil { + return err + } + if ok { + err = decoder.Decode(&obj.PendingOwner) + if err != nil { + return err + } + } + } + return nil +} + +type StrategyAccount struct { + Pool ag_solanago.PublicKey + IsActive bool + AmpMinFactor uint16 + AmpMaxFactor uint16 + RampMinStep uint16 + RampMaxStep uint16 + RampMinDuration uint32 + RampMaxDuration uint32 +} + +var StrategyAccountDiscriminator = [8]byte{174, 110, 39, 119, 82, 106, 169, 102} + +func (obj StrategyAccount) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Write account discriminator: + err = encoder.WriteBytes(StrategyAccountDiscriminator[:], false) + if err != nil { + return err + } + // Serialize `Pool` param: + err = encoder.Encode(obj.Pool) + if err != nil { + return err + } + // Serialize `IsActive` param: + err = encoder.Encode(obj.IsActive) + if err != nil { + return err + } + // Serialize `AmpMinFactor` param: + err = encoder.Encode(obj.AmpMinFactor) + if err != nil { + return err + } + // Serialize `AmpMaxFactor` param: + err = encoder.Encode(obj.AmpMaxFactor) + if err != nil { + return err + } + // Serialize `RampMinStep` param: + err = encoder.Encode(obj.RampMinStep) + if err != nil { + return err + } + // Serialize `RampMaxStep` param: + err = encoder.Encode(obj.RampMaxStep) + if err != nil { + return err + } + // Serialize `RampMinDuration` param: + err = encoder.Encode(obj.RampMinDuration) + if err != nil { + return err + } + // Serialize `RampMaxDuration` param: + err = encoder.Encode(obj.RampMaxDuration) + if err != nil { + return err + } + return nil +} + +func (obj *StrategyAccount) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Read and check account discriminator: + { + discriminator, err := decoder.ReadTypeID() + if err != nil { + return err + } + if !discriminator.Equal(StrategyAccountDiscriminator[:]) { + return fmt.Errorf( + "wrong discriminator: wanted %s, got %s", + "[174 110 39 119 82 106 169 102]", + fmt.Sprint(discriminator[:])) + } + } + // Deserialize `Pool`: + err = decoder.Decode(&obj.Pool) + if err != nil { + return err + } + // Deserialize `IsActive`: + err = decoder.Decode(&obj.IsActive) + if err != nil { + return err + } + // Deserialize `AmpMinFactor`: + err = decoder.Decode(&obj.AmpMinFactor) + if err != nil { + return err + } + // Deserialize `AmpMaxFactor`: + err = decoder.Decode(&obj.AmpMaxFactor) + if err != nil { + return err + } + // Deserialize `RampMinStep`: + err = decoder.Decode(&obj.RampMinStep) + if err != nil { + return err + } + // Deserialize `RampMaxStep`: + err = decoder.Decode(&obj.RampMaxStep) + if err != nil { + return err + } + // Deserialize `RampMinDuration`: + err = decoder.Decode(&obj.RampMinDuration) + if err != nil { + return err + } + // Deserialize `RampMaxDuration`: + err = decoder.Decode(&obj.RampMaxDuration) + if err != nil { + return err + } + return nil +} + +type VaultAccount struct { + Admin ag_solanago.PublicKey + + // PDA of pool programs seeded by vault address + WithdrawAuthority ag_solanago.PublicKey + + // bump seed of withdraw_authority PDA + WithdrawAuthorityBump uint8 + + // bump seed of vault_authority PDA + AuthorityBump uint8 + IsActive bool + Beneficiary ag_solanago.PublicKey + BeneficiaryFee uint64 + PendingAdmin *ag_solanago.PublicKey `bin:"optional"` +} + +var VaultAccountDiscriminator = [8]byte{211, 8, 232, 43, 2, 152, 117, 119} + +func (obj VaultAccount) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Write account discriminator: + err = encoder.WriteBytes(VaultAccountDiscriminator[:], false) + if err != nil { + return err + } + // Serialize `Admin` param: + err = encoder.Encode(obj.Admin) + if err != nil { + return err + } + // Serialize `WithdrawAuthority` param: + err = encoder.Encode(obj.WithdrawAuthority) + if err != nil { + return err + } + // Serialize `WithdrawAuthorityBump` param: + err = encoder.Encode(obj.WithdrawAuthorityBump) + if err != nil { + return err + } + // Serialize `AuthorityBump` param: + err = encoder.Encode(obj.AuthorityBump) + if err != nil { + return err + } + // Serialize `IsActive` param: + err = encoder.Encode(obj.IsActive) + if err != nil { + return err + } + // Serialize `Beneficiary` param: + err = encoder.Encode(obj.Beneficiary) + if err != nil { + return err + } + // Serialize `BeneficiaryFee` param: + err = encoder.Encode(obj.BeneficiaryFee) + if err != nil { + return err + } + // Serialize `PendingAdmin` param (optional): + { + if obj.PendingAdmin == nil { + err = encoder.WriteBool(false) + if err != nil { + return err + } + } else { + err = encoder.WriteBool(true) + if err != nil { + return err + } + err = encoder.Encode(obj.PendingAdmin) + if err != nil { + return err + } + } + } + return nil +} + +func (obj *VaultAccount) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Read and check account discriminator: + { + discriminator, err := decoder.ReadTypeID() + if err != nil { + return err + } + if !discriminator.Equal(VaultAccountDiscriminator[:]) { + return fmt.Errorf( + "wrong discriminator: wanted %s, got %s", + "[211 8 232 43 2 152 117 119]", + fmt.Sprint(discriminator[:])) + } + } + // Deserialize `Admin`: + err = decoder.Decode(&obj.Admin) + if err != nil { + return err + } + // Deserialize `WithdrawAuthority`: + err = decoder.Decode(&obj.WithdrawAuthority) + if err != nil { + return err + } + // Deserialize `WithdrawAuthorityBump`: + err = decoder.Decode(&obj.WithdrawAuthorityBump) + if err != nil { + return err + } + // Deserialize `AuthorityBump`: + err = decoder.Decode(&obj.AuthorityBump) + if err != nil { + return err + } + // Deserialize `IsActive`: + err = decoder.Decode(&obj.IsActive) + if err != nil { + return err + } + // Deserialize `Beneficiary`: + err = decoder.Decode(&obj.Beneficiary) + if err != nil { + return err + } + // Deserialize `BeneficiaryFee`: + err = decoder.Decode(&obj.BeneficiaryFee) + if err != nil { + return err + } + // Deserialize `PendingAdmin` (optional): + { + ok, err := decoder.ReadBool() + if err != nil { + return err + } + if ok { + err = decoder.Decode(&obj.PendingAdmin) + if err != nil { + return err + } + } + } + return nil +} diff --git a/programs/stabblestableswap/addresses.go b/programs/stabblestableswap/addresses.go new file mode 100644 index 00000000..4ae0a463 --- /dev/null +++ b/programs/stabblestableswap/addresses.go @@ -0,0 +1,7 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package stable_swap + +import ag_solanago "github.com/gagliardetto/solana-go" + +var Addresses = map[string]ag_solanago.PublicKey{} diff --git a/programs/stabblestableswap/approvestrategy.go b/programs/stabblestableswap/approvestrategy.go new file mode 100644 index 00000000..14d6e633 --- /dev/null +++ b/programs/stabblestableswap/approvestrategy.go @@ -0,0 +1,194 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package stable_swap + +import ( + "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" +) + +// ApproveStrategy is the `approve_strategy` instruction. +type ApproveStrategy struct { + + // [0] = [] admin_only + // + // ····· admin_only: [1] = [WRITE] pool + // + // ················· [2] = [] vault + // + // ················· [3] = [SIGNER] admin + // + // [4] = [WRITE] strategy + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewApproveStrategyInstructionBuilder creates a new `ApproveStrategy` instruction builder. +func NewApproveStrategyInstructionBuilder() *ApproveStrategy { + nd := &ApproveStrategy{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 5), + } + return nd +} + +// SetAdminOnlyAccount sets the "admin_only" account. +func (inst *ApproveStrategy) SetAdminOnlyAccount(adminOnly ag_solanago.PublicKey) *ApproveStrategy { + inst.AccountMetaSlice[0] = ag_solanago.Meta(adminOnly) + return inst +} + +// GetAdminOnlyAccount gets the "admin_only" account. +func (inst *ApproveStrategy) GetAdminOnlyAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +type ApproveStrategyAdminOnlyAccountsBuilder struct { + ag_solanago.AccountMetaSlice `bin:"-"` +} + +func NewApproveStrategyAdminOnlyAccountsBuilder() *ApproveStrategyAdminOnlyAccountsBuilder { + return &ApproveStrategyAdminOnlyAccountsBuilder{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 3), + } +} + +func (inst *ApproveStrategy) SetAdminOnlyAccountsFromBuilder(approveStrategyAdminOnlyAccountsBuilder *ApproveStrategyAdminOnlyAccountsBuilder) *ApproveStrategy { + inst.AccountMetaSlice[1] = approveStrategyAdminOnlyAccountsBuilder.GetPoolAccount() + inst.AccountMetaSlice[2] = approveStrategyAdminOnlyAccountsBuilder.GetVaultAccount() + inst.AccountMetaSlice[3] = approveStrategyAdminOnlyAccountsBuilder.GetAdminAccount() + return inst +} + +// SetPoolAccount sets the "pool" account. +func (inst *ApproveStrategyAdminOnlyAccountsBuilder) SetPoolAccount(pool ag_solanago.PublicKey) *ApproveStrategyAdminOnlyAccountsBuilder { + inst.AccountMetaSlice[0] = ag_solanago.Meta(pool).WRITE() + return inst +} + +// GetPoolAccount gets the "pool" account. +func (inst *ApproveStrategyAdminOnlyAccountsBuilder) GetPoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetVaultAccount sets the "vault" account. +func (inst *ApproveStrategyAdminOnlyAccountsBuilder) SetVaultAccount(vault ag_solanago.PublicKey) *ApproveStrategyAdminOnlyAccountsBuilder { + inst.AccountMetaSlice[1] = ag_solanago.Meta(vault) + return inst +} + +// GetVaultAccount gets the "vault" account. +func (inst *ApproveStrategyAdminOnlyAccountsBuilder) GetVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetAdminAccount sets the "admin" account. +func (inst *ApproveStrategyAdminOnlyAccountsBuilder) SetAdminAccount(admin ag_solanago.PublicKey) *ApproveStrategyAdminOnlyAccountsBuilder { + inst.AccountMetaSlice[2] = ag_solanago.Meta(admin).SIGNER() + return inst +} + +// GetAdminAccount gets the "admin" account. +func (inst *ApproveStrategyAdminOnlyAccountsBuilder) GetAdminAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetStrategyAccount sets the "strategy" account. +func (inst *ApproveStrategy) SetStrategyAccount(strategy ag_solanago.PublicKey) *ApproveStrategy { + inst.AccountMetaSlice[4] = ag_solanago.Meta(strategy).WRITE() + return inst +} + +// GetStrategyAccount gets the "strategy" account. +func (inst *ApproveStrategy) GetStrategyAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +func (inst ApproveStrategy) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_ApproveStrategy, + }} +} + +// 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 ApproveStrategy) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *ApproveStrategy) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.AdminOnly is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.AdminOnlyPool is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.AdminOnlyVault is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.AdminOnlyAdmin is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.Strategy is not set") + } + } + return nil +} + +func (inst *ApproveStrategy) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("ApproveStrategy")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=5]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" admin_only", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" admin_only/pool", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta("admin_only/vault", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta("admin_only/admin", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" strategy", inst.AccountMetaSlice.Get(4))) + }) + }) + }) +} + +func (obj ApproveStrategy) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *ApproveStrategy) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewApproveStrategyInstruction declares a new ApproveStrategy instruction with the provided parameters and accounts. +func NewApproveStrategyInstruction( + // Accounts: + adminOnly ag_solanago.PublicKey, + adminOnlyPool ag_solanago.PublicKey, + adminOnlyVault ag_solanago.PublicKey, + adminOnlyAdmin ag_solanago.PublicKey, + strategy ag_solanago.PublicKey) *ApproveStrategy { + return NewApproveStrategyInstructionBuilder(). + SetAdminOnlyAccount(adminOnly). + SetAdminOnlyAccountsFromBuilder( + NewApproveStrategyAdminOnlyAccountsBuilder(). + SetPoolAccount(adminOnlyPool). + SetVaultAccount(adminOnlyVault). + SetAdminAccount(adminOnlyAdmin), + ). + SetStrategyAccount(strategy) +} diff --git a/programs/stabblestableswap/approvestrategy_test.go b/programs/stabblestableswap/approvestrategy_test.go new file mode 100644 index 00000000..bb8feb3e --- /dev/null +++ b/programs/stabblestableswap/approvestrategy_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package stable_swap + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_ApproveStrategy(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("ApproveStrategy"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(ApproveStrategy) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(ApproveStrategy) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/stabblestableswap/changeampfactor.go b/programs/stabblestableswap/changeampfactor.go new file mode 100644 index 00000000..65018d65 --- /dev/null +++ b/programs/stabblestableswap/changeampfactor.go @@ -0,0 +1,188 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package stable_swap + +import ( + "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" +) + +// ChangeAmpFactor is the `change_amp_factor` instruction. +type ChangeAmpFactor struct { + NewAmpFactor *uint16 + RampDuration *uint32 + + // [0] = [WRITE] pool + // + // [1] = [] vault + // + // [2] = [SIGNER] admin + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewChangeAmpFactorInstructionBuilder creates a new `ChangeAmpFactor` instruction builder. +func NewChangeAmpFactorInstructionBuilder() *ChangeAmpFactor { + nd := &ChangeAmpFactor{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 3), + } + return nd +} + +// SetNewAmpFactor sets the "new_amp_factor" parameter. +func (inst *ChangeAmpFactor) SetNewAmpFactor(new_amp_factor uint16) *ChangeAmpFactor { + inst.NewAmpFactor = &new_amp_factor + return inst +} + +// SetRampDuration sets the "ramp_duration" parameter. +func (inst *ChangeAmpFactor) SetRampDuration(ramp_duration uint32) *ChangeAmpFactor { + inst.RampDuration = &ramp_duration + return inst +} + +// SetPoolAccount sets the "pool" account. +func (inst *ChangeAmpFactor) SetPoolAccount(pool ag_solanago.PublicKey) *ChangeAmpFactor { + inst.AccountMetaSlice[0] = ag_solanago.Meta(pool).WRITE() + return inst +} + +// GetPoolAccount gets the "pool" account. +func (inst *ChangeAmpFactor) GetPoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetVaultAccount sets the "vault" account. +func (inst *ChangeAmpFactor) SetVaultAccount(vault ag_solanago.PublicKey) *ChangeAmpFactor { + inst.AccountMetaSlice[1] = ag_solanago.Meta(vault) + return inst +} + +// GetVaultAccount gets the "vault" account. +func (inst *ChangeAmpFactor) GetVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetAdminAccount sets the "admin" account. +func (inst *ChangeAmpFactor) SetAdminAccount(admin ag_solanago.PublicKey) *ChangeAmpFactor { + inst.AccountMetaSlice[2] = ag_solanago.Meta(admin).SIGNER() + return inst +} + +// GetAdminAccount gets the "admin" account. +func (inst *ChangeAmpFactor) GetAdminAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +func (inst ChangeAmpFactor) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_ChangeAmpFactor, + }} +} + +// 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 ChangeAmpFactor) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *ChangeAmpFactor) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.NewAmpFactor == nil { + return errors.New("NewAmpFactor parameter is not set") + } + if inst.RampDuration == nil { + return errors.New("RampDuration parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Pool is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Vault is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.Admin is not set") + } + } + return nil +} + +func (inst *ChangeAmpFactor) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("ChangeAmpFactor")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=2]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" NewAmpFactor", *inst.NewAmpFactor)) + paramsBranch.Child(ag_format.Param(" RampDuration", *inst.RampDuration)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=3]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" pool", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta("vault", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta("admin", inst.AccountMetaSlice.Get(2))) + }) + }) + }) +} + +func (obj ChangeAmpFactor) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `NewAmpFactor` param: + err = encoder.Encode(obj.NewAmpFactor) + if err != nil { + return err + } + // Serialize `RampDuration` param: + err = encoder.Encode(obj.RampDuration) + if err != nil { + return err + } + return nil +} +func (obj *ChangeAmpFactor) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `NewAmpFactor`: + err = decoder.Decode(&obj.NewAmpFactor) + if err != nil { + return err + } + // Deserialize `RampDuration`: + err = decoder.Decode(&obj.RampDuration) + if err != nil { + return err + } + return nil +} + +// NewChangeAmpFactorInstruction declares a new ChangeAmpFactor instruction with the provided parameters and accounts. +func NewChangeAmpFactorInstruction( + // Parameters: + new_amp_factor uint16, + ramp_duration uint32, + // Accounts: + pool ag_solanago.PublicKey, + vault ag_solanago.PublicKey, + admin ag_solanago.PublicKey) *ChangeAmpFactor { + return NewChangeAmpFactorInstructionBuilder(). + SetNewAmpFactor(new_amp_factor). + SetRampDuration(ramp_duration). + SetPoolAccount(pool). + SetVaultAccount(vault). + SetAdminAccount(admin) +} diff --git a/programs/stabblestableswap/changeampfactor_test.go b/programs/stabblestableswap/changeampfactor_test.go new file mode 100644 index 00000000..11cadf5d --- /dev/null +++ b/programs/stabblestableswap/changeampfactor_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package stable_swap + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_ChangeAmpFactor(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("ChangeAmpFactor"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(ChangeAmpFactor) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(ChangeAmpFactor) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/stabblestableswap/changeswapfee.go b/programs/stabblestableswap/changeswapfee.go new file mode 100644 index 00000000..1c324979 --- /dev/null +++ b/programs/stabblestableswap/changeswapfee.go @@ -0,0 +1,146 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package stable_swap + +import ( + "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" +) + +// ChangeSwapFee is the `change_swap_fee` instruction. +type ChangeSwapFee struct { + NewSwapFee *uint64 + + // [0] = [SIGNER] owner + // + // [1] = [WRITE] pool + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewChangeSwapFeeInstructionBuilder creates a new `ChangeSwapFee` instruction builder. +func NewChangeSwapFeeInstructionBuilder() *ChangeSwapFee { + nd := &ChangeSwapFee{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 2), + } + return nd +} + +// SetNewSwapFee sets the "new_swap_fee" parameter. +func (inst *ChangeSwapFee) SetNewSwapFee(new_swap_fee uint64) *ChangeSwapFee { + inst.NewSwapFee = &new_swap_fee + return inst +} + +// SetOwnerAccount sets the "owner" account. +func (inst *ChangeSwapFee) SetOwnerAccount(owner ag_solanago.PublicKey) *ChangeSwapFee { + inst.AccountMetaSlice[0] = ag_solanago.Meta(owner).SIGNER() + return inst +} + +// GetOwnerAccount gets the "owner" account. +func (inst *ChangeSwapFee) GetOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetPoolAccount sets the "pool" account. +func (inst *ChangeSwapFee) SetPoolAccount(pool ag_solanago.PublicKey) *ChangeSwapFee { + inst.AccountMetaSlice[1] = ag_solanago.Meta(pool).WRITE() + return inst +} + +// GetPoolAccount gets the "pool" account. +func (inst *ChangeSwapFee) GetPoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +func (inst ChangeSwapFee) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_ChangeSwapFee, + }} +} + +// 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 ChangeSwapFee) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *ChangeSwapFee) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.NewSwapFee == nil { + return errors.New("NewSwapFee parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Owner is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Pool is not set") + } + } + return nil +} + +func (inst *ChangeSwapFee) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("ChangeSwapFee")). + // + 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(" NewSwapFee", *inst.NewSwapFee)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=2]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta("owner", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" pool", inst.AccountMetaSlice.Get(1))) + }) + }) + }) +} + +func (obj ChangeSwapFee) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `NewSwapFee` param: + err = encoder.Encode(obj.NewSwapFee) + if err != nil { + return err + } + return nil +} +func (obj *ChangeSwapFee) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `NewSwapFee`: + err = decoder.Decode(&obj.NewSwapFee) + if err != nil { + return err + } + return nil +} + +// NewChangeSwapFeeInstruction declares a new ChangeSwapFee instruction with the provided parameters and accounts. +func NewChangeSwapFeeInstruction( + // Parameters: + new_swap_fee uint64, + // Accounts: + owner ag_solanago.PublicKey, + pool ag_solanago.PublicKey) *ChangeSwapFee { + return NewChangeSwapFeeInstructionBuilder(). + SetNewSwapFee(new_swap_fee). + SetOwnerAccount(owner). + SetPoolAccount(pool) +} diff --git a/programs/stabblestableswap/changeswapfee_test.go b/programs/stabblestableswap/changeswapfee_test.go new file mode 100644 index 00000000..eea9cd0b --- /dev/null +++ b/programs/stabblestableswap/changeswapfee_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package stable_swap + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_ChangeSwapFee(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("ChangeSwapFee"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(ChangeSwapFee) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(ChangeSwapFee) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/stabblestableswap/constants.go b/programs/stabblestableswap/constants.go new file mode 100644 index 00000000..b17f15db --- /dev/null +++ b/programs/stabblestableswap/constants.go @@ -0,0 +1,3 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package stable_swap diff --git a/programs/stabblestableswap/createstrategy.go b/programs/stabblestableswap/createstrategy.go new file mode 100644 index 00000000..b19b688e --- /dev/null +++ b/programs/stabblestableswap/createstrategy.go @@ -0,0 +1,318 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package stable_swap + +import ( + "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" +) + +// CreateStrategy is the `create_strategy` instruction. +type CreateStrategy struct { + AmpMinFactor *uint16 + AmpMaxFactor *uint16 + RampMinStep *uint16 + RampMaxStep *uint16 + RampMinDuration *uint32 + RampMaxDuration *uint32 + + // [0] = [] owner_only + // + // ····· owner_only: [1] = [SIGNER] owner + // + // ················· [2] = [WRITE] pool + // + // [3] = [WRITE] strategy + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewCreateStrategyInstructionBuilder creates a new `CreateStrategy` instruction builder. +func NewCreateStrategyInstructionBuilder() *CreateStrategy { + nd := &CreateStrategy{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 4), + } + return nd +} + +// SetAmpMinFactor sets the "amp_min_factor" parameter. +func (inst *CreateStrategy) SetAmpMinFactor(amp_min_factor uint16) *CreateStrategy { + inst.AmpMinFactor = &_min_factor + return inst +} + +// SetAmpMaxFactor sets the "amp_max_factor" parameter. +func (inst *CreateStrategy) SetAmpMaxFactor(amp_max_factor uint16) *CreateStrategy { + inst.AmpMaxFactor = &_max_factor + return inst +} + +// SetRampMinStep sets the "ramp_min_step" parameter. +func (inst *CreateStrategy) SetRampMinStep(ramp_min_step uint16) *CreateStrategy { + inst.RampMinStep = &ramp_min_step + return inst +} + +// SetRampMaxStep sets the "ramp_max_step" parameter. +func (inst *CreateStrategy) SetRampMaxStep(ramp_max_step uint16) *CreateStrategy { + inst.RampMaxStep = &ramp_max_step + return inst +} + +// SetRampMinDuration sets the "ramp_min_duration" parameter. +func (inst *CreateStrategy) SetRampMinDuration(ramp_min_duration uint32) *CreateStrategy { + inst.RampMinDuration = &ramp_min_duration + return inst +} + +// SetRampMaxDuration sets the "ramp_max_duration" parameter. +func (inst *CreateStrategy) SetRampMaxDuration(ramp_max_duration uint32) *CreateStrategy { + inst.RampMaxDuration = &ramp_max_duration + return inst +} + +// SetOwnerOnlyAccount sets the "owner_only" account. +func (inst *CreateStrategy) SetOwnerOnlyAccount(ownerOnly ag_solanago.PublicKey) *CreateStrategy { + inst.AccountMetaSlice[0] = ag_solanago.Meta(ownerOnly) + return inst +} + +// GetOwnerOnlyAccount gets the "owner_only" account. +func (inst *CreateStrategy) GetOwnerOnlyAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +type CreateStrategyOwnerOnlyAccountsBuilder struct { + ag_solanago.AccountMetaSlice `bin:"-"` +} + +func NewCreateStrategyOwnerOnlyAccountsBuilder() *CreateStrategyOwnerOnlyAccountsBuilder { + return &CreateStrategyOwnerOnlyAccountsBuilder{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 2), + } +} + +func (inst *CreateStrategy) SetOwnerOnlyAccountsFromBuilder(createStrategyOwnerOnlyAccountsBuilder *CreateStrategyOwnerOnlyAccountsBuilder) *CreateStrategy { + inst.AccountMetaSlice[1] = createStrategyOwnerOnlyAccountsBuilder.GetOwnerAccount() + inst.AccountMetaSlice[2] = createStrategyOwnerOnlyAccountsBuilder.GetPoolAccount() + return inst +} + +// SetOwnerAccount sets the "owner" account. +func (inst *CreateStrategyOwnerOnlyAccountsBuilder) SetOwnerAccount(owner ag_solanago.PublicKey) *CreateStrategyOwnerOnlyAccountsBuilder { + inst.AccountMetaSlice[0] = ag_solanago.Meta(owner).SIGNER() + return inst +} + +// GetOwnerAccount gets the "owner" account. +func (inst *CreateStrategyOwnerOnlyAccountsBuilder) GetOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetPoolAccount sets the "pool" account. +func (inst *CreateStrategyOwnerOnlyAccountsBuilder) SetPoolAccount(pool ag_solanago.PublicKey) *CreateStrategyOwnerOnlyAccountsBuilder { + inst.AccountMetaSlice[1] = ag_solanago.Meta(pool).WRITE() + return inst +} + +// GetPoolAccount gets the "pool" account. +func (inst *CreateStrategyOwnerOnlyAccountsBuilder) GetPoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetStrategyAccount sets the "strategy" account. +func (inst *CreateStrategy) SetStrategyAccount(strategy ag_solanago.PublicKey) *CreateStrategy { + inst.AccountMetaSlice[3] = ag_solanago.Meta(strategy).WRITE() + return inst +} + +// GetStrategyAccount gets the "strategy" account. +func (inst *CreateStrategy) GetStrategyAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +func (inst CreateStrategy) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_CreateStrategy, + }} +} + +// 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 CreateStrategy) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *CreateStrategy) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.AmpMinFactor == nil { + return errors.New("AmpMinFactor parameter is not set") + } + if inst.AmpMaxFactor == nil { + return errors.New("AmpMaxFactor parameter is not set") + } + if inst.RampMinStep == nil { + return errors.New("RampMinStep parameter is not set") + } + if inst.RampMaxStep == nil { + return errors.New("RampMaxStep parameter is not set") + } + if inst.RampMinDuration == nil { + return errors.New("RampMinDuration parameter is not set") + } + if inst.RampMaxDuration == nil { + return errors.New("RampMaxDuration parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.OwnerOnly is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.OwnerOnlyOwner is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.OwnerOnlyPool is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.Strategy is not set") + } + } + return nil +} + +func (inst *CreateStrategy) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("CreateStrategy")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=6]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" AmpMinFactor", *inst.AmpMinFactor)) + paramsBranch.Child(ag_format.Param(" AmpMaxFactor", *inst.AmpMaxFactor)) + paramsBranch.Child(ag_format.Param(" RampMinStep", *inst.RampMinStep)) + paramsBranch.Child(ag_format.Param(" RampMaxStep", *inst.RampMaxStep)) + paramsBranch.Child(ag_format.Param(" RampMinDuration", *inst.RampMinDuration)) + paramsBranch.Child(ag_format.Param(" RampMaxDuration", *inst.RampMaxDuration)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=4]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" owner_only", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta("owner_only/owner", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" owner_only/pool", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" strategy", inst.AccountMetaSlice.Get(3))) + }) + }) + }) +} + +func (obj CreateStrategy) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `AmpMinFactor` param: + err = encoder.Encode(obj.AmpMinFactor) + if err != nil { + return err + } + // Serialize `AmpMaxFactor` param: + err = encoder.Encode(obj.AmpMaxFactor) + if err != nil { + return err + } + // Serialize `RampMinStep` param: + err = encoder.Encode(obj.RampMinStep) + if err != nil { + return err + } + // Serialize `RampMaxStep` param: + err = encoder.Encode(obj.RampMaxStep) + if err != nil { + return err + } + // Serialize `RampMinDuration` param: + err = encoder.Encode(obj.RampMinDuration) + if err != nil { + return err + } + // Serialize `RampMaxDuration` param: + err = encoder.Encode(obj.RampMaxDuration) + if err != nil { + return err + } + return nil +} +func (obj *CreateStrategy) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `AmpMinFactor`: + err = decoder.Decode(&obj.AmpMinFactor) + if err != nil { + return err + } + // Deserialize `AmpMaxFactor`: + err = decoder.Decode(&obj.AmpMaxFactor) + if err != nil { + return err + } + // Deserialize `RampMinStep`: + err = decoder.Decode(&obj.RampMinStep) + if err != nil { + return err + } + // Deserialize `RampMaxStep`: + err = decoder.Decode(&obj.RampMaxStep) + if err != nil { + return err + } + // Deserialize `RampMinDuration`: + err = decoder.Decode(&obj.RampMinDuration) + if err != nil { + return err + } + // Deserialize `RampMaxDuration`: + err = decoder.Decode(&obj.RampMaxDuration) + if err != nil { + return err + } + return nil +} + +// NewCreateStrategyInstruction declares a new CreateStrategy instruction with the provided parameters and accounts. +func NewCreateStrategyInstruction( + // Parameters: + amp_min_factor uint16, + amp_max_factor uint16, + ramp_min_step uint16, + ramp_max_step uint16, + ramp_min_duration uint32, + ramp_max_duration uint32, + // Accounts: + ownerOnly ag_solanago.PublicKey, + ownerOnlyOwner ag_solanago.PublicKey, + ownerOnlyPool ag_solanago.PublicKey, + strategy ag_solanago.PublicKey) *CreateStrategy { + return NewCreateStrategyInstructionBuilder(). + SetAmpMinFactor(amp_min_factor). + SetAmpMaxFactor(amp_max_factor). + SetRampMinStep(ramp_min_step). + SetRampMaxStep(ramp_max_step). + SetRampMinDuration(ramp_min_duration). + SetRampMaxDuration(ramp_max_duration). + SetOwnerOnlyAccount(ownerOnly). + SetOwnerOnlyAccountsFromBuilder( + NewCreateStrategyOwnerOnlyAccountsBuilder(). + SetOwnerAccount(ownerOnlyOwner). + SetPoolAccount(ownerOnlyPool), + ). + SetStrategyAccount(strategy) +} diff --git a/programs/stabblestableswap/createstrategy_test.go b/programs/stabblestableswap/createstrategy_test.go new file mode 100644 index 00000000..e27212c6 --- /dev/null +++ b/programs/stabblestableswap/createstrategy_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package stable_swap + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_CreateStrategy(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("CreateStrategy"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(CreateStrategy) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(CreateStrategy) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/stabblestableswap/deposit.go b/programs/stabblestableswap/deposit.go new file mode 100644 index 00000000..a5115306 --- /dev/null +++ b/programs/stabblestableswap/deposit.go @@ -0,0 +1,302 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package stable_swap + +import ( + "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" +) + +// add liquidity +type Deposit struct { + Amounts *[]uint64 + MinimumAmountOut *uint64 + + // [0] = [SIGNER] user + // + // [1] = [WRITE] user_pool_token + // + // [2] = [WRITE] mint + // + // [3] = [WRITE] pool + // + // [4] = [] pool_authority + // + // [5] = [] vault + // + // [6] = [] vault_authority + // + // [7] = [] token_program + // + // [8] = [] token_program_2022 + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewDepositInstructionBuilder creates a new `Deposit` instruction builder. +func NewDepositInstructionBuilder() *Deposit { + nd := &Deposit{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 9), + } + return nd +} + +// SetAmounts sets the "amounts" parameter. +func (inst *Deposit) SetAmounts(amounts []uint64) *Deposit { + inst.Amounts = &amounts + return inst +} + +// SetMinimumAmountOut sets the "minimum_amount_out" parameter. +func (inst *Deposit) SetMinimumAmountOut(minimum_amount_out uint64) *Deposit { + inst.MinimumAmountOut = &minimum_amount_out + return inst +} + +// SetUserAccount sets the "user" account. +func (inst *Deposit) SetUserAccount(user ag_solanago.PublicKey) *Deposit { + inst.AccountMetaSlice[0] = ag_solanago.Meta(user).SIGNER() + return inst +} + +// GetUserAccount gets the "user" account. +func (inst *Deposit) GetUserAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetUserPoolTokenAccount sets the "user_pool_token" account. +func (inst *Deposit) SetUserPoolTokenAccount(userPoolToken ag_solanago.PublicKey) *Deposit { + inst.AccountMetaSlice[1] = ag_solanago.Meta(userPoolToken).WRITE() + return inst +} + +// GetUserPoolTokenAccount gets the "user_pool_token" account. +func (inst *Deposit) GetUserPoolTokenAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetMintAccount sets the "mint" account. +func (inst *Deposit) SetMintAccount(mint ag_solanago.PublicKey) *Deposit { + inst.AccountMetaSlice[2] = ag_solanago.Meta(mint).WRITE() + return inst +} + +// GetMintAccount gets the "mint" account. +func (inst *Deposit) GetMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetPoolAccount sets the "pool" account. +func (inst *Deposit) SetPoolAccount(pool ag_solanago.PublicKey) *Deposit { + inst.AccountMetaSlice[3] = ag_solanago.Meta(pool).WRITE() + return inst +} + +// GetPoolAccount gets the "pool" account. +func (inst *Deposit) GetPoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetPoolAuthorityAccount sets the "pool_authority" account. +func (inst *Deposit) SetPoolAuthorityAccount(poolAuthority ag_solanago.PublicKey) *Deposit { + inst.AccountMetaSlice[4] = ag_solanago.Meta(poolAuthority) + return inst +} + +// GetPoolAuthorityAccount gets the "pool_authority" account. +func (inst *Deposit) GetPoolAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetVaultAccount sets the "vault" account. +func (inst *Deposit) SetVaultAccount(vault ag_solanago.PublicKey) *Deposit { + inst.AccountMetaSlice[5] = ag_solanago.Meta(vault) + return inst +} + +// GetVaultAccount gets the "vault" account. +func (inst *Deposit) GetVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetVaultAuthorityAccount sets the "vault_authority" account. +func (inst *Deposit) SetVaultAuthorityAccount(vaultAuthority ag_solanago.PublicKey) *Deposit { + inst.AccountMetaSlice[6] = ag_solanago.Meta(vaultAuthority) + return inst +} + +// GetVaultAuthorityAccount gets the "vault_authority" account. +func (inst *Deposit) GetVaultAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetTokenProgramAccount sets the "token_program" account. +func (inst *Deposit) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *Deposit { + inst.AccountMetaSlice[7] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "token_program" account. +func (inst *Deposit) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetTokenProgram2022Account sets the "token_program_2022" account. +func (inst *Deposit) SetTokenProgram2022Account(tokenProgram2022 ag_solanago.PublicKey) *Deposit { + inst.AccountMetaSlice[8] = ag_solanago.Meta(tokenProgram2022) + return inst +} + +// GetTokenProgram2022Account gets the "token_program_2022" account. +func (inst *Deposit) GetTokenProgram2022Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +func (inst Deposit) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_Deposit, + }} +} + +// 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 Deposit) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *Deposit) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.Amounts == nil { + return errors.New("Amounts parameter is not set") + } + if inst.MinimumAmountOut == nil { + return errors.New("MinimumAmountOut parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.User is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.UserPoolToken is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.Mint is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.Pool is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.PoolAuthority is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.Vault is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.VaultAuthority is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.TokenProgram2022 is not set") + } + } + return nil +} + +func (inst *Deposit) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("Deposit")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=2]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" Amounts", *inst.Amounts)) + paramsBranch.Child(ag_format.Param(" MinimumAmountOut", *inst.MinimumAmountOut)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=9]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" user", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" user_pool_token", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" mint", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" pool", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" pool_authority", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" vault", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" vault_authority", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" token_program", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta("token_program_2022", inst.AccountMetaSlice.Get(8))) + }) + }) + }) +} + +func (obj Deposit) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Amounts` param: + err = encoder.Encode(obj.Amounts) + if err != nil { + return err + } + // Serialize `MinimumAmountOut` param: + err = encoder.Encode(obj.MinimumAmountOut) + if err != nil { + return err + } + return nil +} +func (obj *Deposit) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Amounts`: + err = decoder.Decode(&obj.Amounts) + if err != nil { + return err + } + // Deserialize `MinimumAmountOut`: + err = decoder.Decode(&obj.MinimumAmountOut) + if err != nil { + return err + } + return nil +} + +// NewDepositInstruction declares a new Deposit instruction with the provided parameters and accounts. +func NewDepositInstruction( + // Parameters: + amounts []uint64, + minimum_amount_out uint64, + // Accounts: + user ag_solanago.PublicKey, + userPoolToken ag_solanago.PublicKey, + mint ag_solanago.PublicKey, + pool ag_solanago.PublicKey, + poolAuthority ag_solanago.PublicKey, + vault ag_solanago.PublicKey, + vaultAuthority ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + tokenProgram2022 ag_solanago.PublicKey) *Deposit { + return NewDepositInstructionBuilder(). + SetAmounts(amounts). + SetMinimumAmountOut(minimum_amount_out). + SetUserAccount(user). + SetUserPoolTokenAccount(userPoolToken). + SetMintAccount(mint). + SetPoolAccount(pool). + SetPoolAuthorityAccount(poolAuthority). + SetVaultAccount(vault). + SetVaultAuthorityAccount(vaultAuthority). + SetTokenProgramAccount(tokenProgram). + SetTokenProgram2022Account(tokenProgram2022) +} diff --git a/programs/stabblestableswap/deposit_test.go b/programs/stabblestableswap/deposit_test.go new file mode 100644 index 00000000..8ffcc980 --- /dev/null +++ b/programs/stabblestableswap/deposit_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package stable_swap + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_Deposit(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("Deposit"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(Deposit) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(Deposit) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/stabblestableswap/errors.go b/programs/stabblestableswap/errors.go new file mode 100644 index 00000000..3182e421 --- /dev/null +++ b/programs/stabblestableswap/errors.go @@ -0,0 +1,83 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package stable_swap + +import ( + "encoding/json" + "errors" + "fmt" + ag_jsonrpc "github.com/gagliardetto/solana-go/rpc/jsonrpc" +) + +var ( + _ *json.Encoder = nil + _ *ag_jsonrpc.RPCError = nil + _ fmt.Formatter = nil + _ = errors.ErrUnsupported +) +var ( + Errors = map[int]CustomError{} +) + +type CustomError interface { + Code() int + Name() string + Error() string +} + +type customErrorDef struct { + code int + name string + msg string +} + +func (e *customErrorDef) Code() int { + return e.code +} + +func (e *customErrorDef) Name() string { + return e.name +} + +func (e *customErrorDef) Error() string { + return fmt.Sprintf("%s(%d): %s", e.name, e.code, e.msg) +} + +func DecodeCustomError(rpcErr error) (err error, ok bool) { + if errCode, o := decodeErrorCode(rpcErr); o { + if customErr, o := Errors[errCode]; o { + err = customErr + ok = true + return + } + } + return +} + +func decodeErrorCode(rpcErr error) (errorCode int, ok bool) { + var jErr *ag_jsonrpc.RPCError + if errors.As(rpcErr, &jErr) && jErr.Data != nil { + if root, o := jErr.Data.(map[string]interface{}); o { + if rootErr, o := root["err"].(map[string]interface{}); o { + if rootErrInstructionError, o := rootErr["InstructionError"]; o { + if rootErrInstructionErrorItems, o := rootErrInstructionError.([]interface{}); o { + if len(rootErrInstructionErrorItems) == 2 { + if v, o := rootErrInstructionErrorItems[1].(map[string]interface{}); o { + if v2, o := v["Custom"].(json.Number); o { + if code, err := v2.Int64(); err == nil { + ok = true + errorCode = int(code) + } + } else if v2, o := v["Custom"].(float64); o { + ok = true + errorCode = int(v2) + } + } + } + } + } + } + } + } + return +} diff --git a/programs/stabblestableswap/events.go b/programs/stabblestableswap/events.go new file mode 100644 index 00000000..73354460 --- /dev/null +++ b/programs/stabblestableswap/events.go @@ -0,0 +1,243 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package stable_swap + +import ( + "encoding/base64" + "fmt" + ag_binary "github.com/gagliardetto/binary" + ag_solanago "github.com/gagliardetto/solana-go" + ag_rpc "github.com/gagliardetto/solana-go/rpc" + ag_base58 "github.com/mr-tron/base58" + "reflect" + "strings" +) + +type PoolBalanceUpdatedEventEventData struct { + Pubkey ag_solanago.PublicKey + Data PoolBalanceUpdatedData +} + +var PoolBalanceUpdatedEventEventDataDiscriminator = [8]byte{172, 82, 114, 207, 27, 103, 211, 4} + +func (obj PoolBalanceUpdatedEventEventData) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Write account discriminator: + err = encoder.WriteBytes(PoolBalanceUpdatedEventEventDataDiscriminator[:], false) + if err != nil { + return err + } + // Serialize `Pubkey` param: + err = encoder.Encode(obj.Pubkey) + if err != nil { + return err + } + // Serialize `Data` param: + err = encoder.Encode(obj.Data) + if err != nil { + return err + } + return nil +} + +func (obj *PoolBalanceUpdatedEventEventData) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Read and check account discriminator: + { + discriminator, err := decoder.ReadTypeID() + if err != nil { + return err + } + if !discriminator.Equal(PoolBalanceUpdatedEventEventDataDiscriminator[:]) { + return fmt.Errorf( + "wrong discriminator: wanted %s, got %s", + "[172 82 114 207 27 103 211 4]", + fmt.Sprint(discriminator[:])) + } + } + // Deserialize `Pubkey`: + err = decoder.Decode(&obj.Pubkey) + if err != nil { + return err + } + // Deserialize `Data`: + err = decoder.Decode(&obj.Data) + if err != nil { + return err + } + return nil +} + +func (*PoolBalanceUpdatedEventEventData) isEventData() {} + +type PoolUpdatedEventEventData struct { + Pubkey ag_solanago.PublicKey + Data PoolUpdatedData +} + +var PoolUpdatedEventEventDataDiscriminator = [8]byte{128, 39, 94, 221, 230, 222, 127, 141} + +func (obj PoolUpdatedEventEventData) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Write account discriminator: + err = encoder.WriteBytes(PoolUpdatedEventEventDataDiscriminator[:], false) + if err != nil { + return err + } + // Serialize `Pubkey` param: + err = encoder.Encode(obj.Pubkey) + if err != nil { + return err + } + // Serialize `Data` param: + err = encoder.Encode(obj.Data) + if err != nil { + return err + } + return nil +} + +func (obj *PoolUpdatedEventEventData) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Read and check account discriminator: + { + discriminator, err := decoder.ReadTypeID() + if err != nil { + return err + } + if !discriminator.Equal(PoolUpdatedEventEventDataDiscriminator[:]) { + return fmt.Errorf( + "wrong discriminator: wanted %s, got %s", + "[128 39 94 221 230 222 127 141]", + fmt.Sprint(discriminator[:])) + } + } + // Deserialize `Pubkey`: + err = decoder.Decode(&obj.Pubkey) + if err != nil { + return err + } + // Deserialize `Data`: + err = decoder.Decode(&obj.Data) + if err != nil { + return err + } + return nil +} + +func (*PoolUpdatedEventEventData) isEventData() {} + +var eventTypes = map[[8]byte]reflect.Type{ + PoolBalanceUpdatedEventEventDataDiscriminator: reflect.TypeOf(PoolBalanceUpdatedEventEventData{}), + PoolUpdatedEventEventDataDiscriminator: reflect.TypeOf(PoolUpdatedEventEventData{}), +} +var eventNames = map[[8]byte]string{ + PoolBalanceUpdatedEventEventDataDiscriminator: "PoolBalanceUpdatedEvent", + PoolUpdatedEventEventDataDiscriminator: "PoolUpdatedEvent", +} +var ( + _ *strings.Builder = nil +) +var ( + _ *base64.Encoding = nil +) +var ( + _ *ag_binary.Decoder = nil +) +var ( + _ *ag_rpc.GetTransactionResult = nil +) +var ( + _ *ag_base58.Alphabet = nil +) + +type Event struct { + Name string + Data EventData +} + +type EventData interface { + UnmarshalWithDecoder(decoder *ag_binary.Decoder) error + isEventData() +} + +const eventLogPrefix = "Program data: " + +func DecodeEventsFromLogMessage(logMessages []string) (eventBinaries [][]byte, err error) { + for _, log := range logMessages { + if strings.HasPrefix(log, eventLogPrefix) { + eventBase64 := log[len(eventLogPrefix):] + + var eventBinary []byte + if eventBinary, err = base64.StdEncoding.DecodeString(eventBase64); err != nil { + err = fmt.Errorf("failed to decode logMessage event: %s", eventBase64) + return + } + eventBinaries = append(eventBinaries, eventBinary) + } + } + return +} + +func DecodeEventsFromEmitCPI(InnerInstructions []ag_rpc.InnerInstruction, accountKeys ag_solanago.PublicKeySlice, targetProgramId ag_solanago.PublicKey) (eventBinaries [][]byte, err error) { + for _, parsedIx := range InnerInstructions { + for _, ix := range parsedIx.Instructions { + if accountKeys[ix.ProgramIDIndex] != targetProgramId { + continue + } + + var ixData []byte + if ixData, err = ag_base58.Decode(string(ix.Data)); err != nil { + err = fmt.Errorf("failed to decode base58 emit cpi event: %s", string(ixData)) + return + } + eventBase64 := base64.StdEncoding.EncodeToString(ixData[8:]) + var eventBinary []byte + if eventBinary, err = base64.StdEncoding.DecodeString(eventBase64); err != nil { + err = fmt.Errorf("failed to decode base64 emit cpi event: %s", eventBase64) + return + } + eventBinaries = append(eventBinaries, eventBinary) + } + } + return +} + +func DecodeEvents(txData *ag_rpc.GetTransactionResult, targetProgramId ag_solanago.PublicKey) (evts []*Event, err error) { + var tx *ag_solanago.Transaction + if tx, err = txData.Transaction.GetTransaction(); err != nil { + return + } + + var base64Binaries [][]byte + logMessageEventBinaries, err := DecodeEventsFromLogMessage(txData.Meta.LogMessages) + if err != nil { + return + } + emitedCPIEventBinaries, err := DecodeEventsFromEmitCPI(txData.Meta.InnerInstructions, tx.Message.AccountKeys, targetProgramId) + if err != nil { + return + } + + base64Binaries = append(base64Binaries, logMessageEventBinaries...) + base64Binaries = append(base64Binaries, emitedCPIEventBinaries...) + evts, err = ParseEvents(base64Binaries) + return +} + +func ParseEvents(base64Binaries [][]byte) (evts []*Event, err error) { + decoder := ag_binary.NewDecoderWithEncoding(nil, ag_binary.EncodingBorsh) + + for _, eventBinary := range base64Binaries { + eventDiscriminator := ag_binary.TypeID(eventBinary[:8]) + if eventType, ok := eventTypes[eventDiscriminator]; ok { + eventData := reflect.New(eventType).Interface().(EventData) + decoder.Reset(eventBinary) + if err = eventData.UnmarshalWithDecoder(decoder); err != nil { + err = fmt.Errorf("failed to unmarshal event %s: %w", eventType.String(), err) + return + } + evts = append(evts, &Event{ + Name: eventNames[eventDiscriminator], + Data: eventData, + }) + } + } + return +} diff --git a/programs/stabblestableswap/execstrategy.go b/programs/stabblestableswap/execstrategy.go new file mode 100644 index 00000000..58a9fa9f --- /dev/null +++ b/programs/stabblestableswap/execstrategy.go @@ -0,0 +1,169 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package stable_swap + +import ( + "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" +) + +// ExecStrategy is the `exec_strategy` instruction. +type ExecStrategy struct { + RampStep *uint16 + RampDuration *uint32 + + // [0] = [] strategy + // + // [1] = [WRITE] pool + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewExecStrategyInstructionBuilder creates a new `ExecStrategy` instruction builder. +func NewExecStrategyInstructionBuilder() *ExecStrategy { + nd := &ExecStrategy{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 2), + } + return nd +} + +// SetRampStep sets the "ramp_step" parameter. +func (inst *ExecStrategy) SetRampStep(ramp_step uint16) *ExecStrategy { + inst.RampStep = &ramp_step + return inst +} + +// SetRampDuration sets the "ramp_duration" parameter. +func (inst *ExecStrategy) SetRampDuration(ramp_duration uint32) *ExecStrategy { + inst.RampDuration = &ramp_duration + return inst +} + +// SetStrategyAccount sets the "strategy" account. +func (inst *ExecStrategy) SetStrategyAccount(strategy ag_solanago.PublicKey) *ExecStrategy { + inst.AccountMetaSlice[0] = ag_solanago.Meta(strategy) + return inst +} + +// GetStrategyAccount gets the "strategy" account. +func (inst *ExecStrategy) GetStrategyAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetPoolAccount sets the "pool" account. +func (inst *ExecStrategy) SetPoolAccount(pool ag_solanago.PublicKey) *ExecStrategy { + inst.AccountMetaSlice[1] = ag_solanago.Meta(pool).WRITE() + return inst +} + +// GetPoolAccount gets the "pool" account. +func (inst *ExecStrategy) GetPoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +func (inst ExecStrategy) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_ExecStrategy, + }} +} + +// 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 ExecStrategy) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *ExecStrategy) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.RampStep == nil { + return errors.New("RampStep parameter is not set") + } + if inst.RampDuration == nil { + return errors.New("RampDuration parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Strategy is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Pool is not set") + } + } + return nil +} + +func (inst *ExecStrategy) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("ExecStrategy")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=2]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" RampStep", *inst.RampStep)) + paramsBranch.Child(ag_format.Param(" RampDuration", *inst.RampDuration)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=2]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta("strategy", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" pool", inst.AccountMetaSlice.Get(1))) + }) + }) + }) +} + +func (obj ExecStrategy) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `RampStep` param: + err = encoder.Encode(obj.RampStep) + if err != nil { + return err + } + // Serialize `RampDuration` param: + err = encoder.Encode(obj.RampDuration) + if err != nil { + return err + } + return nil +} +func (obj *ExecStrategy) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `RampStep`: + err = decoder.Decode(&obj.RampStep) + if err != nil { + return err + } + // Deserialize `RampDuration`: + err = decoder.Decode(&obj.RampDuration) + if err != nil { + return err + } + return nil +} + +// NewExecStrategyInstruction declares a new ExecStrategy instruction with the provided parameters and accounts. +func NewExecStrategyInstruction( + // Parameters: + ramp_step uint16, + ramp_duration uint32, + // Accounts: + strategy ag_solanago.PublicKey, + pool ag_solanago.PublicKey) *ExecStrategy { + return NewExecStrategyInstructionBuilder(). + SetRampStep(ramp_step). + SetRampDuration(ramp_duration). + SetStrategyAccount(strategy). + SetPoolAccount(pool) +} diff --git a/programs/stabblestableswap/execstrategy_test.go b/programs/stabblestableswap/execstrategy_test.go new file mode 100644 index 00000000..46a82e7c --- /dev/null +++ b/programs/stabblestableswap/execstrategy_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package stable_swap + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_ExecStrategy(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("ExecStrategy"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(ExecStrategy) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(ExecStrategy) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/stabblestableswap/initialize.go b/programs/stabblestableswap/initialize.go new file mode 100644 index 00000000..7b500f6d --- /dev/null +++ b/programs/stabblestableswap/initialize.go @@ -0,0 +1,268 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package stable_swap + +import ( + "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" +) + +// initialize a pool +type Initialize struct { + AmpFactor *uint16 + SwapFee *uint64 + MaxCaps *[]uint64 + + // [0] = [SIGNER] owner + // + // [1] = [] mint + // + // [2] = [WRITE] pool + // + // [3] = [] pool_authority + // + // [4] = [] withdraw_authority + // + // [5] = [] vault + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewInitializeInstructionBuilder creates a new `Initialize` instruction builder. +func NewInitializeInstructionBuilder() *Initialize { + nd := &Initialize{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 6), + } + return nd +} + +// SetAmpFactor sets the "amp_factor" parameter. +func (inst *Initialize) SetAmpFactor(amp_factor uint16) *Initialize { + inst.AmpFactor = &_factor + return inst +} + +// SetSwapFee sets the "swap_fee" parameter. +func (inst *Initialize) SetSwapFee(swap_fee uint64) *Initialize { + inst.SwapFee = &swap_fee + return inst +} + +// SetMaxCaps sets the "max_caps" parameter. +func (inst *Initialize) SetMaxCaps(max_caps []uint64) *Initialize { + inst.MaxCaps = &max_caps + return inst +} + +// SetOwnerAccount sets the "owner" account. +func (inst *Initialize) SetOwnerAccount(owner ag_solanago.PublicKey) *Initialize { + inst.AccountMetaSlice[0] = ag_solanago.Meta(owner).SIGNER() + return inst +} + +// GetOwnerAccount gets the "owner" account. +func (inst *Initialize) GetOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetMintAccount sets the "mint" account. +func (inst *Initialize) SetMintAccount(mint ag_solanago.PublicKey) *Initialize { + inst.AccountMetaSlice[1] = ag_solanago.Meta(mint) + return inst +} + +// GetMintAccount gets the "mint" account. +func (inst *Initialize) GetMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetPoolAccount sets the "pool" account. +func (inst *Initialize) SetPoolAccount(pool ag_solanago.PublicKey) *Initialize { + inst.AccountMetaSlice[2] = ag_solanago.Meta(pool).WRITE() + return inst +} + +// GetPoolAccount gets the "pool" account. +func (inst *Initialize) GetPoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetPoolAuthorityAccount sets the "pool_authority" account. +func (inst *Initialize) SetPoolAuthorityAccount(poolAuthority ag_solanago.PublicKey) *Initialize { + inst.AccountMetaSlice[3] = ag_solanago.Meta(poolAuthority) + return inst +} + +// GetPoolAuthorityAccount gets the "pool_authority" account. +func (inst *Initialize) GetPoolAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetWithdrawAuthorityAccount sets the "withdraw_authority" account. +func (inst *Initialize) SetWithdrawAuthorityAccount(withdrawAuthority ag_solanago.PublicKey) *Initialize { + inst.AccountMetaSlice[4] = ag_solanago.Meta(withdrawAuthority) + return inst +} + +// GetWithdrawAuthorityAccount gets the "withdraw_authority" account. +func (inst *Initialize) GetWithdrawAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetVaultAccount sets the "vault" account. +func (inst *Initialize) SetVaultAccount(vault ag_solanago.PublicKey) *Initialize { + inst.AccountMetaSlice[5] = ag_solanago.Meta(vault) + return inst +} + +// GetVaultAccount gets the "vault" account. +func (inst *Initialize) GetVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +func (inst Initialize) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_Initialize, + }} +} + +// 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 Initialize) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *Initialize) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.AmpFactor == nil { + return errors.New("AmpFactor parameter is not set") + } + if inst.SwapFee == nil { + return errors.New("SwapFee parameter is not set") + } + if inst.MaxCaps == nil { + return errors.New("MaxCaps parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Owner is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Mint is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.Pool is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.PoolAuthority is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.WithdrawAuthority is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.Vault is not set") + } + } + return nil +} + +func (inst *Initialize) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("Initialize")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=3]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" AmpFactor", *inst.AmpFactor)) + paramsBranch.Child(ag_format.Param(" SwapFee", *inst.SwapFee)) + paramsBranch.Child(ag_format.Param(" MaxCaps", *inst.MaxCaps)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=6]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" owner", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" mint", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" pool", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" pool_authority", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta("withdraw_authority", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" vault", inst.AccountMetaSlice.Get(5))) + }) + }) + }) +} + +func (obj Initialize) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `AmpFactor` param: + err = encoder.Encode(obj.AmpFactor) + if err != nil { + return err + } + // Serialize `SwapFee` param: + err = encoder.Encode(obj.SwapFee) + if err != nil { + return err + } + // Serialize `MaxCaps` param: + err = encoder.Encode(obj.MaxCaps) + if err != nil { + return err + } + return nil +} +func (obj *Initialize) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `AmpFactor`: + err = decoder.Decode(&obj.AmpFactor) + if err != nil { + return err + } + // Deserialize `SwapFee`: + err = decoder.Decode(&obj.SwapFee) + if err != nil { + return err + } + // Deserialize `MaxCaps`: + err = decoder.Decode(&obj.MaxCaps) + if err != nil { + return err + } + return nil +} + +// NewInitializeInstruction declares a new Initialize instruction with the provided parameters and accounts. +func NewInitializeInstruction( + // Parameters: + amp_factor uint16, + swap_fee uint64, + max_caps []uint64, + // Accounts: + owner ag_solanago.PublicKey, + mint ag_solanago.PublicKey, + pool ag_solanago.PublicKey, + poolAuthority ag_solanago.PublicKey, + withdrawAuthority ag_solanago.PublicKey, + vault ag_solanago.PublicKey) *Initialize { + return NewInitializeInstructionBuilder(). + SetAmpFactor(amp_factor). + SetSwapFee(swap_fee). + SetMaxCaps(max_caps). + SetOwnerAccount(owner). + SetMintAccount(mint). + SetPoolAccount(pool). + SetPoolAuthorityAccount(poolAuthority). + SetWithdrawAuthorityAccount(withdrawAuthority). + SetVaultAccount(vault) +} diff --git a/programs/stabblestableswap/initialize_test.go b/programs/stabblestableswap/initialize_test.go new file mode 100644 index 00000000..af695a9e --- /dev/null +++ b/programs/stabblestableswap/initialize_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package stable_swap + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_Initialize(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("Initialize"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(Initialize) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(Initialize) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/stabblestableswap/instructions.go b/programs/stabblestableswap/instructions.go new file mode 100644 index 00000000..439ec9ca --- /dev/null +++ b/programs/stabblestableswap/instructions.go @@ -0,0 +1,249 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package stable_swap + +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(PublicKey ag_solanago.PublicKey) { + ProgramID = PublicKey + ag_solanago.RegisterInstructionDecoder(ProgramID, registryDecodeInstruction) +} + +const ProgramName = "StableSwap" + +func init() { + if !ProgramID.IsZero() { + ag_solanago.RegisterInstructionDecoder(ProgramID, registryDecodeInstruction) + } +} + +var ( + Instruction_AcceptOwner = ag_binary.TypeID([8]byte{176, 23, 41, 28, 23, 111, 8, 4}) + + Instruction_ApproveStrategy = ag_binary.TypeID([8]byte{7, 141, 162, 60, 71, 115, 26, 146}) + + Instruction_ChangeAmpFactor = ag_binary.TypeID([8]byte{56, 238, 189, 35, 200, 157, 42, 66}) + + Instruction_ChangeSwapFee = ag_binary.TypeID([8]byte{231, 15, 132, 51, 132, 165, 64, 170}) + + Instruction_CreateStrategy = ag_binary.TypeID([8]byte{152, 160, 107, 148, 245, 190, 127, 224}) + + // add liquidity + Instruction_Deposit = ag_binary.TypeID([8]byte{242, 35, 198, 137, 82, 225, 242, 182}) + + Instruction_ExecStrategy = ag_binary.TypeID([8]byte{249, 46, 55, 57, 31, 38, 61, 27}) + + // initialize a pool + Instruction_Initialize = ag_binary.TypeID([8]byte{175, 175, 109, 31, 13, 152, 155, 237}) + + Instruction_Pause = ag_binary.TypeID([8]byte{211, 22, 221, 251, 74, 121, 193, 47}) + + Instruction_RejectOwner = ag_binary.TypeID([8]byte{238, 206, 198, 215, 51, 178, 133, 228}) + + // shutdown the zero-liquidity pool + Instruction_Shutdown = ag_binary.TypeID([8]byte{146, 204, 241, 213, 86, 21, 253, 211}) + + // swap + Instruction_Swap = ag_binary.TypeID([8]byte{248, 198, 158, 145, 225, 117, 135, 200}) + + Instruction_SwapV2 = ag_binary.TypeID([8]byte{43, 4, 237, 11, 26, 201, 30, 98}) + + Instruction_TransferOwner = ag_binary.TypeID([8]byte{245, 25, 221, 175, 106, 229, 225, 45}) + + Instruction_Unpause = ag_binary.TypeID([8]byte{169, 144, 4, 38, 10, 141, 188, 255}) + + // remove liquidity + Instruction_Withdraw = ag_binary.TypeID([8]byte{183, 18, 70, 156, 148, 109, 161, 34}) +) + +// InstructionIDToName returns the name of the instruction given its ID. +func InstructionIDToName(id ag_binary.TypeID) string { + switch id { + case Instruction_AcceptOwner: + return "AcceptOwner" + case Instruction_ApproveStrategy: + return "ApproveStrategy" + case Instruction_ChangeAmpFactor: + return "ChangeAmpFactor" + case Instruction_ChangeSwapFee: + return "ChangeSwapFee" + case Instruction_CreateStrategy: + return "CreateStrategy" + case Instruction_Deposit: + return "Deposit" + case Instruction_ExecStrategy: + return "ExecStrategy" + case Instruction_Initialize: + return "Initialize" + case Instruction_Pause: + return "Pause" + case Instruction_RejectOwner: + return "RejectOwner" + case Instruction_Shutdown: + return "Shutdown" + case Instruction_Swap: + return "Swap" + case Instruction_SwapV2: + return "SwapV2" + case Instruction_TransferOwner: + return "TransferOwner" + case Instruction_Unpause: + return "Unpause" + case Instruction_Withdraw: + return "Withdraw" + 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{ + { + Name: "accept_owner", Type: (*AcceptOwner)(nil), + }, + { + Name: "approve_strategy", Type: (*ApproveStrategy)(nil), + }, + { + Name: "change_amp_factor", Type: (*ChangeAmpFactor)(nil), + }, + { + Name: "change_swap_fee", Type: (*ChangeSwapFee)(nil), + }, + { + Name: "create_strategy", Type: (*CreateStrategy)(nil), + }, + { + Name: "deposit", Type: (*Deposit)(nil), + }, + { + Name: "exec_strategy", Type: (*ExecStrategy)(nil), + }, + { + Name: "initialize", Type: (*Initialize)(nil), + }, + { + Name: "pause", Type: (*Pause)(nil), + }, + { + Name: "reject_owner", Type: (*RejectOwner)(nil), + }, + { + Name: "shutdown", Type: (*Shutdown)(nil), + }, + { + Name: "swap", Type: (*Swap)(nil), + }, + { + Name: "swap_v2", Type: (*SwapV2)(nil), + }, + { + Name: "transfer_owner", Type: (*TransferOwner)(nil), + }, + { + Name: "unpause", Type: (*Unpause)(nil), + }, + { + Name: "withdraw", Type: (*Withdraw)(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 +} + +func DecodeInstructions(message *ag_solanago.Message) (instructions []*Instruction, err error) { + for _, ins := range message.Instructions { + var programID ag_solanago.PublicKey + if programID, err = message.Program(ins.ProgramIDIndex); err != nil { + return + } + if !programID.Equals(ProgramID) { + continue + } + var accounts []*ag_solanago.AccountMeta + if accounts, err = ins.ResolveInstructionAccounts(message); err != nil { + return + } + var insDecoded *Instruction + if insDecoded, err = decodeInstruction(accounts, ins.Data); err != nil { + return + } + instructions = append(instructions, insDecoded) + } + return +} diff --git a/programs/stabblestableswap/pause.go b/programs/stabblestableswap/pause.go new file mode 100644 index 00000000..678416b1 --- /dev/null +++ b/programs/stabblestableswap/pause.go @@ -0,0 +1,117 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package stable_swap + +import ( + "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" +) + +// Pause is the `pause` instruction. +type Pause struct { + + // [0] = [SIGNER] owner + // + // [1] = [WRITE] pool + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewPauseInstructionBuilder creates a new `Pause` instruction builder. +func NewPauseInstructionBuilder() *Pause { + nd := &Pause{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 2), + } + return nd +} + +// SetOwnerAccount sets the "owner" account. +func (inst *Pause) SetOwnerAccount(owner ag_solanago.PublicKey) *Pause { + inst.AccountMetaSlice[0] = ag_solanago.Meta(owner).SIGNER() + return inst +} + +// GetOwnerAccount gets the "owner" account. +func (inst *Pause) GetOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetPoolAccount sets the "pool" account. +func (inst *Pause) SetPoolAccount(pool ag_solanago.PublicKey) *Pause { + inst.AccountMetaSlice[1] = ag_solanago.Meta(pool).WRITE() + return inst +} + +// GetPoolAccount gets the "pool" account. +func (inst *Pause) GetPoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +func (inst Pause) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_Pause, + }} +} + +// 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 Pause) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *Pause) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Owner is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Pool is not set") + } + } + return nil +} + +func (inst *Pause) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("Pause")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=2]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta("owner", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" pool", inst.AccountMetaSlice.Get(1))) + }) + }) + }) +} + +func (obj Pause) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *Pause) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewPauseInstruction declares a new Pause instruction with the provided parameters and accounts. +func NewPauseInstruction( + // Accounts: + owner ag_solanago.PublicKey, + pool ag_solanago.PublicKey) *Pause { + return NewPauseInstructionBuilder(). + SetOwnerAccount(owner). + SetPoolAccount(pool) +} diff --git a/programs/stabblestableswap/pause_test.go b/programs/stabblestableswap/pause_test.go new file mode 100644 index 00000000..5517e880 --- /dev/null +++ b/programs/stabblestableswap/pause_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package stable_swap + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_Pause(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("Pause"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(Pause) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(Pause) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/stabblestableswap/rejectowner.go b/programs/stabblestableswap/rejectowner.go new file mode 100644 index 00000000..72a7aeee --- /dev/null +++ b/programs/stabblestableswap/rejectowner.go @@ -0,0 +1,117 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package stable_swap + +import ( + "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" +) + +// RejectOwner is the `reject_owner` instruction. +type RejectOwner struct { + + // [0] = [SIGNER] pending_owner + // + // [1] = [WRITE] pool + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewRejectOwnerInstructionBuilder creates a new `RejectOwner` instruction builder. +func NewRejectOwnerInstructionBuilder() *RejectOwner { + nd := &RejectOwner{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 2), + } + return nd +} + +// SetPendingOwnerAccount sets the "pending_owner" account. +func (inst *RejectOwner) SetPendingOwnerAccount(pendingOwner ag_solanago.PublicKey) *RejectOwner { + inst.AccountMetaSlice[0] = ag_solanago.Meta(pendingOwner).SIGNER() + return inst +} + +// GetPendingOwnerAccount gets the "pending_owner" account. +func (inst *RejectOwner) GetPendingOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetPoolAccount sets the "pool" account. +func (inst *RejectOwner) SetPoolAccount(pool ag_solanago.PublicKey) *RejectOwner { + inst.AccountMetaSlice[1] = ag_solanago.Meta(pool).WRITE() + return inst +} + +// GetPoolAccount gets the "pool" account. +func (inst *RejectOwner) GetPoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +func (inst RejectOwner) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_RejectOwner, + }} +} + +// 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 RejectOwner) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *RejectOwner) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.PendingOwner is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Pool is not set") + } + } + return nil +} + +func (inst *RejectOwner) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("RejectOwner")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=2]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta("pending_owner", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" pool", inst.AccountMetaSlice.Get(1))) + }) + }) + }) +} + +func (obj RejectOwner) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *RejectOwner) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewRejectOwnerInstruction declares a new RejectOwner instruction with the provided parameters and accounts. +func NewRejectOwnerInstruction( + // Accounts: + pendingOwner ag_solanago.PublicKey, + pool ag_solanago.PublicKey) *RejectOwner { + return NewRejectOwnerInstructionBuilder(). + SetPendingOwnerAccount(pendingOwner). + SetPoolAccount(pool) +} diff --git a/programs/stabblestableswap/rejectowner_test.go b/programs/stabblestableswap/rejectowner_test.go new file mode 100644 index 00000000..08e7ca3f --- /dev/null +++ b/programs/stabblestableswap/rejectowner_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package stable_swap + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_RejectOwner(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("RejectOwner"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(RejectOwner) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(RejectOwner) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/stabblestableswap/shutdown.go b/programs/stabblestableswap/shutdown.go new file mode 100644 index 00000000..f8238dd6 --- /dev/null +++ b/programs/stabblestableswap/shutdown.go @@ -0,0 +1,117 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package stable_swap + +import ( + "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" +) + +// shutdown the zero-liquidity pool +type Shutdown struct { + + // [0] = [WRITE] owner + // + // [1] = [WRITE] pool + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewShutdownInstructionBuilder creates a new `Shutdown` instruction builder. +func NewShutdownInstructionBuilder() *Shutdown { + nd := &Shutdown{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 2), + } + return nd +} + +// SetOwnerAccount sets the "owner" account. +func (inst *Shutdown) SetOwnerAccount(owner ag_solanago.PublicKey) *Shutdown { + inst.AccountMetaSlice[0] = ag_solanago.Meta(owner).WRITE() + return inst +} + +// GetOwnerAccount gets the "owner" account. +func (inst *Shutdown) GetOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetPoolAccount sets the "pool" account. +func (inst *Shutdown) SetPoolAccount(pool ag_solanago.PublicKey) *Shutdown { + inst.AccountMetaSlice[1] = ag_solanago.Meta(pool).WRITE() + return inst +} + +// GetPoolAccount gets the "pool" account. +func (inst *Shutdown) GetPoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +func (inst Shutdown) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_Shutdown, + }} +} + +// 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 Shutdown) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *Shutdown) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Owner is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Pool is not set") + } + } + return nil +} + +func (inst *Shutdown) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("Shutdown")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=2]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta("owner", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" pool", inst.AccountMetaSlice.Get(1))) + }) + }) + }) +} + +func (obj Shutdown) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *Shutdown) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewShutdownInstruction declares a new Shutdown instruction with the provided parameters and accounts. +func NewShutdownInstruction( + // Accounts: + owner ag_solanago.PublicKey, + pool ag_solanago.PublicKey) *Shutdown { + return NewShutdownInstructionBuilder(). + SetOwnerAccount(owner). + SetPoolAccount(pool) +} diff --git a/programs/stabblestableswap/shutdown_test.go b/programs/stabblestableswap/shutdown_test.go new file mode 100644 index 00000000..37d8c991 --- /dev/null +++ b/programs/stabblestableswap/shutdown_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package stable_swap + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_Shutdown(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("Shutdown"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(Shutdown) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(Shutdown) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/stabblestableswap/swap.go b/programs/stabblestableswap/swap.go new file mode 100644 index 00000000..99b24c1c --- /dev/null +++ b/programs/stabblestableswap/swap.go @@ -0,0 +1,377 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package stable_swap + +import ( + "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" +) + +// swap +type Swap struct { + AmountIn *uint64 `bin:"optional"` + MinimumAmountOut *uint64 + + // [0] = [SIGNER] user + // + // [1] = [WRITE] user_token_in + // + // [2] = [WRITE] user_token_out + // + // [3] = [WRITE] vault_token_in + // + // [4] = [WRITE] vault_token_out + // + // [5] = [WRITE] beneficiary_token_out + // + // [6] = [WRITE] pool + // + // [7] = [] withdraw_authority + // + // [8] = [] vault + // + // [9] = [] vault_authority + // + // [10] = [] vault_program + // + // [11] = [] token_program + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewSwapInstructionBuilder creates a new `Swap` instruction builder. +func NewSwapInstructionBuilder() *Swap { + nd := &Swap{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 12), + } + return nd +} + +// SetAmountIn sets the "amount_in" parameter. +func (inst *Swap) SetAmountIn(amount_in uint64) *Swap { + inst.AmountIn = &amount_in + return inst +} + +// SetMinimumAmountOut sets the "minimum_amount_out" parameter. +func (inst *Swap) SetMinimumAmountOut(minimum_amount_out uint64) *Swap { + inst.MinimumAmountOut = &minimum_amount_out + return inst +} + +// SetUserAccount sets the "user" account. +func (inst *Swap) SetUserAccount(user ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[0] = ag_solanago.Meta(user).SIGNER() + return inst +} + +// GetUserAccount gets the "user" account. +func (inst *Swap) GetUserAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetUserTokenInAccount sets the "user_token_in" account. +func (inst *Swap) SetUserTokenInAccount(userTokenIn ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[1] = ag_solanago.Meta(userTokenIn).WRITE() + return inst +} + +// GetUserTokenInAccount gets the "user_token_in" account. +func (inst *Swap) GetUserTokenInAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetUserTokenOutAccount sets the "user_token_out" account. +func (inst *Swap) SetUserTokenOutAccount(userTokenOut ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[2] = ag_solanago.Meta(userTokenOut).WRITE() + return inst +} + +// GetUserTokenOutAccount gets the "user_token_out" account. +func (inst *Swap) GetUserTokenOutAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetVaultTokenInAccount sets the "vault_token_in" account. +func (inst *Swap) SetVaultTokenInAccount(vaultTokenIn ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[3] = ag_solanago.Meta(vaultTokenIn).WRITE() + return inst +} + +// GetVaultTokenInAccount gets the "vault_token_in" account. +func (inst *Swap) GetVaultTokenInAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetVaultTokenOutAccount sets the "vault_token_out" account. +func (inst *Swap) SetVaultTokenOutAccount(vaultTokenOut ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[4] = ag_solanago.Meta(vaultTokenOut).WRITE() + return inst +} + +// GetVaultTokenOutAccount gets the "vault_token_out" account. +func (inst *Swap) GetVaultTokenOutAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetBeneficiaryTokenOutAccount sets the "beneficiary_token_out" account. +func (inst *Swap) SetBeneficiaryTokenOutAccount(beneficiaryTokenOut ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[5] = ag_solanago.Meta(beneficiaryTokenOut).WRITE() + return inst +} + +// GetBeneficiaryTokenOutAccount gets the "beneficiary_token_out" account. +func (inst *Swap) GetBeneficiaryTokenOutAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetPoolAccount sets the "pool" account. +func (inst *Swap) SetPoolAccount(pool ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[6] = ag_solanago.Meta(pool).WRITE() + return inst +} + +// GetPoolAccount gets the "pool" account. +func (inst *Swap) GetPoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetWithdrawAuthorityAccount sets the "withdraw_authority" account. +func (inst *Swap) SetWithdrawAuthorityAccount(withdrawAuthority ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[7] = ag_solanago.Meta(withdrawAuthority) + return inst +} + +// GetWithdrawAuthorityAccount gets the "withdraw_authority" account. +func (inst *Swap) GetWithdrawAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetVaultAccount sets the "vault" account. +func (inst *Swap) SetVaultAccount(vault ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[8] = ag_solanago.Meta(vault) + return inst +} + +// GetVaultAccount gets the "vault" account. +func (inst *Swap) GetVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetVaultAuthorityAccount sets the "vault_authority" account. +func (inst *Swap) SetVaultAuthorityAccount(vaultAuthority ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[9] = ag_solanago.Meta(vaultAuthority) + return inst +} + +// GetVaultAuthorityAccount gets the "vault_authority" account. +func (inst *Swap) GetVaultAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetVaultProgramAccount sets the "vault_program" account. +func (inst *Swap) SetVaultProgramAccount(vaultProgram ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[10] = ag_solanago.Meta(vaultProgram) + return inst +} + +// GetVaultProgramAccount gets the "vault_program" account. +func (inst *Swap) GetVaultProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetTokenProgramAccount sets the "token_program" account. +func (inst *Swap) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[11] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "token_program" account. +func (inst *Swap) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +func (inst Swap) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_Swap, + }} +} + +// 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 Swap) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *Swap) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.MinimumAmountOut == nil { + return errors.New("MinimumAmountOut parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.User is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.UserTokenIn is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.UserTokenOut is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.VaultTokenIn is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.VaultTokenOut is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.BeneficiaryTokenOut is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.Pool is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.WithdrawAuthority is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.Vault is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.VaultAuthority is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.VaultProgram is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.TokenProgram is not set") + } + } + return nil +} + +func (inst *Swap) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("Swap")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=2]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" AmountIn (OPT)", inst.AmountIn)) + paramsBranch.Child(ag_format.Param(" MinimumAmountOut", *inst.MinimumAmountOut)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=12]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" user", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" user_token_in", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" user_token_out", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" vault_token_in", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" vault_token_out", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta("beneficiary_token_out", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" pool", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" withdraw_authority", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" vault", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" vault_authority", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" vault_program", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" token_program", inst.AccountMetaSlice.Get(11))) + }) + }) + }) +} + +func (obj Swap) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `AmountIn` param (optional): + { + if obj.AmountIn == nil { + err = encoder.WriteBool(false) + if err != nil { + return err + } + } else { + err = encoder.WriteBool(true) + if err != nil { + return err + } + err = encoder.Encode(obj.AmountIn) + if err != nil { + return err + } + } + } + // Serialize `MinimumAmountOut` param: + err = encoder.Encode(obj.MinimumAmountOut) + if err != nil { + return err + } + return nil +} +func (obj *Swap) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `AmountIn` (optional): + { + ok, err := decoder.ReadBool() + if err != nil { + return err + } + if ok { + err = decoder.Decode(&obj.AmountIn) + if err != nil { + return err + } + } + } + // Deserialize `MinimumAmountOut`: + err = decoder.Decode(&obj.MinimumAmountOut) + if err != nil { + return err + } + return nil +} + +// NewSwapInstruction declares a new Swap instruction with the provided parameters and accounts. +func NewSwapInstruction( + // Parameters: + amount_in uint64, + minimum_amount_out uint64, + // Accounts: + user ag_solanago.PublicKey, + userTokenIn ag_solanago.PublicKey, + userTokenOut ag_solanago.PublicKey, + vaultTokenIn ag_solanago.PublicKey, + vaultTokenOut ag_solanago.PublicKey, + beneficiaryTokenOut ag_solanago.PublicKey, + pool ag_solanago.PublicKey, + withdrawAuthority ag_solanago.PublicKey, + vault ag_solanago.PublicKey, + vaultAuthority ag_solanago.PublicKey, + vaultProgram ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey) *Swap { + return NewSwapInstructionBuilder(). + SetAmountIn(amount_in). + SetMinimumAmountOut(minimum_amount_out). + SetUserAccount(user). + SetUserTokenInAccount(userTokenIn). + SetUserTokenOutAccount(userTokenOut). + SetVaultTokenInAccount(vaultTokenIn). + SetVaultTokenOutAccount(vaultTokenOut). + SetBeneficiaryTokenOutAccount(beneficiaryTokenOut). + SetPoolAccount(pool). + SetWithdrawAuthorityAccount(withdrawAuthority). + SetVaultAccount(vault). + SetVaultAuthorityAccount(vaultAuthority). + SetVaultProgramAccount(vaultProgram). + SetTokenProgramAccount(tokenProgram) +} diff --git a/programs/stabblestableswap/swap_test.go b/programs/stabblestableswap/swap_test.go new file mode 100644 index 00000000..863a11f4 --- /dev/null +++ b/programs/stabblestableswap/swap_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package stable_swap + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_Swap(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("Swap"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(Swap) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(Swap) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/stabblestableswap/swapv2.go b/programs/stabblestableswap/swapv2.go new file mode 100644 index 00000000..7d1d8bc6 --- /dev/null +++ b/programs/stabblestableswap/swapv2.go @@ -0,0 +1,434 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package stable_swap + +import ( + "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" +) + +// SwapV2 is the `swap_v2` instruction. +type SwapV2 struct { + AmountIn *uint64 `bin:"optional"` + MinimumAmountOut *uint64 + + // [0] = [SIGNER] user + // + // [1] = [] mint_in + // + // [2] = [] mint_out + // + // [3] = [WRITE] user_token_in + // + // [4] = [WRITE] user_token_out + // + // [5] = [WRITE] vault_token_in + // + // [6] = [WRITE] vault_token_out + // + // [7] = [WRITE] beneficiary_token_out + // + // [8] = [WRITE] pool + // + // [9] = [] withdraw_authority + // + // [10] = [] vault + // + // [11] = [] vault_authority + // + // [12] = [] vault_program + // + // [13] = [] token_program + // + // [14] = [] token_2022_program + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewSwapV2InstructionBuilder creates a new `SwapV2` instruction builder. +func NewSwapV2InstructionBuilder() *SwapV2 { + nd := &SwapV2{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 15), + } + return nd +} + +// SetAmountIn sets the "amount_in" parameter. +func (inst *SwapV2) SetAmountIn(amount_in uint64) *SwapV2 { + inst.AmountIn = &amount_in + return inst +} + +// SetMinimumAmountOut sets the "minimum_amount_out" parameter. +func (inst *SwapV2) SetMinimumAmountOut(minimum_amount_out uint64) *SwapV2 { + inst.MinimumAmountOut = &minimum_amount_out + return inst +} + +// SetUserAccount sets the "user" account. +func (inst *SwapV2) SetUserAccount(user ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[0] = ag_solanago.Meta(user).SIGNER() + return inst +} + +// GetUserAccount gets the "user" account. +func (inst *SwapV2) GetUserAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetMintInAccount sets the "mint_in" account. +func (inst *SwapV2) SetMintInAccount(mintIn ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[1] = ag_solanago.Meta(mintIn) + return inst +} + +// GetMintInAccount gets the "mint_in" account. +func (inst *SwapV2) GetMintInAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetMintOutAccount sets the "mint_out" account. +func (inst *SwapV2) SetMintOutAccount(mintOut ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[2] = ag_solanago.Meta(mintOut) + return inst +} + +// GetMintOutAccount gets the "mint_out" account. +func (inst *SwapV2) GetMintOutAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetUserTokenInAccount sets the "user_token_in" account. +func (inst *SwapV2) SetUserTokenInAccount(userTokenIn ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[3] = ag_solanago.Meta(userTokenIn).WRITE() + return inst +} + +// GetUserTokenInAccount gets the "user_token_in" account. +func (inst *SwapV2) GetUserTokenInAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetUserTokenOutAccount sets the "user_token_out" account. +func (inst *SwapV2) SetUserTokenOutAccount(userTokenOut ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[4] = ag_solanago.Meta(userTokenOut).WRITE() + return inst +} + +// GetUserTokenOutAccount gets the "user_token_out" account. +func (inst *SwapV2) GetUserTokenOutAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetVaultTokenInAccount sets the "vault_token_in" account. +func (inst *SwapV2) SetVaultTokenInAccount(vaultTokenIn ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[5] = ag_solanago.Meta(vaultTokenIn).WRITE() + return inst +} + +// GetVaultTokenInAccount gets the "vault_token_in" account. +func (inst *SwapV2) GetVaultTokenInAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetVaultTokenOutAccount sets the "vault_token_out" account. +func (inst *SwapV2) SetVaultTokenOutAccount(vaultTokenOut ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[6] = ag_solanago.Meta(vaultTokenOut).WRITE() + return inst +} + +// GetVaultTokenOutAccount gets the "vault_token_out" account. +func (inst *SwapV2) GetVaultTokenOutAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetBeneficiaryTokenOutAccount sets the "beneficiary_token_out" account. +func (inst *SwapV2) SetBeneficiaryTokenOutAccount(beneficiaryTokenOut ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[7] = ag_solanago.Meta(beneficiaryTokenOut).WRITE() + return inst +} + +// GetBeneficiaryTokenOutAccount gets the "beneficiary_token_out" account. +func (inst *SwapV2) GetBeneficiaryTokenOutAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetPoolAccount sets the "pool" account. +func (inst *SwapV2) SetPoolAccount(pool ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[8] = ag_solanago.Meta(pool).WRITE() + return inst +} + +// GetPoolAccount gets the "pool" account. +func (inst *SwapV2) GetPoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetWithdrawAuthorityAccount sets the "withdraw_authority" account. +func (inst *SwapV2) SetWithdrawAuthorityAccount(withdrawAuthority ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[9] = ag_solanago.Meta(withdrawAuthority) + return inst +} + +// GetWithdrawAuthorityAccount gets the "withdraw_authority" account. +func (inst *SwapV2) GetWithdrawAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetVaultAccount sets the "vault" account. +func (inst *SwapV2) SetVaultAccount(vault ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[10] = ag_solanago.Meta(vault) + return inst +} + +// GetVaultAccount gets the "vault" account. +func (inst *SwapV2) GetVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetVaultAuthorityAccount sets the "vault_authority" account. +func (inst *SwapV2) SetVaultAuthorityAccount(vaultAuthority ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[11] = ag_solanago.Meta(vaultAuthority) + return inst +} + +// GetVaultAuthorityAccount gets the "vault_authority" account. +func (inst *SwapV2) GetVaultAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetVaultProgramAccount sets the "vault_program" account. +func (inst *SwapV2) SetVaultProgramAccount(vaultProgram ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[12] = ag_solanago.Meta(vaultProgram) + return inst +} + +// GetVaultProgramAccount gets the "vault_program" account. +func (inst *SwapV2) GetVaultProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetTokenProgramAccount sets the "token_program" account. +func (inst *SwapV2) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[13] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "token_program" account. +func (inst *SwapV2) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetToken2022ProgramAccount sets the "token_2022_program" account. +func (inst *SwapV2) SetToken2022ProgramAccount(token2022Program ag_solanago.PublicKey) *SwapV2 { + inst.AccountMetaSlice[14] = ag_solanago.Meta(token2022Program) + return inst +} + +// GetToken2022ProgramAccount gets the "token_2022_program" account. +func (inst *SwapV2) GetToken2022ProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +func (inst SwapV2) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_SwapV2, + }} +} + +// 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 SwapV2) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *SwapV2) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.MinimumAmountOut == nil { + return errors.New("MinimumAmountOut parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.User is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.MintIn is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.MintOut is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.UserTokenIn is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.UserTokenOut is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.VaultTokenIn is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.VaultTokenOut is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.BeneficiaryTokenOut is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.Pool is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.WithdrawAuthority is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.Vault is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.VaultAuthority is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.VaultProgram is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.Token2022Program is not set") + } + } + return nil +} + +func (inst *SwapV2) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("SwapV2")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=2]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" AmountIn (OPT)", inst.AmountIn)) + paramsBranch.Child(ag_format.Param(" MinimumAmountOut", *inst.MinimumAmountOut)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=15]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" user", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" mint_in", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" mint_out", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" user_token_in", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" user_token_out", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" vault_token_in", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" vault_token_out", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta("beneficiary_token_out", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" pool", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" withdraw_authority", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" vault", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" vault_authority", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" vault_program", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" token_program", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta(" token_2022_program", inst.AccountMetaSlice.Get(14))) + }) + }) + }) +} + +func (obj SwapV2) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `AmountIn` param (optional): + { + if obj.AmountIn == nil { + err = encoder.WriteBool(false) + if err != nil { + return err + } + } else { + err = encoder.WriteBool(true) + if err != nil { + return err + } + err = encoder.Encode(obj.AmountIn) + if err != nil { + return err + } + } + } + // Serialize `MinimumAmountOut` param: + err = encoder.Encode(obj.MinimumAmountOut) + if err != nil { + return err + } + return nil +} +func (obj *SwapV2) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `AmountIn` (optional): + { + ok, err := decoder.ReadBool() + if err != nil { + return err + } + if ok { + err = decoder.Decode(&obj.AmountIn) + if err != nil { + return err + } + } + } + // Deserialize `MinimumAmountOut`: + err = decoder.Decode(&obj.MinimumAmountOut) + if err != nil { + return err + } + return nil +} + +// NewSwapV2Instruction declares a new SwapV2 instruction with the provided parameters and accounts. +func NewSwapV2Instruction( + // Parameters: + amount_in uint64, + minimum_amount_out uint64, + // Accounts: + user ag_solanago.PublicKey, + mintIn ag_solanago.PublicKey, + mintOut ag_solanago.PublicKey, + userTokenIn ag_solanago.PublicKey, + userTokenOut ag_solanago.PublicKey, + vaultTokenIn ag_solanago.PublicKey, + vaultTokenOut ag_solanago.PublicKey, + beneficiaryTokenOut ag_solanago.PublicKey, + pool ag_solanago.PublicKey, + withdrawAuthority ag_solanago.PublicKey, + vault ag_solanago.PublicKey, + vaultAuthority ag_solanago.PublicKey, + vaultProgram ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + token2022Program ag_solanago.PublicKey) *SwapV2 { + return NewSwapV2InstructionBuilder(). + SetAmountIn(amount_in). + SetMinimumAmountOut(minimum_amount_out). + SetUserAccount(user). + SetMintInAccount(mintIn). + SetMintOutAccount(mintOut). + SetUserTokenInAccount(userTokenIn). + SetUserTokenOutAccount(userTokenOut). + SetVaultTokenInAccount(vaultTokenIn). + SetVaultTokenOutAccount(vaultTokenOut). + SetBeneficiaryTokenOutAccount(beneficiaryTokenOut). + SetPoolAccount(pool). + SetWithdrawAuthorityAccount(withdrawAuthority). + SetVaultAccount(vault). + SetVaultAuthorityAccount(vaultAuthority). + SetVaultProgramAccount(vaultProgram). + SetTokenProgramAccount(tokenProgram). + SetToken2022ProgramAccount(token2022Program) +} diff --git a/programs/stabblestableswap/swapv2_test.go b/programs/stabblestableswap/swapv2_test.go new file mode 100644 index 00000000..8c351221 --- /dev/null +++ b/programs/stabblestableswap/swapv2_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package stable_swap + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_SwapV2(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("SwapV2"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(SwapV2) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(SwapV2) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/stabblestableswap/testing_utils.go b/programs/stabblestableswap/testing_utils.go new file mode 100644 index 00000000..6329f055 --- /dev/null +++ b/programs/stabblestableswap/testing_utils.go @@ -0,0 +1,20 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package stable_swap + +import ( + "bytes" + "fmt" + ag_binary "github.com/gagliardetto/binary" +) + +func encodeT(data interface{}, buf *bytes.Buffer) error { + if err := ag_binary.NewBorshEncoder(buf).Encode(data); err != nil { + return fmt.Errorf("unable to encode instruction: %w", err) + } + return nil +} + +func decodeT(dst interface{}, data []byte) error { + return ag_binary.NewBorshDecoder(data).Decode(dst) +} diff --git a/programs/stabblestableswap/transferowner.go b/programs/stabblestableswap/transferowner.go new file mode 100644 index 00000000..432617ab --- /dev/null +++ b/programs/stabblestableswap/transferowner.go @@ -0,0 +1,146 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package stable_swap + +import ( + "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" +) + +// TransferOwner is the `transfer_owner` instruction. +type TransferOwner struct { + NewOwner *ag_solanago.PublicKey + + // [0] = [SIGNER] owner + // + // [1] = [WRITE] pool + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewTransferOwnerInstructionBuilder creates a new `TransferOwner` instruction builder. +func NewTransferOwnerInstructionBuilder() *TransferOwner { + nd := &TransferOwner{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 2), + } + return nd +} + +// SetNewOwner sets the "new_owner" parameter. +func (inst *TransferOwner) SetNewOwner(new_owner ag_solanago.PublicKey) *TransferOwner { + inst.NewOwner = &new_owner + return inst +} + +// SetOwnerAccount sets the "owner" account. +func (inst *TransferOwner) SetOwnerAccount(owner ag_solanago.PublicKey) *TransferOwner { + inst.AccountMetaSlice[0] = ag_solanago.Meta(owner).SIGNER() + return inst +} + +// GetOwnerAccount gets the "owner" account. +func (inst *TransferOwner) GetOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetPoolAccount sets the "pool" account. +func (inst *TransferOwner) SetPoolAccount(pool ag_solanago.PublicKey) *TransferOwner { + inst.AccountMetaSlice[1] = ag_solanago.Meta(pool).WRITE() + return inst +} + +// GetPoolAccount gets the "pool" account. +func (inst *TransferOwner) GetPoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +func (inst TransferOwner) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_TransferOwner, + }} +} + +// 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 TransferOwner) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *TransferOwner) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.NewOwner == nil { + return errors.New("NewOwner parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Owner is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Pool is not set") + } + } + return nil +} + +func (inst *TransferOwner) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("TransferOwner")). + // + 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(" NewOwner", *inst.NewOwner)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=2]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta("owner", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" pool", inst.AccountMetaSlice.Get(1))) + }) + }) + }) +} + +func (obj TransferOwner) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `NewOwner` param: + err = encoder.Encode(obj.NewOwner) + if err != nil { + return err + } + return nil +} +func (obj *TransferOwner) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `NewOwner`: + err = decoder.Decode(&obj.NewOwner) + if err != nil { + return err + } + return nil +} + +// NewTransferOwnerInstruction declares a new TransferOwner instruction with the provided parameters and accounts. +func NewTransferOwnerInstruction( + // Parameters: + new_owner ag_solanago.PublicKey, + // Accounts: + owner ag_solanago.PublicKey, + pool ag_solanago.PublicKey) *TransferOwner { + return NewTransferOwnerInstructionBuilder(). + SetNewOwner(new_owner). + SetOwnerAccount(owner). + SetPoolAccount(pool) +} diff --git a/programs/stabblestableswap/transferowner_test.go b/programs/stabblestableswap/transferowner_test.go new file mode 100644 index 00000000..bacd3cd0 --- /dev/null +++ b/programs/stabblestableswap/transferowner_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package stable_swap + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_TransferOwner(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("TransferOwner"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(TransferOwner) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(TransferOwner) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/stabblestableswap/types.go b/programs/stabblestableswap/types.go new file mode 100644 index 00000000..f4a36665 --- /dev/null +++ b/programs/stabblestableswap/types.go @@ -0,0 +1,628 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package stable_swap + +import ( + ag_binary "github.com/gagliardetto/binary" + ag_solanago "github.com/gagliardetto/solana-go" +) + +type Pool struct { + Owner ag_solanago.PublicKey + Vault ag_solanago.PublicKey + Mint ag_solanago.PublicKey + AuthorityBump uint8 + IsActive bool + AmpInitialFactor uint16 + AmpTargetFactor uint16 + RampStartTs int64 + RampStopTs int64 + SwapFee uint64 + Tokens []PoolToken + PendingOwner *ag_solanago.PublicKey `bin:"optional"` +} + +func (obj Pool) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Owner` param: + err = encoder.Encode(obj.Owner) + if err != nil { + return err + } + // Serialize `Vault` param: + err = encoder.Encode(obj.Vault) + if err != nil { + return err + } + // Serialize `Mint` param: + err = encoder.Encode(obj.Mint) + if err != nil { + return err + } + // Serialize `AuthorityBump` param: + err = encoder.Encode(obj.AuthorityBump) + if err != nil { + return err + } + // Serialize `IsActive` param: + err = encoder.Encode(obj.IsActive) + if err != nil { + return err + } + // Serialize `AmpInitialFactor` param: + err = encoder.Encode(obj.AmpInitialFactor) + if err != nil { + return err + } + // Serialize `AmpTargetFactor` param: + err = encoder.Encode(obj.AmpTargetFactor) + if err != nil { + return err + } + // Serialize `RampStartTs` param: + err = encoder.Encode(obj.RampStartTs) + if err != nil { + return err + } + // Serialize `RampStopTs` param: + err = encoder.Encode(obj.RampStopTs) + if err != nil { + return err + } + // Serialize `SwapFee` param: + err = encoder.Encode(obj.SwapFee) + if err != nil { + return err + } + // Serialize `Tokens` param: + err = encoder.Encode(obj.Tokens) + if err != nil { + return err + } + // Serialize `PendingOwner` param (optional): + { + if obj.PendingOwner == nil { + err = encoder.WriteBool(false) + if err != nil { + return err + } + } else { + err = encoder.WriteBool(true) + if err != nil { + return err + } + err = encoder.Encode(obj.PendingOwner) + if err != nil { + return err + } + } + } + return nil +} + +func (obj *Pool) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Owner`: + err = decoder.Decode(&obj.Owner) + if err != nil { + return err + } + // Deserialize `Vault`: + err = decoder.Decode(&obj.Vault) + if err != nil { + return err + } + // Deserialize `Mint`: + err = decoder.Decode(&obj.Mint) + if err != nil { + return err + } + // Deserialize `AuthorityBump`: + err = decoder.Decode(&obj.AuthorityBump) + if err != nil { + return err + } + // Deserialize `IsActive`: + err = decoder.Decode(&obj.IsActive) + if err != nil { + return err + } + // Deserialize `AmpInitialFactor`: + err = decoder.Decode(&obj.AmpInitialFactor) + if err != nil { + return err + } + // Deserialize `AmpTargetFactor`: + err = decoder.Decode(&obj.AmpTargetFactor) + if err != nil { + return err + } + // Deserialize `RampStartTs`: + err = decoder.Decode(&obj.RampStartTs) + if err != nil { + return err + } + // Deserialize `RampStopTs`: + err = decoder.Decode(&obj.RampStopTs) + if err != nil { + return err + } + // Deserialize `SwapFee`: + err = decoder.Decode(&obj.SwapFee) + if err != nil { + return err + } + // Deserialize `Tokens`: + err = decoder.Decode(&obj.Tokens) + if err != nil { + return err + } + // Deserialize `PendingOwner` (optional): + { + ok, err := decoder.ReadBool() + if err != nil { + return err + } + if ok { + err = decoder.Decode(&obj.PendingOwner) + if err != nil { + return err + } + } + } + return nil +} + +type PoolBalanceUpdatedData struct { + Balances []uint64 +} + +func (obj PoolBalanceUpdatedData) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Balances` param: + err = encoder.Encode(obj.Balances) + if err != nil { + return err + } + return nil +} + +func (obj *PoolBalanceUpdatedData) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Balances`: + err = decoder.Decode(&obj.Balances) + if err != nil { + return err + } + return nil +} + +type PoolBalanceUpdatedEvent struct { + Pubkey ag_solanago.PublicKey + Data PoolBalanceUpdatedData +} + +func (obj PoolBalanceUpdatedEvent) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Pubkey` param: + err = encoder.Encode(obj.Pubkey) + if err != nil { + return err + } + // Serialize `Data` param: + err = encoder.Encode(obj.Data) + if err != nil { + return err + } + return nil +} + +func (obj *PoolBalanceUpdatedEvent) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Pubkey`: + err = decoder.Decode(&obj.Pubkey) + if err != nil { + return err + } + // Deserialize `Data`: + err = decoder.Decode(&obj.Data) + if err != nil { + return err + } + return nil +} + +type PoolToken struct { + Mint ag_solanago.PublicKey + Decimals uint8 + ScalingUp bool + ScalingFactor uint64 + Balance uint64 +} + +func (obj PoolToken) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Mint` param: + err = encoder.Encode(obj.Mint) + if err != nil { + return err + } + // Serialize `Decimals` param: + err = encoder.Encode(obj.Decimals) + if err != nil { + return err + } + // Serialize `ScalingUp` param: + err = encoder.Encode(obj.ScalingUp) + if err != nil { + return err + } + // Serialize `ScalingFactor` param: + err = encoder.Encode(obj.ScalingFactor) + if err != nil { + return err + } + // Serialize `Balance` param: + err = encoder.Encode(obj.Balance) + if err != nil { + return err + } + return nil +} + +func (obj *PoolToken) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Mint`: + err = decoder.Decode(&obj.Mint) + if err != nil { + return err + } + // Deserialize `Decimals`: + err = decoder.Decode(&obj.Decimals) + if err != nil { + return err + } + // Deserialize `ScalingUp`: + err = decoder.Decode(&obj.ScalingUp) + if err != nil { + return err + } + // Deserialize `ScalingFactor`: + err = decoder.Decode(&obj.ScalingFactor) + if err != nil { + return err + } + // Deserialize `Balance`: + err = decoder.Decode(&obj.Balance) + if err != nil { + return err + } + return nil +} + +type PoolUpdatedData struct { + IsActive bool + AmpInitialFactor uint16 + AmpTargetFactor uint16 + RampStartTs int64 + RampStopTs int64 + SwapFee uint64 +} + +func (obj PoolUpdatedData) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `IsActive` param: + err = encoder.Encode(obj.IsActive) + if err != nil { + return err + } + // Serialize `AmpInitialFactor` param: + err = encoder.Encode(obj.AmpInitialFactor) + if err != nil { + return err + } + // Serialize `AmpTargetFactor` param: + err = encoder.Encode(obj.AmpTargetFactor) + if err != nil { + return err + } + // Serialize `RampStartTs` param: + err = encoder.Encode(obj.RampStartTs) + if err != nil { + return err + } + // Serialize `RampStopTs` param: + err = encoder.Encode(obj.RampStopTs) + if err != nil { + return err + } + // Serialize `SwapFee` param: + err = encoder.Encode(obj.SwapFee) + if err != nil { + return err + } + return nil +} + +func (obj *PoolUpdatedData) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `IsActive`: + err = decoder.Decode(&obj.IsActive) + if err != nil { + return err + } + // Deserialize `AmpInitialFactor`: + err = decoder.Decode(&obj.AmpInitialFactor) + if err != nil { + return err + } + // Deserialize `AmpTargetFactor`: + err = decoder.Decode(&obj.AmpTargetFactor) + if err != nil { + return err + } + // Deserialize `RampStartTs`: + err = decoder.Decode(&obj.RampStartTs) + if err != nil { + return err + } + // Deserialize `RampStopTs`: + err = decoder.Decode(&obj.RampStopTs) + if err != nil { + return err + } + // Deserialize `SwapFee`: + err = decoder.Decode(&obj.SwapFee) + if err != nil { + return err + } + return nil +} + +type PoolUpdatedEvent struct { + Pubkey ag_solanago.PublicKey + Data PoolUpdatedData +} + +func (obj PoolUpdatedEvent) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Pubkey` param: + err = encoder.Encode(obj.Pubkey) + if err != nil { + return err + } + // Serialize `Data` param: + err = encoder.Encode(obj.Data) + if err != nil { + return err + } + return nil +} + +func (obj *PoolUpdatedEvent) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Pubkey`: + err = decoder.Decode(&obj.Pubkey) + if err != nil { + return err + } + // Deserialize `Data`: + err = decoder.Decode(&obj.Data) + if err != nil { + return err + } + return nil +} + +type Strategy struct { + Pool ag_solanago.PublicKey + IsActive bool + AmpMinFactor uint16 + AmpMaxFactor uint16 + RampMinStep uint16 + RampMaxStep uint16 + RampMinDuration uint32 + RampMaxDuration uint32 +} + +func (obj Strategy) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Pool` param: + err = encoder.Encode(obj.Pool) + if err != nil { + return err + } + // Serialize `IsActive` param: + err = encoder.Encode(obj.IsActive) + if err != nil { + return err + } + // Serialize `AmpMinFactor` param: + err = encoder.Encode(obj.AmpMinFactor) + if err != nil { + return err + } + // Serialize `AmpMaxFactor` param: + err = encoder.Encode(obj.AmpMaxFactor) + if err != nil { + return err + } + // Serialize `RampMinStep` param: + err = encoder.Encode(obj.RampMinStep) + if err != nil { + return err + } + // Serialize `RampMaxStep` param: + err = encoder.Encode(obj.RampMaxStep) + if err != nil { + return err + } + // Serialize `RampMinDuration` param: + err = encoder.Encode(obj.RampMinDuration) + if err != nil { + return err + } + // Serialize `RampMaxDuration` param: + err = encoder.Encode(obj.RampMaxDuration) + if err != nil { + return err + } + return nil +} + +func (obj *Strategy) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Pool`: + err = decoder.Decode(&obj.Pool) + if err != nil { + return err + } + // Deserialize `IsActive`: + err = decoder.Decode(&obj.IsActive) + if err != nil { + return err + } + // Deserialize `AmpMinFactor`: + err = decoder.Decode(&obj.AmpMinFactor) + if err != nil { + return err + } + // Deserialize `AmpMaxFactor`: + err = decoder.Decode(&obj.AmpMaxFactor) + if err != nil { + return err + } + // Deserialize `RampMinStep`: + err = decoder.Decode(&obj.RampMinStep) + if err != nil { + return err + } + // Deserialize `RampMaxStep`: + err = decoder.Decode(&obj.RampMaxStep) + if err != nil { + return err + } + // Deserialize `RampMinDuration`: + err = decoder.Decode(&obj.RampMinDuration) + if err != nil { + return err + } + // Deserialize `RampMaxDuration`: + err = decoder.Decode(&obj.RampMaxDuration) + if err != nil { + return err + } + return nil +} + +type Vault struct { + Admin ag_solanago.PublicKey + + // PDA of pool programs seeded by vault address + WithdrawAuthority ag_solanago.PublicKey + + // bump seed of withdraw_authority PDA + WithdrawAuthorityBump uint8 + + // bump seed of vault_authority PDA + AuthorityBump uint8 + IsActive bool + Beneficiary ag_solanago.PublicKey + BeneficiaryFee uint64 + PendingAdmin *ag_solanago.PublicKey `bin:"optional"` +} + +func (obj Vault) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Admin` param: + err = encoder.Encode(obj.Admin) + if err != nil { + return err + } + // Serialize `WithdrawAuthority` param: + err = encoder.Encode(obj.WithdrawAuthority) + if err != nil { + return err + } + // Serialize `WithdrawAuthorityBump` param: + err = encoder.Encode(obj.WithdrawAuthorityBump) + if err != nil { + return err + } + // Serialize `AuthorityBump` param: + err = encoder.Encode(obj.AuthorityBump) + if err != nil { + return err + } + // Serialize `IsActive` param: + err = encoder.Encode(obj.IsActive) + if err != nil { + return err + } + // Serialize `Beneficiary` param: + err = encoder.Encode(obj.Beneficiary) + if err != nil { + return err + } + // Serialize `BeneficiaryFee` param: + err = encoder.Encode(obj.BeneficiaryFee) + if err != nil { + return err + } + // Serialize `PendingAdmin` param (optional): + { + if obj.PendingAdmin == nil { + err = encoder.WriteBool(false) + if err != nil { + return err + } + } else { + err = encoder.WriteBool(true) + if err != nil { + return err + } + err = encoder.Encode(obj.PendingAdmin) + if err != nil { + return err + } + } + } + return nil +} + +func (obj *Vault) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Admin`: + err = decoder.Decode(&obj.Admin) + if err != nil { + return err + } + // Deserialize `WithdrawAuthority`: + err = decoder.Decode(&obj.WithdrawAuthority) + if err != nil { + return err + } + // Deserialize `WithdrawAuthorityBump`: + err = decoder.Decode(&obj.WithdrawAuthorityBump) + if err != nil { + return err + } + // Deserialize `AuthorityBump`: + err = decoder.Decode(&obj.AuthorityBump) + if err != nil { + return err + } + // Deserialize `IsActive`: + err = decoder.Decode(&obj.IsActive) + if err != nil { + return err + } + // Deserialize `Beneficiary`: + err = decoder.Decode(&obj.Beneficiary) + if err != nil { + return err + } + // Deserialize `BeneficiaryFee`: + err = decoder.Decode(&obj.BeneficiaryFee) + if err != nil { + return err + } + // Deserialize `PendingAdmin` (optional): + { + ok, err := decoder.ReadBool() + if err != nil { + return err + } + if ok { + err = decoder.Decode(&obj.PendingAdmin) + if err != nil { + return err + } + } + } + return nil +} diff --git a/programs/stabblestableswap/unpause.go b/programs/stabblestableswap/unpause.go new file mode 100644 index 00000000..3b32da52 --- /dev/null +++ b/programs/stabblestableswap/unpause.go @@ -0,0 +1,117 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package stable_swap + +import ( + "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" +) + +// Unpause is the `unpause` instruction. +type Unpause struct { + + // [0] = [SIGNER] owner + // + // [1] = [WRITE] pool + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewUnpauseInstructionBuilder creates a new `Unpause` instruction builder. +func NewUnpauseInstructionBuilder() *Unpause { + nd := &Unpause{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 2), + } + return nd +} + +// SetOwnerAccount sets the "owner" account. +func (inst *Unpause) SetOwnerAccount(owner ag_solanago.PublicKey) *Unpause { + inst.AccountMetaSlice[0] = ag_solanago.Meta(owner).SIGNER() + return inst +} + +// GetOwnerAccount gets the "owner" account. +func (inst *Unpause) GetOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetPoolAccount sets the "pool" account. +func (inst *Unpause) SetPoolAccount(pool ag_solanago.PublicKey) *Unpause { + inst.AccountMetaSlice[1] = ag_solanago.Meta(pool).WRITE() + return inst +} + +// GetPoolAccount gets the "pool" account. +func (inst *Unpause) GetPoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +func (inst Unpause) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_Unpause, + }} +} + +// 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 Unpause) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *Unpause) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Owner is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Pool is not set") + } + } + return nil +} + +func (inst *Unpause) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("Unpause")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=2]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta("owner", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" pool", inst.AccountMetaSlice.Get(1))) + }) + }) + }) +} + +func (obj Unpause) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *Unpause) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewUnpauseInstruction declares a new Unpause instruction with the provided parameters and accounts. +func NewUnpauseInstruction( + // Accounts: + owner ag_solanago.PublicKey, + pool ag_solanago.PublicKey) *Unpause { + return NewUnpauseInstructionBuilder(). + SetOwnerAccount(owner). + SetPoolAccount(pool) +} diff --git a/programs/stabblestableswap/unpause_test.go b/programs/stabblestableswap/unpause_test.go new file mode 100644 index 00000000..7c8292a5 --- /dev/null +++ b/programs/stabblestableswap/unpause_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package stable_swap + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_Unpause(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("Unpause"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(Unpause) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(Unpause) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/stabblestableswap/withdraw.go b/programs/stabblestableswap/withdraw.go new file mode 100644 index 00000000..e9d15d8c --- /dev/null +++ b/programs/stabblestableswap/withdraw.go @@ -0,0 +1,321 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package stable_swap + +import ( + "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" +) + +// remove liquidity +type Withdraw struct { + Amount *uint64 + MinimumAmountsOut *[]uint64 + + // [0] = [SIGNER] user + // + // [1] = [WRITE] user_pool_token + // + // [2] = [WRITE] mint + // + // [3] = [WRITE] pool + // + // [4] = [] withdraw_authority + // + // [5] = [] vault + // + // [6] = [] vault_authority + // + // [7] = [] vault_program + // + // [8] = [] token_program + // + // [9] = [] token_program_2022 + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewWithdrawInstructionBuilder creates a new `Withdraw` instruction builder. +func NewWithdrawInstructionBuilder() *Withdraw { + nd := &Withdraw{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 10), + } + return nd +} + +// SetAmount sets the "amount" parameter. +func (inst *Withdraw) SetAmount(amount uint64) *Withdraw { + inst.Amount = &amount + return inst +} + +// SetMinimumAmountsOut sets the "minimum_amounts_out" parameter. +func (inst *Withdraw) SetMinimumAmountsOut(minimum_amounts_out []uint64) *Withdraw { + inst.MinimumAmountsOut = &minimum_amounts_out + return inst +} + +// SetUserAccount sets the "user" account. +func (inst *Withdraw) SetUserAccount(user ag_solanago.PublicKey) *Withdraw { + inst.AccountMetaSlice[0] = ag_solanago.Meta(user).SIGNER() + return inst +} + +// GetUserAccount gets the "user" account. +func (inst *Withdraw) GetUserAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetUserPoolTokenAccount sets the "user_pool_token" account. +func (inst *Withdraw) SetUserPoolTokenAccount(userPoolToken ag_solanago.PublicKey) *Withdraw { + inst.AccountMetaSlice[1] = ag_solanago.Meta(userPoolToken).WRITE() + return inst +} + +// GetUserPoolTokenAccount gets the "user_pool_token" account. +func (inst *Withdraw) GetUserPoolTokenAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetMintAccount sets the "mint" account. +func (inst *Withdraw) SetMintAccount(mint ag_solanago.PublicKey) *Withdraw { + inst.AccountMetaSlice[2] = ag_solanago.Meta(mint).WRITE() + return inst +} + +// GetMintAccount gets the "mint" account. +func (inst *Withdraw) GetMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetPoolAccount sets the "pool" account. +func (inst *Withdraw) SetPoolAccount(pool ag_solanago.PublicKey) *Withdraw { + inst.AccountMetaSlice[3] = ag_solanago.Meta(pool).WRITE() + return inst +} + +// GetPoolAccount gets the "pool" account. +func (inst *Withdraw) GetPoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetWithdrawAuthorityAccount sets the "withdraw_authority" account. +func (inst *Withdraw) SetWithdrawAuthorityAccount(withdrawAuthority ag_solanago.PublicKey) *Withdraw { + inst.AccountMetaSlice[4] = ag_solanago.Meta(withdrawAuthority) + return inst +} + +// GetWithdrawAuthorityAccount gets the "withdraw_authority" account. +func (inst *Withdraw) GetWithdrawAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetVaultAccount sets the "vault" account. +func (inst *Withdraw) SetVaultAccount(vault ag_solanago.PublicKey) *Withdraw { + inst.AccountMetaSlice[5] = ag_solanago.Meta(vault) + return inst +} + +// GetVaultAccount gets the "vault" account. +func (inst *Withdraw) GetVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetVaultAuthorityAccount sets the "vault_authority" account. +func (inst *Withdraw) SetVaultAuthorityAccount(vaultAuthority ag_solanago.PublicKey) *Withdraw { + inst.AccountMetaSlice[6] = ag_solanago.Meta(vaultAuthority) + return inst +} + +// GetVaultAuthorityAccount gets the "vault_authority" account. +func (inst *Withdraw) GetVaultAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetVaultProgramAccount sets the "vault_program" account. +func (inst *Withdraw) SetVaultProgramAccount(vaultProgram ag_solanago.PublicKey) *Withdraw { + inst.AccountMetaSlice[7] = ag_solanago.Meta(vaultProgram) + return inst +} + +// GetVaultProgramAccount gets the "vault_program" account. +func (inst *Withdraw) GetVaultProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetTokenProgramAccount sets the "token_program" account. +func (inst *Withdraw) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *Withdraw { + inst.AccountMetaSlice[8] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "token_program" account. +func (inst *Withdraw) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetTokenProgram2022Account sets the "token_program_2022" account. +func (inst *Withdraw) SetTokenProgram2022Account(tokenProgram2022 ag_solanago.PublicKey) *Withdraw { + inst.AccountMetaSlice[9] = ag_solanago.Meta(tokenProgram2022) + return inst +} + +// GetTokenProgram2022Account gets the "token_program_2022" account. +func (inst *Withdraw) GetTokenProgram2022Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +func (inst Withdraw) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_Withdraw, + }} +} + +// 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 Withdraw) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *Withdraw) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.Amount == nil { + return errors.New("Amount parameter is not set") + } + if inst.MinimumAmountsOut == nil { + return errors.New("MinimumAmountsOut parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.User is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.UserPoolToken is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.Mint is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.Pool is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.WithdrawAuthority is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.Vault is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.VaultAuthority is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.VaultProgram is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.TokenProgram2022 is not set") + } + } + return nil +} + +func (inst *Withdraw) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("Withdraw")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=2]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" Amount", *inst.Amount)) + paramsBranch.Child(ag_format.Param(" MinimumAmountsOut", *inst.MinimumAmountsOut)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=10]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" user", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" user_pool_token", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" mint", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" pool", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta("withdraw_authority", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" vault", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" vault_authority", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" vault_program", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" token_program", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta("token_program_2022", inst.AccountMetaSlice.Get(9))) + }) + }) + }) +} + +func (obj Withdraw) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Amount` param: + err = encoder.Encode(obj.Amount) + if err != nil { + return err + } + // Serialize `MinimumAmountsOut` param: + err = encoder.Encode(obj.MinimumAmountsOut) + if err != nil { + return err + } + return nil +} +func (obj *Withdraw) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Amount`: + err = decoder.Decode(&obj.Amount) + if err != nil { + return err + } + // Deserialize `MinimumAmountsOut`: + err = decoder.Decode(&obj.MinimumAmountsOut) + if err != nil { + return err + } + return nil +} + +// NewWithdrawInstruction declares a new Withdraw instruction with the provided parameters and accounts. +func NewWithdrawInstruction( + // Parameters: + amount uint64, + minimum_amounts_out []uint64, + // Accounts: + user ag_solanago.PublicKey, + userPoolToken ag_solanago.PublicKey, + mint ag_solanago.PublicKey, + pool ag_solanago.PublicKey, + withdrawAuthority ag_solanago.PublicKey, + vault ag_solanago.PublicKey, + vaultAuthority ag_solanago.PublicKey, + vaultProgram ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + tokenProgram2022 ag_solanago.PublicKey) *Withdraw { + return NewWithdrawInstructionBuilder(). + SetAmount(amount). + SetMinimumAmountsOut(minimum_amounts_out). + SetUserAccount(user). + SetUserPoolTokenAccount(userPoolToken). + SetMintAccount(mint). + SetPoolAccount(pool). + SetWithdrawAuthorityAccount(withdrawAuthority). + SetVaultAccount(vault). + SetVaultAuthorityAccount(vaultAuthority). + SetVaultProgramAccount(vaultProgram). + SetTokenProgramAccount(tokenProgram). + SetTokenProgram2022Account(tokenProgram2022) +} diff --git a/programs/stabblestableswap/withdraw_test.go b/programs/stabblestableswap/withdraw_test.go new file mode 100644 index 00000000..9f4c3c17 --- /dev/null +++ b/programs/stabblestableswap/withdraw_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package stable_swap + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_Withdraw(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("Withdraw"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(Withdraw) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(Withdraw) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} From 2a71cd0661b8e147e7bbe2b592c041539e8b165a Mon Sep 17 00:00:00 2001 From: egaotan Date: Thu, 23 Jan 2025 18:18:59 +0800 Subject: [PATCH 5/6] update --- programs/stabblestableswap/events.go | 243 --------------------------- 1 file changed, 243 deletions(-) delete mode 100644 programs/stabblestableswap/events.go diff --git a/programs/stabblestableswap/events.go b/programs/stabblestableswap/events.go deleted file mode 100644 index 73354460..00000000 --- a/programs/stabblestableswap/events.go +++ /dev/null @@ -1,243 +0,0 @@ -// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. - -package stable_swap - -import ( - "encoding/base64" - "fmt" - ag_binary "github.com/gagliardetto/binary" - ag_solanago "github.com/gagliardetto/solana-go" - ag_rpc "github.com/gagliardetto/solana-go/rpc" - ag_base58 "github.com/mr-tron/base58" - "reflect" - "strings" -) - -type PoolBalanceUpdatedEventEventData struct { - Pubkey ag_solanago.PublicKey - Data PoolBalanceUpdatedData -} - -var PoolBalanceUpdatedEventEventDataDiscriminator = [8]byte{172, 82, 114, 207, 27, 103, 211, 4} - -func (obj PoolBalanceUpdatedEventEventData) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { - // Write account discriminator: - err = encoder.WriteBytes(PoolBalanceUpdatedEventEventDataDiscriminator[:], false) - if err != nil { - return err - } - // Serialize `Pubkey` param: - err = encoder.Encode(obj.Pubkey) - if err != nil { - return err - } - // Serialize `Data` param: - err = encoder.Encode(obj.Data) - if err != nil { - return err - } - return nil -} - -func (obj *PoolBalanceUpdatedEventEventData) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { - // Read and check account discriminator: - { - discriminator, err := decoder.ReadTypeID() - if err != nil { - return err - } - if !discriminator.Equal(PoolBalanceUpdatedEventEventDataDiscriminator[:]) { - return fmt.Errorf( - "wrong discriminator: wanted %s, got %s", - "[172 82 114 207 27 103 211 4]", - fmt.Sprint(discriminator[:])) - } - } - // Deserialize `Pubkey`: - err = decoder.Decode(&obj.Pubkey) - if err != nil { - return err - } - // Deserialize `Data`: - err = decoder.Decode(&obj.Data) - if err != nil { - return err - } - return nil -} - -func (*PoolBalanceUpdatedEventEventData) isEventData() {} - -type PoolUpdatedEventEventData struct { - Pubkey ag_solanago.PublicKey - Data PoolUpdatedData -} - -var PoolUpdatedEventEventDataDiscriminator = [8]byte{128, 39, 94, 221, 230, 222, 127, 141} - -func (obj PoolUpdatedEventEventData) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { - // Write account discriminator: - err = encoder.WriteBytes(PoolUpdatedEventEventDataDiscriminator[:], false) - if err != nil { - return err - } - // Serialize `Pubkey` param: - err = encoder.Encode(obj.Pubkey) - if err != nil { - return err - } - // Serialize `Data` param: - err = encoder.Encode(obj.Data) - if err != nil { - return err - } - return nil -} - -func (obj *PoolUpdatedEventEventData) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { - // Read and check account discriminator: - { - discriminator, err := decoder.ReadTypeID() - if err != nil { - return err - } - if !discriminator.Equal(PoolUpdatedEventEventDataDiscriminator[:]) { - return fmt.Errorf( - "wrong discriminator: wanted %s, got %s", - "[128 39 94 221 230 222 127 141]", - fmt.Sprint(discriminator[:])) - } - } - // Deserialize `Pubkey`: - err = decoder.Decode(&obj.Pubkey) - if err != nil { - return err - } - // Deserialize `Data`: - err = decoder.Decode(&obj.Data) - if err != nil { - return err - } - return nil -} - -func (*PoolUpdatedEventEventData) isEventData() {} - -var eventTypes = map[[8]byte]reflect.Type{ - PoolBalanceUpdatedEventEventDataDiscriminator: reflect.TypeOf(PoolBalanceUpdatedEventEventData{}), - PoolUpdatedEventEventDataDiscriminator: reflect.TypeOf(PoolUpdatedEventEventData{}), -} -var eventNames = map[[8]byte]string{ - PoolBalanceUpdatedEventEventDataDiscriminator: "PoolBalanceUpdatedEvent", - PoolUpdatedEventEventDataDiscriminator: "PoolUpdatedEvent", -} -var ( - _ *strings.Builder = nil -) -var ( - _ *base64.Encoding = nil -) -var ( - _ *ag_binary.Decoder = nil -) -var ( - _ *ag_rpc.GetTransactionResult = nil -) -var ( - _ *ag_base58.Alphabet = nil -) - -type Event struct { - Name string - Data EventData -} - -type EventData interface { - UnmarshalWithDecoder(decoder *ag_binary.Decoder) error - isEventData() -} - -const eventLogPrefix = "Program data: " - -func DecodeEventsFromLogMessage(logMessages []string) (eventBinaries [][]byte, err error) { - for _, log := range logMessages { - if strings.HasPrefix(log, eventLogPrefix) { - eventBase64 := log[len(eventLogPrefix):] - - var eventBinary []byte - if eventBinary, err = base64.StdEncoding.DecodeString(eventBase64); err != nil { - err = fmt.Errorf("failed to decode logMessage event: %s", eventBase64) - return - } - eventBinaries = append(eventBinaries, eventBinary) - } - } - return -} - -func DecodeEventsFromEmitCPI(InnerInstructions []ag_rpc.InnerInstruction, accountKeys ag_solanago.PublicKeySlice, targetProgramId ag_solanago.PublicKey) (eventBinaries [][]byte, err error) { - for _, parsedIx := range InnerInstructions { - for _, ix := range parsedIx.Instructions { - if accountKeys[ix.ProgramIDIndex] != targetProgramId { - continue - } - - var ixData []byte - if ixData, err = ag_base58.Decode(string(ix.Data)); err != nil { - err = fmt.Errorf("failed to decode base58 emit cpi event: %s", string(ixData)) - return - } - eventBase64 := base64.StdEncoding.EncodeToString(ixData[8:]) - var eventBinary []byte - if eventBinary, err = base64.StdEncoding.DecodeString(eventBase64); err != nil { - err = fmt.Errorf("failed to decode base64 emit cpi event: %s", eventBase64) - return - } - eventBinaries = append(eventBinaries, eventBinary) - } - } - return -} - -func DecodeEvents(txData *ag_rpc.GetTransactionResult, targetProgramId ag_solanago.PublicKey) (evts []*Event, err error) { - var tx *ag_solanago.Transaction - if tx, err = txData.Transaction.GetTransaction(); err != nil { - return - } - - var base64Binaries [][]byte - logMessageEventBinaries, err := DecodeEventsFromLogMessage(txData.Meta.LogMessages) - if err != nil { - return - } - emitedCPIEventBinaries, err := DecodeEventsFromEmitCPI(txData.Meta.InnerInstructions, tx.Message.AccountKeys, targetProgramId) - if err != nil { - return - } - - base64Binaries = append(base64Binaries, logMessageEventBinaries...) - base64Binaries = append(base64Binaries, emitedCPIEventBinaries...) - evts, err = ParseEvents(base64Binaries) - return -} - -func ParseEvents(base64Binaries [][]byte) (evts []*Event, err error) { - decoder := ag_binary.NewDecoderWithEncoding(nil, ag_binary.EncodingBorsh) - - for _, eventBinary := range base64Binaries { - eventDiscriminator := ag_binary.TypeID(eventBinary[:8]) - if eventType, ok := eventTypes[eventDiscriminator]; ok { - eventData := reflect.New(eventType).Interface().(EventData) - decoder.Reset(eventBinary) - if err = eventData.UnmarshalWithDecoder(decoder); err != nil { - err = fmt.Errorf("failed to unmarshal event %s: %w", eventType.String(), err) - return - } - evts = append(evts, &Event{ - Name: eventNames[eventDiscriminator], - Data: eventData, - }) - } - } - return -} From a676031ec487f2a0aa728addcf1e496c9ac876a5 Mon Sep 17 00:00:00 2001 From: egaotan Date: Thu, 23 Jan 2025 19:41:13 +0800 Subject: [PATCH 6/6] uupdate --- programs/meteoradlmm/AddLiquidity.go | 412 ++++ .../meteoradlmm/AddLiquidityByStrategy.go | 412 ++++ .../AddLiquidityByStrategyOneSide.go | 336 ++++ .../AddLiquidityByStrategyOneSide_test.go | 32 + .../AddLiquidityByStrategy_test.go | 32 + programs/meteoradlmm/AddLiquidityByWeight.go | 412 ++++ .../meteoradlmm/AddLiquidityByWeight_test.go | 32 + programs/meteoradlmm/AddLiquidityOneSide.go | 336 ++++ .../meteoradlmm/AddLiquidityOneSidePrecise.go | 336 ++++ .../AddLiquidityOneSidePrecise_test.go | 32 + .../meteoradlmm/AddLiquidityOneSide_test.go | 32 + programs/meteoradlmm/AddLiquidity_test.go | 32 + programs/meteoradlmm/ClaimFee.go | 345 ++++ programs/meteoradlmm/ClaimFee_test.go | 32 + programs/meteoradlmm/ClaimReward.go | 317 +++ programs/meteoradlmm/ClaimReward_test.go | 32 + programs/meteoradlmm/ClosePosition.go | 231 +++ programs/meteoradlmm/ClosePosition_test.go | 32 + programs/meteoradlmm/ClosePresetParameter.go | 136 ++ .../meteoradlmm/ClosePresetParameter_test.go | 32 + programs/meteoradlmm/FundReward.go | 325 ++++ programs/meteoradlmm/FundReward_test.go | 32 + programs/meteoradlmm/GoToABin.go | 222 +++ programs/meteoradlmm/GoToABin_test.go | 32 + programs/meteoradlmm/IncreaseOracleLength.go | 203 ++ .../meteoradlmm/IncreaseOracleLength_test.go | 32 + programs/meteoradlmm/InitializeBinArray.go | 184 ++ .../InitializeBinArrayBitmapExtension.go | 177 ++ .../InitializeBinArrayBitmapExtension_test.go | 32 + .../meteoradlmm/InitializeBinArray_test.go | 32 + ...tializeCustomizablePermissionlessLbPair.go | 374 ++++ ...zeCustomizablePermissionlessLbPair_test.go | 32 + programs/meteoradlmm/InitializeLbPair.go | 397 ++++ programs/meteoradlmm/InitializeLbPair_test.go | 32 + .../meteoradlmm/InitializePermissionLbPair.go | 374 ++++ .../InitializePermissionLbPair_test.go | 32 + programs/meteoradlmm/InitializePosition.go | 283 +++ .../InitializePositionByOperator.go | 389 ++++ .../InitializePositionByOperator_test.go | 32 + programs/meteoradlmm/InitializePositionPda.go | 305 +++ .../meteoradlmm/InitializePositionPda_test.go | 32 + .../meteoradlmm/InitializePosition_test.go | 32 + .../meteoradlmm/InitializePresetParameter.go | 184 ++ .../InitializePresetParameter_test.go | 32 + programs/meteoradlmm/InitializeReward.go | 325 ++++ programs/meteoradlmm/InitializeReward_test.go | 32 + programs/meteoradlmm/MigrateBinArray.go | 98 + programs/meteoradlmm/MigrateBinArray_test.go | 32 + programs/meteoradlmm/MigratePosition.go | 269 +++ programs/meteoradlmm/MigratePosition_test.go | 32 + programs/meteoradlmm/RemoveAllLiquidity.go | 383 ++++ .../meteoradlmm/RemoveAllLiquidity_test.go | 32 + programs/meteoradlmm/RemoveLiquidity.go | 412 ++++ .../meteoradlmm/RemoveLiquidityByRange.go | 458 +++++ .../RemoveLiquidityByRange_test.go | 32 + programs/meteoradlmm/RemoveLiquidity_test.go | 32 + programs/meteoradlmm/SetActivationPoint.go | 146 ++ .../meteoradlmm/SetActivationPoint_test.go | 32 + .../meteoradlmm/SetPreActivationDuration.go | 146 ++ .../SetPreActivationDuration_test.go | 32 + .../SetPreActivationSwapAddress.go | 146 ++ .../SetPreActivationSwapAddress_test.go | 32 + programs/meteoradlmm/Swap.go | 416 ++++ programs/meteoradlmm/SwapExactOut.go | 416 ++++ programs/meteoradlmm/SwapExactOut_test.go | 32 + programs/meteoradlmm/SwapWithPriceImpact.go | 457 +++++ .../meteoradlmm/SwapWithPriceImpact_test.go | 32 + programs/meteoradlmm/Swap_test.go | 32 + programs/meteoradlmm/TogglePairStatus.go | 117 ++ programs/meteoradlmm/TogglePairStatus_test.go | 32 + programs/meteoradlmm/UpdateFeeParameters.go | 184 ++ .../meteoradlmm/UpdateFeeParameters_test.go | 32 + programs/meteoradlmm/UpdateFeesAndRewards.go | 174 ++ .../meteoradlmm/UpdateFeesAndRewards_test.go | 32 + .../meteoradlmm/UpdatePositionOperator.go | 184 ++ .../UpdatePositionOperator_test.go | 32 + programs/meteoradlmm/UpdateRewardDuration.go | 226 +++ .../meteoradlmm/UpdateRewardDuration_test.go | 32 + programs/meteoradlmm/UpdateRewardFunder.go | 207 ++ .../meteoradlmm/UpdateRewardFunder_test.go | 32 + .../meteoradlmm/WithdrawIneligibleReward.go | 279 +++ .../WithdrawIneligibleReward_test.go | 32 + programs/meteoradlmm/WithdrawProtocolFee.go | 302 +++ .../meteoradlmm/WithdrawProtocolFee_test.go | 32 + programs/meteoradlmm/accounts.go | 1246 ++++++++++++ programs/meteoradlmm/instructions.go | 404 ++++ programs/meteoradlmm/testing_utils.go | 20 + programs/meteoradlmm/types.go | 1724 +++++++++++++++++ programs/meteorapools/AddBalanceLiquidity.go | 506 +++++ .../meteorapools/AddBalanceLiquidity_test.go | 32 + .../meteorapools/AddImbalanceLiquidity.go | 506 +++++ .../AddImbalanceLiquidity_test.go | 32 + programs/meteorapools/BootstrapLiquidity.go | 483 +++++ .../meteorapools/BootstrapLiquidity_test.go | 32 + programs/meteorapools/ClaimFee.go | 504 +++++ programs/meteorapools/ClaimFee_test.go | 32 + programs/meteorapools/CloseConfig.go | 136 ++ programs/meteorapools/CloseConfig_test.go | 32 + programs/meteorapools/CreateConfig.go | 165 ++ programs/meteorapools/CreateConfig_test.go | 32 + programs/meteorapools/CreateLockEscrow.go | 208 ++ .../meteorapools/CreateLockEscrow_test.go | 32 + programs/meteorapools/CreateMintMetadata.go | 227 +++ .../meteorapools/CreateMintMetadata_test.go | 32 + programs/meteorapools/EnableOrDisablePool.go | 152 ++ .../meteorapools/EnableOrDisablePool_test.go | 32 + programs/meteorapools/GetPoolInfo.go | 255 +++ programs/meteorapools/GetPoolInfo_test.go | 32 + ...izablePermissionlessConstantProductPool.go | 695 +++++++ ...ePermissionlessConstantProductPool_test.go | 32 + .../InitializePermissionedPool.go | 653 +++++++ .../InitializePermissionedPool_test.go | 55 + ...issionlessConstantProductPoolWithConfig.go | 691 +++++++ ...ssionlessConstantProductPoolWithConfig2.go | 732 +++++++ ...lessConstantProductPoolWithConfig2_test.go | 32 + ...nlessConstantProductPoolWithConfig_test.go | 32 + .../InitializePermissionlessPool.go | 737 +++++++ ...InitializePermissionlessPoolWithFeeTier.go | 760 ++++++++ ...alizePermissionlessPoolWithFeeTier_test.go | 55 + .../InitializePermissionlessPool_test.go | 55 + programs/meteorapools/Lock.go | 394 ++++ programs/meteorapools/Lock_test.go | 32 + programs/meteorapools/OverrideCurveParam.go | 176 ++ .../meteorapools/OverrideCurveParam_test.go | 55 + programs/meteorapools/PartnerClaimFee.go | 286 +++ programs/meteorapools/PartnerClaimFee_test.go | 32 + .../meteorapools/RemoveBalanceLiquidity.go | 506 +++++ .../RemoveBalanceLiquidity_test.go | 32 + .../meteorapools/RemoveLiquiditySingleSide.go | 461 +++++ .../RemoveLiquiditySingleSide_test.go | 32 + programs/meteorapools/SetPoolFees.go | 175 ++ programs/meteorapools/SetPoolFees_test.go | 32 + programs/meteorapools/SetWhitelistedVault.go | 146 ++ .../meteorapools/SetWhitelistedVault_test.go | 32 + programs/meteorapools/Swap.go | 461 +++++ programs/meteorapools/Swap_test.go | 32 + .../meteorapools/UpdateActivationPoint.go | 152 ++ .../UpdateActivationPoint_test.go | 32 + programs/meteorapools/WithdrawProtocolFees.go | 215 ++ .../meteorapools/WithdrawProtocolFees_test.go | 32 + programs/meteorapools/accounts.go | 589 ++++++ programs/meteorapools/instructions.go | 320 +++ programs/meteorapools/testing_utils.go | 20 + programs/meteorapools/types.go | 842 ++++++++ 144 files changed, 29850 insertions(+) create mode 100644 programs/meteoradlmm/AddLiquidity.go create mode 100644 programs/meteoradlmm/AddLiquidityByStrategy.go create mode 100644 programs/meteoradlmm/AddLiquidityByStrategyOneSide.go create mode 100644 programs/meteoradlmm/AddLiquidityByStrategyOneSide_test.go create mode 100644 programs/meteoradlmm/AddLiquidityByStrategy_test.go create mode 100644 programs/meteoradlmm/AddLiquidityByWeight.go create mode 100644 programs/meteoradlmm/AddLiquidityByWeight_test.go create mode 100644 programs/meteoradlmm/AddLiquidityOneSide.go create mode 100644 programs/meteoradlmm/AddLiquidityOneSidePrecise.go create mode 100644 programs/meteoradlmm/AddLiquidityOneSidePrecise_test.go create mode 100644 programs/meteoradlmm/AddLiquidityOneSide_test.go create mode 100644 programs/meteoradlmm/AddLiquidity_test.go create mode 100644 programs/meteoradlmm/ClaimFee.go create mode 100644 programs/meteoradlmm/ClaimFee_test.go create mode 100644 programs/meteoradlmm/ClaimReward.go create mode 100644 programs/meteoradlmm/ClaimReward_test.go create mode 100644 programs/meteoradlmm/ClosePosition.go create mode 100644 programs/meteoradlmm/ClosePosition_test.go create mode 100644 programs/meteoradlmm/ClosePresetParameter.go create mode 100644 programs/meteoradlmm/ClosePresetParameter_test.go create mode 100644 programs/meteoradlmm/FundReward.go create mode 100644 programs/meteoradlmm/FundReward_test.go create mode 100644 programs/meteoradlmm/GoToABin.go create mode 100644 programs/meteoradlmm/GoToABin_test.go create mode 100644 programs/meteoradlmm/IncreaseOracleLength.go create mode 100644 programs/meteoradlmm/IncreaseOracleLength_test.go create mode 100644 programs/meteoradlmm/InitializeBinArray.go create mode 100644 programs/meteoradlmm/InitializeBinArrayBitmapExtension.go create mode 100644 programs/meteoradlmm/InitializeBinArrayBitmapExtension_test.go create mode 100644 programs/meteoradlmm/InitializeBinArray_test.go create mode 100644 programs/meteoradlmm/InitializeCustomizablePermissionlessLbPair.go create mode 100644 programs/meteoradlmm/InitializeCustomizablePermissionlessLbPair_test.go create mode 100644 programs/meteoradlmm/InitializeLbPair.go create mode 100644 programs/meteoradlmm/InitializeLbPair_test.go create mode 100644 programs/meteoradlmm/InitializePermissionLbPair.go create mode 100644 programs/meteoradlmm/InitializePermissionLbPair_test.go create mode 100644 programs/meteoradlmm/InitializePosition.go create mode 100644 programs/meteoradlmm/InitializePositionByOperator.go create mode 100644 programs/meteoradlmm/InitializePositionByOperator_test.go create mode 100644 programs/meteoradlmm/InitializePositionPda.go create mode 100644 programs/meteoradlmm/InitializePositionPda_test.go create mode 100644 programs/meteoradlmm/InitializePosition_test.go create mode 100644 programs/meteoradlmm/InitializePresetParameter.go create mode 100644 programs/meteoradlmm/InitializePresetParameter_test.go create mode 100644 programs/meteoradlmm/InitializeReward.go create mode 100644 programs/meteoradlmm/InitializeReward_test.go create mode 100644 programs/meteoradlmm/MigrateBinArray.go create mode 100644 programs/meteoradlmm/MigrateBinArray_test.go create mode 100644 programs/meteoradlmm/MigratePosition.go create mode 100644 programs/meteoradlmm/MigratePosition_test.go create mode 100644 programs/meteoradlmm/RemoveAllLiquidity.go create mode 100644 programs/meteoradlmm/RemoveAllLiquidity_test.go create mode 100644 programs/meteoradlmm/RemoveLiquidity.go create mode 100644 programs/meteoradlmm/RemoveLiquidityByRange.go create mode 100644 programs/meteoradlmm/RemoveLiquidityByRange_test.go create mode 100644 programs/meteoradlmm/RemoveLiquidity_test.go create mode 100644 programs/meteoradlmm/SetActivationPoint.go create mode 100644 programs/meteoradlmm/SetActivationPoint_test.go create mode 100644 programs/meteoradlmm/SetPreActivationDuration.go create mode 100644 programs/meteoradlmm/SetPreActivationDuration_test.go create mode 100644 programs/meteoradlmm/SetPreActivationSwapAddress.go create mode 100644 programs/meteoradlmm/SetPreActivationSwapAddress_test.go create mode 100644 programs/meteoradlmm/Swap.go create mode 100644 programs/meteoradlmm/SwapExactOut.go create mode 100644 programs/meteoradlmm/SwapExactOut_test.go create mode 100644 programs/meteoradlmm/SwapWithPriceImpact.go create mode 100644 programs/meteoradlmm/SwapWithPriceImpact_test.go create mode 100644 programs/meteoradlmm/Swap_test.go create mode 100644 programs/meteoradlmm/TogglePairStatus.go create mode 100644 programs/meteoradlmm/TogglePairStatus_test.go create mode 100644 programs/meteoradlmm/UpdateFeeParameters.go create mode 100644 programs/meteoradlmm/UpdateFeeParameters_test.go create mode 100644 programs/meteoradlmm/UpdateFeesAndRewards.go create mode 100644 programs/meteoradlmm/UpdateFeesAndRewards_test.go create mode 100644 programs/meteoradlmm/UpdatePositionOperator.go create mode 100644 programs/meteoradlmm/UpdatePositionOperator_test.go create mode 100644 programs/meteoradlmm/UpdateRewardDuration.go create mode 100644 programs/meteoradlmm/UpdateRewardDuration_test.go create mode 100644 programs/meteoradlmm/UpdateRewardFunder.go create mode 100644 programs/meteoradlmm/UpdateRewardFunder_test.go create mode 100644 programs/meteoradlmm/WithdrawIneligibleReward.go create mode 100644 programs/meteoradlmm/WithdrawIneligibleReward_test.go create mode 100644 programs/meteoradlmm/WithdrawProtocolFee.go create mode 100644 programs/meteoradlmm/WithdrawProtocolFee_test.go create mode 100644 programs/meteoradlmm/accounts.go create mode 100644 programs/meteoradlmm/instructions.go create mode 100644 programs/meteoradlmm/testing_utils.go create mode 100644 programs/meteoradlmm/types.go create mode 100644 programs/meteorapools/AddBalanceLiquidity.go create mode 100644 programs/meteorapools/AddBalanceLiquidity_test.go create mode 100644 programs/meteorapools/AddImbalanceLiquidity.go create mode 100644 programs/meteorapools/AddImbalanceLiquidity_test.go create mode 100644 programs/meteorapools/BootstrapLiquidity.go create mode 100644 programs/meteorapools/BootstrapLiquidity_test.go create mode 100644 programs/meteorapools/ClaimFee.go create mode 100644 programs/meteorapools/ClaimFee_test.go create mode 100644 programs/meteorapools/CloseConfig.go create mode 100644 programs/meteorapools/CloseConfig_test.go create mode 100644 programs/meteorapools/CreateConfig.go create mode 100644 programs/meteorapools/CreateConfig_test.go create mode 100644 programs/meteorapools/CreateLockEscrow.go create mode 100644 programs/meteorapools/CreateLockEscrow_test.go create mode 100644 programs/meteorapools/CreateMintMetadata.go create mode 100644 programs/meteorapools/CreateMintMetadata_test.go create mode 100644 programs/meteorapools/EnableOrDisablePool.go create mode 100644 programs/meteorapools/EnableOrDisablePool_test.go create mode 100644 programs/meteorapools/GetPoolInfo.go create mode 100644 programs/meteorapools/GetPoolInfo_test.go create mode 100644 programs/meteorapools/InitializeCustomizablePermissionlessConstantProductPool.go create mode 100644 programs/meteorapools/InitializeCustomizablePermissionlessConstantProductPool_test.go create mode 100644 programs/meteorapools/InitializePermissionedPool.go create mode 100644 programs/meteorapools/InitializePermissionedPool_test.go create mode 100644 programs/meteorapools/InitializePermissionlessConstantProductPoolWithConfig.go create mode 100644 programs/meteorapools/InitializePermissionlessConstantProductPoolWithConfig2.go create mode 100644 programs/meteorapools/InitializePermissionlessConstantProductPoolWithConfig2_test.go create mode 100644 programs/meteorapools/InitializePermissionlessConstantProductPoolWithConfig_test.go create mode 100644 programs/meteorapools/InitializePermissionlessPool.go create mode 100644 programs/meteorapools/InitializePermissionlessPoolWithFeeTier.go create mode 100644 programs/meteorapools/InitializePermissionlessPoolWithFeeTier_test.go create mode 100644 programs/meteorapools/InitializePermissionlessPool_test.go create mode 100644 programs/meteorapools/Lock.go create mode 100644 programs/meteorapools/Lock_test.go create mode 100644 programs/meteorapools/OverrideCurveParam.go create mode 100644 programs/meteorapools/OverrideCurveParam_test.go create mode 100644 programs/meteorapools/PartnerClaimFee.go create mode 100644 programs/meteorapools/PartnerClaimFee_test.go create mode 100644 programs/meteorapools/RemoveBalanceLiquidity.go create mode 100644 programs/meteorapools/RemoveBalanceLiquidity_test.go create mode 100644 programs/meteorapools/RemoveLiquiditySingleSide.go create mode 100644 programs/meteorapools/RemoveLiquiditySingleSide_test.go create mode 100644 programs/meteorapools/SetPoolFees.go create mode 100644 programs/meteorapools/SetPoolFees_test.go create mode 100644 programs/meteorapools/SetWhitelistedVault.go create mode 100644 programs/meteorapools/SetWhitelistedVault_test.go create mode 100644 programs/meteorapools/Swap.go create mode 100644 programs/meteorapools/Swap_test.go create mode 100644 programs/meteorapools/UpdateActivationPoint.go create mode 100644 programs/meteorapools/UpdateActivationPoint_test.go create mode 100644 programs/meteorapools/WithdrawProtocolFees.go create mode 100644 programs/meteorapools/WithdrawProtocolFees_test.go create mode 100644 programs/meteorapools/accounts.go create mode 100644 programs/meteorapools/instructions.go create mode 100644 programs/meteorapools/testing_utils.go create mode 100644 programs/meteorapools/types.go diff --git a/programs/meteoradlmm/AddLiquidity.go b/programs/meteoradlmm/AddLiquidity.go new file mode 100644 index 00000000..34f3a7d1 --- /dev/null +++ b/programs/meteoradlmm/AddLiquidity.go @@ -0,0 +1,412 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// AddLiquidity is the `addLiquidity` instruction. +type AddLiquidity struct { + LiquidityParameter *LiquidityParameter + + // [0] = [WRITE] position + // + // [1] = [WRITE] lbPair + // + // [2] = [WRITE] binArrayBitmapExtension + // + // [3] = [WRITE] userTokenX + // + // [4] = [WRITE] userTokenY + // + // [5] = [WRITE] reserveX + // + // [6] = [WRITE] reserveY + // + // [7] = [] tokenXMint + // + // [8] = [] tokenYMint + // + // [9] = [WRITE] binArrayLower + // + // [10] = [WRITE] binArrayUpper + // + // [11] = [SIGNER] sender + // + // [12] = [] tokenXProgram + // + // [13] = [] tokenYProgram + // + // [14] = [] eventAuthority + // + // [15] = [] program + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewAddLiquidityInstructionBuilder creates a new `AddLiquidity` instruction builder. +func NewAddLiquidityInstructionBuilder() *AddLiquidity { + nd := &AddLiquidity{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 16), + } + return nd +} + +// SetLiquidityParameter sets the "liquidityParameter" parameter. +func (inst *AddLiquidity) SetLiquidityParameter(liquidityParameter LiquidityParameter) *AddLiquidity { + inst.LiquidityParameter = &liquidityParameter + return inst +} + +// SetPositionAccount sets the "position" account. +func (inst *AddLiquidity) SetPositionAccount(position ag_solanago.PublicKey) *AddLiquidity { + inst.AccountMetaSlice[0] = ag_solanago.Meta(position).WRITE() + return inst +} + +// GetPositionAccount gets the "position" account. +func (inst *AddLiquidity) GetPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetLbPairAccount sets the "lbPair" account. +func (inst *AddLiquidity) SetLbPairAccount(lbPair ag_solanago.PublicKey) *AddLiquidity { + inst.AccountMetaSlice[1] = ag_solanago.Meta(lbPair).WRITE() + return inst +} + +// GetLbPairAccount gets the "lbPair" account. +func (inst *AddLiquidity) GetLbPairAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetBinArrayBitmapExtensionAccount sets the "binArrayBitmapExtension" account. +func (inst *AddLiquidity) SetBinArrayBitmapExtensionAccount(binArrayBitmapExtension ag_solanago.PublicKey) *AddLiquidity { + inst.AccountMetaSlice[2] = ag_solanago.Meta(binArrayBitmapExtension).WRITE() + return inst +} + +// GetBinArrayBitmapExtensionAccount gets the "binArrayBitmapExtension" account. +func (inst *AddLiquidity) GetBinArrayBitmapExtensionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetUserTokenXAccount sets the "userTokenX" account. +func (inst *AddLiquidity) SetUserTokenXAccount(userTokenX ag_solanago.PublicKey) *AddLiquidity { + inst.AccountMetaSlice[3] = ag_solanago.Meta(userTokenX).WRITE() + return inst +} + +// GetUserTokenXAccount gets the "userTokenX" account. +func (inst *AddLiquidity) GetUserTokenXAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetUserTokenYAccount sets the "userTokenY" account. +func (inst *AddLiquidity) SetUserTokenYAccount(userTokenY ag_solanago.PublicKey) *AddLiquidity { + inst.AccountMetaSlice[4] = ag_solanago.Meta(userTokenY).WRITE() + return inst +} + +// GetUserTokenYAccount gets the "userTokenY" account. +func (inst *AddLiquidity) GetUserTokenYAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetReserveXAccount sets the "reserveX" account. +func (inst *AddLiquidity) SetReserveXAccount(reserveX ag_solanago.PublicKey) *AddLiquidity { + inst.AccountMetaSlice[5] = ag_solanago.Meta(reserveX).WRITE() + return inst +} + +// GetReserveXAccount gets the "reserveX" account. +func (inst *AddLiquidity) GetReserveXAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetReserveYAccount sets the "reserveY" account. +func (inst *AddLiquidity) SetReserveYAccount(reserveY ag_solanago.PublicKey) *AddLiquidity { + inst.AccountMetaSlice[6] = ag_solanago.Meta(reserveY).WRITE() + return inst +} + +// GetReserveYAccount gets the "reserveY" account. +func (inst *AddLiquidity) GetReserveYAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetTokenXMintAccount sets the "tokenXMint" account. +func (inst *AddLiquidity) SetTokenXMintAccount(tokenXMint ag_solanago.PublicKey) *AddLiquidity { + inst.AccountMetaSlice[7] = ag_solanago.Meta(tokenXMint) + return inst +} + +// GetTokenXMintAccount gets the "tokenXMint" account. +func (inst *AddLiquidity) GetTokenXMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetTokenYMintAccount sets the "tokenYMint" account. +func (inst *AddLiquidity) SetTokenYMintAccount(tokenYMint ag_solanago.PublicKey) *AddLiquidity { + inst.AccountMetaSlice[8] = ag_solanago.Meta(tokenYMint) + return inst +} + +// GetTokenYMintAccount gets the "tokenYMint" account. +func (inst *AddLiquidity) GetTokenYMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetBinArrayLowerAccount sets the "binArrayLower" account. +func (inst *AddLiquidity) SetBinArrayLowerAccount(binArrayLower ag_solanago.PublicKey) *AddLiquidity { + inst.AccountMetaSlice[9] = ag_solanago.Meta(binArrayLower).WRITE() + return inst +} + +// GetBinArrayLowerAccount gets the "binArrayLower" account. +func (inst *AddLiquidity) GetBinArrayLowerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetBinArrayUpperAccount sets the "binArrayUpper" account. +func (inst *AddLiquidity) SetBinArrayUpperAccount(binArrayUpper ag_solanago.PublicKey) *AddLiquidity { + inst.AccountMetaSlice[10] = ag_solanago.Meta(binArrayUpper).WRITE() + return inst +} + +// GetBinArrayUpperAccount gets the "binArrayUpper" account. +func (inst *AddLiquidity) GetBinArrayUpperAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetSenderAccount sets the "sender" account. +func (inst *AddLiquidity) SetSenderAccount(sender ag_solanago.PublicKey) *AddLiquidity { + inst.AccountMetaSlice[11] = ag_solanago.Meta(sender).SIGNER() + return inst +} + +// GetSenderAccount gets the "sender" account. +func (inst *AddLiquidity) GetSenderAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetTokenXProgramAccount sets the "tokenXProgram" account. +func (inst *AddLiquidity) SetTokenXProgramAccount(tokenXProgram ag_solanago.PublicKey) *AddLiquidity { + inst.AccountMetaSlice[12] = ag_solanago.Meta(tokenXProgram) + return inst +} + +// GetTokenXProgramAccount gets the "tokenXProgram" account. +func (inst *AddLiquidity) GetTokenXProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetTokenYProgramAccount sets the "tokenYProgram" account. +func (inst *AddLiquidity) SetTokenYProgramAccount(tokenYProgram ag_solanago.PublicKey) *AddLiquidity { + inst.AccountMetaSlice[13] = ag_solanago.Meta(tokenYProgram) + return inst +} + +// GetTokenYProgramAccount gets the "tokenYProgram" account. +func (inst *AddLiquidity) GetTokenYProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetEventAuthorityAccount sets the "eventAuthority" account. +func (inst *AddLiquidity) SetEventAuthorityAccount(eventAuthority ag_solanago.PublicKey) *AddLiquidity { + inst.AccountMetaSlice[14] = ag_solanago.Meta(eventAuthority) + return inst +} + +// GetEventAuthorityAccount gets the "eventAuthority" account. +func (inst *AddLiquidity) GetEventAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +// SetProgramAccount sets the "program" account. +func (inst *AddLiquidity) SetProgramAccount(program ag_solanago.PublicKey) *AddLiquidity { + inst.AccountMetaSlice[15] = ag_solanago.Meta(program) + return inst +} + +// GetProgramAccount gets the "program" account. +func (inst *AddLiquidity) GetProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(15) +} + +func (inst AddLiquidity) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_AddLiquidity, + }} +} + +// 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 AddLiquidity) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *AddLiquidity) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.LiquidityParameter == nil { + return errors.New("LiquidityParameter parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Position is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.LbPair is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.BinArrayBitmapExtension is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.UserTokenX is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.UserTokenY is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.ReserveX is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.ReserveY is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.TokenXMint is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.TokenYMint is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.BinArrayLower is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.BinArrayUpper is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.Sender is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.TokenXProgram is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.TokenYProgram is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.EventAuthority is not set") + } + if inst.AccountMetaSlice[15] == nil { + return errors.New("accounts.Program is not set") + } + } + return nil +} + +func (inst *AddLiquidity) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("AddLiquidity")). + // + 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("LiquidityParameter", *inst.LiquidityParameter)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=16]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" position", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" lbPair", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta("binArrayBitmapExtension", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" userTokenX", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" userTokenY", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" reserveX", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" reserveY", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" tokenXMint", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" tokenYMint", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" binArrayLower", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" binArrayUpper", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" sender", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" tokenXProgram", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" tokenYProgram", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta(" eventAuthority", inst.AccountMetaSlice.Get(14))) + accountsBranch.Child(ag_format.Meta(" program", inst.AccountMetaSlice.Get(15))) + }) + }) + }) +} + +func (obj AddLiquidity) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `LiquidityParameter` param: + err = encoder.Encode(obj.LiquidityParameter) + if err != nil { + return err + } + return nil +} +func (obj *AddLiquidity) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `LiquidityParameter`: + err = decoder.Decode(&obj.LiquidityParameter) + if err != nil { + return err + } + return nil +} + +// NewAddLiquidityInstruction declares a new AddLiquidity instruction with the provided parameters and accounts. +func NewAddLiquidityInstruction( + // Parameters: + liquidityParameter LiquidityParameter, + // Accounts: + position ag_solanago.PublicKey, + lbPair ag_solanago.PublicKey, + binArrayBitmapExtension ag_solanago.PublicKey, + userTokenX ag_solanago.PublicKey, + userTokenY ag_solanago.PublicKey, + reserveX ag_solanago.PublicKey, + reserveY ag_solanago.PublicKey, + tokenXMint ag_solanago.PublicKey, + tokenYMint ag_solanago.PublicKey, + binArrayLower ag_solanago.PublicKey, + binArrayUpper ag_solanago.PublicKey, + sender ag_solanago.PublicKey, + tokenXProgram ag_solanago.PublicKey, + tokenYProgram ag_solanago.PublicKey, + eventAuthority ag_solanago.PublicKey, + program ag_solanago.PublicKey) *AddLiquidity { + return NewAddLiquidityInstructionBuilder(). + SetLiquidityParameter(liquidityParameter). + SetPositionAccount(position). + SetLbPairAccount(lbPair). + SetBinArrayBitmapExtensionAccount(binArrayBitmapExtension). + SetUserTokenXAccount(userTokenX). + SetUserTokenYAccount(userTokenY). + SetReserveXAccount(reserveX). + SetReserveYAccount(reserveY). + SetTokenXMintAccount(tokenXMint). + SetTokenYMintAccount(tokenYMint). + SetBinArrayLowerAccount(binArrayLower). + SetBinArrayUpperAccount(binArrayUpper). + SetSenderAccount(sender). + SetTokenXProgramAccount(tokenXProgram). + SetTokenYProgramAccount(tokenYProgram). + SetEventAuthorityAccount(eventAuthority). + SetProgramAccount(program) +} diff --git a/programs/meteoradlmm/AddLiquidityByStrategy.go b/programs/meteoradlmm/AddLiquidityByStrategy.go new file mode 100644 index 00000000..d612e5a6 --- /dev/null +++ b/programs/meteoradlmm/AddLiquidityByStrategy.go @@ -0,0 +1,412 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// AddLiquidityByStrategy is the `addLiquidityByStrategy` instruction. +type AddLiquidityByStrategy struct { + LiquidityParameter *LiquidityParameterByStrategy + + // [0] = [WRITE] position + // + // [1] = [WRITE] lbPair + // + // [2] = [WRITE] binArrayBitmapExtension + // + // [3] = [WRITE] userTokenX + // + // [4] = [WRITE] userTokenY + // + // [5] = [WRITE] reserveX + // + // [6] = [WRITE] reserveY + // + // [7] = [] tokenXMint + // + // [8] = [] tokenYMint + // + // [9] = [WRITE] binArrayLower + // + // [10] = [WRITE] binArrayUpper + // + // [11] = [SIGNER] sender + // + // [12] = [] tokenXProgram + // + // [13] = [] tokenYProgram + // + // [14] = [] eventAuthority + // + // [15] = [] program + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewAddLiquidityByStrategyInstructionBuilder creates a new `AddLiquidityByStrategy` instruction builder. +func NewAddLiquidityByStrategyInstructionBuilder() *AddLiquidityByStrategy { + nd := &AddLiquidityByStrategy{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 16), + } + return nd +} + +// SetLiquidityParameter sets the "liquidityParameter" parameter. +func (inst *AddLiquidityByStrategy) SetLiquidityParameter(liquidityParameter LiquidityParameterByStrategy) *AddLiquidityByStrategy { + inst.LiquidityParameter = &liquidityParameter + return inst +} + +// SetPositionAccount sets the "position" account. +func (inst *AddLiquidityByStrategy) SetPositionAccount(position ag_solanago.PublicKey) *AddLiquidityByStrategy { + inst.AccountMetaSlice[0] = ag_solanago.Meta(position).WRITE() + return inst +} + +// GetPositionAccount gets the "position" account. +func (inst *AddLiquidityByStrategy) GetPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetLbPairAccount sets the "lbPair" account. +func (inst *AddLiquidityByStrategy) SetLbPairAccount(lbPair ag_solanago.PublicKey) *AddLiquidityByStrategy { + inst.AccountMetaSlice[1] = ag_solanago.Meta(lbPair).WRITE() + return inst +} + +// GetLbPairAccount gets the "lbPair" account. +func (inst *AddLiquidityByStrategy) GetLbPairAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetBinArrayBitmapExtensionAccount sets the "binArrayBitmapExtension" account. +func (inst *AddLiquidityByStrategy) SetBinArrayBitmapExtensionAccount(binArrayBitmapExtension ag_solanago.PublicKey) *AddLiquidityByStrategy { + inst.AccountMetaSlice[2] = ag_solanago.Meta(binArrayBitmapExtension).WRITE() + return inst +} + +// GetBinArrayBitmapExtensionAccount gets the "binArrayBitmapExtension" account. +func (inst *AddLiquidityByStrategy) GetBinArrayBitmapExtensionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetUserTokenXAccount sets the "userTokenX" account. +func (inst *AddLiquidityByStrategy) SetUserTokenXAccount(userTokenX ag_solanago.PublicKey) *AddLiquidityByStrategy { + inst.AccountMetaSlice[3] = ag_solanago.Meta(userTokenX).WRITE() + return inst +} + +// GetUserTokenXAccount gets the "userTokenX" account. +func (inst *AddLiquidityByStrategy) GetUserTokenXAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetUserTokenYAccount sets the "userTokenY" account. +func (inst *AddLiquidityByStrategy) SetUserTokenYAccount(userTokenY ag_solanago.PublicKey) *AddLiquidityByStrategy { + inst.AccountMetaSlice[4] = ag_solanago.Meta(userTokenY).WRITE() + return inst +} + +// GetUserTokenYAccount gets the "userTokenY" account. +func (inst *AddLiquidityByStrategy) GetUserTokenYAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetReserveXAccount sets the "reserveX" account. +func (inst *AddLiquidityByStrategy) SetReserveXAccount(reserveX ag_solanago.PublicKey) *AddLiquidityByStrategy { + inst.AccountMetaSlice[5] = ag_solanago.Meta(reserveX).WRITE() + return inst +} + +// GetReserveXAccount gets the "reserveX" account. +func (inst *AddLiquidityByStrategy) GetReserveXAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetReserveYAccount sets the "reserveY" account. +func (inst *AddLiquidityByStrategy) SetReserveYAccount(reserveY ag_solanago.PublicKey) *AddLiquidityByStrategy { + inst.AccountMetaSlice[6] = ag_solanago.Meta(reserveY).WRITE() + return inst +} + +// GetReserveYAccount gets the "reserveY" account. +func (inst *AddLiquidityByStrategy) GetReserveYAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetTokenXMintAccount sets the "tokenXMint" account. +func (inst *AddLiquidityByStrategy) SetTokenXMintAccount(tokenXMint ag_solanago.PublicKey) *AddLiquidityByStrategy { + inst.AccountMetaSlice[7] = ag_solanago.Meta(tokenXMint) + return inst +} + +// GetTokenXMintAccount gets the "tokenXMint" account. +func (inst *AddLiquidityByStrategy) GetTokenXMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetTokenYMintAccount sets the "tokenYMint" account. +func (inst *AddLiquidityByStrategy) SetTokenYMintAccount(tokenYMint ag_solanago.PublicKey) *AddLiquidityByStrategy { + inst.AccountMetaSlice[8] = ag_solanago.Meta(tokenYMint) + return inst +} + +// GetTokenYMintAccount gets the "tokenYMint" account. +func (inst *AddLiquidityByStrategy) GetTokenYMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetBinArrayLowerAccount sets the "binArrayLower" account. +func (inst *AddLiquidityByStrategy) SetBinArrayLowerAccount(binArrayLower ag_solanago.PublicKey) *AddLiquidityByStrategy { + inst.AccountMetaSlice[9] = ag_solanago.Meta(binArrayLower).WRITE() + return inst +} + +// GetBinArrayLowerAccount gets the "binArrayLower" account. +func (inst *AddLiquidityByStrategy) GetBinArrayLowerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetBinArrayUpperAccount sets the "binArrayUpper" account. +func (inst *AddLiquidityByStrategy) SetBinArrayUpperAccount(binArrayUpper ag_solanago.PublicKey) *AddLiquidityByStrategy { + inst.AccountMetaSlice[10] = ag_solanago.Meta(binArrayUpper).WRITE() + return inst +} + +// GetBinArrayUpperAccount gets the "binArrayUpper" account. +func (inst *AddLiquidityByStrategy) GetBinArrayUpperAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetSenderAccount sets the "sender" account. +func (inst *AddLiquidityByStrategy) SetSenderAccount(sender ag_solanago.PublicKey) *AddLiquidityByStrategy { + inst.AccountMetaSlice[11] = ag_solanago.Meta(sender).SIGNER() + return inst +} + +// GetSenderAccount gets the "sender" account. +func (inst *AddLiquidityByStrategy) GetSenderAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetTokenXProgramAccount sets the "tokenXProgram" account. +func (inst *AddLiquidityByStrategy) SetTokenXProgramAccount(tokenXProgram ag_solanago.PublicKey) *AddLiquidityByStrategy { + inst.AccountMetaSlice[12] = ag_solanago.Meta(tokenXProgram) + return inst +} + +// GetTokenXProgramAccount gets the "tokenXProgram" account. +func (inst *AddLiquidityByStrategy) GetTokenXProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetTokenYProgramAccount sets the "tokenYProgram" account. +func (inst *AddLiquidityByStrategy) SetTokenYProgramAccount(tokenYProgram ag_solanago.PublicKey) *AddLiquidityByStrategy { + inst.AccountMetaSlice[13] = ag_solanago.Meta(tokenYProgram) + return inst +} + +// GetTokenYProgramAccount gets the "tokenYProgram" account. +func (inst *AddLiquidityByStrategy) GetTokenYProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetEventAuthorityAccount sets the "eventAuthority" account. +func (inst *AddLiquidityByStrategy) SetEventAuthorityAccount(eventAuthority ag_solanago.PublicKey) *AddLiquidityByStrategy { + inst.AccountMetaSlice[14] = ag_solanago.Meta(eventAuthority) + return inst +} + +// GetEventAuthorityAccount gets the "eventAuthority" account. +func (inst *AddLiquidityByStrategy) GetEventAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +// SetProgramAccount sets the "program" account. +func (inst *AddLiquidityByStrategy) SetProgramAccount(program ag_solanago.PublicKey) *AddLiquidityByStrategy { + inst.AccountMetaSlice[15] = ag_solanago.Meta(program) + return inst +} + +// GetProgramAccount gets the "program" account. +func (inst *AddLiquidityByStrategy) GetProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(15) +} + +func (inst AddLiquidityByStrategy) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_AddLiquidityByStrategy, + }} +} + +// 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 AddLiquidityByStrategy) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *AddLiquidityByStrategy) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.LiquidityParameter == nil { + return errors.New("LiquidityParameter parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Position is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.LbPair is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.BinArrayBitmapExtension is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.UserTokenX is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.UserTokenY is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.ReserveX is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.ReserveY is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.TokenXMint is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.TokenYMint is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.BinArrayLower is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.BinArrayUpper is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.Sender is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.TokenXProgram is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.TokenYProgram is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.EventAuthority is not set") + } + if inst.AccountMetaSlice[15] == nil { + return errors.New("accounts.Program is not set") + } + } + return nil +} + +func (inst *AddLiquidityByStrategy) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("AddLiquidityByStrategy")). + // + 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("LiquidityParameter", *inst.LiquidityParameter)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=16]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" position", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" lbPair", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta("binArrayBitmapExtension", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" userTokenX", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" userTokenY", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" reserveX", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" reserveY", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" tokenXMint", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" tokenYMint", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" binArrayLower", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" binArrayUpper", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" sender", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" tokenXProgram", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" tokenYProgram", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta(" eventAuthority", inst.AccountMetaSlice.Get(14))) + accountsBranch.Child(ag_format.Meta(" program", inst.AccountMetaSlice.Get(15))) + }) + }) + }) +} + +func (obj AddLiquidityByStrategy) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `LiquidityParameter` param: + err = encoder.Encode(obj.LiquidityParameter) + if err != nil { + return err + } + return nil +} +func (obj *AddLiquidityByStrategy) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `LiquidityParameter`: + err = decoder.Decode(&obj.LiquidityParameter) + if err != nil { + return err + } + return nil +} + +// NewAddLiquidityByStrategyInstruction declares a new AddLiquidityByStrategy instruction with the provided parameters and accounts. +func NewAddLiquidityByStrategyInstruction( + // Parameters: + liquidityParameter LiquidityParameterByStrategy, + // Accounts: + position ag_solanago.PublicKey, + lbPair ag_solanago.PublicKey, + binArrayBitmapExtension ag_solanago.PublicKey, + userTokenX ag_solanago.PublicKey, + userTokenY ag_solanago.PublicKey, + reserveX ag_solanago.PublicKey, + reserveY ag_solanago.PublicKey, + tokenXMint ag_solanago.PublicKey, + tokenYMint ag_solanago.PublicKey, + binArrayLower ag_solanago.PublicKey, + binArrayUpper ag_solanago.PublicKey, + sender ag_solanago.PublicKey, + tokenXProgram ag_solanago.PublicKey, + tokenYProgram ag_solanago.PublicKey, + eventAuthority ag_solanago.PublicKey, + program ag_solanago.PublicKey) *AddLiquidityByStrategy { + return NewAddLiquidityByStrategyInstructionBuilder(). + SetLiquidityParameter(liquidityParameter). + SetPositionAccount(position). + SetLbPairAccount(lbPair). + SetBinArrayBitmapExtensionAccount(binArrayBitmapExtension). + SetUserTokenXAccount(userTokenX). + SetUserTokenYAccount(userTokenY). + SetReserveXAccount(reserveX). + SetReserveYAccount(reserveY). + SetTokenXMintAccount(tokenXMint). + SetTokenYMintAccount(tokenYMint). + SetBinArrayLowerAccount(binArrayLower). + SetBinArrayUpperAccount(binArrayUpper). + SetSenderAccount(sender). + SetTokenXProgramAccount(tokenXProgram). + SetTokenYProgramAccount(tokenYProgram). + SetEventAuthorityAccount(eventAuthority). + SetProgramAccount(program) +} diff --git a/programs/meteoradlmm/AddLiquidityByStrategyOneSide.go b/programs/meteoradlmm/AddLiquidityByStrategyOneSide.go new file mode 100644 index 00000000..66d583e3 --- /dev/null +++ b/programs/meteoradlmm/AddLiquidityByStrategyOneSide.go @@ -0,0 +1,336 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// AddLiquidityByStrategyOneSide is the `addLiquidityByStrategyOneSide` instruction. +type AddLiquidityByStrategyOneSide struct { + LiquidityParameter *LiquidityParameterByStrategyOneSide + + // [0] = [WRITE] position + // + // [1] = [WRITE] lbPair + // + // [2] = [WRITE] binArrayBitmapExtension + // + // [3] = [WRITE] userToken + // + // [4] = [WRITE] reserve + // + // [5] = [] tokenMint + // + // [6] = [WRITE] binArrayLower + // + // [7] = [WRITE] binArrayUpper + // + // [8] = [SIGNER] sender + // + // [9] = [] tokenProgram + // + // [10] = [] eventAuthority + // + // [11] = [] program + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewAddLiquidityByStrategyOneSideInstructionBuilder creates a new `AddLiquidityByStrategyOneSide` instruction builder. +func NewAddLiquidityByStrategyOneSideInstructionBuilder() *AddLiquidityByStrategyOneSide { + nd := &AddLiquidityByStrategyOneSide{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 12), + } + return nd +} + +// SetLiquidityParameter sets the "liquidityParameter" parameter. +func (inst *AddLiquidityByStrategyOneSide) SetLiquidityParameter(liquidityParameter LiquidityParameterByStrategyOneSide) *AddLiquidityByStrategyOneSide { + inst.LiquidityParameter = &liquidityParameter + return inst +} + +// SetPositionAccount sets the "position" account. +func (inst *AddLiquidityByStrategyOneSide) SetPositionAccount(position ag_solanago.PublicKey) *AddLiquidityByStrategyOneSide { + inst.AccountMetaSlice[0] = ag_solanago.Meta(position).WRITE() + return inst +} + +// GetPositionAccount gets the "position" account. +func (inst *AddLiquidityByStrategyOneSide) GetPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetLbPairAccount sets the "lbPair" account. +func (inst *AddLiquidityByStrategyOneSide) SetLbPairAccount(lbPair ag_solanago.PublicKey) *AddLiquidityByStrategyOneSide { + inst.AccountMetaSlice[1] = ag_solanago.Meta(lbPair).WRITE() + return inst +} + +// GetLbPairAccount gets the "lbPair" account. +func (inst *AddLiquidityByStrategyOneSide) GetLbPairAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetBinArrayBitmapExtensionAccount sets the "binArrayBitmapExtension" account. +func (inst *AddLiquidityByStrategyOneSide) SetBinArrayBitmapExtensionAccount(binArrayBitmapExtension ag_solanago.PublicKey) *AddLiquidityByStrategyOneSide { + inst.AccountMetaSlice[2] = ag_solanago.Meta(binArrayBitmapExtension).WRITE() + return inst +} + +// GetBinArrayBitmapExtensionAccount gets the "binArrayBitmapExtension" account. +func (inst *AddLiquidityByStrategyOneSide) GetBinArrayBitmapExtensionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetUserTokenAccount sets the "userToken" account. +func (inst *AddLiquidityByStrategyOneSide) SetUserTokenAccount(userToken ag_solanago.PublicKey) *AddLiquidityByStrategyOneSide { + inst.AccountMetaSlice[3] = ag_solanago.Meta(userToken).WRITE() + return inst +} + +// GetUserTokenAccount gets the "userToken" account. +func (inst *AddLiquidityByStrategyOneSide) GetUserTokenAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetReserveAccount sets the "reserve" account. +func (inst *AddLiquidityByStrategyOneSide) SetReserveAccount(reserve ag_solanago.PublicKey) *AddLiquidityByStrategyOneSide { + inst.AccountMetaSlice[4] = ag_solanago.Meta(reserve).WRITE() + return inst +} + +// GetReserveAccount gets the "reserve" account. +func (inst *AddLiquidityByStrategyOneSide) GetReserveAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetTokenMintAccount sets the "tokenMint" account. +func (inst *AddLiquidityByStrategyOneSide) SetTokenMintAccount(tokenMint ag_solanago.PublicKey) *AddLiquidityByStrategyOneSide { + inst.AccountMetaSlice[5] = ag_solanago.Meta(tokenMint) + return inst +} + +// GetTokenMintAccount gets the "tokenMint" account. +func (inst *AddLiquidityByStrategyOneSide) GetTokenMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetBinArrayLowerAccount sets the "binArrayLower" account. +func (inst *AddLiquidityByStrategyOneSide) SetBinArrayLowerAccount(binArrayLower ag_solanago.PublicKey) *AddLiquidityByStrategyOneSide { + inst.AccountMetaSlice[6] = ag_solanago.Meta(binArrayLower).WRITE() + return inst +} + +// GetBinArrayLowerAccount gets the "binArrayLower" account. +func (inst *AddLiquidityByStrategyOneSide) GetBinArrayLowerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetBinArrayUpperAccount sets the "binArrayUpper" account. +func (inst *AddLiquidityByStrategyOneSide) SetBinArrayUpperAccount(binArrayUpper ag_solanago.PublicKey) *AddLiquidityByStrategyOneSide { + inst.AccountMetaSlice[7] = ag_solanago.Meta(binArrayUpper).WRITE() + return inst +} + +// GetBinArrayUpperAccount gets the "binArrayUpper" account. +func (inst *AddLiquidityByStrategyOneSide) GetBinArrayUpperAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetSenderAccount sets the "sender" account. +func (inst *AddLiquidityByStrategyOneSide) SetSenderAccount(sender ag_solanago.PublicKey) *AddLiquidityByStrategyOneSide { + inst.AccountMetaSlice[8] = ag_solanago.Meta(sender).SIGNER() + return inst +} + +// GetSenderAccount gets the "sender" account. +func (inst *AddLiquidityByStrategyOneSide) GetSenderAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *AddLiquidityByStrategyOneSide) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *AddLiquidityByStrategyOneSide { + inst.AccountMetaSlice[9] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *AddLiquidityByStrategyOneSide) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetEventAuthorityAccount sets the "eventAuthority" account. +func (inst *AddLiquidityByStrategyOneSide) SetEventAuthorityAccount(eventAuthority ag_solanago.PublicKey) *AddLiquidityByStrategyOneSide { + inst.AccountMetaSlice[10] = ag_solanago.Meta(eventAuthority) + return inst +} + +// GetEventAuthorityAccount gets the "eventAuthority" account. +func (inst *AddLiquidityByStrategyOneSide) GetEventAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetProgramAccount sets the "program" account. +func (inst *AddLiquidityByStrategyOneSide) SetProgramAccount(program ag_solanago.PublicKey) *AddLiquidityByStrategyOneSide { + inst.AccountMetaSlice[11] = ag_solanago.Meta(program) + return inst +} + +// GetProgramAccount gets the "program" account. +func (inst *AddLiquidityByStrategyOneSide) GetProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +func (inst AddLiquidityByStrategyOneSide) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_AddLiquidityByStrategyOneSide, + }} +} + +// 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 AddLiquidityByStrategyOneSide) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *AddLiquidityByStrategyOneSide) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.LiquidityParameter == nil { + return errors.New("LiquidityParameter parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Position is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.LbPair is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.BinArrayBitmapExtension is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.UserToken is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.Reserve is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.TokenMint is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.BinArrayLower is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.BinArrayUpper is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.Sender is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.EventAuthority is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.Program is not set") + } + } + return nil +} + +func (inst *AddLiquidityByStrategyOneSide) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("AddLiquidityByStrategyOneSide")). + // + 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("LiquidityParameter", *inst.LiquidityParameter)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=12]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" position", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" lbPair", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta("binArrayBitmapExtension", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" userToken", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" reserve", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" tokenMint", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" binArrayLower", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" binArrayUpper", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" sender", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" eventAuthority", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" program", inst.AccountMetaSlice.Get(11))) + }) + }) + }) +} + +func (obj AddLiquidityByStrategyOneSide) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `LiquidityParameter` param: + err = encoder.Encode(obj.LiquidityParameter) + if err != nil { + return err + } + return nil +} +func (obj *AddLiquidityByStrategyOneSide) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `LiquidityParameter`: + err = decoder.Decode(&obj.LiquidityParameter) + if err != nil { + return err + } + return nil +} + +// NewAddLiquidityByStrategyOneSideInstruction declares a new AddLiquidityByStrategyOneSide instruction with the provided parameters and accounts. +func NewAddLiquidityByStrategyOneSideInstruction( + // Parameters: + liquidityParameter LiquidityParameterByStrategyOneSide, + // Accounts: + position ag_solanago.PublicKey, + lbPair ag_solanago.PublicKey, + binArrayBitmapExtension ag_solanago.PublicKey, + userToken ag_solanago.PublicKey, + reserve ag_solanago.PublicKey, + tokenMint ag_solanago.PublicKey, + binArrayLower ag_solanago.PublicKey, + binArrayUpper ag_solanago.PublicKey, + sender ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + eventAuthority ag_solanago.PublicKey, + program ag_solanago.PublicKey) *AddLiquidityByStrategyOneSide { + return NewAddLiquidityByStrategyOneSideInstructionBuilder(). + SetLiquidityParameter(liquidityParameter). + SetPositionAccount(position). + SetLbPairAccount(lbPair). + SetBinArrayBitmapExtensionAccount(binArrayBitmapExtension). + SetUserTokenAccount(userToken). + SetReserveAccount(reserve). + SetTokenMintAccount(tokenMint). + SetBinArrayLowerAccount(binArrayLower). + SetBinArrayUpperAccount(binArrayUpper). + SetSenderAccount(sender). + SetTokenProgramAccount(tokenProgram). + SetEventAuthorityAccount(eventAuthority). + SetProgramAccount(program) +} diff --git a/programs/meteoradlmm/AddLiquidityByStrategyOneSide_test.go b/programs/meteoradlmm/AddLiquidityByStrategyOneSide_test.go new file mode 100644 index 00000000..659bf3be --- /dev/null +++ b/programs/meteoradlmm/AddLiquidityByStrategyOneSide_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_AddLiquidityByStrategyOneSide(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("AddLiquidityByStrategyOneSide"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(AddLiquidityByStrategyOneSide) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(AddLiquidityByStrategyOneSide) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/AddLiquidityByStrategy_test.go b/programs/meteoradlmm/AddLiquidityByStrategy_test.go new file mode 100644 index 00000000..e85de987 --- /dev/null +++ b/programs/meteoradlmm/AddLiquidityByStrategy_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_AddLiquidityByStrategy(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("AddLiquidityByStrategy"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(AddLiquidityByStrategy) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(AddLiquidityByStrategy) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/AddLiquidityByWeight.go b/programs/meteoradlmm/AddLiquidityByWeight.go new file mode 100644 index 00000000..8d9edce4 --- /dev/null +++ b/programs/meteoradlmm/AddLiquidityByWeight.go @@ -0,0 +1,412 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// AddLiquidityByWeight is the `addLiquidityByWeight` instruction. +type AddLiquidityByWeight struct { + LiquidityParameter *LiquidityParameterByWeight + + // [0] = [WRITE] position + // + // [1] = [WRITE] lbPair + // + // [2] = [WRITE] binArrayBitmapExtension + // + // [3] = [WRITE] userTokenX + // + // [4] = [WRITE] userTokenY + // + // [5] = [WRITE] reserveX + // + // [6] = [WRITE] reserveY + // + // [7] = [] tokenXMint + // + // [8] = [] tokenYMint + // + // [9] = [WRITE] binArrayLower + // + // [10] = [WRITE] binArrayUpper + // + // [11] = [SIGNER] sender + // + // [12] = [] tokenXProgram + // + // [13] = [] tokenYProgram + // + // [14] = [] eventAuthority + // + // [15] = [] program + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewAddLiquidityByWeightInstructionBuilder creates a new `AddLiquidityByWeight` instruction builder. +func NewAddLiquidityByWeightInstructionBuilder() *AddLiquidityByWeight { + nd := &AddLiquidityByWeight{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 16), + } + return nd +} + +// SetLiquidityParameter sets the "liquidityParameter" parameter. +func (inst *AddLiquidityByWeight) SetLiquidityParameter(liquidityParameter LiquidityParameterByWeight) *AddLiquidityByWeight { + inst.LiquidityParameter = &liquidityParameter + return inst +} + +// SetPositionAccount sets the "position" account. +func (inst *AddLiquidityByWeight) SetPositionAccount(position ag_solanago.PublicKey) *AddLiquidityByWeight { + inst.AccountMetaSlice[0] = ag_solanago.Meta(position).WRITE() + return inst +} + +// GetPositionAccount gets the "position" account. +func (inst *AddLiquidityByWeight) GetPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetLbPairAccount sets the "lbPair" account. +func (inst *AddLiquidityByWeight) SetLbPairAccount(lbPair ag_solanago.PublicKey) *AddLiquidityByWeight { + inst.AccountMetaSlice[1] = ag_solanago.Meta(lbPair).WRITE() + return inst +} + +// GetLbPairAccount gets the "lbPair" account. +func (inst *AddLiquidityByWeight) GetLbPairAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetBinArrayBitmapExtensionAccount sets the "binArrayBitmapExtension" account. +func (inst *AddLiquidityByWeight) SetBinArrayBitmapExtensionAccount(binArrayBitmapExtension ag_solanago.PublicKey) *AddLiquidityByWeight { + inst.AccountMetaSlice[2] = ag_solanago.Meta(binArrayBitmapExtension).WRITE() + return inst +} + +// GetBinArrayBitmapExtensionAccount gets the "binArrayBitmapExtension" account. +func (inst *AddLiquidityByWeight) GetBinArrayBitmapExtensionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetUserTokenXAccount sets the "userTokenX" account. +func (inst *AddLiquidityByWeight) SetUserTokenXAccount(userTokenX ag_solanago.PublicKey) *AddLiquidityByWeight { + inst.AccountMetaSlice[3] = ag_solanago.Meta(userTokenX).WRITE() + return inst +} + +// GetUserTokenXAccount gets the "userTokenX" account. +func (inst *AddLiquidityByWeight) GetUserTokenXAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetUserTokenYAccount sets the "userTokenY" account. +func (inst *AddLiquidityByWeight) SetUserTokenYAccount(userTokenY ag_solanago.PublicKey) *AddLiquidityByWeight { + inst.AccountMetaSlice[4] = ag_solanago.Meta(userTokenY).WRITE() + return inst +} + +// GetUserTokenYAccount gets the "userTokenY" account. +func (inst *AddLiquidityByWeight) GetUserTokenYAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetReserveXAccount sets the "reserveX" account. +func (inst *AddLiquidityByWeight) SetReserveXAccount(reserveX ag_solanago.PublicKey) *AddLiquidityByWeight { + inst.AccountMetaSlice[5] = ag_solanago.Meta(reserveX).WRITE() + return inst +} + +// GetReserveXAccount gets the "reserveX" account. +func (inst *AddLiquidityByWeight) GetReserveXAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetReserveYAccount sets the "reserveY" account. +func (inst *AddLiquidityByWeight) SetReserveYAccount(reserveY ag_solanago.PublicKey) *AddLiquidityByWeight { + inst.AccountMetaSlice[6] = ag_solanago.Meta(reserveY).WRITE() + return inst +} + +// GetReserveYAccount gets the "reserveY" account. +func (inst *AddLiquidityByWeight) GetReserveYAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetTokenXMintAccount sets the "tokenXMint" account. +func (inst *AddLiquidityByWeight) SetTokenXMintAccount(tokenXMint ag_solanago.PublicKey) *AddLiquidityByWeight { + inst.AccountMetaSlice[7] = ag_solanago.Meta(tokenXMint) + return inst +} + +// GetTokenXMintAccount gets the "tokenXMint" account. +func (inst *AddLiquidityByWeight) GetTokenXMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetTokenYMintAccount sets the "tokenYMint" account. +func (inst *AddLiquidityByWeight) SetTokenYMintAccount(tokenYMint ag_solanago.PublicKey) *AddLiquidityByWeight { + inst.AccountMetaSlice[8] = ag_solanago.Meta(tokenYMint) + return inst +} + +// GetTokenYMintAccount gets the "tokenYMint" account. +func (inst *AddLiquidityByWeight) GetTokenYMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetBinArrayLowerAccount sets the "binArrayLower" account. +func (inst *AddLiquidityByWeight) SetBinArrayLowerAccount(binArrayLower ag_solanago.PublicKey) *AddLiquidityByWeight { + inst.AccountMetaSlice[9] = ag_solanago.Meta(binArrayLower).WRITE() + return inst +} + +// GetBinArrayLowerAccount gets the "binArrayLower" account. +func (inst *AddLiquidityByWeight) GetBinArrayLowerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetBinArrayUpperAccount sets the "binArrayUpper" account. +func (inst *AddLiquidityByWeight) SetBinArrayUpperAccount(binArrayUpper ag_solanago.PublicKey) *AddLiquidityByWeight { + inst.AccountMetaSlice[10] = ag_solanago.Meta(binArrayUpper).WRITE() + return inst +} + +// GetBinArrayUpperAccount gets the "binArrayUpper" account. +func (inst *AddLiquidityByWeight) GetBinArrayUpperAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetSenderAccount sets the "sender" account. +func (inst *AddLiquidityByWeight) SetSenderAccount(sender ag_solanago.PublicKey) *AddLiquidityByWeight { + inst.AccountMetaSlice[11] = ag_solanago.Meta(sender).SIGNER() + return inst +} + +// GetSenderAccount gets the "sender" account. +func (inst *AddLiquidityByWeight) GetSenderAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetTokenXProgramAccount sets the "tokenXProgram" account. +func (inst *AddLiquidityByWeight) SetTokenXProgramAccount(tokenXProgram ag_solanago.PublicKey) *AddLiquidityByWeight { + inst.AccountMetaSlice[12] = ag_solanago.Meta(tokenXProgram) + return inst +} + +// GetTokenXProgramAccount gets the "tokenXProgram" account. +func (inst *AddLiquidityByWeight) GetTokenXProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetTokenYProgramAccount sets the "tokenYProgram" account. +func (inst *AddLiquidityByWeight) SetTokenYProgramAccount(tokenYProgram ag_solanago.PublicKey) *AddLiquidityByWeight { + inst.AccountMetaSlice[13] = ag_solanago.Meta(tokenYProgram) + return inst +} + +// GetTokenYProgramAccount gets the "tokenYProgram" account. +func (inst *AddLiquidityByWeight) GetTokenYProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetEventAuthorityAccount sets the "eventAuthority" account. +func (inst *AddLiquidityByWeight) SetEventAuthorityAccount(eventAuthority ag_solanago.PublicKey) *AddLiquidityByWeight { + inst.AccountMetaSlice[14] = ag_solanago.Meta(eventAuthority) + return inst +} + +// GetEventAuthorityAccount gets the "eventAuthority" account. +func (inst *AddLiquidityByWeight) GetEventAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +// SetProgramAccount sets the "program" account. +func (inst *AddLiquidityByWeight) SetProgramAccount(program ag_solanago.PublicKey) *AddLiquidityByWeight { + inst.AccountMetaSlice[15] = ag_solanago.Meta(program) + return inst +} + +// GetProgramAccount gets the "program" account. +func (inst *AddLiquidityByWeight) GetProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(15) +} + +func (inst AddLiquidityByWeight) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_AddLiquidityByWeight, + }} +} + +// 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 AddLiquidityByWeight) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *AddLiquidityByWeight) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.LiquidityParameter == nil { + return errors.New("LiquidityParameter parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Position is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.LbPair is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.BinArrayBitmapExtension is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.UserTokenX is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.UserTokenY is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.ReserveX is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.ReserveY is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.TokenXMint is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.TokenYMint is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.BinArrayLower is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.BinArrayUpper is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.Sender is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.TokenXProgram is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.TokenYProgram is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.EventAuthority is not set") + } + if inst.AccountMetaSlice[15] == nil { + return errors.New("accounts.Program is not set") + } + } + return nil +} + +func (inst *AddLiquidityByWeight) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("AddLiquidityByWeight")). + // + 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("LiquidityParameter", *inst.LiquidityParameter)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=16]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" position", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" lbPair", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta("binArrayBitmapExtension", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" userTokenX", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" userTokenY", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" reserveX", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" reserveY", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" tokenXMint", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" tokenYMint", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" binArrayLower", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" binArrayUpper", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" sender", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" tokenXProgram", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" tokenYProgram", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta(" eventAuthority", inst.AccountMetaSlice.Get(14))) + accountsBranch.Child(ag_format.Meta(" program", inst.AccountMetaSlice.Get(15))) + }) + }) + }) +} + +func (obj AddLiquidityByWeight) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `LiquidityParameter` param: + err = encoder.Encode(obj.LiquidityParameter) + if err != nil { + return err + } + return nil +} +func (obj *AddLiquidityByWeight) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `LiquidityParameter`: + err = decoder.Decode(&obj.LiquidityParameter) + if err != nil { + return err + } + return nil +} + +// NewAddLiquidityByWeightInstruction declares a new AddLiquidityByWeight instruction with the provided parameters and accounts. +func NewAddLiquidityByWeightInstruction( + // Parameters: + liquidityParameter LiquidityParameterByWeight, + // Accounts: + position ag_solanago.PublicKey, + lbPair ag_solanago.PublicKey, + binArrayBitmapExtension ag_solanago.PublicKey, + userTokenX ag_solanago.PublicKey, + userTokenY ag_solanago.PublicKey, + reserveX ag_solanago.PublicKey, + reserveY ag_solanago.PublicKey, + tokenXMint ag_solanago.PublicKey, + tokenYMint ag_solanago.PublicKey, + binArrayLower ag_solanago.PublicKey, + binArrayUpper ag_solanago.PublicKey, + sender ag_solanago.PublicKey, + tokenXProgram ag_solanago.PublicKey, + tokenYProgram ag_solanago.PublicKey, + eventAuthority ag_solanago.PublicKey, + program ag_solanago.PublicKey) *AddLiquidityByWeight { + return NewAddLiquidityByWeightInstructionBuilder(). + SetLiquidityParameter(liquidityParameter). + SetPositionAccount(position). + SetLbPairAccount(lbPair). + SetBinArrayBitmapExtensionAccount(binArrayBitmapExtension). + SetUserTokenXAccount(userTokenX). + SetUserTokenYAccount(userTokenY). + SetReserveXAccount(reserveX). + SetReserveYAccount(reserveY). + SetTokenXMintAccount(tokenXMint). + SetTokenYMintAccount(tokenYMint). + SetBinArrayLowerAccount(binArrayLower). + SetBinArrayUpperAccount(binArrayUpper). + SetSenderAccount(sender). + SetTokenXProgramAccount(tokenXProgram). + SetTokenYProgramAccount(tokenYProgram). + SetEventAuthorityAccount(eventAuthority). + SetProgramAccount(program) +} diff --git a/programs/meteoradlmm/AddLiquidityByWeight_test.go b/programs/meteoradlmm/AddLiquidityByWeight_test.go new file mode 100644 index 00000000..51cd5ba9 --- /dev/null +++ b/programs/meteoradlmm/AddLiquidityByWeight_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_AddLiquidityByWeight(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("AddLiquidityByWeight"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(AddLiquidityByWeight) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(AddLiquidityByWeight) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/AddLiquidityOneSide.go b/programs/meteoradlmm/AddLiquidityOneSide.go new file mode 100644 index 00000000..9c578e3d --- /dev/null +++ b/programs/meteoradlmm/AddLiquidityOneSide.go @@ -0,0 +1,336 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// AddLiquidityOneSide is the `addLiquidityOneSide` instruction. +type AddLiquidityOneSide struct { + LiquidityParameter *LiquidityOneSideParameter + + // [0] = [WRITE] position + // + // [1] = [WRITE] lbPair + // + // [2] = [WRITE] binArrayBitmapExtension + // + // [3] = [WRITE] userToken + // + // [4] = [WRITE] reserve + // + // [5] = [] tokenMint + // + // [6] = [WRITE] binArrayLower + // + // [7] = [WRITE] binArrayUpper + // + // [8] = [SIGNER] sender + // + // [9] = [] tokenProgram + // + // [10] = [] eventAuthority + // + // [11] = [] program + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewAddLiquidityOneSideInstructionBuilder creates a new `AddLiquidityOneSide` instruction builder. +func NewAddLiquidityOneSideInstructionBuilder() *AddLiquidityOneSide { + nd := &AddLiquidityOneSide{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 12), + } + return nd +} + +// SetLiquidityParameter sets the "liquidityParameter" parameter. +func (inst *AddLiquidityOneSide) SetLiquidityParameter(liquidityParameter LiquidityOneSideParameter) *AddLiquidityOneSide { + inst.LiquidityParameter = &liquidityParameter + return inst +} + +// SetPositionAccount sets the "position" account. +func (inst *AddLiquidityOneSide) SetPositionAccount(position ag_solanago.PublicKey) *AddLiquidityOneSide { + inst.AccountMetaSlice[0] = ag_solanago.Meta(position).WRITE() + return inst +} + +// GetPositionAccount gets the "position" account. +func (inst *AddLiquidityOneSide) GetPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetLbPairAccount sets the "lbPair" account. +func (inst *AddLiquidityOneSide) SetLbPairAccount(lbPair ag_solanago.PublicKey) *AddLiquidityOneSide { + inst.AccountMetaSlice[1] = ag_solanago.Meta(lbPair).WRITE() + return inst +} + +// GetLbPairAccount gets the "lbPair" account. +func (inst *AddLiquidityOneSide) GetLbPairAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetBinArrayBitmapExtensionAccount sets the "binArrayBitmapExtension" account. +func (inst *AddLiquidityOneSide) SetBinArrayBitmapExtensionAccount(binArrayBitmapExtension ag_solanago.PublicKey) *AddLiquidityOneSide { + inst.AccountMetaSlice[2] = ag_solanago.Meta(binArrayBitmapExtension).WRITE() + return inst +} + +// GetBinArrayBitmapExtensionAccount gets the "binArrayBitmapExtension" account. +func (inst *AddLiquidityOneSide) GetBinArrayBitmapExtensionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetUserTokenAccount sets the "userToken" account. +func (inst *AddLiquidityOneSide) SetUserTokenAccount(userToken ag_solanago.PublicKey) *AddLiquidityOneSide { + inst.AccountMetaSlice[3] = ag_solanago.Meta(userToken).WRITE() + return inst +} + +// GetUserTokenAccount gets the "userToken" account. +func (inst *AddLiquidityOneSide) GetUserTokenAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetReserveAccount sets the "reserve" account. +func (inst *AddLiquidityOneSide) SetReserveAccount(reserve ag_solanago.PublicKey) *AddLiquidityOneSide { + inst.AccountMetaSlice[4] = ag_solanago.Meta(reserve).WRITE() + return inst +} + +// GetReserveAccount gets the "reserve" account. +func (inst *AddLiquidityOneSide) GetReserveAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetTokenMintAccount sets the "tokenMint" account. +func (inst *AddLiquidityOneSide) SetTokenMintAccount(tokenMint ag_solanago.PublicKey) *AddLiquidityOneSide { + inst.AccountMetaSlice[5] = ag_solanago.Meta(tokenMint) + return inst +} + +// GetTokenMintAccount gets the "tokenMint" account. +func (inst *AddLiquidityOneSide) GetTokenMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetBinArrayLowerAccount sets the "binArrayLower" account. +func (inst *AddLiquidityOneSide) SetBinArrayLowerAccount(binArrayLower ag_solanago.PublicKey) *AddLiquidityOneSide { + inst.AccountMetaSlice[6] = ag_solanago.Meta(binArrayLower).WRITE() + return inst +} + +// GetBinArrayLowerAccount gets the "binArrayLower" account. +func (inst *AddLiquidityOneSide) GetBinArrayLowerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetBinArrayUpperAccount sets the "binArrayUpper" account. +func (inst *AddLiquidityOneSide) SetBinArrayUpperAccount(binArrayUpper ag_solanago.PublicKey) *AddLiquidityOneSide { + inst.AccountMetaSlice[7] = ag_solanago.Meta(binArrayUpper).WRITE() + return inst +} + +// GetBinArrayUpperAccount gets the "binArrayUpper" account. +func (inst *AddLiquidityOneSide) GetBinArrayUpperAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetSenderAccount sets the "sender" account. +func (inst *AddLiquidityOneSide) SetSenderAccount(sender ag_solanago.PublicKey) *AddLiquidityOneSide { + inst.AccountMetaSlice[8] = ag_solanago.Meta(sender).SIGNER() + return inst +} + +// GetSenderAccount gets the "sender" account. +func (inst *AddLiquidityOneSide) GetSenderAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *AddLiquidityOneSide) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *AddLiquidityOneSide { + inst.AccountMetaSlice[9] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *AddLiquidityOneSide) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetEventAuthorityAccount sets the "eventAuthority" account. +func (inst *AddLiquidityOneSide) SetEventAuthorityAccount(eventAuthority ag_solanago.PublicKey) *AddLiquidityOneSide { + inst.AccountMetaSlice[10] = ag_solanago.Meta(eventAuthority) + return inst +} + +// GetEventAuthorityAccount gets the "eventAuthority" account. +func (inst *AddLiquidityOneSide) GetEventAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetProgramAccount sets the "program" account. +func (inst *AddLiquidityOneSide) SetProgramAccount(program ag_solanago.PublicKey) *AddLiquidityOneSide { + inst.AccountMetaSlice[11] = ag_solanago.Meta(program) + return inst +} + +// GetProgramAccount gets the "program" account. +func (inst *AddLiquidityOneSide) GetProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +func (inst AddLiquidityOneSide) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_AddLiquidityOneSide, + }} +} + +// 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 AddLiquidityOneSide) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *AddLiquidityOneSide) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.LiquidityParameter == nil { + return errors.New("LiquidityParameter parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Position is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.LbPair is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.BinArrayBitmapExtension is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.UserToken is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.Reserve is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.TokenMint is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.BinArrayLower is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.BinArrayUpper is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.Sender is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.EventAuthority is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.Program is not set") + } + } + return nil +} + +func (inst *AddLiquidityOneSide) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("AddLiquidityOneSide")). + // + 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("LiquidityParameter", *inst.LiquidityParameter)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=12]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" position", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" lbPair", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta("binArrayBitmapExtension", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" userToken", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" reserve", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" tokenMint", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" binArrayLower", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" binArrayUpper", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" sender", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" eventAuthority", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" program", inst.AccountMetaSlice.Get(11))) + }) + }) + }) +} + +func (obj AddLiquidityOneSide) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `LiquidityParameter` param: + err = encoder.Encode(obj.LiquidityParameter) + if err != nil { + return err + } + return nil +} +func (obj *AddLiquidityOneSide) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `LiquidityParameter`: + err = decoder.Decode(&obj.LiquidityParameter) + if err != nil { + return err + } + return nil +} + +// NewAddLiquidityOneSideInstruction declares a new AddLiquidityOneSide instruction with the provided parameters and accounts. +func NewAddLiquidityOneSideInstruction( + // Parameters: + liquidityParameter LiquidityOneSideParameter, + // Accounts: + position ag_solanago.PublicKey, + lbPair ag_solanago.PublicKey, + binArrayBitmapExtension ag_solanago.PublicKey, + userToken ag_solanago.PublicKey, + reserve ag_solanago.PublicKey, + tokenMint ag_solanago.PublicKey, + binArrayLower ag_solanago.PublicKey, + binArrayUpper ag_solanago.PublicKey, + sender ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + eventAuthority ag_solanago.PublicKey, + program ag_solanago.PublicKey) *AddLiquidityOneSide { + return NewAddLiquidityOneSideInstructionBuilder(). + SetLiquidityParameter(liquidityParameter). + SetPositionAccount(position). + SetLbPairAccount(lbPair). + SetBinArrayBitmapExtensionAccount(binArrayBitmapExtension). + SetUserTokenAccount(userToken). + SetReserveAccount(reserve). + SetTokenMintAccount(tokenMint). + SetBinArrayLowerAccount(binArrayLower). + SetBinArrayUpperAccount(binArrayUpper). + SetSenderAccount(sender). + SetTokenProgramAccount(tokenProgram). + SetEventAuthorityAccount(eventAuthority). + SetProgramAccount(program) +} diff --git a/programs/meteoradlmm/AddLiquidityOneSidePrecise.go b/programs/meteoradlmm/AddLiquidityOneSidePrecise.go new file mode 100644 index 00000000..0be80d97 --- /dev/null +++ b/programs/meteoradlmm/AddLiquidityOneSidePrecise.go @@ -0,0 +1,336 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// AddLiquidityOneSidePrecise is the `addLiquidityOneSidePrecise` instruction. +type AddLiquidityOneSidePrecise struct { + Parameter *AddLiquiditySingleSidePreciseParameter + + // [0] = [WRITE] position + // + // [1] = [WRITE] lbPair + // + // [2] = [WRITE] binArrayBitmapExtension + // + // [3] = [WRITE] userToken + // + // [4] = [WRITE] reserve + // + // [5] = [] tokenMint + // + // [6] = [WRITE] binArrayLower + // + // [7] = [WRITE] binArrayUpper + // + // [8] = [SIGNER] sender + // + // [9] = [] tokenProgram + // + // [10] = [] eventAuthority + // + // [11] = [] program + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewAddLiquidityOneSidePreciseInstructionBuilder creates a new `AddLiquidityOneSidePrecise` instruction builder. +func NewAddLiquidityOneSidePreciseInstructionBuilder() *AddLiquidityOneSidePrecise { + nd := &AddLiquidityOneSidePrecise{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 12), + } + return nd +} + +// SetParameter sets the "parameter" parameter. +func (inst *AddLiquidityOneSidePrecise) SetParameter(parameter AddLiquiditySingleSidePreciseParameter) *AddLiquidityOneSidePrecise { + inst.Parameter = ¶meter + return inst +} + +// SetPositionAccount sets the "position" account. +func (inst *AddLiquidityOneSidePrecise) SetPositionAccount(position ag_solanago.PublicKey) *AddLiquidityOneSidePrecise { + inst.AccountMetaSlice[0] = ag_solanago.Meta(position).WRITE() + return inst +} + +// GetPositionAccount gets the "position" account. +func (inst *AddLiquidityOneSidePrecise) GetPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetLbPairAccount sets the "lbPair" account. +func (inst *AddLiquidityOneSidePrecise) SetLbPairAccount(lbPair ag_solanago.PublicKey) *AddLiquidityOneSidePrecise { + inst.AccountMetaSlice[1] = ag_solanago.Meta(lbPair).WRITE() + return inst +} + +// GetLbPairAccount gets the "lbPair" account. +func (inst *AddLiquidityOneSidePrecise) GetLbPairAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetBinArrayBitmapExtensionAccount sets the "binArrayBitmapExtension" account. +func (inst *AddLiquidityOneSidePrecise) SetBinArrayBitmapExtensionAccount(binArrayBitmapExtension ag_solanago.PublicKey) *AddLiquidityOneSidePrecise { + inst.AccountMetaSlice[2] = ag_solanago.Meta(binArrayBitmapExtension).WRITE() + return inst +} + +// GetBinArrayBitmapExtensionAccount gets the "binArrayBitmapExtension" account. +func (inst *AddLiquidityOneSidePrecise) GetBinArrayBitmapExtensionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetUserTokenAccount sets the "userToken" account. +func (inst *AddLiquidityOneSidePrecise) SetUserTokenAccount(userToken ag_solanago.PublicKey) *AddLiquidityOneSidePrecise { + inst.AccountMetaSlice[3] = ag_solanago.Meta(userToken).WRITE() + return inst +} + +// GetUserTokenAccount gets the "userToken" account. +func (inst *AddLiquidityOneSidePrecise) GetUserTokenAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetReserveAccount sets the "reserve" account. +func (inst *AddLiquidityOneSidePrecise) SetReserveAccount(reserve ag_solanago.PublicKey) *AddLiquidityOneSidePrecise { + inst.AccountMetaSlice[4] = ag_solanago.Meta(reserve).WRITE() + return inst +} + +// GetReserveAccount gets the "reserve" account. +func (inst *AddLiquidityOneSidePrecise) GetReserveAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetTokenMintAccount sets the "tokenMint" account. +func (inst *AddLiquidityOneSidePrecise) SetTokenMintAccount(tokenMint ag_solanago.PublicKey) *AddLiquidityOneSidePrecise { + inst.AccountMetaSlice[5] = ag_solanago.Meta(tokenMint) + return inst +} + +// GetTokenMintAccount gets the "tokenMint" account. +func (inst *AddLiquidityOneSidePrecise) GetTokenMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetBinArrayLowerAccount sets the "binArrayLower" account. +func (inst *AddLiquidityOneSidePrecise) SetBinArrayLowerAccount(binArrayLower ag_solanago.PublicKey) *AddLiquidityOneSidePrecise { + inst.AccountMetaSlice[6] = ag_solanago.Meta(binArrayLower).WRITE() + return inst +} + +// GetBinArrayLowerAccount gets the "binArrayLower" account. +func (inst *AddLiquidityOneSidePrecise) GetBinArrayLowerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetBinArrayUpperAccount sets the "binArrayUpper" account. +func (inst *AddLiquidityOneSidePrecise) SetBinArrayUpperAccount(binArrayUpper ag_solanago.PublicKey) *AddLiquidityOneSidePrecise { + inst.AccountMetaSlice[7] = ag_solanago.Meta(binArrayUpper).WRITE() + return inst +} + +// GetBinArrayUpperAccount gets the "binArrayUpper" account. +func (inst *AddLiquidityOneSidePrecise) GetBinArrayUpperAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetSenderAccount sets the "sender" account. +func (inst *AddLiquidityOneSidePrecise) SetSenderAccount(sender ag_solanago.PublicKey) *AddLiquidityOneSidePrecise { + inst.AccountMetaSlice[8] = ag_solanago.Meta(sender).SIGNER() + return inst +} + +// GetSenderAccount gets the "sender" account. +func (inst *AddLiquidityOneSidePrecise) GetSenderAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *AddLiquidityOneSidePrecise) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *AddLiquidityOneSidePrecise { + inst.AccountMetaSlice[9] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *AddLiquidityOneSidePrecise) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetEventAuthorityAccount sets the "eventAuthority" account. +func (inst *AddLiquidityOneSidePrecise) SetEventAuthorityAccount(eventAuthority ag_solanago.PublicKey) *AddLiquidityOneSidePrecise { + inst.AccountMetaSlice[10] = ag_solanago.Meta(eventAuthority) + return inst +} + +// GetEventAuthorityAccount gets the "eventAuthority" account. +func (inst *AddLiquidityOneSidePrecise) GetEventAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetProgramAccount sets the "program" account. +func (inst *AddLiquidityOneSidePrecise) SetProgramAccount(program ag_solanago.PublicKey) *AddLiquidityOneSidePrecise { + inst.AccountMetaSlice[11] = ag_solanago.Meta(program) + return inst +} + +// GetProgramAccount gets the "program" account. +func (inst *AddLiquidityOneSidePrecise) GetProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +func (inst AddLiquidityOneSidePrecise) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_AddLiquidityOneSidePrecise, + }} +} + +// 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 AddLiquidityOneSidePrecise) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *AddLiquidityOneSidePrecise) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.Parameter == nil { + return errors.New("Parameter parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Position is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.LbPair is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.BinArrayBitmapExtension is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.UserToken is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.Reserve is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.TokenMint is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.BinArrayLower is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.BinArrayUpper is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.Sender is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.EventAuthority is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.Program is not set") + } + } + return nil +} + +func (inst *AddLiquidityOneSidePrecise) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("AddLiquidityOneSidePrecise")). + // + 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("Parameter", *inst.Parameter)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=12]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" position", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" lbPair", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta("binArrayBitmapExtension", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" userToken", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" reserve", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" tokenMint", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" binArrayLower", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" binArrayUpper", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" sender", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" eventAuthority", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" program", inst.AccountMetaSlice.Get(11))) + }) + }) + }) +} + +func (obj AddLiquidityOneSidePrecise) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Parameter` param: + err = encoder.Encode(obj.Parameter) + if err != nil { + return err + } + return nil +} +func (obj *AddLiquidityOneSidePrecise) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Parameter`: + err = decoder.Decode(&obj.Parameter) + if err != nil { + return err + } + return nil +} + +// NewAddLiquidityOneSidePreciseInstruction declares a new AddLiquidityOneSidePrecise instruction with the provided parameters and accounts. +func NewAddLiquidityOneSidePreciseInstruction( + // Parameters: + parameter AddLiquiditySingleSidePreciseParameter, + // Accounts: + position ag_solanago.PublicKey, + lbPair ag_solanago.PublicKey, + binArrayBitmapExtension ag_solanago.PublicKey, + userToken ag_solanago.PublicKey, + reserve ag_solanago.PublicKey, + tokenMint ag_solanago.PublicKey, + binArrayLower ag_solanago.PublicKey, + binArrayUpper ag_solanago.PublicKey, + sender ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + eventAuthority ag_solanago.PublicKey, + program ag_solanago.PublicKey) *AddLiquidityOneSidePrecise { + return NewAddLiquidityOneSidePreciseInstructionBuilder(). + SetParameter(parameter). + SetPositionAccount(position). + SetLbPairAccount(lbPair). + SetBinArrayBitmapExtensionAccount(binArrayBitmapExtension). + SetUserTokenAccount(userToken). + SetReserveAccount(reserve). + SetTokenMintAccount(tokenMint). + SetBinArrayLowerAccount(binArrayLower). + SetBinArrayUpperAccount(binArrayUpper). + SetSenderAccount(sender). + SetTokenProgramAccount(tokenProgram). + SetEventAuthorityAccount(eventAuthority). + SetProgramAccount(program) +} diff --git a/programs/meteoradlmm/AddLiquidityOneSidePrecise_test.go b/programs/meteoradlmm/AddLiquidityOneSidePrecise_test.go new file mode 100644 index 00000000..10bf6914 --- /dev/null +++ b/programs/meteoradlmm/AddLiquidityOneSidePrecise_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_AddLiquidityOneSidePrecise(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("AddLiquidityOneSidePrecise"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(AddLiquidityOneSidePrecise) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(AddLiquidityOneSidePrecise) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/AddLiquidityOneSide_test.go b/programs/meteoradlmm/AddLiquidityOneSide_test.go new file mode 100644 index 00000000..45658fd6 --- /dev/null +++ b/programs/meteoradlmm/AddLiquidityOneSide_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_AddLiquidityOneSide(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("AddLiquidityOneSide"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(AddLiquidityOneSide) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(AddLiquidityOneSide) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/AddLiquidity_test.go b/programs/meteoradlmm/AddLiquidity_test.go new file mode 100644 index 00000000..7cf1e791 --- /dev/null +++ b/programs/meteoradlmm/AddLiquidity_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_AddLiquidity(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("AddLiquidity"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(AddLiquidity) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(AddLiquidity) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/ClaimFee.go b/programs/meteoradlmm/ClaimFee.go new file mode 100644 index 00000000..91b15f6d --- /dev/null +++ b/programs/meteoradlmm/ClaimFee.go @@ -0,0 +1,345 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// ClaimFee is the `claimFee` instruction. +type ClaimFee struct { + + // [0] = [WRITE] lbPair + // + // [1] = [WRITE] position + // + // [2] = [WRITE] binArrayLower + // + // [3] = [WRITE] binArrayUpper + // + // [4] = [SIGNER] sender + // + // [5] = [WRITE] reserveX + // + // [6] = [WRITE] reserveY + // + // [7] = [WRITE] userTokenX + // + // [8] = [WRITE] userTokenY + // + // [9] = [] tokenXMint + // + // [10] = [] tokenYMint + // + // [11] = [] tokenProgram + // + // [12] = [] eventAuthority + // + // [13] = [] program + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewClaimFeeInstructionBuilder creates a new `ClaimFee` instruction builder. +func NewClaimFeeInstructionBuilder() *ClaimFee { + nd := &ClaimFee{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 14), + } + return nd +} + +// SetLbPairAccount sets the "lbPair" account. +func (inst *ClaimFee) SetLbPairAccount(lbPair ag_solanago.PublicKey) *ClaimFee { + inst.AccountMetaSlice[0] = ag_solanago.Meta(lbPair).WRITE() + return inst +} + +// GetLbPairAccount gets the "lbPair" account. +func (inst *ClaimFee) GetLbPairAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetPositionAccount sets the "position" account. +func (inst *ClaimFee) SetPositionAccount(position ag_solanago.PublicKey) *ClaimFee { + inst.AccountMetaSlice[1] = ag_solanago.Meta(position).WRITE() + return inst +} + +// GetPositionAccount gets the "position" account. +func (inst *ClaimFee) GetPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetBinArrayLowerAccount sets the "binArrayLower" account. +func (inst *ClaimFee) SetBinArrayLowerAccount(binArrayLower ag_solanago.PublicKey) *ClaimFee { + inst.AccountMetaSlice[2] = ag_solanago.Meta(binArrayLower).WRITE() + return inst +} + +// GetBinArrayLowerAccount gets the "binArrayLower" account. +func (inst *ClaimFee) GetBinArrayLowerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetBinArrayUpperAccount sets the "binArrayUpper" account. +func (inst *ClaimFee) SetBinArrayUpperAccount(binArrayUpper ag_solanago.PublicKey) *ClaimFee { + inst.AccountMetaSlice[3] = ag_solanago.Meta(binArrayUpper).WRITE() + return inst +} + +// GetBinArrayUpperAccount gets the "binArrayUpper" account. +func (inst *ClaimFee) GetBinArrayUpperAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetSenderAccount sets the "sender" account. +func (inst *ClaimFee) SetSenderAccount(sender ag_solanago.PublicKey) *ClaimFee { + inst.AccountMetaSlice[4] = ag_solanago.Meta(sender).SIGNER() + return inst +} + +// GetSenderAccount gets the "sender" account. +func (inst *ClaimFee) GetSenderAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetReserveXAccount sets the "reserveX" account. +func (inst *ClaimFee) SetReserveXAccount(reserveX ag_solanago.PublicKey) *ClaimFee { + inst.AccountMetaSlice[5] = ag_solanago.Meta(reserveX).WRITE() + return inst +} + +// GetReserveXAccount gets the "reserveX" account. +func (inst *ClaimFee) GetReserveXAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetReserveYAccount sets the "reserveY" account. +func (inst *ClaimFee) SetReserveYAccount(reserveY ag_solanago.PublicKey) *ClaimFee { + inst.AccountMetaSlice[6] = ag_solanago.Meta(reserveY).WRITE() + return inst +} + +// GetReserveYAccount gets the "reserveY" account. +func (inst *ClaimFee) GetReserveYAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetUserTokenXAccount sets the "userTokenX" account. +func (inst *ClaimFee) SetUserTokenXAccount(userTokenX ag_solanago.PublicKey) *ClaimFee { + inst.AccountMetaSlice[7] = ag_solanago.Meta(userTokenX).WRITE() + return inst +} + +// GetUserTokenXAccount gets the "userTokenX" account. +func (inst *ClaimFee) GetUserTokenXAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetUserTokenYAccount sets the "userTokenY" account. +func (inst *ClaimFee) SetUserTokenYAccount(userTokenY ag_solanago.PublicKey) *ClaimFee { + inst.AccountMetaSlice[8] = ag_solanago.Meta(userTokenY).WRITE() + return inst +} + +// GetUserTokenYAccount gets the "userTokenY" account. +func (inst *ClaimFee) GetUserTokenYAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetTokenXMintAccount sets the "tokenXMint" account. +func (inst *ClaimFee) SetTokenXMintAccount(tokenXMint ag_solanago.PublicKey) *ClaimFee { + inst.AccountMetaSlice[9] = ag_solanago.Meta(tokenXMint) + return inst +} + +// GetTokenXMintAccount gets the "tokenXMint" account. +func (inst *ClaimFee) GetTokenXMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetTokenYMintAccount sets the "tokenYMint" account. +func (inst *ClaimFee) SetTokenYMintAccount(tokenYMint ag_solanago.PublicKey) *ClaimFee { + inst.AccountMetaSlice[10] = ag_solanago.Meta(tokenYMint) + return inst +} + +// GetTokenYMintAccount gets the "tokenYMint" account. +func (inst *ClaimFee) GetTokenYMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *ClaimFee) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *ClaimFee { + inst.AccountMetaSlice[11] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *ClaimFee) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetEventAuthorityAccount sets the "eventAuthority" account. +func (inst *ClaimFee) SetEventAuthorityAccount(eventAuthority ag_solanago.PublicKey) *ClaimFee { + inst.AccountMetaSlice[12] = ag_solanago.Meta(eventAuthority) + return inst +} + +// GetEventAuthorityAccount gets the "eventAuthority" account. +func (inst *ClaimFee) GetEventAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetProgramAccount sets the "program" account. +func (inst *ClaimFee) SetProgramAccount(program ag_solanago.PublicKey) *ClaimFee { + inst.AccountMetaSlice[13] = ag_solanago.Meta(program) + return inst +} + +// GetProgramAccount gets the "program" account. +func (inst *ClaimFee) GetProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +func (inst ClaimFee) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_ClaimFee, + }} +} + +// 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 ClaimFee) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *ClaimFee) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.LbPair is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Position is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.BinArrayLower is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.BinArrayUpper is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.Sender is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.ReserveX is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.ReserveY is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.UserTokenX is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.UserTokenY is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.TokenXMint is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.TokenYMint is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.EventAuthority is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.Program is not set") + } + } + return nil +} + +func (inst *ClaimFee) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("ClaimFee")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=14]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" lbPair", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" position", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" binArrayLower", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" binArrayUpper", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" sender", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" reserveX", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" reserveY", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" userTokenX", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" userTokenY", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" tokenXMint", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" tokenYMint", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta("eventAuthority", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" program", inst.AccountMetaSlice.Get(13))) + }) + }) + }) +} + +func (obj ClaimFee) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *ClaimFee) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewClaimFeeInstruction declares a new ClaimFee instruction with the provided parameters and accounts. +func NewClaimFeeInstruction( + // Accounts: + lbPair ag_solanago.PublicKey, + position ag_solanago.PublicKey, + binArrayLower ag_solanago.PublicKey, + binArrayUpper ag_solanago.PublicKey, + sender ag_solanago.PublicKey, + reserveX ag_solanago.PublicKey, + reserveY ag_solanago.PublicKey, + userTokenX ag_solanago.PublicKey, + userTokenY ag_solanago.PublicKey, + tokenXMint ag_solanago.PublicKey, + tokenYMint ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + eventAuthority ag_solanago.PublicKey, + program ag_solanago.PublicKey) *ClaimFee { + return NewClaimFeeInstructionBuilder(). + SetLbPairAccount(lbPair). + SetPositionAccount(position). + SetBinArrayLowerAccount(binArrayLower). + SetBinArrayUpperAccount(binArrayUpper). + SetSenderAccount(sender). + SetReserveXAccount(reserveX). + SetReserveYAccount(reserveY). + SetUserTokenXAccount(userTokenX). + SetUserTokenYAccount(userTokenY). + SetTokenXMintAccount(tokenXMint). + SetTokenYMintAccount(tokenYMint). + SetTokenProgramAccount(tokenProgram). + SetEventAuthorityAccount(eventAuthority). + SetProgramAccount(program) +} diff --git a/programs/meteoradlmm/ClaimFee_test.go b/programs/meteoradlmm/ClaimFee_test.go new file mode 100644 index 00000000..4d4b5ae4 --- /dev/null +++ b/programs/meteoradlmm/ClaimFee_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_ClaimFee(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("ClaimFee"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(ClaimFee) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(ClaimFee) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/ClaimReward.go b/programs/meteoradlmm/ClaimReward.go new file mode 100644 index 00000000..7c5a16de --- /dev/null +++ b/programs/meteoradlmm/ClaimReward.go @@ -0,0 +1,317 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// ClaimReward is the `claimReward` instruction. +type ClaimReward struct { + RewardIndex *uint64 + + // [0] = [WRITE] lbPair + // + // [1] = [WRITE] position + // + // [2] = [WRITE] binArrayLower + // + // [3] = [WRITE] binArrayUpper + // + // [4] = [SIGNER] sender + // + // [5] = [WRITE] rewardVault + // + // [6] = [] rewardMint + // + // [7] = [WRITE] userTokenAccount + // + // [8] = [] tokenProgram + // + // [9] = [] eventAuthority + // + // [10] = [] program + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewClaimRewardInstructionBuilder creates a new `ClaimReward` instruction builder. +func NewClaimRewardInstructionBuilder() *ClaimReward { + nd := &ClaimReward{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 11), + } + return nd +} + +// SetRewardIndex sets the "rewardIndex" parameter. +func (inst *ClaimReward) SetRewardIndex(rewardIndex uint64) *ClaimReward { + inst.RewardIndex = &rewardIndex + return inst +} + +// SetLbPairAccount sets the "lbPair" account. +func (inst *ClaimReward) SetLbPairAccount(lbPair ag_solanago.PublicKey) *ClaimReward { + inst.AccountMetaSlice[0] = ag_solanago.Meta(lbPair).WRITE() + return inst +} + +// GetLbPairAccount gets the "lbPair" account. +func (inst *ClaimReward) GetLbPairAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetPositionAccount sets the "position" account. +func (inst *ClaimReward) SetPositionAccount(position ag_solanago.PublicKey) *ClaimReward { + inst.AccountMetaSlice[1] = ag_solanago.Meta(position).WRITE() + return inst +} + +// GetPositionAccount gets the "position" account. +func (inst *ClaimReward) GetPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetBinArrayLowerAccount sets the "binArrayLower" account. +func (inst *ClaimReward) SetBinArrayLowerAccount(binArrayLower ag_solanago.PublicKey) *ClaimReward { + inst.AccountMetaSlice[2] = ag_solanago.Meta(binArrayLower).WRITE() + return inst +} + +// GetBinArrayLowerAccount gets the "binArrayLower" account. +func (inst *ClaimReward) GetBinArrayLowerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetBinArrayUpperAccount sets the "binArrayUpper" account. +func (inst *ClaimReward) SetBinArrayUpperAccount(binArrayUpper ag_solanago.PublicKey) *ClaimReward { + inst.AccountMetaSlice[3] = ag_solanago.Meta(binArrayUpper).WRITE() + return inst +} + +// GetBinArrayUpperAccount gets the "binArrayUpper" account. +func (inst *ClaimReward) GetBinArrayUpperAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetSenderAccount sets the "sender" account. +func (inst *ClaimReward) SetSenderAccount(sender ag_solanago.PublicKey) *ClaimReward { + inst.AccountMetaSlice[4] = ag_solanago.Meta(sender).SIGNER() + return inst +} + +// GetSenderAccount gets the "sender" account. +func (inst *ClaimReward) GetSenderAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetRewardVaultAccount sets the "rewardVault" account. +func (inst *ClaimReward) SetRewardVaultAccount(rewardVault ag_solanago.PublicKey) *ClaimReward { + inst.AccountMetaSlice[5] = ag_solanago.Meta(rewardVault).WRITE() + return inst +} + +// GetRewardVaultAccount gets the "rewardVault" account. +func (inst *ClaimReward) GetRewardVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetRewardMintAccount sets the "rewardMint" account. +func (inst *ClaimReward) SetRewardMintAccount(rewardMint ag_solanago.PublicKey) *ClaimReward { + inst.AccountMetaSlice[6] = ag_solanago.Meta(rewardMint) + return inst +} + +// GetRewardMintAccount gets the "rewardMint" account. +func (inst *ClaimReward) GetRewardMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetUserTokenAccountAccount sets the "userTokenAccount" account. +func (inst *ClaimReward) SetUserTokenAccountAccount(userTokenAccount ag_solanago.PublicKey) *ClaimReward { + inst.AccountMetaSlice[7] = ag_solanago.Meta(userTokenAccount).WRITE() + return inst +} + +// GetUserTokenAccountAccount gets the "userTokenAccount" account. +func (inst *ClaimReward) GetUserTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *ClaimReward) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *ClaimReward { + inst.AccountMetaSlice[8] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *ClaimReward) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetEventAuthorityAccount sets the "eventAuthority" account. +func (inst *ClaimReward) SetEventAuthorityAccount(eventAuthority ag_solanago.PublicKey) *ClaimReward { + inst.AccountMetaSlice[9] = ag_solanago.Meta(eventAuthority) + return inst +} + +// GetEventAuthorityAccount gets the "eventAuthority" account. +func (inst *ClaimReward) GetEventAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetProgramAccount sets the "program" account. +func (inst *ClaimReward) SetProgramAccount(program ag_solanago.PublicKey) *ClaimReward { + inst.AccountMetaSlice[10] = ag_solanago.Meta(program) + return inst +} + +// GetProgramAccount gets the "program" account. +func (inst *ClaimReward) GetProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +func (inst ClaimReward) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_ClaimReward, + }} +} + +// 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 ClaimReward) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *ClaimReward) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.RewardIndex == nil { + return errors.New("RewardIndex parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.LbPair is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Position is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.BinArrayLower is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.BinArrayUpper is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.Sender is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.RewardVault is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.RewardMint is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.UserTokenAccount is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.EventAuthority is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.Program is not set") + } + } + return nil +} + +func (inst *ClaimReward) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("ClaimReward")). + // + 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("RewardIndex", *inst.RewardIndex)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=11]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" lbPair", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" position", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" binArrayLower", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" binArrayUpper", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" sender", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" rewardVault", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" rewardMint", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" userToken", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta("eventAuthority", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" program", inst.AccountMetaSlice.Get(10))) + }) + }) + }) +} + +func (obj ClaimReward) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `RewardIndex` param: + err = encoder.Encode(obj.RewardIndex) + if err != nil { + return err + } + return nil +} +func (obj *ClaimReward) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `RewardIndex`: + err = decoder.Decode(&obj.RewardIndex) + if err != nil { + return err + } + return nil +} + +// NewClaimRewardInstruction declares a new ClaimReward instruction with the provided parameters and accounts. +func NewClaimRewardInstruction( + // Parameters: + rewardIndex uint64, + // Accounts: + lbPair ag_solanago.PublicKey, + position ag_solanago.PublicKey, + binArrayLower ag_solanago.PublicKey, + binArrayUpper ag_solanago.PublicKey, + sender ag_solanago.PublicKey, + rewardVault ag_solanago.PublicKey, + rewardMint ag_solanago.PublicKey, + userTokenAccount ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + eventAuthority ag_solanago.PublicKey, + program ag_solanago.PublicKey) *ClaimReward { + return NewClaimRewardInstructionBuilder(). + SetRewardIndex(rewardIndex). + SetLbPairAccount(lbPair). + SetPositionAccount(position). + SetBinArrayLowerAccount(binArrayLower). + SetBinArrayUpperAccount(binArrayUpper). + SetSenderAccount(sender). + SetRewardVaultAccount(rewardVault). + SetRewardMintAccount(rewardMint). + SetUserTokenAccountAccount(userTokenAccount). + SetTokenProgramAccount(tokenProgram). + SetEventAuthorityAccount(eventAuthority). + SetProgramAccount(program) +} diff --git a/programs/meteoradlmm/ClaimReward_test.go b/programs/meteoradlmm/ClaimReward_test.go new file mode 100644 index 00000000..e290ba4f --- /dev/null +++ b/programs/meteoradlmm/ClaimReward_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_ClaimReward(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("ClaimReward"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(ClaimReward) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(ClaimReward) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/ClosePosition.go b/programs/meteoradlmm/ClosePosition.go new file mode 100644 index 00000000..65789129 --- /dev/null +++ b/programs/meteoradlmm/ClosePosition.go @@ -0,0 +1,231 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// ClosePosition is the `closePosition` instruction. +type ClosePosition struct { + + // [0] = [WRITE] position + // + // [1] = [WRITE] lbPair + // + // [2] = [WRITE] binArrayLower + // + // [3] = [WRITE] binArrayUpper + // + // [4] = [SIGNER] sender + // + // [5] = [WRITE] rentReceiver + // + // [6] = [] eventAuthority + // + // [7] = [] program + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewClosePositionInstructionBuilder creates a new `ClosePosition` instruction builder. +func NewClosePositionInstructionBuilder() *ClosePosition { + nd := &ClosePosition{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 8), + } + return nd +} + +// SetPositionAccount sets the "position" account. +func (inst *ClosePosition) SetPositionAccount(position ag_solanago.PublicKey) *ClosePosition { + inst.AccountMetaSlice[0] = ag_solanago.Meta(position).WRITE() + return inst +} + +// GetPositionAccount gets the "position" account. +func (inst *ClosePosition) GetPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetLbPairAccount sets the "lbPair" account. +func (inst *ClosePosition) SetLbPairAccount(lbPair ag_solanago.PublicKey) *ClosePosition { + inst.AccountMetaSlice[1] = ag_solanago.Meta(lbPair).WRITE() + return inst +} + +// GetLbPairAccount gets the "lbPair" account. +func (inst *ClosePosition) GetLbPairAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetBinArrayLowerAccount sets the "binArrayLower" account. +func (inst *ClosePosition) SetBinArrayLowerAccount(binArrayLower ag_solanago.PublicKey) *ClosePosition { + inst.AccountMetaSlice[2] = ag_solanago.Meta(binArrayLower).WRITE() + return inst +} + +// GetBinArrayLowerAccount gets the "binArrayLower" account. +func (inst *ClosePosition) GetBinArrayLowerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetBinArrayUpperAccount sets the "binArrayUpper" account. +func (inst *ClosePosition) SetBinArrayUpperAccount(binArrayUpper ag_solanago.PublicKey) *ClosePosition { + inst.AccountMetaSlice[3] = ag_solanago.Meta(binArrayUpper).WRITE() + return inst +} + +// GetBinArrayUpperAccount gets the "binArrayUpper" account. +func (inst *ClosePosition) GetBinArrayUpperAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetSenderAccount sets the "sender" account. +func (inst *ClosePosition) SetSenderAccount(sender ag_solanago.PublicKey) *ClosePosition { + inst.AccountMetaSlice[4] = ag_solanago.Meta(sender).SIGNER() + return inst +} + +// GetSenderAccount gets the "sender" account. +func (inst *ClosePosition) GetSenderAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetRentReceiverAccount sets the "rentReceiver" account. +func (inst *ClosePosition) SetRentReceiverAccount(rentReceiver ag_solanago.PublicKey) *ClosePosition { + inst.AccountMetaSlice[5] = ag_solanago.Meta(rentReceiver).WRITE() + return inst +} + +// GetRentReceiverAccount gets the "rentReceiver" account. +func (inst *ClosePosition) GetRentReceiverAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetEventAuthorityAccount sets the "eventAuthority" account. +func (inst *ClosePosition) SetEventAuthorityAccount(eventAuthority ag_solanago.PublicKey) *ClosePosition { + inst.AccountMetaSlice[6] = ag_solanago.Meta(eventAuthority) + return inst +} + +// GetEventAuthorityAccount gets the "eventAuthority" account. +func (inst *ClosePosition) GetEventAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetProgramAccount sets the "program" account. +func (inst *ClosePosition) SetProgramAccount(program ag_solanago.PublicKey) *ClosePosition { + inst.AccountMetaSlice[7] = ag_solanago.Meta(program) + return inst +} + +// GetProgramAccount gets the "program" account. +func (inst *ClosePosition) GetProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +func (inst ClosePosition) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_ClosePosition, + }} +} + +// 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 ClosePosition) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *ClosePosition) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Position is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.LbPair is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.BinArrayLower is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.BinArrayUpper is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.Sender is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.RentReceiver is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.EventAuthority is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.Program is not set") + } + } + return nil +} + +func (inst *ClosePosition) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("ClosePosition")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=8]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" position", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" lbPair", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" binArrayLower", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" binArrayUpper", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" sender", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" rentReceiver", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta("eventAuthority", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" program", inst.AccountMetaSlice.Get(7))) + }) + }) + }) +} + +func (obj ClosePosition) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *ClosePosition) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewClosePositionInstruction declares a new ClosePosition instruction with the provided parameters and accounts. +func NewClosePositionInstruction( + // Accounts: + position ag_solanago.PublicKey, + lbPair ag_solanago.PublicKey, + binArrayLower ag_solanago.PublicKey, + binArrayUpper ag_solanago.PublicKey, + sender ag_solanago.PublicKey, + rentReceiver ag_solanago.PublicKey, + eventAuthority ag_solanago.PublicKey, + program ag_solanago.PublicKey) *ClosePosition { + return NewClosePositionInstructionBuilder(). + SetPositionAccount(position). + SetLbPairAccount(lbPair). + SetBinArrayLowerAccount(binArrayLower). + SetBinArrayUpperAccount(binArrayUpper). + SetSenderAccount(sender). + SetRentReceiverAccount(rentReceiver). + SetEventAuthorityAccount(eventAuthority). + SetProgramAccount(program) +} diff --git a/programs/meteoradlmm/ClosePosition_test.go b/programs/meteoradlmm/ClosePosition_test.go new file mode 100644 index 00000000..b4e49ee0 --- /dev/null +++ b/programs/meteoradlmm/ClosePosition_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_ClosePosition(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("ClosePosition"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(ClosePosition) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(ClosePosition) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/ClosePresetParameter.go b/programs/meteoradlmm/ClosePresetParameter.go new file mode 100644 index 00000000..55f00d74 --- /dev/null +++ b/programs/meteoradlmm/ClosePresetParameter.go @@ -0,0 +1,136 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// ClosePresetParameter is the `closePresetParameter` instruction. +type ClosePresetParameter struct { + + // [0] = [WRITE] presetParameter + // + // [1] = [WRITE, SIGNER] admin + // + // [2] = [WRITE] rentReceiver + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewClosePresetParameterInstructionBuilder creates a new `ClosePresetParameter` instruction builder. +func NewClosePresetParameterInstructionBuilder() *ClosePresetParameter { + nd := &ClosePresetParameter{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 3), + } + return nd +} + +// SetPresetParameterAccount sets the "presetParameter" account. +func (inst *ClosePresetParameter) SetPresetParameterAccount(presetParameter ag_solanago.PublicKey) *ClosePresetParameter { + inst.AccountMetaSlice[0] = ag_solanago.Meta(presetParameter).WRITE() + return inst +} + +// GetPresetParameterAccount gets the "presetParameter" account. +func (inst *ClosePresetParameter) GetPresetParameterAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetAdminAccount sets the "admin" account. +func (inst *ClosePresetParameter) SetAdminAccount(admin ag_solanago.PublicKey) *ClosePresetParameter { + inst.AccountMetaSlice[1] = ag_solanago.Meta(admin).WRITE().SIGNER() + return inst +} + +// GetAdminAccount gets the "admin" account. +func (inst *ClosePresetParameter) GetAdminAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetRentReceiverAccount sets the "rentReceiver" account. +func (inst *ClosePresetParameter) SetRentReceiverAccount(rentReceiver ag_solanago.PublicKey) *ClosePresetParameter { + inst.AccountMetaSlice[2] = ag_solanago.Meta(rentReceiver).WRITE() + return inst +} + +// GetRentReceiverAccount gets the "rentReceiver" account. +func (inst *ClosePresetParameter) GetRentReceiverAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +func (inst ClosePresetParameter) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_ClosePresetParameter, + }} +} + +// 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 ClosePresetParameter) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *ClosePresetParameter) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.PresetParameter is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Admin is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.RentReceiver is not set") + } + } + return nil +} + +func (inst *ClosePresetParameter) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("ClosePresetParameter")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=3]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta("presetParameter", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" admin", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" rentReceiver", inst.AccountMetaSlice.Get(2))) + }) + }) + }) +} + +func (obj ClosePresetParameter) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *ClosePresetParameter) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewClosePresetParameterInstruction declares a new ClosePresetParameter instruction with the provided parameters and accounts. +func NewClosePresetParameterInstruction( + // Accounts: + presetParameter ag_solanago.PublicKey, + admin ag_solanago.PublicKey, + rentReceiver ag_solanago.PublicKey) *ClosePresetParameter { + return NewClosePresetParameterInstructionBuilder(). + SetPresetParameterAccount(presetParameter). + SetAdminAccount(admin). + SetRentReceiverAccount(rentReceiver) +} diff --git a/programs/meteoradlmm/ClosePresetParameter_test.go b/programs/meteoradlmm/ClosePresetParameter_test.go new file mode 100644 index 00000000..8225ddab --- /dev/null +++ b/programs/meteoradlmm/ClosePresetParameter_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_ClosePresetParameter(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("ClosePresetParameter"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(ClosePresetParameter) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(ClosePresetParameter) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/FundReward.go b/programs/meteoradlmm/FundReward.go new file mode 100644 index 00000000..01476b11 --- /dev/null +++ b/programs/meteoradlmm/FundReward.go @@ -0,0 +1,325 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// FundReward is the `fundReward` instruction. +type FundReward struct { + RewardIndex *uint64 + Amount *uint64 + CarryForward *bool + + // [0] = [WRITE] lbPair + // + // [1] = [WRITE] rewardVault + // + // [2] = [] rewardMint + // + // [3] = [WRITE] funderTokenAccount + // + // [4] = [SIGNER] funder + // + // [5] = [WRITE] binArray + // + // [6] = [] tokenProgram + // + // [7] = [] eventAuthority + // + // [8] = [] program + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewFundRewardInstructionBuilder creates a new `FundReward` instruction builder. +func NewFundRewardInstructionBuilder() *FundReward { + nd := &FundReward{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 9), + } + return nd +} + +// SetRewardIndex sets the "rewardIndex" parameter. +func (inst *FundReward) SetRewardIndex(rewardIndex uint64) *FundReward { + inst.RewardIndex = &rewardIndex + return inst +} + +// SetAmount sets the "amount" parameter. +func (inst *FundReward) SetAmount(amount uint64) *FundReward { + inst.Amount = &amount + return inst +} + +// SetCarryForward sets the "carryForward" parameter. +func (inst *FundReward) SetCarryForward(carryForward bool) *FundReward { + inst.CarryForward = &carryForward + return inst +} + +// SetLbPairAccount sets the "lbPair" account. +func (inst *FundReward) SetLbPairAccount(lbPair ag_solanago.PublicKey) *FundReward { + inst.AccountMetaSlice[0] = ag_solanago.Meta(lbPair).WRITE() + return inst +} + +// GetLbPairAccount gets the "lbPair" account. +func (inst *FundReward) GetLbPairAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetRewardVaultAccount sets the "rewardVault" account. +func (inst *FundReward) SetRewardVaultAccount(rewardVault ag_solanago.PublicKey) *FundReward { + inst.AccountMetaSlice[1] = ag_solanago.Meta(rewardVault).WRITE() + return inst +} + +// GetRewardVaultAccount gets the "rewardVault" account. +func (inst *FundReward) GetRewardVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetRewardMintAccount sets the "rewardMint" account. +func (inst *FundReward) SetRewardMintAccount(rewardMint ag_solanago.PublicKey) *FundReward { + inst.AccountMetaSlice[2] = ag_solanago.Meta(rewardMint) + return inst +} + +// GetRewardMintAccount gets the "rewardMint" account. +func (inst *FundReward) GetRewardMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetFunderTokenAccountAccount sets the "funderTokenAccount" account. +func (inst *FundReward) SetFunderTokenAccountAccount(funderTokenAccount ag_solanago.PublicKey) *FundReward { + inst.AccountMetaSlice[3] = ag_solanago.Meta(funderTokenAccount).WRITE() + return inst +} + +// GetFunderTokenAccountAccount gets the "funderTokenAccount" account. +func (inst *FundReward) GetFunderTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetFunderAccount sets the "funder" account. +func (inst *FundReward) SetFunderAccount(funder ag_solanago.PublicKey) *FundReward { + inst.AccountMetaSlice[4] = ag_solanago.Meta(funder).SIGNER() + return inst +} + +// GetFunderAccount gets the "funder" account. +func (inst *FundReward) GetFunderAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetBinArrayAccount sets the "binArray" account. +func (inst *FundReward) SetBinArrayAccount(binArray ag_solanago.PublicKey) *FundReward { + inst.AccountMetaSlice[5] = ag_solanago.Meta(binArray).WRITE() + return inst +} + +// GetBinArrayAccount gets the "binArray" account. +func (inst *FundReward) GetBinArrayAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *FundReward) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *FundReward { + inst.AccountMetaSlice[6] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *FundReward) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetEventAuthorityAccount sets the "eventAuthority" account. +func (inst *FundReward) SetEventAuthorityAccount(eventAuthority ag_solanago.PublicKey) *FundReward { + inst.AccountMetaSlice[7] = ag_solanago.Meta(eventAuthority) + return inst +} + +// GetEventAuthorityAccount gets the "eventAuthority" account. +func (inst *FundReward) GetEventAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetProgramAccount sets the "program" account. +func (inst *FundReward) SetProgramAccount(program ag_solanago.PublicKey) *FundReward { + inst.AccountMetaSlice[8] = ag_solanago.Meta(program) + return inst +} + +// GetProgramAccount gets the "program" account. +func (inst *FundReward) GetProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +func (inst FundReward) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_FundReward, + }} +} + +// 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 FundReward) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *FundReward) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.RewardIndex == nil { + return errors.New("RewardIndex parameter is not set") + } + if inst.Amount == nil { + return errors.New("Amount parameter is not set") + } + if inst.CarryForward == nil { + return errors.New("CarryForward parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.LbPair is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.RewardVault is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.RewardMint is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.FunderTokenAccount is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.Funder is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.BinArray is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.EventAuthority is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.Program is not set") + } + } + return nil +} + +func (inst *FundReward) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("FundReward")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=3]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" RewardIndex", *inst.RewardIndex)) + paramsBranch.Child(ag_format.Param(" Amount", *inst.Amount)) + paramsBranch.Child(ag_format.Param("CarryForward", *inst.CarryForward)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=9]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" lbPair", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" rewardVault", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" rewardMint", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" funderToken", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" funder", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" binArray", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta("eventAuthority", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" program", inst.AccountMetaSlice.Get(8))) + }) + }) + }) +} + +func (obj FundReward) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `RewardIndex` param: + err = encoder.Encode(obj.RewardIndex) + if err != nil { + return err + } + // Serialize `Amount` param: + err = encoder.Encode(obj.Amount) + if err != nil { + return err + } + // Serialize `CarryForward` param: + err = encoder.Encode(obj.CarryForward) + if err != nil { + return err + } + return nil +} +func (obj *FundReward) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `RewardIndex`: + err = decoder.Decode(&obj.RewardIndex) + if err != nil { + return err + } + // Deserialize `Amount`: + err = decoder.Decode(&obj.Amount) + if err != nil { + return err + } + // Deserialize `CarryForward`: + err = decoder.Decode(&obj.CarryForward) + if err != nil { + return err + } + return nil +} + +// NewFundRewardInstruction declares a new FundReward instruction with the provided parameters and accounts. +func NewFundRewardInstruction( + // Parameters: + rewardIndex uint64, + amount uint64, + carryForward bool, + // Accounts: + lbPair ag_solanago.PublicKey, + rewardVault ag_solanago.PublicKey, + rewardMint ag_solanago.PublicKey, + funderTokenAccount ag_solanago.PublicKey, + funder ag_solanago.PublicKey, + binArray ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + eventAuthority ag_solanago.PublicKey, + program ag_solanago.PublicKey) *FundReward { + return NewFundRewardInstructionBuilder(). + SetRewardIndex(rewardIndex). + SetAmount(amount). + SetCarryForward(carryForward). + SetLbPairAccount(lbPair). + SetRewardVaultAccount(rewardVault). + SetRewardMintAccount(rewardMint). + SetFunderTokenAccountAccount(funderTokenAccount). + SetFunderAccount(funder). + SetBinArrayAccount(binArray). + SetTokenProgramAccount(tokenProgram). + SetEventAuthorityAccount(eventAuthority). + SetProgramAccount(program) +} diff --git a/programs/meteoradlmm/FundReward_test.go b/programs/meteoradlmm/FundReward_test.go new file mode 100644 index 00000000..4fdecbaa --- /dev/null +++ b/programs/meteoradlmm/FundReward_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_FundReward(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("FundReward"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(FundReward) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(FundReward) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/GoToABin.go b/programs/meteoradlmm/GoToABin.go new file mode 100644 index 00000000..2d52a5e1 --- /dev/null +++ b/programs/meteoradlmm/GoToABin.go @@ -0,0 +1,222 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// GoToABin is the `goToABin` instruction. +type GoToABin struct { + BinId *int32 + + // [0] = [WRITE] lbPair + // + // [1] = [] binArrayBitmapExtension + // + // [2] = [] fromBinArray + // + // [3] = [] toBinArray + // + // [4] = [] eventAuthority + // + // [5] = [] program + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewGoToABinInstructionBuilder creates a new `GoToABin` instruction builder. +func NewGoToABinInstructionBuilder() *GoToABin { + nd := &GoToABin{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 6), + } + return nd +} + +// SetBinId sets the "binId" parameter. +func (inst *GoToABin) SetBinId(binId int32) *GoToABin { + inst.BinId = &binId + return inst +} + +// SetLbPairAccount sets the "lbPair" account. +func (inst *GoToABin) SetLbPairAccount(lbPair ag_solanago.PublicKey) *GoToABin { + inst.AccountMetaSlice[0] = ag_solanago.Meta(lbPair).WRITE() + return inst +} + +// GetLbPairAccount gets the "lbPair" account. +func (inst *GoToABin) GetLbPairAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetBinArrayBitmapExtensionAccount sets the "binArrayBitmapExtension" account. +func (inst *GoToABin) SetBinArrayBitmapExtensionAccount(binArrayBitmapExtension ag_solanago.PublicKey) *GoToABin { + inst.AccountMetaSlice[1] = ag_solanago.Meta(binArrayBitmapExtension) + return inst +} + +// GetBinArrayBitmapExtensionAccount gets the "binArrayBitmapExtension" account. +func (inst *GoToABin) GetBinArrayBitmapExtensionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetFromBinArrayAccount sets the "fromBinArray" account. +func (inst *GoToABin) SetFromBinArrayAccount(fromBinArray ag_solanago.PublicKey) *GoToABin { + inst.AccountMetaSlice[2] = ag_solanago.Meta(fromBinArray) + return inst +} + +// GetFromBinArrayAccount gets the "fromBinArray" account. +func (inst *GoToABin) GetFromBinArrayAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetToBinArrayAccount sets the "toBinArray" account. +func (inst *GoToABin) SetToBinArrayAccount(toBinArray ag_solanago.PublicKey) *GoToABin { + inst.AccountMetaSlice[3] = ag_solanago.Meta(toBinArray) + return inst +} + +// GetToBinArrayAccount gets the "toBinArray" account. +func (inst *GoToABin) GetToBinArrayAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetEventAuthorityAccount sets the "eventAuthority" account. +func (inst *GoToABin) SetEventAuthorityAccount(eventAuthority ag_solanago.PublicKey) *GoToABin { + inst.AccountMetaSlice[4] = ag_solanago.Meta(eventAuthority) + return inst +} + +// GetEventAuthorityAccount gets the "eventAuthority" account. +func (inst *GoToABin) GetEventAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetProgramAccount sets the "program" account. +func (inst *GoToABin) SetProgramAccount(program ag_solanago.PublicKey) *GoToABin { + inst.AccountMetaSlice[5] = ag_solanago.Meta(program) + return inst +} + +// GetProgramAccount gets the "program" account. +func (inst *GoToABin) GetProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +func (inst GoToABin) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_GoToABin, + }} +} + +// 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 GoToABin) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *GoToABin) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.BinId == nil { + return errors.New("BinId parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.LbPair is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.BinArrayBitmapExtension is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.FromBinArray is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.ToBinArray is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.EventAuthority is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.Program is not set") + } + } + return nil +} + +func (inst *GoToABin) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("GoToABin")). + // + 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("BinId", *inst.BinId)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=6]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" lbPair", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta("binArrayBitmapExtension", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" fromBinArray", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" toBinArray", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" eventAuthority", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" program", inst.AccountMetaSlice.Get(5))) + }) + }) + }) +} + +func (obj GoToABin) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `BinId` param: + err = encoder.Encode(obj.BinId) + if err != nil { + return err + } + return nil +} +func (obj *GoToABin) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `BinId`: + err = decoder.Decode(&obj.BinId) + if err != nil { + return err + } + return nil +} + +// NewGoToABinInstruction declares a new GoToABin instruction with the provided parameters and accounts. +func NewGoToABinInstruction( + // Parameters: + binId int32, + // Accounts: + lbPair ag_solanago.PublicKey, + binArrayBitmapExtension ag_solanago.PublicKey, + fromBinArray ag_solanago.PublicKey, + toBinArray ag_solanago.PublicKey, + eventAuthority ag_solanago.PublicKey, + program ag_solanago.PublicKey) *GoToABin { + return NewGoToABinInstructionBuilder(). + SetBinId(binId). + SetLbPairAccount(lbPair). + SetBinArrayBitmapExtensionAccount(binArrayBitmapExtension). + SetFromBinArrayAccount(fromBinArray). + SetToBinArrayAccount(toBinArray). + SetEventAuthorityAccount(eventAuthority). + SetProgramAccount(program) +} diff --git a/programs/meteoradlmm/GoToABin_test.go b/programs/meteoradlmm/GoToABin_test.go new file mode 100644 index 00000000..b37f3943 --- /dev/null +++ b/programs/meteoradlmm/GoToABin_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_GoToABin(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("GoToABin"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(GoToABin) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(GoToABin) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/IncreaseOracleLength.go b/programs/meteoradlmm/IncreaseOracleLength.go new file mode 100644 index 00000000..022d59fc --- /dev/null +++ b/programs/meteoradlmm/IncreaseOracleLength.go @@ -0,0 +1,203 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// IncreaseOracleLength is the `increaseOracleLength` instruction. +type IncreaseOracleLength struct { + LengthToAdd *uint64 + + // [0] = [WRITE] oracle + // + // [1] = [WRITE, SIGNER] funder + // + // [2] = [] systemProgram + // + // [3] = [] eventAuthority + // + // [4] = [] program + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewIncreaseOracleLengthInstructionBuilder creates a new `IncreaseOracleLength` instruction builder. +func NewIncreaseOracleLengthInstructionBuilder() *IncreaseOracleLength { + nd := &IncreaseOracleLength{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 5), + } + return nd +} + +// SetLengthToAdd sets the "lengthToAdd" parameter. +func (inst *IncreaseOracleLength) SetLengthToAdd(lengthToAdd uint64) *IncreaseOracleLength { + inst.LengthToAdd = &lengthToAdd + return inst +} + +// SetOracleAccount sets the "oracle" account. +func (inst *IncreaseOracleLength) SetOracleAccount(oracle ag_solanago.PublicKey) *IncreaseOracleLength { + inst.AccountMetaSlice[0] = ag_solanago.Meta(oracle).WRITE() + return inst +} + +// GetOracleAccount gets the "oracle" account. +func (inst *IncreaseOracleLength) GetOracleAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetFunderAccount sets the "funder" account. +func (inst *IncreaseOracleLength) SetFunderAccount(funder ag_solanago.PublicKey) *IncreaseOracleLength { + inst.AccountMetaSlice[1] = ag_solanago.Meta(funder).WRITE().SIGNER() + return inst +} + +// GetFunderAccount gets the "funder" account. +func (inst *IncreaseOracleLength) GetFunderAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +func (inst *IncreaseOracleLength) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *IncreaseOracleLength { + inst.AccountMetaSlice[2] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +func (inst *IncreaseOracleLength) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetEventAuthorityAccount sets the "eventAuthority" account. +func (inst *IncreaseOracleLength) SetEventAuthorityAccount(eventAuthority ag_solanago.PublicKey) *IncreaseOracleLength { + inst.AccountMetaSlice[3] = ag_solanago.Meta(eventAuthority) + return inst +} + +// GetEventAuthorityAccount gets the "eventAuthority" account. +func (inst *IncreaseOracleLength) GetEventAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetProgramAccount sets the "program" account. +func (inst *IncreaseOracleLength) SetProgramAccount(program ag_solanago.PublicKey) *IncreaseOracleLength { + inst.AccountMetaSlice[4] = ag_solanago.Meta(program) + return inst +} + +// GetProgramAccount gets the "program" account. +func (inst *IncreaseOracleLength) GetProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +func (inst IncreaseOracleLength) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_IncreaseOracleLength, + }} +} + +// 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 IncreaseOracleLength) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *IncreaseOracleLength) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.LengthToAdd == nil { + return errors.New("LengthToAdd parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Oracle is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Funder is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.SystemProgram is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.EventAuthority is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.Program is not set") + } + } + return nil +} + +func (inst *IncreaseOracleLength) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("IncreaseOracleLength")). + // + 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("LengthToAdd", *inst.LengthToAdd)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=5]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" oracle", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" funder", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" systemProgram", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta("eventAuthority", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" program", inst.AccountMetaSlice.Get(4))) + }) + }) + }) +} + +func (obj IncreaseOracleLength) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `LengthToAdd` param: + err = encoder.Encode(obj.LengthToAdd) + if err != nil { + return err + } + return nil +} +func (obj *IncreaseOracleLength) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `LengthToAdd`: + err = decoder.Decode(&obj.LengthToAdd) + if err != nil { + return err + } + return nil +} + +// NewIncreaseOracleLengthInstruction declares a new IncreaseOracleLength instruction with the provided parameters and accounts. +func NewIncreaseOracleLengthInstruction( + // Parameters: + lengthToAdd uint64, + // Accounts: + oracle ag_solanago.PublicKey, + funder ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey, + eventAuthority ag_solanago.PublicKey, + program ag_solanago.PublicKey) *IncreaseOracleLength { + return NewIncreaseOracleLengthInstructionBuilder(). + SetLengthToAdd(lengthToAdd). + SetOracleAccount(oracle). + SetFunderAccount(funder). + SetSystemProgramAccount(systemProgram). + SetEventAuthorityAccount(eventAuthority). + SetProgramAccount(program) +} diff --git a/programs/meteoradlmm/IncreaseOracleLength_test.go b/programs/meteoradlmm/IncreaseOracleLength_test.go new file mode 100644 index 00000000..6e6c7e3f --- /dev/null +++ b/programs/meteoradlmm/IncreaseOracleLength_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_IncreaseOracleLength(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("IncreaseOracleLength"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(IncreaseOracleLength) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(IncreaseOracleLength) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/InitializeBinArray.go b/programs/meteoradlmm/InitializeBinArray.go new file mode 100644 index 00000000..5d0bde74 --- /dev/null +++ b/programs/meteoradlmm/InitializeBinArray.go @@ -0,0 +1,184 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// InitializeBinArray is the `initializeBinArray` instruction. +type InitializeBinArray struct { + Index *int64 + + // [0] = [] lbPair + // + // [1] = [WRITE] binArray + // + // [2] = [WRITE, SIGNER] funder + // + // [3] = [] systemProgram + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewInitializeBinArrayInstructionBuilder creates a new `InitializeBinArray` instruction builder. +func NewInitializeBinArrayInstructionBuilder() *InitializeBinArray { + nd := &InitializeBinArray{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 4), + } + return nd +} + +// SetIndex sets the "index" parameter. +func (inst *InitializeBinArray) SetIndex(index int64) *InitializeBinArray { + inst.Index = &index + return inst +} + +// SetLbPairAccount sets the "lbPair" account. +func (inst *InitializeBinArray) SetLbPairAccount(lbPair ag_solanago.PublicKey) *InitializeBinArray { + inst.AccountMetaSlice[0] = ag_solanago.Meta(lbPair) + return inst +} + +// GetLbPairAccount gets the "lbPair" account. +func (inst *InitializeBinArray) GetLbPairAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetBinArrayAccount sets the "binArray" account. +func (inst *InitializeBinArray) SetBinArrayAccount(binArray ag_solanago.PublicKey) *InitializeBinArray { + inst.AccountMetaSlice[1] = ag_solanago.Meta(binArray).WRITE() + return inst +} + +// GetBinArrayAccount gets the "binArray" account. +func (inst *InitializeBinArray) GetBinArrayAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetFunderAccount sets the "funder" account. +func (inst *InitializeBinArray) SetFunderAccount(funder ag_solanago.PublicKey) *InitializeBinArray { + inst.AccountMetaSlice[2] = ag_solanago.Meta(funder).WRITE().SIGNER() + return inst +} + +// GetFunderAccount gets the "funder" account. +func (inst *InitializeBinArray) GetFunderAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +func (inst *InitializeBinArray) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *InitializeBinArray { + inst.AccountMetaSlice[3] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +func (inst *InitializeBinArray) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +func (inst InitializeBinArray) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_InitializeBinArray, + }} +} + +// 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 InitializeBinArray) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *InitializeBinArray) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.Index == nil { + return errors.New("Index parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.LbPair is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.BinArray is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.Funder is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.SystemProgram is not set") + } + } + return nil +} + +func (inst *InitializeBinArray) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("InitializeBinArray")). + // + 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("Index", *inst.Index)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=4]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" lbPair", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" binArray", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" funder", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta("systemProgram", inst.AccountMetaSlice.Get(3))) + }) + }) + }) +} + +func (obj InitializeBinArray) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Index` param: + err = encoder.Encode(obj.Index) + if err != nil { + return err + } + return nil +} +func (obj *InitializeBinArray) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Index`: + err = decoder.Decode(&obj.Index) + if err != nil { + return err + } + return nil +} + +// NewInitializeBinArrayInstruction declares a new InitializeBinArray instruction with the provided parameters and accounts. +func NewInitializeBinArrayInstruction( + // Parameters: + index int64, + // Accounts: + lbPair ag_solanago.PublicKey, + binArray ag_solanago.PublicKey, + funder ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey) *InitializeBinArray { + return NewInitializeBinArrayInstructionBuilder(). + SetIndex(index). + SetLbPairAccount(lbPair). + SetBinArrayAccount(binArray). + SetFunderAccount(funder). + SetSystemProgramAccount(systemProgram) +} diff --git a/programs/meteoradlmm/InitializeBinArrayBitmapExtension.go b/programs/meteoradlmm/InitializeBinArrayBitmapExtension.go new file mode 100644 index 00000000..c1fb005b --- /dev/null +++ b/programs/meteoradlmm/InitializeBinArrayBitmapExtension.go @@ -0,0 +1,177 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// InitializeBinArrayBitmapExtension is the `initializeBinArrayBitmapExtension` instruction. +type InitializeBinArrayBitmapExtension struct { + + // [0] = [] lbPair + // + // [1] = [WRITE] binArrayBitmapExtension + // ··········· Initialize an account to store if a bin array is initialized. + // + // [2] = [WRITE, SIGNER] funder + // + // [3] = [] systemProgram + // + // [4] = [] rent + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewInitializeBinArrayBitmapExtensionInstructionBuilder creates a new `InitializeBinArrayBitmapExtension` instruction builder. +func NewInitializeBinArrayBitmapExtensionInstructionBuilder() *InitializeBinArrayBitmapExtension { + nd := &InitializeBinArrayBitmapExtension{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 5), + } + return nd +} + +// SetLbPairAccount sets the "lbPair" account. +func (inst *InitializeBinArrayBitmapExtension) SetLbPairAccount(lbPair ag_solanago.PublicKey) *InitializeBinArrayBitmapExtension { + inst.AccountMetaSlice[0] = ag_solanago.Meta(lbPair) + return inst +} + +// GetLbPairAccount gets the "lbPair" account. +func (inst *InitializeBinArrayBitmapExtension) GetLbPairAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetBinArrayBitmapExtensionAccount sets the "binArrayBitmapExtension" account. +// Initialize an account to store if a bin array is initialized. +func (inst *InitializeBinArrayBitmapExtension) SetBinArrayBitmapExtensionAccount(binArrayBitmapExtension ag_solanago.PublicKey) *InitializeBinArrayBitmapExtension { + inst.AccountMetaSlice[1] = ag_solanago.Meta(binArrayBitmapExtension).WRITE() + return inst +} + +// GetBinArrayBitmapExtensionAccount gets the "binArrayBitmapExtension" account. +// Initialize an account to store if a bin array is initialized. +func (inst *InitializeBinArrayBitmapExtension) GetBinArrayBitmapExtensionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetFunderAccount sets the "funder" account. +func (inst *InitializeBinArrayBitmapExtension) SetFunderAccount(funder ag_solanago.PublicKey) *InitializeBinArrayBitmapExtension { + inst.AccountMetaSlice[2] = ag_solanago.Meta(funder).WRITE().SIGNER() + return inst +} + +// GetFunderAccount gets the "funder" account. +func (inst *InitializeBinArrayBitmapExtension) GetFunderAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +func (inst *InitializeBinArrayBitmapExtension) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *InitializeBinArrayBitmapExtension { + inst.AccountMetaSlice[3] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +func (inst *InitializeBinArrayBitmapExtension) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetRentAccount sets the "rent" account. +func (inst *InitializeBinArrayBitmapExtension) SetRentAccount(rent ag_solanago.PublicKey) *InitializeBinArrayBitmapExtension { + inst.AccountMetaSlice[4] = ag_solanago.Meta(rent) + return inst +} + +// GetRentAccount gets the "rent" account. +func (inst *InitializeBinArrayBitmapExtension) GetRentAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +func (inst InitializeBinArrayBitmapExtension) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_InitializeBinArrayBitmapExtension, + }} +} + +// 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 InitializeBinArrayBitmapExtension) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *InitializeBinArrayBitmapExtension) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.LbPair is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.BinArrayBitmapExtension is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.Funder is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.SystemProgram is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.Rent is not set") + } + } + return nil +} + +func (inst *InitializeBinArrayBitmapExtension) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("InitializeBinArrayBitmapExtension")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=5]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" lbPair", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta("binArrayBitmapExtension", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" funder", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" systemProgram", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" rent", inst.AccountMetaSlice.Get(4))) + }) + }) + }) +} + +func (obj InitializeBinArrayBitmapExtension) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *InitializeBinArrayBitmapExtension) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewInitializeBinArrayBitmapExtensionInstruction declares a new InitializeBinArrayBitmapExtension instruction with the provided parameters and accounts. +func NewInitializeBinArrayBitmapExtensionInstruction( + // Accounts: + lbPair ag_solanago.PublicKey, + binArrayBitmapExtension ag_solanago.PublicKey, + funder ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey, + rent ag_solanago.PublicKey) *InitializeBinArrayBitmapExtension { + return NewInitializeBinArrayBitmapExtensionInstructionBuilder(). + SetLbPairAccount(lbPair). + SetBinArrayBitmapExtensionAccount(binArrayBitmapExtension). + SetFunderAccount(funder). + SetSystemProgramAccount(systemProgram). + SetRentAccount(rent) +} diff --git a/programs/meteoradlmm/InitializeBinArrayBitmapExtension_test.go b/programs/meteoradlmm/InitializeBinArrayBitmapExtension_test.go new file mode 100644 index 00000000..f0f4fc8c --- /dev/null +++ b/programs/meteoradlmm/InitializeBinArrayBitmapExtension_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_InitializeBinArrayBitmapExtension(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("InitializeBinArrayBitmapExtension"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(InitializeBinArrayBitmapExtension) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(InitializeBinArrayBitmapExtension) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/InitializeBinArray_test.go b/programs/meteoradlmm/InitializeBinArray_test.go new file mode 100644 index 00000000..47481ae9 --- /dev/null +++ b/programs/meteoradlmm/InitializeBinArray_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_InitializeBinArray(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("InitializeBinArray"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(InitializeBinArray) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(InitializeBinArray) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/InitializeCustomizablePermissionlessLbPair.go b/programs/meteoradlmm/InitializeCustomizablePermissionlessLbPair.go new file mode 100644 index 00000000..896ccc29 --- /dev/null +++ b/programs/meteoradlmm/InitializeCustomizablePermissionlessLbPair.go @@ -0,0 +1,374 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// InitializeCustomizablePermissionlessLbPair is the `initializeCustomizablePermissionlessLbPair` instruction. +type InitializeCustomizablePermissionlessLbPair struct { + Params *CustomizableParams + + // [0] = [WRITE] lbPair + // + // [1] = [WRITE] binArrayBitmapExtension + // + // [2] = [] tokenMintX + // + // [3] = [] tokenMintY + // + // [4] = [WRITE] reserveX + // + // [5] = [WRITE] reserveY + // + // [6] = [WRITE] oracle + // + // [7] = [] userTokenX + // + // [8] = [WRITE, SIGNER] funder + // + // [9] = [] tokenProgram + // + // [10] = [] systemProgram + // + // [11] = [] rent + // + // [12] = [] eventAuthority + // + // [13] = [] program + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewInitializeCustomizablePermissionlessLbPairInstructionBuilder creates a new `InitializeCustomizablePermissionlessLbPair` instruction builder. +func NewInitializeCustomizablePermissionlessLbPairInstructionBuilder() *InitializeCustomizablePermissionlessLbPair { + nd := &InitializeCustomizablePermissionlessLbPair{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 14), + } + return nd +} + +// SetParams sets the "params" parameter. +func (inst *InitializeCustomizablePermissionlessLbPair) SetParams(params CustomizableParams) *InitializeCustomizablePermissionlessLbPair { + inst.Params = ¶ms + return inst +} + +// SetLbPairAccount sets the "lbPair" account. +func (inst *InitializeCustomizablePermissionlessLbPair) SetLbPairAccount(lbPair ag_solanago.PublicKey) *InitializeCustomizablePermissionlessLbPair { + inst.AccountMetaSlice[0] = ag_solanago.Meta(lbPair).WRITE() + return inst +} + +// GetLbPairAccount gets the "lbPair" account. +func (inst *InitializeCustomizablePermissionlessLbPair) GetLbPairAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetBinArrayBitmapExtensionAccount sets the "binArrayBitmapExtension" account. +func (inst *InitializeCustomizablePermissionlessLbPair) SetBinArrayBitmapExtensionAccount(binArrayBitmapExtension ag_solanago.PublicKey) *InitializeCustomizablePermissionlessLbPair { + inst.AccountMetaSlice[1] = ag_solanago.Meta(binArrayBitmapExtension).WRITE() + return inst +} + +// GetBinArrayBitmapExtensionAccount gets the "binArrayBitmapExtension" account. +func (inst *InitializeCustomizablePermissionlessLbPair) GetBinArrayBitmapExtensionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetTokenMintXAccount sets the "tokenMintX" account. +func (inst *InitializeCustomizablePermissionlessLbPair) SetTokenMintXAccount(tokenMintX ag_solanago.PublicKey) *InitializeCustomizablePermissionlessLbPair { + inst.AccountMetaSlice[2] = ag_solanago.Meta(tokenMintX) + return inst +} + +// GetTokenMintXAccount gets the "tokenMintX" account. +func (inst *InitializeCustomizablePermissionlessLbPair) GetTokenMintXAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetTokenMintYAccount sets the "tokenMintY" account. +func (inst *InitializeCustomizablePermissionlessLbPair) SetTokenMintYAccount(tokenMintY ag_solanago.PublicKey) *InitializeCustomizablePermissionlessLbPair { + inst.AccountMetaSlice[3] = ag_solanago.Meta(tokenMintY) + return inst +} + +// GetTokenMintYAccount gets the "tokenMintY" account. +func (inst *InitializeCustomizablePermissionlessLbPair) GetTokenMintYAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetReserveXAccount sets the "reserveX" account. +func (inst *InitializeCustomizablePermissionlessLbPair) SetReserveXAccount(reserveX ag_solanago.PublicKey) *InitializeCustomizablePermissionlessLbPair { + inst.AccountMetaSlice[4] = ag_solanago.Meta(reserveX).WRITE() + return inst +} + +// GetReserveXAccount gets the "reserveX" account. +func (inst *InitializeCustomizablePermissionlessLbPair) GetReserveXAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetReserveYAccount sets the "reserveY" account. +func (inst *InitializeCustomizablePermissionlessLbPair) SetReserveYAccount(reserveY ag_solanago.PublicKey) *InitializeCustomizablePermissionlessLbPair { + inst.AccountMetaSlice[5] = ag_solanago.Meta(reserveY).WRITE() + return inst +} + +// GetReserveYAccount gets the "reserveY" account. +func (inst *InitializeCustomizablePermissionlessLbPair) GetReserveYAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetOracleAccount sets the "oracle" account. +func (inst *InitializeCustomizablePermissionlessLbPair) SetOracleAccount(oracle ag_solanago.PublicKey) *InitializeCustomizablePermissionlessLbPair { + inst.AccountMetaSlice[6] = ag_solanago.Meta(oracle).WRITE() + return inst +} + +// GetOracleAccount gets the "oracle" account. +func (inst *InitializeCustomizablePermissionlessLbPair) GetOracleAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetUserTokenXAccount sets the "userTokenX" account. +func (inst *InitializeCustomizablePermissionlessLbPair) SetUserTokenXAccount(userTokenX ag_solanago.PublicKey) *InitializeCustomizablePermissionlessLbPair { + inst.AccountMetaSlice[7] = ag_solanago.Meta(userTokenX) + return inst +} + +// GetUserTokenXAccount gets the "userTokenX" account. +func (inst *InitializeCustomizablePermissionlessLbPair) GetUserTokenXAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetFunderAccount sets the "funder" account. +func (inst *InitializeCustomizablePermissionlessLbPair) SetFunderAccount(funder ag_solanago.PublicKey) *InitializeCustomizablePermissionlessLbPair { + inst.AccountMetaSlice[8] = ag_solanago.Meta(funder).WRITE().SIGNER() + return inst +} + +// GetFunderAccount gets the "funder" account. +func (inst *InitializeCustomizablePermissionlessLbPair) GetFunderAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *InitializeCustomizablePermissionlessLbPair) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *InitializeCustomizablePermissionlessLbPair { + inst.AccountMetaSlice[9] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *InitializeCustomizablePermissionlessLbPair) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +func (inst *InitializeCustomizablePermissionlessLbPair) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *InitializeCustomizablePermissionlessLbPair { + inst.AccountMetaSlice[10] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +func (inst *InitializeCustomizablePermissionlessLbPair) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetRentAccount sets the "rent" account. +func (inst *InitializeCustomizablePermissionlessLbPair) SetRentAccount(rent ag_solanago.PublicKey) *InitializeCustomizablePermissionlessLbPair { + inst.AccountMetaSlice[11] = ag_solanago.Meta(rent) + return inst +} + +// GetRentAccount gets the "rent" account. +func (inst *InitializeCustomizablePermissionlessLbPair) GetRentAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetEventAuthorityAccount sets the "eventAuthority" account. +func (inst *InitializeCustomizablePermissionlessLbPair) SetEventAuthorityAccount(eventAuthority ag_solanago.PublicKey) *InitializeCustomizablePermissionlessLbPair { + inst.AccountMetaSlice[12] = ag_solanago.Meta(eventAuthority) + return inst +} + +// GetEventAuthorityAccount gets the "eventAuthority" account. +func (inst *InitializeCustomizablePermissionlessLbPair) GetEventAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetProgramAccount sets the "program" account. +func (inst *InitializeCustomizablePermissionlessLbPair) SetProgramAccount(program ag_solanago.PublicKey) *InitializeCustomizablePermissionlessLbPair { + inst.AccountMetaSlice[13] = ag_solanago.Meta(program) + return inst +} + +// GetProgramAccount gets the "program" account. +func (inst *InitializeCustomizablePermissionlessLbPair) GetProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +func (inst InitializeCustomizablePermissionlessLbPair) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_InitializeCustomizablePermissionlessLbPair, + }} +} + +// 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 InitializeCustomizablePermissionlessLbPair) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *InitializeCustomizablePermissionlessLbPair) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.Params == nil { + return errors.New("Params parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.LbPair is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.BinArrayBitmapExtension is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.TokenMintX is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.TokenMintY is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.ReserveX is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.ReserveY is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.Oracle is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.UserTokenX is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.Funder is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.SystemProgram is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.Rent is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.EventAuthority is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.Program is not set") + } + } + return nil +} + +func (inst *InitializeCustomizablePermissionlessLbPair) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("InitializeCustomizablePermissionlessLbPair")). + // + 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("Params", *inst.Params)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=14]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" lbPair", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta("binArrayBitmapExtension", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" tokenMintX", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" tokenMintY", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" reserveX", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" reserveY", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" oracle", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" userTokenX", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" funder", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" systemProgram", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" rent", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" eventAuthority", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" program", inst.AccountMetaSlice.Get(13))) + }) + }) + }) +} + +func (obj InitializeCustomizablePermissionlessLbPair) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Params` param: + err = encoder.Encode(obj.Params) + if err != nil { + return err + } + return nil +} +func (obj *InitializeCustomizablePermissionlessLbPair) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Params`: + err = decoder.Decode(&obj.Params) + if err != nil { + return err + } + return nil +} + +// NewInitializeCustomizablePermissionlessLbPairInstruction declares a new InitializeCustomizablePermissionlessLbPair instruction with the provided parameters and accounts. +func NewInitializeCustomizablePermissionlessLbPairInstruction( + // Parameters: + params CustomizableParams, + // Accounts: + lbPair ag_solanago.PublicKey, + binArrayBitmapExtension ag_solanago.PublicKey, + tokenMintX ag_solanago.PublicKey, + tokenMintY ag_solanago.PublicKey, + reserveX ag_solanago.PublicKey, + reserveY ag_solanago.PublicKey, + oracle ag_solanago.PublicKey, + userTokenX ag_solanago.PublicKey, + funder ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey, + rent ag_solanago.PublicKey, + eventAuthority ag_solanago.PublicKey, + program ag_solanago.PublicKey) *InitializeCustomizablePermissionlessLbPair { + return NewInitializeCustomizablePermissionlessLbPairInstructionBuilder(). + SetParams(params). + SetLbPairAccount(lbPair). + SetBinArrayBitmapExtensionAccount(binArrayBitmapExtension). + SetTokenMintXAccount(tokenMintX). + SetTokenMintYAccount(tokenMintY). + SetReserveXAccount(reserveX). + SetReserveYAccount(reserveY). + SetOracleAccount(oracle). + SetUserTokenXAccount(userTokenX). + SetFunderAccount(funder). + SetTokenProgramAccount(tokenProgram). + SetSystemProgramAccount(systemProgram). + SetRentAccount(rent). + SetEventAuthorityAccount(eventAuthority). + SetProgramAccount(program) +} diff --git a/programs/meteoradlmm/InitializeCustomizablePermissionlessLbPair_test.go b/programs/meteoradlmm/InitializeCustomizablePermissionlessLbPair_test.go new file mode 100644 index 00000000..b7acbb3e --- /dev/null +++ b/programs/meteoradlmm/InitializeCustomizablePermissionlessLbPair_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_InitializeCustomizablePermissionlessLbPair(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("InitializeCustomizablePermissionlessLbPair"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(InitializeCustomizablePermissionlessLbPair) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(InitializeCustomizablePermissionlessLbPair) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/InitializeLbPair.go b/programs/meteoradlmm/InitializeLbPair.go new file mode 100644 index 00000000..3d93fcc4 --- /dev/null +++ b/programs/meteoradlmm/InitializeLbPair.go @@ -0,0 +1,397 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// InitializeLbPair is the `initializeLbPair` instruction. +type InitializeLbPair struct { + ActiveId *int32 + BinStep *uint16 + + // [0] = [WRITE] lbPair + // + // [1] = [WRITE] binArrayBitmapExtension + // + // [2] = [] tokenMintX + // + // [3] = [] tokenMintY + // + // [4] = [WRITE] reserveX + // + // [5] = [WRITE] reserveY + // + // [6] = [WRITE] oracle + // + // [7] = [] presetParameter + // + // [8] = [WRITE, SIGNER] funder + // + // [9] = [] tokenProgram + // + // [10] = [] systemProgram + // + // [11] = [] rent + // + // [12] = [] eventAuthority + // + // [13] = [] program + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewInitializeLbPairInstructionBuilder creates a new `InitializeLbPair` instruction builder. +func NewInitializeLbPairInstructionBuilder() *InitializeLbPair { + nd := &InitializeLbPair{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 14), + } + return nd +} + +// SetActiveId sets the "activeId" parameter. +func (inst *InitializeLbPair) SetActiveId(activeId int32) *InitializeLbPair { + inst.ActiveId = &activeId + return inst +} + +// SetBinStep sets the "binStep" parameter. +func (inst *InitializeLbPair) SetBinStep(binStep uint16) *InitializeLbPair { + inst.BinStep = &binStep + return inst +} + +// SetLbPairAccount sets the "lbPair" account. +func (inst *InitializeLbPair) SetLbPairAccount(lbPair ag_solanago.PublicKey) *InitializeLbPair { + inst.AccountMetaSlice[0] = ag_solanago.Meta(lbPair).WRITE() + return inst +} + +// GetLbPairAccount gets the "lbPair" account. +func (inst *InitializeLbPair) GetLbPairAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetBinArrayBitmapExtensionAccount sets the "binArrayBitmapExtension" account. +func (inst *InitializeLbPair) SetBinArrayBitmapExtensionAccount(binArrayBitmapExtension ag_solanago.PublicKey) *InitializeLbPair { + inst.AccountMetaSlice[1] = ag_solanago.Meta(binArrayBitmapExtension).WRITE() + return inst +} + +// GetBinArrayBitmapExtensionAccount gets the "binArrayBitmapExtension" account. +func (inst *InitializeLbPair) GetBinArrayBitmapExtensionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetTokenMintXAccount sets the "tokenMintX" account. +func (inst *InitializeLbPair) SetTokenMintXAccount(tokenMintX ag_solanago.PublicKey) *InitializeLbPair { + inst.AccountMetaSlice[2] = ag_solanago.Meta(tokenMintX) + return inst +} + +// GetTokenMintXAccount gets the "tokenMintX" account. +func (inst *InitializeLbPair) GetTokenMintXAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetTokenMintYAccount sets the "tokenMintY" account. +func (inst *InitializeLbPair) SetTokenMintYAccount(tokenMintY ag_solanago.PublicKey) *InitializeLbPair { + inst.AccountMetaSlice[3] = ag_solanago.Meta(tokenMintY) + return inst +} + +// GetTokenMintYAccount gets the "tokenMintY" account. +func (inst *InitializeLbPair) GetTokenMintYAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetReserveXAccount sets the "reserveX" account. +func (inst *InitializeLbPair) SetReserveXAccount(reserveX ag_solanago.PublicKey) *InitializeLbPair { + inst.AccountMetaSlice[4] = ag_solanago.Meta(reserveX).WRITE() + return inst +} + +// GetReserveXAccount gets the "reserveX" account. +func (inst *InitializeLbPair) GetReserveXAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetReserveYAccount sets the "reserveY" account. +func (inst *InitializeLbPair) SetReserveYAccount(reserveY ag_solanago.PublicKey) *InitializeLbPair { + inst.AccountMetaSlice[5] = ag_solanago.Meta(reserveY).WRITE() + return inst +} + +// GetReserveYAccount gets the "reserveY" account. +func (inst *InitializeLbPair) GetReserveYAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetOracleAccount sets the "oracle" account. +func (inst *InitializeLbPair) SetOracleAccount(oracle ag_solanago.PublicKey) *InitializeLbPair { + inst.AccountMetaSlice[6] = ag_solanago.Meta(oracle).WRITE() + return inst +} + +// GetOracleAccount gets the "oracle" account. +func (inst *InitializeLbPair) GetOracleAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetPresetParameterAccount sets the "presetParameter" account. +func (inst *InitializeLbPair) SetPresetParameterAccount(presetParameter ag_solanago.PublicKey) *InitializeLbPair { + inst.AccountMetaSlice[7] = ag_solanago.Meta(presetParameter) + return inst +} + +// GetPresetParameterAccount gets the "presetParameter" account. +func (inst *InitializeLbPair) GetPresetParameterAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetFunderAccount sets the "funder" account. +func (inst *InitializeLbPair) SetFunderAccount(funder ag_solanago.PublicKey) *InitializeLbPair { + inst.AccountMetaSlice[8] = ag_solanago.Meta(funder).WRITE().SIGNER() + return inst +} + +// GetFunderAccount gets the "funder" account. +func (inst *InitializeLbPair) GetFunderAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *InitializeLbPair) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *InitializeLbPair { + inst.AccountMetaSlice[9] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *InitializeLbPair) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +func (inst *InitializeLbPair) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *InitializeLbPair { + inst.AccountMetaSlice[10] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +func (inst *InitializeLbPair) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetRentAccount sets the "rent" account. +func (inst *InitializeLbPair) SetRentAccount(rent ag_solanago.PublicKey) *InitializeLbPair { + inst.AccountMetaSlice[11] = ag_solanago.Meta(rent) + return inst +} + +// GetRentAccount gets the "rent" account. +func (inst *InitializeLbPair) GetRentAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetEventAuthorityAccount sets the "eventAuthority" account. +func (inst *InitializeLbPair) SetEventAuthorityAccount(eventAuthority ag_solanago.PublicKey) *InitializeLbPair { + inst.AccountMetaSlice[12] = ag_solanago.Meta(eventAuthority) + return inst +} + +// GetEventAuthorityAccount gets the "eventAuthority" account. +func (inst *InitializeLbPair) GetEventAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetProgramAccount sets the "program" account. +func (inst *InitializeLbPair) SetProgramAccount(program ag_solanago.PublicKey) *InitializeLbPair { + inst.AccountMetaSlice[13] = ag_solanago.Meta(program) + return inst +} + +// GetProgramAccount gets the "program" account. +func (inst *InitializeLbPair) GetProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +func (inst InitializeLbPair) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_InitializeLbPair, + }} +} + +// 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 InitializeLbPair) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *InitializeLbPair) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.ActiveId == nil { + return errors.New("ActiveId parameter is not set") + } + if inst.BinStep == nil { + return errors.New("BinStep parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.LbPair is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.BinArrayBitmapExtension is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.TokenMintX is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.TokenMintY is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.ReserveX is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.ReserveY is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.Oracle is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.PresetParameter is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.Funder is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.SystemProgram is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.Rent is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.EventAuthority is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.Program is not set") + } + } + return nil +} + +func (inst *InitializeLbPair) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("InitializeLbPair")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=2]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param("ActiveId", *inst.ActiveId)) + paramsBranch.Child(ag_format.Param(" BinStep", *inst.BinStep)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=14]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" lbPair", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta("binArrayBitmapExtension", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" tokenMintX", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" tokenMintY", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" reserveX", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" reserveY", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" oracle", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" presetParameter", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" funder", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" systemProgram", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" rent", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" eventAuthority", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" program", inst.AccountMetaSlice.Get(13))) + }) + }) + }) +} + +func (obj InitializeLbPair) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `ActiveId` param: + err = encoder.Encode(obj.ActiveId) + if err != nil { + return err + } + // Serialize `BinStep` param: + err = encoder.Encode(obj.BinStep) + if err != nil { + return err + } + return nil +} +func (obj *InitializeLbPair) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `ActiveId`: + err = decoder.Decode(&obj.ActiveId) + if err != nil { + return err + } + // Deserialize `BinStep`: + err = decoder.Decode(&obj.BinStep) + if err != nil { + return err + } + return nil +} + +// NewInitializeLbPairInstruction declares a new InitializeLbPair instruction with the provided parameters and accounts. +func NewInitializeLbPairInstruction( + // Parameters: + activeId int32, + binStep uint16, + // Accounts: + lbPair ag_solanago.PublicKey, + binArrayBitmapExtension ag_solanago.PublicKey, + tokenMintX ag_solanago.PublicKey, + tokenMintY ag_solanago.PublicKey, + reserveX ag_solanago.PublicKey, + reserveY ag_solanago.PublicKey, + oracle ag_solanago.PublicKey, + presetParameter ag_solanago.PublicKey, + funder ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey, + rent ag_solanago.PublicKey, + eventAuthority ag_solanago.PublicKey, + program ag_solanago.PublicKey) *InitializeLbPair { + return NewInitializeLbPairInstructionBuilder(). + SetActiveId(activeId). + SetBinStep(binStep). + SetLbPairAccount(lbPair). + SetBinArrayBitmapExtensionAccount(binArrayBitmapExtension). + SetTokenMintXAccount(tokenMintX). + SetTokenMintYAccount(tokenMintY). + SetReserveXAccount(reserveX). + SetReserveYAccount(reserveY). + SetOracleAccount(oracle). + SetPresetParameterAccount(presetParameter). + SetFunderAccount(funder). + SetTokenProgramAccount(tokenProgram). + SetSystemProgramAccount(systemProgram). + SetRentAccount(rent). + SetEventAuthorityAccount(eventAuthority). + SetProgramAccount(program) +} diff --git a/programs/meteoradlmm/InitializeLbPair_test.go b/programs/meteoradlmm/InitializeLbPair_test.go new file mode 100644 index 00000000..b39a5f0d --- /dev/null +++ b/programs/meteoradlmm/InitializeLbPair_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_InitializeLbPair(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("InitializeLbPair"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(InitializeLbPair) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(InitializeLbPair) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/InitializePermissionLbPair.go b/programs/meteoradlmm/InitializePermissionLbPair.go new file mode 100644 index 00000000..27595e33 --- /dev/null +++ b/programs/meteoradlmm/InitializePermissionLbPair.go @@ -0,0 +1,374 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// InitializePermissionLbPair is the `initializePermissionLbPair` instruction. +type InitializePermissionLbPair struct { + IxData *InitPermissionPairIx + + // [0] = [SIGNER] base + // + // [1] = [WRITE] lbPair + // + // [2] = [WRITE] binArrayBitmapExtension + // + // [3] = [] tokenMintX + // + // [4] = [] tokenMintY + // + // [5] = [WRITE] reserveX + // + // [6] = [WRITE] reserveY + // + // [7] = [WRITE] oracle + // + // [8] = [WRITE, SIGNER] admin + // + // [9] = [] tokenProgram + // + // [10] = [] systemProgram + // + // [11] = [] rent + // + // [12] = [] eventAuthority + // + // [13] = [] program + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewInitializePermissionLbPairInstructionBuilder creates a new `InitializePermissionLbPair` instruction builder. +func NewInitializePermissionLbPairInstructionBuilder() *InitializePermissionLbPair { + nd := &InitializePermissionLbPair{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 14), + } + return nd +} + +// SetIxData sets the "ixData" parameter. +func (inst *InitializePermissionLbPair) SetIxData(ixData InitPermissionPairIx) *InitializePermissionLbPair { + inst.IxData = &ixData + return inst +} + +// SetBaseAccount sets the "base" account. +func (inst *InitializePermissionLbPair) SetBaseAccount(base ag_solanago.PublicKey) *InitializePermissionLbPair { + inst.AccountMetaSlice[0] = ag_solanago.Meta(base).SIGNER() + return inst +} + +// GetBaseAccount gets the "base" account. +func (inst *InitializePermissionLbPair) GetBaseAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetLbPairAccount sets the "lbPair" account. +func (inst *InitializePermissionLbPair) SetLbPairAccount(lbPair ag_solanago.PublicKey) *InitializePermissionLbPair { + inst.AccountMetaSlice[1] = ag_solanago.Meta(lbPair).WRITE() + return inst +} + +// GetLbPairAccount gets the "lbPair" account. +func (inst *InitializePermissionLbPair) GetLbPairAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetBinArrayBitmapExtensionAccount sets the "binArrayBitmapExtension" account. +func (inst *InitializePermissionLbPair) SetBinArrayBitmapExtensionAccount(binArrayBitmapExtension ag_solanago.PublicKey) *InitializePermissionLbPair { + inst.AccountMetaSlice[2] = ag_solanago.Meta(binArrayBitmapExtension).WRITE() + return inst +} + +// GetBinArrayBitmapExtensionAccount gets the "binArrayBitmapExtension" account. +func (inst *InitializePermissionLbPair) GetBinArrayBitmapExtensionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetTokenMintXAccount sets the "tokenMintX" account. +func (inst *InitializePermissionLbPair) SetTokenMintXAccount(tokenMintX ag_solanago.PublicKey) *InitializePermissionLbPair { + inst.AccountMetaSlice[3] = ag_solanago.Meta(tokenMintX) + return inst +} + +// GetTokenMintXAccount gets the "tokenMintX" account. +func (inst *InitializePermissionLbPair) GetTokenMintXAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetTokenMintYAccount sets the "tokenMintY" account. +func (inst *InitializePermissionLbPair) SetTokenMintYAccount(tokenMintY ag_solanago.PublicKey) *InitializePermissionLbPair { + inst.AccountMetaSlice[4] = ag_solanago.Meta(tokenMintY) + return inst +} + +// GetTokenMintYAccount gets the "tokenMintY" account. +func (inst *InitializePermissionLbPair) GetTokenMintYAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetReserveXAccount sets the "reserveX" account. +func (inst *InitializePermissionLbPair) SetReserveXAccount(reserveX ag_solanago.PublicKey) *InitializePermissionLbPair { + inst.AccountMetaSlice[5] = ag_solanago.Meta(reserveX).WRITE() + return inst +} + +// GetReserveXAccount gets the "reserveX" account. +func (inst *InitializePermissionLbPair) GetReserveXAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetReserveYAccount sets the "reserveY" account. +func (inst *InitializePermissionLbPair) SetReserveYAccount(reserveY ag_solanago.PublicKey) *InitializePermissionLbPair { + inst.AccountMetaSlice[6] = ag_solanago.Meta(reserveY).WRITE() + return inst +} + +// GetReserveYAccount gets the "reserveY" account. +func (inst *InitializePermissionLbPair) GetReserveYAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetOracleAccount sets the "oracle" account. +func (inst *InitializePermissionLbPair) SetOracleAccount(oracle ag_solanago.PublicKey) *InitializePermissionLbPair { + inst.AccountMetaSlice[7] = ag_solanago.Meta(oracle).WRITE() + return inst +} + +// GetOracleAccount gets the "oracle" account. +func (inst *InitializePermissionLbPair) GetOracleAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetAdminAccount sets the "admin" account. +func (inst *InitializePermissionLbPair) SetAdminAccount(admin ag_solanago.PublicKey) *InitializePermissionLbPair { + inst.AccountMetaSlice[8] = ag_solanago.Meta(admin).WRITE().SIGNER() + return inst +} + +// GetAdminAccount gets the "admin" account. +func (inst *InitializePermissionLbPair) GetAdminAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *InitializePermissionLbPair) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *InitializePermissionLbPair { + inst.AccountMetaSlice[9] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *InitializePermissionLbPair) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +func (inst *InitializePermissionLbPair) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *InitializePermissionLbPair { + inst.AccountMetaSlice[10] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +func (inst *InitializePermissionLbPair) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetRentAccount sets the "rent" account. +func (inst *InitializePermissionLbPair) SetRentAccount(rent ag_solanago.PublicKey) *InitializePermissionLbPair { + inst.AccountMetaSlice[11] = ag_solanago.Meta(rent) + return inst +} + +// GetRentAccount gets the "rent" account. +func (inst *InitializePermissionLbPair) GetRentAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetEventAuthorityAccount sets the "eventAuthority" account. +func (inst *InitializePermissionLbPair) SetEventAuthorityAccount(eventAuthority ag_solanago.PublicKey) *InitializePermissionLbPair { + inst.AccountMetaSlice[12] = ag_solanago.Meta(eventAuthority) + return inst +} + +// GetEventAuthorityAccount gets the "eventAuthority" account. +func (inst *InitializePermissionLbPair) GetEventAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetProgramAccount sets the "program" account. +func (inst *InitializePermissionLbPair) SetProgramAccount(program ag_solanago.PublicKey) *InitializePermissionLbPair { + inst.AccountMetaSlice[13] = ag_solanago.Meta(program) + return inst +} + +// GetProgramAccount gets the "program" account. +func (inst *InitializePermissionLbPair) GetProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +func (inst InitializePermissionLbPair) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_InitializePermissionLbPair, + }} +} + +// 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 InitializePermissionLbPair) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *InitializePermissionLbPair) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.IxData == nil { + return errors.New("IxData parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Base is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.LbPair is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.BinArrayBitmapExtension is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.TokenMintX is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.TokenMintY is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.ReserveX is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.ReserveY is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.Oracle is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.Admin is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.SystemProgram is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.Rent is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.EventAuthority is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.Program is not set") + } + } + return nil +} + +func (inst *InitializePermissionLbPair) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("InitializePermissionLbPair")). + // + 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("IxData", *inst.IxData)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=14]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" base", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" lbPair", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta("binArrayBitmapExtension", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" tokenMintX", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" tokenMintY", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" reserveX", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" reserveY", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" oracle", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" admin", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" systemProgram", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" rent", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" eventAuthority", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" program", inst.AccountMetaSlice.Get(13))) + }) + }) + }) +} + +func (obj InitializePermissionLbPair) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `IxData` param: + err = encoder.Encode(obj.IxData) + if err != nil { + return err + } + return nil +} +func (obj *InitializePermissionLbPair) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `IxData`: + err = decoder.Decode(&obj.IxData) + if err != nil { + return err + } + return nil +} + +// NewInitializePermissionLbPairInstruction declares a new InitializePermissionLbPair instruction with the provided parameters and accounts. +func NewInitializePermissionLbPairInstruction( + // Parameters: + ixData InitPermissionPairIx, + // Accounts: + base ag_solanago.PublicKey, + lbPair ag_solanago.PublicKey, + binArrayBitmapExtension ag_solanago.PublicKey, + tokenMintX ag_solanago.PublicKey, + tokenMintY ag_solanago.PublicKey, + reserveX ag_solanago.PublicKey, + reserveY ag_solanago.PublicKey, + oracle ag_solanago.PublicKey, + admin ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey, + rent ag_solanago.PublicKey, + eventAuthority ag_solanago.PublicKey, + program ag_solanago.PublicKey) *InitializePermissionLbPair { + return NewInitializePermissionLbPairInstructionBuilder(). + SetIxData(ixData). + SetBaseAccount(base). + SetLbPairAccount(lbPair). + SetBinArrayBitmapExtensionAccount(binArrayBitmapExtension). + SetTokenMintXAccount(tokenMintX). + SetTokenMintYAccount(tokenMintY). + SetReserveXAccount(reserveX). + SetReserveYAccount(reserveY). + SetOracleAccount(oracle). + SetAdminAccount(admin). + SetTokenProgramAccount(tokenProgram). + SetSystemProgramAccount(systemProgram). + SetRentAccount(rent). + SetEventAuthorityAccount(eventAuthority). + SetProgramAccount(program) +} diff --git a/programs/meteoradlmm/InitializePermissionLbPair_test.go b/programs/meteoradlmm/InitializePermissionLbPair_test.go new file mode 100644 index 00000000..0a0be7dc --- /dev/null +++ b/programs/meteoradlmm/InitializePermissionLbPair_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_InitializePermissionLbPair(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("InitializePermissionLbPair"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(InitializePermissionLbPair) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(InitializePermissionLbPair) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/InitializePosition.go b/programs/meteoradlmm/InitializePosition.go new file mode 100644 index 00000000..cb156cc6 --- /dev/null +++ b/programs/meteoradlmm/InitializePosition.go @@ -0,0 +1,283 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// InitializePosition is the `initializePosition` instruction. +type InitializePosition struct { + LowerBinId *int32 + Width *int32 + + // [0] = [WRITE, SIGNER] payer + // + // [1] = [WRITE, SIGNER] position + // + // [2] = [] lbPair + // + // [3] = [SIGNER] owner + // + // [4] = [] systemProgram + // + // [5] = [] rent + // + // [6] = [] eventAuthority + // + // [7] = [] program + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewInitializePositionInstructionBuilder creates a new `InitializePosition` instruction builder. +func NewInitializePositionInstructionBuilder() *InitializePosition { + nd := &InitializePosition{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 8), + } + return nd +} + +// SetLowerBinId sets the "lowerBinId" parameter. +func (inst *InitializePosition) SetLowerBinId(lowerBinId int32) *InitializePosition { + inst.LowerBinId = &lowerBinId + return inst +} + +// SetWidth sets the "width" parameter. +func (inst *InitializePosition) SetWidth(width int32) *InitializePosition { + inst.Width = &width + return inst +} + +// SetPayerAccount sets the "payer" account. +func (inst *InitializePosition) SetPayerAccount(payer ag_solanago.PublicKey) *InitializePosition { + inst.AccountMetaSlice[0] = ag_solanago.Meta(payer).WRITE().SIGNER() + return inst +} + +// GetPayerAccount gets the "payer" account. +func (inst *InitializePosition) GetPayerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetPositionAccount sets the "position" account. +func (inst *InitializePosition) SetPositionAccount(position ag_solanago.PublicKey) *InitializePosition { + inst.AccountMetaSlice[1] = ag_solanago.Meta(position).WRITE().SIGNER() + return inst +} + +// GetPositionAccount gets the "position" account. +func (inst *InitializePosition) GetPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetLbPairAccount sets the "lbPair" account. +func (inst *InitializePosition) SetLbPairAccount(lbPair ag_solanago.PublicKey) *InitializePosition { + inst.AccountMetaSlice[2] = ag_solanago.Meta(lbPair) + return inst +} + +// GetLbPairAccount gets the "lbPair" account. +func (inst *InitializePosition) GetLbPairAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetOwnerAccount sets the "owner" account. +func (inst *InitializePosition) SetOwnerAccount(owner ag_solanago.PublicKey) *InitializePosition { + inst.AccountMetaSlice[3] = ag_solanago.Meta(owner).SIGNER() + return inst +} + +// GetOwnerAccount gets the "owner" account. +func (inst *InitializePosition) GetOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +func (inst *InitializePosition) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *InitializePosition { + inst.AccountMetaSlice[4] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +func (inst *InitializePosition) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetRentAccount sets the "rent" account. +func (inst *InitializePosition) SetRentAccount(rent ag_solanago.PublicKey) *InitializePosition { + inst.AccountMetaSlice[5] = ag_solanago.Meta(rent) + return inst +} + +// GetRentAccount gets the "rent" account. +func (inst *InitializePosition) GetRentAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetEventAuthorityAccount sets the "eventAuthority" account. +func (inst *InitializePosition) SetEventAuthorityAccount(eventAuthority ag_solanago.PublicKey) *InitializePosition { + inst.AccountMetaSlice[6] = ag_solanago.Meta(eventAuthority) + return inst +} + +// GetEventAuthorityAccount gets the "eventAuthority" account. +func (inst *InitializePosition) GetEventAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetProgramAccount sets the "program" account. +func (inst *InitializePosition) SetProgramAccount(program ag_solanago.PublicKey) *InitializePosition { + inst.AccountMetaSlice[7] = ag_solanago.Meta(program) + return inst +} + +// GetProgramAccount gets the "program" account. +func (inst *InitializePosition) GetProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +func (inst InitializePosition) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_InitializePosition, + }} +} + +// 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 InitializePosition) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *InitializePosition) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.LowerBinId == nil { + return errors.New("LowerBinId parameter is not set") + } + if inst.Width == nil { + return errors.New("Width parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Payer is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Position is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.LbPair is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.Owner is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.SystemProgram is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.Rent is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.EventAuthority is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.Program is not set") + } + } + return nil +} + +func (inst *InitializePosition) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("InitializePosition")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=2]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param("LowerBinId", *inst.LowerBinId)) + paramsBranch.Child(ag_format.Param(" Width", *inst.Width)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=8]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" payer", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" position", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" lbPair", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" owner", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" systemProgram", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" rent", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta("eventAuthority", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" program", inst.AccountMetaSlice.Get(7))) + }) + }) + }) +} + +func (obj InitializePosition) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `LowerBinId` param: + err = encoder.Encode(obj.LowerBinId) + if err != nil { + return err + } + // Serialize `Width` param: + err = encoder.Encode(obj.Width) + if err != nil { + return err + } + return nil +} +func (obj *InitializePosition) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `LowerBinId`: + err = decoder.Decode(&obj.LowerBinId) + if err != nil { + return err + } + // Deserialize `Width`: + err = decoder.Decode(&obj.Width) + if err != nil { + return err + } + return nil +} + +// NewInitializePositionInstruction declares a new InitializePosition instruction with the provided parameters and accounts. +func NewInitializePositionInstruction( + // Parameters: + lowerBinId int32, + width int32, + // Accounts: + payer ag_solanago.PublicKey, + position ag_solanago.PublicKey, + lbPair ag_solanago.PublicKey, + owner ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey, + rent ag_solanago.PublicKey, + eventAuthority ag_solanago.PublicKey, + program ag_solanago.PublicKey) *InitializePosition { + return NewInitializePositionInstructionBuilder(). + SetLowerBinId(lowerBinId). + SetWidth(width). + SetPayerAccount(payer). + SetPositionAccount(position). + SetLbPairAccount(lbPair). + SetOwnerAccount(owner). + SetSystemProgramAccount(systemProgram). + SetRentAccount(rent). + SetEventAuthorityAccount(eventAuthority). + SetProgramAccount(program) +} diff --git a/programs/meteoradlmm/InitializePositionByOperator.go b/programs/meteoradlmm/InitializePositionByOperator.go new file mode 100644 index 00000000..d94a4ce0 --- /dev/null +++ b/programs/meteoradlmm/InitializePositionByOperator.go @@ -0,0 +1,389 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// InitializePositionByOperator is the `initializePositionByOperator` instruction. +type InitializePositionByOperator struct { + LowerBinId *int32 + Width *int32 + FeeOwner *ag_solanago.PublicKey + LockReleasePoint *uint64 + + // [0] = [WRITE, SIGNER] payer + // + // [1] = [SIGNER] base + // + // [2] = [WRITE] position + // + // [3] = [] lbPair + // + // [4] = [] owner + // + // [5] = [SIGNER] operator + // ··········· operator + // + // [6] = [] operatorTokenX + // + // [7] = [] ownerTokenX + // + // [8] = [] systemProgram + // + // [9] = [] eventAuthority + // + // [10] = [] program + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewInitializePositionByOperatorInstructionBuilder creates a new `InitializePositionByOperator` instruction builder. +func NewInitializePositionByOperatorInstructionBuilder() *InitializePositionByOperator { + nd := &InitializePositionByOperator{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 11), + } + return nd +} + +// SetLowerBinId sets the "lowerBinId" parameter. +func (inst *InitializePositionByOperator) SetLowerBinId(lowerBinId int32) *InitializePositionByOperator { + inst.LowerBinId = &lowerBinId + return inst +} + +// SetWidth sets the "width" parameter. +func (inst *InitializePositionByOperator) SetWidth(width int32) *InitializePositionByOperator { + inst.Width = &width + return inst +} + +// SetFeeOwner sets the "feeOwner" parameter. +func (inst *InitializePositionByOperator) SetFeeOwner(feeOwner ag_solanago.PublicKey) *InitializePositionByOperator { + inst.FeeOwner = &feeOwner + return inst +} + +// SetLockReleasePoint sets the "lockReleasePoint" parameter. +func (inst *InitializePositionByOperator) SetLockReleasePoint(lockReleasePoint uint64) *InitializePositionByOperator { + inst.LockReleasePoint = &lockReleasePoint + return inst +} + +// SetPayerAccount sets the "payer" account. +func (inst *InitializePositionByOperator) SetPayerAccount(payer ag_solanago.PublicKey) *InitializePositionByOperator { + inst.AccountMetaSlice[0] = ag_solanago.Meta(payer).WRITE().SIGNER() + return inst +} + +// GetPayerAccount gets the "payer" account. +func (inst *InitializePositionByOperator) GetPayerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetBaseAccount sets the "base" account. +func (inst *InitializePositionByOperator) SetBaseAccount(base ag_solanago.PublicKey) *InitializePositionByOperator { + inst.AccountMetaSlice[1] = ag_solanago.Meta(base).SIGNER() + return inst +} + +// GetBaseAccount gets the "base" account. +func (inst *InitializePositionByOperator) GetBaseAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetPositionAccount sets the "position" account. +func (inst *InitializePositionByOperator) SetPositionAccount(position ag_solanago.PublicKey) *InitializePositionByOperator { + inst.AccountMetaSlice[2] = ag_solanago.Meta(position).WRITE() + return inst +} + +// GetPositionAccount gets the "position" account. +func (inst *InitializePositionByOperator) GetPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetLbPairAccount sets the "lbPair" account. +func (inst *InitializePositionByOperator) SetLbPairAccount(lbPair ag_solanago.PublicKey) *InitializePositionByOperator { + inst.AccountMetaSlice[3] = ag_solanago.Meta(lbPair) + return inst +} + +// GetLbPairAccount gets the "lbPair" account. +func (inst *InitializePositionByOperator) GetLbPairAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetOwnerAccount sets the "owner" account. +func (inst *InitializePositionByOperator) SetOwnerAccount(owner ag_solanago.PublicKey) *InitializePositionByOperator { + inst.AccountMetaSlice[4] = ag_solanago.Meta(owner) + return inst +} + +// GetOwnerAccount gets the "owner" account. +func (inst *InitializePositionByOperator) GetOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetOperatorAccount sets the "operator" account. +// operator +func (inst *InitializePositionByOperator) SetOperatorAccount(operator ag_solanago.PublicKey) *InitializePositionByOperator { + inst.AccountMetaSlice[5] = ag_solanago.Meta(operator).SIGNER() + return inst +} + +// GetOperatorAccount gets the "operator" account. +// operator +func (inst *InitializePositionByOperator) GetOperatorAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetOperatorTokenXAccount sets the "operatorTokenX" account. +func (inst *InitializePositionByOperator) SetOperatorTokenXAccount(operatorTokenX ag_solanago.PublicKey) *InitializePositionByOperator { + inst.AccountMetaSlice[6] = ag_solanago.Meta(operatorTokenX) + return inst +} + +// GetOperatorTokenXAccount gets the "operatorTokenX" account. +func (inst *InitializePositionByOperator) GetOperatorTokenXAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetOwnerTokenXAccount sets the "ownerTokenX" account. +func (inst *InitializePositionByOperator) SetOwnerTokenXAccount(ownerTokenX ag_solanago.PublicKey) *InitializePositionByOperator { + inst.AccountMetaSlice[7] = ag_solanago.Meta(ownerTokenX) + return inst +} + +// GetOwnerTokenXAccount gets the "ownerTokenX" account. +func (inst *InitializePositionByOperator) GetOwnerTokenXAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +func (inst *InitializePositionByOperator) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *InitializePositionByOperator { + inst.AccountMetaSlice[8] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +func (inst *InitializePositionByOperator) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetEventAuthorityAccount sets the "eventAuthority" account. +func (inst *InitializePositionByOperator) SetEventAuthorityAccount(eventAuthority ag_solanago.PublicKey) *InitializePositionByOperator { + inst.AccountMetaSlice[9] = ag_solanago.Meta(eventAuthority) + return inst +} + +// GetEventAuthorityAccount gets the "eventAuthority" account. +func (inst *InitializePositionByOperator) GetEventAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetProgramAccount sets the "program" account. +func (inst *InitializePositionByOperator) SetProgramAccount(program ag_solanago.PublicKey) *InitializePositionByOperator { + inst.AccountMetaSlice[10] = ag_solanago.Meta(program) + return inst +} + +// GetProgramAccount gets the "program" account. +func (inst *InitializePositionByOperator) GetProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +func (inst InitializePositionByOperator) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_InitializePositionByOperator, + }} +} + +// 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 InitializePositionByOperator) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *InitializePositionByOperator) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.LowerBinId == nil { + return errors.New("LowerBinId parameter is not set") + } + if inst.Width == nil { + return errors.New("Width parameter is not set") + } + if inst.FeeOwner == nil { + return errors.New("FeeOwner parameter is not set") + } + if inst.LockReleasePoint == nil { + return errors.New("LockReleasePoint parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Payer is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Base is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.Position is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.LbPair is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.Owner is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.Operator is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.OperatorTokenX is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.OwnerTokenX is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.SystemProgram is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.EventAuthority is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.Program is not set") + } + } + return nil +} + +func (inst *InitializePositionByOperator) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("InitializePositionByOperator")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=4]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" LowerBinId", *inst.LowerBinId)) + paramsBranch.Child(ag_format.Param(" Width", *inst.Width)) + paramsBranch.Child(ag_format.Param(" FeeOwner", *inst.FeeOwner)) + paramsBranch.Child(ag_format.Param("LockReleasePoint", *inst.LockReleasePoint)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=11]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" payer", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" base", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" position", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" lbPair", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" owner", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" operator", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta("operatorTokenX", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" ownerTokenX", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" systemProgram", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta("eventAuthority", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" program", inst.AccountMetaSlice.Get(10))) + }) + }) + }) +} + +func (obj InitializePositionByOperator) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `LowerBinId` param: + err = encoder.Encode(obj.LowerBinId) + if err != nil { + return err + } + // Serialize `Width` param: + err = encoder.Encode(obj.Width) + if err != nil { + return err + } + // Serialize `FeeOwner` param: + err = encoder.Encode(obj.FeeOwner) + if err != nil { + return err + } + // Serialize `LockReleasePoint` param: + err = encoder.Encode(obj.LockReleasePoint) + if err != nil { + return err + } + return nil +} +func (obj *InitializePositionByOperator) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `LowerBinId`: + err = decoder.Decode(&obj.LowerBinId) + if err != nil { + return err + } + // Deserialize `Width`: + err = decoder.Decode(&obj.Width) + if err != nil { + return err + } + // Deserialize `FeeOwner`: + err = decoder.Decode(&obj.FeeOwner) + if err != nil { + return err + } + // Deserialize `LockReleasePoint`: + err = decoder.Decode(&obj.LockReleasePoint) + if err != nil { + return err + } + return nil +} + +// NewInitializePositionByOperatorInstruction declares a new InitializePositionByOperator instruction with the provided parameters and accounts. +func NewInitializePositionByOperatorInstruction( + // Parameters: + lowerBinId int32, + width int32, + feeOwner ag_solanago.PublicKey, + lockReleasePoint uint64, + // Accounts: + payer ag_solanago.PublicKey, + base ag_solanago.PublicKey, + position ag_solanago.PublicKey, + lbPair ag_solanago.PublicKey, + owner ag_solanago.PublicKey, + operator ag_solanago.PublicKey, + operatorTokenX ag_solanago.PublicKey, + ownerTokenX ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey, + eventAuthority ag_solanago.PublicKey, + program ag_solanago.PublicKey) *InitializePositionByOperator { + return NewInitializePositionByOperatorInstructionBuilder(). + SetLowerBinId(lowerBinId). + SetWidth(width). + SetFeeOwner(feeOwner). + SetLockReleasePoint(lockReleasePoint). + SetPayerAccount(payer). + SetBaseAccount(base). + SetPositionAccount(position). + SetLbPairAccount(lbPair). + SetOwnerAccount(owner). + SetOperatorAccount(operator). + SetOperatorTokenXAccount(operatorTokenX). + SetOwnerTokenXAccount(ownerTokenX). + SetSystemProgramAccount(systemProgram). + SetEventAuthorityAccount(eventAuthority). + SetProgramAccount(program) +} diff --git a/programs/meteoradlmm/InitializePositionByOperator_test.go b/programs/meteoradlmm/InitializePositionByOperator_test.go new file mode 100644 index 00000000..5eb0cb33 --- /dev/null +++ b/programs/meteoradlmm/InitializePositionByOperator_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_InitializePositionByOperator(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("InitializePositionByOperator"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(InitializePositionByOperator) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(InitializePositionByOperator) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/InitializePositionPda.go b/programs/meteoradlmm/InitializePositionPda.go new file mode 100644 index 00000000..8ceb8ca7 --- /dev/null +++ b/programs/meteoradlmm/InitializePositionPda.go @@ -0,0 +1,305 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// InitializePositionPda is the `initializePositionPda` instruction. +type InitializePositionPda struct { + LowerBinId *int32 + Width *int32 + + // [0] = [WRITE, SIGNER] payer + // + // [1] = [SIGNER] base + // + // [2] = [WRITE] position + // + // [3] = [] lbPair + // + // [4] = [SIGNER] owner + // ··········· owner + // + // [5] = [] systemProgram + // + // [6] = [] rent + // + // [7] = [] eventAuthority + // + // [8] = [] program + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewInitializePositionPdaInstructionBuilder creates a new `InitializePositionPda` instruction builder. +func NewInitializePositionPdaInstructionBuilder() *InitializePositionPda { + nd := &InitializePositionPda{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 9), + } + return nd +} + +// SetLowerBinId sets the "lowerBinId" parameter. +func (inst *InitializePositionPda) SetLowerBinId(lowerBinId int32) *InitializePositionPda { + inst.LowerBinId = &lowerBinId + return inst +} + +// SetWidth sets the "width" parameter. +func (inst *InitializePositionPda) SetWidth(width int32) *InitializePositionPda { + inst.Width = &width + return inst +} + +// SetPayerAccount sets the "payer" account. +func (inst *InitializePositionPda) SetPayerAccount(payer ag_solanago.PublicKey) *InitializePositionPda { + inst.AccountMetaSlice[0] = ag_solanago.Meta(payer).WRITE().SIGNER() + return inst +} + +// GetPayerAccount gets the "payer" account. +func (inst *InitializePositionPda) GetPayerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetBaseAccount sets the "base" account. +func (inst *InitializePositionPda) SetBaseAccount(base ag_solanago.PublicKey) *InitializePositionPda { + inst.AccountMetaSlice[1] = ag_solanago.Meta(base).SIGNER() + return inst +} + +// GetBaseAccount gets the "base" account. +func (inst *InitializePositionPda) GetBaseAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetPositionAccount sets the "position" account. +func (inst *InitializePositionPda) SetPositionAccount(position ag_solanago.PublicKey) *InitializePositionPda { + inst.AccountMetaSlice[2] = ag_solanago.Meta(position).WRITE() + return inst +} + +// GetPositionAccount gets the "position" account. +func (inst *InitializePositionPda) GetPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetLbPairAccount sets the "lbPair" account. +func (inst *InitializePositionPda) SetLbPairAccount(lbPair ag_solanago.PublicKey) *InitializePositionPda { + inst.AccountMetaSlice[3] = ag_solanago.Meta(lbPair) + return inst +} + +// GetLbPairAccount gets the "lbPair" account. +func (inst *InitializePositionPda) GetLbPairAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetOwnerAccount sets the "owner" account. +// owner +func (inst *InitializePositionPda) SetOwnerAccount(owner ag_solanago.PublicKey) *InitializePositionPda { + inst.AccountMetaSlice[4] = ag_solanago.Meta(owner).SIGNER() + return inst +} + +// GetOwnerAccount gets the "owner" account. +// owner +func (inst *InitializePositionPda) GetOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +func (inst *InitializePositionPda) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *InitializePositionPda { + inst.AccountMetaSlice[5] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +func (inst *InitializePositionPda) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetRentAccount sets the "rent" account. +func (inst *InitializePositionPda) SetRentAccount(rent ag_solanago.PublicKey) *InitializePositionPda { + inst.AccountMetaSlice[6] = ag_solanago.Meta(rent) + return inst +} + +// GetRentAccount gets the "rent" account. +func (inst *InitializePositionPda) GetRentAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetEventAuthorityAccount sets the "eventAuthority" account. +func (inst *InitializePositionPda) SetEventAuthorityAccount(eventAuthority ag_solanago.PublicKey) *InitializePositionPda { + inst.AccountMetaSlice[7] = ag_solanago.Meta(eventAuthority) + return inst +} + +// GetEventAuthorityAccount gets the "eventAuthority" account. +func (inst *InitializePositionPda) GetEventAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetProgramAccount sets the "program" account. +func (inst *InitializePositionPda) SetProgramAccount(program ag_solanago.PublicKey) *InitializePositionPda { + inst.AccountMetaSlice[8] = ag_solanago.Meta(program) + return inst +} + +// GetProgramAccount gets the "program" account. +func (inst *InitializePositionPda) GetProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +func (inst InitializePositionPda) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_InitializePositionPda, + }} +} + +// 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 InitializePositionPda) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *InitializePositionPda) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.LowerBinId == nil { + return errors.New("LowerBinId parameter is not set") + } + if inst.Width == nil { + return errors.New("Width parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Payer is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Base is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.Position is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.LbPair is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.Owner is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.SystemProgram is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.Rent is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.EventAuthority is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.Program is not set") + } + } + return nil +} + +func (inst *InitializePositionPda) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("InitializePositionPda")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=2]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param("LowerBinId", *inst.LowerBinId)) + paramsBranch.Child(ag_format.Param(" Width", *inst.Width)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=9]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" payer", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" base", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" position", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" lbPair", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" owner", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" systemProgram", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" rent", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta("eventAuthority", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" program", inst.AccountMetaSlice.Get(8))) + }) + }) + }) +} + +func (obj InitializePositionPda) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `LowerBinId` param: + err = encoder.Encode(obj.LowerBinId) + if err != nil { + return err + } + // Serialize `Width` param: + err = encoder.Encode(obj.Width) + if err != nil { + return err + } + return nil +} +func (obj *InitializePositionPda) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `LowerBinId`: + err = decoder.Decode(&obj.LowerBinId) + if err != nil { + return err + } + // Deserialize `Width`: + err = decoder.Decode(&obj.Width) + if err != nil { + return err + } + return nil +} + +// NewInitializePositionPdaInstruction declares a new InitializePositionPda instruction with the provided parameters and accounts. +func NewInitializePositionPdaInstruction( + // Parameters: + lowerBinId int32, + width int32, + // Accounts: + payer ag_solanago.PublicKey, + base ag_solanago.PublicKey, + position ag_solanago.PublicKey, + lbPair ag_solanago.PublicKey, + owner ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey, + rent ag_solanago.PublicKey, + eventAuthority ag_solanago.PublicKey, + program ag_solanago.PublicKey) *InitializePositionPda { + return NewInitializePositionPdaInstructionBuilder(). + SetLowerBinId(lowerBinId). + SetWidth(width). + SetPayerAccount(payer). + SetBaseAccount(base). + SetPositionAccount(position). + SetLbPairAccount(lbPair). + SetOwnerAccount(owner). + SetSystemProgramAccount(systemProgram). + SetRentAccount(rent). + SetEventAuthorityAccount(eventAuthority). + SetProgramAccount(program) +} diff --git a/programs/meteoradlmm/InitializePositionPda_test.go b/programs/meteoradlmm/InitializePositionPda_test.go new file mode 100644 index 00000000..2ae80286 --- /dev/null +++ b/programs/meteoradlmm/InitializePositionPda_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_InitializePositionPda(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("InitializePositionPda"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(InitializePositionPda) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(InitializePositionPda) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/InitializePosition_test.go b/programs/meteoradlmm/InitializePosition_test.go new file mode 100644 index 00000000..27cd0de7 --- /dev/null +++ b/programs/meteoradlmm/InitializePosition_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_InitializePosition(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("InitializePosition"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(InitializePosition) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(InitializePosition) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/InitializePresetParameter.go b/programs/meteoradlmm/InitializePresetParameter.go new file mode 100644 index 00000000..ea207c1d --- /dev/null +++ b/programs/meteoradlmm/InitializePresetParameter.go @@ -0,0 +1,184 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// InitializePresetParameter is the `initializePresetParameter` instruction. +type InitializePresetParameter struct { + Ix *InitPresetParametersIx + + // [0] = [WRITE] presetParameter + // + // [1] = [WRITE, SIGNER] admin + // + // [2] = [] systemProgram + // + // [3] = [] rent + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewInitializePresetParameterInstructionBuilder creates a new `InitializePresetParameter` instruction builder. +func NewInitializePresetParameterInstructionBuilder() *InitializePresetParameter { + nd := &InitializePresetParameter{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 4), + } + return nd +} + +// SetIx sets the "ix" parameter. +func (inst *InitializePresetParameter) SetIx(ix InitPresetParametersIx) *InitializePresetParameter { + inst.Ix = &ix + return inst +} + +// SetPresetParameterAccount sets the "presetParameter" account. +func (inst *InitializePresetParameter) SetPresetParameterAccount(presetParameter ag_solanago.PublicKey) *InitializePresetParameter { + inst.AccountMetaSlice[0] = ag_solanago.Meta(presetParameter).WRITE() + return inst +} + +// GetPresetParameterAccount gets the "presetParameter" account. +func (inst *InitializePresetParameter) GetPresetParameterAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetAdminAccount sets the "admin" account. +func (inst *InitializePresetParameter) SetAdminAccount(admin ag_solanago.PublicKey) *InitializePresetParameter { + inst.AccountMetaSlice[1] = ag_solanago.Meta(admin).WRITE().SIGNER() + return inst +} + +// GetAdminAccount gets the "admin" account. +func (inst *InitializePresetParameter) GetAdminAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +func (inst *InitializePresetParameter) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *InitializePresetParameter { + inst.AccountMetaSlice[2] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +func (inst *InitializePresetParameter) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetRentAccount sets the "rent" account. +func (inst *InitializePresetParameter) SetRentAccount(rent ag_solanago.PublicKey) *InitializePresetParameter { + inst.AccountMetaSlice[3] = ag_solanago.Meta(rent) + return inst +} + +// GetRentAccount gets the "rent" account. +func (inst *InitializePresetParameter) GetRentAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +func (inst InitializePresetParameter) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_InitializePresetParameter, + }} +} + +// 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 InitializePresetParameter) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *InitializePresetParameter) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.Ix == nil { + return errors.New("Ix parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.PresetParameter is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Admin is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.SystemProgram is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.Rent is not set") + } + } + return nil +} + +func (inst *InitializePresetParameter) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("InitializePresetParameter")). + // + 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("Ix", *inst.Ix)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=4]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta("presetParameter", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" admin", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" systemProgram", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" rent", inst.AccountMetaSlice.Get(3))) + }) + }) + }) +} + +func (obj InitializePresetParameter) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Ix` param: + err = encoder.Encode(obj.Ix) + if err != nil { + return err + } + return nil +} +func (obj *InitializePresetParameter) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Ix`: + err = decoder.Decode(&obj.Ix) + if err != nil { + return err + } + return nil +} + +// NewInitializePresetParameterInstruction declares a new InitializePresetParameter instruction with the provided parameters and accounts. +func NewInitializePresetParameterInstruction( + // Parameters: + ix InitPresetParametersIx, + // Accounts: + presetParameter ag_solanago.PublicKey, + admin ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey, + rent ag_solanago.PublicKey) *InitializePresetParameter { + return NewInitializePresetParameterInstructionBuilder(). + SetIx(ix). + SetPresetParameterAccount(presetParameter). + SetAdminAccount(admin). + SetSystemProgramAccount(systemProgram). + SetRentAccount(rent) +} diff --git a/programs/meteoradlmm/InitializePresetParameter_test.go b/programs/meteoradlmm/InitializePresetParameter_test.go new file mode 100644 index 00000000..5dcdb6a0 --- /dev/null +++ b/programs/meteoradlmm/InitializePresetParameter_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_InitializePresetParameter(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("InitializePresetParameter"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(InitializePresetParameter) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(InitializePresetParameter) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/InitializeReward.go b/programs/meteoradlmm/InitializeReward.go new file mode 100644 index 00000000..0edca46f --- /dev/null +++ b/programs/meteoradlmm/InitializeReward.go @@ -0,0 +1,325 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// InitializeReward is the `initializeReward` instruction. +type InitializeReward struct { + RewardIndex *uint64 + RewardDuration *uint64 + Funder *ag_solanago.PublicKey + + // [0] = [WRITE] lbPair + // + // [1] = [WRITE] rewardVault + // + // [2] = [] rewardMint + // + // [3] = [WRITE, SIGNER] admin + // + // [4] = [] tokenProgram + // + // [5] = [] systemProgram + // + // [6] = [] rent + // + // [7] = [] eventAuthority + // + // [8] = [] program + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewInitializeRewardInstructionBuilder creates a new `InitializeReward` instruction builder. +func NewInitializeRewardInstructionBuilder() *InitializeReward { + nd := &InitializeReward{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 9), + } + return nd +} + +// SetRewardIndex sets the "rewardIndex" parameter. +func (inst *InitializeReward) SetRewardIndex(rewardIndex uint64) *InitializeReward { + inst.RewardIndex = &rewardIndex + return inst +} + +// SetRewardDuration sets the "rewardDuration" parameter. +func (inst *InitializeReward) SetRewardDuration(rewardDuration uint64) *InitializeReward { + inst.RewardDuration = &rewardDuration + return inst +} + +// SetFunder sets the "funder" parameter. +func (inst *InitializeReward) SetFunder(funder ag_solanago.PublicKey) *InitializeReward { + inst.Funder = &funder + return inst +} + +// SetLbPairAccount sets the "lbPair" account. +func (inst *InitializeReward) SetLbPairAccount(lbPair ag_solanago.PublicKey) *InitializeReward { + inst.AccountMetaSlice[0] = ag_solanago.Meta(lbPair).WRITE() + return inst +} + +// GetLbPairAccount gets the "lbPair" account. +func (inst *InitializeReward) GetLbPairAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetRewardVaultAccount sets the "rewardVault" account. +func (inst *InitializeReward) SetRewardVaultAccount(rewardVault ag_solanago.PublicKey) *InitializeReward { + inst.AccountMetaSlice[1] = ag_solanago.Meta(rewardVault).WRITE() + return inst +} + +// GetRewardVaultAccount gets the "rewardVault" account. +func (inst *InitializeReward) GetRewardVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetRewardMintAccount sets the "rewardMint" account. +func (inst *InitializeReward) SetRewardMintAccount(rewardMint ag_solanago.PublicKey) *InitializeReward { + inst.AccountMetaSlice[2] = ag_solanago.Meta(rewardMint) + return inst +} + +// GetRewardMintAccount gets the "rewardMint" account. +func (inst *InitializeReward) GetRewardMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetAdminAccount sets the "admin" account. +func (inst *InitializeReward) SetAdminAccount(admin ag_solanago.PublicKey) *InitializeReward { + inst.AccountMetaSlice[3] = ag_solanago.Meta(admin).WRITE().SIGNER() + return inst +} + +// GetAdminAccount gets the "admin" account. +func (inst *InitializeReward) GetAdminAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *InitializeReward) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *InitializeReward { + inst.AccountMetaSlice[4] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *InitializeReward) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +func (inst *InitializeReward) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *InitializeReward { + inst.AccountMetaSlice[5] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +func (inst *InitializeReward) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetRentAccount sets the "rent" account. +func (inst *InitializeReward) SetRentAccount(rent ag_solanago.PublicKey) *InitializeReward { + inst.AccountMetaSlice[6] = ag_solanago.Meta(rent) + return inst +} + +// GetRentAccount gets the "rent" account. +func (inst *InitializeReward) GetRentAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetEventAuthorityAccount sets the "eventAuthority" account. +func (inst *InitializeReward) SetEventAuthorityAccount(eventAuthority ag_solanago.PublicKey) *InitializeReward { + inst.AccountMetaSlice[7] = ag_solanago.Meta(eventAuthority) + return inst +} + +// GetEventAuthorityAccount gets the "eventAuthority" account. +func (inst *InitializeReward) GetEventAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetProgramAccount sets the "program" account. +func (inst *InitializeReward) SetProgramAccount(program ag_solanago.PublicKey) *InitializeReward { + inst.AccountMetaSlice[8] = ag_solanago.Meta(program) + return inst +} + +// GetProgramAccount gets the "program" account. +func (inst *InitializeReward) GetProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +func (inst InitializeReward) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_InitializeReward, + }} +} + +// 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 InitializeReward) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *InitializeReward) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.RewardIndex == nil { + return errors.New("RewardIndex parameter is not set") + } + if inst.RewardDuration == nil { + return errors.New("RewardDuration parameter is not set") + } + if inst.Funder == nil { + return errors.New("Funder parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.LbPair is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.RewardVault is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.RewardMint is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.Admin is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.SystemProgram is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.Rent is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.EventAuthority is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.Program is not set") + } + } + return nil +} + +func (inst *InitializeReward) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("InitializeReward")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=3]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" RewardIndex", *inst.RewardIndex)) + paramsBranch.Child(ag_format.Param("RewardDuration", *inst.RewardDuration)) + paramsBranch.Child(ag_format.Param(" Funder", *inst.Funder)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=9]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" lbPair", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" rewardVault", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" rewardMint", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" admin", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" systemProgram", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" rent", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta("eventAuthority", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" program", inst.AccountMetaSlice.Get(8))) + }) + }) + }) +} + +func (obj InitializeReward) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `RewardIndex` param: + err = encoder.Encode(obj.RewardIndex) + if err != nil { + return err + } + // Serialize `RewardDuration` param: + err = encoder.Encode(obj.RewardDuration) + if err != nil { + return err + } + // Serialize `Funder` param: + err = encoder.Encode(obj.Funder) + if err != nil { + return err + } + return nil +} +func (obj *InitializeReward) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `RewardIndex`: + err = decoder.Decode(&obj.RewardIndex) + if err != nil { + return err + } + // Deserialize `RewardDuration`: + err = decoder.Decode(&obj.RewardDuration) + if err != nil { + return err + } + // Deserialize `Funder`: + err = decoder.Decode(&obj.Funder) + if err != nil { + return err + } + return nil +} + +// NewInitializeRewardInstruction declares a new InitializeReward instruction with the provided parameters and accounts. +func NewInitializeRewardInstruction( + // Parameters: + rewardIndex uint64, + rewardDuration uint64, + funder ag_solanago.PublicKey, + // Accounts: + lbPair ag_solanago.PublicKey, + rewardVault ag_solanago.PublicKey, + rewardMint ag_solanago.PublicKey, + admin ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey, + rent ag_solanago.PublicKey, + eventAuthority ag_solanago.PublicKey, + program ag_solanago.PublicKey) *InitializeReward { + return NewInitializeRewardInstructionBuilder(). + SetRewardIndex(rewardIndex). + SetRewardDuration(rewardDuration). + SetFunder(funder). + SetLbPairAccount(lbPair). + SetRewardVaultAccount(rewardVault). + SetRewardMintAccount(rewardMint). + SetAdminAccount(admin). + SetTokenProgramAccount(tokenProgram). + SetSystemProgramAccount(systemProgram). + SetRentAccount(rent). + SetEventAuthorityAccount(eventAuthority). + SetProgramAccount(program) +} diff --git a/programs/meteoradlmm/InitializeReward_test.go b/programs/meteoradlmm/InitializeReward_test.go new file mode 100644 index 00000000..59c4479a --- /dev/null +++ b/programs/meteoradlmm/InitializeReward_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_InitializeReward(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("InitializeReward"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(InitializeReward) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(InitializeReward) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/MigrateBinArray.go b/programs/meteoradlmm/MigrateBinArray.go new file mode 100644 index 00000000..ca489dcb --- /dev/null +++ b/programs/meteoradlmm/MigrateBinArray.go @@ -0,0 +1,98 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// MigrateBinArray is the `migrateBinArray` instruction. +type MigrateBinArray struct { + + // [0] = [] lbPair + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewMigrateBinArrayInstructionBuilder creates a new `MigrateBinArray` instruction builder. +func NewMigrateBinArrayInstructionBuilder() *MigrateBinArray { + nd := &MigrateBinArray{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 1), + } + return nd +} + +// SetLbPairAccount sets the "lbPair" account. +func (inst *MigrateBinArray) SetLbPairAccount(lbPair ag_solanago.PublicKey) *MigrateBinArray { + inst.AccountMetaSlice[0] = ag_solanago.Meta(lbPair) + return inst +} + +// GetLbPairAccount gets the "lbPair" account. +func (inst *MigrateBinArray) GetLbPairAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +func (inst MigrateBinArray) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_MigrateBinArray, + }} +} + +// 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 MigrateBinArray) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *MigrateBinArray) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.LbPair is not set") + } + } + return nil +} + +func (inst *MigrateBinArray) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("MigrateBinArray")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=1]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta("lbPair", inst.AccountMetaSlice.Get(0))) + }) + }) + }) +} + +func (obj MigrateBinArray) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *MigrateBinArray) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewMigrateBinArrayInstruction declares a new MigrateBinArray instruction with the provided parameters and accounts. +func NewMigrateBinArrayInstruction( + // Accounts: + lbPair ag_solanago.PublicKey) *MigrateBinArray { + return NewMigrateBinArrayInstructionBuilder(). + SetLbPairAccount(lbPair) +} diff --git a/programs/meteoradlmm/MigrateBinArray_test.go b/programs/meteoradlmm/MigrateBinArray_test.go new file mode 100644 index 00000000..422bd395 --- /dev/null +++ b/programs/meteoradlmm/MigrateBinArray_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_MigrateBinArray(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("MigrateBinArray"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(MigrateBinArray) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(MigrateBinArray) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/MigratePosition.go b/programs/meteoradlmm/MigratePosition.go new file mode 100644 index 00000000..6a266abb --- /dev/null +++ b/programs/meteoradlmm/MigratePosition.go @@ -0,0 +1,269 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// MigratePosition is the `migratePosition` instruction. +type MigratePosition struct { + + // [0] = [WRITE, SIGNER] positionV2 + // + // [1] = [WRITE] positionV1 + // + // [2] = [] lbPair + // + // [3] = [WRITE] binArrayLower + // + // [4] = [WRITE] binArrayUpper + // + // [5] = [WRITE, SIGNER] owner + // + // [6] = [] systemProgram + // + // [7] = [WRITE] rentReceiver + // + // [8] = [] eventAuthority + // + // [9] = [] program + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewMigratePositionInstructionBuilder creates a new `MigratePosition` instruction builder. +func NewMigratePositionInstructionBuilder() *MigratePosition { + nd := &MigratePosition{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 10), + } + return nd +} + +// SetPositionV2Account sets the "positionV2" account. +func (inst *MigratePosition) SetPositionV2Account(positionV2 ag_solanago.PublicKey) *MigratePosition { + inst.AccountMetaSlice[0] = ag_solanago.Meta(positionV2).WRITE().SIGNER() + return inst +} + +// GetPositionV2Account gets the "positionV2" account. +func (inst *MigratePosition) GetPositionV2Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetPositionV1Account sets the "positionV1" account. +func (inst *MigratePosition) SetPositionV1Account(positionV1 ag_solanago.PublicKey) *MigratePosition { + inst.AccountMetaSlice[1] = ag_solanago.Meta(positionV1).WRITE() + return inst +} + +// GetPositionV1Account gets the "positionV1" account. +func (inst *MigratePosition) GetPositionV1Account() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetLbPairAccount sets the "lbPair" account. +func (inst *MigratePosition) SetLbPairAccount(lbPair ag_solanago.PublicKey) *MigratePosition { + inst.AccountMetaSlice[2] = ag_solanago.Meta(lbPair) + return inst +} + +// GetLbPairAccount gets the "lbPair" account. +func (inst *MigratePosition) GetLbPairAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetBinArrayLowerAccount sets the "binArrayLower" account. +func (inst *MigratePosition) SetBinArrayLowerAccount(binArrayLower ag_solanago.PublicKey) *MigratePosition { + inst.AccountMetaSlice[3] = ag_solanago.Meta(binArrayLower).WRITE() + return inst +} + +// GetBinArrayLowerAccount gets the "binArrayLower" account. +func (inst *MigratePosition) GetBinArrayLowerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetBinArrayUpperAccount sets the "binArrayUpper" account. +func (inst *MigratePosition) SetBinArrayUpperAccount(binArrayUpper ag_solanago.PublicKey) *MigratePosition { + inst.AccountMetaSlice[4] = ag_solanago.Meta(binArrayUpper).WRITE() + return inst +} + +// GetBinArrayUpperAccount gets the "binArrayUpper" account. +func (inst *MigratePosition) GetBinArrayUpperAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetOwnerAccount sets the "owner" account. +func (inst *MigratePosition) SetOwnerAccount(owner ag_solanago.PublicKey) *MigratePosition { + inst.AccountMetaSlice[5] = ag_solanago.Meta(owner).WRITE().SIGNER() + return inst +} + +// GetOwnerAccount gets the "owner" account. +func (inst *MigratePosition) GetOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +func (inst *MigratePosition) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *MigratePosition { + inst.AccountMetaSlice[6] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +func (inst *MigratePosition) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetRentReceiverAccount sets the "rentReceiver" account. +func (inst *MigratePosition) SetRentReceiverAccount(rentReceiver ag_solanago.PublicKey) *MigratePosition { + inst.AccountMetaSlice[7] = ag_solanago.Meta(rentReceiver).WRITE() + return inst +} + +// GetRentReceiverAccount gets the "rentReceiver" account. +func (inst *MigratePosition) GetRentReceiverAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetEventAuthorityAccount sets the "eventAuthority" account. +func (inst *MigratePosition) SetEventAuthorityAccount(eventAuthority ag_solanago.PublicKey) *MigratePosition { + inst.AccountMetaSlice[8] = ag_solanago.Meta(eventAuthority) + return inst +} + +// GetEventAuthorityAccount gets the "eventAuthority" account. +func (inst *MigratePosition) GetEventAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetProgramAccount sets the "program" account. +func (inst *MigratePosition) SetProgramAccount(program ag_solanago.PublicKey) *MigratePosition { + inst.AccountMetaSlice[9] = ag_solanago.Meta(program) + return inst +} + +// GetProgramAccount gets the "program" account. +func (inst *MigratePosition) GetProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +func (inst MigratePosition) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_MigratePosition, + }} +} + +// 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 MigratePosition) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *MigratePosition) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.PositionV2 is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.PositionV1 is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.LbPair is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.BinArrayLower is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.BinArrayUpper is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.Owner is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.SystemProgram is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.RentReceiver is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.EventAuthority is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.Program is not set") + } + } + return nil +} + +func (inst *MigratePosition) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("MigratePosition")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=10]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" positionV2", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" positionV1", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" lbPair", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" binArrayLower", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" binArrayUpper", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" owner", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" systemProgram", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" rentReceiver", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta("eventAuthority", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" program", inst.AccountMetaSlice.Get(9))) + }) + }) + }) +} + +func (obj MigratePosition) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *MigratePosition) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewMigratePositionInstruction declares a new MigratePosition instruction with the provided parameters and accounts. +func NewMigratePositionInstruction( + // Accounts: + positionV2 ag_solanago.PublicKey, + positionV1 ag_solanago.PublicKey, + lbPair ag_solanago.PublicKey, + binArrayLower ag_solanago.PublicKey, + binArrayUpper ag_solanago.PublicKey, + owner ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey, + rentReceiver ag_solanago.PublicKey, + eventAuthority ag_solanago.PublicKey, + program ag_solanago.PublicKey) *MigratePosition { + return NewMigratePositionInstructionBuilder(). + SetPositionV2Account(positionV2). + SetPositionV1Account(positionV1). + SetLbPairAccount(lbPair). + SetBinArrayLowerAccount(binArrayLower). + SetBinArrayUpperAccount(binArrayUpper). + SetOwnerAccount(owner). + SetSystemProgramAccount(systemProgram). + SetRentReceiverAccount(rentReceiver). + SetEventAuthorityAccount(eventAuthority). + SetProgramAccount(program) +} diff --git a/programs/meteoradlmm/MigratePosition_test.go b/programs/meteoradlmm/MigratePosition_test.go new file mode 100644 index 00000000..29d04740 --- /dev/null +++ b/programs/meteoradlmm/MigratePosition_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_MigratePosition(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("MigratePosition"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(MigratePosition) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(MigratePosition) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/RemoveAllLiquidity.go b/programs/meteoradlmm/RemoveAllLiquidity.go new file mode 100644 index 00000000..e26a5632 --- /dev/null +++ b/programs/meteoradlmm/RemoveAllLiquidity.go @@ -0,0 +1,383 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// RemoveAllLiquidity is the `removeAllLiquidity` instruction. +type RemoveAllLiquidity struct { + + // [0] = [WRITE] position + // + // [1] = [WRITE] lbPair + // + // [2] = [WRITE] binArrayBitmapExtension + // + // [3] = [WRITE] userTokenX + // + // [4] = [WRITE] userTokenY + // + // [5] = [WRITE] reserveX + // + // [6] = [WRITE] reserveY + // + // [7] = [] tokenXMint + // + // [8] = [] tokenYMint + // + // [9] = [WRITE] binArrayLower + // + // [10] = [WRITE] binArrayUpper + // + // [11] = [SIGNER] sender + // + // [12] = [] tokenXProgram + // + // [13] = [] tokenYProgram + // + // [14] = [] eventAuthority + // + // [15] = [] program + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewRemoveAllLiquidityInstructionBuilder creates a new `RemoveAllLiquidity` instruction builder. +func NewRemoveAllLiquidityInstructionBuilder() *RemoveAllLiquidity { + nd := &RemoveAllLiquidity{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 16), + } + return nd +} + +// SetPositionAccount sets the "position" account. +func (inst *RemoveAllLiquidity) SetPositionAccount(position ag_solanago.PublicKey) *RemoveAllLiquidity { + inst.AccountMetaSlice[0] = ag_solanago.Meta(position).WRITE() + return inst +} + +// GetPositionAccount gets the "position" account. +func (inst *RemoveAllLiquidity) GetPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetLbPairAccount sets the "lbPair" account. +func (inst *RemoveAllLiquidity) SetLbPairAccount(lbPair ag_solanago.PublicKey) *RemoveAllLiquidity { + inst.AccountMetaSlice[1] = ag_solanago.Meta(lbPair).WRITE() + return inst +} + +// GetLbPairAccount gets the "lbPair" account. +func (inst *RemoveAllLiquidity) GetLbPairAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetBinArrayBitmapExtensionAccount sets the "binArrayBitmapExtension" account. +func (inst *RemoveAllLiquidity) SetBinArrayBitmapExtensionAccount(binArrayBitmapExtension ag_solanago.PublicKey) *RemoveAllLiquidity { + inst.AccountMetaSlice[2] = ag_solanago.Meta(binArrayBitmapExtension).WRITE() + return inst +} + +// GetBinArrayBitmapExtensionAccount gets the "binArrayBitmapExtension" account. +func (inst *RemoveAllLiquidity) GetBinArrayBitmapExtensionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetUserTokenXAccount sets the "userTokenX" account. +func (inst *RemoveAllLiquidity) SetUserTokenXAccount(userTokenX ag_solanago.PublicKey) *RemoveAllLiquidity { + inst.AccountMetaSlice[3] = ag_solanago.Meta(userTokenX).WRITE() + return inst +} + +// GetUserTokenXAccount gets the "userTokenX" account. +func (inst *RemoveAllLiquidity) GetUserTokenXAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetUserTokenYAccount sets the "userTokenY" account. +func (inst *RemoveAllLiquidity) SetUserTokenYAccount(userTokenY ag_solanago.PublicKey) *RemoveAllLiquidity { + inst.AccountMetaSlice[4] = ag_solanago.Meta(userTokenY).WRITE() + return inst +} + +// GetUserTokenYAccount gets the "userTokenY" account. +func (inst *RemoveAllLiquidity) GetUserTokenYAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetReserveXAccount sets the "reserveX" account. +func (inst *RemoveAllLiquidity) SetReserveXAccount(reserveX ag_solanago.PublicKey) *RemoveAllLiquidity { + inst.AccountMetaSlice[5] = ag_solanago.Meta(reserveX).WRITE() + return inst +} + +// GetReserveXAccount gets the "reserveX" account. +func (inst *RemoveAllLiquidity) GetReserveXAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetReserveYAccount sets the "reserveY" account. +func (inst *RemoveAllLiquidity) SetReserveYAccount(reserveY ag_solanago.PublicKey) *RemoveAllLiquidity { + inst.AccountMetaSlice[6] = ag_solanago.Meta(reserveY).WRITE() + return inst +} + +// GetReserveYAccount gets the "reserveY" account. +func (inst *RemoveAllLiquidity) GetReserveYAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetTokenXMintAccount sets the "tokenXMint" account. +func (inst *RemoveAllLiquidity) SetTokenXMintAccount(tokenXMint ag_solanago.PublicKey) *RemoveAllLiquidity { + inst.AccountMetaSlice[7] = ag_solanago.Meta(tokenXMint) + return inst +} + +// GetTokenXMintAccount gets the "tokenXMint" account. +func (inst *RemoveAllLiquidity) GetTokenXMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetTokenYMintAccount sets the "tokenYMint" account. +func (inst *RemoveAllLiquidity) SetTokenYMintAccount(tokenYMint ag_solanago.PublicKey) *RemoveAllLiquidity { + inst.AccountMetaSlice[8] = ag_solanago.Meta(tokenYMint) + return inst +} + +// GetTokenYMintAccount gets the "tokenYMint" account. +func (inst *RemoveAllLiquidity) GetTokenYMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetBinArrayLowerAccount sets the "binArrayLower" account. +func (inst *RemoveAllLiquidity) SetBinArrayLowerAccount(binArrayLower ag_solanago.PublicKey) *RemoveAllLiquidity { + inst.AccountMetaSlice[9] = ag_solanago.Meta(binArrayLower).WRITE() + return inst +} + +// GetBinArrayLowerAccount gets the "binArrayLower" account. +func (inst *RemoveAllLiquidity) GetBinArrayLowerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetBinArrayUpperAccount sets the "binArrayUpper" account. +func (inst *RemoveAllLiquidity) SetBinArrayUpperAccount(binArrayUpper ag_solanago.PublicKey) *RemoveAllLiquidity { + inst.AccountMetaSlice[10] = ag_solanago.Meta(binArrayUpper).WRITE() + return inst +} + +// GetBinArrayUpperAccount gets the "binArrayUpper" account. +func (inst *RemoveAllLiquidity) GetBinArrayUpperAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetSenderAccount sets the "sender" account. +func (inst *RemoveAllLiquidity) SetSenderAccount(sender ag_solanago.PublicKey) *RemoveAllLiquidity { + inst.AccountMetaSlice[11] = ag_solanago.Meta(sender).SIGNER() + return inst +} + +// GetSenderAccount gets the "sender" account. +func (inst *RemoveAllLiquidity) GetSenderAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetTokenXProgramAccount sets the "tokenXProgram" account. +func (inst *RemoveAllLiquidity) SetTokenXProgramAccount(tokenXProgram ag_solanago.PublicKey) *RemoveAllLiquidity { + inst.AccountMetaSlice[12] = ag_solanago.Meta(tokenXProgram) + return inst +} + +// GetTokenXProgramAccount gets the "tokenXProgram" account. +func (inst *RemoveAllLiquidity) GetTokenXProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetTokenYProgramAccount sets the "tokenYProgram" account. +func (inst *RemoveAllLiquidity) SetTokenYProgramAccount(tokenYProgram ag_solanago.PublicKey) *RemoveAllLiquidity { + inst.AccountMetaSlice[13] = ag_solanago.Meta(tokenYProgram) + return inst +} + +// GetTokenYProgramAccount gets the "tokenYProgram" account. +func (inst *RemoveAllLiquidity) GetTokenYProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetEventAuthorityAccount sets the "eventAuthority" account. +func (inst *RemoveAllLiquidity) SetEventAuthorityAccount(eventAuthority ag_solanago.PublicKey) *RemoveAllLiquidity { + inst.AccountMetaSlice[14] = ag_solanago.Meta(eventAuthority) + return inst +} + +// GetEventAuthorityAccount gets the "eventAuthority" account. +func (inst *RemoveAllLiquidity) GetEventAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +// SetProgramAccount sets the "program" account. +func (inst *RemoveAllLiquidity) SetProgramAccount(program ag_solanago.PublicKey) *RemoveAllLiquidity { + inst.AccountMetaSlice[15] = ag_solanago.Meta(program) + return inst +} + +// GetProgramAccount gets the "program" account. +func (inst *RemoveAllLiquidity) GetProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(15) +} + +func (inst RemoveAllLiquidity) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_RemoveAllLiquidity, + }} +} + +// 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 RemoveAllLiquidity) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *RemoveAllLiquidity) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Position is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.LbPair is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.BinArrayBitmapExtension is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.UserTokenX is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.UserTokenY is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.ReserveX is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.ReserveY is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.TokenXMint is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.TokenYMint is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.BinArrayLower is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.BinArrayUpper is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.Sender is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.TokenXProgram is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.TokenYProgram is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.EventAuthority is not set") + } + if inst.AccountMetaSlice[15] == nil { + return errors.New("accounts.Program is not set") + } + } + return nil +} + +func (inst *RemoveAllLiquidity) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("RemoveAllLiquidity")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=16]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" position", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" lbPair", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta("binArrayBitmapExtension", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" userTokenX", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" userTokenY", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" reserveX", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" reserveY", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" tokenXMint", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" tokenYMint", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" binArrayLower", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" binArrayUpper", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" sender", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" tokenXProgram", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" tokenYProgram", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta(" eventAuthority", inst.AccountMetaSlice.Get(14))) + accountsBranch.Child(ag_format.Meta(" program", inst.AccountMetaSlice.Get(15))) + }) + }) + }) +} + +func (obj RemoveAllLiquidity) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *RemoveAllLiquidity) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewRemoveAllLiquidityInstruction declares a new RemoveAllLiquidity instruction with the provided parameters and accounts. +func NewRemoveAllLiquidityInstruction( + // Accounts: + position ag_solanago.PublicKey, + lbPair ag_solanago.PublicKey, + binArrayBitmapExtension ag_solanago.PublicKey, + userTokenX ag_solanago.PublicKey, + userTokenY ag_solanago.PublicKey, + reserveX ag_solanago.PublicKey, + reserveY ag_solanago.PublicKey, + tokenXMint ag_solanago.PublicKey, + tokenYMint ag_solanago.PublicKey, + binArrayLower ag_solanago.PublicKey, + binArrayUpper ag_solanago.PublicKey, + sender ag_solanago.PublicKey, + tokenXProgram ag_solanago.PublicKey, + tokenYProgram ag_solanago.PublicKey, + eventAuthority ag_solanago.PublicKey, + program ag_solanago.PublicKey) *RemoveAllLiquidity { + return NewRemoveAllLiquidityInstructionBuilder(). + SetPositionAccount(position). + SetLbPairAccount(lbPair). + SetBinArrayBitmapExtensionAccount(binArrayBitmapExtension). + SetUserTokenXAccount(userTokenX). + SetUserTokenYAccount(userTokenY). + SetReserveXAccount(reserveX). + SetReserveYAccount(reserveY). + SetTokenXMintAccount(tokenXMint). + SetTokenYMintAccount(tokenYMint). + SetBinArrayLowerAccount(binArrayLower). + SetBinArrayUpperAccount(binArrayUpper). + SetSenderAccount(sender). + SetTokenXProgramAccount(tokenXProgram). + SetTokenYProgramAccount(tokenYProgram). + SetEventAuthorityAccount(eventAuthority). + SetProgramAccount(program) +} diff --git a/programs/meteoradlmm/RemoveAllLiquidity_test.go b/programs/meteoradlmm/RemoveAllLiquidity_test.go new file mode 100644 index 00000000..95f7b9c8 --- /dev/null +++ b/programs/meteoradlmm/RemoveAllLiquidity_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_RemoveAllLiquidity(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("RemoveAllLiquidity"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(RemoveAllLiquidity) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(RemoveAllLiquidity) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/RemoveLiquidity.go b/programs/meteoradlmm/RemoveLiquidity.go new file mode 100644 index 00000000..c7153e67 --- /dev/null +++ b/programs/meteoradlmm/RemoveLiquidity.go @@ -0,0 +1,412 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// RemoveLiquidity is the `removeLiquidity` instruction. +type RemoveLiquidity struct { + BinLiquidityRemoval *[]BinLiquidityReduction + + // [0] = [WRITE] position + // + // [1] = [WRITE] lbPair + // + // [2] = [WRITE] binArrayBitmapExtension + // + // [3] = [WRITE] userTokenX + // + // [4] = [WRITE] userTokenY + // + // [5] = [WRITE] reserveX + // + // [6] = [WRITE] reserveY + // + // [7] = [] tokenXMint + // + // [8] = [] tokenYMint + // + // [9] = [WRITE] binArrayLower + // + // [10] = [WRITE] binArrayUpper + // + // [11] = [SIGNER] sender + // + // [12] = [] tokenXProgram + // + // [13] = [] tokenYProgram + // + // [14] = [] eventAuthority + // + // [15] = [] program + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewRemoveLiquidityInstructionBuilder creates a new `RemoveLiquidity` instruction builder. +func NewRemoveLiquidityInstructionBuilder() *RemoveLiquidity { + nd := &RemoveLiquidity{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 16), + } + return nd +} + +// SetBinLiquidityRemoval sets the "binLiquidityRemoval" parameter. +func (inst *RemoveLiquidity) SetBinLiquidityRemoval(binLiquidityRemoval []BinLiquidityReduction) *RemoveLiquidity { + inst.BinLiquidityRemoval = &binLiquidityRemoval + return inst +} + +// SetPositionAccount sets the "position" account. +func (inst *RemoveLiquidity) SetPositionAccount(position ag_solanago.PublicKey) *RemoveLiquidity { + inst.AccountMetaSlice[0] = ag_solanago.Meta(position).WRITE() + return inst +} + +// GetPositionAccount gets the "position" account. +func (inst *RemoveLiquidity) GetPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetLbPairAccount sets the "lbPair" account. +func (inst *RemoveLiquidity) SetLbPairAccount(lbPair ag_solanago.PublicKey) *RemoveLiquidity { + inst.AccountMetaSlice[1] = ag_solanago.Meta(lbPair).WRITE() + return inst +} + +// GetLbPairAccount gets the "lbPair" account. +func (inst *RemoveLiquidity) GetLbPairAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetBinArrayBitmapExtensionAccount sets the "binArrayBitmapExtension" account. +func (inst *RemoveLiquidity) SetBinArrayBitmapExtensionAccount(binArrayBitmapExtension ag_solanago.PublicKey) *RemoveLiquidity { + inst.AccountMetaSlice[2] = ag_solanago.Meta(binArrayBitmapExtension).WRITE() + return inst +} + +// GetBinArrayBitmapExtensionAccount gets the "binArrayBitmapExtension" account. +func (inst *RemoveLiquidity) GetBinArrayBitmapExtensionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetUserTokenXAccount sets the "userTokenX" account. +func (inst *RemoveLiquidity) SetUserTokenXAccount(userTokenX ag_solanago.PublicKey) *RemoveLiquidity { + inst.AccountMetaSlice[3] = ag_solanago.Meta(userTokenX).WRITE() + return inst +} + +// GetUserTokenXAccount gets the "userTokenX" account. +func (inst *RemoveLiquidity) GetUserTokenXAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetUserTokenYAccount sets the "userTokenY" account. +func (inst *RemoveLiquidity) SetUserTokenYAccount(userTokenY ag_solanago.PublicKey) *RemoveLiquidity { + inst.AccountMetaSlice[4] = ag_solanago.Meta(userTokenY).WRITE() + return inst +} + +// GetUserTokenYAccount gets the "userTokenY" account. +func (inst *RemoveLiquidity) GetUserTokenYAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetReserveXAccount sets the "reserveX" account. +func (inst *RemoveLiquidity) SetReserveXAccount(reserveX ag_solanago.PublicKey) *RemoveLiquidity { + inst.AccountMetaSlice[5] = ag_solanago.Meta(reserveX).WRITE() + return inst +} + +// GetReserveXAccount gets the "reserveX" account. +func (inst *RemoveLiquidity) GetReserveXAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetReserveYAccount sets the "reserveY" account. +func (inst *RemoveLiquidity) SetReserveYAccount(reserveY ag_solanago.PublicKey) *RemoveLiquidity { + inst.AccountMetaSlice[6] = ag_solanago.Meta(reserveY).WRITE() + return inst +} + +// GetReserveYAccount gets the "reserveY" account. +func (inst *RemoveLiquidity) GetReserveYAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetTokenXMintAccount sets the "tokenXMint" account. +func (inst *RemoveLiquidity) SetTokenXMintAccount(tokenXMint ag_solanago.PublicKey) *RemoveLiquidity { + inst.AccountMetaSlice[7] = ag_solanago.Meta(tokenXMint) + return inst +} + +// GetTokenXMintAccount gets the "tokenXMint" account. +func (inst *RemoveLiquidity) GetTokenXMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetTokenYMintAccount sets the "tokenYMint" account. +func (inst *RemoveLiquidity) SetTokenYMintAccount(tokenYMint ag_solanago.PublicKey) *RemoveLiquidity { + inst.AccountMetaSlice[8] = ag_solanago.Meta(tokenYMint) + return inst +} + +// GetTokenYMintAccount gets the "tokenYMint" account. +func (inst *RemoveLiquidity) GetTokenYMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetBinArrayLowerAccount sets the "binArrayLower" account. +func (inst *RemoveLiquidity) SetBinArrayLowerAccount(binArrayLower ag_solanago.PublicKey) *RemoveLiquidity { + inst.AccountMetaSlice[9] = ag_solanago.Meta(binArrayLower).WRITE() + return inst +} + +// GetBinArrayLowerAccount gets the "binArrayLower" account. +func (inst *RemoveLiquidity) GetBinArrayLowerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetBinArrayUpperAccount sets the "binArrayUpper" account. +func (inst *RemoveLiquidity) SetBinArrayUpperAccount(binArrayUpper ag_solanago.PublicKey) *RemoveLiquidity { + inst.AccountMetaSlice[10] = ag_solanago.Meta(binArrayUpper).WRITE() + return inst +} + +// GetBinArrayUpperAccount gets the "binArrayUpper" account. +func (inst *RemoveLiquidity) GetBinArrayUpperAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetSenderAccount sets the "sender" account. +func (inst *RemoveLiquidity) SetSenderAccount(sender ag_solanago.PublicKey) *RemoveLiquidity { + inst.AccountMetaSlice[11] = ag_solanago.Meta(sender).SIGNER() + return inst +} + +// GetSenderAccount gets the "sender" account. +func (inst *RemoveLiquidity) GetSenderAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetTokenXProgramAccount sets the "tokenXProgram" account. +func (inst *RemoveLiquidity) SetTokenXProgramAccount(tokenXProgram ag_solanago.PublicKey) *RemoveLiquidity { + inst.AccountMetaSlice[12] = ag_solanago.Meta(tokenXProgram) + return inst +} + +// GetTokenXProgramAccount gets the "tokenXProgram" account. +func (inst *RemoveLiquidity) GetTokenXProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetTokenYProgramAccount sets the "tokenYProgram" account. +func (inst *RemoveLiquidity) SetTokenYProgramAccount(tokenYProgram ag_solanago.PublicKey) *RemoveLiquidity { + inst.AccountMetaSlice[13] = ag_solanago.Meta(tokenYProgram) + return inst +} + +// GetTokenYProgramAccount gets the "tokenYProgram" account. +func (inst *RemoveLiquidity) GetTokenYProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetEventAuthorityAccount sets the "eventAuthority" account. +func (inst *RemoveLiquidity) SetEventAuthorityAccount(eventAuthority ag_solanago.PublicKey) *RemoveLiquidity { + inst.AccountMetaSlice[14] = ag_solanago.Meta(eventAuthority) + return inst +} + +// GetEventAuthorityAccount gets the "eventAuthority" account. +func (inst *RemoveLiquidity) GetEventAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +// SetProgramAccount sets the "program" account. +func (inst *RemoveLiquidity) SetProgramAccount(program ag_solanago.PublicKey) *RemoveLiquidity { + inst.AccountMetaSlice[15] = ag_solanago.Meta(program) + return inst +} + +// GetProgramAccount gets the "program" account. +func (inst *RemoveLiquidity) GetProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(15) +} + +func (inst RemoveLiquidity) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_RemoveLiquidity, + }} +} + +// 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 RemoveLiquidity) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *RemoveLiquidity) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.BinLiquidityRemoval == nil { + return errors.New("BinLiquidityRemoval parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Position is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.LbPair is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.BinArrayBitmapExtension is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.UserTokenX is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.UserTokenY is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.ReserveX is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.ReserveY is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.TokenXMint is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.TokenYMint is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.BinArrayLower is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.BinArrayUpper is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.Sender is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.TokenXProgram is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.TokenYProgram is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.EventAuthority is not set") + } + if inst.AccountMetaSlice[15] == nil { + return errors.New("accounts.Program is not set") + } + } + return nil +} + +func (inst *RemoveLiquidity) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("RemoveLiquidity")). + // + 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("BinLiquidityRemoval", *inst.BinLiquidityRemoval)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=16]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" position", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" lbPair", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta("binArrayBitmapExtension", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" userTokenX", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" userTokenY", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" reserveX", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" reserveY", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" tokenXMint", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" tokenYMint", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" binArrayLower", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" binArrayUpper", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" sender", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" tokenXProgram", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" tokenYProgram", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta(" eventAuthority", inst.AccountMetaSlice.Get(14))) + accountsBranch.Child(ag_format.Meta(" program", inst.AccountMetaSlice.Get(15))) + }) + }) + }) +} + +func (obj RemoveLiquidity) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `BinLiquidityRemoval` param: + err = encoder.Encode(obj.BinLiquidityRemoval) + if err != nil { + return err + } + return nil +} +func (obj *RemoveLiquidity) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `BinLiquidityRemoval`: + err = decoder.Decode(&obj.BinLiquidityRemoval) + if err != nil { + return err + } + return nil +} + +// NewRemoveLiquidityInstruction declares a new RemoveLiquidity instruction with the provided parameters and accounts. +func NewRemoveLiquidityInstruction( + // Parameters: + binLiquidityRemoval []BinLiquidityReduction, + // Accounts: + position ag_solanago.PublicKey, + lbPair ag_solanago.PublicKey, + binArrayBitmapExtension ag_solanago.PublicKey, + userTokenX ag_solanago.PublicKey, + userTokenY ag_solanago.PublicKey, + reserveX ag_solanago.PublicKey, + reserveY ag_solanago.PublicKey, + tokenXMint ag_solanago.PublicKey, + tokenYMint ag_solanago.PublicKey, + binArrayLower ag_solanago.PublicKey, + binArrayUpper ag_solanago.PublicKey, + sender ag_solanago.PublicKey, + tokenXProgram ag_solanago.PublicKey, + tokenYProgram ag_solanago.PublicKey, + eventAuthority ag_solanago.PublicKey, + program ag_solanago.PublicKey) *RemoveLiquidity { + return NewRemoveLiquidityInstructionBuilder(). + SetBinLiquidityRemoval(binLiquidityRemoval). + SetPositionAccount(position). + SetLbPairAccount(lbPair). + SetBinArrayBitmapExtensionAccount(binArrayBitmapExtension). + SetUserTokenXAccount(userTokenX). + SetUserTokenYAccount(userTokenY). + SetReserveXAccount(reserveX). + SetReserveYAccount(reserveY). + SetTokenXMintAccount(tokenXMint). + SetTokenYMintAccount(tokenYMint). + SetBinArrayLowerAccount(binArrayLower). + SetBinArrayUpperAccount(binArrayUpper). + SetSenderAccount(sender). + SetTokenXProgramAccount(tokenXProgram). + SetTokenYProgramAccount(tokenYProgram). + SetEventAuthorityAccount(eventAuthority). + SetProgramAccount(program) +} diff --git a/programs/meteoradlmm/RemoveLiquidityByRange.go b/programs/meteoradlmm/RemoveLiquidityByRange.go new file mode 100644 index 00000000..81c8ebaf --- /dev/null +++ b/programs/meteoradlmm/RemoveLiquidityByRange.go @@ -0,0 +1,458 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// RemoveLiquidityByRange is the `removeLiquidityByRange` instruction. +type RemoveLiquidityByRange struct { + FromBinId *int32 + ToBinId *int32 + BpsToRemove *uint16 + + // [0] = [WRITE] position + // + // [1] = [WRITE] lbPair + // + // [2] = [WRITE] binArrayBitmapExtension + // + // [3] = [WRITE] userTokenX + // + // [4] = [WRITE] userTokenY + // + // [5] = [WRITE] reserveX + // + // [6] = [WRITE] reserveY + // + // [7] = [] tokenXMint + // + // [8] = [] tokenYMint + // + // [9] = [WRITE] binArrayLower + // + // [10] = [WRITE] binArrayUpper + // + // [11] = [SIGNER] sender + // + // [12] = [] tokenXProgram + // + // [13] = [] tokenYProgram + // + // [14] = [] eventAuthority + // + // [15] = [] program + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewRemoveLiquidityByRangeInstructionBuilder creates a new `RemoveLiquidityByRange` instruction builder. +func NewRemoveLiquidityByRangeInstructionBuilder() *RemoveLiquidityByRange { + nd := &RemoveLiquidityByRange{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 16), + } + return nd +} + +// SetFromBinId sets the "fromBinId" parameter. +func (inst *RemoveLiquidityByRange) SetFromBinId(fromBinId int32) *RemoveLiquidityByRange { + inst.FromBinId = &fromBinId + return inst +} + +// SetToBinId sets the "toBinId" parameter. +func (inst *RemoveLiquidityByRange) SetToBinId(toBinId int32) *RemoveLiquidityByRange { + inst.ToBinId = &toBinId + return inst +} + +// SetBpsToRemove sets the "bpsToRemove" parameter. +func (inst *RemoveLiquidityByRange) SetBpsToRemove(bpsToRemove uint16) *RemoveLiquidityByRange { + inst.BpsToRemove = &bpsToRemove + return inst +} + +// SetPositionAccount sets the "position" account. +func (inst *RemoveLiquidityByRange) SetPositionAccount(position ag_solanago.PublicKey) *RemoveLiquidityByRange { + inst.AccountMetaSlice[0] = ag_solanago.Meta(position).WRITE() + return inst +} + +// GetPositionAccount gets the "position" account. +func (inst *RemoveLiquidityByRange) GetPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetLbPairAccount sets the "lbPair" account. +func (inst *RemoveLiquidityByRange) SetLbPairAccount(lbPair ag_solanago.PublicKey) *RemoveLiquidityByRange { + inst.AccountMetaSlice[1] = ag_solanago.Meta(lbPair).WRITE() + return inst +} + +// GetLbPairAccount gets the "lbPair" account. +func (inst *RemoveLiquidityByRange) GetLbPairAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetBinArrayBitmapExtensionAccount sets the "binArrayBitmapExtension" account. +func (inst *RemoveLiquidityByRange) SetBinArrayBitmapExtensionAccount(binArrayBitmapExtension ag_solanago.PublicKey) *RemoveLiquidityByRange { + inst.AccountMetaSlice[2] = ag_solanago.Meta(binArrayBitmapExtension).WRITE() + return inst +} + +// GetBinArrayBitmapExtensionAccount gets the "binArrayBitmapExtension" account. +func (inst *RemoveLiquidityByRange) GetBinArrayBitmapExtensionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetUserTokenXAccount sets the "userTokenX" account. +func (inst *RemoveLiquidityByRange) SetUserTokenXAccount(userTokenX ag_solanago.PublicKey) *RemoveLiquidityByRange { + inst.AccountMetaSlice[3] = ag_solanago.Meta(userTokenX).WRITE() + return inst +} + +// GetUserTokenXAccount gets the "userTokenX" account. +func (inst *RemoveLiquidityByRange) GetUserTokenXAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetUserTokenYAccount sets the "userTokenY" account. +func (inst *RemoveLiquidityByRange) SetUserTokenYAccount(userTokenY ag_solanago.PublicKey) *RemoveLiquidityByRange { + inst.AccountMetaSlice[4] = ag_solanago.Meta(userTokenY).WRITE() + return inst +} + +// GetUserTokenYAccount gets the "userTokenY" account. +func (inst *RemoveLiquidityByRange) GetUserTokenYAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetReserveXAccount sets the "reserveX" account. +func (inst *RemoveLiquidityByRange) SetReserveXAccount(reserveX ag_solanago.PublicKey) *RemoveLiquidityByRange { + inst.AccountMetaSlice[5] = ag_solanago.Meta(reserveX).WRITE() + return inst +} + +// GetReserveXAccount gets the "reserveX" account. +func (inst *RemoveLiquidityByRange) GetReserveXAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetReserveYAccount sets the "reserveY" account. +func (inst *RemoveLiquidityByRange) SetReserveYAccount(reserveY ag_solanago.PublicKey) *RemoveLiquidityByRange { + inst.AccountMetaSlice[6] = ag_solanago.Meta(reserveY).WRITE() + return inst +} + +// GetReserveYAccount gets the "reserveY" account. +func (inst *RemoveLiquidityByRange) GetReserveYAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetTokenXMintAccount sets the "tokenXMint" account. +func (inst *RemoveLiquidityByRange) SetTokenXMintAccount(tokenXMint ag_solanago.PublicKey) *RemoveLiquidityByRange { + inst.AccountMetaSlice[7] = ag_solanago.Meta(tokenXMint) + return inst +} + +// GetTokenXMintAccount gets the "tokenXMint" account. +func (inst *RemoveLiquidityByRange) GetTokenXMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetTokenYMintAccount sets the "tokenYMint" account. +func (inst *RemoveLiquidityByRange) SetTokenYMintAccount(tokenYMint ag_solanago.PublicKey) *RemoveLiquidityByRange { + inst.AccountMetaSlice[8] = ag_solanago.Meta(tokenYMint) + return inst +} + +// GetTokenYMintAccount gets the "tokenYMint" account. +func (inst *RemoveLiquidityByRange) GetTokenYMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetBinArrayLowerAccount sets the "binArrayLower" account. +func (inst *RemoveLiquidityByRange) SetBinArrayLowerAccount(binArrayLower ag_solanago.PublicKey) *RemoveLiquidityByRange { + inst.AccountMetaSlice[9] = ag_solanago.Meta(binArrayLower).WRITE() + return inst +} + +// GetBinArrayLowerAccount gets the "binArrayLower" account. +func (inst *RemoveLiquidityByRange) GetBinArrayLowerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetBinArrayUpperAccount sets the "binArrayUpper" account. +func (inst *RemoveLiquidityByRange) SetBinArrayUpperAccount(binArrayUpper ag_solanago.PublicKey) *RemoveLiquidityByRange { + inst.AccountMetaSlice[10] = ag_solanago.Meta(binArrayUpper).WRITE() + return inst +} + +// GetBinArrayUpperAccount gets the "binArrayUpper" account. +func (inst *RemoveLiquidityByRange) GetBinArrayUpperAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetSenderAccount sets the "sender" account. +func (inst *RemoveLiquidityByRange) SetSenderAccount(sender ag_solanago.PublicKey) *RemoveLiquidityByRange { + inst.AccountMetaSlice[11] = ag_solanago.Meta(sender).SIGNER() + return inst +} + +// GetSenderAccount gets the "sender" account. +func (inst *RemoveLiquidityByRange) GetSenderAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetTokenXProgramAccount sets the "tokenXProgram" account. +func (inst *RemoveLiquidityByRange) SetTokenXProgramAccount(tokenXProgram ag_solanago.PublicKey) *RemoveLiquidityByRange { + inst.AccountMetaSlice[12] = ag_solanago.Meta(tokenXProgram) + return inst +} + +// GetTokenXProgramAccount gets the "tokenXProgram" account. +func (inst *RemoveLiquidityByRange) GetTokenXProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetTokenYProgramAccount sets the "tokenYProgram" account. +func (inst *RemoveLiquidityByRange) SetTokenYProgramAccount(tokenYProgram ag_solanago.PublicKey) *RemoveLiquidityByRange { + inst.AccountMetaSlice[13] = ag_solanago.Meta(tokenYProgram) + return inst +} + +// GetTokenYProgramAccount gets the "tokenYProgram" account. +func (inst *RemoveLiquidityByRange) GetTokenYProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetEventAuthorityAccount sets the "eventAuthority" account. +func (inst *RemoveLiquidityByRange) SetEventAuthorityAccount(eventAuthority ag_solanago.PublicKey) *RemoveLiquidityByRange { + inst.AccountMetaSlice[14] = ag_solanago.Meta(eventAuthority) + return inst +} + +// GetEventAuthorityAccount gets the "eventAuthority" account. +func (inst *RemoveLiquidityByRange) GetEventAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +// SetProgramAccount sets the "program" account. +func (inst *RemoveLiquidityByRange) SetProgramAccount(program ag_solanago.PublicKey) *RemoveLiquidityByRange { + inst.AccountMetaSlice[15] = ag_solanago.Meta(program) + return inst +} + +// GetProgramAccount gets the "program" account. +func (inst *RemoveLiquidityByRange) GetProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(15) +} + +func (inst RemoveLiquidityByRange) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_RemoveLiquidityByRange, + }} +} + +// 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 RemoveLiquidityByRange) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *RemoveLiquidityByRange) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.FromBinId == nil { + return errors.New("FromBinId parameter is not set") + } + if inst.ToBinId == nil { + return errors.New("ToBinId parameter is not set") + } + if inst.BpsToRemove == nil { + return errors.New("BpsToRemove parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Position is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.LbPair is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.BinArrayBitmapExtension is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.UserTokenX is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.UserTokenY is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.ReserveX is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.ReserveY is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.TokenXMint is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.TokenYMint is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.BinArrayLower is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.BinArrayUpper is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.Sender is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.TokenXProgram is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.TokenYProgram is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.EventAuthority is not set") + } + if inst.AccountMetaSlice[15] == nil { + return errors.New("accounts.Program is not set") + } + } + return nil +} + +func (inst *RemoveLiquidityByRange) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("RemoveLiquidityByRange")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=3]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" FromBinId", *inst.FromBinId)) + paramsBranch.Child(ag_format.Param(" ToBinId", *inst.ToBinId)) + paramsBranch.Child(ag_format.Param("BpsToRemove", *inst.BpsToRemove)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=16]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" position", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" lbPair", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta("binArrayBitmapExtension", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" userTokenX", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" userTokenY", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" reserveX", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" reserveY", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" tokenXMint", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" tokenYMint", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" binArrayLower", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" binArrayUpper", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" sender", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" tokenXProgram", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" tokenYProgram", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta(" eventAuthority", inst.AccountMetaSlice.Get(14))) + accountsBranch.Child(ag_format.Meta(" program", inst.AccountMetaSlice.Get(15))) + }) + }) + }) +} + +func (obj RemoveLiquidityByRange) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `FromBinId` param: + err = encoder.Encode(obj.FromBinId) + if err != nil { + return err + } + // Serialize `ToBinId` param: + err = encoder.Encode(obj.ToBinId) + if err != nil { + return err + } + // Serialize `BpsToRemove` param: + err = encoder.Encode(obj.BpsToRemove) + if err != nil { + return err + } + return nil +} +func (obj *RemoveLiquidityByRange) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `FromBinId`: + err = decoder.Decode(&obj.FromBinId) + if err != nil { + return err + } + // Deserialize `ToBinId`: + err = decoder.Decode(&obj.ToBinId) + if err != nil { + return err + } + // Deserialize `BpsToRemove`: + err = decoder.Decode(&obj.BpsToRemove) + if err != nil { + return err + } + return nil +} + +// NewRemoveLiquidityByRangeInstruction declares a new RemoveLiquidityByRange instruction with the provided parameters and accounts. +func NewRemoveLiquidityByRangeInstruction( + // Parameters: + fromBinId int32, + toBinId int32, + bpsToRemove uint16, + // Accounts: + position ag_solanago.PublicKey, + lbPair ag_solanago.PublicKey, + binArrayBitmapExtension ag_solanago.PublicKey, + userTokenX ag_solanago.PublicKey, + userTokenY ag_solanago.PublicKey, + reserveX ag_solanago.PublicKey, + reserveY ag_solanago.PublicKey, + tokenXMint ag_solanago.PublicKey, + tokenYMint ag_solanago.PublicKey, + binArrayLower ag_solanago.PublicKey, + binArrayUpper ag_solanago.PublicKey, + sender ag_solanago.PublicKey, + tokenXProgram ag_solanago.PublicKey, + tokenYProgram ag_solanago.PublicKey, + eventAuthority ag_solanago.PublicKey, + program ag_solanago.PublicKey) *RemoveLiquidityByRange { + return NewRemoveLiquidityByRangeInstructionBuilder(). + SetFromBinId(fromBinId). + SetToBinId(toBinId). + SetBpsToRemove(bpsToRemove). + SetPositionAccount(position). + SetLbPairAccount(lbPair). + SetBinArrayBitmapExtensionAccount(binArrayBitmapExtension). + SetUserTokenXAccount(userTokenX). + SetUserTokenYAccount(userTokenY). + SetReserveXAccount(reserveX). + SetReserveYAccount(reserveY). + SetTokenXMintAccount(tokenXMint). + SetTokenYMintAccount(tokenYMint). + SetBinArrayLowerAccount(binArrayLower). + SetBinArrayUpperAccount(binArrayUpper). + SetSenderAccount(sender). + SetTokenXProgramAccount(tokenXProgram). + SetTokenYProgramAccount(tokenYProgram). + SetEventAuthorityAccount(eventAuthority). + SetProgramAccount(program) +} diff --git a/programs/meteoradlmm/RemoveLiquidityByRange_test.go b/programs/meteoradlmm/RemoveLiquidityByRange_test.go new file mode 100644 index 00000000..0f8cb21f --- /dev/null +++ b/programs/meteoradlmm/RemoveLiquidityByRange_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_RemoveLiquidityByRange(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("RemoveLiquidityByRange"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(RemoveLiquidityByRange) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(RemoveLiquidityByRange) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/RemoveLiquidity_test.go b/programs/meteoradlmm/RemoveLiquidity_test.go new file mode 100644 index 00000000..95bf02ac --- /dev/null +++ b/programs/meteoradlmm/RemoveLiquidity_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_RemoveLiquidity(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("RemoveLiquidity"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(RemoveLiquidity) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(RemoveLiquidity) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/SetActivationPoint.go b/programs/meteoradlmm/SetActivationPoint.go new file mode 100644 index 00000000..5e20ad5e --- /dev/null +++ b/programs/meteoradlmm/SetActivationPoint.go @@ -0,0 +1,146 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// SetActivationPoint is the `setActivationPoint` instruction. +type SetActivationPoint struct { + ActivationPoint *uint64 + + // [0] = [WRITE] lbPair + // + // [1] = [WRITE, SIGNER] admin + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewSetActivationPointInstructionBuilder creates a new `SetActivationPoint` instruction builder. +func NewSetActivationPointInstructionBuilder() *SetActivationPoint { + nd := &SetActivationPoint{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 2), + } + return nd +} + +// SetActivationPoint sets the "activationPoint" parameter. +func (inst *SetActivationPoint) SetActivationPoint(activationPoint uint64) *SetActivationPoint { + inst.ActivationPoint = &activationPoint + return inst +} + +// SetLbPairAccount sets the "lbPair" account. +func (inst *SetActivationPoint) SetLbPairAccount(lbPair ag_solanago.PublicKey) *SetActivationPoint { + inst.AccountMetaSlice[0] = ag_solanago.Meta(lbPair).WRITE() + return inst +} + +// GetLbPairAccount gets the "lbPair" account. +func (inst *SetActivationPoint) GetLbPairAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetAdminAccount sets the "admin" account. +func (inst *SetActivationPoint) SetAdminAccount(admin ag_solanago.PublicKey) *SetActivationPoint { + inst.AccountMetaSlice[1] = ag_solanago.Meta(admin).WRITE().SIGNER() + return inst +} + +// GetAdminAccount gets the "admin" account. +func (inst *SetActivationPoint) GetAdminAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +func (inst SetActivationPoint) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_SetActivationPoint, + }} +} + +// 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 SetActivationPoint) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *SetActivationPoint) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.ActivationPoint == nil { + return errors.New("ActivationPoint parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.LbPair is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Admin is not set") + } + } + return nil +} + +func (inst *SetActivationPoint) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("SetActivationPoint")). + // + 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("ActivationPoint", *inst.ActivationPoint)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=2]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta("lbPair", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" admin", inst.AccountMetaSlice.Get(1))) + }) + }) + }) +} + +func (obj SetActivationPoint) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `ActivationPoint` param: + err = encoder.Encode(obj.ActivationPoint) + if err != nil { + return err + } + return nil +} +func (obj *SetActivationPoint) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `ActivationPoint`: + err = decoder.Decode(&obj.ActivationPoint) + if err != nil { + return err + } + return nil +} + +// NewSetActivationPointInstruction declares a new SetActivationPoint instruction with the provided parameters and accounts. +func NewSetActivationPointInstruction( + // Parameters: + activationPoint uint64, + // Accounts: + lbPair ag_solanago.PublicKey, + admin ag_solanago.PublicKey) *SetActivationPoint { + return NewSetActivationPointInstructionBuilder(). + SetActivationPoint(activationPoint). + SetLbPairAccount(lbPair). + SetAdminAccount(admin) +} diff --git a/programs/meteoradlmm/SetActivationPoint_test.go b/programs/meteoradlmm/SetActivationPoint_test.go new file mode 100644 index 00000000..b9a2a52a --- /dev/null +++ b/programs/meteoradlmm/SetActivationPoint_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_SetActivationPoint(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("SetActivationPoint"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(SetActivationPoint) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(SetActivationPoint) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/SetPreActivationDuration.go b/programs/meteoradlmm/SetPreActivationDuration.go new file mode 100644 index 00000000..6ebc8f19 --- /dev/null +++ b/programs/meteoradlmm/SetPreActivationDuration.go @@ -0,0 +1,146 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// SetPreActivationDuration is the `setPreActivationDuration` instruction. +type SetPreActivationDuration struct { + PreActivationDuration *uint64 + + // [0] = [WRITE] lbPair + // + // [1] = [SIGNER] creator + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewSetPreActivationDurationInstructionBuilder creates a new `SetPreActivationDuration` instruction builder. +func NewSetPreActivationDurationInstructionBuilder() *SetPreActivationDuration { + nd := &SetPreActivationDuration{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 2), + } + return nd +} + +// SetPreActivationDuration sets the "preActivationDuration" parameter. +func (inst *SetPreActivationDuration) SetPreActivationDuration(preActivationDuration uint64) *SetPreActivationDuration { + inst.PreActivationDuration = &preActivationDuration + return inst +} + +// SetLbPairAccount sets the "lbPair" account. +func (inst *SetPreActivationDuration) SetLbPairAccount(lbPair ag_solanago.PublicKey) *SetPreActivationDuration { + inst.AccountMetaSlice[0] = ag_solanago.Meta(lbPair).WRITE() + return inst +} + +// GetLbPairAccount gets the "lbPair" account. +func (inst *SetPreActivationDuration) GetLbPairAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetCreatorAccount sets the "creator" account. +func (inst *SetPreActivationDuration) SetCreatorAccount(creator ag_solanago.PublicKey) *SetPreActivationDuration { + inst.AccountMetaSlice[1] = ag_solanago.Meta(creator).SIGNER() + return inst +} + +// GetCreatorAccount gets the "creator" account. +func (inst *SetPreActivationDuration) GetCreatorAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +func (inst SetPreActivationDuration) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_SetPreActivationDuration, + }} +} + +// 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 SetPreActivationDuration) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *SetPreActivationDuration) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.PreActivationDuration == nil { + return errors.New("PreActivationDuration parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.LbPair is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Creator is not set") + } + } + return nil +} + +func (inst *SetPreActivationDuration) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("SetPreActivationDuration")). + // + 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("PreActivationDuration", *inst.PreActivationDuration)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=2]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" lbPair", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta("creator", inst.AccountMetaSlice.Get(1))) + }) + }) + }) +} + +func (obj SetPreActivationDuration) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `PreActivationDuration` param: + err = encoder.Encode(obj.PreActivationDuration) + if err != nil { + return err + } + return nil +} +func (obj *SetPreActivationDuration) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `PreActivationDuration`: + err = decoder.Decode(&obj.PreActivationDuration) + if err != nil { + return err + } + return nil +} + +// NewSetPreActivationDurationInstruction declares a new SetPreActivationDuration instruction with the provided parameters and accounts. +func NewSetPreActivationDurationInstruction( + // Parameters: + preActivationDuration uint64, + // Accounts: + lbPair ag_solanago.PublicKey, + creator ag_solanago.PublicKey) *SetPreActivationDuration { + return NewSetPreActivationDurationInstructionBuilder(). + SetPreActivationDuration(preActivationDuration). + SetLbPairAccount(lbPair). + SetCreatorAccount(creator) +} diff --git a/programs/meteoradlmm/SetPreActivationDuration_test.go b/programs/meteoradlmm/SetPreActivationDuration_test.go new file mode 100644 index 00000000..14cf375b --- /dev/null +++ b/programs/meteoradlmm/SetPreActivationDuration_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_SetPreActivationDuration(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("SetPreActivationDuration"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(SetPreActivationDuration) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(SetPreActivationDuration) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/SetPreActivationSwapAddress.go b/programs/meteoradlmm/SetPreActivationSwapAddress.go new file mode 100644 index 00000000..b1628a62 --- /dev/null +++ b/programs/meteoradlmm/SetPreActivationSwapAddress.go @@ -0,0 +1,146 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// SetPreActivationSwapAddress is the `setPreActivationSwapAddress` instruction. +type SetPreActivationSwapAddress struct { + PreActivationSwapAddress *ag_solanago.PublicKey + + // [0] = [WRITE] lbPair + // + // [1] = [SIGNER] creator + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewSetPreActivationSwapAddressInstructionBuilder creates a new `SetPreActivationSwapAddress` instruction builder. +func NewSetPreActivationSwapAddressInstructionBuilder() *SetPreActivationSwapAddress { + nd := &SetPreActivationSwapAddress{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 2), + } + return nd +} + +// SetPreActivationSwapAddress sets the "preActivationSwapAddress" parameter. +func (inst *SetPreActivationSwapAddress) SetPreActivationSwapAddress(preActivationSwapAddress ag_solanago.PublicKey) *SetPreActivationSwapAddress { + inst.PreActivationSwapAddress = &preActivationSwapAddress + return inst +} + +// SetLbPairAccount sets the "lbPair" account. +func (inst *SetPreActivationSwapAddress) SetLbPairAccount(lbPair ag_solanago.PublicKey) *SetPreActivationSwapAddress { + inst.AccountMetaSlice[0] = ag_solanago.Meta(lbPair).WRITE() + return inst +} + +// GetLbPairAccount gets the "lbPair" account. +func (inst *SetPreActivationSwapAddress) GetLbPairAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetCreatorAccount sets the "creator" account. +func (inst *SetPreActivationSwapAddress) SetCreatorAccount(creator ag_solanago.PublicKey) *SetPreActivationSwapAddress { + inst.AccountMetaSlice[1] = ag_solanago.Meta(creator).SIGNER() + return inst +} + +// GetCreatorAccount gets the "creator" account. +func (inst *SetPreActivationSwapAddress) GetCreatorAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +func (inst SetPreActivationSwapAddress) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_SetPreActivationSwapAddress, + }} +} + +// 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 SetPreActivationSwapAddress) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *SetPreActivationSwapAddress) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.PreActivationSwapAddress == nil { + return errors.New("PreActivationSwapAddress parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.LbPair is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Creator is not set") + } + } + return nil +} + +func (inst *SetPreActivationSwapAddress) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("SetPreActivationSwapAddress")). + // + 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("PreActivationSwapAddress", *inst.PreActivationSwapAddress)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=2]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" lbPair", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta("creator", inst.AccountMetaSlice.Get(1))) + }) + }) + }) +} + +func (obj SetPreActivationSwapAddress) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `PreActivationSwapAddress` param: + err = encoder.Encode(obj.PreActivationSwapAddress) + if err != nil { + return err + } + return nil +} +func (obj *SetPreActivationSwapAddress) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `PreActivationSwapAddress`: + err = decoder.Decode(&obj.PreActivationSwapAddress) + if err != nil { + return err + } + return nil +} + +// NewSetPreActivationSwapAddressInstruction declares a new SetPreActivationSwapAddress instruction with the provided parameters and accounts. +func NewSetPreActivationSwapAddressInstruction( + // Parameters: + preActivationSwapAddress ag_solanago.PublicKey, + // Accounts: + lbPair ag_solanago.PublicKey, + creator ag_solanago.PublicKey) *SetPreActivationSwapAddress { + return NewSetPreActivationSwapAddressInstructionBuilder(). + SetPreActivationSwapAddress(preActivationSwapAddress). + SetLbPairAccount(lbPair). + SetCreatorAccount(creator) +} diff --git a/programs/meteoradlmm/SetPreActivationSwapAddress_test.go b/programs/meteoradlmm/SetPreActivationSwapAddress_test.go new file mode 100644 index 00000000..88a854ce --- /dev/null +++ b/programs/meteoradlmm/SetPreActivationSwapAddress_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_SetPreActivationSwapAddress(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("SetPreActivationSwapAddress"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(SetPreActivationSwapAddress) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(SetPreActivationSwapAddress) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/Swap.go b/programs/meteoradlmm/Swap.go new file mode 100644 index 00000000..60009bb5 --- /dev/null +++ b/programs/meteoradlmm/Swap.go @@ -0,0 +1,416 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// Swap is the `swap` instruction. +type Swap struct { + AmountIn *uint64 + MinAmountOut *uint64 + + // [0] = [WRITE] lbPair + // + // [1] = [] binArrayBitmapExtension + // + // [2] = [WRITE] reserveX + // + // [3] = [WRITE] reserveY + // + // [4] = [WRITE] userTokenIn + // + // [5] = [WRITE] userTokenOut + // + // [6] = [] tokenXMint + // + // [7] = [] tokenYMint + // + // [8] = [WRITE] oracle + // + // [9] = [WRITE] hostFeeIn + // + // [10] = [SIGNER] user + // + // [11] = [] tokenXProgram + // + // [12] = [] tokenYProgram + // + // [13] = [] eventAuthority + // + // [14] = [] program + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewSwapInstructionBuilder creates a new `Swap` instruction builder. +func NewSwapInstructionBuilder() *Swap { + nd := &Swap{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 15), + } + return nd +} + +// SetAmountIn sets the "amountIn" parameter. +func (inst *Swap) SetAmountIn(amountIn uint64) *Swap { + inst.AmountIn = &amountIn + return inst +} + +// SetMinAmountOut sets the "minAmountOut" parameter. +func (inst *Swap) SetMinAmountOut(minAmountOut uint64) *Swap { + inst.MinAmountOut = &minAmountOut + return inst +} + +// SetLbPairAccount sets the "lbPair" account. +func (inst *Swap) SetLbPairAccount(lbPair ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[0] = ag_solanago.Meta(lbPair).WRITE() + return inst +} + +// GetLbPairAccount gets the "lbPair" account. +func (inst *Swap) GetLbPairAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetBinArrayBitmapExtensionAccount sets the "binArrayBitmapExtension" account. +func (inst *Swap) SetBinArrayBitmapExtensionAccount(binArrayBitmapExtension ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[1] = ag_solanago.Meta(binArrayBitmapExtension) + return inst +} + +// GetBinArrayBitmapExtensionAccount gets the "binArrayBitmapExtension" account. +func (inst *Swap) GetBinArrayBitmapExtensionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetReserveXAccount sets the "reserveX" account. +func (inst *Swap) SetReserveXAccount(reserveX ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[2] = ag_solanago.Meta(reserveX).WRITE() + return inst +} + +// GetReserveXAccount gets the "reserveX" account. +func (inst *Swap) GetReserveXAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetReserveYAccount sets the "reserveY" account. +func (inst *Swap) SetReserveYAccount(reserveY ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[3] = ag_solanago.Meta(reserveY).WRITE() + return inst +} + +// GetReserveYAccount gets the "reserveY" account. +func (inst *Swap) GetReserveYAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetUserTokenInAccount sets the "userTokenIn" account. +func (inst *Swap) SetUserTokenInAccount(userTokenIn ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[4] = ag_solanago.Meta(userTokenIn).WRITE() + return inst +} + +// GetUserTokenInAccount gets the "userTokenIn" account. +func (inst *Swap) GetUserTokenInAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetUserTokenOutAccount sets the "userTokenOut" account. +func (inst *Swap) SetUserTokenOutAccount(userTokenOut ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[5] = ag_solanago.Meta(userTokenOut).WRITE() + return inst +} + +// GetUserTokenOutAccount gets the "userTokenOut" account. +func (inst *Swap) GetUserTokenOutAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetTokenXMintAccount sets the "tokenXMint" account. +func (inst *Swap) SetTokenXMintAccount(tokenXMint ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[6] = ag_solanago.Meta(tokenXMint) + return inst +} + +// GetTokenXMintAccount gets the "tokenXMint" account. +func (inst *Swap) GetTokenXMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetTokenYMintAccount sets the "tokenYMint" account. +func (inst *Swap) SetTokenYMintAccount(tokenYMint ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[7] = ag_solanago.Meta(tokenYMint) + return inst +} + +// GetTokenYMintAccount gets the "tokenYMint" account. +func (inst *Swap) GetTokenYMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetOracleAccount sets the "oracle" account. +func (inst *Swap) SetOracleAccount(oracle ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[8] = ag_solanago.Meta(oracle).WRITE() + return inst +} + +// GetOracleAccount gets the "oracle" account. +func (inst *Swap) GetOracleAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetHostFeeInAccount sets the "hostFeeIn" account. +func (inst *Swap) SetHostFeeInAccount(hostFeeIn ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[9] = ag_solanago.Meta(hostFeeIn).WRITE() + return inst +} + +// GetHostFeeInAccount gets the "hostFeeIn" account. +func (inst *Swap) GetHostFeeInAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetUserAccount sets the "user" account. +func (inst *Swap) SetUserAccount(user ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[10] = ag_solanago.Meta(user).SIGNER() + return inst +} + +// GetUserAccount gets the "user" account. +func (inst *Swap) GetUserAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetTokenXProgramAccount sets the "tokenXProgram" account. +func (inst *Swap) SetTokenXProgramAccount(tokenXProgram ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[11] = ag_solanago.Meta(tokenXProgram) + return inst +} + +// GetTokenXProgramAccount gets the "tokenXProgram" account. +func (inst *Swap) GetTokenXProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetTokenYProgramAccount sets the "tokenYProgram" account. +func (inst *Swap) SetTokenYProgramAccount(tokenYProgram ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[12] = ag_solanago.Meta(tokenYProgram) + return inst +} + +// GetTokenYProgramAccount gets the "tokenYProgram" account. +func (inst *Swap) GetTokenYProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetEventAuthorityAccount sets the "eventAuthority" account. +func (inst *Swap) SetEventAuthorityAccount(eventAuthority ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[13] = ag_solanago.Meta(eventAuthority) + return inst +} + +// GetEventAuthorityAccount gets the "eventAuthority" account. +func (inst *Swap) GetEventAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetProgramAccount sets the "program" account. +func (inst *Swap) SetProgramAccount(program ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[14] = ag_solanago.Meta(program) + return inst +} + +// GetProgramAccount gets the "program" account. +func (inst *Swap) GetProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +func (inst Swap) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_Swap, + }} +} + +// 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 Swap) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *Swap) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.AmountIn == nil { + return errors.New("AmountIn parameter is not set") + } + if inst.MinAmountOut == nil { + return errors.New("MinAmountOut parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.LbPair is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.BinArrayBitmapExtension is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.ReserveX is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.ReserveY is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.UserTokenIn is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.UserTokenOut is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.TokenXMint is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.TokenYMint is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.Oracle is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.HostFeeIn is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.User is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.TokenXProgram is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.TokenYProgram is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.EventAuthority is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.Program is not set") + } + } + return nil +} + +func (inst *Swap) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("Swap")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=2]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" AmountIn", *inst.AmountIn)) + paramsBranch.Child(ag_format.Param("MinAmountOut", *inst.MinAmountOut)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=15]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" lbPair", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta("binArrayBitmapExtension", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" reserveX", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" reserveY", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" userTokenIn", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" userTokenOut", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" tokenXMint", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" tokenYMint", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" oracle", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" hostFeeIn", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" user", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" tokenXProgram", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" tokenYProgram", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" eventAuthority", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta(" program", inst.AccountMetaSlice.Get(14))) + }) + }) + }) +} + +func (obj Swap) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `AmountIn` param: + err = encoder.Encode(obj.AmountIn) + if err != nil { + return err + } + // Serialize `MinAmountOut` param: + err = encoder.Encode(obj.MinAmountOut) + if err != nil { + return err + } + return nil +} +func (obj *Swap) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `AmountIn`: + err = decoder.Decode(&obj.AmountIn) + if err != nil { + return err + } + // Deserialize `MinAmountOut`: + err = decoder.Decode(&obj.MinAmountOut) + if err != nil { + return err + } + return nil +} + +// NewSwapInstruction declares a new Swap instruction with the provided parameters and accounts. +func NewSwapInstruction( + // Parameters: + amountIn uint64, + minAmountOut uint64, + // Accounts: + lbPair ag_solanago.PublicKey, + binArrayBitmapExtension ag_solanago.PublicKey, + reserveX ag_solanago.PublicKey, + reserveY ag_solanago.PublicKey, + userTokenIn ag_solanago.PublicKey, + userTokenOut ag_solanago.PublicKey, + tokenXMint ag_solanago.PublicKey, + tokenYMint ag_solanago.PublicKey, + oracle ag_solanago.PublicKey, + hostFeeIn ag_solanago.PublicKey, + user ag_solanago.PublicKey, + tokenXProgram ag_solanago.PublicKey, + tokenYProgram ag_solanago.PublicKey, + eventAuthority ag_solanago.PublicKey, + program ag_solanago.PublicKey) *Swap { + return NewSwapInstructionBuilder(). + SetAmountIn(amountIn). + SetMinAmountOut(minAmountOut). + SetLbPairAccount(lbPair). + SetBinArrayBitmapExtensionAccount(binArrayBitmapExtension). + SetReserveXAccount(reserveX). + SetReserveYAccount(reserveY). + SetUserTokenInAccount(userTokenIn). + SetUserTokenOutAccount(userTokenOut). + SetTokenXMintAccount(tokenXMint). + SetTokenYMintAccount(tokenYMint). + SetOracleAccount(oracle). + SetHostFeeInAccount(hostFeeIn). + SetUserAccount(user). + SetTokenXProgramAccount(tokenXProgram). + SetTokenYProgramAccount(tokenYProgram). + SetEventAuthorityAccount(eventAuthority). + SetProgramAccount(program) +} diff --git a/programs/meteoradlmm/SwapExactOut.go b/programs/meteoradlmm/SwapExactOut.go new file mode 100644 index 00000000..930af3d4 --- /dev/null +++ b/programs/meteoradlmm/SwapExactOut.go @@ -0,0 +1,416 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// SwapExactOut is the `swapExactOut` instruction. +type SwapExactOut struct { + MaxInAmount *uint64 + OutAmount *uint64 + + // [0] = [WRITE] lbPair + // + // [1] = [] binArrayBitmapExtension + // + // [2] = [WRITE] reserveX + // + // [3] = [WRITE] reserveY + // + // [4] = [WRITE] userTokenIn + // + // [5] = [WRITE] userTokenOut + // + // [6] = [] tokenXMint + // + // [7] = [] tokenYMint + // + // [8] = [WRITE] oracle + // + // [9] = [WRITE] hostFeeIn + // + // [10] = [SIGNER] user + // + // [11] = [] tokenXProgram + // + // [12] = [] tokenYProgram + // + // [13] = [] eventAuthority + // + // [14] = [] program + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewSwapExactOutInstructionBuilder creates a new `SwapExactOut` instruction builder. +func NewSwapExactOutInstructionBuilder() *SwapExactOut { + nd := &SwapExactOut{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 15), + } + return nd +} + +// SetMaxInAmount sets the "maxInAmount" parameter. +func (inst *SwapExactOut) SetMaxInAmount(maxInAmount uint64) *SwapExactOut { + inst.MaxInAmount = &maxInAmount + return inst +} + +// SetOutAmount sets the "outAmount" parameter. +func (inst *SwapExactOut) SetOutAmount(outAmount uint64) *SwapExactOut { + inst.OutAmount = &outAmount + return inst +} + +// SetLbPairAccount sets the "lbPair" account. +func (inst *SwapExactOut) SetLbPairAccount(lbPair ag_solanago.PublicKey) *SwapExactOut { + inst.AccountMetaSlice[0] = ag_solanago.Meta(lbPair).WRITE() + return inst +} + +// GetLbPairAccount gets the "lbPair" account. +func (inst *SwapExactOut) GetLbPairAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetBinArrayBitmapExtensionAccount sets the "binArrayBitmapExtension" account. +func (inst *SwapExactOut) SetBinArrayBitmapExtensionAccount(binArrayBitmapExtension ag_solanago.PublicKey) *SwapExactOut { + inst.AccountMetaSlice[1] = ag_solanago.Meta(binArrayBitmapExtension) + return inst +} + +// GetBinArrayBitmapExtensionAccount gets the "binArrayBitmapExtension" account. +func (inst *SwapExactOut) GetBinArrayBitmapExtensionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetReserveXAccount sets the "reserveX" account. +func (inst *SwapExactOut) SetReserveXAccount(reserveX ag_solanago.PublicKey) *SwapExactOut { + inst.AccountMetaSlice[2] = ag_solanago.Meta(reserveX).WRITE() + return inst +} + +// GetReserveXAccount gets the "reserveX" account. +func (inst *SwapExactOut) GetReserveXAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetReserveYAccount sets the "reserveY" account. +func (inst *SwapExactOut) SetReserveYAccount(reserveY ag_solanago.PublicKey) *SwapExactOut { + inst.AccountMetaSlice[3] = ag_solanago.Meta(reserveY).WRITE() + return inst +} + +// GetReserveYAccount gets the "reserveY" account. +func (inst *SwapExactOut) GetReserveYAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetUserTokenInAccount sets the "userTokenIn" account. +func (inst *SwapExactOut) SetUserTokenInAccount(userTokenIn ag_solanago.PublicKey) *SwapExactOut { + inst.AccountMetaSlice[4] = ag_solanago.Meta(userTokenIn).WRITE() + return inst +} + +// GetUserTokenInAccount gets the "userTokenIn" account. +func (inst *SwapExactOut) GetUserTokenInAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetUserTokenOutAccount sets the "userTokenOut" account. +func (inst *SwapExactOut) SetUserTokenOutAccount(userTokenOut ag_solanago.PublicKey) *SwapExactOut { + inst.AccountMetaSlice[5] = ag_solanago.Meta(userTokenOut).WRITE() + return inst +} + +// GetUserTokenOutAccount gets the "userTokenOut" account. +func (inst *SwapExactOut) GetUserTokenOutAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetTokenXMintAccount sets the "tokenXMint" account. +func (inst *SwapExactOut) SetTokenXMintAccount(tokenXMint ag_solanago.PublicKey) *SwapExactOut { + inst.AccountMetaSlice[6] = ag_solanago.Meta(tokenXMint) + return inst +} + +// GetTokenXMintAccount gets the "tokenXMint" account. +func (inst *SwapExactOut) GetTokenXMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetTokenYMintAccount sets the "tokenYMint" account. +func (inst *SwapExactOut) SetTokenYMintAccount(tokenYMint ag_solanago.PublicKey) *SwapExactOut { + inst.AccountMetaSlice[7] = ag_solanago.Meta(tokenYMint) + return inst +} + +// GetTokenYMintAccount gets the "tokenYMint" account. +func (inst *SwapExactOut) GetTokenYMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetOracleAccount sets the "oracle" account. +func (inst *SwapExactOut) SetOracleAccount(oracle ag_solanago.PublicKey) *SwapExactOut { + inst.AccountMetaSlice[8] = ag_solanago.Meta(oracle).WRITE() + return inst +} + +// GetOracleAccount gets the "oracle" account. +func (inst *SwapExactOut) GetOracleAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetHostFeeInAccount sets the "hostFeeIn" account. +func (inst *SwapExactOut) SetHostFeeInAccount(hostFeeIn ag_solanago.PublicKey) *SwapExactOut { + inst.AccountMetaSlice[9] = ag_solanago.Meta(hostFeeIn).WRITE() + return inst +} + +// GetHostFeeInAccount gets the "hostFeeIn" account. +func (inst *SwapExactOut) GetHostFeeInAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetUserAccount sets the "user" account. +func (inst *SwapExactOut) SetUserAccount(user ag_solanago.PublicKey) *SwapExactOut { + inst.AccountMetaSlice[10] = ag_solanago.Meta(user).SIGNER() + return inst +} + +// GetUserAccount gets the "user" account. +func (inst *SwapExactOut) GetUserAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetTokenXProgramAccount sets the "tokenXProgram" account. +func (inst *SwapExactOut) SetTokenXProgramAccount(tokenXProgram ag_solanago.PublicKey) *SwapExactOut { + inst.AccountMetaSlice[11] = ag_solanago.Meta(tokenXProgram) + return inst +} + +// GetTokenXProgramAccount gets the "tokenXProgram" account. +func (inst *SwapExactOut) GetTokenXProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetTokenYProgramAccount sets the "tokenYProgram" account. +func (inst *SwapExactOut) SetTokenYProgramAccount(tokenYProgram ag_solanago.PublicKey) *SwapExactOut { + inst.AccountMetaSlice[12] = ag_solanago.Meta(tokenYProgram) + return inst +} + +// GetTokenYProgramAccount gets the "tokenYProgram" account. +func (inst *SwapExactOut) GetTokenYProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetEventAuthorityAccount sets the "eventAuthority" account. +func (inst *SwapExactOut) SetEventAuthorityAccount(eventAuthority ag_solanago.PublicKey) *SwapExactOut { + inst.AccountMetaSlice[13] = ag_solanago.Meta(eventAuthority) + return inst +} + +// GetEventAuthorityAccount gets the "eventAuthority" account. +func (inst *SwapExactOut) GetEventAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetProgramAccount sets the "program" account. +func (inst *SwapExactOut) SetProgramAccount(program ag_solanago.PublicKey) *SwapExactOut { + inst.AccountMetaSlice[14] = ag_solanago.Meta(program) + return inst +} + +// GetProgramAccount gets the "program" account. +func (inst *SwapExactOut) GetProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +func (inst SwapExactOut) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_SwapExactOut, + }} +} + +// 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 SwapExactOut) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *SwapExactOut) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.MaxInAmount == nil { + return errors.New("MaxInAmount parameter is not set") + } + if inst.OutAmount == nil { + return errors.New("OutAmount parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.LbPair is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.BinArrayBitmapExtension is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.ReserveX is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.ReserveY is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.UserTokenIn is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.UserTokenOut is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.TokenXMint is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.TokenYMint is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.Oracle is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.HostFeeIn is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.User is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.TokenXProgram is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.TokenYProgram is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.EventAuthority is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.Program is not set") + } + } + return nil +} + +func (inst *SwapExactOut) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("SwapExactOut")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=2]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param("MaxInAmount", *inst.MaxInAmount)) + paramsBranch.Child(ag_format.Param(" OutAmount", *inst.OutAmount)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=15]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" lbPair", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta("binArrayBitmapExtension", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" reserveX", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" reserveY", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" userTokenIn", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" userTokenOut", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" tokenXMint", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" tokenYMint", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" oracle", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" hostFeeIn", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" user", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" tokenXProgram", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" tokenYProgram", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" eventAuthority", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta(" program", inst.AccountMetaSlice.Get(14))) + }) + }) + }) +} + +func (obj SwapExactOut) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `MaxInAmount` param: + err = encoder.Encode(obj.MaxInAmount) + if err != nil { + return err + } + // Serialize `OutAmount` param: + err = encoder.Encode(obj.OutAmount) + if err != nil { + return err + } + return nil +} +func (obj *SwapExactOut) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `MaxInAmount`: + err = decoder.Decode(&obj.MaxInAmount) + if err != nil { + return err + } + // Deserialize `OutAmount`: + err = decoder.Decode(&obj.OutAmount) + if err != nil { + return err + } + return nil +} + +// NewSwapExactOutInstruction declares a new SwapExactOut instruction with the provided parameters and accounts. +func NewSwapExactOutInstruction( + // Parameters: + maxInAmount uint64, + outAmount uint64, + // Accounts: + lbPair ag_solanago.PublicKey, + binArrayBitmapExtension ag_solanago.PublicKey, + reserveX ag_solanago.PublicKey, + reserveY ag_solanago.PublicKey, + userTokenIn ag_solanago.PublicKey, + userTokenOut ag_solanago.PublicKey, + tokenXMint ag_solanago.PublicKey, + tokenYMint ag_solanago.PublicKey, + oracle ag_solanago.PublicKey, + hostFeeIn ag_solanago.PublicKey, + user ag_solanago.PublicKey, + tokenXProgram ag_solanago.PublicKey, + tokenYProgram ag_solanago.PublicKey, + eventAuthority ag_solanago.PublicKey, + program ag_solanago.PublicKey) *SwapExactOut { + return NewSwapExactOutInstructionBuilder(). + SetMaxInAmount(maxInAmount). + SetOutAmount(outAmount). + SetLbPairAccount(lbPair). + SetBinArrayBitmapExtensionAccount(binArrayBitmapExtension). + SetReserveXAccount(reserveX). + SetReserveYAccount(reserveY). + SetUserTokenInAccount(userTokenIn). + SetUserTokenOutAccount(userTokenOut). + SetTokenXMintAccount(tokenXMint). + SetTokenYMintAccount(tokenYMint). + SetOracleAccount(oracle). + SetHostFeeInAccount(hostFeeIn). + SetUserAccount(user). + SetTokenXProgramAccount(tokenXProgram). + SetTokenYProgramAccount(tokenYProgram). + SetEventAuthorityAccount(eventAuthority). + SetProgramAccount(program) +} diff --git a/programs/meteoradlmm/SwapExactOut_test.go b/programs/meteoradlmm/SwapExactOut_test.go new file mode 100644 index 00000000..09bbe4fd --- /dev/null +++ b/programs/meteoradlmm/SwapExactOut_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_SwapExactOut(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("SwapExactOut"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(SwapExactOut) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(SwapExactOut) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/SwapWithPriceImpact.go b/programs/meteoradlmm/SwapWithPriceImpact.go new file mode 100644 index 00000000..4a0c8202 --- /dev/null +++ b/programs/meteoradlmm/SwapWithPriceImpact.go @@ -0,0 +1,457 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// SwapWithPriceImpact is the `swapWithPriceImpact` instruction. +type SwapWithPriceImpact struct { + AmountIn *uint64 + ActiveId *int32 `bin:"optional"` + MaxPriceImpactBps *uint16 + + // [0] = [WRITE] lbPair + // + // [1] = [] binArrayBitmapExtension + // + // [2] = [WRITE] reserveX + // + // [3] = [WRITE] reserveY + // + // [4] = [WRITE] userTokenIn + // + // [5] = [WRITE] userTokenOut + // + // [6] = [] tokenXMint + // + // [7] = [] tokenYMint + // + // [8] = [WRITE] oracle + // + // [9] = [WRITE] hostFeeIn + // + // [10] = [SIGNER] user + // + // [11] = [] tokenXProgram + // + // [12] = [] tokenYProgram + // + // [13] = [] eventAuthority + // + // [14] = [] program + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewSwapWithPriceImpactInstructionBuilder creates a new `SwapWithPriceImpact` instruction builder. +func NewSwapWithPriceImpactInstructionBuilder() *SwapWithPriceImpact { + nd := &SwapWithPriceImpact{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 15), + } + return nd +} + +// SetAmountIn sets the "amountIn" parameter. +func (inst *SwapWithPriceImpact) SetAmountIn(amountIn uint64) *SwapWithPriceImpact { + inst.AmountIn = &amountIn + return inst +} + +// SetActiveId sets the "activeId" parameter. +func (inst *SwapWithPriceImpact) SetActiveId(activeId int32) *SwapWithPriceImpact { + inst.ActiveId = &activeId + return inst +} + +// SetMaxPriceImpactBps sets the "maxPriceImpactBps" parameter. +func (inst *SwapWithPriceImpact) SetMaxPriceImpactBps(maxPriceImpactBps uint16) *SwapWithPriceImpact { + inst.MaxPriceImpactBps = &maxPriceImpactBps + return inst +} + +// SetLbPairAccount sets the "lbPair" account. +func (inst *SwapWithPriceImpact) SetLbPairAccount(lbPair ag_solanago.PublicKey) *SwapWithPriceImpact { + inst.AccountMetaSlice[0] = ag_solanago.Meta(lbPair).WRITE() + return inst +} + +// GetLbPairAccount gets the "lbPair" account. +func (inst *SwapWithPriceImpact) GetLbPairAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetBinArrayBitmapExtensionAccount sets the "binArrayBitmapExtension" account. +func (inst *SwapWithPriceImpact) SetBinArrayBitmapExtensionAccount(binArrayBitmapExtension ag_solanago.PublicKey) *SwapWithPriceImpact { + inst.AccountMetaSlice[1] = ag_solanago.Meta(binArrayBitmapExtension) + return inst +} + +// GetBinArrayBitmapExtensionAccount gets the "binArrayBitmapExtension" account. +func (inst *SwapWithPriceImpact) GetBinArrayBitmapExtensionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetReserveXAccount sets the "reserveX" account. +func (inst *SwapWithPriceImpact) SetReserveXAccount(reserveX ag_solanago.PublicKey) *SwapWithPriceImpact { + inst.AccountMetaSlice[2] = ag_solanago.Meta(reserveX).WRITE() + return inst +} + +// GetReserveXAccount gets the "reserveX" account. +func (inst *SwapWithPriceImpact) GetReserveXAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetReserveYAccount sets the "reserveY" account. +func (inst *SwapWithPriceImpact) SetReserveYAccount(reserveY ag_solanago.PublicKey) *SwapWithPriceImpact { + inst.AccountMetaSlice[3] = ag_solanago.Meta(reserveY).WRITE() + return inst +} + +// GetReserveYAccount gets the "reserveY" account. +func (inst *SwapWithPriceImpact) GetReserveYAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetUserTokenInAccount sets the "userTokenIn" account. +func (inst *SwapWithPriceImpact) SetUserTokenInAccount(userTokenIn ag_solanago.PublicKey) *SwapWithPriceImpact { + inst.AccountMetaSlice[4] = ag_solanago.Meta(userTokenIn).WRITE() + return inst +} + +// GetUserTokenInAccount gets the "userTokenIn" account. +func (inst *SwapWithPriceImpact) GetUserTokenInAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetUserTokenOutAccount sets the "userTokenOut" account. +func (inst *SwapWithPriceImpact) SetUserTokenOutAccount(userTokenOut ag_solanago.PublicKey) *SwapWithPriceImpact { + inst.AccountMetaSlice[5] = ag_solanago.Meta(userTokenOut).WRITE() + return inst +} + +// GetUserTokenOutAccount gets the "userTokenOut" account. +func (inst *SwapWithPriceImpact) GetUserTokenOutAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetTokenXMintAccount sets the "tokenXMint" account. +func (inst *SwapWithPriceImpact) SetTokenXMintAccount(tokenXMint ag_solanago.PublicKey) *SwapWithPriceImpact { + inst.AccountMetaSlice[6] = ag_solanago.Meta(tokenXMint) + return inst +} + +// GetTokenXMintAccount gets the "tokenXMint" account. +func (inst *SwapWithPriceImpact) GetTokenXMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetTokenYMintAccount sets the "tokenYMint" account. +func (inst *SwapWithPriceImpact) SetTokenYMintAccount(tokenYMint ag_solanago.PublicKey) *SwapWithPriceImpact { + inst.AccountMetaSlice[7] = ag_solanago.Meta(tokenYMint) + return inst +} + +// GetTokenYMintAccount gets the "tokenYMint" account. +func (inst *SwapWithPriceImpact) GetTokenYMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetOracleAccount sets the "oracle" account. +func (inst *SwapWithPriceImpact) SetOracleAccount(oracle ag_solanago.PublicKey) *SwapWithPriceImpact { + inst.AccountMetaSlice[8] = ag_solanago.Meta(oracle).WRITE() + return inst +} + +// GetOracleAccount gets the "oracle" account. +func (inst *SwapWithPriceImpact) GetOracleAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetHostFeeInAccount sets the "hostFeeIn" account. +func (inst *SwapWithPriceImpact) SetHostFeeInAccount(hostFeeIn ag_solanago.PublicKey) *SwapWithPriceImpact { + inst.AccountMetaSlice[9] = ag_solanago.Meta(hostFeeIn).WRITE() + return inst +} + +// GetHostFeeInAccount gets the "hostFeeIn" account. +func (inst *SwapWithPriceImpact) GetHostFeeInAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetUserAccount sets the "user" account. +func (inst *SwapWithPriceImpact) SetUserAccount(user ag_solanago.PublicKey) *SwapWithPriceImpact { + inst.AccountMetaSlice[10] = ag_solanago.Meta(user).SIGNER() + return inst +} + +// GetUserAccount gets the "user" account. +func (inst *SwapWithPriceImpact) GetUserAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetTokenXProgramAccount sets the "tokenXProgram" account. +func (inst *SwapWithPriceImpact) SetTokenXProgramAccount(tokenXProgram ag_solanago.PublicKey) *SwapWithPriceImpact { + inst.AccountMetaSlice[11] = ag_solanago.Meta(tokenXProgram) + return inst +} + +// GetTokenXProgramAccount gets the "tokenXProgram" account. +func (inst *SwapWithPriceImpact) GetTokenXProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetTokenYProgramAccount sets the "tokenYProgram" account. +func (inst *SwapWithPriceImpact) SetTokenYProgramAccount(tokenYProgram ag_solanago.PublicKey) *SwapWithPriceImpact { + inst.AccountMetaSlice[12] = ag_solanago.Meta(tokenYProgram) + return inst +} + +// GetTokenYProgramAccount gets the "tokenYProgram" account. +func (inst *SwapWithPriceImpact) GetTokenYProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetEventAuthorityAccount sets the "eventAuthority" account. +func (inst *SwapWithPriceImpact) SetEventAuthorityAccount(eventAuthority ag_solanago.PublicKey) *SwapWithPriceImpact { + inst.AccountMetaSlice[13] = ag_solanago.Meta(eventAuthority) + return inst +} + +// GetEventAuthorityAccount gets the "eventAuthority" account. +func (inst *SwapWithPriceImpact) GetEventAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetProgramAccount sets the "program" account. +func (inst *SwapWithPriceImpact) SetProgramAccount(program ag_solanago.PublicKey) *SwapWithPriceImpact { + inst.AccountMetaSlice[14] = ag_solanago.Meta(program) + return inst +} + +// GetProgramAccount gets the "program" account. +func (inst *SwapWithPriceImpact) GetProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +func (inst SwapWithPriceImpact) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_SwapWithPriceImpact, + }} +} + +// 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 SwapWithPriceImpact) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *SwapWithPriceImpact) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.AmountIn == nil { + return errors.New("AmountIn parameter is not set") + } + if inst.MaxPriceImpactBps == nil { + return errors.New("MaxPriceImpactBps parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.LbPair is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.BinArrayBitmapExtension is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.ReserveX is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.ReserveY is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.UserTokenIn is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.UserTokenOut is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.TokenXMint is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.TokenYMint is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.Oracle is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.HostFeeIn is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.User is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.TokenXProgram is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.TokenYProgram is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.EventAuthority is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.Program is not set") + } + } + return nil +} + +func (inst *SwapWithPriceImpact) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("SwapWithPriceImpact")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=3]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" AmountIn", *inst.AmountIn)) + paramsBranch.Child(ag_format.Param(" ActiveId (OPT)", inst.ActiveId)) + paramsBranch.Child(ag_format.Param("MaxPriceImpactBps", *inst.MaxPriceImpactBps)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=15]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" lbPair", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta("binArrayBitmapExtension", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" reserveX", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" reserveY", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" userTokenIn", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" userTokenOut", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" tokenXMint", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" tokenYMint", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" oracle", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" hostFeeIn", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" user", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" tokenXProgram", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" tokenYProgram", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" eventAuthority", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta(" program", inst.AccountMetaSlice.Get(14))) + }) + }) + }) +} + +func (obj SwapWithPriceImpact) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `AmountIn` param: + err = encoder.Encode(obj.AmountIn) + if err != nil { + return err + } + // Serialize `ActiveId` param (optional): + { + if obj.ActiveId == nil { + err = encoder.WriteBool(false) + if err != nil { + return err + } + } else { + err = encoder.WriteBool(true) + if err != nil { + return err + } + err = encoder.Encode(obj.ActiveId) + if err != nil { + return err + } + } + } + // Serialize `MaxPriceImpactBps` param: + err = encoder.Encode(obj.MaxPriceImpactBps) + if err != nil { + return err + } + return nil +} +func (obj *SwapWithPriceImpact) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `AmountIn`: + err = decoder.Decode(&obj.AmountIn) + if err != nil { + return err + } + // Deserialize `ActiveId` (optional): + { + ok, err := decoder.ReadBool() + if err != nil { + return err + } + if ok { + err = decoder.Decode(&obj.ActiveId) + if err != nil { + return err + } + } + } + // Deserialize `MaxPriceImpactBps`: + err = decoder.Decode(&obj.MaxPriceImpactBps) + if err != nil { + return err + } + return nil +} + +// NewSwapWithPriceImpactInstruction declares a new SwapWithPriceImpact instruction with the provided parameters and accounts. +func NewSwapWithPriceImpactInstruction( + // Parameters: + amountIn uint64, + activeId int32, + maxPriceImpactBps uint16, + // Accounts: + lbPair ag_solanago.PublicKey, + binArrayBitmapExtension ag_solanago.PublicKey, + reserveX ag_solanago.PublicKey, + reserveY ag_solanago.PublicKey, + userTokenIn ag_solanago.PublicKey, + userTokenOut ag_solanago.PublicKey, + tokenXMint ag_solanago.PublicKey, + tokenYMint ag_solanago.PublicKey, + oracle ag_solanago.PublicKey, + hostFeeIn ag_solanago.PublicKey, + user ag_solanago.PublicKey, + tokenXProgram ag_solanago.PublicKey, + tokenYProgram ag_solanago.PublicKey, + eventAuthority ag_solanago.PublicKey, + program ag_solanago.PublicKey) *SwapWithPriceImpact { + return NewSwapWithPriceImpactInstructionBuilder(). + SetAmountIn(amountIn). + SetActiveId(activeId). + SetMaxPriceImpactBps(maxPriceImpactBps). + SetLbPairAccount(lbPair). + SetBinArrayBitmapExtensionAccount(binArrayBitmapExtension). + SetReserveXAccount(reserveX). + SetReserveYAccount(reserveY). + SetUserTokenInAccount(userTokenIn). + SetUserTokenOutAccount(userTokenOut). + SetTokenXMintAccount(tokenXMint). + SetTokenYMintAccount(tokenYMint). + SetOracleAccount(oracle). + SetHostFeeInAccount(hostFeeIn). + SetUserAccount(user). + SetTokenXProgramAccount(tokenXProgram). + SetTokenYProgramAccount(tokenYProgram). + SetEventAuthorityAccount(eventAuthority). + SetProgramAccount(program) +} diff --git a/programs/meteoradlmm/SwapWithPriceImpact_test.go b/programs/meteoradlmm/SwapWithPriceImpact_test.go new file mode 100644 index 00000000..be0dda25 --- /dev/null +++ b/programs/meteoradlmm/SwapWithPriceImpact_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_SwapWithPriceImpact(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("SwapWithPriceImpact"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(SwapWithPriceImpact) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(SwapWithPriceImpact) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/Swap_test.go b/programs/meteoradlmm/Swap_test.go new file mode 100644 index 00000000..98bf6740 --- /dev/null +++ b/programs/meteoradlmm/Swap_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_Swap(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("Swap"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(Swap) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(Swap) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/TogglePairStatus.go b/programs/meteoradlmm/TogglePairStatus.go new file mode 100644 index 00000000..a028be15 --- /dev/null +++ b/programs/meteoradlmm/TogglePairStatus.go @@ -0,0 +1,117 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// TogglePairStatus is the `togglePairStatus` instruction. +type TogglePairStatus struct { + + // [0] = [WRITE] lbPair + // + // [1] = [SIGNER] admin + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewTogglePairStatusInstructionBuilder creates a new `TogglePairStatus` instruction builder. +func NewTogglePairStatusInstructionBuilder() *TogglePairStatus { + nd := &TogglePairStatus{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 2), + } + return nd +} + +// SetLbPairAccount sets the "lbPair" account. +func (inst *TogglePairStatus) SetLbPairAccount(lbPair ag_solanago.PublicKey) *TogglePairStatus { + inst.AccountMetaSlice[0] = ag_solanago.Meta(lbPair).WRITE() + return inst +} + +// GetLbPairAccount gets the "lbPair" account. +func (inst *TogglePairStatus) GetLbPairAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetAdminAccount sets the "admin" account. +func (inst *TogglePairStatus) SetAdminAccount(admin ag_solanago.PublicKey) *TogglePairStatus { + inst.AccountMetaSlice[1] = ag_solanago.Meta(admin).SIGNER() + return inst +} + +// GetAdminAccount gets the "admin" account. +func (inst *TogglePairStatus) GetAdminAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +func (inst TogglePairStatus) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_TogglePairStatus, + }} +} + +// 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 TogglePairStatus) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *TogglePairStatus) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.LbPair is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Admin is not set") + } + } + return nil +} + +func (inst *TogglePairStatus) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("TogglePairStatus")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=2]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta("lbPair", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" admin", inst.AccountMetaSlice.Get(1))) + }) + }) + }) +} + +func (obj TogglePairStatus) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *TogglePairStatus) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewTogglePairStatusInstruction declares a new TogglePairStatus instruction with the provided parameters and accounts. +func NewTogglePairStatusInstruction( + // Accounts: + lbPair ag_solanago.PublicKey, + admin ag_solanago.PublicKey) *TogglePairStatus { + return NewTogglePairStatusInstructionBuilder(). + SetLbPairAccount(lbPair). + SetAdminAccount(admin) +} diff --git a/programs/meteoradlmm/TogglePairStatus_test.go b/programs/meteoradlmm/TogglePairStatus_test.go new file mode 100644 index 00000000..df83fb10 --- /dev/null +++ b/programs/meteoradlmm/TogglePairStatus_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_TogglePairStatus(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("TogglePairStatus"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(TogglePairStatus) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(TogglePairStatus) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/UpdateFeeParameters.go b/programs/meteoradlmm/UpdateFeeParameters.go new file mode 100644 index 00000000..61828f88 --- /dev/null +++ b/programs/meteoradlmm/UpdateFeeParameters.go @@ -0,0 +1,184 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// UpdateFeeParameters is the `updateFeeParameters` instruction. +type UpdateFeeParameters struct { + FeeParameter *FeeParameter + + // [0] = [WRITE] lbPair + // + // [1] = [SIGNER] admin + // + // [2] = [] eventAuthority + // + // [3] = [] program + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewUpdateFeeParametersInstructionBuilder creates a new `UpdateFeeParameters` instruction builder. +func NewUpdateFeeParametersInstructionBuilder() *UpdateFeeParameters { + nd := &UpdateFeeParameters{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 4), + } + return nd +} + +// SetFeeParameter sets the "feeParameter" parameter. +func (inst *UpdateFeeParameters) SetFeeParameter(feeParameter FeeParameter) *UpdateFeeParameters { + inst.FeeParameter = &feeParameter + return inst +} + +// SetLbPairAccount sets the "lbPair" account. +func (inst *UpdateFeeParameters) SetLbPairAccount(lbPair ag_solanago.PublicKey) *UpdateFeeParameters { + inst.AccountMetaSlice[0] = ag_solanago.Meta(lbPair).WRITE() + return inst +} + +// GetLbPairAccount gets the "lbPair" account. +func (inst *UpdateFeeParameters) GetLbPairAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetAdminAccount sets the "admin" account. +func (inst *UpdateFeeParameters) SetAdminAccount(admin ag_solanago.PublicKey) *UpdateFeeParameters { + inst.AccountMetaSlice[1] = ag_solanago.Meta(admin).SIGNER() + return inst +} + +// GetAdminAccount gets the "admin" account. +func (inst *UpdateFeeParameters) GetAdminAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetEventAuthorityAccount sets the "eventAuthority" account. +func (inst *UpdateFeeParameters) SetEventAuthorityAccount(eventAuthority ag_solanago.PublicKey) *UpdateFeeParameters { + inst.AccountMetaSlice[2] = ag_solanago.Meta(eventAuthority) + return inst +} + +// GetEventAuthorityAccount gets the "eventAuthority" account. +func (inst *UpdateFeeParameters) GetEventAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetProgramAccount sets the "program" account. +func (inst *UpdateFeeParameters) SetProgramAccount(program ag_solanago.PublicKey) *UpdateFeeParameters { + inst.AccountMetaSlice[3] = ag_solanago.Meta(program) + return inst +} + +// GetProgramAccount gets the "program" account. +func (inst *UpdateFeeParameters) GetProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +func (inst UpdateFeeParameters) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_UpdateFeeParameters, + }} +} + +// 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 UpdateFeeParameters) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *UpdateFeeParameters) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.FeeParameter == nil { + return errors.New("FeeParameter parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.LbPair is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Admin is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.EventAuthority is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.Program is not set") + } + } + return nil +} + +func (inst *UpdateFeeParameters) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("UpdateFeeParameters")). + // + 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("FeeParameter", *inst.FeeParameter)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=4]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" lbPair", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" admin", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta("eventAuthority", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" program", inst.AccountMetaSlice.Get(3))) + }) + }) + }) +} + +func (obj UpdateFeeParameters) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `FeeParameter` param: + err = encoder.Encode(obj.FeeParameter) + if err != nil { + return err + } + return nil +} +func (obj *UpdateFeeParameters) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `FeeParameter`: + err = decoder.Decode(&obj.FeeParameter) + if err != nil { + return err + } + return nil +} + +// NewUpdateFeeParametersInstruction declares a new UpdateFeeParameters instruction with the provided parameters and accounts. +func NewUpdateFeeParametersInstruction( + // Parameters: + feeParameter FeeParameter, + // Accounts: + lbPair ag_solanago.PublicKey, + admin ag_solanago.PublicKey, + eventAuthority ag_solanago.PublicKey, + program ag_solanago.PublicKey) *UpdateFeeParameters { + return NewUpdateFeeParametersInstructionBuilder(). + SetFeeParameter(feeParameter). + SetLbPairAccount(lbPair). + SetAdminAccount(admin). + SetEventAuthorityAccount(eventAuthority). + SetProgramAccount(program) +} diff --git a/programs/meteoradlmm/UpdateFeeParameters_test.go b/programs/meteoradlmm/UpdateFeeParameters_test.go new file mode 100644 index 00000000..85656a43 --- /dev/null +++ b/programs/meteoradlmm/UpdateFeeParameters_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_UpdateFeeParameters(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("UpdateFeeParameters"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(UpdateFeeParameters) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(UpdateFeeParameters) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/UpdateFeesAndRewards.go b/programs/meteoradlmm/UpdateFeesAndRewards.go new file mode 100644 index 00000000..651647ea --- /dev/null +++ b/programs/meteoradlmm/UpdateFeesAndRewards.go @@ -0,0 +1,174 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// UpdateFeesAndRewards is the `updateFeesAndRewards` instruction. +type UpdateFeesAndRewards struct { + + // [0] = [WRITE] position + // + // [1] = [WRITE] lbPair + // + // [2] = [WRITE] binArrayLower + // + // [3] = [WRITE] binArrayUpper + // + // [4] = [SIGNER] owner + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewUpdateFeesAndRewardsInstructionBuilder creates a new `UpdateFeesAndRewards` instruction builder. +func NewUpdateFeesAndRewardsInstructionBuilder() *UpdateFeesAndRewards { + nd := &UpdateFeesAndRewards{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 5), + } + return nd +} + +// SetPositionAccount sets the "position" account. +func (inst *UpdateFeesAndRewards) SetPositionAccount(position ag_solanago.PublicKey) *UpdateFeesAndRewards { + inst.AccountMetaSlice[0] = ag_solanago.Meta(position).WRITE() + return inst +} + +// GetPositionAccount gets the "position" account. +func (inst *UpdateFeesAndRewards) GetPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetLbPairAccount sets the "lbPair" account. +func (inst *UpdateFeesAndRewards) SetLbPairAccount(lbPair ag_solanago.PublicKey) *UpdateFeesAndRewards { + inst.AccountMetaSlice[1] = ag_solanago.Meta(lbPair).WRITE() + return inst +} + +// GetLbPairAccount gets the "lbPair" account. +func (inst *UpdateFeesAndRewards) GetLbPairAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetBinArrayLowerAccount sets the "binArrayLower" account. +func (inst *UpdateFeesAndRewards) SetBinArrayLowerAccount(binArrayLower ag_solanago.PublicKey) *UpdateFeesAndRewards { + inst.AccountMetaSlice[2] = ag_solanago.Meta(binArrayLower).WRITE() + return inst +} + +// GetBinArrayLowerAccount gets the "binArrayLower" account. +func (inst *UpdateFeesAndRewards) GetBinArrayLowerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetBinArrayUpperAccount sets the "binArrayUpper" account. +func (inst *UpdateFeesAndRewards) SetBinArrayUpperAccount(binArrayUpper ag_solanago.PublicKey) *UpdateFeesAndRewards { + inst.AccountMetaSlice[3] = ag_solanago.Meta(binArrayUpper).WRITE() + return inst +} + +// GetBinArrayUpperAccount gets the "binArrayUpper" account. +func (inst *UpdateFeesAndRewards) GetBinArrayUpperAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetOwnerAccount sets the "owner" account. +func (inst *UpdateFeesAndRewards) SetOwnerAccount(owner ag_solanago.PublicKey) *UpdateFeesAndRewards { + inst.AccountMetaSlice[4] = ag_solanago.Meta(owner).SIGNER() + return inst +} + +// GetOwnerAccount gets the "owner" account. +func (inst *UpdateFeesAndRewards) GetOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +func (inst UpdateFeesAndRewards) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_UpdateFeesAndRewards, + }} +} + +// 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 UpdateFeesAndRewards) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *UpdateFeesAndRewards) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Position is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.LbPair is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.BinArrayLower is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.BinArrayUpper is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.Owner is not set") + } + } + return nil +} + +func (inst *UpdateFeesAndRewards) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("UpdateFeesAndRewards")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=5]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" position", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" lbPair", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta("binArrayLower", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta("binArrayUpper", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" owner", inst.AccountMetaSlice.Get(4))) + }) + }) + }) +} + +func (obj UpdateFeesAndRewards) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *UpdateFeesAndRewards) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewUpdateFeesAndRewardsInstruction declares a new UpdateFeesAndRewards instruction with the provided parameters and accounts. +func NewUpdateFeesAndRewardsInstruction( + // Accounts: + position ag_solanago.PublicKey, + lbPair ag_solanago.PublicKey, + binArrayLower ag_solanago.PublicKey, + binArrayUpper ag_solanago.PublicKey, + owner ag_solanago.PublicKey) *UpdateFeesAndRewards { + return NewUpdateFeesAndRewardsInstructionBuilder(). + SetPositionAccount(position). + SetLbPairAccount(lbPair). + SetBinArrayLowerAccount(binArrayLower). + SetBinArrayUpperAccount(binArrayUpper). + SetOwnerAccount(owner) +} diff --git a/programs/meteoradlmm/UpdateFeesAndRewards_test.go b/programs/meteoradlmm/UpdateFeesAndRewards_test.go new file mode 100644 index 00000000..59408c70 --- /dev/null +++ b/programs/meteoradlmm/UpdateFeesAndRewards_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_UpdateFeesAndRewards(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("UpdateFeesAndRewards"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(UpdateFeesAndRewards) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(UpdateFeesAndRewards) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/UpdatePositionOperator.go b/programs/meteoradlmm/UpdatePositionOperator.go new file mode 100644 index 00000000..76352638 --- /dev/null +++ b/programs/meteoradlmm/UpdatePositionOperator.go @@ -0,0 +1,184 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// UpdatePositionOperator is the `updatePositionOperator` instruction. +type UpdatePositionOperator struct { + Operator *ag_solanago.PublicKey + + // [0] = [WRITE] position + // + // [1] = [SIGNER] owner + // + // [2] = [] eventAuthority + // + // [3] = [] program + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewUpdatePositionOperatorInstructionBuilder creates a new `UpdatePositionOperator` instruction builder. +func NewUpdatePositionOperatorInstructionBuilder() *UpdatePositionOperator { + nd := &UpdatePositionOperator{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 4), + } + return nd +} + +// SetOperator sets the "operator" parameter. +func (inst *UpdatePositionOperator) SetOperator(operator ag_solanago.PublicKey) *UpdatePositionOperator { + inst.Operator = &operator + return inst +} + +// SetPositionAccount sets the "position" account. +func (inst *UpdatePositionOperator) SetPositionAccount(position ag_solanago.PublicKey) *UpdatePositionOperator { + inst.AccountMetaSlice[0] = ag_solanago.Meta(position).WRITE() + return inst +} + +// GetPositionAccount gets the "position" account. +func (inst *UpdatePositionOperator) GetPositionAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetOwnerAccount sets the "owner" account. +func (inst *UpdatePositionOperator) SetOwnerAccount(owner ag_solanago.PublicKey) *UpdatePositionOperator { + inst.AccountMetaSlice[1] = ag_solanago.Meta(owner).SIGNER() + return inst +} + +// GetOwnerAccount gets the "owner" account. +func (inst *UpdatePositionOperator) GetOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetEventAuthorityAccount sets the "eventAuthority" account. +func (inst *UpdatePositionOperator) SetEventAuthorityAccount(eventAuthority ag_solanago.PublicKey) *UpdatePositionOperator { + inst.AccountMetaSlice[2] = ag_solanago.Meta(eventAuthority) + return inst +} + +// GetEventAuthorityAccount gets the "eventAuthority" account. +func (inst *UpdatePositionOperator) GetEventAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetProgramAccount sets the "program" account. +func (inst *UpdatePositionOperator) SetProgramAccount(program ag_solanago.PublicKey) *UpdatePositionOperator { + inst.AccountMetaSlice[3] = ag_solanago.Meta(program) + return inst +} + +// GetProgramAccount gets the "program" account. +func (inst *UpdatePositionOperator) GetProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +func (inst UpdatePositionOperator) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_UpdatePositionOperator, + }} +} + +// 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 UpdatePositionOperator) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *UpdatePositionOperator) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.Operator == nil { + return errors.New("Operator parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Position is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Owner is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.EventAuthority is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.Program is not set") + } + } + return nil +} + +func (inst *UpdatePositionOperator) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("UpdatePositionOperator")). + // + 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("Operator", *inst.Operator)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=4]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" position", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" owner", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta("eventAuthority", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" program", inst.AccountMetaSlice.Get(3))) + }) + }) + }) +} + +func (obj UpdatePositionOperator) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Operator` param: + err = encoder.Encode(obj.Operator) + if err != nil { + return err + } + return nil +} +func (obj *UpdatePositionOperator) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Operator`: + err = decoder.Decode(&obj.Operator) + if err != nil { + return err + } + return nil +} + +// NewUpdatePositionOperatorInstruction declares a new UpdatePositionOperator instruction with the provided parameters and accounts. +func NewUpdatePositionOperatorInstruction( + // Parameters: + operator ag_solanago.PublicKey, + // Accounts: + position ag_solanago.PublicKey, + owner ag_solanago.PublicKey, + eventAuthority ag_solanago.PublicKey, + program ag_solanago.PublicKey) *UpdatePositionOperator { + return NewUpdatePositionOperatorInstructionBuilder(). + SetOperator(operator). + SetPositionAccount(position). + SetOwnerAccount(owner). + SetEventAuthorityAccount(eventAuthority). + SetProgramAccount(program) +} diff --git a/programs/meteoradlmm/UpdatePositionOperator_test.go b/programs/meteoradlmm/UpdatePositionOperator_test.go new file mode 100644 index 00000000..1bfb24f8 --- /dev/null +++ b/programs/meteoradlmm/UpdatePositionOperator_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_UpdatePositionOperator(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("UpdatePositionOperator"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(UpdatePositionOperator) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(UpdatePositionOperator) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/UpdateRewardDuration.go b/programs/meteoradlmm/UpdateRewardDuration.go new file mode 100644 index 00000000..5d5ef818 --- /dev/null +++ b/programs/meteoradlmm/UpdateRewardDuration.go @@ -0,0 +1,226 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// UpdateRewardDuration is the `updateRewardDuration` instruction. +type UpdateRewardDuration struct { + RewardIndex *uint64 + NewDuration *uint64 + + // [0] = [WRITE] lbPair + // + // [1] = [SIGNER] admin + // + // [2] = [WRITE] binArray + // + // [3] = [] eventAuthority + // + // [4] = [] program + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewUpdateRewardDurationInstructionBuilder creates a new `UpdateRewardDuration` instruction builder. +func NewUpdateRewardDurationInstructionBuilder() *UpdateRewardDuration { + nd := &UpdateRewardDuration{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 5), + } + return nd +} + +// SetRewardIndex sets the "rewardIndex" parameter. +func (inst *UpdateRewardDuration) SetRewardIndex(rewardIndex uint64) *UpdateRewardDuration { + inst.RewardIndex = &rewardIndex + return inst +} + +// SetNewDuration sets the "newDuration" parameter. +func (inst *UpdateRewardDuration) SetNewDuration(newDuration uint64) *UpdateRewardDuration { + inst.NewDuration = &newDuration + return inst +} + +// SetLbPairAccount sets the "lbPair" account. +func (inst *UpdateRewardDuration) SetLbPairAccount(lbPair ag_solanago.PublicKey) *UpdateRewardDuration { + inst.AccountMetaSlice[0] = ag_solanago.Meta(lbPair).WRITE() + return inst +} + +// GetLbPairAccount gets the "lbPair" account. +func (inst *UpdateRewardDuration) GetLbPairAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetAdminAccount sets the "admin" account. +func (inst *UpdateRewardDuration) SetAdminAccount(admin ag_solanago.PublicKey) *UpdateRewardDuration { + inst.AccountMetaSlice[1] = ag_solanago.Meta(admin).SIGNER() + return inst +} + +// GetAdminAccount gets the "admin" account. +func (inst *UpdateRewardDuration) GetAdminAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetBinArrayAccount sets the "binArray" account. +func (inst *UpdateRewardDuration) SetBinArrayAccount(binArray ag_solanago.PublicKey) *UpdateRewardDuration { + inst.AccountMetaSlice[2] = ag_solanago.Meta(binArray).WRITE() + return inst +} + +// GetBinArrayAccount gets the "binArray" account. +func (inst *UpdateRewardDuration) GetBinArrayAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetEventAuthorityAccount sets the "eventAuthority" account. +func (inst *UpdateRewardDuration) SetEventAuthorityAccount(eventAuthority ag_solanago.PublicKey) *UpdateRewardDuration { + inst.AccountMetaSlice[3] = ag_solanago.Meta(eventAuthority) + return inst +} + +// GetEventAuthorityAccount gets the "eventAuthority" account. +func (inst *UpdateRewardDuration) GetEventAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetProgramAccount sets the "program" account. +func (inst *UpdateRewardDuration) SetProgramAccount(program ag_solanago.PublicKey) *UpdateRewardDuration { + inst.AccountMetaSlice[4] = ag_solanago.Meta(program) + return inst +} + +// GetProgramAccount gets the "program" account. +func (inst *UpdateRewardDuration) GetProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +func (inst UpdateRewardDuration) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_UpdateRewardDuration, + }} +} + +// 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 UpdateRewardDuration) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *UpdateRewardDuration) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.RewardIndex == nil { + return errors.New("RewardIndex parameter is not set") + } + if inst.NewDuration == nil { + return errors.New("NewDuration parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.LbPair is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Admin is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.BinArray is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.EventAuthority is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.Program is not set") + } + } + return nil +} + +func (inst *UpdateRewardDuration) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("UpdateRewardDuration")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=2]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param("RewardIndex", *inst.RewardIndex)) + paramsBranch.Child(ag_format.Param("NewDuration", *inst.NewDuration)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=5]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" lbPair", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" admin", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" binArray", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta("eventAuthority", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" program", inst.AccountMetaSlice.Get(4))) + }) + }) + }) +} + +func (obj UpdateRewardDuration) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `RewardIndex` param: + err = encoder.Encode(obj.RewardIndex) + if err != nil { + return err + } + // Serialize `NewDuration` param: + err = encoder.Encode(obj.NewDuration) + if err != nil { + return err + } + return nil +} +func (obj *UpdateRewardDuration) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `RewardIndex`: + err = decoder.Decode(&obj.RewardIndex) + if err != nil { + return err + } + // Deserialize `NewDuration`: + err = decoder.Decode(&obj.NewDuration) + if err != nil { + return err + } + return nil +} + +// NewUpdateRewardDurationInstruction declares a new UpdateRewardDuration instruction with the provided parameters and accounts. +func NewUpdateRewardDurationInstruction( + // Parameters: + rewardIndex uint64, + newDuration uint64, + // Accounts: + lbPair ag_solanago.PublicKey, + admin ag_solanago.PublicKey, + binArray ag_solanago.PublicKey, + eventAuthority ag_solanago.PublicKey, + program ag_solanago.PublicKey) *UpdateRewardDuration { + return NewUpdateRewardDurationInstructionBuilder(). + SetRewardIndex(rewardIndex). + SetNewDuration(newDuration). + SetLbPairAccount(lbPair). + SetAdminAccount(admin). + SetBinArrayAccount(binArray). + SetEventAuthorityAccount(eventAuthority). + SetProgramAccount(program) +} diff --git a/programs/meteoradlmm/UpdateRewardDuration_test.go b/programs/meteoradlmm/UpdateRewardDuration_test.go new file mode 100644 index 00000000..6094c1cc --- /dev/null +++ b/programs/meteoradlmm/UpdateRewardDuration_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_UpdateRewardDuration(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("UpdateRewardDuration"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(UpdateRewardDuration) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(UpdateRewardDuration) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/UpdateRewardFunder.go b/programs/meteoradlmm/UpdateRewardFunder.go new file mode 100644 index 00000000..e9172429 --- /dev/null +++ b/programs/meteoradlmm/UpdateRewardFunder.go @@ -0,0 +1,207 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// UpdateRewardFunder is the `updateRewardFunder` instruction. +type UpdateRewardFunder struct { + RewardIndex *uint64 + NewFunder *ag_solanago.PublicKey + + // [0] = [WRITE] lbPair + // + // [1] = [SIGNER] admin + // + // [2] = [] eventAuthority + // + // [3] = [] program + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewUpdateRewardFunderInstructionBuilder creates a new `UpdateRewardFunder` instruction builder. +func NewUpdateRewardFunderInstructionBuilder() *UpdateRewardFunder { + nd := &UpdateRewardFunder{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 4), + } + return nd +} + +// SetRewardIndex sets the "rewardIndex" parameter. +func (inst *UpdateRewardFunder) SetRewardIndex(rewardIndex uint64) *UpdateRewardFunder { + inst.RewardIndex = &rewardIndex + return inst +} + +// SetNewFunder sets the "newFunder" parameter. +func (inst *UpdateRewardFunder) SetNewFunder(newFunder ag_solanago.PublicKey) *UpdateRewardFunder { + inst.NewFunder = &newFunder + return inst +} + +// SetLbPairAccount sets the "lbPair" account. +func (inst *UpdateRewardFunder) SetLbPairAccount(lbPair ag_solanago.PublicKey) *UpdateRewardFunder { + inst.AccountMetaSlice[0] = ag_solanago.Meta(lbPair).WRITE() + return inst +} + +// GetLbPairAccount gets the "lbPair" account. +func (inst *UpdateRewardFunder) GetLbPairAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetAdminAccount sets the "admin" account. +func (inst *UpdateRewardFunder) SetAdminAccount(admin ag_solanago.PublicKey) *UpdateRewardFunder { + inst.AccountMetaSlice[1] = ag_solanago.Meta(admin).SIGNER() + return inst +} + +// GetAdminAccount gets the "admin" account. +func (inst *UpdateRewardFunder) GetAdminAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetEventAuthorityAccount sets the "eventAuthority" account. +func (inst *UpdateRewardFunder) SetEventAuthorityAccount(eventAuthority ag_solanago.PublicKey) *UpdateRewardFunder { + inst.AccountMetaSlice[2] = ag_solanago.Meta(eventAuthority) + return inst +} + +// GetEventAuthorityAccount gets the "eventAuthority" account. +func (inst *UpdateRewardFunder) GetEventAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetProgramAccount sets the "program" account. +func (inst *UpdateRewardFunder) SetProgramAccount(program ag_solanago.PublicKey) *UpdateRewardFunder { + inst.AccountMetaSlice[3] = ag_solanago.Meta(program) + return inst +} + +// GetProgramAccount gets the "program" account. +func (inst *UpdateRewardFunder) GetProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +func (inst UpdateRewardFunder) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_UpdateRewardFunder, + }} +} + +// 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 UpdateRewardFunder) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *UpdateRewardFunder) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.RewardIndex == nil { + return errors.New("RewardIndex parameter is not set") + } + if inst.NewFunder == nil { + return errors.New("NewFunder parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.LbPair is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Admin is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.EventAuthority is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.Program is not set") + } + } + return nil +} + +func (inst *UpdateRewardFunder) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("UpdateRewardFunder")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=2]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param("RewardIndex", *inst.RewardIndex)) + paramsBranch.Child(ag_format.Param(" NewFunder", *inst.NewFunder)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=4]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" lbPair", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" admin", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta("eventAuthority", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" program", inst.AccountMetaSlice.Get(3))) + }) + }) + }) +} + +func (obj UpdateRewardFunder) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `RewardIndex` param: + err = encoder.Encode(obj.RewardIndex) + if err != nil { + return err + } + // Serialize `NewFunder` param: + err = encoder.Encode(obj.NewFunder) + if err != nil { + return err + } + return nil +} +func (obj *UpdateRewardFunder) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `RewardIndex`: + err = decoder.Decode(&obj.RewardIndex) + if err != nil { + return err + } + // Deserialize `NewFunder`: + err = decoder.Decode(&obj.NewFunder) + if err != nil { + return err + } + return nil +} + +// NewUpdateRewardFunderInstruction declares a new UpdateRewardFunder instruction with the provided parameters and accounts. +func NewUpdateRewardFunderInstruction( + // Parameters: + rewardIndex uint64, + newFunder ag_solanago.PublicKey, + // Accounts: + lbPair ag_solanago.PublicKey, + admin ag_solanago.PublicKey, + eventAuthority ag_solanago.PublicKey, + program ag_solanago.PublicKey) *UpdateRewardFunder { + return NewUpdateRewardFunderInstructionBuilder(). + SetRewardIndex(rewardIndex). + SetNewFunder(newFunder). + SetLbPairAccount(lbPair). + SetAdminAccount(admin). + SetEventAuthorityAccount(eventAuthority). + SetProgramAccount(program) +} diff --git a/programs/meteoradlmm/UpdateRewardFunder_test.go b/programs/meteoradlmm/UpdateRewardFunder_test.go new file mode 100644 index 00000000..11814bd1 --- /dev/null +++ b/programs/meteoradlmm/UpdateRewardFunder_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_UpdateRewardFunder(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("UpdateRewardFunder"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(UpdateRewardFunder) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(UpdateRewardFunder) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/WithdrawIneligibleReward.go b/programs/meteoradlmm/WithdrawIneligibleReward.go new file mode 100644 index 00000000..f46e5c11 --- /dev/null +++ b/programs/meteoradlmm/WithdrawIneligibleReward.go @@ -0,0 +1,279 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// WithdrawIneligibleReward is the `withdrawIneligibleReward` instruction. +type WithdrawIneligibleReward struct { + RewardIndex *uint64 + + // [0] = [WRITE] lbPair + // + // [1] = [WRITE] rewardVault + // + // [2] = [] rewardMint + // + // [3] = [WRITE] funderTokenAccount + // + // [4] = [SIGNER] funder + // + // [5] = [WRITE] binArray + // + // [6] = [] tokenProgram + // + // [7] = [] eventAuthority + // + // [8] = [] program + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewWithdrawIneligibleRewardInstructionBuilder creates a new `WithdrawIneligibleReward` instruction builder. +func NewWithdrawIneligibleRewardInstructionBuilder() *WithdrawIneligibleReward { + nd := &WithdrawIneligibleReward{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 9), + } + return nd +} + +// SetRewardIndex sets the "rewardIndex" parameter. +func (inst *WithdrawIneligibleReward) SetRewardIndex(rewardIndex uint64) *WithdrawIneligibleReward { + inst.RewardIndex = &rewardIndex + return inst +} + +// SetLbPairAccount sets the "lbPair" account. +func (inst *WithdrawIneligibleReward) SetLbPairAccount(lbPair ag_solanago.PublicKey) *WithdrawIneligibleReward { + inst.AccountMetaSlice[0] = ag_solanago.Meta(lbPair).WRITE() + return inst +} + +// GetLbPairAccount gets the "lbPair" account. +func (inst *WithdrawIneligibleReward) GetLbPairAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetRewardVaultAccount sets the "rewardVault" account. +func (inst *WithdrawIneligibleReward) SetRewardVaultAccount(rewardVault ag_solanago.PublicKey) *WithdrawIneligibleReward { + inst.AccountMetaSlice[1] = ag_solanago.Meta(rewardVault).WRITE() + return inst +} + +// GetRewardVaultAccount gets the "rewardVault" account. +func (inst *WithdrawIneligibleReward) GetRewardVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetRewardMintAccount sets the "rewardMint" account. +func (inst *WithdrawIneligibleReward) SetRewardMintAccount(rewardMint ag_solanago.PublicKey) *WithdrawIneligibleReward { + inst.AccountMetaSlice[2] = ag_solanago.Meta(rewardMint) + return inst +} + +// GetRewardMintAccount gets the "rewardMint" account. +func (inst *WithdrawIneligibleReward) GetRewardMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetFunderTokenAccountAccount sets the "funderTokenAccount" account. +func (inst *WithdrawIneligibleReward) SetFunderTokenAccountAccount(funderTokenAccount ag_solanago.PublicKey) *WithdrawIneligibleReward { + inst.AccountMetaSlice[3] = ag_solanago.Meta(funderTokenAccount).WRITE() + return inst +} + +// GetFunderTokenAccountAccount gets the "funderTokenAccount" account. +func (inst *WithdrawIneligibleReward) GetFunderTokenAccountAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetFunderAccount sets the "funder" account. +func (inst *WithdrawIneligibleReward) SetFunderAccount(funder ag_solanago.PublicKey) *WithdrawIneligibleReward { + inst.AccountMetaSlice[4] = ag_solanago.Meta(funder).SIGNER() + return inst +} + +// GetFunderAccount gets the "funder" account. +func (inst *WithdrawIneligibleReward) GetFunderAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetBinArrayAccount sets the "binArray" account. +func (inst *WithdrawIneligibleReward) SetBinArrayAccount(binArray ag_solanago.PublicKey) *WithdrawIneligibleReward { + inst.AccountMetaSlice[5] = ag_solanago.Meta(binArray).WRITE() + return inst +} + +// GetBinArrayAccount gets the "binArray" account. +func (inst *WithdrawIneligibleReward) GetBinArrayAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *WithdrawIneligibleReward) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *WithdrawIneligibleReward { + inst.AccountMetaSlice[6] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *WithdrawIneligibleReward) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetEventAuthorityAccount sets the "eventAuthority" account. +func (inst *WithdrawIneligibleReward) SetEventAuthorityAccount(eventAuthority ag_solanago.PublicKey) *WithdrawIneligibleReward { + inst.AccountMetaSlice[7] = ag_solanago.Meta(eventAuthority) + return inst +} + +// GetEventAuthorityAccount gets the "eventAuthority" account. +func (inst *WithdrawIneligibleReward) GetEventAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetProgramAccount sets the "program" account. +func (inst *WithdrawIneligibleReward) SetProgramAccount(program ag_solanago.PublicKey) *WithdrawIneligibleReward { + inst.AccountMetaSlice[8] = ag_solanago.Meta(program) + return inst +} + +// GetProgramAccount gets the "program" account. +func (inst *WithdrawIneligibleReward) GetProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +func (inst WithdrawIneligibleReward) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_WithdrawIneligibleReward, + }} +} + +// 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 WithdrawIneligibleReward) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *WithdrawIneligibleReward) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.RewardIndex == nil { + return errors.New("RewardIndex parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.LbPair is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.RewardVault is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.RewardMint is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.FunderTokenAccount is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.Funder is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.BinArray is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.EventAuthority is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.Program is not set") + } + } + return nil +} + +func (inst *WithdrawIneligibleReward) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("WithdrawIneligibleReward")). + // + 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("RewardIndex", *inst.RewardIndex)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=9]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" lbPair", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" rewardVault", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" rewardMint", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" funderToken", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" funder", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" binArray", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta("eventAuthority", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" program", inst.AccountMetaSlice.Get(8))) + }) + }) + }) +} + +func (obj WithdrawIneligibleReward) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `RewardIndex` param: + err = encoder.Encode(obj.RewardIndex) + if err != nil { + return err + } + return nil +} +func (obj *WithdrawIneligibleReward) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `RewardIndex`: + err = decoder.Decode(&obj.RewardIndex) + if err != nil { + return err + } + return nil +} + +// NewWithdrawIneligibleRewardInstruction declares a new WithdrawIneligibleReward instruction with the provided parameters and accounts. +func NewWithdrawIneligibleRewardInstruction( + // Parameters: + rewardIndex uint64, + // Accounts: + lbPair ag_solanago.PublicKey, + rewardVault ag_solanago.PublicKey, + rewardMint ag_solanago.PublicKey, + funderTokenAccount ag_solanago.PublicKey, + funder ag_solanago.PublicKey, + binArray ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + eventAuthority ag_solanago.PublicKey, + program ag_solanago.PublicKey) *WithdrawIneligibleReward { + return NewWithdrawIneligibleRewardInstructionBuilder(). + SetRewardIndex(rewardIndex). + SetLbPairAccount(lbPair). + SetRewardVaultAccount(rewardVault). + SetRewardMintAccount(rewardMint). + SetFunderTokenAccountAccount(funderTokenAccount). + SetFunderAccount(funder). + SetBinArrayAccount(binArray). + SetTokenProgramAccount(tokenProgram). + SetEventAuthorityAccount(eventAuthority). + SetProgramAccount(program) +} diff --git a/programs/meteoradlmm/WithdrawIneligibleReward_test.go b/programs/meteoradlmm/WithdrawIneligibleReward_test.go new file mode 100644 index 00000000..4f71d41b --- /dev/null +++ b/programs/meteoradlmm/WithdrawIneligibleReward_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_WithdrawIneligibleReward(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("WithdrawIneligibleReward"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(WithdrawIneligibleReward) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(WithdrawIneligibleReward) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/WithdrawProtocolFee.go b/programs/meteoradlmm/WithdrawProtocolFee.go new file mode 100644 index 00000000..1bf7de8e --- /dev/null +++ b/programs/meteoradlmm/WithdrawProtocolFee.go @@ -0,0 +1,302 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "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" +) + +// WithdrawProtocolFee is the `withdrawProtocolFee` instruction. +type WithdrawProtocolFee struct { + AmountX *uint64 + AmountY *uint64 + + // [0] = [WRITE] lbPair + // + // [1] = [WRITE] reserveX + // + // [2] = [WRITE] reserveY + // + // [3] = [] tokenXMint + // + // [4] = [] tokenYMint + // + // [5] = [WRITE] receiverTokenX + // + // [6] = [WRITE] receiverTokenY + // + // [7] = [] tokenXProgram + // + // [8] = [] tokenYProgram + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewWithdrawProtocolFeeInstructionBuilder creates a new `WithdrawProtocolFee` instruction builder. +func NewWithdrawProtocolFeeInstructionBuilder() *WithdrawProtocolFee { + nd := &WithdrawProtocolFee{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 9), + } + return nd +} + +// SetAmountX sets the "amountX" parameter. +func (inst *WithdrawProtocolFee) SetAmountX(amountX uint64) *WithdrawProtocolFee { + inst.AmountX = &amountX + return inst +} + +// SetAmountY sets the "amountY" parameter. +func (inst *WithdrawProtocolFee) SetAmountY(amountY uint64) *WithdrawProtocolFee { + inst.AmountY = &amountY + return inst +} + +// SetLbPairAccount sets the "lbPair" account. +func (inst *WithdrawProtocolFee) SetLbPairAccount(lbPair ag_solanago.PublicKey) *WithdrawProtocolFee { + inst.AccountMetaSlice[0] = ag_solanago.Meta(lbPair).WRITE() + return inst +} + +// GetLbPairAccount gets the "lbPair" account. +func (inst *WithdrawProtocolFee) GetLbPairAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetReserveXAccount sets the "reserveX" account. +func (inst *WithdrawProtocolFee) SetReserveXAccount(reserveX ag_solanago.PublicKey) *WithdrawProtocolFee { + inst.AccountMetaSlice[1] = ag_solanago.Meta(reserveX).WRITE() + return inst +} + +// GetReserveXAccount gets the "reserveX" account. +func (inst *WithdrawProtocolFee) GetReserveXAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetReserveYAccount sets the "reserveY" account. +func (inst *WithdrawProtocolFee) SetReserveYAccount(reserveY ag_solanago.PublicKey) *WithdrawProtocolFee { + inst.AccountMetaSlice[2] = ag_solanago.Meta(reserveY).WRITE() + return inst +} + +// GetReserveYAccount gets the "reserveY" account. +func (inst *WithdrawProtocolFee) GetReserveYAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetTokenXMintAccount sets the "tokenXMint" account. +func (inst *WithdrawProtocolFee) SetTokenXMintAccount(tokenXMint ag_solanago.PublicKey) *WithdrawProtocolFee { + inst.AccountMetaSlice[3] = ag_solanago.Meta(tokenXMint) + return inst +} + +// GetTokenXMintAccount gets the "tokenXMint" account. +func (inst *WithdrawProtocolFee) GetTokenXMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetTokenYMintAccount sets the "tokenYMint" account. +func (inst *WithdrawProtocolFee) SetTokenYMintAccount(tokenYMint ag_solanago.PublicKey) *WithdrawProtocolFee { + inst.AccountMetaSlice[4] = ag_solanago.Meta(tokenYMint) + return inst +} + +// GetTokenYMintAccount gets the "tokenYMint" account. +func (inst *WithdrawProtocolFee) GetTokenYMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetReceiverTokenXAccount sets the "receiverTokenX" account. +func (inst *WithdrawProtocolFee) SetReceiverTokenXAccount(receiverTokenX ag_solanago.PublicKey) *WithdrawProtocolFee { + inst.AccountMetaSlice[5] = ag_solanago.Meta(receiverTokenX).WRITE() + return inst +} + +// GetReceiverTokenXAccount gets the "receiverTokenX" account. +func (inst *WithdrawProtocolFee) GetReceiverTokenXAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetReceiverTokenYAccount sets the "receiverTokenY" account. +func (inst *WithdrawProtocolFee) SetReceiverTokenYAccount(receiverTokenY ag_solanago.PublicKey) *WithdrawProtocolFee { + inst.AccountMetaSlice[6] = ag_solanago.Meta(receiverTokenY).WRITE() + return inst +} + +// GetReceiverTokenYAccount gets the "receiverTokenY" account. +func (inst *WithdrawProtocolFee) GetReceiverTokenYAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetTokenXProgramAccount sets the "tokenXProgram" account. +func (inst *WithdrawProtocolFee) SetTokenXProgramAccount(tokenXProgram ag_solanago.PublicKey) *WithdrawProtocolFee { + inst.AccountMetaSlice[7] = ag_solanago.Meta(tokenXProgram) + return inst +} + +// GetTokenXProgramAccount gets the "tokenXProgram" account. +func (inst *WithdrawProtocolFee) GetTokenXProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetTokenYProgramAccount sets the "tokenYProgram" account. +func (inst *WithdrawProtocolFee) SetTokenYProgramAccount(tokenYProgram ag_solanago.PublicKey) *WithdrawProtocolFee { + inst.AccountMetaSlice[8] = ag_solanago.Meta(tokenYProgram) + return inst +} + +// GetTokenYProgramAccount gets the "tokenYProgram" account. +func (inst *WithdrawProtocolFee) GetTokenYProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +func (inst WithdrawProtocolFee) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_WithdrawProtocolFee, + }} +} + +// 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 WithdrawProtocolFee) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *WithdrawProtocolFee) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.AmountX == nil { + return errors.New("AmountX parameter is not set") + } + if inst.AmountY == nil { + return errors.New("AmountY parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.LbPair is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.ReserveX is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.ReserveY is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.TokenXMint is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.TokenYMint is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.ReceiverTokenX is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.ReceiverTokenY is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.TokenXProgram is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.TokenYProgram is not set") + } + } + return nil +} + +func (inst *WithdrawProtocolFee) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("WithdrawProtocolFee")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=2]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param("AmountX", *inst.AmountX)) + paramsBranch.Child(ag_format.Param("AmountY", *inst.AmountY)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=9]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" lbPair", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" reserveX", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" reserveY", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" tokenXMint", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" tokenYMint", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta("receiverTokenX", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta("receiverTokenY", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" tokenXProgram", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" tokenYProgram", inst.AccountMetaSlice.Get(8))) + }) + }) + }) +} + +func (obj WithdrawProtocolFee) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `AmountX` param: + err = encoder.Encode(obj.AmountX) + if err != nil { + return err + } + // Serialize `AmountY` param: + err = encoder.Encode(obj.AmountY) + if err != nil { + return err + } + return nil +} +func (obj *WithdrawProtocolFee) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `AmountX`: + err = decoder.Decode(&obj.AmountX) + if err != nil { + return err + } + // Deserialize `AmountY`: + err = decoder.Decode(&obj.AmountY) + if err != nil { + return err + } + return nil +} + +// NewWithdrawProtocolFeeInstruction declares a new WithdrawProtocolFee instruction with the provided parameters and accounts. +func NewWithdrawProtocolFeeInstruction( + // Parameters: + amountX uint64, + amountY uint64, + // Accounts: + lbPair ag_solanago.PublicKey, + reserveX ag_solanago.PublicKey, + reserveY ag_solanago.PublicKey, + tokenXMint ag_solanago.PublicKey, + tokenYMint ag_solanago.PublicKey, + receiverTokenX ag_solanago.PublicKey, + receiverTokenY ag_solanago.PublicKey, + tokenXProgram ag_solanago.PublicKey, + tokenYProgram ag_solanago.PublicKey) *WithdrawProtocolFee { + return NewWithdrawProtocolFeeInstructionBuilder(). + SetAmountX(amountX). + SetAmountY(amountY). + SetLbPairAccount(lbPair). + SetReserveXAccount(reserveX). + SetReserveYAccount(reserveY). + SetTokenXMintAccount(tokenXMint). + SetTokenYMintAccount(tokenYMint). + SetReceiverTokenXAccount(receiverTokenX). + SetReceiverTokenYAccount(receiverTokenY). + SetTokenXProgramAccount(tokenXProgram). + SetTokenYProgramAccount(tokenYProgram) +} diff --git a/programs/meteoradlmm/WithdrawProtocolFee_test.go b/programs/meteoradlmm/WithdrawProtocolFee_test.go new file mode 100644 index 00000000..88e9162e --- /dev/null +++ b/programs/meteoradlmm/WithdrawProtocolFee_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_WithdrawProtocolFee(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("WithdrawProtocolFee"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(WithdrawProtocolFee) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(WithdrawProtocolFee) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteoradlmm/accounts.go b/programs/meteoradlmm/accounts.go new file mode 100644 index 00000000..ec40490c --- /dev/null +++ b/programs/meteoradlmm/accounts.go @@ -0,0 +1,1246 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "fmt" + ag_binary "github.com/gagliardetto/binary" + ag_solanago "github.com/gagliardetto/solana-go" +) + +type BinArrayBitmapExtension struct { + LbPair ag_solanago.PublicKey + + // Packed initialized bin array state for start_bin_index is positive + PositiveBinArrayBitmap [12][8]uint64 + + // Packed initialized bin array state for start_bin_index is negative + NegativeBinArrayBitmap [12][8]uint64 +} + +var BinArrayBitmapExtensionDiscriminator = [8]byte{80, 111, 124, 113, 55, 237, 18, 5} + +func (obj BinArrayBitmapExtension) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Write account discriminator: + err = encoder.WriteBytes(BinArrayBitmapExtensionDiscriminator[:], false) + if err != nil { + return err + } + // Serialize `LbPair` param: + err = encoder.Encode(obj.LbPair) + if err != nil { + return err + } + // Serialize `PositiveBinArrayBitmap` param: + err = encoder.Encode(obj.PositiveBinArrayBitmap) + if err != nil { + return err + } + // Serialize `NegativeBinArrayBitmap` param: + err = encoder.Encode(obj.NegativeBinArrayBitmap) + if err != nil { + return err + } + return nil +} + +func (obj *BinArrayBitmapExtension) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Read and check account discriminator: + { + discriminator, err := decoder.ReadTypeID() + if err != nil { + return err + } + if !discriminator.Equal(BinArrayBitmapExtensionDiscriminator[:]) { + return fmt.Errorf( + "wrong discriminator: wanted %s, got %s", + "[80 111 124 113 55 237 18 5]", + fmt.Sprint(discriminator[:])) + } + } + // Deserialize `LbPair`: + err = decoder.Decode(&obj.LbPair) + if err != nil { + return err + } + // Deserialize `PositiveBinArrayBitmap`: + err = decoder.Decode(&obj.PositiveBinArrayBitmap) + if err != nil { + return err + } + // Deserialize `NegativeBinArrayBitmap`: + err = decoder.Decode(&obj.NegativeBinArrayBitmap) + if err != nil { + return err + } + return nil +} + +type BinArray struct { + Index int64 + + // Version of binArray + Version uint8 + Padding [7]uint8 + LbPair ag_solanago.PublicKey + Bins [70]Bin +} + +var BinArrayDiscriminator = [8]byte{92, 142, 92, 220, 5, 148, 70, 181} + +func (obj BinArray) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Write account discriminator: + err = encoder.WriteBytes(BinArrayDiscriminator[:], false) + if err != nil { + return err + } + // Serialize `Index` param: + err = encoder.Encode(obj.Index) + if err != nil { + return err + } + // Serialize `Version` param: + err = encoder.Encode(obj.Version) + if err != nil { + return err + } + // Serialize `Padding` param: + err = encoder.Encode(obj.Padding) + if err != nil { + return err + } + // Serialize `LbPair` param: + err = encoder.Encode(obj.LbPair) + if err != nil { + return err + } + // Serialize `Bins` param: + err = encoder.Encode(obj.Bins) + if err != nil { + return err + } + return nil +} + +func (obj *BinArray) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Read and check account discriminator: + { + discriminator, err := decoder.ReadTypeID() + if err != nil { + return err + } + if !discriminator.Equal(BinArrayDiscriminator[:]) { + return fmt.Errorf( + "wrong discriminator: wanted %s, got %s", + "[92 142 92 220 5 148 70 181]", + fmt.Sprint(discriminator[:])) + } + } + // Deserialize `Index`: + err = decoder.Decode(&obj.Index) + if err != nil { + return err + } + // Deserialize `Version`: + err = decoder.Decode(&obj.Version) + if err != nil { + return err + } + // Deserialize `Padding`: + err = decoder.Decode(&obj.Padding) + if err != nil { + return err + } + // Deserialize `LbPair`: + err = decoder.Decode(&obj.LbPair) + if err != nil { + return err + } + // Deserialize `Bins`: + err = decoder.Decode(&obj.Bins) + if err != nil { + return err + } + return nil +} + +type LbPair struct { + Parameters StaticParameters + VParameters VariableParameters + BumpSeed [1]uint8 + + // Bin step signer seed + BinStepSeed [2]uint8 + + // Type of the pair + PairType uint8 + + // Active bin id + ActiveId int32 + + // Bin step. Represent the price increment / decrement. + BinStep uint16 + + // Status of the pair. Check PairStatus enum. + Status uint8 + + // Require base factor seed + RequireBaseFactorSeed uint8 + + // Base factor seed + BaseFactorSeed [2]uint8 + + // Activation type + ActivationType uint8 + + // padding 0 + Padding0 uint8 + + // Token X mint + TokenXMint ag_solanago.PublicKey + + // Token Y mint + TokenYMint ag_solanago.PublicKey + + // LB token X vault + ReserveX ag_solanago.PublicKey + + // LB token Y vault + ReserveY ag_solanago.PublicKey + + // Uncollected protocol fee + ProtocolFee ProtocolFee + + // _padding_1, previous Fee owner, BE CAREFUL FOR TOMBSTONE WHEN REUSE !! + Padding1 [32]uint8 + + // Farming reward information + RewardInfos [2]RewardInfo + + // Oracle pubkey + Oracle ag_solanago.PublicKey + + // Packed initialized bin array state + BinArrayBitmap [16]uint64 + + // Last time the pool fee parameter was updated + LastUpdatedAt int64 + + // _padding_2, previous whitelisted_wallet, BE CAREFUL FOR TOMBSTONE WHEN REUSE !! + Padding2 [32]uint8 + + // Address allowed to swap when the current point is greater than or equal to the pre-activation point. The pre-activation point is calculated as `activation_point - pre_activation_duration`. + PreActivationSwapAddress ag_solanago.PublicKey + + // Base keypair. Only required for permission pair + BaseKey ag_solanago.PublicKey + + // Time point to enable the pair. Only applicable for permission pair. + ActivationPoint uint64 + + // Duration before activation activation_point. Used to calculate pre-activation time point for pre_activation_swap_address + PreActivationDuration uint64 + + // _padding 3 is reclaimed free space from swap_cap_deactivate_point and swap_cap_amount before, BE CAREFUL FOR TOMBSTONE WHEN REUSE !! + Padding3 [8]uint8 + + // _padding_4, previous lock_duration, BE CAREFUL FOR TOMBSTONE WHEN REUSE !! + Padding4 uint64 + + // Pool creator + Creator ag_solanago.PublicKey + + // Reserved space for future use + Reserved [24]uint8 +} + +var LbPairDiscriminator = [8]byte{33, 11, 49, 98, 181, 101, 177, 13} + +func (obj LbPair) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Write account discriminator: + err = encoder.WriteBytes(LbPairDiscriminator[:], false) + if err != nil { + return err + } + // Serialize `Parameters` param: + err = encoder.Encode(obj.Parameters) + if err != nil { + return err + } + // Serialize `VParameters` param: + err = encoder.Encode(obj.VParameters) + if err != nil { + return err + } + // Serialize `BumpSeed` param: + err = encoder.Encode(obj.BumpSeed) + if err != nil { + return err + } + // Serialize `BinStepSeed` param: + err = encoder.Encode(obj.BinStepSeed) + if err != nil { + return err + } + // Serialize `PairType` param: + err = encoder.Encode(obj.PairType) + if err != nil { + return err + } + // Serialize `ActiveId` param: + err = encoder.Encode(obj.ActiveId) + if err != nil { + return err + } + // Serialize `BinStep` param: + err = encoder.Encode(obj.BinStep) + if err != nil { + return err + } + // Serialize `Status` param: + err = encoder.Encode(obj.Status) + if err != nil { + return err + } + // Serialize `RequireBaseFactorSeed` param: + err = encoder.Encode(obj.RequireBaseFactorSeed) + if err != nil { + return err + } + // Serialize `BaseFactorSeed` param: + err = encoder.Encode(obj.BaseFactorSeed) + if err != nil { + return err + } + // Serialize `ActivationType` param: + err = encoder.Encode(obj.ActivationType) + if err != nil { + return err + } + // Serialize `Padding0` param: + err = encoder.Encode(obj.Padding0) + if err != nil { + return err + } + // Serialize `TokenXMint` param: + err = encoder.Encode(obj.TokenXMint) + if err != nil { + return err + } + // Serialize `TokenYMint` param: + err = encoder.Encode(obj.TokenYMint) + if err != nil { + return err + } + // Serialize `ReserveX` param: + err = encoder.Encode(obj.ReserveX) + if err != nil { + return err + } + // Serialize `ReserveY` param: + err = encoder.Encode(obj.ReserveY) + if err != nil { + return err + } + // Serialize `ProtocolFee` param: + err = encoder.Encode(obj.ProtocolFee) + if err != nil { + return err + } + // Serialize `Padding1` param: + err = encoder.Encode(obj.Padding1) + if err != nil { + return err + } + // Serialize `RewardInfos` param: + err = encoder.Encode(obj.RewardInfos) + if err != nil { + return err + } + // Serialize `Oracle` param: + err = encoder.Encode(obj.Oracle) + if err != nil { + return err + } + // Serialize `BinArrayBitmap` param: + err = encoder.Encode(obj.BinArrayBitmap) + if err != nil { + return err + } + // Serialize `LastUpdatedAt` param: + err = encoder.Encode(obj.LastUpdatedAt) + if err != nil { + return err + } + // Serialize `Padding2` param: + err = encoder.Encode(obj.Padding2) + if err != nil { + return err + } + // Serialize `PreActivationSwapAddress` param: + err = encoder.Encode(obj.PreActivationSwapAddress) + if err != nil { + return err + } + // Serialize `BaseKey` param: + err = encoder.Encode(obj.BaseKey) + if err != nil { + return err + } + // Serialize `ActivationPoint` param: + err = encoder.Encode(obj.ActivationPoint) + if err != nil { + return err + } + // Serialize `PreActivationDuration` param: + err = encoder.Encode(obj.PreActivationDuration) + if err != nil { + return err + } + // Serialize `Padding3` param: + err = encoder.Encode(obj.Padding3) + if err != nil { + return err + } + // Serialize `Padding4` param: + err = encoder.Encode(obj.Padding4) + if err != nil { + return err + } + // Serialize `Creator` param: + err = encoder.Encode(obj.Creator) + if err != nil { + return err + } + // Serialize `Reserved` param: + err = encoder.Encode(obj.Reserved) + if err != nil { + return err + } + return nil +} + +func (obj *LbPair) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Read and check account discriminator: + { + discriminator, err := decoder.ReadTypeID() + if err != nil { + return err + } + if !discriminator.Equal(LbPairDiscriminator[:]) { + return fmt.Errorf( + "wrong discriminator: wanted %s, got %s", + "[33 11 49 98 181 101 177 13]", + fmt.Sprint(discriminator[:])) + } + } + // Deserialize `Parameters`: + err = decoder.Decode(&obj.Parameters) + if err != nil { + return err + } + // Deserialize `VParameters`: + err = decoder.Decode(&obj.VParameters) + if err != nil { + return err + } + // Deserialize `BumpSeed`: + err = decoder.Decode(&obj.BumpSeed) + if err != nil { + return err + } + // Deserialize `BinStepSeed`: + err = decoder.Decode(&obj.BinStepSeed) + if err != nil { + return err + } + // Deserialize `PairType`: + err = decoder.Decode(&obj.PairType) + if err != nil { + return err + } + // Deserialize `ActiveId`: + err = decoder.Decode(&obj.ActiveId) + if err != nil { + return err + } + // Deserialize `BinStep`: + err = decoder.Decode(&obj.BinStep) + if err != nil { + return err + } + // Deserialize `Status`: + err = decoder.Decode(&obj.Status) + if err != nil { + return err + } + // Deserialize `RequireBaseFactorSeed`: + err = decoder.Decode(&obj.RequireBaseFactorSeed) + if err != nil { + return err + } + // Deserialize `BaseFactorSeed`: + err = decoder.Decode(&obj.BaseFactorSeed) + if err != nil { + return err + } + // Deserialize `ActivationType`: + err = decoder.Decode(&obj.ActivationType) + if err != nil { + return err + } + // Deserialize `Padding0`: + err = decoder.Decode(&obj.Padding0) + if err != nil { + return err + } + // Deserialize `TokenXMint`: + err = decoder.Decode(&obj.TokenXMint) + if err != nil { + return err + } + // Deserialize `TokenYMint`: + err = decoder.Decode(&obj.TokenYMint) + if err != nil { + return err + } + // Deserialize `ReserveX`: + err = decoder.Decode(&obj.ReserveX) + if err != nil { + return err + } + // Deserialize `ReserveY`: + err = decoder.Decode(&obj.ReserveY) + if err != nil { + return err + } + // Deserialize `ProtocolFee`: + err = decoder.Decode(&obj.ProtocolFee) + if err != nil { + return err + } + // Deserialize `Padding1`: + err = decoder.Decode(&obj.Padding1) + if err != nil { + return err + } + // Deserialize `RewardInfos`: + err = decoder.Decode(&obj.RewardInfos) + if err != nil { + return err + } + // Deserialize `Oracle`: + err = decoder.Decode(&obj.Oracle) + if err != nil { + return err + } + // Deserialize `BinArrayBitmap`: + err = decoder.Decode(&obj.BinArrayBitmap) + if err != nil { + return err + } + // Deserialize `LastUpdatedAt`: + err = decoder.Decode(&obj.LastUpdatedAt) + if err != nil { + return err + } + // Deserialize `Padding2`: + err = decoder.Decode(&obj.Padding2) + if err != nil { + return err + } + // Deserialize `PreActivationSwapAddress`: + err = decoder.Decode(&obj.PreActivationSwapAddress) + if err != nil { + return err + } + // Deserialize `BaseKey`: + err = decoder.Decode(&obj.BaseKey) + if err != nil { + return err + } + // Deserialize `ActivationPoint`: + err = decoder.Decode(&obj.ActivationPoint) + if err != nil { + return err + } + // Deserialize `PreActivationDuration`: + err = decoder.Decode(&obj.PreActivationDuration) + if err != nil { + return err + } + // Deserialize `Padding3`: + err = decoder.Decode(&obj.Padding3) + if err != nil { + return err + } + // Deserialize `Padding4`: + err = decoder.Decode(&obj.Padding4) + if err != nil { + return err + } + // Deserialize `Creator`: + err = decoder.Decode(&obj.Creator) + if err != nil { + return err + } + // Deserialize `Reserved`: + err = decoder.Decode(&obj.Reserved) + if err != nil { + return err + } + return nil +} + +type Oracle struct { + // Index of latest observation + Idx uint64 + + // Size of active sample. Active sample is initialized observation. + ActiveSize uint64 + + // Number of observations + Length uint64 +} + +var OracleDiscriminator = [8]byte{139, 194, 131, 179, 140, 179, 229, 244} + +func (obj Oracle) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Write account discriminator: + err = encoder.WriteBytes(OracleDiscriminator[:], false) + if err != nil { + return err + } + // Serialize `Idx` param: + err = encoder.Encode(obj.Idx) + if err != nil { + return err + } + // Serialize `ActiveSize` param: + err = encoder.Encode(obj.ActiveSize) + if err != nil { + return err + } + // Serialize `Length` param: + err = encoder.Encode(obj.Length) + if err != nil { + return err + } + return nil +} + +func (obj *Oracle) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Read and check account discriminator: + { + discriminator, err := decoder.ReadTypeID() + if err != nil { + return err + } + if !discriminator.Equal(OracleDiscriminator[:]) { + return fmt.Errorf( + "wrong discriminator: wanted %s, got %s", + "[139 194 131 179 140 179 229 244]", + fmt.Sprint(discriminator[:])) + } + } + // Deserialize `Idx`: + err = decoder.Decode(&obj.Idx) + if err != nil { + return err + } + // Deserialize `ActiveSize`: + err = decoder.Decode(&obj.ActiveSize) + if err != nil { + return err + } + // Deserialize `Length`: + err = decoder.Decode(&obj.Length) + if err != nil { + return err + } + return nil +} + +type Position struct { + // The LB pair of this position + LbPair ag_solanago.PublicKey + + // Owner of the position. Client rely on this to to fetch their positions. + Owner ag_solanago.PublicKey + + // Liquidity shares of this position in bins (lower_bin_id <-> upper_bin_id). This is the same as LP concept. + LiquidityShares [70]uint64 + + // Farming reward information + RewardInfos [70]UserRewardInfo + + // Swap fee to claim information + FeeInfos [70]FeeInfo + + // Lower bin ID + LowerBinId int32 + + // Upper bin ID + UpperBinId int32 + + // Last updated timestamp + LastUpdatedAt int64 + + // Total claimed token fee X + TotalClaimedFeeXAmount uint64 + + // Total claimed token fee Y + TotalClaimedFeeYAmount uint64 + + // Total claimed rewards + TotalClaimedRewards [2]uint64 + + // Reserved space for future use + Reserved [160]uint8 +} + +var PositionDiscriminator = [8]byte{170, 188, 143, 228, 122, 64, 247, 208} + +func (obj Position) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Write account discriminator: + err = encoder.WriteBytes(PositionDiscriminator[:], false) + if err != nil { + return err + } + // Serialize `LbPair` param: + err = encoder.Encode(obj.LbPair) + if err != nil { + return err + } + // Serialize `Owner` param: + err = encoder.Encode(obj.Owner) + if err != nil { + return err + } + // Serialize `LiquidityShares` param: + err = encoder.Encode(obj.LiquidityShares) + if err != nil { + return err + } + // Serialize `RewardInfos` param: + err = encoder.Encode(obj.RewardInfos) + if err != nil { + return err + } + // Serialize `FeeInfos` param: + err = encoder.Encode(obj.FeeInfos) + if err != nil { + return err + } + // Serialize `LowerBinId` param: + err = encoder.Encode(obj.LowerBinId) + if err != nil { + return err + } + // Serialize `UpperBinId` param: + err = encoder.Encode(obj.UpperBinId) + if err != nil { + return err + } + // Serialize `LastUpdatedAt` param: + err = encoder.Encode(obj.LastUpdatedAt) + if err != nil { + return err + } + // Serialize `TotalClaimedFeeXAmount` param: + err = encoder.Encode(obj.TotalClaimedFeeXAmount) + if err != nil { + return err + } + // Serialize `TotalClaimedFeeYAmount` param: + err = encoder.Encode(obj.TotalClaimedFeeYAmount) + if err != nil { + return err + } + // Serialize `TotalClaimedRewards` param: + err = encoder.Encode(obj.TotalClaimedRewards) + if err != nil { + return err + } + // Serialize `Reserved` param: + err = encoder.Encode(obj.Reserved) + if err != nil { + return err + } + return nil +} + +func (obj *Position) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Read and check account discriminator: + { + discriminator, err := decoder.ReadTypeID() + if err != nil { + return err + } + if !discriminator.Equal(PositionDiscriminator[:]) { + return fmt.Errorf( + "wrong discriminator: wanted %s, got %s", + "[170 188 143 228 122 64 247 208]", + fmt.Sprint(discriminator[:])) + } + } + // Deserialize `LbPair`: + err = decoder.Decode(&obj.LbPair) + if err != nil { + return err + } + // Deserialize `Owner`: + err = decoder.Decode(&obj.Owner) + if err != nil { + return err + } + // Deserialize `LiquidityShares`: + err = decoder.Decode(&obj.LiquidityShares) + if err != nil { + return err + } + // Deserialize `RewardInfos`: + err = decoder.Decode(&obj.RewardInfos) + if err != nil { + return err + } + // Deserialize `FeeInfos`: + err = decoder.Decode(&obj.FeeInfos) + if err != nil { + return err + } + // Deserialize `LowerBinId`: + err = decoder.Decode(&obj.LowerBinId) + if err != nil { + return err + } + // Deserialize `UpperBinId`: + err = decoder.Decode(&obj.UpperBinId) + if err != nil { + return err + } + // Deserialize `LastUpdatedAt`: + err = decoder.Decode(&obj.LastUpdatedAt) + if err != nil { + return err + } + // Deserialize `TotalClaimedFeeXAmount`: + err = decoder.Decode(&obj.TotalClaimedFeeXAmount) + if err != nil { + return err + } + // Deserialize `TotalClaimedFeeYAmount`: + err = decoder.Decode(&obj.TotalClaimedFeeYAmount) + if err != nil { + return err + } + // Deserialize `TotalClaimedRewards`: + err = decoder.Decode(&obj.TotalClaimedRewards) + if err != nil { + return err + } + // Deserialize `Reserved`: + err = decoder.Decode(&obj.Reserved) + if err != nil { + return err + } + return nil +} + +type PositionV2 struct { + // The LB pair of this position + LbPair ag_solanago.PublicKey + + // Owner of the position. Client rely on this to to fetch their positions. + Owner ag_solanago.PublicKey + + // Liquidity shares of this position in bins (lower_bin_id <-> upper_bin_id). This is the same as LP concept. + LiquidityShares [70]ag_binary.Uint128 + + // Farming reward information + RewardInfos [70]UserRewardInfo + + // Swap fee to claim information + FeeInfos [70]FeeInfo + + // Lower bin ID + LowerBinId int32 + + // Upper bin ID + UpperBinId int32 + + // Last updated timestamp + LastUpdatedAt int64 + + // Total claimed token fee X + TotalClaimedFeeXAmount uint64 + + // Total claimed token fee Y + TotalClaimedFeeYAmount uint64 + + // Total claimed rewards + TotalClaimedRewards [2]uint64 + + // Operator of position + Operator ag_solanago.PublicKey + + // Time point which the locked liquidity can be withdraw + LockReleasePoint uint64 + + // _padding_0, previous subjected_to_bootstrap_liquidity_locking, BE CAREFUL FOR TOMBSTONE WHEN REUSE !! + Padding0 uint8 + + // Address is able to claim fee in this position, only valid for bootstrap_liquidity_position + FeeOwner ag_solanago.PublicKey + + // Reserved space for future use + Reserved [87]uint8 +} + +var PositionV2Discriminator = [8]byte{117, 176, 212, 199, 245, 180, 133, 182} + +func (obj PositionV2) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Write account discriminator: + err = encoder.WriteBytes(PositionV2Discriminator[:], false) + if err != nil { + return err + } + // Serialize `LbPair` param: + err = encoder.Encode(obj.LbPair) + if err != nil { + return err + } + // Serialize `Owner` param: + err = encoder.Encode(obj.Owner) + if err != nil { + return err + } + // Serialize `LiquidityShares` param: + err = encoder.Encode(obj.LiquidityShares) + if err != nil { + return err + } + // Serialize `RewardInfos` param: + err = encoder.Encode(obj.RewardInfos) + if err != nil { + return err + } + // Serialize `FeeInfos` param: + err = encoder.Encode(obj.FeeInfos) + if err != nil { + return err + } + // Serialize `LowerBinId` param: + err = encoder.Encode(obj.LowerBinId) + if err != nil { + return err + } + // Serialize `UpperBinId` param: + err = encoder.Encode(obj.UpperBinId) + if err != nil { + return err + } + // Serialize `LastUpdatedAt` param: + err = encoder.Encode(obj.LastUpdatedAt) + if err != nil { + return err + } + // Serialize `TotalClaimedFeeXAmount` param: + err = encoder.Encode(obj.TotalClaimedFeeXAmount) + if err != nil { + return err + } + // Serialize `TotalClaimedFeeYAmount` param: + err = encoder.Encode(obj.TotalClaimedFeeYAmount) + if err != nil { + return err + } + // Serialize `TotalClaimedRewards` param: + err = encoder.Encode(obj.TotalClaimedRewards) + if err != nil { + return err + } + // Serialize `Operator` param: + err = encoder.Encode(obj.Operator) + if err != nil { + return err + } + // Serialize `LockReleasePoint` param: + err = encoder.Encode(obj.LockReleasePoint) + if err != nil { + return err + } + // Serialize `Padding0` param: + err = encoder.Encode(obj.Padding0) + if err != nil { + return err + } + // Serialize `FeeOwner` param: + err = encoder.Encode(obj.FeeOwner) + if err != nil { + return err + } + // Serialize `Reserved` param: + err = encoder.Encode(obj.Reserved) + if err != nil { + return err + } + return nil +} + +func (obj *PositionV2) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Read and check account discriminator: + { + discriminator, err := decoder.ReadTypeID() + if err != nil { + return err + } + if !discriminator.Equal(PositionV2Discriminator[:]) { + return fmt.Errorf( + "wrong discriminator: wanted %s, got %s", + "[117 176 212 199 245 180 133 182]", + fmt.Sprint(discriminator[:])) + } + } + // Deserialize `LbPair`: + err = decoder.Decode(&obj.LbPair) + if err != nil { + return err + } + // Deserialize `Owner`: + err = decoder.Decode(&obj.Owner) + if err != nil { + return err + } + // Deserialize `LiquidityShares`: + err = decoder.Decode(&obj.LiquidityShares) + if err != nil { + return err + } + // Deserialize `RewardInfos`: + err = decoder.Decode(&obj.RewardInfos) + if err != nil { + return err + } + // Deserialize `FeeInfos`: + err = decoder.Decode(&obj.FeeInfos) + if err != nil { + return err + } + // Deserialize `LowerBinId`: + err = decoder.Decode(&obj.LowerBinId) + if err != nil { + return err + } + // Deserialize `UpperBinId`: + err = decoder.Decode(&obj.UpperBinId) + if err != nil { + return err + } + // Deserialize `LastUpdatedAt`: + err = decoder.Decode(&obj.LastUpdatedAt) + if err != nil { + return err + } + // Deserialize `TotalClaimedFeeXAmount`: + err = decoder.Decode(&obj.TotalClaimedFeeXAmount) + if err != nil { + return err + } + // Deserialize `TotalClaimedFeeYAmount`: + err = decoder.Decode(&obj.TotalClaimedFeeYAmount) + if err != nil { + return err + } + // Deserialize `TotalClaimedRewards`: + err = decoder.Decode(&obj.TotalClaimedRewards) + if err != nil { + return err + } + // Deserialize `Operator`: + err = decoder.Decode(&obj.Operator) + if err != nil { + return err + } + // Deserialize `LockReleasePoint`: + err = decoder.Decode(&obj.LockReleasePoint) + if err != nil { + return err + } + // Deserialize `Padding0`: + err = decoder.Decode(&obj.Padding0) + if err != nil { + return err + } + // Deserialize `FeeOwner`: + err = decoder.Decode(&obj.FeeOwner) + if err != nil { + return err + } + // Deserialize `Reserved`: + err = decoder.Decode(&obj.Reserved) + if err != nil { + return err + } + return nil +} + +type PresetParameter struct { + // Bin step. Represent the price increment / decrement. + BinStep uint16 + + // Used for base fee calculation. base_fee_rate = base_factor * bin_step + BaseFactor uint16 + + // Filter period determine high frequency trading time window. + FilterPeriod uint16 + + // Decay period determine when the volatile fee start decay / decrease. + DecayPeriod uint16 + + // Reduction factor controls the volatile fee rate decrement rate. + ReductionFactor uint16 + + // Used to scale the variable fee component depending on the dynamic of the market + VariableFeeControl uint32 + + // Maximum number of bin crossed can be accumulated. Used to cap volatile fee rate. + MaxVolatilityAccumulator uint32 + + // Min bin id supported by the pool based on the configured bin step. + MinBinId int32 + + // Max bin id supported by the pool based on the configured bin step. + MaxBinId int32 + + // Portion of swap fees retained by the protocol by controlling protocol_share parameter. protocol_swap_fee = protocol_share * total_swap_fee + ProtocolShare uint16 +} + +var PresetParameterDiscriminator = [8]byte{242, 62, 244, 34, 181, 112, 58, 170} + +func (obj PresetParameter) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Write account discriminator: + err = encoder.WriteBytes(PresetParameterDiscriminator[:], false) + if err != nil { + return err + } + // Serialize `BinStep` param: + err = encoder.Encode(obj.BinStep) + if err != nil { + return err + } + // Serialize `BaseFactor` param: + err = encoder.Encode(obj.BaseFactor) + if err != nil { + return err + } + // Serialize `FilterPeriod` param: + err = encoder.Encode(obj.FilterPeriod) + if err != nil { + return err + } + // Serialize `DecayPeriod` param: + err = encoder.Encode(obj.DecayPeriod) + if err != nil { + return err + } + // Serialize `ReductionFactor` param: + err = encoder.Encode(obj.ReductionFactor) + if err != nil { + return err + } + // Serialize `VariableFeeControl` param: + err = encoder.Encode(obj.VariableFeeControl) + if err != nil { + return err + } + // Serialize `MaxVolatilityAccumulator` param: + err = encoder.Encode(obj.MaxVolatilityAccumulator) + if err != nil { + return err + } + // Serialize `MinBinId` param: + err = encoder.Encode(obj.MinBinId) + if err != nil { + return err + } + // Serialize `MaxBinId` param: + err = encoder.Encode(obj.MaxBinId) + if err != nil { + return err + } + // Serialize `ProtocolShare` param: + err = encoder.Encode(obj.ProtocolShare) + if err != nil { + return err + } + return nil +} + +func (obj *PresetParameter) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Read and check account discriminator: + { + discriminator, err := decoder.ReadTypeID() + if err != nil { + return err + } + if !discriminator.Equal(PresetParameterDiscriminator[:]) { + return fmt.Errorf( + "wrong discriminator: wanted %s, got %s", + "[242 62 244 34 181 112 58 170]", + fmt.Sprint(discriminator[:])) + } + } + // Deserialize `BinStep`: + err = decoder.Decode(&obj.BinStep) + if err != nil { + return err + } + // Deserialize `BaseFactor`: + err = decoder.Decode(&obj.BaseFactor) + if err != nil { + return err + } + // Deserialize `FilterPeriod`: + err = decoder.Decode(&obj.FilterPeriod) + if err != nil { + return err + } + // Deserialize `DecayPeriod`: + err = decoder.Decode(&obj.DecayPeriod) + if err != nil { + return err + } + // Deserialize `ReductionFactor`: + err = decoder.Decode(&obj.ReductionFactor) + if err != nil { + return err + } + // Deserialize `VariableFeeControl`: + err = decoder.Decode(&obj.VariableFeeControl) + if err != nil { + return err + } + // Deserialize `MaxVolatilityAccumulator`: + err = decoder.Decode(&obj.MaxVolatilityAccumulator) + if err != nil { + return err + } + // Deserialize `MinBinId`: + err = decoder.Decode(&obj.MinBinId) + if err != nil { + return err + } + // Deserialize `MaxBinId`: + err = decoder.Decode(&obj.MaxBinId) + if err != nil { + return err + } + // Deserialize `ProtocolShare`: + err = decoder.Decode(&obj.ProtocolShare) + if err != nil { + return err + } + return nil +} diff --git a/programs/meteoradlmm/instructions.go b/programs/meteoradlmm/instructions.go new file mode 100644 index 00000000..17d8022c --- /dev/null +++ b/programs/meteoradlmm/instructions.go @@ -0,0 +1,404 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +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 = "LbClmm" + +func init() { + if !ProgramID.IsZero() { + ag_solanago.RegisterInstructionDecoder(ProgramID, registryDecodeInstruction) + } +} + +var ( + Instruction_InitializeLbPair = ag_binary.TypeID([8]byte{45, 154, 237, 210, 221, 15, 166, 92}) + + Instruction_InitializePermissionLbPair = ag_binary.TypeID([8]byte{108, 102, 213, 85, 251, 3, 53, 21}) + + Instruction_InitializeCustomizablePermissionlessLbPair = ag_binary.TypeID([8]byte{46, 39, 41, 135, 111, 183, 200, 64}) + + Instruction_InitializeBinArrayBitmapExtension = ag_binary.TypeID([8]byte{47, 157, 226, 180, 12, 240, 33, 71}) + + Instruction_InitializeBinArray = ag_binary.TypeID([8]byte{35, 86, 19, 185, 78, 212, 75, 211}) + + Instruction_AddLiquidity = ag_binary.TypeID([8]byte{181, 157, 89, 67, 143, 182, 52, 72}) + + Instruction_AddLiquidityByWeight = ag_binary.TypeID([8]byte{28, 140, 238, 99, 231, 162, 21, 149}) + + Instruction_AddLiquidityByStrategy = ag_binary.TypeID([8]byte{7, 3, 150, 127, 148, 40, 61, 200}) + + Instruction_AddLiquidityByStrategyOneSide = ag_binary.TypeID([8]byte{41, 5, 238, 175, 100, 225, 6, 205}) + + Instruction_AddLiquidityOneSide = ag_binary.TypeID([8]byte{94, 155, 103, 151, 70, 95, 220, 165}) + + Instruction_RemoveLiquidity = ag_binary.TypeID([8]byte{80, 85, 209, 72, 24, 206, 177, 108}) + + Instruction_InitializePosition = ag_binary.TypeID([8]byte{219, 192, 234, 71, 190, 191, 102, 80}) + + Instruction_InitializePositionPda = ag_binary.TypeID([8]byte{46, 82, 125, 146, 85, 141, 228, 153}) + + Instruction_InitializePositionByOperator = ag_binary.TypeID([8]byte{251, 189, 190, 244, 117, 254, 35, 148}) + + Instruction_UpdatePositionOperator = ag_binary.TypeID([8]byte{202, 184, 103, 143, 180, 191, 116, 217}) + + Instruction_Swap = ag_binary.TypeID([8]byte{248, 198, 158, 145, 225, 117, 135, 200}) + + Instruction_SwapExactOut = ag_binary.TypeID([8]byte{250, 73, 101, 33, 38, 207, 75, 184}) + + Instruction_SwapWithPriceImpact = ag_binary.TypeID([8]byte{56, 173, 230, 208, 173, 228, 156, 205}) + + Instruction_WithdrawProtocolFee = ag_binary.TypeID([8]byte{158, 201, 158, 189, 33, 93, 162, 103}) + + Instruction_InitializeReward = ag_binary.TypeID([8]byte{95, 135, 192, 196, 242, 129, 230, 68}) + + Instruction_FundReward = ag_binary.TypeID([8]byte{188, 50, 249, 165, 93, 151, 38, 63}) + + Instruction_UpdateRewardFunder = ag_binary.TypeID([8]byte{211, 28, 48, 32, 215, 160, 35, 23}) + + Instruction_UpdateRewardDuration = ag_binary.TypeID([8]byte{138, 174, 196, 169, 213, 235, 254, 107}) + + Instruction_ClaimReward = ag_binary.TypeID([8]byte{149, 95, 181, 242, 94, 90, 158, 162}) + + Instruction_ClaimFee = ag_binary.TypeID([8]byte{169, 32, 79, 137, 136, 232, 70, 137}) + + Instruction_ClosePosition = ag_binary.TypeID([8]byte{123, 134, 81, 0, 49, 68, 98, 98}) + + Instruction_UpdateFeeParameters = ag_binary.TypeID([8]byte{128, 128, 208, 91, 246, 53, 31, 176}) + + Instruction_IncreaseOracleLength = ag_binary.TypeID([8]byte{190, 61, 125, 87, 103, 79, 158, 173}) + + Instruction_InitializePresetParameter = ag_binary.TypeID([8]byte{66, 188, 71, 211, 98, 109, 14, 186}) + + Instruction_ClosePresetParameter = ag_binary.TypeID([8]byte{4, 148, 145, 100, 134, 26, 181, 61}) + + Instruction_RemoveAllLiquidity = ag_binary.TypeID([8]byte{10, 51, 61, 35, 112, 105, 24, 85}) + + Instruction_TogglePairStatus = ag_binary.TypeID([8]byte{61, 115, 52, 23, 46, 13, 31, 144}) + + Instruction_MigratePosition = ag_binary.TypeID([8]byte{15, 132, 59, 50, 199, 6, 251, 46}) + + Instruction_MigrateBinArray = ag_binary.TypeID([8]byte{17, 23, 159, 211, 101, 184, 41, 241}) + + Instruction_UpdateFeesAndRewards = ag_binary.TypeID([8]byte{154, 230, 250, 13, 236, 209, 75, 223}) + + Instruction_WithdrawIneligibleReward = ag_binary.TypeID([8]byte{148, 206, 42, 195, 247, 49, 103, 8}) + + Instruction_SetActivationPoint = ag_binary.TypeID([8]byte{91, 249, 15, 165, 26, 129, 254, 125}) + + Instruction_RemoveLiquidityByRange = ag_binary.TypeID([8]byte{26, 82, 102, 152, 240, 74, 105, 26}) + + Instruction_AddLiquidityOneSidePrecise = ag_binary.TypeID([8]byte{161, 194, 103, 84, 171, 71, 250, 154}) + + Instruction_GoToABin = ag_binary.TypeID([8]byte{146, 72, 174, 224, 40, 253, 84, 174}) + + Instruction_SetPreActivationDuration = ag_binary.TypeID([8]byte{165, 61, 201, 244, 130, 159, 22, 100}) + + Instruction_SetPreActivationSwapAddress = ag_binary.TypeID([8]byte{57, 139, 47, 123, 216, 80, 223, 10}) +) + +// InstructionIDToName returns the name of the instruction given its ID. +func InstructionIDToName(id ag_binary.TypeID) string { + switch id { + case Instruction_InitializeLbPair: + return "InitializeLbPair" + case Instruction_InitializePermissionLbPair: + return "InitializePermissionLbPair" + case Instruction_InitializeCustomizablePermissionlessLbPair: + return "InitializeCustomizablePermissionlessLbPair" + case Instruction_InitializeBinArrayBitmapExtension: + return "InitializeBinArrayBitmapExtension" + case Instruction_InitializeBinArray: + return "InitializeBinArray" + case Instruction_AddLiquidity: + return "AddLiquidity" + case Instruction_AddLiquidityByWeight: + return "AddLiquidityByWeight" + case Instruction_AddLiquidityByStrategy: + return "AddLiquidityByStrategy" + case Instruction_AddLiquidityByStrategyOneSide: + return "AddLiquidityByStrategyOneSide" + case Instruction_AddLiquidityOneSide: + return "AddLiquidityOneSide" + case Instruction_RemoveLiquidity: + return "RemoveLiquidity" + case Instruction_InitializePosition: + return "InitializePosition" + case Instruction_InitializePositionPda: + return "InitializePositionPda" + case Instruction_InitializePositionByOperator: + return "InitializePositionByOperator" + case Instruction_UpdatePositionOperator: + return "UpdatePositionOperator" + case Instruction_Swap: + return "Swap" + case Instruction_SwapExactOut: + return "SwapExactOut" + case Instruction_SwapWithPriceImpact: + return "SwapWithPriceImpact" + case Instruction_WithdrawProtocolFee: + return "WithdrawProtocolFee" + case Instruction_InitializeReward: + return "InitializeReward" + case Instruction_FundReward: + return "FundReward" + case Instruction_UpdateRewardFunder: + return "UpdateRewardFunder" + case Instruction_UpdateRewardDuration: + return "UpdateRewardDuration" + case Instruction_ClaimReward: + return "ClaimReward" + case Instruction_ClaimFee: + return "ClaimFee" + case Instruction_ClosePosition: + return "ClosePosition" + case Instruction_UpdateFeeParameters: + return "UpdateFeeParameters" + case Instruction_IncreaseOracleLength: + return "IncreaseOracleLength" + case Instruction_InitializePresetParameter: + return "InitializePresetParameter" + case Instruction_ClosePresetParameter: + return "ClosePresetParameter" + case Instruction_RemoveAllLiquidity: + return "RemoveAllLiquidity" + case Instruction_TogglePairStatus: + return "TogglePairStatus" + case Instruction_MigratePosition: + return "MigratePosition" + case Instruction_MigrateBinArray: + return "MigrateBinArray" + case Instruction_UpdateFeesAndRewards: + return "UpdateFeesAndRewards" + case Instruction_WithdrawIneligibleReward: + return "WithdrawIneligibleReward" + case Instruction_SetActivationPoint: + return "SetActivationPoint" + case Instruction_RemoveLiquidityByRange: + return "RemoveLiquidityByRange" + case Instruction_AddLiquidityOneSidePrecise: + return "AddLiquidityOneSidePrecise" + case Instruction_GoToABin: + return "GoToABin" + case Instruction_SetPreActivationDuration: + return "SetPreActivationDuration" + case Instruction_SetPreActivationSwapAddress: + return "SetPreActivationSwapAddress" + 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_lb_pair", (*InitializeLbPair)(nil), + }, + { + "initialize_permission_lb_pair", (*InitializePermissionLbPair)(nil), + }, + { + "initialize_customizable_permissionless_lb_pair", (*InitializeCustomizablePermissionlessLbPair)(nil), + }, + { + "initialize_bin_array_bitmap_extension", (*InitializeBinArrayBitmapExtension)(nil), + }, + { + "initialize_bin_array", (*InitializeBinArray)(nil), + }, + { + "add_liquidity", (*AddLiquidity)(nil), + }, + { + "add_liquidity_by_weight", (*AddLiquidityByWeight)(nil), + }, + { + "add_liquidity_by_strategy", (*AddLiquidityByStrategy)(nil), + }, + { + "add_liquidity_by_strategy_one_side", (*AddLiquidityByStrategyOneSide)(nil), + }, + { + "add_liquidity_one_side", (*AddLiquidityOneSide)(nil), + }, + { + "remove_liquidity", (*RemoveLiquidity)(nil), + }, + { + "initialize_position", (*InitializePosition)(nil), + }, + { + "initialize_position_pda", (*InitializePositionPda)(nil), + }, + { + "initialize_position_by_operator", (*InitializePositionByOperator)(nil), + }, + { + "update_position_operator", (*UpdatePositionOperator)(nil), + }, + { + "swap", (*Swap)(nil), + }, + { + "swap_exact_out", (*SwapExactOut)(nil), + }, + { + "swap_with_price_impact", (*SwapWithPriceImpact)(nil), + }, + { + "withdraw_protocol_fee", (*WithdrawProtocolFee)(nil), + }, + { + "initialize_reward", (*InitializeReward)(nil), + }, + { + "fund_reward", (*FundReward)(nil), + }, + { + "update_reward_funder", (*UpdateRewardFunder)(nil), + }, + { + "update_reward_duration", (*UpdateRewardDuration)(nil), + }, + { + "claim_reward", (*ClaimReward)(nil), + }, + { + "claim_fee", (*ClaimFee)(nil), + }, + { + "close_position", (*ClosePosition)(nil), + }, + { + "update_fee_parameters", (*UpdateFeeParameters)(nil), + }, + { + "increase_oracle_length", (*IncreaseOracleLength)(nil), + }, + { + "initialize_preset_parameter", (*InitializePresetParameter)(nil), + }, + { + "close_preset_parameter", (*ClosePresetParameter)(nil), + }, + { + "remove_all_liquidity", (*RemoveAllLiquidity)(nil), + }, + { + "toggle_pair_status", (*TogglePairStatus)(nil), + }, + { + "migrate_position", (*MigratePosition)(nil), + }, + { + "migrate_bin_array", (*MigrateBinArray)(nil), + }, + { + "update_fees_and_rewards", (*UpdateFeesAndRewards)(nil), + }, + { + "withdraw_ineligible_reward", (*WithdrawIneligibleReward)(nil), + }, + { + "set_activation_point", (*SetActivationPoint)(nil), + }, + { + "remove_liquidity_by_range", (*RemoveLiquidityByRange)(nil), + }, + { + "add_liquidity_one_side_precise", (*AddLiquidityOneSidePrecise)(nil), + }, + { + "go_to_a_bin", (*GoToABin)(nil), + }, + { + "set_pre_activation_duration", (*SetPreActivationDuration)(nil), + }, + { + "set_pre_activation_swap_address", (*SetPreActivationSwapAddress)(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 +} diff --git a/programs/meteoradlmm/testing_utils.go b/programs/meteoradlmm/testing_utils.go new file mode 100644 index 00000000..90687a19 --- /dev/null +++ b/programs/meteoradlmm/testing_utils.go @@ -0,0 +1,20 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + "bytes" + "fmt" + ag_binary "github.com/gagliardetto/binary" +) + +func encodeT(data interface{}, buf *bytes.Buffer) error { + if err := ag_binary.NewBorshEncoder(buf).Encode(data); err != nil { + return fmt.Errorf("unable to encode instruction: %w", err) + } + return nil +} + +func decodeT(dst interface{}, data []byte) error { + return ag_binary.NewBorshDecoder(data).Decode(dst) +} diff --git a/programs/meteoradlmm/types.go b/programs/meteoradlmm/types.go new file mode 100644 index 00000000..402341f5 --- /dev/null +++ b/programs/meteoradlmm/types.go @@ -0,0 +1,1724 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package lb_clmm + +import ( + ag_binary "github.com/gagliardetto/binary" + ag_solanago "github.com/gagliardetto/solana-go" +) + +type InitPresetParametersIx struct { + // Bin step. Represent the price increment / decrement. + BinStep uint16 + + // Used for base fee calculation. base_fee_rate = base_factor * bin_step + BaseFactor uint16 + + // Filter period determine high frequency trading time window. + FilterPeriod uint16 + + // Decay period determine when the volatile fee start decay / decrease. + DecayPeriod uint16 + + // Reduction factor controls the volatile fee rate decrement rate. + ReductionFactor uint16 + + // Used to scale the variable fee component depending on the dynamic of the market + VariableFeeControl uint32 + + // Maximum number of bin crossed can be accumulated. Used to cap volatile fee rate. + MaxVolatilityAccumulator uint32 + + // Min bin id supported by the pool based on the configured bin step. + MinBinId int32 + + // Max bin id supported by the pool based on the configured bin step. + MaxBinId int32 + + // Portion of swap fees retained by the protocol by controlling protocol_share parameter. protocol_swap_fee = protocol_share * total_swap_fee + ProtocolShare uint16 +} + +func (obj InitPresetParametersIx) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `BinStep` param: + err = encoder.Encode(obj.BinStep) + if err != nil { + return err + } + // Serialize `BaseFactor` param: + err = encoder.Encode(obj.BaseFactor) + if err != nil { + return err + } + // Serialize `FilterPeriod` param: + err = encoder.Encode(obj.FilterPeriod) + if err != nil { + return err + } + // Serialize `DecayPeriod` param: + err = encoder.Encode(obj.DecayPeriod) + if err != nil { + return err + } + // Serialize `ReductionFactor` param: + err = encoder.Encode(obj.ReductionFactor) + if err != nil { + return err + } + // Serialize `VariableFeeControl` param: + err = encoder.Encode(obj.VariableFeeControl) + if err != nil { + return err + } + // Serialize `MaxVolatilityAccumulator` param: + err = encoder.Encode(obj.MaxVolatilityAccumulator) + if err != nil { + return err + } + // Serialize `MinBinId` param: + err = encoder.Encode(obj.MinBinId) + if err != nil { + return err + } + // Serialize `MaxBinId` param: + err = encoder.Encode(obj.MaxBinId) + if err != nil { + return err + } + // Serialize `ProtocolShare` param: + err = encoder.Encode(obj.ProtocolShare) + if err != nil { + return err + } + return nil +} + +func (obj *InitPresetParametersIx) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `BinStep`: + err = decoder.Decode(&obj.BinStep) + if err != nil { + return err + } + // Deserialize `BaseFactor`: + err = decoder.Decode(&obj.BaseFactor) + if err != nil { + return err + } + // Deserialize `FilterPeriod`: + err = decoder.Decode(&obj.FilterPeriod) + if err != nil { + return err + } + // Deserialize `DecayPeriod`: + err = decoder.Decode(&obj.DecayPeriod) + if err != nil { + return err + } + // Deserialize `ReductionFactor`: + err = decoder.Decode(&obj.ReductionFactor) + if err != nil { + return err + } + // Deserialize `VariableFeeControl`: + err = decoder.Decode(&obj.VariableFeeControl) + if err != nil { + return err + } + // Deserialize `MaxVolatilityAccumulator`: + err = decoder.Decode(&obj.MaxVolatilityAccumulator) + if err != nil { + return err + } + // Deserialize `MinBinId`: + err = decoder.Decode(&obj.MinBinId) + if err != nil { + return err + } + // Deserialize `MaxBinId`: + err = decoder.Decode(&obj.MaxBinId) + if err != nil { + return err + } + // Deserialize `ProtocolShare`: + err = decoder.Decode(&obj.ProtocolShare) + if err != nil { + return err + } + return nil +} + +type FeeParameter struct { + // Portion of swap fees retained by the protocol by controlling protocol_share parameter. protocol_swap_fee = protocol_share * total_swap_fee + ProtocolShare uint16 + + // Base factor for base fee rate + BaseFactor uint16 +} + +func (obj FeeParameter) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `ProtocolShare` param: + err = encoder.Encode(obj.ProtocolShare) + if err != nil { + return err + } + // Serialize `BaseFactor` param: + err = encoder.Encode(obj.BaseFactor) + if err != nil { + return err + } + return nil +} + +func (obj *FeeParameter) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `ProtocolShare`: + err = decoder.Decode(&obj.ProtocolShare) + if err != nil { + return err + } + // Deserialize `BaseFactor`: + err = decoder.Decode(&obj.BaseFactor) + if err != nil { + return err + } + return nil +} + +type LiquidityParameterByStrategyOneSide struct { + // Amount of X token or Y token to deposit + Amount uint64 + + // Active bin that integrator observe off-chain + ActiveId int32 + + // max active bin slippage allowed + MaxActiveBinSlippage int32 + + // strategy parameters + StrategyParameters StrategyParameters +} + +func (obj LiquidityParameterByStrategyOneSide) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Amount` param: + err = encoder.Encode(obj.Amount) + if err != nil { + return err + } + // Serialize `ActiveId` param: + err = encoder.Encode(obj.ActiveId) + if err != nil { + return err + } + // Serialize `MaxActiveBinSlippage` param: + err = encoder.Encode(obj.MaxActiveBinSlippage) + if err != nil { + return err + } + // Serialize `StrategyParameters` param: + err = encoder.Encode(obj.StrategyParameters) + if err != nil { + return err + } + return nil +} + +func (obj *LiquidityParameterByStrategyOneSide) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Amount`: + err = decoder.Decode(&obj.Amount) + if err != nil { + return err + } + // Deserialize `ActiveId`: + err = decoder.Decode(&obj.ActiveId) + if err != nil { + return err + } + // Deserialize `MaxActiveBinSlippage`: + err = decoder.Decode(&obj.MaxActiveBinSlippage) + if err != nil { + return err + } + // Deserialize `StrategyParameters`: + err = decoder.Decode(&obj.StrategyParameters) + if err != nil { + return err + } + return nil +} + +type LiquidityParameterByStrategy struct { + // Amount of X token to deposit + AmountX uint64 + + // Amount of Y token to deposit + AmountY uint64 + + // Active bin that integrator observe off-chain + ActiveId int32 + + // max active bin slippage allowed + MaxActiveBinSlippage int32 + + // strategy parameters + StrategyParameters StrategyParameters +} + +func (obj LiquidityParameterByStrategy) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `AmountX` param: + err = encoder.Encode(obj.AmountX) + if err != nil { + return err + } + // Serialize `AmountY` param: + err = encoder.Encode(obj.AmountY) + if err != nil { + return err + } + // Serialize `ActiveId` param: + err = encoder.Encode(obj.ActiveId) + if err != nil { + return err + } + // Serialize `MaxActiveBinSlippage` param: + err = encoder.Encode(obj.MaxActiveBinSlippage) + if err != nil { + return err + } + // Serialize `StrategyParameters` param: + err = encoder.Encode(obj.StrategyParameters) + if err != nil { + return err + } + return nil +} + +func (obj *LiquidityParameterByStrategy) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `AmountX`: + err = decoder.Decode(&obj.AmountX) + if err != nil { + return err + } + // Deserialize `AmountY`: + err = decoder.Decode(&obj.AmountY) + if err != nil { + return err + } + // Deserialize `ActiveId`: + err = decoder.Decode(&obj.ActiveId) + if err != nil { + return err + } + // Deserialize `MaxActiveBinSlippage`: + err = decoder.Decode(&obj.MaxActiveBinSlippage) + if err != nil { + return err + } + // Deserialize `StrategyParameters`: + err = decoder.Decode(&obj.StrategyParameters) + if err != nil { + return err + } + return nil +} + +type StrategyParameters struct { + // min bin id + MinBinId int32 + + // max bin id + MaxBinId int32 + + // strategy type + StrategyType StrategyType + + // parameters + Parameteres [64]uint8 +} + +func (obj StrategyParameters) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `MinBinId` param: + err = encoder.Encode(obj.MinBinId) + if err != nil { + return err + } + // Serialize `MaxBinId` param: + err = encoder.Encode(obj.MaxBinId) + if err != nil { + return err + } + // Serialize `StrategyType` param: + err = encoder.Encode(obj.StrategyType) + if err != nil { + return err + } + // Serialize `Parameteres` param: + err = encoder.Encode(obj.Parameteres) + if err != nil { + return err + } + return nil +} + +func (obj *StrategyParameters) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `MinBinId`: + err = decoder.Decode(&obj.MinBinId) + if err != nil { + return err + } + // Deserialize `MaxBinId`: + err = decoder.Decode(&obj.MaxBinId) + if err != nil { + return err + } + // Deserialize `StrategyType`: + err = decoder.Decode(&obj.StrategyType) + if err != nil { + return err + } + // Deserialize `Parameteres`: + err = decoder.Decode(&obj.Parameteres) + if err != nil { + return err + } + return nil +} + +type LiquidityOneSideParameter struct { + // Amount of X token or Y token to deposit + Amount uint64 + + // Active bin that integrator observe off-chain + ActiveId int32 + + // max active bin slippage allowed + MaxActiveBinSlippage int32 + + // Liquidity distribution to each bins + BinLiquidityDist []BinLiquidityDistributionByWeight +} + +func (obj LiquidityOneSideParameter) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Amount` param: + err = encoder.Encode(obj.Amount) + if err != nil { + return err + } + // Serialize `ActiveId` param: + err = encoder.Encode(obj.ActiveId) + if err != nil { + return err + } + // Serialize `MaxActiveBinSlippage` param: + err = encoder.Encode(obj.MaxActiveBinSlippage) + if err != nil { + return err + } + // Serialize `BinLiquidityDist` param: + err = encoder.Encode(obj.BinLiquidityDist) + if err != nil { + return err + } + return nil +} + +func (obj *LiquidityOneSideParameter) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Amount`: + err = decoder.Decode(&obj.Amount) + if err != nil { + return err + } + // Deserialize `ActiveId`: + err = decoder.Decode(&obj.ActiveId) + if err != nil { + return err + } + // Deserialize `MaxActiveBinSlippage`: + err = decoder.Decode(&obj.MaxActiveBinSlippage) + if err != nil { + return err + } + // Deserialize `BinLiquidityDist`: + err = decoder.Decode(&obj.BinLiquidityDist) + if err != nil { + return err + } + return nil +} + +type BinLiquidityDistributionByWeight struct { + // Define the bin ID wish to deposit to. + BinId int32 + + // weight of liquidity distributed for this bin id + Weight uint16 +} + +func (obj BinLiquidityDistributionByWeight) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `BinId` param: + err = encoder.Encode(obj.BinId) + if err != nil { + return err + } + // Serialize `Weight` param: + err = encoder.Encode(obj.Weight) + if err != nil { + return err + } + return nil +} + +func (obj *BinLiquidityDistributionByWeight) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `BinId`: + err = decoder.Decode(&obj.BinId) + if err != nil { + return err + } + // Deserialize `Weight`: + err = decoder.Decode(&obj.Weight) + if err != nil { + return err + } + return nil +} + +type LiquidityParameterByWeight struct { + // Amount of X token to deposit + AmountX uint64 + + // Amount of Y token to deposit + AmountY uint64 + + // Active bin that integrator observe off-chain + ActiveId int32 + + // max active bin slippage allowed + MaxActiveBinSlippage int32 + + // Liquidity distribution to each bins + BinLiquidityDist []BinLiquidityDistributionByWeight +} + +func (obj LiquidityParameterByWeight) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `AmountX` param: + err = encoder.Encode(obj.AmountX) + if err != nil { + return err + } + // Serialize `AmountY` param: + err = encoder.Encode(obj.AmountY) + if err != nil { + return err + } + // Serialize `ActiveId` param: + err = encoder.Encode(obj.ActiveId) + if err != nil { + return err + } + // Serialize `MaxActiveBinSlippage` param: + err = encoder.Encode(obj.MaxActiveBinSlippage) + if err != nil { + return err + } + // Serialize `BinLiquidityDist` param: + err = encoder.Encode(obj.BinLiquidityDist) + if err != nil { + return err + } + return nil +} + +func (obj *LiquidityParameterByWeight) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `AmountX`: + err = decoder.Decode(&obj.AmountX) + if err != nil { + return err + } + // Deserialize `AmountY`: + err = decoder.Decode(&obj.AmountY) + if err != nil { + return err + } + // Deserialize `ActiveId`: + err = decoder.Decode(&obj.ActiveId) + if err != nil { + return err + } + // Deserialize `MaxActiveBinSlippage`: + err = decoder.Decode(&obj.MaxActiveBinSlippage) + if err != nil { + return err + } + // Deserialize `BinLiquidityDist`: + err = decoder.Decode(&obj.BinLiquidityDist) + if err != nil { + return err + } + return nil +} + +type AddLiquiditySingleSidePreciseParameter struct { + Bins []CompressedBinDepositAmount + DecompressMultiplier uint64 +} + +func (obj AddLiquiditySingleSidePreciseParameter) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Bins` param: + err = encoder.Encode(obj.Bins) + if err != nil { + return err + } + // Serialize `DecompressMultiplier` param: + err = encoder.Encode(obj.DecompressMultiplier) + if err != nil { + return err + } + return nil +} + +func (obj *AddLiquiditySingleSidePreciseParameter) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Bins`: + err = decoder.Decode(&obj.Bins) + if err != nil { + return err + } + // Deserialize `DecompressMultiplier`: + err = decoder.Decode(&obj.DecompressMultiplier) + if err != nil { + return err + } + return nil +} + +type CompressedBinDepositAmount struct { + BinId int32 + Amount uint32 +} + +func (obj CompressedBinDepositAmount) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `BinId` param: + err = encoder.Encode(obj.BinId) + if err != nil { + return err + } + // Serialize `Amount` param: + err = encoder.Encode(obj.Amount) + if err != nil { + return err + } + return nil +} + +func (obj *CompressedBinDepositAmount) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `BinId`: + err = decoder.Decode(&obj.BinId) + if err != nil { + return err + } + // Deserialize `Amount`: + err = decoder.Decode(&obj.Amount) + if err != nil { + return err + } + return nil +} + +type BinLiquidityDistribution struct { + // Define the bin ID wish to deposit to. + BinId int32 + + // DistributionX (or distributionY) is the percentages of amountX (or amountY) you want to add to each bin. + DistributionX uint16 + + // DistributionX (or distributionY) is the percentages of amountX (or amountY) you want to add to each bin. + DistributionY uint16 +} + +func (obj BinLiquidityDistribution) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `BinId` param: + err = encoder.Encode(obj.BinId) + if err != nil { + return err + } + // Serialize `DistributionX` param: + err = encoder.Encode(obj.DistributionX) + if err != nil { + return err + } + // Serialize `DistributionY` param: + err = encoder.Encode(obj.DistributionY) + if err != nil { + return err + } + return nil +} + +func (obj *BinLiquidityDistribution) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `BinId`: + err = decoder.Decode(&obj.BinId) + if err != nil { + return err + } + // Deserialize `DistributionX`: + err = decoder.Decode(&obj.DistributionX) + if err != nil { + return err + } + // Deserialize `DistributionY`: + err = decoder.Decode(&obj.DistributionY) + if err != nil { + return err + } + return nil +} + +type LiquidityParameter struct { + // Amount of X token to deposit + AmountX uint64 + + // Amount of Y token to deposit + AmountY uint64 + + // Liquidity distribution to each bins + BinLiquidityDist []BinLiquidityDistribution +} + +func (obj LiquidityParameter) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `AmountX` param: + err = encoder.Encode(obj.AmountX) + if err != nil { + return err + } + // Serialize `AmountY` param: + err = encoder.Encode(obj.AmountY) + if err != nil { + return err + } + // Serialize `BinLiquidityDist` param: + err = encoder.Encode(obj.BinLiquidityDist) + if err != nil { + return err + } + return nil +} + +func (obj *LiquidityParameter) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `AmountX`: + err = decoder.Decode(&obj.AmountX) + if err != nil { + return err + } + // Deserialize `AmountY`: + err = decoder.Decode(&obj.AmountY) + if err != nil { + return err + } + // Deserialize `BinLiquidityDist`: + err = decoder.Decode(&obj.BinLiquidityDist) + if err != nil { + return err + } + return nil +} + +type CustomizableParams struct { + // Pool price + ActiveId int32 + + // Bin step + BinStep uint16 + + // Base factor + BaseFactor uint16 + + // Activation type. 0 = Slot, 1 = Time. Check ActivationType enum + ActivationType uint8 + + // Whether the pool has an alpha vault + HasAlphaVault bool + + // Decide when does the pool start trade. None = Now + ActivationPoint *uint64 `bin:"optional"` + + // Padding, for future use + Padding [64]uint8 +} + +func (obj CustomizableParams) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `ActiveId` param: + err = encoder.Encode(obj.ActiveId) + if err != nil { + return err + } + // Serialize `BinStep` param: + err = encoder.Encode(obj.BinStep) + if err != nil { + return err + } + // Serialize `BaseFactor` param: + err = encoder.Encode(obj.BaseFactor) + if err != nil { + return err + } + // Serialize `ActivationType` param: + err = encoder.Encode(obj.ActivationType) + if err != nil { + return err + } + // Serialize `HasAlphaVault` param: + err = encoder.Encode(obj.HasAlphaVault) + if err != nil { + return err + } + // Serialize `ActivationPoint` param (optional): + { + if obj.ActivationPoint == nil { + err = encoder.WriteBool(false) + if err != nil { + return err + } + } else { + err = encoder.WriteBool(true) + if err != nil { + return err + } + err = encoder.Encode(obj.ActivationPoint) + if err != nil { + return err + } + } + } + // Serialize `Padding` param: + err = encoder.Encode(obj.Padding) + if err != nil { + return err + } + return nil +} + +func (obj *CustomizableParams) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `ActiveId`: + err = decoder.Decode(&obj.ActiveId) + if err != nil { + return err + } + // Deserialize `BinStep`: + err = decoder.Decode(&obj.BinStep) + if err != nil { + return err + } + // Deserialize `BaseFactor`: + err = decoder.Decode(&obj.BaseFactor) + if err != nil { + return err + } + // Deserialize `ActivationType`: + err = decoder.Decode(&obj.ActivationType) + if err != nil { + return err + } + // Deserialize `HasAlphaVault`: + err = decoder.Decode(&obj.HasAlphaVault) + if err != nil { + return err + } + // Deserialize `ActivationPoint` (optional): + { + ok, err := decoder.ReadBool() + if err != nil { + return err + } + if ok { + err = decoder.Decode(&obj.ActivationPoint) + if err != nil { + return err + } + } + } + // Deserialize `Padding`: + err = decoder.Decode(&obj.Padding) + if err != nil { + return err + } + return nil +} + +type InitPermissionPairIx struct { + ActiveId int32 + BinStep uint16 + BaseFactor uint16 + MinBinId int32 + MaxBinId int32 + ActivationType uint8 +} + +func (obj InitPermissionPairIx) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `ActiveId` param: + err = encoder.Encode(obj.ActiveId) + if err != nil { + return err + } + // Serialize `BinStep` param: + err = encoder.Encode(obj.BinStep) + if err != nil { + return err + } + // Serialize `BaseFactor` param: + err = encoder.Encode(obj.BaseFactor) + if err != nil { + return err + } + // Serialize `MinBinId` param: + err = encoder.Encode(obj.MinBinId) + if err != nil { + return err + } + // Serialize `MaxBinId` param: + err = encoder.Encode(obj.MaxBinId) + if err != nil { + return err + } + // Serialize `ActivationType` param: + err = encoder.Encode(obj.ActivationType) + if err != nil { + return err + } + return nil +} + +func (obj *InitPermissionPairIx) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `ActiveId`: + err = decoder.Decode(&obj.ActiveId) + if err != nil { + return err + } + // Deserialize `BinStep`: + err = decoder.Decode(&obj.BinStep) + if err != nil { + return err + } + // Deserialize `BaseFactor`: + err = decoder.Decode(&obj.BaseFactor) + if err != nil { + return err + } + // Deserialize `MinBinId`: + err = decoder.Decode(&obj.MinBinId) + if err != nil { + return err + } + // Deserialize `MaxBinId`: + err = decoder.Decode(&obj.MaxBinId) + if err != nil { + return err + } + // Deserialize `ActivationType`: + err = decoder.Decode(&obj.ActivationType) + if err != nil { + return err + } + return nil +} + +type BinLiquidityReduction struct { + BinId int32 + BpsToRemove uint16 +} + +func (obj BinLiquidityReduction) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `BinId` param: + err = encoder.Encode(obj.BinId) + if err != nil { + return err + } + // Serialize `BpsToRemove` param: + err = encoder.Encode(obj.BpsToRemove) + if err != nil { + return err + } + return nil +} + +func (obj *BinLiquidityReduction) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `BinId`: + err = decoder.Decode(&obj.BinId) + if err != nil { + return err + } + // Deserialize `BpsToRemove`: + err = decoder.Decode(&obj.BpsToRemove) + if err != nil { + return err + } + return nil +} + +type Bin struct { + // Amount of token X in the bin. This already excluded protocol fees. + AmountX uint64 + + // Amount of token Y in the bin. This already excluded protocol fees. + AmountY uint64 + + // Bin price + Price ag_binary.Uint128 + + // Liquidities of the bin. This is the same as LP mint supply. q-number + LiquiditySupply ag_binary.Uint128 + + // reward_a_per_token_stored + RewardPerTokenStored [2]ag_binary.Uint128 + + // Swap fee amount of token X per liquidity deposited. + FeeAmountXPerTokenStored ag_binary.Uint128 + + // Swap fee amount of token Y per liquidity deposited. + FeeAmountYPerTokenStored ag_binary.Uint128 + + // Total token X swap into the bin. Only used for tracking purpose. + AmountXIn ag_binary.Uint128 + + // Total token Y swap into he bin. Only used for tracking purpose. + AmountYIn ag_binary.Uint128 +} + +func (obj Bin) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `AmountX` param: + err = encoder.Encode(obj.AmountX) + if err != nil { + return err + } + // Serialize `AmountY` param: + err = encoder.Encode(obj.AmountY) + if err != nil { + return err + } + // Serialize `Price` param: + err = encoder.Encode(obj.Price) + if err != nil { + return err + } + // Serialize `LiquiditySupply` param: + err = encoder.Encode(obj.LiquiditySupply) + if err != nil { + return err + } + // Serialize `RewardPerTokenStored` param: + err = encoder.Encode(obj.RewardPerTokenStored) + if err != nil { + return err + } + // Serialize `FeeAmountXPerTokenStored` param: + err = encoder.Encode(obj.FeeAmountXPerTokenStored) + if err != nil { + return err + } + // Serialize `FeeAmountYPerTokenStored` param: + err = encoder.Encode(obj.FeeAmountYPerTokenStored) + if err != nil { + return err + } + // Serialize `AmountXIn` param: + err = encoder.Encode(obj.AmountXIn) + if err != nil { + return err + } + // Serialize `AmountYIn` param: + err = encoder.Encode(obj.AmountYIn) + if err != nil { + return err + } + return nil +} + +func (obj *Bin) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `AmountX`: + err = decoder.Decode(&obj.AmountX) + if err != nil { + return err + } + // Deserialize `AmountY`: + err = decoder.Decode(&obj.AmountY) + if err != nil { + return err + } + // Deserialize `Price`: + err = decoder.Decode(&obj.Price) + if err != nil { + return err + } + // Deserialize `LiquiditySupply`: + err = decoder.Decode(&obj.LiquiditySupply) + if err != nil { + return err + } + // Deserialize `RewardPerTokenStored`: + err = decoder.Decode(&obj.RewardPerTokenStored) + if err != nil { + return err + } + // Deserialize `FeeAmountXPerTokenStored`: + err = decoder.Decode(&obj.FeeAmountXPerTokenStored) + if err != nil { + return err + } + // Deserialize `FeeAmountYPerTokenStored`: + err = decoder.Decode(&obj.FeeAmountYPerTokenStored) + if err != nil { + return err + } + // Deserialize `AmountXIn`: + err = decoder.Decode(&obj.AmountXIn) + if err != nil { + return err + } + // Deserialize `AmountYIn`: + err = decoder.Decode(&obj.AmountYIn) + if err != nil { + return err + } + return nil +} + +type ProtocolFee struct { + AmountX uint64 + AmountY uint64 +} + +func (obj ProtocolFee) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `AmountX` param: + err = encoder.Encode(obj.AmountX) + if err != nil { + return err + } + // Serialize `AmountY` param: + err = encoder.Encode(obj.AmountY) + if err != nil { + return err + } + return nil +} + +func (obj *ProtocolFee) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `AmountX`: + err = decoder.Decode(&obj.AmountX) + if err != nil { + return err + } + // Deserialize `AmountY`: + err = decoder.Decode(&obj.AmountY) + if err != nil { + return err + } + return nil +} + +type RewardInfo struct { + // Reward token mint. + Mint ag_solanago.PublicKey + + // Reward vault token account. + Vault ag_solanago.PublicKey + + // Authority account that allows to fund rewards + Funder ag_solanago.PublicKey + + // TODO check whether we need to store it in pool + RewardDuration uint64 + + // TODO check whether we need to store it in pool + RewardDurationEnd uint64 + + // TODO check whether we need to store it in pool + RewardRate ag_binary.Uint128 + + // The last time reward states were updated. + LastUpdateTime uint64 + + // Accumulated seconds where when farm distribute rewards, but the bin is empty. The reward will be accumulated for next reward time window. + CumulativeSecondsWithEmptyLiquidityReward uint64 +} + +func (obj RewardInfo) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Mint` param: + err = encoder.Encode(obj.Mint) + if err != nil { + return err + } + // Serialize `Vault` param: + err = encoder.Encode(obj.Vault) + if err != nil { + return err + } + // Serialize `Funder` param: + err = encoder.Encode(obj.Funder) + if err != nil { + return err + } + // Serialize `RewardDuration` param: + err = encoder.Encode(obj.RewardDuration) + if err != nil { + return err + } + // Serialize `RewardDurationEnd` param: + err = encoder.Encode(obj.RewardDurationEnd) + if err != nil { + return err + } + // Serialize `RewardRate` param: + err = encoder.Encode(obj.RewardRate) + if err != nil { + return err + } + // Serialize `LastUpdateTime` param: + err = encoder.Encode(obj.LastUpdateTime) + if err != nil { + return err + } + // Serialize `CumulativeSecondsWithEmptyLiquidityReward` param: + err = encoder.Encode(obj.CumulativeSecondsWithEmptyLiquidityReward) + if err != nil { + return err + } + return nil +} + +func (obj *RewardInfo) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Mint`: + err = decoder.Decode(&obj.Mint) + if err != nil { + return err + } + // Deserialize `Vault`: + err = decoder.Decode(&obj.Vault) + if err != nil { + return err + } + // Deserialize `Funder`: + err = decoder.Decode(&obj.Funder) + if err != nil { + return err + } + // Deserialize `RewardDuration`: + err = decoder.Decode(&obj.RewardDuration) + if err != nil { + return err + } + // Deserialize `RewardDurationEnd`: + err = decoder.Decode(&obj.RewardDurationEnd) + if err != nil { + return err + } + // Deserialize `RewardRate`: + err = decoder.Decode(&obj.RewardRate) + if err != nil { + return err + } + // Deserialize `LastUpdateTime`: + err = decoder.Decode(&obj.LastUpdateTime) + if err != nil { + return err + } + // Deserialize `CumulativeSecondsWithEmptyLiquidityReward`: + err = decoder.Decode(&obj.CumulativeSecondsWithEmptyLiquidityReward) + if err != nil { + return err + } + return nil +} + +type Observation struct { + // Cumulative active bin ID + CumulativeActiveBinId ag_binary.Int128 + + // Observation sample created timestamp + CreatedAt int64 + + // Observation sample last updated timestamp + LastUpdatedAt int64 +} + +func (obj Observation) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `CumulativeActiveBinId` param: + err = encoder.Encode(obj.CumulativeActiveBinId) + if err != nil { + return err + } + // Serialize `CreatedAt` param: + err = encoder.Encode(obj.CreatedAt) + if err != nil { + return err + } + // Serialize `LastUpdatedAt` param: + err = encoder.Encode(obj.LastUpdatedAt) + if err != nil { + return err + } + return nil +} + +func (obj *Observation) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `CumulativeActiveBinId`: + err = decoder.Decode(&obj.CumulativeActiveBinId) + if err != nil { + return err + } + // Deserialize `CreatedAt`: + err = decoder.Decode(&obj.CreatedAt) + if err != nil { + return err + } + // Deserialize `LastUpdatedAt`: + err = decoder.Decode(&obj.LastUpdatedAt) + if err != nil { + return err + } + return nil +} + +type StaticParameters struct { + // Used for base fee calculation. base_fee_rate = base_factor * bin_step + BaseFactor uint16 + + // Filter period determine high frequency trading time window. + FilterPeriod uint16 + + // Decay period determine when the volatile fee start decay / decrease. + DecayPeriod uint16 + + // Reduction factor controls the volatile fee rate decrement rate. + ReductionFactor uint16 + + // Used to scale the variable fee component depending on the dynamic of the market + VariableFeeControl uint32 + + // Maximum number of bin crossed can be accumulated. Used to cap volatile fee rate. + MaxVolatilityAccumulator uint32 + + // Min bin id supported by the pool based on the configured bin step. + MinBinId int32 + + // Max bin id supported by the pool based on the configured bin step. + MaxBinId int32 + + // Portion of swap fees retained by the protocol by controlling protocol_share parameter. protocol_swap_fee = protocol_share * total_swap_fee + ProtocolShare uint16 + + // Padding for bytemuck safe alignment + Padding [6]uint8 +} + +func (obj StaticParameters) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `BaseFactor` param: + err = encoder.Encode(obj.BaseFactor) + if err != nil { + return err + } + // Serialize `FilterPeriod` param: + err = encoder.Encode(obj.FilterPeriod) + if err != nil { + return err + } + // Serialize `DecayPeriod` param: + err = encoder.Encode(obj.DecayPeriod) + if err != nil { + return err + } + // Serialize `ReductionFactor` param: + err = encoder.Encode(obj.ReductionFactor) + if err != nil { + return err + } + // Serialize `VariableFeeControl` param: + err = encoder.Encode(obj.VariableFeeControl) + if err != nil { + return err + } + // Serialize `MaxVolatilityAccumulator` param: + err = encoder.Encode(obj.MaxVolatilityAccumulator) + if err != nil { + return err + } + // Serialize `MinBinId` param: + err = encoder.Encode(obj.MinBinId) + if err != nil { + return err + } + // Serialize `MaxBinId` param: + err = encoder.Encode(obj.MaxBinId) + if err != nil { + return err + } + // Serialize `ProtocolShare` param: + err = encoder.Encode(obj.ProtocolShare) + if err != nil { + return err + } + // Serialize `Padding` param: + err = encoder.Encode(obj.Padding) + if err != nil { + return err + } + return nil +} + +func (obj *StaticParameters) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `BaseFactor`: + err = decoder.Decode(&obj.BaseFactor) + if err != nil { + return err + } + // Deserialize `FilterPeriod`: + err = decoder.Decode(&obj.FilterPeriod) + if err != nil { + return err + } + // Deserialize `DecayPeriod`: + err = decoder.Decode(&obj.DecayPeriod) + if err != nil { + return err + } + // Deserialize `ReductionFactor`: + err = decoder.Decode(&obj.ReductionFactor) + if err != nil { + return err + } + // Deserialize `VariableFeeControl`: + err = decoder.Decode(&obj.VariableFeeControl) + if err != nil { + return err + } + // Deserialize `MaxVolatilityAccumulator`: + err = decoder.Decode(&obj.MaxVolatilityAccumulator) + if err != nil { + return err + } + // Deserialize `MinBinId`: + err = decoder.Decode(&obj.MinBinId) + if err != nil { + return err + } + // Deserialize `MaxBinId`: + err = decoder.Decode(&obj.MaxBinId) + if err != nil { + return err + } + // Deserialize `ProtocolShare`: + err = decoder.Decode(&obj.ProtocolShare) + if err != nil { + return err + } + // Deserialize `Padding`: + err = decoder.Decode(&obj.Padding) + if err != nil { + return err + } + return nil +} + +type VariableParameters struct { + // Volatility accumulator measure the number of bin crossed since reference bin ID. Normally (without filter period taken into consideration), reference bin ID is the active bin of last swap. + // It affects the variable fee rate + VolatilityAccumulator uint32 + + // Volatility reference is decayed volatility accumulator. It is always <= volatility_accumulator + VolatilityReference uint32 + + // Active bin id of last swap. + IndexReference int32 + + // Padding for bytemuck safe alignment + Padding [4]uint8 + + // Last timestamp the variable parameters was updated + LastUpdateTimestamp int64 + + // Padding for bytemuck safe alignment + Padding1 [8]uint8 +} + +func (obj VariableParameters) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `VolatilityAccumulator` param: + err = encoder.Encode(obj.VolatilityAccumulator) + if err != nil { + return err + } + // Serialize `VolatilityReference` param: + err = encoder.Encode(obj.VolatilityReference) + if err != nil { + return err + } + // Serialize `IndexReference` param: + err = encoder.Encode(obj.IndexReference) + if err != nil { + return err + } + // Serialize `Padding` param: + err = encoder.Encode(obj.Padding) + if err != nil { + return err + } + // Serialize `LastUpdateTimestamp` param: + err = encoder.Encode(obj.LastUpdateTimestamp) + if err != nil { + return err + } + // Serialize `Padding1` param: + err = encoder.Encode(obj.Padding1) + if err != nil { + return err + } + return nil +} + +func (obj *VariableParameters) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `VolatilityAccumulator`: + err = decoder.Decode(&obj.VolatilityAccumulator) + if err != nil { + return err + } + // Deserialize `VolatilityReference`: + err = decoder.Decode(&obj.VolatilityReference) + if err != nil { + return err + } + // Deserialize `IndexReference`: + err = decoder.Decode(&obj.IndexReference) + if err != nil { + return err + } + // Deserialize `Padding`: + err = decoder.Decode(&obj.Padding) + if err != nil { + return err + } + // Deserialize `LastUpdateTimestamp`: + err = decoder.Decode(&obj.LastUpdateTimestamp) + if err != nil { + return err + } + // Deserialize `Padding1`: + err = decoder.Decode(&obj.Padding1) + if err != nil { + return err + } + return nil +} + +type FeeInfo struct { + FeeXPerTokenComplete ag_binary.Uint128 + FeeYPerTokenComplete ag_binary.Uint128 + FeeXPending uint64 + FeeYPending uint64 +} + +func (obj FeeInfo) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `FeeXPerTokenComplete` param: + err = encoder.Encode(obj.FeeXPerTokenComplete) + if err != nil { + return err + } + // Serialize `FeeYPerTokenComplete` param: + err = encoder.Encode(obj.FeeYPerTokenComplete) + if err != nil { + return err + } + // Serialize `FeeXPending` param: + err = encoder.Encode(obj.FeeXPending) + if err != nil { + return err + } + // Serialize `FeeYPending` param: + err = encoder.Encode(obj.FeeYPending) + if err != nil { + return err + } + return nil +} + +func (obj *FeeInfo) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `FeeXPerTokenComplete`: + err = decoder.Decode(&obj.FeeXPerTokenComplete) + if err != nil { + return err + } + // Deserialize `FeeYPerTokenComplete`: + err = decoder.Decode(&obj.FeeYPerTokenComplete) + if err != nil { + return err + } + // Deserialize `FeeXPending`: + err = decoder.Decode(&obj.FeeXPending) + if err != nil { + return err + } + // Deserialize `FeeYPending`: + err = decoder.Decode(&obj.FeeYPending) + if err != nil { + return err + } + return nil +} + +type UserRewardInfo struct { + RewardPerTokenCompletes [2]ag_binary.Uint128 + RewardPendings [2]uint64 +} + +func (obj UserRewardInfo) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `RewardPerTokenCompletes` param: + err = encoder.Encode(obj.RewardPerTokenCompletes) + if err != nil { + return err + } + // Serialize `RewardPendings` param: + err = encoder.Encode(obj.RewardPendings) + if err != nil { + return err + } + return nil +} + +func (obj *UserRewardInfo) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `RewardPerTokenCompletes`: + err = decoder.Decode(&obj.RewardPerTokenCompletes) + if err != nil { + return err + } + // Deserialize `RewardPendings`: + err = decoder.Decode(&obj.RewardPendings) + if err != nil { + return err + } + return nil +} + +type StrategyType ag_binary.BorshEnum + +const ( + StrategyTypeSpotOneSide StrategyType = iota + StrategyTypeCurveOneSide + StrategyTypeBidAskOneSide + StrategyTypeSpotBalanced + StrategyTypeCurveBalanced + StrategyTypeBidAskBalanced + StrategyTypeSpotImBalanced + StrategyTypeCurveImBalanced + StrategyTypeBidAskImBalanced +) + +func (value StrategyType) String() string { + switch value { + case StrategyTypeSpotOneSide: + return "SpotOneSide" + case StrategyTypeCurveOneSide: + return "CurveOneSide" + case StrategyTypeBidAskOneSide: + return "BidAskOneSide" + case StrategyTypeSpotBalanced: + return "SpotBalanced" + case StrategyTypeCurveBalanced: + return "CurveBalanced" + case StrategyTypeBidAskBalanced: + return "BidAskBalanced" + case StrategyTypeSpotImBalanced: + return "SpotImBalanced" + case StrategyTypeCurveImBalanced: + return "CurveImBalanced" + case StrategyTypeBidAskImBalanced: + return "BidAskImBalanced" + default: + return "" + } +} + +type Rounding ag_binary.BorshEnum + +const ( + RoundingUp Rounding = iota + RoundingDown +) + +func (value Rounding) String() string { + switch value { + case RoundingUp: + return "Up" + case RoundingDown: + return "Down" + default: + return "" + } +} + +type ActivationType ag_binary.BorshEnum + +const ( + ActivationTypeSlot ActivationType = iota + ActivationTypeTimestamp +) + +func (value ActivationType) String() string { + switch value { + case ActivationTypeSlot: + return "Slot" + case ActivationTypeTimestamp: + return "Timestamp" + default: + return "" + } +} + +type LayoutVersion ag_binary.BorshEnum + +const ( + LayoutVersionV0 LayoutVersion = iota + LayoutVersionV1 +) + +func (value LayoutVersion) String() string { + switch value { + case LayoutVersionV0: + return "V0" + case LayoutVersionV1: + return "V1" + default: + return "" + } +} + +type PairType ag_binary.BorshEnum + +const ( + PairTypePermissionless PairType = iota + PairTypePermission + PairTypeCustomizablePermissionless +) + +func (value PairType) String() string { + switch value { + case PairTypePermissionless: + return "Permissionless" + case PairTypePermission: + return "Permission" + case PairTypeCustomizablePermissionless: + return "CustomizablePermissionless" + default: + return "" + } +} + +type PairStatus ag_binary.BorshEnum + +const ( + PairStatusEnabled PairStatus = iota + PairStatusDisabled +) + +func (value PairStatus) String() string { + switch value { + case PairStatusEnabled: + return "Enabled" + case PairStatusDisabled: + return "Disabled" + default: + return "" + } +} diff --git a/programs/meteorapools/AddBalanceLiquidity.go b/programs/meteorapools/AddBalanceLiquidity.go new file mode 100644 index 00000000..27d677c7 --- /dev/null +++ b/programs/meteorapools/AddBalanceLiquidity.go @@ -0,0 +1,506 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "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" +) + +// Deposit tokens to the pool in a balanced ratio. +type AddBalanceLiquidity struct { + PoolTokenAmount *uint64 + MaximumTokenAAmount *uint64 + MaximumTokenBAmount *uint64 + + // [0] = [WRITE] pool + // ··········· Pool account (PDA) + // + // [1] = [WRITE] lpMint + // ··········· LP token mint of the pool + // + // [2] = [WRITE] userPoolLp + // ··········· user pool lp token account. lp will be burned from this account upon success liquidity removal. + // + // [3] = [WRITE] aVaultLp + // ··········· LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. + // + // [4] = [WRITE] bVaultLp + // ··········· LP token account of vault B. Used to receive/burn the vault LP upon deposit/withdraw from the vault. + // + // [5] = [WRITE] aVault + // ··········· Vault account for token a. token a of the pool will be deposit / withdraw from this vault account. + // + // [6] = [WRITE] bVault + // ··········· Vault account for token b. token b of the pool will be deposit / withdraw from this vault account. + // + // [7] = [WRITE] aVaultLpMint + // ··········· LP token mint of vault a + // + // [8] = [WRITE] bVaultLpMint + // ··········· LP token mint of vault b + // + // [9] = [WRITE] aTokenVault + // ··········· Token vault account of vault A + // + // [10] = [WRITE] bTokenVault + // ··········· Token vault account of vault B + // + // [11] = [WRITE] userAToken + // ··········· User token A account. Token will be transfer from this account if it is add liquidity operation. Else, token will be transfer into this account. + // + // [12] = [WRITE] userBToken + // ··········· User token B account. Token will be transfer from this account if it is add liquidity operation. Else, token will be transfer into this account. + // + // [13] = [SIGNER] user + // ··········· User account. Must be owner of user_a_token, and user_b_token. + // + // [14] = [] vaultProgram + // ··········· Vault program. the pool will deposit/withdraw liquidity from the vault. + // + // [15] = [] tokenProgram + // ··········· Token program. + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewAddBalanceLiquidityInstructionBuilder creates a new `AddBalanceLiquidity` instruction builder. +func NewAddBalanceLiquidityInstructionBuilder() *AddBalanceLiquidity { + nd := &AddBalanceLiquidity{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 16), + } + return nd +} + +// SetPoolTokenAmount sets the "poolTokenAmount" parameter. +func (inst *AddBalanceLiquidity) SetPoolTokenAmount(poolTokenAmount uint64) *AddBalanceLiquidity { + inst.PoolTokenAmount = &poolTokenAmount + return inst +} + +// SetMaximumTokenAAmount sets the "maximumTokenAAmount" parameter. +func (inst *AddBalanceLiquidity) SetMaximumTokenAAmount(maximumTokenAAmount uint64) *AddBalanceLiquidity { + inst.MaximumTokenAAmount = &maximumTokenAAmount + return inst +} + +// SetMaximumTokenBAmount sets the "maximumTokenBAmount" parameter. +func (inst *AddBalanceLiquidity) SetMaximumTokenBAmount(maximumTokenBAmount uint64) *AddBalanceLiquidity { + inst.MaximumTokenBAmount = &maximumTokenBAmount + return inst +} + +// SetPoolAccount sets the "pool" account. +// Pool account (PDA) +func (inst *AddBalanceLiquidity) SetPoolAccount(pool ag_solanago.PublicKey) *AddBalanceLiquidity { + inst.AccountMetaSlice[0] = ag_solanago.Meta(pool).WRITE() + return inst +} + +// GetPoolAccount gets the "pool" account. +// Pool account (PDA) +func (inst *AddBalanceLiquidity) GetPoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetLpMintAccount sets the "lpMint" account. +// LP token mint of the pool +func (inst *AddBalanceLiquidity) SetLpMintAccount(lpMint ag_solanago.PublicKey) *AddBalanceLiquidity { + inst.AccountMetaSlice[1] = ag_solanago.Meta(lpMint).WRITE() + return inst +} + +// GetLpMintAccount gets the "lpMint" account. +// LP token mint of the pool +func (inst *AddBalanceLiquidity) GetLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetUserPoolLpAccount sets the "userPoolLp" account. +// user pool lp token account. lp will be burned from this account upon success liquidity removal. +func (inst *AddBalanceLiquidity) SetUserPoolLpAccount(userPoolLp ag_solanago.PublicKey) *AddBalanceLiquidity { + inst.AccountMetaSlice[2] = ag_solanago.Meta(userPoolLp).WRITE() + return inst +} + +// GetUserPoolLpAccount gets the "userPoolLp" account. +// user pool lp token account. lp will be burned from this account upon success liquidity removal. +func (inst *AddBalanceLiquidity) GetUserPoolLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetAVaultLpAccount sets the "aVaultLp" account. +// LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *AddBalanceLiquidity) SetAVaultLpAccount(aVaultLp ag_solanago.PublicKey) *AddBalanceLiquidity { + inst.AccountMetaSlice[3] = ag_solanago.Meta(aVaultLp).WRITE() + return inst +} + +// GetAVaultLpAccount gets the "aVaultLp" account. +// LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *AddBalanceLiquidity) GetAVaultLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetBVaultLpAccount sets the "bVaultLp" account. +// LP token account of vault B. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *AddBalanceLiquidity) SetBVaultLpAccount(bVaultLp ag_solanago.PublicKey) *AddBalanceLiquidity { + inst.AccountMetaSlice[4] = ag_solanago.Meta(bVaultLp).WRITE() + return inst +} + +// GetBVaultLpAccount gets the "bVaultLp" account. +// LP token account of vault B. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *AddBalanceLiquidity) GetBVaultLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetAVaultAccount sets the "aVault" account. +// Vault account for token a. token a of the pool will be deposit / withdraw from this vault account. +func (inst *AddBalanceLiquidity) SetAVaultAccount(aVault ag_solanago.PublicKey) *AddBalanceLiquidity { + inst.AccountMetaSlice[5] = ag_solanago.Meta(aVault).WRITE() + return inst +} + +// GetAVaultAccount gets the "aVault" account. +// Vault account for token a. token a of the pool will be deposit / withdraw from this vault account. +func (inst *AddBalanceLiquidity) GetAVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetBVaultAccount sets the "bVault" account. +// Vault account for token b. token b of the pool will be deposit / withdraw from this vault account. +func (inst *AddBalanceLiquidity) SetBVaultAccount(bVault ag_solanago.PublicKey) *AddBalanceLiquidity { + inst.AccountMetaSlice[6] = ag_solanago.Meta(bVault).WRITE() + return inst +} + +// GetBVaultAccount gets the "bVault" account. +// Vault account for token b. token b of the pool will be deposit / withdraw from this vault account. +func (inst *AddBalanceLiquidity) GetBVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetAVaultLpMintAccount sets the "aVaultLpMint" account. +// LP token mint of vault a +func (inst *AddBalanceLiquidity) SetAVaultLpMintAccount(aVaultLpMint ag_solanago.PublicKey) *AddBalanceLiquidity { + inst.AccountMetaSlice[7] = ag_solanago.Meta(aVaultLpMint).WRITE() + return inst +} + +// GetAVaultLpMintAccount gets the "aVaultLpMint" account. +// LP token mint of vault a +func (inst *AddBalanceLiquidity) GetAVaultLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetBVaultLpMintAccount sets the "bVaultLpMint" account. +// LP token mint of vault b +func (inst *AddBalanceLiquidity) SetBVaultLpMintAccount(bVaultLpMint ag_solanago.PublicKey) *AddBalanceLiquidity { + inst.AccountMetaSlice[8] = ag_solanago.Meta(bVaultLpMint).WRITE() + return inst +} + +// GetBVaultLpMintAccount gets the "bVaultLpMint" account. +// LP token mint of vault b +func (inst *AddBalanceLiquidity) GetBVaultLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetATokenVaultAccount sets the "aTokenVault" account. +// Token vault account of vault A +func (inst *AddBalanceLiquidity) SetATokenVaultAccount(aTokenVault ag_solanago.PublicKey) *AddBalanceLiquidity { + inst.AccountMetaSlice[9] = ag_solanago.Meta(aTokenVault).WRITE() + return inst +} + +// GetATokenVaultAccount gets the "aTokenVault" account. +// Token vault account of vault A +func (inst *AddBalanceLiquidity) GetATokenVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetBTokenVaultAccount sets the "bTokenVault" account. +// Token vault account of vault B +func (inst *AddBalanceLiquidity) SetBTokenVaultAccount(bTokenVault ag_solanago.PublicKey) *AddBalanceLiquidity { + inst.AccountMetaSlice[10] = ag_solanago.Meta(bTokenVault).WRITE() + return inst +} + +// GetBTokenVaultAccount gets the "bTokenVault" account. +// Token vault account of vault B +func (inst *AddBalanceLiquidity) GetBTokenVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetUserATokenAccount sets the "userAToken" account. +// User token A account. Token will be transfer from this account if it is add liquidity operation. Else, token will be transfer into this account. +func (inst *AddBalanceLiquidity) SetUserATokenAccount(userAToken ag_solanago.PublicKey) *AddBalanceLiquidity { + inst.AccountMetaSlice[11] = ag_solanago.Meta(userAToken).WRITE() + return inst +} + +// GetUserATokenAccount gets the "userAToken" account. +// User token A account. Token will be transfer from this account if it is add liquidity operation. Else, token will be transfer into this account. +func (inst *AddBalanceLiquidity) GetUserATokenAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetUserBTokenAccount sets the "userBToken" account. +// User token B account. Token will be transfer from this account if it is add liquidity operation. Else, token will be transfer into this account. +func (inst *AddBalanceLiquidity) SetUserBTokenAccount(userBToken ag_solanago.PublicKey) *AddBalanceLiquidity { + inst.AccountMetaSlice[12] = ag_solanago.Meta(userBToken).WRITE() + return inst +} + +// GetUserBTokenAccount gets the "userBToken" account. +// User token B account. Token will be transfer from this account if it is add liquidity operation. Else, token will be transfer into this account. +func (inst *AddBalanceLiquidity) GetUserBTokenAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetUserAccount sets the "user" account. +// User account. Must be owner of user_a_token, and user_b_token. +func (inst *AddBalanceLiquidity) SetUserAccount(user ag_solanago.PublicKey) *AddBalanceLiquidity { + inst.AccountMetaSlice[13] = ag_solanago.Meta(user).SIGNER() + return inst +} + +// GetUserAccount gets the "user" account. +// User account. Must be owner of user_a_token, and user_b_token. +func (inst *AddBalanceLiquidity) GetUserAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetVaultProgramAccount sets the "vaultProgram" account. +// Vault program. the pool will deposit/withdraw liquidity from the vault. +func (inst *AddBalanceLiquidity) SetVaultProgramAccount(vaultProgram ag_solanago.PublicKey) *AddBalanceLiquidity { + inst.AccountMetaSlice[14] = ag_solanago.Meta(vaultProgram) + return inst +} + +// GetVaultProgramAccount gets the "vaultProgram" account. +// Vault program. the pool will deposit/withdraw liquidity from the vault. +func (inst *AddBalanceLiquidity) GetVaultProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +// Token program. +func (inst *AddBalanceLiquidity) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *AddBalanceLiquidity { + inst.AccountMetaSlice[15] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +// Token program. +func (inst *AddBalanceLiquidity) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(15) +} + +func (inst AddBalanceLiquidity) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_AddBalanceLiquidity, + }} +} + +// 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 AddBalanceLiquidity) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *AddBalanceLiquidity) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.PoolTokenAmount == nil { + return errors.New("PoolTokenAmount parameter is not set") + } + if inst.MaximumTokenAAmount == nil { + return errors.New("MaximumTokenAAmount parameter is not set") + } + if inst.MaximumTokenBAmount == nil { + return errors.New("MaximumTokenBAmount parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Pool is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.LpMint is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.UserPoolLp is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.AVaultLp is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.BVaultLp is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.AVault is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.BVault is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.AVaultLpMint is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.BVaultLpMint is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.ATokenVault is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.BTokenVault is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.UserAToken is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.UserBToken is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.User is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.VaultProgram is not set") + } + if inst.AccountMetaSlice[15] == nil { + return errors.New("accounts.TokenProgram is not set") + } + } + return nil +} + +func (inst *AddBalanceLiquidity) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("AddBalanceLiquidity")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=3]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" PoolTokenAmount", *inst.PoolTokenAmount)) + paramsBranch.Child(ag_format.Param("MaximumTokenAAmount", *inst.MaximumTokenAAmount)) + paramsBranch.Child(ag_format.Param("MaximumTokenBAmount", *inst.MaximumTokenBAmount)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=16]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" pool", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" lpMint", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" userPoolLp", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" aVaultLp", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" bVaultLp", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" aVault", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" bVault", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta("aVaultLpMint", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta("bVaultLpMint", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" aTokenVault", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" bTokenVault", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" userAToken", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" userBToken", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" user", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta("vaultProgram", inst.AccountMetaSlice.Get(14))) + accountsBranch.Child(ag_format.Meta("tokenProgram", inst.AccountMetaSlice.Get(15))) + }) + }) + }) +} + +func (obj AddBalanceLiquidity) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `PoolTokenAmount` param: + err = encoder.Encode(obj.PoolTokenAmount) + if err != nil { + return err + } + // Serialize `MaximumTokenAAmount` param: + err = encoder.Encode(obj.MaximumTokenAAmount) + if err != nil { + return err + } + // Serialize `MaximumTokenBAmount` param: + err = encoder.Encode(obj.MaximumTokenBAmount) + if err != nil { + return err + } + return nil +} +func (obj *AddBalanceLiquidity) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `PoolTokenAmount`: + err = decoder.Decode(&obj.PoolTokenAmount) + if err != nil { + return err + } + // Deserialize `MaximumTokenAAmount`: + err = decoder.Decode(&obj.MaximumTokenAAmount) + if err != nil { + return err + } + // Deserialize `MaximumTokenBAmount`: + err = decoder.Decode(&obj.MaximumTokenBAmount) + if err != nil { + return err + } + return nil +} + +// NewAddBalanceLiquidityInstruction declares a new AddBalanceLiquidity instruction with the provided parameters and accounts. +func NewAddBalanceLiquidityInstruction( + // Parameters: + poolTokenAmount uint64, + maximumTokenAAmount uint64, + maximumTokenBAmount uint64, + // Accounts: + pool ag_solanago.PublicKey, + lpMint ag_solanago.PublicKey, + userPoolLp ag_solanago.PublicKey, + aVaultLp ag_solanago.PublicKey, + bVaultLp ag_solanago.PublicKey, + aVault ag_solanago.PublicKey, + bVault ag_solanago.PublicKey, + aVaultLpMint ag_solanago.PublicKey, + bVaultLpMint ag_solanago.PublicKey, + aTokenVault ag_solanago.PublicKey, + bTokenVault ag_solanago.PublicKey, + userAToken ag_solanago.PublicKey, + userBToken ag_solanago.PublicKey, + user ag_solanago.PublicKey, + vaultProgram ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey) *AddBalanceLiquidity { + return NewAddBalanceLiquidityInstructionBuilder(). + SetPoolTokenAmount(poolTokenAmount). + SetMaximumTokenAAmount(maximumTokenAAmount). + SetMaximumTokenBAmount(maximumTokenBAmount). + SetPoolAccount(pool). + SetLpMintAccount(lpMint). + SetUserPoolLpAccount(userPoolLp). + SetAVaultLpAccount(aVaultLp). + SetBVaultLpAccount(bVaultLp). + SetAVaultAccount(aVault). + SetBVaultAccount(bVault). + SetAVaultLpMintAccount(aVaultLpMint). + SetBVaultLpMintAccount(bVaultLpMint). + SetATokenVaultAccount(aTokenVault). + SetBTokenVaultAccount(bTokenVault). + SetUserATokenAccount(userAToken). + SetUserBTokenAccount(userBToken). + SetUserAccount(user). + SetVaultProgramAccount(vaultProgram). + SetTokenProgramAccount(tokenProgram) +} diff --git a/programs/meteorapools/AddBalanceLiquidity_test.go b/programs/meteorapools/AddBalanceLiquidity_test.go new file mode 100644 index 00000000..341b9137 --- /dev/null +++ b/programs/meteorapools/AddBalanceLiquidity_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_AddBalanceLiquidity(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("AddBalanceLiquidity"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(AddBalanceLiquidity) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(AddBalanceLiquidity) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteorapools/AddImbalanceLiquidity.go b/programs/meteorapools/AddImbalanceLiquidity.go new file mode 100644 index 00000000..de0b40b8 --- /dev/null +++ b/programs/meteorapools/AddImbalanceLiquidity.go @@ -0,0 +1,506 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "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" +) + +// Deposit tokens to the pool in an imbalance ratio. Only supported by pool with stable swap curve. +type AddImbalanceLiquidity struct { + MinimumPoolTokenAmount *uint64 + TokenAAmount *uint64 + TokenBAmount *uint64 + + // [0] = [WRITE] pool + // ··········· Pool account (PDA) + // + // [1] = [WRITE] lpMint + // ··········· LP token mint of the pool + // + // [2] = [WRITE] userPoolLp + // ··········· user pool lp token account. lp will be burned from this account upon success liquidity removal. + // + // [3] = [WRITE] aVaultLp + // ··········· LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. + // + // [4] = [WRITE] bVaultLp + // ··········· LP token account of vault B. Used to receive/burn the vault LP upon deposit/withdraw from the vault. + // + // [5] = [WRITE] aVault + // ··········· Vault account for token a. token a of the pool will be deposit / withdraw from this vault account. + // + // [6] = [WRITE] bVault + // ··········· Vault account for token b. token b of the pool will be deposit / withdraw from this vault account. + // + // [7] = [WRITE] aVaultLpMint + // ··········· LP token mint of vault a + // + // [8] = [WRITE] bVaultLpMint + // ··········· LP token mint of vault b + // + // [9] = [WRITE] aTokenVault + // ··········· Token vault account of vault A + // + // [10] = [WRITE] bTokenVault + // ··········· Token vault account of vault B + // + // [11] = [WRITE] userAToken + // ··········· User token A account. Token will be transfer from this account if it is add liquidity operation. Else, token will be transfer into this account. + // + // [12] = [WRITE] userBToken + // ··········· User token B account. Token will be transfer from this account if it is add liquidity operation. Else, token will be transfer into this account. + // + // [13] = [SIGNER] user + // ··········· User account. Must be owner of user_a_token, and user_b_token. + // + // [14] = [] vaultProgram + // ··········· Vault program. the pool will deposit/withdraw liquidity from the vault. + // + // [15] = [] tokenProgram + // ··········· Token program. + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewAddImbalanceLiquidityInstructionBuilder creates a new `AddImbalanceLiquidity` instruction builder. +func NewAddImbalanceLiquidityInstructionBuilder() *AddImbalanceLiquidity { + nd := &AddImbalanceLiquidity{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 16), + } + return nd +} + +// SetMinimumPoolTokenAmount sets the "minimumPoolTokenAmount" parameter. +func (inst *AddImbalanceLiquidity) SetMinimumPoolTokenAmount(minimumPoolTokenAmount uint64) *AddImbalanceLiquidity { + inst.MinimumPoolTokenAmount = &minimumPoolTokenAmount + return inst +} + +// SetTokenAAmount sets the "tokenAAmount" parameter. +func (inst *AddImbalanceLiquidity) SetTokenAAmount(tokenAAmount uint64) *AddImbalanceLiquidity { + inst.TokenAAmount = &tokenAAmount + return inst +} + +// SetTokenBAmount sets the "tokenBAmount" parameter. +func (inst *AddImbalanceLiquidity) SetTokenBAmount(tokenBAmount uint64) *AddImbalanceLiquidity { + inst.TokenBAmount = &tokenBAmount + return inst +} + +// SetPoolAccount sets the "pool" account. +// Pool account (PDA) +func (inst *AddImbalanceLiquidity) SetPoolAccount(pool ag_solanago.PublicKey) *AddImbalanceLiquidity { + inst.AccountMetaSlice[0] = ag_solanago.Meta(pool).WRITE() + return inst +} + +// GetPoolAccount gets the "pool" account. +// Pool account (PDA) +func (inst *AddImbalanceLiquidity) GetPoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetLpMintAccount sets the "lpMint" account. +// LP token mint of the pool +func (inst *AddImbalanceLiquidity) SetLpMintAccount(lpMint ag_solanago.PublicKey) *AddImbalanceLiquidity { + inst.AccountMetaSlice[1] = ag_solanago.Meta(lpMint).WRITE() + return inst +} + +// GetLpMintAccount gets the "lpMint" account. +// LP token mint of the pool +func (inst *AddImbalanceLiquidity) GetLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetUserPoolLpAccount sets the "userPoolLp" account. +// user pool lp token account. lp will be burned from this account upon success liquidity removal. +func (inst *AddImbalanceLiquidity) SetUserPoolLpAccount(userPoolLp ag_solanago.PublicKey) *AddImbalanceLiquidity { + inst.AccountMetaSlice[2] = ag_solanago.Meta(userPoolLp).WRITE() + return inst +} + +// GetUserPoolLpAccount gets the "userPoolLp" account. +// user pool lp token account. lp will be burned from this account upon success liquidity removal. +func (inst *AddImbalanceLiquidity) GetUserPoolLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetAVaultLpAccount sets the "aVaultLp" account. +// LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *AddImbalanceLiquidity) SetAVaultLpAccount(aVaultLp ag_solanago.PublicKey) *AddImbalanceLiquidity { + inst.AccountMetaSlice[3] = ag_solanago.Meta(aVaultLp).WRITE() + return inst +} + +// GetAVaultLpAccount gets the "aVaultLp" account. +// LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *AddImbalanceLiquidity) GetAVaultLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetBVaultLpAccount sets the "bVaultLp" account. +// LP token account of vault B. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *AddImbalanceLiquidity) SetBVaultLpAccount(bVaultLp ag_solanago.PublicKey) *AddImbalanceLiquidity { + inst.AccountMetaSlice[4] = ag_solanago.Meta(bVaultLp).WRITE() + return inst +} + +// GetBVaultLpAccount gets the "bVaultLp" account. +// LP token account of vault B. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *AddImbalanceLiquidity) GetBVaultLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetAVaultAccount sets the "aVault" account. +// Vault account for token a. token a of the pool will be deposit / withdraw from this vault account. +func (inst *AddImbalanceLiquidity) SetAVaultAccount(aVault ag_solanago.PublicKey) *AddImbalanceLiquidity { + inst.AccountMetaSlice[5] = ag_solanago.Meta(aVault).WRITE() + return inst +} + +// GetAVaultAccount gets the "aVault" account. +// Vault account for token a. token a of the pool will be deposit / withdraw from this vault account. +func (inst *AddImbalanceLiquidity) GetAVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetBVaultAccount sets the "bVault" account. +// Vault account for token b. token b of the pool will be deposit / withdraw from this vault account. +func (inst *AddImbalanceLiquidity) SetBVaultAccount(bVault ag_solanago.PublicKey) *AddImbalanceLiquidity { + inst.AccountMetaSlice[6] = ag_solanago.Meta(bVault).WRITE() + return inst +} + +// GetBVaultAccount gets the "bVault" account. +// Vault account for token b. token b of the pool will be deposit / withdraw from this vault account. +func (inst *AddImbalanceLiquidity) GetBVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetAVaultLpMintAccount sets the "aVaultLpMint" account. +// LP token mint of vault a +func (inst *AddImbalanceLiquidity) SetAVaultLpMintAccount(aVaultLpMint ag_solanago.PublicKey) *AddImbalanceLiquidity { + inst.AccountMetaSlice[7] = ag_solanago.Meta(aVaultLpMint).WRITE() + return inst +} + +// GetAVaultLpMintAccount gets the "aVaultLpMint" account. +// LP token mint of vault a +func (inst *AddImbalanceLiquidity) GetAVaultLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetBVaultLpMintAccount sets the "bVaultLpMint" account. +// LP token mint of vault b +func (inst *AddImbalanceLiquidity) SetBVaultLpMintAccount(bVaultLpMint ag_solanago.PublicKey) *AddImbalanceLiquidity { + inst.AccountMetaSlice[8] = ag_solanago.Meta(bVaultLpMint).WRITE() + return inst +} + +// GetBVaultLpMintAccount gets the "bVaultLpMint" account. +// LP token mint of vault b +func (inst *AddImbalanceLiquidity) GetBVaultLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetATokenVaultAccount sets the "aTokenVault" account. +// Token vault account of vault A +func (inst *AddImbalanceLiquidity) SetATokenVaultAccount(aTokenVault ag_solanago.PublicKey) *AddImbalanceLiquidity { + inst.AccountMetaSlice[9] = ag_solanago.Meta(aTokenVault).WRITE() + return inst +} + +// GetATokenVaultAccount gets the "aTokenVault" account. +// Token vault account of vault A +func (inst *AddImbalanceLiquidity) GetATokenVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetBTokenVaultAccount sets the "bTokenVault" account. +// Token vault account of vault B +func (inst *AddImbalanceLiquidity) SetBTokenVaultAccount(bTokenVault ag_solanago.PublicKey) *AddImbalanceLiquidity { + inst.AccountMetaSlice[10] = ag_solanago.Meta(bTokenVault).WRITE() + return inst +} + +// GetBTokenVaultAccount gets the "bTokenVault" account. +// Token vault account of vault B +func (inst *AddImbalanceLiquidity) GetBTokenVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetUserATokenAccount sets the "userAToken" account. +// User token A account. Token will be transfer from this account if it is add liquidity operation. Else, token will be transfer into this account. +func (inst *AddImbalanceLiquidity) SetUserATokenAccount(userAToken ag_solanago.PublicKey) *AddImbalanceLiquidity { + inst.AccountMetaSlice[11] = ag_solanago.Meta(userAToken).WRITE() + return inst +} + +// GetUserATokenAccount gets the "userAToken" account. +// User token A account. Token will be transfer from this account if it is add liquidity operation. Else, token will be transfer into this account. +func (inst *AddImbalanceLiquidity) GetUserATokenAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetUserBTokenAccount sets the "userBToken" account. +// User token B account. Token will be transfer from this account if it is add liquidity operation. Else, token will be transfer into this account. +func (inst *AddImbalanceLiquidity) SetUserBTokenAccount(userBToken ag_solanago.PublicKey) *AddImbalanceLiquidity { + inst.AccountMetaSlice[12] = ag_solanago.Meta(userBToken).WRITE() + return inst +} + +// GetUserBTokenAccount gets the "userBToken" account. +// User token B account. Token will be transfer from this account if it is add liquidity operation. Else, token will be transfer into this account. +func (inst *AddImbalanceLiquidity) GetUserBTokenAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetUserAccount sets the "user" account. +// User account. Must be owner of user_a_token, and user_b_token. +func (inst *AddImbalanceLiquidity) SetUserAccount(user ag_solanago.PublicKey) *AddImbalanceLiquidity { + inst.AccountMetaSlice[13] = ag_solanago.Meta(user).SIGNER() + return inst +} + +// GetUserAccount gets the "user" account. +// User account. Must be owner of user_a_token, and user_b_token. +func (inst *AddImbalanceLiquidity) GetUserAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetVaultProgramAccount sets the "vaultProgram" account. +// Vault program. the pool will deposit/withdraw liquidity from the vault. +func (inst *AddImbalanceLiquidity) SetVaultProgramAccount(vaultProgram ag_solanago.PublicKey) *AddImbalanceLiquidity { + inst.AccountMetaSlice[14] = ag_solanago.Meta(vaultProgram) + return inst +} + +// GetVaultProgramAccount gets the "vaultProgram" account. +// Vault program. the pool will deposit/withdraw liquidity from the vault. +func (inst *AddImbalanceLiquidity) GetVaultProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +// Token program. +func (inst *AddImbalanceLiquidity) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *AddImbalanceLiquidity { + inst.AccountMetaSlice[15] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +// Token program. +func (inst *AddImbalanceLiquidity) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(15) +} + +func (inst AddImbalanceLiquidity) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_AddImbalanceLiquidity, + }} +} + +// 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 AddImbalanceLiquidity) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *AddImbalanceLiquidity) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.MinimumPoolTokenAmount == nil { + return errors.New("MinimumPoolTokenAmount parameter is not set") + } + if inst.TokenAAmount == nil { + return errors.New("TokenAAmount parameter is not set") + } + if inst.TokenBAmount == nil { + return errors.New("TokenBAmount parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Pool is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.LpMint is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.UserPoolLp is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.AVaultLp is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.BVaultLp is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.AVault is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.BVault is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.AVaultLpMint is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.BVaultLpMint is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.ATokenVault is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.BTokenVault is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.UserAToken is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.UserBToken is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.User is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.VaultProgram is not set") + } + if inst.AccountMetaSlice[15] == nil { + return errors.New("accounts.TokenProgram is not set") + } + } + return nil +} + +func (inst *AddImbalanceLiquidity) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("AddImbalanceLiquidity")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=3]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param("MinimumPoolTokenAmount", *inst.MinimumPoolTokenAmount)) + paramsBranch.Child(ag_format.Param(" TokenAAmount", *inst.TokenAAmount)) + paramsBranch.Child(ag_format.Param(" TokenBAmount", *inst.TokenBAmount)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=16]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" pool", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" lpMint", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" userPoolLp", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" aVaultLp", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" bVaultLp", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" aVault", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" bVault", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta("aVaultLpMint", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta("bVaultLpMint", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" aTokenVault", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" bTokenVault", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" userAToken", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" userBToken", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" user", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta("vaultProgram", inst.AccountMetaSlice.Get(14))) + accountsBranch.Child(ag_format.Meta("tokenProgram", inst.AccountMetaSlice.Get(15))) + }) + }) + }) +} + +func (obj AddImbalanceLiquidity) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `MinimumPoolTokenAmount` param: + err = encoder.Encode(obj.MinimumPoolTokenAmount) + if err != nil { + return err + } + // Serialize `TokenAAmount` param: + err = encoder.Encode(obj.TokenAAmount) + if err != nil { + return err + } + // Serialize `TokenBAmount` param: + err = encoder.Encode(obj.TokenBAmount) + if err != nil { + return err + } + return nil +} +func (obj *AddImbalanceLiquidity) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `MinimumPoolTokenAmount`: + err = decoder.Decode(&obj.MinimumPoolTokenAmount) + if err != nil { + return err + } + // Deserialize `TokenAAmount`: + err = decoder.Decode(&obj.TokenAAmount) + if err != nil { + return err + } + // Deserialize `TokenBAmount`: + err = decoder.Decode(&obj.TokenBAmount) + if err != nil { + return err + } + return nil +} + +// NewAddImbalanceLiquidityInstruction declares a new AddImbalanceLiquidity instruction with the provided parameters and accounts. +func NewAddImbalanceLiquidityInstruction( + // Parameters: + minimumPoolTokenAmount uint64, + tokenAAmount uint64, + tokenBAmount uint64, + // Accounts: + pool ag_solanago.PublicKey, + lpMint ag_solanago.PublicKey, + userPoolLp ag_solanago.PublicKey, + aVaultLp ag_solanago.PublicKey, + bVaultLp ag_solanago.PublicKey, + aVault ag_solanago.PublicKey, + bVault ag_solanago.PublicKey, + aVaultLpMint ag_solanago.PublicKey, + bVaultLpMint ag_solanago.PublicKey, + aTokenVault ag_solanago.PublicKey, + bTokenVault ag_solanago.PublicKey, + userAToken ag_solanago.PublicKey, + userBToken ag_solanago.PublicKey, + user ag_solanago.PublicKey, + vaultProgram ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey) *AddImbalanceLiquidity { + return NewAddImbalanceLiquidityInstructionBuilder(). + SetMinimumPoolTokenAmount(minimumPoolTokenAmount). + SetTokenAAmount(tokenAAmount). + SetTokenBAmount(tokenBAmount). + SetPoolAccount(pool). + SetLpMintAccount(lpMint). + SetUserPoolLpAccount(userPoolLp). + SetAVaultLpAccount(aVaultLp). + SetBVaultLpAccount(bVaultLp). + SetAVaultAccount(aVault). + SetBVaultAccount(bVault). + SetAVaultLpMintAccount(aVaultLpMint). + SetBVaultLpMintAccount(bVaultLpMint). + SetATokenVaultAccount(aTokenVault). + SetBTokenVaultAccount(bTokenVault). + SetUserATokenAccount(userAToken). + SetUserBTokenAccount(userBToken). + SetUserAccount(user). + SetVaultProgramAccount(vaultProgram). + SetTokenProgramAccount(tokenProgram) +} diff --git a/programs/meteorapools/AddImbalanceLiquidity_test.go b/programs/meteorapools/AddImbalanceLiquidity_test.go new file mode 100644 index 00000000..d4290b61 --- /dev/null +++ b/programs/meteorapools/AddImbalanceLiquidity_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_AddImbalanceLiquidity(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("AddImbalanceLiquidity"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(AddImbalanceLiquidity) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(AddImbalanceLiquidity) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteorapools/BootstrapLiquidity.go b/programs/meteorapools/BootstrapLiquidity.go new file mode 100644 index 00000000..7d761c99 --- /dev/null +++ b/programs/meteorapools/BootstrapLiquidity.go @@ -0,0 +1,483 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "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" +) + +// Bootstrap the pool when liquidity is depleted. +type BootstrapLiquidity struct { + TokenAAmount *uint64 + TokenBAmount *uint64 + + // [0] = [WRITE] pool + // ··········· Pool account (PDA) + // + // [1] = [WRITE] lpMint + // ··········· LP token mint of the pool + // + // [2] = [WRITE] userPoolLp + // ··········· user pool lp token account. lp will be burned from this account upon success liquidity removal. + // + // [3] = [WRITE] aVaultLp + // ··········· LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. + // + // [4] = [WRITE] bVaultLp + // ··········· LP token account of vault B. Used to receive/burn the vault LP upon deposit/withdraw from the vault. + // + // [5] = [WRITE] aVault + // ··········· Vault account for token a. token a of the pool will be deposit / withdraw from this vault account. + // + // [6] = [WRITE] bVault + // ··········· Vault account for token b. token b of the pool will be deposit / withdraw from this vault account. + // + // [7] = [WRITE] aVaultLpMint + // ··········· LP token mint of vault a + // + // [8] = [WRITE] bVaultLpMint + // ··········· LP token mint of vault b + // + // [9] = [WRITE] aTokenVault + // ··········· Token vault account of vault A + // + // [10] = [WRITE] bTokenVault + // ··········· Token vault account of vault B + // + // [11] = [WRITE] userAToken + // ··········· User token A account. Token will be transfer from this account if it is add liquidity operation. Else, token will be transfer into this account. + // + // [12] = [WRITE] userBToken + // ··········· User token B account. Token will be transfer from this account if it is add liquidity operation. Else, token will be transfer into this account. + // + // [13] = [SIGNER] user + // ··········· User account. Must be owner of user_a_token, and user_b_token. + // + // [14] = [] vaultProgram + // ··········· Vault program. the pool will deposit/withdraw liquidity from the vault. + // + // [15] = [] tokenProgram + // ··········· Token program. + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewBootstrapLiquidityInstructionBuilder creates a new `BootstrapLiquidity` instruction builder. +func NewBootstrapLiquidityInstructionBuilder() *BootstrapLiquidity { + nd := &BootstrapLiquidity{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 16), + } + return nd +} + +// SetTokenAAmount sets the "tokenAAmount" parameter. +func (inst *BootstrapLiquidity) SetTokenAAmount(tokenAAmount uint64) *BootstrapLiquidity { + inst.TokenAAmount = &tokenAAmount + return inst +} + +// SetTokenBAmount sets the "tokenBAmount" parameter. +func (inst *BootstrapLiquidity) SetTokenBAmount(tokenBAmount uint64) *BootstrapLiquidity { + inst.TokenBAmount = &tokenBAmount + return inst +} + +// SetPoolAccount sets the "pool" account. +// Pool account (PDA) +func (inst *BootstrapLiquidity) SetPoolAccount(pool ag_solanago.PublicKey) *BootstrapLiquidity { + inst.AccountMetaSlice[0] = ag_solanago.Meta(pool).WRITE() + return inst +} + +// GetPoolAccount gets the "pool" account. +// Pool account (PDA) +func (inst *BootstrapLiquidity) GetPoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetLpMintAccount sets the "lpMint" account. +// LP token mint of the pool +func (inst *BootstrapLiquidity) SetLpMintAccount(lpMint ag_solanago.PublicKey) *BootstrapLiquidity { + inst.AccountMetaSlice[1] = ag_solanago.Meta(lpMint).WRITE() + return inst +} + +// GetLpMintAccount gets the "lpMint" account. +// LP token mint of the pool +func (inst *BootstrapLiquidity) GetLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetUserPoolLpAccount sets the "userPoolLp" account. +// user pool lp token account. lp will be burned from this account upon success liquidity removal. +func (inst *BootstrapLiquidity) SetUserPoolLpAccount(userPoolLp ag_solanago.PublicKey) *BootstrapLiquidity { + inst.AccountMetaSlice[2] = ag_solanago.Meta(userPoolLp).WRITE() + return inst +} + +// GetUserPoolLpAccount gets the "userPoolLp" account. +// user pool lp token account. lp will be burned from this account upon success liquidity removal. +func (inst *BootstrapLiquidity) GetUserPoolLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetAVaultLpAccount sets the "aVaultLp" account. +// LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *BootstrapLiquidity) SetAVaultLpAccount(aVaultLp ag_solanago.PublicKey) *BootstrapLiquidity { + inst.AccountMetaSlice[3] = ag_solanago.Meta(aVaultLp).WRITE() + return inst +} + +// GetAVaultLpAccount gets the "aVaultLp" account. +// LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *BootstrapLiquidity) GetAVaultLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetBVaultLpAccount sets the "bVaultLp" account. +// LP token account of vault B. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *BootstrapLiquidity) SetBVaultLpAccount(bVaultLp ag_solanago.PublicKey) *BootstrapLiquidity { + inst.AccountMetaSlice[4] = ag_solanago.Meta(bVaultLp).WRITE() + return inst +} + +// GetBVaultLpAccount gets the "bVaultLp" account. +// LP token account of vault B. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *BootstrapLiquidity) GetBVaultLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetAVaultAccount sets the "aVault" account. +// Vault account for token a. token a of the pool will be deposit / withdraw from this vault account. +func (inst *BootstrapLiquidity) SetAVaultAccount(aVault ag_solanago.PublicKey) *BootstrapLiquidity { + inst.AccountMetaSlice[5] = ag_solanago.Meta(aVault).WRITE() + return inst +} + +// GetAVaultAccount gets the "aVault" account. +// Vault account for token a. token a of the pool will be deposit / withdraw from this vault account. +func (inst *BootstrapLiquidity) GetAVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetBVaultAccount sets the "bVault" account. +// Vault account for token b. token b of the pool will be deposit / withdraw from this vault account. +func (inst *BootstrapLiquidity) SetBVaultAccount(bVault ag_solanago.PublicKey) *BootstrapLiquidity { + inst.AccountMetaSlice[6] = ag_solanago.Meta(bVault).WRITE() + return inst +} + +// GetBVaultAccount gets the "bVault" account. +// Vault account for token b. token b of the pool will be deposit / withdraw from this vault account. +func (inst *BootstrapLiquidity) GetBVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetAVaultLpMintAccount sets the "aVaultLpMint" account. +// LP token mint of vault a +func (inst *BootstrapLiquidity) SetAVaultLpMintAccount(aVaultLpMint ag_solanago.PublicKey) *BootstrapLiquidity { + inst.AccountMetaSlice[7] = ag_solanago.Meta(aVaultLpMint).WRITE() + return inst +} + +// GetAVaultLpMintAccount gets the "aVaultLpMint" account. +// LP token mint of vault a +func (inst *BootstrapLiquidity) GetAVaultLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetBVaultLpMintAccount sets the "bVaultLpMint" account. +// LP token mint of vault b +func (inst *BootstrapLiquidity) SetBVaultLpMintAccount(bVaultLpMint ag_solanago.PublicKey) *BootstrapLiquidity { + inst.AccountMetaSlice[8] = ag_solanago.Meta(bVaultLpMint).WRITE() + return inst +} + +// GetBVaultLpMintAccount gets the "bVaultLpMint" account. +// LP token mint of vault b +func (inst *BootstrapLiquidity) GetBVaultLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetATokenVaultAccount sets the "aTokenVault" account. +// Token vault account of vault A +func (inst *BootstrapLiquidity) SetATokenVaultAccount(aTokenVault ag_solanago.PublicKey) *BootstrapLiquidity { + inst.AccountMetaSlice[9] = ag_solanago.Meta(aTokenVault).WRITE() + return inst +} + +// GetATokenVaultAccount gets the "aTokenVault" account. +// Token vault account of vault A +func (inst *BootstrapLiquidity) GetATokenVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetBTokenVaultAccount sets the "bTokenVault" account. +// Token vault account of vault B +func (inst *BootstrapLiquidity) SetBTokenVaultAccount(bTokenVault ag_solanago.PublicKey) *BootstrapLiquidity { + inst.AccountMetaSlice[10] = ag_solanago.Meta(bTokenVault).WRITE() + return inst +} + +// GetBTokenVaultAccount gets the "bTokenVault" account. +// Token vault account of vault B +func (inst *BootstrapLiquidity) GetBTokenVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetUserATokenAccount sets the "userAToken" account. +// User token A account. Token will be transfer from this account if it is add liquidity operation. Else, token will be transfer into this account. +func (inst *BootstrapLiquidity) SetUserATokenAccount(userAToken ag_solanago.PublicKey) *BootstrapLiquidity { + inst.AccountMetaSlice[11] = ag_solanago.Meta(userAToken).WRITE() + return inst +} + +// GetUserATokenAccount gets the "userAToken" account. +// User token A account. Token will be transfer from this account if it is add liquidity operation. Else, token will be transfer into this account. +func (inst *BootstrapLiquidity) GetUserATokenAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetUserBTokenAccount sets the "userBToken" account. +// User token B account. Token will be transfer from this account if it is add liquidity operation. Else, token will be transfer into this account. +func (inst *BootstrapLiquidity) SetUserBTokenAccount(userBToken ag_solanago.PublicKey) *BootstrapLiquidity { + inst.AccountMetaSlice[12] = ag_solanago.Meta(userBToken).WRITE() + return inst +} + +// GetUserBTokenAccount gets the "userBToken" account. +// User token B account. Token will be transfer from this account if it is add liquidity operation. Else, token will be transfer into this account. +func (inst *BootstrapLiquidity) GetUserBTokenAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetUserAccount sets the "user" account. +// User account. Must be owner of user_a_token, and user_b_token. +func (inst *BootstrapLiquidity) SetUserAccount(user ag_solanago.PublicKey) *BootstrapLiquidity { + inst.AccountMetaSlice[13] = ag_solanago.Meta(user).SIGNER() + return inst +} + +// GetUserAccount gets the "user" account. +// User account. Must be owner of user_a_token, and user_b_token. +func (inst *BootstrapLiquidity) GetUserAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetVaultProgramAccount sets the "vaultProgram" account. +// Vault program. the pool will deposit/withdraw liquidity from the vault. +func (inst *BootstrapLiquidity) SetVaultProgramAccount(vaultProgram ag_solanago.PublicKey) *BootstrapLiquidity { + inst.AccountMetaSlice[14] = ag_solanago.Meta(vaultProgram) + return inst +} + +// GetVaultProgramAccount gets the "vaultProgram" account. +// Vault program. the pool will deposit/withdraw liquidity from the vault. +func (inst *BootstrapLiquidity) GetVaultProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +// Token program. +func (inst *BootstrapLiquidity) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *BootstrapLiquidity { + inst.AccountMetaSlice[15] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +// Token program. +func (inst *BootstrapLiquidity) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(15) +} + +func (inst BootstrapLiquidity) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_BootstrapLiquidity, + }} +} + +// 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 BootstrapLiquidity) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *BootstrapLiquidity) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.TokenAAmount == nil { + return errors.New("TokenAAmount parameter is not set") + } + if inst.TokenBAmount == nil { + return errors.New("TokenBAmount parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Pool is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.LpMint is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.UserPoolLp is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.AVaultLp is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.BVaultLp is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.AVault is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.BVault is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.AVaultLpMint is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.BVaultLpMint is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.ATokenVault is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.BTokenVault is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.UserAToken is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.UserBToken is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.User is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.VaultProgram is not set") + } + if inst.AccountMetaSlice[15] == nil { + return errors.New("accounts.TokenProgram is not set") + } + } + return nil +} + +func (inst *BootstrapLiquidity) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("BootstrapLiquidity")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=2]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param("TokenAAmount", *inst.TokenAAmount)) + paramsBranch.Child(ag_format.Param("TokenBAmount", *inst.TokenBAmount)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=16]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" pool", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" lpMint", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" userPoolLp", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" aVaultLp", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" bVaultLp", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" aVault", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" bVault", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta("aVaultLpMint", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta("bVaultLpMint", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" aTokenVault", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" bTokenVault", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" userAToken", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" userBToken", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" user", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta("vaultProgram", inst.AccountMetaSlice.Get(14))) + accountsBranch.Child(ag_format.Meta("tokenProgram", inst.AccountMetaSlice.Get(15))) + }) + }) + }) +} + +func (obj BootstrapLiquidity) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `TokenAAmount` param: + err = encoder.Encode(obj.TokenAAmount) + if err != nil { + return err + } + // Serialize `TokenBAmount` param: + err = encoder.Encode(obj.TokenBAmount) + if err != nil { + return err + } + return nil +} +func (obj *BootstrapLiquidity) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `TokenAAmount`: + err = decoder.Decode(&obj.TokenAAmount) + if err != nil { + return err + } + // Deserialize `TokenBAmount`: + err = decoder.Decode(&obj.TokenBAmount) + if err != nil { + return err + } + return nil +} + +// NewBootstrapLiquidityInstruction declares a new BootstrapLiquidity instruction with the provided parameters and accounts. +func NewBootstrapLiquidityInstruction( + // Parameters: + tokenAAmount uint64, + tokenBAmount uint64, + // Accounts: + pool ag_solanago.PublicKey, + lpMint ag_solanago.PublicKey, + userPoolLp ag_solanago.PublicKey, + aVaultLp ag_solanago.PublicKey, + bVaultLp ag_solanago.PublicKey, + aVault ag_solanago.PublicKey, + bVault ag_solanago.PublicKey, + aVaultLpMint ag_solanago.PublicKey, + bVaultLpMint ag_solanago.PublicKey, + aTokenVault ag_solanago.PublicKey, + bTokenVault ag_solanago.PublicKey, + userAToken ag_solanago.PublicKey, + userBToken ag_solanago.PublicKey, + user ag_solanago.PublicKey, + vaultProgram ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey) *BootstrapLiquidity { + return NewBootstrapLiquidityInstructionBuilder(). + SetTokenAAmount(tokenAAmount). + SetTokenBAmount(tokenBAmount). + SetPoolAccount(pool). + SetLpMintAccount(lpMint). + SetUserPoolLpAccount(userPoolLp). + SetAVaultLpAccount(aVaultLp). + SetBVaultLpAccount(bVaultLp). + SetAVaultAccount(aVault). + SetBVaultAccount(bVault). + SetAVaultLpMintAccount(aVaultLpMint). + SetBVaultLpMintAccount(bVaultLpMint). + SetATokenVaultAccount(aTokenVault). + SetBTokenVaultAccount(bTokenVault). + SetUserATokenAccount(userAToken). + SetUserBTokenAccount(userBToken). + SetUserAccount(user). + SetVaultProgramAccount(vaultProgram). + SetTokenProgramAccount(tokenProgram) +} diff --git a/programs/meteorapools/BootstrapLiquidity_test.go b/programs/meteorapools/BootstrapLiquidity_test.go new file mode 100644 index 00000000..931e0b39 --- /dev/null +++ b/programs/meteorapools/BootstrapLiquidity_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_BootstrapLiquidity(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("BootstrapLiquidity"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(BootstrapLiquidity) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(BootstrapLiquidity) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteorapools/ClaimFee.go b/programs/meteorapools/ClaimFee.go new file mode 100644 index 00000000..19c08420 --- /dev/null +++ b/programs/meteorapools/ClaimFee.go @@ -0,0 +1,504 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "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" +) + +// Claim fee +type ClaimFee struct { + MaxAmount *uint64 + + // [0] = [WRITE] pool + // ··········· Pool account + // + // [1] = [WRITE] lpMint + // ··········· LP token mint of the pool + // + // [2] = [WRITE] lockEscrow + // ··········· Lock account + // + // [3] = [WRITE, SIGNER] owner + // ··········· Owner of lock account + // + // [4] = [WRITE] sourceTokens + // ··········· owner lp token account + // + // [5] = [WRITE] escrowVault + // ··········· Escrow vault + // + // [6] = [] tokenProgram + // ··········· Token program. + // + // [7] = [WRITE] aTokenVault + // ··········· Token vault account of vault A + // + // [8] = [WRITE] bTokenVault + // ··········· Token vault account of vault B + // + // [9] = [WRITE] aVault + // ··········· Vault account for token a. token a of the pool will be deposit / withdraw from this vault account. + // + // [10] = [WRITE] bVault + // ··········· Vault account for token b. token b of the pool will be deposit / withdraw from this vault account. + // + // [11] = [WRITE] aVaultLp + // ··········· LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. + // + // [12] = [WRITE] bVaultLp + // ··········· LP token account of vault B. Used to receive/burn the vault LP upon deposit/withdraw from the vault. + // + // [13] = [WRITE] aVaultLpMint + // ··········· LP token mint of vault a + // + // [14] = [WRITE] bVaultLpMint + // ··········· LP token mint of vault b + // + // [15] = [WRITE] userAToken + // ··········· User token A account. Token will be transfer from this account if it is add liquidity operation. Else, token will be transfer into this account. + // + // [16] = [WRITE] userBToken + // ··········· User token B account. Token will be transfer from this account if it is add liquidity operation. Else, token will be transfer into this account. + // + // [17] = [] vaultProgram + // ··········· Vault program. the pool will deposit/withdraw liquidity from the vault. + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewClaimFeeInstructionBuilder creates a new `ClaimFee` instruction builder. +func NewClaimFeeInstructionBuilder() *ClaimFee { + nd := &ClaimFee{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 18), + } + return nd +} + +// SetMaxAmount sets the "maxAmount" parameter. +func (inst *ClaimFee) SetMaxAmount(maxAmount uint64) *ClaimFee { + inst.MaxAmount = &maxAmount + return inst +} + +// SetPoolAccount sets the "pool" account. +// Pool account +func (inst *ClaimFee) SetPoolAccount(pool ag_solanago.PublicKey) *ClaimFee { + inst.AccountMetaSlice[0] = ag_solanago.Meta(pool).WRITE() + return inst +} + +// GetPoolAccount gets the "pool" account. +// Pool account +func (inst *ClaimFee) GetPoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetLpMintAccount sets the "lpMint" account. +// LP token mint of the pool +func (inst *ClaimFee) SetLpMintAccount(lpMint ag_solanago.PublicKey) *ClaimFee { + inst.AccountMetaSlice[1] = ag_solanago.Meta(lpMint).WRITE() + return inst +} + +// GetLpMintAccount gets the "lpMint" account. +// LP token mint of the pool +func (inst *ClaimFee) GetLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetLockEscrowAccount sets the "lockEscrow" account. +// Lock account +func (inst *ClaimFee) SetLockEscrowAccount(lockEscrow ag_solanago.PublicKey) *ClaimFee { + inst.AccountMetaSlice[2] = ag_solanago.Meta(lockEscrow).WRITE() + return inst +} + +// GetLockEscrowAccount gets the "lockEscrow" account. +// Lock account +func (inst *ClaimFee) GetLockEscrowAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetOwnerAccount sets the "owner" account. +// Owner of lock account +func (inst *ClaimFee) SetOwnerAccount(owner ag_solanago.PublicKey) *ClaimFee { + inst.AccountMetaSlice[3] = ag_solanago.Meta(owner).WRITE().SIGNER() + return inst +} + +// GetOwnerAccount gets the "owner" account. +// Owner of lock account +func (inst *ClaimFee) GetOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetSourceTokensAccount sets the "sourceTokens" account. +// owner lp token account +func (inst *ClaimFee) SetSourceTokensAccount(sourceTokens ag_solanago.PublicKey) *ClaimFee { + inst.AccountMetaSlice[4] = ag_solanago.Meta(sourceTokens).WRITE() + return inst +} + +// GetSourceTokensAccount gets the "sourceTokens" account. +// owner lp token account +func (inst *ClaimFee) GetSourceTokensAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetEscrowVaultAccount sets the "escrowVault" account. +// Escrow vault +func (inst *ClaimFee) SetEscrowVaultAccount(escrowVault ag_solanago.PublicKey) *ClaimFee { + inst.AccountMetaSlice[5] = ag_solanago.Meta(escrowVault).WRITE() + return inst +} + +// GetEscrowVaultAccount gets the "escrowVault" account. +// Escrow vault +func (inst *ClaimFee) GetEscrowVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +// Token program. +func (inst *ClaimFee) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *ClaimFee { + inst.AccountMetaSlice[6] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +// Token program. +func (inst *ClaimFee) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetATokenVaultAccount sets the "aTokenVault" account. +// Token vault account of vault A +func (inst *ClaimFee) SetATokenVaultAccount(aTokenVault ag_solanago.PublicKey) *ClaimFee { + inst.AccountMetaSlice[7] = ag_solanago.Meta(aTokenVault).WRITE() + return inst +} + +// GetATokenVaultAccount gets the "aTokenVault" account. +// Token vault account of vault A +func (inst *ClaimFee) GetATokenVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetBTokenVaultAccount sets the "bTokenVault" account. +// Token vault account of vault B +func (inst *ClaimFee) SetBTokenVaultAccount(bTokenVault ag_solanago.PublicKey) *ClaimFee { + inst.AccountMetaSlice[8] = ag_solanago.Meta(bTokenVault).WRITE() + return inst +} + +// GetBTokenVaultAccount gets the "bTokenVault" account. +// Token vault account of vault B +func (inst *ClaimFee) GetBTokenVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetAVaultAccount sets the "aVault" account. +// Vault account for token a. token a of the pool will be deposit / withdraw from this vault account. +func (inst *ClaimFee) SetAVaultAccount(aVault ag_solanago.PublicKey) *ClaimFee { + inst.AccountMetaSlice[9] = ag_solanago.Meta(aVault).WRITE() + return inst +} + +// GetAVaultAccount gets the "aVault" account. +// Vault account for token a. token a of the pool will be deposit / withdraw from this vault account. +func (inst *ClaimFee) GetAVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetBVaultAccount sets the "bVault" account. +// Vault account for token b. token b of the pool will be deposit / withdraw from this vault account. +func (inst *ClaimFee) SetBVaultAccount(bVault ag_solanago.PublicKey) *ClaimFee { + inst.AccountMetaSlice[10] = ag_solanago.Meta(bVault).WRITE() + return inst +} + +// GetBVaultAccount gets the "bVault" account. +// Vault account for token b. token b of the pool will be deposit / withdraw from this vault account. +func (inst *ClaimFee) GetBVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetAVaultLpAccount sets the "aVaultLp" account. +// LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *ClaimFee) SetAVaultLpAccount(aVaultLp ag_solanago.PublicKey) *ClaimFee { + inst.AccountMetaSlice[11] = ag_solanago.Meta(aVaultLp).WRITE() + return inst +} + +// GetAVaultLpAccount gets the "aVaultLp" account. +// LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *ClaimFee) GetAVaultLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetBVaultLpAccount sets the "bVaultLp" account. +// LP token account of vault B. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *ClaimFee) SetBVaultLpAccount(bVaultLp ag_solanago.PublicKey) *ClaimFee { + inst.AccountMetaSlice[12] = ag_solanago.Meta(bVaultLp).WRITE() + return inst +} + +// GetBVaultLpAccount gets the "bVaultLp" account. +// LP token account of vault B. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *ClaimFee) GetBVaultLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetAVaultLpMintAccount sets the "aVaultLpMint" account. +// LP token mint of vault a +func (inst *ClaimFee) SetAVaultLpMintAccount(aVaultLpMint ag_solanago.PublicKey) *ClaimFee { + inst.AccountMetaSlice[13] = ag_solanago.Meta(aVaultLpMint).WRITE() + return inst +} + +// GetAVaultLpMintAccount gets the "aVaultLpMint" account. +// LP token mint of vault a +func (inst *ClaimFee) GetAVaultLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetBVaultLpMintAccount sets the "bVaultLpMint" account. +// LP token mint of vault b +func (inst *ClaimFee) SetBVaultLpMintAccount(bVaultLpMint ag_solanago.PublicKey) *ClaimFee { + inst.AccountMetaSlice[14] = ag_solanago.Meta(bVaultLpMint).WRITE() + return inst +} + +// GetBVaultLpMintAccount gets the "bVaultLpMint" account. +// LP token mint of vault b +func (inst *ClaimFee) GetBVaultLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +// SetUserATokenAccount sets the "userAToken" account. +// User token A account. Token will be transfer from this account if it is add liquidity operation. Else, token will be transfer into this account. +func (inst *ClaimFee) SetUserATokenAccount(userAToken ag_solanago.PublicKey) *ClaimFee { + inst.AccountMetaSlice[15] = ag_solanago.Meta(userAToken).WRITE() + return inst +} + +// GetUserATokenAccount gets the "userAToken" account. +// User token A account. Token will be transfer from this account if it is add liquidity operation. Else, token will be transfer into this account. +func (inst *ClaimFee) GetUserATokenAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(15) +} + +// SetUserBTokenAccount sets the "userBToken" account. +// User token B account. Token will be transfer from this account if it is add liquidity operation. Else, token will be transfer into this account. +func (inst *ClaimFee) SetUserBTokenAccount(userBToken ag_solanago.PublicKey) *ClaimFee { + inst.AccountMetaSlice[16] = ag_solanago.Meta(userBToken).WRITE() + return inst +} + +// GetUserBTokenAccount gets the "userBToken" account. +// User token B account. Token will be transfer from this account if it is add liquidity operation. Else, token will be transfer into this account. +func (inst *ClaimFee) GetUserBTokenAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(16) +} + +// SetVaultProgramAccount sets the "vaultProgram" account. +// Vault program. the pool will deposit/withdraw liquidity from the vault. +func (inst *ClaimFee) SetVaultProgramAccount(vaultProgram ag_solanago.PublicKey) *ClaimFee { + inst.AccountMetaSlice[17] = ag_solanago.Meta(vaultProgram) + return inst +} + +// GetVaultProgramAccount gets the "vaultProgram" account. +// Vault program. the pool will deposit/withdraw liquidity from the vault. +func (inst *ClaimFee) GetVaultProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(17) +} + +func (inst ClaimFee) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_ClaimFee, + }} +} + +// 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 ClaimFee) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *ClaimFee) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.MaxAmount == nil { + return errors.New("MaxAmount parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Pool is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.LpMint is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.LockEscrow is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.Owner is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.SourceTokens is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.EscrowVault is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.ATokenVault is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.BTokenVault is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.AVault is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.BVault is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.AVaultLp is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.BVaultLp is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.AVaultLpMint is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.BVaultLpMint is not set") + } + if inst.AccountMetaSlice[15] == nil { + return errors.New("accounts.UserAToken is not set") + } + if inst.AccountMetaSlice[16] == nil { + return errors.New("accounts.UserBToken is not set") + } + if inst.AccountMetaSlice[17] == nil { + return errors.New("accounts.VaultProgram is not set") + } + } + return nil +} + +func (inst *ClaimFee) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("ClaimFee")). + // + 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("MaxAmount", *inst.MaxAmount)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=18]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" pool", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" lpMint", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" lockEscrow", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" owner", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta("sourceTokens", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" escrowVault", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta("tokenProgram", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" aTokenVault", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" bTokenVault", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" aVault", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" bVault", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" aVaultLp", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" bVaultLp", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta("aVaultLpMint", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta("bVaultLpMint", inst.AccountMetaSlice.Get(14))) + accountsBranch.Child(ag_format.Meta(" userAToken", inst.AccountMetaSlice.Get(15))) + accountsBranch.Child(ag_format.Meta(" userBToken", inst.AccountMetaSlice.Get(16))) + accountsBranch.Child(ag_format.Meta("vaultProgram", inst.AccountMetaSlice.Get(17))) + }) + }) + }) +} + +func (obj ClaimFee) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `MaxAmount` param: + err = encoder.Encode(obj.MaxAmount) + if err != nil { + return err + } + return nil +} +func (obj *ClaimFee) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `MaxAmount`: + err = decoder.Decode(&obj.MaxAmount) + if err != nil { + return err + } + return nil +} + +// NewClaimFeeInstruction declares a new ClaimFee instruction with the provided parameters and accounts. +func NewClaimFeeInstruction( + // Parameters: + maxAmount uint64, + // Accounts: + pool ag_solanago.PublicKey, + lpMint ag_solanago.PublicKey, + lockEscrow ag_solanago.PublicKey, + owner ag_solanago.PublicKey, + sourceTokens ag_solanago.PublicKey, + escrowVault ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + aTokenVault ag_solanago.PublicKey, + bTokenVault ag_solanago.PublicKey, + aVault ag_solanago.PublicKey, + bVault ag_solanago.PublicKey, + aVaultLp ag_solanago.PublicKey, + bVaultLp ag_solanago.PublicKey, + aVaultLpMint ag_solanago.PublicKey, + bVaultLpMint ag_solanago.PublicKey, + userAToken ag_solanago.PublicKey, + userBToken ag_solanago.PublicKey, + vaultProgram ag_solanago.PublicKey) *ClaimFee { + return NewClaimFeeInstructionBuilder(). + SetMaxAmount(maxAmount). + SetPoolAccount(pool). + SetLpMintAccount(lpMint). + SetLockEscrowAccount(lockEscrow). + SetOwnerAccount(owner). + SetSourceTokensAccount(sourceTokens). + SetEscrowVaultAccount(escrowVault). + SetTokenProgramAccount(tokenProgram). + SetATokenVaultAccount(aTokenVault). + SetBTokenVaultAccount(bTokenVault). + SetAVaultAccount(aVault). + SetBVaultAccount(bVault). + SetAVaultLpAccount(aVaultLp). + SetBVaultLpAccount(bVaultLp). + SetAVaultLpMintAccount(aVaultLpMint). + SetBVaultLpMintAccount(bVaultLpMint). + SetUserATokenAccount(userAToken). + SetUserBTokenAccount(userBToken). + SetVaultProgramAccount(vaultProgram) +} diff --git a/programs/meteorapools/ClaimFee_test.go b/programs/meteorapools/ClaimFee_test.go new file mode 100644 index 00000000..03155b47 --- /dev/null +++ b/programs/meteorapools/ClaimFee_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_ClaimFee(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("ClaimFee"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(ClaimFee) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(ClaimFee) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteorapools/CloseConfig.go b/programs/meteorapools/CloseConfig.go new file mode 100644 index 00000000..436439de --- /dev/null +++ b/programs/meteorapools/CloseConfig.go @@ -0,0 +1,136 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "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" +) + +// Close config +type CloseConfig struct { + + // [0] = [WRITE] config + // + // [1] = [WRITE, SIGNER] admin + // + // [2] = [WRITE] rentReceiver + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewCloseConfigInstructionBuilder creates a new `CloseConfig` instruction builder. +func NewCloseConfigInstructionBuilder() *CloseConfig { + nd := &CloseConfig{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 3), + } + return nd +} + +// SetConfigAccount sets the "config" account. +func (inst *CloseConfig) SetConfigAccount(config ag_solanago.PublicKey) *CloseConfig { + inst.AccountMetaSlice[0] = ag_solanago.Meta(config).WRITE() + return inst +} + +// GetConfigAccount gets the "config" account. +func (inst *CloseConfig) GetConfigAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetAdminAccount sets the "admin" account. +func (inst *CloseConfig) SetAdminAccount(admin ag_solanago.PublicKey) *CloseConfig { + inst.AccountMetaSlice[1] = ag_solanago.Meta(admin).WRITE().SIGNER() + return inst +} + +// GetAdminAccount gets the "admin" account. +func (inst *CloseConfig) GetAdminAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetRentReceiverAccount sets the "rentReceiver" account. +func (inst *CloseConfig) SetRentReceiverAccount(rentReceiver ag_solanago.PublicKey) *CloseConfig { + inst.AccountMetaSlice[2] = ag_solanago.Meta(rentReceiver).WRITE() + return inst +} + +// GetRentReceiverAccount gets the "rentReceiver" account. +func (inst *CloseConfig) GetRentReceiverAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +func (inst CloseConfig) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_CloseConfig, + }} +} + +// 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 CloseConfig) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *CloseConfig) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Config is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Admin is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.RentReceiver is not set") + } + } + return nil +} + +func (inst *CloseConfig) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("CloseConfig")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=3]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" config", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" admin", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta("rentReceiver", inst.AccountMetaSlice.Get(2))) + }) + }) + }) +} + +func (obj CloseConfig) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *CloseConfig) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewCloseConfigInstruction declares a new CloseConfig instruction with the provided parameters and accounts. +func NewCloseConfigInstruction( + // Accounts: + config ag_solanago.PublicKey, + admin ag_solanago.PublicKey, + rentReceiver ag_solanago.PublicKey) *CloseConfig { + return NewCloseConfigInstructionBuilder(). + SetConfigAccount(config). + SetAdminAccount(admin). + SetRentReceiverAccount(rentReceiver) +} diff --git a/programs/meteorapools/CloseConfig_test.go b/programs/meteorapools/CloseConfig_test.go new file mode 100644 index 00000000..3a9ba00c --- /dev/null +++ b/programs/meteorapools/CloseConfig_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_CloseConfig(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("CloseConfig"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(CloseConfig) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(CloseConfig) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteorapools/CreateConfig.go b/programs/meteorapools/CreateConfig.go new file mode 100644 index 00000000..3ede0d4f --- /dev/null +++ b/programs/meteorapools/CreateConfig.go @@ -0,0 +1,165 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "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" +) + +// Create config +type CreateConfig struct { + ConfigParameters *ConfigParameters + + // [0] = [WRITE] config + // + // [1] = [WRITE, SIGNER] admin + // + // [2] = [] systemProgram + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewCreateConfigInstructionBuilder creates a new `CreateConfig` instruction builder. +func NewCreateConfigInstructionBuilder() *CreateConfig { + nd := &CreateConfig{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 3), + } + return nd +} + +// SetConfigParameters sets the "configParameters" parameter. +func (inst *CreateConfig) SetConfigParameters(configParameters ConfigParameters) *CreateConfig { + inst.ConfigParameters = &configParameters + return inst +} + +// SetConfigAccount sets the "config" account. +func (inst *CreateConfig) SetConfigAccount(config ag_solanago.PublicKey) *CreateConfig { + inst.AccountMetaSlice[0] = ag_solanago.Meta(config).WRITE() + return inst +} + +// GetConfigAccount gets the "config" account. +func (inst *CreateConfig) GetConfigAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetAdminAccount sets the "admin" account. +func (inst *CreateConfig) SetAdminAccount(admin ag_solanago.PublicKey) *CreateConfig { + inst.AccountMetaSlice[1] = ag_solanago.Meta(admin).WRITE().SIGNER() + return inst +} + +// GetAdminAccount gets the "admin" account. +func (inst *CreateConfig) GetAdminAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +func (inst *CreateConfig) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *CreateConfig { + inst.AccountMetaSlice[2] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +func (inst *CreateConfig) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +func (inst CreateConfig) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_CreateConfig, + }} +} + +// 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 CreateConfig) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *CreateConfig) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.ConfigParameters == nil { + return errors.New("ConfigParameters parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Config is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Admin is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.SystemProgram is not set") + } + } + return nil +} + +func (inst *CreateConfig) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("CreateConfig")). + // + 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("ConfigParameters", *inst.ConfigParameters)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=3]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" config", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" admin", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta("systemProgram", inst.AccountMetaSlice.Get(2))) + }) + }) + }) +} + +func (obj CreateConfig) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `ConfigParameters` param: + err = encoder.Encode(obj.ConfigParameters) + if err != nil { + return err + } + return nil +} +func (obj *CreateConfig) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `ConfigParameters`: + err = decoder.Decode(&obj.ConfigParameters) + if err != nil { + return err + } + return nil +} + +// NewCreateConfigInstruction declares a new CreateConfig instruction with the provided parameters and accounts. +func NewCreateConfigInstruction( + // Parameters: + configParameters ConfigParameters, + // Accounts: + config ag_solanago.PublicKey, + admin ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey) *CreateConfig { + return NewCreateConfigInstructionBuilder(). + SetConfigParameters(configParameters). + SetConfigAccount(config). + SetAdminAccount(admin). + SetSystemProgramAccount(systemProgram) +} diff --git a/programs/meteorapools/CreateConfig_test.go b/programs/meteorapools/CreateConfig_test.go new file mode 100644 index 00000000..d4a1d28c --- /dev/null +++ b/programs/meteorapools/CreateConfig_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_CreateConfig(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("CreateConfig"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(CreateConfig) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(CreateConfig) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteorapools/CreateLockEscrow.go b/programs/meteorapools/CreateLockEscrow.go new file mode 100644 index 00000000..644ac67a --- /dev/null +++ b/programs/meteorapools/CreateLockEscrow.go @@ -0,0 +1,208 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "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" +) + +// Create lock account +type CreateLockEscrow struct { + + // [0] = [] pool + // ··········· Pool account + // + // [1] = [WRITE] lockEscrow + // ··········· Lock account + // + // [2] = [] owner + // + // [3] = [] lpMint + // ··········· LP token mint of the pool + // + // [4] = [WRITE, SIGNER] payer + // ··········· Payer account + // + // [5] = [] systemProgram + // ··········· System program. + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewCreateLockEscrowInstructionBuilder creates a new `CreateLockEscrow` instruction builder. +func NewCreateLockEscrowInstructionBuilder() *CreateLockEscrow { + nd := &CreateLockEscrow{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 6), + } + return nd +} + +// SetPoolAccount sets the "pool" account. +// Pool account +func (inst *CreateLockEscrow) SetPoolAccount(pool ag_solanago.PublicKey) *CreateLockEscrow { + inst.AccountMetaSlice[0] = ag_solanago.Meta(pool) + return inst +} + +// GetPoolAccount gets the "pool" account. +// Pool account +func (inst *CreateLockEscrow) GetPoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetLockEscrowAccount sets the "lockEscrow" account. +// Lock account +func (inst *CreateLockEscrow) SetLockEscrowAccount(lockEscrow ag_solanago.PublicKey) *CreateLockEscrow { + inst.AccountMetaSlice[1] = ag_solanago.Meta(lockEscrow).WRITE() + return inst +} + +// GetLockEscrowAccount gets the "lockEscrow" account. +// Lock account +func (inst *CreateLockEscrow) GetLockEscrowAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetOwnerAccount sets the "owner" account. +func (inst *CreateLockEscrow) SetOwnerAccount(owner ag_solanago.PublicKey) *CreateLockEscrow { + inst.AccountMetaSlice[2] = ag_solanago.Meta(owner) + return inst +} + +// GetOwnerAccount gets the "owner" account. +func (inst *CreateLockEscrow) GetOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetLpMintAccount sets the "lpMint" account. +// LP token mint of the pool +func (inst *CreateLockEscrow) SetLpMintAccount(lpMint ag_solanago.PublicKey) *CreateLockEscrow { + inst.AccountMetaSlice[3] = ag_solanago.Meta(lpMint) + return inst +} + +// GetLpMintAccount gets the "lpMint" account. +// LP token mint of the pool +func (inst *CreateLockEscrow) GetLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetPayerAccount sets the "payer" account. +// Payer account +func (inst *CreateLockEscrow) SetPayerAccount(payer ag_solanago.PublicKey) *CreateLockEscrow { + inst.AccountMetaSlice[4] = ag_solanago.Meta(payer).WRITE().SIGNER() + return inst +} + +// GetPayerAccount gets the "payer" account. +// Payer account +func (inst *CreateLockEscrow) GetPayerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +// System program. +func (inst *CreateLockEscrow) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *CreateLockEscrow { + inst.AccountMetaSlice[5] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +// System program. +func (inst *CreateLockEscrow) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +func (inst CreateLockEscrow) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_CreateLockEscrow, + }} +} + +// 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 CreateLockEscrow) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *CreateLockEscrow) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Pool is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.LockEscrow is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.Owner is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.LpMint is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.Payer is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.SystemProgram is not set") + } + } + return nil +} + +func (inst *CreateLockEscrow) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("CreateLockEscrow")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=6]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" pool", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" lockEscrow", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" owner", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" lpMint", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" payer", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta("systemProgram", inst.AccountMetaSlice.Get(5))) + }) + }) + }) +} + +func (obj CreateLockEscrow) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *CreateLockEscrow) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewCreateLockEscrowInstruction declares a new CreateLockEscrow instruction with the provided parameters and accounts. +func NewCreateLockEscrowInstruction( + // Accounts: + pool ag_solanago.PublicKey, + lockEscrow ag_solanago.PublicKey, + owner ag_solanago.PublicKey, + lpMint ag_solanago.PublicKey, + payer ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey) *CreateLockEscrow { + return NewCreateLockEscrowInstructionBuilder(). + SetPoolAccount(pool). + SetLockEscrowAccount(lockEscrow). + SetOwnerAccount(owner). + SetLpMintAccount(lpMint). + SetPayerAccount(payer). + SetSystemProgramAccount(systemProgram) +} diff --git a/programs/meteorapools/CreateLockEscrow_test.go b/programs/meteorapools/CreateLockEscrow_test.go new file mode 100644 index 00000000..6a9cdfa4 --- /dev/null +++ b/programs/meteorapools/CreateLockEscrow_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_CreateLockEscrow(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("CreateLockEscrow"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(CreateLockEscrow) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(CreateLockEscrow) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteorapools/CreateMintMetadata.go b/programs/meteorapools/CreateMintMetadata.go new file mode 100644 index 00000000..f2cdd10c --- /dev/null +++ b/programs/meteorapools/CreateMintMetadata.go @@ -0,0 +1,227 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "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" +) + +// Create mint metadata account for old pools +type CreateMintMetadata struct { + + // [0] = [] pool + // ··········· Pool account + // + // [1] = [] lpMint + // ··········· LP mint account of the pool + // + // [2] = [] aVaultLp + // ··········· Vault A LP account of the pool + // + // [3] = [WRITE] mintMetadata + // + // [4] = [] metadataProgram + // + // [5] = [] systemProgram + // ··········· System program. + // + // [6] = [WRITE, SIGNER] payer + // ··········· Payer + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewCreateMintMetadataInstructionBuilder creates a new `CreateMintMetadata` instruction builder. +func NewCreateMintMetadataInstructionBuilder() *CreateMintMetadata { + nd := &CreateMintMetadata{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 7), + } + return nd +} + +// SetPoolAccount sets the "pool" account. +// Pool account +func (inst *CreateMintMetadata) SetPoolAccount(pool ag_solanago.PublicKey) *CreateMintMetadata { + inst.AccountMetaSlice[0] = ag_solanago.Meta(pool) + return inst +} + +// GetPoolAccount gets the "pool" account. +// Pool account +func (inst *CreateMintMetadata) GetPoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetLpMintAccount sets the "lpMint" account. +// LP mint account of the pool +func (inst *CreateMintMetadata) SetLpMintAccount(lpMint ag_solanago.PublicKey) *CreateMintMetadata { + inst.AccountMetaSlice[1] = ag_solanago.Meta(lpMint) + return inst +} + +// GetLpMintAccount gets the "lpMint" account. +// LP mint account of the pool +func (inst *CreateMintMetadata) GetLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetAVaultLpAccount sets the "aVaultLp" account. +// Vault A LP account of the pool +func (inst *CreateMintMetadata) SetAVaultLpAccount(aVaultLp ag_solanago.PublicKey) *CreateMintMetadata { + inst.AccountMetaSlice[2] = ag_solanago.Meta(aVaultLp) + return inst +} + +// GetAVaultLpAccount gets the "aVaultLp" account. +// Vault A LP account of the pool +func (inst *CreateMintMetadata) GetAVaultLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetMintMetadataAccount sets the "mintMetadata" account. +func (inst *CreateMintMetadata) SetMintMetadataAccount(mintMetadata ag_solanago.PublicKey) *CreateMintMetadata { + inst.AccountMetaSlice[3] = ag_solanago.Meta(mintMetadata).WRITE() + return inst +} + +// GetMintMetadataAccount gets the "mintMetadata" account. +func (inst *CreateMintMetadata) GetMintMetadataAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetMetadataProgramAccount sets the "metadataProgram" account. +func (inst *CreateMintMetadata) SetMetadataProgramAccount(metadataProgram ag_solanago.PublicKey) *CreateMintMetadata { + inst.AccountMetaSlice[4] = ag_solanago.Meta(metadataProgram) + return inst +} + +// GetMetadataProgramAccount gets the "metadataProgram" account. +func (inst *CreateMintMetadata) GetMetadataProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +// System program. +func (inst *CreateMintMetadata) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *CreateMintMetadata { + inst.AccountMetaSlice[5] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +// System program. +func (inst *CreateMintMetadata) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetPayerAccount sets the "payer" account. +// Payer +func (inst *CreateMintMetadata) SetPayerAccount(payer ag_solanago.PublicKey) *CreateMintMetadata { + inst.AccountMetaSlice[6] = ag_solanago.Meta(payer).WRITE().SIGNER() + return inst +} + +// GetPayerAccount gets the "payer" account. +// Payer +func (inst *CreateMintMetadata) GetPayerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +func (inst CreateMintMetadata) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_CreateMintMetadata, + }} +} + +// 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 CreateMintMetadata) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *CreateMintMetadata) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Pool is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.LpMint is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.AVaultLp is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.MintMetadata is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.MetadataProgram is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.SystemProgram is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.Payer is not set") + } + } + return nil +} + +func (inst *CreateMintMetadata) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("CreateMintMetadata")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=7]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" pool", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" lpMint", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" aVaultLp", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" mintMetadata", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta("metadataProgram", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" systemProgram", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" payer", inst.AccountMetaSlice.Get(6))) + }) + }) + }) +} + +func (obj CreateMintMetadata) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *CreateMintMetadata) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewCreateMintMetadataInstruction declares a new CreateMintMetadata instruction with the provided parameters and accounts. +func NewCreateMintMetadataInstruction( + // Accounts: + pool ag_solanago.PublicKey, + lpMint ag_solanago.PublicKey, + aVaultLp ag_solanago.PublicKey, + mintMetadata ag_solanago.PublicKey, + metadataProgram ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey, + payer ag_solanago.PublicKey) *CreateMintMetadata { + return NewCreateMintMetadataInstructionBuilder(). + SetPoolAccount(pool). + SetLpMintAccount(lpMint). + SetAVaultLpAccount(aVaultLp). + SetMintMetadataAccount(mintMetadata). + SetMetadataProgramAccount(metadataProgram). + SetSystemProgramAccount(systemProgram). + SetPayerAccount(payer) +} diff --git a/programs/meteorapools/CreateMintMetadata_test.go b/programs/meteorapools/CreateMintMetadata_test.go new file mode 100644 index 00000000..1ab65670 --- /dev/null +++ b/programs/meteorapools/CreateMintMetadata_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_CreateMintMetadata(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("CreateMintMetadata"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(CreateMintMetadata) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(CreateMintMetadata) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteorapools/EnableOrDisablePool.go b/programs/meteorapools/EnableOrDisablePool.go new file mode 100644 index 00000000..99900d14 --- /dev/null +++ b/programs/meteorapools/EnableOrDisablePool.go @@ -0,0 +1,152 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "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" +) + +// Enable or disable a pool. A disabled pool allow only remove balanced liquidity operation. +type EnableOrDisablePool struct { + Enable *bool + + // [0] = [WRITE] pool + // ··········· Pool account (PDA) + // + // [1] = [SIGNER] admin + // ··········· Admin account. Must be owner of the pool. + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewEnableOrDisablePoolInstructionBuilder creates a new `EnableOrDisablePool` instruction builder. +func NewEnableOrDisablePoolInstructionBuilder() *EnableOrDisablePool { + nd := &EnableOrDisablePool{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 2), + } + return nd +} + +// SetEnable sets the "enable" parameter. +func (inst *EnableOrDisablePool) SetEnable(enable bool) *EnableOrDisablePool { + inst.Enable = &enable + return inst +} + +// SetPoolAccount sets the "pool" account. +// Pool account (PDA) +func (inst *EnableOrDisablePool) SetPoolAccount(pool ag_solanago.PublicKey) *EnableOrDisablePool { + inst.AccountMetaSlice[0] = ag_solanago.Meta(pool).WRITE() + return inst +} + +// GetPoolAccount gets the "pool" account. +// Pool account (PDA) +func (inst *EnableOrDisablePool) GetPoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetAdminAccount sets the "admin" account. +// Admin account. Must be owner of the pool. +func (inst *EnableOrDisablePool) SetAdminAccount(admin ag_solanago.PublicKey) *EnableOrDisablePool { + inst.AccountMetaSlice[1] = ag_solanago.Meta(admin).SIGNER() + return inst +} + +// GetAdminAccount gets the "admin" account. +// Admin account. Must be owner of the pool. +func (inst *EnableOrDisablePool) GetAdminAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +func (inst EnableOrDisablePool) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_EnableOrDisablePool, + }} +} + +// 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 EnableOrDisablePool) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *EnableOrDisablePool) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.Enable == nil { + return errors.New("Enable parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Pool is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Admin is not set") + } + } + return nil +} + +func (inst *EnableOrDisablePool) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("EnableOrDisablePool")). + // + 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("Enable", *inst.Enable)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=2]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" pool", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta("admin", inst.AccountMetaSlice.Get(1))) + }) + }) + }) +} + +func (obj EnableOrDisablePool) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Enable` param: + err = encoder.Encode(obj.Enable) + if err != nil { + return err + } + return nil +} +func (obj *EnableOrDisablePool) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Enable`: + err = decoder.Decode(&obj.Enable) + if err != nil { + return err + } + return nil +} + +// NewEnableOrDisablePoolInstruction declares a new EnableOrDisablePool instruction with the provided parameters and accounts. +func NewEnableOrDisablePoolInstruction( + // Parameters: + enable bool, + // Accounts: + pool ag_solanago.PublicKey, + admin ag_solanago.PublicKey) *EnableOrDisablePool { + return NewEnableOrDisablePoolInstructionBuilder(). + SetEnable(enable). + SetPoolAccount(pool). + SetAdminAccount(admin) +} diff --git a/programs/meteorapools/EnableOrDisablePool_test.go b/programs/meteorapools/EnableOrDisablePool_test.go new file mode 100644 index 00000000..5bebaa86 --- /dev/null +++ b/programs/meteorapools/EnableOrDisablePool_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_EnableOrDisablePool(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("EnableOrDisablePool"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(EnableOrDisablePool) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(EnableOrDisablePool) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteorapools/GetPoolInfo.go b/programs/meteorapools/GetPoolInfo.go new file mode 100644 index 00000000..e58f32b4 --- /dev/null +++ b/programs/meteorapools/GetPoolInfo.go @@ -0,0 +1,255 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "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" +) + +// Get the general information of the pool. +type GetPoolInfo struct { + + // [0] = [] pool + // ··········· Pool account (PDA) + // + // [1] = [] lpMint + // ··········· LP token mint of the pool + // + // [2] = [] aVaultLp + // ··········· LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. + // + // [3] = [] bVaultLp + // ··········· LP token account of vault B. Used to receive/burn the vault LP upon deposit/withdraw from the vault. + // + // [4] = [] aVault + // ··········· Vault account for token a. token a of the pool will be deposit / withdraw from this vault account. + // + // [5] = [] bVault + // ··········· Vault account for token b. token b of the pool will be deposit / withdraw from this vault account. + // + // [6] = [] aVaultLpMint + // ··········· LP token mint of vault a + // + // [7] = [] bVaultLpMint + // ··········· LP token mint of vault b + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewGetPoolInfoInstructionBuilder creates a new `GetPoolInfo` instruction builder. +func NewGetPoolInfoInstructionBuilder() *GetPoolInfo { + nd := &GetPoolInfo{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 8), + } + return nd +} + +// SetPoolAccount sets the "pool" account. +// Pool account (PDA) +func (inst *GetPoolInfo) SetPoolAccount(pool ag_solanago.PublicKey) *GetPoolInfo { + inst.AccountMetaSlice[0] = ag_solanago.Meta(pool) + return inst +} + +// GetPoolAccount gets the "pool" account. +// Pool account (PDA) +func (inst *GetPoolInfo) GetPoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetLpMintAccount sets the "lpMint" account. +// LP token mint of the pool +func (inst *GetPoolInfo) SetLpMintAccount(lpMint ag_solanago.PublicKey) *GetPoolInfo { + inst.AccountMetaSlice[1] = ag_solanago.Meta(lpMint) + return inst +} + +// GetLpMintAccount gets the "lpMint" account. +// LP token mint of the pool +func (inst *GetPoolInfo) GetLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetAVaultLpAccount sets the "aVaultLp" account. +// LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *GetPoolInfo) SetAVaultLpAccount(aVaultLp ag_solanago.PublicKey) *GetPoolInfo { + inst.AccountMetaSlice[2] = ag_solanago.Meta(aVaultLp) + return inst +} + +// GetAVaultLpAccount gets the "aVaultLp" account. +// LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *GetPoolInfo) GetAVaultLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetBVaultLpAccount sets the "bVaultLp" account. +// LP token account of vault B. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *GetPoolInfo) SetBVaultLpAccount(bVaultLp ag_solanago.PublicKey) *GetPoolInfo { + inst.AccountMetaSlice[3] = ag_solanago.Meta(bVaultLp) + return inst +} + +// GetBVaultLpAccount gets the "bVaultLp" account. +// LP token account of vault B. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *GetPoolInfo) GetBVaultLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetAVaultAccount sets the "aVault" account. +// Vault account for token a. token a of the pool will be deposit / withdraw from this vault account. +func (inst *GetPoolInfo) SetAVaultAccount(aVault ag_solanago.PublicKey) *GetPoolInfo { + inst.AccountMetaSlice[4] = ag_solanago.Meta(aVault) + return inst +} + +// GetAVaultAccount gets the "aVault" account. +// Vault account for token a. token a of the pool will be deposit / withdraw from this vault account. +func (inst *GetPoolInfo) GetAVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetBVaultAccount sets the "bVault" account. +// Vault account for token b. token b of the pool will be deposit / withdraw from this vault account. +func (inst *GetPoolInfo) SetBVaultAccount(bVault ag_solanago.PublicKey) *GetPoolInfo { + inst.AccountMetaSlice[5] = ag_solanago.Meta(bVault) + return inst +} + +// GetBVaultAccount gets the "bVault" account. +// Vault account for token b. token b of the pool will be deposit / withdraw from this vault account. +func (inst *GetPoolInfo) GetBVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetAVaultLpMintAccount sets the "aVaultLpMint" account. +// LP token mint of vault a +func (inst *GetPoolInfo) SetAVaultLpMintAccount(aVaultLpMint ag_solanago.PublicKey) *GetPoolInfo { + inst.AccountMetaSlice[6] = ag_solanago.Meta(aVaultLpMint) + return inst +} + +// GetAVaultLpMintAccount gets the "aVaultLpMint" account. +// LP token mint of vault a +func (inst *GetPoolInfo) GetAVaultLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetBVaultLpMintAccount sets the "bVaultLpMint" account. +// LP token mint of vault b +func (inst *GetPoolInfo) SetBVaultLpMintAccount(bVaultLpMint ag_solanago.PublicKey) *GetPoolInfo { + inst.AccountMetaSlice[7] = ag_solanago.Meta(bVaultLpMint) + return inst +} + +// GetBVaultLpMintAccount gets the "bVaultLpMint" account. +// LP token mint of vault b +func (inst *GetPoolInfo) GetBVaultLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +func (inst GetPoolInfo) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_GetPoolInfo, + }} +} + +// 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 GetPoolInfo) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *GetPoolInfo) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Pool is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.LpMint is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.AVaultLp is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.BVaultLp is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.AVault is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.BVault is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.AVaultLpMint is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.BVaultLpMint is not set") + } + } + return nil +} + +func (inst *GetPoolInfo) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("GetPoolInfo")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=8]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" pool", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" lpMint", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" aVaultLp", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" bVaultLp", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" aVault", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" bVault", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta("aVaultLpMint", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta("bVaultLpMint", inst.AccountMetaSlice.Get(7))) + }) + }) + }) +} + +func (obj GetPoolInfo) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *GetPoolInfo) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewGetPoolInfoInstruction declares a new GetPoolInfo instruction with the provided parameters and accounts. +func NewGetPoolInfoInstruction( + // Accounts: + pool ag_solanago.PublicKey, + lpMint ag_solanago.PublicKey, + aVaultLp ag_solanago.PublicKey, + bVaultLp ag_solanago.PublicKey, + aVault ag_solanago.PublicKey, + bVault ag_solanago.PublicKey, + aVaultLpMint ag_solanago.PublicKey, + bVaultLpMint ag_solanago.PublicKey) *GetPoolInfo { + return NewGetPoolInfoInstructionBuilder(). + SetPoolAccount(pool). + SetLpMintAccount(lpMint). + SetAVaultLpAccount(aVaultLp). + SetBVaultLpAccount(bVaultLp). + SetAVaultAccount(aVault). + SetBVaultAccount(bVault). + SetAVaultLpMintAccount(aVaultLpMint). + SetBVaultLpMintAccount(bVaultLpMint) +} diff --git a/programs/meteorapools/GetPoolInfo_test.go b/programs/meteorapools/GetPoolInfo_test.go new file mode 100644 index 00000000..19d9c62a --- /dev/null +++ b/programs/meteorapools/GetPoolInfo_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_GetPoolInfo(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("GetPoolInfo"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(GetPoolInfo) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(GetPoolInfo) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteorapools/InitializeCustomizablePermissionlessConstantProductPool.go b/programs/meteorapools/InitializeCustomizablePermissionlessConstantProductPool.go new file mode 100644 index 00000000..818d6ce5 --- /dev/null +++ b/programs/meteorapools/InitializeCustomizablePermissionlessConstantProductPool.go @@ -0,0 +1,695 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "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" +) + +// Initialize permissionless pool with customizable params +type InitializeCustomizablePermissionlessConstantProductPool struct { + TokenAAmount *uint64 + TokenBAmount *uint64 + Params *CustomizableParams + + // [0] = [WRITE] pool + // ··········· Pool account (PDA address) + // + // [1] = [WRITE] lpMint + // ··········· LP token mint of the pool + // + // [2] = [] tokenAMint + // ··········· Token A mint of the pool. Eg: USDT + // + // [3] = [] tokenBMint + // ··········· Token B mint of the pool. Eg: USDC + // + // [4] = [WRITE] aVault + // ··········· Vault account for token A. Token A of the pool will be deposit / withdraw from this vault account. + // + // [5] = [WRITE] bVault + // ··········· Vault account for token B. Token B of the pool will be deposit / withdraw from this vault account. + // + // [6] = [WRITE] aTokenVault + // ··········· Token vault account of vault A + // + // [7] = [WRITE] bTokenVault + // ··········· Token vault account of vault B + // + // [8] = [WRITE] aVaultLpMint + // ··········· LP token mint of vault A + // + // [9] = [WRITE] bVaultLpMint + // ··········· LP token mint of vault B + // + // [10] = [WRITE] aVaultLp + // ··········· LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. + // + // [11] = [WRITE] bVaultLp + // ··········· LP token account of vault B. Used to receive/burn vault LP upon deposit/withdraw from the vault. + // + // [12] = [WRITE] payerTokenA + // ··········· Payer token account for pool token A mint. Used to bootstrap the pool with initial liquidity. + // + // [13] = [WRITE] payerTokenB + // ··········· Admin token account for pool token B mint. Used to bootstrap the pool with initial liquidity. + // + // [14] = [WRITE] payerPoolLp + // + // [15] = [WRITE] protocolTokenAFee + // ··········· Protocol fee token account for token A. Used to receive trading fee. + // + // [16] = [WRITE] protocolTokenBFee + // ··········· Protocol fee token account for token B. Used to receive trading fee. + // + // [17] = [WRITE, SIGNER] payer + // ··········· Admin account. This account will be the admin of the pool, and the payer for PDA during initialize pool. + // + // [18] = [] rent + // ··········· Rent account. + // + // [19] = [WRITE] mintMetadata + // + // [20] = [] metadataProgram + // + // [21] = [] vaultProgram + // ··········· Vault program. The pool will deposit/withdraw liquidity from the vault. + // + // [22] = [] tokenProgram + // ··········· Token program. + // + // [23] = [] associatedTokenProgram + // ··········· Associated token program. + // + // [24] = [] systemProgram + // ··········· System program. + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewInitializeCustomizablePermissionlessConstantProductPoolInstructionBuilder creates a new `InitializeCustomizablePermissionlessConstantProductPool` instruction builder. +func NewInitializeCustomizablePermissionlessConstantProductPoolInstructionBuilder() *InitializeCustomizablePermissionlessConstantProductPool { + nd := &InitializeCustomizablePermissionlessConstantProductPool{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 25), + } + return nd +} + +// SetTokenAAmount sets the "tokenAAmount" parameter. +func (inst *InitializeCustomizablePermissionlessConstantProductPool) SetTokenAAmount(tokenAAmount uint64) *InitializeCustomizablePermissionlessConstantProductPool { + inst.TokenAAmount = &tokenAAmount + return inst +} + +// SetTokenBAmount sets the "tokenBAmount" parameter. +func (inst *InitializeCustomizablePermissionlessConstantProductPool) SetTokenBAmount(tokenBAmount uint64) *InitializeCustomizablePermissionlessConstantProductPool { + inst.TokenBAmount = &tokenBAmount + return inst +} + +// SetParams sets the "params" parameter. +func (inst *InitializeCustomizablePermissionlessConstantProductPool) SetParams(params CustomizableParams) *InitializeCustomizablePermissionlessConstantProductPool { + inst.Params = ¶ms + return inst +} + +// SetPoolAccount sets the "pool" account. +// Pool account (PDA address) +func (inst *InitializeCustomizablePermissionlessConstantProductPool) SetPoolAccount(pool ag_solanago.PublicKey) *InitializeCustomizablePermissionlessConstantProductPool { + inst.AccountMetaSlice[0] = ag_solanago.Meta(pool).WRITE() + return inst +} + +// GetPoolAccount gets the "pool" account. +// Pool account (PDA address) +func (inst *InitializeCustomizablePermissionlessConstantProductPool) GetPoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetLpMintAccount sets the "lpMint" account. +// LP token mint of the pool +func (inst *InitializeCustomizablePermissionlessConstantProductPool) SetLpMintAccount(lpMint ag_solanago.PublicKey) *InitializeCustomizablePermissionlessConstantProductPool { + inst.AccountMetaSlice[1] = ag_solanago.Meta(lpMint).WRITE() + return inst +} + +// GetLpMintAccount gets the "lpMint" account. +// LP token mint of the pool +func (inst *InitializeCustomizablePermissionlessConstantProductPool) GetLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetTokenAMintAccount sets the "tokenAMint" account. +// Token A mint of the pool. Eg: USDT +func (inst *InitializeCustomizablePermissionlessConstantProductPool) SetTokenAMintAccount(tokenAMint ag_solanago.PublicKey) *InitializeCustomizablePermissionlessConstantProductPool { + inst.AccountMetaSlice[2] = ag_solanago.Meta(tokenAMint) + return inst +} + +// GetTokenAMintAccount gets the "tokenAMint" account. +// Token A mint of the pool. Eg: USDT +func (inst *InitializeCustomizablePermissionlessConstantProductPool) GetTokenAMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetTokenBMintAccount sets the "tokenBMint" account. +// Token B mint of the pool. Eg: USDC +func (inst *InitializeCustomizablePermissionlessConstantProductPool) SetTokenBMintAccount(tokenBMint ag_solanago.PublicKey) *InitializeCustomizablePermissionlessConstantProductPool { + inst.AccountMetaSlice[3] = ag_solanago.Meta(tokenBMint) + return inst +} + +// GetTokenBMintAccount gets the "tokenBMint" account. +// Token B mint of the pool. Eg: USDC +func (inst *InitializeCustomizablePermissionlessConstantProductPool) GetTokenBMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetAVaultAccount sets the "aVault" account. +// Vault account for token A. Token A of the pool will be deposit / withdraw from this vault account. +func (inst *InitializeCustomizablePermissionlessConstantProductPool) SetAVaultAccount(aVault ag_solanago.PublicKey) *InitializeCustomizablePermissionlessConstantProductPool { + inst.AccountMetaSlice[4] = ag_solanago.Meta(aVault).WRITE() + return inst +} + +// GetAVaultAccount gets the "aVault" account. +// Vault account for token A. Token A of the pool will be deposit / withdraw from this vault account. +func (inst *InitializeCustomizablePermissionlessConstantProductPool) GetAVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetBVaultAccount sets the "bVault" account. +// Vault account for token B. Token B of the pool will be deposit / withdraw from this vault account. +func (inst *InitializeCustomizablePermissionlessConstantProductPool) SetBVaultAccount(bVault ag_solanago.PublicKey) *InitializeCustomizablePermissionlessConstantProductPool { + inst.AccountMetaSlice[5] = ag_solanago.Meta(bVault).WRITE() + return inst +} + +// GetBVaultAccount gets the "bVault" account. +// Vault account for token B. Token B of the pool will be deposit / withdraw from this vault account. +func (inst *InitializeCustomizablePermissionlessConstantProductPool) GetBVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetATokenVaultAccount sets the "aTokenVault" account. +// Token vault account of vault A +func (inst *InitializeCustomizablePermissionlessConstantProductPool) SetATokenVaultAccount(aTokenVault ag_solanago.PublicKey) *InitializeCustomizablePermissionlessConstantProductPool { + inst.AccountMetaSlice[6] = ag_solanago.Meta(aTokenVault).WRITE() + return inst +} + +// GetATokenVaultAccount gets the "aTokenVault" account. +// Token vault account of vault A +func (inst *InitializeCustomizablePermissionlessConstantProductPool) GetATokenVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetBTokenVaultAccount sets the "bTokenVault" account. +// Token vault account of vault B +func (inst *InitializeCustomizablePermissionlessConstantProductPool) SetBTokenVaultAccount(bTokenVault ag_solanago.PublicKey) *InitializeCustomizablePermissionlessConstantProductPool { + inst.AccountMetaSlice[7] = ag_solanago.Meta(bTokenVault).WRITE() + return inst +} + +// GetBTokenVaultAccount gets the "bTokenVault" account. +// Token vault account of vault B +func (inst *InitializeCustomizablePermissionlessConstantProductPool) GetBTokenVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetAVaultLpMintAccount sets the "aVaultLpMint" account. +// LP token mint of vault A +func (inst *InitializeCustomizablePermissionlessConstantProductPool) SetAVaultLpMintAccount(aVaultLpMint ag_solanago.PublicKey) *InitializeCustomizablePermissionlessConstantProductPool { + inst.AccountMetaSlice[8] = ag_solanago.Meta(aVaultLpMint).WRITE() + return inst +} + +// GetAVaultLpMintAccount gets the "aVaultLpMint" account. +// LP token mint of vault A +func (inst *InitializeCustomizablePermissionlessConstantProductPool) GetAVaultLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetBVaultLpMintAccount sets the "bVaultLpMint" account. +// LP token mint of vault B +func (inst *InitializeCustomizablePermissionlessConstantProductPool) SetBVaultLpMintAccount(bVaultLpMint ag_solanago.PublicKey) *InitializeCustomizablePermissionlessConstantProductPool { + inst.AccountMetaSlice[9] = ag_solanago.Meta(bVaultLpMint).WRITE() + return inst +} + +// GetBVaultLpMintAccount gets the "bVaultLpMint" account. +// LP token mint of vault B +func (inst *InitializeCustomizablePermissionlessConstantProductPool) GetBVaultLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetAVaultLpAccount sets the "aVaultLp" account. +// LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *InitializeCustomizablePermissionlessConstantProductPool) SetAVaultLpAccount(aVaultLp ag_solanago.PublicKey) *InitializeCustomizablePermissionlessConstantProductPool { + inst.AccountMetaSlice[10] = ag_solanago.Meta(aVaultLp).WRITE() + return inst +} + +// GetAVaultLpAccount gets the "aVaultLp" account. +// LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *InitializeCustomizablePermissionlessConstantProductPool) GetAVaultLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetBVaultLpAccount sets the "bVaultLp" account. +// LP token account of vault B. Used to receive/burn vault LP upon deposit/withdraw from the vault. +func (inst *InitializeCustomizablePermissionlessConstantProductPool) SetBVaultLpAccount(bVaultLp ag_solanago.PublicKey) *InitializeCustomizablePermissionlessConstantProductPool { + inst.AccountMetaSlice[11] = ag_solanago.Meta(bVaultLp).WRITE() + return inst +} + +// GetBVaultLpAccount gets the "bVaultLp" account. +// LP token account of vault B. Used to receive/burn vault LP upon deposit/withdraw from the vault. +func (inst *InitializeCustomizablePermissionlessConstantProductPool) GetBVaultLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetPayerTokenAAccount sets the "payerTokenA" account. +// Payer token account for pool token A mint. Used to bootstrap the pool with initial liquidity. +func (inst *InitializeCustomizablePermissionlessConstantProductPool) SetPayerTokenAAccount(payerTokenA ag_solanago.PublicKey) *InitializeCustomizablePermissionlessConstantProductPool { + inst.AccountMetaSlice[12] = ag_solanago.Meta(payerTokenA).WRITE() + return inst +} + +// GetPayerTokenAAccount gets the "payerTokenA" account. +// Payer token account for pool token A mint. Used to bootstrap the pool with initial liquidity. +func (inst *InitializeCustomizablePermissionlessConstantProductPool) GetPayerTokenAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetPayerTokenBAccount sets the "payerTokenB" account. +// Admin token account for pool token B mint. Used to bootstrap the pool with initial liquidity. +func (inst *InitializeCustomizablePermissionlessConstantProductPool) SetPayerTokenBAccount(payerTokenB ag_solanago.PublicKey) *InitializeCustomizablePermissionlessConstantProductPool { + inst.AccountMetaSlice[13] = ag_solanago.Meta(payerTokenB).WRITE() + return inst +} + +// GetPayerTokenBAccount gets the "payerTokenB" account. +// Admin token account for pool token B mint. Used to bootstrap the pool with initial liquidity. +func (inst *InitializeCustomizablePermissionlessConstantProductPool) GetPayerTokenBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetPayerPoolLpAccount sets the "payerPoolLp" account. +func (inst *InitializeCustomizablePermissionlessConstantProductPool) SetPayerPoolLpAccount(payerPoolLp ag_solanago.PublicKey) *InitializeCustomizablePermissionlessConstantProductPool { + inst.AccountMetaSlice[14] = ag_solanago.Meta(payerPoolLp).WRITE() + return inst +} + +// GetPayerPoolLpAccount gets the "payerPoolLp" account. +func (inst *InitializeCustomizablePermissionlessConstantProductPool) GetPayerPoolLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +// SetProtocolTokenAFeeAccount sets the "protocolTokenAFee" account. +// Protocol fee token account for token A. Used to receive trading fee. +func (inst *InitializeCustomizablePermissionlessConstantProductPool) SetProtocolTokenAFeeAccount(protocolTokenAFee ag_solanago.PublicKey) *InitializeCustomizablePermissionlessConstantProductPool { + inst.AccountMetaSlice[15] = ag_solanago.Meta(protocolTokenAFee).WRITE() + return inst +} + +// GetProtocolTokenAFeeAccount gets the "protocolTokenAFee" account. +// Protocol fee token account for token A. Used to receive trading fee. +func (inst *InitializeCustomizablePermissionlessConstantProductPool) GetProtocolTokenAFeeAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(15) +} + +// SetProtocolTokenBFeeAccount sets the "protocolTokenBFee" account. +// Protocol fee token account for token B. Used to receive trading fee. +func (inst *InitializeCustomizablePermissionlessConstantProductPool) SetProtocolTokenBFeeAccount(protocolTokenBFee ag_solanago.PublicKey) *InitializeCustomizablePermissionlessConstantProductPool { + inst.AccountMetaSlice[16] = ag_solanago.Meta(protocolTokenBFee).WRITE() + return inst +} + +// GetProtocolTokenBFeeAccount gets the "protocolTokenBFee" account. +// Protocol fee token account for token B. Used to receive trading fee. +func (inst *InitializeCustomizablePermissionlessConstantProductPool) GetProtocolTokenBFeeAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(16) +} + +// SetPayerAccount sets the "payer" account. +// Admin account. This account will be the admin of the pool, and the payer for PDA during initialize pool. +func (inst *InitializeCustomizablePermissionlessConstantProductPool) SetPayerAccount(payer ag_solanago.PublicKey) *InitializeCustomizablePermissionlessConstantProductPool { + inst.AccountMetaSlice[17] = ag_solanago.Meta(payer).WRITE().SIGNER() + return inst +} + +// GetPayerAccount gets the "payer" account. +// Admin account. This account will be the admin of the pool, and the payer for PDA during initialize pool. +func (inst *InitializeCustomizablePermissionlessConstantProductPool) GetPayerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(17) +} + +// SetRentAccount sets the "rent" account. +// Rent account. +func (inst *InitializeCustomizablePermissionlessConstantProductPool) SetRentAccount(rent ag_solanago.PublicKey) *InitializeCustomizablePermissionlessConstantProductPool { + inst.AccountMetaSlice[18] = ag_solanago.Meta(rent) + return inst +} + +// GetRentAccount gets the "rent" account. +// Rent account. +func (inst *InitializeCustomizablePermissionlessConstantProductPool) GetRentAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(18) +} + +// SetMintMetadataAccount sets the "mintMetadata" account. +func (inst *InitializeCustomizablePermissionlessConstantProductPool) SetMintMetadataAccount(mintMetadata ag_solanago.PublicKey) *InitializeCustomizablePermissionlessConstantProductPool { + inst.AccountMetaSlice[19] = ag_solanago.Meta(mintMetadata).WRITE() + return inst +} + +// GetMintMetadataAccount gets the "mintMetadata" account. +func (inst *InitializeCustomizablePermissionlessConstantProductPool) GetMintMetadataAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(19) +} + +// SetMetadataProgramAccount sets the "metadataProgram" account. +func (inst *InitializeCustomizablePermissionlessConstantProductPool) SetMetadataProgramAccount(metadataProgram ag_solanago.PublicKey) *InitializeCustomizablePermissionlessConstantProductPool { + inst.AccountMetaSlice[20] = ag_solanago.Meta(metadataProgram) + return inst +} + +// GetMetadataProgramAccount gets the "metadataProgram" account. +func (inst *InitializeCustomizablePermissionlessConstantProductPool) GetMetadataProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(20) +} + +// SetVaultProgramAccount sets the "vaultProgram" account. +// Vault program. The pool will deposit/withdraw liquidity from the vault. +func (inst *InitializeCustomizablePermissionlessConstantProductPool) SetVaultProgramAccount(vaultProgram ag_solanago.PublicKey) *InitializeCustomizablePermissionlessConstantProductPool { + inst.AccountMetaSlice[21] = ag_solanago.Meta(vaultProgram) + return inst +} + +// GetVaultProgramAccount gets the "vaultProgram" account. +// Vault program. The pool will deposit/withdraw liquidity from the vault. +func (inst *InitializeCustomizablePermissionlessConstantProductPool) GetVaultProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(21) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +// Token program. +func (inst *InitializeCustomizablePermissionlessConstantProductPool) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *InitializeCustomizablePermissionlessConstantProductPool { + inst.AccountMetaSlice[22] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +// Token program. +func (inst *InitializeCustomizablePermissionlessConstantProductPool) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(22) +} + +// SetAssociatedTokenProgramAccount sets the "associatedTokenProgram" account. +// Associated token program. +func (inst *InitializeCustomizablePermissionlessConstantProductPool) SetAssociatedTokenProgramAccount(associatedTokenProgram ag_solanago.PublicKey) *InitializeCustomizablePermissionlessConstantProductPool { + inst.AccountMetaSlice[23] = ag_solanago.Meta(associatedTokenProgram) + return inst +} + +// GetAssociatedTokenProgramAccount gets the "associatedTokenProgram" account. +// Associated token program. +func (inst *InitializeCustomizablePermissionlessConstantProductPool) GetAssociatedTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(23) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +// System program. +func (inst *InitializeCustomizablePermissionlessConstantProductPool) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *InitializeCustomizablePermissionlessConstantProductPool { + inst.AccountMetaSlice[24] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +// System program. +func (inst *InitializeCustomizablePermissionlessConstantProductPool) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(24) +} + +func (inst InitializeCustomizablePermissionlessConstantProductPool) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_InitializeCustomizablePermissionlessConstantProductPool, + }} +} + +// 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 InitializeCustomizablePermissionlessConstantProductPool) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *InitializeCustomizablePermissionlessConstantProductPool) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.TokenAAmount == nil { + return errors.New("TokenAAmount parameter is not set") + } + if inst.TokenBAmount == nil { + return errors.New("TokenBAmount parameter is not set") + } + if inst.Params == nil { + return errors.New("Params parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Pool is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.LpMint is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.TokenAMint is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.TokenBMint is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.AVault is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.BVault is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.ATokenVault is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.BTokenVault is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.AVaultLpMint is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.BVaultLpMint is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.AVaultLp is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.BVaultLp is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.PayerTokenA is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.PayerTokenB is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.PayerPoolLp is not set") + } + if inst.AccountMetaSlice[15] == nil { + return errors.New("accounts.ProtocolTokenAFee is not set") + } + if inst.AccountMetaSlice[16] == nil { + return errors.New("accounts.ProtocolTokenBFee is not set") + } + if inst.AccountMetaSlice[17] == nil { + return errors.New("accounts.Payer is not set") + } + if inst.AccountMetaSlice[18] == nil { + return errors.New("accounts.Rent is not set") + } + if inst.AccountMetaSlice[19] == nil { + return errors.New("accounts.MintMetadata is not set") + } + if inst.AccountMetaSlice[20] == nil { + return errors.New("accounts.MetadataProgram is not set") + } + if inst.AccountMetaSlice[21] == nil { + return errors.New("accounts.VaultProgram is not set") + } + if inst.AccountMetaSlice[22] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[23] == nil { + return errors.New("accounts.AssociatedTokenProgram is not set") + } + if inst.AccountMetaSlice[24] == nil { + return errors.New("accounts.SystemProgram is not set") + } + } + return nil +} + +func (inst *InitializeCustomizablePermissionlessConstantProductPool) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("InitializeCustomizablePermissionlessConstantProductPool")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=3]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param("TokenAAmount", *inst.TokenAAmount)) + paramsBranch.Child(ag_format.Param("TokenBAmount", *inst.TokenBAmount)) + paramsBranch.Child(ag_format.Param(" Params", *inst.Params)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=25]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" pool", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" lpMint", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" tokenAMint", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" tokenBMint", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" aVault", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" bVault", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" aTokenVault", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" bTokenVault", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" aVaultLpMint", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" bVaultLpMint", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" aVaultLp", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" bVaultLp", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" payerTokenA", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" payerTokenB", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta(" payerPoolLp", inst.AccountMetaSlice.Get(14))) + accountsBranch.Child(ag_format.Meta(" protocolTokenAFee", inst.AccountMetaSlice.Get(15))) + accountsBranch.Child(ag_format.Meta(" protocolTokenBFee", inst.AccountMetaSlice.Get(16))) + accountsBranch.Child(ag_format.Meta(" payer", inst.AccountMetaSlice.Get(17))) + accountsBranch.Child(ag_format.Meta(" rent", inst.AccountMetaSlice.Get(18))) + accountsBranch.Child(ag_format.Meta(" mintMetadata", inst.AccountMetaSlice.Get(19))) + accountsBranch.Child(ag_format.Meta(" metadataProgram", inst.AccountMetaSlice.Get(20))) + accountsBranch.Child(ag_format.Meta(" vaultProgram", inst.AccountMetaSlice.Get(21))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(22))) + accountsBranch.Child(ag_format.Meta("associatedTokenProgram", inst.AccountMetaSlice.Get(23))) + accountsBranch.Child(ag_format.Meta(" systemProgram", inst.AccountMetaSlice.Get(24))) + }) + }) + }) +} + +func (obj InitializeCustomizablePermissionlessConstantProductPool) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `TokenAAmount` param: + err = encoder.Encode(obj.TokenAAmount) + if err != nil { + return err + } + // Serialize `TokenBAmount` param: + err = encoder.Encode(obj.TokenBAmount) + if err != nil { + return err + } + // Serialize `Params` param: + err = encoder.Encode(obj.Params) + if err != nil { + return err + } + return nil +} +func (obj *InitializeCustomizablePermissionlessConstantProductPool) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `TokenAAmount`: + err = decoder.Decode(&obj.TokenAAmount) + if err != nil { + return err + } + // Deserialize `TokenBAmount`: + err = decoder.Decode(&obj.TokenBAmount) + if err != nil { + return err + } + // Deserialize `Params`: + err = decoder.Decode(&obj.Params) + if err != nil { + return err + } + return nil +} + +// NewInitializeCustomizablePermissionlessConstantProductPoolInstruction declares a new InitializeCustomizablePermissionlessConstantProductPool instruction with the provided parameters and accounts. +func NewInitializeCustomizablePermissionlessConstantProductPoolInstruction( + // Parameters: + tokenAAmount uint64, + tokenBAmount uint64, + params CustomizableParams, + // Accounts: + pool ag_solanago.PublicKey, + lpMint ag_solanago.PublicKey, + tokenAMint ag_solanago.PublicKey, + tokenBMint ag_solanago.PublicKey, + aVault ag_solanago.PublicKey, + bVault ag_solanago.PublicKey, + aTokenVault ag_solanago.PublicKey, + bTokenVault ag_solanago.PublicKey, + aVaultLpMint ag_solanago.PublicKey, + bVaultLpMint ag_solanago.PublicKey, + aVaultLp ag_solanago.PublicKey, + bVaultLp ag_solanago.PublicKey, + payerTokenA ag_solanago.PublicKey, + payerTokenB ag_solanago.PublicKey, + payerPoolLp ag_solanago.PublicKey, + protocolTokenAFee ag_solanago.PublicKey, + protocolTokenBFee ag_solanago.PublicKey, + payer ag_solanago.PublicKey, + rent ag_solanago.PublicKey, + mintMetadata ag_solanago.PublicKey, + metadataProgram ag_solanago.PublicKey, + vaultProgram ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + associatedTokenProgram ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey) *InitializeCustomizablePermissionlessConstantProductPool { + return NewInitializeCustomizablePermissionlessConstantProductPoolInstructionBuilder(). + SetTokenAAmount(tokenAAmount). + SetTokenBAmount(tokenBAmount). + SetParams(params). + SetPoolAccount(pool). + SetLpMintAccount(lpMint). + SetTokenAMintAccount(tokenAMint). + SetTokenBMintAccount(tokenBMint). + SetAVaultAccount(aVault). + SetBVaultAccount(bVault). + SetATokenVaultAccount(aTokenVault). + SetBTokenVaultAccount(bTokenVault). + SetAVaultLpMintAccount(aVaultLpMint). + SetBVaultLpMintAccount(bVaultLpMint). + SetAVaultLpAccount(aVaultLp). + SetBVaultLpAccount(bVaultLp). + SetPayerTokenAAccount(payerTokenA). + SetPayerTokenBAccount(payerTokenB). + SetPayerPoolLpAccount(payerPoolLp). + SetProtocolTokenAFeeAccount(protocolTokenAFee). + SetProtocolTokenBFeeAccount(protocolTokenBFee). + SetPayerAccount(payer). + SetRentAccount(rent). + SetMintMetadataAccount(mintMetadata). + SetMetadataProgramAccount(metadataProgram). + SetVaultProgramAccount(vaultProgram). + SetTokenProgramAccount(tokenProgram). + SetAssociatedTokenProgramAccount(associatedTokenProgram). + SetSystemProgramAccount(systemProgram) +} diff --git a/programs/meteorapools/InitializeCustomizablePermissionlessConstantProductPool_test.go b/programs/meteorapools/InitializeCustomizablePermissionlessConstantProductPool_test.go new file mode 100644 index 00000000..4d13f755 --- /dev/null +++ b/programs/meteorapools/InitializeCustomizablePermissionlessConstantProductPool_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_InitializeCustomizablePermissionlessConstantProductPool(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("InitializeCustomizablePermissionlessConstantProductPool"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(InitializeCustomizablePermissionlessConstantProductPool) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(InitializeCustomizablePermissionlessConstantProductPool) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteorapools/InitializePermissionedPool.go b/programs/meteorapools/InitializePermissionedPool.go new file mode 100644 index 00000000..93f03298 --- /dev/null +++ b/programs/meteorapools/InitializePermissionedPool.go @@ -0,0 +1,653 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "errors" + "fmt" + 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" +) + +// Initialize a new permissioned pool. +type InitializePermissionedPool struct { + CurveType CurveType + + // [0] = [WRITE, SIGNER] pool + // ··········· Pool account (arbitrary address) + // + // [1] = [WRITE] lpMint + // ··········· LP token mint of the pool + // + // [2] = [] tokenAMint + // ··········· Token A mint of the pool. Eg: USDT + // + // [3] = [] tokenBMint + // ··········· Token B mint of the pool. Eg: USDC + // + // [4] = [WRITE] aVault + // ··········· Vault account for token A. Token A of the pool will be deposit / withdraw from this vault account. + // + // [5] = [WRITE] bVault + // ··········· Vault account for token B. Token B of the pool will be deposit / withdraw from this vault account. + // + // [6] = [WRITE] aVaultLpMint + // ··········· LP token mint of vault A + // + // [7] = [WRITE] bVaultLpMint + // ··········· LP token mint of vault B + // + // [8] = [WRITE] aVaultLp + // ··········· LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. + // + // [9] = [WRITE] bVaultLp + // ··········· LP token account of vault B. Used to receive/burn vault LP upon deposit/withdraw from the vault. + // + // [10] = [WRITE] adminTokenA + // ··········· Admin token account for pool token A mint. Used to bootstrap the pool with initial liquidity. + // + // [11] = [WRITE] adminTokenB + // ··········· Admin token account for pool token B mint. Used to bootstrap the pool with initial liquidity. + // + // [12] = [WRITE] adminPoolLp + // ··········· Admin pool LP token account. Used to receive LP during first deposit (initialize pool) + // ··········· Admin pool LP token account. Used to receive LP during first deposit (initialize pool) + // + // [13] = [WRITE] protocolTokenAFee + // ··········· Protocol fee token account for token A. Used to receive trading fee. + // + // [14] = [WRITE] protocolTokenBFee + // ··········· Protocol fee token account for token B. Used to receive trading fee. + // + // [15] = [WRITE, SIGNER] admin + // ··········· Admin account. This account will be the admin of the pool, and the payer for PDA during initialize pool. + // + // [16] = [] feeOwner + // + // [17] = [] rent + // ··········· Rent account. + // + // [18] = [WRITE] mintMetadata + // + // [19] = [] metadataProgram + // + // [20] = [] vaultProgram + // ··········· Vault program. The pool will deposit/withdraw liquidity from the vault. + // + // [21] = [] tokenProgram + // ··········· Token program. + // + // [22] = [] associatedTokenProgram + // ··········· Associated token program. + // + // [23] = [] systemProgram + // ··········· System program. + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewInitializePermissionedPoolInstructionBuilder creates a new `InitializePermissionedPool` instruction builder. +func NewInitializePermissionedPoolInstructionBuilder() *InitializePermissionedPool { + nd := &InitializePermissionedPool{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 24), + } + return nd +} + +// SetCurveType sets the "curveType" parameter. +func (inst *InitializePermissionedPool) SetCurveType(curveType CurveType) *InitializePermissionedPool { + inst.CurveType = curveType + return inst +} + +// SetPoolAccount sets the "pool" account. +// Pool account (arbitrary address) +func (inst *InitializePermissionedPool) SetPoolAccount(pool ag_solanago.PublicKey) *InitializePermissionedPool { + inst.AccountMetaSlice[0] = ag_solanago.Meta(pool).WRITE().SIGNER() + return inst +} + +// GetPoolAccount gets the "pool" account. +// Pool account (arbitrary address) +func (inst *InitializePermissionedPool) GetPoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetLpMintAccount sets the "lpMint" account. +// LP token mint of the pool +func (inst *InitializePermissionedPool) SetLpMintAccount(lpMint ag_solanago.PublicKey) *InitializePermissionedPool { + inst.AccountMetaSlice[1] = ag_solanago.Meta(lpMint).WRITE() + return inst +} + +// GetLpMintAccount gets the "lpMint" account. +// LP token mint of the pool +func (inst *InitializePermissionedPool) GetLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetTokenAMintAccount sets the "tokenAMint" account. +// Token A mint of the pool. Eg: USDT +func (inst *InitializePermissionedPool) SetTokenAMintAccount(tokenAMint ag_solanago.PublicKey) *InitializePermissionedPool { + inst.AccountMetaSlice[2] = ag_solanago.Meta(tokenAMint) + return inst +} + +// GetTokenAMintAccount gets the "tokenAMint" account. +// Token A mint of the pool. Eg: USDT +func (inst *InitializePermissionedPool) GetTokenAMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetTokenBMintAccount sets the "tokenBMint" account. +// Token B mint of the pool. Eg: USDC +func (inst *InitializePermissionedPool) SetTokenBMintAccount(tokenBMint ag_solanago.PublicKey) *InitializePermissionedPool { + inst.AccountMetaSlice[3] = ag_solanago.Meta(tokenBMint) + return inst +} + +// GetTokenBMintAccount gets the "tokenBMint" account. +// Token B mint of the pool. Eg: USDC +func (inst *InitializePermissionedPool) GetTokenBMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetAVaultAccount sets the "aVault" account. +// Vault account for token A. Token A of the pool will be deposit / withdraw from this vault account. +func (inst *InitializePermissionedPool) SetAVaultAccount(aVault ag_solanago.PublicKey) *InitializePermissionedPool { + inst.AccountMetaSlice[4] = ag_solanago.Meta(aVault).WRITE() + return inst +} + +// GetAVaultAccount gets the "aVault" account. +// Vault account for token A. Token A of the pool will be deposit / withdraw from this vault account. +func (inst *InitializePermissionedPool) GetAVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetBVaultAccount sets the "bVault" account. +// Vault account for token B. Token B of the pool will be deposit / withdraw from this vault account. +func (inst *InitializePermissionedPool) SetBVaultAccount(bVault ag_solanago.PublicKey) *InitializePermissionedPool { + inst.AccountMetaSlice[5] = ag_solanago.Meta(bVault).WRITE() + return inst +} + +// GetBVaultAccount gets the "bVault" account. +// Vault account for token B. Token B of the pool will be deposit / withdraw from this vault account. +func (inst *InitializePermissionedPool) GetBVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetAVaultLpMintAccount sets the "aVaultLpMint" account. +// LP token mint of vault A +func (inst *InitializePermissionedPool) SetAVaultLpMintAccount(aVaultLpMint ag_solanago.PublicKey) *InitializePermissionedPool { + inst.AccountMetaSlice[6] = ag_solanago.Meta(aVaultLpMint).WRITE() + return inst +} + +// GetAVaultLpMintAccount gets the "aVaultLpMint" account. +// LP token mint of vault A +func (inst *InitializePermissionedPool) GetAVaultLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetBVaultLpMintAccount sets the "bVaultLpMint" account. +// LP token mint of vault B +func (inst *InitializePermissionedPool) SetBVaultLpMintAccount(bVaultLpMint ag_solanago.PublicKey) *InitializePermissionedPool { + inst.AccountMetaSlice[7] = ag_solanago.Meta(bVaultLpMint).WRITE() + return inst +} + +// GetBVaultLpMintAccount gets the "bVaultLpMint" account. +// LP token mint of vault B +func (inst *InitializePermissionedPool) GetBVaultLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetAVaultLpAccount sets the "aVaultLp" account. +// LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *InitializePermissionedPool) SetAVaultLpAccount(aVaultLp ag_solanago.PublicKey) *InitializePermissionedPool { + inst.AccountMetaSlice[8] = ag_solanago.Meta(aVaultLp).WRITE() + return inst +} + +// GetAVaultLpAccount gets the "aVaultLp" account. +// LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *InitializePermissionedPool) GetAVaultLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetBVaultLpAccount sets the "bVaultLp" account. +// LP token account of vault B. Used to receive/burn vault LP upon deposit/withdraw from the vault. +func (inst *InitializePermissionedPool) SetBVaultLpAccount(bVaultLp ag_solanago.PublicKey) *InitializePermissionedPool { + inst.AccountMetaSlice[9] = ag_solanago.Meta(bVaultLp).WRITE() + return inst +} + +// GetBVaultLpAccount gets the "bVaultLp" account. +// LP token account of vault B. Used to receive/burn vault LP upon deposit/withdraw from the vault. +func (inst *InitializePermissionedPool) GetBVaultLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetAdminTokenAAccount sets the "adminTokenA" account. +// Admin token account for pool token A mint. Used to bootstrap the pool with initial liquidity. +func (inst *InitializePermissionedPool) SetAdminTokenAAccount(adminTokenA ag_solanago.PublicKey) *InitializePermissionedPool { + inst.AccountMetaSlice[10] = ag_solanago.Meta(adminTokenA).WRITE() + return inst +} + +// GetAdminTokenAAccount gets the "adminTokenA" account. +// Admin token account for pool token A mint. Used to bootstrap the pool with initial liquidity. +func (inst *InitializePermissionedPool) GetAdminTokenAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetAdminTokenBAccount sets the "adminTokenB" account. +// Admin token account for pool token B mint. Used to bootstrap the pool with initial liquidity. +func (inst *InitializePermissionedPool) SetAdminTokenBAccount(adminTokenB ag_solanago.PublicKey) *InitializePermissionedPool { + inst.AccountMetaSlice[11] = ag_solanago.Meta(adminTokenB).WRITE() + return inst +} + +// GetAdminTokenBAccount gets the "adminTokenB" account. +// Admin token account for pool token B mint. Used to bootstrap the pool with initial liquidity. +func (inst *InitializePermissionedPool) GetAdminTokenBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetAdminPoolLpAccount sets the "adminPoolLp" account. +// Admin pool LP token account. Used to receive LP during first deposit (initialize pool) +// Admin pool LP token account. Used to receive LP during first deposit (initialize pool) +func (inst *InitializePermissionedPool) SetAdminPoolLpAccount(adminPoolLp ag_solanago.PublicKey) *InitializePermissionedPool { + inst.AccountMetaSlice[12] = ag_solanago.Meta(adminPoolLp).WRITE() + return inst +} + +// GetAdminPoolLpAccount gets the "adminPoolLp" account. +// Admin pool LP token account. Used to receive LP during first deposit (initialize pool) +// Admin pool LP token account. Used to receive LP during first deposit (initialize pool) +func (inst *InitializePermissionedPool) GetAdminPoolLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetProtocolTokenAFeeAccount sets the "protocolTokenAFee" account. +// Protocol fee token account for token A. Used to receive trading fee. +func (inst *InitializePermissionedPool) SetProtocolTokenAFeeAccount(protocolTokenAFee ag_solanago.PublicKey) *InitializePermissionedPool { + inst.AccountMetaSlice[13] = ag_solanago.Meta(protocolTokenAFee).WRITE() + return inst +} + +// GetProtocolTokenAFeeAccount gets the "protocolTokenAFee" account. +// Protocol fee token account for token A. Used to receive trading fee. +func (inst *InitializePermissionedPool) GetProtocolTokenAFeeAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetProtocolTokenBFeeAccount sets the "protocolTokenBFee" account. +// Protocol fee token account for token B. Used to receive trading fee. +func (inst *InitializePermissionedPool) SetProtocolTokenBFeeAccount(protocolTokenBFee ag_solanago.PublicKey) *InitializePermissionedPool { + inst.AccountMetaSlice[14] = ag_solanago.Meta(protocolTokenBFee).WRITE() + return inst +} + +// GetProtocolTokenBFeeAccount gets the "protocolTokenBFee" account. +// Protocol fee token account for token B. Used to receive trading fee. +func (inst *InitializePermissionedPool) GetProtocolTokenBFeeAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +// SetAdminAccount sets the "admin" account. +// Admin account. This account will be the admin of the pool, and the payer for PDA during initialize pool. +func (inst *InitializePermissionedPool) SetAdminAccount(admin ag_solanago.PublicKey) *InitializePermissionedPool { + inst.AccountMetaSlice[15] = ag_solanago.Meta(admin).WRITE().SIGNER() + return inst +} + +// GetAdminAccount gets the "admin" account. +// Admin account. This account will be the admin of the pool, and the payer for PDA during initialize pool. +func (inst *InitializePermissionedPool) GetAdminAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(15) +} + +// SetFeeOwnerAccount sets the "feeOwner" account. +func (inst *InitializePermissionedPool) SetFeeOwnerAccount(feeOwner ag_solanago.PublicKey) *InitializePermissionedPool { + inst.AccountMetaSlice[16] = ag_solanago.Meta(feeOwner) + return inst +} + +// GetFeeOwnerAccount gets the "feeOwner" account. +func (inst *InitializePermissionedPool) GetFeeOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(16) +} + +// SetRentAccount sets the "rent" account. +// Rent account. +func (inst *InitializePermissionedPool) SetRentAccount(rent ag_solanago.PublicKey) *InitializePermissionedPool { + inst.AccountMetaSlice[17] = ag_solanago.Meta(rent) + return inst +} + +// GetRentAccount gets the "rent" account. +// Rent account. +func (inst *InitializePermissionedPool) GetRentAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(17) +} + +// SetMintMetadataAccount sets the "mintMetadata" account. +func (inst *InitializePermissionedPool) SetMintMetadataAccount(mintMetadata ag_solanago.PublicKey) *InitializePermissionedPool { + inst.AccountMetaSlice[18] = ag_solanago.Meta(mintMetadata).WRITE() + return inst +} + +// GetMintMetadataAccount gets the "mintMetadata" account. +func (inst *InitializePermissionedPool) GetMintMetadataAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(18) +} + +// SetMetadataProgramAccount sets the "metadataProgram" account. +func (inst *InitializePermissionedPool) SetMetadataProgramAccount(metadataProgram ag_solanago.PublicKey) *InitializePermissionedPool { + inst.AccountMetaSlice[19] = ag_solanago.Meta(metadataProgram) + return inst +} + +// GetMetadataProgramAccount gets the "metadataProgram" account. +func (inst *InitializePermissionedPool) GetMetadataProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(19) +} + +// SetVaultProgramAccount sets the "vaultProgram" account. +// Vault program. The pool will deposit/withdraw liquidity from the vault. +func (inst *InitializePermissionedPool) SetVaultProgramAccount(vaultProgram ag_solanago.PublicKey) *InitializePermissionedPool { + inst.AccountMetaSlice[20] = ag_solanago.Meta(vaultProgram) + return inst +} + +// GetVaultProgramAccount gets the "vaultProgram" account. +// Vault program. The pool will deposit/withdraw liquidity from the vault. +func (inst *InitializePermissionedPool) GetVaultProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(20) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +// Token program. +func (inst *InitializePermissionedPool) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *InitializePermissionedPool { + inst.AccountMetaSlice[21] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +// Token program. +func (inst *InitializePermissionedPool) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(21) +} + +// SetAssociatedTokenProgramAccount sets the "associatedTokenProgram" account. +// Associated token program. +func (inst *InitializePermissionedPool) SetAssociatedTokenProgramAccount(associatedTokenProgram ag_solanago.PublicKey) *InitializePermissionedPool { + inst.AccountMetaSlice[22] = ag_solanago.Meta(associatedTokenProgram) + return inst +} + +// GetAssociatedTokenProgramAccount gets the "associatedTokenProgram" account. +// Associated token program. +func (inst *InitializePermissionedPool) GetAssociatedTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(22) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +// System program. +func (inst *InitializePermissionedPool) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *InitializePermissionedPool { + inst.AccountMetaSlice[23] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +// System program. +func (inst *InitializePermissionedPool) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(23) +} + +func (inst InitializePermissionedPool) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_InitializePermissionedPool, + }} +} + +// 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 InitializePermissionedPool) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *InitializePermissionedPool) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.CurveType == nil { + return errors.New("CurveType parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Pool is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.LpMint is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.TokenAMint is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.TokenBMint is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.AVault is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.BVault is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.AVaultLpMint is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.BVaultLpMint is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.AVaultLp is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.BVaultLp is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.AdminTokenA is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.AdminTokenB is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.AdminPoolLp is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.ProtocolTokenAFee is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.ProtocolTokenBFee is not set") + } + if inst.AccountMetaSlice[15] == nil { + return errors.New("accounts.Admin is not set") + } + if inst.AccountMetaSlice[16] == nil { + return errors.New("accounts.FeeOwner is not set") + } + if inst.AccountMetaSlice[17] == nil { + return errors.New("accounts.Rent is not set") + } + if inst.AccountMetaSlice[18] == nil { + return errors.New("accounts.MintMetadata is not set") + } + if inst.AccountMetaSlice[19] == nil { + return errors.New("accounts.MetadataProgram is not set") + } + if inst.AccountMetaSlice[20] == nil { + return errors.New("accounts.VaultProgram is not set") + } + if inst.AccountMetaSlice[21] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[22] == nil { + return errors.New("accounts.AssociatedTokenProgram is not set") + } + if inst.AccountMetaSlice[23] == nil { + return errors.New("accounts.SystemProgram is not set") + } + } + return nil +} + +func (inst *InitializePermissionedPool) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("InitializePermissionedPool")). + // + 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("CurveType", inst.CurveType)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=24]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" pool", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" lpMint", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" tokenAMint", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" tokenBMint", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" aVault", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" bVault", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" aVaultLpMint", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" bVaultLpMint", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" aVaultLp", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" bVaultLp", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" adminTokenA", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" adminTokenB", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" adminPoolLp", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" protocolTokenAFee", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta(" protocolTokenBFee", inst.AccountMetaSlice.Get(14))) + accountsBranch.Child(ag_format.Meta(" admin", inst.AccountMetaSlice.Get(15))) + accountsBranch.Child(ag_format.Meta(" feeOwner", inst.AccountMetaSlice.Get(16))) + accountsBranch.Child(ag_format.Meta(" rent", inst.AccountMetaSlice.Get(17))) + accountsBranch.Child(ag_format.Meta(" mintMetadata", inst.AccountMetaSlice.Get(18))) + accountsBranch.Child(ag_format.Meta(" metadataProgram", inst.AccountMetaSlice.Get(19))) + accountsBranch.Child(ag_format.Meta(" vaultProgram", inst.AccountMetaSlice.Get(20))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(21))) + accountsBranch.Child(ag_format.Meta("associatedTokenProgram", inst.AccountMetaSlice.Get(22))) + accountsBranch.Child(ag_format.Meta(" systemProgram", inst.AccountMetaSlice.Get(23))) + }) + }) + }) +} + +func (obj InitializePermissionedPool) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `CurveType` param: + { + tmp := curveTypeContainer{} + switch realvalue := obj.CurveType.(type) { + case *CurveTypeConstantProduct: + tmp.Enum = 0 + tmp.ConstantProduct = *realvalue + case *CurveTypeStable: + tmp.Enum = 1 + tmp.Stable = *realvalue + } + err := encoder.Encode(tmp) + if err != nil { + return err + } + } + return nil +} +func (obj *InitializePermissionedPool) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `CurveType`: + { + tmp := new(curveTypeContainer) + err := decoder.Decode(tmp) + if err != nil { + return err + } + switch tmp.Enum { + case 0: + obj.CurveType = (*CurveTypeConstantProduct)(&tmp.Enum) + case 1: + obj.CurveType = &tmp.Stable + default: + return fmt.Errorf("unknown enum index: %v", tmp.Enum) + } + } + return nil +} + +// NewInitializePermissionedPoolInstruction declares a new InitializePermissionedPool instruction with the provided parameters and accounts. +func NewInitializePermissionedPoolInstruction( + // Parameters: + curveType CurveType, + // Accounts: + pool ag_solanago.PublicKey, + lpMint ag_solanago.PublicKey, + tokenAMint ag_solanago.PublicKey, + tokenBMint ag_solanago.PublicKey, + aVault ag_solanago.PublicKey, + bVault ag_solanago.PublicKey, + aVaultLpMint ag_solanago.PublicKey, + bVaultLpMint ag_solanago.PublicKey, + aVaultLp ag_solanago.PublicKey, + bVaultLp ag_solanago.PublicKey, + adminTokenA ag_solanago.PublicKey, + adminTokenB ag_solanago.PublicKey, + adminPoolLp ag_solanago.PublicKey, + protocolTokenAFee ag_solanago.PublicKey, + protocolTokenBFee ag_solanago.PublicKey, + admin ag_solanago.PublicKey, + feeOwner ag_solanago.PublicKey, + rent ag_solanago.PublicKey, + mintMetadata ag_solanago.PublicKey, + metadataProgram ag_solanago.PublicKey, + vaultProgram ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + associatedTokenProgram ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey) *InitializePermissionedPool { + return NewInitializePermissionedPoolInstructionBuilder(). + SetCurveType(curveType). + SetPoolAccount(pool). + SetLpMintAccount(lpMint). + SetTokenAMintAccount(tokenAMint). + SetTokenBMintAccount(tokenBMint). + SetAVaultAccount(aVault). + SetBVaultAccount(bVault). + SetAVaultLpMintAccount(aVaultLpMint). + SetBVaultLpMintAccount(bVaultLpMint). + SetAVaultLpAccount(aVaultLp). + SetBVaultLpAccount(bVaultLp). + SetAdminTokenAAccount(adminTokenA). + SetAdminTokenBAccount(adminTokenB). + SetAdminPoolLpAccount(adminPoolLp). + SetProtocolTokenAFeeAccount(protocolTokenAFee). + SetProtocolTokenBFeeAccount(protocolTokenBFee). + SetAdminAccount(admin). + SetFeeOwnerAccount(feeOwner). + SetRentAccount(rent). + SetMintMetadataAccount(mintMetadata). + SetMetadataProgramAccount(metadataProgram). + SetVaultProgramAccount(vaultProgram). + SetTokenProgramAccount(tokenProgram). + SetAssociatedTokenProgramAccount(associatedTokenProgram). + SetSystemProgramAccount(systemProgram) +} diff --git a/programs/meteorapools/InitializePermissionedPool_test.go b/programs/meteorapools/InitializePermissionedPool_test.go new file mode 100644 index 00000000..fde71ad9 --- /dev/null +++ b/programs/meteorapools/InitializePermissionedPool_test.go @@ -0,0 +1,55 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_InitializePermissionedPool(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("InitializePermissionedPool"+strconv.Itoa(i), func(t *testing.T) { + { + { + { + params := new(InitializePermissionedPool) + fu.Fuzz(params) + params.AccountMetaSlice = nil + tmp := new(ConstantProduct) + fu.Fuzz(tmp) + params.SetCurveType(tmp) + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(InitializePermissionedPool) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + { + params := new(InitializePermissionedPool) + fu.Fuzz(params) + params.AccountMetaSlice = nil + tmp := new(Stable) + fu.Fuzz(tmp) + params.SetCurveType(tmp) + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(InitializePermissionedPool) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + } + } + }) + } +} diff --git a/programs/meteorapools/InitializePermissionlessConstantProductPoolWithConfig.go b/programs/meteorapools/InitializePermissionlessConstantProductPoolWithConfig.go new file mode 100644 index 00000000..e229b538 --- /dev/null +++ b/programs/meteorapools/InitializePermissionlessConstantProductPoolWithConfig.go @@ -0,0 +1,691 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "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" +) + +// Initialize permissionless pool with config +type InitializePermissionlessConstantProductPoolWithConfig struct { + TokenAAmount *uint64 + TokenBAmount *uint64 + + // [0] = [WRITE] pool + // ··········· Pool account (PDA address) + // + // [1] = [] config + // + // [2] = [WRITE] lpMint + // ··········· LP token mint of the pool + // + // [3] = [] tokenAMint + // ··········· Token A mint of the pool. Eg: USDT + // + // [4] = [] tokenBMint + // ··········· Token B mint of the pool. Eg: USDC + // + // [5] = [WRITE] aVault + // ··········· Vault account for token A. Token A of the pool will be deposit / withdraw from this vault account. + // + // [6] = [WRITE] bVault + // ··········· Vault account for token B. Token B of the pool will be deposit / withdraw from this vault account. + // + // [7] = [WRITE] aTokenVault + // ··········· Token vault account of vault A + // + // [8] = [WRITE] bTokenVault + // ··········· Token vault account of vault B + // + // [9] = [WRITE] aVaultLpMint + // ··········· LP token mint of vault A + // + // [10] = [WRITE] bVaultLpMint + // ··········· LP token mint of vault B + // + // [11] = [WRITE] aVaultLp + // ··········· LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. + // + // [12] = [WRITE] bVaultLp + // ··········· LP token account of vault B. Used to receive/burn vault LP upon deposit/withdraw from the vault. + // + // [13] = [WRITE] payerTokenA + // ··········· Payer token account for pool token A mint. Used to bootstrap the pool with initial liquidity. + // + // [14] = [WRITE] payerTokenB + // ··········· Admin token account for pool token B mint. Used to bootstrap the pool with initial liquidity. + // + // [15] = [WRITE] payerPoolLp + // + // [16] = [WRITE] protocolTokenAFee + // ··········· Protocol fee token account for token A. Used to receive trading fee. + // + // [17] = [WRITE] protocolTokenBFee + // ··········· Protocol fee token account for token B. Used to receive trading fee. + // + // [18] = [WRITE, SIGNER] payer + // ··········· Admin account. This account will be the admin of the pool, and the payer for PDA during initialize pool. + // + // [19] = [] rent + // ··········· Rent account. + // + // [20] = [WRITE] mintMetadata + // + // [21] = [] metadataProgram + // + // [22] = [] vaultProgram + // ··········· Vault program. The pool will deposit/withdraw liquidity from the vault. + // + // [23] = [] tokenProgram + // ··········· Token program. + // + // [24] = [] associatedTokenProgram + // ··········· Associated token program. + // + // [25] = [] systemProgram + // ··········· System program. + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewInitializePermissionlessConstantProductPoolWithConfigInstructionBuilder creates a new `InitializePermissionlessConstantProductPoolWithConfig` instruction builder. +func NewInitializePermissionlessConstantProductPoolWithConfigInstructionBuilder() *InitializePermissionlessConstantProductPoolWithConfig { + nd := &InitializePermissionlessConstantProductPoolWithConfig{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 26), + } + return nd +} + +// SetTokenAAmount sets the "tokenAAmount" parameter. +func (inst *InitializePermissionlessConstantProductPoolWithConfig) SetTokenAAmount(tokenAAmount uint64) *InitializePermissionlessConstantProductPoolWithConfig { + inst.TokenAAmount = &tokenAAmount + return inst +} + +// SetTokenBAmount sets the "tokenBAmount" parameter. +func (inst *InitializePermissionlessConstantProductPoolWithConfig) SetTokenBAmount(tokenBAmount uint64) *InitializePermissionlessConstantProductPoolWithConfig { + inst.TokenBAmount = &tokenBAmount + return inst +} + +// SetPoolAccount sets the "pool" account. +// Pool account (PDA address) +func (inst *InitializePermissionlessConstantProductPoolWithConfig) SetPoolAccount(pool ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig { + inst.AccountMetaSlice[0] = ag_solanago.Meta(pool).WRITE() + return inst +} + +// GetPoolAccount gets the "pool" account. +// Pool account (PDA address) +func (inst *InitializePermissionlessConstantProductPoolWithConfig) GetPoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetConfigAccount sets the "config" account. +func (inst *InitializePermissionlessConstantProductPoolWithConfig) SetConfigAccount(config ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig { + inst.AccountMetaSlice[1] = ag_solanago.Meta(config) + return inst +} + +// GetConfigAccount gets the "config" account. +func (inst *InitializePermissionlessConstantProductPoolWithConfig) GetConfigAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetLpMintAccount sets the "lpMint" account. +// LP token mint of the pool +func (inst *InitializePermissionlessConstantProductPoolWithConfig) SetLpMintAccount(lpMint ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig { + inst.AccountMetaSlice[2] = ag_solanago.Meta(lpMint).WRITE() + return inst +} + +// GetLpMintAccount gets the "lpMint" account. +// LP token mint of the pool +func (inst *InitializePermissionlessConstantProductPoolWithConfig) GetLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetTokenAMintAccount sets the "tokenAMint" account. +// Token A mint of the pool. Eg: USDT +func (inst *InitializePermissionlessConstantProductPoolWithConfig) SetTokenAMintAccount(tokenAMint ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig { + inst.AccountMetaSlice[3] = ag_solanago.Meta(tokenAMint) + return inst +} + +// GetTokenAMintAccount gets the "tokenAMint" account. +// Token A mint of the pool. Eg: USDT +func (inst *InitializePermissionlessConstantProductPoolWithConfig) GetTokenAMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetTokenBMintAccount sets the "tokenBMint" account. +// Token B mint of the pool. Eg: USDC +func (inst *InitializePermissionlessConstantProductPoolWithConfig) SetTokenBMintAccount(tokenBMint ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig { + inst.AccountMetaSlice[4] = ag_solanago.Meta(tokenBMint) + return inst +} + +// GetTokenBMintAccount gets the "tokenBMint" account. +// Token B mint of the pool. Eg: USDC +func (inst *InitializePermissionlessConstantProductPoolWithConfig) GetTokenBMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetAVaultAccount sets the "aVault" account. +// Vault account for token A. Token A of the pool will be deposit / withdraw from this vault account. +func (inst *InitializePermissionlessConstantProductPoolWithConfig) SetAVaultAccount(aVault ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig { + inst.AccountMetaSlice[5] = ag_solanago.Meta(aVault).WRITE() + return inst +} + +// GetAVaultAccount gets the "aVault" account. +// Vault account for token A. Token A of the pool will be deposit / withdraw from this vault account. +func (inst *InitializePermissionlessConstantProductPoolWithConfig) GetAVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetBVaultAccount sets the "bVault" account. +// Vault account for token B. Token B of the pool will be deposit / withdraw from this vault account. +func (inst *InitializePermissionlessConstantProductPoolWithConfig) SetBVaultAccount(bVault ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig { + inst.AccountMetaSlice[6] = ag_solanago.Meta(bVault).WRITE() + return inst +} + +// GetBVaultAccount gets the "bVault" account. +// Vault account for token B. Token B of the pool will be deposit / withdraw from this vault account. +func (inst *InitializePermissionlessConstantProductPoolWithConfig) GetBVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetATokenVaultAccount sets the "aTokenVault" account. +// Token vault account of vault A +func (inst *InitializePermissionlessConstantProductPoolWithConfig) SetATokenVaultAccount(aTokenVault ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig { + inst.AccountMetaSlice[7] = ag_solanago.Meta(aTokenVault).WRITE() + return inst +} + +// GetATokenVaultAccount gets the "aTokenVault" account. +// Token vault account of vault A +func (inst *InitializePermissionlessConstantProductPoolWithConfig) GetATokenVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetBTokenVaultAccount sets the "bTokenVault" account. +// Token vault account of vault B +func (inst *InitializePermissionlessConstantProductPoolWithConfig) SetBTokenVaultAccount(bTokenVault ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig { + inst.AccountMetaSlice[8] = ag_solanago.Meta(bTokenVault).WRITE() + return inst +} + +// GetBTokenVaultAccount gets the "bTokenVault" account. +// Token vault account of vault B +func (inst *InitializePermissionlessConstantProductPoolWithConfig) GetBTokenVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetAVaultLpMintAccount sets the "aVaultLpMint" account. +// LP token mint of vault A +func (inst *InitializePermissionlessConstantProductPoolWithConfig) SetAVaultLpMintAccount(aVaultLpMint ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig { + inst.AccountMetaSlice[9] = ag_solanago.Meta(aVaultLpMint).WRITE() + return inst +} + +// GetAVaultLpMintAccount gets the "aVaultLpMint" account. +// LP token mint of vault A +func (inst *InitializePermissionlessConstantProductPoolWithConfig) GetAVaultLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetBVaultLpMintAccount sets the "bVaultLpMint" account. +// LP token mint of vault B +func (inst *InitializePermissionlessConstantProductPoolWithConfig) SetBVaultLpMintAccount(bVaultLpMint ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig { + inst.AccountMetaSlice[10] = ag_solanago.Meta(bVaultLpMint).WRITE() + return inst +} + +// GetBVaultLpMintAccount gets the "bVaultLpMint" account. +// LP token mint of vault B +func (inst *InitializePermissionlessConstantProductPoolWithConfig) GetBVaultLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetAVaultLpAccount sets the "aVaultLp" account. +// LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *InitializePermissionlessConstantProductPoolWithConfig) SetAVaultLpAccount(aVaultLp ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig { + inst.AccountMetaSlice[11] = ag_solanago.Meta(aVaultLp).WRITE() + return inst +} + +// GetAVaultLpAccount gets the "aVaultLp" account. +// LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *InitializePermissionlessConstantProductPoolWithConfig) GetAVaultLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetBVaultLpAccount sets the "bVaultLp" account. +// LP token account of vault B. Used to receive/burn vault LP upon deposit/withdraw from the vault. +func (inst *InitializePermissionlessConstantProductPoolWithConfig) SetBVaultLpAccount(bVaultLp ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig { + inst.AccountMetaSlice[12] = ag_solanago.Meta(bVaultLp).WRITE() + return inst +} + +// GetBVaultLpAccount gets the "bVaultLp" account. +// LP token account of vault B. Used to receive/burn vault LP upon deposit/withdraw from the vault. +func (inst *InitializePermissionlessConstantProductPoolWithConfig) GetBVaultLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetPayerTokenAAccount sets the "payerTokenA" account. +// Payer token account for pool token A mint. Used to bootstrap the pool with initial liquidity. +func (inst *InitializePermissionlessConstantProductPoolWithConfig) SetPayerTokenAAccount(payerTokenA ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig { + inst.AccountMetaSlice[13] = ag_solanago.Meta(payerTokenA).WRITE() + return inst +} + +// GetPayerTokenAAccount gets the "payerTokenA" account. +// Payer token account for pool token A mint. Used to bootstrap the pool with initial liquidity. +func (inst *InitializePermissionlessConstantProductPoolWithConfig) GetPayerTokenAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetPayerTokenBAccount sets the "payerTokenB" account. +// Admin token account for pool token B mint. Used to bootstrap the pool with initial liquidity. +func (inst *InitializePermissionlessConstantProductPoolWithConfig) SetPayerTokenBAccount(payerTokenB ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig { + inst.AccountMetaSlice[14] = ag_solanago.Meta(payerTokenB).WRITE() + return inst +} + +// GetPayerTokenBAccount gets the "payerTokenB" account. +// Admin token account for pool token B mint. Used to bootstrap the pool with initial liquidity. +func (inst *InitializePermissionlessConstantProductPoolWithConfig) GetPayerTokenBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +// SetPayerPoolLpAccount sets the "payerPoolLp" account. +func (inst *InitializePermissionlessConstantProductPoolWithConfig) SetPayerPoolLpAccount(payerPoolLp ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig { + inst.AccountMetaSlice[15] = ag_solanago.Meta(payerPoolLp).WRITE() + return inst +} + +// GetPayerPoolLpAccount gets the "payerPoolLp" account. +func (inst *InitializePermissionlessConstantProductPoolWithConfig) GetPayerPoolLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(15) +} + +// SetProtocolTokenAFeeAccount sets the "protocolTokenAFee" account. +// Protocol fee token account for token A. Used to receive trading fee. +func (inst *InitializePermissionlessConstantProductPoolWithConfig) SetProtocolTokenAFeeAccount(protocolTokenAFee ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig { + inst.AccountMetaSlice[16] = ag_solanago.Meta(protocolTokenAFee).WRITE() + return inst +} + +// GetProtocolTokenAFeeAccount gets the "protocolTokenAFee" account. +// Protocol fee token account for token A. Used to receive trading fee. +func (inst *InitializePermissionlessConstantProductPoolWithConfig) GetProtocolTokenAFeeAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(16) +} + +// SetProtocolTokenBFeeAccount sets the "protocolTokenBFee" account. +// Protocol fee token account for token B. Used to receive trading fee. +func (inst *InitializePermissionlessConstantProductPoolWithConfig) SetProtocolTokenBFeeAccount(protocolTokenBFee ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig { + inst.AccountMetaSlice[17] = ag_solanago.Meta(protocolTokenBFee).WRITE() + return inst +} + +// GetProtocolTokenBFeeAccount gets the "protocolTokenBFee" account. +// Protocol fee token account for token B. Used to receive trading fee. +func (inst *InitializePermissionlessConstantProductPoolWithConfig) GetProtocolTokenBFeeAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(17) +} + +// SetPayerAccount sets the "payer" account. +// Admin account. This account will be the admin of the pool, and the payer for PDA during initialize pool. +func (inst *InitializePermissionlessConstantProductPoolWithConfig) SetPayerAccount(payer ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig { + inst.AccountMetaSlice[18] = ag_solanago.Meta(payer).WRITE().SIGNER() + return inst +} + +// GetPayerAccount gets the "payer" account. +// Admin account. This account will be the admin of the pool, and the payer for PDA during initialize pool. +func (inst *InitializePermissionlessConstantProductPoolWithConfig) GetPayerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(18) +} + +// SetRentAccount sets the "rent" account. +// Rent account. +func (inst *InitializePermissionlessConstantProductPoolWithConfig) SetRentAccount(rent ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig { + inst.AccountMetaSlice[19] = ag_solanago.Meta(rent) + return inst +} + +// GetRentAccount gets the "rent" account. +// Rent account. +func (inst *InitializePermissionlessConstantProductPoolWithConfig) GetRentAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(19) +} + +// SetMintMetadataAccount sets the "mintMetadata" account. +func (inst *InitializePermissionlessConstantProductPoolWithConfig) SetMintMetadataAccount(mintMetadata ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig { + inst.AccountMetaSlice[20] = ag_solanago.Meta(mintMetadata).WRITE() + return inst +} + +// GetMintMetadataAccount gets the "mintMetadata" account. +func (inst *InitializePermissionlessConstantProductPoolWithConfig) GetMintMetadataAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(20) +} + +// SetMetadataProgramAccount sets the "metadataProgram" account. +func (inst *InitializePermissionlessConstantProductPoolWithConfig) SetMetadataProgramAccount(metadataProgram ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig { + inst.AccountMetaSlice[21] = ag_solanago.Meta(metadataProgram) + return inst +} + +// GetMetadataProgramAccount gets the "metadataProgram" account. +func (inst *InitializePermissionlessConstantProductPoolWithConfig) GetMetadataProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(21) +} + +// SetVaultProgramAccount sets the "vaultProgram" account. +// Vault program. The pool will deposit/withdraw liquidity from the vault. +func (inst *InitializePermissionlessConstantProductPoolWithConfig) SetVaultProgramAccount(vaultProgram ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig { + inst.AccountMetaSlice[22] = ag_solanago.Meta(vaultProgram) + return inst +} + +// GetVaultProgramAccount gets the "vaultProgram" account. +// Vault program. The pool will deposit/withdraw liquidity from the vault. +func (inst *InitializePermissionlessConstantProductPoolWithConfig) GetVaultProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(22) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +// Token program. +func (inst *InitializePermissionlessConstantProductPoolWithConfig) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig { + inst.AccountMetaSlice[23] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +// Token program. +func (inst *InitializePermissionlessConstantProductPoolWithConfig) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(23) +} + +// SetAssociatedTokenProgramAccount sets the "associatedTokenProgram" account. +// Associated token program. +func (inst *InitializePermissionlessConstantProductPoolWithConfig) SetAssociatedTokenProgramAccount(associatedTokenProgram ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig { + inst.AccountMetaSlice[24] = ag_solanago.Meta(associatedTokenProgram) + return inst +} + +// GetAssociatedTokenProgramAccount gets the "associatedTokenProgram" account. +// Associated token program. +func (inst *InitializePermissionlessConstantProductPoolWithConfig) GetAssociatedTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(24) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +// System program. +func (inst *InitializePermissionlessConstantProductPoolWithConfig) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig { + inst.AccountMetaSlice[25] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +// System program. +func (inst *InitializePermissionlessConstantProductPoolWithConfig) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(25) +} + +func (inst InitializePermissionlessConstantProductPoolWithConfig) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_InitializePermissionlessConstantProductPoolWithConfig, + }} +} + +// 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 InitializePermissionlessConstantProductPoolWithConfig) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *InitializePermissionlessConstantProductPoolWithConfig) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.TokenAAmount == nil { + return errors.New("TokenAAmount parameter is not set") + } + if inst.TokenBAmount == nil { + return errors.New("TokenBAmount parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Pool is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Config is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.LpMint is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.TokenAMint is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.TokenBMint is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.AVault is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.BVault is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.ATokenVault is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.BTokenVault is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.AVaultLpMint is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.BVaultLpMint is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.AVaultLp is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.BVaultLp is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.PayerTokenA is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.PayerTokenB is not set") + } + if inst.AccountMetaSlice[15] == nil { + return errors.New("accounts.PayerPoolLp is not set") + } + if inst.AccountMetaSlice[16] == nil { + return errors.New("accounts.ProtocolTokenAFee is not set") + } + if inst.AccountMetaSlice[17] == nil { + return errors.New("accounts.ProtocolTokenBFee is not set") + } + if inst.AccountMetaSlice[18] == nil { + return errors.New("accounts.Payer is not set") + } + if inst.AccountMetaSlice[19] == nil { + return errors.New("accounts.Rent is not set") + } + if inst.AccountMetaSlice[20] == nil { + return errors.New("accounts.MintMetadata is not set") + } + if inst.AccountMetaSlice[21] == nil { + return errors.New("accounts.MetadataProgram is not set") + } + if inst.AccountMetaSlice[22] == nil { + return errors.New("accounts.VaultProgram is not set") + } + if inst.AccountMetaSlice[23] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[24] == nil { + return errors.New("accounts.AssociatedTokenProgram is not set") + } + if inst.AccountMetaSlice[25] == nil { + return errors.New("accounts.SystemProgram is not set") + } + } + return nil +} + +func (inst *InitializePermissionlessConstantProductPoolWithConfig) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("InitializePermissionlessConstantProductPoolWithConfig")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=2]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param("TokenAAmount", *inst.TokenAAmount)) + paramsBranch.Child(ag_format.Param("TokenBAmount", *inst.TokenBAmount)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=26]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" pool", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" config", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" lpMint", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" tokenAMint", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" tokenBMint", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" aVault", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" bVault", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" aTokenVault", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" bTokenVault", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" aVaultLpMint", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" bVaultLpMint", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" aVaultLp", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" bVaultLp", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" payerTokenA", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta(" payerTokenB", inst.AccountMetaSlice.Get(14))) + accountsBranch.Child(ag_format.Meta(" payerPoolLp", inst.AccountMetaSlice.Get(15))) + accountsBranch.Child(ag_format.Meta(" protocolTokenAFee", inst.AccountMetaSlice.Get(16))) + accountsBranch.Child(ag_format.Meta(" protocolTokenBFee", inst.AccountMetaSlice.Get(17))) + accountsBranch.Child(ag_format.Meta(" payer", inst.AccountMetaSlice.Get(18))) + accountsBranch.Child(ag_format.Meta(" rent", inst.AccountMetaSlice.Get(19))) + accountsBranch.Child(ag_format.Meta(" mintMetadata", inst.AccountMetaSlice.Get(20))) + accountsBranch.Child(ag_format.Meta(" metadataProgram", inst.AccountMetaSlice.Get(21))) + accountsBranch.Child(ag_format.Meta(" vaultProgram", inst.AccountMetaSlice.Get(22))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(23))) + accountsBranch.Child(ag_format.Meta("associatedTokenProgram", inst.AccountMetaSlice.Get(24))) + accountsBranch.Child(ag_format.Meta(" systemProgram", inst.AccountMetaSlice.Get(25))) + }) + }) + }) +} + +func (obj InitializePermissionlessConstantProductPoolWithConfig) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `TokenAAmount` param: + err = encoder.Encode(obj.TokenAAmount) + if err != nil { + return err + } + // Serialize `TokenBAmount` param: + err = encoder.Encode(obj.TokenBAmount) + if err != nil { + return err + } + return nil +} +func (obj *InitializePermissionlessConstantProductPoolWithConfig) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `TokenAAmount`: + err = decoder.Decode(&obj.TokenAAmount) + if err != nil { + return err + } + // Deserialize `TokenBAmount`: + err = decoder.Decode(&obj.TokenBAmount) + if err != nil { + return err + } + return nil +} + +// NewInitializePermissionlessConstantProductPoolWithConfigInstruction declares a new InitializePermissionlessConstantProductPoolWithConfig instruction with the provided parameters and accounts. +func NewInitializePermissionlessConstantProductPoolWithConfigInstruction( + // Parameters: + tokenAAmount uint64, + tokenBAmount uint64, + // Accounts: + pool ag_solanago.PublicKey, + config ag_solanago.PublicKey, + lpMint ag_solanago.PublicKey, + tokenAMint ag_solanago.PublicKey, + tokenBMint ag_solanago.PublicKey, + aVault ag_solanago.PublicKey, + bVault ag_solanago.PublicKey, + aTokenVault ag_solanago.PublicKey, + bTokenVault ag_solanago.PublicKey, + aVaultLpMint ag_solanago.PublicKey, + bVaultLpMint ag_solanago.PublicKey, + aVaultLp ag_solanago.PublicKey, + bVaultLp ag_solanago.PublicKey, + payerTokenA ag_solanago.PublicKey, + payerTokenB ag_solanago.PublicKey, + payerPoolLp ag_solanago.PublicKey, + protocolTokenAFee ag_solanago.PublicKey, + protocolTokenBFee ag_solanago.PublicKey, + payer ag_solanago.PublicKey, + rent ag_solanago.PublicKey, + mintMetadata ag_solanago.PublicKey, + metadataProgram ag_solanago.PublicKey, + vaultProgram ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + associatedTokenProgram ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig { + return NewInitializePermissionlessConstantProductPoolWithConfigInstructionBuilder(). + SetTokenAAmount(tokenAAmount). + SetTokenBAmount(tokenBAmount). + SetPoolAccount(pool). + SetConfigAccount(config). + SetLpMintAccount(lpMint). + SetTokenAMintAccount(tokenAMint). + SetTokenBMintAccount(tokenBMint). + SetAVaultAccount(aVault). + SetBVaultAccount(bVault). + SetATokenVaultAccount(aTokenVault). + SetBTokenVaultAccount(bTokenVault). + SetAVaultLpMintAccount(aVaultLpMint). + SetBVaultLpMintAccount(bVaultLpMint). + SetAVaultLpAccount(aVaultLp). + SetBVaultLpAccount(bVaultLp). + SetPayerTokenAAccount(payerTokenA). + SetPayerTokenBAccount(payerTokenB). + SetPayerPoolLpAccount(payerPoolLp). + SetProtocolTokenAFeeAccount(protocolTokenAFee). + SetProtocolTokenBFeeAccount(protocolTokenBFee). + SetPayerAccount(payer). + SetRentAccount(rent). + SetMintMetadataAccount(mintMetadata). + SetMetadataProgramAccount(metadataProgram). + SetVaultProgramAccount(vaultProgram). + SetTokenProgramAccount(tokenProgram). + SetAssociatedTokenProgramAccount(associatedTokenProgram). + SetSystemProgramAccount(systemProgram) +} diff --git a/programs/meteorapools/InitializePermissionlessConstantProductPoolWithConfig2.go b/programs/meteorapools/InitializePermissionlessConstantProductPoolWithConfig2.go new file mode 100644 index 00000000..b9bb46b9 --- /dev/null +++ b/programs/meteorapools/InitializePermissionlessConstantProductPoolWithConfig2.go @@ -0,0 +1,732 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "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" +) + +// Initialize permissionless pool with config 2 +type InitializePermissionlessConstantProductPoolWithConfig2 struct { + TokenAAmount *uint64 + TokenBAmount *uint64 + ActivationPoint *uint64 `bin:"optional"` + + // [0] = [WRITE] pool + // ··········· Pool account (PDA address) + // + // [1] = [] config + // + // [2] = [WRITE] lpMint + // ··········· LP token mint of the pool + // + // [3] = [] tokenAMint + // ··········· Token A mint of the pool. Eg: USDT + // + // [4] = [] tokenBMint + // ··········· Token B mint of the pool. Eg: USDC + // + // [5] = [WRITE] aVault + // ··········· Vault account for token A. Token A of the pool will be deposit / withdraw from this vault account. + // + // [6] = [WRITE] bVault + // ··········· Vault account for token B. Token B of the pool will be deposit / withdraw from this vault account. + // + // [7] = [WRITE] aTokenVault + // ··········· Token vault account of vault A + // + // [8] = [WRITE] bTokenVault + // ··········· Token vault account of vault B + // + // [9] = [WRITE] aVaultLpMint + // ··········· LP token mint of vault A + // + // [10] = [WRITE] bVaultLpMint + // ··········· LP token mint of vault B + // + // [11] = [WRITE] aVaultLp + // ··········· LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. + // + // [12] = [WRITE] bVaultLp + // ··········· LP token account of vault B. Used to receive/burn vault LP upon deposit/withdraw from the vault. + // + // [13] = [WRITE] payerTokenA + // ··········· Payer token account for pool token A mint. Used to bootstrap the pool with initial liquidity. + // + // [14] = [WRITE] payerTokenB + // ··········· Admin token account for pool token B mint. Used to bootstrap the pool with initial liquidity. + // + // [15] = [WRITE] payerPoolLp + // + // [16] = [WRITE] protocolTokenAFee + // ··········· Protocol fee token account for token A. Used to receive trading fee. + // + // [17] = [WRITE] protocolTokenBFee + // ··········· Protocol fee token account for token B. Used to receive trading fee. + // + // [18] = [WRITE, SIGNER] payer + // ··········· Admin account. This account will be the admin of the pool, and the payer for PDA during initialize pool. + // + // [19] = [] rent + // ··········· Rent account. + // + // [20] = [WRITE] mintMetadata + // + // [21] = [] metadataProgram + // + // [22] = [] vaultProgram + // ··········· Vault program. The pool will deposit/withdraw liquidity from the vault. + // + // [23] = [] tokenProgram + // ··········· Token program. + // + // [24] = [] associatedTokenProgram + // ··········· Associated token program. + // + // [25] = [] systemProgram + // ··········· System program. + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewInitializePermissionlessConstantProductPoolWithConfig2InstructionBuilder creates a new `InitializePermissionlessConstantProductPoolWithConfig2` instruction builder. +func NewInitializePermissionlessConstantProductPoolWithConfig2InstructionBuilder() *InitializePermissionlessConstantProductPoolWithConfig2 { + nd := &InitializePermissionlessConstantProductPoolWithConfig2{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 26), + } + return nd +} + +// SetTokenAAmount sets the "tokenAAmount" parameter. +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) SetTokenAAmount(tokenAAmount uint64) *InitializePermissionlessConstantProductPoolWithConfig2 { + inst.TokenAAmount = &tokenAAmount + return inst +} + +// SetTokenBAmount sets the "tokenBAmount" parameter. +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) SetTokenBAmount(tokenBAmount uint64) *InitializePermissionlessConstantProductPoolWithConfig2 { + inst.TokenBAmount = &tokenBAmount + return inst +} + +// SetActivationPoint sets the "activationPoint" parameter. +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) SetActivationPoint(activationPoint uint64) *InitializePermissionlessConstantProductPoolWithConfig2 { + inst.ActivationPoint = &activationPoint + return inst +} + +// SetPoolAccount sets the "pool" account. +// Pool account (PDA address) +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) SetPoolAccount(pool ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig2 { + inst.AccountMetaSlice[0] = ag_solanago.Meta(pool).WRITE() + return inst +} + +// GetPoolAccount gets the "pool" account. +// Pool account (PDA address) +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) GetPoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetConfigAccount sets the "config" account. +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) SetConfigAccount(config ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig2 { + inst.AccountMetaSlice[1] = ag_solanago.Meta(config) + return inst +} + +// GetConfigAccount gets the "config" account. +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) GetConfigAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetLpMintAccount sets the "lpMint" account. +// LP token mint of the pool +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) SetLpMintAccount(lpMint ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig2 { + inst.AccountMetaSlice[2] = ag_solanago.Meta(lpMint).WRITE() + return inst +} + +// GetLpMintAccount gets the "lpMint" account. +// LP token mint of the pool +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) GetLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetTokenAMintAccount sets the "tokenAMint" account. +// Token A mint of the pool. Eg: USDT +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) SetTokenAMintAccount(tokenAMint ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig2 { + inst.AccountMetaSlice[3] = ag_solanago.Meta(tokenAMint) + return inst +} + +// GetTokenAMintAccount gets the "tokenAMint" account. +// Token A mint of the pool. Eg: USDT +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) GetTokenAMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetTokenBMintAccount sets the "tokenBMint" account. +// Token B mint of the pool. Eg: USDC +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) SetTokenBMintAccount(tokenBMint ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig2 { + inst.AccountMetaSlice[4] = ag_solanago.Meta(tokenBMint) + return inst +} + +// GetTokenBMintAccount gets the "tokenBMint" account. +// Token B mint of the pool. Eg: USDC +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) GetTokenBMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetAVaultAccount sets the "aVault" account. +// Vault account for token A. Token A of the pool will be deposit / withdraw from this vault account. +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) SetAVaultAccount(aVault ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig2 { + inst.AccountMetaSlice[5] = ag_solanago.Meta(aVault).WRITE() + return inst +} + +// GetAVaultAccount gets the "aVault" account. +// Vault account for token A. Token A of the pool will be deposit / withdraw from this vault account. +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) GetAVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetBVaultAccount sets the "bVault" account. +// Vault account for token B. Token B of the pool will be deposit / withdraw from this vault account. +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) SetBVaultAccount(bVault ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig2 { + inst.AccountMetaSlice[6] = ag_solanago.Meta(bVault).WRITE() + return inst +} + +// GetBVaultAccount gets the "bVault" account. +// Vault account for token B. Token B of the pool will be deposit / withdraw from this vault account. +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) GetBVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetATokenVaultAccount sets the "aTokenVault" account. +// Token vault account of vault A +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) SetATokenVaultAccount(aTokenVault ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig2 { + inst.AccountMetaSlice[7] = ag_solanago.Meta(aTokenVault).WRITE() + return inst +} + +// GetATokenVaultAccount gets the "aTokenVault" account. +// Token vault account of vault A +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) GetATokenVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetBTokenVaultAccount sets the "bTokenVault" account. +// Token vault account of vault B +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) SetBTokenVaultAccount(bTokenVault ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig2 { + inst.AccountMetaSlice[8] = ag_solanago.Meta(bTokenVault).WRITE() + return inst +} + +// GetBTokenVaultAccount gets the "bTokenVault" account. +// Token vault account of vault B +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) GetBTokenVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetAVaultLpMintAccount sets the "aVaultLpMint" account. +// LP token mint of vault A +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) SetAVaultLpMintAccount(aVaultLpMint ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig2 { + inst.AccountMetaSlice[9] = ag_solanago.Meta(aVaultLpMint).WRITE() + return inst +} + +// GetAVaultLpMintAccount gets the "aVaultLpMint" account. +// LP token mint of vault A +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) GetAVaultLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetBVaultLpMintAccount sets the "bVaultLpMint" account. +// LP token mint of vault B +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) SetBVaultLpMintAccount(bVaultLpMint ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig2 { + inst.AccountMetaSlice[10] = ag_solanago.Meta(bVaultLpMint).WRITE() + return inst +} + +// GetBVaultLpMintAccount gets the "bVaultLpMint" account. +// LP token mint of vault B +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) GetBVaultLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetAVaultLpAccount sets the "aVaultLp" account. +// LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) SetAVaultLpAccount(aVaultLp ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig2 { + inst.AccountMetaSlice[11] = ag_solanago.Meta(aVaultLp).WRITE() + return inst +} + +// GetAVaultLpAccount gets the "aVaultLp" account. +// LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) GetAVaultLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetBVaultLpAccount sets the "bVaultLp" account. +// LP token account of vault B. Used to receive/burn vault LP upon deposit/withdraw from the vault. +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) SetBVaultLpAccount(bVaultLp ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig2 { + inst.AccountMetaSlice[12] = ag_solanago.Meta(bVaultLp).WRITE() + return inst +} + +// GetBVaultLpAccount gets the "bVaultLp" account. +// LP token account of vault B. Used to receive/burn vault LP upon deposit/withdraw from the vault. +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) GetBVaultLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetPayerTokenAAccount sets the "payerTokenA" account. +// Payer token account for pool token A mint. Used to bootstrap the pool with initial liquidity. +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) SetPayerTokenAAccount(payerTokenA ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig2 { + inst.AccountMetaSlice[13] = ag_solanago.Meta(payerTokenA).WRITE() + return inst +} + +// GetPayerTokenAAccount gets the "payerTokenA" account. +// Payer token account for pool token A mint. Used to bootstrap the pool with initial liquidity. +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) GetPayerTokenAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetPayerTokenBAccount sets the "payerTokenB" account. +// Admin token account for pool token B mint. Used to bootstrap the pool with initial liquidity. +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) SetPayerTokenBAccount(payerTokenB ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig2 { + inst.AccountMetaSlice[14] = ag_solanago.Meta(payerTokenB).WRITE() + return inst +} + +// GetPayerTokenBAccount gets the "payerTokenB" account. +// Admin token account for pool token B mint. Used to bootstrap the pool with initial liquidity. +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) GetPayerTokenBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +// SetPayerPoolLpAccount sets the "payerPoolLp" account. +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) SetPayerPoolLpAccount(payerPoolLp ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig2 { + inst.AccountMetaSlice[15] = ag_solanago.Meta(payerPoolLp).WRITE() + return inst +} + +// GetPayerPoolLpAccount gets the "payerPoolLp" account. +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) GetPayerPoolLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(15) +} + +// SetProtocolTokenAFeeAccount sets the "protocolTokenAFee" account. +// Protocol fee token account for token A. Used to receive trading fee. +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) SetProtocolTokenAFeeAccount(protocolTokenAFee ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig2 { + inst.AccountMetaSlice[16] = ag_solanago.Meta(protocolTokenAFee).WRITE() + return inst +} + +// GetProtocolTokenAFeeAccount gets the "protocolTokenAFee" account. +// Protocol fee token account for token A. Used to receive trading fee. +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) GetProtocolTokenAFeeAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(16) +} + +// SetProtocolTokenBFeeAccount sets the "protocolTokenBFee" account. +// Protocol fee token account for token B. Used to receive trading fee. +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) SetProtocolTokenBFeeAccount(protocolTokenBFee ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig2 { + inst.AccountMetaSlice[17] = ag_solanago.Meta(protocolTokenBFee).WRITE() + return inst +} + +// GetProtocolTokenBFeeAccount gets the "protocolTokenBFee" account. +// Protocol fee token account for token B. Used to receive trading fee. +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) GetProtocolTokenBFeeAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(17) +} + +// SetPayerAccount sets the "payer" account. +// Admin account. This account will be the admin of the pool, and the payer for PDA during initialize pool. +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) SetPayerAccount(payer ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig2 { + inst.AccountMetaSlice[18] = ag_solanago.Meta(payer).WRITE().SIGNER() + return inst +} + +// GetPayerAccount gets the "payer" account. +// Admin account. This account will be the admin of the pool, and the payer for PDA during initialize pool. +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) GetPayerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(18) +} + +// SetRentAccount sets the "rent" account. +// Rent account. +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) SetRentAccount(rent ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig2 { + inst.AccountMetaSlice[19] = ag_solanago.Meta(rent) + return inst +} + +// GetRentAccount gets the "rent" account. +// Rent account. +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) GetRentAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(19) +} + +// SetMintMetadataAccount sets the "mintMetadata" account. +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) SetMintMetadataAccount(mintMetadata ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig2 { + inst.AccountMetaSlice[20] = ag_solanago.Meta(mintMetadata).WRITE() + return inst +} + +// GetMintMetadataAccount gets the "mintMetadata" account. +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) GetMintMetadataAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(20) +} + +// SetMetadataProgramAccount sets the "metadataProgram" account. +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) SetMetadataProgramAccount(metadataProgram ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig2 { + inst.AccountMetaSlice[21] = ag_solanago.Meta(metadataProgram) + return inst +} + +// GetMetadataProgramAccount gets the "metadataProgram" account. +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) GetMetadataProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(21) +} + +// SetVaultProgramAccount sets the "vaultProgram" account. +// Vault program. The pool will deposit/withdraw liquidity from the vault. +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) SetVaultProgramAccount(vaultProgram ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig2 { + inst.AccountMetaSlice[22] = ag_solanago.Meta(vaultProgram) + return inst +} + +// GetVaultProgramAccount gets the "vaultProgram" account. +// Vault program. The pool will deposit/withdraw liquidity from the vault. +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) GetVaultProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(22) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +// Token program. +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig2 { + inst.AccountMetaSlice[23] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +// Token program. +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(23) +} + +// SetAssociatedTokenProgramAccount sets the "associatedTokenProgram" account. +// Associated token program. +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) SetAssociatedTokenProgramAccount(associatedTokenProgram ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig2 { + inst.AccountMetaSlice[24] = ag_solanago.Meta(associatedTokenProgram) + return inst +} + +// GetAssociatedTokenProgramAccount gets the "associatedTokenProgram" account. +// Associated token program. +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) GetAssociatedTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(24) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +// System program. +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig2 { + inst.AccountMetaSlice[25] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +// System program. +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(25) +} + +func (inst InitializePermissionlessConstantProductPoolWithConfig2) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_InitializePermissionlessConstantProductPoolWithConfig2, + }} +} + +// 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 InitializePermissionlessConstantProductPoolWithConfig2) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.TokenAAmount == nil { + return errors.New("TokenAAmount parameter is not set") + } + if inst.TokenBAmount == nil { + return errors.New("TokenBAmount parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Pool is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Config is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.LpMint is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.TokenAMint is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.TokenBMint is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.AVault is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.BVault is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.ATokenVault is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.BTokenVault is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.AVaultLpMint is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.BVaultLpMint is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.AVaultLp is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.BVaultLp is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.PayerTokenA is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.PayerTokenB is not set") + } + if inst.AccountMetaSlice[15] == nil { + return errors.New("accounts.PayerPoolLp is not set") + } + if inst.AccountMetaSlice[16] == nil { + return errors.New("accounts.ProtocolTokenAFee is not set") + } + if inst.AccountMetaSlice[17] == nil { + return errors.New("accounts.ProtocolTokenBFee is not set") + } + if inst.AccountMetaSlice[18] == nil { + return errors.New("accounts.Payer is not set") + } + if inst.AccountMetaSlice[19] == nil { + return errors.New("accounts.Rent is not set") + } + if inst.AccountMetaSlice[20] == nil { + return errors.New("accounts.MintMetadata is not set") + } + if inst.AccountMetaSlice[21] == nil { + return errors.New("accounts.MetadataProgram is not set") + } + if inst.AccountMetaSlice[22] == nil { + return errors.New("accounts.VaultProgram is not set") + } + if inst.AccountMetaSlice[23] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[24] == nil { + return errors.New("accounts.AssociatedTokenProgram is not set") + } + if inst.AccountMetaSlice[25] == nil { + return errors.New("accounts.SystemProgram is not set") + } + } + return nil +} + +func (inst *InitializePermissionlessConstantProductPoolWithConfig2) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("InitializePermissionlessConstantProductPoolWithConfig2")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=3]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" TokenAAmount", *inst.TokenAAmount)) + paramsBranch.Child(ag_format.Param(" TokenBAmount", *inst.TokenBAmount)) + paramsBranch.Child(ag_format.Param("ActivationPoint (OPT)", inst.ActivationPoint)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=26]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" pool", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" config", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" lpMint", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" tokenAMint", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" tokenBMint", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" aVault", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" bVault", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" aTokenVault", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" bTokenVault", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" aVaultLpMint", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" bVaultLpMint", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" aVaultLp", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" bVaultLp", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" payerTokenA", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta(" payerTokenB", inst.AccountMetaSlice.Get(14))) + accountsBranch.Child(ag_format.Meta(" payerPoolLp", inst.AccountMetaSlice.Get(15))) + accountsBranch.Child(ag_format.Meta(" protocolTokenAFee", inst.AccountMetaSlice.Get(16))) + accountsBranch.Child(ag_format.Meta(" protocolTokenBFee", inst.AccountMetaSlice.Get(17))) + accountsBranch.Child(ag_format.Meta(" payer", inst.AccountMetaSlice.Get(18))) + accountsBranch.Child(ag_format.Meta(" rent", inst.AccountMetaSlice.Get(19))) + accountsBranch.Child(ag_format.Meta(" mintMetadata", inst.AccountMetaSlice.Get(20))) + accountsBranch.Child(ag_format.Meta(" metadataProgram", inst.AccountMetaSlice.Get(21))) + accountsBranch.Child(ag_format.Meta(" vaultProgram", inst.AccountMetaSlice.Get(22))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(23))) + accountsBranch.Child(ag_format.Meta("associatedTokenProgram", inst.AccountMetaSlice.Get(24))) + accountsBranch.Child(ag_format.Meta(" systemProgram", inst.AccountMetaSlice.Get(25))) + }) + }) + }) +} + +func (obj InitializePermissionlessConstantProductPoolWithConfig2) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `TokenAAmount` param: + err = encoder.Encode(obj.TokenAAmount) + if err != nil { + return err + } + // Serialize `TokenBAmount` param: + err = encoder.Encode(obj.TokenBAmount) + if err != nil { + return err + } + // Serialize `ActivationPoint` param (optional): + { + if obj.ActivationPoint == nil { + err = encoder.WriteBool(false) + if err != nil { + return err + } + } else { + err = encoder.WriteBool(true) + if err != nil { + return err + } + err = encoder.Encode(obj.ActivationPoint) + if err != nil { + return err + } + } + } + return nil +} +func (obj *InitializePermissionlessConstantProductPoolWithConfig2) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `TokenAAmount`: + err = decoder.Decode(&obj.TokenAAmount) + if err != nil { + return err + } + // Deserialize `TokenBAmount`: + err = decoder.Decode(&obj.TokenBAmount) + if err != nil { + return err + } + // Deserialize `ActivationPoint` (optional): + { + ok, err := decoder.ReadBool() + if err != nil { + return err + } + if ok { + err = decoder.Decode(&obj.ActivationPoint) + if err != nil { + return err + } + } + } + return nil +} + +// NewInitializePermissionlessConstantProductPoolWithConfig2Instruction declares a new InitializePermissionlessConstantProductPoolWithConfig2 instruction with the provided parameters and accounts. +func NewInitializePermissionlessConstantProductPoolWithConfig2Instruction( + // Parameters: + tokenAAmount uint64, + tokenBAmount uint64, + activationPoint uint64, + // Accounts: + pool ag_solanago.PublicKey, + config ag_solanago.PublicKey, + lpMint ag_solanago.PublicKey, + tokenAMint ag_solanago.PublicKey, + tokenBMint ag_solanago.PublicKey, + aVault ag_solanago.PublicKey, + bVault ag_solanago.PublicKey, + aTokenVault ag_solanago.PublicKey, + bTokenVault ag_solanago.PublicKey, + aVaultLpMint ag_solanago.PublicKey, + bVaultLpMint ag_solanago.PublicKey, + aVaultLp ag_solanago.PublicKey, + bVaultLp ag_solanago.PublicKey, + payerTokenA ag_solanago.PublicKey, + payerTokenB ag_solanago.PublicKey, + payerPoolLp ag_solanago.PublicKey, + protocolTokenAFee ag_solanago.PublicKey, + protocolTokenBFee ag_solanago.PublicKey, + payer ag_solanago.PublicKey, + rent ag_solanago.PublicKey, + mintMetadata ag_solanago.PublicKey, + metadataProgram ag_solanago.PublicKey, + vaultProgram ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + associatedTokenProgram ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey) *InitializePermissionlessConstantProductPoolWithConfig2 { + return NewInitializePermissionlessConstantProductPoolWithConfig2InstructionBuilder(). + SetTokenAAmount(tokenAAmount). + SetTokenBAmount(tokenBAmount). + SetActivationPoint(activationPoint). + SetPoolAccount(pool). + SetConfigAccount(config). + SetLpMintAccount(lpMint). + SetTokenAMintAccount(tokenAMint). + SetTokenBMintAccount(tokenBMint). + SetAVaultAccount(aVault). + SetBVaultAccount(bVault). + SetATokenVaultAccount(aTokenVault). + SetBTokenVaultAccount(bTokenVault). + SetAVaultLpMintAccount(aVaultLpMint). + SetBVaultLpMintAccount(bVaultLpMint). + SetAVaultLpAccount(aVaultLp). + SetBVaultLpAccount(bVaultLp). + SetPayerTokenAAccount(payerTokenA). + SetPayerTokenBAccount(payerTokenB). + SetPayerPoolLpAccount(payerPoolLp). + SetProtocolTokenAFeeAccount(protocolTokenAFee). + SetProtocolTokenBFeeAccount(protocolTokenBFee). + SetPayerAccount(payer). + SetRentAccount(rent). + SetMintMetadataAccount(mintMetadata). + SetMetadataProgramAccount(metadataProgram). + SetVaultProgramAccount(vaultProgram). + SetTokenProgramAccount(tokenProgram). + SetAssociatedTokenProgramAccount(associatedTokenProgram). + SetSystemProgramAccount(systemProgram) +} diff --git a/programs/meteorapools/InitializePermissionlessConstantProductPoolWithConfig2_test.go b/programs/meteorapools/InitializePermissionlessConstantProductPoolWithConfig2_test.go new file mode 100644 index 00000000..809f3114 --- /dev/null +++ b/programs/meteorapools/InitializePermissionlessConstantProductPoolWithConfig2_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_InitializePermissionlessConstantProductPoolWithConfig2(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("InitializePermissionlessConstantProductPoolWithConfig2"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(InitializePermissionlessConstantProductPoolWithConfig2) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(InitializePermissionlessConstantProductPoolWithConfig2) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteorapools/InitializePermissionlessConstantProductPoolWithConfig_test.go b/programs/meteorapools/InitializePermissionlessConstantProductPoolWithConfig_test.go new file mode 100644 index 00000000..734b6067 --- /dev/null +++ b/programs/meteorapools/InitializePermissionlessConstantProductPoolWithConfig_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_InitializePermissionlessConstantProductPoolWithConfig(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("InitializePermissionlessConstantProductPoolWithConfig"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(InitializePermissionlessConstantProductPoolWithConfig) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(InitializePermissionlessConstantProductPoolWithConfig) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteorapools/InitializePermissionlessPool.go b/programs/meteorapools/InitializePermissionlessPool.go new file mode 100644 index 00000000..e67368e9 --- /dev/null +++ b/programs/meteorapools/InitializePermissionlessPool.go @@ -0,0 +1,737 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "errors" + "fmt" + 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" +) + +// Initialize a new permissionless pool. +type InitializePermissionlessPool struct { + CurveType CurveType + TokenAAmount *uint64 + TokenBAmount *uint64 + + // [0] = [WRITE] pool + // ··········· Pool account (PDA address) + // + // [1] = [WRITE] lpMint + // ··········· LP token mint of the pool + // + // [2] = [] tokenAMint + // ··········· Token A mint of the pool. Eg: USDT + // + // [3] = [] tokenBMint + // ··········· Token B mint of the pool. Eg: USDC + // + // [4] = [WRITE] aVault + // ··········· Vault account for token A. Token A of the pool will be deposit / withdraw from this vault account. + // + // [5] = [WRITE] bVault + // ··········· Vault account for token B. Token B of the pool will be deposit / withdraw from this vault account. + // + // [6] = [WRITE] aTokenVault + // ··········· Token vault account of vault A + // + // [7] = [WRITE] bTokenVault + // ··········· Token vault account of vault B + // + // [8] = [WRITE] aVaultLpMint + // ··········· LP token mint of vault A + // + // [9] = [WRITE] bVaultLpMint + // ··········· LP token mint of vault B + // + // [10] = [WRITE] aVaultLp + // ··········· LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. + // + // [11] = [WRITE] bVaultLp + // ··········· LP token account of vault B. Used to receive/burn vault LP upon deposit/withdraw from the vault. + // + // [12] = [WRITE] payerTokenA + // ··········· Payer token account for pool token A mint. Used to bootstrap the pool with initial liquidity. + // + // [13] = [WRITE] payerTokenB + // ··········· Admin token account for pool token B mint. Used to bootstrap the pool with initial liquidity. + // + // [14] = [WRITE] payerPoolLp + // + // [15] = [WRITE] protocolTokenAFee + // ··········· Protocol fee token account for token A. Used to receive trading fee. + // + // [16] = [WRITE] protocolTokenBFee + // ··········· Protocol fee token account for token B. Used to receive trading fee. + // + // [17] = [WRITE, SIGNER] payer + // ··········· Admin account. This account will be the admin of the pool, and the payer for PDA during initialize pool. + // + // [18] = [] feeOwner + // + // [19] = [] rent + // ··········· Rent account. + // + // [20] = [WRITE] mintMetadata + // + // [21] = [] metadataProgram + // + // [22] = [] vaultProgram + // ··········· Vault program. The pool will deposit/withdraw liquidity from the vault. + // + // [23] = [] tokenProgram + // ··········· Token program. + // + // [24] = [] associatedTokenProgram + // ··········· Associated token program. + // + // [25] = [] systemProgram + // ··········· System program. + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewInitializePermissionlessPoolInstructionBuilder creates a new `InitializePermissionlessPool` instruction builder. +func NewInitializePermissionlessPoolInstructionBuilder() *InitializePermissionlessPool { + nd := &InitializePermissionlessPool{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 26), + } + return nd +} + +// SetCurveType sets the "curveType" parameter. +func (inst *InitializePermissionlessPool) SetCurveType(curveType CurveType) *InitializePermissionlessPool { + inst.CurveType = curveType + return inst +} + +// SetTokenAAmount sets the "tokenAAmount" parameter. +func (inst *InitializePermissionlessPool) SetTokenAAmount(tokenAAmount uint64) *InitializePermissionlessPool { + inst.TokenAAmount = &tokenAAmount + return inst +} + +// SetTokenBAmount sets the "tokenBAmount" parameter. +func (inst *InitializePermissionlessPool) SetTokenBAmount(tokenBAmount uint64) *InitializePermissionlessPool { + inst.TokenBAmount = &tokenBAmount + return inst +} + +// SetPoolAccount sets the "pool" account. +// Pool account (PDA address) +func (inst *InitializePermissionlessPool) SetPoolAccount(pool ag_solanago.PublicKey) *InitializePermissionlessPool { + inst.AccountMetaSlice[0] = ag_solanago.Meta(pool).WRITE() + return inst +} + +// GetPoolAccount gets the "pool" account. +// Pool account (PDA address) +func (inst *InitializePermissionlessPool) GetPoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetLpMintAccount sets the "lpMint" account. +// LP token mint of the pool +func (inst *InitializePermissionlessPool) SetLpMintAccount(lpMint ag_solanago.PublicKey) *InitializePermissionlessPool { + inst.AccountMetaSlice[1] = ag_solanago.Meta(lpMint).WRITE() + return inst +} + +// GetLpMintAccount gets the "lpMint" account. +// LP token mint of the pool +func (inst *InitializePermissionlessPool) GetLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetTokenAMintAccount sets the "tokenAMint" account. +// Token A mint of the pool. Eg: USDT +func (inst *InitializePermissionlessPool) SetTokenAMintAccount(tokenAMint ag_solanago.PublicKey) *InitializePermissionlessPool { + inst.AccountMetaSlice[2] = ag_solanago.Meta(tokenAMint) + return inst +} + +// GetTokenAMintAccount gets the "tokenAMint" account. +// Token A mint of the pool. Eg: USDT +func (inst *InitializePermissionlessPool) GetTokenAMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetTokenBMintAccount sets the "tokenBMint" account. +// Token B mint of the pool. Eg: USDC +func (inst *InitializePermissionlessPool) SetTokenBMintAccount(tokenBMint ag_solanago.PublicKey) *InitializePermissionlessPool { + inst.AccountMetaSlice[3] = ag_solanago.Meta(tokenBMint) + return inst +} + +// GetTokenBMintAccount gets the "tokenBMint" account. +// Token B mint of the pool. Eg: USDC +func (inst *InitializePermissionlessPool) GetTokenBMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetAVaultAccount sets the "aVault" account. +// Vault account for token A. Token A of the pool will be deposit / withdraw from this vault account. +func (inst *InitializePermissionlessPool) SetAVaultAccount(aVault ag_solanago.PublicKey) *InitializePermissionlessPool { + inst.AccountMetaSlice[4] = ag_solanago.Meta(aVault).WRITE() + return inst +} + +// GetAVaultAccount gets the "aVault" account. +// Vault account for token A. Token A of the pool will be deposit / withdraw from this vault account. +func (inst *InitializePermissionlessPool) GetAVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetBVaultAccount sets the "bVault" account. +// Vault account for token B. Token B of the pool will be deposit / withdraw from this vault account. +func (inst *InitializePermissionlessPool) SetBVaultAccount(bVault ag_solanago.PublicKey) *InitializePermissionlessPool { + inst.AccountMetaSlice[5] = ag_solanago.Meta(bVault).WRITE() + return inst +} + +// GetBVaultAccount gets the "bVault" account. +// Vault account for token B. Token B of the pool will be deposit / withdraw from this vault account. +func (inst *InitializePermissionlessPool) GetBVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetATokenVaultAccount sets the "aTokenVault" account. +// Token vault account of vault A +func (inst *InitializePermissionlessPool) SetATokenVaultAccount(aTokenVault ag_solanago.PublicKey) *InitializePermissionlessPool { + inst.AccountMetaSlice[6] = ag_solanago.Meta(aTokenVault).WRITE() + return inst +} + +// GetATokenVaultAccount gets the "aTokenVault" account. +// Token vault account of vault A +func (inst *InitializePermissionlessPool) GetATokenVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetBTokenVaultAccount sets the "bTokenVault" account. +// Token vault account of vault B +func (inst *InitializePermissionlessPool) SetBTokenVaultAccount(bTokenVault ag_solanago.PublicKey) *InitializePermissionlessPool { + inst.AccountMetaSlice[7] = ag_solanago.Meta(bTokenVault).WRITE() + return inst +} + +// GetBTokenVaultAccount gets the "bTokenVault" account. +// Token vault account of vault B +func (inst *InitializePermissionlessPool) GetBTokenVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetAVaultLpMintAccount sets the "aVaultLpMint" account. +// LP token mint of vault A +func (inst *InitializePermissionlessPool) SetAVaultLpMintAccount(aVaultLpMint ag_solanago.PublicKey) *InitializePermissionlessPool { + inst.AccountMetaSlice[8] = ag_solanago.Meta(aVaultLpMint).WRITE() + return inst +} + +// GetAVaultLpMintAccount gets the "aVaultLpMint" account. +// LP token mint of vault A +func (inst *InitializePermissionlessPool) GetAVaultLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetBVaultLpMintAccount sets the "bVaultLpMint" account. +// LP token mint of vault B +func (inst *InitializePermissionlessPool) SetBVaultLpMintAccount(bVaultLpMint ag_solanago.PublicKey) *InitializePermissionlessPool { + inst.AccountMetaSlice[9] = ag_solanago.Meta(bVaultLpMint).WRITE() + return inst +} + +// GetBVaultLpMintAccount gets the "bVaultLpMint" account. +// LP token mint of vault B +func (inst *InitializePermissionlessPool) GetBVaultLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetAVaultLpAccount sets the "aVaultLp" account. +// LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *InitializePermissionlessPool) SetAVaultLpAccount(aVaultLp ag_solanago.PublicKey) *InitializePermissionlessPool { + inst.AccountMetaSlice[10] = ag_solanago.Meta(aVaultLp).WRITE() + return inst +} + +// GetAVaultLpAccount gets the "aVaultLp" account. +// LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *InitializePermissionlessPool) GetAVaultLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetBVaultLpAccount sets the "bVaultLp" account. +// LP token account of vault B. Used to receive/burn vault LP upon deposit/withdraw from the vault. +func (inst *InitializePermissionlessPool) SetBVaultLpAccount(bVaultLp ag_solanago.PublicKey) *InitializePermissionlessPool { + inst.AccountMetaSlice[11] = ag_solanago.Meta(bVaultLp).WRITE() + return inst +} + +// GetBVaultLpAccount gets the "bVaultLp" account. +// LP token account of vault B. Used to receive/burn vault LP upon deposit/withdraw from the vault. +func (inst *InitializePermissionlessPool) GetBVaultLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetPayerTokenAAccount sets the "payerTokenA" account. +// Payer token account for pool token A mint. Used to bootstrap the pool with initial liquidity. +func (inst *InitializePermissionlessPool) SetPayerTokenAAccount(payerTokenA ag_solanago.PublicKey) *InitializePermissionlessPool { + inst.AccountMetaSlice[12] = ag_solanago.Meta(payerTokenA).WRITE() + return inst +} + +// GetPayerTokenAAccount gets the "payerTokenA" account. +// Payer token account for pool token A mint. Used to bootstrap the pool with initial liquidity. +func (inst *InitializePermissionlessPool) GetPayerTokenAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetPayerTokenBAccount sets the "payerTokenB" account. +// Admin token account for pool token B mint. Used to bootstrap the pool with initial liquidity. +func (inst *InitializePermissionlessPool) SetPayerTokenBAccount(payerTokenB ag_solanago.PublicKey) *InitializePermissionlessPool { + inst.AccountMetaSlice[13] = ag_solanago.Meta(payerTokenB).WRITE() + return inst +} + +// GetPayerTokenBAccount gets the "payerTokenB" account. +// Admin token account for pool token B mint. Used to bootstrap the pool with initial liquidity. +func (inst *InitializePermissionlessPool) GetPayerTokenBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetPayerPoolLpAccount sets the "payerPoolLp" account. +func (inst *InitializePermissionlessPool) SetPayerPoolLpAccount(payerPoolLp ag_solanago.PublicKey) *InitializePermissionlessPool { + inst.AccountMetaSlice[14] = ag_solanago.Meta(payerPoolLp).WRITE() + return inst +} + +// GetPayerPoolLpAccount gets the "payerPoolLp" account. +func (inst *InitializePermissionlessPool) GetPayerPoolLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +// SetProtocolTokenAFeeAccount sets the "protocolTokenAFee" account. +// Protocol fee token account for token A. Used to receive trading fee. +func (inst *InitializePermissionlessPool) SetProtocolTokenAFeeAccount(protocolTokenAFee ag_solanago.PublicKey) *InitializePermissionlessPool { + inst.AccountMetaSlice[15] = ag_solanago.Meta(protocolTokenAFee).WRITE() + return inst +} + +// GetProtocolTokenAFeeAccount gets the "protocolTokenAFee" account. +// Protocol fee token account for token A. Used to receive trading fee. +func (inst *InitializePermissionlessPool) GetProtocolTokenAFeeAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(15) +} + +// SetProtocolTokenBFeeAccount sets the "protocolTokenBFee" account. +// Protocol fee token account for token B. Used to receive trading fee. +func (inst *InitializePermissionlessPool) SetProtocolTokenBFeeAccount(protocolTokenBFee ag_solanago.PublicKey) *InitializePermissionlessPool { + inst.AccountMetaSlice[16] = ag_solanago.Meta(protocolTokenBFee).WRITE() + return inst +} + +// GetProtocolTokenBFeeAccount gets the "protocolTokenBFee" account. +// Protocol fee token account for token B. Used to receive trading fee. +func (inst *InitializePermissionlessPool) GetProtocolTokenBFeeAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(16) +} + +// SetPayerAccount sets the "payer" account. +// Admin account. This account will be the admin of the pool, and the payer for PDA during initialize pool. +func (inst *InitializePermissionlessPool) SetPayerAccount(payer ag_solanago.PublicKey) *InitializePermissionlessPool { + inst.AccountMetaSlice[17] = ag_solanago.Meta(payer).WRITE().SIGNER() + return inst +} + +// GetPayerAccount gets the "payer" account. +// Admin account. This account will be the admin of the pool, and the payer for PDA during initialize pool. +func (inst *InitializePermissionlessPool) GetPayerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(17) +} + +// SetFeeOwnerAccount sets the "feeOwner" account. +func (inst *InitializePermissionlessPool) SetFeeOwnerAccount(feeOwner ag_solanago.PublicKey) *InitializePermissionlessPool { + inst.AccountMetaSlice[18] = ag_solanago.Meta(feeOwner) + return inst +} + +// GetFeeOwnerAccount gets the "feeOwner" account. +func (inst *InitializePermissionlessPool) GetFeeOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(18) +} + +// SetRentAccount sets the "rent" account. +// Rent account. +func (inst *InitializePermissionlessPool) SetRentAccount(rent ag_solanago.PublicKey) *InitializePermissionlessPool { + inst.AccountMetaSlice[19] = ag_solanago.Meta(rent) + return inst +} + +// GetRentAccount gets the "rent" account. +// Rent account. +func (inst *InitializePermissionlessPool) GetRentAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(19) +} + +// SetMintMetadataAccount sets the "mintMetadata" account. +func (inst *InitializePermissionlessPool) SetMintMetadataAccount(mintMetadata ag_solanago.PublicKey) *InitializePermissionlessPool { + inst.AccountMetaSlice[20] = ag_solanago.Meta(mintMetadata).WRITE() + return inst +} + +// GetMintMetadataAccount gets the "mintMetadata" account. +func (inst *InitializePermissionlessPool) GetMintMetadataAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(20) +} + +// SetMetadataProgramAccount sets the "metadataProgram" account. +func (inst *InitializePermissionlessPool) SetMetadataProgramAccount(metadataProgram ag_solanago.PublicKey) *InitializePermissionlessPool { + inst.AccountMetaSlice[21] = ag_solanago.Meta(metadataProgram) + return inst +} + +// GetMetadataProgramAccount gets the "metadataProgram" account. +func (inst *InitializePermissionlessPool) GetMetadataProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(21) +} + +// SetVaultProgramAccount sets the "vaultProgram" account. +// Vault program. The pool will deposit/withdraw liquidity from the vault. +func (inst *InitializePermissionlessPool) SetVaultProgramAccount(vaultProgram ag_solanago.PublicKey) *InitializePermissionlessPool { + inst.AccountMetaSlice[22] = ag_solanago.Meta(vaultProgram) + return inst +} + +// GetVaultProgramAccount gets the "vaultProgram" account. +// Vault program. The pool will deposit/withdraw liquidity from the vault. +func (inst *InitializePermissionlessPool) GetVaultProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(22) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +// Token program. +func (inst *InitializePermissionlessPool) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *InitializePermissionlessPool { + inst.AccountMetaSlice[23] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +// Token program. +func (inst *InitializePermissionlessPool) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(23) +} + +// SetAssociatedTokenProgramAccount sets the "associatedTokenProgram" account. +// Associated token program. +func (inst *InitializePermissionlessPool) SetAssociatedTokenProgramAccount(associatedTokenProgram ag_solanago.PublicKey) *InitializePermissionlessPool { + inst.AccountMetaSlice[24] = ag_solanago.Meta(associatedTokenProgram) + return inst +} + +// GetAssociatedTokenProgramAccount gets the "associatedTokenProgram" account. +// Associated token program. +func (inst *InitializePermissionlessPool) GetAssociatedTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(24) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +// System program. +func (inst *InitializePermissionlessPool) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *InitializePermissionlessPool { + inst.AccountMetaSlice[25] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +// System program. +func (inst *InitializePermissionlessPool) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(25) +} + +func (inst InitializePermissionlessPool) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_InitializePermissionlessPool, + }} +} + +// 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 InitializePermissionlessPool) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *InitializePermissionlessPool) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.CurveType == nil { + return errors.New("CurveType parameter is not set") + } + if inst.TokenAAmount == nil { + return errors.New("TokenAAmount parameter is not set") + } + if inst.TokenBAmount == nil { + return errors.New("TokenBAmount parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Pool is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.LpMint is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.TokenAMint is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.TokenBMint is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.AVault is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.BVault is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.ATokenVault is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.BTokenVault is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.AVaultLpMint is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.BVaultLpMint is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.AVaultLp is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.BVaultLp is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.PayerTokenA is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.PayerTokenB is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.PayerPoolLp is not set") + } + if inst.AccountMetaSlice[15] == nil { + return errors.New("accounts.ProtocolTokenAFee is not set") + } + if inst.AccountMetaSlice[16] == nil { + return errors.New("accounts.ProtocolTokenBFee is not set") + } + if inst.AccountMetaSlice[17] == nil { + return errors.New("accounts.Payer is not set") + } + if inst.AccountMetaSlice[18] == nil { + return errors.New("accounts.FeeOwner is not set") + } + if inst.AccountMetaSlice[19] == nil { + return errors.New("accounts.Rent is not set") + } + if inst.AccountMetaSlice[20] == nil { + return errors.New("accounts.MintMetadata is not set") + } + if inst.AccountMetaSlice[21] == nil { + return errors.New("accounts.MetadataProgram is not set") + } + if inst.AccountMetaSlice[22] == nil { + return errors.New("accounts.VaultProgram is not set") + } + if inst.AccountMetaSlice[23] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[24] == nil { + return errors.New("accounts.AssociatedTokenProgram is not set") + } + if inst.AccountMetaSlice[25] == nil { + return errors.New("accounts.SystemProgram is not set") + } + } + return nil +} + +func (inst *InitializePermissionlessPool) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("InitializePermissionlessPool")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=3]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" CurveType", inst.CurveType)) + paramsBranch.Child(ag_format.Param("TokenAAmount", *inst.TokenAAmount)) + paramsBranch.Child(ag_format.Param("TokenBAmount", *inst.TokenBAmount)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=26]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" pool", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" lpMint", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" tokenAMint", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" tokenBMint", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" aVault", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" bVault", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" aTokenVault", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" bTokenVault", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" aVaultLpMint", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" bVaultLpMint", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" aVaultLp", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" bVaultLp", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" payerTokenA", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" payerTokenB", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta(" payerPoolLp", inst.AccountMetaSlice.Get(14))) + accountsBranch.Child(ag_format.Meta(" protocolTokenAFee", inst.AccountMetaSlice.Get(15))) + accountsBranch.Child(ag_format.Meta(" protocolTokenBFee", inst.AccountMetaSlice.Get(16))) + accountsBranch.Child(ag_format.Meta(" payer", inst.AccountMetaSlice.Get(17))) + accountsBranch.Child(ag_format.Meta(" feeOwner", inst.AccountMetaSlice.Get(18))) + accountsBranch.Child(ag_format.Meta(" rent", inst.AccountMetaSlice.Get(19))) + accountsBranch.Child(ag_format.Meta(" mintMetadata", inst.AccountMetaSlice.Get(20))) + accountsBranch.Child(ag_format.Meta(" metadataProgram", inst.AccountMetaSlice.Get(21))) + accountsBranch.Child(ag_format.Meta(" vaultProgram", inst.AccountMetaSlice.Get(22))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(23))) + accountsBranch.Child(ag_format.Meta("associatedTokenProgram", inst.AccountMetaSlice.Get(24))) + accountsBranch.Child(ag_format.Meta(" systemProgram", inst.AccountMetaSlice.Get(25))) + }) + }) + }) +} + +func (obj InitializePermissionlessPool) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `CurveType` param: + { + tmp := curveTypeContainer{} + switch realvalue := obj.CurveType.(type) { + case *CurveTypeConstantProduct: + tmp.Enum = 0 + tmp.ConstantProduct = *realvalue + case *CurveTypeStable: + tmp.Enum = 1 + tmp.Stable = *realvalue + } + err := encoder.Encode(tmp) + if err != nil { + return err + } + } + // Serialize `TokenAAmount` param: + err = encoder.Encode(obj.TokenAAmount) + if err != nil { + return err + } + // Serialize `TokenBAmount` param: + err = encoder.Encode(obj.TokenBAmount) + if err != nil { + return err + } + return nil +} +func (obj *InitializePermissionlessPool) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `CurveType`: + { + tmp := new(curveTypeContainer) + err := decoder.Decode(tmp) + if err != nil { + return err + } + switch tmp.Enum { + case 0: + obj.CurveType = (*CurveTypeConstantProduct)(&tmp.Enum) + case 1: + obj.CurveType = &tmp.Stable + default: + return fmt.Errorf("unknown enum index: %v", tmp.Enum) + } + } + // Deserialize `TokenAAmount`: + err = decoder.Decode(&obj.TokenAAmount) + if err != nil { + return err + } + // Deserialize `TokenBAmount`: + err = decoder.Decode(&obj.TokenBAmount) + if err != nil { + return err + } + return nil +} + +// NewInitializePermissionlessPoolInstruction declares a new InitializePermissionlessPool instruction with the provided parameters and accounts. +func NewInitializePermissionlessPoolInstruction( + // Parameters: + curveType CurveType, + tokenAAmount uint64, + tokenBAmount uint64, + // Accounts: + pool ag_solanago.PublicKey, + lpMint ag_solanago.PublicKey, + tokenAMint ag_solanago.PublicKey, + tokenBMint ag_solanago.PublicKey, + aVault ag_solanago.PublicKey, + bVault ag_solanago.PublicKey, + aTokenVault ag_solanago.PublicKey, + bTokenVault ag_solanago.PublicKey, + aVaultLpMint ag_solanago.PublicKey, + bVaultLpMint ag_solanago.PublicKey, + aVaultLp ag_solanago.PublicKey, + bVaultLp ag_solanago.PublicKey, + payerTokenA ag_solanago.PublicKey, + payerTokenB ag_solanago.PublicKey, + payerPoolLp ag_solanago.PublicKey, + protocolTokenAFee ag_solanago.PublicKey, + protocolTokenBFee ag_solanago.PublicKey, + payer ag_solanago.PublicKey, + feeOwner ag_solanago.PublicKey, + rent ag_solanago.PublicKey, + mintMetadata ag_solanago.PublicKey, + metadataProgram ag_solanago.PublicKey, + vaultProgram ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + associatedTokenProgram ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey) *InitializePermissionlessPool { + return NewInitializePermissionlessPoolInstructionBuilder(). + SetCurveType(curveType). + SetTokenAAmount(tokenAAmount). + SetTokenBAmount(tokenBAmount). + SetPoolAccount(pool). + SetLpMintAccount(lpMint). + SetTokenAMintAccount(tokenAMint). + SetTokenBMintAccount(tokenBMint). + SetAVaultAccount(aVault). + SetBVaultAccount(bVault). + SetATokenVaultAccount(aTokenVault). + SetBTokenVaultAccount(bTokenVault). + SetAVaultLpMintAccount(aVaultLpMint). + SetBVaultLpMintAccount(bVaultLpMint). + SetAVaultLpAccount(aVaultLp). + SetBVaultLpAccount(bVaultLp). + SetPayerTokenAAccount(payerTokenA). + SetPayerTokenBAccount(payerTokenB). + SetPayerPoolLpAccount(payerPoolLp). + SetProtocolTokenAFeeAccount(protocolTokenAFee). + SetProtocolTokenBFeeAccount(protocolTokenBFee). + SetPayerAccount(payer). + SetFeeOwnerAccount(feeOwner). + SetRentAccount(rent). + SetMintMetadataAccount(mintMetadata). + SetMetadataProgramAccount(metadataProgram). + SetVaultProgramAccount(vaultProgram). + SetTokenProgramAccount(tokenProgram). + SetAssociatedTokenProgramAccount(associatedTokenProgram). + SetSystemProgramAccount(systemProgram) +} diff --git a/programs/meteorapools/InitializePermissionlessPoolWithFeeTier.go b/programs/meteorapools/InitializePermissionlessPoolWithFeeTier.go new file mode 100644 index 00000000..c85ad493 --- /dev/null +++ b/programs/meteorapools/InitializePermissionlessPoolWithFeeTier.go @@ -0,0 +1,760 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "errors" + "fmt" + 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" +) + +// Initialize a new permissionless pool with customized fee tier +type InitializePermissionlessPoolWithFeeTier struct { + CurveType CurveType + TradeFeeBps *uint64 + TokenAAmount *uint64 + TokenBAmount *uint64 + + // [0] = [WRITE] pool + // ··········· Pool account (PDA address) + // + // [1] = [WRITE] lpMint + // ··········· LP token mint of the pool + // + // [2] = [] tokenAMint + // ··········· Token A mint of the pool. Eg: USDT + // + // [3] = [] tokenBMint + // ··········· Token B mint of the pool. Eg: USDC + // + // [4] = [WRITE] aVault + // ··········· Vault account for token A. Token A of the pool will be deposit / withdraw from this vault account. + // + // [5] = [WRITE] bVault + // ··········· Vault account for token B. Token B of the pool will be deposit / withdraw from this vault account. + // + // [6] = [WRITE] aTokenVault + // ··········· Token vault account of vault A + // + // [7] = [WRITE] bTokenVault + // ··········· Token vault account of vault B + // + // [8] = [WRITE] aVaultLpMint + // ··········· LP token mint of vault A + // + // [9] = [WRITE] bVaultLpMint + // ··········· LP token mint of vault B + // + // [10] = [WRITE] aVaultLp + // ··········· LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. + // + // [11] = [WRITE] bVaultLp + // ··········· LP token account of vault B. Used to receive/burn vault LP upon deposit/withdraw from the vault. + // + // [12] = [WRITE] payerTokenA + // ··········· Payer token account for pool token A mint. Used to bootstrap the pool with initial liquidity. + // + // [13] = [WRITE] payerTokenB + // ··········· Admin token account for pool token B mint. Used to bootstrap the pool with initial liquidity. + // + // [14] = [WRITE] payerPoolLp + // + // [15] = [WRITE] protocolTokenAFee + // ··········· Protocol fee token account for token A. Used to receive trading fee. + // + // [16] = [WRITE] protocolTokenBFee + // ··········· Protocol fee token account for token B. Used to receive trading fee. + // + // [17] = [WRITE, SIGNER] payer + // ··········· Admin account. This account will be the admin of the pool, and the payer for PDA during initialize pool. + // + // [18] = [] feeOwner + // + // [19] = [] rent + // ··········· Rent account. + // + // [20] = [WRITE] mintMetadata + // + // [21] = [] metadataProgram + // + // [22] = [] vaultProgram + // ··········· Vault program. The pool will deposit/withdraw liquidity from the vault. + // + // [23] = [] tokenProgram + // ··········· Token program. + // + // [24] = [] associatedTokenProgram + // ··········· Associated token program. + // + // [25] = [] systemProgram + // ··········· System program. + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewInitializePermissionlessPoolWithFeeTierInstructionBuilder creates a new `InitializePermissionlessPoolWithFeeTier` instruction builder. +func NewInitializePermissionlessPoolWithFeeTierInstructionBuilder() *InitializePermissionlessPoolWithFeeTier { + nd := &InitializePermissionlessPoolWithFeeTier{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 26), + } + return nd +} + +// SetCurveType sets the "curveType" parameter. +func (inst *InitializePermissionlessPoolWithFeeTier) SetCurveType(curveType CurveType) *InitializePermissionlessPoolWithFeeTier { + inst.CurveType = curveType + return inst +} + +// SetTradeFeeBps sets the "tradeFeeBps" parameter. +func (inst *InitializePermissionlessPoolWithFeeTier) SetTradeFeeBps(tradeFeeBps uint64) *InitializePermissionlessPoolWithFeeTier { + inst.TradeFeeBps = &tradeFeeBps + return inst +} + +// SetTokenAAmount sets the "tokenAAmount" parameter. +func (inst *InitializePermissionlessPoolWithFeeTier) SetTokenAAmount(tokenAAmount uint64) *InitializePermissionlessPoolWithFeeTier { + inst.TokenAAmount = &tokenAAmount + return inst +} + +// SetTokenBAmount sets the "tokenBAmount" parameter. +func (inst *InitializePermissionlessPoolWithFeeTier) SetTokenBAmount(tokenBAmount uint64) *InitializePermissionlessPoolWithFeeTier { + inst.TokenBAmount = &tokenBAmount + return inst +} + +// SetPoolAccount sets the "pool" account. +// Pool account (PDA address) +func (inst *InitializePermissionlessPoolWithFeeTier) SetPoolAccount(pool ag_solanago.PublicKey) *InitializePermissionlessPoolWithFeeTier { + inst.AccountMetaSlice[0] = ag_solanago.Meta(pool).WRITE() + return inst +} + +// GetPoolAccount gets the "pool" account. +// Pool account (PDA address) +func (inst *InitializePermissionlessPoolWithFeeTier) GetPoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetLpMintAccount sets the "lpMint" account. +// LP token mint of the pool +func (inst *InitializePermissionlessPoolWithFeeTier) SetLpMintAccount(lpMint ag_solanago.PublicKey) *InitializePermissionlessPoolWithFeeTier { + inst.AccountMetaSlice[1] = ag_solanago.Meta(lpMint).WRITE() + return inst +} + +// GetLpMintAccount gets the "lpMint" account. +// LP token mint of the pool +func (inst *InitializePermissionlessPoolWithFeeTier) GetLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetTokenAMintAccount sets the "tokenAMint" account. +// Token A mint of the pool. Eg: USDT +func (inst *InitializePermissionlessPoolWithFeeTier) SetTokenAMintAccount(tokenAMint ag_solanago.PublicKey) *InitializePermissionlessPoolWithFeeTier { + inst.AccountMetaSlice[2] = ag_solanago.Meta(tokenAMint) + return inst +} + +// GetTokenAMintAccount gets the "tokenAMint" account. +// Token A mint of the pool. Eg: USDT +func (inst *InitializePermissionlessPoolWithFeeTier) GetTokenAMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetTokenBMintAccount sets the "tokenBMint" account. +// Token B mint of the pool. Eg: USDC +func (inst *InitializePermissionlessPoolWithFeeTier) SetTokenBMintAccount(tokenBMint ag_solanago.PublicKey) *InitializePermissionlessPoolWithFeeTier { + inst.AccountMetaSlice[3] = ag_solanago.Meta(tokenBMint) + return inst +} + +// GetTokenBMintAccount gets the "tokenBMint" account. +// Token B mint of the pool. Eg: USDC +func (inst *InitializePermissionlessPoolWithFeeTier) GetTokenBMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetAVaultAccount sets the "aVault" account. +// Vault account for token A. Token A of the pool will be deposit / withdraw from this vault account. +func (inst *InitializePermissionlessPoolWithFeeTier) SetAVaultAccount(aVault ag_solanago.PublicKey) *InitializePermissionlessPoolWithFeeTier { + inst.AccountMetaSlice[4] = ag_solanago.Meta(aVault).WRITE() + return inst +} + +// GetAVaultAccount gets the "aVault" account. +// Vault account for token A. Token A of the pool will be deposit / withdraw from this vault account. +func (inst *InitializePermissionlessPoolWithFeeTier) GetAVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetBVaultAccount sets the "bVault" account. +// Vault account for token B. Token B of the pool will be deposit / withdraw from this vault account. +func (inst *InitializePermissionlessPoolWithFeeTier) SetBVaultAccount(bVault ag_solanago.PublicKey) *InitializePermissionlessPoolWithFeeTier { + inst.AccountMetaSlice[5] = ag_solanago.Meta(bVault).WRITE() + return inst +} + +// GetBVaultAccount gets the "bVault" account. +// Vault account for token B. Token B of the pool will be deposit / withdraw from this vault account. +func (inst *InitializePermissionlessPoolWithFeeTier) GetBVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetATokenVaultAccount sets the "aTokenVault" account. +// Token vault account of vault A +func (inst *InitializePermissionlessPoolWithFeeTier) SetATokenVaultAccount(aTokenVault ag_solanago.PublicKey) *InitializePermissionlessPoolWithFeeTier { + inst.AccountMetaSlice[6] = ag_solanago.Meta(aTokenVault).WRITE() + return inst +} + +// GetATokenVaultAccount gets the "aTokenVault" account. +// Token vault account of vault A +func (inst *InitializePermissionlessPoolWithFeeTier) GetATokenVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetBTokenVaultAccount sets the "bTokenVault" account. +// Token vault account of vault B +func (inst *InitializePermissionlessPoolWithFeeTier) SetBTokenVaultAccount(bTokenVault ag_solanago.PublicKey) *InitializePermissionlessPoolWithFeeTier { + inst.AccountMetaSlice[7] = ag_solanago.Meta(bTokenVault).WRITE() + return inst +} + +// GetBTokenVaultAccount gets the "bTokenVault" account. +// Token vault account of vault B +func (inst *InitializePermissionlessPoolWithFeeTier) GetBTokenVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetAVaultLpMintAccount sets the "aVaultLpMint" account. +// LP token mint of vault A +func (inst *InitializePermissionlessPoolWithFeeTier) SetAVaultLpMintAccount(aVaultLpMint ag_solanago.PublicKey) *InitializePermissionlessPoolWithFeeTier { + inst.AccountMetaSlice[8] = ag_solanago.Meta(aVaultLpMint).WRITE() + return inst +} + +// GetAVaultLpMintAccount gets the "aVaultLpMint" account. +// LP token mint of vault A +func (inst *InitializePermissionlessPoolWithFeeTier) GetAVaultLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetBVaultLpMintAccount sets the "bVaultLpMint" account. +// LP token mint of vault B +func (inst *InitializePermissionlessPoolWithFeeTier) SetBVaultLpMintAccount(bVaultLpMint ag_solanago.PublicKey) *InitializePermissionlessPoolWithFeeTier { + inst.AccountMetaSlice[9] = ag_solanago.Meta(bVaultLpMint).WRITE() + return inst +} + +// GetBVaultLpMintAccount gets the "bVaultLpMint" account. +// LP token mint of vault B +func (inst *InitializePermissionlessPoolWithFeeTier) GetBVaultLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetAVaultLpAccount sets the "aVaultLp" account. +// LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *InitializePermissionlessPoolWithFeeTier) SetAVaultLpAccount(aVaultLp ag_solanago.PublicKey) *InitializePermissionlessPoolWithFeeTier { + inst.AccountMetaSlice[10] = ag_solanago.Meta(aVaultLp).WRITE() + return inst +} + +// GetAVaultLpAccount gets the "aVaultLp" account. +// LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *InitializePermissionlessPoolWithFeeTier) GetAVaultLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetBVaultLpAccount sets the "bVaultLp" account. +// LP token account of vault B. Used to receive/burn vault LP upon deposit/withdraw from the vault. +func (inst *InitializePermissionlessPoolWithFeeTier) SetBVaultLpAccount(bVaultLp ag_solanago.PublicKey) *InitializePermissionlessPoolWithFeeTier { + inst.AccountMetaSlice[11] = ag_solanago.Meta(bVaultLp).WRITE() + return inst +} + +// GetBVaultLpAccount gets the "bVaultLp" account. +// LP token account of vault B. Used to receive/burn vault LP upon deposit/withdraw from the vault. +func (inst *InitializePermissionlessPoolWithFeeTier) GetBVaultLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetPayerTokenAAccount sets the "payerTokenA" account. +// Payer token account for pool token A mint. Used to bootstrap the pool with initial liquidity. +func (inst *InitializePermissionlessPoolWithFeeTier) SetPayerTokenAAccount(payerTokenA ag_solanago.PublicKey) *InitializePermissionlessPoolWithFeeTier { + inst.AccountMetaSlice[12] = ag_solanago.Meta(payerTokenA).WRITE() + return inst +} + +// GetPayerTokenAAccount gets the "payerTokenA" account. +// Payer token account for pool token A mint. Used to bootstrap the pool with initial liquidity. +func (inst *InitializePermissionlessPoolWithFeeTier) GetPayerTokenAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetPayerTokenBAccount sets the "payerTokenB" account. +// Admin token account for pool token B mint. Used to bootstrap the pool with initial liquidity. +func (inst *InitializePermissionlessPoolWithFeeTier) SetPayerTokenBAccount(payerTokenB ag_solanago.PublicKey) *InitializePermissionlessPoolWithFeeTier { + inst.AccountMetaSlice[13] = ag_solanago.Meta(payerTokenB).WRITE() + return inst +} + +// GetPayerTokenBAccount gets the "payerTokenB" account. +// Admin token account for pool token B mint. Used to bootstrap the pool with initial liquidity. +func (inst *InitializePermissionlessPoolWithFeeTier) GetPayerTokenBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetPayerPoolLpAccount sets the "payerPoolLp" account. +func (inst *InitializePermissionlessPoolWithFeeTier) SetPayerPoolLpAccount(payerPoolLp ag_solanago.PublicKey) *InitializePermissionlessPoolWithFeeTier { + inst.AccountMetaSlice[14] = ag_solanago.Meta(payerPoolLp).WRITE() + return inst +} + +// GetPayerPoolLpAccount gets the "payerPoolLp" account. +func (inst *InitializePermissionlessPoolWithFeeTier) GetPayerPoolLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +// SetProtocolTokenAFeeAccount sets the "protocolTokenAFee" account. +// Protocol fee token account for token A. Used to receive trading fee. +func (inst *InitializePermissionlessPoolWithFeeTier) SetProtocolTokenAFeeAccount(protocolTokenAFee ag_solanago.PublicKey) *InitializePermissionlessPoolWithFeeTier { + inst.AccountMetaSlice[15] = ag_solanago.Meta(protocolTokenAFee).WRITE() + return inst +} + +// GetProtocolTokenAFeeAccount gets the "protocolTokenAFee" account. +// Protocol fee token account for token A. Used to receive trading fee. +func (inst *InitializePermissionlessPoolWithFeeTier) GetProtocolTokenAFeeAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(15) +} + +// SetProtocolTokenBFeeAccount sets the "protocolTokenBFee" account. +// Protocol fee token account for token B. Used to receive trading fee. +func (inst *InitializePermissionlessPoolWithFeeTier) SetProtocolTokenBFeeAccount(protocolTokenBFee ag_solanago.PublicKey) *InitializePermissionlessPoolWithFeeTier { + inst.AccountMetaSlice[16] = ag_solanago.Meta(protocolTokenBFee).WRITE() + return inst +} + +// GetProtocolTokenBFeeAccount gets the "protocolTokenBFee" account. +// Protocol fee token account for token B. Used to receive trading fee. +func (inst *InitializePermissionlessPoolWithFeeTier) GetProtocolTokenBFeeAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(16) +} + +// SetPayerAccount sets the "payer" account. +// Admin account. This account will be the admin of the pool, and the payer for PDA during initialize pool. +func (inst *InitializePermissionlessPoolWithFeeTier) SetPayerAccount(payer ag_solanago.PublicKey) *InitializePermissionlessPoolWithFeeTier { + inst.AccountMetaSlice[17] = ag_solanago.Meta(payer).WRITE().SIGNER() + return inst +} + +// GetPayerAccount gets the "payer" account. +// Admin account. This account will be the admin of the pool, and the payer for PDA during initialize pool. +func (inst *InitializePermissionlessPoolWithFeeTier) GetPayerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(17) +} + +// SetFeeOwnerAccount sets the "feeOwner" account. +func (inst *InitializePermissionlessPoolWithFeeTier) SetFeeOwnerAccount(feeOwner ag_solanago.PublicKey) *InitializePermissionlessPoolWithFeeTier { + inst.AccountMetaSlice[18] = ag_solanago.Meta(feeOwner) + return inst +} + +// GetFeeOwnerAccount gets the "feeOwner" account. +func (inst *InitializePermissionlessPoolWithFeeTier) GetFeeOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(18) +} + +// SetRentAccount sets the "rent" account. +// Rent account. +func (inst *InitializePermissionlessPoolWithFeeTier) SetRentAccount(rent ag_solanago.PublicKey) *InitializePermissionlessPoolWithFeeTier { + inst.AccountMetaSlice[19] = ag_solanago.Meta(rent) + return inst +} + +// GetRentAccount gets the "rent" account. +// Rent account. +func (inst *InitializePermissionlessPoolWithFeeTier) GetRentAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(19) +} + +// SetMintMetadataAccount sets the "mintMetadata" account. +func (inst *InitializePermissionlessPoolWithFeeTier) SetMintMetadataAccount(mintMetadata ag_solanago.PublicKey) *InitializePermissionlessPoolWithFeeTier { + inst.AccountMetaSlice[20] = ag_solanago.Meta(mintMetadata).WRITE() + return inst +} + +// GetMintMetadataAccount gets the "mintMetadata" account. +func (inst *InitializePermissionlessPoolWithFeeTier) GetMintMetadataAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(20) +} + +// SetMetadataProgramAccount sets the "metadataProgram" account. +func (inst *InitializePermissionlessPoolWithFeeTier) SetMetadataProgramAccount(metadataProgram ag_solanago.PublicKey) *InitializePermissionlessPoolWithFeeTier { + inst.AccountMetaSlice[21] = ag_solanago.Meta(metadataProgram) + return inst +} + +// GetMetadataProgramAccount gets the "metadataProgram" account. +func (inst *InitializePermissionlessPoolWithFeeTier) GetMetadataProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(21) +} + +// SetVaultProgramAccount sets the "vaultProgram" account. +// Vault program. The pool will deposit/withdraw liquidity from the vault. +func (inst *InitializePermissionlessPoolWithFeeTier) SetVaultProgramAccount(vaultProgram ag_solanago.PublicKey) *InitializePermissionlessPoolWithFeeTier { + inst.AccountMetaSlice[22] = ag_solanago.Meta(vaultProgram) + return inst +} + +// GetVaultProgramAccount gets the "vaultProgram" account. +// Vault program. The pool will deposit/withdraw liquidity from the vault. +func (inst *InitializePermissionlessPoolWithFeeTier) GetVaultProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(22) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +// Token program. +func (inst *InitializePermissionlessPoolWithFeeTier) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *InitializePermissionlessPoolWithFeeTier { + inst.AccountMetaSlice[23] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +// Token program. +func (inst *InitializePermissionlessPoolWithFeeTier) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(23) +} + +// SetAssociatedTokenProgramAccount sets the "associatedTokenProgram" account. +// Associated token program. +func (inst *InitializePermissionlessPoolWithFeeTier) SetAssociatedTokenProgramAccount(associatedTokenProgram ag_solanago.PublicKey) *InitializePermissionlessPoolWithFeeTier { + inst.AccountMetaSlice[24] = ag_solanago.Meta(associatedTokenProgram) + return inst +} + +// GetAssociatedTokenProgramAccount gets the "associatedTokenProgram" account. +// Associated token program. +func (inst *InitializePermissionlessPoolWithFeeTier) GetAssociatedTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(24) +} + +// SetSystemProgramAccount sets the "systemProgram" account. +// System program. +func (inst *InitializePermissionlessPoolWithFeeTier) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *InitializePermissionlessPoolWithFeeTier { + inst.AccountMetaSlice[25] = ag_solanago.Meta(systemProgram) + return inst +} + +// GetSystemProgramAccount gets the "systemProgram" account. +// System program. +func (inst *InitializePermissionlessPoolWithFeeTier) GetSystemProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(25) +} + +func (inst InitializePermissionlessPoolWithFeeTier) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_InitializePermissionlessPoolWithFeeTier, + }} +} + +// 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 InitializePermissionlessPoolWithFeeTier) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *InitializePermissionlessPoolWithFeeTier) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.CurveType == nil { + return errors.New("CurveType parameter is not set") + } + if inst.TradeFeeBps == nil { + return errors.New("TradeFeeBps parameter is not set") + } + if inst.TokenAAmount == nil { + return errors.New("TokenAAmount parameter is not set") + } + if inst.TokenBAmount == nil { + return errors.New("TokenBAmount parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Pool is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.LpMint is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.TokenAMint is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.TokenBMint is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.AVault is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.BVault is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.ATokenVault is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.BTokenVault is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.AVaultLpMint is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.BVaultLpMint is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.AVaultLp is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.BVaultLp is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.PayerTokenA is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.PayerTokenB is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.PayerPoolLp is not set") + } + if inst.AccountMetaSlice[15] == nil { + return errors.New("accounts.ProtocolTokenAFee is not set") + } + if inst.AccountMetaSlice[16] == nil { + return errors.New("accounts.ProtocolTokenBFee is not set") + } + if inst.AccountMetaSlice[17] == nil { + return errors.New("accounts.Payer is not set") + } + if inst.AccountMetaSlice[18] == nil { + return errors.New("accounts.FeeOwner is not set") + } + if inst.AccountMetaSlice[19] == nil { + return errors.New("accounts.Rent is not set") + } + if inst.AccountMetaSlice[20] == nil { + return errors.New("accounts.MintMetadata is not set") + } + if inst.AccountMetaSlice[21] == nil { + return errors.New("accounts.MetadataProgram is not set") + } + if inst.AccountMetaSlice[22] == nil { + return errors.New("accounts.VaultProgram is not set") + } + if inst.AccountMetaSlice[23] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[24] == nil { + return errors.New("accounts.AssociatedTokenProgram is not set") + } + if inst.AccountMetaSlice[25] == nil { + return errors.New("accounts.SystemProgram is not set") + } + } + return nil +} + +func (inst *InitializePermissionlessPoolWithFeeTier) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("InitializePermissionlessPoolWithFeeTier")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=4]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" CurveType", inst.CurveType)) + paramsBranch.Child(ag_format.Param(" TradeFeeBps", *inst.TradeFeeBps)) + paramsBranch.Child(ag_format.Param("TokenAAmount", *inst.TokenAAmount)) + paramsBranch.Child(ag_format.Param("TokenBAmount", *inst.TokenBAmount)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=26]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" pool", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" lpMint", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" tokenAMint", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" tokenBMint", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" aVault", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" bVault", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" aTokenVault", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" bTokenVault", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" aVaultLpMint", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" bVaultLpMint", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" aVaultLp", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" bVaultLp", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" payerTokenA", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" payerTokenB", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta(" payerPoolLp", inst.AccountMetaSlice.Get(14))) + accountsBranch.Child(ag_format.Meta(" protocolTokenAFee", inst.AccountMetaSlice.Get(15))) + accountsBranch.Child(ag_format.Meta(" protocolTokenBFee", inst.AccountMetaSlice.Get(16))) + accountsBranch.Child(ag_format.Meta(" payer", inst.AccountMetaSlice.Get(17))) + accountsBranch.Child(ag_format.Meta(" feeOwner", inst.AccountMetaSlice.Get(18))) + accountsBranch.Child(ag_format.Meta(" rent", inst.AccountMetaSlice.Get(19))) + accountsBranch.Child(ag_format.Meta(" mintMetadata", inst.AccountMetaSlice.Get(20))) + accountsBranch.Child(ag_format.Meta(" metadataProgram", inst.AccountMetaSlice.Get(21))) + accountsBranch.Child(ag_format.Meta(" vaultProgram", inst.AccountMetaSlice.Get(22))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(23))) + accountsBranch.Child(ag_format.Meta("associatedTokenProgram", inst.AccountMetaSlice.Get(24))) + accountsBranch.Child(ag_format.Meta(" systemProgram", inst.AccountMetaSlice.Get(25))) + }) + }) + }) +} + +func (obj InitializePermissionlessPoolWithFeeTier) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `CurveType` param: + { + tmp := curveTypeContainer{} + switch realvalue := obj.CurveType.(type) { + case *CurveTypeConstantProduct: + tmp.Enum = 0 + tmp.ConstantProduct = *realvalue + case *CurveTypeStable: + tmp.Enum = 1 + tmp.Stable = *realvalue + } + err := encoder.Encode(tmp) + if err != nil { + return err + } + } + // Serialize `TradeFeeBps` param: + err = encoder.Encode(obj.TradeFeeBps) + if err != nil { + return err + } + // Serialize `TokenAAmount` param: + err = encoder.Encode(obj.TokenAAmount) + if err != nil { + return err + } + // Serialize `TokenBAmount` param: + err = encoder.Encode(obj.TokenBAmount) + if err != nil { + return err + } + return nil +} +func (obj *InitializePermissionlessPoolWithFeeTier) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `CurveType`: + { + tmp := new(curveTypeContainer) + err := decoder.Decode(tmp) + if err != nil { + return err + } + switch tmp.Enum { + case 0: + obj.CurveType = (*CurveTypeConstantProduct)(&tmp.Enum) + case 1: + obj.CurveType = &tmp.Stable + default: + return fmt.Errorf("unknown enum index: %v", tmp.Enum) + } + } + // Deserialize `TradeFeeBps`: + err = decoder.Decode(&obj.TradeFeeBps) + if err != nil { + return err + } + // Deserialize `TokenAAmount`: + err = decoder.Decode(&obj.TokenAAmount) + if err != nil { + return err + } + // Deserialize `TokenBAmount`: + err = decoder.Decode(&obj.TokenBAmount) + if err != nil { + return err + } + return nil +} + +// NewInitializePermissionlessPoolWithFeeTierInstruction declares a new InitializePermissionlessPoolWithFeeTier instruction with the provided parameters and accounts. +func NewInitializePermissionlessPoolWithFeeTierInstruction( + // Parameters: + curveType CurveType, + tradeFeeBps uint64, + tokenAAmount uint64, + tokenBAmount uint64, + // Accounts: + pool ag_solanago.PublicKey, + lpMint ag_solanago.PublicKey, + tokenAMint ag_solanago.PublicKey, + tokenBMint ag_solanago.PublicKey, + aVault ag_solanago.PublicKey, + bVault ag_solanago.PublicKey, + aTokenVault ag_solanago.PublicKey, + bTokenVault ag_solanago.PublicKey, + aVaultLpMint ag_solanago.PublicKey, + bVaultLpMint ag_solanago.PublicKey, + aVaultLp ag_solanago.PublicKey, + bVaultLp ag_solanago.PublicKey, + payerTokenA ag_solanago.PublicKey, + payerTokenB ag_solanago.PublicKey, + payerPoolLp ag_solanago.PublicKey, + protocolTokenAFee ag_solanago.PublicKey, + protocolTokenBFee ag_solanago.PublicKey, + payer ag_solanago.PublicKey, + feeOwner ag_solanago.PublicKey, + rent ag_solanago.PublicKey, + mintMetadata ag_solanago.PublicKey, + metadataProgram ag_solanago.PublicKey, + vaultProgram ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + associatedTokenProgram ag_solanago.PublicKey, + systemProgram ag_solanago.PublicKey) *InitializePermissionlessPoolWithFeeTier { + return NewInitializePermissionlessPoolWithFeeTierInstructionBuilder(). + SetCurveType(curveType). + SetTradeFeeBps(tradeFeeBps). + SetTokenAAmount(tokenAAmount). + SetTokenBAmount(tokenBAmount). + SetPoolAccount(pool). + SetLpMintAccount(lpMint). + SetTokenAMintAccount(tokenAMint). + SetTokenBMintAccount(tokenBMint). + SetAVaultAccount(aVault). + SetBVaultAccount(bVault). + SetATokenVaultAccount(aTokenVault). + SetBTokenVaultAccount(bTokenVault). + SetAVaultLpMintAccount(aVaultLpMint). + SetBVaultLpMintAccount(bVaultLpMint). + SetAVaultLpAccount(aVaultLp). + SetBVaultLpAccount(bVaultLp). + SetPayerTokenAAccount(payerTokenA). + SetPayerTokenBAccount(payerTokenB). + SetPayerPoolLpAccount(payerPoolLp). + SetProtocolTokenAFeeAccount(protocolTokenAFee). + SetProtocolTokenBFeeAccount(protocolTokenBFee). + SetPayerAccount(payer). + SetFeeOwnerAccount(feeOwner). + SetRentAccount(rent). + SetMintMetadataAccount(mintMetadata). + SetMetadataProgramAccount(metadataProgram). + SetVaultProgramAccount(vaultProgram). + SetTokenProgramAccount(tokenProgram). + SetAssociatedTokenProgramAccount(associatedTokenProgram). + SetSystemProgramAccount(systemProgram) +} diff --git a/programs/meteorapools/InitializePermissionlessPoolWithFeeTier_test.go b/programs/meteorapools/InitializePermissionlessPoolWithFeeTier_test.go new file mode 100644 index 00000000..a3035bc0 --- /dev/null +++ b/programs/meteorapools/InitializePermissionlessPoolWithFeeTier_test.go @@ -0,0 +1,55 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_InitializePermissionlessPoolWithFeeTier(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("InitializePermissionlessPoolWithFeeTier"+strconv.Itoa(i), func(t *testing.T) { + { + { + { + params := new(InitializePermissionlessPoolWithFeeTier) + fu.Fuzz(params) + params.AccountMetaSlice = nil + tmp := new(ConstantProduct) + fu.Fuzz(tmp) + params.SetCurveType(tmp) + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(InitializePermissionlessPoolWithFeeTier) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + { + params := new(InitializePermissionlessPoolWithFeeTier) + fu.Fuzz(params) + params.AccountMetaSlice = nil + tmp := new(Stable) + fu.Fuzz(tmp) + params.SetCurveType(tmp) + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(InitializePermissionlessPoolWithFeeTier) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + } + } + }) + } +} diff --git a/programs/meteorapools/InitializePermissionlessPool_test.go b/programs/meteorapools/InitializePermissionlessPool_test.go new file mode 100644 index 00000000..69ff75ed --- /dev/null +++ b/programs/meteorapools/InitializePermissionlessPool_test.go @@ -0,0 +1,55 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_InitializePermissionlessPool(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("InitializePermissionlessPool"+strconv.Itoa(i), func(t *testing.T) { + { + { + { + params := new(InitializePermissionlessPool) + fu.Fuzz(params) + params.AccountMetaSlice = nil + tmp := new(ConstantProduct) + fu.Fuzz(tmp) + params.SetCurveType(tmp) + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(InitializePermissionlessPool) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + { + params := new(InitializePermissionlessPool) + fu.Fuzz(params) + params.AccountMetaSlice = nil + tmp := new(Stable) + fu.Fuzz(tmp) + params.SetCurveType(tmp) + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(InitializePermissionlessPool) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + } + } + }) + } +} diff --git a/programs/meteorapools/Lock.go b/programs/meteorapools/Lock.go new file mode 100644 index 00000000..25902976 --- /dev/null +++ b/programs/meteorapools/Lock.go @@ -0,0 +1,394 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "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" +) + +// Lock Lp token +type Lock struct { + MaxAmount *uint64 + + // [0] = [WRITE] pool + // ··········· Pool account + // + // [1] = [] lpMint + // ··········· LP token mint of the pool + // + // [2] = [WRITE] lockEscrow + // ··········· Lock account + // + // [3] = [WRITE, SIGNER] owner + // ··········· Can be anyone + // + // [4] = [WRITE] sourceTokens + // ··········· owner lp token account + // + // [5] = [WRITE] escrowVault + // ··········· Escrow vault + // + // [6] = [] tokenProgram + // ··········· Token program. + // + // [7] = [] aVault + // ··········· Vault account for token a. token a of the pool will be deposit / withdraw from this vault account. + // + // [8] = [] bVault + // ··········· Vault account for token b. token b of the pool will be deposit / withdraw from this vault account. + // + // [9] = [] aVaultLp + // ··········· LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. + // + // [10] = [] bVaultLp + // ··········· LP token account of vault B. Used to receive/burn the vault LP upon deposit/withdraw from the vault. + // + // [11] = [] aVaultLpMint + // ··········· LP token mint of vault a + // + // [12] = [] bVaultLpMint + // ··········· LP token mint of vault b + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewLockInstructionBuilder creates a new `Lock` instruction builder. +func NewLockInstructionBuilder() *Lock { + nd := &Lock{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 13), + } + return nd +} + +// SetMaxAmount sets the "maxAmount" parameter. +func (inst *Lock) SetMaxAmount(maxAmount uint64) *Lock { + inst.MaxAmount = &maxAmount + return inst +} + +// SetPoolAccount sets the "pool" account. +// Pool account +func (inst *Lock) SetPoolAccount(pool ag_solanago.PublicKey) *Lock { + inst.AccountMetaSlice[0] = ag_solanago.Meta(pool).WRITE() + return inst +} + +// GetPoolAccount gets the "pool" account. +// Pool account +func (inst *Lock) GetPoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetLpMintAccount sets the "lpMint" account. +// LP token mint of the pool +func (inst *Lock) SetLpMintAccount(lpMint ag_solanago.PublicKey) *Lock { + inst.AccountMetaSlice[1] = ag_solanago.Meta(lpMint) + return inst +} + +// GetLpMintAccount gets the "lpMint" account. +// LP token mint of the pool +func (inst *Lock) GetLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetLockEscrowAccount sets the "lockEscrow" account. +// Lock account +func (inst *Lock) SetLockEscrowAccount(lockEscrow ag_solanago.PublicKey) *Lock { + inst.AccountMetaSlice[2] = ag_solanago.Meta(lockEscrow).WRITE() + return inst +} + +// GetLockEscrowAccount gets the "lockEscrow" account. +// Lock account +func (inst *Lock) GetLockEscrowAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetOwnerAccount sets the "owner" account. +// Can be anyone +func (inst *Lock) SetOwnerAccount(owner ag_solanago.PublicKey) *Lock { + inst.AccountMetaSlice[3] = ag_solanago.Meta(owner).WRITE().SIGNER() + return inst +} + +// GetOwnerAccount gets the "owner" account. +// Can be anyone +func (inst *Lock) GetOwnerAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetSourceTokensAccount sets the "sourceTokens" account. +// owner lp token account +func (inst *Lock) SetSourceTokensAccount(sourceTokens ag_solanago.PublicKey) *Lock { + inst.AccountMetaSlice[4] = ag_solanago.Meta(sourceTokens).WRITE() + return inst +} + +// GetSourceTokensAccount gets the "sourceTokens" account. +// owner lp token account +func (inst *Lock) GetSourceTokensAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetEscrowVaultAccount sets the "escrowVault" account. +// Escrow vault +func (inst *Lock) SetEscrowVaultAccount(escrowVault ag_solanago.PublicKey) *Lock { + inst.AccountMetaSlice[5] = ag_solanago.Meta(escrowVault).WRITE() + return inst +} + +// GetEscrowVaultAccount gets the "escrowVault" account. +// Escrow vault +func (inst *Lock) GetEscrowVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +// Token program. +func (inst *Lock) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *Lock { + inst.AccountMetaSlice[6] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +// Token program. +func (inst *Lock) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetAVaultAccount sets the "aVault" account. +// Vault account for token a. token a of the pool will be deposit / withdraw from this vault account. +func (inst *Lock) SetAVaultAccount(aVault ag_solanago.PublicKey) *Lock { + inst.AccountMetaSlice[7] = ag_solanago.Meta(aVault) + return inst +} + +// GetAVaultAccount gets the "aVault" account. +// Vault account for token a. token a of the pool will be deposit / withdraw from this vault account. +func (inst *Lock) GetAVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetBVaultAccount sets the "bVault" account. +// Vault account for token b. token b of the pool will be deposit / withdraw from this vault account. +func (inst *Lock) SetBVaultAccount(bVault ag_solanago.PublicKey) *Lock { + inst.AccountMetaSlice[8] = ag_solanago.Meta(bVault) + return inst +} + +// GetBVaultAccount gets the "bVault" account. +// Vault account for token b. token b of the pool will be deposit / withdraw from this vault account. +func (inst *Lock) GetBVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetAVaultLpAccount sets the "aVaultLp" account. +// LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *Lock) SetAVaultLpAccount(aVaultLp ag_solanago.PublicKey) *Lock { + inst.AccountMetaSlice[9] = ag_solanago.Meta(aVaultLp) + return inst +} + +// GetAVaultLpAccount gets the "aVaultLp" account. +// LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *Lock) GetAVaultLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetBVaultLpAccount sets the "bVaultLp" account. +// LP token account of vault B. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *Lock) SetBVaultLpAccount(bVaultLp ag_solanago.PublicKey) *Lock { + inst.AccountMetaSlice[10] = ag_solanago.Meta(bVaultLp) + return inst +} + +// GetBVaultLpAccount gets the "bVaultLp" account. +// LP token account of vault B. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *Lock) GetBVaultLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetAVaultLpMintAccount sets the "aVaultLpMint" account. +// LP token mint of vault a +func (inst *Lock) SetAVaultLpMintAccount(aVaultLpMint ag_solanago.PublicKey) *Lock { + inst.AccountMetaSlice[11] = ag_solanago.Meta(aVaultLpMint) + return inst +} + +// GetAVaultLpMintAccount gets the "aVaultLpMint" account. +// LP token mint of vault a +func (inst *Lock) GetAVaultLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetBVaultLpMintAccount sets the "bVaultLpMint" account. +// LP token mint of vault b +func (inst *Lock) SetBVaultLpMintAccount(bVaultLpMint ag_solanago.PublicKey) *Lock { + inst.AccountMetaSlice[12] = ag_solanago.Meta(bVaultLpMint) + return inst +} + +// GetBVaultLpMintAccount gets the "bVaultLpMint" account. +// LP token mint of vault b +func (inst *Lock) GetBVaultLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +func (inst Lock) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_Lock, + }} +} + +// 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 Lock) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *Lock) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.MaxAmount == nil { + return errors.New("MaxAmount parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Pool is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.LpMint is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.LockEscrow is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.Owner is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.SourceTokens is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.EscrowVault is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.AVault is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.BVault is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.AVaultLp is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.BVaultLp is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.AVaultLpMint is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.BVaultLpMint is not set") + } + } + return nil +} + +func (inst *Lock) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("Lock")). + // + 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("MaxAmount", *inst.MaxAmount)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=13]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" pool", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" lpMint", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" lockEscrow", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" owner", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta("sourceTokens", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" escrowVault", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta("tokenProgram", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" aVault", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" bVault", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" aVaultLp", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" bVaultLp", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta("aVaultLpMint", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta("bVaultLpMint", inst.AccountMetaSlice.Get(12))) + }) + }) + }) +} + +func (obj Lock) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `MaxAmount` param: + err = encoder.Encode(obj.MaxAmount) + if err != nil { + return err + } + return nil +} +func (obj *Lock) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `MaxAmount`: + err = decoder.Decode(&obj.MaxAmount) + if err != nil { + return err + } + return nil +} + +// NewLockInstruction declares a new Lock instruction with the provided parameters and accounts. +func NewLockInstruction( + // Parameters: + maxAmount uint64, + // Accounts: + pool ag_solanago.PublicKey, + lpMint ag_solanago.PublicKey, + lockEscrow ag_solanago.PublicKey, + owner ag_solanago.PublicKey, + sourceTokens ag_solanago.PublicKey, + escrowVault ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + aVault ag_solanago.PublicKey, + bVault ag_solanago.PublicKey, + aVaultLp ag_solanago.PublicKey, + bVaultLp ag_solanago.PublicKey, + aVaultLpMint ag_solanago.PublicKey, + bVaultLpMint ag_solanago.PublicKey) *Lock { + return NewLockInstructionBuilder(). + SetMaxAmount(maxAmount). + SetPoolAccount(pool). + SetLpMintAccount(lpMint). + SetLockEscrowAccount(lockEscrow). + SetOwnerAccount(owner). + SetSourceTokensAccount(sourceTokens). + SetEscrowVaultAccount(escrowVault). + SetTokenProgramAccount(tokenProgram). + SetAVaultAccount(aVault). + SetBVaultAccount(bVault). + SetAVaultLpAccount(aVaultLp). + SetBVaultLpAccount(bVaultLp). + SetAVaultLpMintAccount(aVaultLpMint). + SetBVaultLpMintAccount(bVaultLpMint) +} diff --git a/programs/meteorapools/Lock_test.go b/programs/meteorapools/Lock_test.go new file mode 100644 index 00000000..7e2f91bd --- /dev/null +++ b/programs/meteorapools/Lock_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_Lock(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("Lock"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(Lock) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(Lock) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteorapools/OverrideCurveParam.go b/programs/meteorapools/OverrideCurveParam.go new file mode 100644 index 00000000..0e453404 --- /dev/null +++ b/programs/meteorapools/OverrideCurveParam.go @@ -0,0 +1,176 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "errors" + "fmt" + 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" +) + +// Update swap curve parameters. This function do not allow update of curve type. For example: stable swap curve to constant product curve. Only supported by pool with stable swap curve. +// Only amp is allowed to be override. The other attributes of stable swap curve will be ignored. +type OverrideCurveParam struct { + CurveType CurveType + + // [0] = [WRITE] pool + // ··········· Pool account (PDA) + // + // [1] = [SIGNER] admin + // ··········· Admin account. + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewOverrideCurveParamInstructionBuilder creates a new `OverrideCurveParam` instruction builder. +func NewOverrideCurveParamInstructionBuilder() *OverrideCurveParam { + nd := &OverrideCurveParam{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 2), + } + return nd +} + +// SetCurveType sets the "curveType" parameter. +func (inst *OverrideCurveParam) SetCurveType(curveType CurveType) *OverrideCurveParam { + inst.CurveType = curveType + return inst +} + +// SetPoolAccount sets the "pool" account. +// Pool account (PDA) +func (inst *OverrideCurveParam) SetPoolAccount(pool ag_solanago.PublicKey) *OverrideCurveParam { + inst.AccountMetaSlice[0] = ag_solanago.Meta(pool).WRITE() + return inst +} + +// GetPoolAccount gets the "pool" account. +// Pool account (PDA) +func (inst *OverrideCurveParam) GetPoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetAdminAccount sets the "admin" account. +// Admin account. +func (inst *OverrideCurveParam) SetAdminAccount(admin ag_solanago.PublicKey) *OverrideCurveParam { + inst.AccountMetaSlice[1] = ag_solanago.Meta(admin).SIGNER() + return inst +} + +// GetAdminAccount gets the "admin" account. +// Admin account. +func (inst *OverrideCurveParam) GetAdminAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +func (inst OverrideCurveParam) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_OverrideCurveParam, + }} +} + +// 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 OverrideCurveParam) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *OverrideCurveParam) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.CurveType == nil { + return errors.New("CurveType parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Pool is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Admin is not set") + } + } + return nil +} + +func (inst *OverrideCurveParam) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("OverrideCurveParam")). + // + 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("CurveType", inst.CurveType)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=2]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" pool", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta("admin", inst.AccountMetaSlice.Get(1))) + }) + }) + }) +} + +func (obj OverrideCurveParam) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `CurveType` param: + { + tmp := curveTypeContainer{} + switch realvalue := obj.CurveType.(type) { + case *CurveTypeConstantProduct: + tmp.Enum = 0 + tmp.ConstantProduct = *realvalue + case *CurveTypeStable: + tmp.Enum = 1 + tmp.Stable = *realvalue + } + err := encoder.Encode(tmp) + if err != nil { + return err + } + } + return nil +} +func (obj *OverrideCurveParam) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `CurveType`: + { + tmp := new(curveTypeContainer) + err := decoder.Decode(tmp) + if err != nil { + return err + } + switch tmp.Enum { + case 0: + obj.CurveType = (*CurveTypeConstantProduct)(&tmp.Enum) + case 1: + obj.CurveType = &tmp.Stable + default: + return fmt.Errorf("unknown enum index: %v", tmp.Enum) + } + } + return nil +} + +// NewOverrideCurveParamInstruction declares a new OverrideCurveParam instruction with the provided parameters and accounts. +func NewOverrideCurveParamInstruction( + // Parameters: + curveType CurveType, + // Accounts: + pool ag_solanago.PublicKey, + admin ag_solanago.PublicKey) *OverrideCurveParam { + return NewOverrideCurveParamInstructionBuilder(). + SetCurveType(curveType). + SetPoolAccount(pool). + SetAdminAccount(admin) +} diff --git a/programs/meteorapools/OverrideCurveParam_test.go b/programs/meteorapools/OverrideCurveParam_test.go new file mode 100644 index 00000000..ef499b5d --- /dev/null +++ b/programs/meteorapools/OverrideCurveParam_test.go @@ -0,0 +1,55 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_OverrideCurveParam(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("OverrideCurveParam"+strconv.Itoa(i), func(t *testing.T) { + { + { + { + params := new(OverrideCurveParam) + fu.Fuzz(params) + params.AccountMetaSlice = nil + tmp := new(ConstantProduct) + fu.Fuzz(tmp) + params.SetCurveType(tmp) + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(OverrideCurveParam) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + { + params := new(OverrideCurveParam) + fu.Fuzz(params) + params.AccountMetaSlice = nil + tmp := new(Stable) + fu.Fuzz(tmp) + params.SetCurveType(tmp) + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(OverrideCurveParam) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + } + } + }) + } +} diff --git a/programs/meteorapools/PartnerClaimFee.go b/programs/meteorapools/PartnerClaimFee.go new file mode 100644 index 00000000..0033eb9c --- /dev/null +++ b/programs/meteorapools/PartnerClaimFee.go @@ -0,0 +1,286 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "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" +) + +// Partner claim fee +type PartnerClaimFee struct { + MaxAmountA *uint64 + MaxAmountB *uint64 + + // [0] = [WRITE] pool + // ··········· Pool account (PDA) + // + // [1] = [] aVaultLp + // + // [2] = [WRITE] protocolTokenAFee + // + // [3] = [WRITE] protocolTokenBFee + // + // [4] = [WRITE] partnerTokenA + // + // [5] = [WRITE] partnerTokenB + // + // [6] = [] tokenProgram + // + // [7] = [SIGNER] partnerAuthority + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewPartnerClaimFeeInstructionBuilder creates a new `PartnerClaimFee` instruction builder. +func NewPartnerClaimFeeInstructionBuilder() *PartnerClaimFee { + nd := &PartnerClaimFee{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 8), + } + return nd +} + +// SetMaxAmountA sets the "maxAmountA" parameter. +func (inst *PartnerClaimFee) SetMaxAmountA(maxAmountA uint64) *PartnerClaimFee { + inst.MaxAmountA = &maxAmountA + return inst +} + +// SetMaxAmountB sets the "maxAmountB" parameter. +func (inst *PartnerClaimFee) SetMaxAmountB(maxAmountB uint64) *PartnerClaimFee { + inst.MaxAmountB = &maxAmountB + return inst +} + +// SetPoolAccount sets the "pool" account. +// Pool account (PDA) +func (inst *PartnerClaimFee) SetPoolAccount(pool ag_solanago.PublicKey) *PartnerClaimFee { + inst.AccountMetaSlice[0] = ag_solanago.Meta(pool).WRITE() + return inst +} + +// GetPoolAccount gets the "pool" account. +// Pool account (PDA) +func (inst *PartnerClaimFee) GetPoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetAVaultLpAccount sets the "aVaultLp" account. +func (inst *PartnerClaimFee) SetAVaultLpAccount(aVaultLp ag_solanago.PublicKey) *PartnerClaimFee { + inst.AccountMetaSlice[1] = ag_solanago.Meta(aVaultLp) + return inst +} + +// GetAVaultLpAccount gets the "aVaultLp" account. +func (inst *PartnerClaimFee) GetAVaultLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetProtocolTokenAFeeAccount sets the "protocolTokenAFee" account. +func (inst *PartnerClaimFee) SetProtocolTokenAFeeAccount(protocolTokenAFee ag_solanago.PublicKey) *PartnerClaimFee { + inst.AccountMetaSlice[2] = ag_solanago.Meta(protocolTokenAFee).WRITE() + return inst +} + +// GetProtocolTokenAFeeAccount gets the "protocolTokenAFee" account. +func (inst *PartnerClaimFee) GetProtocolTokenAFeeAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetProtocolTokenBFeeAccount sets the "protocolTokenBFee" account. +func (inst *PartnerClaimFee) SetProtocolTokenBFeeAccount(protocolTokenBFee ag_solanago.PublicKey) *PartnerClaimFee { + inst.AccountMetaSlice[3] = ag_solanago.Meta(protocolTokenBFee).WRITE() + return inst +} + +// GetProtocolTokenBFeeAccount gets the "protocolTokenBFee" account. +func (inst *PartnerClaimFee) GetProtocolTokenBFeeAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetPartnerTokenAAccount sets the "partnerTokenA" account. +func (inst *PartnerClaimFee) SetPartnerTokenAAccount(partnerTokenA ag_solanago.PublicKey) *PartnerClaimFee { + inst.AccountMetaSlice[4] = ag_solanago.Meta(partnerTokenA).WRITE() + return inst +} + +// GetPartnerTokenAAccount gets the "partnerTokenA" account. +func (inst *PartnerClaimFee) GetPartnerTokenAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetPartnerTokenBAccount sets the "partnerTokenB" account. +func (inst *PartnerClaimFee) SetPartnerTokenBAccount(partnerTokenB ag_solanago.PublicKey) *PartnerClaimFee { + inst.AccountMetaSlice[5] = ag_solanago.Meta(partnerTokenB).WRITE() + return inst +} + +// GetPartnerTokenBAccount gets the "partnerTokenB" account. +func (inst *PartnerClaimFee) GetPartnerTokenBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *PartnerClaimFee) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *PartnerClaimFee { + inst.AccountMetaSlice[6] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *PartnerClaimFee) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetPartnerAuthorityAccount sets the "partnerAuthority" account. +func (inst *PartnerClaimFee) SetPartnerAuthorityAccount(partnerAuthority ag_solanago.PublicKey) *PartnerClaimFee { + inst.AccountMetaSlice[7] = ag_solanago.Meta(partnerAuthority).SIGNER() + return inst +} + +// GetPartnerAuthorityAccount gets the "partnerAuthority" account. +func (inst *PartnerClaimFee) GetPartnerAuthorityAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +func (inst PartnerClaimFee) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_PartnerClaimFee, + }} +} + +// 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 PartnerClaimFee) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *PartnerClaimFee) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.MaxAmountA == nil { + return errors.New("MaxAmountA parameter is not set") + } + if inst.MaxAmountB == nil { + return errors.New("MaxAmountB parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Pool is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.AVaultLp is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.ProtocolTokenAFee is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.ProtocolTokenBFee is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.PartnerTokenA is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.PartnerTokenB is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.TokenProgram is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.PartnerAuthority is not set") + } + } + return nil +} + +func (inst *PartnerClaimFee) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("PartnerClaimFee")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=2]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param("MaxAmountA", *inst.MaxAmountA)) + paramsBranch.Child(ag_format.Param("MaxAmountB", *inst.MaxAmountB)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=8]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" pool", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" aVaultLp", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta("protocolTokenAFee", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta("protocolTokenBFee", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" partnerTokenA", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" partnerTokenB", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" partnerAuthority", inst.AccountMetaSlice.Get(7))) + }) + }) + }) +} + +func (obj PartnerClaimFee) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `MaxAmountA` param: + err = encoder.Encode(obj.MaxAmountA) + if err != nil { + return err + } + // Serialize `MaxAmountB` param: + err = encoder.Encode(obj.MaxAmountB) + if err != nil { + return err + } + return nil +} +func (obj *PartnerClaimFee) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `MaxAmountA`: + err = decoder.Decode(&obj.MaxAmountA) + if err != nil { + return err + } + // Deserialize `MaxAmountB`: + err = decoder.Decode(&obj.MaxAmountB) + if err != nil { + return err + } + return nil +} + +// NewPartnerClaimFeeInstruction declares a new PartnerClaimFee instruction with the provided parameters and accounts. +func NewPartnerClaimFeeInstruction( + // Parameters: + maxAmountA uint64, + maxAmountB uint64, + // Accounts: + pool ag_solanago.PublicKey, + aVaultLp ag_solanago.PublicKey, + protocolTokenAFee ag_solanago.PublicKey, + protocolTokenBFee ag_solanago.PublicKey, + partnerTokenA ag_solanago.PublicKey, + partnerTokenB ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey, + partnerAuthority ag_solanago.PublicKey) *PartnerClaimFee { + return NewPartnerClaimFeeInstructionBuilder(). + SetMaxAmountA(maxAmountA). + SetMaxAmountB(maxAmountB). + SetPoolAccount(pool). + SetAVaultLpAccount(aVaultLp). + SetProtocolTokenAFeeAccount(protocolTokenAFee). + SetProtocolTokenBFeeAccount(protocolTokenBFee). + SetPartnerTokenAAccount(partnerTokenA). + SetPartnerTokenBAccount(partnerTokenB). + SetTokenProgramAccount(tokenProgram). + SetPartnerAuthorityAccount(partnerAuthority) +} diff --git a/programs/meteorapools/PartnerClaimFee_test.go b/programs/meteorapools/PartnerClaimFee_test.go new file mode 100644 index 00000000..3dd01663 --- /dev/null +++ b/programs/meteorapools/PartnerClaimFee_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_PartnerClaimFee(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("PartnerClaimFee"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(PartnerClaimFee) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(PartnerClaimFee) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteorapools/RemoveBalanceLiquidity.go b/programs/meteorapools/RemoveBalanceLiquidity.go new file mode 100644 index 00000000..123fea93 --- /dev/null +++ b/programs/meteorapools/RemoveBalanceLiquidity.go @@ -0,0 +1,506 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "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" +) + +// Withdraw tokens from the pool in a balanced ratio. User will still able to withdraw from pool even the pool is disabled. This allow user to exit their liquidity when there's some unforeseen event happen. +type RemoveBalanceLiquidity struct { + PoolTokenAmount *uint64 + MinimumATokenOut *uint64 + MinimumBTokenOut *uint64 + + // [0] = [WRITE] pool + // ··········· Pool account (PDA) + // + // [1] = [WRITE] lpMint + // ··········· LP token mint of the pool + // + // [2] = [WRITE] userPoolLp + // ··········· user pool lp token account. lp will be burned from this account upon success liquidity removal. + // + // [3] = [WRITE] aVaultLp + // ··········· LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. + // + // [4] = [WRITE] bVaultLp + // ··········· LP token account of vault B. Used to receive/burn the vault LP upon deposit/withdraw from the vault. + // + // [5] = [WRITE] aVault + // ··········· Vault account for token a. token a of the pool will be deposit / withdraw from this vault account. + // + // [6] = [WRITE] bVault + // ··········· Vault account for token b. token b of the pool will be deposit / withdraw from this vault account. + // + // [7] = [WRITE] aVaultLpMint + // ··········· LP token mint of vault a + // + // [8] = [WRITE] bVaultLpMint + // ··········· LP token mint of vault b + // + // [9] = [WRITE] aTokenVault + // ··········· Token vault account of vault A + // + // [10] = [WRITE] bTokenVault + // ··········· Token vault account of vault B + // + // [11] = [WRITE] userAToken + // ··········· User token A account. Token will be transfer from this account if it is add liquidity operation. Else, token will be transfer into this account. + // + // [12] = [WRITE] userBToken + // ··········· User token B account. Token will be transfer from this account if it is add liquidity operation. Else, token will be transfer into this account. + // + // [13] = [SIGNER] user + // ··········· User account. Must be owner of user_a_token, and user_b_token. + // + // [14] = [] vaultProgram + // ··········· Vault program. the pool will deposit/withdraw liquidity from the vault. + // + // [15] = [] tokenProgram + // ··········· Token program. + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewRemoveBalanceLiquidityInstructionBuilder creates a new `RemoveBalanceLiquidity` instruction builder. +func NewRemoveBalanceLiquidityInstructionBuilder() *RemoveBalanceLiquidity { + nd := &RemoveBalanceLiquidity{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 16), + } + return nd +} + +// SetPoolTokenAmount sets the "poolTokenAmount" parameter. +func (inst *RemoveBalanceLiquidity) SetPoolTokenAmount(poolTokenAmount uint64) *RemoveBalanceLiquidity { + inst.PoolTokenAmount = &poolTokenAmount + return inst +} + +// SetMinimumATokenOut sets the "minimumATokenOut" parameter. +func (inst *RemoveBalanceLiquidity) SetMinimumATokenOut(minimumATokenOut uint64) *RemoveBalanceLiquidity { + inst.MinimumATokenOut = &minimumATokenOut + return inst +} + +// SetMinimumBTokenOut sets the "minimumBTokenOut" parameter. +func (inst *RemoveBalanceLiquidity) SetMinimumBTokenOut(minimumBTokenOut uint64) *RemoveBalanceLiquidity { + inst.MinimumBTokenOut = &minimumBTokenOut + return inst +} + +// SetPoolAccount sets the "pool" account. +// Pool account (PDA) +func (inst *RemoveBalanceLiquidity) SetPoolAccount(pool ag_solanago.PublicKey) *RemoveBalanceLiquidity { + inst.AccountMetaSlice[0] = ag_solanago.Meta(pool).WRITE() + return inst +} + +// GetPoolAccount gets the "pool" account. +// Pool account (PDA) +func (inst *RemoveBalanceLiquidity) GetPoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetLpMintAccount sets the "lpMint" account. +// LP token mint of the pool +func (inst *RemoveBalanceLiquidity) SetLpMintAccount(lpMint ag_solanago.PublicKey) *RemoveBalanceLiquidity { + inst.AccountMetaSlice[1] = ag_solanago.Meta(lpMint).WRITE() + return inst +} + +// GetLpMintAccount gets the "lpMint" account. +// LP token mint of the pool +func (inst *RemoveBalanceLiquidity) GetLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetUserPoolLpAccount sets the "userPoolLp" account. +// user pool lp token account. lp will be burned from this account upon success liquidity removal. +func (inst *RemoveBalanceLiquidity) SetUserPoolLpAccount(userPoolLp ag_solanago.PublicKey) *RemoveBalanceLiquidity { + inst.AccountMetaSlice[2] = ag_solanago.Meta(userPoolLp).WRITE() + return inst +} + +// GetUserPoolLpAccount gets the "userPoolLp" account. +// user pool lp token account. lp will be burned from this account upon success liquidity removal. +func (inst *RemoveBalanceLiquidity) GetUserPoolLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetAVaultLpAccount sets the "aVaultLp" account. +// LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *RemoveBalanceLiquidity) SetAVaultLpAccount(aVaultLp ag_solanago.PublicKey) *RemoveBalanceLiquidity { + inst.AccountMetaSlice[3] = ag_solanago.Meta(aVaultLp).WRITE() + return inst +} + +// GetAVaultLpAccount gets the "aVaultLp" account. +// LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *RemoveBalanceLiquidity) GetAVaultLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetBVaultLpAccount sets the "bVaultLp" account. +// LP token account of vault B. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *RemoveBalanceLiquidity) SetBVaultLpAccount(bVaultLp ag_solanago.PublicKey) *RemoveBalanceLiquidity { + inst.AccountMetaSlice[4] = ag_solanago.Meta(bVaultLp).WRITE() + return inst +} + +// GetBVaultLpAccount gets the "bVaultLp" account. +// LP token account of vault B. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *RemoveBalanceLiquidity) GetBVaultLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetAVaultAccount sets the "aVault" account. +// Vault account for token a. token a of the pool will be deposit / withdraw from this vault account. +func (inst *RemoveBalanceLiquidity) SetAVaultAccount(aVault ag_solanago.PublicKey) *RemoveBalanceLiquidity { + inst.AccountMetaSlice[5] = ag_solanago.Meta(aVault).WRITE() + return inst +} + +// GetAVaultAccount gets the "aVault" account. +// Vault account for token a. token a of the pool will be deposit / withdraw from this vault account. +func (inst *RemoveBalanceLiquidity) GetAVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetBVaultAccount sets the "bVault" account. +// Vault account for token b. token b of the pool will be deposit / withdraw from this vault account. +func (inst *RemoveBalanceLiquidity) SetBVaultAccount(bVault ag_solanago.PublicKey) *RemoveBalanceLiquidity { + inst.AccountMetaSlice[6] = ag_solanago.Meta(bVault).WRITE() + return inst +} + +// GetBVaultAccount gets the "bVault" account. +// Vault account for token b. token b of the pool will be deposit / withdraw from this vault account. +func (inst *RemoveBalanceLiquidity) GetBVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetAVaultLpMintAccount sets the "aVaultLpMint" account. +// LP token mint of vault a +func (inst *RemoveBalanceLiquidity) SetAVaultLpMintAccount(aVaultLpMint ag_solanago.PublicKey) *RemoveBalanceLiquidity { + inst.AccountMetaSlice[7] = ag_solanago.Meta(aVaultLpMint).WRITE() + return inst +} + +// GetAVaultLpMintAccount gets the "aVaultLpMint" account. +// LP token mint of vault a +func (inst *RemoveBalanceLiquidity) GetAVaultLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetBVaultLpMintAccount sets the "bVaultLpMint" account. +// LP token mint of vault b +func (inst *RemoveBalanceLiquidity) SetBVaultLpMintAccount(bVaultLpMint ag_solanago.PublicKey) *RemoveBalanceLiquidity { + inst.AccountMetaSlice[8] = ag_solanago.Meta(bVaultLpMint).WRITE() + return inst +} + +// GetBVaultLpMintAccount gets the "bVaultLpMint" account. +// LP token mint of vault b +func (inst *RemoveBalanceLiquidity) GetBVaultLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetATokenVaultAccount sets the "aTokenVault" account. +// Token vault account of vault A +func (inst *RemoveBalanceLiquidity) SetATokenVaultAccount(aTokenVault ag_solanago.PublicKey) *RemoveBalanceLiquidity { + inst.AccountMetaSlice[9] = ag_solanago.Meta(aTokenVault).WRITE() + return inst +} + +// GetATokenVaultAccount gets the "aTokenVault" account. +// Token vault account of vault A +func (inst *RemoveBalanceLiquidity) GetATokenVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetBTokenVaultAccount sets the "bTokenVault" account. +// Token vault account of vault B +func (inst *RemoveBalanceLiquidity) SetBTokenVaultAccount(bTokenVault ag_solanago.PublicKey) *RemoveBalanceLiquidity { + inst.AccountMetaSlice[10] = ag_solanago.Meta(bTokenVault).WRITE() + return inst +} + +// GetBTokenVaultAccount gets the "bTokenVault" account. +// Token vault account of vault B +func (inst *RemoveBalanceLiquidity) GetBTokenVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetUserATokenAccount sets the "userAToken" account. +// User token A account. Token will be transfer from this account if it is add liquidity operation. Else, token will be transfer into this account. +func (inst *RemoveBalanceLiquidity) SetUserATokenAccount(userAToken ag_solanago.PublicKey) *RemoveBalanceLiquidity { + inst.AccountMetaSlice[11] = ag_solanago.Meta(userAToken).WRITE() + return inst +} + +// GetUserATokenAccount gets the "userAToken" account. +// User token A account. Token will be transfer from this account if it is add liquidity operation. Else, token will be transfer into this account. +func (inst *RemoveBalanceLiquidity) GetUserATokenAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetUserBTokenAccount sets the "userBToken" account. +// User token B account. Token will be transfer from this account if it is add liquidity operation. Else, token will be transfer into this account. +func (inst *RemoveBalanceLiquidity) SetUserBTokenAccount(userBToken ag_solanago.PublicKey) *RemoveBalanceLiquidity { + inst.AccountMetaSlice[12] = ag_solanago.Meta(userBToken).WRITE() + return inst +} + +// GetUserBTokenAccount gets the "userBToken" account. +// User token B account. Token will be transfer from this account if it is add liquidity operation. Else, token will be transfer into this account. +func (inst *RemoveBalanceLiquidity) GetUserBTokenAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetUserAccount sets the "user" account. +// User account. Must be owner of user_a_token, and user_b_token. +func (inst *RemoveBalanceLiquidity) SetUserAccount(user ag_solanago.PublicKey) *RemoveBalanceLiquidity { + inst.AccountMetaSlice[13] = ag_solanago.Meta(user).SIGNER() + return inst +} + +// GetUserAccount gets the "user" account. +// User account. Must be owner of user_a_token, and user_b_token. +func (inst *RemoveBalanceLiquidity) GetUserAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetVaultProgramAccount sets the "vaultProgram" account. +// Vault program. the pool will deposit/withdraw liquidity from the vault. +func (inst *RemoveBalanceLiquidity) SetVaultProgramAccount(vaultProgram ag_solanago.PublicKey) *RemoveBalanceLiquidity { + inst.AccountMetaSlice[14] = ag_solanago.Meta(vaultProgram) + return inst +} + +// GetVaultProgramAccount gets the "vaultProgram" account. +// Vault program. the pool will deposit/withdraw liquidity from the vault. +func (inst *RemoveBalanceLiquidity) GetVaultProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +// Token program. +func (inst *RemoveBalanceLiquidity) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *RemoveBalanceLiquidity { + inst.AccountMetaSlice[15] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +// Token program. +func (inst *RemoveBalanceLiquidity) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(15) +} + +func (inst RemoveBalanceLiquidity) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_RemoveBalanceLiquidity, + }} +} + +// 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 RemoveBalanceLiquidity) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *RemoveBalanceLiquidity) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.PoolTokenAmount == nil { + return errors.New("PoolTokenAmount parameter is not set") + } + if inst.MinimumATokenOut == nil { + return errors.New("MinimumATokenOut parameter is not set") + } + if inst.MinimumBTokenOut == nil { + return errors.New("MinimumBTokenOut parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Pool is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.LpMint is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.UserPoolLp is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.AVaultLp is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.BVaultLp is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.AVault is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.BVault is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.AVaultLpMint is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.BVaultLpMint is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.ATokenVault is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.BTokenVault is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.UserAToken is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.UserBToken is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.User is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.VaultProgram is not set") + } + if inst.AccountMetaSlice[15] == nil { + return errors.New("accounts.TokenProgram is not set") + } + } + return nil +} + +func (inst *RemoveBalanceLiquidity) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("RemoveBalanceLiquidity")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=3]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" PoolTokenAmount", *inst.PoolTokenAmount)) + paramsBranch.Child(ag_format.Param("MinimumATokenOut", *inst.MinimumATokenOut)) + paramsBranch.Child(ag_format.Param("MinimumBTokenOut", *inst.MinimumBTokenOut)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=16]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" pool", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" lpMint", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" userPoolLp", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" aVaultLp", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" bVaultLp", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" aVault", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" bVault", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta("aVaultLpMint", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta("bVaultLpMint", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" aTokenVault", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" bTokenVault", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" userAToken", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" userBToken", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" user", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta("vaultProgram", inst.AccountMetaSlice.Get(14))) + accountsBranch.Child(ag_format.Meta("tokenProgram", inst.AccountMetaSlice.Get(15))) + }) + }) + }) +} + +func (obj RemoveBalanceLiquidity) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `PoolTokenAmount` param: + err = encoder.Encode(obj.PoolTokenAmount) + if err != nil { + return err + } + // Serialize `MinimumATokenOut` param: + err = encoder.Encode(obj.MinimumATokenOut) + if err != nil { + return err + } + // Serialize `MinimumBTokenOut` param: + err = encoder.Encode(obj.MinimumBTokenOut) + if err != nil { + return err + } + return nil +} +func (obj *RemoveBalanceLiquidity) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `PoolTokenAmount`: + err = decoder.Decode(&obj.PoolTokenAmount) + if err != nil { + return err + } + // Deserialize `MinimumATokenOut`: + err = decoder.Decode(&obj.MinimumATokenOut) + if err != nil { + return err + } + // Deserialize `MinimumBTokenOut`: + err = decoder.Decode(&obj.MinimumBTokenOut) + if err != nil { + return err + } + return nil +} + +// NewRemoveBalanceLiquidityInstruction declares a new RemoveBalanceLiquidity instruction with the provided parameters and accounts. +func NewRemoveBalanceLiquidityInstruction( + // Parameters: + poolTokenAmount uint64, + minimumATokenOut uint64, + minimumBTokenOut uint64, + // Accounts: + pool ag_solanago.PublicKey, + lpMint ag_solanago.PublicKey, + userPoolLp ag_solanago.PublicKey, + aVaultLp ag_solanago.PublicKey, + bVaultLp ag_solanago.PublicKey, + aVault ag_solanago.PublicKey, + bVault ag_solanago.PublicKey, + aVaultLpMint ag_solanago.PublicKey, + bVaultLpMint ag_solanago.PublicKey, + aTokenVault ag_solanago.PublicKey, + bTokenVault ag_solanago.PublicKey, + userAToken ag_solanago.PublicKey, + userBToken ag_solanago.PublicKey, + user ag_solanago.PublicKey, + vaultProgram ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey) *RemoveBalanceLiquidity { + return NewRemoveBalanceLiquidityInstructionBuilder(). + SetPoolTokenAmount(poolTokenAmount). + SetMinimumATokenOut(minimumATokenOut). + SetMinimumBTokenOut(minimumBTokenOut). + SetPoolAccount(pool). + SetLpMintAccount(lpMint). + SetUserPoolLpAccount(userPoolLp). + SetAVaultLpAccount(aVaultLp). + SetBVaultLpAccount(bVaultLp). + SetAVaultAccount(aVault). + SetBVaultAccount(bVault). + SetAVaultLpMintAccount(aVaultLpMint). + SetBVaultLpMintAccount(bVaultLpMint). + SetATokenVaultAccount(aTokenVault). + SetBTokenVaultAccount(bTokenVault). + SetUserATokenAccount(userAToken). + SetUserBTokenAccount(userBToken). + SetUserAccount(user). + SetVaultProgramAccount(vaultProgram). + SetTokenProgramAccount(tokenProgram) +} diff --git a/programs/meteorapools/RemoveBalanceLiquidity_test.go b/programs/meteorapools/RemoveBalanceLiquidity_test.go new file mode 100644 index 00000000..ccd30c35 --- /dev/null +++ b/programs/meteorapools/RemoveBalanceLiquidity_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_RemoveBalanceLiquidity(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("RemoveBalanceLiquidity"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(RemoveBalanceLiquidity) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(RemoveBalanceLiquidity) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteorapools/RemoveLiquiditySingleSide.go b/programs/meteorapools/RemoveLiquiditySingleSide.go new file mode 100644 index 00000000..263b2ec9 --- /dev/null +++ b/programs/meteorapools/RemoveLiquiditySingleSide.go @@ -0,0 +1,461 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "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" +) + +// Withdraw only single token from the pool. Only supported by pool with stable swap curve. +type RemoveLiquiditySingleSide struct { + PoolTokenAmount *uint64 + MinimumOutAmount *uint64 + + // [0] = [WRITE] pool + // ··········· Pool account (PDA) + // + // [1] = [WRITE] lpMint + // ··········· LP token mint of the pool + // + // [2] = [WRITE] userPoolLp + // ··········· User pool lp token account. LP will be burned from this account upon success liquidity removal. + // + // [3] = [WRITE] aVaultLp + // ··········· LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. + // + // [4] = [WRITE] bVaultLp + // ··········· LP token account of vault B. Used to receive/burn the vault LP upon deposit/withdraw from the vault. + // + // [5] = [WRITE] aVault + // ··········· Vault account for token A. Token A of the pool will be deposit / withdraw from this vault account. + // + // [6] = [WRITE] bVault + // ··········· Vault account for token B. Token B of the pool will be deposit / withdraw from this vault account. + // + // [7] = [WRITE] aVaultLpMint + // ··········· LP token mint of vault A + // + // [8] = [WRITE] bVaultLpMint + // ··········· LP token mint of vault B + // + // [9] = [WRITE] aTokenVault + // ··········· Token vault account of vault A + // + // [10] = [WRITE] bTokenVault + // ··········· Token vault account of vault B + // + // [11] = [WRITE] userDestinationToken + // ··········· User token account to receive token upon success liquidity removal. + // + // [12] = [SIGNER] user + // ··········· User account. Must be owner of the user_pool_lp account. + // + // [13] = [] vaultProgram + // ··········· Vault program. The pool will deposit/withdraw liquidity from the vault. + // + // [14] = [] tokenProgram + // ··········· Token program. + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewRemoveLiquiditySingleSideInstructionBuilder creates a new `RemoveLiquiditySingleSide` instruction builder. +func NewRemoveLiquiditySingleSideInstructionBuilder() *RemoveLiquiditySingleSide { + nd := &RemoveLiquiditySingleSide{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 15), + } + return nd +} + +// SetPoolTokenAmount sets the "poolTokenAmount" parameter. +func (inst *RemoveLiquiditySingleSide) SetPoolTokenAmount(poolTokenAmount uint64) *RemoveLiquiditySingleSide { + inst.PoolTokenAmount = &poolTokenAmount + return inst +} + +// SetMinimumOutAmount sets the "minimumOutAmount" parameter. +func (inst *RemoveLiquiditySingleSide) SetMinimumOutAmount(minimumOutAmount uint64) *RemoveLiquiditySingleSide { + inst.MinimumOutAmount = &minimumOutAmount + return inst +} + +// SetPoolAccount sets the "pool" account. +// Pool account (PDA) +func (inst *RemoveLiquiditySingleSide) SetPoolAccount(pool ag_solanago.PublicKey) *RemoveLiquiditySingleSide { + inst.AccountMetaSlice[0] = ag_solanago.Meta(pool).WRITE() + return inst +} + +// GetPoolAccount gets the "pool" account. +// Pool account (PDA) +func (inst *RemoveLiquiditySingleSide) GetPoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetLpMintAccount sets the "lpMint" account. +// LP token mint of the pool +func (inst *RemoveLiquiditySingleSide) SetLpMintAccount(lpMint ag_solanago.PublicKey) *RemoveLiquiditySingleSide { + inst.AccountMetaSlice[1] = ag_solanago.Meta(lpMint).WRITE() + return inst +} + +// GetLpMintAccount gets the "lpMint" account. +// LP token mint of the pool +func (inst *RemoveLiquiditySingleSide) GetLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetUserPoolLpAccount sets the "userPoolLp" account. +// User pool lp token account. LP will be burned from this account upon success liquidity removal. +func (inst *RemoveLiquiditySingleSide) SetUserPoolLpAccount(userPoolLp ag_solanago.PublicKey) *RemoveLiquiditySingleSide { + inst.AccountMetaSlice[2] = ag_solanago.Meta(userPoolLp).WRITE() + return inst +} + +// GetUserPoolLpAccount gets the "userPoolLp" account. +// User pool lp token account. LP will be burned from this account upon success liquidity removal. +func (inst *RemoveLiquiditySingleSide) GetUserPoolLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetAVaultLpAccount sets the "aVaultLp" account. +// LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *RemoveLiquiditySingleSide) SetAVaultLpAccount(aVaultLp ag_solanago.PublicKey) *RemoveLiquiditySingleSide { + inst.AccountMetaSlice[3] = ag_solanago.Meta(aVaultLp).WRITE() + return inst +} + +// GetAVaultLpAccount gets the "aVaultLp" account. +// LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *RemoveLiquiditySingleSide) GetAVaultLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetBVaultLpAccount sets the "bVaultLp" account. +// LP token account of vault B. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *RemoveLiquiditySingleSide) SetBVaultLpAccount(bVaultLp ag_solanago.PublicKey) *RemoveLiquiditySingleSide { + inst.AccountMetaSlice[4] = ag_solanago.Meta(bVaultLp).WRITE() + return inst +} + +// GetBVaultLpAccount gets the "bVaultLp" account. +// LP token account of vault B. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *RemoveLiquiditySingleSide) GetBVaultLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetAVaultAccount sets the "aVault" account. +// Vault account for token A. Token A of the pool will be deposit / withdraw from this vault account. +func (inst *RemoveLiquiditySingleSide) SetAVaultAccount(aVault ag_solanago.PublicKey) *RemoveLiquiditySingleSide { + inst.AccountMetaSlice[5] = ag_solanago.Meta(aVault).WRITE() + return inst +} + +// GetAVaultAccount gets the "aVault" account. +// Vault account for token A. Token A of the pool will be deposit / withdraw from this vault account. +func (inst *RemoveLiquiditySingleSide) GetAVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetBVaultAccount sets the "bVault" account. +// Vault account for token B. Token B of the pool will be deposit / withdraw from this vault account. +func (inst *RemoveLiquiditySingleSide) SetBVaultAccount(bVault ag_solanago.PublicKey) *RemoveLiquiditySingleSide { + inst.AccountMetaSlice[6] = ag_solanago.Meta(bVault).WRITE() + return inst +} + +// GetBVaultAccount gets the "bVault" account. +// Vault account for token B. Token B of the pool will be deposit / withdraw from this vault account. +func (inst *RemoveLiquiditySingleSide) GetBVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetAVaultLpMintAccount sets the "aVaultLpMint" account. +// LP token mint of vault A +func (inst *RemoveLiquiditySingleSide) SetAVaultLpMintAccount(aVaultLpMint ag_solanago.PublicKey) *RemoveLiquiditySingleSide { + inst.AccountMetaSlice[7] = ag_solanago.Meta(aVaultLpMint).WRITE() + return inst +} + +// GetAVaultLpMintAccount gets the "aVaultLpMint" account. +// LP token mint of vault A +func (inst *RemoveLiquiditySingleSide) GetAVaultLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetBVaultLpMintAccount sets the "bVaultLpMint" account. +// LP token mint of vault B +func (inst *RemoveLiquiditySingleSide) SetBVaultLpMintAccount(bVaultLpMint ag_solanago.PublicKey) *RemoveLiquiditySingleSide { + inst.AccountMetaSlice[8] = ag_solanago.Meta(bVaultLpMint).WRITE() + return inst +} + +// GetBVaultLpMintAccount gets the "bVaultLpMint" account. +// LP token mint of vault B +func (inst *RemoveLiquiditySingleSide) GetBVaultLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetATokenVaultAccount sets the "aTokenVault" account. +// Token vault account of vault A +func (inst *RemoveLiquiditySingleSide) SetATokenVaultAccount(aTokenVault ag_solanago.PublicKey) *RemoveLiquiditySingleSide { + inst.AccountMetaSlice[9] = ag_solanago.Meta(aTokenVault).WRITE() + return inst +} + +// GetATokenVaultAccount gets the "aTokenVault" account. +// Token vault account of vault A +func (inst *RemoveLiquiditySingleSide) GetATokenVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetBTokenVaultAccount sets the "bTokenVault" account. +// Token vault account of vault B +func (inst *RemoveLiquiditySingleSide) SetBTokenVaultAccount(bTokenVault ag_solanago.PublicKey) *RemoveLiquiditySingleSide { + inst.AccountMetaSlice[10] = ag_solanago.Meta(bTokenVault).WRITE() + return inst +} + +// GetBTokenVaultAccount gets the "bTokenVault" account. +// Token vault account of vault B +func (inst *RemoveLiquiditySingleSide) GetBTokenVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetUserDestinationTokenAccount sets the "userDestinationToken" account. +// User token account to receive token upon success liquidity removal. +func (inst *RemoveLiquiditySingleSide) SetUserDestinationTokenAccount(userDestinationToken ag_solanago.PublicKey) *RemoveLiquiditySingleSide { + inst.AccountMetaSlice[11] = ag_solanago.Meta(userDestinationToken).WRITE() + return inst +} + +// GetUserDestinationTokenAccount gets the "userDestinationToken" account. +// User token account to receive token upon success liquidity removal. +func (inst *RemoveLiquiditySingleSide) GetUserDestinationTokenAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetUserAccount sets the "user" account. +// User account. Must be owner of the user_pool_lp account. +func (inst *RemoveLiquiditySingleSide) SetUserAccount(user ag_solanago.PublicKey) *RemoveLiquiditySingleSide { + inst.AccountMetaSlice[12] = ag_solanago.Meta(user).SIGNER() + return inst +} + +// GetUserAccount gets the "user" account. +// User account. Must be owner of the user_pool_lp account. +func (inst *RemoveLiquiditySingleSide) GetUserAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetVaultProgramAccount sets the "vaultProgram" account. +// Vault program. The pool will deposit/withdraw liquidity from the vault. +func (inst *RemoveLiquiditySingleSide) SetVaultProgramAccount(vaultProgram ag_solanago.PublicKey) *RemoveLiquiditySingleSide { + inst.AccountMetaSlice[13] = ag_solanago.Meta(vaultProgram) + return inst +} + +// GetVaultProgramAccount gets the "vaultProgram" account. +// Vault program. The pool will deposit/withdraw liquidity from the vault. +func (inst *RemoveLiquiditySingleSide) GetVaultProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +// Token program. +func (inst *RemoveLiquiditySingleSide) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *RemoveLiquiditySingleSide { + inst.AccountMetaSlice[14] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +// Token program. +func (inst *RemoveLiquiditySingleSide) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +func (inst RemoveLiquiditySingleSide) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_RemoveLiquiditySingleSide, + }} +} + +// 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 RemoveLiquiditySingleSide) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *RemoveLiquiditySingleSide) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.PoolTokenAmount == nil { + return errors.New("PoolTokenAmount parameter is not set") + } + if inst.MinimumOutAmount == nil { + return errors.New("MinimumOutAmount parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Pool is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.LpMint is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.UserPoolLp is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.AVaultLp is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.BVaultLp is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.AVault is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.BVault is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.AVaultLpMint is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.BVaultLpMint is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.ATokenVault is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.BTokenVault is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.UserDestinationToken is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.User is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.VaultProgram is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.TokenProgram is not set") + } + } + return nil +} + +func (inst *RemoveLiquiditySingleSide) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("RemoveLiquiditySingleSide")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=2]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" PoolTokenAmount", *inst.PoolTokenAmount)) + paramsBranch.Child(ag_format.Param("MinimumOutAmount", *inst.MinimumOutAmount)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=15]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" pool", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" lpMint", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta(" userPoolLp", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" aVaultLp", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" bVaultLp", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" aVault", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" bVault", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" aVaultLpMint", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" bVaultLpMint", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" aTokenVault", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" bTokenVault", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta("userDestinationToken", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" user", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" vaultProgram", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(14))) + }) + }) + }) +} + +func (obj RemoveLiquiditySingleSide) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `PoolTokenAmount` param: + err = encoder.Encode(obj.PoolTokenAmount) + if err != nil { + return err + } + // Serialize `MinimumOutAmount` param: + err = encoder.Encode(obj.MinimumOutAmount) + if err != nil { + return err + } + return nil +} +func (obj *RemoveLiquiditySingleSide) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `PoolTokenAmount`: + err = decoder.Decode(&obj.PoolTokenAmount) + if err != nil { + return err + } + // Deserialize `MinimumOutAmount`: + err = decoder.Decode(&obj.MinimumOutAmount) + if err != nil { + return err + } + return nil +} + +// NewRemoveLiquiditySingleSideInstruction declares a new RemoveLiquiditySingleSide instruction with the provided parameters and accounts. +func NewRemoveLiquiditySingleSideInstruction( + // Parameters: + poolTokenAmount uint64, + minimumOutAmount uint64, + // Accounts: + pool ag_solanago.PublicKey, + lpMint ag_solanago.PublicKey, + userPoolLp ag_solanago.PublicKey, + aVaultLp ag_solanago.PublicKey, + bVaultLp ag_solanago.PublicKey, + aVault ag_solanago.PublicKey, + bVault ag_solanago.PublicKey, + aVaultLpMint ag_solanago.PublicKey, + bVaultLpMint ag_solanago.PublicKey, + aTokenVault ag_solanago.PublicKey, + bTokenVault ag_solanago.PublicKey, + userDestinationToken ag_solanago.PublicKey, + user ag_solanago.PublicKey, + vaultProgram ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey) *RemoveLiquiditySingleSide { + return NewRemoveLiquiditySingleSideInstructionBuilder(). + SetPoolTokenAmount(poolTokenAmount). + SetMinimumOutAmount(minimumOutAmount). + SetPoolAccount(pool). + SetLpMintAccount(lpMint). + SetUserPoolLpAccount(userPoolLp). + SetAVaultLpAccount(aVaultLp). + SetBVaultLpAccount(bVaultLp). + SetAVaultAccount(aVault). + SetBVaultAccount(bVault). + SetAVaultLpMintAccount(aVaultLpMint). + SetBVaultLpMintAccount(bVaultLpMint). + SetATokenVaultAccount(aTokenVault). + SetBTokenVaultAccount(bTokenVault). + SetUserDestinationTokenAccount(userDestinationToken). + SetUserAccount(user). + SetVaultProgramAccount(vaultProgram). + SetTokenProgramAccount(tokenProgram) +} diff --git a/programs/meteorapools/RemoveLiquiditySingleSide_test.go b/programs/meteorapools/RemoveLiquiditySingleSide_test.go new file mode 100644 index 00000000..a36c327d --- /dev/null +++ b/programs/meteorapools/RemoveLiquiditySingleSide_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_RemoveLiquiditySingleSide(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("RemoveLiquiditySingleSide"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(RemoveLiquiditySingleSide) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(RemoveLiquiditySingleSide) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteorapools/SetPoolFees.go b/programs/meteorapools/SetPoolFees.go new file mode 100644 index 00000000..8358ee17 --- /dev/null +++ b/programs/meteorapools/SetPoolFees.go @@ -0,0 +1,175 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "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" +) + +// Update trading fee charged for liquidity provider, and admin. +type SetPoolFees struct { + Fees *PoolFees + NewPartnerFeeNumerator *uint64 + + // [0] = [WRITE] pool + // ··········· Pool account (PDA) + // + // [1] = [SIGNER] feeOperator + // ··········· Fee operator account + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewSetPoolFeesInstructionBuilder creates a new `SetPoolFees` instruction builder. +func NewSetPoolFeesInstructionBuilder() *SetPoolFees { + nd := &SetPoolFees{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 2), + } + return nd +} + +// SetFees sets the "fees" parameter. +func (inst *SetPoolFees) SetFees(fees PoolFees) *SetPoolFees { + inst.Fees = &fees + return inst +} + +// SetNewPartnerFeeNumerator sets the "newPartnerFeeNumerator" parameter. +func (inst *SetPoolFees) SetNewPartnerFeeNumerator(newPartnerFeeNumerator uint64) *SetPoolFees { + inst.NewPartnerFeeNumerator = &newPartnerFeeNumerator + return inst +} + +// SetPoolAccount sets the "pool" account. +// Pool account (PDA) +func (inst *SetPoolFees) SetPoolAccount(pool ag_solanago.PublicKey) *SetPoolFees { + inst.AccountMetaSlice[0] = ag_solanago.Meta(pool).WRITE() + return inst +} + +// GetPoolAccount gets the "pool" account. +// Pool account (PDA) +func (inst *SetPoolFees) GetPoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetFeeOperatorAccount sets the "feeOperator" account. +// Fee operator account +func (inst *SetPoolFees) SetFeeOperatorAccount(feeOperator ag_solanago.PublicKey) *SetPoolFees { + inst.AccountMetaSlice[1] = ag_solanago.Meta(feeOperator).SIGNER() + return inst +} + +// GetFeeOperatorAccount gets the "feeOperator" account. +// Fee operator account +func (inst *SetPoolFees) GetFeeOperatorAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +func (inst SetPoolFees) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_SetPoolFees, + }} +} + +// 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 SetPoolFees) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *SetPoolFees) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.Fees == nil { + return errors.New("Fees parameter is not set") + } + if inst.NewPartnerFeeNumerator == nil { + return errors.New("NewPartnerFeeNumerator parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Pool is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.FeeOperator is not set") + } + } + return nil +} + +func (inst *SetPoolFees) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("SetPoolFees")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=2]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" Fees", *inst.Fees)) + paramsBranch.Child(ag_format.Param("NewPartnerFeeNumerator", *inst.NewPartnerFeeNumerator)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=2]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" pool", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta("feeOperator", inst.AccountMetaSlice.Get(1))) + }) + }) + }) +} + +func (obj SetPoolFees) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Fees` param: + err = encoder.Encode(obj.Fees) + if err != nil { + return err + } + // Serialize `NewPartnerFeeNumerator` param: + err = encoder.Encode(obj.NewPartnerFeeNumerator) + if err != nil { + return err + } + return nil +} +func (obj *SetPoolFees) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Fees`: + err = decoder.Decode(&obj.Fees) + if err != nil { + return err + } + // Deserialize `NewPartnerFeeNumerator`: + err = decoder.Decode(&obj.NewPartnerFeeNumerator) + if err != nil { + return err + } + return nil +} + +// NewSetPoolFeesInstruction declares a new SetPoolFees instruction with the provided parameters and accounts. +func NewSetPoolFeesInstruction( + // Parameters: + fees PoolFees, + newPartnerFeeNumerator uint64, + // Accounts: + pool ag_solanago.PublicKey, + feeOperator ag_solanago.PublicKey) *SetPoolFees { + return NewSetPoolFeesInstructionBuilder(). + SetFees(fees). + SetNewPartnerFeeNumerator(newPartnerFeeNumerator). + SetPoolAccount(pool). + SetFeeOperatorAccount(feeOperator) +} diff --git a/programs/meteorapools/SetPoolFees_test.go b/programs/meteorapools/SetPoolFees_test.go new file mode 100644 index 00000000..5ade1859 --- /dev/null +++ b/programs/meteorapools/SetPoolFees_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_SetPoolFees(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("SetPoolFees"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(SetPoolFees) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(SetPoolFees) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteorapools/SetWhitelistedVault.go b/programs/meteorapools/SetWhitelistedVault.go new file mode 100644 index 00000000..f4b9b44d --- /dev/null +++ b/programs/meteorapools/SetWhitelistedVault.go @@ -0,0 +1,146 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "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" +) + +// Set whitelisted vault +type SetWhitelistedVault struct { + WhitelistedVault *ag_solanago.PublicKey + + // [0] = [WRITE] pool + // + // [1] = [SIGNER] admin + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewSetWhitelistedVaultInstructionBuilder creates a new `SetWhitelistedVault` instruction builder. +func NewSetWhitelistedVaultInstructionBuilder() *SetWhitelistedVault { + nd := &SetWhitelistedVault{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 2), + } + return nd +} + +// SetWhitelistedVault sets the "whitelistedVault" parameter. +func (inst *SetWhitelistedVault) SetWhitelistedVault(whitelistedVault ag_solanago.PublicKey) *SetWhitelistedVault { + inst.WhitelistedVault = &whitelistedVault + return inst +} + +// SetPoolAccount sets the "pool" account. +func (inst *SetWhitelistedVault) SetPoolAccount(pool ag_solanago.PublicKey) *SetWhitelistedVault { + inst.AccountMetaSlice[0] = ag_solanago.Meta(pool).WRITE() + return inst +} + +// GetPoolAccount gets the "pool" account. +func (inst *SetWhitelistedVault) GetPoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetAdminAccount sets the "admin" account. +func (inst *SetWhitelistedVault) SetAdminAccount(admin ag_solanago.PublicKey) *SetWhitelistedVault { + inst.AccountMetaSlice[1] = ag_solanago.Meta(admin).SIGNER() + return inst +} + +// GetAdminAccount gets the "admin" account. +func (inst *SetWhitelistedVault) GetAdminAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +func (inst SetWhitelistedVault) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_SetWhitelistedVault, + }} +} + +// 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 SetWhitelistedVault) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *SetWhitelistedVault) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.WhitelistedVault == nil { + return errors.New("WhitelistedVault parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Pool is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Admin is not set") + } + } + return nil +} + +func (inst *SetWhitelistedVault) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("SetWhitelistedVault")). + // + 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("WhitelistedVault", *inst.WhitelistedVault)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=2]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" pool", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta("admin", inst.AccountMetaSlice.Get(1))) + }) + }) + }) +} + +func (obj SetWhitelistedVault) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `WhitelistedVault` param: + err = encoder.Encode(obj.WhitelistedVault) + if err != nil { + return err + } + return nil +} +func (obj *SetWhitelistedVault) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `WhitelistedVault`: + err = decoder.Decode(&obj.WhitelistedVault) + if err != nil { + return err + } + return nil +} + +// NewSetWhitelistedVaultInstruction declares a new SetWhitelistedVault instruction with the provided parameters and accounts. +func NewSetWhitelistedVaultInstruction( + // Parameters: + whitelistedVault ag_solanago.PublicKey, + // Accounts: + pool ag_solanago.PublicKey, + admin ag_solanago.PublicKey) *SetWhitelistedVault { + return NewSetWhitelistedVaultInstructionBuilder(). + SetWhitelistedVault(whitelistedVault). + SetPoolAccount(pool). + SetAdminAccount(admin) +} diff --git a/programs/meteorapools/SetWhitelistedVault_test.go b/programs/meteorapools/SetWhitelistedVault_test.go new file mode 100644 index 00000000..461702e2 --- /dev/null +++ b/programs/meteorapools/SetWhitelistedVault_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_SetWhitelistedVault(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("SetWhitelistedVault"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(SetWhitelistedVault) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(SetWhitelistedVault) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteorapools/Swap.go b/programs/meteorapools/Swap.go new file mode 100644 index 00000000..7592f973 --- /dev/null +++ b/programs/meteorapools/Swap.go @@ -0,0 +1,461 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "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" +) + +// Swap token A to B, or vice versa. An amount of trading fee will be charged for liquidity provider, and the admin of the pool. +type Swap struct { + InAmount *uint64 + MinimumOutAmount *uint64 + + // [0] = [WRITE] pool + // ··········· Pool account (PDA) + // + // [1] = [WRITE] userSourceToken + // ··········· User token account. Token from this account will be transfer into the vault by the pool in exchange for another token of the pool. + // + // [2] = [WRITE] userDestinationToken + // ··········· User token account. The exchanged token will be transfer into this account from the pool. + // + // [3] = [WRITE] aVault + // ··········· Vault account for token a. token a of the pool will be deposit / withdraw from this vault account. + // + // [4] = [WRITE] bVault + // ··········· Vault account for token b. token b of the pool will be deposit / withdraw from this vault account. + // + // [5] = [WRITE] aTokenVault + // ··········· Token vault account of vault A + // + // [6] = [WRITE] bTokenVault + // ··········· Token vault account of vault B + // + // [7] = [WRITE] aVaultLpMint + // ··········· Lp token mint of vault a + // + // [8] = [WRITE] bVaultLpMint + // ··········· Lp token mint of vault b + // + // [9] = [WRITE] aVaultLp + // ··········· LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. + // + // [10] = [WRITE] bVaultLp + // ··········· LP token account of vault B. Used to receive/burn the vault LP upon deposit/withdraw from the vault. + // + // [11] = [WRITE] protocolTokenFee + // ··········· Protocol fee token account. Used to receive trading fee. It's mint field must matched with user_source_token mint field. + // + // [12] = [SIGNER] user + // ··········· User account. Must be owner of user_source_token. + // + // [13] = [] vaultProgram + // ··········· Vault program. the pool will deposit/withdraw liquidity from the vault. + // + // [14] = [] tokenProgram + // ··········· Token program. + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewSwapInstructionBuilder creates a new `Swap` instruction builder. +func NewSwapInstructionBuilder() *Swap { + nd := &Swap{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 15), + } + return nd +} + +// SetInAmount sets the "inAmount" parameter. +func (inst *Swap) SetInAmount(inAmount uint64) *Swap { + inst.InAmount = &inAmount + return inst +} + +// SetMinimumOutAmount sets the "minimumOutAmount" parameter. +func (inst *Swap) SetMinimumOutAmount(minimumOutAmount uint64) *Swap { + inst.MinimumOutAmount = &minimumOutAmount + return inst +} + +// SetPoolAccount sets the "pool" account. +// Pool account (PDA) +func (inst *Swap) SetPoolAccount(pool ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[0] = ag_solanago.Meta(pool).WRITE() + return inst +} + +// GetPoolAccount gets the "pool" account. +// Pool account (PDA) +func (inst *Swap) GetPoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetUserSourceTokenAccount sets the "userSourceToken" account. +// User token account. Token from this account will be transfer into the vault by the pool in exchange for another token of the pool. +func (inst *Swap) SetUserSourceTokenAccount(userSourceToken ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[1] = ag_solanago.Meta(userSourceToken).WRITE() + return inst +} + +// GetUserSourceTokenAccount gets the "userSourceToken" account. +// User token account. Token from this account will be transfer into the vault by the pool in exchange for another token of the pool. +func (inst *Swap) GetUserSourceTokenAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetUserDestinationTokenAccount sets the "userDestinationToken" account. +// User token account. The exchanged token will be transfer into this account from the pool. +func (inst *Swap) SetUserDestinationTokenAccount(userDestinationToken ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[2] = ag_solanago.Meta(userDestinationToken).WRITE() + return inst +} + +// GetUserDestinationTokenAccount gets the "userDestinationToken" account. +// User token account. The exchanged token will be transfer into this account from the pool. +func (inst *Swap) GetUserDestinationTokenAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetAVaultAccount sets the "aVault" account. +// Vault account for token a. token a of the pool will be deposit / withdraw from this vault account. +func (inst *Swap) SetAVaultAccount(aVault ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[3] = ag_solanago.Meta(aVault).WRITE() + return inst +} + +// GetAVaultAccount gets the "aVault" account. +// Vault account for token a. token a of the pool will be deposit / withdraw from this vault account. +func (inst *Swap) GetAVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetBVaultAccount sets the "bVault" account. +// Vault account for token b. token b of the pool will be deposit / withdraw from this vault account. +func (inst *Swap) SetBVaultAccount(bVault ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[4] = ag_solanago.Meta(bVault).WRITE() + return inst +} + +// GetBVaultAccount gets the "bVault" account. +// Vault account for token b. token b of the pool will be deposit / withdraw from this vault account. +func (inst *Swap) GetBVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetATokenVaultAccount sets the "aTokenVault" account. +// Token vault account of vault A +func (inst *Swap) SetATokenVaultAccount(aTokenVault ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[5] = ag_solanago.Meta(aTokenVault).WRITE() + return inst +} + +// GetATokenVaultAccount gets the "aTokenVault" account. +// Token vault account of vault A +func (inst *Swap) GetATokenVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetBTokenVaultAccount sets the "bTokenVault" account. +// Token vault account of vault B +func (inst *Swap) SetBTokenVaultAccount(bTokenVault ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[6] = ag_solanago.Meta(bTokenVault).WRITE() + return inst +} + +// GetBTokenVaultAccount gets the "bTokenVault" account. +// Token vault account of vault B +func (inst *Swap) GetBTokenVaultAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +// SetAVaultLpMintAccount sets the "aVaultLpMint" account. +// Lp token mint of vault a +func (inst *Swap) SetAVaultLpMintAccount(aVaultLpMint ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[7] = ag_solanago.Meta(aVaultLpMint).WRITE() + return inst +} + +// GetAVaultLpMintAccount gets the "aVaultLpMint" account. +// Lp token mint of vault a +func (inst *Swap) GetAVaultLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(7) +} + +// SetBVaultLpMintAccount sets the "bVaultLpMint" account. +// Lp token mint of vault b +func (inst *Swap) SetBVaultLpMintAccount(bVaultLpMint ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[8] = ag_solanago.Meta(bVaultLpMint).WRITE() + return inst +} + +// GetBVaultLpMintAccount gets the "bVaultLpMint" account. +// Lp token mint of vault b +func (inst *Swap) GetBVaultLpMintAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(8) +} + +// SetAVaultLpAccount sets the "aVaultLp" account. +// LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *Swap) SetAVaultLpAccount(aVaultLp ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[9] = ag_solanago.Meta(aVaultLp).WRITE() + return inst +} + +// GetAVaultLpAccount gets the "aVaultLp" account. +// LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *Swap) GetAVaultLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(9) +} + +// SetBVaultLpAccount sets the "bVaultLp" account. +// LP token account of vault B. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *Swap) SetBVaultLpAccount(bVaultLp ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[10] = ag_solanago.Meta(bVaultLp).WRITE() + return inst +} + +// GetBVaultLpAccount gets the "bVaultLp" account. +// LP token account of vault B. Used to receive/burn the vault LP upon deposit/withdraw from the vault. +func (inst *Swap) GetBVaultLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(10) +} + +// SetProtocolTokenFeeAccount sets the "protocolTokenFee" account. +// Protocol fee token account. Used to receive trading fee. It's mint field must matched with user_source_token mint field. +func (inst *Swap) SetProtocolTokenFeeAccount(protocolTokenFee ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[11] = ag_solanago.Meta(protocolTokenFee).WRITE() + return inst +} + +// GetProtocolTokenFeeAccount gets the "protocolTokenFee" account. +// Protocol fee token account. Used to receive trading fee. It's mint field must matched with user_source_token mint field. +func (inst *Swap) GetProtocolTokenFeeAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(11) +} + +// SetUserAccount sets the "user" account. +// User account. Must be owner of user_source_token. +func (inst *Swap) SetUserAccount(user ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[12] = ag_solanago.Meta(user).SIGNER() + return inst +} + +// GetUserAccount gets the "user" account. +// User account. Must be owner of user_source_token. +func (inst *Swap) GetUserAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(12) +} + +// SetVaultProgramAccount sets the "vaultProgram" account. +// Vault program. the pool will deposit/withdraw liquidity from the vault. +func (inst *Swap) SetVaultProgramAccount(vaultProgram ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[13] = ag_solanago.Meta(vaultProgram) + return inst +} + +// GetVaultProgramAccount gets the "vaultProgram" account. +// Vault program. the pool will deposit/withdraw liquidity from the vault. +func (inst *Swap) GetVaultProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(13) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +// Token program. +func (inst *Swap) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *Swap { + inst.AccountMetaSlice[14] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +// Token program. +func (inst *Swap) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(14) +} + +func (inst Swap) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_Swap, + }} +} + +// 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 Swap) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *Swap) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.InAmount == nil { + return errors.New("InAmount parameter is not set") + } + if inst.MinimumOutAmount == nil { + return errors.New("MinimumOutAmount parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Pool is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.UserSourceToken is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.UserDestinationToken is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.AVault is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.BVault is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.ATokenVault is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.BTokenVault is not set") + } + if inst.AccountMetaSlice[7] == nil { + return errors.New("accounts.AVaultLpMint is not set") + } + if inst.AccountMetaSlice[8] == nil { + return errors.New("accounts.BVaultLpMint is not set") + } + if inst.AccountMetaSlice[9] == nil { + return errors.New("accounts.AVaultLp is not set") + } + if inst.AccountMetaSlice[10] == nil { + return errors.New("accounts.BVaultLp is not set") + } + if inst.AccountMetaSlice[11] == nil { + return errors.New("accounts.ProtocolTokenFee is not set") + } + if inst.AccountMetaSlice[12] == nil { + return errors.New("accounts.User is not set") + } + if inst.AccountMetaSlice[13] == nil { + return errors.New("accounts.VaultProgram is not set") + } + if inst.AccountMetaSlice[14] == nil { + return errors.New("accounts.TokenProgram is not set") + } + } + return nil +} + +func (inst *Swap) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("Swap")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=2]").ParentFunc(func(paramsBranch ag_treeout.Branches) { + paramsBranch.Child(ag_format.Param(" InAmount", *inst.InAmount)) + paramsBranch.Child(ag_format.Param("MinimumOutAmount", *inst.MinimumOutAmount)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=15]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" pool", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" userSourceToken", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta("userDestinationToken", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta(" aVault", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" bVault", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" aTokenVault", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" bTokenVault", inst.AccountMetaSlice.Get(6))) + accountsBranch.Child(ag_format.Meta(" aVaultLpMint", inst.AccountMetaSlice.Get(7))) + accountsBranch.Child(ag_format.Meta(" bVaultLpMint", inst.AccountMetaSlice.Get(8))) + accountsBranch.Child(ag_format.Meta(" aVaultLp", inst.AccountMetaSlice.Get(9))) + accountsBranch.Child(ag_format.Meta(" bVaultLp", inst.AccountMetaSlice.Get(10))) + accountsBranch.Child(ag_format.Meta(" protocolTokenFee", inst.AccountMetaSlice.Get(11))) + accountsBranch.Child(ag_format.Meta(" user", inst.AccountMetaSlice.Get(12))) + accountsBranch.Child(ag_format.Meta(" vaultProgram", inst.AccountMetaSlice.Get(13))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(14))) + }) + }) + }) +} + +func (obj Swap) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `InAmount` param: + err = encoder.Encode(obj.InAmount) + if err != nil { + return err + } + // Serialize `MinimumOutAmount` param: + err = encoder.Encode(obj.MinimumOutAmount) + if err != nil { + return err + } + return nil +} +func (obj *Swap) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `InAmount`: + err = decoder.Decode(&obj.InAmount) + if err != nil { + return err + } + // Deserialize `MinimumOutAmount`: + err = decoder.Decode(&obj.MinimumOutAmount) + if err != nil { + return err + } + return nil +} + +// NewSwapInstruction declares a new Swap instruction with the provided parameters and accounts. +func NewSwapInstruction( + // Parameters: + inAmount uint64, + minimumOutAmount uint64, + // Accounts: + pool ag_solanago.PublicKey, + userSourceToken ag_solanago.PublicKey, + userDestinationToken ag_solanago.PublicKey, + aVault ag_solanago.PublicKey, + bVault ag_solanago.PublicKey, + aTokenVault ag_solanago.PublicKey, + bTokenVault ag_solanago.PublicKey, + aVaultLpMint ag_solanago.PublicKey, + bVaultLpMint ag_solanago.PublicKey, + aVaultLp ag_solanago.PublicKey, + bVaultLp ag_solanago.PublicKey, + protocolTokenFee ag_solanago.PublicKey, + user ag_solanago.PublicKey, + vaultProgram ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey) *Swap { + return NewSwapInstructionBuilder(). + SetInAmount(inAmount). + SetMinimumOutAmount(minimumOutAmount). + SetPoolAccount(pool). + SetUserSourceTokenAccount(userSourceToken). + SetUserDestinationTokenAccount(userDestinationToken). + SetAVaultAccount(aVault). + SetBVaultAccount(bVault). + SetATokenVaultAccount(aTokenVault). + SetBTokenVaultAccount(bTokenVault). + SetAVaultLpMintAccount(aVaultLpMint). + SetBVaultLpMintAccount(bVaultLpMint). + SetAVaultLpAccount(aVaultLp). + SetBVaultLpAccount(bVaultLp). + SetProtocolTokenFeeAccount(protocolTokenFee). + SetUserAccount(user). + SetVaultProgramAccount(vaultProgram). + SetTokenProgramAccount(tokenProgram) +} diff --git a/programs/meteorapools/Swap_test.go b/programs/meteorapools/Swap_test.go new file mode 100644 index 00000000..51b79b60 --- /dev/null +++ b/programs/meteorapools/Swap_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_Swap(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("Swap"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(Swap) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(Swap) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteorapools/UpdateActivationPoint.go b/programs/meteorapools/UpdateActivationPoint.go new file mode 100644 index 00000000..9a53b85b --- /dev/null +++ b/programs/meteorapools/UpdateActivationPoint.go @@ -0,0 +1,152 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "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" +) + +// Update activation slot +type UpdateActivationPoint struct { + NewActivationPoint *uint64 + + // [0] = [WRITE] pool + // ··········· Pool account (PDA) + // + // [1] = [SIGNER] admin + // ··········· Admin account. + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewUpdateActivationPointInstructionBuilder creates a new `UpdateActivationPoint` instruction builder. +func NewUpdateActivationPointInstructionBuilder() *UpdateActivationPoint { + nd := &UpdateActivationPoint{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 2), + } + return nd +} + +// SetNewActivationPoint sets the "newActivationPoint" parameter. +func (inst *UpdateActivationPoint) SetNewActivationPoint(newActivationPoint uint64) *UpdateActivationPoint { + inst.NewActivationPoint = &newActivationPoint + return inst +} + +// SetPoolAccount sets the "pool" account. +// Pool account (PDA) +func (inst *UpdateActivationPoint) SetPoolAccount(pool ag_solanago.PublicKey) *UpdateActivationPoint { + inst.AccountMetaSlice[0] = ag_solanago.Meta(pool).WRITE() + return inst +} + +// GetPoolAccount gets the "pool" account. +// Pool account (PDA) +func (inst *UpdateActivationPoint) GetPoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetAdminAccount sets the "admin" account. +// Admin account. +func (inst *UpdateActivationPoint) SetAdminAccount(admin ag_solanago.PublicKey) *UpdateActivationPoint { + inst.AccountMetaSlice[1] = ag_solanago.Meta(admin).SIGNER() + return inst +} + +// GetAdminAccount gets the "admin" account. +// Admin account. +func (inst *UpdateActivationPoint) GetAdminAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +func (inst UpdateActivationPoint) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_UpdateActivationPoint, + }} +} + +// 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 UpdateActivationPoint) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *UpdateActivationPoint) Validate() error { + // Check whether all (required) parameters are set: + { + if inst.NewActivationPoint == nil { + return errors.New("NewActivationPoint parameter is not set") + } + } + + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Pool is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.Admin is not set") + } + } + return nil +} + +func (inst *UpdateActivationPoint) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("UpdateActivationPoint")). + // + 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("NewActivationPoint", *inst.NewActivationPoint)) + }) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=2]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" pool", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta("admin", inst.AccountMetaSlice.Get(1))) + }) + }) + }) +} + +func (obj UpdateActivationPoint) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `NewActivationPoint` param: + err = encoder.Encode(obj.NewActivationPoint) + if err != nil { + return err + } + return nil +} +func (obj *UpdateActivationPoint) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `NewActivationPoint`: + err = decoder.Decode(&obj.NewActivationPoint) + if err != nil { + return err + } + return nil +} + +// NewUpdateActivationPointInstruction declares a new UpdateActivationPoint instruction with the provided parameters and accounts. +func NewUpdateActivationPointInstruction( + // Parameters: + newActivationPoint uint64, + // Accounts: + pool ag_solanago.PublicKey, + admin ag_solanago.PublicKey) *UpdateActivationPoint { + return NewUpdateActivationPointInstructionBuilder(). + SetNewActivationPoint(newActivationPoint). + SetPoolAccount(pool). + SetAdminAccount(admin) +} diff --git a/programs/meteorapools/UpdateActivationPoint_test.go b/programs/meteorapools/UpdateActivationPoint_test.go new file mode 100644 index 00000000..db95dd03 --- /dev/null +++ b/programs/meteorapools/UpdateActivationPoint_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_UpdateActivationPoint(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("UpdateActivationPoint"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(UpdateActivationPoint) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(UpdateActivationPoint) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteorapools/WithdrawProtocolFees.go b/programs/meteorapools/WithdrawProtocolFees.go new file mode 100644 index 00000000..0e6ee767 --- /dev/null +++ b/programs/meteorapools/WithdrawProtocolFees.go @@ -0,0 +1,215 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "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" +) + +// Withdraw protocol fee +type WithdrawProtocolFees struct { + + // [0] = [] pool + // ··········· Pool account (PDA) + // + // [1] = [] aVaultLp + // + // [2] = [WRITE] protocolTokenAFee + // + // [3] = [WRITE] protocolTokenBFee + // + // [4] = [WRITE] treasuryTokenA + // + // [5] = [WRITE] treasuryTokenB + // + // [6] = [] tokenProgram + ag_solanago.AccountMetaSlice `bin:"-"` +} + +// NewWithdrawProtocolFeesInstructionBuilder creates a new `WithdrawProtocolFees` instruction builder. +func NewWithdrawProtocolFeesInstructionBuilder() *WithdrawProtocolFees { + nd := &WithdrawProtocolFees{ + AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 7), + } + return nd +} + +// SetPoolAccount sets the "pool" account. +// Pool account (PDA) +func (inst *WithdrawProtocolFees) SetPoolAccount(pool ag_solanago.PublicKey) *WithdrawProtocolFees { + inst.AccountMetaSlice[0] = ag_solanago.Meta(pool) + return inst +} + +// GetPoolAccount gets the "pool" account. +// Pool account (PDA) +func (inst *WithdrawProtocolFees) GetPoolAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(0) +} + +// SetAVaultLpAccount sets the "aVaultLp" account. +func (inst *WithdrawProtocolFees) SetAVaultLpAccount(aVaultLp ag_solanago.PublicKey) *WithdrawProtocolFees { + inst.AccountMetaSlice[1] = ag_solanago.Meta(aVaultLp) + return inst +} + +// GetAVaultLpAccount gets the "aVaultLp" account. +func (inst *WithdrawProtocolFees) GetAVaultLpAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(1) +} + +// SetProtocolTokenAFeeAccount sets the "protocolTokenAFee" account. +func (inst *WithdrawProtocolFees) SetProtocolTokenAFeeAccount(protocolTokenAFee ag_solanago.PublicKey) *WithdrawProtocolFees { + inst.AccountMetaSlice[2] = ag_solanago.Meta(protocolTokenAFee).WRITE() + return inst +} + +// GetProtocolTokenAFeeAccount gets the "protocolTokenAFee" account. +func (inst *WithdrawProtocolFees) GetProtocolTokenAFeeAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(2) +} + +// SetProtocolTokenBFeeAccount sets the "protocolTokenBFee" account. +func (inst *WithdrawProtocolFees) SetProtocolTokenBFeeAccount(protocolTokenBFee ag_solanago.PublicKey) *WithdrawProtocolFees { + inst.AccountMetaSlice[3] = ag_solanago.Meta(protocolTokenBFee).WRITE() + return inst +} + +// GetProtocolTokenBFeeAccount gets the "protocolTokenBFee" account. +func (inst *WithdrawProtocolFees) GetProtocolTokenBFeeAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(3) +} + +// SetTreasuryTokenAAccount sets the "treasuryTokenA" account. +func (inst *WithdrawProtocolFees) SetTreasuryTokenAAccount(treasuryTokenA ag_solanago.PublicKey) *WithdrawProtocolFees { + inst.AccountMetaSlice[4] = ag_solanago.Meta(treasuryTokenA).WRITE() + return inst +} + +// GetTreasuryTokenAAccount gets the "treasuryTokenA" account. +func (inst *WithdrawProtocolFees) GetTreasuryTokenAAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(4) +} + +// SetTreasuryTokenBAccount sets the "treasuryTokenB" account. +func (inst *WithdrawProtocolFees) SetTreasuryTokenBAccount(treasuryTokenB ag_solanago.PublicKey) *WithdrawProtocolFees { + inst.AccountMetaSlice[5] = ag_solanago.Meta(treasuryTokenB).WRITE() + return inst +} + +// GetTreasuryTokenBAccount gets the "treasuryTokenB" account. +func (inst *WithdrawProtocolFees) GetTreasuryTokenBAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(5) +} + +// SetTokenProgramAccount sets the "tokenProgram" account. +func (inst *WithdrawProtocolFees) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *WithdrawProtocolFees { + inst.AccountMetaSlice[6] = ag_solanago.Meta(tokenProgram) + return inst +} + +// GetTokenProgramAccount gets the "tokenProgram" account. +func (inst *WithdrawProtocolFees) GetTokenProgramAccount() *ag_solanago.AccountMeta { + return inst.AccountMetaSlice.Get(6) +} + +func (inst WithdrawProtocolFees) Build() *Instruction { + return &Instruction{BaseVariant: ag_binary.BaseVariant{ + Impl: inst, + TypeID: Instruction_WithdrawProtocolFees, + }} +} + +// 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 WithdrawProtocolFees) ValidateAndBuild() (*Instruction, error) { + if err := inst.Validate(); err != nil { + return nil, err + } + return inst.Build(), nil +} + +func (inst *WithdrawProtocolFees) Validate() error { + // Check whether all (required) accounts are set: + { + if inst.AccountMetaSlice[0] == nil { + return errors.New("accounts.Pool is not set") + } + if inst.AccountMetaSlice[1] == nil { + return errors.New("accounts.AVaultLp is not set") + } + if inst.AccountMetaSlice[2] == nil { + return errors.New("accounts.ProtocolTokenAFee is not set") + } + if inst.AccountMetaSlice[3] == nil { + return errors.New("accounts.ProtocolTokenBFee is not set") + } + if inst.AccountMetaSlice[4] == nil { + return errors.New("accounts.TreasuryTokenA is not set") + } + if inst.AccountMetaSlice[5] == nil { + return errors.New("accounts.TreasuryTokenB is not set") + } + if inst.AccountMetaSlice[6] == nil { + return errors.New("accounts.TokenProgram is not set") + } + } + return nil +} + +func (inst *WithdrawProtocolFees) EncodeToTree(parent ag_treeout.Branches) { + parent.Child(ag_format.Program(ProgramName, ProgramID)). + // + ParentFunc(func(programBranch ag_treeout.Branches) { + programBranch.Child(ag_format.Instruction("WithdrawProtocolFees")). + // + ParentFunc(func(instructionBranch ag_treeout.Branches) { + + // Parameters of the instruction: + instructionBranch.Child("Params[len=0]").ParentFunc(func(paramsBranch ag_treeout.Branches) {}) + + // Accounts of the instruction: + instructionBranch.Child("Accounts[len=7]").ParentFunc(func(accountsBranch ag_treeout.Branches) { + accountsBranch.Child(ag_format.Meta(" pool", inst.AccountMetaSlice.Get(0))) + accountsBranch.Child(ag_format.Meta(" aVaultLp", inst.AccountMetaSlice.Get(1))) + accountsBranch.Child(ag_format.Meta("protocolTokenAFee", inst.AccountMetaSlice.Get(2))) + accountsBranch.Child(ag_format.Meta("protocolTokenBFee", inst.AccountMetaSlice.Get(3))) + accountsBranch.Child(ag_format.Meta(" treasuryTokenA", inst.AccountMetaSlice.Get(4))) + accountsBranch.Child(ag_format.Meta(" treasuryTokenB", inst.AccountMetaSlice.Get(5))) + accountsBranch.Child(ag_format.Meta(" tokenProgram", inst.AccountMetaSlice.Get(6))) + }) + }) + }) +} + +func (obj WithdrawProtocolFees) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} +func (obj *WithdrawProtocolFees) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +// NewWithdrawProtocolFeesInstruction declares a new WithdrawProtocolFees instruction with the provided parameters and accounts. +func NewWithdrawProtocolFeesInstruction( + // Accounts: + pool ag_solanago.PublicKey, + aVaultLp ag_solanago.PublicKey, + protocolTokenAFee ag_solanago.PublicKey, + protocolTokenBFee ag_solanago.PublicKey, + treasuryTokenA ag_solanago.PublicKey, + treasuryTokenB ag_solanago.PublicKey, + tokenProgram ag_solanago.PublicKey) *WithdrawProtocolFees { + return NewWithdrawProtocolFeesInstructionBuilder(). + SetPoolAccount(pool). + SetAVaultLpAccount(aVaultLp). + SetProtocolTokenAFeeAccount(protocolTokenAFee). + SetProtocolTokenBFeeAccount(protocolTokenBFee). + SetTreasuryTokenAAccount(treasuryTokenA). + SetTreasuryTokenBAccount(treasuryTokenB). + SetTokenProgramAccount(tokenProgram) +} diff --git a/programs/meteorapools/WithdrawProtocolFees_test.go b/programs/meteorapools/WithdrawProtocolFees_test.go new file mode 100644 index 00000000..ef000abc --- /dev/null +++ b/programs/meteorapools/WithdrawProtocolFees_test.go @@ -0,0 +1,32 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "bytes" + ag_gofuzz "github.com/gagliardetto/gofuzz" + ag_require "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func TestEncodeDecode_WithdrawProtocolFees(t *testing.T) { + fu := ag_gofuzz.New().NilChance(0) + for i := 0; i < 1; i++ { + t.Run("WithdrawProtocolFees"+strconv.Itoa(i), func(t *testing.T) { + { + params := new(WithdrawProtocolFees) + fu.Fuzz(params) + params.AccountMetaSlice = nil + buf := new(bytes.Buffer) + err := encodeT(*params, buf) + ag_require.NoError(t, err) + got := new(WithdrawProtocolFees) + err = decodeT(got, buf.Bytes()) + got.AccountMetaSlice = nil + ag_require.NoError(t, err) + ag_require.Equal(t, params, got) + } + }) + } +} diff --git a/programs/meteorapools/accounts.go b/programs/meteorapools/accounts.go new file mode 100644 index 00000000..b1d6230a --- /dev/null +++ b/programs/meteorapools/accounts.go @@ -0,0 +1,589 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "fmt" + ag_binary "github.com/gagliardetto/binary" + ag_solanago "github.com/gagliardetto/solana-go" +) + +type Config struct { + PoolFees PoolFees + ActivationDuration uint64 + VaultConfigKey ag_solanago.PublicKey + + // Only pool_creator_authority can use the current config to initialize new pool. When it's Pubkey::default, it's a public config. + PoolCreatorAuthority ag_solanago.PublicKey + + // Activation type + ActivationType uint8 + PartnerFeeNumerator uint64 + Padding [219]uint8 +} + +var ConfigDiscriminator = [8]byte{155, 12, 170, 224, 30, 250, 204, 130} + +func (obj Config) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Write account discriminator: + err = encoder.WriteBytes(ConfigDiscriminator[:], false) + if err != nil { + return err + } + // Serialize `PoolFees` param: + err = encoder.Encode(obj.PoolFees) + if err != nil { + return err + } + // Serialize `ActivationDuration` param: + err = encoder.Encode(obj.ActivationDuration) + if err != nil { + return err + } + // Serialize `VaultConfigKey` param: + err = encoder.Encode(obj.VaultConfigKey) + if err != nil { + return err + } + // Serialize `PoolCreatorAuthority` param: + err = encoder.Encode(obj.PoolCreatorAuthority) + if err != nil { + return err + } + // Serialize `ActivationType` param: + err = encoder.Encode(obj.ActivationType) + if err != nil { + return err + } + // Serialize `PartnerFeeNumerator` param: + err = encoder.Encode(obj.PartnerFeeNumerator) + if err != nil { + return err + } + // Serialize `Padding` param: + err = encoder.Encode(obj.Padding) + if err != nil { + return err + } + return nil +} + +func (obj *Config) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Read and check account discriminator: + { + discriminator, err := decoder.ReadTypeID() + if err != nil { + return err + } + if !discriminator.Equal(ConfigDiscriminator[:]) { + return fmt.Errorf( + "wrong discriminator: wanted %s, got %s", + "[155 12 170 224 30 250 204 130]", + fmt.Sprint(discriminator[:])) + } + } + // Deserialize `PoolFees`: + err = decoder.Decode(&obj.PoolFees) + if err != nil { + return err + } + // Deserialize `ActivationDuration`: + err = decoder.Decode(&obj.ActivationDuration) + if err != nil { + return err + } + // Deserialize `VaultConfigKey`: + err = decoder.Decode(&obj.VaultConfigKey) + if err != nil { + return err + } + // Deserialize `PoolCreatorAuthority`: + err = decoder.Decode(&obj.PoolCreatorAuthority) + if err != nil { + return err + } + // Deserialize `ActivationType`: + err = decoder.Decode(&obj.ActivationType) + if err != nil { + return err + } + // Deserialize `PartnerFeeNumerator`: + err = decoder.Decode(&obj.PartnerFeeNumerator) + if err != nil { + return err + } + // Deserialize `Padding`: + err = decoder.Decode(&obj.Padding) + if err != nil { + return err + } + return nil +} + +type LockEscrow struct { + // Pool address + Pool ag_solanago.PublicKey + + // Owner address + Owner ag_solanago.PublicKey + + // Vault address, store the lock user lock + EscrowVault ag_solanago.PublicKey + + // bump, used to sign + Bump uint8 + + // Total locked amount + TotalLockedAmount uint64 + + // Lp per token, virtual price of lp token + LpPerToken ag_binary.Uint128 + + // Unclaimed fee pending + UnclaimedFeePending uint64 + + // Total a fee claimed so far + AFee uint64 + + // Total b fee claimed so far + BFee uint64 +} + +var LockEscrowDiscriminator = [8]byte{190, 106, 121, 6, 200, 182, 21, 75} + +func (obj LockEscrow) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Write account discriminator: + err = encoder.WriteBytes(LockEscrowDiscriminator[:], false) + if err != nil { + return err + } + // Serialize `Pool` param: + err = encoder.Encode(obj.Pool) + if err != nil { + return err + } + // Serialize `Owner` param: + err = encoder.Encode(obj.Owner) + if err != nil { + return err + } + // Serialize `EscrowVault` param: + err = encoder.Encode(obj.EscrowVault) + if err != nil { + return err + } + // Serialize `Bump` param: + err = encoder.Encode(obj.Bump) + if err != nil { + return err + } + // Serialize `TotalLockedAmount` param: + err = encoder.Encode(obj.TotalLockedAmount) + if err != nil { + return err + } + // Serialize `LpPerToken` param: + err = encoder.Encode(obj.LpPerToken) + if err != nil { + return err + } + // Serialize `UnclaimedFeePending` param: + err = encoder.Encode(obj.UnclaimedFeePending) + if err != nil { + return err + } + // Serialize `AFee` param: + err = encoder.Encode(obj.AFee) + if err != nil { + return err + } + // Serialize `BFee` param: + err = encoder.Encode(obj.BFee) + if err != nil { + return err + } + return nil +} + +func (obj *LockEscrow) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Read and check account discriminator: + { + discriminator, err := decoder.ReadTypeID() + if err != nil { + return err + } + if !discriminator.Equal(LockEscrowDiscriminator[:]) { + return fmt.Errorf( + "wrong discriminator: wanted %s, got %s", + "[190 106 121 6 200 182 21 75]", + fmt.Sprint(discriminator[:])) + } + } + // Deserialize `Pool`: + err = decoder.Decode(&obj.Pool) + if err != nil { + return err + } + // Deserialize `Owner`: + err = decoder.Decode(&obj.Owner) + if err != nil { + return err + } + // Deserialize `EscrowVault`: + err = decoder.Decode(&obj.EscrowVault) + if err != nil { + return err + } + // Deserialize `Bump`: + err = decoder.Decode(&obj.Bump) + if err != nil { + return err + } + // Deserialize `TotalLockedAmount`: + err = decoder.Decode(&obj.TotalLockedAmount) + if err != nil { + return err + } + // Deserialize `LpPerToken`: + err = decoder.Decode(&obj.LpPerToken) + if err != nil { + return err + } + // Deserialize `UnclaimedFeePending`: + err = decoder.Decode(&obj.UnclaimedFeePending) + if err != nil { + return err + } + // Deserialize `AFee`: + err = decoder.Decode(&obj.AFee) + if err != nil { + return err + } + // Deserialize `BFee`: + err = decoder.Decode(&obj.BFee) + if err != nil { + return err + } + return nil +} + +type Pool struct { + // LP token mint of the pool + LpMint ag_solanago.PublicKey + + // Token A mint of the pool. Eg: USDT + TokenAMint ag_solanago.PublicKey + + // Token B mint of the pool. Eg: USDC + TokenBMint ag_solanago.PublicKey + + // Vault account for token A. Token A of the pool will be deposit / withdraw from this vault account. + AVault ag_solanago.PublicKey + + // Vault account for token B. Token B of the pool will be deposit / withdraw from this vault account. + BVault ag_solanago.PublicKey + + // LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault. + AVaultLp ag_solanago.PublicKey + + // LP token account of vault B. Used to receive/burn the vault LP upon deposit/withdraw from the vault. + BVaultLp ag_solanago.PublicKey + + // "A" vault lp bump. Used to create signer seeds. + AVaultLpBump uint8 + + // Flag to determine whether the pool is enabled, or disabled. + Enabled bool + + // Protocol fee token account for token A. Used to receive trading fee. + ProtocolTokenAFee ag_solanago.PublicKey + + // Protocol fee token account for token B. Used to receive trading fee. + ProtocolTokenBFee ag_solanago.PublicKey + + // Fee last updated timestamp + FeeLastUpdatedAt uint64 + Padding0 [24]uint8 + + // Store the fee charges setting. + Fees PoolFees + + // Pool type + PoolType PoolType + + // Stake pubkey of SPL stake pool + Stake ag_solanago.PublicKey + + // Total locked lp token + TotalLockedLp uint64 + + // bootstrapping config + Bootstrapping Bootstrapping + PartnerInfo PartnerInfo + + // Padding for future pool field + Padding Padding + + // The type of the swap curve supported by the pool. + CurveType CurveType +} + +var PoolDiscriminator = [8]byte{241, 154, 109, 4, 17, 177, 109, 188} + +func (obj Pool) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Write account discriminator: + err = encoder.WriteBytes(PoolDiscriminator[:], false) + if err != nil { + return err + } + // Serialize `LpMint` param: + err = encoder.Encode(obj.LpMint) + if err != nil { + return err + } + // Serialize `TokenAMint` param: + err = encoder.Encode(obj.TokenAMint) + if err != nil { + return err + } + // Serialize `TokenBMint` param: + err = encoder.Encode(obj.TokenBMint) + if err != nil { + return err + } + // Serialize `AVault` param: + err = encoder.Encode(obj.AVault) + if err != nil { + return err + } + // Serialize `BVault` param: + err = encoder.Encode(obj.BVault) + if err != nil { + return err + } + // Serialize `AVaultLp` param: + err = encoder.Encode(obj.AVaultLp) + if err != nil { + return err + } + // Serialize `BVaultLp` param: + err = encoder.Encode(obj.BVaultLp) + if err != nil { + return err + } + // Serialize `AVaultLpBump` param: + err = encoder.Encode(obj.AVaultLpBump) + if err != nil { + return err + } + // Serialize `Enabled` param: + err = encoder.Encode(obj.Enabled) + if err != nil { + return err + } + // Serialize `ProtocolTokenAFee` param: + err = encoder.Encode(obj.ProtocolTokenAFee) + if err != nil { + return err + } + // Serialize `ProtocolTokenBFee` param: + err = encoder.Encode(obj.ProtocolTokenBFee) + if err != nil { + return err + } + // Serialize `FeeLastUpdatedAt` param: + err = encoder.Encode(obj.FeeLastUpdatedAt) + if err != nil { + return err + } + // Serialize `Padding0` param: + err = encoder.Encode(obj.Padding0) + if err != nil { + return err + } + // Serialize `Fees` param: + err = encoder.Encode(obj.Fees) + if err != nil { + return err + } + // Serialize `PoolType` param: + err = encoder.Encode(obj.PoolType) + if err != nil { + return err + } + // Serialize `Stake` param: + err = encoder.Encode(obj.Stake) + if err != nil { + return err + } + // Serialize `TotalLockedLp` param: + err = encoder.Encode(obj.TotalLockedLp) + if err != nil { + return err + } + // Serialize `Bootstrapping` param: + err = encoder.Encode(obj.Bootstrapping) + if err != nil { + return err + } + // Serialize `PartnerInfo` param: + err = encoder.Encode(obj.PartnerInfo) + if err != nil { + return err + } + // Serialize `Padding` param: + err = encoder.Encode(obj.Padding) + if err != nil { + return err + } + // Serialize `CurveType` param: + { + tmp := curveTypeContainer{} + switch realvalue := obj.CurveType.(type) { + case *CurveTypeConstantProduct: + tmp.Enum = 0 + tmp.ConstantProduct = *realvalue + case *CurveTypeStable: + tmp.Enum = 1 + tmp.Stable = *realvalue + } + err := encoder.Encode(tmp) + if err != nil { + return err + } + } + return nil +} + +func (obj *Pool) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Read and check account discriminator: + { + discriminator, err := decoder.ReadTypeID() + if err != nil { + return err + } + if !discriminator.Equal(PoolDiscriminator[:]) { + return fmt.Errorf( + "wrong discriminator: wanted %s, got %s", + "[241 154 109 4 17 177 109 188]", + fmt.Sprint(discriminator[:])) + } + } + // Deserialize `LpMint`: + err = decoder.Decode(&obj.LpMint) + if err != nil { + return err + } + // Deserialize `TokenAMint`: + err = decoder.Decode(&obj.TokenAMint) + if err != nil { + return err + } + // Deserialize `TokenBMint`: + err = decoder.Decode(&obj.TokenBMint) + if err != nil { + return err + } + // Deserialize `AVault`: + err = decoder.Decode(&obj.AVault) + if err != nil { + return err + } + // Deserialize `BVault`: + err = decoder.Decode(&obj.BVault) + if err != nil { + return err + } + // Deserialize `AVaultLp`: + err = decoder.Decode(&obj.AVaultLp) + if err != nil { + return err + } + // Deserialize `BVaultLp`: + err = decoder.Decode(&obj.BVaultLp) + if err != nil { + return err + } + // Deserialize `AVaultLpBump`: + err = decoder.Decode(&obj.AVaultLpBump) + if err != nil { + return err + } + // Deserialize `Enabled`: + err = decoder.Decode(&obj.Enabled) + if err != nil { + return err + } + // Deserialize `ProtocolTokenAFee`: + err = decoder.Decode(&obj.ProtocolTokenAFee) + if err != nil { + return err + } + // Deserialize `ProtocolTokenBFee`: + err = decoder.Decode(&obj.ProtocolTokenBFee) + if err != nil { + return err + } + // Deserialize `FeeLastUpdatedAt`: + err = decoder.Decode(&obj.FeeLastUpdatedAt) + if err != nil { + return err + } + // Deserialize `Padding0`: + err = decoder.Decode(&obj.Padding0) + if err != nil { + return err + } + // Deserialize `Fees`: + err = decoder.Decode(&obj.Fees) + if err != nil { + return err + } + // Deserialize `PoolType`: + err = decoder.Decode(&obj.PoolType) + if err != nil { + return err + } + // Deserialize `Stake`: + err = decoder.Decode(&obj.Stake) + if err != nil { + return err + } + // Deserialize `TotalLockedLp`: + err = decoder.Decode(&obj.TotalLockedLp) + if err != nil { + return err + } + // Deserialize `Bootstrapping`: + err = decoder.Decode(&obj.Bootstrapping) + if err != nil { + return err + } + // Deserialize `PartnerInfo`: + err = decoder.Decode(&obj.PartnerInfo) + if err != nil { + return err + } + // Deserialize `Padding`: + err = decoder.Decode(&obj.Padding) + if err != nil { + return err + } + // Deserialize `CurveType`: + { + tmp := new(curveTypeContainer) + err := decoder.Decode(tmp) + if err != nil { + return err + } + switch tmp.Enum { + case 0: + obj.CurveType = (*CurveTypeConstantProduct)(&tmp.Enum) + case 1: + obj.CurveType = &tmp.Stable + default: + return fmt.Errorf("unknown enum index: %v", tmp.Enum) + } + } + return nil +} diff --git a/programs/meteorapools/instructions.go b/programs/meteorapools/instructions.go new file mode 100644 index 00000000..8292947a --- /dev/null +++ b/programs/meteorapools/instructions.go @@ -0,0 +1,320 @@ +// Program for AMM +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +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 = "Amm" + +func init() { + if !ProgramID.IsZero() { + ag_solanago.RegisterInstructionDecoder(ProgramID, registryDecodeInstruction) + } +} + +var ( + // Initialize a new permissioned pool. + Instruction_InitializePermissionedPool = ag_binary.TypeID([8]byte{77, 85, 178, 157, 50, 48, 212, 126}) + + // Initialize a new permissionless pool. + Instruction_InitializePermissionlessPool = ag_binary.TypeID([8]byte{118, 173, 41, 157, 173, 72, 97, 103}) + + // Initialize a new permissionless pool with customized fee tier + Instruction_InitializePermissionlessPoolWithFeeTier = ag_binary.TypeID([8]byte{6, 135, 68, 147, 229, 82, 169, 113}) + + // Enable or disable a pool. A disabled pool allow only remove balanced liquidity operation. + Instruction_EnableOrDisablePool = ag_binary.TypeID([8]byte{128, 6, 228, 131, 55, 161, 52, 169}) + + // Swap token A to B, or vice versa. An amount of trading fee will be charged for liquidity provider, and the admin of the pool. + Instruction_Swap = ag_binary.TypeID([8]byte{248, 198, 158, 145, 225, 117, 135, 200}) + + // Withdraw only single token from the pool. Only supported by pool with stable swap curve. + Instruction_RemoveLiquiditySingleSide = ag_binary.TypeID([8]byte{84, 84, 177, 66, 254, 185, 10, 251}) + + // Deposit tokens to the pool in an imbalance ratio. Only supported by pool with stable swap curve. + Instruction_AddImbalanceLiquidity = ag_binary.TypeID([8]byte{79, 35, 122, 84, 173, 15, 93, 191}) + + // Withdraw tokens from the pool in a balanced ratio. User will still able to withdraw from pool even the pool is disabled. This allow user to exit their liquidity when there's some unforeseen event happen. + Instruction_RemoveBalanceLiquidity = ag_binary.TypeID([8]byte{133, 109, 44, 179, 56, 238, 114, 33}) + + // Deposit tokens to the pool in a balanced ratio. + Instruction_AddBalanceLiquidity = ag_binary.TypeID([8]byte{168, 227, 50, 62, 189, 171, 84, 176}) + + // Update trading fee charged for liquidity provider, and admin. + Instruction_SetPoolFees = ag_binary.TypeID([8]byte{102, 44, 158, 54, 205, 37, 126, 78}) + + // Update swap curve parameters. This function do not allow update of curve type. For example: stable swap curve to constant product curve. Only supported by pool with stable swap curve. + // Only amp is allowed to be override. The other attributes of stable swap curve will be ignored. + Instruction_OverrideCurveParam = ag_binary.TypeID([8]byte{98, 86, 204, 51, 94, 71, 69, 187}) + + // Get the general information of the pool. + Instruction_GetPoolInfo = ag_binary.TypeID([8]byte{9, 48, 220, 101, 22, 240, 78, 200}) + + // Bootstrap the pool when liquidity is depleted. + Instruction_BootstrapLiquidity = ag_binary.TypeID([8]byte{4, 228, 215, 71, 225, 253, 119, 206}) + + // Create mint metadata account for old pools + Instruction_CreateMintMetadata = ag_binary.TypeID([8]byte{13, 70, 168, 41, 250, 100, 148, 90}) + + // Create lock account + Instruction_CreateLockEscrow = ag_binary.TypeID([8]byte{54, 87, 165, 19, 69, 227, 218, 224}) + + // Lock Lp token + Instruction_Lock = ag_binary.TypeID([8]byte{21, 19, 208, 43, 237, 62, 255, 87}) + + // Claim fee + Instruction_ClaimFee = ag_binary.TypeID([8]byte{169, 32, 79, 137, 136, 232, 70, 137}) + + // Create config + Instruction_CreateConfig = ag_binary.TypeID([8]byte{201, 207, 243, 114, 75, 111, 47, 189}) + + // Close config + Instruction_CloseConfig = ag_binary.TypeID([8]byte{145, 9, 72, 157, 95, 125, 61, 85}) + + // Initialize permissionless pool with config + Instruction_InitializePermissionlessConstantProductPoolWithConfig = ag_binary.TypeID([8]byte{7, 166, 138, 171, 206, 171, 236, 244}) + + // Initialize permissionless pool with config 2 + Instruction_InitializePermissionlessConstantProductPoolWithConfig2 = ag_binary.TypeID([8]byte{48, 149, 220, 130, 61, 11, 9, 178}) + + // Initialize permissionless pool with customizable params + Instruction_InitializeCustomizablePermissionlessConstantProductPool = ag_binary.TypeID([8]byte{145, 24, 172, 194, 219, 125, 3, 190}) + + // Update activation slot + Instruction_UpdateActivationPoint = ag_binary.TypeID([8]byte{150, 62, 125, 219, 171, 220, 26, 237}) + + // Withdraw protocol fee + Instruction_WithdrawProtocolFees = ag_binary.TypeID([8]byte{11, 68, 165, 98, 18, 208, 134, 73}) + + // Set whitelisted vault + Instruction_SetWhitelistedVault = ag_binary.TypeID([8]byte{12, 148, 94, 42, 55, 57, 83, 247}) + + // Partner claim fee + Instruction_PartnerClaimFee = ag_binary.TypeID([8]byte{57, 53, 176, 30, 123, 70, 52, 64}) +) + +// InstructionIDToName returns the name of the instruction given its ID. +func InstructionIDToName(id ag_binary.TypeID) string { + switch id { + case Instruction_InitializePermissionedPool: + return "InitializePermissionedPool" + case Instruction_InitializePermissionlessPool: + return "InitializePermissionlessPool" + case Instruction_InitializePermissionlessPoolWithFeeTier: + return "InitializePermissionlessPoolWithFeeTier" + case Instruction_EnableOrDisablePool: + return "EnableOrDisablePool" + case Instruction_Swap: + return "Swap" + case Instruction_RemoveLiquiditySingleSide: + return "RemoveLiquiditySingleSide" + case Instruction_AddImbalanceLiquidity: + return "AddImbalanceLiquidity" + case Instruction_RemoveBalanceLiquidity: + return "RemoveBalanceLiquidity" + case Instruction_AddBalanceLiquidity: + return "AddBalanceLiquidity" + case Instruction_SetPoolFees: + return "SetPoolFees" + case Instruction_OverrideCurveParam: + return "OverrideCurveParam" + case Instruction_GetPoolInfo: + return "GetPoolInfo" + case Instruction_BootstrapLiquidity: + return "BootstrapLiquidity" + case Instruction_CreateMintMetadata: + return "CreateMintMetadata" + case Instruction_CreateLockEscrow: + return "CreateLockEscrow" + case Instruction_Lock: + return "Lock" + case Instruction_ClaimFee: + return "ClaimFee" + case Instruction_CreateConfig: + return "CreateConfig" + case Instruction_CloseConfig: + return "CloseConfig" + case Instruction_InitializePermissionlessConstantProductPoolWithConfig: + return "InitializePermissionlessConstantProductPoolWithConfig" + case Instruction_InitializePermissionlessConstantProductPoolWithConfig2: + return "InitializePermissionlessConstantProductPoolWithConfig2" + case Instruction_InitializeCustomizablePermissionlessConstantProductPool: + return "InitializeCustomizablePermissionlessConstantProductPool" + case Instruction_UpdateActivationPoint: + return "UpdateActivationPoint" + case Instruction_WithdrawProtocolFees: + return "WithdrawProtocolFees" + case Instruction_SetWhitelistedVault: + return "SetWhitelistedVault" + case Instruction_PartnerClaimFee: + return "PartnerClaimFee" + 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_permissioned_pool", (*InitializePermissionedPool)(nil), + }, + { + "initialize_permissionless_pool", (*InitializePermissionlessPool)(nil), + }, + { + "initialize_permissionless_pool_with_fee_tier", (*InitializePermissionlessPoolWithFeeTier)(nil), + }, + { + "enable_or_disable_pool", (*EnableOrDisablePool)(nil), + }, + { + "swap", (*Swap)(nil), + }, + { + "remove_liquidity_single_side", (*RemoveLiquiditySingleSide)(nil), + }, + { + "add_imbalance_liquidity", (*AddImbalanceLiquidity)(nil), + }, + { + "remove_balance_liquidity", (*RemoveBalanceLiquidity)(nil), + }, + { + "add_balance_liquidity", (*AddBalanceLiquidity)(nil), + }, + { + "set_pool_fees", (*SetPoolFees)(nil), + }, + { + "override_curve_param", (*OverrideCurveParam)(nil), + }, + { + "get_pool_info", (*GetPoolInfo)(nil), + }, + { + "bootstrap_liquidity", (*BootstrapLiquidity)(nil), + }, + { + "create_mint_metadata", (*CreateMintMetadata)(nil), + }, + { + "create_lock_escrow", (*CreateLockEscrow)(nil), + }, + { + "lock", (*Lock)(nil), + }, + { + "claim_fee", (*ClaimFee)(nil), + }, + { + "create_config", (*CreateConfig)(nil), + }, + { + "close_config", (*CloseConfig)(nil), + }, + { + "initialize_permissionless_constant_product_pool_with_config", (*InitializePermissionlessConstantProductPoolWithConfig)(nil), + }, + { + "initialize_permissionless_constant_product_pool_with_config2", (*InitializePermissionlessConstantProductPoolWithConfig2)(nil), + }, + { + "initialize_customizable_permissionless_constant_product_pool", (*InitializeCustomizablePermissionlessConstantProductPool)(nil), + }, + { + "update_activation_point", (*UpdateActivationPoint)(nil), + }, + { + "withdraw_protocol_fees", (*WithdrawProtocolFees)(nil), + }, + { + "set_whitelisted_vault", (*SetWhitelistedVault)(nil), + }, + { + "partner_claim_fee", (*PartnerClaimFee)(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 +} diff --git a/programs/meteorapools/testing_utils.go b/programs/meteorapools/testing_utils.go new file mode 100644 index 00000000..df9b52c7 --- /dev/null +++ b/programs/meteorapools/testing_utils.go @@ -0,0 +1,20 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + "bytes" + "fmt" + ag_binary "github.com/gagliardetto/binary" +) + +func encodeT(data interface{}, buf *bytes.Buffer) error { + if err := ag_binary.NewBorshEncoder(buf).Encode(data); err != nil { + return fmt.Errorf("unable to encode instruction: %w", err) + } + return nil +} + +func decodeT(dst interface{}, data []byte) error { + return ag_binary.NewBorshDecoder(data).Decode(dst) +} diff --git a/programs/meteorapools/types.go b/programs/meteorapools/types.go new file mode 100644 index 00000000..370ca0b2 --- /dev/null +++ b/programs/meteorapools/types.go @@ -0,0 +1,842 @@ +// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. + +package amm + +import ( + ag_binary "github.com/gagliardetto/binary" + ag_solanago "github.com/gagliardetto/solana-go" +) + +type TokenMultiplier struct { + // Multiplier for token A of the pool. + TokenAMultiplier uint64 + + // Multiplier for token B of the pool. + TokenBMultiplier uint64 + + // Record the highest token decimal in the pool. For example, Token A is 6 decimal, token B is 9 decimal. This will save value of 9. + PrecisionFactor uint8 +} + +func (obj TokenMultiplier) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `TokenAMultiplier` param: + err = encoder.Encode(obj.TokenAMultiplier) + if err != nil { + return err + } + // Serialize `TokenBMultiplier` param: + err = encoder.Encode(obj.TokenBMultiplier) + if err != nil { + return err + } + // Serialize `PrecisionFactor` param: + err = encoder.Encode(obj.PrecisionFactor) + if err != nil { + return err + } + return nil +} + +func (obj *TokenMultiplier) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `TokenAMultiplier`: + err = decoder.Decode(&obj.TokenAMultiplier) + if err != nil { + return err + } + // Deserialize `TokenBMultiplier`: + err = decoder.Decode(&obj.TokenBMultiplier) + if err != nil { + return err + } + // Deserialize `PrecisionFactor`: + err = decoder.Decode(&obj.PrecisionFactor) + if err != nil { + return err + } + return nil +} + +type PoolFees struct { + // Trade fees are extra token amounts that are held inside the token + // accounts during a trade, making the value of liquidity tokens rise. + // Trade fee numerator + TradeFeeNumerator uint64 + + // Trade fee denominator + TradeFeeDenominator uint64 + + // Protocol trading fees are extra token amounts that are held inside the token + // accounts during a trade, with the equivalent in pool tokens minted to + // the protocol of the program. + // Protocol trade fee numerator + ProtocolTradeFeeNumerator uint64 + + // Protocol trade fee denominator + ProtocolTradeFeeDenominator uint64 +} + +func (obj PoolFees) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `TradeFeeNumerator` param: + err = encoder.Encode(obj.TradeFeeNumerator) + if err != nil { + return err + } + // Serialize `TradeFeeDenominator` param: + err = encoder.Encode(obj.TradeFeeDenominator) + if err != nil { + return err + } + // Serialize `ProtocolTradeFeeNumerator` param: + err = encoder.Encode(obj.ProtocolTradeFeeNumerator) + if err != nil { + return err + } + // Serialize `ProtocolTradeFeeDenominator` param: + err = encoder.Encode(obj.ProtocolTradeFeeDenominator) + if err != nil { + return err + } + return nil +} + +func (obj *PoolFees) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `TradeFeeNumerator`: + err = decoder.Decode(&obj.TradeFeeNumerator) + if err != nil { + return err + } + // Deserialize `TradeFeeDenominator`: + err = decoder.Decode(&obj.TradeFeeDenominator) + if err != nil { + return err + } + // Deserialize `ProtocolTradeFeeNumerator`: + err = decoder.Decode(&obj.ProtocolTradeFeeNumerator) + if err != nil { + return err + } + // Deserialize `ProtocolTradeFeeDenominator`: + err = decoder.Decode(&obj.ProtocolTradeFeeDenominator) + if err != nil { + return err + } + return nil +} + +type Depeg struct { + // The virtual price of staking / interest bearing token + BaseVirtualPrice uint64 + + // The last time base_virtual_price is updated + BaseCacheUpdated uint64 + + // Type of the depeg pool + DepegType DepegType +} + +func (obj Depeg) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `BaseVirtualPrice` param: + err = encoder.Encode(obj.BaseVirtualPrice) + if err != nil { + return err + } + // Serialize `BaseCacheUpdated` param: + err = encoder.Encode(obj.BaseCacheUpdated) + if err != nil { + return err + } + // Serialize `DepegType` param: + err = encoder.Encode(obj.DepegType) + if err != nil { + return err + } + return nil +} + +func (obj *Depeg) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `BaseVirtualPrice`: + err = decoder.Decode(&obj.BaseVirtualPrice) + if err != nil { + return err + } + // Deserialize `BaseCacheUpdated`: + err = decoder.Decode(&obj.BaseCacheUpdated) + if err != nil { + return err + } + // Deserialize `DepegType`: + err = decoder.Decode(&obj.DepegType) + if err != nil { + return err + } + return nil +} + +type ConfigParameters struct { + TradeFeeNumerator uint64 + ProtocolTradeFeeNumerator uint64 + ActivationDuration uint64 + VaultConfigKey ag_solanago.PublicKey + PoolCreatorAuthority ag_solanago.PublicKey + ActivationType uint8 + Index uint64 + PartnerFeeNumerator uint64 +} + +func (obj ConfigParameters) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `TradeFeeNumerator` param: + err = encoder.Encode(obj.TradeFeeNumerator) + if err != nil { + return err + } + // Serialize `ProtocolTradeFeeNumerator` param: + err = encoder.Encode(obj.ProtocolTradeFeeNumerator) + if err != nil { + return err + } + // Serialize `ActivationDuration` param: + err = encoder.Encode(obj.ActivationDuration) + if err != nil { + return err + } + // Serialize `VaultConfigKey` param: + err = encoder.Encode(obj.VaultConfigKey) + if err != nil { + return err + } + // Serialize `PoolCreatorAuthority` param: + err = encoder.Encode(obj.PoolCreatorAuthority) + if err != nil { + return err + } + // Serialize `ActivationType` param: + err = encoder.Encode(obj.ActivationType) + if err != nil { + return err + } + // Serialize `Index` param: + err = encoder.Encode(obj.Index) + if err != nil { + return err + } + // Serialize `PartnerFeeNumerator` param: + err = encoder.Encode(obj.PartnerFeeNumerator) + if err != nil { + return err + } + return nil +} + +func (obj *ConfigParameters) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `TradeFeeNumerator`: + err = decoder.Decode(&obj.TradeFeeNumerator) + if err != nil { + return err + } + // Deserialize `ProtocolTradeFeeNumerator`: + err = decoder.Decode(&obj.ProtocolTradeFeeNumerator) + if err != nil { + return err + } + // Deserialize `ActivationDuration`: + err = decoder.Decode(&obj.ActivationDuration) + if err != nil { + return err + } + // Deserialize `VaultConfigKey`: + err = decoder.Decode(&obj.VaultConfigKey) + if err != nil { + return err + } + // Deserialize `PoolCreatorAuthority`: + err = decoder.Decode(&obj.PoolCreatorAuthority) + if err != nil { + return err + } + // Deserialize `ActivationType`: + err = decoder.Decode(&obj.ActivationType) + if err != nil { + return err + } + // Deserialize `Index`: + err = decoder.Decode(&obj.Index) + if err != nil { + return err + } + // Deserialize `PartnerFeeNumerator`: + err = decoder.Decode(&obj.PartnerFeeNumerator) + if err != nil { + return err + } + return nil +} + +type CustomizableParams struct { + // Trading fee. + TradeFeeNumerator uint32 + + // The pool start trading. + ActivationPoint *uint64 `bin:"optional"` + + // Whether the pool support alpha vault + HasAlphaVault bool + + // Activation type + ActivationType uint8 + + // Padding + Padding [90]uint8 +} + +func (obj CustomizableParams) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `TradeFeeNumerator` param: + err = encoder.Encode(obj.TradeFeeNumerator) + if err != nil { + return err + } + // Serialize `ActivationPoint` param (optional): + { + if obj.ActivationPoint == nil { + err = encoder.WriteBool(false) + if err != nil { + return err + } + } else { + err = encoder.WriteBool(true) + if err != nil { + return err + } + err = encoder.Encode(obj.ActivationPoint) + if err != nil { + return err + } + } + } + // Serialize `HasAlphaVault` param: + err = encoder.Encode(obj.HasAlphaVault) + if err != nil { + return err + } + // Serialize `ActivationType` param: + err = encoder.Encode(obj.ActivationType) + if err != nil { + return err + } + // Serialize `Padding` param: + err = encoder.Encode(obj.Padding) + if err != nil { + return err + } + return nil +} + +func (obj *CustomizableParams) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `TradeFeeNumerator`: + err = decoder.Decode(&obj.TradeFeeNumerator) + if err != nil { + return err + } + // Deserialize `ActivationPoint` (optional): + { + ok, err := decoder.ReadBool() + if err != nil { + return err + } + if ok { + err = decoder.Decode(&obj.ActivationPoint) + if err != nil { + return err + } + } + } + // Deserialize `HasAlphaVault`: + err = decoder.Decode(&obj.HasAlphaVault) + if err != nil { + return err + } + // Deserialize `ActivationType`: + err = decoder.Decode(&obj.ActivationType) + if err != nil { + return err + } + // Deserialize `Padding`: + err = decoder.Decode(&obj.Padding) + if err != nil { + return err + } + return nil +} + +type Padding struct { + // Padding 0 + Padding0 [6]uint8 + + // Padding 1 + Padding1 [21]uint64 + + // Padding 2 + Padding2 [21]uint64 +} + +func (obj Padding) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Padding0` param: + err = encoder.Encode(obj.Padding0) + if err != nil { + return err + } + // Serialize `Padding1` param: + err = encoder.Encode(obj.Padding1) + if err != nil { + return err + } + // Serialize `Padding2` param: + err = encoder.Encode(obj.Padding2) + if err != nil { + return err + } + return nil +} + +func (obj *Padding) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Padding0`: + err = decoder.Decode(&obj.Padding0) + if err != nil { + return err + } + // Deserialize `Padding1`: + err = decoder.Decode(&obj.Padding1) + if err != nil { + return err + } + // Deserialize `Padding2`: + err = decoder.Decode(&obj.Padding2) + if err != nil { + return err + } + return nil +} + +type PartnerInfo struct { + FeeNumerator uint64 + PartnerAuthority ag_solanago.PublicKey + PendingFeeA uint64 + PendingFeeB uint64 +} + +func (obj PartnerInfo) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `FeeNumerator` param: + err = encoder.Encode(obj.FeeNumerator) + if err != nil { + return err + } + // Serialize `PartnerAuthority` param: + err = encoder.Encode(obj.PartnerAuthority) + if err != nil { + return err + } + // Serialize `PendingFeeA` param: + err = encoder.Encode(obj.PendingFeeA) + if err != nil { + return err + } + // Serialize `PendingFeeB` param: + err = encoder.Encode(obj.PendingFeeB) + if err != nil { + return err + } + return nil +} + +func (obj *PartnerInfo) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `FeeNumerator`: + err = decoder.Decode(&obj.FeeNumerator) + if err != nil { + return err + } + // Deserialize `PartnerAuthority`: + err = decoder.Decode(&obj.PartnerAuthority) + if err != nil { + return err + } + // Deserialize `PendingFeeA`: + err = decoder.Decode(&obj.PendingFeeA) + if err != nil { + return err + } + // Deserialize `PendingFeeB`: + err = decoder.Decode(&obj.PendingFeeB) + if err != nil { + return err + } + return nil +} + +type Bootstrapping struct { + // Activation point, can be slot or timestamp + ActivationPoint uint64 + + // Whitelisted vault to be able to buy pool before activation_point + WhitelistedVault ag_solanago.PublicKey + + // Need to store pool creator in lauch pool, so they can modify liquidity before activation_point + PoolCreator ag_solanago.PublicKey + + // Activation type, 0 means by slot, 1 means by timestamp + ActivationType uint8 +} + +func (obj Bootstrapping) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `ActivationPoint` param: + err = encoder.Encode(obj.ActivationPoint) + if err != nil { + return err + } + // Serialize `WhitelistedVault` param: + err = encoder.Encode(obj.WhitelistedVault) + if err != nil { + return err + } + // Serialize `PoolCreator` param: + err = encoder.Encode(obj.PoolCreator) + if err != nil { + return err + } + // Serialize `ActivationType` param: + err = encoder.Encode(obj.ActivationType) + if err != nil { + return err + } + return nil +} + +func (obj *Bootstrapping) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `ActivationPoint`: + err = decoder.Decode(&obj.ActivationPoint) + if err != nil { + return err + } + // Deserialize `WhitelistedVault`: + err = decoder.Decode(&obj.WhitelistedVault) + if err != nil { + return err + } + // Deserialize `PoolCreator`: + err = decoder.Decode(&obj.PoolCreator) + if err != nil { + return err + } + // Deserialize `ActivationType`: + err = decoder.Decode(&obj.ActivationType) + if err != nil { + return err + } + return nil +} + +type ActivationType ag_binary.BorshEnum + +const ( + ActivationTypeSlot ActivationType = iota + ActivationTypeTimestamp +) + +func (value ActivationType) String() string { + switch value { + case ActivationTypeSlot: + return "Slot" + case ActivationTypeTimestamp: + return "Timestamp" + default: + return "" + } +} + +type RoundDirection ag_binary.BorshEnum + +const ( + RoundDirectionFloor RoundDirection = iota + RoundDirectionCeiling +) + +func (value RoundDirection) String() string { + switch value { + case RoundDirectionFloor: + return "Floor" + case RoundDirectionCeiling: + return "Ceiling" + default: + return "" + } +} + +type TradeDirection ag_binary.BorshEnum + +const ( + TradeDirectionAtoB TradeDirection = iota + TradeDirectionBtoA +) + +func (value TradeDirection) String() string { + switch value { + case TradeDirectionAtoB: + return "AtoB" + case TradeDirectionBtoA: + return "BtoA" + default: + return "" + } +} + +type NewCurveType interface { + isNewCurveType() +} + +type newCurveTypeContainer struct { + Enum ag_binary.BorshEnum `borsh_enum:"true"` + ConstantProduct NewCurveTypeConstantProduct + Stable NewCurveTypeStable + NewCurve NewCurveTypeNewCurve +} + +type NewCurveTypeConstantProduct uint8 + +func (obj NewCurveTypeConstantProduct) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} + +func (obj *NewCurveTypeConstantProduct) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +func (_ *NewCurveTypeConstantProduct) isNewCurveType() {} + +type NewCurveTypeStable struct { + Amp uint64 + TokenMultiplier TokenMultiplier + Depeg Depeg + LastAmpUpdatedTimestamp uint64 +} + +func (obj NewCurveTypeStable) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Amp` param: + err = encoder.Encode(obj.Amp) + if err != nil { + return err + } + // Serialize `TokenMultiplier` param: + err = encoder.Encode(obj.TokenMultiplier) + if err != nil { + return err + } + // Serialize `Depeg` param: + err = encoder.Encode(obj.Depeg) + if err != nil { + return err + } + // Serialize `LastAmpUpdatedTimestamp` param: + err = encoder.Encode(obj.LastAmpUpdatedTimestamp) + if err != nil { + return err + } + return nil +} + +func (obj *NewCurveTypeStable) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Amp`: + err = decoder.Decode(&obj.Amp) + if err != nil { + return err + } + // Deserialize `TokenMultiplier`: + err = decoder.Decode(&obj.TokenMultiplier) + if err != nil { + return err + } + // Deserialize `Depeg`: + err = decoder.Decode(&obj.Depeg) + if err != nil { + return err + } + // Deserialize `LastAmpUpdatedTimestamp`: + err = decoder.Decode(&obj.LastAmpUpdatedTimestamp) + if err != nil { + return err + } + return nil +} + +func (_ *NewCurveTypeStable) isNewCurveType() {} + +type NewCurveTypeNewCurve struct { + FieldOne uint64 + FieldTwo uint64 +} + +func (obj NewCurveTypeNewCurve) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `FieldOne` param: + err = encoder.Encode(obj.FieldOne) + if err != nil { + return err + } + // Serialize `FieldTwo` param: + err = encoder.Encode(obj.FieldTwo) + if err != nil { + return err + } + return nil +} + +func (obj *NewCurveTypeNewCurve) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `FieldOne`: + err = decoder.Decode(&obj.FieldOne) + if err != nil { + return err + } + // Deserialize `FieldTwo`: + err = decoder.Decode(&obj.FieldTwo) + if err != nil { + return err + } + return nil +} + +func (_ *NewCurveTypeNewCurve) isNewCurveType() {} + +type CurveType interface { + isCurveType() +} + +type curveTypeContainer struct { + Enum ag_binary.BorshEnum `borsh_enum:"true"` + ConstantProduct CurveTypeConstantProduct + Stable CurveTypeStable +} + +type CurveTypeConstantProduct uint8 + +func (obj CurveTypeConstantProduct) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + return nil +} + +func (obj *CurveTypeConstantProduct) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + return nil +} + +func (_ *CurveTypeConstantProduct) isCurveType() {} + +type CurveTypeStable struct { + Amp uint64 + TokenMultiplier TokenMultiplier + Depeg Depeg + LastAmpUpdatedTimestamp uint64 +} + +func (obj CurveTypeStable) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { + // Serialize `Amp` param: + err = encoder.Encode(obj.Amp) + if err != nil { + return err + } + // Serialize `TokenMultiplier` param: + err = encoder.Encode(obj.TokenMultiplier) + if err != nil { + return err + } + // Serialize `Depeg` param: + err = encoder.Encode(obj.Depeg) + if err != nil { + return err + } + // Serialize `LastAmpUpdatedTimestamp` param: + err = encoder.Encode(obj.LastAmpUpdatedTimestamp) + if err != nil { + return err + } + return nil +} + +func (obj *CurveTypeStable) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { + // Deserialize `Amp`: + err = decoder.Decode(&obj.Amp) + if err != nil { + return err + } + // Deserialize `TokenMultiplier`: + err = decoder.Decode(&obj.TokenMultiplier) + if err != nil { + return err + } + // Deserialize `Depeg`: + err = decoder.Decode(&obj.Depeg) + if err != nil { + return err + } + // Deserialize `LastAmpUpdatedTimestamp`: + err = decoder.Decode(&obj.LastAmpUpdatedTimestamp) + if err != nil { + return err + } + return nil +} + +func (_ *CurveTypeStable) isCurveType() {} + +type DepegType ag_binary.BorshEnum + +const ( + DepegTypeNone DepegType = iota + DepegTypeMarinade + DepegTypeLido + DepegTypeSplStake +) + +func (value DepegType) String() string { + switch value { + case DepegTypeNone: + return "None" + case DepegTypeMarinade: + return "Marinade" + case DepegTypeLido: + return "Lido" + case DepegTypeSplStake: + return "SplStake" + default: + return "" + } +} + +type Rounding ag_binary.BorshEnum + +const ( + RoundingUp Rounding = iota + RoundingDown +) + +func (value Rounding) String() string { + switch value { + case RoundingUp: + return "Up" + case RoundingDown: + return "Down" + default: + return "" + } +} + +type PoolType ag_binary.BorshEnum + +const ( + PoolTypePermissioned PoolType = iota + PoolTypePermissionless +) + +func (value PoolType) String() string { + switch value { + case PoolTypePermissioned: + return "Permissioned" + case PoolTypePermissionless: + return "Permissionless" + default: + return "" + } +}