diff --git a/.gitignore b/.gitignore index 9b6e13e8..d00c5d1a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ .DS_Store target test-ledger + +node_modules/ diff --git a/clients/js/src/generated/accounts/automation.ts b/clients/js/src/generated/accounts/automation.ts new file mode 100644 index 00000000..bc098f99 --- /dev/null +++ b/clients/js/src/generated/accounts/automation.ts @@ -0,0 +1,144 @@ +/** + * 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 { + assertAccountExists, + assertAccountsExist, + combineCodec, + decodeAccount, + fetchEncodedAccount, + fetchEncodedAccounts, + getAddressDecoder, + getAddressEncoder, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + type Account, + type Address, + type EncodedAccount, + type FetchAccountConfig, + type FetchAccountsConfig, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type MaybeAccount, + type MaybeEncodedAccount, +} from "@solana/kit"; + +/** Automation parameters for automated mining deployments. */ +export type Automation = { + amount: bigint; + authority: Address; + balance: bigint; + executor: Address; + fee: bigint; + strategy: bigint; + mask: bigint; +}; + +export type AutomationArgs = { + amount: number | bigint; + authority: Address; + balance: number | bigint; + executor: Address; + fee: number | bigint; + strategy: number | bigint; + mask: number | bigint; +}; + +/** Gets the encoder for {@link AutomationArgs} account data. */ +export function getAutomationEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ["amount", getU64Encoder()], + ["authority", getAddressEncoder()], + ["balance", getU64Encoder()], + ["executor", getAddressEncoder()], + ["fee", getU64Encoder()], + ["strategy", getU64Encoder()], + ["mask", getU64Encoder()], + ]); +} + +/** Gets the decoder for {@link Automation} account data. */ +export function getAutomationDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["amount", getU64Decoder()], + ["authority", getAddressDecoder()], + ["balance", getU64Decoder()], + ["executor", getAddressDecoder()], + ["fee", getU64Decoder()], + ["strategy", getU64Decoder()], + ["mask", getU64Decoder()], + ]); +} + +/** Gets the codec for {@link Automation} account data. */ +export function getAutomationCodec(): FixedSizeCodec< + AutomationArgs, + Automation +> { + return combineCodec(getAutomationEncoder(), getAutomationDecoder()); +} + +export function decodeAutomation( + encodedAccount: EncodedAccount, +): Account; +export function decodeAutomation( + encodedAccount: MaybeEncodedAccount, +): MaybeAccount; +export function decodeAutomation( + encodedAccount: EncodedAccount | MaybeEncodedAccount, +): Account | MaybeAccount { + return decodeAccount( + encodedAccount as MaybeEncodedAccount, + getAutomationDecoder(), + ); +} + +export async function fetchAutomation( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchMaybeAutomation(rpc, address, config); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeAutomation( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchEncodedAccount(rpc, address, config); + return decodeAutomation(maybeAccount); +} + +export async function fetchAllAutomation( + rpc: Parameters[0], + addresses: Array
, + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchAllMaybeAutomation(rpc, addresses, config); + assertAccountsExist(maybeAccounts); + return maybeAccounts; +} + +export async function fetchAllMaybeAutomation( + rpc: Parameters[0], + addresses: Array
, + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); + return maybeAccounts.map((maybeAccount) => decodeAutomation(maybeAccount)); +} + +export function getAutomationSize(): number { + return 104; +} diff --git a/clients/js/src/generated/accounts/board.ts b/clients/js/src/generated/accounts/board.ts new file mode 100644 index 00000000..dd8e0a5f --- /dev/null +++ b/clients/js/src/generated/accounts/board.ts @@ -0,0 +1,127 @@ +/** + * 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 { + assertAccountExists, + assertAccountsExist, + combineCodec, + decodeAccount, + fetchEncodedAccount, + fetchEncodedAccounts, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + type Account, + type Address, + type EncodedAccount, + type FetchAccountConfig, + type FetchAccountsConfig, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type MaybeAccount, + type MaybeEncodedAccount, +} from "@solana/kit"; + +/** Global round tracking for the mining game. */ +export type Board = { + roundId: bigint; + startSlot: bigint; + endSlot: bigint; + epochId: bigint; +}; + +export type BoardArgs = { + roundId: number | bigint; + startSlot: number | bigint; + endSlot: number | bigint; + epochId: number | bigint; +}; + +/** Gets the encoder for {@link BoardArgs} account data. */ +export function getBoardEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ["roundId", getU64Encoder()], + ["startSlot", getU64Encoder()], + ["endSlot", getU64Encoder()], + ["epochId", getU64Encoder()], + ]); +} + +/** Gets the decoder for {@link Board} account data. */ +export function getBoardDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["roundId", getU64Decoder()], + ["startSlot", getU64Decoder()], + ["endSlot", getU64Decoder()], + ["epochId", getU64Decoder()], + ]); +} + +/** Gets the codec for {@link Board} account data. */ +export function getBoardCodec(): FixedSizeCodec { + return combineCodec(getBoardEncoder(), getBoardDecoder()); +} + +export function decodeBoard( + encodedAccount: EncodedAccount, +): Account; +export function decodeBoard( + encodedAccount: MaybeEncodedAccount, +): MaybeAccount; +export function decodeBoard( + encodedAccount: EncodedAccount | MaybeEncodedAccount, +): Account | MaybeAccount { + return decodeAccount( + encodedAccount as MaybeEncodedAccount, + getBoardDecoder(), + ); +} + +export async function fetchBoard( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchMaybeBoard(rpc, address, config); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeBoard( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchEncodedAccount(rpc, address, config); + return decodeBoard(maybeAccount); +} + +export async function fetchAllBoard( + rpc: Parameters[0], + addresses: Array
, + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchAllMaybeBoard(rpc, addresses, config); + assertAccountsExist(maybeAccounts); + return maybeAccounts; +} + +export async function fetchAllMaybeBoard( + rpc: Parameters[0], + addresses: Array
, + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); + return maybeAccounts.map((maybeAccount) => decodeBoard(maybeAccount)); +} + +export function getBoardSize(): number { + return 32; +} diff --git a/clients/js/src/generated/accounts/config.ts b/clients/js/src/generated/accounts/config.ts new file mode 100644 index 00000000..4c7a821a --- /dev/null +++ b/clients/js/src/generated/accounts/config.ts @@ -0,0 +1,137 @@ +/** + * 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 { + assertAccountExists, + assertAccountsExist, + combineCodec, + decodeAccount, + fetchEncodedAccount, + fetchEncodedAccounts, + getAddressDecoder, + getAddressEncoder, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + type Account, + type Address, + type EncodedAccount, + type FetchAccountConfig, + type FetchAccountsConfig, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type MaybeAccount, + type MaybeEncodedAccount, +} from "@solana/kit"; + +/** Program configuration state. */ +export type Config = { + admin: Address; + bufferA: Address; + bufferB: Address; + bufferC: Address; + bufferD: Address; + bufferE: bigint; +}; + +export type ConfigArgs = { + admin: Address; + bufferA: Address; + bufferB: Address; + bufferC: Address; + bufferD: Address; + bufferE: number | bigint; +}; + +/** Gets the encoder for {@link ConfigArgs} account data. */ +export function getConfigEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ["admin", getAddressEncoder()], + ["bufferA", getAddressEncoder()], + ["bufferB", getAddressEncoder()], + ["bufferC", getAddressEncoder()], + ["bufferD", getAddressEncoder()], + ["bufferE", getU64Encoder()], + ]); +} + +/** Gets the decoder for {@link Config} account data. */ +export function getConfigDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["admin", getAddressDecoder()], + ["bufferA", getAddressDecoder()], + ["bufferB", getAddressDecoder()], + ["bufferC", getAddressDecoder()], + ["bufferD", getAddressDecoder()], + ["bufferE", getU64Decoder()], + ]); +} + +/** Gets the codec for {@link Config} account data. */ +export function getConfigCodec(): FixedSizeCodec { + return combineCodec(getConfigEncoder(), getConfigDecoder()); +} + +export function decodeConfig( + encodedAccount: EncodedAccount, +): Account; +export function decodeConfig( + encodedAccount: MaybeEncodedAccount, +): MaybeAccount; +export function decodeConfig( + encodedAccount: EncodedAccount | MaybeEncodedAccount, +): Account | MaybeAccount { + return decodeAccount( + encodedAccount as MaybeEncodedAccount, + getConfigDecoder(), + ); +} + +export async function fetchConfig( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchMaybeConfig(rpc, address, config); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeConfig( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchEncodedAccount(rpc, address, config); + return decodeConfig(maybeAccount); +} + +export async function fetchAllConfig( + rpc: Parameters[0], + addresses: Array
, + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchAllMaybeConfig(rpc, addresses, config); + assertAccountsExist(maybeAccounts); + return maybeAccounts; +} + +export async function fetchAllMaybeConfig( + rpc: Parameters[0], + addresses: Array
, + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); + return maybeAccounts.map((maybeAccount) => decodeConfig(maybeAccount)); +} + +export function getConfigSize(): number { + return 168; +} diff --git a/clients/js/src/generated/accounts/index.ts b/clients/js/src/generated/accounts/index.ts new file mode 100644 index 00000000..67a26442 --- /dev/null +++ b/clients/js/src/generated/accounts/index.ts @@ -0,0 +1,15 @@ +/** + * 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 "./automation"; +export * from "./board"; +export * from "./config"; +export * from "./miner"; +export * from "./round"; +export * from "./stake"; +export * from "./treasury"; diff --git a/clients/js/src/generated/accounts/miner.ts b/clients/js/src/generated/accounts/miner.ts new file mode 100644 index 00000000..746d16ce --- /dev/null +++ b/clients/js/src/generated/accounts/miner.ts @@ -0,0 +1,183 @@ +/** + * 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 { + assertAccountExists, + assertAccountsExist, + combineCodec, + decodeAccount, + fetchEncodedAccount, + fetchEncodedAccounts, + getAddressDecoder, + getAddressEncoder, + getArrayDecoder, + getArrayEncoder, + getI64Decoder, + getI64Encoder, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + type Account, + type Address, + type EncodedAccount, + type FetchAccountConfig, + type FetchAccountsConfig, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type MaybeAccount, + type MaybeEncodedAccount, +} from "@solana/kit"; +import { + getNumericDecoder, + getNumericEncoder, + type Numeric, + type NumericArgs, +} from "../types"; + +/** Tracks a miner's deployed SOL and reward balances. */ +export type Miner = { + authority: Address; + deployed: Array; + cumulative: Array; + checkpointFee: bigint; + checkpointId: bigint; + lastClaimOreAt: bigint; + lastClaimSolAt: bigint; + rewardsFactor: Numeric; + rewardsSol: bigint; + rewardsOre: bigint; + refinedOre: bigint; + roundId: bigint; + lifetimeRewardsSol: bigint; + lifetimeRewardsOre: bigint; + lifetimeDeployed: bigint; +}; + +export type MinerArgs = { + authority: Address; + deployed: Array; + cumulative: Array; + checkpointFee: number | bigint; + checkpointId: number | bigint; + lastClaimOreAt: number | bigint; + lastClaimSolAt: number | bigint; + rewardsFactor: NumericArgs; + rewardsSol: number | bigint; + rewardsOre: number | bigint; + refinedOre: number | bigint; + roundId: number | bigint; + lifetimeRewardsSol: number | bigint; + lifetimeRewardsOre: number | bigint; + lifetimeDeployed: number | bigint; +}; + +/** Gets the encoder for {@link MinerArgs} account data. */ +export function getMinerEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ["authority", getAddressEncoder()], + ["deployed", getArrayEncoder(getU64Encoder(), { size: 25 })], + ["cumulative", getArrayEncoder(getU64Encoder(), { size: 25 })], + ["checkpointFee", getU64Encoder()], + ["checkpointId", getU64Encoder()], + ["lastClaimOreAt", getI64Encoder()], + ["lastClaimSolAt", getI64Encoder()], + ["rewardsFactor", getNumericEncoder()], + ["rewardsSol", getU64Encoder()], + ["rewardsOre", getU64Encoder()], + ["refinedOre", getU64Encoder()], + ["roundId", getU64Encoder()], + ["lifetimeRewardsSol", getU64Encoder()], + ["lifetimeRewardsOre", getU64Encoder()], + ["lifetimeDeployed", getU64Encoder()], + ]); +} + +/** Gets the decoder for {@link Miner} account data. */ +export function getMinerDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["authority", getAddressDecoder()], + ["deployed", getArrayDecoder(getU64Decoder(), { size: 25 })], + ["cumulative", getArrayDecoder(getU64Decoder(), { size: 25 })], + ["checkpointFee", getU64Decoder()], + ["checkpointId", getU64Decoder()], + ["lastClaimOreAt", getI64Decoder()], + ["lastClaimSolAt", getI64Decoder()], + ["rewardsFactor", getNumericDecoder()], + ["rewardsSol", getU64Decoder()], + ["rewardsOre", getU64Decoder()], + ["refinedOre", getU64Decoder()], + ["roundId", getU64Decoder()], + ["lifetimeRewardsSol", getU64Decoder()], + ["lifetimeRewardsOre", getU64Decoder()], + ["lifetimeDeployed", getU64Decoder()], + ]); +} + +/** Gets the codec for {@link Miner} account data. */ +export function getMinerCodec(): FixedSizeCodec { + return combineCodec(getMinerEncoder(), getMinerDecoder()); +} + +export function decodeMiner( + encodedAccount: EncodedAccount, +): Account; +export function decodeMiner( + encodedAccount: MaybeEncodedAccount, +): MaybeAccount; +export function decodeMiner( + encodedAccount: EncodedAccount | MaybeEncodedAccount, +): Account | MaybeAccount { + return decodeAccount( + encodedAccount as MaybeEncodedAccount, + getMinerDecoder(), + ); +} + +export async function fetchMiner( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchMaybeMiner(rpc, address, config); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeMiner( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchEncodedAccount(rpc, address, config); + return decodeMiner(maybeAccount); +} + +export async function fetchAllMiner( + rpc: Parameters[0], + addresses: Array
, + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchAllMaybeMiner(rpc, addresses, config); + assertAccountsExist(maybeAccounts); + return maybeAccounts; +} + +export async function fetchAllMaybeMiner( + rpc: Parameters[0], + addresses: Array
, + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); + return maybeAccounts.map((maybeAccount) => decodeMiner(maybeAccount)); +} + +export function getMinerSize(): number { + return 536; +} diff --git a/clients/js/src/generated/accounts/round.ts b/clients/js/src/generated/accounts/round.ts new file mode 100644 index 00000000..a9699d6c --- /dev/null +++ b/clients/js/src/generated/accounts/round.ts @@ -0,0 +1,172 @@ +/** + * 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 { + assertAccountExists, + assertAccountsExist, + combineCodec, + decodeAccount, + fetchEncodedAccount, + fetchEncodedAccounts, + fixDecoderSize, + fixEncoderSize, + getAddressDecoder, + getAddressEncoder, + getArrayDecoder, + getArrayEncoder, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + type Account, + type Address, + type EncodedAccount, + type FetchAccountConfig, + type FetchAccountsConfig, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type MaybeAccount, + type MaybeEncodedAccount, + type ReadonlyUint8Array, +} from "@solana/kit"; + +/** State for a single mining round. */ +export type Round = { + id: bigint; + deployed: Array; + slotHash: ReadonlyUint8Array; + count: Array; + expiresAt: bigint; + motherlode: bigint; + rentPayer: Address; + topMiner: Address; + topMinerReward: bigint; + totalDeployed: bigint; + totalMiners: bigint; + totalVaulted: bigint; + totalWinnings: bigint; +}; + +export type RoundArgs = { + id: number | bigint; + deployed: Array; + slotHash: ReadonlyUint8Array; + count: Array; + expiresAt: number | bigint; + motherlode: number | bigint; + rentPayer: Address; + topMiner: Address; + topMinerReward: number | bigint; + totalDeployed: number | bigint; + totalMiners: number | bigint; + totalVaulted: number | bigint; + totalWinnings: number | bigint; +}; + +/** Gets the encoder for {@link RoundArgs} account data. */ +export function getRoundEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ["id", getU64Encoder()], + ["deployed", getArrayEncoder(getU64Encoder(), { size: 25 })], + ["slotHash", fixEncoderSize(getBytesEncoder(), 32)], + ["count", getArrayEncoder(getU64Encoder(), { size: 25 })], + ["expiresAt", getU64Encoder()], + ["motherlode", getU64Encoder()], + ["rentPayer", getAddressEncoder()], + ["topMiner", getAddressEncoder()], + ["topMinerReward", getU64Encoder()], + ["totalDeployed", getU64Encoder()], + ["totalMiners", getU64Encoder()], + ["totalVaulted", getU64Encoder()], + ["totalWinnings", getU64Encoder()], + ]); +} + +/** Gets the decoder for {@link Round} account data. */ +export function getRoundDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["id", getU64Decoder()], + ["deployed", getArrayDecoder(getU64Decoder(), { size: 25 })], + ["slotHash", fixDecoderSize(getBytesDecoder(), 32)], + ["count", getArrayDecoder(getU64Decoder(), { size: 25 })], + ["expiresAt", getU64Decoder()], + ["motherlode", getU64Decoder()], + ["rentPayer", getAddressDecoder()], + ["topMiner", getAddressDecoder()], + ["topMinerReward", getU64Decoder()], + ["totalDeployed", getU64Decoder()], + ["totalMiners", getU64Decoder()], + ["totalVaulted", getU64Decoder()], + ["totalWinnings", getU64Decoder()], + ]); +} + +/** Gets the codec for {@link Round} account data. */ +export function getRoundCodec(): FixedSizeCodec { + return combineCodec(getRoundEncoder(), getRoundDecoder()); +} + +export function decodeRound( + encodedAccount: EncodedAccount, +): Account; +export function decodeRound( + encodedAccount: MaybeEncodedAccount, +): MaybeAccount; +export function decodeRound( + encodedAccount: EncodedAccount | MaybeEncodedAccount, +): Account | MaybeAccount { + return decodeAccount( + encodedAccount as MaybeEncodedAccount, + getRoundDecoder(), + ); +} + +export async function fetchRound( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchMaybeRound(rpc, address, config); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeRound( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchEncodedAccount(rpc, address, config); + return decodeRound(maybeAccount); +} + +export async function fetchAllRound( + rpc: Parameters[0], + addresses: Array
, + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchAllMaybeRound(rpc, addresses, config); + assertAccountsExist(maybeAccounts); + return maybeAccounts; +} + +export async function fetchAllMaybeRound( + rpc: Parameters[0], + addresses: Array
, + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); + return maybeAccounts.map((maybeAccount) => decodeRound(maybeAccount)); +} + +export function getRoundSize(): number { + return 560; +} diff --git a/clients/js/src/generated/accounts/stake.ts b/clients/js/src/generated/accounts/stake.ts new file mode 100644 index 00000000..6c2fd286 --- /dev/null +++ b/clients/js/src/generated/accounts/stake.ts @@ -0,0 +1,177 @@ +/** + * 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 { + assertAccountExists, + assertAccountsExist, + combineCodec, + decodeAccount, + fetchEncodedAccount, + fetchEncodedAccounts, + getAddressDecoder, + getAddressEncoder, + getI64Decoder, + getI64Encoder, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + type Account, + type Address, + type EncodedAccount, + type FetchAccountConfig, + type FetchAccountsConfig, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type MaybeAccount, + type MaybeEncodedAccount, +} from "@solana/kit"; +import { + getNumericDecoder, + getNumericEncoder, + type Numeric, + type NumericArgs, +} from "../types"; + +/** State for a staking participant. */ +export type Stake = { + authority: Address; + balance: bigint; + bufferA: bigint; + bufferB: bigint; + bufferC: bigint; + bufferD: bigint; + bufferE: bigint; + lastClaimAt: bigint; + lastDepositAt: bigint; + lastWithdrawAt: bigint; + rewardsFactor: Numeric; + rewards: bigint; + lifetimeRewards: bigint; + bufferF: bigint; +}; + +export type StakeArgs = { + authority: Address; + balance: number | bigint; + bufferA: number | bigint; + bufferB: number | bigint; + bufferC: number | bigint; + bufferD: number | bigint; + bufferE: number | bigint; + lastClaimAt: number | bigint; + lastDepositAt: number | bigint; + lastWithdrawAt: number | bigint; + rewardsFactor: NumericArgs; + rewards: number | bigint; + lifetimeRewards: number | bigint; + bufferF: number | bigint; +}; + +/** Gets the encoder for {@link StakeArgs} account data. */ +export function getStakeEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ["authority", getAddressEncoder()], + ["balance", getU64Encoder()], + ["bufferA", getU64Encoder()], + ["bufferB", getU64Encoder()], + ["bufferC", getU64Encoder()], + ["bufferD", getU64Encoder()], + ["bufferE", getU64Encoder()], + ["lastClaimAt", getI64Encoder()], + ["lastDepositAt", getI64Encoder()], + ["lastWithdrawAt", getI64Encoder()], + ["rewardsFactor", getNumericEncoder()], + ["rewards", getU64Encoder()], + ["lifetimeRewards", getU64Encoder()], + ["bufferF", getU64Encoder()], + ]); +} + +/** Gets the decoder for {@link Stake} account data. */ +export function getStakeDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["authority", getAddressDecoder()], + ["balance", getU64Decoder()], + ["bufferA", getU64Decoder()], + ["bufferB", getU64Decoder()], + ["bufferC", getU64Decoder()], + ["bufferD", getU64Decoder()], + ["bufferE", getU64Decoder()], + ["lastClaimAt", getI64Decoder()], + ["lastDepositAt", getI64Decoder()], + ["lastWithdrawAt", getI64Decoder()], + ["rewardsFactor", getNumericDecoder()], + ["rewards", getU64Decoder()], + ["lifetimeRewards", getU64Decoder()], + ["bufferF", getU64Decoder()], + ]); +} + +/** Gets the codec for {@link Stake} account data. */ +export function getStakeCodec(): FixedSizeCodec { + return combineCodec(getStakeEncoder(), getStakeDecoder()); +} + +export function decodeStake( + encodedAccount: EncodedAccount, +): Account; +export function decodeStake( + encodedAccount: MaybeEncodedAccount, +): MaybeAccount; +export function decodeStake( + encodedAccount: EncodedAccount | MaybeEncodedAccount, +): Account | MaybeAccount { + return decodeAccount( + encodedAccount as MaybeEncodedAccount, + getStakeDecoder(), + ); +} + +export async function fetchStake( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchMaybeStake(rpc, address, config); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeStake( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchEncodedAccount(rpc, address, config); + return decodeStake(maybeAccount); +} + +export async function fetchAllStake( + rpc: Parameters[0], + addresses: Array
, + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchAllMaybeStake(rpc, addresses, config); + assertAccountsExist(maybeAccounts); + return maybeAccounts; +} + +export async function fetchAllMaybeStake( + rpc: Parameters[0], + addresses: Array
, + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); + return maybeAccounts.map((maybeAccount) => decodeStake(maybeAccount)); +} + +export function getStakeSize(): number { + return 144; +} diff --git a/clients/js/src/generated/accounts/treasury.ts b/clients/js/src/generated/accounts/treasury.ts new file mode 100644 index 00000000..5bca88f2 --- /dev/null +++ b/clients/js/src/generated/accounts/treasury.ts @@ -0,0 +1,153 @@ +/** + * 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 { + assertAccountExists, + assertAccountsExist, + combineCodec, + decodeAccount, + fetchEncodedAccount, + fetchEncodedAccounts, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + type Account, + type Address, + type EncodedAccount, + type FetchAccountConfig, + type FetchAccountsConfig, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type MaybeAccount, + type MaybeEncodedAccount, +} from "@solana/kit"; +import { + getNumericDecoder, + getNumericEncoder, + type Numeric, + type NumericArgs, +} from "../types"; + +/** Singleton treasury account tracking protocol balances. */ +export type Treasury = { + balance: bigint; + bufferA: bigint; + motherlode: bigint; + minerRewardsFactor: Numeric; + stakeRewardsFactor: Numeric; + bufferB: bigint; + totalRefined: bigint; + totalStaked: bigint; + totalUnclaimed: bigint; +}; + +export type TreasuryArgs = { + balance: number | bigint; + bufferA: number | bigint; + motherlode: number | bigint; + minerRewardsFactor: NumericArgs; + stakeRewardsFactor: NumericArgs; + bufferB: number | bigint; + totalRefined: number | bigint; + totalStaked: number | bigint; + totalUnclaimed: number | bigint; +}; + +/** Gets the encoder for {@link TreasuryArgs} account data. */ +export function getTreasuryEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ["balance", getU64Encoder()], + ["bufferA", getU64Encoder()], + ["motherlode", getU64Encoder()], + ["minerRewardsFactor", getNumericEncoder()], + ["stakeRewardsFactor", getNumericEncoder()], + ["bufferB", getU64Encoder()], + ["totalRefined", getU64Encoder()], + ["totalStaked", getU64Encoder()], + ["totalUnclaimed", getU64Encoder()], + ]); +} + +/** Gets the decoder for {@link Treasury} account data. */ +export function getTreasuryDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["balance", getU64Decoder()], + ["bufferA", getU64Decoder()], + ["motherlode", getU64Decoder()], + ["minerRewardsFactor", getNumericDecoder()], + ["stakeRewardsFactor", getNumericDecoder()], + ["bufferB", getU64Decoder()], + ["totalRefined", getU64Decoder()], + ["totalStaked", getU64Decoder()], + ["totalUnclaimed", getU64Decoder()], + ]); +} + +/** Gets the codec for {@link Treasury} account data. */ +export function getTreasuryCodec(): FixedSizeCodec { + return combineCodec(getTreasuryEncoder(), getTreasuryDecoder()); +} + +export function decodeTreasury( + encodedAccount: EncodedAccount, +): Account; +export function decodeTreasury( + encodedAccount: MaybeEncodedAccount, +): MaybeAccount; +export function decodeTreasury( + encodedAccount: EncodedAccount | MaybeEncodedAccount, +): Account | MaybeAccount { + return decodeAccount( + encodedAccount as MaybeEncodedAccount, + getTreasuryDecoder(), + ); +} + +export async function fetchTreasury( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchMaybeTreasury(rpc, address, config); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeTreasury( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchEncodedAccount(rpc, address, config); + return decodeTreasury(maybeAccount); +} + +export async function fetchAllTreasury( + rpc: Parameters[0], + addresses: Array
, + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchAllMaybeTreasury(rpc, addresses, config); + assertAccountsExist(maybeAccounts); + return maybeAccounts; +} + +export async function fetchAllMaybeTreasury( + rpc: Parameters[0], + addresses: Array
, + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); + return maybeAccounts.map((maybeAccount) => decodeTreasury(maybeAccount)); +} + +export function getTreasurySize(): number { + return 88; +} diff --git a/clients/js/src/generated/errors/index.ts b/clients/js/src/generated/errors/index.ts new file mode 100644 index 00000000..ef7aaf9e --- /dev/null +++ b/clients/js/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 "./ore"; diff --git a/clients/js/src/generated/errors/ore.ts b/clients/js/src/generated/errors/ore.ts new file mode 100644 index 00000000..5b470cf9 --- /dev/null +++ b/clients/js/src/generated/errors/ore.ts @@ -0,0 +1,56 @@ +/** + * 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 { + isProgramError, + type Address, + type SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM, + type SolanaError, +} from "@solana/kit"; +import { ORE_PROGRAM_ADDRESS } from "../programs"; + +/** AmountTooSmall: Amount too small */ +export const ORE_ERROR__AMOUNT_TOO_SMALL = 0x0; // 0 +/** NotAuthorized: Not authorized */ +export const ORE_ERROR__NOT_AUTHORIZED = 0x1; // 1 + +export type OreError = + | typeof ORE_ERROR__AMOUNT_TOO_SMALL + | typeof ORE_ERROR__NOT_AUTHORIZED; + +let oreErrorMessages: Record | undefined; +if (process.env.NODE_ENV !== "production") { + oreErrorMessages = { + [ORE_ERROR__AMOUNT_TOO_SMALL]: `Amount too small`, + [ORE_ERROR__NOT_AUTHORIZED]: `Not authorized`, + }; +} + +export function getOreErrorMessage(code: OreError): string { + if (process.env.NODE_ENV !== "production") { + return (oreErrorMessages as Record)[code]; + } + + return "Error message not available in production bundles."; +} + +export function isOreError( + error: unknown, + transactionMessage: { + instructions: Record; + }, + code?: TProgramErrorCode, +): error is SolanaError & + Readonly<{ context: Readonly<{ code: TProgramErrorCode }> }> { + return isProgramError( + error, + transactionMessage, + ORE_PROGRAM_ADDRESS, + code, + ); +} diff --git a/clients/js/src/generated/index.ts b/clients/js/src/generated/index.ts new file mode 100644 index 00000000..3113fee4 --- /dev/null +++ b/clients/js/src/generated/index.ts @@ -0,0 +1,13 @@ +/** + * 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"; +export * from "./errors"; +export * from "./instructions"; +export * from "./programs"; +export * from "./types"; diff --git a/clients/js/src/generated/instructions/automate.ts b/clients/js/src/generated/instructions/automate.ts new file mode 100644 index 00000000..9c755c2b --- /dev/null +++ b/clients/js/src/generated/instructions/automate.ts @@ -0,0 +1,262 @@ +/** + * 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 { + combineCodec, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, + type WritableSignerAccount, +} from "@solana/kit"; +import { ORE_PROGRAM_ADDRESS } from "../programs"; +import { getAccountMetaFactory, type ResolvedAccount } from "../shared"; + +export const AUTOMATE_DISCRIMINATOR = 0; + +export function getAutomateDiscriminatorBytes() { + return getU8Encoder().encode(AUTOMATE_DISCRIMINATOR); +} + +export type AutomateInstruction< + TProgram extends string = typeof ORE_PROGRAM_ADDRESS, + TAccountSigner extends string | AccountMeta = string, + TAccountAutomation extends string | AccountMeta = string, + TAccountExecutor extends string | AccountMeta = string, + TAccountMiner extends string | AccountMeta = string, + TAccountSystemProgram extends string | AccountMeta = + "11111111111111111111111111111111", + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountSigner extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountSigner, + TAccountAutomation extends string + ? WritableAccount + : TAccountAutomation, + TAccountExecutor extends string + ? ReadonlyAccount + : TAccountExecutor, + TAccountMiner extends string + ? WritableAccount + : TAccountMiner, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + ...TRemainingAccounts, + ] + >; + +export type AutomateInstructionData = { + discriminator: number; + amount: bigint; + deposit: bigint; + fee: bigint; + mask: bigint; + strategy: number; +}; + +export type AutomateInstructionDataArgs = { + amount: number | bigint; + deposit: number | bigint; + fee: number | bigint; + mask: number | bigint; + strategy: number; +}; + +export function getAutomateInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", getU8Encoder()], + ["amount", getU64Encoder()], + ["deposit", getU64Encoder()], + ["fee", getU64Encoder()], + ["mask", getU64Encoder()], + ["strategy", getU8Encoder()], + ]), + (value) => ({ ...value, discriminator: AUTOMATE_DISCRIMINATOR }), + ); +} + +export function getAutomateInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", getU8Decoder()], + ["amount", getU64Decoder()], + ["deposit", getU64Decoder()], + ["fee", getU64Decoder()], + ["mask", getU64Decoder()], + ["strategy", getU8Decoder()], + ]); +} + +export function getAutomateInstructionDataCodec(): FixedSizeCodec< + AutomateInstructionDataArgs, + AutomateInstructionData +> { + return combineCodec( + getAutomateInstructionDataEncoder(), + getAutomateInstructionDataDecoder(), + ); +} + +export type AutomateInput< + TAccountSigner extends string = string, + TAccountAutomation extends string = string, + TAccountExecutor extends string = string, + TAccountMiner extends string = string, + TAccountSystemProgram extends string = string, +> = { + signer: TransactionSigner; + automation: Address; + executor: Address; + miner: Address; + systemProgram?: Address; + amount: AutomateInstructionDataArgs["amount"]; + deposit: AutomateInstructionDataArgs["deposit"]; + fee: AutomateInstructionDataArgs["fee"]; + mask: AutomateInstructionDataArgs["mask"]; + strategy: AutomateInstructionDataArgs["strategy"]; +}; + +export function getAutomateInstruction< + TAccountSigner extends string, + TAccountAutomation extends string, + TAccountExecutor extends string, + TAccountMiner extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof ORE_PROGRAM_ADDRESS, +>( + input: AutomateInput< + TAccountSigner, + TAccountAutomation, + TAccountExecutor, + TAccountMiner, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress }, +): AutomateInstruction< + TProgramAddress, + TAccountSigner, + TAccountAutomation, + TAccountExecutor, + TAccountMiner, + TAccountSystemProgram +> { + // Program address. + const programAddress = config?.programAddress ?? ORE_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + signer: { value: input.signer ?? null, isWritable: true }, + automation: { value: input.automation ?? null, isWritable: true }, + executor: { value: input.executor ?? null, isWritable: false }, + miner: { value: input.miner ?? null, isWritable: true }, + 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.signer), + getAccountMeta(accounts.automation), + getAccountMeta(accounts.executor), + getAccountMeta(accounts.miner), + getAccountMeta(accounts.systemProgram), + ], + data: getAutomateInstructionDataEncoder().encode( + args as AutomateInstructionDataArgs, + ), + programAddress, + } as AutomateInstruction< + TProgramAddress, + TAccountSigner, + TAccountAutomation, + TAccountExecutor, + TAccountMiner, + TAccountSystemProgram + >); +} + +export type ParsedAutomateInstruction< + TProgram extends string = typeof ORE_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + signer: TAccountMetas[0]; + automation: TAccountMetas[1]; + executor: TAccountMetas[2]; + miner: TAccountMetas[3]; + systemProgram: TAccountMetas[4]; + }; + data: AutomateInstructionData; +}; + +export function parseAutomateInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedAutomateInstruction { + 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: { + signer: getNextAccount(), + automation: getNextAccount(), + executor: getNextAccount(), + miner: getNextAccount(), + systemProgram: getNextAccount(), + }, + data: getAutomateInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/js/src/generated/instructions/bury.ts b/clients/js/src/generated/instructions/bury.ts new file mode 100644 index 00000000..81fbd366 --- /dev/null +++ b/clients/js/src/generated/instructions/bury.ts @@ -0,0 +1,279 @@ +/** + * 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 { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyAccount, + type ReadonlySignerAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, +} from "@solana/kit"; +import { ORE_PROGRAM_ADDRESS } from "../programs"; +import { getAccountMetaFactory, type ResolvedAccount } from "../shared"; + +export const BURY_DISCRIMINATOR = 13; + +export function getBuryDiscriminatorBytes() { + return getU8Encoder().encode(BURY_DISCRIMINATOR); +} + +export type BuryInstruction< + TProgram extends string = typeof ORE_PROGRAM_ADDRESS, + TAccountSigner extends string | AccountMeta = string, + TAccountBoard extends string | AccountMeta = string, + TAccountConfig extends string | AccountMeta = string, + TAccountMint extends string | AccountMeta = string, + TAccountTreasury extends string | AccountMeta = string, + TAccountTreasuryOre extends string | AccountMeta = string, + TAccountTreasurySol extends string | AccountMeta = string, + TAccountTokenProgram extends string | AccountMeta = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + TAccountOreProgram extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountSigner extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountSigner, + TAccountBoard extends string + ? WritableAccount + : TAccountBoard, + TAccountConfig extends string + ? ReadonlyAccount + : TAccountConfig, + TAccountMint extends string + ? ReadonlyAccount + : TAccountMint, + TAccountTreasury extends string + ? WritableAccount + : TAccountTreasury, + TAccountTreasuryOre extends string + ? WritableAccount + : TAccountTreasuryOre, + TAccountTreasurySol extends string + ? WritableAccount + : TAccountTreasurySol, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + TAccountOreProgram extends string + ? ReadonlyAccount + : TAccountOreProgram, + ...TRemainingAccounts, + ] + >; + +export type BuryInstructionData = { discriminator: number }; + +export type BuryInstructionDataArgs = {}; + +export function getBuryInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", getU8Encoder()]]), + (value) => ({ ...value, discriminator: BURY_DISCRIMINATOR }), + ); +} + +export function getBuryInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([["discriminator", getU8Decoder()]]); +} + +export function getBuryInstructionDataCodec(): FixedSizeCodec< + BuryInstructionDataArgs, + BuryInstructionData +> { + return combineCodec( + getBuryInstructionDataEncoder(), + getBuryInstructionDataDecoder(), + ); +} + +export type BuryInput< + TAccountSigner extends string = string, + TAccountBoard extends string = string, + TAccountConfig extends string = string, + TAccountMint extends string = string, + TAccountTreasury extends string = string, + TAccountTreasuryOre extends string = string, + TAccountTreasurySol extends string = string, + TAccountTokenProgram extends string = string, + TAccountOreProgram extends string = string, +> = { + signer: TransactionSigner; + board: Address; + config: Address; + mint: Address; + treasury: Address; + treasuryOre: Address; + treasurySol: Address; + tokenProgram?: Address; + oreProgram: Address; +}; + +export function getBuryInstruction< + TAccountSigner extends string, + TAccountBoard extends string, + TAccountConfig extends string, + TAccountMint extends string, + TAccountTreasury extends string, + TAccountTreasuryOre extends string, + TAccountTreasurySol extends string, + TAccountTokenProgram extends string, + TAccountOreProgram extends string, + TProgramAddress extends Address = typeof ORE_PROGRAM_ADDRESS, +>( + input: BuryInput< + TAccountSigner, + TAccountBoard, + TAccountConfig, + TAccountMint, + TAccountTreasury, + TAccountTreasuryOre, + TAccountTreasurySol, + TAccountTokenProgram, + TAccountOreProgram + >, + config?: { programAddress?: TProgramAddress }, +): BuryInstruction< + TProgramAddress, + TAccountSigner, + TAccountBoard, + TAccountConfig, + TAccountMint, + TAccountTreasury, + TAccountTreasuryOre, + TAccountTreasurySol, + TAccountTokenProgram, + TAccountOreProgram +> { + // Program address. + const programAddress = config?.programAddress ?? ORE_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + signer: { value: input.signer ?? null, isWritable: false }, + board: { value: input.board ?? null, isWritable: true }, + config: { value: input.config ?? null, isWritable: false }, + mint: { value: input.mint ?? null, isWritable: false }, + treasury: { value: input.treasury ?? null, isWritable: true }, + treasuryOre: { value: input.treasuryOre ?? null, isWritable: true }, + treasurySol: { value: input.treasurySol ?? null, isWritable: true }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + oreProgram: { value: input.oreProgram ?? 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.signer), + getAccountMeta(accounts.board), + getAccountMeta(accounts.config), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.treasury), + getAccountMeta(accounts.treasuryOre), + getAccountMeta(accounts.treasurySol), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.oreProgram), + ], + data: getBuryInstructionDataEncoder().encode({}), + programAddress, + } as BuryInstruction< + TProgramAddress, + TAccountSigner, + TAccountBoard, + TAccountConfig, + TAccountMint, + TAccountTreasury, + TAccountTreasuryOre, + TAccountTreasurySol, + TAccountTokenProgram, + TAccountOreProgram + >); +} + +export type ParsedBuryInstruction< + TProgram extends string = typeof ORE_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + signer: TAccountMetas[0]; + board: TAccountMetas[1]; + config: TAccountMetas[2]; + mint: TAccountMetas[3]; + treasury: TAccountMetas[4]; + treasuryOre: TAccountMetas[5]; + treasurySol: TAccountMetas[6]; + tokenProgram: TAccountMetas[7]; + oreProgram: TAccountMetas[8]; + }; + data: BuryInstructionData; +}; + +export function parseBuryInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedBuryInstruction { + if (instruction.accounts.length < 9) { + // 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: { + signer: getNextAccount(), + board: getNextAccount(), + config: getNextAccount(), + mint: getNextAccount(), + treasury: getNextAccount(), + treasuryOre: getNextAccount(), + treasurySol: getNextAccount(), + tokenProgram: getNextAccount(), + oreProgram: getNextAccount(), + }, + data: getBuryInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/js/src/generated/instructions/checkpoint.ts b/clients/js/src/generated/instructions/checkpoint.ts new file mode 100644 index 00000000..47525373 --- /dev/null +++ b/clients/js/src/generated/instructions/checkpoint.ts @@ -0,0 +1,237 @@ +/** + * 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 { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, + type WritableSignerAccount, +} from "@solana/kit"; +import { ORE_PROGRAM_ADDRESS } from "../programs"; +import { getAccountMetaFactory, type ResolvedAccount } from "../shared"; + +export const CHECKPOINT_DISCRIMINATOR = 2; + +export function getCheckpointDiscriminatorBytes() { + return getU8Encoder().encode(CHECKPOINT_DISCRIMINATOR); +} + +export type CheckpointInstruction< + TProgram extends string = typeof ORE_PROGRAM_ADDRESS, + TAccountSigner extends string | AccountMeta = string, + TAccountBoard extends string | AccountMeta = string, + TAccountMiner extends string | AccountMeta = string, + TAccountRound extends string | AccountMeta = string, + TAccountTreasury extends string | AccountMeta = string, + TAccountSystemProgram extends string | AccountMeta = + "11111111111111111111111111111111", + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountSigner extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountSigner, + TAccountBoard extends string + ? ReadonlyAccount + : TAccountBoard, + TAccountMiner extends string + ? WritableAccount + : TAccountMiner, + TAccountRound extends string + ? WritableAccount + : TAccountRound, + TAccountTreasury extends string + ? WritableAccount + : TAccountTreasury, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + ...TRemainingAccounts, + ] + >; + +export type CheckpointInstructionData = { discriminator: number }; + +export type CheckpointInstructionDataArgs = {}; + +export function getCheckpointInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", getU8Encoder()]]), + (value) => ({ ...value, discriminator: CHECKPOINT_DISCRIMINATOR }), + ); +} + +export function getCheckpointInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([["discriminator", getU8Decoder()]]); +} + +export function getCheckpointInstructionDataCodec(): FixedSizeCodec< + CheckpointInstructionDataArgs, + CheckpointInstructionData +> { + return combineCodec( + getCheckpointInstructionDataEncoder(), + getCheckpointInstructionDataDecoder(), + ); +} + +export type CheckpointInput< + TAccountSigner extends string = string, + TAccountBoard extends string = string, + TAccountMiner extends string = string, + TAccountRound extends string = string, + TAccountTreasury extends string = string, + TAccountSystemProgram extends string = string, +> = { + signer: TransactionSigner; + board: Address; + miner: Address; + round: Address; + treasury: Address; + systemProgram?: Address; +}; + +export function getCheckpointInstruction< + TAccountSigner extends string, + TAccountBoard extends string, + TAccountMiner extends string, + TAccountRound extends string, + TAccountTreasury extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof ORE_PROGRAM_ADDRESS, +>( + input: CheckpointInput< + TAccountSigner, + TAccountBoard, + TAccountMiner, + TAccountRound, + TAccountTreasury, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress }, +): CheckpointInstruction< + TProgramAddress, + TAccountSigner, + TAccountBoard, + TAccountMiner, + TAccountRound, + TAccountTreasury, + TAccountSystemProgram +> { + // Program address. + const programAddress = config?.programAddress ?? ORE_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + signer: { value: input.signer ?? null, isWritable: true }, + board: { value: input.board ?? null, isWritable: false }, + miner: { value: input.miner ?? null, isWritable: true }, + round: { value: input.round ?? null, isWritable: true }, + treasury: { value: input.treasury ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // 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.signer), + getAccountMeta(accounts.board), + getAccountMeta(accounts.miner), + getAccountMeta(accounts.round), + getAccountMeta(accounts.treasury), + getAccountMeta(accounts.systemProgram), + ], + data: getCheckpointInstructionDataEncoder().encode({}), + programAddress, + } as CheckpointInstruction< + TProgramAddress, + TAccountSigner, + TAccountBoard, + TAccountMiner, + TAccountRound, + TAccountTreasury, + TAccountSystemProgram + >); +} + +export type ParsedCheckpointInstruction< + TProgram extends string = typeof ORE_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + signer: TAccountMetas[0]; + board: TAccountMetas[1]; + miner: TAccountMetas[2]; + round: TAccountMetas[3]; + treasury: TAccountMetas[4]; + systemProgram: TAccountMetas[5]; + }; + data: CheckpointInstructionData; +}; + +export function parseCheckpointInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedCheckpointInstruction { + if (instruction.accounts.length < 6) { + // 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: { + signer: getNextAccount(), + board: getNextAccount(), + miner: getNextAccount(), + round: getNextAccount(), + treasury: getNextAccount(), + systemProgram: getNextAccount(), + }, + data: getCheckpointInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/js/src/generated/instructions/claimOre.ts b/clients/js/src/generated/instructions/claimOre.ts new file mode 100644 index 00000000..3045a109 --- /dev/null +++ b/clients/js/src/generated/instructions/claimOre.ts @@ -0,0 +1,287 @@ +/** + * 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 { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, + type WritableSignerAccount, +} from "@solana/kit"; +import { ORE_PROGRAM_ADDRESS } from "../programs"; +import { getAccountMetaFactory, type ResolvedAccount } from "../shared"; + +export const CLAIM_ORE_DISCRIMINATOR = 4; + +export function getClaimOreDiscriminatorBytes() { + return getU8Encoder().encode(CLAIM_ORE_DISCRIMINATOR); +} + +export type ClaimOreInstruction< + TProgram extends string = typeof ORE_PROGRAM_ADDRESS, + TAccountSigner extends string | AccountMeta = string, + TAccountMiner extends string | AccountMeta = string, + TAccountMint extends string | AccountMeta = string, + TAccountRecipient extends string | AccountMeta = string, + TAccountTreasury extends string | AccountMeta = string, + TAccountTreasuryTokens extends string | AccountMeta = string, + TAccountSystemProgram extends string | AccountMeta = + "11111111111111111111111111111111", + TAccountTokenProgram extends string | AccountMeta = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + TAccountAssociatedTokenProgram extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountSigner extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountSigner, + TAccountMiner extends string + ? WritableAccount + : TAccountMiner, + TAccountMint extends string + ? ReadonlyAccount + : TAccountMint, + TAccountRecipient extends string + ? WritableAccount + : TAccountRecipient, + TAccountTreasury extends string + ? WritableAccount + : TAccountTreasury, + TAccountTreasuryTokens extends string + ? WritableAccount + : TAccountTreasuryTokens, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + TAccountAssociatedTokenProgram extends string + ? ReadonlyAccount + : TAccountAssociatedTokenProgram, + ...TRemainingAccounts, + ] + >; + +export type ClaimOreInstructionData = { discriminator: number }; + +export type ClaimOreInstructionDataArgs = {}; + +export function getClaimOreInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", getU8Encoder()]]), + (value) => ({ ...value, discriminator: CLAIM_ORE_DISCRIMINATOR }), + ); +} + +export function getClaimOreInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([["discriminator", getU8Decoder()]]); +} + +export function getClaimOreInstructionDataCodec(): FixedSizeCodec< + ClaimOreInstructionDataArgs, + ClaimOreInstructionData +> { + return combineCodec( + getClaimOreInstructionDataEncoder(), + getClaimOreInstructionDataDecoder(), + ); +} + +export type ClaimOreInput< + TAccountSigner extends string = string, + TAccountMiner extends string = string, + TAccountMint extends string = string, + TAccountRecipient extends string = string, + TAccountTreasury extends string = string, + TAccountTreasuryTokens extends string = string, + TAccountSystemProgram extends string = string, + TAccountTokenProgram extends string = string, + TAccountAssociatedTokenProgram extends string = string, +> = { + signer: TransactionSigner; + miner: Address; + mint: Address; + recipient: Address; + treasury: Address; + treasuryTokens: Address; + systemProgram?: Address; + tokenProgram?: Address; + associatedTokenProgram: Address; +}; + +export function getClaimOreInstruction< + TAccountSigner extends string, + TAccountMiner extends string, + TAccountMint extends string, + TAccountRecipient extends string, + TAccountTreasury extends string, + TAccountTreasuryTokens extends string, + TAccountSystemProgram extends string, + TAccountTokenProgram extends string, + TAccountAssociatedTokenProgram extends string, + TProgramAddress extends Address = typeof ORE_PROGRAM_ADDRESS, +>( + input: ClaimOreInput< + TAccountSigner, + TAccountMiner, + TAccountMint, + TAccountRecipient, + TAccountTreasury, + TAccountTreasuryTokens, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountAssociatedTokenProgram + >, + config?: { programAddress?: TProgramAddress }, +): ClaimOreInstruction< + TProgramAddress, + TAccountSigner, + TAccountMiner, + TAccountMint, + TAccountRecipient, + TAccountTreasury, + TAccountTreasuryTokens, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountAssociatedTokenProgram +> { + // Program address. + const programAddress = config?.programAddress ?? ORE_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + signer: { value: input.signer ?? null, isWritable: true }, + miner: { value: input.miner ?? null, isWritable: true }, + mint: { value: input.mint ?? null, isWritable: false }, + recipient: { value: input.recipient ?? null, isWritable: true }, + treasury: { value: input.treasury ?? null, isWritable: true }, + treasuryTokens: { value: input.treasuryTokens ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + associatedTokenProgram: { + value: input.associatedTokenProgram ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // 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.signer), + getAccountMeta(accounts.miner), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.recipient), + getAccountMeta(accounts.treasury), + getAccountMeta(accounts.treasuryTokens), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.associatedTokenProgram), + ], + data: getClaimOreInstructionDataEncoder().encode({}), + programAddress, + } as ClaimOreInstruction< + TProgramAddress, + TAccountSigner, + TAccountMiner, + TAccountMint, + TAccountRecipient, + TAccountTreasury, + TAccountTreasuryTokens, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountAssociatedTokenProgram + >); +} + +export type ParsedClaimOreInstruction< + TProgram extends string = typeof ORE_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + signer: TAccountMetas[0]; + miner: TAccountMetas[1]; + mint: TAccountMetas[2]; + recipient: TAccountMetas[3]; + treasury: TAccountMetas[4]; + treasuryTokens: TAccountMetas[5]; + systemProgram: TAccountMetas[6]; + tokenProgram: TAccountMetas[7]; + associatedTokenProgram: TAccountMetas[8]; + }; + data: ClaimOreInstructionData; +}; + +export function parseClaimOreInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedClaimOreInstruction { + if (instruction.accounts.length < 9) { + // 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: { + signer: getNextAccount(), + miner: getNextAccount(), + mint: getNextAccount(), + recipient: getNextAccount(), + treasury: getNextAccount(), + treasuryTokens: getNextAccount(), + systemProgram: getNextAccount(), + tokenProgram: getNextAccount(), + associatedTokenProgram: getNextAccount(), + }, + data: getClaimOreInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/js/src/generated/instructions/claimSol.ts b/clients/js/src/generated/instructions/claimSol.ts new file mode 100644 index 00000000..b95f8f92 --- /dev/null +++ b/clients/js/src/generated/instructions/claimSol.ts @@ -0,0 +1,191 @@ +/** + * 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 { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, + type WritableSignerAccount, +} from "@solana/kit"; +import { ORE_PROGRAM_ADDRESS } from "../programs"; +import { getAccountMetaFactory, type ResolvedAccount } from "../shared"; + +export const CLAIM_SOL_DISCRIMINATOR = 3; + +export function getClaimSolDiscriminatorBytes() { + return getU8Encoder().encode(CLAIM_SOL_DISCRIMINATOR); +} + +export type ClaimSolInstruction< + TProgram extends string = typeof ORE_PROGRAM_ADDRESS, + TAccountSigner extends string | AccountMeta = string, + TAccountMiner extends string | AccountMeta = string, + TAccountSystemProgram extends string | AccountMeta = + "11111111111111111111111111111111", + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountSigner extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountSigner, + TAccountMiner extends string + ? WritableAccount + : TAccountMiner, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + ...TRemainingAccounts, + ] + >; + +export type ClaimSolInstructionData = { discriminator: number }; + +export type ClaimSolInstructionDataArgs = {}; + +export function getClaimSolInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", getU8Encoder()]]), + (value) => ({ ...value, discriminator: CLAIM_SOL_DISCRIMINATOR }), + ); +} + +export function getClaimSolInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([["discriminator", getU8Decoder()]]); +} + +export function getClaimSolInstructionDataCodec(): FixedSizeCodec< + ClaimSolInstructionDataArgs, + ClaimSolInstructionData +> { + return combineCodec( + getClaimSolInstructionDataEncoder(), + getClaimSolInstructionDataDecoder(), + ); +} + +export type ClaimSolInput< + TAccountSigner extends string = string, + TAccountMiner extends string = string, + TAccountSystemProgram extends string = string, +> = { + signer: TransactionSigner; + miner: Address; + systemProgram?: Address; +}; + +export function getClaimSolInstruction< + TAccountSigner extends string, + TAccountMiner extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof ORE_PROGRAM_ADDRESS, +>( + input: ClaimSolInput, + config?: { programAddress?: TProgramAddress }, +): ClaimSolInstruction< + TProgramAddress, + TAccountSigner, + TAccountMiner, + TAccountSystemProgram +> { + // Program address. + const programAddress = config?.programAddress ?? ORE_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + signer: { value: input.signer ?? null, isWritable: true }, + miner: { value: input.miner ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // 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.signer), + getAccountMeta(accounts.miner), + getAccountMeta(accounts.systemProgram), + ], + data: getClaimSolInstructionDataEncoder().encode({}), + programAddress, + } as ClaimSolInstruction< + TProgramAddress, + TAccountSigner, + TAccountMiner, + TAccountSystemProgram + >); +} + +export type ParsedClaimSolInstruction< + TProgram extends string = typeof ORE_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + signer: TAccountMetas[0]; + miner: TAccountMetas[1]; + systemProgram: TAccountMetas[2]; + }; + data: ClaimSolInstructionData; +}; + +export function parseClaimSolInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedClaimSolInstruction { + 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: { + signer: getNextAccount(), + miner: getNextAccount(), + systemProgram: getNextAccount(), + }, + data: getClaimSolInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/js/src/generated/instructions/claimYield.ts b/clients/js/src/generated/instructions/claimYield.ts new file mode 100644 index 00000000..7f7b6520 --- /dev/null +++ b/clients/js/src/generated/instructions/claimYield.ts @@ -0,0 +1,304 @@ +/** + * 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 { + combineCodec, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, + type WritableSignerAccount, +} from "@solana/kit"; +import { ORE_PROGRAM_ADDRESS } from "../programs"; +import { getAccountMetaFactory, type ResolvedAccount } from "../shared"; + +export const CLAIM_YIELD_DISCRIMINATOR = 12; + +export function getClaimYieldDiscriminatorBytes() { + return getU8Encoder().encode(CLAIM_YIELD_DISCRIMINATOR); +} + +export type ClaimYieldInstruction< + TProgram extends string = typeof ORE_PROGRAM_ADDRESS, + TAccountSigner extends string | AccountMeta = string, + TAccountMint extends string | AccountMeta = string, + TAccountRecipient extends string | AccountMeta = string, + TAccountStake extends string | AccountMeta = string, + TAccountTreasury extends string | AccountMeta = string, + TAccountTreasuryTokens extends string | AccountMeta = string, + TAccountSystemProgram extends string | AccountMeta = + "11111111111111111111111111111111", + TAccountTokenProgram extends string | AccountMeta = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + TAccountAssociatedTokenProgram extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountSigner extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountSigner, + TAccountMint extends string + ? ReadonlyAccount + : TAccountMint, + TAccountRecipient extends string + ? WritableAccount + : TAccountRecipient, + TAccountStake extends string + ? WritableAccount + : TAccountStake, + TAccountTreasury extends string + ? WritableAccount + : TAccountTreasury, + TAccountTreasuryTokens extends string + ? WritableAccount + : TAccountTreasuryTokens, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + TAccountAssociatedTokenProgram extends string + ? ReadonlyAccount + : TAccountAssociatedTokenProgram, + ...TRemainingAccounts, + ] + >; + +export type ClaimYieldInstructionData = { + discriminator: number; + amount: bigint; +}; + +export type ClaimYieldInstructionDataArgs = { amount: number | bigint }; + +export function getClaimYieldInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", getU8Encoder()], + ["amount", getU64Encoder()], + ]), + (value) => ({ ...value, discriminator: CLAIM_YIELD_DISCRIMINATOR }), + ); +} + +export function getClaimYieldInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", getU8Decoder()], + ["amount", getU64Decoder()], + ]); +} + +export function getClaimYieldInstructionDataCodec(): FixedSizeCodec< + ClaimYieldInstructionDataArgs, + ClaimYieldInstructionData +> { + return combineCodec( + getClaimYieldInstructionDataEncoder(), + getClaimYieldInstructionDataDecoder(), + ); +} + +export type ClaimYieldInput< + TAccountSigner extends string = string, + TAccountMint extends string = string, + TAccountRecipient extends string = string, + TAccountStake extends string = string, + TAccountTreasury extends string = string, + TAccountTreasuryTokens extends string = string, + TAccountSystemProgram extends string = string, + TAccountTokenProgram extends string = string, + TAccountAssociatedTokenProgram extends string = string, +> = { + signer: TransactionSigner; + mint: Address; + recipient: Address; + stake: Address; + treasury: Address; + treasuryTokens: Address; + systemProgram?: Address; + tokenProgram?: Address; + associatedTokenProgram: Address; + amount: ClaimYieldInstructionDataArgs["amount"]; +}; + +export function getClaimYieldInstruction< + TAccountSigner extends string, + TAccountMint extends string, + TAccountRecipient extends string, + TAccountStake extends string, + TAccountTreasury extends string, + TAccountTreasuryTokens extends string, + TAccountSystemProgram extends string, + TAccountTokenProgram extends string, + TAccountAssociatedTokenProgram extends string, + TProgramAddress extends Address = typeof ORE_PROGRAM_ADDRESS, +>( + input: ClaimYieldInput< + TAccountSigner, + TAccountMint, + TAccountRecipient, + TAccountStake, + TAccountTreasury, + TAccountTreasuryTokens, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountAssociatedTokenProgram + >, + config?: { programAddress?: TProgramAddress }, +): ClaimYieldInstruction< + TProgramAddress, + TAccountSigner, + TAccountMint, + TAccountRecipient, + TAccountStake, + TAccountTreasury, + TAccountTreasuryTokens, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountAssociatedTokenProgram +> { + // Program address. + const programAddress = config?.programAddress ?? ORE_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + signer: { value: input.signer ?? null, isWritable: true }, + mint: { value: input.mint ?? null, isWritable: false }, + recipient: { value: input.recipient ?? null, isWritable: true }, + stake: { value: input.stake ?? null, isWritable: true }, + treasury: { value: input.treasury ?? null, isWritable: true }, + treasuryTokens: { value: input.treasuryTokens ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + associatedTokenProgram: { + value: input.associatedTokenProgram ?? 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.signer), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.recipient), + getAccountMeta(accounts.stake), + getAccountMeta(accounts.treasury), + getAccountMeta(accounts.treasuryTokens), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.associatedTokenProgram), + ], + data: getClaimYieldInstructionDataEncoder().encode( + args as ClaimYieldInstructionDataArgs, + ), + programAddress, + } as ClaimYieldInstruction< + TProgramAddress, + TAccountSigner, + TAccountMint, + TAccountRecipient, + TAccountStake, + TAccountTreasury, + TAccountTreasuryTokens, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountAssociatedTokenProgram + >); +} + +export type ParsedClaimYieldInstruction< + TProgram extends string = typeof ORE_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + signer: TAccountMetas[0]; + mint: TAccountMetas[1]; + recipient: TAccountMetas[2]; + stake: TAccountMetas[3]; + treasury: TAccountMetas[4]; + treasuryTokens: TAccountMetas[5]; + systemProgram: TAccountMetas[6]; + tokenProgram: TAccountMetas[7]; + associatedTokenProgram: TAccountMetas[8]; + }; + data: ClaimYieldInstructionData; +}; + +export function parseClaimYieldInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedClaimYieldInstruction { + if (instruction.accounts.length < 9) { + // 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: { + signer: getNextAccount(), + mint: getNextAccount(), + recipient: getNextAccount(), + stake: getNextAccount(), + treasury: getNextAccount(), + treasuryTokens: getNextAccount(), + systemProgram: getNextAccount(), + tokenProgram: getNextAccount(), + associatedTokenProgram: getNextAccount(), + }, + data: getClaimYieldInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/js/src/generated/instructions/close.ts b/clients/js/src/generated/instructions/close.ts new file mode 100644 index 00000000..3b3e30c2 --- /dev/null +++ b/clients/js/src/generated/instructions/close.ts @@ -0,0 +1,237 @@ +/** + * 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 { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyAccount, + type ReadonlySignerAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, +} from "@solana/kit"; +import { ORE_PROGRAM_ADDRESS } from "../programs"; +import { getAccountMetaFactory, type ResolvedAccount } from "../shared"; + +export const CLOSE_DISCRIMINATOR = 5; + +export function getCloseDiscriminatorBytes() { + return getU8Encoder().encode(CLOSE_DISCRIMINATOR); +} + +export type CloseInstruction< + TProgram extends string = typeof ORE_PROGRAM_ADDRESS, + TAccountSigner extends string | AccountMeta = string, + TAccountBoard extends string | AccountMeta = string, + TAccountRentPayer extends string | AccountMeta = string, + TAccountRound extends string | AccountMeta = string, + TAccountTreasury extends string | AccountMeta = string, + TAccountSystemProgram extends string | AccountMeta = + "11111111111111111111111111111111", + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountSigner extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountSigner, + TAccountBoard extends string + ? WritableAccount + : TAccountBoard, + TAccountRentPayer extends string + ? WritableAccount + : TAccountRentPayer, + TAccountRound extends string + ? WritableAccount + : TAccountRound, + TAccountTreasury extends string + ? WritableAccount + : TAccountTreasury, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + ...TRemainingAccounts, + ] + >; + +export type CloseInstructionData = { discriminator: number }; + +export type CloseInstructionDataArgs = {}; + +export function getCloseInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", getU8Encoder()]]), + (value) => ({ ...value, discriminator: CLOSE_DISCRIMINATOR }), + ); +} + +export function getCloseInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([["discriminator", getU8Decoder()]]); +} + +export function getCloseInstructionDataCodec(): FixedSizeCodec< + CloseInstructionDataArgs, + CloseInstructionData +> { + return combineCodec( + getCloseInstructionDataEncoder(), + getCloseInstructionDataDecoder(), + ); +} + +export type CloseInput< + TAccountSigner extends string = string, + TAccountBoard extends string = string, + TAccountRentPayer extends string = string, + TAccountRound extends string = string, + TAccountTreasury extends string = string, + TAccountSystemProgram extends string = string, +> = { + signer: TransactionSigner; + board: Address; + rentPayer: Address; + round: Address; + treasury: Address; + systemProgram?: Address; +}; + +export function getCloseInstruction< + TAccountSigner extends string, + TAccountBoard extends string, + TAccountRentPayer extends string, + TAccountRound extends string, + TAccountTreasury extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof ORE_PROGRAM_ADDRESS, +>( + input: CloseInput< + TAccountSigner, + TAccountBoard, + TAccountRentPayer, + TAccountRound, + TAccountTreasury, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress }, +): CloseInstruction< + TProgramAddress, + TAccountSigner, + TAccountBoard, + TAccountRentPayer, + TAccountRound, + TAccountTreasury, + TAccountSystemProgram +> { + // Program address. + const programAddress = config?.programAddress ?? ORE_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + signer: { value: input.signer ?? null, isWritable: false }, + board: { value: input.board ?? null, isWritable: true }, + rentPayer: { value: input.rentPayer ?? null, isWritable: true }, + round: { value: input.round ?? null, isWritable: true }, + treasury: { value: input.treasury ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // 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.signer), + getAccountMeta(accounts.board), + getAccountMeta(accounts.rentPayer), + getAccountMeta(accounts.round), + getAccountMeta(accounts.treasury), + getAccountMeta(accounts.systemProgram), + ], + data: getCloseInstructionDataEncoder().encode({}), + programAddress, + } as CloseInstruction< + TProgramAddress, + TAccountSigner, + TAccountBoard, + TAccountRentPayer, + TAccountRound, + TAccountTreasury, + TAccountSystemProgram + >); +} + +export type ParsedCloseInstruction< + TProgram extends string = typeof ORE_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + signer: TAccountMetas[0]; + board: TAccountMetas[1]; + rentPayer: TAccountMetas[2]; + round: TAccountMetas[3]; + treasury: TAccountMetas[4]; + systemProgram: TAccountMetas[5]; + }; + data: CloseInstructionData; +}; + +export function parseCloseInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedCloseInstruction { + if (instruction.accounts.length < 6) { + // 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: { + signer: getNextAccount(), + board: getNextAccount(), + rentPayer: getNextAccount(), + round: getNextAccount(), + treasury: getNextAccount(), + systemProgram: getNextAccount(), + }, + data: getCloseInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/js/src/generated/instructions/deploy.ts b/clients/js/src/generated/instructions/deploy.ts new file mode 100644 index 00000000..f859fac9 --- /dev/null +++ b/clients/js/src/generated/instructions/deploy.ts @@ -0,0 +1,333 @@ +/** + * 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 { + combineCodec, + getStructDecoder, + getStructEncoder, + getU32Decoder, + getU32Encoder, + getU64Decoder, + getU64Encoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, + type WritableSignerAccount, +} from "@solana/kit"; +import { ORE_PROGRAM_ADDRESS } from "../programs"; +import { getAccountMetaFactory, type ResolvedAccount } from "../shared"; + +export const DEPLOY_DISCRIMINATOR = 6; + +export function getDeployDiscriminatorBytes() { + return getU8Encoder().encode(DEPLOY_DISCRIMINATOR); +} + +export type DeployInstruction< + TProgram extends string = typeof ORE_PROGRAM_ADDRESS, + TAccountSigner extends string | AccountMeta = string, + TAccountAuthority extends string | AccountMeta = string, + TAccountAutomation extends string | AccountMeta = string, + TAccountBoard extends string | AccountMeta = string, + TAccountConfig extends string | AccountMeta = string, + TAccountMiner extends string | AccountMeta = string, + TAccountRound extends string | AccountMeta = string, + TAccountSystemProgram extends string | AccountMeta = + "11111111111111111111111111111111", + TAccountOreProgram extends string | AccountMeta = string, + TAccountEntropyVar extends string | AccountMeta = string, + TAccountEntropyProgram extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountSigner extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountSigner, + TAccountAuthority extends string + ? WritableAccount + : TAccountAuthority, + TAccountAutomation extends string + ? WritableAccount + : TAccountAutomation, + TAccountBoard extends string + ? WritableAccount + : TAccountBoard, + TAccountConfig extends string + ? WritableAccount + : TAccountConfig, + TAccountMiner extends string + ? WritableAccount + : TAccountMiner, + TAccountRound extends string + ? WritableAccount + : TAccountRound, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + TAccountOreProgram extends string + ? ReadonlyAccount + : TAccountOreProgram, + TAccountEntropyVar extends string + ? WritableAccount + : TAccountEntropyVar, + TAccountEntropyProgram extends string + ? ReadonlyAccount + : TAccountEntropyProgram, + ...TRemainingAccounts, + ] + >; + +export type DeployInstructionData = { + discriminator: number; + amount: bigint; + squares: number; +}; + +export type DeployInstructionDataArgs = { + amount: number | bigint; + squares: number; +}; + +export function getDeployInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", getU8Encoder()], + ["amount", getU64Encoder()], + ["squares", getU32Encoder()], + ]), + (value) => ({ ...value, discriminator: DEPLOY_DISCRIMINATOR }), + ); +} + +export function getDeployInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", getU8Decoder()], + ["amount", getU64Decoder()], + ["squares", getU32Decoder()], + ]); +} + +export function getDeployInstructionDataCodec(): FixedSizeCodec< + DeployInstructionDataArgs, + DeployInstructionData +> { + return combineCodec( + getDeployInstructionDataEncoder(), + getDeployInstructionDataDecoder(), + ); +} + +export type DeployInput< + TAccountSigner extends string = string, + TAccountAuthority extends string = string, + TAccountAutomation extends string = string, + TAccountBoard extends string = string, + TAccountConfig extends string = string, + TAccountMiner extends string = string, + TAccountRound extends string = string, + TAccountSystemProgram extends string = string, + TAccountOreProgram extends string = string, + TAccountEntropyVar extends string = string, + TAccountEntropyProgram extends string = string, +> = { + signer: TransactionSigner; + authority: Address; + automation: Address; + board: Address; + config: Address; + miner: Address; + round: Address; + systemProgram?: Address; + oreProgram: Address; + entropyVar: Address; + entropyProgram: Address; + amount: DeployInstructionDataArgs["amount"]; + squares: DeployInstructionDataArgs["squares"]; +}; + +export function getDeployInstruction< + TAccountSigner extends string, + TAccountAuthority extends string, + TAccountAutomation extends string, + TAccountBoard extends string, + TAccountConfig extends string, + TAccountMiner extends string, + TAccountRound extends string, + TAccountSystemProgram extends string, + TAccountOreProgram extends string, + TAccountEntropyVar extends string, + TAccountEntropyProgram extends string, + TProgramAddress extends Address = typeof ORE_PROGRAM_ADDRESS, +>( + input: DeployInput< + TAccountSigner, + TAccountAuthority, + TAccountAutomation, + TAccountBoard, + TAccountConfig, + TAccountMiner, + TAccountRound, + TAccountSystemProgram, + TAccountOreProgram, + TAccountEntropyVar, + TAccountEntropyProgram + >, + config?: { programAddress?: TProgramAddress }, +): DeployInstruction< + TProgramAddress, + TAccountSigner, + TAccountAuthority, + TAccountAutomation, + TAccountBoard, + TAccountConfig, + TAccountMiner, + TAccountRound, + TAccountSystemProgram, + TAccountOreProgram, + TAccountEntropyVar, + TAccountEntropyProgram +> { + // Program address. + const programAddress = config?.programAddress ?? ORE_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + signer: { value: input.signer ?? null, isWritable: true }, + authority: { value: input.authority ?? null, isWritable: true }, + automation: { value: input.automation ?? null, isWritable: true }, + board: { value: input.board ?? null, isWritable: true }, + config: { value: input.config ?? null, isWritable: true }, + miner: { value: input.miner ?? null, isWritable: true }, + round: { value: input.round ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + oreProgram: { value: input.oreProgram ?? null, isWritable: false }, + entropyVar: { value: input.entropyVar ?? null, isWritable: true }, + entropyProgram: { value: input.entropyProgram ?? 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.signer), + getAccountMeta(accounts.authority), + getAccountMeta(accounts.automation), + getAccountMeta(accounts.board), + getAccountMeta(accounts.config), + getAccountMeta(accounts.miner), + getAccountMeta(accounts.round), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.oreProgram), + getAccountMeta(accounts.entropyVar), + getAccountMeta(accounts.entropyProgram), + ], + data: getDeployInstructionDataEncoder().encode( + args as DeployInstructionDataArgs, + ), + programAddress, + } as DeployInstruction< + TProgramAddress, + TAccountSigner, + TAccountAuthority, + TAccountAutomation, + TAccountBoard, + TAccountConfig, + TAccountMiner, + TAccountRound, + TAccountSystemProgram, + TAccountOreProgram, + TAccountEntropyVar, + TAccountEntropyProgram + >); +} + +export type ParsedDeployInstruction< + TProgram extends string = typeof ORE_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + signer: TAccountMetas[0]; + authority: TAccountMetas[1]; + automation: TAccountMetas[2]; + board: TAccountMetas[3]; + config: TAccountMetas[4]; + miner: TAccountMetas[5]; + round: TAccountMetas[6]; + systemProgram: TAccountMetas[7]; + oreProgram: TAccountMetas[8]; + entropyVar: TAccountMetas[9]; + entropyProgram: TAccountMetas[10]; + }; + data: DeployInstructionData; +}; + +export function parseDeployInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedDeployInstruction { + 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: { + signer: getNextAccount(), + authority: getNextAccount(), + automation: getNextAccount(), + board: getNextAccount(), + config: getNextAccount(), + miner: getNextAccount(), + round: getNextAccount(), + systemProgram: getNextAccount(), + oreProgram: getNextAccount(), + entropyVar: getNextAccount(), + entropyProgram: getNextAccount(), + }, + data: getDeployInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/js/src/generated/instructions/deposit.ts b/clients/js/src/generated/instructions/deposit.ts new file mode 100644 index 00000000..93ab3fe8 --- /dev/null +++ b/clients/js/src/generated/instructions/deposit.ts @@ -0,0 +1,301 @@ +/** + * 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 { + combineCodec, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, + type WritableSignerAccount, +} from "@solana/kit"; +import { ORE_PROGRAM_ADDRESS } from "../programs"; +import { getAccountMetaFactory, type ResolvedAccount } from "../shared"; + +export const DEPOSIT_DISCRIMINATOR = 10; + +export function getDepositDiscriminatorBytes() { + return getU8Encoder().encode(DEPOSIT_DISCRIMINATOR); +} + +export type DepositInstruction< + TProgram extends string = typeof ORE_PROGRAM_ADDRESS, + TAccountSigner extends string | AccountMeta = string, + TAccountMint extends string | AccountMeta = string, + TAccountSender extends string | AccountMeta = string, + TAccountStake extends string | AccountMeta = string, + TAccountStakeTokens extends string | AccountMeta = string, + TAccountTreasury extends string | AccountMeta = string, + TAccountSystemProgram extends string | AccountMeta = + "11111111111111111111111111111111", + TAccountTokenProgram extends string | AccountMeta = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + TAccountAssociatedTokenProgram extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountSigner extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountSigner, + TAccountMint extends string + ? ReadonlyAccount + : TAccountMint, + TAccountSender extends string + ? WritableAccount + : TAccountSender, + TAccountStake extends string + ? WritableAccount + : TAccountStake, + TAccountStakeTokens extends string + ? WritableAccount + : TAccountStakeTokens, + TAccountTreasury extends string + ? WritableAccount + : TAccountTreasury, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + TAccountAssociatedTokenProgram extends string + ? ReadonlyAccount + : TAccountAssociatedTokenProgram, + ...TRemainingAccounts, + ] + >; + +export type DepositInstructionData = { discriminator: number; amount: bigint }; + +export type DepositInstructionDataArgs = { amount: number | bigint }; + +export function getDepositInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", getU8Encoder()], + ["amount", getU64Encoder()], + ]), + (value) => ({ ...value, discriminator: DEPOSIT_DISCRIMINATOR }), + ); +} + +export function getDepositInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", getU8Decoder()], + ["amount", getU64Decoder()], + ]); +} + +export function getDepositInstructionDataCodec(): FixedSizeCodec< + DepositInstructionDataArgs, + DepositInstructionData +> { + return combineCodec( + getDepositInstructionDataEncoder(), + getDepositInstructionDataDecoder(), + ); +} + +export type DepositInput< + TAccountSigner extends string = string, + TAccountMint extends string = string, + TAccountSender extends string = string, + TAccountStake extends string = string, + TAccountStakeTokens extends string = string, + TAccountTreasury extends string = string, + TAccountSystemProgram extends string = string, + TAccountTokenProgram extends string = string, + TAccountAssociatedTokenProgram extends string = string, +> = { + signer: TransactionSigner; + mint: Address; + sender: Address; + stake: Address; + stakeTokens: Address; + treasury: Address; + systemProgram?: Address; + tokenProgram?: Address; + associatedTokenProgram: Address; + amount: DepositInstructionDataArgs["amount"]; +}; + +export function getDepositInstruction< + TAccountSigner extends string, + TAccountMint extends string, + TAccountSender extends string, + TAccountStake extends string, + TAccountStakeTokens extends string, + TAccountTreasury extends string, + TAccountSystemProgram extends string, + TAccountTokenProgram extends string, + TAccountAssociatedTokenProgram extends string, + TProgramAddress extends Address = typeof ORE_PROGRAM_ADDRESS, +>( + input: DepositInput< + TAccountSigner, + TAccountMint, + TAccountSender, + TAccountStake, + TAccountStakeTokens, + TAccountTreasury, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountAssociatedTokenProgram + >, + config?: { programAddress?: TProgramAddress }, +): DepositInstruction< + TProgramAddress, + TAccountSigner, + TAccountMint, + TAccountSender, + TAccountStake, + TAccountStakeTokens, + TAccountTreasury, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountAssociatedTokenProgram +> { + // Program address. + const programAddress = config?.programAddress ?? ORE_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + signer: { value: input.signer ?? null, isWritable: true }, + mint: { value: input.mint ?? null, isWritable: false }, + sender: { value: input.sender ?? null, isWritable: true }, + stake: { value: input.stake ?? null, isWritable: true }, + stakeTokens: { value: input.stakeTokens ?? null, isWritable: true }, + treasury: { value: input.treasury ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + associatedTokenProgram: { + value: input.associatedTokenProgram ?? 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.signer), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.sender), + getAccountMeta(accounts.stake), + getAccountMeta(accounts.stakeTokens), + getAccountMeta(accounts.treasury), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.associatedTokenProgram), + ], + data: getDepositInstructionDataEncoder().encode( + args as DepositInstructionDataArgs, + ), + programAddress, + } as DepositInstruction< + TProgramAddress, + TAccountSigner, + TAccountMint, + TAccountSender, + TAccountStake, + TAccountStakeTokens, + TAccountTreasury, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountAssociatedTokenProgram + >); +} + +export type ParsedDepositInstruction< + TProgram extends string = typeof ORE_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + signer: TAccountMetas[0]; + mint: TAccountMetas[1]; + sender: TAccountMetas[2]; + stake: TAccountMetas[3]; + stakeTokens: TAccountMetas[4]; + treasury: TAccountMetas[5]; + systemProgram: TAccountMetas[6]; + tokenProgram: TAccountMetas[7]; + associatedTokenProgram: TAccountMetas[8]; + }; + data: DepositInstructionData; +}; + +export function parseDepositInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedDepositInstruction { + if (instruction.accounts.length < 9) { + // 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: { + signer: getNextAccount(), + mint: getNextAccount(), + sender: getNextAccount(), + stake: getNextAccount(), + stakeTokens: getNextAccount(), + treasury: getNextAccount(), + systemProgram: getNextAccount(), + tokenProgram: getNextAccount(), + associatedTokenProgram: getNextAccount(), + }, + data: getDepositInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/js/src/generated/instructions/index.ts b/clients/js/src/generated/instructions/index.ts new file mode 100644 index 00000000..0351436c --- /dev/null +++ b/clients/js/src/generated/instructions/index.ts @@ -0,0 +1,23 @@ +/** + * 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 "./automate"; +export * from "./bury"; +export * from "./checkpoint"; +export * from "./claimOre"; +export * from "./claimSol"; +export * from "./claimYield"; +export * from "./close"; +export * from "./deploy"; +export * from "./deposit"; +export * from "./log"; +export * from "./newVar"; +export * from "./reset"; +export * from "./setAdmin"; +export * from "./withdraw"; +export * from "./wrap"; diff --git a/clients/js/src/generated/instructions/log.ts b/clients/js/src/generated/instructions/log.ts new file mode 100644 index 00000000..33a08cd5 --- /dev/null +++ b/clients/js/src/generated/instructions/log.ts @@ -0,0 +1,144 @@ +/** + * 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 { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlySignerAccount, + type ReadonlyUint8Array, + type TransactionSigner, +} from "@solana/kit"; +import { ORE_PROGRAM_ADDRESS } from "../programs"; +import { getAccountMetaFactory, type ResolvedAccount } from "../shared"; + +export const LOG_DISCRIMINATOR = 8; + +export function getLogDiscriminatorBytes() { + return getU8Encoder().encode(LOG_DISCRIMINATOR); +} + +export type LogInstruction< + TProgram extends string = typeof ORE_PROGRAM_ADDRESS, + TAccountBoard extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountBoard extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountBoard, + ...TRemainingAccounts, + ] + >; + +export type LogInstructionData = { discriminator: number }; + +export type LogInstructionDataArgs = {}; + +export function getLogInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", getU8Encoder()]]), + (value) => ({ ...value, discriminator: LOG_DISCRIMINATOR }), + ); +} + +export function getLogInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([["discriminator", getU8Decoder()]]); +} + +export function getLogInstructionDataCodec(): FixedSizeCodec< + LogInstructionDataArgs, + LogInstructionData +> { + return combineCodec( + getLogInstructionDataEncoder(), + getLogInstructionDataDecoder(), + ); +} + +export type LogInput = { + board: TransactionSigner; +}; + +export function getLogInstruction< + TAccountBoard extends string, + TProgramAddress extends Address = typeof ORE_PROGRAM_ADDRESS, +>( + input: LogInput, + config?: { programAddress?: TProgramAddress }, +): LogInstruction { + // Program address. + const programAddress = config?.programAddress ?? ORE_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + board: { value: input.board ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [getAccountMeta(accounts.board)], + data: getLogInstructionDataEncoder().encode({}), + programAddress, + } as LogInstruction); +} + +export type ParsedLogInstruction< + TProgram extends string = typeof ORE_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + board: TAccountMetas[0]; + }; + data: LogInstructionData; +}; + +export function parseLogInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedLogInstruction { + if (instruction.accounts.length < 1) { + // 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: { board: getNextAccount() }, + data: getLogInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/js/src/generated/instructions/newVar.ts b/clients/js/src/generated/instructions/newVar.ts new file mode 100644 index 00000000..820afd19 --- /dev/null +++ b/clients/js/src/generated/instructions/newVar.ts @@ -0,0 +1,282 @@ +/** + * 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 { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyAccount, + type ReadonlySignerAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, +} from "@solana/kit"; +import { ORE_PROGRAM_ADDRESS } from "../programs"; +import { getAccountMetaFactory, type ResolvedAccount } from "../shared"; + +export const NEW_VAR_DISCRIMINATOR = 17; + +export function getNewVarDiscriminatorBytes() { + return getU8Encoder().encode(NEW_VAR_DISCRIMINATOR); +} + +export type NewVarInstruction< + TProgram extends string = typeof ORE_PROGRAM_ADDRESS, + TAccountSigner extends string | AccountMeta = string, + TAccountBoard extends string | AccountMeta = string, + TAccountConfig extends string | AccountMeta = string, + TAccountProvider extends string | AccountMeta = string, + TAccountVar extends string | AccountMeta = string, + TAccountSystemProgram extends string | AccountMeta = + "11111111111111111111111111111111", + TAccountEntropyProgram extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountSigner extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountSigner, + TAccountBoard extends string + ? WritableAccount + : TAccountBoard, + TAccountConfig extends string + ? WritableAccount + : TAccountConfig, + TAccountProvider extends string + ? ReadonlyAccount + : TAccountProvider, + TAccountVar extends string ? WritableAccount : TAccountVar, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + TAccountEntropyProgram extends string + ? ReadonlyAccount + : TAccountEntropyProgram, + ...TRemainingAccounts, + ] + >; + +export type NewVarInstructionData = { + discriminator: number; + id: bigint; + commit: ReadonlyUint8Array; + samples: bigint; +}; + +export type NewVarInstructionDataArgs = { + id: number | bigint; + commit: ReadonlyUint8Array; + samples: number | bigint; +}; + +export function getNewVarInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", getU8Encoder()], + ["id", getU64Encoder()], + ["commit", fixEncoderSize(getBytesEncoder(), 32)], + ["samples", getU64Encoder()], + ]), + (value) => ({ ...value, discriminator: NEW_VAR_DISCRIMINATOR }), + ); +} + +export function getNewVarInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", getU8Decoder()], + ["id", getU64Decoder()], + ["commit", fixDecoderSize(getBytesDecoder(), 32)], + ["samples", getU64Decoder()], + ]); +} + +export function getNewVarInstructionDataCodec(): FixedSizeCodec< + NewVarInstructionDataArgs, + NewVarInstructionData +> { + return combineCodec( + getNewVarInstructionDataEncoder(), + getNewVarInstructionDataDecoder(), + ); +} + +export type NewVarInput< + TAccountSigner extends string = string, + TAccountBoard extends string = string, + TAccountConfig extends string = string, + TAccountProvider extends string = string, + TAccountVar extends string = string, + TAccountSystemProgram extends string = string, + TAccountEntropyProgram extends string = string, +> = { + signer: TransactionSigner; + board: Address; + config: Address; + provider: Address; + var: Address; + systemProgram?: Address; + entropyProgram: Address; + id: NewVarInstructionDataArgs["id"]; + commit: NewVarInstructionDataArgs["commit"]; + samples: NewVarInstructionDataArgs["samples"]; +}; + +export function getNewVarInstruction< + TAccountSigner extends string, + TAccountBoard extends string, + TAccountConfig extends string, + TAccountProvider extends string, + TAccountVar extends string, + TAccountSystemProgram extends string, + TAccountEntropyProgram extends string, + TProgramAddress extends Address = typeof ORE_PROGRAM_ADDRESS, +>( + input: NewVarInput< + TAccountSigner, + TAccountBoard, + TAccountConfig, + TAccountProvider, + TAccountVar, + TAccountSystemProgram, + TAccountEntropyProgram + >, + config?: { programAddress?: TProgramAddress }, +): NewVarInstruction< + TProgramAddress, + TAccountSigner, + TAccountBoard, + TAccountConfig, + TAccountProvider, + TAccountVar, + TAccountSystemProgram, + TAccountEntropyProgram +> { + // Program address. + const programAddress = config?.programAddress ?? ORE_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + signer: { value: input.signer ?? null, isWritable: false }, + board: { value: input.board ?? null, isWritable: true }, + config: { value: input.config ?? null, isWritable: true }, + provider: { value: input.provider ?? null, isWritable: false }, + var: { value: input.var ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + entropyProgram: { value: input.entropyProgram ?? 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.signer), + getAccountMeta(accounts.board), + getAccountMeta(accounts.config), + getAccountMeta(accounts.provider), + getAccountMeta(accounts.var), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.entropyProgram), + ], + data: getNewVarInstructionDataEncoder().encode( + args as NewVarInstructionDataArgs, + ), + programAddress, + } as NewVarInstruction< + TProgramAddress, + TAccountSigner, + TAccountBoard, + TAccountConfig, + TAccountProvider, + TAccountVar, + TAccountSystemProgram, + TAccountEntropyProgram + >); +} + +export type ParsedNewVarInstruction< + TProgram extends string = typeof ORE_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + signer: TAccountMetas[0]; + board: TAccountMetas[1]; + config: TAccountMetas[2]; + provider: TAccountMetas[3]; + var: TAccountMetas[4]; + systemProgram: TAccountMetas[5]; + entropyProgram: TAccountMetas[6]; + }; + data: NewVarInstructionData; +}; + +export function parseNewVarInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedNewVarInstruction { + 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: { + signer: getNextAccount(), + board: getNextAccount(), + config: getNextAccount(), + provider: getNextAccount(), + var: getNextAccount(), + systemProgram: getNextAccount(), + entropyProgram: getNextAccount(), + }, + data: getNewVarInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/js/src/generated/instructions/reset.ts b/clients/js/src/generated/instructions/reset.ts new file mode 100644 index 00000000..c450ab8c --- /dev/null +++ b/clients/js/src/generated/instructions/reset.ts @@ -0,0 +1,390 @@ +/** + * 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 { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, + type WritableSignerAccount, +} from "@solana/kit"; +import { ORE_PROGRAM_ADDRESS } from "../programs"; +import { getAccountMetaFactory, type ResolvedAccount } from "../shared"; + +export const RESET_DISCRIMINATOR = 9; + +export function getResetDiscriminatorBytes() { + return getU8Encoder().encode(RESET_DISCRIMINATOR); +} + +export type ResetInstruction< + TProgram extends string = typeof ORE_PROGRAM_ADDRESS, + TAccountSigner extends string | AccountMeta = string, + TAccountBoard extends string | AccountMeta = string, + TAccountConfig extends string | AccountMeta = string, + TAccountFeeCollector extends string | AccountMeta = string, + TAccountMint extends string | AccountMeta = string, + TAccountRound extends string | AccountMeta = string, + TAccountRoundNext extends string | AccountMeta = string, + TAccountTopMiner extends string | AccountMeta = string, + TAccountTreasury extends string | AccountMeta = string, + TAccountTreasuryTokens extends string | AccountMeta = string, + TAccountSystemProgram extends string | AccountMeta = + "11111111111111111111111111111111", + TAccountTokenProgram extends string | AccountMeta = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + TAccountOreProgram extends string | AccountMeta = string, + TAccountSlotHashesSysvar extends string | AccountMeta = + "SysvarS1otHashes111111111111111111111111111", + TAccountEntropyVar extends string | AccountMeta = string, + TAccountEntropyProgram extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountSigner extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountSigner, + TAccountBoard extends string + ? WritableAccount + : TAccountBoard, + TAccountConfig extends string + ? ReadonlyAccount + : TAccountConfig, + TAccountFeeCollector extends string + ? WritableAccount + : TAccountFeeCollector, + TAccountMint extends string + ? WritableAccount + : TAccountMint, + TAccountRound extends string + ? WritableAccount + : TAccountRound, + TAccountRoundNext extends string + ? WritableAccount + : TAccountRoundNext, + TAccountTopMiner extends string + ? ReadonlyAccount + : TAccountTopMiner, + TAccountTreasury extends string + ? WritableAccount + : TAccountTreasury, + TAccountTreasuryTokens extends string + ? WritableAccount + : TAccountTreasuryTokens, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + TAccountOreProgram extends string + ? ReadonlyAccount + : TAccountOreProgram, + TAccountSlotHashesSysvar extends string + ? ReadonlyAccount + : TAccountSlotHashesSysvar, + TAccountEntropyVar extends string + ? ReadonlyAccount + : TAccountEntropyVar, + TAccountEntropyProgram extends string + ? ReadonlyAccount + : TAccountEntropyProgram, + ...TRemainingAccounts, + ] + >; + +export type ResetInstructionData = { discriminator: number }; + +export type ResetInstructionDataArgs = {}; + +export function getResetInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", getU8Encoder()]]), + (value) => ({ ...value, discriminator: RESET_DISCRIMINATOR }), + ); +} + +export function getResetInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([["discriminator", getU8Decoder()]]); +} + +export function getResetInstructionDataCodec(): FixedSizeCodec< + ResetInstructionDataArgs, + ResetInstructionData +> { + return combineCodec( + getResetInstructionDataEncoder(), + getResetInstructionDataDecoder(), + ); +} + +export type ResetInput< + TAccountSigner extends string = string, + TAccountBoard extends string = string, + TAccountConfig extends string = string, + TAccountFeeCollector extends string = string, + TAccountMint extends string = string, + TAccountRound extends string = string, + TAccountRoundNext extends string = string, + TAccountTopMiner extends string = string, + TAccountTreasury extends string = string, + TAccountTreasuryTokens extends string = string, + TAccountSystemProgram extends string = string, + TAccountTokenProgram extends string = string, + TAccountOreProgram extends string = string, + TAccountSlotHashesSysvar extends string = string, + TAccountEntropyVar extends string = string, + TAccountEntropyProgram extends string = string, +> = { + signer: TransactionSigner; + board: Address; + config: Address; + feeCollector: Address; + mint: Address; + round: Address; + roundNext: Address; + topMiner: Address; + treasury: Address; + treasuryTokens: Address; + systemProgram?: Address; + tokenProgram?: Address; + oreProgram: Address; + slotHashesSysvar?: Address; + entropyVar: Address; + entropyProgram: Address; +}; + +export function getResetInstruction< + TAccountSigner extends string, + TAccountBoard extends string, + TAccountConfig extends string, + TAccountFeeCollector extends string, + TAccountMint extends string, + TAccountRound extends string, + TAccountRoundNext extends string, + TAccountTopMiner extends string, + TAccountTreasury extends string, + TAccountTreasuryTokens extends string, + TAccountSystemProgram extends string, + TAccountTokenProgram extends string, + TAccountOreProgram extends string, + TAccountSlotHashesSysvar extends string, + TAccountEntropyVar extends string, + TAccountEntropyProgram extends string, + TProgramAddress extends Address = typeof ORE_PROGRAM_ADDRESS, +>( + input: ResetInput< + TAccountSigner, + TAccountBoard, + TAccountConfig, + TAccountFeeCollector, + TAccountMint, + TAccountRound, + TAccountRoundNext, + TAccountTopMiner, + TAccountTreasury, + TAccountTreasuryTokens, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountOreProgram, + TAccountSlotHashesSysvar, + TAccountEntropyVar, + TAccountEntropyProgram + >, + config?: { programAddress?: TProgramAddress }, +): ResetInstruction< + TProgramAddress, + TAccountSigner, + TAccountBoard, + TAccountConfig, + TAccountFeeCollector, + TAccountMint, + TAccountRound, + TAccountRoundNext, + TAccountTopMiner, + TAccountTreasury, + TAccountTreasuryTokens, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountOreProgram, + TAccountSlotHashesSysvar, + TAccountEntropyVar, + TAccountEntropyProgram +> { + // Program address. + const programAddress = config?.programAddress ?? ORE_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + signer: { value: input.signer ?? null, isWritable: true }, + board: { value: input.board ?? null, isWritable: true }, + config: { value: input.config ?? null, isWritable: false }, + feeCollector: { value: input.feeCollector ?? null, isWritable: true }, + mint: { value: input.mint ?? null, isWritable: true }, + round: { value: input.round ?? null, isWritable: true }, + roundNext: { value: input.roundNext ?? null, isWritable: true }, + topMiner: { value: input.topMiner ?? null, isWritable: false }, + treasury: { value: input.treasury ?? null, isWritable: true }, + treasuryTokens: { value: input.treasuryTokens ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + oreProgram: { value: input.oreProgram ?? null, isWritable: false }, + slotHashesSysvar: { + value: input.slotHashesSysvar ?? null, + isWritable: false, + }, + entropyVar: { value: input.entropyVar ?? null, isWritable: false }, + entropyProgram: { value: input.entropyProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // 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">; + } + if (!accounts.slotHashesSysvar.value) { + accounts.slotHashesSysvar.value = + "SysvarS1otHashes111111111111111111111111111" as Address<"SysvarS1otHashes111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.signer), + getAccountMeta(accounts.board), + getAccountMeta(accounts.config), + getAccountMeta(accounts.feeCollector), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.round), + getAccountMeta(accounts.roundNext), + getAccountMeta(accounts.topMiner), + getAccountMeta(accounts.treasury), + getAccountMeta(accounts.treasuryTokens), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.oreProgram), + getAccountMeta(accounts.slotHashesSysvar), + getAccountMeta(accounts.entropyVar), + getAccountMeta(accounts.entropyProgram), + ], + data: getResetInstructionDataEncoder().encode({}), + programAddress, + } as ResetInstruction< + TProgramAddress, + TAccountSigner, + TAccountBoard, + TAccountConfig, + TAccountFeeCollector, + TAccountMint, + TAccountRound, + TAccountRoundNext, + TAccountTopMiner, + TAccountTreasury, + TAccountTreasuryTokens, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountOreProgram, + TAccountSlotHashesSysvar, + TAccountEntropyVar, + TAccountEntropyProgram + >); +} + +export type ParsedResetInstruction< + TProgram extends string = typeof ORE_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + signer: TAccountMetas[0]; + board: TAccountMetas[1]; + config: TAccountMetas[2]; + feeCollector: TAccountMetas[3]; + mint: TAccountMetas[4]; + round: TAccountMetas[5]; + roundNext: TAccountMetas[6]; + topMiner: TAccountMetas[7]; + treasury: TAccountMetas[8]; + treasuryTokens: TAccountMetas[9]; + systemProgram: TAccountMetas[10]; + tokenProgram: TAccountMetas[11]; + oreProgram: TAccountMetas[12]; + slotHashesSysvar: TAccountMetas[13]; + entropyVar: TAccountMetas[14]; + entropyProgram: TAccountMetas[15]; + }; + data: ResetInstructionData; +}; + +export function parseResetInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedResetInstruction { + 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: { + signer: getNextAccount(), + board: getNextAccount(), + config: getNextAccount(), + feeCollector: getNextAccount(), + mint: getNextAccount(), + round: getNextAccount(), + roundNext: getNextAccount(), + topMiner: getNextAccount(), + treasury: getNextAccount(), + treasuryTokens: getNextAccount(), + systemProgram: getNextAccount(), + tokenProgram: getNextAccount(), + oreProgram: getNextAccount(), + slotHashesSysvar: getNextAccount(), + entropyVar: getNextAccount(), + entropyProgram: getNextAccount(), + }, + data: getResetInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/js/src/generated/instructions/setAdmin.ts b/clients/js/src/generated/instructions/setAdmin.ts new file mode 100644 index 00000000..e6ec4eab --- /dev/null +++ b/clients/js/src/generated/instructions/setAdmin.ts @@ -0,0 +1,205 @@ +/** + * 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 { + combineCodec, + getAddressDecoder, + getAddressEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyAccount, + type ReadonlySignerAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, +} from "@solana/kit"; +import { ORE_PROGRAM_ADDRESS } from "../programs"; +import { getAccountMetaFactory, type ResolvedAccount } from "../shared"; + +export const SET_ADMIN_DISCRIMINATOR = 15; + +export function getSetAdminDiscriminatorBytes() { + return getU8Encoder().encode(SET_ADMIN_DISCRIMINATOR); +} + +export type SetAdminInstruction< + TProgram extends string = typeof ORE_PROGRAM_ADDRESS, + TAccountSigner extends string | AccountMeta = string, + TAccountConfig extends string | AccountMeta = string, + TAccountSystemProgram extends string | AccountMeta = + "11111111111111111111111111111111", + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountSigner extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountSigner, + TAccountConfig extends string + ? WritableAccount + : TAccountConfig, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + ...TRemainingAccounts, + ] + >; + +export type SetAdminInstructionData = { discriminator: number; admin: Address }; + +export type SetAdminInstructionDataArgs = { admin: Address }; + +export function getSetAdminInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", getU8Encoder()], + ["admin", getAddressEncoder()], + ]), + (value) => ({ ...value, discriminator: SET_ADMIN_DISCRIMINATOR }), + ); +} + +export function getSetAdminInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", getU8Decoder()], + ["admin", getAddressDecoder()], + ]); +} + +export function getSetAdminInstructionDataCodec(): FixedSizeCodec< + SetAdminInstructionDataArgs, + SetAdminInstructionData +> { + return combineCodec( + getSetAdminInstructionDataEncoder(), + getSetAdminInstructionDataDecoder(), + ); +} + +export type SetAdminInput< + TAccountSigner extends string = string, + TAccountConfig extends string = string, + TAccountSystemProgram extends string = string, +> = { + signer: TransactionSigner; + config: Address; + systemProgram?: Address; + admin: SetAdminInstructionDataArgs["admin"]; +}; + +export function getSetAdminInstruction< + TAccountSigner extends string, + TAccountConfig extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof ORE_PROGRAM_ADDRESS, +>( + input: SetAdminInput, + config?: { programAddress?: TProgramAddress }, +): SetAdminInstruction< + TProgramAddress, + TAccountSigner, + TAccountConfig, + TAccountSystemProgram +> { + // Program address. + const programAddress = config?.programAddress ?? ORE_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + signer: { value: input.signer ?? null, isWritable: false }, + config: { value: input.config ?? null, isWritable: true }, + 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.signer), + getAccountMeta(accounts.config), + getAccountMeta(accounts.systemProgram), + ], + data: getSetAdminInstructionDataEncoder().encode( + args as SetAdminInstructionDataArgs, + ), + programAddress, + } as SetAdminInstruction< + TProgramAddress, + TAccountSigner, + TAccountConfig, + TAccountSystemProgram + >); +} + +export type ParsedSetAdminInstruction< + TProgram extends string = typeof ORE_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + signer: TAccountMetas[0]; + config: TAccountMetas[1]; + systemProgram: TAccountMetas[2]; + }; + data: SetAdminInstructionData; +}; + +export function parseSetAdminInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedSetAdminInstruction { + 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: { + signer: getNextAccount(), + config: getNextAccount(), + systemProgram: getNextAccount(), + }, + data: getSetAdminInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/js/src/generated/instructions/withdraw.ts b/clients/js/src/generated/instructions/withdraw.ts new file mode 100644 index 00000000..2f0735f1 --- /dev/null +++ b/clients/js/src/generated/instructions/withdraw.ts @@ -0,0 +1,301 @@ +/** + * 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 { + combineCodec, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, + type WritableSignerAccount, +} from "@solana/kit"; +import { ORE_PROGRAM_ADDRESS } from "../programs"; +import { getAccountMetaFactory, type ResolvedAccount } from "../shared"; + +export const WITHDRAW_DISCRIMINATOR = 11; + +export function getWithdrawDiscriminatorBytes() { + return getU8Encoder().encode(WITHDRAW_DISCRIMINATOR); +} + +export type WithdrawInstruction< + TProgram extends string = typeof ORE_PROGRAM_ADDRESS, + TAccountSigner extends string | AccountMeta = string, + TAccountMint extends string | AccountMeta = string, + TAccountRecipient extends string | AccountMeta = string, + TAccountStake extends string | AccountMeta = string, + TAccountStakeTokens extends string | AccountMeta = string, + TAccountTreasury extends string | AccountMeta = string, + TAccountSystemProgram extends string | AccountMeta = + "11111111111111111111111111111111", + TAccountTokenProgram extends string | AccountMeta = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + TAccountAssociatedTokenProgram extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountSigner extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountSigner, + TAccountMint extends string + ? ReadonlyAccount + : TAccountMint, + TAccountRecipient extends string + ? WritableAccount + : TAccountRecipient, + TAccountStake extends string + ? WritableAccount + : TAccountStake, + TAccountStakeTokens extends string + ? WritableAccount + : TAccountStakeTokens, + TAccountTreasury extends string + ? WritableAccount + : TAccountTreasury, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + TAccountAssociatedTokenProgram extends string + ? ReadonlyAccount + : TAccountAssociatedTokenProgram, + ...TRemainingAccounts, + ] + >; + +export type WithdrawInstructionData = { discriminator: number; amount: bigint }; + +export type WithdrawInstructionDataArgs = { amount: number | bigint }; + +export function getWithdrawInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", getU8Encoder()], + ["amount", getU64Encoder()], + ]), + (value) => ({ ...value, discriminator: WITHDRAW_DISCRIMINATOR }), + ); +} + +export function getWithdrawInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", getU8Decoder()], + ["amount", getU64Decoder()], + ]); +} + +export function getWithdrawInstructionDataCodec(): FixedSizeCodec< + WithdrawInstructionDataArgs, + WithdrawInstructionData +> { + return combineCodec( + getWithdrawInstructionDataEncoder(), + getWithdrawInstructionDataDecoder(), + ); +} + +export type WithdrawInput< + TAccountSigner extends string = string, + TAccountMint extends string = string, + TAccountRecipient extends string = string, + TAccountStake extends string = string, + TAccountStakeTokens extends string = string, + TAccountTreasury extends string = string, + TAccountSystemProgram extends string = string, + TAccountTokenProgram extends string = string, + TAccountAssociatedTokenProgram extends string = string, +> = { + signer: TransactionSigner; + mint: Address; + recipient: Address; + stake: Address; + stakeTokens: Address; + treasury: Address; + systemProgram?: Address; + tokenProgram?: Address; + associatedTokenProgram: Address; + amount: WithdrawInstructionDataArgs["amount"]; +}; + +export function getWithdrawInstruction< + TAccountSigner extends string, + TAccountMint extends string, + TAccountRecipient extends string, + TAccountStake extends string, + TAccountStakeTokens extends string, + TAccountTreasury extends string, + TAccountSystemProgram extends string, + TAccountTokenProgram extends string, + TAccountAssociatedTokenProgram extends string, + TProgramAddress extends Address = typeof ORE_PROGRAM_ADDRESS, +>( + input: WithdrawInput< + TAccountSigner, + TAccountMint, + TAccountRecipient, + TAccountStake, + TAccountStakeTokens, + TAccountTreasury, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountAssociatedTokenProgram + >, + config?: { programAddress?: TProgramAddress }, +): WithdrawInstruction< + TProgramAddress, + TAccountSigner, + TAccountMint, + TAccountRecipient, + TAccountStake, + TAccountStakeTokens, + TAccountTreasury, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountAssociatedTokenProgram +> { + // Program address. + const programAddress = config?.programAddress ?? ORE_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + signer: { value: input.signer ?? null, isWritable: true }, + mint: { value: input.mint ?? null, isWritable: false }, + recipient: { value: input.recipient ?? null, isWritable: true }, + stake: { value: input.stake ?? null, isWritable: true }, + stakeTokens: { value: input.stakeTokens ?? null, isWritable: true }, + treasury: { value: input.treasury ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + associatedTokenProgram: { + value: input.associatedTokenProgram ?? 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.signer), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.recipient), + getAccountMeta(accounts.stake), + getAccountMeta(accounts.stakeTokens), + getAccountMeta(accounts.treasury), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.associatedTokenProgram), + ], + data: getWithdrawInstructionDataEncoder().encode( + args as WithdrawInstructionDataArgs, + ), + programAddress, + } as WithdrawInstruction< + TProgramAddress, + TAccountSigner, + TAccountMint, + TAccountRecipient, + TAccountStake, + TAccountStakeTokens, + TAccountTreasury, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountAssociatedTokenProgram + >); +} + +export type ParsedWithdrawInstruction< + TProgram extends string = typeof ORE_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + signer: TAccountMetas[0]; + mint: TAccountMetas[1]; + recipient: TAccountMetas[2]; + stake: TAccountMetas[3]; + stakeTokens: TAccountMetas[4]; + treasury: TAccountMetas[5]; + systemProgram: TAccountMetas[6]; + tokenProgram: TAccountMetas[7]; + associatedTokenProgram: TAccountMetas[8]; + }; + data: WithdrawInstructionData; +}; + +export function parseWithdrawInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedWithdrawInstruction { + if (instruction.accounts.length < 9) { + // 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: { + signer: getNextAccount(), + mint: getNextAccount(), + recipient: getNextAccount(), + stake: getNextAccount(), + stakeTokens: getNextAccount(), + treasury: getNextAccount(), + systemProgram: getNextAccount(), + tokenProgram: getNextAccount(), + associatedTokenProgram: getNextAccount(), + }, + data: getWithdrawInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/js/src/generated/instructions/wrap.ts b/clients/js/src/generated/instructions/wrap.ts new file mode 100644 index 00000000..924f222c --- /dev/null +++ b/clients/js/src/generated/instructions/wrap.ts @@ -0,0 +1,237 @@ +/** + * 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 { + combineCodec, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyAccount, + type ReadonlySignerAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, +} from "@solana/kit"; +import { ORE_PROGRAM_ADDRESS } from "../programs"; +import { getAccountMetaFactory, type ResolvedAccount } from "../shared"; + +export const WRAP_DISCRIMINATOR = 14; + +export function getWrapDiscriminatorBytes() { + return getU8Encoder().encode(WRAP_DISCRIMINATOR); +} + +export type WrapInstruction< + TProgram extends string = typeof ORE_PROGRAM_ADDRESS, + TAccountSigner extends string | AccountMeta = string, + TAccountConfig extends string | AccountMeta = string, + TAccountTreasury extends string | AccountMeta = string, + TAccountTreasurySol extends string | AccountMeta = string, + TAccountSystemProgram extends string | AccountMeta = + "11111111111111111111111111111111", + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountSigner extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountSigner, + TAccountConfig extends string + ? ReadonlyAccount + : TAccountConfig, + TAccountTreasury extends string + ? WritableAccount + : TAccountTreasury, + TAccountTreasurySol extends string + ? WritableAccount + : TAccountTreasurySol, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + ...TRemainingAccounts, + ] + >; + +export type WrapInstructionData = { discriminator: number; amount: bigint }; + +export type WrapInstructionDataArgs = { amount: number | bigint }; + +export function getWrapInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", getU8Encoder()], + ["amount", getU64Encoder()], + ]), + (value) => ({ ...value, discriminator: WRAP_DISCRIMINATOR }), + ); +} + +export function getWrapInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", getU8Decoder()], + ["amount", getU64Decoder()], + ]); +} + +export function getWrapInstructionDataCodec(): FixedSizeCodec< + WrapInstructionDataArgs, + WrapInstructionData +> { + return combineCodec( + getWrapInstructionDataEncoder(), + getWrapInstructionDataDecoder(), + ); +} + +export type WrapInput< + TAccountSigner extends string = string, + TAccountConfig extends string = string, + TAccountTreasury extends string = string, + TAccountTreasurySol extends string = string, + TAccountSystemProgram extends string = string, +> = { + signer: TransactionSigner; + config: Address; + treasury: Address; + treasurySol: Address; + systemProgram?: Address; + amount: WrapInstructionDataArgs["amount"]; +}; + +export function getWrapInstruction< + TAccountSigner extends string, + TAccountConfig extends string, + TAccountTreasury extends string, + TAccountTreasurySol extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof ORE_PROGRAM_ADDRESS, +>( + input: WrapInput< + TAccountSigner, + TAccountConfig, + TAccountTreasury, + TAccountTreasurySol, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress }, +): WrapInstruction< + TProgramAddress, + TAccountSigner, + TAccountConfig, + TAccountTreasury, + TAccountTreasurySol, + TAccountSystemProgram +> { + // Program address. + const programAddress = config?.programAddress ?? ORE_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + signer: { value: input.signer ?? null, isWritable: false }, + config: { value: input.config ?? null, isWritable: false }, + treasury: { value: input.treasury ?? null, isWritable: true }, + treasurySol: { value: input.treasurySol ?? null, isWritable: true }, + 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.signer), + getAccountMeta(accounts.config), + getAccountMeta(accounts.treasury), + getAccountMeta(accounts.treasurySol), + getAccountMeta(accounts.systemProgram), + ], + data: getWrapInstructionDataEncoder().encode( + args as WrapInstructionDataArgs, + ), + programAddress, + } as WrapInstruction< + TProgramAddress, + TAccountSigner, + TAccountConfig, + TAccountTreasury, + TAccountTreasurySol, + TAccountSystemProgram + >); +} + +export type ParsedWrapInstruction< + TProgram extends string = typeof ORE_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + signer: TAccountMetas[0]; + config: TAccountMetas[1]; + treasury: TAccountMetas[2]; + treasurySol: TAccountMetas[3]; + systemProgram: TAccountMetas[4]; + }; + data: WrapInstructionData; +}; + +export function parseWrapInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedWrapInstruction { + 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: { + signer: getNextAccount(), + config: getNextAccount(), + treasury: getNextAccount(), + treasurySol: getNextAccount(), + systemProgram: getNextAccount(), + }, + data: getWrapInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/js/src/generated/programs/index.ts b/clients/js/src/generated/programs/index.ts new file mode 100644 index 00000000..ef7aaf9e --- /dev/null +++ b/clients/js/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 "./ore"; diff --git a/clients/js/src/generated/programs/ore.ts b/clients/js/src/generated/programs/ore.ts new file mode 100644 index 00000000..9fda5cd0 --- /dev/null +++ b/clients/js/src/generated/programs/ore.ts @@ -0,0 +1,159 @@ +/** + * 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 { + containsBytes, + getU8Encoder, + type Address, + type ReadonlyUint8Array, +} from "@solana/kit"; +import { + type ParsedAutomateInstruction, + type ParsedBuryInstruction, + type ParsedCheckpointInstruction, + type ParsedClaimOreInstruction, + type ParsedClaimSolInstruction, + type ParsedClaimYieldInstruction, + type ParsedCloseInstruction, + type ParsedDeployInstruction, + type ParsedDepositInstruction, + type ParsedLogInstruction, + type ParsedNewVarInstruction, + type ParsedResetInstruction, + type ParsedSetAdminInstruction, + type ParsedWithdrawInstruction, + type ParsedWrapInstruction, +} from "../instructions"; + +export const ORE_PROGRAM_ADDRESS = + "oreV3EG1i9BEgiAJ8b177Z2S2rMarzak4NMv1kULvWv" as Address<"oreV3EG1i9BEgiAJ8b177Z2S2rMarzak4NMv1kULvWv">; + +export enum OreAccount { + Automation, + Board, + Config, + Miner, + Round, + Stake, + Treasury, +} + +export enum OreInstruction { + Automate, + Checkpoint, + ClaimSol, + ClaimOre, + Close, + Deploy, + Log, + Reset, + Deposit, + Withdraw, + ClaimYield, + Bury, + Wrap, + SetAdmin, + NewVar, +} + +export function identifyOreInstruction( + instruction: { data: ReadonlyUint8Array } | ReadonlyUint8Array, +): OreInstruction { + const data = "data" in instruction ? instruction.data : instruction; + if (containsBytes(data, getU8Encoder().encode(0), 0)) { + return OreInstruction.Automate; + } + if (containsBytes(data, getU8Encoder().encode(2), 0)) { + return OreInstruction.Checkpoint; + } + if (containsBytes(data, getU8Encoder().encode(3), 0)) { + return OreInstruction.ClaimSol; + } + if (containsBytes(data, getU8Encoder().encode(4), 0)) { + return OreInstruction.ClaimOre; + } + if (containsBytes(data, getU8Encoder().encode(5), 0)) { + return OreInstruction.Close; + } + if (containsBytes(data, getU8Encoder().encode(6), 0)) { + return OreInstruction.Deploy; + } + if (containsBytes(data, getU8Encoder().encode(8), 0)) { + return OreInstruction.Log; + } + if (containsBytes(data, getU8Encoder().encode(9), 0)) { + return OreInstruction.Reset; + } + if (containsBytes(data, getU8Encoder().encode(10), 0)) { + return OreInstruction.Deposit; + } + if (containsBytes(data, getU8Encoder().encode(11), 0)) { + return OreInstruction.Withdraw; + } + if (containsBytes(data, getU8Encoder().encode(12), 0)) { + return OreInstruction.ClaimYield; + } + if (containsBytes(data, getU8Encoder().encode(13), 0)) { + return OreInstruction.Bury; + } + if (containsBytes(data, getU8Encoder().encode(14), 0)) { + return OreInstruction.Wrap; + } + if (containsBytes(data, getU8Encoder().encode(15), 0)) { + return OreInstruction.SetAdmin; + } + if (containsBytes(data, getU8Encoder().encode(17), 0)) { + return OreInstruction.NewVar; + } + throw new Error( + "The provided instruction could not be identified as a ore instruction.", + ); +} + +export type ParsedOreInstruction< + TProgram extends string = "oreV3EG1i9BEgiAJ8b177Z2S2rMarzak4NMv1kULvWv", +> = + | ({ + instructionType: OreInstruction.Automate; + } & ParsedAutomateInstruction) + | ({ + instructionType: OreInstruction.Checkpoint; + } & ParsedCheckpointInstruction) + | ({ + instructionType: OreInstruction.ClaimSol; + } & ParsedClaimSolInstruction) + | ({ + instructionType: OreInstruction.ClaimOre; + } & ParsedClaimOreInstruction) + | ({ + instructionType: OreInstruction.Close; + } & ParsedCloseInstruction) + | ({ + instructionType: OreInstruction.Deploy; + } & ParsedDeployInstruction) + | ({ instructionType: OreInstruction.Log } & ParsedLogInstruction) + | ({ + instructionType: OreInstruction.Reset; + } & ParsedResetInstruction) + | ({ + instructionType: OreInstruction.Deposit; + } & ParsedDepositInstruction) + | ({ + instructionType: OreInstruction.Withdraw; + } & ParsedWithdrawInstruction) + | ({ + instructionType: OreInstruction.ClaimYield; + } & ParsedClaimYieldInstruction) + | ({ instructionType: OreInstruction.Bury } & ParsedBuryInstruction) + | ({ instructionType: OreInstruction.Wrap } & ParsedWrapInstruction) + | ({ + instructionType: OreInstruction.SetAdmin; + } & ParsedSetAdminInstruction) + | ({ + instructionType: OreInstruction.NewVar; + } & ParsedNewVarInstruction); diff --git a/clients/js/src/generated/shared/index.ts b/clients/js/src/generated/shared/index.ts new file mode 100644 index 00000000..634232f5 --- /dev/null +++ b/clients/js/src/generated/shared/index.ts @@ -0,0 +1,164 @@ +/** + * 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 { + AccountRole, + isProgramDerivedAddress, + isTransactionSigner as kitIsTransactionSigner, + type AccountMeta, + type AccountSignerMeta, + type Address, + type ProgramDerivedAddress, + type TransactionSigner, + 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 type 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 type 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/js/src/generated/types/index.ts b/clients/js/src/generated/types/index.ts new file mode 100644 index 00000000..5f114c6f --- /dev/null +++ b/clients/js/src/generated/types/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 "./numeric"; diff --git a/clients/js/src/generated/types/numeric.ts b/clients/js/src/generated/types/numeric.ts new file mode 100644 index 00000000..0f38583d --- /dev/null +++ b/clients/js/src/generated/types/numeric.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 { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type ReadonlyUint8Array, +} from "@solana/kit"; + +/** Fixed-point helper backed by I80F48 from the steel crate. */ +export type Numeric = { bits: ReadonlyUint8Array }; + +export type NumericArgs = Numeric; + +export function getNumericEncoder(): FixedSizeEncoder { + return getStructEncoder([["bits", fixEncoderSize(getBytesEncoder(), 16)]]); +} + +export function getNumericDecoder(): FixedSizeDecoder { + return getStructDecoder([["bits", fixDecoderSize(getBytesDecoder(), 16)]]); +} + +export function getNumericCodec(): FixedSizeCodec { + return combineCodec(getNumericEncoder(), getNumericDecoder()); +} diff --git a/clients/rust/src/generated/accounts/automation.rs b/clients/rust/src/generated/accounts/automation.rs new file mode 100644 index 00000000..66970042 --- /dev/null +++ b/clients/rust/src/generated/accounts/automation.rs @@ -0,0 +1,133 @@ +//! 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. +//! +//! +//! + +use solana_pubkey::Pubkey; +use borsh::BorshSerialize; +use borsh::BorshDeserialize; + +/// Automation parameters for automated mining deployments. + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct Automation { +pub amount: u64, +#[cfg_attr(feature = "serde", serde(with = "serde_with::As::"))] +pub authority: Pubkey, +pub balance: u64, +#[cfg_attr(feature = "serde", serde(with = "serde_with::As::"))] +pub executor: Pubkey, +pub fee: u64, +pub strategy: u64, +pub mask: u64, +} + + + + +impl Automation { + pub const LEN: usize = 104; + + + + #[inline(always)] + pub fn from_bytes(data: &[u8]) -> Result { + let mut data = data; + Self::deserialize(&mut data) + } +} + +impl<'a> TryFrom<&solana_account_info::AccountInfo<'a>> for Automation { + type Error = std::io::Error; + + fn try_from(account_info: &solana_account_info::AccountInfo<'a>) -> Result { + let mut data: &[u8] = &(*account_info.data).borrow(); + Self::deserialize(&mut data) + } +} + +#[cfg(feature = "fetch")] +pub fn fetch_automation( + rpc: &solana_client::rpc_client::RpcClient, + address: &solana_pubkey::Pubkey, +) -> Result, std::io::Error> { + let accounts = fetch_all_automation(rpc, &[*address])?; + Ok(accounts[0].clone()) +} + +#[cfg(feature = "fetch")] +pub fn fetch_all_automation( + rpc: &solana_client::rpc_client::RpcClient, + addresses: &[solana_pubkey::Pubkey], +) -> Result>, std::io::Error> { + let accounts = rpc.get_multiple_accounts(addresses) + .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?; + let mut decoded_accounts: Vec> = Vec::new(); + for i in 0..addresses.len() { + let address = addresses[i]; + let account = accounts[i].as_ref() + .ok_or(std::io::Error::new(std::io::ErrorKind::Other, format!("Account not found: {}", address)))?; + let data = Automation::from_bytes(&account.data)?; + decoded_accounts.push(crate::shared::DecodedAccount { address, account: account.clone(), data }); + } + Ok(decoded_accounts) +} + +#[cfg(feature = "fetch")] +pub fn fetch_maybe_automation( + rpc: &solana_client::rpc_client::RpcClient, + address: &solana_pubkey::Pubkey, +) -> Result, std::io::Error> { + let accounts = fetch_all_maybe_automation(rpc, &[*address])?; + Ok(accounts[0].clone()) +} + +#[cfg(feature = "fetch")] +pub fn fetch_all_maybe_automation( + rpc: &solana_client::rpc_client::RpcClient, + addresses: &[solana_pubkey::Pubkey], +) -> Result>, std::io::Error> { + let accounts = rpc.get_multiple_accounts(addresses) + .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?; + let mut decoded_accounts: Vec> = Vec::new(); + for i in 0..addresses.len() { + let address = addresses[i]; + if let Some(account) = accounts[i].as_ref() { + let data = Automation::from_bytes(&account.data)?; + decoded_accounts.push(crate::shared::MaybeAccount::Exists(crate::shared::DecodedAccount { address, account: account.clone(), data })); + } else { + decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address)); + } + } + Ok(decoded_accounts) +} + + #[cfg(feature = "anchor")] + impl anchor_lang::AccountDeserialize for Automation { + fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result { + Ok(Self::deserialize(buf)?) + } + } + + #[cfg(feature = "anchor")] + impl anchor_lang::AccountSerialize for Automation {} + + #[cfg(feature = "anchor")] + impl anchor_lang::Owner for Automation { + fn owner() -> Pubkey { + crate::ORE_ID + } + } + + #[cfg(feature = "anchor-idl-build")] + impl anchor_lang::IdlBuild for Automation {} + + + #[cfg(feature = "anchor-idl-build")] + impl anchor_lang::Discriminator for Automation { + const DISCRIMINATOR: &[u8] = &[0; 8]; + } + diff --git a/clients/rust/src/generated/accounts/board.rs b/clients/rust/src/generated/accounts/board.rs new file mode 100644 index 00000000..7e19c0e1 --- /dev/null +++ b/clients/rust/src/generated/accounts/board.rs @@ -0,0 +1,127 @@ +//! 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. +//! +//! +//! + +use borsh::BorshSerialize; +use borsh::BorshDeserialize; + +/// Global round tracking for the mining game. + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct Board { +pub round_id: u64, +pub start_slot: u64, +pub end_slot: u64, +pub epoch_id: u64, +} + + + + +impl Board { + pub const LEN: usize = 32; + + + + #[inline(always)] + pub fn from_bytes(data: &[u8]) -> Result { + let mut data = data; + Self::deserialize(&mut data) + } +} + +impl<'a> TryFrom<&solana_account_info::AccountInfo<'a>> for Board { + type Error = std::io::Error; + + fn try_from(account_info: &solana_account_info::AccountInfo<'a>) -> Result { + let mut data: &[u8] = &(*account_info.data).borrow(); + Self::deserialize(&mut data) + } +} + +#[cfg(feature = "fetch")] +pub fn fetch_board( + rpc: &solana_client::rpc_client::RpcClient, + address: &solana_pubkey::Pubkey, +) -> Result, std::io::Error> { + let accounts = fetch_all_board(rpc, &[*address])?; + Ok(accounts[0].clone()) +} + +#[cfg(feature = "fetch")] +pub fn fetch_all_board( + rpc: &solana_client::rpc_client::RpcClient, + addresses: &[solana_pubkey::Pubkey], +) -> Result>, std::io::Error> { + let accounts = rpc.get_multiple_accounts(addresses) + .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?; + let mut decoded_accounts: Vec> = Vec::new(); + for i in 0..addresses.len() { + let address = addresses[i]; + let account = accounts[i].as_ref() + .ok_or(std::io::Error::new(std::io::ErrorKind::Other, format!("Account not found: {}", address)))?; + let data = Board::from_bytes(&account.data)?; + decoded_accounts.push(crate::shared::DecodedAccount { address, account: account.clone(), data }); + } + Ok(decoded_accounts) +} + +#[cfg(feature = "fetch")] +pub fn fetch_maybe_board( + rpc: &solana_client::rpc_client::RpcClient, + address: &solana_pubkey::Pubkey, +) -> Result, std::io::Error> { + let accounts = fetch_all_maybe_board(rpc, &[*address])?; + Ok(accounts[0].clone()) +} + +#[cfg(feature = "fetch")] +pub fn fetch_all_maybe_board( + rpc: &solana_client::rpc_client::RpcClient, + addresses: &[solana_pubkey::Pubkey], +) -> Result>, std::io::Error> { + let accounts = rpc.get_multiple_accounts(addresses) + .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?; + let mut decoded_accounts: Vec> = Vec::new(); + for i in 0..addresses.len() { + let address = addresses[i]; + if let Some(account) = accounts[i].as_ref() { + let data = Board::from_bytes(&account.data)?; + decoded_accounts.push(crate::shared::MaybeAccount::Exists(crate::shared::DecodedAccount { address, account: account.clone(), data })); + } else { + decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address)); + } + } + Ok(decoded_accounts) +} + + #[cfg(feature = "anchor")] + impl anchor_lang::AccountDeserialize for Board { + fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result { + Ok(Self::deserialize(buf)?) + } + } + + #[cfg(feature = "anchor")] + impl anchor_lang::AccountSerialize for Board {} + + #[cfg(feature = "anchor")] + impl anchor_lang::Owner for Board { + fn owner() -> Pubkey { + crate::ORE_ID + } + } + + #[cfg(feature = "anchor-idl-build")] + impl anchor_lang::IdlBuild for Board {} + + + #[cfg(feature = "anchor-idl-build")] + impl anchor_lang::Discriminator for Board { + const DISCRIMINATOR: &[u8] = &[0; 8]; + } + diff --git a/clients/rust/src/generated/accounts/config.rs b/clients/rust/src/generated/accounts/config.rs new file mode 100644 index 00000000..5a13f9ac --- /dev/null +++ b/clients/rust/src/generated/accounts/config.rs @@ -0,0 +1,135 @@ +//! 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. +//! +//! +//! + +use solana_pubkey::Pubkey; +use borsh::BorshSerialize; +use borsh::BorshDeserialize; + +/// Program configuration state. + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct Config { +#[cfg_attr(feature = "serde", serde(with = "serde_with::As::"))] +pub admin: Pubkey, +#[cfg_attr(feature = "serde", serde(with = "serde_with::As::"))] +pub buffer_a: Pubkey, +#[cfg_attr(feature = "serde", serde(with = "serde_with::As::"))] +pub buffer_b: Pubkey, +#[cfg_attr(feature = "serde", serde(with = "serde_with::As::"))] +pub buffer_c: Pubkey, +#[cfg_attr(feature = "serde", serde(with = "serde_with::As::"))] +pub buffer_d: Pubkey, +pub buffer_e: u64, +} + + + + +impl Config { + pub const LEN: usize = 168; + + + + #[inline(always)] + pub fn from_bytes(data: &[u8]) -> Result { + let mut data = data; + Self::deserialize(&mut data) + } +} + +impl<'a> TryFrom<&solana_account_info::AccountInfo<'a>> for Config { + type Error = std::io::Error; + + fn try_from(account_info: &solana_account_info::AccountInfo<'a>) -> Result { + let mut data: &[u8] = &(*account_info.data).borrow(); + Self::deserialize(&mut data) + } +} + +#[cfg(feature = "fetch")] +pub fn fetch_config( + rpc: &solana_client::rpc_client::RpcClient, + address: &solana_pubkey::Pubkey, +) -> Result, std::io::Error> { + let accounts = fetch_all_config(rpc, &[*address])?; + Ok(accounts[0].clone()) +} + +#[cfg(feature = "fetch")] +pub fn fetch_all_config( + rpc: &solana_client::rpc_client::RpcClient, + addresses: &[solana_pubkey::Pubkey], +) -> Result>, std::io::Error> { + let accounts = rpc.get_multiple_accounts(addresses) + .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?; + let mut decoded_accounts: Vec> = Vec::new(); + for i in 0..addresses.len() { + let address = addresses[i]; + let account = accounts[i].as_ref() + .ok_or(std::io::Error::new(std::io::ErrorKind::Other, format!("Account not found: {}", address)))?; + let data = Config::from_bytes(&account.data)?; + decoded_accounts.push(crate::shared::DecodedAccount { address, account: account.clone(), data }); + } + Ok(decoded_accounts) +} + +#[cfg(feature = "fetch")] +pub fn fetch_maybe_config( + rpc: &solana_client::rpc_client::RpcClient, + address: &solana_pubkey::Pubkey, +) -> Result, std::io::Error> { + let accounts = fetch_all_maybe_config(rpc, &[*address])?; + Ok(accounts[0].clone()) +} + +#[cfg(feature = "fetch")] +pub fn fetch_all_maybe_config( + rpc: &solana_client::rpc_client::RpcClient, + addresses: &[solana_pubkey::Pubkey], +) -> Result>, std::io::Error> { + let accounts = rpc.get_multiple_accounts(addresses) + .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?; + let mut decoded_accounts: Vec> = Vec::new(); + for i in 0..addresses.len() { + let address = addresses[i]; + if let Some(account) = accounts[i].as_ref() { + let data = Config::from_bytes(&account.data)?; + decoded_accounts.push(crate::shared::MaybeAccount::Exists(crate::shared::DecodedAccount { address, account: account.clone(), data })); + } else { + decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address)); + } + } + Ok(decoded_accounts) +} + + #[cfg(feature = "anchor")] + impl anchor_lang::AccountDeserialize for Config { + fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result { + Ok(Self::deserialize(buf)?) + } + } + + #[cfg(feature = "anchor")] + impl anchor_lang::AccountSerialize for Config {} + + #[cfg(feature = "anchor")] + impl anchor_lang::Owner for Config { + fn owner() -> Pubkey { + crate::ORE_ID + } + } + + #[cfg(feature = "anchor-idl-build")] + impl anchor_lang::IdlBuild for Config {} + + + #[cfg(feature = "anchor-idl-build")] + impl anchor_lang::Discriminator for Config { + const DISCRIMINATOR: &[u8] = &[0; 8]; + } + diff --git a/clients/rust/src/generated/accounts/miner.rs b/clients/rust/src/generated/accounts/miner.rs new file mode 100644 index 00000000..5c8d97da --- /dev/null +++ b/clients/rust/src/generated/accounts/miner.rs @@ -0,0 +1,141 @@ +//! 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. +//! +//! +//! + +use solana_pubkey::Pubkey; +use crate::generated::types::Numeric; +use borsh::BorshSerialize; +use borsh::BorshDeserialize; + +/// Tracks a miner's deployed SOL and reward balances. + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct Miner { +#[cfg_attr(feature = "serde", serde(with = "serde_with::As::"))] +pub authority: Pubkey, +pub deployed: [u64; 25], +pub cumulative: [u64; 25], +pub checkpoint_fee: u64, +pub checkpoint_id: u64, +pub last_claim_ore_at: i64, +pub last_claim_sol_at: i64, +pub rewards_factor: Numeric, +pub rewards_sol: u64, +pub rewards_ore: u64, +pub refined_ore: u64, +pub round_id: u64, +pub lifetime_rewards_sol: u64, +pub lifetime_rewards_ore: u64, +pub lifetime_deployed: u64, +} + + + + +impl Miner { + pub const LEN: usize = 536; + + + + #[inline(always)] + pub fn from_bytes(data: &[u8]) -> Result { + let mut data = data; + Self::deserialize(&mut data) + } +} + +impl<'a> TryFrom<&solana_account_info::AccountInfo<'a>> for Miner { + type Error = std::io::Error; + + fn try_from(account_info: &solana_account_info::AccountInfo<'a>) -> Result { + let mut data: &[u8] = &(*account_info.data).borrow(); + Self::deserialize(&mut data) + } +} + +#[cfg(feature = "fetch")] +pub fn fetch_miner( + rpc: &solana_client::rpc_client::RpcClient, + address: &solana_pubkey::Pubkey, +) -> Result, std::io::Error> { + let accounts = fetch_all_miner(rpc, &[*address])?; + Ok(accounts[0].clone()) +} + +#[cfg(feature = "fetch")] +pub fn fetch_all_miner( + rpc: &solana_client::rpc_client::RpcClient, + addresses: &[solana_pubkey::Pubkey], +) -> Result>, std::io::Error> { + let accounts = rpc.get_multiple_accounts(addresses) + .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?; + let mut decoded_accounts: Vec> = Vec::new(); + for i in 0..addresses.len() { + let address = addresses[i]; + let account = accounts[i].as_ref() + .ok_or(std::io::Error::new(std::io::ErrorKind::Other, format!("Account not found: {}", address)))?; + let data = Miner::from_bytes(&account.data)?; + decoded_accounts.push(crate::shared::DecodedAccount { address, account: account.clone(), data }); + } + Ok(decoded_accounts) +} + +#[cfg(feature = "fetch")] +pub fn fetch_maybe_miner( + rpc: &solana_client::rpc_client::RpcClient, + address: &solana_pubkey::Pubkey, +) -> Result, std::io::Error> { + let accounts = fetch_all_maybe_miner(rpc, &[*address])?; + Ok(accounts[0].clone()) +} + +#[cfg(feature = "fetch")] +pub fn fetch_all_maybe_miner( + rpc: &solana_client::rpc_client::RpcClient, + addresses: &[solana_pubkey::Pubkey], +) -> Result>, std::io::Error> { + let accounts = rpc.get_multiple_accounts(addresses) + .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?; + let mut decoded_accounts: Vec> = Vec::new(); + for i in 0..addresses.len() { + let address = addresses[i]; + if let Some(account) = accounts[i].as_ref() { + let data = Miner::from_bytes(&account.data)?; + decoded_accounts.push(crate::shared::MaybeAccount::Exists(crate::shared::DecodedAccount { address, account: account.clone(), data })); + } else { + decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address)); + } + } + Ok(decoded_accounts) +} + + #[cfg(feature = "anchor")] + impl anchor_lang::AccountDeserialize for Miner { + fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result { + Ok(Self::deserialize(buf)?) + } + } + + #[cfg(feature = "anchor")] + impl anchor_lang::AccountSerialize for Miner {} + + #[cfg(feature = "anchor")] + impl anchor_lang::Owner for Miner { + fn owner() -> Pubkey { + crate::ORE_ID + } + } + + #[cfg(feature = "anchor-idl-build")] + impl anchor_lang::IdlBuild for Miner {} + + + #[cfg(feature = "anchor-idl-build")] + impl anchor_lang::Discriminator for Miner { + const DISCRIMINATOR: &[u8] = &[0; 8]; + } + diff --git a/clients/rust/src/generated/accounts/mod.rs b/clients/rust/src/generated/accounts/mod.rs new file mode 100644 index 00000000..7fa2101c --- /dev/null +++ b/clients/rust/src/generated/accounts/mod.rs @@ -0,0 +1,23 @@ +//! 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. +//! +//! +//! + + pub(crate) mod r#automation; + pub(crate) mod r#board; + pub(crate) mod r#config; + pub(crate) mod r#miner; + pub(crate) mod r#round; + pub(crate) mod r#stake; + pub(crate) mod r#treasury; + + pub use self::r#automation::*; + pub use self::r#board::*; + pub use self::r#config::*; + pub use self::r#miner::*; + pub use self::r#round::*; + pub use self::r#stake::*; + pub use self::r#treasury::*; + diff --git a/clients/rust/src/generated/accounts/round.rs b/clients/rust/src/generated/accounts/round.rs new file mode 100644 index 00000000..84bde8cf --- /dev/null +++ b/clients/rust/src/generated/accounts/round.rs @@ -0,0 +1,139 @@ +//! 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. +//! +//! +//! + +use solana_pubkey::Pubkey; +use borsh::BorshSerialize; +use borsh::BorshDeserialize; + +/// State for a single mining round. + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct Round { +pub id: u64, +pub deployed: [u64; 25], +pub slot_hash: [u8; 32], +pub count: [u64; 25], +pub expires_at: u64, +pub motherlode: u64, +#[cfg_attr(feature = "serde", serde(with = "serde_with::As::"))] +pub rent_payer: Pubkey, +#[cfg_attr(feature = "serde", serde(with = "serde_with::As::"))] +pub top_miner: Pubkey, +pub top_miner_reward: u64, +pub total_deployed: u64, +pub total_miners: u64, +pub total_vaulted: u64, +pub total_winnings: u64, +} + + + + +impl Round { + pub const LEN: usize = 560; + + + + #[inline(always)] + pub fn from_bytes(data: &[u8]) -> Result { + let mut data = data; + Self::deserialize(&mut data) + } +} + +impl<'a> TryFrom<&solana_account_info::AccountInfo<'a>> for Round { + type Error = std::io::Error; + + fn try_from(account_info: &solana_account_info::AccountInfo<'a>) -> Result { + let mut data: &[u8] = &(*account_info.data).borrow(); + Self::deserialize(&mut data) + } +} + +#[cfg(feature = "fetch")] +pub fn fetch_round( + rpc: &solana_client::rpc_client::RpcClient, + address: &solana_pubkey::Pubkey, +) -> Result, std::io::Error> { + let accounts = fetch_all_round(rpc, &[*address])?; + Ok(accounts[0].clone()) +} + +#[cfg(feature = "fetch")] +pub fn fetch_all_round( + rpc: &solana_client::rpc_client::RpcClient, + addresses: &[solana_pubkey::Pubkey], +) -> Result>, std::io::Error> { + let accounts = rpc.get_multiple_accounts(addresses) + .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?; + let mut decoded_accounts: Vec> = Vec::new(); + for i in 0..addresses.len() { + let address = addresses[i]; + let account = accounts[i].as_ref() + .ok_or(std::io::Error::new(std::io::ErrorKind::Other, format!("Account not found: {}", address)))?; + let data = Round::from_bytes(&account.data)?; + decoded_accounts.push(crate::shared::DecodedAccount { address, account: account.clone(), data }); + } + Ok(decoded_accounts) +} + +#[cfg(feature = "fetch")] +pub fn fetch_maybe_round( + rpc: &solana_client::rpc_client::RpcClient, + address: &solana_pubkey::Pubkey, +) -> Result, std::io::Error> { + let accounts = fetch_all_maybe_round(rpc, &[*address])?; + Ok(accounts[0].clone()) +} + +#[cfg(feature = "fetch")] +pub fn fetch_all_maybe_round( + rpc: &solana_client::rpc_client::RpcClient, + addresses: &[solana_pubkey::Pubkey], +) -> Result>, std::io::Error> { + let accounts = rpc.get_multiple_accounts(addresses) + .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?; + let mut decoded_accounts: Vec> = Vec::new(); + for i in 0..addresses.len() { + let address = addresses[i]; + if let Some(account) = accounts[i].as_ref() { + let data = Round::from_bytes(&account.data)?; + decoded_accounts.push(crate::shared::MaybeAccount::Exists(crate::shared::DecodedAccount { address, account: account.clone(), data })); + } else { + decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address)); + } + } + Ok(decoded_accounts) +} + + #[cfg(feature = "anchor")] + impl anchor_lang::AccountDeserialize for Round { + fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result { + Ok(Self::deserialize(buf)?) + } + } + + #[cfg(feature = "anchor")] + impl anchor_lang::AccountSerialize for Round {} + + #[cfg(feature = "anchor")] + impl anchor_lang::Owner for Round { + fn owner() -> Pubkey { + crate::ORE_ID + } + } + + #[cfg(feature = "anchor-idl-build")] + impl anchor_lang::IdlBuild for Round {} + + + #[cfg(feature = "anchor-idl-build")] + impl anchor_lang::Discriminator for Round { + const DISCRIMINATOR: &[u8] = &[0; 8]; + } + diff --git a/clients/rust/src/generated/accounts/stake.rs b/clients/rust/src/generated/accounts/stake.rs new file mode 100644 index 00000000..c0849742 --- /dev/null +++ b/clients/rust/src/generated/accounts/stake.rs @@ -0,0 +1,140 @@ +//! 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. +//! +//! +//! + +use solana_pubkey::Pubkey; +use crate::generated::types::Numeric; +use borsh::BorshSerialize; +use borsh::BorshDeserialize; + +/// State for a staking participant. + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct Stake { +#[cfg_attr(feature = "serde", serde(with = "serde_with::As::"))] +pub authority: Pubkey, +pub balance: u64, +pub buffer_a: u64, +pub buffer_b: u64, +pub buffer_c: u64, +pub buffer_d: u64, +pub buffer_e: u64, +pub last_claim_at: i64, +pub last_deposit_at: i64, +pub last_withdraw_at: i64, +pub rewards_factor: Numeric, +pub rewards: u64, +pub lifetime_rewards: u64, +pub buffer_f: u64, +} + + + + +impl Stake { + pub const LEN: usize = 144; + + + + #[inline(always)] + pub fn from_bytes(data: &[u8]) -> Result { + let mut data = data; + Self::deserialize(&mut data) + } +} + +impl<'a> TryFrom<&solana_account_info::AccountInfo<'a>> for Stake { + type Error = std::io::Error; + + fn try_from(account_info: &solana_account_info::AccountInfo<'a>) -> Result { + let mut data: &[u8] = &(*account_info.data).borrow(); + Self::deserialize(&mut data) + } +} + +#[cfg(feature = "fetch")] +pub fn fetch_stake( + rpc: &solana_client::rpc_client::RpcClient, + address: &solana_pubkey::Pubkey, +) -> Result, std::io::Error> { + let accounts = fetch_all_stake(rpc, &[*address])?; + Ok(accounts[0].clone()) +} + +#[cfg(feature = "fetch")] +pub fn fetch_all_stake( + rpc: &solana_client::rpc_client::RpcClient, + addresses: &[solana_pubkey::Pubkey], +) -> Result>, std::io::Error> { + let accounts = rpc.get_multiple_accounts(addresses) + .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?; + let mut decoded_accounts: Vec> = Vec::new(); + for i in 0..addresses.len() { + let address = addresses[i]; + let account = accounts[i].as_ref() + .ok_or(std::io::Error::new(std::io::ErrorKind::Other, format!("Account not found: {}", address)))?; + let data = Stake::from_bytes(&account.data)?; + decoded_accounts.push(crate::shared::DecodedAccount { address, account: account.clone(), data }); + } + Ok(decoded_accounts) +} + +#[cfg(feature = "fetch")] +pub fn fetch_maybe_stake( + rpc: &solana_client::rpc_client::RpcClient, + address: &solana_pubkey::Pubkey, +) -> Result, std::io::Error> { + let accounts = fetch_all_maybe_stake(rpc, &[*address])?; + Ok(accounts[0].clone()) +} + +#[cfg(feature = "fetch")] +pub fn fetch_all_maybe_stake( + rpc: &solana_client::rpc_client::RpcClient, + addresses: &[solana_pubkey::Pubkey], +) -> Result>, std::io::Error> { + let accounts = rpc.get_multiple_accounts(addresses) + .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?; + let mut decoded_accounts: Vec> = Vec::new(); + for i in 0..addresses.len() { + let address = addresses[i]; + if let Some(account) = accounts[i].as_ref() { + let data = Stake::from_bytes(&account.data)?; + decoded_accounts.push(crate::shared::MaybeAccount::Exists(crate::shared::DecodedAccount { address, account: account.clone(), data })); + } else { + decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address)); + } + } + Ok(decoded_accounts) +} + + #[cfg(feature = "anchor")] + impl anchor_lang::AccountDeserialize for Stake { + fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result { + Ok(Self::deserialize(buf)?) + } + } + + #[cfg(feature = "anchor")] + impl anchor_lang::AccountSerialize for Stake {} + + #[cfg(feature = "anchor")] + impl anchor_lang::Owner for Stake { + fn owner() -> Pubkey { + crate::ORE_ID + } + } + + #[cfg(feature = "anchor-idl-build")] + impl anchor_lang::IdlBuild for Stake {} + + + #[cfg(feature = "anchor-idl-build")] + impl anchor_lang::Discriminator for Stake { + const DISCRIMINATOR: &[u8] = &[0; 8]; + } + diff --git a/clients/rust/src/generated/accounts/treasury.rs b/clients/rust/src/generated/accounts/treasury.rs new file mode 100644 index 00000000..761bdb4d --- /dev/null +++ b/clients/rust/src/generated/accounts/treasury.rs @@ -0,0 +1,133 @@ +//! 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. +//! +//! +//! + +use crate::generated::types::Numeric; +use borsh::BorshSerialize; +use borsh::BorshDeserialize; + +/// Singleton treasury account tracking protocol balances. + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct Treasury { +pub balance: u64, +pub buffer_a: u64, +pub motherlode: u64, +pub miner_rewards_factor: Numeric, +pub stake_rewards_factor: Numeric, +pub buffer_b: u64, +pub total_refined: u64, +pub total_staked: u64, +pub total_unclaimed: u64, +} + + + + +impl Treasury { + pub const LEN: usize = 88; + + + + #[inline(always)] + pub fn from_bytes(data: &[u8]) -> Result { + let mut data = data; + Self::deserialize(&mut data) + } +} + +impl<'a> TryFrom<&solana_account_info::AccountInfo<'a>> for Treasury { + type Error = std::io::Error; + + fn try_from(account_info: &solana_account_info::AccountInfo<'a>) -> Result { + let mut data: &[u8] = &(*account_info.data).borrow(); + Self::deserialize(&mut data) + } +} + +#[cfg(feature = "fetch")] +pub fn fetch_treasury( + rpc: &solana_client::rpc_client::RpcClient, + address: &solana_pubkey::Pubkey, +) -> Result, std::io::Error> { + let accounts = fetch_all_treasury(rpc, &[*address])?; + Ok(accounts[0].clone()) +} + +#[cfg(feature = "fetch")] +pub fn fetch_all_treasury( + rpc: &solana_client::rpc_client::RpcClient, + addresses: &[solana_pubkey::Pubkey], +) -> Result>, std::io::Error> { + let accounts = rpc.get_multiple_accounts(addresses) + .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?; + let mut decoded_accounts: Vec> = Vec::new(); + for i in 0..addresses.len() { + let address = addresses[i]; + let account = accounts[i].as_ref() + .ok_or(std::io::Error::new(std::io::ErrorKind::Other, format!("Account not found: {}", address)))?; + let data = Treasury::from_bytes(&account.data)?; + decoded_accounts.push(crate::shared::DecodedAccount { address, account: account.clone(), data }); + } + Ok(decoded_accounts) +} + +#[cfg(feature = "fetch")] +pub fn fetch_maybe_treasury( + rpc: &solana_client::rpc_client::RpcClient, + address: &solana_pubkey::Pubkey, +) -> Result, std::io::Error> { + let accounts = fetch_all_maybe_treasury(rpc, &[*address])?; + Ok(accounts[0].clone()) +} + +#[cfg(feature = "fetch")] +pub fn fetch_all_maybe_treasury( + rpc: &solana_client::rpc_client::RpcClient, + addresses: &[solana_pubkey::Pubkey], +) -> Result>, std::io::Error> { + let accounts = rpc.get_multiple_accounts(addresses) + .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?; + let mut decoded_accounts: Vec> = Vec::new(); + for i in 0..addresses.len() { + let address = addresses[i]; + if let Some(account) = accounts[i].as_ref() { + let data = Treasury::from_bytes(&account.data)?; + decoded_accounts.push(crate::shared::MaybeAccount::Exists(crate::shared::DecodedAccount { address, account: account.clone(), data })); + } else { + decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address)); + } + } + Ok(decoded_accounts) +} + + #[cfg(feature = "anchor")] + impl anchor_lang::AccountDeserialize for Treasury { + fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result { + Ok(Self::deserialize(buf)?) + } + } + + #[cfg(feature = "anchor")] + impl anchor_lang::AccountSerialize for Treasury {} + + #[cfg(feature = "anchor")] + impl anchor_lang::Owner for Treasury { + fn owner() -> Pubkey { + crate::ORE_ID + } + } + + #[cfg(feature = "anchor-idl-build")] + impl anchor_lang::IdlBuild for Treasury {} + + + #[cfg(feature = "anchor-idl-build")] + impl anchor_lang::Discriminator for Treasury { + const DISCRIMINATOR: &[u8] = &[0; 8]; + } + diff --git a/clients/rust/src/generated/errors/mod.rs b/clients/rust/src/generated/errors/mod.rs new file mode 100644 index 00000000..149fbf0e --- /dev/null +++ b/clients/rust/src/generated/errors/mod.rs @@ -0,0 +1,11 @@ +//! 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. +//! +//! +//! + + pub(crate) mod ore; + + pub use self::ore::OreError; + diff --git a/clients/rust/src/generated/errors/ore.rs b/clients/rust/src/generated/errors/ore.rs new file mode 100644 index 00000000..9d27e4ef --- /dev/null +++ b/clients/rust/src/generated/errors/ore.rs @@ -0,0 +1,26 @@ +//! 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. +//! +//! +//! + +use num_derive::FromPrimitive; +use thiserror::Error; + +#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)] +pub enum OreError { + /// 0 - Amount too small + #[error("Amount too small")] + AmountTooSmall = 0x0, + /// 1 - Not authorized + #[error("Not authorized")] + NotAuthorized = 0x1, +} + +impl From for solana_program_error::ProgramError { + fn from(e: OreError) -> Self { + solana_program_error::ProgramError::Custom(e as u32) + } +} + diff --git a/clients/rust/src/generated/instructions/automate.rs b/clients/rust/src/generated/instructions/automate.rs new file mode 100644 index 00000000..69ee5485 --- /dev/null +++ b/clients/rust/src/generated/instructions/automate.rs @@ -0,0 +1,504 @@ +//! 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. +//! +//! +//! + +use borsh::BorshSerialize; +use borsh::BorshDeserialize; + +pub const AUTOMATE_DISCRIMINATOR: u8 = 0; + +/// Accounts. +#[derive(Debug)] +pub struct Automate { + + + pub signer: solana_pubkey::Pubkey, + + + pub automation: solana_pubkey::Pubkey, + + + pub executor: solana_pubkey::Pubkey, + + + pub miner: solana_pubkey::Pubkey, + + + pub system_program: solana_pubkey::Pubkey, + } + +impl Automate { + pub fn instruction(&self, args: AutomateInstructionArgs) -> solana_instruction::Instruction { + self.instruction_with_remaining_accounts(args, &[]) + } + #[allow(clippy::arithmetic_side_effects)] + #[allow(clippy::vec_init_then_push)] + pub fn instruction_with_remaining_accounts(&self, args: AutomateInstructionArgs, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction { + let mut accounts = Vec::with_capacity(5+ remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new( + self.signer, + true + )); + accounts.push(solana_instruction::AccountMeta::new( + self.automation, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.executor, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.miner, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.system_program, + false + )); + accounts.extend_from_slice(remaining_accounts); + let mut data = AutomateInstructionData::new().try_to_vec().unwrap(); + let mut args = args.try_to_vec().unwrap(); + data.append(&mut args); + + solana_instruction::Instruction { + program_id: crate::ORE_ID, + accounts, + data, + } + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] + pub struct AutomateInstructionData { + discriminator: u8, + } + +impl AutomateInstructionData { + pub fn new() -> Self { + Self { + discriminator: 0, + } + } + + pub(crate) fn try_to_vec(&self) -> Result, std::io::Error> { + borsh::to_vec(self) + } + } + +impl Default for AutomateInstructionData { + fn default() -> Self { + Self::new() + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] + pub struct AutomateInstructionArgs { + pub amount: u64, + pub deposit: u64, + pub fee: u64, + pub mask: u64, + pub strategy: u8, + } + +impl AutomateInstructionArgs { + pub(crate) fn try_to_vec(&self) -> Result, std::io::Error> { + borsh::to_vec(self) + } +} + + +/// Instruction builder for `Automate`. +/// +/// ### Accounts: +/// + /// 0. `[writable, signer]` signer + /// 1. `[writable]` automation + /// 2. `[]` executor + /// 3. `[writable]` miner + /// 4. `[optional]` system_program (default to `11111111111111111111111111111111`) +#[derive(Clone, Debug, Default)] +pub struct AutomateBuilder { + signer: Option, + automation: Option, + executor: Option, + miner: Option, + system_program: Option, + amount: Option, + deposit: Option, + fee: Option, + mask: Option, + strategy: Option, + __remaining_accounts: Vec, +} + +impl AutomateBuilder { + pub fn new() -> Self { + Self::default() + } + #[inline(always)] + pub fn signer(&mut self, signer: solana_pubkey::Pubkey) -> &mut Self { + self.signer = Some(signer); + self + } + #[inline(always)] + pub fn automation(&mut self, automation: solana_pubkey::Pubkey) -> &mut Self { + self.automation = Some(automation); + self + } + #[inline(always)] + pub fn executor(&mut self, executor: solana_pubkey::Pubkey) -> &mut Self { + self.executor = Some(executor); + self + } + #[inline(always)] + pub fn miner(&mut self, miner: solana_pubkey::Pubkey) -> &mut Self { + self.miner = Some(miner); + self + } + /// `[optional account, default to '11111111111111111111111111111111']` +#[inline(always)] + pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self { + self.system_program = Some(system_program); + self + } + #[inline(always)] + pub fn amount(&mut self, amount: u64) -> &mut Self { + self.amount = Some(amount); + self + } + #[inline(always)] + pub fn deposit(&mut self, deposit: u64) -> &mut Self { + self.deposit = Some(deposit); + self + } + #[inline(always)] + pub fn fee(&mut self, fee: u64) -> &mut Self { + self.fee = Some(fee); + self + } + #[inline(always)] + pub fn mask(&mut self, mask: u64) -> &mut Self { + self.mask = Some(mask); + self + } + #[inline(always)] + pub fn strategy(&mut self, strategy: u8) -> &mut Self { + self.strategy = Some(strategy); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self { + self.__remaining_accounts.push(account); + self + } + /// Add additional accounts to the instruction. + #[inline(always)] + pub fn add_remaining_accounts(&mut self, accounts: &[solana_instruction::AccountMeta]) -> &mut Self { + self.__remaining_accounts.extend_from_slice(accounts); + self + } + #[allow(clippy::clone_on_copy)] + pub fn instruction(&self) -> solana_instruction::Instruction { + let accounts = Automate { + signer: self.signer.expect("signer is not set"), + automation: self.automation.expect("automation is not set"), + executor: self.executor.expect("executor is not set"), + miner: self.miner.expect("miner is not set"), + system_program: self.system_program.unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")), + }; + let args = AutomateInstructionArgs { + amount: self.amount.clone().expect("amount is not set"), + deposit: self.deposit.clone().expect("deposit is not set"), + fee: self.fee.clone().expect("fee is not set"), + mask: self.mask.clone().expect("mask is not set"), + strategy: self.strategy.clone().expect("strategy is not set"), + }; + + accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts) + } +} + + /// `automate` CPI accounts. + pub struct AutomateCpiAccounts<'a, 'b> { + + + pub signer: &'b solana_account_info::AccountInfo<'a>, + + + pub automation: &'b solana_account_info::AccountInfo<'a>, + + + pub executor: &'b solana_account_info::AccountInfo<'a>, + + + pub miner: &'b solana_account_info::AccountInfo<'a>, + + + pub system_program: &'b solana_account_info::AccountInfo<'a>, + } + +/// `automate` CPI instruction. +pub struct AutomateCpi<'a, 'b> { + /// The program to invoke. + pub __program: &'b solana_account_info::AccountInfo<'a>, + + + pub signer: &'b solana_account_info::AccountInfo<'a>, + + + pub automation: &'b solana_account_info::AccountInfo<'a>, + + + pub executor: &'b solana_account_info::AccountInfo<'a>, + + + pub miner: &'b solana_account_info::AccountInfo<'a>, + + + pub system_program: &'b solana_account_info::AccountInfo<'a>, + /// The arguments for the instruction. + pub __args: AutomateInstructionArgs, + } + +impl<'a, 'b> AutomateCpi<'a, 'b> { + pub fn new( + program: &'b solana_account_info::AccountInfo<'a>, + accounts: AutomateCpiAccounts<'a, 'b>, + args: AutomateInstructionArgs, + ) -> Self { + Self { + __program: program, + signer: accounts.signer, + automation: accounts.automation, + executor: accounts.executor, + miner: accounts.miner, + system_program: accounts.system_program, + __args: args, + } + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], &[]) + } + #[inline(always)] + pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], remaining_accounts) + } + #[inline(always)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(signers_seeds, &[]) + } + #[allow(clippy::arithmetic_side_effects)] + #[allow(clippy::clone_on_copy)] + #[allow(clippy::vec_init_then_push)] + pub fn invoke_signed_with_remaining_accounts( + &self, + signers_seeds: &[&[&[u8]]], + remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)] + ) -> solana_program_error::ProgramResult { + let mut accounts = Vec::with_capacity(5+ remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new( + *self.signer.key, + true + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.automation.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.executor.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.miner.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.system_program.key, + false + )); + remaining_accounts.iter().for_each(|remaining_account| { + accounts.push(solana_instruction::AccountMeta { + pubkey: *remaining_account.0.key, + is_signer: remaining_account.1, + is_writable: remaining_account.2, + }) + }); + let mut data = AutomateInstructionData::new().try_to_vec().unwrap(); + let mut args = self.__args.try_to_vec().unwrap(); + data.append(&mut args); + + let instruction = solana_instruction::Instruction { + program_id: crate::ORE_ID, + accounts, + data, + }; + let mut account_infos = Vec::with_capacity(6 + remaining_accounts.len()); + account_infos.push(self.__program.clone()); + account_infos.push(self.signer.clone()); + account_infos.push(self.automation.clone()); + account_infos.push(self.executor.clone()); + account_infos.push(self.miner.clone()); + account_infos.push(self.system_program.clone()); + remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone())); + + if signers_seeds.is_empty() { + solana_cpi::invoke(&instruction, &account_infos) + } else { + solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds) + } + } +} + +/// Instruction builder for `Automate` via CPI. +/// +/// ### Accounts: +/// + /// 0. `[writable, signer]` signer + /// 1. `[writable]` automation + /// 2. `[]` executor + /// 3. `[writable]` miner + /// 4. `[]` system_program +#[derive(Clone, Debug)] +pub struct AutomateCpiBuilder<'a, 'b> { + instruction: Box>, +} + +impl<'a, 'b> AutomateCpiBuilder<'a, 'b> { + pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self { + let instruction = Box::new(AutomateCpiBuilderInstruction { + __program: program, + signer: None, + automation: None, + executor: None, + miner: None, + system_program: None, + amount: None, + deposit: None, + fee: None, + mask: None, + strategy: None, + __remaining_accounts: Vec::new(), + }); + Self { instruction } + } + #[inline(always)] + pub fn signer(&mut self, signer: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.signer = Some(signer); + self + } + #[inline(always)] + pub fn automation(&mut self, automation: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.automation = Some(automation); + self + } + #[inline(always)] + pub fn executor(&mut self, executor: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.executor = Some(executor); + self + } + #[inline(always)] + pub fn miner(&mut self, miner: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.miner = Some(miner); + self + } + #[inline(always)] + pub fn system_program(&mut self, system_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.system_program = Some(system_program); + self + } + #[inline(always)] + pub fn amount(&mut self, amount: u64) -> &mut Self { + self.instruction.amount = Some(amount); + self + } + #[inline(always)] + pub fn deposit(&mut self, deposit: u64) -> &mut Self { + self.instruction.deposit = Some(deposit); + self + } + #[inline(always)] + pub fn fee(&mut self, fee: u64) -> &mut Self { + self.instruction.fee = Some(fee); + self + } + #[inline(always)] + pub fn mask(&mut self, mask: u64) -> &mut Self { + self.instruction.mask = Some(mask); + self + } + #[inline(always)] + pub fn strategy(&mut self, strategy: u8) -> &mut Self { + self.instruction.strategy = Some(strategy); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: &'b solana_account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self { + self.instruction.__remaining_accounts.push((account, is_writable, is_signer)); + self + } + /// Add additional accounts to the instruction. + /// + /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not, + /// and a `bool` indicating whether the account is a signer or not. + #[inline(always)] + pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self { + self.instruction.__remaining_accounts.extend_from_slice(accounts); + self + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed(&[]) + } + #[allow(clippy::clone_on_copy)] + #[allow(clippy::vec_init_then_push)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult { + let args = AutomateInstructionArgs { + amount: self.instruction.amount.clone().expect("amount is not set"), + deposit: self.instruction.deposit.clone().expect("deposit is not set"), + fee: self.instruction.fee.clone().expect("fee is not set"), + mask: self.instruction.mask.clone().expect("mask is not set"), + strategy: self.instruction.strategy.clone().expect("strategy is not set"), + }; + let instruction = AutomateCpi { + __program: self.instruction.__program, + + signer: self.instruction.signer.expect("signer is not set"), + + automation: self.instruction.automation.expect("automation is not set"), + + executor: self.instruction.executor.expect("executor is not set"), + + miner: self.instruction.miner.expect("miner is not set"), + + system_program: self.instruction.system_program.expect("system_program is not set"), + __args: args, + }; + instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts) + } +} + +#[derive(Clone, Debug)] +struct AutomateCpiBuilderInstruction<'a, 'b> { + __program: &'b solana_account_info::AccountInfo<'a>, + signer: Option<&'b solana_account_info::AccountInfo<'a>>, + automation: Option<&'b solana_account_info::AccountInfo<'a>>, + executor: Option<&'b solana_account_info::AccountInfo<'a>>, + miner: Option<&'b solana_account_info::AccountInfo<'a>>, + system_program: Option<&'b solana_account_info::AccountInfo<'a>>, + amount: Option, + deposit: Option, + fee: Option, + mask: Option, + strategy: Option, + /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`. + __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>, +} + diff --git a/clients/rust/src/generated/instructions/bury.rs b/clients/rust/src/generated/instructions/bury.rs new file mode 100644 index 00000000..fad5210e --- /dev/null +++ b/clients/rust/src/generated/instructions/bury.rs @@ -0,0 +1,549 @@ +//! 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. +//! +//! +//! + +use borsh::BorshSerialize; +use borsh::BorshDeserialize; + +pub const BURY_DISCRIMINATOR: u8 = 13; + +/// Accounts. +#[derive(Debug)] +pub struct Bury { + + + pub signer: solana_pubkey::Pubkey, + + + pub board: solana_pubkey::Pubkey, + + + pub config: solana_pubkey::Pubkey, + + + pub mint: solana_pubkey::Pubkey, + + + pub treasury: solana_pubkey::Pubkey, + + + pub treasury_ore: solana_pubkey::Pubkey, + + + pub treasury_sol: solana_pubkey::Pubkey, + + + pub token_program: solana_pubkey::Pubkey, + + + pub ore_program: solana_pubkey::Pubkey, + } + +impl Bury { + pub fn instruction(&self) -> solana_instruction::Instruction { + self.instruction_with_remaining_accounts(&[]) + } + #[allow(clippy::arithmetic_side_effects)] + #[allow(clippy::vec_init_then_push)] + pub fn instruction_with_remaining_accounts(&self, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction { + let mut accounts = Vec::with_capacity(9+ remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.signer, + true + )); + accounts.push(solana_instruction::AccountMeta::new( + self.board, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.config, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.mint, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.treasury, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.treasury_ore, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.treasury_sol, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.token_program, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.ore_program, + false + )); + accounts.extend_from_slice(remaining_accounts); + let data = BuryInstructionData::new().try_to_vec().unwrap(); + + solana_instruction::Instruction { + program_id: crate::ORE_ID, + accounts, + data, + } + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] + pub struct BuryInstructionData { + discriminator: u8, + } + +impl BuryInstructionData { + pub fn new() -> Self { + Self { + discriminator: 13, + } + } + + pub(crate) fn try_to_vec(&self) -> Result, std::io::Error> { + borsh::to_vec(self) + } + } + +impl Default for BuryInstructionData { + fn default() -> Self { + Self::new() + } +} + + + +/// Instruction builder for `Bury`. +/// +/// ### Accounts: +/// + /// 0. `[signer]` signer + /// 1. `[writable]` board + /// 2. `[]` config + /// 3. `[]` mint + /// 4. `[writable]` treasury + /// 5. `[writable]` treasury_ore + /// 6. `[writable]` treasury_sol + /// 7. `[optional]` token_program (default to `TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA`) + /// 8. `[]` ore_program +#[derive(Clone, Debug, Default)] +pub struct BuryBuilder { + signer: Option, + board: Option, + config: Option, + mint: Option, + treasury: Option, + treasury_ore: Option, + treasury_sol: Option, + token_program: Option, + ore_program: Option, + __remaining_accounts: Vec, +} + +impl BuryBuilder { + pub fn new() -> Self { + Self::default() + } + #[inline(always)] + pub fn signer(&mut self, signer: solana_pubkey::Pubkey) -> &mut Self { + self.signer = Some(signer); + self + } + #[inline(always)] + pub fn board(&mut self, board: solana_pubkey::Pubkey) -> &mut Self { + self.board = Some(board); + self + } + #[inline(always)] + pub fn config(&mut self, config: solana_pubkey::Pubkey) -> &mut Self { + self.config = Some(config); + self + } + #[inline(always)] + pub fn mint(&mut self, mint: solana_pubkey::Pubkey) -> &mut Self { + self.mint = Some(mint); + self + } + #[inline(always)] + pub fn treasury(&mut self, treasury: solana_pubkey::Pubkey) -> &mut Self { + self.treasury = Some(treasury); + self + } + #[inline(always)] + pub fn treasury_ore(&mut self, treasury_ore: solana_pubkey::Pubkey) -> &mut Self { + self.treasury_ore = Some(treasury_ore); + self + } + #[inline(always)] + pub fn treasury_sol(&mut self, treasury_sol: solana_pubkey::Pubkey) -> &mut Self { + self.treasury_sol = Some(treasury_sol); + self + } + /// `[optional account, default to 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA']` +#[inline(always)] + pub fn token_program(&mut self, token_program: solana_pubkey::Pubkey) -> &mut Self { + self.token_program = Some(token_program); + self + } + #[inline(always)] + pub fn ore_program(&mut self, ore_program: solana_pubkey::Pubkey) -> &mut Self { + self.ore_program = Some(ore_program); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self { + self.__remaining_accounts.push(account); + self + } + /// Add additional accounts to the instruction. + #[inline(always)] + pub fn add_remaining_accounts(&mut self, accounts: &[solana_instruction::AccountMeta]) -> &mut Self { + self.__remaining_accounts.extend_from_slice(accounts); + self + } + #[allow(clippy::clone_on_copy)] + pub fn instruction(&self) -> solana_instruction::Instruction { + let accounts = Bury { + signer: self.signer.expect("signer is not set"), + board: self.board.expect("board is not set"), + config: self.config.expect("config is not set"), + mint: self.mint.expect("mint is not set"), + treasury: self.treasury.expect("treasury is not set"), + treasury_ore: self.treasury_ore.expect("treasury_ore is not set"), + treasury_sol: self.treasury_sol.expect("treasury_sol is not set"), + token_program: self.token_program.unwrap_or(solana_pubkey::pubkey!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA")), + ore_program: self.ore_program.expect("ore_program is not set"), + }; + + accounts.instruction_with_remaining_accounts(&self.__remaining_accounts) + } +} + + /// `bury` CPI accounts. + pub struct BuryCpiAccounts<'a, 'b> { + + + pub signer: &'b solana_account_info::AccountInfo<'a>, + + + pub board: &'b solana_account_info::AccountInfo<'a>, + + + pub config: &'b solana_account_info::AccountInfo<'a>, + + + pub mint: &'b solana_account_info::AccountInfo<'a>, + + + pub treasury: &'b solana_account_info::AccountInfo<'a>, + + + pub treasury_ore: &'b solana_account_info::AccountInfo<'a>, + + + pub treasury_sol: &'b solana_account_info::AccountInfo<'a>, + + + pub token_program: &'b solana_account_info::AccountInfo<'a>, + + + pub ore_program: &'b solana_account_info::AccountInfo<'a>, + } + +/// `bury` CPI instruction. +pub struct BuryCpi<'a, 'b> { + /// The program to invoke. + pub __program: &'b solana_account_info::AccountInfo<'a>, + + + pub signer: &'b solana_account_info::AccountInfo<'a>, + + + pub board: &'b solana_account_info::AccountInfo<'a>, + + + pub config: &'b solana_account_info::AccountInfo<'a>, + + + pub mint: &'b solana_account_info::AccountInfo<'a>, + + + pub treasury: &'b solana_account_info::AccountInfo<'a>, + + + pub treasury_ore: &'b solana_account_info::AccountInfo<'a>, + + + pub treasury_sol: &'b solana_account_info::AccountInfo<'a>, + + + pub token_program: &'b solana_account_info::AccountInfo<'a>, + + + pub ore_program: &'b solana_account_info::AccountInfo<'a>, + } + +impl<'a, 'b> BuryCpi<'a, 'b> { + pub fn new( + program: &'b solana_account_info::AccountInfo<'a>, + accounts: BuryCpiAccounts<'a, 'b>, + ) -> Self { + Self { + __program: program, + signer: accounts.signer, + board: accounts.board, + config: accounts.config, + mint: accounts.mint, + treasury: accounts.treasury, + treasury_ore: accounts.treasury_ore, + treasury_sol: accounts.treasury_sol, + token_program: accounts.token_program, + ore_program: accounts.ore_program, + } + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], &[]) + } + #[inline(always)] + pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], remaining_accounts) + } + #[inline(always)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(signers_seeds, &[]) + } + #[allow(clippy::arithmetic_side_effects)] + #[allow(clippy::clone_on_copy)] + #[allow(clippy::vec_init_then_push)] + pub fn invoke_signed_with_remaining_accounts( + &self, + signers_seeds: &[&[&[u8]]], + remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)] + ) -> solana_program_error::ProgramResult { + let mut accounts = Vec::with_capacity(9+ remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.signer.key, + true + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.board.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.config.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.mint.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.treasury.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.treasury_ore.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.treasury_sol.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.token_program.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.ore_program.key, + false + )); + remaining_accounts.iter().for_each(|remaining_account| { + accounts.push(solana_instruction::AccountMeta { + pubkey: *remaining_account.0.key, + is_signer: remaining_account.1, + is_writable: remaining_account.2, + }) + }); + let data = BuryInstructionData::new().try_to_vec().unwrap(); + + let instruction = solana_instruction::Instruction { + program_id: crate::ORE_ID, + accounts, + data, + }; + let mut account_infos = Vec::with_capacity(10 + remaining_accounts.len()); + account_infos.push(self.__program.clone()); + account_infos.push(self.signer.clone()); + account_infos.push(self.board.clone()); + account_infos.push(self.config.clone()); + account_infos.push(self.mint.clone()); + account_infos.push(self.treasury.clone()); + account_infos.push(self.treasury_ore.clone()); + account_infos.push(self.treasury_sol.clone()); + account_infos.push(self.token_program.clone()); + account_infos.push(self.ore_program.clone()); + remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone())); + + if signers_seeds.is_empty() { + solana_cpi::invoke(&instruction, &account_infos) + } else { + solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds) + } + } +} + +/// Instruction builder for `Bury` via CPI. +/// +/// ### Accounts: +/// + /// 0. `[signer]` signer + /// 1. `[writable]` board + /// 2. `[]` config + /// 3. `[]` mint + /// 4. `[writable]` treasury + /// 5. `[writable]` treasury_ore + /// 6. `[writable]` treasury_sol + /// 7. `[]` token_program + /// 8. `[]` ore_program +#[derive(Clone, Debug)] +pub struct BuryCpiBuilder<'a, 'b> { + instruction: Box>, +} + +impl<'a, 'b> BuryCpiBuilder<'a, 'b> { + pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self { + let instruction = Box::new(BuryCpiBuilderInstruction { + __program: program, + signer: None, + board: None, + config: None, + mint: None, + treasury: None, + treasury_ore: None, + treasury_sol: None, + token_program: None, + ore_program: None, + __remaining_accounts: Vec::new(), + }); + Self { instruction } + } + #[inline(always)] + pub fn signer(&mut self, signer: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.signer = Some(signer); + self + } + #[inline(always)] + pub fn board(&mut self, board: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.board = Some(board); + self + } + #[inline(always)] + pub fn config(&mut self, config: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.config = Some(config); + self + } + #[inline(always)] + pub fn mint(&mut self, mint: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.mint = Some(mint); + self + } + #[inline(always)] + pub fn treasury(&mut self, treasury: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.treasury = Some(treasury); + self + } + #[inline(always)] + pub fn treasury_ore(&mut self, treasury_ore: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.treasury_ore = Some(treasury_ore); + self + } + #[inline(always)] + pub fn treasury_sol(&mut self, treasury_sol: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.treasury_sol = Some(treasury_sol); + self + } + #[inline(always)] + pub fn token_program(&mut self, token_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.token_program = Some(token_program); + self + } + #[inline(always)] + pub fn ore_program(&mut self, ore_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.ore_program = Some(ore_program); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: &'b solana_account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self { + self.instruction.__remaining_accounts.push((account, is_writable, is_signer)); + self + } + /// Add additional accounts to the instruction. + /// + /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not, + /// and a `bool` indicating whether the account is a signer or not. + #[inline(always)] + pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self { + self.instruction.__remaining_accounts.extend_from_slice(accounts); + self + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed(&[]) + } + #[allow(clippy::clone_on_copy)] + #[allow(clippy::vec_init_then_push)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult { + let instruction = BuryCpi { + __program: self.instruction.__program, + + signer: self.instruction.signer.expect("signer is not set"), + + board: self.instruction.board.expect("board is not set"), + + config: self.instruction.config.expect("config is not set"), + + mint: self.instruction.mint.expect("mint is not set"), + + treasury: self.instruction.treasury.expect("treasury is not set"), + + treasury_ore: self.instruction.treasury_ore.expect("treasury_ore is not set"), + + treasury_sol: self.instruction.treasury_sol.expect("treasury_sol is not set"), + + token_program: self.instruction.token_program.expect("token_program is not set"), + + ore_program: self.instruction.ore_program.expect("ore_program is not set"), + }; + instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts) + } +} + +#[derive(Clone, Debug)] +struct BuryCpiBuilderInstruction<'a, 'b> { + __program: &'b solana_account_info::AccountInfo<'a>, + signer: Option<&'b solana_account_info::AccountInfo<'a>>, + board: Option<&'b solana_account_info::AccountInfo<'a>>, + config: Option<&'b solana_account_info::AccountInfo<'a>>, + mint: Option<&'b solana_account_info::AccountInfo<'a>>, + treasury: Option<&'b solana_account_info::AccountInfo<'a>>, + treasury_ore: Option<&'b solana_account_info::AccountInfo<'a>>, + treasury_sol: Option<&'b solana_account_info::AccountInfo<'a>>, + token_program: Option<&'b solana_account_info::AccountInfo<'a>>, + ore_program: Option<&'b solana_account_info::AccountInfo<'a>>, + /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`. + __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>, +} + diff --git a/clients/rust/src/generated/instructions/checkpoint.rs b/clients/rust/src/generated/instructions/checkpoint.rs new file mode 100644 index 00000000..e99c6905 --- /dev/null +++ b/clients/rust/src/generated/instructions/checkpoint.rs @@ -0,0 +1,438 @@ +//! 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. +//! +//! +//! + +use borsh::BorshSerialize; +use borsh::BorshDeserialize; + +pub const CHECKPOINT_DISCRIMINATOR: u8 = 2; + +/// Accounts. +#[derive(Debug)] +pub struct Checkpoint { + + + pub signer: solana_pubkey::Pubkey, + + + pub board: solana_pubkey::Pubkey, + + + pub miner: solana_pubkey::Pubkey, + + + pub round: solana_pubkey::Pubkey, + + + pub treasury: solana_pubkey::Pubkey, + + + pub system_program: solana_pubkey::Pubkey, + } + +impl Checkpoint { + pub fn instruction(&self) -> solana_instruction::Instruction { + self.instruction_with_remaining_accounts(&[]) + } + #[allow(clippy::arithmetic_side_effects)] + #[allow(clippy::vec_init_then_push)] + pub fn instruction_with_remaining_accounts(&self, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction { + let mut accounts = Vec::with_capacity(6+ remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new( + self.signer, + true + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.board, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.miner, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.round, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.treasury, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.system_program, + false + )); + accounts.extend_from_slice(remaining_accounts); + let data = CheckpointInstructionData::new().try_to_vec().unwrap(); + + solana_instruction::Instruction { + program_id: crate::ORE_ID, + accounts, + data, + } + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] + pub struct CheckpointInstructionData { + discriminator: u8, + } + +impl CheckpointInstructionData { + pub fn new() -> Self { + Self { + discriminator: 2, + } + } + + pub(crate) fn try_to_vec(&self) -> Result, std::io::Error> { + borsh::to_vec(self) + } + } + +impl Default for CheckpointInstructionData { + fn default() -> Self { + Self::new() + } +} + + + +/// Instruction builder for `Checkpoint`. +/// +/// ### Accounts: +/// + /// 0. `[writable, signer]` signer + /// 1. `[]` board + /// 2. `[writable]` miner + /// 3. `[writable]` round + /// 4. `[writable]` treasury + /// 5. `[optional]` system_program (default to `11111111111111111111111111111111`) +#[derive(Clone, Debug, Default)] +pub struct CheckpointBuilder { + signer: Option, + board: Option, + miner: Option, + round: Option, + treasury: Option, + system_program: Option, + __remaining_accounts: Vec, +} + +impl CheckpointBuilder { + pub fn new() -> Self { + Self::default() + } + #[inline(always)] + pub fn signer(&mut self, signer: solana_pubkey::Pubkey) -> &mut Self { + self.signer = Some(signer); + self + } + #[inline(always)] + pub fn board(&mut self, board: solana_pubkey::Pubkey) -> &mut Self { + self.board = Some(board); + self + } + #[inline(always)] + pub fn miner(&mut self, miner: solana_pubkey::Pubkey) -> &mut Self { + self.miner = Some(miner); + self + } + #[inline(always)] + pub fn round(&mut self, round: solana_pubkey::Pubkey) -> &mut Self { + self.round = Some(round); + self + } + #[inline(always)] + pub fn treasury(&mut self, treasury: solana_pubkey::Pubkey) -> &mut Self { + self.treasury = Some(treasury); + self + } + /// `[optional account, default to '11111111111111111111111111111111']` +#[inline(always)] + pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self { + self.system_program = Some(system_program); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self { + self.__remaining_accounts.push(account); + self + } + /// Add additional accounts to the instruction. + #[inline(always)] + pub fn add_remaining_accounts(&mut self, accounts: &[solana_instruction::AccountMeta]) -> &mut Self { + self.__remaining_accounts.extend_from_slice(accounts); + self + } + #[allow(clippy::clone_on_copy)] + pub fn instruction(&self) -> solana_instruction::Instruction { + let accounts = Checkpoint { + signer: self.signer.expect("signer is not set"), + board: self.board.expect("board is not set"), + miner: self.miner.expect("miner is not set"), + round: self.round.expect("round is not set"), + treasury: self.treasury.expect("treasury is not set"), + system_program: self.system_program.unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")), + }; + + accounts.instruction_with_remaining_accounts(&self.__remaining_accounts) + } +} + + /// `checkpoint` CPI accounts. + pub struct CheckpointCpiAccounts<'a, 'b> { + + + pub signer: &'b solana_account_info::AccountInfo<'a>, + + + pub board: &'b solana_account_info::AccountInfo<'a>, + + + pub miner: &'b solana_account_info::AccountInfo<'a>, + + + pub round: &'b solana_account_info::AccountInfo<'a>, + + + pub treasury: &'b solana_account_info::AccountInfo<'a>, + + + pub system_program: &'b solana_account_info::AccountInfo<'a>, + } + +/// `checkpoint` CPI instruction. +pub struct CheckpointCpi<'a, 'b> { + /// The program to invoke. + pub __program: &'b solana_account_info::AccountInfo<'a>, + + + pub signer: &'b solana_account_info::AccountInfo<'a>, + + + pub board: &'b solana_account_info::AccountInfo<'a>, + + + pub miner: &'b solana_account_info::AccountInfo<'a>, + + + pub round: &'b solana_account_info::AccountInfo<'a>, + + + pub treasury: &'b solana_account_info::AccountInfo<'a>, + + + pub system_program: &'b solana_account_info::AccountInfo<'a>, + } + +impl<'a, 'b> CheckpointCpi<'a, 'b> { + pub fn new( + program: &'b solana_account_info::AccountInfo<'a>, + accounts: CheckpointCpiAccounts<'a, 'b>, + ) -> Self { + Self { + __program: program, + signer: accounts.signer, + board: accounts.board, + miner: accounts.miner, + round: accounts.round, + treasury: accounts.treasury, + system_program: accounts.system_program, + } + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], &[]) + } + #[inline(always)] + pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], remaining_accounts) + } + #[inline(always)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(signers_seeds, &[]) + } + #[allow(clippy::arithmetic_side_effects)] + #[allow(clippy::clone_on_copy)] + #[allow(clippy::vec_init_then_push)] + pub fn invoke_signed_with_remaining_accounts( + &self, + signers_seeds: &[&[&[u8]]], + remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)] + ) -> solana_program_error::ProgramResult { + let mut accounts = Vec::with_capacity(6+ remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new( + *self.signer.key, + true + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.board.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.miner.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.round.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.treasury.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.system_program.key, + false + )); + remaining_accounts.iter().for_each(|remaining_account| { + accounts.push(solana_instruction::AccountMeta { + pubkey: *remaining_account.0.key, + is_signer: remaining_account.1, + is_writable: remaining_account.2, + }) + }); + let data = CheckpointInstructionData::new().try_to_vec().unwrap(); + + let instruction = solana_instruction::Instruction { + program_id: crate::ORE_ID, + accounts, + data, + }; + let mut account_infos = Vec::with_capacity(7 + remaining_accounts.len()); + account_infos.push(self.__program.clone()); + account_infos.push(self.signer.clone()); + account_infos.push(self.board.clone()); + account_infos.push(self.miner.clone()); + account_infos.push(self.round.clone()); + account_infos.push(self.treasury.clone()); + account_infos.push(self.system_program.clone()); + remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone())); + + if signers_seeds.is_empty() { + solana_cpi::invoke(&instruction, &account_infos) + } else { + solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds) + } + } +} + +/// Instruction builder for `Checkpoint` via CPI. +/// +/// ### Accounts: +/// + /// 0. `[writable, signer]` signer + /// 1. `[]` board + /// 2. `[writable]` miner + /// 3. `[writable]` round + /// 4. `[writable]` treasury + /// 5. `[]` system_program +#[derive(Clone, Debug)] +pub struct CheckpointCpiBuilder<'a, 'b> { + instruction: Box>, +} + +impl<'a, 'b> CheckpointCpiBuilder<'a, 'b> { + pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self { + let instruction = Box::new(CheckpointCpiBuilderInstruction { + __program: program, + signer: None, + board: None, + miner: None, + round: None, + treasury: None, + system_program: None, + __remaining_accounts: Vec::new(), + }); + Self { instruction } + } + #[inline(always)] + pub fn signer(&mut self, signer: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.signer = Some(signer); + self + } + #[inline(always)] + pub fn board(&mut self, board: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.board = Some(board); + self + } + #[inline(always)] + pub fn miner(&mut self, miner: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.miner = Some(miner); + self + } + #[inline(always)] + pub fn round(&mut self, round: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.round = Some(round); + self + } + #[inline(always)] + pub fn treasury(&mut self, treasury: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.treasury = Some(treasury); + self + } + #[inline(always)] + pub fn system_program(&mut self, system_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.system_program = Some(system_program); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: &'b solana_account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self { + self.instruction.__remaining_accounts.push((account, is_writable, is_signer)); + self + } + /// Add additional accounts to the instruction. + /// + /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not, + /// and a `bool` indicating whether the account is a signer or not. + #[inline(always)] + pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self { + self.instruction.__remaining_accounts.extend_from_slice(accounts); + self + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed(&[]) + } + #[allow(clippy::clone_on_copy)] + #[allow(clippy::vec_init_then_push)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult { + let instruction = CheckpointCpi { + __program: self.instruction.__program, + + signer: self.instruction.signer.expect("signer is not set"), + + board: self.instruction.board.expect("board is not set"), + + miner: self.instruction.miner.expect("miner is not set"), + + round: self.instruction.round.expect("round is not set"), + + treasury: self.instruction.treasury.expect("treasury is not set"), + + system_program: self.instruction.system_program.expect("system_program is not set"), + }; + instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts) + } +} + +#[derive(Clone, Debug)] +struct CheckpointCpiBuilderInstruction<'a, 'b> { + __program: &'b solana_account_info::AccountInfo<'a>, + signer: Option<&'b solana_account_info::AccountInfo<'a>>, + board: Option<&'b solana_account_info::AccountInfo<'a>>, + miner: Option<&'b solana_account_info::AccountInfo<'a>>, + round: Option<&'b solana_account_info::AccountInfo<'a>>, + treasury: Option<&'b solana_account_info::AccountInfo<'a>>, + system_program: Option<&'b solana_account_info::AccountInfo<'a>>, + /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`. + __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>, +} + diff --git a/clients/rust/src/generated/instructions/claim_ore.rs b/clients/rust/src/generated/instructions/claim_ore.rs new file mode 100644 index 00000000..edd27c95 --- /dev/null +++ b/clients/rust/src/generated/instructions/claim_ore.rs @@ -0,0 +1,550 @@ +//! 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. +//! +//! +//! + +use borsh::BorshSerialize; +use borsh::BorshDeserialize; + +pub const CLAIM_ORE_DISCRIMINATOR: u8 = 4; + +/// Accounts. +#[derive(Debug)] +pub struct ClaimOre { + + + pub signer: solana_pubkey::Pubkey, + + + pub miner: solana_pubkey::Pubkey, + + + pub mint: solana_pubkey::Pubkey, + + + pub recipient: solana_pubkey::Pubkey, + + + pub treasury: solana_pubkey::Pubkey, + + + pub treasury_tokens: solana_pubkey::Pubkey, + + + pub system_program: solana_pubkey::Pubkey, + + + pub token_program: solana_pubkey::Pubkey, + + + pub associated_token_program: solana_pubkey::Pubkey, + } + +impl ClaimOre { + pub fn instruction(&self) -> solana_instruction::Instruction { + self.instruction_with_remaining_accounts(&[]) + } + #[allow(clippy::arithmetic_side_effects)] + #[allow(clippy::vec_init_then_push)] + pub fn instruction_with_remaining_accounts(&self, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction { + let mut accounts = Vec::with_capacity(9+ remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new( + self.signer, + true + )); + accounts.push(solana_instruction::AccountMeta::new( + self.miner, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.mint, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.recipient, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.treasury, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.treasury_tokens, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.system_program, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.token_program, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.associated_token_program, + false + )); + accounts.extend_from_slice(remaining_accounts); + let data = ClaimOreInstructionData::new().try_to_vec().unwrap(); + + solana_instruction::Instruction { + program_id: crate::ORE_ID, + accounts, + data, + } + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] + pub struct ClaimOreInstructionData { + discriminator: u8, + } + +impl ClaimOreInstructionData { + pub fn new() -> Self { + Self { + discriminator: 4, + } + } + + pub(crate) fn try_to_vec(&self) -> Result, std::io::Error> { + borsh::to_vec(self) + } + } + +impl Default for ClaimOreInstructionData { + fn default() -> Self { + Self::new() + } +} + + + +/// Instruction builder for `ClaimOre`. +/// +/// ### Accounts: +/// + /// 0. `[writable, signer]` signer + /// 1. `[writable]` miner + /// 2. `[]` mint + /// 3. `[writable]` recipient + /// 4. `[writable]` treasury + /// 5. `[writable]` treasury_tokens + /// 6. `[optional]` system_program (default to `11111111111111111111111111111111`) + /// 7. `[optional]` token_program (default to `TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA`) + /// 8. `[]` associated_token_program +#[derive(Clone, Debug, Default)] +pub struct ClaimOreBuilder { + signer: Option, + miner: Option, + mint: Option, + recipient: Option, + treasury: Option, + treasury_tokens: Option, + system_program: Option, + token_program: Option, + associated_token_program: Option, + __remaining_accounts: Vec, +} + +impl ClaimOreBuilder { + pub fn new() -> Self { + Self::default() + } + #[inline(always)] + pub fn signer(&mut self, signer: solana_pubkey::Pubkey) -> &mut Self { + self.signer = Some(signer); + self + } + #[inline(always)] + pub fn miner(&mut self, miner: solana_pubkey::Pubkey) -> &mut Self { + self.miner = Some(miner); + self + } + #[inline(always)] + pub fn mint(&mut self, mint: solana_pubkey::Pubkey) -> &mut Self { + self.mint = Some(mint); + self + } + #[inline(always)] + pub fn recipient(&mut self, recipient: solana_pubkey::Pubkey) -> &mut Self { + self.recipient = Some(recipient); + self + } + #[inline(always)] + pub fn treasury(&mut self, treasury: solana_pubkey::Pubkey) -> &mut Self { + self.treasury = Some(treasury); + self + } + #[inline(always)] + pub fn treasury_tokens(&mut self, treasury_tokens: solana_pubkey::Pubkey) -> &mut Self { + self.treasury_tokens = Some(treasury_tokens); + self + } + /// `[optional account, default to '11111111111111111111111111111111']` +#[inline(always)] + pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self { + self.system_program = Some(system_program); + self + } + /// `[optional account, default to 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA']` +#[inline(always)] + pub fn token_program(&mut self, token_program: solana_pubkey::Pubkey) -> &mut Self { + self.token_program = Some(token_program); + self + } + #[inline(always)] + pub fn associated_token_program(&mut self, associated_token_program: solana_pubkey::Pubkey) -> &mut Self { + self.associated_token_program = Some(associated_token_program); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self { + self.__remaining_accounts.push(account); + self + } + /// Add additional accounts to the instruction. + #[inline(always)] + pub fn add_remaining_accounts(&mut self, accounts: &[solana_instruction::AccountMeta]) -> &mut Self { + self.__remaining_accounts.extend_from_slice(accounts); + self + } + #[allow(clippy::clone_on_copy)] + pub fn instruction(&self) -> solana_instruction::Instruction { + let accounts = ClaimOre { + signer: self.signer.expect("signer is not set"), + miner: self.miner.expect("miner is not set"), + mint: self.mint.expect("mint is not set"), + recipient: self.recipient.expect("recipient is not set"), + treasury: self.treasury.expect("treasury is not set"), + treasury_tokens: self.treasury_tokens.expect("treasury_tokens is not set"), + system_program: self.system_program.unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")), + token_program: self.token_program.unwrap_or(solana_pubkey::pubkey!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA")), + associated_token_program: self.associated_token_program.expect("associated_token_program is not set"), + }; + + accounts.instruction_with_remaining_accounts(&self.__remaining_accounts) + } +} + + /// `claim_ore` CPI accounts. + pub struct ClaimOreCpiAccounts<'a, 'b> { + + + pub signer: &'b solana_account_info::AccountInfo<'a>, + + + pub miner: &'b solana_account_info::AccountInfo<'a>, + + + pub mint: &'b solana_account_info::AccountInfo<'a>, + + + pub recipient: &'b solana_account_info::AccountInfo<'a>, + + + pub treasury: &'b solana_account_info::AccountInfo<'a>, + + + pub treasury_tokens: &'b solana_account_info::AccountInfo<'a>, + + + pub system_program: &'b solana_account_info::AccountInfo<'a>, + + + pub token_program: &'b solana_account_info::AccountInfo<'a>, + + + pub associated_token_program: &'b solana_account_info::AccountInfo<'a>, + } + +/// `claim_ore` CPI instruction. +pub struct ClaimOreCpi<'a, 'b> { + /// The program to invoke. + pub __program: &'b solana_account_info::AccountInfo<'a>, + + + pub signer: &'b solana_account_info::AccountInfo<'a>, + + + pub miner: &'b solana_account_info::AccountInfo<'a>, + + + pub mint: &'b solana_account_info::AccountInfo<'a>, + + + pub recipient: &'b solana_account_info::AccountInfo<'a>, + + + pub treasury: &'b solana_account_info::AccountInfo<'a>, + + + pub treasury_tokens: &'b solana_account_info::AccountInfo<'a>, + + + pub system_program: &'b solana_account_info::AccountInfo<'a>, + + + pub token_program: &'b solana_account_info::AccountInfo<'a>, + + + pub associated_token_program: &'b solana_account_info::AccountInfo<'a>, + } + +impl<'a, 'b> ClaimOreCpi<'a, 'b> { + pub fn new( + program: &'b solana_account_info::AccountInfo<'a>, + accounts: ClaimOreCpiAccounts<'a, 'b>, + ) -> Self { + Self { + __program: program, + signer: accounts.signer, + miner: accounts.miner, + mint: accounts.mint, + recipient: accounts.recipient, + treasury: accounts.treasury, + treasury_tokens: accounts.treasury_tokens, + system_program: accounts.system_program, + token_program: accounts.token_program, + associated_token_program: accounts.associated_token_program, + } + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], &[]) + } + #[inline(always)] + pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], remaining_accounts) + } + #[inline(always)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(signers_seeds, &[]) + } + #[allow(clippy::arithmetic_side_effects)] + #[allow(clippy::clone_on_copy)] + #[allow(clippy::vec_init_then_push)] + pub fn invoke_signed_with_remaining_accounts( + &self, + signers_seeds: &[&[&[u8]]], + remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)] + ) -> solana_program_error::ProgramResult { + let mut accounts = Vec::with_capacity(9+ remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new( + *self.signer.key, + true + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.miner.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.mint.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.recipient.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.treasury.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.treasury_tokens.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.system_program.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.token_program.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.associated_token_program.key, + false + )); + remaining_accounts.iter().for_each(|remaining_account| { + accounts.push(solana_instruction::AccountMeta { + pubkey: *remaining_account.0.key, + is_signer: remaining_account.1, + is_writable: remaining_account.2, + }) + }); + let data = ClaimOreInstructionData::new().try_to_vec().unwrap(); + + let instruction = solana_instruction::Instruction { + program_id: crate::ORE_ID, + accounts, + data, + }; + let mut account_infos = Vec::with_capacity(10 + remaining_accounts.len()); + account_infos.push(self.__program.clone()); + account_infos.push(self.signer.clone()); + account_infos.push(self.miner.clone()); + account_infos.push(self.mint.clone()); + account_infos.push(self.recipient.clone()); + account_infos.push(self.treasury.clone()); + account_infos.push(self.treasury_tokens.clone()); + account_infos.push(self.system_program.clone()); + account_infos.push(self.token_program.clone()); + account_infos.push(self.associated_token_program.clone()); + remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone())); + + if signers_seeds.is_empty() { + solana_cpi::invoke(&instruction, &account_infos) + } else { + solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds) + } + } +} + +/// Instruction builder for `ClaimOre` via CPI. +/// +/// ### Accounts: +/// + /// 0. `[writable, signer]` signer + /// 1. `[writable]` miner + /// 2. `[]` mint + /// 3. `[writable]` recipient + /// 4. `[writable]` treasury + /// 5. `[writable]` treasury_tokens + /// 6. `[]` system_program + /// 7. `[]` token_program + /// 8. `[]` associated_token_program +#[derive(Clone, Debug)] +pub struct ClaimOreCpiBuilder<'a, 'b> { + instruction: Box>, +} + +impl<'a, 'b> ClaimOreCpiBuilder<'a, 'b> { + pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self { + let instruction = Box::new(ClaimOreCpiBuilderInstruction { + __program: program, + signer: None, + miner: None, + mint: None, + recipient: None, + treasury: None, + treasury_tokens: None, + system_program: None, + token_program: None, + associated_token_program: None, + __remaining_accounts: Vec::new(), + }); + Self { instruction } + } + #[inline(always)] + pub fn signer(&mut self, signer: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.signer = Some(signer); + self + } + #[inline(always)] + pub fn miner(&mut self, miner: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.miner = Some(miner); + self + } + #[inline(always)] + pub fn mint(&mut self, mint: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.mint = Some(mint); + self + } + #[inline(always)] + pub fn recipient(&mut self, recipient: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.recipient = Some(recipient); + self + } + #[inline(always)] + pub fn treasury(&mut self, treasury: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.treasury = Some(treasury); + self + } + #[inline(always)] + pub fn treasury_tokens(&mut self, treasury_tokens: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.treasury_tokens = Some(treasury_tokens); + self + } + #[inline(always)] + pub fn system_program(&mut self, system_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.system_program = Some(system_program); + self + } + #[inline(always)] + pub fn token_program(&mut self, token_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.token_program = Some(token_program); + self + } + #[inline(always)] + pub fn associated_token_program(&mut self, associated_token_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.associated_token_program = Some(associated_token_program); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: &'b solana_account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self { + self.instruction.__remaining_accounts.push((account, is_writable, is_signer)); + self + } + /// Add additional accounts to the instruction. + /// + /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not, + /// and a `bool` indicating whether the account is a signer or not. + #[inline(always)] + pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self { + self.instruction.__remaining_accounts.extend_from_slice(accounts); + self + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed(&[]) + } + #[allow(clippy::clone_on_copy)] + #[allow(clippy::vec_init_then_push)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult { + let instruction = ClaimOreCpi { + __program: self.instruction.__program, + + signer: self.instruction.signer.expect("signer is not set"), + + miner: self.instruction.miner.expect("miner is not set"), + + mint: self.instruction.mint.expect("mint is not set"), + + recipient: self.instruction.recipient.expect("recipient is not set"), + + treasury: self.instruction.treasury.expect("treasury is not set"), + + treasury_tokens: self.instruction.treasury_tokens.expect("treasury_tokens is not set"), + + system_program: self.instruction.system_program.expect("system_program is not set"), + + token_program: self.instruction.token_program.expect("token_program is not set"), + + associated_token_program: self.instruction.associated_token_program.expect("associated_token_program is not set"), + }; + instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts) + } +} + +#[derive(Clone, Debug)] +struct ClaimOreCpiBuilderInstruction<'a, 'b> { + __program: &'b solana_account_info::AccountInfo<'a>, + signer: Option<&'b solana_account_info::AccountInfo<'a>>, + miner: Option<&'b solana_account_info::AccountInfo<'a>>, + mint: Option<&'b solana_account_info::AccountInfo<'a>>, + recipient: Option<&'b solana_account_info::AccountInfo<'a>>, + treasury: Option<&'b solana_account_info::AccountInfo<'a>>, + treasury_tokens: Option<&'b solana_account_info::AccountInfo<'a>>, + system_program: Option<&'b solana_account_info::AccountInfo<'a>>, + token_program: Option<&'b solana_account_info::AccountInfo<'a>>, + associated_token_program: Option<&'b solana_account_info::AccountInfo<'a>>, + /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`. + __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>, +} + diff --git a/clients/rust/src/generated/instructions/claim_sol.rs b/clients/rust/src/generated/instructions/claim_sol.rs new file mode 100644 index 00000000..0c49c461 --- /dev/null +++ b/clients/rust/src/generated/instructions/claim_sol.rs @@ -0,0 +1,327 @@ +//! 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. +//! +//! +//! + +use borsh::BorshSerialize; +use borsh::BorshDeserialize; + +pub const CLAIM_SOL_DISCRIMINATOR: u8 = 3; + +/// Accounts. +#[derive(Debug)] +pub struct ClaimSol { + + + pub signer: solana_pubkey::Pubkey, + + + pub miner: solana_pubkey::Pubkey, + + + pub system_program: solana_pubkey::Pubkey, + } + +impl ClaimSol { + pub fn instruction(&self) -> solana_instruction::Instruction { + self.instruction_with_remaining_accounts(&[]) + } + #[allow(clippy::arithmetic_side_effects)] + #[allow(clippy::vec_init_then_push)] + pub fn instruction_with_remaining_accounts(&self, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction { + let mut accounts = Vec::with_capacity(3+ remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new( + self.signer, + true + )); + accounts.push(solana_instruction::AccountMeta::new( + self.miner, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.system_program, + false + )); + accounts.extend_from_slice(remaining_accounts); + let data = ClaimSolInstructionData::new().try_to_vec().unwrap(); + + solana_instruction::Instruction { + program_id: crate::ORE_ID, + accounts, + data, + } + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] + pub struct ClaimSolInstructionData { + discriminator: u8, + } + +impl ClaimSolInstructionData { + pub fn new() -> Self { + Self { + discriminator: 3, + } + } + + pub(crate) fn try_to_vec(&self) -> Result, std::io::Error> { + borsh::to_vec(self) + } + } + +impl Default for ClaimSolInstructionData { + fn default() -> Self { + Self::new() + } +} + + + +/// Instruction builder for `ClaimSol`. +/// +/// ### Accounts: +/// + /// 0. `[writable, signer]` signer + /// 1. `[writable]` miner + /// 2. `[optional]` system_program (default to `11111111111111111111111111111111`) +#[derive(Clone, Debug, Default)] +pub struct ClaimSolBuilder { + signer: Option, + miner: Option, + system_program: Option, + __remaining_accounts: Vec, +} + +impl ClaimSolBuilder { + pub fn new() -> Self { + Self::default() + } + #[inline(always)] + pub fn signer(&mut self, signer: solana_pubkey::Pubkey) -> &mut Self { + self.signer = Some(signer); + self + } + #[inline(always)] + pub fn miner(&mut self, miner: solana_pubkey::Pubkey) -> &mut Self { + self.miner = Some(miner); + self + } + /// `[optional account, default to '11111111111111111111111111111111']` +#[inline(always)] + pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self { + self.system_program = Some(system_program); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self { + self.__remaining_accounts.push(account); + self + } + /// Add additional accounts to the instruction. + #[inline(always)] + pub fn add_remaining_accounts(&mut self, accounts: &[solana_instruction::AccountMeta]) -> &mut Self { + self.__remaining_accounts.extend_from_slice(accounts); + self + } + #[allow(clippy::clone_on_copy)] + pub fn instruction(&self) -> solana_instruction::Instruction { + let accounts = ClaimSol { + signer: self.signer.expect("signer is not set"), + miner: self.miner.expect("miner is not set"), + system_program: self.system_program.unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")), + }; + + accounts.instruction_with_remaining_accounts(&self.__remaining_accounts) + } +} + + /// `claim_sol` CPI accounts. + pub struct ClaimSolCpiAccounts<'a, 'b> { + + + pub signer: &'b solana_account_info::AccountInfo<'a>, + + + pub miner: &'b solana_account_info::AccountInfo<'a>, + + + pub system_program: &'b solana_account_info::AccountInfo<'a>, + } + +/// `claim_sol` CPI instruction. +pub struct ClaimSolCpi<'a, 'b> { + /// The program to invoke. + pub __program: &'b solana_account_info::AccountInfo<'a>, + + + pub signer: &'b solana_account_info::AccountInfo<'a>, + + + pub miner: &'b solana_account_info::AccountInfo<'a>, + + + pub system_program: &'b solana_account_info::AccountInfo<'a>, + } + +impl<'a, 'b> ClaimSolCpi<'a, 'b> { + pub fn new( + program: &'b solana_account_info::AccountInfo<'a>, + accounts: ClaimSolCpiAccounts<'a, 'b>, + ) -> Self { + Self { + __program: program, + signer: accounts.signer, + miner: accounts.miner, + system_program: accounts.system_program, + } + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], &[]) + } + #[inline(always)] + pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], remaining_accounts) + } + #[inline(always)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(signers_seeds, &[]) + } + #[allow(clippy::arithmetic_side_effects)] + #[allow(clippy::clone_on_copy)] + #[allow(clippy::vec_init_then_push)] + pub fn invoke_signed_with_remaining_accounts( + &self, + signers_seeds: &[&[&[u8]]], + remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)] + ) -> solana_program_error::ProgramResult { + let mut accounts = Vec::with_capacity(3+ remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new( + *self.signer.key, + true + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.miner.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.system_program.key, + false + )); + remaining_accounts.iter().for_each(|remaining_account| { + accounts.push(solana_instruction::AccountMeta { + pubkey: *remaining_account.0.key, + is_signer: remaining_account.1, + is_writable: remaining_account.2, + }) + }); + let data = ClaimSolInstructionData::new().try_to_vec().unwrap(); + + let instruction = solana_instruction::Instruction { + program_id: crate::ORE_ID, + accounts, + data, + }; + let mut account_infos = Vec::with_capacity(4 + remaining_accounts.len()); + account_infos.push(self.__program.clone()); + account_infos.push(self.signer.clone()); + account_infos.push(self.miner.clone()); + account_infos.push(self.system_program.clone()); + remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone())); + + if signers_seeds.is_empty() { + solana_cpi::invoke(&instruction, &account_infos) + } else { + solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds) + } + } +} + +/// Instruction builder for `ClaimSol` via CPI. +/// +/// ### Accounts: +/// + /// 0. `[writable, signer]` signer + /// 1. `[writable]` miner + /// 2. `[]` system_program +#[derive(Clone, Debug)] +pub struct ClaimSolCpiBuilder<'a, 'b> { + instruction: Box>, +} + +impl<'a, 'b> ClaimSolCpiBuilder<'a, 'b> { + pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self { + let instruction = Box::new(ClaimSolCpiBuilderInstruction { + __program: program, + signer: None, + miner: None, + system_program: None, + __remaining_accounts: Vec::new(), + }); + Self { instruction } + } + #[inline(always)] + pub fn signer(&mut self, signer: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.signer = Some(signer); + self + } + #[inline(always)] + pub fn miner(&mut self, miner: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.miner = Some(miner); + self + } + #[inline(always)] + pub fn system_program(&mut self, system_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.system_program = Some(system_program); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: &'b solana_account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self { + self.instruction.__remaining_accounts.push((account, is_writable, is_signer)); + self + } + /// Add additional accounts to the instruction. + /// + /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not, + /// and a `bool` indicating whether the account is a signer or not. + #[inline(always)] + pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self { + self.instruction.__remaining_accounts.extend_from_slice(accounts); + self + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed(&[]) + } + #[allow(clippy::clone_on_copy)] + #[allow(clippy::vec_init_then_push)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult { + let instruction = ClaimSolCpi { + __program: self.instruction.__program, + + signer: self.instruction.signer.expect("signer is not set"), + + miner: self.instruction.miner.expect("miner is not set"), + + system_program: self.instruction.system_program.expect("system_program is not set"), + }; + instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts) + } +} + +#[derive(Clone, Debug)] +struct ClaimSolCpiBuilderInstruction<'a, 'b> { + __program: &'b solana_account_info::AccountInfo<'a>, + signer: Option<&'b solana_account_info::AccountInfo<'a>>, + miner: Option<&'b solana_account_info::AccountInfo<'a>>, + system_program: Option<&'b solana_account_info::AccountInfo<'a>>, + /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`. + __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>, +} + diff --git a/clients/rust/src/generated/instructions/claim_yield.rs b/clients/rust/src/generated/instructions/claim_yield.rs new file mode 100644 index 00000000..8f1d65bb --- /dev/null +++ b/clients/rust/src/generated/instructions/claim_yield.rs @@ -0,0 +1,589 @@ +//! 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. +//! +//! +//! + +use borsh::BorshSerialize; +use borsh::BorshDeserialize; + +pub const CLAIM_YIELD_DISCRIMINATOR: u8 = 12; + +/// Accounts. +#[derive(Debug)] +pub struct ClaimYield { + + + pub signer: solana_pubkey::Pubkey, + + + pub mint: solana_pubkey::Pubkey, + + + pub recipient: solana_pubkey::Pubkey, + + + pub stake: solana_pubkey::Pubkey, + + + pub treasury: solana_pubkey::Pubkey, + + + pub treasury_tokens: solana_pubkey::Pubkey, + + + pub system_program: solana_pubkey::Pubkey, + + + pub token_program: solana_pubkey::Pubkey, + + + pub associated_token_program: solana_pubkey::Pubkey, + } + +impl ClaimYield { + pub fn instruction(&self, args: ClaimYieldInstructionArgs) -> solana_instruction::Instruction { + self.instruction_with_remaining_accounts(args, &[]) + } + #[allow(clippy::arithmetic_side_effects)] + #[allow(clippy::vec_init_then_push)] + pub fn instruction_with_remaining_accounts(&self, args: ClaimYieldInstructionArgs, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction { + let mut accounts = Vec::with_capacity(9+ remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new( + self.signer, + true + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.mint, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.recipient, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.stake, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.treasury, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.treasury_tokens, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.system_program, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.token_program, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.associated_token_program, + false + )); + accounts.extend_from_slice(remaining_accounts); + let mut data = ClaimYieldInstructionData::new().try_to_vec().unwrap(); + let mut args = args.try_to_vec().unwrap(); + data.append(&mut args); + + solana_instruction::Instruction { + program_id: crate::ORE_ID, + accounts, + data, + } + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] + pub struct ClaimYieldInstructionData { + discriminator: u8, + } + +impl ClaimYieldInstructionData { + pub fn new() -> Self { + Self { + discriminator: 12, + } + } + + pub(crate) fn try_to_vec(&self) -> Result, std::io::Error> { + borsh::to_vec(self) + } + } + +impl Default for ClaimYieldInstructionData { + fn default() -> Self { + Self::new() + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] + pub struct ClaimYieldInstructionArgs { + pub amount: u64, + } + +impl ClaimYieldInstructionArgs { + pub(crate) fn try_to_vec(&self) -> Result, std::io::Error> { + borsh::to_vec(self) + } +} + + +/// Instruction builder for `ClaimYield`. +/// +/// ### Accounts: +/// + /// 0. `[writable, signer]` signer + /// 1. `[]` mint + /// 2. `[writable]` recipient + /// 3. `[writable]` stake + /// 4. `[writable]` treasury + /// 5. `[writable]` treasury_tokens + /// 6. `[optional]` system_program (default to `11111111111111111111111111111111`) + /// 7. `[optional]` token_program (default to `TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA`) + /// 8. `[]` associated_token_program +#[derive(Clone, Debug, Default)] +pub struct ClaimYieldBuilder { + signer: Option, + mint: Option, + recipient: Option, + stake: Option, + treasury: Option, + treasury_tokens: Option, + system_program: Option, + token_program: Option, + associated_token_program: Option, + amount: Option, + __remaining_accounts: Vec, +} + +impl ClaimYieldBuilder { + pub fn new() -> Self { + Self::default() + } + #[inline(always)] + pub fn signer(&mut self, signer: solana_pubkey::Pubkey) -> &mut Self { + self.signer = Some(signer); + self + } + #[inline(always)] + pub fn mint(&mut self, mint: solana_pubkey::Pubkey) -> &mut Self { + self.mint = Some(mint); + self + } + #[inline(always)] + pub fn recipient(&mut self, recipient: solana_pubkey::Pubkey) -> &mut Self { + self.recipient = Some(recipient); + self + } + #[inline(always)] + pub fn stake(&mut self, stake: solana_pubkey::Pubkey) -> &mut Self { + self.stake = Some(stake); + self + } + #[inline(always)] + pub fn treasury(&mut self, treasury: solana_pubkey::Pubkey) -> &mut Self { + self.treasury = Some(treasury); + self + } + #[inline(always)] + pub fn treasury_tokens(&mut self, treasury_tokens: solana_pubkey::Pubkey) -> &mut Self { + self.treasury_tokens = Some(treasury_tokens); + self + } + /// `[optional account, default to '11111111111111111111111111111111']` +#[inline(always)] + pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self { + self.system_program = Some(system_program); + self + } + /// `[optional account, default to 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA']` +#[inline(always)] + pub fn token_program(&mut self, token_program: solana_pubkey::Pubkey) -> &mut Self { + self.token_program = Some(token_program); + self + } + #[inline(always)] + pub fn associated_token_program(&mut self, associated_token_program: solana_pubkey::Pubkey) -> &mut Self { + self.associated_token_program = Some(associated_token_program); + self + } + #[inline(always)] + pub fn amount(&mut self, amount: u64) -> &mut Self { + self.amount = Some(amount); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self { + self.__remaining_accounts.push(account); + self + } + /// Add additional accounts to the instruction. + #[inline(always)] + pub fn add_remaining_accounts(&mut self, accounts: &[solana_instruction::AccountMeta]) -> &mut Self { + self.__remaining_accounts.extend_from_slice(accounts); + self + } + #[allow(clippy::clone_on_copy)] + pub fn instruction(&self) -> solana_instruction::Instruction { + let accounts = ClaimYield { + signer: self.signer.expect("signer is not set"), + mint: self.mint.expect("mint is not set"), + recipient: self.recipient.expect("recipient is not set"), + stake: self.stake.expect("stake is not set"), + treasury: self.treasury.expect("treasury is not set"), + treasury_tokens: self.treasury_tokens.expect("treasury_tokens is not set"), + system_program: self.system_program.unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")), + token_program: self.token_program.unwrap_or(solana_pubkey::pubkey!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA")), + associated_token_program: self.associated_token_program.expect("associated_token_program is not set"), + }; + let args = ClaimYieldInstructionArgs { + amount: self.amount.clone().expect("amount is not set"), + }; + + accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts) + } +} + + /// `claim_yield` CPI accounts. + pub struct ClaimYieldCpiAccounts<'a, 'b> { + + + pub signer: &'b solana_account_info::AccountInfo<'a>, + + + pub mint: &'b solana_account_info::AccountInfo<'a>, + + + pub recipient: &'b solana_account_info::AccountInfo<'a>, + + + pub stake: &'b solana_account_info::AccountInfo<'a>, + + + pub treasury: &'b solana_account_info::AccountInfo<'a>, + + + pub treasury_tokens: &'b solana_account_info::AccountInfo<'a>, + + + pub system_program: &'b solana_account_info::AccountInfo<'a>, + + + pub token_program: &'b solana_account_info::AccountInfo<'a>, + + + pub associated_token_program: &'b solana_account_info::AccountInfo<'a>, + } + +/// `claim_yield` CPI instruction. +pub struct ClaimYieldCpi<'a, 'b> { + /// The program to invoke. + pub __program: &'b solana_account_info::AccountInfo<'a>, + + + pub signer: &'b solana_account_info::AccountInfo<'a>, + + + pub mint: &'b solana_account_info::AccountInfo<'a>, + + + pub recipient: &'b solana_account_info::AccountInfo<'a>, + + + pub stake: &'b solana_account_info::AccountInfo<'a>, + + + pub treasury: &'b solana_account_info::AccountInfo<'a>, + + + pub treasury_tokens: &'b solana_account_info::AccountInfo<'a>, + + + pub system_program: &'b solana_account_info::AccountInfo<'a>, + + + pub token_program: &'b solana_account_info::AccountInfo<'a>, + + + pub associated_token_program: &'b solana_account_info::AccountInfo<'a>, + /// The arguments for the instruction. + pub __args: ClaimYieldInstructionArgs, + } + +impl<'a, 'b> ClaimYieldCpi<'a, 'b> { + pub fn new( + program: &'b solana_account_info::AccountInfo<'a>, + accounts: ClaimYieldCpiAccounts<'a, 'b>, + args: ClaimYieldInstructionArgs, + ) -> Self { + Self { + __program: program, + signer: accounts.signer, + mint: accounts.mint, + recipient: accounts.recipient, + stake: accounts.stake, + treasury: accounts.treasury, + treasury_tokens: accounts.treasury_tokens, + system_program: accounts.system_program, + token_program: accounts.token_program, + associated_token_program: accounts.associated_token_program, + __args: args, + } + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], &[]) + } + #[inline(always)] + pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], remaining_accounts) + } + #[inline(always)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(signers_seeds, &[]) + } + #[allow(clippy::arithmetic_side_effects)] + #[allow(clippy::clone_on_copy)] + #[allow(clippy::vec_init_then_push)] + pub fn invoke_signed_with_remaining_accounts( + &self, + signers_seeds: &[&[&[u8]]], + remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)] + ) -> solana_program_error::ProgramResult { + let mut accounts = Vec::with_capacity(9+ remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new( + *self.signer.key, + true + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.mint.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.recipient.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.stake.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.treasury.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.treasury_tokens.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.system_program.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.token_program.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.associated_token_program.key, + false + )); + remaining_accounts.iter().for_each(|remaining_account| { + accounts.push(solana_instruction::AccountMeta { + pubkey: *remaining_account.0.key, + is_signer: remaining_account.1, + is_writable: remaining_account.2, + }) + }); + let mut data = ClaimYieldInstructionData::new().try_to_vec().unwrap(); + let mut args = self.__args.try_to_vec().unwrap(); + data.append(&mut args); + + let instruction = solana_instruction::Instruction { + program_id: crate::ORE_ID, + accounts, + data, + }; + let mut account_infos = Vec::with_capacity(10 + remaining_accounts.len()); + account_infos.push(self.__program.clone()); + account_infos.push(self.signer.clone()); + account_infos.push(self.mint.clone()); + account_infos.push(self.recipient.clone()); + account_infos.push(self.stake.clone()); + account_infos.push(self.treasury.clone()); + account_infos.push(self.treasury_tokens.clone()); + account_infos.push(self.system_program.clone()); + account_infos.push(self.token_program.clone()); + account_infos.push(self.associated_token_program.clone()); + remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone())); + + if signers_seeds.is_empty() { + solana_cpi::invoke(&instruction, &account_infos) + } else { + solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds) + } + } +} + +/// Instruction builder for `ClaimYield` via CPI. +/// +/// ### Accounts: +/// + /// 0. `[writable, signer]` signer + /// 1. `[]` mint + /// 2. `[writable]` recipient + /// 3. `[writable]` stake + /// 4. `[writable]` treasury + /// 5. `[writable]` treasury_tokens + /// 6. `[]` system_program + /// 7. `[]` token_program + /// 8. `[]` associated_token_program +#[derive(Clone, Debug)] +pub struct ClaimYieldCpiBuilder<'a, 'b> { + instruction: Box>, +} + +impl<'a, 'b> ClaimYieldCpiBuilder<'a, 'b> { + pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self { + let instruction = Box::new(ClaimYieldCpiBuilderInstruction { + __program: program, + signer: None, + mint: None, + recipient: None, + stake: None, + treasury: None, + treasury_tokens: None, + system_program: None, + token_program: None, + associated_token_program: None, + amount: None, + __remaining_accounts: Vec::new(), + }); + Self { instruction } + } + #[inline(always)] + pub fn signer(&mut self, signer: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.signer = Some(signer); + self + } + #[inline(always)] + pub fn mint(&mut self, mint: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.mint = Some(mint); + self + } + #[inline(always)] + pub fn recipient(&mut self, recipient: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.recipient = Some(recipient); + self + } + #[inline(always)] + pub fn stake(&mut self, stake: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.stake = Some(stake); + self + } + #[inline(always)] + pub fn treasury(&mut self, treasury: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.treasury = Some(treasury); + self + } + #[inline(always)] + pub fn treasury_tokens(&mut self, treasury_tokens: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.treasury_tokens = Some(treasury_tokens); + self + } + #[inline(always)] + pub fn system_program(&mut self, system_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.system_program = Some(system_program); + self + } + #[inline(always)] + pub fn token_program(&mut self, token_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.token_program = Some(token_program); + self + } + #[inline(always)] + pub fn associated_token_program(&mut self, associated_token_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.associated_token_program = Some(associated_token_program); + self + } + #[inline(always)] + pub fn amount(&mut self, amount: u64) -> &mut Self { + self.instruction.amount = Some(amount); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: &'b solana_account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self { + self.instruction.__remaining_accounts.push((account, is_writable, is_signer)); + self + } + /// Add additional accounts to the instruction. + /// + /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not, + /// and a `bool` indicating whether the account is a signer or not. + #[inline(always)] + pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self { + self.instruction.__remaining_accounts.extend_from_slice(accounts); + self + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed(&[]) + } + #[allow(clippy::clone_on_copy)] + #[allow(clippy::vec_init_then_push)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult { + let args = ClaimYieldInstructionArgs { + amount: self.instruction.amount.clone().expect("amount is not set"), + }; + let instruction = ClaimYieldCpi { + __program: self.instruction.__program, + + signer: self.instruction.signer.expect("signer is not set"), + + mint: self.instruction.mint.expect("mint is not set"), + + recipient: self.instruction.recipient.expect("recipient is not set"), + + stake: self.instruction.stake.expect("stake is not set"), + + treasury: self.instruction.treasury.expect("treasury is not set"), + + treasury_tokens: self.instruction.treasury_tokens.expect("treasury_tokens is not set"), + + system_program: self.instruction.system_program.expect("system_program is not set"), + + token_program: self.instruction.token_program.expect("token_program is not set"), + + associated_token_program: self.instruction.associated_token_program.expect("associated_token_program is not set"), + __args: args, + }; + instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts) + } +} + +#[derive(Clone, Debug)] +struct ClaimYieldCpiBuilderInstruction<'a, 'b> { + __program: &'b solana_account_info::AccountInfo<'a>, + signer: Option<&'b solana_account_info::AccountInfo<'a>>, + mint: Option<&'b solana_account_info::AccountInfo<'a>>, + recipient: Option<&'b solana_account_info::AccountInfo<'a>>, + stake: Option<&'b solana_account_info::AccountInfo<'a>>, + treasury: Option<&'b solana_account_info::AccountInfo<'a>>, + treasury_tokens: Option<&'b solana_account_info::AccountInfo<'a>>, + system_program: Option<&'b solana_account_info::AccountInfo<'a>>, + token_program: Option<&'b solana_account_info::AccountInfo<'a>>, + associated_token_program: Option<&'b solana_account_info::AccountInfo<'a>>, + amount: Option, + /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`. + __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>, +} + diff --git a/clients/rust/src/generated/instructions/close.rs b/clients/rust/src/generated/instructions/close.rs new file mode 100644 index 00000000..43d503a3 --- /dev/null +++ b/clients/rust/src/generated/instructions/close.rs @@ -0,0 +1,438 @@ +//! 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. +//! +//! +//! + +use borsh::BorshSerialize; +use borsh::BorshDeserialize; + +pub const CLOSE_DISCRIMINATOR: u8 = 5; + +/// Accounts. +#[derive(Debug)] +pub struct Close { + + + pub signer: solana_pubkey::Pubkey, + + + pub board: solana_pubkey::Pubkey, + + + pub rent_payer: solana_pubkey::Pubkey, + + + pub round: solana_pubkey::Pubkey, + + + pub treasury: solana_pubkey::Pubkey, + + + pub system_program: solana_pubkey::Pubkey, + } + +impl Close { + pub fn instruction(&self) -> solana_instruction::Instruction { + self.instruction_with_remaining_accounts(&[]) + } + #[allow(clippy::arithmetic_side_effects)] + #[allow(clippy::vec_init_then_push)] + pub fn instruction_with_remaining_accounts(&self, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction { + let mut accounts = Vec::with_capacity(6+ remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.signer, + true + )); + accounts.push(solana_instruction::AccountMeta::new( + self.board, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.rent_payer, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.round, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.treasury, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.system_program, + false + )); + accounts.extend_from_slice(remaining_accounts); + let data = CloseInstructionData::new().try_to_vec().unwrap(); + + solana_instruction::Instruction { + program_id: crate::ORE_ID, + accounts, + data, + } + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] + pub struct CloseInstructionData { + discriminator: u8, + } + +impl CloseInstructionData { + pub fn new() -> Self { + Self { + discriminator: 5, + } + } + + pub(crate) fn try_to_vec(&self) -> Result, std::io::Error> { + borsh::to_vec(self) + } + } + +impl Default for CloseInstructionData { + fn default() -> Self { + Self::new() + } +} + + + +/// Instruction builder for `Close`. +/// +/// ### Accounts: +/// + /// 0. `[signer]` signer + /// 1. `[writable]` board + /// 2. `[writable]` rent_payer + /// 3. `[writable]` round + /// 4. `[writable]` treasury + /// 5. `[optional]` system_program (default to `11111111111111111111111111111111`) +#[derive(Clone, Debug, Default)] +pub struct CloseBuilder { + signer: Option, + board: Option, + rent_payer: Option, + round: Option, + treasury: Option, + system_program: Option, + __remaining_accounts: Vec, +} + +impl CloseBuilder { + pub fn new() -> Self { + Self::default() + } + #[inline(always)] + pub fn signer(&mut self, signer: solana_pubkey::Pubkey) -> &mut Self { + self.signer = Some(signer); + self + } + #[inline(always)] + pub fn board(&mut self, board: solana_pubkey::Pubkey) -> &mut Self { + self.board = Some(board); + self + } + #[inline(always)] + pub fn rent_payer(&mut self, rent_payer: solana_pubkey::Pubkey) -> &mut Self { + self.rent_payer = Some(rent_payer); + self + } + #[inline(always)] + pub fn round(&mut self, round: solana_pubkey::Pubkey) -> &mut Self { + self.round = Some(round); + self + } + #[inline(always)] + pub fn treasury(&mut self, treasury: solana_pubkey::Pubkey) -> &mut Self { + self.treasury = Some(treasury); + self + } + /// `[optional account, default to '11111111111111111111111111111111']` +#[inline(always)] + pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self { + self.system_program = Some(system_program); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self { + self.__remaining_accounts.push(account); + self + } + /// Add additional accounts to the instruction. + #[inline(always)] + pub fn add_remaining_accounts(&mut self, accounts: &[solana_instruction::AccountMeta]) -> &mut Self { + self.__remaining_accounts.extend_from_slice(accounts); + self + } + #[allow(clippy::clone_on_copy)] + pub fn instruction(&self) -> solana_instruction::Instruction { + let accounts = Close { + signer: self.signer.expect("signer is not set"), + board: self.board.expect("board is not set"), + rent_payer: self.rent_payer.expect("rent_payer is not set"), + round: self.round.expect("round is not set"), + treasury: self.treasury.expect("treasury is not set"), + system_program: self.system_program.unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")), + }; + + accounts.instruction_with_remaining_accounts(&self.__remaining_accounts) + } +} + + /// `close` CPI accounts. + pub struct CloseCpiAccounts<'a, 'b> { + + + pub signer: &'b solana_account_info::AccountInfo<'a>, + + + pub board: &'b solana_account_info::AccountInfo<'a>, + + + pub rent_payer: &'b solana_account_info::AccountInfo<'a>, + + + pub round: &'b solana_account_info::AccountInfo<'a>, + + + pub treasury: &'b solana_account_info::AccountInfo<'a>, + + + pub system_program: &'b solana_account_info::AccountInfo<'a>, + } + +/// `close` CPI instruction. +pub struct CloseCpi<'a, 'b> { + /// The program to invoke. + pub __program: &'b solana_account_info::AccountInfo<'a>, + + + pub signer: &'b solana_account_info::AccountInfo<'a>, + + + pub board: &'b solana_account_info::AccountInfo<'a>, + + + pub rent_payer: &'b solana_account_info::AccountInfo<'a>, + + + pub round: &'b solana_account_info::AccountInfo<'a>, + + + pub treasury: &'b solana_account_info::AccountInfo<'a>, + + + pub system_program: &'b solana_account_info::AccountInfo<'a>, + } + +impl<'a, 'b> CloseCpi<'a, 'b> { + pub fn new( + program: &'b solana_account_info::AccountInfo<'a>, + accounts: CloseCpiAccounts<'a, 'b>, + ) -> Self { + Self { + __program: program, + signer: accounts.signer, + board: accounts.board, + rent_payer: accounts.rent_payer, + round: accounts.round, + treasury: accounts.treasury, + system_program: accounts.system_program, + } + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], &[]) + } + #[inline(always)] + pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], remaining_accounts) + } + #[inline(always)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(signers_seeds, &[]) + } + #[allow(clippy::arithmetic_side_effects)] + #[allow(clippy::clone_on_copy)] + #[allow(clippy::vec_init_then_push)] + pub fn invoke_signed_with_remaining_accounts( + &self, + signers_seeds: &[&[&[u8]]], + remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)] + ) -> solana_program_error::ProgramResult { + let mut accounts = Vec::with_capacity(6+ remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.signer.key, + true + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.board.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.rent_payer.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.round.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.treasury.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.system_program.key, + false + )); + remaining_accounts.iter().for_each(|remaining_account| { + accounts.push(solana_instruction::AccountMeta { + pubkey: *remaining_account.0.key, + is_signer: remaining_account.1, + is_writable: remaining_account.2, + }) + }); + let data = CloseInstructionData::new().try_to_vec().unwrap(); + + let instruction = solana_instruction::Instruction { + program_id: crate::ORE_ID, + accounts, + data, + }; + let mut account_infos = Vec::with_capacity(7 + remaining_accounts.len()); + account_infos.push(self.__program.clone()); + account_infos.push(self.signer.clone()); + account_infos.push(self.board.clone()); + account_infos.push(self.rent_payer.clone()); + account_infos.push(self.round.clone()); + account_infos.push(self.treasury.clone()); + account_infos.push(self.system_program.clone()); + remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone())); + + if signers_seeds.is_empty() { + solana_cpi::invoke(&instruction, &account_infos) + } else { + solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds) + } + } +} + +/// Instruction builder for `Close` via CPI. +/// +/// ### Accounts: +/// + /// 0. `[signer]` signer + /// 1. `[writable]` board + /// 2. `[writable]` rent_payer + /// 3. `[writable]` round + /// 4. `[writable]` treasury + /// 5. `[]` system_program +#[derive(Clone, Debug)] +pub struct CloseCpiBuilder<'a, 'b> { + instruction: Box>, +} + +impl<'a, 'b> CloseCpiBuilder<'a, 'b> { + pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self { + let instruction = Box::new(CloseCpiBuilderInstruction { + __program: program, + signer: None, + board: None, + rent_payer: None, + round: None, + treasury: None, + system_program: None, + __remaining_accounts: Vec::new(), + }); + Self { instruction } + } + #[inline(always)] + pub fn signer(&mut self, signer: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.signer = Some(signer); + self + } + #[inline(always)] + pub fn board(&mut self, board: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.board = Some(board); + self + } + #[inline(always)] + pub fn rent_payer(&mut self, rent_payer: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.rent_payer = Some(rent_payer); + self + } + #[inline(always)] + pub fn round(&mut self, round: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.round = Some(round); + self + } + #[inline(always)] + pub fn treasury(&mut self, treasury: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.treasury = Some(treasury); + self + } + #[inline(always)] + pub fn system_program(&mut self, system_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.system_program = Some(system_program); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: &'b solana_account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self { + self.instruction.__remaining_accounts.push((account, is_writable, is_signer)); + self + } + /// Add additional accounts to the instruction. + /// + /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not, + /// and a `bool` indicating whether the account is a signer or not. + #[inline(always)] + pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self { + self.instruction.__remaining_accounts.extend_from_slice(accounts); + self + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed(&[]) + } + #[allow(clippy::clone_on_copy)] + #[allow(clippy::vec_init_then_push)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult { + let instruction = CloseCpi { + __program: self.instruction.__program, + + signer: self.instruction.signer.expect("signer is not set"), + + board: self.instruction.board.expect("board is not set"), + + rent_payer: self.instruction.rent_payer.expect("rent_payer is not set"), + + round: self.instruction.round.expect("round is not set"), + + treasury: self.instruction.treasury.expect("treasury is not set"), + + system_program: self.instruction.system_program.expect("system_program is not set"), + }; + instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts) + } +} + +#[derive(Clone, Debug)] +struct CloseCpiBuilderInstruction<'a, 'b> { + __program: &'b solana_account_info::AccountInfo<'a>, + signer: Option<&'b solana_account_info::AccountInfo<'a>>, + board: Option<&'b solana_account_info::AccountInfo<'a>>, + rent_payer: Option<&'b solana_account_info::AccountInfo<'a>>, + round: Option<&'b solana_account_info::AccountInfo<'a>>, + treasury: Option<&'b solana_account_info::AccountInfo<'a>>, + system_program: Option<&'b solana_account_info::AccountInfo<'a>>, + /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`. + __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>, +} + diff --git a/clients/rust/src/generated/instructions/deploy.rs b/clients/rust/src/generated/instructions/deploy.rs new file mode 100644 index 00000000..cbc451d6 --- /dev/null +++ b/clients/rust/src/generated/instructions/deploy.rs @@ -0,0 +1,678 @@ +//! 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. +//! +//! +//! + +use borsh::BorshSerialize; +use borsh::BorshDeserialize; + +pub const DEPLOY_DISCRIMINATOR: u8 = 6; + +/// Accounts. +#[derive(Debug)] +pub struct Deploy { + + + pub signer: solana_pubkey::Pubkey, + + + pub authority: solana_pubkey::Pubkey, + + + pub automation: solana_pubkey::Pubkey, + + + pub board: solana_pubkey::Pubkey, + + + pub config: solana_pubkey::Pubkey, + + + pub miner: solana_pubkey::Pubkey, + + + pub round: solana_pubkey::Pubkey, + + + pub system_program: solana_pubkey::Pubkey, + + + pub ore_program: solana_pubkey::Pubkey, + + + pub entropy_var: solana_pubkey::Pubkey, + + + pub entropy_program: solana_pubkey::Pubkey, + } + +impl Deploy { + pub fn instruction(&self, args: DeployInstructionArgs) -> solana_instruction::Instruction { + self.instruction_with_remaining_accounts(args, &[]) + } + #[allow(clippy::arithmetic_side_effects)] + #[allow(clippy::vec_init_then_push)] + pub fn instruction_with_remaining_accounts(&self, args: DeployInstructionArgs, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction { + let mut accounts = Vec::with_capacity(11+ remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new( + self.signer, + true + )); + accounts.push(solana_instruction::AccountMeta::new( + self.authority, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.automation, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.board, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.config, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.miner, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.round, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.system_program, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.ore_program, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.entropy_var, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.entropy_program, + false + )); + accounts.extend_from_slice(remaining_accounts); + let mut data = DeployInstructionData::new().try_to_vec().unwrap(); + let mut args = args.try_to_vec().unwrap(); + data.append(&mut args); + + solana_instruction::Instruction { + program_id: crate::ORE_ID, + accounts, + data, + } + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] + pub struct DeployInstructionData { + discriminator: u8, + } + +impl DeployInstructionData { + pub fn new() -> Self { + Self { + discriminator: 6, + } + } + + pub(crate) fn try_to_vec(&self) -> Result, std::io::Error> { + borsh::to_vec(self) + } + } + +impl Default for DeployInstructionData { + fn default() -> Self { + Self::new() + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] + pub struct DeployInstructionArgs { + pub amount: u64, + pub squares: u32, + } + +impl DeployInstructionArgs { + pub(crate) fn try_to_vec(&self) -> Result, std::io::Error> { + borsh::to_vec(self) + } +} + + +/// Instruction builder for `Deploy`. +/// +/// ### Accounts: +/// + /// 0. `[writable, signer]` signer + /// 1. `[writable]` authority + /// 2. `[writable]` automation + /// 3. `[writable]` board + /// 4. `[writable]` config + /// 5. `[writable]` miner + /// 6. `[writable]` round + /// 7. `[optional]` system_program (default to `11111111111111111111111111111111`) + /// 8. `[]` ore_program + /// 9. `[writable]` entropy_var + /// 10. `[]` entropy_program +#[derive(Clone, Debug, Default)] +pub struct DeployBuilder { + signer: Option, + authority: Option, + automation: Option, + board: Option, + config: Option, + miner: Option, + round: Option, + system_program: Option, + ore_program: Option, + entropy_var: Option, + entropy_program: Option, + amount: Option, + squares: Option, + __remaining_accounts: Vec, +} + +impl DeployBuilder { + pub fn new() -> Self { + Self::default() + } + #[inline(always)] + pub fn signer(&mut self, signer: solana_pubkey::Pubkey) -> &mut Self { + self.signer = Some(signer); + self + } + #[inline(always)] + pub fn authority(&mut self, authority: solana_pubkey::Pubkey) -> &mut Self { + self.authority = Some(authority); + self + } + #[inline(always)] + pub fn automation(&mut self, automation: solana_pubkey::Pubkey) -> &mut Self { + self.automation = Some(automation); + self + } + #[inline(always)] + pub fn board(&mut self, board: solana_pubkey::Pubkey) -> &mut Self { + self.board = Some(board); + self + } + #[inline(always)] + pub fn config(&mut self, config: solana_pubkey::Pubkey) -> &mut Self { + self.config = Some(config); + self + } + #[inline(always)] + pub fn miner(&mut self, miner: solana_pubkey::Pubkey) -> &mut Self { + self.miner = Some(miner); + self + } + #[inline(always)] + pub fn round(&mut self, round: solana_pubkey::Pubkey) -> &mut Self { + self.round = Some(round); + self + } + /// `[optional account, default to '11111111111111111111111111111111']` +#[inline(always)] + pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self { + self.system_program = Some(system_program); + self + } + #[inline(always)] + pub fn ore_program(&mut self, ore_program: solana_pubkey::Pubkey) -> &mut Self { + self.ore_program = Some(ore_program); + self + } + #[inline(always)] + pub fn entropy_var(&mut self, entropy_var: solana_pubkey::Pubkey) -> &mut Self { + self.entropy_var = Some(entropy_var); + self + } + #[inline(always)] + pub fn entropy_program(&mut self, entropy_program: solana_pubkey::Pubkey) -> &mut Self { + self.entropy_program = Some(entropy_program); + self + } + #[inline(always)] + pub fn amount(&mut self, amount: u64) -> &mut Self { + self.amount = Some(amount); + self + } + #[inline(always)] + pub fn squares(&mut self, squares: u32) -> &mut Self { + self.squares = Some(squares); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self { + self.__remaining_accounts.push(account); + self + } + /// Add additional accounts to the instruction. + #[inline(always)] + pub fn add_remaining_accounts(&mut self, accounts: &[solana_instruction::AccountMeta]) -> &mut Self { + self.__remaining_accounts.extend_from_slice(accounts); + self + } + #[allow(clippy::clone_on_copy)] + pub fn instruction(&self) -> solana_instruction::Instruction { + let accounts = Deploy { + signer: self.signer.expect("signer is not set"), + authority: self.authority.expect("authority is not set"), + automation: self.automation.expect("automation is not set"), + board: self.board.expect("board is not set"), + config: self.config.expect("config is not set"), + miner: self.miner.expect("miner is not set"), + round: self.round.expect("round is not set"), + system_program: self.system_program.unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")), + ore_program: self.ore_program.expect("ore_program is not set"), + entropy_var: self.entropy_var.expect("entropy_var is not set"), + entropy_program: self.entropy_program.expect("entropy_program is not set"), + }; + let args = DeployInstructionArgs { + amount: self.amount.clone().expect("amount is not set"), + squares: self.squares.clone().expect("squares is not set"), + }; + + accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts) + } +} + + /// `deploy` CPI accounts. + pub struct DeployCpiAccounts<'a, 'b> { + + + pub signer: &'b solana_account_info::AccountInfo<'a>, + + + pub authority: &'b solana_account_info::AccountInfo<'a>, + + + pub automation: &'b solana_account_info::AccountInfo<'a>, + + + pub board: &'b solana_account_info::AccountInfo<'a>, + + + pub config: &'b solana_account_info::AccountInfo<'a>, + + + pub miner: &'b solana_account_info::AccountInfo<'a>, + + + pub round: &'b solana_account_info::AccountInfo<'a>, + + + pub system_program: &'b solana_account_info::AccountInfo<'a>, + + + pub ore_program: &'b solana_account_info::AccountInfo<'a>, + + + pub entropy_var: &'b solana_account_info::AccountInfo<'a>, + + + pub entropy_program: &'b solana_account_info::AccountInfo<'a>, + } + +/// `deploy` CPI instruction. +pub struct DeployCpi<'a, 'b> { + /// The program to invoke. + pub __program: &'b solana_account_info::AccountInfo<'a>, + + + pub signer: &'b solana_account_info::AccountInfo<'a>, + + + pub authority: &'b solana_account_info::AccountInfo<'a>, + + + pub automation: &'b solana_account_info::AccountInfo<'a>, + + + pub board: &'b solana_account_info::AccountInfo<'a>, + + + pub config: &'b solana_account_info::AccountInfo<'a>, + + + pub miner: &'b solana_account_info::AccountInfo<'a>, + + + pub round: &'b solana_account_info::AccountInfo<'a>, + + + pub system_program: &'b solana_account_info::AccountInfo<'a>, + + + pub ore_program: &'b solana_account_info::AccountInfo<'a>, + + + pub entropy_var: &'b solana_account_info::AccountInfo<'a>, + + + pub entropy_program: &'b solana_account_info::AccountInfo<'a>, + /// The arguments for the instruction. + pub __args: DeployInstructionArgs, + } + +impl<'a, 'b> DeployCpi<'a, 'b> { + pub fn new( + program: &'b solana_account_info::AccountInfo<'a>, + accounts: DeployCpiAccounts<'a, 'b>, + args: DeployInstructionArgs, + ) -> Self { + Self { + __program: program, + signer: accounts.signer, + authority: accounts.authority, + automation: accounts.automation, + board: accounts.board, + config: accounts.config, + miner: accounts.miner, + round: accounts.round, + system_program: accounts.system_program, + ore_program: accounts.ore_program, + entropy_var: accounts.entropy_var, + entropy_program: accounts.entropy_program, + __args: args, + } + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], &[]) + } + #[inline(always)] + pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], remaining_accounts) + } + #[inline(always)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(signers_seeds, &[]) + } + #[allow(clippy::arithmetic_side_effects)] + #[allow(clippy::clone_on_copy)] + #[allow(clippy::vec_init_then_push)] + pub fn invoke_signed_with_remaining_accounts( + &self, + signers_seeds: &[&[&[u8]]], + remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)] + ) -> solana_program_error::ProgramResult { + let mut accounts = Vec::with_capacity(11+ remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new( + *self.signer.key, + true + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.authority.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.automation.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.board.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.config.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.miner.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.round.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.system_program.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.ore_program.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.entropy_var.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.entropy_program.key, + false + )); + remaining_accounts.iter().for_each(|remaining_account| { + accounts.push(solana_instruction::AccountMeta { + pubkey: *remaining_account.0.key, + is_signer: remaining_account.1, + is_writable: remaining_account.2, + }) + }); + let mut data = DeployInstructionData::new().try_to_vec().unwrap(); + let mut args = self.__args.try_to_vec().unwrap(); + data.append(&mut args); + + let instruction = solana_instruction::Instruction { + program_id: crate::ORE_ID, + accounts, + data, + }; + let mut account_infos = Vec::with_capacity(12 + remaining_accounts.len()); + account_infos.push(self.__program.clone()); + account_infos.push(self.signer.clone()); + account_infos.push(self.authority.clone()); + account_infos.push(self.automation.clone()); + account_infos.push(self.board.clone()); + account_infos.push(self.config.clone()); + account_infos.push(self.miner.clone()); + account_infos.push(self.round.clone()); + account_infos.push(self.system_program.clone()); + account_infos.push(self.ore_program.clone()); + account_infos.push(self.entropy_var.clone()); + account_infos.push(self.entropy_program.clone()); + remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone())); + + if signers_seeds.is_empty() { + solana_cpi::invoke(&instruction, &account_infos) + } else { + solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds) + } + } +} + +/// Instruction builder for `Deploy` via CPI. +/// +/// ### Accounts: +/// + /// 0. `[writable, signer]` signer + /// 1. `[writable]` authority + /// 2. `[writable]` automation + /// 3. `[writable]` board + /// 4. `[writable]` config + /// 5. `[writable]` miner + /// 6. `[writable]` round + /// 7. `[]` system_program + /// 8. `[]` ore_program + /// 9. `[writable]` entropy_var + /// 10. `[]` entropy_program +#[derive(Clone, Debug)] +pub struct DeployCpiBuilder<'a, 'b> { + instruction: Box>, +} + +impl<'a, 'b> DeployCpiBuilder<'a, 'b> { + pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self { + let instruction = Box::new(DeployCpiBuilderInstruction { + __program: program, + signer: None, + authority: None, + automation: None, + board: None, + config: None, + miner: None, + round: None, + system_program: None, + ore_program: None, + entropy_var: None, + entropy_program: None, + amount: None, + squares: None, + __remaining_accounts: Vec::new(), + }); + Self { instruction } + } + #[inline(always)] + pub fn signer(&mut self, signer: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.signer = Some(signer); + self + } + #[inline(always)] + pub fn authority(&mut self, authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.authority = Some(authority); + self + } + #[inline(always)] + pub fn automation(&mut self, automation: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.automation = Some(automation); + self + } + #[inline(always)] + pub fn board(&mut self, board: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.board = Some(board); + self + } + #[inline(always)] + pub fn config(&mut self, config: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.config = Some(config); + self + } + #[inline(always)] + pub fn miner(&mut self, miner: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.miner = Some(miner); + self + } + #[inline(always)] + pub fn round(&mut self, round: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.round = Some(round); + self + } + #[inline(always)] + pub fn system_program(&mut self, system_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.system_program = Some(system_program); + self + } + #[inline(always)] + pub fn ore_program(&mut self, ore_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.ore_program = Some(ore_program); + self + } + #[inline(always)] + pub fn entropy_var(&mut self, entropy_var: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.entropy_var = Some(entropy_var); + self + } + #[inline(always)] + pub fn entropy_program(&mut self, entropy_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.entropy_program = Some(entropy_program); + self + } + #[inline(always)] + pub fn amount(&mut self, amount: u64) -> &mut Self { + self.instruction.amount = Some(amount); + self + } + #[inline(always)] + pub fn squares(&mut self, squares: u32) -> &mut Self { + self.instruction.squares = Some(squares); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: &'b solana_account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self { + self.instruction.__remaining_accounts.push((account, is_writable, is_signer)); + self + } + /// Add additional accounts to the instruction. + /// + /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not, + /// and a `bool` indicating whether the account is a signer or not. + #[inline(always)] + pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self { + self.instruction.__remaining_accounts.extend_from_slice(accounts); + self + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed(&[]) + } + #[allow(clippy::clone_on_copy)] + #[allow(clippy::vec_init_then_push)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult { + let args = DeployInstructionArgs { + amount: self.instruction.amount.clone().expect("amount is not set"), + squares: self.instruction.squares.clone().expect("squares is not set"), + }; + let instruction = DeployCpi { + __program: self.instruction.__program, + + signer: self.instruction.signer.expect("signer is not set"), + + authority: self.instruction.authority.expect("authority is not set"), + + automation: self.instruction.automation.expect("automation is not set"), + + board: self.instruction.board.expect("board is not set"), + + config: self.instruction.config.expect("config is not set"), + + miner: self.instruction.miner.expect("miner is not set"), + + round: self.instruction.round.expect("round is not set"), + + system_program: self.instruction.system_program.expect("system_program is not set"), + + ore_program: self.instruction.ore_program.expect("ore_program is not set"), + + entropy_var: self.instruction.entropy_var.expect("entropy_var is not set"), + + entropy_program: self.instruction.entropy_program.expect("entropy_program is not set"), + __args: args, + }; + instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts) + } +} + +#[derive(Clone, Debug)] +struct DeployCpiBuilderInstruction<'a, 'b> { + __program: &'b solana_account_info::AccountInfo<'a>, + signer: Option<&'b solana_account_info::AccountInfo<'a>>, + authority: Option<&'b solana_account_info::AccountInfo<'a>>, + automation: Option<&'b solana_account_info::AccountInfo<'a>>, + board: Option<&'b solana_account_info::AccountInfo<'a>>, + config: Option<&'b solana_account_info::AccountInfo<'a>>, + miner: Option<&'b solana_account_info::AccountInfo<'a>>, + round: Option<&'b solana_account_info::AccountInfo<'a>>, + system_program: Option<&'b solana_account_info::AccountInfo<'a>>, + ore_program: Option<&'b solana_account_info::AccountInfo<'a>>, + entropy_var: Option<&'b solana_account_info::AccountInfo<'a>>, + entropy_program: Option<&'b solana_account_info::AccountInfo<'a>>, + amount: Option, + squares: Option, + /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`. + __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>, +} + diff --git a/clients/rust/src/generated/instructions/deposit.rs b/clients/rust/src/generated/instructions/deposit.rs new file mode 100644 index 00000000..ce619c82 --- /dev/null +++ b/clients/rust/src/generated/instructions/deposit.rs @@ -0,0 +1,589 @@ +//! 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. +//! +//! +//! + +use borsh::BorshSerialize; +use borsh::BorshDeserialize; + +pub const DEPOSIT_DISCRIMINATOR: u8 = 10; + +/// Accounts. +#[derive(Debug)] +pub struct Deposit { + + + pub signer: solana_pubkey::Pubkey, + + + pub mint: solana_pubkey::Pubkey, + + + pub sender: solana_pubkey::Pubkey, + + + pub stake: solana_pubkey::Pubkey, + + + pub stake_tokens: solana_pubkey::Pubkey, + + + pub treasury: solana_pubkey::Pubkey, + + + pub system_program: solana_pubkey::Pubkey, + + + pub token_program: solana_pubkey::Pubkey, + + + pub associated_token_program: solana_pubkey::Pubkey, + } + +impl Deposit { + pub fn instruction(&self, args: DepositInstructionArgs) -> solana_instruction::Instruction { + self.instruction_with_remaining_accounts(args, &[]) + } + #[allow(clippy::arithmetic_side_effects)] + #[allow(clippy::vec_init_then_push)] + pub fn instruction_with_remaining_accounts(&self, args: DepositInstructionArgs, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction { + let mut accounts = Vec::with_capacity(9+ remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new( + self.signer, + true + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.mint, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.sender, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.stake, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.stake_tokens, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.treasury, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.system_program, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.token_program, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.associated_token_program, + false + )); + accounts.extend_from_slice(remaining_accounts); + let mut data = DepositInstructionData::new().try_to_vec().unwrap(); + let mut args = args.try_to_vec().unwrap(); + data.append(&mut args); + + solana_instruction::Instruction { + program_id: crate::ORE_ID, + accounts, + data, + } + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] + pub struct DepositInstructionData { + discriminator: u8, + } + +impl DepositInstructionData { + pub fn new() -> Self { + Self { + discriminator: 10, + } + } + + pub(crate) fn try_to_vec(&self) -> Result, std::io::Error> { + borsh::to_vec(self) + } + } + +impl Default for DepositInstructionData { + fn default() -> Self { + Self::new() + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] + pub struct DepositInstructionArgs { + pub amount: u64, + } + +impl DepositInstructionArgs { + pub(crate) fn try_to_vec(&self) -> Result, std::io::Error> { + borsh::to_vec(self) + } +} + + +/// Instruction builder for `Deposit`. +/// +/// ### Accounts: +/// + /// 0. `[writable, signer]` signer + /// 1. `[]` mint + /// 2. `[writable]` sender + /// 3. `[writable]` stake + /// 4. `[writable]` stake_tokens + /// 5. `[writable]` treasury + /// 6. `[optional]` system_program (default to `11111111111111111111111111111111`) + /// 7. `[optional]` token_program (default to `TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA`) + /// 8. `[]` associated_token_program +#[derive(Clone, Debug, Default)] +pub struct DepositBuilder { + signer: Option, + mint: Option, + sender: Option, + stake: Option, + stake_tokens: Option, + treasury: Option, + system_program: Option, + token_program: Option, + associated_token_program: Option, + amount: Option, + __remaining_accounts: Vec, +} + +impl DepositBuilder { + pub fn new() -> Self { + Self::default() + } + #[inline(always)] + pub fn signer(&mut self, signer: solana_pubkey::Pubkey) -> &mut Self { + self.signer = Some(signer); + self + } + #[inline(always)] + pub fn mint(&mut self, mint: solana_pubkey::Pubkey) -> &mut Self { + self.mint = Some(mint); + self + } + #[inline(always)] + pub fn sender(&mut self, sender: solana_pubkey::Pubkey) -> &mut Self { + self.sender = Some(sender); + self + } + #[inline(always)] + pub fn stake(&mut self, stake: solana_pubkey::Pubkey) -> &mut Self { + self.stake = Some(stake); + self + } + #[inline(always)] + pub fn stake_tokens(&mut self, stake_tokens: solana_pubkey::Pubkey) -> &mut Self { + self.stake_tokens = Some(stake_tokens); + self + } + #[inline(always)] + pub fn treasury(&mut self, treasury: solana_pubkey::Pubkey) -> &mut Self { + self.treasury = Some(treasury); + self + } + /// `[optional account, default to '11111111111111111111111111111111']` +#[inline(always)] + pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self { + self.system_program = Some(system_program); + self + } + /// `[optional account, default to 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA']` +#[inline(always)] + pub fn token_program(&mut self, token_program: solana_pubkey::Pubkey) -> &mut Self { + self.token_program = Some(token_program); + self + } + #[inline(always)] + pub fn associated_token_program(&mut self, associated_token_program: solana_pubkey::Pubkey) -> &mut Self { + self.associated_token_program = Some(associated_token_program); + self + } + #[inline(always)] + pub fn amount(&mut self, amount: u64) -> &mut Self { + self.amount = Some(amount); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self { + self.__remaining_accounts.push(account); + self + } + /// Add additional accounts to the instruction. + #[inline(always)] + pub fn add_remaining_accounts(&mut self, accounts: &[solana_instruction::AccountMeta]) -> &mut Self { + self.__remaining_accounts.extend_from_slice(accounts); + self + } + #[allow(clippy::clone_on_copy)] + pub fn instruction(&self) -> solana_instruction::Instruction { + let accounts = Deposit { + signer: self.signer.expect("signer is not set"), + mint: self.mint.expect("mint is not set"), + sender: self.sender.expect("sender is not set"), + stake: self.stake.expect("stake is not set"), + stake_tokens: self.stake_tokens.expect("stake_tokens is not set"), + treasury: self.treasury.expect("treasury is not set"), + system_program: self.system_program.unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")), + token_program: self.token_program.unwrap_or(solana_pubkey::pubkey!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA")), + associated_token_program: self.associated_token_program.expect("associated_token_program is not set"), + }; + let args = DepositInstructionArgs { + amount: self.amount.clone().expect("amount is not set"), + }; + + accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts) + } +} + + /// `deposit` CPI accounts. + pub struct DepositCpiAccounts<'a, 'b> { + + + pub signer: &'b solana_account_info::AccountInfo<'a>, + + + pub mint: &'b solana_account_info::AccountInfo<'a>, + + + pub sender: &'b solana_account_info::AccountInfo<'a>, + + + pub stake: &'b solana_account_info::AccountInfo<'a>, + + + pub stake_tokens: &'b solana_account_info::AccountInfo<'a>, + + + pub treasury: &'b solana_account_info::AccountInfo<'a>, + + + pub system_program: &'b solana_account_info::AccountInfo<'a>, + + + pub token_program: &'b solana_account_info::AccountInfo<'a>, + + + pub associated_token_program: &'b solana_account_info::AccountInfo<'a>, + } + +/// `deposit` CPI instruction. +pub struct DepositCpi<'a, 'b> { + /// The program to invoke. + pub __program: &'b solana_account_info::AccountInfo<'a>, + + + pub signer: &'b solana_account_info::AccountInfo<'a>, + + + pub mint: &'b solana_account_info::AccountInfo<'a>, + + + pub sender: &'b solana_account_info::AccountInfo<'a>, + + + pub stake: &'b solana_account_info::AccountInfo<'a>, + + + pub stake_tokens: &'b solana_account_info::AccountInfo<'a>, + + + pub treasury: &'b solana_account_info::AccountInfo<'a>, + + + pub system_program: &'b solana_account_info::AccountInfo<'a>, + + + pub token_program: &'b solana_account_info::AccountInfo<'a>, + + + pub associated_token_program: &'b solana_account_info::AccountInfo<'a>, + /// The arguments for the instruction. + pub __args: DepositInstructionArgs, + } + +impl<'a, 'b> DepositCpi<'a, 'b> { + pub fn new( + program: &'b solana_account_info::AccountInfo<'a>, + accounts: DepositCpiAccounts<'a, 'b>, + args: DepositInstructionArgs, + ) -> Self { + Self { + __program: program, + signer: accounts.signer, + mint: accounts.mint, + sender: accounts.sender, + stake: accounts.stake, + stake_tokens: accounts.stake_tokens, + treasury: accounts.treasury, + system_program: accounts.system_program, + token_program: accounts.token_program, + associated_token_program: accounts.associated_token_program, + __args: args, + } + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], &[]) + } + #[inline(always)] + pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], remaining_accounts) + } + #[inline(always)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(signers_seeds, &[]) + } + #[allow(clippy::arithmetic_side_effects)] + #[allow(clippy::clone_on_copy)] + #[allow(clippy::vec_init_then_push)] + pub fn invoke_signed_with_remaining_accounts( + &self, + signers_seeds: &[&[&[u8]]], + remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)] + ) -> solana_program_error::ProgramResult { + let mut accounts = Vec::with_capacity(9+ remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new( + *self.signer.key, + true + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.mint.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.sender.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.stake.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.stake_tokens.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.treasury.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.system_program.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.token_program.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.associated_token_program.key, + false + )); + remaining_accounts.iter().for_each(|remaining_account| { + accounts.push(solana_instruction::AccountMeta { + pubkey: *remaining_account.0.key, + is_signer: remaining_account.1, + is_writable: remaining_account.2, + }) + }); + let mut data = DepositInstructionData::new().try_to_vec().unwrap(); + let mut args = self.__args.try_to_vec().unwrap(); + data.append(&mut args); + + let instruction = solana_instruction::Instruction { + program_id: crate::ORE_ID, + accounts, + data, + }; + let mut account_infos = Vec::with_capacity(10 + remaining_accounts.len()); + account_infos.push(self.__program.clone()); + account_infos.push(self.signer.clone()); + account_infos.push(self.mint.clone()); + account_infos.push(self.sender.clone()); + account_infos.push(self.stake.clone()); + account_infos.push(self.stake_tokens.clone()); + account_infos.push(self.treasury.clone()); + account_infos.push(self.system_program.clone()); + account_infos.push(self.token_program.clone()); + account_infos.push(self.associated_token_program.clone()); + remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone())); + + if signers_seeds.is_empty() { + solana_cpi::invoke(&instruction, &account_infos) + } else { + solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds) + } + } +} + +/// Instruction builder for `Deposit` via CPI. +/// +/// ### Accounts: +/// + /// 0. `[writable, signer]` signer + /// 1. `[]` mint + /// 2. `[writable]` sender + /// 3. `[writable]` stake + /// 4. `[writable]` stake_tokens + /// 5. `[writable]` treasury + /// 6. `[]` system_program + /// 7. `[]` token_program + /// 8. `[]` associated_token_program +#[derive(Clone, Debug)] +pub struct DepositCpiBuilder<'a, 'b> { + instruction: Box>, +} + +impl<'a, 'b> DepositCpiBuilder<'a, 'b> { + pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self { + let instruction = Box::new(DepositCpiBuilderInstruction { + __program: program, + signer: None, + mint: None, + sender: None, + stake: None, + stake_tokens: None, + treasury: None, + system_program: None, + token_program: None, + associated_token_program: None, + amount: None, + __remaining_accounts: Vec::new(), + }); + Self { instruction } + } + #[inline(always)] + pub fn signer(&mut self, signer: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.signer = Some(signer); + self + } + #[inline(always)] + pub fn mint(&mut self, mint: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.mint = Some(mint); + self + } + #[inline(always)] + pub fn sender(&mut self, sender: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.sender = Some(sender); + self + } + #[inline(always)] + pub fn stake(&mut self, stake: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.stake = Some(stake); + self + } + #[inline(always)] + pub fn stake_tokens(&mut self, stake_tokens: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.stake_tokens = Some(stake_tokens); + self + } + #[inline(always)] + pub fn treasury(&mut self, treasury: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.treasury = Some(treasury); + self + } + #[inline(always)] + pub fn system_program(&mut self, system_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.system_program = Some(system_program); + self + } + #[inline(always)] + pub fn token_program(&mut self, token_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.token_program = Some(token_program); + self + } + #[inline(always)] + pub fn associated_token_program(&mut self, associated_token_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.associated_token_program = Some(associated_token_program); + self + } + #[inline(always)] + pub fn amount(&mut self, amount: u64) -> &mut Self { + self.instruction.amount = Some(amount); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: &'b solana_account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self { + self.instruction.__remaining_accounts.push((account, is_writable, is_signer)); + self + } + /// Add additional accounts to the instruction. + /// + /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not, + /// and a `bool` indicating whether the account is a signer or not. + #[inline(always)] + pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self { + self.instruction.__remaining_accounts.extend_from_slice(accounts); + self + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed(&[]) + } + #[allow(clippy::clone_on_copy)] + #[allow(clippy::vec_init_then_push)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult { + let args = DepositInstructionArgs { + amount: self.instruction.amount.clone().expect("amount is not set"), + }; + let instruction = DepositCpi { + __program: self.instruction.__program, + + signer: self.instruction.signer.expect("signer is not set"), + + mint: self.instruction.mint.expect("mint is not set"), + + sender: self.instruction.sender.expect("sender is not set"), + + stake: self.instruction.stake.expect("stake is not set"), + + stake_tokens: self.instruction.stake_tokens.expect("stake_tokens is not set"), + + treasury: self.instruction.treasury.expect("treasury is not set"), + + system_program: self.instruction.system_program.expect("system_program is not set"), + + token_program: self.instruction.token_program.expect("token_program is not set"), + + associated_token_program: self.instruction.associated_token_program.expect("associated_token_program is not set"), + __args: args, + }; + instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts) + } +} + +#[derive(Clone, Debug)] +struct DepositCpiBuilderInstruction<'a, 'b> { + __program: &'b solana_account_info::AccountInfo<'a>, + signer: Option<&'b solana_account_info::AccountInfo<'a>>, + mint: Option<&'b solana_account_info::AccountInfo<'a>>, + sender: Option<&'b solana_account_info::AccountInfo<'a>>, + stake: Option<&'b solana_account_info::AccountInfo<'a>>, + stake_tokens: Option<&'b solana_account_info::AccountInfo<'a>>, + treasury: Option<&'b solana_account_info::AccountInfo<'a>>, + system_program: Option<&'b solana_account_info::AccountInfo<'a>>, + token_program: Option<&'b solana_account_info::AccountInfo<'a>>, + associated_token_program: Option<&'b solana_account_info::AccountInfo<'a>>, + amount: Option, + /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`. + __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>, +} + diff --git a/clients/rust/src/generated/instructions/log.rs b/clients/rust/src/generated/instructions/log.rs new file mode 100644 index 00000000..260f3e9f --- /dev/null +++ b/clients/rust/src/generated/instructions/log.rs @@ -0,0 +1,252 @@ +//! 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. +//! +//! +//! + +use borsh::BorshSerialize; +use borsh::BorshDeserialize; + +pub const LOG_DISCRIMINATOR: u8 = 8; + +/// Accounts. +#[derive(Debug)] +pub struct Log { + + + pub board: solana_pubkey::Pubkey, + } + +impl Log { + pub fn instruction(&self) -> solana_instruction::Instruction { + self.instruction_with_remaining_accounts(&[]) + } + #[allow(clippy::arithmetic_side_effects)] + #[allow(clippy::vec_init_then_push)] + pub fn instruction_with_remaining_accounts(&self, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction { + let mut accounts = Vec::with_capacity(1+ remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.board, + true + )); + accounts.extend_from_slice(remaining_accounts); + let data = LogInstructionData::new().try_to_vec().unwrap(); + + solana_instruction::Instruction { + program_id: crate::ORE_ID, + accounts, + data, + } + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] + pub struct LogInstructionData { + discriminator: u8, + } + +impl LogInstructionData { + pub fn new() -> Self { + Self { + discriminator: 8, + } + } + + pub(crate) fn try_to_vec(&self) -> Result, std::io::Error> { + borsh::to_vec(self) + } + } + +impl Default for LogInstructionData { + fn default() -> Self { + Self::new() + } +} + + + +/// Instruction builder for `Log`. +/// +/// ### Accounts: +/// + /// 0. `[signer]` board +#[derive(Clone, Debug, Default)] +pub struct LogBuilder { + board: Option, + __remaining_accounts: Vec, +} + +impl LogBuilder { + pub fn new() -> Self { + Self::default() + } + #[inline(always)] + pub fn board(&mut self, board: solana_pubkey::Pubkey) -> &mut Self { + self.board = Some(board); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self { + self.__remaining_accounts.push(account); + self + } + /// Add additional accounts to the instruction. + #[inline(always)] + pub fn add_remaining_accounts(&mut self, accounts: &[solana_instruction::AccountMeta]) -> &mut Self { + self.__remaining_accounts.extend_from_slice(accounts); + self + } + #[allow(clippy::clone_on_copy)] + pub fn instruction(&self) -> solana_instruction::Instruction { + let accounts = Log { + board: self.board.expect("board is not set"), + }; + + accounts.instruction_with_remaining_accounts(&self.__remaining_accounts) + } +} + + /// `log` CPI accounts. + pub struct LogCpiAccounts<'a, 'b> { + + + pub board: &'b solana_account_info::AccountInfo<'a>, + } + +/// `log` CPI instruction. +pub struct LogCpi<'a, 'b> { + /// The program to invoke. + pub __program: &'b solana_account_info::AccountInfo<'a>, + + + pub board: &'b solana_account_info::AccountInfo<'a>, + } + +impl<'a, 'b> LogCpi<'a, 'b> { + pub fn new( + program: &'b solana_account_info::AccountInfo<'a>, + accounts: LogCpiAccounts<'a, 'b>, + ) -> Self { + Self { + __program: program, + board: accounts.board, + } + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], &[]) + } + #[inline(always)] + pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], remaining_accounts) + } + #[inline(always)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(signers_seeds, &[]) + } + #[allow(clippy::arithmetic_side_effects)] + #[allow(clippy::clone_on_copy)] + #[allow(clippy::vec_init_then_push)] + pub fn invoke_signed_with_remaining_accounts( + &self, + signers_seeds: &[&[&[u8]]], + remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)] + ) -> solana_program_error::ProgramResult { + let mut accounts = Vec::with_capacity(1+ remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.board.key, + true + )); + remaining_accounts.iter().for_each(|remaining_account| { + accounts.push(solana_instruction::AccountMeta { + pubkey: *remaining_account.0.key, + is_signer: remaining_account.1, + is_writable: remaining_account.2, + }) + }); + let data = LogInstructionData::new().try_to_vec().unwrap(); + + let instruction = solana_instruction::Instruction { + program_id: crate::ORE_ID, + accounts, + data, + }; + let mut account_infos = Vec::with_capacity(2 + remaining_accounts.len()); + account_infos.push(self.__program.clone()); + account_infos.push(self.board.clone()); + remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone())); + + if signers_seeds.is_empty() { + solana_cpi::invoke(&instruction, &account_infos) + } else { + solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds) + } + } +} + +/// Instruction builder for `Log` via CPI. +/// +/// ### Accounts: +/// + /// 0. `[signer]` board +#[derive(Clone, Debug)] +pub struct LogCpiBuilder<'a, 'b> { + instruction: Box>, +} + +impl<'a, 'b> LogCpiBuilder<'a, 'b> { + pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self { + let instruction = Box::new(LogCpiBuilderInstruction { + __program: program, + board: None, + __remaining_accounts: Vec::new(), + }); + Self { instruction } + } + #[inline(always)] + pub fn board(&mut self, board: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.board = Some(board); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: &'b solana_account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self { + self.instruction.__remaining_accounts.push((account, is_writable, is_signer)); + self + } + /// Add additional accounts to the instruction. + /// + /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not, + /// and a `bool` indicating whether the account is a signer or not. + #[inline(always)] + pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self { + self.instruction.__remaining_accounts.extend_from_slice(accounts); + self + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed(&[]) + } + #[allow(clippy::clone_on_copy)] + #[allow(clippy::vec_init_then_push)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult { + let instruction = LogCpi { + __program: self.instruction.__program, + + board: self.instruction.board.expect("board is not set"), + }; + instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts) + } +} + +#[derive(Clone, Debug)] +struct LogCpiBuilderInstruction<'a, 'b> { + __program: &'b solana_account_info::AccountInfo<'a>, + board: Option<&'b solana_account_info::AccountInfo<'a>>, + /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`. + __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>, +} + diff --git a/clients/rust/src/generated/instructions/mod.rs b/clients/rust/src/generated/instructions/mod.rs new file mode 100644 index 00000000..438ba0cc --- /dev/null +++ b/clients/rust/src/generated/instructions/mod.rs @@ -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. +//! +//! +//! + + pub(crate) mod r#automate; + pub(crate) mod r#bury; + pub(crate) mod r#checkpoint; + pub(crate) mod r#claim_ore; + pub(crate) mod r#claim_sol; + pub(crate) mod r#claim_yield; + pub(crate) mod r#close; + pub(crate) mod r#deploy; + pub(crate) mod r#deposit; + pub(crate) mod r#log; + pub(crate) mod r#new_var; + pub(crate) mod r#reset; + pub(crate) mod r#set_admin; + pub(crate) mod r#withdraw; + pub(crate) mod r#wrap; + + pub use self::r#automate::*; + pub use self::r#bury::*; + pub use self::r#checkpoint::*; + pub use self::r#claim_ore::*; + pub use self::r#claim_sol::*; + pub use self::r#claim_yield::*; + pub use self::r#close::*; + pub use self::r#deploy::*; + pub use self::r#deposit::*; + pub use self::r#log::*; + pub use self::r#new_var::*; + pub use self::r#reset::*; + pub use self::r#set_admin::*; + pub use self::r#withdraw::*; + pub use self::r#wrap::*; + diff --git a/clients/rust/src/generated/instructions/new_var.rs b/clients/rust/src/generated/instructions/new_var.rs new file mode 100644 index 00000000..464cab07 --- /dev/null +++ b/clients/rust/src/generated/instructions/new_var.rs @@ -0,0 +1,546 @@ +//! 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. +//! +//! +//! + +use borsh::BorshSerialize; +use borsh::BorshDeserialize; + +pub const NEW_VAR_DISCRIMINATOR: u8 = 17; + +/// Accounts. +#[derive(Debug)] +pub struct NewVar { + + + pub signer: solana_pubkey::Pubkey, + + + pub board: solana_pubkey::Pubkey, + + + pub config: solana_pubkey::Pubkey, + + + pub provider: solana_pubkey::Pubkey, + + + pub var: solana_pubkey::Pubkey, + + + pub system_program: solana_pubkey::Pubkey, + + + pub entropy_program: solana_pubkey::Pubkey, + } + +impl NewVar { + pub fn instruction(&self, args: NewVarInstructionArgs) -> solana_instruction::Instruction { + self.instruction_with_remaining_accounts(args, &[]) + } + #[allow(clippy::arithmetic_side_effects)] + #[allow(clippy::vec_init_then_push)] + pub fn instruction_with_remaining_accounts(&self, args: NewVarInstructionArgs, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction { + let mut accounts = Vec::with_capacity(7+ remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.signer, + true + )); + accounts.push(solana_instruction::AccountMeta::new( + self.board, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.config, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.provider, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.var, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.system_program, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.entropy_program, + false + )); + accounts.extend_from_slice(remaining_accounts); + let mut data = NewVarInstructionData::new().try_to_vec().unwrap(); + let mut args = args.try_to_vec().unwrap(); + data.append(&mut args); + + solana_instruction::Instruction { + program_id: crate::ORE_ID, + accounts, + data, + } + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] + pub struct NewVarInstructionData { + discriminator: u8, + } + +impl NewVarInstructionData { + pub fn new() -> Self { + Self { + discriminator: 17, + } + } + + pub(crate) fn try_to_vec(&self) -> Result, std::io::Error> { + borsh::to_vec(self) + } + } + +impl Default for NewVarInstructionData { + fn default() -> Self { + Self::new() + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] + pub struct NewVarInstructionArgs { + pub id: u64, + pub commit: [u8; 32], + pub samples: u64, + } + +impl NewVarInstructionArgs { + pub(crate) fn try_to_vec(&self) -> Result, std::io::Error> { + borsh::to_vec(self) + } +} + + +/// Instruction builder for `NewVar`. +/// +/// ### Accounts: +/// + /// 0. `[signer]` signer + /// 1. `[writable]` board + /// 2. `[writable]` config + /// 3. `[]` provider + /// 4. `[writable]` var + /// 5. `[optional]` system_program (default to `11111111111111111111111111111111`) + /// 6. `[]` entropy_program +#[derive(Clone, Debug, Default)] +pub struct NewVarBuilder { + signer: Option, + board: Option, + config: Option, + provider: Option, + var: Option, + system_program: Option, + entropy_program: Option, + id: Option, + commit: Option<[u8; 32]>, + samples: Option, + __remaining_accounts: Vec, +} + +impl NewVarBuilder { + pub fn new() -> Self { + Self::default() + } + #[inline(always)] + pub fn signer(&mut self, signer: solana_pubkey::Pubkey) -> &mut Self { + self.signer = Some(signer); + self + } + #[inline(always)] + pub fn board(&mut self, board: solana_pubkey::Pubkey) -> &mut Self { + self.board = Some(board); + self + } + #[inline(always)] + pub fn config(&mut self, config: solana_pubkey::Pubkey) -> &mut Self { + self.config = Some(config); + self + } + #[inline(always)] + pub fn provider(&mut self, provider: solana_pubkey::Pubkey) -> &mut Self { + self.provider = Some(provider); + self + } + #[inline(always)] + pub fn var(&mut self, var: solana_pubkey::Pubkey) -> &mut Self { + self.var = Some(var); + self + } + /// `[optional account, default to '11111111111111111111111111111111']` +#[inline(always)] + pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self { + self.system_program = Some(system_program); + self + } + #[inline(always)] + pub fn entropy_program(&mut self, entropy_program: solana_pubkey::Pubkey) -> &mut Self { + self.entropy_program = Some(entropy_program); + self + } + #[inline(always)] + pub fn id(&mut self, id: u64) -> &mut Self { + self.id = Some(id); + self + } + #[inline(always)] + pub fn commit(&mut self, commit: [u8; 32]) -> &mut Self { + self.commit = Some(commit); + self + } + #[inline(always)] + pub fn samples(&mut self, samples: u64) -> &mut Self { + self.samples = Some(samples); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self { + self.__remaining_accounts.push(account); + self + } + /// Add additional accounts to the instruction. + #[inline(always)] + pub fn add_remaining_accounts(&mut self, accounts: &[solana_instruction::AccountMeta]) -> &mut Self { + self.__remaining_accounts.extend_from_slice(accounts); + self + } + #[allow(clippy::clone_on_copy)] + pub fn instruction(&self) -> solana_instruction::Instruction { + let accounts = NewVar { + signer: self.signer.expect("signer is not set"), + board: self.board.expect("board is not set"), + config: self.config.expect("config is not set"), + provider: self.provider.expect("provider is not set"), + var: self.var.expect("var is not set"), + system_program: self.system_program.unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")), + entropy_program: self.entropy_program.expect("entropy_program is not set"), + }; + let args = NewVarInstructionArgs { + id: self.id.clone().expect("id is not set"), + commit: self.commit.clone().expect("commit is not set"), + samples: self.samples.clone().expect("samples is not set"), + }; + + accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts) + } +} + + /// `new_var` CPI accounts. + pub struct NewVarCpiAccounts<'a, 'b> { + + + pub signer: &'b solana_account_info::AccountInfo<'a>, + + + pub board: &'b solana_account_info::AccountInfo<'a>, + + + pub config: &'b solana_account_info::AccountInfo<'a>, + + + pub provider: &'b solana_account_info::AccountInfo<'a>, + + + pub var: &'b solana_account_info::AccountInfo<'a>, + + + pub system_program: &'b solana_account_info::AccountInfo<'a>, + + + pub entropy_program: &'b solana_account_info::AccountInfo<'a>, + } + +/// `new_var` CPI instruction. +pub struct NewVarCpi<'a, 'b> { + /// The program to invoke. + pub __program: &'b solana_account_info::AccountInfo<'a>, + + + pub signer: &'b solana_account_info::AccountInfo<'a>, + + + pub board: &'b solana_account_info::AccountInfo<'a>, + + + pub config: &'b solana_account_info::AccountInfo<'a>, + + + pub provider: &'b solana_account_info::AccountInfo<'a>, + + + pub var: &'b solana_account_info::AccountInfo<'a>, + + + pub system_program: &'b solana_account_info::AccountInfo<'a>, + + + pub entropy_program: &'b solana_account_info::AccountInfo<'a>, + /// The arguments for the instruction. + pub __args: NewVarInstructionArgs, + } + +impl<'a, 'b> NewVarCpi<'a, 'b> { + pub fn new( + program: &'b solana_account_info::AccountInfo<'a>, + accounts: NewVarCpiAccounts<'a, 'b>, + args: NewVarInstructionArgs, + ) -> Self { + Self { + __program: program, + signer: accounts.signer, + board: accounts.board, + config: accounts.config, + provider: accounts.provider, + var: accounts.var, + system_program: accounts.system_program, + entropy_program: accounts.entropy_program, + __args: args, + } + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], &[]) + } + #[inline(always)] + pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], remaining_accounts) + } + #[inline(always)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(signers_seeds, &[]) + } + #[allow(clippy::arithmetic_side_effects)] + #[allow(clippy::clone_on_copy)] + #[allow(clippy::vec_init_then_push)] + pub fn invoke_signed_with_remaining_accounts( + &self, + signers_seeds: &[&[&[u8]]], + remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)] + ) -> solana_program_error::ProgramResult { + let mut accounts = Vec::with_capacity(7+ remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.signer.key, + true + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.board.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.config.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.provider.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.var.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.system_program.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.entropy_program.key, + false + )); + remaining_accounts.iter().for_each(|remaining_account| { + accounts.push(solana_instruction::AccountMeta { + pubkey: *remaining_account.0.key, + is_signer: remaining_account.1, + is_writable: remaining_account.2, + }) + }); + let mut data = NewVarInstructionData::new().try_to_vec().unwrap(); + let mut args = self.__args.try_to_vec().unwrap(); + data.append(&mut args); + + let instruction = solana_instruction::Instruction { + program_id: crate::ORE_ID, + accounts, + data, + }; + let mut account_infos = Vec::with_capacity(8 + remaining_accounts.len()); + account_infos.push(self.__program.clone()); + account_infos.push(self.signer.clone()); + account_infos.push(self.board.clone()); + account_infos.push(self.config.clone()); + account_infos.push(self.provider.clone()); + account_infos.push(self.var.clone()); + account_infos.push(self.system_program.clone()); + account_infos.push(self.entropy_program.clone()); + remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone())); + + if signers_seeds.is_empty() { + solana_cpi::invoke(&instruction, &account_infos) + } else { + solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds) + } + } +} + +/// Instruction builder for `NewVar` via CPI. +/// +/// ### Accounts: +/// + /// 0. `[signer]` signer + /// 1. `[writable]` board + /// 2. `[writable]` config + /// 3. `[]` provider + /// 4. `[writable]` var + /// 5. `[]` system_program + /// 6. `[]` entropy_program +#[derive(Clone, Debug)] +pub struct NewVarCpiBuilder<'a, 'b> { + instruction: Box>, +} + +impl<'a, 'b> NewVarCpiBuilder<'a, 'b> { + pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self { + let instruction = Box::new(NewVarCpiBuilderInstruction { + __program: program, + signer: None, + board: None, + config: None, + provider: None, + var: None, + system_program: None, + entropy_program: None, + id: None, + commit: None, + samples: None, + __remaining_accounts: Vec::new(), + }); + Self { instruction } + } + #[inline(always)] + pub fn signer(&mut self, signer: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.signer = Some(signer); + self + } + #[inline(always)] + pub fn board(&mut self, board: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.board = Some(board); + self + } + #[inline(always)] + pub fn config(&mut self, config: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.config = Some(config); + self + } + #[inline(always)] + pub fn provider(&mut self, provider: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.provider = Some(provider); + self + } + #[inline(always)] + pub fn var(&mut self, var: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.var = Some(var); + self + } + #[inline(always)] + pub fn system_program(&mut self, system_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.system_program = Some(system_program); + self + } + #[inline(always)] + pub fn entropy_program(&mut self, entropy_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.entropy_program = Some(entropy_program); + self + } + #[inline(always)] + pub fn id(&mut self, id: u64) -> &mut Self { + self.instruction.id = Some(id); + self + } + #[inline(always)] + pub fn commit(&mut self, commit: [u8; 32]) -> &mut Self { + self.instruction.commit = Some(commit); + self + } + #[inline(always)] + pub fn samples(&mut self, samples: u64) -> &mut Self { + self.instruction.samples = Some(samples); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: &'b solana_account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self { + self.instruction.__remaining_accounts.push((account, is_writable, is_signer)); + self + } + /// Add additional accounts to the instruction. + /// + /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not, + /// and a `bool` indicating whether the account is a signer or not. + #[inline(always)] + pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self { + self.instruction.__remaining_accounts.extend_from_slice(accounts); + self + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed(&[]) + } + #[allow(clippy::clone_on_copy)] + #[allow(clippy::vec_init_then_push)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult { + let args = NewVarInstructionArgs { + id: self.instruction.id.clone().expect("id is not set"), + commit: self.instruction.commit.clone().expect("commit is not set"), + samples: self.instruction.samples.clone().expect("samples is not set"), + }; + let instruction = NewVarCpi { + __program: self.instruction.__program, + + signer: self.instruction.signer.expect("signer is not set"), + + board: self.instruction.board.expect("board is not set"), + + config: self.instruction.config.expect("config is not set"), + + provider: self.instruction.provider.expect("provider is not set"), + + var: self.instruction.var.expect("var is not set"), + + system_program: self.instruction.system_program.expect("system_program is not set"), + + entropy_program: self.instruction.entropy_program.expect("entropy_program is not set"), + __args: args, + }; + instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts) + } +} + +#[derive(Clone, Debug)] +struct NewVarCpiBuilderInstruction<'a, 'b> { + __program: &'b solana_account_info::AccountInfo<'a>, + signer: Option<&'b solana_account_info::AccountInfo<'a>>, + board: Option<&'b solana_account_info::AccountInfo<'a>>, + config: Option<&'b solana_account_info::AccountInfo<'a>>, + provider: Option<&'b solana_account_info::AccountInfo<'a>>, + var: Option<&'b solana_account_info::AccountInfo<'a>>, + system_program: Option<&'b solana_account_info::AccountInfo<'a>>, + entropy_program: Option<&'b solana_account_info::AccountInfo<'a>>, + id: Option, + commit: Option<[u8; 32]>, + samples: Option, + /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`. + __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>, +} + diff --git a/clients/rust/src/generated/instructions/reset.rs b/clients/rust/src/generated/instructions/reset.rs new file mode 100644 index 00000000..061ae58e --- /dev/null +++ b/clients/rust/src/generated/instructions/reset.rs @@ -0,0 +1,810 @@ +//! 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. +//! +//! +//! + +use borsh::BorshSerialize; +use borsh::BorshDeserialize; + +pub const RESET_DISCRIMINATOR: u8 = 9; + +/// Accounts. +#[derive(Debug)] +pub struct Reset { + + + pub signer: solana_pubkey::Pubkey, + + + pub board: solana_pubkey::Pubkey, + + + pub config: solana_pubkey::Pubkey, + + + pub fee_collector: solana_pubkey::Pubkey, + + + pub mint: solana_pubkey::Pubkey, + + + pub round: solana_pubkey::Pubkey, + + + pub round_next: solana_pubkey::Pubkey, + + + pub top_miner: solana_pubkey::Pubkey, + + + pub treasury: solana_pubkey::Pubkey, + + + pub treasury_tokens: solana_pubkey::Pubkey, + + + pub system_program: solana_pubkey::Pubkey, + + + pub token_program: solana_pubkey::Pubkey, + + + pub ore_program: solana_pubkey::Pubkey, + + + pub slot_hashes_sysvar: solana_pubkey::Pubkey, + + + pub entropy_var: solana_pubkey::Pubkey, + + + pub entropy_program: solana_pubkey::Pubkey, + } + +impl Reset { + pub fn instruction(&self) -> solana_instruction::Instruction { + self.instruction_with_remaining_accounts(&[]) + } + #[allow(clippy::arithmetic_side_effects)] + #[allow(clippy::vec_init_then_push)] + pub fn instruction_with_remaining_accounts(&self, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction { + let mut accounts = Vec::with_capacity(16+ remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new( + self.signer, + true + )); + accounts.push(solana_instruction::AccountMeta::new( + self.board, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.config, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.fee_collector, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.mint, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.round, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.round_next, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.top_miner, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.treasury, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.treasury_tokens, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.system_program, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.token_program, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.ore_program, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.slot_hashes_sysvar, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.entropy_var, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.entropy_program, + false + )); + accounts.extend_from_slice(remaining_accounts); + let data = ResetInstructionData::new().try_to_vec().unwrap(); + + solana_instruction::Instruction { + program_id: crate::ORE_ID, + accounts, + data, + } + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] + pub struct ResetInstructionData { + discriminator: u8, + } + +impl ResetInstructionData { + pub fn new() -> Self { + Self { + discriminator: 9, + } + } + + pub(crate) fn try_to_vec(&self) -> Result, std::io::Error> { + borsh::to_vec(self) + } + } + +impl Default for ResetInstructionData { + fn default() -> Self { + Self::new() + } +} + + + +/// Instruction builder for `Reset`. +/// +/// ### Accounts: +/// + /// 0. `[writable, signer]` signer + /// 1. `[writable]` board + /// 2. `[]` config + /// 3. `[writable]` fee_collector + /// 4. `[writable]` mint + /// 5. `[writable]` round + /// 6. `[writable]` round_next + /// 7. `[]` top_miner + /// 8. `[writable]` treasury + /// 9. `[writable]` treasury_tokens + /// 10. `[optional]` system_program (default to `11111111111111111111111111111111`) + /// 11. `[optional]` token_program (default to `TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA`) + /// 12. `[]` ore_program + /// 13. `[optional]` slot_hashes_sysvar (default to `SysvarS1otHashes111111111111111111111111111`) + /// 14. `[]` entropy_var + /// 15. `[]` entropy_program +#[derive(Clone, Debug, Default)] +pub struct ResetBuilder { + signer: Option, + board: Option, + config: Option, + fee_collector: Option, + mint: Option, + round: Option, + round_next: Option, + top_miner: Option, + treasury: Option, + treasury_tokens: Option, + system_program: Option, + token_program: Option, + ore_program: Option, + slot_hashes_sysvar: Option, + entropy_var: Option, + entropy_program: Option, + __remaining_accounts: Vec, +} + +impl ResetBuilder { + pub fn new() -> Self { + Self::default() + } + #[inline(always)] + pub fn signer(&mut self, signer: solana_pubkey::Pubkey) -> &mut Self { + self.signer = Some(signer); + self + } + #[inline(always)] + pub fn board(&mut self, board: solana_pubkey::Pubkey) -> &mut Self { + self.board = Some(board); + self + } + #[inline(always)] + pub fn config(&mut self, config: solana_pubkey::Pubkey) -> &mut Self { + self.config = Some(config); + self + } + #[inline(always)] + pub fn fee_collector(&mut self, fee_collector: solana_pubkey::Pubkey) -> &mut Self { + self.fee_collector = Some(fee_collector); + self + } + #[inline(always)] + pub fn mint(&mut self, mint: solana_pubkey::Pubkey) -> &mut Self { + self.mint = Some(mint); + self + } + #[inline(always)] + pub fn round(&mut self, round: solana_pubkey::Pubkey) -> &mut Self { + self.round = Some(round); + self + } + #[inline(always)] + pub fn round_next(&mut self, round_next: solana_pubkey::Pubkey) -> &mut Self { + self.round_next = Some(round_next); + self + } + #[inline(always)] + pub fn top_miner(&mut self, top_miner: solana_pubkey::Pubkey) -> &mut Self { + self.top_miner = Some(top_miner); + self + } + #[inline(always)] + pub fn treasury(&mut self, treasury: solana_pubkey::Pubkey) -> &mut Self { + self.treasury = Some(treasury); + self + } + #[inline(always)] + pub fn treasury_tokens(&mut self, treasury_tokens: solana_pubkey::Pubkey) -> &mut Self { + self.treasury_tokens = Some(treasury_tokens); + self + } + /// `[optional account, default to '11111111111111111111111111111111']` +#[inline(always)] + pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self { + self.system_program = Some(system_program); + self + } + /// `[optional account, default to 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA']` +#[inline(always)] + pub fn token_program(&mut self, token_program: solana_pubkey::Pubkey) -> &mut Self { + self.token_program = Some(token_program); + self + } + #[inline(always)] + pub fn ore_program(&mut self, ore_program: solana_pubkey::Pubkey) -> &mut Self { + self.ore_program = Some(ore_program); + self + } + /// `[optional account, default to 'SysvarS1otHashes111111111111111111111111111']` +#[inline(always)] + pub fn slot_hashes_sysvar(&mut self, slot_hashes_sysvar: solana_pubkey::Pubkey) -> &mut Self { + self.slot_hashes_sysvar = Some(slot_hashes_sysvar); + self + } + #[inline(always)] + pub fn entropy_var(&mut self, entropy_var: solana_pubkey::Pubkey) -> &mut Self { + self.entropy_var = Some(entropy_var); + self + } + #[inline(always)] + pub fn entropy_program(&mut self, entropy_program: solana_pubkey::Pubkey) -> &mut Self { + self.entropy_program = Some(entropy_program); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self { + self.__remaining_accounts.push(account); + self + } + /// Add additional accounts to the instruction. + #[inline(always)] + pub fn add_remaining_accounts(&mut self, accounts: &[solana_instruction::AccountMeta]) -> &mut Self { + self.__remaining_accounts.extend_from_slice(accounts); + self + } + #[allow(clippy::clone_on_copy)] + pub fn instruction(&self) -> solana_instruction::Instruction { + let accounts = Reset { + signer: self.signer.expect("signer is not set"), + board: self.board.expect("board is not set"), + config: self.config.expect("config is not set"), + fee_collector: self.fee_collector.expect("fee_collector is not set"), + mint: self.mint.expect("mint is not set"), + round: self.round.expect("round is not set"), + round_next: self.round_next.expect("round_next is not set"), + top_miner: self.top_miner.expect("top_miner is not set"), + treasury: self.treasury.expect("treasury is not set"), + treasury_tokens: self.treasury_tokens.expect("treasury_tokens is not set"), + system_program: self.system_program.unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")), + token_program: self.token_program.unwrap_or(solana_pubkey::pubkey!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA")), + ore_program: self.ore_program.expect("ore_program is not set"), + slot_hashes_sysvar: self.slot_hashes_sysvar.unwrap_or(solana_pubkey::pubkey!("SysvarS1otHashes111111111111111111111111111")), + entropy_var: self.entropy_var.expect("entropy_var is not set"), + entropy_program: self.entropy_program.expect("entropy_program is not set"), + }; + + accounts.instruction_with_remaining_accounts(&self.__remaining_accounts) + } +} + + /// `reset` CPI accounts. + pub struct ResetCpiAccounts<'a, 'b> { + + + pub signer: &'b solana_account_info::AccountInfo<'a>, + + + pub board: &'b solana_account_info::AccountInfo<'a>, + + + pub config: &'b solana_account_info::AccountInfo<'a>, + + + pub fee_collector: &'b solana_account_info::AccountInfo<'a>, + + + pub mint: &'b solana_account_info::AccountInfo<'a>, + + + pub round: &'b solana_account_info::AccountInfo<'a>, + + + pub round_next: &'b solana_account_info::AccountInfo<'a>, + + + pub top_miner: &'b solana_account_info::AccountInfo<'a>, + + + pub treasury: &'b solana_account_info::AccountInfo<'a>, + + + pub treasury_tokens: &'b solana_account_info::AccountInfo<'a>, + + + pub system_program: &'b solana_account_info::AccountInfo<'a>, + + + pub token_program: &'b solana_account_info::AccountInfo<'a>, + + + pub ore_program: &'b solana_account_info::AccountInfo<'a>, + + + pub slot_hashes_sysvar: &'b solana_account_info::AccountInfo<'a>, + + + pub entropy_var: &'b solana_account_info::AccountInfo<'a>, + + + pub entropy_program: &'b solana_account_info::AccountInfo<'a>, + } + +/// `reset` CPI instruction. +pub struct ResetCpi<'a, 'b> { + /// The program to invoke. + pub __program: &'b solana_account_info::AccountInfo<'a>, + + + pub signer: &'b solana_account_info::AccountInfo<'a>, + + + pub board: &'b solana_account_info::AccountInfo<'a>, + + + pub config: &'b solana_account_info::AccountInfo<'a>, + + + pub fee_collector: &'b solana_account_info::AccountInfo<'a>, + + + pub mint: &'b solana_account_info::AccountInfo<'a>, + + + pub round: &'b solana_account_info::AccountInfo<'a>, + + + pub round_next: &'b solana_account_info::AccountInfo<'a>, + + + pub top_miner: &'b solana_account_info::AccountInfo<'a>, + + + pub treasury: &'b solana_account_info::AccountInfo<'a>, + + + pub treasury_tokens: &'b solana_account_info::AccountInfo<'a>, + + + pub system_program: &'b solana_account_info::AccountInfo<'a>, + + + pub token_program: &'b solana_account_info::AccountInfo<'a>, + + + pub ore_program: &'b solana_account_info::AccountInfo<'a>, + + + pub slot_hashes_sysvar: &'b solana_account_info::AccountInfo<'a>, + + + pub entropy_var: &'b solana_account_info::AccountInfo<'a>, + + + pub entropy_program: &'b solana_account_info::AccountInfo<'a>, + } + +impl<'a, 'b> ResetCpi<'a, 'b> { + pub fn new( + program: &'b solana_account_info::AccountInfo<'a>, + accounts: ResetCpiAccounts<'a, 'b>, + ) -> Self { + Self { + __program: program, + signer: accounts.signer, + board: accounts.board, + config: accounts.config, + fee_collector: accounts.fee_collector, + mint: accounts.mint, + round: accounts.round, + round_next: accounts.round_next, + top_miner: accounts.top_miner, + treasury: accounts.treasury, + treasury_tokens: accounts.treasury_tokens, + system_program: accounts.system_program, + token_program: accounts.token_program, + ore_program: accounts.ore_program, + slot_hashes_sysvar: accounts.slot_hashes_sysvar, + entropy_var: accounts.entropy_var, + entropy_program: accounts.entropy_program, + } + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], &[]) + } + #[inline(always)] + pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], remaining_accounts) + } + #[inline(always)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(signers_seeds, &[]) + } + #[allow(clippy::arithmetic_side_effects)] + #[allow(clippy::clone_on_copy)] + #[allow(clippy::vec_init_then_push)] + pub fn invoke_signed_with_remaining_accounts( + &self, + signers_seeds: &[&[&[u8]]], + remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)] + ) -> solana_program_error::ProgramResult { + let mut accounts = Vec::with_capacity(16+ remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new( + *self.signer.key, + true + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.board.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.config.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.fee_collector.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.mint.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.round.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.round_next.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.top_miner.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.treasury.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.treasury_tokens.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.system_program.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.token_program.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.ore_program.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.slot_hashes_sysvar.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.entropy_var.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.entropy_program.key, + false + )); + remaining_accounts.iter().for_each(|remaining_account| { + accounts.push(solana_instruction::AccountMeta { + pubkey: *remaining_account.0.key, + is_signer: remaining_account.1, + is_writable: remaining_account.2, + }) + }); + let data = ResetInstructionData::new().try_to_vec().unwrap(); + + let instruction = solana_instruction::Instruction { + program_id: crate::ORE_ID, + accounts, + data, + }; + let mut account_infos = Vec::with_capacity(17 + remaining_accounts.len()); + account_infos.push(self.__program.clone()); + account_infos.push(self.signer.clone()); + account_infos.push(self.board.clone()); + account_infos.push(self.config.clone()); + account_infos.push(self.fee_collector.clone()); + account_infos.push(self.mint.clone()); + account_infos.push(self.round.clone()); + account_infos.push(self.round_next.clone()); + account_infos.push(self.top_miner.clone()); + account_infos.push(self.treasury.clone()); + account_infos.push(self.treasury_tokens.clone()); + account_infos.push(self.system_program.clone()); + account_infos.push(self.token_program.clone()); + account_infos.push(self.ore_program.clone()); + account_infos.push(self.slot_hashes_sysvar.clone()); + account_infos.push(self.entropy_var.clone()); + account_infos.push(self.entropy_program.clone()); + remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone())); + + if signers_seeds.is_empty() { + solana_cpi::invoke(&instruction, &account_infos) + } else { + solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds) + } + } +} + +/// Instruction builder for `Reset` via CPI. +/// +/// ### Accounts: +/// + /// 0. `[writable, signer]` signer + /// 1. `[writable]` board + /// 2. `[]` config + /// 3. `[writable]` fee_collector + /// 4. `[writable]` mint + /// 5. `[writable]` round + /// 6. `[writable]` round_next + /// 7. `[]` top_miner + /// 8. `[writable]` treasury + /// 9. `[writable]` treasury_tokens + /// 10. `[]` system_program + /// 11. `[]` token_program + /// 12. `[]` ore_program + /// 13. `[]` slot_hashes_sysvar + /// 14. `[]` entropy_var + /// 15. `[]` entropy_program +#[derive(Clone, Debug)] +pub struct ResetCpiBuilder<'a, 'b> { + instruction: Box>, +} + +impl<'a, 'b> ResetCpiBuilder<'a, 'b> { + pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self { + let instruction = Box::new(ResetCpiBuilderInstruction { + __program: program, + signer: None, + board: None, + config: None, + fee_collector: None, + mint: None, + round: None, + round_next: None, + top_miner: None, + treasury: None, + treasury_tokens: None, + system_program: None, + token_program: None, + ore_program: None, + slot_hashes_sysvar: None, + entropy_var: None, + entropy_program: None, + __remaining_accounts: Vec::new(), + }); + Self { instruction } + } + #[inline(always)] + pub fn signer(&mut self, signer: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.signer = Some(signer); + self + } + #[inline(always)] + pub fn board(&mut self, board: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.board = Some(board); + self + } + #[inline(always)] + pub fn config(&mut self, config: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.config = Some(config); + self + } + #[inline(always)] + pub fn fee_collector(&mut self, fee_collector: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.fee_collector = Some(fee_collector); + self + } + #[inline(always)] + pub fn mint(&mut self, mint: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.mint = Some(mint); + self + } + #[inline(always)] + pub fn round(&mut self, round: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.round = Some(round); + self + } + #[inline(always)] + pub fn round_next(&mut self, round_next: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.round_next = Some(round_next); + self + } + #[inline(always)] + pub fn top_miner(&mut self, top_miner: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.top_miner = Some(top_miner); + self + } + #[inline(always)] + pub fn treasury(&mut self, treasury: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.treasury = Some(treasury); + self + } + #[inline(always)] + pub fn treasury_tokens(&mut self, treasury_tokens: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.treasury_tokens = Some(treasury_tokens); + self + } + #[inline(always)] + pub fn system_program(&mut self, system_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.system_program = Some(system_program); + self + } + #[inline(always)] + pub fn token_program(&mut self, token_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.token_program = Some(token_program); + self + } + #[inline(always)] + pub fn ore_program(&mut self, ore_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.ore_program = Some(ore_program); + self + } + #[inline(always)] + pub fn slot_hashes_sysvar(&mut self, slot_hashes_sysvar: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.slot_hashes_sysvar = Some(slot_hashes_sysvar); + self + } + #[inline(always)] + pub fn entropy_var(&mut self, entropy_var: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.entropy_var = Some(entropy_var); + self + } + #[inline(always)] + pub fn entropy_program(&mut self, entropy_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.entropy_program = Some(entropy_program); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: &'b solana_account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self { + self.instruction.__remaining_accounts.push((account, is_writable, is_signer)); + self + } + /// Add additional accounts to the instruction. + /// + /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not, + /// and a `bool` indicating whether the account is a signer or not. + #[inline(always)] + pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self { + self.instruction.__remaining_accounts.extend_from_slice(accounts); + self + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed(&[]) + } + #[allow(clippy::clone_on_copy)] + #[allow(clippy::vec_init_then_push)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult { + let instruction = ResetCpi { + __program: self.instruction.__program, + + signer: self.instruction.signer.expect("signer is not set"), + + board: self.instruction.board.expect("board is not set"), + + config: self.instruction.config.expect("config is not set"), + + fee_collector: self.instruction.fee_collector.expect("fee_collector is not set"), + + mint: self.instruction.mint.expect("mint is not set"), + + round: self.instruction.round.expect("round is not set"), + + round_next: self.instruction.round_next.expect("round_next is not set"), + + top_miner: self.instruction.top_miner.expect("top_miner is not set"), + + treasury: self.instruction.treasury.expect("treasury is not set"), + + treasury_tokens: self.instruction.treasury_tokens.expect("treasury_tokens is not set"), + + system_program: self.instruction.system_program.expect("system_program is not set"), + + token_program: self.instruction.token_program.expect("token_program is not set"), + + ore_program: self.instruction.ore_program.expect("ore_program is not set"), + + slot_hashes_sysvar: self.instruction.slot_hashes_sysvar.expect("slot_hashes_sysvar is not set"), + + entropy_var: self.instruction.entropy_var.expect("entropy_var is not set"), + + entropy_program: self.instruction.entropy_program.expect("entropy_program is not set"), + }; + instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts) + } +} + +#[derive(Clone, Debug)] +struct ResetCpiBuilderInstruction<'a, 'b> { + __program: &'b solana_account_info::AccountInfo<'a>, + signer: Option<&'b solana_account_info::AccountInfo<'a>>, + board: Option<&'b solana_account_info::AccountInfo<'a>>, + config: Option<&'b solana_account_info::AccountInfo<'a>>, + fee_collector: Option<&'b solana_account_info::AccountInfo<'a>>, + mint: Option<&'b solana_account_info::AccountInfo<'a>>, + round: Option<&'b solana_account_info::AccountInfo<'a>>, + round_next: Option<&'b solana_account_info::AccountInfo<'a>>, + top_miner: Option<&'b solana_account_info::AccountInfo<'a>>, + treasury: Option<&'b solana_account_info::AccountInfo<'a>>, + treasury_tokens: Option<&'b solana_account_info::AccountInfo<'a>>, + system_program: Option<&'b solana_account_info::AccountInfo<'a>>, + token_program: Option<&'b solana_account_info::AccountInfo<'a>>, + ore_program: Option<&'b solana_account_info::AccountInfo<'a>>, + slot_hashes_sysvar: Option<&'b solana_account_info::AccountInfo<'a>>, + entropy_var: Option<&'b solana_account_info::AccountInfo<'a>>, + entropy_program: Option<&'b solana_account_info::AccountInfo<'a>>, + /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`. + __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>, +} + diff --git a/clients/rust/src/generated/instructions/set_admin.rs b/clients/rust/src/generated/instructions/set_admin.rs new file mode 100644 index 00000000..2057a412 --- /dev/null +++ b/clients/rust/src/generated/instructions/set_admin.rs @@ -0,0 +1,367 @@ +//! 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. +//! +//! +//! + +use solana_pubkey::Pubkey; +use borsh::BorshSerialize; +use borsh::BorshDeserialize; + +pub const SET_ADMIN_DISCRIMINATOR: u8 = 15; + +/// Accounts. +#[derive(Debug)] +pub struct SetAdmin { + + + pub signer: solana_pubkey::Pubkey, + + + pub config: solana_pubkey::Pubkey, + + + pub system_program: solana_pubkey::Pubkey, + } + +impl SetAdmin { + pub fn instruction(&self, args: SetAdminInstructionArgs) -> solana_instruction::Instruction { + self.instruction_with_remaining_accounts(args, &[]) + } + #[allow(clippy::arithmetic_side_effects)] + #[allow(clippy::vec_init_then_push)] + pub fn instruction_with_remaining_accounts(&self, args: SetAdminInstructionArgs, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction { + let mut accounts = Vec::with_capacity(3+ remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.signer, + true + )); + accounts.push(solana_instruction::AccountMeta::new( + self.config, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.system_program, + false + )); + accounts.extend_from_slice(remaining_accounts); + let mut data = SetAdminInstructionData::new().try_to_vec().unwrap(); + let mut args = args.try_to_vec().unwrap(); + data.append(&mut args); + + solana_instruction::Instruction { + program_id: crate::ORE_ID, + accounts, + data, + } + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] + pub struct SetAdminInstructionData { + discriminator: u8, + } + +impl SetAdminInstructionData { + pub fn new() -> Self { + Self { + discriminator: 15, + } + } + + pub(crate) fn try_to_vec(&self) -> Result, std::io::Error> { + borsh::to_vec(self) + } + } + +impl Default for SetAdminInstructionData { + fn default() -> Self { + Self::new() + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] + pub struct SetAdminInstructionArgs { + pub admin: Pubkey, + } + +impl SetAdminInstructionArgs { + pub(crate) fn try_to_vec(&self) -> Result, std::io::Error> { + borsh::to_vec(self) + } +} + + +/// Instruction builder for `SetAdmin`. +/// +/// ### Accounts: +/// + /// 0. `[signer]` signer + /// 1. `[writable]` config + /// 2. `[optional]` system_program (default to `11111111111111111111111111111111`) +#[derive(Clone, Debug, Default)] +pub struct SetAdminBuilder { + signer: Option, + config: Option, + system_program: Option, + admin: Option, + __remaining_accounts: Vec, +} + +impl SetAdminBuilder { + pub fn new() -> Self { + Self::default() + } + #[inline(always)] + pub fn signer(&mut self, signer: solana_pubkey::Pubkey) -> &mut Self { + self.signer = Some(signer); + self + } + #[inline(always)] + pub fn config(&mut self, config: solana_pubkey::Pubkey) -> &mut Self { + self.config = Some(config); + self + } + /// `[optional account, default to '11111111111111111111111111111111']` +#[inline(always)] + pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self { + self.system_program = Some(system_program); + self + } + #[inline(always)] + pub fn admin(&mut self, admin: Pubkey) -> &mut Self { + self.admin = Some(admin); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self { + self.__remaining_accounts.push(account); + self + } + /// Add additional accounts to the instruction. + #[inline(always)] + pub fn add_remaining_accounts(&mut self, accounts: &[solana_instruction::AccountMeta]) -> &mut Self { + self.__remaining_accounts.extend_from_slice(accounts); + self + } + #[allow(clippy::clone_on_copy)] + pub fn instruction(&self) -> solana_instruction::Instruction { + let accounts = SetAdmin { + signer: self.signer.expect("signer is not set"), + config: self.config.expect("config is not set"), + system_program: self.system_program.unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")), + }; + let args = SetAdminInstructionArgs { + admin: self.admin.clone().expect("admin is not set"), + }; + + accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts) + } +} + + /// `set_admin` CPI accounts. + pub struct SetAdminCpiAccounts<'a, 'b> { + + + pub signer: &'b solana_account_info::AccountInfo<'a>, + + + pub config: &'b solana_account_info::AccountInfo<'a>, + + + pub system_program: &'b solana_account_info::AccountInfo<'a>, + } + +/// `set_admin` CPI instruction. +pub struct SetAdminCpi<'a, 'b> { + /// The program to invoke. + pub __program: &'b solana_account_info::AccountInfo<'a>, + + + pub signer: &'b solana_account_info::AccountInfo<'a>, + + + pub config: &'b solana_account_info::AccountInfo<'a>, + + + pub system_program: &'b solana_account_info::AccountInfo<'a>, + /// The arguments for the instruction. + pub __args: SetAdminInstructionArgs, + } + +impl<'a, 'b> SetAdminCpi<'a, 'b> { + pub fn new( + program: &'b solana_account_info::AccountInfo<'a>, + accounts: SetAdminCpiAccounts<'a, 'b>, + args: SetAdminInstructionArgs, + ) -> Self { + Self { + __program: program, + signer: accounts.signer, + config: accounts.config, + system_program: accounts.system_program, + __args: args, + } + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], &[]) + } + #[inline(always)] + pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], remaining_accounts) + } + #[inline(always)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(signers_seeds, &[]) + } + #[allow(clippy::arithmetic_side_effects)] + #[allow(clippy::clone_on_copy)] + #[allow(clippy::vec_init_then_push)] + pub fn invoke_signed_with_remaining_accounts( + &self, + signers_seeds: &[&[&[u8]]], + remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)] + ) -> solana_program_error::ProgramResult { + let mut accounts = Vec::with_capacity(3+ remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.signer.key, + true + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.config.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.system_program.key, + false + )); + remaining_accounts.iter().for_each(|remaining_account| { + accounts.push(solana_instruction::AccountMeta { + pubkey: *remaining_account.0.key, + is_signer: remaining_account.1, + is_writable: remaining_account.2, + }) + }); + let mut data = SetAdminInstructionData::new().try_to_vec().unwrap(); + let mut args = self.__args.try_to_vec().unwrap(); + data.append(&mut args); + + let instruction = solana_instruction::Instruction { + program_id: crate::ORE_ID, + accounts, + data, + }; + let mut account_infos = Vec::with_capacity(4 + remaining_accounts.len()); + account_infos.push(self.__program.clone()); + account_infos.push(self.signer.clone()); + account_infos.push(self.config.clone()); + account_infos.push(self.system_program.clone()); + remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone())); + + if signers_seeds.is_empty() { + solana_cpi::invoke(&instruction, &account_infos) + } else { + solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds) + } + } +} + +/// Instruction builder for `SetAdmin` via CPI. +/// +/// ### Accounts: +/// + /// 0. `[signer]` signer + /// 1. `[writable]` config + /// 2. `[]` system_program +#[derive(Clone, Debug)] +pub struct SetAdminCpiBuilder<'a, 'b> { + instruction: Box>, +} + +impl<'a, 'b> SetAdminCpiBuilder<'a, 'b> { + pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self { + let instruction = Box::new(SetAdminCpiBuilderInstruction { + __program: program, + signer: None, + config: None, + system_program: None, + admin: None, + __remaining_accounts: Vec::new(), + }); + Self { instruction } + } + #[inline(always)] + pub fn signer(&mut self, signer: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.signer = Some(signer); + self + } + #[inline(always)] + pub fn config(&mut self, config: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.config = Some(config); + self + } + #[inline(always)] + pub fn system_program(&mut self, system_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.system_program = Some(system_program); + self + } + #[inline(always)] + pub fn admin(&mut self, admin: Pubkey) -> &mut Self { + self.instruction.admin = Some(admin); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: &'b solana_account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self { + self.instruction.__remaining_accounts.push((account, is_writable, is_signer)); + self + } + /// Add additional accounts to the instruction. + /// + /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not, + /// and a `bool` indicating whether the account is a signer or not. + #[inline(always)] + pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self { + self.instruction.__remaining_accounts.extend_from_slice(accounts); + self + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed(&[]) + } + #[allow(clippy::clone_on_copy)] + #[allow(clippy::vec_init_then_push)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult { + let args = SetAdminInstructionArgs { + admin: self.instruction.admin.clone().expect("admin is not set"), + }; + let instruction = SetAdminCpi { + __program: self.instruction.__program, + + signer: self.instruction.signer.expect("signer is not set"), + + config: self.instruction.config.expect("config is not set"), + + system_program: self.instruction.system_program.expect("system_program is not set"), + __args: args, + }; + instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts) + } +} + +#[derive(Clone, Debug)] +struct SetAdminCpiBuilderInstruction<'a, 'b> { + __program: &'b solana_account_info::AccountInfo<'a>, + signer: Option<&'b solana_account_info::AccountInfo<'a>>, + config: Option<&'b solana_account_info::AccountInfo<'a>>, + system_program: Option<&'b solana_account_info::AccountInfo<'a>>, + admin: Option, + /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`. + __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>, +} + diff --git a/clients/rust/src/generated/instructions/withdraw.rs b/clients/rust/src/generated/instructions/withdraw.rs new file mode 100644 index 00000000..4d318a6a --- /dev/null +++ b/clients/rust/src/generated/instructions/withdraw.rs @@ -0,0 +1,589 @@ +//! 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. +//! +//! +//! + +use borsh::BorshSerialize; +use borsh::BorshDeserialize; + +pub const WITHDRAW_DISCRIMINATOR: u8 = 11; + +/// Accounts. +#[derive(Debug)] +pub struct Withdraw { + + + pub signer: solana_pubkey::Pubkey, + + + pub mint: solana_pubkey::Pubkey, + + + pub recipient: solana_pubkey::Pubkey, + + + pub stake: solana_pubkey::Pubkey, + + + pub stake_tokens: solana_pubkey::Pubkey, + + + pub treasury: solana_pubkey::Pubkey, + + + pub system_program: solana_pubkey::Pubkey, + + + pub token_program: solana_pubkey::Pubkey, + + + pub associated_token_program: solana_pubkey::Pubkey, + } + +impl Withdraw { + pub fn instruction(&self, args: WithdrawInstructionArgs) -> solana_instruction::Instruction { + self.instruction_with_remaining_accounts(args, &[]) + } + #[allow(clippy::arithmetic_side_effects)] + #[allow(clippy::vec_init_then_push)] + pub fn instruction_with_remaining_accounts(&self, args: WithdrawInstructionArgs, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction { + let mut accounts = Vec::with_capacity(9+ remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new( + self.signer, + true + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.mint, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.recipient, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.stake, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.stake_tokens, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.treasury, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.system_program, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.token_program, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.associated_token_program, + false + )); + accounts.extend_from_slice(remaining_accounts); + let mut data = WithdrawInstructionData::new().try_to_vec().unwrap(); + let mut args = args.try_to_vec().unwrap(); + data.append(&mut args); + + solana_instruction::Instruction { + program_id: crate::ORE_ID, + accounts, + data, + } + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] + pub struct WithdrawInstructionData { + discriminator: u8, + } + +impl WithdrawInstructionData { + pub fn new() -> Self { + Self { + discriminator: 11, + } + } + + pub(crate) fn try_to_vec(&self) -> Result, std::io::Error> { + borsh::to_vec(self) + } + } + +impl Default for WithdrawInstructionData { + fn default() -> Self { + Self::new() + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] + pub struct WithdrawInstructionArgs { + pub amount: u64, + } + +impl WithdrawInstructionArgs { + pub(crate) fn try_to_vec(&self) -> Result, std::io::Error> { + borsh::to_vec(self) + } +} + + +/// Instruction builder for `Withdraw`. +/// +/// ### Accounts: +/// + /// 0. `[writable, signer]` signer + /// 1. `[]` mint + /// 2. `[writable]` recipient + /// 3. `[writable]` stake + /// 4. `[writable]` stake_tokens + /// 5. `[writable]` treasury + /// 6. `[optional]` system_program (default to `11111111111111111111111111111111`) + /// 7. `[optional]` token_program (default to `TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA`) + /// 8. `[]` associated_token_program +#[derive(Clone, Debug, Default)] +pub struct WithdrawBuilder { + signer: Option, + mint: Option, + recipient: Option, + stake: Option, + stake_tokens: Option, + treasury: Option, + system_program: Option, + token_program: Option, + associated_token_program: Option, + amount: Option, + __remaining_accounts: Vec, +} + +impl WithdrawBuilder { + pub fn new() -> Self { + Self::default() + } + #[inline(always)] + pub fn signer(&mut self, signer: solana_pubkey::Pubkey) -> &mut Self { + self.signer = Some(signer); + self + } + #[inline(always)] + pub fn mint(&mut self, mint: solana_pubkey::Pubkey) -> &mut Self { + self.mint = Some(mint); + self + } + #[inline(always)] + pub fn recipient(&mut self, recipient: solana_pubkey::Pubkey) -> &mut Self { + self.recipient = Some(recipient); + self + } + #[inline(always)] + pub fn stake(&mut self, stake: solana_pubkey::Pubkey) -> &mut Self { + self.stake = Some(stake); + self + } + #[inline(always)] + pub fn stake_tokens(&mut self, stake_tokens: solana_pubkey::Pubkey) -> &mut Self { + self.stake_tokens = Some(stake_tokens); + self + } + #[inline(always)] + pub fn treasury(&mut self, treasury: solana_pubkey::Pubkey) -> &mut Self { + self.treasury = Some(treasury); + self + } + /// `[optional account, default to '11111111111111111111111111111111']` +#[inline(always)] + pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self { + self.system_program = Some(system_program); + self + } + /// `[optional account, default to 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA']` +#[inline(always)] + pub fn token_program(&mut self, token_program: solana_pubkey::Pubkey) -> &mut Self { + self.token_program = Some(token_program); + self + } + #[inline(always)] + pub fn associated_token_program(&mut self, associated_token_program: solana_pubkey::Pubkey) -> &mut Self { + self.associated_token_program = Some(associated_token_program); + self + } + #[inline(always)] + pub fn amount(&mut self, amount: u64) -> &mut Self { + self.amount = Some(amount); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self { + self.__remaining_accounts.push(account); + self + } + /// Add additional accounts to the instruction. + #[inline(always)] + pub fn add_remaining_accounts(&mut self, accounts: &[solana_instruction::AccountMeta]) -> &mut Self { + self.__remaining_accounts.extend_from_slice(accounts); + self + } + #[allow(clippy::clone_on_copy)] + pub fn instruction(&self) -> solana_instruction::Instruction { + let accounts = Withdraw { + signer: self.signer.expect("signer is not set"), + mint: self.mint.expect("mint is not set"), + recipient: self.recipient.expect("recipient is not set"), + stake: self.stake.expect("stake is not set"), + stake_tokens: self.stake_tokens.expect("stake_tokens is not set"), + treasury: self.treasury.expect("treasury is not set"), + system_program: self.system_program.unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")), + token_program: self.token_program.unwrap_or(solana_pubkey::pubkey!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA")), + associated_token_program: self.associated_token_program.expect("associated_token_program is not set"), + }; + let args = WithdrawInstructionArgs { + amount: self.amount.clone().expect("amount is not set"), + }; + + accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts) + } +} + + /// `withdraw` CPI accounts. + pub struct WithdrawCpiAccounts<'a, 'b> { + + + pub signer: &'b solana_account_info::AccountInfo<'a>, + + + pub mint: &'b solana_account_info::AccountInfo<'a>, + + + pub recipient: &'b solana_account_info::AccountInfo<'a>, + + + pub stake: &'b solana_account_info::AccountInfo<'a>, + + + pub stake_tokens: &'b solana_account_info::AccountInfo<'a>, + + + pub treasury: &'b solana_account_info::AccountInfo<'a>, + + + pub system_program: &'b solana_account_info::AccountInfo<'a>, + + + pub token_program: &'b solana_account_info::AccountInfo<'a>, + + + pub associated_token_program: &'b solana_account_info::AccountInfo<'a>, + } + +/// `withdraw` CPI instruction. +pub struct WithdrawCpi<'a, 'b> { + /// The program to invoke. + pub __program: &'b solana_account_info::AccountInfo<'a>, + + + pub signer: &'b solana_account_info::AccountInfo<'a>, + + + pub mint: &'b solana_account_info::AccountInfo<'a>, + + + pub recipient: &'b solana_account_info::AccountInfo<'a>, + + + pub stake: &'b solana_account_info::AccountInfo<'a>, + + + pub stake_tokens: &'b solana_account_info::AccountInfo<'a>, + + + pub treasury: &'b solana_account_info::AccountInfo<'a>, + + + pub system_program: &'b solana_account_info::AccountInfo<'a>, + + + pub token_program: &'b solana_account_info::AccountInfo<'a>, + + + pub associated_token_program: &'b solana_account_info::AccountInfo<'a>, + /// The arguments for the instruction. + pub __args: WithdrawInstructionArgs, + } + +impl<'a, 'b> WithdrawCpi<'a, 'b> { + pub fn new( + program: &'b solana_account_info::AccountInfo<'a>, + accounts: WithdrawCpiAccounts<'a, 'b>, + args: WithdrawInstructionArgs, + ) -> Self { + Self { + __program: program, + signer: accounts.signer, + mint: accounts.mint, + recipient: accounts.recipient, + stake: accounts.stake, + stake_tokens: accounts.stake_tokens, + treasury: accounts.treasury, + system_program: accounts.system_program, + token_program: accounts.token_program, + associated_token_program: accounts.associated_token_program, + __args: args, + } + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], &[]) + } + #[inline(always)] + pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], remaining_accounts) + } + #[inline(always)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(signers_seeds, &[]) + } + #[allow(clippy::arithmetic_side_effects)] + #[allow(clippy::clone_on_copy)] + #[allow(clippy::vec_init_then_push)] + pub fn invoke_signed_with_remaining_accounts( + &self, + signers_seeds: &[&[&[u8]]], + remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)] + ) -> solana_program_error::ProgramResult { + let mut accounts = Vec::with_capacity(9+ remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new( + *self.signer.key, + true + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.mint.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.recipient.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.stake.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.stake_tokens.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.treasury.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.system_program.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.token_program.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.associated_token_program.key, + false + )); + remaining_accounts.iter().for_each(|remaining_account| { + accounts.push(solana_instruction::AccountMeta { + pubkey: *remaining_account.0.key, + is_signer: remaining_account.1, + is_writable: remaining_account.2, + }) + }); + let mut data = WithdrawInstructionData::new().try_to_vec().unwrap(); + let mut args = self.__args.try_to_vec().unwrap(); + data.append(&mut args); + + let instruction = solana_instruction::Instruction { + program_id: crate::ORE_ID, + accounts, + data, + }; + let mut account_infos = Vec::with_capacity(10 + remaining_accounts.len()); + account_infos.push(self.__program.clone()); + account_infos.push(self.signer.clone()); + account_infos.push(self.mint.clone()); + account_infos.push(self.recipient.clone()); + account_infos.push(self.stake.clone()); + account_infos.push(self.stake_tokens.clone()); + account_infos.push(self.treasury.clone()); + account_infos.push(self.system_program.clone()); + account_infos.push(self.token_program.clone()); + account_infos.push(self.associated_token_program.clone()); + remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone())); + + if signers_seeds.is_empty() { + solana_cpi::invoke(&instruction, &account_infos) + } else { + solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds) + } + } +} + +/// Instruction builder for `Withdraw` via CPI. +/// +/// ### Accounts: +/// + /// 0. `[writable, signer]` signer + /// 1. `[]` mint + /// 2. `[writable]` recipient + /// 3. `[writable]` stake + /// 4. `[writable]` stake_tokens + /// 5. `[writable]` treasury + /// 6. `[]` system_program + /// 7. `[]` token_program + /// 8. `[]` associated_token_program +#[derive(Clone, Debug)] +pub struct WithdrawCpiBuilder<'a, 'b> { + instruction: Box>, +} + +impl<'a, 'b> WithdrawCpiBuilder<'a, 'b> { + pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self { + let instruction = Box::new(WithdrawCpiBuilderInstruction { + __program: program, + signer: None, + mint: None, + recipient: None, + stake: None, + stake_tokens: None, + treasury: None, + system_program: None, + token_program: None, + associated_token_program: None, + amount: None, + __remaining_accounts: Vec::new(), + }); + Self { instruction } + } + #[inline(always)] + pub fn signer(&mut self, signer: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.signer = Some(signer); + self + } + #[inline(always)] + pub fn mint(&mut self, mint: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.mint = Some(mint); + self + } + #[inline(always)] + pub fn recipient(&mut self, recipient: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.recipient = Some(recipient); + self + } + #[inline(always)] + pub fn stake(&mut self, stake: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.stake = Some(stake); + self + } + #[inline(always)] + pub fn stake_tokens(&mut self, stake_tokens: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.stake_tokens = Some(stake_tokens); + self + } + #[inline(always)] + pub fn treasury(&mut self, treasury: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.treasury = Some(treasury); + self + } + #[inline(always)] + pub fn system_program(&mut self, system_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.system_program = Some(system_program); + self + } + #[inline(always)] + pub fn token_program(&mut self, token_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.token_program = Some(token_program); + self + } + #[inline(always)] + pub fn associated_token_program(&mut self, associated_token_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.associated_token_program = Some(associated_token_program); + self + } + #[inline(always)] + pub fn amount(&mut self, amount: u64) -> &mut Self { + self.instruction.amount = Some(amount); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: &'b solana_account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self { + self.instruction.__remaining_accounts.push((account, is_writable, is_signer)); + self + } + /// Add additional accounts to the instruction. + /// + /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not, + /// and a `bool` indicating whether the account is a signer or not. + #[inline(always)] + pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self { + self.instruction.__remaining_accounts.extend_from_slice(accounts); + self + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed(&[]) + } + #[allow(clippy::clone_on_copy)] + #[allow(clippy::vec_init_then_push)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult { + let args = WithdrawInstructionArgs { + amount: self.instruction.amount.clone().expect("amount is not set"), + }; + let instruction = WithdrawCpi { + __program: self.instruction.__program, + + signer: self.instruction.signer.expect("signer is not set"), + + mint: self.instruction.mint.expect("mint is not set"), + + recipient: self.instruction.recipient.expect("recipient is not set"), + + stake: self.instruction.stake.expect("stake is not set"), + + stake_tokens: self.instruction.stake_tokens.expect("stake_tokens is not set"), + + treasury: self.instruction.treasury.expect("treasury is not set"), + + system_program: self.instruction.system_program.expect("system_program is not set"), + + token_program: self.instruction.token_program.expect("token_program is not set"), + + associated_token_program: self.instruction.associated_token_program.expect("associated_token_program is not set"), + __args: args, + }; + instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts) + } +} + +#[derive(Clone, Debug)] +struct WithdrawCpiBuilderInstruction<'a, 'b> { + __program: &'b solana_account_info::AccountInfo<'a>, + signer: Option<&'b solana_account_info::AccountInfo<'a>>, + mint: Option<&'b solana_account_info::AccountInfo<'a>>, + recipient: Option<&'b solana_account_info::AccountInfo<'a>>, + stake: Option<&'b solana_account_info::AccountInfo<'a>>, + stake_tokens: Option<&'b solana_account_info::AccountInfo<'a>>, + treasury: Option<&'b solana_account_info::AccountInfo<'a>>, + system_program: Option<&'b solana_account_info::AccountInfo<'a>>, + token_program: Option<&'b solana_account_info::AccountInfo<'a>>, + associated_token_program: Option<&'b solana_account_info::AccountInfo<'a>>, + amount: Option, + /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`. + __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>, +} + diff --git a/clients/rust/src/generated/instructions/wrap.rs b/clients/rust/src/generated/instructions/wrap.rs new file mode 100644 index 00000000..a69b0747 --- /dev/null +++ b/clients/rust/src/generated/instructions/wrap.rs @@ -0,0 +1,440 @@ +//! 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. +//! +//! +//! + +use borsh::BorshSerialize; +use borsh::BorshDeserialize; + +pub const WRAP_DISCRIMINATOR: u8 = 14; + +/// Accounts. +#[derive(Debug)] +pub struct Wrap { + + + pub signer: solana_pubkey::Pubkey, + + + pub config: solana_pubkey::Pubkey, + + + pub treasury: solana_pubkey::Pubkey, + + + pub treasury_sol: solana_pubkey::Pubkey, + + + pub system_program: solana_pubkey::Pubkey, + } + +impl Wrap { + pub fn instruction(&self, args: WrapInstructionArgs) -> solana_instruction::Instruction { + self.instruction_with_remaining_accounts(args, &[]) + } + #[allow(clippy::arithmetic_side_effects)] + #[allow(clippy::vec_init_then_push)] + pub fn instruction_with_remaining_accounts(&self, args: WrapInstructionArgs, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction { + let mut accounts = Vec::with_capacity(5+ remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.signer, + true + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.config, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.treasury, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.treasury_sol, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.system_program, + false + )); + accounts.extend_from_slice(remaining_accounts); + let mut data = WrapInstructionData::new().try_to_vec().unwrap(); + let mut args = args.try_to_vec().unwrap(); + data.append(&mut args); + + solana_instruction::Instruction { + program_id: crate::ORE_ID, + accounts, + data, + } + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] + pub struct WrapInstructionData { + discriminator: u8, + } + +impl WrapInstructionData { + pub fn new() -> Self { + Self { + discriminator: 14, + } + } + + pub(crate) fn try_to_vec(&self) -> Result, std::io::Error> { + borsh::to_vec(self) + } + } + +impl Default for WrapInstructionData { + fn default() -> Self { + Self::new() + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] + pub struct WrapInstructionArgs { + pub amount: u64, + } + +impl WrapInstructionArgs { + pub(crate) fn try_to_vec(&self) -> Result, std::io::Error> { + borsh::to_vec(self) + } +} + + +/// Instruction builder for `Wrap`. +/// +/// ### Accounts: +/// + /// 0. `[signer]` signer + /// 1. `[]` config + /// 2. `[writable]` treasury + /// 3. `[writable]` treasury_sol + /// 4. `[optional]` system_program (default to `11111111111111111111111111111111`) +#[derive(Clone, Debug, Default)] +pub struct WrapBuilder { + signer: Option, + config: Option, + treasury: Option, + treasury_sol: Option, + system_program: Option, + amount: Option, + __remaining_accounts: Vec, +} + +impl WrapBuilder { + pub fn new() -> Self { + Self::default() + } + #[inline(always)] + pub fn signer(&mut self, signer: solana_pubkey::Pubkey) -> &mut Self { + self.signer = Some(signer); + self + } + #[inline(always)] + pub fn config(&mut self, config: solana_pubkey::Pubkey) -> &mut Self { + self.config = Some(config); + self + } + #[inline(always)] + pub fn treasury(&mut self, treasury: solana_pubkey::Pubkey) -> &mut Self { + self.treasury = Some(treasury); + self + } + #[inline(always)] + pub fn treasury_sol(&mut self, treasury_sol: solana_pubkey::Pubkey) -> &mut Self { + self.treasury_sol = Some(treasury_sol); + self + } + /// `[optional account, default to '11111111111111111111111111111111']` +#[inline(always)] + pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self { + self.system_program = Some(system_program); + self + } + #[inline(always)] + pub fn amount(&mut self, amount: u64) -> &mut Self { + self.amount = Some(amount); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self { + self.__remaining_accounts.push(account); + self + } + /// Add additional accounts to the instruction. + #[inline(always)] + pub fn add_remaining_accounts(&mut self, accounts: &[solana_instruction::AccountMeta]) -> &mut Self { + self.__remaining_accounts.extend_from_slice(accounts); + self + } + #[allow(clippy::clone_on_copy)] + pub fn instruction(&self) -> solana_instruction::Instruction { + let accounts = Wrap { + signer: self.signer.expect("signer is not set"), + config: self.config.expect("config is not set"), + treasury: self.treasury.expect("treasury is not set"), + treasury_sol: self.treasury_sol.expect("treasury_sol is not set"), + system_program: self.system_program.unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")), + }; + let args = WrapInstructionArgs { + amount: self.amount.clone().expect("amount is not set"), + }; + + accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts) + } +} + + /// `wrap` CPI accounts. + pub struct WrapCpiAccounts<'a, 'b> { + + + pub signer: &'b solana_account_info::AccountInfo<'a>, + + + pub config: &'b solana_account_info::AccountInfo<'a>, + + + pub treasury: &'b solana_account_info::AccountInfo<'a>, + + + pub treasury_sol: &'b solana_account_info::AccountInfo<'a>, + + + pub system_program: &'b solana_account_info::AccountInfo<'a>, + } + +/// `wrap` CPI instruction. +pub struct WrapCpi<'a, 'b> { + /// The program to invoke. + pub __program: &'b solana_account_info::AccountInfo<'a>, + + + pub signer: &'b solana_account_info::AccountInfo<'a>, + + + pub config: &'b solana_account_info::AccountInfo<'a>, + + + pub treasury: &'b solana_account_info::AccountInfo<'a>, + + + pub treasury_sol: &'b solana_account_info::AccountInfo<'a>, + + + pub system_program: &'b solana_account_info::AccountInfo<'a>, + /// The arguments for the instruction. + pub __args: WrapInstructionArgs, + } + +impl<'a, 'b> WrapCpi<'a, 'b> { + pub fn new( + program: &'b solana_account_info::AccountInfo<'a>, + accounts: WrapCpiAccounts<'a, 'b>, + args: WrapInstructionArgs, + ) -> Self { + Self { + __program: program, + signer: accounts.signer, + config: accounts.config, + treasury: accounts.treasury, + treasury_sol: accounts.treasury_sol, + system_program: accounts.system_program, + __args: args, + } + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], &[]) + } + #[inline(always)] + pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], remaining_accounts) + } + #[inline(always)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(signers_seeds, &[]) + } + #[allow(clippy::arithmetic_side_effects)] + #[allow(clippy::clone_on_copy)] + #[allow(clippy::vec_init_then_push)] + pub fn invoke_signed_with_remaining_accounts( + &self, + signers_seeds: &[&[&[u8]]], + remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)] + ) -> solana_program_error::ProgramResult { + let mut accounts = Vec::with_capacity(5+ remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.signer.key, + true + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.config.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.treasury.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.treasury_sol.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.system_program.key, + false + )); + remaining_accounts.iter().for_each(|remaining_account| { + accounts.push(solana_instruction::AccountMeta { + pubkey: *remaining_account.0.key, + is_signer: remaining_account.1, + is_writable: remaining_account.2, + }) + }); + let mut data = WrapInstructionData::new().try_to_vec().unwrap(); + let mut args = self.__args.try_to_vec().unwrap(); + data.append(&mut args); + + let instruction = solana_instruction::Instruction { + program_id: crate::ORE_ID, + accounts, + data, + }; + let mut account_infos = Vec::with_capacity(6 + remaining_accounts.len()); + account_infos.push(self.__program.clone()); + account_infos.push(self.signer.clone()); + account_infos.push(self.config.clone()); + account_infos.push(self.treasury.clone()); + account_infos.push(self.treasury_sol.clone()); + account_infos.push(self.system_program.clone()); + remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone())); + + if signers_seeds.is_empty() { + solana_cpi::invoke(&instruction, &account_infos) + } else { + solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds) + } + } +} + +/// Instruction builder for `Wrap` via CPI. +/// +/// ### Accounts: +/// + /// 0. `[signer]` signer + /// 1. `[]` config + /// 2. `[writable]` treasury + /// 3. `[writable]` treasury_sol + /// 4. `[]` system_program +#[derive(Clone, Debug)] +pub struct WrapCpiBuilder<'a, 'b> { + instruction: Box>, +} + +impl<'a, 'b> WrapCpiBuilder<'a, 'b> { + pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self { + let instruction = Box::new(WrapCpiBuilderInstruction { + __program: program, + signer: None, + config: None, + treasury: None, + treasury_sol: None, + system_program: None, + amount: None, + __remaining_accounts: Vec::new(), + }); + Self { instruction } + } + #[inline(always)] + pub fn signer(&mut self, signer: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.signer = Some(signer); + self + } + #[inline(always)] + pub fn config(&mut self, config: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.config = Some(config); + self + } + #[inline(always)] + pub fn treasury(&mut self, treasury: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.treasury = Some(treasury); + self + } + #[inline(always)] + pub fn treasury_sol(&mut self, treasury_sol: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.treasury_sol = Some(treasury_sol); + self + } + #[inline(always)] + pub fn system_program(&mut self, system_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.system_program = Some(system_program); + self + } + #[inline(always)] + pub fn amount(&mut self, amount: u64) -> &mut Self { + self.instruction.amount = Some(amount); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: &'b solana_account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self { + self.instruction.__remaining_accounts.push((account, is_writable, is_signer)); + self + } + /// Add additional accounts to the instruction. + /// + /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not, + /// and a `bool` indicating whether the account is a signer or not. + #[inline(always)] + pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self { + self.instruction.__remaining_accounts.extend_from_slice(accounts); + self + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed(&[]) + } + #[allow(clippy::clone_on_copy)] + #[allow(clippy::vec_init_then_push)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult { + let args = WrapInstructionArgs { + amount: self.instruction.amount.clone().expect("amount is not set"), + }; + let instruction = WrapCpi { + __program: self.instruction.__program, + + signer: self.instruction.signer.expect("signer is not set"), + + config: self.instruction.config.expect("config is not set"), + + treasury: self.instruction.treasury.expect("treasury is not set"), + + treasury_sol: self.instruction.treasury_sol.expect("treasury_sol is not set"), + + system_program: self.instruction.system_program.expect("system_program is not set"), + __args: args, + }; + instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts) + } +} + +#[derive(Clone, Debug)] +struct WrapCpiBuilderInstruction<'a, 'b> { + __program: &'b solana_account_info::AccountInfo<'a>, + signer: Option<&'b solana_account_info::AccountInfo<'a>>, + config: Option<&'b solana_account_info::AccountInfo<'a>>, + treasury: Option<&'b solana_account_info::AccountInfo<'a>>, + treasury_sol: Option<&'b solana_account_info::AccountInfo<'a>>, + system_program: Option<&'b solana_account_info::AccountInfo<'a>>, + amount: Option, + /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`. + __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>, +} + diff --git a/clients/rust/src/generated/mod.rs b/clients/rust/src/generated/mod.rs new file mode 100644 index 00000000..fb2c5f72 --- /dev/null +++ b/clients/rust/src/generated/mod.rs @@ -0,0 +1,15 @@ +//! 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. +//! +//! +//! + + pub mod accounts; + pub mod errors; + pub mod instructions; + pub mod programs; + pub mod shared; + pub mod types; + + pub(crate) use programs::*; diff --git a/clients/rust/src/generated/programs.rs b/clients/rust/src/generated/programs.rs new file mode 100644 index 00000000..8d176e30 --- /dev/null +++ b/clients/rust/src/generated/programs.rs @@ -0,0 +1,13 @@ +//! 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. +//! +//! +//! + +use solana_pubkey::{pubkey, Pubkey}; + + + /// `ore` program ID. + pub const ORE_ID: Pubkey = pubkey!("oreV3EG1i9BEgiAJ8b177Z2S2rMarzak4NMv1kULvWv"); + diff --git a/clients/rust/src/generated/shared.rs b/clients/rust/src/generated/shared.rs new file mode 100644 index 00000000..76fa92ec --- /dev/null +++ b/clients/rust/src/generated/shared.rs @@ -0,0 +1,26 @@ +//! 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. +//! +//! +//! + + + + + #[cfg(feature = "fetch")] + #[derive(Debug, Clone)] + pub struct DecodedAccount { + pub address: solana_pubkey::Pubkey, + pub account: solana_account::Account, + pub data: T, + } + + #[cfg(feature = "fetch")] + #[derive(Debug, Clone)] + pub enum MaybeAccount { + Exists(DecodedAccount), + NotFound(solana_pubkey::Pubkey), + } + + diff --git a/clients/rust/src/generated/types/mod.rs b/clients/rust/src/generated/types/mod.rs new file mode 100644 index 00000000..c91e2fec --- /dev/null +++ b/clients/rust/src/generated/types/mod.rs @@ -0,0 +1,11 @@ +//! 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. +//! +//! +//! + + pub(crate) mod r#numeric; + + pub use self::r#numeric::*; + diff --git a/clients/rust/src/generated/types/numeric.rs b/clients/rust/src/generated/types/numeric.rs new file mode 100644 index 00000000..370dcf45 --- /dev/null +++ b/clients/rust/src/generated/types/numeric.rs @@ -0,0 +1,18 @@ +//! 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. +//! +//! +//! + +use borsh::BorshSerialize; +use borsh::BorshDeserialize; + +/// Fixed-point helper backed by I80F48 from the steel crate. +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct Numeric { +pub bits: [u8; 16], +} + + diff --git a/codama.json b/codama.json new file mode 100644 index 00000000..2dd9267a --- /dev/null +++ b/codama.json @@ -0,0 +1,22 @@ +{ + "idl": "api/idl.json", + "before": [], + "scripts": { + "js": { + "from": "@codama/renderers-js", + "args": [ + "clients/js/src/generated" + ] + }, + "rust": { + "from": "@codama/renderers-rust", + "args": [ + "clients/rust/src/generated", + { + "crateFolder": "program", + "formatCode": true + } + ] + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 00000000..8308a3b7 --- /dev/null +++ b/package.json @@ -0,0 +1,16 @@ +{ + "name": "ore", + "private": true, + "devDependencies": { + "@types/bun": "latest" + }, + "peerDependencies": { + "typescript": "^5" + }, + "dependencies": { + "@codama/nodes-from-anchor": "^1.3.8", + "@codama/renderers-js": "^1.5.5", + "@codama/renderers-rust": "^1.2.9", + "codama": "^1.5.0" + } +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000..bfa0fead --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,29 @@ +{ + "compilerOptions": { + // Environment setup & latest features + "lib": ["ESNext"], + "target": "ESNext", + "module": "Preserve", + "moduleDetection": "force", + "jsx": "react-jsx", + "allowJs": true, + + // Bundler mode + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "verbatimModuleSyntax": true, + "noEmit": true, + + // Best practices + "strict": true, + "skipLibCheck": true, + "noFallthroughCasesInSwitch": true, + "noUncheckedIndexedAccess": true, + "noImplicitOverride": true, + + // Some stricter flags (disabled by default) + "noUnusedLocals": false, + "noUnusedParameters": false, + "noPropertyAccessFromIndexSignature": false + } +}