diff --git a/.gitignore b/.gitignore index 9b6e13e..d00c5d1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ .DS_Store target test-ledger + +node_modules/ diff --git a/clients/js/src/generated/accounts/index.ts b/clients/js/src/generated/accounts/index.ts new file mode 100644 index 0000000..986a7b8 --- /dev/null +++ b/clients/js/src/generated/accounts/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 "./vault"; diff --git a/clients/js/src/generated/accounts/vault.ts b/clients/js/src/generated/accounts/vault.ts new file mode 100644 index 0000000..05f9669 --- /dev/null +++ b/clients/js/src/generated/accounts/vault.ts @@ -0,0 +1,105 @@ +/** + * 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, + type Account, + type Address, + type EncodedAccount, + type FetchAccountConfig, + type FetchAccountsConfig, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type MaybeAccount, + type MaybeEncodedAccount, +} from "@solana/kit"; + +/** stORE mint authority. */ +export type Vault = {}; + +export type VaultArgs = Vault; + +/** Gets the encoder for {@link VaultArgs} account data. */ +export function getVaultEncoder(): FixedSizeEncoder { + return getStructEncoder([]); +} + +/** Gets the decoder for {@link Vault} account data. */ +export function getVaultDecoder(): FixedSizeDecoder { + return getStructDecoder([]); +} + +/** Gets the codec for {@link Vault} account data. */ +export function getVaultCodec(): FixedSizeCodec { + return combineCodec(getVaultEncoder(), getVaultDecoder()); +} + +export function decodeVault( + encodedAccount: EncodedAccount, +): Account; +export function decodeVault( + encodedAccount: MaybeEncodedAccount, +): MaybeAccount; +export function decodeVault( + encodedAccount: EncodedAccount | MaybeEncodedAccount, +): Account | MaybeAccount { + return decodeAccount( + encodedAccount as MaybeEncodedAccount, + getVaultDecoder(), + ); +} + +export async function fetchVault( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchMaybeVault(rpc, address, config); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeVault( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchEncodedAccount(rpc, address, config); + return decodeVault(maybeAccount); +} + +export async function fetchAllVault( + rpc: Parameters[0], + addresses: Array
, + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchAllMaybeVault(rpc, addresses, config); + assertAccountsExist(maybeAccounts); + return maybeAccounts; +} + +export async function fetchAllMaybeVault( + rpc: Parameters[0], + addresses: Array
, + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); + return maybeAccounts.map((maybeAccount) => decodeVault(maybeAccount)); +} + +export function getVaultSize(): number { + return 0; +} diff --git a/clients/js/src/generated/errors/index.ts b/clients/js/src/generated/errors/index.ts new file mode 100644 index 0000000..fd9a561 --- /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 "./oreLst"; diff --git a/clients/js/src/generated/errors/oreLst.ts b/clients/js/src/generated/errors/oreLst.ts new file mode 100644 index 0000000..7490b13 --- /dev/null +++ b/clients/js/src/generated/errors/oreLst.ts @@ -0,0 +1,49 @@ +/** + * 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_LST_PROGRAM_ADDRESS } from "../programs"; + +/** Dummy: Dummy */ +export const ORE_LST_ERROR__DUMMY = 0x0; // 0 + +export type OreLstError = typeof ORE_LST_ERROR__DUMMY; + +let oreLstErrorMessages: Record | undefined; +if (process.env.NODE_ENV !== "production") { + oreLstErrorMessages = { [ORE_LST_ERROR__DUMMY]: `Dummy` }; +} + +export function getOreLstErrorMessage(code: OreLstError): string { + if (process.env.NODE_ENV !== "production") { + return (oreLstErrorMessages as Record)[code]; + } + + return "Error message not available in production bundles."; +} + +export function isOreLstError( + error: unknown, + transactionMessage: { + instructions: Record; + }, + code?: TProgramErrorCode, +): error is SolanaError & + Readonly<{ context: Readonly<{ code: TProgramErrorCode }> }> { + return isProgramError( + error, + transactionMessage, + ORE_LST_PROGRAM_ADDRESS, + code, + ); +} diff --git a/clients/js/src/generated/index.ts b/clients/js/src/generated/index.ts new file mode 100644 index 0000000..974b439 --- /dev/null +++ b/clients/js/src/generated/index.ts @@ -0,0 +1,12 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +export * from "./accounts"; +export * from "./errors"; +export * from "./instructions"; +export * from "./programs"; diff --git a/clients/js/src/generated/instructions/compound.ts b/clients/js/src/generated/instructions/compound.ts new file mode 100644 index 0000000..fcc0119 --- /dev/null +++ b/clients/js/src/generated/instructions/compound.ts @@ -0,0 +1,329 @@ +/** + * 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_LST_PROGRAM_ADDRESS } from "../programs"; +import { getAccountMetaFactory, type ResolvedAccount } from "../shared"; + +export const COMPOUND_DISCRIMINATOR = 1; + +export function getCompoundDiscriminatorBytes() { + return getU8Encoder().encode(COMPOUND_DISCRIMINATOR); +} + +export type CompoundInstruction< + TProgram extends string = typeof ORE_LST_PROGRAM_ADDRESS, + TAccountSigner extends string | AccountMeta = string, + TAccountOreMint extends string | AccountMeta = string, + TAccountStake extends string | AccountMeta = string, + TAccountStakeTokens extends string | AccountMeta = string, + TAccountTreasury extends string | AccountMeta = string, + TAccountTreasuryTokens extends string | AccountMeta = string, + TAccountVault extends string | AccountMeta = string, + TAccountVaultTokens extends string | AccountMeta = string, + TAccountSystemProgram extends string | AccountMeta = + "11111111111111111111111111111111", + TAccountTokenProgram extends string | AccountMeta = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + TAccountAssociatedTokenProgram extends string | AccountMeta = string, + TAccountOreProgram extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountSigner extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountSigner, + TAccountOreMint extends string + ? WritableAccount + : TAccountOreMint, + TAccountStake extends string + ? WritableAccount + : TAccountStake, + TAccountStakeTokens extends string + ? WritableAccount + : TAccountStakeTokens, + TAccountTreasury extends string + ? WritableAccount + : TAccountTreasury, + TAccountTreasuryTokens extends string + ? WritableAccount + : TAccountTreasuryTokens, + TAccountVault extends string + ? WritableAccount + : TAccountVault, + TAccountVaultTokens extends string + ? WritableAccount + : TAccountVaultTokens, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + TAccountAssociatedTokenProgram extends string + ? ReadonlyAccount + : TAccountAssociatedTokenProgram, + TAccountOreProgram extends string + ? ReadonlyAccount + : TAccountOreProgram, + ...TRemainingAccounts, + ] + >; + +export type CompoundInstructionData = { discriminator: number }; + +export type CompoundInstructionDataArgs = {}; + +export function getCompoundInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", getU8Encoder()]]), + (value) => ({ ...value, discriminator: COMPOUND_DISCRIMINATOR }), + ); +} + +export function getCompoundInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([["discriminator", getU8Decoder()]]); +} + +export function getCompoundInstructionDataCodec(): FixedSizeCodec< + CompoundInstructionDataArgs, + CompoundInstructionData +> { + return combineCodec( + getCompoundInstructionDataEncoder(), + getCompoundInstructionDataDecoder(), + ); +} + +export type CompoundInput< + TAccountSigner extends string = string, + TAccountOreMint extends string = string, + TAccountStake extends string = string, + TAccountStakeTokens extends string = string, + TAccountTreasury extends string = string, + TAccountTreasuryTokens extends string = string, + TAccountVault extends string = string, + TAccountVaultTokens extends string = string, + TAccountSystemProgram extends string = string, + TAccountTokenProgram extends string = string, + TAccountAssociatedTokenProgram extends string = string, + TAccountOreProgram extends string = string, +> = { + signer: TransactionSigner; + oreMint: Address; + stake: Address; + stakeTokens: Address; + treasury: Address; + treasuryTokens: Address; + vault: Address; + vaultTokens: Address; + systemProgram?: Address; + tokenProgram?: Address; + associatedTokenProgram: Address; + oreProgram: Address; +}; + +export function getCompoundInstruction< + TAccountSigner extends string, + TAccountOreMint extends string, + TAccountStake extends string, + TAccountStakeTokens extends string, + TAccountTreasury extends string, + TAccountTreasuryTokens extends string, + TAccountVault extends string, + TAccountVaultTokens extends string, + TAccountSystemProgram extends string, + TAccountTokenProgram extends string, + TAccountAssociatedTokenProgram extends string, + TAccountOreProgram extends string, + TProgramAddress extends Address = typeof ORE_LST_PROGRAM_ADDRESS, +>( + input: CompoundInput< + TAccountSigner, + TAccountOreMint, + TAccountStake, + TAccountStakeTokens, + TAccountTreasury, + TAccountTreasuryTokens, + TAccountVault, + TAccountVaultTokens, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountAssociatedTokenProgram, + TAccountOreProgram + >, + config?: { programAddress?: TProgramAddress }, +): CompoundInstruction< + TProgramAddress, + TAccountSigner, + TAccountOreMint, + TAccountStake, + TAccountStakeTokens, + TAccountTreasury, + TAccountTreasuryTokens, + TAccountVault, + TAccountVaultTokens, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountAssociatedTokenProgram, + TAccountOreProgram +> { + // Program address. + const programAddress = config?.programAddress ?? ORE_LST_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + signer: { value: input.signer ?? null, isWritable: true }, + oreMint: { value: input.oreMint ?? null, isWritable: true }, + stake: { value: input.stake ?? null, isWritable: true }, + stakeTokens: { value: input.stakeTokens ?? null, isWritable: true }, + treasury: { value: input.treasury ?? null, isWritable: true }, + treasuryTokens: { value: input.treasuryTokens ?? null, isWritable: true }, + vault: { value: input.vault ?? null, isWritable: true }, + vaultTokens: { value: input.vaultTokens ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + associatedTokenProgram: { + value: input.associatedTokenProgram ?? null, + isWritable: false, + }, + oreProgram: { value: input.oreProgram ?? 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.oreMint), + getAccountMeta(accounts.stake), + getAccountMeta(accounts.stakeTokens), + getAccountMeta(accounts.treasury), + getAccountMeta(accounts.treasuryTokens), + getAccountMeta(accounts.vault), + getAccountMeta(accounts.vaultTokens), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.associatedTokenProgram), + getAccountMeta(accounts.oreProgram), + ], + data: getCompoundInstructionDataEncoder().encode({}), + programAddress, + } as CompoundInstruction< + TProgramAddress, + TAccountSigner, + TAccountOreMint, + TAccountStake, + TAccountStakeTokens, + TAccountTreasury, + TAccountTreasuryTokens, + TAccountVault, + TAccountVaultTokens, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountAssociatedTokenProgram, + TAccountOreProgram + >); +} + +export type ParsedCompoundInstruction< + TProgram extends string = typeof ORE_LST_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + signer: TAccountMetas[0]; + oreMint: TAccountMetas[1]; + stake: TAccountMetas[2]; + stakeTokens: TAccountMetas[3]; + treasury: TAccountMetas[4]; + treasuryTokens: TAccountMetas[5]; + vault: TAccountMetas[6]; + vaultTokens: TAccountMetas[7]; + systemProgram: TAccountMetas[8]; + tokenProgram: TAccountMetas[9]; + associatedTokenProgram: TAccountMetas[10]; + oreProgram: TAccountMetas[11]; + }; + data: CompoundInstructionData; +}; + +export function parseCompoundInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedCompoundInstruction { + if (instruction.accounts.length < 12) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + signer: getNextAccount(), + oreMint: getNextAccount(), + stake: getNextAccount(), + stakeTokens: getNextAccount(), + treasury: getNextAccount(), + treasuryTokens: getNextAccount(), + vault: getNextAccount(), + vaultTokens: getNextAccount(), + systemProgram: getNextAccount(), + tokenProgram: getNextAccount(), + associatedTokenProgram: getNextAccount(), + oreProgram: getNextAccount(), + }, + data: getCompoundInstructionDataDecoder().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 0000000..10eff20 --- /dev/null +++ b/clients/js/src/generated/instructions/index.ts @@ -0,0 +1,12 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +export * from "./compound"; +export * from "./initialize"; +export * from "./unwrap"; +export * from "./wrap"; diff --git a/clients/js/src/generated/instructions/initialize.ts b/clients/js/src/generated/instructions/initialize.ts new file mode 100644 index 0000000..eb7ac4f --- /dev/null +++ b/clients/js/src/generated/instructions/initialize.ts @@ -0,0 +1,379 @@ +/** + * 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_LST_PROGRAM_ADDRESS } from "../programs"; +import { getAccountMetaFactory, type ResolvedAccount } from "../shared"; + +export const INITIALIZE_DISCRIMINATOR = 100; + +export function getInitializeDiscriminatorBytes() { + return getU8Encoder().encode(INITIALIZE_DISCRIMINATOR); +} + +export type InitializeInstruction< + TProgram extends string = typeof ORE_LST_PROGRAM_ADDRESS, + TAccountSigner extends string | AccountMeta = string, + TAccountOreMint extends string | AccountMeta = string, + TAccountStoreMint extends string | AccountMeta = string, + TAccountMetadata extends string | AccountMeta = string, + TAccountStake extends string | AccountMeta = string, + TAccountStakeTokens extends string | AccountMeta = string, + TAccountTreasury extends string | AccountMeta = string, + TAccountVault extends string | AccountMeta = string, + TAccountVaultTokens extends string | AccountMeta = string, + TAccountSystemProgram extends string | AccountMeta = + "11111111111111111111111111111111", + TAccountTokenProgram extends string | AccountMeta = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + TAccountAssociatedTokenProgram extends string | AccountMeta = string, + TAccountMetadataProgram extends string | AccountMeta = string, + TAccountOreProgram extends string | AccountMeta = string, + TAccountRentSysvar extends string | AccountMeta = + "SysvarRent111111111111111111111111111111111", + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountSigner extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountSigner, + TAccountOreMint extends string + ? WritableAccount + : TAccountOreMint, + TAccountStoreMint extends string + ? WritableAccount + : TAccountStoreMint, + TAccountMetadata extends string + ? WritableAccount + : TAccountMetadata, + TAccountStake extends string + ? WritableAccount + : TAccountStake, + TAccountStakeTokens extends string + ? WritableAccount + : TAccountStakeTokens, + TAccountTreasury extends string + ? WritableAccount + : TAccountTreasury, + TAccountVault extends string + ? WritableAccount + : TAccountVault, + TAccountVaultTokens extends string + ? WritableAccount + : TAccountVaultTokens, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + TAccountAssociatedTokenProgram extends string + ? ReadonlyAccount + : TAccountAssociatedTokenProgram, + TAccountMetadataProgram extends string + ? ReadonlyAccount + : TAccountMetadataProgram, + TAccountOreProgram extends string + ? ReadonlyAccount + : TAccountOreProgram, + TAccountRentSysvar extends string + ? ReadonlyAccount + : TAccountRentSysvar, + ...TRemainingAccounts, + ] + >; + +export type InitializeInstructionData = { discriminator: number }; + +export type InitializeInstructionDataArgs = {}; + +export function getInitializeInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", getU8Encoder()]]), + (value) => ({ ...value, discriminator: INITIALIZE_DISCRIMINATOR }), + ); +} + +export function getInitializeInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([["discriminator", getU8Decoder()]]); +} + +export function getInitializeInstructionDataCodec(): FixedSizeCodec< + InitializeInstructionDataArgs, + InitializeInstructionData +> { + return combineCodec( + getInitializeInstructionDataEncoder(), + getInitializeInstructionDataDecoder(), + ); +} + +export type InitializeInput< + TAccountSigner extends string = string, + TAccountOreMint extends string = string, + TAccountStoreMint extends string = string, + TAccountMetadata extends string = string, + TAccountStake extends string = string, + TAccountStakeTokens extends string = string, + TAccountTreasury extends string = string, + TAccountVault extends string = string, + TAccountVaultTokens extends string = string, + TAccountSystemProgram extends string = string, + TAccountTokenProgram extends string = string, + TAccountAssociatedTokenProgram extends string = string, + TAccountMetadataProgram extends string = string, + TAccountOreProgram extends string = string, + TAccountRentSysvar extends string = string, +> = { + signer: TransactionSigner; + oreMint: Address; + storeMint: Address; + metadata: Address; + stake: Address; + stakeTokens: Address; + treasury: Address; + vault: Address; + vaultTokens: Address; + systemProgram?: Address; + tokenProgram?: Address; + associatedTokenProgram: Address; + metadataProgram: Address; + oreProgram: Address; + rentSysvar?: Address; +}; + +export function getInitializeInstruction< + TAccountSigner extends string, + TAccountOreMint extends string, + TAccountStoreMint extends string, + TAccountMetadata extends string, + TAccountStake extends string, + TAccountStakeTokens extends string, + TAccountTreasury extends string, + TAccountVault extends string, + TAccountVaultTokens extends string, + TAccountSystemProgram extends string, + TAccountTokenProgram extends string, + TAccountAssociatedTokenProgram extends string, + TAccountMetadataProgram extends string, + TAccountOreProgram extends string, + TAccountRentSysvar extends string, + TProgramAddress extends Address = typeof ORE_LST_PROGRAM_ADDRESS, +>( + input: InitializeInput< + TAccountSigner, + TAccountOreMint, + TAccountStoreMint, + TAccountMetadata, + TAccountStake, + TAccountStakeTokens, + TAccountTreasury, + TAccountVault, + TAccountVaultTokens, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountAssociatedTokenProgram, + TAccountMetadataProgram, + TAccountOreProgram, + TAccountRentSysvar + >, + config?: { programAddress?: TProgramAddress }, +): InitializeInstruction< + TProgramAddress, + TAccountSigner, + TAccountOreMint, + TAccountStoreMint, + TAccountMetadata, + TAccountStake, + TAccountStakeTokens, + TAccountTreasury, + TAccountVault, + TAccountVaultTokens, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountAssociatedTokenProgram, + TAccountMetadataProgram, + TAccountOreProgram, + TAccountRentSysvar +> { + // Program address. + const programAddress = config?.programAddress ?? ORE_LST_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + signer: { value: input.signer ?? null, isWritable: true }, + oreMint: { value: input.oreMint ?? null, isWritable: true }, + storeMint: { value: input.storeMint ?? null, isWritable: true }, + metadata: { value: input.metadata ?? null, isWritable: true }, + stake: { value: input.stake ?? null, isWritable: true }, + stakeTokens: { value: input.stakeTokens ?? null, isWritable: true }, + treasury: { value: input.treasury ?? null, isWritable: true }, + vault: { value: input.vault ?? null, isWritable: true }, + vaultTokens: { value: input.vaultTokens ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + associatedTokenProgram: { + value: input.associatedTokenProgram ?? null, + isWritable: false, + }, + metadataProgram: { + value: input.metadataProgram ?? null, + isWritable: false, + }, + oreProgram: { value: input.oreProgram ?? null, isWritable: false }, + rentSysvar: { value: input.rentSysvar ?? 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.rentSysvar.value) { + accounts.rentSysvar.value = + "SysvarRent111111111111111111111111111111111" as Address<"SysvarRent111111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.signer), + getAccountMeta(accounts.oreMint), + getAccountMeta(accounts.storeMint), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.stake), + getAccountMeta(accounts.stakeTokens), + getAccountMeta(accounts.treasury), + getAccountMeta(accounts.vault), + getAccountMeta(accounts.vaultTokens), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.associatedTokenProgram), + getAccountMeta(accounts.metadataProgram), + getAccountMeta(accounts.oreProgram), + getAccountMeta(accounts.rentSysvar), + ], + data: getInitializeInstructionDataEncoder().encode({}), + programAddress, + } as InitializeInstruction< + TProgramAddress, + TAccountSigner, + TAccountOreMint, + TAccountStoreMint, + TAccountMetadata, + TAccountStake, + TAccountStakeTokens, + TAccountTreasury, + TAccountVault, + TAccountVaultTokens, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountAssociatedTokenProgram, + TAccountMetadataProgram, + TAccountOreProgram, + TAccountRentSysvar + >); +} + +export type ParsedInitializeInstruction< + TProgram extends string = typeof ORE_LST_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + signer: TAccountMetas[0]; + oreMint: TAccountMetas[1]; + storeMint: TAccountMetas[2]; + metadata: TAccountMetas[3]; + stake: TAccountMetas[4]; + stakeTokens: TAccountMetas[5]; + treasury: TAccountMetas[6]; + vault: TAccountMetas[7]; + vaultTokens: TAccountMetas[8]; + systemProgram: TAccountMetas[9]; + tokenProgram: TAccountMetas[10]; + associatedTokenProgram: TAccountMetas[11]; + metadataProgram: TAccountMetas[12]; + oreProgram: TAccountMetas[13]; + rentSysvar: TAccountMetas[14]; + }; + data: InitializeInstructionData; +}; + +export function parseInitializeInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedInitializeInstruction { + if (instruction.accounts.length < 15) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + signer: getNextAccount(), + oreMint: getNextAccount(), + storeMint: getNextAccount(), + metadata: getNextAccount(), + stake: getNextAccount(), + stakeTokens: getNextAccount(), + treasury: getNextAccount(), + vault: getNextAccount(), + vaultTokens: getNextAccount(), + systemProgram: getNextAccount(), + tokenProgram: getNextAccount(), + associatedTokenProgram: getNextAccount(), + metadataProgram: getNextAccount(), + oreProgram: getNextAccount(), + rentSysvar: getNextAccount(), + }, + data: getInitializeInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/js/src/generated/instructions/unwrap.ts b/clients/js/src/generated/instructions/unwrap.ts new file mode 100644 index 0000000..3d91ead --- /dev/null +++ b/clients/js/src/generated/instructions/unwrap.ts @@ -0,0 +1,400 @@ +/** + * 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_LST_PROGRAM_ADDRESS } from "../programs"; +import { getAccountMetaFactory, type ResolvedAccount } from "../shared"; + +export const UNWRAP_DISCRIMINATOR = 2; + +export function getUnwrapDiscriminatorBytes() { + return getU8Encoder().encode(UNWRAP_DISCRIMINATOR); +} + +export type UnwrapInstruction< + TProgram extends string = typeof ORE_LST_PROGRAM_ADDRESS, + TAccountSigner extends string | AccountMeta = string, + TAccountPayer extends string | AccountMeta = string, + TAccountSenderOre extends string | AccountMeta = string, + TAccountSenderStore extends string | AccountMeta = string, + TAccountOreMint extends string | AccountMeta = string, + TAccountStoreMint extends string | AccountMeta = string, + TAccountStake extends string | AccountMeta = string, + TAccountStakeTokens extends string | AccountMeta = string, + TAccountTreasury extends string | AccountMeta = string, + TAccountTreasuryTokens extends string | AccountMeta = string, + TAccountVault extends string | AccountMeta = string, + TAccountVaultTokens extends string | AccountMeta = string, + TAccountSystemProgram extends string | AccountMeta = + "11111111111111111111111111111111", + TAccountTokenProgram extends string | AccountMeta = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + TAccountAssociatedTokenProgram extends string | AccountMeta = string, + TAccountOreProgram extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountSigner extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountSigner, + TAccountPayer extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountPayer, + TAccountSenderOre extends string + ? WritableAccount + : TAccountSenderOre, + TAccountSenderStore extends string + ? WritableAccount + : TAccountSenderStore, + TAccountOreMint extends string + ? WritableAccount + : TAccountOreMint, + TAccountStoreMint extends string + ? WritableAccount + : TAccountStoreMint, + TAccountStake extends string + ? WritableAccount + : TAccountStake, + TAccountStakeTokens extends string + ? WritableAccount + : TAccountStakeTokens, + TAccountTreasury extends string + ? WritableAccount + : TAccountTreasury, + TAccountTreasuryTokens extends string + ? WritableAccount + : TAccountTreasuryTokens, + TAccountVault extends string + ? WritableAccount + : TAccountVault, + TAccountVaultTokens extends string + ? WritableAccount + : TAccountVaultTokens, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + TAccountAssociatedTokenProgram extends string + ? ReadonlyAccount + : TAccountAssociatedTokenProgram, + TAccountOreProgram extends string + ? ReadonlyAccount + : TAccountOreProgram, + ...TRemainingAccounts, + ] + >; + +export type UnwrapInstructionData = { discriminator: number; amount: bigint }; + +export type UnwrapInstructionDataArgs = { amount: number | bigint }; + +export function getUnwrapInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", getU8Encoder()], + ["amount", getU64Encoder()], + ]), + (value) => ({ ...value, discriminator: UNWRAP_DISCRIMINATOR }), + ); +} + +export function getUnwrapInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", getU8Decoder()], + ["amount", getU64Decoder()], + ]); +} + +export function getUnwrapInstructionDataCodec(): FixedSizeCodec< + UnwrapInstructionDataArgs, + UnwrapInstructionData +> { + return combineCodec( + getUnwrapInstructionDataEncoder(), + getUnwrapInstructionDataDecoder(), + ); +} + +export type UnwrapInput< + TAccountSigner extends string = string, + TAccountPayer extends string = string, + TAccountSenderOre extends string = string, + TAccountSenderStore extends string = string, + TAccountOreMint extends string = string, + TAccountStoreMint extends string = string, + TAccountStake extends string = string, + TAccountStakeTokens extends string = string, + TAccountTreasury extends string = string, + TAccountTreasuryTokens extends string = string, + TAccountVault extends string = string, + TAccountVaultTokens extends string = string, + TAccountSystemProgram extends string = string, + TAccountTokenProgram extends string = string, + TAccountAssociatedTokenProgram extends string = string, + TAccountOreProgram extends string = string, +> = { + signer: TransactionSigner; + payer: TransactionSigner; + senderOre: Address; + senderStore: Address; + oreMint: Address; + storeMint: Address; + stake: Address; + stakeTokens: Address; + treasury: Address; + treasuryTokens: Address; + vault: Address; + vaultTokens: Address; + systemProgram?: Address; + tokenProgram?: Address; + associatedTokenProgram: Address; + oreProgram: Address; + amount: UnwrapInstructionDataArgs["amount"]; +}; + +export function getUnwrapInstruction< + TAccountSigner extends string, + TAccountPayer extends string, + TAccountSenderOre extends string, + TAccountSenderStore extends string, + TAccountOreMint extends string, + TAccountStoreMint extends string, + TAccountStake extends string, + TAccountStakeTokens extends string, + TAccountTreasury extends string, + TAccountTreasuryTokens extends string, + TAccountVault extends string, + TAccountVaultTokens extends string, + TAccountSystemProgram extends string, + TAccountTokenProgram extends string, + TAccountAssociatedTokenProgram extends string, + TAccountOreProgram extends string, + TProgramAddress extends Address = typeof ORE_LST_PROGRAM_ADDRESS, +>( + input: UnwrapInput< + TAccountSigner, + TAccountPayer, + TAccountSenderOre, + TAccountSenderStore, + TAccountOreMint, + TAccountStoreMint, + TAccountStake, + TAccountStakeTokens, + TAccountTreasury, + TAccountTreasuryTokens, + TAccountVault, + TAccountVaultTokens, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountAssociatedTokenProgram, + TAccountOreProgram + >, + config?: { programAddress?: TProgramAddress }, +): UnwrapInstruction< + TProgramAddress, + TAccountSigner, + TAccountPayer, + TAccountSenderOre, + TAccountSenderStore, + TAccountOreMint, + TAccountStoreMint, + TAccountStake, + TAccountStakeTokens, + TAccountTreasury, + TAccountTreasuryTokens, + TAccountVault, + TAccountVaultTokens, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountAssociatedTokenProgram, + TAccountOreProgram +> { + // Program address. + const programAddress = config?.programAddress ?? ORE_LST_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + signer: { value: input.signer ?? null, isWritable: true }, + payer: { value: input.payer ?? null, isWritable: true }, + senderOre: { value: input.senderOre ?? null, isWritable: true }, + senderStore: { value: input.senderStore ?? null, isWritable: true }, + oreMint: { value: input.oreMint ?? null, isWritable: true }, + storeMint: { value: input.storeMint ?? null, isWritable: true }, + stake: { value: input.stake ?? null, isWritable: true }, + stakeTokens: { value: input.stakeTokens ?? null, isWritable: true }, + treasury: { value: input.treasury ?? null, isWritable: true }, + treasuryTokens: { value: input.treasuryTokens ?? null, isWritable: true }, + vault: { value: input.vault ?? null, isWritable: true }, + vaultTokens: { value: input.vaultTokens ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + associatedTokenProgram: { + value: input.associatedTokenProgram ?? null, + isWritable: false, + }, + oreProgram: { value: input.oreProgram ?? 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.payer), + getAccountMeta(accounts.senderOre), + getAccountMeta(accounts.senderStore), + getAccountMeta(accounts.oreMint), + getAccountMeta(accounts.storeMint), + getAccountMeta(accounts.stake), + getAccountMeta(accounts.stakeTokens), + getAccountMeta(accounts.treasury), + getAccountMeta(accounts.treasuryTokens), + getAccountMeta(accounts.vault), + getAccountMeta(accounts.vaultTokens), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.associatedTokenProgram), + getAccountMeta(accounts.oreProgram), + ], + data: getUnwrapInstructionDataEncoder().encode( + args as UnwrapInstructionDataArgs, + ), + programAddress, + } as UnwrapInstruction< + TProgramAddress, + TAccountSigner, + TAccountPayer, + TAccountSenderOre, + TAccountSenderStore, + TAccountOreMint, + TAccountStoreMint, + TAccountStake, + TAccountStakeTokens, + TAccountTreasury, + TAccountTreasuryTokens, + TAccountVault, + TAccountVaultTokens, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountAssociatedTokenProgram, + TAccountOreProgram + >); +} + +export type ParsedUnwrapInstruction< + TProgram extends string = typeof ORE_LST_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + signer: TAccountMetas[0]; + payer: TAccountMetas[1]; + senderOre: TAccountMetas[2]; + senderStore: TAccountMetas[3]; + oreMint: TAccountMetas[4]; + storeMint: TAccountMetas[5]; + stake: TAccountMetas[6]; + stakeTokens: TAccountMetas[7]; + treasury: TAccountMetas[8]; + treasuryTokens: TAccountMetas[9]; + vault: TAccountMetas[10]; + vaultTokens: TAccountMetas[11]; + systemProgram: TAccountMetas[12]; + tokenProgram: TAccountMetas[13]; + associatedTokenProgram: TAccountMetas[14]; + oreProgram: TAccountMetas[15]; + }; + data: UnwrapInstructionData; +}; + +export function parseUnwrapInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedUnwrapInstruction { + 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(), + payer: getNextAccount(), + senderOre: getNextAccount(), + senderStore: getNextAccount(), + oreMint: getNextAccount(), + storeMint: getNextAccount(), + stake: getNextAccount(), + stakeTokens: getNextAccount(), + treasury: getNextAccount(), + treasuryTokens: getNextAccount(), + vault: getNextAccount(), + vaultTokens: getNextAccount(), + systemProgram: getNextAccount(), + tokenProgram: getNextAccount(), + associatedTokenProgram: getNextAccount(), + oreProgram: getNextAccount(), + }, + data: getUnwrapInstructionDataDecoder().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 0000000..c99ea38 --- /dev/null +++ b/clients/js/src/generated/instructions/wrap.ts @@ -0,0 +1,400 @@ +/** + * 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_LST_PROGRAM_ADDRESS } from "../programs"; +import { getAccountMetaFactory, type ResolvedAccount } from "../shared"; + +export const WRAP_DISCRIMINATOR = 3; + +export function getWrapDiscriminatorBytes() { + return getU8Encoder().encode(WRAP_DISCRIMINATOR); +} + +export type WrapInstruction< + TProgram extends string = typeof ORE_LST_PROGRAM_ADDRESS, + TAccountSigner extends string | AccountMeta = string, + TAccountPayer extends string | AccountMeta = string, + TAccountSenderOre extends string | AccountMeta = string, + TAccountSenderStore extends string | AccountMeta = string, + TAccountOreMint extends string | AccountMeta = string, + TAccountStoreMint extends string | AccountMeta = string, + TAccountStake extends string | AccountMeta = string, + TAccountStakeTokens extends string | AccountMeta = string, + TAccountTreasury extends string | AccountMeta = string, + TAccountTreasuryTokens extends string | AccountMeta = string, + TAccountVault extends string | AccountMeta = string, + TAccountVaultTokens extends string | AccountMeta = string, + TAccountSystemProgram extends string | AccountMeta = + "11111111111111111111111111111111", + TAccountTokenProgram extends string | AccountMeta = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + TAccountAssociatedTokenProgram extends string | AccountMeta = string, + TAccountOreProgram extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountSigner extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountSigner, + TAccountPayer extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountPayer, + TAccountSenderOre extends string + ? WritableAccount + : TAccountSenderOre, + TAccountSenderStore extends string + ? WritableAccount + : TAccountSenderStore, + TAccountOreMint extends string + ? WritableAccount + : TAccountOreMint, + TAccountStoreMint extends string + ? WritableAccount + : TAccountStoreMint, + TAccountStake extends string + ? WritableAccount + : TAccountStake, + TAccountStakeTokens extends string + ? WritableAccount + : TAccountStakeTokens, + TAccountTreasury extends string + ? WritableAccount + : TAccountTreasury, + TAccountTreasuryTokens extends string + ? WritableAccount + : TAccountTreasuryTokens, + TAccountVault extends string + ? WritableAccount + : TAccountVault, + TAccountVaultTokens extends string + ? WritableAccount + : TAccountVaultTokens, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + TAccountAssociatedTokenProgram extends string + ? ReadonlyAccount + : TAccountAssociatedTokenProgram, + TAccountOreProgram extends string + ? ReadonlyAccount + : TAccountOreProgram, + ...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, + TAccountPayer extends string = string, + TAccountSenderOre extends string = string, + TAccountSenderStore extends string = string, + TAccountOreMint extends string = string, + TAccountStoreMint extends string = string, + TAccountStake extends string = string, + TAccountStakeTokens extends string = string, + TAccountTreasury extends string = string, + TAccountTreasuryTokens extends string = string, + TAccountVault extends string = string, + TAccountVaultTokens extends string = string, + TAccountSystemProgram extends string = string, + TAccountTokenProgram extends string = string, + TAccountAssociatedTokenProgram extends string = string, + TAccountOreProgram extends string = string, +> = { + signer: TransactionSigner; + payer: TransactionSigner; + senderOre: Address; + senderStore: Address; + oreMint: Address; + storeMint: Address; + stake: Address; + stakeTokens: Address; + treasury: Address; + treasuryTokens: Address; + vault: Address; + vaultTokens: Address; + systemProgram?: Address; + tokenProgram?: Address; + associatedTokenProgram: Address; + oreProgram: Address; + amount: WrapInstructionDataArgs["amount"]; +}; + +export function getWrapInstruction< + TAccountSigner extends string, + TAccountPayer extends string, + TAccountSenderOre extends string, + TAccountSenderStore extends string, + TAccountOreMint extends string, + TAccountStoreMint extends string, + TAccountStake extends string, + TAccountStakeTokens extends string, + TAccountTreasury extends string, + TAccountTreasuryTokens extends string, + TAccountVault extends string, + TAccountVaultTokens extends string, + TAccountSystemProgram extends string, + TAccountTokenProgram extends string, + TAccountAssociatedTokenProgram extends string, + TAccountOreProgram extends string, + TProgramAddress extends Address = typeof ORE_LST_PROGRAM_ADDRESS, +>( + input: WrapInput< + TAccountSigner, + TAccountPayer, + TAccountSenderOre, + TAccountSenderStore, + TAccountOreMint, + TAccountStoreMint, + TAccountStake, + TAccountStakeTokens, + TAccountTreasury, + TAccountTreasuryTokens, + TAccountVault, + TAccountVaultTokens, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountAssociatedTokenProgram, + TAccountOreProgram + >, + config?: { programAddress?: TProgramAddress }, +): WrapInstruction< + TProgramAddress, + TAccountSigner, + TAccountPayer, + TAccountSenderOre, + TAccountSenderStore, + TAccountOreMint, + TAccountStoreMint, + TAccountStake, + TAccountStakeTokens, + TAccountTreasury, + TAccountTreasuryTokens, + TAccountVault, + TAccountVaultTokens, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountAssociatedTokenProgram, + TAccountOreProgram +> { + // Program address. + const programAddress = config?.programAddress ?? ORE_LST_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + signer: { value: input.signer ?? null, isWritable: true }, + payer: { value: input.payer ?? null, isWritable: true }, + senderOre: { value: input.senderOre ?? null, isWritable: true }, + senderStore: { value: input.senderStore ?? null, isWritable: true }, + oreMint: { value: input.oreMint ?? null, isWritable: true }, + storeMint: { value: input.storeMint ?? null, isWritable: true }, + stake: { value: input.stake ?? null, isWritable: true }, + stakeTokens: { value: input.stakeTokens ?? null, isWritable: true }, + treasury: { value: input.treasury ?? null, isWritable: true }, + treasuryTokens: { value: input.treasuryTokens ?? null, isWritable: true }, + vault: { value: input.vault ?? null, isWritable: true }, + vaultTokens: { value: input.vaultTokens ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + associatedTokenProgram: { + value: input.associatedTokenProgram ?? null, + isWritable: false, + }, + oreProgram: { value: input.oreProgram ?? 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.payer), + getAccountMeta(accounts.senderOre), + getAccountMeta(accounts.senderStore), + getAccountMeta(accounts.oreMint), + getAccountMeta(accounts.storeMint), + getAccountMeta(accounts.stake), + getAccountMeta(accounts.stakeTokens), + getAccountMeta(accounts.treasury), + getAccountMeta(accounts.treasuryTokens), + getAccountMeta(accounts.vault), + getAccountMeta(accounts.vaultTokens), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.associatedTokenProgram), + getAccountMeta(accounts.oreProgram), + ], + data: getWrapInstructionDataEncoder().encode( + args as WrapInstructionDataArgs, + ), + programAddress, + } as WrapInstruction< + TProgramAddress, + TAccountSigner, + TAccountPayer, + TAccountSenderOre, + TAccountSenderStore, + TAccountOreMint, + TAccountStoreMint, + TAccountStake, + TAccountStakeTokens, + TAccountTreasury, + TAccountTreasuryTokens, + TAccountVault, + TAccountVaultTokens, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountAssociatedTokenProgram, + TAccountOreProgram + >); +} + +export type ParsedWrapInstruction< + TProgram extends string = typeof ORE_LST_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + signer: TAccountMetas[0]; + payer: TAccountMetas[1]; + senderOre: TAccountMetas[2]; + senderStore: TAccountMetas[3]; + oreMint: TAccountMetas[4]; + storeMint: TAccountMetas[5]; + stake: TAccountMetas[6]; + stakeTokens: TAccountMetas[7]; + treasury: TAccountMetas[8]; + treasuryTokens: TAccountMetas[9]; + vault: TAccountMetas[10]; + vaultTokens: TAccountMetas[11]; + systemProgram: TAccountMetas[12]; + tokenProgram: TAccountMetas[13]; + associatedTokenProgram: TAccountMetas[14]; + oreProgram: TAccountMetas[15]; + }; + data: WrapInstructionData; +}; + +export function parseWrapInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedWrapInstruction { + 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(), + payer: getNextAccount(), + senderOre: getNextAccount(), + senderStore: getNextAccount(), + oreMint: getNextAccount(), + storeMint: getNextAccount(), + stake: getNextAccount(), + stakeTokens: getNextAccount(), + treasury: getNextAccount(), + treasuryTokens: getNextAccount(), + vault: getNextAccount(), + vaultTokens: getNextAccount(), + systemProgram: getNextAccount(), + tokenProgram: getNextAccount(), + associatedTokenProgram: getNextAccount(), + oreProgram: 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 0000000..fd9a561 --- /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 "./oreLst"; diff --git a/clients/js/src/generated/programs/oreLst.ts b/clients/js/src/generated/programs/oreLst.ts new file mode 100644 index 0000000..6656f4a --- /dev/null +++ b/clients/js/src/generated/programs/oreLst.ts @@ -0,0 +1,71 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import { + containsBytes, + getU8Encoder, + type Address, + type ReadonlyUint8Array, +} from "@solana/kit"; +import { + type ParsedCompoundInstruction, + type ParsedInitializeInstruction, + type ParsedUnwrapInstruction, + type ParsedWrapInstruction, +} from "../instructions"; + +export const ORE_LST_PROGRAM_ADDRESS = + "LStwN2E5Uw6MCtuxHRLhy8RY9hxqW2XRpLzettb696y" as Address<"LStwN2E5Uw6MCtuxHRLhy8RY9hxqW2XRpLzettb696y">; + +export enum OreLstAccount { + Vault, +} + +export enum OreLstInstruction { + Compound, + Unwrap, + Wrap, + Initialize, +} + +export function identifyOreLstInstruction( + instruction: { data: ReadonlyUint8Array } | ReadonlyUint8Array, +): OreLstInstruction { + const data = "data" in instruction ? instruction.data : instruction; + if (containsBytes(data, getU8Encoder().encode(1), 0)) { + return OreLstInstruction.Compound; + } + if (containsBytes(data, getU8Encoder().encode(2), 0)) { + return OreLstInstruction.Unwrap; + } + if (containsBytes(data, getU8Encoder().encode(3), 0)) { + return OreLstInstruction.Wrap; + } + if (containsBytes(data, getU8Encoder().encode(100), 0)) { + return OreLstInstruction.Initialize; + } + throw new Error( + "The provided instruction could not be identified as a oreLst instruction.", + ); +} + +export type ParsedOreLstInstruction< + TProgram extends string = "LStwN2E5Uw6MCtuxHRLhy8RY9hxqW2XRpLzettb696y", +> = + | ({ + instructionType: OreLstInstruction.Compound; + } & ParsedCompoundInstruction) + | ({ + instructionType: OreLstInstruction.Unwrap; + } & ParsedUnwrapInstruction) + | ({ + instructionType: OreLstInstruction.Wrap; + } & ParsedWrapInstruction) + | ({ + instructionType: OreLstInstruction.Initialize; + } & ParsedInitializeInstruction); diff --git a/clients/js/src/generated/shared/index.ts b/clients/js/src/generated/shared/index.ts new file mode 100644 index 0000000..634232f --- /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/rust/src/generated/accounts/mod.rs b/clients/rust/src/generated/accounts/mod.rs new file mode 100644 index 0000000..9260cb2 --- /dev/null +++ b/clients/rust/src/generated/accounts/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#vault; + + pub use self::r#vault::*; + diff --git a/clients/rust/src/generated/accounts/vault.rs b/clients/rust/src/generated/accounts/vault.rs new file mode 100644 index 0000000..b030fd2 --- /dev/null +++ b/clients/rust/src/generated/accounts/vault.rs @@ -0,0 +1,124 @@ +//! 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; + +/// stORE mint authority. + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct Vault { + +} + + + + +impl Vault { + pub const LEN: usize = 0; + + + + #[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 Vault { + 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_vault( + rpc: &solana_client::rpc_client::RpcClient, + address: &solana_pubkey::Pubkey, +) -> Result, std::io::Error> { + let accounts = fetch_all_vault(rpc, &[*address])?; + Ok(accounts[0].clone()) +} + +#[cfg(feature = "fetch")] +pub fn fetch_all_vault( + 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 = Vault::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_vault( + rpc: &solana_client::rpc_client::RpcClient, + address: &solana_pubkey::Pubkey, +) -> Result, std::io::Error> { + let accounts = fetch_all_maybe_vault(rpc, &[*address])?; + Ok(accounts[0].clone()) +} + +#[cfg(feature = "fetch")] +pub fn fetch_all_maybe_vault( + 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 = Vault::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 Vault { + fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result { + Ok(Self::deserialize(buf)?) + } + } + + #[cfg(feature = "anchor")] + impl anchor_lang::AccountSerialize for Vault {} + + #[cfg(feature = "anchor")] + impl anchor_lang::Owner for Vault { + fn owner() -> Pubkey { + crate::ORE_LST_ID + } + } + + #[cfg(feature = "anchor-idl-build")] + impl anchor_lang::IdlBuild for Vault {} + + + #[cfg(feature = "anchor-idl-build")] + impl anchor_lang::Discriminator for Vault { + 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 0000000..e42a00d --- /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_lst; + + pub use self::ore_lst::OreLstError; + diff --git a/clients/rust/src/generated/errors/ore_lst.rs b/clients/rust/src/generated/errors/ore_lst.rs new file mode 100644 index 0000000..c5e6860 --- /dev/null +++ b/clients/rust/src/generated/errors/ore_lst.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. +//! +//! +//! + +use num_derive::FromPrimitive; +use thiserror::Error; + +#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)] +pub enum OreLstError { + /// 0 - Dummy + #[error("Dummy")] + Dummy = 0x0, +} + +impl From for solana_program_error::ProgramError { + fn from(e: OreLstError) -> Self { + solana_program_error::ProgramError::Custom(e as u32) + } +} + diff --git a/clients/rust/src/generated/instructions/compound.rs b/clients/rust/src/generated/instructions/compound.rs new file mode 100644 index 0000000..b8aaf36 --- /dev/null +++ b/clients/rust/src/generated/instructions/compound.rs @@ -0,0 +1,661 @@ +//! 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 COMPOUND_DISCRIMINATOR: u8 = 1; + +/// Accounts. +#[derive(Debug)] +pub struct Compound { + + + pub signer: solana_pubkey::Pubkey, + + + pub ore_mint: solana_pubkey::Pubkey, + + + pub stake: solana_pubkey::Pubkey, + + + pub stake_tokens: solana_pubkey::Pubkey, + + + pub treasury: solana_pubkey::Pubkey, + + + pub treasury_tokens: solana_pubkey::Pubkey, + + + pub vault: solana_pubkey::Pubkey, + + + pub vault_tokens: solana_pubkey::Pubkey, + + + pub system_program: solana_pubkey::Pubkey, + + + pub token_program: solana_pubkey::Pubkey, + + + pub associated_token_program: solana_pubkey::Pubkey, + + + pub ore_program: solana_pubkey::Pubkey, + } + +impl Compound { + 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(12+ remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new( + self.signer, + true + )); + accounts.push(solana_instruction::AccountMeta::new( + self.ore_mint, + 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( + self.treasury_tokens, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.vault, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.vault_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.push(solana_instruction::AccountMeta::new_readonly( + self.ore_program, + false + )); + accounts.extend_from_slice(remaining_accounts); + let data = CompoundInstructionData::new().try_to_vec().unwrap(); + + solana_instruction::Instruction { + program_id: crate::ORE_LST_ID, + accounts, + data, + } + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] + pub struct CompoundInstructionData { + discriminator: u8, + } + +impl CompoundInstructionData { + pub fn new() -> Self { + Self { + discriminator: 1, + } + } + + pub(crate) fn try_to_vec(&self) -> Result, std::io::Error> { + borsh::to_vec(self) + } + } + +impl Default for CompoundInstructionData { + fn default() -> Self { + Self::new() + } +} + + + +/// Instruction builder for `Compound`. +/// +/// ### Accounts: +/// + /// 0. `[writable, signer]` signer + /// 1. `[writable]` ore_mint + /// 2. `[writable]` stake + /// 3. `[writable]` stake_tokens + /// 4. `[writable]` treasury + /// 5. `[writable]` treasury_tokens + /// 6. `[writable]` vault + /// 7. `[writable]` vault_tokens + /// 8. `[optional]` system_program (default to `11111111111111111111111111111111`) + /// 9. `[optional]` token_program (default to `TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA`) + /// 10. `[]` associated_token_program + /// 11. `[]` ore_program +#[derive(Clone, Debug, Default)] +pub struct CompoundBuilder { + signer: Option, + ore_mint: Option, + stake: Option, + stake_tokens: Option, + treasury: Option, + treasury_tokens: Option, + vault: Option, + vault_tokens: Option, + system_program: Option, + token_program: Option, + associated_token_program: Option, + ore_program: Option, + __remaining_accounts: Vec, +} + +impl CompoundBuilder { + 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 ore_mint(&mut self, ore_mint: solana_pubkey::Pubkey) -> &mut Self { + self.ore_mint = Some(ore_mint); + 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 + } + #[inline(always)] + pub fn treasury_tokens(&mut self, treasury_tokens: solana_pubkey::Pubkey) -> &mut Self { + self.treasury_tokens = Some(treasury_tokens); + self + } + #[inline(always)] + pub fn vault(&mut self, vault: solana_pubkey::Pubkey) -> &mut Self { + self.vault = Some(vault); + self + } + #[inline(always)] + pub fn vault_tokens(&mut self, vault_tokens: solana_pubkey::Pubkey) -> &mut Self { + self.vault_tokens = Some(vault_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 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 = Compound { + signer: self.signer.expect("signer is not set"), + ore_mint: self.ore_mint.expect("ore_mint 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"), + treasury_tokens: self.treasury_tokens.expect("treasury_tokens is not set"), + vault: self.vault.expect("vault is not set"), + vault_tokens: self.vault_tokens.expect("vault_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"), + ore_program: self.ore_program.expect("ore_program is not set"), + }; + + accounts.instruction_with_remaining_accounts(&self.__remaining_accounts) + } +} + + /// `compound` CPI accounts. + pub struct CompoundCpiAccounts<'a, 'b> { + + + pub signer: &'b solana_account_info::AccountInfo<'a>, + + + pub ore_mint: &'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 treasury_tokens: &'b solana_account_info::AccountInfo<'a>, + + + pub vault: &'b solana_account_info::AccountInfo<'a>, + + + pub vault_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>, + + + pub ore_program: &'b solana_account_info::AccountInfo<'a>, + } + +/// `compound` CPI instruction. +pub struct CompoundCpi<'a, 'b> { + /// The program to invoke. + pub __program: &'b solana_account_info::AccountInfo<'a>, + + + pub signer: &'b solana_account_info::AccountInfo<'a>, + + + pub ore_mint: &'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 treasury_tokens: &'b solana_account_info::AccountInfo<'a>, + + + pub vault: &'b solana_account_info::AccountInfo<'a>, + + + pub vault_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>, + + + pub ore_program: &'b solana_account_info::AccountInfo<'a>, + } + +impl<'a, 'b> CompoundCpi<'a, 'b> { + pub fn new( + program: &'b solana_account_info::AccountInfo<'a>, + accounts: CompoundCpiAccounts<'a, 'b>, + ) -> Self { + Self { + __program: program, + signer: accounts.signer, + ore_mint: accounts.ore_mint, + stake: accounts.stake, + stake_tokens: accounts.stake_tokens, + treasury: accounts.treasury, + treasury_tokens: accounts.treasury_tokens, + vault: accounts.vault, + vault_tokens: accounts.vault_tokens, + system_program: accounts.system_program, + token_program: accounts.token_program, + associated_token_program: accounts.associated_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(12+ remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new( + *self.signer.key, + true + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.ore_mint.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( + *self.treasury_tokens.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.vault.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.vault_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 + )); + 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 = CompoundInstructionData::new().try_to_vec().unwrap(); + + let instruction = solana_instruction::Instruction { + program_id: crate::ORE_LST_ID, + accounts, + data, + }; + let mut account_infos = Vec::with_capacity(13 + remaining_accounts.len()); + account_infos.push(self.__program.clone()); + account_infos.push(self.signer.clone()); + account_infos.push(self.ore_mint.clone()); + account_infos.push(self.stake.clone()); + account_infos.push(self.stake_tokens.clone()); + account_infos.push(self.treasury.clone()); + account_infos.push(self.treasury_tokens.clone()); + account_infos.push(self.vault.clone()); + account_infos.push(self.vault_tokens.clone()); + account_infos.push(self.system_program.clone()); + account_infos.push(self.token_program.clone()); + account_infos.push(self.associated_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 `Compound` via CPI. +/// +/// ### Accounts: +/// + /// 0. `[writable, signer]` signer + /// 1. `[writable]` ore_mint + /// 2. `[writable]` stake + /// 3. `[writable]` stake_tokens + /// 4. `[writable]` treasury + /// 5. `[writable]` treasury_tokens + /// 6. `[writable]` vault + /// 7. `[writable]` vault_tokens + /// 8. `[]` system_program + /// 9. `[]` token_program + /// 10. `[]` associated_token_program + /// 11. `[]` ore_program +#[derive(Clone, Debug)] +pub struct CompoundCpiBuilder<'a, 'b> { + instruction: Box>, +} + +impl<'a, 'b> CompoundCpiBuilder<'a, 'b> { + pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self { + let instruction = Box::new(CompoundCpiBuilderInstruction { + __program: program, + signer: None, + ore_mint: None, + stake: None, + stake_tokens: None, + treasury: None, + treasury_tokens: None, + vault: None, + vault_tokens: None, + system_program: None, + token_program: None, + associated_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 ore_mint(&mut self, ore_mint: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.ore_mint = Some(ore_mint); + 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 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 vault(&mut self, vault: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.vault = Some(vault); + self + } + #[inline(always)] + pub fn vault_tokens(&mut self, vault_tokens: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.vault_tokens = Some(vault_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 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 = CompoundCpi { + __program: self.instruction.__program, + + signer: self.instruction.signer.expect("signer is not set"), + + ore_mint: self.instruction.ore_mint.expect("ore_mint 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"), + + treasury_tokens: self.instruction.treasury_tokens.expect("treasury_tokens is not set"), + + vault: self.instruction.vault.expect("vault is not set"), + + vault_tokens: self.instruction.vault_tokens.expect("vault_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"), + + 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 CompoundCpiBuilderInstruction<'a, 'b> { + __program: &'b solana_account_info::AccountInfo<'a>, + signer: Option<&'b solana_account_info::AccountInfo<'a>>, + ore_mint: 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>>, + treasury_tokens: Option<&'b solana_account_info::AccountInfo<'a>>, + vault: Option<&'b solana_account_info::AccountInfo<'a>>, + vault_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>>, + 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/initialize.rs b/clients/rust/src/generated/instructions/initialize.rs new file mode 100644 index 0000000..e4c2259 --- /dev/null +++ b/clients/rust/src/generated/instructions/initialize.rs @@ -0,0 +1,773 @@ +//! 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 INITIALIZE_DISCRIMINATOR: u8 = 100; + +/// Accounts. +#[derive(Debug)] +pub struct Initialize { + + + pub signer: solana_pubkey::Pubkey, + + + pub ore_mint: solana_pubkey::Pubkey, + + + pub store_mint: solana_pubkey::Pubkey, + + + pub metadata: solana_pubkey::Pubkey, + + + pub stake: solana_pubkey::Pubkey, + + + pub stake_tokens: solana_pubkey::Pubkey, + + + pub treasury: solana_pubkey::Pubkey, + + + pub vault: solana_pubkey::Pubkey, + + + pub vault_tokens: solana_pubkey::Pubkey, + + + pub system_program: solana_pubkey::Pubkey, + + + pub token_program: solana_pubkey::Pubkey, + + + pub associated_token_program: solana_pubkey::Pubkey, + + + pub metadata_program: solana_pubkey::Pubkey, + + + pub ore_program: solana_pubkey::Pubkey, + + + pub rent_sysvar: solana_pubkey::Pubkey, + } + +impl Initialize { + 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(15+ remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new( + self.signer, + true + )); + accounts.push(solana_instruction::AccountMeta::new( + self.ore_mint, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.store_mint, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.metadata, + 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( + self.vault, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.vault_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.push(solana_instruction::AccountMeta::new_readonly( + self.metadata_program, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.ore_program, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.rent_sysvar, + false + )); + accounts.extend_from_slice(remaining_accounts); + let data = InitializeInstructionData::new().try_to_vec().unwrap(); + + solana_instruction::Instruction { + program_id: crate::ORE_LST_ID, + accounts, + data, + } + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] + pub struct InitializeInstructionData { + discriminator: u8, + } + +impl InitializeInstructionData { + pub fn new() -> Self { + Self { + discriminator: 100, + } + } + + pub(crate) fn try_to_vec(&self) -> Result, std::io::Error> { + borsh::to_vec(self) + } + } + +impl Default for InitializeInstructionData { + fn default() -> Self { + Self::new() + } +} + + + +/// Instruction builder for `Initialize`. +/// +/// ### Accounts: +/// + /// 0. `[writable, signer]` signer + /// 1. `[writable]` ore_mint + /// 2. `[writable]` store_mint + /// 3. `[writable]` metadata + /// 4. `[writable]` stake + /// 5. `[writable]` stake_tokens + /// 6. `[writable]` treasury + /// 7. `[writable]` vault + /// 8. `[writable]` vault_tokens + /// 9. `[optional]` system_program (default to `11111111111111111111111111111111`) + /// 10. `[optional]` token_program (default to `TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA`) + /// 11. `[]` associated_token_program + /// 12. `[]` metadata_program + /// 13. `[]` ore_program + /// 14. `[optional]` rent_sysvar (default to `SysvarRent111111111111111111111111111111111`) +#[derive(Clone, Debug, Default)] +pub struct InitializeBuilder { + signer: Option, + ore_mint: Option, + store_mint: Option, + metadata: Option, + stake: Option, + stake_tokens: Option, + treasury: Option, + vault: Option, + vault_tokens: Option, + system_program: Option, + token_program: Option, + associated_token_program: Option, + metadata_program: Option, + ore_program: Option, + rent_sysvar: Option, + __remaining_accounts: Vec, +} + +impl InitializeBuilder { + 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 ore_mint(&mut self, ore_mint: solana_pubkey::Pubkey) -> &mut Self { + self.ore_mint = Some(ore_mint); + self + } + #[inline(always)] + pub fn store_mint(&mut self, store_mint: solana_pubkey::Pubkey) -> &mut Self { + self.store_mint = Some(store_mint); + self + } + #[inline(always)] + pub fn metadata(&mut self, metadata: solana_pubkey::Pubkey) -> &mut Self { + self.metadata = Some(metadata); + 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 + } + #[inline(always)] + pub fn vault(&mut self, vault: solana_pubkey::Pubkey) -> &mut Self { + self.vault = Some(vault); + self + } + #[inline(always)] + pub fn vault_tokens(&mut self, vault_tokens: solana_pubkey::Pubkey) -> &mut Self { + self.vault_tokens = Some(vault_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 metadata_program(&mut self, metadata_program: solana_pubkey::Pubkey) -> &mut Self { + self.metadata_program = Some(metadata_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 'SysvarRent111111111111111111111111111111111']` +#[inline(always)] + pub fn rent_sysvar(&mut self, rent_sysvar: solana_pubkey::Pubkey) -> &mut Self { + self.rent_sysvar = Some(rent_sysvar); + 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 = Initialize { + signer: self.signer.expect("signer is not set"), + ore_mint: self.ore_mint.expect("ore_mint is not set"), + store_mint: self.store_mint.expect("store_mint is not set"), + metadata: self.metadata.expect("metadata 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"), + vault: self.vault.expect("vault is not set"), + vault_tokens: self.vault_tokens.expect("vault_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"), + metadata_program: self.metadata_program.expect("metadata_program is not set"), + ore_program: self.ore_program.expect("ore_program is not set"), + rent_sysvar: self.rent_sysvar.unwrap_or(solana_pubkey::pubkey!("SysvarRent111111111111111111111111111111111")), + }; + + accounts.instruction_with_remaining_accounts(&self.__remaining_accounts) + } +} + + /// `initialize` CPI accounts. + pub struct InitializeCpiAccounts<'a, 'b> { + + + pub signer: &'b solana_account_info::AccountInfo<'a>, + + + pub ore_mint: &'b solana_account_info::AccountInfo<'a>, + + + pub store_mint: &'b solana_account_info::AccountInfo<'a>, + + + pub metadata: &'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 vault: &'b solana_account_info::AccountInfo<'a>, + + + pub vault_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>, + + + pub metadata_program: &'b solana_account_info::AccountInfo<'a>, + + + pub ore_program: &'b solana_account_info::AccountInfo<'a>, + + + pub rent_sysvar: &'b solana_account_info::AccountInfo<'a>, + } + +/// `initialize` CPI instruction. +pub struct InitializeCpi<'a, 'b> { + /// The program to invoke. + pub __program: &'b solana_account_info::AccountInfo<'a>, + + + pub signer: &'b solana_account_info::AccountInfo<'a>, + + + pub ore_mint: &'b solana_account_info::AccountInfo<'a>, + + + pub store_mint: &'b solana_account_info::AccountInfo<'a>, + + + pub metadata: &'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 vault: &'b solana_account_info::AccountInfo<'a>, + + + pub vault_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>, + + + pub metadata_program: &'b solana_account_info::AccountInfo<'a>, + + + pub ore_program: &'b solana_account_info::AccountInfo<'a>, + + + pub rent_sysvar: &'b solana_account_info::AccountInfo<'a>, + } + +impl<'a, 'b> InitializeCpi<'a, 'b> { + pub fn new( + program: &'b solana_account_info::AccountInfo<'a>, + accounts: InitializeCpiAccounts<'a, 'b>, + ) -> Self { + Self { + __program: program, + signer: accounts.signer, + ore_mint: accounts.ore_mint, + store_mint: accounts.store_mint, + metadata: accounts.metadata, + stake: accounts.stake, + stake_tokens: accounts.stake_tokens, + treasury: accounts.treasury, + vault: accounts.vault, + vault_tokens: accounts.vault_tokens, + system_program: accounts.system_program, + token_program: accounts.token_program, + associated_token_program: accounts.associated_token_program, + metadata_program: accounts.metadata_program, + ore_program: accounts.ore_program, + rent_sysvar: accounts.rent_sysvar, + } + } + #[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(15+ remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new( + *self.signer.key, + true + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.ore_mint.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.store_mint.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.metadata.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( + *self.vault.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.vault_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 + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.metadata_program.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.ore_program.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.rent_sysvar.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 = InitializeInstructionData::new().try_to_vec().unwrap(); + + let instruction = solana_instruction::Instruction { + program_id: crate::ORE_LST_ID, + accounts, + data, + }; + let mut account_infos = Vec::with_capacity(16 + remaining_accounts.len()); + account_infos.push(self.__program.clone()); + account_infos.push(self.signer.clone()); + account_infos.push(self.ore_mint.clone()); + account_infos.push(self.store_mint.clone()); + account_infos.push(self.metadata.clone()); + account_infos.push(self.stake.clone()); + account_infos.push(self.stake_tokens.clone()); + account_infos.push(self.treasury.clone()); + account_infos.push(self.vault.clone()); + account_infos.push(self.vault_tokens.clone()); + account_infos.push(self.system_program.clone()); + account_infos.push(self.token_program.clone()); + account_infos.push(self.associated_token_program.clone()); + account_infos.push(self.metadata_program.clone()); + account_infos.push(self.ore_program.clone()); + account_infos.push(self.rent_sysvar.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 `Initialize` via CPI. +/// +/// ### Accounts: +/// + /// 0. `[writable, signer]` signer + /// 1. `[writable]` ore_mint + /// 2. `[writable]` store_mint + /// 3. `[writable]` metadata + /// 4. `[writable]` stake + /// 5. `[writable]` stake_tokens + /// 6. `[writable]` treasury + /// 7. `[writable]` vault + /// 8. `[writable]` vault_tokens + /// 9. `[]` system_program + /// 10. `[]` token_program + /// 11. `[]` associated_token_program + /// 12. `[]` metadata_program + /// 13. `[]` ore_program + /// 14. `[]` rent_sysvar +#[derive(Clone, Debug)] +pub struct InitializeCpiBuilder<'a, 'b> { + instruction: Box>, +} + +impl<'a, 'b> InitializeCpiBuilder<'a, 'b> { + pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self { + let instruction = Box::new(InitializeCpiBuilderInstruction { + __program: program, + signer: None, + ore_mint: None, + store_mint: None, + metadata: None, + stake: None, + stake_tokens: None, + treasury: None, + vault: None, + vault_tokens: None, + system_program: None, + token_program: None, + associated_token_program: None, + metadata_program: None, + ore_program: None, + rent_sysvar: 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 ore_mint(&mut self, ore_mint: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.ore_mint = Some(ore_mint); + self + } + #[inline(always)] + pub fn store_mint(&mut self, store_mint: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.store_mint = Some(store_mint); + self + } + #[inline(always)] + pub fn metadata(&mut self, metadata: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.metadata = Some(metadata); + 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 vault(&mut self, vault: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.vault = Some(vault); + self + } + #[inline(always)] + pub fn vault_tokens(&mut self, vault_tokens: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.vault_tokens = Some(vault_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 metadata_program(&mut self, metadata_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.metadata_program = Some(metadata_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 rent_sysvar(&mut self, rent_sysvar: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.rent_sysvar = Some(rent_sysvar); + 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 = InitializeCpi { + __program: self.instruction.__program, + + signer: self.instruction.signer.expect("signer is not set"), + + ore_mint: self.instruction.ore_mint.expect("ore_mint is not set"), + + store_mint: self.instruction.store_mint.expect("store_mint is not set"), + + metadata: self.instruction.metadata.expect("metadata 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"), + + vault: self.instruction.vault.expect("vault is not set"), + + vault_tokens: self.instruction.vault_tokens.expect("vault_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"), + + metadata_program: self.instruction.metadata_program.expect("metadata_program is not set"), + + ore_program: self.instruction.ore_program.expect("ore_program is not set"), + + rent_sysvar: self.instruction.rent_sysvar.expect("rent_sysvar is not set"), + }; + instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts) + } +} + +#[derive(Clone, Debug)] +struct InitializeCpiBuilderInstruction<'a, 'b> { + __program: &'b solana_account_info::AccountInfo<'a>, + signer: Option<&'b solana_account_info::AccountInfo<'a>>, + ore_mint: Option<&'b solana_account_info::AccountInfo<'a>>, + store_mint: Option<&'b solana_account_info::AccountInfo<'a>>, + metadata: 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>>, + vault: Option<&'b solana_account_info::AccountInfo<'a>>, + vault_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>>, + metadata_program: Option<&'b solana_account_info::AccountInfo<'a>>, + ore_program: Option<&'b solana_account_info::AccountInfo<'a>>, + rent_sysvar: 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 0000000..173a40c --- /dev/null +++ b/clients/rust/src/generated/instructions/mod.rs @@ -0,0 +1,17 @@ +//! 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#compound; + pub(crate) mod r#initialize; + pub(crate) mod r#unwrap; + pub(crate) mod r#wrap; + + pub use self::r#compound::*; + pub use self::r#initialize::*; + pub use self::r#unwrap::*; + pub use self::r#wrap::*; + diff --git a/clients/rust/src/generated/instructions/unwrap.rs b/clients/rust/src/generated/instructions/unwrap.rs new file mode 100644 index 0000000..1e35a3c --- /dev/null +++ b/clients/rust/src/generated/instructions/unwrap.rs @@ -0,0 +1,848 @@ +//! 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 UNWRAP_DISCRIMINATOR: u8 = 2; + +/// Accounts. +#[derive(Debug)] +pub struct Unwrap { + + + pub signer: solana_pubkey::Pubkey, + + + pub payer: solana_pubkey::Pubkey, + + + pub sender_ore: solana_pubkey::Pubkey, + + + pub sender_store: solana_pubkey::Pubkey, + + + pub ore_mint: solana_pubkey::Pubkey, + + + pub store_mint: solana_pubkey::Pubkey, + + + pub stake: solana_pubkey::Pubkey, + + + pub stake_tokens: solana_pubkey::Pubkey, + + + pub treasury: solana_pubkey::Pubkey, + + + pub treasury_tokens: solana_pubkey::Pubkey, + + + pub vault: solana_pubkey::Pubkey, + + + pub vault_tokens: solana_pubkey::Pubkey, + + + pub system_program: solana_pubkey::Pubkey, + + + pub token_program: solana_pubkey::Pubkey, + + + pub associated_token_program: solana_pubkey::Pubkey, + + + pub ore_program: solana_pubkey::Pubkey, + } + +impl Unwrap { + pub fn instruction(&self, args: UnwrapInstructionArgs) -> 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: UnwrapInstructionArgs, 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.payer, + true + )); + accounts.push(solana_instruction::AccountMeta::new( + self.sender_ore, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.sender_store, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.ore_mint, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.store_mint, + 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( + self.treasury_tokens, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.vault, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.vault_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.push(solana_instruction::AccountMeta::new_readonly( + self.ore_program, + false + )); + accounts.extend_from_slice(remaining_accounts); + let mut data = UnwrapInstructionData::new().try_to_vec().unwrap(); + let mut args = args.try_to_vec().unwrap(); + data.append(&mut args); + + solana_instruction::Instruction { + program_id: crate::ORE_LST_ID, + accounts, + data, + } + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] + pub struct UnwrapInstructionData { + discriminator: u8, + } + +impl UnwrapInstructionData { + 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 UnwrapInstructionData { + fn default() -> Self { + Self::new() + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] + pub struct UnwrapInstructionArgs { + pub amount: u64, + } + +impl UnwrapInstructionArgs { + pub(crate) fn try_to_vec(&self) -> Result, std::io::Error> { + borsh::to_vec(self) + } +} + + +/// Instruction builder for `Unwrap`. +/// +/// ### Accounts: +/// + /// 0. `[writable, signer]` signer + /// 1. `[writable, signer]` payer + /// 2. `[writable]` sender_ore + /// 3. `[writable]` sender_store + /// 4. `[writable]` ore_mint + /// 5. `[writable]` store_mint + /// 6. `[writable]` stake + /// 7. `[writable]` stake_tokens + /// 8. `[writable]` treasury + /// 9. `[writable]` treasury_tokens + /// 10. `[writable]` vault + /// 11. `[writable]` vault_tokens + /// 12. `[optional]` system_program (default to `11111111111111111111111111111111`) + /// 13. `[optional]` token_program (default to `TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA`) + /// 14. `[]` associated_token_program + /// 15. `[]` ore_program +#[derive(Clone, Debug, Default)] +pub struct UnwrapBuilder { + signer: Option, + payer: Option, + sender_ore: Option, + sender_store: Option, + ore_mint: Option, + store_mint: Option, + stake: Option, + stake_tokens: Option, + treasury: Option, + treasury_tokens: Option, + vault: Option, + vault_tokens: Option, + system_program: Option, + token_program: Option, + associated_token_program: Option, + ore_program: Option, + amount: Option, + __remaining_accounts: Vec, +} + +impl UnwrapBuilder { + 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 payer(&mut self, payer: solana_pubkey::Pubkey) -> &mut Self { + self.payer = Some(payer); + self + } + #[inline(always)] + pub fn sender_ore(&mut self, sender_ore: solana_pubkey::Pubkey) -> &mut Self { + self.sender_ore = Some(sender_ore); + self + } + #[inline(always)] + pub fn sender_store(&mut self, sender_store: solana_pubkey::Pubkey) -> &mut Self { + self.sender_store = Some(sender_store); + self + } + #[inline(always)] + pub fn ore_mint(&mut self, ore_mint: solana_pubkey::Pubkey) -> &mut Self { + self.ore_mint = Some(ore_mint); + self + } + #[inline(always)] + pub fn store_mint(&mut self, store_mint: solana_pubkey::Pubkey) -> &mut Self { + self.store_mint = Some(store_mint); + 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 + } + #[inline(always)] + pub fn treasury_tokens(&mut self, treasury_tokens: solana_pubkey::Pubkey) -> &mut Self { + self.treasury_tokens = Some(treasury_tokens); + self + } + #[inline(always)] + pub fn vault(&mut self, vault: solana_pubkey::Pubkey) -> &mut Self { + self.vault = Some(vault); + self + } + #[inline(always)] + pub fn vault_tokens(&mut self, vault_tokens: solana_pubkey::Pubkey) -> &mut Self { + self.vault_tokens = Some(vault_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 ore_program(&mut self, ore_program: solana_pubkey::Pubkey) -> &mut Self { + self.ore_program = Some(ore_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 = Unwrap { + signer: self.signer.expect("signer is not set"), + payer: self.payer.expect("payer is not set"), + sender_ore: self.sender_ore.expect("sender_ore is not set"), + sender_store: self.sender_store.expect("sender_store is not set"), + ore_mint: self.ore_mint.expect("ore_mint is not set"), + store_mint: self.store_mint.expect("store_mint 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"), + treasury_tokens: self.treasury_tokens.expect("treasury_tokens is not set"), + vault: self.vault.expect("vault is not set"), + vault_tokens: self.vault_tokens.expect("vault_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"), + ore_program: self.ore_program.expect("ore_program is not set"), + }; + let args = UnwrapInstructionArgs { + amount: self.amount.clone().expect("amount is not set"), + }; + + accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts) + } +} + + /// `unwrap` CPI accounts. + pub struct UnwrapCpiAccounts<'a, 'b> { + + + pub signer: &'b solana_account_info::AccountInfo<'a>, + + + pub payer: &'b solana_account_info::AccountInfo<'a>, + + + pub sender_ore: &'b solana_account_info::AccountInfo<'a>, + + + pub sender_store: &'b solana_account_info::AccountInfo<'a>, + + + pub ore_mint: &'b solana_account_info::AccountInfo<'a>, + + + pub store_mint: &'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 treasury_tokens: &'b solana_account_info::AccountInfo<'a>, + + + pub vault: &'b solana_account_info::AccountInfo<'a>, + + + pub vault_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>, + + + pub ore_program: &'b solana_account_info::AccountInfo<'a>, + } + +/// `unwrap` CPI instruction. +pub struct UnwrapCpi<'a, 'b> { + /// The program to invoke. + pub __program: &'b solana_account_info::AccountInfo<'a>, + + + pub signer: &'b solana_account_info::AccountInfo<'a>, + + + pub payer: &'b solana_account_info::AccountInfo<'a>, + + + pub sender_ore: &'b solana_account_info::AccountInfo<'a>, + + + pub sender_store: &'b solana_account_info::AccountInfo<'a>, + + + pub ore_mint: &'b solana_account_info::AccountInfo<'a>, + + + pub store_mint: &'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 treasury_tokens: &'b solana_account_info::AccountInfo<'a>, + + + pub vault: &'b solana_account_info::AccountInfo<'a>, + + + pub vault_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>, + + + pub ore_program: &'b solana_account_info::AccountInfo<'a>, + /// The arguments for the instruction. + pub __args: UnwrapInstructionArgs, + } + +impl<'a, 'b> UnwrapCpi<'a, 'b> { + pub fn new( + program: &'b solana_account_info::AccountInfo<'a>, + accounts: UnwrapCpiAccounts<'a, 'b>, + args: UnwrapInstructionArgs, + ) -> Self { + Self { + __program: program, + signer: accounts.signer, + payer: accounts.payer, + sender_ore: accounts.sender_ore, + sender_store: accounts.sender_store, + ore_mint: accounts.ore_mint, + store_mint: accounts.store_mint, + stake: accounts.stake, + stake_tokens: accounts.stake_tokens, + treasury: accounts.treasury, + treasury_tokens: accounts.treasury_tokens, + vault: accounts.vault, + vault_tokens: accounts.vault_tokens, + system_program: accounts.system_program, + token_program: accounts.token_program, + associated_token_program: accounts.associated_token_program, + ore_program: accounts.ore_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(16+ remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new( + *self.signer.key, + true + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.payer.key, + true + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.sender_ore.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.sender_store.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.ore_mint.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.store_mint.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( + *self.treasury_tokens.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.vault.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.vault_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 + )); + 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 mut data = UnwrapInstructionData::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_LST_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.payer.clone()); + account_infos.push(self.sender_ore.clone()); + account_infos.push(self.sender_store.clone()); + account_infos.push(self.ore_mint.clone()); + account_infos.push(self.store_mint.clone()); + account_infos.push(self.stake.clone()); + account_infos.push(self.stake_tokens.clone()); + account_infos.push(self.treasury.clone()); + account_infos.push(self.treasury_tokens.clone()); + account_infos.push(self.vault.clone()); + account_infos.push(self.vault_tokens.clone()); + account_infos.push(self.system_program.clone()); + account_infos.push(self.token_program.clone()); + account_infos.push(self.associated_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 `Unwrap` via CPI. +/// +/// ### Accounts: +/// + /// 0. `[writable, signer]` signer + /// 1. `[writable, signer]` payer + /// 2. `[writable]` sender_ore + /// 3. `[writable]` sender_store + /// 4. `[writable]` ore_mint + /// 5. `[writable]` store_mint + /// 6. `[writable]` stake + /// 7. `[writable]` stake_tokens + /// 8. `[writable]` treasury + /// 9. `[writable]` treasury_tokens + /// 10. `[writable]` vault + /// 11. `[writable]` vault_tokens + /// 12. `[]` system_program + /// 13. `[]` token_program + /// 14. `[]` associated_token_program + /// 15. `[]` ore_program +#[derive(Clone, Debug)] +pub struct UnwrapCpiBuilder<'a, 'b> { + instruction: Box>, +} + +impl<'a, 'b> UnwrapCpiBuilder<'a, 'b> { + pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self { + let instruction = Box::new(UnwrapCpiBuilderInstruction { + __program: program, + signer: None, + payer: None, + sender_ore: None, + sender_store: None, + ore_mint: None, + store_mint: None, + stake: None, + stake_tokens: None, + treasury: None, + treasury_tokens: None, + vault: None, + vault_tokens: None, + system_program: None, + token_program: None, + associated_token_program: None, + ore_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 payer(&mut self, payer: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.payer = Some(payer); + self + } + #[inline(always)] + pub fn sender_ore(&mut self, sender_ore: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.sender_ore = Some(sender_ore); + self + } + #[inline(always)] + pub fn sender_store(&mut self, sender_store: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.sender_store = Some(sender_store); + self + } + #[inline(always)] + pub fn ore_mint(&mut self, ore_mint: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.ore_mint = Some(ore_mint); + self + } + #[inline(always)] + pub fn store_mint(&mut self, store_mint: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.store_mint = Some(store_mint); + 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 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 vault(&mut self, vault: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.vault = Some(vault); + self + } + #[inline(always)] + pub fn vault_tokens(&mut self, vault_tokens: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.vault_tokens = Some(vault_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 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 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 = UnwrapInstructionArgs { + amount: self.instruction.amount.clone().expect("amount is not set"), + }; + let instruction = UnwrapCpi { + __program: self.instruction.__program, + + signer: self.instruction.signer.expect("signer is not set"), + + payer: self.instruction.payer.expect("payer is not set"), + + sender_ore: self.instruction.sender_ore.expect("sender_ore is not set"), + + sender_store: self.instruction.sender_store.expect("sender_store is not set"), + + ore_mint: self.instruction.ore_mint.expect("ore_mint is not set"), + + store_mint: self.instruction.store_mint.expect("store_mint 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"), + + treasury_tokens: self.instruction.treasury_tokens.expect("treasury_tokens is not set"), + + vault: self.instruction.vault.expect("vault is not set"), + + vault_tokens: self.instruction.vault_tokens.expect("vault_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"), + + ore_program: self.instruction.ore_program.expect("ore_program is not set"), + __args: args, + }; + instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts) + } +} + +#[derive(Clone, Debug)] +struct UnwrapCpiBuilderInstruction<'a, 'b> { + __program: &'b solana_account_info::AccountInfo<'a>, + signer: Option<&'b solana_account_info::AccountInfo<'a>>, + payer: Option<&'b solana_account_info::AccountInfo<'a>>, + sender_ore: Option<&'b solana_account_info::AccountInfo<'a>>, + sender_store: Option<&'b solana_account_info::AccountInfo<'a>>, + ore_mint: Option<&'b solana_account_info::AccountInfo<'a>>, + store_mint: 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>>, + treasury_tokens: Option<&'b solana_account_info::AccountInfo<'a>>, + vault: Option<&'b solana_account_info::AccountInfo<'a>>, + vault_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>>, + ore_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 0000000..849aa6c --- /dev/null +++ b/clients/rust/src/generated/instructions/wrap.rs @@ -0,0 +1,848 @@ +//! 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 = 3; + +/// Accounts. +#[derive(Debug)] +pub struct Wrap { + + + pub signer: solana_pubkey::Pubkey, + + + pub payer: solana_pubkey::Pubkey, + + + pub sender_ore: solana_pubkey::Pubkey, + + + pub sender_store: solana_pubkey::Pubkey, + + + pub ore_mint: solana_pubkey::Pubkey, + + + pub store_mint: solana_pubkey::Pubkey, + + + pub stake: solana_pubkey::Pubkey, + + + pub stake_tokens: solana_pubkey::Pubkey, + + + pub treasury: solana_pubkey::Pubkey, + + + pub treasury_tokens: solana_pubkey::Pubkey, + + + pub vault: solana_pubkey::Pubkey, + + + pub vault_tokens: solana_pubkey::Pubkey, + + + pub system_program: solana_pubkey::Pubkey, + + + pub token_program: solana_pubkey::Pubkey, + + + pub associated_token_program: solana_pubkey::Pubkey, + + + pub ore_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(16+ remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new( + self.signer, + true + )); + accounts.push(solana_instruction::AccountMeta::new( + self.payer, + true + )); + accounts.push(solana_instruction::AccountMeta::new( + self.sender_ore, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.sender_store, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.ore_mint, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.store_mint, + 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( + self.treasury_tokens, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.vault, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + self.vault_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.push(solana_instruction::AccountMeta::new_readonly( + self.ore_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_LST_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: 3, + } + } + + 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. `[writable, signer]` signer + /// 1. `[writable, signer]` payer + /// 2. `[writable]` sender_ore + /// 3. `[writable]` sender_store + /// 4. `[writable]` ore_mint + /// 5. `[writable]` store_mint + /// 6. `[writable]` stake + /// 7. `[writable]` stake_tokens + /// 8. `[writable]` treasury + /// 9. `[writable]` treasury_tokens + /// 10. `[writable]` vault + /// 11. `[writable]` vault_tokens + /// 12. `[optional]` system_program (default to `11111111111111111111111111111111`) + /// 13. `[optional]` token_program (default to `TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA`) + /// 14. `[]` associated_token_program + /// 15. `[]` ore_program +#[derive(Clone, Debug, Default)] +pub struct WrapBuilder { + signer: Option, + payer: Option, + sender_ore: Option, + sender_store: Option, + ore_mint: Option, + store_mint: Option, + stake: Option, + stake_tokens: Option, + treasury: Option, + treasury_tokens: Option, + vault: Option, + vault_tokens: Option, + system_program: Option, + token_program: Option, + associated_token_program: Option, + ore_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 payer(&mut self, payer: solana_pubkey::Pubkey) -> &mut Self { + self.payer = Some(payer); + self + } + #[inline(always)] + pub fn sender_ore(&mut self, sender_ore: solana_pubkey::Pubkey) -> &mut Self { + self.sender_ore = Some(sender_ore); + self + } + #[inline(always)] + pub fn sender_store(&mut self, sender_store: solana_pubkey::Pubkey) -> &mut Self { + self.sender_store = Some(sender_store); + self + } + #[inline(always)] + pub fn ore_mint(&mut self, ore_mint: solana_pubkey::Pubkey) -> &mut Self { + self.ore_mint = Some(ore_mint); + self + } + #[inline(always)] + pub fn store_mint(&mut self, store_mint: solana_pubkey::Pubkey) -> &mut Self { + self.store_mint = Some(store_mint); + 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 + } + #[inline(always)] + pub fn treasury_tokens(&mut self, treasury_tokens: solana_pubkey::Pubkey) -> &mut Self { + self.treasury_tokens = Some(treasury_tokens); + self + } + #[inline(always)] + pub fn vault(&mut self, vault: solana_pubkey::Pubkey) -> &mut Self { + self.vault = Some(vault); + self + } + #[inline(always)] + pub fn vault_tokens(&mut self, vault_tokens: solana_pubkey::Pubkey) -> &mut Self { + self.vault_tokens = Some(vault_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 ore_program(&mut self, ore_program: solana_pubkey::Pubkey) -> &mut Self { + self.ore_program = Some(ore_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"), + payer: self.payer.expect("payer is not set"), + sender_ore: self.sender_ore.expect("sender_ore is not set"), + sender_store: self.sender_store.expect("sender_store is not set"), + ore_mint: self.ore_mint.expect("ore_mint is not set"), + store_mint: self.store_mint.expect("store_mint 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"), + treasury_tokens: self.treasury_tokens.expect("treasury_tokens is not set"), + vault: self.vault.expect("vault is not set"), + vault_tokens: self.vault_tokens.expect("vault_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"), + ore_program: self.ore_program.expect("ore_program is not set"), + }; + 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 payer: &'b solana_account_info::AccountInfo<'a>, + + + pub sender_ore: &'b solana_account_info::AccountInfo<'a>, + + + pub sender_store: &'b solana_account_info::AccountInfo<'a>, + + + pub ore_mint: &'b solana_account_info::AccountInfo<'a>, + + + pub store_mint: &'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 treasury_tokens: &'b solana_account_info::AccountInfo<'a>, + + + pub vault: &'b solana_account_info::AccountInfo<'a>, + + + pub vault_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>, + + + pub ore_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 payer: &'b solana_account_info::AccountInfo<'a>, + + + pub sender_ore: &'b solana_account_info::AccountInfo<'a>, + + + pub sender_store: &'b solana_account_info::AccountInfo<'a>, + + + pub ore_mint: &'b solana_account_info::AccountInfo<'a>, + + + pub store_mint: &'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 treasury_tokens: &'b solana_account_info::AccountInfo<'a>, + + + pub vault: &'b solana_account_info::AccountInfo<'a>, + + + pub vault_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>, + + + pub ore_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, + payer: accounts.payer, + sender_ore: accounts.sender_ore, + sender_store: accounts.sender_store, + ore_mint: accounts.ore_mint, + store_mint: accounts.store_mint, + stake: accounts.stake, + stake_tokens: accounts.stake_tokens, + treasury: accounts.treasury, + treasury_tokens: accounts.treasury_tokens, + vault: accounts.vault, + vault_tokens: accounts.vault_tokens, + system_program: accounts.system_program, + token_program: accounts.token_program, + associated_token_program: accounts.associated_token_program, + ore_program: accounts.ore_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(16+ remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new( + *self.signer.key, + true + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.payer.key, + true + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.sender_ore.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.sender_store.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.ore_mint.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.store_mint.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( + *self.treasury_tokens.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.vault.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.vault_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 + )); + 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 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_LST_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.payer.clone()); + account_infos.push(self.sender_ore.clone()); + account_infos.push(self.sender_store.clone()); + account_infos.push(self.ore_mint.clone()); + account_infos.push(self.store_mint.clone()); + account_infos.push(self.stake.clone()); + account_infos.push(self.stake_tokens.clone()); + account_infos.push(self.treasury.clone()); + account_infos.push(self.treasury_tokens.clone()); + account_infos.push(self.vault.clone()); + account_infos.push(self.vault_tokens.clone()); + account_infos.push(self.system_program.clone()); + account_infos.push(self.token_program.clone()); + account_infos.push(self.associated_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 `Wrap` via CPI. +/// +/// ### Accounts: +/// + /// 0. `[writable, signer]` signer + /// 1. `[writable, signer]` payer + /// 2. `[writable]` sender_ore + /// 3. `[writable]` sender_store + /// 4. `[writable]` ore_mint + /// 5. `[writable]` store_mint + /// 6. `[writable]` stake + /// 7. `[writable]` stake_tokens + /// 8. `[writable]` treasury + /// 9. `[writable]` treasury_tokens + /// 10. `[writable]` vault + /// 11. `[writable]` vault_tokens + /// 12. `[]` system_program + /// 13. `[]` token_program + /// 14. `[]` associated_token_program + /// 15. `[]` ore_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, + payer: None, + sender_ore: None, + sender_store: None, + ore_mint: None, + store_mint: None, + stake: None, + stake_tokens: None, + treasury: None, + treasury_tokens: None, + vault: None, + vault_tokens: None, + system_program: None, + token_program: None, + associated_token_program: None, + ore_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 payer(&mut self, payer: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.payer = Some(payer); + self + } + #[inline(always)] + pub fn sender_ore(&mut self, sender_ore: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.sender_ore = Some(sender_ore); + self + } + #[inline(always)] + pub fn sender_store(&mut self, sender_store: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.sender_store = Some(sender_store); + self + } + #[inline(always)] + pub fn ore_mint(&mut self, ore_mint: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.ore_mint = Some(ore_mint); + self + } + #[inline(always)] + pub fn store_mint(&mut self, store_mint: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.store_mint = Some(store_mint); + 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 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 vault(&mut self, vault: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.vault = Some(vault); + self + } + #[inline(always)] + pub fn vault_tokens(&mut self, vault_tokens: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.vault_tokens = Some(vault_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 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 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"), + + payer: self.instruction.payer.expect("payer is not set"), + + sender_ore: self.instruction.sender_ore.expect("sender_ore is not set"), + + sender_store: self.instruction.sender_store.expect("sender_store is not set"), + + ore_mint: self.instruction.ore_mint.expect("ore_mint is not set"), + + store_mint: self.instruction.store_mint.expect("store_mint 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"), + + treasury_tokens: self.instruction.treasury_tokens.expect("treasury_tokens is not set"), + + vault: self.instruction.vault.expect("vault is not set"), + + vault_tokens: self.instruction.vault_tokens.expect("vault_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"), + + ore_program: self.instruction.ore_program.expect("ore_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>>, + payer: Option<&'b solana_account_info::AccountInfo<'a>>, + sender_ore: Option<&'b solana_account_info::AccountInfo<'a>>, + sender_store: Option<&'b solana_account_info::AccountInfo<'a>>, + ore_mint: Option<&'b solana_account_info::AccountInfo<'a>>, + store_mint: 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>>, + treasury_tokens: Option<&'b solana_account_info::AccountInfo<'a>>, + vault: Option<&'b solana_account_info::AccountInfo<'a>>, + vault_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>>, + ore_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 0000000..52d3f4b --- /dev/null +++ b/clients/rust/src/generated/mod.rs @@ -0,0 +1,14 @@ +//! This code was AUTOGENERATED using the codama library. +//! Please DO NOT EDIT THIS FILE, instead use visitors +//! to add features, then rerun codama to update it. +//! +//! +//! + + pub mod accounts; + pub mod errors; + pub mod instructions; + pub mod programs; + pub mod shared; + + 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 0000000..a05550e --- /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_lst` program ID. + pub const ORE_LST_ID: Pubkey = pubkey!("LStwN2E5Uw6MCtuxHRLhy8RY9hxqW2XRpLzettb696y"); + diff --git a/clients/rust/src/generated/shared.rs b/clients/rust/src/generated/shared.rs new file mode 100644 index 0000000..76fa92e --- /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/codama.json b/codama.json new file mode 100644 index 0000000..b536cd8 --- /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 + } + ] + } + } +} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..ac02b9e --- /dev/null +++ b/package.json @@ -0,0 +1,16 @@ +{ + "name": "ore-lst", + "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 0000000..bfa0fea --- /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 + } +}