diff --git a/.changeset/brave-flies-hope.md b/.changeset/brave-flies-hope.md new file mode 100644 index 00000000..f772125e --- /dev/null +++ b/.changeset/brave-flies-hope.md @@ -0,0 +1,11 @@ +--- +"@macalinao/clients-orca-whirlpools": patch +"@macalinao/clients-kamino-lending": patch +"@macalinao/clients-spl-governance": patch +"@macalinao/clients-spl-stake-pool": patch +"@macalinao/clients-token-metadata": patch +"@macalinao/clients-quarry": patch +"@macalinao/coda": patch +--- + +Update docs diff --git a/bun.lock b/bun.lock index eb421866..ff064151 100644 --- a/bun.lock +++ b/bun.lock @@ -8,9 +8,10 @@ "@changesets/cli": "^2.29.7", "@macalinao/biome-config": "^0.1.2", "husky": "^9.1.7", - "lint-staged": "^16.2.3", + "lint-staged": "^16.2.4", "turbo": "^2.5.8", - "typedoc": "^0.28.13", + "typedoc": "^0.28.14", + "typescript": "catalog:", }, }, "apps/docs": { @@ -99,6 +100,21 @@ "@solana/kit": "*", }, }, + "clients/spl-stake-pool": { + "name": "@macalinao/clients-spl-stake-pool", + "version": "0.1.0", + "devDependencies": { + "@macalinao/coda": "workspace:^", + "@macalinao/eslint-config": "catalog:", + "@macalinao/tsconfig": "catalog:", + "@solana/kit": "catalog:", + "eslint": "catalog:", + "typescript": "catalog:", + }, + "peerDependencies": { + "@solana/kit": "*", + }, + }, "clients/token-metadata": { "name": "@macalinao/clients-token-metadata", "version": "0.4.2", @@ -533,6 +549,8 @@ "@macalinao/clients-spl-governance": ["@macalinao/clients-spl-governance@workspace:clients/spl-governance"], + "@macalinao/clients-spl-stake-pool": ["@macalinao/clients-spl-stake-pool@workspace:clients/spl-stake-pool"], + "@macalinao/clients-token-metadata": ["@macalinao/clients-token-metadata@workspace:clients/token-metadata"], "@macalinao/clients-voter-stake-registry": ["@macalinao/clients-voter-stake-registry@workspace:clients/voter-stake-registry"], diff --git a/clients/kamino-lending/README.md b/clients/kamino-lending/README.md index 5997bb12..f01781f8 100644 --- a/clients/kamino-lending/README.md +++ b/clients/kamino-lending/README.md @@ -26,7 +26,7 @@ npm install @macalinao/clients-kamino-lending ```typescript import { - createInitializeInstruction, + getInitLendingMarketInstruction, fetchLendingMarket, // ... other exports } from "@macalinao/clients-kamino-lending"; @@ -39,7 +39,7 @@ const rpc = createSolanaRpc("https://api.mainnet-beta.solana.com"); const lendingMarket = await fetchLendingMarket(rpc, marketAddress); // Create instructions -const instruction = createInitializeInstruction({ +const instruction = getInitLendingMarketInstruction({ // ... instruction parameters }); ``` diff --git a/clients/orca-whirlpools/README.md b/clients/orca-whirlpools/README.md index 978156cc..bdf7c125 100644 --- a/clients/orca-whirlpools/README.md +++ b/clients/orca-whirlpools/README.md @@ -33,9 +33,18 @@ The `coda.config.mjs` file can be customized to add PDAs and other Codama visito ## Usage ```typescript -import {} from /* generated exports */ "@macalinao/clients-orca-whirlpools"; - -// Use the generated client functions +import { + getSwapInstruction, + fetchWhirlpool, +} from "@macalinao/clients-orca-whirlpools"; + +// Fetch whirlpool account +const whirlpool = await fetchWhirlpool(rpc, whirlpoolAddress); + +// Create swap instruction +const instruction = getSwapInstruction({ + // ... instruction parameters +}); ``` ## License diff --git a/clients/quarry/README.md b/clients/quarry/README.md index 843807cf..88e81ec8 100644 --- a/clients/quarry/README.md +++ b/clients/quarry/README.md @@ -40,9 +40,18 @@ The `coda.config.mjs` file is configured to load all Quarry protocol IDLs and ge ## Usage ```typescript -import {} from /* generated exports */ "@macalinao/clients-quarry"; - -// Use the generated client functions for any Quarry program +import { + getCreateMinerInstruction, + fetchMiner, +} from "@macalinao/clients-quarry"; + +// Fetch miner account +const miner = await fetchMiner(rpc, minerAddress); + +// Create miner instruction +const instruction = getCreateMinerInstruction({ + // ... instruction parameters +}); ``` ## License diff --git a/clients/spl-governance/README.md b/clients/spl-governance/README.md index d633a9ef..af913f1a 100644 --- a/clients/spl-governance/README.md +++ b/clients/spl-governance/README.md @@ -40,10 +40,10 @@ The `coda.config.mjs` file defines custom PDAs for the SPL Governance program, i ## Usage ```typescript -import { createRealm, getRealmPda } from "@macalinao/clients-spl-governance"; +import { getCreateRealmInstruction, findRealmPda } from "@macalinao/clients-spl-governance"; // Create a new realm -const realmPda = getRealmPda({ name: "my-dao" }); +const realmPda = await findRealmPda({ name: "my-dao" }); // Use the generated client functions ``` diff --git a/clients/spl-stake-pool/README.md b/clients/spl-stake-pool/README.md new file mode 100644 index 00000000..57aee4e7 --- /dev/null +++ b/clients/spl-stake-pool/README.md @@ -0,0 +1,61 @@ +# @macalinao/clients-spl-stake-pool + +[![npm version](https://img.shields.io/npm/v/@macalinao/clients-spl-stake-pool.svg)](https://www.npmjs.com/package/@macalinao/clients-spl-stake-pool) + +TypeScript client for the SPL Stake Pool program, generated using Coda with full ESM support. + +## Installation + +```bash +bun add @macalinao/clients-spl-stake-pool +``` + +## Development + +This client is generated from the SPL Stake Pool IDL using Coda CLI: + +```bash +# Generate the client from idls/spl_stake_pool.json +bun run codegen + +# Build the TypeScript +bun run build +``` + +### Configuration + +The `coda.config.mjs` file defines custom PDAs for the SPL Stake Pool program, including: + +- Withdraw authority for the stake pool +- Stake accounts for validators +- Stake accounts with custom seeds +- Transient stake accounts for delegation operations +- Ephemeral stake accounts for temporary operations + +## Usage + +```typescript +import { + findWithdrawAuthorityPda, + findStakePda +} from "@macalinao/clients-spl-stake-pool"; + +// Get withdraw authority PDA +const withdrawAuthorityPda = await findWithdrawAuthorityPda({ + stakePool: stakePoolPublicKey +}); + +// Get stake account PDA +const stakePda = await findStakePda({ + voteAccount: validatorVoteAccount, + stakePool: stakePoolPublicKey +}); + +// Use the generated client functions +``` + +## License + +Copyright © 2025 Ian Macalinao + +Licensed under the Apache License, Version 2.0 diff --git a/clients/spl-stake-pool/coda.config.mjs b/clients/spl-stake-pool/coda.config.mjs new file mode 100644 index 00000000..435ec9df --- /dev/null +++ b/clients/spl-stake-pool/coda.config.mjs @@ -0,0 +1,108 @@ +import { + accountValueNode, + addPdasVisitor, + argumentValueNode, + constantPdaSeedNodeFromString, + defineConfig, + definedTypeLinkNode, + enumValueNode, + numberTypeNode, + pdaLinkNode, + pdaSeedValueNode, + pdaValueNode, + publicKeyTypeNode, + publicKeyValueNode, + remainderOptionTypeNode, + setAccountDiscriminatorFromFieldVisitor, + setInstructionAccountDefaultValuesVisitor, + variablePdaSeedNode, +} from "@macalinao/coda"; + +/** @type {import("@macalinao/coda").CodaConfig} */ +export default defineConfig({ + // Use glob pattern to match both IDL files + outputDir: "./src/generated", + docs: { + npmPackageName: "@macalinao/clients-spl-stake-pool", + }, + visitors: [ + setAccountDiscriminatorFromFieldVisitor({ + // Realm accounts + stakePool: { + field: "accountType", + value: enumValueNode(definedTypeLinkNode("accountType"), "StakePool"), + }, + validatorList: { + field: "accountType", + value: enumValueNode( + definedTypeLinkNode("accountType"), + "ValidatorList", + ), + }, + }), + addPdasVisitor({ + splStakePool: [ + { + name: "withdrawAuthority", + seeds: [ + variablePdaSeedNode("stakePoolAddress", publicKeyTypeNode()), + constantPdaSeedNodeFromString("utf8", "withdraw"), + ], + }, + { + name: "stake", + seeds: [ + variablePdaSeedNode("voteAccountAddress", publicKeyTypeNode()), + variablePdaSeedNode("stakePoolAddress", publicKeyTypeNode()), + variablePdaSeedNode( + "seed", + remainderOptionTypeNode(numberTypeNode("u32", "le")), + ), + ], + }, + { + name: "transientStake", + seeds: [ + constantPdaSeedNodeFromString("utf8", "transient"), + variablePdaSeedNode("voteAccountAddress", publicKeyTypeNode()), + variablePdaSeedNode("stakePoolAddress", publicKeyTypeNode()), + variablePdaSeedNode("seed", numberTypeNode("u64", "le")), + ], + }, + { + name: "ephemeralStake", + seeds: [ + constantPdaSeedNodeFromString("utf8", "ephemeral"), + variablePdaSeedNode("stakePoolAddress", publicKeyTypeNode()), + variablePdaSeedNode("seed", numberTypeNode("u64", "le")), + ], + }, + ], + }), + setInstructionAccountDefaultValuesVisitor([ + { + account: "stakeProgram", + defaultValue: publicKeyValueNode( + "Stake11111111111111111111111111111111111111", + ), + }, + { + account: "withdrawAuthority", + defaultValue: pdaValueNode(pdaLinkNode("withdrawAuthority"), [ + pdaSeedValueNode("stakePoolAddress", accountValueNode("stakePool")), + ]), + }, + { + account: "transientStakeAccount", + defaultValue: pdaValueNode(pdaLinkNode("transientStake"), [ + pdaSeedValueNode( + "voteAccountAddress", + accountValueNode("validatorVoteAccount"), + ), + pdaSeedValueNode("stakePoolAddress", accountValueNode("stakePool")), + pdaSeedValueNode("seed", argumentValueNode("transientStakeSeed")), + ]), + }, + ]), + ], +}); diff --git a/clients/spl-stake-pool/eslint.config.js b/clients/spl-stake-pool/eslint.config.js new file mode 100644 index 00000000..f157753e --- /dev/null +++ b/clients/spl-stake-pool/eslint.config.js @@ -0,0 +1,31 @@ +import { configs } from "@macalinao/eslint-config"; + +export default [ + ...configs.fast, + { + languageOptions: { + parserOptions: { + tsconfigRootDir: import.meta.dirname, + }, + }, + }, + { + files: ["src/generated/**/*.ts"], + rules: { + "@typescript-eslint/no-non-null-assertion": "off", + "@typescript-eslint/prefer-nullish-coalescing": "off", + }, + }, + { + files: [ + "src/generated/instructions/*.ts", + "src/generated/types/*.ts", + "src/generated/errors/*.ts", + ], + rules: { + "@typescript-eslint/no-unnecessary-condition": "off", + "no-constant-condition": "off", + "@typescript-eslint/no-empty-object-type": "off", + }, + }, +]; diff --git a/clients/spl-stake-pool/idls/spl_stake_pool.json b/clients/spl-stake-pool/idls/spl_stake_pool.json new file mode 100644 index 00000000..bcdb27ba --- /dev/null +++ b/clients/spl-stake-pool/idls/spl_stake_pool.json @@ -0,0 +1,3312 @@ +{ + "version": "2.0.1", + "name": "spl_stake_pool", + "instructions": [ + { + "name": "Initialize", + "docs": [ + "Initializes a new `StakePool`.", + "0. `[w]` New `StakePool` to create.", + "1. `[s]` Manager", + "2. `[]` Staker", + "3. `[]` Stake pool withdraw authority", + "4. `[w]` Uninitialized validator stake list storage account", + "5. `[]` Reserve stake account must be initialized, have zero balance,", + "and staker / withdrawer authority set to pool withdraw authority.", + "6. `[]` Pool token mint. Must have zero supply, owned by withdraw", + "authority.", + "7. `[]` Pool account to deposit the generated fee for manager.", + "8. `[]` Token program id", + "9. `[]` (Optional) Deposit authority that must sign all deposits.", + "Defaults to the program address generated using", + "`find_deposit_authority_program_address`, making deposits", + "permissionless." + ], + "accounts": [ + { + "name": "stakePool", + "isMut": true, + "isSigner": false + }, + { + "name": "manager", + "isMut": false, + "isSigner": true + }, + { + "name": "staker", + "isMut": false, + "isSigner": false + }, + { + "name": "withdrawAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "validatorList", + "isMut": true, + "isSigner": false + }, + { + "name": "reserveStake", + "isMut": false, + "isSigner": false + }, + { + "name": "poolMint", + "isMut": false, + "isSigner": false + }, + { + "name": "feeAccount", + "isMut": false, + "isSigner": false + }, + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "depositAuthority", + "isMut": false, + "isSigner": false, + "isOptionalSigner": true + } + ], + "args": [ + { + "name": "fee", + "type": { + "defined": "Fee" + } + }, + { + "name": "withdrawalFee", + "type": { + "defined": "Fee" + } + }, + { + "name": "depositFee", + "type": { + "defined": "Fee" + } + }, + { + "name": "referralFee", + "type": "u8" + }, + { + "name": "maxValidators", + "type": "u32" + } + ], + "discriminant": { + "type": "u8", + "value": 0 + } + }, + { + "name": "AddValidatorToPool", + "docs": [ + "(Staker only) Adds stake account delegated to validator to the pool's", + "list of managed validators.", + "The stake account will have the rent-exempt amount plus", + "`max(", + "crate::MINIMUM_ACTIVE_STAKE,", + "solana_program::stake::tools::get_minimum_delegation()", + ")`.", + "It is funded from the stake pool reserve.", + "0. `[w]` Stake pool", + "1. `[s]` Staker", + "2. `[w]` Reserve stake account", + "3. `[]` Stake pool withdraw authority", + "4. `[w]` Validator stake list storage account", + "5. `[w]` Stake account to add to the pool", + "6. `[]` Validator this stake account will be delegated to", + "7. `[]` Rent sysvar", + "8. `[]` Clock sysvar", + "9. '[]' Stake history sysvar", + "10. '[]' Stake config sysvar", + "11. `[]` System program", + "12. `[]` Stake program", + "User data: optional non-zero `u32` seed used for generating the", + "validator stake address" + ], + "accounts": [ + { + "name": "stakePool", + "isMut": true, + "isSigner": false, + "docs": ["Stake pool"] + }, + { + "name": "staker", + "isMut": false, + "isSigner": true, + "docs": ["Staker"] + }, + { + "name": "reserveStakeAccount", + "isMut": true, + "isSigner": false, + "docs": ["Reserve stake account"] + }, + { + "name": "withdrawAuthority", + "isMut": false, + "isSigner": false, + "docs": ["Stake pool withdraw authority"] + }, + { + "name": "validatorStakeList", + "isMut": true, + "isSigner": false, + "docs": ["Validator stake list storage account"] + }, + { + "name": "newStakeAccount", + "isMut": true, + "isSigner": false, + "docs": ["Stake account to add to the pool"] + }, + { + "name": "validatorVoteAccount", + "isMut": false, + "isSigner": false, + "docs": ["Validator this stake account will be delegated to"] + }, + { + "name": "rentSysvar", + "isMut": false, + "isSigner": false, + "docs": ["Rent sysvar"] + }, + { + "name": "clockSysvar", + "isMut": false, + "isSigner": false, + "docs": ["Clock sysvar"] + }, + { + "name": "stakeHistorySysvar", + "isMut": false, + "isSigner": false, + "docs": ["Stake history sysvar"] + }, + { + "name": "stakeConfigSysvar", + "isMut": false, + "isSigner": false, + "docs": ["Stake config sysvar"] + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false, + "docs": ["System program"] + }, + { + "name": "stakeProgram", + "isMut": false, + "isSigner": false, + "docs": ["Stake program"] + } + ], + "args": [ + { + "name": "args", + "type": "u32" + } + ], + "discriminant": { + "type": "u8", + "value": 1 + } + }, + { + "name": "RemoveValidatorFromPool", + "docs": [ + "(Staker only) Removes validator from the pool, deactivating its stake", + "Only succeeds if the validator stake account has the minimum of", + "`max(crate::MINIMUM_ACTIVE_STAKE,", + "solana_program::stake::tools::get_minimum_delegation())`. plus the", + "rent-exempt amount.", + "0. `[w]` Stake pool", + "1. `[s]` Staker", + "2. `[]` Stake pool withdraw authority", + "3. `[w]` Validator stake list storage account", + "4. `[w]` Stake account to remove from the pool", + "5. `[w]` Transient stake account, to deactivate if necessary", + "6. `[]` Sysvar clock", + "7. `[]` Stake program id," + ], + "accounts": [ + { + "name": "stakePool", + "isMut": true, + "isSigner": false, + "docs": ["Stake pool"] + }, + { + "name": "staker", + "isMut": false, + "isSigner": true, + "docs": ["Staker"] + }, + { + "name": "withdrawAuthority", + "isMut": false, + "isSigner": false, + "docs": ["Stake pool withdraw authority"] + }, + { + "name": "validatorStakeList", + "isMut": true, + "isSigner": false, + "docs": ["Validator stake list storage account"] + }, + { + "name": "stakeAccount", + "isMut": true, + "isSigner": false, + "docs": ["Stake account to remove from the pool"] + }, + { + "name": "transientStakeAccount", + "isMut": true, + "isSigner": false, + "docs": ["Transient stake account, to deactivate if necessary"] + }, + { + "name": "clockSysvar", + "isMut": false, + "isSigner": false, + "docs": ["Sysvar clock"] + }, + { + "name": "stakeProgram", + "isMut": false, + "isSigner": false, + "docs": ["Stake program id"] + } + ], + "args": [], + "discriminant": { + "type": "u8", + "value": 2 + } + }, + { + "name": "DecreaseValidatorStake", + "docs": [ + "NOTE: This instruction has been deprecated since version 0.7.0. Please", + "use `DecreaseValidatorStakeWithReserve` instead.", + "(Staker only) Decrease active stake on a validator, eventually moving it", + "to the reserve", + "Internally, this instruction splits a validator stake account into its", + "corresponding transient stake account and deactivates it.", + "In order to rebalance the pool without taking custody, the staker needs", + "a way of reducing the stake on a stake account. This instruction splits", + "some amount of stake, up to the total activated stake, from the", + "canonical validator stake account, into its \"transient\" stake", + "account.", + "The instruction only succeeds if the transient stake account does not", + "exist. The amount of lamports to move must be at least rent-exemption", + "plus `max(crate::MINIMUM_ACTIVE_STAKE,", + "solana_program::stake::tools::get_minimum_delegation())`.", + "0. `[]` Stake pool", + "1. `[s]` Stake pool staker", + "2. `[]` Stake pool withdraw authority", + "3. `[w]` Validator list", + "4. `[w]` Canonical stake account to split from", + "5. `[w]` Transient stake account to receive split", + "6. `[]` Clock sysvar", + "7. `[]` Rent sysvar", + "8. `[]` System program", + "9. `[]` Stake program" + ], + "accounts": [ + { + "name": "stakePool", + "isMut": false, + "isSigner": false + }, + { + "name": "staker", + "isMut": false, + "isSigner": true + }, + { + "name": "withdrawAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "validatorList", + "isMut": true, + "isSigner": false + }, + { + "name": "stakeAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "transientStakeAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "clockSysvar", + "isMut": false, + "isSigner": false + }, + { + "name": "rentSysvar", + "isMut": false, + "isSigner": false + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "stakeProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "lamports", + "type": "u64" + }, + { + "name": "transientStakeSeed", + "type": "u64" + } + ], + "discriminant": { + "type": "u8", + "value": 3 + } + }, + { + "name": "IncreaseValidatorStake", + "docs": [ + "(Staker only) Increase stake on a validator from the reserve account", + "Internally, this instruction splits reserve stake into a transient stake", + "account and delegate to the appropriate validator.", + "`UpdateValidatorListBalance` will do the work of merging once it's", + "ready.", + "This instruction only succeeds if the transient stake account does not", + "exist. The minimum amount to move is rent-exemption plus", + "`max(crate::MINIMUM_ACTIVE_STAKE,", + "solana_program::stake::tools::get_minimum_delegation())`.", + "0. `[]` Stake pool", + "1. `[s]` Stake pool staker", + "2. `[]` Stake pool withdraw authority", + "3. `[w]` Validator list", + "4. `[w]` Stake pool reserve stake", + "5. `[w]` Transient stake account", + "6. `[]` Validator stake account", + "7. `[]` Validator vote account to delegate to", + "8. '[]' Clock sysvar", + "9. '[]' Rent sysvar", + "10. `[]` Stake History sysvar", + "11. `[]` Stake Config sysvar", + "12. `[]` System program", + "13. `[]` Stake program", + "User data: amount of lamports to increase on the given validator.", + "The actual amount split into the transient stake account is:", + "`lamports + stake_rent_exemption`.", + "The rent-exemption of the stake account is withdrawn back to the", + "reserve after it is merged." + ], + "accounts": [ + { + "name": "stakePool", + "isMut": false, + "isSigner": false + }, + { + "name": "staker", + "isMut": false, + "isSigner": true + }, + { + "name": "withdrawAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "validatorList", + "isMut": true, + "isSigner": false + }, + { + "name": "reserveStake", + "isMut": true, + "isSigner": false + }, + { + "name": "transientStakeAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "validatorStakeAccount", + "isMut": false, + "isSigner": false + }, + { + "name": "validatorVoteAccount", + "isMut": false, + "isSigner": false + }, + { + "name": "clockSysvar", + "isMut": false, + "isSigner": false + }, + { + "name": "rentSysvar", + "isMut": false, + "isSigner": false + }, + { + "name": "stakeHistorySysvar", + "isMut": false, + "isSigner": false + }, + { + "name": "stakeConfigSysvar", + "isMut": false, + "isSigner": false + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "stakeProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "lamports", + "type": "u64" + }, + { + "name": "transientStakeSeed", + "type": "u64" + } + ], + "discriminant": { + "type": "u8", + "value": 4 + } + }, + { + "name": "SetPreferredValidator", + "docs": [ + "(Staker only) Set the preferred deposit or withdraw stake account for", + "the stake pool", + "In order to avoid users abusing the stake pool as a free conversion", + "between SOL staked on different validators, the staker can force all", + "deposits and/or withdraws to go to one chosen account, or unset that", + "account.", + "0. `[w]` Stake pool", + "1. `[s]` Stake pool staker", + "2. `[]` Validator list", + "Fails if the validator is not part of the stake pool." + ], + "accounts": [ + { + "name": "stakePool", + "isMut": true, + "isSigner": false + }, + { + "name": "staker", + "isMut": false, + "isSigner": true + }, + { + "name": "validatorList", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "validatorType", + "type": { + "defined": "PreferredValidatorType" + } + }, + { + "name": "validatorVoteAddress", + "type": { + "option": "publicKey" + } + } + ], + "discriminant": { + "type": "u8", + "value": 5 + } + }, + { + "name": "UpdateValidatorListBalance", + "docs": [ + "Updates balances of validator and transient stake accounts in the pool", + "While going through the pairs of validator and transient stake", + "accounts, if the transient stake is inactive, it is merged into the", + "reserve stake account. If the transient stake is active and has", + "matching credits observed, it is merged into the canonical", + "validator stake account. In all other states, nothing is done, and", + "the balance is simply added to the canonical stake account balance.", + "0. `[]` Stake pool", + "1. `[]` Stake pool withdraw authority", + "2. `[w]` Validator stake list storage account", + "3. `[w]` Reserve stake account", + "4. `[]` Sysvar clock", + "5. `[]` Sysvar stake history", + "6. `[]` Stake program", + "7. `..7+2N` [] N pairs of validator and transient stake accounts" + ], + "accounts": [ + { + "name": "stakePool", + "isMut": false, + "isSigner": false + }, + { + "name": "withdrawAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "validatorList", + "isMut": true, + "isSigner": false + }, + { + "name": "reserveStake", + "isMut": true, + "isSigner": false + }, + { + "name": "clockSysvar", + "isMut": false, + "isSigner": false + }, + { + "name": "stakeHistorySysvar", + "isMut": false, + "isSigner": false + }, + { + "name": "stakeProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "startIndex", + "type": "u32" + }, + { + "name": "noMerge", + "type": "bool" + } + ], + "discriminant": { + "type": "u8", + "value": 6 + } + }, + { + "name": "UpdateStakePoolBalance", + "docs": [ + "Updates total pool balance based on balances in the reserve and", + "validator list", + "0. `[w]` Stake pool", + "1. `[]` Stake pool withdraw authority", + "2. `[w]` Validator stake list storage account", + "3. `[]` Reserve stake account", + "4. `[w]` Account to receive pool fee tokens", + "5. `[w]` Pool mint account", + "6. `[]` Pool token program" + ], + "accounts": [ + { + "name": "stakePool", + "isMut": true, + "isSigner": false + }, + { + "name": "withdrawAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "validatorList", + "isMut": true, + "isSigner": false + }, + { + "name": "reserveStake", + "isMut": false, + "isSigner": false + }, + { + "name": "feeAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "poolMint", + "isMut": true, + "isSigner": false + }, + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [], + "discriminant": { + "type": "u8", + "value": 7 + } + }, + { + "name": "CleanupRemovedValidatorEntries", + "docs": [ + "Cleans up validator stake account entries marked as `ReadyForRemoval`", + "0. `[]` Stake pool", + "1. `[w]` Validator stake list storage account" + ], + "accounts": [ + { + "name": "stakePool", + "isMut": false, + "isSigner": false + }, + { + "name": "validatorList", + "isMut": true, + "isSigner": false + } + ], + "args": [], + "discriminant": { + "type": "u8", + "value": 8 + } + }, + { + "name": "DepositStake", + "docs": [ + "Deposit some stake into the pool. The output is a \"pool\" token", + "representing ownership into the pool. Inputs are converted to the", + "current ratio.", + "0. `[w]` Stake pool", + "1. `[w]` Validator stake list storage account", + "2. `[s]/[]` Stake pool deposit authority", + "3. `[]` Stake pool withdraw authority", + "4. `[w]` Stake account to join the pool (withdraw authority for the", + "stake account should be first set to the stake pool deposit", + "authority)", + "5. `[w]` Validator stake account for the stake account to be merged", + "with", + "6. `[w]` Reserve stake account, to withdraw rent exempt reserve", + "7. `[w]` User account to receive pool tokens", + "8. `[w]` Account to receive pool fee tokens", + "9. `[w]` Account to receive a portion of pool fee tokens as referral", + "fees", + "10. `[w]` Pool token mint account", + "11. '[]' Sysvar clock account", + "12. '[]' Sysvar stake history account", + "13. `[]` Pool token program id,", + "14. `[]` Stake program id," + ], + "accounts": [ + { + "name": "stakePool", + "isMut": true, + "isSigner": false + }, + { + "name": "validatorList", + "isMut": true, + "isSigner": false + }, + { + "name": "depositAuthority", + "isMut": false, + "isSigner": false, + "isOptionalSigner": true + }, + { + "name": "withdrawAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "stakeToMerge", + "isMut": true, + "isSigner": false + }, + { + "name": "validatorStakeAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "reserveStake", + "isMut": true, + "isSigner": false + }, + { + "name": "userPoolTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "feeAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "referralFeeAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "poolMint", + "isMut": true, + "isSigner": false + }, + { + "name": "clockSysvar", + "isMut": false, + "isSigner": false + }, + { + "name": "stakeHistorySysvar", + "isMut": false, + "isSigner": false + }, + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "stakeProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [], + "discriminant": { + "type": "u8", + "value": 9 + } + }, + { + "name": "WithdrawStake", + "docs": [ + "Withdraw the token from the pool at the current ratio.", + "Succeeds if the stake account has enough SOL to cover the desired", + "amount of pool tokens, and if the withdrawal keeps the total", + "staked amount above the minimum of rent-exempt amount plus `max(", + "crate::MINIMUM_ACTIVE_STAKE,", + "solana_program::stake::tools::get_minimum_delegation()", + ")`.", + "When allowing withdrawals, the order of priority goes:", + "* preferred withdraw validator stake account (if set)", + "* validator stake accounts", + "* transient stake accounts", + "* reserve stake account OR totally remove validator stake accounts", + "A user can freely withdraw from a validator stake account, and if they", + "are all at the minimum, then they can withdraw from transient stake", + "accounts, and if they are all at minimum, then they can withdraw from", + "the reserve or remove any validator from the pool.", + "0. `[w]` Stake pool", + "1. `[w]` Validator stake list storage account", + "2. `[]` Stake pool withdraw authority", + "3. `[w]` Validator or reserve stake account to split", + "4. `[w]` Uninitialized stake account to receive withdrawal", + "5. `[]` User account to set as a new withdraw authority", + "6. `[s]` User transfer authority, for pool token account", + "7. `[w]` User account with pool tokens to burn from", + "8. `[w]` Account to receive pool fee tokens", + "9. `[w]` Pool token mint account", + "10. `[]` Sysvar clock account (required)", + "11. `[]` Pool token program id", + "12. `[]` Stake program id,", + "User data: amount of pool tokens to withdraw" + ], + "accounts": [ + { + "name": "stakePool", + "isMut": true, + "isSigner": false, + "docs": ["Stake pool"] + }, + { + "name": "validatorList", + "isMut": true, + "isSigner": false, + "docs": ["Validator list"] + }, + { + "name": "withdrawAuthority", + "isMut": false, + "isSigner": false, + "docs": ["Withdraw authority"] + }, + { + "name": "sourceStakeAccount", + "isMut": true, + "isSigner": false, + "docs": ["Source stake account"] + }, + { + "name": "destinationStakeAccount", + "isMut": true, + "isSigner": false, + "docs": ["Destination stake account"] + }, + { + "name": "newWithdrawAuthority", + "isMut": false, + "isSigner": false, + "docs": ["New withdraw authority"] + }, + { + "name": "userTransferAuthority", + "isMut": false, + "isSigner": true, + "docs": ["User transfer authority"] + }, + { + "name": "userPoolTokenAccount", + "isMut": true, + "isSigner": false, + "docs": ["User pool token account"] + }, + { + "name": "feeAccount", + "isMut": true, + "isSigner": false, + "docs": ["Fee account"] + }, + { + "name": "poolMint", + "isMut": true, + "isSigner": false, + "docs": ["Pool mint"] + }, + { + "name": "clockSysvar", + "isMut": false, + "isSigner": false, + "docs": ["Clock sysvar"] + }, + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false, + "docs": ["Token program"] + }, + { + "name": "stakeProgram", + "isMut": false, + "isSigner": false, + "docs": ["Stake program"] + } + ], + "args": [ + { + "name": "args", + "type": "u64" + } + ], + "discriminant": { + "type": "u8", + "value": 10 + } + }, + { + "name": "SetManager", + "docs": [ + "(Manager only) Update manager", + "0. `[w]` Stake pool", + "1. `[s]` Manager", + "2. `[s]` New manager", + "3. `[]` New manager fee account" + ], + "accounts": [ + { + "name": "stakePool", + "isMut": true, + "isSigner": false, + "docs": ["Stake pool"] + }, + { + "name": "manager", + "isMut": false, + "isSigner": true, + "docs": ["Manager"] + }, + { + "name": "newManager", + "isMut": false, + "isSigner": true, + "docs": ["New manager"] + }, + { + "name": "newManagerFeeAccount", + "isMut": false, + "isSigner": false, + "docs": ["New manager fee account"] + } + ], + "args": [], + "discriminant": { + "type": "u8", + "value": 11 + } + }, + { + "name": "SetFee", + "docs": [ + "(Manager only) Update fee", + "0. `[w]` Stake pool", + "1. `[s]` Manager" + ], + "accounts": [ + { + "name": "stakePool", + "isMut": true, + "isSigner": false, + "docs": ["Stake pool"] + }, + { + "name": "manager", + "isMut": false, + "isSigner": true, + "docs": ["Manager"] + } + ], + "args": [ + { + "name": "fee", + "type": { + "defined": "FeeType" + } + } + ], + "discriminant": { + "type": "u8", + "value": 12 + } + }, + { + "name": "SetStaker", + "docs": [ + "(Manager or staker only) Update staker", + "0. `[w]` Stake pool", + "1. `[s]` Manager or current staker", + "2. '[]` New staker pubkey" + ], + "accounts": [ + { + "name": "stakePool", + "isMut": true, + "isSigner": false, + "docs": ["Stake pool"] + }, + { + "name": "authority", + "isMut": false, + "isSigner": true, + "docs": ["Manager or current staker"] + }, + { + "name": "newStakerPubkey", + "isMut": false, + "isSigner": false, + "docs": ["New staker pubkey"] + } + ], + "args": [], + "discriminant": { + "type": "u8", + "value": 13 + } + }, + { + "name": "DepositSol", + "docs": [ + "Deposit SOL directly into the pool's reserve account. The output is a", + "\"pool\" token representing ownership into the pool. Inputs are", + "converted to the current ratio.", + "0. `[w]` Stake pool", + "1. `[]` Stake pool withdraw authority", + "2. `[w]` Reserve stake account, to deposit SOL", + "3. `[s]` Account providing the lamports to be deposited into the pool", + "4. `[w]` User account to receive pool tokens", + "5. `[w]` Account to receive fee tokens", + "6. `[w]` Account to receive a portion of fee as referral fees", + "7. `[w]` Pool token mint account", + "8. `[]` System program account", + "9. `[]` Token program id", + "10. `[s]` (Optional) Stake pool sol deposit authority." + ], + "accounts": [ + { + "name": "stakePool", + "isMut": true, + "isSigner": false, + "docs": ["Stake pool"] + }, + { + "name": "withdrawAuthority", + "isMut": false, + "isSigner": false, + "docs": ["Stake pool withdraw authority"] + }, + { + "name": "reserveStake", + "isMut": true, + "isSigner": false, + "docs": ["Reserve stake account, to deposit SOL"] + }, + { + "name": "payer", + "isMut": true, + "isSigner": true, + "docs": [ + "Account providing the lamports to be deposited into the pool" + ] + }, + { + "name": "userPoolTokenAccount", + "isMut": true, + "isSigner": false, + "docs": ["User account to receive pool tokens"] + }, + { + "name": "managerFeeAccount", + "isMut": true, + "isSigner": false, + "docs": ["Account to receive fee tokens"] + }, + { + "name": "referralPoolAccount", + "isMut": true, + "isSigner": false, + "docs": ["Account to receive a portion of fee as referral fees"] + }, + { + "name": "poolMint", + "isMut": true, + "isSigner": false, + "docs": ["Pool token mint account"] + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false, + "docs": ["System program account"] + }, + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false, + "docs": ["Token program id"] + }, + { + "name": "depositAuthority", + "isMut": false, + "isSigner": true, + "isOptional": true, + "docs": ["(Optional) Stake pool sol deposit authority."] + } + ], + "args": [ + { + "name": "args", + "type": "u64" + } + ], + "discriminant": { + "type": "u8", + "value": 14 + } + }, + { + "name": "SetFundingAuthority", + "docs": [ + "(Manager only) Update SOL deposit, stake deposit, or SOL withdrawal", + "authority.", + "0. `[w]` Stake pool", + "1. `[s]` Manager", + "2. '[]` New authority pubkey or none" + ], + "accounts": [ + { + "name": "stakePool", + "isMut": true, + "isSigner": false, + "docs": ["Stake pool"] + }, + { + "name": "manager", + "isMut": false, + "isSigner": true, + "docs": ["Manager"] + }, + { + "name": "newAuthorityPubkey", + "isMut": false, + "isSigner": false, + "docs": ["New authority pubkey"] + } + ], + "args": [ + { + "name": "fundingType", + "type": { + "defined": "FundingType" + } + } + ], + "discriminant": { + "type": "u8", + "value": 15 + } + }, + { + "name": "WithdrawSol", + "docs": [ + "Withdraw SOL directly from the pool's reserve account. Fails if the", + "reserve does not have enough SOL.", + "0. `[w]` Stake pool", + "1. `[]` Stake pool withdraw authority", + "2. `[s]` User transfer authority, for pool token account", + "3. `[w]` User account to burn pool tokens", + "4. `[w]` Reserve stake account, to withdraw SOL", + "5. `[w]` Account receiving the lamports from the reserve, must be a", + "system account", + "6. `[w]` Account to receive pool fee tokens", + "7. `[w]` Pool token mint account", + "8. '[]' Clock sysvar", + "9. '[]' Stake history sysvar", + "10. `[]` Stake program account", + "11. `[]` Token program id", + "12. `[s]` (Optional) Stake pool sol withdraw authority" + ], + "accounts": [ + { + "name": "stakePool", + "isMut": true, + "isSigner": false, + "docs": ["Stake pool"] + }, + { + "name": "withdrawAuthority", + "isMut": false, + "isSigner": false, + "docs": ["Withdraw authority"] + }, + { + "name": "userTransferAuthority", + "isMut": false, + "isSigner": true, + "docs": ["User transfer authority"] + }, + { + "name": "userPoolTokenAccount", + "isMut": true, + "isSigner": false, + "docs": ["User pool token account"] + }, + { + "name": "reserveStake", + "isMut": true, + "isSigner": false, + "docs": ["Reserve stake"] + }, + { + "name": "destinationSystemAccount", + "isMut": true, + "isSigner": false, + "docs": ["Destination system account"] + }, + { + "name": "feeAccount", + "isMut": true, + "isSigner": false, + "docs": ["Fee account"] + }, + { + "name": "poolMint", + "isMut": true, + "isSigner": false, + "docs": ["Pool mint"] + }, + { + "name": "clockSysvar", + "isMut": false, + "isSigner": false, + "docs": ["Clock sysvar"] + }, + { + "name": "stakeHistorySysvar", + "isMut": false, + "isSigner": false, + "docs": ["Stake history sysvar"] + }, + { + "name": "stakeProgram", + "isMut": false, + "isSigner": false, + "docs": ["Stake program"] + }, + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false, + "docs": ["Token program"] + }, + { + "name": "solWithdrawAuthority", + "isMut": false, + "isSigner": true, + "isOptional": true, + "docs": ["Sol withdraw authority"] + } + ], + "args": [ + { + "name": "args", + "type": "u64" + } + ], + "discriminant": { + "type": "u8", + "value": 16 + } + }, + { + "name": "CreateTokenMetadata", + "docs": [ + "Create token metadata for the stake-pool token in the", + "metaplex-token program", + "0. `[]` Stake pool", + "1. `[s]` Manager", + "2. `[]` Stake pool withdraw authority", + "3. `[]` Pool token mint account", + "4. `[s, w]` Payer for creation of token metadata account", + "5. `[w]` Token metadata account", + "6. `[]` Metadata program id", + "7. `[]` System program id" + ], + "accounts": [ + { + "name": "stakePool", + "isMut": false, + "isSigner": false + }, + { + "name": "manager", + "isMut": false, + "isSigner": true + }, + { + "name": "withdrawAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "poolMint", + "isMut": false, + "isSigner": false + }, + { + "name": "payer", + "isMut": true, + "isSigner": true + }, + { + "name": "metadataAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "metadataProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "name", + "type": "string" + }, + { + "name": "symbol", + "type": "string" + }, + { + "name": "uri", + "type": "string" + } + ], + "discriminant": { + "type": "u8", + "value": 17 + } + }, + { + "name": "UpdateTokenMetadata", + "docs": [ + "Update token metadata for the stake-pool token in the", + "metaplex-token program", + "0. `[]` Stake pool", + "1. `[s]` Manager", + "2. `[]` Stake pool withdraw authority", + "3. `[w]` Token metadata account", + "4. `[]` Metadata program id" + ], + "accounts": [ + { + "name": "stakePool", + "isMut": false, + "isSigner": false + }, + { + "name": "manager", + "isMut": false, + "isSigner": true + }, + { + "name": "withdrawAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "metadataAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "metadataProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "name", + "type": "string" + }, + { + "name": "symbol", + "type": "string" + }, + { + "name": "uri", + "type": "string" + } + ], + "discriminant": { + "type": "u8", + "value": 18 + } + }, + { + "name": "IncreaseAdditionalValidatorStake", + "docs": [ + "(Staker only) Increase stake on a validator again in an epoch.", + "Works regardless if the transient stake account exists.", + "Internally, this instruction splits reserve stake into an ephemeral", + "stake account, activates it, then merges or splits it into the", + "transient stake account delegated to the appropriate validator.", + "`UpdateValidatorListBalance` will do the work of merging once it's", + "ready.", + "The minimum amount to move is rent-exemption plus", + "`max(crate::MINIMUM_ACTIVE_STAKE,", + "solana_program::stake::tools::get_minimum_delegation())`.", + "0. `[]` Stake pool", + "1. `[s]` Stake pool staker", + "2. `[]` Stake pool withdraw authority", + "3. `[w]` Validator list", + "4. `[w]` Stake pool reserve stake", + "5. `[w]` Uninitialized ephemeral stake account to receive stake", + "6. `[w]` Transient stake account", + "7. `[]` Validator stake account", + "8. `[]` Validator vote account to delegate to", + "9. '[]' Clock sysvar", + "10. `[]` Stake History sysvar", + "11. `[]` Stake Config sysvar", + "12. `[]` System program", + "13. `[]` Stake program", + "User data: amount of lamports to increase on the given validator.", + "The actual amount split into the transient stake account is:", + "`lamports + stake_rent_exemption`.", + "The rent-exemption of the stake account is withdrawn back to the", + "reserve after it is merged." + ], + "accounts": [ + { + "name": "stakePool", + "isMut": false, + "isSigner": false + }, + { + "name": "staker", + "isMut": false, + "isSigner": true + }, + { + "name": "withdrawAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "validatorList", + "isMut": true, + "isSigner": false + }, + { + "name": "reserveStake", + "isMut": true, + "isSigner": false + }, + { + "name": "ephemeralStake", + "isMut": true, + "isSigner": false + }, + { + "name": "transientStake", + "isMut": true, + "isSigner": false + }, + { + "name": "validatorStake", + "isMut": false, + "isSigner": false + }, + { + "name": "validatorVote", + "isMut": false, + "isSigner": false + }, + { + "name": "clockSysvar", + "isMut": false, + "isSigner": false + }, + { + "name": "stakeHistorySysvar", + "isMut": false, + "isSigner": false + }, + { + "name": "stakeConfigSysvar", + "isMut": false, + "isSigner": false + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "stakeProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "lamports", + "type": "u64" + }, + { + "name": "transientStakeSeed", + "type": "u64" + }, + { + "name": "ephemeralStakeSeed", + "type": "u64" + } + ], + "discriminant": { + "type": "u8", + "value": 19 + } + }, + { + "name": "DecreaseAdditionalValidatorStake", + "docs": [ + "(Staker only) Decrease active stake again from a validator, eventually", + "moving it to the reserve", + "Works regardless if the transient stake account already exists.", + "Internally, this instruction:", + "* withdraws rent-exempt reserve lamports from the reserve into the", + "ephemeral stake", + "* splits a validator stake account into an ephemeral stake account", + "* deactivates the ephemeral account", + "* merges or splits the ephemeral account into the transient stake", + "account delegated to the appropriate validator", + "The amount of lamports to move must be at least", + "`max(crate::MINIMUM_ACTIVE_STAKE,", + "solana_program::stake::tools::get_minimum_delegation())`.", + "0. `[]` Stake pool", + "1. `[s]` Stake pool staker", + "2. `[]` Stake pool withdraw authority", + "3. `[w]` Validator list", + "4. `[w]` Reserve stake account, to fund rent exempt reserve", + "5. `[w]` Canonical stake account to split from", + "6. `[w]` Uninitialized ephemeral stake account to receive stake", + "7. `[w]` Transient stake account", + "8. `[]` Clock sysvar", + "9. '[]' Stake history sysvar", + "10. `[]` System program", + "11. `[]` Stake program" + ], + "accounts": [ + { + "name": "stakePool", + "isMut": false, + "isSigner": false + }, + { + "name": "staker", + "isMut": false, + "isSigner": true + }, + { + "name": "withdrawAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "validatorList", + "isMut": true, + "isSigner": false + }, + { + "name": "reserveStake", + "isMut": true, + "isSigner": false + }, + { + "name": "canonicalStake", + "isMut": true, + "isSigner": false + }, + { + "name": "ephemeralStake", + "isMut": true, + "isSigner": false + }, + { + "name": "transientStake", + "isMut": true, + "isSigner": false + }, + { + "name": "clockSysvar", + "isMut": false, + "isSigner": false + }, + { + "name": "stakeHistorySysvar", + "isMut": false, + "isSigner": false + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "stakeProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "lamports", + "type": "u64" + }, + { + "name": "transientStakeSeed", + "type": "u64" + }, + { + "name": "ephemeralStakeSeed", + "type": "u64" + } + ], + "discriminant": { + "type": "u8", + "value": 20 + } + }, + { + "name": "DecreaseValidatorStakeWithReserve", + "docs": [ + "(Staker only) Decrease active stake on a validator, eventually moving it", + "to the reserve", + "Internally, this instruction:", + "* withdraws enough lamports to make the transient account rent-exempt", + "* splits from a validator stake account into a transient stake account", + "* deactivates the transient stake account", + "In order to rebalance the pool without taking custody, the staker needs", + "a way of reducing the stake on a stake account. This instruction splits", + "some amount of stake, up to the total activated stake, from the", + "canonical validator stake account, into its \"transient\" stake", + "account.", + "The instruction only succeeds if the transient stake account does not", + "exist. The amount of lamports to move must be at least rent-exemption", + "plus `max(crate::MINIMUM_ACTIVE_STAKE,", + "solana_program::stake::tools::get_minimum_delegation())`.", + "0. `[]` Stake pool", + "1. `[s]` Stake pool staker", + "2. `[]` Stake pool withdraw authority", + "3. `[w]` Validator list", + "4. `[w]` Reserve stake account, to fund rent exempt reserve", + "5. `[w]` Canonical stake account to split from", + "6. `[w]` Transient stake account to receive split", + "7. `[]` Clock sysvar", + "8. '[]' Stake history sysvar", + "9. `[]` System program", + "10. `[]` Stake program" + ], + "accounts": [ + { + "name": "stakePool", + "isMut": false, + "isSigner": false + }, + { + "name": "staker", + "isMut": false, + "isSigner": true + }, + { + "name": "withdrawAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "validatorList", + "isMut": true, + "isSigner": false + }, + { + "name": "reserveStake", + "isMut": true, + "isSigner": false + }, + { + "name": "canonicalStake", + "isMut": true, + "isSigner": false + }, + { + "name": "transientStake", + "isMut": true, + "isSigner": false + }, + { + "name": "clockSysvar", + "isMut": false, + "isSigner": false + }, + { + "name": "stakeHistorySysvar", + "isMut": false, + "isSigner": false + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "stakeProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "lamports", + "type": "u64" + }, + { + "name": "transientStakeSeed", + "type": "u64" + } + ], + "discriminant": { + "type": "u8", + "value": 21 + } + }, + { + "name": "Redelegate", + "docs": [ + "(Staker only) Redelegate active stake on a validator, eventually moving", + "it to another", + "Internally, this instruction splits a validator stake account into its", + "corresponding transient stake account, redelegates it to an ephemeral", + "stake account, then merges that stake into the destination transient", + "stake account.", + "In order to rebalance the pool without taking custody, the staker needs", + "a way of reducing the stake on a stake account. This instruction splits", + "some amount of stake, up to the total activated stake, from the", + "canonical validator stake account, into its \"transient\" stake", + "account.", + "The instruction only succeeds if the source transient stake account and", + "ephemeral stake account do not exist.", + "The amount of lamports to move must be at least rent-exemption plus the", + "minimum delegation amount. Rent-exemption plus minimum delegation", + "is required for the destination ephemeral stake account.", + "The rent-exemption for the source transient account comes from the stake", + "pool reserve, if needed.", + "The amount that arrives at the destination validator in the end is", + "`redelegate_lamports - rent_exemption` if the destination transient", + "account does *not* exist, and `redelegate_lamports` if the destination", + "transient account already exists. The `rent_exemption` is not activated", + "when creating the destination transient stake account, but if it already", + "exists, then the full amount is delegated.", + "0. `[]` Stake pool", + "1. `[s]` Stake pool staker", + "2. `[]` Stake pool withdraw authority", + "3. `[w]` Validator list", + "4. `[w]` Reserve stake account, to withdraw rent exempt reserve", + "5. `[w]` Source canonical stake account to split from", + "6. `[w]` Source transient stake account to receive split and be", + "redelegated", + "7. `[w]` Uninitialized ephemeral stake account to receive redelegation", + "8. `[w]` Destination transient stake account to receive ephemeral stake", + "by merge", + "9. `[]` Destination stake account to receive transient stake after", + "activation", + "10. `[]` Destination validator vote account", + "11. `[]` Clock sysvar", + "12. `[]` Stake History sysvar", + "13. `[]` Stake Config sysvar", + "14. `[]` System program", + "15. `[]` Stake program" + ], + "accounts": [ + { + "name": "stakePool", + "isMut": false, + "isSigner": false + }, + { + "name": "staker", + "isMut": false, + "isSigner": true + }, + { + "name": "withdrawAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "validatorList", + "isMut": true, + "isSigner": false + }, + { + "name": "reserveStake", + "isMut": true, + "isSigner": false + }, + { + "name": "sourceCanonicalStake", + "isMut": true, + "isSigner": false + }, + { + "name": "sourceTransientStake", + "isMut": true, + "isSigner": false + }, + { + "name": "ephemeralStake", + "isMut": true, + "isSigner": false + }, + { + "name": "destinationTransientStake", + "isMut": true, + "isSigner": false + }, + { + "name": "destinationStake", + "isMut": false, + "isSigner": false + }, + { + "name": "destinationVote", + "isMut": false, + "isSigner": false + }, + { + "name": "clockSysvar", + "isMut": false, + "isSigner": false + }, + { + "name": "stakeHistorySysvar", + "isMut": false, + "isSigner": false + }, + { + "name": "stakeConfigSysvar", + "isMut": false, + "isSigner": false + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "stakeProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "lamports", + "type": "u64" + }, + { + "name": "sourceTransientStakeSeed", + "type": "u64" + }, + { + "name": "ephemeralStakeSeed", + "type": "u64" + }, + { + "name": "destinationTransientStakeSeed", + "type": "u64" + } + ], + "discriminant": { + "type": "u8", + "value": 22 + } + }, + { + "name": "DepositStakeWithSlippage", + "docs": [ + "Deposit some stake into the pool, with a specified slippage", + "constraint. The output is a \"pool\" token representing ownership", + "into the pool. Inputs are converted at the current ratio.", + "0. `[w]` Stake pool", + "1. `[w]` Validator stake list storage account", + "2. `[s]/[]` Stake pool deposit authority", + "3. `[]` Stake pool withdraw authority", + "4. `[w]` Stake account to join the pool (withdraw authority for the", + "stake account should be first set to the stake pool deposit", + "authority)", + "5. `[w]` Validator stake account for the stake account to be merged", + "with", + "6. `[w]` Reserve stake account, to withdraw rent exempt reserve", + "7. `[w]` User account to receive pool tokens", + "8. `[w]` Account to receive pool fee tokens", + "9. `[w]` Account to receive a portion of pool fee tokens as referral", + "fees", + "10. `[w]` Pool token mint account", + "11. '[]' Sysvar clock account", + "12. '[]' Sysvar stake history account", + "13. `[]` Pool token program id,", + "14. `[]` Stake program id," + ], + "accounts": [ + { + "name": "stakePool", + "isMut": true, + "isSigner": false + }, + { + "name": "validatorList", + "isMut": true, + "isSigner": false + }, + { + "name": "depositAuthority", + "isMut": false, + "isSigner": false, + "isOptionalSigner": true + }, + { + "name": "withdrawAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "stakeToMerge", + "isMut": true, + "isSigner": false + }, + { + "name": "validatorStakeAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "reserveStake", + "isMut": true, + "isSigner": false + }, + { + "name": "userPoolTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "feeAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "referralFeeAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "poolMint", + "isMut": true, + "isSigner": false + }, + { + "name": "clockSysvar", + "isMut": false, + "isSigner": false + }, + { + "name": "stakeHistorySysvar", + "isMut": false, + "isSigner": false + }, + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "stakeProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "minimumPoolTokensOut", + "type": "u64" + } + ], + "discriminant": { + "type": "u8", + "value": 23 + } + }, + { + "name": "WithdrawStakeWithSlippage", + "docs": [ + "Withdraw the token from the pool at the current ratio, specifying a", + "minimum expected output lamport amount.", + "Succeeds if the stake account has enough SOL to cover the desired", + "amount of pool tokens, and if the withdrawal keeps the total", + "staked amount above the minimum of rent-exempt amount plus `max(", + "crate::MINIMUM_ACTIVE_STAKE,", + "solana_program::stake::tools::get_minimum_delegation()", + ")`.", + "0. `[w]` Stake pool", + "1. `[w]` Validator stake list storage account", + "2. `[]` Stake pool withdraw authority", + "3. `[w]` Validator or reserve stake account to split", + "4. `[w]` Uninitialized stake account to receive withdrawal", + "5. `[]` User account to set as a new withdraw authority", + "6. `[s]` User transfer authority, for pool token account", + "7. `[w]` User account with pool tokens to burn from", + "8. `[w]` Account to receive pool fee tokens", + "9. `[w]` Pool token mint account", + "10. `[]` Sysvar clock account (required)", + "11. `[]` Pool token program id", + "12. `[]` Stake program id,", + "User data: amount of pool tokens to withdraw" + ], + "accounts": [ + { + "name": "stakePool", + "isMut": true, + "isSigner": false + }, + { + "name": "validatorList", + "isMut": true, + "isSigner": false + }, + { + "name": "withdrawAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "sourceStakeAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "destinationStakeAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "newWithdrawAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "userTransferAuthority", + "isMut": false, + "isSigner": true + }, + { + "name": "userPoolTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "feeAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "poolMint", + "isMut": true, + "isSigner": false + }, + { + "name": "clockSysvar", + "isMut": false, + "isSigner": false + }, + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "stakeProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "poolTokensIn", + "type": "u64" + }, + { + "name": "minimumLamportsOut", + "type": "u64" + } + ], + "discriminant": { + "type": "u8", + "value": 24 + } + }, + { + "name": "DepositSolWithSlippage", + "docs": [ + "Deposit SOL directly into the pool's reserve account, with a", + "specified slippage constraint. The output is a \"pool\" token", + "representing ownership into the pool. Inputs are converted at the", + "current ratio.", + "0. `[w]` Stake pool", + "1. `[]` Stake pool withdraw authority", + "2. `[w]` Reserve stake account, to deposit SOL", + "3. `[s]` Account providing the lamports to be deposited into the pool", + "4. `[w]` User account to receive pool tokens", + "5. `[w]` Account to receive fee tokens", + "6. `[w]` Account to receive a portion of fee as referral fees", + "7. `[w]` Pool token mint account", + "8. `[]` System program account", + "9. `[]` Token program id", + "10. `[s]` (Optional) Stake pool sol deposit authority." + ], + "accounts": [ + { + "name": "stakePool", + "isMut": true, + "isSigner": false, + "docs": ["Stake pool"] + }, + { + "name": "withdrawAuthority", + "isMut": false, + "isSigner": false, + "docs": ["Stake pool withdraw authority"] + }, + { + "name": "reserveStake", + "isMut": true, + "isSigner": false, + "docs": ["Reserve stake"] + }, + { + "name": "payer", + "isMut": false, + "isSigner": true, + "docs": ["Payer"] + }, + { + "name": "userPoolTokenAccount", + "isMut": true, + "isSigner": false, + "docs": ["User pool token account"] + }, + { + "name": "feeAccount", + "isMut": true, + "isSigner": false, + "docs": ["Fee account"] + }, + { + "name": "referralFeeAccount", + "isMut": true, + "isSigner": false, + "docs": ["Referral fee account"] + }, + { + "name": "poolMint", + "isMut": true, + "isSigner": false, + "docs": ["Pool mint"] + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false, + "docs": ["System program"] + }, + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false, + "docs": ["Token program"] + }, + { + "name": "solDepositAuthority", + "isMut": false, + "isSigner": false, + "isOptionalSigner": true, + "docs": ["Stake pool sol deposit authority"] + } + ], + "args": [ + { + "name": "lamportsIn", + "type": "u64" + }, + { + "name": "minimumPoolTokensOut", + "type": "u64" + } + ], + "discriminant": { + "type": "u8", + "value": 25 + } + }, + { + "name": "WithdrawSolWithSlippage", + "docs": [ + "Withdraw SOL directly from the pool's reserve account. Fails if the", + "reserve does not have enough SOL or if the slippage constraint is not", + "met.", + "0. `[w]` Stake pool", + "1. `[]` Stake pool withdraw authority", + "2. `[s]` User transfer authority, for pool token account", + "3. `[w]` User account to burn pool tokens", + "4. `[w]` Reserve stake account, to withdraw SOL", + "5. `[w]` Account receiving the lamports from the reserve, must be a", + "system account", + "6. `[w]` Account to receive pool fee tokens", + "7. `[w]` Pool token mint account", + "8. '[]' Clock sysvar", + "9. '[]' Stake history sysvar", + "10. `[]` Stake program account", + "11. `[]` Token program id", + "12. `[s]` (Optional) Stake pool sol withdraw authority" + ], + "accounts": [ + { + "name": "stakePool", + "isMut": true, + "isSigner": false, + "docs": ["Stake pool"] + }, + { + "name": "withdrawAuthority", + "isMut": false, + "isSigner": false, + "docs": ["Stake pool withdraw authority"] + }, + { + "name": "userTransferAuthority", + "isMut": false, + "isSigner": true, + "docs": ["User transfer authority"] + }, + { + "name": "userPoolTokenAccount", + "isMut": true, + "isSigner": false, + "docs": ["User pool token account"] + }, + { + "name": "reserveStake", + "isMut": true, + "isSigner": false, + "docs": ["Reserve stake"] + }, + { + "name": "destinationSystemAccount", + "isMut": true, + "isSigner": false, + "docs": ["Destination system account"] + }, + { + "name": "feeAccount", + "isMut": true, + "isSigner": false, + "docs": ["Fee account"] + }, + { + "name": "poolMint", + "isMut": true, + "isSigner": false, + "docs": ["Pool mint"] + }, + { + "name": "clockSysvar", + "isMut": false, + "isSigner": false, + "docs": ["Clock sysvar"] + }, + { + "name": "stakeHistorySysvar", + "isMut": false, + "isSigner": false, + "docs": ["Stake history sysvar"] + }, + { + "name": "stakeProgram", + "isMut": false, + "isSigner": false, + "docs": ["Stake program"] + }, + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false, + "docs": ["Token program"] + }, + { + "name": "solWithdrawAuthority", + "isMut": false, + "isSigner": false, + "isOptionalSigner": true, + "docs": ["Stake pool sol withdraw authority"] + } + ], + "args": [ + { + "name": "poolTokensIn", + "type": "u64" + }, + { + "name": "minimumLamportsOut", + "type": "u64" + } + ], + "discriminant": { + "type": "u8", + "value": 26 + } + } + ], + "accounts": [ + { + "name": "StakePool", + "type": { + "kind": "struct", + "fields": [ + { + "name": "accountType", + "type": { + "defined": "AccountType" + }, + "docs": ["Account type, must be `StakePool` currently"] + }, + { + "name": "manager", + "type": "publicKey", + "docs": [ + "Manager authority, allows for updating the staker, manager, and fee", + "account" + ] + }, + { + "name": "staker", + "type": "publicKey", + "docs": [ + "Staker authority, allows for adding and removing validators, and", + "managing stake distribution" + ] + }, + { + "name": "stakeDepositAuthority", + "type": "publicKey", + "docs": [ + "Stake deposit authority", + "If a depositor pubkey is specified on initialization, then deposits must", + "be signed by this authority. If no deposit authority is specified,", + "then the stake pool will default to the result of:", + "`Pubkey::find_program_address(", + "&[&stake_pool_address.as_ref(), b\"deposit\"],", + "program_id,", + ")`" + ] + }, + { + "name": "stakeWithdrawBumpSeed", + "type": "u8", + "docs": [ + "Stake withdrawal authority bump seed", + "for `create_program_address(&[state::StakePool account, \"withdrawal\"])`" + ] + }, + { + "name": "validatorList", + "type": "publicKey", + "docs": ["Validator stake list storage account"] + }, + { + "name": "reserveStake", + "type": "publicKey", + "docs": ["Reserve stake account, holds deactivated stake"] + }, + { + "name": "poolMint", + "type": "publicKey", + "docs": ["Pool Mint"] + }, + { + "name": "managerFeeAccount", + "type": "publicKey", + "docs": ["Manager fee account"] + }, + { + "name": "tokenProgramId", + "type": "publicKey", + "docs": ["Pool token program id"] + }, + { + "name": "totalLamports", + "type": "u64", + "docs": [ + "Total stake under management.", + "Note that if `last_update_epoch` does not match the current epoch then", + "this field may not be accurate" + ] + }, + { + "name": "poolTokenSupply", + "type": "u64", + "docs": [ + "Total supply of pool tokens (should always match the supply in the Pool", + "Mint)" + ] + }, + { + "name": "lastUpdateEpoch", + "type": "u64", + "docs": ["Last epoch the `total_lamports` field was updated"] + }, + { + "name": "lockup", + "type": { + "defined": "Lockup" + }, + "docs": ["Lockup that all stakes in the pool must have"] + }, + { + "name": "epochFee", + "type": { + "defined": "Fee" + }, + "docs": ["Fee taken as a proportion of rewards each epoch"] + }, + { + "name": "nextEpochFee", + "type": { + "defined": "FutureEpoch" + }, + "docs": ["Fee for next epoch"] + }, + { + "name": "preferredDepositValidatorVoteAddress", + "type": { + "option": "publicKey" + }, + "docs": ["Preferred deposit validator vote account pubkey"] + }, + { + "name": "preferredWithdrawValidatorVoteAddress", + "type": { + "option": "publicKey" + }, + "docs": ["Preferred withdraw validator vote account pubkey"] + }, + { + "name": "stakeDepositFee", + "type": { + "defined": "Fee" + }, + "docs": ["Fee assessed on stake deposits"] + }, + { + "name": "stakeWithdrawalFee", + "type": { + "defined": "Fee" + }, + "docs": ["Fee assessed on withdrawals"] + }, + { + "name": "nextStakeWithdrawalFee", + "type": { + "defined": "FutureEpoch" + }, + "docs": [ + "Future stake withdrawal fee, to be set for the following epoch" + ] + }, + { + "name": "stakeReferralFee", + "type": "u8", + "docs": [ + "Fees paid out to referrers on referred stake deposits.", + "Expressed as a percentage (0 - 100) of deposit fees.", + "i.e. `stake_deposit_fee`% of stake deposited is collected as deposit", + "fees for every deposit and `stake_referral_fee`% of the collected", + "stake deposit fees is paid out to the referrer" + ] + }, + { + "name": "solDepositAuthority", + "type": { + "option": "publicKey" + }, + "docs": [ + "Toggles whether the `DepositSol` instruction requires a signature from", + "this `sol_deposit_authority`" + ] + }, + { + "name": "solDepositFee", + "type": { + "defined": "Fee" + }, + "docs": ["Fee assessed on SOL deposits"] + }, + { + "name": "solReferralFee", + "type": "u8", + "docs": [ + "Fees paid out to referrers on referred SOL deposits.", + "Expressed as a percentage (0 - 100) of SOL deposit fees.", + "i.e. `sol_deposit_fee`% of SOL deposited is collected as deposit fees", + "for every deposit and `sol_referral_fee`% of the collected SOL", + "deposit fees is paid out to the referrer" + ] + }, + { + "name": "solWithdrawAuthority", + "type": { + "option": "publicKey" + }, + "docs": [ + "Toggles whether the `WithdrawSol` instruction requires a signature from", + "the `deposit_authority`" + ] + }, + { + "name": "solWithdrawalFee", + "type": { + "defined": "Fee" + }, + "docs": ["Fee assessed on SOL withdrawals"] + }, + { + "name": "nextSolWithdrawalFee", + "type": { + "defined": "FutureEpoch" + }, + "docs": [ + "Future SOL withdrawal fee, to be set for the following epoch" + ] + }, + { + "name": "lastEpochPoolTokenSupply", + "type": "u64", + "docs": [ + "Last epoch's total pool tokens, used only for APR estimation" + ] + }, + { + "name": "lastEpochTotalLamports", + "type": "u64", + "docs": [ + "Last epoch's total lamports, used only for APR estimation" + ] + } + ] + }, + "docs": ["Initialized program details."] + }, + { + "name": "ValidatorList", + "type": { + "kind": "struct", + "fields": [ + { + "name": "accountType", + "type": { + "defined": "AccountType" + }, + "docs": ["Account type, must be `ValidatorList` currently"] + }, + { + "name": "maxValidators", + "type": "u32", + "docs": ["Maximum allowable number of validators"] + }, + { + "name": "validators", + "type": { + "vec": { + "defined": "ValidatorStakeInfo" + } + }, + "docs": ["List of stake info for each validator in the pool"] + } + ] + }, + "docs": ["Storage list for all validator stake accounts in the pool."] + } + ], + "types": [ + { + "name": "CreateMetadataAccountArgsV3", + "type": { + "kind": "struct", + "fields": [ + { + "name": "data", + "type": { + "defined": "DataV2" + }, + "docs": ["Note that unique metadata is disabled for now."] + }, + { + "name": "isMutable", + "type": "bool", + "docs": [ + "Whether you want your metadata to be changeable in the future." + ] + }, + { + "name": "collectionDetails", + "type": { + "option": "u8" + }, + "docs": ["UNUSED If this is a collection parent NFT."] + } + ] + } + }, + { + "name": "UpdateMetadataAccountArgsV2", + "type": { + "kind": "struct", + "fields": [ + { + "name": "data", + "type": { + "option": { + "defined": "DataV2" + } + } + }, + { + "name": "updateAuthority", + "type": { + "option": "publicKey" + } + }, + { + "name": "primarySaleHappened", + "type": { + "option": "bool" + } + }, + { + "name": "isMutable", + "type": { + "option": "bool" + } + } + ] + } + }, + { + "name": "DataV2", + "type": { + "kind": "struct", + "fields": [ + { + "name": "name", + "type": "string", + "docs": ["The name of the asset"] + }, + { + "name": "symbol", + "type": "string", + "docs": ["The symbol for the asset"] + }, + { + "name": "uri", + "type": "string", + "docs": ["URI pointing to JSON representing the asset"] + }, + { + "name": "sellerFeeBasisPoints", + "type": "u16", + "docs": [ + "Royalty basis points that goes to creators in secondary sales", + "(0-10000)" + ] + }, + { + "name": "creators", + "type": { + "option": "u8" + }, + "docs": ["UNUSED Array of creators, optional"] + }, + { + "name": "collection", + "type": { + "option": "u8" + }, + "docs": ["UNUSED Collection"] + }, + { + "name": "uses", + "type": { + "option": "u8" + }, + "docs": ["UNUSED Uses"] + } + ] + } + }, + { + "name": "PodStakeStatus", + "type": { + "kind": "struct", + "fields": [ + { + "name": "status", + "type": "u8", + "docs": ["Pod stake status"] + } + ] + }, + "docs": [ + "Wrapper struct that can be `Pod`, containing a byte that *should* be a valid", + "`StakeStatus` underneath." + ] + }, + { + "name": "Lockup", + "type": { + "kind": "struct", + "fields": [ + { + "name": "unixTimestamp", + "type": "i64", + "docs": [ + "UnixTimestamp at which this stake will allow withdrawal, unless the", + "transaction is signed by the custodian" + ] + }, + { + "name": "epoch", + "type": "u64", + "docs": [ + "epoch height at which this stake will allow withdrawal, unless the", + "transaction is signed by the custodian" + ] + }, + { + "name": "custodian", + "type": "publicKey", + "docs": [ + "custodian signature on a transaction exempts the operation from", + "lockup constraints" + ] + } + ] + } + }, + { + "name": "ValidatorStakeInfo", + "type": { + "kind": "struct", + "fields": [ + { + "name": "activeStakeLamports", + "type": "u64", + "attrs": ["idl-type"], + "docs": [ + "Amount of lamports on the validator stake account, including rent", + "Note that if `last_update_epoch` does not match the current epoch then", + "this field may not be accurate" + ] + }, + { + "name": "transientStakeLamports", + "type": "u64", + "attrs": ["idl-type"], + "docs": [ + "Amount of transient stake delegated to this validator", + "Note that if `last_update_epoch` does not match the current epoch then", + "this field may not be accurate" + ] + }, + { + "name": "lastUpdateEpoch", + "type": "u64", + "attrs": ["idl-type"], + "docs": [ + "Last epoch the active and transient stake lamports fields were updated" + ] + }, + { + "name": "transientSeedSuffix", + "type": "u64", + "attrs": ["idl-type"], + "docs": [ + "Transient account seed suffix, used to derive the transient stake", + "account address" + ] + }, + { + "name": "unused", + "type": "u32", + "attrs": ["idl-type"], + "docs": [ + "Unused space, initially meant to specify the end of seed suffixes" + ] + }, + { + "name": "validatorSeedSuffix", + "type": "u32", + "attrs": ["idl-type"], + "docs": ["Validator account seed suffix"] + }, + { + "name": "status", + "type": { + "defined": "PodStakeStatus" + }, + "docs": ["Status of the validator stake account"] + }, + { + "name": "voteAccountAddress", + "type": "publicKey", + "docs": ["Validator vote account address"] + } + ] + }, + "docs": [ + "Information about a validator in the pool", + "NOTE: ORDER IS VERY IMPORTANT HERE, PLEASE DO NOT RE-ORDER THE FIELDS UNLESS", + "THERE'S AN EXTREMELY GOOD REASON.", + "To save on BPF instructions, the serialized bytes are reinterpreted with a", + "`bytemuck` transmute, which means that this structure cannot have any", + "undeclared alignment-padding in its representation." + ] + }, + { + "name": "Fee", + "type": { + "kind": "struct", + "fields": [ + { + "name": "denominator", + "type": "u64", + "docs": ["denominator of the fee ratio"] + }, + { + "name": "numerator", + "type": "u64", + "docs": ["numerator of the fee ratio"] + } + ] + }, + "docs": [ + "Fee rate as a ratio, minted on `UpdateStakePoolBalance` as a proportion of", + "the rewards", + "If either the numerator or the denominator is 0, the fee is considered to be", + "0" + ] + }, + { + "name": "PreferredValidatorType", + "type": { + "kind": "enum", + "variants": [ + { + "name": "Deposit" + }, + { + "name": "Withdraw" + } + ] + }, + "docs": [ + "Defines which validator vote account is set during the", + "`SetPreferredValidator` instruction" + ] + }, + { + "name": "FundingType", + "type": { + "kind": "enum", + "variants": [ + { + "name": "StakeDeposit" + }, + { + "name": "SolDeposit" + }, + { + "name": "SolWithdraw" + } + ] + }, + "docs": [ + "Defines which authority to update in the `SetFundingAuthority`", + "instruction" + ] + }, + { + "name": "AccountType", + "type": { + "kind": "enum", + "variants": [ + { + "name": "Uninitialized" + }, + { + "name": "StakePool" + }, + { + "name": "ValidatorList" + } + ] + }, + "docs": ["Enum representing the account type managed by the program"] + }, + { + "name": "StakeStatus", + "type": { + "kind": "enum", + "variants": [ + { + "name": "Active" + }, + { + "name": "DeactivatingTransient" + }, + { + "name": "ReadyForRemoval" + }, + { + "name": "DeactivatingValidator" + }, + { + "name": "DeactivatingAll" + } + ] + }, + "docs": [ + "Status of the stake account in the validator list, for accounting" + ] + }, + { + "name": "FutureEpoch", + "type": { + "kind": "enum", + "variants": [ + { + "name": "None" + }, + { + "name": "One", + "fields": [ + { + "defined": "Fee" + } + ] + }, + { + "name": "Two", + "fields": [ + { + "defined": "Fee" + } + ] + } + ] + }, + "docs": [ + "Wrapper type that \"counts down\" epochs, which is Borsh-compatible with the", + "native `Option`" + ] + }, + { + "name": "FeeType", + "type": { + "kind": "enum", + "variants": [ + { + "name": "SolReferral", + "fields": ["u8"] + }, + { + "name": "StakeReferral", + "fields": ["u8"] + }, + { + "name": "Epoch", + "fields": [ + { + "defined": "Fee" + } + ] + }, + { + "name": "StakeWithdrawal", + "fields": [ + { + "defined": "Fee" + } + ] + }, + { + "name": "SolDeposit", + "fields": [ + { + "defined": "Fee" + } + ] + }, + { + "name": "StakeDeposit", + "fields": [ + { + "defined": "Fee" + } + ] + }, + { + "name": "SolWithdrawal", + "fields": [ + { + "defined": "Fee" + } + ] + } + ] + }, + "docs": ["The type of fees that can be set on the stake pool"] + } + ], + "errors": [ + { + "code": 0, + "name": "AlreadyInUse", + "msg": "AlreadyInUse" + }, + { + "code": 1, + "name": "InvalidProgramAddress", + "msg": "InvalidProgramAddress" + }, + { + "code": 2, + "name": "InvalidState", + "msg": "InvalidState" + }, + { + "code": 3, + "name": "CalculationFailure", + "msg": "CalculationFailure" + }, + { + "code": 4, + "name": "FeeTooHigh", + "msg": "FeeTooHigh" + }, + { + "code": 5, + "name": "WrongAccountMint", + "msg": "WrongAccountMint" + }, + { + "code": 6, + "name": "WrongManager", + "msg": "WrongManager" + }, + { + "code": 7, + "name": "SignatureMissing", + "msg": "SignatureMissing" + }, + { + "code": 8, + "name": "InvalidValidatorStakeList", + "msg": "InvalidValidatorStakeList" + }, + { + "code": 9, + "name": "InvalidFeeAccount", + "msg": "InvalidFeeAccount" + }, + { + "code": 10, + "name": "WrongPoolMint", + "msg": "WrongPoolMint" + }, + { + "code": 11, + "name": "WrongStakeStake", + "msg": "WrongStakeStake" + }, + { + "code": 12, + "name": "UserStakeNotActive", + "msg": "UserStakeNotActive" + }, + { + "code": 13, + "name": "ValidatorAlreadyAdded", + "msg": "ValidatorAlreadyAdded" + }, + { + "code": 14, + "name": "ValidatorNotFound", + "msg": "ValidatorNotFound" + }, + { + "code": 15, + "name": "InvalidStakeAccountAddress", + "msg": "InvalidStakeAccountAddress" + }, + { + "code": 16, + "name": "StakeListOutOfDate", + "msg": "StakeListOutOfDate" + }, + { + "code": 17, + "name": "StakeListAndPoolOutOfDate", + "msg": "StakeListAndPoolOutOfDate" + }, + { + "code": 18, + "name": "UnknownValidatorStakeAccount", + "msg": "UnknownValidatorStakeAccount" + }, + { + "code": 19, + "name": "WrongMintingAuthority", + "msg": "WrongMintingAuthority" + }, + { + "code": 20, + "name": "UnexpectedValidatorListAccountSize", + "msg": "UnexpectedValidatorListAccountSize" + }, + { + "code": 21, + "name": "WrongStaker", + "msg": "WrongStaker" + }, + { + "code": 22, + "name": "NonZeroPoolTokenSupply", + "msg": "NonZeroPoolTokenSupply" + }, + { + "code": 23, + "name": "StakeLamportsNotEqualToMinimum", + "msg": "StakeLamportsNotEqualToMinimum" + }, + { + "code": 24, + "name": "IncorrectDepositVoteAddress", + "msg": "IncorrectDepositVoteAddress" + }, + { + "code": 25, + "name": "IncorrectWithdrawVoteAddress", + "msg": "IncorrectWithdrawVoteAddress" + }, + { + "code": 26, + "name": "InvalidMintFreezeAuthority", + "msg": "InvalidMintFreezeAuthority" + }, + { + "code": 27, + "name": "FeeIncreaseTooHigh", + "msg": "FeeIncreaseTooHigh" + }, + { + "code": 28, + "name": "WithdrawalTooSmall", + "msg": "WithdrawalTooSmall" + }, + { + "code": 29, + "name": "DepositTooSmall", + "msg": "DepositTooSmall" + }, + { + "code": 30, + "name": "InvalidStakeDepositAuthority", + "msg": "InvalidStakeDepositAuthority" + }, + { + "code": 31, + "name": "InvalidSolDepositAuthority", + "msg": "InvalidSolDepositAuthority" + }, + { + "code": 32, + "name": "InvalidPreferredValidator", + "msg": "InvalidPreferredValidator" + }, + { + "code": 33, + "name": "TransientAccountInUse", + "msg": "TransientAccountInUse" + }, + { + "code": 34, + "name": "InvalidSolWithdrawAuthority", + "msg": "InvalidSolWithdrawAuthority" + }, + { + "code": 35, + "name": "SolWithdrawalTooLarge", + "msg": "SolWithdrawalTooLarge" + }, + { + "code": 36, + "name": "InvalidMetadataAccount", + "msg": "InvalidMetadataAccount" + }, + { + "code": 37, + "name": "UnsupportedMintExtension", + "msg": "UnsupportedMintExtension" + }, + { + "code": 38, + "name": "UnsupportedFeeAccountExtension", + "msg": "UnsupportedFeeAccountExtension" + }, + { + "code": 39, + "name": "ExceededSlippage", + "msg": "Instruction exceeds desired slippage limit" + }, + { + "code": 40, + "name": "IncorrectMintDecimals", + "msg": "IncorrectMintDecimals" + }, + { + "code": 41, + "name": "ReserveDepleted", + "msg": "ReserveDepleted" + }, + { + "code": 42, + "name": "MissingRequiredSysvar", + "msg": "Missing required sysvar account" + } + ], + "metadata": { + "origin": "shank", + "address": "SPoo1Ku8WFXoNDMHPsrGSTSG1Y47rzgn41SLUNakuHy" + } +} diff --git a/clients/spl-stake-pool/package.json b/clients/spl-stake-pool/package.json new file mode 100644 index 00000000..afcb8a4f --- /dev/null +++ b/clients/spl-stake-pool/package.json @@ -0,0 +1,60 @@ +{ + "name": "@macalinao/clients-spl-stake-pool", + "version": "0.1.0", + "description": "TypeScript client for the SPL Stake Pool program", + "type": "module", + "sideEffects": false, + "author": "Ian Macalinao ", + "homepage": "https://coda.ianm.com", + "license": "Apache-2.0", + "keywords": [ + "coda", + "solana", + "spl", + "stake-pool", + "staking", + "delegation", + "validator", + "client", + "esm", + "typescript", + "ian-macalinao" + ], + "main": "dist/index.js", + "types": "dist/index.d.ts", + "exports": { + ".": { + "import": "./dist/index.js", + "types": "./dist/index.d.ts" + } + }, + "files": [ + "dist/", + "src/" + ], + "publishConfig": { + "access": "public" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/macalinao/coda.git", + "directory": "clients/spl-stake-pool" + }, + "scripts": { + "build": "tsc", + "clean": "rm -fr dist/", + "lint": "eslint . --cache", + "codegen": "coda generate" + }, + "peerDependencies": { + "@solana/kit": "*" + }, + "devDependencies": { + "@macalinao/coda": "workspace:^", + "@macalinao/eslint-config": "catalog:", + "@macalinao/tsconfig": "catalog:", + "@solana/kit": "catalog:", + "eslint": "catalog:", + "typescript": "catalog:" + } +} diff --git a/clients/spl-stake-pool/src/generated/accounts/index.ts b/clients/spl-stake-pool/src/generated/accounts/index.ts new file mode 100644 index 00000000..c597acb0 --- /dev/null +++ b/clients/spl-stake-pool/src/generated/accounts/index.ts @@ -0,0 +1,10 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +export * from "./stakePool.js"; +export * from "./validatorList.js"; diff --git a/clients/spl-stake-pool/src/generated/accounts/stakePool.ts b/clients/spl-stake-pool/src/generated/accounts/stakePool.ts new file mode 100644 index 00000000..e9475260 --- /dev/null +++ b/clients/spl-stake-pool/src/generated/accounts/stakePool.ts @@ -0,0 +1,418 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + Account, + Address, + Codec, + Decoder, + EncodedAccount, + Encoder, + FetchAccountConfig, + FetchAccountsConfig, + MaybeAccount, + MaybeEncodedAccount, + Option, + OptionOrNullable, +} from "@solana/kit"; +import type { + Fee, + FeeArgs, + FutureEpoch, + FutureEpochArgs, + Lockup, + LockupArgs, +} from "../types/index.js"; +import { + assertAccountExists, + assertAccountsExist, + combineCodec, + decodeAccount, + fetchEncodedAccount, + fetchEncodedAccounts, + getAddressDecoder, + getAddressEncoder, + getOptionDecoder, + getOptionEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getU64Decoder, + getU64Encoder, + transformEncoder, +} from "@solana/kit"; +import { + AccountType, + getAccountTypeDecoder, + getAccountTypeEncoder, + getFeeDecoder, + getFeeEncoder, + getFutureEpochDecoder, + getFutureEpochEncoder, + getLockupDecoder, + getLockupEncoder, +} from "../types/index.js"; + +export const STAKE_POOL_ACCOUNT_TYPE = AccountType.StakePool; + +export function getStakePoolAccountTypeBytes() { + return getAccountTypeEncoder().encode(STAKE_POOL_ACCOUNT_TYPE); +} + +export interface StakePool { + /** Account type, must be `StakePool` currently */ + accountType: AccountType; + /** + * Manager authority, allows for updating the staker, manager, and fee + * account + */ + manager: Address; + /** + * Staker authority, allows for adding and removing validators, and + * managing stake distribution + */ + staker: Address; + /** + * Stake deposit authority + * If a depositor pubkey is specified on initialization, then deposits must + * be signed by this authority. If no deposit authority is specified, + * then the stake pool will default to the result of: + * `Pubkey::find_program_address( + * &[&stake_pool_address.as_ref(), b"deposit"], + * program_id, + * )` + */ + stakeDepositAuthority: Address; + /** + * Stake withdrawal authority bump seed + * for `create_program_address(&[state::StakePool account, "withdrawal"])` + */ + stakeWithdrawBumpSeed: number; + /** Validator stake list storage account */ + validatorList: Address; + /** Reserve stake account, holds deactivated stake */ + reserveStake: Address; + /** Pool Mint */ + poolMint: Address; + /** Manager fee account */ + managerFeeAccount: Address; + /** Pool token program id */ + tokenProgramId: Address; + /** + * Total stake under management. + * Note that if `last_update_epoch` does not match the current epoch then + * this field may not be accurate + */ + totalLamports: bigint; + /** + * Total supply of pool tokens (should always match the supply in the Pool + * Mint) + */ + poolTokenSupply: bigint; + /** Last epoch the `total_lamports` field was updated */ + lastUpdateEpoch: bigint; + /** Lockup that all stakes in the pool must have */ + lockup: Lockup; + /** Fee taken as a proportion of rewards each epoch */ + epochFee: Fee; + /** Fee for next epoch */ + nextEpochFee: FutureEpoch; + /** Preferred deposit validator vote account pubkey */ + preferredDepositValidatorVoteAddress: Option
; + /** Preferred withdraw validator vote account pubkey */ + preferredWithdrawValidatorVoteAddress: Option
; + /** Fee assessed on stake deposits */ + stakeDepositFee: Fee; + /** Fee assessed on withdrawals */ + stakeWithdrawalFee: Fee; + /** Future stake withdrawal fee, to be set for the following epoch */ + nextStakeWithdrawalFee: FutureEpoch; + /** + * Fees paid out to referrers on referred stake deposits. + * Expressed as a percentage (0 - 100) of deposit fees. + * i.e. `stake_deposit_fee`% of stake deposited is collected as deposit + * fees for every deposit and `stake_referral_fee`% of the collected + * stake deposit fees is paid out to the referrer + */ + stakeReferralFee: number; + /** + * Toggles whether the `DepositSol` instruction requires a signature from + * this `sol_deposit_authority` + */ + solDepositAuthority: Option
; + /** Fee assessed on SOL deposits */ + solDepositFee: Fee; + /** + * Fees paid out to referrers on referred SOL deposits. + * Expressed as a percentage (0 - 100) of SOL deposit fees. + * i.e. `sol_deposit_fee`% of SOL deposited is collected as deposit fees + * for every deposit and `sol_referral_fee`% of the collected SOL + * deposit fees is paid out to the referrer + */ + solReferralFee: number; + /** + * Toggles whether the `WithdrawSol` instruction requires a signature from + * the `deposit_authority` + */ + solWithdrawAuthority: Option
; + /** Fee assessed on SOL withdrawals */ + solWithdrawalFee: Fee; + /** Future SOL withdrawal fee, to be set for the following epoch */ + nextSolWithdrawalFee: FutureEpoch; + /** Last epoch's total pool tokens, used only for APR estimation */ + lastEpochPoolTokenSupply: bigint; + /** Last epoch's total lamports, used only for APR estimation */ + lastEpochTotalLamports: bigint; +} + +export interface StakePoolArgs { + /** + * Manager authority, allows for updating the staker, manager, and fee + * account + */ + manager: Address; + /** + * Staker authority, allows for adding and removing validators, and + * managing stake distribution + */ + staker: Address; + /** + * Stake deposit authority + * If a depositor pubkey is specified on initialization, then deposits must + * be signed by this authority. If no deposit authority is specified, + * then the stake pool will default to the result of: + * `Pubkey::find_program_address( + * &[&stake_pool_address.as_ref(), b"deposit"], + * program_id, + * )` + */ + stakeDepositAuthority: Address; + /** + * Stake withdrawal authority bump seed + * for `create_program_address(&[state::StakePool account, "withdrawal"])` + */ + stakeWithdrawBumpSeed: number; + /** Validator stake list storage account */ + validatorList: Address; + /** Reserve stake account, holds deactivated stake */ + reserveStake: Address; + /** Pool Mint */ + poolMint: Address; + /** Manager fee account */ + managerFeeAccount: Address; + /** Pool token program id */ + tokenProgramId: Address; + /** + * Total stake under management. + * Note that if `last_update_epoch` does not match the current epoch then + * this field may not be accurate + */ + totalLamports: number | bigint; + /** + * Total supply of pool tokens (should always match the supply in the Pool + * Mint) + */ + poolTokenSupply: number | bigint; + /** Last epoch the `total_lamports` field was updated */ + lastUpdateEpoch: number | bigint; + /** Lockup that all stakes in the pool must have */ + lockup: LockupArgs; + /** Fee taken as a proportion of rewards each epoch */ + epochFee: FeeArgs; + /** Fee for next epoch */ + nextEpochFee: FutureEpochArgs; + /** Preferred deposit validator vote account pubkey */ + preferredDepositValidatorVoteAddress: OptionOrNullable
; + /** Preferred withdraw validator vote account pubkey */ + preferredWithdrawValidatorVoteAddress: OptionOrNullable
; + /** Fee assessed on stake deposits */ + stakeDepositFee: FeeArgs; + /** Fee assessed on withdrawals */ + stakeWithdrawalFee: FeeArgs; + /** Future stake withdrawal fee, to be set for the following epoch */ + nextStakeWithdrawalFee: FutureEpochArgs; + /** + * Fees paid out to referrers on referred stake deposits. + * Expressed as a percentage (0 - 100) of deposit fees. + * i.e. `stake_deposit_fee`% of stake deposited is collected as deposit + * fees for every deposit and `stake_referral_fee`% of the collected + * stake deposit fees is paid out to the referrer + */ + stakeReferralFee: number; + /** + * Toggles whether the `DepositSol` instruction requires a signature from + * this `sol_deposit_authority` + */ + solDepositAuthority: OptionOrNullable
; + /** Fee assessed on SOL deposits */ + solDepositFee: FeeArgs; + /** + * Fees paid out to referrers on referred SOL deposits. + * Expressed as a percentage (0 - 100) of SOL deposit fees. + * i.e. `sol_deposit_fee`% of SOL deposited is collected as deposit fees + * for every deposit and `sol_referral_fee`% of the collected SOL + * deposit fees is paid out to the referrer + */ + solReferralFee: number; + /** + * Toggles whether the `WithdrawSol` instruction requires a signature from + * the `deposit_authority` + */ + solWithdrawAuthority: OptionOrNullable
; + /** Fee assessed on SOL withdrawals */ + solWithdrawalFee: FeeArgs; + /** Future SOL withdrawal fee, to be set for the following epoch */ + nextSolWithdrawalFee: FutureEpochArgs; + /** Last epoch's total pool tokens, used only for APR estimation */ + lastEpochPoolTokenSupply: number | bigint; + /** Last epoch's total lamports, used only for APR estimation */ + lastEpochTotalLamports: number | bigint; +} + +export function getStakePoolEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ["accountType", getAccountTypeEncoder()], + ["manager", getAddressEncoder()], + ["staker", getAddressEncoder()], + ["stakeDepositAuthority", getAddressEncoder()], + ["stakeWithdrawBumpSeed", getU8Encoder()], + ["validatorList", getAddressEncoder()], + ["reserveStake", getAddressEncoder()], + ["poolMint", getAddressEncoder()], + ["managerFeeAccount", getAddressEncoder()], + ["tokenProgramId", getAddressEncoder()], + ["totalLamports", getU64Encoder()], + ["poolTokenSupply", getU64Encoder()], + ["lastUpdateEpoch", getU64Encoder()], + ["lockup", getLockupEncoder()], + ["epochFee", getFeeEncoder()], + ["nextEpochFee", getFutureEpochEncoder()], + [ + "preferredDepositValidatorVoteAddress", + getOptionEncoder(getAddressEncoder()), + ], + [ + "preferredWithdrawValidatorVoteAddress", + getOptionEncoder(getAddressEncoder()), + ], + ["stakeDepositFee", getFeeEncoder()], + ["stakeWithdrawalFee", getFeeEncoder()], + ["nextStakeWithdrawalFee", getFutureEpochEncoder()], + ["stakeReferralFee", getU8Encoder()], + ["solDepositAuthority", getOptionEncoder(getAddressEncoder())], + ["solDepositFee", getFeeEncoder()], + ["solReferralFee", getU8Encoder()], + ["solWithdrawAuthority", getOptionEncoder(getAddressEncoder())], + ["solWithdrawalFee", getFeeEncoder()], + ["nextSolWithdrawalFee", getFutureEpochEncoder()], + ["lastEpochPoolTokenSupply", getU64Encoder()], + ["lastEpochTotalLamports", getU64Encoder()], + ]), + (value) => ({ ...value, accountType: STAKE_POOL_ACCOUNT_TYPE }), + ); +} + +export function getStakePoolDecoder(): Decoder { + return getStructDecoder([ + ["accountType", getAccountTypeDecoder()], + ["manager", getAddressDecoder()], + ["staker", getAddressDecoder()], + ["stakeDepositAuthority", getAddressDecoder()], + ["stakeWithdrawBumpSeed", getU8Decoder()], + ["validatorList", getAddressDecoder()], + ["reserveStake", getAddressDecoder()], + ["poolMint", getAddressDecoder()], + ["managerFeeAccount", getAddressDecoder()], + ["tokenProgramId", getAddressDecoder()], + ["totalLamports", getU64Decoder()], + ["poolTokenSupply", getU64Decoder()], + ["lastUpdateEpoch", getU64Decoder()], + ["lockup", getLockupDecoder()], + ["epochFee", getFeeDecoder()], + ["nextEpochFee", getFutureEpochDecoder()], + [ + "preferredDepositValidatorVoteAddress", + getOptionDecoder(getAddressDecoder()), + ], + [ + "preferredWithdrawValidatorVoteAddress", + getOptionDecoder(getAddressDecoder()), + ], + ["stakeDepositFee", getFeeDecoder()], + ["stakeWithdrawalFee", getFeeDecoder()], + ["nextStakeWithdrawalFee", getFutureEpochDecoder()], + ["stakeReferralFee", getU8Decoder()], + ["solDepositAuthority", getOptionDecoder(getAddressDecoder())], + ["solDepositFee", getFeeDecoder()], + ["solReferralFee", getU8Decoder()], + ["solWithdrawAuthority", getOptionDecoder(getAddressDecoder())], + ["solWithdrawalFee", getFeeDecoder()], + ["nextSolWithdrawalFee", getFutureEpochDecoder()], + ["lastEpochPoolTokenSupply", getU64Decoder()], + ["lastEpochTotalLamports", getU64Decoder()], + ]); +} + +export function getStakePoolCodec(): Codec { + return combineCodec(getStakePoolEncoder(), getStakePoolDecoder()); +} + +export function decodeStakePool( + encodedAccount: EncodedAccount, +): Account; +export function decodeStakePool( + encodedAccount: MaybeEncodedAccount, +): MaybeAccount; +export function decodeStakePool( + encodedAccount: EncodedAccount | MaybeEncodedAccount, +): Account | MaybeAccount { + return decodeAccount( + encodedAccount as MaybeEncodedAccount, + getStakePoolDecoder(), + ); +} + +export async function fetchStakePool( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchMaybeStakePool(rpc, address, config); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeStakePool( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchEncodedAccount(rpc, address, config); + return decodeStakePool(maybeAccount); +} + +export async function fetchAllStakePool( + rpc: Parameters[0], + addresses: Address[], + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchAllMaybeStakePool(rpc, addresses, config); + assertAccountsExist(maybeAccounts); + return maybeAccounts; +} + +export async function fetchAllMaybeStakePool( + rpc: Parameters[0], + addresses: Address[], + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); + return maybeAccounts.map((maybeAccount) => decodeStakePool(maybeAccount)); +} diff --git a/clients/spl-stake-pool/src/generated/accounts/validatorList.ts b/clients/spl-stake-pool/src/generated/accounts/validatorList.ts new file mode 100644 index 00000000..dba6c1f3 --- /dev/null +++ b/clients/spl-stake-pool/src/generated/accounts/validatorList.ts @@ -0,0 +1,151 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + Account, + Address, + Codec, + Decoder, + EncodedAccount, + Encoder, + FetchAccountConfig, + FetchAccountsConfig, + MaybeAccount, + MaybeEncodedAccount, +} from "@solana/kit"; +import type { + ValidatorStakeInfo, + ValidatorStakeInfoArgs, +} from "../types/index.js"; +import { + assertAccountExists, + assertAccountsExist, + combineCodec, + decodeAccount, + fetchEncodedAccount, + fetchEncodedAccounts, + getArrayDecoder, + getArrayEncoder, + getStructDecoder, + getStructEncoder, + getU32Decoder, + getU32Encoder, + transformEncoder, +} from "@solana/kit"; +import { + AccountType, + getAccountTypeDecoder, + getAccountTypeEncoder, + getValidatorStakeInfoDecoder, + getValidatorStakeInfoEncoder, +} from "../types/index.js"; + +export const VALIDATOR_LIST_ACCOUNT_TYPE = AccountType.ValidatorList; + +export function getValidatorListAccountTypeBytes() { + return getAccountTypeEncoder().encode(VALIDATOR_LIST_ACCOUNT_TYPE); +} + +export interface ValidatorList { + /** Account type, must be `ValidatorList` currently */ + accountType: AccountType; + /** Maximum allowable number of validators */ + maxValidators: number; + /** List of stake info for each validator in the pool */ + validators: ValidatorStakeInfo[]; +} + +export interface ValidatorListArgs { + /** Maximum allowable number of validators */ + maxValidators: number; + /** List of stake info for each validator in the pool */ + validators: ValidatorStakeInfoArgs[]; +} + +export function getValidatorListEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ["accountType", getAccountTypeEncoder()], + ["maxValidators", getU32Encoder()], + ["validators", getArrayEncoder(getValidatorStakeInfoEncoder())], + ]), + (value) => ({ ...value, accountType: VALIDATOR_LIST_ACCOUNT_TYPE }), + ); +} + +export function getValidatorListDecoder(): Decoder { + return getStructDecoder([ + ["accountType", getAccountTypeDecoder()], + ["maxValidators", getU32Decoder()], + ["validators", getArrayDecoder(getValidatorStakeInfoDecoder())], + ]); +} + +export function getValidatorListCodec(): Codec< + ValidatorListArgs, + ValidatorList +> { + return combineCodec(getValidatorListEncoder(), getValidatorListDecoder()); +} + +export function decodeValidatorList( + encodedAccount: EncodedAccount, +): Account; +export function decodeValidatorList( + encodedAccount: MaybeEncodedAccount, +): MaybeAccount; +export function decodeValidatorList( + encodedAccount: EncodedAccount | MaybeEncodedAccount, +): Account | MaybeAccount { + return decodeAccount( + encodedAccount as MaybeEncodedAccount, + getValidatorListDecoder(), + ); +} + +export async function fetchValidatorList( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchMaybeValidatorList(rpc, address, config); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeValidatorList( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchEncodedAccount(rpc, address, config); + return decodeValidatorList(maybeAccount); +} + +export async function fetchAllValidatorList( + rpc: Parameters[0], + addresses: Address[], + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchAllMaybeValidatorList( + rpc, + addresses, + config, + ); + assertAccountsExist(maybeAccounts); + return maybeAccounts; +} + +export async function fetchAllMaybeValidatorList( + rpc: Parameters[0], + addresses: Address[], + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); + return maybeAccounts.map((maybeAccount) => decodeValidatorList(maybeAccount)); +} diff --git a/clients/spl-stake-pool/src/generated/errors/index.ts b/clients/spl-stake-pool/src/generated/errors/index.ts new file mode 100644 index 00000000..21cd3fa2 --- /dev/null +++ b/clients/spl-stake-pool/src/generated/errors/index.ts @@ -0,0 +1,9 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +export * from "./splStakePool.js"; diff --git a/clients/spl-stake-pool/src/generated/errors/splStakePool.ts b/clients/spl-stake-pool/src/generated/errors/splStakePool.ts new file mode 100644 index 00000000..243ac276 --- /dev/null +++ b/clients/spl-stake-pool/src/generated/errors/splStakePool.ts @@ -0,0 +1,240 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + Address, + SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM, + SolanaError, +} from "@solana/kit"; +import { isProgramError } from "@solana/kit"; +import { SPL_STAKE_POOL_PROGRAM_ADDRESS } from "../programs/index.js"; + +/** AlreadyInUse: AlreadyInUse */ +export const SPL_STAKE_POOL_ERROR__ALREADY_IN_USE = 0x0; // 0 +/** InvalidProgramAddress: InvalidProgramAddress */ +export const SPL_STAKE_POOL_ERROR__INVALID_PROGRAM_ADDRESS = 0x1; // 1 +/** InvalidState: InvalidState */ +export const SPL_STAKE_POOL_ERROR__INVALID_STATE = 0x2; // 2 +/** CalculationFailure: CalculationFailure */ +export const SPL_STAKE_POOL_ERROR__CALCULATION_FAILURE = 0x3; // 3 +/** FeeTooHigh: FeeTooHigh */ +export const SPL_STAKE_POOL_ERROR__FEE_TOO_HIGH = 0x4; // 4 +/** WrongAccountMint: WrongAccountMint */ +export const SPL_STAKE_POOL_ERROR__WRONG_ACCOUNT_MINT = 0x5; // 5 +/** WrongManager: WrongManager */ +export const SPL_STAKE_POOL_ERROR__WRONG_MANAGER = 0x6; // 6 +/** SignatureMissing: SignatureMissing */ +export const SPL_STAKE_POOL_ERROR__SIGNATURE_MISSING = 0x7; // 7 +/** InvalidValidatorStakeList: InvalidValidatorStakeList */ +export const SPL_STAKE_POOL_ERROR__INVALID_VALIDATOR_STAKE_LIST = 0x8; // 8 +/** InvalidFeeAccount: InvalidFeeAccount */ +export const SPL_STAKE_POOL_ERROR__INVALID_FEE_ACCOUNT = 0x9; // 9 +/** WrongPoolMint: WrongPoolMint */ +export const SPL_STAKE_POOL_ERROR__WRONG_POOL_MINT = 0xa; // 10 +/** WrongStakeStake: WrongStakeStake */ +export const SPL_STAKE_POOL_ERROR__WRONG_STAKE_STAKE = 0xb; // 11 +/** UserStakeNotActive: UserStakeNotActive */ +export const SPL_STAKE_POOL_ERROR__USER_STAKE_NOT_ACTIVE = 0xc; // 12 +/** ValidatorAlreadyAdded: ValidatorAlreadyAdded */ +export const SPL_STAKE_POOL_ERROR__VALIDATOR_ALREADY_ADDED = 0xd; // 13 +/** ValidatorNotFound: ValidatorNotFound */ +export const SPL_STAKE_POOL_ERROR__VALIDATOR_NOT_FOUND = 0xe; // 14 +/** InvalidStakeAccountAddress: InvalidStakeAccountAddress */ +export const SPL_STAKE_POOL_ERROR__INVALID_STAKE_ACCOUNT_ADDRESS = 0xf; // 15 +/** StakeListOutOfDate: StakeListOutOfDate */ +export const SPL_STAKE_POOL_ERROR__STAKE_LIST_OUT_OF_DATE = 0x10; // 16 +/** StakeListAndPoolOutOfDate: StakeListAndPoolOutOfDate */ +export const SPL_STAKE_POOL_ERROR__STAKE_LIST_AND_POOL_OUT_OF_DATE = 0x11; // 17 +/** UnknownValidatorStakeAccount: UnknownValidatorStakeAccount */ +export const SPL_STAKE_POOL_ERROR__UNKNOWN_VALIDATOR_STAKE_ACCOUNT = 0x12; // 18 +/** WrongMintingAuthority: WrongMintingAuthority */ +export const SPL_STAKE_POOL_ERROR__WRONG_MINTING_AUTHORITY = 0x13; // 19 +/** UnexpectedValidatorListAccountSize: UnexpectedValidatorListAccountSize */ +export const SPL_STAKE_POOL_ERROR__UNEXPECTED_VALIDATOR_LIST_ACCOUNT_SIZE = 0x14; // 20 +/** WrongStaker: WrongStaker */ +export const SPL_STAKE_POOL_ERROR__WRONG_STAKER = 0x15; // 21 +/** NonZeroPoolTokenSupply: NonZeroPoolTokenSupply */ +export const SPL_STAKE_POOL_ERROR__NON_ZERO_POOL_TOKEN_SUPPLY = 0x16; // 22 +/** StakeLamportsNotEqualToMinimum: StakeLamportsNotEqualToMinimum */ +export const SPL_STAKE_POOL_ERROR__STAKE_LAMPORTS_NOT_EQUAL_TO_MINIMUM = 0x17; // 23 +/** IncorrectDepositVoteAddress: IncorrectDepositVoteAddress */ +export const SPL_STAKE_POOL_ERROR__INCORRECT_DEPOSIT_VOTE_ADDRESS = 0x18; // 24 +/** IncorrectWithdrawVoteAddress: IncorrectWithdrawVoteAddress */ +export const SPL_STAKE_POOL_ERROR__INCORRECT_WITHDRAW_VOTE_ADDRESS = 0x19; // 25 +/** InvalidMintFreezeAuthority: InvalidMintFreezeAuthority */ +export const SPL_STAKE_POOL_ERROR__INVALID_MINT_FREEZE_AUTHORITY = 0x1a; // 26 +/** FeeIncreaseTooHigh: FeeIncreaseTooHigh */ +export const SPL_STAKE_POOL_ERROR__FEE_INCREASE_TOO_HIGH = 0x1b; // 27 +/** WithdrawalTooSmall: WithdrawalTooSmall */ +export const SPL_STAKE_POOL_ERROR__WITHDRAWAL_TOO_SMALL = 0x1c; // 28 +/** DepositTooSmall: DepositTooSmall */ +export const SPL_STAKE_POOL_ERROR__DEPOSIT_TOO_SMALL = 0x1d; // 29 +/** InvalidStakeDepositAuthority: InvalidStakeDepositAuthority */ +export const SPL_STAKE_POOL_ERROR__INVALID_STAKE_DEPOSIT_AUTHORITY = 0x1e; // 30 +/** InvalidSolDepositAuthority: InvalidSolDepositAuthority */ +export const SPL_STAKE_POOL_ERROR__INVALID_SOL_DEPOSIT_AUTHORITY = 0x1f; // 31 +/** InvalidPreferredValidator: InvalidPreferredValidator */ +export const SPL_STAKE_POOL_ERROR__INVALID_PREFERRED_VALIDATOR = 0x20; // 32 +/** TransientAccountInUse: TransientAccountInUse */ +export const SPL_STAKE_POOL_ERROR__TRANSIENT_ACCOUNT_IN_USE = 0x21; // 33 +/** InvalidSolWithdrawAuthority: InvalidSolWithdrawAuthority */ +export const SPL_STAKE_POOL_ERROR__INVALID_SOL_WITHDRAW_AUTHORITY = 0x22; // 34 +/** SolWithdrawalTooLarge: SolWithdrawalTooLarge */ +export const SPL_STAKE_POOL_ERROR__SOL_WITHDRAWAL_TOO_LARGE = 0x23; // 35 +/** InvalidMetadataAccount: InvalidMetadataAccount */ +export const SPL_STAKE_POOL_ERROR__INVALID_METADATA_ACCOUNT = 0x24; // 36 +/** UnsupportedMintExtension: UnsupportedMintExtension */ +export const SPL_STAKE_POOL_ERROR__UNSUPPORTED_MINT_EXTENSION = 0x25; // 37 +/** UnsupportedFeeAccountExtension: UnsupportedFeeAccountExtension */ +export const SPL_STAKE_POOL_ERROR__UNSUPPORTED_FEE_ACCOUNT_EXTENSION = 0x26; // 38 +/** ExceededSlippage: Instruction exceeds desired slippage limit */ +export const SPL_STAKE_POOL_ERROR__EXCEEDED_SLIPPAGE = 0x27; // 39 +/** IncorrectMintDecimals: IncorrectMintDecimals */ +export const SPL_STAKE_POOL_ERROR__INCORRECT_MINT_DECIMALS = 0x28; // 40 +/** ReserveDepleted: ReserveDepleted */ +export const SPL_STAKE_POOL_ERROR__RESERVE_DEPLETED = 0x29; // 41 +/** MissingRequiredSysvar: Missing required sysvar account */ +export const SPL_STAKE_POOL_ERROR__MISSING_REQUIRED_SYSVAR = 0x2a; // 42 + +export type SplStakePoolError = + | typeof SPL_STAKE_POOL_ERROR__ALREADY_IN_USE + | typeof SPL_STAKE_POOL_ERROR__CALCULATION_FAILURE + | typeof SPL_STAKE_POOL_ERROR__DEPOSIT_TOO_SMALL + | typeof SPL_STAKE_POOL_ERROR__EXCEEDED_SLIPPAGE + | typeof SPL_STAKE_POOL_ERROR__FEE_INCREASE_TOO_HIGH + | typeof SPL_STAKE_POOL_ERROR__FEE_TOO_HIGH + | typeof SPL_STAKE_POOL_ERROR__INCORRECT_DEPOSIT_VOTE_ADDRESS + | typeof SPL_STAKE_POOL_ERROR__INCORRECT_MINT_DECIMALS + | typeof SPL_STAKE_POOL_ERROR__INCORRECT_WITHDRAW_VOTE_ADDRESS + | typeof SPL_STAKE_POOL_ERROR__INVALID_FEE_ACCOUNT + | typeof SPL_STAKE_POOL_ERROR__INVALID_METADATA_ACCOUNT + | typeof SPL_STAKE_POOL_ERROR__INVALID_MINT_FREEZE_AUTHORITY + | typeof SPL_STAKE_POOL_ERROR__INVALID_PREFERRED_VALIDATOR + | typeof SPL_STAKE_POOL_ERROR__INVALID_PROGRAM_ADDRESS + | typeof SPL_STAKE_POOL_ERROR__INVALID_SOL_DEPOSIT_AUTHORITY + | typeof SPL_STAKE_POOL_ERROR__INVALID_SOL_WITHDRAW_AUTHORITY + | typeof SPL_STAKE_POOL_ERROR__INVALID_STAKE_ACCOUNT_ADDRESS + | typeof SPL_STAKE_POOL_ERROR__INVALID_STAKE_DEPOSIT_AUTHORITY + | typeof SPL_STAKE_POOL_ERROR__INVALID_STATE + | typeof SPL_STAKE_POOL_ERROR__INVALID_VALIDATOR_STAKE_LIST + | typeof SPL_STAKE_POOL_ERROR__MISSING_REQUIRED_SYSVAR + | typeof SPL_STAKE_POOL_ERROR__NON_ZERO_POOL_TOKEN_SUPPLY + | typeof SPL_STAKE_POOL_ERROR__RESERVE_DEPLETED + | typeof SPL_STAKE_POOL_ERROR__SIGNATURE_MISSING + | typeof SPL_STAKE_POOL_ERROR__SOL_WITHDRAWAL_TOO_LARGE + | typeof SPL_STAKE_POOL_ERROR__STAKE_LAMPORTS_NOT_EQUAL_TO_MINIMUM + | typeof SPL_STAKE_POOL_ERROR__STAKE_LIST_AND_POOL_OUT_OF_DATE + | typeof SPL_STAKE_POOL_ERROR__STAKE_LIST_OUT_OF_DATE + | typeof SPL_STAKE_POOL_ERROR__TRANSIENT_ACCOUNT_IN_USE + | typeof SPL_STAKE_POOL_ERROR__UNEXPECTED_VALIDATOR_LIST_ACCOUNT_SIZE + | typeof SPL_STAKE_POOL_ERROR__UNKNOWN_VALIDATOR_STAKE_ACCOUNT + | typeof SPL_STAKE_POOL_ERROR__UNSUPPORTED_FEE_ACCOUNT_EXTENSION + | typeof SPL_STAKE_POOL_ERROR__UNSUPPORTED_MINT_EXTENSION + | typeof SPL_STAKE_POOL_ERROR__USER_STAKE_NOT_ACTIVE + | typeof SPL_STAKE_POOL_ERROR__VALIDATOR_ALREADY_ADDED + | typeof SPL_STAKE_POOL_ERROR__VALIDATOR_NOT_FOUND + | typeof SPL_STAKE_POOL_ERROR__WITHDRAWAL_TOO_SMALL + | typeof SPL_STAKE_POOL_ERROR__WRONG_ACCOUNT_MINT + | typeof SPL_STAKE_POOL_ERROR__WRONG_MANAGER + | typeof SPL_STAKE_POOL_ERROR__WRONG_MINTING_AUTHORITY + | typeof SPL_STAKE_POOL_ERROR__WRONG_POOL_MINT + | typeof SPL_STAKE_POOL_ERROR__WRONG_STAKER + | typeof SPL_STAKE_POOL_ERROR__WRONG_STAKE_STAKE; + +let splStakePoolErrorMessages: Record | undefined; +if (true) { + splStakePoolErrorMessages = { + [SPL_STAKE_POOL_ERROR__ALREADY_IN_USE]: "AlreadyInUse", + [SPL_STAKE_POOL_ERROR__CALCULATION_FAILURE]: "CalculationFailure", + [SPL_STAKE_POOL_ERROR__DEPOSIT_TOO_SMALL]: "DepositTooSmall", + [SPL_STAKE_POOL_ERROR__EXCEEDED_SLIPPAGE]: + "Instruction exceeds desired slippage limit", + [SPL_STAKE_POOL_ERROR__FEE_INCREASE_TOO_HIGH]: "FeeIncreaseTooHigh", + [SPL_STAKE_POOL_ERROR__FEE_TOO_HIGH]: "FeeTooHigh", + [SPL_STAKE_POOL_ERROR__INCORRECT_DEPOSIT_VOTE_ADDRESS]: + "IncorrectDepositVoteAddress", + [SPL_STAKE_POOL_ERROR__INCORRECT_MINT_DECIMALS]: "IncorrectMintDecimals", + [SPL_STAKE_POOL_ERROR__INCORRECT_WITHDRAW_VOTE_ADDRESS]: + "IncorrectWithdrawVoteAddress", + [SPL_STAKE_POOL_ERROR__INVALID_FEE_ACCOUNT]: "InvalidFeeAccount", + [SPL_STAKE_POOL_ERROR__INVALID_METADATA_ACCOUNT]: "InvalidMetadataAccount", + [SPL_STAKE_POOL_ERROR__INVALID_MINT_FREEZE_AUTHORITY]: + "InvalidMintFreezeAuthority", + [SPL_STAKE_POOL_ERROR__INVALID_PREFERRED_VALIDATOR]: + "InvalidPreferredValidator", + [SPL_STAKE_POOL_ERROR__INVALID_PROGRAM_ADDRESS]: "InvalidProgramAddress", + [SPL_STAKE_POOL_ERROR__INVALID_SOL_DEPOSIT_AUTHORITY]: + "InvalidSolDepositAuthority", + [SPL_STAKE_POOL_ERROR__INVALID_SOL_WITHDRAW_AUTHORITY]: + "InvalidSolWithdrawAuthority", + [SPL_STAKE_POOL_ERROR__INVALID_STAKE_ACCOUNT_ADDRESS]: + "InvalidStakeAccountAddress", + [SPL_STAKE_POOL_ERROR__INVALID_STAKE_DEPOSIT_AUTHORITY]: + "InvalidStakeDepositAuthority", + [SPL_STAKE_POOL_ERROR__INVALID_STATE]: "InvalidState", + [SPL_STAKE_POOL_ERROR__INVALID_VALIDATOR_STAKE_LIST]: + "InvalidValidatorStakeList", + [SPL_STAKE_POOL_ERROR__MISSING_REQUIRED_SYSVAR]: + "Missing required sysvar account", + [SPL_STAKE_POOL_ERROR__NON_ZERO_POOL_TOKEN_SUPPLY]: + "NonZeroPoolTokenSupply", + [SPL_STAKE_POOL_ERROR__RESERVE_DEPLETED]: "ReserveDepleted", + [SPL_STAKE_POOL_ERROR__SIGNATURE_MISSING]: "SignatureMissing", + [SPL_STAKE_POOL_ERROR__SOL_WITHDRAWAL_TOO_LARGE]: "SolWithdrawalTooLarge", + [SPL_STAKE_POOL_ERROR__STAKE_LAMPORTS_NOT_EQUAL_TO_MINIMUM]: + "StakeLamportsNotEqualToMinimum", + [SPL_STAKE_POOL_ERROR__STAKE_LIST_AND_POOL_OUT_OF_DATE]: + "StakeListAndPoolOutOfDate", + [SPL_STAKE_POOL_ERROR__STAKE_LIST_OUT_OF_DATE]: "StakeListOutOfDate", + [SPL_STAKE_POOL_ERROR__TRANSIENT_ACCOUNT_IN_USE]: "TransientAccountInUse", + [SPL_STAKE_POOL_ERROR__UNEXPECTED_VALIDATOR_LIST_ACCOUNT_SIZE]: + "UnexpectedValidatorListAccountSize", + [SPL_STAKE_POOL_ERROR__UNKNOWN_VALIDATOR_STAKE_ACCOUNT]: + "UnknownValidatorStakeAccount", + [SPL_STAKE_POOL_ERROR__UNSUPPORTED_FEE_ACCOUNT_EXTENSION]: + "UnsupportedFeeAccountExtension", + [SPL_STAKE_POOL_ERROR__UNSUPPORTED_MINT_EXTENSION]: + "UnsupportedMintExtension", + [SPL_STAKE_POOL_ERROR__USER_STAKE_NOT_ACTIVE]: "UserStakeNotActive", + [SPL_STAKE_POOL_ERROR__VALIDATOR_ALREADY_ADDED]: "ValidatorAlreadyAdded", + [SPL_STAKE_POOL_ERROR__VALIDATOR_NOT_FOUND]: "ValidatorNotFound", + [SPL_STAKE_POOL_ERROR__WITHDRAWAL_TOO_SMALL]: "WithdrawalTooSmall", + [SPL_STAKE_POOL_ERROR__WRONG_ACCOUNT_MINT]: "WrongAccountMint", + [SPL_STAKE_POOL_ERROR__WRONG_MANAGER]: "WrongManager", + [SPL_STAKE_POOL_ERROR__WRONG_MINTING_AUTHORITY]: "WrongMintingAuthority", + [SPL_STAKE_POOL_ERROR__WRONG_POOL_MINT]: "WrongPoolMint", + [SPL_STAKE_POOL_ERROR__WRONG_STAKER]: "WrongStaker", + [SPL_STAKE_POOL_ERROR__WRONG_STAKE_STAKE]: "WrongStakeStake", + }; +} + +export function getSplStakePoolErrorMessage(code: SplStakePoolError): string { + if (true) { + return splStakePoolErrorMessages![code]; + } + + return "Error message not available in production bundles."; +} + +export function isSplStakePoolError< + TProgramErrorCode extends SplStakePoolError, +>( + error: unknown, + transactionMessage: { + instructions: Record; + }, + code?: TProgramErrorCode, +): error is SolanaError & + Readonly<{ context: Readonly<{ code: TProgramErrorCode }> }> { + return isProgramError( + error, + transactionMessage, + SPL_STAKE_POOL_PROGRAM_ADDRESS, + code, + ); +} diff --git a/clients/spl-stake-pool/src/generated/index.ts b/clients/spl-stake-pool/src/generated/index.ts new file mode 100644 index 00000000..975e985c --- /dev/null +++ b/clients/spl-stake-pool/src/generated/index.ts @@ -0,0 +1,14 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +export * from "./accounts/index.js"; +export * from "./errors/index.js"; +export * from "./instructions/index.js"; +export * from "./pdas/index.js"; +export * from "./programs/index.js"; +export * from "./types/index.js"; diff --git a/clients/spl-stake-pool/src/generated/instructions/addValidatorToPool.ts b/clients/spl-stake-pool/src/generated/instructions/addValidatorToPool.ts new file mode 100644 index 00000000..dcb757a5 --- /dev/null +++ b/clients/spl-stake-pool/src/generated/instructions/addValidatorToPool.ts @@ -0,0 +1,649 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getU32Decoder, + getU32Encoder, + transformEncoder, +} from "@solana/kit"; +import { findWithdrawAuthorityPda } from "../pdas/index.js"; +import { SPL_STAKE_POOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; + +export const ADD_VALIDATOR_TO_POOL_DISCRIMINATOR = 1; + +export function getAddValidatorToPoolDiscriminatorBytes(): ReadonlyUint8Array { + return getU8Encoder().encode(ADD_VALIDATOR_TO_POOL_DISCRIMINATOR); +} + +export type AddValidatorToPoolInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountStakePool extends string | AccountMeta = string, + TAccountStaker extends string | AccountMeta = string, + TAccountReserveStakeAccount extends string | AccountMeta = string, + TAccountWithdrawAuthority extends string | AccountMeta = string, + TAccountValidatorStakeList extends string | AccountMeta = string, + TAccountNewStakeAccount extends string | AccountMeta = string, + TAccountValidatorVoteAccount extends string | AccountMeta = string, + TAccountRentSysvar extends + | string + | AccountMeta = "SysvarRent111111111111111111111111111111111", + TAccountClockSysvar extends + | string + | AccountMeta = "SysvarC1ock11111111111111111111111111111111", + TAccountStakeHistorySysvar extends + | string + | AccountMeta = "SysvarStakeHistory1111111111111111111111111", + TAccountStakeConfigSysvar extends + | string + | AccountMeta = "StakeConfig11111111111111111111111111111111", + TAccountSystemProgram extends + | string + | AccountMeta = "11111111111111111111111111111111", + TAccountStakeProgram extends + | string + | AccountMeta = "Stake11111111111111111111111111111111111111", + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountStakePool extends string + ? WritableAccount + : TAccountStakePool, + TAccountStaker extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountStaker, + TAccountReserveStakeAccount extends string + ? WritableAccount + : TAccountReserveStakeAccount, + TAccountWithdrawAuthority extends string + ? ReadonlyAccount + : TAccountWithdrawAuthority, + TAccountValidatorStakeList extends string + ? WritableAccount + : TAccountValidatorStakeList, + TAccountNewStakeAccount extends string + ? WritableAccount + : TAccountNewStakeAccount, + TAccountValidatorVoteAccount extends string + ? ReadonlyAccount + : TAccountValidatorVoteAccount, + TAccountRentSysvar extends string + ? ReadonlyAccount + : TAccountRentSysvar, + TAccountClockSysvar extends string + ? ReadonlyAccount + : TAccountClockSysvar, + TAccountStakeHistorySysvar extends string + ? ReadonlyAccount + : TAccountStakeHistorySysvar, + TAccountStakeConfigSysvar extends string + ? ReadonlyAccount + : TAccountStakeConfigSysvar, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + TAccountStakeProgram extends string + ? ReadonlyAccount + : TAccountStakeProgram, + ...TRemainingAccounts, + ] + >; + +export interface AddValidatorToPoolInstructionData { + discriminator: number; + args: number; +} + +export interface AddValidatorToPoolInstructionDataArgs { + args: number; +} + +export function getAddValidatorToPoolInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", getU8Encoder()], + ["args", getU32Encoder()], + ]), + (value) => ({ + ...value, + discriminator: ADD_VALIDATOR_TO_POOL_DISCRIMINATOR, + }), + ); +} + +export function getAddValidatorToPoolInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", getU8Decoder()], + ["args", getU32Decoder()], + ]); +} + +export function getAddValidatorToPoolInstructionDataCodec(): FixedSizeCodec< + AddValidatorToPoolInstructionDataArgs, + AddValidatorToPoolInstructionData +> { + return combineCodec( + getAddValidatorToPoolInstructionDataEncoder(), + getAddValidatorToPoolInstructionDataDecoder(), + ); +} + +export interface AddValidatorToPoolAsyncInput< + TAccountStakePool extends string = string, + TAccountStaker extends string = string, + TAccountReserveStakeAccount extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountValidatorStakeList extends string = string, + TAccountNewStakeAccount extends string = string, + TAccountValidatorVoteAccount extends string = string, + TAccountRentSysvar extends string = string, + TAccountClockSysvar extends string = string, + TAccountStakeHistorySysvar extends string = string, + TAccountStakeConfigSysvar extends string = string, + TAccountSystemProgram extends string = string, + TAccountStakeProgram extends string = string, +> { + /** Stake pool */ + stakePool: Address; + /** Staker */ + staker: TransactionSigner; + /** Reserve stake account */ + reserveStakeAccount: Address; + /** Stake pool withdraw authority */ + withdrawAuthority?: Address; + /** Validator stake list storage account */ + validatorStakeList: Address; + /** Stake account to add to the pool */ + newStakeAccount: Address; + /** Validator this stake account will be delegated to */ + validatorVoteAccount: Address; + /** Rent sysvar */ + rentSysvar?: Address; + /** Clock sysvar */ + clockSysvar?: Address; + /** Stake history sysvar */ + stakeHistorySysvar?: Address; + /** Stake config sysvar */ + stakeConfigSysvar?: Address; + /** System program */ + systemProgram?: Address; + /** Stake program */ + stakeProgram?: Address; + args: AddValidatorToPoolInstructionDataArgs["args"]; +} + +export async function getAddValidatorToPoolInstructionAsync< + TAccountStakePool extends string, + TAccountStaker extends string, + TAccountReserveStakeAccount extends string, + TAccountWithdrawAuthority extends string, + TAccountValidatorStakeList extends string, + TAccountNewStakeAccount extends string, + TAccountValidatorVoteAccount extends string, + TAccountRentSysvar extends string, + TAccountClockSysvar extends string, + TAccountStakeHistorySysvar extends string, + TAccountStakeConfigSysvar extends string, + TAccountSystemProgram extends string, + TAccountStakeProgram extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: AddValidatorToPoolAsyncInput< + TAccountStakePool, + TAccountStaker, + TAccountReserveStakeAccount, + TAccountWithdrawAuthority, + TAccountValidatorStakeList, + TAccountNewStakeAccount, + TAccountValidatorVoteAccount, + TAccountRentSysvar, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountStakeConfigSysvar, + TAccountSystemProgram, + TAccountStakeProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + AddValidatorToPoolInstruction< + TProgramAddress, + TAccountStakePool, + TAccountStaker, + TAccountReserveStakeAccount, + TAccountWithdrawAuthority, + TAccountValidatorStakeList, + TAccountNewStakeAccount, + TAccountValidatorVoteAccount, + TAccountRentSysvar, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountStakeConfigSysvar, + TAccountSystemProgram, + TAccountStakeProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: true }, + staker: { value: input.staker ?? null, isWritable: false }, + reserveStakeAccount: { + value: input.reserveStakeAccount ?? null, + isWritable: true, + }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + validatorStakeList: { + value: input.validatorStakeList ?? null, + isWritable: true, + }, + newStakeAccount: { value: input.newStakeAccount ?? null, isWritable: true }, + validatorVoteAccount: { + value: input.validatorVoteAccount ?? null, + isWritable: false, + }, + rentSysvar: { value: input.rentSysvar ?? null, isWritable: false }, + clockSysvar: { value: input.clockSysvar ?? null, isWritable: false }, + stakeHistorySysvar: { + value: input.stakeHistorySysvar ?? null, + isWritable: false, + }, + stakeConfigSysvar: { + value: input.stakeConfigSysvar ?? null, + isWritable: false, + }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + stakeProgram: { value: input.stakeProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.withdrawAuthority.value) { + accounts.withdrawAuthority.value = await findWithdrawAuthorityPda({ + stakePoolAddress: expectAddress(accounts.stakePool.value), + }); + } + if (!accounts.rentSysvar.value) { + accounts.rentSysvar.value = + "SysvarRent111111111111111111111111111111111" as Address<"SysvarRent111111111111111111111111111111111">; + } + if (!accounts.clockSysvar.value) { + accounts.clockSysvar.value = + "SysvarC1ock11111111111111111111111111111111" as Address<"SysvarC1ock11111111111111111111111111111111">; + } + if (!accounts.stakeHistorySysvar.value) { + accounts.stakeHistorySysvar.value = + "SysvarStakeHistory1111111111111111111111111" as Address<"SysvarStakeHistory1111111111111111111111111">; + } + if (!accounts.stakeConfigSysvar.value) { + accounts.stakeConfigSysvar.value = + "StakeConfig11111111111111111111111111111111" as Address<"StakeConfig11111111111111111111111111111111">; + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + if (!accounts.stakeProgram.value) { + accounts.stakeProgram.value = + "Stake11111111111111111111111111111111111111" as Address<"Stake11111111111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.staker), + getAccountMeta(accounts.reserveStakeAccount), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.validatorStakeList), + getAccountMeta(accounts.newStakeAccount), + getAccountMeta(accounts.validatorVoteAccount), + getAccountMeta(accounts.rentSysvar), + getAccountMeta(accounts.clockSysvar), + getAccountMeta(accounts.stakeHistorySysvar), + getAccountMeta(accounts.stakeConfigSysvar), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.stakeProgram), + ], + data: getAddValidatorToPoolInstructionDataEncoder().encode( + args as AddValidatorToPoolInstructionDataArgs, + ), + programAddress, + } as AddValidatorToPoolInstruction< + TProgramAddress, + TAccountStakePool, + TAccountStaker, + TAccountReserveStakeAccount, + TAccountWithdrawAuthority, + TAccountValidatorStakeList, + TAccountNewStakeAccount, + TAccountValidatorVoteAccount, + TAccountRentSysvar, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountStakeConfigSysvar, + TAccountSystemProgram, + TAccountStakeProgram + >); +} + +export interface AddValidatorToPoolInput< + TAccountStakePool extends string = string, + TAccountStaker extends string = string, + TAccountReserveStakeAccount extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountValidatorStakeList extends string = string, + TAccountNewStakeAccount extends string = string, + TAccountValidatorVoteAccount extends string = string, + TAccountRentSysvar extends string = string, + TAccountClockSysvar extends string = string, + TAccountStakeHistorySysvar extends string = string, + TAccountStakeConfigSysvar extends string = string, + TAccountSystemProgram extends string = string, + TAccountStakeProgram extends string = string, +> { + /** Stake pool */ + stakePool: Address; + /** Staker */ + staker: TransactionSigner; + /** Reserve stake account */ + reserveStakeAccount: Address; + /** Stake pool withdraw authority */ + withdrawAuthority: Address; + /** Validator stake list storage account */ + validatorStakeList: Address; + /** Stake account to add to the pool */ + newStakeAccount: Address; + /** Validator this stake account will be delegated to */ + validatorVoteAccount: Address; + /** Rent sysvar */ + rentSysvar?: Address; + /** Clock sysvar */ + clockSysvar?: Address; + /** Stake history sysvar */ + stakeHistorySysvar?: Address; + /** Stake config sysvar */ + stakeConfigSysvar?: Address; + /** System program */ + systemProgram?: Address; + /** Stake program */ + stakeProgram?: Address; + args: AddValidatorToPoolInstructionDataArgs["args"]; +} + +export function getAddValidatorToPoolInstruction< + TAccountStakePool extends string, + TAccountStaker extends string, + TAccountReserveStakeAccount extends string, + TAccountWithdrawAuthority extends string, + TAccountValidatorStakeList extends string, + TAccountNewStakeAccount extends string, + TAccountValidatorVoteAccount extends string, + TAccountRentSysvar extends string, + TAccountClockSysvar extends string, + TAccountStakeHistorySysvar extends string, + TAccountStakeConfigSysvar extends string, + TAccountSystemProgram extends string, + TAccountStakeProgram extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: AddValidatorToPoolInput< + TAccountStakePool, + TAccountStaker, + TAccountReserveStakeAccount, + TAccountWithdrawAuthority, + TAccountValidatorStakeList, + TAccountNewStakeAccount, + TAccountValidatorVoteAccount, + TAccountRentSysvar, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountStakeConfigSysvar, + TAccountSystemProgram, + TAccountStakeProgram + >, + config?: { programAddress?: TProgramAddress }, +): AddValidatorToPoolInstruction< + TProgramAddress, + TAccountStakePool, + TAccountStaker, + TAccountReserveStakeAccount, + TAccountWithdrawAuthority, + TAccountValidatorStakeList, + TAccountNewStakeAccount, + TAccountValidatorVoteAccount, + TAccountRentSysvar, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountStakeConfigSysvar, + TAccountSystemProgram, + TAccountStakeProgram +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: true }, + staker: { value: input.staker ?? null, isWritable: false }, + reserveStakeAccount: { + value: input.reserveStakeAccount ?? null, + isWritable: true, + }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + validatorStakeList: { + value: input.validatorStakeList ?? null, + isWritable: true, + }, + newStakeAccount: { value: input.newStakeAccount ?? null, isWritable: true }, + validatorVoteAccount: { + value: input.validatorVoteAccount ?? null, + isWritable: false, + }, + rentSysvar: { value: input.rentSysvar ?? null, isWritable: false }, + clockSysvar: { value: input.clockSysvar ?? null, isWritable: false }, + stakeHistorySysvar: { + value: input.stakeHistorySysvar ?? null, + isWritable: false, + }, + stakeConfigSysvar: { + value: input.stakeConfigSysvar ?? null, + isWritable: false, + }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + stakeProgram: { value: input.stakeProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.rentSysvar.value) { + accounts.rentSysvar.value = + "SysvarRent111111111111111111111111111111111" as Address<"SysvarRent111111111111111111111111111111111">; + } + if (!accounts.clockSysvar.value) { + accounts.clockSysvar.value = + "SysvarC1ock11111111111111111111111111111111" as Address<"SysvarC1ock11111111111111111111111111111111">; + } + if (!accounts.stakeHistorySysvar.value) { + accounts.stakeHistorySysvar.value = + "SysvarStakeHistory1111111111111111111111111" as Address<"SysvarStakeHistory1111111111111111111111111">; + } + if (!accounts.stakeConfigSysvar.value) { + accounts.stakeConfigSysvar.value = + "StakeConfig11111111111111111111111111111111" as Address<"StakeConfig11111111111111111111111111111111">; + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + if (!accounts.stakeProgram.value) { + accounts.stakeProgram.value = + "Stake11111111111111111111111111111111111111" as Address<"Stake11111111111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.staker), + getAccountMeta(accounts.reserveStakeAccount), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.validatorStakeList), + getAccountMeta(accounts.newStakeAccount), + getAccountMeta(accounts.validatorVoteAccount), + getAccountMeta(accounts.rentSysvar), + getAccountMeta(accounts.clockSysvar), + getAccountMeta(accounts.stakeHistorySysvar), + getAccountMeta(accounts.stakeConfigSysvar), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.stakeProgram), + ], + data: getAddValidatorToPoolInstructionDataEncoder().encode( + args as AddValidatorToPoolInstructionDataArgs, + ), + programAddress, + } as AddValidatorToPoolInstruction< + TProgramAddress, + TAccountStakePool, + TAccountStaker, + TAccountReserveStakeAccount, + TAccountWithdrawAuthority, + TAccountValidatorStakeList, + TAccountNewStakeAccount, + TAccountValidatorVoteAccount, + TAccountRentSysvar, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountStakeConfigSysvar, + TAccountSystemProgram, + TAccountStakeProgram + >); +} + +export interface ParsedAddValidatorToPoolInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + /** Stake pool */ + stakePool: TAccountMetas[0]; + /** Staker */ + staker: TAccountMetas[1]; + /** Reserve stake account */ + reserveStakeAccount: TAccountMetas[2]; + /** Stake pool withdraw authority */ + withdrawAuthority: TAccountMetas[3]; + /** Validator stake list storage account */ + validatorStakeList: TAccountMetas[4]; + /** Stake account to add to the pool */ + newStakeAccount: TAccountMetas[5]; + /** Validator this stake account will be delegated to */ + validatorVoteAccount: TAccountMetas[6]; + /** Rent sysvar */ + rentSysvar: TAccountMetas[7]; + /** Clock sysvar */ + clockSysvar: TAccountMetas[8]; + /** Stake history sysvar */ + stakeHistorySysvar: TAccountMetas[9]; + /** Stake config sysvar */ + stakeConfigSysvar: TAccountMetas[10]; + /** System program */ + systemProgram: TAccountMetas[11]; + /** Stake program */ + stakeProgram: TAccountMetas[12]; + }; + data: AddValidatorToPoolInstructionData; +} + +export function parseAddValidatorToPoolInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedAddValidatorToPoolInstruction { + if (instruction.accounts.length < 13) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + stakePool: getNextAccount(), + staker: getNextAccount(), + reserveStakeAccount: getNextAccount(), + withdrawAuthority: getNextAccount(), + validatorStakeList: getNextAccount(), + newStakeAccount: getNextAccount(), + validatorVoteAccount: getNextAccount(), + rentSysvar: getNextAccount(), + clockSysvar: getNextAccount(), + stakeHistorySysvar: getNextAccount(), + stakeConfigSysvar: getNextAccount(), + systemProgram: getNextAccount(), + stakeProgram: getNextAccount(), + }, + data: getAddValidatorToPoolInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/spl-stake-pool/src/generated/instructions/cleanupRemovedValidatorEntries.ts b/clients/spl-stake-pool/src/generated/instructions/cleanupRemovedValidatorEntries.ts new file mode 100644 index 00000000..e7217b11 --- /dev/null +++ b/clients/spl-stake-pool/src/generated/instructions/cleanupRemovedValidatorEntries.ts @@ -0,0 +1,178 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlyUint8Array, + WritableAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, +} from "@solana/kit"; +import { SPL_STAKE_POOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const CLEANUP_REMOVED_VALIDATOR_ENTRIES_DISCRIMINATOR = 8; + +export function getCleanupRemovedValidatorEntriesDiscriminatorBytes(): ReadonlyUint8Array { + return getU8Encoder().encode(CLEANUP_REMOVED_VALIDATOR_ENTRIES_DISCRIMINATOR); +} + +export type CleanupRemovedValidatorEntriesInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountStakePool extends string | AccountMeta = string, + TAccountValidatorList extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountStakePool extends string + ? ReadonlyAccount + : TAccountStakePool, + TAccountValidatorList extends string + ? WritableAccount + : TAccountValidatorList, + ...TRemainingAccounts, + ] + >; + +export interface CleanupRemovedValidatorEntriesInstructionData { + discriminator: number; +} + +export interface CleanupRemovedValidatorEntriesInstructionDataArgs {} + +export function getCleanupRemovedValidatorEntriesInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", getU8Encoder()]]), + (value) => ({ + ...value, + discriminator: CLEANUP_REMOVED_VALIDATOR_ENTRIES_DISCRIMINATOR, + }), + ); +} + +export function getCleanupRemovedValidatorEntriesInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([["discriminator", getU8Decoder()]]); +} + +export function getCleanupRemovedValidatorEntriesInstructionDataCodec(): FixedSizeCodec< + CleanupRemovedValidatorEntriesInstructionDataArgs, + CleanupRemovedValidatorEntriesInstructionData +> { + return combineCodec( + getCleanupRemovedValidatorEntriesInstructionDataEncoder(), + getCleanupRemovedValidatorEntriesInstructionDataDecoder(), + ); +} + +export interface CleanupRemovedValidatorEntriesInput< + TAccountStakePool extends string = string, + TAccountValidatorList extends string = string, +> { + stakePool: Address; + validatorList: Address; +} + +export function getCleanupRemovedValidatorEntriesInstruction< + TAccountStakePool extends string, + TAccountValidatorList extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: CleanupRemovedValidatorEntriesInput< + TAccountStakePool, + TAccountValidatorList + >, + config?: { programAddress?: TProgramAddress }, +): CleanupRemovedValidatorEntriesInstruction< + TProgramAddress, + TAccountStakePool, + TAccountValidatorList +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: false }, + validatorList: { value: input.validatorList ?? null, isWritable: true }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.validatorList), + ], + data: getCleanupRemovedValidatorEntriesInstructionDataEncoder().encode({}), + programAddress, + } as CleanupRemovedValidatorEntriesInstruction< + TProgramAddress, + TAccountStakePool, + TAccountValidatorList + >); +} + +export interface ParsedCleanupRemovedValidatorEntriesInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + stakePool: TAccountMetas[0]; + validatorList: TAccountMetas[1]; + }; + data: CleanupRemovedValidatorEntriesInstructionData; +} + +export function parseCleanupRemovedValidatorEntriesInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedCleanupRemovedValidatorEntriesInstruction { + if (instruction.accounts.length < 2) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { stakePool: getNextAccount(), validatorList: getNextAccount() }, + data: getCleanupRemovedValidatorEntriesInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/spl-stake-pool/src/generated/instructions/createTokenMetadata.ts b/clients/spl-stake-pool/src/generated/instructions/createTokenMetadata.ts new file mode 100644 index 00000000..e5504fde --- /dev/null +++ b/clients/spl-stake-pool/src/generated/instructions/createTokenMetadata.ts @@ -0,0 +1,444 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + Codec, + Decoder, + Encoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, + WritableSignerAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import { + addDecoderSizePrefix, + addEncoderSizePrefix, + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getU32Decoder, + getU32Encoder, + getUtf8Decoder, + getUtf8Encoder, + transformEncoder, +} from "@solana/kit"; +import { findWithdrawAuthorityPda } from "../pdas/index.js"; +import { SPL_STAKE_POOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; + +export const CREATE_TOKEN_METADATA_DISCRIMINATOR = 17; + +export function getCreateTokenMetadataDiscriminatorBytes(): ReadonlyUint8Array { + return getU8Encoder().encode(CREATE_TOKEN_METADATA_DISCRIMINATOR); +} + +export type CreateTokenMetadataInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountStakePool extends string | AccountMeta = string, + TAccountManager extends string | AccountMeta = string, + TAccountWithdrawAuthority extends string | AccountMeta = string, + TAccountPoolMint extends string | AccountMeta = string, + TAccountPayer extends string | AccountMeta = string, + TAccountMetadataAccount extends string | AccountMeta = string, + TAccountMetadataProgram extends string | AccountMeta = string, + TAccountSystemProgram extends + | string + | AccountMeta = "11111111111111111111111111111111", + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountStakePool extends string + ? ReadonlyAccount + : TAccountStakePool, + TAccountManager extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountManager, + TAccountWithdrawAuthority extends string + ? ReadonlyAccount + : TAccountWithdrawAuthority, + TAccountPoolMint extends string + ? ReadonlyAccount + : TAccountPoolMint, + TAccountPayer extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountPayer, + TAccountMetadataAccount extends string + ? WritableAccount + : TAccountMetadataAccount, + TAccountMetadataProgram extends string + ? ReadonlyAccount + : TAccountMetadataProgram, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + ...TRemainingAccounts, + ] + >; + +export interface CreateTokenMetadataInstructionData { + discriminator: number; + name: string; + symbol: string; + uri: string; +} + +export interface CreateTokenMetadataInstructionDataArgs { + name: string; + symbol: string; + uri: string; +} + +export function getCreateTokenMetadataInstructionDataEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", getU8Encoder()], + ["name", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())], + ["symbol", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())], + ["uri", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())], + ]), + (value) => ({ + ...value, + discriminator: CREATE_TOKEN_METADATA_DISCRIMINATOR, + }), + ); +} + +export function getCreateTokenMetadataInstructionDataDecoder(): Decoder { + return getStructDecoder([ + ["discriminator", getU8Decoder()], + ["name", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())], + ["symbol", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())], + ["uri", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())], + ]); +} + +export function getCreateTokenMetadataInstructionDataCodec(): Codec< + CreateTokenMetadataInstructionDataArgs, + CreateTokenMetadataInstructionData +> { + return combineCodec( + getCreateTokenMetadataInstructionDataEncoder(), + getCreateTokenMetadataInstructionDataDecoder(), + ); +} + +export interface CreateTokenMetadataAsyncInput< + TAccountStakePool extends string = string, + TAccountManager extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountPoolMint extends string = string, + TAccountPayer extends string = string, + TAccountMetadataAccount extends string = string, + TAccountMetadataProgram extends string = string, + TAccountSystemProgram extends string = string, +> { + stakePool: Address; + manager: TransactionSigner; + withdrawAuthority?: Address; + poolMint: Address; + payer: TransactionSigner; + metadataAccount: Address; + metadataProgram: Address; + systemProgram?: Address; + name: CreateTokenMetadataInstructionDataArgs["name"]; + symbol: CreateTokenMetadataInstructionDataArgs["symbol"]; + uri: CreateTokenMetadataInstructionDataArgs["uri"]; +} + +export async function getCreateTokenMetadataInstructionAsync< + TAccountStakePool extends string, + TAccountManager extends string, + TAccountWithdrawAuthority extends string, + TAccountPoolMint extends string, + TAccountPayer extends string, + TAccountMetadataAccount extends string, + TAccountMetadataProgram extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: CreateTokenMetadataAsyncInput< + TAccountStakePool, + TAccountManager, + TAccountWithdrawAuthority, + TAccountPoolMint, + TAccountPayer, + TAccountMetadataAccount, + TAccountMetadataProgram, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + CreateTokenMetadataInstruction< + TProgramAddress, + TAccountStakePool, + TAccountManager, + TAccountWithdrawAuthority, + TAccountPoolMint, + TAccountPayer, + TAccountMetadataAccount, + TAccountMetadataProgram, + TAccountSystemProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: false }, + manager: { value: input.manager ?? null, isWritable: false }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + poolMint: { value: input.poolMint ?? null, isWritable: false }, + payer: { value: input.payer ?? null, isWritable: true }, + metadataAccount: { value: input.metadataAccount ?? null, isWritable: true }, + metadataProgram: { + value: input.metadataProgram ?? null, + isWritable: false, + }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.withdrawAuthority.value) { + accounts.withdrawAuthority.value = await findWithdrawAuthorityPda({ + stakePoolAddress: expectAddress(accounts.stakePool.value), + }); + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.manager), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.poolMint), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.metadataAccount), + getAccountMeta(accounts.metadataProgram), + getAccountMeta(accounts.systemProgram), + ], + data: getCreateTokenMetadataInstructionDataEncoder().encode( + args as CreateTokenMetadataInstructionDataArgs, + ), + programAddress, + } as CreateTokenMetadataInstruction< + TProgramAddress, + TAccountStakePool, + TAccountManager, + TAccountWithdrawAuthority, + TAccountPoolMint, + TAccountPayer, + TAccountMetadataAccount, + TAccountMetadataProgram, + TAccountSystemProgram + >); +} + +export interface CreateTokenMetadataInput< + TAccountStakePool extends string = string, + TAccountManager extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountPoolMint extends string = string, + TAccountPayer extends string = string, + TAccountMetadataAccount extends string = string, + TAccountMetadataProgram extends string = string, + TAccountSystemProgram extends string = string, +> { + stakePool: Address; + manager: TransactionSigner; + withdrawAuthority: Address; + poolMint: Address; + payer: TransactionSigner; + metadataAccount: Address; + metadataProgram: Address; + systemProgram?: Address; + name: CreateTokenMetadataInstructionDataArgs["name"]; + symbol: CreateTokenMetadataInstructionDataArgs["symbol"]; + uri: CreateTokenMetadataInstructionDataArgs["uri"]; +} + +export function getCreateTokenMetadataInstruction< + TAccountStakePool extends string, + TAccountManager extends string, + TAccountWithdrawAuthority extends string, + TAccountPoolMint extends string, + TAccountPayer extends string, + TAccountMetadataAccount extends string, + TAccountMetadataProgram extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: CreateTokenMetadataInput< + TAccountStakePool, + TAccountManager, + TAccountWithdrawAuthority, + TAccountPoolMint, + TAccountPayer, + TAccountMetadataAccount, + TAccountMetadataProgram, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress }, +): CreateTokenMetadataInstruction< + TProgramAddress, + TAccountStakePool, + TAccountManager, + TAccountWithdrawAuthority, + TAccountPoolMint, + TAccountPayer, + TAccountMetadataAccount, + TAccountMetadataProgram, + TAccountSystemProgram +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: false }, + manager: { value: input.manager ?? null, isWritable: false }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + poolMint: { value: input.poolMint ?? null, isWritable: false }, + payer: { value: input.payer ?? null, isWritable: true }, + metadataAccount: { value: input.metadataAccount ?? null, isWritable: true }, + metadataProgram: { + value: input.metadataProgram ?? null, + isWritable: false, + }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.manager), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.poolMint), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.metadataAccount), + getAccountMeta(accounts.metadataProgram), + getAccountMeta(accounts.systemProgram), + ], + data: getCreateTokenMetadataInstructionDataEncoder().encode( + args as CreateTokenMetadataInstructionDataArgs, + ), + programAddress, + } as CreateTokenMetadataInstruction< + TProgramAddress, + TAccountStakePool, + TAccountManager, + TAccountWithdrawAuthority, + TAccountPoolMint, + TAccountPayer, + TAccountMetadataAccount, + TAccountMetadataProgram, + TAccountSystemProgram + >); +} + +export interface ParsedCreateTokenMetadataInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + stakePool: TAccountMetas[0]; + manager: TAccountMetas[1]; + withdrawAuthority: TAccountMetas[2]; + poolMint: TAccountMetas[3]; + payer: TAccountMetas[4]; + metadataAccount: TAccountMetas[5]; + metadataProgram: TAccountMetas[6]; + systemProgram: TAccountMetas[7]; + }; + data: CreateTokenMetadataInstructionData; +} + +export function parseCreateTokenMetadataInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedCreateTokenMetadataInstruction { + if (instruction.accounts.length < 8) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + stakePool: getNextAccount(), + manager: getNextAccount(), + withdrawAuthority: getNextAccount(), + poolMint: getNextAccount(), + payer: getNextAccount(), + metadataAccount: getNextAccount(), + metadataProgram: getNextAccount(), + systemProgram: getNextAccount(), + }, + data: getCreateTokenMetadataInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/spl-stake-pool/src/generated/instructions/decreaseAdditionalValidatorStake.ts b/clients/spl-stake-pool/src/generated/instructions/decreaseAdditionalValidatorStake.ts new file mode 100644 index 00000000..d8bf13f4 --- /dev/null +++ b/clients/spl-stake-pool/src/generated/instructions/decreaseAdditionalValidatorStake.ts @@ -0,0 +1,558 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getU64Decoder, + getU64Encoder, + transformEncoder, +} from "@solana/kit"; +import { findWithdrawAuthorityPda } from "../pdas/index.js"; +import { SPL_STAKE_POOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; + +export const DECREASE_ADDITIONAL_VALIDATOR_STAKE_DISCRIMINATOR = 20; + +export function getDecreaseAdditionalValidatorStakeDiscriminatorBytes(): ReadonlyUint8Array { + return getU8Encoder().encode( + DECREASE_ADDITIONAL_VALIDATOR_STAKE_DISCRIMINATOR, + ); +} + +export type DecreaseAdditionalValidatorStakeInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountStakePool extends string | AccountMeta = string, + TAccountStaker extends string | AccountMeta = string, + TAccountWithdrawAuthority extends string | AccountMeta = string, + TAccountValidatorList extends string | AccountMeta = string, + TAccountReserveStake extends string | AccountMeta = string, + TAccountCanonicalStake extends string | AccountMeta = string, + TAccountEphemeralStake extends string | AccountMeta = string, + TAccountTransientStake extends string | AccountMeta = string, + TAccountClockSysvar extends + | string + | AccountMeta = "SysvarC1ock11111111111111111111111111111111", + TAccountStakeHistorySysvar extends + | string + | AccountMeta = "SysvarStakeHistory1111111111111111111111111", + TAccountSystemProgram extends + | string + | AccountMeta = "11111111111111111111111111111111", + TAccountStakeProgram extends + | string + | AccountMeta = "Stake11111111111111111111111111111111111111", + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountStakePool extends string + ? ReadonlyAccount + : TAccountStakePool, + TAccountStaker extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountStaker, + TAccountWithdrawAuthority extends string + ? ReadonlyAccount + : TAccountWithdrawAuthority, + TAccountValidatorList extends string + ? WritableAccount + : TAccountValidatorList, + TAccountReserveStake extends string + ? WritableAccount + : TAccountReserveStake, + TAccountCanonicalStake extends string + ? WritableAccount + : TAccountCanonicalStake, + TAccountEphemeralStake extends string + ? WritableAccount + : TAccountEphemeralStake, + TAccountTransientStake extends string + ? WritableAccount + : TAccountTransientStake, + TAccountClockSysvar extends string + ? ReadonlyAccount + : TAccountClockSysvar, + TAccountStakeHistorySysvar extends string + ? ReadonlyAccount + : TAccountStakeHistorySysvar, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + TAccountStakeProgram extends string + ? ReadonlyAccount + : TAccountStakeProgram, + ...TRemainingAccounts, + ] + >; + +export interface DecreaseAdditionalValidatorStakeInstructionData { + discriminator: number; + lamports: bigint; + transientStakeSeed: bigint; + ephemeralStakeSeed: bigint; +} + +export interface DecreaseAdditionalValidatorStakeInstructionDataArgs { + lamports: number | bigint; + transientStakeSeed: number | bigint; + ephemeralStakeSeed: number | bigint; +} + +export function getDecreaseAdditionalValidatorStakeInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", getU8Encoder()], + ["lamports", getU64Encoder()], + ["transientStakeSeed", getU64Encoder()], + ["ephemeralStakeSeed", getU64Encoder()], + ]), + (value) => ({ + ...value, + discriminator: DECREASE_ADDITIONAL_VALIDATOR_STAKE_DISCRIMINATOR, + }), + ); +} + +export function getDecreaseAdditionalValidatorStakeInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", getU8Decoder()], + ["lamports", getU64Decoder()], + ["transientStakeSeed", getU64Decoder()], + ["ephemeralStakeSeed", getU64Decoder()], + ]); +} + +export function getDecreaseAdditionalValidatorStakeInstructionDataCodec(): FixedSizeCodec< + DecreaseAdditionalValidatorStakeInstructionDataArgs, + DecreaseAdditionalValidatorStakeInstructionData +> { + return combineCodec( + getDecreaseAdditionalValidatorStakeInstructionDataEncoder(), + getDecreaseAdditionalValidatorStakeInstructionDataDecoder(), + ); +} + +export interface DecreaseAdditionalValidatorStakeAsyncInput< + TAccountStakePool extends string = string, + TAccountStaker extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountValidatorList extends string = string, + TAccountReserveStake extends string = string, + TAccountCanonicalStake extends string = string, + TAccountEphemeralStake extends string = string, + TAccountTransientStake extends string = string, + TAccountClockSysvar extends string = string, + TAccountStakeHistorySysvar extends string = string, + TAccountSystemProgram extends string = string, + TAccountStakeProgram extends string = string, +> { + stakePool: Address; + staker: TransactionSigner; + withdrawAuthority?: Address; + validatorList: Address; + reserveStake: Address; + canonicalStake: Address; + ephemeralStake: Address; + transientStake: Address; + clockSysvar?: Address; + stakeHistorySysvar?: Address; + systemProgram?: Address; + stakeProgram?: Address; + lamports: DecreaseAdditionalValidatorStakeInstructionDataArgs["lamports"]; + transientStakeSeed: DecreaseAdditionalValidatorStakeInstructionDataArgs["transientStakeSeed"]; + ephemeralStakeSeed: DecreaseAdditionalValidatorStakeInstructionDataArgs["ephemeralStakeSeed"]; +} + +export async function getDecreaseAdditionalValidatorStakeInstructionAsync< + TAccountStakePool extends string, + TAccountStaker extends string, + TAccountWithdrawAuthority extends string, + TAccountValidatorList extends string, + TAccountReserveStake extends string, + TAccountCanonicalStake extends string, + TAccountEphemeralStake extends string, + TAccountTransientStake extends string, + TAccountClockSysvar extends string, + TAccountStakeHistorySysvar extends string, + TAccountSystemProgram extends string, + TAccountStakeProgram extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: DecreaseAdditionalValidatorStakeAsyncInput< + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountCanonicalStake, + TAccountEphemeralStake, + TAccountTransientStake, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountSystemProgram, + TAccountStakeProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + DecreaseAdditionalValidatorStakeInstruction< + TProgramAddress, + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountCanonicalStake, + TAccountEphemeralStake, + TAccountTransientStake, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountSystemProgram, + TAccountStakeProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: false }, + staker: { value: input.staker ?? null, isWritable: false }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + validatorList: { value: input.validatorList ?? null, isWritable: true }, + reserveStake: { value: input.reserveStake ?? null, isWritable: true }, + canonicalStake: { value: input.canonicalStake ?? null, isWritable: true }, + ephemeralStake: { value: input.ephemeralStake ?? null, isWritable: true }, + transientStake: { value: input.transientStake ?? null, isWritable: true }, + clockSysvar: { value: input.clockSysvar ?? null, isWritable: false }, + stakeHistorySysvar: { + value: input.stakeHistorySysvar ?? null, + isWritable: false, + }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + stakeProgram: { value: input.stakeProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.withdrawAuthority.value) { + accounts.withdrawAuthority.value = await findWithdrawAuthorityPda({ + stakePoolAddress: expectAddress(accounts.stakePool.value), + }); + } + if (!accounts.clockSysvar.value) { + accounts.clockSysvar.value = + "SysvarC1ock11111111111111111111111111111111" as Address<"SysvarC1ock11111111111111111111111111111111">; + } + if (!accounts.stakeHistorySysvar.value) { + accounts.stakeHistorySysvar.value = + "SysvarStakeHistory1111111111111111111111111" as Address<"SysvarStakeHistory1111111111111111111111111">; + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + if (!accounts.stakeProgram.value) { + accounts.stakeProgram.value = + "Stake11111111111111111111111111111111111111" as Address<"Stake11111111111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.staker), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.validatorList), + getAccountMeta(accounts.reserveStake), + getAccountMeta(accounts.canonicalStake), + getAccountMeta(accounts.ephemeralStake), + getAccountMeta(accounts.transientStake), + getAccountMeta(accounts.clockSysvar), + getAccountMeta(accounts.stakeHistorySysvar), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.stakeProgram), + ], + data: getDecreaseAdditionalValidatorStakeInstructionDataEncoder().encode( + args as DecreaseAdditionalValidatorStakeInstructionDataArgs, + ), + programAddress, + } as DecreaseAdditionalValidatorStakeInstruction< + TProgramAddress, + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountCanonicalStake, + TAccountEphemeralStake, + TAccountTransientStake, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountSystemProgram, + TAccountStakeProgram + >); +} + +export interface DecreaseAdditionalValidatorStakeInput< + TAccountStakePool extends string = string, + TAccountStaker extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountValidatorList extends string = string, + TAccountReserveStake extends string = string, + TAccountCanonicalStake extends string = string, + TAccountEphemeralStake extends string = string, + TAccountTransientStake extends string = string, + TAccountClockSysvar extends string = string, + TAccountStakeHistorySysvar extends string = string, + TAccountSystemProgram extends string = string, + TAccountStakeProgram extends string = string, +> { + stakePool: Address; + staker: TransactionSigner; + withdrawAuthority: Address; + validatorList: Address; + reserveStake: Address; + canonicalStake: Address; + ephemeralStake: Address; + transientStake: Address; + clockSysvar?: Address; + stakeHistorySysvar?: Address; + systemProgram?: Address; + stakeProgram?: Address; + lamports: DecreaseAdditionalValidatorStakeInstructionDataArgs["lamports"]; + transientStakeSeed: DecreaseAdditionalValidatorStakeInstructionDataArgs["transientStakeSeed"]; + ephemeralStakeSeed: DecreaseAdditionalValidatorStakeInstructionDataArgs["ephemeralStakeSeed"]; +} + +export function getDecreaseAdditionalValidatorStakeInstruction< + TAccountStakePool extends string, + TAccountStaker extends string, + TAccountWithdrawAuthority extends string, + TAccountValidatorList extends string, + TAccountReserveStake extends string, + TAccountCanonicalStake extends string, + TAccountEphemeralStake extends string, + TAccountTransientStake extends string, + TAccountClockSysvar extends string, + TAccountStakeHistorySysvar extends string, + TAccountSystemProgram extends string, + TAccountStakeProgram extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: DecreaseAdditionalValidatorStakeInput< + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountCanonicalStake, + TAccountEphemeralStake, + TAccountTransientStake, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountSystemProgram, + TAccountStakeProgram + >, + config?: { programAddress?: TProgramAddress }, +): DecreaseAdditionalValidatorStakeInstruction< + TProgramAddress, + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountCanonicalStake, + TAccountEphemeralStake, + TAccountTransientStake, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountSystemProgram, + TAccountStakeProgram +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: false }, + staker: { value: input.staker ?? null, isWritable: false }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + validatorList: { value: input.validatorList ?? null, isWritable: true }, + reserveStake: { value: input.reserveStake ?? null, isWritable: true }, + canonicalStake: { value: input.canonicalStake ?? null, isWritable: true }, + ephemeralStake: { value: input.ephemeralStake ?? null, isWritable: true }, + transientStake: { value: input.transientStake ?? null, isWritable: true }, + clockSysvar: { value: input.clockSysvar ?? null, isWritable: false }, + stakeHistorySysvar: { + value: input.stakeHistorySysvar ?? null, + isWritable: false, + }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + stakeProgram: { value: input.stakeProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.clockSysvar.value) { + accounts.clockSysvar.value = + "SysvarC1ock11111111111111111111111111111111" as Address<"SysvarC1ock11111111111111111111111111111111">; + } + if (!accounts.stakeHistorySysvar.value) { + accounts.stakeHistorySysvar.value = + "SysvarStakeHistory1111111111111111111111111" as Address<"SysvarStakeHistory1111111111111111111111111">; + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + if (!accounts.stakeProgram.value) { + accounts.stakeProgram.value = + "Stake11111111111111111111111111111111111111" as Address<"Stake11111111111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.staker), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.validatorList), + getAccountMeta(accounts.reserveStake), + getAccountMeta(accounts.canonicalStake), + getAccountMeta(accounts.ephemeralStake), + getAccountMeta(accounts.transientStake), + getAccountMeta(accounts.clockSysvar), + getAccountMeta(accounts.stakeHistorySysvar), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.stakeProgram), + ], + data: getDecreaseAdditionalValidatorStakeInstructionDataEncoder().encode( + args as DecreaseAdditionalValidatorStakeInstructionDataArgs, + ), + programAddress, + } as DecreaseAdditionalValidatorStakeInstruction< + TProgramAddress, + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountCanonicalStake, + TAccountEphemeralStake, + TAccountTransientStake, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountSystemProgram, + TAccountStakeProgram + >); +} + +export interface ParsedDecreaseAdditionalValidatorStakeInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + stakePool: TAccountMetas[0]; + staker: TAccountMetas[1]; + withdrawAuthority: TAccountMetas[2]; + validatorList: TAccountMetas[3]; + reserveStake: TAccountMetas[4]; + canonicalStake: TAccountMetas[5]; + ephemeralStake: TAccountMetas[6]; + transientStake: TAccountMetas[7]; + clockSysvar: TAccountMetas[8]; + stakeHistorySysvar: TAccountMetas[9]; + systemProgram: TAccountMetas[10]; + stakeProgram: TAccountMetas[11]; + }; + data: DecreaseAdditionalValidatorStakeInstructionData; +} + +export function parseDecreaseAdditionalValidatorStakeInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedDecreaseAdditionalValidatorStakeInstruction { + if (instruction.accounts.length < 12) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + stakePool: getNextAccount(), + staker: getNextAccount(), + withdrawAuthority: getNextAccount(), + validatorList: getNextAccount(), + reserveStake: getNextAccount(), + canonicalStake: getNextAccount(), + ephemeralStake: getNextAccount(), + transientStake: getNextAccount(), + clockSysvar: getNextAccount(), + stakeHistorySysvar: getNextAccount(), + systemProgram: getNextAccount(), + stakeProgram: getNextAccount(), + }, + data: getDecreaseAdditionalValidatorStakeInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/spl-stake-pool/src/generated/instructions/decreaseValidatorStake.ts b/clients/spl-stake-pool/src/generated/instructions/decreaseValidatorStake.ts new file mode 100644 index 00000000..315bb4c8 --- /dev/null +++ b/clients/spl-stake-pool/src/generated/instructions/decreaseValidatorStake.ts @@ -0,0 +1,506 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getU64Decoder, + getU64Encoder, + transformEncoder, +} from "@solana/kit"; +import { findWithdrawAuthorityPda } from "../pdas/index.js"; +import { SPL_STAKE_POOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; + +export const DECREASE_VALIDATOR_STAKE_DISCRIMINATOR = 3; + +export function getDecreaseValidatorStakeDiscriminatorBytes(): ReadonlyUint8Array { + return getU8Encoder().encode(DECREASE_VALIDATOR_STAKE_DISCRIMINATOR); +} + +export type DecreaseValidatorStakeInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountStakePool extends string | AccountMeta = string, + TAccountStaker extends string | AccountMeta = string, + TAccountWithdrawAuthority extends string | AccountMeta = string, + TAccountValidatorList extends string | AccountMeta = string, + TAccountStakeAccount extends string | AccountMeta = string, + TAccountTransientStakeAccount extends string | AccountMeta = string, + TAccountClockSysvar extends + | string + | AccountMeta = "SysvarC1ock11111111111111111111111111111111", + TAccountRentSysvar extends + | string + | AccountMeta = "SysvarRent111111111111111111111111111111111", + TAccountSystemProgram extends + | string + | AccountMeta = "11111111111111111111111111111111", + TAccountStakeProgram extends + | string + | AccountMeta = "Stake11111111111111111111111111111111111111", + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountStakePool extends string + ? ReadonlyAccount + : TAccountStakePool, + TAccountStaker extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountStaker, + TAccountWithdrawAuthority extends string + ? ReadonlyAccount + : TAccountWithdrawAuthority, + TAccountValidatorList extends string + ? WritableAccount + : TAccountValidatorList, + TAccountStakeAccount extends string + ? WritableAccount + : TAccountStakeAccount, + TAccountTransientStakeAccount extends string + ? WritableAccount + : TAccountTransientStakeAccount, + TAccountClockSysvar extends string + ? ReadonlyAccount + : TAccountClockSysvar, + TAccountRentSysvar extends string + ? ReadonlyAccount + : TAccountRentSysvar, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + TAccountStakeProgram extends string + ? ReadonlyAccount + : TAccountStakeProgram, + ...TRemainingAccounts, + ] + >; + +export interface DecreaseValidatorStakeInstructionData { + discriminator: number; + lamports: bigint; + transientStakeSeed: bigint; +} + +export interface DecreaseValidatorStakeInstructionDataArgs { + lamports: number | bigint; + transientStakeSeed: number | bigint; +} + +export function getDecreaseValidatorStakeInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", getU8Encoder()], + ["lamports", getU64Encoder()], + ["transientStakeSeed", getU64Encoder()], + ]), + (value) => ({ + ...value, + discriminator: DECREASE_VALIDATOR_STAKE_DISCRIMINATOR, + }), + ); +} + +export function getDecreaseValidatorStakeInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", getU8Decoder()], + ["lamports", getU64Decoder()], + ["transientStakeSeed", getU64Decoder()], + ]); +} + +export function getDecreaseValidatorStakeInstructionDataCodec(): FixedSizeCodec< + DecreaseValidatorStakeInstructionDataArgs, + DecreaseValidatorStakeInstructionData +> { + return combineCodec( + getDecreaseValidatorStakeInstructionDataEncoder(), + getDecreaseValidatorStakeInstructionDataDecoder(), + ); +} + +export interface DecreaseValidatorStakeAsyncInput< + TAccountStakePool extends string = string, + TAccountStaker extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountValidatorList extends string = string, + TAccountStakeAccount extends string = string, + TAccountTransientStakeAccount extends string = string, + TAccountClockSysvar extends string = string, + TAccountRentSysvar extends string = string, + TAccountSystemProgram extends string = string, + TAccountStakeProgram extends string = string, +> { + stakePool: Address; + staker: TransactionSigner; + withdrawAuthority?: Address; + validatorList: Address; + stakeAccount: Address; + transientStakeAccount: Address; + clockSysvar?: Address; + rentSysvar?: Address; + systemProgram?: Address; + stakeProgram?: Address; + lamports: DecreaseValidatorStakeInstructionDataArgs["lamports"]; + transientStakeSeed: DecreaseValidatorStakeInstructionDataArgs["transientStakeSeed"]; +} + +export async function getDecreaseValidatorStakeInstructionAsync< + TAccountStakePool extends string, + TAccountStaker extends string, + TAccountWithdrawAuthority extends string, + TAccountValidatorList extends string, + TAccountStakeAccount extends string, + TAccountTransientStakeAccount extends string, + TAccountClockSysvar extends string, + TAccountRentSysvar extends string, + TAccountSystemProgram extends string, + TAccountStakeProgram extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: DecreaseValidatorStakeAsyncInput< + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountStakeAccount, + TAccountTransientStakeAccount, + TAccountClockSysvar, + TAccountRentSysvar, + TAccountSystemProgram, + TAccountStakeProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + DecreaseValidatorStakeInstruction< + TProgramAddress, + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountStakeAccount, + TAccountTransientStakeAccount, + TAccountClockSysvar, + TAccountRentSysvar, + TAccountSystemProgram, + TAccountStakeProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: false }, + staker: { value: input.staker ?? null, isWritable: false }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + validatorList: { value: input.validatorList ?? null, isWritable: true }, + stakeAccount: { value: input.stakeAccount ?? null, isWritable: true }, + transientStakeAccount: { + value: input.transientStakeAccount ?? null, + isWritable: true, + }, + clockSysvar: { value: input.clockSysvar ?? null, isWritable: false }, + rentSysvar: { value: input.rentSysvar ?? null, isWritable: false }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + stakeProgram: { value: input.stakeProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.withdrawAuthority.value) { + accounts.withdrawAuthority.value = await findWithdrawAuthorityPda({ + stakePoolAddress: expectAddress(accounts.stakePool.value), + }); + } + if (!accounts.clockSysvar.value) { + accounts.clockSysvar.value = + "SysvarC1ock11111111111111111111111111111111" as Address<"SysvarC1ock11111111111111111111111111111111">; + } + if (!accounts.rentSysvar.value) { + accounts.rentSysvar.value = + "SysvarRent111111111111111111111111111111111" as Address<"SysvarRent111111111111111111111111111111111">; + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + if (!accounts.stakeProgram.value) { + accounts.stakeProgram.value = + "Stake11111111111111111111111111111111111111" as Address<"Stake11111111111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.staker), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.validatorList), + getAccountMeta(accounts.stakeAccount), + getAccountMeta(accounts.transientStakeAccount), + getAccountMeta(accounts.clockSysvar), + getAccountMeta(accounts.rentSysvar), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.stakeProgram), + ], + data: getDecreaseValidatorStakeInstructionDataEncoder().encode( + args as DecreaseValidatorStakeInstructionDataArgs, + ), + programAddress, + } as DecreaseValidatorStakeInstruction< + TProgramAddress, + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountStakeAccount, + TAccountTransientStakeAccount, + TAccountClockSysvar, + TAccountRentSysvar, + TAccountSystemProgram, + TAccountStakeProgram + >); +} + +export interface DecreaseValidatorStakeInput< + TAccountStakePool extends string = string, + TAccountStaker extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountValidatorList extends string = string, + TAccountStakeAccount extends string = string, + TAccountTransientStakeAccount extends string = string, + TAccountClockSysvar extends string = string, + TAccountRentSysvar extends string = string, + TAccountSystemProgram extends string = string, + TAccountStakeProgram extends string = string, +> { + stakePool: Address; + staker: TransactionSigner; + withdrawAuthority: Address; + validatorList: Address; + stakeAccount: Address; + transientStakeAccount: Address; + clockSysvar?: Address; + rentSysvar?: Address; + systemProgram?: Address; + stakeProgram?: Address; + lamports: DecreaseValidatorStakeInstructionDataArgs["lamports"]; + transientStakeSeed: DecreaseValidatorStakeInstructionDataArgs["transientStakeSeed"]; +} + +export function getDecreaseValidatorStakeInstruction< + TAccountStakePool extends string, + TAccountStaker extends string, + TAccountWithdrawAuthority extends string, + TAccountValidatorList extends string, + TAccountStakeAccount extends string, + TAccountTransientStakeAccount extends string, + TAccountClockSysvar extends string, + TAccountRentSysvar extends string, + TAccountSystemProgram extends string, + TAccountStakeProgram extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: DecreaseValidatorStakeInput< + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountStakeAccount, + TAccountTransientStakeAccount, + TAccountClockSysvar, + TAccountRentSysvar, + TAccountSystemProgram, + TAccountStakeProgram + >, + config?: { programAddress?: TProgramAddress }, +): DecreaseValidatorStakeInstruction< + TProgramAddress, + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountStakeAccount, + TAccountTransientStakeAccount, + TAccountClockSysvar, + TAccountRentSysvar, + TAccountSystemProgram, + TAccountStakeProgram +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: false }, + staker: { value: input.staker ?? null, isWritable: false }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + validatorList: { value: input.validatorList ?? null, isWritable: true }, + stakeAccount: { value: input.stakeAccount ?? null, isWritable: true }, + transientStakeAccount: { + value: input.transientStakeAccount ?? null, + isWritable: true, + }, + clockSysvar: { value: input.clockSysvar ?? null, isWritable: false }, + rentSysvar: { value: input.rentSysvar ?? null, isWritable: false }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + stakeProgram: { value: input.stakeProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.clockSysvar.value) { + accounts.clockSysvar.value = + "SysvarC1ock11111111111111111111111111111111" as Address<"SysvarC1ock11111111111111111111111111111111">; + } + if (!accounts.rentSysvar.value) { + accounts.rentSysvar.value = + "SysvarRent111111111111111111111111111111111" as Address<"SysvarRent111111111111111111111111111111111">; + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + if (!accounts.stakeProgram.value) { + accounts.stakeProgram.value = + "Stake11111111111111111111111111111111111111" as Address<"Stake11111111111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.staker), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.validatorList), + getAccountMeta(accounts.stakeAccount), + getAccountMeta(accounts.transientStakeAccount), + getAccountMeta(accounts.clockSysvar), + getAccountMeta(accounts.rentSysvar), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.stakeProgram), + ], + data: getDecreaseValidatorStakeInstructionDataEncoder().encode( + args as DecreaseValidatorStakeInstructionDataArgs, + ), + programAddress, + } as DecreaseValidatorStakeInstruction< + TProgramAddress, + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountStakeAccount, + TAccountTransientStakeAccount, + TAccountClockSysvar, + TAccountRentSysvar, + TAccountSystemProgram, + TAccountStakeProgram + >); +} + +export interface ParsedDecreaseValidatorStakeInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + stakePool: TAccountMetas[0]; + staker: TAccountMetas[1]; + withdrawAuthority: TAccountMetas[2]; + validatorList: TAccountMetas[3]; + stakeAccount: TAccountMetas[4]; + transientStakeAccount: TAccountMetas[5]; + clockSysvar: TAccountMetas[6]; + rentSysvar: TAccountMetas[7]; + systemProgram: TAccountMetas[8]; + stakeProgram: TAccountMetas[9]; + }; + data: DecreaseValidatorStakeInstructionData; +} + +export function parseDecreaseValidatorStakeInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedDecreaseValidatorStakeInstruction { + if (instruction.accounts.length < 10) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + stakePool: getNextAccount(), + staker: getNextAccount(), + withdrawAuthority: getNextAccount(), + validatorList: getNextAccount(), + stakeAccount: getNextAccount(), + transientStakeAccount: getNextAccount(), + clockSysvar: getNextAccount(), + rentSysvar: getNextAccount(), + systemProgram: getNextAccount(), + stakeProgram: getNextAccount(), + }, + data: getDecreaseValidatorStakeInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/spl-stake-pool/src/generated/instructions/decreaseValidatorStakeWithReserve.ts b/clients/spl-stake-pool/src/generated/instructions/decreaseValidatorStakeWithReserve.ts new file mode 100644 index 00000000..67b434b2 --- /dev/null +++ b/clients/spl-stake-pool/src/generated/instructions/decreaseValidatorStakeWithReserve.ts @@ -0,0 +1,530 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getU64Decoder, + getU64Encoder, + transformEncoder, +} from "@solana/kit"; +import { findWithdrawAuthorityPda } from "../pdas/index.js"; +import { SPL_STAKE_POOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; + +export const DECREASE_VALIDATOR_STAKE_WITH_RESERVE_DISCRIMINATOR = 21; + +export function getDecreaseValidatorStakeWithReserveDiscriminatorBytes(): ReadonlyUint8Array { + return getU8Encoder().encode( + DECREASE_VALIDATOR_STAKE_WITH_RESERVE_DISCRIMINATOR, + ); +} + +export type DecreaseValidatorStakeWithReserveInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountStakePool extends string | AccountMeta = string, + TAccountStaker extends string | AccountMeta = string, + TAccountWithdrawAuthority extends string | AccountMeta = string, + TAccountValidatorList extends string | AccountMeta = string, + TAccountReserveStake extends string | AccountMeta = string, + TAccountCanonicalStake extends string | AccountMeta = string, + TAccountTransientStake extends string | AccountMeta = string, + TAccountClockSysvar extends + | string + | AccountMeta = "SysvarC1ock11111111111111111111111111111111", + TAccountStakeHistorySysvar extends + | string + | AccountMeta = "SysvarStakeHistory1111111111111111111111111", + TAccountSystemProgram extends + | string + | AccountMeta = "11111111111111111111111111111111", + TAccountStakeProgram extends + | string + | AccountMeta = "Stake11111111111111111111111111111111111111", + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountStakePool extends string + ? ReadonlyAccount + : TAccountStakePool, + TAccountStaker extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountStaker, + TAccountWithdrawAuthority extends string + ? ReadonlyAccount + : TAccountWithdrawAuthority, + TAccountValidatorList extends string + ? WritableAccount + : TAccountValidatorList, + TAccountReserveStake extends string + ? WritableAccount + : TAccountReserveStake, + TAccountCanonicalStake extends string + ? WritableAccount + : TAccountCanonicalStake, + TAccountTransientStake extends string + ? WritableAccount + : TAccountTransientStake, + TAccountClockSysvar extends string + ? ReadonlyAccount + : TAccountClockSysvar, + TAccountStakeHistorySysvar extends string + ? ReadonlyAccount + : TAccountStakeHistorySysvar, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + TAccountStakeProgram extends string + ? ReadonlyAccount + : TAccountStakeProgram, + ...TRemainingAccounts, + ] + >; + +export interface DecreaseValidatorStakeWithReserveInstructionData { + discriminator: number; + lamports: bigint; + transientStakeSeed: bigint; +} + +export interface DecreaseValidatorStakeWithReserveInstructionDataArgs { + lamports: number | bigint; + transientStakeSeed: number | bigint; +} + +export function getDecreaseValidatorStakeWithReserveInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", getU8Encoder()], + ["lamports", getU64Encoder()], + ["transientStakeSeed", getU64Encoder()], + ]), + (value) => ({ + ...value, + discriminator: DECREASE_VALIDATOR_STAKE_WITH_RESERVE_DISCRIMINATOR, + }), + ); +} + +export function getDecreaseValidatorStakeWithReserveInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", getU8Decoder()], + ["lamports", getU64Decoder()], + ["transientStakeSeed", getU64Decoder()], + ]); +} + +export function getDecreaseValidatorStakeWithReserveInstructionDataCodec(): FixedSizeCodec< + DecreaseValidatorStakeWithReserveInstructionDataArgs, + DecreaseValidatorStakeWithReserveInstructionData +> { + return combineCodec( + getDecreaseValidatorStakeWithReserveInstructionDataEncoder(), + getDecreaseValidatorStakeWithReserveInstructionDataDecoder(), + ); +} + +export interface DecreaseValidatorStakeWithReserveAsyncInput< + TAccountStakePool extends string = string, + TAccountStaker extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountValidatorList extends string = string, + TAccountReserveStake extends string = string, + TAccountCanonicalStake extends string = string, + TAccountTransientStake extends string = string, + TAccountClockSysvar extends string = string, + TAccountStakeHistorySysvar extends string = string, + TAccountSystemProgram extends string = string, + TAccountStakeProgram extends string = string, +> { + stakePool: Address; + staker: TransactionSigner; + withdrawAuthority?: Address; + validatorList: Address; + reserveStake: Address; + canonicalStake: Address; + transientStake: Address; + clockSysvar?: Address; + stakeHistorySysvar?: Address; + systemProgram?: Address; + stakeProgram?: Address; + lamports: DecreaseValidatorStakeWithReserveInstructionDataArgs["lamports"]; + transientStakeSeed: DecreaseValidatorStakeWithReserveInstructionDataArgs["transientStakeSeed"]; +} + +export async function getDecreaseValidatorStakeWithReserveInstructionAsync< + TAccountStakePool extends string, + TAccountStaker extends string, + TAccountWithdrawAuthority extends string, + TAccountValidatorList extends string, + TAccountReserveStake extends string, + TAccountCanonicalStake extends string, + TAccountTransientStake extends string, + TAccountClockSysvar extends string, + TAccountStakeHistorySysvar extends string, + TAccountSystemProgram extends string, + TAccountStakeProgram extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: DecreaseValidatorStakeWithReserveAsyncInput< + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountCanonicalStake, + TAccountTransientStake, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountSystemProgram, + TAccountStakeProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + DecreaseValidatorStakeWithReserveInstruction< + TProgramAddress, + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountCanonicalStake, + TAccountTransientStake, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountSystemProgram, + TAccountStakeProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: false }, + staker: { value: input.staker ?? null, isWritable: false }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + validatorList: { value: input.validatorList ?? null, isWritable: true }, + reserveStake: { value: input.reserveStake ?? null, isWritable: true }, + canonicalStake: { value: input.canonicalStake ?? null, isWritable: true }, + transientStake: { value: input.transientStake ?? null, isWritable: true }, + clockSysvar: { value: input.clockSysvar ?? null, isWritable: false }, + stakeHistorySysvar: { + value: input.stakeHistorySysvar ?? null, + isWritable: false, + }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + stakeProgram: { value: input.stakeProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.withdrawAuthority.value) { + accounts.withdrawAuthority.value = await findWithdrawAuthorityPda({ + stakePoolAddress: expectAddress(accounts.stakePool.value), + }); + } + if (!accounts.clockSysvar.value) { + accounts.clockSysvar.value = + "SysvarC1ock11111111111111111111111111111111" as Address<"SysvarC1ock11111111111111111111111111111111">; + } + if (!accounts.stakeHistorySysvar.value) { + accounts.stakeHistorySysvar.value = + "SysvarStakeHistory1111111111111111111111111" as Address<"SysvarStakeHistory1111111111111111111111111">; + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + if (!accounts.stakeProgram.value) { + accounts.stakeProgram.value = + "Stake11111111111111111111111111111111111111" as Address<"Stake11111111111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.staker), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.validatorList), + getAccountMeta(accounts.reserveStake), + getAccountMeta(accounts.canonicalStake), + getAccountMeta(accounts.transientStake), + getAccountMeta(accounts.clockSysvar), + getAccountMeta(accounts.stakeHistorySysvar), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.stakeProgram), + ], + data: getDecreaseValidatorStakeWithReserveInstructionDataEncoder().encode( + args as DecreaseValidatorStakeWithReserveInstructionDataArgs, + ), + programAddress, + } as DecreaseValidatorStakeWithReserveInstruction< + TProgramAddress, + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountCanonicalStake, + TAccountTransientStake, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountSystemProgram, + TAccountStakeProgram + >); +} + +export interface DecreaseValidatorStakeWithReserveInput< + TAccountStakePool extends string = string, + TAccountStaker extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountValidatorList extends string = string, + TAccountReserveStake extends string = string, + TAccountCanonicalStake extends string = string, + TAccountTransientStake extends string = string, + TAccountClockSysvar extends string = string, + TAccountStakeHistorySysvar extends string = string, + TAccountSystemProgram extends string = string, + TAccountStakeProgram extends string = string, +> { + stakePool: Address; + staker: TransactionSigner; + withdrawAuthority: Address; + validatorList: Address; + reserveStake: Address; + canonicalStake: Address; + transientStake: Address; + clockSysvar?: Address; + stakeHistorySysvar?: Address; + systemProgram?: Address; + stakeProgram?: Address; + lamports: DecreaseValidatorStakeWithReserveInstructionDataArgs["lamports"]; + transientStakeSeed: DecreaseValidatorStakeWithReserveInstructionDataArgs["transientStakeSeed"]; +} + +export function getDecreaseValidatorStakeWithReserveInstruction< + TAccountStakePool extends string, + TAccountStaker extends string, + TAccountWithdrawAuthority extends string, + TAccountValidatorList extends string, + TAccountReserveStake extends string, + TAccountCanonicalStake extends string, + TAccountTransientStake extends string, + TAccountClockSysvar extends string, + TAccountStakeHistorySysvar extends string, + TAccountSystemProgram extends string, + TAccountStakeProgram extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: DecreaseValidatorStakeWithReserveInput< + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountCanonicalStake, + TAccountTransientStake, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountSystemProgram, + TAccountStakeProgram + >, + config?: { programAddress?: TProgramAddress }, +): DecreaseValidatorStakeWithReserveInstruction< + TProgramAddress, + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountCanonicalStake, + TAccountTransientStake, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountSystemProgram, + TAccountStakeProgram +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: false }, + staker: { value: input.staker ?? null, isWritable: false }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + validatorList: { value: input.validatorList ?? null, isWritable: true }, + reserveStake: { value: input.reserveStake ?? null, isWritable: true }, + canonicalStake: { value: input.canonicalStake ?? null, isWritable: true }, + transientStake: { value: input.transientStake ?? null, isWritable: true }, + clockSysvar: { value: input.clockSysvar ?? null, isWritable: false }, + stakeHistorySysvar: { + value: input.stakeHistorySysvar ?? null, + isWritable: false, + }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + stakeProgram: { value: input.stakeProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.clockSysvar.value) { + accounts.clockSysvar.value = + "SysvarC1ock11111111111111111111111111111111" as Address<"SysvarC1ock11111111111111111111111111111111">; + } + if (!accounts.stakeHistorySysvar.value) { + accounts.stakeHistorySysvar.value = + "SysvarStakeHistory1111111111111111111111111" as Address<"SysvarStakeHistory1111111111111111111111111">; + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + if (!accounts.stakeProgram.value) { + accounts.stakeProgram.value = + "Stake11111111111111111111111111111111111111" as Address<"Stake11111111111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.staker), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.validatorList), + getAccountMeta(accounts.reserveStake), + getAccountMeta(accounts.canonicalStake), + getAccountMeta(accounts.transientStake), + getAccountMeta(accounts.clockSysvar), + getAccountMeta(accounts.stakeHistorySysvar), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.stakeProgram), + ], + data: getDecreaseValidatorStakeWithReserveInstructionDataEncoder().encode( + args as DecreaseValidatorStakeWithReserveInstructionDataArgs, + ), + programAddress, + } as DecreaseValidatorStakeWithReserveInstruction< + TProgramAddress, + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountCanonicalStake, + TAccountTransientStake, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountSystemProgram, + TAccountStakeProgram + >); +} + +export interface ParsedDecreaseValidatorStakeWithReserveInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + stakePool: TAccountMetas[0]; + staker: TAccountMetas[1]; + withdrawAuthority: TAccountMetas[2]; + validatorList: TAccountMetas[3]; + reserveStake: TAccountMetas[4]; + canonicalStake: TAccountMetas[5]; + transientStake: TAccountMetas[6]; + clockSysvar: TAccountMetas[7]; + stakeHistorySysvar: TAccountMetas[8]; + systemProgram: TAccountMetas[9]; + stakeProgram: TAccountMetas[10]; + }; + data: DecreaseValidatorStakeWithReserveInstructionData; +} + +export function parseDecreaseValidatorStakeWithReserveInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedDecreaseValidatorStakeWithReserveInstruction { + if (instruction.accounts.length < 11) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + stakePool: getNextAccount(), + staker: getNextAccount(), + withdrawAuthority: getNextAccount(), + validatorList: getNextAccount(), + reserveStake: getNextAccount(), + canonicalStake: getNextAccount(), + transientStake: getNextAccount(), + clockSysvar: getNextAccount(), + stakeHistorySysvar: getNextAccount(), + systemProgram: getNextAccount(), + stakeProgram: getNextAccount(), + }, + data: getDecreaseValidatorStakeWithReserveInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/spl-stake-pool/src/generated/instructions/depositSol.ts b/clients/spl-stake-pool/src/generated/instructions/depositSol.ts new file mode 100644 index 00000000..ca84924f --- /dev/null +++ b/clients/spl-stake-pool/src/generated/instructions/depositSol.ts @@ -0,0 +1,556 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, + WritableSignerAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getU64Decoder, + getU64Encoder, + transformEncoder, +} from "@solana/kit"; +import { findWithdrawAuthorityPda } from "../pdas/index.js"; +import { SPL_STAKE_POOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; + +export const DEPOSIT_SOL_DISCRIMINATOR = 14; + +export function getDepositSolDiscriminatorBytes(): ReadonlyUint8Array { + return getU8Encoder().encode(DEPOSIT_SOL_DISCRIMINATOR); +} + +export type DepositSolInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountStakePool extends string | AccountMeta = string, + TAccountWithdrawAuthority extends string | AccountMeta = string, + TAccountReserveStake extends string | AccountMeta = string, + TAccountPayer extends string | AccountMeta = string, + TAccountUserPoolTokenAccount extends string | AccountMeta = string, + TAccountManagerFeeAccount extends string | AccountMeta = string, + TAccountReferralPoolAccount extends string | AccountMeta = string, + TAccountPoolMint extends string | AccountMeta = string, + TAccountSystemProgram extends + | string + | AccountMeta = "11111111111111111111111111111111", + TAccountTokenProgram extends + | string + | AccountMeta = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + TAccountDepositAuthority extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountStakePool extends string + ? WritableAccount + : TAccountStakePool, + TAccountWithdrawAuthority extends string + ? ReadonlyAccount + : TAccountWithdrawAuthority, + TAccountReserveStake extends string + ? WritableAccount + : TAccountReserveStake, + TAccountPayer extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountPayer, + TAccountUserPoolTokenAccount extends string + ? WritableAccount + : TAccountUserPoolTokenAccount, + TAccountManagerFeeAccount extends string + ? WritableAccount + : TAccountManagerFeeAccount, + TAccountReferralPoolAccount extends string + ? WritableAccount + : TAccountReferralPoolAccount, + TAccountPoolMint extends string + ? WritableAccount + : TAccountPoolMint, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + TAccountDepositAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountDepositAuthority, + ...TRemainingAccounts, + ] + >; + +export interface DepositSolInstructionData { + discriminator: number; + args: bigint; +} + +export interface DepositSolInstructionDataArgs { + args: number | bigint; +} + +export function getDepositSolInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", getU8Encoder()], + ["args", getU64Encoder()], + ]), + (value) => ({ ...value, discriminator: DEPOSIT_SOL_DISCRIMINATOR }), + ); +} + +export function getDepositSolInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", getU8Decoder()], + ["args", getU64Decoder()], + ]); +} + +export function getDepositSolInstructionDataCodec(): FixedSizeCodec< + DepositSolInstructionDataArgs, + DepositSolInstructionData +> { + return combineCodec( + getDepositSolInstructionDataEncoder(), + getDepositSolInstructionDataDecoder(), + ); +} + +export interface DepositSolAsyncInput< + TAccountStakePool extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountReserveStake extends string = string, + TAccountPayer extends string = string, + TAccountUserPoolTokenAccount extends string = string, + TAccountManagerFeeAccount extends string = string, + TAccountReferralPoolAccount extends string = string, + TAccountPoolMint extends string = string, + TAccountSystemProgram extends string = string, + TAccountTokenProgram extends string = string, + TAccountDepositAuthority extends string = string, +> { + /** Stake pool */ + stakePool: Address; + /** Stake pool withdraw authority */ + withdrawAuthority?: Address; + /** Reserve stake account, to deposit SOL */ + reserveStake: Address; + /** Account providing the lamports to be deposited into the pool */ + payer: TransactionSigner; + /** User account to receive pool tokens */ + userPoolTokenAccount: Address; + /** Account to receive fee tokens */ + managerFeeAccount: Address; + /** Account to receive a portion of fee as referral fees */ + referralPoolAccount: Address; + /** Pool token mint account */ + poolMint: Address; + /** System program account */ + systemProgram?: Address; + /** Token program id */ + tokenProgram?: Address; + /** (Optional) Stake pool sol deposit authority. */ + depositAuthority?: TransactionSigner; + args: DepositSolInstructionDataArgs["args"]; +} + +export async function getDepositSolInstructionAsync< + TAccountStakePool extends string, + TAccountWithdrawAuthority extends string, + TAccountReserveStake extends string, + TAccountPayer extends string, + TAccountUserPoolTokenAccount extends string, + TAccountManagerFeeAccount extends string, + TAccountReferralPoolAccount extends string, + TAccountPoolMint extends string, + TAccountSystemProgram extends string, + TAccountTokenProgram extends string, + TAccountDepositAuthority extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: DepositSolAsyncInput< + TAccountStakePool, + TAccountWithdrawAuthority, + TAccountReserveStake, + TAccountPayer, + TAccountUserPoolTokenAccount, + TAccountManagerFeeAccount, + TAccountReferralPoolAccount, + TAccountPoolMint, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountDepositAuthority + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + DepositSolInstruction< + TProgramAddress, + TAccountStakePool, + TAccountWithdrawAuthority, + TAccountReserveStake, + TAccountPayer, + TAccountUserPoolTokenAccount, + TAccountManagerFeeAccount, + TAccountReferralPoolAccount, + TAccountPoolMint, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountDepositAuthority + > +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: true }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + reserveStake: { value: input.reserveStake ?? null, isWritable: true }, + payer: { value: input.payer ?? null, isWritable: true }, + userPoolTokenAccount: { + value: input.userPoolTokenAccount ?? null, + isWritable: true, + }, + managerFeeAccount: { + value: input.managerFeeAccount ?? null, + isWritable: true, + }, + referralPoolAccount: { + value: input.referralPoolAccount ?? null, + isWritable: true, + }, + poolMint: { value: input.poolMint ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + depositAuthority: { + value: input.depositAuthority ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.withdrawAuthority.value) { + accounts.withdrawAuthority.value = await findWithdrawAuthorityPda({ + stakePoolAddress: expectAddress(accounts.stakePool.value), + }); + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.reserveStake), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.userPoolTokenAccount), + getAccountMeta(accounts.managerFeeAccount), + getAccountMeta(accounts.referralPoolAccount), + getAccountMeta(accounts.poolMint), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.depositAuthority), + ], + data: getDepositSolInstructionDataEncoder().encode( + args as DepositSolInstructionDataArgs, + ), + programAddress, + } as DepositSolInstruction< + TProgramAddress, + TAccountStakePool, + TAccountWithdrawAuthority, + TAccountReserveStake, + TAccountPayer, + TAccountUserPoolTokenAccount, + TAccountManagerFeeAccount, + TAccountReferralPoolAccount, + TAccountPoolMint, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountDepositAuthority + >); +} + +export interface DepositSolInput< + TAccountStakePool extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountReserveStake extends string = string, + TAccountPayer extends string = string, + TAccountUserPoolTokenAccount extends string = string, + TAccountManagerFeeAccount extends string = string, + TAccountReferralPoolAccount extends string = string, + TAccountPoolMint extends string = string, + TAccountSystemProgram extends string = string, + TAccountTokenProgram extends string = string, + TAccountDepositAuthority extends string = string, +> { + /** Stake pool */ + stakePool: Address; + /** Stake pool withdraw authority */ + withdrawAuthority: Address; + /** Reserve stake account, to deposit SOL */ + reserveStake: Address; + /** Account providing the lamports to be deposited into the pool */ + payer: TransactionSigner; + /** User account to receive pool tokens */ + userPoolTokenAccount: Address; + /** Account to receive fee tokens */ + managerFeeAccount: Address; + /** Account to receive a portion of fee as referral fees */ + referralPoolAccount: Address; + /** Pool token mint account */ + poolMint: Address; + /** System program account */ + systemProgram?: Address; + /** Token program id */ + tokenProgram?: Address; + /** (Optional) Stake pool sol deposit authority. */ + depositAuthority?: TransactionSigner; + args: DepositSolInstructionDataArgs["args"]; +} + +export function getDepositSolInstruction< + TAccountStakePool extends string, + TAccountWithdrawAuthority extends string, + TAccountReserveStake extends string, + TAccountPayer extends string, + TAccountUserPoolTokenAccount extends string, + TAccountManagerFeeAccount extends string, + TAccountReferralPoolAccount extends string, + TAccountPoolMint extends string, + TAccountSystemProgram extends string, + TAccountTokenProgram extends string, + TAccountDepositAuthority extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: DepositSolInput< + TAccountStakePool, + TAccountWithdrawAuthority, + TAccountReserveStake, + TAccountPayer, + TAccountUserPoolTokenAccount, + TAccountManagerFeeAccount, + TAccountReferralPoolAccount, + TAccountPoolMint, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountDepositAuthority + >, + config?: { programAddress?: TProgramAddress }, +): DepositSolInstruction< + TProgramAddress, + TAccountStakePool, + TAccountWithdrawAuthority, + TAccountReserveStake, + TAccountPayer, + TAccountUserPoolTokenAccount, + TAccountManagerFeeAccount, + TAccountReferralPoolAccount, + TAccountPoolMint, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountDepositAuthority +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: true }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + reserveStake: { value: input.reserveStake ?? null, isWritable: true }, + payer: { value: input.payer ?? null, isWritable: true }, + userPoolTokenAccount: { + value: input.userPoolTokenAccount ?? null, + isWritable: true, + }, + managerFeeAccount: { + value: input.managerFeeAccount ?? null, + isWritable: true, + }, + referralPoolAccount: { + value: input.referralPoolAccount ?? null, + isWritable: true, + }, + poolMint: { value: input.poolMint ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + depositAuthority: { + value: input.depositAuthority ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.reserveStake), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.userPoolTokenAccount), + getAccountMeta(accounts.managerFeeAccount), + getAccountMeta(accounts.referralPoolAccount), + getAccountMeta(accounts.poolMint), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.depositAuthority), + ], + data: getDepositSolInstructionDataEncoder().encode( + args as DepositSolInstructionDataArgs, + ), + programAddress, + } as DepositSolInstruction< + TProgramAddress, + TAccountStakePool, + TAccountWithdrawAuthority, + TAccountReserveStake, + TAccountPayer, + TAccountUserPoolTokenAccount, + TAccountManagerFeeAccount, + TAccountReferralPoolAccount, + TAccountPoolMint, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountDepositAuthority + >); +} + +export interface ParsedDepositSolInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + /** Stake pool */ + stakePool: TAccountMetas[0]; + /** Stake pool withdraw authority */ + withdrawAuthority: TAccountMetas[1]; + /** Reserve stake account, to deposit SOL */ + reserveStake: TAccountMetas[2]; + /** Account providing the lamports to be deposited into the pool */ + payer: TAccountMetas[3]; + /** User account to receive pool tokens */ + userPoolTokenAccount: TAccountMetas[4]; + /** Account to receive fee tokens */ + managerFeeAccount: TAccountMetas[5]; + /** Account to receive a portion of fee as referral fees */ + referralPoolAccount: TAccountMetas[6]; + /** Pool token mint account */ + poolMint: TAccountMetas[7]; + /** System program account */ + systemProgram: TAccountMetas[8]; + /** Token program id */ + tokenProgram: TAccountMetas[9]; + /** (Optional) Stake pool sol deposit authority. */ + depositAuthority?: TAccountMetas[10] | undefined; + }; + data: DepositSolInstructionData; +} + +export function parseDepositSolInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedDepositSolInstruction { + if (instruction.accounts.length < 11) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + const getNextOptionalAccount = () => { + const accountMeta = getNextAccount(); + return accountMeta.address === SPL_STAKE_POOL_PROGRAM_ADDRESS + ? undefined + : accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + stakePool: getNextAccount(), + withdrawAuthority: getNextAccount(), + reserveStake: getNextAccount(), + payer: getNextAccount(), + userPoolTokenAccount: getNextAccount(), + managerFeeAccount: getNextAccount(), + referralPoolAccount: getNextAccount(), + poolMint: getNextAccount(), + systemProgram: getNextAccount(), + tokenProgram: getNextAccount(), + depositAuthority: getNextOptionalAccount(), + }, + data: getDepositSolInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/spl-stake-pool/src/generated/instructions/depositSolWithSlippage.ts b/clients/spl-stake-pool/src/generated/instructions/depositSolWithSlippage.ts new file mode 100644 index 00000000..b6b914cd --- /dev/null +++ b/clients/spl-stake-pool/src/generated/instructions/depositSolWithSlippage.ts @@ -0,0 +1,569 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getU64Decoder, + getU64Encoder, + transformEncoder, +} from "@solana/kit"; +import { findWithdrawAuthorityPda } from "../pdas/index.js"; +import { SPL_STAKE_POOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; + +export const DEPOSIT_SOL_WITH_SLIPPAGE_DISCRIMINATOR = 25; + +export function getDepositSolWithSlippageDiscriminatorBytes(): ReadonlyUint8Array { + return getU8Encoder().encode(DEPOSIT_SOL_WITH_SLIPPAGE_DISCRIMINATOR); +} + +export type DepositSolWithSlippageInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountStakePool extends string | AccountMeta = string, + TAccountWithdrawAuthority extends string | AccountMeta = string, + TAccountReserveStake extends string | AccountMeta = string, + TAccountPayer extends string | AccountMeta = string, + TAccountUserPoolTokenAccount extends string | AccountMeta = string, + TAccountFeeAccount extends string | AccountMeta = string, + TAccountReferralFeeAccount extends string | AccountMeta = string, + TAccountPoolMint extends string | AccountMeta = string, + TAccountSystemProgram extends + | string + | AccountMeta = "11111111111111111111111111111111", + TAccountTokenProgram extends + | string + | AccountMeta = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + TAccountSolDepositAuthority extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountStakePool extends string + ? WritableAccount + : TAccountStakePool, + TAccountWithdrawAuthority extends string + ? ReadonlyAccount + : TAccountWithdrawAuthority, + TAccountReserveStake extends string + ? WritableAccount + : TAccountReserveStake, + TAccountPayer extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountPayer, + TAccountUserPoolTokenAccount extends string + ? WritableAccount + : TAccountUserPoolTokenAccount, + TAccountFeeAccount extends string + ? WritableAccount + : TAccountFeeAccount, + TAccountReferralFeeAccount extends string + ? WritableAccount + : TAccountReferralFeeAccount, + TAccountPoolMint extends string + ? WritableAccount + : TAccountPoolMint, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + TAccountSolDepositAuthority extends string + ? ReadonlyAccount + : TAccountSolDepositAuthority, + ...TRemainingAccounts, + ] + >; + +export interface DepositSolWithSlippageInstructionData { + discriminator: number; + lamportsIn: bigint; + minimumPoolTokensOut: bigint; +} + +export interface DepositSolWithSlippageInstructionDataArgs { + lamportsIn: number | bigint; + minimumPoolTokensOut: number | bigint; +} + +export function getDepositSolWithSlippageInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", getU8Encoder()], + ["lamportsIn", getU64Encoder()], + ["minimumPoolTokensOut", getU64Encoder()], + ]), + (value) => ({ + ...value, + discriminator: DEPOSIT_SOL_WITH_SLIPPAGE_DISCRIMINATOR, + }), + ); +} + +export function getDepositSolWithSlippageInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", getU8Decoder()], + ["lamportsIn", getU64Decoder()], + ["minimumPoolTokensOut", getU64Decoder()], + ]); +} + +export function getDepositSolWithSlippageInstructionDataCodec(): FixedSizeCodec< + DepositSolWithSlippageInstructionDataArgs, + DepositSolWithSlippageInstructionData +> { + return combineCodec( + getDepositSolWithSlippageInstructionDataEncoder(), + getDepositSolWithSlippageInstructionDataDecoder(), + ); +} + +export interface DepositSolWithSlippageAsyncInput< + TAccountStakePool extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountReserveStake extends string = string, + TAccountPayer extends string = string, + TAccountUserPoolTokenAccount extends string = string, + TAccountFeeAccount extends string = string, + TAccountReferralFeeAccount extends string = string, + TAccountPoolMint extends string = string, + TAccountSystemProgram extends string = string, + TAccountTokenProgram extends string = string, + TAccountSolDepositAuthority extends string = string, +> { + /** Stake pool */ + stakePool: Address; + /** Stake pool withdraw authority */ + withdrawAuthority?: Address; + /** Reserve stake */ + reserveStake: Address; + /** Payer */ + payer: TransactionSigner; + /** User pool token account */ + userPoolTokenAccount: Address; + /** Fee account */ + feeAccount: Address; + /** Referral fee account */ + referralFeeAccount: Address; + /** Pool mint */ + poolMint: Address; + /** System program */ + systemProgram?: Address; + /** Token program */ + tokenProgram?: Address; + /** Stake pool sol deposit authority */ + solDepositAuthority: + | Address + | TransactionSigner; + lamportsIn: DepositSolWithSlippageInstructionDataArgs["lamportsIn"]; + minimumPoolTokensOut: DepositSolWithSlippageInstructionDataArgs["minimumPoolTokensOut"]; +} + +export async function getDepositSolWithSlippageInstructionAsync< + TAccountStakePool extends string, + TAccountWithdrawAuthority extends string, + TAccountReserveStake extends string, + TAccountPayer extends string, + TAccountUserPoolTokenAccount extends string, + TAccountFeeAccount extends string, + TAccountReferralFeeAccount extends string, + TAccountPoolMint extends string, + TAccountSystemProgram extends string, + TAccountTokenProgram extends string, + TAccountSolDepositAuthority extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: DepositSolWithSlippageAsyncInput< + TAccountStakePool, + TAccountWithdrawAuthority, + TAccountReserveStake, + TAccountPayer, + TAccountUserPoolTokenAccount, + TAccountFeeAccount, + TAccountReferralFeeAccount, + TAccountPoolMint, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountSolDepositAuthority + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + DepositSolWithSlippageInstruction< + TProgramAddress, + TAccountStakePool, + TAccountWithdrawAuthority, + TAccountReserveStake, + TAccountPayer, + TAccountUserPoolTokenAccount, + TAccountFeeAccount, + TAccountReferralFeeAccount, + TAccountPoolMint, + TAccountSystemProgram, + TAccountTokenProgram, + (typeof input)["solDepositAuthority"] extends TransactionSigner + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountSolDepositAuthority + > +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: true }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + reserveStake: { value: input.reserveStake ?? null, isWritable: true }, + payer: { value: input.payer ?? null, isWritable: false }, + userPoolTokenAccount: { + value: input.userPoolTokenAccount ?? null, + isWritable: true, + }, + feeAccount: { value: input.feeAccount ?? null, isWritable: true }, + referralFeeAccount: { + value: input.referralFeeAccount ?? null, + isWritable: true, + }, + poolMint: { value: input.poolMint ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + solDepositAuthority: { + value: input.solDepositAuthority ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.withdrawAuthority.value) { + accounts.withdrawAuthority.value = await findWithdrawAuthorityPda({ + stakePoolAddress: expectAddress(accounts.stakePool.value), + }); + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.reserveStake), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.userPoolTokenAccount), + getAccountMeta(accounts.feeAccount), + getAccountMeta(accounts.referralFeeAccount), + getAccountMeta(accounts.poolMint), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.solDepositAuthority), + ], + data: getDepositSolWithSlippageInstructionDataEncoder().encode( + args as DepositSolWithSlippageInstructionDataArgs, + ), + programAddress, + } as DepositSolWithSlippageInstruction< + TProgramAddress, + TAccountStakePool, + TAccountWithdrawAuthority, + TAccountReserveStake, + TAccountPayer, + TAccountUserPoolTokenAccount, + TAccountFeeAccount, + TAccountReferralFeeAccount, + TAccountPoolMint, + TAccountSystemProgram, + TAccountTokenProgram, + (typeof input)["solDepositAuthority"] extends TransactionSigner + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountSolDepositAuthority + >); +} + +export interface DepositSolWithSlippageInput< + TAccountStakePool extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountReserveStake extends string = string, + TAccountPayer extends string = string, + TAccountUserPoolTokenAccount extends string = string, + TAccountFeeAccount extends string = string, + TAccountReferralFeeAccount extends string = string, + TAccountPoolMint extends string = string, + TAccountSystemProgram extends string = string, + TAccountTokenProgram extends string = string, + TAccountSolDepositAuthority extends string = string, +> { + /** Stake pool */ + stakePool: Address; + /** Stake pool withdraw authority */ + withdrawAuthority: Address; + /** Reserve stake */ + reserveStake: Address; + /** Payer */ + payer: TransactionSigner; + /** User pool token account */ + userPoolTokenAccount: Address; + /** Fee account */ + feeAccount: Address; + /** Referral fee account */ + referralFeeAccount: Address; + /** Pool mint */ + poolMint: Address; + /** System program */ + systemProgram?: Address; + /** Token program */ + tokenProgram?: Address; + /** Stake pool sol deposit authority */ + solDepositAuthority: + | Address + | TransactionSigner; + lamportsIn: DepositSolWithSlippageInstructionDataArgs["lamportsIn"]; + minimumPoolTokensOut: DepositSolWithSlippageInstructionDataArgs["minimumPoolTokensOut"]; +} + +export function getDepositSolWithSlippageInstruction< + TAccountStakePool extends string, + TAccountWithdrawAuthority extends string, + TAccountReserveStake extends string, + TAccountPayer extends string, + TAccountUserPoolTokenAccount extends string, + TAccountFeeAccount extends string, + TAccountReferralFeeAccount extends string, + TAccountPoolMint extends string, + TAccountSystemProgram extends string, + TAccountTokenProgram extends string, + TAccountSolDepositAuthority extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: DepositSolWithSlippageInput< + TAccountStakePool, + TAccountWithdrawAuthority, + TAccountReserveStake, + TAccountPayer, + TAccountUserPoolTokenAccount, + TAccountFeeAccount, + TAccountReferralFeeAccount, + TAccountPoolMint, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountSolDepositAuthority + >, + config?: { programAddress?: TProgramAddress }, +): DepositSolWithSlippageInstruction< + TProgramAddress, + TAccountStakePool, + TAccountWithdrawAuthority, + TAccountReserveStake, + TAccountPayer, + TAccountUserPoolTokenAccount, + TAccountFeeAccount, + TAccountReferralFeeAccount, + TAccountPoolMint, + TAccountSystemProgram, + TAccountTokenProgram, + (typeof input)["solDepositAuthority"] extends TransactionSigner + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountSolDepositAuthority +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: true }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + reserveStake: { value: input.reserveStake ?? null, isWritable: true }, + payer: { value: input.payer ?? null, isWritable: false }, + userPoolTokenAccount: { + value: input.userPoolTokenAccount ?? null, + isWritable: true, + }, + feeAccount: { value: input.feeAccount ?? null, isWritable: true }, + referralFeeAccount: { + value: input.referralFeeAccount ?? null, + isWritable: true, + }, + poolMint: { value: input.poolMint ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + solDepositAuthority: { + value: input.solDepositAuthority ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.reserveStake), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.userPoolTokenAccount), + getAccountMeta(accounts.feeAccount), + getAccountMeta(accounts.referralFeeAccount), + getAccountMeta(accounts.poolMint), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.solDepositAuthority), + ], + data: getDepositSolWithSlippageInstructionDataEncoder().encode( + args as DepositSolWithSlippageInstructionDataArgs, + ), + programAddress, + } as DepositSolWithSlippageInstruction< + TProgramAddress, + TAccountStakePool, + TAccountWithdrawAuthority, + TAccountReserveStake, + TAccountPayer, + TAccountUserPoolTokenAccount, + TAccountFeeAccount, + TAccountReferralFeeAccount, + TAccountPoolMint, + TAccountSystemProgram, + TAccountTokenProgram, + (typeof input)["solDepositAuthority"] extends TransactionSigner + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountSolDepositAuthority + >); +} + +export interface ParsedDepositSolWithSlippageInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + /** Stake pool */ + stakePool: TAccountMetas[0]; + /** Stake pool withdraw authority */ + withdrawAuthority: TAccountMetas[1]; + /** Reserve stake */ + reserveStake: TAccountMetas[2]; + /** Payer */ + payer: TAccountMetas[3]; + /** User pool token account */ + userPoolTokenAccount: TAccountMetas[4]; + /** Fee account */ + feeAccount: TAccountMetas[5]; + /** Referral fee account */ + referralFeeAccount: TAccountMetas[6]; + /** Pool mint */ + poolMint: TAccountMetas[7]; + /** System program */ + systemProgram: TAccountMetas[8]; + /** Token program */ + tokenProgram: TAccountMetas[9]; + /** Stake pool sol deposit authority */ + solDepositAuthority: TAccountMetas[10]; + }; + data: DepositSolWithSlippageInstructionData; +} + +export function parseDepositSolWithSlippageInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedDepositSolWithSlippageInstruction { + if (instruction.accounts.length < 11) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + stakePool: getNextAccount(), + withdrawAuthority: getNextAccount(), + reserveStake: getNextAccount(), + payer: getNextAccount(), + userPoolTokenAccount: getNextAccount(), + feeAccount: getNextAccount(), + referralFeeAccount: getNextAccount(), + poolMint: getNextAccount(), + systemProgram: getNextAccount(), + tokenProgram: getNextAccount(), + solDepositAuthority: getNextAccount(), + }, + data: getDepositSolWithSlippageInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/spl-stake-pool/src/generated/instructions/depositStake.ts b/clients/spl-stake-pool/src/generated/instructions/depositStake.ts new file mode 100644 index 00000000..c1c2bc99 --- /dev/null +++ b/clients/spl-stake-pool/src/generated/instructions/depositStake.ts @@ -0,0 +1,621 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, +} from "@solana/kit"; +import { findWithdrawAuthorityPda } from "../pdas/index.js"; +import { SPL_STAKE_POOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; + +export const DEPOSIT_STAKE_DISCRIMINATOR = 9; + +export function getDepositStakeDiscriminatorBytes(): ReadonlyUint8Array { + return getU8Encoder().encode(DEPOSIT_STAKE_DISCRIMINATOR); +} + +export type DepositStakeInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountStakePool extends string | AccountMeta = string, + TAccountValidatorList extends string | AccountMeta = string, + TAccountDepositAuthority extends string | AccountMeta = string, + TAccountWithdrawAuthority extends string | AccountMeta = string, + TAccountStakeToMerge extends string | AccountMeta = string, + TAccountValidatorStakeAccount extends string | AccountMeta = string, + TAccountReserveStake extends string | AccountMeta = string, + TAccountUserPoolTokenAccount extends string | AccountMeta = string, + TAccountFeeAccount extends string | AccountMeta = string, + TAccountReferralFeeAccount extends string | AccountMeta = string, + TAccountPoolMint extends string | AccountMeta = string, + TAccountClockSysvar extends + | string + | AccountMeta = "SysvarC1ock11111111111111111111111111111111", + TAccountStakeHistorySysvar extends + | string + | AccountMeta = "SysvarStakeHistory1111111111111111111111111", + TAccountTokenProgram extends + | string + | AccountMeta = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + TAccountStakeProgram extends + | string + | AccountMeta = "Stake11111111111111111111111111111111111111", + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountStakePool extends string + ? WritableAccount + : TAccountStakePool, + TAccountValidatorList extends string + ? WritableAccount + : TAccountValidatorList, + TAccountDepositAuthority extends string + ? ReadonlyAccount + : TAccountDepositAuthority, + TAccountWithdrawAuthority extends string + ? ReadonlyAccount + : TAccountWithdrawAuthority, + TAccountStakeToMerge extends string + ? WritableAccount + : TAccountStakeToMerge, + TAccountValidatorStakeAccount extends string + ? WritableAccount + : TAccountValidatorStakeAccount, + TAccountReserveStake extends string + ? WritableAccount + : TAccountReserveStake, + TAccountUserPoolTokenAccount extends string + ? WritableAccount + : TAccountUserPoolTokenAccount, + TAccountFeeAccount extends string + ? WritableAccount + : TAccountFeeAccount, + TAccountReferralFeeAccount extends string + ? WritableAccount + : TAccountReferralFeeAccount, + TAccountPoolMint extends string + ? WritableAccount + : TAccountPoolMint, + TAccountClockSysvar extends string + ? ReadonlyAccount + : TAccountClockSysvar, + TAccountStakeHistorySysvar extends string + ? ReadonlyAccount + : TAccountStakeHistorySysvar, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + TAccountStakeProgram extends string + ? ReadonlyAccount + : TAccountStakeProgram, + ...TRemainingAccounts, + ] + >; + +export interface DepositStakeInstructionData { + discriminator: number; +} + +export interface DepositStakeInstructionDataArgs {} + +export function getDepositStakeInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", getU8Encoder()]]), + (value) => ({ ...value, discriminator: DEPOSIT_STAKE_DISCRIMINATOR }), + ); +} + +export function getDepositStakeInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([["discriminator", getU8Decoder()]]); +} + +export function getDepositStakeInstructionDataCodec(): FixedSizeCodec< + DepositStakeInstructionDataArgs, + DepositStakeInstructionData +> { + return combineCodec( + getDepositStakeInstructionDataEncoder(), + getDepositStakeInstructionDataDecoder(), + ); +} + +export interface DepositStakeAsyncInput< + TAccountStakePool extends string = string, + TAccountValidatorList extends string = string, + TAccountDepositAuthority extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountStakeToMerge extends string = string, + TAccountValidatorStakeAccount extends string = string, + TAccountReserveStake extends string = string, + TAccountUserPoolTokenAccount extends string = string, + TAccountFeeAccount extends string = string, + TAccountReferralFeeAccount extends string = string, + TAccountPoolMint extends string = string, + TAccountClockSysvar extends string = string, + TAccountStakeHistorySysvar extends string = string, + TAccountTokenProgram extends string = string, + TAccountStakeProgram extends string = string, +> { + stakePool: Address; + validatorList: Address; + depositAuthority: + | Address + | TransactionSigner; + withdrawAuthority?: Address; + stakeToMerge: Address; + validatorStakeAccount: Address; + reserveStake: Address; + userPoolTokenAccount: Address; + feeAccount: Address; + referralFeeAccount: Address; + poolMint: Address; + clockSysvar?: Address; + stakeHistorySysvar?: Address; + tokenProgram?: Address; + stakeProgram?: Address; +} + +export async function getDepositStakeInstructionAsync< + TAccountStakePool extends string, + TAccountValidatorList extends string, + TAccountDepositAuthority extends string, + TAccountWithdrawAuthority extends string, + TAccountStakeToMerge extends string, + TAccountValidatorStakeAccount extends string, + TAccountReserveStake extends string, + TAccountUserPoolTokenAccount extends string, + TAccountFeeAccount extends string, + TAccountReferralFeeAccount extends string, + TAccountPoolMint extends string, + TAccountClockSysvar extends string, + TAccountStakeHistorySysvar extends string, + TAccountTokenProgram extends string, + TAccountStakeProgram extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: DepositStakeAsyncInput< + TAccountStakePool, + TAccountValidatorList, + TAccountDepositAuthority, + TAccountWithdrawAuthority, + TAccountStakeToMerge, + TAccountValidatorStakeAccount, + TAccountReserveStake, + TAccountUserPoolTokenAccount, + TAccountFeeAccount, + TAccountReferralFeeAccount, + TAccountPoolMint, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountTokenProgram, + TAccountStakeProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + DepositStakeInstruction< + TProgramAddress, + TAccountStakePool, + TAccountValidatorList, + (typeof input)["depositAuthority"] extends TransactionSigner + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountDepositAuthority, + TAccountWithdrawAuthority, + TAccountStakeToMerge, + TAccountValidatorStakeAccount, + TAccountReserveStake, + TAccountUserPoolTokenAccount, + TAccountFeeAccount, + TAccountReferralFeeAccount, + TAccountPoolMint, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountTokenProgram, + TAccountStakeProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: true }, + validatorList: { value: input.validatorList ?? null, isWritable: true }, + depositAuthority: { + value: input.depositAuthority ?? null, + isWritable: false, + }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + stakeToMerge: { value: input.stakeToMerge ?? null, isWritable: true }, + validatorStakeAccount: { + value: input.validatorStakeAccount ?? null, + isWritable: true, + }, + reserveStake: { value: input.reserveStake ?? null, isWritable: true }, + userPoolTokenAccount: { + value: input.userPoolTokenAccount ?? null, + isWritable: true, + }, + feeAccount: { value: input.feeAccount ?? null, isWritable: true }, + referralFeeAccount: { + value: input.referralFeeAccount ?? null, + isWritable: true, + }, + poolMint: { value: input.poolMint ?? null, isWritable: true }, + clockSysvar: { value: input.clockSysvar ?? null, isWritable: false }, + stakeHistorySysvar: { + value: input.stakeHistorySysvar ?? null, + isWritable: false, + }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + stakeProgram: { value: input.stakeProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Resolve default values. + if (!accounts.withdrawAuthority.value) { + accounts.withdrawAuthority.value = await findWithdrawAuthorityPda({ + stakePoolAddress: expectAddress(accounts.stakePool.value), + }); + } + if (!accounts.clockSysvar.value) { + accounts.clockSysvar.value = + "SysvarC1ock11111111111111111111111111111111" as Address<"SysvarC1ock11111111111111111111111111111111">; + } + if (!accounts.stakeHistorySysvar.value) { + accounts.stakeHistorySysvar.value = + "SysvarStakeHistory1111111111111111111111111" as Address<"SysvarStakeHistory1111111111111111111111111">; + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + if (!accounts.stakeProgram.value) { + accounts.stakeProgram.value = + "Stake11111111111111111111111111111111111111" as Address<"Stake11111111111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.validatorList), + getAccountMeta(accounts.depositAuthority), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.stakeToMerge), + getAccountMeta(accounts.validatorStakeAccount), + getAccountMeta(accounts.reserveStake), + getAccountMeta(accounts.userPoolTokenAccount), + getAccountMeta(accounts.feeAccount), + getAccountMeta(accounts.referralFeeAccount), + getAccountMeta(accounts.poolMint), + getAccountMeta(accounts.clockSysvar), + getAccountMeta(accounts.stakeHistorySysvar), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.stakeProgram), + ], + data: getDepositStakeInstructionDataEncoder().encode({}), + programAddress, + } as DepositStakeInstruction< + TProgramAddress, + TAccountStakePool, + TAccountValidatorList, + (typeof input)["depositAuthority"] extends TransactionSigner + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountDepositAuthority, + TAccountWithdrawAuthority, + TAccountStakeToMerge, + TAccountValidatorStakeAccount, + TAccountReserveStake, + TAccountUserPoolTokenAccount, + TAccountFeeAccount, + TAccountReferralFeeAccount, + TAccountPoolMint, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountTokenProgram, + TAccountStakeProgram + >); +} + +export interface DepositStakeInput< + TAccountStakePool extends string = string, + TAccountValidatorList extends string = string, + TAccountDepositAuthority extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountStakeToMerge extends string = string, + TAccountValidatorStakeAccount extends string = string, + TAccountReserveStake extends string = string, + TAccountUserPoolTokenAccount extends string = string, + TAccountFeeAccount extends string = string, + TAccountReferralFeeAccount extends string = string, + TAccountPoolMint extends string = string, + TAccountClockSysvar extends string = string, + TAccountStakeHistorySysvar extends string = string, + TAccountTokenProgram extends string = string, + TAccountStakeProgram extends string = string, +> { + stakePool: Address; + validatorList: Address; + depositAuthority: + | Address + | TransactionSigner; + withdrawAuthority: Address; + stakeToMerge: Address; + validatorStakeAccount: Address; + reserveStake: Address; + userPoolTokenAccount: Address; + feeAccount: Address; + referralFeeAccount: Address; + poolMint: Address; + clockSysvar?: Address; + stakeHistorySysvar?: Address; + tokenProgram?: Address; + stakeProgram?: Address; +} + +export function getDepositStakeInstruction< + TAccountStakePool extends string, + TAccountValidatorList extends string, + TAccountDepositAuthority extends string, + TAccountWithdrawAuthority extends string, + TAccountStakeToMerge extends string, + TAccountValidatorStakeAccount extends string, + TAccountReserveStake extends string, + TAccountUserPoolTokenAccount extends string, + TAccountFeeAccount extends string, + TAccountReferralFeeAccount extends string, + TAccountPoolMint extends string, + TAccountClockSysvar extends string, + TAccountStakeHistorySysvar extends string, + TAccountTokenProgram extends string, + TAccountStakeProgram extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: DepositStakeInput< + TAccountStakePool, + TAccountValidatorList, + TAccountDepositAuthority, + TAccountWithdrawAuthority, + TAccountStakeToMerge, + TAccountValidatorStakeAccount, + TAccountReserveStake, + TAccountUserPoolTokenAccount, + TAccountFeeAccount, + TAccountReferralFeeAccount, + TAccountPoolMint, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountTokenProgram, + TAccountStakeProgram + >, + config?: { programAddress?: TProgramAddress }, +): DepositStakeInstruction< + TProgramAddress, + TAccountStakePool, + TAccountValidatorList, + (typeof input)["depositAuthority"] extends TransactionSigner + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountDepositAuthority, + TAccountWithdrawAuthority, + TAccountStakeToMerge, + TAccountValidatorStakeAccount, + TAccountReserveStake, + TAccountUserPoolTokenAccount, + TAccountFeeAccount, + TAccountReferralFeeAccount, + TAccountPoolMint, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountTokenProgram, + TAccountStakeProgram +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: true }, + validatorList: { value: input.validatorList ?? null, isWritable: true }, + depositAuthority: { + value: input.depositAuthority ?? null, + isWritable: false, + }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + stakeToMerge: { value: input.stakeToMerge ?? null, isWritable: true }, + validatorStakeAccount: { + value: input.validatorStakeAccount ?? null, + isWritable: true, + }, + reserveStake: { value: input.reserveStake ?? null, isWritable: true }, + userPoolTokenAccount: { + value: input.userPoolTokenAccount ?? null, + isWritable: true, + }, + feeAccount: { value: input.feeAccount ?? null, isWritable: true }, + referralFeeAccount: { + value: input.referralFeeAccount ?? null, + isWritable: true, + }, + poolMint: { value: input.poolMint ?? null, isWritable: true }, + clockSysvar: { value: input.clockSysvar ?? null, isWritable: false }, + stakeHistorySysvar: { + value: input.stakeHistorySysvar ?? null, + isWritable: false, + }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + stakeProgram: { value: input.stakeProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Resolve default values. + if (!accounts.clockSysvar.value) { + accounts.clockSysvar.value = + "SysvarC1ock11111111111111111111111111111111" as Address<"SysvarC1ock11111111111111111111111111111111">; + } + if (!accounts.stakeHistorySysvar.value) { + accounts.stakeHistorySysvar.value = + "SysvarStakeHistory1111111111111111111111111" as Address<"SysvarStakeHistory1111111111111111111111111">; + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + if (!accounts.stakeProgram.value) { + accounts.stakeProgram.value = + "Stake11111111111111111111111111111111111111" as Address<"Stake11111111111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.validatorList), + getAccountMeta(accounts.depositAuthority), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.stakeToMerge), + getAccountMeta(accounts.validatorStakeAccount), + getAccountMeta(accounts.reserveStake), + getAccountMeta(accounts.userPoolTokenAccount), + getAccountMeta(accounts.feeAccount), + getAccountMeta(accounts.referralFeeAccount), + getAccountMeta(accounts.poolMint), + getAccountMeta(accounts.clockSysvar), + getAccountMeta(accounts.stakeHistorySysvar), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.stakeProgram), + ], + data: getDepositStakeInstructionDataEncoder().encode({}), + programAddress, + } as DepositStakeInstruction< + TProgramAddress, + TAccountStakePool, + TAccountValidatorList, + (typeof input)["depositAuthority"] extends TransactionSigner + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountDepositAuthority, + TAccountWithdrawAuthority, + TAccountStakeToMerge, + TAccountValidatorStakeAccount, + TAccountReserveStake, + TAccountUserPoolTokenAccount, + TAccountFeeAccount, + TAccountReferralFeeAccount, + TAccountPoolMint, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountTokenProgram, + TAccountStakeProgram + >); +} + +export interface ParsedDepositStakeInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + stakePool: TAccountMetas[0]; + validatorList: TAccountMetas[1]; + depositAuthority: TAccountMetas[2]; + withdrawAuthority: TAccountMetas[3]; + stakeToMerge: TAccountMetas[4]; + validatorStakeAccount: TAccountMetas[5]; + reserveStake: TAccountMetas[6]; + userPoolTokenAccount: TAccountMetas[7]; + feeAccount: TAccountMetas[8]; + referralFeeAccount: TAccountMetas[9]; + poolMint: TAccountMetas[10]; + clockSysvar: TAccountMetas[11]; + stakeHistorySysvar: TAccountMetas[12]; + tokenProgram: TAccountMetas[13]; + stakeProgram: TAccountMetas[14]; + }; + data: DepositStakeInstructionData; +} + +export function parseDepositStakeInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedDepositStakeInstruction { + if (instruction.accounts.length < 15) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + stakePool: getNextAccount(), + validatorList: getNextAccount(), + depositAuthority: getNextAccount(), + withdrawAuthority: getNextAccount(), + stakeToMerge: getNextAccount(), + validatorStakeAccount: getNextAccount(), + reserveStake: getNextAccount(), + userPoolTokenAccount: getNextAccount(), + feeAccount: getNextAccount(), + referralFeeAccount: getNextAccount(), + poolMint: getNextAccount(), + clockSysvar: getNextAccount(), + stakeHistorySysvar: getNextAccount(), + tokenProgram: getNextAccount(), + stakeProgram: getNextAccount(), + }, + data: getDepositStakeInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/spl-stake-pool/src/generated/instructions/depositStakeWithSlippage.ts b/clients/spl-stake-pool/src/generated/instructions/depositStakeWithSlippage.ts new file mode 100644 index 00000000..ab9b656a --- /dev/null +++ b/clients/spl-stake-pool/src/generated/instructions/depositStakeWithSlippage.ts @@ -0,0 +1,649 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getU64Decoder, + getU64Encoder, + transformEncoder, +} from "@solana/kit"; +import { findWithdrawAuthorityPda } from "../pdas/index.js"; +import { SPL_STAKE_POOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; + +export const DEPOSIT_STAKE_WITH_SLIPPAGE_DISCRIMINATOR = 23; + +export function getDepositStakeWithSlippageDiscriminatorBytes(): ReadonlyUint8Array { + return getU8Encoder().encode(DEPOSIT_STAKE_WITH_SLIPPAGE_DISCRIMINATOR); +} + +export type DepositStakeWithSlippageInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountStakePool extends string | AccountMeta = string, + TAccountValidatorList extends string | AccountMeta = string, + TAccountDepositAuthority extends string | AccountMeta = string, + TAccountWithdrawAuthority extends string | AccountMeta = string, + TAccountStakeToMerge extends string | AccountMeta = string, + TAccountValidatorStakeAccount extends string | AccountMeta = string, + TAccountReserveStake extends string | AccountMeta = string, + TAccountUserPoolTokenAccount extends string | AccountMeta = string, + TAccountFeeAccount extends string | AccountMeta = string, + TAccountReferralFeeAccount extends string | AccountMeta = string, + TAccountPoolMint extends string | AccountMeta = string, + TAccountClockSysvar extends + | string + | AccountMeta = "SysvarC1ock11111111111111111111111111111111", + TAccountStakeHistorySysvar extends + | string + | AccountMeta = "SysvarStakeHistory1111111111111111111111111", + TAccountTokenProgram extends + | string + | AccountMeta = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + TAccountStakeProgram extends + | string + | AccountMeta = "Stake11111111111111111111111111111111111111", + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountStakePool extends string + ? WritableAccount + : TAccountStakePool, + TAccountValidatorList extends string + ? WritableAccount + : TAccountValidatorList, + TAccountDepositAuthority extends string + ? ReadonlyAccount + : TAccountDepositAuthority, + TAccountWithdrawAuthority extends string + ? ReadonlyAccount + : TAccountWithdrawAuthority, + TAccountStakeToMerge extends string + ? WritableAccount + : TAccountStakeToMerge, + TAccountValidatorStakeAccount extends string + ? WritableAccount + : TAccountValidatorStakeAccount, + TAccountReserveStake extends string + ? WritableAccount + : TAccountReserveStake, + TAccountUserPoolTokenAccount extends string + ? WritableAccount + : TAccountUserPoolTokenAccount, + TAccountFeeAccount extends string + ? WritableAccount + : TAccountFeeAccount, + TAccountReferralFeeAccount extends string + ? WritableAccount + : TAccountReferralFeeAccount, + TAccountPoolMint extends string + ? WritableAccount + : TAccountPoolMint, + TAccountClockSysvar extends string + ? ReadonlyAccount + : TAccountClockSysvar, + TAccountStakeHistorySysvar extends string + ? ReadonlyAccount + : TAccountStakeHistorySysvar, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + TAccountStakeProgram extends string + ? ReadonlyAccount + : TAccountStakeProgram, + ...TRemainingAccounts, + ] + >; + +export interface DepositStakeWithSlippageInstructionData { + discriminator: number; + minimumPoolTokensOut: bigint; +} + +export interface DepositStakeWithSlippageInstructionDataArgs { + minimumPoolTokensOut: number | bigint; +} + +export function getDepositStakeWithSlippageInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", getU8Encoder()], + ["minimumPoolTokensOut", getU64Encoder()], + ]), + (value) => ({ + ...value, + discriminator: DEPOSIT_STAKE_WITH_SLIPPAGE_DISCRIMINATOR, + }), + ); +} + +export function getDepositStakeWithSlippageInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", getU8Decoder()], + ["minimumPoolTokensOut", getU64Decoder()], + ]); +} + +export function getDepositStakeWithSlippageInstructionDataCodec(): FixedSizeCodec< + DepositStakeWithSlippageInstructionDataArgs, + DepositStakeWithSlippageInstructionData +> { + return combineCodec( + getDepositStakeWithSlippageInstructionDataEncoder(), + getDepositStakeWithSlippageInstructionDataDecoder(), + ); +} + +export interface DepositStakeWithSlippageAsyncInput< + TAccountStakePool extends string = string, + TAccountValidatorList extends string = string, + TAccountDepositAuthority extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountStakeToMerge extends string = string, + TAccountValidatorStakeAccount extends string = string, + TAccountReserveStake extends string = string, + TAccountUserPoolTokenAccount extends string = string, + TAccountFeeAccount extends string = string, + TAccountReferralFeeAccount extends string = string, + TAccountPoolMint extends string = string, + TAccountClockSysvar extends string = string, + TAccountStakeHistorySysvar extends string = string, + TAccountTokenProgram extends string = string, + TAccountStakeProgram extends string = string, +> { + stakePool: Address; + validatorList: Address; + depositAuthority: + | Address + | TransactionSigner; + withdrawAuthority?: Address; + stakeToMerge: Address; + validatorStakeAccount: Address; + reserveStake: Address; + userPoolTokenAccount: Address; + feeAccount: Address; + referralFeeAccount: Address; + poolMint: Address; + clockSysvar?: Address; + stakeHistorySysvar?: Address; + tokenProgram?: Address; + stakeProgram?: Address; + minimumPoolTokensOut: DepositStakeWithSlippageInstructionDataArgs["minimumPoolTokensOut"]; +} + +export async function getDepositStakeWithSlippageInstructionAsync< + TAccountStakePool extends string, + TAccountValidatorList extends string, + TAccountDepositAuthority extends string, + TAccountWithdrawAuthority extends string, + TAccountStakeToMerge extends string, + TAccountValidatorStakeAccount extends string, + TAccountReserveStake extends string, + TAccountUserPoolTokenAccount extends string, + TAccountFeeAccount extends string, + TAccountReferralFeeAccount extends string, + TAccountPoolMint extends string, + TAccountClockSysvar extends string, + TAccountStakeHistorySysvar extends string, + TAccountTokenProgram extends string, + TAccountStakeProgram extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: DepositStakeWithSlippageAsyncInput< + TAccountStakePool, + TAccountValidatorList, + TAccountDepositAuthority, + TAccountWithdrawAuthority, + TAccountStakeToMerge, + TAccountValidatorStakeAccount, + TAccountReserveStake, + TAccountUserPoolTokenAccount, + TAccountFeeAccount, + TAccountReferralFeeAccount, + TAccountPoolMint, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountTokenProgram, + TAccountStakeProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + DepositStakeWithSlippageInstruction< + TProgramAddress, + TAccountStakePool, + TAccountValidatorList, + (typeof input)["depositAuthority"] extends TransactionSigner + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountDepositAuthority, + TAccountWithdrawAuthority, + TAccountStakeToMerge, + TAccountValidatorStakeAccount, + TAccountReserveStake, + TAccountUserPoolTokenAccount, + TAccountFeeAccount, + TAccountReferralFeeAccount, + TAccountPoolMint, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountTokenProgram, + TAccountStakeProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: true }, + validatorList: { value: input.validatorList ?? null, isWritable: true }, + depositAuthority: { + value: input.depositAuthority ?? null, + isWritable: false, + }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + stakeToMerge: { value: input.stakeToMerge ?? null, isWritable: true }, + validatorStakeAccount: { + value: input.validatorStakeAccount ?? null, + isWritable: true, + }, + reserveStake: { value: input.reserveStake ?? null, isWritable: true }, + userPoolTokenAccount: { + value: input.userPoolTokenAccount ?? null, + isWritable: true, + }, + feeAccount: { value: input.feeAccount ?? null, isWritable: true }, + referralFeeAccount: { + value: input.referralFeeAccount ?? null, + isWritable: true, + }, + poolMint: { value: input.poolMint ?? null, isWritable: true }, + clockSysvar: { value: input.clockSysvar ?? null, isWritable: false }, + stakeHistorySysvar: { + value: input.stakeHistorySysvar ?? null, + isWritable: false, + }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + stakeProgram: { value: input.stakeProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.withdrawAuthority.value) { + accounts.withdrawAuthority.value = await findWithdrawAuthorityPda({ + stakePoolAddress: expectAddress(accounts.stakePool.value), + }); + } + if (!accounts.clockSysvar.value) { + accounts.clockSysvar.value = + "SysvarC1ock11111111111111111111111111111111" as Address<"SysvarC1ock11111111111111111111111111111111">; + } + if (!accounts.stakeHistorySysvar.value) { + accounts.stakeHistorySysvar.value = + "SysvarStakeHistory1111111111111111111111111" as Address<"SysvarStakeHistory1111111111111111111111111">; + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + if (!accounts.stakeProgram.value) { + accounts.stakeProgram.value = + "Stake11111111111111111111111111111111111111" as Address<"Stake11111111111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.validatorList), + getAccountMeta(accounts.depositAuthority), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.stakeToMerge), + getAccountMeta(accounts.validatorStakeAccount), + getAccountMeta(accounts.reserveStake), + getAccountMeta(accounts.userPoolTokenAccount), + getAccountMeta(accounts.feeAccount), + getAccountMeta(accounts.referralFeeAccount), + getAccountMeta(accounts.poolMint), + getAccountMeta(accounts.clockSysvar), + getAccountMeta(accounts.stakeHistorySysvar), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.stakeProgram), + ], + data: getDepositStakeWithSlippageInstructionDataEncoder().encode( + args as DepositStakeWithSlippageInstructionDataArgs, + ), + programAddress, + } as DepositStakeWithSlippageInstruction< + TProgramAddress, + TAccountStakePool, + TAccountValidatorList, + (typeof input)["depositAuthority"] extends TransactionSigner + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountDepositAuthority, + TAccountWithdrawAuthority, + TAccountStakeToMerge, + TAccountValidatorStakeAccount, + TAccountReserveStake, + TAccountUserPoolTokenAccount, + TAccountFeeAccount, + TAccountReferralFeeAccount, + TAccountPoolMint, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountTokenProgram, + TAccountStakeProgram + >); +} + +export interface DepositStakeWithSlippageInput< + TAccountStakePool extends string = string, + TAccountValidatorList extends string = string, + TAccountDepositAuthority extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountStakeToMerge extends string = string, + TAccountValidatorStakeAccount extends string = string, + TAccountReserveStake extends string = string, + TAccountUserPoolTokenAccount extends string = string, + TAccountFeeAccount extends string = string, + TAccountReferralFeeAccount extends string = string, + TAccountPoolMint extends string = string, + TAccountClockSysvar extends string = string, + TAccountStakeHistorySysvar extends string = string, + TAccountTokenProgram extends string = string, + TAccountStakeProgram extends string = string, +> { + stakePool: Address; + validatorList: Address; + depositAuthority: + | Address + | TransactionSigner; + withdrawAuthority: Address; + stakeToMerge: Address; + validatorStakeAccount: Address; + reserveStake: Address; + userPoolTokenAccount: Address; + feeAccount: Address; + referralFeeAccount: Address; + poolMint: Address; + clockSysvar?: Address; + stakeHistorySysvar?: Address; + tokenProgram?: Address; + stakeProgram?: Address; + minimumPoolTokensOut: DepositStakeWithSlippageInstructionDataArgs["minimumPoolTokensOut"]; +} + +export function getDepositStakeWithSlippageInstruction< + TAccountStakePool extends string, + TAccountValidatorList extends string, + TAccountDepositAuthority extends string, + TAccountWithdrawAuthority extends string, + TAccountStakeToMerge extends string, + TAccountValidatorStakeAccount extends string, + TAccountReserveStake extends string, + TAccountUserPoolTokenAccount extends string, + TAccountFeeAccount extends string, + TAccountReferralFeeAccount extends string, + TAccountPoolMint extends string, + TAccountClockSysvar extends string, + TAccountStakeHistorySysvar extends string, + TAccountTokenProgram extends string, + TAccountStakeProgram extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: DepositStakeWithSlippageInput< + TAccountStakePool, + TAccountValidatorList, + TAccountDepositAuthority, + TAccountWithdrawAuthority, + TAccountStakeToMerge, + TAccountValidatorStakeAccount, + TAccountReserveStake, + TAccountUserPoolTokenAccount, + TAccountFeeAccount, + TAccountReferralFeeAccount, + TAccountPoolMint, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountTokenProgram, + TAccountStakeProgram + >, + config?: { programAddress?: TProgramAddress }, +): DepositStakeWithSlippageInstruction< + TProgramAddress, + TAccountStakePool, + TAccountValidatorList, + (typeof input)["depositAuthority"] extends TransactionSigner + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountDepositAuthority, + TAccountWithdrawAuthority, + TAccountStakeToMerge, + TAccountValidatorStakeAccount, + TAccountReserveStake, + TAccountUserPoolTokenAccount, + TAccountFeeAccount, + TAccountReferralFeeAccount, + TAccountPoolMint, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountTokenProgram, + TAccountStakeProgram +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: true }, + validatorList: { value: input.validatorList ?? null, isWritable: true }, + depositAuthority: { + value: input.depositAuthority ?? null, + isWritable: false, + }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + stakeToMerge: { value: input.stakeToMerge ?? null, isWritable: true }, + validatorStakeAccount: { + value: input.validatorStakeAccount ?? null, + isWritable: true, + }, + reserveStake: { value: input.reserveStake ?? null, isWritable: true }, + userPoolTokenAccount: { + value: input.userPoolTokenAccount ?? null, + isWritable: true, + }, + feeAccount: { value: input.feeAccount ?? null, isWritable: true }, + referralFeeAccount: { + value: input.referralFeeAccount ?? null, + isWritable: true, + }, + poolMint: { value: input.poolMint ?? null, isWritable: true }, + clockSysvar: { value: input.clockSysvar ?? null, isWritable: false }, + stakeHistorySysvar: { + value: input.stakeHistorySysvar ?? null, + isWritable: false, + }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + stakeProgram: { value: input.stakeProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.clockSysvar.value) { + accounts.clockSysvar.value = + "SysvarC1ock11111111111111111111111111111111" as Address<"SysvarC1ock11111111111111111111111111111111">; + } + if (!accounts.stakeHistorySysvar.value) { + accounts.stakeHistorySysvar.value = + "SysvarStakeHistory1111111111111111111111111" as Address<"SysvarStakeHistory1111111111111111111111111">; + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + if (!accounts.stakeProgram.value) { + accounts.stakeProgram.value = + "Stake11111111111111111111111111111111111111" as Address<"Stake11111111111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.validatorList), + getAccountMeta(accounts.depositAuthority), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.stakeToMerge), + getAccountMeta(accounts.validatorStakeAccount), + getAccountMeta(accounts.reserveStake), + getAccountMeta(accounts.userPoolTokenAccount), + getAccountMeta(accounts.feeAccount), + getAccountMeta(accounts.referralFeeAccount), + getAccountMeta(accounts.poolMint), + getAccountMeta(accounts.clockSysvar), + getAccountMeta(accounts.stakeHistorySysvar), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.stakeProgram), + ], + data: getDepositStakeWithSlippageInstructionDataEncoder().encode( + args as DepositStakeWithSlippageInstructionDataArgs, + ), + programAddress, + } as DepositStakeWithSlippageInstruction< + TProgramAddress, + TAccountStakePool, + TAccountValidatorList, + (typeof input)["depositAuthority"] extends TransactionSigner + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountDepositAuthority, + TAccountWithdrawAuthority, + TAccountStakeToMerge, + TAccountValidatorStakeAccount, + TAccountReserveStake, + TAccountUserPoolTokenAccount, + TAccountFeeAccount, + TAccountReferralFeeAccount, + TAccountPoolMint, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountTokenProgram, + TAccountStakeProgram + >); +} + +export interface ParsedDepositStakeWithSlippageInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + stakePool: TAccountMetas[0]; + validatorList: TAccountMetas[1]; + depositAuthority: TAccountMetas[2]; + withdrawAuthority: TAccountMetas[3]; + stakeToMerge: TAccountMetas[4]; + validatorStakeAccount: TAccountMetas[5]; + reserveStake: TAccountMetas[6]; + userPoolTokenAccount: TAccountMetas[7]; + feeAccount: TAccountMetas[8]; + referralFeeAccount: TAccountMetas[9]; + poolMint: TAccountMetas[10]; + clockSysvar: TAccountMetas[11]; + stakeHistorySysvar: TAccountMetas[12]; + tokenProgram: TAccountMetas[13]; + stakeProgram: TAccountMetas[14]; + }; + data: DepositStakeWithSlippageInstructionData; +} + +export function parseDepositStakeWithSlippageInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedDepositStakeWithSlippageInstruction { + if (instruction.accounts.length < 15) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + stakePool: getNextAccount(), + validatorList: getNextAccount(), + depositAuthority: getNextAccount(), + withdrawAuthority: getNextAccount(), + stakeToMerge: getNextAccount(), + validatorStakeAccount: getNextAccount(), + reserveStake: getNextAccount(), + userPoolTokenAccount: getNextAccount(), + feeAccount: getNextAccount(), + referralFeeAccount: getNextAccount(), + poolMint: getNextAccount(), + clockSysvar: getNextAccount(), + stakeHistorySysvar: getNextAccount(), + tokenProgram: getNextAccount(), + stakeProgram: getNextAccount(), + }, + data: getDepositStakeWithSlippageInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/spl-stake-pool/src/generated/instructions/increaseAdditionalValidatorStake.ts b/clients/spl-stake-pool/src/generated/instructions/increaseAdditionalValidatorStake.ts new file mode 100644 index 00000000..34590c5e --- /dev/null +++ b/clients/spl-stake-pool/src/generated/instructions/increaseAdditionalValidatorStake.ts @@ -0,0 +1,618 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getU64Decoder, + getU64Encoder, + transformEncoder, +} from "@solana/kit"; +import { findWithdrawAuthorityPda } from "../pdas/index.js"; +import { SPL_STAKE_POOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; + +export const INCREASE_ADDITIONAL_VALIDATOR_STAKE_DISCRIMINATOR = 19; + +export function getIncreaseAdditionalValidatorStakeDiscriminatorBytes(): ReadonlyUint8Array { + return getU8Encoder().encode( + INCREASE_ADDITIONAL_VALIDATOR_STAKE_DISCRIMINATOR, + ); +} + +export type IncreaseAdditionalValidatorStakeInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountStakePool extends string | AccountMeta = string, + TAccountStaker extends string | AccountMeta = string, + TAccountWithdrawAuthority extends string | AccountMeta = string, + TAccountValidatorList extends string | AccountMeta = string, + TAccountReserveStake extends string | AccountMeta = string, + TAccountEphemeralStake extends string | AccountMeta = string, + TAccountTransientStake extends string | AccountMeta = string, + TAccountValidatorStake extends string | AccountMeta = string, + TAccountValidatorVote extends string | AccountMeta = string, + TAccountClockSysvar extends + | string + | AccountMeta = "SysvarC1ock11111111111111111111111111111111", + TAccountStakeHistorySysvar extends + | string + | AccountMeta = "SysvarStakeHistory1111111111111111111111111", + TAccountStakeConfigSysvar extends + | string + | AccountMeta = "StakeConfig11111111111111111111111111111111", + TAccountSystemProgram extends + | string + | AccountMeta = "11111111111111111111111111111111", + TAccountStakeProgram extends + | string + | AccountMeta = "Stake11111111111111111111111111111111111111", + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountStakePool extends string + ? ReadonlyAccount + : TAccountStakePool, + TAccountStaker extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountStaker, + TAccountWithdrawAuthority extends string + ? ReadonlyAccount + : TAccountWithdrawAuthority, + TAccountValidatorList extends string + ? WritableAccount + : TAccountValidatorList, + TAccountReserveStake extends string + ? WritableAccount + : TAccountReserveStake, + TAccountEphemeralStake extends string + ? WritableAccount + : TAccountEphemeralStake, + TAccountTransientStake extends string + ? WritableAccount + : TAccountTransientStake, + TAccountValidatorStake extends string + ? ReadonlyAccount + : TAccountValidatorStake, + TAccountValidatorVote extends string + ? ReadonlyAccount + : TAccountValidatorVote, + TAccountClockSysvar extends string + ? ReadonlyAccount + : TAccountClockSysvar, + TAccountStakeHistorySysvar extends string + ? ReadonlyAccount + : TAccountStakeHistorySysvar, + TAccountStakeConfigSysvar extends string + ? ReadonlyAccount + : TAccountStakeConfigSysvar, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + TAccountStakeProgram extends string + ? ReadonlyAccount + : TAccountStakeProgram, + ...TRemainingAccounts, + ] + >; + +export interface IncreaseAdditionalValidatorStakeInstructionData { + discriminator: number; + lamports: bigint; + transientStakeSeed: bigint; + ephemeralStakeSeed: bigint; +} + +export interface IncreaseAdditionalValidatorStakeInstructionDataArgs { + lamports: number | bigint; + transientStakeSeed: number | bigint; + ephemeralStakeSeed: number | bigint; +} + +export function getIncreaseAdditionalValidatorStakeInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", getU8Encoder()], + ["lamports", getU64Encoder()], + ["transientStakeSeed", getU64Encoder()], + ["ephemeralStakeSeed", getU64Encoder()], + ]), + (value) => ({ + ...value, + discriminator: INCREASE_ADDITIONAL_VALIDATOR_STAKE_DISCRIMINATOR, + }), + ); +} + +export function getIncreaseAdditionalValidatorStakeInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", getU8Decoder()], + ["lamports", getU64Decoder()], + ["transientStakeSeed", getU64Decoder()], + ["ephemeralStakeSeed", getU64Decoder()], + ]); +} + +export function getIncreaseAdditionalValidatorStakeInstructionDataCodec(): FixedSizeCodec< + IncreaseAdditionalValidatorStakeInstructionDataArgs, + IncreaseAdditionalValidatorStakeInstructionData +> { + return combineCodec( + getIncreaseAdditionalValidatorStakeInstructionDataEncoder(), + getIncreaseAdditionalValidatorStakeInstructionDataDecoder(), + ); +} + +export interface IncreaseAdditionalValidatorStakeAsyncInput< + TAccountStakePool extends string = string, + TAccountStaker extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountValidatorList extends string = string, + TAccountReserveStake extends string = string, + TAccountEphemeralStake extends string = string, + TAccountTransientStake extends string = string, + TAccountValidatorStake extends string = string, + TAccountValidatorVote extends string = string, + TAccountClockSysvar extends string = string, + TAccountStakeHistorySysvar extends string = string, + TAccountStakeConfigSysvar extends string = string, + TAccountSystemProgram extends string = string, + TAccountStakeProgram extends string = string, +> { + stakePool: Address; + staker: TransactionSigner; + withdrawAuthority?: Address; + validatorList: Address; + reserveStake: Address; + ephemeralStake: Address; + transientStake: Address; + validatorStake: Address; + validatorVote: Address; + clockSysvar?: Address; + stakeHistorySysvar?: Address; + stakeConfigSysvar?: Address; + systemProgram?: Address; + stakeProgram?: Address; + lamports: IncreaseAdditionalValidatorStakeInstructionDataArgs["lamports"]; + transientStakeSeed: IncreaseAdditionalValidatorStakeInstructionDataArgs["transientStakeSeed"]; + ephemeralStakeSeed: IncreaseAdditionalValidatorStakeInstructionDataArgs["ephemeralStakeSeed"]; +} + +export async function getIncreaseAdditionalValidatorStakeInstructionAsync< + TAccountStakePool extends string, + TAccountStaker extends string, + TAccountWithdrawAuthority extends string, + TAccountValidatorList extends string, + TAccountReserveStake extends string, + TAccountEphemeralStake extends string, + TAccountTransientStake extends string, + TAccountValidatorStake extends string, + TAccountValidatorVote extends string, + TAccountClockSysvar extends string, + TAccountStakeHistorySysvar extends string, + TAccountStakeConfigSysvar extends string, + TAccountSystemProgram extends string, + TAccountStakeProgram extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: IncreaseAdditionalValidatorStakeAsyncInput< + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountEphemeralStake, + TAccountTransientStake, + TAccountValidatorStake, + TAccountValidatorVote, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountStakeConfigSysvar, + TAccountSystemProgram, + TAccountStakeProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + IncreaseAdditionalValidatorStakeInstruction< + TProgramAddress, + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountEphemeralStake, + TAccountTransientStake, + TAccountValidatorStake, + TAccountValidatorVote, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountStakeConfigSysvar, + TAccountSystemProgram, + TAccountStakeProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: false }, + staker: { value: input.staker ?? null, isWritable: false }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + validatorList: { value: input.validatorList ?? null, isWritable: true }, + reserveStake: { value: input.reserveStake ?? null, isWritable: true }, + ephemeralStake: { value: input.ephemeralStake ?? null, isWritable: true }, + transientStake: { value: input.transientStake ?? null, isWritable: true }, + validatorStake: { value: input.validatorStake ?? null, isWritable: false }, + validatorVote: { value: input.validatorVote ?? null, isWritable: false }, + clockSysvar: { value: input.clockSysvar ?? null, isWritable: false }, + stakeHistorySysvar: { + value: input.stakeHistorySysvar ?? null, + isWritable: false, + }, + stakeConfigSysvar: { + value: input.stakeConfigSysvar ?? null, + isWritable: false, + }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + stakeProgram: { value: input.stakeProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.withdrawAuthority.value) { + accounts.withdrawAuthority.value = await findWithdrawAuthorityPda({ + stakePoolAddress: expectAddress(accounts.stakePool.value), + }); + } + if (!accounts.clockSysvar.value) { + accounts.clockSysvar.value = + "SysvarC1ock11111111111111111111111111111111" as Address<"SysvarC1ock11111111111111111111111111111111">; + } + if (!accounts.stakeHistorySysvar.value) { + accounts.stakeHistorySysvar.value = + "SysvarStakeHistory1111111111111111111111111" as Address<"SysvarStakeHistory1111111111111111111111111">; + } + if (!accounts.stakeConfigSysvar.value) { + accounts.stakeConfigSysvar.value = + "StakeConfig11111111111111111111111111111111" as Address<"StakeConfig11111111111111111111111111111111">; + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + if (!accounts.stakeProgram.value) { + accounts.stakeProgram.value = + "Stake11111111111111111111111111111111111111" as Address<"Stake11111111111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.staker), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.validatorList), + getAccountMeta(accounts.reserveStake), + getAccountMeta(accounts.ephemeralStake), + getAccountMeta(accounts.transientStake), + getAccountMeta(accounts.validatorStake), + getAccountMeta(accounts.validatorVote), + getAccountMeta(accounts.clockSysvar), + getAccountMeta(accounts.stakeHistorySysvar), + getAccountMeta(accounts.stakeConfigSysvar), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.stakeProgram), + ], + data: getIncreaseAdditionalValidatorStakeInstructionDataEncoder().encode( + args as IncreaseAdditionalValidatorStakeInstructionDataArgs, + ), + programAddress, + } as IncreaseAdditionalValidatorStakeInstruction< + TProgramAddress, + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountEphemeralStake, + TAccountTransientStake, + TAccountValidatorStake, + TAccountValidatorVote, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountStakeConfigSysvar, + TAccountSystemProgram, + TAccountStakeProgram + >); +} + +export interface IncreaseAdditionalValidatorStakeInput< + TAccountStakePool extends string = string, + TAccountStaker extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountValidatorList extends string = string, + TAccountReserveStake extends string = string, + TAccountEphemeralStake extends string = string, + TAccountTransientStake extends string = string, + TAccountValidatorStake extends string = string, + TAccountValidatorVote extends string = string, + TAccountClockSysvar extends string = string, + TAccountStakeHistorySysvar extends string = string, + TAccountStakeConfigSysvar extends string = string, + TAccountSystemProgram extends string = string, + TAccountStakeProgram extends string = string, +> { + stakePool: Address; + staker: TransactionSigner; + withdrawAuthority: Address; + validatorList: Address; + reserveStake: Address; + ephemeralStake: Address; + transientStake: Address; + validatorStake: Address; + validatorVote: Address; + clockSysvar?: Address; + stakeHistorySysvar?: Address; + stakeConfigSysvar?: Address; + systemProgram?: Address; + stakeProgram?: Address; + lamports: IncreaseAdditionalValidatorStakeInstructionDataArgs["lamports"]; + transientStakeSeed: IncreaseAdditionalValidatorStakeInstructionDataArgs["transientStakeSeed"]; + ephemeralStakeSeed: IncreaseAdditionalValidatorStakeInstructionDataArgs["ephemeralStakeSeed"]; +} + +export function getIncreaseAdditionalValidatorStakeInstruction< + TAccountStakePool extends string, + TAccountStaker extends string, + TAccountWithdrawAuthority extends string, + TAccountValidatorList extends string, + TAccountReserveStake extends string, + TAccountEphemeralStake extends string, + TAccountTransientStake extends string, + TAccountValidatorStake extends string, + TAccountValidatorVote extends string, + TAccountClockSysvar extends string, + TAccountStakeHistorySysvar extends string, + TAccountStakeConfigSysvar extends string, + TAccountSystemProgram extends string, + TAccountStakeProgram extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: IncreaseAdditionalValidatorStakeInput< + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountEphemeralStake, + TAccountTransientStake, + TAccountValidatorStake, + TAccountValidatorVote, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountStakeConfigSysvar, + TAccountSystemProgram, + TAccountStakeProgram + >, + config?: { programAddress?: TProgramAddress }, +): IncreaseAdditionalValidatorStakeInstruction< + TProgramAddress, + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountEphemeralStake, + TAccountTransientStake, + TAccountValidatorStake, + TAccountValidatorVote, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountStakeConfigSysvar, + TAccountSystemProgram, + TAccountStakeProgram +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: false }, + staker: { value: input.staker ?? null, isWritable: false }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + validatorList: { value: input.validatorList ?? null, isWritable: true }, + reserveStake: { value: input.reserveStake ?? null, isWritable: true }, + ephemeralStake: { value: input.ephemeralStake ?? null, isWritable: true }, + transientStake: { value: input.transientStake ?? null, isWritable: true }, + validatorStake: { value: input.validatorStake ?? null, isWritable: false }, + validatorVote: { value: input.validatorVote ?? null, isWritable: false }, + clockSysvar: { value: input.clockSysvar ?? null, isWritable: false }, + stakeHistorySysvar: { + value: input.stakeHistorySysvar ?? null, + isWritable: false, + }, + stakeConfigSysvar: { + value: input.stakeConfigSysvar ?? null, + isWritable: false, + }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + stakeProgram: { value: input.stakeProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.clockSysvar.value) { + accounts.clockSysvar.value = + "SysvarC1ock11111111111111111111111111111111" as Address<"SysvarC1ock11111111111111111111111111111111">; + } + if (!accounts.stakeHistorySysvar.value) { + accounts.stakeHistorySysvar.value = + "SysvarStakeHistory1111111111111111111111111" as Address<"SysvarStakeHistory1111111111111111111111111">; + } + if (!accounts.stakeConfigSysvar.value) { + accounts.stakeConfigSysvar.value = + "StakeConfig11111111111111111111111111111111" as Address<"StakeConfig11111111111111111111111111111111">; + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + if (!accounts.stakeProgram.value) { + accounts.stakeProgram.value = + "Stake11111111111111111111111111111111111111" as Address<"Stake11111111111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.staker), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.validatorList), + getAccountMeta(accounts.reserveStake), + getAccountMeta(accounts.ephemeralStake), + getAccountMeta(accounts.transientStake), + getAccountMeta(accounts.validatorStake), + getAccountMeta(accounts.validatorVote), + getAccountMeta(accounts.clockSysvar), + getAccountMeta(accounts.stakeHistorySysvar), + getAccountMeta(accounts.stakeConfigSysvar), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.stakeProgram), + ], + data: getIncreaseAdditionalValidatorStakeInstructionDataEncoder().encode( + args as IncreaseAdditionalValidatorStakeInstructionDataArgs, + ), + programAddress, + } as IncreaseAdditionalValidatorStakeInstruction< + TProgramAddress, + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountEphemeralStake, + TAccountTransientStake, + TAccountValidatorStake, + TAccountValidatorVote, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountStakeConfigSysvar, + TAccountSystemProgram, + TAccountStakeProgram + >); +} + +export interface ParsedIncreaseAdditionalValidatorStakeInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + stakePool: TAccountMetas[0]; + staker: TAccountMetas[1]; + withdrawAuthority: TAccountMetas[2]; + validatorList: TAccountMetas[3]; + reserveStake: TAccountMetas[4]; + ephemeralStake: TAccountMetas[5]; + transientStake: TAccountMetas[6]; + validatorStake: TAccountMetas[7]; + validatorVote: TAccountMetas[8]; + clockSysvar: TAccountMetas[9]; + stakeHistorySysvar: TAccountMetas[10]; + stakeConfigSysvar: TAccountMetas[11]; + systemProgram: TAccountMetas[12]; + stakeProgram: TAccountMetas[13]; + }; + data: IncreaseAdditionalValidatorStakeInstructionData; +} + +export function parseIncreaseAdditionalValidatorStakeInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedIncreaseAdditionalValidatorStakeInstruction { + if (instruction.accounts.length < 14) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + stakePool: getNextAccount(), + staker: getNextAccount(), + withdrawAuthority: getNextAccount(), + validatorList: getNextAccount(), + reserveStake: getNextAccount(), + ephemeralStake: getNextAccount(), + transientStake: getNextAccount(), + validatorStake: getNextAccount(), + validatorVote: getNextAccount(), + clockSysvar: getNextAccount(), + stakeHistorySysvar: getNextAccount(), + stakeConfigSysvar: getNextAccount(), + systemProgram: getNextAccount(), + stakeProgram: getNextAccount(), + }, + data: getIncreaseAdditionalValidatorStakeInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/spl-stake-pool/src/generated/instructions/increaseValidatorStake.ts b/clients/spl-stake-pool/src/generated/instructions/increaseValidatorStake.ts new file mode 100644 index 00000000..28d99852 --- /dev/null +++ b/clients/spl-stake-pool/src/generated/instructions/increaseValidatorStake.ts @@ -0,0 +1,652 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getU64Decoder, + getU64Encoder, + transformEncoder, +} from "@solana/kit"; +import { + findTransientStakePda, + findWithdrawAuthorityPda, +} from "../pdas/index.js"; +import { SPL_STAKE_POOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import { + expectAddress, + expectSome, + getAccountMetaFactory, +} from "../shared/index.js"; + +export const INCREASE_VALIDATOR_STAKE_DISCRIMINATOR = 4; + +export function getIncreaseValidatorStakeDiscriminatorBytes(): ReadonlyUint8Array { + return getU8Encoder().encode(INCREASE_VALIDATOR_STAKE_DISCRIMINATOR); +} + +export type IncreaseValidatorStakeInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountStakePool extends string | AccountMeta = string, + TAccountStaker extends string | AccountMeta = string, + TAccountWithdrawAuthority extends string | AccountMeta = string, + TAccountValidatorList extends string | AccountMeta = string, + TAccountReserveStake extends string | AccountMeta = string, + TAccountTransientStakeAccount extends string | AccountMeta = string, + TAccountValidatorStakeAccount extends string | AccountMeta = string, + TAccountValidatorVoteAccount extends string | AccountMeta = string, + TAccountClockSysvar extends + | string + | AccountMeta = "SysvarC1ock11111111111111111111111111111111", + TAccountRentSysvar extends + | string + | AccountMeta = "SysvarRent111111111111111111111111111111111", + TAccountStakeHistorySysvar extends + | string + | AccountMeta = "SysvarStakeHistory1111111111111111111111111", + TAccountStakeConfigSysvar extends + | string + | AccountMeta = "StakeConfig11111111111111111111111111111111", + TAccountSystemProgram extends + | string + | AccountMeta = "11111111111111111111111111111111", + TAccountStakeProgram extends + | string + | AccountMeta = "Stake11111111111111111111111111111111111111", + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountStakePool extends string + ? ReadonlyAccount + : TAccountStakePool, + TAccountStaker extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountStaker, + TAccountWithdrawAuthority extends string + ? ReadonlyAccount + : TAccountWithdrawAuthority, + TAccountValidatorList extends string + ? WritableAccount + : TAccountValidatorList, + TAccountReserveStake extends string + ? WritableAccount + : TAccountReserveStake, + TAccountTransientStakeAccount extends string + ? WritableAccount + : TAccountTransientStakeAccount, + TAccountValidatorStakeAccount extends string + ? ReadonlyAccount + : TAccountValidatorStakeAccount, + TAccountValidatorVoteAccount extends string + ? ReadonlyAccount + : TAccountValidatorVoteAccount, + TAccountClockSysvar extends string + ? ReadonlyAccount + : TAccountClockSysvar, + TAccountRentSysvar extends string + ? ReadonlyAccount + : TAccountRentSysvar, + TAccountStakeHistorySysvar extends string + ? ReadonlyAccount + : TAccountStakeHistorySysvar, + TAccountStakeConfigSysvar extends string + ? ReadonlyAccount + : TAccountStakeConfigSysvar, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + TAccountStakeProgram extends string + ? ReadonlyAccount + : TAccountStakeProgram, + ...TRemainingAccounts, + ] + >; + +export interface IncreaseValidatorStakeInstructionData { + discriminator: number; + lamports: bigint; + transientStakeSeed: bigint; +} + +export interface IncreaseValidatorStakeInstructionDataArgs { + lamports: number | bigint; + transientStakeSeed: number | bigint; +} + +export function getIncreaseValidatorStakeInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", getU8Encoder()], + ["lamports", getU64Encoder()], + ["transientStakeSeed", getU64Encoder()], + ]), + (value) => ({ + ...value, + discriminator: INCREASE_VALIDATOR_STAKE_DISCRIMINATOR, + }), + ); +} + +export function getIncreaseValidatorStakeInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", getU8Decoder()], + ["lamports", getU64Decoder()], + ["transientStakeSeed", getU64Decoder()], + ]); +} + +export function getIncreaseValidatorStakeInstructionDataCodec(): FixedSizeCodec< + IncreaseValidatorStakeInstructionDataArgs, + IncreaseValidatorStakeInstructionData +> { + return combineCodec( + getIncreaseValidatorStakeInstructionDataEncoder(), + getIncreaseValidatorStakeInstructionDataDecoder(), + ); +} + +export interface IncreaseValidatorStakeAsyncInput< + TAccountStakePool extends string = string, + TAccountStaker extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountValidatorList extends string = string, + TAccountReserveStake extends string = string, + TAccountTransientStakeAccount extends string = string, + TAccountValidatorStakeAccount extends string = string, + TAccountValidatorVoteAccount extends string = string, + TAccountClockSysvar extends string = string, + TAccountRentSysvar extends string = string, + TAccountStakeHistorySysvar extends string = string, + TAccountStakeConfigSysvar extends string = string, + TAccountSystemProgram extends string = string, + TAccountStakeProgram extends string = string, +> { + stakePool: Address; + staker: TransactionSigner; + withdrawAuthority?: Address; + validatorList: Address; + reserveStake: Address; + transientStakeAccount?: Address; + validatorStakeAccount: Address; + validatorVoteAccount: Address; + clockSysvar?: Address; + rentSysvar?: Address; + stakeHistorySysvar?: Address; + stakeConfigSysvar?: Address; + systemProgram?: Address; + stakeProgram?: Address; + lamports: IncreaseValidatorStakeInstructionDataArgs["lamports"]; + transientStakeSeed: IncreaseValidatorStakeInstructionDataArgs["transientStakeSeed"]; +} + +export async function getIncreaseValidatorStakeInstructionAsync< + TAccountStakePool extends string, + TAccountStaker extends string, + TAccountWithdrawAuthority extends string, + TAccountValidatorList extends string, + TAccountReserveStake extends string, + TAccountTransientStakeAccount extends string, + TAccountValidatorStakeAccount extends string, + TAccountValidatorVoteAccount extends string, + TAccountClockSysvar extends string, + TAccountRentSysvar extends string, + TAccountStakeHistorySysvar extends string, + TAccountStakeConfigSysvar extends string, + TAccountSystemProgram extends string, + TAccountStakeProgram extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: IncreaseValidatorStakeAsyncInput< + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountTransientStakeAccount, + TAccountValidatorStakeAccount, + TAccountValidatorVoteAccount, + TAccountClockSysvar, + TAccountRentSysvar, + TAccountStakeHistorySysvar, + TAccountStakeConfigSysvar, + TAccountSystemProgram, + TAccountStakeProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + IncreaseValidatorStakeInstruction< + TProgramAddress, + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountTransientStakeAccount, + TAccountValidatorStakeAccount, + TAccountValidatorVoteAccount, + TAccountClockSysvar, + TAccountRentSysvar, + TAccountStakeHistorySysvar, + TAccountStakeConfigSysvar, + TAccountSystemProgram, + TAccountStakeProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: false }, + staker: { value: input.staker ?? null, isWritable: false }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + validatorList: { value: input.validatorList ?? null, isWritable: true }, + reserveStake: { value: input.reserveStake ?? null, isWritable: true }, + transientStakeAccount: { + value: input.transientStakeAccount ?? null, + isWritable: true, + }, + validatorStakeAccount: { + value: input.validatorStakeAccount ?? null, + isWritable: false, + }, + validatorVoteAccount: { + value: input.validatorVoteAccount ?? null, + isWritable: false, + }, + clockSysvar: { value: input.clockSysvar ?? null, isWritable: false }, + rentSysvar: { value: input.rentSysvar ?? null, isWritable: false }, + stakeHistorySysvar: { + value: input.stakeHistorySysvar ?? null, + isWritable: false, + }, + stakeConfigSysvar: { + value: input.stakeConfigSysvar ?? null, + isWritable: false, + }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + stakeProgram: { value: input.stakeProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.withdrawAuthority.value) { + accounts.withdrawAuthority.value = await findWithdrawAuthorityPda({ + stakePoolAddress: expectAddress(accounts.stakePool.value), + }); + } + if (!accounts.transientStakeAccount.value) { + accounts.transientStakeAccount.value = await findTransientStakePda({ + voteAccountAddress: expectAddress(accounts.validatorVoteAccount.value), + stakePoolAddress: expectAddress(accounts.stakePool.value), + seed: expectSome(args.transientStakeSeed), + }); + } + if (!accounts.clockSysvar.value) { + accounts.clockSysvar.value = + "SysvarC1ock11111111111111111111111111111111" as Address<"SysvarC1ock11111111111111111111111111111111">; + } + if (!accounts.rentSysvar.value) { + accounts.rentSysvar.value = + "SysvarRent111111111111111111111111111111111" as Address<"SysvarRent111111111111111111111111111111111">; + } + if (!accounts.stakeHistorySysvar.value) { + accounts.stakeHistorySysvar.value = + "SysvarStakeHistory1111111111111111111111111" as Address<"SysvarStakeHistory1111111111111111111111111">; + } + if (!accounts.stakeConfigSysvar.value) { + accounts.stakeConfigSysvar.value = + "StakeConfig11111111111111111111111111111111" as Address<"StakeConfig11111111111111111111111111111111">; + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + if (!accounts.stakeProgram.value) { + accounts.stakeProgram.value = + "Stake11111111111111111111111111111111111111" as Address<"Stake11111111111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.staker), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.validatorList), + getAccountMeta(accounts.reserveStake), + getAccountMeta(accounts.transientStakeAccount), + getAccountMeta(accounts.validatorStakeAccount), + getAccountMeta(accounts.validatorVoteAccount), + getAccountMeta(accounts.clockSysvar), + getAccountMeta(accounts.rentSysvar), + getAccountMeta(accounts.stakeHistorySysvar), + getAccountMeta(accounts.stakeConfigSysvar), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.stakeProgram), + ], + data: getIncreaseValidatorStakeInstructionDataEncoder().encode( + args as IncreaseValidatorStakeInstructionDataArgs, + ), + programAddress, + } as IncreaseValidatorStakeInstruction< + TProgramAddress, + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountTransientStakeAccount, + TAccountValidatorStakeAccount, + TAccountValidatorVoteAccount, + TAccountClockSysvar, + TAccountRentSysvar, + TAccountStakeHistorySysvar, + TAccountStakeConfigSysvar, + TAccountSystemProgram, + TAccountStakeProgram + >); +} + +export interface IncreaseValidatorStakeInput< + TAccountStakePool extends string = string, + TAccountStaker extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountValidatorList extends string = string, + TAccountReserveStake extends string = string, + TAccountTransientStakeAccount extends string = string, + TAccountValidatorStakeAccount extends string = string, + TAccountValidatorVoteAccount extends string = string, + TAccountClockSysvar extends string = string, + TAccountRentSysvar extends string = string, + TAccountStakeHistorySysvar extends string = string, + TAccountStakeConfigSysvar extends string = string, + TAccountSystemProgram extends string = string, + TAccountStakeProgram extends string = string, +> { + stakePool: Address; + staker: TransactionSigner; + withdrawAuthority: Address; + validatorList: Address; + reserveStake: Address; + transientStakeAccount: Address; + validatorStakeAccount: Address; + validatorVoteAccount: Address; + clockSysvar?: Address; + rentSysvar?: Address; + stakeHistorySysvar?: Address; + stakeConfigSysvar?: Address; + systemProgram?: Address; + stakeProgram?: Address; + lamports: IncreaseValidatorStakeInstructionDataArgs["lamports"]; + transientStakeSeed: IncreaseValidatorStakeInstructionDataArgs["transientStakeSeed"]; +} + +export function getIncreaseValidatorStakeInstruction< + TAccountStakePool extends string, + TAccountStaker extends string, + TAccountWithdrawAuthority extends string, + TAccountValidatorList extends string, + TAccountReserveStake extends string, + TAccountTransientStakeAccount extends string, + TAccountValidatorStakeAccount extends string, + TAccountValidatorVoteAccount extends string, + TAccountClockSysvar extends string, + TAccountRentSysvar extends string, + TAccountStakeHistorySysvar extends string, + TAccountStakeConfigSysvar extends string, + TAccountSystemProgram extends string, + TAccountStakeProgram extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: IncreaseValidatorStakeInput< + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountTransientStakeAccount, + TAccountValidatorStakeAccount, + TAccountValidatorVoteAccount, + TAccountClockSysvar, + TAccountRentSysvar, + TAccountStakeHistorySysvar, + TAccountStakeConfigSysvar, + TAccountSystemProgram, + TAccountStakeProgram + >, + config?: { programAddress?: TProgramAddress }, +): IncreaseValidatorStakeInstruction< + TProgramAddress, + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountTransientStakeAccount, + TAccountValidatorStakeAccount, + TAccountValidatorVoteAccount, + TAccountClockSysvar, + TAccountRentSysvar, + TAccountStakeHistorySysvar, + TAccountStakeConfigSysvar, + TAccountSystemProgram, + TAccountStakeProgram +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: false }, + staker: { value: input.staker ?? null, isWritable: false }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + validatorList: { value: input.validatorList ?? null, isWritable: true }, + reserveStake: { value: input.reserveStake ?? null, isWritable: true }, + transientStakeAccount: { + value: input.transientStakeAccount ?? null, + isWritable: true, + }, + validatorStakeAccount: { + value: input.validatorStakeAccount ?? null, + isWritable: false, + }, + validatorVoteAccount: { + value: input.validatorVoteAccount ?? null, + isWritable: false, + }, + clockSysvar: { value: input.clockSysvar ?? null, isWritable: false }, + rentSysvar: { value: input.rentSysvar ?? null, isWritable: false }, + stakeHistorySysvar: { + value: input.stakeHistorySysvar ?? null, + isWritable: false, + }, + stakeConfigSysvar: { + value: input.stakeConfigSysvar ?? null, + isWritable: false, + }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + stakeProgram: { value: input.stakeProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.clockSysvar.value) { + accounts.clockSysvar.value = + "SysvarC1ock11111111111111111111111111111111" as Address<"SysvarC1ock11111111111111111111111111111111">; + } + if (!accounts.rentSysvar.value) { + accounts.rentSysvar.value = + "SysvarRent111111111111111111111111111111111" as Address<"SysvarRent111111111111111111111111111111111">; + } + if (!accounts.stakeHistorySysvar.value) { + accounts.stakeHistorySysvar.value = + "SysvarStakeHistory1111111111111111111111111" as Address<"SysvarStakeHistory1111111111111111111111111">; + } + if (!accounts.stakeConfigSysvar.value) { + accounts.stakeConfigSysvar.value = + "StakeConfig11111111111111111111111111111111" as Address<"StakeConfig11111111111111111111111111111111">; + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + if (!accounts.stakeProgram.value) { + accounts.stakeProgram.value = + "Stake11111111111111111111111111111111111111" as Address<"Stake11111111111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.staker), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.validatorList), + getAccountMeta(accounts.reserveStake), + getAccountMeta(accounts.transientStakeAccount), + getAccountMeta(accounts.validatorStakeAccount), + getAccountMeta(accounts.validatorVoteAccount), + getAccountMeta(accounts.clockSysvar), + getAccountMeta(accounts.rentSysvar), + getAccountMeta(accounts.stakeHistorySysvar), + getAccountMeta(accounts.stakeConfigSysvar), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.stakeProgram), + ], + data: getIncreaseValidatorStakeInstructionDataEncoder().encode( + args as IncreaseValidatorStakeInstructionDataArgs, + ), + programAddress, + } as IncreaseValidatorStakeInstruction< + TProgramAddress, + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountTransientStakeAccount, + TAccountValidatorStakeAccount, + TAccountValidatorVoteAccount, + TAccountClockSysvar, + TAccountRentSysvar, + TAccountStakeHistorySysvar, + TAccountStakeConfigSysvar, + TAccountSystemProgram, + TAccountStakeProgram + >); +} + +export interface ParsedIncreaseValidatorStakeInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + stakePool: TAccountMetas[0]; + staker: TAccountMetas[1]; + withdrawAuthority: TAccountMetas[2]; + validatorList: TAccountMetas[3]; + reserveStake: TAccountMetas[4]; + transientStakeAccount: TAccountMetas[5]; + validatorStakeAccount: TAccountMetas[6]; + validatorVoteAccount: TAccountMetas[7]; + clockSysvar: TAccountMetas[8]; + rentSysvar: TAccountMetas[9]; + stakeHistorySysvar: TAccountMetas[10]; + stakeConfigSysvar: TAccountMetas[11]; + systemProgram: TAccountMetas[12]; + stakeProgram: TAccountMetas[13]; + }; + data: IncreaseValidatorStakeInstructionData; +} + +export function parseIncreaseValidatorStakeInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedIncreaseValidatorStakeInstruction { + if (instruction.accounts.length < 14) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + stakePool: getNextAccount(), + staker: getNextAccount(), + withdrawAuthority: getNextAccount(), + validatorList: getNextAccount(), + reserveStake: getNextAccount(), + transientStakeAccount: getNextAccount(), + validatorStakeAccount: getNextAccount(), + validatorVoteAccount: getNextAccount(), + clockSysvar: getNextAccount(), + rentSysvar: getNextAccount(), + stakeHistorySysvar: getNextAccount(), + stakeConfigSysvar: getNextAccount(), + systemProgram: getNextAccount(), + stakeProgram: getNextAccount(), + }, + data: getIncreaseValidatorStakeInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/spl-stake-pool/src/generated/instructions/index.ts b/clients/spl-stake-pool/src/generated/instructions/index.ts new file mode 100644 index 00000000..3ef7170f --- /dev/null +++ b/clients/spl-stake-pool/src/generated/instructions/index.ts @@ -0,0 +1,35 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +export * from "./addValidatorToPool.js"; +export * from "./cleanupRemovedValidatorEntries.js"; +export * from "./createTokenMetadata.js"; +export * from "./decreaseAdditionalValidatorStake.js"; +export * from "./decreaseValidatorStake.js"; +export * from "./decreaseValidatorStakeWithReserve.js"; +export * from "./depositSol.js"; +export * from "./depositSolWithSlippage.js"; +export * from "./depositStake.js"; +export * from "./depositStakeWithSlippage.js"; +export * from "./increaseAdditionalValidatorStake.js"; +export * from "./increaseValidatorStake.js"; +export * from "./initialize.js"; +export * from "./redelegate.js"; +export * from "./removeValidatorFromPool.js"; +export * from "./setFee.js"; +export * from "./setFundingAuthority.js"; +export * from "./setManager.js"; +export * from "./setPreferredValidator.js"; +export * from "./setStaker.js"; +export * from "./updateStakePoolBalance.js"; +export * from "./updateTokenMetadata.js"; +export * from "./updateValidatorListBalance.js"; +export * from "./withdrawSol.js"; +export * from "./withdrawSolWithSlippage.js"; +export * from "./withdrawStake.js"; +export * from "./withdrawStakeWithSlippage.js"; diff --git a/clients/spl-stake-pool/src/generated/instructions/initialize.ts b/clients/spl-stake-pool/src/generated/instructions/initialize.ts new file mode 100644 index 00000000..1794da10 --- /dev/null +++ b/clients/spl-stake-pool/src/generated/instructions/initialize.ts @@ -0,0 +1,507 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import type { Fee, FeeArgs } from "../types/index.js"; +import { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getU32Decoder, + getU32Encoder, + transformEncoder, +} from "@solana/kit"; +import { findWithdrawAuthorityPda } from "../pdas/index.js"; +import { SPL_STAKE_POOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; +import { getFeeDecoder, getFeeEncoder } from "../types/index.js"; + +export const INITIALIZE_DISCRIMINATOR = 0; + +export function getInitializeDiscriminatorBytes(): ReadonlyUint8Array { + return getU8Encoder().encode(INITIALIZE_DISCRIMINATOR); +} + +export type InitializeInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountStakePool extends string | AccountMeta = string, + TAccountManager extends string | AccountMeta = string, + TAccountStaker extends string | AccountMeta = string, + TAccountWithdrawAuthority extends string | AccountMeta = string, + TAccountValidatorList extends string | AccountMeta = string, + TAccountReserveStake extends string | AccountMeta = string, + TAccountPoolMint extends string | AccountMeta = string, + TAccountFeeAccount extends string | AccountMeta = string, + TAccountTokenProgram extends + | string + | AccountMeta = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + TAccountDepositAuthority extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountStakePool extends string + ? WritableAccount + : TAccountStakePool, + TAccountManager extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountManager, + TAccountStaker extends string + ? ReadonlyAccount + : TAccountStaker, + TAccountWithdrawAuthority extends string + ? ReadonlyAccount + : TAccountWithdrawAuthority, + TAccountValidatorList extends string + ? WritableAccount + : TAccountValidatorList, + TAccountReserveStake extends string + ? ReadonlyAccount + : TAccountReserveStake, + TAccountPoolMint extends string + ? ReadonlyAccount + : TAccountPoolMint, + TAccountFeeAccount extends string + ? ReadonlyAccount + : TAccountFeeAccount, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + TAccountDepositAuthority extends string + ? ReadonlyAccount + : TAccountDepositAuthority, + ...TRemainingAccounts, + ] + >; + +export interface InitializeInstructionData { + discriminator: number; + fee: Fee; + withdrawalFee: Fee; + depositFee: Fee; + referralFee: number; + maxValidators: number; +} + +export interface InitializeInstructionDataArgs { + fee: FeeArgs; + withdrawalFee: FeeArgs; + depositFee: FeeArgs; + referralFee: number; + maxValidators: number; +} + +export function getInitializeInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", getU8Encoder()], + ["fee", getFeeEncoder()], + ["withdrawalFee", getFeeEncoder()], + ["depositFee", getFeeEncoder()], + ["referralFee", getU8Encoder()], + ["maxValidators", getU32Encoder()], + ]), + (value) => ({ ...value, discriminator: INITIALIZE_DISCRIMINATOR }), + ); +} + +export function getInitializeInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", getU8Decoder()], + ["fee", getFeeDecoder()], + ["withdrawalFee", getFeeDecoder()], + ["depositFee", getFeeDecoder()], + ["referralFee", getU8Decoder()], + ["maxValidators", getU32Decoder()], + ]); +} + +export function getInitializeInstructionDataCodec(): FixedSizeCodec< + InitializeInstructionDataArgs, + InitializeInstructionData +> { + return combineCodec( + getInitializeInstructionDataEncoder(), + getInitializeInstructionDataDecoder(), + ); +} + +export interface InitializeAsyncInput< + TAccountStakePool extends string = string, + TAccountManager extends string = string, + TAccountStaker extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountValidatorList extends string = string, + TAccountReserveStake extends string = string, + TAccountPoolMint extends string = string, + TAccountFeeAccount extends string = string, + TAccountTokenProgram extends string = string, + TAccountDepositAuthority extends string = string, +> { + stakePool: Address; + manager: TransactionSigner; + staker: Address; + withdrawAuthority?: Address; + validatorList: Address; + reserveStake: Address; + poolMint: Address; + feeAccount: Address; + tokenProgram?: Address; + depositAuthority: + | Address + | TransactionSigner; + fee: InitializeInstructionDataArgs["fee"]; + withdrawalFee: InitializeInstructionDataArgs["withdrawalFee"]; + depositFee: InitializeInstructionDataArgs["depositFee"]; + referralFee: InitializeInstructionDataArgs["referralFee"]; + maxValidators: InitializeInstructionDataArgs["maxValidators"]; +} + +export async function getInitializeInstructionAsync< + TAccountStakePool extends string, + TAccountManager extends string, + TAccountStaker extends string, + TAccountWithdrawAuthority extends string, + TAccountValidatorList extends string, + TAccountReserveStake extends string, + TAccountPoolMint extends string, + TAccountFeeAccount extends string, + TAccountTokenProgram extends string, + TAccountDepositAuthority extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: InitializeAsyncInput< + TAccountStakePool, + TAccountManager, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountPoolMint, + TAccountFeeAccount, + TAccountTokenProgram, + TAccountDepositAuthority + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + InitializeInstruction< + TProgramAddress, + TAccountStakePool, + TAccountManager, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountPoolMint, + TAccountFeeAccount, + TAccountTokenProgram, + (typeof input)["depositAuthority"] extends TransactionSigner + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountDepositAuthority + > +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: true }, + manager: { value: input.manager ?? null, isWritable: false }, + staker: { value: input.staker ?? null, isWritable: false }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + validatorList: { value: input.validatorList ?? null, isWritable: true }, + reserveStake: { value: input.reserveStake ?? null, isWritable: false }, + poolMint: { value: input.poolMint ?? null, isWritable: false }, + feeAccount: { value: input.feeAccount ?? null, isWritable: false }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + depositAuthority: { + value: input.depositAuthority ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.withdrawAuthority.value) { + accounts.withdrawAuthority.value = await findWithdrawAuthorityPda({ + stakePoolAddress: expectAddress(accounts.stakePool.value), + }); + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.manager), + getAccountMeta(accounts.staker), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.validatorList), + getAccountMeta(accounts.reserveStake), + getAccountMeta(accounts.poolMint), + getAccountMeta(accounts.feeAccount), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.depositAuthority), + ], + data: getInitializeInstructionDataEncoder().encode( + args as InitializeInstructionDataArgs, + ), + programAddress, + } as InitializeInstruction< + TProgramAddress, + TAccountStakePool, + TAccountManager, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountPoolMint, + TAccountFeeAccount, + TAccountTokenProgram, + (typeof input)["depositAuthority"] extends TransactionSigner + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountDepositAuthority + >); +} + +export interface InitializeInput< + TAccountStakePool extends string = string, + TAccountManager extends string = string, + TAccountStaker extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountValidatorList extends string = string, + TAccountReserveStake extends string = string, + TAccountPoolMint extends string = string, + TAccountFeeAccount extends string = string, + TAccountTokenProgram extends string = string, + TAccountDepositAuthority extends string = string, +> { + stakePool: Address; + manager: TransactionSigner; + staker: Address; + withdrawAuthority: Address; + validatorList: Address; + reserveStake: Address; + poolMint: Address; + feeAccount: Address; + tokenProgram?: Address; + depositAuthority: + | Address + | TransactionSigner; + fee: InitializeInstructionDataArgs["fee"]; + withdrawalFee: InitializeInstructionDataArgs["withdrawalFee"]; + depositFee: InitializeInstructionDataArgs["depositFee"]; + referralFee: InitializeInstructionDataArgs["referralFee"]; + maxValidators: InitializeInstructionDataArgs["maxValidators"]; +} + +export function getInitializeInstruction< + TAccountStakePool extends string, + TAccountManager extends string, + TAccountStaker extends string, + TAccountWithdrawAuthority extends string, + TAccountValidatorList extends string, + TAccountReserveStake extends string, + TAccountPoolMint extends string, + TAccountFeeAccount extends string, + TAccountTokenProgram extends string, + TAccountDepositAuthority extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: InitializeInput< + TAccountStakePool, + TAccountManager, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountPoolMint, + TAccountFeeAccount, + TAccountTokenProgram, + TAccountDepositAuthority + >, + config?: { programAddress?: TProgramAddress }, +): InitializeInstruction< + TProgramAddress, + TAccountStakePool, + TAccountManager, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountPoolMint, + TAccountFeeAccount, + TAccountTokenProgram, + (typeof input)["depositAuthority"] extends TransactionSigner + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountDepositAuthority +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: true }, + manager: { value: input.manager ?? null, isWritable: false }, + staker: { value: input.staker ?? null, isWritable: false }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + validatorList: { value: input.validatorList ?? null, isWritable: true }, + reserveStake: { value: input.reserveStake ?? null, isWritable: false }, + poolMint: { value: input.poolMint ?? null, isWritable: false }, + feeAccount: { value: input.feeAccount ?? null, isWritable: false }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + depositAuthority: { + value: input.depositAuthority ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.manager), + getAccountMeta(accounts.staker), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.validatorList), + getAccountMeta(accounts.reserveStake), + getAccountMeta(accounts.poolMint), + getAccountMeta(accounts.feeAccount), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.depositAuthority), + ], + data: getInitializeInstructionDataEncoder().encode( + args as InitializeInstructionDataArgs, + ), + programAddress, + } as InitializeInstruction< + TProgramAddress, + TAccountStakePool, + TAccountManager, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountPoolMint, + TAccountFeeAccount, + TAccountTokenProgram, + (typeof input)["depositAuthority"] extends TransactionSigner + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountDepositAuthority + >); +} + +export interface ParsedInitializeInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + stakePool: TAccountMetas[0]; + manager: TAccountMetas[1]; + staker: TAccountMetas[2]; + withdrawAuthority: TAccountMetas[3]; + validatorList: TAccountMetas[4]; + reserveStake: TAccountMetas[5]; + poolMint: TAccountMetas[6]; + feeAccount: TAccountMetas[7]; + tokenProgram: TAccountMetas[8]; + depositAuthority: TAccountMetas[9]; + }; + data: InitializeInstructionData; +} + +export function parseInitializeInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedInitializeInstruction { + if (instruction.accounts.length < 10) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + stakePool: getNextAccount(), + manager: getNextAccount(), + staker: getNextAccount(), + withdrawAuthority: getNextAccount(), + validatorList: getNextAccount(), + reserveStake: getNextAccount(), + poolMint: getNextAccount(), + feeAccount: getNextAccount(), + tokenProgram: getNextAccount(), + depositAuthority: getNextAccount(), + }, + data: getInitializeInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/spl-stake-pool/src/generated/instructions/redelegate.ts b/clients/spl-stake-pool/src/generated/instructions/redelegate.ts new file mode 100644 index 00000000..2202cf6d --- /dev/null +++ b/clients/spl-stake-pool/src/generated/instructions/redelegate.ts @@ -0,0 +1,691 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getU64Decoder, + getU64Encoder, + transformEncoder, +} from "@solana/kit"; +import { findWithdrawAuthorityPda } from "../pdas/index.js"; +import { SPL_STAKE_POOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; + +export const REDELEGATE_DISCRIMINATOR = 22; + +export function getRedelegateDiscriminatorBytes(): ReadonlyUint8Array { + return getU8Encoder().encode(REDELEGATE_DISCRIMINATOR); +} + +export type RedelegateInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountStakePool extends string | AccountMeta = string, + TAccountStaker extends string | AccountMeta = string, + TAccountWithdrawAuthority extends string | AccountMeta = string, + TAccountValidatorList extends string | AccountMeta = string, + TAccountReserveStake extends string | AccountMeta = string, + TAccountSourceCanonicalStake extends string | AccountMeta = string, + TAccountSourceTransientStake extends string | AccountMeta = string, + TAccountEphemeralStake extends string | AccountMeta = string, + TAccountDestinationTransientStake extends string | AccountMeta = string, + TAccountDestinationStake extends string | AccountMeta = string, + TAccountDestinationVote extends string | AccountMeta = string, + TAccountClockSysvar extends + | string + | AccountMeta = "SysvarC1ock11111111111111111111111111111111", + TAccountStakeHistorySysvar extends + | string + | AccountMeta = "SysvarStakeHistory1111111111111111111111111", + TAccountStakeConfigSysvar extends + | string + | AccountMeta = "StakeConfig11111111111111111111111111111111", + TAccountSystemProgram extends + | string + | AccountMeta = "11111111111111111111111111111111", + TAccountStakeProgram extends + | string + | AccountMeta = "Stake11111111111111111111111111111111111111", + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountStakePool extends string + ? ReadonlyAccount + : TAccountStakePool, + TAccountStaker extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountStaker, + TAccountWithdrawAuthority extends string + ? ReadonlyAccount + : TAccountWithdrawAuthority, + TAccountValidatorList extends string + ? WritableAccount + : TAccountValidatorList, + TAccountReserveStake extends string + ? WritableAccount + : TAccountReserveStake, + TAccountSourceCanonicalStake extends string + ? WritableAccount + : TAccountSourceCanonicalStake, + TAccountSourceTransientStake extends string + ? WritableAccount + : TAccountSourceTransientStake, + TAccountEphemeralStake extends string + ? WritableAccount + : TAccountEphemeralStake, + TAccountDestinationTransientStake extends string + ? WritableAccount + : TAccountDestinationTransientStake, + TAccountDestinationStake extends string + ? ReadonlyAccount + : TAccountDestinationStake, + TAccountDestinationVote extends string + ? ReadonlyAccount + : TAccountDestinationVote, + TAccountClockSysvar extends string + ? ReadonlyAccount + : TAccountClockSysvar, + TAccountStakeHistorySysvar extends string + ? ReadonlyAccount + : TAccountStakeHistorySysvar, + TAccountStakeConfigSysvar extends string + ? ReadonlyAccount + : TAccountStakeConfigSysvar, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + TAccountStakeProgram extends string + ? ReadonlyAccount + : TAccountStakeProgram, + ...TRemainingAccounts, + ] + >; + +export interface RedelegateInstructionData { + discriminator: number; + lamports: bigint; + sourceTransientStakeSeed: bigint; + ephemeralStakeSeed: bigint; + destinationTransientStakeSeed: bigint; +} + +export interface RedelegateInstructionDataArgs { + lamports: number | bigint; + sourceTransientStakeSeed: number | bigint; + ephemeralStakeSeed: number | bigint; + destinationTransientStakeSeed: number | bigint; +} + +export function getRedelegateInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", getU8Encoder()], + ["lamports", getU64Encoder()], + ["sourceTransientStakeSeed", getU64Encoder()], + ["ephemeralStakeSeed", getU64Encoder()], + ["destinationTransientStakeSeed", getU64Encoder()], + ]), + (value) => ({ ...value, discriminator: REDELEGATE_DISCRIMINATOR }), + ); +} + +export function getRedelegateInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", getU8Decoder()], + ["lamports", getU64Decoder()], + ["sourceTransientStakeSeed", getU64Decoder()], + ["ephemeralStakeSeed", getU64Decoder()], + ["destinationTransientStakeSeed", getU64Decoder()], + ]); +} + +export function getRedelegateInstructionDataCodec(): FixedSizeCodec< + RedelegateInstructionDataArgs, + RedelegateInstructionData +> { + return combineCodec( + getRedelegateInstructionDataEncoder(), + getRedelegateInstructionDataDecoder(), + ); +} + +export interface RedelegateAsyncInput< + TAccountStakePool extends string = string, + TAccountStaker extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountValidatorList extends string = string, + TAccountReserveStake extends string = string, + TAccountSourceCanonicalStake extends string = string, + TAccountSourceTransientStake extends string = string, + TAccountEphemeralStake extends string = string, + TAccountDestinationTransientStake extends string = string, + TAccountDestinationStake extends string = string, + TAccountDestinationVote extends string = string, + TAccountClockSysvar extends string = string, + TAccountStakeHistorySysvar extends string = string, + TAccountStakeConfigSysvar extends string = string, + TAccountSystemProgram extends string = string, + TAccountStakeProgram extends string = string, +> { + stakePool: Address; + staker: TransactionSigner; + withdrawAuthority?: Address; + validatorList: Address; + reserveStake: Address; + sourceCanonicalStake: Address; + sourceTransientStake: Address; + ephemeralStake: Address; + destinationTransientStake: Address; + destinationStake: Address; + destinationVote: Address; + clockSysvar?: Address; + stakeHistorySysvar?: Address; + stakeConfigSysvar?: Address; + systemProgram?: Address; + stakeProgram?: Address; + lamports: RedelegateInstructionDataArgs["lamports"]; + sourceTransientStakeSeed: RedelegateInstructionDataArgs["sourceTransientStakeSeed"]; + ephemeralStakeSeed: RedelegateInstructionDataArgs["ephemeralStakeSeed"]; + destinationTransientStakeSeed: RedelegateInstructionDataArgs["destinationTransientStakeSeed"]; +} + +export async function getRedelegateInstructionAsync< + TAccountStakePool extends string, + TAccountStaker extends string, + TAccountWithdrawAuthority extends string, + TAccountValidatorList extends string, + TAccountReserveStake extends string, + TAccountSourceCanonicalStake extends string, + TAccountSourceTransientStake extends string, + TAccountEphemeralStake extends string, + TAccountDestinationTransientStake extends string, + TAccountDestinationStake extends string, + TAccountDestinationVote extends string, + TAccountClockSysvar extends string, + TAccountStakeHistorySysvar extends string, + TAccountStakeConfigSysvar extends string, + TAccountSystemProgram extends string, + TAccountStakeProgram extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: RedelegateAsyncInput< + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountSourceCanonicalStake, + TAccountSourceTransientStake, + TAccountEphemeralStake, + TAccountDestinationTransientStake, + TAccountDestinationStake, + TAccountDestinationVote, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountStakeConfigSysvar, + TAccountSystemProgram, + TAccountStakeProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + RedelegateInstruction< + TProgramAddress, + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountSourceCanonicalStake, + TAccountSourceTransientStake, + TAccountEphemeralStake, + TAccountDestinationTransientStake, + TAccountDestinationStake, + TAccountDestinationVote, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountStakeConfigSysvar, + TAccountSystemProgram, + TAccountStakeProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: false }, + staker: { value: input.staker ?? null, isWritable: false }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + validatorList: { value: input.validatorList ?? null, isWritable: true }, + reserveStake: { value: input.reserveStake ?? null, isWritable: true }, + sourceCanonicalStake: { + value: input.sourceCanonicalStake ?? null, + isWritable: true, + }, + sourceTransientStake: { + value: input.sourceTransientStake ?? null, + isWritable: true, + }, + ephemeralStake: { value: input.ephemeralStake ?? null, isWritable: true }, + destinationTransientStake: { + value: input.destinationTransientStake ?? null, + isWritable: true, + }, + destinationStake: { + value: input.destinationStake ?? null, + isWritable: false, + }, + destinationVote: { + value: input.destinationVote ?? null, + isWritable: false, + }, + clockSysvar: { value: input.clockSysvar ?? null, isWritable: false }, + stakeHistorySysvar: { + value: input.stakeHistorySysvar ?? null, + isWritable: false, + }, + stakeConfigSysvar: { + value: input.stakeConfigSysvar ?? null, + isWritable: false, + }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + stakeProgram: { value: input.stakeProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.withdrawAuthority.value) { + accounts.withdrawAuthority.value = await findWithdrawAuthorityPda({ + stakePoolAddress: expectAddress(accounts.stakePool.value), + }); + } + if (!accounts.clockSysvar.value) { + accounts.clockSysvar.value = + "SysvarC1ock11111111111111111111111111111111" as Address<"SysvarC1ock11111111111111111111111111111111">; + } + if (!accounts.stakeHistorySysvar.value) { + accounts.stakeHistorySysvar.value = + "SysvarStakeHistory1111111111111111111111111" as Address<"SysvarStakeHistory1111111111111111111111111">; + } + if (!accounts.stakeConfigSysvar.value) { + accounts.stakeConfigSysvar.value = + "StakeConfig11111111111111111111111111111111" as Address<"StakeConfig11111111111111111111111111111111">; + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + if (!accounts.stakeProgram.value) { + accounts.stakeProgram.value = + "Stake11111111111111111111111111111111111111" as Address<"Stake11111111111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.staker), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.validatorList), + getAccountMeta(accounts.reserveStake), + getAccountMeta(accounts.sourceCanonicalStake), + getAccountMeta(accounts.sourceTransientStake), + getAccountMeta(accounts.ephemeralStake), + getAccountMeta(accounts.destinationTransientStake), + getAccountMeta(accounts.destinationStake), + getAccountMeta(accounts.destinationVote), + getAccountMeta(accounts.clockSysvar), + getAccountMeta(accounts.stakeHistorySysvar), + getAccountMeta(accounts.stakeConfigSysvar), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.stakeProgram), + ], + data: getRedelegateInstructionDataEncoder().encode( + args as RedelegateInstructionDataArgs, + ), + programAddress, + } as RedelegateInstruction< + TProgramAddress, + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountSourceCanonicalStake, + TAccountSourceTransientStake, + TAccountEphemeralStake, + TAccountDestinationTransientStake, + TAccountDestinationStake, + TAccountDestinationVote, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountStakeConfigSysvar, + TAccountSystemProgram, + TAccountStakeProgram + >); +} + +export interface RedelegateInput< + TAccountStakePool extends string = string, + TAccountStaker extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountValidatorList extends string = string, + TAccountReserveStake extends string = string, + TAccountSourceCanonicalStake extends string = string, + TAccountSourceTransientStake extends string = string, + TAccountEphemeralStake extends string = string, + TAccountDestinationTransientStake extends string = string, + TAccountDestinationStake extends string = string, + TAccountDestinationVote extends string = string, + TAccountClockSysvar extends string = string, + TAccountStakeHistorySysvar extends string = string, + TAccountStakeConfigSysvar extends string = string, + TAccountSystemProgram extends string = string, + TAccountStakeProgram extends string = string, +> { + stakePool: Address; + staker: TransactionSigner; + withdrawAuthority: Address; + validatorList: Address; + reserveStake: Address; + sourceCanonicalStake: Address; + sourceTransientStake: Address; + ephemeralStake: Address; + destinationTransientStake: Address; + destinationStake: Address; + destinationVote: Address; + clockSysvar?: Address; + stakeHistorySysvar?: Address; + stakeConfigSysvar?: Address; + systemProgram?: Address; + stakeProgram?: Address; + lamports: RedelegateInstructionDataArgs["lamports"]; + sourceTransientStakeSeed: RedelegateInstructionDataArgs["sourceTransientStakeSeed"]; + ephemeralStakeSeed: RedelegateInstructionDataArgs["ephemeralStakeSeed"]; + destinationTransientStakeSeed: RedelegateInstructionDataArgs["destinationTransientStakeSeed"]; +} + +export function getRedelegateInstruction< + TAccountStakePool extends string, + TAccountStaker extends string, + TAccountWithdrawAuthority extends string, + TAccountValidatorList extends string, + TAccountReserveStake extends string, + TAccountSourceCanonicalStake extends string, + TAccountSourceTransientStake extends string, + TAccountEphemeralStake extends string, + TAccountDestinationTransientStake extends string, + TAccountDestinationStake extends string, + TAccountDestinationVote extends string, + TAccountClockSysvar extends string, + TAccountStakeHistorySysvar extends string, + TAccountStakeConfigSysvar extends string, + TAccountSystemProgram extends string, + TAccountStakeProgram extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: RedelegateInput< + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountSourceCanonicalStake, + TAccountSourceTransientStake, + TAccountEphemeralStake, + TAccountDestinationTransientStake, + TAccountDestinationStake, + TAccountDestinationVote, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountStakeConfigSysvar, + TAccountSystemProgram, + TAccountStakeProgram + >, + config?: { programAddress?: TProgramAddress }, +): RedelegateInstruction< + TProgramAddress, + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountSourceCanonicalStake, + TAccountSourceTransientStake, + TAccountEphemeralStake, + TAccountDestinationTransientStake, + TAccountDestinationStake, + TAccountDestinationVote, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountStakeConfigSysvar, + TAccountSystemProgram, + TAccountStakeProgram +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: false }, + staker: { value: input.staker ?? null, isWritable: false }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + validatorList: { value: input.validatorList ?? null, isWritable: true }, + reserveStake: { value: input.reserveStake ?? null, isWritable: true }, + sourceCanonicalStake: { + value: input.sourceCanonicalStake ?? null, + isWritable: true, + }, + sourceTransientStake: { + value: input.sourceTransientStake ?? null, + isWritable: true, + }, + ephemeralStake: { value: input.ephemeralStake ?? null, isWritable: true }, + destinationTransientStake: { + value: input.destinationTransientStake ?? null, + isWritable: true, + }, + destinationStake: { + value: input.destinationStake ?? null, + isWritable: false, + }, + destinationVote: { + value: input.destinationVote ?? null, + isWritable: false, + }, + clockSysvar: { value: input.clockSysvar ?? null, isWritable: false }, + stakeHistorySysvar: { + value: input.stakeHistorySysvar ?? null, + isWritable: false, + }, + stakeConfigSysvar: { + value: input.stakeConfigSysvar ?? null, + isWritable: false, + }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + stakeProgram: { value: input.stakeProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.clockSysvar.value) { + accounts.clockSysvar.value = + "SysvarC1ock11111111111111111111111111111111" as Address<"SysvarC1ock11111111111111111111111111111111">; + } + if (!accounts.stakeHistorySysvar.value) { + accounts.stakeHistorySysvar.value = + "SysvarStakeHistory1111111111111111111111111" as Address<"SysvarStakeHistory1111111111111111111111111">; + } + if (!accounts.stakeConfigSysvar.value) { + accounts.stakeConfigSysvar.value = + "StakeConfig11111111111111111111111111111111" as Address<"StakeConfig11111111111111111111111111111111">; + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + if (!accounts.stakeProgram.value) { + accounts.stakeProgram.value = + "Stake11111111111111111111111111111111111111" as Address<"Stake11111111111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.staker), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.validatorList), + getAccountMeta(accounts.reserveStake), + getAccountMeta(accounts.sourceCanonicalStake), + getAccountMeta(accounts.sourceTransientStake), + getAccountMeta(accounts.ephemeralStake), + getAccountMeta(accounts.destinationTransientStake), + getAccountMeta(accounts.destinationStake), + getAccountMeta(accounts.destinationVote), + getAccountMeta(accounts.clockSysvar), + getAccountMeta(accounts.stakeHistorySysvar), + getAccountMeta(accounts.stakeConfigSysvar), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.stakeProgram), + ], + data: getRedelegateInstructionDataEncoder().encode( + args as RedelegateInstructionDataArgs, + ), + programAddress, + } as RedelegateInstruction< + TProgramAddress, + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountSourceCanonicalStake, + TAccountSourceTransientStake, + TAccountEphemeralStake, + TAccountDestinationTransientStake, + TAccountDestinationStake, + TAccountDestinationVote, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountStakeConfigSysvar, + TAccountSystemProgram, + TAccountStakeProgram + >); +} + +export interface ParsedRedelegateInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + stakePool: TAccountMetas[0]; + staker: TAccountMetas[1]; + withdrawAuthority: TAccountMetas[2]; + validatorList: TAccountMetas[3]; + reserveStake: TAccountMetas[4]; + sourceCanonicalStake: TAccountMetas[5]; + sourceTransientStake: TAccountMetas[6]; + ephemeralStake: TAccountMetas[7]; + destinationTransientStake: TAccountMetas[8]; + destinationStake: TAccountMetas[9]; + destinationVote: TAccountMetas[10]; + clockSysvar: TAccountMetas[11]; + stakeHistorySysvar: TAccountMetas[12]; + stakeConfigSysvar: TAccountMetas[13]; + systemProgram: TAccountMetas[14]; + stakeProgram: TAccountMetas[15]; + }; + data: RedelegateInstructionData; +} + +export function parseRedelegateInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedRedelegateInstruction { + if (instruction.accounts.length < 16) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + stakePool: getNextAccount(), + staker: getNextAccount(), + withdrawAuthority: getNextAccount(), + validatorList: getNextAccount(), + reserveStake: getNextAccount(), + sourceCanonicalStake: getNextAccount(), + sourceTransientStake: getNextAccount(), + ephemeralStake: getNextAccount(), + destinationTransientStake: getNextAccount(), + destinationStake: getNextAccount(), + destinationVote: getNextAccount(), + clockSysvar: getNextAccount(), + stakeHistorySysvar: getNextAccount(), + stakeConfigSysvar: getNextAccount(), + systemProgram: getNextAccount(), + stakeProgram: getNextAccount(), + }, + data: getRedelegateInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/spl-stake-pool/src/generated/instructions/removeValidatorFromPool.ts b/clients/spl-stake-pool/src/generated/instructions/removeValidatorFromPool.ts new file mode 100644 index 00000000..cca30e14 --- /dev/null +++ b/clients/spl-stake-pool/src/generated/instructions/removeValidatorFromPool.ts @@ -0,0 +1,443 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, +} from "@solana/kit"; +import { findWithdrawAuthorityPda } from "../pdas/index.js"; +import { SPL_STAKE_POOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; + +export const REMOVE_VALIDATOR_FROM_POOL_DISCRIMINATOR = 2; + +export function getRemoveValidatorFromPoolDiscriminatorBytes(): ReadonlyUint8Array { + return getU8Encoder().encode(REMOVE_VALIDATOR_FROM_POOL_DISCRIMINATOR); +} + +export type RemoveValidatorFromPoolInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountStakePool extends string | AccountMeta = string, + TAccountStaker extends string | AccountMeta = string, + TAccountWithdrawAuthority extends string | AccountMeta = string, + TAccountValidatorStakeList extends string | AccountMeta = string, + TAccountStakeAccount extends string | AccountMeta = string, + TAccountTransientStakeAccount extends string | AccountMeta = string, + TAccountClockSysvar extends + | string + | AccountMeta = "SysvarC1ock11111111111111111111111111111111", + TAccountStakeProgram extends + | string + | AccountMeta = "Stake11111111111111111111111111111111111111", + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountStakePool extends string + ? WritableAccount + : TAccountStakePool, + TAccountStaker extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountStaker, + TAccountWithdrawAuthority extends string + ? ReadonlyAccount + : TAccountWithdrawAuthority, + TAccountValidatorStakeList extends string + ? WritableAccount + : TAccountValidatorStakeList, + TAccountStakeAccount extends string + ? WritableAccount + : TAccountStakeAccount, + TAccountTransientStakeAccount extends string + ? WritableAccount + : TAccountTransientStakeAccount, + TAccountClockSysvar extends string + ? ReadonlyAccount + : TAccountClockSysvar, + TAccountStakeProgram extends string + ? ReadonlyAccount + : TAccountStakeProgram, + ...TRemainingAccounts, + ] + >; + +export interface RemoveValidatorFromPoolInstructionData { + discriminator: number; +} + +export interface RemoveValidatorFromPoolInstructionDataArgs {} + +export function getRemoveValidatorFromPoolInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", getU8Encoder()]]), + (value) => ({ + ...value, + discriminator: REMOVE_VALIDATOR_FROM_POOL_DISCRIMINATOR, + }), + ); +} + +export function getRemoveValidatorFromPoolInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([["discriminator", getU8Decoder()]]); +} + +export function getRemoveValidatorFromPoolInstructionDataCodec(): FixedSizeCodec< + RemoveValidatorFromPoolInstructionDataArgs, + RemoveValidatorFromPoolInstructionData +> { + return combineCodec( + getRemoveValidatorFromPoolInstructionDataEncoder(), + getRemoveValidatorFromPoolInstructionDataDecoder(), + ); +} + +export interface RemoveValidatorFromPoolAsyncInput< + TAccountStakePool extends string = string, + TAccountStaker extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountValidatorStakeList extends string = string, + TAccountStakeAccount extends string = string, + TAccountTransientStakeAccount extends string = string, + TAccountClockSysvar extends string = string, + TAccountStakeProgram extends string = string, +> { + /** Stake pool */ + stakePool: Address; + /** Staker */ + staker: TransactionSigner; + /** Stake pool withdraw authority */ + withdrawAuthority?: Address; + /** Validator stake list storage account */ + validatorStakeList: Address; + /** Stake account to remove from the pool */ + stakeAccount: Address; + /** Transient stake account, to deactivate if necessary */ + transientStakeAccount: Address; + /** Sysvar clock */ + clockSysvar?: Address; + /** Stake program id */ + stakeProgram?: Address; +} + +export async function getRemoveValidatorFromPoolInstructionAsync< + TAccountStakePool extends string, + TAccountStaker extends string, + TAccountWithdrawAuthority extends string, + TAccountValidatorStakeList extends string, + TAccountStakeAccount extends string, + TAccountTransientStakeAccount extends string, + TAccountClockSysvar extends string, + TAccountStakeProgram extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: RemoveValidatorFromPoolAsyncInput< + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorStakeList, + TAccountStakeAccount, + TAccountTransientStakeAccount, + TAccountClockSysvar, + TAccountStakeProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + RemoveValidatorFromPoolInstruction< + TProgramAddress, + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorStakeList, + TAccountStakeAccount, + TAccountTransientStakeAccount, + TAccountClockSysvar, + TAccountStakeProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: true }, + staker: { value: input.staker ?? null, isWritable: false }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + validatorStakeList: { + value: input.validatorStakeList ?? null, + isWritable: true, + }, + stakeAccount: { value: input.stakeAccount ?? null, isWritable: true }, + transientStakeAccount: { + value: input.transientStakeAccount ?? null, + isWritable: true, + }, + clockSysvar: { value: input.clockSysvar ?? null, isWritable: false }, + stakeProgram: { value: input.stakeProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Resolve default values. + if (!accounts.withdrawAuthority.value) { + accounts.withdrawAuthority.value = await findWithdrawAuthorityPda({ + stakePoolAddress: expectAddress(accounts.stakePool.value), + }); + } + if (!accounts.clockSysvar.value) { + accounts.clockSysvar.value = + "SysvarC1ock11111111111111111111111111111111" as Address<"SysvarC1ock11111111111111111111111111111111">; + } + if (!accounts.stakeProgram.value) { + accounts.stakeProgram.value = + "Stake11111111111111111111111111111111111111" as Address<"Stake11111111111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.staker), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.validatorStakeList), + getAccountMeta(accounts.stakeAccount), + getAccountMeta(accounts.transientStakeAccount), + getAccountMeta(accounts.clockSysvar), + getAccountMeta(accounts.stakeProgram), + ], + data: getRemoveValidatorFromPoolInstructionDataEncoder().encode({}), + programAddress, + } as RemoveValidatorFromPoolInstruction< + TProgramAddress, + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorStakeList, + TAccountStakeAccount, + TAccountTransientStakeAccount, + TAccountClockSysvar, + TAccountStakeProgram + >); +} + +export interface RemoveValidatorFromPoolInput< + TAccountStakePool extends string = string, + TAccountStaker extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountValidatorStakeList extends string = string, + TAccountStakeAccount extends string = string, + TAccountTransientStakeAccount extends string = string, + TAccountClockSysvar extends string = string, + TAccountStakeProgram extends string = string, +> { + /** Stake pool */ + stakePool: Address; + /** Staker */ + staker: TransactionSigner; + /** Stake pool withdraw authority */ + withdrawAuthority: Address; + /** Validator stake list storage account */ + validatorStakeList: Address; + /** Stake account to remove from the pool */ + stakeAccount: Address; + /** Transient stake account, to deactivate if necessary */ + transientStakeAccount: Address; + /** Sysvar clock */ + clockSysvar?: Address; + /** Stake program id */ + stakeProgram?: Address; +} + +export function getRemoveValidatorFromPoolInstruction< + TAccountStakePool extends string, + TAccountStaker extends string, + TAccountWithdrawAuthority extends string, + TAccountValidatorStakeList extends string, + TAccountStakeAccount extends string, + TAccountTransientStakeAccount extends string, + TAccountClockSysvar extends string, + TAccountStakeProgram extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: RemoveValidatorFromPoolInput< + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorStakeList, + TAccountStakeAccount, + TAccountTransientStakeAccount, + TAccountClockSysvar, + TAccountStakeProgram + >, + config?: { programAddress?: TProgramAddress }, +): RemoveValidatorFromPoolInstruction< + TProgramAddress, + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorStakeList, + TAccountStakeAccount, + TAccountTransientStakeAccount, + TAccountClockSysvar, + TAccountStakeProgram +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: true }, + staker: { value: input.staker ?? null, isWritable: false }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + validatorStakeList: { + value: input.validatorStakeList ?? null, + isWritable: true, + }, + stakeAccount: { value: input.stakeAccount ?? null, isWritable: true }, + transientStakeAccount: { + value: input.transientStakeAccount ?? null, + isWritable: true, + }, + clockSysvar: { value: input.clockSysvar ?? null, isWritable: false }, + stakeProgram: { value: input.stakeProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Resolve default values. + if (!accounts.clockSysvar.value) { + accounts.clockSysvar.value = + "SysvarC1ock11111111111111111111111111111111" as Address<"SysvarC1ock11111111111111111111111111111111">; + } + if (!accounts.stakeProgram.value) { + accounts.stakeProgram.value = + "Stake11111111111111111111111111111111111111" as Address<"Stake11111111111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.staker), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.validatorStakeList), + getAccountMeta(accounts.stakeAccount), + getAccountMeta(accounts.transientStakeAccount), + getAccountMeta(accounts.clockSysvar), + getAccountMeta(accounts.stakeProgram), + ], + data: getRemoveValidatorFromPoolInstructionDataEncoder().encode({}), + programAddress, + } as RemoveValidatorFromPoolInstruction< + TProgramAddress, + TAccountStakePool, + TAccountStaker, + TAccountWithdrawAuthority, + TAccountValidatorStakeList, + TAccountStakeAccount, + TAccountTransientStakeAccount, + TAccountClockSysvar, + TAccountStakeProgram + >); +} + +export interface ParsedRemoveValidatorFromPoolInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + /** Stake pool */ + stakePool: TAccountMetas[0]; + /** Staker */ + staker: TAccountMetas[1]; + /** Stake pool withdraw authority */ + withdrawAuthority: TAccountMetas[2]; + /** Validator stake list storage account */ + validatorStakeList: TAccountMetas[3]; + /** Stake account to remove from the pool */ + stakeAccount: TAccountMetas[4]; + /** Transient stake account, to deactivate if necessary */ + transientStakeAccount: TAccountMetas[5]; + /** Sysvar clock */ + clockSysvar: TAccountMetas[6]; + /** Stake program id */ + stakeProgram: TAccountMetas[7]; + }; + data: RemoveValidatorFromPoolInstructionData; +} + +export function parseRemoveValidatorFromPoolInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedRemoveValidatorFromPoolInstruction { + if (instruction.accounts.length < 8) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + stakePool: getNextAccount(), + staker: getNextAccount(), + withdrawAuthority: getNextAccount(), + validatorStakeList: getNextAccount(), + stakeAccount: getNextAccount(), + transientStakeAccount: getNextAccount(), + clockSysvar: getNextAccount(), + stakeProgram: getNextAccount(), + }, + data: getRemoveValidatorFromPoolInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/spl-stake-pool/src/generated/instructions/setFee.ts b/clients/spl-stake-pool/src/generated/instructions/setFee.ts new file mode 100644 index 00000000..a79894b6 --- /dev/null +++ b/clients/spl-stake-pool/src/generated/instructions/setFee.ts @@ -0,0 +1,186 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + Codec, + Decoder, + Encoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import type { FeeType, FeeTypeArgs } from "../types/index.js"; +import { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, +} from "@solana/kit"; +import { SPL_STAKE_POOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; +import { getFeeTypeDecoder, getFeeTypeEncoder } from "../types/index.js"; + +export const SET_FEE_DISCRIMINATOR = 12; + +export function getSetFeeDiscriminatorBytes(): ReadonlyUint8Array { + return getU8Encoder().encode(SET_FEE_DISCRIMINATOR); +} + +export type SetFeeInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountStakePool extends string | AccountMeta = string, + TAccountManager extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountStakePool extends string + ? WritableAccount + : TAccountStakePool, + TAccountManager extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountManager, + ...TRemainingAccounts, + ] + >; + +export interface SetFeeInstructionData { + discriminator: number; + fee: FeeType; +} + +export interface SetFeeInstructionDataArgs { + fee: FeeTypeArgs; +} + +export function getSetFeeInstructionDataEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", getU8Encoder()], + ["fee", getFeeTypeEncoder()], + ]), + (value) => ({ ...value, discriminator: SET_FEE_DISCRIMINATOR }), + ); +} + +export function getSetFeeInstructionDataDecoder(): Decoder { + return getStructDecoder([ + ["discriminator", getU8Decoder()], + ["fee", getFeeTypeDecoder()], + ]); +} + +export function getSetFeeInstructionDataCodec(): Codec< + SetFeeInstructionDataArgs, + SetFeeInstructionData +> { + return combineCodec( + getSetFeeInstructionDataEncoder(), + getSetFeeInstructionDataDecoder(), + ); +} + +export interface SetFeeInput< + TAccountStakePool extends string = string, + TAccountManager extends string = string, +> { + /** Stake pool */ + stakePool: Address; + /** Manager */ + manager: TransactionSigner; + fee: SetFeeInstructionDataArgs["fee"]; +} + +export function getSetFeeInstruction< + TAccountStakePool extends string, + TAccountManager extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: SetFeeInput, + config?: { programAddress?: TProgramAddress }, +): SetFeeInstruction { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: true }, + manager: { value: input.manager ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.manager), + ], + data: getSetFeeInstructionDataEncoder().encode( + args as SetFeeInstructionDataArgs, + ), + programAddress, + } as SetFeeInstruction); +} + +export interface ParsedSetFeeInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + /** Stake pool */ + stakePool: TAccountMetas[0]; + /** Manager */ + manager: TAccountMetas[1]; + }; + data: SetFeeInstructionData; +} + +export function parseSetFeeInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedSetFeeInstruction { + if (instruction.accounts.length < 2) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { stakePool: getNextAccount(), manager: getNextAccount() }, + data: getSetFeeInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/spl-stake-pool/src/generated/instructions/setFundingAuthority.ts b/clients/spl-stake-pool/src/generated/instructions/setFundingAuthority.ts new file mode 100644 index 00000000..f4253e17 --- /dev/null +++ b/clients/spl-stake-pool/src/generated/instructions/setFundingAuthority.ts @@ -0,0 +1,228 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import type { FundingType, FundingTypeArgs } from "../types/index.js"; +import { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, +} from "@solana/kit"; +import { SPL_STAKE_POOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; +import { + getFundingTypeDecoder, + getFundingTypeEncoder, +} from "../types/index.js"; + +export const SET_FUNDING_AUTHORITY_DISCRIMINATOR = 15; + +export function getSetFundingAuthorityDiscriminatorBytes(): ReadonlyUint8Array { + return getU8Encoder().encode(SET_FUNDING_AUTHORITY_DISCRIMINATOR); +} + +export type SetFundingAuthorityInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountStakePool extends string | AccountMeta = string, + TAccountManager extends string | AccountMeta = string, + TAccountNewAuthorityPubkey extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountStakePool extends string + ? WritableAccount + : TAccountStakePool, + TAccountManager extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountManager, + TAccountNewAuthorityPubkey extends string + ? ReadonlyAccount + : TAccountNewAuthorityPubkey, + ...TRemainingAccounts, + ] + >; + +export interface SetFundingAuthorityInstructionData { + discriminator: number; + fundingType: FundingType; +} + +export interface SetFundingAuthorityInstructionDataArgs { + fundingType: FundingTypeArgs; +} + +export function getSetFundingAuthorityInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", getU8Encoder()], + ["fundingType", getFundingTypeEncoder()], + ]), + (value) => ({ + ...value, + discriminator: SET_FUNDING_AUTHORITY_DISCRIMINATOR, + }), + ); +} + +export function getSetFundingAuthorityInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", getU8Decoder()], + ["fundingType", getFundingTypeDecoder()], + ]); +} + +export function getSetFundingAuthorityInstructionDataCodec(): FixedSizeCodec< + SetFundingAuthorityInstructionDataArgs, + SetFundingAuthorityInstructionData +> { + return combineCodec( + getSetFundingAuthorityInstructionDataEncoder(), + getSetFundingAuthorityInstructionDataDecoder(), + ); +} + +export interface SetFundingAuthorityInput< + TAccountStakePool extends string = string, + TAccountManager extends string = string, + TAccountNewAuthorityPubkey extends string = string, +> { + /** Stake pool */ + stakePool: Address; + /** Manager */ + manager: TransactionSigner; + /** New authority pubkey */ + newAuthorityPubkey: Address; + fundingType: SetFundingAuthorityInstructionDataArgs["fundingType"]; +} + +export function getSetFundingAuthorityInstruction< + TAccountStakePool extends string, + TAccountManager extends string, + TAccountNewAuthorityPubkey extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: SetFundingAuthorityInput< + TAccountStakePool, + TAccountManager, + TAccountNewAuthorityPubkey + >, + config?: { programAddress?: TProgramAddress }, +): SetFundingAuthorityInstruction< + TProgramAddress, + TAccountStakePool, + TAccountManager, + TAccountNewAuthorityPubkey +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: true }, + manager: { value: input.manager ?? null, isWritable: false }, + newAuthorityPubkey: { + value: input.newAuthorityPubkey ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.manager), + getAccountMeta(accounts.newAuthorityPubkey), + ], + data: getSetFundingAuthorityInstructionDataEncoder().encode( + args as SetFundingAuthorityInstructionDataArgs, + ), + programAddress, + } as SetFundingAuthorityInstruction< + TProgramAddress, + TAccountStakePool, + TAccountManager, + TAccountNewAuthorityPubkey + >); +} + +export interface ParsedSetFundingAuthorityInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + /** Stake pool */ + stakePool: TAccountMetas[0]; + /** Manager */ + manager: TAccountMetas[1]; + /** New authority pubkey */ + newAuthorityPubkey: TAccountMetas[2]; + }; + data: SetFundingAuthorityInstructionData; +} + +export function parseSetFundingAuthorityInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedSetFundingAuthorityInstruction { + if (instruction.accounts.length < 3) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + stakePool: getNextAccount(), + manager: getNextAccount(), + newAuthorityPubkey: getNextAccount(), + }, + data: getSetFundingAuthorityInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/spl-stake-pool/src/generated/instructions/setManager.ts b/clients/spl-stake-pool/src/generated/instructions/setManager.ts new file mode 100644 index 00000000..4eb1ee3b --- /dev/null +++ b/clients/spl-stake-pool/src/generated/instructions/setManager.ts @@ -0,0 +1,220 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, +} from "@solana/kit"; +import { SPL_STAKE_POOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const SET_MANAGER_DISCRIMINATOR = 11; + +export function getSetManagerDiscriminatorBytes(): ReadonlyUint8Array { + return getU8Encoder().encode(SET_MANAGER_DISCRIMINATOR); +} + +export type SetManagerInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountStakePool extends string | AccountMeta = string, + TAccountManager extends string | AccountMeta = string, + TAccountNewManager extends string | AccountMeta = string, + TAccountNewManagerFeeAccount extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountStakePool extends string + ? WritableAccount + : TAccountStakePool, + TAccountManager extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountManager, + TAccountNewManager extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountNewManager, + TAccountNewManagerFeeAccount extends string + ? ReadonlyAccount + : TAccountNewManagerFeeAccount, + ...TRemainingAccounts, + ] + >; + +export interface SetManagerInstructionData { + discriminator: number; +} + +export interface SetManagerInstructionDataArgs {} + +export function getSetManagerInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", getU8Encoder()]]), + (value) => ({ ...value, discriminator: SET_MANAGER_DISCRIMINATOR }), + ); +} + +export function getSetManagerInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([["discriminator", getU8Decoder()]]); +} + +export function getSetManagerInstructionDataCodec(): FixedSizeCodec< + SetManagerInstructionDataArgs, + SetManagerInstructionData +> { + return combineCodec( + getSetManagerInstructionDataEncoder(), + getSetManagerInstructionDataDecoder(), + ); +} + +export interface SetManagerInput< + TAccountStakePool extends string = string, + TAccountManager extends string = string, + TAccountNewManager extends string = string, + TAccountNewManagerFeeAccount extends string = string, +> { + /** Stake pool */ + stakePool: Address; + /** Manager */ + manager: TransactionSigner; + /** New manager */ + newManager: TransactionSigner; + /** New manager fee account */ + newManagerFeeAccount: Address; +} + +export function getSetManagerInstruction< + TAccountStakePool extends string, + TAccountManager extends string, + TAccountNewManager extends string, + TAccountNewManagerFeeAccount extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: SetManagerInput< + TAccountStakePool, + TAccountManager, + TAccountNewManager, + TAccountNewManagerFeeAccount + >, + config?: { programAddress?: TProgramAddress }, +): SetManagerInstruction< + TProgramAddress, + TAccountStakePool, + TAccountManager, + TAccountNewManager, + TAccountNewManagerFeeAccount +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: true }, + manager: { value: input.manager ?? null, isWritable: false }, + newManager: { value: input.newManager ?? null, isWritable: false }, + newManagerFeeAccount: { + value: input.newManagerFeeAccount ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.manager), + getAccountMeta(accounts.newManager), + getAccountMeta(accounts.newManagerFeeAccount), + ], + data: getSetManagerInstructionDataEncoder().encode({}), + programAddress, + } as SetManagerInstruction< + TProgramAddress, + TAccountStakePool, + TAccountManager, + TAccountNewManager, + TAccountNewManagerFeeAccount + >); +} + +export interface ParsedSetManagerInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + /** Stake pool */ + stakePool: TAccountMetas[0]; + /** Manager */ + manager: TAccountMetas[1]; + /** New manager */ + newManager: TAccountMetas[2]; + /** New manager fee account */ + newManagerFeeAccount: TAccountMetas[3]; + }; + data: SetManagerInstructionData; +} + +export function parseSetManagerInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedSetManagerInstruction { + if (instruction.accounts.length < 4) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + stakePool: getNextAccount(), + manager: getNextAccount(), + newManager: getNextAccount(), + newManagerFeeAccount: getNextAccount(), + }, + data: getSetManagerInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/spl-stake-pool/src/generated/instructions/setPreferredValidator.ts b/clients/spl-stake-pool/src/generated/instructions/setPreferredValidator.ts new file mode 100644 index 00000000..d9914e6e --- /dev/null +++ b/clients/spl-stake-pool/src/generated/instructions/setPreferredValidator.ts @@ -0,0 +1,233 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + Codec, + Decoder, + Encoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + Option, + OptionOrNullable, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import type { + PreferredValidatorType, + PreferredValidatorTypeArgs, +} from "../types/index.js"; +import { + combineCodec, + getAddressDecoder, + getAddressEncoder, + getOptionDecoder, + getOptionEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, +} from "@solana/kit"; +import { SPL_STAKE_POOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; +import { + getPreferredValidatorTypeDecoder, + getPreferredValidatorTypeEncoder, +} from "../types/index.js"; + +export const SET_PREFERRED_VALIDATOR_DISCRIMINATOR = 5; + +export function getSetPreferredValidatorDiscriminatorBytes(): ReadonlyUint8Array { + return getU8Encoder().encode(SET_PREFERRED_VALIDATOR_DISCRIMINATOR); +} + +export type SetPreferredValidatorInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountStakePool extends string | AccountMeta = string, + TAccountStaker extends string | AccountMeta = string, + TAccountValidatorList extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountStakePool extends string + ? WritableAccount + : TAccountStakePool, + TAccountStaker extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountStaker, + TAccountValidatorList extends string + ? ReadonlyAccount + : TAccountValidatorList, + ...TRemainingAccounts, + ] + >; + +export interface SetPreferredValidatorInstructionData { + discriminator: number; + validatorType: PreferredValidatorType; + validatorVoteAddress: Option
; +} + +export interface SetPreferredValidatorInstructionDataArgs { + validatorType: PreferredValidatorTypeArgs; + validatorVoteAddress: OptionOrNullable
; +} + +export function getSetPreferredValidatorInstructionDataEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", getU8Encoder()], + ["validatorType", getPreferredValidatorTypeEncoder()], + ["validatorVoteAddress", getOptionEncoder(getAddressEncoder())], + ]), + (value) => ({ + ...value, + discriminator: SET_PREFERRED_VALIDATOR_DISCRIMINATOR, + }), + ); +} + +export function getSetPreferredValidatorInstructionDataDecoder(): Decoder { + return getStructDecoder([ + ["discriminator", getU8Decoder()], + ["validatorType", getPreferredValidatorTypeDecoder()], + ["validatorVoteAddress", getOptionDecoder(getAddressDecoder())], + ]); +} + +export function getSetPreferredValidatorInstructionDataCodec(): Codec< + SetPreferredValidatorInstructionDataArgs, + SetPreferredValidatorInstructionData +> { + return combineCodec( + getSetPreferredValidatorInstructionDataEncoder(), + getSetPreferredValidatorInstructionDataDecoder(), + ); +} + +export interface SetPreferredValidatorInput< + TAccountStakePool extends string = string, + TAccountStaker extends string = string, + TAccountValidatorList extends string = string, +> { + stakePool: Address; + staker: TransactionSigner; + validatorList: Address; + validatorType: SetPreferredValidatorInstructionDataArgs["validatorType"]; + validatorVoteAddress: SetPreferredValidatorInstructionDataArgs["validatorVoteAddress"]; +} + +export function getSetPreferredValidatorInstruction< + TAccountStakePool extends string, + TAccountStaker extends string, + TAccountValidatorList extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: SetPreferredValidatorInput< + TAccountStakePool, + TAccountStaker, + TAccountValidatorList + >, + config?: { programAddress?: TProgramAddress }, +): SetPreferredValidatorInstruction< + TProgramAddress, + TAccountStakePool, + TAccountStaker, + TAccountValidatorList +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: true }, + staker: { value: input.staker ?? null, isWritable: false }, + validatorList: { value: input.validatorList ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.staker), + getAccountMeta(accounts.validatorList), + ], + data: getSetPreferredValidatorInstructionDataEncoder().encode( + args as SetPreferredValidatorInstructionDataArgs, + ), + programAddress, + } as SetPreferredValidatorInstruction< + TProgramAddress, + TAccountStakePool, + TAccountStaker, + TAccountValidatorList + >); +} + +export interface ParsedSetPreferredValidatorInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + stakePool: TAccountMetas[0]; + staker: TAccountMetas[1]; + validatorList: TAccountMetas[2]; + }; + data: SetPreferredValidatorInstructionData; +} + +export function parseSetPreferredValidatorInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedSetPreferredValidatorInstruction { + if (instruction.accounts.length < 3) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + stakePool: getNextAccount(), + staker: getNextAccount(), + validatorList: getNextAccount(), + }, + data: getSetPreferredValidatorInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/spl-stake-pool/src/generated/instructions/setStaker.ts b/clients/spl-stake-pool/src/generated/instructions/setStaker.ts new file mode 100644 index 00000000..8fb1d2fb --- /dev/null +++ b/clients/spl-stake-pool/src/generated/instructions/setStaker.ts @@ -0,0 +1,203 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, +} from "@solana/kit"; +import { SPL_STAKE_POOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const SET_STAKER_DISCRIMINATOR = 13; + +export function getSetStakerDiscriminatorBytes(): ReadonlyUint8Array { + return getU8Encoder().encode(SET_STAKER_DISCRIMINATOR); +} + +export type SetStakerInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountStakePool extends string | AccountMeta = string, + TAccountAuthority extends string | AccountMeta = string, + TAccountNewStakerPubkey extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountStakePool extends string + ? WritableAccount + : TAccountStakePool, + TAccountAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountAuthority, + TAccountNewStakerPubkey extends string + ? ReadonlyAccount + : TAccountNewStakerPubkey, + ...TRemainingAccounts, + ] + >; + +export interface SetStakerInstructionData { + discriminator: number; +} + +export interface SetStakerInstructionDataArgs {} + +export function getSetStakerInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", getU8Encoder()]]), + (value) => ({ ...value, discriminator: SET_STAKER_DISCRIMINATOR }), + ); +} + +export function getSetStakerInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([["discriminator", getU8Decoder()]]); +} + +export function getSetStakerInstructionDataCodec(): FixedSizeCodec< + SetStakerInstructionDataArgs, + SetStakerInstructionData +> { + return combineCodec( + getSetStakerInstructionDataEncoder(), + getSetStakerInstructionDataDecoder(), + ); +} + +export interface SetStakerInput< + TAccountStakePool extends string = string, + TAccountAuthority extends string = string, + TAccountNewStakerPubkey extends string = string, +> { + /** Stake pool */ + stakePool: Address; + /** Manager or current staker */ + authority: TransactionSigner; + /** New staker pubkey */ + newStakerPubkey: Address; +} + +export function getSetStakerInstruction< + TAccountStakePool extends string, + TAccountAuthority extends string, + TAccountNewStakerPubkey extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: SetStakerInput< + TAccountStakePool, + TAccountAuthority, + TAccountNewStakerPubkey + >, + config?: { programAddress?: TProgramAddress }, +): SetStakerInstruction< + TProgramAddress, + TAccountStakePool, + TAccountAuthority, + TAccountNewStakerPubkey +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: true }, + authority: { value: input.authority ?? null, isWritable: false }, + newStakerPubkey: { + value: input.newStakerPubkey ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.authority), + getAccountMeta(accounts.newStakerPubkey), + ], + data: getSetStakerInstructionDataEncoder().encode({}), + programAddress, + } as SetStakerInstruction< + TProgramAddress, + TAccountStakePool, + TAccountAuthority, + TAccountNewStakerPubkey + >); +} + +export interface ParsedSetStakerInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + /** Stake pool */ + stakePool: TAccountMetas[0]; + /** Manager or current staker */ + authority: TAccountMetas[1]; + /** New staker pubkey */ + newStakerPubkey: TAccountMetas[2]; + }; + data: SetStakerInstructionData; +} + +export function parseSetStakerInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedSetStakerInstruction { + if (instruction.accounts.length < 3) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + stakePool: getNextAccount(), + authority: getNextAccount(), + newStakerPubkey: getNextAccount(), + }, + data: getSetStakerInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/spl-stake-pool/src/generated/instructions/updateStakePoolBalance.ts b/clients/spl-stake-pool/src/generated/instructions/updateStakePoolBalance.ts new file mode 100644 index 00000000..e34eb7da --- /dev/null +++ b/clients/spl-stake-pool/src/generated/instructions/updateStakePoolBalance.ts @@ -0,0 +1,371 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlyUint8Array, + WritableAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, +} from "@solana/kit"; +import { findWithdrawAuthorityPda } from "../pdas/index.js"; +import { SPL_STAKE_POOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; + +export const UPDATE_STAKE_POOL_BALANCE_DISCRIMINATOR = 7; + +export function getUpdateStakePoolBalanceDiscriminatorBytes(): ReadonlyUint8Array { + return getU8Encoder().encode(UPDATE_STAKE_POOL_BALANCE_DISCRIMINATOR); +} + +export type UpdateStakePoolBalanceInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountStakePool extends string | AccountMeta = string, + TAccountWithdrawAuthority extends string | AccountMeta = string, + TAccountValidatorList extends string | AccountMeta = string, + TAccountReserveStake extends string | AccountMeta = string, + TAccountFeeAccount extends string | AccountMeta = string, + TAccountPoolMint extends string | AccountMeta = string, + TAccountTokenProgram extends + | string + | AccountMeta = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountStakePool extends string + ? WritableAccount + : TAccountStakePool, + TAccountWithdrawAuthority extends string + ? ReadonlyAccount + : TAccountWithdrawAuthority, + TAccountValidatorList extends string + ? WritableAccount + : TAccountValidatorList, + TAccountReserveStake extends string + ? ReadonlyAccount + : TAccountReserveStake, + TAccountFeeAccount extends string + ? WritableAccount + : TAccountFeeAccount, + TAccountPoolMint extends string + ? WritableAccount + : TAccountPoolMint, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + ...TRemainingAccounts, + ] + >; + +export interface UpdateStakePoolBalanceInstructionData { + discriminator: number; +} + +export interface UpdateStakePoolBalanceInstructionDataArgs {} + +export function getUpdateStakePoolBalanceInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", getU8Encoder()]]), + (value) => ({ + ...value, + discriminator: UPDATE_STAKE_POOL_BALANCE_DISCRIMINATOR, + }), + ); +} + +export function getUpdateStakePoolBalanceInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([["discriminator", getU8Decoder()]]); +} + +export function getUpdateStakePoolBalanceInstructionDataCodec(): FixedSizeCodec< + UpdateStakePoolBalanceInstructionDataArgs, + UpdateStakePoolBalanceInstructionData +> { + return combineCodec( + getUpdateStakePoolBalanceInstructionDataEncoder(), + getUpdateStakePoolBalanceInstructionDataDecoder(), + ); +} + +export interface UpdateStakePoolBalanceAsyncInput< + TAccountStakePool extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountValidatorList extends string = string, + TAccountReserveStake extends string = string, + TAccountFeeAccount extends string = string, + TAccountPoolMint extends string = string, + TAccountTokenProgram extends string = string, +> { + stakePool: Address; + withdrawAuthority?: Address; + validatorList: Address; + reserveStake: Address; + feeAccount: Address; + poolMint: Address; + tokenProgram?: Address; +} + +export async function getUpdateStakePoolBalanceInstructionAsync< + TAccountStakePool extends string, + TAccountWithdrawAuthority extends string, + TAccountValidatorList extends string, + TAccountReserveStake extends string, + TAccountFeeAccount extends string, + TAccountPoolMint extends string, + TAccountTokenProgram extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: UpdateStakePoolBalanceAsyncInput< + TAccountStakePool, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountFeeAccount, + TAccountPoolMint, + TAccountTokenProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + UpdateStakePoolBalanceInstruction< + TProgramAddress, + TAccountStakePool, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountFeeAccount, + TAccountPoolMint, + TAccountTokenProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: true }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + validatorList: { value: input.validatorList ?? null, isWritable: true }, + reserveStake: { value: input.reserveStake ?? null, isWritable: false }, + feeAccount: { value: input.feeAccount ?? null, isWritable: true }, + poolMint: { value: input.poolMint ?? null, isWritable: true }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Resolve default values. + if (!accounts.withdrawAuthority.value) { + accounts.withdrawAuthority.value = await findWithdrawAuthorityPda({ + stakePoolAddress: expectAddress(accounts.stakePool.value), + }); + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.validatorList), + getAccountMeta(accounts.reserveStake), + getAccountMeta(accounts.feeAccount), + getAccountMeta(accounts.poolMint), + getAccountMeta(accounts.tokenProgram), + ], + data: getUpdateStakePoolBalanceInstructionDataEncoder().encode({}), + programAddress, + } as UpdateStakePoolBalanceInstruction< + TProgramAddress, + TAccountStakePool, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountFeeAccount, + TAccountPoolMint, + TAccountTokenProgram + >); +} + +export interface UpdateStakePoolBalanceInput< + TAccountStakePool extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountValidatorList extends string = string, + TAccountReserveStake extends string = string, + TAccountFeeAccount extends string = string, + TAccountPoolMint extends string = string, + TAccountTokenProgram extends string = string, +> { + stakePool: Address; + withdrawAuthority: Address; + validatorList: Address; + reserveStake: Address; + feeAccount: Address; + poolMint: Address; + tokenProgram?: Address; +} + +export function getUpdateStakePoolBalanceInstruction< + TAccountStakePool extends string, + TAccountWithdrawAuthority extends string, + TAccountValidatorList extends string, + TAccountReserveStake extends string, + TAccountFeeAccount extends string, + TAccountPoolMint extends string, + TAccountTokenProgram extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: UpdateStakePoolBalanceInput< + TAccountStakePool, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountFeeAccount, + TAccountPoolMint, + TAccountTokenProgram + >, + config?: { programAddress?: TProgramAddress }, +): UpdateStakePoolBalanceInstruction< + TProgramAddress, + TAccountStakePool, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountFeeAccount, + TAccountPoolMint, + TAccountTokenProgram +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: true }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + validatorList: { value: input.validatorList ?? null, isWritable: true }, + reserveStake: { value: input.reserveStake ?? null, isWritable: false }, + feeAccount: { value: input.feeAccount ?? null, isWritable: true }, + poolMint: { value: input.poolMint ?? null, isWritable: true }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Resolve default values. + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.validatorList), + getAccountMeta(accounts.reserveStake), + getAccountMeta(accounts.feeAccount), + getAccountMeta(accounts.poolMint), + getAccountMeta(accounts.tokenProgram), + ], + data: getUpdateStakePoolBalanceInstructionDataEncoder().encode({}), + programAddress, + } as UpdateStakePoolBalanceInstruction< + TProgramAddress, + TAccountStakePool, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountFeeAccount, + TAccountPoolMint, + TAccountTokenProgram + >); +} + +export interface ParsedUpdateStakePoolBalanceInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + stakePool: TAccountMetas[0]; + withdrawAuthority: TAccountMetas[1]; + validatorList: TAccountMetas[2]; + reserveStake: TAccountMetas[3]; + feeAccount: TAccountMetas[4]; + poolMint: TAccountMetas[5]; + tokenProgram: TAccountMetas[6]; + }; + data: UpdateStakePoolBalanceInstructionData; +} + +export function parseUpdateStakePoolBalanceInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedUpdateStakePoolBalanceInstruction { + if (instruction.accounts.length < 7) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + stakePool: getNextAccount(), + withdrawAuthority: getNextAccount(), + validatorList: getNextAccount(), + reserveStake: getNextAccount(), + feeAccount: getNextAccount(), + poolMint: getNextAccount(), + tokenProgram: getNextAccount(), + }, + data: getUpdateStakePoolBalanceInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/spl-stake-pool/src/generated/instructions/updateTokenMetadata.ts b/clients/spl-stake-pool/src/generated/instructions/updateTokenMetadata.ts new file mode 100644 index 00000000..a1b8e7b7 --- /dev/null +++ b/clients/spl-stake-pool/src/generated/instructions/updateTokenMetadata.ts @@ -0,0 +1,364 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + Codec, + Decoder, + Encoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import { + addDecoderSizePrefix, + addEncoderSizePrefix, + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getU32Decoder, + getU32Encoder, + getUtf8Decoder, + getUtf8Encoder, + transformEncoder, +} from "@solana/kit"; +import { findWithdrawAuthorityPda } from "../pdas/index.js"; +import { SPL_STAKE_POOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; + +export const UPDATE_TOKEN_METADATA_DISCRIMINATOR = 18; + +export function getUpdateTokenMetadataDiscriminatorBytes(): ReadonlyUint8Array { + return getU8Encoder().encode(UPDATE_TOKEN_METADATA_DISCRIMINATOR); +} + +export type UpdateTokenMetadataInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountStakePool extends string | AccountMeta = string, + TAccountManager extends string | AccountMeta = string, + TAccountWithdrawAuthority extends string | AccountMeta = string, + TAccountMetadataAccount extends string | AccountMeta = string, + TAccountMetadataProgram extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountStakePool extends string + ? ReadonlyAccount + : TAccountStakePool, + TAccountManager extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountManager, + TAccountWithdrawAuthority extends string + ? ReadonlyAccount + : TAccountWithdrawAuthority, + TAccountMetadataAccount extends string + ? WritableAccount + : TAccountMetadataAccount, + TAccountMetadataProgram extends string + ? ReadonlyAccount + : TAccountMetadataProgram, + ...TRemainingAccounts, + ] + >; + +export interface UpdateTokenMetadataInstructionData { + discriminator: number; + name: string; + symbol: string; + uri: string; +} + +export interface UpdateTokenMetadataInstructionDataArgs { + name: string; + symbol: string; + uri: string; +} + +export function getUpdateTokenMetadataInstructionDataEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", getU8Encoder()], + ["name", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())], + ["symbol", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())], + ["uri", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())], + ]), + (value) => ({ + ...value, + discriminator: UPDATE_TOKEN_METADATA_DISCRIMINATOR, + }), + ); +} + +export function getUpdateTokenMetadataInstructionDataDecoder(): Decoder { + return getStructDecoder([ + ["discriminator", getU8Decoder()], + ["name", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())], + ["symbol", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())], + ["uri", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())], + ]); +} + +export function getUpdateTokenMetadataInstructionDataCodec(): Codec< + UpdateTokenMetadataInstructionDataArgs, + UpdateTokenMetadataInstructionData +> { + return combineCodec( + getUpdateTokenMetadataInstructionDataEncoder(), + getUpdateTokenMetadataInstructionDataDecoder(), + ); +} + +export interface UpdateTokenMetadataAsyncInput< + TAccountStakePool extends string = string, + TAccountManager extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountMetadataAccount extends string = string, + TAccountMetadataProgram extends string = string, +> { + stakePool: Address; + manager: TransactionSigner; + withdrawAuthority?: Address; + metadataAccount: Address; + metadataProgram: Address; + name: UpdateTokenMetadataInstructionDataArgs["name"]; + symbol: UpdateTokenMetadataInstructionDataArgs["symbol"]; + uri: UpdateTokenMetadataInstructionDataArgs["uri"]; +} + +export async function getUpdateTokenMetadataInstructionAsync< + TAccountStakePool extends string, + TAccountManager extends string, + TAccountWithdrawAuthority extends string, + TAccountMetadataAccount extends string, + TAccountMetadataProgram extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: UpdateTokenMetadataAsyncInput< + TAccountStakePool, + TAccountManager, + TAccountWithdrawAuthority, + TAccountMetadataAccount, + TAccountMetadataProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + UpdateTokenMetadataInstruction< + TProgramAddress, + TAccountStakePool, + TAccountManager, + TAccountWithdrawAuthority, + TAccountMetadataAccount, + TAccountMetadataProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: false }, + manager: { value: input.manager ?? null, isWritable: false }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + metadataAccount: { value: input.metadataAccount ?? null, isWritable: true }, + metadataProgram: { + value: input.metadataProgram ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.withdrawAuthority.value) { + accounts.withdrawAuthority.value = await findWithdrawAuthorityPda({ + stakePoolAddress: expectAddress(accounts.stakePool.value), + }); + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.manager), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.metadataAccount), + getAccountMeta(accounts.metadataProgram), + ], + data: getUpdateTokenMetadataInstructionDataEncoder().encode( + args as UpdateTokenMetadataInstructionDataArgs, + ), + programAddress, + } as UpdateTokenMetadataInstruction< + TProgramAddress, + TAccountStakePool, + TAccountManager, + TAccountWithdrawAuthority, + TAccountMetadataAccount, + TAccountMetadataProgram + >); +} + +export interface UpdateTokenMetadataInput< + TAccountStakePool extends string = string, + TAccountManager extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountMetadataAccount extends string = string, + TAccountMetadataProgram extends string = string, +> { + stakePool: Address; + manager: TransactionSigner; + withdrawAuthority: Address; + metadataAccount: Address; + metadataProgram: Address; + name: UpdateTokenMetadataInstructionDataArgs["name"]; + symbol: UpdateTokenMetadataInstructionDataArgs["symbol"]; + uri: UpdateTokenMetadataInstructionDataArgs["uri"]; +} + +export function getUpdateTokenMetadataInstruction< + TAccountStakePool extends string, + TAccountManager extends string, + TAccountWithdrawAuthority extends string, + TAccountMetadataAccount extends string, + TAccountMetadataProgram extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: UpdateTokenMetadataInput< + TAccountStakePool, + TAccountManager, + TAccountWithdrawAuthority, + TAccountMetadataAccount, + TAccountMetadataProgram + >, + config?: { programAddress?: TProgramAddress }, +): UpdateTokenMetadataInstruction< + TProgramAddress, + TAccountStakePool, + TAccountManager, + TAccountWithdrawAuthority, + TAccountMetadataAccount, + TAccountMetadataProgram +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: false }, + manager: { value: input.manager ?? null, isWritable: false }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + metadataAccount: { value: input.metadataAccount ?? null, isWritable: true }, + metadataProgram: { + value: input.metadataProgram ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.manager), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.metadataAccount), + getAccountMeta(accounts.metadataProgram), + ], + data: getUpdateTokenMetadataInstructionDataEncoder().encode( + args as UpdateTokenMetadataInstructionDataArgs, + ), + programAddress, + } as UpdateTokenMetadataInstruction< + TProgramAddress, + TAccountStakePool, + TAccountManager, + TAccountWithdrawAuthority, + TAccountMetadataAccount, + TAccountMetadataProgram + >); +} + +export interface ParsedUpdateTokenMetadataInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + stakePool: TAccountMetas[0]; + manager: TAccountMetas[1]; + withdrawAuthority: TAccountMetas[2]; + metadataAccount: TAccountMetas[3]; + metadataProgram: TAccountMetas[4]; + }; + data: UpdateTokenMetadataInstructionData; +} + +export function parseUpdateTokenMetadataInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedUpdateTokenMetadataInstruction { + if (instruction.accounts.length < 5) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + stakePool: getNextAccount(), + manager: getNextAccount(), + withdrawAuthority: getNextAccount(), + metadataAccount: getNextAccount(), + metadataProgram: getNextAccount(), + }, + data: getUpdateTokenMetadataInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/spl-stake-pool/src/generated/instructions/updateValidatorListBalance.ts b/clients/spl-stake-pool/src/generated/instructions/updateValidatorListBalance.ts new file mode 100644 index 00000000..801aacf8 --- /dev/null +++ b/clients/spl-stake-pool/src/generated/instructions/updateValidatorListBalance.ts @@ -0,0 +1,428 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlyUint8Array, + WritableAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import { + combineCodec, + getBooleanDecoder, + getBooleanEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getU32Decoder, + getU32Encoder, + transformEncoder, +} from "@solana/kit"; +import { findWithdrawAuthorityPda } from "../pdas/index.js"; +import { SPL_STAKE_POOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; + +export const UPDATE_VALIDATOR_LIST_BALANCE_DISCRIMINATOR = 6; + +export function getUpdateValidatorListBalanceDiscriminatorBytes(): ReadonlyUint8Array { + return getU8Encoder().encode(UPDATE_VALIDATOR_LIST_BALANCE_DISCRIMINATOR); +} + +export type UpdateValidatorListBalanceInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountStakePool extends string | AccountMeta = string, + TAccountWithdrawAuthority extends string | AccountMeta = string, + TAccountValidatorList extends string | AccountMeta = string, + TAccountReserveStake extends string | AccountMeta = string, + TAccountClockSysvar extends + | string + | AccountMeta = "SysvarC1ock11111111111111111111111111111111", + TAccountStakeHistorySysvar extends + | string + | AccountMeta = "SysvarStakeHistory1111111111111111111111111", + TAccountStakeProgram extends + | string + | AccountMeta = "Stake11111111111111111111111111111111111111", + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountStakePool extends string + ? ReadonlyAccount + : TAccountStakePool, + TAccountWithdrawAuthority extends string + ? ReadonlyAccount + : TAccountWithdrawAuthority, + TAccountValidatorList extends string + ? WritableAccount + : TAccountValidatorList, + TAccountReserveStake extends string + ? WritableAccount + : TAccountReserveStake, + TAccountClockSysvar extends string + ? ReadonlyAccount + : TAccountClockSysvar, + TAccountStakeHistorySysvar extends string + ? ReadonlyAccount + : TAccountStakeHistorySysvar, + TAccountStakeProgram extends string + ? ReadonlyAccount + : TAccountStakeProgram, + ...TRemainingAccounts, + ] + >; + +export interface UpdateValidatorListBalanceInstructionData { + discriminator: number; + startIndex: number; + noMerge: boolean; +} + +export interface UpdateValidatorListBalanceInstructionDataArgs { + startIndex: number; + noMerge: boolean; +} + +export function getUpdateValidatorListBalanceInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", getU8Encoder()], + ["startIndex", getU32Encoder()], + ["noMerge", getBooleanEncoder()], + ]), + (value) => ({ + ...value, + discriminator: UPDATE_VALIDATOR_LIST_BALANCE_DISCRIMINATOR, + }), + ); +} + +export function getUpdateValidatorListBalanceInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", getU8Decoder()], + ["startIndex", getU32Decoder()], + ["noMerge", getBooleanDecoder()], + ]); +} + +export function getUpdateValidatorListBalanceInstructionDataCodec(): FixedSizeCodec< + UpdateValidatorListBalanceInstructionDataArgs, + UpdateValidatorListBalanceInstructionData +> { + return combineCodec( + getUpdateValidatorListBalanceInstructionDataEncoder(), + getUpdateValidatorListBalanceInstructionDataDecoder(), + ); +} + +export interface UpdateValidatorListBalanceAsyncInput< + TAccountStakePool extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountValidatorList extends string = string, + TAccountReserveStake extends string = string, + TAccountClockSysvar extends string = string, + TAccountStakeHistorySysvar extends string = string, + TAccountStakeProgram extends string = string, +> { + stakePool: Address; + withdrawAuthority?: Address; + validatorList: Address; + reserveStake: Address; + clockSysvar?: Address; + stakeHistorySysvar?: Address; + stakeProgram?: Address; + startIndex: UpdateValidatorListBalanceInstructionDataArgs["startIndex"]; + noMerge: UpdateValidatorListBalanceInstructionDataArgs["noMerge"]; +} + +export async function getUpdateValidatorListBalanceInstructionAsync< + TAccountStakePool extends string, + TAccountWithdrawAuthority extends string, + TAccountValidatorList extends string, + TAccountReserveStake extends string, + TAccountClockSysvar extends string, + TAccountStakeHistorySysvar extends string, + TAccountStakeProgram extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: UpdateValidatorListBalanceAsyncInput< + TAccountStakePool, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountStakeProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + UpdateValidatorListBalanceInstruction< + TProgramAddress, + TAccountStakePool, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountStakeProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: false }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + validatorList: { value: input.validatorList ?? null, isWritable: true }, + reserveStake: { value: input.reserveStake ?? null, isWritable: true }, + clockSysvar: { value: input.clockSysvar ?? null, isWritable: false }, + stakeHistorySysvar: { + value: input.stakeHistorySysvar ?? null, + isWritable: false, + }, + stakeProgram: { value: input.stakeProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.withdrawAuthority.value) { + accounts.withdrawAuthority.value = await findWithdrawAuthorityPda({ + stakePoolAddress: expectAddress(accounts.stakePool.value), + }); + } + if (!accounts.clockSysvar.value) { + accounts.clockSysvar.value = + "SysvarC1ock11111111111111111111111111111111" as Address<"SysvarC1ock11111111111111111111111111111111">; + } + if (!accounts.stakeHistorySysvar.value) { + accounts.stakeHistorySysvar.value = + "SysvarStakeHistory1111111111111111111111111" as Address<"SysvarStakeHistory1111111111111111111111111">; + } + if (!accounts.stakeProgram.value) { + accounts.stakeProgram.value = + "Stake11111111111111111111111111111111111111" as Address<"Stake11111111111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.validatorList), + getAccountMeta(accounts.reserveStake), + getAccountMeta(accounts.clockSysvar), + getAccountMeta(accounts.stakeHistorySysvar), + getAccountMeta(accounts.stakeProgram), + ], + data: getUpdateValidatorListBalanceInstructionDataEncoder().encode( + args as UpdateValidatorListBalanceInstructionDataArgs, + ), + programAddress, + } as UpdateValidatorListBalanceInstruction< + TProgramAddress, + TAccountStakePool, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountStakeProgram + >); +} + +export interface UpdateValidatorListBalanceInput< + TAccountStakePool extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountValidatorList extends string = string, + TAccountReserveStake extends string = string, + TAccountClockSysvar extends string = string, + TAccountStakeHistorySysvar extends string = string, + TAccountStakeProgram extends string = string, +> { + stakePool: Address; + withdrawAuthority: Address; + validatorList: Address; + reserveStake: Address; + clockSysvar?: Address; + stakeHistorySysvar?: Address; + stakeProgram?: Address; + startIndex: UpdateValidatorListBalanceInstructionDataArgs["startIndex"]; + noMerge: UpdateValidatorListBalanceInstructionDataArgs["noMerge"]; +} + +export function getUpdateValidatorListBalanceInstruction< + TAccountStakePool extends string, + TAccountWithdrawAuthority extends string, + TAccountValidatorList extends string, + TAccountReserveStake extends string, + TAccountClockSysvar extends string, + TAccountStakeHistorySysvar extends string, + TAccountStakeProgram extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: UpdateValidatorListBalanceInput< + TAccountStakePool, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountStakeProgram + >, + config?: { programAddress?: TProgramAddress }, +): UpdateValidatorListBalanceInstruction< + TProgramAddress, + TAccountStakePool, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountStakeProgram +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: false }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + validatorList: { value: input.validatorList ?? null, isWritable: true }, + reserveStake: { value: input.reserveStake ?? null, isWritable: true }, + clockSysvar: { value: input.clockSysvar ?? null, isWritable: false }, + stakeHistorySysvar: { + value: input.stakeHistorySysvar ?? null, + isWritable: false, + }, + stakeProgram: { value: input.stakeProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.clockSysvar.value) { + accounts.clockSysvar.value = + "SysvarC1ock11111111111111111111111111111111" as Address<"SysvarC1ock11111111111111111111111111111111">; + } + if (!accounts.stakeHistorySysvar.value) { + accounts.stakeHistorySysvar.value = + "SysvarStakeHistory1111111111111111111111111" as Address<"SysvarStakeHistory1111111111111111111111111">; + } + if (!accounts.stakeProgram.value) { + accounts.stakeProgram.value = + "Stake11111111111111111111111111111111111111" as Address<"Stake11111111111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.validatorList), + getAccountMeta(accounts.reserveStake), + getAccountMeta(accounts.clockSysvar), + getAccountMeta(accounts.stakeHistorySysvar), + getAccountMeta(accounts.stakeProgram), + ], + data: getUpdateValidatorListBalanceInstructionDataEncoder().encode( + args as UpdateValidatorListBalanceInstructionDataArgs, + ), + programAddress, + } as UpdateValidatorListBalanceInstruction< + TProgramAddress, + TAccountStakePool, + TAccountWithdrawAuthority, + TAccountValidatorList, + TAccountReserveStake, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountStakeProgram + >); +} + +export interface ParsedUpdateValidatorListBalanceInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + stakePool: TAccountMetas[0]; + withdrawAuthority: TAccountMetas[1]; + validatorList: TAccountMetas[2]; + reserveStake: TAccountMetas[3]; + clockSysvar: TAccountMetas[4]; + stakeHistorySysvar: TAccountMetas[5]; + stakeProgram: TAccountMetas[6]; + }; + data: UpdateValidatorListBalanceInstructionData; +} + +export function parseUpdateValidatorListBalanceInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedUpdateValidatorListBalanceInstruction { + if (instruction.accounts.length < 7) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + stakePool: getNextAccount(), + withdrawAuthority: getNextAccount(), + validatorList: getNextAccount(), + reserveStake: getNextAccount(), + clockSysvar: getNextAccount(), + stakeHistorySysvar: getNextAccount(), + stakeProgram: getNextAccount(), + }, + data: getUpdateValidatorListBalanceInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/spl-stake-pool/src/generated/instructions/withdrawSol.ts b/clients/spl-stake-pool/src/generated/instructions/withdrawSol.ts new file mode 100644 index 00000000..af57d99c --- /dev/null +++ b/clients/spl-stake-pool/src/generated/instructions/withdrawSol.ts @@ -0,0 +1,631 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getU64Decoder, + getU64Encoder, + transformEncoder, +} from "@solana/kit"; +import { findWithdrawAuthorityPda } from "../pdas/index.js"; +import { SPL_STAKE_POOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; + +export const WITHDRAW_SOL_DISCRIMINATOR = 16; + +export function getWithdrawSolDiscriminatorBytes(): ReadonlyUint8Array { + return getU8Encoder().encode(WITHDRAW_SOL_DISCRIMINATOR); +} + +export type WithdrawSolInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountStakePool extends string | AccountMeta = string, + TAccountWithdrawAuthority extends string | AccountMeta = string, + TAccountUserTransferAuthority extends string | AccountMeta = string, + TAccountUserPoolTokenAccount extends string | AccountMeta = string, + TAccountReserveStake extends string | AccountMeta = string, + TAccountDestinationSystemAccount extends string | AccountMeta = string, + TAccountFeeAccount extends string | AccountMeta = string, + TAccountPoolMint extends string | AccountMeta = string, + TAccountClockSysvar extends + | string + | AccountMeta = "SysvarC1ock11111111111111111111111111111111", + TAccountStakeHistorySysvar extends + | string + | AccountMeta = "SysvarStakeHistory1111111111111111111111111", + TAccountStakeProgram extends + | string + | AccountMeta = "Stake11111111111111111111111111111111111111", + TAccountTokenProgram extends + | string + | AccountMeta = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + TAccountSolWithdrawAuthority extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountStakePool extends string + ? WritableAccount + : TAccountStakePool, + TAccountWithdrawAuthority extends string + ? ReadonlyAccount + : TAccountWithdrawAuthority, + TAccountUserTransferAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountUserTransferAuthority, + TAccountUserPoolTokenAccount extends string + ? WritableAccount + : TAccountUserPoolTokenAccount, + TAccountReserveStake extends string + ? WritableAccount + : TAccountReserveStake, + TAccountDestinationSystemAccount extends string + ? WritableAccount + : TAccountDestinationSystemAccount, + TAccountFeeAccount extends string + ? WritableAccount + : TAccountFeeAccount, + TAccountPoolMint extends string + ? WritableAccount + : TAccountPoolMint, + TAccountClockSysvar extends string + ? ReadonlyAccount + : TAccountClockSysvar, + TAccountStakeHistorySysvar extends string + ? ReadonlyAccount + : TAccountStakeHistorySysvar, + TAccountStakeProgram extends string + ? ReadonlyAccount + : TAccountStakeProgram, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + TAccountSolWithdrawAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountSolWithdrawAuthority, + ...TRemainingAccounts, + ] + >; + +export interface WithdrawSolInstructionData { + discriminator: number; + args: bigint; +} + +export interface WithdrawSolInstructionDataArgs { + args: number | bigint; +} + +export function getWithdrawSolInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", getU8Encoder()], + ["args", getU64Encoder()], + ]), + (value) => ({ ...value, discriminator: WITHDRAW_SOL_DISCRIMINATOR }), + ); +} + +export function getWithdrawSolInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", getU8Decoder()], + ["args", getU64Decoder()], + ]); +} + +export function getWithdrawSolInstructionDataCodec(): FixedSizeCodec< + WithdrawSolInstructionDataArgs, + WithdrawSolInstructionData +> { + return combineCodec( + getWithdrawSolInstructionDataEncoder(), + getWithdrawSolInstructionDataDecoder(), + ); +} + +export interface WithdrawSolAsyncInput< + TAccountStakePool extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountUserTransferAuthority extends string = string, + TAccountUserPoolTokenAccount extends string = string, + TAccountReserveStake extends string = string, + TAccountDestinationSystemAccount extends string = string, + TAccountFeeAccount extends string = string, + TAccountPoolMint extends string = string, + TAccountClockSysvar extends string = string, + TAccountStakeHistorySysvar extends string = string, + TAccountStakeProgram extends string = string, + TAccountTokenProgram extends string = string, + TAccountSolWithdrawAuthority extends string = string, +> { + /** Stake pool */ + stakePool: Address; + /** Withdraw authority */ + withdrawAuthority?: Address; + /** User transfer authority */ + userTransferAuthority: TransactionSigner; + /** User pool token account */ + userPoolTokenAccount: Address; + /** Reserve stake */ + reserveStake: Address; + /** Destination system account */ + destinationSystemAccount: Address; + /** Fee account */ + feeAccount: Address; + /** Pool mint */ + poolMint: Address; + /** Clock sysvar */ + clockSysvar?: Address; + /** Stake history sysvar */ + stakeHistorySysvar?: Address; + /** Stake program */ + stakeProgram?: Address; + /** Token program */ + tokenProgram?: Address; + /** Sol withdraw authority */ + solWithdrawAuthority?: TransactionSigner; + args: WithdrawSolInstructionDataArgs["args"]; +} + +export async function getWithdrawSolInstructionAsync< + TAccountStakePool extends string, + TAccountWithdrawAuthority extends string, + TAccountUserTransferAuthority extends string, + TAccountUserPoolTokenAccount extends string, + TAccountReserveStake extends string, + TAccountDestinationSystemAccount extends string, + TAccountFeeAccount extends string, + TAccountPoolMint extends string, + TAccountClockSysvar extends string, + TAccountStakeHistorySysvar extends string, + TAccountStakeProgram extends string, + TAccountTokenProgram extends string, + TAccountSolWithdrawAuthority extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: WithdrawSolAsyncInput< + TAccountStakePool, + TAccountWithdrawAuthority, + TAccountUserTransferAuthority, + TAccountUserPoolTokenAccount, + TAccountReserveStake, + TAccountDestinationSystemAccount, + TAccountFeeAccount, + TAccountPoolMint, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountStakeProgram, + TAccountTokenProgram, + TAccountSolWithdrawAuthority + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + WithdrawSolInstruction< + TProgramAddress, + TAccountStakePool, + TAccountWithdrawAuthority, + TAccountUserTransferAuthority, + TAccountUserPoolTokenAccount, + TAccountReserveStake, + TAccountDestinationSystemAccount, + TAccountFeeAccount, + TAccountPoolMint, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountStakeProgram, + TAccountTokenProgram, + TAccountSolWithdrawAuthority + > +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: true }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + userTransferAuthority: { + value: input.userTransferAuthority ?? null, + isWritable: false, + }, + userPoolTokenAccount: { + value: input.userPoolTokenAccount ?? null, + isWritable: true, + }, + reserveStake: { value: input.reserveStake ?? null, isWritable: true }, + destinationSystemAccount: { + value: input.destinationSystemAccount ?? null, + isWritable: true, + }, + feeAccount: { value: input.feeAccount ?? null, isWritable: true }, + poolMint: { value: input.poolMint ?? null, isWritable: true }, + clockSysvar: { value: input.clockSysvar ?? null, isWritable: false }, + stakeHistorySysvar: { + value: input.stakeHistorySysvar ?? null, + isWritable: false, + }, + stakeProgram: { value: input.stakeProgram ?? null, isWritable: false }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + solWithdrawAuthority: { + value: input.solWithdrawAuthority ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.withdrawAuthority.value) { + accounts.withdrawAuthority.value = await findWithdrawAuthorityPda({ + stakePoolAddress: expectAddress(accounts.stakePool.value), + }); + } + if (!accounts.clockSysvar.value) { + accounts.clockSysvar.value = + "SysvarC1ock11111111111111111111111111111111" as Address<"SysvarC1ock11111111111111111111111111111111">; + } + if (!accounts.stakeHistorySysvar.value) { + accounts.stakeHistorySysvar.value = + "SysvarStakeHistory1111111111111111111111111" as Address<"SysvarStakeHistory1111111111111111111111111">; + } + if (!accounts.stakeProgram.value) { + accounts.stakeProgram.value = + "Stake11111111111111111111111111111111111111" as Address<"Stake11111111111111111111111111111111111111">; + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.userTransferAuthority), + getAccountMeta(accounts.userPoolTokenAccount), + getAccountMeta(accounts.reserveStake), + getAccountMeta(accounts.destinationSystemAccount), + getAccountMeta(accounts.feeAccount), + getAccountMeta(accounts.poolMint), + getAccountMeta(accounts.clockSysvar), + getAccountMeta(accounts.stakeHistorySysvar), + getAccountMeta(accounts.stakeProgram), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.solWithdrawAuthority), + ], + data: getWithdrawSolInstructionDataEncoder().encode( + args as WithdrawSolInstructionDataArgs, + ), + programAddress, + } as WithdrawSolInstruction< + TProgramAddress, + TAccountStakePool, + TAccountWithdrawAuthority, + TAccountUserTransferAuthority, + TAccountUserPoolTokenAccount, + TAccountReserveStake, + TAccountDestinationSystemAccount, + TAccountFeeAccount, + TAccountPoolMint, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountStakeProgram, + TAccountTokenProgram, + TAccountSolWithdrawAuthority + >); +} + +export interface WithdrawSolInput< + TAccountStakePool extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountUserTransferAuthority extends string = string, + TAccountUserPoolTokenAccount extends string = string, + TAccountReserveStake extends string = string, + TAccountDestinationSystemAccount extends string = string, + TAccountFeeAccount extends string = string, + TAccountPoolMint extends string = string, + TAccountClockSysvar extends string = string, + TAccountStakeHistorySysvar extends string = string, + TAccountStakeProgram extends string = string, + TAccountTokenProgram extends string = string, + TAccountSolWithdrawAuthority extends string = string, +> { + /** Stake pool */ + stakePool: Address; + /** Withdraw authority */ + withdrawAuthority: Address; + /** User transfer authority */ + userTransferAuthority: TransactionSigner; + /** User pool token account */ + userPoolTokenAccount: Address; + /** Reserve stake */ + reserveStake: Address; + /** Destination system account */ + destinationSystemAccount: Address; + /** Fee account */ + feeAccount: Address; + /** Pool mint */ + poolMint: Address; + /** Clock sysvar */ + clockSysvar?: Address; + /** Stake history sysvar */ + stakeHistorySysvar?: Address; + /** Stake program */ + stakeProgram?: Address; + /** Token program */ + tokenProgram?: Address; + /** Sol withdraw authority */ + solWithdrawAuthority?: TransactionSigner; + args: WithdrawSolInstructionDataArgs["args"]; +} + +export function getWithdrawSolInstruction< + TAccountStakePool extends string, + TAccountWithdrawAuthority extends string, + TAccountUserTransferAuthority extends string, + TAccountUserPoolTokenAccount extends string, + TAccountReserveStake extends string, + TAccountDestinationSystemAccount extends string, + TAccountFeeAccount extends string, + TAccountPoolMint extends string, + TAccountClockSysvar extends string, + TAccountStakeHistorySysvar extends string, + TAccountStakeProgram extends string, + TAccountTokenProgram extends string, + TAccountSolWithdrawAuthority extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: WithdrawSolInput< + TAccountStakePool, + TAccountWithdrawAuthority, + TAccountUserTransferAuthority, + TAccountUserPoolTokenAccount, + TAccountReserveStake, + TAccountDestinationSystemAccount, + TAccountFeeAccount, + TAccountPoolMint, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountStakeProgram, + TAccountTokenProgram, + TAccountSolWithdrawAuthority + >, + config?: { programAddress?: TProgramAddress }, +): WithdrawSolInstruction< + TProgramAddress, + TAccountStakePool, + TAccountWithdrawAuthority, + TAccountUserTransferAuthority, + TAccountUserPoolTokenAccount, + TAccountReserveStake, + TAccountDestinationSystemAccount, + TAccountFeeAccount, + TAccountPoolMint, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountStakeProgram, + TAccountTokenProgram, + TAccountSolWithdrawAuthority +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: true }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + userTransferAuthority: { + value: input.userTransferAuthority ?? null, + isWritable: false, + }, + userPoolTokenAccount: { + value: input.userPoolTokenAccount ?? null, + isWritable: true, + }, + reserveStake: { value: input.reserveStake ?? null, isWritable: true }, + destinationSystemAccount: { + value: input.destinationSystemAccount ?? null, + isWritable: true, + }, + feeAccount: { value: input.feeAccount ?? null, isWritable: true }, + poolMint: { value: input.poolMint ?? null, isWritable: true }, + clockSysvar: { value: input.clockSysvar ?? null, isWritable: false }, + stakeHistorySysvar: { + value: input.stakeHistorySysvar ?? null, + isWritable: false, + }, + stakeProgram: { value: input.stakeProgram ?? null, isWritable: false }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + solWithdrawAuthority: { + value: input.solWithdrawAuthority ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.clockSysvar.value) { + accounts.clockSysvar.value = + "SysvarC1ock11111111111111111111111111111111" as Address<"SysvarC1ock11111111111111111111111111111111">; + } + if (!accounts.stakeHistorySysvar.value) { + accounts.stakeHistorySysvar.value = + "SysvarStakeHistory1111111111111111111111111" as Address<"SysvarStakeHistory1111111111111111111111111">; + } + if (!accounts.stakeProgram.value) { + accounts.stakeProgram.value = + "Stake11111111111111111111111111111111111111" as Address<"Stake11111111111111111111111111111111111111">; + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.userTransferAuthority), + getAccountMeta(accounts.userPoolTokenAccount), + getAccountMeta(accounts.reserveStake), + getAccountMeta(accounts.destinationSystemAccount), + getAccountMeta(accounts.feeAccount), + getAccountMeta(accounts.poolMint), + getAccountMeta(accounts.clockSysvar), + getAccountMeta(accounts.stakeHistorySysvar), + getAccountMeta(accounts.stakeProgram), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.solWithdrawAuthority), + ], + data: getWithdrawSolInstructionDataEncoder().encode( + args as WithdrawSolInstructionDataArgs, + ), + programAddress, + } as WithdrawSolInstruction< + TProgramAddress, + TAccountStakePool, + TAccountWithdrawAuthority, + TAccountUserTransferAuthority, + TAccountUserPoolTokenAccount, + TAccountReserveStake, + TAccountDestinationSystemAccount, + TAccountFeeAccount, + TAccountPoolMint, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountStakeProgram, + TAccountTokenProgram, + TAccountSolWithdrawAuthority + >); +} + +export interface ParsedWithdrawSolInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + /** Stake pool */ + stakePool: TAccountMetas[0]; + /** Withdraw authority */ + withdrawAuthority: TAccountMetas[1]; + /** User transfer authority */ + userTransferAuthority: TAccountMetas[2]; + /** User pool token account */ + userPoolTokenAccount: TAccountMetas[3]; + /** Reserve stake */ + reserveStake: TAccountMetas[4]; + /** Destination system account */ + destinationSystemAccount: TAccountMetas[5]; + /** Fee account */ + feeAccount: TAccountMetas[6]; + /** Pool mint */ + poolMint: TAccountMetas[7]; + /** Clock sysvar */ + clockSysvar: TAccountMetas[8]; + /** Stake history sysvar */ + stakeHistorySysvar: TAccountMetas[9]; + /** Stake program */ + stakeProgram: TAccountMetas[10]; + /** Token program */ + tokenProgram: TAccountMetas[11]; + /** Sol withdraw authority */ + solWithdrawAuthority?: TAccountMetas[12] | undefined; + }; + data: WithdrawSolInstructionData; +} + +export function parseWithdrawSolInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedWithdrawSolInstruction { + if (instruction.accounts.length < 13) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + const getNextOptionalAccount = () => { + const accountMeta = getNextAccount(); + return accountMeta.address === SPL_STAKE_POOL_PROGRAM_ADDRESS + ? undefined + : accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + stakePool: getNextAccount(), + withdrawAuthority: getNextAccount(), + userTransferAuthority: getNextAccount(), + userPoolTokenAccount: getNextAccount(), + reserveStake: getNextAccount(), + destinationSystemAccount: getNextAccount(), + feeAccount: getNextAccount(), + poolMint: getNextAccount(), + clockSysvar: getNextAccount(), + stakeHistorySysvar: getNextAccount(), + stakeProgram: getNextAccount(), + tokenProgram: getNextAccount(), + solWithdrawAuthority: getNextOptionalAccount(), + }, + data: getWithdrawSolInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/spl-stake-pool/src/generated/instructions/withdrawSolWithSlippage.ts b/clients/spl-stake-pool/src/generated/instructions/withdrawSolWithSlippage.ts new file mode 100644 index 00000000..1bb7da9e --- /dev/null +++ b/clients/spl-stake-pool/src/generated/instructions/withdrawSolWithSlippage.ts @@ -0,0 +1,651 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getU64Decoder, + getU64Encoder, + transformEncoder, +} from "@solana/kit"; +import { findWithdrawAuthorityPda } from "../pdas/index.js"; +import { SPL_STAKE_POOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; + +export const WITHDRAW_SOL_WITH_SLIPPAGE_DISCRIMINATOR = 26; + +export function getWithdrawSolWithSlippageDiscriminatorBytes(): ReadonlyUint8Array { + return getU8Encoder().encode(WITHDRAW_SOL_WITH_SLIPPAGE_DISCRIMINATOR); +} + +export type WithdrawSolWithSlippageInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountStakePool extends string | AccountMeta = string, + TAccountWithdrawAuthority extends string | AccountMeta = string, + TAccountUserTransferAuthority extends string | AccountMeta = string, + TAccountUserPoolTokenAccount extends string | AccountMeta = string, + TAccountReserveStake extends string | AccountMeta = string, + TAccountDestinationSystemAccount extends string | AccountMeta = string, + TAccountFeeAccount extends string | AccountMeta = string, + TAccountPoolMint extends string | AccountMeta = string, + TAccountClockSysvar extends + | string + | AccountMeta = "SysvarC1ock11111111111111111111111111111111", + TAccountStakeHistorySysvar extends + | string + | AccountMeta = "SysvarStakeHistory1111111111111111111111111", + TAccountStakeProgram extends + | string + | AccountMeta = "Stake11111111111111111111111111111111111111", + TAccountTokenProgram extends + | string + | AccountMeta = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + TAccountSolWithdrawAuthority extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountStakePool extends string + ? WritableAccount + : TAccountStakePool, + TAccountWithdrawAuthority extends string + ? ReadonlyAccount + : TAccountWithdrawAuthority, + TAccountUserTransferAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountUserTransferAuthority, + TAccountUserPoolTokenAccount extends string + ? WritableAccount + : TAccountUserPoolTokenAccount, + TAccountReserveStake extends string + ? WritableAccount + : TAccountReserveStake, + TAccountDestinationSystemAccount extends string + ? WritableAccount + : TAccountDestinationSystemAccount, + TAccountFeeAccount extends string + ? WritableAccount + : TAccountFeeAccount, + TAccountPoolMint extends string + ? WritableAccount + : TAccountPoolMint, + TAccountClockSysvar extends string + ? ReadonlyAccount + : TAccountClockSysvar, + TAccountStakeHistorySysvar extends string + ? ReadonlyAccount + : TAccountStakeHistorySysvar, + TAccountStakeProgram extends string + ? ReadonlyAccount + : TAccountStakeProgram, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + TAccountSolWithdrawAuthority extends string + ? ReadonlyAccount + : TAccountSolWithdrawAuthority, + ...TRemainingAccounts, + ] + >; + +export interface WithdrawSolWithSlippageInstructionData { + discriminator: number; + poolTokensIn: bigint; + minimumLamportsOut: bigint; +} + +export interface WithdrawSolWithSlippageInstructionDataArgs { + poolTokensIn: number | bigint; + minimumLamportsOut: number | bigint; +} + +export function getWithdrawSolWithSlippageInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", getU8Encoder()], + ["poolTokensIn", getU64Encoder()], + ["minimumLamportsOut", getU64Encoder()], + ]), + (value) => ({ + ...value, + discriminator: WITHDRAW_SOL_WITH_SLIPPAGE_DISCRIMINATOR, + }), + ); +} + +export function getWithdrawSolWithSlippageInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", getU8Decoder()], + ["poolTokensIn", getU64Decoder()], + ["minimumLamportsOut", getU64Decoder()], + ]); +} + +export function getWithdrawSolWithSlippageInstructionDataCodec(): FixedSizeCodec< + WithdrawSolWithSlippageInstructionDataArgs, + WithdrawSolWithSlippageInstructionData +> { + return combineCodec( + getWithdrawSolWithSlippageInstructionDataEncoder(), + getWithdrawSolWithSlippageInstructionDataDecoder(), + ); +} + +export interface WithdrawSolWithSlippageAsyncInput< + TAccountStakePool extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountUserTransferAuthority extends string = string, + TAccountUserPoolTokenAccount extends string = string, + TAccountReserveStake extends string = string, + TAccountDestinationSystemAccount extends string = string, + TAccountFeeAccount extends string = string, + TAccountPoolMint extends string = string, + TAccountClockSysvar extends string = string, + TAccountStakeHistorySysvar extends string = string, + TAccountStakeProgram extends string = string, + TAccountTokenProgram extends string = string, + TAccountSolWithdrawAuthority extends string = string, +> { + /** Stake pool */ + stakePool: Address; + /** Stake pool withdraw authority */ + withdrawAuthority?: Address; + /** User transfer authority */ + userTransferAuthority: TransactionSigner; + /** User pool token account */ + userPoolTokenAccount: Address; + /** Reserve stake */ + reserveStake: Address; + /** Destination system account */ + destinationSystemAccount: Address; + /** Fee account */ + feeAccount: Address; + /** Pool mint */ + poolMint: Address; + /** Clock sysvar */ + clockSysvar?: Address; + /** Stake history sysvar */ + stakeHistorySysvar?: Address; + /** Stake program */ + stakeProgram?: Address; + /** Token program */ + tokenProgram?: Address; + /** Stake pool sol withdraw authority */ + solWithdrawAuthority: + | Address + | TransactionSigner; + poolTokensIn: WithdrawSolWithSlippageInstructionDataArgs["poolTokensIn"]; + minimumLamportsOut: WithdrawSolWithSlippageInstructionDataArgs["minimumLamportsOut"]; +} + +export async function getWithdrawSolWithSlippageInstructionAsync< + TAccountStakePool extends string, + TAccountWithdrawAuthority extends string, + TAccountUserTransferAuthority extends string, + TAccountUserPoolTokenAccount extends string, + TAccountReserveStake extends string, + TAccountDestinationSystemAccount extends string, + TAccountFeeAccount extends string, + TAccountPoolMint extends string, + TAccountClockSysvar extends string, + TAccountStakeHistorySysvar extends string, + TAccountStakeProgram extends string, + TAccountTokenProgram extends string, + TAccountSolWithdrawAuthority extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: WithdrawSolWithSlippageAsyncInput< + TAccountStakePool, + TAccountWithdrawAuthority, + TAccountUserTransferAuthority, + TAccountUserPoolTokenAccount, + TAccountReserveStake, + TAccountDestinationSystemAccount, + TAccountFeeAccount, + TAccountPoolMint, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountStakeProgram, + TAccountTokenProgram, + TAccountSolWithdrawAuthority + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + WithdrawSolWithSlippageInstruction< + TProgramAddress, + TAccountStakePool, + TAccountWithdrawAuthority, + TAccountUserTransferAuthority, + TAccountUserPoolTokenAccount, + TAccountReserveStake, + TAccountDestinationSystemAccount, + TAccountFeeAccount, + TAccountPoolMint, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountStakeProgram, + TAccountTokenProgram, + (typeof input)["solWithdrawAuthority"] extends TransactionSigner + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountSolWithdrawAuthority + > +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: true }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + userTransferAuthority: { + value: input.userTransferAuthority ?? null, + isWritable: false, + }, + userPoolTokenAccount: { + value: input.userPoolTokenAccount ?? null, + isWritable: true, + }, + reserveStake: { value: input.reserveStake ?? null, isWritable: true }, + destinationSystemAccount: { + value: input.destinationSystemAccount ?? null, + isWritable: true, + }, + feeAccount: { value: input.feeAccount ?? null, isWritable: true }, + poolMint: { value: input.poolMint ?? null, isWritable: true }, + clockSysvar: { value: input.clockSysvar ?? null, isWritable: false }, + stakeHistorySysvar: { + value: input.stakeHistorySysvar ?? null, + isWritable: false, + }, + stakeProgram: { value: input.stakeProgram ?? null, isWritable: false }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + solWithdrawAuthority: { + value: input.solWithdrawAuthority ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.withdrawAuthority.value) { + accounts.withdrawAuthority.value = await findWithdrawAuthorityPda({ + stakePoolAddress: expectAddress(accounts.stakePool.value), + }); + } + if (!accounts.clockSysvar.value) { + accounts.clockSysvar.value = + "SysvarC1ock11111111111111111111111111111111" as Address<"SysvarC1ock11111111111111111111111111111111">; + } + if (!accounts.stakeHistorySysvar.value) { + accounts.stakeHistorySysvar.value = + "SysvarStakeHistory1111111111111111111111111" as Address<"SysvarStakeHistory1111111111111111111111111">; + } + if (!accounts.stakeProgram.value) { + accounts.stakeProgram.value = + "Stake11111111111111111111111111111111111111" as Address<"Stake11111111111111111111111111111111111111">; + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.userTransferAuthority), + getAccountMeta(accounts.userPoolTokenAccount), + getAccountMeta(accounts.reserveStake), + getAccountMeta(accounts.destinationSystemAccount), + getAccountMeta(accounts.feeAccount), + getAccountMeta(accounts.poolMint), + getAccountMeta(accounts.clockSysvar), + getAccountMeta(accounts.stakeHistorySysvar), + getAccountMeta(accounts.stakeProgram), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.solWithdrawAuthority), + ], + data: getWithdrawSolWithSlippageInstructionDataEncoder().encode( + args as WithdrawSolWithSlippageInstructionDataArgs, + ), + programAddress, + } as WithdrawSolWithSlippageInstruction< + TProgramAddress, + TAccountStakePool, + TAccountWithdrawAuthority, + TAccountUserTransferAuthority, + TAccountUserPoolTokenAccount, + TAccountReserveStake, + TAccountDestinationSystemAccount, + TAccountFeeAccount, + TAccountPoolMint, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountStakeProgram, + TAccountTokenProgram, + (typeof input)["solWithdrawAuthority"] extends TransactionSigner + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountSolWithdrawAuthority + >); +} + +export interface WithdrawSolWithSlippageInput< + TAccountStakePool extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountUserTransferAuthority extends string = string, + TAccountUserPoolTokenAccount extends string = string, + TAccountReserveStake extends string = string, + TAccountDestinationSystemAccount extends string = string, + TAccountFeeAccount extends string = string, + TAccountPoolMint extends string = string, + TAccountClockSysvar extends string = string, + TAccountStakeHistorySysvar extends string = string, + TAccountStakeProgram extends string = string, + TAccountTokenProgram extends string = string, + TAccountSolWithdrawAuthority extends string = string, +> { + /** Stake pool */ + stakePool: Address; + /** Stake pool withdraw authority */ + withdrawAuthority: Address; + /** User transfer authority */ + userTransferAuthority: TransactionSigner; + /** User pool token account */ + userPoolTokenAccount: Address; + /** Reserve stake */ + reserveStake: Address; + /** Destination system account */ + destinationSystemAccount: Address; + /** Fee account */ + feeAccount: Address; + /** Pool mint */ + poolMint: Address; + /** Clock sysvar */ + clockSysvar?: Address; + /** Stake history sysvar */ + stakeHistorySysvar?: Address; + /** Stake program */ + stakeProgram?: Address; + /** Token program */ + tokenProgram?: Address; + /** Stake pool sol withdraw authority */ + solWithdrawAuthority: + | Address + | TransactionSigner; + poolTokensIn: WithdrawSolWithSlippageInstructionDataArgs["poolTokensIn"]; + minimumLamportsOut: WithdrawSolWithSlippageInstructionDataArgs["minimumLamportsOut"]; +} + +export function getWithdrawSolWithSlippageInstruction< + TAccountStakePool extends string, + TAccountWithdrawAuthority extends string, + TAccountUserTransferAuthority extends string, + TAccountUserPoolTokenAccount extends string, + TAccountReserveStake extends string, + TAccountDestinationSystemAccount extends string, + TAccountFeeAccount extends string, + TAccountPoolMint extends string, + TAccountClockSysvar extends string, + TAccountStakeHistorySysvar extends string, + TAccountStakeProgram extends string, + TAccountTokenProgram extends string, + TAccountSolWithdrawAuthority extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: WithdrawSolWithSlippageInput< + TAccountStakePool, + TAccountWithdrawAuthority, + TAccountUserTransferAuthority, + TAccountUserPoolTokenAccount, + TAccountReserveStake, + TAccountDestinationSystemAccount, + TAccountFeeAccount, + TAccountPoolMint, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountStakeProgram, + TAccountTokenProgram, + TAccountSolWithdrawAuthority + >, + config?: { programAddress?: TProgramAddress }, +): WithdrawSolWithSlippageInstruction< + TProgramAddress, + TAccountStakePool, + TAccountWithdrawAuthority, + TAccountUserTransferAuthority, + TAccountUserPoolTokenAccount, + TAccountReserveStake, + TAccountDestinationSystemAccount, + TAccountFeeAccount, + TAccountPoolMint, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountStakeProgram, + TAccountTokenProgram, + (typeof input)["solWithdrawAuthority"] extends TransactionSigner + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountSolWithdrawAuthority +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: true }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + userTransferAuthority: { + value: input.userTransferAuthority ?? null, + isWritable: false, + }, + userPoolTokenAccount: { + value: input.userPoolTokenAccount ?? null, + isWritable: true, + }, + reserveStake: { value: input.reserveStake ?? null, isWritable: true }, + destinationSystemAccount: { + value: input.destinationSystemAccount ?? null, + isWritable: true, + }, + feeAccount: { value: input.feeAccount ?? null, isWritable: true }, + poolMint: { value: input.poolMint ?? null, isWritable: true }, + clockSysvar: { value: input.clockSysvar ?? null, isWritable: false }, + stakeHistorySysvar: { + value: input.stakeHistorySysvar ?? null, + isWritable: false, + }, + stakeProgram: { value: input.stakeProgram ?? null, isWritable: false }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + solWithdrawAuthority: { + value: input.solWithdrawAuthority ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.clockSysvar.value) { + accounts.clockSysvar.value = + "SysvarC1ock11111111111111111111111111111111" as Address<"SysvarC1ock11111111111111111111111111111111">; + } + if (!accounts.stakeHistorySysvar.value) { + accounts.stakeHistorySysvar.value = + "SysvarStakeHistory1111111111111111111111111" as Address<"SysvarStakeHistory1111111111111111111111111">; + } + if (!accounts.stakeProgram.value) { + accounts.stakeProgram.value = + "Stake11111111111111111111111111111111111111" as Address<"Stake11111111111111111111111111111111111111">; + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.userTransferAuthority), + getAccountMeta(accounts.userPoolTokenAccount), + getAccountMeta(accounts.reserveStake), + getAccountMeta(accounts.destinationSystemAccount), + getAccountMeta(accounts.feeAccount), + getAccountMeta(accounts.poolMint), + getAccountMeta(accounts.clockSysvar), + getAccountMeta(accounts.stakeHistorySysvar), + getAccountMeta(accounts.stakeProgram), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.solWithdrawAuthority), + ], + data: getWithdrawSolWithSlippageInstructionDataEncoder().encode( + args as WithdrawSolWithSlippageInstructionDataArgs, + ), + programAddress, + } as WithdrawSolWithSlippageInstruction< + TProgramAddress, + TAccountStakePool, + TAccountWithdrawAuthority, + TAccountUserTransferAuthority, + TAccountUserPoolTokenAccount, + TAccountReserveStake, + TAccountDestinationSystemAccount, + TAccountFeeAccount, + TAccountPoolMint, + TAccountClockSysvar, + TAccountStakeHistorySysvar, + TAccountStakeProgram, + TAccountTokenProgram, + (typeof input)["solWithdrawAuthority"] extends TransactionSigner + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountSolWithdrawAuthority + >); +} + +export interface ParsedWithdrawSolWithSlippageInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + /** Stake pool */ + stakePool: TAccountMetas[0]; + /** Stake pool withdraw authority */ + withdrawAuthority: TAccountMetas[1]; + /** User transfer authority */ + userTransferAuthority: TAccountMetas[2]; + /** User pool token account */ + userPoolTokenAccount: TAccountMetas[3]; + /** Reserve stake */ + reserveStake: TAccountMetas[4]; + /** Destination system account */ + destinationSystemAccount: TAccountMetas[5]; + /** Fee account */ + feeAccount: TAccountMetas[6]; + /** Pool mint */ + poolMint: TAccountMetas[7]; + /** Clock sysvar */ + clockSysvar: TAccountMetas[8]; + /** Stake history sysvar */ + stakeHistorySysvar: TAccountMetas[9]; + /** Stake program */ + stakeProgram: TAccountMetas[10]; + /** Token program */ + tokenProgram: TAccountMetas[11]; + /** Stake pool sol withdraw authority */ + solWithdrawAuthority: TAccountMetas[12]; + }; + data: WithdrawSolWithSlippageInstructionData; +} + +export function parseWithdrawSolWithSlippageInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedWithdrawSolWithSlippageInstruction { + if (instruction.accounts.length < 13) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + stakePool: getNextAccount(), + withdrawAuthority: getNextAccount(), + userTransferAuthority: getNextAccount(), + userPoolTokenAccount: getNextAccount(), + reserveStake: getNextAccount(), + destinationSystemAccount: getNextAccount(), + feeAccount: getNextAccount(), + poolMint: getNextAccount(), + clockSysvar: getNextAccount(), + stakeHistorySysvar: getNextAccount(), + stakeProgram: getNextAccount(), + tokenProgram: getNextAccount(), + solWithdrawAuthority: getNextAccount(), + }, + data: getWithdrawSolWithSlippageInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/spl-stake-pool/src/generated/instructions/withdrawStake.ts b/clients/spl-stake-pool/src/generated/instructions/withdrawStake.ts new file mode 100644 index 00000000..75259a58 --- /dev/null +++ b/clients/spl-stake-pool/src/generated/instructions/withdrawStake.ts @@ -0,0 +1,614 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getU64Decoder, + getU64Encoder, + transformEncoder, +} from "@solana/kit"; +import { findWithdrawAuthorityPda } from "../pdas/index.js"; +import { SPL_STAKE_POOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; + +export const WITHDRAW_STAKE_DISCRIMINATOR = 10; + +export function getWithdrawStakeDiscriminatorBytes(): ReadonlyUint8Array { + return getU8Encoder().encode(WITHDRAW_STAKE_DISCRIMINATOR); +} + +export type WithdrawStakeInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountStakePool extends string | AccountMeta = string, + TAccountValidatorList extends string | AccountMeta = string, + TAccountWithdrawAuthority extends string | AccountMeta = string, + TAccountSourceStakeAccount extends string | AccountMeta = string, + TAccountDestinationStakeAccount extends string | AccountMeta = string, + TAccountNewWithdrawAuthority extends string | AccountMeta = string, + TAccountUserTransferAuthority extends string | AccountMeta = string, + TAccountUserPoolTokenAccount extends string | AccountMeta = string, + TAccountFeeAccount extends string | AccountMeta = string, + TAccountPoolMint extends string | AccountMeta = string, + TAccountClockSysvar extends + | string + | AccountMeta = "SysvarC1ock11111111111111111111111111111111", + TAccountTokenProgram extends + | string + | AccountMeta = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + TAccountStakeProgram extends + | string + | AccountMeta = "Stake11111111111111111111111111111111111111", + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountStakePool extends string + ? WritableAccount + : TAccountStakePool, + TAccountValidatorList extends string + ? WritableAccount + : TAccountValidatorList, + TAccountWithdrawAuthority extends string + ? ReadonlyAccount + : TAccountWithdrawAuthority, + TAccountSourceStakeAccount extends string + ? WritableAccount + : TAccountSourceStakeAccount, + TAccountDestinationStakeAccount extends string + ? WritableAccount + : TAccountDestinationStakeAccount, + TAccountNewWithdrawAuthority extends string + ? ReadonlyAccount + : TAccountNewWithdrawAuthority, + TAccountUserTransferAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountUserTransferAuthority, + TAccountUserPoolTokenAccount extends string + ? WritableAccount + : TAccountUserPoolTokenAccount, + TAccountFeeAccount extends string + ? WritableAccount + : TAccountFeeAccount, + TAccountPoolMint extends string + ? WritableAccount + : TAccountPoolMint, + TAccountClockSysvar extends string + ? ReadonlyAccount + : TAccountClockSysvar, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + TAccountStakeProgram extends string + ? ReadonlyAccount + : TAccountStakeProgram, + ...TRemainingAccounts, + ] + >; + +export interface WithdrawStakeInstructionData { + discriminator: number; + args: bigint; +} + +export interface WithdrawStakeInstructionDataArgs { + args: number | bigint; +} + +export function getWithdrawStakeInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", getU8Encoder()], + ["args", getU64Encoder()], + ]), + (value) => ({ ...value, discriminator: WITHDRAW_STAKE_DISCRIMINATOR }), + ); +} + +export function getWithdrawStakeInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", getU8Decoder()], + ["args", getU64Decoder()], + ]); +} + +export function getWithdrawStakeInstructionDataCodec(): FixedSizeCodec< + WithdrawStakeInstructionDataArgs, + WithdrawStakeInstructionData +> { + return combineCodec( + getWithdrawStakeInstructionDataEncoder(), + getWithdrawStakeInstructionDataDecoder(), + ); +} + +export interface WithdrawStakeAsyncInput< + TAccountStakePool extends string = string, + TAccountValidatorList extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountSourceStakeAccount extends string = string, + TAccountDestinationStakeAccount extends string = string, + TAccountNewWithdrawAuthority extends string = string, + TAccountUserTransferAuthority extends string = string, + TAccountUserPoolTokenAccount extends string = string, + TAccountFeeAccount extends string = string, + TAccountPoolMint extends string = string, + TAccountClockSysvar extends string = string, + TAccountTokenProgram extends string = string, + TAccountStakeProgram extends string = string, +> { + /** Stake pool */ + stakePool: Address; + /** Validator list */ + validatorList: Address; + /** Withdraw authority */ + withdrawAuthority?: Address; + /** Source stake account */ + sourceStakeAccount: Address; + /** Destination stake account */ + destinationStakeAccount: Address; + /** New withdraw authority */ + newWithdrawAuthority: Address; + /** User transfer authority */ + userTransferAuthority: TransactionSigner; + /** User pool token account */ + userPoolTokenAccount: Address; + /** Fee account */ + feeAccount: Address; + /** Pool mint */ + poolMint: Address; + /** Clock sysvar */ + clockSysvar?: Address; + /** Token program */ + tokenProgram?: Address; + /** Stake program */ + stakeProgram?: Address; + args: WithdrawStakeInstructionDataArgs["args"]; +} + +export async function getWithdrawStakeInstructionAsync< + TAccountStakePool extends string, + TAccountValidatorList extends string, + TAccountWithdrawAuthority extends string, + TAccountSourceStakeAccount extends string, + TAccountDestinationStakeAccount extends string, + TAccountNewWithdrawAuthority extends string, + TAccountUserTransferAuthority extends string, + TAccountUserPoolTokenAccount extends string, + TAccountFeeAccount extends string, + TAccountPoolMint extends string, + TAccountClockSysvar extends string, + TAccountTokenProgram extends string, + TAccountStakeProgram extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: WithdrawStakeAsyncInput< + TAccountStakePool, + TAccountValidatorList, + TAccountWithdrawAuthority, + TAccountSourceStakeAccount, + TAccountDestinationStakeAccount, + TAccountNewWithdrawAuthority, + TAccountUserTransferAuthority, + TAccountUserPoolTokenAccount, + TAccountFeeAccount, + TAccountPoolMint, + TAccountClockSysvar, + TAccountTokenProgram, + TAccountStakeProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + WithdrawStakeInstruction< + TProgramAddress, + TAccountStakePool, + TAccountValidatorList, + TAccountWithdrawAuthority, + TAccountSourceStakeAccount, + TAccountDestinationStakeAccount, + TAccountNewWithdrawAuthority, + TAccountUserTransferAuthority, + TAccountUserPoolTokenAccount, + TAccountFeeAccount, + TAccountPoolMint, + TAccountClockSysvar, + TAccountTokenProgram, + TAccountStakeProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: true }, + validatorList: { value: input.validatorList ?? null, isWritable: true }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + sourceStakeAccount: { + value: input.sourceStakeAccount ?? null, + isWritable: true, + }, + destinationStakeAccount: { + value: input.destinationStakeAccount ?? null, + isWritable: true, + }, + newWithdrawAuthority: { + value: input.newWithdrawAuthority ?? null, + isWritable: false, + }, + userTransferAuthority: { + value: input.userTransferAuthority ?? null, + isWritable: false, + }, + userPoolTokenAccount: { + value: input.userPoolTokenAccount ?? null, + isWritable: true, + }, + feeAccount: { value: input.feeAccount ?? null, isWritable: true }, + poolMint: { value: input.poolMint ?? null, isWritable: true }, + clockSysvar: { value: input.clockSysvar ?? null, isWritable: false }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + stakeProgram: { value: input.stakeProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.withdrawAuthority.value) { + accounts.withdrawAuthority.value = await findWithdrawAuthorityPda({ + stakePoolAddress: expectAddress(accounts.stakePool.value), + }); + } + if (!accounts.clockSysvar.value) { + accounts.clockSysvar.value = + "SysvarC1ock11111111111111111111111111111111" as Address<"SysvarC1ock11111111111111111111111111111111">; + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + if (!accounts.stakeProgram.value) { + accounts.stakeProgram.value = + "Stake11111111111111111111111111111111111111" as Address<"Stake11111111111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.validatorList), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.sourceStakeAccount), + getAccountMeta(accounts.destinationStakeAccount), + getAccountMeta(accounts.newWithdrawAuthority), + getAccountMeta(accounts.userTransferAuthority), + getAccountMeta(accounts.userPoolTokenAccount), + getAccountMeta(accounts.feeAccount), + getAccountMeta(accounts.poolMint), + getAccountMeta(accounts.clockSysvar), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.stakeProgram), + ], + data: getWithdrawStakeInstructionDataEncoder().encode( + args as WithdrawStakeInstructionDataArgs, + ), + programAddress, + } as WithdrawStakeInstruction< + TProgramAddress, + TAccountStakePool, + TAccountValidatorList, + TAccountWithdrawAuthority, + TAccountSourceStakeAccount, + TAccountDestinationStakeAccount, + TAccountNewWithdrawAuthority, + TAccountUserTransferAuthority, + TAccountUserPoolTokenAccount, + TAccountFeeAccount, + TAccountPoolMint, + TAccountClockSysvar, + TAccountTokenProgram, + TAccountStakeProgram + >); +} + +export interface WithdrawStakeInput< + TAccountStakePool extends string = string, + TAccountValidatorList extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountSourceStakeAccount extends string = string, + TAccountDestinationStakeAccount extends string = string, + TAccountNewWithdrawAuthority extends string = string, + TAccountUserTransferAuthority extends string = string, + TAccountUserPoolTokenAccount extends string = string, + TAccountFeeAccount extends string = string, + TAccountPoolMint extends string = string, + TAccountClockSysvar extends string = string, + TAccountTokenProgram extends string = string, + TAccountStakeProgram extends string = string, +> { + /** Stake pool */ + stakePool: Address; + /** Validator list */ + validatorList: Address; + /** Withdraw authority */ + withdrawAuthority: Address; + /** Source stake account */ + sourceStakeAccount: Address; + /** Destination stake account */ + destinationStakeAccount: Address; + /** New withdraw authority */ + newWithdrawAuthority: Address; + /** User transfer authority */ + userTransferAuthority: TransactionSigner; + /** User pool token account */ + userPoolTokenAccount: Address; + /** Fee account */ + feeAccount: Address; + /** Pool mint */ + poolMint: Address; + /** Clock sysvar */ + clockSysvar?: Address; + /** Token program */ + tokenProgram?: Address; + /** Stake program */ + stakeProgram?: Address; + args: WithdrawStakeInstructionDataArgs["args"]; +} + +export function getWithdrawStakeInstruction< + TAccountStakePool extends string, + TAccountValidatorList extends string, + TAccountWithdrawAuthority extends string, + TAccountSourceStakeAccount extends string, + TAccountDestinationStakeAccount extends string, + TAccountNewWithdrawAuthority extends string, + TAccountUserTransferAuthority extends string, + TAccountUserPoolTokenAccount extends string, + TAccountFeeAccount extends string, + TAccountPoolMint extends string, + TAccountClockSysvar extends string, + TAccountTokenProgram extends string, + TAccountStakeProgram extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: WithdrawStakeInput< + TAccountStakePool, + TAccountValidatorList, + TAccountWithdrawAuthority, + TAccountSourceStakeAccount, + TAccountDestinationStakeAccount, + TAccountNewWithdrawAuthority, + TAccountUserTransferAuthority, + TAccountUserPoolTokenAccount, + TAccountFeeAccount, + TAccountPoolMint, + TAccountClockSysvar, + TAccountTokenProgram, + TAccountStakeProgram + >, + config?: { programAddress?: TProgramAddress }, +): WithdrawStakeInstruction< + TProgramAddress, + TAccountStakePool, + TAccountValidatorList, + TAccountWithdrawAuthority, + TAccountSourceStakeAccount, + TAccountDestinationStakeAccount, + TAccountNewWithdrawAuthority, + TAccountUserTransferAuthority, + TAccountUserPoolTokenAccount, + TAccountFeeAccount, + TAccountPoolMint, + TAccountClockSysvar, + TAccountTokenProgram, + TAccountStakeProgram +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: true }, + validatorList: { value: input.validatorList ?? null, isWritable: true }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + sourceStakeAccount: { + value: input.sourceStakeAccount ?? null, + isWritable: true, + }, + destinationStakeAccount: { + value: input.destinationStakeAccount ?? null, + isWritable: true, + }, + newWithdrawAuthority: { + value: input.newWithdrawAuthority ?? null, + isWritable: false, + }, + userTransferAuthority: { + value: input.userTransferAuthority ?? null, + isWritable: false, + }, + userPoolTokenAccount: { + value: input.userPoolTokenAccount ?? null, + isWritable: true, + }, + feeAccount: { value: input.feeAccount ?? null, isWritable: true }, + poolMint: { value: input.poolMint ?? null, isWritable: true }, + clockSysvar: { value: input.clockSysvar ?? null, isWritable: false }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + stakeProgram: { value: input.stakeProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.clockSysvar.value) { + accounts.clockSysvar.value = + "SysvarC1ock11111111111111111111111111111111" as Address<"SysvarC1ock11111111111111111111111111111111">; + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + if (!accounts.stakeProgram.value) { + accounts.stakeProgram.value = + "Stake11111111111111111111111111111111111111" as Address<"Stake11111111111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.validatorList), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.sourceStakeAccount), + getAccountMeta(accounts.destinationStakeAccount), + getAccountMeta(accounts.newWithdrawAuthority), + getAccountMeta(accounts.userTransferAuthority), + getAccountMeta(accounts.userPoolTokenAccount), + getAccountMeta(accounts.feeAccount), + getAccountMeta(accounts.poolMint), + getAccountMeta(accounts.clockSysvar), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.stakeProgram), + ], + data: getWithdrawStakeInstructionDataEncoder().encode( + args as WithdrawStakeInstructionDataArgs, + ), + programAddress, + } as WithdrawStakeInstruction< + TProgramAddress, + TAccountStakePool, + TAccountValidatorList, + TAccountWithdrawAuthority, + TAccountSourceStakeAccount, + TAccountDestinationStakeAccount, + TAccountNewWithdrawAuthority, + TAccountUserTransferAuthority, + TAccountUserPoolTokenAccount, + TAccountFeeAccount, + TAccountPoolMint, + TAccountClockSysvar, + TAccountTokenProgram, + TAccountStakeProgram + >); +} + +export interface ParsedWithdrawStakeInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + /** Stake pool */ + stakePool: TAccountMetas[0]; + /** Validator list */ + validatorList: TAccountMetas[1]; + /** Withdraw authority */ + withdrawAuthority: TAccountMetas[2]; + /** Source stake account */ + sourceStakeAccount: TAccountMetas[3]; + /** Destination stake account */ + destinationStakeAccount: TAccountMetas[4]; + /** New withdraw authority */ + newWithdrawAuthority: TAccountMetas[5]; + /** User transfer authority */ + userTransferAuthority: TAccountMetas[6]; + /** User pool token account */ + userPoolTokenAccount: TAccountMetas[7]; + /** Fee account */ + feeAccount: TAccountMetas[8]; + /** Pool mint */ + poolMint: TAccountMetas[9]; + /** Clock sysvar */ + clockSysvar: TAccountMetas[10]; + /** Token program */ + tokenProgram: TAccountMetas[11]; + /** Stake program */ + stakeProgram: TAccountMetas[12]; + }; + data: WithdrawStakeInstructionData; +} + +export function parseWithdrawStakeInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedWithdrawStakeInstruction { + if (instruction.accounts.length < 13) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + stakePool: getNextAccount(), + validatorList: getNextAccount(), + withdrawAuthority: getNextAccount(), + sourceStakeAccount: getNextAccount(), + destinationStakeAccount: getNextAccount(), + newWithdrawAuthority: getNextAccount(), + userTransferAuthority: getNextAccount(), + userPoolTokenAccount: getNextAccount(), + feeAccount: getNextAccount(), + poolMint: getNextAccount(), + clockSysvar: getNextAccount(), + tokenProgram: getNextAccount(), + stakeProgram: getNextAccount(), + }, + data: getWithdrawStakeInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/spl-stake-pool/src/generated/instructions/withdrawStakeWithSlippage.ts b/clients/spl-stake-pool/src/generated/instructions/withdrawStakeWithSlippage.ts new file mode 100644 index 00000000..9bfd916f --- /dev/null +++ b/clients/spl-stake-pool/src/generated/instructions/withdrawStakeWithSlippage.ts @@ -0,0 +1,586 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getU64Decoder, + getU64Encoder, + transformEncoder, +} from "@solana/kit"; +import { findWithdrawAuthorityPda } from "../pdas/index.js"; +import { SPL_STAKE_POOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; + +export const WITHDRAW_STAKE_WITH_SLIPPAGE_DISCRIMINATOR = 24; + +export function getWithdrawStakeWithSlippageDiscriminatorBytes(): ReadonlyUint8Array { + return getU8Encoder().encode(WITHDRAW_STAKE_WITH_SLIPPAGE_DISCRIMINATOR); +} + +export type WithdrawStakeWithSlippageInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountStakePool extends string | AccountMeta = string, + TAccountValidatorList extends string | AccountMeta = string, + TAccountWithdrawAuthority extends string | AccountMeta = string, + TAccountSourceStakeAccount extends string | AccountMeta = string, + TAccountDestinationStakeAccount extends string | AccountMeta = string, + TAccountNewWithdrawAuthority extends string | AccountMeta = string, + TAccountUserTransferAuthority extends string | AccountMeta = string, + TAccountUserPoolTokenAccount extends string | AccountMeta = string, + TAccountFeeAccount extends string | AccountMeta = string, + TAccountPoolMint extends string | AccountMeta = string, + TAccountClockSysvar extends + | string + | AccountMeta = "SysvarC1ock11111111111111111111111111111111", + TAccountTokenProgram extends + | string + | AccountMeta = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + TAccountStakeProgram extends + | string + | AccountMeta = "Stake11111111111111111111111111111111111111", + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountStakePool extends string + ? WritableAccount + : TAccountStakePool, + TAccountValidatorList extends string + ? WritableAccount + : TAccountValidatorList, + TAccountWithdrawAuthority extends string + ? ReadonlyAccount + : TAccountWithdrawAuthority, + TAccountSourceStakeAccount extends string + ? WritableAccount + : TAccountSourceStakeAccount, + TAccountDestinationStakeAccount extends string + ? WritableAccount + : TAccountDestinationStakeAccount, + TAccountNewWithdrawAuthority extends string + ? ReadonlyAccount + : TAccountNewWithdrawAuthority, + TAccountUserTransferAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountUserTransferAuthority, + TAccountUserPoolTokenAccount extends string + ? WritableAccount + : TAccountUserPoolTokenAccount, + TAccountFeeAccount extends string + ? WritableAccount + : TAccountFeeAccount, + TAccountPoolMint extends string + ? WritableAccount + : TAccountPoolMint, + TAccountClockSysvar extends string + ? ReadonlyAccount + : TAccountClockSysvar, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + TAccountStakeProgram extends string + ? ReadonlyAccount + : TAccountStakeProgram, + ...TRemainingAccounts, + ] + >; + +export interface WithdrawStakeWithSlippageInstructionData { + discriminator: number; + poolTokensIn: bigint; + minimumLamportsOut: bigint; +} + +export interface WithdrawStakeWithSlippageInstructionDataArgs { + poolTokensIn: number | bigint; + minimumLamportsOut: number | bigint; +} + +export function getWithdrawStakeWithSlippageInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", getU8Encoder()], + ["poolTokensIn", getU64Encoder()], + ["minimumLamportsOut", getU64Encoder()], + ]), + (value) => ({ + ...value, + discriminator: WITHDRAW_STAKE_WITH_SLIPPAGE_DISCRIMINATOR, + }), + ); +} + +export function getWithdrawStakeWithSlippageInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", getU8Decoder()], + ["poolTokensIn", getU64Decoder()], + ["minimumLamportsOut", getU64Decoder()], + ]); +} + +export function getWithdrawStakeWithSlippageInstructionDataCodec(): FixedSizeCodec< + WithdrawStakeWithSlippageInstructionDataArgs, + WithdrawStakeWithSlippageInstructionData +> { + return combineCodec( + getWithdrawStakeWithSlippageInstructionDataEncoder(), + getWithdrawStakeWithSlippageInstructionDataDecoder(), + ); +} + +export interface WithdrawStakeWithSlippageAsyncInput< + TAccountStakePool extends string = string, + TAccountValidatorList extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountSourceStakeAccount extends string = string, + TAccountDestinationStakeAccount extends string = string, + TAccountNewWithdrawAuthority extends string = string, + TAccountUserTransferAuthority extends string = string, + TAccountUserPoolTokenAccount extends string = string, + TAccountFeeAccount extends string = string, + TAccountPoolMint extends string = string, + TAccountClockSysvar extends string = string, + TAccountTokenProgram extends string = string, + TAccountStakeProgram extends string = string, +> { + stakePool: Address; + validatorList: Address; + withdrawAuthority?: Address; + sourceStakeAccount: Address; + destinationStakeAccount: Address; + newWithdrawAuthority: Address; + userTransferAuthority: TransactionSigner; + userPoolTokenAccount: Address; + feeAccount: Address; + poolMint: Address; + clockSysvar?: Address; + tokenProgram?: Address; + stakeProgram?: Address; + poolTokensIn: WithdrawStakeWithSlippageInstructionDataArgs["poolTokensIn"]; + minimumLamportsOut: WithdrawStakeWithSlippageInstructionDataArgs["minimumLamportsOut"]; +} + +export async function getWithdrawStakeWithSlippageInstructionAsync< + TAccountStakePool extends string, + TAccountValidatorList extends string, + TAccountWithdrawAuthority extends string, + TAccountSourceStakeAccount extends string, + TAccountDestinationStakeAccount extends string, + TAccountNewWithdrawAuthority extends string, + TAccountUserTransferAuthority extends string, + TAccountUserPoolTokenAccount extends string, + TAccountFeeAccount extends string, + TAccountPoolMint extends string, + TAccountClockSysvar extends string, + TAccountTokenProgram extends string, + TAccountStakeProgram extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: WithdrawStakeWithSlippageAsyncInput< + TAccountStakePool, + TAccountValidatorList, + TAccountWithdrawAuthority, + TAccountSourceStakeAccount, + TAccountDestinationStakeAccount, + TAccountNewWithdrawAuthority, + TAccountUserTransferAuthority, + TAccountUserPoolTokenAccount, + TAccountFeeAccount, + TAccountPoolMint, + TAccountClockSysvar, + TAccountTokenProgram, + TAccountStakeProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + WithdrawStakeWithSlippageInstruction< + TProgramAddress, + TAccountStakePool, + TAccountValidatorList, + TAccountWithdrawAuthority, + TAccountSourceStakeAccount, + TAccountDestinationStakeAccount, + TAccountNewWithdrawAuthority, + TAccountUserTransferAuthority, + TAccountUserPoolTokenAccount, + TAccountFeeAccount, + TAccountPoolMint, + TAccountClockSysvar, + TAccountTokenProgram, + TAccountStakeProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: true }, + validatorList: { value: input.validatorList ?? null, isWritable: true }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + sourceStakeAccount: { + value: input.sourceStakeAccount ?? null, + isWritable: true, + }, + destinationStakeAccount: { + value: input.destinationStakeAccount ?? null, + isWritable: true, + }, + newWithdrawAuthority: { + value: input.newWithdrawAuthority ?? null, + isWritable: false, + }, + userTransferAuthority: { + value: input.userTransferAuthority ?? null, + isWritable: false, + }, + userPoolTokenAccount: { + value: input.userPoolTokenAccount ?? null, + isWritable: true, + }, + feeAccount: { value: input.feeAccount ?? null, isWritable: true }, + poolMint: { value: input.poolMint ?? null, isWritable: true }, + clockSysvar: { value: input.clockSysvar ?? null, isWritable: false }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + stakeProgram: { value: input.stakeProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.withdrawAuthority.value) { + accounts.withdrawAuthority.value = await findWithdrawAuthorityPda({ + stakePoolAddress: expectAddress(accounts.stakePool.value), + }); + } + if (!accounts.clockSysvar.value) { + accounts.clockSysvar.value = + "SysvarC1ock11111111111111111111111111111111" as Address<"SysvarC1ock11111111111111111111111111111111">; + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + if (!accounts.stakeProgram.value) { + accounts.stakeProgram.value = + "Stake11111111111111111111111111111111111111" as Address<"Stake11111111111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.validatorList), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.sourceStakeAccount), + getAccountMeta(accounts.destinationStakeAccount), + getAccountMeta(accounts.newWithdrawAuthority), + getAccountMeta(accounts.userTransferAuthority), + getAccountMeta(accounts.userPoolTokenAccount), + getAccountMeta(accounts.feeAccount), + getAccountMeta(accounts.poolMint), + getAccountMeta(accounts.clockSysvar), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.stakeProgram), + ], + data: getWithdrawStakeWithSlippageInstructionDataEncoder().encode( + args as WithdrawStakeWithSlippageInstructionDataArgs, + ), + programAddress, + } as WithdrawStakeWithSlippageInstruction< + TProgramAddress, + TAccountStakePool, + TAccountValidatorList, + TAccountWithdrawAuthority, + TAccountSourceStakeAccount, + TAccountDestinationStakeAccount, + TAccountNewWithdrawAuthority, + TAccountUserTransferAuthority, + TAccountUserPoolTokenAccount, + TAccountFeeAccount, + TAccountPoolMint, + TAccountClockSysvar, + TAccountTokenProgram, + TAccountStakeProgram + >); +} + +export interface WithdrawStakeWithSlippageInput< + TAccountStakePool extends string = string, + TAccountValidatorList extends string = string, + TAccountWithdrawAuthority extends string = string, + TAccountSourceStakeAccount extends string = string, + TAccountDestinationStakeAccount extends string = string, + TAccountNewWithdrawAuthority extends string = string, + TAccountUserTransferAuthority extends string = string, + TAccountUserPoolTokenAccount extends string = string, + TAccountFeeAccount extends string = string, + TAccountPoolMint extends string = string, + TAccountClockSysvar extends string = string, + TAccountTokenProgram extends string = string, + TAccountStakeProgram extends string = string, +> { + stakePool: Address; + validatorList: Address; + withdrawAuthority: Address; + sourceStakeAccount: Address; + destinationStakeAccount: Address; + newWithdrawAuthority: Address; + userTransferAuthority: TransactionSigner; + userPoolTokenAccount: Address; + feeAccount: Address; + poolMint: Address; + clockSysvar?: Address; + tokenProgram?: Address; + stakeProgram?: Address; + poolTokensIn: WithdrawStakeWithSlippageInstructionDataArgs["poolTokensIn"]; + minimumLamportsOut: WithdrawStakeWithSlippageInstructionDataArgs["minimumLamportsOut"]; +} + +export function getWithdrawStakeWithSlippageInstruction< + TAccountStakePool extends string, + TAccountValidatorList extends string, + TAccountWithdrawAuthority extends string, + TAccountSourceStakeAccount extends string, + TAccountDestinationStakeAccount extends string, + TAccountNewWithdrawAuthority extends string, + TAccountUserTransferAuthority extends string, + TAccountUserPoolTokenAccount extends string, + TAccountFeeAccount extends string, + TAccountPoolMint extends string, + TAccountClockSysvar extends string, + TAccountTokenProgram extends string, + TAccountStakeProgram extends string, + TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, +>( + input: WithdrawStakeWithSlippageInput< + TAccountStakePool, + TAccountValidatorList, + TAccountWithdrawAuthority, + TAccountSourceStakeAccount, + TAccountDestinationStakeAccount, + TAccountNewWithdrawAuthority, + TAccountUserTransferAuthority, + TAccountUserPoolTokenAccount, + TAccountFeeAccount, + TAccountPoolMint, + TAccountClockSysvar, + TAccountTokenProgram, + TAccountStakeProgram + >, + config?: { programAddress?: TProgramAddress }, +): WithdrawStakeWithSlippageInstruction< + TProgramAddress, + TAccountStakePool, + TAccountValidatorList, + TAccountWithdrawAuthority, + TAccountSourceStakeAccount, + TAccountDestinationStakeAccount, + TAccountNewWithdrawAuthority, + TAccountUserTransferAuthority, + TAccountUserPoolTokenAccount, + TAccountFeeAccount, + TAccountPoolMint, + TAccountClockSysvar, + TAccountTokenProgram, + TAccountStakeProgram +> { + // Program address. + const programAddress = + config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + stakePool: { value: input.stakePool ?? null, isWritable: true }, + validatorList: { value: input.validatorList ?? null, isWritable: true }, + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: false, + }, + sourceStakeAccount: { + value: input.sourceStakeAccount ?? null, + isWritable: true, + }, + destinationStakeAccount: { + value: input.destinationStakeAccount ?? null, + isWritable: true, + }, + newWithdrawAuthority: { + value: input.newWithdrawAuthority ?? null, + isWritable: false, + }, + userTransferAuthority: { + value: input.userTransferAuthority ?? null, + isWritable: false, + }, + userPoolTokenAccount: { + value: input.userPoolTokenAccount ?? null, + isWritable: true, + }, + feeAccount: { value: input.feeAccount ?? null, isWritable: true }, + poolMint: { value: input.poolMint ?? null, isWritable: true }, + clockSysvar: { value: input.clockSysvar ?? null, isWritable: false }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + stakeProgram: { value: input.stakeProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.clockSysvar.value) { + accounts.clockSysvar.value = + "SysvarC1ock11111111111111111111111111111111" as Address<"SysvarC1ock11111111111111111111111111111111">; + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + if (!accounts.stakeProgram.value) { + accounts.stakeProgram.value = + "Stake11111111111111111111111111111111111111" as Address<"Stake11111111111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.stakePool), + getAccountMeta(accounts.validatorList), + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.sourceStakeAccount), + getAccountMeta(accounts.destinationStakeAccount), + getAccountMeta(accounts.newWithdrawAuthority), + getAccountMeta(accounts.userTransferAuthority), + getAccountMeta(accounts.userPoolTokenAccount), + getAccountMeta(accounts.feeAccount), + getAccountMeta(accounts.poolMint), + getAccountMeta(accounts.clockSysvar), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.stakeProgram), + ], + data: getWithdrawStakeWithSlippageInstructionDataEncoder().encode( + args as WithdrawStakeWithSlippageInstructionDataArgs, + ), + programAddress, + } as WithdrawStakeWithSlippageInstruction< + TProgramAddress, + TAccountStakePool, + TAccountValidatorList, + TAccountWithdrawAuthority, + TAccountSourceStakeAccount, + TAccountDestinationStakeAccount, + TAccountNewWithdrawAuthority, + TAccountUserTransferAuthority, + TAccountUserPoolTokenAccount, + TAccountFeeAccount, + TAccountPoolMint, + TAccountClockSysvar, + TAccountTokenProgram, + TAccountStakeProgram + >); +} + +export interface ParsedWithdrawStakeWithSlippageInstruction< + TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + stakePool: TAccountMetas[0]; + validatorList: TAccountMetas[1]; + withdrawAuthority: TAccountMetas[2]; + sourceStakeAccount: TAccountMetas[3]; + destinationStakeAccount: TAccountMetas[4]; + newWithdrawAuthority: TAccountMetas[5]; + userTransferAuthority: TAccountMetas[6]; + userPoolTokenAccount: TAccountMetas[7]; + feeAccount: TAccountMetas[8]; + poolMint: TAccountMetas[9]; + clockSysvar: TAccountMetas[10]; + tokenProgram: TAccountMetas[11]; + stakeProgram: TAccountMetas[12]; + }; + data: WithdrawStakeWithSlippageInstructionData; +} + +export function parseWithdrawStakeWithSlippageInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedWithdrawStakeWithSlippageInstruction { + if (instruction.accounts.length < 13) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + stakePool: getNextAccount(), + validatorList: getNextAccount(), + withdrawAuthority: getNextAccount(), + sourceStakeAccount: getNextAccount(), + destinationStakeAccount: getNextAccount(), + newWithdrawAuthority: getNextAccount(), + userTransferAuthority: getNextAccount(), + userPoolTokenAccount: getNextAccount(), + feeAccount: getNextAccount(), + poolMint: getNextAccount(), + clockSysvar: getNextAccount(), + tokenProgram: getNextAccount(), + stakeProgram: getNextAccount(), + }, + data: getWithdrawStakeWithSlippageInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/spl-stake-pool/src/generated/pdas/ephemeralStake.ts b/clients/spl-stake-pool/src/generated/pdas/ephemeralStake.ts new file mode 100644 index 00000000..c9effe35 --- /dev/null +++ b/clients/spl-stake-pool/src/generated/pdas/ephemeralStake.ts @@ -0,0 +1,37 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { Address, ProgramDerivedAddress } from "@solana/kit"; +import { + getAddressEncoder, + getProgramDerivedAddress, + getU64Encoder, + getUtf8Encoder, +} from "@solana/kit"; + +export interface EphemeralStakeSeeds { + stakePoolAddress: Address; + seed: number | bigint; +} + +export async function findEphemeralStakePda( + seeds: EphemeralStakeSeeds, + config: { programAddress?: Address | undefined } = {}, +): Promise { + const { + programAddress = "SPoo1Ku8WFXoNDMHPsrGSTSG1Y47rzgn41SLUNakuHy" as Address<"SPoo1Ku8WFXoNDMHPsrGSTSG1Y47rzgn41SLUNakuHy">, + } = config; + return await getProgramDerivedAddress({ + programAddress, + seeds: [ + getUtf8Encoder().encode("ephemeral"), + getAddressEncoder().encode(seeds.stakePoolAddress), + getU64Encoder().encode(seeds.seed), + ], + }); +} diff --git a/clients/spl-stake-pool/src/generated/pdas/index.ts b/clients/spl-stake-pool/src/generated/pdas/index.ts new file mode 100644 index 00000000..a74be1a2 --- /dev/null +++ b/clients/spl-stake-pool/src/generated/pdas/index.ts @@ -0,0 +1,12 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +export * from "./ephemeralStake.js"; +export * from "./stake.js"; +export * from "./transientStake.js"; +export * from "./withdrawAuthority.js"; diff --git a/clients/spl-stake-pool/src/generated/pdas/stake.ts b/clients/spl-stake-pool/src/generated/pdas/stake.ts new file mode 100644 index 00000000..91b05d22 --- /dev/null +++ b/clients/spl-stake-pool/src/generated/pdas/stake.ts @@ -0,0 +1,42 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + Address, + OptionOrNullable, + ProgramDerivedAddress, +} from "@solana/kit"; +import { + getAddressEncoder, + getOptionEncoder, + getProgramDerivedAddress, + getU32Encoder, +} from "@solana/kit"; + +export interface StakeSeeds { + voteAccountAddress: Address; + stakePoolAddress: Address; + seed: OptionOrNullable; +} + +export async function findStakePda( + seeds: StakeSeeds, + config: { programAddress?: Address | undefined } = {}, +): Promise { + const { + programAddress = "SPoo1Ku8WFXoNDMHPsrGSTSG1Y47rzgn41SLUNakuHy" as Address<"SPoo1Ku8WFXoNDMHPsrGSTSG1Y47rzgn41SLUNakuHy">, + } = config; + return await getProgramDerivedAddress({ + programAddress, + seeds: [ + getAddressEncoder().encode(seeds.voteAccountAddress), + getAddressEncoder().encode(seeds.stakePoolAddress), + getOptionEncoder(getU32Encoder(), { prefix: null }).encode(seeds.seed), + ], + }); +} diff --git a/clients/spl-stake-pool/src/generated/pdas/transientStake.ts b/clients/spl-stake-pool/src/generated/pdas/transientStake.ts new file mode 100644 index 00000000..42d0e84c --- /dev/null +++ b/clients/spl-stake-pool/src/generated/pdas/transientStake.ts @@ -0,0 +1,39 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { Address, ProgramDerivedAddress } from "@solana/kit"; +import { + getAddressEncoder, + getProgramDerivedAddress, + getU64Encoder, + getUtf8Encoder, +} from "@solana/kit"; + +export interface TransientStakeSeeds { + voteAccountAddress: Address; + stakePoolAddress: Address; + seed: number | bigint; +} + +export async function findTransientStakePda( + seeds: TransientStakeSeeds, + config: { programAddress?: Address | undefined } = {}, +): Promise { + const { + programAddress = "SPoo1Ku8WFXoNDMHPsrGSTSG1Y47rzgn41SLUNakuHy" as Address<"SPoo1Ku8WFXoNDMHPsrGSTSG1Y47rzgn41SLUNakuHy">, + } = config; + return await getProgramDerivedAddress({ + programAddress, + seeds: [ + getUtf8Encoder().encode("transient"), + getAddressEncoder().encode(seeds.voteAccountAddress), + getAddressEncoder().encode(seeds.stakePoolAddress), + getU64Encoder().encode(seeds.seed), + ], + }); +} diff --git a/clients/spl-stake-pool/src/generated/pdas/withdrawAuthority.ts b/clients/spl-stake-pool/src/generated/pdas/withdrawAuthority.ts new file mode 100644 index 00000000..f3c63ef0 --- /dev/null +++ b/clients/spl-stake-pool/src/generated/pdas/withdrawAuthority.ts @@ -0,0 +1,34 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { Address, ProgramDerivedAddress } from "@solana/kit"; +import { + getAddressEncoder, + getProgramDerivedAddress, + getUtf8Encoder, +} from "@solana/kit"; + +export interface WithdrawAuthoritySeeds { + stakePoolAddress: Address; +} + +export async function findWithdrawAuthorityPda( + seeds: WithdrawAuthoritySeeds, + config: { programAddress?: Address | undefined } = {}, +): Promise { + const { + programAddress = "SPoo1Ku8WFXoNDMHPsrGSTSG1Y47rzgn41SLUNakuHy" as Address<"SPoo1Ku8WFXoNDMHPsrGSTSG1Y47rzgn41SLUNakuHy">, + } = config; + return await getProgramDerivedAddress({ + programAddress, + seeds: [ + getAddressEncoder().encode(seeds.stakePoolAddress), + getUtf8Encoder().encode("withdraw"), + ], + }); +} diff --git a/clients/spl-stake-pool/src/generated/programs/index.ts b/clients/spl-stake-pool/src/generated/programs/index.ts new file mode 100644 index 00000000..21cd3fa2 --- /dev/null +++ b/clients/spl-stake-pool/src/generated/programs/index.ts @@ -0,0 +1,9 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +export * from "./splStakePool.js"; diff --git a/clients/spl-stake-pool/src/generated/programs/splStakePool.ts b/clients/spl-stake-pool/src/generated/programs/splStakePool.ts new file mode 100644 index 00000000..d0a3b481 --- /dev/null +++ b/clients/spl-stake-pool/src/generated/programs/splStakePool.ts @@ -0,0 +1,280 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { Address, ReadonlyUint8Array } from "@solana/kit"; +import type { + ParsedAddValidatorToPoolInstruction, + ParsedCleanupRemovedValidatorEntriesInstruction, + ParsedCreateTokenMetadataInstruction, + ParsedDecreaseAdditionalValidatorStakeInstruction, + ParsedDecreaseValidatorStakeInstruction, + ParsedDecreaseValidatorStakeWithReserveInstruction, + ParsedDepositSolInstruction, + ParsedDepositSolWithSlippageInstruction, + ParsedDepositStakeInstruction, + ParsedDepositStakeWithSlippageInstruction, + ParsedIncreaseAdditionalValidatorStakeInstruction, + ParsedIncreaseValidatorStakeInstruction, + ParsedInitializeInstruction, + ParsedRedelegateInstruction, + ParsedRemoveValidatorFromPoolInstruction, + ParsedSetFeeInstruction, + ParsedSetFundingAuthorityInstruction, + ParsedSetManagerInstruction, + ParsedSetPreferredValidatorInstruction, + ParsedSetStakerInstruction, + ParsedUpdateStakePoolBalanceInstruction, + ParsedUpdateTokenMetadataInstruction, + ParsedUpdateValidatorListBalanceInstruction, + ParsedWithdrawSolInstruction, + ParsedWithdrawSolWithSlippageInstruction, + ParsedWithdrawStakeInstruction, + ParsedWithdrawStakeWithSlippageInstruction, +} from "../instructions/index.js"; +import { containsBytes, getU8Encoder } from "@solana/kit"; +import { AccountType, getAccountTypeEncoder } from "../types/index.js"; + +export const SPL_STAKE_POOL_PROGRAM_ADDRESS = + "SPoo1Ku8WFXoNDMHPsrGSTSG1Y47rzgn41SLUNakuHy" as Address<"SPoo1Ku8WFXoNDMHPsrGSTSG1Y47rzgn41SLUNakuHy">; + +export enum SplStakePoolAccount { + StakePool = 0, + ValidatorList = 1, +} + +export function identifySplStakePoolAccount( + account: { data: ReadonlyUint8Array } | ReadonlyUint8Array, +): SplStakePoolAccount { + const data = "data" in account ? account.data : account; + if ( + containsBytes( + data, + getAccountTypeEncoder().encode(AccountType.StakePool), + 0, + ) + ) { + return SplStakePoolAccount.StakePool; + } + if ( + containsBytes( + data, + getAccountTypeEncoder().encode(AccountType.ValidatorList), + 0, + ) + ) { + return SplStakePoolAccount.ValidatorList; + } + throw new Error( + "The provided account could not be identified as a splStakePool account.", + ); +} + +export enum SplStakePoolInstruction { + Initialize = 0, + AddValidatorToPool = 1, + RemoveValidatorFromPool = 2, + DecreaseValidatorStake = 3, + IncreaseValidatorStake = 4, + SetPreferredValidator = 5, + UpdateValidatorListBalance = 6, + UpdateStakePoolBalance = 7, + CleanupRemovedValidatorEntries = 8, + DepositStake = 9, + WithdrawStake = 10, + SetManager = 11, + SetFee = 12, + SetStaker = 13, + DepositSol = 14, + SetFundingAuthority = 15, + WithdrawSol = 16, + CreateTokenMetadata = 17, + UpdateTokenMetadata = 18, + IncreaseAdditionalValidatorStake = 19, + DecreaseAdditionalValidatorStake = 20, + DecreaseValidatorStakeWithReserve = 21, + Redelegate = 22, + DepositStakeWithSlippage = 23, + WithdrawStakeWithSlippage = 24, + DepositSolWithSlippage = 25, + WithdrawSolWithSlippage = 26, +} + +export function identifySplStakePoolInstruction( + instruction: { data: ReadonlyUint8Array } | ReadonlyUint8Array, +): SplStakePoolInstruction { + const data = "data" in instruction ? instruction.data : instruction; + if (containsBytes(data, getU8Encoder().encode(0), 0)) { + return SplStakePoolInstruction.Initialize; + } + if (containsBytes(data, getU8Encoder().encode(1), 0)) { + return SplStakePoolInstruction.AddValidatorToPool; + } + if (containsBytes(data, getU8Encoder().encode(2), 0)) { + return SplStakePoolInstruction.RemoveValidatorFromPool; + } + if (containsBytes(data, getU8Encoder().encode(3), 0)) { + return SplStakePoolInstruction.DecreaseValidatorStake; + } + if (containsBytes(data, getU8Encoder().encode(4), 0)) { + return SplStakePoolInstruction.IncreaseValidatorStake; + } + if (containsBytes(data, getU8Encoder().encode(5), 0)) { + return SplStakePoolInstruction.SetPreferredValidator; + } + if (containsBytes(data, getU8Encoder().encode(6), 0)) { + return SplStakePoolInstruction.UpdateValidatorListBalance; + } + if (containsBytes(data, getU8Encoder().encode(7), 0)) { + return SplStakePoolInstruction.UpdateStakePoolBalance; + } + if (containsBytes(data, getU8Encoder().encode(8), 0)) { + return SplStakePoolInstruction.CleanupRemovedValidatorEntries; + } + if (containsBytes(data, getU8Encoder().encode(9), 0)) { + return SplStakePoolInstruction.DepositStake; + } + if (containsBytes(data, getU8Encoder().encode(10), 0)) { + return SplStakePoolInstruction.WithdrawStake; + } + if (containsBytes(data, getU8Encoder().encode(11), 0)) { + return SplStakePoolInstruction.SetManager; + } + if (containsBytes(data, getU8Encoder().encode(12), 0)) { + return SplStakePoolInstruction.SetFee; + } + if (containsBytes(data, getU8Encoder().encode(13), 0)) { + return SplStakePoolInstruction.SetStaker; + } + if (containsBytes(data, getU8Encoder().encode(14), 0)) { + return SplStakePoolInstruction.DepositSol; + } + if (containsBytes(data, getU8Encoder().encode(15), 0)) { + return SplStakePoolInstruction.SetFundingAuthority; + } + if (containsBytes(data, getU8Encoder().encode(16), 0)) { + return SplStakePoolInstruction.WithdrawSol; + } + if (containsBytes(data, getU8Encoder().encode(17), 0)) { + return SplStakePoolInstruction.CreateTokenMetadata; + } + if (containsBytes(data, getU8Encoder().encode(18), 0)) { + return SplStakePoolInstruction.UpdateTokenMetadata; + } + if (containsBytes(data, getU8Encoder().encode(19), 0)) { + return SplStakePoolInstruction.IncreaseAdditionalValidatorStake; + } + if (containsBytes(data, getU8Encoder().encode(20), 0)) { + return SplStakePoolInstruction.DecreaseAdditionalValidatorStake; + } + if (containsBytes(data, getU8Encoder().encode(21), 0)) { + return SplStakePoolInstruction.DecreaseValidatorStakeWithReserve; + } + if (containsBytes(data, getU8Encoder().encode(22), 0)) { + return SplStakePoolInstruction.Redelegate; + } + if (containsBytes(data, getU8Encoder().encode(23), 0)) { + return SplStakePoolInstruction.DepositStakeWithSlippage; + } + if (containsBytes(data, getU8Encoder().encode(24), 0)) { + return SplStakePoolInstruction.WithdrawStakeWithSlippage; + } + if (containsBytes(data, getU8Encoder().encode(25), 0)) { + return SplStakePoolInstruction.DepositSolWithSlippage; + } + if (containsBytes(data, getU8Encoder().encode(26), 0)) { + return SplStakePoolInstruction.WithdrawSolWithSlippage; + } + throw new Error( + "The provided instruction could not be identified as a splStakePool instruction.", + ); +} + +export type ParsedSplStakePoolInstruction< + TProgram extends string = "SPoo1Ku8WFXoNDMHPsrGSTSG1Y47rzgn41SLUNakuHy", +> = + | ({ + instructionType: SplStakePoolInstruction.Initialize; + } & ParsedInitializeInstruction) + | ({ + instructionType: SplStakePoolInstruction.AddValidatorToPool; + } & ParsedAddValidatorToPoolInstruction) + | ({ + instructionType: SplStakePoolInstruction.RemoveValidatorFromPool; + } & ParsedRemoveValidatorFromPoolInstruction) + | ({ + instructionType: SplStakePoolInstruction.DecreaseValidatorStake; + } & ParsedDecreaseValidatorStakeInstruction) + | ({ + instructionType: SplStakePoolInstruction.IncreaseValidatorStake; + } & ParsedIncreaseValidatorStakeInstruction) + | ({ + instructionType: SplStakePoolInstruction.SetPreferredValidator; + } & ParsedSetPreferredValidatorInstruction) + | ({ + instructionType: SplStakePoolInstruction.UpdateValidatorListBalance; + } & ParsedUpdateValidatorListBalanceInstruction) + | ({ + instructionType: SplStakePoolInstruction.UpdateStakePoolBalance; + } & ParsedUpdateStakePoolBalanceInstruction) + | ({ + instructionType: SplStakePoolInstruction.CleanupRemovedValidatorEntries; + } & ParsedCleanupRemovedValidatorEntriesInstruction) + | ({ + instructionType: SplStakePoolInstruction.DepositStake; + } & ParsedDepositStakeInstruction) + | ({ + instructionType: SplStakePoolInstruction.WithdrawStake; + } & ParsedWithdrawStakeInstruction) + | ({ + instructionType: SplStakePoolInstruction.SetManager; + } & ParsedSetManagerInstruction) + | ({ + instructionType: SplStakePoolInstruction.SetFee; + } & ParsedSetFeeInstruction) + | ({ + instructionType: SplStakePoolInstruction.SetStaker; + } & ParsedSetStakerInstruction) + | ({ + instructionType: SplStakePoolInstruction.DepositSol; + } & ParsedDepositSolInstruction) + | ({ + instructionType: SplStakePoolInstruction.SetFundingAuthority; + } & ParsedSetFundingAuthorityInstruction) + | ({ + instructionType: SplStakePoolInstruction.WithdrawSol; + } & ParsedWithdrawSolInstruction) + | ({ + instructionType: SplStakePoolInstruction.CreateTokenMetadata; + } & ParsedCreateTokenMetadataInstruction) + | ({ + instructionType: SplStakePoolInstruction.UpdateTokenMetadata; + } & ParsedUpdateTokenMetadataInstruction) + | ({ + instructionType: SplStakePoolInstruction.IncreaseAdditionalValidatorStake; + } & ParsedIncreaseAdditionalValidatorStakeInstruction) + | ({ + instructionType: SplStakePoolInstruction.DecreaseAdditionalValidatorStake; + } & ParsedDecreaseAdditionalValidatorStakeInstruction) + | ({ + instructionType: SplStakePoolInstruction.DecreaseValidatorStakeWithReserve; + } & ParsedDecreaseValidatorStakeWithReserveInstruction) + | ({ + instructionType: SplStakePoolInstruction.Redelegate; + } & ParsedRedelegateInstruction) + | ({ + instructionType: SplStakePoolInstruction.DepositStakeWithSlippage; + } & ParsedDepositStakeWithSlippageInstruction) + | ({ + instructionType: SplStakePoolInstruction.WithdrawStakeWithSlippage; + } & ParsedWithdrawStakeWithSlippageInstruction) + | ({ + instructionType: SplStakePoolInstruction.DepositSolWithSlippage; + } & ParsedDepositSolWithSlippageInstruction) + | ({ + instructionType: SplStakePoolInstruction.WithdrawSolWithSlippage; + } & ParsedWithdrawSolWithSlippageInstruction); diff --git a/clients/spl-stake-pool/src/generated/shared/index.ts b/clients/spl-stake-pool/src/generated/shared/index.ts new file mode 100644 index 00000000..b79b9c6b --- /dev/null +++ b/clients/spl-stake-pool/src/generated/shared/index.ts @@ -0,0 +1,168 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + ProgramDerivedAddress, + TransactionSigner, +} from "@solana/kit"; +import { + AccountRole, + isProgramDerivedAddress, + isTransactionSigner as kitIsTransactionSigner, + upgradeRoleToSigner, +} from "@solana/kit"; + +/** + * Asserts that the given value is not null or undefined. + * @internal + */ +export function expectSome(value: T | null | undefined): T { + if (value === null || value === undefined) { + throw new Error("Expected a value but received null or undefined."); + } + return value; +} + +/** + * Asserts that the given value is a PublicKey. + * @internal + */ +export function expectAddress( + value: + | Address + | ProgramDerivedAddress + | TransactionSigner + | null + | undefined, +): Address { + if (!value) { + throw new Error("Expected a Address."); + } + if (typeof value === "object" && "address" in value) { + return value.address; + } + if (Array.isArray(value)) { + return value[0] as Address; + } + return value as Address; +} + +/** + * Asserts that the given value is a PDA. + * @internal + */ +export function expectProgramDerivedAddress( + value: + | Address + | ProgramDerivedAddress + | TransactionSigner + | null + | undefined, +): ProgramDerivedAddress { + if (!(value && Array.isArray(value) && isProgramDerivedAddress(value))) { + throw new Error("Expected a ProgramDerivedAddress."); + } + return value; +} + +/** + * Asserts that the given value is a TransactionSigner. + * @internal + */ +export function expectTransactionSigner( + value: + | Address + | ProgramDerivedAddress + | TransactionSigner + | null + | undefined, +): TransactionSigner { + if (!(value && isTransactionSigner(value))) { + throw new Error("Expected a TransactionSigner."); + } + return value; +} + +/** + * Defines an instruction account to resolve. + * @internal + */ +export interface ResolvedAccount< + T extends string = string, + U extends + | Address + | ProgramDerivedAddress + | TransactionSigner + | null = + | Address + | ProgramDerivedAddress + | TransactionSigner + | null, +> { + isWritable: boolean; + value: U; +} + +/** + * Defines an instruction that stores additional bytes on-chain. + * @internal + */ +export interface InstructionWithByteDelta { + byteDelta: number; +} + +/** + * Get account metas and signers from resolved accounts. + * @internal + */ +export function getAccountMetaFactory( + programAddress: Address, + optionalAccountStrategy: "omitted" | "programId", +) { + return ( + account: ResolvedAccount, + ): AccountMeta | AccountSignerMeta | undefined => { + if (!account.value) { + if (optionalAccountStrategy === "omitted") { + return; + } + return Object.freeze({ + address: programAddress, + role: AccountRole.READONLY, + }); + } + + const writableRole = account.isWritable + ? AccountRole.WRITABLE + : AccountRole.READONLY; + return Object.freeze({ + address: expectAddress(account.value), + role: isTransactionSigner(account.value) + ? upgradeRoleToSigner(writableRole) + : writableRole, + ...(isTransactionSigner(account.value) ? { signer: account.value } : {}), + }); + }; +} + +export function isTransactionSigner( + value: + | Address + | ProgramDerivedAddress + | TransactionSigner, +): value is TransactionSigner { + return ( + !!value && + typeof value === "object" && + "address" in value && + kitIsTransactionSigner(value) + ); +} diff --git a/clients/spl-stake-pool/src/generated/types/accountType.ts b/clients/spl-stake-pool/src/generated/types/accountType.ts new file mode 100644 index 00000000..de4db3dc --- /dev/null +++ b/clients/spl-stake-pool/src/generated/types/accountType.ts @@ -0,0 +1,38 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, +} from "@solana/kit"; +import { combineCodec, getEnumDecoder, getEnumEncoder } from "@solana/kit"; + +/** Enum representing the account type managed by the program */ +export enum AccountType { + Uninitialized = 0, + StakePool = 1, + ValidatorList = 2, +} + +export type AccountTypeArgs = AccountType; + +export function getAccountTypeEncoder(): FixedSizeEncoder { + return getEnumEncoder(AccountType); +} + +export function getAccountTypeDecoder(): FixedSizeDecoder { + return getEnumDecoder(AccountType); +} + +export function getAccountTypeCodec(): FixedSizeCodec< + AccountTypeArgs, + AccountType +> { + return combineCodec(getAccountTypeEncoder(), getAccountTypeDecoder()); +} diff --git a/clients/spl-stake-pool/src/generated/types/createMetadataAccountArgsV3.ts b/clients/spl-stake-pool/src/generated/types/createMetadataAccountArgsV3.ts new file mode 100644 index 00000000..9964c3d1 --- /dev/null +++ b/clients/spl-stake-pool/src/generated/types/createMetadataAccountArgsV3.ts @@ -0,0 +1,72 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + Codec, + Decoder, + Encoder, + Option, + OptionOrNullable, +} from "@solana/kit"; +import type { DataV2, DataV2Args } from "./index.js"; +import { + combineCodec, + getBooleanDecoder, + getBooleanEncoder, + getOptionDecoder, + getOptionEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, +} from "@solana/kit"; +import { getDataV2Decoder, getDataV2Encoder } from "./index.js"; + +export interface CreateMetadataAccountArgsV3 { + /** Note that unique metadata is disabled for now. */ + data: DataV2; + /** Whether you want your metadata to be changeable in the future. */ + isMutable: boolean; + /** UNUSED If this is a collection parent NFT. */ + collectionDetails: Option; +} + +export interface CreateMetadataAccountArgsV3Args { + /** Note that unique metadata is disabled for now. */ + data: DataV2Args; + /** Whether you want your metadata to be changeable in the future. */ + isMutable: boolean; + /** UNUSED If this is a collection parent NFT. */ + collectionDetails: OptionOrNullable; +} + +export function getCreateMetadataAccountArgsV3Encoder(): Encoder { + return getStructEncoder([ + ["data", getDataV2Encoder()], + ["isMutable", getBooleanEncoder()], + ["collectionDetails", getOptionEncoder(getU8Encoder())], + ]); +} + +export function getCreateMetadataAccountArgsV3Decoder(): Decoder { + return getStructDecoder([ + ["data", getDataV2Decoder()], + ["isMutable", getBooleanDecoder()], + ["collectionDetails", getOptionDecoder(getU8Decoder())], + ]); +} + +export function getCreateMetadataAccountArgsV3Codec(): Codec< + CreateMetadataAccountArgsV3Args, + CreateMetadataAccountArgsV3 +> { + return combineCodec( + getCreateMetadataAccountArgsV3Encoder(), + getCreateMetadataAccountArgsV3Decoder(), + ); +} diff --git a/clients/spl-stake-pool/src/generated/types/dataV2.ts b/clients/spl-stake-pool/src/generated/types/dataV2.ts new file mode 100644 index 00000000..e48921e9 --- /dev/null +++ b/clients/spl-stake-pool/src/generated/types/dataV2.ts @@ -0,0 +1,100 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + Codec, + Decoder, + Encoder, + Option, + OptionOrNullable, +} from "@solana/kit"; +import { + addDecoderSizePrefix, + addEncoderSizePrefix, + combineCodec, + getOptionDecoder, + getOptionEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getU16Decoder, + getU16Encoder, + getU32Decoder, + getU32Encoder, + getUtf8Decoder, + getUtf8Encoder, +} from "@solana/kit"; + +export interface DataV2 { + /** The name of the asset */ + name: string; + /** The symbol for the asset */ + symbol: string; + /** URI pointing to JSON representing the asset */ + uri: string; + /** + * Royalty basis points that goes to creators in secondary sales + * (0-10000) + */ + sellerFeeBasisPoints: number; + /** UNUSED Array of creators, optional */ + creators: Option; + /** UNUSED Collection */ + collection: Option; + /** UNUSED Uses */ + uses: Option; +} + +export interface DataV2Args { + /** The name of the asset */ + name: string; + /** The symbol for the asset */ + symbol: string; + /** URI pointing to JSON representing the asset */ + uri: string; + /** + * Royalty basis points that goes to creators in secondary sales + * (0-10000) + */ + sellerFeeBasisPoints: number; + /** UNUSED Array of creators, optional */ + creators: OptionOrNullable; + /** UNUSED Collection */ + collection: OptionOrNullable; + /** UNUSED Uses */ + uses: OptionOrNullable; +} + +export function getDataV2Encoder(): Encoder { + return getStructEncoder([ + ["name", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())], + ["symbol", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())], + ["uri", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())], + ["sellerFeeBasisPoints", getU16Encoder()], + ["creators", getOptionEncoder(getU8Encoder())], + ["collection", getOptionEncoder(getU8Encoder())], + ["uses", getOptionEncoder(getU8Encoder())], + ]); +} + +export function getDataV2Decoder(): Decoder { + return getStructDecoder([ + ["name", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())], + ["symbol", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())], + ["uri", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())], + ["sellerFeeBasisPoints", getU16Decoder()], + ["creators", getOptionDecoder(getU8Decoder())], + ["collection", getOptionDecoder(getU8Decoder())], + ["uses", getOptionDecoder(getU8Decoder())], + ]); +} + +export function getDataV2Codec(): Codec { + return combineCodec(getDataV2Encoder(), getDataV2Decoder()); +} diff --git a/clients/spl-stake-pool/src/generated/types/fee.ts b/clients/spl-stake-pool/src/generated/types/fee.ts new file mode 100644 index 00000000..b6cba787 --- /dev/null +++ b/clients/spl-stake-pool/src/generated/types/fee.ts @@ -0,0 +1,58 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, +} from "@solana/kit"; +import { + combineCodec, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, +} from "@solana/kit"; + +/** + * Fee rate as a ratio, minted on `UpdateStakePoolBalance` as a proportion of + * the rewards + * If either the numerator or the denominator is 0, the fee is considered to be + * 0 + */ +export interface Fee { + /** denominator of the fee ratio */ + denominator: bigint; + /** numerator of the fee ratio */ + numerator: bigint; +} + +export interface FeeArgs { + /** denominator of the fee ratio */ + denominator: number | bigint; + /** numerator of the fee ratio */ + numerator: number | bigint; +} + +export function getFeeEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ["denominator", getU64Encoder()], + ["numerator", getU64Encoder()], + ]); +} + +export function getFeeDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["denominator", getU64Decoder()], + ["numerator", getU64Decoder()], + ]); +} + +export function getFeeCodec(): FixedSizeCodec { + return combineCodec(getFeeEncoder(), getFeeDecoder()); +} diff --git a/clients/spl-stake-pool/src/generated/types/feeType.ts b/clients/spl-stake-pool/src/generated/types/feeType.ts new file mode 100644 index 00000000..84c79f66 --- /dev/null +++ b/clients/spl-stake-pool/src/generated/types/feeType.ts @@ -0,0 +1,190 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + Codec, + Decoder, + Encoder, + GetDiscriminatedUnionVariant, + GetDiscriminatedUnionVariantContent, +} from "@solana/kit"; +import type { Fee, FeeArgs } from "./index.js"; +import { + combineCodec, + getDiscriminatedUnionDecoder, + getDiscriminatedUnionEncoder, + getStructDecoder, + getStructEncoder, + getTupleDecoder, + getTupleEncoder, + getU8Decoder, + getU8Encoder, +} from "@solana/kit"; +import { getFeeDecoder, getFeeEncoder } from "./index.js"; + +/** The type of fees that can be set on the stake pool */ +export type FeeType = + | { __kind: "SolReferral"; fields: readonly [number] } + | { __kind: "StakeReferral"; fields: readonly [number] } + | { __kind: "Epoch"; fields: readonly [Fee] } + | { __kind: "StakeWithdrawal"; fields: readonly [Fee] } + | { __kind: "SolDeposit"; fields: readonly [Fee] } + | { __kind: "StakeDeposit"; fields: readonly [Fee] } + | { __kind: "SolWithdrawal"; fields: readonly [Fee] }; + +export type FeeTypeArgs = + | { __kind: "SolReferral"; fields: readonly [number] } + | { __kind: "StakeReferral"; fields: readonly [number] } + | { __kind: "Epoch"; fields: readonly [FeeArgs] } + | { __kind: "StakeWithdrawal"; fields: readonly [FeeArgs] } + | { __kind: "SolDeposit"; fields: readonly [FeeArgs] } + | { __kind: "StakeDeposit"; fields: readonly [FeeArgs] } + | { __kind: "SolWithdrawal"; fields: readonly [FeeArgs] }; + +export function getFeeTypeEncoder(): Encoder { + return getDiscriminatedUnionEncoder([ + [ + "SolReferral", + getStructEncoder([["fields", getTupleEncoder([getU8Encoder()])]]), + ], + [ + "StakeReferral", + getStructEncoder([["fields", getTupleEncoder([getU8Encoder()])]]), + ], + [ + "Epoch", + getStructEncoder([["fields", getTupleEncoder([getFeeEncoder()])]]), + ], + [ + "StakeWithdrawal", + getStructEncoder([["fields", getTupleEncoder([getFeeEncoder()])]]), + ], + [ + "SolDeposit", + getStructEncoder([["fields", getTupleEncoder([getFeeEncoder()])]]), + ], + [ + "StakeDeposit", + getStructEncoder([["fields", getTupleEncoder([getFeeEncoder()])]]), + ], + [ + "SolWithdrawal", + getStructEncoder([["fields", getTupleEncoder([getFeeEncoder()])]]), + ], + ]); +} + +export function getFeeTypeDecoder(): Decoder { + return getDiscriminatedUnionDecoder([ + [ + "SolReferral", + getStructDecoder([["fields", getTupleDecoder([getU8Decoder()])]]), + ], + [ + "StakeReferral", + getStructDecoder([["fields", getTupleDecoder([getU8Decoder()])]]), + ], + [ + "Epoch", + getStructDecoder([["fields", getTupleDecoder([getFeeDecoder()])]]), + ], + [ + "StakeWithdrawal", + getStructDecoder([["fields", getTupleDecoder([getFeeDecoder()])]]), + ], + [ + "SolDeposit", + getStructDecoder([["fields", getTupleDecoder([getFeeDecoder()])]]), + ], + [ + "StakeDeposit", + getStructDecoder([["fields", getTupleDecoder([getFeeDecoder()])]]), + ], + [ + "SolWithdrawal", + getStructDecoder([["fields", getTupleDecoder([getFeeDecoder()])]]), + ], + ]); +} + +export function getFeeTypeCodec(): Codec { + return combineCodec(getFeeTypeEncoder(), getFeeTypeDecoder()); +} + +// Data Enum Helpers. +export function feeType( + kind: "SolReferral", + data: GetDiscriminatedUnionVariantContent< + FeeTypeArgs, + "__kind", + "SolReferral" + >["fields"], +): GetDiscriminatedUnionVariant; +export function feeType( + kind: "StakeReferral", + data: GetDiscriminatedUnionVariantContent< + FeeTypeArgs, + "__kind", + "StakeReferral" + >["fields"], +): GetDiscriminatedUnionVariant; +export function feeType( + kind: "Epoch", + data: GetDiscriminatedUnionVariantContent< + FeeTypeArgs, + "__kind", + "Epoch" + >["fields"], +): GetDiscriminatedUnionVariant; +export function feeType( + kind: "StakeWithdrawal", + data: GetDiscriminatedUnionVariantContent< + FeeTypeArgs, + "__kind", + "StakeWithdrawal" + >["fields"], +): GetDiscriminatedUnionVariant; +export function feeType( + kind: "SolDeposit", + data: GetDiscriminatedUnionVariantContent< + FeeTypeArgs, + "__kind", + "SolDeposit" + >["fields"], +): GetDiscriminatedUnionVariant; +export function feeType( + kind: "StakeDeposit", + data: GetDiscriminatedUnionVariantContent< + FeeTypeArgs, + "__kind", + "StakeDeposit" + >["fields"], +): GetDiscriminatedUnionVariant; +export function feeType( + kind: "SolWithdrawal", + data: GetDiscriminatedUnionVariantContent< + FeeTypeArgs, + "__kind", + "SolWithdrawal" + >["fields"], +): GetDiscriminatedUnionVariant; +export function feeType( + kind: K, + data?: Data, +) { + return Array.isArray(data) + ? { __kind: kind, fields: data } + : { __kind: kind, ...(data ?? {}) }; +} + +export function isFeeType( + kind: K, + value: FeeType, +): value is FeeType & { __kind: K } { + return value.__kind === kind; +} diff --git a/clients/spl-stake-pool/src/generated/types/fundingType.ts b/clients/spl-stake-pool/src/generated/types/fundingType.ts new file mode 100644 index 00000000..bacfa83f --- /dev/null +++ b/clients/spl-stake-pool/src/generated/types/fundingType.ts @@ -0,0 +1,41 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, +} from "@solana/kit"; +import { combineCodec, getEnumDecoder, getEnumEncoder } from "@solana/kit"; + +/** + * Defines which authority to update in the `SetFundingAuthority` + * instruction + */ +export enum FundingType { + StakeDeposit = 0, + SolDeposit = 1, + SolWithdraw = 2, +} + +export type FundingTypeArgs = FundingType; + +export function getFundingTypeEncoder(): FixedSizeEncoder { + return getEnumEncoder(FundingType); +} + +export function getFundingTypeDecoder(): FixedSizeDecoder { + return getEnumDecoder(FundingType); +} + +export function getFundingTypeCodec(): FixedSizeCodec< + FundingTypeArgs, + FundingType +> { + return combineCodec(getFundingTypeEncoder(), getFundingTypeDecoder()); +} diff --git a/clients/spl-stake-pool/src/generated/types/futureEpoch.ts b/clients/spl-stake-pool/src/generated/types/futureEpoch.ts new file mode 100644 index 00000000..63f0d63d --- /dev/null +++ b/clients/spl-stake-pool/src/generated/types/futureEpoch.ts @@ -0,0 +1,98 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + Codec, + Decoder, + Encoder, + GetDiscriminatedUnionVariant, + GetDiscriminatedUnionVariantContent, +} from "@solana/kit"; +import type { Fee, FeeArgs } from "./index.js"; +import { + combineCodec, + getDiscriminatedUnionDecoder, + getDiscriminatedUnionEncoder, + getStructDecoder, + getStructEncoder, + getTupleDecoder, + getTupleEncoder, + getUnitDecoder, + getUnitEncoder, +} from "@solana/kit"; +import { getFeeDecoder, getFeeEncoder } from "./index.js"; + +/** + * Wrapper type that "counts down" epochs, which is Borsh-compatible with the + * native `Option` + */ +export type FutureEpoch = + | { __kind: "None" } + | { __kind: "One"; fields: readonly [Fee] } + | { __kind: "Two"; fields: readonly [Fee] }; + +export type FutureEpochArgs = + | { __kind: "None" } + | { __kind: "One"; fields: readonly [FeeArgs] } + | { __kind: "Two"; fields: readonly [FeeArgs] }; + +export function getFutureEpochEncoder(): Encoder { + return getDiscriminatedUnionEncoder([ + ["None", getUnitEncoder()], + ["One", getStructEncoder([["fields", getTupleEncoder([getFeeEncoder()])]])], + ["Two", getStructEncoder([["fields", getTupleEncoder([getFeeEncoder()])]])], + ]); +} + +export function getFutureEpochDecoder(): Decoder { + return getDiscriminatedUnionDecoder([ + ["None", getUnitDecoder()], + ["One", getStructDecoder([["fields", getTupleDecoder([getFeeDecoder()])]])], + ["Two", getStructDecoder([["fields", getTupleDecoder([getFeeDecoder()])]])], + ]); +} + +export function getFutureEpochCodec(): Codec { + return combineCodec(getFutureEpochEncoder(), getFutureEpochDecoder()); +} + +// Data Enum Helpers. +export function futureEpoch( + kind: "None", +): GetDiscriminatedUnionVariant; +export function futureEpoch( + kind: "One", + data: GetDiscriminatedUnionVariantContent< + FutureEpochArgs, + "__kind", + "One" + >["fields"], +): GetDiscriminatedUnionVariant; +export function futureEpoch( + kind: "Two", + data: GetDiscriminatedUnionVariantContent< + FutureEpochArgs, + "__kind", + "Two" + >["fields"], +): GetDiscriminatedUnionVariant; +export function futureEpoch( + kind: K, + data?: Data, +) { + return Array.isArray(data) + ? { __kind: kind, fields: data } + : { __kind: kind, ...(data ?? {}) }; +} + +export function isFutureEpoch( + kind: K, + value: FutureEpoch, +): value is FutureEpoch & { __kind: K } { + return value.__kind === kind; +} diff --git a/clients/spl-stake-pool/src/generated/types/index.ts b/clients/spl-stake-pool/src/generated/types/index.ts new file mode 100644 index 00000000..e8ab489d --- /dev/null +++ b/clients/spl-stake-pool/src/generated/types/index.ts @@ -0,0 +1,21 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +export * from "./accountType.js"; +export * from "./createMetadataAccountArgsV3.js"; +export * from "./dataV2.js"; +export * from "./fee.js"; +export * from "./feeType.js"; +export * from "./fundingType.js"; +export * from "./futureEpoch.js"; +export * from "./lockup.js"; +export * from "./podStakeStatus.js"; +export * from "./preferredValidatorType.js"; +export * from "./stakeStatus.js"; +export * from "./updateMetadataAccountArgsV2.js"; +export * from "./validatorStakeInfo.js"; diff --git a/clients/spl-stake-pool/src/generated/types/lockup.ts b/clients/spl-stake-pool/src/generated/types/lockup.ts new file mode 100644 index 00000000..d37ab908 --- /dev/null +++ b/clients/spl-stake-pool/src/generated/types/lockup.ts @@ -0,0 +1,81 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, +} from "@solana/kit"; +import { + combineCodec, + getAddressDecoder, + getAddressEncoder, + getI64Decoder, + getI64Encoder, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, +} from "@solana/kit"; + +export interface Lockup { + /** + * UnixTimestamp at which this stake will allow withdrawal, unless the + * transaction is signed by the custodian + */ + unixTimestamp: bigint; + /** + * epoch height at which this stake will allow withdrawal, unless the + * transaction is signed by the custodian + */ + epoch: bigint; + /** + * custodian signature on a transaction exempts the operation from + * lockup constraints + */ + custodian: Address; +} + +export interface LockupArgs { + /** + * UnixTimestamp at which this stake will allow withdrawal, unless the + * transaction is signed by the custodian + */ + unixTimestamp: number | bigint; + /** + * epoch height at which this stake will allow withdrawal, unless the + * transaction is signed by the custodian + */ + epoch: number | bigint; + /** + * custodian signature on a transaction exempts the operation from + * lockup constraints + */ + custodian: Address; +} + +export function getLockupEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ["unixTimestamp", getI64Encoder()], + ["epoch", getU64Encoder()], + ["custodian", getAddressEncoder()], + ]); +} + +export function getLockupDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["unixTimestamp", getI64Decoder()], + ["epoch", getU64Decoder()], + ["custodian", getAddressDecoder()], + ]); +} + +export function getLockupCodec(): FixedSizeCodec { + return combineCodec(getLockupEncoder(), getLockupDecoder()); +} diff --git a/clients/spl-stake-pool/src/generated/types/podStakeStatus.ts b/clients/spl-stake-pool/src/generated/types/podStakeStatus.ts new file mode 100644 index 00000000..29da1a6f --- /dev/null +++ b/clients/spl-stake-pool/src/generated/types/podStakeStatus.ts @@ -0,0 +1,46 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, +} from "@solana/kit"; +import { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, +} from "@solana/kit"; + +/** + * Wrapper struct that can be `Pod`, containing a byte that *should* be a valid + * `StakeStatus` underneath. + */ +export interface PodStakeStatus { + /** Pod stake status */ + status: number; +} + +export type PodStakeStatusArgs = PodStakeStatus; + +export function getPodStakeStatusEncoder(): FixedSizeEncoder { + return getStructEncoder([["status", getU8Encoder()]]); +} + +export function getPodStakeStatusDecoder(): FixedSizeDecoder { + return getStructDecoder([["status", getU8Decoder()]]); +} + +export function getPodStakeStatusCodec(): FixedSizeCodec< + PodStakeStatusArgs, + PodStakeStatus +> { + return combineCodec(getPodStakeStatusEncoder(), getPodStakeStatusDecoder()); +} diff --git a/clients/spl-stake-pool/src/generated/types/preferredValidatorType.ts b/clients/spl-stake-pool/src/generated/types/preferredValidatorType.ts new file mode 100644 index 00000000..7dd59d11 --- /dev/null +++ b/clients/spl-stake-pool/src/generated/types/preferredValidatorType.ts @@ -0,0 +1,43 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, +} from "@solana/kit"; +import { combineCodec, getEnumDecoder, getEnumEncoder } from "@solana/kit"; + +/** + * Defines which validator vote account is set during the + * `SetPreferredValidator` instruction + */ +export enum PreferredValidatorType { + Deposit = 0, + Withdraw = 1, +} + +export type PreferredValidatorTypeArgs = PreferredValidatorType; + +export function getPreferredValidatorTypeEncoder(): FixedSizeEncoder { + return getEnumEncoder(PreferredValidatorType); +} + +export function getPreferredValidatorTypeDecoder(): FixedSizeDecoder { + return getEnumDecoder(PreferredValidatorType); +} + +export function getPreferredValidatorTypeCodec(): FixedSizeCodec< + PreferredValidatorTypeArgs, + PreferredValidatorType +> { + return combineCodec( + getPreferredValidatorTypeEncoder(), + getPreferredValidatorTypeDecoder(), + ); +} diff --git a/clients/spl-stake-pool/src/generated/types/stakeStatus.ts b/clients/spl-stake-pool/src/generated/types/stakeStatus.ts new file mode 100644 index 00000000..1fb14b23 --- /dev/null +++ b/clients/spl-stake-pool/src/generated/types/stakeStatus.ts @@ -0,0 +1,40 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, +} from "@solana/kit"; +import { combineCodec, getEnumDecoder, getEnumEncoder } from "@solana/kit"; + +/** Status of the stake account in the validator list, for accounting */ +export enum StakeStatus { + Active = 0, + DeactivatingTransient = 1, + ReadyForRemoval = 2, + DeactivatingValidator = 3, + DeactivatingAll = 4, +} + +export type StakeStatusArgs = StakeStatus; + +export function getStakeStatusEncoder(): FixedSizeEncoder { + return getEnumEncoder(StakeStatus); +} + +export function getStakeStatusDecoder(): FixedSizeDecoder { + return getEnumDecoder(StakeStatus); +} + +export function getStakeStatusCodec(): FixedSizeCodec< + StakeStatusArgs, + StakeStatus +> { + return combineCodec(getStakeStatusEncoder(), getStakeStatusDecoder()); +} diff --git a/clients/spl-stake-pool/src/generated/types/updateMetadataAccountArgsV2.ts b/clients/spl-stake-pool/src/generated/types/updateMetadataAccountArgsV2.ts new file mode 100644 index 00000000..58138f86 --- /dev/null +++ b/clients/spl-stake-pool/src/generated/types/updateMetadataAccountArgsV2.ts @@ -0,0 +1,71 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + Address, + Codec, + Decoder, + Encoder, + Option, + OptionOrNullable, +} from "@solana/kit"; +import type { DataV2, DataV2Args } from "./index.js"; +import { + combineCodec, + getAddressDecoder, + getAddressEncoder, + getBooleanDecoder, + getBooleanEncoder, + getOptionDecoder, + getOptionEncoder, + getStructDecoder, + getStructEncoder, +} from "@solana/kit"; +import { getDataV2Decoder, getDataV2Encoder } from "./index.js"; + +export interface UpdateMetadataAccountArgsV2 { + data: Option; + updateAuthority: Option
; + primarySaleHappened: Option; + isMutable: Option; +} + +export interface UpdateMetadataAccountArgsV2Args { + data: OptionOrNullable; + updateAuthority: OptionOrNullable
; + primarySaleHappened: OptionOrNullable; + isMutable: OptionOrNullable; +} + +export function getUpdateMetadataAccountArgsV2Encoder(): Encoder { + return getStructEncoder([ + ["data", getOptionEncoder(getDataV2Encoder())], + ["updateAuthority", getOptionEncoder(getAddressEncoder())], + ["primarySaleHappened", getOptionEncoder(getBooleanEncoder())], + ["isMutable", getOptionEncoder(getBooleanEncoder())], + ]); +} + +export function getUpdateMetadataAccountArgsV2Decoder(): Decoder { + return getStructDecoder([ + ["data", getOptionDecoder(getDataV2Decoder())], + ["updateAuthority", getOptionDecoder(getAddressDecoder())], + ["primarySaleHappened", getOptionDecoder(getBooleanDecoder())], + ["isMutable", getOptionDecoder(getBooleanDecoder())], + ]); +} + +export function getUpdateMetadataAccountArgsV2Codec(): Codec< + UpdateMetadataAccountArgsV2Args, + UpdateMetadataAccountArgsV2 +> { + return combineCodec( + getUpdateMetadataAccountArgsV2Encoder(), + getUpdateMetadataAccountArgsV2Decoder(), + ); +} diff --git a/clients/spl-stake-pool/src/generated/types/validatorStakeInfo.ts b/clients/spl-stake-pool/src/generated/types/validatorStakeInfo.ts new file mode 100644 index 00000000..7c9493ba --- /dev/null +++ b/clients/spl-stake-pool/src/generated/types/validatorStakeInfo.ts @@ -0,0 +1,131 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, +} from "@solana/kit"; +import type { PodStakeStatus, PodStakeStatusArgs } from "./index.js"; +import { + combineCodec, + getAddressDecoder, + getAddressEncoder, + getStructDecoder, + getStructEncoder, + getU32Decoder, + getU32Encoder, + getU64Decoder, + getU64Encoder, +} from "@solana/kit"; +import { getPodStakeStatusDecoder, getPodStakeStatusEncoder } from "./index.js"; + +/** + * Information about a validator in the pool + * NOTE: ORDER IS VERY IMPORTANT HERE, PLEASE DO NOT RE-ORDER THE FIELDS UNLESS + * THERE'S AN EXTREMELY GOOD REASON. + * To save on BPF instructions, the serialized bytes are reinterpreted with a + * `bytemuck` transmute, which means that this structure cannot have any + * undeclared alignment-padding in its representation. + */ +export interface ValidatorStakeInfo { + /** + * Amount of lamports on the validator stake account, including rent + * Note that if `last_update_epoch` does not match the current epoch then + * this field may not be accurate + */ + activeStakeLamports: bigint; + /** + * Amount of transient stake delegated to this validator + * Note that if `last_update_epoch` does not match the current epoch then + * this field may not be accurate + */ + transientStakeLamports: bigint; + /** Last epoch the active and transient stake lamports fields were updated */ + lastUpdateEpoch: bigint; + /** + * Transient account seed suffix, used to derive the transient stake + * account address + */ + transientSeedSuffix: bigint; + /** Unused space, initially meant to specify the end of seed suffixes */ + unused: number; + /** Validator account seed suffix */ + validatorSeedSuffix: number; + /** Status of the validator stake account */ + status: PodStakeStatus; + /** Validator vote account address */ + voteAccountAddress: Address; +} + +export interface ValidatorStakeInfoArgs { + /** + * Amount of lamports on the validator stake account, including rent + * Note that if `last_update_epoch` does not match the current epoch then + * this field may not be accurate + */ + activeStakeLamports: number | bigint; + /** + * Amount of transient stake delegated to this validator + * Note that if `last_update_epoch` does not match the current epoch then + * this field may not be accurate + */ + transientStakeLamports: number | bigint; + /** Last epoch the active and transient stake lamports fields were updated */ + lastUpdateEpoch: number | bigint; + /** + * Transient account seed suffix, used to derive the transient stake + * account address + */ + transientSeedSuffix: number | bigint; + /** Unused space, initially meant to specify the end of seed suffixes */ + unused: number; + /** Validator account seed suffix */ + validatorSeedSuffix: number; + /** Status of the validator stake account */ + status: PodStakeStatusArgs; + /** Validator vote account address */ + voteAccountAddress: Address; +} + +export function getValidatorStakeInfoEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ["activeStakeLamports", getU64Encoder()], + ["transientStakeLamports", getU64Encoder()], + ["lastUpdateEpoch", getU64Encoder()], + ["transientSeedSuffix", getU64Encoder()], + ["unused", getU32Encoder()], + ["validatorSeedSuffix", getU32Encoder()], + ["status", getPodStakeStatusEncoder()], + ["voteAccountAddress", getAddressEncoder()], + ]); +} + +export function getValidatorStakeInfoDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["activeStakeLamports", getU64Decoder()], + ["transientStakeLamports", getU64Decoder()], + ["lastUpdateEpoch", getU64Decoder()], + ["transientSeedSuffix", getU64Decoder()], + ["unused", getU32Decoder()], + ["validatorSeedSuffix", getU32Decoder()], + ["status", getPodStakeStatusDecoder()], + ["voteAccountAddress", getAddressDecoder()], + ]); +} + +export function getValidatorStakeInfoCodec(): FixedSizeCodec< + ValidatorStakeInfoArgs, + ValidatorStakeInfo +> { + return combineCodec( + getValidatorStakeInfoEncoder(), + getValidatorStakeInfoDecoder(), + ); +} diff --git a/clients/spl-stake-pool/src/index.ts b/clients/spl-stake-pool/src/index.ts new file mode 100644 index 00000000..9248f57d --- /dev/null +++ b/clients/spl-stake-pool/src/index.ts @@ -0,0 +1,8 @@ +/** + * @macalinao/clients-spl-governance + * + * TypeScript client for the SPL Governance program. + * Generated using Codama with full ESM support. + */ + +export * from "./generated/index.js"; diff --git a/clients/spl-stake-pool/tsconfig.json b/clients/spl-stake-pool/tsconfig.json new file mode 100644 index 00000000..c9d54033 --- /dev/null +++ b/clients/spl-stake-pool/tsconfig.json @@ -0,0 +1,6 @@ +{ + "extends": "@macalinao/tsconfig/tsconfig.base.json", + "compilerOptions": { + "isolatedDeclarations": false + } +} diff --git a/clients/token-metadata/README.md b/clients/token-metadata/README.md index 32b8db7a..ad11359c 100644 --- a/clients/token-metadata/README.md +++ b/clients/token-metadata/README.md @@ -29,9 +29,18 @@ The `coda.config.mjs` file adds custom PDAs to the generated client, including t ## Usage ```typescript -import {} from /* generated exports */ "@macalinao/clients-token-metadata"; - -// Use the generated client functions +import { + getCreateMetadataAccountInstruction, + fetchMetadata, +} from "@macalinao/clients-token-metadata"; + +// Fetch metadata account +const metadata = await fetchMetadata(rpc, metadataAddress); + +// Create metadata account instruction +const instruction = getCreateMetadataAccountInstruction({ + // ... instruction parameters +}); ``` ## License diff --git a/package.json b/package.json index dc7fa771..f3cf75e2 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,8 @@ "husky": "^9.1.7", "lint-staged": "^16.2.4", "turbo": "^2.5.8", - "typedoc": "^0.28.14" + "typedoc": "^0.28.14", + "typescript": "catalog:" }, "packageManager": "bun@1.3.0", "lint-staged": { diff --git a/packages/coda/src/utils/process-idls.ts b/packages/coda/src/utils/process-idls.ts index 69eefb16..f7c47874 100644 --- a/packages/coda/src/utils/process-idls.ts +++ b/packages/coda/src/utils/process-idls.ts @@ -5,6 +5,7 @@ import { resolve } from "node:path"; import { fixDocsVisitor } from "@macalinao/coda-visitors"; import { getCommonInstructionAccountDefaultRules, + publicKeyValueNode, setInstructionAccountDefaultValuesVisitor, } from "codama"; import { applyCustomVisitors } from "./apply-custom-visitors.js"; @@ -50,6 +51,12 @@ export async function processIdls(options: { codama.update( setInstructionAccountDefaultValuesVisitor([ ...getCommonInstructionAccountDefaultRules(), + { + account: "stakeConfigSysvar", + defaultValue: publicKeyValueNode( + "StakeConfig11111111111111111111111111111111", + ), + }, ...(config.instructionAccountDefaultValues ?? []), ]), );